@component-hook/pdf-canvas 0.2.0-alpha.0 → 0.2.0

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(rt,q){typeof exports=="object"&&typeof module<"u"?q(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],q):(rt=typeof globalThis<"u"?globalThis:rt||self,q(rt["pdf-canvas"]={},rt.Vue))})(this,function(rt,q){"use strict";var SS=Object.defineProperty;var tb=rt=>{throw TypeError(rt)};var CS=(rt,q,Dt)=>q in rt?SS(rt,q,{enumerable:!0,configurable:!0,writable:!0,value:Dt}):rt[q]=Dt;var K=(rt,q,Dt)=>CS(rt,typeof q!="symbol"?q+"":q,Dt),tf=(rt,q,Dt)=>q.has(rt)||tb("Cannot "+Dt);var c=(rt,q,Dt)=>(tf(rt,q,"read from private field"),Dt?Dt.call(rt):q.get(rt)),_=(rt,q,Dt)=>q.has(rt)?tb("Cannot add the same private member more than once"):q instanceof WeakSet?q.add(rt):q.set(rt,Dt),b=(rt,q,Dt,A)=>(tf(rt,q,"write to private field"),A?A.call(rt,Dt):q.set(rt,Dt),Dt),y=(rt,q,Dt)=>(tf(rt,q,"access private method"),Dt);var Fe=(rt,q,Dt,A)=>({set _(Ql){b(rt,q,Ql,Dt)},get _(){return c(rt,q,A)}});var Oi,jd,ef,wh,vn,pr,Es,mr,xh,Sh,yd,eb,Oe,sb,ib,Nd,nb,sf,Ch,br,vr,yn,rb,ob,ab,_d,Ho,Ah,be,Wo,Bd,ee,_n,Th,se,wd,hb,Xo,$e,$t,oe,zo,Pi,Vo,ks,wn,Go,yr,$s,Ms,_r,Eh,kh,Uo,Mh,Ks,xn,Yo,Sn,Qs,Sd,Cn,Oh,An,wr,Dh,Ph,ie,ft,Li,xr,Lh,Fh,Tn,Js,Fi,Rh,cs,N,Hd,nf,lb,cb,Wd,db,ub,gb,rf,fb,of,af,pb,Re,Yn,mb,bb,hf,vb,jl,lf,ne,Zs,Os,$o,ti,Ke,Ko,ei,He,Ri,Sr,si,En,Ds,Nl,Xd,Cr,Ps,kt,Qo,Ar,ae,Tr,kn,Ih,Er,Mn,jh,kr,Ii,ii,Jo,Zo,ds,Nh,Cd,et,cf,Bh,df,uf,yb,_b,gf,ff,pf,wb,mf,xb,Sb,Cb,bf,Bl,Mr,Or,re,Ad,Ab,Hh,ta,Wh,Dr,Pr,ni,ji,ve,Td,Lr,W,we,Ba,Ha,zd,Wa,Tb,vf,Xa,Hl,Wl,yf,Xl,On,_f,wf,Xh,zh,ea,us,Eb,kb,Mb,Vd,Fr,Vh,Gh,Uh,Yh,sa,Dn,pt,ia,na,qh,xf,Z0,Pn,We,$h,Kh,Rr,Ni,Qh,Jh,Ir,ra,oa,Ln,aa,Zh,ha,jr,tl,el,Nr,Br,sl,Fn,la,Bi,Ob,Db,Sf,Qe,Gd,Cf,Pb,Lb,kd,Rn,Hi,gs,za,Ud,Wi,Od,Dd,Hr,Wr,ca,Yd,da,qd,Xi,ri,ua,ga,oi,Xr,zl,Ls,il,Af,In,jn,zr,Gr,fa,pa,nl,Tf,Je,bo,Fb,Rb,ma,Pd,Ld,ba,Ur,Lt,zi,va,rl,ol,ya,Vi,Fs,Gi,al,Ui,hl,Yr,qr,mt,$d,Ef,Ib,jb,Nb,Bb,Kd,Qd,kf,ll,cl,dl,ul,gl,fl,pl,Mf,ml,$r,Kr,bl,Qr,Hb,Of,Rs,Ze,vl,Jr,ts,Vt,Wb,Xb,zb,Jd,Yi,Zd,tu,Vb,Df,Gb,es,Is,_a,wa,ai,it,Zr,to,yl,_l,xa,Sa,Nn,wl,Fd,Rd,Qt,Vl,Ub,Yb,qb,$b,Kb,Qb,Ca,eo,$i,xl,ss,Sl,Ht,Xe,Gl,Ul,Jb,Cl,Bn,js,Pe,Zb,eu,tv,ev,Pf,Al,Aa,Ns,so,Ta,Jt,Tl,Ea,El,kl,Hn,Bs,ka,Ml,bt,Lf,Ff,Rf,vo,sv,qn,Ma,Ol,Ki,io,Oa,fs,Dl,Pl,no,Hs,ye,Ve,Da,Qi,Zt,Pa,ps,Ll,Z,If,su,iv,nv,rv,jf,yo,ms,Va,ov,iu,Yl,av,hv,lv,cv,dv,ro,oo,hi,Ji,bs,ao,ho,lo,Zi,La,co,uo,Wn,j,uv,gv,fv,pv,Nf,mv,Bf,bv,vv,yv,_v,wv,_o,Hf,Wf,Xf,nu,ru,Ga,zf,ou,tn,xv,Vf,Sv,Cv,Gf,au,ql,Ot,he,Xn,en,zn,Fa,li,sn,ci,is,Ra,nt,$l,Kl,hu,Uf,Av,lu,Yf,cu,Tv,Ev,go,Ia,di,Vn,nn,ns,Gn,ja,Na,_e,rn,U,Un,le,kv,qf,$f,Kf,du,ui,Rl,Gt,on,Il,Qf,fo,Jf,Mv;var Dt=typeof document<"u"?document.currentScript:null;function A(a,t,e){return(t=function(s){var i=function(n,r){if(typeof n!="object"||!n)return n;var o=n[Symbol.toPrimitive];if(o!==void 0){var h=o.call(n,r||"default");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 Ql(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?Ql(Object(e),!0).forEach(function(s){A(a,s,e[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(e)):Ql(Object(e)).forEach(function(s){Object.defineProperty(a,s,Object.getOwnPropertyDescriptor(e,s))})}return a}function St(a,t){if(a==null)return{};var e,s,i=function(r,o){if(r==null)return{};var h={};for(var l in r)if({}.hasOwnProperty.call(r,l)){if(o.indexOf(l)>=0)continue;h[l]=r[l]}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 Zf{constructor(){A(this,"browserShadowBlurConstant",1),A(this,"DPI",96),A(this,"devicePixelRatio",typeof window<"u"?window.devicePixelRatio:1),A(this,"perfLimitSizeTotal",2097152),A(this,"maxCacheSideLimit",4096),A(this,"minCacheSideLimit",256),A(this,"disableStyleCopyPaste",!1),A(this,"enableGLFiltering",!0),A(this,"textureSize",4096),A(this,"forceGLPutImageData",!1),A(this,"cachesBoundsOfCurve",!1),A(this,"fontPaths",{}),A(this,"NUM_FRACTION_DIGITS",4)}}const at=new class extends Zf{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 Zf,e=(a==null?void 0:a.reduce((s,i)=>(s[i]=t[i],s),{}))||t;this.configure(e)}},pi=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 Xs extends Error{constructor(t,e){super("fabric: ".concat(t),e)}}class uu extends Xs{constructor(t){super("".concat(t," 'options.signal' is in 'aborted' state"))}}class Ov{}class Dv extends Ov{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(),pi("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const Pv={};let tp;const zs=()=>tp||(tp={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new Dv,dispose(){},copyPasteData:Pv}),wo=()=>zs().document,Jl=()=>zs().window,ep=()=>{var a;return Math.max((a=at.devicePixelRatio)!==null&&a!==void 0?a:Jl().devicePixelRatio,1)},Ua=new class{constructor(){A(this,"charWidthsCache",{}),A(this,"boundsOfCurveCache",{})}getFontCache(a){let{fontFamily:t,fontStyle:e,fontWeight:s}=a;t=t.toLowerCase(),this.charWidthsCache[t]||(this.charWidthsCache[t]={});const i=this.charWidthsCache[t],n="".concat(e.toLowerCase(),"_").concat((s+"").toLowerCase());return i[n]||(i[n]={}),i[n]}clearFontCache(a){(a=(a||"").toLowerCase())?this.charWidthsCache[a]&&delete this.charWidthsCache[a]:this.charWidthsCache={}}limitDimsByArea(a){const{perfLimitSizeTotal:t}=at,e=Math.sqrt(t*a);return[Math.floor(e),Math.floor(t/e)]}},gu="6.4.3";function $n(){}const hn=Math.PI/2,mi=2*Math.PI,fu=Math.PI/180,xe=Object.freeze([1,0,0,1,0,0]),pu=16,ln=.4477152502,J="center",lt="left",Ie="top",mu="bottom",Rt="right",Se="none",bu=/\r?\n/,sp="moving",Zl="scaling",ip="rotating",vu="rotate",np="skewing",Ya="resizing",Lv="modifyPoly",Fv="modifyPath",tc="changed",ec="scale",Ce="scaleX",Ge="scaleY",xo="skewX",So="skewY",It="fill",Ae="stroke",sc="modified",Co="json",yu="svg",X=new class{constructor(){this[Co]=new Map,this[yu]=new Map}has(a){return this[Co].has(a)}getClass(a){const t=this[Co].get(a);if(!t)throw new Xs("No class registered for ".concat(a));return t}setClass(a,t){t?this[Co].set(t,a):(this[Co].set(a.type,a),this[Co].set(a.type.toLowerCase(),a))}getSVGClass(a){return this[yu].get(a)}setSVGClass(a,t){this[yu].set(t??a.type.toLowerCase(),a)}},ic=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 Rv{constructor(){A(this,"__eventListeners",{})}on(t,e){if(this.__eventListeners||(this.__eventListeners={}),typeof t=="object")return Object.entries(t).forEach(s=>{let[i,n]=s;this.on(i,n)}),()=>this.off(t);if(e){const s=t;return this.__eventListeners[s]||(this.__eventListeners[s]=[]),this.__eventListeners[s].push(e),()=>this.off(s,e)}return()=>!1}once(t,e){if(typeof t=="object"){const s=[];return Object.entries(t).forEach(i=>{let[n,r]=i;s.push(this.once(n,r))}),()=>s.forEach(i=>i())}if(e){const s=this.on(t,function(){for(var i=arguments.length,n=new Array(i),r=0;r<i;r++)n[r]=arguments[r];e.call(this,...n),s()});return s}return()=>!1}_removeEventListener(t,e){if(this.__eventListeners[t])if(e){const s=this.__eventListeners[t],i=s.indexOf(e);i>-1&&s.splice(i,1)}else this.__eventListeners[t]=[]}off(t,e){if(this.__eventListeners)if(t===void 0)for(const s in this.__eventListeners)this._removeEventListener(s);else typeof t=="object"?Object.entries(t).forEach(s=>{let[i,n]=s;this._removeEventListener(i,n)}):this._removeEventListener(t,e)}fire(t,e){var s;if(!this.__eventListeners)return;const i=(s=this.__eventListeners[t])===null||s===void 0?void 0:s.concat();if(i)for(let n=0;n<i.length;n++)i[n].call(this,e||{})}}const Kn=(a,t)=>{const e=a.indexOf(t);return e!==-1&&a.splice(e,1),a},vs=a=>{if(a===0)return 1;switch(Math.abs(a)/hn){case 1:case 3:return 0;case 2:return-1}return Math.cos(a)},ys=a=>{if(a===0)return 0;const t=a/hn,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]:_u;const s=ys(t),i=vs(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 _u=new M(0,0),nc=a=>!!a&&Array.isArray(a._objects);function rp(a){class t extends a{constructor(){super(...arguments),A(this,"_objects",[])}_onObjectAdded(s){}_onObjectRemoved(s){}_onStackOrderChanged(s){}add(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];const r=this._objects.push(...i);return i.forEach(o=>this._onObjectAdded(o)),r}insertAt(s){for(var i=arguments.length,n=new Array(i>1?i-1:0),r=1;r<i;r++)n[r-1]=arguments[r];return this._objects.splice(s,0,...n),n.forEach(o=>this._onObjectAdded(o)),this._objects.length}remove(){const s=this._objects,i=[];for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return r.forEach(h=>{const l=s.indexOf(h);l!==-1&&(s.splice(l,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])&&(Kn(this._objects,s),this._objects.unshift(s),this._onStackOrderChanged(s),!0)}bringObjectToFront(s){return!(!s||s===this._objects[this._objects.length-1])&&(Kn(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 Kn(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 Kn(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}moveObjectTo(s,i){return s!==this._objects[i]&&(Kn(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 l=[],d=new M(i,n),u=d.add(new M(r,o));for(let g=this._objects.length-1;g>=0;g--){const f=this._objects[g];f.selectable&&f.visible&&(h&&f.intersectsWithRect(d,u)||f.isContainedWithinRect(d,u)||h&&f.containsPoint(d)||h&&f.containsPoint(u))&&l.push(f)}return l}}return t}class op extends Rv{_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 qa(a){return Jl().requestAnimationFrame(a)}function ap(a){return Jl().cancelAnimationFrame(a)}let Iv=0;const cn=()=>Iv++,jt=()=>{const a=wo().createElement("canvas");if(!a||a.getContext===void 0)throw new Xs("Failed to create `canvas` element");return a},hp=()=>wo().createElement("img"),wu=(a,t,e)=>a.toDataURL("image/".concat(t),e),Pt=a=>a*fu,dn=a=>a/fu,lp=a=>a.every((t,e)=>t===xe[e]),de=(a,t,e)=>new M(a).transform(t,e),je=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},Nt=(a,t,e)=>[a[0]*t[0]+a[2]*t[1],a[1]*t[0]+a[3]*t[1],a[0]*t[2]+a[2]*t[3],a[1]*t[2]+a[3]*t[3],e?0:a[0]*t[4]+a[2]*t[5]+a[4],e?0:a[1]*t[4]+a[3]*t[5]+a[5]],rc=(a,t)=>a.reduceRight((e,s)=>s&&e?Nt(s,e,t):s||e,void 0)||xe.concat(),cp=a=>{let[t,e]=a;return Math.atan2(e,t)},Qn=a=>{const t=cp(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:dn(t),scaleX:s,scaleY:i,skewX:dn(n),skewY:0,translateX:a[4]||0,translateY:a[5]||0}},Ao=function(a){return[1,0,0,1,a,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function To(){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=Pt(a),i=vs(s),n=ys(s);return[i,n,-n,i,t?t-(i*t-n*e):0,e?e-(n*t+i*e):0]}const oc=function(a){return[a,0,0,arguments.length>1&&arguments[1]!==void 0?arguments[1]:a,0,0]},dp=a=>Math.tan(Pt(a)),xu=a=>[1,0,dp(a),1,0,0],Su=a=>[1,dp(a),0,1,0,0],$a=a=>{let{scaleX:t=1,scaleY:e=1,flipX:s=!1,flipY:i=!1,skewX:n=0,skewY:r=0}=a,o=oc(s?-t:t,i?-e:e);return n&&(o=Nt(o,xu(n),!0)),r&&(o=Nt(o,Su(r),!0)),o},up=a=>{const{translateX:t=0,translateY:e=0,angle:s=0}=a;let i=Ao(t,e);s&&(i=Nt(i,To({angle:s})));const n=$a(a);return lp(n)||(i=Nt(i,n)),i},Ka=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 uu("loadImage"));const n=hp();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 Xs("Error loading ".concat(n.src)))},e&&(n.crossOrigin=e),n.src=a):o()})},Eo=function(a){let{signal:t,reviver:e=$n}=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=>X.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)})})},Qa=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&&X.has(o.type)?Eo([o],{signal:t}).then(h=>{let[l]=h;return i.push(l),l}):o),r=Object.keys(a);Promise.all(n).then(o=>o.reduce((h,l,d)=>(h[r[d]]=l,h),{})).then(e).catch(o=>{i.forEach(h=>{h.dispose&&h.dispose()}),s(o)}).finally(()=>{t&&t.removeEventListener("abort",s)})})},Jn=function(a){return(arguments.length>1&&arguments[1]!==void 0?arguments[1]:[]).reduce((t,e)=>(e in a&&(t[e]=a[e]),t),{})},Cu=(a,t)=>Object.keys(a).reduce((e,s)=>(t(a[s],s,a)&&(e[s]=a[s]),e),{}),gp={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"},Au=(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),fp=(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 l=i-n;switch(o=h>.5?l/(2-i-n):l/(i+n),i){case a:r=(t-e)/l+(t<e?6:0);break;case t:r=(e-a)/l+2;break;case e:r=(a-t)/l+4}r/=6}return[Math.round(360*r),Math.round(100*o),Math.round(100*h),s]},pp=function(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"1";return parseFloat(a)/(a.endsWith("%")?100:1)},ac=a=>Math.min(Math.round(a),255).toString(16).toUpperCase().padStart(2,"0"),mp=a=>{let[t,e,s,i=1]=a;const n=Math.round(.3*t+.59*e+.11*s);return[n,n,n,i]};class ut{constructor(t){if(A(this,"isUnrecognised",!1),t)if(t instanceof ut)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 in gp&&(t=gp[t]),t==="transparent"?[255,255,255,0]:ut.sourceFromHex(t)||ut.sourceFromRgb(t)||ut.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]=fp(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(s,"%)")}toHsla(){const[t,e,s,i]=fp(...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(ac(t)).concat(ac(e)).concat(ac(s)).concat(ac(Math.round(255*i)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(mp(this.getSource())),this}toBlackWhite(t){const[e,,,s]=mp(this.getSource()),i=e<(t||127)?0:255;return this.setSource([i,i,i,s]),this}overlayWith(t){t instanceof ut||(t=new ut(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 ut.fromRgba(t)}static fromRgba(t){return new ut(ut.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,pp(e[4])]}}static fromHsl(t){return ut.fromHsla(t)}static fromHsla(t){return new ut(ut.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=(ut.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 l=n<=.5?n*(i+1):n+i-n*i,d=2*n-l;r=Au(d,l,s+1/3),o=Au(d,l,s),h=Au(d,l,s-1/3)}return[Math.round(255*r),Math.round(255*o),Math.round(255*h),pp(e[4])]}static fromHex(t){return new ut(ut.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")?dn(s):e.includes("turn")?360*s:s}}const Ct=(a,t)=>parseFloat(Number(a).toFixed(t)),Te=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:pu;const e=/\D{0,2}$/.exec(a),s=parseFloat(a),i=at.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}},Tu=a=>{const[t,e]=a.trim().split(" "),[s,i]=(n=t)&&n!==Se?[n.slice(1,4),n.slice(5,8)]:n===Se?[n,n]:["Mid","Mid"];var n;return{meetOrSlice:e||"meet",alignX:s,alignY:i}},Ja=a=>"matrix("+a.map(t=>Ct(t,at.NUM_FRACTION_DIGITS)).join(" ")+")",Za=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 ut(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,'" '):"")},rs=a=>!!a&&a.toLive!==void 0,bp=a=>!!a&&typeof a.toObject=="function",vp=a=>!!a&&a.offsetX!==void 0&&"source"in a,yp=a=>!!a&&typeof a._renderText=="function",Zn=a=>!!a&&"multiSelectionStacking"in a;function _p(a){const t=a&&_s(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 _s=a=>a.ownerDocument||null,wp=a=>{var t;return((t=a.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null},xp=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))},Eu=(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 Sp(a){return a.onselectstart!==void 0&&(a.onselectstart=()=>!1),a.style.userSelect=Se,a}class Cp{constructor(t){A(this,"_originalCanvasStyle",void 0),A(this,"lower",void 0);const e=this.createLowerCanvas(t);this.lower={el:e,ctx:e.getContext("2d")}}createLowerCanvas(t){const e=(s=t)&&s.getContext!==void 0?t:t&&wo().getElementById(t)||jt();var s;if(e.hasAttribute("data-fabric"))throw new Xs("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;xp(s,i,t,e)}setCSSDimensions(t){Eu(this.lower.el,t)}calcOffset(){return function(t){var e;const s=t&&_s(t),i={left:0,top:0};if(!s)return i;const n=((e=wp(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=_p(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(){zs().dispose(this.lower.el),delete this.lower}}const jv={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...xe]};class th extends rp(op){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 th.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 Cp(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&&(pi("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?ep():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=de(t,je(i));i[0]=e,i[3]=e;const r=de(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=qa(()=>this.renderAndReset()))}calcViewportBoundaries(){const t=this.width,e=this.height,s=je(this.viewportTransform),i=de({x:0,y:0},s),n=de({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&&(ap(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=rs(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 de(this.getCenterPoint(),je(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:gu},Jn(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 rs(r)?r.excludeFromExport||(s.background=r.toObject(e)):r&&(s.background=r),rs(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(rt,U){typeof exports=="object"&&typeof module<"u"?U(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],U):(rt=typeof globalThis<"u"?globalThis:rt||self,U(rt["pdf-canvas"]={},rt.Vue))})(this,function(rt,U){"use strict";var IS=Object.defineProperty;var ib=rt=>{throw TypeError(rt)};var jS=(rt,U,Mt)=>U in rt?IS(rt,U,{enumerable:!0,configurable:!0,writable:!0,value:Mt}):rt[U]=Mt;var q=(rt,U,Mt)=>jS(rt,typeof U!="symbol"?U+"":U,Mt),ef=(rt,U,Mt)=>U.has(rt)||ib("Cannot "+Mt);var c=(rt,U,Mt)=>(ef(rt,U,"read from private field"),Mt?Mt.call(rt):U.get(rt)),w=(rt,U,Mt)=>U.has(rt)?ib("Cannot add the same private member more than once"):U instanceof WeakSet?U.add(rt):U.set(rt,Mt),b=(rt,U,Mt,A)=>(ef(rt,U,"write to private field"),A?A.call(rt,Mt):U.set(rt,Mt),Mt),y=(rt,U,Mt)=>(ef(rt,U,"access private method"),Mt);var Fe=(rt,U,Mt,A)=>({set _(Jl){b(rt,U,Jl,Mt)},get _(){return c(rt,U,A)}});var Oi,Nd,sf,xh,vn,pr,Es,mr,Sh,Ch,_d,nb,Oe,rb,ob,Bd,ab,nf,Ah,br,vr,yn,hb,lb,cb,wd,Ho,Th,be,Wo,Hd,te,_n,Eh,ee,xd,db,Xo,$e,Yt,re,zo,Pi,Vo,ks,wn,Go,yr,$s,Ms,_r,kh,Mh,Uo,Oh,Ks,xn,Yo,Sn,Qs,Cd,Cn,Dh,An,wr,Ph,Lh,se,ft,Li,xr,Fh,Rh,Tn,Js,Fi,Ih,cs,I,Wd,rf,ub,gb,Xd,fb,pb,mb,of,bb,af,hf,vb,Re,Yn,yb,_b,lf,wb,Nl,cf,ie,Zs,Os,$o,ti,Ke,Ko,ei,He,Ri,Sr,si,En,Ds,Bl,zd,Cr,Ps,Tt,Qo,Ar,oe,Tr,kn,jh,Er,Mn,Nh,kr,Ii,ii,Jo,Zo,ds,Bh,Ad,et,df,Hh,uf,gf,xb,Sb,ff,pf,mf,Cb,bf,Ab,Tb,Eb,vf,Hl,Mr,Or,ne,Td,kb,Wh,ta,Xh,Dr,Pr,ni,ji,ve,Ed,Lr,j,we,Ba,Ha,Vd,Wa,Mb,yf,Xa,Wl,Xl,_f,zl,On,wf,xf,zh,Vh,ea,us,Ob,Db,Pb,Gd,Fr,Gh,Uh,Yh,qh,sa,Dn,pt,ia,na,$h,Sf,sb,Pn,We,Kh,Qh,Rr,Ni,Jh,Zh,Ir,ra,oa,Ln,aa,tl,ha,jr,el,sl,Nr,Br,il,Fn,la,Bi,Lb,Fb,Cf,Qe,Ud,Af,Rb,Ib,Md,Rn,Hi,gs,za,Yd,Wi,Dd,Pd,Hr,Wr,ca,qd,da,$d,Xi,ri,ua,ga,oi,Xr,Vl,Ls,nl,Tf,In,jn,zr,Gr,fa,pa,rl,Ef,Je,bo,jb,Nb,ma,Ld,Fd,ba,Ur,Dt,zi,va,ol,al,ya,Vi,Fs,Gi,hl,Ui,ll,Yr,qr,mt,Kd,kf,Bb,Hb,Wb,Xb,Qd,Jd,Mf,cl,dl,ul,gl,fl,pl,ml,Of,bl,$r,Kr,vl,Qr,zb,Df,Rs,Ze,yl,Jr,ts,Wt,Vb,Gb,Ub,Zd,Yi,tu,eu,Yb,Pf,qb,es,Is,_a,wa,ai,it,Zr,to,_l,wl,xa,Sa,Nn,xl,Rd,Id,$t,Gl,$b,Kb,Qb,Jb,Zb,tv,Ca,eo,$i,Sl,ss,Cl,Nt,Xe,Ul,Yl,ev,Al,Bn,js,Pe,sv,su,iv,nv,Lf,Tl,Aa,Ns,so,Ta,Kt,El,Ea,kl,Ml,Hn,Bs,ka,Ol,bt,Ff,Rf,If,vo,rv,qn,Ma,Dl,Ki,io,Oa,fs,Pl,Ll,no,Hs,ye,Ve,Da,Qi,Qt,Pa,ps,Fl,J,jf,iu,ov,av,hv,Nf,yo,ms,Va,lv,nu,ql,cv,dv,uv,gv,fv,ro,oo,hi,Ji,bs,ao,ho,lo,Zi,La,co,uo,Wn,R,pv,mv,bv,vv,Bf,yv,Hf,_v,wv,xv,Sv,Cv,_o,Wf,Xf,zf,ru,ou,Ga,Vf,au,tn,Av,Gf,Tv,Ev,Uf,hu,$l,kt,ae,Xn,en,zn,Fa,li,sn,ci,is,Ra,nt,Kl,Ql,lu,Yf,kv,cu,qf,du,Mv,Ov,go,Ia,di,Vn,nn,ns,Gn,ja,Na,_e,rn,G,Un,he,Dv,$f,Kf,Qf,uu,ui,Il,Xt,on,jl,Jf,fo,Zf,Pv;var Mt=typeof document<"u"?document.currentScript:null;function A(a,t,e){return(t=function(s){var i=function(n,r){if(typeof n!="object"||!n)return n;var o=n[Symbol.toPrimitive];if(o!==void 0){var h=o.call(n,r||"default");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 Jl(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?Jl(Object(e),!0).forEach(function(s){A(a,s,e[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(e)):Jl(Object(e)).forEach(function(s){Object.defineProperty(a,s,Object.getOwnPropertyDescriptor(e,s))})}return a}function wt(a,t){if(a==null)return{};var e,s,i=function(r,o){if(r==null)return{};var h={};for(var l in r)if({}.hasOwnProperty.call(r,l)){if(o.indexOf(l)>=0)continue;h[l]=r[l]}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 tp{constructor(){A(this,"browserShadowBlurConstant",1),A(this,"DPI",96),A(this,"devicePixelRatio",typeof window<"u"?window.devicePixelRatio:1),A(this,"perfLimitSizeTotal",2097152),A(this,"maxCacheSideLimit",4096),A(this,"minCacheSideLimit",256),A(this,"disableStyleCopyPaste",!1),A(this,"enableGLFiltering",!0),A(this,"textureSize",4096),A(this,"forceGLPutImageData",!1),A(this,"cachesBoundsOfCurve",!1),A(this,"fontPaths",{}),A(this,"NUM_FRACTION_DIGITS",4)}}const at=new class extends tp{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 tp,e=(a==null?void 0:a.reduce((s,i)=>(s[i]=t[i],s),{}))||t;this.configure(e)}},pi=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 Xs extends Error{constructor(t,e){super("fabric: ".concat(t),e)}}class gu extends Xs{constructor(t){super("".concat(t," 'options.signal' is in 'aborted' state"))}}class Lv{}class Fv extends Lv{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(),pi("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const Rv={};let ep;const zs=()=>ep||(ep={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new Fv,dispose(){},copyPasteData:Rv}),wo=()=>zs().document,Zl=()=>zs().window,sp=()=>{var a;return Math.max((a=at.devicePixelRatio)!==null&&a!==void 0?a:Zl().devicePixelRatio,1)},Ua=new class{constructor(){A(this,"charWidthsCache",{}),A(this,"boundsOfCurveCache",{})}getFontCache(a){let{fontFamily:t,fontStyle:e,fontWeight:s}=a;t=t.toLowerCase(),this.charWidthsCache[t]||(this.charWidthsCache[t]={});const i=this.charWidthsCache[t],n="".concat(e.toLowerCase(),"_").concat((s+"").toLowerCase());return i[n]||(i[n]={}),i[n]}clearFontCache(a){(a=(a||"").toLowerCase())?this.charWidthsCache[a]&&delete this.charWidthsCache[a]:this.charWidthsCache={}}limitDimsByArea(a){const{perfLimitSizeTotal:t}=at,e=Math.sqrt(t*a);return[Math.floor(e),Math.floor(t/e)]}},fu="6.4.3";function $n(){}const hn=Math.PI/2,mi=2*Math.PI,pu=Math.PI/180,xe=Object.freeze([1,0,0,1,0,0]),mu=16,ln=.4477152502,Q="center",lt="left",Ie="top",bu="bottom",Lt="right",Se="none",vu=/\r?\n/,ip="moving",tc="scaling",np="rotating",yu="rotate",rp="skewing",Ya="resizing",Iv="modifyPoly",jv="modifyPath",ec="changed",sc="scale",Ce="scaleX",Ge="scaleY",xo="skewX",So="skewY",Ft="fill",Ae="stroke",ic="modified",Co="json",_u="svg",N=new class{constructor(){this[Co]=new Map,this[_u]=new Map}has(a){return this[Co].has(a)}getClass(a){const t=this[Co].get(a);if(!t)throw new Xs("No class registered for ".concat(a));return t}setClass(a,t){t?this[Co].set(t,a):(this[Co].set(a.type,a),this[Co].set(a.type.toLowerCase(),a))}getSVGClass(a){return this[_u].get(a)}setSVGClass(a,t){this[_u].set(t??a.type.toLowerCase(),a)}},nc=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 Nv{constructor(){A(this,"__eventListeners",{})}on(t,e){if(this.__eventListeners||(this.__eventListeners={}),typeof t=="object")return Object.entries(t).forEach(s=>{let[i,n]=s;this.on(i,n)}),()=>this.off(t);if(e){const s=t;return this.__eventListeners[s]||(this.__eventListeners[s]=[]),this.__eventListeners[s].push(e),()=>this.off(s,e)}return()=>!1}once(t,e){if(typeof t=="object"){const s=[];return Object.entries(t).forEach(i=>{let[n,r]=i;s.push(this.once(n,r))}),()=>s.forEach(i=>i())}if(e){const s=this.on(t,function(){for(var i=arguments.length,n=new Array(i),r=0;r<i;r++)n[r]=arguments[r];e.call(this,...n),s()});return s}return()=>!1}_removeEventListener(t,e){if(this.__eventListeners[t])if(e){const s=this.__eventListeners[t],i=s.indexOf(e);i>-1&&s.splice(i,1)}else this.__eventListeners[t]=[]}off(t,e){if(this.__eventListeners)if(t===void 0)for(const s in this.__eventListeners)this._removeEventListener(s);else typeof t=="object"?Object.entries(t).forEach(s=>{let[i,n]=s;this._removeEventListener(i,n)}):this._removeEventListener(t,e)}fire(t,e){var s;if(!this.__eventListeners)return;const i=(s=this.__eventListeners[t])===null||s===void 0?void 0:s.concat();if(i)for(let n=0;n<i.length;n++)i[n].call(this,e||{})}}const Kn=(a,t)=>{const e=a.indexOf(t);return e!==-1&&a.splice(e,1),a},vs=a=>{if(a===0)return 1;switch(Math.abs(a)/hn){case 1:case 3:return 0;case 2:return-1}return Math.cos(a)},ys=a=>{if(a===0)return 0;const t=a/hn,e=Math.sign(a);switch(t){case 1:return e;case 2:return 0;case 3:return-e}return Math.sin(a)};class D{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 D(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new D(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new D(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new D(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new D(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new D(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new D(this.x/t.x,this.y/t.y)}scalarDivide(t){return new D(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 D(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 D(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new D(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 D(this.x,this.y)}rotate(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:wu;const s=ys(t),i=vs(t),n=this.subtract(e);return new D(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 D(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 wu=new D(0,0),rc=a=>!!a&&Array.isArray(a._objects);function op(a){class t extends a{constructor(){super(...arguments),A(this,"_objects",[])}_onObjectAdded(s){}_onObjectRemoved(s){}_onStackOrderChanged(s){}add(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];const r=this._objects.push(...i);return i.forEach(o=>this._onObjectAdded(o)),r}insertAt(s){for(var i=arguments.length,n=new Array(i>1?i-1:0),r=1;r<i;r++)n[r-1]=arguments[r];return this._objects.splice(s,0,...n),n.forEach(o=>this._onObjectAdded(o)),this._objects.length}remove(){const s=this._objects,i=[];for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return r.forEach(h=>{const l=s.indexOf(h);l!==-1&&(s.splice(l,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])&&(Kn(this._objects,s),this._objects.unshift(s),this._onStackOrderChanged(s),!0)}bringObjectToFront(s){return!(!s||s===this._objects[this._objects.length-1])&&(Kn(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 Kn(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 Kn(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}moveObjectTo(s,i){return s!==this._objects[i]&&(Kn(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 l=[],d=new D(i,n),u=d.add(new D(r,o));for(let g=this._objects.length-1;g>=0;g--){const f=this._objects[g];f.selectable&&f.visible&&(h&&f.intersectsWithRect(d,u)||f.isContainedWithinRect(d,u)||h&&f.containsPoint(d)||h&&f.containsPoint(u))&&l.push(f)}return l}}return t}class ap extends Nv{_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 qa(a){return Zl().requestAnimationFrame(a)}function hp(a){return Zl().cancelAnimationFrame(a)}let Bv=0;const cn=()=>Bv++,Rt=()=>{const a=wo().createElement("canvas");if(!a||a.getContext===void 0)throw new Xs("Failed to create `canvas` element");return a},lp=()=>wo().createElement("img"),xu=(a,t,e)=>a.toDataURL("image/".concat(t),e),Ot=a=>a*pu,dn=a=>a/pu,cp=a=>a.every((t,e)=>t===xe[e]),de=(a,t,e)=>new D(a).transform(t,e),je=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 D(a[4],a[5]).transform(e,!0);return e[4]=-s,e[5]=-i,e},It=(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]],oc=(a,t)=>a.reduceRight((e,s)=>s&&e?It(s,e,t):s||e,void 0)||xe.concat(),dp=a=>{let[t,e]=a;return Math.atan2(e,t)},Qn=a=>{const t=dp(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:dn(t),scaleX:s,scaleY:i,skewX:dn(n),skewY:0,translateX:a[4]||0,translateY:a[5]||0}},Ao=function(a){return[1,0,0,1,a,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function To(){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=Ot(a),i=vs(s),n=ys(s);return[i,n,-n,i,t?t-(i*t-n*e):0,e?e-(n*t+i*e):0]}const ac=function(a){return[a,0,0,arguments.length>1&&arguments[1]!==void 0?arguments[1]:a,0,0]},up=a=>Math.tan(Ot(a)),Su=a=>[1,0,up(a),1,0,0],Cu=a=>[1,up(a),0,1,0,0],$a=a=>{let{scaleX:t=1,scaleY:e=1,flipX:s=!1,flipY:i=!1,skewX:n=0,skewY:r=0}=a,o=ac(s?-t:t,i?-e:e);return n&&(o=It(o,Su(n),!0)),r&&(o=It(o,Cu(r),!0)),o},gp=a=>{const{translateX:t=0,translateY:e=0,angle:s=0}=a;let i=Ao(t,e);s&&(i=It(i,To({angle:s})));const n=$a(a);return cp(n)||(i=It(i,n)),i},Ka=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 gu("loadImage"));const n=lp();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 Xs("Error loading ".concat(n.src)))},e&&(n.crossOrigin=e),n.src=a):o()})},Eo=function(a){let{signal:t,reviver:e=$n}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise((s,i)=>{const n=[];t&&t.addEventListener("abort",i,{once:!0}),Promise.all(a.map(r=>N.getClass(r.type).fromObject(r,{signal:t}).then(o=>(e(r,o),n.push(o),o)))).then(s).catch(r=>{n.forEach(o=>{o.dispose&&o.dispose()}),i(r)}).finally(()=>{t&&t.removeEventListener("abort",i)})})},Qa=function(a){let{signal:t}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise((e,s)=>{const i=[];t&&t.addEventListener("abort",s,{once:!0});const n=Object.values(a).map(o=>o&&o.type&&N.has(o.type)?Eo([o],{signal:t}).then(h=>{let[l]=h;return i.push(l),l}):o),r=Object.keys(a);Promise.all(n).then(o=>o.reduce((h,l,d)=>(h[r[d]]=l,h),{})).then(e).catch(o=>{i.forEach(h=>{h.dispose&&h.dispose()}),s(o)}).finally(()=>{t&&t.removeEventListener("abort",s)})})},Jn=function(a){return(arguments.length>1&&arguments[1]!==void 0?arguments[1]:[]).reduce((t,e)=>(e in a&&(t[e]=a[e]),t),{})},Au=(a,t)=>Object.keys(a).reduce((e,s)=>(t(a[s],s,a)&&(e[s]=a[s]),e),{}),fp={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"},Tu=(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),pp=(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 l=i-n;switch(o=h>.5?l/(2-i-n):l/(i+n),i){case a:r=(t-e)/l+(t<e?6:0);break;case t:r=(e-a)/l+2;break;case e:r=(a-t)/l+4}r/=6}return[Math.round(360*r),Math.round(100*o),Math.round(100*h),s]},mp=function(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"1";return parseFloat(a)/(a.endsWith("%")?100:1)},hc=a=>Math.min(Math.round(a),255).toString(16).toUpperCase().padStart(2,"0"),bp=a=>{let[t,e,s,i=1]=a;const n=Math.round(.3*t+.59*e+.11*s);return[n,n,n,i]};class ut{constructor(t){if(A(this,"isUnrecognised",!1),t)if(t instanceof ut)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 in fp&&(t=fp[t]),t==="transparent"?[255,255,255,0]:ut.sourceFromHex(t)||ut.sourceFromRgb(t)||ut.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]=pp(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(s,"%)")}toHsla(){const[t,e,s,i]=pp(...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(hc(t)).concat(hc(e)).concat(hc(s)).concat(hc(Math.round(255*i)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(bp(this.getSource())),this}toBlackWhite(t){const[e,,,s]=bp(this.getSource()),i=e<(t||127)?0:255;return this.setSource([i,i,i,s]),this}overlayWith(t){t instanceof ut||(t=new ut(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 ut.fromRgba(t)}static fromRgba(t){return new ut(ut.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,mp(e[4])]}}static fromHsl(t){return ut.fromHsla(t)}static fromHsla(t){return new ut(ut.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=(ut.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 l=n<=.5?n*(i+1):n+i-n*i,d=2*n-l;r=Tu(d,l,s+1/3),o=Tu(d,l,s),h=Tu(d,l,s-1/3)}return[Math.round(255*r),Math.round(255*o),Math.round(255*h),mp(e[4])]}static fromHex(t){return new ut(ut.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")?dn(s):e.includes("turn")?360*s:s}}const xt=(a,t)=>parseFloat(Number(a).toFixed(t)),Te=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:mu;const e=/\D{0,2}$/.exec(a),s=parseFloat(a),i=at.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}},Eu=a=>{const[t,e]=a.trim().split(" "),[s,i]=(n=t)&&n!==Se?[n.slice(1,4),n.slice(5,8)]:n===Se?[n,n]:["Mid","Mid"];var n;return{meetOrSlice:e||"meet",alignX:s,alignY:i}},Ja=a=>"matrix("+a.map(t=>xt(t,at.NUM_FRACTION_DIGITS)).join(" ")+")",Za=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 ut(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,'" '):"")},rs=a=>!!a&&a.toLive!==void 0,vp=a=>!!a&&typeof a.toObject=="function",yp=a=>!!a&&a.offsetX!==void 0&&"source"in a,_p=a=>!!a&&typeof a._renderText=="function",Zn=a=>!!a&&"multiSelectionStacking"in a;function wp(a){const t=a&&_s(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 _s=a=>a.ownerDocument||null,xp=a=>{var t;return((t=a.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null},Sp=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))},ku=(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 Cp(a){return a.onselectstart!==void 0&&(a.onselectstart=()=>!1),a.style.userSelect=Se,a}class Ap{constructor(t){A(this,"_originalCanvasStyle",void 0),A(this,"lower",void 0);const e=this.createLowerCanvas(t);this.lower={el:e,ctx:e.getContext("2d")}}createLowerCanvas(t){const e=(s=t)&&s.getContext!==void 0?t:t&&wo().getElementById(t)||Rt();var s;if(e.hasAttribute("data-fabric"))throw new Xs("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;Sp(s,i,t,e)}setCSSDimensions(t){ku(this.lower.el,t)}calcOffset(){return function(t){var e;const s=t&&_s(t),i={left:0,top:0};if(!s)return i;const n=((e=xp(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=wp(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(){zs().dispose(this.lower.el),delete this.lower}}const Hv={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...xe]};class th extends op(ap){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 th.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 Ap(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&&(pi("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?sp():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=de(t,je(i));i[0]=e,i[3]=e;const r=de(n,i);i[4]+=s.x-r.x,i[5]+=s.y-r.y,this.setViewportTransform(i)}setZoom(t){this.zoomToPoint(new D(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 D(-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=qa(()=>this.renderAndReset()))}calcViewportBoundaries(){const t=this.width,e=this.height,s=je(this.viewportTransform),i=de({x:0,y:0},s),n=de({x:t,y:e},s),r=i.min(n),o=i.max(n);return this.vptCoords={tl:r,tr:new D(o.x,r.y),bl:new D(r.x,o.y),br:o}}cancelRequestedRender(){this.nextRenderHandle&&(hp(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=rs(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 D(this.width/2,this.height/2)}centerObjectH(t){return this._centerObject(t,new D(this.getCenterPoint().x,t.getCenterPoint().y))}centerObjectV(t){return this._centerObject(t,new D(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 D(this.getVpCenter().x,t.getCenterPoint().y))}viewportCenterObjectV(t){return this._centerObject(t,new D(t.getCenterPoint().x,this.getVpCenter().y))}getVpCenter(){return de(this.getCenterPoint(),je(this.viewportTransform))}_centerObject(t,e){t.setXY(e,Q,Q),t.setCoords(),this.renderOnAddRemove&&this.requestRenderAll()}toDatalessJSON(t){return this.toDatalessObject(t)}toObject(t){return this._toObjectMethod("toObject",t)}toJSON(){return this.toObject()}toDatalessObject(t){return this._toObjectMethod("toDatalessObject",t)}_toObjectMethod(t,e){const s=this.clipPath,i=s&&!s.excludeFromExport?this._toObject(s,t,e):null;return T(T(T({version:fu},Jn(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 rs(r)?r.excludeFromExport||(s.background=r.toObject(e)):r&&(s.background=r),rs(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=at.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(Ct(-h[4]/h[0],n)," ").concat(Ct(-h[5]/h[3],n)," ").concat(Ct(this.width/h[0],n)," ").concat(Ct(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 ",gu,`</desc>
7
+ `)}_setSVGHeader(t,e){const s=e.width||"".concat(this.width),i=e.height||"".concat(this.height),n=at.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(xt(-h[4]/h[0],n)," ").concat(xt(-h[5]/h[3],n)," ").concat(xt(this.width/h[0],n)," ").concat(xt(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 ",fu,`</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(cn()),'<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(rs(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?Ja(i):""})}}).join("")}createSVGFontFacesMarkup(){const t=[],e={},s=at.fontPaths;this._objects.forEach(function n(r){t.push(r),nc(r)&&r._objects.forEach(n)}),t.forEach(n=>{if(!yp(n))return;const{styles:r,fontFamily:o}=n;!e[o]&&s[o]&&(e[o]=!0,r&&Object.values(r).forEach(h=>{Object.values(h).forEach(l=>{let{fontFamily:d=""}=l;!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(rs(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?Ja(i):""})}}).join("")}createSVGFontFacesMarkup(){const t=[],e={},s=at.fontPaths;this._objects.forEach(function n(r){t.push(r),rc(r)&&r._objects.forEach(n)}),t.forEach(n=>{if(!_p(n))return;const{styles:r,fontFamily:o}=n;!e[o]&&s[o]&&(e[o]=!0,r&&Object.values(r).forEach(h=>{Object.values(h).forEach(l=>{let{fontFamily:d=""}=l;!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(rs(s)){const i=s.repeat||"",n=this.width,r=this.height,o=this["".concat(e,"Vpt")]?Ja(je(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"||!vp(s)?n:s.source.width,'" height="').concat(i!=="repeat-x"&&i!=="no-repeat"||!vp(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(rs(s)){const i=s.repeat||"",n=this.width,r=this.height,o=this["".concat(e,"Vpt")]?Ja(je(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"||!yp(s)?n:s.source.width,'" height="').concat(i!=="repeat-x"&&i!=="no-repeat"||!yp(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 Xs("`json` is undefined"));const i=typeof t=="string"?JSON.parse(t):t,{objects:n=[],backgroundImage:r,background:o,overlayImage:h,overlay:l,clipPath:d}=i,u=this.renderOnAddRemove;return this.renderOnAddRemove=!1,Promise.all([Eo(n,{reviver:e,signal:s}),Qa({backgroundImage:r,backgroundColor:o,overlayImage:h,overlayColor:l,clipPath:d},{signal:s})]).then(g=>{let[f,p]=g;return this.clear(),this.add(...f),this.set(i),this.set(p),this.renderOnAddRemove=u,this})}clone(t){const e=this.toObject(t);return this.cloneWithoutData().loadFromJSON(e)}cloneWithoutData(){const t=jt();return t.width=this.width,t.height=this.height,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 wu(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,l=this.getZoom(),d=this.width,u=this.height,g=this.skipControlsDrawing,f=l*t,p=this.viewportTransform,m=[f,0,0,f,(p[4]-(i||0))*t,(p[5]-(n||0))*t],w=this.enableRetinaScaling,v=jt(),x=r?this._objects.filter(S=>r(S)):this._objects;return v.width=o,v.height=h,this.enableRetinaScaling=!1,this.viewportTransform=m,this.width=o,this.height=h,this.skipControlsDrawing=!0,this.calcViewportBoundaries(),this.renderCanvas(v.getContext("2d"),x),this.viewportTransform=p,this.width=d,this.height=u,this.calcViewportBoundaries(),this.enableRetinaScaling=w,this.skipControlsDrawing=g,v}dispose(){return!this.disposed&&this.elements.cleanupDOM({width:this.width,height:this.height}),ic.cancelByCanvas(this),this.disposed=!0,new Promise((t,e)=>{const s=()=>{this.destroy(),t(!0)};s.kill=e,this.__cleanupTask&&this.__cleanupTask.kill("aborted"),this.destroyed?t(!1):this.nextRenderHandle?this.__cleanupTask=s:s()})}destroy(){this.destroyed=!0,this.cancelRequestedRender(),this.forEachObject(t=>t.dispose()),this._objects=[],this.backgroundImage&&this.backgroundImage.dispose(),this.backgroundImage=void 0,this.overlayImage&&this.overlayImage.dispose(),this.overlayImage=void 0,this.elements.dispose()}toString(){return"#<Canvas (".concat(this.complexity(),"): { objects: ").concat(this._objects.length," }>")}}A(th,"ownDefaults",jv);const Nv=["touchstart","touchmove","touchend"],Ap=a=>{const t=_p(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)},hc=a=>Nv.includes(a.type)||a.pointerType==="touch",ku=a=>{a.preventDefault(),a.stopPropagation()},Vs=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}},Bv=["translateX","translateY","scaleX","scaleY"],Tp=(a,t)=>ko(a,Nt(t,a.calcOwnMatrix())),ko=(a,t)=>{const e=Qn(t),{translateX:s,translateY:i,scaleX:n,scaleY:r}=e,o=St(e,Bv),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)},Ep=a=>{a.scaleX=1,a.scaleY=1,a.skewX=0,a.skewY=0,a.flipX=!1,a.flipY=!1,a.rotate(0)},Mu=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}),lc=(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=Vs(n);return new M(r.width,r.height)},eh=function(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:xe;return Nt(je(arguments.length>1&&arguments[1]!==void 0?arguments[1]:xe),a)},tr=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:xe,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:xe;return a.transform(eh(t,e))},kp=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:xe,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:xe;return a.transform(eh(t,e),!0)},Ou=(a,t,e)=>{const s=eh(t,e);return ko(a,Nt(s,a.calcOwnMatrix())),s},Mp=(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)},Hv={left:-.5,top:-.5,center:0,bottom:.5,right:.5},Xt=a=>typeof a=="string"?Hv[a]:a-.5,cc="not-allowed";function Op(a){return Xt(a.originX)===Xt(J)&&Xt(a.originY)===Xt(J)}function Dp(a){return .5-Xt(a)}const ws=(a,t)=>a[t],Pp=(a,t,e,s)=>({e:a,transform:t,pointer:new M(e,s)});function Lp(a,t){const e=a.getTotalAngle()+dn(Math.atan2(t.y,t.x))+360;return Math.round(e%360/45)}function Du(a,t,e,s,i){var n;let{target:r,corner:o}=a;const h=r.controls[o],l=((n=r.canvas)===null||n===void 0?void 0:n.getZoom())||1,d=r.padding/l,u=function(g,f,p,m){const w=g.getRelativeCenterPoint(),v=p!==void 0&&m!==void 0?g.translateToGivenOrigin(w,J,J,p,m):new M(g.left,g.top);return(g.angle?f.rotate(-Pt(g.angle),w):f).subtract(v)}(r,new M(s,i),t,e);return u.x>=d&&(u.x-=d),u.x<=-d&&(u.x+=d),u.y>=d&&(u.y-=d),u.y<=d&&(u.y+=d),u.x-=h.offsetX,u.y-=h.offsetY,u}const Wv=(a,t,e,s)=>{const{target:i,offsetX:n,offsetY:r}=t,o=e-n,h=s-r,l=!ws(i,"lockMovementX")&&i.left!==o,d=!ws(i,"lockMovementY")&&i.top!==h;return l&&i.set(lt,o),d&&i.set(Ie,h),(l||d)&&Mp(sp,Pp(a,t,e,s)),l||d};class Fp{getSvgStyles(t){const e=this.fillRule?this.fillRule:"nonzero",s=this.strokeWidth?this.strokeWidth:"0",i=this.strokeDashArray?this.strokeDashArray.join(" "):Se,n=this.strokeDashOffset?this.strokeDashOffset:"0",r=this.strokeLineCap?this.strokeLineCap:"butt",o=this.strokeLineJoin?this.strokeLineJoin:"miter",h=this.strokeMiterLimit?this.strokeMiterLimit:"4",l=this.opacity!==void 0?this.opacity:"1",d=this.visible?"":" visibility: hidden;",u=t?"":this.getSvgFilter(),g=Za(It,this.fill);return[Za(Ae,this.stroke),"stroke-width: ",s,"; ","stroke-dasharray: ",i,"; ","stroke-linecap: ",r,"; ","stroke-dashoffset: ",n,"; ","stroke-linejoin: ",o,"; ","stroke-miterlimit: ",h,"; ",g,"fill-rule: ",e,"; ","opacity: ",l,";",u,d].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(Ja(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,l=this.strokeUniform?'vector-effect="non-scaling-stroke" ':"",d=h&&h.absolutePositioned,u=this.stroke,g=this.fill,f=this.shadow,p=[],m=t.indexOf("COMMON_PARTS");let w;h&&(h.clipPathId="CLIPPATH_".concat(cn()),w='<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 Xs("`json` is undefined"));const i=typeof t=="string"?JSON.parse(t):t,{objects:n=[],backgroundImage:r,background:o,overlayImage:h,overlay:l,clipPath:d}=i,u=this.renderOnAddRemove;return this.renderOnAddRemove=!1,Promise.all([Eo(n,{reviver:e,signal:s}),Qa({backgroundImage:r,backgroundColor:o,overlayImage:h,overlayColor:l,clipPath:d},{signal:s})]).then(g=>{let[f,p]=g;return this.clear(),this.add(...f),this.set(i),this.set(p),this.renderOnAddRemove=u,this})}clone(t){const e=this.toObject(t);return this.cloneWithoutData().loadFromJSON(e)}cloneWithoutData(){const t=Rt();return t.width=this.width,t.height=this.height,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 xu(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,l=this.getZoom(),d=this.width,u=this.height,g=this.skipControlsDrawing,f=l*t,p=this.viewportTransform,m=[f,0,0,f,(p[4]-(i||0))*t,(p[5]-(n||0))*t],_=this.enableRetinaScaling,v=Rt(),x=r?this._objects.filter(S=>r(S)):this._objects;return v.width=o,v.height=h,this.enableRetinaScaling=!1,this.viewportTransform=m,this.width=o,this.height=h,this.skipControlsDrawing=!0,this.calcViewportBoundaries(),this.renderCanvas(v.getContext("2d"),x),this.viewportTransform=p,this.width=d,this.height=u,this.calcViewportBoundaries(),this.enableRetinaScaling=_,this.skipControlsDrawing=g,v}dispose(){return!this.disposed&&this.elements.cleanupDOM({width:this.width,height:this.height}),nc.cancelByCanvas(this),this.disposed=!0,new Promise((t,e)=>{const s=()=>{this.destroy(),t(!0)};s.kill=e,this.__cleanupTask&&this.__cleanupTask.kill("aborted"),this.destroyed?t(!1):this.nextRenderHandle?this.__cleanupTask=s:s()})}destroy(){this.destroyed=!0,this.cancelRequestedRender(),this.forEachObject(t=>t.dispose()),this._objects=[],this.backgroundImage&&this.backgroundImage.dispose(),this.backgroundImage=void 0,this.overlayImage&&this.overlayImage.dispose(),this.overlayImage=void 0,this.elements.dispose()}toString(){return"#<Canvas (".concat(this.complexity(),"): { objects: ").concat(this._objects.length," }>")}}A(th,"ownDefaults",Hv);const Wv=["touchstart","touchmove","touchend"],Tp=a=>{const t=wp(a.target),e=function(s){const i=s.changedTouches;return i&&i[0]?i[0]:s}(a);return new D(e.clientX+t.left,e.clientY+t.top)},lc=a=>Wv.includes(a.type)||a.pointerType==="touch",Mu=a=>{a.preventDefault(),a.stopPropagation()},Vs=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}},Xv=["translateX","translateY","scaleX","scaleY"],Ep=(a,t)=>ko(a,It(t,a.calcOwnMatrix())),ko=(a,t)=>{const e=Qn(t),{translateX:s,translateY:i,scaleX:n,scaleY:r}=e,o=wt(e,Xv),h=new D(s,i);a.flipX=!1,a.flipY=!1,Object.assign(a,o),a.set({scaleX:n,scaleY:r}),a.setPositionByOrigin(h,Q,Q)},kp=a=>{a.scaleX=1,a.scaleY=1,a.skewX=0,a.skewY=0,a.flipX=!1,a.flipY=!1,a.rotate(0)},Ou=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}),cc=(a,t,e)=>{const s=a/2,i=t/2,n=[new D(-s,-i),new D(s,-i),new D(-s,i),new D(s,i)].map(o=>o.transform(e)),r=Vs(n);return new D(r.width,r.height)},eh=function(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:xe;return It(je(arguments.length>1&&arguments[1]!==void 0?arguments[1]:xe),a)},tr=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:xe,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:xe;return a.transform(eh(t,e))},Mp=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:xe,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:xe;return a.transform(eh(t,e),!0)},Du=(a,t,e)=>{const s=eh(t,e);return ko(a,It(s,a.calcOwnMatrix())),s},Op=(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)},zv={left:-.5,top:-.5,center:0,bottom:.5,right:.5},Bt=a=>typeof a=="string"?zv[a]:a-.5,dc="not-allowed";function Dp(a){return Bt(a.originX)===Bt(Q)&&Bt(a.originY)===Bt(Q)}function Pp(a){return .5-Bt(a)}const ws=(a,t)=>a[t],Lp=(a,t,e,s)=>({e:a,transform:t,pointer:new D(e,s)});function Fp(a,t){const e=a.getTotalAngle()+dn(Math.atan2(t.y,t.x))+360;return Math.round(e%360/45)}function Pu(a,t,e,s,i){var n;let{target:r,corner:o}=a;const h=r.controls[o],l=((n=r.canvas)===null||n===void 0?void 0:n.getZoom())||1,d=r.padding/l,u=function(g,f,p,m){const _=g.getRelativeCenterPoint(),v=p!==void 0&&m!==void 0?g.translateToGivenOrigin(_,Q,Q,p,m):new D(g.left,g.top);return(g.angle?f.rotate(-Ot(g.angle),_):f).subtract(v)}(r,new D(s,i),t,e);return u.x>=d&&(u.x-=d),u.x<=-d&&(u.x+=d),u.y>=d&&(u.y-=d),u.y<=d&&(u.y+=d),u.x-=h.offsetX,u.y-=h.offsetY,u}const Vv=(a,t,e,s)=>{const{target:i,offsetX:n,offsetY:r}=t,o=e-n,h=s-r,l=!ws(i,"lockMovementX")&&i.left!==o,d=!ws(i,"lockMovementY")&&i.top!==h;return l&&i.set(lt,o),d&&i.set(Ie,h),(l||d)&&Op(ip,Lp(a,t,e,s)),l||d};class Rp{getSvgStyles(t){const e=this.fillRule?this.fillRule:"nonzero",s=this.strokeWidth?this.strokeWidth:"0",i=this.strokeDashArray?this.strokeDashArray.join(" "):Se,n=this.strokeDashOffset?this.strokeDashOffset:"0",r=this.strokeLineCap?this.strokeLineCap:"butt",o=this.strokeLineJoin?this.strokeLineJoin:"miter",h=this.strokeMiterLimit?this.strokeMiterLimit:"4",l=this.opacity!==void 0?this.opacity:"1",d=this.visible?"":" visibility: hidden;",u=t?"":this.getSvgFilter(),g=Za(Ft,this.fill);return[Za(Ae,this.stroke),"stroke-width: ",s,"; ","stroke-dasharray: ",i,"; ","stroke-linecap: ",r,"; ","stroke-dashoffset: ",n,"; ","stroke-linejoin: ",o,"; ","stroke-miterlimit: ",h,"; ",g,"fill-rule: ",e,"; ","opacity: ",l,";",u,d].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(Ja(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,l=this.strokeUniform?'vector-effect="non-scaling-stroke" ':"",d=h&&h.absolutePositioned,u=this.stroke,g=this.fill,f=this.shadow,p=[],m=t.indexOf("COMMON_PARTS");let _;h&&(h.clipPathId="CLIPPATH_".concat(cn()),_='<clipPath id="'.concat(h.clipPathId,`" >
22
22
  `).concat(h.toClipPathSVG(s),`</clipPath>
23
23
  `)),d&&p.push("<g ",o,this.getSvgCommons(),` >
24
24
  `),p.push("<g ",this.getSvgTransform(!1),d?"":o+this.getSvgCommons(),` >
25
- `);const v=[r,l,e?"":this.addPaintOrder()," ",n?'transform="'.concat(n,'" '):""].join("");return t[m]=v,rs(g)&&p.push(g.toSVG(this)),rs(u)&&p.push(u.toSVG(this)),f&&p.push(f.toSVG(this)),h&&p.push(w),p.push(t.join("")),p.push(`</g>
25
+ `);const v=[r,l,e?"":this.addPaintOrder()," ",n?'transform="'.concat(n,'" '):""].join("");return t[m]=v,rs(g)&&p.push(g.toSVG(this)),rs(u)&&p.push(u.toSVG(this)),f&&p.push(f.toSVG(this)),h&&p.push(_),p.push(t.join("")),p.push(`</g>
26
26
  `),d&&p.push(`</g>
27
- `),s?s(p.join("")):p.join("")}addPaintOrder(){return this.paintFirst!==It?' paint-order="'.concat(this.paintFirst,'" '):""}}function dc(a){return new RegExp("^("+a.join("|")+")\\b","i")}var Rp;const xs=String.raw(Rp||(Rp=an(["(?:[-+]?(?:d*.d+|d+.?)(?:[eE][-+]?d+)?)"],["(?:[-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?)"]))),Pu="http://www.w3.org/2000/svg",Xv=new RegExp("(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*("+xs+"(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|"+xs+"))?\\s+(.*)"),zv={cx:lt,x:lt,r:"radius",cy:Ie,y:Ie,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"},Lu="font-size",Fu="clip-path",Vv=dc(["path","circle","polygon","polyline","ellipse","rect","line","image","text"]),Gv=dc(["symbol","image","marker","pattern","view","svg"]),Ip=dc(["symbol","g","a","svg","clipPath","defs"]),jp=new RegExp("^\\s*("+xs+"+)\\s*,?\\s*("+xs+"+)\\s*,?\\s*("+xs+"+)\\s*,?\\s*("+xs+"+)\\s*$"),Uv=new M(1,0),Np=new M,Ru=(a,t)=>a.rotate(t),uc=(a,t)=>new M(t).subtract(a),gc=a=>a.distanceFrom(Np),fc=(a,t)=>Math.atan2(Mo(a,t),Hp(a,t)),Bp=a=>fc(Uv,a),pc=a=>a.eq(Np)?a:a.scalarDivide(gc(a)),Iu=function(a){let t=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];return pc(new M(-a.y,a.x).scalarMultiply(t?1:-1))},Mo=(a,t)=>a.x*t.y-a.y*t.x,Hp=(a,t)=>a.x*t.x+a.y*t.y,ju=(a,t,e)=>{if(a.eq(t)||a.eq(e))return!0;const s=Mo(t,e),i=Mo(t,a),n=Mo(e,a);return s>=0?i>=0&&n<=0:!(i<=0&&n>=0)},Wp="(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?",Xp=new RegExp("(?:\\s|^)"+Wp+Wp+"("+xs+"?(?:px)?)?(?:\\s?|$)(?:$|\\s)");class bi{constructor(t){const e=typeof t=="string"?bi.parseShadow(t):t;Object.assign(this,bi.ownDefaults,e),this.id=cn()}static parseShadow(t){const e=t.trim(),[,s=0,i=0,n=0]=(Xp.exec(e)||[]).map(r=>parseFloat(r)||0);return{color:(e.replace(Xp,"")||"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=Ru(new M(this.offsetX,this.offsetY),Pt(-t.angle)),s=new ut(this.color);let i=40,n=40;return t.width&&t.height&&(i=100*Ct((Math.abs(e.x)+this.blur)/t.width,at.NUM_FRACTION_DIGITS)+20,n=100*Ct((Math.abs(e.y)+this.blur)/t.height,at.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(Ct(this.blur?this.blur/2:0,at.NUM_FRACTION_DIGITS),`"></feGaussianBlur>
29
- <feOffset dx="`).concat(Ct(e.x,at.NUM_FRACTION_DIGITS),'" dy="').concat(Ct(e.y,at.NUM_FRACTION_DIGITS),`" result="oBlur" ></feOffset>
27
+ `),s?s(p.join("")):p.join("")}addPaintOrder(){return this.paintFirst!==Ft?' paint-order="'.concat(this.paintFirst,'" '):""}}function uc(a){return new RegExp("^("+a.join("|")+")\\b","i")}var Ip;const xs=String.raw(Ip||(Ip=an(["(?:[-+]?(?:d*.d+|d+.?)(?:[eE][-+]?d+)?)"],["(?:[-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?)"]))),Lu="http://www.w3.org/2000/svg",Gv=new RegExp("(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*("+xs+"(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|"+xs+"))?\\s+(.*)"),Uv={cx:lt,x:lt,r:"radius",cy:Ie,y:Ie,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"},Fu="font-size",Ru="clip-path",Yv=uc(["path","circle","polygon","polyline","ellipse","rect","line","image","text"]),qv=uc(["symbol","image","marker","pattern","view","svg"]),jp=uc(["symbol","g","a","svg","clipPath","defs"]),Np=new RegExp("^\\s*("+xs+"+)\\s*,?\\s*("+xs+"+)\\s*,?\\s*("+xs+"+)\\s*,?\\s*("+xs+"+)\\s*$"),$v=new D(1,0),Bp=new D,Iu=(a,t)=>a.rotate(t),gc=(a,t)=>new D(t).subtract(a),fc=a=>a.distanceFrom(Bp),pc=(a,t)=>Math.atan2(Mo(a,t),Wp(a,t)),Hp=a=>pc($v,a),mc=a=>a.eq(Bp)?a:a.scalarDivide(fc(a)),ju=function(a){let t=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];return mc(new D(-a.y,a.x).scalarMultiply(t?1:-1))},Mo=(a,t)=>a.x*t.y-a.y*t.x,Wp=(a,t)=>a.x*t.x+a.y*t.y,Nu=(a,t,e)=>{if(a.eq(t)||a.eq(e))return!0;const s=Mo(t,e),i=Mo(t,a),n=Mo(e,a);return s>=0?i>=0&&n<=0:!(i<=0&&n>=0)},Xp="(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?",zp=new RegExp("(?:\\s|^)"+Xp+Xp+"("+xs+"?(?:px)?)?(?:\\s?|$)(?:$|\\s)");class bi{constructor(t){const e=typeof t=="string"?bi.parseShadow(t):t;Object.assign(this,bi.ownDefaults,e),this.id=cn()}static parseShadow(t){const e=t.trim(),[,s=0,i=0,n=0]=(zp.exec(e)||[]).map(r=>parseFloat(r)||0);return{color:(e.replace(zp,"")||"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=Iu(new D(this.offsetX,this.offsetY),Ot(-t.angle)),s=new ut(this.color);let i=40,n=40;return t.width&&t.height&&(i=100*xt((Math.abs(e.x)+this.blur)/t.width,at.NUM_FRACTION_DIGITS)+20,n=100*xt((Math.abs(e.y)+this.blur)/t.height,at.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(xt(this.blur?this.blur/2:0,at.NUM_FRACTION_DIGITS),`"></feGaussianBlur>
29
+ <feOffset dx="`).concat(xt(e.x,at.NUM_FRACTION_DIGITS),'" dy="').concat(xt(e.y,at.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=bi.ownDefaults;return this.includeDefaultValues?t:Cu(t,(s,i)=>s!==e[i])}static async fromObject(t){return new this(t)}}A(bi,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),A(bi,"type","shadow"),X.setClass(bi,"shadow");const er=(a,t,e)=>Math.max(a,Math.min(t,e)),Yv=[Ie,lt,Ce,Ge,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",xo,So],vi=[It,Ae,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],qv={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:lt,originY:Ie,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:It,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},Nu=(a,t,e,s)=>(a<Math.abs(t)?(a=t,s=e/4):s=t===0&&a===0?e/mi*Math.asin(1):e/mi*Math.asin(t/a),{a,c:t,p:e,s}),zp=(a,t,e,s,i)=>a*Math.pow(2,10*(s-=1))*Math.sin((s*i-t)*mi/e),Vp=(a,t,e,s)=>-e*Math.cos(a/s*hn)+e+t,Bu=(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,Gp=(a,t,e,s)=>e-Bu(s-a,0,e,s)+t;var $v=Object.freeze({__proto__:null,defaultEasing:Vp,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:Gp,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}=Nu(i,e,n,1.70158);return-zp(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*Gp(2*a,0,e,s)+t:.5*Bu(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:l}=Nu(i,e,n,1.70158);return a<1?-.5*zp(r,o,h,a,s)+t:r*Math.pow(2,-10*(a-=1))*Math.sin((a*s-o)*mi/h)*.5+l+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*hn)+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:Bu,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:l}=Nu(i,e,n,1.70158);return r*2**(-10*a)*Math.sin((a*s-o)*mi/h)+l+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*hn)+t});const Kv=()=>!1;class Hu{constructor(t){let{startValue:e,byValue:s,duration:i=500,delay:n=0,easing:r=Vp,onStart:o=$n,onChange:h=$n,onComplete:l=$n,abort:d=Kv,target:u}=t;A(this,"_state","pending"),A(this,"durationProgress",0),A(this,"valueProgress",0),this.tick=this.tick.bind(this),this.duration=i,this.delay=n,this.easing=r,this._onStart=o,this._onChange=h,this._onComplete=l,this._abort=d,this.target=u,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(()=>qa(t),this.delay):qa(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),qa(this.tick)))}register(){ic.push(this)}unregister(){ic.remove(this)}abort(){this._state="aborted",this.unregister()}}const Qv=["startValue","endValue"];class Jv extends Hu{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(T(T({},St(t,Qv)),{},{startValue:e,byValue:s-e}))}calculate(t){const e=this.easing(t,this.startValue,this.byValue,this.duration);return{value:e,valueProgress:Math.abs((e-this.startValue)/this.byValue)}}}const Zv=["startValue","endValue"];class ty extends Hu{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(T(T({},St(t,Zv)),{},{startValue:e,byValue:s.map((i,n)=>i-e[n])}))}calculate(t){const e=this.startValue.map((s,i)=>this.easing(t,s,this.byValue[i],this.duration,i));return{value:e,valueProgress:Math.abs((e[0]-this.startValue[0])/this.byValue[0])}}}const ey=["startValue","endValue","easing","onChange","onComplete","abort"],sy=(a,t,e,s)=>t+e*(1-Math.cos(a/s*hn)),Wu=a=>a&&((t,e,s)=>a(new ut(t).toRgba(),e,s));class iy extends Hu{constructor(t){let{startValue:e,endValue:s,easing:i=sy,onChange:n,onComplete:r,abort:o}=t,h=St(t,ey);const l=new ut(e).getSource(),d=new ut(s).getSource();super(T(T({},h),{},{startValue:l,byValue:d.map((u,g)=>u-l[g]),easing:i,onChange:Wu(n),onComplete:Wu(r),abort:Wu(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),er(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 Xu(a){const t=(e=>Array.isArray(e.startValue)||Array.isArray(e.endValue))(a)?new ty(a):new Jv(a);return t.start(),t}function Up(a){const t=new iy(a);return t.start(),t}class Tt{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=uc(e,s),r=uc(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,l=i.x-s.x,d=i.y-s.y,u=t.x-s.x,g=t.y-s.y,f=l*g-d*u,p=o*g-h*u,m=d*o-l*h;if(m!==0){const w=f/m,v=p/m;return(n||0<=w&&w<=1)&&(r||0<=v&&v<=1)?new Tt("Intersection").append(new M(t.x+w*o,t.y+w*h)):new Tt}if(f===0||p===0){const w=n||r||Tt.isPointContained(t,s,i)||Tt.isPointContained(e,s,i)||Tt.isPointContained(s,t,e)||Tt.isPointContained(i,t,e);return new Tt(w?"Coincident":void 0)}return new Tt("Parallel")}static intersectSegmentLine(t,e,s,i){return Tt.intersectLineLine(t,e,s,i,!1,!0)}static intersectSegmentSegment(t,e,s,i){return Tt.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 Tt,r=s.length;for(let o,h,l,d=0;d<r;d++){if(o=s[d],h=s[(d+1)%r],l=Tt.intersectLineLine(t,e,o,h,i,!1),l.status==="Coincident")return l;n.append(...l.points)}return n.points.length>0&&(n.status="Intersection"),n}static intersectSegmentPolygon(t,e,s){return Tt.intersectLinePolygon(t,e,s,!1)}static intersectPolygonPolygon(t,e){const s=new Tt,i=t.length,n=[];for(let r=0;r<i;r++){const o=t[r],h=t[(r+1)%i],l=Tt.intersectSegmentPolygon(o,h,e);l.status==="Coincident"?(n.push(l),s.append(o,h)):s.append(...l.points)}return n.length>0&&n.length===t.length?new Tt("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 Tt.intersectPolygonPolygon(t,[i,r,n,o])}}class ny extends op{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?de(t,this.group.calcTransformMatrix()):t}setXY(t,e,s){this.group&&(t=de(t,je(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=>de(o,r))}return n}intersectsWithRect(t,e){return Tt.intersectPolygonRectangle(this.getCoords(),t,e).status==="Intersection"}intersectsWithObject(t){const e=Tt.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 Tt.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 Vs(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(Ce,t),this._set(Ge,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?dn(cp(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.viewportTransform)||xe.concat()}calcACoords(){const t=To({angle:this.angle}),{x:e,y:s}=this.getRelativeCenterPoint(),i=Ao(e,s),n=Nt(i,t),r=this._getTransformedDimensions(),o=r.x/2,h=r.y/2;return{tl:de({x:-o,y:-h},n),tr:de({x:o,y:-h},n),bl:de({x:-o,y:h},n),br:de({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,Xt(this.originX),Xt(this.originY)),e}calcTransformMatrix(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0],e=this.calcOwnMatrix();if(t||!this.group)return e;const s=this.transformMatrixKey(t),i=this.matrixCache;return i&&i.key.every((n,r)=>n===s[r])?i.value:(this.group&&(e=Nt(this.group.calcTransformMatrix(!1),e)),this.matrixCache={key:s,value:e},e)}calcOwnMatrix(){const t=this.transformMatrixKey(!0),e=this.ownMatrixCache;if(e&&e.key===t)return e.value;const s=this.getRelativeCenterPoint(),i={angle:this.angle,translateX:s.x,translateY:s.y,scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,flipX:this.flipX,flipY:this.flipY},n=up(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):lc(r,o,$a(e)),h.scalarAdd(n)}translateToGivenOrigin(t,e,s,i,n){let r=t.x,o=t.y;const h=Xt(i)-Xt(e),l=Xt(n)-Xt(s);if(h||l){const d=this._getTransformedDimensions();r+=h*d.x,o+=l*d.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(Pt(this.angle),t):i}translateToOriginPoint(t,e,s){const i=this.translateToGivenOrigin(t,J,J,e,s);return this.angle?i.rotate(Pt(this.angle),t):i}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?de(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(),lt,Ie)}}const ry=["type"],oy=["extraParam"];let yi=class Id extends ny{static getDefaults(){return Id.ownDefaults}get type(){const t=this.constructor.type;return t==="FabricObject"?"object":t.toLowerCase()}set type(t){pi("warn","Setting type has no effect",t)}constructor(t){super(),A(this,"_cacheContext",null),Object.assign(this,Id.ownDefaults),this.setOptions(t)}_createCacheCanvas(){this._cacheCanvas=jt(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,s=t.height,i=at.maxCacheSideLimit,n=at.minCacheSideLimit;if(e<=i&&s<=i&&e*s<=at.perfLimitSizeTotal)return e<n&&(t.width=n),s<n&&(t.height=n),t;const r=e/s,[o,h]=Ua.limitDimsByArea(r),l=er(n,o,i),d=er(n,h,i);return e>l&&(t.zoomX/=e/l,t.width=l,t.capped=!0),s>d&&(t.zoomY/=s/d,t.height=d,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:s+2,height:i+2,zoomX:t.x,zoomY:t.y,x:s,y:i}}_updateCacheCanvas(){const t=this._cacheCanvas,e=this._cacheContext,s=this._limitCacheSize(this._getCacheCanvasDimensions()),i=at.minCacheSideLimit,n=s.width,r=s.height,o=s.zoomX,h=s.zoomY,l=n!==t.width||r!==t.height,d=this.zoomX!==o||this.zoomY!==h;if(!t||!e)return!1;let u,g,f=l||d,p=0,m=0,w=!1;if(l){const v=this._cacheCanvas.width,x=this._cacheCanvas.height,S=n>v||r>x;w=S||(n<.9*v||r<.9*x)&&v>i&&x>i,S&&!s.capped&&(n>i||r>i)&&(p=.1*n,m=.1*r)}return yp(this)&&this.path&&(f=!0,w=!0,p+=this.getHeightOfLine(0)*this.zoomX,m+=this.getHeightOfLine(0)*this.zoomY),!!f&&(w?(t.width=Math.ceil(n+p),t.height=Math.ceil(r+m)):(e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,t.width,t.height)),u=s.x/2,g=s.y/2,this.cacheTranslationX=Math.round(t.width/2-u)+u,this.cacheTranslationY=Math.round(t.height/2-g)+g,e.translate(this.cacheTranslationX,this.cacheTranslationY),e.scale(o,h),this.zoomX=o,this.zoomY=h,!0)}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=Qn(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!==Ce&&t!==Ge||(e=this._constrainScale(e)),t===Ce&&e<0?(this.flipX=!this.flipX,e*=-1):t==="scaleY"&&e<0?(this.flipY=!this.flipY,e*=-1):t!=="shadow"||!e||e instanceof bi||(e=new bi(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),this.dirty=!1),t.restore())}drawSelectionBackground(t){}renderCache(t){t=t||{},this._cacheCanvas&&this._cacheContext||this._createCacheCanvas(),this.isCacheDirty()&&this._cacheContext&&(this.drawObject(this._cacheContext,t.forClipping),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===Ae&&this.hasFill()&&this.hasStroke()&&this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.needsItsOwnCache()||this.objectCaching&&(!this.parent||!this.parent.isOnACache()),this.ownCaching}willDrawShadow(){return!!this.shadow&&(this.shadow.offsetX!==0||this.shadow.offsetY!==0)}drawClipPathOnCache(t,e){if(t.save(),e.inverted?t.globalCompositeOperation="destination-out":t.globalCompositeOperation="destination-in",e.absolutePositioned){const s=je(this.calcTransformMatrix());t.transform(s[0],s[1],s[2],s[3],s[4],s[5])}e.transform(t),t.scale(1/e.zoomX,1/e.zoomY),t.drawImage(e._cacheCanvas,-e.cacheTranslationX,-e.cacheTranslationY),t.restore()}drawObject(t,e){const s=this.fill,i=this.stroke;e?(this.fill="black",this.stroke="",this._setClippingProperties(t)):this._renderBackground(t),this._render(t),this._drawClipPath(t,this.clipPath),this.fill=s,this.stroke=i}_drawClipPath(t,e){e&&(e._set("canvas",this.canvas),e.shouldCache(),e._transformDone=!0,e.renderCache({forClipping:!0}),this.drawClipPathOnCache(t,e))}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,rs(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&&(rs(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&&(1&e.length&&e.push(...e),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)||xe,o=n*i,h=r*i,l=e.nonScaling?new M(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*at.browserShadowBlurConstant*(o+h)*(l.x+l.y)/4,t.shadowOffsetX=e.offsetX*o*l.x,t.shadowOffsetY=e.offsetY*h*l.y}_removeShadow(t){this.shadow&&(t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0)}_applyPatternGradientTransform(t,e){if(!rs(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===Ae?(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=jt(),r=this.getCanvasRetinaScaling(),o=i.x/this.scaleX/r,h=i.y/this.scaleY/r;n.width=Math.ceil(o),n.height=Math.ceil(h);const l=n.getContext("2d");l&&(l.beginPath(),l.moveTo(0,0),l.lineTo(o,0),l.lineTo(o,h),l.lineTo(0,h),l.closePath(),l.translate(o/2,h/2),l.scale(i.zoomX/this.scaleX/r,i.zoomY/this.scaleY/r),this._applyPatternGradientTransform(l,e),l.fillStyle=e.toLive(t),l.fill(),t.translate(-this.width/2-this.strokeWidth/2,-this.height/2-this.strokeWidth/2),t.scale(r*this.scaleX/i.zoomX,r*this.scaleY/i.zoomY),t.strokeStyle=(s=l.createPattern(n,"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(X.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=Mu(this),s=this.group,i=this.shadow,n=Math.abs,r=t.enableRetinaScaling?ep():1,o=(t.multiplier||1)*r,h=t.canvasProvider||(x=>new th(x,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&Ep(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&Ou(this,this.getViewportTransform()),this.setCoords();const l=jt(),d=this.getBoundingRect(),u=this.shadow,g=new M;if(u){const x=u.blur,S=u.nonScaling?new M(1,1):this.getObjectScaling();g.x=2*Math.round(n(u.offsetX)+x)*n(S.x),g.y=2*Math.round(n(u.offsetY)+x)*n(S.y)}const f=d.width+g.x,p=d.height+g.y;l.width=Math.ceil(f),l.height=Math.ceil(p);const m=h(l);t.format==="jpeg"&&(m.backgroundColor="#fff"),this.setPositionByOrigin(new M(m.width/2,m.height/2),J,J);const w=this.canvas;m._objects=[this],this.set("canvas",m),this.setCoords();const v=m.toCanvasElement(o||1,t);return this.set("canvas",w),this.shadow=i,s&&(this.group=s),this.set(e),this.setCoords(),m._objects=[],m.destroy(),v}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return wu(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(){ic.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&zs().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:l}=s,d=T(T({},s),{},{target:this,startValue:o??i.reduce((u,g)=>u[g],this),endValue:e,abort:r==null?void 0:r.bind(this),onChange:(u,g,f)=>{i.reduce((p,m,w)=>(w===i.length-1&&(p[m]=u),p[m]),this),h&&h(u,g,f)},onComplete:(u,g,f)=>{this.setCoords(),l&&l(u,g,f)}});return n?Up(d):Xu(d)}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(Id.customProperties,this.constructor.customProperties||[]);let e;const s=at.NUM_FRACTION_DIGITS,{clipPath:i,fill:n,stroke:r,shadow:o,strokeDashArray:h,left:l,top:d,originX:u,originY:g,width:f,height:p,strokeWidth:m,strokeLineCap:w,strokeDashOffset:v,strokeLineJoin:x,strokeUniform:S,strokeMiterLimit:C,scaleX:E,scaleY:k,angle:P,flipX:D,flipY:R,opacity:B,visible:O,backgroundColor:F,fillRule:L,paintFirst:I,globalCompositeOperation:G,skewX:Y,skewY:z}=this;i&&!i.excludeFromExport&&(e=i.toObject(t.concat("inverted","absolutePositioned")));const H=vt=>Ct(vt,s),_t=T(T({},Jn(this,t)),{},{type:this.constructor.type,version:gu,originX:u,originY:g,left:H(l),top:H(d),width:H(f),height:H(p),fill:bp(n)?n.toObject():n,stroke:bp(r)?r.toObject():r,strokeWidth:H(m),strokeDashArray:h&&h.concat(),strokeLineCap:w,strokeDashOffset:v,strokeLineJoin:x,strokeUniform:S,strokeMiterLimit:H(C),scaleX:H(E),scaleY:H(k),angle:H(P),flipX:D,flipY:R,opacity:H(B),shadow:o&&o.toObject(),visible:O,backgroundColor:F,fillRule:L,paintFirst:I,globalCompositeOperation:G,skewX:H(Y),skewY:H(z)},e?{clipPath:e}:null);return this.includeDefaultValues?_t:this._removeDefaultValues(_t)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),s=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return Cu(t,(i,n)=>{if(n===lt||n===Ie||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=St(t,ry),s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{extraParam:i}=s,n=St(s,oy);return Qa(e,n).then(r=>i?(delete r[i],new this(e[i],r)):new this(r))}static fromObject(t,e){return this._fromObject(t,e)}};A(yi,"stateProperties",Yv),A(yi,"cacheProperties",vi),A(yi,"ownDefaults",qv),A(yi,"type","FabricObject"),A(yi,"colorProperties",[It,Ae,"backgroundColor"]),A(yi,"customProperties",[]),X.setClass(yi),X.setClass(yi,"object");const Oo=(a,t,e)=>(s,i,n,r)=>{const o=t(s,i,n,r);return o&&Mp(a,T(T({},Pp(s,i,n,r)),e)),o};function Do(a){return(t,e,s,i)=>{const{target:n,originX:r,originY:o}=e,h=n.getRelativeCenterPoint(),l=n.translateToOriginPoint(h,r,o),d=a(t,e,s,i);return n.setPositionByOrigin(l,e.originX,e.originY),d}}const Yp=Oo(Ya,Do((a,t,e,s)=>{const i=Du(t,t.originX,t.originY,e,s);if(Xt(t.originX)===Xt(J)||Xt(t.originX)===Xt(Rt)&&i.x<0||Xt(t.originX)===Xt(lt)&&i.x>0){const{target:n}=t,r=n.strokeWidth/(n.strokeUniform?n.scaleX:1),o=Op(t)?2:1,h=n.width,l=Math.abs(i.x*o/n.scaleX)-r;return n.set("width",Math.max(l,1)),h!==n.width}return!1}));function ay(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?Ae:It,l=!o&&(s.cornerStrokeColor||i.cornerStrokeColor);let d,u=t,g=e;a.save(),a.fillStyle=s.cornerColor||i.cornerColor||"",a.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",n>r?(d=n,a.scale(1,r/n),g=e*n/r):r>n?(d=r,a.scale(n/r,1),u=t*r/n):d=n,a.lineWidth=1,a.beginPath(),a.arc(u,g,d/2,0,mi,!1),a[h](),l&&a.stroke(),a.restore()}function hy(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?Ae:It,l=!o&&(s.cornerStrokeColor||i.cornerStrokeColor),d=n/2,u=r/2;a.save(),a.fillStyle=s.cornerColor||i.cornerColor||"",a.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",a.lineWidth=1,a.translate(t,e);const g=i.getTotalAngle();a.rotate(Pt(g)),a["".concat(h,"Rect")](-d,-u,n,r),l&&a.strokeRect(-d,-u,n,r),a.restore()}class Ss{constructor(t){A(this,"visible",!0),A(this,"actionName",ec),A(this,"angle",0),A(this,"x",0),A(this,"y",0),A(this,"offsetX",0),A(this,"offsetY",0),A(this,"sizeX",0),A(this,"sizeY",0),A(this,"touchSizeX",0),A(this,"touchSizeY",0),A(this,"cursorStyle","crosshair"),A(this,"withConnection",!1),Object.assign(this,t)}shouldActivate(t,e,s,i){var n;let{tl:r,tr:o,br:h,bl:l}=i;return((n=e.canvas)===null||n===void 0?void 0:n.getActiveObject())===e&&e.isControlVisible(t)&&Tt.isPointInPolygon(s,[r,o,h,l])}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=rc([Ao(s,i),To({angle:t}),oc((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"?ay.call(this,t,e,s,i,n):hy.call(this,t,e,s,i,n)}}const ly=(a,t,e)=>e.lockRotation?cc:t.cursorStyle,cy=Oo(ip,Do((a,t,e,s)=>{let{target:i,ex:n,ey:r,theta:o,originX:h,originY:l}=t;const d=i.translateToOriginPoint(i.getRelativeCenterPoint(),h,l);if(ws(i,"lockRotation"))return!1;const u=Math.atan2(r-d.y,n-d.x),g=Math.atan2(s-d.y,e-d.x);let f=dn(g-u+o);if(i.snapAngle&&i.snapAngle>0){const m=i.snapAngle,w=i.snapThreshold||m,v=Math.ceil(f/m)*m,x=Math.floor(f/m)*m;Math.abs(f-x)<w?f=x:Math.abs(f-v)<w&&(f=v)}f<0&&(f=360+f),f%=360;const p=i.angle!==f;return i.angle=f,p}));function qp(a,t){const e=t.canvas,s=a[e.uniScaleKey];return e.uniformScaling&&!s||!e.uniformScaling&&s}function $p(a,t,e){const s=ws(a,"lockScalingX"),i=ws(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 dy=["e","se","s","sw","w","nw","n","ne","e"],sh=(a,t,e)=>{const s=qp(a,e);if($p(e,t.x!==0&&t.y===0?"x":t.x===0&&t.y!==0?"y":"",s))return cc;const i=Lp(e,t);return"".concat(dy[i],"-resize")};function zu(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{};const n=t.target,r=i.by,o=qp(a,n);let h,l,d,u,g,f;if($p(n,r,o))return!1;if(t.gestureScale)l=t.scaleX*t.gestureScale,d=t.scaleY*t.gestureScale;else{if(h=Du(t,t.originX,t.originY,e,s),g=r!=="y"?Math.sign(h.x||t.signX||1):1,f=r!=="x"?Math.sign(h.y||t.signY||1):1,t.signX||(t.signX=g),t.signY||(t.signY=f),ws(n,"lockScalingFlip")&&(t.signX!==g||t.signY!==f))return!1;if(u=n._getTransformedDimensions(),o&&!r){const w=Math.abs(h.x)+Math.abs(h.y),{original:v}=t,x=w/(Math.abs(u.x*v.scaleX/n.scaleX)+Math.abs(u.y*v.scaleY/n.scaleY));l=v.scaleX*x,d=v.scaleY*x}else l=Math.abs(h.x*n.scaleX/u.x),d=Math.abs(h.y*n.scaleY/u.y);Op(t)&&(l*=2,d*=2),t.signX!==g&&r!=="y"&&(t.originX=Dp(t.originX),l*=-1,t.signX=g),t.signY!==f&&r!=="x"&&(t.originY=Dp(t.originY),d*=-1,t.signY=f)}const p=n.scaleX,m=n.scaleY;return r?(r==="x"&&n.set(Ce,l),r==="y"&&n.set(Ge,d)):(!ws(n,"lockScalingX")&&n.set(Ce,l),!ws(n,"lockScalingY")&&n.set(Ge,d)),p!==n.scaleX||m!==n.scaleY}const mc=Oo(Zl,Do((a,t,e,s)=>zu(a,t,e,s))),uy=Oo(Zl,Do((a,t,e,s)=>zu(a,t,e,s,{by:"x"}))),gy=Oo(Zl,Do((a,t,e,s)=>zu(a,t,e,s,{by:"y"}))),fy=["target","ex","ey","skewingSide"],Vu={x:{counterAxis:"y",scale:Ce,skew:xo,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:Ge,skew:So,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},py=["ns","nesw","ew","nwse"],my=(a,t,e)=>{if(t.x!==0&&ws(e,"lockSkewingY")||t.y!==0&&ws(e,"lockSkewingX"))return cc;const s=Lp(e,t)%4;return"".concat(py[s],"-resize")};function Kp(a,t,e,s,i){const{target:n}=e,{counterAxis:r,origin:o,lockSkewing:h,skew:l,flip:d}=Vu[a];if(ws(n,h))return!1;const{origin:u,flip:g}=Vu[r],f=Xt(e[u])*(n[g]?-1:1),p=-Math.sign(f)*(n[d]?-1:1),m=.5*-((n[l]===0&&Du(e,J,J,s,i)[a]>0||n[l]>0?1:-1)*p)+.5;return Oo(np,Do((v,x,S,C)=>function(E,k,P){let{target:D,ex:R,ey:B,skewingSide:O}=k,F=St(k,fy);const{skew:L}=Vu[E],I=P.subtract(new M(R,B)).divide(new M(D.scaleX,D.scaleY))[E],G=D[L],Y=F[L],z=Math.tan(Pt(Y)),H=E==="y"?D._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:D._getTransformedDimensions({scaleX:1,scaleY:1}).y,_t=2*I*O/Math.max(H,1)+z,vt=dn(Math.atan(_t));D.set(L,vt);const te=G!==D[L];if(te&&E==="y"){const{skewX:Wt,scaleX:xt}=D,Le=D._getTransformedDimensions({skewY:G}),gi=D._getTransformedDimensions(),Ft=Wt!==0?Le.x/gi.x:1;Ft!==1&&D.set(Ce,Ft*xt)}return te}(a,x,new M(S,C))))(t,T(T({},e),{},{[o]:m,skewingSide:p}),s,i)}const by=(a,t,e,s)=>Kp("x",a,t,e,s),vy=(a,t,e,s)=>Kp("y",a,t,e,s);function bc(a,t){return a[t.canvas.altActionKey]}const vc=(a,t,e)=>{const s=bc(a,e);return t.x===0?s?xo:Ge:t.y===0?s?So:Ce:""},Po=(a,t,e)=>bc(a,e)?my(0,t,e):sh(a,t,e),Qp=(a,t,e,s)=>bc(a,t.target)?vy(a,t,e,s):uy(a,t,e,s),Jp=(a,t,e,s)=>bc(a,t.target)?by(a,t,e,s):gy(a,t,e,s),Zp=()=>({ml:new Ss({x:-.5,y:0,cursorStyleHandler:Po,actionHandler:Qp,getActionName:vc}),mr:new Ss({x:.5,y:0,cursorStyleHandler:Po,actionHandler:Qp,getActionName:vc}),mb:new Ss({x:0,y:.5,cursorStyleHandler:Po,actionHandler:Jp,getActionName:vc}),mt:new Ss({x:0,y:-.5,cursorStyleHandler:Po,actionHandler:Jp,getActionName:vc}),tl:new Ss({x:-.5,y:-.5,cursorStyleHandler:sh,actionHandler:mc}),tr:new Ss({x:.5,y:-.5,cursorStyleHandler:sh,actionHandler:mc}),bl:new Ss({x:-.5,y:.5,cursorStyleHandler:sh,actionHandler:mc}),br:new Ss({x:.5,y:.5,cursorStyleHandler:sh,actionHandler:mc}),mtr:new Ss({x:0,y:-.5,actionHandler:cy,cursorStyleHandler:ly,offsetY:-40,withConnection:!0,actionName:vu})}),yy=()=>({mr:new Ss({x:.5,y:0,actionHandler:Yp,cursorStyleHandler:Po,actionName:Ya}),ml:new Ss({x:-.5,y:0,actionHandler:Yp,cursorStyleHandler:Po,actionName:Ya})}),_y=()=>T(T({},Zp()),yy());class ih extends yi{static getDefaults(){return T(T({},super.getDefaults()),ih.ownDefaults)}constructor(t){super(),Object.assign(this,this.constructor.createControls(),ih.ownDefaults),this.setOptions(t)}static createControls(){return{controls:Zp()}}_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(ec))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=Ao(e.x,e.y),i=To({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),n=Nt(s,i),r=Nt(t,n),o=Nt(r,[1/t[0],0,0,1/t[3],0,0]),h=this.group?Qn(this.calcTransformMatrix()):void 0;h&&(h.scaleX=Math.abs(h.scaleX),h.scaleY=Math.abs(h.scaleY));const l=this._calculateCurrentDimensions(h),d={};return this.forEachControl((u,g)=>{const f=u.positionHandler(l,o,this,u);d[g]=Object.assign(f,this._calcCornerCoords(u,f))}),d}_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(Pt(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,l=Nt(r,this.calcTransformMatrix()),d=Qn(l);t.save(),t.translate(d.translateX,d.translateY),t.lineWidth=1*this.borderScaleFactor,this.group===this.parent&&(t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1),this.flipX&&(d.angle-=180),t.rotate(Pt(this.group?d.angle:this.angle)),o&&this.drawBorders(t,d,e),h&&this.drawControls(t,e),t.restore()}drawBorders(t,e,s){let i;if(s&&s.forActiveSelection||this.group){const n=lc(this.width,this.height,$a(e)),r=this.isStrokeAccountedForInDimensions()?_u:(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,l)=>{if(h.getVisibility(this,l)){const d=this.oCoords[l];h.render(t,d.x,d.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 tm(a,t){return t.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(s=>{s!=="constructor"&&Object.defineProperty(a.prototype,s,Object.getOwnPropertyDescriptor(e.prototype,s)||Object.create(null))})}),a}A(ih,"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 ue extends ih{}tm(ue,[Fp]),X.setClass(ue),X.setClass(ue,"object");const em=(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 sm{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=uc(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(Pt(this.options.skewY)),e.x+=e.y*Math.tan(Pt(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}const wy=new M;class Lo extends sm{static getOrthogonalRotationFactor(t,e){const s=e?fc(t,e):Bp(t);return Math.abs(s)<hn?-1:1}constructor(t,e,s,i){super(i),A(this,"AB",void 0),A(this,"AC",void 0),A(this,"alpha",void 0),A(this,"bisector",void 0),this.A=new 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=fc(this.AB,this.AC),this.bisector=pc(Ru(this.AB.eq(wy)?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=Iu(i),r=Lo.getOrthogonalRotationFactor(n,this.bisector);return this.scaleUnitVector(n,s*r)}projectBevel(){const t=[];return(this.alpha%mi==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?gc(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return gc(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(Lo.getOrthogonalRotationFactor(this.bisector),Lo.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=>{ju(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,l=new M(Math.tan(Pt(i)),Math.tan(Pt(n))),d=this.strokeProjectionMagnitude,u=h?d/o/Math.sqrt(1/o**2+1/r**2*l.y**2):d/Math.sqrt(1+l.y**2),g=new M(Math.sqrt(Math.max(d**2-u**2,0)),u),f=h?d/Math.sqrt(1+l.x**2*(1/o)**2/(1/r+1/r*l.x*l.y)**2):d/Math.sqrt(1+l.x**2/(1+l.x*l.y)**2),p=new M(f,Math.sqrt(Math.max(d**2-f**2,0)));return[p,p.scalarMultiply(-1),g,g.scalarMultiply(-1)].map(m=>this.applySkew(h?m.multiply(this.strokeUniformScalar):m)).forEach(m=>{ju(m,t,e)&&s.push(this.applySkew(this.A).add(m))}),s}projectRound(){const t=[];t.push(...this.projectBevel());const e=this.alpha%mi==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=Mo(i,r)>0,h=o?i:n,l=o?n:i;return this.isSkewed()?t.push(...this.projectRoundWithSkew(h,l)):t.push(...this.projectRoundNoSkew(h,l)),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 im extends sm{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(Iu(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 Lo(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(pc(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 nm=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 l=o.length-1;l>=0;l--)if(h(o[l],l,o))return l;return-1})(i,o=>!o.eq(n));i.splice(r+1)}return i.forEach((n,r,o)=>{let h,l;r===0?(l=o[1],h=e?n:o[o.length-1]):r===o.length-1?(h=o[r-1],l=e?n:o[0]):(h=o[r-1],l=o[r+1]),e&&o.length===1?s.push(...new im(n,n,t).project()):!e||r!==0&&r!==o.length-1?s.push(...new Lo(n,h,l,t).project()):s.push(...new im(n,r===0?l:h,t).project())}),s},Gu=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},rm=a=>a.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&apos;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),yc=a=>{const t=[];for(let e,s=0;s<a.length;s++)(e=xy(a,s))!==!1&&t.push(e);return t},xy=(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 Sy=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:rm,graphemeSplit:yc});const _c=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)},om=(a,t)=>{const e=t.split(`
38
- `),s=[];let i=-1,n={};a=Gu(a);for(let r=0;r<e.length;r++){const o=yc(e[r]);if(a[r])for(let h=0;h<o.length;h++){i++;const l=a[r][h];l&&Object.keys(l).length>0&&(_c(n,l,!0)?s.push({start:i,end:i+1,style:l}):s[s.length-1].end++),n=l||{}}else i+=o.length,n={}}return s},am=(a,t)=>{if(!Array.isArray(a))return Gu(a);const e=t.split(bu),s={};let i=-1,n=0;for(let r=0;r<e.length;r++){const o=yc(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},un=["display","transform",It,"fill-opacity","fill-rule","opacity",Ae,"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 hm(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 Cy(a,t){let e=!0;const s=hm(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=hm(i=i.parentElement,r);return n.length===0}(a,t)),s&&e&&t.length===0}const Ay=a=>{var t;return(t=zv[a])!==null&&t!==void 0?t:a},Ty=new RegExp("(".concat(xs,")"),"gi"),Ey=a=>a.replace(Ty," $1 ").replace(/,/gi," ").replace(/\s+/gi," ");var lm,cm,dm,um,gm,fm,pm;const Ee="(".concat(xs,")"),ky=String.raw(lm||(lm=an(["(skewX)(",")"],["(skewX)\\(","\\)"])),Ee),My=String.raw(cm||(cm=an(["(skewY)(",")"],["(skewY)\\(","\\)"])),Ee),Oy=String.raw(dm||(dm=an(["(rotate)(","(?: "," ",")?)"],["(rotate)\\(","(?: "," ",")?\\)"])),Ee,Ee,Ee),Dy=String.raw(um||(um=an(["(scale)(","(?: ",")?)"],["(scale)\\(","(?: ",")?\\)"])),Ee,Ee),Py=String.raw(gm||(gm=an(["(translate)(","(?: ",")?)"],["(translate)\\(","(?: ",")?\\)"])),Ee,Ee),Ly=String.raw(fm||(fm=an(["(matrix)("," "," "," "," "," ",")"],["(matrix)\\("," "," "," "," "," ","\\)"])),Ee,Ee,Ee,Ee,Ee,Ee),Uu="(?:".concat(Ly,"|").concat(Py,"|").concat(Oy,"|").concat(Dy,"|").concat(ky,"|").concat(My,")"),Fy="(?:".concat(Uu,"*)"),Ry=String.raw(pm||(pm=an(["^s*(?:","?)s*$"],["^\\s*(?:","?)\\s*$"])),Fy),Iy=new RegExp(Ry),jy=new RegExp(Uu),Ny=new RegExp(Uu,"g");function wc(a){const t=[];if(!(a=Ey(a).replace(/\s*([()])\s*/gi,"$1"))||a&&!Iy.test(a))return[...xe];for(const e of a.matchAll(Ny)){const s=jy.exec(e[0]);if(!s)continue;let i=xe;const n=s.filter(p=>!!p),[,r,...o]=n,[h,l,d,u,g,f]=o.map(p=>parseFloat(p));switch(r){case"translate":i=Ao(h,l);break;case vu:i=To({angle:h},{x:l,y:d});break;case ec:i=oc(h,l);break;case xo:i=xu(h);break;case So:i=Su(h);break;case"matrix":i=[h,l,d,u,g,f]}t.push(i)}return rc(t)}function By(a,t,e,s){const i=Array.isArray(t);let n,r=t;if(a!==It&&a!==Ae||t!==Se){if(a==="strokeUniform")return t==="non-scaling-stroke";if(a==="strokeDashArray")r=t===Se?null:t.replace(/,/g," ").split(/\s+/).map(parseFloat);else if(a==="transformMatrix")r=e&&e.transformMatrix?Nt(e.transformMatrix,wc(t)):wc(t);else if(a==="visible")r=t!==Se&&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"?lt:t==="end"?Rt:J;else if(a==="charSpacing")n=Te(t,s)/s*1e3;else if(a==="paintFirst"){const o=t.indexOf(It),h=t.indexOf(Ae);r=It,(o>-1&&h>-1&&h<o||o===-1&&h>-1)&&(r=Ae)}else{if(a==="href"||a==="xlink:href"||a==="font"||a==="id")return t;if(a==="imageSmoothing")return t==="optimizeQuality";n=i?t.map(Te):Te(t,s)}}else r="";return!i&&isNaN(n)?r:n}function Hy(a,t){const e=a.match(Xv);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=Te(n)),o&&(t.fontFamily=o),r&&(t.lineHeight=r==="normal"?1:r)}function Yu(a,t){a.replace(/;\s*$/,"").split(";").forEach(e=>{if(!e)return;const[s,i]=e.split(":");t[s.trim().toLowerCase()]=i.trim()})}function Wy(a){const t={},e=a.getAttribute("style");return e&&(typeof e=="string"?Yu(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 Xy={stroke:"strokeOpacity",fill:"fillOpacity"};function _i(a,t,e){if(!a)return{};let s,i={},n=pu;a.parentNode&&Ip.test(a.parentNode.nodeName)&&(i=_i(a.parentElement,t,e),i.fontSize&&(s=n=Te(i.fontSize)));const r=T(T(T({},t.reduce((l,d)=>{const u=a.getAttribute(d);return u&&(l[d]=u),l},{})),function(l){let d=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},u={};for(const g in d)Cy(l,g.split(" "))&&(u=T(T({},u),d[g]));return u}(a,e)),Wy(a));r[Fu]&&a.setAttribute(Fu,r[Fu]),r[Lu]&&(s=Te(r[Lu],n),r[Lu]="".concat(s));const o={};for(const l in r){const d=Ay(l),u=By(d,r[l],i,s);o[d]=u}o&&o.font&&Hy(o.font,o);const h=T(T({},i),o);return Ip.test(a.nodeName)?h:function(l){const d=ue.getDefaults();return Object.entries(Xy).forEach(u=>{let[g,f]=u;if(l[f]===void 0||l[g]==="")return;if(l[g]===void 0){if(!d[g])return;l[g]=d[g]}if(l[g].indexOf("url(")===0)return;const p=new ut(l[g]);l[g]=p.setAlpha(Ct(p.getAlpha()*l[f],2)).toRgba()}),l}(h)}const zy=["left","top","width","height","visible"],mm=["rx","ry"];class Gs extends ue{static getDefaults(){return T(T({},super.getDefaults()),Gs.ownDefaults)}constructor(t){super(),Object.assign(this,Gs.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-ln*r,n,i+e,n+ln*o,i+e,n+o),t.lineTo(i+e,n+s-o),h&&t.bezierCurveTo(i+e,n+s-ln*o,i+e-ln*r,n+s,i+e-r,n+s),t.lineTo(i+r,n+s),h&&t.bezierCurveTo(i+ln*r,n+s,i,n+s-ln*o,i,n+s-o),t.lineTo(i,n+o),h&&t.bezierCurveTo(i,n+ln*o,i+ln*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([...mm,...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=_i(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,width:o=0,height:h=0,visible:l=!0}=i,d=St(i,zy);return new this(T(T(T({},e),d),{},{left:n,top:r,width:o,height:h,visible:!!(l&&o&&h)}))}}A(Gs,"type","Rect"),A(Gs,"cacheProperties",[...vi,...mm]),A(Gs,"ownDefaults",{rx:0,ry:0}),A(Gs,"ATTRIBUTE_NAMES",[...un,"x","y","rx","ry","width","height"]),X.setClass(Gs),X.setSVGClass(Gs);const wi="initialization",xc="added",qu="removed",Sc="imperative",bm=(a,t)=>{const{strokeUniform:e,strokeWidth:s,width:i,height:n,group:r}=t,o=r&&r!==a?eh(r.calcTransformMatrix(),a.calcTransformMatrix()):null,h=o?t.getRelativeCenterPoint().transform(o):t.getRelativeCenterPoint(),l=!t.isStrokeAccountedForInDimensions(),d=e&&l?kp(new M(s,s),void 0,a.calcTransformMatrix()):_u,u=!e&&l?s:0,g=lc(i+u,n+u,rc([o,t.calcOwnMatrix()],!0)).add(d).scalarDivide(2);return[h.subtract(g),h.add(g)]};class Cc{calcLayoutResult(t,e){if(this.shouldPerformLayout(t))return this.calcBoundingBox(e,t)}shouldPerformLayout(t){let{type:e,prevStrategy:s,strategy:i}=t;return e===wi||e===Sc||!!s&&i!==s}shouldLayoutClipPath(t){let{type:e,target:{clipPath:s}}=t;return e!==wi&&s&&!s.absolutePositioned}getInitialSize(t,e){return e.size}calcBoundingBox(t,e){const{type:s,target:i}=e;if(s===Sc&&e.overrides)return e.overrides;if(t.length===0)return;const{left:n,top:r,width:o,height:h}=Vs(t.map(u=>bm(i,u)).reduce((u,g)=>u.concat(g),[])),l=new M(o,h),d=new M(n,r).add(l.scalarDivide(2));if(s===wi){const u=this.getInitialSize(e,{size:l,center:d});return{center:d,relativeCorrection:new M(0,0),size:u}}return{center:d.transform(i.calcOwnMatrix()),size:l}}}A(Cc,"type","strategy");class $u extends Cc{shouldPerformLayout(t){return!0}}A($u,"type","fit-content"),X.setClass($u);const Vy=["strategy"],Gy=["target","strategy","bubbles","prevStrategy"],vm="layoutManager";class nh{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:new $u;A(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[sc,sp,Ya,ip,Zl,np,tc,Lv,Fv].map(i=>t.on(i,n=>this.performLayout(i===sc?{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===wi||s===xc?this.subscribeTargets(t):s===qu&&this.unsubscribeTargets(t),e.fire("layout:before",{context:t}),i&&i.fire("object:layout:before",{target:e,context:t}),s===Sc&&t.deep){const n=St(t,Vy);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===wi?new M:e.getRelativeCenterPoint(),{center:o,correction:h=new M,relativeCorrection:l=new M}=n,d=r.subtract(o).add(h).transform(i===wi?xe:je(e.calcOwnMatrix()),!0).add(l);return{result:n,prevCenter:r,nextCenter:o,offset:d}}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===wi?s.set({left:(r=t.x)!==null&&r!==void 0?r:n.x+i.x*Xt(s.originX),top:(o=t.y)!==null&&o!==void 0?o:n.y+i.y*Xt(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=St(t,Gy),{canvas:h}=s;s.fire("layout:after",{context:t,result:e}),h&&h.fire("object:layout:after",{context:t,result:e,target:s});const l=s.parent;n&&l!=null&&l.layoutManager&&((o.path||(o.path=[])).push(s),l.layoutManager.performLayout(T(T({},o),{},{target:l}))),s.set("dirty",!0)}dispose(){const{_subscriptions:t}=this;t.forEach(e=>e.forEach(s=>s())),t.clear()}toObject(){return{type:vm,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}X.setClass(nh,vm);const Uy=["type","objects","layoutManager"];class Yy extends nh{performLayout(){}}class Us extends rp(ue){static getDefaults(){return T(T({},super.getDefaults()),Us.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),A(this,"_activeObjects",[]),A(this,"__objectSelectionTracker",void 0),A(this,"__objectSelectionDisposer",void 0),Object.assign(this,Us.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 nh,this.layoutManager.performLayout({type:wi,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(pi("error","Group: circular object trees are not supported, this call has no effect"),!1):this._objects.indexOf(t)===-1||(pi("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(xc,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(xc,n),r}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange(qu,t),t}_onObjectAdded(t){this.enterGroup(t,!0),this.fire("object:added",{target:t}),t.fire("added",{target:this})}_onObjectRemoved(t,e){this.exitGroup(t,e),this.fire("object:removed",{target:t}),t.fire("removed",{target:this})}_onAfterObjectsChange(t,e){this.layoutManager.performLayout({type:t,targets:e,target:this})}_onStackOrderChanged(){this._set("dirty",!0)}_set(t,e){const s=this[t];return super._set(t,e),t==="canvas"&&s!==e&&(this._objects||[]).forEach(i=>{i._set(t,e)}),this}_shouldSetNestedCoords(){return this.subTargetCheck}removeAll(){return this._activeObjects=[],this.remove(...this._objects)}__objectSelectionMonitor(t,e){let{target:s}=e;const i=this._activeObjects;if(t)i.push(s),this._set("dirty",!0);else if(i.length>0){const n=i.indexOf(s);n>-1&&(i.splice(n,1),this._set("dirty",!0))}}_watchObject(t,e){t&&this._watchObject(!1,e),t?(e.on("selected",this.__objectSelectionTracker),e.on("deselected",this.__objectSelectionDisposer)):(e.off("selected",this.__objectSelectionTracker),e.off("deselected",this.__objectSelectionDisposer))}enterGroup(t,e){t.group&&t.group.remove(t),t._set("parent",this),this._enterGroup(t,e)}_enterGroup(t,e){e&&ko(t,Nt(je(this.calcTransformMatrix()),t.calcTransformMatrix())),this._shouldSetNestedCoords()&&t.setCoords(),t._set("group",this),t._set("canvas",this.canvas),this._watchObject(!0,t);const s=this.canvas&&this.canvas.getActiveObject&&this.canvas.getActiveObject();s&&(s===t||t.isDescendantOf(s))&&this._activeObjects.push(t)}exitGroup(t,e){this._exitGroup(t,e),t._set("parent",void 0),t._set("canvas",void 0)}_exitGroup(t,e){t._set("group",void 0),e||(ko(t,Nt(this.calcTransformMatrix(),t.calcTransformMatrix())),t.setCoords()),this._watchObject(!1,t);const s=this._activeObjects.length>0?this._activeObjects.indexOf(t):-1;s>-1&&this._activeObjects.splice(s,1)}shouldCache(){const t=ue.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){this._renderBackground(t);for(let s=0;s<this._objects.length;s++){var e;(e=this.canvas)!==null&&e!==void 0&&e.preserveObjectStacking&&this._objects[s].group!==this?(t.save(),t.transform(...je(this.calcTransformMatrix())),this._objects[s].render(t),t.restore()):this._objects[s].group===this&&this._objects[s].render(t)}this._drawClipPath(t,this.clipPath)}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:Sc},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=Gs.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=bi.ownDefaults;return this.includeDefaultValues?t:Au(t,(s,i)=>s!==e[i])}static async fromObject(t){return new this(t)}}A(bi,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),A(bi,"type","shadow"),N.setClass(bi,"shadow");const er=(a,t,e)=>Math.max(a,Math.min(t,e)),Kv=[Ie,lt,Ce,Ge,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",xo,So],vi=[Ft,Ae,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],Qv={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:lt,originY:Ie,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:Ft,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},Bu=(a,t,e,s)=>(a<Math.abs(t)?(a=t,s=e/4):s=t===0&&a===0?e/mi*Math.asin(1):e/mi*Math.asin(t/a),{a,c:t,p:e,s}),Vp=(a,t,e,s,i)=>a*Math.pow(2,10*(s-=1))*Math.sin((s*i-t)*mi/e),Gp=(a,t,e,s)=>-e*Math.cos(a/s*hn)+e+t,Hu=(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,Up=(a,t,e,s)=>e-Hu(s-a,0,e,s)+t;var Jv=Object.freeze({__proto__:null,defaultEasing:Gp,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:Up,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}=Bu(i,e,n,1.70158);return-Vp(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*Up(2*a,0,e,s)+t:.5*Hu(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:l}=Bu(i,e,n,1.70158);return a<1?-.5*Vp(r,o,h,a,s)+t:r*Math.pow(2,-10*(a-=1))*Math.sin((a*s-o)*mi/h)*.5+l+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*hn)+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:Hu,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:l}=Bu(i,e,n,1.70158);return r*2**(-10*a)*Math.sin((a*s-o)*mi/h)+l+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*hn)+t});const Zv=()=>!1;class Wu{constructor(t){let{startValue:e,byValue:s,duration:i=500,delay:n=0,easing:r=Gp,onStart:o=$n,onChange:h=$n,onComplete:l=$n,abort:d=Zv,target:u}=t;A(this,"_state","pending"),A(this,"durationProgress",0),A(this,"valueProgress",0),this.tick=this.tick.bind(this),this.duration=i,this.delay=n,this.easing=r,this._onStart=o,this._onChange=h,this._onComplete=l,this._abort=d,this.target=u,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(()=>qa(t),this.delay):qa(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),qa(this.tick)))}register(){nc.push(this)}unregister(){nc.remove(this)}abort(){this._state="aborted",this.unregister()}}const ty=["startValue","endValue"];class ey extends Wu{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(T(T({},wt(t,ty)),{},{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 sy=["startValue","endValue"];class iy extends Wu{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(T(T({},wt(t,sy)),{},{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 ny=["startValue","endValue","easing","onChange","onComplete","abort"],ry=(a,t,e,s)=>t+e*(1-Math.cos(a/s*hn)),Xu=a=>a&&((t,e,s)=>a(new ut(t).toRgba(),e,s));class oy extends Wu{constructor(t){let{startValue:e,endValue:s,easing:i=ry,onChange:n,onComplete:r,abort:o}=t,h=wt(t,ny);const l=new ut(e).getSource(),d=new ut(s).getSource();super(T(T({},h),{},{startValue:l,byValue:d.map((u,g)=>u-l[g]),easing:i,onChange:Xu(n),onComplete:Xu(r),abort:Xu(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),er(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 zu(a){const t=(e=>Array.isArray(e.startValue)||Array.isArray(e.endValue))(a)?new iy(a):new ey(a);return t.start(),t}function Yp(a){const t=new oy(a);return t.start(),t}class Ct{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=gc(e,s),r=gc(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 D(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,l=i.x-s.x,d=i.y-s.y,u=t.x-s.x,g=t.y-s.y,f=l*g-d*u,p=o*g-h*u,m=d*o-l*h;if(m!==0){const _=f/m,v=p/m;return(n||0<=_&&_<=1)&&(r||0<=v&&v<=1)?new Ct("Intersection").append(new D(t.x+_*o,t.y+_*h)):new Ct}if(f===0||p===0){const _=n||r||Ct.isPointContained(t,s,i)||Ct.isPointContained(e,s,i)||Ct.isPointContained(s,t,e)||Ct.isPointContained(i,t,e);return new Ct(_?"Coincident":void 0)}return new Ct("Parallel")}static intersectSegmentLine(t,e,s,i){return Ct.intersectLineLine(t,e,s,i,!1,!0)}static intersectSegmentSegment(t,e,s,i){return Ct.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 Ct,r=s.length;for(let o,h,l,d=0;d<r;d++){if(o=s[d],h=s[(d+1)%r],l=Ct.intersectLineLine(t,e,o,h,i,!1),l.status==="Coincident")return l;n.append(...l.points)}return n.points.length>0&&(n.status="Intersection"),n}static intersectSegmentPolygon(t,e,s){return Ct.intersectLinePolygon(t,e,s,!1)}static intersectPolygonPolygon(t,e){const s=new Ct,i=t.length,n=[];for(let r=0;r<i;r++){const o=t[r],h=t[(r+1)%i],l=Ct.intersectSegmentPolygon(o,h,e);l.status==="Coincident"?(n.push(l),s.append(o,h)):s.append(...l.points)}return n.length>0&&n.length===t.length?new Ct("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 D(n.x,i.y),o=new D(i.x,n.y);return Ct.intersectPolygonPolygon(t,[i,r,n,o])}}class ay extends ap{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?de(t,this.group.calcTransformMatrix()):t}setXY(t,e,s){this.group&&(t=de(t,je(this.group.calcTransformMatrix()))),this.setRelativeXY(t,e,s)}getRelativeXY(){return new D(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=>de(o,r))}return n}intersectsWithRect(t,e){return Ct.intersectPolygonRectangle(this.getCoords(),t,e).status==="Intersection"}intersectsWithObject(t){const e=Ct.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 Ct.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 Vs(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(Ce,t),this._set(Ge,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?dn(dp(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.viewportTransform)||xe.concat()}calcACoords(){const t=To({angle:this.angle}),{x:e,y:s}=this.getRelativeCenterPoint(),i=Ao(e,s),n=It(i,t),r=this._getTransformedDimensions(),o=r.x/2,h=r.y/2;return{tl:de({x:-o,y:-h},n),tr:de({x:o,y:-h},n),bl:de({x:-o,y:h},n),br:de({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,Bt(this.originX),Bt(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=It(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=gp(i);return this.ownMatrixCache={key:t,value:n},n}_getNonTransformedDimensions(){return new D(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 D(r*e.scaleX,o*e.scaleY):cc(r,o,$a(e)),h.scalarAdd(n)}translateToGivenOrigin(t,e,s,i,n){let r=t.x,o=t.y;const h=Bt(i)-Bt(e),l=Bt(n)-Bt(s);if(h||l){const d=this._getTransformedDimensions();r+=h*d.x,o+=l*d.y}return new D(r,o)}translateToCenterPoint(t,e,s){if(e===Q&&s===Q)return t;const i=this.translateToGivenOrigin(t,e,s,Q,Q);return this.angle?i.rotate(Ot(this.angle),t):i}translateToOriginPoint(t,e,s){const i=this.translateToGivenOrigin(t,Q,Q,e,s);return this.angle?i.rotate(Ot(this.angle),t):i}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?de(t,this.group.calcTransformMatrix()):t}getRelativeCenterPoint(){return this.translateToCenterPoint(new D(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(),lt,Ie)}}const hy=["type"],ly=["extraParam"];let yi=class jd extends ay{static getDefaults(){return jd.ownDefaults}get type(){const t=this.constructor.type;return t==="FabricObject"?"object":t.toLowerCase()}set type(t){pi("warn","Setting type has no effect",t)}constructor(t){super(),A(this,"_cacheContext",null),Object.assign(this,jd.ownDefaults),this.setOptions(t)}_createCacheCanvas(){this._cacheCanvas=Rt(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,s=t.height,i=at.maxCacheSideLimit,n=at.minCacheSideLimit;if(e<=i&&s<=i&&e*s<=at.perfLimitSizeTotal)return e<n&&(t.width=n),s<n&&(t.height=n),t;const r=e/s,[o,h]=Ua.limitDimsByArea(r),l=er(n,o,i),d=er(n,h,i);return e>l&&(t.zoomX/=e/l,t.width=l,t.capped=!0),s>d&&(t.zoomY/=s/d,t.height=d,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:s+2,height:i+2,zoomX:t.x,zoomY:t.y,x:s,y:i}}_updateCacheCanvas(){const t=this._cacheCanvas,e=this._cacheContext,s=this._limitCacheSize(this._getCacheCanvasDimensions()),i=at.minCacheSideLimit,n=s.width,r=s.height,o=s.zoomX,h=s.zoomY,l=n!==t.width||r!==t.height,d=this.zoomX!==o||this.zoomY!==h;if(!t||!e)return!1;let u,g,f=l||d,p=0,m=0,_=!1;if(l){const v=this._cacheCanvas.width,x=this._cacheCanvas.height,S=n>v||r>x;_=S||(n<.9*v||r<.9*x)&&v>i&&x>i,S&&!s.capped&&(n>i||r>i)&&(p=.1*n,m=.1*r)}return _p(this)&&this.path&&(f=!0,_=!0,p+=this.getHeightOfLine(0)*this.zoomX,m+=this.getHeightOfLine(0)*this.zoomY),!!f&&(_?(t.width=Math.ceil(n+p),t.height=Math.ceil(r+m)):(e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,t.width,t.height)),u=s.x/2,g=s.y/2,this.cacheTranslationX=Math.round(t.width/2-u)+u,this.cacheTranslationY=Math.round(t.height/2-g)+g,e.translate(this.cacheTranslationX,this.cacheTranslationY),e.scale(o,h),this.zoomX=o,this.zoomY=h,!0)}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 D(Math.abs(this.scaleX),Math.abs(this.scaleY));const t=Qn(this.calcTransformMatrix());return new D(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!==Ce&&t!==Ge||(e=this._constrainScale(e)),t===Ce&&e<0?(this.flipX=!this.flipX,e*=-1):t==="scaleY"&&e<0?(this.flipY=!this.flipY,e*=-1):t!=="shadow"||!e||e instanceof bi||(e=new bi(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),this.dirty=!1),t.restore())}drawSelectionBackground(t){}renderCache(t){t=t||{},this._cacheCanvas&&this._cacheContext||this._createCacheCanvas(),this.isCacheDirty()&&this._cacheContext&&(this.drawObject(this._cacheContext,t.forClipping),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===Ae&&this.hasFill()&&this.hasStroke()&&this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.needsItsOwnCache()||this.objectCaching&&(!this.parent||!this.parent.isOnACache()),this.ownCaching}willDrawShadow(){return!!this.shadow&&(this.shadow.offsetX!==0||this.shadow.offsetY!==0)}drawClipPathOnCache(t,e){if(t.save(),e.inverted?t.globalCompositeOperation="destination-out":t.globalCompositeOperation="destination-in",e.absolutePositioned){const s=je(this.calcTransformMatrix());t.transform(s[0],s[1],s[2],s[3],s[4],s[5])}e.transform(t),t.scale(1/e.zoomX,1/e.zoomY),t.drawImage(e._cacheCanvas,-e.cacheTranslationX,-e.cacheTranslationY),t.restore()}drawObject(t,e){const s=this.fill,i=this.stroke;e?(this.fill="black",this.stroke="",this._setClippingProperties(t)):this._renderBackground(t),this._render(t),this._drawClipPath(t,this.clipPath),this.fill=s,this.stroke=i}_drawClipPath(t,e){e&&(e._set("canvas",this.canvas),e.shouldCache(),e._transformDone=!0,e.renderCache({forClipping:!0}),this.drawClipPathOnCache(t,e))}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,rs(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&&(rs(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&&(1&e.length&&e.push(...e),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)||xe,o=n*i,h=r*i,l=e.nonScaling?new D(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*at.browserShadowBlurConstant*(o+h)*(l.x+l.y)/4,t.shadowOffsetX=e.offsetX*o*l.x,t.shadowOffsetY=e.offsetY*h*l.y}_removeShadow(t){this.shadow&&(t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0)}_applyPatternGradientTransform(t,e){if(!rs(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===Ae?(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=Rt(),r=this.getCanvasRetinaScaling(),o=i.x/this.scaleX/r,h=i.y/this.scaleY/r;n.width=Math.ceil(o),n.height=Math.ceil(h);const l=n.getContext("2d");l&&(l.beginPath(),l.moveTo(0,0),l.lineTo(o,0),l.lineTo(o,h),l.lineTo(0,h),l.closePath(),l.translate(o/2,h/2),l.scale(i.zoomX/this.scaleX/r,i.zoomY/this.scaleY/r),this._applyPatternGradientTransform(l,e),l.fillStyle=e.toLive(t),l.fill(),t.translate(-this.width/2-this.strokeWidth/2,-this.height/2-this.strokeWidth/2),t.scale(r*this.scaleX/i.zoomX,r*this.scaleY/i.zoomY),t.strokeStyle=(s=l.createPattern(n,"no-repeat"))!==null&&s!==void 0?s:"")}_findCenterFromElement(){return new D(this.left+this.width/2,this.top+this.height/2)}clone(t){const e=this.toObject(t);return this.constructor.fromObject(e)}cloneAsImage(t){const e=this.toCanvasElement(t);return new(N.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=Ou(this),s=this.group,i=this.shadow,n=Math.abs,r=t.enableRetinaScaling?sp():1,o=(t.multiplier||1)*r,h=t.canvasProvider||(x=>new th(x,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&kp(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&Du(this,this.getViewportTransform()),this.setCoords();const l=Rt(),d=this.getBoundingRect(),u=this.shadow,g=new D;if(u){const x=u.blur,S=u.nonScaling?new D(1,1):this.getObjectScaling();g.x=2*Math.round(n(u.offsetX)+x)*n(S.x),g.y=2*Math.round(n(u.offsetY)+x)*n(S.y)}const f=d.width+g.x,p=d.height+g.y;l.width=Math.ceil(f),l.height=Math.ceil(p);const m=h(l);t.format==="jpeg"&&(m.backgroundColor="#fff"),this.setPositionByOrigin(new D(m.width/2,m.height/2),Q,Q);const _=this.canvas;m._objects=[this],this.set("canvas",m),this.setCoords();const v=m.toCanvasElement(o||1,t);return this.set("canvas",_),this.shadow=i,s&&(this.group=s),this.set(e),this.setCoords(),m._objects=[],m.destroy(),v}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return xu(this.toCanvasElement(t),t.format||"png",t.quality||1)}isType(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];return e.includes(this.constructor.type)||e.includes(this.type)}complexity(){return 1}toJSON(){return this.toObject()}rotate(t){const{centeredRotation:e,originX:s,originY:i}=this;if(e){const{x:n,y:r}=this.getRelativeCenterPoint();this.originX=Q,this.originY=Q,this.left=n,this.top=r}if(this.set("angle",t),e){const{x:n,y:r}=this.translateToOriginPoint(this.getRelativeCenterPoint(),s,i);this.left=n,this.top=r,this.originX=s,this.originY=i}}setOnGroup(){}_setupCompositeOperation(t){this.globalCompositeOperation&&(t.globalCompositeOperation=this.globalCompositeOperation)}dispose(){nc.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&zs().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:l}=s,d=T(T({},s),{},{target:this,startValue:o??i.reduce((u,g)=>u[g],this),endValue:e,abort:r==null?void 0:r.bind(this),onChange:(u,g,f)=>{i.reduce((p,m,_)=>(_===i.length-1&&(p[m]=u),p[m]),this),h&&h(u,g,f)},onComplete:(u,g,f)=>{this.setCoords(),l&&l(u,g,f)}});return n?Yp(d):zu(d)}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(jd.customProperties,this.constructor.customProperties||[]);let e;const s=at.NUM_FRACTION_DIGITS,{clipPath:i,fill:n,stroke:r,shadow:o,strokeDashArray:h,left:l,top:d,originX:u,originY:g,width:f,height:p,strokeWidth:m,strokeLineCap:_,strokeDashOffset:v,strokeLineJoin:x,strokeUniform:S,strokeMiterLimit:C,scaleX:E,scaleY:M,angle:k,flipX:O,flipY:P,opacity:L,visible:F,backgroundColor:W,fillRule:B,paintFirst:z,globalCompositeOperation:K,skewX:tt,skewY:V}=this;i&&!i.excludeFromExport&&(e=i.toObject(t.concat("inverted","absolutePositioned")));const H=Zt=>xt(Zt,s),Jt=T(T({},Jn(this,t)),{},{type:this.constructor.type,version:fu,originX:u,originY:g,left:H(l),top:H(d),width:H(f),height:H(p),fill:vp(n)?n.toObject():n,stroke:vp(r)?r.toObject():r,strokeWidth:H(m),strokeDashArray:h&&h.concat(),strokeLineCap:_,strokeDashOffset:v,strokeLineJoin:x,strokeUniform:S,strokeMiterLimit:H(C),scaleX:H(E),scaleY:H(M),angle:H(k),flipX:O,flipY:P,opacity:H(L),shadow:o&&o.toObject(),visible:F,backgroundColor:W,fillRule:B,paintFirst:z,globalCompositeOperation:K,skewX:H(tt),skewY:H(V)},e?{clipPath:e}:null);return this.includeDefaultValues?Jt:this._removeDefaultValues(Jt)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),s=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return Au(t,(i,n)=>{if(n===lt||n===Ie||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=wt(t,hy),s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{extraParam:i}=s,n=wt(s,ly);return Qa(e,n).then(r=>i?(delete r[i],new this(e[i],r)):new this(r))}static fromObject(t,e){return this._fromObject(t,e)}};A(yi,"stateProperties",Kv),A(yi,"cacheProperties",vi),A(yi,"ownDefaults",Qv),A(yi,"type","FabricObject"),A(yi,"colorProperties",[Ft,Ae,"backgroundColor"]),A(yi,"customProperties",[]),N.setClass(yi),N.setClass(yi,"object");const Oo=(a,t,e)=>(s,i,n,r)=>{const o=t(s,i,n,r);return o&&Op(a,T(T({},Lp(s,i,n,r)),e)),o};function Do(a){return(t,e,s,i)=>{const{target:n,originX:r,originY:o}=e,h=n.getRelativeCenterPoint(),l=n.translateToOriginPoint(h,r,o),d=a(t,e,s,i);return n.setPositionByOrigin(l,e.originX,e.originY),d}}const qp=Oo(Ya,Do((a,t,e,s)=>{const i=Pu(t,t.originX,t.originY,e,s);if(Bt(t.originX)===Bt(Q)||Bt(t.originX)===Bt(Lt)&&i.x<0||Bt(t.originX)===Bt(lt)&&i.x>0){const{target:n}=t,r=n.strokeWidth/(n.strokeUniform?n.scaleX:1),o=Dp(t)?2:1,h=n.width,l=Math.abs(i.x*o/n.scaleX)-r;return n.set("width",Math.max(l,1)),h!==n.width}return!1}));function cy(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?Ae:Ft,l=!o&&(s.cornerStrokeColor||i.cornerStrokeColor);let d,u=t,g=e;a.save(),a.fillStyle=s.cornerColor||i.cornerColor||"",a.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",n>r?(d=n,a.scale(1,r/n),g=e*n/r):r>n?(d=r,a.scale(n/r,1),u=t*r/n):d=n,a.lineWidth=1,a.beginPath(),a.arc(u,g,d/2,0,mi,!1),a[h](),l&&a.stroke(),a.restore()}function dy(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?Ae:Ft,l=!o&&(s.cornerStrokeColor||i.cornerStrokeColor),d=n/2,u=r/2;a.save(),a.fillStyle=s.cornerColor||i.cornerColor||"",a.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",a.lineWidth=1,a.translate(t,e);const g=i.getTotalAngle();a.rotate(Ot(g)),a["".concat(h,"Rect")](-d,-u,n,r),l&&a.strokeRect(-d,-u,n,r),a.restore()}class Ss{constructor(t){A(this,"visible",!0),A(this,"actionName",sc),A(this,"angle",0),A(this,"x",0),A(this,"y",0),A(this,"offsetX",0),A(this,"offsetY",0),A(this,"sizeX",0),A(this,"sizeY",0),A(this,"touchSizeX",0),A(this,"touchSizeY",0),A(this,"cursorStyle","crosshair"),A(this,"withConnection",!1),Object.assign(this,t)}shouldActivate(t,e,s,i){var n;let{tl:r,tr:o,br:h,bl:l}=i;return((n=e.canvas)===null||n===void 0?void 0:n.getActiveObject())===e&&e.isControlVisible(t)&&Ct.isPointInPolygon(s,[r,o,h,l])}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 D(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(e)}calcCornerCoords(t,e,s,i,n,r){const o=oc([Ao(s,i),To({angle:t}),ac((n?this.touchSizeX:this.sizeX)||e,(n?this.touchSizeY:this.sizeY)||e)]);return{tl:new D(-.5,-.5).transform(o),tr:new D(.5,-.5).transform(o),br:new D(.5,.5).transform(o),bl:new D(-.5,.5).transform(o)}}render(t,e,s,i,n){((i=i||{}).cornerStyle||n.cornerStyle)==="circle"?cy.call(this,t,e,s,i,n):dy.call(this,t,e,s,i,n)}}const uy=(a,t,e)=>e.lockRotation?dc:t.cursorStyle,gy=Oo(np,Do((a,t,e,s)=>{let{target:i,ex:n,ey:r,theta:o,originX:h,originY:l}=t;const d=i.translateToOriginPoint(i.getRelativeCenterPoint(),h,l);if(ws(i,"lockRotation"))return!1;const u=Math.atan2(r-d.y,n-d.x),g=Math.atan2(s-d.y,e-d.x);let f=dn(g-u+o);if(i.snapAngle&&i.snapAngle>0){const m=i.snapAngle,_=i.snapThreshold||m,v=Math.ceil(f/m)*m,x=Math.floor(f/m)*m;Math.abs(f-x)<_?f=x:Math.abs(f-v)<_&&(f=v)}f<0&&(f=360+f),f%=360;const p=i.angle!==f;return i.angle=f,p}));function $p(a,t){const e=t.canvas,s=a[e.uniScaleKey];return e.uniformScaling&&!s||!e.uniformScaling&&s}function Kp(a,t,e){const s=ws(a,"lockScalingX"),i=ws(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 fy=["e","se","s","sw","w","nw","n","ne","e"],sh=(a,t,e)=>{const s=$p(a,e);if(Kp(e,t.x!==0&&t.y===0?"x":t.x===0&&t.y!==0?"y":"",s))return dc;const i=Fp(e,t);return"".concat(fy[i],"-resize")};function Vu(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{};const n=t.target,r=i.by,o=$p(a,n);let h,l,d,u,g,f;if(Kp(n,r,o))return!1;if(t.gestureScale)l=t.scaleX*t.gestureScale,d=t.scaleY*t.gestureScale;else{if(h=Pu(t,t.originX,t.originY,e,s),g=r!=="y"?Math.sign(h.x||t.signX||1):1,f=r!=="x"?Math.sign(h.y||t.signY||1):1,t.signX||(t.signX=g),t.signY||(t.signY=f),ws(n,"lockScalingFlip")&&(t.signX!==g||t.signY!==f))return!1;if(u=n._getTransformedDimensions(),o&&!r){const _=Math.abs(h.x)+Math.abs(h.y),{original:v}=t,x=_/(Math.abs(u.x*v.scaleX/n.scaleX)+Math.abs(u.y*v.scaleY/n.scaleY));l=v.scaleX*x,d=v.scaleY*x}else l=Math.abs(h.x*n.scaleX/u.x),d=Math.abs(h.y*n.scaleY/u.y);Dp(t)&&(l*=2,d*=2),t.signX!==g&&r!=="y"&&(t.originX=Pp(t.originX),l*=-1,t.signX=g),t.signY!==f&&r!=="x"&&(t.originY=Pp(t.originY),d*=-1,t.signY=f)}const p=n.scaleX,m=n.scaleY;return r?(r==="x"&&n.set(Ce,l),r==="y"&&n.set(Ge,d)):(!ws(n,"lockScalingX")&&n.set(Ce,l),!ws(n,"lockScalingY")&&n.set(Ge,d)),p!==n.scaleX||m!==n.scaleY}const bc=Oo(tc,Do((a,t,e,s)=>Vu(a,t,e,s))),py=Oo(tc,Do((a,t,e,s)=>Vu(a,t,e,s,{by:"x"}))),my=Oo(tc,Do((a,t,e,s)=>Vu(a,t,e,s,{by:"y"}))),by=["target","ex","ey","skewingSide"],Gu={x:{counterAxis:"y",scale:Ce,skew:xo,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:Ge,skew:So,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},vy=["ns","nesw","ew","nwse"],yy=(a,t,e)=>{if(t.x!==0&&ws(e,"lockSkewingY")||t.y!==0&&ws(e,"lockSkewingX"))return dc;const s=Fp(e,t)%4;return"".concat(vy[s],"-resize")};function Qp(a,t,e,s,i){const{target:n}=e,{counterAxis:r,origin:o,lockSkewing:h,skew:l,flip:d}=Gu[a];if(ws(n,h))return!1;const{origin:u,flip:g}=Gu[r],f=Bt(e[u])*(n[g]?-1:1),p=-Math.sign(f)*(n[d]?-1:1),m=.5*-((n[l]===0&&Pu(e,Q,Q,s,i)[a]>0||n[l]>0?1:-1)*p)+.5;return Oo(rp,Do((v,x,S,C)=>function(E,M,k){let{target:O,ex:P,ey:L,skewingSide:F}=M,W=wt(M,by);const{skew:B}=Gu[E],z=k.subtract(new D(P,L)).divide(new D(O.scaleX,O.scaleY))[E],K=O[B],tt=W[B],V=Math.tan(Ot(tt)),H=E==="y"?O._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:O._getTransformedDimensions({scaleX:1,scaleY:1}).y,Jt=2*z*F/Math.max(H,1)+V,Zt=dn(Math.atan(Jt));O.set(B,Zt);const ce=K!==O[B];if(ce&&E==="y"){const{skewX:zt,scaleX:_t}=O,Le=O._getTransformedDimensions({skewY:K}),gi=O._getTransformedDimensions(),Pt=zt!==0?Le.x/gi.x:1;Pt!==1&&O.set(Ce,Pt*_t)}return ce}(a,x,new D(S,C))))(t,T(T({},e),{},{[o]:m,skewingSide:p}),s,i)}const _y=(a,t,e,s)=>Qp("x",a,t,e,s),wy=(a,t,e,s)=>Qp("y",a,t,e,s);function vc(a,t){return a[t.canvas.altActionKey]}const yc=(a,t,e)=>{const s=vc(a,e);return t.x===0?s?xo:Ge:t.y===0?s?So:Ce:""},Po=(a,t,e)=>vc(a,e)?yy(0,t,e):sh(a,t,e),Jp=(a,t,e,s)=>vc(a,t.target)?wy(a,t,e,s):py(a,t,e,s),Zp=(a,t,e,s)=>vc(a,t.target)?_y(a,t,e,s):my(a,t,e,s),tm=()=>({ml:new Ss({x:-.5,y:0,cursorStyleHandler:Po,actionHandler:Jp,getActionName:yc}),mr:new Ss({x:.5,y:0,cursorStyleHandler:Po,actionHandler:Jp,getActionName:yc}),mb:new Ss({x:0,y:.5,cursorStyleHandler:Po,actionHandler:Zp,getActionName:yc}),mt:new Ss({x:0,y:-.5,cursorStyleHandler:Po,actionHandler:Zp,getActionName:yc}),tl:new Ss({x:-.5,y:-.5,cursorStyleHandler:sh,actionHandler:bc}),tr:new Ss({x:.5,y:-.5,cursorStyleHandler:sh,actionHandler:bc}),bl:new Ss({x:-.5,y:.5,cursorStyleHandler:sh,actionHandler:bc}),br:new Ss({x:.5,y:.5,cursorStyleHandler:sh,actionHandler:bc}),mtr:new Ss({x:0,y:-.5,actionHandler:gy,cursorStyleHandler:uy,offsetY:-40,withConnection:!0,actionName:yu})}),xy=()=>({mr:new Ss({x:.5,y:0,actionHandler:qp,cursorStyleHandler:Po,actionName:Ya}),ml:new Ss({x:-.5,y:0,actionHandler:qp,cursorStyleHandler:Po,actionName:Ya})}),Sy=()=>T(T({},tm()),xy());class ih extends yi{static getDefaults(){return T(T({},super.getDefaults()),ih.ownDefaults)}constructor(t){super(),Object.assign(this,this.constructor.createControls(),ih.ownDefaults),this.setOptions(t)}static createControls(){return{controls:tm()}}_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(sc))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=Ao(e.x,e.y),i=To({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),n=It(s,i),r=It(t,n),o=It(r,[1/t[0],0,0,1/t[3],0,0]),h=this.group?Qn(this.calcTransformMatrix()):void 0;h&&(h.scaleX=Math.abs(h.scaleX),h.scaleY=Math.abs(h.scaleY));const l=this._calculateCurrentDimensions(h),d={};return this.forEachControl((u,g)=>{const f=u.positionHandler(l,o,this,u);d[g]=Object.assign(f,this._calcCornerCoords(u,f))}),d}_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(Ot(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,l=It(r,this.calcTransformMatrix()),d=Qn(l);t.save(),t.translate(d.translateX,d.translateY),t.lineWidth=1*this.borderScaleFactor,this.group===this.parent&&(t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1),this.flipX&&(d.angle-=180),t.rotate(Ot(this.group?d.angle:this.angle)),o&&this.drawBorders(t,d,e),h&&this.drawControls(t,e),t.restore()}drawBorders(t,e,s){let i;if(s&&s.forActiveSelection||this.group){const n=cc(this.width,this.height,$a(e)),r=this.isStrokeAccountedForInDimensions()?wu:(this.strokeUniform?new D().scalarAdd(this.canvas?this.canvas.getZoom():1):new D(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,l)=>{if(h.getVisibility(this,l)){const d=this.oCoords[l];h.render(t,d.x,d.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 em(a,t){return t.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(s=>{s!=="constructor"&&Object.defineProperty(a.prototype,s,Object.getOwnPropertyDescriptor(e.prototype,s)||Object.create(null))})}),a}A(ih,"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 ue extends ih{}em(ue,[Rp]),N.setClass(ue),N.setClass(ue,"object");const sm=(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 im{constructor(t){this.options=t,this.strokeProjectionMagnitude=this.options.strokeWidth/2,this.scale=new D(this.options.scaleX,this.options.scaleY),this.strokeUniformScalar=this.options.strokeUniform?new D(1/this.options.scaleX,1/this.options.scaleY):new D(1,1)}createSideVector(t,e){const s=gc(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 D(t);return e.y+=e.x*Math.tan(Ot(this.options.skewY)),e.x+=e.y*Math.tan(Ot(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}const Cy=new D;class Lo extends im{static getOrthogonalRotationFactor(t,e){const s=e?pc(t,e):Hp(t);return Math.abs(s)<hn?-1:1}constructor(t,e,s,i){super(i),A(this,"AB",void 0),A(this,"AC",void 0),A(this,"alpha",void 0),A(this,"bisector",void 0),this.A=new D(t),this.B=new D(e),this.C=new D(s),this.AB=this.createSideVector(this.A,this.B),this.AC=this.createSideVector(this.A,this.C),this.alpha=pc(this.AB,this.AC),this.bisector=mc(Iu(this.AB.eq(Cy)?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=ju(i),r=Lo.getOrthogonalRotationFactor(n,this.bisector);return this.scaleUnitVector(n,s*r)}projectBevel(){const t=[];return(this.alpha%mi==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?fc(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return fc(i)/this.strokeProjectionMagnitude<=n&&t.push(this.applySkew(this.A.add(i))),t.push(...this.projectBevel()),t}projectRoundNoSkew(t,e){const s=[],i=new D(Lo.getOrthogonalRotationFactor(this.bisector),Lo.getOrthogonalRotationFactor(new D(this.bisector.y,this.bisector.x)));return[new D(1,0).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i),new D(0,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i)].forEach(n=>{Nu(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,l=new D(Math.tan(Ot(i)),Math.tan(Ot(n))),d=this.strokeProjectionMagnitude,u=h?d/o/Math.sqrt(1/o**2+1/r**2*l.y**2):d/Math.sqrt(1+l.y**2),g=new D(Math.sqrt(Math.max(d**2-u**2,0)),u),f=h?d/Math.sqrt(1+l.x**2*(1/o)**2/(1/r+1/r*l.x*l.y)**2):d/Math.sqrt(1+l.x**2/(1+l.x*l.y)**2),p=new D(f,Math.sqrt(Math.max(d**2-f**2,0)));return[p,p.scalarMultiply(-1),g,g.scalarMultiply(-1)].map(m=>this.applySkew(h?m.multiply(this.strokeUniformScalar):m)).forEach(m=>{Nu(m,t,e)&&s.push(this.applySkew(this.A).add(m))}),s}projectRound(){const t=[];t.push(...this.projectBevel());const e=this.alpha%mi==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=Mo(i,r)>0,h=o?i:n,l=o?n:i;return this.isSkewed()?t.push(...this.projectRoundWithSkew(h,l)):t.push(...this.projectRoundNoSkew(h,l)),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 nm extends im{constructor(t,e,s){super(s),this.A=new D(t),this.T=new D(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(ju(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 D(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 Lo(this.A,this.T,this.T,this.options).projectRound());return t}projectSquare(){const t=[];if(this.A.eq(this.T)){const e=new D(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(mc(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 rm=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 D(r)),n),[new D(a[0])]);if(i.length===1)e=!0;else if(!e){const n=i[0],r=((o,h)=>{for(let l=o.length-1;l>=0;l--)if(h(o[l],l,o))return l;return-1})(i,o=>!o.eq(n));i.splice(r+1)}return i.forEach((n,r,o)=>{let h,l;r===0?(l=o[1],h=e?n:o[o.length-1]):r===o.length-1?(h=o[r-1],l=e?n:o[0]):(h=o[r-1],l=o[r+1]),e&&o.length===1?s.push(...new nm(n,n,t).project()):!e||r!==0&&r!==o.length-1?s.push(...new Lo(n,h,l,t).project()):s.push(...new nm(n,r===0?l:h,t).project())}),s},Uu=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},om=a=>a.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&apos;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),_c=a=>{const t=[];for(let e,s=0;s<a.length;s++)(e=Ay(a,s))!==!1&&t.push(e);return t},Ay=(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 Ty=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:om,graphemeSplit:_c});const wc=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)},am=(a,t)=>{const e=t.split(`
38
+ `),s=[];let i=-1,n={};a=Uu(a);for(let r=0;r<e.length;r++){const o=_c(e[r]);if(a[r])for(let h=0;h<o.length;h++){i++;const l=a[r][h];l&&Object.keys(l).length>0&&(wc(n,l,!0)?s.push({start:i,end:i+1,style:l}):s[s.length-1].end++),n=l||{}}else i+=o.length,n={}}return s},hm=(a,t)=>{if(!Array.isArray(a))return Uu(a);const e=t.split(vu),s={};let i=-1,n=0;for(let r=0;r<e.length;r++){const o=_c(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},un=["display","transform",Ft,"fill-opacity","fill-rule","opacity",Ae,"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 lm(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 Ey(a,t){let e=!0;const s=lm(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=lm(i=i.parentElement,r);return n.length===0}(a,t)),s&&e&&t.length===0}const ky=a=>{var t;return(t=Uv[a])!==null&&t!==void 0?t:a},My=new RegExp("(".concat(xs,")"),"gi"),Oy=a=>a.replace(My," $1 ").replace(/,/gi," ").replace(/\s+/gi," ");var cm,dm,um,gm,fm,pm,mm;const Ee="(".concat(xs,")"),Dy=String.raw(cm||(cm=an(["(skewX)(",")"],["(skewX)\\(","\\)"])),Ee),Py=String.raw(dm||(dm=an(["(skewY)(",")"],["(skewY)\\(","\\)"])),Ee),Ly=String.raw(um||(um=an(["(rotate)(","(?: "," ",")?)"],["(rotate)\\(","(?: "," ",")?\\)"])),Ee,Ee,Ee),Fy=String.raw(gm||(gm=an(["(scale)(","(?: ",")?)"],["(scale)\\(","(?: ",")?\\)"])),Ee,Ee),Ry=String.raw(fm||(fm=an(["(translate)(","(?: ",")?)"],["(translate)\\(","(?: ",")?\\)"])),Ee,Ee),Iy=String.raw(pm||(pm=an(["(matrix)("," "," "," "," "," ",")"],["(matrix)\\("," "," "," "," "," ","\\)"])),Ee,Ee,Ee,Ee,Ee,Ee),Yu="(?:".concat(Iy,"|").concat(Ry,"|").concat(Ly,"|").concat(Fy,"|").concat(Dy,"|").concat(Py,")"),jy="(?:".concat(Yu,"*)"),Ny=String.raw(mm||(mm=an(["^s*(?:","?)s*$"],["^\\s*(?:","?)\\s*$"])),jy),By=new RegExp(Ny),Hy=new RegExp(Yu),Wy=new RegExp(Yu,"g");function xc(a){const t=[];if(!(a=Oy(a).replace(/\s*([()])\s*/gi,"$1"))||a&&!By.test(a))return[...xe];for(const e of a.matchAll(Wy)){const s=Hy.exec(e[0]);if(!s)continue;let i=xe;const n=s.filter(p=>!!p),[,r,...o]=n,[h,l,d,u,g,f]=o.map(p=>parseFloat(p));switch(r){case"translate":i=Ao(h,l);break;case yu:i=To({angle:h},{x:l,y:d});break;case sc:i=ac(h,l);break;case xo:i=Su(h);break;case So:i=Cu(h);break;case"matrix":i=[h,l,d,u,g,f]}t.push(i)}return oc(t)}function Xy(a,t,e,s){const i=Array.isArray(t);let n,r=t;if(a!==Ft&&a!==Ae||t!==Se){if(a==="strokeUniform")return t==="non-scaling-stroke";if(a==="strokeDashArray")r=t===Se?null:t.replace(/,/g," ").split(/\s+/).map(parseFloat);else if(a==="transformMatrix")r=e&&e.transformMatrix?It(e.transformMatrix,xc(t)):xc(t);else if(a==="visible")r=t!==Se&&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"?lt:t==="end"?Lt:Q;else if(a==="charSpacing")n=Te(t,s)/s*1e3;else if(a==="paintFirst"){const o=t.indexOf(Ft),h=t.indexOf(Ae);r=Ft,(o>-1&&h>-1&&h<o||o===-1&&h>-1)&&(r=Ae)}else{if(a==="href"||a==="xlink:href"||a==="font"||a==="id")return t;if(a==="imageSmoothing")return t==="optimizeQuality";n=i?t.map(Te):Te(t,s)}}else r="";return!i&&isNaN(n)?r:n}function zy(a,t){const e=a.match(Gv);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=Te(n)),o&&(t.fontFamily=o),r&&(t.lineHeight=r==="normal"?1:r)}function qu(a,t){a.replace(/;\s*$/,"").split(";").forEach(e=>{if(!e)return;const[s,i]=e.split(":");t[s.trim().toLowerCase()]=i.trim()})}function Vy(a){const t={},e=a.getAttribute("style");return e&&(typeof e=="string"?qu(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 Gy={stroke:"strokeOpacity",fill:"fillOpacity"};function _i(a,t,e){if(!a)return{};let s,i={},n=mu;a.parentNode&&jp.test(a.parentNode.nodeName)&&(i=_i(a.parentElement,t,e),i.fontSize&&(s=n=Te(i.fontSize)));const r=T(T(T({},t.reduce((l,d)=>{const u=a.getAttribute(d);return u&&(l[d]=u),l},{})),function(l){let d=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},u={};for(const g in d)Ey(l,g.split(" "))&&(u=T(T({},u),d[g]));return u}(a,e)),Vy(a));r[Ru]&&a.setAttribute(Ru,r[Ru]),r[Fu]&&(s=Te(r[Fu],n),r[Fu]="".concat(s));const o={};for(const l in r){const d=ky(l),u=Xy(d,r[l],i,s);o[d]=u}o&&o.font&&zy(o.font,o);const h=T(T({},i),o);return jp.test(a.nodeName)?h:function(l){const d=ue.getDefaults();return Object.entries(Gy).forEach(u=>{let[g,f]=u;if(l[f]===void 0||l[g]==="")return;if(l[g]===void 0){if(!d[g])return;l[g]=d[g]}if(l[g].indexOf("url(")===0)return;const p=new ut(l[g]);l[g]=p.setAlpha(xt(p.getAlpha()*l[f],2)).toRgba()}),l}(h)}const Uy=["left","top","width","height","visible"],bm=["rx","ry"];class Gs extends ue{static getDefaults(){return T(T({},super.getDefaults()),Gs.ownDefaults)}constructor(t){super(),Object.assign(this,Gs.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-ln*r,n,i+e,n+ln*o,i+e,n+o),t.lineTo(i+e,n+s-o),h&&t.bezierCurveTo(i+e,n+s-ln*o,i+e-ln*r,n+s,i+e-r,n+s),t.lineTo(i+r,n+s),h&&t.bezierCurveTo(i+ln*r,n+s,i,n+s-ln*o,i,n+s-o),t.lineTo(i,n+o),h&&t.bezierCurveTo(i,n+ln*o,i+ln*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([...bm,...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=_i(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,width:o=0,height:h=0,visible:l=!0}=i,d=wt(i,Uy);return new this(T(T(T({},e),d),{},{left:n,top:r,width:o,height:h,visible:!!(l&&o&&h)}))}}A(Gs,"type","Rect"),A(Gs,"cacheProperties",[...vi,...bm]),A(Gs,"ownDefaults",{rx:0,ry:0}),A(Gs,"ATTRIBUTE_NAMES",[...un,"x","y","rx","ry","width","height"]),N.setClass(Gs),N.setSVGClass(Gs);const wi="initialization",Sc="added",$u="removed",Cc="imperative",vm=(a,t)=>{const{strokeUniform:e,strokeWidth:s,width:i,height:n,group:r}=t,o=r&&r!==a?eh(r.calcTransformMatrix(),a.calcTransformMatrix()):null,h=o?t.getRelativeCenterPoint().transform(o):t.getRelativeCenterPoint(),l=!t.isStrokeAccountedForInDimensions(),d=e&&l?Mp(new D(s,s),void 0,a.calcTransformMatrix()):wu,u=!e&&l?s:0,g=cc(i+u,n+u,oc([o,t.calcOwnMatrix()],!0)).add(d).scalarDivide(2);return[h.subtract(g),h.add(g)]};class Ac{calcLayoutResult(t,e){if(this.shouldPerformLayout(t))return this.calcBoundingBox(e,t)}shouldPerformLayout(t){let{type:e,prevStrategy:s,strategy:i}=t;return e===wi||e===Cc||!!s&&i!==s}shouldLayoutClipPath(t){let{type:e,target:{clipPath:s}}=t;return e!==wi&&s&&!s.absolutePositioned}getInitialSize(t,e){return e.size}calcBoundingBox(t,e){const{type:s,target:i}=e;if(s===Cc&&e.overrides)return e.overrides;if(t.length===0)return;const{left:n,top:r,width:o,height:h}=Vs(t.map(u=>vm(i,u)).reduce((u,g)=>u.concat(g),[])),l=new D(o,h),d=new D(n,r).add(l.scalarDivide(2));if(s===wi){const u=this.getInitialSize(e,{size:l,center:d});return{center:d,relativeCorrection:new D(0,0),size:u}}return{center:d.transform(i.calcOwnMatrix()),size:l}}}A(Ac,"type","strategy");class Ku extends Ac{shouldPerformLayout(t){return!0}}A(Ku,"type","fit-content"),N.setClass(Ku);const Yy=["strategy"],qy=["target","strategy","bubbles","prevStrategy"],ym="layoutManager";class nh{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:new Ku;A(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[ic,ip,Ya,np,tc,rp,ec,Iv,jv].map(i=>t.on(i,n=>this.performLayout(i===ic?{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===wi||s===Sc?this.subscribeTargets(t):s===$u&&this.unsubscribeTargets(t),e.fire("layout:before",{context:t}),i&&i.fire("object:layout:before",{target:e,context:t}),s===Cc&&t.deep){const n=wt(t,Yy);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===wi?new D:e.getRelativeCenterPoint(),{center:o,correction:h=new D,relativeCorrection:l=new D}=n,d=r.subtract(o).add(h).transform(i===wi?xe:je(e.calcOwnMatrix()),!0).add(l);return{result:n,prevCenter:r,nextCenter:o,offset:d}}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===wi?s.set({left:(r=t.x)!==null&&r!==void 0?r:n.x+i.x*Bt(s.originX),top:(o=t.y)!==null&&o!==void 0?o:n.y+i.y*Bt(s.originY)}):(s.setPositionByOrigin(n,Q,Q),s.setCoords(),s.set("dirty",!0))}layoutObjects(t,e){const{target:s}=t;s.forEachObject(i=>{i.group===s&&this.layoutObject(t,e,i)}),t.strategy.shouldLayoutClipPath(t)&&this.layoutObject(t,e,s.clipPath)}layoutObject(t,e,s){let{offset:i}=e;s.set({left:s.left+i.x,top:s.top+i.y})}onAfterLayout(t,e){const{target:s,strategy:i,bubbles:n,prevStrategy:r}=t,o=wt(t,qy),{canvas:h}=s;s.fire("layout:after",{context:t,result:e}),h&&h.fire("object:layout:after",{context:t,result:e,target:s});const l=s.parent;n&&l!=null&&l.layoutManager&&((o.path||(o.path=[])).push(s),l.layoutManager.performLayout(T(T({},o),{},{target:l}))),s.set("dirty",!0)}dispose(){const{_subscriptions:t}=this;t.forEach(e=>e.forEach(s=>s())),t.clear()}toObject(){return{type:ym,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}N.setClass(nh,ym);const $y=["type","objects","layoutManager"];class Ky extends nh{performLayout(){}}class Us extends op(ue){static getDefaults(){return T(T({},super.getDefaults()),Us.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),A(this,"_activeObjects",[]),A(this,"__objectSelectionTracker",void 0),A(this,"__objectSelectionDisposer",void 0),Object.assign(this,Us.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 nh,this.layoutManager.performLayout({type:wi,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(pi("error","Group: circular object trees are not supported, this call has no effect"),!1):this._objects.indexOf(t)===-1||(pi("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(Sc,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(Sc,n),r}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange($u,t),t}_onObjectAdded(t){this.enterGroup(t,!0),this.fire("object:added",{target:t}),t.fire("added",{target:this})}_onObjectRemoved(t,e){this.exitGroup(t,e),this.fire("object:removed",{target:t}),t.fire("removed",{target:this})}_onAfterObjectsChange(t,e){this.layoutManager.performLayout({type:t,targets:e,target:this})}_onStackOrderChanged(){this._set("dirty",!0)}_set(t,e){const s=this[t];return super._set(t,e),t==="canvas"&&s!==e&&(this._objects||[]).forEach(i=>{i._set(t,e)}),this}_shouldSetNestedCoords(){return this.subTargetCheck}removeAll(){return this._activeObjects=[],this.remove(...this._objects)}__objectSelectionMonitor(t,e){let{target:s}=e;const i=this._activeObjects;if(t)i.push(s),this._set("dirty",!0);else if(i.length>0){const n=i.indexOf(s);n>-1&&(i.splice(n,1),this._set("dirty",!0))}}_watchObject(t,e){t&&this._watchObject(!1,e),t?(e.on("selected",this.__objectSelectionTracker),e.on("deselected",this.__objectSelectionDisposer)):(e.off("selected",this.__objectSelectionTracker),e.off("deselected",this.__objectSelectionDisposer))}enterGroup(t,e){t.group&&t.group.remove(t),t._set("parent",this),this._enterGroup(t,e)}_enterGroup(t,e){e&&ko(t,It(je(this.calcTransformMatrix()),t.calcTransformMatrix())),this._shouldSetNestedCoords()&&t.setCoords(),t._set("group",this),t._set("canvas",this.canvas),this._watchObject(!0,t);const s=this.canvas&&this.canvas.getActiveObject&&this.canvas.getActiveObject();s&&(s===t||t.isDescendantOf(s))&&this._activeObjects.push(t)}exitGroup(t,e){this._exitGroup(t,e),t._set("parent",void 0),t._set("canvas",void 0)}_exitGroup(t,e){t._set("group",void 0),e||(ko(t,It(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=ue.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){this._renderBackground(t);for(let s=0;s<this._objects.length;s++){var e;(e=this.canvas)!==null&&e!==void 0&&e.preserveObjectStacking&&this._objects[s].group!==this?(t.save(),t.transform(...je(this.calcTransformMatrix())),this._objects[s].render(t),t.restore()):this._objects[s].group===this&&this._objects[s].render(t)}this._drawClipPath(t,this.clipPath)}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:Cc},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=Gs.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=St(t,Uy);return Promise.all([Eo(i,e),Qa(r,e)]).then(o=>{let[h,l]=o;const d=new this(h,T(T(T({},r),l),{},{layoutManager:new Yy}));if(n){const u=X.getClass(n.type),g=X.getClass(n.strategy);d.layoutManager=new u(new g)}else d.layoutManager=new nh;return d.layoutManager.subscribeTargets({type:wi,target:d,targets:d.getObjects()}),d.setCoords(),d})}}A(Us,"type","Group"),A(Us,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),X.setClass(Us);const ym=(a,t)=>Math.min(t.width/a.width,t.height/a.height),_m=(a,t)=>Math.max(t.width/a.width,t.height/a.height),Ku="\\s*,?\\s*",rh="".concat(Ku,"(").concat(xs,")"),qy="".concat(rh).concat(rh).concat(rh).concat(Ku,"([01])").concat(Ku,"([01])").concat(rh).concat(rh),$y={m:"l",M:"L"},Ky=(a,t,e,s,i,n,r,o,h,l,d)=>{const u=vs(a),g=ys(a),f=vs(t),p=ys(t),m=e*i*f-s*n*p+r,w=s*i*f+e*n*p+o;return["C",l+h*(-e*i*g-s*n*u),d+h*(-s*i*g+e*n*u),m+h*(e*i*p+s*n*f),w+h*(s*i*p-e*n*f),m,w]},wm=(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 Qu(a,t,e,s,i,n,r,o){let h;if(at.cachesBoundsOfCurve&&(h=[...arguments].join(),Ua.boundsOfCurveCache[h]))return Ua.boundsOfCurveCache[h];const l=Math.sqrt,d=Math.abs,u=[],g=[[0,0],[0,0]];let f=6*a-12*e+6*i,p=-3*a+9*e-9*i+3*r,m=3*e-3*a;for(let C=0;C<2;++C){if(C>0&&(f=6*t-12*s+6*n,p=-3*t+9*s-9*n+3*o,m=3*s-3*t),d(p)<1e-12){if(d(f)<1e-12)continue;const R=-m/f;0<R&&R<1&&u.push(R);continue}const E=f*f-4*m*p;if(E<0)continue;const k=l(E),P=(-f+k)/(2*p);0<P&&P<1&&u.push(P);const D=(-f-k)/(2*p);0<D&&D<1&&u.push(D)}let w=u.length;const v=w,x=Sm(a,t,e,s,i,n,r,o);for(;w--;){const{x:C,y:E}=x(u[w]);g[0][w]=C,g[1][w]=E}g[0][v]=a,g[1][v]=t,g[0][v+1]=r,g[1][v+1]=o;const S=[new M(Math.min(...g[0]),Math.min(...g[1])),new M(Math.max(...g[0]),Math.max(...g[1]))];return at.cachesBoundsOfCurve&&(Ua.boundsOfCurveCache[h]=S),S}const Qy=(a,t,e)=>{let[s,i,n,r,o,h,l,d]=e;const u=((g,f,p,m,w,v,x)=>{if(p===0||m===0)return[];let S=0,C=0,E=0;const k=Math.PI,P=x*fu,D=ys(P),R=vs(P),B=.5*(-R*g-D*f),O=.5*(-R*f+D*g),F=p**2,L=m**2,I=O**2,G=B**2,Y=F*L-F*I-L*G;let z=Math.abs(p),H=Math.abs(m);if(Y<0){const fi=Math.sqrt(1-Y/(F*L));z*=fi,H*=fi}else E=(w===v?-1:1)*Math.sqrt(Y/(F*I+L*G));const _t=E*z*O/H,vt=-E*H*B/z,te=R*_t-D*vt+.5*g,Wt=D*_t+R*vt+.5*f;let xt=wm(1,0,(B-_t)/z,(O-vt)/H),Le=wm((B-_t)/z,(O-vt)/H,(-B-_t)/z,(-O-vt)/H);v===0&&Le>0?Le-=2*k:v===1&&Le<0&&(Le+=2*k);const gi=Math.ceil(Math.abs(Le/k*2)),Ft=[],dt=Le/gi,po=8/3*Math.sin(dt/4)*Math.sin(dt/4)/Math.sin(dt/2);let mo=xt+dt;for(let fi=0;fi<gi;fi++)Ft[fi]=Ky(xt,mo,R,D,z,H,te,Wt,po,S,C),S=Ft[fi][5],C=Ft[fi][6],xt=mo,mo+=dt;return Ft})(l-a,d-t,i,n,o,h,r);for(let g=0,f=u.length;g<f;g++)u[g][1]+=a,u[g][2]+=t,u[g][3]+=a,u[g][4]+=t,u[g][5]+=a,u[g][6]+=t;return u},xm=a=>{let t=0,e=0,s=0,i=0;const n=[];let r,o=0,h=0;for(const l of a){const d=[...l];let u;switch(d[0]){case"l":d[1]+=t,d[2]+=e;case"L":t=d[1],e=d[2],u=["L",t,e];break;case"h":d[1]+=t;case"H":t=d[1],u=["L",t,e];break;case"v":d[1]+=e;case"V":e=d[1],u=["L",t,e];break;case"m":d[1]+=t,d[2]+=e;case"M":t=d[1],e=d[2],s=d[1],i=d[2],u=["M",t,e];break;case"c":d[1]+=t,d[2]+=e,d[3]+=t,d[4]+=e,d[5]+=t,d[6]+=e;case"C":o=d[3],h=d[4],t=d[5],e=d[6],u=["C",d[1],d[2],o,h,t,e];break;case"s":d[1]+=t,d[2]+=e,d[3]+=t,d[4]+=e;case"S":r==="C"?(o=2*t-o,h=2*e-h):(o=t,h=e),t=d[3],e=d[4],u=["C",o,h,d[1],d[2],t,e],o=u[3],h=u[4];break;case"q":d[1]+=t,d[2]+=e,d[3]+=t,d[4]+=e;case"Q":o=d[1],h=d[2],t=d[3],e=d[4],u=["Q",o,h,t,e];break;case"t":d[1]+=t,d[2]+=e;case"T":r==="Q"?(o=2*t-o,h=2*e-h):(o=t,h=e),t=d[1],e=d[2],u=["Q",o,h,t,e];break;case"a":d[6]+=t,d[7]+=e;case"A":Qy(t,e,d).forEach(g=>n.push(g)),t=d[6],e=d[7];break;case"z":case"Z":t=s,e=i,u=["Z"]}u?(n.push(u),r=u[0]):r=""}return n},Ac=(a,t,e,s)=>Math.sqrt((e-a)**2+(s-t)**2),Sm=(a,t,e,s,i,n,r,o)=>h=>{const l=h**3,d=(f=>3*f**2*(1-f))(h),u=(f=>3*f*(1-f)**2)(h),g=(f=>(1-f)**3)(h);return new M(r*l+i*d+e*u+a*g,o*l+n*d+s*u+t*g)},Cm=a=>a**2,Am=a=>2*a*(1-a),Tm=a=>(1-a)**2,Jy=(a,t,e,s,i,n,r,o)=>h=>{const l=Cm(h),d=Am(h),u=Tm(h),g=3*(u*(e-a)+d*(i-e)+l*(r-i)),f=3*(u*(s-t)+d*(n-s)+l*(o-n));return Math.atan2(f,g)},Zy=(a,t,e,s,i,n)=>r=>{const o=Cm(r),h=Am(r),l=Tm(r);return new M(i*o+e*h+a*l,n*o+s*h+t*l)},t_=(a,t,e,s,i,n)=>r=>{const o=1-r,h=2*(o*(e-a)+r*(i-e)),l=2*(o*(s-t)+r*(n-s));return Math.atan2(l,h)},Em=(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+=Ac(s.x,s.y,r.x,r.y),s=r}return i},e_=(a,t)=>{let e,s=0,i=0,n={x:a.x,y:a.y},r=T({},n),o=.01,h=0;const l=a.iterator,d=a.angleFinder;for(;i<t&&o>1e-4;)r=l(s),h=s,e=Ac(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:d(h)})},Ju=a=>{let t,e,s=0,i=0,n=0,r=0,o=0;const h=[];for(const l of a){const d={x:i,y:n,command:l[0],length:0};switch(l[0]){case"M":e=d,e.x=r=i=l[1],e.y=o=n=l[2];break;case"L":e=d,e.length=Ac(i,n,l[1],l[2]),i=l[1],n=l[2];break;case"C":t=Sm(i,n,l[1],l[2],l[3],l[4],l[5],l[6]),e=d,e.iterator=t,e.angleFinder=Jy(i,n,l[1],l[2],l[3],l[4],l[5],l[6]),e.length=Em(t,i,n),i=l[5],n=l[6];break;case"Q":t=Zy(i,n,l[1],l[2],l[3],l[4]),e=d,e.iterator=t,e.angleFinder=t_(i,n,l[1],l[2],l[3],l[4]),e.length=Em(t,i,n),i=l[3],n=l[4];break;case"Z":e=d,e.destX=r,e.destY=o,e.length=Ac(i,n,r,o),i=r,n=o}s+=e.length,h.push(e)}return h.push({length:s,x:i,y:n}),h},km=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Ju(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 e_(i,t)}},s_=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),Mm=new RegExp(qy,"g"),i_=new RegExp(xs,"gi"),n_={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},Om=a=>{var t;const e=[],s=(t=a.match(s_))!==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=n_[n.toLowerCase()];let o=[];if(n==="a"||n==="A"){Mm.lastIndex=0;for(let h=null;h=Mm.exec(i);)o.push(...h.slice(1))}else o=i.match(i_)||[];for(let h=0;h<o.length;h+=r){const l=new Array(r),d=$y[n];l[0]=h>0&&d?d:n;for(let u=0;u<r;u++)l[u+1]=parseFloat(o[h+u]);e.push(l)}}return e},r_=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 l;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]),l=1;l<o;l++){if(!e.eq(s)){const d=e.midPointFrom(s);r.push(["Q",e.x,e.y,d.x,d.y])}e=a[l],l+1<a.length&&(s=a[l+1])}return h&&(i=e.x>a[l-2].x?1:e.x===a[l-2].x?0:-1,n=e.y>a[l-2].y?1:e.y===a[l-2].y?0:-1),r.push(["L",e.x+i*t,e.y+n*t]),r},Dm=(a,t)=>a.map(e=>e.map((s,i)=>i===0||t===void 0?s:Ct(s,t)).join(" ")).join(" ");function Tc(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 o_=(a,t)=>Math.floor(Math.random()*(t-a+1))+a;function Pm(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const e=t.onComplete||$n,s=new(Jl()).XMLHttpRequest,i=t.signal,n=function(){s.abort()},r=function(){i&&i.removeEventListener("abort",n),s.onerror=s.ontimeout=$n};if(i&&i.aborted)throw new uu("request");return i&&i.addEventListener("abort",n,{once:!0}),s.onreadystatechange=function(){s.readyState===4&&(r(),e(s),s.onreadystatechange=$n)},s.onerror=s.ontimeout=r,s.open("get",a,!0),s.send(),s}const Ec=(a,t)=>{let e=a._findCenterFromElement();a.transformMatrix&&((s=>{if(s.transformMatrix){const{scaleX:i,scaleY:n,angle:r,skewX:o}=Qn(s.transformMatrix);s.flipX=!1,s.flipY=!1,s.set(Ce,i),s.set(Ge,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 a_=Object.freeze({__proto__:null,addTransformToObject:Tp,animate:Xu,animateColor:Up,applyTransformToObject:ko,calcAngleBetweenVectors:fc,calcDimensionsMatrix:$a,calcPlaneChangeMatrix:eh,calcVectorRotation:Bp,cancelAnimFrame:ap,capValue:er,composeMatrix:up,copyCanvasElement:a=>{var t;const e=jt();return e.width=a.width,e.height=a.height,(t=e.getContext("2d"))===null||t===void 0||t.drawImage(a,0,0),e},cos:vs,createCanvasElement:jt,createImage:hp,createRotateMatrix:To,createScaleMatrix:oc,createSkewXMatrix:xu,createSkewYMatrix:Su,createTranslateMatrix:Ao,createVector:uc,crossProduct:Mo,degreesToRadians:Pt,dotProduct:Hp,ease:$v,enlivenObjectEnlivables:Qa,enlivenObjects:Eo,findScaleToCover:_m,findScaleToFit:ym,getBoundsOfCurve:Qu,getOrthonormalVector:Iu,getPathSegmentsInfo:Ju,getPointOnPath:km,getPointer:Ap,getRandomInt:o_,getRegularPolygonPath:(a,t)=>{const e=2*Math.PI/a;let s=-hn;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(vs(r),ys(r)).scalarMultiply(t);i[n]=[n===0?"M":"L",o,h]}return i[a]=["Z"],i},getSmoothPathFromPoints:r_,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:pc,groupSVGElements:(a,t)=>a&&a.length===1?a[0]:new Us(a,t),hasStyleChanged:_c,invertTransform:je,isBetweenVectors:ju,isIdentityMatrix:lp,isTouchEvent:hc,isTransparent:em,joinPath:Dm,loadImage:Ka,magnitude:gc,makeBoundingBoxFromPoints:Vs,makePathSimpler:xm,matrixToSVG:Ja,mergeClipPaths:(a,t)=>{var e;let s=a,i=t;s.inverted&&!i.inverted&&(s=t,i=a),Ou(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 Us([s],{clipPath:i,inverted:n})},multiplyTransformMatrices:Nt,multiplyTransformMatrixArray:rc,parsePath:Om,parsePreserveAspectRatioAttribute:Tu,parseUnit:Te,pick:Jn,projectStrokeOnPoints:nm,qrDecompose:Qn,radiansToDegrees:dn,removeFromArray:Kn,removeTransformFromObject:(a,t)=>{const e=je(t),s=Nt(e,a.calcOwnMatrix());ko(a,s)},removeTransformMatrixForSvgParsing:Ec,request:Pm,requestAnimFrame:qa,resetObjectTransform:Ep,rotatePoint:(a,t,e)=>a.rotate(e,t),rotateVector:Ru,saveObjectTransform:Mu,sendObjectToPlane:Ou,sendPointToPlane:tr,sendVectorToPlane:kp,setStyle:Tc,sin:ys,sizeAfterTransform:lc,string:Sy,stylesFromArray:am,stylesToArray:om,toDataURL:wu,toFixed:Ct,transformPath:(a,t,e)=>(e&&(t=Nt(t,[1,0,0,1,-e.x,-e.y])),a.map(s=>{const i=[...s];for(let n=1;n<s.length-1;n+=2){const{x:r,y:o}=de({x:s[n],y:s[n+1]},t);i[n]=r,i[n+1]=o}return i})),transformPoint:de});class h_ extends Cp{constructor(t){let{allowTouchScrolling:e=!1,containerClass:s=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(t),A(this,"upper",void 0),A(this,"container",void 0);const{el:i}=this.lower,n=this.createUpperCanvas();this.upper={el:n,ctx:n.getContext("2d")},this.applyCanvasStyle(i,{allowTouchScrolling:e}),this.applyCanvasStyle(n,{allowTouchScrolling:e,styles:{position:"absolute",left:"0",top:"0"}});const r=this.createContainerElement();r.classList.add(s),i.parentNode&&i.parentNode.replaceChild(r,i),r.append(i,n),this.container=r}createUpperCanvas(){const{el:t}=this.lower,e=jt();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"),Tc(t,{position:"relative"}),Sp(t),t}applyCanvasStyle(t,e){const{styles:s,allowTouchScrolling:i}=e;Tc(t,T(T({},s),{},{"touch-action":i?"manipulation":Se})),Sp(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:s,ctx:i}=this.upper;xp(s,i,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),Eu(this.upper.el,t),Eu(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(),zs().dispose(this.upper.el),delete this.upper,delete this.container}}class kc extends th{constructor(){super(...arguments),A(this,"targets",[]),A(this,"_hoveredTargets",[]),A(this,"_objectsToRender",void 0),A(this,"_currentTransform",null),A(this,"_groupSelector",null),A(this,"contextTopDirty",!1)}static getDefaults(){return T(T({},super.getDefaults()),kc.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 h_(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 em(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===ec||e===Ce||e===Ge||e===Ya?i=this.centeredScaling||t.centeredScaling:e===vu&&(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=Rt:["mr","tr","br"].includes(e)&&(s.x=lt),["tl","mt","tr"].includes(e)?s.y=mu:["bl","mb","br"].includes(e)&&(s.y=Ie)),s}_setupCurrentTransform(t,e,s){var i;const n=e.group?tr(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):Wv,l=((f,p,m,w)=>{if(!p||!f)return"drag";const v=w.controls[p];return v.getActionName(m,v,w)})(s,r,t,e),d=t[this.centeredKey],u=this._shouldCenterTransform(e,l,d)?{x:J,y:J}:this._getOriginFromCorner(e,r),g={target:e,action:l,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:u.x,originY:u.y,ex:n.x,ey:n.y,lastX:n.x,lastY:n.y,theta:Pt(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:d,original:T(T({},Mu(e)),{},{originX:u.x,originY:u.y})};this._currentTransform=g,this.fire("before:transform",{e:t,transform:g})}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 l=Math.min(r.x,o.x),d=Math.min(r.y,o.y),u=Math.max(r.x,o.x),g=Math.max(r.y,o.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(l,d,u-l,g-d)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,l+=h,d+=h,u-=h,g-=h,ue.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(l,d,u-l,g-d))}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,hc(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,l]=s,d=Math.atan2(o.y-r.y,o.x-r.x),u=vs(d)*n,g=ys(d)*n,f=u+g,p=u-g;s=[new M(r.x-p,r.y-f),new M(o.x+f,o.y-p),new M(h.x+p,h.y+f),new M(l.x-f,l.y+p)]}return Tt.isPointInPolygon(e,s)}_checkTarget(t,e){return!!(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,tr(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(nc(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&&nc(s)&&s.interactive&&this.targets[0]){const i=this.targets;for(let n=i.length-1;n>0;n--){const r=i[n];if(!nc(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=Ap(t),r=i.width||0,o=i.height||0;r&&o||(Ie in i&&mu in i&&(o=Math.abs(i.top-i.bottom)),Rt in i&&lt 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=tr(n,void 0,this.viewportTransform));const h=this.getRetinaScaling();h!==1&&(n.x/=h,n.y/=h);const l=r===0||o===0?new M(1,1):new M(s.width/r,s.height/o);return n.multiply(l)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=jt(),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 Zn(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,Zn(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),Zn(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(sc,i))}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeObject;Zn(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&&Zn(e)&&this._activeObject===e){const s=Jn(t,["angle","flipX","flipY",lt,Ce,Ge,xo,So,Ie]);return Tp(t,e.calcOwnMatrix()),s}return{}}_setSVGObject(t,e,s){const i=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,s),e.set(i)}}A(kc,"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 l_{constructor(t){A(this,"targets",[]),A(this,"__disposer",void 0);const e=()=>{const{hiddenTextarea:i}=t.getActiveObject()||{};i&&i.focus()},s=t.upperCanvasEl;s.addEventListener("click",e),this.__disposer=()=>s.removeEventListener("click",e)}exitTextEditing(){this.target=void 0,this.targets.forEach(t=>{t.isEditing&&t.exitEditing()})}add(t){this.targets.push(t)}remove(t){this.unregister(t),Kn(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 c_=["target","oldTarget","fireCanvas","e"],Ue={passive:!1},Fo=(a,t)=>{const e=a.getViewportPoint(t),s=a.getScenePoint(t);return{viewportPoint:e,scenePoint:s,pointer:e,absolutePointer:s}},gn=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)},os=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)},d_={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 Zu extends kc{constructor(t){super(t,arguments.length>1&&arguments[1]!==void 0?arguments[1]:{}),A(this,"_isClick",void 0),A(this,"textEditingManager",new l_(this)),["_onMouseDown","_onTouchStart","_onMouseMove","_onMouseUp","_onTouchEnd","_onResize","_onMouseWheel","_onMouseOut","_onMouseEnter","_onContextMenu","_onDoubleClick","_onDragStart","_onDragEnd","_onDragProgress","_onDragOver","_onDragEnter","_onDragLeave","_onDrop"].forEach(e=>{this[e]=this[e].bind(this)}),this.addOrRemove(gn,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const s=this.upperCanvasEl,i=this._getEventPrefix();t(wp(s),"resize",this._onResize),t(s,i+"down",this._onMouseDown),t(s,"".concat(i,"move"),this._onMouseMove,Ue),t(s,"".concat(i,"out"),this._onMouseOut),t(s,"".concat(i,"enter"),this._onMouseEnter),t(s,"wheel",this._onMouseWheel),t(s,"contextmenu",this._onContextMenu),t(s,"dblclick",this._onDoubleClick),t(s,"dragstart",this._onDragStart),t(s,"dragend",this._onDragEnd),t(s,"dragover",this._onDragOver),t(s,"dragenter",this._onDragEnter),t(s,"dragleave",this._onDragLeave),t(s,"drop",this._onDrop),this.enablePointerEvents||t(s,"touchstart",this._onTouchStart,Ue)}removeListeners(){this.addOrRemove(os,"remove");const t=this._getEventPrefix(),e=_s(this.upperCanvasEl);os(e,"".concat(t,"up"),this._onMouseUp),os(e,"touchend",this._onTouchEnd,Ue),os(e,"".concat(t,"move"),this._onMouseMove,Ue),os(e,"touchmove",this._onMouseMove,Ue)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s=T({e:t},Fo(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},Fo(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 gn(this.upperCanvasEl,"drag",this._onDragProgress)}ku(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!==Se,s=e?this._activeObject:void 0,i={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:s};os(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 l=i[h];l.canDrop(t)&&(o=l),l.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},Fo(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&&ku(t),this._basicEventHandler("contextmenu",i),!1}_onDoubleClick(t){this._cacheTransformEventData(t),this._handleEvent(t,"dblclick"),this._resetTransformEventData()}getPointerId(t){const e=t.changedTouches;return e?e[0]&&e[0].identifier:this.enablePointerEvents?t.pointerId:-1}_isMainEvent(t){return t.isPrimary===!0||t.isPrimary!==!1&&(t.type==="touchend"&&t.touches.length===0||!t.changedTouches||t.changedTouches[0].identifier===this.mainTouchId)}_onTouchStart(t){t.preventDefault(),this.mainTouchId===void 0&&(this.mainTouchId=this.getPointerId(t)),this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix(),i=_s(e);gn(i,"touchend",this._onTouchEnd,Ue),gn(i,"touchmove",this._onMouseMove,Ue),os(e,"".concat(s,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();os(e,"".concat(s,"move"),this._onMouseMove,Ue);const i=_s(e);gn(i,"".concat(s,"up"),this._onMouseUp),gn(i,"".concat(s,"move"),this._onMouseMove,Ue)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),s=_s(this.upperCanvasEl);os(s,"touchend",this._onTouchEnd,Ue),os(s,"touchmove",this._onMouseMove,Ue),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout(()=>{gn(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=_s(this.upperCanvasEl);os(i,"".concat(s,"up"),this._onMouseUp),os(i,"".concat(s,"move"),this._onMouseMove,Ue),gn(e,"".concat(s,"move"),this._onMouseMove,Ue)}}_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,l=!1;if(s&&(this._finalizeCurrentTransform(t),l=s.actionPerformed),!i){const d=n===this._activeObject;this.handleSelection(t),l||(l=this._shouldRender(n)||!d&&n===this._activeObject)}if(n){const d=n.findControl(this.getViewportPoint(t),hc(t)),{key:u,control:g}=d||{};if(h=u,n.selectable&&n!==this._activeObject&&n.activeOn==="up")this.setActiveObject(n,t),l=!0;else if(g){const f=g.getMouseUpHandler(t,n,g);f&&(o=this.getScenePoint(t),f.call(g,t,s,o.x,o.y))}n.isMoving=!1}if(s&&(s.target!==n||s.corner!==h)){const d=s.target&&s.target.controls[s.corner],u=d&&d.getMouseUpHandler(t,s.target,d);o=o||this.getScenePoint(t),u&&u.call(d,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),l?this.requestRenderAll():i||(e=this._activeObject)!==null&&e!==void 0&&e.isEditing||this.renderTop()}_basicEventHandler(t,e){const{target:s,subTargets:i=[]}=e;this.fire(t,e),s&&s.fire(t,e);for(let n=0;n<i.length;n++)i[n]!==s&&i[n].fire(t,e);return e}_handleEvent(t,e){const s=this._target,i=this.targets||[],n=T(T({e:t,target:s,subTargets:i},Fo(this,t)),{},{transform:this._currentTransform},e==="up:before"||e==="up"?{isClick:this._isClick,currentTarget:this.findTarget(t),currentSubTargets:this.targets}:{});this.fire("mouse:".concat(e),n),s&&s.fire("mouse".concat(e),n);for(let r=0;r<i.length;r++)i[r]!==s&&i[r].fire("mouse".concat(e),n)}_onMouseDownInDrawingMode(t){this._isCurrentlyDrawing=!0,this.getActiveObject()&&(this.discardActiveObject(t),this.requestRenderAll());const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseDown(e,{e:t,pointer:e}),this._handleEvent(t,"down")}_onMouseMoveInDrawingMode(t){if(this._isCurrentlyDrawing){const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseMove(e,{e:t,pointer:e})}this.setCursor(this.freeDrawingCursor),this._handleEvent(t,"move")}_onMouseUpInDrawingMode(t){const e=this.getScenePoint(t);this.freeDrawingBrush?this._isCurrentlyDrawing=!!this.freeDrawingBrush.onMouseUp({e:t,pointer:e}):this._isCurrentlyDrawing=!1,this._handleEvent(t,"up")}__onMouseDown(t){this._isClick=!0,this._cacheTransformEventData(t),this._handleEvent(t,"down:before");let e=this._target;const{button:s}=t;if(s)return(this.fireMiddleClick&&s===1||this.fireRightClick&&s===2)&&this._handleEvent(t,"down"),void this._resetTransformEventData();if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t)||this._currentTransform)return;let i=this._shouldRender(e),n=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,n=!0,i=!0):this._shouldClearSelection(t,e)&&this.discardActiveObject(t),this.selection&&(!e||!e.selectable&&!e.isEditing&&e!==this._activeObject)){const r=this.getScenePoint(t);this._groupSelector={x:r.x,y:r.y,deltaY:0,deltaX:0}}if(e){const r=e===this._activeObject;e.selectable&&e.activeOn==="down"&&this.setActiveObject(e,t);const o=e.findControl(this.getViewportPoint(t),hc(t));if(e===this._activeObject&&(o||!n)){this._setupCurrentTransform(t,e,r);const h=o?o.control:void 0,l=this.getScenePoint(t),d=h&&h.getMouseDownHandler(t,e,h);d&&d.call(h,t,this._currentTransform,l.x,l.y)}}i&&(this._objectsToRender=void 0),this._handleEvent(t,"down"),i&&this.requestRenderAll()}_resetTransformEventData(){this._target=void 0,this._pointer=void 0,this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getViewportPoint(t),this._absolutePointer=tr(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=St(e,c_);const{targetIn:h,targetOut:l,canvasIn:d,canvasOut:u}=d_[t],g=i!==s;if(i&&g){const f=T(T({},o),{},{e:r,target:i,nextTarget:s},Fo(this,r));n&&this.fire(u,f),i.fire(l,f)}if(s&&g){const f=T(T({},o),{},{e:r,target:s,previousTarget:i},Fo(this,r));n&&this.fire(d,f),s.fire(h,f)}}__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?tr(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=Zn(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=Zn(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.exitEditing&&s.exitEditing();const n=new(X.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),l=r.max(o).subtract(h),d=this.collectObjects({left:h.x,top:h.y,width:l.x,height:l.y},{includeIntersecting:!this.selectionFullyContained}),u=r.eq(o)?d[0]?[d[0]]:[]:d.length>1?d.filter(g=>!g.onSelect({e:t})).reverse():d;if(u.length===1)this.setActiveObject(u[0],t);else if(u.length>1){const g=X.getClass("ActiveSelection");this.setActiveObject(new g(u,{canvas:this}),t)}return this._groupSelector=null,!0}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const Lm={x1:0,y1:0,x2:0,y2:0},u_=T(T({},Lm),{},{r1:0,r2:0}),Ro=(a,t)=>isNaN(a)&&typeof t=="number"?t:a,g_=/^(\d+\.\d+)%|(\d+)%$/;function Fm(a){return a&&g_.test(a)}function Rm(a,t){const e=typeof a=="number"?a:typeof a=="string"?parseFloat(a)/(Fm(a)?100:1):NaN;return er(0,Ro(e,t),1)}const f_=/\s*;\s*/,p_=/\s*:\s*/;function m_(a,t){let e,s;const i=a.getAttribute("style");if(i){const r=i.split(f_);r[r.length-1]===""&&r.pop();for(let o=r.length;o--;){const[h,l]=r[o].split(p_).map(d=>d.trim());h==="stop-color"?e=l:h==="stop-opacity"&&(s=l)}}const n=new ut(e||a.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:Rm(a.getAttribute("offset"),0),color:n.toRgb(),opacity:Ro(parseFloat(s||a.getAttribute("stop-opacity")||""),1)*n.getAlpha()*t}}function b_(a,t){const e=[],s=a.getElementsByTagName("stop"),i=Rm(t,1);for(let n=s.length;n--;)e.push(m_(s[n],i));return e}function Im(a){return a.nodeName==="linearGradient"||a.nodeName==="LINEARGRADIENT"?"linear":"radial"}function jm(a){return a.getAttribute("gradientUnits")==="userSpaceOnUse"?"pixels":"percentage"}function Cs(a,t){return a.getAttribute(t)}function v_(a,t){return function(e,s){let i,{width:n,height:r,gradientUnits:o}=s;return Object.keys(e).reduce((h,l)=>{const d=e[l];return d==="Infinity"?i=1:d==="-Infinity"?i=0:(i=typeof d=="string"?parseFloat(d):d,typeof d=="string"&&Fm(d)&&(i*=.01,o==="pixels"&&(l!=="x1"&&l!=="x2"&&l!=="r2"||(i*=n),l!=="y1"&&l!=="y2"||(i*=r)))),h[l]=i,h},{})}(Im(a)==="linear"?function(e){return{x1:Cs(e,"x1")||0,y1:Cs(e,"y1")||0,x2:Cs(e,"x2")||"100%",y2:Cs(e,"y2")||0}}(a):function(e){return{x1:Cs(e,"fx")||Cs(e,"cx")||"50%",y1:Cs(e,"fy")||Cs(e,"cy")||"50%",r1:0,x2:Cs(e,"cx")||"50%",y2:Cs(e,"cy")||"50%",r2:Cs(e,"r")||"50%"}}(a),T(T({},t),{},{gradientUnits:jm(a)}))}class oh{constructor(t){const{type:e="linear",gradientUnits:s="pixels",coords:i={},colorStops:n=[],offsetX:r=0,offsetY:o=0,gradientTransform:h,id:l}=t||{};Object.assign(this,{type:e,gradientUnits:s,coords:T(T({},e==="radial"?u_:Lm),i),colorStops:n,offsetX:r,offsetY:o,gradientTransform:h,id:l?"".concat(l,"_").concat(cn()):cn()})}addColorStop(t){for(const e in t){const s=new ut(t[e]);this.colorStops.push({offset:parseFloat(e),color:s.toRgb(),opacity:s.getAlpha()})}return this}toObject(t){return T(T({},Jn(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():xe.concat(),n=this.gradientUnits==="pixels"?"userSpaceOnUse":"objectBoundingBox",r=this.colorStops.map(u=>T({},u)).sort((u,g)=>u.offset-g.offset);let o=-this.offsetX,h=-this.offsetY;var l;n==="objectBoundingBox"?(o/=t.width,h/=t.height):(o+=t.width/2,h+=t.height/2),(l=t)&&typeof l._renderPathCommands=="function"&&this.gradientUnits!=="percentage"&&(o-=t.pathOffset.x,h-=t.pathOffset.y),i[4]-=o,i[5]-=h;const d=['id="SVGID_'.concat(this.id,'"'),'gradientUnits="'.concat(n,'"'),'gradientTransform="'.concat(e?e+" ":"").concat(Ja(i),'"'),""].join(" ");if(this.type==="linear"){const{x1:u,y1:g,x2:f,y2:p}=this.coords;s.push("<linearGradient ",d,' x1="',u,'" y1="',g,'" x2="',f,'" y2="',p,`">
42
- `)}else if(this.type==="radial"){const{x1:u,y1:g,x2:f,y2:p,r1:m,r2:w}=this.coords,v=m>w;s.push("<radialGradient ",d,' cx="',v?u:f,'" cy="',v?g:p,'" r="',v?m:w,'" fx="',v?f:u,'" fy="',v?p:g,`">
43
- `),v&&(r.reverse(),r.forEach(S=>{S.offset=1-S.offset}));const x=Math.min(m,w);if(x>0){const S=x/Math.max(m,w);r.forEach(C=>{C.offset+=S*(1-C.offset)})}}return r.forEach(u=>{let{color:g,offset:f,opacity:p}=u;s.push("<stop ",'offset="',100*f+"%",'" style="stop-color:',g,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=wt(t,$y);return Promise.all([Eo(i,e),Qa(r,e)]).then(o=>{let[h,l]=o;const d=new this(h,T(T(T({},r),l),{},{layoutManager:new Ky}));if(n){const u=N.getClass(n.type),g=N.getClass(n.strategy);d.layoutManager=new u(new g)}else d.layoutManager=new nh;return d.layoutManager.subscribeTargets({type:wi,target:d,targets:d.getObjects()}),d.setCoords(),d})}}A(Us,"type","Group"),A(Us,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),N.setClass(Us);const _m=(a,t)=>Math.min(t.width/a.width,t.height/a.height),wm=(a,t)=>Math.max(t.width/a.width,t.height/a.height),Qu="\\s*,?\\s*",rh="".concat(Qu,"(").concat(xs,")"),Qy="".concat(rh).concat(rh).concat(rh).concat(Qu,"([01])").concat(Qu,"([01])").concat(rh).concat(rh),Jy={m:"l",M:"L"},Zy=(a,t,e,s,i,n,r,o,h,l,d)=>{const u=vs(a),g=ys(a),f=vs(t),p=ys(t),m=e*i*f-s*n*p+r,_=s*i*f+e*n*p+o;return["C",l+h*(-e*i*g-s*n*u),d+h*(-s*i*g+e*n*u),m+h*(e*i*p+s*n*f),_+h*(s*i*p-e*n*f),m,_]},xm=(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 Ju(a,t,e,s,i,n,r,o){let h;if(at.cachesBoundsOfCurve&&(h=[...arguments].join(),Ua.boundsOfCurveCache[h]))return Ua.boundsOfCurveCache[h];const l=Math.sqrt,d=Math.abs,u=[],g=[[0,0],[0,0]];let f=6*a-12*e+6*i,p=-3*a+9*e-9*i+3*r,m=3*e-3*a;for(let C=0;C<2;++C){if(C>0&&(f=6*t-12*s+6*n,p=-3*t+9*s-9*n+3*o,m=3*s-3*t),d(p)<1e-12){if(d(f)<1e-12)continue;const P=-m/f;0<P&&P<1&&u.push(P);continue}const E=f*f-4*m*p;if(E<0)continue;const M=l(E),k=(-f+M)/(2*p);0<k&&k<1&&u.push(k);const O=(-f-M)/(2*p);0<O&&O<1&&u.push(O)}let _=u.length;const v=_,x=Cm(a,t,e,s,i,n,r,o);for(;_--;){const{x:C,y:E}=x(u[_]);g[0][_]=C,g[1][_]=E}g[0][v]=a,g[1][v]=t,g[0][v+1]=r,g[1][v+1]=o;const S=[new D(Math.min(...g[0]),Math.min(...g[1])),new D(Math.max(...g[0]),Math.max(...g[1]))];return at.cachesBoundsOfCurve&&(Ua.boundsOfCurveCache[h]=S),S}const t_=(a,t,e)=>{let[s,i,n,r,o,h,l,d]=e;const u=((g,f,p,m,_,v,x)=>{if(p===0||m===0)return[];let S=0,C=0,E=0;const M=Math.PI,k=x*pu,O=ys(k),P=vs(k),L=.5*(-P*g-O*f),F=.5*(-P*f+O*g),W=p**2,B=m**2,z=F**2,K=L**2,tt=W*B-W*z-B*K;let V=Math.abs(p),H=Math.abs(m);if(tt<0){const fi=Math.sqrt(1-tt/(W*B));V*=fi,H*=fi}else E=(_===v?-1:1)*Math.sqrt(tt/(W*z+B*K));const Jt=E*V*F/H,Zt=-E*H*L/V,ce=P*Jt-O*Zt+.5*g,zt=O*Jt+P*Zt+.5*f;let _t=xm(1,0,(L-Jt)/V,(F-Zt)/H),Le=xm((L-Jt)/V,(F-Zt)/H,(-L-Jt)/V,(-F-Zt)/H);v===0&&Le>0?Le-=2*M:v===1&&Le<0&&(Le+=2*M);const gi=Math.ceil(Math.abs(Le/M*2)),Pt=[],dt=Le/gi,po=8/3*Math.sin(dt/4)*Math.sin(dt/4)/Math.sin(dt/2);let mo=_t+dt;for(let fi=0;fi<gi;fi++)Pt[fi]=Zy(_t,mo,P,O,V,H,ce,zt,po,S,C),S=Pt[fi][5],C=Pt[fi][6],_t=mo,mo+=dt;return Pt})(l-a,d-t,i,n,o,h,r);for(let g=0,f=u.length;g<f;g++)u[g][1]+=a,u[g][2]+=t,u[g][3]+=a,u[g][4]+=t,u[g][5]+=a,u[g][6]+=t;return u},Sm=a=>{let t=0,e=0,s=0,i=0;const n=[];let r,o=0,h=0;for(const l of a){const d=[...l];let u;switch(d[0]){case"l":d[1]+=t,d[2]+=e;case"L":t=d[1],e=d[2],u=["L",t,e];break;case"h":d[1]+=t;case"H":t=d[1],u=["L",t,e];break;case"v":d[1]+=e;case"V":e=d[1],u=["L",t,e];break;case"m":d[1]+=t,d[2]+=e;case"M":t=d[1],e=d[2],s=d[1],i=d[2],u=["M",t,e];break;case"c":d[1]+=t,d[2]+=e,d[3]+=t,d[4]+=e,d[5]+=t,d[6]+=e;case"C":o=d[3],h=d[4],t=d[5],e=d[6],u=["C",d[1],d[2],o,h,t,e];break;case"s":d[1]+=t,d[2]+=e,d[3]+=t,d[4]+=e;case"S":r==="C"?(o=2*t-o,h=2*e-h):(o=t,h=e),t=d[3],e=d[4],u=["C",o,h,d[1],d[2],t,e],o=u[3],h=u[4];break;case"q":d[1]+=t,d[2]+=e,d[3]+=t,d[4]+=e;case"Q":o=d[1],h=d[2],t=d[3],e=d[4],u=["Q",o,h,t,e];break;case"t":d[1]+=t,d[2]+=e;case"T":r==="Q"?(o=2*t-o,h=2*e-h):(o=t,h=e),t=d[1],e=d[2],u=["Q",o,h,t,e];break;case"a":d[6]+=t,d[7]+=e;case"A":t_(t,e,d).forEach(g=>n.push(g)),t=d[6],e=d[7];break;case"z":case"Z":t=s,e=i,u=["Z"]}u?(n.push(u),r=u[0]):r=""}return n},Tc=(a,t,e,s)=>Math.sqrt((e-a)**2+(s-t)**2),Cm=(a,t,e,s,i,n,r,o)=>h=>{const l=h**3,d=(f=>3*f**2*(1-f))(h),u=(f=>3*f*(1-f)**2)(h),g=(f=>(1-f)**3)(h);return new D(r*l+i*d+e*u+a*g,o*l+n*d+s*u+t*g)},Am=a=>a**2,Tm=a=>2*a*(1-a),Em=a=>(1-a)**2,e_=(a,t,e,s,i,n,r,o)=>h=>{const l=Am(h),d=Tm(h),u=Em(h),g=3*(u*(e-a)+d*(i-e)+l*(r-i)),f=3*(u*(s-t)+d*(n-s)+l*(o-n));return Math.atan2(f,g)},s_=(a,t,e,s,i,n)=>r=>{const o=Am(r),h=Tm(r),l=Em(r);return new D(i*o+e*h+a*l,n*o+s*h+t*l)},i_=(a,t,e,s,i,n)=>r=>{const o=1-r,h=2*(o*(e-a)+r*(i-e)),l=2*(o*(s-t)+r*(n-s));return Math.atan2(l,h)},km=(a,t,e)=>{let s=new D(t,e),i=0;for(let n=1;n<=100;n+=1){const r=a(n/100);i+=Tc(s.x,s.y,r.x,r.y),s=r}return i},n_=(a,t)=>{let e,s=0,i=0,n={x:a.x,y:a.y},r=T({},n),o=.01,h=0;const l=a.iterator,d=a.angleFinder;for(;i<t&&o>1e-4;)r=l(s),h=s,e=Tc(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:d(h)})},Zu=a=>{let t,e,s=0,i=0,n=0,r=0,o=0;const h=[];for(const l of a){const d={x:i,y:n,command:l[0],length:0};switch(l[0]){case"M":e=d,e.x=r=i=l[1],e.y=o=n=l[2];break;case"L":e=d,e.length=Tc(i,n,l[1],l[2]),i=l[1],n=l[2];break;case"C":t=Cm(i,n,l[1],l[2],l[3],l[4],l[5],l[6]),e=d,e.iterator=t,e.angleFinder=e_(i,n,l[1],l[2],l[3],l[4],l[5],l[6]),e.length=km(t,i,n),i=l[5],n=l[6];break;case"Q":t=s_(i,n,l[1],l[2],l[3],l[4]),e=d,e.iterator=t,e.angleFinder=i_(i,n,l[1],l[2],l[3],l[4]),e.length=km(t,i,n),i=l[3],n=l[4];break;case"Z":e=d,e.destX=r,e.destY=o,e.length=Tc(i,n,r,o),i=r,n=o}s+=e.length,h.push(e)}return h.push({length:s,x:i,y:n}),h},Mm=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Zu(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 D(i.x,i.y).lerp(new D(i.destX,i.destY),n)),{},{angle:Math.atan2(i.destY-i.y,i.destX-i.x)});case"L":return T(T({},new D(i.x,i.y).lerp(new D(r[1],r[2]),n)),{},{angle:Math.atan2(r[2]-i.y,r[1]-i.x)});case"C":case"Q":return n_(i,t)}},r_=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),Om=new RegExp(Qy,"g"),o_=new RegExp(xs,"gi"),a_={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},Dm=a=>{var t;const e=[],s=(t=a.match(r_))!==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=a_[n.toLowerCase()];let o=[];if(n==="a"||n==="A"){Om.lastIndex=0;for(let h=null;h=Om.exec(i);)o.push(...h.slice(1))}else o=i.match(o_)||[];for(let h=0;h<o.length;h+=r){const l=new Array(r),d=Jy[n];l[0]=h>0&&d?d:n;for(let u=0;u<r;u++)l[u+1]=parseFloat(o[h+u]);e.push(l)}}return e},h_=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=new D(a[0]),s=new D(a[1]),i=1,n=0;const r=[],o=a.length,h=o>2;let l;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]),l=1;l<o;l++){if(!e.eq(s)){const d=e.midPointFrom(s);r.push(["Q",e.x,e.y,d.x,d.y])}e=a[l],l+1<a.length&&(s=a[l+1])}return h&&(i=e.x>a[l-2].x?1:e.x===a[l-2].x?0:-1,n=e.y>a[l-2].y?1:e.y===a[l-2].y?0:-1),r.push(["L",e.x+i*t,e.y+n*t]),r},Pm=(a,t)=>a.map(e=>e.map((s,i)=>i===0||t===void 0?s:xt(s,t)).join(" ")).join(" ");function Ec(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 l_=(a,t)=>Math.floor(Math.random()*(t-a+1))+a;function Lm(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const e=t.onComplete||$n,s=new(Zl()).XMLHttpRequest,i=t.signal,n=function(){s.abort()},r=function(){i&&i.removeEventListener("abort",n),s.onerror=s.ontimeout=$n};if(i&&i.aborted)throw new gu("request");return i&&i.addEventListener("abort",n,{once:!0}),s.onreadystatechange=function(){s.readyState===4&&(r(),e(s),s.onreadystatechange=$n)},s.onerror=s.ontimeout=r,s.open("get",a,!0),s.send(),s}const kc=(a,t)=>{let e=a._findCenterFromElement();a.transformMatrix&&((s=>{if(s.transformMatrix){const{scaleX:i,scaleY:n,angle:r,skewX:o}=Qn(s.transformMatrix);s.flipX=!1,s.flipY=!1,s.set(Ce,i),s.set(Ge,n),s.angle=r,s.skewX=o,s.skewY=0}})(a),e=e.transform(a.transformMatrix)),delete a.transformMatrix,t&&(a.scaleX*=t.scaleX,a.scaleY*=t.scaleY,a.cropX=t.cropX,a.cropY=t.cropY,e.x+=t.offsetLeft,e.y+=t.offsetTop,a.width=t.width,a.height=t.height),a.setPositionByOrigin(e,Q,Q)};var c_=Object.freeze({__proto__:null,addTransformToObject:Ep,animate:zu,animateColor:Yp,applyTransformToObject:ko,calcAngleBetweenVectors:pc,calcDimensionsMatrix:$a,calcPlaneChangeMatrix:eh,calcVectorRotation:Hp,cancelAnimFrame:hp,capValue:er,composeMatrix:gp,copyCanvasElement:a=>{var t;const e=Rt();return e.width=a.width,e.height=a.height,(t=e.getContext("2d"))===null||t===void 0||t.drawImage(a,0,0),e},cos:vs,createCanvasElement:Rt,createImage:lp,createRotateMatrix:To,createScaleMatrix:ac,createSkewXMatrix:Su,createSkewYMatrix:Cu,createTranslateMatrix:Ao,createVector:gc,crossProduct:Mo,degreesToRadians:Ot,dotProduct:Wp,ease:Jv,enlivenObjectEnlivables:Qa,enlivenObjects:Eo,findScaleToCover:wm,findScaleToFit:_m,getBoundsOfCurve:Ju,getOrthonormalVector:ju,getPathSegmentsInfo:Zu,getPointOnPath:Mm,getPointer:Tp,getRandomInt:l_,getRegularPolygonPath:(a,t)=>{const e=2*Math.PI/a;let s=-hn;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 D(vs(r),ys(r)).scalarMultiply(t);i[n]=[n===0?"M":"L",o,h]}return i[a]=["Z"],i},getSmoothPathFromPoints:h_,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:mc,groupSVGElements:(a,t)=>a&&a.length===1?a[0]:new Us(a,t),hasStyleChanged:wc,invertTransform:je,isBetweenVectors:Nu,isIdentityMatrix:cp,isTouchEvent:lc,isTransparent:sm,joinPath:Pm,loadImage:Ka,magnitude:fc,makeBoundingBoxFromPoints:Vs,makePathSimpler:Sm,matrixToSVG:Ja,mergeClipPaths:(a,t)=>{var e;let s=a,i=t;s.inverted&&!i.inverted&&(s=t,i=a),Du(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 Us([s],{clipPath:i,inverted:n})},multiplyTransformMatrices:It,multiplyTransformMatrixArray:oc,parsePath:Dm,parsePreserveAspectRatioAttribute:Eu,parseUnit:Te,pick:Jn,projectStrokeOnPoints:rm,qrDecompose:Qn,radiansToDegrees:dn,removeFromArray:Kn,removeTransformFromObject:(a,t)=>{const e=je(t),s=It(e,a.calcOwnMatrix());ko(a,s)},removeTransformMatrixForSvgParsing:kc,request:Lm,requestAnimFrame:qa,resetObjectTransform:kp,rotatePoint:(a,t,e)=>a.rotate(e,t),rotateVector:Iu,saveObjectTransform:Ou,sendObjectToPlane:Du,sendPointToPlane:tr,sendVectorToPlane:Mp,setStyle:Ec,sin:ys,sizeAfterTransform:cc,string:Ty,stylesFromArray:hm,stylesToArray:am,toDataURL:xu,toFixed:xt,transformPath:(a,t,e)=>(e&&(t=It(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}=de({x:s[n],y:s[n+1]},t);i[n]=r,i[n+1]=o}return i})),transformPoint:de});class d_ extends Ap{constructor(t){let{allowTouchScrolling:e=!1,containerClass:s=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(t),A(this,"upper",void 0),A(this,"container",void 0);const{el:i}=this.lower,n=this.createUpperCanvas();this.upper={el:n,ctx:n.getContext("2d")},this.applyCanvasStyle(i,{allowTouchScrolling:e}),this.applyCanvasStyle(n,{allowTouchScrolling:e,styles:{position:"absolute",left:"0",top:"0"}});const r=this.createContainerElement();r.classList.add(s),i.parentNode&&i.parentNode.replaceChild(r,i),r.append(i,n),this.container=r}createUpperCanvas(){const{el:t}=this.lower,e=Rt();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"),Ec(t,{position:"relative"}),Cp(t),t}applyCanvasStyle(t,e){const{styles:s,allowTouchScrolling:i}=e;Ec(t,T(T({},s),{},{"touch-action":i?"manipulation":Se})),Cp(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:s,ctx:i}=this.upper;Sp(s,i,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),ku(this.upper.el,t),ku(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(),zs().dispose(this.upper.el),delete this.upper,delete this.container}}class Mc extends th{constructor(){super(...arguments),A(this,"targets",[]),A(this,"_hoveredTargets",[]),A(this,"_objectsToRender",void 0),A(this,"_currentTransform",null),A(this,"_groupSelector",null),A(this,"contextTopDirty",!1)}static getDefaults(){return T(T({},super.getDefaults()),Mc.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 d_(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 sm(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===sc||e===Ce||e===Ge||e===Ya?i=this.centeredScaling||t.centeredScaling:e===yu&&(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=Lt:["mr","tr","br"].includes(e)&&(s.x=lt),["tl","mt","tr"].includes(e)?s.y=bu:["bl","mb","br"].includes(e)&&(s.y=Ie)),s}_setupCurrentTransform(t,e,s){var i;const n=e.group?tr(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):Vv,l=((f,p,m,_)=>{if(!p||!f)return"drag";const v=_.controls[p];return v.getActionName(m,v,_)})(s,r,t,e),d=t[this.centeredKey],u=this._shouldCenterTransform(e,l,d)?{x:Q,y:Q}:this._getOriginFromCorner(e,r),g={target:e,action:l,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:u.x,originY:u.y,ex:n.x,ey:n.y,lastX:n.x,lastY:n.y,theta:Ot(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:d,original:T(T({},Ou(e)),{},{originX:u.x,originY:u.y})};this._currentTransform=g,this.fire("before:transform",{e:t,transform:g})}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new D(e,s).transform(this.viewportTransform),o=new D(e+i,s+n).transform(this.viewportTransform),h=this.selectionLineWidth/2;let l=Math.min(r.x,o.x),d=Math.min(r.y,o.y),u=Math.max(r.x,o.x),g=Math.max(r.y,o.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(l,d,u-l,g-d)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,l+=h,d+=h,u-=h,g-=h,ue.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(l,d,u-l,g-d))}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,lc(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,l]=s,d=Math.atan2(o.y-r.y,o.x-r.x),u=vs(d)*n,g=ys(d)*n,f=u+g,p=u-g;s=[new D(r.x-p,r.y-f),new D(o.x+f,o.y-p),new D(h.x+p,h.y+f),new D(l.x-f,l.y+p)]}return Ct.isPointInPolygon(e,s)}_checkTarget(t,e){return!!(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,tr(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(rc(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&&rc(s)&&s.interactive&&this.targets[0]){const i=this.targets;for(let n=i.length-1;n>0;n--){const r=i[n];if(!rc(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=Tp(t),r=i.width||0,o=i.height||0;r&&o||(Ie in i&&bu in i&&(o=Math.abs(i.top-i.bottom)),Lt in i&&lt 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=tr(n,void 0,this.viewportTransform));const h=this.getRetinaScaling();h!==1&&(n.x/=h,n.y/=h);const l=r===0||o===0?new D(1,1):new D(s.width/r,s.height/o);return n.multiply(l)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=Rt(),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 Zn(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,Zn(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),Zn(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(ic,i))}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeObject;Zn(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&&Zn(e)&&this._activeObject===e){const s=Jn(t,["angle","flipX","flipY",lt,Ce,Ge,xo,So,Ie]);return Ep(t,e.calcOwnMatrix()),s}return{}}_setSVGObject(t,e,s){const i=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,s),e.set(i)}}A(Mc,"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 u_{constructor(t){A(this,"targets",[]),A(this,"__disposer",void 0);const e=()=>{const{hiddenTextarea:i}=t.getActiveObject()||{};i&&i.focus()},s=t.upperCanvasEl;s.addEventListener("click",e),this.__disposer=()=>s.removeEventListener("click",e)}exitTextEditing(){this.target=void 0,this.targets.forEach(t=>{t.isEditing&&t.exitEditing()})}add(t){this.targets.push(t)}remove(t){this.unregister(t),Kn(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 g_=["target","oldTarget","fireCanvas","e"],Ue={passive:!1},Fo=(a,t)=>{const e=a.getViewportPoint(t),s=a.getScenePoint(t);return{viewportPoint:e,scenePoint:s,pointer:e,absolutePointer:s}},gn=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)},os=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)},f_={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 tg extends Mc{constructor(t){super(t,arguments.length>1&&arguments[1]!==void 0?arguments[1]:{}),A(this,"_isClick",void 0),A(this,"textEditingManager",new u_(this)),["_onMouseDown","_onTouchStart","_onMouseMove","_onMouseUp","_onTouchEnd","_onResize","_onMouseWheel","_onMouseOut","_onMouseEnter","_onContextMenu","_onDoubleClick","_onDragStart","_onDragEnd","_onDragProgress","_onDragOver","_onDragEnter","_onDragLeave","_onDrop"].forEach(e=>{this[e]=this[e].bind(this)}),this.addOrRemove(gn,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const s=this.upperCanvasEl,i=this._getEventPrefix();t(xp(s),"resize",this._onResize),t(s,i+"down",this._onMouseDown),t(s,"".concat(i,"move"),this._onMouseMove,Ue),t(s,"".concat(i,"out"),this._onMouseOut),t(s,"".concat(i,"enter"),this._onMouseEnter),t(s,"wheel",this._onMouseWheel),t(s,"contextmenu",this._onContextMenu),t(s,"dblclick",this._onDoubleClick),t(s,"dragstart",this._onDragStart),t(s,"dragend",this._onDragEnd),t(s,"dragover",this._onDragOver),t(s,"dragenter",this._onDragEnter),t(s,"dragleave",this._onDragLeave),t(s,"drop",this._onDrop),this.enablePointerEvents||t(s,"touchstart",this._onTouchStart,Ue)}removeListeners(){this.addOrRemove(os,"remove");const t=this._getEventPrefix(),e=_s(this.upperCanvasEl);os(e,"".concat(t,"up"),this._onMouseUp),os(e,"touchend",this._onTouchEnd,Ue),os(e,"".concat(t,"move"),this._onMouseMove,Ue),os(e,"touchmove",this._onMouseMove,Ue)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s=T({e:t},Fo(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},Fo(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 gn(this.upperCanvasEl,"drag",this._onDragProgress)}Mu(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!==Se,s=e?this._activeObject:void 0,i={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:s};os(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 l=i[h];l.canDrop(t)&&(o=l),l.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},Fo(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&&Mu(t),this._basicEventHandler("contextmenu",i),!1}_onDoubleClick(t){this._cacheTransformEventData(t),this._handleEvent(t,"dblclick"),this._resetTransformEventData()}getPointerId(t){const e=t.changedTouches;return e?e[0]&&e[0].identifier:this.enablePointerEvents?t.pointerId:-1}_isMainEvent(t){return t.isPrimary===!0||t.isPrimary!==!1&&(t.type==="touchend"&&t.touches.length===0||!t.changedTouches||t.changedTouches[0].identifier===this.mainTouchId)}_onTouchStart(t){t.preventDefault(),this.mainTouchId===void 0&&(this.mainTouchId=this.getPointerId(t)),this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix(),i=_s(e);gn(i,"touchend",this._onTouchEnd,Ue),gn(i,"touchmove",this._onMouseMove,Ue),os(e,"".concat(s,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();os(e,"".concat(s,"move"),this._onMouseMove,Ue);const i=_s(e);gn(i,"".concat(s,"up"),this._onMouseUp),gn(i,"".concat(s,"move"),this._onMouseMove,Ue)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),s=_s(this.upperCanvasEl);os(s,"touchend",this._onTouchEnd,Ue),os(s,"touchmove",this._onMouseMove,Ue),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout(()=>{gn(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=_s(this.upperCanvasEl);os(i,"".concat(s,"up"),this._onMouseUp),os(i,"".concat(s,"move"),this._onMouseMove,Ue),gn(e,"".concat(s,"move"),this._onMouseMove,Ue)}}_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,l=!1;if(s&&(this._finalizeCurrentTransform(t),l=s.actionPerformed),!i){const d=n===this._activeObject;this.handleSelection(t),l||(l=this._shouldRender(n)||!d&&n===this._activeObject)}if(n){const d=n.findControl(this.getViewportPoint(t),lc(t)),{key:u,control:g}=d||{};if(h=u,n.selectable&&n!==this._activeObject&&n.activeOn==="up")this.setActiveObject(n,t),l=!0;else if(g){const f=g.getMouseUpHandler(t,n,g);f&&(o=this.getScenePoint(t),f.call(g,t,s,o.x,o.y))}n.isMoving=!1}if(s&&(s.target!==n||s.corner!==h)){const d=s.target&&s.target.controls[s.corner],u=d&&d.getMouseUpHandler(t,s.target,d);o=o||this.getScenePoint(t),u&&u.call(d,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),l?this.requestRenderAll():i||(e=this._activeObject)!==null&&e!==void 0&&e.isEditing||this.renderTop()}_basicEventHandler(t,e){const{target:s,subTargets:i=[]}=e;this.fire(t,e),s&&s.fire(t,e);for(let n=0;n<i.length;n++)i[n]!==s&&i[n].fire(t,e);return e}_handleEvent(t,e){const s=this._target,i=this.targets||[],n=T(T({e:t,target:s,subTargets:i},Fo(this,t)),{},{transform:this._currentTransform},e==="up:before"||e==="up"?{isClick:this._isClick,currentTarget:this.findTarget(t),currentSubTargets:this.targets}:{});this.fire("mouse:".concat(e),n),s&&s.fire("mouse".concat(e),n);for(let r=0;r<i.length;r++)i[r]!==s&&i[r].fire("mouse".concat(e),n)}_onMouseDownInDrawingMode(t){this._isCurrentlyDrawing=!0,this.getActiveObject()&&(this.discardActiveObject(t),this.requestRenderAll());const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseDown(e,{e:t,pointer:e}),this._handleEvent(t,"down")}_onMouseMoveInDrawingMode(t){if(this._isCurrentlyDrawing){const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseMove(e,{e:t,pointer:e})}this.setCursor(this.freeDrawingCursor),this._handleEvent(t,"move")}_onMouseUpInDrawingMode(t){const e=this.getScenePoint(t);this.freeDrawingBrush?this._isCurrentlyDrawing=!!this.freeDrawingBrush.onMouseUp({e:t,pointer:e}):this._isCurrentlyDrawing=!1,this._handleEvent(t,"up")}__onMouseDown(t){this._isClick=!0,this._cacheTransformEventData(t),this._handleEvent(t,"down:before");let e=this._target;const{button:s}=t;if(s)return(this.fireMiddleClick&&s===1||this.fireRightClick&&s===2)&&this._handleEvent(t,"down"),void this._resetTransformEventData();if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t)||this._currentTransform)return;let i=this._shouldRender(e),n=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,n=!0,i=!0):this._shouldClearSelection(t,e)&&this.discardActiveObject(t),this.selection&&(!e||!e.selectable&&!e.isEditing&&e!==this._activeObject)){const r=this.getScenePoint(t);this._groupSelector={x:r.x,y:r.y,deltaY:0,deltaX:0}}if(e){const r=e===this._activeObject;e.selectable&&e.activeOn==="down"&&this.setActiveObject(e,t);const o=e.findControl(this.getViewportPoint(t),lc(t));if(e===this._activeObject&&(o||!n)){this._setupCurrentTransform(t,e,r);const h=o?o.control:void 0,l=this.getScenePoint(t),d=h&&h.getMouseDownHandler(t,e,h);d&&d.call(h,t,this._currentTransform,l.x,l.y)}}i&&(this._objectsToRender=void 0),this._handleEvent(t,"down"),i&&this.requestRenderAll()}_resetTransformEventData(){this._target=void 0,this._pointer=void 0,this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getViewportPoint(t),this._absolutePointer=tr(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=wt(e,g_);const{targetIn:h,targetOut:l,canvasIn:d,canvasOut:u}=f_[t],g=i!==s;if(i&&g){const f=T(T({},o),{},{e:r,target:i,nextTarget:s},Fo(this,r));n&&this.fire(u,f),i.fire(l,f)}if(s&&g){const f=T(T({},o),{},{e:r,target:s,previousTarget:i},Fo(this,r));n&&this.fire(d,f),s.fire(h,f)}}__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?tr(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=Zn(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=Zn(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.exitEditing&&s.exitEditing();const n=new(N.getClass("ActiveSelection"))([],{canvas:this});n.multiSelectAdd(s,e),this._hoveredTarget=n,this._setActiveObject(n,t),this._fireSelectionEvents([s],t)}return!0}return!1}handleSelection(t){if(!this.selection||!this._groupSelector)return!1;const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new D(e,s),o=r.add(new D(i,n)),h=r.min(o),l=r.max(o).subtract(h),d=this.collectObjects({left:h.x,top:h.y,width:l.x,height:l.y},{includeIntersecting:!this.selectionFullyContained}),u=r.eq(o)?d[0]?[d[0]]:[]:d.length>1?d.filter(g=>!g.onSelect({e:t})).reverse():d;if(u.length===1)this.setActiveObject(u[0],t);else if(u.length>1){const g=N.getClass("ActiveSelection");this.setActiveObject(new g(u,{canvas:this}),t)}return this._groupSelector=null,!0}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const Fm={x1:0,y1:0,x2:0,y2:0},p_=T(T({},Fm),{},{r1:0,r2:0}),Ro=(a,t)=>isNaN(a)&&typeof t=="number"?t:a,m_=/^(\d+\.\d+)%|(\d+)%$/;function Rm(a){return a&&m_.test(a)}function Im(a,t){const e=typeof a=="number"?a:typeof a=="string"?parseFloat(a)/(Rm(a)?100:1):NaN;return er(0,Ro(e,t),1)}const b_=/\s*;\s*/,v_=/\s*:\s*/;function y_(a,t){let e,s;const i=a.getAttribute("style");if(i){const r=i.split(b_);r[r.length-1]===""&&r.pop();for(let o=r.length;o--;){const[h,l]=r[o].split(v_).map(d=>d.trim());h==="stop-color"?e=l:h==="stop-opacity"&&(s=l)}}const n=new ut(e||a.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:Im(a.getAttribute("offset"),0),color:n.toRgb(),opacity:Ro(parseFloat(s||a.getAttribute("stop-opacity")||""),1)*n.getAlpha()*t}}function __(a,t){const e=[],s=a.getElementsByTagName("stop"),i=Im(t,1);for(let n=s.length;n--;)e.push(y_(s[n],i));return e}function jm(a){return a.nodeName==="linearGradient"||a.nodeName==="LINEARGRADIENT"?"linear":"radial"}function Nm(a){return a.getAttribute("gradientUnits")==="userSpaceOnUse"?"pixels":"percentage"}function Cs(a,t){return a.getAttribute(t)}function w_(a,t){return function(e,s){let i,{width:n,height:r,gradientUnits:o}=s;return Object.keys(e).reduce((h,l)=>{const d=e[l];return d==="Infinity"?i=1:d==="-Infinity"?i=0:(i=typeof d=="string"?parseFloat(d):d,typeof d=="string"&&Rm(d)&&(i*=.01,o==="pixels"&&(l!=="x1"&&l!=="x2"&&l!=="r2"||(i*=n),l!=="y1"&&l!=="y2"||(i*=r)))),h[l]=i,h},{})}(jm(a)==="linear"?function(e){return{x1:Cs(e,"x1")||0,y1:Cs(e,"y1")||0,x2:Cs(e,"x2")||"100%",y2:Cs(e,"y2")||0}}(a):function(e){return{x1:Cs(e,"fx")||Cs(e,"cx")||"50%",y1:Cs(e,"fy")||Cs(e,"cy")||"50%",r1:0,x2:Cs(e,"cx")||"50%",y2:Cs(e,"cy")||"50%",r2:Cs(e,"r")||"50%"}}(a),T(T({},t),{},{gradientUnits:Nm(a)}))}class oh{constructor(t){const{type:e="linear",gradientUnits:s="pixels",coords:i={},colorStops:n=[],offsetX:r=0,offsetY:o=0,gradientTransform:h,id:l}=t||{};Object.assign(this,{type:e,gradientUnits:s,coords:T(T({},e==="radial"?p_:Fm),i),colorStops:n,offsetX:r,offsetY:o,gradientTransform:h,id:l?"".concat(l,"_").concat(cn()):cn()})}addColorStop(t){for(const e in t){const s=new ut(t[e]);this.colorStops.push({offset:parseFloat(e),color:s.toRgb(),opacity:s.getAlpha()})}return this}toObject(t){return T(T({},Jn(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():xe.concat(),n=this.gradientUnits==="pixels"?"userSpaceOnUse":"objectBoundingBox",r=this.colorStops.map(u=>T({},u)).sort((u,g)=>u.offset-g.offset);let o=-this.offsetX,h=-this.offsetY;var l;n==="objectBoundingBox"?(o/=t.width,h/=t.height):(o+=t.width/2,h+=t.height/2),(l=t)&&typeof l._renderPathCommands=="function"&&this.gradientUnits!=="percentage"&&(o-=t.pathOffset.x,h-=t.pathOffset.y),i[4]-=o,i[5]-=h;const d=['id="SVGID_'.concat(this.id,'"'),'gradientUnits="'.concat(n,'"'),'gradientTransform="'.concat(e?e+" ":"").concat(Ja(i),'"'),""].join(" ");if(this.type==="linear"){const{x1:u,y1:g,x2:f,y2:p}=this.coords;s.push("<linearGradient ",d,' x1="',u,'" y1="',g,'" x2="',f,'" y2="',p,`">
42
+ `)}else if(this.type==="radial"){const{x1:u,y1:g,x2:f,y2:p,r1:m,r2:_}=this.coords,v=m>_;s.push("<radialGradient ",d,' cx="',v?u:f,'" cy="',v?g:p,'" r="',v?m:_,'" fx="',v?f:u,'" fy="',v?p:g,`">
43
+ `),v&&(r.reverse(),r.forEach(S=>{S.offset=1-S.offset}));const x=Math.min(m,_);if(x>0){const S=x/Math.max(m,_);r.forEach(C=>{C.offset+=S*(1-C.offset)})}}return r.forEach(u=>{let{color:g,offset:f,opacity:p}=u;s.push("<stop ",'offset="',100*f+"%",'" style="stop-color:',g,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(l=>{let{color:d,opacity:u,offset:g}=l;h.addColorStop(g,u!==void 0?new ut(d).setAlpha(u).toRgba():d)}),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=jm(t),n=e._findCenterFromElement();return new this(T({id:t.getAttribute("id")||void 0,type:Im(t),coords:v_(t,{width:s.viewBoxWidth||s.width,height:s.viewBoxHeight||s.height}),colorStops:b_(t,s.opacity),gradientUnits:i,gradientTransform:wc(t.getAttribute("gradientTransform")||"")},i==="pixels"?{offsetX:e.width/2-n.x,offsetY:e.height/2-n.y}:{offsetX:0,offsetY:0}))}}A(oh,"type","Gradient"),X.setClass(oh,"gradient"),X.setClass(oh,"linear"),X.setClass(oh,"radial");const y_=["type","source","patternTransform"];class tg{get type(){return"pattern"}set type(t){pi("warn","Setting type has no effect",t)}constructor(t){A(this,"repeat","repeat"),A(this,"offsetX",0),A(this,"offsetY",0),A(this,"crossOrigin",""),this.id=cn(),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({},Jn(this,t)),{},{type:"pattern",source:this.sourceToString(),repeat:e,crossOrigin:s,offsetX:Ct(this.offsetX,at.NUM_FRACTION_DIGITS),offsetY:Ct(this.offsetY,at.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=Ro(this.offsetX/e,0),h=Ro(this.offsetY/s,0),l=n==="repeat-y"||n==="no-repeat"?1+Math.abs(o||0):Ro(i.width/e,0),d=n==="repeat-x"||n==="no-repeat"?1+Math.abs(h||0):Ro(i.height/s,0);return['<pattern id="SVGID_'.concat(r,'" x="').concat(o,'" y="').concat(h,'" width="').concat(l,'" height="').concat(d,'">'),'<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=St(t,y_);const o=await Ka(i,T(T({},e),{},{crossOrigin:r.crossOrigin}));return new this(T(T({},r),{},{patternTransform:n&&n.slice(0),source:o}))}}A(tg,"type","Pattern"),X.setClass(tg),X.setClass(tg,"pattern");const __=["path","left","top"],w_=["d"];class sr extends ue{constructor(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{path:s,left:i,top:n}=e,r=St(e,__);super(),Object.assign(this,sr.ownDefaults),this.setOptions(r),this._setPath(t||[],!0),typeof i=="number"&&this.set(lt,i),typeof n=="number"&&this.set(Ie,n)}_setPath(t,e){this.path=xm(Array.isArray(t)?t:Om(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=Dm(this.path,at.NUM_FRACTION_DIGITS);return["<path ","COMMON_PARTS",'d="'.concat(t,`" stroke-linecap="round" />
47
- `)]}_getOffsetTransform(){const t=at.NUM_FRACTION_DIGITS;return" translate(".concat(Ct(-this.pathOffset.x,t),", ").concat(Ct(-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(...Qu(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(...Qu(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 Vs(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=_i(t,this.ATTRIBUTE_NAMES,s),{d:n}=i;return new this(n,T(T(T({},St(i,w_)),e),{},{left:void 0,top:void 0}))}}A(sr,"type","Path"),A(sr,"cacheProperties",[...vi,"path","fillRule"]),A(sr,"ATTRIBUTE_NAMES",[...un,"d"]),X.setClass(sr),X.setSVGClass(sr);const x_=["left","top","radius"],Nm=["radius","startAngle","endAngle","counterClockwise"];class xi extends ue{static getDefaults(){return T(T({},super.getDefaults()),xi.ownDefaults)}constructor(t){super(),Object.assign(this,xi.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,Pt(this.startAngle),Pt(this.endAngle),this.counterClockwise),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get(Ce)}getRadiusY(){return this.get("radius")*this.get(Ge)}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([...Nm,...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=Pt(this.startAngle),i=Pt(this.endAngle),n=vs(s)*e,r=ys(s)*e,o=vs(i)*e,h=ys(i)*e,l=t>180?1:0,d=this.counterClockwise?0:1;return['<path d="M '.concat(n," ").concat(r," A ").concat(e," ").concat(e," 0 ").concat(l," ").concat(d," ").concat(o," ").concat(h,'" '),"COMMON_PARTS",` />
49
- `]}}static async fromElement(t,e,s){const i=_i(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,radius:o=0}=i;return new this(T(T({},St(i,x_)),{},{radius:o,left:n-o,top:r-o}))}static fromObject(t){return super._fromObject(t)}}A(xi,"type","Circle"),A(xi,"cacheProperties",[...vi,...Nm]),A(xi,"ownDefaults",{radius:0,startAngle:0,endAngle:360,counterClockwise:!1}),A(xi,"ATTRIBUTE_NAMES",["cx","cy","r",...un]),X.setClass(xi),X.setSVGClass(xi);const S_=["x1","y1","x2","y2"],C_=["x1","y1","x2","y2"],eg=["x1","x2","y1","y2"];class ir extends ue{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,ir.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(lt,r),typeof o=="number"&&this.set(Ie,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}=Vs([{x:t,y:e},{x:s,y:i}]),l=new M(n+o/2,r+h/2);this.setPositionByOrigin(l,J,J)}_set(t,e){return super._set(t,e),eg.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;rs(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=_i(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],St(i,S_))}static fromObject(t){let{x1:e,y1:s,x2:i,y2:n}=t,r=St(t,C_);return this._fromObject(T(T({},r),{},{points:[e,s,i,n]}),{extraParam:"points"})}}A(ir,"type","Line"),A(ir,"cacheProperties",[...vi,...eg]),A(ir,"ATTRIBUTE_NAMES",un.concat(eg)),X.setClass(ir),X.setSVGClass(ir);class nr extends ue{static getDefaults(){return T(T({},super.getDefaults()),nr.ownDefaults)}constructor(t){super(),Object.assign(this,nr.ownDefaults),this.setOptions(t)}_render(t){const e=this.width/2,s=this.height/2;t.beginPath(),t.moveTo(-e,s),t.lineTo(0,-s),t.lineTo(e,s),t.closePath(),this._renderPaintInOrder(t)}_toSVG(){const t=this.width/2,e=this.height/2;return["<polygon ","COMMON_PARTS",'points="',"".concat(-t," ").concat(e,",0 ").concat(-e,",").concat(t," ").concat(e),'" />']}}A(nr,"type","Triangle"),A(nr,"ownDefaults",{width:100,height:100}),X.setClass(nr),X.setSVGClass(nr);const Bm=["rx","ry"];class Si extends ue{static getDefaults(){return T(T({},super.getDefaults()),Si.ownDefaults)}constructor(t){super(),Object.assign(this,Si.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(Ce)}getRy(){return this.get("ry")*this.get(Ge)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...Bm,...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,mi,!1),t.restore(),this._renderPaintInOrder(t)}static async fromElement(t,e,s){const i=_i(t,this.ATTRIBUTE_NAMES,s);return i.left=(i.left||0)-i.rx,i.top=(i.top||0)-i.ry,new this(i)}}function A_(a){if(!a)return[];const t=a.replace(/,/g," ").trim().split(/\s+/),e=[];for(let s=0;s<t.length;s+=2)e.push({x:parseFloat(t[s]),y:parseFloat(t[s+1])});return e}A(Si,"type","Ellipse"),A(Si,"cacheProperties",[...vi,...Bm]),A(Si,"ownDefaults",{rx:0,ry:0}),A(Si,"ATTRIBUTE_NAMES",[...un,"cx","cy","rx","ry"]),X.setClass(Si),X.setSVGClass(Si);const T_=["left","top"],Hm={exactBoundingBox:!1};class As extends ue{static getDefaults(){return T(T({},super.getDefaults()),As.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),A(this,"strokeDiff",void 0),Object.assign(this,As.ownDefaults),this.setOptions(e),this.points=t;const{left:s,top:i}=e;this.initialized=!0,this.setBoundingBox(!0),typeof s=="number"&&this.set(lt,s),typeof i=="number"&&this.set(Ie,i)}isOpen(){return!0}_projectStrokeOnPoints(t){return nm(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(l=>l.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=Vs(e),i=$a(T(T({},t),{},{scaleX:1,scaleY:1})),n=Vs(this.points.map(l=>de(l,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(Pt(this.skewX)),h-=o*Math.tan(Pt(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=Vs(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===Ce||t===Ge)&&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=at.NUM_FRACTION_DIGITS;for(let n=0,r=this.points.length;n<r;n++)t.push(Ct(this.points[n].x-e,i),",",Ct(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(A_(t.getAttribute("points")),T(T({},St(_i(t,this.ATTRIBUTE_NAMES,s),T_)),e))}static fromObject(t){return this._fromObject(t,{extraParam:"points"})}}A(As,"ownDefaults",Hm),A(As,"type","Polyline"),A(As,"layoutProperties",[xo,So,"strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeWidth","strokeUniform","points"]),A(As,"cacheProperties",[...vi,"points"]),A(As,"ATTRIBUTE_NAMES",[...un]),X.setClass(As),X.setSVGClass(As);class Mc extends As{isOpen(){return!1}}A(Mc,"ownDefaults",Hm),A(Mc,"type","Polygon"),X.setClass(Mc),X.setSVGClass(Mc);const Wm=["fontSize","fontWeight","fontFamily","fontStyle"],Xm=["underline","overline","linethrough"],zm=[...Wm,"lineHeight","text","charSpacing","textAlign","styles","path","pathStartOffset","pathSide","pathAlign"],Vm=[...zm,...Xm,"textBackgroundColor","direction"],E_=[...Wm,...Xm,Ae,"strokeWidth",It,"deltaY","textBackgroundColor"],k_={_reNewline:bu,_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:lt,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:lt,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},Ys="justify",Oc="justify-left",ah="justify-right",hh="justify-center";class Gm extends ue{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 l in e[h]){const d=e[h][l]||{};n++,d[t]!==void 0?(i?d[t]!==i&&(r=!1):i=d[t],d[t]===this[t]&&delete d[t]):r=!1,Object.keys(d).length!==0?s++:delete e[h][l]}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=Cu(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({},Jn(this,this.constructor._styleProperties)),this._getStyleDeclaration(t,e))}_setStyleDeclaration(t,e,s){this.styles[t][e]=s}_deleteStyleDeclaration(t,e){delete this.styles[t][e]}_getLineStyle(t){return!!this.styles[t]}_setLineStyle(t){this.styles[t]={}}_deleteLineStyle(t){delete this.styles[t]}}A(Gm,"_styleProperties",E_);const M_=/ +/g,O_=/"/g;function sg(a,t,e,s,i){return" ".concat(function(n,r){let{left:o,top:h,width:l,height:d}=r,u=arguments.length>2&&arguments[2]!==void 0?arguments[2]:at.NUM_FRACTION_DIGITS;const g=Za(It,n,!1),[f,p,m,w]=[o,h,l,d].map(v=>Ct(v,u));return"<rect ".concat(g,' x="').concat(f,'" y="').concat(p,'" width="').concat(m,'" height="').concat(w,'"></rect>')}(a,{left:t,top:e,width:s,height:i}),`
53
- `)}const D_=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let ig;class ge extends Gm{static getDefaults(){return T(T({},super.getDefaults()),ge.ownDefaults)}constructor(t,e){super(),A(this,"__charBounds",[]),Object.assign(this,ge.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=Ju(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(Ys)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,s,i,n,r,o;for(let h=0,l=this._textLines.length;h<l;h++)if((this.textAlign===Ys||h!==l-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 d=0;d<=n.length;d++)r=this.__charBounds[h][d],this._reSpaceAndTab.test(n[d])?(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===Ae?(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=Ie;break;case"descender":t.textBaseline=mu}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,l=this._getLineLeftOffset(n);let d,u,g=0,f=0,p=this.getValueOfPropertyAt(n,0,"textBackgroundColor");for(let m=0;m<h;m++){const w=this.__charBounds[n][m];u=this.getValueOfPropertyAt(n,m,"textBackgroundColor"),this.path?(t.save(),t.translate(w.renderLeft,w.renderTop),t.rotate(w.angle),t.fillStyle=u,u&&t.fillRect(-w.width/2,-o/this.lineHeight*(1-this._fontSizeFraction),w.width,o/this.lineHeight),t.restore()):u!==p?(d=s+l+f,this.direction==="rtl"&&(d=this.width-d-g),t.fillStyle=p,p&&t.fillRect(d,i,g,o/this.lineHeight),f=w.left,g=w.width,p=u):g+=w.kernedWidth}u&&!this.path&&(d=s+l+f,this.direction==="rtl"&&(d=this.width-d-g),t.fillStyle=u,t.fillRect(d,i,g,o/this.lineHeight)),i+=o}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,s,i){const n=Ua.getFontCache(e),r=this._getFontDeclaration(e),o=s+t,h=s&&r===this._getFontDeclaration(i),l=e.fontSize/this.CACHE_FONT_SIZE;let d,u,g,f;if(s&&n[s]!==void 0&&(g=n[s]),n[t]!==void 0&&(f=d=n[t]),h&&n[o]!==void 0&&(u=n[o],f=u-g),d===void 0||g===void 0||u===void 0){const p=function(){if(!ig){const m=jt();m.width=m.height=0,ig=m.getContext("2d")}return ig}();this._setTextStyles(p,e,!0),d===void 0&&(f=d=p.measureText(t).width,n[t]=d),g===void 0&&h&&s&&(g=p.measureText(s).width,n[s]=g),h&&u===void 0&&(u=p.measureText(o).width,n[o]=u,f=u-g)}return{width:d*l,kernedWidth:f*l}}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===Rt,r=this.path,o=this._textLines[t],h=o.length,l=new Array(h);this.__charBounds[t]=l;for(let d=0;d<h;d++){const u=o[d];s=this._getGraphemeBox(u,t,d,e),l[d]=s,i+=s.kernedWidth,e=u}if(l[h]={left:s?s.left+s.width:0,width:0,kernedWidth:0,height:this.fontSize,deltaY:0},r&&r.segmentsInfo){let d=0;const u=r.segmentsInfo[r.segmentsInfo.length-1].length;switch(this.textAlign){case lt:d=n?u-i:0;break;case J:d=(u-i)/2;break;case Rt:d=n?0:u-i}d+=this.pathStartOffset*(n?-1:1);for(let g=n?h-1:0;n?g>=0:g<h;n?g--:g++)s=l[g],d>u?d%=u:d<0&&(d+=u),this._setGraphemeOnPath(d,s),d+=s.kernedWidth}return{width:i,numOfSpaces:0}}_setGraphemeOnPath(t,e){const s=t+e.kernedWidth/2,i=this.path,n=km(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===Rt?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 l,d=h.kernedWidth,u=h.width;this.charSpacing!==0&&(l=this._getWidthOfCharSpacing(),u+=l,d+=l);const g={width:u,left:0,height:r.fontSize,kernedWidth:d,deltaY:r.deltaY};if(s>0&&!n){const f=this.__charBounds[e][s-1];g.left=f.left+f.width+h.kernedWidth-h.width}return g}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),l=h/this.lineHeight,d=this._getLineLeftOffset(r);this._renderTextLine(e,t,this._textLines[r],i+d,n+s+l,r),s+=h}t.restore()}_renderTextFill(t){(this.fill||this.styleHas(It))&&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(Ys),l=this.path,d=!h&&this.charSpacing===0&&this.isEmptyStyles(r)&&!l,u=this.direction==="ltr",g=this.direction==="ltr"?1:-1,f=e.direction;let p,m,w,v,x,S="",C=0;if(e.save(),f!==this.direction&&(e.canvas.setAttribute("dir",u?"ltr":"rtl"),e.direction=u?"ltr":"rtl",e.textAlign=u?lt:Rt),n-=o*this._fontSizeFraction/this.lineHeight,d)return this._renderChar(t,e,r,0,s.join(""),i,n),void e.restore();for(let E=0,k=s.length-1;E<=k;E++)v=E===k||this.charSpacing||l,S+=s[E],w=this.__charBounds[r][E],C===0?(i+=g*(w.kernedWidth-w.width),C+=w.width):C+=w.kernedWidth,h&&!v&&this._reSpaceAndTab.test(s[E])&&(v=!0),v||(p=p||this.getCompleteStyleDeclaration(r,E),m=this.getCompleteStyleDeclaration(r,E+1),v=_c(p,m,!1)),v&&(l?(e.save(),e.translate(w.renderLeft,w.renderTop),e.rotate(w.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=m,i+=g*C,C=0);e.restore()}_applyPatternGradientTransformText(t){const e=jt(),s=this.width+this.strokeWidth,i=this.height+this.strokeWidth,n=e.getContext("2d");return e.width=s,e.height=i,n.beginPath(),n.moveTo(0,0),n.lineTo(s,0),n.lineTo(s,i),n.lineTo(0,i),n.closePath(),n.translate(s/2,i/2),n.fillStyle=t.toLive(n),this._applyPatternGradientTransform(n,t),n.fill(),n.createPattern(e,"no-repeat")}handleFiller(t,e,s){let i,n;return rs(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),l=this.getCompleteStyleDeclaration(s,i),d=t==="fillText"&&l.fill,u=t==="strokeText"&&l.stroke&&l.strokeWidth;if(u||d){if(e.save(),e.font=this._getFontDeclaration(l),h.textBackgroundColor&&this._removeShadow(e),h.deltaY&&(o+=h.deltaY),d){const g=this._setFillStyles(e,l);e.fillText(n,r-g.offsetX,o-g.offsetY)}if(u){const g=this._setStrokeStyles(e,l);e.strokeText(n,r-g.offsetX,o-g.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===Ys||i===hh&&!r||i===ah&&!r||i===Oc&&!r?0:(i===J&&(o=s/2),i===Rt&&(o=s),i===hh&&(o=s/2),i===ah&&(o=s),n==="rtl"&&(i===Rt||i===Ys||i===ah?o=0:i===lt||i===Oc?o=-s:i!==J&&i!==hh||(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,l=this._textLines.length;h<l;h++){const d=this.getHeightOfLine(h);if(!this[e]&&!this.styleHas(e,h)){s+=d;continue}const u=this._textLines[h],g=d/this.lineHeight,f=this._getLineLeftOffset(h);let p,m,w=0,v=0,x=this.getValueOfPropertyAt(h,0,e),S=this.getValueOfPropertyAt(h,0,It);const C=s+g*(1-this._fontSizeFraction);let E=this.getHeightOfChar(h,0),k=this.getValueOfPropertyAt(h,0,"deltaY");for(let D=0,R=u.length;D<R;D++){const B=this.__charBounds[h][D];p=this.getValueOfPropertyAt(h,D,e),m=this.getValueOfPropertyAt(h,D,It);const O=this.getHeightOfChar(h,D),F=this.getValueOfPropertyAt(h,D,"deltaY");if(n&&p&&m)t.save(),t.fillStyle=S,t.translate(B.renderLeft,B.renderTop),t.rotate(B.angle),t.fillRect(-B.kernedWidth/2,o*O+F,B.kernedWidth,this.fontSize/15),t.restore();else if((p!==x||m!==S||O!==E||F!==k)&&v>0){let L=i+f+w;this.direction==="rtl"&&(L=this.width-L-v),x&&S&&(t.fillStyle=S,t.fillRect(L,C+o*E+k,v,this.fontSize/15)),w=B.left,v=B.width,x=p,S=m,E=O,k=F}else v+=B.kernedWidth}let P=i+f+w;this.direction==="rtl"&&(P=this.width-P-v),t.fillStyle=m,p&&m&&t.fillRect(P,C+o*E+k,v-r,this.fontSize/15),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(",")||ge.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 yc(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([...Vm,...t])),{},{styles:om(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=_i(t,ge.ATTRIBUTE_NAMES,s),n=T(T({},e),i),{textAnchor:r=lt,textDecoration:o="",dx:h=0,dy:l=0,top:d=0,left:u=0,fontSize:g=pu,strokeWidth:f=1}=n,p=St(n,D_),m=new this((t.textContent||"").replace(/^\s+|\s+$|\n+/g,"").replace(/\s+/g," "),T({left:u+h,top:d+l,underline:o.includes("underline"),overline:o.includes("overline"),linethrough:o.includes("line-through"),strokeWidth:0,fontSize:g},p)),w=m.getScaledHeight()/m.height,v=((m.height+m.strokeWidth)*m.lineHeight-m.height)*w,x=m.getScaledHeight()+v;let S=0;return r===J&&(S=m.getScaledWidth()/2),r===Rt&&(S=m.getScaledWidth()),m.set({left:m.left-S,top:m.top-(x-m.fontSize*(.07+m._fontSizeFraction))/m.lineHeight,strokeWidth:f}),m}static fromObject(t){return this._fromObject(T(T({},t),{},{styles:am(t.styles||{},t.text)}),{extraParam:"text"})}}A(ge,"textLayoutProperties",zm),A(ge,"cacheProperties",[...vi,...Vm]),A(ge,"ownDefaults",k_),A(ge,"type","Text"),A(ge,"genericFonts",["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong"]),A(ge,"ATTRIBUTE_NAMES",un.concat("x","y","dx","dy","font-family","font-style","font-weight","font-size","letter-spacing","text-decoration","text-anchor")),tm(ge,[class extends Fp{_toSVG(){const a=this._getSVGLeftTopOffsets(),t=this._getSVGTextAndBg(a.textTop,a.textLeft);return this._wrapSVGTextAndBg(t)}toSVG(a){return this._createBaseSVGMarkup(this._toSVG(),{reviver:a,noStyle:!0,withShadow:!0})}_getSVGLeftTopOffsets(){return{textLeft:-this.width/2,textTop:-this.height/2,lineTop:this.getHeightOfLine(0)}}_wrapSVGTextAndBg(a){let{textBgRects:t,textSpans:e}=a;const s=this.getSvgTextDecoration(this);return[t.join(""),' <text xml:space="preserve" ',this.fontFamily?'font-family="'.concat(this.fontFamily.replace(O_,"'"),'" '):"",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(...sg(this.backgroundColor,-this.width/2,-this.height/2,this.width,this.height));for(let r=0,o=this._textLines.length;r<o;r++)i=this._getLineLeftOffset(r),this.direction==="rtl"&&(i+=this.width),(this.textBackgroundColor||this.styleHas("textBackgroundColor",r))&&this._setSVGTextLineBg(s,r,t+i,n),this._setSVGTextLineText(e,r,t+i,n),n+=this.getHeightOfLine(r);return{textSpans:e,textBgRects:s}}_createTextCharSpan(a,t,e,s){const i=this.getSvgSpanStyles(t,a!==a.trim()||!!a.match(M_)),n=i?'style="'.concat(i,'"'):"",r=t.deltaY,o=r?' dy="'.concat(Ct(r,at.NUM_FRACTION_DIGITS),'" '):"";return'<tspan x="'.concat(Ct(e,at.NUM_FRACTION_DIGITS),'" y="').concat(Ct(s,at.NUM_FRACTION_DIGITS),'" ').concat(o).concat(n,">").concat(rm(a),"</tspan>")}_setSVGTextLineText(a,t,e,s){const i=this.getHeightOfLine(t),n=this.textAlign.includes(Ys),r=this._textLines[t];let o,h,l,d,u,g="",f=0;s+=i*(1-this._fontSizeFraction)/this.lineHeight;for(let p=0,m=r.length-1;p<=m;p++)u=p===m||this.charSpacing,g+=r[p],l=this.__charBounds[t][p],f===0?(e+=l.kernedWidth-l.width,f+=l.width):f+=l.kernedWidth,n&&!u&&this._reSpaceAndTab.test(r[p])&&(u=!0),u||(o=o||this.getCompleteStyleDeclaration(t,p),h=this.getCompleteStyleDeclaration(t,p+1),u=_c(o,h,!0)),u&&(d=this._getStyleDeclaration(t,p),a.push(this._createTextCharSpan(g,d,e,s)),g="",o=h,this.direction==="rtl"?e-=f:e+=f,f=0)}_setSVGTextLineBg(a,t,e,s){const i=this._textLines[t],n=this.getHeightOfLine(t)/this.lineHeight;let r,o=0,h=0,l=this.getValueOfPropertyAt(t,0,"textBackgroundColor");for(let d=0;d<i.length;d++){const{left:u,width:g,kernedWidth:f}=this.__charBounds[t][d];r=this.getValueOfPropertyAt(t,d,"textBackgroundColor"),r!==l?(l&&a.push(...sg(l,e+h,s,o,n)),h=u,o=g,l=r):o+=f}r&&a.push(...sg(l,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:l}=a,d=this.getSvgTextDecoration(a);return[i?Za(Ae,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,"; "):"",d&&"text-decoration: ".concat(d,"; "),n?Za(It,n):"",l?"baseline-shift: ".concat(-l,"; "):"",t?"white-space: pre; ":""].join("")}getSvgTextDecoration(a){return["overline","underline","line-through"].filter(t=>a[t.replace("-","")]).join(" ")}}]),X.setClass(ge),X.setSVGClass(ge);class P_{constructor(t){A(this,"target",void 0),A(this,"__mouseDownInPlace",!1),A(this,"__dragStartFired",!1),A(this,"__isDraggingOver",!1),A(this,"__dragStartSelection",void 0),A(this,"__dragImageDisposer",void 0),A(this,"_dispose",void 0),this.target=t;const e=[this.target.on("dragenter",this.dragEnterHandler.bind(this)),this.target.on("dragover",this.dragOverHandler.bind(this)),this.target.on("dragleave",this.dragLeaveHandler.bind(this)),this.target.on("dragend",this.dragEndHandler.bind(this)),this.target.on("drop",this.dropHandler.bind(this))];this._dispose=()=>{e.forEach(s=>s()),this._dispose=void 0}}isPointerOverSelection(t){const e=this.target,s=e.getSelectionStartFromPointer(t);return e.isEditing&&s>=e.selectionStart&&s<=e.selectionEnd&&e.selectionStart<e.selectionEnd}start(t){return this.__mouseDownInPlace=this.isPointerOverSelection(t)}isActive(){return this.__mouseDownInPlace}end(t){const e=this.isActive();return e&&!this.__dragStartFired&&(this.target.setCursorByClick(t),this.target.initDelayedCursor(!0)),this.__mouseDownInPlace=!1,this.__dragStartFired=!1,this.__isDraggingOver=!1,e}getDragStartSelection(){return this.__dragStartSelection}setDragImage(t,e){var s;let{selectionStart:i,selectionEnd:n}=e;const r=this.target,o=r.canvas,h=new M(r.flipX?-1:1,r.flipY?-1:1),l=r._getCursorBoundaries(i),d=new M(l.left+l.leftOffset,l.top+l.topOffset).multiply(h).transform(r.calcTransformMatrix()),u=o.getScenePoint(t).subtract(d),g=r.getCanvasRetinaScaling(),f=r.getBoundingRect(),p=d.subtract(new M(f.left,f.top)),m=o.viewportTransform,w=p.add(u).transform(m,!0),v=r.backgroundColor,x=Gu(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=v,r.styles=x,r.dirty=!0,Tc(C,{position:"fixed",left:"".concat(-C.width,"px"),border:Se,width:"".concat(C.width/g,"px"),height:"".concat(C.height/g,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{C.remove()},_s(t.target||this.target.hiddenTextarea).body.appendChild(C),(s=t.dataTransfer)===null||s===void 0||s.setDragImage(C,w.x,w.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:l}=s.dataTransfer.types.includes("application/fabric")?JSON.parse(s.dataTransfer.getData("application/fabric")):{},d=n[Math.max(0,n.length-1)],u=0;if(this.__dragStartSelection){const g=this.__dragStartSelection.selectionStart,f=this.__dragStartSelection.selectionEnd;h>g&&h<=f?h=g:h>f&&(h-=f-g),r.removeChars(g,f),delete this.__dragStartSelection}r._reNewline.test(d)&&(r._reNewline.test(r._text[h])||h===r._text.length)&&(n=n.trimEnd()),t.didDrop=!0,t.dropTarget=r,r.insertChars(n,l,h),o.setActiveObject(r),r.enterEditing(s),r.selectionStart=Math.min(h+u,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(tc,{index:h+u,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)||Se;h===Se?(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(tc,{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 Um=/[ \n\.,;!\?\-]/;class L_ extends ge{constructor(){super(...arguments),A(this,"_currentCursorOpacity",1)}initBehavior(){this._tick=this._tick.bind(this),this._onTickComplete=this._onTickComplete.bind(this),this.updateSelectionOnMouseMove=this.updateSelectionOnMouseMove.bind(this)}onDeselect(t){return this.isEditing&&this.exitEditing(),this.selected=!1,super.onDeselect(t)}_animateCursor(t){let{toValue:e,duration:s,delay:i,onComplete:n}=t;return Xu({startValue:this._currentCursorOpacity,endValue:e,duration:s,delay:i,onComplete:n,abort:()=>!this.canvas||this.selectionStart!==this.selectionEnd,onChange:r=>{this._currentCursorOpacity=r,this.renderCursorOrSelection()}})}_tick(t){this._currentTickState=this._animateCursor({toValue:0,duration:this.cursorDuration/2,delay:Math.max(t||0,100),onComplete:this._onTickComplete})}_onTickComplete(){var t;(t=this._currentTickCompleteState)===null||t===void 0||t.abort(),this._currentTickCompleteState=this._animateCursor({toValue:1,duration:this.cursorDuration,onComplete:this._tick})}initDelayedCursor(t){this.abortCursorAnimation(),this._tick(t?0:this.cursorDelay)}abortCursorAnimation(){let t=!1;[this._currentTickState,this._currentTickCompleteState].forEach(e=>{e&&!e.isDone()&&(t=!0,e.abort())}),this._currentCursorOpacity=1,t&&this.clearContextTop()}restartCursorIfNeeded(){[this._currentTickState,this._currentTickCompleteState].some(t=>!t||t.isDone())&&this.initDelayedCursor()}selectAll(){return this.selectionStart=0,this.selectionEnd=this._text.length,this._fireSelectionChanged(),this._updateTextarea(),this}getSelectedText(){return this._text.slice(this.selectionStart,this.selectionEnd).join("")}findWordBoundaryLeft(t){let e=0,s=t-1;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s--;for(;/\S/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findWordBoundaryRight(t){let e=0,s=t;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s++;for(;/\S/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}findLineBoundaryLeft(t){let e=0,s=t-1;for(;!/\n/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findLineBoundaryRight(t){let e=0,s=t;for(;!/\n/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}searchWordBoundary(t,e){const s=this._text;let i=t>0&&this._reSpace.test(s[t])&&(e===-1||!bu.test(s[t-1]))?t-1:t,n=s[i];for(;i>0&&i<s.length&&!Um.test(n);)i+=e,n=s[i];return e===-1&&Um.test(n)&&i++,i}selectWord(t){t=t||this.selectionStart;const e=this.searchWordBoundary(t,-1),s=Math.max(e,this.searchWordBoundary(t,1));this.selectionStart=e,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(t){t=t||this.selectionStart;const e=this.findLineBoundaryLeft(t),s=this.findLineBoundaryRight(t);return this.selectionStart=e,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea(),this}enterEditing(t){!this.isEditing&&this.editable&&(this.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(),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()))}updateSelectionOnMouseMove(t){if(this.getActiveControl())return;const e=this.hiddenTextarea;_s(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(),l=this.canvas.upperCanvasEl,d=l.width/h,u=l.height/h,g=d-r,f=u-r,p=new M(e.left+o,e.top+e.topOffset+r).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new M(l.clientWidth/d,l.clientHeight/u));return p.x<0&&(p.x=0),p.x>g&&(p.x=g),p.y<0&&(p.y=0),p.y>f&&(p.y=f),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()}exitEditing(){const t=this._textBeforeEdit!==this.text;return this._exitEditing(),this.selectionEnd=this.selectionStart,this._restoreEditingProps(),this._forceClearCache&&(this.initDimensions(),this.setCoords()),this.fire("editing:exited"),t&&this.fire(sc),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 l=i;l<r;l++)delete o[l];for(const l in this.styles[s]){const d=parseInt(l,10);d>=r&&(o[d-h]=o[l],delete o[l])}}}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 l=this.styles[t]?this.styles[t][e===0?e:e-1]:void 0;for(const u in this.styles[t]){const g=parseInt(u,10);g>=e&&(h=!0,n[g-e]=this.styles[t][u],o&&e===0||delete this.styles[t][u])}let d=!1;for(h&&!o&&(this.styles[t+s]=n,d=!0),(d||r>e)&&s--;s>0;)i&&i[s-1]?this.styles[t+s]={0:T({},i[s-1])}:l?this.styles[t+s]={0:T({},l)}: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 l=parseInt(h,10);l>=e&&(n[l+s]=r[l],r[l-s]||delete n[l])}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=lt:this._selectionDirection===Rt&&(this._selectionDirection=lt,this.selectionEnd=t),this.selectionStart=s):s>t&&s<e?this._selectionDirection===Rt?this.selectionEnd=s:this.selectionStart=s:(e===t?this._selectionDirection=Rt:this._selectionDirection===lt&&(this._selectionDirection=Rt,this.selectionStart=e),this.selectionEnd=s)}}class F_ extends L_{initHiddenTextarea(){const t=this.canvas&&_s(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;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;const s=()=>{this.updateFromTextArea(),this.fire(tc),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(this.hiddenTextarea.value==="")return this.styles={},void s();const i=this._splitTextIntoLines(this.hiddenTextarea.value).graphemeText,n=this._text.length,r=i.length,o=this.selectionStart,h=this.selectionEnd,l=o!==h;let d,u,g,f,p=r-n;const m=this.fromStringToGraphemeSelection(this.hiddenTextarea.selectionStart,this.hiddenTextarea.selectionEnd,this.hiddenTextarea.value),w=o>m.selectionStart;l?(u=this._text.slice(o,h),p+=h-o):r<n&&(u=w?this._text.slice(h+p,h):this._text.slice(o,o-p));const v=i.slice(m.selectionEnd-p,m.selectionEnd);if(u&&u.length&&(v.length&&(d=this.getSelectionStyles(o,o+1,!1),d=v.map(()=>d[0])),l?(g=o,f=h):w?(g=h-u.length,f=h):(g=h,f=h+u.length),this.removeStyleFromTo(g,f)),v.length){const{copyPasteData:x}=zs();e&&v.join("")===x.copiedText&&!at.disableStyleCopyPaste&&(d=x.copiedTextStyle),this.insertNewStyleBlock(v,o,d)}s()}onCompositionStart(){this.inCompositionMode=!0}onCompositionEnd(){this.inCompositionMode=!1}onCompositionUpdate(t){let{target:e}=t;const{selectionStart:s,selectionEnd:i}=e;this.compositionStart=s,this.compositionEnd=i,this.updateTextareaPosition()}copy(){if(this.selectionStart===this.selectionEnd)return;const{copyPasteData:t}=zs();t.copiedText=this.getSelectedText(),at.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),l=this._textLines[n].slice(0,r),d=this.missingNewlineOffset(n-1);return-this._textLines[n-1].length+h-l.length+(1-d)}_getIndexOnLine(t,e){const s=this._textLines[t];let i,n,r=this._getLineLeftOffset(t),o=0;for(let h=0,l=s.length;h<l;h++)if(i=this.__charBounds[t][h].width,r+=i,r>e){n=!0;const d=r-i,u=r,g=Math.abs(d-e);o=Math.abs(u-e)<g?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===Rt);if(e.shiftKey?this.moveCursorWithShift(s):this.moveCursorWithoutShift(s),s!==0){const i=this.text.length;this.selectionStart=er(0,this.selectionStart,i),this.selectionEnd=er(0,this.selectionEnd,i),this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea()}}moveCursorWithShift(t){const e=this._selectionDirection===lt?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=lt,this.selectionEnd===this.selectionStart&&this.selectionStart!==0&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return this._selectionDirection===Rt&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):this.selectionStart!==0?(this._selectionDirection=lt,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===lt&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection=Rt,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=Rt,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}const ng=a=>!!a.button;class R_ extends F_{constructor(){super(...arguments),A(this,"draggableTextDelegate",void 0)}initBehavior(){this.on("mousedown",this._mouseDownHandler),this.on("mousedown:before",this._mouseDownHandlerBefore),this.on("mouseup",this.mouseUpHandler),this.on("mousedblclick",this.doubleClickHandler),this.on("tripleclick",this.tripleClickHandler),this.__lastClickTime=+new Date,this.__lastLastClickTime=+new Date,this.__lastPointer={},this.on("mousedown",this.onMouseDown),this.draggableTextDelegate=new P_(this),super.initBehavior()}shouldStartDragging(){return this.draggableTextDelegate.isActive()}onDragStart(t){return this.draggableTextDelegate.onDragStart(t)}canDrop(t){return this.draggableTextDelegate.canDrop(t)}onMouseDown(t){if(!this.canvas)return;this.__newClickTime=+new Date;const e=t.pointer;this.isTripleClick(e)&&(this.fire("tripleclick",t),ku(t.e)),this.__lastLastClickTime=this.__lastClickTime,this.__lastClickTime=this.__newClickTime,this.__lastPointer=e,this.__lastSelected=this.selected&&!this.getActiveControl()}isTripleClick(t){return this.__newClickTime-this.__lastClickTime<500&&this.__lastClickTime-this.__lastLastClickTime<500&&this.__lastPointer.x===t.x&&this.__lastPointer.y===t.y}doubleClickHandler(t){this.isEditing&&this.selectWord(this.getSelectionStartFromPointer(t.e))}tripleClickHandler(t){this.isEditing&&this.selectLine(this.getSelectionStartFromPointer(t.e))}_mouseDownHandler(t){let{e}=t;this.canvas&&this.editable&&!ng(e)&&!this.getActiveControl()&&(this.draggableTextDelegate.start(e)||(this.canvas.textEditingManager.register(this),this.selected&&(this.inCompositionMode=!1,this.setCursorByClick(e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection())))}_mouseDownHandlerBefore(t){let{e}=t;this.canvas&&this.editable&&!ng(e)&&(this.selected=this===this.canvas._activeObject)}mouseUpHandler(t){let{e,transform:s}=t;const i=this.draggableTextDelegate.end(e);if(this.canvas){this.canvas.textEditingManager.unregister(this);const n=this.canvas._activeObject;if(n&&n!==this)return}!this.editable||this.group&&!this.group.interactive||s&&s.actionPerformed||ng(e)||i||(this.__lastSelected&&!this.getActiveControl()?(this.selected=!1,this.__lastSelected=!1,this.enterEditing(e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection()):this.selected=!0)}setCursorByClick(t){const e=this.getSelectionStartFromPointer(t),s=this.selectionStart,i=this.selectionEnd;t.shiftKey?this.setSelectionStartEndWithShift(s,i,e):(this.selectionStart=e,this.selectionEnd=e),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())}getSelectionStartFromPointer(t){const e=this.canvas.getScenePoint(t).transform(je(this.calcTransformMatrix())).add(new M(-this._getLeftOffset(),-this._getTopOffset()));let s=0,i=0,n=0;for(let l=0;l<this._textLines.length&&s<=e.y;l++)s+=this.getHeightOfLine(l),n=l,l>0&&(i+=this._textLines[l-1].length+this.missingNewlineOffset(l-1));let r=Math.abs(this._getLineLeftOffset(n));const o=this._textLines[n].length,h=this.__charBounds[n];for(let l=0;l<o;l++){const d=r+h[l].kernedWidth;if(e.x<=d){Math.abs(e.x-d)<=Math.abs(e.x-r)&&i++;break}r=d,i++}return Math.min(this.flipX?o-i:i,this._text.length)}}const Dc="moveCursorUp",Pc="moveCursorDown",Lc="moveCursorLeft",Fc="moveCursorRight",Rc="exitEditing",I_=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:Rc,27:Rc,33:Dc,34:Pc,35:Fc,36:Lc,37:Lc,38:Dc,39:Fc,40:Pc},keysMapRtl:{9:Rc,27:Rc,33:Dc,34:Pc,35:Lc,36:Fc,37:Fc,38:Dc,39:Lc,40:Pc},ctrlKeysMapDown:{65:"selectAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}},{_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1});class Ci extends R_{static getDefaults(){return T(T({},super.getDefaults()),Ci.ownDefaults)}get type(){const t=super.type;return t==="itext"?"i-text":t}constructor(t,e){super(t,T(T({},Ci.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 Zu&&this.canvas.textEditingManager.remove(this),e instanceof Zu&&e.textEditingManager.add(this)),super._set(t,e))}setSelectionStart(t){t=Math.max(t,0),this._updateAndFire("selectionStart",t)}setSelectionEnd(t){t=Math.min(t,this.text.length),this._updateAndFire("selectionEnd",t)}_updateAndFire(t,e){this[t]!==e&&(this._fireSelectionChanged(),this[t]=e),this._updateTextarea()}_fireSelectionChanged(){this.fire("selection:changed"),this.canvas&&this.canvas.fire("text:selection:changed",{target:this})}initDimensions(){this.isEditing&&this.initDelayedCursor(),super.initDimensions()}getSelectionStyles(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart||0,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionEnd,s=arguments.length>2?arguments[2]:void 0;return super.getSelectionStyles(t,e,s)}setSelectionStyles(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionStart||0,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.selectionEnd;return super.setSelectionStyles(t,e,s)}get2DCursorLocation(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;return super.get2DCursorLocation(t,e)}render(t){super.render(t),this.cursorOffsetCache={},this.renderCursorOrSelection()}toCanvasElement(t){const e=this.isEditing;this.isEditing=!1;const s=super.toCanvasElement(t);return this.isEditing=e,s}renderCursorOrSelection(){if(!this.isEditing)return;const t=this.clearContextTop(!0);if(!t)return;const e=this._getCursorBoundaries();this.selectionStart===this.selectionEnd?this.renderCursor(t,e):this.renderSelection(t,e),this.canvas.contextTopDirty=!0,t.restore()}_getCursorBoundaries(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;const s=this._getLeftOffset(),i=this._getTopOffset(),n=this._getCursorBoundariesOffsets(t,e);return{left:s,top:i,leftOffset:n.left,topOffset:n.top}}_getCursorBoundariesOffsets(t,e){return e?this.__getCursorBoundariesOffsets(t):this.cursorOffsetCache&&"top"in this.cursorOffsetCache?this.cursorOffsetCache:this.cursorOffsetCache=this.__getCursorBoundariesOffsets(t)}__getCursorBoundariesOffsets(t){let e=0,s=0;const{charIndex:i,lineIndex:n}=this.get2DCursorLocation(t);for(let l=0;l<n;l++)e+=this.getHeightOfLine(l);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===Rt||this.textAlign===Ys||this.textAlign===ah?h.left*=-1:this.textAlign===lt||this.textAlign===Oc?h.left=r-(s>0?s:0):this.textAlign!==J&&this.textAlign!==hh||(h.left=r-(s>0?s:0))),h}renderCursorAt(t){const e=this._getCursorBoundaries(t,!0);this._renderCursor(this.canvas.contextTop,e,t)}renderCursor(t,e){this._renderCursor(t,e,this.selectionStart)}_renderCursor(t,e,s){const i=this.get2DCursorLocation(s),n=i.lineIndex,r=i.charIndex>0?i.charIndex-1:0,o=this.getValueOfPropertyAt(n,r,"fontSize"),h=this.getObjectScaling().x*this.canvas.getZoom(),l=this.cursorWidth/h,d=this.getValueOfPropertyAt(n,r,"deltaY"),u=e.topOffset+(1-this._fontSizeFraction)*this.getHeightOfLine(n)/this.lineHeight-o*(1-this._fontSizeFraction);this.inCompositionMode&&this.renderSelection(t,e),t.fillStyle=this.cursorColor||this.getValueOfPropertyAt(n,r,It),t.globalAlpha=this._currentCursorOpacity,t.fillRect(e.left+e.leftOffset-l/2,u+e.top+d,l,o)}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(Ys),o=this.get2DCursorLocation(i),h=this.get2DCursorLocation(n),l=o.lineIndex,d=h.lineIndex,u=o.charIndex<0?0:o.charIndex,g=h.charIndex<0?0:h.charIndex;for(let f=l;f<=d;f++){const p=this._getLineLeftOffset(f)||0;let m=this.getHeightOfLine(f),w=0,v=0,x=0;if(f===l&&(v=this.__charBounds[l][u].left),f>=l&&f<d)x=r&&!this.isEndOfWrapping(f)?this.width:this.getLineWidth(f)||5;else if(f===d)if(g===0)x=this.__charBounds[d][g].left;else{const P=this._getWidthOfCharSpacing();x=this.__charBounds[d][g-1].left+this.__charBounds[d][g-1].width-P}w=m,(this.lineHeight<1||f===d&&this.lineHeight>1)&&(m/=this.lineHeight);let S=s.left+p+v,C=m,E=0;const k=x-v;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",C=1,E=m):t.fillStyle=this.selectionColor,this.direction==="rtl"&&(this.textAlign===Rt||this.textAlign===Ys||this.textAlign===ah?S=this.width-S-k:this.textAlign===lt||this.textAlign===Oc?S=s.left+p-x:this.textAlign!==J&&this.textAlign!==hh||(S=s.left+p-x)),t.fillRect(S,s.top+s.topOffset+E,k,C),s.topOffset+=w}}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,It)}_getCurrentCharIndex(){const t=this.get2DCursorLocation(this.selectionStart,!0),e=t.charIndex>0?t.charIndex-1:0;return{l:t.lineIndex,c:e}}dispose(){this._exitEditing(),this.draggableTextDelegate.dispose(),super.dispose()}}A(Ci,"ownDefaults",I_),A(Ci,"type","IText"),X.setClass(Ci),X.setClass(Ci,"i-text");class rr extends Ci{static getDefaults(){return T(T({},super.getDefaults()),rr.ownDefaults)}constructor(t,e){super(t,T(T({},rr.ownDefaults),e))}static createControls(){return{controls:_y()}}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(Ys)&&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 l in h)for(const d in h[l]){const u=parseInt(d,10);if(u>=s&&(!n||u<e))for(const g in h[l][d])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(l=>{const d=e?[l]:this.graphemeSplit(l),u=this._measureWord(d,r,o);return i=Math.max(u,i),o+=d.length+s.length,{word:d,width:u}})}),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,l=[],d=h?"":" ";let u=0,g=[],f=0,p=0,m=!0;e-=r;const w=Math.max(e,i,this.dynamicMinWidth),v=n[t];let x;for(f=0,x=0;x<v.length;x++){const{word:S,width:C}=v[x];f+=S.length,u+=p+C-o,u>w&&!m?(l.push(g),g=[],u=C,m=!0):u+=o,m||h||g.push(d),g=g.concat(S),p=h?0:this._measureWord([d],t,f),f++,m=!1}return x&&l.push(g),i+r>this.dynamicMinWidth&&(this.dynamicMinWidth=i-o+r),l}isEndOfWrapping(t){return!this._styleMap[t+1]||this._styleMap[t+1].line!==this._styleMap[t].line}missingNewlineOffset(t,e){return this.splitByGrapheme&&!e?this.isEndOfWrapping(t)?1:0:1}_splitTextIntoLines(t){const e=super._splitTextIntoLines(t),s=this._wrapText(e.lines,this.width),i=new Array(s.length);for(let n=0;n<s.length;n++)i[n]=s[n].join("");return e.lines=i,e.graphemeLines=s,e}getMinWidth(){return Math.max(this.minWidth,this.dynamicMinWidth)}_removeExtraneousStyles(){const t=new Map;for(const e in this._styleMap){const s=parseInt(e,10);if(this._textLines[s]){const i=this._styleMap[e].line;t.set("".concat(i),!0)}}for(const e in this.styles)t.has(e)||delete this.styles[e]}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject(["minWidth","splitByGrapheme",...t])}}A(rr,"type","Textbox"),A(rr,"textLayoutProperties",[...Ci.textLayoutProperties,"width"]),A(rr,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),X.setClass(rr);class Ym extends Cc{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}=Vs(bm(s,i)),h=new M(r,o);if(i.absolutePositioned)return{center:tr(i.getRelativeCenterPoint(),void 0,n?n.calcTransformMatrix():void 0),size:h};{const l=i.getRelativeCenterPoint().transform(s.calcOwnMatrix(),!0);if(this.shouldPerformLayout(t)){const{center:d=new M,correction:u=new M}=this.calcBoundingBox(e,t)||{};return{center:d.add(l),correction:u.subtract(l),size:h}}return{center:s.getRelativeCenterPoint().add(l),size:h}}}}A(Ym,"type","clip-path"),X.setClass(Ym);class qm extends Cc{getInitialSize(t,e){let{target:s}=t,{size:i}=e;return new M(s.width||i.x,s.height||i.y)}}A(qm,"type","fixed"),X.setClass(qm);class j_ extends nh{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 or extends Us{static getDefaults(){return T(T({},super.getDefaults()),or.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,or.ownDefaults),this.setOptions(e);const{left:s,top:i,layoutManager:n}=e;this.groupInit(t,{left:s,top:i,layoutManager:n??new j_})}_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))?(pi("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===qu?s.forEach(i=>{i._onAfterObjectsChange(xc,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()}}A(or,"type","ActiveSelection"),A(or,"ownDefaults",{multiSelectionStacking:"canvas-stacking"}),X.setClass(or),X.setClass(or,"activeSelection");class N_{constructor(){A(this,"resources",{})}applyFilters(t,e,s,i,n){const r=n.getContext("2d");if(!r)return;r.drawImage(e,0,0,s,i);const o={sourceWidth:s,sourceHeight:i,imageData:r.getImageData(0,0,s,i),originalEl:e,originalImageData:r.getImageData(0,0,s,i),canvasEl:n,ctx:r,filterBackend:this};t.forEach(l=>{l.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 $m{constructor(){let{tileSize:t=at.textureSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};A(this,"aPosition",new Float32Array([0,0,0,1,1,0,1,1])),A(this,"resources",{}),this.tileSize=t,this.setupGLContext(t,t),this.captureGPUInfo()}setupGLContext(t,e){this.dispose(),this.createWebGLCanvas(t,e)}createWebGLCanvas(t,e){const s=jt();s.width=t,s.height=e;const 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 l;r&&(l=this.getCachedTexture(r,e));const d={originalWidth:e.width||e.originalWidth||0,originalHeight:e.height||e.originalHeight||0,sourceWidth:s,sourceHeight:i,destinationWidth:s,destinationHeight:i,context:o,sourceTexture:this.createTexture(o,s,i,l?void 0:e),targetTexture:this.createTexture(o,s,i),originalTexture:l||this.createTexture(o,s,i,l?void 0:e),passes:t.length,webgl:!0,aPosition:this.aPosition,programCache:this.programCache,pass:0,filterBackend:this,targetCanvas:n},u=o.createFramebuffer();return o.bindFramebuffer(o.FRAMEBUFFER,u),t.forEach(g=>{g&&g.applyTo(d)}),function(g){const f=g.targetCanvas,p=f.width,m=f.height,w=g.destinationWidth,v=g.destinationHeight;p===w&&m===v||(f.width=w,f.height=v)}(d),this.copyGLTo2D(o,d),o.bindTexture(o.TEXTURE_2D,null),o.deleteTexture(d.sourceTexture),o.deleteTexture(d.targetTexture),o.deleteFramebuffer(u),h.setTransform(1,0,0,1,0,0),d}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:l,CLAMP_TO_EDGE:d,TEXTURE_MAG_FILTER:u,TEXTURE_MIN_FILTER:g,TEXTURE_WRAP_S:f,TEXTURE_WRAP_T:p}=t,m=t.createTexture();return t.bindTexture(o,m),t.texParameteri(o,u,n||r),t.texParameteri(o,g,n||r),t.texParameteri(o,f,d),t.texParameteri(o,p,d),i?t.texImage2D(o,0,h,h,l,i):t.texImage2D(o,0,h,e,s,0,h,l,null),m}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 l=new ImageData(h,i,n);s.putImageData(l,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 rg;function B_(){const{WebGLProbe:a}=zs();return a.queryWebGL(jt()),at.enableGLFiltering&&a.isSupported(at.textureSize)?new $m({tileSize:at.textureSize}):new N_}function og(){return!rg&&(!(arguments.length>0&&arguments[0]!==void 0)||arguments[0])&&(rg=B_()),rg}const H_=["filters","resizeFilter","src","crossOrigin","type"],Km=["cropX","cropY"];class fe extends ue{static getDefaults(){return T(T({},super.getDefaults()),fe.ownDefaults)}constructor(t,e){super(),A(this,"_lastScaleX",1),A(this,"_lastScaleY",1),A(this,"_filterScalingX",1),A(this,"_filterScalingY",1),this.filters=[],Object.assign(this,fe.ownDefaults),this.setOptions(e),this.cacheKey="texture".concat(cn()),this.setElement(typeof t=="string"?(this.canvas&&_s(this.canvas.getElement())||wo()).getElementById(t):t,e)}getElement(){return this._element}setElement(t){let e=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(e),t.classList.add(fe.CSS_CANVAS),this.filters.length!==0&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){const e=og(!1);e instanceof $m&&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&&zs().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([...Km,...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 l=cn();n.push('<clipPath id="imageCrop_'+l+`">
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(l=>{let{color:d,opacity:u,offset:g}=l;h.addColorStop(g,u!==void 0?new ut(d).setAlpha(u).toRgba():d)}),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=Nm(t),n=e._findCenterFromElement();return new this(T({id:t.getAttribute("id")||void 0,type:jm(t),coords:w_(t,{width:s.viewBoxWidth||s.width,height:s.viewBoxHeight||s.height}),colorStops:__(t,s.opacity),gradientUnits:i,gradientTransform:xc(t.getAttribute("gradientTransform")||"")},i==="pixels"?{offsetX:e.width/2-n.x,offsetY:e.height/2-n.y}:{offsetX:0,offsetY:0}))}}A(oh,"type","Gradient"),N.setClass(oh,"gradient"),N.setClass(oh,"linear"),N.setClass(oh,"radial");const x_=["type","source","patternTransform"];class eg{get type(){return"pattern"}set type(t){pi("warn","Setting type has no effect",t)}constructor(t){A(this,"repeat","repeat"),A(this,"offsetX",0),A(this,"offsetY",0),A(this,"crossOrigin",""),this.id=cn(),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({},Jn(this,t)),{},{type:"pattern",source:this.sourceToString(),repeat:e,crossOrigin:s,offsetX:xt(this.offsetX,at.NUM_FRACTION_DIGITS),offsetY:xt(this.offsetY,at.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=Ro(this.offsetX/e,0),h=Ro(this.offsetY/s,0),l=n==="repeat-y"||n==="no-repeat"?1+Math.abs(o||0):Ro(i.width/e,0),d=n==="repeat-x"||n==="no-repeat"?1+Math.abs(h||0):Ro(i.height/s,0);return['<pattern id="SVGID_'.concat(r,'" x="').concat(o,'" y="').concat(h,'" width="').concat(l,'" height="').concat(d,'">'),'<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=wt(t,x_);const o=await Ka(i,T(T({},e),{},{crossOrigin:r.crossOrigin}));return new this(T(T({},r),{},{patternTransform:n&&n.slice(0),source:o}))}}A(eg,"type","Pattern"),N.setClass(eg),N.setClass(eg,"pattern");const S_=["path","left","top"],C_=["d"];class sr extends ue{constructor(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{path:s,left:i,top:n}=e,r=wt(e,S_);super(),Object.assign(this,sr.ownDefaults),this.setOptions(r),this._setPath(t||[],!0),typeof i=="number"&&this.set(lt,i),typeof n=="number"&&this.set(Ie,n)}_setPath(t,e){this.path=Sm(Array.isArray(t)?t:Dm(t)),this.setBoundingBox(e)}_findCenterFromElement(){const t=this._calcBoundsFromPath();return new D(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=Pm(this.path,at.NUM_FRACTION_DIGITS);return["<path ","COMMON_PARTS",'d="'.concat(t,`" stroke-linecap="round" />
47
+ `)]}_getOffsetTransform(){const t=at.NUM_FRACTION_DIGITS;return" translate(".concat(xt(-this.pathOffset.x,t),", ").concat(xt(-this.pathOffset.y,t),")")}toClipPathSVG(t){const e=this._getOffsetTransform();return" "+this._createBaseClipPathSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}toSVG(t){const e=this._getOffsetTransform();return this._createBaseSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}complexity(){return this.path.length}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{width:e,height:s,pathOffset:i}=this._calcDimensions();this.set({width:e,height:s,pathOffset:i}),t&&this.setPositionByOrigin(i,Q,Q)}_calcBoundsFromPath(){const t=[];let e=0,s=0,i=0,n=0;for(const r of this.path)switch(r[0]){case"L":i=r[1],n=r[2],t.push({x:e,y:s},{x:i,y:n});break;case"M":i=r[1],n=r[2],e=i,s=n;break;case"C":t.push(...Ju(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(...Ju(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 Vs(t)}_calcDimensions(){const t=this._calcBoundsFromPath();return T(T({},t),{},{pathOffset:new D(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=_i(t,this.ATTRIBUTE_NAMES,s),{d:n}=i;return new this(n,T(T(T({},wt(i,C_)),e),{},{left:void 0,top:void 0}))}}A(sr,"type","Path"),A(sr,"cacheProperties",[...vi,"path","fillRule"]),A(sr,"ATTRIBUTE_NAMES",[...un,"d"]),N.setClass(sr),N.setSVGClass(sr);const A_=["left","top","radius"],Bm=["radius","startAngle","endAngle","counterClockwise"];class xi extends ue{static getDefaults(){return T(T({},super.getDefaults()),xi.ownDefaults)}constructor(t){super(),Object.assign(this,xi.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,Ot(this.startAngle),Ot(this.endAngle),this.counterClockwise),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get(Ce)}getRadiusY(){return this.get("radius")*this.get(Ge)}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([...Bm,...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=Ot(this.startAngle),i=Ot(this.endAngle),n=vs(s)*e,r=ys(s)*e,o=vs(i)*e,h=ys(i)*e,l=t>180?1:0,d=this.counterClockwise?0:1;return['<path d="M '.concat(n," ").concat(r," A ").concat(e," ").concat(e," 0 ").concat(l," ").concat(d," ").concat(o," ").concat(h,'" '),"COMMON_PARTS",` />
49
+ `]}}static async fromElement(t,e,s){const i=_i(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,radius:o=0}=i;return new this(T(T({},wt(i,A_)),{},{radius:o,left:n-o,top:r-o}))}static fromObject(t){return super._fromObject(t)}}A(xi,"type","Circle"),A(xi,"cacheProperties",[...vi,...Bm]),A(xi,"ownDefaults",{radius:0,startAngle:0,endAngle:360,counterClockwise:!1}),A(xi,"ATTRIBUTE_NAMES",["cx","cy","r",...un]),N.setClass(xi),N.setSVGClass(xi);const T_=["x1","y1","x2","y2"],E_=["x1","y1","x2","y2"],sg=["x1","x2","y1","y2"];class ir extends ue{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,ir.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(lt,r),typeof o=="number"&&this.set(Ie,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}=Vs([{x:t,y:e},{x:s,y:i}]),l=new D(n+o/2,r+h/2);this.setPositionByOrigin(l,Q,Q)}_set(t,e){return super._set(t,e),sg.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;rs(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 D((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=_i(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],wt(i,T_))}static fromObject(t){let{x1:e,y1:s,x2:i,y2:n}=t,r=wt(t,E_);return this._fromObject(T(T({},r),{},{points:[e,s,i,n]}),{extraParam:"points"})}}A(ir,"type","Line"),A(ir,"cacheProperties",[...vi,...sg]),A(ir,"ATTRIBUTE_NAMES",un.concat(sg)),N.setClass(ir),N.setSVGClass(ir);class nr extends ue{static getDefaults(){return T(T({},super.getDefaults()),nr.ownDefaults)}constructor(t){super(),Object.assign(this,nr.ownDefaults),this.setOptions(t)}_render(t){const e=this.width/2,s=this.height/2;t.beginPath(),t.moveTo(-e,s),t.lineTo(0,-s),t.lineTo(e,s),t.closePath(),this._renderPaintInOrder(t)}_toSVG(){const t=this.width/2,e=this.height/2;return["<polygon ","COMMON_PARTS",'points="',"".concat(-t," ").concat(e,",0 ").concat(-e,",").concat(t," ").concat(e),'" />']}}A(nr,"type","Triangle"),A(nr,"ownDefaults",{width:100,height:100}),N.setClass(nr),N.setSVGClass(nr);const Hm=["rx","ry"];class Si extends ue{static getDefaults(){return T(T({},super.getDefaults()),Si.ownDefaults)}constructor(t){super(),Object.assign(this,Si.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(Ce)}getRy(){return this.get("ry")*this.get(Ge)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...Hm,...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,mi,!1),t.restore(),this._renderPaintInOrder(t)}static async fromElement(t,e,s){const i=_i(t,this.ATTRIBUTE_NAMES,s);return i.left=(i.left||0)-i.rx,i.top=(i.top||0)-i.ry,new this(i)}}function k_(a){if(!a)return[];const t=a.replace(/,/g," ").trim().split(/\s+/),e=[];for(let s=0;s<t.length;s+=2)e.push({x:parseFloat(t[s]),y:parseFloat(t[s+1])});return e}A(Si,"type","Ellipse"),A(Si,"cacheProperties",[...vi,...Hm]),A(Si,"ownDefaults",{rx:0,ry:0}),A(Si,"ATTRIBUTE_NAMES",[...un,"cx","cy","rx","ry"]),N.setClass(Si),N.setSVGClass(Si);const M_=["left","top"],Wm={exactBoundingBox:!1};class As extends ue{static getDefaults(){return T(T({},super.getDefaults()),As.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),A(this,"strokeDiff",void 0),Object.assign(this,As.ownDefaults),this.setOptions(e),this.points=t;const{left:s,top:i}=e;this.initialized=!0,this.setBoundingBox(!0),typeof s=="number"&&this.set(lt,s),typeof i=="number"&&this.set(Ie,i)}isOpen(){return!0}_projectStrokeOnPoints(t){return rm(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(l=>l.projectedPoint):this.points;if(e.length===0)return{left:0,top:0,width:0,height:0,pathOffset:new D,strokeOffset:new D,strokeDiff:new D};const s=Vs(e),i=$a(T(T({},t),{},{scaleX:1,scaleY:1})),n=Vs(this.points.map(l=>de(l,i,!0))),r=new D(this.scaleX,this.scaleY);let o=s.left+s.width/2,h=s.top+s.height/2;return this.exactBoundingBox&&(o-=h*Math.tan(Ot(this.skewX)),h-=o*Math.tan(Ot(this.skewY))),T(T({},s),{},{pathOffset:new D(o,h),strokeOffset:new D(n.left,n.top).subtract(new D(s.left,s.top)).multiply(r),strokeDiff:new D(s.width,s.height).subtract(new D(n.width,n.height)).multiply(r)})}_findCenterFromElement(){const t=Vs(this.points);return new D(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 D(e+i/2,s+n/2),Q,Q)}isStrokeAccountedForInDimensions(){return this.exactBoundingBox}_getNonTransformedDimensions(){return this.exactBoundingBox?new D(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 D((e=t.width)!==null&&e!==void 0?e:o,(s=t.height)!==null&&s!==void 0?s:h)}else{var i,n;r=new D((i=t.width)!==null&&i!==void 0?i:this.width,(n=t.height)!==null&&n!==void 0?n:this.height)}return r.multiply(new D(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===Ce||t===Ge)&&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=at.NUM_FRACTION_DIGITS;for(let n=0,r=this.points.length;n<r;n++)t.push(xt(this.points[n].x-e,i),",",xt(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(k_(t.getAttribute("points")),T(T({},wt(_i(t,this.ATTRIBUTE_NAMES,s),M_)),e))}static fromObject(t){return this._fromObject(t,{extraParam:"points"})}}A(As,"ownDefaults",Wm),A(As,"type","Polyline"),A(As,"layoutProperties",[xo,So,"strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeWidth","strokeUniform","points"]),A(As,"cacheProperties",[...vi,"points"]),A(As,"ATTRIBUTE_NAMES",[...un]),N.setClass(As),N.setSVGClass(As);class Oc extends As{isOpen(){return!1}}A(Oc,"ownDefaults",Wm),A(Oc,"type","Polygon"),N.setClass(Oc),N.setSVGClass(Oc);const Xm=["fontSize","fontWeight","fontFamily","fontStyle"],zm=["underline","overline","linethrough"],Vm=[...Xm,"lineHeight","text","charSpacing","textAlign","styles","path","pathStartOffset","pathSide","pathAlign"],Gm=[...Vm,...zm,"textBackgroundColor","direction"],O_=[...Xm,...zm,Ae,"strokeWidth",Ft,"deltaY","textBackgroundColor"],D_={_reNewline:vu,_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:lt,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:lt,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},Ys="justify",Dc="justify-left",ah="justify-right",hh="justify-center";class Um extends ue{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 l in e[h]){const d=e[h][l]||{};n++,d[t]!==void 0?(i?d[t]!==i&&(r=!1):i=d[t],d[t]===this[t]&&delete d[t]):r=!1,Object.keys(d).length!==0?s++:delete e[h][l]}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=Au(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({},Jn(this,this.constructor._styleProperties)),this._getStyleDeclaration(t,e))}_setStyleDeclaration(t,e,s){this.styles[t][e]=s}_deleteStyleDeclaration(t,e){delete this.styles[t][e]}_getLineStyle(t){return!!this.styles[t]}_setLineStyle(t){this.styles[t]={}}_deleteLineStyle(t){delete this.styles[t]}}A(Um,"_styleProperties",O_);const P_=/ +/g,L_=/"/g;function ig(a,t,e,s,i){return" ".concat(function(n,r){let{left:o,top:h,width:l,height:d}=r,u=arguments.length>2&&arguments[2]!==void 0?arguments[2]:at.NUM_FRACTION_DIGITS;const g=Za(Ft,n,!1),[f,p,m,_]=[o,h,l,d].map(v=>xt(v,u));return"<rect ".concat(g,' x="').concat(f,'" y="').concat(p,'" width="').concat(m,'" height="').concat(_,'"></rect>')}(a,{left:t,top:e,width:s,height:i}),`
53
+ `)}const F_=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let ng;class ge extends Um{static getDefaults(){return T(T({},super.getDefaults()),ge.ownDefaults)}constructor(t,e){super(),A(this,"__charBounds",[]),Object.assign(this,ge.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=Zu(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(Ys)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,s,i,n,r,o;for(let h=0,l=this._textLines.length;h<l;h++)if((this.textAlign===Ys||h!==l-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 d=0;d<=n.length;d++)r=this.__charBounds[h][d],this._reSpaceAndTab.test(n[d])?(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===Ae?(this._renderTextStroke(t),this._renderTextFill(t)):(this._renderTextFill(t),this._renderTextStroke(t))}_setTextStyles(t,e,s){if(t.textBaseline="alphabetic",this.path)switch(this.pathAlign){case Q:t.textBaseline="middle";break;case"ascender":t.textBaseline=Ie;break;case"descender":t.textBaseline=bu}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,l=this._getLineLeftOffset(n);let d,u,g=0,f=0,p=this.getValueOfPropertyAt(n,0,"textBackgroundColor");for(let m=0;m<h;m++){const _=this.__charBounds[n][m];u=this.getValueOfPropertyAt(n,m,"textBackgroundColor"),this.path?(t.save(),t.translate(_.renderLeft,_.renderTop),t.rotate(_.angle),t.fillStyle=u,u&&t.fillRect(-_.width/2,-o/this.lineHeight*(1-this._fontSizeFraction),_.width,o/this.lineHeight),t.restore()):u!==p?(d=s+l+f,this.direction==="rtl"&&(d=this.width-d-g),t.fillStyle=p,p&&t.fillRect(d,i,g,o/this.lineHeight),f=_.left,g=_.width,p=u):g+=_.kernedWidth}u&&!this.path&&(d=s+l+f,this.direction==="rtl"&&(d=this.width-d-g),t.fillStyle=u,t.fillRect(d,i,g,o/this.lineHeight)),i+=o}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,s,i){const n=Ua.getFontCache(e),r=this._getFontDeclaration(e),o=s+t,h=s&&r===this._getFontDeclaration(i),l=e.fontSize/this.CACHE_FONT_SIZE;let d,u,g,f;if(s&&n[s]!==void 0&&(g=n[s]),n[t]!==void 0&&(f=d=n[t]),h&&n[o]!==void 0&&(u=n[o],f=u-g),d===void 0||g===void 0||u===void 0){const p=function(){if(!ng){const m=Rt();m.width=m.height=0,ng=m.getContext("2d")}return ng}();this._setTextStyles(p,e,!0),d===void 0&&(f=d=p.measureText(t).width,n[t]=d),g===void 0&&h&&s&&(g=p.measureText(s).width,n[s]=g),h&&u===void 0&&(u=p.measureText(o).width,n[o]=u,f=u-g)}return{width:d*l,kernedWidth:f*l}}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===Lt,r=this.path,o=this._textLines[t],h=o.length,l=new Array(h);this.__charBounds[t]=l;for(let d=0;d<h;d++){const u=o[d];s=this._getGraphemeBox(u,t,d,e),l[d]=s,i+=s.kernedWidth,e=u}if(l[h]={left:s?s.left+s.width:0,width:0,kernedWidth:0,height:this.fontSize,deltaY:0},r&&r.segmentsInfo){let d=0;const u=r.segmentsInfo[r.segmentsInfo.length-1].length;switch(this.textAlign){case lt:d=n?u-i:0;break;case Q:d=(u-i)/2;break;case Lt:d=n?0:u-i}d+=this.pathStartOffset*(n?-1:1);for(let g=n?h-1:0;n?g>=0:g<h;n?g--:g++)s=l[g],d>u?d%=u:d<0&&(d+=u),this._setGraphemeOnPath(d,s),d+=s.kernedWidth}return{width:i,numOfSpaces:0}}_setGraphemeOnPath(t,e){const s=t+e.kernedWidth/2,i=this.path,n=Mm(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===Lt?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 l,d=h.kernedWidth,u=h.width;this.charSpacing!==0&&(l=this._getWidthOfCharSpacing(),u+=l,d+=l);const g={width:u,left:0,height:r.fontSize,kernedWidth:d,deltaY:r.deltaY};if(s>0&&!n){const f=this.__charBounds[e][s-1];g.left=f.left+f.width+h.kernedWidth-h.width}return g}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),l=h/this.lineHeight,d=this._getLineLeftOffset(r);this._renderTextLine(e,t,this._textLines[r],i+d,n+s+l,r),s+=h}t.restore()}_renderTextFill(t){(this.fill||this.styleHas(Ft))&&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(Ys),l=this.path,d=!h&&this.charSpacing===0&&this.isEmptyStyles(r)&&!l,u=this.direction==="ltr",g=this.direction==="ltr"?1:-1,f=e.direction;let p,m,_,v,x,S="",C=0;if(e.save(),f!==this.direction&&(e.canvas.setAttribute("dir",u?"ltr":"rtl"),e.direction=u?"ltr":"rtl",e.textAlign=u?lt:Lt),n-=o*this._fontSizeFraction/this.lineHeight,d)return this._renderChar(t,e,r,0,s.join(""),i,n),void e.restore();for(let E=0,M=s.length-1;E<=M;E++)v=E===M||this.charSpacing||l,S+=s[E],_=this.__charBounds[r][E],C===0?(i+=g*(_.kernedWidth-_.width),C+=_.width):C+=_.kernedWidth,h&&!v&&this._reSpaceAndTab.test(s[E])&&(v=!0),v||(p=p||this.getCompleteStyleDeclaration(r,E),m=this.getCompleteStyleDeclaration(r,E+1),v=wc(p,m,!1)),v&&(l?(e.save(),e.translate(_.renderLeft,_.renderTop),e.rotate(_.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=m,i+=g*C,C=0);e.restore()}_applyPatternGradientTransformText(t){const e=Rt(),s=this.width+this.strokeWidth,i=this.height+this.strokeWidth,n=e.getContext("2d");return e.width=s,e.height=i,n.beginPath(),n.moveTo(0,0),n.lineTo(s,0),n.lineTo(s,i),n.lineTo(0,i),n.closePath(),n.translate(s/2,i/2),n.fillStyle=t.toLive(n),this._applyPatternGradientTransform(n,t),n.fill(),n.createPattern(e,"no-repeat")}handleFiller(t,e,s){let i,n;return rs(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),l=this.getCompleteStyleDeclaration(s,i),d=t==="fillText"&&l.fill,u=t==="strokeText"&&l.stroke&&l.strokeWidth;if(u||d){if(e.save(),e.font=this._getFontDeclaration(l),h.textBackgroundColor&&this._removeShadow(e),h.deltaY&&(o+=h.deltaY),d){const g=this._setFillStyles(e,l);e.fillText(n,r-g.offsetX,o-g.offsetY)}if(u){const g=this._setStrokeStyles(e,l);e.strokeText(n,r-g.offsetX,o-g.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===Ys||i===hh&&!r||i===ah&&!r||i===Dc&&!r?0:(i===Q&&(o=s/2),i===Lt&&(o=s),i===hh&&(o=s/2),i===ah&&(o=s),n==="rtl"&&(i===Lt||i===Ys||i===ah?o=0:i===lt||i===Dc?o=-s:i!==Q&&i!==hh||(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,l=this._textLines.length;h<l;h++){const d=this.getHeightOfLine(h);if(!this[e]&&!this.styleHas(e,h)){s+=d;continue}const u=this._textLines[h],g=d/this.lineHeight,f=this._getLineLeftOffset(h);let p,m,_=0,v=0,x=this.getValueOfPropertyAt(h,0,e),S=this.getValueOfPropertyAt(h,0,Ft);const C=s+g*(1-this._fontSizeFraction);let E=this.getHeightOfChar(h,0),M=this.getValueOfPropertyAt(h,0,"deltaY");for(let O=0,P=u.length;O<P;O++){const L=this.__charBounds[h][O];p=this.getValueOfPropertyAt(h,O,e),m=this.getValueOfPropertyAt(h,O,Ft);const F=this.getHeightOfChar(h,O),W=this.getValueOfPropertyAt(h,O,"deltaY");if(n&&p&&m)t.save(),t.fillStyle=S,t.translate(L.renderLeft,L.renderTop),t.rotate(L.angle),t.fillRect(-L.kernedWidth/2,o*F+W,L.kernedWidth,this.fontSize/15),t.restore();else if((p!==x||m!==S||F!==E||W!==M)&&v>0){let B=i+f+_;this.direction==="rtl"&&(B=this.width-B-v),x&&S&&(t.fillStyle=S,t.fillRect(B,C+o*E+M,v,this.fontSize/15)),_=L.left,v=L.width,x=p,S=m,E=F,M=W}else v+=L.kernedWidth}let k=i+f+_;this.direction==="rtl"&&(k=this.width-k-v),t.fillStyle=m,p&&m&&t.fillRect(k,C+o*E+M,v-r,this.fontSize/15),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(",")||ge.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 _c(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([...Gm,...t])),{},{styles:am(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=_i(t,ge.ATTRIBUTE_NAMES,s),n=T(T({},e),i),{textAnchor:r=lt,textDecoration:o="",dx:h=0,dy:l=0,top:d=0,left:u=0,fontSize:g=mu,strokeWidth:f=1}=n,p=wt(n,F_),m=new this((t.textContent||"").replace(/^\s+|\s+$|\n+/g,"").replace(/\s+/g," "),T({left:u+h,top:d+l,underline:o.includes("underline"),overline:o.includes("overline"),linethrough:o.includes("line-through"),strokeWidth:0,fontSize:g},p)),_=m.getScaledHeight()/m.height,v=((m.height+m.strokeWidth)*m.lineHeight-m.height)*_,x=m.getScaledHeight()+v;let S=0;return r===Q&&(S=m.getScaledWidth()/2),r===Lt&&(S=m.getScaledWidth()),m.set({left:m.left-S,top:m.top-(x-m.fontSize*(.07+m._fontSizeFraction))/m.lineHeight,strokeWidth:f}),m}static fromObject(t){return this._fromObject(T(T({},t),{},{styles:hm(t.styles||{},t.text)}),{extraParam:"text"})}}A(ge,"textLayoutProperties",Vm),A(ge,"cacheProperties",[...vi,...Gm]),A(ge,"ownDefaults",D_),A(ge,"type","Text"),A(ge,"genericFonts",["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong"]),A(ge,"ATTRIBUTE_NAMES",un.concat("x","y","dx","dy","font-family","font-style","font-weight","font-size","letter-spacing","text-decoration","text-anchor")),em(ge,[class extends Rp{_toSVG(){const a=this._getSVGLeftTopOffsets(),t=this._getSVGTextAndBg(a.textTop,a.textLeft);return this._wrapSVGTextAndBg(t)}toSVG(a){return this._createBaseSVGMarkup(this._toSVG(),{reviver:a,noStyle:!0,withShadow:!0})}_getSVGLeftTopOffsets(){return{textLeft:-this.width/2,textTop:-this.height/2,lineTop:this.getHeightOfLine(0)}}_wrapSVGTextAndBg(a){let{textBgRects:t,textSpans:e}=a;const s=this.getSvgTextDecoration(this);return[t.join(""),' <text xml:space="preserve" ',this.fontFamily?'font-family="'.concat(this.fontFamily.replace(L_,"'"),'" '):"",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(...ig(this.backgroundColor,-this.width/2,-this.height/2,this.width,this.height));for(let r=0,o=this._textLines.length;r<o;r++)i=this._getLineLeftOffset(r),this.direction==="rtl"&&(i+=this.width),(this.textBackgroundColor||this.styleHas("textBackgroundColor",r))&&this._setSVGTextLineBg(s,r,t+i,n),this._setSVGTextLineText(e,r,t+i,n),n+=this.getHeightOfLine(r);return{textSpans:e,textBgRects:s}}_createTextCharSpan(a,t,e,s){const i=this.getSvgSpanStyles(t,a!==a.trim()||!!a.match(P_)),n=i?'style="'.concat(i,'"'):"",r=t.deltaY,o=r?' dy="'.concat(xt(r,at.NUM_FRACTION_DIGITS),'" '):"";return'<tspan x="'.concat(xt(e,at.NUM_FRACTION_DIGITS),'" y="').concat(xt(s,at.NUM_FRACTION_DIGITS),'" ').concat(o).concat(n,">").concat(om(a),"</tspan>")}_setSVGTextLineText(a,t,e,s){const i=this.getHeightOfLine(t),n=this.textAlign.includes(Ys),r=this._textLines[t];let o,h,l,d,u,g="",f=0;s+=i*(1-this._fontSizeFraction)/this.lineHeight;for(let p=0,m=r.length-1;p<=m;p++)u=p===m||this.charSpacing,g+=r[p],l=this.__charBounds[t][p],f===0?(e+=l.kernedWidth-l.width,f+=l.width):f+=l.kernedWidth,n&&!u&&this._reSpaceAndTab.test(r[p])&&(u=!0),u||(o=o||this.getCompleteStyleDeclaration(t,p),h=this.getCompleteStyleDeclaration(t,p+1),u=wc(o,h,!0)),u&&(d=this._getStyleDeclaration(t,p),a.push(this._createTextCharSpan(g,d,e,s)),g="",o=h,this.direction==="rtl"?e-=f:e+=f,f=0)}_setSVGTextLineBg(a,t,e,s){const i=this._textLines[t],n=this.getHeightOfLine(t)/this.lineHeight;let r,o=0,h=0,l=this.getValueOfPropertyAt(t,0,"textBackgroundColor");for(let d=0;d<i.length;d++){const{left:u,width:g,kernedWidth:f}=this.__charBounds[t][d];r=this.getValueOfPropertyAt(t,d,"textBackgroundColor"),r!==l?(l&&a.push(...ig(l,e+h,s,o,n)),h=u,o=g,l=r):o+=f}r&&a.push(...ig(l,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:l}=a,d=this.getSvgTextDecoration(a);return[i?Za(Ae,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,"; "):"",d&&"text-decoration: ".concat(d,"; "),n?Za(Ft,n):"",l?"baseline-shift: ".concat(-l,"; "):"",t?"white-space: pre; ":""].join("")}getSvgTextDecoration(a){return["overline","underline","line-through"].filter(t=>a[t.replace("-","")]).join(" ")}}]),N.setClass(ge),N.setSVGClass(ge);class R_{constructor(t){A(this,"target",void 0),A(this,"__mouseDownInPlace",!1),A(this,"__dragStartFired",!1),A(this,"__isDraggingOver",!1),A(this,"__dragStartSelection",void 0),A(this,"__dragImageDisposer",void 0),A(this,"_dispose",void 0),this.target=t;const e=[this.target.on("dragenter",this.dragEnterHandler.bind(this)),this.target.on("dragover",this.dragOverHandler.bind(this)),this.target.on("dragleave",this.dragLeaveHandler.bind(this)),this.target.on("dragend",this.dragEndHandler.bind(this)),this.target.on("drop",this.dropHandler.bind(this))];this._dispose=()=>{e.forEach(s=>s()),this._dispose=void 0}}isPointerOverSelection(t){const e=this.target,s=e.getSelectionStartFromPointer(t);return e.isEditing&&s>=e.selectionStart&&s<=e.selectionEnd&&e.selectionStart<e.selectionEnd}start(t){return this.__mouseDownInPlace=this.isPointerOverSelection(t)}isActive(){return this.__mouseDownInPlace}end(t){const e=this.isActive();return e&&!this.__dragStartFired&&(this.target.setCursorByClick(t),this.target.initDelayedCursor(!0)),this.__mouseDownInPlace=!1,this.__dragStartFired=!1,this.__isDraggingOver=!1,e}getDragStartSelection(){return this.__dragStartSelection}setDragImage(t,e){var s;let{selectionStart:i,selectionEnd:n}=e;const r=this.target,o=r.canvas,h=new D(r.flipX?-1:1,r.flipY?-1:1),l=r._getCursorBoundaries(i),d=new D(l.left+l.leftOffset,l.top+l.topOffset).multiply(h).transform(r.calcTransformMatrix()),u=o.getScenePoint(t).subtract(d),g=r.getCanvasRetinaScaling(),f=r.getBoundingRect(),p=d.subtract(new D(f.left,f.top)),m=o.viewportTransform,_=p.add(u).transform(m,!0),v=r.backgroundColor,x=Uu(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=v,r.styles=x,r.dirty=!0,Ec(C,{position:"fixed",left:"".concat(-C.width,"px"),border:Se,width:"".concat(C.width/g,"px"),height:"".concat(C.height/g,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{C.remove()},_s(t.target||this.target.hiddenTextarea).body.appendChild(C),(s=t.dataTransfer)===null||s===void 0||s.setDragImage(C,_.x,_.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:l}=s.dataTransfer.types.includes("application/fabric")?JSON.parse(s.dataTransfer.getData("application/fabric")):{},d=n[Math.max(0,n.length-1)],u=0;if(this.__dragStartSelection){const g=this.__dragStartSelection.selectionStart,f=this.__dragStartSelection.selectionEnd;h>g&&h<=f?h=g:h>f&&(h-=f-g),r.removeChars(g,f),delete this.__dragStartSelection}r._reNewline.test(d)&&(r._reNewline.test(r._text[h])||h===r._text.length)&&(n=n.trimEnd()),t.didDrop=!0,t.dropTarget=r,r.insertChars(n,l,h),o.setActiveObject(r),r.enterEditing(s),r.selectionStart=Math.min(h+u,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(ec,{index:h+u,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)||Se;h===Se?(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(ec,{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 Ym=/[ \n\.,;!\?\-]/;class I_ extends ge{constructor(){super(...arguments),A(this,"_currentCursorOpacity",1)}initBehavior(){this._tick=this._tick.bind(this),this._onTickComplete=this._onTickComplete.bind(this),this.updateSelectionOnMouseMove=this.updateSelectionOnMouseMove.bind(this)}onDeselect(t){return this.isEditing&&this.exitEditing(),this.selected=!1,super.onDeselect(t)}_animateCursor(t){let{toValue:e,duration:s,delay:i,onComplete:n}=t;return zu({startValue:this._currentCursorOpacity,endValue:e,duration:s,delay:i,onComplete:n,abort:()=>!this.canvas||this.selectionStart!==this.selectionEnd,onChange:r=>{this._currentCursorOpacity=r,this.renderCursorOrSelection()}})}_tick(t){this._currentTickState=this._animateCursor({toValue:0,duration:this.cursorDuration/2,delay:Math.max(t||0,100),onComplete:this._onTickComplete})}_onTickComplete(){var t;(t=this._currentTickCompleteState)===null||t===void 0||t.abort(),this._currentTickCompleteState=this._animateCursor({toValue:1,duration:this.cursorDuration,onComplete:this._tick})}initDelayedCursor(t){this.abortCursorAnimation(),this._tick(t?0:this.cursorDelay)}abortCursorAnimation(){let t=!1;[this._currentTickState,this._currentTickCompleteState].forEach(e=>{e&&!e.isDone()&&(t=!0,e.abort())}),this._currentCursorOpacity=1,t&&this.clearContextTop()}restartCursorIfNeeded(){[this._currentTickState,this._currentTickCompleteState].some(t=>!t||t.isDone())&&this.initDelayedCursor()}selectAll(){return this.selectionStart=0,this.selectionEnd=this._text.length,this._fireSelectionChanged(),this._updateTextarea(),this}getSelectedText(){return this._text.slice(this.selectionStart,this.selectionEnd).join("")}findWordBoundaryLeft(t){let e=0,s=t-1;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s--;for(;/\S/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findWordBoundaryRight(t){let e=0,s=t;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s++;for(;/\S/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}findLineBoundaryLeft(t){let e=0,s=t-1;for(;!/\n/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findLineBoundaryRight(t){let e=0,s=t;for(;!/\n/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}searchWordBoundary(t,e){const s=this._text;let i=t>0&&this._reSpace.test(s[t])&&(e===-1||!vu.test(s[t-1]))?t-1:t,n=s[i];for(;i>0&&i<s.length&&!Ym.test(n);)i+=e,n=s[i];return e===-1&&Ym.test(n)&&i++,i}selectWord(t){t=t||this.selectionStart;const e=this.searchWordBoundary(t,-1),s=Math.max(e,this.searchWordBoundary(t,1));this.selectionStart=e,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(t){t=t||this.selectionStart;const e=this.findLineBoundaryLeft(t),s=this.findLineBoundaryRight(t);return this.selectionStart=e,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea(),this}enterEditing(t){!this.isEditing&&this.editable&&(this.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(),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()))}updateSelectionOnMouseMove(t){if(this.getActiveControl())return;const e=this.hiddenTextarea;_s(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(),l=this.canvas.upperCanvasEl,d=l.width/h,u=l.height/h,g=d-r,f=u-r,p=new D(e.left+o,e.top+e.topOffset+r).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new D(l.clientWidth/d,l.clientHeight/u));return p.x<0&&(p.x=0),p.x>g&&(p.x=g),p.y<0&&(p.y=0),p.y>f&&(p.y=f),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()}exitEditing(){const t=this._textBeforeEdit!==this.text;return this._exitEditing(),this.selectionEnd=this.selectionStart,this._restoreEditingProps(),this._forceClearCache&&(this.initDimensions(),this.setCoords()),this.fire("editing:exited"),t&&this.fire(ic),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 l=i;l<r;l++)delete o[l];for(const l in this.styles[s]){const d=parseInt(l,10);d>=r&&(o[d-h]=o[l],delete o[l])}}}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 l=this.styles[t]?this.styles[t][e===0?e:e-1]:void 0;for(const u in this.styles[t]){const g=parseInt(u,10);g>=e&&(h=!0,n[g-e]=this.styles[t][u],o&&e===0||delete this.styles[t][u])}let d=!1;for(h&&!o&&(this.styles[t+s]=n,d=!0),(d||r>e)&&s--;s>0;)i&&i[s-1]?this.styles[t+s]={0:T({},i[s-1])}:l?this.styles[t+s]={0:T({},l)}: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 l=parseInt(h,10);l>=e&&(n[l+s]=r[l],r[l-s]||delete n[l])}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=lt:this._selectionDirection===Lt&&(this._selectionDirection=lt,this.selectionEnd=t),this.selectionStart=s):s>t&&s<e?this._selectionDirection===Lt?this.selectionEnd=s:this.selectionStart=s:(e===t?this._selectionDirection=Lt:this._selectionDirection===lt&&(this._selectionDirection=Lt,this.selectionStart=e),this.selectionEnd=s)}}class j_ extends I_{initHiddenTextarea(){const t=this.canvas&&_s(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;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;const s=()=>{this.updateFromTextArea(),this.fire(ec),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(this.hiddenTextarea.value==="")return this.styles={},void s();const i=this._splitTextIntoLines(this.hiddenTextarea.value).graphemeText,n=this._text.length,r=i.length,o=this.selectionStart,h=this.selectionEnd,l=o!==h;let d,u,g,f,p=r-n;const m=this.fromStringToGraphemeSelection(this.hiddenTextarea.selectionStart,this.hiddenTextarea.selectionEnd,this.hiddenTextarea.value),_=o>m.selectionStart;l?(u=this._text.slice(o,h),p+=h-o):r<n&&(u=_?this._text.slice(h+p,h):this._text.slice(o,o-p));const v=i.slice(m.selectionEnd-p,m.selectionEnd);if(u&&u.length&&(v.length&&(d=this.getSelectionStyles(o,o+1,!1),d=v.map(()=>d[0])),l?(g=o,f=h):_?(g=h-u.length,f=h):(g=h,f=h+u.length),this.removeStyleFromTo(g,f)),v.length){const{copyPasteData:x}=zs();e&&v.join("")===x.copiedText&&!at.disableStyleCopyPaste&&(d=x.copiedTextStyle),this.insertNewStyleBlock(v,o,d)}s()}onCompositionStart(){this.inCompositionMode=!0}onCompositionEnd(){this.inCompositionMode=!1}onCompositionUpdate(t){let{target:e}=t;const{selectionStart:s,selectionEnd:i}=e;this.compositionStart=s,this.compositionEnd=i,this.updateTextareaPosition()}copy(){if(this.selectionStart===this.selectionEnd)return;const{copyPasteData:t}=zs();t.copiedText=this.getSelectedText(),at.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),l=this._textLines[n].slice(0,r),d=this.missingNewlineOffset(n-1);return-this._textLines[n-1].length+h-l.length+(1-d)}_getIndexOnLine(t,e){const s=this._textLines[t];let i,n,r=this._getLineLeftOffset(t),o=0;for(let h=0,l=s.length;h<l;h++)if(i=this.__charBounds[t][h].width,r+=i,r>e){n=!0;const d=r-i,u=r,g=Math.abs(d-e);o=Math.abs(u-e)<g?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===Lt);if(e.shiftKey?this.moveCursorWithShift(s):this.moveCursorWithoutShift(s),s!==0){const i=this.text.length;this.selectionStart=er(0,this.selectionStart,i),this.selectionEnd=er(0,this.selectionEnd,i),this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea()}}moveCursorWithShift(t){const e=this._selectionDirection===lt?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=lt,this.selectionEnd===this.selectionStart&&this.selectionStart!==0&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return this._selectionDirection===Lt&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):this.selectionStart!==0?(this._selectionDirection=lt,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===lt&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection=Lt,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=Lt,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}const rg=a=>!!a.button;class N_ extends j_{constructor(){super(...arguments),A(this,"draggableTextDelegate",void 0)}initBehavior(){this.on("mousedown",this._mouseDownHandler),this.on("mousedown:before",this._mouseDownHandlerBefore),this.on("mouseup",this.mouseUpHandler),this.on("mousedblclick",this.doubleClickHandler),this.on("tripleclick",this.tripleClickHandler),this.__lastClickTime=+new Date,this.__lastLastClickTime=+new Date,this.__lastPointer={},this.on("mousedown",this.onMouseDown),this.draggableTextDelegate=new R_(this),super.initBehavior()}shouldStartDragging(){return this.draggableTextDelegate.isActive()}onDragStart(t){return this.draggableTextDelegate.onDragStart(t)}canDrop(t){return this.draggableTextDelegate.canDrop(t)}onMouseDown(t){if(!this.canvas)return;this.__newClickTime=+new Date;const e=t.pointer;this.isTripleClick(e)&&(this.fire("tripleclick",t),Mu(t.e)),this.__lastLastClickTime=this.__lastClickTime,this.__lastClickTime=this.__newClickTime,this.__lastPointer=e,this.__lastSelected=this.selected&&!this.getActiveControl()}isTripleClick(t){return this.__newClickTime-this.__lastClickTime<500&&this.__lastClickTime-this.__lastLastClickTime<500&&this.__lastPointer.x===t.x&&this.__lastPointer.y===t.y}doubleClickHandler(t){this.isEditing&&this.selectWord(this.getSelectionStartFromPointer(t.e))}tripleClickHandler(t){this.isEditing&&this.selectLine(this.getSelectionStartFromPointer(t.e))}_mouseDownHandler(t){let{e}=t;this.canvas&&this.editable&&!rg(e)&&!this.getActiveControl()&&(this.draggableTextDelegate.start(e)||(this.canvas.textEditingManager.register(this),this.selected&&(this.inCompositionMode=!1,this.setCursorByClick(e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection())))}_mouseDownHandlerBefore(t){let{e}=t;this.canvas&&this.editable&&!rg(e)&&(this.selected=this===this.canvas._activeObject)}mouseUpHandler(t){let{e,transform:s}=t;const i=this.draggableTextDelegate.end(e);if(this.canvas){this.canvas.textEditingManager.unregister(this);const n=this.canvas._activeObject;if(n&&n!==this)return}!this.editable||this.group&&!this.group.interactive||s&&s.actionPerformed||rg(e)||i||(this.__lastSelected&&!this.getActiveControl()?(this.selected=!1,this.__lastSelected=!1,this.enterEditing(e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection()):this.selected=!0)}setCursorByClick(t){const e=this.getSelectionStartFromPointer(t),s=this.selectionStart,i=this.selectionEnd;t.shiftKey?this.setSelectionStartEndWithShift(s,i,e):(this.selectionStart=e,this.selectionEnd=e),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())}getSelectionStartFromPointer(t){const e=this.canvas.getScenePoint(t).transform(je(this.calcTransformMatrix())).add(new D(-this._getLeftOffset(),-this._getTopOffset()));let s=0,i=0,n=0;for(let l=0;l<this._textLines.length&&s<=e.y;l++)s+=this.getHeightOfLine(l),n=l,l>0&&(i+=this._textLines[l-1].length+this.missingNewlineOffset(l-1));let r=Math.abs(this._getLineLeftOffset(n));const o=this._textLines[n].length,h=this.__charBounds[n];for(let l=0;l<o;l++){const d=r+h[l].kernedWidth;if(e.x<=d){Math.abs(e.x-d)<=Math.abs(e.x-r)&&i++;break}r=d,i++}return Math.min(this.flipX?o-i:i,this._text.length)}}const Pc="moveCursorUp",Lc="moveCursorDown",Fc="moveCursorLeft",Rc="moveCursorRight",Ic="exitEditing",B_=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:Ic,27:Ic,33:Pc,34:Lc,35:Rc,36:Fc,37:Fc,38:Pc,39:Rc,40:Lc},keysMapRtl:{9:Ic,27:Ic,33:Pc,34:Lc,35:Fc,36:Rc,37:Rc,38:Pc,39:Fc,40:Lc},ctrlKeysMapDown:{65:"selectAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}},{_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1});class Ci extends N_{static getDefaults(){return T(T({},super.getDefaults()),Ci.ownDefaults)}get type(){const t=super.type;return t==="itext"?"i-text":t}constructor(t,e){super(t,T(T({},Ci.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 tg&&this.canvas.textEditingManager.remove(this),e instanceof tg&&e.textEditingManager.add(this)),super._set(t,e))}setSelectionStart(t){t=Math.max(t,0),this._updateAndFire("selectionStart",t)}setSelectionEnd(t){t=Math.min(t,this.text.length),this._updateAndFire("selectionEnd",t)}_updateAndFire(t,e){this[t]!==e&&(this._fireSelectionChanged(),this[t]=e),this._updateTextarea()}_fireSelectionChanged(){this.fire("selection:changed"),this.canvas&&this.canvas.fire("text:selection:changed",{target:this})}initDimensions(){this.isEditing&&this.initDelayedCursor(),super.initDimensions()}getSelectionStyles(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart||0,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionEnd,s=arguments.length>2?arguments[2]:void 0;return super.getSelectionStyles(t,e,s)}setSelectionStyles(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionStart||0,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.selectionEnd;return super.setSelectionStyles(t,e,s)}get2DCursorLocation(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;return super.get2DCursorLocation(t,e)}render(t){super.render(t),this.cursorOffsetCache={},this.renderCursorOrSelection()}toCanvasElement(t){const e=this.isEditing;this.isEditing=!1;const s=super.toCanvasElement(t);return this.isEditing=e,s}renderCursorOrSelection(){if(!this.isEditing)return;const t=this.clearContextTop(!0);if(!t)return;const e=this._getCursorBoundaries();this.selectionStart===this.selectionEnd?this.renderCursor(t,e):this.renderSelection(t,e),this.canvas.contextTopDirty=!0,t.restore()}_getCursorBoundaries(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;const s=this._getLeftOffset(),i=this._getTopOffset(),n=this._getCursorBoundariesOffsets(t,e);return{left:s,top:i,leftOffset:n.left,topOffset:n.top}}_getCursorBoundariesOffsets(t,e){return e?this.__getCursorBoundariesOffsets(t):this.cursorOffsetCache&&"top"in this.cursorOffsetCache?this.cursorOffsetCache:this.cursorOffsetCache=this.__getCursorBoundariesOffsets(t)}__getCursorBoundariesOffsets(t){let e=0,s=0;const{charIndex:i,lineIndex:n}=this.get2DCursorLocation(t);for(let l=0;l<n;l++)e+=this.getHeightOfLine(l);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===Lt||this.textAlign===Ys||this.textAlign===ah?h.left*=-1:this.textAlign===lt||this.textAlign===Dc?h.left=r-(s>0?s:0):this.textAlign!==Q&&this.textAlign!==hh||(h.left=r-(s>0?s:0))),h}renderCursorAt(t){const e=this._getCursorBoundaries(t,!0);this._renderCursor(this.canvas.contextTop,e,t)}renderCursor(t,e){this._renderCursor(t,e,this.selectionStart)}_renderCursor(t,e,s){const i=this.get2DCursorLocation(s),n=i.lineIndex,r=i.charIndex>0?i.charIndex-1:0,o=this.getValueOfPropertyAt(n,r,"fontSize"),h=this.getObjectScaling().x*this.canvas.getZoom(),l=this.cursorWidth/h,d=this.getValueOfPropertyAt(n,r,"deltaY"),u=e.topOffset+(1-this._fontSizeFraction)*this.getHeightOfLine(n)/this.lineHeight-o*(1-this._fontSizeFraction);this.inCompositionMode&&this.renderSelection(t,e),t.fillStyle=this.cursorColor||this.getValueOfPropertyAt(n,r,Ft),t.globalAlpha=this._currentCursorOpacity,t.fillRect(e.left+e.leftOffset-l/2,u+e.top+d,l,o)}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(Ys),o=this.get2DCursorLocation(i),h=this.get2DCursorLocation(n),l=o.lineIndex,d=h.lineIndex,u=o.charIndex<0?0:o.charIndex,g=h.charIndex<0?0:h.charIndex;for(let f=l;f<=d;f++){const p=this._getLineLeftOffset(f)||0;let m=this.getHeightOfLine(f),_=0,v=0,x=0;if(f===l&&(v=this.__charBounds[l][u].left),f>=l&&f<d)x=r&&!this.isEndOfWrapping(f)?this.width:this.getLineWidth(f)||5;else if(f===d)if(g===0)x=this.__charBounds[d][g].left;else{const k=this._getWidthOfCharSpacing();x=this.__charBounds[d][g-1].left+this.__charBounds[d][g-1].width-k}_=m,(this.lineHeight<1||f===d&&this.lineHeight>1)&&(m/=this.lineHeight);let S=s.left+p+v,C=m,E=0;const M=x-v;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",C=1,E=m):t.fillStyle=this.selectionColor,this.direction==="rtl"&&(this.textAlign===Lt||this.textAlign===Ys||this.textAlign===ah?S=this.width-S-M:this.textAlign===lt||this.textAlign===Dc?S=s.left+p-x:this.textAlign!==Q&&this.textAlign!==hh||(S=s.left+p-x)),t.fillRect(S,s.top+s.topOffset+E,M,C),s.topOffset+=_}}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,Ft)}_getCurrentCharIndex(){const t=this.get2DCursorLocation(this.selectionStart,!0),e=t.charIndex>0?t.charIndex-1:0;return{l:t.lineIndex,c:e}}dispose(){this._exitEditing(),this.draggableTextDelegate.dispose(),super.dispose()}}A(Ci,"ownDefaults",B_),A(Ci,"type","IText"),N.setClass(Ci),N.setClass(Ci,"i-text");class rr extends Ci{static getDefaults(){return T(T({},super.getDefaults()),rr.ownDefaults)}constructor(t,e){super(t,T(T({},rr.ownDefaults),e))}static createControls(){return{controls:Sy()}}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(Ys)&&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 l in h)for(const d in h[l]){const u=parseInt(d,10);if(u>=s&&(!n||u<e))for(const g in h[l][d])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(l=>{const d=e?[l]:this.graphemeSplit(l),u=this._measureWord(d,r,o);return i=Math.max(u,i),o+=d.length+s.length,{word:d,width:u}})}),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,l=[],d=h?"":" ";let u=0,g=[],f=0,p=0,m=!0;e-=r;const _=Math.max(e,i,this.dynamicMinWidth),v=n[t];let x;for(f=0,x=0;x<v.length;x++){const{word:S,width:C}=v[x];f+=S.length,u+=p+C-o,u>_&&!m?(l.push(g),g=[],u=C,m=!0):u+=o,m||h||g.push(d),g=g.concat(S),p=h?0:this._measureWord([d],t,f),f++,m=!1}return x&&l.push(g),i+r>this.dynamicMinWidth&&(this.dynamicMinWidth=i-o+r),l}isEndOfWrapping(t){return!this._styleMap[t+1]||this._styleMap[t+1].line!==this._styleMap[t].line}missingNewlineOffset(t,e){return this.splitByGrapheme&&!e?this.isEndOfWrapping(t)?1:0:1}_splitTextIntoLines(t){const e=super._splitTextIntoLines(t),s=this._wrapText(e.lines,this.width),i=new Array(s.length);for(let n=0;n<s.length;n++)i[n]=s[n].join("");return e.lines=i,e.graphemeLines=s,e}getMinWidth(){return Math.max(this.minWidth,this.dynamicMinWidth)}_removeExtraneousStyles(){const t=new Map;for(const e in this._styleMap){const s=parseInt(e,10);if(this._textLines[s]){const i=this._styleMap[e].line;t.set("".concat(i),!0)}}for(const e in this.styles)t.has(e)||delete this.styles[e]}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject(["minWidth","splitByGrapheme",...t])}}A(rr,"type","Textbox"),A(rr,"textLayoutProperties",[...Ci.textLayoutProperties,"width"]),A(rr,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),N.setClass(rr);class qm extends Ac{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}=Vs(vm(s,i)),h=new D(r,o);if(i.absolutePositioned)return{center:tr(i.getRelativeCenterPoint(),void 0,n?n.calcTransformMatrix():void 0),size:h};{const l=i.getRelativeCenterPoint().transform(s.calcOwnMatrix(),!0);if(this.shouldPerformLayout(t)){const{center:d=new D,correction:u=new D}=this.calcBoundingBox(e,t)||{};return{center:d.add(l),correction:u.subtract(l),size:h}}return{center:s.getRelativeCenterPoint().add(l),size:h}}}}A(qm,"type","clip-path"),N.setClass(qm);class $m extends Ac{getInitialSize(t,e){let{target:s}=t,{size:i}=e;return new D(s.width||i.x,s.height||i.y)}}A($m,"type","fixed"),N.setClass($m);class H_ extends nh{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 or extends Us{static getDefaults(){return T(T({},super.getDefaults()),or.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,or.ownDefaults),this.setOptions(e);const{left:s,top:i,layoutManager:n}=e;this.groupInit(t,{left:s,top:i,layoutManager:n??new H_})}_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))?(pi("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===$u?s.forEach(i=>{i._onAfterObjectsChange(Sc,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()}}A(or,"type","ActiveSelection"),A(or,"ownDefaults",{multiSelectionStacking:"canvas-stacking"}),N.setClass(or),N.setClass(or,"activeSelection");class W_{constructor(){A(this,"resources",{})}applyFilters(t,e,s,i,n){const r=n.getContext("2d");if(!r)return;r.drawImage(e,0,0,s,i);const o={sourceWidth:s,sourceHeight:i,imageData:r.getImageData(0,0,s,i),originalEl:e,originalImageData:r.getImageData(0,0,s,i),canvasEl:n,ctx:r,filterBackend:this};t.forEach(l=>{l.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 Km{constructor(){let{tileSize:t=at.textureSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};A(this,"aPosition",new Float32Array([0,0,0,1,1,0,1,1])),A(this,"resources",{}),this.tileSize=t,this.setupGLContext(t,t),this.captureGPUInfo()}setupGLContext(t,e){this.dispose(),this.createWebGLCanvas(t,e)}createWebGLCanvas(t,e){const s=Rt();s.width=t,s.height=e;const 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 l;r&&(l=this.getCachedTexture(r,e));const d={originalWidth:e.width||e.originalWidth||0,originalHeight:e.height||e.originalHeight||0,sourceWidth:s,sourceHeight:i,destinationWidth:s,destinationHeight:i,context:o,sourceTexture:this.createTexture(o,s,i,l?void 0:e),targetTexture:this.createTexture(o,s,i),originalTexture:l||this.createTexture(o,s,i,l?void 0:e),passes:t.length,webgl:!0,aPosition:this.aPosition,programCache:this.programCache,pass:0,filterBackend:this,targetCanvas:n},u=o.createFramebuffer();return o.bindFramebuffer(o.FRAMEBUFFER,u),t.forEach(g=>{g&&g.applyTo(d)}),function(g){const f=g.targetCanvas,p=f.width,m=f.height,_=g.destinationWidth,v=g.destinationHeight;p===_&&m===v||(f.width=_,f.height=v)}(d),this.copyGLTo2D(o,d),o.bindTexture(o.TEXTURE_2D,null),o.deleteTexture(d.sourceTexture),o.deleteTexture(d.targetTexture),o.deleteFramebuffer(u),h.setTransform(1,0,0,1,0,0),d}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:l,CLAMP_TO_EDGE:d,TEXTURE_MAG_FILTER:u,TEXTURE_MIN_FILTER:g,TEXTURE_WRAP_S:f,TEXTURE_WRAP_T:p}=t,m=t.createTexture();return t.bindTexture(o,m),t.texParameteri(o,u,n||r),t.texParameteri(o,g,n||r),t.texParameteri(o,f,d),t.texParameteri(o,p,d),i?t.texImage2D(o,0,h,h,l,i):t.texImage2D(o,0,h,e,s,0,h,l,null),m}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 l=new ImageData(h,i,n);s.putImageData(l,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 og;function X_(){const{WebGLProbe:a}=zs();return a.queryWebGL(Rt()),at.enableGLFiltering&&a.isSupported(at.textureSize)?new Km({tileSize:at.textureSize}):new W_}function ag(){return!og&&(!(arguments.length>0&&arguments[0]!==void 0)||arguments[0])&&(og=X_()),og}const z_=["filters","resizeFilter","src","crossOrigin","type"],Qm=["cropX","cropY"];class fe extends ue{static getDefaults(){return T(T({},super.getDefaults()),fe.ownDefaults)}constructor(t,e){super(),A(this,"_lastScaleX",1),A(this,"_lastScaleY",1),A(this,"_filterScalingX",1),A(this,"_filterScalingY",1),this.filters=[],Object.assign(this,fe.ownDefaults),this.setOptions(e),this.cacheKey="texture".concat(cn()),this.setElement(typeof t=="string"?(this.canvas&&_s(this.canvas.getElement())||wo()).getElementById(t):t,e)}getElement(){return this._element}setElement(t){let e=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(e),t.classList.add(fe.CSS_CANVAS),this.filters.length!==0&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){const e=ag(!1);e instanceof Km&&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&&zs().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([...Qm,...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 l=cn();n.push('<clipPath id="imageCrop_'+l+`">
58
58
  `,' <rect x="'+s+'" y="'+i+'" width="'+this.width+'" height="'+this.height+`" />
59
59
  `,`</clipPath>
60
60
  `),o=' clip-path="url(#imageCrop_'+l+')" '}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 l=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=l}return n=this.paintFirst!==It?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 Ka(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=jt(),h=r.width,l=r.height;o.width=h,o.height=l,this._element=o,this._lastScaleX=t.scaleX=i,this._lastScaleY=t.scaleY=n,og().applyFilters([t],r,h,l,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=jt();n.width=s,n.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);og().applyFilters(t,this._originalElement,s,i,this._element),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),l=e.naturalWidth||e.width,d=e.naturalHeight||e.height,u=o*s,g=h*i,f=Math.min(n*s,l-u),p=Math.min(r*i,d-g),m=-n/2,w=-r/2,v=Math.min(n,l/s-o),x=Math.min(r,d/i-h);e&&t.drawImage(e,u,g,f,p,m,w,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=Tu(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,l=1,d=0,u=0,g=0,f=0;return!t||t.alignX===Se&&t.alignY===Se?(h=e/r,l=s/o):(t.meetOrSlice==="meet"&&(h=l=ym(this._element,i),n=(e-r*h)/2,t.alignX==="Min"&&(d=-n),t.alignX==="Max"&&(d=n),n=(s-o*l)/2,t.alignY==="Min"&&(u=-n),t.alignY==="Max"&&(u=n)),t.meetOrSlice==="slice"&&(h=l=_m(this._element,i),n=r-e/h,t.alignX==="Mid"&&(g=n/2),t.alignX==="Max"&&(g=n),n=o-s/l,t.alignY==="Mid"&&(f=n/2),t.alignY==="Max"&&(f=n),r=e/h,o=s/l)),{width:r,height:o,scaleX:h,scaleY:l,offsetLeft:d,offsetTop:u,cropX:g,cropY:f}}static fromObject(t,e){let{filters:s,resizeFilter:i,src:n,crossOrigin:r,type:o}=t,h=St(t,H_);return Promise.all([Ka(n,T(T({},e),{},{crossOrigin:r})),s&&Eo(s,e),i&&Eo([i],e),Qa(h,e)]).then(l=>{let[d,u=[],[g]=[],f={}]=l;return new this(d,T(T({},h),{},{src:n,filters:u,resizeFilter:g},f))})}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 Ka(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=_i(t,this.ATTRIBUTE_NAMES,s);return this.fromURL(i["xlink:href"],e,i).catch(n=>(pi("log","Unable to parse Image",n),null))}}function ag(a){if(!Gv.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"),l=a.getAttribute("height"),d=a.getAttribute("x")||0,u=a.getAttribute("y")||0,g=!(t&&jp.test(t)),f=!h||!l||h==="100%"||l==="100%";let p="",m=0,w=0;if(g&&(d||u)&&a.parentNode&&a.parentNode.nodeName!=="#document"&&(p=" translate("+Te(d||"0")+" "+Te(u||"0")+") ",e=(a.getAttribute("transform")||"")+p,a.setAttribute("transform",e),a.removeAttribute("x"),a.removeAttribute("y")),g&&f)return{width:0,height:0};const v={width:0,height:0};if(g)return v.width=Te(h),v.height=Te(l),v;const x=t.match(jp);r=-parseFloat(x[1]),o=-parseFloat(x[2]);const S=parseFloat(x[3]),C=parseFloat(x[4]);v.minX=r,v.minY=o,v.viewBoxWidth=S,v.viewBoxHeight=C,f?(v.width=S,v.height=C):(v.width=Te(h),v.height=Te(l),i=v.width/S,n=v.height/C);const E=Tu(a.getAttribute("preserveAspectRatio")||"");if(E.alignX!==Se&&(E.meetOrSlice==="meet"&&(n=i=i>n?n:i),E.meetOrSlice==="slice"&&(n=i=i>n?i:n),m=v.width-S*i,w=v.height-C*i,E.alignX==="Mid"&&(m/=2),E.alignY==="Mid"&&(w/=2),E.alignX==="Min"&&(m=0),E.alignY==="Min"&&(w=0)),i===1&&n===1&&r===0&&o===0&&d===0&&u===0)return v;if((d||u)&&a.parentNode.nodeName!=="#document"&&(p=" translate("+Te(d||"0")+" "+Te(u||"0")+") "),e=p+" matrix("+i+" 0 0 "+n+" "+(r*i+m)+" "+(o*n+w)+") ",a.nodeName==="svg"){for(s=a.ownerDocument.createElementNS(Pu,"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}A(fe,"type","Image"),A(fe,"cacheProperties",[...vi,...Km]),A(fe,"ownDefaults",{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),A(fe,"CSS_CANVAS","canvas-img"),A(fe,"ATTRIBUTE_NAMES",[...un,"x","y","width","height","preserveAspectRatio","xlink:href","crossOrigin","image-rendering"]),X.setClass(fe),X.setSVGClass(fe);const Ic=a=>a.tagName.replace("svg:",""),W_=dc(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);function Qm(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 X_=["gradientTransform","x1","x2","y1","y2","gradientUnits","cx","cy","r","fx","fy"],hg="xlink:href";function Jm(a,t){var e;const s=((e=t.getAttribute(hg))===null||e===void 0?void 0:e.slice(1))||"",i=a.getElementById(s);if(i&&i.getAttribute(hg)&&Jm(a,i),i&&(X_.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(hg)}const z_=["linearGradient","radialGradient","svg:linearGradient","svg:radialGradient"];function V_(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={},l=o[1].trim().split(";").filter(function(d){return d.trim()});for(e=0,s=l.length;e<s;e++){const d=l[e].split(":"),u=d[0].trim(),g=d[1].trim();h[u]=g}(r=o[0].trim()).split(",").forEach(d=>{(d=d.replace(/^svg/i,"").trim())!==""&&(i[d]=T(T({},i[d]||{}),h))})})}return i}const Zm=a=>X.getSVGClass(Ic(a).toLowerCase());class G_{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=Qm(r,z_),h={};let l=o.length;for(;l--;){const d=o[l];d.getAttribute("xlink:href")&&Jm(r,d);const u=d.getAttribute("id");u&&(h[u]=d)}return h}(i),this.cssRules=V_(i)}parse(){return Promise.all(this.elements.map(t=>this.createObject(t)))}async createObject(t){const e=Zm(t);if(e){const s=await e.fromElement(t,this.options,this.cssRules);return this.resolveGradient(s,t,It),this.resolveGradient(s,t,Ae),s instanceof fe&&s._originalElement?Ec(s,s.parsePreserveAspectRatioAttribute()):Ec(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=oh.fromElement(i,t,T(T({},this.options),{},{opacity:n}));t.set(s,r)}}async resolveClipPath(t,e){const s=this.extractPropertyDefinition(t,"clipPath",this.clipPaths);if(s){const i=je(t.calcTransformMatrix()),n=s[0].parentElement;let r=e;for(;r.parentElement&&r.getAttribute("clip-path")!==t.clipPath;)r=r.parentElement;r.parentElement.appendChild(n);const o=wc("".concat(r.getAttribute("transform")||""," ").concat(n.getAttribute("originalTransform")||""));n.setAttribute("transform","matrix(".concat(o.join(","),")"));const h=await Promise.all(s.map(v=>Zm(v).fromElement(v,this.options,this.cssRules).then(x=>(Ec(x),x.fillRule=x.clipRule,delete x.clipRule,x)))),l=h.length===1?h[0]:new Us(h),d=Nt(i,l.calcTransformMatrix());l.clipPath&&await this.resolveClipPath(l,r);const{scaleX:u,scaleY:g,angle:f,skewX:p,translateX:m,translateY:w}=Qn(d);l.set({flipX:!1,flipY:!1}),l.set({scaleX:u,scaleY:g,angle:f,skewX:p,skewY:0}),l.setPositionByOrigin(new M(m,w),J,J),t.clipPath=l}else delete t.clipPath}}const t0=a=>Vv.test(Ic(a)),lg=()=>({objects:[],elements:[],options:{},allElements:[]});async function U_(a,t){let{crossOrigin:e,signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(s&&s.aborted)return pi("log",new uu("parseSVGDocument")),lg();const i=a.documentElement;(function(d){const u=Qm(d,["use","svg:use"]),g=["x","y","xlink:href","href","transform"];for(const f of u){const p=f.attributes,m={};for(const R of p)R.value&&(m[R.name]=R.value);const w=(m["xlink:href"]||m.href||"").slice(1);if(w==="")return;const v=d.getElementById(w);if(v===null)return;let x=v.cloneNode(!0);const S=x.attributes,C={};for(const R of S)R.value&&(C[R.name]=R.value);const{x:E=0,y:k=0,transform:P=""}=m,D="".concat(P," ").concat(C.transform||""," translate(").concat(E,", ").concat(k,")");if(ag(x),/^svg$/i.test(x.nodeName)){const R=x.ownerDocument.createElementNS(Pu,"g");Object.entries(C).forEach(B=>{let[O,F]=B;return R.setAttributeNS(Pu,O,F)}),R.append(...x.childNodes),x=R}for(const R of p){if(!R)continue;const{name:B,value:O}=R;if(!g.includes(B))if(B==="style"){const F={};Yu(O,F),Object.entries(C).forEach(I=>{let[G,Y]=I;F[G]=Y}),Yu(C.style||"",F);const L=Object.entries(F).map(I=>I.join(":")).join(";");x.setAttribute(B,L)}else!C[B]&&x.setAttribute(B,O)}x.setAttribute("transform",D),x.setAttribute("instantiated_by_use","1"),x.removeAttribute("id"),f.parentNode.replaceChild(x,f)}})(a);const n=Array.from(i.getElementsByTagName("*")),r=T(T({},ag(i)),{},{crossOrigin:e,signal:s}),o=n.filter(d=>(ag(d),t0(d)&&!function(u){let g=u;for(;g&&(g=g.parentElement);)if(g&&g.nodeName&&W_.test(Ic(g))&&!g.getAttribute("instantiated_by_use"))return!0;return!1}(d)));if(!o||o&&!o.length)return T(T({},lg()),{},{options:r,allElements:n});const h={};return n.filter(d=>Ic(d)==="clipPath").forEach(d=>{d.setAttribute("originalTransform",d.getAttribute("transform")||"");const u=d.getAttribute("id");h[u]=Array.from(d.getElementsByTagName("*")).filter(g=>t0(g))}),{objects:await new G_(o,r,t,a,h).parse(),elements:o,options:r,allElements:n}}function Y_(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return new Promise((s,i)=>{Pm(a.replace(/^\n\s*/,"").trim(),{onComplete:n=>{const r=n.responseXML;r&&s(r),i()},signal:e.signal})}).then(s=>U_(s,t,e)).catch(()=>lg())}const jc=a=>a.webgl!==void 0,cg="precision highp float",q_=`
63
- `.concat(cg,`;
62
+ `)],this.fill=l}return n=this.paintFirst!==Ft?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 Ka(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=Rt(),h=r.width,l=r.height;o.width=h,o.height=l,this._element=o,this._lastScaleX=t.scaleX=i,this._lastScaleY=t.scaleY=n,ag().applyFilters([t],r,h,l,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=Rt();n.width=s,n.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);ag().applyFilters(t,this._originalElement,s,i,this._element),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),l=e.naturalWidth||e.width,d=e.naturalHeight||e.height,u=o*s,g=h*i,f=Math.min(n*s,l-u),p=Math.min(r*i,d-g),m=-n/2,_=-r/2,v=Math.min(n,l/s-o),x=Math.min(r,d/i-h);e&&t.drawImage(e,u,g,f,p,m,_,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=Eu(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,l=1,d=0,u=0,g=0,f=0;return!t||t.alignX===Se&&t.alignY===Se?(h=e/r,l=s/o):(t.meetOrSlice==="meet"&&(h=l=_m(this._element,i),n=(e-r*h)/2,t.alignX==="Min"&&(d=-n),t.alignX==="Max"&&(d=n),n=(s-o*l)/2,t.alignY==="Min"&&(u=-n),t.alignY==="Max"&&(u=n)),t.meetOrSlice==="slice"&&(h=l=wm(this._element,i),n=r-e/h,t.alignX==="Mid"&&(g=n/2),t.alignX==="Max"&&(g=n),n=o-s/l,t.alignY==="Mid"&&(f=n/2),t.alignY==="Max"&&(f=n),r=e/h,o=s/l)),{width:r,height:o,scaleX:h,scaleY:l,offsetLeft:d,offsetTop:u,cropX:g,cropY:f}}static fromObject(t,e){let{filters:s,resizeFilter:i,src:n,crossOrigin:r,type:o}=t,h=wt(t,z_);return Promise.all([Ka(n,T(T({},e),{},{crossOrigin:r})),s&&Eo(s,e),i&&Eo([i],e),Qa(h,e)]).then(l=>{let[d,u=[],[g]=[],f={}]=l;return new this(d,T(T({},h),{},{src:n,filters:u,resizeFilter:g},f))})}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 Ka(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=_i(t,this.ATTRIBUTE_NAMES,s);return this.fromURL(i["xlink:href"],e,i).catch(n=>(pi("log","Unable to parse Image",n),null))}}function hg(a){if(!qv.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"),l=a.getAttribute("height"),d=a.getAttribute("x")||0,u=a.getAttribute("y")||0,g=!(t&&Np.test(t)),f=!h||!l||h==="100%"||l==="100%";let p="",m=0,_=0;if(g&&(d||u)&&a.parentNode&&a.parentNode.nodeName!=="#document"&&(p=" translate("+Te(d||"0")+" "+Te(u||"0")+") ",e=(a.getAttribute("transform")||"")+p,a.setAttribute("transform",e),a.removeAttribute("x"),a.removeAttribute("y")),g&&f)return{width:0,height:0};const v={width:0,height:0};if(g)return v.width=Te(h),v.height=Te(l),v;const x=t.match(Np);r=-parseFloat(x[1]),o=-parseFloat(x[2]);const S=parseFloat(x[3]),C=parseFloat(x[4]);v.minX=r,v.minY=o,v.viewBoxWidth=S,v.viewBoxHeight=C,f?(v.width=S,v.height=C):(v.width=Te(h),v.height=Te(l),i=v.width/S,n=v.height/C);const E=Eu(a.getAttribute("preserveAspectRatio")||"");if(E.alignX!==Se&&(E.meetOrSlice==="meet"&&(n=i=i>n?n:i),E.meetOrSlice==="slice"&&(n=i=i>n?i:n),m=v.width-S*i,_=v.height-C*i,E.alignX==="Mid"&&(m/=2),E.alignY==="Mid"&&(_/=2),E.alignX==="Min"&&(m=0),E.alignY==="Min"&&(_=0)),i===1&&n===1&&r===0&&o===0&&d===0&&u===0)return v;if((d||u)&&a.parentNode.nodeName!=="#document"&&(p=" translate("+Te(d||"0")+" "+Te(u||"0")+") "),e=p+" matrix("+i+" 0 0 "+n+" "+(r*i+m)+" "+(o*n+_)+") ",a.nodeName==="svg"){for(s=a.ownerDocument.createElementNS(Lu,"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}A(fe,"type","Image"),A(fe,"cacheProperties",[...vi,...Qm]),A(fe,"ownDefaults",{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),A(fe,"CSS_CANVAS","canvas-img"),A(fe,"ATTRIBUTE_NAMES",[...un,"x","y","width","height","preserveAspectRatio","xlink:href","crossOrigin","image-rendering"]),N.setClass(fe),N.setSVGClass(fe);const jc=a=>a.tagName.replace("svg:",""),V_=uc(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);function Jm(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 G_=["gradientTransform","x1","x2","y1","y2","gradientUnits","cx","cy","r","fx","fy"],lg="xlink:href";function Zm(a,t){var e;const s=((e=t.getAttribute(lg))===null||e===void 0?void 0:e.slice(1))||"",i=a.getElementById(s);if(i&&i.getAttribute(lg)&&Zm(a,i),i&&(G_.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(lg)}const U_=["linearGradient","radialGradient","svg:linearGradient","svg:radialGradient"];function Y_(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={},l=o[1].trim().split(";").filter(function(d){return d.trim()});for(e=0,s=l.length;e<s;e++){const d=l[e].split(":"),u=d[0].trim(),g=d[1].trim();h[u]=g}(r=o[0].trim()).split(",").forEach(d=>{(d=d.replace(/^svg/i,"").trim())!==""&&(i[d]=T(T({},i[d]||{}),h))})})}return i}const t0=a=>N.getSVGClass(jc(a).toLowerCase());class q_{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=Jm(r,U_),h={};let l=o.length;for(;l--;){const d=o[l];d.getAttribute("xlink:href")&&Zm(r,d);const u=d.getAttribute("id");u&&(h[u]=d)}return h}(i),this.cssRules=Y_(i)}parse(){return Promise.all(this.elements.map(t=>this.createObject(t)))}async createObject(t){const e=t0(t);if(e){const s=await e.fromElement(t,this.options,this.cssRules);return this.resolveGradient(s,t,Ft),this.resolveGradient(s,t,Ae),s instanceof fe&&s._originalElement?kc(s,s.parsePreserveAspectRatioAttribute()):kc(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=oh.fromElement(i,t,T(T({},this.options),{},{opacity:n}));t.set(s,r)}}async resolveClipPath(t,e){const s=this.extractPropertyDefinition(t,"clipPath",this.clipPaths);if(s){const i=je(t.calcTransformMatrix()),n=s[0].parentElement;let r=e;for(;r.parentElement&&r.getAttribute("clip-path")!==t.clipPath;)r=r.parentElement;r.parentElement.appendChild(n);const o=xc("".concat(r.getAttribute("transform")||""," ").concat(n.getAttribute("originalTransform")||""));n.setAttribute("transform","matrix(".concat(o.join(","),")"));const h=await Promise.all(s.map(v=>t0(v).fromElement(v,this.options,this.cssRules).then(x=>(kc(x),x.fillRule=x.clipRule,delete x.clipRule,x)))),l=h.length===1?h[0]:new Us(h),d=It(i,l.calcTransformMatrix());l.clipPath&&await this.resolveClipPath(l,r);const{scaleX:u,scaleY:g,angle:f,skewX:p,translateX:m,translateY:_}=Qn(d);l.set({flipX:!1,flipY:!1}),l.set({scaleX:u,scaleY:g,angle:f,skewX:p,skewY:0}),l.setPositionByOrigin(new D(m,_),Q,Q),t.clipPath=l}else delete t.clipPath}}const e0=a=>Yv.test(jc(a)),cg=()=>({objects:[],elements:[],options:{},allElements:[]});async function $_(a,t){let{crossOrigin:e,signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(s&&s.aborted)return pi("log",new gu("parseSVGDocument")),cg();const i=a.documentElement;(function(d){const u=Jm(d,["use","svg:use"]),g=["x","y","xlink:href","href","transform"];for(const f of u){const p=f.attributes,m={};for(const P of p)P.value&&(m[P.name]=P.value);const _=(m["xlink:href"]||m.href||"").slice(1);if(_==="")return;const v=d.getElementById(_);if(v===null)return;let x=v.cloneNode(!0);const S=x.attributes,C={};for(const P of S)P.value&&(C[P.name]=P.value);const{x:E=0,y:M=0,transform:k=""}=m,O="".concat(k," ").concat(C.transform||""," translate(").concat(E,", ").concat(M,")");if(hg(x),/^svg$/i.test(x.nodeName)){const P=x.ownerDocument.createElementNS(Lu,"g");Object.entries(C).forEach(L=>{let[F,W]=L;return P.setAttributeNS(Lu,F,W)}),P.append(...x.childNodes),x=P}for(const P of p){if(!P)continue;const{name:L,value:F}=P;if(!g.includes(L))if(L==="style"){const W={};qu(F,W),Object.entries(C).forEach(z=>{let[K,tt]=z;W[K]=tt}),qu(C.style||"",W);const B=Object.entries(W).map(z=>z.join(":")).join(";");x.setAttribute(L,B)}else!C[L]&&x.setAttribute(L,F)}x.setAttribute("transform",O),x.setAttribute("instantiated_by_use","1"),x.removeAttribute("id"),f.parentNode.replaceChild(x,f)}})(a);const n=Array.from(i.getElementsByTagName("*")),r=T(T({},hg(i)),{},{crossOrigin:e,signal:s}),o=n.filter(d=>(hg(d),e0(d)&&!function(u){let g=u;for(;g&&(g=g.parentElement);)if(g&&g.nodeName&&V_.test(jc(g))&&!g.getAttribute("instantiated_by_use"))return!0;return!1}(d)));if(!o||o&&!o.length)return T(T({},cg()),{},{options:r,allElements:n});const h={};return n.filter(d=>jc(d)==="clipPath").forEach(d=>{d.setAttribute("originalTransform",d.getAttribute("transform")||"");const u=d.getAttribute("id");h[u]=Array.from(d.getElementsByTagName("*")).filter(g=>e0(g))}),{objects:await new q_(o,r,t,a,h).parse(),elements:o,options:r,allElements:n}}function K_(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return new Promise((s,i)=>{Lm(a.replace(/^\n\s*/,"").trim(),{onComplete:n=>{const r=n.responseXML;r&&s(r),i()},signal:e.signal})}).then(s=>$_(s,t,e)).catch(()=>cg())}const Nc=a=>a.webgl!==void 0,dg="precision highp float",Q_=`
63
+ `.concat(dg,`;
64
64
  varying vec2 vTexCoord;
65
65
  uniform sampler2D uTexture;
66
66
  void main() {
67
67
  gl_FragColor = texture2D(uTexture, vTexCoord);
68
- }`),$_=["type"],K_=["type"],Q_=new RegExp(cg,"g");class Ut{get type(){return this.constructor.type}constructor(){let t=St(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},$_);Object.assign(this,this.constructor.defaults,t)}getFragmentSource(){return q_}getVertexSource(){return`
68
+ }`),J_=["type"],Z_=["type"],tw=new RegExp(dg,"g");class Vt{get type(){return this.constructor.type}constructor(){let t=wt(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},J_);Object.assign(this,this.constructor.defaults,t)}getFragmentSource(){return Q_}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"}}=zs();i!=="highp"&&(e=e.replace(Q_,cg.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 Xs("Vertex, fragment shader or program creation error");if(t.shaderSource(n,s),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new Xs("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 Xs("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 Xs('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){jc(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 e=jt();e.width=t.sourceWidth,e.height=t.sourceHeight,t.helpLayer=e}}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(St(t,K_))}}A(Ut,"type","BaseFilter"),A(Ut,"uniformLocations",[]);const J_={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"}}=zs();i!=="highp"&&(e=e.replace(tw,dg.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 Xs("Vertex, fragment shader or program creation error");if(t.shaderSource(n,s),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new Xs("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 Xs("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 Xs('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){Nc(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 e=Rt();e.width=t.sourceWidth,e.height=t.sourceHeight,t.helpLayer=e}}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(wt(t,Z_))}}A(Vt,"type","BaseFilter"),A(Vt,"uniformLocations",[]);const ew={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 Nc extends Ut{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return`
101
+ `};class Bc extends Vt{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(J_[this.mode],`
110
+ `.concat(ew[this.mode],`
111
111
  }
112
112
  }
113
- `)}applyTo2d(t){let{imageData:{data:e}}=t;const s=new ut(this.color).getSource(),i=s[0]*this.alpha,n=s[1]*this.alpha,r=s[2]*this.alpha,o=1-this.alpha;for(let h=0;h<e.length;h+=4){const l=e[h],d=e[h+1],u=e[h+2];switch(this.mode){case"multiply":e[h]=l*i/255,e[h+1]=d*n/255,e[h+2]=u*r/255;break;case"screen":e[h]=255-(255-l)*(255-i)/255,e[h+1]=255-(255-d)*(255-n)/255,e[h+2]=255-(255-u)*(255-r)/255;break;case"add":e[h]=l+i,e[h+1]=d+n,e[h+2]=u+r;break;case"difference":e[h]=Math.abs(l-i),e[h+1]=Math.abs(d-n),e[h+2]=Math.abs(u-r);break;case"subtract":e[h]=l-i,e[h+1]=d-n,e[h+2]=u-r;break;case"darken":e[h]=Math.min(l,i),e[h+1]=Math.min(d,n),e[h+2]=Math.min(u,r);break;case"lighten":e[h]=Math.max(l,i),e[h+1]=Math.max(d,n),e[h+2]=Math.max(u,r);break;case"overlay":e[h]=i<128?2*l*i/255:255-2*(255-l)*(255-i)/255,e[h+1]=n<128?2*d*n/255:255-2*(255-d)*(255-n)/255,e[h+2]=r<128?2*u*r/255:255-2*(255-u)*(255-r)/255;break;case"exclusion":e[h]=i+l-2*i*l/255,e[h+1]=n+d-2*n*d/255,e[h+2]=r+u-2*r*u/255;break;case"tint":e[h]=i+l*o,e[h+1]=n+d*o,e[h+2]=r+u*o}}}sendUniformData(t,e){const s=new ut(this.color).getSource();s[0]=this.alpha*s[0]/255,s[1]=this.alpha*s[1]/255,s[2]=this.alpha*s[2]/255,s[3]=this.alpha,t.uniform4fv(e.uColor,s)}}A(Nc,"defaults",{color:"#F95C63",mode:"multiply",alpha:1}),A(Nc,"type","BlendColor"),A(Nc,"uniformLocations",["uColor"]),X.setClass(Nc);const Z_={multiply:`
113
+ `)}applyTo2d(t){let{imageData:{data:e}}=t;const s=new ut(this.color).getSource(),i=s[0]*this.alpha,n=s[1]*this.alpha,r=s[2]*this.alpha,o=1-this.alpha;for(let h=0;h<e.length;h+=4){const l=e[h],d=e[h+1],u=e[h+2];switch(this.mode){case"multiply":e[h]=l*i/255,e[h+1]=d*n/255,e[h+2]=u*r/255;break;case"screen":e[h]=255-(255-l)*(255-i)/255,e[h+1]=255-(255-d)*(255-n)/255,e[h+2]=255-(255-u)*(255-r)/255;break;case"add":e[h]=l+i,e[h+1]=d+n,e[h+2]=u+r;break;case"difference":e[h]=Math.abs(l-i),e[h+1]=Math.abs(d-n),e[h+2]=Math.abs(u-r);break;case"subtract":e[h]=l-i,e[h+1]=d-n,e[h+2]=u-r;break;case"darken":e[h]=Math.min(l,i),e[h+1]=Math.min(d,n),e[h+2]=Math.min(u,r);break;case"lighten":e[h]=Math.max(l,i),e[h+1]=Math.max(d,n),e[h+2]=Math.max(u,r);break;case"overlay":e[h]=i<128?2*l*i/255:255-2*(255-l)*(255-i)/255,e[h+1]=n<128?2*d*n/255:255-2*(255-d)*(255-n)/255,e[h+2]=r<128?2*u*r/255:255-2*(255-u)*(255-r)/255;break;case"exclusion":e[h]=i+l-2*i*l/255,e[h+1]=n+d-2*n*d/255,e[h+2]=r+u-2*r*u/255;break;case"tint":e[h]=i+l*o,e[h+1]=n+d*o,e[h+2]=r+u*o}}}sendUniformData(t,e){const s=new ut(this.color).getSource();s[0]=this.alpha*s[0]/255,s[1]=this.alpha*s[1]/255,s[2]=this.alpha*s[2]/255,s[3]=this.alpha,t.uniform4fv(e.uColor,s)}}A(Bc,"defaults",{color:"#F95C63",mode:"multiply",alpha:1}),A(Bc,"type","BlendColor"),A(Bc,"uniformLocations",["uColor"]),N.setClass(Bc);const sw={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
- `},tw=["type","image"];class Bc extends Ut{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return Z_[this.mode]}getVertexSource(){return`
139
+ `},iw=["type","image"];class Hc extends Vt{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return sw[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=jt());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 l=h.getImageData(0,0,s,i).data;for(let d=0;d<e.length;d+=4){const u=e[d],g=e[d+1],f=e[d+2],p=e[d+3],m=l[d],w=l[d+1],v=l[d+2],x=l[d+3];switch(this.mode){case"multiply":e[d]=u*m/255,e[d+1]=g*w/255,e[d+2]=f*v/255,e[d+3]=p*x/255;break;case"mask":e[d+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=St(t,tw);return fe.fromObject(i,e).then(r=>new this(T(T({},n),{},{image:r})))}}A(Bc,"type","BlendImage"),A(Bc,"defaults",{mode:"multiply",alpha:1}),A(Bc,"uniformLocations",["uTransformMatrix","uImage"]),X.setClass(Bc);class Hc extends Ut{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=Rt());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 l=h.getImageData(0,0,s,i).data;for(let d=0;d<e.length;d+=4){const u=e[d],g=e[d+1],f=e[d+2],p=e[d+3],m=l[d],_=l[d+1],v=l[d+2],x=l[d+3];switch(this.mode){case"multiply":e[d]=u*m/255,e[d+1]=g*_/255,e[d+2]=f*v/255,e[d+3]=p*x/255;break;case"mask":e[d+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=wt(t,iw);return fe.fromObject(i,e).then(r=>new this(T(T({},n),{},{image:r})))}}A(Hc,"type","BlendImage"),A(Hc,"defaults",{mode:"multiply",alpha:1}),A(Hc,"uniformLocations",["uTransformMatrix","uImage"]),N.setClass(Hc);class Wc extends Vt{getFragmentSource(){return`
150
150
  precision highp float;
151
151
  uniform sampler2D uTexture;
152
152
  uniform vec2 uDelta;
@@ -169,7 +169,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
169
169
  }
170
170
  gl_FragColor = color / total;
171
171
  }
172
- `}applyTo(t){jc(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=jt(),i.blurLayer2=jt());const o=i.blurLayer1,h=i.blurLayer2;o.width===n&&o.height===r||(h.width=o.width=n,h.height=o.height=r);const l=o.getContext("2d"),d=h.getContext("2d"),u=15,g=.06*this.blur*.5;let f,p,m,w;for(l.putImageData(s,0,0),d.clearRect(0,0,n,r),w=-15;w<=u;w++)f=(Math.random()-.5)/4,p=w/u,m=g*p*n+f,d.globalAlpha=1-Math.abs(p),d.drawImage(o,m,f),l.drawImage(h,0,0),d.globalAlpha=1,d.clearRect(0,0,h.width,h.height);for(w=-15;w<=u;w++)f=(Math.random()-.5)/4,p=w/u,m=g*p*r+f,d.globalAlpha=1-Math.abs(p),d.drawImage(o,f,m),l.drawImage(h,0,0),d.globalAlpha=1,d.clearRect(0,0,h.width,h.height);e.drawImage(o,0,0);const v=e.getImageData(0,0,o.width,o.height);return l.globalAlpha=1,l.clearRect(0,0,o.width,o.height),v}sendUniformData(t,e){const s=this.chooseRightDelta();t.uniform2fv(e.uDelta,s)}isNeutralState(){return this.blur===0}chooseRightDelta(){let t=1;const e=[0,0];this.horizontal?this.aspectRatio>1&&(t=1/this.aspectRatio):this.aspectRatio<1&&(t=this.aspectRatio);const s=t*this.blur*.12;return this.horizontal?e[0]=s:e[1]=s,e}}A(Hc,"type","Blur"),A(Hc,"defaults",{blur:0}),A(Hc,"uniformLocations",["uDelta"]),X.setClass(Hc);class Wc extends Ut{getFragmentSource(){return`
172
+ `}applyTo(t){Nc(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=Rt(),i.blurLayer2=Rt());const o=i.blurLayer1,h=i.blurLayer2;o.width===n&&o.height===r||(h.width=o.width=n,h.height=o.height=r);const l=o.getContext("2d"),d=h.getContext("2d"),u=15,g=.06*this.blur*.5;let f,p,m,_;for(l.putImageData(s,0,0),d.clearRect(0,0,n,r),_=-15;_<=u;_++)f=(Math.random()-.5)/4,p=_/u,m=g*p*n+f,d.globalAlpha=1-Math.abs(p),d.drawImage(o,m,f),l.drawImage(h,0,0),d.globalAlpha=1,d.clearRect(0,0,h.width,h.height);for(_=-15;_<=u;_++)f=(Math.random()-.5)/4,p=_/u,m=g*p*r+f,d.globalAlpha=1-Math.abs(p),d.drawImage(o,f,m),l.drawImage(h,0,0),d.globalAlpha=1,d.clearRect(0,0,h.width,h.height);e.drawImage(o,0,0);const v=e.getImageData(0,0,o.width,o.height);return l.globalAlpha=1,l.clearRect(0,0,o.width,o.height),v}sendUniformData(t,e){const s=this.chooseRightDelta();t.uniform2fv(e.uDelta,s)}isNeutralState(){return this.blur===0}chooseRightDelta(){let t=1;const e=[0,0];this.horizontal?this.aspectRatio>1&&(t=1/this.aspectRatio):this.aspectRatio<1&&(t=this.aspectRatio);const s=t*this.blur*.12;return this.horizontal?e[0]=s:e[1]=s,e}}A(Wc,"type","Blur"),A(Wc,"defaults",{blur:0}),A(Wc,"uniformLocations",["uDelta"]),N.setClass(Wc);class Xc extends Vt{getFragmentSource(){return`
173
173
  precision highp float;
174
174
  uniform sampler2D uTexture;
175
175
  uniform float uBrightness;
@@ -179,7 +179,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
179
179
  color.rgb += uBrightness;
180
180
  gl_FragColor = color;
181
181
  }
182
- `}applyTo2d(t){let{imageData:{data:e}}=t;const s=Math.round(255*this.brightness);for(let i=0;i<e.length;i+=4)e[i]=e[i]+s,e[i+1]=e[i+1]+s,e[i+2]=e[i+2]+s}isNeutralState(){return this.brightness===0}sendUniformData(t,e){t.uniform1f(e.uBrightness,this.brightness)}}A(Wc,"type","Brightness"),A(Wc,"defaults",{brightness:0}),A(Wc,"uniformLocations",["uBrightness"]),X.setClass(Wc);class Io extends Ut{getFragmentSource(){return`
182
+ `}applyTo2d(t){let{imageData:{data:e}}=t;const s=Math.round(255*this.brightness);for(let i=0;i<e.length;i+=4)e[i]=e[i]+s,e[i+1]=e[i+1]+s,e[i+2]=e[i+2]+s}isNeutralState(){return this.brightness===0}sendUniformData(t,e){t.uniform1f(e.uBrightness,this.brightness)}}A(Xc,"type","Brightness"),A(Xc,"defaults",{brightness:0}),A(Xc,"uniformLocations",["uBrightness"]),N.setClass(Xc);class Io extends Vt{getFragmentSource(){return`
183
183
  precision highp float;
184
184
  uniform sampler2D uTexture;
185
185
  varying vec2 vTexCoord;
@@ -190,7 +190,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
190
190
  color *= uColorMatrix;
191
191
  color += uConstants;
192
192
  gl_FragColor = color;
193
- }`}applyTo2d(t){const e=t.imageData.data,s=this.matrix,i=this.colorsOnly;for(let n=0;n<e.length;n+=4){const r=e[n],o=e[n+1],h=e[n+2];if(i)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];else{const l=e[n+3];e[n]=r*s[0]+o*s[1]+h*s[2]+l*s[3]+255*s[4],e[n+1]=r*s[5]+o*s[6]+h*s[7]+l*s[8]+255*s[9],e[n+2]=r*s[10]+o*s[11]+h*s[12]+l*s[13]+255*s[14],e[n+3]=r*s[15]+o*s[16]+h*s[17]+l*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 ar(a,t){var e;const s=(A(e=class extends Io{toObject(){return{type:this.type,colorsOnly:this.colorsOnly}}},"type",a),A(e,"defaults",{colorsOnly:!1,matrix:t}),e);return X.setClass(s,a),s}A(Io,"type","ColorMatrix"),A(Io,"defaults",{matrix:[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],colorsOnly:!0}),A(Io,"uniformLocations",["uColorMatrix","uConstants"]),X.setClass(Io),ar("Brownie",[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0]),ar("Vintage",[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0]),ar("Kodachrome",[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0]),ar("Technicolor",[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0]),ar("Polaroid",[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0]),ar("Sepia",[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0]),ar("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 e0 extends Ut{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.subFilters=t.subFilters||[]}applyTo(t){jc(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=>X.getClass(s.type).fromObject(s,e))).then(s=>new this({subFilters:s}))}}A(e0,"type","Composed"),X.setClass(e0);class Xc extends Ut{getFragmentSource(){return`
193
+ }`}applyTo2d(t){const e=t.imageData.data,s=this.matrix,i=this.colorsOnly;for(let n=0;n<e.length;n+=4){const r=e[n],o=e[n+1],h=e[n+2];if(i)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];else{const l=e[n+3];e[n]=r*s[0]+o*s[1]+h*s[2]+l*s[3]+255*s[4],e[n+1]=r*s[5]+o*s[6]+h*s[7]+l*s[8]+255*s[9],e[n+2]=r*s[10]+o*s[11]+h*s[12]+l*s[13]+255*s[14],e[n+3]=r*s[15]+o*s[16]+h*s[17]+l*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 ar(a,t){var e;const s=(A(e=class extends Io{toObject(){return{type:this.type,colorsOnly:this.colorsOnly}}},"type",a),A(e,"defaults",{colorsOnly:!1,matrix:t}),e);return N.setClass(s,a),s}A(Io,"type","ColorMatrix"),A(Io,"defaults",{matrix:[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],colorsOnly:!0}),A(Io,"uniformLocations",["uColorMatrix","uConstants"]),N.setClass(Io),ar("Brownie",[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0]),ar("Vintage",[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0]),ar("Kodachrome",[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0]),ar("Technicolor",[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0]),ar("Polaroid",[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0]),ar("Sepia",[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0]),ar("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 s0 extends Vt{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.subFilters=t.subFilters||[]}applyTo(t){Nc(t)&&(t.passes+=this.subFilters.length-1),this.subFilters.forEach(e=>{e.applyTo(t)})}toObject(){return{type:this.type,subFilters:this.subFilters.map(t=>t.toObject())}}isNeutralState(){return!this.subFilters.some(t=>!t.isNeutralState())}static fromObject(t,e){return Promise.all((t.subFilters||[]).map(s=>N.getClass(s.type).fromObject(s,e))).then(s=>new this({subFilters:s}))}}A(s0,"type","Composed"),N.setClass(s0);class zc extends Vt{getFragmentSource(){return`
194
194
  precision highp float;
195
195
  uniform sampler2D uTexture;
196
196
  uniform float uContrast;
@@ -200,7 +200,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
200
200
  float contrastF = 1.015 * (uContrast + 1.0) / (1.0 * (1.015 - uContrast));
201
201
  color.rgb = contrastF * (color.rgb - 0.5) + 0.5;
202
202
  gl_FragColor = color;
203
- }`}isNeutralState(){return this.contrast===0}applyTo2d(t){let{imageData:{data:e}}=t;const s=Math.floor(255*this.contrast),i=259*(s+255)/(255*(259-s));for(let n=0;n<e.length;n+=4)e[n]=i*(e[n]-128)+128,e[n+1]=i*(e[n+1]-128)+128,e[n+2]=i*(e[n+2]-128)+128}sendUniformData(t,e){t.uniform1f(e.uContrast,this.contrast)}}A(Xc,"type","Contrast"),A(Xc,"defaults",{contrast:0}),A(Xc,"uniformLocations",["uContrast"]),X.setClass(Xc);const ew={Convolute_3_1:`
203
+ }`}isNeutralState(){return this.contrast===0}applyTo2d(t){let{imageData:{data:e}}=t;const s=Math.floor(255*this.contrast),i=259*(s+255)/(255*(259-s));for(let n=0;n<e.length;n+=4)e[n]=i*(e[n]-128)+128,e[n+1]=i*(e[n+1]-128)+128,e[n+2]=i*(e[n+2]-128)+128}sendUniformData(t,e){t.uniform1f(e.uContrast,this.contrast)}}A(zc,"type","Contrast"),A(zc,"defaults",{contrast:0}),A(zc,"uniformLocations",["uContrast"]),N.setClass(zc);const nw={Convolute_3_1:`
204
204
  precision highp float;
205
205
  uniform sampler2D uTexture;
206
206
  uniform float uMatrix[9];
@@ -344,7 +344,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
344
344
  gl_FragColor = color;
345
345
  gl_FragColor.a = alpha;
346
346
  }
347
- `};class zc extends Ut{getCacheKey(){return"".concat(this.type,"_").concat(Math.sqrt(this.matrix.length),"_").concat(this.opaque?1:0)}getFragmentSource(){return ew[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,l=t.ctx.createImageData(o,h),d=l.data,u=this.opaque?1:0;let g,f,p,m,w,v,x,S,C,E,k,P,D;for(k=0;k<h;k++)for(E=0;E<o;E++){for(w=4*(k*o+E),g=0,f=0,p=0,m=0,D=0;D<n;D++)for(P=0;P<n;P++)x=k+D-r,v=E+P-r,x<0||x>=h||v<0||v>=o||(S=4*(x*o+v),C=i[D*n+P],g+=s[S]*C,f+=s[S+1]*C,p+=s[S+2]*C,u||(m+=s[S+3]*C));d[w]=g,d[w+1]=f,d[w+2]=p,d[w+3]=u?s[w+3]:m}t.imageData=l}sendUniformData(t,e){t.uniform1fv(e.uMatrix,this.matrix)}toObject(){return T(T({},super.toObject()),{},{opaque:this.opaque,matrix:[...this.matrix]})}}A(zc,"type","Convolute"),A(zc,"defaults",{opaque:!1,matrix:[0,0,0,0,1,0,0,0,0]}),A(zc,"uniformLocations",["uMatrix","uOpaque","uHalfSize","uSize"]),X.setClass(zc);const s0="Gamma";class Vc extends Ut{getFragmentSource(){return`
347
+ `};class Vc extends Vt{getCacheKey(){return"".concat(this.type,"_").concat(Math.sqrt(this.matrix.length),"_").concat(this.opaque?1:0)}getFragmentSource(){return nw[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,l=t.ctx.createImageData(o,h),d=l.data,u=this.opaque?1:0;let g,f,p,m,_,v,x,S,C,E,M,k,O;for(M=0;M<h;M++)for(E=0;E<o;E++){for(_=4*(M*o+E),g=0,f=0,p=0,m=0,O=0;O<n;O++)for(k=0;k<n;k++)x=M+O-r,v=E+k-r,x<0||x>=h||v<0||v>=o||(S=4*(x*o+v),C=i[O*n+k],g+=s[S]*C,f+=s[S+1]*C,p+=s[S+2]*C,u||(m+=s[S+3]*C));d[_]=g,d[_+1]=f,d[_+2]=p,d[_+3]=u?s[_+3]:m}t.imageData=l}sendUniformData(t,e){t.uniform1fv(e.uMatrix,this.matrix)}toObject(){return T(T({},super.toObject()),{},{opaque:this.opaque,matrix:[...this.matrix]})}}A(Vc,"type","Convolute"),A(Vc,"defaults",{opaque:!1,matrix:[0,0,0,0,1,0,0,0,0]}),A(Vc,"uniformLocations",["uMatrix","uOpaque","uHalfSize","uSize"]),N.setClass(Vc);const i0="Gamma";class Gc extends Vt{getFragmentSource(){return`
348
348
  precision highp float;
349
349
  uniform sampler2D uTexture;
350
350
  uniform vec3 uGamma;
@@ -358,7 +358,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
358
358
  gl_FragColor = color;
359
359
  gl_FragColor.rgb *= color.a;
360
360
  }
361
- `}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.gamma=t.gamma||this.constructor.defaults.gamma.concat()}applyTo2d(t){let{imageData:{data:e}}=t;const s=this.gamma,i=1/s[0],n=1/s[1],r=1/s[2];this.rgbValues||(this.rgbValues={r:new Uint8Array(256),g:new Uint8Array(256),b:new Uint8Array(256)});const o=this.rgbValues;for(let h=0;h<256;h++)o.r[h]=255*Math.pow(h/255,i),o.g[h]=255*Math.pow(h/255,n),o.b[h]=255*Math.pow(h/255,r);for(let h=0;h<e.length;h+=4)e[h]=o.r[e[h]],e[h+1]=o.g[e[h+1]],e[h+2]=o.b[e[h+2]]}sendUniformData(t,e){t.uniform3fv(e.uGamma,this.gamma)}isNeutralState(){const{gamma:t}=this;return t[0]===1&&t[1]===1&&t[2]===1}toObject(){return{type:s0,gamma:this.gamma.concat()}}}A(Vc,"type",s0),A(Vc,"defaults",{gamma:[1,1,1]}),A(Vc,"uniformLocations",["uGamma"]),X.setClass(Vc);const sw={average:`
361
+ `}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.gamma=t.gamma||this.constructor.defaults.gamma.concat()}applyTo2d(t){let{imageData:{data:e}}=t;const s=this.gamma,i=1/s[0],n=1/s[1],r=1/s[2];this.rgbValues||(this.rgbValues={r:new Uint8Array(256),g:new Uint8Array(256),b:new Uint8Array(256)});const o=this.rgbValues;for(let h=0;h<256;h++)o.r[h]=255*Math.pow(h/255,i),o.g[h]=255*Math.pow(h/255,n),o.b[h]=255*Math.pow(h/255,r);for(let h=0;h<e.length;h+=4)e[h]=o.r[e[h]],e[h+1]=o.g[e[h+1]],e[h+2]=o.b[e[h+2]]}sendUniformData(t,e){t.uniform3fv(e.uGamma,this.gamma)}isNeutralState(){const{gamma:t}=this;return t[0]===1&&t[1]===1&&t[2]===1}toObject(){return{type:i0,gamma:this.gamma.concat()}}}A(Gc,"type",i0),A(Gc,"defaults",{gamma:[1,1,1]}),A(Gc,"uniformLocations",["uGamma"]),N.setClass(Gc);const rw={average:`
362
362
  precision highp float;
363
363
  uniform sampler2D uTexture;
364
364
  varying vec2 vTexCoord;
@@ -387,7 +387,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
387
387
  float average = 0.21 * col.r + 0.72 * col.g + 0.07 * col.b;
388
388
  gl_FragColor = vec4(average, average, average, col.a);
389
389
  }
390
- `};class Gc extends Ut{applyTo2d(t){let{imageData:{data:e}}=t;for(let s,i=0;i<e.length;i+=4){switch(this.mode){case"average":s=(e[i]+e[i+1]+e[i+2])/3;break;case"lightness":s=(Math.min(e[i],e[i+1],e[i+2])+Math.max(e[i],e[i+1],e[i+2]))/2;break;case"luminosity":s=.21*e[i]+.72*e[i+1]+.07*e[i+2]}e[i]=s,e[i+1]=s,e[i+2]=s}}getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return sw[this.mode]}sendUniformData(t,e){t.uniform1i(e.uMode,1)}isNeutralState(){return!1}}A(Gc,"type","Grayscale"),A(Gc,"defaults",{mode:"average"}),A(Gc,"uniformLocations",["uMode"]),X.setClass(Gc);class dg extends Io{calculateMatrix(){const t=this.rotation*Math.PI,e=vs(t),s=ys(t),i=1/3,n=Math.sqrt(i)*s,r=1-e;this.matrix=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],this.matrix[0]=e+r/3,this.matrix[1]=i*r-n,this.matrix[2]=i*r+n,this.matrix[5]=i*r+n,this.matrix[6]=e+i*r,this.matrix[7]=i*r-n,this.matrix[10]=i*r-n,this.matrix[11]=i*r+n,this.matrix[12]=e+i*r}isNeutralState(){return this.rotation===0}applyTo(t){this.calculateMatrix(),super.applyTo(t)}toObject(){return{type:this.type,rotation:this.rotation}}}A(dg,"type","HueRotation"),A(dg,"defaults",{rotation:0}),X.setClass(dg);class Uc extends Ut{applyTo2d(t){let{imageData:{data:e}}=t;for(let s=0;s<e.length;s+=4)e[s]=255-e[s],e[s+1]=255-e[s+1],e[s+2]=255-e[s+2],this.alpha&&(e[s+3]=255-e[s+3])}getFragmentSource(){return`
390
+ `};class Uc extends Vt{applyTo2d(t){let{imageData:{data:e}}=t;for(let s,i=0;i<e.length;i+=4){switch(this.mode){case"average":s=(e[i]+e[i+1]+e[i+2])/3;break;case"lightness":s=(Math.min(e[i],e[i+1],e[i+2])+Math.max(e[i],e[i+1],e[i+2]))/2;break;case"luminosity":s=.21*e[i]+.72*e[i+1]+.07*e[i+2]}e[i]=s,e[i+1]=s,e[i+2]=s}}getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return rw[this.mode]}sendUniformData(t,e){t.uniform1i(e.uMode,1)}isNeutralState(){return!1}}A(Uc,"type","Grayscale"),A(Uc,"defaults",{mode:"average"}),A(Uc,"uniformLocations",["uMode"]),N.setClass(Uc);class ug extends Io{calculateMatrix(){const t=this.rotation*Math.PI,e=vs(t),s=ys(t),i=1/3,n=Math.sqrt(i)*s,r=1-e;this.matrix=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],this.matrix[0]=e+r/3,this.matrix[1]=i*r-n,this.matrix[2]=i*r+n,this.matrix[5]=i*r+n,this.matrix[6]=e+i*r,this.matrix[7]=i*r-n,this.matrix[10]=i*r-n,this.matrix[11]=i*r+n,this.matrix[12]=e+i*r}isNeutralState(){return this.rotation===0}applyTo(t){this.calculateMatrix(),super.applyTo(t)}toObject(){return{type:this.type,rotation:this.rotation}}}A(ug,"type","HueRotation"),A(ug,"defaults",{rotation:0}),N.setClass(ug);class Yc extends Vt{applyTo2d(t){let{imageData:{data:e}}=t;for(let s=0;s<e.length;s+=4)e[s]=255-e[s],e[s+1]=255-e[s+1],e[s+2]=255-e[s+2],this.alpha&&(e[s+3]=255-e[s+3])}getFragmentSource(){return`
391
391
  precision highp float;
392
392
  uniform sampler2D uTexture;
393
393
  uniform int uInvert;
@@ -405,7 +405,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
405
405
  gl_FragColor = color;
406
406
  }
407
407
  }
408
- `}isNeutralState(){return!this.invert}sendUniformData(t,e){t.uniform1i(e.uInvert,Number(this.invert)),t.uniform1i(e.uAlpha,Number(this.alpha))}}A(Uc,"type","Invert"),A(Uc,"defaults",{alpha:!1,invert:!0}),A(Uc,"uniformLocations",["uInvert","uAlpha"]),X.setClass(Uc);class Yc extends Ut{getFragmentSource(){return`
408
+ `}isNeutralState(){return!this.invert}sendUniformData(t,e){t.uniform1i(e.uInvert,Number(this.invert)),t.uniform1i(e.uAlpha,Number(this.alpha))}}A(Yc,"type","Invert"),A(Yc,"defaults",{alpha:!1,invert:!0}),A(Yc,"uniformLocations",["uInvert","uAlpha"]),N.setClass(Yc);class qc extends Vt{getFragmentSource(){return`
409
409
  precision highp float;
410
410
  uniform sampler2D uTexture;
411
411
  uniform float uStepH;
@@ -420,7 +420,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
420
420
  color.rgb += (0.5 - rand(vTexCoord, uSeed, 0.1 / uStepH)) * uNoise;
421
421
  gl_FragColor = color;
422
422
  }
423
- `}applyTo2d(t){let{imageData:{data:e}}=t;const s=this.noise;for(let i=0;i<e.length;i+=4){const n=(.5-Math.random())*s;e[i]+=n,e[i+1]+=n,e[i+2]+=n}}sendUniformData(t,e){t.uniform1f(e.uNoise,this.noise/255),t.uniform1f(e.uSeed,Math.random())}isNeutralState(){return this.noise===0}}A(Yc,"type","Noise"),A(Yc,"defaults",{noise:0}),A(Yc,"uniformLocations",["uNoise","uSeed"]),X.setClass(Yc);class qc extends Ut{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],l=e[o+1],d=e[o+2],u=e[o+3];for(let g=n;g<Math.min(n+this.blocksize,i);g++)for(let f=r;f<Math.min(r+this.blocksize,s);f++){const p=4*g*s+4*f;e[p]=h,e[p+1]=l,e[p+2]=d,e[p+3]=u}}}isNeutralState(){return this.blocksize===1}getFragmentSource(){return`
423
+ `}applyTo2d(t){let{imageData:{data:e}}=t;const s=this.noise;for(let i=0;i<e.length;i+=4){const n=(.5-Math.random())*s;e[i]+=n,e[i+1]+=n,e[i+2]+=n}}sendUniformData(t,e){t.uniform1f(e.uNoise,this.noise/255),t.uniform1f(e.uSeed,Math.random())}isNeutralState(){return this.noise===0}}A(qc,"type","Noise"),A(qc,"defaults",{noise:0}),A(qc,"uniformLocations",["uNoise","uSeed"]),N.setClass(qc);class $c extends Vt{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],l=e[o+1],d=e[o+2],u=e[o+3];for(let g=n;g<Math.min(n+this.blocksize,i);g++)for(let f=r;f<Math.min(r+this.blocksize,s);f++){const p=4*g*s+4*f;e[p]=h,e[p+1]=l,e[p+2]=d,e[p+3]=u}}}isNeutralState(){return this.blocksize===1}getFragmentSource(){return`
424
424
  precision highp float;
425
425
  uniform sampler2D uTexture;
426
426
  uniform float uBlocksize;
@@ -438,7 +438,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
438
438
  vec4 color = texture2D(uTexture, squareCoords);
439
439
  gl_FragColor = color;
440
440
  }
441
- `}sendUniformData(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}}A(qc,"type","Pixelate"),A(qc,"defaults",{blocksize:4}),A(qc,"uniformLocations",["uBlocksize"]),X.setClass(qc);class $c extends Ut{getFragmentSource(){return`
441
+ `}sendUniformData(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}}A($c,"type","Pixelate"),A($c,"defaults",{blocksize:4}),A($c,"uniformLocations",["uBlocksize"]),N.setClass($c);class Kc extends Vt{getFragmentSource(){return`
442
442
  precision highp float;
443
443
  uniform sampler2D uTexture;
444
444
  uniform vec4 uLow;
@@ -450,7 +450,7 @@ void main() {
450
450
  gl_FragColor.a = 0.0;
451
451
  }
452
452
  }
453
- `}applyTo2d(t){let{imageData:{data:e}}=t;const s=255*this.distance,i=new ut(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],l=e[o+1],d=e[o+2];h>n[0]&&l>n[1]&&d>n[2]&&h<r[0]&&l<r[1]&&d<r[2]&&(e[o+3]=0)}}sendUniformData(t,e){const s=new ut(this.color).getSource(),i=this.distance,n=[0+s[0]/255-i,0+s[1]/255-i,0+s[2]/255-i,1],r=[s[0]/255+i,s[1]/255+i,s[2]/255+i,1];t.uniform4fv(e.uLow,n),t.uniform4fv(e.uHigh,r)}}A($c,"type","RemoveColor"),A($c,"defaults",{color:"#FFFFFF",distance:.02,useAlpha:!1}),A($c,"uniformLocations",["uLow","uHigh"]),X.setClass($c);class Kc extends Ut{sendUniformData(t,e){t.uniform2fv(e.uDelta,this.horizontal?[1/this.width,0]:[0,1/this.height]),t.uniform1fv(e.uTaps,this.taps)}getFilterWindow(){const t=this.tempScale;return Math.ceil(this.lanczosLobes/t)}getCacheKey(){const t=this.getFilterWindow();return"".concat(this.type,"_").concat(t)}getFragmentSource(){const t=this.getFilterWindow();return this.generateShader(t)}getTaps(){const t=this.lanczosCreate(this.lanczosLobes),e=this.tempScale,s=this.getFilterWindow(),i=new Array(s);for(let n=1;n<=s;n++)i[n-1]=t(n*e);return i}generateShader(t){const e=new Array(t);for(let s=1;s<=t;s++)e[s-1]="".concat(s,".0 * uDelta");return`
453
+ `}applyTo2d(t){let{imageData:{data:e}}=t;const s=255*this.distance,i=new ut(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],l=e[o+1],d=e[o+2];h>n[0]&&l>n[1]&&d>n[2]&&h<r[0]&&l<r[1]&&d<r[2]&&(e[o+3]=0)}}sendUniformData(t,e){const s=new ut(this.color).getSource(),i=this.distance,n=[0+s[0]/255-i,0+s[1]/255-i,0+s[2]/255-i,1],r=[s[0]/255+i,s[1]/255+i,s[2]/255+i,1];t.uniform4fv(e.uLow,n),t.uniform4fv(e.uHigh,r)}}A(Kc,"type","RemoveColor"),A(Kc,"defaults",{color:"#FFFFFF",distance:.02,useAlpha:!1}),A(Kc,"uniformLocations",["uLow","uHigh"]),N.setClass(Kc);class Qc extends Vt{sendUniformData(t,e){t.uniform2fv(e.uDelta,this.horizontal?[1/this.width,0]:[0,1/this.height]),t.uniform1fv(e.uTaps,this.taps)}getFilterWindow(){const t=this.tempScale;return Math.ceil(this.lanczosLobes/t)}getCacheKey(){const t=this.getFilterWindow();return"".concat(this.type,"_").concat(t)}getFragmentSource(){const t=this.getFilterWindow();return this.generateShader(t)}getTaps(){const t=this.lanczosCreate(this.lanczosLobes),e=this.tempScale,s=this.getFilterWindow(),i=new Array(s);for(let n=1;n<=s;n++)i[n-1]=t(n*e);return i}generateShader(t){const e=new Array(t);for(let s=1;s<=t;s++)e[s-1]="".concat(s,".0 * uDelta");return`
454
454
  precision highp float;
455
455
  uniform sampler2D uTexture;
456
456
  uniform vec2 uDelta;
@@ -466,7 +466,7 @@ void main() {
466
466
  `),`
467
467
  gl_FragColor = color / sum;
468
468
  }
469
- `)}applyToForWebgl(t){t.passes++,this.width=t.sourceWidth,this.horizontal=!0,this.dW=Math.round(this.width*this.scaleX),this.dH=t.sourceHeight,this.tempScale=this.dW/this.width,this.taps=this.getTaps(),t.destinationWidth=this.dW,super.applyTo(t),t.sourceWidth=t.destinationWidth,this.height=t.sourceHeight,this.horizontal=!1,this.dH=Math.round(this.height*this.scaleY),this.tempScale=this.dH/this.height,this.taps=this.getTaps(),t.destinationHeight=this.dH,super.applyTo(t),t.sourceHeight=t.destinationHeight}applyTo(t){jc(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 l;l=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=l}sliceByTwo(t,e,s,i,n){const r=t.imageData,o=.5;let h=!1,l=!1,d=e*o,u=s*o;const g=t.filterBackend.resources;let f=0,p=0;const m=e;let w=0;g.sliceByTwo||(g.sliceByTwo=jt());const v=g.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||!l;)e=d,s=u,i<Math.floor(d*o)?d=Math.floor(d*o):(d=i,h=!0),n<Math.floor(u*o)?u=Math.floor(u*o):(u=n,l=!0),x.drawImage(v,f,p,e,s,m,w,d,u),f=m,p=w,w+=u;return x.getImageData(f,p,i,n)}lanczosResize(t,e,s,i,n){const r=t.imageData.data,o=t.ctx.createImageData(i,n),h=o.data,l=this.lanczosCreate(this.lanczosLobes),d=this.rcpScaleX,u=this.rcpScaleY,g=2/this.rcpScaleX,f=2/this.rcpScaleY,p=Math.ceil(d*this.lanczosLobes/2),m=Math.ceil(u*this.lanczosLobes/2),w={},v={x:0,y:0},x={x:0,y:0};return function S(C){let E,k,P,D,R,B,O,F,L,I,G;for(v.x=(C+.5)*d,x.x=Math.floor(v.x),E=0;E<n;E++){for(v.y=(E+.5)*u,x.y=Math.floor(v.y),R=0,B=0,O=0,F=0,L=0,k=x.x-p;k<=x.x+p;k++)if(!(k<0||k>=e)){I=Math.floor(1e3*Math.abs(k-v.x)),w[I]||(w[I]={});for(let Y=x.y-m;Y<=x.y+m;Y++)Y<0||Y>=s||(G=Math.floor(1e3*Math.abs(Y-v.y)),w[I][G]||(w[I][G]=l(Math.sqrt(Math.pow(I*g,2)+Math.pow(G*f,2))/1e3)),P=w[I][G],P>0&&(D=4*(Y*e+k),R+=P,B+=P*r[D],O+=P*r[D+1],F+=P*r[D+2],L+=P*r[D+3]))}D=4*(E*i+C),h[D]=B/R,h[D+1]=O/R,h[D+2]=F/R,h[D+3]=L/R}return++C<i?S(C):o}(0)}bilinearFiltering(t,e,s,i,n){let r,o,h,l,d,u,g,f,p,m,w,v,x,S=0;const C=this.rcpScaleX,E=this.rcpScaleY,k=4*(e-1),P=t.imageData.data,D=t.ctx.createImageData(i,n),R=D.data;for(g=0;g<n;g++)for(f=0;f<i;f++)for(d=Math.floor(C*f),u=Math.floor(E*g),p=C*f-d,m=E*g-u,x=4*(u*e+d),w=0;w<4;w++)r=P[x+w],o=P[x+4+w],h=P[x+k+w],l=P[x+k+4+w],v=r*(1-p)*(1-m)+o*p*(1-m)+h*m*(1-p)+l*p*m,R[S++]=v;return D}hermiteFastResize(t,e,s,i,n){const r=this.rcpScaleX,o=this.rcpScaleY,h=Math.ceil(r/2),l=Math.ceil(o/2),d=t.imageData.data,u=t.ctx.createImageData(i,n),g=u.data;for(let f=0;f<n;f++)for(let p=0;p<i;p++){const m=4*(p+f*i);let w=0,v=0,x=0,S=0,C=0,E=0,k=0;const P=(f+.5)*o;for(let D=Math.floor(f*o);D<(f+1)*o;D++){const R=Math.abs(P-(D+.5))/l,B=(p+.5)*r,O=R*R;for(let F=Math.floor(p*r);F<(p+1)*r;F++){let L=Math.abs(B-(F+.5))/h;const I=Math.sqrt(O+L*L);I>1&&I<-1||(w=2*I*I*I-3*I*I+1,w>0&&(L=4*(F+D*e),k+=w*d[L+3],x+=w,d[L+3]<255&&(w=w*d[L+3]/250),S+=w*d[L],C+=w*d[L+1],E+=w*d[L+2],v+=w))}}g[m]=S/v,g[m+1]=C/v,g[m+2]=E/v,g[m+3]=k/x}return u}}A(Kc,"type","Resize"),A(Kc,"defaults",{resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3}),A(Kc,"uniformLocations",["uDelta","uTaps"]),X.setClass(Kc);class Qc extends Ut{getFragmentSource(){return`
469
+ `)}applyToForWebgl(t){t.passes++,this.width=t.sourceWidth,this.horizontal=!0,this.dW=Math.round(this.width*this.scaleX),this.dH=t.sourceHeight,this.tempScale=this.dW/this.width,this.taps=this.getTaps(),t.destinationWidth=this.dW,super.applyTo(t),t.sourceWidth=t.destinationWidth,this.height=t.sourceHeight,this.horizontal=!1,this.dH=Math.round(this.height*this.scaleY),this.tempScale=this.dH/this.height,this.taps=this.getTaps(),t.destinationHeight=this.dH,super.applyTo(t),t.sourceHeight=t.destinationHeight}applyTo(t){Nc(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 l;l=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=l}sliceByTwo(t,e,s,i,n){const r=t.imageData,o=.5;let h=!1,l=!1,d=e*o,u=s*o;const g=t.filterBackend.resources;let f=0,p=0;const m=e;let _=0;g.sliceByTwo||(g.sliceByTwo=Rt());const v=g.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||!l;)e=d,s=u,i<Math.floor(d*o)?d=Math.floor(d*o):(d=i,h=!0),n<Math.floor(u*o)?u=Math.floor(u*o):(u=n,l=!0),x.drawImage(v,f,p,e,s,m,_,d,u),f=m,p=_,_+=u;return x.getImageData(f,p,i,n)}lanczosResize(t,e,s,i,n){const r=t.imageData.data,o=t.ctx.createImageData(i,n),h=o.data,l=this.lanczosCreate(this.lanczosLobes),d=this.rcpScaleX,u=this.rcpScaleY,g=2/this.rcpScaleX,f=2/this.rcpScaleY,p=Math.ceil(d*this.lanczosLobes/2),m=Math.ceil(u*this.lanczosLobes/2),_={},v={x:0,y:0},x={x:0,y:0};return function S(C){let E,M,k,O,P,L,F,W,B,z,K;for(v.x=(C+.5)*d,x.x=Math.floor(v.x),E=0;E<n;E++){for(v.y=(E+.5)*u,x.y=Math.floor(v.y),P=0,L=0,F=0,W=0,B=0,M=x.x-p;M<=x.x+p;M++)if(!(M<0||M>=e)){z=Math.floor(1e3*Math.abs(M-v.x)),_[z]||(_[z]={});for(let tt=x.y-m;tt<=x.y+m;tt++)tt<0||tt>=s||(K=Math.floor(1e3*Math.abs(tt-v.y)),_[z][K]||(_[z][K]=l(Math.sqrt(Math.pow(z*g,2)+Math.pow(K*f,2))/1e3)),k=_[z][K],k>0&&(O=4*(tt*e+M),P+=k,L+=k*r[O],F+=k*r[O+1],W+=k*r[O+2],B+=k*r[O+3]))}O=4*(E*i+C),h[O]=L/P,h[O+1]=F/P,h[O+2]=W/P,h[O+3]=B/P}return++C<i?S(C):o}(0)}bilinearFiltering(t,e,s,i,n){let r,o,h,l,d,u,g,f,p,m,_,v,x,S=0;const C=this.rcpScaleX,E=this.rcpScaleY,M=4*(e-1),k=t.imageData.data,O=t.ctx.createImageData(i,n),P=O.data;for(g=0;g<n;g++)for(f=0;f<i;f++)for(d=Math.floor(C*f),u=Math.floor(E*g),p=C*f-d,m=E*g-u,x=4*(u*e+d),_=0;_<4;_++)r=k[x+_],o=k[x+4+_],h=k[x+M+_],l=k[x+M+4+_],v=r*(1-p)*(1-m)+o*p*(1-m)+h*m*(1-p)+l*p*m,P[S++]=v;return O}hermiteFastResize(t,e,s,i,n){const r=this.rcpScaleX,o=this.rcpScaleY,h=Math.ceil(r/2),l=Math.ceil(o/2),d=t.imageData.data,u=t.ctx.createImageData(i,n),g=u.data;for(let f=0;f<n;f++)for(let p=0;p<i;p++){const m=4*(p+f*i);let _=0,v=0,x=0,S=0,C=0,E=0,M=0;const k=(f+.5)*o;for(let O=Math.floor(f*o);O<(f+1)*o;O++){const P=Math.abs(k-(O+.5))/l,L=(p+.5)*r,F=P*P;for(let W=Math.floor(p*r);W<(p+1)*r;W++){let B=Math.abs(L-(W+.5))/h;const z=Math.sqrt(F+B*B);z>1&&z<-1||(_=2*z*z*z-3*z*z+1,_>0&&(B=4*(W+O*e),M+=_*d[B+3],x+=_,d[B+3]<255&&(_=_*d[B+3]/250),S+=_*d[B],C+=_*d[B+1],E+=_*d[B+2],v+=_))}}g[m]=S/v,g[m+1]=C/v,g[m+2]=E/v,g[m+3]=M/x}return u}}A(Qc,"type","Resize"),A(Qc,"defaults",{resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3}),A(Qc,"uniformLocations",["uDelta","uTaps"]),N.setClass(Qc);class Jc extends Vt{getFragmentSource(){return`
470
470
  precision highp float;
471
471
  uniform sampler2D uTexture;
472
472
  uniform float uSaturation;
@@ -480,7 +480,7 @@ void main() {
480
480
  color.b += rgbMax != color.b ? (rgbMax - color.b) * uSaturation : 0.00;
481
481
  gl_FragColor = color;
482
482
  }
483
- `}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.saturation;for(let i=0;i<e.length;i+=4){const n=Math.max(e[i],e[i+1],e[i+2]);e[i]+=n!==e[i]?(n-e[i])*s:0,e[i+1]+=n!==e[i+1]?(n-e[i+1])*s:0,e[i+2]+=n!==e[i+2]?(n-e[i+2])*s:0}}sendUniformData(t,e){t.uniform1f(e.uSaturation,-this.saturation)}isNeutralState(){return this.saturation===0}}A(Qc,"type","Saturation"),A(Qc,"defaults",{saturation:0}),A(Qc,"uniformLocations",["uSaturation"]),X.setClass(Qc);class Jc extends Ut{getFragmentSource(){return`
483
+ `}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.saturation;for(let i=0;i<e.length;i+=4){const n=Math.max(e[i],e[i+1],e[i+2]);e[i]+=n!==e[i]?(n-e[i])*s:0,e[i+1]+=n!==e[i+1]?(n-e[i+1])*s:0,e[i+2]+=n!==e[i+2]?(n-e[i+2])*s:0}}sendUniformData(t,e){t.uniform1f(e.uSaturation,-this.saturation)}isNeutralState(){return this.saturation===0}}A(Jc,"type","Saturation"),A(Jc,"defaults",{saturation:0}),A(Jc,"uniformLocations",["uSaturation"]),N.setClass(Jc);class Zc extends Vt{getFragmentSource(){return`
484
484
  precision highp float;
485
485
  uniform sampler2D uTexture;
486
486
  uniform float uVibrance;
@@ -495,15 +495,15 @@ void main() {
495
495
  color.b += max != color.b ? (max - color.b) * amt : 0.00;
496
496
  gl_FragColor = color;
497
497
  }
498
- `}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.vibrance;for(let i=0;i<e.length;i+=4){const n=Math.max(e[i],e[i+1],e[i+2]),r=(e[i]+e[i+1]+e[i+2])/3,o=2*Math.abs(n-r)/255*s;e[i]+=n!==e[i]?(n-e[i])*o:0,e[i+1]+=n!==e[i+1]?(n-e[i+1])*o:0,e[i+2]+=n!==e[i+2]?(n-e[i+2])*o:0}}sendUniformData(t,e){t.uniform1f(e.uVibrance,-this.vibrance)}isNeutralState(){return this.vibrance===0}}A(Jc,"type","Vibrance"),A(Jc,"defaults",{vibrance:0}),A(Jc,"uniformLocations",["uVibrance"]),X.setClass(Jc);var lh={};lh.d=(a,t)=>{for(var e in t)lh.o(t,e)&&!lh.o(a,e)&&Object.defineProperty(a,e,{enumerable:!0,get:t[e]})},lh.o=(a,t)=>Object.prototype.hasOwnProperty.call(a,t);var Q=globalThis.pdfjsLib={};lh.d(Q,{AbortException:()=>lr,AnnotationEditorLayer:()=>$g,AnnotationEditorParamsType:()=>$,AnnotationEditorType:()=>tt,AnnotationEditorUIManager:()=>dr,AnnotationLayer:()=>tS,AnnotationMode:()=>fn,ColorPicker:()=>md,DOMSVGFactory:()=>Xg,DrawLayer:()=>Kg,FeatureTest:()=>ke,GlobalWorkerOptions:()=>ki,ImageKind:()=>Zc,InvalidPDFException:()=>n0,MissingPDFException:()=>hr,OPS:()=>Ts,OutputScale:()=>Cg,PDFDataRangeTransport:()=>j0,PDFDateString:()=>xg,PDFWorker:()=>Bo,PasswordResponses:()=>ow,PermissionFlag:()=>rw,PixelsPerInch:()=>mn,RenderingCancelledException:()=>_g,TextLayer:()=>bh,UnexpectedResponseException:()=>id,Util:()=>V,VerbosityLevel:()=>td,XfaLayer:()=>W0,build:()=>Fx,createValidAbsoluteUrl:()=>cw,fetchData:()=>rd,getDocument:()=>Ax,getFilenameFromUrl:()=>yw,getPdfFilenameFromUrl:()=>_w,getXfaPageViewport:()=>ww,isDataScheme:()=>od,isPdfFile:()=>wg,noContextMenu:()=>as,normalizeUnicode:()=>mw,setLayerDimensions:()=>cr,shadow:()=>ot,version:()=>Lx});const pe=typeof process=="object"&&process+""=="[object process]"&&!process.versions.nw&&!(process.versions.electron&&process.type&&process.type!=="browser"),i0=[1,0,0,1,0,0],ug=[.001,0,0,.001,0,0],iw=1e7,gg=1.35,Ye={ANY:1,DISPLAY:2,PRINT:4,SAVE:8,ANNOTATIONS_FORMS:16,ANNOTATIONS_STORAGE:32,ANNOTATIONS_DISABLE:64,IS_EDITING:128,OPLIST:256},fn={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},nw="pdfjs_internal_editor_",tt={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15},$={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},rw={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},me={FILL:0,STROKE:1,FILL_STROKE:2,INVISIBLE:3,FILL_ADD_TO_PATH:4,STROKE_ADD_TO_PATH:5,FILL_STROKE_ADD_TO_PATH:6,ADD_TO_PATH:7,FILL_STROKE_MASK:3,ADD_TO_PATH_FLAG:4},Zc={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},Yt={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,SOUND:18,MOVIE:19,WIDGET:20,SCREEN:21,PRINTERMARK:22,TRAPNET:23,WATERMARK:24,THREED:25,REDACT:26},ch={SOLID:1,DASHED:2,BEVELED:3,INSET:4,UNDERLINE:5},td={ERRORS:0,WARNINGS:1,INFOS:5},Ts={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},ow={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};let ed=td.WARNINGS;function aw(a){Number.isInteger(a)&&(ed=a)}function hw(){return ed}function sd(a){ed>=td.INFOS&&console.log(`Info: ${a}`)}function st(a){ed>=td.WARNINGS&&console.log(`Warning: ${a}`)}function wt(a){throw new Error(a)}function qt(a,t){a||wt(t)}function lw(a){switch(a==null?void 0:a.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}function cw(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=pw(a)}catch{}}const s=t?new URL(a,t):new URL(a);if(lw(s))return s}catch{}return null}function ot(a,t,e,s=!1){return Object.defineProperty(a,t,{value:e,enumerable:!s,configurable:!0,writable:!1}),e}const pn=function(){function t(e,s){this.message=e,this.name=s}return t.prototype=new Error,t.constructor=t,t}();class fg extends pn{constructor(t,e){super(t,"PasswordException"),this.code=e}}class pg extends pn{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}}class n0 extends pn{constructor(t){super(t,"InvalidPDFException")}}class hr extends pn{constructor(t){super(t,"MissingPDFException")}}class id extends pn{constructor(t,e){super(t,"UnexpectedResponseException"),this.status=e}}class dw extends pn{constructor(t){super(t,"FormatError")}}class lr extends pn{constructor(t){super(t,"AbortException")}}function r0(a){(typeof a!="object"||(a==null?void 0:a.length)===void 0)&&wt("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 nd(a){typeof a!="string"&&wt("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 uw(a){return String.fromCharCode(a>>24&255,a>>16&255,a>>8&255,a&255)}function mg(a){const t=Object.create(null);for(const[e,s]of a)t[e]=s;return t}function gw(){const a=new Uint8Array(4);return a[0]=1,new Uint32Array(a.buffer,0,1)[0]===1}function fw(){try{return new Function(""),!0}catch{return!1}}class ke{static get isLittleEndian(){return ot(this,"isLittleEndian",gw())}static get isEvalSupported(){return ot(this,"isEvalSupported",fw())}static get isOffscreenCanvasSupported(){return ot(this,"isOffscreenCanvasSupported",typeof OffscreenCanvas<"u")}static get platform(){return typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.platform)=="string"?ot(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")}):ot(this,"platform",{isMac:!1,isWindows:!1,isFirefox:!1})}static get isCSSRoundSupported(){var t,e;return ot(this,"isCSSRoundSupported",(e=(t=globalThis.CSS)==null?void 0:t.supports)==null?void 0:e.call(t,"width: round(1.5px, 1px)"))}}const bg=Array.from(Array(256).keys(),a=>a.toString(16).padStart(2,"0"));class V{static makeHexColor(t,e,s){return`#${bg[t]}${bg[e]}${bg[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,l=o+h||1,d=o-h||1;return[Math.sqrt(l),Math.sqrt(d)]}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,l){return l?(l[0]=Math.min(l[0],t,o),l[1]=Math.min(l[1],e,h),l[2]=Math.max(l[2],t,o),l[3]=Math.max(l[3],e,h)):l=[Math.min(t,o),Math.min(e,h),Math.max(t,o),Math.max(e,h)],y(this,Oi,ef).call(this,t,s,n,o,e,i,r,h,3*(-t+3*(s-n)+o),6*(t-2*s+n),3*(s-t),l),y(this,Oi,ef).call(this,t,s,n,o,e,i,r,h,3*(-e+3*(i-r)+h),6*(e-2*i+r),3*(i-e),l),l}}Oi=new WeakSet,jd=function(t,e,s,i,n,r,o,h,l,d){if(l<=0||l>=1)return;const u=1-l,g=l*l,f=g*l,p=u*(u*(u*t+3*l*e)+3*g*s)+f*i,m=u*(u*(u*n+3*l*r)+3*g*o)+f*h;d[0]=Math.min(d[0],p),d[1]=Math.min(d[1],m),d[2]=Math.max(d[2],p),d[3]=Math.max(d[3],m)},ef=function(t,e,s,i,n,r,o,h,l,d,u,g){if(Math.abs(l)<1e-12){Math.abs(d)>=1e-12&&y(this,Oi,jd).call(this,t,e,s,i,n,r,o,h,-u/d,g);return}const f=d**2-4*u*l;if(f<0)return;const p=Math.sqrt(f),m=2*l;y(this,Oi,jd).call(this,t,e,s,i,n,r,o,h,(-d+p)/m,g),y(this,Oi,jd).call(this,t,e,s,i,n,r,o,h,(-d-p)/m,g)},_(V,Oi);function pw(a){return decodeURIComponent(escape(a))}let vg=null,o0=null;function mw(a){return vg||(vg=/([\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,o0=new Map([["ſt","ſt"]])),a.replaceAll(vg,(t,e,s)=>e?e.normalize("NFKC"):o0.get(s))}function bw(){if(typeof crypto<"u"&&typeof(crypto==null?void 0:crypto.randomUUID)=="function")return crypto.randomUUID();const a=new Uint8Array(32);if(typeof crypto<"u"&&typeof(crypto==null?void 0:crypto.getRandomValues)=="function")crypto.getRandomValues(a);else for(let t=0;t<32;t++)a[t]=Math.floor(Math.random()*255);return r0(a)}const yg="pdfjs_internal_id_",Ai={BEZIER_CURVE_TO:0,MOVE_TO:1,LINE_TO:2,QUADRATIC_CURVE_TO:3,RESTORE:4,SAVE:5,SCALE:6,TRANSFORM:7,TRANSLATE:8};function vw(a){return Uint8Array.prototype.toBase64?a.toBase64():btoa(r0(a))}const Ti="http://www.w3.org/2000/svg",fr=class fr{};K(fr,"CSS",96),K(fr,"PDF",72),K(fr,"PDF_TO_CSS_UNITS",fr.CSS/fr.PDF);let mn=fr;async function rd(a,t="text"){if(uh(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 dh{constructor({viewBox:t,scale:e,rotation:s,offsetX:i=0,offsetY:n=0,dontFlip:r=!1}){this.viewBox=t,this.scale=e,this.rotation=s,this.offsetX=i,this.offsetY=n;const o=(t[2]+t[0])/2,h=(t[3]+t[1])/2;let l,d,u,g;switch(s%=360,s<0&&(s+=360),s){case 180:l=-1,d=0,u=0,g=1;break;case 90:l=0,d=1,u=1,g=0;break;case 270:l=0,d=-1,u=-1,g=0;break;case 0:l=1,d=0,u=0,g=-1;break;default:throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.")}r&&(u=-u,g=-g);let f,p,m,w;l===0?(f=Math.abs(h-t[1])*e+i,p=Math.abs(o-t[0])*e+n,m=(t[3]-t[1])*e,w=(t[2]-t[0])*e):(f=Math.abs(o-t[0])*e+i,p=Math.abs(h-t[1])*e+n,m=(t[2]-t[0])*e,w=(t[3]-t[1])*e),this.transform=[l*e,d*e,u*e,g*e,f-l*e*o-u*e*h,p-d*e*o-g*e*h],this.width=m,this.height=w}get rawDims(){const{viewBox:t}=this;return ot(this,"rawDims",{pageWidth:t[2]-t[0],pageHeight:t[3]-t[1],pageX:t[0],pageY:t[1]})}clone({scale:t=this.scale,rotation:e=this.rotation,offsetX:s=this.offsetX,offsetY:i=this.offsetY,dontFlip:n=!1}={}){return new dh({viewBox:this.viewBox.slice(),scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}convertToViewportPoint(t,e){return V.applyTransform([t,e],this.transform)}convertToViewportRectangle(t){const e=V.applyTransform([t[0],t[1]],this.transform),s=V.applyTransform([t[2],t[3]],this.transform);return[e[0],e[1],s[0],s[1]]}convertToPdfPoint(t,e){return V.applyInverseTransform([t,e],this.transform)}}class _g extends pn{constructor(t,e=0){super(t,"RenderingCancelledException"),this.extraDelay=e}}function od(a){const t=a.length;let e=0;for(;e<t&&a[e].trim()==="";)e++;return a.substring(e,e+5).toLowerCase()==="data:"}function wg(a){return typeof a=="string"&&/\.pdf$/i.test(a)}function yw(a){return[a]=a.split(/[#?]/,1),a.substring(a.lastIndexOf("/")+1)}function _w(a,t="document.pdf"){if(typeof a!="string")return t;if(od(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 a0{constructor(){K(this,"started",Object.create(null));K(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
499
- `);return t.join("")}}function uh(a,t){try{const{protocol:e}=t?new URL(a,t):new URL(a);return e==="http:"||e==="https:"}catch{return!1}}function as(a){a.preventDefault()}function h0(a){console.log("Deprecated API usage: "+a)}class xg{static toDateObject(t){if(!t||typeof t!="string")return null;c(this,wh)||b(this,wh,new RegExp("^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+|-])?(\\d{2})?'?(\\d{2})?'?"));const e=c(this,wh).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 l=e[7]||"Z";let d=parseInt(e[8],10);d=d>=0&&d<=23?d:0;let u=parseInt(e[9],10)||0;return u=u>=0&&u<=59?u:0,l==="-"?(r+=d,o+=u):l==="+"&&(r-=d,o-=u),new Date(Date.UTC(s,i,n,r,o,h))}}wh=new WeakMap,_(xg,wh);function ww(a,{scale:t=1,rotation:e=0}){const{width:s,height:i}=a.attributes.style,n=[0,0,parseInt(s),parseInt(i)];return new dh({viewBox:n,scale:t,rotation:e})}function Sg(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 xw(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,Sg(s))}t.remove()}function Et(a){const{a:t,b:e,c:s,d:i,e:n,f:r}=a.getTransform();return[t,e,s,i,n,r]}function Ei(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 cr(a,t,e=!1,s=!0){if(t instanceof dh){const{pageWidth:i,pageHeight:n}=t.rawDims,{style:r}=a,o=ke.isCSSRoundSupported,h=`var(--scale-factor) * ${i}px`,l=`var(--scale-factor) * ${n}px`,d=o?`round(down, ${h}, var(--scale-round-x, 1px))`:`calc(${h})`,u=o?`round(down, ${l}, var(--scale-round-y, 1px))`:`calc(${l})`;!e||t.rotation%180===0?(r.width=d,r.height=u):(r.width=u,r.height=d)}s&&a.setAttribute("data-main-rotation",t.rotation)}class Cg{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 Di=class Di{constructor(t){_(this,Oe);_(this,vn,null);_(this,pr,null);_(this,Es);_(this,mr,null);_(this,xh,null);b(this,Es,t),c(Di,Sh)||b(Di,Sh,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=b(this,vn,document.createElement("div"));t.classList.add("editToolbar","hidden"),t.setAttribute("role","toolbar");const e=c(this,Es)._uiManager._signal;t.addEventListener("contextmenu",as,{signal:e}),t.addEventListener("pointerdown",y(Di,yd,eb),{signal:e});const s=b(this,mr,document.createElement("div"));s.className="buttons",t.append(s);const i=c(this,Es).toolbarPosition;if(i){const{style:n}=t,r=c(this,Es)._uiManager.direction==="ltr"?1-i[0]:i[0];n.insetInlineEnd=`${100*r}%`,n.top=`calc(${100*i[1]}% + var(--editor-toolbar-vert-offset))`}return y(this,Oe,nb).call(this),t}get div(){return c(this,vn)}hide(){var t;c(this,vn).classList.add("hidden"),(t=c(this,pr))==null||t.hideDropdown()}show(){var t;c(this,vn).classList.remove("hidden"),(t=c(this,xh))==null||t.shown()}async addAltText(t){const e=await t.render();y(this,Oe,Nd).call(this,e),c(this,mr).prepend(e,c(this,Oe,sf)),b(this,xh,t)}addColorPicker(t){b(this,pr,t);const e=t.renderButton();y(this,Oe,Nd).call(this,e),c(this,mr).prepend(e,c(this,Oe,sf))}remove(){var t;c(this,vn).remove(),(t=c(this,pr))==null||t.destroy(),b(this,pr,null)}};vn=new WeakMap,pr=new WeakMap,Es=new WeakMap,mr=new WeakMap,xh=new WeakMap,Sh=new WeakMap,yd=new WeakSet,eb=function(t){t.stopPropagation()},Oe=new WeakSet,sb=function(t){c(this,Es)._focusEventsAllowed=!1,t.preventDefault(),t.stopPropagation()},ib=function(t){c(this,Es)._focusEventsAllowed=!0,t.preventDefault(),t.stopPropagation()},Nd=function(t){const e=c(this,Es)._uiManager._signal;t.addEventListener("focusin",y(this,Oe,sb).bind(this),{capture:!0,signal:e}),t.addEventListener("focusout",y(this,Oe,ib).bind(this),{capture:!0,signal:e}),t.addEventListener("contextmenu",as,{signal:e})},nb=function(){const{editorType:t,_uiManager:e}=c(this,Es),s=document.createElement("button");s.className="delete",s.tabIndex=0,s.setAttribute("data-l10n-id",c(Di,Sh)[t]),y(this,Oe,Nd).call(this,s),s.addEventListener("click",i=>{e.delete()},{signal:e._signal}),c(this,mr).append(s)},sf=function(){const t=document.createElement("div");return t.className="divider",t},_(Di,yd),_(Di,Sh,null);let Ag=Di;class Sw{constructor(t){_(this,yn);_(this,Ch,null);_(this,br,null);_(this,vr);b(this,vr,t)}show(t,e,s){const[i,n]=y(this,yn,ob).call(this,e,s),{style:r}=c(this,br)||b(this,br,y(this,yn,rb).call(this));t.append(c(this,br)),r.insetInlineEnd=`${100*i}%`,r.top=`calc(${100*n}% + var(--editor-toolbar-vert-offset))`}hide(){c(this,br).remove()}}Ch=new WeakMap,br=new WeakMap,vr=new WeakMap,yn=new WeakSet,rb=function(){const t=b(this,br,document.createElement("div"));t.className="editToolbar",t.setAttribute("role","toolbar"),t.addEventListener("contextmenu",as,{signal:c(this,vr)._signal});const e=b(this,Ch,document.createElement("div"));return e.className="buttons",t.append(e),y(this,yn,ab).call(this),t},ob=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]},ab=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=c(this,vr)._signal;t.addEventListener("contextmenu",as,{signal:s}),t.addEventListener("click",()=>{c(this,vr).highlightSelection("floating_button")},{signal:s}),c(this,Ch).append(t)};function ad(a,t,e){for(const s of e)t.addEventListener(s,a[s].bind(a))}function Cw(a){return Math.round(Math.min(255,Math.max(1,255*a))).toString(16).padStart(2,"0")}class Aw{constructor(){_(this,_d,0)}get id(){return`${nw}${Fe(this,_d)._++}`}}_d=new WeakMap;const Qg=class Qg{constructor(){_(this,Wo);_(this,Ho,bw());_(this,Ah,0);_(this,be,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 ot(this,"_isSVGFittingCanvas",n)}async getFromFile(t){const{lastModified:e,name:s,size:i,type:n}=t;return y(this,Wo,Bd).call(this,`${e}_${s}_${i}_${n}`,t)}async getFromUrl(t){return y(this,Wo,Bd).call(this,t,t)}async getFromBlob(t,e){const s=await e;return y(this,Wo,Bd).call(this,t,s)}async getFromId(t){c(this,be)||b(this,be,new Map);const e=c(this,be).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){c(this,be)||b(this,be,new Map);let s=c(this,be).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_${c(this,Ho)}_${Fe(this,Ah)._++}`,refCounter:1,isSvg:!1},c(this,be).set(t,s),c(this,be).set(s.id,s),s}getSvgUrl(t){const e=c(this,be).get(t);return e!=null&&e.isSvg?e.svgUrl:null}deleteId(t){var i;c(this,be)||b(this,be,new Map);const e=c(this,be).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_${c(this,Ho)}_`)}};Ho=new WeakMap,Ah=new WeakMap,be=new WeakMap,Wo=new WeakSet,Bd=async function(t,e){c(this,be)||b(this,be,new Map);let s=c(this,be).get(t);if(s===null)return null;if(s!=null&&s.bitmap)return s.refCounter+=1,s;try{s||(s={bitmap:null,id:`image_${c(this,Ho)}_${Fe(this,Ah)._++}`,refCounter:0,isSvg:!1});let i;if(typeof e=="string"?(s.url=e,i=await rd(e,"blob")):e instanceof File?i=s.file=e:e instanceof Blob&&(i=e),i.type==="image/svg+xml"){const n=Qg._isSVGFittingCanvas,r=new FileReader,o=new Image,h=new Promise((l,d)=>{o.onload=()=>{s.bitmap=o,s.isSvg=!0,l()},r.onload=async()=>{const u=s.svgUrl=r.result;o.src=await n?`${u}#svgView(preserveAspectRatio(none))`:u},o.onerror=r.onerror=d});r.readAsDataURL(i),await h}else s.bitmap=await createImageBitmap(i);s.refCounter=1}catch(i){console.error(i),s=null}return c(this,be).set(t,s),s&&c(this,be).set(s.id,s),s};let Tg=Qg;class Tw{constructor(t=128){_(this,ee,[]);_(this,_n,!1);_(this,Th);_(this,se,-1);b(this,Th,t)}add({cmd:t,undo:e,post:s,mustExec:i,type:n=NaN,overwriteIfSameType:r=!1,keepUndo:o=!1}){if(i&&t(),c(this,_n))return;const h={cmd:t,undo:e,post:s,type:n};if(c(this,se)===-1){c(this,ee).length>0&&(c(this,ee).length=0),b(this,se,0),c(this,ee).push(h);return}if(r&&c(this,ee)[c(this,se)].type===n){o&&(h.undo=c(this,ee)[c(this,se)].undo),c(this,ee)[c(this,se)]=h;return}const l=c(this,se)+1;l===c(this,Th)?c(this,ee).splice(0,1):(b(this,se,l),l<c(this,ee).length&&c(this,ee).splice(l)),c(this,ee).push(h)}undo(){if(c(this,se)===-1)return;b(this,_n,!0);const{undo:t,post:e}=c(this,ee)[c(this,se)];t(),e==null||e(),b(this,_n,!1),b(this,se,c(this,se)-1)}redo(){if(c(this,se)<c(this,ee).length-1){b(this,se,c(this,se)+1),b(this,_n,!0);const{cmd:t,post:e}=c(this,ee)[c(this,se)];t(),e==null||e(),b(this,_n,!1)}}hasSomethingToUndo(){return c(this,se)!==-1}hasSomethingToRedo(){return c(this,se)<c(this,ee).length-1}destroy(){b(this,ee,null)}}ee=new WeakMap,_n=new WeakMap,Th=new WeakMap,se=new WeakMap;class gh{constructor(t){_(this,wd);this.buffer=[],this.callbacks=new Map,this.allKeys=new Set;const{isMac:e}=ke.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(y(this,wd,hb).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||(e.stopPropagation(),e.preventDefault()))}}wd=new WeakSet,hb=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 xd=class xd{get _colors(){const t=new Map([["CanvasText",null],["Canvas",null]]);return xw(t),ot(this,"_colors",t)}convert(t){const e=Sg(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 xd._colorsMapping.get(s);return e}getHexCode(t){const e=this._colors.get(t);return e?V.makeHexColor(...e):t}};K(xd,"_colorsMapping",new Map([["CanvasText",[0,0,0]],["Canvas",[255,255,255]]]));let Eg=xd;const qo=class qo{constructor(t,e,s,i,n,r,o,h,l,d,u){_(this,N);_(this,Xo,new AbortController);_(this,$e,null);_(this,$t,new Map);_(this,oe,new Map);_(this,zo,null);_(this,Pi,null);_(this,Vo,null);_(this,ks,new Tw);_(this,wn,null);_(this,Go,0);_(this,yr,new Set);_(this,$s,null);_(this,Ms,null);_(this,_r,new Set);_(this,Eh,!1);_(this,kh,!1);_(this,Uo,!1);_(this,Mh,null);_(this,Ks,null);_(this,xn,null);_(this,Yo,null);_(this,Sn,!1);_(this,Qs,null);_(this,Sd,new Aw);_(this,Cn,!1);_(this,Oh,!1);_(this,An,null);_(this,wr,null);_(this,Dh,null);_(this,Ph,null);_(this,ie,tt.NONE);_(this,ft,new Set);_(this,Li,null);_(this,xr,null);_(this,Lh,null);_(this,Fh,{isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1});_(this,Tn,[0,0]);_(this,Js,null);_(this,Fi,null);_(this,Rh,null);_(this,cs,null);const g=this._signal=c(this,Xo).signal;b(this,Fi,t),b(this,Rh,e),b(this,zo,s),this._eventBus=i,i._on("editingaction",this.onEditingAction.bind(this),{signal:g}),i._on("pagechanging",this.onPageChanging.bind(this),{signal:g}),i._on("scalechanging",this.onScaleChanging.bind(this),{signal:g}),i._on("rotationchanging",this.onRotationChanging.bind(this),{signal:g}),i._on("setpreference",this.onSetPreference.bind(this),{signal:g}),i._on("switchannotationeditorparams",f=>this.updateParams(f.type,f.value),{signal:g}),y(this,N,db).call(this),y(this,N,pb).call(this),y(this,N,rf).call(this),b(this,Pi,n.annotationStorage),b(this,Mh,n.filterFactory),b(this,xr,r),b(this,Yo,o||null),b(this,Eh,h),b(this,kh,l),b(this,Uo,d),b(this,Ph,u||null),this.viewParameters={realScale:mn.PDF_TO_CSS_UNITS,rotation:0},this.isShiftKeyDown=!1}static get _keyboardManager(){const t=qo.prototype,e=r=>c(r,Fi).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 ot(this,"_keyboardManager",new gh([[["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)&&c(r,Fi).contains(o)&&!r.isEnterHandled}],[[" ","mac+ "],t.addNewEditorFromKeyboard,{checker:(r,{target:o})=>!(o instanceof HTMLButtonElement)&&c(r,Fi).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;(t=c(this,cs))==null||t.resolve(),b(this,cs,null),(e=c(this,Xo))==null||e.abort(),b(this,Xo,null),this._signal=null;for(const n of c(this,oe).values())n.destroy();c(this,oe).clear(),c(this,$t).clear(),c(this,_r).clear(),b(this,$e,null),c(this,ft).clear(),c(this,ks).destroy(),(s=c(this,zo))==null||s.destroy(),(i=c(this,Qs))==null||i.hide(),b(this,Qs,null),c(this,Ks)&&(clearTimeout(c(this,Ks)),b(this,Ks,null)),c(this,Js)&&(clearTimeout(c(this,Js)),b(this,Js,null))}combinedSignal(t){return AbortSignal.any([this._signal,t.signal])}get mlManager(){return c(this,Ph)}get useNewAltTextFlow(){return c(this,kh)}get useNewAltTextWhenAddingImage(){return c(this,Uo)}get hcmFilter(){return ot(this,"hcmFilter",c(this,xr)?c(this,Mh).addHCMFilter(c(this,xr).foreground,c(this,xr).background):"none")}get direction(){return ot(this,"direction",getComputedStyle(c(this,Fi)).direction)}get highlightColors(){return ot(this,"highlightColors",c(this,Yo)?new Map(c(this,Yo).split(",").map(t=>t.split("=").map(e=>e.trim()))):null)}get highlightColorNames(){return ot(this,"highlightColorNames",this.highlightColors?new Map(Array.from(this.highlightColors,t=>t.reverse())):null)}setMainHighlightColorPicker(t){b(this,Dh,t)}editAltText(t,e=!1){var s;(s=c(this,zo))==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":b(this,Uo,e);break}}onPageChanging({pageNumber:t}){b(this,Go,t-1)}focusMainContainer(){c(this,Fi).focus()}findParent(t,e){for(const s of c(this,oe).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){c(this,Rh).classList.toggle("noUserSelect",t)}addShouldRescale(t){c(this,_r).add(t)}removeShouldRescale(t){c(this,_r).delete(t)}onScaleChanging({scale:t}){this.commitOrRemove(),this.viewParameters.realScale=t*mn.PDF_TO_CSS_UNITS;for(const e of c(this,_r))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(),l=y(this,N,Hd).call(this,e).closest(".textLayer"),d=this.getSelectionBoxes(l);if(!d)return;e.empty();const u=y(this,N,nf).call(this,l),g=c(this,ie)===tt.NONE,f=()=>{u==null||u.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:t,boxes:d,anchorNode:s,anchorOffset:i,focusNode:n,focusOffset:r,text:o}),g&&this.showAllEditors("highlight",!0,!0)};if(g){this.switchToMode(tt.HIGHLIGHT,f);return}f()}addToAnnotationStorage(t){!t.isEmpty()&&c(this,Pi)&&!c(this,Pi).has(t.id)&&c(this,Pi).setValue(t.id,t)}blur(){if(this.isShiftKeyDown=!1,c(this,Sn)&&(b(this,Sn,!1),y(this,N,Wd).call(this,"main_toolbar")),!this.hasSelection)return;const{activeElement:t}=document;for(const e of c(this,ft))if(e.div.contains(t)){b(this,wr,[e,t]),e._focusEventsAllowed=!1;break}}focus(){if(!c(this,wr))return;const[t,e]=c(this,wr);b(this,wr,null),e.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this._signal}),e.focus()}addEditListeners(){y(this,N,rf).call(this),y(this,N,of).call(this)}removeEditListeners(){y(this,N,fb).call(this),y(this,N,af).call(this)}dragOver(t){for(const{type:e}of t.dataTransfer.items)for(const s of c(this,Ms))if(s.isHandlingMimeForPasting(e)){t.dataTransfer.dropEffect="copy",t.preventDefault();return}}drop(t){for(const e of t.dataTransfer.items)for(const s of c(this,Ms))if(s.isHandlingMimeForPasting(e.type)){s.paste(e,this.currentLayer),t.preventDefault();return}}copy(t){var s;if(t.preventDefault(),(s=c(this,$e))==null||s.commitOrRemove(),!this.hasSelection)return;const e=[];for(const i of c(this,ft)){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 c(this,Ms))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 l=await i.deserialize(h);if(!l)return;n.push(l)}const r=()=>{for(const h of n)y(this,N,hf).call(this,h);y(this,N,lf).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),c(this,ie)!==tt.NONE&&!this.isEditorHandlingKeyboard&&qo._keyboardManager.exec(this,t)}keyup(t){this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!1,c(this,Sn)&&(b(this,Sn,!1),y(this,N,Wd).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?(y(this,N,ub).call(this),y(this,N,of).call(this),y(this,N,Re).call(this,{isEditing:c(this,ie)!==tt.NONE,isEmpty:y(this,N,jl).call(this),hasSomethingToUndo:c(this,ks).hasSomethingToUndo(),hasSomethingToRedo:c(this,ks).hasSomethingToRedo(),hasSelectedEditor:!1})):(y(this,N,gb).call(this),y(this,N,af).call(this),y(this,N,Re).call(this,{isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(t){if(!c(this,Ms)){b(this,Ms,t);for(const e of c(this,Ms))y(this,N,Yn).call(this,e.defaultPropertiesToUpdate)}}getId(){return c(this,Sd).id}get currentLayer(){return c(this,oe).get(c(this,Go))}getLayer(t){return c(this,oe).get(t)}get currentPageIndex(){return c(this,Go)}addLayer(t){c(this,oe).set(t.pageIndex,t),c(this,Cn)?t.enable():t.disable()}removeLayer(t){c(this,oe).delete(t.pageIndex)}async updateMode(t,e=null,s=!1){if(c(this,ie)!==t&&!(c(this,cs)&&(await c(this,cs).promise,!c(this,cs)))){if(b(this,cs,Promise.withResolvers()),b(this,ie,t),t===tt.NONE){this.setEditingState(!1),y(this,N,bb).call(this),c(this,cs).resolve();return}this.setEditingState(!0),await y(this,N,mb).call(this),this.unselectAll();for(const i of c(this,oe).values())i.updateMode(t);if(!e){s&&this.addNewEditorFromKeyboard(),c(this,cs).resolve();return}for(const i of c(this,$t).values())i.annotationElementId===e?(this.setSelected(i),i.enterInEditMode()):i.unselect();c(this,cs).resolve()}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(t){t!==c(this,ie)&&this._eventBus.dispatch("switchannotationeditormode",{source:this,mode:t})}updateParams(t,e){var s;if(c(this,Ms)){switch(t){case $.CREATE:this.currentLayer.addNewEditor();return;case $.HIGHLIGHT_DEFAULT_COLOR:(s=c(this,Dh))==null||s.updateColor(e);break;case $.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:{type:"highlight",action:"toggle_visibility"}}}),(c(this,Lh)||b(this,Lh,new Map)).set(t,e),this.showAllEditors("highlight",e);break}for(const i of c(this,ft))i.updateParams(t,e);for(const i of c(this,Ms))i.updateDefaultParams(t,e)}}showAllEditors(t,e,s=!1){var n;for(const r of c(this,$t).values())r.editorType===t&&r.show(e);(((n=c(this,Lh))==null?void 0:n.get($.HIGHLIGHT_SHOW_ALL))??!0)!==e&&y(this,N,Yn).call(this,[[$.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(c(this,Oh)!==t){b(this,Oh,t);for(const e of c(this,oe).values())t?e.disableClick():e.enableClick(),e.div.classList.toggle("waiting",t)}}getEditors(t){const e=[];for(const s of c(this,$t).values())s.pageIndex===t&&e.push(s);return e}getEditor(t){return c(this,$t).get(t)}addEditor(t){c(this,$t).set(t.id,t)}removeEditor(t){var e;t.div.contains(document.activeElement)&&(c(this,Ks)&&clearTimeout(c(this,Ks)),b(this,Ks,setTimeout(()=>{this.focusMainContainer(),b(this,Ks,null)},0))),c(this,$t).delete(t.id),this.unselect(t),(!t.annotationElementId||!c(this,yr).has(t.annotationElementId))&&((e=c(this,Pi))==null||e.remove(t.id))}addDeletedAnnotationElement(t){c(this,yr).add(t.annotationElementId),this.addChangedExistingAnnotation(t),t.deleted=!0}isDeletedAnnotationElement(t){return c(this,yr).has(t)}removeDeletedAnnotationElement(t){c(this,yr).delete(t.annotationElementId),this.removeChangedExistingAnnotation(t),t.deleted=!1}setActiveEditor(t){c(this,$e)!==t&&(b(this,$e,t),t&&y(this,N,Yn).call(this,t.propertiesToUpdate))}updateUI(t){c(this,N,vb)===t&&y(this,N,Yn).call(this,t.propertiesToUpdate)}toggleSelected(t){if(c(this,ft).has(t)){c(this,ft).delete(t),t.unselect(),y(this,N,Re).call(this,{hasSelectedEditor:this.hasSelection});return}c(this,ft).add(t),t.select(),y(this,N,Yn).call(this,t.propertiesToUpdate),y(this,N,Re).call(this,{hasSelectedEditor:!0})}setSelected(t){for(const e of c(this,ft))e!==t&&e.unselect();c(this,ft).clear(),c(this,ft).add(t),t.select(),y(this,N,Yn).call(this,t.propertiesToUpdate),y(this,N,Re).call(this,{hasSelectedEditor:!0})}isSelected(t){return c(this,ft).has(t)}get firstSelectedEditor(){return c(this,ft).values().next().value}unselect(t){t.unselect(),c(this,ft).delete(t),y(this,N,Re).call(this,{hasSelectedEditor:this.hasSelection})}get hasSelection(){return c(this,ft).size!==0}get isEnterHandled(){return c(this,ft).size===1&&this.firstSelectedEditor.isEnterHandled}undo(){c(this,ks).undo(),y(this,N,Re).call(this,{hasSomethingToUndo:c(this,ks).hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:y(this,N,jl).call(this)})}redo(){c(this,ks).redo(),y(this,N,Re).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:c(this,ks).hasSomethingToRedo(),isEmpty:y(this,N,jl).call(this)})}addCommands(t){c(this,ks).add(t),y(this,N,Re).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:y(this,N,jl).call(this)})}delete(){if(this.commitOrRemove(),!this.hasSelection)return;const t=[...c(this,ft)],e=()=>{for(const i of t)i.remove()},s=()=>{for(const i of t)y(this,N,hf).call(this,i)};this.addCommands({cmd:e,undo:s,mustExec:!0})}commitOrRemove(){var t;(t=c(this,$e))==null||t.commitOrRemove()}hasSomethingToControl(){return c(this,$e)||this.hasSelection}selectAll(){for(const t of c(this,ft))t.commit();y(this,N,lf).call(this,c(this,$t).values())}unselectAll(){if(!(c(this,$e)&&(c(this,$e).commitOrRemove(),c(this,ie)!==tt.NONE))&&this.hasSelection){for(const t of c(this,ft))t.unselect();c(this,ft).clear(),y(this,N,Re).call(this,{hasSelectedEditor:!1})}}translateSelectedEditors(t,e,s=!1){if(s||this.commitOrRemove(),!this.hasSelection)return;c(this,Tn)[0]+=t,c(this,Tn)[1]+=e;const[i,n]=c(this,Tn),r=[...c(this,ft)],o=1e3;c(this,Js)&&clearTimeout(c(this,Js)),b(this,Js,setTimeout(()=>{b(this,Js,null),c(this,Tn)[0]=c(this,Tn)[1]=0,this.addCommands({cmd:()=>{for(const h of r)c(this,$t).has(h.id)&&h.translateInPage(i,n)},undo:()=>{for(const h of r)c(this,$t).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),b(this,$s,new Map);for(const t of c(this,ft))c(this,$s).set(t,{savedX:t.x,savedY:t.y,savedPageIndex:t.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!c(this,$s))return!1;this.disableUserSelect(!1);const t=c(this,$s);b(this,$s,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(c(this,$t).has(i.id)){const h=c(this,oe).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(c(this,$s))for(const s of c(this,$s).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())||c(this,ft).size===1&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(t){return c(this,$e)===t}getActive(){return c(this,$e)}getMode(){return c(this,ie)}get imageManager(){return ot(this,"imageManager",new Tg)}getSelectionBoxes(t){if(!t)return null;const e=document.getSelection();for(let l=0,d=e.rangeCount;l<d;l++)if(!t.contains(e.getRangeAt(l).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=(l,d,u,g)=>({x:(d-i)/r,y:1-(l+u-s)/n,width:g/r,height:u/n});break;case"180":o=(l,d,u,g)=>({x:1-(l+u-s)/n,y:1-(d+g-i)/r,width:u/n,height:g/r});break;case"270":o=(l,d,u,g)=>({x:1-(d+g-i)/r,y:(l-s)/n,width:g/r,height:u/n});break;default:o=(l,d,u,g)=>({x:(l-s)/n,y:(d-i)/r,width:u/n,height:g/r});break}const h=[];for(let l=0,d=e.rangeCount;l<d;l++){const u=e.getRangeAt(l);if(!u.collapsed)for(const{x:g,y:f,width:p,height:m}of u.getClientRects())p===0||m===0||h.push(o(g,f,p,m))}return h.length===0?null:h}addChangedExistingAnnotation({annotationElementId:t,id:e}){(c(this,Vo)||b(this,Vo,new Map)).set(t,e)}removeChangedExistingAnnotation({annotationElementId:t}){var e;(e=c(this,Vo))==null||e.delete(t)}renderAnnotationElement(t){var i;const e=(i=c(this,Vo))==null?void 0:i.get(t.data.id);if(!e)return;const s=c(this,Pi).getRawValue(e);s&&(c(this,ie)===tt.NONE&&!s.hasBeenModified||s.renderAnnotationElement(t))}};Xo=new WeakMap,$e=new WeakMap,$t=new WeakMap,oe=new WeakMap,zo=new WeakMap,Pi=new WeakMap,Vo=new WeakMap,ks=new WeakMap,wn=new WeakMap,Go=new WeakMap,yr=new WeakMap,$s=new WeakMap,Ms=new WeakMap,_r=new WeakMap,Eh=new WeakMap,kh=new WeakMap,Uo=new WeakMap,Mh=new WeakMap,Ks=new WeakMap,xn=new WeakMap,Yo=new WeakMap,Sn=new WeakMap,Qs=new WeakMap,Sd=new WeakMap,Cn=new WeakMap,Oh=new WeakMap,An=new WeakMap,wr=new WeakMap,Dh=new WeakMap,Ph=new WeakMap,ie=new WeakMap,ft=new WeakMap,Li=new WeakMap,xr=new WeakMap,Lh=new WeakMap,Fh=new WeakMap,Tn=new WeakMap,Js=new WeakMap,Fi=new WeakMap,Rh=new WeakMap,cs=new WeakMap,N=new WeakSet,Hd=function({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t},nf=function(t){const{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(const s of c(this,oe).values())if(s.hasTextLayer(t))return s;return null},lb=function(){const t=document.getSelection();if(!t||t.isCollapsed)return;const s=y(this,N,Hd).call(this,t).closest(".textLayer"),i=this.getSelectionBoxes(s);i&&(c(this,Qs)||b(this,Qs,new Sw(this)),c(this,Qs).show(s,i,this.direction==="ltr"))},cb=function(){var n,r,o;const t=document.getSelection();if(!t||t.isCollapsed){c(this,Li)&&((n=c(this,Qs))==null||n.hide(),b(this,Li,null),y(this,N,Re).call(this,{hasSelectedText:!1}));return}const{anchorNode:e}=t;if(e===c(this,Li))return;const i=y(this,N,Hd).call(this,t).closest(".textLayer");if(!i){c(this,Li)&&((r=c(this,Qs))==null||r.hide(),b(this,Li,null),y(this,N,Re).call(this,{hasSelectedText:!1}));return}if((o=c(this,Qs))==null||o.hide(),b(this,Li,e),y(this,N,Re).call(this,{hasSelectedText:!0}),!(c(this,ie)!==tt.HIGHLIGHT&&c(this,ie)!==tt.NONE)&&(c(this,ie)===tt.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0),b(this,Sn,this.isShiftKeyDown),!this.isShiftKeyDown)){const h=c(this,ie)===tt.HIGHLIGHT?y(this,N,nf).call(this,i):null;h==null||h.toggleDrawing();const l=new AbortController,d=this.combinedSignal(l),u=g=>{g.type==="pointerup"&&g.button!==0||(l.abort(),h==null||h.toggleDrawing(!0),g.type==="pointerup"&&y(this,N,Wd).call(this,"main_toolbar"))};window.addEventListener("pointerup",u,{signal:d}),window.addEventListener("blur",u,{signal:d})}},Wd=function(t=""){c(this,ie)===tt.HIGHLIGHT?this.highlightSelection(t):c(this,Eh)&&y(this,N,lb).call(this)},db=function(){document.addEventListener("selectionchange",y(this,N,cb).bind(this),{signal:this._signal})},ub=function(){if(c(this,xn))return;b(this,xn,new AbortController);const t=this.combinedSignal(c(this,xn));window.addEventListener("focus",this.focus.bind(this),{signal:t}),window.addEventListener("blur",this.blur.bind(this),{signal:t})},gb=function(){var t;(t=c(this,xn))==null||t.abort(),b(this,xn,null)},rf=function(){if(c(this,An))return;b(this,An,new AbortController);const t=this.combinedSignal(c(this,An));window.addEventListener("keydown",this.keydown.bind(this),{signal:t}),window.addEventListener("keyup",this.keyup.bind(this),{signal:t})},fb=function(){var t;(t=c(this,An))==null||t.abort(),b(this,An,null)},of=function(){if(c(this,wn))return;b(this,wn,new AbortController);const t=this.combinedSignal(c(this,wn));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})},af=function(){var t;(t=c(this,wn))==null||t.abort(),b(this,wn,null)},pb=function(){const t=this._signal;document.addEventListener("dragover",this.dragOver.bind(this),{signal:t}),document.addEventListener("drop",this.drop.bind(this),{signal:t})},Re=function(t){Object.entries(t).some(([s,i])=>c(this,Fh)[s]!==i)&&(this._eventBus.dispatch("annotationeditorstateschanged",{source:this,details:Object.assign(c(this,Fh),t)}),c(this,ie)===tt.HIGHLIGHT&&t.hasSelectedEditor===!1&&y(this,N,Yn).call(this,[[$.HIGHLIGHT_FREE,!0]]))},Yn=function(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})},mb=async function(){if(!c(this,Cn)){b(this,Cn,!0);const t=[];for(const e of c(this,oe).values())t.push(e.enable());await Promise.all(t);for(const e of c(this,$t).values())e.enable()}},bb=function(){if(this.unselectAll(),c(this,Cn)){b(this,Cn,!1);for(const t of c(this,oe).values())t.disable();for(const t of c(this,$t).values())t.disable()}},hf=function(t){const e=c(this,oe).get(t.pageIndex);e?e.addOrRebuild(t):(this.addEditor(t),this.addToAnnotationStorage(t))},vb=function(){let t=null;for(t of c(this,ft));return t},jl=function(){if(c(this,$t).size===0)return!0;if(c(this,$t).size===1)for(const t of c(this,$t).values())return t.isEmpty();return!1},lf=function(t){for(const e of c(this,ft))e.unselect();c(this,ft).clear();for(const e of t)e.isEmpty()||(c(this,ft).add(e),e.select());y(this,N,Re).call(this,{hasSelectedEditor:this.hasSelection})},K(qo,"TRANSLATE_SMALL",1),K(qo,"TRANSLATE_BIG",10);let dr=qo;const De=class De{constructor(t){_(this,Ds);_(this,ne,null);_(this,Zs,!1);_(this,Os,null);_(this,$o,null);_(this,ti,null);_(this,Ke,null);_(this,Ko,!1);_(this,ei,null);_(this,He,null);_(this,Ri,null);_(this,Sr,null);_(this,si,!1);b(this,He,t),b(this,si,t._uiManager.useNewAltTextFlow),c(De,En)||b(De,En,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){De._l10n??(De._l10n=t)}async render(){const t=b(this,Os,document.createElement("button"));t.className="altText",t.tabIndex="0";const e=b(this,$o,document.createElement("span"));t.append(e),c(this,si)?(t.classList.add("new"),t.setAttribute("data-l10n-id",c(De,En).missing),e.setAttribute("data-l10n-id",c(De,En)["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=c(this,He)._uiManager._signal;t.addEventListener("contextmenu",as,{signal:s}),t.addEventListener("pointerdown",n=>n.stopPropagation(),{signal:s});const i=n=>{n.preventDefault(),c(this,He)._uiManager.editAltText(c(this,He)),c(this,si)&&c(this,He)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_clicked",data:{label:c(this,Ds,Nl)}})};return t.addEventListener("click",i,{capture:!0,signal:s}),t.addEventListener("keydown",n=>{n.target===t&&n.key==="Enter"&&(b(this,Ko,!0),i(n))},{signal:s}),await y(this,Ds,Xd).call(this),t}finish(){c(this,Os)&&(c(this,Os).focus({focusVisible:c(this,Ko)}),b(this,Ko,!1))}isEmpty(){return c(this,si)?c(this,ne)===null:!c(this,ne)&&!c(this,Zs)}hasData(){return c(this,si)?c(this,ne)!==null||!!c(this,Ri):this.isEmpty()}get guessedText(){return c(this,Ri)}async setGuessedText(t){c(this,ne)===null&&(b(this,Ri,t),b(this,Sr,await De._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",{generatedAltText:t})),y(this,Ds,Xd).call(this))}toggleAltTextBadge(t=!1){var e;if(!c(this,si)||c(this,ne)){(e=c(this,ei))==null||e.remove(),b(this,ei,null);return}if(!c(this,ei)){const s=b(this,ei,document.createElement("div"));s.className="noAltTextBadge",c(this,He).div.append(s)}c(this,ei).classList.toggle("hidden",!t)}serialize(t){let e=c(this,ne);return!t&&c(this,Ri)===e&&(e=c(this,Sr)),{altText:e,decorative:c(this,Zs),guessedText:c(this,Ri),textWithDisclaimer:c(this,Sr)}}get data(){return{altText:c(this,ne),decorative:c(this,Zs)}}set data({altText:t,decorative:e,guessedText:s,textWithDisclaimer:i,cancel:n=!1}){s&&(b(this,Ri,s),b(this,Sr,i)),!(c(this,ne)===t&&c(this,Zs)===e)&&(n||(b(this,ne,t),b(this,Zs,e)),y(this,Ds,Xd).call(this))}toggle(t=!1){c(this,Os)&&(!t&&c(this,Ke)&&(clearTimeout(c(this,Ke)),b(this,Ke,null)),c(this,Os).disabled=!t)}shown(){c(this,He)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_displayed",data:{label:c(this,Ds,Nl)}})}destroy(){var t,e;(t=c(this,Os))==null||t.remove(),b(this,Os,null),b(this,$o,null),b(this,ti,null),(e=c(this,ei))==null||e.remove(),b(this,ei,null)}};ne=new WeakMap,Zs=new WeakMap,Os=new WeakMap,$o=new WeakMap,ti=new WeakMap,Ke=new WeakMap,Ko=new WeakMap,ei=new WeakMap,He=new WeakMap,Ri=new WeakMap,Sr=new WeakMap,si=new WeakMap,En=new WeakMap,Ds=new WeakSet,Nl=function(){return c(this,ne)&&"added"||c(this,ne)===null&&this.guessedText&&"review"||"missing"},Xd=async function(){var i,n,r;const t=c(this,Os);if(!t)return;if(c(this,si)){if(t.classList.toggle("done",!!c(this,ne)),t.setAttribute("data-l10n-id",c(De,En)[c(this,Ds,Nl)]),(i=c(this,$o))==null||i.setAttribute("data-l10n-id",c(De,En)[`${c(this,Ds,Nl)}-label`]),!c(this,ne)){(n=c(this,ti))==null||n.remove();return}}else{if(!c(this,ne)&&!c(this,Zs)){t.classList.remove("done"),(r=c(this,ti))==null||r.remove();return}t.classList.add("done"),t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-edit-button")}let e=c(this,ti);if(!e){b(this,ti,e=document.createElement("span")),e.className="tooltip",e.setAttribute("role","tooltip"),e.id=`alt-text-tooltip-${c(this,He).id}`;const o=100,h=c(this,He)._uiManager._signal;h.addEventListener("abort",()=>{clearTimeout(c(this,Ke)),b(this,Ke,null)},{once:!0}),t.addEventListener("mouseenter",()=>{b(this,Ke,setTimeout(()=>{b(this,Ke,null),c(this,ti).classList.add("show"),c(this,He)._reportTelemetry({action:"alt_text_tooltip"})},o))},{signal:h}),t.addEventListener("mouseleave",()=>{var l;c(this,Ke)&&(clearTimeout(c(this,Ke)),b(this,Ke,null)),(l=c(this,ti))==null||l.classList.remove("show")},{signal:h})}c(this,Zs)?e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-decorative-tooltip"):(e.removeAttribute("data-l10n-id"),e.textContent=c(this,ne)),e.parentNode||t.append(e);const s=c(this,He).getImageForAltText();s==null||s.setAttribute("aria-describedby",e.id)},_(De,En,null),K(De,"_l10n",null);let hd=De;const ct=class ct{constructor(t){_(this,et);_(this,Cr,null);_(this,Ps,null);_(this,kt,null);_(this,Qo,!1);_(this,Ar,!1);_(this,ae,null);_(this,Tr,null);_(this,kn,null);_(this,Ih,"");_(this,Er,!1);_(this,Mn,null);_(this,jh,!1);_(this,kr,!1);_(this,Ii,!1);_(this,ii,null);_(this,Jo,0);_(this,Zo,0);_(this,ds,null);K(this,"_editToolbar",null);K(this,"_initialOptions",Object.create(null));K(this,"_initialData",null);K(this,"_isVisible",!0);K(this,"_uiManager",null);K(this,"_focusEventsAllowed",!0);_(this,Nh,!1);_(this,Cd,ct._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=ct.prototype._resizeWithKeyboard,e=dr.TRANSLATE_SMALL,s=dr.TRANSLATE_BIG;return ot(this,"_resizerKeyboardManager",new gh([[["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"],ct.prototype._stopResizingWithKeyboard]]))}get editorType(){return Object.getPrototypeOf(this).constructor._type}static get _defaultLineColor(){return ot(this,"_defaultLineColor",this._colorManager.getHexCode("CanvasText"))}static deleteAnnotationElement(t){const e=new Ew({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(ct._l10n??(ct._l10n=t),ct._l10nResizer||(ct._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"})),ct._borderLineWidth!==-1)return;const s=getComputedStyle(document.documentElement);ct._borderLineWidth=parseFloat(s.getPropertyValue("--outline-width"))||0}static updateDefaultParams(t,e){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(t){return!1}static paste(t,e){wt("Not implemented")}get propertiesToUpdate(){return[]}get _isDraggable(){return c(this,Nh)}set _isDraggable(t){var e;b(this,Nh,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=c(this,Cd)}setParent(t){t!==null?(this.pageIndex=t.pageIndex,this.pageDimensions=t.pageDimensions):y(this,et,Bl).call(this),this.parent=t}focusin(t){this._focusEventsAllowed&&(c(this,Er)?b(this,Er,!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){y(this,et,cf).call(this,this.parentDimensions,t,e)}translateInPage(t,e){c(this,Mn)||b(this,Mn,[this.x,this.y]),y(this,et,cf).call(this,this.pageDimensions,t,e),this.div.scrollIntoView({block:"nearest"})}drag(t,e){c(this,Mn)||b(this,Mn,[this.x,this.y]);const[s,i]=this.parentDimensions;if(this.x+=t/s,this.y+=e/i,this.parent&&(this.x<0||this.x>1||this.y<0||this.y>1)){const{x:l,y:d}=this.div.getBoundingClientRect();this.parent.findNewParent(this,l,d)&&(this.x-=Math.floor(this.x),this.y-=Math.floor(this.y))}let{x:n,y:r}=this;const[o,h]=this.getBaseTranslation();n+=o,r+=h,this.div.style.left=`${(100*n).toFixed(2)}%`,this.div.style.top=`${(100*r).toFixed(2)}%`,this.div.scrollIntoView({block:"nearest"})}get _hasBeenMoved(){return!!c(this,Mn)&&(c(this,Mn)[0]!==this.x||c(this,Mn)[1]!==this.y)}getBaseTranslation(){const[t,e]=this.parentDimensions,{_borderLineWidth:s}=ct,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[e,s]=this.pageDimensions;let{x:i,y:n,width:r,height:o}=this;if(r*=e,o*=s,i*=e,n*=s,this._mustFixPosition)switch(t){case 0:i=Math.max(0,Math.min(e-r,i)),n=Math.max(0,Math.min(s-o,n));break;case 90:i=Math.max(0,Math.min(e-o,i)),n=Math.min(s,Math.max(r,n));break;case 180:i=Math.min(e,Math.max(r,i)),n=Math.min(s,Math.max(o,n));break;case 270:i=Math.min(e,Math.max(o,i)),n=Math.max(0,Math.min(s-r,n));break}this.x=i/=e,this.y=n/=s;const[h,l]=this.getBaseTranslation();i+=h,n+=l;const{style:d}=this.div;d.left=`${(100*i).toFixed(2)}%`,d.top=`${(100*n).toFixed(2)}%`,this.moveInDOM()}screenToPageTranslation(t,e){var s;return y(s=ct,Bh,df).call(s,t,e,this.parentRotation)}pageTranslationToScreen(t,e){var s;return y(s=ct,Bh,df).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;this.div.style.width=`${(100*t/s).toFixed(2)}%`,c(this,Ar)||(this.div.style.height=`${(100*e/i).toFixed(2)}%`)}fixDims(){const{style:t}=this.div,{height:e,width:s}=t,i=s.endsWith("%"),n=!c(this,Ar)&&e.endsWith("%");if(i&&n)return;const[r,o]=this.parentDimensions;i||(t.width=`${(100*parseFloat(s)/r).toFixed(2)}%`),!c(this,Ar)&&!n&&(t.height=`${(100*parseFloat(e)/o).toFixed(2)}%`)}getInitialTranslation(){return[0,0]}altTextFinish(){var t;(t=c(this,kt))==null||t.finish()}async addEditToolbar(){return this._editToolbar||c(this,kr)?this._editToolbar:(this._editToolbar=new Ag(this),this.div.append(this._editToolbar.render()),c(this,kt)&&await this._editToolbar.addAltText(c(this,kt)),this._editToolbar)}removeEditToolbar(){var t;this._editToolbar&&(this._editToolbar.remove(),this._editToolbar=null,(t=c(this,kt))==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(){c(this,kt)||(hd.initialize(ct._l10n),b(this,kt,new hd(this)),c(this,Cr)&&(c(this,kt).data=c(this,Cr),b(this,Cr,null)),await this.addEditToolbar())}get altTextData(){var t;return(t=c(this,kt))==null?void 0:t.data}set altTextData(t){c(this,kt)&&(c(this,kt).data=t)}get guessedAltText(){var t;return(t=c(this,kt))==null?void 0:t.guessedText}async setGuessedAltText(t){var e;await((e=c(this,kt))==null?void 0:e.setGuessedText(t))}serializeAltText(t){var e;return(e=c(this,kt))==null?void 0:e.serialize(t)}hasAltText(){return!!c(this,kt)&&!c(this,kt).isEmpty()}hasAltTextData(){var t;return((t=c(this,kt))==null?void 0:t.hasData())??!1}render(){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=c(this,Qo)?-1:0,this._isVisible||this.div.classList.add("hidden"),this.setInForeground(),y(this,et,mf).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),ad(this,this.div,["pointerdown"]),this.div}pointerdown(t){const{isMac:e}=ke.platform;if(t.button!==0||t.ctrlKey&&e){t.preventDefault();return}if(b(this,Er,!0),this._isDraggable){y(this,et,wb).call(this,t);return}y(this,et,pf).call(this,t)}get isSelected(){return this._uiManager.isSelected(this)}moveInDOM(){c(this,ii)&&clearTimeout(c(this,ii)),b(this,ii,setTimeout(()=>{var t;b(this,ii,null),(t=this.parent)==null||t.moveEditorInDOM(this)},0))}_setParentAndPosition(t,e,s){t.changeParent(this),this.x=e,this.y=s,this.fixAndSetPosition()}getRect(t,e,s=this.rotation){const i=this.parentScale,[n,r]=this.pageDimensions,[o,h]=this.pageTranslation,l=t/i,d=e/i,u=this.x*n,g=this.y*r,f=this.width*n,p=this.height*r;switch(s){case 0:return[u+l+o,r-g-d-p+h,u+l+f+o,r-g-d+h];case 90:return[u+d+o,r-g+l+h,u+d+p+o,r-g+l+f+h];case 180:return[u-l-f+o,r-g+d+h,u-l+o,r-g+d+p+h];case 270:return[u-d-p+o,r-g-l-f+h,u-d+o,r-g-l+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(){}isEmpty(){return!1}enableEditMode(){b(this,kr,!0)}disableEditMode(){b(this,kr,!1)}isInEditMode(){return c(this,kr)}shouldGetKeyboardEvents(){return c(this,Ii)}needsToBeRebuilt(){return this.div&&!this.isAttachedToDOM}rebuild(){y(this,et,mf).call(this)}rotate(t){}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){wt("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,b(i,Cr,t.accessibilityData);const[n,r]=i.pageDimensions,[o,h,l,d]=i.getRectInCurrentCoords(t.rect,r);return i.x=o/n,i.y=h/r,i.width=l/n,i.height=d/r,i}get hasBeenModified(){return!!this.annotationElementId&&(this.deleted||this.serialize()!==null)}remove(){var t;if((t=c(this,kn))==null||t.abort(),b(this,kn,null),this.isEmpty()||this.commit(),this.parent?this.parent.remove(this):this._uiManager.removeEditor(this),c(this,ii)&&(clearTimeout(c(this,ii)),b(this,ii,null)),y(this,et,Bl).call(this),this.removeEditToolbar(),c(this,ds)){for(const e of c(this,ds).values())clearTimeout(e);b(this,ds,null)}this.parent=null}get isResizable(){return!1}makeResizable(){this.isResizable&&(y(this,et,yb).call(this),c(this,ae).classList.remove("hidden"),ad(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),b(this,Tr,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height});const e=c(this,ae).children;if(!c(this,Ps)){b(this,Ps,Array.from(e));const r=y(this,et,xb).bind(this),o=y(this,et,Sb).bind(this),h=this._uiManager._signal;for(const l of c(this,Ps)){const d=l.getAttribute("data-resizer-name");l.setAttribute("role","spinbutton"),l.addEventListener("keydown",r,{signal:h}),l.addEventListener("blur",o,{signal:h}),l.addEventListener("focus",y(this,et,Cb).bind(this,d),{signal:h}),l.setAttribute("data-l10n-id",ct._l10nResizer[d])}}const s=c(this,Ps)[0];let i=0;for(const r of e){if(r===s)break;i++}const n=(360-this.rotation+this.parentRotation)%360/90*(c(this,Ps).length/4);if(n!==i){if(n<i)for(let o=0;o<i-n;o++)c(this,ae).append(c(this,ae).firstChild);else if(n>i)for(let o=0;o<n-i;o++)c(this,ae).firstChild.before(c(this,ae).lastChild);let r=0;for(const o of e){const l=c(this,Ps)[r++].getAttribute("data-resizer-name");o.setAttribute("data-l10n-id",ct._l10nResizer[l])}}y(this,et,bf).call(this,0),b(this,Ii,!0),c(this,ae).firstChild.focus({focusVisible:!0}),t.preventDefault(),t.stopImmediatePropagation()}_resizeWithKeyboard(t,e){c(this,Ii)&&y(this,et,ff).call(this,c(this,Ih),{movementX:t,movementY:e})}_stopResizingWithKeyboard(){y(this,et,Bl).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=c(this,kt))==null||s.toggleAltTextBadge(!1)}unselect(){var t,e,s,i,n;(t=c(this,ae))==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=c(this,kt))==null||n.toggleAltTextBadge(!0)}updateParams(t,e){}disableEditing(){}enableEditing(){}enterInEditMode(){}getImageForAltText(){return null}get contentDiv(){return this.div}get isEditing(){return c(this,jh)}set isEditing(t){b(this,jh,t),this.parent&&(t?(this.parent.setSelected(this),this.parent.setActiveEditor(this)):this.parent.setActiveEditor(null))}setAspectRatio(t,e){b(this,Ar,!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){c(this,ds)||b(this,ds,new Map);const{action:s}=t;let i=c(this,ds).get(s);i&&clearTimeout(i),i=setTimeout(()=>{this._reportTelemetry(t),c(this,ds).delete(s),c(this,ds).size===0&&b(this,ds,null)},ct._telemetryTimeout),c(this,ds).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),b(this,Qo,!1)}disable(){this.div&&(this.div.tabIndex=-1),b(this,Qo,!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()}};Cr=new WeakMap,Ps=new WeakMap,kt=new WeakMap,Qo=new WeakMap,Ar=new WeakMap,ae=new WeakMap,Tr=new WeakMap,kn=new WeakMap,Ih=new WeakMap,Er=new WeakMap,Mn=new WeakMap,jh=new WeakMap,kr=new WeakMap,Ii=new WeakMap,ii=new WeakMap,Jo=new WeakMap,Zo=new WeakMap,ds=new WeakMap,Nh=new WeakMap,Cd=new WeakMap,et=new WeakSet,cf=function([t,e],s,i){[s,i]=this.screenToPageTranslation(s,i),this.x+=s/t,this.y+=i/e,this.fixAndSetPosition()},Bh=new WeakSet,df=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]}},uf=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]}},yb=function(){if(c(this,ae))return;b(this,ae,document.createElement("div")),c(this,ae).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");c(this,ae).append(i),i.classList.add("resizer",s),i.setAttribute("data-resizer-name",s),i.addEventListener("pointerdown",y(this,et,_b).bind(this,s),{signal:e}),i.addEventListener("contextmenu",as,{signal:e}),i.tabIndex=-1}this.div.prepend(c(this,ae))},_b=function(t,e){var p;e.preventDefault();const{isMac:s}=ke.platform;if(e.button!==0||e.ctrlKey&&s)return;(p=c(this,kt))==null||p.toggle(!1);const i=this._isDraggable;this._isDraggable=!1;const n=new AbortController,r=this._uiManager.combinedSignal(n);this.parent.togglePointerEvents(!1),window.addEventListener("pointermove",y(this,et,ff).bind(this,t),{passive:!0,capture:!0,signal:r}),window.addEventListener("contextmenu",as,{signal:r});const o=this.x,h=this.y,l=this.width,d=this.height,u=this.parent.div.style.cursor,g=this.div.style.cursor;this.div.style.cursor=this.parent.div.style.cursor=window.getComputedStyle(e.target).cursor;const f=()=>{var m;n.abort(),this.parent.togglePointerEvents(!0),(m=c(this,kt))==null||m.toggle(!0),this._isDraggable=i,this.parent.div.style.cursor=u,this.div.style.cursor=g,y(this,et,gf).call(this,o,h,l,d)};window.addEventListener("pointerup",f,{signal:r}),window.addEventListener("blur",f,{signal:r})},gf=function(t,e,s,i){const n=this.x,r=this.y,o=this.width,h=this.height;n===t&&r===e&&o===s&&h===i||this.addCommands({cmd:()=>{this.width=o,this.height=h,this.x=n,this.y=r;const[l,d]=this.parentDimensions;this.setDims(l*o,d*h),this.fixAndSetPosition()},undo:()=>{this.width=s,this.height=i,this.x=t,this.y=e;const[l,d]=this.parentDimensions;this.setDims(l*s,d*i),this.fixAndSetPosition()},mustExec:!0})},ff=function(t,e){const[s,i]=this.parentDimensions,n=this.x,r=this.y,o=this.width,h=this.height,l=ct.MIN_SIZE/s,d=ct.MIN_SIZE/i,u=z=>Math.round(z*1e4)/1e4,g=y(this,et,uf).call(this,this.rotation),f=(z,H)=>[g[0]*z+g[2]*H,g[1]*z+g[3]*H],p=y(this,et,uf).call(this,360-this.rotation),m=(z,H)=>[p[0]*z+p[2]*H,p[1]*z+p[3]*H];let w,v,x=!1,S=!1;switch(t){case"topLeft":x=!0,w=(z,H)=>[0,0],v=(z,H)=>[z,H];break;case"topMiddle":w=(z,H)=>[z/2,0],v=(z,H)=>[z/2,H];break;case"topRight":x=!0,w=(z,H)=>[z,0],v=(z,H)=>[0,H];break;case"middleRight":S=!0,w=(z,H)=>[z,H/2],v=(z,H)=>[0,H/2];break;case"bottomRight":x=!0,w=(z,H)=>[z,H],v=(z,H)=>[0,0];break;case"bottomMiddle":w=(z,H)=>[z/2,H],v=(z,H)=>[z/2,0];break;case"bottomLeft":x=!0,w=(z,H)=>[0,H],v=(z,H)=>[z,0];break;case"middleLeft":S=!0,w=(z,H)=>[0,H/2],v=(z,H)=>[z,H/2];break}const C=w(o,h),E=v(o,h);let k=f(...E);const P=u(n+k[0]),D=u(r+k[1]);let R=1,B=1,[O,F]=this.screenToPageTranslation(e.movementX,e.movementY);if([O,F]=m(O/s,F/i),x){const z=Math.hypot(o,h);R=B=Math.max(Math.min(Math.hypot(E[0]-C[0]-O,E[1]-C[1]-F)/z,1/o,1/h),l/o,d/h)}else S?R=Math.max(l,Math.min(1,Math.abs(E[0]-C[0]-O)))/o:B=Math.max(d,Math.min(1,Math.abs(E[1]-C[1]-F)))/h;const L=u(o*R),I=u(h*B);k=f(...v(L,I));const G=P-k[0],Y=D-k[1];this.width=L,this.height=I,this.x=G,this.y=Y,this.setDims(s*L,i*I),this.fixAndSetPosition()},pf=function(t){const{isMac:e}=ke.platform;t.ctrlKey&&!e||t.shiftKey||t.metaKey&&e?this.parent.toggleSelected(this):this.parent.setSelected(this)},wb=function(t){const{isSelected:e}=this;this._uiManager.setUpDragSession();const s=new AbortController,i=this._uiManager.combinedSignal(s);if(e){this.div.classList.add("moving"),b(this,Jo,t.clientX),b(this,Zo,t.clientY);const r=o=>{const{clientX:h,clientY:l}=o,[d,u]=this.screenToPageTranslation(h-c(this,Jo),l-c(this,Zo));b(this,Jo,h),b(this,Zo,l),this._uiManager.dragSelectedEditors(d,u)};window.addEventListener("pointermove",r,{passive:!0,capture:!0,signal:i})}const n=()=>{s.abort(),e&&this.div.classList.remove("moving"),b(this,Er,!1),this._uiManager.endDragSession()||y(this,et,pf).call(this,t)};window.addEventListener("pointerup",n,{signal:i}),window.addEventListener("blur",n,{signal:i})},mf=function(){if(c(this,kn)||!this.div)return;b(this,kn,new AbortController);const t=this._uiManager.combinedSignal(c(this,kn));this.div.addEventListener("focusin",this.focusin.bind(this),{signal:t}),this.div.addEventListener("focusout",this.focusout.bind(this),{signal:t})},xb=function(t){ct._resizerKeyboardManager.exec(this,t)},Sb=function(t){var e;c(this,Ii)&&((e=t.relatedTarget)==null?void 0:e.parentNode)!==c(this,ae)&&y(this,et,Bl).call(this)},Cb=function(t){b(this,Ih,c(this,Ii)?t:"")},bf=function(t){if(c(this,Ps))for(const e of c(this,Ps))e.tabIndex=t},Bl=function(){if(b(this,Ii,!1),y(this,et,bf).call(this,-1),c(this,Tr)){const{savedX:t,savedY:e,savedWidth:s,savedHeight:i}=c(this,Tr);y(this,et,gf).call(this,t,e,s,i),b(this,Tr,null)}},_(ct,Bh),K(ct,"_l10n",null),K(ct,"_l10nResizer",null),K(ct,"_borderLineWidth",-1),K(ct,"_colorManager",new Eg),K(ct,"_zIndex",1),K(ct,"_telemetryTimeout",1e3);let gt=ct;class Ew extends gt{constructor(t){super(t),this.annotationElementId=t.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}}const l0=3285377520,hs=4294901760,qs=65535;class c0{constructor(t){this.h1=t?t&4294967295:l0,this.h2=t?t&4294967295:l0}update(t){let e,s;if(typeof t=="string"){e=new Uint8Array(t.length*2),s=0;for(let m=0,w=t.length;m<w;m++){const v=t.charCodeAt(m);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,l=this.h1,d=this.h2;const u=3432918353,g=461845907,f=u&qs,p=g&qs;for(let m=0;m<i;m++)m&1?(o=r[m],o=o*u&hs|o*f&qs,o=o<<15|o>>>17,o=o*g&hs|o*p&qs,l^=o,l=l<<13|l>>>19,l=l*5+3864292196):(h=r[m],h=h*u&hs|h*f&qs,h=h<<15|h>>>17,h=h*g&hs|h*p&qs,d^=h,d=d<<13|d>>>19,d=d*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*u&hs|o*f&qs,o=o<<15|o>>>17,o=o*g&hs|o*p&qs,i&1?l^=o:d^=o}this.h1=l,this.h2=d}hexdigest(){let t=this.h1,e=this.h2;return t^=e>>>1,t=t*3981806797&hs|t*36045&qs,e=e*4283543511&hs|((e<<16|t>>>16)*2950163797&hs)>>>16,t^=e>>>1,t=t*444984403&hs|t*60499&qs,e=e*3301882366&hs|((e<<16|t>>>16)*3120437893&hs)>>>16,t^=e>>>1,(t>>>0).toString(16).padStart(8,"0")+(e>>>0).toString(16).padStart(8,"0")}}const kg=Object.freeze({map:null,hash:"",transfer:void 0});class Mg{constructor(){_(this,Ad);_(this,Mr,!1);_(this,Or,null);_(this,re,new Map);this.onSetModified=null,this.onResetModified=null,this.onAnnotationEditor=null}getValue(t,e){const s=c(this,re).get(t);return s===void 0?e:Object.assign(e,s)}getRawValue(t){return c(this,re).get(t)}remove(t){if(c(this,re).delete(t),c(this,re).size===0&&this.resetModified(),typeof this.onAnnotationEditor=="function"){for(const e of c(this,re).values())if(e instanceof gt)return;this.onAnnotationEditor(null)}}setValue(t,e){const s=c(this,re).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,c(this,re).set(t,e);i&&y(this,Ad,Ab).call(this),e instanceof gt&&typeof this.onAnnotationEditor=="function"&&this.onAnnotationEditor(e.constructor._type)}has(t){return c(this,re).has(t)}getAll(){return c(this,re).size>0?mg(c(this,re)):null}setAll(t){for(const[e,s]of Object.entries(t))this.setValue(e,s)}get size(){return c(this,re).size}resetModified(){c(this,Mr)&&(b(this,Mr,!1),typeof this.onResetModified=="function"&&this.onResetModified())}get print(){return new d0(this)}get serializable(){if(c(this,re).size===0)return kg;const t=new Map,e=new c0,s=[],i=Object.create(null);let n=!1;for(const[r,o]of c(this,re)){const h=o instanceof gt?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}:kg}get editorStats(){let t=null;const e=new Map;for(const s of c(this,re).values()){if(!(s instanceof gt))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 l=r.get(o);l||(l=new Map,r.set(o,l));const d=l.get(h)??0;l.set(h,d+1)}}for(const[s,i]of e)t[s]=i.computeTelemetryFinalData(t[s]);return t}resetModifiedIds(){b(this,Or,null)}get modifiedIds(){if(c(this,Or))return c(this,Or);const t=[];for(const e of c(this,re).values())!(e instanceof gt)||!e.annotationElementId||!e.serialize()||t.push(e.annotationElementId);return b(this,Or,{ids:new Set(t),hash:t.join(",")})}}Mr=new WeakMap,Or=new WeakMap,re=new WeakMap,Ad=new WeakSet,Ab=function(){c(this,Mr)||(b(this,Mr,!0),typeof this.onSetModified=="function"&&this.onSetModified())};class d0 extends Mg{constructor(e){super();_(this,Hh);const{map:s,hash:i,transfer:n}=e.serializable,r=structuredClone(s,n?{transfer:n}:null);b(this,Hh,{map:r,hash:i,transfer:n})}get print(){wt("Should not call PrintAnnotationStorage.print")}get serializable(){return c(this,Hh)}get modifiedIds(){return ot(this,"modifiedIds",{ids:new Set,hash:""})}}Hh=new WeakMap;class kw{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(),c(this,ta).clear(),this.styleElement&&(this.styleElement.remove(),this.styleElement=null)}async loadSystemFont({systemFontInfo:t,_inspectFont:e}){if(!(!t||c(this,ta).has(t.loadedName))){if(qt(!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(),c(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}wt("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 ot(this,"isFontLoadingAPISupported",t)}get isSyncFontLoadingSupported(){let t=!1;return(pe||typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.userAgent)=="string"&&/Mozilla\/5.0.*?rv:\d+.*? Gecko/.test(navigator.userAgent))&&(t=!0),ot(this,"isSyncFontLoadingSupported",t)}_queueLoadingCallback(t){function e(){for(qt(!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 ot(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,k,P){const D=C.substring(0,E),R=C.substring(E+k);return D+P+R}let n,r;const o=this._document.createElement("canvas");o.width=1,o.height=1;const h=o.getContext("2d");let l=0;function d(C,E){if(++l>30){st("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(d.bind(null,C,E))}const u=`lt${Date.now()}${this.loadTestFontId++}`;let g=this._loadTestFont;g=i(g,976,u.length,u);const p=16,m=1482184792;let w=s(g,p);for(n=0,r=u.length-3;n<r;n+=4)w=w-m+s(u,n)|0;n<u.length&&(w=w-m+s(u+"XXX",n)|0),g=i(g,p,4,uw(w));const v=`url(data:font/opentype;base64,${btoa(g)});`,x=`@font-face {font-family:"${u}";src:${v}}`;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,u]){const E=this._document.createElement("span");E.textContent="Hi",E.style.fontFamily=C,S.append(E)}this._document.body.append(S),d(u,()=>{S.remove(),e.complete()})}}ta=new WeakMap;class Mw{constructor(t,{disableFontFace:e=!1,inspectFont:s=null}){this.compiledGlyphs=Object.create(null);for(const i in t)this[i]=t[i];this.disableFontFace=e===!0,this._inspectFont=s}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,${vw(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];let s;try{s=t.get(this.loadedName+"_path_"+e)}catch(n){st(`getPathGenerator - ignoring character: "${n}".`)}if(!Array.isArray(s)||s.length===0)return this.compiledGlyphs[e]=function(n,r){};const i=[];for(let n=0,r=s.length;n<r;)switch(s[n++]){case Ai.BEZIER_CURVE_TO:{const[o,h,l,d,u,g]=s.slice(n,n+6);i.push(f=>f.bezierCurveTo(o,h,l,d,u,g)),n+=6}break;case Ai.MOVE_TO:{const[o,h]=s.slice(n,n+2);i.push(l=>l.moveTo(o,h)),n+=2}break;case Ai.LINE_TO:{const[o,h]=s.slice(n,n+2);i.push(l=>l.lineTo(o,h)),n+=2}break;case Ai.QUADRATIC_CURVE_TO:{const[o,h,l,d]=s.slice(n,n+4);i.push(u=>u.quadraticCurveTo(o,h,l,d)),n+=4}break;case Ai.RESTORE:i.push(o=>o.restore());break;case Ai.SAVE:i.push(o=>o.save());break;case Ai.SCALE:qt(i.length===2,"Scale command is only valid at the third position.");break;case Ai.TRANSFORM:{const[o,h,l,d,u,g]=s.slice(n,n+6);i.push(f=>f.transform(o,h,l,d,u,g)),n+=6}break;case Ai.TRANSLATE:{const[o,h]=s.slice(n,n+2);i.push(l=>l.translate(o,h)),n+=2}break}return this.compiledGlyphs[e]=function(r,o){i[0](r),i[1](r),r.scale(o,-o);for(let h=2,l=i.length;h<l;h++)i[h](r)}}}class u0{constructor({enableHWA:t=!1}){_(this,Wh,!1);b(this,Wh,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:!c(this,Wh)})}}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){wt("Abstract method `_createCanvas` called.")}}Wh=new WeakMap;class Ow extends u0{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 g0{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){wt("Abstract method `_fetch` called.")}}class f0 extends g0{async _fetch(t){const e=await rd(t,this.isCompressed?"arraybuffer":"text");return e instanceof ArrayBuffer?new Uint8Array(e):nd(e)}}class p0{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 Dw extends p0{constructor({docId:e,ownerDocument:s=globalThis.document}){super();_(this,W);_(this,Dr);_(this,Pr);_(this,ni);_(this,ji);_(this,ve);_(this,Td);_(this,Lr,0);b(this,ji,e),b(this,ve,s)}addFilter(e){if(!e)return"none";let s=c(this,W,we).get(e);if(s)return s;const[i,n,r]=y(this,W,zd).call(this,e),o=e.length===1?i:`${i}${n}${r}`;if(s=c(this,W,we).get(o),s)return c(this,W,we).set(e,s),s;const h=`g_${c(this,ji)}_transfer_map_${Fe(this,Lr)._++}`,l=y(this,W,Wa).call(this,h);c(this,W,we).set(e,l),c(this,W,we).set(o,l);const d=y(this,W,Xa).call(this,h);return y(this,W,Wl).call(this,i,n,r,d),l}addHCMFilter(e,s){var p;const i=`${e}-${s}`,n="base";let r=c(this,W,Ba).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},c(this,W,Ba).set(n,r)),!e||!s))return r.url;const o=y(this,W,Xl).call(this,e);e=V.makeHexColor(...o);const h=y(this,W,Xl).call(this,s);if(s=V.makeHexColor(...h),c(this,W,Ha).style.color="",e==="#000000"&&s==="#ffffff"||e===s)return r.url;const l=new Array(256);for(let m=0;m<=255;m++){const w=m/255;l[m]=w<=.03928?w/12.92:((w+.055)/1.055)**2.4}const d=l.join(","),u=`g_${c(this,ji)}_hcm_filter`,g=r.filter=y(this,W,Xa).call(this,u);y(this,W,Wl).call(this,d,d,d,g),y(this,W,vf).call(this,g);const f=(m,w)=>{const v=o[m]/255,x=h[m]/255,S=new Array(w+1);for(let C=0;C<=w;C++)S[C]=v+C/w*(x-v);return S.join(",")};return y(this,W,Wl).call(this,f(0,5),f(1,5),f(2,5),g),r.url=y(this,W,Wa).call(this,u),r.url}addAlphaFilter(e){let s=c(this,W,we).get(e);if(s)return s;const[i]=y(this,W,zd).call(this,[e]),n=`alpha_${i}`;if(s=c(this,W,we).get(n),s)return c(this,W,we).set(e,s),s;const r=`g_${c(this,ji)}_alpha_map_${Fe(this,Lr)._++}`,o=y(this,W,Wa).call(this,r);c(this,W,we).set(e,o),c(this,W,we).set(n,o);const h=y(this,W,Xa).call(this,r);return y(this,W,yf).call(this,i,h),o}addLuminosityFilter(e){let s=c(this,W,we).get(e||"luminosity");if(s)return s;let i,n;if(e?([i]=y(this,W,zd).call(this,[e]),n=`luminosity_${i}`):n="luminosity",s=c(this,W,we).get(n),s)return c(this,W,we).set(e,s),s;const r=`g_${c(this,ji)}_luminosity_map_${Fe(this,Lr)._++}`,o=y(this,W,Wa).call(this,r);c(this,W,we).set(e,o),c(this,W,we).set(n,o);const h=y(this,W,Xa).call(this,r);return y(this,W,Tb).call(this,h),e&&y(this,W,yf).call(this,i,h),o}addHighlightHCMFilter(e,s,i,n,r){var x;const o=`${s}-${i}-${n}-${r}`;let h=c(this,W,Ba).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},c(this,W,Ba).set(e,h)),!s||!i))return h.url;const[l,d]=[s,i].map(y(this,W,Xl).bind(this));let u=Math.round(.2126*l[0]+.7152*l[1]+.0722*l[2]),g=Math.round(.2126*d[0]+.7152*d[1]+.0722*d[2]),[f,p]=[n,r].map(y(this,W,Xl).bind(this));g<u&&([u,g,f,p]=[g,u,p,f]),c(this,W,Ha).style.color="";const m=(S,C,E)=>{const k=new Array(256),P=(g-u)/E,D=S/255,R=(C-S)/(255*E);let B=0;for(let O=0;O<=E;O++){const F=Math.round(u+O*P),L=D+O*R;for(let I=B;I<=F;I++)k[I]=L;B=F+1}for(let O=B;O<256;O++)k[O]=k[B-1];return k.join(",")},w=`g_${c(this,ji)}_hcm_${e}_filter`,v=h.filter=y(this,W,Xa).call(this,w);return y(this,W,vf).call(this,v),y(this,W,Wl).call(this,m(f[0],p[0],5),m(f[1],p[1],5),m(f[2],p[2],5),v),h.url=y(this,W,Wa).call(this,w),h.url}destroy(e=!1){e&&c(this,W,Ba).size!==0||(c(this,ni)&&(c(this,ni).parentNode.parentNode.remove(),b(this,ni,null)),c(this,Pr)&&(c(this,Pr).clear(),b(this,Pr,null)),b(this,Lr,0))}}Dr=new WeakMap,Pr=new WeakMap,ni=new WeakMap,ji=new WeakMap,ve=new WeakMap,Td=new WeakMap,Lr=new WeakMap,W=new WeakSet,we=function(){return c(this,Pr)||b(this,Pr,new Map)},Ba=function(){return c(this,Td)||b(this,Td,new Map)},Ha=function(){if(!c(this,ni)){const e=c(this,ve).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=c(this,ve).createElementNS(Ti,"svg");i.setAttribute("width",0),i.setAttribute("height",0),b(this,ni,c(this,ve).createElementNS(Ti,"defs")),e.append(i),i.append(c(this,ni)),c(this,ve).body.append(e)}return c(this,ni)},zd=function(e){if(e.length===1){const l=e[0],d=new Array(256);for(let g=0;g<256;g++)d[g]=l[g]/255;const u=d.join(",");return[u,u,u]}const[s,i,n]=e,r=new Array(256),o=new Array(256),h=new Array(256);for(let l=0;l<256;l++)r[l]=s[l]/255,o[l]=i[l]/255,h[l]=n[l]/255;return[r.join(","),o.join(","),h.join(",")]},Wa=function(e){if(c(this,Dr)===void 0){b(this,Dr,"");const s=c(this,ve).URL;s!==c(this,ve).baseURI&&(od(s)?st('#createUrl: ignore "data:"-URL for performance reasons.'):b(this,Dr,s.split("#",1)[0]))}return`url(${c(this,Dr)}#${e})`},Tb=function(e){const s=c(this,ve).createElementNS(Ti,"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)},vf=function(e){const s=c(this,ve).createElementNS(Ti,"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)},Xa=function(e){const s=c(this,ve).createElementNS(Ti,"filter");return s.setAttribute("color-interpolation-filters","sRGB"),s.setAttribute("id",e),c(this,W,Ha).append(s),s},Hl=function(e,s,i){const n=c(this,ve).createElementNS(Ti,s);n.setAttribute("type","discrete"),n.setAttribute("tableValues",i),e.append(n)},Wl=function(e,s,i,n){const r=c(this,ve).createElementNS(Ti,"feComponentTransfer");n.append(r),y(this,W,Hl).call(this,r,"feFuncR",e),y(this,W,Hl).call(this,r,"feFuncG",s),y(this,W,Hl).call(this,r,"feFuncB",i)},yf=function(e,s){const i=c(this,ve).createElementNS(Ti,"feComponentTransfer");s.append(i),y(this,W,Hl).call(this,i,"feFuncA",e)},Xl=function(e){return c(this,W,Ha).style.color=e,Sg(getComputedStyle(c(this,W,Ha)).getPropertyValue("color"))};class m0{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){wt("Abstract method `_fetch` called.")}}class b0 extends m0{async _fetch(t){const e=await rd(t,"arraybuffer");return new Uint8Array(e)}}if(pe){var Og=Promise.withResolvers(),fh=null;(async()=>{const t=await Promise.resolve().then(()=>vd),e=await Promise.resolve().then(()=>vd),s=await Promise.resolve().then(()=>vd),i=await Promise.resolve().then(()=>vd);let n,r;return new Map(Object.entries({fs:t,http:e,https:s,url:i,canvas:n,path2d:r}))})().then(t=>{fh=t,Og.resolve()},t=>{st(`loadPackages: ${t}`),fh=new Map,Og.resolve()})}class bn{static get promise(){return Og.promise}static get(t){return fh==null?void 0:fh.get(t)}}async function v0(a){const e=await bn.get("fs").promises.readFile(a);return new Uint8Array(e)}class Pw extends p0{}class Lw extends u0{_createCanvas(t,e){return bn.get("canvas").createCanvas(t,e)}}class Fw extends g0{async _fetch(t){return v0(t)}}class Rw extends m0{async _fetch(t){return v0(t)}}const Me={FILL:"Fill",STROKE:"Stroke",SHADING:"Shading"};function Dg(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 Pg{getPattern(){wt("Abstract method `getPattern` called.")}}class Iw extends Pg{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===Me.STROKE||i===Me.FILL){const r=e.current.getClippedPathBoundingBox(i,Et(t))||[0,0,0,0],o=Math.ceil(r[2]-r[0])||1,h=Math.ceil(r[3]-r[1])||1,l=e.cachedCanvases.getCanvas("pattern",o,h),d=l.context;d.clearRect(0,0,d.canvas.width,d.canvas.height),d.beginPath(),d.rect(0,0,d.canvas.width,d.canvas.height),d.translate(-r[0],-r[1]),s=V.transform(s,[1,0,0,1,r[0],r[1]]),d.transform(...e.baseTransform),this.matrix&&d.transform(...this.matrix),Dg(d,this._bbox),d.fillStyle=this._createGradient(d),d.fill(),n=t.createPattern(l.canvas,"no-repeat");const u=new DOMMatrix(s);n.setTransform(u)}else Dg(t,this._bbox),n=this._createGradient(t);return n}}function Lg(a,t,e,s,i,n,r,o){const h=t.coords,l=t.colors,d=a.data,u=a.width*4;let g;h[e+1]>h[s+1]&&(g=e,e=s,s=g,g=n,n=r,r=g),h[s+1]>h[i+1]&&(g=s,s=i,i=g,g=r,r=o,o=g),h[e+1]>h[s+1]&&(g=e,e=s,s=g,g=n,n=r,r=g);const f=(h[e]+t.offsetX)*t.scaleX,p=(h[e+1]+t.offsetY)*t.scaleY,m=(h[s]+t.offsetX)*t.scaleX,w=(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 S=l[n],C=l[n+1],E=l[n+2],k=l[r],P=l[r+1],D=l[r+2],R=l[o],B=l[o+1],O=l[o+2],F=Math.round(p),L=Math.round(x);let I,G,Y,z,H,_t,vt,te;for(let Wt=F;Wt<=L;Wt++){if(Wt<w){const dt=Wt<p?0:(p-Wt)/(p-w);I=f-(f-m)*dt,G=S-(S-k)*dt,Y=C-(C-P)*dt,z=E-(E-D)*dt}else{let dt;Wt>x?dt=1:w===x?dt=0:dt=(w-Wt)/(w-x),I=m-(m-v)*dt,G=k-(k-R)*dt,Y=P-(P-B)*dt,z=D-(D-O)*dt}let xt;Wt<p?xt=0:Wt>x?xt=1:xt=(p-Wt)/(p-x),H=f-(f-v)*xt,_t=S-(S-R)*xt,vt=C-(C-B)*xt,te=E-(E-O)*xt;const Le=Math.round(Math.min(I,H)),gi=Math.round(Math.max(I,H));let Ft=u*Wt+Le*4;for(let dt=Le;dt<=gi;dt++)xt=(I-dt)/(I-H),xt<0?xt=0:xt>1&&(xt=1),d[Ft++]=G-(G-_t)*xt|0,d[Ft++]=Y-(Y-vt)*xt|0,d[Ft++]=z-(z-te)*xt|0,d[Ft++]=255}}function jw(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,l=o-1;for(n=0;n<h;n++){let d=n*o;for(let u=0;u<l;u++,d++)Lg(a,e,s[d],s[d+1],s[d+o],i[d],i[d+1],i[d+o]),Lg(a,e,s[d+o+1],s[d+1],s[d+o],i[d+o+1],i[d+1],i[d+o])}break;case"triangles":for(n=0,r=s.length;n<r;n+=3)Lg(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 Nw extends Pg{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]),l=Math.ceil(this._bounds[2])-o,d=Math.ceil(this._bounds[3])-h,u=Math.min(Math.ceil(Math.abs(l*t[0]*1.1)),3e3),g=Math.min(Math.ceil(Math.abs(d*t[1]*1.1)),3e3),f=l/u,p=d/g,m={coords:this._coords,colors:this._colors,offsetX:-o,offsetY:-h,scaleX:1/f,scaleY:1/p},w=u+2*2,v=g+2*2,x=s.getCanvas("mesh",w,v),S=x.context,C=S.createImageData(u,g);if(e){const k=C.data;for(let P=0,D=k.length;P<D;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)jw(C,k,m);return S.putImageData(C,2,2),{canvas:x.canvas,offsetX:o-2*f,offsetY:h-2*p,scaleX:f,scaleY:p}}getPattern(t,e,s,i){Dg(t,this._bbox);let n;if(i===Me.SHADING)n=V.singularValueDecompose2dScale(Et(t));else if(n=V.singularValueDecompose2dScale(e.baseTransform),this.matrix){const o=V.singularValueDecompose2dScale(this.matrix);n=[n[0]*o[0],n[1]*o[1]]}const r=this._createMeshCanvas(n,i===Me.SHADING?null:this._background,e.cachedCanvases);return i!==Me.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 Bw extends Pg{getPattern(){return"hotpink"}}function Hw(a){switch(a[0]){case"RadialAxial":return new Iw(a);case"Mesh":return new Nw(a);case"Dummy":return new Bw}throw new Error(`Unknown IR type: ${a[0]}`)}const y0={COLORED:1,UNCOLORED:2},Ed=class Ed{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:l}=this;h=Math.abs(h),l=Math.abs(l),sd("TilingType: "+n);const d=e[0],u=e[1],g=e[2],f=e[3],p=g-d,m=f-u,w=V.singularValueDecompose2dScale(this.matrix),v=V.singularValueDecompose2dScale(this.baseTransform),x=w[0]*v[0],S=w[1]*v[1];let C=p,E=m,k=!1,P=!1;const D=Math.ceil(h*x),R=Math.ceil(l*S),B=Math.ceil(p*x),O=Math.ceil(m*S);D>=B?C=h:k=!0,R>=O?E=l:P=!0;const F=this.getSizeAndScale(C,this.ctx.canvas.width,x),L=this.getSizeAndScale(E,this.ctx.canvas.height,S),I=t.cachedCanvases.getCanvas("pattern",F.size,L.size),G=I.context,Y=o.createCanvasGraphics(G);if(Y.groupLevel=t.groupLevel,this.setFillAndStrokeStyleToContext(Y,i,r),G.translate(-F.scale*d,-L.scale*u),Y.transform(F.scale,0,0,L.scale,0,0),G.save(),this.clipBbox(Y,d,u,g,f),Y.baseTransform=Et(Y.ctx),Y.executeOperatorList(s),Y.endDrawing(),G.restore(),k||P){const z=I.canvas;k&&(C=h),P&&(E=l);const H=this.getSizeAndScale(C,this.ctx.canvas.width,x),_t=this.getSizeAndScale(E,this.ctx.canvas.height,S),vt=H.size,te=_t.size,Wt=t.cachedCanvases.getCanvas("pattern-workaround",vt,te),xt=Wt.context,Le=k?Math.floor(p/h):0,gi=P?Math.floor(m/l):0;for(let Ft=0;Ft<=Le;Ft++)for(let dt=0;dt<=gi;dt++)xt.drawImage(z,vt*Ft,te*dt,vt,te,0,0,vt,te);return{canvas:Wt.canvas,scaleX:H.scale,scaleY:_t.scale,offsetX:d,offsetY:u}}return{canvas:I.canvas,scaleX:F.scale,scaleY:L.scale,offsetX:d,offsetY:u}}getSizeAndScale(t,e,s){const i=Math.max(Ed.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(Et(t.ctx),[e,s,i,n]),t.clip(),t.endPath()}setFillAndStrokeStyleToContext(t,e,s){const i=t.ctx,n=t.current;switch(e){case y0.COLORED:const r=this.ctx;i.fillStyle=r.fillStyle,i.strokeStyle=r.strokeStyle,n.fillColor=r.fillStyle,n.strokeColor=r.strokeStyle;break;case y0.UNCOLORED:const o=V.makeHexColor(s[0],s[1],s[2]);i.fillStyle=o,i.strokeStyle=o,n.fillColor=o,n.strokeColor=o;break;default:throw new dw(`Unsupported paint type: ${e}`)}}getPattern(t,e,s,i){let n=s;i!==Me.SHADING&&(n=V.transform(n,e.baseTransform),this.matrix&&(n=V.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}};K(Ed,"MAX_PATTERN_SIZE",3e3);let Fg=Ed;function Ww({src:a,srcPos:t=0,dest:e,width:s,height:i,nonBlackColor:n=4294967295,inverseDecode:r=!1}){const o=ke.isLittleEndian?4278190080:255,[h,l]=r?[n,o]:[o,n],d=s>>3,u=s&7,g=a.length;e=new Uint32Array(e.buffer);let f=0;for(let p=0;p<i;p++){for(const w=t+d;t<w;t++){const v=t<g?a[t]:255;e[f++]=v&128?l:h,e[f++]=v&64?l:h,e[f++]=v&32?l:h,e[f++]=v&16?l:h,e[f++]=v&8?l:h,e[f++]=v&4?l:h,e[f++]=v&2?l:h,e[f++]=v&1?l:h}if(u===0)continue;const m=t<g?a[t++]:255;for(let w=0;w<u;w++)e[f++]=m&1<<7-w?l:h}return{srcPos:t,destPos:f}}const _0=16,w0=100,Xw=15,x0=10,S0=1e3,Ne=16;function zw(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 Vw{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 ld(a,t,e,s,i,n,r,o,h,l){const[d,u,g,f,p,m]=Et(a);if(u===0&&g===0){const x=r*d+p,S=Math.round(x),C=o*f+m,E=Math.round(C),k=(r+h)*d+p,P=Math.abs(Math.round(k)-S)||1,D=(o+l)*f+m,R=Math.abs(Math.round(D)-E)||1;return a.setTransform(Math.sign(d),0,0,Math.sign(f),S,E),a.drawImage(t,e,s,i,n,0,0,P,R),a.setTransform(d,u,g,f,p,m),[P,R]}if(d===0&&f===0){const x=o*g+p,S=Math.round(x),C=r*u+m,E=Math.round(C),k=(o+l)*g+p,P=Math.abs(Math.round(k)-S)||1,D=(r+h)*u+m,R=Math.abs(Math.round(D)-E)||1;return a.setTransform(0,Math.sign(u),Math.sign(g),0,S,E),a.drawImage(t,e,s,i,n,0,0,R,P),a.setTransform(d,u,g,f,p,m),[R,P]}a.drawImage(t,e,s,i,n,r,o,h,l);const w=Math.hypot(d,u),v=Math.hypot(g,f);return[w*h,v*l]}function Gw(a){const{width:t,height:e}=a;if(t>S0||e>S0)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,l;const d=t+7&-8;let u=new Uint8Array(d*e),g=0;for(const v of a.data){let x=128;for(;x>0;)u[g++]=v&x?0:255,x>>=1}let f=0;for(g=0,u[g]!==0&&(r[0]=1,++f),h=1;h<t;h++)u[g]!==u[g+1]&&(r[h]=u[g]?2:1,++f),g++;for(u[g]!==0&&(r[h]=2,++f),o=1;o<e;o++){g=o*d,l=o*n,u[g-d]!==u[g]&&(r[l]=u[g]?1:8,++f);let v=(u[g]?4:0)+(u[g-d]?8:0);for(h=1;h<t;h++)v=(v>>2)+(u[g+1]?4:0)+(u[g-d+1]?8:0),i[v]&&(r[l+h]=i[v],++f),g++;if(u[g-d]!==u[g]&&(r[l+h]=u[g]?2:4,++f),f>s)return null}for(g=d*(e-1),l=o*n,u[g]!==0&&(r[l]=8,++f),h=1;h<t;h++)u[g]!==u[g+1]&&(r[l+h]=u[g]?4:8,++f),g++;if(u[g]!==0&&(r[l+h]=4,++f),f>s)return null;const p=new Int32Array([0,n,-1,0,-n,0,0,0,1]),m=new Path2D;for(o=0;f&&o<=e;o++){let v=o*n;const x=v+t;for(;v<x&&!r[v];)v++;if(v===x)continue;m.moveTo(v%n,o);const S=v;let C=r[v];do{const E=p[C];do v+=E;while(!r[v]);const k=r[v];k!==5&&k!==10?(C=k,r[v]=0):(C=k&51*C>>4,r[v]&=C>>2|C<<2),m.lineTo(v%n,v/n|0),r[v]||--f}while(S!==v);--o}return u=null,r=null,function(v){v.save(),v.scale(1/t,-1/e),v.translate(0,-e),v.fill(m),v.beginPath(),v.restore()}}class C0{constructor(t,e){this.alphaIsShape=!1,this.fontSize=0,this.fontSizeScale=1,this.textMatrix=i0,this.textMatrixScale=1,this.fontMatrix=ug,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=me.FILL,this.textRise=0,this.fillColor="#000000",this.strokeColor="#000000",this.patternFill=!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]=V.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=V.applyTransform(e,t),i=V.applyTransform(e.slice(2),t),n=V.applyTransform([e[0],e[3]],t),r=V.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){V.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,l,d){const u=V.bezierBoundingBox(e,s,i,n,r,o,h,l,d);d||this.updateRectMinMax(t,u)}getPathBoundingBox(t=Me.FILL,e=null){const s=[this.minX,this.minY,this.maxX,this.maxY];if(t===Me.STROKE){e||wt("Stroke bounding box must include transform.");const i=V.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=V.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=Me.FILL,e=null){return V.intersect(this.clipBox,this.getPathBoundingBox(t,e))}}function A0(a,t){if(typeof ImageData<"u"&&t instanceof ImageData){a.putImageData(t,0,0);return}const e=t.height,s=t.width,i=e%Ne,n=(e-i)/Ne,r=i===0?n:n+1,o=a.createImageData(s,Ne);let h=0,l;const d=t.data,u=o.data;let g,f,p,m;if(t.kind===Zc.GRAYSCALE_1BPP){const w=d.byteLength,v=new Uint32Array(u.buffer,0,u.byteLength>>2),x=v.length,S=s+7>>3,C=4294967295,E=ke.isLittleEndian?4278190080:255;for(g=0;g<r;g++){for(p=g<n?Ne:i,l=0,f=0;f<p;f++){const k=w-h;let P=0;const D=k>S?s:k*8-7,R=D&-8;let B=0,O=0;for(;P<R;P+=8)O=d[h++],v[l++]=O&128?C:E,v[l++]=O&64?C:E,v[l++]=O&32?C:E,v[l++]=O&16?C:E,v[l++]=O&8?C:E,v[l++]=O&4?C:E,v[l++]=O&2?C:E,v[l++]=O&1?C:E;for(;P<D;P++)B===0&&(O=d[h++],B=128),v[l++]=O&B?C:E,B>>=1}for(;l<x;)v[l++]=0;a.putImageData(o,0,g*Ne)}}else if(t.kind===Zc.RGBA_32BPP){for(f=0,m=s*Ne*4,g=0;g<n;g++)u.set(d.subarray(h,h+m)),h+=m,a.putImageData(o,0,f),f+=Ne;g<r&&(m=s*i*4,u.set(d.subarray(h,h+m)),a.putImageData(o,0,f))}else if(t.kind===Zc.RGB_24BPP)for(p=Ne,m=s*p,g=0;g<r;g++){for(g>=n&&(p=i,m=s*p),l=0,f=m;f--;)u[l++]=d[h++],u[l++]=d[h++],u[l++]=d[h++],u[l++]=255;a.putImageData(o,0,g*Ne)}else throw new Error(`bad image kind: ${t.kind}`)}function T0(a,t){if(t.bitmap){a.drawImage(t.bitmap,0,0);return}const e=t.height,s=t.width,i=e%Ne,n=(e-i)/Ne,r=i===0?n:n+1,o=a.createImageData(s,Ne);let h=0;const l=t.data,d=o.data;for(let u=0;u<r;u++){const g=u<n?Ne:i;({srcPos:h}=Ww({src:l,srcPos:h,dest:d,width:s,height:g,nonBlackColor:0})),a.putImageData(o,0,u*Ne)}}function ph(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 cd(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),!pe){const{filter:t}=a;t!=="none"&&t!==""&&(a.filter="none")}}function E0(a,t){if(t)return!0;const e=V.singularValueDecompose2dScale(a);e[0]=Math.fround(e[0]),e[1]=Math.fround(e[1]);const s=Math.fround((globalThis.devicePixelRatio||1)*mn.PDF_TO_CSS_UNITS);return e[0]<=s&&e[1]<=s}const Uw=["butt","round","square"],Yw=["miter","round","bevel"],qw={},k0={},Jg=class Jg{constructor(t,e,s,i,n,{optionalContentConfig:r,markedContentStack:o=null},h,l){_(this,On);this.ctx=t,this.current=new C0(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 Vw(this.canvasFactory),this.cachedPatterns=new Map,this.annotationCanvasMap=h,this.viewportScale=1,this.outputScaleX=1,this.outputScaleY=1,this.pageColors=l,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(...Et(this.compositeCtx))}this.ctx.save(),cd(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=Et(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 l=h-o>x0&&typeof s=="function",d=l?Date.now()+Xw:0;let u=0;const g=this.commonObjs,f=this.objs;let p;for(;;){if(i!==void 0&&o===i.nextBreakPoint)return i.breakIt(o,s),o;if(p=r[o],p!==Ts.dependency)this[p].apply(this,n[o]);else for(const m of n[o]){const w=m.startsWith("g_")?g:f;if(!w.has(m))return w.get(m,s),o}if(o++,o===h)return o;if(l&&++u>x0){if(Date.now()>d)return s(),o;u=0}}}endDrawing(){y(this,On,_f).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(),y(this,On,wf).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,l="prescale1",d,u;for(;n>2&&o>1||r>2&&h>1;){let g=o,f=h;n>2&&o>1&&(g=o>=16384?Math.floor(o/2)-1||1:Math.ceil(o/2),n/=o/g),r>2&&h>1&&(f=h>=16384?Math.floor(h/2)-1||1:Math.ceil(h)/2,r/=h/f),d=this.cachedCanvases.getCanvas(l,g,f),u=d.context,u.clearRect(0,0,g,f),u.drawImage(t,0,0,o,h,0,0,g,f),t=d.canvas,o=g,h=f,l=l==="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=Et(e);let h,l,d,u;if((t.bitmap||t.data)&&t.count>1){const D=t.bitmap||t.data.buffer;l=JSON.stringify(r?o:[o.slice(0,4),n]),h=this._cachedBitmapsMap.get(D),h||(h=new Map,this._cachedBitmapsMap.set(D,h));const R=h.get(l);if(R&&!r){const B=Math.round(Math.min(o[0],o[2])+o[4]),O=Math.round(Math.min(o[1],o[3])+o[5]);return{canvas:R,offsetX:B,offsetY:O}}d=R}d||(u=this.cachedCanvases.getCanvas("maskCanvas",s,i),T0(u.context,t));let g=V.transform(o,[1/s,0,0,-1/i,0,0]);g=V.transform(g,[1,0,0,1,0,-i]);const[f,p,m,w]=V.getAxialAlignedBoundingBox([0,0,s,i],g),v=Math.round(m-f)||1,x=Math.round(w-p)||1,S=this.cachedCanvases.getCanvas("fillCanvas",v,x),C=S.context,E=f,k=p;C.translate(-E,-k),C.transform(...g),d||(d=this._scaleImage(u.canvas,Ei(C)),d=d.img,h&&r&&h.set(l,d)),C.imageSmoothingEnabled=E0(Et(C),t.interpolate),ld(C,d,0,0,d.width,d.height,0,0,s,i),C.globalCompositeOperation="source-in";const P=V.transform(Ei(C),[1,0,0,1,-E,-k]);return C.fillStyle=r?n.getPattern(e,this,P,Me.FILL):n,C.fillRect(0,0,s,i),h&&!r&&(this.cachedCanvases.delete("fillCanvas"),h.set(l,S.canvas)),{canvas:S.canvas,offsetX:Math.round(E),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=Uw[t]}setLineJoin(t){this.ctx.lineJoin=Yw[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(...Et(this.suspendedCtx)),ph(this.suspendedCtx,n),zw(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(),ph(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,l,d,u){let g=t.canvas,f=h-d,p=l-u;if(r){const w=V.makeHexColor(...r);if(f<0||p<0||f+s>g.width||p+i>g.height){const v=this.cachedCanvases.getCanvas("maskExtension",s,i),x=v.context;x.drawImage(g,-f,-p),x.globalCompositeOperation="destination-atop",x.fillStyle=w,x.fillRect(0,0,s,i),x.globalCompositeOperation="source-over",g=v.canvas,f=p=0}else{t.save(),t.globalAlpha=1,t.setTransform(1,0,0,1,0,0);const v=new Path2D;v.rect(f,p,s,i),t.clip(v),t.globalCompositeOperation="destination-atop",t.fillStyle=w,t.fillRect(f,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 m=new Path2D;m.rect(h,l,s,i),e.clip(m),e.globalCompositeOperation="destination-in",e.drawImage(g,f,p,s,i,h,l,s,i),e.restore()}save(){this.inSMaskMode?(ph(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(),ph(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,l;const d=Et(i),u=d[0]===0&&d[3]===0||d[1]===0&&d[2]===0,g=u?s.slice(0):null;for(let f=0,p=0,m=t.length;f<m;f++)switch(t[f]|0){case Ts.rectangle:r=e[p++],o=e[p++];const w=e[p++],v=e[p++],x=r+w,S=o+v;i.moveTo(r,o),w===0||v===0?i.lineTo(x,S):(i.lineTo(x,o),i.lineTo(x,S),i.lineTo(r,S)),u||n.updateRectMinMax(d,[r,o,x,S]),i.closePath();break;case Ts.moveTo:r=e[p++],o=e[p++],i.moveTo(r,o),u||n.updatePathMinMax(d,r,o);break;case Ts.lineTo:r=e[p++],o=e[p++],i.lineTo(r,o),u||n.updatePathMinMax(d,r,o);break;case Ts.curveTo:h=r,l=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(d,h,l,e[p],e[p+1],e[p+2],e[p+3],r,o,g),p+=6;break;case Ts.curveTo2:h=r,l=o,i.bezierCurveTo(r,o,e[p],e[p+1],e[p+2],e[p+3]),n.updateCurvePathMinMax(d,h,l,r,o,e[p],e[p+1],e[p+2],e[p+3],g),r=e[p+2],o=e[p+3],p+=4;break;case Ts.curveTo3:h=r,l=o,r=e[p+2],o=e[p+3],i.bezierCurveTo(e[p],e[p+1],r,o,r,o),n.updateCurvePathMinMax(d,h,l,e[p],e[p+1],r,o,r,o,g),p+=4;break;case Ts.closePath:i.closePath();break}u&&n.updateScalingPathMinMax(d,g),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,Ei(e),Me.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,Ei(e),Me.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=qw}eoClip(){this.pendingClip=k0}beginText(){this.current.textMatrix=i0,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}e.save(),e.beginPath();for(const s of t)e.setTransform(...s.transform),e.translate(s.x,s.y),s.addToPath(e,s.fontSize);e.restore(),e.clip(),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 d;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||ug,(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=((d=s.systemFontInfo)==null?void 0:d.css)||`"${n}", ${s.fallbackName}`;let o="normal";s.black?o="900":s.bold&&(o="bold");const h=s.italic?"italic":"normal";let l=e;e<_0?l=_0:e>w0&&(l=w0),this.current.fontSizeScale=e/l,this.ctx.font=`${h} ${o} ${l}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){const n=this.ctx,r=this.current,o=r.font,h=r.textRenderingMode,l=r.fontSize/r.fontSizeScale,d=h&me.FILL_STROKE_MASK,u=!!(h&me.ADD_TO_PATH_FLAG),g=r.patternFill&&!o.missingFile;let f;(o.disableFontFace||u||g)&&(f=o.getPathGenerator(this.commonObjs,t)),o.disableFontFace||g?(n.save(),n.translate(e,s),n.beginPath(),f(n,l),i&&n.setTransform(...i),(d===me.FILL||d===me.FILL_STROKE)&&n.fill(),(d===me.STROKE||d===me.FILL_STROKE)&&n.stroke(),n.restore()):((d===me.FILL||d===me.FILL_STROKE)&&n.fillText(t,e,s),(d===me.STROKE||d===me.FILL_STROKE)&&n.strokeText(t,e,s)),u&&(this.pendingTextPaths||(this.pendingTextPaths=[])).push({transform:Et(n),x:e,y:s,fontSize:l,addToPath:f})}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 ot(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,l=e.fontDirection,d=e.textHScale*l,u=t.length,g=s.vertical,f=g?1:-1,p=s.defaultVMetrics,m=i*e.fontMatrix[0],w=e.textRenderingMode===me.FILL&&!s.disableFontFace&&!e.patternFill;n.save(),n.transform(...e.textMatrix),n.translate(e.x,e.y+e.textRise),l>0?n.scale(d,-1):n.scale(d,1);let v;if(e.patternFill){n.save();const k=e.fillColor.getPattern(n,this,Ei(n),Me.FILL);v=Et(n),n.restore(),n.fillStyle=k}let x=e.lineWidth;const S=e.textMatrixScale;if(S===0||x===0){const k=e.textRenderingMode&me.FILL_STROKE_MASK;(k===me.STROKE||k===me.FILL_STROKE)&&(x=this.getSinglePixelWidth())}else x/=S;if(r!==1&&(n.scale(r,r),x/=r),n.lineWidth=x,s.isInvalidPDFjsFont){const k=[];let P=0;for(const D of t)k.push(D.unicode),P+=D.width;n.fillText(k.join(""),0,0),e.x+=P*m*d,n.restore(),this.compose();return}let C=0,E;for(E=0;E<u;++E){const k=t[E];if(typeof k=="number"){C+=f*k*i/1e3;continue}let P=!1;const D=(k.isSpace?h:0)+o,R=k.fontChar,B=k.accent;let O,F,L=k.width;if(g){const G=k.vmetric||p,Y=-(k.vmetric?G[1]:L*.5)*m,z=G[2]*m;L=G?-G[0]:L,O=Y/r,F=(C+z)/r}else O=C/r,F=0;if(s.remeasure&&L>0){const G=n.measureText(R).width*1e3/i*r;if(L<G&&this.isFontSubpixelAAEnabled){const Y=L/G;P=!0,n.save(),n.scale(Y,1),O/=Y}else L!==G&&(O+=(L-G)/2e3*i/r)}if(this.contentVisible&&(k.isInFont||s.missingFile)){if(w&&!B)n.fillText(R,O,F);else if(this.paintChar(R,O,F,v),B){const G=O+i*B.offset.x/r,Y=F-i*B.offset.y/r;this.paintChar(B.fontChar,G,Y,v)}}const I=g?L*m-D*l:L*m+D*l;C+=I,P&&n.restore()}g?e.y-=C:e.x+=C*d,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,l=s.wordSpacing,d=s.textHScale*r,u=s.fontMatrix||ug,g=t.length,f=s.textRenderingMode===me.INVISIBLE;let p,m,w,v;if(!(f||n===0)){for(this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null,e.save(),e.transform(...s.textMatrix),e.translate(s.x,s.y),e.scale(d,r),p=0;p<g;++p){if(m=t[p],typeof m=="number"){v=o*m*n/1e3,this.ctx.translate(v,0),s.x+=v*d;continue}const x=(m.isSpace?l:0)+h,S=i.charProcOperatorList[m.operatorListId];if(!S){st(`Type3 character "${m.operatorListId}" is not available.`);continue}this.contentVisible&&(this.processingType3=m,this.save(),e.scale(n,n),e.transform(...u),this.executeOperatorList(S),this.restore()),w=V.applyTransform([m.width,0],u)[0]*n+x,e.translate(w,0),s.x+=w*d}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||Et(this.ctx),n={createCanvasGraphics:r=>new Jg(r,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack})};e=new Fg(t,s,this.ctx,n,i)}else e=this._getPattern(t[1],t[2]);return e}setStrokeColorN(){this.current.strokeColor=this.getColorN_Pattern(arguments)}setFillColorN(){this.current.fillColor=this.getColorN_Pattern(arguments),this.current.patternFill=!0}setStrokeRGBColor(t,e,s){this.ctx.strokeStyle=this.current.strokeColor=V.makeHexColor(t,e,s)}setStrokeTransparent(){this.ctx.strokeStyle=this.current.strokeColor="transparent"}setFillRGBColor(t,e,s){this.ctx.fillStyle=this.current.fillColor=V.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=Hw(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,Ei(e),Me.SHADING);const i=Ei(e);if(i){const{width:n,height:r}=e.canvas,[o,h,l,d]=V.getAxialAlignedBoundingBox([0,0,n,r],i);this.ctx.fillRect(o,h,l-o,d-h)}else this.ctx.fillRect(-1e10,-1e10,2e10,2e10);this.compose(this.current.getClippedPathBoundingBox()),this.restore()}beginInlineImage(){wt("Should not call beginInlineImage")}beginImageData(){wt("Should not call beginImageData")}paintFormXObjectBegin(t,e){if(this.contentVisible&&(this.save(),this.baseTransformStack.push(this.baseTransform),t&&this.transform(...t),this.baseTransform=Et(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(Et(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||sd("TODO: Support non-isolated groups."),t.knockout&&st("Knockout groups not supported.");const s=Et(e);if(t.matrix&&e.transform(...t.matrix),!t.bbox)throw new Error("Bounding box is required.");let i=V.getAxialAlignedBoundingBox(t.bbox,Et(e));const n=[0,0,e.canvas.width,e.canvas.height];i=V.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),l=Math.max(Math.ceil(i[3])-o,1);this.current.startNewPathAndClipBox([0,0,h,l]);let d="groupAt"+this.groupLevel;t.smask&&(d+="_smask_"+this.smaskCounter++%2);const u=this.cachedCanvases.getCanvas(d,h,l),g=u.context;g.translate(-r,-o),g.transform(...s),t.smask?this.smaskStack.push({canvas:u.canvas,context:g,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()),ph(e,g),this.ctx=g,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=Et(this.ctx);this.restore(),this.ctx.save(),this.ctx.setTransform(...i);const n=V.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(y(this,On,_f).call(this),cd(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,l]=V.singularValueDecompose2dScale(Et(this.ctx)),{viewportScale:d}=this,u=Math.ceil(r*this.outputScaleX*d),g=Math.ceil(o*this.outputScaleY*d);this.annotationCanvas=this.canvasFactory.create(u,g);const{canvas:f,context:p}=this.annotationCanvas;this.annotationCanvasMap.set(t,f),this.annotationCanvas.savedCtx=this.ctx,this.ctx=p,this.ctx.save(),this.ctx.setTransform(h,0,0,-l,0,o*l),cd(this.ctx)}else cd(this.ctx),this.endPath(),this.ctx.rect(e[0],e[1],r,o),this.ctx.clip(),this.ctx.beginPath()}this.current=new C0(this.ctx.canvas.width,this.ctx.canvas.height),this.transform(...s),this.transform(...i)}endAnnotation(){this.annotationCanvas&&(this.ctx.restore(),y(this,On,wf).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=Gw(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=Et(o);o.transform(e,s,i,n,0,0);const l=this._createMaskCanvas(t);o.setTransform(1,0,0,1,l.offsetX-h[4],l.offsetY-h[5]);for(let d=0,u=r.length;d<u;d+=2){const g=V.transform(h,[e,s,i,n,r[d],r[d+1]]),[f,p]=V.applyTransform([0,0],g);o.drawImage(l.canvas,f,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:l}=n,d=this.cachedCanvases.getCanvas("maskCanvas",o,h),u=d.context;u.save();const g=this.getObject(r,n);T0(u,g),u.globalCompositeOperation="source-in",u.fillStyle=i?s.getPattern(u,this,Ei(e),Me.FILL):s,u.fillRect(0,0,o,h),u.restore(),e.save(),e.transform(...l),e.scale(1,-1),ld(e,d.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 l=0,d=i.length;l<d;l+=2)h.push({transform:[e,0,0,s,i[l],i[l+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(),!pe){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;A0(h,t),n=this.applyTransferMapsToCanvas(h)}const r=this._scaleImage(n,Ei(i));i.imageSmoothingEnabled=E0(Et(i),t.interpolate),ld(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;A0(h,t),i=this.applyTransferMapsToCanvas(h)}for(const n of e)s.save(),s.transform(...n.transform),s.scale(1,-1),ld(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===k0?s.clip("evenodd"):s.clip()),this.pendingClip=null),this.current.startNewPathAndClipBox(this.current.clipBox),s.beginPath()}getSinglePixelWidth(){if(!this._cachedGetSinglePixelWidth){const t=Et(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),l=Math.abs(n);if(h===l)if(t===0)r=o=1/h;else{const d=h*t;r=o=d<1?1/d:1}else if(t===0)r=1/h,o=1/l;else{const d=h*t,u=l*t;r=d<1?1/d:1,o=u<1?1/u:1}}else{const h=Math.abs(e*n-s*i),l=Math.hypot(e,s),d=Math.hypot(i,n);if(t===0)r=d/h,o=l/h;else{const u=t*h;r=d>u?d/u:1,o=l>u?l/u: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}};On=new WeakSet,_f=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)},wf=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}}};let jo=Jg;for(const a in Ts)jo.prototype[a]!==void 0&&(jo.prototype[Ts[a]]=jo.prototype[a]);class ki{static get workerPort(){return c(this,Xh)}static set workerPort(t){if(!(typeof Worker<"u"&&t instanceof Worker)&&t!==null)throw new Error("Invalid `workerPort` type.");b(this,Xh,t)}static get workerSrc(){return c(this,zh)}static set workerSrc(t){if(typeof t!="string")throw new Error("Invalid `workerSrc` type.");b(this,zh,t)}}Xh=new WeakMap,zh=new WeakMap,_(ki,Xh,null),_(ki,zh,"");const dd={UNKNOWN:0,DATA:1,ERROR:2},zt={UNKNOWN:0,CANCEL:1,CANCEL_COMPLETE:2,CLOSE:3,ENQUEUE:4,ERROR:5,PULL:6,PULL_COMPLETE:7,START_COMPLETE:8};function qe(a){switch(a instanceof Error||typeof a=="object"&&a!==null||wt('wrapReason: Expected "reason" to be a (possibly cloned) Error.'),a.name){case"AbortException":return new lr(a.message);case"MissingPDFException":return new hr(a.message);case"PasswordException":return new fg(a.message,a.code);case"UnexpectedResponseException":return new id(a.message,a.status);case"UnknownErrorException":return new pg(a.message,a.details);default:return new pg(a.message,a.toString())}}class mh{constructor(t,e,s){_(this,us);_(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",y(this,us,Eb).bind(this),{signal:c(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:l=>{const d=Promise.withResolvers();return this.streamControllers[n]={controller:l,startCall:d,pullCall:null,cancelCall:null,isClosed:!1},h.postMessage({sourceName:r,targetName:o,action:t,streamId:n,data:e,desiredSize:l.desiredSize},i),d.promise},pull:l=>{const d=Promise.withResolvers();return this.streamControllers[n].pullCall=d,h.postMessage({sourceName:r,targetName:o,stream:zt.PULL,streamId:n,desiredSize:l.desiredSize}),d.promise},cancel:l=>{qt(l instanceof Error,"cancel must have a valid reason");const d=Promise.withResolvers();return this.streamControllers[n].cancelCall=d,this.streamControllers[n].isClosed=!0,h.postMessage({sourceName:r,targetName:o,stream:zt.CANCEL,streamId:n,reason:qe(l)}),d.promise}},s)}destroy(){var t;(t=c(this,ea))==null||t.abort(),b(this,ea,null)}}ea=new WeakMap,us=new WeakSet,Eb=function({data:t}){if(t.targetName!==this.sourceName)return;if(t.stream){y(this,us,Mb).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===dd.DATA)i.resolve(t.data);else if(t.callback===dd.ERROR)i.reject(qe(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;new Promise(function(r){r(e(t.data))}).then(function(r){n.postMessage({sourceName:s,targetName:i,callback:dd.DATA,callbackId:t.callbackId,data:r})},function(r){n.postMessage({sourceName:s,targetName:i,callback:dd.ERROR,callbackId:t.callbackId,reason:qe(r)})});return}if(t.streamId){y(this,us,kb).call(this,t);return}e(t.data)},kb=function(t){const e=t.streamId,s=this.sourceName,i=t.sourceName,n=this.comObj,r=this,o=this.actionHandler[t.action],h={enqueue(l,d=1,u){if(this.isCancelled)return;const g=this.desiredSize;this.desiredSize-=d,g>0&&this.desiredSize<=0&&(this.sinkCapability=Promise.withResolvers(),this.ready=this.sinkCapability.promise),n.postMessage({sourceName:s,targetName:i,stream:zt.ENQUEUE,streamId:e,chunk:l},u)},close(){this.isCancelled||(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:zt.CLOSE,streamId:e}),delete r.streamSinks[e])},error(l){qt(l instanceof Error,"error must have a valid reason"),!this.isCancelled&&(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:zt.ERROR,streamId:e,reason:qe(l)}))},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,new Promise(function(l){l(o(t.data,h))}).then(function(){n.postMessage({sourceName:s,targetName:i,stream:zt.START_COMPLETE,streamId:e,success:!0})},function(l){n.postMessage({sourceName:s,targetName:i,stream:zt.START_COMPLETE,streamId:e,reason:qe(l)})})},Mb=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 zt.START_COMPLETE:t.success?r.startCall.resolve():r.startCall.reject(qe(t.reason));break;case zt.PULL_COMPLETE:t.success?r.pullCall.resolve():r.pullCall.reject(qe(t.reason));break;case zt.PULL:if(!o){n.postMessage({sourceName:s,targetName:i,stream:zt.PULL_COMPLETE,streamId:e,success:!0});break}o.desiredSize<=0&&t.desiredSize>0&&o.sinkCapability.resolve(),o.desiredSize=t.desiredSize,new Promise(function(h){var l;h((l=o.onPull)==null?void 0:l.call(o))}).then(function(){n.postMessage({sourceName:s,targetName:i,stream:zt.PULL_COMPLETE,streamId:e,success:!0})},function(h){n.postMessage({sourceName:s,targetName:i,stream:zt.PULL_COMPLETE,streamId:e,reason:qe(h)})});break;case zt.ENQUEUE:if(qt(r,"enqueue should have stream controller"),r.isClosed)break;r.controller.enqueue(t.chunk);break;case zt.CLOSE:if(qt(r,"close should have stream controller"),r.isClosed)break;r.isClosed=!0,r.controller.close(),y(this,us,Vd).call(this,r,e);break;case zt.ERROR:qt(r,"error should have stream controller"),r.controller.error(qe(t.reason)),y(this,us,Vd).call(this,r,e);break;case zt.CANCEL_COMPLETE:t.success?r.cancelCall.resolve():r.cancelCall.reject(qe(t.reason)),y(this,us,Vd).call(this,r,e);break;case zt.CANCEL:if(!o)break;new Promise(function(h){var l;h((l=o.onCancel)==null?void 0:l.call(o,qe(t.reason)))}).then(function(){n.postMessage({sourceName:s,targetName:i,stream:zt.CANCEL_COMPLETE,streamId:e,success:!0})},function(h){n.postMessage({sourceName:s,targetName:i,stream:zt.CANCEL_COMPLETE,streamId:e,reason:qe(h)})}),o.sinkCapability.reject(qe(t.reason)),o.isCancelled=!0,delete this.streamSinks[e];break;default:throw new Error("Unexpected stream case")}},Vd=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 $w{constructor({parsedData:t,rawData:e}){_(this,Fr);_(this,Vh);b(this,Fr,t),b(this,Vh,e)}getRaw(){return c(this,Vh)}get(t){return c(this,Fr).get(t)??null}getAll(){return mg(c(this,Fr))}has(t){return c(this,Fr).has(t)}}Fr=new WeakMap,Vh=new WeakMap;const No=Symbol("INTERNAL");class Kw{constructor(t,{name:e,intent:s,usage:i,rbGroups:n}){_(this,Gh,!1);_(this,Uh,!1);_(this,Yh,!1);_(this,sa,!0);b(this,Gh,!!(t&Ye.DISPLAY)),b(this,Uh,!!(t&Ye.PRINT)),this.name=e,this.intent=s,this.usage=i,this.rbGroups=n}get visible(){if(c(this,Yh))return c(this,sa);if(!c(this,sa))return!1;const{print:t,view:e}=this.usage;return c(this,Gh)?(e==null?void 0:e.viewState)!=="OFF":c(this,Uh)?(t==null?void 0:t.printState)!=="OFF":!0}_setVisible(t,e,s=!1){t!==No&&wt("Internal method `_setVisible` called."),b(this,Yh,s),b(this,sa,e)}}Gh=new WeakMap,Uh=new WeakMap,Yh=new WeakMap,sa=new WeakMap;class Qw{constructor(t,e=Ye.DISPLAY){_(this,qh);_(this,Dn,null);_(this,pt,new Map);_(this,ia,null);_(this,na,null);if(this.renderingIntent=e,this.name=null,this.creator=null,t!==null){this.name=t.name,this.creator=t.creator,b(this,na,t.order);for(const s of t.groups)c(this,pt).set(s.id,new Kw(e,s));if(t.baseState==="OFF")for(const s of c(this,pt).values())s._setVisible(No,!1);for(const s of t.on)c(this,pt).get(s)._setVisible(No,!0);for(const s of t.off)c(this,pt).get(s)._setVisible(No,!1);b(this,ia,this.getHash())}}isVisible(t){if(c(this,pt).size===0)return!0;if(!t)return sd("Optional content group not defined."),!0;if(t.type==="OCG")return c(this,pt).has(t.id)?c(this,pt).get(t.id).visible:(st(`Optional content group not found: ${t.id}`),!0);if(t.type==="OCMD"){if(t.expression)return y(this,qh,xf).call(this,t.expression);if(!t.policy||t.policy==="AnyOn"){for(const e of t.ids){if(!c(this,pt).has(e))return st(`Optional content group not found: ${e}`),!0;if(c(this,pt).get(e).visible)return!0}return!1}else if(t.policy==="AllOn"){for(const e of t.ids){if(!c(this,pt).has(e))return st(`Optional content group not found: ${e}`),!0;if(!c(this,pt).get(e).visible)return!1}return!0}else if(t.policy==="AnyOff"){for(const e of t.ids){if(!c(this,pt).has(e))return st(`Optional content group not found: ${e}`),!0;if(!c(this,pt).get(e).visible)return!0}return!1}else if(t.policy==="AllOff"){for(const e of t.ids){if(!c(this,pt).has(e))return st(`Optional content group not found: ${e}`),!0;if(c(this,pt).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=c(this,pt).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=c(this,pt).get(o))==null||n._setVisible(No,!1,!0));i._setVisible(No,!!e,!0),b(this,Dn,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=c(this,pt).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}}b(this,Dn,null)}get hasInitialVisibility(){return c(this,ia)===null||this.getHash()===c(this,ia)}getOrder(){return c(this,pt).size?c(this,na)?c(this,na).slice():[...c(this,pt).keys()]:null}getGroups(){return c(this,pt).size>0?mg(c(this,pt)):null}getGroup(t){return c(this,pt).get(t)||null}getHash(){if(c(this,Dn)!==null)return c(this,Dn);const t=new c0;for(const[e,s]of c(this,pt))t.update(`${e}:${s.visible}`);return b(this,Dn,t.hexdigest())}}Dn=new WeakMap,pt=new WeakMap,ia=new WeakMap,na=new WeakMap,qh=new WeakSet,xf=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=y(this,qh,xf).call(this,n);else if(c(this,pt).has(n))r=c(this,pt).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 Jw{constructor(t,{disableRange:e=!1,disableStream:s=!1}){qt(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,l)=>{this._onReceiveData({begin:h,chunk:l})}),t.addProgressListener((h,l)=>{this._onProgress({loaded:h,total:l})}),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)});qt(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(){qt(!this._fullRequestReader,"PDFDataTransportStream.getFullReader can only be called once.");const t=this._queuedChunks;return this._queuedChunks=null,new Zw(this,t,this._progressiveDone,this._contentDispositionFilename)}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new tx(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 Zw{constructor(t,e,s=!1,i=null){this._stream=t,this._done=s||!1,this._filename=wg(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 tx{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 ex(a){let t=!0,e=s("filename\\*","i").exec(a);if(e){e=e[1];let d=o(e);return d=unescape(d),d=h(d),d=l(d),n(d)}if(e=r(a),e){const d=l(e);return n(d)}if(e=s("filename","i").exec(a),e){e=e[1];let d=o(e);return d=l(d),n(d)}function s(d,u){return new RegExp("(?:^|;)\\s*"+d+'\\s*=\\s*([^";\\s][^;\\s]*|"(?:[^"\\\\]|\\\\"?)+"?)',u)}function i(d,u){if(d){if(!/^[\x00-\xFF]+$/.test(u))return u;try{const g=new TextDecoder(d,{fatal:!0}),f=nd(u);u=g.decode(f),t=!1}catch{}}return u}function n(d){return t&&/[\x80-\xff]/.test(d)&&(d=i("utf-8",d),t&&(d=i("iso-8859-1",d))),d}function r(d){const u=[];let g;const f=s("filename\\*((?!0\\d)\\d+)(\\*?)","ig");for(;(g=f.exec(d))!==null;){let[,m,w,v]=g;if(m=parseInt(m,10),m in u){if(m===0)break;continue}u[m]=[w,v]}const p=[];for(let m=0;m<u.length&&m in u;++m){let[w,v]=u[m];v=o(v),w&&(v=unescape(v),m===0&&(v=h(v))),p.push(v)}return p.join("")}function o(d){if(d.startsWith('"')){const u=d.slice(1).split('\\"');for(let g=0;g<u.length;++g){const f=u[g].indexOf('"');f!==-1&&(u[g]=u[g].slice(0,f),u.length=g+1),u[g]=u[g].replaceAll(/\\(.)/g,"$1")}d=u.join('"')}return d}function h(d){const u=d.indexOf("'");if(u===-1)return d;const g=d.slice(0,u),p=d.slice(u+1).replace(/^[^']*'/,"");return i(g,p)}function l(d){return!d.startsWith("=?")||/[\x00-\x19\x80-\xff]/.test(d)?d:d.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,function(u,g,f,p){if(f==="q"||f==="Q")return p=p.replaceAll("_"," "),p=p.replaceAll(/=([0-9a-fA-F]{2})/g,function(m,w){return String.fromCharCode(parseInt(w,16))}),i(g,p);try{p=atob(p)}catch{}return i(g,p)})}return""}function Rg(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 Ig({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 jg(a){const t=a.get("Content-Disposition");if(t){let e=ex(t);if(e.includes("%"))try{e=decodeURIComponent(e)}catch{}if(wg(e))return e}return null}function ud(a,t){return a===404||a===0&&t.startsWith("file:")?new hr('Missing PDF "'+t+'".'):new id(`Unexpected server response (${a}) while retrieving PDF "${t}".`,a)}function M0(a){return a===200||a===206}function O0(a,t,e){return{method:"GET",headers:a,signal:e.signal,mode:"cors",credentials:t?"include":"same-origin",redirect:"follow"}}function D0(a){return a instanceof Uint8Array?a.buffer:a instanceof ArrayBuffer?a:(st(`getArrayBuffer - unexpected data format: ${a}`),new Uint8Array(a).buffer)}class P0{constructor(t){this.source=t,this.isHttp=/^https?:/i.test(t.url),this.headers=Rg(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 qt(!this._fullRequestReader,"PDFFetchStream.getFullReader can only be called once."),this._fullRequestReader=new sx(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new ix(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 sx{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,O0(s,this._withCredentials,this._abortController)).then(n=>{if(!M0(n.status))throw ud(n.status,i);this._reader=n.body.getReader(),this._headersCapability.resolve();const r=n.headers,{allowRangeRequests:o,suggestedLength:h}=Ig({responseHeaders:r,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=o,this._contentLength=h||this._contentLength,this._filename=jg(r),!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new lr("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:D0(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}class ix{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,O0(n,this._withCredentials,this._abortController)).then(o=>{if(!M0(o.status))throw ud(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:D0(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}const Ng=200,Bg=206;function nx(a){const t=a.response;return typeof t!="string"?t:nd(t).buffer}class rx{constructor({url:t,httpHeaders:e,withCredentials:s}){this.url=t,this.isHttp=/^https?:/i.test(t),this.headers=Rg(this.isHttp,e),this.withCredentials=s||!1,this.currXhrId=0,this.pendingRequests=Object.create(null)}requestRange(t,e,s){const i={begin:t,end:e};for(const n in s)i[n]=s[n];return this.request(i)}requestFull(t){return this.request(t)}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=Bg):i.expectedStatus=Ng,e.responseType="arraybuffer",t.onError&&(e.onerror=function(n){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){var h,l,d;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){(h=s.onError)==null||h.call(s,i.status);return}const n=i.status||Ng;if(!(n===Ng&&s.expectedStatus===Bg)&&n!==s.expectedStatus){(l=s.onError)==null||l.call(s,i.status);return}const o=nx(i);if(n===Bg){const u=i.getResponseHeader("Content-Range"),g=/bytes (\d+)-(\d+)\/(\d+)/.exec(u);s.onDone({begin:parseInt(g[1],10),chunk:o})}else o?s.onDone({begin:0,chunk:o}):(d=s.onError)==null||d.call(s,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 ox{constructor(t){this._source=t,this._manager=new rx(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 qt(!this._fullRequestReader,"PDFNetworkStream.getFullReader can only be called once."),this._fullRequestReader=new ax(this._manager,this._source),this._fullRequestReader}getRangeReader(t,e){const s=new hx(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 ax{constructor(t,e){this._manager=t;const s={onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)};this._url=e.url,this._fullRequestId=t.requestFull(s),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),s=new Headers(e.getAllResponseHeaders().trim().split(/[\r\n]+/).map(r=>{const[o,...h]=r.split(": ");return[o,h.join(": ")]})),{allowRangeRequests:i,suggestedLength:n}=Ig({responseHeaders:s,isHttp:this._manager.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});i&&(this._isRangeSupported=!0),this._contentLength=n||this._contentLength,this._filename=jg(s),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=ud(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(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 hx{constructor(t,e,s){this._manager=t;const i={onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)};this._url=t.url,this._requestId=t.requestRange(e,s,i),this._requests=[],this._queuedChunk=null,this._done=!1,this._storedError=void 0,this.onProgress=null,this.onClosed=null}_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=ud(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 lx=/^[a-z][a-z0-9\-+.]+:/i;function cx(a){if(lx.test(a))return new URL(a);const t=bn.get("url");return new URL(t.pathToFileURL(a))}function L0(a,t,e){return a.protocol==="http:"?bn.get("http").request(a,{headers:t},e):bn.get("https").request(a,{headers:t},e)}class dx{constructor(t){this.source=t,this.url=cx(t.url),this.isHttp=this.url.protocol==="http:"||this.url.protocol==="https:",this.isFsUrl=this.url.protocol==="file:",this.headers=Rg(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 qt(!this._fullRequestReader,"PDFNodeStream.getFullReader can only be called once."),this._fullRequestReader=this.isFsUrl?new fx(this):new ux(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=this.isFsUrl?new px(this,t,e):new gx(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 F0{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()}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 lr("streaming is disabled")),this._storedError&&this._readableStream.destroy(this._storedError)}}class R0{constructor(t){this._url=t.url,this._done=!1,this._storedError=null,this.onProgress=null,this._loaded=0,this._readableStream=null,this._readCapability=Promise.withResolvers();const e=t.source;this._isStreamingSupported=!e.disableStream}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)}}class ux extends F0{constructor(t){super(t);const e=Object.fromEntries(t.headers),s=i=>{if(i.statusCode===404){const h=new hr(`Missing PDF "${this._url}".`);this._storedError=h,this._headersCapability.reject(h);return}this._headersCapability.resolve(),this._setReadableStream(i);const n=new Headers(this._readableStream.headers),{allowRangeRequests:r,suggestedLength:o}=Ig({responseHeaders:n,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=r,this._contentLength=o||this._contentLength,this._filename=jg(n)};this._request=L0(this._url,e,s),this._request.on("error",i=>{this._storedError=i,this._headersCapability.reject(i)}),this._request.end()}}class gx extends R0{constructor(t,e,s){super(t);const i=Object.fromEntries(t.headers);i.Range=`bytes=${e}-${s-1}`;const n=r=>{if(r.statusCode===404){const o=new hr(`Missing PDF "${this._url}".`);this._storedError=o;return}this._setReadableStream(r)};this._request=L0(this._url,i,n),this._request.on("error",r=>{this._storedError=r}),this._request.end()}}class fx extends F0{constructor(t){super(t);const e=bn.get("fs");e.promises.lstat(this._url).then(s=>{this._contentLength=s.size,this._setReadableStream(e.createReadStream(this._url)),this._headersCapability.resolve()},s=>{s.code==="ENOENT"&&(s=new hr(`Missing PDF "${this._url}".`)),this._storedError=s,this._headersCapability.reject(s)})}}class px extends R0{constructor(t,e,s){super(t);const i=bn.get("fs");this._setReadableStream(i.createReadStream(this._url,{start:e,end:s-1}))}}const mx=1e5,Be=30,bx=.8,Kt=class Kt{constructor({textContentSource:t,container:e,viewport:s}){_(this,Bi);_(this,Pn,Promise.withResolvers());_(this,We,null);_(this,$h,!1);_(this,Kh,!!((Z0=globalThis.FontInspector)!=null&&Z0.enabled));_(this,Rr,null);_(this,Ni,null);_(this,Qh,0);_(this,Jh,0);_(this,Ir,null);_(this,ra,null);_(this,oa,0);_(this,Ln,0);_(this,aa,Object.create(null));_(this,Zh,[]);_(this,ha,null);_(this,jr,[]);_(this,tl,new WeakMap);_(this,el,null);var h;if(t instanceof ReadableStream)b(this,ha,t);else if(typeof t=="object")b(this,ha,new ReadableStream({start(l){l.enqueue(t),l.close()}}));else throw new Error('No "textContentSource" parameter specified.');b(this,We,b(this,ra,e)),b(this,Ln,s.scale*(globalThis.devicePixelRatio||1)),b(this,oa,s.rotation),b(this,Ni,{div:null,properties:null,ctx:null});const{pageWidth:i,pageHeight:n,pageX:r,pageY:o}=s.rawDims;b(this,el,[1,0,0,-1,-r,o+n]),b(this,Jh,i),b(this,Qh,n),y(h=Kt,Qe,Pb).call(h),cr(e,s),c(this,Pn).promise.finally(()=>{c(Kt,la).delete(this),b(this,Ni,null),b(this,aa,null)}).catch(()=>{})}static get fontFamilyMap(){const{isWindows:t,isFirefox:e}=ke.platform;return ot(this,"fontFamilyMap",new Map([["sans-serif",`${t&&e?"Calibri, ":""}sans-serif`],["monospace",`${t&&e?"Lucida Console, ":""}monospace`]]))}render(){const t=()=>{c(this,Ir).read().then(({value:e,done:s})=>{if(s){c(this,Pn).resolve();return}c(this,Rr)??b(this,Rr,e.lang),Object.assign(c(this,aa),e.styles),y(this,Bi,Ob).call(this,e.items),t()},c(this,Pn).reject)};return b(this,Ir,c(this,ha).getReader()),c(Kt,la).add(this),t(),c(this,Pn).promise}update({viewport:t,onBefore:e=null}){var n;const s=t.scale*(globalThis.devicePixelRatio||1),i=t.rotation;if(i!==c(this,oa)&&(e==null||e(),b(this,oa,i),cr(c(this,ra),{rotation:i})),s!==c(this,Ln)){e==null||e(),b(this,Ln,s);const r={div:null,properties:null,ctx:y(n=Kt,Qe,Gd).call(n,c(this,Rr))};for(const o of c(this,jr))r.properties=c(this,tl).get(o),r.div=o,y(this,Bi,Sf).call(this,r)}}cancel(){var e;const t=new lr("TextLayer task cancelled.");(e=c(this,Ir))==null||e.cancel(t).catch(()=>{}),b(this,Ir,null),c(this,Pn).reject(t)}get textDivs(){return c(this,jr)}get textContentItemsStr(){return c(this,Zh)}static cleanup(){if(!(c(this,la).size>0)){c(this,Nr).clear();for(const{canvas:t}of c(this,Br).values())t.remove();c(this,Br).clear()}}};Pn=new WeakMap,We=new WeakMap,$h=new WeakMap,Kh=new WeakMap,Rr=new WeakMap,Ni=new WeakMap,Qh=new WeakMap,Jh=new WeakMap,Ir=new WeakMap,ra=new WeakMap,oa=new WeakMap,Ln=new WeakMap,aa=new WeakMap,Zh=new WeakMap,ha=new WeakMap,jr=new WeakMap,tl=new WeakMap,el=new WeakMap,Nr=new WeakMap,Br=new WeakMap,sl=new WeakMap,Fn=new WeakMap,la=new WeakMap,Bi=new WeakSet,Ob=function(t){var i,n;if(c(this,$h))return;(n=c(this,Ni)).ctx??(n.ctx=y(i=Kt,Qe,Gd).call(i,c(this,Rr)));const e=c(this,jr),s=c(this,Zh);for(const r of t){if(e.length>mx){st("Ignoring additional textDivs for performance reasons."),b(this,$h,!0);return}if(r.str===void 0){if(r.type==="beginMarkedContentProps"||r.type==="beginMarkedContent"){const o=c(this,We);b(this,We,document.createElement("span")),c(this,We).classList.add("markedContent"),r.id!==null&&c(this,We).setAttribute("id",`${r.id}`),o.append(c(this,We))}else r.type==="endMarkedContent"&&b(this,We,c(this,We).parentNode);continue}s.push(r.str),y(this,Bi,Db).call(this,r)}},Db=function(t){var m;const e=document.createElement("span"),s={angle:0,canvasWidth:0,hasText:t.str!=="",hasEOL:t.hasEOL,fontSize:0};c(this,jr).push(e);const i=V.transform(c(this,el),t.transform);let n=Math.atan2(i[1],i[0]);const r=c(this,aa)[t.fontName];r.vertical&&(n+=Math.PI/2);let o=c(this,Kh)&&r.fontSubstitution||r.fontFamily;o=Kt.fontFamilyMap.get(o)||o;const h=Math.hypot(i[2],i[3]),l=h*y(m=Kt,Qe,Lb).call(m,o,c(this,Rr));let d,u;n===0?(d=i[4],u=i[5]-l):(d=i[4]+l*Math.sin(n),u=i[5]-l*Math.cos(n));const g="calc(var(--scale-factor)*",f=e.style;c(this,We)===c(this,ra)?(f.left=`${(100*d/c(this,Jh)).toFixed(2)}%`,f.top=`${(100*u/c(this,Qh)).toFixed(2)}%`):(f.left=`${g}${d.toFixed(2)}px)`,f.top=`${g}${u.toFixed(2)}px)`),f.fontSize=`${g}${(c(Kt,Fn)*h).toFixed(2)}px)`,f.fontFamily=o,s.fontSize=h,e.setAttribute("role","presentation"),e.textContent=t.str,e.dir=t.dir,c(this,Kh)&&(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 w=Math.abs(t.transform[0]),v=Math.abs(t.transform[3]);w!==v&&Math.max(w,v)/Math.min(w,v)>1.5&&(p=!0)}if(p&&(s.canvasWidth=r.vertical?t.height:t.width),c(this,tl).set(e,s),c(this,Ni).div=e,c(this,Ni).properties=s,y(this,Bi,Sf).call(this,c(this,Ni)),s.hasText&&c(this,We).append(e),s.hasEOL){const w=document.createElement("br");w.setAttribute("role","presentation"),c(this,We).append(w)}},Sf=function(t){var o;const{div:e,properties:s,ctx:i}=t,{style:n}=e;let r="";if(c(Kt,Fn)>1&&(r=`scale(${1/c(Kt,Fn)})`),s.canvasWidth!==0&&s.hasText){const{fontFamily:h}=n,{canvasWidth:l,fontSize:d}=s;y(o=Kt,Qe,Cf).call(o,i,d*c(this,Ln),h);const{width:u}=i.measureText(e.textContent);u>0&&(r=`scaleX(${l*c(this,Ln)/u}) ${r}`)}s.angle!==0&&(r=`rotate(${s.angle}deg) ${r}`),r.length>0&&(n.transform=r)},Qe=new WeakSet,Gd=function(t=null){let e=c(this,Br).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}),c(this,Br).set(t,e),c(this,sl).set(e,{size:0,family:""})}return e},Cf=function(t,e,s){const i=c(this,sl).get(t);e===i.size&&s===i.family||(t.font=`${e}px ${s}`,i.size=e,i.family=s)},Pb=function(){if(c(this,Fn)!==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),b(this,Fn,t.getBoundingClientRect().height),t.remove()},Lb=function(t,e){const s=c(this,Nr).get(t);if(s)return s;const i=y(this,Qe,Gd).call(this,e);i.canvas.width=i.canvas.height=Be,y(this,Qe,Cf).call(this,i,Be,t);const n=i.measureText("");let r=n.fontBoundingBoxAscent,o=Math.abs(n.fontBoundingBoxDescent);if(r){const d=r/(r+o);return c(this,Nr).set(t,d),i.canvas.width=i.canvas.height=0,d}i.strokeStyle="red",i.clearRect(0,0,Be,Be),i.strokeText("g",0,0);let h=i.getImageData(0,0,Be,Be).data;o=0;for(let d=h.length-1-3;d>=0;d-=4)if(h[d]>0){o=Math.ceil(d/4/Be);break}i.clearRect(0,0,Be,Be),i.strokeText("A",0,Be),h=i.getImageData(0,0,Be,Be).data,r=0;for(let d=0,u=h.length;d<u;d+=4)if(h[d]>0){r=Be-Math.floor(d/4/Be);break}i.canvas.width=i.canvas.height=0;const l=r?r/(r+o):bx;return c(this,Nr).set(t,l),l},_(Kt,Qe),_(Kt,Nr,new Map),_(Kt,Br,new Map),_(Kt,sl,new WeakMap),_(Kt,Fn,null),_(Kt,la,new Set);let bh=Kt;class vh{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(vh.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 l of n.children)i(l)}return i(t),s}static shouldBuildText(t){return!(t==="textarea"||t==="input"||t==="option"||t==="select")}}const vx=65536,yx=100,_x=5e3,wx=pe?Lw:Ow,xx=pe?Fw:f0,Sx=pe?Pw:Dw,Cx=pe?Rw:b0;function Ax(a={}){typeof a=="string"||a instanceof URL?a={url:a}:(a instanceof ArrayBuffer||ArrayBuffer.isView(a))&&(a={data:a});const t=new Hg,{docId:e}=t,s=a.url?Tx(a.url):null,i=a.data?Ex(a.data):null,n=a.httpHeaders||null,r=a.withCredentials===!0,o=a.password??null,h=a.range instanceof j0?a.range:null,l=Number.isInteger(a.rangeChunkSize)&&a.rangeChunkSize>0?a.rangeChunkSize:vx;let d=a.worker instanceof Bo?a.worker:null;const u=a.verbosity,g=typeof a.docBaseUrl=="string"&&!od(a.docBaseUrl)?a.docBaseUrl:null,f=typeof a.cMapUrl=="string"?a.cMapUrl:null,p=a.cMapPacked!==!1,m=a.CMapReaderFactory||xx,w=typeof a.standardFontDataUrl=="string"?a.standardFontDataUrl:null,v=a.StandardFontDataFactory||Cx,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:!pe,k=typeof a.isChrome=="boolean"?a.isChrome:!ke.platform.isFirefox&&typeof window<"u"&&!!(window!=null&&window.chrome),P=Number.isInteger(a.canvasMaxAreaInBytes)?a.canvasMaxAreaInBytes:-1,D=typeof a.disableFontFace=="boolean"?a.disableFontFace:pe,R=a.fontExtraProperties===!0,B=a.enableXfa===!0,O=a.ownerDocument||globalThis.document,F=a.disableRange===!0,L=a.disableStream===!0,I=a.disableAutoFetch===!0,G=a.pdfBug===!0,Y=a.CanvasFactory||wx,z=a.FilterFactory||Sx,H=a.enableHWA===!0,_t=h?h.length:a.length??NaN,vt=typeof a.useSystemFonts=="boolean"?a.useSystemFonts:!pe&&!D,te=typeof a.useWorkerFetch=="boolean"?a.useWorkerFetch:m===f0&&v===b0&&f&&w&&uh(f,document.baseURI)&&uh(w,document.baseURI);a.canvasFactory&&h0("`canvasFactory`-instance option, please use `CanvasFactory` instead."),a.filterFactory&&h0("`filterFactory`-instance option, please use `FilterFactory` instead.");const Wt=null;aw(u);const xt={canvasFactory:new Y({ownerDocument:O,enableHWA:H}),filterFactory:new z({docId:e,ownerDocument:O}),cMapReaderFactory:te?null:new m({baseUrl:f,isCompressed:p}),standardFontDataFactory:te?null:new v({baseUrl:w})};if(!d){const Ft={verbosity:u,port:ki.workerPort};d=Ft.port?Bo.fromPort(Ft):new Bo(Ft),t._worker=d}const Le={docId:e,apiVersion:"4.8.69",data:i,password:o,disableAutoFetch:I,rangeChunkSize:l,length:_t,docBaseUrl:g,enableXfa:B,evaluatorOptions:{maxImageSize:S,disableFontFace:D,ignoreErrors:x,isEvalSupported:C,isOffscreenCanvasSupported:E,isChrome:k,canvasMaxAreaInBytes:P,fontExtraProperties:R,useSystemFonts:vt,cMapUrl:te?f:null,standardFontDataUrl:te?w:null}},gi={disableFontFace:D,fontExtraProperties:R,ownerDocument:O,pdfBug:G,styleElement:Wt,loadingParams:{disableAutoFetch:I,enableXfa:B}};return d.promise.then(function(){if(t.destroyed)throw new Error("Loading aborted");if(d.destroyed)throw new Error("Worker was destroyed");const Ft=d.messageHandler.sendWithPromise("GetDocRequest",Le,i?[i.buffer]:null);let dt;if(h)dt=new Jw(h,{disableRange:F,disableStream:L});else if(!i){if(!s)throw new Error("getDocument - no `url` parameter provided.");let po;pe?po=typeof fetch<"u"&&typeof Response<"u"&&"body"in Response.prototype&&uh(s)?P0:dx:po=uh(s)?P0:ox,dt=new po({url:s,length:_t,httpHeaders:n,withCredentials:r,rangeChunkSize:l,disableRange:F,disableStream:L})}return Ft.then(po=>{if(t.destroyed)throw new Error("Loading aborted");if(d.destroyed)throw new Error("Worker was destroyed");const mo=new mh(e,po,d.port),fi=new Dx(mo,t,dt,gi,xt);t._transport=fi,mo.send("Ready",null)})}).catch(t._capability.reject),t}function Tx(a){if(a instanceof URL)return a.href;try{return new URL(a,window.location).href}catch{if(pe&&typeof a=="string")return a}throw new Error("Invalid PDF url data: either string or URL-object is expected in the url property.")}function Ex(a){if(pe&&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 nd(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 I0(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${Fe(Md,kd)._++}`,this.destroyed=!1,this.onPassword=null,this.onProgress=null}get promise(){return this._capability.promise}async destroy(){var t,e,s;this.destroyed=!0;try{(t=this._worker)!=null&&t.port&&(this._worker._pendingDestroy=!0),await((e=this._transport)==null?void 0:e.destroy())}catch(i){throw(s=this._worker)!=null&&s.port&&delete this._worker._pendingDestroy,i}this._transport=null,this._worker&&(this._worker.destroy(),this._worker=null)}};kd=new WeakMap,_(Md,kd,0);let Hg=Md;class j0{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){wt("Abstract method PDFDataRangeTransport.requestDataRange")}abort(){}}class kx{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 ot(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 Mx{constructor(t,e,s,i=!1){_(this,gs);_(this,Rn,null);_(this,Hi,!1);this._pageIndex=t,this._pageInfo=e,this._transport=s,this._stats=i?new a0:null,this._pdfBug=i,this.commonObjs=s.commonObjs,this.objs=new N0,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 dh({viewBox:this.view,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 ot(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=fn.ENABLE,transform:n=null,background:r=null,optionalContentConfigPromise:o=null,annotationCanvasMap:h=null,pageColors:l=null,printAnnotationStorage:d=null,isEditing:u=!1}){var C,E;(C=this._stats)==null||C.time("Overall");const g=this._transport.getRenderingIntent(s,i,d,u),{renderingIntent:f,cacheKey:p}=g;b(this,Hi,!1),y(this,gs,Ud).call(this),o||(o=this._transport.getOptionalContentConfig(f));let m=this._intentStates.get(p);m||(m=Object.create(null),this._intentStates.set(p,m)),m.streamReaderCancelTimeout&&(clearTimeout(m.streamReaderCancelTimeout),m.streamReaderCancelTimeout=null);const w=!!(f&Ye.PRINT);m.displayReadyCapability||(m.displayReadyCapability=Promise.withResolvers(),m.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(E=this._stats)==null||E.time("Page Request"),this._pumpOperatorList(g));const v=k=>{var P;m.renderTasks.delete(x),(this._maybeCleanupAfterRender||w)&&b(this,Hi,!0),y(this,gs,za).call(this,!w),k?(x.capability.reject(k),this._abortOperatorList({intentState:m,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 Wg({callback:v,params:{canvasContext:t,viewport:e,transform:n,background:r},objs:this.objs,commonObjs:this.commonObjs,annotationCanvasMap:h,operatorList:m.operatorList,pageIndex:this._pageIndex,canvasFactory:this._transport.canvasFactory,filterFactory:this._transport.filterFactory,useRequestAnimationFrame:!w,pdfBug:this._pdfBug,pageColors:l});(m.renderTasks||(m.renderTasks=new Set)).add(x);const S=x.task;return Promise.all([m.displayReadyCapability.promise,o]).then(([k,P])=>{var D;if(this.destroyed){v();return}if((D=this._stats)==null||D.time("Rendering"),!(P.renderingIntent&f))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),S}getOperatorList({intent:t="display",annotationMode:e=fn.ENABLE,printAnnotationStorage:s=null,isEditing:i=!1}={}){var l;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},(l=this._stats)==null||l.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=>vh.textContent(s));const e=this.streamTextContent(t);return new Promise(function(s,i){function n(){r.read().then(function({value:h,done:l}){if(l){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(),b(this,Hi,!1),y(this,gs,Ud).call(this),Promise.all(t)}cleanup(t=!1){b(this,Hi,!0);const e=y(this,gs,za).call(this,!1);return t&&e&&this._stats&&(this._stats=new a0),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&&y(this,gs,za).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(),l=this._intentStates.get(e);l.streamReader=h;const d=()=>{h.read().then(({value:u,done:g})=>{if(g){l.streamReader=null;return}this._transport.destroyed||(this._renderPageChunk(u,l),d())},u=>{if(l.streamReader=null,!this._transport.destroyed){if(l.operatorList){l.operatorList.lastChunk=!0;for(const g of l.renderTasks)g.operatorListChanged();y(this,gs,za).call(this,!0)}if(l.displayReadyCapability)l.displayReadyCapability.reject(u);else if(l.opListReadCapability)l.opListReadCapability.reject(u);else throw u}})};d()}_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 _g){let i=yx;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 lr(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}}Rn=new WeakMap,Hi=new WeakMap,gs=new WeakSet,za=function(t=!1){if(y(this,gs,Ud).call(this),!c(this,Hi)||this.destroyed)return!1;if(t)return b(this,Rn,setTimeout(()=>{b(this,Rn,null),y(this,gs,za).call(this,!1)},_x)),!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(),b(this,Hi,!1),!0},Ud=function(){c(this,Rn)&&(clearTimeout(c(this,Rn)),b(this,Rn,null))};class Ox{constructor(){_(this,Wi,new Map);_(this,Od,Promise.resolve())}postMessage(t,e){const s={data:structuredClone(t,e?{transfer:e}:null)};c(this,Od).then(()=>{for(const[i]of c(this,Wi))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)}c(this,Wi).set(e,i)}removeEventListener(t,e){const s=c(this,Wi).get(e);s==null||s(),c(this,Wi).delete(e)}terminate(){for(const[,t]of c(this,Wi))t==null||t();c(this,Wi).clear()}}Wi=new WeakMap,Od=new WeakMap;const At=class At{constructor({name:t=null,port:e=null,verbosity:s=hw()}={}){_(this,ca);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=c(At,Wr))!=null&&i.has(e))throw new Error("Cannot use more than one PDFWorker per port.");(c(At,Wr)||b(At,Wr,new WeakMap)).set(e,this),this._initializeFromPort(e);return}this._initialize()}get promise(){return pe?Promise.all([bn.promise,this._readyCapability.promise]):this._readyCapability.promise}get port(){return this._port}get messageHandler(){return this._messageHandler}_initializeFromPort(t){this._port=t,this._messageHandler=new mh("main","worker",t),this._messageHandler.on("ready",function(){}),y(this,ca,Yd).call(this)}_initialize(){if(c(At,Hr)||c(At,da,qd)){this._setupFakeWorker();return}let{workerSrc:t}=At;try{At._isSameOrigin(window.location.href,t)||(t=At._createCDNWrapper(new URL(t,window.location).href));const e=new Worker(t,{type:"module"}),s=new mh("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,y(this,ca,Yd).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{sd("The worker has been disabled.")}this._setupFakeWorker()}_setupFakeWorker(){c(At,Hr)||(st("Setting up fake worker."),b(At,Hr,!0)),At._setupFakeWorkerGlobal.then(t=>{if(this.destroyed){this._readyCapability.reject(new Error("Worker was destroyed"));return}const e=new Ox;this._port=e;const s=`fake${Fe(At,Dd)._++}`,i=new mh(s+"_worker",s,e);t.setup(i,e),this._messageHandler=new mh(s,s+"_worker",e),y(this,ca,Yd).call(this)}).catch(t=>{this._readyCapability.reject(new Error(`Setting up fake worker failed: "${t.message}".`))})}destroy(){var t;this.destroyed=!0,this._webWorker&&(this._webWorker.terminate(),this._webWorker=null),(t=c(At,Wr))==null||t.delete(this._port),this._port=null,this._messageHandler&&(this._messageHandler.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=c(this,Wr))==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 At(t)}static get workerSrc(){if(ki.workerSrc)return ki.workerSrc;throw new Error('No "GlobalWorkerOptions.workerSrc" specified.')}static get _setupFakeWorkerGlobal(){return ot(this,"_setupFakeWorkerGlobal",(async()=>c(this,da,qd)?c(this,da,qd):(await import(this.workerSrc)).WorkerMessageHandler)())}};Dd=new WeakMap,Hr=new WeakMap,Wr=new WeakMap,ca=new WeakSet,Yd=function(){this._readyCapability.resolve(),this._messageHandler.send("configure",{verbosity:this.verbosity})},da=new WeakSet,qd=function(){var t;try{return((t=globalThis.pdfjsWorker)==null?void 0:t.WorkerMessageHandler)||null}catch{return null}},_(At,da),_(At,Dd,0),_(At,Hr,!1),_(At,Wr),pe&&(b(At,Hr,!0),ki.workerSrc||(ki.workerSrc="./pdf.worker.mjs")),At._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},At._createCDNWrapper=t=>{const e=`await import("${t}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))};let Bo=At;class Dx{constructor(t,e,s,i,n){_(this,Xr);_(this,Xi,new Map);_(this,ri,new Map);_(this,ua,new Map);_(this,ga,new Map);_(this,oi,null);this.messageHandler=t,this.loadingTask=e,this.commonObjs=new N0,this.fontLoader=new kw({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 ot(this,"annotationStorage",new Mg)}getRenderingIntent(t,e=fn.ENABLE,s=null,i=!1,n=!1){let r=Ye.DISPLAY,o=kg;switch(t){case"any":r=Ye.ANY;break;case"display":break;case"print":r=Ye.PRINT;break;default:st(`getRenderingIntent - invalid intent: ${t}`)}const h=r&Ye.PRINT&&s instanceof d0?s:this.annotationStorage;switch(e){case fn.DISABLE:r+=Ye.ANNOTATIONS_DISABLE;break;case fn.ENABLE:break;case fn.ENABLE_FORMS:r+=Ye.ANNOTATIONS_FORMS;break;case fn.ENABLE_STORAGE:r+=Ye.ANNOTATIONS_STORAGE,o=h.serializable;break;default:st(`getRenderingIntent - invalid annotationMode: ${e}`)}i&&(r+=Ye.IS_EDITING),n&&(r+=Ye.OPLIST);const{ids:l,hash:d}=h.modifiedIds,u=[r,o.hash,d];return{renderingIntent:r,cacheKey:u.join("_"),annotationStorageSerializable:o,modifiedIds:l}}destroy(){var s;if(this.destroyCapability)return this.destroyCapability.promise;this.destroyed=!0,this.destroyCapability=Promise.withResolvers(),(s=c(this,oi))==null||s.reject(new Error("Worker was destroyed during onPassword callback"));const t=[];for(const i of c(this,ri).values())t.push(i._destroy());c(this,ri).clear(),c(this,ua).clear(),c(this,ga).clear(),this.hasOwnProperty("annotationStorage")&&this.annotationStorage.resetModified();const e=this.messageHandler.sendWithPromise("Terminate",null);return t.push(e),Promise.all(t).then(()=>{var i;this.commonObjs.clear(),this.fontLoader.clear(),c(this,Xi).clear(),this.filterFactory.destroy(),bh.cleanup(),(i=this._networkStream)==null||i.cancelAllRequests(new lr("Worker was terminated.")),this.messageHandler&&(this.messageHandler.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)=>{qt(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}qt(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 l;(l=e.onProgress)==null||l.call(e,{loaded:h.loaded,total:h.total})}),{isStreamingSupported:i,isRangeSupported:n,contentLength:r}}),t.on("GetRangeReader",(s,i)=>{qt(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}qt(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 kx(s,this))}),t.on("DocException",function(s){let i;switch(s.name){case"PasswordException":i=new fg(s.message,s.code);break;case"InvalidPDFException":i=new n0(s.message);break;case"MissingPDFException":i=new hr(s.message);break;case"UnexpectedResponseException":i=new id(s.message,s.status);break;case"UnknownErrorException":i=new pg(s.message,s.details);break;default:wt("DocException - expected a valid Error.")}e._capability.reject(i)}),t.on("PasswordRequest",s=>{if(b(this,oi,Promise.withResolvers()),e.onPassword){const i=n=>{n instanceof Error?c(this,oi).reject(n):c(this,oi).resolve({password:n})};try{e.onPassword(i,s.code)}catch(n){c(this,oi).reject(n)}}else c(this,oi).reject(new fg(s.message,s.code));return c(this,oi).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;c(this,ri).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:l}=this._params;if("error"in n){const f=n.error;st(`Error during font loading: ${f}`),this.commonObjs.resolve(s,f);break}const d=l&&((r=globalThis.FontInspector)!=null&&r.enabled)?(f,p)=>globalThis.FontInspector.fontAdded(f,p):null,u=new Mw(n,{disableFontFace:o,inspectFont:d});this.fontLoader.bind(u).catch(()=>t.sendWithPromise("FontFallback",{id:s})).finally(()=>{!h&&u.data&&(u.data=null),this.commonObjs.resolve(s,u)});break;case"CopyLocalImage":const{imageRef:g}=n;qt(g,"The imageRef must be defined.");for(const f of c(this,ri).values())for(const[,p]of f.objs)if((p==null?void 0:p.ref)===g)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=c(this,ri).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)>iw&&(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=c(this,ua).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&&c(this,ga).set(n.refStr,t);const r=new Mx(e,n,this,this._params.pdfBug);return c(this,ri).set(e,r),r});return c(this,ua).set(e,i),i}getPageIndex(t){return I0(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 y(this,Xr,zl).call(this,"GetFieldObjects")}hasJSActions(){return y(this,Xr,zl).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 y(this,Xr,zl).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 y(this,Xr,zl).call(this,"GetOptionalContentConfig").then(e=>new Qw(e,t))}getPermissions(){return this.messageHandler.sendWithPromise("GetPermissions",null)}getMetadata(){const t="GetMetadata",e=c(this,Xi).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 $w(i[1]):null,contentDispositionFilename:((n=this._fullReader)==null?void 0:n.filename)??null,contentLength:((r=this._fullReader)==null?void 0:r.contentLength)??null}});return c(this,Xi).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 c(this,ri).values())if(!e.cleanup())throw new Error(`startCleanup: Page ${e.pageNumber} is currently rendering.`);this.commonObjs.clear(),t||this.fontLoader.clear(),c(this,Xi).clear(),this.filterFactory.destroy(!0),bh.cleanup()}}cachedPageNumber(t){if(!I0(t))return null;const e=t.gen===0?`${t.num}R`:`${t.num}R${t.gen}`;return c(this,ga).get(e)??null}}Xi=new WeakMap,ri=new WeakMap,ua=new WeakMap,ga=new WeakMap,oi=new WeakMap,Xr=new WeakSet,zl=function(t,e=null){const s=c(this,Xi).get(t);if(s)return s;const i=this.messageHandler.sendWithPromise(t,e);return c(this,Xi).set(t,i),i};const gd=Symbol("INITIAL_DATA");class N0{constructor(){_(this,il);_(this,Ls,Object.create(null))}get(t,e=null){if(e){const i=y(this,il,Af).call(this,t);return i.promise.then(()=>e(i.data)),null}const s=c(this,Ls)[t];if(!s||s.data===gd)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return s.data}has(t){const e=c(this,Ls)[t];return!!e&&e.data!==gd}resolve(t,e=null){const s=y(this,il,Af).call(this,t);s.data=e,s.resolve()}clear(){var t;for(const e in c(this,Ls)){const{data:s}=c(this,Ls)[e];(t=s==null?void 0:s.bitmap)==null||t.close()}b(this,Ls,Object.create(null))}*[Symbol.iterator](){for(const t in c(this,Ls)){const{data:e}=c(this,Ls)[t];e!==gd&&(yield[t,e])}}}Ls=new WeakMap,il=new WeakSet,Af=function(t){var e;return(e=c(this,Ls))[t]||(e[t]={...Promise.withResolvers(),data:gd})};class Px{constructor(t){_(this,In,null);b(this,In,t),this.onContinue=null}get promise(){return c(this,In).capability.promise}cancel(t=0){c(this,In).cancel(null,t)}get separateAnnots(){const{separateAnnots:t}=c(this,In).operatorList;if(!t)return!1;const{annotationCanvasMap:e}=c(this,In);return t.form||t.canvas&&(e==null?void 0:e.size)>0}}In=new WeakMap;const Vr=class Vr{constructor({callback:t,params:e,objs:s,commonObjs:i,annotationCanvasMap:n,operatorList:r,pageIndex:o,canvasFactory:h,filterFactory:l,useRequestAnimationFrame:d=!1,pdfBug:u=!1,pageColors:g=null}){_(this,jn,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=l,this._pdfBug=u,this.pageColors=g,this.running=!1,this.graphicsReadyCallback=null,this.graphicsReady=!1,this._useRequestAnimationFrame=d===!0&&typeof window<"u",this.cancelled=!1,this.capability=Promise.withResolvers(),this.task=new Px(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(c(Vr,zr).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.");c(Vr,zr).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 jo(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(),c(this,jn)&&(window.cancelAnimationFrame(c(this,jn)),b(this,jn,null)),c(Vr,zr).delete(this._canvas),this.callback(t||new _g(`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?b(this,jn,window.requestAnimationFrame(()=>{b(this,jn,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(),c(Vr,zr).delete(this._canvas),this.callback())))}};jn=new WeakMap,zr=new WeakMap,_(Vr,zr,new WeakSet);let Wg=Vr;const Lx="4.8.69",Fx="3634dab10";function B0(a){return Math.floor(Math.max(0,Math.min(1,a))*255).toString(16).padStart(2,"0")}function yh(a){return Math.max(0,Math.min(255,255*a))}class H0{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=yh(t),[t,t,t]}static G_HTML([t]){const e=B0(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(yh)}static RGB_HTML(t){return`#${t.map(B0).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[yh(1-Math.min(1,t+i)),yh(1-Math.min(1,s+i)),yh(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 Rx{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){wt("Abstract method `_createSVG` called.")}}class Xg extends Rx{_createSVG(t){return document.createElementNS(Ti,t)}}class W0{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,l=h.selectedIndex===-1?"":h[h.selectedIndex].value;i.setValue(e,{value:l})});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,l]of Object.entries(r))if(l!=null)switch(h){case"class":l.length&&t.setAttribute(h,l.join(" "));break;case"dataId":break;case"id":t.setAttribute("data-element-id",l);break;case"style":Object.assign(t.style,l);break;case"textContent":t.textContent=l;break;default:(!o||h!=="href"&&h!=="newWindow")&&t.setAttribute(h,l)}o&&n.addLinkAttributes(t,r.href,r.newWindow),s&&r.dataId&&this.setupStorage(t,r.dataId,e,s)}static render(t){var u,g;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 f=`matrix(${t.viewport.transform.join(",")})`;h.style.transform=f}o&&h.setAttribute("class","xfaLayer xfaFont");const l=[];if(i.children.length===0){if(i.value){const f=document.createTextNode(i.value);r.append(f),o&&vh.shouldBuildText(i.name)&&l.push(f)}return{textDivs:l}}const d=[[i,-1,r]];for(;d.length>0;){const[f,p,m]=d.at(-1);if(p+1===f.children.length){d.pop();continue}const w=f.children[++d.at(-1)[1]];if(w===null)continue;const{name:v}=w;if(v==="#text"){const S=document.createTextNode(w.value);l.push(S),m.append(S);continue}const x=(u=w==null?void 0:w.attributes)!=null&&u.xmlns?document.createElementNS(w.attributes.xmlns,v):document.createElement(v);if(m.append(x),w.attributes&&this.setAttributes({html:x,element:w,storage:e,intent:n,linkService:s}),((g=w.children)==null?void 0:g.length)>0)d.push([w,-1,x]);else if(w.value){const S=document.createTextNode(w.value);o&&vh.shouldBuildText(v)&&l.push(S),x.append(S)}}for(const f of h.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea"))f.setAttribute("readOnly",!0);return{textDivs:l}}static update(t){const e=`matrix(${t.viewport.transform.join(",")})`;t.div.style.transform=e,t.div.hidden=!1}}const _h=1e3,Ix=9,ur=new WeakSet;function Mi(a){return{width:a[2]-a[0],height:a[3]-a[1]}}class jx{static create(t){switch(t.data.annotationType){case Yt.LINK:return new X0(t);case Yt.TEXT:return new Nx(t);case Yt.WIDGET:switch(t.data.fieldType){case"Tx":return new Bx(t);case"Btn":return t.data.radioButton?new z0(t):t.data.checkBox?new Wx(t):new Xx(t);case"Ch":return new zx(t);case"Sig":return new Hx(t)}return new gr(t);case Yt.POPUP:return new zg(t);case Yt.FREETEXT:return new V0(t);case Yt.LINE:return new Gx(t);case Yt.SQUARE:return new Ux(t);case Yt.CIRCLE:return new Yx(t);case Yt.POLYLINE:return new G0(t);case Yt.CARET:return new $x(t);case Yt.INK:return new Vg(t);case Yt.POLYGON:return new qx(t);case Yt.HIGHLIGHT:return new U0(t);case Yt.UNDERLINE:return new Kx(t);case Yt.SQUIGGLY:return new Qx(t);case Yt.STRIKEOUT:return new Jx(t);case Yt.STAMP:return new Y0(t);case Yt.FILEATTACHMENT:return new Zx(t);default:return new Bt(t)}}}const Zg=class Zg{constructor(t,{isRenderable:e=!1,ignoreBorder:s=!1,createQuadrilaterals:i=!1}={}){_(this,nl);_(this,Gr,null);_(this,fa,!1);_(this,pa,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 Zg._hasPopupData(this.data)}updateEdited(t){var s;if(!this.container)return;c(this,Gr)||b(this,Gr,{rect:this.data.rect.slice(0)});const{rect:e}=t;e&&y(this,nl,Tf).call(this,e),(s=c(this,pa))==null||s.popup.updateEdited(t)}resetEdited(){var t;c(this,Gr)&&(y(this,nl,Tf).call(this,c(this,Gr).rect),(t=c(this,pa))==null||t.popup.resetEdited(),b(this,Gr,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 gr||(n.tabIndex=_h);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 zg){const{rotation:m}=e;return!e.hasOwnCanvas&&m!==0&&this.setRotation(m,n),n}const{width:o,height:h}=Mi(e.rect);if(!t&&e.borderStyle.width>0){r.borderWidth=`${e.borderStyle.width}px`;const m=e.borderStyle.horizontalCornerRadius,w=e.borderStyle.verticalCornerRadius;if(m>0||w>0){const x=`calc(${m}px * var(--scale-factor)) / calc(${w}px * var(--scale-factor))`;r.borderRadius=x}else if(this instanceof z0){const x=`calc(${o}px * var(--scale-factor)) / calc(${h}px * var(--scale-factor))`;r.borderRadius=x}switch(e.borderStyle.style){case ch.SOLID:r.borderStyle="solid";break;case ch.DASHED:r.borderStyle="dashed";break;case ch.BEVELED:st("Unimplemented border style: beveled");break;case ch.INSET:st("Unimplemented border style: inset");break;case ch.UNDERLINE:r.borderBottomStyle="solid";break}const v=e.borderColor||null;v?(b(this,fa,!0),r.borderColor=V.makeHexColor(v[0]|0,v[1]|0,v[2]|0)):r.borderWidth=0}const l=V.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:d,pageHeight:u,pageX:g,pageY:f}=i.rawDims;r.left=`${100*(l[0]-g)/d}%`,r.top=`${100*(l[1]-f)/u}%`;const{rotation:p}=e;return e.hasOwnCanvas||p===0?(r.width=`${100*o/d}%`,r.height=`${100*h/u}%`):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}=Mi(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]=H0[`${r}_HTML`](o),this.annotationStorage.setValue(this.data.id,{[s]:H0[`${r}_rgb`](o)})};return ot(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(m=>Math.fround(m));if(t.length===8){const[m,w,v,x]=t.subarray(2,6);if(i===m&&n===w&&e===v&&s===x)return}const{style:r}=this.container;let o;if(c(this,fa)){const{borderColor:m,borderWidth:w}=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="${m}" stroke-width="${w}">`],this.container.classList.add("hasBorder")}const h=i-e,l=n-s,{svgFactory:d}=this,u=d.createElement("svg");u.classList.add("quadrilateralsContainer"),u.setAttribute("width",0),u.setAttribute("height",0);const g=d.createElement("defs");u.append(g);const f=d.createElement("clipPath"),p=`clippath_${this.data.id}`;f.setAttribute("id",p),f.setAttribute("clipPathUnits","objectBoundingBox"),g.append(f);for(let m=2,w=t.length;m<w;m+=8){const v=t[m],x=t[m+1],S=t[m+2],C=t[m+3],E=d.createElement("rect"),k=(S-e)/h,P=(n-x)/l,D=(v-S)/h,R=(x-C)/l;E.setAttribute("x",k),E.setAttribute("y",P),E.setAttribute("width",D),E.setAttribute("height",R),f.append(E),o==null||o.push(`<rect vector-effect="non-scaling-stroke" x="${k}" y="${P}" width="${D}" height="${R}"/>`)}c(this,fa)&&(o.push("</g></svg>')"),r.backgroundImage=o.join("")),this.container.append(u),this.container.style.clipPath=`url(#${p})`}_createPopup(){const{data:t}=this,e=b(this,pa,new zg({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(){wt("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,l=document.querySelector(`[data-element-id="${r}"]`);if(l&&!ur.has(l)){st(`_getElementsByName - element not allowed: ${r}`);continue}s.push({id:r,exportValue:h,domElement:l})}return s}for(const i of document.getElementsByName(t)){const{exportValue:n}=i,r=i.getAttribute("data-element-id");r!==e&&ur.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})})}};Gr=new WeakMap,fa=new WeakMap,pa=new WeakMap,nl=new WeakSet,Tf=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:l,height:d}=Mi(t);e.left=`${100*(t[0]-o)/n}%`,e.top=`${100*(r-t[3]+h)/r}%`,i===0?(e.width=`${100*l/n}%`,e.height=`${100*d/r}%`):this.setRotation(i)};let Bt=Zg;class X0 extends Bt{constructor(e,s=null){super(e,{isRenderable:!0,ignoreBorder:!!(s!=null&&s.ignoreBorder),createQuadrilaterals:!0});_(this,Je);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?(y(this,Je,Fb).call(this,i,e.attachment,e.attachmentDest),n=!0):e.setOCGState?(y(this,Je,Rb).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==="")&&y(this,Je,bo).call(this)}_bindNamedAction(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeNamedAction(s),!1),y(this,Je,bo).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),y(this,Je,bo).call(this)}_bindResetFormAction(e,s){const i=e.onclick;if(i||(e.href=this.linkService.getAnchorUrl("")),y(this,Je,bo).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 u;i==null||i();const{fields:n,refs:r,include:o}=s,h=[];if(n.length!==0||r.length!==0){const g=new Set(r);for(const f of n){const p=this._fieldObjects[f]||[];for(const{id:m}of p)g.add(m)}for(const f of Object.values(this._fieldObjects))for(const p of f)g.has(p.id)===o&&h.push(p)}else for(const g of Object.values(this._fieldObjects))h.push(...g);const l=this.annotationStorage,d=[];for(const g of h){const{id:f}=g;switch(d.push(f),g.type){case"text":{const m=g.defaultValue||"";l.setValue(f,{value:m});break}case"checkbox":case"radiobutton":{const m=g.defaultValue===g.exportValues;l.setValue(f,{value:m});break}case"combobox":case"listbox":{const m=g.defaultValue||"";l.setValue(f,{value:m});break}default:continue}const p=document.querySelector(`[data-element-id="${f}"]`);if(p){if(!ur.has(p)){st(`_bindResetFormAction - element not allowed: ${f}`);continue}}else continue;p.dispatchEvent(new Event("resetform"))}return this.enableScripting&&((u=this.linkService.eventBus)==null||u.dispatch("dispatcheventinsandbox",{source:this,detail:{id:"app",ids:d,name:"ResetForm"}})),!1}}}Je=new WeakSet,bo=function(){this.container.setAttribute("data-internal-link","")},Fb=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},y(this,Je,bo).call(this)},Rb=function(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeSetOCGState(s),!1),y(this,Je,bo).call(this)};class Nx 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 gr 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 ke.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,l]of s)(l==="Action"||(n=this.data.actions)!=null&&n[l])&&((l==="Focus"||l==="Blur")&&(e||(e={focused:!1})),this._setEventListener(t,e,h,l,i),l==="Focus"&&!((r=this.data.actions)!=null&&r.Blur)?this._setEventListener(t,e,"blur","Blur",null):l==="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":V.makeHexColor(e[0],e[1],e[2])}_setTextStyle(t){const e=["left","center","right"],{fontColor:s}=this.data.defaultAppearanceData,i=this.data.defaultAppearanceData.fontSize||Ix,n=t.style;let r;const o=2,h=l=>Math.round(10*l)/10;if(this.data.multiLine){const l=Math.abs(this.data.rect[3]-this.data.rect[1]-o),d=Math.round(l/(gg*i))||1,u=l/d;r=Math.min(i,h(u/gg))}else{const l=Math.abs(this.data.rect[3]-this.data.rect[1]-o);r=Math.min(i,h(l/gg))}n.fontSize=`calc(${r}px * var(--scale-factor))`,n.color=V.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 Bx extends gr{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 l=r.formattedValue||((i=this.data.textContent)==null?void 0:i.join(`
500
- `))||null;l&&this.data.comb&&(l=l.replaceAll(/\s+/g,""));const d={userValue:o,formattedValue:l,lastCommittedValue:null,commitKey:1,focused:!1};this.data.multiLine?(s=document.createElement("textarea"),s.textContent=l??o,this.data.doNotScroll&&(s.style.overflowY="hidden")):(s=document.createElement("input"),s.type="text",s.setAttribute("value",l??o),this.data.doNotScroll&&(s.style.overflowX="hidden")),this.data.hasOwnCanvas&&(s.hidden=!0),ur.add(s),s.setAttribute("data-element-id",e),s.disabled=this.data.readOnly,s.name=this.data.fieldName,s.tabIndex=_h,this._setRequired(s,this.data.required),h&&(s.maxLength=h),s.addEventListener("input",g=>{t.setValue(e,{value:g.target.value}),this.setPropertyOnSiblings(s,"value",g.target.value,"value"),d.formattedValue=null}),s.addEventListener("resetform",g=>{const f=this.data.defaultFieldValue??"";s.value=d.userValue=f,d.formattedValue=null});let u=g=>{const{formattedValue:f}=d;f!=null&&(g.target.value=f),g.target.scrollLeft=0};if(this.enableScripting&&this.hasJSActions){s.addEventListener("focus",f=>{var m;if(d.focused)return;const{target:p}=f;d.userValue&&(p.value=d.userValue),d.lastCommittedValue=p.value,d.commitKey=1,(m=this.data.actions)!=null&&m.Focus||(d.focused=!0)}),s.addEventListener("updatefromsandbox",f=>{this.showElementAndHideCanvas(f.target);const p={value(m){d.userValue=m.detail.value??"",t.setValue(e,{value:d.userValue.toString()}),m.target.value=d.userValue},formattedValue(m){const{formattedValue:w}=m.detail;d.formattedValue=w,w!=null&&m.target!==document.activeElement&&(m.target.value=w),t.setValue(e,{formattedValue:w})},selRange(m){m.target.setSelectionRange(...m.detail.selRange)},charLimit:m=>{var S;const{charLimit:w}=m.detail,{target:v}=m;if(w===0){v.removeAttribute("maxLength");return}v.setAttribute("maxLength",w);let x=d.userValue;!x||x.length<=w||(x=x.slice(0,w),v.value=d.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:v.selectionStart,selEnd:v.selectionEnd}}))}};this._dispatchEventFromSandbox(p,f)}),s.addEventListener("keydown",f=>{var w;d.commitKey=1;let p=-1;if(f.key==="Escape"?p=0:f.key==="Enter"&&!this.data.multiLine?p=2:f.key==="Tab"&&(d.commitKey=3),p===-1)return;const{value:m}=f.target;d.lastCommittedValue!==m&&(d.lastCommittedValue=m,d.userValue=m,(w=this.linkService.eventBus)==null||w.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:m,willCommit:!0,commitKey:p,selStart:f.target.selectionStart,selEnd:f.target.selectionEnd}}))});const g=u;u=null,s.addEventListener("blur",f=>{var m,w;if(!d.focused||!f.relatedTarget)return;(m=this.data.actions)!=null&&m.Blur||(d.focused=!1);const{value:p}=f.target;d.userValue=p,d.lastCommittedValue!==p&&((w=this.linkService.eventBus)==null||w.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:p,willCommit:!0,commitKey:d.commitKey,selStart:f.target.selectionStart,selEnd:f.target.selectionEnd}})),g(f)}),(n=this.data.actions)!=null&&n.Keystroke&&s.addEventListener("beforeinput",f=>{var E;d.lastCommittedValue=null;const{data:p,target:m}=f,{value:w,selectionStart:v,selectionEnd:x}=m;let S=v,C=x;switch(f.inputType){case"deleteWordBackward":{const k=w.substring(0,v).match(/\w*[^\w]*$/);k&&(S-=k[0].length);break}case"deleteWordForward":{const k=w.substring(v).match(/^[^\w]*\w*/);k&&(C+=k[0].length);break}case"deleteContentBackward":v===x&&(S-=1);break;case"deleteContentForward":v===x&&(C+=1);break}f.preventDefault(),(E=this.linkService.eventBus)==null||E.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:w,change:p||"",willCommit:!1,selStart:S,selEnd:C}})}),this._setEventListeners(s,d,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],f=>f.target.value)}if(u&&s.addEventListener("blur",u),this.data.comb){const f=(this.data.rect[2]-this.data.rect[0])/h;s.classList.add("comb"),s.style.letterSpacing=`calc(${f}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 Hx extends gr{constructor(t){super(t,{isRenderable:!!t.data.hasOwnCanvas})}}class Wx extends gr{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 ur.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=_h,n.addEventListener("change",r=>{const{name:o,checked:h}=r.target;for(const l of this._getElementsByName(o,s)){const d=h&&l.exportValue===e.exportValue;l.domElement&&(l.domElement.checked=d),t.setValue(l.id,{value:d})}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 z0 extends gr{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(ur.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=_h,n.addEventListener("change",r=>{const{name:o,checked:h}=r.target;for(const l of this._getElementsByName(o,s))t.setValue(l.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:l=>{const d=r===l.detail.value;for(const u of this._getElementsByName(l.target.name)){const g=d&&u.id===s;u.domElement&&(u.domElement.checked=g),t.setValue(u.id,{value:g})}}};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 Xx extends X0{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 zx extends gr{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");ur.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=_h;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",d=>{const u=this.data.defaultFieldValue;for(const g of i.options)g.selected=g.value===u});for(const d of this.data.options){const u=document.createElement("option");u.textContent=d.displayValue,u.value=d.exportValue,s.value.includes(d.exportValue)&&(u.setAttribute("selected",!0),n=!1),i.append(u)}let r=null;if(n){const d=document.createElement("option");d.value=" ",d.setAttribute("hidden",!0),d.setAttribute("selected",!0),i.prepend(d),r=()=>{d.remove(),i.removeEventListener("input",r),r=null},i.addEventListener("input",r)}const o=d=>{const u=d?"value":"textContent",{options:g,multiple:f}=i;return f?Array.prototype.filter.call(g,p=>p.selected).map(p=>p[u]):g.selectedIndex===-1?null:g[g.selectedIndex][u]};let h=o(!1);const l=d=>{const u=d.target.options;return Array.prototype.map.call(u,g=>({displayValue:g.textContent,exportValue:g.value}))};return this.enableScripting&&this.hasJSActions?(i.addEventListener("updatefromsandbox",d=>{const u={value(g){r==null||r();const f=g.detail.value,p=new Set(Array.isArray(f)?f:[f]);for(const m of i.options)m.selected=p.has(m.value);t.setValue(e,{value:o(!0)}),h=o(!1)},multipleSelection(g){i.multiple=!0},remove(g){const f=i.options,p=g.detail.remove;f[p].selected=!1,i.remove(p),f.length>0&&Array.prototype.findIndex.call(f,w=>w.selected)===-1&&(f[0].selected=!0),t.setValue(e,{value:o(!0),items:l(g)}),h=o(!1)},clear(g){for(;i.length!==0;)i.remove(0);t.setValue(e,{value:null,items:[]}),h=o(!1)},insert(g){const{index:f,displayValue:p,exportValue:m}=g.detail.insert,w=i.children[f],v=document.createElement("option");v.textContent=p,v.value=m,w?w.before(v):i.append(v),t.setValue(e,{value:o(!0),items:l(g)}),h=o(!1)},items(g){const{items:f}=g.detail;for(;i.length!==0;)i.remove(0);for(const p of f){const{displayValue:m,exportValue:w}=p,v=document.createElement("option");v.textContent=m,v.value=w,i.append(v)}i.options.length>0&&(i.options[0].selected=!0),t.setValue(e,{value:o(!0),items:l(g)}),h=o(!1)},indices(g){const f=new Set(g.detail.indices);for(const p of g.target.options)p.selected=f.has(p.index);t.setValue(e,{value:o(!0)}),h=o(!1)},editable(g){g.target.disabled=!g.detail.editable}};this._dispatchEventFromSandbox(u,d)}),i.addEventListener("input",d=>{var f;const u=o(!0),g=o(!1);t.setValue(e,{value:u}),d.preventDefault(),(f=this.linkService.eventBus)==null||f.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:h,change:g,changeEx:u,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"]],d=>d.target.value)):i.addEventListener("input",function(d){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 zg 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 Vx({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=>`${yg}${s}`).join(",")),this.container}}class Vx{constructor({container:t,color:e,elements:s,titleObj:i,modificationDate:n,contentsObj:r,richText:o,parent:h,rect:l,parentRect:d,open:u}){_(this,mt);_(this,ma,y(this,mt,Nb).bind(this));_(this,Pd,y(this,mt,kf).bind(this));_(this,Ld,y(this,mt,Qd).bind(this));_(this,ba,y(this,mt,Kd).bind(this));_(this,Ur,null);_(this,Lt,null);_(this,zi,null);_(this,va,null);_(this,rl,null);_(this,ol,null);_(this,ya,null);_(this,Vi,!1);_(this,Fs,null);_(this,Gi,null);_(this,al,null);_(this,Ui,null);_(this,hl,null);_(this,Yr,null);_(this,qr,!1);var g;b(this,Lt,t),b(this,hl,i),b(this,zi,r),b(this,Ui,o),b(this,ol,h),b(this,Ur,e),b(this,al,l),b(this,ya,d),b(this,rl,s),b(this,va,xg.toDateObject(n)),this.trigger=s.flatMap(f=>f.getElementsToTriggerPopup());for(const f of this.trigger)f.addEventListener("click",c(this,ba)),f.addEventListener("mouseenter",c(this,Ld)),f.addEventListener("mouseleave",c(this,Pd)),f.classList.add("popupTriggerArea");for(const f of s)(g=f.container)==null||g.addEventListener("keydown",c(this,ma));c(this,Lt).hidden=!0,u&&y(this,mt,Kd).call(this)}render(){if(c(this,Fs))return;const t=b(this,Fs,document.createElement("div"));if(t.className="popup",c(this,Ur)){const n=t.style.outlineColor=V.makeHexColor(...c(this,Ur));CSS.supports("background-color","color-mix(in srgb, red 30%, white)")?t.style.backgroundColor=`color-mix(in srgb, ${n} 30%, white)`:t.style.backgroundColor=V.makeHexColor(...c(this,Ur).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}=c(this,hl),t.append(e),c(this,va)){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:c(this,va).valueOf()})),e.append(n)}const i=c(this,mt,$d);if(i)W0.render({xfaHtml:i,intent:"richText",div:t}),t.lastChild.classList.add("richText","popupContent");else{const n=this._formatContents(c(this,zi));t.append(n)}c(this,Lt).append(t)}_formatContents({str:t,dir:e}){const s=document.createElement("p");s.classList.add("popupContent"),s.dir=e;const i=t.split(/(?:\r\n?|\n)/);for(let n=0,r=i.length;n<r;++n){const o=i[n];s.append(document.createTextNode(o)),n<r-1&&s.append(document.createElement("br"))}return s}updateEdited({rect:t,popupContent:e}){var s;c(this,Yr)||b(this,Yr,{contentsObj:c(this,zi),richText:c(this,Ui)}),t&&b(this,Gi,null),e&&(b(this,Ui,y(this,mt,jb).call(this,e)),b(this,zi,null)),(s=c(this,Fs))==null||s.remove(),b(this,Fs,null)}resetEdited(){var t;c(this,Yr)&&({contentsObj:Fe(this,zi)._,richText:Fe(this,Ui)._}=c(this,Yr),b(this,Yr,null),(t=c(this,Fs))==null||t.remove(),b(this,Fs,null),b(this,Gi,null))}forceHide(){b(this,qr,this.isVisible),c(this,qr)&&(c(this,Lt).hidden=!0)}maybeShow(){c(this,qr)&&(c(this,Fs)||y(this,mt,Qd).call(this),b(this,qr,!1),c(this,Lt).hidden=!1)}get isVisible(){return c(this,Lt).hidden===!1}}ma=new WeakMap,Pd=new WeakMap,Ld=new WeakMap,ba=new WeakMap,Ur=new WeakMap,Lt=new WeakMap,zi=new WeakMap,va=new WeakMap,rl=new WeakMap,ol=new WeakMap,ya=new WeakMap,Vi=new WeakMap,Fs=new WeakMap,Gi=new WeakMap,al=new WeakMap,Ui=new WeakMap,hl=new WeakMap,Yr=new WeakMap,qr=new WeakMap,mt=new WeakSet,$d=function(){const t=c(this,Ui),e=c(this,zi);return t!=null&&t.str&&(!(e!=null&&e.str)||e.str===t.str)&&c(this,Ui).html||null},Ef=function(){var t,e,s;return((s=(e=(t=c(this,mt,$d))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.fontSize)||0},Ib=function(){var t,e,s;return((s=(e=(t=c(this,mt,$d))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.color)||null},jb=function(t){const e=[],s={str:t,html:{name:"div",attributes:{dir:"auto"},children:[{name:"p",children:e}]}},i={style:{color:c(this,mt,Ib),fontSize:c(this,mt,Ef)?`calc(${c(this,mt,Ef)}px * var(--scale-factor))`:""}};for(const n of t.split(`
501
- `))e.push({name:"span",value:n,attributes:i});return s},Nb=function(t){t.altKey||t.shiftKey||t.ctrlKey||t.metaKey||(t.key==="Enter"||t.key==="Escape"&&c(this,Vi))&&y(this,mt,Kd).call(this)},Bb=function(){if(c(this,Gi)!==null)return;const{page:{view:t},viewport:{rawDims:{pageWidth:e,pageHeight:s,pageX:i,pageY:n}}}=c(this,ol);let r=!!c(this,ya),o=r?c(this,ya):c(this,al);for(const p of c(this,rl))if(!o||V.intersect(p.data.rect,o)!==null){o=p.data.rect,r=!0;break}const h=V.normalizeRect([o[0],t[3]-o[1]+t[1],o[2],t[3]-o[3]+t[1]]),d=r?o[2]-o[0]+5:0,u=h[0]+d,g=h[1];b(this,Gi,[100*(u-i)/e,100*(g-n)/s]);const{style:f}=c(this,Lt);f.left=`${c(this,Gi)[0]}%`,f.top=`${c(this,Gi)[1]}%`},Kd=function(){b(this,Vi,!c(this,Vi)),c(this,Vi)?(y(this,mt,Qd).call(this),c(this,Lt).addEventListener("click",c(this,ba)),c(this,Lt).addEventListener("keydown",c(this,ma))):(y(this,mt,kf).call(this),c(this,Lt).removeEventListener("click",c(this,ba)),c(this,Lt).removeEventListener("keydown",c(this,ma)))},Qd=function(){c(this,Fs)||this.render(),this.isVisible?c(this,Vi)&&c(this,Lt).classList.add("focused"):(y(this,mt,Bb).call(this),c(this,Lt).hidden=!1,c(this,Lt).style.zIndex=parseInt(c(this,Lt).style.zIndex)+1e3)},kf=function(){c(this,Lt).classList.remove("focused"),!(c(this,Vi)||!this.isVisible)&&(c(this,Lt).hidden=!0,c(this,Lt).style.zIndex=parseInt(c(this,Lt).style.zIndex)-1e3)};class V0 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 Gx extends Bt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,ll,null)}render(){this.container.classList.add("lineAnnotation");const e=this.data,{width:s,height:i}=Mi(e.rect),n=this.svgFactory.create(s,i,!0),r=b(this,ll,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 c(this,ll)}addHighlightArea(){this.container.classList.add("highlightArea")}}ll=new WeakMap;class Ux extends Bt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,cl,null)}render(){this.container.classList.add("squareAnnotation");const e=this.data,{width:s,height:i}=Mi(e.rect),n=this.svgFactory.create(s,i,!0),r=e.borderStyle.width,o=b(this,cl,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 c(this,cl)}addHighlightArea(){this.container.classList.add("highlightArea")}}cl=new WeakMap;class Yx extends Bt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,dl,null)}render(){this.container.classList.add("circleAnnotation");const e=this.data,{width:s,height:i}=Mi(e.rect),n=this.svgFactory.create(s,i,!0),r=e.borderStyle.width,o=b(this,dl,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 c(this,dl)}addHighlightArea(){this.container.classList.add("highlightArea")}}dl=new WeakMap;class G0 extends Bt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,ul,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}=Mi(e),h=this.svgFactory.create(r,o,!0);let l=[];for(let u=0,g=s.length;u<g;u+=2){const f=s[u]-e[0],p=e[3]-s[u+1];l.push(`${f},${p}`)}l=l.join(" ");const d=b(this,ul,this.svgFactory.createElement(this.svgElementName));return d.setAttribute("points",l),d.setAttribute("stroke-width",i.width||1),d.setAttribute("stroke","transparent"),d.setAttribute("fill","transparent"),h.append(d),this.container.append(h),!n&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return c(this,ul)}addHighlightArea(){this.container.classList.add("highlightArea")}}ul=new WeakMap;class qx extends G0{constructor(t){super(t),this.containerClassName="polygonAnnotation",this.svgElementName="svg:polygon"}}class $x 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 Vg extends Bt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,gl,[]);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,inkLists:s,borderStyle:i,popupRef:n}}=this,{width:r,height:o}=Mi(e),h=this.svgFactory.create(r,o,!0);for(const l of s){let d=[];for(let g=0,f=l.length;g<f;g+=2){const p=l[g]-e[0],m=e[3]-l[g+1];d.push(`${p},${m}`)}d=d.join(" ");const u=this.svgFactory.createElement(this.svgElementName);c(this,gl).push(u),u.setAttribute("points",d),u.setAttribute("stroke-width",i.width||1),u.setAttribute("stroke","transparent"),u.setAttribute("fill","transparent"),h.append(u)}return!n&&this.hasPopupData&&this._createPopup(),this.container.append(h),this._editOnDoubleClick(),this.container}getElementsToTriggerPopup(){return c(this,gl)}addHighlightArea(){this.container.classList.add("highlightArea")}}gl=new WeakMap;class U0 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 Kx 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 Qx 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 Jx 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 Y0 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 Zx extends Bt{constructor(e){var i;super(e,{isRenderable:!0});_(this,pl);_(this,fl,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",y(this,pl,Mf).bind(this)),b(this,fl,i);const{isMac:n}=ke.platform;return e.addEventListener("keydown",r=>{r.key==="Enter"&&(n?r.metaKey:r.ctrlKey)&&y(this,pl,Mf).call(this)}),!s.popupRef&&this.hasPopupData?this._createPopup():i.classList.add("popupTriggerArea"),e.append(i),e}getElementsToTriggerPopup(){return c(this,fl)}addHighlightArea(){this.container.classList.add("highlightArea")}}fl=new WeakMap,pl=new WeakSet,Mf=function(){var e;(e=this.downloadManager)==null||e.openOrDownloadData(this.content,this.filename)};class tS{constructor({div:t,accessibilityManager:e,annotationCanvasMap:s,annotationEditorUIManager:i,page:n,viewport:r,structTreeLayer:o}){_(this,Qr);_(this,ml,null);_(this,$r,null);_(this,Kr,new Map);_(this,bl,null);this.div=t,b(this,ml,e),b(this,$r,s),b(this,bl,o||null),this.page=n,this.viewport=r,this.zIndex=0,this._annotationEditorUIManager=i}hasEditableAnnotations(){return c(this,Kr).size>0}async render(t){var r;const{annotations:e}=t,s=this.div;cr(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 Xg,annotationStorage:t.annotationStorage||new Mg,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===Yt.POPUP;if(h){const u=i.get(o.id);if(!u)continue;n.elements=u}else{const{width:u,height:g}=Mi(o.rect);if(u<=0||g<=0)continue}n.data=o;const l=jx.create(n);if(!l.isRenderable)continue;if(!h&&o.popupRef){const u=i.get(o.popupRef);u?u.push(l):i.set(o.popupRef,[l])}const d=l.render();o.hidden&&(d.style.visibility="hidden"),await y(this,Qr,Hb).call(this,d,o.id),l._isEditable&&(c(this,Kr).set(l.data.id,l),(r=this._annotationEditorUIManager)==null||r.renderAnnotationElement(l))}y(this,Qr,Of).call(this)}update({viewport:t}){const e=this.div;this.viewport=t,cr(e,{rotation:t.rotation}),y(this,Qr,Of).call(this),e.hidden=!1}getEditableAnnotations(){return Array.from(c(this,Kr).values())}getEditableAnnotation(t){return c(this,Kr).get(t)}}ml=new WeakMap,$r=new WeakMap,Kr=new WeakMap,bl=new WeakMap,Qr=new WeakSet,Hb=async function(t,e){var r,o;const s=t.firstChild||t,i=s.id=`${yg}${e}`,n=await((r=c(this,bl))==null?void 0:r.getAriaAttributes(i));if(n)for(const[h,l]of n)s.setAttribute(h,l);this.div.append(t),(o=c(this,ml))==null||o.moveElementInDOM(this.div,t,s,!1)},Of=function(){if(!c(this,$r))return;const t=this.div;for(const[e,s]of c(this,$r)){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)}c(this,$r).clear()};const fd=/\r\n?|\n/g,yt=class yt extends gt{constructor(e){super({...e,name:"freeTextEditor"});_(this,Vt);_(this,Rs);_(this,Ze,"");_(this,vl,`${this.id}-editor`);_(this,Jr,null);_(this,ts);b(this,Rs,e.color||yt._defaultColor||gt._defaultLineColor),b(this,ts,e.fontSize||yt._defaultFontSize)}static get _keyboardManager(){const e=yt.prototype,s=r=>r.isEmpty(),i=dr.TRANSLATE_SMALL,n=dr.TRANSLATE_BIG;return ot(this,"_keyboardManager",new gh([[["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){gt.initialize(e,s);const i=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(i.getPropertyValue("--freetext-padding"))}static updateDefaultParams(e,s){switch(e){case $.FREETEXT_SIZE:yt._defaultFontSize=s;break;case $.FREETEXT_COLOR:yt._defaultColor=s;break}}updateParams(e,s){switch(e){case $.FREETEXT_SIZE:y(this,Vt,Wb).call(this,s);break;case $.FREETEXT_COLOR:y(this,Vt,Xb).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[$.FREETEXT_SIZE,yt._defaultFontSize],[$.FREETEXT_COLOR,yt._defaultColor||gt._defaultLineColor]]}get propertiesToUpdate(){return[[$.FREETEXT_SIZE,c(this,ts)],[$.FREETEXT_COLOR,c(this,Rs)]]}_translateEmpty(e,s){this._uiManager.translateSelectedEditors(e,s,!0)}getInitialTranslation(){const e=this.parentScale;return[-yt._internalPadding*e,-(yt._internalPadding+c(this,ts))*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"),b(this,Jr,new AbortController);const e=this._uiManager.combinedSignal(c(this,Jr));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",c(this,vl)),this._isDraggable=!0,(e=c(this,Jr))==null||e.abort(),b(this,Jr,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(){var e;this.width||(this.enableEditMode(),this.editorDiv.focus(),(e=this._initialOptions)!=null&&e.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=c(this,Ze),s=b(this,Ze,y(this,Vt,zb).call(this).trimEnd());if(e===s)return;const i=n=>{if(b(this,Ze,n),!n){this.remove();return}y(this,Vt,tu).call(this),this._uiManager.rebuild(this),y(this,Vt,Jd).call(this)};this.addCommands({cmd:()=>{i(s)},undo:()=>{i(e)},mustExec:!1}),y(this,Vt,Jd).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){yt._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",c(this,vl)),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(${c(this,ts)}px * var(--scale-factor))`,i.color=c(this,Rs),this.div.append(this.editorDiv),this.overlayDiv=document.createElement("div"),this.overlayDiv.classList.add("overlay","enabled"),this.div.append(this.overlayDiv),ad(this,this.div,["dblclick","keydown"]),this.width){const[n,r]=this.parentDimensions;if(this.annotationElementId){const{position:o}=this._initialData;let[h,l]=this.getInitialTranslation();[h,l]=this.pageTranslationToScreen(h,l);const[d,u]=this.pageDimensions,[g,f]=this.pageTranslation;let p,m;switch(this.rotation){case 0:p=e+(o[0]-g)/d,m=s+this.height-(o[1]-f)/u;break;case 90:p=e+(o[0]-g)/d,m=s-(o[1]-f)/u,[h,l]=[l,-h];break;case 180:p=e-this.width+(o[0]-g)/d,m=s-(o[1]-f)/u,[h,l]=[-h,-l];break;case 270:p=e+(o[0]-g-this.height*u)/d,m=s+(o[1]-f-this.width*d)/u,[h,l]=[-l,h];break}this.setAt(p*n,m*r,h,l)}else this.setAt(e*n,s*r,this.width*n,this.height*r);y(this,Vt,tu).call(this),this._isDraggable=!0,this.editorDiv.contentEditable=!1}else this._isDraggable=!1,this.editorDiv.contentEditable=!0;return this.div}editorDivPaste(e){var p,m,w;const s=e.clipboardData||window.clipboardData,{types:i}=s;if(i.length===1&&i[0]==="text/plain")return;e.preventDefault();const n=y(p=yt,Yi,Df).call(p,s.getData("text")||"").replaceAll(fd,`
498
+ `}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.vibrance;for(let i=0;i<e.length;i+=4){const n=Math.max(e[i],e[i+1],e[i+2]),r=(e[i]+e[i+1]+e[i+2])/3,o=2*Math.abs(n-r)/255*s;e[i]+=n!==e[i]?(n-e[i])*o:0,e[i+1]+=n!==e[i+1]?(n-e[i+1])*o:0,e[i+2]+=n!==e[i+2]?(n-e[i+2])*o:0}}sendUniformData(t,e){t.uniform1f(e.uVibrance,-this.vibrance)}isNeutralState(){return this.vibrance===0}}A(Zc,"type","Vibrance"),A(Zc,"defaults",{vibrance:0}),A(Zc,"uniformLocations",["uVibrance"]),N.setClass(Zc);const ow="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2040%2040'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3ccircle%20cx='20'%20cy='20'%20r='10.75'%20stroke='currentColor'%20stroke-width='2.5'/%3e%3cpath%20d='M16%2024L23.7782%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3cpath%20d='M24%2024L16.2218%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3c/svg%3e";function aw(a){return new URL(Object.assign({"../assets/close.svg":ow})[`../assets/${a}`],typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Mt&&Mt.src||new URL("pdf-canvas.umd.js",document.baseURI).href).href}function hw(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 lw(i))}),i.addEventListener("error",n=>{window.URL.revokeObjectURL(s),e(n)})})}function lw(a){return new Promise(t=>{const e=document.createElement("canvas"),s=e.getContext("2d"),{naturalWidth:i,naturalHeight:n}=a;e.width=i,e.height=n,s==null||s.drawImage(a,0,0,i,n),t(e.toDataURL("image/jpeg",.8))})}let n0=null;function cw(){const a=document.createElement("div");a.style.width="1in",document.body.append(a);const t=a.offsetWidth;return a.remove(),t}function dw(){const a=n0??cw();return n0=a,a/72}function uw(a,t=500){if(typeof a!="function")throw new TypeError("The first argument is not a function.");let e=null;return function(...s){e&&clearTimeout(e),e=setTimeout(()=>{e=null,a.apply(this,s)},t)}}const as=new Map;function gw(a){const t=new tg(a);return as.set(a,t),t}function fw(a,t){const e=Date.now();return{PDFId:`${a.name}-${e}`,name:a.name.replace(/.pdf/,""),updateDate:e,PDFBase64:t}}function pw(a,t){const e=a.getViewport({scale:t}),s=document.createElement("canvas"),i=s.getContext("2d"),n=dw()/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 mw(a,t,e){const s=a||aw("close.svg"),{objects:i,options:n}=await K_(s),r=i.filter(h=>h!==null),o=c_.groupSVGElements(r,n);return r.forEach(h=>{h.stroke=t}),o.hoverCursor="pointer",o.stroke=`${t}-${e}`,o}function bw(a,t){if(!as.get(a))return;const s=1/3,i=Sw(t,s);o0(a,i,s)}async function vw(a,t){const e=await hw(t),s=Date.now(),n={PDFId:`${t.name}${s}`,name:t.name.replace(/.png|.jpg|.jpeg/,""),updateDate:s,PDFBase64:e};return r0(a,{url:e}),{...n,pages:1}}async function r0(a,{url:t,scale:e=.5}){if(!as.get(a))return;const i=await fe.fromURL(t);i.scale(e),o0(a,i,e)}function o0(a,t,e){const s=as.get(a);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function lh(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 yw(a,t,e){!e||!a||(e.scale(1/t),lh(a,e))}function _w(a,t,e){a&&(a.borderScaleFactor=1/t,a.cornerSize=6*(1/t),a.touchCornerSize=24*(1/t),a.cornerStrokeColor=e.stroke,a.setCoords())}function ww(a){const t=as.get(a);t&&(t.discardActiveObject(),t.renderAll())}function xw(a){const t=as.get(a);t&&(t.clear(),as.delete(a))}function Sw(a,t){return new fe(a,{scaleX:t,scaleY:t})}var ch={};ch.d=(a,t)=>{for(var e in t)ch.o(t,e)&&!ch.o(a,e)&&Object.defineProperty(a,e,{enumerable:!0,get:t[e]})},ch.o=(a,t)=>Object.prototype.hasOwnProperty.call(a,t);var $=globalThis.pdfjsLib={};ch.d($,{AbortException:()=>lr,AnnotationEditorLayer:()=>Kg,AnnotationEditorParamsType:()=>Y,AnnotationEditorType:()=>Z,AnnotationEditorUIManager:()=>dr,AnnotationLayer:()=>wS,AnnotationMode:()=>fn,ColorPicker:()=>bd,DOMSVGFactory:()=>zg,DrawLayer:()=>Qg,FeatureTest:()=>ke,GlobalWorkerOptions:()=>ki,ImageKind:()=>td,InvalidPDFException:()=>h0,MissingPDFException:()=>hr,OPS:()=>Ts,OutputScale:()=>Ag,PDFDataRangeTransport:()=>W0,PDFDateString:()=>Sg,PDFWorker:()=>Bo,PasswordResponses:()=>Ew,PermissionFlag:()=>Tw,PixelsPerInch:()=>mn,RenderingCancelledException:()=>wg,TextLayer:()=>vh,UnexpectedResponseException:()=>nd,Util:()=>X,VerbosityLevel:()=>ed,XfaLayer:()=>G0,build:()=>eS,createValidAbsoluteUrl:()=>Dw,fetchData:()=>od,getDocument:()=>Ux,getFilenameFromUrl:()=>Hw,getPdfFilenameFromUrl:()=>Ww,getXfaPageViewport:()=>Xw,isDataScheme:()=>ad,isPdfFile:()=>xg,noContextMenu:()=>hs,normalizeUnicode:()=>jw,setLayerDimensions:()=>cr,shadow:()=>ot,version:()=>tS});const pe=typeof process=="object"&&process+""=="[object process]"&&!process.versions.nw&&!(process.versions.electron&&process.type&&process.type!=="browser"),a0=[1,0,0,1,0,0],gg=[.001,0,0,.001,0,0],Cw=1e7,fg=1.35,Ye={ANY:1,DISPLAY:2,PRINT:4,SAVE:8,ANNOTATIONS_FORMS:16,ANNOTATIONS_STORAGE:32,ANNOTATIONS_DISABLE:64,IS_EDITING:128,OPLIST:256},fn={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},Aw="pdfjs_internal_editor_",Z={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15},Y={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},Tw={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},me={FILL:0,STROKE:1,FILL_STROKE:2,INVISIBLE:3,FILL_ADD_TO_PATH:4,STROKE_ADD_TO_PATH:5,FILL_STROKE_ADD_TO_PATH:6,ADD_TO_PATH:7,FILL_STROKE_MASK:3,ADD_TO_PATH_FLAG:4},td={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},Gt={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,SOUND:18,MOVIE:19,WIDGET:20,SCREEN:21,PRINTERMARK:22,TRAPNET:23,WATERMARK:24,THREED:25,REDACT:26},dh={SOLID:1,DASHED:2,BEVELED:3,INSET:4,UNDERLINE:5},ed={ERRORS:0,WARNINGS:1,INFOS:5},Ts={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},Ew={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};let sd=ed.WARNINGS;function kw(a){Number.isInteger(a)&&(sd=a)}function Mw(){return sd}function id(a){sd>=ed.INFOS&&console.log(`Info: ${a}`)}function st(a){sd>=ed.WARNINGS&&console.log(`Warning: ${a}`)}function yt(a){throw new Error(a)}function Ut(a,t){a||yt(t)}function Ow(a){switch(a==null?void 0:a.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}function Dw(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=Iw(a)}catch{}}const s=t?new URL(a,t):new URL(a);if(Ow(s))return s}catch{}return null}function ot(a,t,e,s=!1){return Object.defineProperty(a,t,{value:e,enumerable:!s,configurable:!0,writable:!1}),e}const pn=function(){function t(e,s){this.message=e,this.name=s}return t.prototype=new Error,t.constructor=t,t}();class pg extends pn{constructor(t,e){super(t,"PasswordException"),this.code=e}}class mg extends pn{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}}class h0 extends pn{constructor(t){super(t,"InvalidPDFException")}}class hr extends pn{constructor(t){super(t,"MissingPDFException")}}class nd extends pn{constructor(t,e){super(t,"UnexpectedResponseException"),this.status=e}}class Pw extends pn{constructor(t){super(t,"FormatError")}}class lr extends pn{constructor(t){super(t,"AbortException")}}function l0(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 rd(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 Lw(a){return String.fromCharCode(a>>24&255,a>>16&255,a>>8&255,a&255)}function bg(a){const t=Object.create(null);for(const[e,s]of a)t[e]=s;return t}function Fw(){const a=new Uint8Array(4);return a[0]=1,new Uint32Array(a.buffer,0,1)[0]===1}function Rw(){try{return new Function(""),!0}catch{return!1}}class ke{static get isLittleEndian(){return ot(this,"isLittleEndian",Fw())}static get isEvalSupported(){return ot(this,"isEvalSupported",Rw())}static get isOffscreenCanvasSupported(){return ot(this,"isOffscreenCanvasSupported",typeof OffscreenCanvas<"u")}static get platform(){return typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.platform)=="string"?ot(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")}):ot(this,"platform",{isMac:!1,isWindows:!1,isFirefox:!1})}static get isCSSRoundSupported(){var t,e;return ot(this,"isCSSRoundSupported",(e=(t=globalThis.CSS)==null?void 0:t.supports)==null?void 0:e.call(t,"width: round(1.5px, 1px)"))}}const vg=Array.from(Array(256).keys(),a=>a.toString(16).padStart(2,"0"));class X{static makeHexColor(t,e,s){return`#${vg[t]}${vg[e]}${vg[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,l=o+h||1,d=o-h||1;return[Math.sqrt(l),Math.sqrt(d)]}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,l){return l?(l[0]=Math.min(l[0],t,o),l[1]=Math.min(l[1],e,h),l[2]=Math.max(l[2],t,o),l[3]=Math.max(l[3],e,h)):l=[Math.min(t,o),Math.min(e,h),Math.max(t,o),Math.max(e,h)],y(this,Oi,sf).call(this,t,s,n,o,e,i,r,h,3*(-t+3*(s-n)+o),6*(t-2*s+n),3*(s-t),l),y(this,Oi,sf).call(this,t,s,n,o,e,i,r,h,3*(-e+3*(i-r)+h),6*(e-2*i+r),3*(i-e),l),l}}Oi=new WeakSet,Nd=function(t,e,s,i,n,r,o,h,l,d){if(l<=0||l>=1)return;const u=1-l,g=l*l,f=g*l,p=u*(u*(u*t+3*l*e)+3*g*s)+f*i,m=u*(u*(u*n+3*l*r)+3*g*o)+f*h;d[0]=Math.min(d[0],p),d[1]=Math.min(d[1],m),d[2]=Math.max(d[2],p),d[3]=Math.max(d[3],m)},sf=function(t,e,s,i,n,r,o,h,l,d,u,g){if(Math.abs(l)<1e-12){Math.abs(d)>=1e-12&&y(this,Oi,Nd).call(this,t,e,s,i,n,r,o,h,-u/d,g);return}const f=d**2-4*u*l;if(f<0)return;const p=Math.sqrt(f),m=2*l;y(this,Oi,Nd).call(this,t,e,s,i,n,r,o,h,(-d+p)/m,g),y(this,Oi,Nd).call(this,t,e,s,i,n,r,o,h,(-d-p)/m,g)},w(X,Oi);function Iw(a){return decodeURIComponent(escape(a))}let yg=null,c0=null;function jw(a){return yg||(yg=/([\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,c0=new Map([["ſt","ſt"]])),a.replaceAll(yg,(t,e,s)=>e?e.normalize("NFKC"):c0.get(s))}function Nw(){if(typeof crypto<"u"&&typeof(crypto==null?void 0:crypto.randomUUID)=="function")return crypto.randomUUID();const a=new Uint8Array(32);if(typeof crypto<"u"&&typeof(crypto==null?void 0:crypto.getRandomValues)=="function")crypto.getRandomValues(a);else for(let t=0;t<32;t++)a[t]=Math.floor(Math.random()*255);return l0(a)}const _g="pdfjs_internal_id_",Ai={BEZIER_CURVE_TO:0,MOVE_TO:1,LINE_TO:2,QUADRATIC_CURVE_TO:3,RESTORE:4,SAVE:5,SCALE:6,TRANSFORM:7,TRANSLATE:8};function Bw(a){return Uint8Array.prototype.toBase64?a.toBase64():btoa(l0(a))}const Ti="http://www.w3.org/2000/svg",fr=class fr{};q(fr,"CSS",96),q(fr,"PDF",72),q(fr,"PDF_TO_CSS_UNITS",fr.CSS/fr.PDF);let mn=fr;async function od(a,t="text"){if(gh(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,scale:e,rotation:s,offsetX:i=0,offsetY:n=0,dontFlip:r=!1}){this.viewBox=t,this.scale=e,this.rotation=s,this.offsetX=i,this.offsetY=n;const o=(t[2]+t[0])/2,h=(t[3]+t[1])/2;let l,d,u,g;switch(s%=360,s<0&&(s+=360),s){case 180:l=-1,d=0,u=0,g=1;break;case 90:l=0,d=1,u=1,g=0;break;case 270:l=0,d=-1,u=-1,g=0;break;case 0:l=1,d=0,u=0,g=-1;break;default:throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.")}r&&(u=-u,g=-g);let f,p,m,_;l===0?(f=Math.abs(h-t[1])*e+i,p=Math.abs(o-t[0])*e+n,m=(t[3]-t[1])*e,_=(t[2]-t[0])*e):(f=Math.abs(o-t[0])*e+i,p=Math.abs(h-t[1])*e+n,m=(t[2]-t[0])*e,_=(t[3]-t[1])*e),this.transform=[l*e,d*e,u*e,g*e,f-l*e*o-u*e*h,p-d*e*o-g*e*h],this.width=m,this.height=_}get rawDims(){const{viewBox:t}=this;return ot(this,"rawDims",{pageWidth:t[2]-t[0],pageHeight:t[3]-t[1],pageX:t[0],pageY:t[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(),scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}convertToViewportPoint(t,e){return X.applyTransform([t,e],this.transform)}convertToViewportRectangle(t){const e=X.applyTransform([t[0],t[1]],this.transform),s=X.applyTransform([t[2],t[3]],this.transform);return[e[0],e[1],s[0],s[1]]}convertToPdfPoint(t,e){return X.applyInverseTransform([t,e],this.transform)}}class wg extends pn{constructor(t,e=0){super(t,"RenderingCancelledException"),this.extraDelay=e}}function ad(a){const t=a.length;let e=0;for(;e<t&&a[e].trim()==="";)e++;return a.substring(e,e+5).toLowerCase()==="data:"}function xg(a){return typeof a=="string"&&/\.pdf$/i.test(a)}function Hw(a){return[a]=a.split(/[#?]/,1),a.substring(a.lastIndexOf("/")+1)}function Ww(a,t="document.pdf"){if(typeof a!="string")return t;if(ad(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 d0{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
499
+ `);return t.join("")}}function gh(a,t){try{const{protocol:e}=t?new URL(a,t):new URL(a);return e==="http:"||e==="https:"}catch{return!1}}function hs(a){a.preventDefault()}function u0(a){console.log("Deprecated API usage: "+a)}class Sg{static toDateObject(t){if(!t||typeof t!="string")return null;c(this,xh)||b(this,xh,new RegExp("^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+|-])?(\\d{2})?'?(\\d{2})?'?"));const e=c(this,xh).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 l=e[7]||"Z";let d=parseInt(e[8],10);d=d>=0&&d<=23?d:0;let u=parseInt(e[9],10)||0;return u=u>=0&&u<=59?u:0,l==="-"?(r+=d,o+=u):l==="+"&&(r-=d,o-=u),new Date(Date.UTC(s,i,n,r,o,h))}}xh=new WeakMap,w(Sg,xh);function Xw(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,scale:t,rotation:e})}function Cg(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 zw(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,Cg(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 Ei(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 cr(a,t,e=!1,s=!0){if(t instanceof uh){const{pageWidth:i,pageHeight:n}=t.rawDims,{style:r}=a,o=ke.isCSSRoundSupported,h=`var(--scale-factor) * ${i}px`,l=`var(--scale-factor) * ${n}px`,d=o?`round(down, ${h}, var(--scale-round-x, 1px))`:`calc(${h})`,u=o?`round(down, ${l}, var(--scale-round-y, 1px))`:`calc(${l})`;!e||t.rotation%180===0?(r.width=d,r.height=u):(r.width=u,r.height=d)}s&&a.setAttribute("data-main-rotation",t.rotation)}class Ag{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 Di=class Di{constructor(t){w(this,Oe);w(this,vn,null);w(this,pr,null);w(this,Es);w(this,mr,null);w(this,Sh,null);b(this,Es,t),c(Di,Ch)||b(Di,Ch,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=b(this,vn,document.createElement("div"));t.classList.add("editToolbar","hidden"),t.setAttribute("role","toolbar");const e=c(this,Es)._uiManager._signal;t.addEventListener("contextmenu",hs,{signal:e}),t.addEventListener("pointerdown",y(Di,_d,nb),{signal:e});const s=b(this,mr,document.createElement("div"));s.className="buttons",t.append(s);const i=c(this,Es).toolbarPosition;if(i){const{style:n}=t,r=c(this,Es)._uiManager.direction==="ltr"?1-i[0]:i[0];n.insetInlineEnd=`${100*r}%`,n.top=`calc(${100*i[1]}% + var(--editor-toolbar-vert-offset))`}return y(this,Oe,ab).call(this),t}get div(){return c(this,vn)}hide(){var t;c(this,vn).classList.add("hidden"),(t=c(this,pr))==null||t.hideDropdown()}show(){var t;c(this,vn).classList.remove("hidden"),(t=c(this,Sh))==null||t.shown()}async addAltText(t){const e=await t.render();y(this,Oe,Bd).call(this,e),c(this,mr).prepend(e,c(this,Oe,nf)),b(this,Sh,t)}addColorPicker(t){b(this,pr,t);const e=t.renderButton();y(this,Oe,Bd).call(this,e),c(this,mr).prepend(e,c(this,Oe,nf))}remove(){var t;c(this,vn).remove(),(t=c(this,pr))==null||t.destroy(),b(this,pr,null)}};vn=new WeakMap,pr=new WeakMap,Es=new WeakMap,mr=new WeakMap,Sh=new WeakMap,Ch=new WeakMap,_d=new WeakSet,nb=function(t){t.stopPropagation()},Oe=new WeakSet,rb=function(t){c(this,Es)._focusEventsAllowed=!1,t.preventDefault(),t.stopPropagation()},ob=function(t){c(this,Es)._focusEventsAllowed=!0,t.preventDefault(),t.stopPropagation()},Bd=function(t){const e=c(this,Es)._uiManager._signal;t.addEventListener("focusin",y(this,Oe,rb).bind(this),{capture:!0,signal:e}),t.addEventListener("focusout",y(this,Oe,ob).bind(this),{capture:!0,signal:e}),t.addEventListener("contextmenu",hs,{signal:e})},ab=function(){const{editorType:t,_uiManager:e}=c(this,Es),s=document.createElement("button");s.className="delete",s.tabIndex=0,s.setAttribute("data-l10n-id",c(Di,Ch)[t]),y(this,Oe,Bd).call(this,s),s.addEventListener("click",i=>{e.delete()},{signal:e._signal}),c(this,mr).append(s)},nf=function(){const t=document.createElement("div");return t.className="divider",t},w(Di,_d),w(Di,Ch,null);let Tg=Di;class Vw{constructor(t){w(this,yn);w(this,Ah,null);w(this,br,null);w(this,vr);b(this,vr,t)}show(t,e,s){const[i,n]=y(this,yn,lb).call(this,e,s),{style:r}=c(this,br)||b(this,br,y(this,yn,hb).call(this));t.append(c(this,br)),r.insetInlineEnd=`${100*i}%`,r.top=`calc(${100*n}% + var(--editor-toolbar-vert-offset))`}hide(){c(this,br).remove()}}Ah=new WeakMap,br=new WeakMap,vr=new WeakMap,yn=new WeakSet,hb=function(){const t=b(this,br,document.createElement("div"));t.className="editToolbar",t.setAttribute("role","toolbar"),t.addEventListener("contextmenu",hs,{signal:c(this,vr)._signal});const e=b(this,Ah,document.createElement("div"));return e.className="buttons",t.append(e),y(this,yn,cb).call(this),t},lb=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]},cb=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=c(this,vr)._signal;t.addEventListener("contextmenu",hs,{signal:s}),t.addEventListener("click",()=>{c(this,vr).highlightSelection("floating_button")},{signal:s}),c(this,Ah).append(t)};function hd(a,t,e){for(const s of e)t.addEventListener(s,a[s].bind(a))}function Gw(a){return Math.round(Math.min(255,Math.max(1,255*a))).toString(16).padStart(2,"0")}class Uw{constructor(){w(this,wd,0)}get id(){return`${Aw}${Fe(this,wd)._++}`}}wd=new WeakMap;const Jg=class Jg{constructor(){w(this,Wo);w(this,Ho,Nw());w(this,Th,0);w(this,be,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 ot(this,"_isSVGFittingCanvas",n)}async getFromFile(t){const{lastModified:e,name:s,size:i,type:n}=t;return y(this,Wo,Hd).call(this,`${e}_${s}_${i}_${n}`,t)}async getFromUrl(t){return y(this,Wo,Hd).call(this,t,t)}async getFromBlob(t,e){const s=await e;return y(this,Wo,Hd).call(this,t,s)}async getFromId(t){c(this,be)||b(this,be,new Map);const e=c(this,be).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){c(this,be)||b(this,be,new Map);let s=c(this,be).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_${c(this,Ho)}_${Fe(this,Th)._++}`,refCounter:1,isSvg:!1},c(this,be).set(t,s),c(this,be).set(s.id,s),s}getSvgUrl(t){const e=c(this,be).get(t);return e!=null&&e.isSvg?e.svgUrl:null}deleteId(t){var i;c(this,be)||b(this,be,new Map);const e=c(this,be).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_${c(this,Ho)}_`)}};Ho=new WeakMap,Th=new WeakMap,be=new WeakMap,Wo=new WeakSet,Hd=async function(t,e){c(this,be)||b(this,be,new Map);let s=c(this,be).get(t);if(s===null)return null;if(s!=null&&s.bitmap)return s.refCounter+=1,s;try{s||(s={bitmap:null,id:`image_${c(this,Ho)}_${Fe(this,Th)._++}`,refCounter:0,isSvg:!1});let i;if(typeof e=="string"?(s.url=e,i=await od(e,"blob")):e instanceof File?i=s.file=e:e instanceof Blob&&(i=e),i.type==="image/svg+xml"){const n=Jg._isSVGFittingCanvas,r=new FileReader,o=new Image,h=new Promise((l,d)=>{o.onload=()=>{s.bitmap=o,s.isSvg=!0,l()},r.onload=async()=>{const u=s.svgUrl=r.result;o.src=await n?`${u}#svgView(preserveAspectRatio(none))`:u},o.onerror=r.onerror=d});r.readAsDataURL(i),await h}else s.bitmap=await createImageBitmap(i);s.refCounter=1}catch(i){console.error(i),s=null}return c(this,be).set(t,s),s&&c(this,be).set(s.id,s),s};let Eg=Jg;class Yw{constructor(t=128){w(this,te,[]);w(this,_n,!1);w(this,Eh);w(this,ee,-1);b(this,Eh,t)}add({cmd:t,undo:e,post:s,mustExec:i,type:n=NaN,overwriteIfSameType:r=!1,keepUndo:o=!1}){if(i&&t(),c(this,_n))return;const h={cmd:t,undo:e,post:s,type:n};if(c(this,ee)===-1){c(this,te).length>0&&(c(this,te).length=0),b(this,ee,0),c(this,te).push(h);return}if(r&&c(this,te)[c(this,ee)].type===n){o&&(h.undo=c(this,te)[c(this,ee)].undo),c(this,te)[c(this,ee)]=h;return}const l=c(this,ee)+1;l===c(this,Eh)?c(this,te).splice(0,1):(b(this,ee,l),l<c(this,te).length&&c(this,te).splice(l)),c(this,te).push(h)}undo(){if(c(this,ee)===-1)return;b(this,_n,!0);const{undo:t,post:e}=c(this,te)[c(this,ee)];t(),e==null||e(),b(this,_n,!1),b(this,ee,c(this,ee)-1)}redo(){if(c(this,ee)<c(this,te).length-1){b(this,ee,c(this,ee)+1),b(this,_n,!0);const{cmd:t,post:e}=c(this,te)[c(this,ee)];t(),e==null||e(),b(this,_n,!1)}}hasSomethingToUndo(){return c(this,ee)!==-1}hasSomethingToRedo(){return c(this,ee)<c(this,te).length-1}destroy(){b(this,te,null)}}te=new WeakMap,_n=new WeakMap,Eh=new WeakMap,ee=new WeakMap;class fh{constructor(t){w(this,xd);this.buffer=[],this.callbacks=new Map,this.allKeys=new Set;const{isMac:e}=ke.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(y(this,xd,db).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||(e.stopPropagation(),e.preventDefault()))}}xd=new WeakSet,db=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 Sd=class Sd{get _colors(){const t=new Map([["CanvasText",null],["Canvas",null]]);return zw(t),ot(this,"_colors",t)}convert(t){const e=Cg(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 Sd._colorsMapping.get(s);return e}getHexCode(t){const e=this._colors.get(t);return e?X.makeHexColor(...e):t}};q(Sd,"_colorsMapping",new Map([["CanvasText",[0,0,0]],["Canvas",[255,255,255]]]));let kg=Sd;const qo=class qo{constructor(t,e,s,i,n,r,o,h,l,d,u){w(this,I);w(this,Xo,new AbortController);w(this,$e,null);w(this,Yt,new Map);w(this,re,new Map);w(this,zo,null);w(this,Pi,null);w(this,Vo,null);w(this,ks,new Yw);w(this,wn,null);w(this,Go,0);w(this,yr,new Set);w(this,$s,null);w(this,Ms,null);w(this,_r,new Set);w(this,kh,!1);w(this,Mh,!1);w(this,Uo,!1);w(this,Oh,null);w(this,Ks,null);w(this,xn,null);w(this,Yo,null);w(this,Sn,!1);w(this,Qs,null);w(this,Cd,new Uw);w(this,Cn,!1);w(this,Dh,!1);w(this,An,null);w(this,wr,null);w(this,Ph,null);w(this,Lh,null);w(this,se,Z.NONE);w(this,ft,new Set);w(this,Li,null);w(this,xr,null);w(this,Fh,null);w(this,Rh,{isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1});w(this,Tn,[0,0]);w(this,Js,null);w(this,Fi,null);w(this,Ih,null);w(this,cs,null);const g=this._signal=c(this,Xo).signal;b(this,Fi,t),b(this,Ih,e),b(this,zo,s),this._eventBus=i,i._on("editingaction",this.onEditingAction.bind(this),{signal:g}),i._on("pagechanging",this.onPageChanging.bind(this),{signal:g}),i._on("scalechanging",this.onScaleChanging.bind(this),{signal:g}),i._on("rotationchanging",this.onRotationChanging.bind(this),{signal:g}),i._on("setpreference",this.onSetPreference.bind(this),{signal:g}),i._on("switchannotationeditorparams",f=>this.updateParams(f.type,f.value),{signal:g}),y(this,I,fb).call(this),y(this,I,vb).call(this),y(this,I,of).call(this),b(this,Pi,n.annotationStorage),b(this,Oh,n.filterFactory),b(this,xr,r),b(this,Yo,o||null),b(this,kh,h),b(this,Mh,l),b(this,Uo,d),b(this,Lh,u||null),this.viewParameters={realScale:mn.PDF_TO_CSS_UNITS,rotation:0},this.isShiftKeyDown=!1}static get _keyboardManager(){const t=qo.prototype,e=r=>c(r,Fi).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 ot(this,"_keyboardManager",new fh([[["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)&&c(r,Fi).contains(o)&&!r.isEnterHandled}],[[" ","mac+ "],t.addNewEditorFromKeyboard,{checker:(r,{target:o})=>!(o instanceof HTMLButtonElement)&&c(r,Fi).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;(t=c(this,cs))==null||t.resolve(),b(this,cs,null),(e=c(this,Xo))==null||e.abort(),b(this,Xo,null),this._signal=null;for(const n of c(this,re).values())n.destroy();c(this,re).clear(),c(this,Yt).clear(),c(this,_r).clear(),b(this,$e,null),c(this,ft).clear(),c(this,ks).destroy(),(s=c(this,zo))==null||s.destroy(),(i=c(this,Qs))==null||i.hide(),b(this,Qs,null),c(this,Ks)&&(clearTimeout(c(this,Ks)),b(this,Ks,null)),c(this,Js)&&(clearTimeout(c(this,Js)),b(this,Js,null))}combinedSignal(t){return AbortSignal.any([this._signal,t.signal])}get mlManager(){return c(this,Lh)}get useNewAltTextFlow(){return c(this,Mh)}get useNewAltTextWhenAddingImage(){return c(this,Uo)}get hcmFilter(){return ot(this,"hcmFilter",c(this,xr)?c(this,Oh).addHCMFilter(c(this,xr).foreground,c(this,xr).background):"none")}get direction(){return ot(this,"direction",getComputedStyle(c(this,Fi)).direction)}get highlightColors(){return ot(this,"highlightColors",c(this,Yo)?new Map(c(this,Yo).split(",").map(t=>t.split("=").map(e=>e.trim()))):null)}get highlightColorNames(){return ot(this,"highlightColorNames",this.highlightColors?new Map(Array.from(this.highlightColors,t=>t.reverse())):null)}setMainHighlightColorPicker(t){b(this,Ph,t)}editAltText(t,e=!1){var s;(s=c(this,zo))==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":b(this,Uo,e);break}}onPageChanging({pageNumber:t}){b(this,Go,t-1)}focusMainContainer(){c(this,Fi).focus()}findParent(t,e){for(const s of c(this,re).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){c(this,Ih).classList.toggle("noUserSelect",t)}addShouldRescale(t){c(this,_r).add(t)}removeShouldRescale(t){c(this,_r).delete(t)}onScaleChanging({scale:t}){this.commitOrRemove(),this.viewParameters.realScale=t*mn.PDF_TO_CSS_UNITS;for(const e of c(this,_r))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(),l=y(this,I,Wd).call(this,e).closest(".textLayer"),d=this.getSelectionBoxes(l);if(!d)return;e.empty();const u=y(this,I,rf).call(this,l),g=c(this,se)===Z.NONE,f=()=>{u==null||u.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:t,boxes:d,anchorNode:s,anchorOffset:i,focusNode:n,focusOffset:r,text:o}),g&&this.showAllEditors("highlight",!0,!0)};if(g){this.switchToMode(Z.HIGHLIGHT,f);return}f()}addToAnnotationStorage(t){!t.isEmpty()&&c(this,Pi)&&!c(this,Pi).has(t.id)&&c(this,Pi).setValue(t.id,t)}blur(){if(this.isShiftKeyDown=!1,c(this,Sn)&&(b(this,Sn,!1),y(this,I,Xd).call(this,"main_toolbar")),!this.hasSelection)return;const{activeElement:t}=document;for(const e of c(this,ft))if(e.div.contains(t)){b(this,wr,[e,t]),e._focusEventsAllowed=!1;break}}focus(){if(!c(this,wr))return;const[t,e]=c(this,wr);b(this,wr,null),e.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this._signal}),e.focus()}addEditListeners(){y(this,I,of).call(this),y(this,I,af).call(this)}removeEditListeners(){y(this,I,bb).call(this),y(this,I,hf).call(this)}dragOver(t){for(const{type:e}of t.dataTransfer.items)for(const s of c(this,Ms))if(s.isHandlingMimeForPasting(e)){t.dataTransfer.dropEffect="copy",t.preventDefault();return}}drop(t){for(const e of t.dataTransfer.items)for(const s of c(this,Ms))if(s.isHandlingMimeForPasting(e.type)){s.paste(e,this.currentLayer),t.preventDefault();return}}copy(t){var s;if(t.preventDefault(),(s=c(this,$e))==null||s.commitOrRemove(),!this.hasSelection)return;const e=[];for(const i of c(this,ft)){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 c(this,Ms))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 l=await i.deserialize(h);if(!l)return;n.push(l)}const r=()=>{for(const h of n)y(this,I,lf).call(this,h);y(this,I,cf).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),c(this,se)!==Z.NONE&&!this.isEditorHandlingKeyboard&&qo._keyboardManager.exec(this,t)}keyup(t){this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!1,c(this,Sn)&&(b(this,Sn,!1),y(this,I,Xd).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?(y(this,I,pb).call(this),y(this,I,af).call(this),y(this,I,Re).call(this,{isEditing:c(this,se)!==Z.NONE,isEmpty:y(this,I,Nl).call(this),hasSomethingToUndo:c(this,ks).hasSomethingToUndo(),hasSomethingToRedo:c(this,ks).hasSomethingToRedo(),hasSelectedEditor:!1})):(y(this,I,mb).call(this),y(this,I,hf).call(this),y(this,I,Re).call(this,{isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(t){if(!c(this,Ms)){b(this,Ms,t);for(const e of c(this,Ms))y(this,I,Yn).call(this,e.defaultPropertiesToUpdate)}}getId(){return c(this,Cd).id}get currentLayer(){return c(this,re).get(c(this,Go))}getLayer(t){return c(this,re).get(t)}get currentPageIndex(){return c(this,Go)}addLayer(t){c(this,re).set(t.pageIndex,t),c(this,Cn)?t.enable():t.disable()}removeLayer(t){c(this,re).delete(t.pageIndex)}async updateMode(t,e=null,s=!1){if(c(this,se)!==t&&!(c(this,cs)&&(await c(this,cs).promise,!c(this,cs)))){if(b(this,cs,Promise.withResolvers()),b(this,se,t),t===Z.NONE){this.setEditingState(!1),y(this,I,_b).call(this),c(this,cs).resolve();return}this.setEditingState(!0),await y(this,I,yb).call(this),this.unselectAll();for(const i of c(this,re).values())i.updateMode(t);if(!e){s&&this.addNewEditorFromKeyboard(),c(this,cs).resolve();return}for(const i of c(this,Yt).values())i.annotationElementId===e?(this.setSelected(i),i.enterInEditMode()):i.unselect();c(this,cs).resolve()}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(t){t!==c(this,se)&&this._eventBus.dispatch("switchannotationeditormode",{source:this,mode:t})}updateParams(t,e){var s;if(c(this,Ms)){switch(t){case Y.CREATE:this.currentLayer.addNewEditor();return;case Y.HIGHLIGHT_DEFAULT_COLOR:(s=c(this,Ph))==null||s.updateColor(e);break;case Y.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:{type:"highlight",action:"toggle_visibility"}}}),(c(this,Fh)||b(this,Fh,new Map)).set(t,e),this.showAllEditors("highlight",e);break}for(const i of c(this,ft))i.updateParams(t,e);for(const i of c(this,Ms))i.updateDefaultParams(t,e)}}showAllEditors(t,e,s=!1){var n;for(const r of c(this,Yt).values())r.editorType===t&&r.show(e);(((n=c(this,Fh))==null?void 0:n.get(Y.HIGHLIGHT_SHOW_ALL))??!0)!==e&&y(this,I,Yn).call(this,[[Y.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(c(this,Dh)!==t){b(this,Dh,t);for(const e of c(this,re).values())t?e.disableClick():e.enableClick(),e.div.classList.toggle("waiting",t)}}getEditors(t){const e=[];for(const s of c(this,Yt).values())s.pageIndex===t&&e.push(s);return e}getEditor(t){return c(this,Yt).get(t)}addEditor(t){c(this,Yt).set(t.id,t)}removeEditor(t){var e;t.div.contains(document.activeElement)&&(c(this,Ks)&&clearTimeout(c(this,Ks)),b(this,Ks,setTimeout(()=>{this.focusMainContainer(),b(this,Ks,null)},0))),c(this,Yt).delete(t.id),this.unselect(t),(!t.annotationElementId||!c(this,yr).has(t.annotationElementId))&&((e=c(this,Pi))==null||e.remove(t.id))}addDeletedAnnotationElement(t){c(this,yr).add(t.annotationElementId),this.addChangedExistingAnnotation(t),t.deleted=!0}isDeletedAnnotationElement(t){return c(this,yr).has(t)}removeDeletedAnnotationElement(t){c(this,yr).delete(t.annotationElementId),this.removeChangedExistingAnnotation(t),t.deleted=!1}setActiveEditor(t){c(this,$e)!==t&&(b(this,$e,t),t&&y(this,I,Yn).call(this,t.propertiesToUpdate))}updateUI(t){c(this,I,wb)===t&&y(this,I,Yn).call(this,t.propertiesToUpdate)}toggleSelected(t){if(c(this,ft).has(t)){c(this,ft).delete(t),t.unselect(),y(this,I,Re).call(this,{hasSelectedEditor:this.hasSelection});return}c(this,ft).add(t),t.select(),y(this,I,Yn).call(this,t.propertiesToUpdate),y(this,I,Re).call(this,{hasSelectedEditor:!0})}setSelected(t){for(const e of c(this,ft))e!==t&&e.unselect();c(this,ft).clear(),c(this,ft).add(t),t.select(),y(this,I,Yn).call(this,t.propertiesToUpdate),y(this,I,Re).call(this,{hasSelectedEditor:!0})}isSelected(t){return c(this,ft).has(t)}get firstSelectedEditor(){return c(this,ft).values().next().value}unselect(t){t.unselect(),c(this,ft).delete(t),y(this,I,Re).call(this,{hasSelectedEditor:this.hasSelection})}get hasSelection(){return c(this,ft).size!==0}get isEnterHandled(){return c(this,ft).size===1&&this.firstSelectedEditor.isEnterHandled}undo(){c(this,ks).undo(),y(this,I,Re).call(this,{hasSomethingToUndo:c(this,ks).hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:y(this,I,Nl).call(this)})}redo(){c(this,ks).redo(),y(this,I,Re).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:c(this,ks).hasSomethingToRedo(),isEmpty:y(this,I,Nl).call(this)})}addCommands(t){c(this,ks).add(t),y(this,I,Re).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:y(this,I,Nl).call(this)})}delete(){if(this.commitOrRemove(),!this.hasSelection)return;const t=[...c(this,ft)],e=()=>{for(const i of t)i.remove()},s=()=>{for(const i of t)y(this,I,lf).call(this,i)};this.addCommands({cmd:e,undo:s,mustExec:!0})}commitOrRemove(){var t;(t=c(this,$e))==null||t.commitOrRemove()}hasSomethingToControl(){return c(this,$e)||this.hasSelection}selectAll(){for(const t of c(this,ft))t.commit();y(this,I,cf).call(this,c(this,Yt).values())}unselectAll(){if(!(c(this,$e)&&(c(this,$e).commitOrRemove(),c(this,se)!==Z.NONE))&&this.hasSelection){for(const t of c(this,ft))t.unselect();c(this,ft).clear(),y(this,I,Re).call(this,{hasSelectedEditor:!1})}}translateSelectedEditors(t,e,s=!1){if(s||this.commitOrRemove(),!this.hasSelection)return;c(this,Tn)[0]+=t,c(this,Tn)[1]+=e;const[i,n]=c(this,Tn),r=[...c(this,ft)],o=1e3;c(this,Js)&&clearTimeout(c(this,Js)),b(this,Js,setTimeout(()=>{b(this,Js,null),c(this,Tn)[0]=c(this,Tn)[1]=0,this.addCommands({cmd:()=>{for(const h of r)c(this,Yt).has(h.id)&&h.translateInPage(i,n)},undo:()=>{for(const h of r)c(this,Yt).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),b(this,$s,new Map);for(const t of c(this,ft))c(this,$s).set(t,{savedX:t.x,savedY:t.y,savedPageIndex:t.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!c(this,$s))return!1;this.disableUserSelect(!1);const t=c(this,$s);b(this,$s,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(c(this,Yt).has(i.id)){const h=c(this,re).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(c(this,$s))for(const s of c(this,$s).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())||c(this,ft).size===1&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(t){return c(this,$e)===t}getActive(){return c(this,$e)}getMode(){return c(this,se)}get imageManager(){return ot(this,"imageManager",new Eg)}getSelectionBoxes(t){if(!t)return null;const e=document.getSelection();for(let l=0,d=e.rangeCount;l<d;l++)if(!t.contains(e.getRangeAt(l).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=(l,d,u,g)=>({x:(d-i)/r,y:1-(l+u-s)/n,width:g/r,height:u/n});break;case"180":o=(l,d,u,g)=>({x:1-(l+u-s)/n,y:1-(d+g-i)/r,width:u/n,height:g/r});break;case"270":o=(l,d,u,g)=>({x:1-(d+g-i)/r,y:(l-s)/n,width:g/r,height:u/n});break;default:o=(l,d,u,g)=>({x:(l-s)/n,y:(d-i)/r,width:u/n,height:g/r});break}const h=[];for(let l=0,d=e.rangeCount;l<d;l++){const u=e.getRangeAt(l);if(!u.collapsed)for(const{x:g,y:f,width:p,height:m}of u.getClientRects())p===0||m===0||h.push(o(g,f,p,m))}return h.length===0?null:h}addChangedExistingAnnotation({annotationElementId:t,id:e}){(c(this,Vo)||b(this,Vo,new Map)).set(t,e)}removeChangedExistingAnnotation({annotationElementId:t}){var e;(e=c(this,Vo))==null||e.delete(t)}renderAnnotationElement(t){var i;const e=(i=c(this,Vo))==null?void 0:i.get(t.data.id);if(!e)return;const s=c(this,Pi).getRawValue(e);s&&(c(this,se)===Z.NONE&&!s.hasBeenModified||s.renderAnnotationElement(t))}};Xo=new WeakMap,$e=new WeakMap,Yt=new WeakMap,re=new WeakMap,zo=new WeakMap,Pi=new WeakMap,Vo=new WeakMap,ks=new WeakMap,wn=new WeakMap,Go=new WeakMap,yr=new WeakMap,$s=new WeakMap,Ms=new WeakMap,_r=new WeakMap,kh=new WeakMap,Mh=new WeakMap,Uo=new WeakMap,Oh=new WeakMap,Ks=new WeakMap,xn=new WeakMap,Yo=new WeakMap,Sn=new WeakMap,Qs=new WeakMap,Cd=new WeakMap,Cn=new WeakMap,Dh=new WeakMap,An=new WeakMap,wr=new WeakMap,Ph=new WeakMap,Lh=new WeakMap,se=new WeakMap,ft=new WeakMap,Li=new WeakMap,xr=new WeakMap,Fh=new WeakMap,Rh=new WeakMap,Tn=new WeakMap,Js=new WeakMap,Fi=new WeakMap,Ih=new WeakMap,cs=new WeakMap,I=new WeakSet,Wd=function({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t},rf=function(t){const{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(const s of c(this,re).values())if(s.hasTextLayer(t))return s;return null},ub=function(){const t=document.getSelection();if(!t||t.isCollapsed)return;const s=y(this,I,Wd).call(this,t).closest(".textLayer"),i=this.getSelectionBoxes(s);i&&(c(this,Qs)||b(this,Qs,new Vw(this)),c(this,Qs).show(s,i,this.direction==="ltr"))},gb=function(){var n,r,o;const t=document.getSelection();if(!t||t.isCollapsed){c(this,Li)&&((n=c(this,Qs))==null||n.hide(),b(this,Li,null),y(this,I,Re).call(this,{hasSelectedText:!1}));return}const{anchorNode:e}=t;if(e===c(this,Li))return;const i=y(this,I,Wd).call(this,t).closest(".textLayer");if(!i){c(this,Li)&&((r=c(this,Qs))==null||r.hide(),b(this,Li,null),y(this,I,Re).call(this,{hasSelectedText:!1}));return}if((o=c(this,Qs))==null||o.hide(),b(this,Li,e),y(this,I,Re).call(this,{hasSelectedText:!0}),!(c(this,se)!==Z.HIGHLIGHT&&c(this,se)!==Z.NONE)&&(c(this,se)===Z.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0),b(this,Sn,this.isShiftKeyDown),!this.isShiftKeyDown)){const h=c(this,se)===Z.HIGHLIGHT?y(this,I,rf).call(this,i):null;h==null||h.toggleDrawing();const l=new AbortController,d=this.combinedSignal(l),u=g=>{g.type==="pointerup"&&g.button!==0||(l.abort(),h==null||h.toggleDrawing(!0),g.type==="pointerup"&&y(this,I,Xd).call(this,"main_toolbar"))};window.addEventListener("pointerup",u,{signal:d}),window.addEventListener("blur",u,{signal:d})}},Xd=function(t=""){c(this,se)===Z.HIGHLIGHT?this.highlightSelection(t):c(this,kh)&&y(this,I,ub).call(this)},fb=function(){document.addEventListener("selectionchange",y(this,I,gb).bind(this),{signal:this._signal})},pb=function(){if(c(this,xn))return;b(this,xn,new AbortController);const t=this.combinedSignal(c(this,xn));window.addEventListener("focus",this.focus.bind(this),{signal:t}),window.addEventListener("blur",this.blur.bind(this),{signal:t})},mb=function(){var t;(t=c(this,xn))==null||t.abort(),b(this,xn,null)},of=function(){if(c(this,An))return;b(this,An,new AbortController);const t=this.combinedSignal(c(this,An));window.addEventListener("keydown",this.keydown.bind(this),{signal:t}),window.addEventListener("keyup",this.keyup.bind(this),{signal:t})},bb=function(){var t;(t=c(this,An))==null||t.abort(),b(this,An,null)},af=function(){if(c(this,wn))return;b(this,wn,new AbortController);const t=this.combinedSignal(c(this,wn));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})},hf=function(){var t;(t=c(this,wn))==null||t.abort(),b(this,wn,null)},vb=function(){const t=this._signal;document.addEventListener("dragover",this.dragOver.bind(this),{signal:t}),document.addEventListener("drop",this.drop.bind(this),{signal:t})},Re=function(t){Object.entries(t).some(([s,i])=>c(this,Rh)[s]!==i)&&(this._eventBus.dispatch("annotationeditorstateschanged",{source:this,details:Object.assign(c(this,Rh),t)}),c(this,se)===Z.HIGHLIGHT&&t.hasSelectedEditor===!1&&y(this,I,Yn).call(this,[[Y.HIGHLIGHT_FREE,!0]]))},Yn=function(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})},yb=async function(){if(!c(this,Cn)){b(this,Cn,!0);const t=[];for(const e of c(this,re).values())t.push(e.enable());await Promise.all(t);for(const e of c(this,Yt).values())e.enable()}},_b=function(){if(this.unselectAll(),c(this,Cn)){b(this,Cn,!1);for(const t of c(this,re).values())t.disable();for(const t of c(this,Yt).values())t.disable()}},lf=function(t){const e=c(this,re).get(t.pageIndex);e?e.addOrRebuild(t):(this.addEditor(t),this.addToAnnotationStorage(t))},wb=function(){let t=null;for(t of c(this,ft));return t},Nl=function(){if(c(this,Yt).size===0)return!0;if(c(this,Yt).size===1)for(const t of c(this,Yt).values())return t.isEmpty();return!1},cf=function(t){for(const e of c(this,ft))e.unselect();c(this,ft).clear();for(const e of t)e.isEmpty()||(c(this,ft).add(e),e.select());y(this,I,Re).call(this,{hasSelectedEditor:this.hasSelection})},q(qo,"TRANSLATE_SMALL",1),q(qo,"TRANSLATE_BIG",10);let dr=qo;const De=class De{constructor(t){w(this,Ds);w(this,ie,null);w(this,Zs,!1);w(this,Os,null);w(this,$o,null);w(this,ti,null);w(this,Ke,null);w(this,Ko,!1);w(this,ei,null);w(this,He,null);w(this,Ri,null);w(this,Sr,null);w(this,si,!1);b(this,He,t),b(this,si,t._uiManager.useNewAltTextFlow),c(De,En)||b(De,En,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){De._l10n??(De._l10n=t)}async render(){const t=b(this,Os,document.createElement("button"));t.className="altText",t.tabIndex="0";const e=b(this,$o,document.createElement("span"));t.append(e),c(this,si)?(t.classList.add("new"),t.setAttribute("data-l10n-id",c(De,En).missing),e.setAttribute("data-l10n-id",c(De,En)["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=c(this,He)._uiManager._signal;t.addEventListener("contextmenu",hs,{signal:s}),t.addEventListener("pointerdown",n=>n.stopPropagation(),{signal:s});const i=n=>{n.preventDefault(),c(this,He)._uiManager.editAltText(c(this,He)),c(this,si)&&c(this,He)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_clicked",data:{label:c(this,Ds,Bl)}})};return t.addEventListener("click",i,{capture:!0,signal:s}),t.addEventListener("keydown",n=>{n.target===t&&n.key==="Enter"&&(b(this,Ko,!0),i(n))},{signal:s}),await y(this,Ds,zd).call(this),t}finish(){c(this,Os)&&(c(this,Os).focus({focusVisible:c(this,Ko)}),b(this,Ko,!1))}isEmpty(){return c(this,si)?c(this,ie)===null:!c(this,ie)&&!c(this,Zs)}hasData(){return c(this,si)?c(this,ie)!==null||!!c(this,Ri):this.isEmpty()}get guessedText(){return c(this,Ri)}async setGuessedText(t){c(this,ie)===null&&(b(this,Ri,t),b(this,Sr,await De._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",{generatedAltText:t})),y(this,Ds,zd).call(this))}toggleAltTextBadge(t=!1){var e;if(!c(this,si)||c(this,ie)){(e=c(this,ei))==null||e.remove(),b(this,ei,null);return}if(!c(this,ei)){const s=b(this,ei,document.createElement("div"));s.className="noAltTextBadge",c(this,He).div.append(s)}c(this,ei).classList.toggle("hidden",!t)}serialize(t){let e=c(this,ie);return!t&&c(this,Ri)===e&&(e=c(this,Sr)),{altText:e,decorative:c(this,Zs),guessedText:c(this,Ri),textWithDisclaimer:c(this,Sr)}}get data(){return{altText:c(this,ie),decorative:c(this,Zs)}}set data({altText:t,decorative:e,guessedText:s,textWithDisclaimer:i,cancel:n=!1}){s&&(b(this,Ri,s),b(this,Sr,i)),!(c(this,ie)===t&&c(this,Zs)===e)&&(n||(b(this,ie,t),b(this,Zs,e)),y(this,Ds,zd).call(this))}toggle(t=!1){c(this,Os)&&(!t&&c(this,Ke)&&(clearTimeout(c(this,Ke)),b(this,Ke,null)),c(this,Os).disabled=!t)}shown(){c(this,He)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_displayed",data:{label:c(this,Ds,Bl)}})}destroy(){var t,e;(t=c(this,Os))==null||t.remove(),b(this,Os,null),b(this,$o,null),b(this,ti,null),(e=c(this,ei))==null||e.remove(),b(this,ei,null)}};ie=new WeakMap,Zs=new WeakMap,Os=new WeakMap,$o=new WeakMap,ti=new WeakMap,Ke=new WeakMap,Ko=new WeakMap,ei=new WeakMap,He=new WeakMap,Ri=new WeakMap,Sr=new WeakMap,si=new WeakMap,En=new WeakMap,Ds=new WeakSet,Bl=function(){return c(this,ie)&&"added"||c(this,ie)===null&&this.guessedText&&"review"||"missing"},zd=async function(){var i,n,r;const t=c(this,Os);if(!t)return;if(c(this,si)){if(t.classList.toggle("done",!!c(this,ie)),t.setAttribute("data-l10n-id",c(De,En)[c(this,Ds,Bl)]),(i=c(this,$o))==null||i.setAttribute("data-l10n-id",c(De,En)[`${c(this,Ds,Bl)}-label`]),!c(this,ie)){(n=c(this,ti))==null||n.remove();return}}else{if(!c(this,ie)&&!c(this,Zs)){t.classList.remove("done"),(r=c(this,ti))==null||r.remove();return}t.classList.add("done"),t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-edit-button")}let e=c(this,ti);if(!e){b(this,ti,e=document.createElement("span")),e.className="tooltip",e.setAttribute("role","tooltip"),e.id=`alt-text-tooltip-${c(this,He).id}`;const o=100,h=c(this,He)._uiManager._signal;h.addEventListener("abort",()=>{clearTimeout(c(this,Ke)),b(this,Ke,null)},{once:!0}),t.addEventListener("mouseenter",()=>{b(this,Ke,setTimeout(()=>{b(this,Ke,null),c(this,ti).classList.add("show"),c(this,He)._reportTelemetry({action:"alt_text_tooltip"})},o))},{signal:h}),t.addEventListener("mouseleave",()=>{var l;c(this,Ke)&&(clearTimeout(c(this,Ke)),b(this,Ke,null)),(l=c(this,ti))==null||l.classList.remove("show")},{signal:h})}c(this,Zs)?e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-decorative-tooltip"):(e.removeAttribute("data-l10n-id"),e.textContent=c(this,ie)),e.parentNode||t.append(e);const s=c(this,He).getImageForAltText();s==null||s.setAttribute("aria-describedby",e.id)},w(De,En,null),q(De,"_l10n",null);let ld=De;const ct=class ct{constructor(t){w(this,et);w(this,Cr,null);w(this,Ps,null);w(this,Tt,null);w(this,Qo,!1);w(this,Ar,!1);w(this,oe,null);w(this,Tr,null);w(this,kn,null);w(this,jh,"");w(this,Er,!1);w(this,Mn,null);w(this,Nh,!1);w(this,kr,!1);w(this,Ii,!1);w(this,ii,null);w(this,Jo,0);w(this,Zo,0);w(this,ds,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);w(this,Bh,!1);w(this,Ad,ct._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=ct.prototype._resizeWithKeyboard,e=dr.TRANSLATE_SMALL,s=dr.TRANSLATE_BIG;return ot(this,"_resizerKeyboardManager",new fh([[["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"],ct.prototype._stopResizingWithKeyboard]]))}get editorType(){return Object.getPrototypeOf(this).constructor._type}static get _defaultLineColor(){return ot(this,"_defaultLineColor",this._colorManager.getHexCode("CanvasText"))}static deleteAnnotationElement(t){const e=new qw({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(ct._l10n??(ct._l10n=t),ct._l10nResizer||(ct._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"})),ct._borderLineWidth!==-1)return;const s=getComputedStyle(document.documentElement);ct._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 c(this,Bh)}set _isDraggable(t){var e;b(this,Bh,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=c(this,Ad)}setParent(t){t!==null?(this.pageIndex=t.pageIndex,this.pageDimensions=t.pageDimensions):y(this,et,Hl).call(this),this.parent=t}focusin(t){this._focusEventsAllowed&&(c(this,Er)?b(this,Er,!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){y(this,et,df).call(this,this.parentDimensions,t,e)}translateInPage(t,e){c(this,Mn)||b(this,Mn,[this.x,this.y]),y(this,et,df).call(this,this.pageDimensions,t,e),this.div.scrollIntoView({block:"nearest"})}drag(t,e){c(this,Mn)||b(this,Mn,[this.x,this.y]);const[s,i]=this.parentDimensions;if(this.x+=t/s,this.y+=e/i,this.parent&&(this.x<0||this.x>1||this.y<0||this.y>1)){const{x:l,y:d}=this.div.getBoundingClientRect();this.parent.findNewParent(this,l,d)&&(this.x-=Math.floor(this.x),this.y-=Math.floor(this.y))}let{x:n,y:r}=this;const[o,h]=this.getBaseTranslation();n+=o,r+=h,this.div.style.left=`${(100*n).toFixed(2)}%`,this.div.style.top=`${(100*r).toFixed(2)}%`,this.div.scrollIntoView({block:"nearest"})}get _hasBeenMoved(){return!!c(this,Mn)&&(c(this,Mn)[0]!==this.x||c(this,Mn)[1]!==this.y)}getBaseTranslation(){const[t,e]=this.parentDimensions,{_borderLineWidth:s}=ct,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[e,s]=this.pageDimensions;let{x:i,y:n,width:r,height:o}=this;if(r*=e,o*=s,i*=e,n*=s,this._mustFixPosition)switch(t){case 0:i=Math.max(0,Math.min(e-r,i)),n=Math.max(0,Math.min(s-o,n));break;case 90:i=Math.max(0,Math.min(e-o,i)),n=Math.min(s,Math.max(r,n));break;case 180:i=Math.min(e,Math.max(r,i)),n=Math.min(s,Math.max(o,n));break;case 270:i=Math.min(e,Math.max(o,i)),n=Math.max(0,Math.min(s-r,n));break}this.x=i/=e,this.y=n/=s;const[h,l]=this.getBaseTranslation();i+=h,n+=l;const{style:d}=this.div;d.left=`${(100*i).toFixed(2)}%`,d.top=`${(100*n).toFixed(2)}%`,this.moveInDOM()}screenToPageTranslation(t,e){var s;return y(s=ct,Hh,uf).call(s,t,e,this.parentRotation)}pageTranslationToScreen(t,e){var s;return y(s=ct,Hh,uf).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;this.div.style.width=`${(100*t/s).toFixed(2)}%`,c(this,Ar)||(this.div.style.height=`${(100*e/i).toFixed(2)}%`)}fixDims(){const{style:t}=this.div,{height:e,width:s}=t,i=s.endsWith("%"),n=!c(this,Ar)&&e.endsWith("%");if(i&&n)return;const[r,o]=this.parentDimensions;i||(t.width=`${(100*parseFloat(s)/r).toFixed(2)}%`),!c(this,Ar)&&!n&&(t.height=`${(100*parseFloat(e)/o).toFixed(2)}%`)}getInitialTranslation(){return[0,0]}altTextFinish(){var t;(t=c(this,Tt))==null||t.finish()}async addEditToolbar(){return this._editToolbar||c(this,kr)?this._editToolbar:(this._editToolbar=new Tg(this),this.div.append(this._editToolbar.render()),c(this,Tt)&&await this._editToolbar.addAltText(c(this,Tt)),this._editToolbar)}removeEditToolbar(){var t;this._editToolbar&&(this._editToolbar.remove(),this._editToolbar=null,(t=c(this,Tt))==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(){c(this,Tt)||(ld.initialize(ct._l10n),b(this,Tt,new ld(this)),c(this,Cr)&&(c(this,Tt).data=c(this,Cr),b(this,Cr,null)),await this.addEditToolbar())}get altTextData(){var t;return(t=c(this,Tt))==null?void 0:t.data}set altTextData(t){c(this,Tt)&&(c(this,Tt).data=t)}get guessedAltText(){var t;return(t=c(this,Tt))==null?void 0:t.guessedText}async setGuessedAltText(t){var e;await((e=c(this,Tt))==null?void 0:e.setGuessedText(t))}serializeAltText(t){var e;return(e=c(this,Tt))==null?void 0:e.serialize(t)}hasAltText(){return!!c(this,Tt)&&!c(this,Tt).isEmpty()}hasAltTextData(){var t;return((t=c(this,Tt))==null?void 0:t.hasData())??!1}render(){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=c(this,Qo)?-1:0,this._isVisible||this.div.classList.add("hidden"),this.setInForeground(),y(this,et,bf).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),hd(this,this.div,["pointerdown"]),this.div}pointerdown(t){const{isMac:e}=ke.platform;if(t.button!==0||t.ctrlKey&&e){t.preventDefault();return}if(b(this,Er,!0),this._isDraggable){y(this,et,Cb).call(this,t);return}y(this,et,mf).call(this,t)}get isSelected(){return this._uiManager.isSelected(this)}moveInDOM(){c(this,ii)&&clearTimeout(c(this,ii)),b(this,ii,setTimeout(()=>{var t;b(this,ii,null),(t=this.parent)==null||t.moveEditorInDOM(this)},0))}_setParentAndPosition(t,e,s){t.changeParent(this),this.x=e,this.y=s,this.fixAndSetPosition()}getRect(t,e,s=this.rotation){const i=this.parentScale,[n,r]=this.pageDimensions,[o,h]=this.pageTranslation,l=t/i,d=e/i,u=this.x*n,g=this.y*r,f=this.width*n,p=this.height*r;switch(s){case 0:return[u+l+o,r-g-d-p+h,u+l+f+o,r-g-d+h];case 90:return[u+d+o,r-g+l+h,u+d+p+o,r-g+l+f+h];case 180:return[u-l-f+o,r-g+d+h,u-l+o,r-g+d+p+h];case 270:return[u-d-p+o,r-g-l-f+h,u-d+o,r-g-l+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(){}isEmpty(){return!1}enableEditMode(){b(this,kr,!0)}disableEditMode(){b(this,kr,!1)}isInEditMode(){return c(this,kr)}shouldGetKeyboardEvents(){return c(this,Ii)}needsToBeRebuilt(){return this.div&&!this.isAttachedToDOM}rebuild(){y(this,et,bf).call(this)}rotate(t){}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,b(i,Cr,t.accessibilityData);const[n,r]=i.pageDimensions,[o,h,l,d]=i.getRectInCurrentCoords(t.rect,r);return i.x=o/n,i.y=h/r,i.width=l/n,i.height=d/r,i}get hasBeenModified(){return!!this.annotationElementId&&(this.deleted||this.serialize()!==null)}remove(){var t;if((t=c(this,kn))==null||t.abort(),b(this,kn,null),this.isEmpty()||this.commit(),this.parent?this.parent.remove(this):this._uiManager.removeEditor(this),c(this,ii)&&(clearTimeout(c(this,ii)),b(this,ii,null)),y(this,et,Hl).call(this),this.removeEditToolbar(),c(this,ds)){for(const e of c(this,ds).values())clearTimeout(e);b(this,ds,null)}this.parent=null}get isResizable(){return!1}makeResizable(){this.isResizable&&(y(this,et,xb).call(this),c(this,oe).classList.remove("hidden"),hd(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),b(this,Tr,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height});const e=c(this,oe).children;if(!c(this,Ps)){b(this,Ps,Array.from(e));const r=y(this,et,Ab).bind(this),o=y(this,et,Tb).bind(this),h=this._uiManager._signal;for(const l of c(this,Ps)){const d=l.getAttribute("data-resizer-name");l.setAttribute("role","spinbutton"),l.addEventListener("keydown",r,{signal:h}),l.addEventListener("blur",o,{signal:h}),l.addEventListener("focus",y(this,et,Eb).bind(this,d),{signal:h}),l.setAttribute("data-l10n-id",ct._l10nResizer[d])}}const s=c(this,Ps)[0];let i=0;for(const r of e){if(r===s)break;i++}const n=(360-this.rotation+this.parentRotation)%360/90*(c(this,Ps).length/4);if(n!==i){if(n<i)for(let o=0;o<i-n;o++)c(this,oe).append(c(this,oe).firstChild);else if(n>i)for(let o=0;o<n-i;o++)c(this,oe).firstChild.before(c(this,oe).lastChild);let r=0;for(const o of e){const l=c(this,Ps)[r++].getAttribute("data-resizer-name");o.setAttribute("data-l10n-id",ct._l10nResizer[l])}}y(this,et,vf).call(this,0),b(this,Ii,!0),c(this,oe).firstChild.focus({focusVisible:!0}),t.preventDefault(),t.stopImmediatePropagation()}_resizeWithKeyboard(t,e){c(this,Ii)&&y(this,et,pf).call(this,c(this,jh),{movementX:t,movementY:e})}_stopResizingWithKeyboard(){y(this,et,Hl).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=c(this,Tt))==null||s.toggleAltTextBadge(!1)}unselect(){var t,e,s,i,n;(t=c(this,oe))==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=c(this,Tt))==null||n.toggleAltTextBadge(!0)}updateParams(t,e){}disableEditing(){}enableEditing(){}enterInEditMode(){}getImageForAltText(){return null}get contentDiv(){return this.div}get isEditing(){return c(this,Nh)}set isEditing(t){b(this,Nh,t),this.parent&&(t?(this.parent.setSelected(this),this.parent.setActiveEditor(this)):this.parent.setActiveEditor(null))}setAspectRatio(t,e){b(this,Ar,!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){c(this,ds)||b(this,ds,new Map);const{action:s}=t;let i=c(this,ds).get(s);i&&clearTimeout(i),i=setTimeout(()=>{this._reportTelemetry(t),c(this,ds).delete(s),c(this,ds).size===0&&b(this,ds,null)},ct._telemetryTimeout),c(this,ds).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),b(this,Qo,!1)}disable(){this.div&&(this.div.tabIndex=-1),b(this,Qo,!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()}};Cr=new WeakMap,Ps=new WeakMap,Tt=new WeakMap,Qo=new WeakMap,Ar=new WeakMap,oe=new WeakMap,Tr=new WeakMap,kn=new WeakMap,jh=new WeakMap,Er=new WeakMap,Mn=new WeakMap,Nh=new WeakMap,kr=new WeakMap,Ii=new WeakMap,ii=new WeakMap,Jo=new WeakMap,Zo=new WeakMap,ds=new WeakMap,Bh=new WeakMap,Ad=new WeakMap,et=new WeakSet,df=function([t,e],s,i){[s,i]=this.screenToPageTranslation(s,i),this.x+=s/t,this.y+=i/e,this.fixAndSetPosition()},Hh=new WeakSet,uf=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]}},gf=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]}},xb=function(){if(c(this,oe))return;b(this,oe,document.createElement("div")),c(this,oe).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");c(this,oe).append(i),i.classList.add("resizer",s),i.setAttribute("data-resizer-name",s),i.addEventListener("pointerdown",y(this,et,Sb).bind(this,s),{signal:e}),i.addEventListener("contextmenu",hs,{signal:e}),i.tabIndex=-1}this.div.prepend(c(this,oe))},Sb=function(t,e){var p;e.preventDefault();const{isMac:s}=ke.platform;if(e.button!==0||e.ctrlKey&&s)return;(p=c(this,Tt))==null||p.toggle(!1);const i=this._isDraggable;this._isDraggable=!1;const n=new AbortController,r=this._uiManager.combinedSignal(n);this.parent.togglePointerEvents(!1),window.addEventListener("pointermove",y(this,et,pf).bind(this,t),{passive:!0,capture:!0,signal:r}),window.addEventListener("contextmenu",hs,{signal:r});const o=this.x,h=this.y,l=this.width,d=this.height,u=this.parent.div.style.cursor,g=this.div.style.cursor;this.div.style.cursor=this.parent.div.style.cursor=window.getComputedStyle(e.target).cursor;const f=()=>{var m;n.abort(),this.parent.togglePointerEvents(!0),(m=c(this,Tt))==null||m.toggle(!0),this._isDraggable=i,this.parent.div.style.cursor=u,this.div.style.cursor=g,y(this,et,ff).call(this,o,h,l,d)};window.addEventListener("pointerup",f,{signal:r}),window.addEventListener("blur",f,{signal:r})},ff=function(t,e,s,i){const n=this.x,r=this.y,o=this.width,h=this.height;n===t&&r===e&&o===s&&h===i||this.addCommands({cmd:()=>{this.width=o,this.height=h,this.x=n,this.y=r;const[l,d]=this.parentDimensions;this.setDims(l*o,d*h),this.fixAndSetPosition()},undo:()=>{this.width=s,this.height=i,this.x=t,this.y=e;const[l,d]=this.parentDimensions;this.setDims(l*s,d*i),this.fixAndSetPosition()},mustExec:!0})},pf=function(t,e){const[s,i]=this.parentDimensions,n=this.x,r=this.y,o=this.width,h=this.height,l=ct.MIN_SIZE/s,d=ct.MIN_SIZE/i,u=V=>Math.round(V*1e4)/1e4,g=y(this,et,gf).call(this,this.rotation),f=(V,H)=>[g[0]*V+g[2]*H,g[1]*V+g[3]*H],p=y(this,et,gf).call(this,360-this.rotation),m=(V,H)=>[p[0]*V+p[2]*H,p[1]*V+p[3]*H];let _,v,x=!1,S=!1;switch(t){case"topLeft":x=!0,_=(V,H)=>[0,0],v=(V,H)=>[V,H];break;case"topMiddle":_=(V,H)=>[V/2,0],v=(V,H)=>[V/2,H];break;case"topRight":x=!0,_=(V,H)=>[V,0],v=(V,H)=>[0,H];break;case"middleRight":S=!0,_=(V,H)=>[V,H/2],v=(V,H)=>[0,H/2];break;case"bottomRight":x=!0,_=(V,H)=>[V,H],v=(V,H)=>[0,0];break;case"bottomMiddle":_=(V,H)=>[V/2,H],v=(V,H)=>[V/2,0];break;case"bottomLeft":x=!0,_=(V,H)=>[0,H],v=(V,H)=>[V,0];break;case"middleLeft":S=!0,_=(V,H)=>[0,H/2],v=(V,H)=>[V,H/2];break}const C=_(o,h),E=v(o,h);let M=f(...E);const k=u(n+M[0]),O=u(r+M[1]);let P=1,L=1,[F,W]=this.screenToPageTranslation(e.movementX,e.movementY);if([F,W]=m(F/s,W/i),x){const V=Math.hypot(o,h);P=L=Math.max(Math.min(Math.hypot(E[0]-C[0]-F,E[1]-C[1]-W)/V,1/o,1/h),l/o,d/h)}else S?P=Math.max(l,Math.min(1,Math.abs(E[0]-C[0]-F)))/o:L=Math.max(d,Math.min(1,Math.abs(E[1]-C[1]-W)))/h;const B=u(o*P),z=u(h*L);M=f(...v(B,z));const K=k-M[0],tt=O-M[1];this.width=B,this.height=z,this.x=K,this.y=tt,this.setDims(s*B,i*z),this.fixAndSetPosition()},mf=function(t){const{isMac:e}=ke.platform;t.ctrlKey&&!e||t.shiftKey||t.metaKey&&e?this.parent.toggleSelected(this):this.parent.setSelected(this)},Cb=function(t){const{isSelected:e}=this;this._uiManager.setUpDragSession();const s=new AbortController,i=this._uiManager.combinedSignal(s);if(e){this.div.classList.add("moving"),b(this,Jo,t.clientX),b(this,Zo,t.clientY);const r=o=>{const{clientX:h,clientY:l}=o,[d,u]=this.screenToPageTranslation(h-c(this,Jo),l-c(this,Zo));b(this,Jo,h),b(this,Zo,l),this._uiManager.dragSelectedEditors(d,u)};window.addEventListener("pointermove",r,{passive:!0,capture:!0,signal:i})}const n=()=>{s.abort(),e&&this.div.classList.remove("moving"),b(this,Er,!1),this._uiManager.endDragSession()||y(this,et,mf).call(this,t)};window.addEventListener("pointerup",n,{signal:i}),window.addEventListener("blur",n,{signal:i})},bf=function(){if(c(this,kn)||!this.div)return;b(this,kn,new AbortController);const t=this._uiManager.combinedSignal(c(this,kn));this.div.addEventListener("focusin",this.focusin.bind(this),{signal:t}),this.div.addEventListener("focusout",this.focusout.bind(this),{signal:t})},Ab=function(t){ct._resizerKeyboardManager.exec(this,t)},Tb=function(t){var e;c(this,Ii)&&((e=t.relatedTarget)==null?void 0:e.parentNode)!==c(this,oe)&&y(this,et,Hl).call(this)},Eb=function(t){b(this,jh,c(this,Ii)?t:"")},vf=function(t){if(c(this,Ps))for(const e of c(this,Ps))e.tabIndex=t},Hl=function(){if(b(this,Ii,!1),y(this,et,vf).call(this,-1),c(this,Tr)){const{savedX:t,savedY:e,savedWidth:s,savedHeight:i}=c(this,Tr);y(this,et,ff).call(this,t,e,s,i),b(this,Tr,null)}},w(ct,Hh),q(ct,"_l10n",null),q(ct,"_l10nResizer",null),q(ct,"_borderLineWidth",-1),q(ct,"_colorManager",new kg),q(ct,"_zIndex",1),q(ct,"_telemetryTimeout",1e3);let gt=ct;class qw extends gt{constructor(t){super(t),this.annotationElementId=t.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}}const g0=3285377520,ls=4294901760,qs=65535;class f0{constructor(t){this.h1=t?t&4294967295:g0,this.h2=t?t&4294967295:g0}update(t){let e,s;if(typeof t=="string"){e=new Uint8Array(t.length*2),s=0;for(let m=0,_=t.length;m<_;m++){const v=t.charCodeAt(m);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,l=this.h1,d=this.h2;const u=3432918353,g=461845907,f=u&qs,p=g&qs;for(let m=0;m<i;m++)m&1?(o=r[m],o=o*u&ls|o*f&qs,o=o<<15|o>>>17,o=o*g&ls|o*p&qs,l^=o,l=l<<13|l>>>19,l=l*5+3864292196):(h=r[m],h=h*u&ls|h*f&qs,h=h<<15|h>>>17,h=h*g&ls|h*p&qs,d^=h,d=d<<13|d>>>19,d=d*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*u&ls|o*f&qs,o=o<<15|o>>>17,o=o*g&ls|o*p&qs,i&1?l^=o:d^=o}this.h1=l,this.h2=d}hexdigest(){let t=this.h1,e=this.h2;return t^=e>>>1,t=t*3981806797&ls|t*36045&qs,e=e*4283543511&ls|((e<<16|t>>>16)*2950163797&ls)>>>16,t^=e>>>1,t=t*444984403&ls|t*60499&qs,e=e*3301882366&ls|((e<<16|t>>>16)*3120437893&ls)>>>16,t^=e>>>1,(t>>>0).toString(16).padStart(8,"0")+(e>>>0).toString(16).padStart(8,"0")}}const Mg=Object.freeze({map:null,hash:"",transfer:void 0});class Og{constructor(){w(this,Td);w(this,Mr,!1);w(this,Or,null);w(this,ne,new Map);this.onSetModified=null,this.onResetModified=null,this.onAnnotationEditor=null}getValue(t,e){const s=c(this,ne).get(t);return s===void 0?e:Object.assign(e,s)}getRawValue(t){return c(this,ne).get(t)}remove(t){if(c(this,ne).delete(t),c(this,ne).size===0&&this.resetModified(),typeof this.onAnnotationEditor=="function"){for(const e of c(this,ne).values())if(e instanceof gt)return;this.onAnnotationEditor(null)}}setValue(t,e){const s=c(this,ne).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,c(this,ne).set(t,e);i&&y(this,Td,kb).call(this),e instanceof gt&&typeof this.onAnnotationEditor=="function"&&this.onAnnotationEditor(e.constructor._type)}has(t){return c(this,ne).has(t)}getAll(){return c(this,ne).size>0?bg(c(this,ne)):null}setAll(t){for(const[e,s]of Object.entries(t))this.setValue(e,s)}get size(){return c(this,ne).size}resetModified(){c(this,Mr)&&(b(this,Mr,!1),typeof this.onResetModified=="function"&&this.onResetModified())}get print(){return new p0(this)}get serializable(){if(c(this,ne).size===0)return Mg;const t=new Map,e=new f0,s=[],i=Object.create(null);let n=!1;for(const[r,o]of c(this,ne)){const h=o instanceof gt?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}:Mg}get editorStats(){let t=null;const e=new Map;for(const s of c(this,ne).values()){if(!(s instanceof gt))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 l=r.get(o);l||(l=new Map,r.set(o,l));const d=l.get(h)??0;l.set(h,d+1)}}for(const[s,i]of e)t[s]=i.computeTelemetryFinalData(t[s]);return t}resetModifiedIds(){b(this,Or,null)}get modifiedIds(){if(c(this,Or))return c(this,Or);const t=[];for(const e of c(this,ne).values())!(e instanceof gt)||!e.annotationElementId||!e.serialize()||t.push(e.annotationElementId);return b(this,Or,{ids:new Set(t),hash:t.join(",")})}}Mr=new WeakMap,Or=new WeakMap,ne=new WeakMap,Td=new WeakSet,kb=function(){c(this,Mr)||(b(this,Mr,!0),typeof this.onSetModified=="function"&&this.onSetModified())};class p0 extends Og{constructor(e){super();w(this,Wh);const{map:s,hash:i,transfer:n}=e.serializable,r=structuredClone(s,n?{transfer:n}:null);b(this,Wh,{map:r,hash:i,transfer:n})}get print(){yt("Should not call PrintAnnotationStorage.print")}get serializable(){return c(this,Wh)}get modifiedIds(){return ot(this,"modifiedIds",{ids:new Set,hash:""})}}Wh=new WeakMap;class $w{constructor({ownerDocument:t=globalThis.document,styleElement:e=null}){w(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(),c(this,ta).clear(),this.styleElement&&(this.styleElement.remove(),this.styleElement=null)}async loadSystemFont({systemFontInfo:t,_inspectFont:e}){if(!(!t||c(this,ta).has(t.loadedName))){if(Ut(!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(),c(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}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 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 ot(this,"isFontLoadingAPISupported",t)}get isSyncFontLoadingSupported(){let t=!1;return(pe||typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.userAgent)=="string"&&/Mozilla\/5.0.*?rv:\d+.*? Gecko/.test(navigator.userAgent))&&(t=!0),ot(this,"isSyncFontLoadingSupported",t)}_queueLoadingCallback(t){function e(){for(Ut(!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 ot(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,M,k){const O=C.substring(0,E),P=C.substring(E+M);return O+k+P}let n,r;const o=this._document.createElement("canvas");o.width=1,o.height=1;const h=o.getContext("2d");let l=0;function d(C,E){if(++l>30){st("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(d.bind(null,C,E))}const u=`lt${Date.now()}${this.loadTestFontId++}`;let g=this._loadTestFont;g=i(g,976,u.length,u);const p=16,m=1482184792;let _=s(g,p);for(n=0,r=u.length-3;n<r;n+=4)_=_-m+s(u,n)|0;n<u.length&&(_=_-m+s(u+"XXX",n)|0),g=i(g,p,4,Lw(_));const v=`url(data:font/opentype;base64,${btoa(g)});`,x=`@font-face {font-family:"${u}";src:${v}}`;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,u]){const E=this._document.createElement("span");E.textContent="Hi",E.style.fontFamily=C,S.append(E)}this._document.body.append(S),d(u,()=>{S.remove(),e.complete()})}}ta=new WeakMap;class Kw{constructor(t,{disableFontFace:e=!1,inspectFont:s=null}){this.compiledGlyphs=Object.create(null);for(const i in t)this[i]=t[i];this.disableFontFace=e===!0,this._inspectFont=s}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,${Bw(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];let s;try{s=t.get(this.loadedName+"_path_"+e)}catch(n){st(`getPathGenerator - ignoring character: "${n}".`)}if(!Array.isArray(s)||s.length===0)return this.compiledGlyphs[e]=function(n,r){};const i=[];for(let n=0,r=s.length;n<r;)switch(s[n++]){case Ai.BEZIER_CURVE_TO:{const[o,h,l,d,u,g]=s.slice(n,n+6);i.push(f=>f.bezierCurveTo(o,h,l,d,u,g)),n+=6}break;case Ai.MOVE_TO:{const[o,h]=s.slice(n,n+2);i.push(l=>l.moveTo(o,h)),n+=2}break;case Ai.LINE_TO:{const[o,h]=s.slice(n,n+2);i.push(l=>l.lineTo(o,h)),n+=2}break;case Ai.QUADRATIC_CURVE_TO:{const[o,h,l,d]=s.slice(n,n+4);i.push(u=>u.quadraticCurveTo(o,h,l,d)),n+=4}break;case Ai.RESTORE:i.push(o=>o.restore());break;case Ai.SAVE:i.push(o=>o.save());break;case Ai.SCALE:Ut(i.length===2,"Scale command is only valid at the third position.");break;case Ai.TRANSFORM:{const[o,h,l,d,u,g]=s.slice(n,n+6);i.push(f=>f.transform(o,h,l,d,u,g)),n+=6}break;case Ai.TRANSLATE:{const[o,h]=s.slice(n,n+2);i.push(l=>l.translate(o,h)),n+=2}break}return this.compiledGlyphs[e]=function(r,o){i[0](r),i[1](r),r.scale(o,-o);for(let h=2,l=i.length;h<l;h++)i[h](r)}}}class m0{constructor({enableHWA:t=!1}){w(this,Xh,!1);b(this,Xh,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:!c(this,Xh)})}}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.")}}Xh=new WeakMap;class Qw extends m0{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 b0{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 v0 extends b0{async _fetch(t){const e=await od(t,this.isCompressed?"arraybuffer":"text");return e instanceof ArrayBuffer?new Uint8Array(e):rd(e)}}class y0{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 Jw extends y0{constructor({docId:e,ownerDocument:s=globalThis.document}){super();w(this,j);w(this,Dr);w(this,Pr);w(this,ni);w(this,ji);w(this,ve);w(this,Ed);w(this,Lr,0);b(this,ji,e),b(this,ve,s)}addFilter(e){if(!e)return"none";let s=c(this,j,we).get(e);if(s)return s;const[i,n,r]=y(this,j,Vd).call(this,e),o=e.length===1?i:`${i}${n}${r}`;if(s=c(this,j,we).get(o),s)return c(this,j,we).set(e,s),s;const h=`g_${c(this,ji)}_transfer_map_${Fe(this,Lr)._++}`,l=y(this,j,Wa).call(this,h);c(this,j,we).set(e,l),c(this,j,we).set(o,l);const d=y(this,j,Xa).call(this,h);return y(this,j,Xl).call(this,i,n,r,d),l}addHCMFilter(e,s){var p;const i=`${e}-${s}`,n="base";let r=c(this,j,Ba).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},c(this,j,Ba).set(n,r)),!e||!s))return r.url;const o=y(this,j,zl).call(this,e);e=X.makeHexColor(...o);const h=y(this,j,zl).call(this,s);if(s=X.makeHexColor(...h),c(this,j,Ha).style.color="",e==="#000000"&&s==="#ffffff"||e===s)return r.url;const l=new Array(256);for(let m=0;m<=255;m++){const _=m/255;l[m]=_<=.03928?_/12.92:((_+.055)/1.055)**2.4}const d=l.join(","),u=`g_${c(this,ji)}_hcm_filter`,g=r.filter=y(this,j,Xa).call(this,u);y(this,j,Xl).call(this,d,d,d,g),y(this,j,yf).call(this,g);const f=(m,_)=>{const v=o[m]/255,x=h[m]/255,S=new Array(_+1);for(let C=0;C<=_;C++)S[C]=v+C/_*(x-v);return S.join(",")};return y(this,j,Xl).call(this,f(0,5),f(1,5),f(2,5),g),r.url=y(this,j,Wa).call(this,u),r.url}addAlphaFilter(e){let s=c(this,j,we).get(e);if(s)return s;const[i]=y(this,j,Vd).call(this,[e]),n=`alpha_${i}`;if(s=c(this,j,we).get(n),s)return c(this,j,we).set(e,s),s;const r=`g_${c(this,ji)}_alpha_map_${Fe(this,Lr)._++}`,o=y(this,j,Wa).call(this,r);c(this,j,we).set(e,o),c(this,j,we).set(n,o);const h=y(this,j,Xa).call(this,r);return y(this,j,_f).call(this,i,h),o}addLuminosityFilter(e){let s=c(this,j,we).get(e||"luminosity");if(s)return s;let i,n;if(e?([i]=y(this,j,Vd).call(this,[e]),n=`luminosity_${i}`):n="luminosity",s=c(this,j,we).get(n),s)return c(this,j,we).set(e,s),s;const r=`g_${c(this,ji)}_luminosity_map_${Fe(this,Lr)._++}`,o=y(this,j,Wa).call(this,r);c(this,j,we).set(e,o),c(this,j,we).set(n,o);const h=y(this,j,Xa).call(this,r);return y(this,j,Mb).call(this,h),e&&y(this,j,_f).call(this,i,h),o}addHighlightHCMFilter(e,s,i,n,r){var x;const o=`${s}-${i}-${n}-${r}`;let h=c(this,j,Ba).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},c(this,j,Ba).set(e,h)),!s||!i))return h.url;const[l,d]=[s,i].map(y(this,j,zl).bind(this));let u=Math.round(.2126*l[0]+.7152*l[1]+.0722*l[2]),g=Math.round(.2126*d[0]+.7152*d[1]+.0722*d[2]),[f,p]=[n,r].map(y(this,j,zl).bind(this));g<u&&([u,g,f,p]=[g,u,p,f]),c(this,j,Ha).style.color="";const m=(S,C,E)=>{const M=new Array(256),k=(g-u)/E,O=S/255,P=(C-S)/(255*E);let L=0;for(let F=0;F<=E;F++){const W=Math.round(u+F*k),B=O+F*P;for(let z=L;z<=W;z++)M[z]=B;L=W+1}for(let F=L;F<256;F++)M[F]=M[L-1];return M.join(",")},_=`g_${c(this,ji)}_hcm_${e}_filter`,v=h.filter=y(this,j,Xa).call(this,_);return y(this,j,yf).call(this,v),y(this,j,Xl).call(this,m(f[0],p[0],5),m(f[1],p[1],5),m(f[2],p[2],5),v),h.url=y(this,j,Wa).call(this,_),h.url}destroy(e=!1){e&&c(this,j,Ba).size!==0||(c(this,ni)&&(c(this,ni).parentNode.parentNode.remove(),b(this,ni,null)),c(this,Pr)&&(c(this,Pr).clear(),b(this,Pr,null)),b(this,Lr,0))}}Dr=new WeakMap,Pr=new WeakMap,ni=new WeakMap,ji=new WeakMap,ve=new WeakMap,Ed=new WeakMap,Lr=new WeakMap,j=new WeakSet,we=function(){return c(this,Pr)||b(this,Pr,new Map)},Ba=function(){return c(this,Ed)||b(this,Ed,new Map)},Ha=function(){if(!c(this,ni)){const e=c(this,ve).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=c(this,ve).createElementNS(Ti,"svg");i.setAttribute("width",0),i.setAttribute("height",0),b(this,ni,c(this,ve).createElementNS(Ti,"defs")),e.append(i),i.append(c(this,ni)),c(this,ve).body.append(e)}return c(this,ni)},Vd=function(e){if(e.length===1){const l=e[0],d=new Array(256);for(let g=0;g<256;g++)d[g]=l[g]/255;const u=d.join(",");return[u,u,u]}const[s,i,n]=e,r=new Array(256),o=new Array(256),h=new Array(256);for(let l=0;l<256;l++)r[l]=s[l]/255,o[l]=i[l]/255,h[l]=n[l]/255;return[r.join(","),o.join(","),h.join(",")]},Wa=function(e){if(c(this,Dr)===void 0){b(this,Dr,"");const s=c(this,ve).URL;s!==c(this,ve).baseURI&&(ad(s)?st('#createUrl: ignore "data:"-URL for performance reasons.'):b(this,Dr,s.split("#",1)[0]))}return`url(${c(this,Dr)}#${e})`},Mb=function(e){const s=c(this,ve).createElementNS(Ti,"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)},yf=function(e){const s=c(this,ve).createElementNS(Ti,"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)},Xa=function(e){const s=c(this,ve).createElementNS(Ti,"filter");return s.setAttribute("color-interpolation-filters","sRGB"),s.setAttribute("id",e),c(this,j,Ha).append(s),s},Wl=function(e,s,i){const n=c(this,ve).createElementNS(Ti,s);n.setAttribute("type","discrete"),n.setAttribute("tableValues",i),e.append(n)},Xl=function(e,s,i,n){const r=c(this,ve).createElementNS(Ti,"feComponentTransfer");n.append(r),y(this,j,Wl).call(this,r,"feFuncR",e),y(this,j,Wl).call(this,r,"feFuncG",s),y(this,j,Wl).call(this,r,"feFuncB",i)},_f=function(e,s){const i=c(this,ve).createElementNS(Ti,"feComponentTransfer");s.append(i),y(this,j,Wl).call(this,i,"feFuncA",e)},zl=function(e){return c(this,j,Ha).style.color=e,Cg(getComputedStyle(c(this,j,Ha)).getPropertyValue("color"))};class _0{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 w0 extends _0{async _fetch(t){const e=await od(t,"arraybuffer");return new Uint8Array(e)}}if(pe){var Dg=Promise.withResolvers(),ph=null;(async()=>{const t=await Promise.resolve().then(()=>yd),e=await Promise.resolve().then(()=>yd),s=await Promise.resolve().then(()=>yd),i=await Promise.resolve().then(()=>yd);let n,r;return new Map(Object.entries({fs:t,http:e,https:s,url:i,canvas:n,path2d:r}))})().then(t=>{ph=t,Dg.resolve()},t=>{st(`loadPackages: ${t}`),ph=new Map,Dg.resolve()})}class bn{static get promise(){return Dg.promise}static get(t){return ph==null?void 0:ph.get(t)}}async function x0(a){const e=await bn.get("fs").promises.readFile(a);return new Uint8Array(e)}class Zw extends y0{}class tx extends m0{_createCanvas(t,e){return bn.get("canvas").createCanvas(t,e)}}class ex extends b0{async _fetch(t){return x0(t)}}class sx extends _0{async _fetch(t){return x0(t)}}const Me={FILL:"Fill",STROKE:"Stroke",SHADING:"Shading"};function Pg(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 Lg{getPattern(){yt("Abstract method `getPattern` called.")}}class ix extends Lg{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===Me.STROKE||i===Me.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,l=e.cachedCanvases.getCanvas("pattern",o,h),d=l.context;d.clearRect(0,0,d.canvas.width,d.canvas.height),d.beginPath(),d.rect(0,0,d.canvas.width,d.canvas.height),d.translate(-r[0],-r[1]),s=X.transform(s,[1,0,0,1,r[0],r[1]]),d.transform(...e.baseTransform),this.matrix&&d.transform(...this.matrix),Pg(d,this._bbox),d.fillStyle=this._createGradient(d),d.fill(),n=t.createPattern(l.canvas,"no-repeat");const u=new DOMMatrix(s);n.setTransform(u)}else Pg(t,this._bbox),n=this._createGradient(t);return n}}function Fg(a,t,e,s,i,n,r,o){const h=t.coords,l=t.colors,d=a.data,u=a.width*4;let g;h[e+1]>h[s+1]&&(g=e,e=s,s=g,g=n,n=r,r=g),h[s+1]>h[i+1]&&(g=s,s=i,i=g,g=r,r=o,o=g),h[e+1]>h[s+1]&&(g=e,e=s,s=g,g=n,n=r,r=g);const f=(h[e]+t.offsetX)*t.scaleX,p=(h[e+1]+t.offsetY)*t.scaleY,m=(h[s]+t.offsetX)*t.scaleX,_=(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 S=l[n],C=l[n+1],E=l[n+2],M=l[r],k=l[r+1],O=l[r+2],P=l[o],L=l[o+1],F=l[o+2],W=Math.round(p),B=Math.round(x);let z,K,tt,V,H,Jt,Zt,ce;for(let zt=W;zt<=B;zt++){if(zt<_){const dt=zt<p?0:(p-zt)/(p-_);z=f-(f-m)*dt,K=S-(S-M)*dt,tt=C-(C-k)*dt,V=E-(E-O)*dt}else{let dt;zt>x?dt=1:_===x?dt=0:dt=(_-zt)/(_-x),z=m-(m-v)*dt,K=M-(M-P)*dt,tt=k-(k-L)*dt,V=O-(O-F)*dt}let _t;zt<p?_t=0:zt>x?_t=1:_t=(p-zt)/(p-x),H=f-(f-v)*_t,Jt=S-(S-P)*_t,Zt=C-(C-L)*_t,ce=E-(E-F)*_t;const Le=Math.round(Math.min(z,H)),gi=Math.round(Math.max(z,H));let Pt=u*zt+Le*4;for(let dt=Le;dt<=gi;dt++)_t=(z-dt)/(z-H),_t<0?_t=0:_t>1&&(_t=1),d[Pt++]=K-(K-Jt)*_t|0,d[Pt++]=tt-(tt-Zt)*_t|0,d[Pt++]=V-(V-ce)*_t|0,d[Pt++]=255}}function nx(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,l=o-1;for(n=0;n<h;n++){let d=n*o;for(let u=0;u<l;u++,d++)Fg(a,e,s[d],s[d+1],s[d+o],i[d],i[d+1],i[d+o]),Fg(a,e,s[d+o+1],s[d+1],s[d+o],i[d+o+1],i[d+1],i[d+o])}break;case"triangles":for(n=0,r=s.length;n<r;n+=3)Fg(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 rx extends Lg{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]),l=Math.ceil(this._bounds[2])-o,d=Math.ceil(this._bounds[3])-h,u=Math.min(Math.ceil(Math.abs(l*t[0]*1.1)),3e3),g=Math.min(Math.ceil(Math.abs(d*t[1]*1.1)),3e3),f=l/u,p=d/g,m={coords:this._coords,colors:this._colors,offsetX:-o,offsetY:-h,scaleX:1/f,scaleY:1/p},_=u+2*2,v=g+2*2,x=s.getCanvas("mesh",_,v),S=x.context,C=S.createImageData(u,g);if(e){const M=C.data;for(let k=0,O=M.length;k<O;k+=4)M[k]=e[0],M[k+1]=e[1],M[k+2]=e[2],M[k+3]=255}for(const M of this._figures)nx(C,M,m);return S.putImageData(C,2,2),{canvas:x.canvas,offsetX:o-2*f,offsetY:h-2*p,scaleX:f,scaleY:p}}getPattern(t,e,s,i){Pg(t,this._bbox);let n;if(i===Me.SHADING)n=X.singularValueDecompose2dScale(At(t));else if(n=X.singularValueDecompose2dScale(e.baseTransform),this.matrix){const o=X.singularValueDecompose2dScale(this.matrix);n=[n[0]*o[0],n[1]*o[1]]}const r=this._createMeshCanvas(n,i===Me.SHADING?null:this._background,e.cachedCanvases);return i!==Me.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 ox extends Lg{getPattern(){return"hotpink"}}function ax(a){switch(a[0]){case"RadialAxial":return new ix(a);case"Mesh":return new rx(a);case"Dummy":return new ox}throw new Error(`Unknown IR type: ${a[0]}`)}const S0={COLORED:1,UNCOLORED:2},kd=class kd{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:l}=this;h=Math.abs(h),l=Math.abs(l),id("TilingType: "+n);const d=e[0],u=e[1],g=e[2],f=e[3],p=g-d,m=f-u,_=X.singularValueDecompose2dScale(this.matrix),v=X.singularValueDecompose2dScale(this.baseTransform),x=_[0]*v[0],S=_[1]*v[1];let C=p,E=m,M=!1,k=!1;const O=Math.ceil(h*x),P=Math.ceil(l*S),L=Math.ceil(p*x),F=Math.ceil(m*S);O>=L?C=h:M=!0,P>=F?E=l:k=!0;const W=this.getSizeAndScale(C,this.ctx.canvas.width,x),B=this.getSizeAndScale(E,this.ctx.canvas.height,S),z=t.cachedCanvases.getCanvas("pattern",W.size,B.size),K=z.context,tt=o.createCanvasGraphics(K);if(tt.groupLevel=t.groupLevel,this.setFillAndStrokeStyleToContext(tt,i,r),K.translate(-W.scale*d,-B.scale*u),tt.transform(W.scale,0,0,B.scale,0,0),K.save(),this.clipBbox(tt,d,u,g,f),tt.baseTransform=At(tt.ctx),tt.executeOperatorList(s),tt.endDrawing(),K.restore(),M||k){const V=z.canvas;M&&(C=h),k&&(E=l);const H=this.getSizeAndScale(C,this.ctx.canvas.width,x),Jt=this.getSizeAndScale(E,this.ctx.canvas.height,S),Zt=H.size,ce=Jt.size,zt=t.cachedCanvases.getCanvas("pattern-workaround",Zt,ce),_t=zt.context,Le=M?Math.floor(p/h):0,gi=k?Math.floor(m/l):0;for(let Pt=0;Pt<=Le;Pt++)for(let dt=0;dt<=gi;dt++)_t.drawImage(V,Zt*Pt,ce*dt,Zt,ce,0,0,Zt,ce);return{canvas:zt.canvas,scaleX:H.scale,scaleY:Jt.scale,offsetX:d,offsetY:u}}return{canvas:z.canvas,scaleX:W.scale,scaleY:B.scale,offsetX:d,offsetY:u}}getSizeAndScale(t,e,s){const i=Math.max(kd.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 S0.COLORED:const r=this.ctx;i.fillStyle=r.fillStyle,i.strokeStyle=r.strokeStyle,n.fillColor=r.fillStyle,n.strokeColor=r.strokeStyle;break;case S0.UNCOLORED:const o=X.makeHexColor(s[0],s[1],s[2]);i.fillStyle=o,i.strokeStyle=o,n.fillColor=o,n.strokeColor=o;break;default:throw new Pw(`Unsupported paint type: ${e}`)}}getPattern(t,e,s,i){let n=s;i!==Me.SHADING&&(n=X.transform(n,e.baseTransform),this.matrix&&(n=X.transform(n,this.matrix)));const r=this.createPatternCanvas(e);let o=new DOMMatrix(n);o=o.translate(r.offsetX,r.offsetY),o=o.scale(1/r.scaleX,1/r.scaleY);const h=t.createPattern(r.canvas,"repeat");return h.setTransform(o),h}};q(kd,"MAX_PATTERN_SIZE",3e3);let Rg=kd;function hx({src:a,srcPos:t=0,dest:e,width:s,height:i,nonBlackColor:n=4294967295,inverseDecode:r=!1}){const o=ke.isLittleEndian?4278190080:255,[h,l]=r?[n,o]:[o,n],d=s>>3,u=s&7,g=a.length;e=new Uint32Array(e.buffer);let f=0;for(let p=0;p<i;p++){for(const _=t+d;t<_;t++){const v=t<g?a[t]:255;e[f++]=v&128?l:h,e[f++]=v&64?l:h,e[f++]=v&32?l:h,e[f++]=v&16?l:h,e[f++]=v&8?l:h,e[f++]=v&4?l:h,e[f++]=v&2?l:h,e[f++]=v&1?l:h}if(u===0)continue;const m=t<g?a[t++]:255;for(let _=0;_<u;_++)e[f++]=m&1<<7-_?l:h}return{srcPos:t,destPos:f}}const C0=16,A0=100,lx=15,T0=10,E0=1e3,Ne=16;function cx(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 dx{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 cd(a,t,e,s,i,n,r,o,h,l){const[d,u,g,f,p,m]=At(a);if(u===0&&g===0){const x=r*d+p,S=Math.round(x),C=o*f+m,E=Math.round(C),M=(r+h)*d+p,k=Math.abs(Math.round(M)-S)||1,O=(o+l)*f+m,P=Math.abs(Math.round(O)-E)||1;return a.setTransform(Math.sign(d),0,0,Math.sign(f),S,E),a.drawImage(t,e,s,i,n,0,0,k,P),a.setTransform(d,u,g,f,p,m),[k,P]}if(d===0&&f===0){const x=o*g+p,S=Math.round(x),C=r*u+m,E=Math.round(C),M=(o+l)*g+p,k=Math.abs(Math.round(M)-S)||1,O=(r+h)*u+m,P=Math.abs(Math.round(O)-E)||1;return a.setTransform(0,Math.sign(u),Math.sign(g),0,S,E),a.drawImage(t,e,s,i,n,0,0,P,k),a.setTransform(d,u,g,f,p,m),[P,k]}a.drawImage(t,e,s,i,n,r,o,h,l);const _=Math.hypot(d,u),v=Math.hypot(g,f);return[_*h,v*l]}function ux(a){const{width:t,height:e}=a;if(t>E0||e>E0)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,l;const d=t+7&-8;let u=new Uint8Array(d*e),g=0;for(const v of a.data){let x=128;for(;x>0;)u[g++]=v&x?0:255,x>>=1}let f=0;for(g=0,u[g]!==0&&(r[0]=1,++f),h=1;h<t;h++)u[g]!==u[g+1]&&(r[h]=u[g]?2:1,++f),g++;for(u[g]!==0&&(r[h]=2,++f),o=1;o<e;o++){g=o*d,l=o*n,u[g-d]!==u[g]&&(r[l]=u[g]?1:8,++f);let v=(u[g]?4:0)+(u[g-d]?8:0);for(h=1;h<t;h++)v=(v>>2)+(u[g+1]?4:0)+(u[g-d+1]?8:0),i[v]&&(r[l+h]=i[v],++f),g++;if(u[g-d]!==u[g]&&(r[l+h]=u[g]?2:4,++f),f>s)return null}for(g=d*(e-1),l=o*n,u[g]!==0&&(r[l]=8,++f),h=1;h<t;h++)u[g]!==u[g+1]&&(r[l+h]=u[g]?4:8,++f),g++;if(u[g]!==0&&(r[l+h]=4,++f),f>s)return null;const p=new Int32Array([0,n,-1,0,-n,0,0,0,1]),m=new Path2D;for(o=0;f&&o<=e;o++){let v=o*n;const x=v+t;for(;v<x&&!r[v];)v++;if(v===x)continue;m.moveTo(v%n,o);const S=v;let C=r[v];do{const E=p[C];do v+=E;while(!r[v]);const M=r[v];M!==5&&M!==10?(C=M,r[v]=0):(C=M&51*C>>4,r[v]&=C>>2|C<<2),m.lineTo(v%n,v/n|0),r[v]||--f}while(S!==v);--o}return u=null,r=null,function(v){v.save(),v.scale(1/t,-1/e),v.translate(0,-e),v.fill(m),v.beginPath(),v.restore()}}class k0{constructor(t,e){this.alphaIsShape=!1,this.fontSize=0,this.fontSizeScale=1,this.textMatrix=a0,this.textMatrixScale=1,this.fontMatrix=gg,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=me.FILL,this.textRise=0,this.fillColor="#000000",this.strokeColor="#000000",this.patternFill=!1,this.fillAlpha=1,this.strokeAlpha=1,this.lineWidth=1,this.activeSMask=null,this.transferMaps="none",this.startNewPathAndClipBox([0,0,t,e])}clone(){const t=Object.create(this);return t.clipBox=this.clipBox.slice(),t}setCurrentPoint(t,e){this.x=t,this.y=e}updatePathMinMax(t,e,s){[e,s]=X.applyTransform([e,s],t),this.minX=Math.min(this.minX,e),this.minY=Math.min(this.minY,s),this.maxX=Math.max(this.maxX,e),this.maxY=Math.max(this.maxY,s)}updateRectMinMax(t,e){const s=X.applyTransform(e,t),i=X.applyTransform(e.slice(2),t),n=X.applyTransform([e[0],e[3]],t),r=X.applyTransform([e[2],e[1]],t);this.minX=Math.min(this.minX,s[0],i[0],n[0],r[0]),this.minY=Math.min(this.minY,s[1],i[1],n[1],r[1]),this.maxX=Math.max(this.maxX,s[0],i[0],n[0],r[0]),this.maxY=Math.max(this.maxY,s[1],i[1],n[1],r[1])}updateScalingPathMinMax(t,e){X.scaleMinMax(t,e),this.minX=Math.min(this.minX,e[0]),this.minY=Math.min(this.minY,e[1]),this.maxX=Math.max(this.maxX,e[2]),this.maxY=Math.max(this.maxY,e[3])}updateCurvePathMinMax(t,e,s,i,n,r,o,h,l,d){const u=X.bezierBoundingBox(e,s,i,n,r,o,h,l,d);d||this.updateRectMinMax(t,u)}getPathBoundingBox(t=Me.FILL,e=null){const s=[this.minX,this.minY,this.maxX,this.maxY];if(t===Me.STROKE){e||yt("Stroke bounding box must include transform.");const i=X.singularValueDecompose2dScale(e),n=i[0]*this.lineWidth/2,r=i[1]*this.lineWidth/2;s[0]-=n,s[1]-=r,s[2]+=n,s[3]+=r}return s}updateClipFromPath(){const t=X.intersect(this.clipBox,this.getPathBoundingBox());this.startNewPathAndClipBox(t||[0,0,0,0])}isEmptyClip(){return this.minX===1/0}startNewPathAndClipBox(t){this.clipBox=t,this.minX=1/0,this.minY=1/0,this.maxX=0,this.maxY=0}getClippedPathBoundingBox(t=Me.FILL,e=null){return X.intersect(this.clipBox,this.getPathBoundingBox(t,e))}}function M0(a,t){if(typeof ImageData<"u"&&t instanceof ImageData){a.putImageData(t,0,0);return}const e=t.height,s=t.width,i=e%Ne,n=(e-i)/Ne,r=i===0?n:n+1,o=a.createImageData(s,Ne);let h=0,l;const d=t.data,u=o.data;let g,f,p,m;if(t.kind===td.GRAYSCALE_1BPP){const _=d.byteLength,v=new Uint32Array(u.buffer,0,u.byteLength>>2),x=v.length,S=s+7>>3,C=4294967295,E=ke.isLittleEndian?4278190080:255;for(g=0;g<r;g++){for(p=g<n?Ne:i,l=0,f=0;f<p;f++){const M=_-h;let k=0;const O=M>S?s:M*8-7,P=O&-8;let L=0,F=0;for(;k<P;k+=8)F=d[h++],v[l++]=F&128?C:E,v[l++]=F&64?C:E,v[l++]=F&32?C:E,v[l++]=F&16?C:E,v[l++]=F&8?C:E,v[l++]=F&4?C:E,v[l++]=F&2?C:E,v[l++]=F&1?C:E;for(;k<O;k++)L===0&&(F=d[h++],L=128),v[l++]=F&L?C:E,L>>=1}for(;l<x;)v[l++]=0;a.putImageData(o,0,g*Ne)}}else if(t.kind===td.RGBA_32BPP){for(f=0,m=s*Ne*4,g=0;g<n;g++)u.set(d.subarray(h,h+m)),h+=m,a.putImageData(o,0,f),f+=Ne;g<r&&(m=s*i*4,u.set(d.subarray(h,h+m)),a.putImageData(o,0,f))}else if(t.kind===td.RGB_24BPP)for(p=Ne,m=s*p,g=0;g<r;g++){for(g>=n&&(p=i,m=s*p),l=0,f=m;f--;)u[l++]=d[h++],u[l++]=d[h++],u[l++]=d[h++],u[l++]=255;a.putImageData(o,0,g*Ne)}else throw new Error(`bad image kind: ${t.kind}`)}function O0(a,t){if(t.bitmap){a.drawImage(t.bitmap,0,0);return}const e=t.height,s=t.width,i=e%Ne,n=(e-i)/Ne,r=i===0?n:n+1,o=a.createImageData(s,Ne);let h=0;const l=t.data,d=o.data;for(let u=0;u<r;u++){const g=u<n?Ne:i;({srcPos:h}=hx({src:l,srcPos:h,dest:d,width:s,height:g,nonBlackColor:0})),a.putImageData(o,0,u*Ne)}}function mh(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 dd(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),!pe){const{filter:t}=a;t!=="none"&&t!==""&&(a.filter="none")}}function D0(a,t){if(t)return!0;const e=X.singularValueDecompose2dScale(a);e[0]=Math.fround(e[0]),e[1]=Math.fround(e[1]);const s=Math.fround((globalThis.devicePixelRatio||1)*mn.PDF_TO_CSS_UNITS);return e[0]<=s&&e[1]<=s}const gx=["butt","round","square"],fx=["miter","round","bevel"],px={},P0={},Zg=class Zg{constructor(t,e,s,i,n,{optionalContentConfig:r,markedContentStack:o=null},h,l){w(this,On);this.ctx=t,this.current=new k0(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 dx(this.canvasFactory),this.cachedPatterns=new Map,this.annotationCanvasMap=h,this.viewportScale=1,this.outputScaleX=1,this.outputScaleY=1,this.pageColors=l,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(),dd(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 l=h-o>T0&&typeof s=="function",d=l?Date.now()+lx:0;let u=0;const g=this.commonObjs,f=this.objs;let p;for(;;){if(i!==void 0&&o===i.nextBreakPoint)return i.breakIt(o,s),o;if(p=r[o],p!==Ts.dependency)this[p].apply(this,n[o]);else for(const m of n[o]){const _=m.startsWith("g_")?g:f;if(!_.has(m))return _.get(m,s),o}if(o++,o===h)return o;if(l&&++u>T0){if(Date.now()>d)return s(),o;u=0}}}endDrawing(){y(this,On,wf).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(),y(this,On,xf).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,l="prescale1",d,u;for(;n>2&&o>1||r>2&&h>1;){let g=o,f=h;n>2&&o>1&&(g=o>=16384?Math.floor(o/2)-1||1:Math.ceil(o/2),n/=o/g),r>2&&h>1&&(f=h>=16384?Math.floor(h/2)-1||1:Math.ceil(h)/2,r/=h/f),d=this.cachedCanvases.getCanvas(l,g,f),u=d.context,u.clearRect(0,0,g,f),u.drawImage(t,0,0,o,h,0,0,g,f),t=d.canvas,o=g,h=f,l=l==="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,l,d,u;if((t.bitmap||t.data)&&t.count>1){const O=t.bitmap||t.data.buffer;l=JSON.stringify(r?o:[o.slice(0,4),n]),h=this._cachedBitmapsMap.get(O),h||(h=new Map,this._cachedBitmapsMap.set(O,h));const P=h.get(l);if(P&&!r){const L=Math.round(Math.min(o[0],o[2])+o[4]),F=Math.round(Math.min(o[1],o[3])+o[5]);return{canvas:P,offsetX:L,offsetY:F}}d=P}d||(u=this.cachedCanvases.getCanvas("maskCanvas",s,i),O0(u.context,t));let g=X.transform(o,[1/s,0,0,-1/i,0,0]);g=X.transform(g,[1,0,0,1,0,-i]);const[f,p,m,_]=X.getAxialAlignedBoundingBox([0,0,s,i],g),v=Math.round(m-f)||1,x=Math.round(_-p)||1,S=this.cachedCanvases.getCanvas("fillCanvas",v,x),C=S.context,E=f,M=p;C.translate(-E,-M),C.transform(...g),d||(d=this._scaleImage(u.canvas,Ei(C)),d=d.img,h&&r&&h.set(l,d)),C.imageSmoothingEnabled=D0(At(C),t.interpolate),cd(C,d,0,0,d.width,d.height,0,0,s,i),C.globalCompositeOperation="source-in";const k=X.transform(Ei(C),[1,0,0,1,-E,-M]);return C.fillStyle=r?n.getPattern(e,this,k,Me.FILL):n,C.fillRect(0,0,s,i),h&&!r&&(this.cachedCanvases.delete("fillCanvas"),h.set(l,S.canvas)),{canvas:S.canvas,offsetX:Math.round(E),offsetY:Math.round(M)}}setLineWidth(t){t!==this.current.lineWidth&&(this._cachedScaleForStroking[0]=-1),this.current.lineWidth=t,this.ctx.lineWidth=t}setLineCap(t){this.ctx.lineCap=gx[t]}setLineJoin(t){this.ctx.lineJoin=fx[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)),mh(this.suspendedCtx,n),cx(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(),mh(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,l,d,u){let g=t.canvas,f=h-d,p=l-u;if(r){const _=X.makeHexColor(...r);if(f<0||p<0||f+s>g.width||p+i>g.height){const v=this.cachedCanvases.getCanvas("maskExtension",s,i),x=v.context;x.drawImage(g,-f,-p),x.globalCompositeOperation="destination-atop",x.fillStyle=_,x.fillRect(0,0,s,i),x.globalCompositeOperation="source-over",g=v.canvas,f=p=0}else{t.save(),t.globalAlpha=1,t.setTransform(1,0,0,1,0,0);const v=new Path2D;v.rect(f,p,s,i),t.clip(v),t.globalCompositeOperation="destination-atop",t.fillStyle=_,t.fillRect(f,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 m=new Path2D;m.rect(h,l,s,i),e.clip(m),e.globalCompositeOperation="destination-in",e.drawImage(g,f,p,s,i,h,l,s,i),e.restore()}save(){this.inSMaskMode?(mh(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(),mh(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,l;const d=At(i),u=d[0]===0&&d[3]===0||d[1]===0&&d[2]===0,g=u?s.slice(0):null;for(let f=0,p=0,m=t.length;f<m;f++)switch(t[f]|0){case Ts.rectangle:r=e[p++],o=e[p++];const _=e[p++],v=e[p++],x=r+_,S=o+v;i.moveTo(r,o),_===0||v===0?i.lineTo(x,S):(i.lineTo(x,o),i.lineTo(x,S),i.lineTo(r,S)),u||n.updateRectMinMax(d,[r,o,x,S]),i.closePath();break;case Ts.moveTo:r=e[p++],o=e[p++],i.moveTo(r,o),u||n.updatePathMinMax(d,r,o);break;case Ts.lineTo:r=e[p++],o=e[p++],i.lineTo(r,o),u||n.updatePathMinMax(d,r,o);break;case Ts.curveTo:h=r,l=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(d,h,l,e[p],e[p+1],e[p+2],e[p+3],r,o,g),p+=6;break;case Ts.curveTo2:h=r,l=o,i.bezierCurveTo(r,o,e[p],e[p+1],e[p+2],e[p+3]),n.updateCurvePathMinMax(d,h,l,r,o,e[p],e[p+1],e[p+2],e[p+3],g),r=e[p+2],o=e[p+3],p+=4;break;case Ts.curveTo3:h=r,l=o,r=e[p+2],o=e[p+3],i.bezierCurveTo(e[p],e[p+1],r,o,r,o),n.updateCurvePathMinMax(d,h,l,e[p],e[p+1],r,o,r,o,g),p+=4;break;case Ts.closePath:i.closePath();break}u&&n.updateScalingPathMinMax(d,g),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,Ei(e),Me.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,Ei(e),Me.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=px}eoClip(){this.pendingClip=P0}beginText(){this.current.textMatrix=a0,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}e.save(),e.beginPath();for(const s of t)e.setTransform(...s.transform),e.translate(s.x,s.y),s.addToPath(e,s.fontSize);e.restore(),e.clip(),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 d;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||gg,(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=((d=s.systemFontInfo)==null?void 0:d.css)||`"${n}", ${s.fallbackName}`;let o="normal";s.black?o="900":s.bold&&(o="bold");const h=s.italic?"italic":"normal";let l=e;e<C0?l=C0:e>A0&&(l=A0),this.current.fontSizeScale=e/l,this.ctx.font=`${h} ${o} ${l}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){const n=this.ctx,r=this.current,o=r.font,h=r.textRenderingMode,l=r.fontSize/r.fontSizeScale,d=h&me.FILL_STROKE_MASK,u=!!(h&me.ADD_TO_PATH_FLAG),g=r.patternFill&&!o.missingFile;let f;(o.disableFontFace||u||g)&&(f=o.getPathGenerator(this.commonObjs,t)),o.disableFontFace||g?(n.save(),n.translate(e,s),n.beginPath(),f(n,l),i&&n.setTransform(...i),(d===me.FILL||d===me.FILL_STROKE)&&n.fill(),(d===me.STROKE||d===me.FILL_STROKE)&&n.stroke(),n.restore()):((d===me.FILL||d===me.FILL_STROKE)&&n.fillText(t,e,s),(d===me.STROKE||d===me.FILL_STROKE)&&n.strokeText(t,e,s)),u&&(this.pendingTextPaths||(this.pendingTextPaths=[])).push({transform:At(n),x:e,y:s,fontSize:l,addToPath:f})}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 ot(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,l=e.fontDirection,d=e.textHScale*l,u=t.length,g=s.vertical,f=g?1:-1,p=s.defaultVMetrics,m=i*e.fontMatrix[0],_=e.textRenderingMode===me.FILL&&!s.disableFontFace&&!e.patternFill;n.save(),n.transform(...e.textMatrix),n.translate(e.x,e.y+e.textRise),l>0?n.scale(d,-1):n.scale(d,1);let v;if(e.patternFill){n.save();const M=e.fillColor.getPattern(n,this,Ei(n),Me.FILL);v=At(n),n.restore(),n.fillStyle=M}let x=e.lineWidth;const S=e.textMatrixScale;if(S===0||x===0){const M=e.textRenderingMode&me.FILL_STROKE_MASK;(M===me.STROKE||M===me.FILL_STROKE)&&(x=this.getSinglePixelWidth())}else x/=S;if(r!==1&&(n.scale(r,r),x/=r),n.lineWidth=x,s.isInvalidPDFjsFont){const M=[];let k=0;for(const O of t)M.push(O.unicode),k+=O.width;n.fillText(M.join(""),0,0),e.x+=k*m*d,n.restore(),this.compose();return}let C=0,E;for(E=0;E<u;++E){const M=t[E];if(typeof M=="number"){C+=f*M*i/1e3;continue}let k=!1;const O=(M.isSpace?h:0)+o,P=M.fontChar,L=M.accent;let F,W,B=M.width;if(g){const K=M.vmetric||p,tt=-(M.vmetric?K[1]:B*.5)*m,V=K[2]*m;B=K?-K[0]:B,F=tt/r,W=(C+V)/r}else F=C/r,W=0;if(s.remeasure&&B>0){const K=n.measureText(P).width*1e3/i*r;if(B<K&&this.isFontSubpixelAAEnabled){const tt=B/K;k=!0,n.save(),n.scale(tt,1),F/=tt}else B!==K&&(F+=(B-K)/2e3*i/r)}if(this.contentVisible&&(M.isInFont||s.missingFile)){if(_&&!L)n.fillText(P,F,W);else if(this.paintChar(P,F,W,v),L){const K=F+i*L.offset.x/r,tt=W-i*L.offset.y/r;this.paintChar(L.fontChar,K,tt,v)}}const z=g?B*m-O*l:B*m+O*l;C+=z,k&&n.restore()}g?e.y-=C:e.x+=C*d,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,l=s.wordSpacing,d=s.textHScale*r,u=s.fontMatrix||gg,g=t.length,f=s.textRenderingMode===me.INVISIBLE;let p,m,_,v;if(!(f||n===0)){for(this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null,e.save(),e.transform(...s.textMatrix),e.translate(s.x,s.y),e.scale(d,r),p=0;p<g;++p){if(m=t[p],typeof m=="number"){v=o*m*n/1e3,this.ctx.translate(v,0),s.x+=v*d;continue}const x=(m.isSpace?l:0)+h,S=i.charProcOperatorList[m.operatorListId];if(!S){st(`Type3 character "${m.operatorListId}" is not available.`);continue}this.contentVisible&&(this.processingType3=m,this.save(),e.scale(n,n),e.transform(...u),this.executeOperatorList(S),this.restore()),_=X.applyTransform([m.width,0],u)[0]*n+x,e.translate(_,0),s.x+=_*d}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 Zg(r,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack})};e=new Rg(t,s,this.ctx,n,i)}else e=this._getPattern(t[1],t[2]);return e}setStrokeColorN(){this.current.strokeColor=this.getColorN_Pattern(arguments)}setFillColorN(){this.current.fillColor=this.getColorN_Pattern(arguments),this.current.patternFill=!0}setStrokeRGBColor(t,e,s){this.ctx.strokeStyle=this.current.strokeColor=X.makeHexColor(t,e,s)}setStrokeTransparent(){this.ctx.strokeStyle=this.current.strokeColor="transparent"}setFillRGBColor(t,e,s){this.ctx.fillStyle=this.current.fillColor=X.makeHexColor(t,e,s),this.current.patternFill=!1}setFillTransparent(){this.ctx.fillStyle=this.current.fillColor="transparent",this.current.patternFill=!1}_getPattern(t,e=null){let s;return this.cachedPatterns.has(t)?s=this.cachedPatterns.get(t):(s=ax(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,Ei(e),Me.SHADING);const i=Ei(e);if(i){const{width:n,height:r}=e.canvas,[o,h,l,d]=X.getAxialAlignedBoundingBox([0,0,n,r],i);this.ctx.fillRect(o,h,l-o,d-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||id("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=X.getAxialAlignedBoundingBox(t.bbox,At(e));const n=[0,0,e.canvas.width,e.canvas.height];i=X.intersect(i,n)||[0,0,0,0];const r=Math.floor(i[0]),o=Math.floor(i[1]),h=Math.max(Math.ceil(i[2])-r,1),l=Math.max(Math.ceil(i[3])-o,1);this.current.startNewPathAndClipBox([0,0,h,l]);let d="groupAt"+this.groupLevel;t.smask&&(d+="_smask_"+this.smaskCounter++%2);const u=this.cachedCanvases.getCanvas(d,h,l),g=u.context;g.translate(-r,-o),g.transform(...s),t.smask?this.smaskStack.push({canvas:u.canvas,context:g,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()),mh(e,g),this.ctx=g,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=X.getAxialAlignedBoundingBox([0,0,e.canvas.width,e.canvas.height],i);this.ctx.drawImage(e.canvas,0,0),this.ctx.restore(),this.compose(n)}}beginAnnotation(t,e,s,i,n){if(y(this,On,wf).call(this),dd(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,l]=X.singularValueDecompose2dScale(At(this.ctx)),{viewportScale:d}=this,u=Math.ceil(r*this.outputScaleX*d),g=Math.ceil(o*this.outputScaleY*d);this.annotationCanvas=this.canvasFactory.create(u,g);const{canvas:f,context:p}=this.annotationCanvas;this.annotationCanvasMap.set(t,f),this.annotationCanvas.savedCtx=this.ctx,this.ctx=p,this.ctx.save(),this.ctx.setTransform(h,0,0,-l,0,o*l),dd(this.ctx)}else dd(this.ctx),this.endPath(),this.ctx.rect(e[0],e[1],r,o),this.ctx.clip(),this.ctx.beginPath()}this.current=new k0(this.ctx.canvas.width,this.ctx.canvas.height),this.transform(...s),this.transform(...i)}endAnnotation(){this.annotationCanvas&&(this.ctx.restore(),y(this,On,xf).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 l=this._createMaskCanvas(t);o.setTransform(1,0,0,1,l.offsetX-h[4],l.offsetY-h[5]);for(let d=0,u=r.length;d<u;d+=2){const g=X.transform(h,[e,s,i,n,r[d],r[d+1]]),[f,p]=X.applyTransform([0,0],g);o.drawImage(l.canvas,f,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:l}=n,d=this.cachedCanvases.getCanvas("maskCanvas",o,h),u=d.context;u.save();const g=this.getObject(r,n);O0(u,g),u.globalCompositeOperation="source-in",u.fillStyle=i?s.getPattern(u,this,Ei(e),Me.FILL):s,u.fillRect(0,0,o,h),u.restore(),e.save(),e.transform(...l),e.scale(1,-1),cd(e,d.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 l=0,d=i.length;l<d;l+=2)h.push({transform:[e,0,0,s,i[l],i[l+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(),!pe){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;M0(h,t),n=this.applyTransferMapsToCanvas(h)}const r=this._scaleImage(n,Ei(i));i.imageSmoothingEnabled=D0(At(i),t.interpolate),cd(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;M0(h,t),i=this.applyTransferMapsToCanvas(h)}for(const n of e)s.save(),s.transform(...n.transform),s.scale(1,-1),cd(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===P0?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),l=Math.abs(n);if(h===l)if(t===0)r=o=1/h;else{const d=h*t;r=o=d<1?1/d:1}else if(t===0)r=1/h,o=1/l;else{const d=h*t,u=l*t;r=d<1?1/d:1,o=u<1?1/u:1}}else{const h=Math.abs(e*n-s*i),l=Math.hypot(e,s),d=Math.hypot(i,n);if(t===0)r=d/h,o=l/h;else{const u=t*h;r=d>u?d/u:1,o=l>u?l/u: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}};On=new WeakSet,wf=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)},xf=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}}};let jo=Zg;for(const a in Ts)jo.prototype[a]!==void 0&&(jo.prototype[Ts[a]]=jo.prototype[a]);class ki{static get workerPort(){return c(this,zh)}static set workerPort(t){if(!(typeof Worker<"u"&&t instanceof Worker)&&t!==null)throw new Error("Invalid `workerPort` type.");b(this,zh,t)}static get workerSrc(){return c(this,Vh)}static set workerSrc(t){if(typeof t!="string")throw new Error("Invalid `workerSrc` type.");b(this,Vh,t)}}zh=new WeakMap,Vh=new WeakMap,w(ki,zh,null),w(ki,Vh,"");const ud={UNKNOWN:0,DATA:1,ERROR:2},Ht={UNKNOWN:0,CANCEL:1,CANCEL_COMPLETE:2,CLOSE:3,ENQUEUE:4,ERROR:5,PULL:6,PULL_COMPLETE:7,START_COMPLETE:8};function qe(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 lr(a.message);case"MissingPDFException":return new hr(a.message);case"PasswordException":return new pg(a.message,a.code);case"UnexpectedResponseException":return new nd(a.message,a.status);case"UnknownErrorException":return new mg(a.message,a.details);default:return new mg(a.message,a.toString())}}class bh{constructor(t,e,s){w(this,us);w(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",y(this,us,Ob).bind(this),{signal:c(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:l=>{const d=Promise.withResolvers();return this.streamControllers[n]={controller:l,startCall:d,pullCall:null,cancelCall:null,isClosed:!1},h.postMessage({sourceName:r,targetName:o,action:t,streamId:n,data:e,desiredSize:l.desiredSize},i),d.promise},pull:l=>{const d=Promise.withResolvers();return this.streamControllers[n].pullCall=d,h.postMessage({sourceName:r,targetName:o,stream:Ht.PULL,streamId:n,desiredSize:l.desiredSize}),d.promise},cancel:l=>{Ut(l instanceof Error,"cancel must have a valid reason");const d=Promise.withResolvers();return this.streamControllers[n].cancelCall=d,this.streamControllers[n].isClosed=!0,h.postMessage({sourceName:r,targetName:o,stream:Ht.CANCEL,streamId:n,reason:qe(l)}),d.promise}},s)}destroy(){var t;(t=c(this,ea))==null||t.abort(),b(this,ea,null)}}ea=new WeakMap,us=new WeakSet,Ob=function({data:t}){if(t.targetName!==this.sourceName)return;if(t.stream){y(this,us,Pb).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===ud.DATA)i.resolve(t.data);else if(t.callback===ud.ERROR)i.reject(qe(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;new Promise(function(r){r(e(t.data))}).then(function(r){n.postMessage({sourceName:s,targetName:i,callback:ud.DATA,callbackId:t.callbackId,data:r})},function(r){n.postMessage({sourceName:s,targetName:i,callback:ud.ERROR,callbackId:t.callbackId,reason:qe(r)})});return}if(t.streamId){y(this,us,Db).call(this,t);return}e(t.data)},Db=function(t){const e=t.streamId,s=this.sourceName,i=t.sourceName,n=this.comObj,r=this,o=this.actionHandler[t.action],h={enqueue(l,d=1,u){if(this.isCancelled)return;const g=this.desiredSize;this.desiredSize-=d,g>0&&this.desiredSize<=0&&(this.sinkCapability=Promise.withResolvers(),this.ready=this.sinkCapability.promise),n.postMessage({sourceName:s,targetName:i,stream:Ht.ENQUEUE,streamId:e,chunk:l},u)},close(){this.isCancelled||(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:Ht.CLOSE,streamId:e}),delete r.streamSinks[e])},error(l){Ut(l instanceof Error,"error must have a valid reason"),!this.isCancelled&&(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:Ht.ERROR,streamId:e,reason:qe(l)}))},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,new Promise(function(l){l(o(t.data,h))}).then(function(){n.postMessage({sourceName:s,targetName:i,stream:Ht.START_COMPLETE,streamId:e,success:!0})},function(l){n.postMessage({sourceName:s,targetName:i,stream:Ht.START_COMPLETE,streamId:e,reason:qe(l)})})},Pb=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 Ht.START_COMPLETE:t.success?r.startCall.resolve():r.startCall.reject(qe(t.reason));break;case Ht.PULL_COMPLETE:t.success?r.pullCall.resolve():r.pullCall.reject(qe(t.reason));break;case Ht.PULL:if(!o){n.postMessage({sourceName:s,targetName:i,stream:Ht.PULL_COMPLETE,streamId:e,success:!0});break}o.desiredSize<=0&&t.desiredSize>0&&o.sinkCapability.resolve(),o.desiredSize=t.desiredSize,new Promise(function(h){var l;h((l=o.onPull)==null?void 0:l.call(o))}).then(function(){n.postMessage({sourceName:s,targetName:i,stream:Ht.PULL_COMPLETE,streamId:e,success:!0})},function(h){n.postMessage({sourceName:s,targetName:i,stream:Ht.PULL_COMPLETE,streamId:e,reason:qe(h)})});break;case Ht.ENQUEUE:if(Ut(r,"enqueue should have stream controller"),r.isClosed)break;r.controller.enqueue(t.chunk);break;case Ht.CLOSE:if(Ut(r,"close should have stream controller"),r.isClosed)break;r.isClosed=!0,r.controller.close(),y(this,us,Gd).call(this,r,e);break;case Ht.ERROR:Ut(r,"error should have stream controller"),r.controller.error(qe(t.reason)),y(this,us,Gd).call(this,r,e);break;case Ht.CANCEL_COMPLETE:t.success?r.cancelCall.resolve():r.cancelCall.reject(qe(t.reason)),y(this,us,Gd).call(this,r,e);break;case Ht.CANCEL:if(!o)break;new Promise(function(h){var l;h((l=o.onCancel)==null?void 0:l.call(o,qe(t.reason)))}).then(function(){n.postMessage({sourceName:s,targetName:i,stream:Ht.CANCEL_COMPLETE,streamId:e,success:!0})},function(h){n.postMessage({sourceName:s,targetName:i,stream:Ht.CANCEL_COMPLETE,streamId:e,reason:qe(h)})}),o.sinkCapability.reject(qe(t.reason)),o.isCancelled=!0,delete this.streamSinks[e];break;default:throw new Error("Unexpected stream case")}},Gd=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 mx{constructor({parsedData:t,rawData:e}){w(this,Fr);w(this,Gh);b(this,Fr,t),b(this,Gh,e)}getRaw(){return c(this,Gh)}get(t){return c(this,Fr).get(t)??null}getAll(){return bg(c(this,Fr))}has(t){return c(this,Fr).has(t)}}Fr=new WeakMap,Gh=new WeakMap;const No=Symbol("INTERNAL");class bx{constructor(t,{name:e,intent:s,usage:i,rbGroups:n}){w(this,Uh,!1);w(this,Yh,!1);w(this,qh,!1);w(this,sa,!0);b(this,Uh,!!(t&Ye.DISPLAY)),b(this,Yh,!!(t&Ye.PRINT)),this.name=e,this.intent=s,this.usage=i,this.rbGroups=n}get visible(){if(c(this,qh))return c(this,sa);if(!c(this,sa))return!1;const{print:t,view:e}=this.usage;return c(this,Uh)?(e==null?void 0:e.viewState)!=="OFF":c(this,Yh)?(t==null?void 0:t.printState)!=="OFF":!0}_setVisible(t,e,s=!1){t!==No&&yt("Internal method `_setVisible` called."),b(this,qh,s),b(this,sa,e)}}Uh=new WeakMap,Yh=new WeakMap,qh=new WeakMap,sa=new WeakMap;class vx{constructor(t,e=Ye.DISPLAY){w(this,$h);w(this,Dn,null);w(this,pt,new Map);w(this,ia,null);w(this,na,null);if(this.renderingIntent=e,this.name=null,this.creator=null,t!==null){this.name=t.name,this.creator=t.creator,b(this,na,t.order);for(const s of t.groups)c(this,pt).set(s.id,new bx(e,s));if(t.baseState==="OFF")for(const s of c(this,pt).values())s._setVisible(No,!1);for(const s of t.on)c(this,pt).get(s)._setVisible(No,!0);for(const s of t.off)c(this,pt).get(s)._setVisible(No,!1);b(this,ia,this.getHash())}}isVisible(t){if(c(this,pt).size===0)return!0;if(!t)return id("Optional content group not defined."),!0;if(t.type==="OCG")return c(this,pt).has(t.id)?c(this,pt).get(t.id).visible:(st(`Optional content group not found: ${t.id}`),!0);if(t.type==="OCMD"){if(t.expression)return y(this,$h,Sf).call(this,t.expression);if(!t.policy||t.policy==="AnyOn"){for(const e of t.ids){if(!c(this,pt).has(e))return st(`Optional content group not found: ${e}`),!0;if(c(this,pt).get(e).visible)return!0}return!1}else if(t.policy==="AllOn"){for(const e of t.ids){if(!c(this,pt).has(e))return st(`Optional content group not found: ${e}`),!0;if(!c(this,pt).get(e).visible)return!1}return!0}else if(t.policy==="AnyOff"){for(const e of t.ids){if(!c(this,pt).has(e))return st(`Optional content group not found: ${e}`),!0;if(!c(this,pt).get(e).visible)return!0}return!1}else if(t.policy==="AllOff"){for(const e of t.ids){if(!c(this,pt).has(e))return st(`Optional content group not found: ${e}`),!0;if(c(this,pt).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=c(this,pt).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=c(this,pt).get(o))==null||n._setVisible(No,!1,!0));i._setVisible(No,!!e,!0),b(this,Dn,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=c(this,pt).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}}b(this,Dn,null)}get hasInitialVisibility(){return c(this,ia)===null||this.getHash()===c(this,ia)}getOrder(){return c(this,pt).size?c(this,na)?c(this,na).slice():[...c(this,pt).keys()]:null}getGroups(){return c(this,pt).size>0?bg(c(this,pt)):null}getGroup(t){return c(this,pt).get(t)||null}getHash(){if(c(this,Dn)!==null)return c(this,Dn);const t=new f0;for(const[e,s]of c(this,pt))t.update(`${e}:${s.visible}`);return b(this,Dn,t.hexdigest())}}Dn=new WeakMap,pt=new WeakMap,ia=new WeakMap,na=new WeakMap,$h=new WeakSet,Sf=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=y(this,$h,Sf).call(this,n);else if(c(this,pt).has(n))r=c(this,pt).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 yx{constructor(t,{disableRange:e=!1,disableStream:s=!1}){Ut(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,l)=>{this._onReceiveData({begin:h,chunk:l})}),t.addProgressListener((h,l)=>{this._onProgress({loaded:h,total:l})}),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)});Ut(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(){Ut(!this._fullRequestReader,"PDFDataTransportStream.getFullReader can only be called once.");const t=this._queuedChunks;return this._queuedChunks=null,new _x(this,t,this._progressiveDone,this._contentDispositionFilename)}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new wx(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 _x{constructor(t,e,s=!1,i=null){this._stream=t,this._done=s||!1,this._filename=xg(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 wx{constructor(t,e,s){this._stream=t,this._begin=e,this._end=s,this._queuedChunk=null,this._requests=[],this._done=!1,this.onProgress=null}_enqueue(t){if(!this._done){if(this._requests.length===0)this._queuedChunk=t;else{this._requests.shift().resolve({value:t,done:!1});for(const s of this._requests)s.resolve({value:void 0,done:!0});this._requests.length=0}this._done=!0,this._stream._removeRangeReader(this)}}get isStreamingSupported(){return!1}async read(){if(this._queuedChunk){const e=this._queuedChunk;return this._queuedChunk=null,{value:e,done:!1}}if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._stream._removeRangeReader(this)}}function xx(a){let t=!0,e=s("filename\\*","i").exec(a);if(e){e=e[1];let d=o(e);return d=unescape(d),d=h(d),d=l(d),n(d)}if(e=r(a),e){const d=l(e);return n(d)}if(e=s("filename","i").exec(a),e){e=e[1];let d=o(e);return d=l(d),n(d)}function s(d,u){return new RegExp("(?:^|;)\\s*"+d+'\\s*=\\s*([^";\\s][^;\\s]*|"(?:[^"\\\\]|\\\\"?)+"?)',u)}function i(d,u){if(d){if(!/^[\x00-\xFF]+$/.test(u))return u;try{const g=new TextDecoder(d,{fatal:!0}),f=rd(u);u=g.decode(f),t=!1}catch{}}return u}function n(d){return t&&/[\x80-\xff]/.test(d)&&(d=i("utf-8",d),t&&(d=i("iso-8859-1",d))),d}function r(d){const u=[];let g;const f=s("filename\\*((?!0\\d)\\d+)(\\*?)","ig");for(;(g=f.exec(d))!==null;){let[,m,_,v]=g;if(m=parseInt(m,10),m in u){if(m===0)break;continue}u[m]=[_,v]}const p=[];for(let m=0;m<u.length&&m in u;++m){let[_,v]=u[m];v=o(v),_&&(v=unescape(v),m===0&&(v=h(v))),p.push(v)}return p.join("")}function o(d){if(d.startsWith('"')){const u=d.slice(1).split('\\"');for(let g=0;g<u.length;++g){const f=u[g].indexOf('"');f!==-1&&(u[g]=u[g].slice(0,f),u.length=g+1),u[g]=u[g].replaceAll(/\\(.)/g,"$1")}d=u.join('"')}return d}function h(d){const u=d.indexOf("'");if(u===-1)return d;const g=d.slice(0,u),p=d.slice(u+1).replace(/^[^']*'/,"");return i(g,p)}function l(d){return!d.startsWith("=?")||/[\x00-\x19\x80-\xff]/.test(d)?d:d.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,function(u,g,f,p){if(f==="q"||f==="Q")return p=p.replaceAll("_"," "),p=p.replaceAll(/=([0-9a-fA-F]{2})/g,function(m,_){return String.fromCharCode(parseInt(_,16))}),i(g,p);try{p=atob(p)}catch{}return i(g,p)})}return""}function Ig(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 jg({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 Ng(a){const t=a.get("Content-Disposition");if(t){let e=xx(t);if(e.includes("%"))try{e=decodeURIComponent(e)}catch{}if(xg(e))return e}return null}function gd(a,t){return a===404||a===0&&t.startsWith("file:")?new hr('Missing PDF "'+t+'".'):new nd(`Unexpected server response (${a}) while retrieving PDF "${t}".`,a)}function L0(a){return a===200||a===206}function F0(a,t,e){return{method:"GET",headers:a,signal:e.signal,mode:"cors",credentials:t?"include":"same-origin",redirect:"follow"}}function R0(a){return a instanceof Uint8Array?a.buffer:a instanceof ArrayBuffer?a:(st(`getArrayBuffer - unexpected data format: ${a}`),new Uint8Array(a).buffer)}class I0{constructor(t){this.source=t,this.isHttp=/^https?:/i.test(t.url),this.headers=Ig(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 Ut(!this._fullRequestReader,"PDFFetchStream.getFullReader can only be called once."),this._fullRequestReader=new Sx(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new Cx(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 Sx{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,F0(s,this._withCredentials,this._abortController)).then(n=>{if(!L0(n.status))throw gd(n.status,i);this._reader=n.body.getReader(),this._headersCapability.resolve();const r=n.headers,{allowRangeRequests:o,suggestedLength:h}=jg({responseHeaders:r,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=o,this._contentLength=h||this._contentLength,this._filename=Ng(r),!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new lr("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:R0(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}class Cx{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,F0(n,this._withCredentials,this._abortController)).then(o=>{if(!L0(o.status))throw gd(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:R0(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}const Bg=200,Hg=206;function Ax(a){const t=a.response;return typeof t!="string"?t:rd(t).buffer}class Tx{constructor({url:t,httpHeaders:e,withCredentials:s}){this.url=t,this.isHttp=/^https?:/i.test(t),this.headers=Ig(this.isHttp,e),this.withCredentials=s||!1,this.currXhrId=0,this.pendingRequests=Object.create(null)}requestRange(t,e,s){const i={begin:t,end:e};for(const n in s)i[n]=s[n];return this.request(i)}requestFull(t){return this.request(t)}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=Hg):i.expectedStatus=Bg,e.responseType="arraybuffer",t.onError&&(e.onerror=function(n){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){var h,l,d;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){(h=s.onError)==null||h.call(s,i.status);return}const n=i.status||Bg;if(!(n===Bg&&s.expectedStatus===Hg)&&n!==s.expectedStatus){(l=s.onError)==null||l.call(s,i.status);return}const o=Ax(i);if(n===Hg){const u=i.getResponseHeader("Content-Range"),g=/bytes (\d+)-(\d+)\/(\d+)/.exec(u);s.onDone({begin:parseInt(g[1],10),chunk:o})}else o?s.onDone({begin:0,chunk:o}):(d=s.onError)==null||d.call(s,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 Ex{constructor(t){this._source=t,this._manager=new Tx(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 Ut(!this._fullRequestReader,"PDFNetworkStream.getFullReader can only be called once."),this._fullRequestReader=new kx(this._manager,this._source),this._fullRequestReader}getRangeReader(t,e){const s=new Mx(this._manager,t,e);return s.onClosed=this._onRangeRequestReaderClosed.bind(this),this._rangeRequestReaders.push(s),s}cancelAllRequests(t){var e;(e=this._fullRequestReader)==null||e.cancel(t);for(const s of this._rangeRequestReaders.slice(0))s.cancel(t)}}class kx{constructor(t,e){this._manager=t;const s={onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)};this._url=e.url,this._fullRequestId=t.requestFull(s),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),s=new Headers(e.getAllResponseHeaders().trim().split(/[\r\n]+/).map(r=>{const[o,...h]=r.split(": ");return[o,h.join(": ")]})),{allowRangeRequests:i,suggestedLength:n}=jg({responseHeaders:s,isHttp:this._manager.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});i&&(this._isRangeSupported=!0),this._contentLength=n||this._contentLength,this._filename=Ng(s),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=gd(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(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 Mx{constructor(t,e,s){this._manager=t;const i={onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)};this._url=t.url,this._requestId=t.requestRange(e,s,i),this._requests=[],this._queuedChunk=null,this._done=!1,this._storedError=void 0,this.onProgress=null,this.onClosed=null}_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=gd(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 Ox=/^[a-z][a-z0-9\-+.]+:/i;function Dx(a){if(Ox.test(a))return new URL(a);const t=bn.get("url");return new URL(t.pathToFileURL(a))}function j0(a,t,e){return a.protocol==="http:"?bn.get("http").request(a,{headers:t},e):bn.get("https").request(a,{headers:t},e)}class Px{constructor(t){this.source=t,this.url=Dx(t.url),this.isHttp=this.url.protocol==="http:"||this.url.protocol==="https:",this.isFsUrl=this.url.protocol==="file:",this.headers=Ig(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 Ut(!this._fullRequestReader,"PDFNodeStream.getFullReader can only be called once."),this._fullRequestReader=this.isFsUrl?new Rx(this):new Lx(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=this.isFsUrl?new Ix(this,t,e):new Fx(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 N0{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()}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 lr("streaming is disabled")),this._storedError&&this._readableStream.destroy(this._storedError)}}class B0{constructor(t){this._url=t.url,this._done=!1,this._storedError=null,this.onProgress=null,this._loaded=0,this._readableStream=null,this._readCapability=Promise.withResolvers();const e=t.source;this._isStreamingSupported=!e.disableStream}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)}}class Lx extends N0{constructor(t){super(t);const e=Object.fromEntries(t.headers),s=i=>{if(i.statusCode===404){const h=new hr(`Missing PDF "${this._url}".`);this._storedError=h,this._headersCapability.reject(h);return}this._headersCapability.resolve(),this._setReadableStream(i);const n=new Headers(this._readableStream.headers),{allowRangeRequests:r,suggestedLength:o}=jg({responseHeaders:n,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=r,this._contentLength=o||this._contentLength,this._filename=Ng(n)};this._request=j0(this._url,e,s),this._request.on("error",i=>{this._storedError=i,this._headersCapability.reject(i)}),this._request.end()}}class Fx extends B0{constructor(t,e,s){super(t);const i=Object.fromEntries(t.headers);i.Range=`bytes=${e}-${s-1}`;const n=r=>{if(r.statusCode===404){const o=new hr(`Missing PDF "${this._url}".`);this._storedError=o;return}this._setReadableStream(r)};this._request=j0(this._url,i,n),this._request.on("error",r=>{this._storedError=r}),this._request.end()}}class Rx extends N0{constructor(t){super(t);const e=bn.get("fs");e.promises.lstat(this._url).then(s=>{this._contentLength=s.size,this._setReadableStream(e.createReadStream(this._url)),this._headersCapability.resolve()},s=>{s.code==="ENOENT"&&(s=new hr(`Missing PDF "${this._url}".`)),this._storedError=s,this._headersCapability.reject(s)})}}class Ix extends B0{constructor(t,e,s){super(t);const i=bn.get("fs");this._setReadableStream(i.createReadStream(this._url,{start:e,end:s-1}))}}const jx=1e5,Be=30,Nx=.8,qt=class qt{constructor({textContentSource:t,container:e,viewport:s}){w(this,Bi);w(this,Pn,Promise.withResolvers());w(this,We,null);w(this,Kh,!1);w(this,Qh,!!((sb=globalThis.FontInspector)!=null&&sb.enabled));w(this,Rr,null);w(this,Ni,null);w(this,Jh,0);w(this,Zh,0);w(this,Ir,null);w(this,ra,null);w(this,oa,0);w(this,Ln,0);w(this,aa,Object.create(null));w(this,tl,[]);w(this,ha,null);w(this,jr,[]);w(this,el,new WeakMap);w(this,sl,null);var h;if(t instanceof ReadableStream)b(this,ha,t);else if(typeof t=="object")b(this,ha,new ReadableStream({start(l){l.enqueue(t),l.close()}}));else throw new Error('No "textContentSource" parameter specified.');b(this,We,b(this,ra,e)),b(this,Ln,s.scale*(globalThis.devicePixelRatio||1)),b(this,oa,s.rotation),b(this,Ni,{div:null,properties:null,ctx:null});const{pageWidth:i,pageHeight:n,pageX:r,pageY:o}=s.rawDims;b(this,sl,[1,0,0,-1,-r,o+n]),b(this,Zh,i),b(this,Jh,n),y(h=qt,Qe,Rb).call(h),cr(e,s),c(this,Pn).promise.finally(()=>{c(qt,la).delete(this),b(this,Ni,null),b(this,aa,null)}).catch(()=>{})}static get fontFamilyMap(){const{isWindows:t,isFirefox:e}=ke.platform;return ot(this,"fontFamilyMap",new Map([["sans-serif",`${t&&e?"Calibri, ":""}sans-serif`],["monospace",`${t&&e?"Lucida Console, ":""}monospace`]]))}render(){const t=()=>{c(this,Ir).read().then(({value:e,done:s})=>{if(s){c(this,Pn).resolve();return}c(this,Rr)??b(this,Rr,e.lang),Object.assign(c(this,aa),e.styles),y(this,Bi,Lb).call(this,e.items),t()},c(this,Pn).reject)};return b(this,Ir,c(this,ha).getReader()),c(qt,la).add(this),t(),c(this,Pn).promise}update({viewport:t,onBefore:e=null}){var n;const s=t.scale*(globalThis.devicePixelRatio||1),i=t.rotation;if(i!==c(this,oa)&&(e==null||e(),b(this,oa,i),cr(c(this,ra),{rotation:i})),s!==c(this,Ln)){e==null||e(),b(this,Ln,s);const r={div:null,properties:null,ctx:y(n=qt,Qe,Ud).call(n,c(this,Rr))};for(const o of c(this,jr))r.properties=c(this,el).get(o),r.div=o,y(this,Bi,Cf).call(this,r)}}cancel(){var e;const t=new lr("TextLayer task cancelled.");(e=c(this,Ir))==null||e.cancel(t).catch(()=>{}),b(this,Ir,null),c(this,Pn).reject(t)}get textDivs(){return c(this,jr)}get textContentItemsStr(){return c(this,tl)}static cleanup(){if(!(c(this,la).size>0)){c(this,Nr).clear();for(const{canvas:t}of c(this,Br).values())t.remove();c(this,Br).clear()}}};Pn=new WeakMap,We=new WeakMap,Kh=new WeakMap,Qh=new WeakMap,Rr=new WeakMap,Ni=new WeakMap,Jh=new WeakMap,Zh=new WeakMap,Ir=new WeakMap,ra=new WeakMap,oa=new WeakMap,Ln=new WeakMap,aa=new WeakMap,tl=new WeakMap,ha=new WeakMap,jr=new WeakMap,el=new WeakMap,sl=new WeakMap,Nr=new WeakMap,Br=new WeakMap,il=new WeakMap,Fn=new WeakMap,la=new WeakMap,Bi=new WeakSet,Lb=function(t){var i,n;if(c(this,Kh))return;(n=c(this,Ni)).ctx??(n.ctx=y(i=qt,Qe,Ud).call(i,c(this,Rr)));const e=c(this,jr),s=c(this,tl);for(const r of t){if(e.length>jx){st("Ignoring additional textDivs for performance reasons."),b(this,Kh,!0);return}if(r.str===void 0){if(r.type==="beginMarkedContentProps"||r.type==="beginMarkedContent"){const o=c(this,We);b(this,We,document.createElement("span")),c(this,We).classList.add("markedContent"),r.id!==null&&c(this,We).setAttribute("id",`${r.id}`),o.append(c(this,We))}else r.type==="endMarkedContent"&&b(this,We,c(this,We).parentNode);continue}s.push(r.str),y(this,Bi,Fb).call(this,r)}},Fb=function(t){var m;const e=document.createElement("span"),s={angle:0,canvasWidth:0,hasText:t.str!=="",hasEOL:t.hasEOL,fontSize:0};c(this,jr).push(e);const i=X.transform(c(this,sl),t.transform);let n=Math.atan2(i[1],i[0]);const r=c(this,aa)[t.fontName];r.vertical&&(n+=Math.PI/2);let o=c(this,Qh)&&r.fontSubstitution||r.fontFamily;o=qt.fontFamilyMap.get(o)||o;const h=Math.hypot(i[2],i[3]),l=h*y(m=qt,Qe,Ib).call(m,o,c(this,Rr));let d,u;n===0?(d=i[4],u=i[5]-l):(d=i[4]+l*Math.sin(n),u=i[5]-l*Math.cos(n));const g="calc(var(--scale-factor)*",f=e.style;c(this,We)===c(this,ra)?(f.left=`${(100*d/c(this,Zh)).toFixed(2)}%`,f.top=`${(100*u/c(this,Jh)).toFixed(2)}%`):(f.left=`${g}${d.toFixed(2)}px)`,f.top=`${g}${u.toFixed(2)}px)`),f.fontSize=`${g}${(c(qt,Fn)*h).toFixed(2)}px)`,f.fontFamily=o,s.fontSize=h,e.setAttribute("role","presentation"),e.textContent=t.str,e.dir=t.dir,c(this,Qh)&&(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 _=Math.abs(t.transform[0]),v=Math.abs(t.transform[3]);_!==v&&Math.max(_,v)/Math.min(_,v)>1.5&&(p=!0)}if(p&&(s.canvasWidth=r.vertical?t.height:t.width),c(this,el).set(e,s),c(this,Ni).div=e,c(this,Ni).properties=s,y(this,Bi,Cf).call(this,c(this,Ni)),s.hasText&&c(this,We).append(e),s.hasEOL){const _=document.createElement("br");_.setAttribute("role","presentation"),c(this,We).append(_)}},Cf=function(t){var o;const{div:e,properties:s,ctx:i}=t,{style:n}=e;let r="";if(c(qt,Fn)>1&&(r=`scale(${1/c(qt,Fn)})`),s.canvasWidth!==0&&s.hasText){const{fontFamily:h}=n,{canvasWidth:l,fontSize:d}=s;y(o=qt,Qe,Af).call(o,i,d*c(this,Ln),h);const{width:u}=i.measureText(e.textContent);u>0&&(r=`scaleX(${l*c(this,Ln)/u}) ${r}`)}s.angle!==0&&(r=`rotate(${s.angle}deg) ${r}`),r.length>0&&(n.transform=r)},Qe=new WeakSet,Ud=function(t=null){let e=c(this,Br).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}),c(this,Br).set(t,e),c(this,il).set(e,{size:0,family:""})}return e},Af=function(t,e,s){const i=c(this,il).get(t);e===i.size&&s===i.family||(t.font=`${e}px ${s}`,i.size=e,i.family=s)},Rb=function(){if(c(this,Fn)!==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),b(this,Fn,t.getBoundingClientRect().height),t.remove()},Ib=function(t,e){const s=c(this,Nr).get(t);if(s)return s;const i=y(this,Qe,Ud).call(this,e);i.canvas.width=i.canvas.height=Be,y(this,Qe,Af).call(this,i,Be,t);const n=i.measureText("");let r=n.fontBoundingBoxAscent,o=Math.abs(n.fontBoundingBoxDescent);if(r){const d=r/(r+o);return c(this,Nr).set(t,d),i.canvas.width=i.canvas.height=0,d}i.strokeStyle="red",i.clearRect(0,0,Be,Be),i.strokeText("g",0,0);let h=i.getImageData(0,0,Be,Be).data;o=0;for(let d=h.length-1-3;d>=0;d-=4)if(h[d]>0){o=Math.ceil(d/4/Be);break}i.clearRect(0,0,Be,Be),i.strokeText("A",0,Be),h=i.getImageData(0,0,Be,Be).data,r=0;for(let d=0,u=h.length;d<u;d+=4)if(h[d]>0){r=Be-Math.floor(d/4/Be);break}i.canvas.width=i.canvas.height=0;const l=r?r/(r+o):Nx;return c(this,Nr).set(t,l),l},w(qt,Qe),w(qt,Nr,new Map),w(qt,Br,new Map),w(qt,il,new WeakMap),w(qt,Fn,null),w(qt,la,new Set);let vh=qt;class yh{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(yh.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 l of n.children)i(l)}return i(t),s}static shouldBuildText(t){return!(t==="textarea"||t==="input"||t==="option"||t==="select")}}const Bx=65536,Hx=100,Wx=5e3,Xx=pe?tx:Qw,zx=pe?ex:v0,Vx=pe?Zw:Jw,Gx=pe?sx:w0;function Ux(a={}){typeof a=="string"||a instanceof URL?a={url:a}:(a instanceof ArrayBuffer||ArrayBuffer.isView(a))&&(a={data:a});const t=new Wg,{docId:e}=t,s=a.url?Yx(a.url):null,i=a.data?qx(a.data):null,n=a.httpHeaders||null,r=a.withCredentials===!0,o=a.password??null,h=a.range instanceof W0?a.range:null,l=Number.isInteger(a.rangeChunkSize)&&a.rangeChunkSize>0?a.rangeChunkSize:Bx;let d=a.worker instanceof Bo?a.worker:null;const u=a.verbosity,g=typeof a.docBaseUrl=="string"&&!ad(a.docBaseUrl)?a.docBaseUrl:null,f=typeof a.cMapUrl=="string"?a.cMapUrl:null,p=a.cMapPacked!==!1,m=a.CMapReaderFactory||zx,_=typeof a.standardFontDataUrl=="string"?a.standardFontDataUrl:null,v=a.StandardFontDataFactory||Gx,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:!pe,M=typeof a.isChrome=="boolean"?a.isChrome:!ke.platform.isFirefox&&typeof window<"u"&&!!(window!=null&&window.chrome),k=Number.isInteger(a.canvasMaxAreaInBytes)?a.canvasMaxAreaInBytes:-1,O=typeof a.disableFontFace=="boolean"?a.disableFontFace:pe,P=a.fontExtraProperties===!0,L=a.enableXfa===!0,F=a.ownerDocument||globalThis.document,W=a.disableRange===!0,B=a.disableStream===!0,z=a.disableAutoFetch===!0,K=a.pdfBug===!0,tt=a.CanvasFactory||Xx,V=a.FilterFactory||Vx,H=a.enableHWA===!0,Jt=h?h.length:a.length??NaN,Zt=typeof a.useSystemFonts=="boolean"?a.useSystemFonts:!pe&&!O,ce=typeof a.useWorkerFetch=="boolean"?a.useWorkerFetch:m===v0&&v===w0&&f&&_&&gh(f,document.baseURI)&&gh(_,document.baseURI);a.canvasFactory&&u0("`canvasFactory`-instance option, please use `CanvasFactory` instead."),a.filterFactory&&u0("`filterFactory`-instance option, please use `FilterFactory` instead.");const zt=null;kw(u);const _t={canvasFactory:new tt({ownerDocument:F,enableHWA:H}),filterFactory:new V({docId:e,ownerDocument:F}),cMapReaderFactory:ce?null:new m({baseUrl:f,isCompressed:p}),standardFontDataFactory:ce?null:new v({baseUrl:_})};if(!d){const Pt={verbosity:u,port:ki.workerPort};d=Pt.port?Bo.fromPort(Pt):new Bo(Pt),t._worker=d}const Le={docId:e,apiVersion:"4.8.69",data:i,password:o,disableAutoFetch:z,rangeChunkSize:l,length:Jt,docBaseUrl:g,enableXfa:L,evaluatorOptions:{maxImageSize:S,disableFontFace:O,ignoreErrors:x,isEvalSupported:C,isOffscreenCanvasSupported:E,isChrome:M,canvasMaxAreaInBytes:k,fontExtraProperties:P,useSystemFonts:Zt,cMapUrl:ce?f:null,standardFontDataUrl:ce?_:null}},gi={disableFontFace:O,fontExtraProperties:P,ownerDocument:F,pdfBug:K,styleElement:zt,loadingParams:{disableAutoFetch:z,enableXfa:L}};return d.promise.then(function(){if(t.destroyed)throw new Error("Loading aborted");if(d.destroyed)throw new Error("Worker was destroyed");const Pt=d.messageHandler.sendWithPromise("GetDocRequest",Le,i?[i.buffer]:null);let dt;if(h)dt=new yx(h,{disableRange:W,disableStream:B});else if(!i){if(!s)throw new Error("getDocument - no `url` parameter provided.");let po;pe?po=typeof fetch<"u"&&typeof Response<"u"&&"body"in Response.prototype&&gh(s)?I0:Px:po=gh(s)?I0:Ex,dt=new po({url:s,length:Jt,httpHeaders:n,withCredentials:r,rangeChunkSize:l,disableRange:W,disableStream:B})}return Pt.then(po=>{if(t.destroyed)throw new Error("Loading aborted");if(d.destroyed)throw new Error("Worker was destroyed");const mo=new bh(e,po,d.port),fi=new Jx(mo,t,dt,gi,_t);t._transport=fi,mo.send("Ready",null)})}).catch(t._capability.reject),t}function Yx(a){if(a instanceof URL)return a.href;try{return new URL(a,window.location).href}catch{if(pe&&typeof a=="string")return a}throw new Error("Invalid PDF url data: either string or URL-object is expected in the url property.")}function qx(a){if(pe&&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 rd(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 H0(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 Od=class Od{constructor(){this._capability=Promise.withResolvers(),this._transport=null,this._worker=null,this.docId=`d${Fe(Od,Md)._++}`,this.destroyed=!1,this.onPassword=null,this.onProgress=null}get promise(){return this._capability.promise}async destroy(){var t,e,s;this.destroyed=!0;try{(t=this._worker)!=null&&t.port&&(this._worker._pendingDestroy=!0),await((e=this._transport)==null?void 0:e.destroy())}catch(i){throw(s=this._worker)!=null&&s.port&&delete this._worker._pendingDestroy,i}this._transport=null,this._worker&&(this._worker.destroy(),this._worker=null)}};Md=new WeakMap,w(Od,Md,0);let Wg=Od;class W0{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 $x{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 ot(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 Kx{constructor(t,e,s,i=!1){w(this,gs);w(this,Rn,null);w(this,Hi,!1);this._pageIndex=t,this._pageInfo=e,this._transport=s,this._stats=i?new d0:null,this._pdfBug=i,this.commonObjs=s.commonObjs,this.objs=new X0,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,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 ot(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=fn.ENABLE,transform:n=null,background:r=null,optionalContentConfigPromise:o=null,annotationCanvasMap:h=null,pageColors:l=null,printAnnotationStorage:d=null,isEditing:u=!1}){var C,E;(C=this._stats)==null||C.time("Overall");const g=this._transport.getRenderingIntent(s,i,d,u),{renderingIntent:f,cacheKey:p}=g;b(this,Hi,!1),y(this,gs,Yd).call(this),o||(o=this._transport.getOptionalContentConfig(f));let m=this._intentStates.get(p);m||(m=Object.create(null),this._intentStates.set(p,m)),m.streamReaderCancelTimeout&&(clearTimeout(m.streamReaderCancelTimeout),m.streamReaderCancelTimeout=null);const _=!!(f&Ye.PRINT);m.displayReadyCapability||(m.displayReadyCapability=Promise.withResolvers(),m.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(E=this._stats)==null||E.time("Page Request"),this._pumpOperatorList(g));const v=M=>{var k;m.renderTasks.delete(x),(this._maybeCleanupAfterRender||_)&&b(this,Hi,!0),y(this,gs,za).call(this,!_),M?(x.capability.reject(M),this._abortOperatorList({intentState:m,reason:M instanceof Error?M:new Error(M)})):x.capability.resolve(),this._stats&&(this._stats.timeEnd("Rendering"),this._stats.timeEnd("Overall"),(k=globalThis.Stats)!=null&&k.enabled&&globalThis.Stats.add(this.pageNumber,this._stats))},x=new Xg({callback:v,params:{canvasContext:t,viewport:e,transform:n,background:r},objs:this.objs,commonObjs:this.commonObjs,annotationCanvasMap:h,operatorList:m.operatorList,pageIndex:this._pageIndex,canvasFactory:this._transport.canvasFactory,filterFactory:this._transport.filterFactory,useRequestAnimationFrame:!_,pdfBug:this._pdfBug,pageColors:l});(m.renderTasks||(m.renderTasks=new Set)).add(x);const S=x.task;return Promise.all([m.displayReadyCapability.promise,o]).then(([M,k])=>{var O;if(this.destroyed){v();return}if((O=this._stats)==null||O.time("Rendering"),!(k.renderingIntent&f))throw new Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");x.initializeGraphics({transparency:M,optionalContentConfig:k}),x.operatorListChanged()}).catch(v),S}getOperatorList({intent:t="display",annotationMode:e=fn.ENABLE,printAnnotationStorage:s=null,isEditing:i=!1}={}){var l;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},(l=this._stats)==null||l.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=>yh.textContent(s));const e=this.streamTextContent(t);return new Promise(function(s,i){function n(){r.read().then(function({value:h,done:l}){if(l){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(),b(this,Hi,!1),y(this,gs,Yd).call(this),Promise.all(t)}cleanup(t=!1){b(this,Hi,!0);const e=y(this,gs,za).call(this,!1);return t&&e&&this._stats&&(this._stats=new d0),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&&y(this,gs,za).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(),l=this._intentStates.get(e);l.streamReader=h;const d=()=>{h.read().then(({value:u,done:g})=>{if(g){l.streamReader=null;return}this._transport.destroyed||(this._renderPageChunk(u,l),d())},u=>{if(l.streamReader=null,!this._transport.destroyed){if(l.operatorList){l.operatorList.lastChunk=!0;for(const g of l.renderTasks)g.operatorListChanged();y(this,gs,za).call(this,!0)}if(l.displayReadyCapability)l.displayReadyCapability.reject(u);else if(l.opListReadCapability)l.opListReadCapability.reject(u);else throw u}})};d()}_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 wg){let i=Hx;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 lr(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}}Rn=new WeakMap,Hi=new WeakMap,gs=new WeakSet,za=function(t=!1){if(y(this,gs,Yd).call(this),!c(this,Hi)||this.destroyed)return!1;if(t)return b(this,Rn,setTimeout(()=>{b(this,Rn,null),y(this,gs,za).call(this,!1)},Wx)),!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(),b(this,Hi,!1),!0},Yd=function(){c(this,Rn)&&(clearTimeout(c(this,Rn)),b(this,Rn,null))};class Qx{constructor(){w(this,Wi,new Map);w(this,Dd,Promise.resolve())}postMessage(t,e){const s={data:structuredClone(t,e?{transfer:e}:null)};c(this,Dd).then(()=>{for(const[i]of c(this,Wi))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)}c(this,Wi).set(e,i)}removeEventListener(t,e){const s=c(this,Wi).get(e);s==null||s(),c(this,Wi).delete(e)}terminate(){for(const[,t]of c(this,Wi))t==null||t();c(this,Wi).clear()}}Wi=new WeakMap,Dd=new WeakMap;const St=class St{constructor({name:t=null,port:e=null,verbosity:s=Mw()}={}){w(this,ca);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=c(St,Wr))!=null&&i.has(e))throw new Error("Cannot use more than one PDFWorker per port.");(c(St,Wr)||b(St,Wr,new WeakMap)).set(e,this),this._initializeFromPort(e);return}this._initialize()}get promise(){return pe?Promise.all([bn.promise,this._readyCapability.promise]):this._readyCapability.promise}get port(){return this._port}get messageHandler(){return this._messageHandler}_initializeFromPort(t){this._port=t,this._messageHandler=new bh("main","worker",t),this._messageHandler.on("ready",function(){}),y(this,ca,qd).call(this)}_initialize(){if(c(St,Hr)||c(St,da,$d)){this._setupFakeWorker();return}let{workerSrc:t}=St;try{St._isSameOrigin(window.location.href,t)||(t=St._createCDNWrapper(new URL(t,window.location).href));const e=new Worker(t,{type:"module"}),s=new bh("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,y(this,ca,qd).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{id("The worker has been disabled.")}this._setupFakeWorker()}_setupFakeWorker(){c(St,Hr)||(st("Setting up fake worker."),b(St,Hr,!0)),St._setupFakeWorkerGlobal.then(t=>{if(this.destroyed){this._readyCapability.reject(new Error("Worker was destroyed"));return}const e=new Qx;this._port=e;const s=`fake${Fe(St,Pd)._++}`,i=new bh(s+"_worker",s,e);t.setup(i,e),this._messageHandler=new bh(s,s+"_worker",e),y(this,ca,qd).call(this)}).catch(t=>{this._readyCapability.reject(new Error(`Setting up fake worker failed: "${t.message}".`))})}destroy(){var t;this.destroyed=!0,this._webWorker&&(this._webWorker.terminate(),this._webWorker=null),(t=c(St,Wr))==null||t.delete(this._port),this._port=null,this._messageHandler&&(this._messageHandler.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=c(this,Wr))==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 St(t)}static get workerSrc(){if(ki.workerSrc)return ki.workerSrc;throw new Error('No "GlobalWorkerOptions.workerSrc" specified.')}static get _setupFakeWorkerGlobal(){return ot(this,"_setupFakeWorkerGlobal",(async()=>c(this,da,$d)?c(this,da,$d):(await import(this.workerSrc)).WorkerMessageHandler)())}};Pd=new WeakMap,Hr=new WeakMap,Wr=new WeakMap,ca=new WeakSet,qd=function(){this._readyCapability.resolve(),this._messageHandler.send("configure",{verbosity:this.verbosity})},da=new WeakSet,$d=function(){var t;try{return((t=globalThis.pdfjsWorker)==null?void 0:t.WorkerMessageHandler)||null}catch{return null}},w(St,da),w(St,Pd,0),w(St,Hr,!1),w(St,Wr),pe&&(b(St,Hr,!0),ki.workerSrc||(ki.workerSrc="./pdf.worker.mjs")),St._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},St._createCDNWrapper=t=>{const e=`await import("${t}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))};let Bo=St;class Jx{constructor(t,e,s,i,n){w(this,Xr);w(this,Xi,new Map);w(this,ri,new Map);w(this,ua,new Map);w(this,ga,new Map);w(this,oi,null);this.messageHandler=t,this.loadingTask=e,this.commonObjs=new X0,this.fontLoader=new $w({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 ot(this,"annotationStorage",new Og)}getRenderingIntent(t,e=fn.ENABLE,s=null,i=!1,n=!1){let r=Ye.DISPLAY,o=Mg;switch(t){case"any":r=Ye.ANY;break;case"display":break;case"print":r=Ye.PRINT;break;default:st(`getRenderingIntent - invalid intent: ${t}`)}const h=r&Ye.PRINT&&s instanceof p0?s:this.annotationStorage;switch(e){case fn.DISABLE:r+=Ye.ANNOTATIONS_DISABLE;break;case fn.ENABLE:break;case fn.ENABLE_FORMS:r+=Ye.ANNOTATIONS_FORMS;break;case fn.ENABLE_STORAGE:r+=Ye.ANNOTATIONS_STORAGE,o=h.serializable;break;default:st(`getRenderingIntent - invalid annotationMode: ${e}`)}i&&(r+=Ye.IS_EDITING),n&&(r+=Ye.OPLIST);const{ids:l,hash:d}=h.modifiedIds,u=[r,o.hash,d];return{renderingIntent:r,cacheKey:u.join("_"),annotationStorageSerializable:o,modifiedIds:l}}destroy(){var s;if(this.destroyCapability)return this.destroyCapability.promise;this.destroyed=!0,this.destroyCapability=Promise.withResolvers(),(s=c(this,oi))==null||s.reject(new Error("Worker was destroyed during onPassword callback"));const t=[];for(const i of c(this,ri).values())t.push(i._destroy());c(this,ri).clear(),c(this,ua).clear(),c(this,ga).clear(),this.hasOwnProperty("annotationStorage")&&this.annotationStorage.resetModified();const e=this.messageHandler.sendWithPromise("Terminate",null);return t.push(e),Promise.all(t).then(()=>{var i;this.commonObjs.clear(),this.fontLoader.clear(),c(this,Xi).clear(),this.filterFactory.destroy(),vh.cleanup(),(i=this._networkStream)==null||i.cancelAllRequests(new lr("Worker was terminated.")),this.messageHandler&&(this.messageHandler.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)=>{Ut(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}Ut(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 l;(l=e.onProgress)==null||l.call(e,{loaded:h.loaded,total:h.total})}),{isStreamingSupported:i,isRangeSupported:n,contentLength:r}}),t.on("GetRangeReader",(s,i)=>{Ut(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}Ut(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 $x(s,this))}),t.on("DocException",function(s){let i;switch(s.name){case"PasswordException":i=new pg(s.message,s.code);break;case"InvalidPDFException":i=new h0(s.message);break;case"MissingPDFException":i=new hr(s.message);break;case"UnexpectedResponseException":i=new nd(s.message,s.status);break;case"UnknownErrorException":i=new mg(s.message,s.details);break;default:yt("DocException - expected a valid Error.")}e._capability.reject(i)}),t.on("PasswordRequest",s=>{if(b(this,oi,Promise.withResolvers()),e.onPassword){const i=n=>{n instanceof Error?c(this,oi).reject(n):c(this,oi).resolve({password:n})};try{e.onPassword(i,s.code)}catch(n){c(this,oi).reject(n)}}else c(this,oi).reject(new pg(s.message,s.code));return c(this,oi).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;c(this,ri).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:l}=this._params;if("error"in n){const f=n.error;st(`Error during font loading: ${f}`),this.commonObjs.resolve(s,f);break}const d=l&&((r=globalThis.FontInspector)!=null&&r.enabled)?(f,p)=>globalThis.FontInspector.fontAdded(f,p):null,u=new Kw(n,{disableFontFace:o,inspectFont:d});this.fontLoader.bind(u).catch(()=>t.sendWithPromise("FontFallback",{id:s})).finally(()=>{!h&&u.data&&(u.data=null),this.commonObjs.resolve(s,u)});break;case"CopyLocalImage":const{imageRef:g}=n;Ut(g,"The imageRef must be defined.");for(const f of c(this,ri).values())for(const[,p]of f.objs)if((p==null?void 0:p.ref)===g)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=c(this,ri).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)>Cw&&(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=c(this,ua).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&&c(this,ga).set(n.refStr,t);const r=new Kx(e,n,this,this._params.pdfBug);return c(this,ri).set(e,r),r});return c(this,ua).set(e,i),i}getPageIndex(t){return H0(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 y(this,Xr,Vl).call(this,"GetFieldObjects")}hasJSActions(){return y(this,Xr,Vl).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 y(this,Xr,Vl).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 y(this,Xr,Vl).call(this,"GetOptionalContentConfig").then(e=>new vx(e,t))}getPermissions(){return this.messageHandler.sendWithPromise("GetPermissions",null)}getMetadata(){const t="GetMetadata",e=c(this,Xi).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 mx(i[1]):null,contentDispositionFilename:((n=this._fullReader)==null?void 0:n.filename)??null,contentLength:((r=this._fullReader)==null?void 0:r.contentLength)??null}});return c(this,Xi).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 c(this,ri).values())if(!e.cleanup())throw new Error(`startCleanup: Page ${e.pageNumber} is currently rendering.`);this.commonObjs.clear(),t||this.fontLoader.clear(),c(this,Xi).clear(),this.filterFactory.destroy(!0),vh.cleanup()}}cachedPageNumber(t){if(!H0(t))return null;const e=t.gen===0?`${t.num}R`:`${t.num}R${t.gen}`;return c(this,ga).get(e)??null}}Xi=new WeakMap,ri=new WeakMap,ua=new WeakMap,ga=new WeakMap,oi=new WeakMap,Xr=new WeakSet,Vl=function(t,e=null){const s=c(this,Xi).get(t);if(s)return s;const i=this.messageHandler.sendWithPromise(t,e);return c(this,Xi).set(t,i),i};const fd=Symbol("INITIAL_DATA");class X0{constructor(){w(this,nl);w(this,Ls,Object.create(null))}get(t,e=null){if(e){const i=y(this,nl,Tf).call(this,t);return i.promise.then(()=>e(i.data)),null}const s=c(this,Ls)[t];if(!s||s.data===fd)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return s.data}has(t){const e=c(this,Ls)[t];return!!e&&e.data!==fd}resolve(t,e=null){const s=y(this,nl,Tf).call(this,t);s.data=e,s.resolve()}clear(){var t;for(const e in c(this,Ls)){const{data:s}=c(this,Ls)[e];(t=s==null?void 0:s.bitmap)==null||t.close()}b(this,Ls,Object.create(null))}*[Symbol.iterator](){for(const t in c(this,Ls)){const{data:e}=c(this,Ls)[t];e!==fd&&(yield[t,e])}}}Ls=new WeakMap,nl=new WeakSet,Tf=function(t){var e;return(e=c(this,Ls))[t]||(e[t]={...Promise.withResolvers(),data:fd})};class Zx{constructor(t){w(this,In,null);b(this,In,t),this.onContinue=null}get promise(){return c(this,In).capability.promise}cancel(t=0){c(this,In).cancel(null,t)}get separateAnnots(){const{separateAnnots:t}=c(this,In).operatorList;if(!t)return!1;const{annotationCanvasMap:e}=c(this,In);return t.form||t.canvas&&(e==null?void 0:e.size)>0}}In=new WeakMap;const Vr=class Vr{constructor({callback:t,params:e,objs:s,commonObjs:i,annotationCanvasMap:n,operatorList:r,pageIndex:o,canvasFactory:h,filterFactory:l,useRequestAnimationFrame:d=!1,pdfBug:u=!1,pageColors:g=null}){w(this,jn,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=l,this._pdfBug=u,this.pageColors=g,this.running=!1,this.graphicsReadyCallback=null,this.graphicsReady=!1,this._useRequestAnimationFrame=d===!0&&typeof window<"u",this.cancelled=!1,this.capability=Promise.withResolvers(),this.task=new Zx(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(c(Vr,zr).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.");c(Vr,zr).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 jo(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(),c(this,jn)&&(window.cancelAnimationFrame(c(this,jn)),b(this,jn,null)),c(Vr,zr).delete(this._canvas),this.callback(t||new wg(`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?b(this,jn,window.requestAnimationFrame(()=>{b(this,jn,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(),c(Vr,zr).delete(this._canvas),this.callback())))}};jn=new WeakMap,zr=new WeakMap,w(Vr,zr,new WeakSet);let Xg=Vr;const tS="4.8.69",eS="3634dab10";function z0(a){return Math.floor(Math.max(0,Math.min(1,a))*255).toString(16).padStart(2,"0")}function _h(a){return Math.max(0,Math.min(255,255*a))}class V0{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=_h(t),[t,t,t]}static G_HTML([t]){const e=z0(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(_h)}static RGB_HTML(t){return`#${t.map(z0).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[_h(1-Math.min(1,t+i)),_h(1-Math.min(1,s+i)),_h(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 sS{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 zg extends sS{_createSVG(t){return document.createElementNS(Ti,t)}}class G0{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,l=h.selectedIndex===-1?"":h[h.selectedIndex].value;i.setValue(e,{value:l})});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,l]of Object.entries(r))if(l!=null)switch(h){case"class":l.length&&t.setAttribute(h,l.join(" "));break;case"dataId":break;case"id":t.setAttribute("data-element-id",l);break;case"style":Object.assign(t.style,l);break;case"textContent":t.textContent=l;break;default:(!o||h!=="href"&&h!=="newWindow")&&t.setAttribute(h,l)}o&&n.addLinkAttributes(t,r.href,r.newWindow),s&&r.dataId&&this.setupStorage(t,r.dataId,e,s)}static render(t){var u,g;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 f=`matrix(${t.viewport.transform.join(",")})`;h.style.transform=f}o&&h.setAttribute("class","xfaLayer xfaFont");const l=[];if(i.children.length===0){if(i.value){const f=document.createTextNode(i.value);r.append(f),o&&yh.shouldBuildText(i.name)&&l.push(f)}return{textDivs:l}}const d=[[i,-1,r]];for(;d.length>0;){const[f,p,m]=d.at(-1);if(p+1===f.children.length){d.pop();continue}const _=f.children[++d.at(-1)[1]];if(_===null)continue;const{name:v}=_;if(v==="#text"){const S=document.createTextNode(_.value);l.push(S),m.append(S);continue}const x=(u=_==null?void 0:_.attributes)!=null&&u.xmlns?document.createElementNS(_.attributes.xmlns,v):document.createElement(v);if(m.append(x),_.attributes&&this.setAttributes({html:x,element:_,storage:e,intent:n,linkService:s}),((g=_.children)==null?void 0:g.length)>0)d.push([_,-1,x]);else if(_.value){const S=document.createTextNode(_.value);o&&yh.shouldBuildText(v)&&l.push(S),x.append(S)}}for(const f of h.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea"))f.setAttribute("readOnly",!0);return{textDivs:l}}static update(t){const e=`matrix(${t.viewport.transform.join(",")})`;t.div.style.transform=e,t.div.hidden=!1}}const wh=1e3,iS=9,ur=new WeakSet;function Mi(a){return{width:a[2]-a[0],height:a[3]-a[1]}}class nS{static create(t){switch(t.data.annotationType){case Gt.LINK:return new U0(t);case Gt.TEXT:return new rS(t);case Gt.WIDGET:switch(t.data.fieldType){case"Tx":return new oS(t);case"Btn":return t.data.radioButton?new Y0(t):t.data.checkBox?new hS(t):new lS(t);case"Ch":return new cS(t);case"Sig":return new aS(t)}return new gr(t);case Gt.POPUP:return new Vg(t);case Gt.FREETEXT:return new q0(t);case Gt.LINE:return new uS(t);case Gt.SQUARE:return new gS(t);case Gt.CIRCLE:return new fS(t);case Gt.POLYLINE:return new $0(t);case Gt.CARET:return new mS(t);case Gt.INK:return new Gg(t);case Gt.POLYGON:return new pS(t);case Gt.HIGHLIGHT:return new K0(t);case Gt.UNDERLINE:return new bS(t);case Gt.SQUIGGLY:return new vS(t);case Gt.STRIKEOUT:return new yS(t);case Gt.STAMP:return new Q0(t);case Gt.FILEATTACHMENT:return new _S(t);default:return new jt(t)}}}const tf=class tf{constructor(t,{isRenderable:e=!1,ignoreBorder:s=!1,createQuadrilaterals:i=!1}={}){w(this,rl);w(this,Gr,null);w(this,fa,!1);w(this,pa,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 tf._hasPopupData(this.data)}updateEdited(t){var s;if(!this.container)return;c(this,Gr)||b(this,Gr,{rect:this.data.rect.slice(0)});const{rect:e}=t;e&&y(this,rl,Ef).call(this,e),(s=c(this,pa))==null||s.popup.updateEdited(t)}resetEdited(){var t;c(this,Gr)&&(y(this,rl,Ef).call(this,c(this,Gr).rect),(t=c(this,pa))==null||t.popup.resetEdited(),b(this,Gr,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 gr||(n.tabIndex=wh);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 Vg){const{rotation:m}=e;return!e.hasOwnCanvas&&m!==0&&this.setRotation(m,n),n}const{width:o,height:h}=Mi(e.rect);if(!t&&e.borderStyle.width>0){r.borderWidth=`${e.borderStyle.width}px`;const m=e.borderStyle.horizontalCornerRadius,_=e.borderStyle.verticalCornerRadius;if(m>0||_>0){const x=`calc(${m}px * var(--scale-factor)) / calc(${_}px * var(--scale-factor))`;r.borderRadius=x}else if(this instanceof Y0){const x=`calc(${o}px * var(--scale-factor)) / calc(${h}px * var(--scale-factor))`;r.borderRadius=x}switch(e.borderStyle.style){case dh.SOLID:r.borderStyle="solid";break;case dh.DASHED:r.borderStyle="dashed";break;case dh.BEVELED:st("Unimplemented border style: beveled");break;case dh.INSET:st("Unimplemented border style: inset");break;case dh.UNDERLINE:r.borderBottomStyle="solid";break}const v=e.borderColor||null;v?(b(this,fa,!0),r.borderColor=X.makeHexColor(v[0]|0,v[1]|0,v[2]|0)):r.borderWidth=0}const l=X.normalizeRect([e.rect[0],s.view[3]-e.rect[1]+s.view[1],e.rect[2],s.view[3]-e.rect[3]+s.view[1]]),{pageWidth:d,pageHeight:u,pageX:g,pageY:f}=i.rawDims;r.left=`${100*(l[0]-g)/d}%`,r.top=`${100*(l[1]-f)/u}%`;const{rotation:p}=e;return e.hasOwnCanvas||p===0?(r.width=`${100*o/d}%`,r.height=`${100*h/u}%`):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}=Mi(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]=V0[`${r}_HTML`](o),this.annotationStorage.setValue(this.data.id,{[s]:V0[`${r}_rgb`](o)})};return ot(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(m=>Math.fround(m));if(t.length===8){const[m,_,v,x]=t.subarray(2,6);if(i===m&&n===_&&e===v&&s===x)return}const{style:r}=this.container;let o;if(c(this,fa)){const{borderColor:m,borderWidth:_}=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="${m}" stroke-width="${_}">`],this.container.classList.add("hasBorder")}const h=i-e,l=n-s,{svgFactory:d}=this,u=d.createElement("svg");u.classList.add("quadrilateralsContainer"),u.setAttribute("width",0),u.setAttribute("height",0);const g=d.createElement("defs");u.append(g);const f=d.createElement("clipPath"),p=`clippath_${this.data.id}`;f.setAttribute("id",p),f.setAttribute("clipPathUnits","objectBoundingBox"),g.append(f);for(let m=2,_=t.length;m<_;m+=8){const v=t[m],x=t[m+1],S=t[m+2],C=t[m+3],E=d.createElement("rect"),M=(S-e)/h,k=(n-x)/l,O=(v-S)/h,P=(x-C)/l;E.setAttribute("x",M),E.setAttribute("y",k),E.setAttribute("width",O),E.setAttribute("height",P),f.append(E),o==null||o.push(`<rect vector-effect="non-scaling-stroke" x="${M}" y="${k}" width="${O}" height="${P}"/>`)}c(this,fa)&&(o.push("</g></svg>')"),r.backgroundImage=o.join("")),this.container.append(u),this.container.style.clipPath=`url(#${p})`}_createPopup(){const{data:t}=this,e=b(this,pa,new Vg({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,l=document.querySelector(`[data-element-id="${r}"]`);if(l&&!ur.has(l)){st(`_getElementsByName - element not allowed: ${r}`);continue}s.push({id:r,exportValue:h,domElement:l})}return s}for(const i of document.getElementsByName(t)){const{exportValue:n}=i,r=i.getAttribute("data-element-id");r!==e&&ur.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})})}};Gr=new WeakMap,fa=new WeakMap,pa=new WeakMap,rl=new WeakSet,Ef=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:l,height:d}=Mi(t);e.left=`${100*(t[0]-o)/n}%`,e.top=`${100*(r-t[3]+h)/r}%`,i===0?(e.width=`${100*l/n}%`,e.height=`${100*d/r}%`):this.setRotation(i)};let jt=tf;class U0 extends jt{constructor(e,s=null){super(e,{isRenderable:!0,ignoreBorder:!!(s!=null&&s.ignoreBorder),createQuadrilaterals:!0});w(this,Je);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?(y(this,Je,jb).call(this,i,e.attachment,e.attachmentDest),n=!0):e.setOCGState?(y(this,Je,Nb).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==="")&&y(this,Je,bo).call(this)}_bindNamedAction(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeNamedAction(s),!1),y(this,Je,bo).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),y(this,Je,bo).call(this)}_bindResetFormAction(e,s){const i=e.onclick;if(i||(e.href=this.linkService.getAnchorUrl("")),y(this,Je,bo).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 u;i==null||i();const{fields:n,refs:r,include:o}=s,h=[];if(n.length!==0||r.length!==0){const g=new Set(r);for(const f of n){const p=this._fieldObjects[f]||[];for(const{id:m}of p)g.add(m)}for(const f of Object.values(this._fieldObjects))for(const p of f)g.has(p.id)===o&&h.push(p)}else for(const g of Object.values(this._fieldObjects))h.push(...g);const l=this.annotationStorage,d=[];for(const g of h){const{id:f}=g;switch(d.push(f),g.type){case"text":{const m=g.defaultValue||"";l.setValue(f,{value:m});break}case"checkbox":case"radiobutton":{const m=g.defaultValue===g.exportValues;l.setValue(f,{value:m});break}case"combobox":case"listbox":{const m=g.defaultValue||"";l.setValue(f,{value:m});break}default:continue}const p=document.querySelector(`[data-element-id="${f}"]`);if(p){if(!ur.has(p)){st(`_bindResetFormAction - element not allowed: ${f}`);continue}}else continue;p.dispatchEvent(new Event("resetform"))}return this.enableScripting&&((u=this.linkService.eventBus)==null||u.dispatch("dispatcheventinsandbox",{source:this,detail:{id:"app",ids:d,name:"ResetForm"}})),!1}}}Je=new WeakSet,bo=function(){this.container.setAttribute("data-internal-link","")},jb=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},y(this,Je,bo).call(this)},Nb=function(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeSetOCGState(s),!1),y(this,Je,bo).call(this)};class rS extends jt{constructor(t){super(t,{isRenderable:!0})}render(){this.container.classList.add("textAnnotation");const t=document.createElement("img");return t.src=this.imageResourcesPath+"annotation-"+this.data.name.toLowerCase()+".svg",t.setAttribute("data-l10n-id","pdfjs-text-annotation-type"),t.setAttribute("data-l10n-args",JSON.stringify({type:this.data.name})),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.append(t),this.container}}class gr extends jt{render(){return this.container}showElementAndHideCanvas(t){var e;this.data.hasOwnCanvas&&(((e=t.previousSibling)==null?void 0:e.nodeName)==="CANVAS"&&(t.previousSibling.hidden=!0),t.hidden=!1)}_getKeyModifier(t){return ke.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,l]of s)(l==="Action"||(n=this.data.actions)!=null&&n[l])&&((l==="Focus"||l==="Blur")&&(e||(e={focused:!1})),this._setEventListener(t,e,h,l,i),l==="Focus"&&!((r=this.data.actions)!=null&&r.Blur)?this._setEventListener(t,e,"blur","Blur",null):l==="Blur"&&!((o=this.data.actions)!=null&&o.Focus)&&this._setEventListener(t,e,"focus","Focus",null))}_setBackgroundColor(t){const e=this.data.backgroundColor||null;t.style.backgroundColor=e===null?"transparent":X.makeHexColor(e[0],e[1],e[2])}_setTextStyle(t){const e=["left","center","right"],{fontColor:s}=this.data.defaultAppearanceData,i=this.data.defaultAppearanceData.fontSize||iS,n=t.style;let r;const o=2,h=l=>Math.round(10*l)/10;if(this.data.multiLine){const l=Math.abs(this.data.rect[3]-this.data.rect[1]-o),d=Math.round(l/(fg*i))||1,u=l/d;r=Math.min(i,h(u/fg))}else{const l=Math.abs(this.data.rect[3]-this.data.rect[1]-o);r=Math.min(i,h(l/fg))}n.fontSize=`calc(${r}px * var(--scale-factor))`,n.color=X.makeHexColor(s[0],s[1],s[2]),this.data.textAlignment!==null&&(n.textAlign=e[this.data.textAlignment])}_setRequired(t,e){e?t.setAttribute("required",!0):t.removeAttribute("required"),t.setAttribute("aria-required",e)}}class oS extends gr{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 l=r.formattedValue||((i=this.data.textContent)==null?void 0:i.join(`
500
+ `))||null;l&&this.data.comb&&(l=l.replaceAll(/\s+/g,""));const d={userValue:o,formattedValue:l,lastCommittedValue:null,commitKey:1,focused:!1};this.data.multiLine?(s=document.createElement("textarea"),s.textContent=l??o,this.data.doNotScroll&&(s.style.overflowY="hidden")):(s=document.createElement("input"),s.type="text",s.setAttribute("value",l??o),this.data.doNotScroll&&(s.style.overflowX="hidden")),this.data.hasOwnCanvas&&(s.hidden=!0),ur.add(s),s.setAttribute("data-element-id",e),s.disabled=this.data.readOnly,s.name=this.data.fieldName,s.tabIndex=wh,this._setRequired(s,this.data.required),h&&(s.maxLength=h),s.addEventListener("input",g=>{t.setValue(e,{value:g.target.value}),this.setPropertyOnSiblings(s,"value",g.target.value,"value"),d.formattedValue=null}),s.addEventListener("resetform",g=>{const f=this.data.defaultFieldValue??"";s.value=d.userValue=f,d.formattedValue=null});let u=g=>{const{formattedValue:f}=d;f!=null&&(g.target.value=f),g.target.scrollLeft=0};if(this.enableScripting&&this.hasJSActions){s.addEventListener("focus",f=>{var m;if(d.focused)return;const{target:p}=f;d.userValue&&(p.value=d.userValue),d.lastCommittedValue=p.value,d.commitKey=1,(m=this.data.actions)!=null&&m.Focus||(d.focused=!0)}),s.addEventListener("updatefromsandbox",f=>{this.showElementAndHideCanvas(f.target);const p={value(m){d.userValue=m.detail.value??"",t.setValue(e,{value:d.userValue.toString()}),m.target.value=d.userValue},formattedValue(m){const{formattedValue:_}=m.detail;d.formattedValue=_,_!=null&&m.target!==document.activeElement&&(m.target.value=_),t.setValue(e,{formattedValue:_})},selRange(m){m.target.setSelectionRange(...m.detail.selRange)},charLimit:m=>{var S;const{charLimit:_}=m.detail,{target:v}=m;if(_===0){v.removeAttribute("maxLength");return}v.setAttribute("maxLength",_);let x=d.userValue;!x||x.length<=_||(x=x.slice(0,_),v.value=d.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:v.selectionStart,selEnd:v.selectionEnd}}))}};this._dispatchEventFromSandbox(p,f)}),s.addEventListener("keydown",f=>{var _;d.commitKey=1;let p=-1;if(f.key==="Escape"?p=0:f.key==="Enter"&&!this.data.multiLine?p=2:f.key==="Tab"&&(d.commitKey=3),p===-1)return;const{value:m}=f.target;d.lastCommittedValue!==m&&(d.lastCommittedValue=m,d.userValue=m,(_=this.linkService.eventBus)==null||_.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:m,willCommit:!0,commitKey:p,selStart:f.target.selectionStart,selEnd:f.target.selectionEnd}}))});const g=u;u=null,s.addEventListener("blur",f=>{var m,_;if(!d.focused||!f.relatedTarget)return;(m=this.data.actions)!=null&&m.Blur||(d.focused=!1);const{value:p}=f.target;d.userValue=p,d.lastCommittedValue!==p&&((_=this.linkService.eventBus)==null||_.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:p,willCommit:!0,commitKey:d.commitKey,selStart:f.target.selectionStart,selEnd:f.target.selectionEnd}})),g(f)}),(n=this.data.actions)!=null&&n.Keystroke&&s.addEventListener("beforeinput",f=>{var E;d.lastCommittedValue=null;const{data:p,target:m}=f,{value:_,selectionStart:v,selectionEnd:x}=m;let S=v,C=x;switch(f.inputType){case"deleteWordBackward":{const M=_.substring(0,v).match(/\w*[^\w]*$/);M&&(S-=M[0].length);break}case"deleteWordForward":{const M=_.substring(v).match(/^[^\w]*\w*/);M&&(C+=M[0].length);break}case"deleteContentBackward":v===x&&(S-=1);break;case"deleteContentForward":v===x&&(C+=1);break}f.preventDefault(),(E=this.linkService.eventBus)==null||E.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:_,change:p||"",willCommit:!1,selStart:S,selEnd:C}})}),this._setEventListeners(s,d,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],f=>f.target.value)}if(u&&s.addEventListener("blur",u),this.data.comb){const f=(this.data.rect[2]-this.data.rect[0])/h;s.classList.add("comb"),s.style.letterSpacing=`calc(${f}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 aS extends gr{constructor(t){super(t,{isRenderable:!!t.data.hasOwnCanvas})}}class hS extends gr{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 ur.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=wh,n.addEventListener("change",r=>{const{name:o,checked:h}=r.target;for(const l of this._getElementsByName(o,s)){const d=h&&l.exportValue===e.exportValue;l.domElement&&(l.domElement.checked=d),t.setValue(l.id,{value:d})}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 Y0 extends gr{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(ur.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=wh,n.addEventListener("change",r=>{const{name:o,checked:h}=r.target;for(const l of this._getElementsByName(o,s))t.setValue(l.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:l=>{const d=r===l.detail.value;for(const u of this._getElementsByName(l.target.name)){const g=d&&u.id===s;u.domElement&&(u.domElement.checked=g),t.setValue(u.id,{value:g})}}};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 lS extends U0{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 cS extends gr{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");ur.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=wh;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",d=>{const u=this.data.defaultFieldValue;for(const g of i.options)g.selected=g.value===u});for(const d of this.data.options){const u=document.createElement("option");u.textContent=d.displayValue,u.value=d.exportValue,s.value.includes(d.exportValue)&&(u.setAttribute("selected",!0),n=!1),i.append(u)}let r=null;if(n){const d=document.createElement("option");d.value=" ",d.setAttribute("hidden",!0),d.setAttribute("selected",!0),i.prepend(d),r=()=>{d.remove(),i.removeEventListener("input",r),r=null},i.addEventListener("input",r)}const o=d=>{const u=d?"value":"textContent",{options:g,multiple:f}=i;return f?Array.prototype.filter.call(g,p=>p.selected).map(p=>p[u]):g.selectedIndex===-1?null:g[g.selectedIndex][u]};let h=o(!1);const l=d=>{const u=d.target.options;return Array.prototype.map.call(u,g=>({displayValue:g.textContent,exportValue:g.value}))};return this.enableScripting&&this.hasJSActions?(i.addEventListener("updatefromsandbox",d=>{const u={value(g){r==null||r();const f=g.detail.value,p=new Set(Array.isArray(f)?f:[f]);for(const m of i.options)m.selected=p.has(m.value);t.setValue(e,{value:o(!0)}),h=o(!1)},multipleSelection(g){i.multiple=!0},remove(g){const f=i.options,p=g.detail.remove;f[p].selected=!1,i.remove(p),f.length>0&&Array.prototype.findIndex.call(f,_=>_.selected)===-1&&(f[0].selected=!0),t.setValue(e,{value:o(!0),items:l(g)}),h=o(!1)},clear(g){for(;i.length!==0;)i.remove(0);t.setValue(e,{value:null,items:[]}),h=o(!1)},insert(g){const{index:f,displayValue:p,exportValue:m}=g.detail.insert,_=i.children[f],v=document.createElement("option");v.textContent=p,v.value=m,_?_.before(v):i.append(v),t.setValue(e,{value:o(!0),items:l(g)}),h=o(!1)},items(g){const{items:f}=g.detail;for(;i.length!==0;)i.remove(0);for(const p of f){const{displayValue:m,exportValue:_}=p,v=document.createElement("option");v.textContent=m,v.value=_,i.append(v)}i.options.length>0&&(i.options[0].selected=!0),t.setValue(e,{value:o(!0),items:l(g)}),h=o(!1)},indices(g){const f=new Set(g.detail.indices);for(const p of g.target.options)p.selected=f.has(p.index);t.setValue(e,{value:o(!0)}),h=o(!1)},editable(g){g.target.disabled=!g.detail.editable}};this._dispatchEventFromSandbox(u,d)}),i.addEventListener("input",d=>{var f;const u=o(!0),g=o(!1);t.setValue(e,{value:u}),d.preventDefault(),(f=this.linkService.eventBus)==null||f.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:h,change:g,changeEx:u,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"]],d=>d.target.value)):i.addEventListener("input",function(d){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 Vg extends jt{constructor(t){const{data:e,elements:s}=t;super(t,{isRenderable:jt._hasPopupData(e)}),this.elements=s,this.popup=null}render(){this.container.classList.add("popupAnnotation");const t=this.popup=new dS({container:this.container,color:this.data.color,titleObj:this.data.titleObj,modificationDate:this.data.modificationDate,contentsObj:this.data.contentsObj,richText:this.data.richText,rect:this.data.rect,parentRect:this.data.parentRect||null,parent:this.parent,elements:this.elements,open:this.data.open}),e=[];for(const s of this.elements)s.popup=t,s.container.ariaHasPopup="dialog",e.push(s.data.id),s.addHighlightArea();return this.container.setAttribute("aria-controls",e.map(s=>`${_g}${s}`).join(",")),this.container}}class dS{constructor({container:t,color:e,elements:s,titleObj:i,modificationDate:n,contentsObj:r,richText:o,parent:h,rect:l,parentRect:d,open:u}){w(this,mt);w(this,ma,y(this,mt,Wb).bind(this));w(this,Ld,y(this,mt,Mf).bind(this));w(this,Fd,y(this,mt,Jd).bind(this));w(this,ba,y(this,mt,Qd).bind(this));w(this,Ur,null);w(this,Dt,null);w(this,zi,null);w(this,va,null);w(this,ol,null);w(this,al,null);w(this,ya,null);w(this,Vi,!1);w(this,Fs,null);w(this,Gi,null);w(this,hl,null);w(this,Ui,null);w(this,ll,null);w(this,Yr,null);w(this,qr,!1);var g;b(this,Dt,t),b(this,ll,i),b(this,zi,r),b(this,Ui,o),b(this,al,h),b(this,Ur,e),b(this,hl,l),b(this,ya,d),b(this,ol,s),b(this,va,Sg.toDateObject(n)),this.trigger=s.flatMap(f=>f.getElementsToTriggerPopup());for(const f of this.trigger)f.addEventListener("click",c(this,ba)),f.addEventListener("mouseenter",c(this,Fd)),f.addEventListener("mouseleave",c(this,Ld)),f.classList.add("popupTriggerArea");for(const f of s)(g=f.container)==null||g.addEventListener("keydown",c(this,ma));c(this,Dt).hidden=!0,u&&y(this,mt,Qd).call(this)}render(){if(c(this,Fs))return;const t=b(this,Fs,document.createElement("div"));if(t.className="popup",c(this,Ur)){const n=t.style.outlineColor=X.makeHexColor(...c(this,Ur));CSS.supports("background-color","color-mix(in srgb, red 30%, white)")?t.style.backgroundColor=`color-mix(in srgb, ${n} 30%, white)`:t.style.backgroundColor=X.makeHexColor(...c(this,Ur).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}=c(this,ll),t.append(e),c(this,va)){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:c(this,va).valueOf()})),e.append(n)}const i=c(this,mt,Kd);if(i)G0.render({xfaHtml:i,intent:"richText",div:t}),t.lastChild.classList.add("richText","popupContent");else{const n=this._formatContents(c(this,zi));t.append(n)}c(this,Dt).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;c(this,Yr)||b(this,Yr,{contentsObj:c(this,zi),richText:c(this,Ui)}),t&&b(this,Gi,null),e&&(b(this,Ui,y(this,mt,Hb).call(this,e)),b(this,zi,null)),(s=c(this,Fs))==null||s.remove(),b(this,Fs,null)}resetEdited(){var t;c(this,Yr)&&({contentsObj:Fe(this,zi)._,richText:Fe(this,Ui)._}=c(this,Yr),b(this,Yr,null),(t=c(this,Fs))==null||t.remove(),b(this,Fs,null),b(this,Gi,null))}forceHide(){b(this,qr,this.isVisible),c(this,qr)&&(c(this,Dt).hidden=!0)}maybeShow(){c(this,qr)&&(c(this,Fs)||y(this,mt,Jd).call(this),b(this,qr,!1),c(this,Dt).hidden=!1)}get isVisible(){return c(this,Dt).hidden===!1}}ma=new WeakMap,Ld=new WeakMap,Fd=new WeakMap,ba=new WeakMap,Ur=new WeakMap,Dt=new WeakMap,zi=new WeakMap,va=new WeakMap,ol=new WeakMap,al=new WeakMap,ya=new WeakMap,Vi=new WeakMap,Fs=new WeakMap,Gi=new WeakMap,hl=new WeakMap,Ui=new WeakMap,ll=new WeakMap,Yr=new WeakMap,qr=new WeakMap,mt=new WeakSet,Kd=function(){const t=c(this,Ui),e=c(this,zi);return t!=null&&t.str&&(!(e!=null&&e.str)||e.str===t.str)&&c(this,Ui).html||null},kf=function(){var t,e,s;return((s=(e=(t=c(this,mt,Kd))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.fontSize)||0},Bb=function(){var t,e,s;return((s=(e=(t=c(this,mt,Kd))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.color)||null},Hb=function(t){const e=[],s={str:t,html:{name:"div",attributes:{dir:"auto"},children:[{name:"p",children:e}]}},i={style:{color:c(this,mt,Bb),fontSize:c(this,mt,kf)?`calc(${c(this,mt,kf)}px * var(--scale-factor))`:""}};for(const n of t.split(`
501
+ `))e.push({name:"span",value:n,attributes:i});return s},Wb=function(t){t.altKey||t.shiftKey||t.ctrlKey||t.metaKey||(t.key==="Enter"||t.key==="Escape"&&c(this,Vi))&&y(this,mt,Qd).call(this)},Xb=function(){if(c(this,Gi)!==null)return;const{page:{view:t},viewport:{rawDims:{pageWidth:e,pageHeight:s,pageX:i,pageY:n}}}=c(this,al);let r=!!c(this,ya),o=r?c(this,ya):c(this,hl);for(const p of c(this,ol))if(!o||X.intersect(p.data.rect,o)!==null){o=p.data.rect,r=!0;break}const h=X.normalizeRect([o[0],t[3]-o[1]+t[1],o[2],t[3]-o[3]+t[1]]),d=r?o[2]-o[0]+5:0,u=h[0]+d,g=h[1];b(this,Gi,[100*(u-i)/e,100*(g-n)/s]);const{style:f}=c(this,Dt);f.left=`${c(this,Gi)[0]}%`,f.top=`${c(this,Gi)[1]}%`},Qd=function(){b(this,Vi,!c(this,Vi)),c(this,Vi)?(y(this,mt,Jd).call(this),c(this,Dt).addEventListener("click",c(this,ba)),c(this,Dt).addEventListener("keydown",c(this,ma))):(y(this,mt,Mf).call(this),c(this,Dt).removeEventListener("click",c(this,ba)),c(this,Dt).removeEventListener("keydown",c(this,ma)))},Jd=function(){c(this,Fs)||this.render(),this.isVisible?c(this,Vi)&&c(this,Dt).classList.add("focused"):(y(this,mt,Xb).call(this),c(this,Dt).hidden=!1,c(this,Dt).style.zIndex=parseInt(c(this,Dt).style.zIndex)+1e3)},Mf=function(){c(this,Dt).classList.remove("focused"),!(c(this,Vi)||!this.isVisible)&&(c(this,Dt).hidden=!0,c(this,Dt).style.zIndex=parseInt(c(this,Dt).style.zIndex)-1e3)};class q0 extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.textContent=t.data.textContent,this.textPosition=t.data.textPosition,this.annotationEditorType=Z.FREETEXT}render(){if(this.container.classList.add("freeTextAnnotation"),this.textContent){const t=document.createElement("div");t.classList.add("annotationTextContent"),t.setAttribute("role","comment");for(const e of this.textContent){const s=document.createElement("span");s.textContent=e,t.append(s)}this.container.append(t)}return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this._editOnDoubleClick(),this.container}}class uS extends jt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});w(this,cl,null)}render(){this.container.classList.add("lineAnnotation");const e=this.data,{width:s,height:i}=Mi(e.rect),n=this.svgFactory.create(s,i,!0),r=b(this,cl,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 c(this,cl)}addHighlightArea(){this.container.classList.add("highlightArea")}}cl=new WeakMap;class gS extends jt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});w(this,dl,null)}render(){this.container.classList.add("squareAnnotation");const e=this.data,{width:s,height:i}=Mi(e.rect),n=this.svgFactory.create(s,i,!0),r=e.borderStyle.width,o=b(this,dl,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 c(this,dl)}addHighlightArea(){this.container.classList.add("highlightArea")}}dl=new WeakMap;class fS extends jt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});w(this,ul,null)}render(){this.container.classList.add("circleAnnotation");const e=this.data,{width:s,height:i}=Mi(e.rect),n=this.svgFactory.create(s,i,!0),r=e.borderStyle.width,o=b(this,ul,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 c(this,ul)}addHighlightArea(){this.container.classList.add("highlightArea")}}ul=new WeakMap;class $0 extends jt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});w(this,gl,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}=Mi(e),h=this.svgFactory.create(r,o,!0);let l=[];for(let u=0,g=s.length;u<g;u+=2){const f=s[u]-e[0],p=e[3]-s[u+1];l.push(`${f},${p}`)}l=l.join(" ");const d=b(this,gl,this.svgFactory.createElement(this.svgElementName));return d.setAttribute("points",l),d.setAttribute("stroke-width",i.width||1),d.setAttribute("stroke","transparent"),d.setAttribute("fill","transparent"),h.append(d),this.container.append(h),!n&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return c(this,gl)}addHighlightArea(){this.container.classList.add("highlightArea")}}gl=new WeakMap;class pS extends $0{constructor(t){super(t),this.containerClassName="polygonAnnotation",this.svgElementName="svg:polygon"}}class mS extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){return this.container.classList.add("caretAnnotation"),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container}}class Gg extends jt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});w(this,fl,[]);this.containerClassName="inkAnnotation",this.svgElementName="svg:polyline",this.annotationEditorType=this.data.it==="InkHighlight"?Z.HIGHLIGHT:Z.INK}render(){this.container.classList.add(this.containerClassName);const{data:{rect:e,inkLists:s,borderStyle:i,popupRef:n}}=this,{width:r,height:o}=Mi(e),h=this.svgFactory.create(r,o,!0);for(const l of s){let d=[];for(let g=0,f=l.length;g<f;g+=2){const p=l[g]-e[0],m=e[3]-l[g+1];d.push(`${p},${m}`)}d=d.join(" ");const u=this.svgFactory.createElement(this.svgElementName);c(this,fl).push(u),u.setAttribute("points",d),u.setAttribute("stroke-width",i.width||1),u.setAttribute("stroke","transparent"),u.setAttribute("fill","transparent"),h.append(u)}return!n&&this.hasPopupData&&this._createPopup(),this.container.append(h),this._editOnDoubleClick(),this.container}getElementsToTriggerPopup(){return c(this,fl)}addHighlightArea(){this.container.classList.add("highlightArea")}}fl=new WeakMap;class K0 extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0}),this.annotationEditorType=Z.HIGHLIGHT}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("highlightAnnotation"),this._editOnDoubleClick(),this.container}}class bS extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("underlineAnnotation"),this.container}}class vS extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("squigglyAnnotation"),this.container}}class yS extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("strikeoutAnnotation"),this.container}}class Q0 extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.annotationEditorType=Z.STAMP}render(){return this.container.classList.add("stampAnnotation"),this.container.setAttribute("role","img"),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this._editOnDoubleClick(),this.container}}class _S extends jt{constructor(e){var i;super(e,{isRenderable:!0});w(this,ml);w(this,pl,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",y(this,ml,Of).bind(this)),b(this,pl,i);const{isMac:n}=ke.platform;return e.addEventListener("keydown",r=>{r.key==="Enter"&&(n?r.metaKey:r.ctrlKey)&&y(this,ml,Of).call(this)}),!s.popupRef&&this.hasPopupData?this._createPopup():i.classList.add("popupTriggerArea"),e.append(i),e}getElementsToTriggerPopup(){return c(this,pl)}addHighlightArea(){this.container.classList.add("highlightArea")}}pl=new WeakMap,ml=new WeakSet,Of=function(){var e;(e=this.downloadManager)==null||e.openOrDownloadData(this.content,this.filename)};class wS{constructor({div:t,accessibilityManager:e,annotationCanvasMap:s,annotationEditorUIManager:i,page:n,viewport:r,structTreeLayer:o}){w(this,Qr);w(this,bl,null);w(this,$r,null);w(this,Kr,new Map);w(this,vl,null);this.div=t,b(this,bl,e),b(this,$r,s),b(this,vl,o||null),this.page=n,this.viewport=r,this.zIndex=0,this._annotationEditorUIManager=i}hasEditableAnnotations(){return c(this,Kr).size>0}async render(t){var r;const{annotations:e}=t,s=this.div;cr(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 zg,annotationStorage:t.annotationStorage||new Og,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===Gt.POPUP;if(h){const u=i.get(o.id);if(!u)continue;n.elements=u}else{const{width:u,height:g}=Mi(o.rect);if(u<=0||g<=0)continue}n.data=o;const l=nS.create(n);if(!l.isRenderable)continue;if(!h&&o.popupRef){const u=i.get(o.popupRef);u?u.push(l):i.set(o.popupRef,[l])}const d=l.render();o.hidden&&(d.style.visibility="hidden"),await y(this,Qr,zb).call(this,d,o.id),l._isEditable&&(c(this,Kr).set(l.data.id,l),(r=this._annotationEditorUIManager)==null||r.renderAnnotationElement(l))}y(this,Qr,Df).call(this)}update({viewport:t}){const e=this.div;this.viewport=t,cr(e,{rotation:t.rotation}),y(this,Qr,Df).call(this),e.hidden=!1}getEditableAnnotations(){return Array.from(c(this,Kr).values())}getEditableAnnotation(t){return c(this,Kr).get(t)}}bl=new WeakMap,$r=new WeakMap,Kr=new WeakMap,vl=new WeakMap,Qr=new WeakSet,zb=async function(t,e){var r,o;const s=t.firstChild||t,i=s.id=`${_g}${e}`,n=await((r=c(this,vl))==null?void 0:r.getAriaAttributes(i));if(n)for(const[h,l]of n)s.setAttribute(h,l);this.div.append(t),(o=c(this,bl))==null||o.moveElementInDOM(this.div,t,s,!1)},Df=function(){if(!c(this,$r))return;const t=this.div;for(const[e,s]of c(this,$r)){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)}c(this,$r).clear()};const pd=/\r\n?|\n/g,vt=class vt extends gt{constructor(e){super({...e,name:"freeTextEditor"});w(this,Wt);w(this,Rs);w(this,Ze,"");w(this,yl,`${this.id}-editor`);w(this,Jr,null);w(this,ts);b(this,Rs,e.color||vt._defaultColor||gt._defaultLineColor),b(this,ts,e.fontSize||vt._defaultFontSize)}static get _keyboardManager(){const e=vt.prototype,s=r=>r.isEmpty(),i=dr.TRANSLATE_SMALL,n=dr.TRANSLATE_BIG;return ot(this,"_keyboardManager",new fh([[["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){gt.initialize(e,s);const i=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(i.getPropertyValue("--freetext-padding"))}static updateDefaultParams(e,s){switch(e){case Y.FREETEXT_SIZE:vt._defaultFontSize=s;break;case Y.FREETEXT_COLOR:vt._defaultColor=s;break}}updateParams(e,s){switch(e){case Y.FREETEXT_SIZE:y(this,Wt,Vb).call(this,s);break;case Y.FREETEXT_COLOR:y(this,Wt,Gb).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[Y.FREETEXT_SIZE,vt._defaultFontSize],[Y.FREETEXT_COLOR,vt._defaultColor||gt._defaultLineColor]]}get propertiesToUpdate(){return[[Y.FREETEXT_SIZE,c(this,ts)],[Y.FREETEXT_COLOR,c(this,Rs)]]}_translateEmpty(e,s){this._uiManager.translateSelectedEditors(e,s,!0)}getInitialTranslation(){const e=this.parentScale;return[-vt._internalPadding*e,-(vt._internalPadding+c(this,ts))*e]}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.isAttachedToDOM||this.parent.add(this)))}enableEditMode(){if(this.isInEditMode())return;this.parent.setEditingState(!1),this.parent.updateToolbar(Z.FREETEXT),super.enableEditMode(),this.overlayDiv.classList.remove("enabled"),this.editorDiv.contentEditable=!0,this._isDraggable=!1,this.div.removeAttribute("aria-activedescendant"),b(this,Jr,new AbortController);const e=this._uiManager.combinedSignal(c(this,Jr));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",c(this,yl)),this._isDraggable=!0,(e=c(this,Jr))==null||e.abort(),b(this,Jr,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(){var e;this.width||(this.enableEditMode(),this.editorDiv.focus(),(e=this._initialOptions)!=null&&e.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=c(this,Ze),s=b(this,Ze,y(this,Wt,Ub).call(this).trimEnd());if(e===s)return;const i=n=>{if(b(this,Ze,n),!n){this.remove();return}y(this,Wt,eu).call(this),this._uiManager.rebuild(this),y(this,Wt,Zd).call(this)};this.addCommands({cmd:()=>{i(s)},undo:()=>{i(e)},mustExec:!1}),y(this,Wt,Zd).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){vt._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",c(this,yl)),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(${c(this,ts)}px * var(--scale-factor))`,i.color=c(this,Rs),this.div.append(this.editorDiv),this.overlayDiv=document.createElement("div"),this.overlayDiv.classList.add("overlay","enabled"),this.div.append(this.overlayDiv),hd(this,this.div,["dblclick","keydown"]),this.width){const[n,r]=this.parentDimensions;if(this.annotationElementId){const{position:o}=this._initialData;let[h,l]=this.getInitialTranslation();[h,l]=this.pageTranslationToScreen(h,l);const[d,u]=this.pageDimensions,[g,f]=this.pageTranslation;let p,m;switch(this.rotation){case 0:p=e+(o[0]-g)/d,m=s+this.height-(o[1]-f)/u;break;case 90:p=e+(o[0]-g)/d,m=s-(o[1]-f)/u,[h,l]=[l,-h];break;case 180:p=e-this.width+(o[0]-g)/d,m=s-(o[1]-f)/u,[h,l]=[-h,-l];break;case 270:p=e+(o[0]-g-this.height*u)/d,m=s+(o[1]-f-this.width*d)/u,[h,l]=[-l,h];break}this.setAt(p*n,m*r,h,l)}else this.setAt(e*n,s*r,this.width*n,this.height*r);y(this,Wt,eu).call(this),this._isDraggable=!0,this.editorDiv.contentEditable=!1}else this._isDraggable=!1,this.editorDiv.contentEditable=!0;return this.div}editorDivPaste(e){var p,m,_;const s=e.clipboardData||window.clipboardData,{types:i}=s;if(i.length===1&&i[0]==="text/plain")return;e.preventDefault();const n=y(p=vt,Yi,Pf).call(p,s.getData("text")||"").replaceAll(pd,`
502
502
  `);if(!n)return;const r=window.getSelection();if(!r.rangeCount)return;this.editorDiv.normalize(),r.deleteFromDocument();const o=r.getRangeAt(0);if(!n.includes(`
503
- `)){o.insertNode(document.createTextNode(n)),this.editorDiv.normalize(),r.collapseToStart();return}const{startContainer:h,startOffset:l}=o,d=[],u=[];if(h.nodeType===Node.TEXT_NODE){const v=h.parentElement;if(u.push(h.nodeValue.slice(l).replaceAll(fd,"")),v!==this.editorDiv){let x=d;for(const S of this.editorDiv.childNodes){if(S===v){x=u;continue}x.push(y(m=yt,Yi,Zd).call(m,S))}}d.push(h.nodeValue.slice(0,l).replaceAll(fd,""))}else if(h===this.editorDiv){let v=d,x=0;for(const S of this.editorDiv.childNodes)x++===l&&(v=u),v.push(y(w=yt,Yi,Zd).call(w,S))}b(this,Ze,`${d.join(`
503
+ `)){o.insertNode(document.createTextNode(n)),this.editorDiv.normalize(),r.collapseToStart();return}const{startContainer:h,startOffset:l}=o,d=[],u=[];if(h.nodeType===Node.TEXT_NODE){const v=h.parentElement;if(u.push(h.nodeValue.slice(l).replaceAll(pd,"")),v!==this.editorDiv){let x=d;for(const S of this.editorDiv.childNodes){if(S===v){x=u;continue}x.push(y(m=vt,Yi,tu).call(m,S))}}d.push(h.nodeValue.slice(0,l).replaceAll(pd,""))}else if(h===this.editorDiv){let v=d,x=0;for(const S of this.editorDiv.childNodes)x++===l&&(v=u),v.push(y(_=vt,Yi,tu).call(_,S))}b(this,Ze,`${d.join(`
504
504
  `)}${n}${u.join(`
505
- `)}`),y(this,Vt,tu).call(this);const g=new Range;let f=d.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(f<=x){g.setStart(v,f),g.setEnd(v,f);break}f-=x}r.removeAllRanges(),r.addRange(g)}get contentDiv(){return this.editorDiv}static async deserialize(e,s,i){var o;let n=null;if(e instanceof V0){const{data:{defaultAppearanceData:{fontSize:h,fontColor:l},rect:d,rotation:u,id:g,popupRef:f},textContent:p,textPosition:m,parent:{page:{pageNumber:w}}}=e;if(!p||p.length===0)return null;n=e={annotationType:tt.FREETEXT,color:Array.from(l),fontSize:h,value:p.join(`
506
- `),position:m,pageIndex:w-1,rect:d.slice(0),rotation:u,id:g,deleted:!1,popupRef:f}}const r=await super.deserialize(e,s,i);return b(r,ts,e.fontSize),b(r,Rs,V.makeHexColor(...e.color)),b(r,Ze,y(o=yt,Yi,Df).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=yt._internalPadding*this.parentScale,i=this.getRect(s,s),n=gt._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:c(this,Rs)),r={annotationType:tt.FREETEXT,color:n,fontSize:c(this,ts),value:y(this,Vt,Vb).call(this),pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?r:this.annotationElementId&&!y(this,Vt,Gb).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(${c(this,ts)}px * var(--scale-factor))`,i.color=c(this,Rs),s.replaceChildren();for(const r of c(this,Ze).split(`
507
- `)){const o=document.createElement("div");o.append(r?document.createTextNode(r):document.createElement("br")),s.append(o)}const n=yt._internalPadding*this.parentScale;return e.updateEdited({rect:this.getRect(n,n),popupContent:c(this,Ze)}),s}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}};Rs=new WeakMap,Ze=new WeakMap,vl=new WeakMap,Jr=new WeakMap,ts=new WeakMap,Vt=new WeakSet,Wb=function(e){const s=n=>{this.editorDiv.style.fontSize=`calc(${n}px * var(--scale-factor))`,this.translate(0,-(n-c(this,ts))*this.parentScale),b(this,ts,n),y(this,Vt,Jd).call(this)},i=c(this,ts);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:$.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})},Xb=function(e){const s=n=>{b(this,Rs,this.editorDiv.style.color=n)},i=c(this,Rs);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:$.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})},zb=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(y(i=yt,Yi,Zd).call(i,n)),s=n);return e.join(`
508
- `)},Jd=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()},Yi=new WeakSet,Zd=function(e){return(e.nodeType===Node.TEXT_NODE?e.nodeValue:e.innerText).replaceAll(fd,"")},tu=function(){if(this.editorDiv.replaceChildren(),!!c(this,Ze))for(const e of c(this,Ze).split(`
509
- `)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},Vb=function(){return c(this,Ze).replaceAll(" "," ")},Df=function(e){return e.replaceAll(" "," ")},Gb=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},_(yt,Yi),K(yt,"_freeTextDefaultContent",""),K(yt,"_internalPadding",0),K(yt,"_defaultColor",null),K(yt,"_defaultFontSize",10),K(yt,"_type","freetext"),K(yt,"_editorType",tt.FREETEXT);let Gg=yt;class q0{toSVGPath(){wt("Abstract method `toSVGPath` must be implemented.")}get box(){wt("Abstract getter `box` must be implemented.")}serialize(t,e){wt("Abstract method `serialize` must be implemented.")}get classNamesForDrawing(){wt("Abstract getter `classNamesForDrawing` must be implemented.")}get classNamesForOutlining(){wt("Abstract getter `classNamesForOutlining` must be implemented.")}get mustRemoveSelfIntersections(){return!1}}const qi=class qi{constructor({x:t,y:e},s,i,n,r,o=0){_(this,Qt);_(this,es);_(this,Is,[]);_(this,_a);_(this,wa);_(this,ai,[]);_(this,it,new Float64Array(18));_(this,Zr);_(this,to);_(this,yl);_(this,_l);_(this,xa);_(this,Sa);_(this,Nn,[]);b(this,es,s),b(this,Sa,n*i),b(this,wa,r),c(this,it).set([NaN,NaN,NaN,NaN,t,e],6),b(this,_a,o),b(this,_l,c(qi,wl)*i),b(this,yl,c(qi,Rd)*i),b(this,xa,i),c(this,Nn).push(t,e)}isEmpty(){return isNaN(c(this,it)[8])}add({x:t,y:e}){var R;b(this,Zr,t),b(this,to,e);const[s,i,n,r]=c(this,es);let[o,h,l,d]=c(this,it).subarray(8,12);const u=t-l,g=e-d,f=Math.hypot(u,g);if(f<c(this,yl))return!1;const p=f-c(this,_l),m=p/f,w=m*u,v=m*g;let x=o,S=h;o=l,h=d,l+=w,d+=v,(R=c(this,Nn))==null||R.push(t,e);const C=-v/p,E=w/p,k=C*c(this,Sa),P=E*c(this,Sa);return c(this,it).set(c(this,it).subarray(2,8),0),c(this,it).set([l+k,d+P],4),c(this,it).set(c(this,it).subarray(14,18),12),c(this,it).set([l-k,d-P],16),isNaN(c(this,it)[6])?(c(this,ai).length===0&&(c(this,it).set([o+k,h+P],2),c(this,ai).push(NaN,NaN,NaN,NaN,(o+k-s)/n,(h+P-i)/r),c(this,it).set([o-k,h-P],14),c(this,Is).push(NaN,NaN,NaN,NaN,(o-k-s)/n,(h-P-i)/r)),c(this,it).set([x,S,o,h,l,d],6),!this.isEmpty()):(c(this,it).set([x,S,o,h,l,d],6),Math.abs(Math.atan2(S-h,x-o)-Math.atan2(v,w))<Math.PI/2?([o,h,l,d]=c(this,it).subarray(2,6),c(this,ai).push(NaN,NaN,NaN,NaN,((o+l)/2-s)/n,((h+d)/2-i)/r),[o,h,x,S]=c(this,it).subarray(14,18),c(this,Is).push(NaN,NaN,NaN,NaN,((x+o)/2-s)/n,((S+h)/2-i)/r),!0):([x,S,o,h,l,d]=c(this,it).subarray(0,6),c(this,ai).push(((x+5*o)/6-s)/n,((S+5*h)/6-i)/r,((5*o+l)/6-s)/n,((5*h+d)/6-i)/r,((o+l)/2-s)/n,((h+d)/2-i)/r),[l,d,o,h,x,S]=c(this,it).subarray(12,18),c(this,Is).push(((x+5*o)/6-s)/n,((S+5*h)/6-i)/r,((5*o+l)/6-s)/n,((5*h+d)/6-i)/r,((o+l)/2-s)/n,((h+d)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=c(this,ai),e=c(this,Is);if(isNaN(c(this,it)[6])&&!this.isEmpty())return y(this,Qt,Ub).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]}`);y(this,Qt,qb).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 y(this,Qt,Yb).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new $0(t,e,s,i,n,r)}getOutlines(){var u;const t=c(this,ai),e=c(this,Is),s=c(this,it),[i,n,r,o]=c(this,es),h=new Float64Array((((u=c(this,Nn))==null?void 0:u.length)??0)+2);for(let g=0,f=h.length-2;g<f;g+=2)h[g]=(c(this,Nn)[g]-i)/r,h[g+1]=(c(this,Nn)[g+1]-n)/o;if(h[h.length-2]=(c(this,Zr)-i)/r,h[h.length-1]=(c(this,to)-n)/o,isNaN(s[6])&&!this.isEmpty())return y(this,Qt,$b).call(this,h);const l=new Float64Array(c(this,ai).length+24+c(this,Is).length);let d=t.length;for(let g=0;g<d;g+=2){if(isNaN(t[g])){l[g]=l[g+1]=NaN;continue}l[g]=t[g],l[g+1]=t[g+1]}d=y(this,Qt,Qb).call(this,l,d);for(let g=e.length-6;g>=6;g-=6)for(let f=0;f<6;f+=2){if(isNaN(e[g+f])){l[d]=l[d+1]=NaN,d+=2;continue}l[d]=e[g+f],l[d+1]=e[g+f+1],d+=2}return y(this,Qt,Kb).call(this,l,d),this.newFreeDrawOutline(l,h,c(this,es),c(this,xa),c(this,_a),c(this,wa))}};es=new WeakMap,Is=new WeakMap,_a=new WeakMap,wa=new WeakMap,ai=new WeakMap,it=new WeakMap,Zr=new WeakMap,to=new WeakMap,yl=new WeakMap,_l=new WeakMap,xa=new WeakMap,Sa=new WeakMap,Nn=new WeakMap,wl=new WeakMap,Fd=new WeakMap,Rd=new WeakMap,Qt=new WeakSet,Vl=function(){const t=c(this,it).subarray(4,6),e=c(this,it).subarray(16,18),[s,i,n,r]=c(this,es);return[(c(this,Zr)+(t[0]-e[0])/2-s)/n,(c(this,to)+(t[1]-e[1])/2-i)/r,(c(this,Zr)+(e[0]-t[0])/2-s)/n,(c(this,to)+(e[1]-t[1])/2-i)/r]},Ub=function(){const[t,e,s,i]=c(this,es),[n,r,o,h]=y(this,Qt,Vl).call(this);return`M${(c(this,it)[2]-t)/s} ${(c(this,it)[3]-e)/i} L${(c(this,it)[4]-t)/s} ${(c(this,it)[5]-e)/i} L${n} ${r} L${o} ${h} L${(c(this,it)[16]-t)/s} ${(c(this,it)[17]-e)/i} L${(c(this,it)[14]-t)/s} ${(c(this,it)[15]-e)/i} Z`},Yb=function(t){const e=c(this,Is);t.push(`L${e[4]} ${e[5]} Z`)},qb=function(t){const[e,s,i,n]=c(this,es),r=c(this,it).subarray(4,6),o=c(this,it).subarray(16,18),[h,l,d,u]=y(this,Qt,Vl).call(this);t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${h} ${l} L${d} ${u} L${(o[0]-e)/i} ${(o[1]-s)/n}`)},$b=function(t){const e=c(this,it),[s,i,n,r]=c(this,es),[o,h,l,d]=y(this,Qt,Vl).call(this),u=new Float64Array(36);return u.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,l,d,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(u,t,c(this,es),c(this,xa),c(this,_a),c(this,wa))},Kb=function(t,e){const s=c(this,Is);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},Qb=function(t,e){const s=c(this,it).subarray(4,6),i=c(this,it).subarray(16,18),[n,r,o,h]=c(this,es),[l,d,u,g]=y(this,Qt,Vl).call(this);return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/o,(s[1]-r)/h,NaN,NaN,NaN,NaN,l,d,NaN,NaN,NaN,NaN,u,g,NaN,NaN,NaN,NaN,(i[0]-n)/o,(i[1]-r)/h],e),e+=24},_(qi,wl,8),_(qi,Fd,2),_(qi,Rd,c(qi,wl)+c(qi,Fd));let pd=qi;class $0 extends q0{constructor(e,s,i,n,r,o){super();_(this,Xe);_(this,Ca);_(this,eo,null);_(this,$i);_(this,xl);_(this,ss);_(this,Sl);_(this,Ht);b(this,Ht,e),b(this,ss,s),b(this,Ca,i),b(this,Sl,n),b(this,$i,r),b(this,xl,o),y(this,Xe,Jb).call(this,o);const{x:h,y:l,width:d,height:u}=c(this,eo);for(let g=0,f=e.length;g<f;g+=2)e[g]=(e[g]-h)/d,e[g+1]=(e[g+1]-l)/u;for(let g=0,f=s.length;g<f;g+=2)s[g]=(s[g]-h)/d,s[g+1]=(s[g+1]-l)/u}toSVGPath(){const e=[`M${c(this,Ht)[4]} ${c(this,Ht)[5]}`];for(let s=6,i=c(this,Ht).length;s<i;s+=6){if(isNaN(c(this,Ht)[s])){e.push(`L${c(this,Ht)[s+4]} ${c(this,Ht)[s+5]}`);continue}e.push(`C${c(this,Ht)[s]} ${c(this,Ht)[s+1]} ${c(this,Ht)[s+2]} ${c(this,Ht)[s+3]} ${c(this,Ht)[s+4]} ${c(this,Ht)[s+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,s,i,n],r){const o=i-e,h=n-s;let l,d;switch(r){case 0:l=y(this,Xe,Gl).call(this,c(this,Ht),e,n,o,-h),d=y(this,Xe,Gl).call(this,c(this,ss),e,n,o,-h);break;case 90:l=y(this,Xe,Ul).call(this,c(this,Ht),e,s,o,h),d=y(this,Xe,Ul).call(this,c(this,ss),e,s,o,h);break;case 180:l=y(this,Xe,Gl).call(this,c(this,Ht),i,s,-o,h),d=y(this,Xe,Gl).call(this,c(this,ss),i,s,-o,h);break;case 270:l=y(this,Xe,Ul).call(this,c(this,Ht),i,n,-o,-h),d=y(this,Xe,Ul).call(this,c(this,ss),i,n,-o,-h);break}return{outline:Array.from(l),points:[Array.from(d)]}}get box(){return c(this,eo)}newOutliner(e,s,i,n,r,o=0){return new pd(e,s,i,n,r,o)}getNewOutline(e,s){const{x:i,y:n,width:r,height:o}=c(this,eo),[h,l,d,u]=c(this,Ca),g=r*d,f=o*u,p=i*d+h,m=n*u+l,w=this.newOutliner({x:c(this,ss)[0]*g+p,y:c(this,ss)[1]*f+m},c(this,Ca),c(this,Sl),e,c(this,xl),s??c(this,$i));for(let v=2;v<c(this,ss).length;v+=2)w.add({x:c(this,ss)[v]*g+p,y:c(this,ss)[v+1]*f+m});return w.getOutlines()}get mustRemoveSelfIntersections(){return!0}}Ca=new WeakMap,eo=new WeakMap,$i=new WeakMap,xl=new WeakMap,ss=new WeakMap,Sl=new WeakMap,Ht=new WeakMap,Xe=new WeakSet,Gl=function(e,s,i,n,r){const o=new Float64Array(e.length);for(let h=0,l=e.length;h<l;h+=2)o[h]=s+e[h]*n,o[h+1]=i+e[h+1]*r;return o},Ul=function(e,s,i,n,r){const o=new Float64Array(e.length);for(let h=0,l=e.length;h<l;h+=2)o[h]=s+e[h+1]*n,o[h+1]=i+e[h]*r;return o},Jb=function(e){const s=c(this,Ht);let i=s[4],n=s[5],r=i,o=n,h=i,l=n,d=i,u=n;const g=e?Math.max:Math.min;for(let v=6,x=s.length;v<x;v+=6){if(isNaN(s[v]))r=Math.min(r,s[v+4]),o=Math.min(o,s[v+5]),h=Math.max(h,s[v+4]),l=Math.max(l,s[v+5]),u<s[v+5]?(d=s[v+4],u=s[v+5]):u===s[v+5]&&(d=g(d,s[v+4]));else{const S=V.bezierBoundingBox(i,n,...s.slice(v,v+6));r=Math.min(r,S[0]),o=Math.min(o,S[1]),h=Math.max(h,S[2]),l=Math.max(l,S[3]),u<S[3]?(d=S[2],u=S[3]):u===S[3]&&(d=g(d,S[2]))}i=s[v+4],n=s[v+5]}const f=r-c(this,$i),p=o-c(this,$i),m=h-r+2*c(this,$i),w=l-o+2*c(this,$i);b(this,eo,{x:f,y:p,width:m,height:w,lastPoint:[d,u]})};class K0{constructor(t,e=0,s=0,i=!0){_(this,Pe);_(this,Cl);_(this,Bn,[]);_(this,js,[]);let n=1/0,r=-1/0,o=1/0,h=-1/0;const d=10**-4;for(const{x:v,y:x,width:S,height:C}of t){const E=Math.floor((v-e)/d)*d,k=Math.ceil((v+S+e)/d)*d,P=Math.floor((x-e)/d)*d,D=Math.ceil((x+C+e)/d)*d,R=[E,P,D,!0],B=[k,P,D,!1];c(this,Bn).push(R,B),n=Math.min(n,E),r=Math.max(r,k),o=Math.min(o,P),h=Math.max(h,D)}const u=r-n+2*s,g=h-o+2*s,f=n-s,p=o-s,m=c(this,Bn).at(i?-1:-2),w=[m[0],m[2]];for(const v of c(this,Bn)){const[x,S,C]=v;v[0]=(x-f)/u,v[1]=(S-p)/g,v[2]=(C-p)/g}b(this,Cl,{x:f,y:p,width:u,height:g,lastPoint:w})}getOutlines(){c(this,Bn).sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of c(this,Bn))e[3]?(t.push(...y(this,Pe,Pf).call(this,e)),y(this,Pe,tv).call(this,e)):(y(this,Pe,ev).call(this,e),t.push(...y(this,Pe,Pf).call(this,e)));return y(this,Pe,Zb).call(this,t)}}Cl=new WeakMap,Bn=new WeakMap,js=new WeakMap,Pe=new WeakSet,Zb=function(t){const e=[],s=new Set;for(const r of t){const[o,h,l]=r;e.push([o,h,r],[o,l,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],l=e[r+1][2];h.push(l),l.push(h),s.add(h),s.add(l)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[o,h,l,d,u]=r;s.delete(r);let g=o,f=h;for(n=[o,l],i.push(n);;){let p;if(s.has(d))p=d;else if(s.has(u))p=u;else break;s.delete(p),[o,h,l,d,u]=p,g!==o&&(n.push(g,f,o,f===h?h:l),g=o),f=f===h?l:h}n.push(g,f)}return new eS(i,c(this,Cl))},eu=function(t){const e=c(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},tv=function([,t,e]){const s=y(this,Pe,eu).call(this,t);c(this,js).splice(s,0,[t,e])},ev=function([,t,e]){const s=y(this,Pe,eu).call(this,t);for(let i=s;i<c(this,js).length;i++){const[n,r]=c(this,js)[i];if(n!==t)break;if(n===t&&r===e){c(this,js).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=c(this,js)[i];if(n!==t)break;if(n===t&&r===e){c(this,js).splice(i,1);return}}},Pf=function(t){const[e,s,i]=t,n=[[e,s,i]],r=y(this,Pe,eu).call(this,i);for(let o=0;o<r;o++){const[h,l]=c(this,js)[o];for(let d=0,u=n.length;d<u;d++){const[,g,f]=n[d];if(!(l<=g||f<=h)){if(g>=h){if(f>l)n[d][1]=l;else{if(u===1)return[];n.splice(d,1),d--,u--}continue}n[d][2]=h,f>l&&n.push([e,l,f])}}}return n};class eS extends q0{constructor(e,s){super();_(this,Al);_(this,Aa);b(this,Aa,e),b(this,Al,s)}toSVGPath(){const e=[];for(const s of c(this,Aa)){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,l=n-s;for(const d of c(this,Aa)){const u=new Array(d.length);for(let g=0;g<d.length;g+=2)u[g]=e+d[g]*h,u[g+1]=n-d[g+1]*l;o.push(u)}return o}get box(){return c(this,Al)}get classNamesForDrawing(){return["highlight"]}get classNamesForOutlining(){return["highlightOutline"]}}Al=new WeakMap,Aa=new WeakMap;class Ug extends pd{newFreeDrawOutline(t,e,s,i,n,r){return new sS(t,e,s,i,n,r)}get classNamesForDrawing(){return["highlight","free"]}}class sS extends $0{get classNamesForDrawing(){return["highlight","free"]}get classNamesForOutlining(){return["highlightOutline","free"]}newOutliner(t,e,s,i,n,r=0){return new Ug(t,e,s,i,n,r)}}const ze=class ze{constructor({editor:t=null,uiManager:e=null}){_(this,bt);_(this,Ns,null);_(this,so,null);_(this,Ta);_(this,Jt,null);_(this,Tl,!1);_(this,Ea,!1);_(this,El,null);_(this,kl);_(this,Hn,null);_(this,Bs,null);_(this,ka);var s;t?(b(this,Ea,!1),b(this,ka,$.HIGHLIGHT_COLOR),b(this,El,t)):(b(this,Ea,!0),b(this,ka,$.HIGHLIGHT_DEFAULT_COLOR)),b(this,Bs,(t==null?void 0:t._uiManager)||e),b(this,kl,c(this,Bs)._eventBus),b(this,Ta,(t==null?void 0:t.color)||((s=c(this,Bs))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),c(ze,Ml)||b(ze,Ml,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 ot(this,"_keyboardManager",new gh([[["Escape","mac+Escape"],ze.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],ze.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],ze.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],ze.prototype._moveToPrevious],[["Home","mac+Home"],ze.prototype._moveToBeginning],[["End","mac+End"],ze.prototype._moveToEnd]]))}renderButton(){const t=b(this,Ns,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=c(this,Bs)._signal;t.addEventListener("click",y(this,bt,vo).bind(this),{signal:e}),t.addEventListener("keydown",y(this,bt,Rf).bind(this),{signal:e});const s=b(this,so,document.createElement("span"));return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=c(this,Ta),t.append(s),t}renderMainDropdown(){const t=b(this,Jt,y(this,bt,Lf).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===c(this,Ns)){y(this,bt,vo).call(this,t);return}const e=t.target.getAttribute("data-color");e&&y(this,bt,Ff).call(this,e,t)}_moveToNext(t){var e,s;if(!c(this,bt,qn)){y(this,bt,vo).call(this,t);return}if(t.target===c(this,Ns)){(e=c(this,Jt).firstChild)==null||e.focus();return}(s=t.target.nextSibling)==null||s.focus()}_moveToPrevious(t){var e,s;if(t.target===((e=c(this,Jt))==null?void 0:e.firstChild)||t.target===c(this,Ns)){c(this,bt,qn)&&this._hideDropdownFromKeyboard();return}c(this,bt,qn)||y(this,bt,vo).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!c(this,bt,qn)){y(this,bt,vo).call(this,t);return}(e=c(this,Jt).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!c(this,bt,qn)){y(this,bt,vo).call(this,t);return}(e=c(this,Jt).lastChild)==null||e.focus()}hideDropdown(){var t,e;(t=c(this,Jt))==null||t.classList.add("hidden"),(e=c(this,Hn))==null||e.abort(),b(this,Hn,null)}_hideDropdownFromKeyboard(){var t;if(!c(this,Ea)){if(!c(this,bt,qn)){(t=c(this,El))==null||t.unselect();return}this.hideDropdown(),c(this,Ns).focus({preventScroll:!0,focusVisible:c(this,Tl)})}}updateColor(t){if(c(this,so)&&(c(this,so).style.backgroundColor=t),!c(this,Jt))return;const e=c(this,Bs).highlightColors.values();for(const s of c(this,Jt).children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){var t,e;(t=c(this,Ns))==null||t.remove(),b(this,Ns,null),b(this,so,null),(e=c(this,Jt))==null||e.remove(),b(this,Jt,null)}};Ns=new WeakMap,so=new WeakMap,Ta=new WeakMap,Jt=new WeakMap,Tl=new WeakMap,Ea=new WeakMap,El=new WeakMap,kl=new WeakMap,Hn=new WeakMap,Bs=new WeakMap,ka=new WeakMap,Ml=new WeakMap,bt=new WeakSet,Lf=function(){const t=document.createElement("div"),e=c(this,Bs)._signal;t.addEventListener("contextmenu",as,{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 c(this,Bs).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",c(ze,Ml)[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===c(this,Ta)),n.addEventListener("click",y(this,bt,Ff).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",y(this,bt,Rf).bind(this),{signal:e}),t},Ff=function(t,e){e.stopPropagation(),c(this,kl).dispatch("switchannotationeditorparams",{source:this,type:c(this,ka),value:t})},Rf=function(t){ze._keyboardManager.exec(this,t)},vo=function(t){if(c(this,bt,qn)){this.hideDropdown();return}if(b(this,Tl,t.detail===0),c(this,Hn)||(b(this,Hn,new AbortController),window.addEventListener("pointerdown",y(this,bt,sv).bind(this),{signal:c(this,Bs).combinedSignal(c(this,Hn))})),c(this,Jt)){c(this,Jt).classList.remove("hidden");return}const e=b(this,Jt,y(this,bt,Lf).call(this));c(this,Ns).append(e)},sv=function(t){var e;(e=c(this,Jt))!=null&&e.contains(t.target)||this.hideDropdown()},qn=function(){return c(this,Jt)&&!c(this,Jt).classList.contains("hidden")},_(ze,Ml,null);let md=ze;const ht=class ht extends gt{constructor(e){super({...e,name:"highlightEditor"});_(this,Z);_(this,Ma,null);_(this,Ol,0);_(this,Ki);_(this,io,null);_(this,Oa,null);_(this,fs,null);_(this,Dl,null);_(this,Pl,0);_(this,no,null);_(this,Hs,null);_(this,ye,null);_(this,Ve,!1);_(this,Da,null);_(this,Qi);_(this,Zt,null);_(this,Pa,"");_(this,ps);_(this,Ll,"");this.color=e.color||ht._defaultColor,b(this,ps,e.thickness||ht._defaultThickness),b(this,Qi,e.opacity||ht._defaultOpacity),b(this,Ki,e.boxes||null),b(this,Ll,e.methodOfCreation||""),b(this,Pa,e.text||""),this._isDraggable=!1,e.highlightId>-1?(b(this,Ve,!0),y(this,Z,su).call(this,e),y(this,Z,yo).call(this)):c(this,Ki)&&(b(this,Ma,e.anchorNode),b(this,Ol,e.anchorOffset),b(this,Dl,e.focusNode),b(this,Pl,e.focusOffset),y(this,Z,If).call(this),y(this,Z,yo).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=ht.prototype;return ot(this,"_keyboardManager",new gh([[["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:c(this,Ve)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:c(this,ps),methodOfCreation:c(this,Ll)}}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;gt.initialize(e,s),ht._defaultColor||(ht._defaultColor=((i=s.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,s){switch(e){case $.HIGHLIGHT_DEFAULT_COLOR:ht._defaultColor=s;break;case $.HIGHLIGHT_THICKNESS:ht._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return c(this,Da)}updateParams(e,s){switch(e){case $.HIGHLIGHT_COLOR:y(this,Z,iv).call(this,s);break;case $.HIGHLIGHT_THICKNESS:y(this,Z,nv).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[$.HIGHLIGHT_DEFAULT_COLOR,ht._defaultColor],[$.HIGHLIGHT_THICKNESS,ht._defaultThickness]]}get propertiesToUpdate(){return[[$.HIGHLIGHT_COLOR,this.color||ht._defaultColor],[$.HIGHLIGHT_THICKNESS,c(this,ps)||ht._defaultThickness],[$.HIGHLIGHT_FREE,c(this,Ve)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(b(this,Oa,new md({editor:this})),e.addColorPicker(c(this,Oa))),e):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(y(this,Z,Yl).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,y(this,Z,Yl).call(this))}onceAdded(){this.annotationElementId||this.parent.addUndoableEditor(this),this.div.focus()}remove(){y(this,Z,jf).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(y(this,Z,yo).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?y(this,Z,jf).call(this):e&&(y(this,Z,yo).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;c(this,Ve)?(e=(e-this.rotation+360)%360,i=y(n=ht,ms,Va).call(n,c(this,Hs).box,e)):i=y(r=ht,ms,Va).call(r,this,e),s.rotate(c(this,ye),e),s.rotate(c(this,Zt),e),s.updateBox(c(this,ye),i),s.updateBox(c(this,Zt),y(o=ht,ms,Va).call(o,c(this,fs).box,e))}render(){if(this.div)return this.div;const e=super.render();c(this,Pa)&&(e.setAttribute("aria-label",c(this,Pa)),e.setAttribute("role","mark")),c(this,Ve)?e.classList.add("free"):this.div.addEventListener("keydown",y(this,Z,ov).bind(this),{signal:this._uiManager._signal});const s=b(this,no,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=c(this,io);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),ad(this,c(this,no),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){this.isSelected||this.parent.drawLayer.addClass(c(this,Zt),"hovered")}pointerleave(){this.isSelected||this.parent.drawLayer.removeClass(c(this,Zt),"hovered")}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:y(this,Z,iu).call(this,!0);break;case 1:case 3:y(this,Z,iu).call(this,!1);break}}select(){var e,s;super.select(),c(this,Zt)&&((e=this.parent)==null||e.drawLayer.removeClass(c(this,Zt),"hovered"),(s=this.parent)==null||s.drawLayer.addClass(c(this,Zt),"selected"))}unselect(){var e;super.unselect(),c(this,Zt)&&((e=this.parent)==null||e.drawLayer.removeClass(c(this,Zt),"selected"),c(this,Ve)||y(this,Z,iu).call(this,!1))}get _mustFixPosition(){return!c(this,Ve)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.show(c(this,ye),e),this.parent.drawLayer.show(c(this,Zt),e))}static startHighlighting(e,s,{target:i,x:n,y:r}){const{x:o,y:h,width:l,height:d}=i.getBoundingClientRect(),u=new AbortController,g=e.combinedSignal(u),f=m=>{m.preventDefault(),m.stopPropagation()},p=m=>{u.abort(),y(this,ms,cv).call(this,e,m)};window.addEventListener("blur",p,{signal:g}),window.addEventListener("pointerup",p,{signal:g}),window.addEventListener("pointerdown",f,{capture:!0,passive:!1,signal:g}),window.addEventListener("contextmenu",as,{signal:g}),i.addEventListener("pointermove",y(this,ms,lv).bind(this,e),{signal:g}),this._freeHighlight=new Ug({x:n,y:r},[o,h,l,d],e.scale,this._defaultThickness/2,s,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw(this._freeHighlight,this._defaultColor,this._defaultOpacity,!0)}static async deserialize(e,s,i){var m,w,v,x;let n=null;if(e instanceof U0){const{data:{quadPoints:S,rect:C,rotation:E,id:k,color:P,opacity:D,popupRef:R},parent:{page:{pageNumber:B}}}=e;n=e={annotationType:tt.HIGHLIGHT,color:Array.from(P),opacity:D,quadPoints:S,boxes:null,pageIndex:B-1,rect:C.slice(0),rotation:E,id:k,deleted:!1,popupRef:R}}else if(e instanceof Vg){const{data:{inkLists:S,rect:C,rotation:E,id:k,color:P,borderStyle:{rawWidth:D},popupRef:R},parent:{page:{pageNumber:B}}}=e;n=e={annotationType:tt.HIGHLIGHT,color:Array.from(P),thickness:D,inkLists:S,boxes:null,pageIndex:B-1,rect:C.slice(0),rotation:E,id:k,deleted:!1,popupRef:R}}const{color:r,quadPoints:o,inkLists:h,opacity:l}=e,d=await super.deserialize(e,s,i);d.color=V.makeHexColor(...r),b(d,Qi,l||1),h&&b(d,ps,e.thickness),d.annotationElementId=e.id||null,d._initialData=n;const[u,g]=d.pageDimensions,[f,p]=d.pageTranslation;if(o){const S=b(d,Ki,[]);for(let C=0;C<o.length;C+=8)S.push({x:(o[C]-f)/u,y:1-(o[C+1]-p)/g,width:(o[C+2]-o[C])/u,height:(o[C+1]-o[C+5])/g});y(m=d,Z,If).call(m),y(w=d,Z,yo).call(w),d.rotate(d.rotation)}else if(h){b(d,Ve,!0);const S=h[0],C={x:S[0]-f,y:g-(S[1]-p)},E=new Ug(C,[0,0,u,g],1,c(d,ps)/2,!0,.001);for(let D=0,R=S.length;D<R;D+=2)C.x=S[D]-f,C.y=g-(S[D+1]-p),E.add(C);const{id:k,clipPathId:P}=s.drawLayer.draw(E,d.color,d._defaultOpacity,!0);y(v=d,Z,su).call(v,{highlightOutlines:E.getOutlines(),highlightId:k,clipPathId:P}),y(x=d,Z,yo).call(x)}return d}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();const s=this.getRect(0,0),i=gt._colorManager.convert(this.color),n={annotationType:tt.HIGHLIGHT,color:i,opacity:c(this,Qi),thickness:c(this,ps),quadPoints:y(this,Z,av).call(this),outlines:y(this,Z,hv).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:y(this,Z,Yl).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!y(this,Z,dv).call(this,n)?null:(n.id=this.annotationElementId,n)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};Ma=new WeakMap,Ol=new WeakMap,Ki=new WeakMap,io=new WeakMap,Oa=new WeakMap,fs=new WeakMap,Dl=new WeakMap,Pl=new WeakMap,no=new WeakMap,Hs=new WeakMap,ye=new WeakMap,Ve=new WeakMap,Da=new WeakMap,Qi=new WeakMap,Zt=new WeakMap,Pa=new WeakMap,ps=new WeakMap,Ll=new WeakMap,Z=new WeakSet,If=function(){const e=new K0(c(this,Ki),.001);b(this,Hs,e.getOutlines()),{x:this.x,y:this.y,width:this.width,height:this.height}=c(this,Hs).box;const s=new K0(c(this,Ki),.0025,.001,this._uiManager.direction==="ltr");b(this,fs,s.getOutlines());const{lastPoint:i}=c(this,fs).box;b(this,Da,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height])},su=function({highlightOutlines:e,highlightId:s,clipPathId:i}){var u,g;if(b(this,Hs,e),b(this,fs,e.getNewOutline(c(this,ps)/2+1.5,.0025)),s>=0)b(this,ye,s),b(this,io,i),this.parent.drawLayer.finalizeLine(s,e),b(this,Zt,this.parent.drawLayer.drawOutline(c(this,fs)));else if(this.parent){const f=this.parent.viewport.rotation;this.parent.drawLayer.updateLine(c(this,ye),e),this.parent.drawLayer.updateBox(c(this,ye),y(u=ht,ms,Va).call(u,c(this,Hs).box,(f-this.rotation+360)%360)),this.parent.drawLayer.updateLine(c(this,Zt),c(this,fs)),this.parent.drawLayer.updateBox(c(this,Zt),y(g=ht,ms,Va).call(g,c(this,fs).box,f))}const{x:r,y:o,width:h,height:l}=e.box;switch(this.rotation){case 0:this.x=r,this.y=o,this.width=h,this.height=l;break;case 90:{const[f,p]=this.parentDimensions;this.x=o,this.y=1-r,this.width=h*p/f,this.height=l*f/p;break}case 180:this.x=1-r,this.y=1-o,this.width=h,this.height=l;break;case 270:{const[f,p]=this.parentDimensions;this.x=1-o,this.y=r,this.width=h*p/f,this.height=l*f/p;break}}const{lastPoint:d}=c(this,fs).box;b(this,Da,[(d[0]-r)/h,(d[1]-o)/l])},iv=function(e){const s=(r,o)=>{var h,l,d;this.color=r,(h=this.parent)==null||h.drawLayer.changeColor(c(this,ye),r),(l=c(this,Oa))==null||l.updateColor(r),b(this,Qi,o),(d=this.parent)==null||d.drawLayer.changeOpacity(c(this,ye),o)},i=this.color,n=c(this,Qi);this.addCommands({cmd:s.bind(this,e,ht._defaultOpacity),undo:s.bind(this,i,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:$.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},nv=function(e){const s=c(this,ps),i=n=>{b(this,ps,n),y(this,Z,rv).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:$.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},rv=function(e){if(!c(this,Ve))return;y(this,Z,su).call(this,{highlightOutlines:c(this,Hs).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},jf=function(){c(this,ye)===null||!this.parent||(this.parent.drawLayer.remove(c(this,ye)),b(this,ye,null),this.parent.drawLayer.remove(c(this,Zt)),b(this,Zt,null))},yo=function(e=this.parent){c(this,ye)===null&&({id:Fe(this,ye)._,clipPathId:Fe(this,io)._}=e.drawLayer.draw(c(this,Hs),this.color,c(this,Qi)),b(this,Zt,e.drawLayer.drawOutline(c(this,fs))),c(this,no)&&(c(this,no).style.clipPath=c(this,io)))},ms=new WeakSet,Va=function({x:e,y:s,width:i,height:n},r){switch(r){case 90:return{x:1-s-n,y:e,width:n,height:i};case 180:return{x:1-e-i,y:1-s-n,width:i,height:n};case 270:return{x:s,y:1-e-i,width:n,height:i}}return{x:e,y:s,width:i,height:n}},ov=function(e){ht._keyboardManager.exec(this,e)},iu=function(e){if(!c(this,Ma))return;const s=window.getSelection();e?s.setPosition(c(this,Ma),c(this,Ol)):s.setPosition(c(this,Dl),c(this,Pl))},Yl=function(){return c(this,Ve)?this.rotation:0},av=function(){if(c(this,Ve))return null;const[e,s]=this.pageDimensions,[i,n]=this.pageTranslation,r=c(this,Ki),o=new Float32Array(r.length*8);let h=0;for(const{x:l,y:d,width:u,height:g}of r){const f=l*e+i,p=(1-d-g)*s+n;o[h]=o[h+4]=f,o[h+1]=o[h+3]=p,o[h+2]=o[h+6]=f+u*e,o[h+5]=o[h+7]=p+g*s,h+=8}return o},hv=function(e){return c(this,Hs).serialize(e,y(this,Z,Yl).call(this))},lv=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updatePath(this._freeHighlightId,this._freeHighlight)},cv=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=""},dv=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},_(ht,ms),K(ht,"_defaultColor",null),K(ht,"_defaultOpacity",1),K(ht,"_defaultThickness",12),K(ht,"_type","highlight"),K(ht,"_editorType",tt.HIGHLIGHT),K(ht,"_freeHighlightId",-1),K(ht,"_freeHighlight",null),K(ht,"_freeHighlightClipId","");let bd=ht;const Mt=class Mt extends gt{constructor(e){super({...e,name:"inkEditor"});_(this,j);_(this,ro,0);_(this,oo,0);_(this,hi,null);_(this,Ji,new Path2D);_(this,bs,!1);_(this,ao,null);_(this,ho,!1);_(this,lo,!1);_(this,Zi,null);_(this,La,null);_(this,co,0);_(this,uo,0);_(this,Wn,null);this.color=e.color||null,this.thickness=e.thickness||null,this.opacity=e.opacity||null,this.paths=[],this.bezierPath2D=[],this.allRawPaths=[],this.currentPath=[],this.scaleFactor=1,this.translationX=this.translationY=0,this.x=0,this.y=0,this._willKeepAspectRatio=!0}static initialize(e,s){gt.initialize(e,s)}static updateDefaultParams(e,s){switch(e){case $.INK_THICKNESS:Mt._defaultThickness=s;break;case $.INK_COLOR:Mt._defaultColor=s;break;case $.INK_OPACITY:Mt._defaultOpacity=s/100;break}}updateParams(e,s){switch(e){case $.INK_THICKNESS:y(this,j,uv).call(this,s);break;case $.INK_COLOR:y(this,j,gv).call(this,s);break;case $.INK_OPACITY:y(this,j,fv).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[$.INK_THICKNESS,Mt._defaultThickness],[$.INK_COLOR,Mt._defaultColor||gt._defaultLineColor],[$.INK_OPACITY,Math.round(Mt._defaultOpacity*100)]]}get propertiesToUpdate(){return[[$.INK_THICKNESS,this.thickness||Mt._defaultThickness],[$.INK_COLOR,this.color||Mt._defaultColor||gt._defaultLineColor],[$.INK_OPACITY,Math.round(100*(this.opacity??Mt._defaultOpacity))]]}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.canvas||(y(this,j,nu).call(this),y(this,j,ru).call(this)),this.isAttachedToDOM||(this.parent.add(this),y(this,j,Ga).call(this)),y(this,j,ql).call(this)))}remove(){var e;this.canvas!==null&&(this.isEmpty()||this.commit(),this.canvas.width=this.canvas.height=0,this.canvas.remove(),this.canvas=null,c(this,hi)&&(clearTimeout(c(this,hi)),b(this,hi,null)),(e=c(this,Zi))==null||e.disconnect(),b(this,Zi,null),super.remove())}setParent(e){!this.parent&&e?this._uiManager.removeShouldRescale(this):this.parent&&e===null&&this._uiManager.addShouldRescale(this),super.setParent(e)}onScaleChanging(){const[e,s]=this.parentDimensions,i=this.width*e,n=this.height*s;this.setDimensions(i,n)}enableEditMode(){c(this,bs)||this.canvas===null||(super.enableEditMode(),this._isDraggable=!1,y(this,j,Hf).call(this))}disableEditMode(){!this.isInEditMode()||this.canvas===null||(super.disableEditMode(),this._isDraggable=!this.isEmpty(),this.div.classList.remove("editing"),y(this,j,Wf).call(this))}onceAdded(){this._isDraggable=!this.isEmpty()}isEmpty(){return this.paths.length===0||this.paths.length===1&&this.paths[0].length===0}commit(){c(this,bs)||(super.commit(),this.isEditing=!1,this.disableEditMode(),this.setInForeground(),b(this,bs,!0),this.div.classList.add("disabled"),y(this,j,ql).call(this,!0),this.select(),this.parent.addInkEditorIfNeeded(!0),this.moveInDOM(),this.div.focus({preventScroll:!0}))}focusin(e){this._focusEventsAllowed&&(super.focusin(e),this.enableEditMode())}canvasPointerdown(e){e.button!==0||!this.isInEditMode()||c(this,bs)||(this.setInForeground(),e.preventDefault(),this.div.contains(document.activeElement)||this.div.focus({preventScroll:!0}),y(this,j,mv).call(this,e.offsetX,e.offsetY))}canvasPointermove(e){e.preventDefault(),y(this,j,Bf).call(this,e.offsetX,e.offsetY)}canvasPointerup(e){e.preventDefault(),y(this,j,Xf).call(this,e)}canvasPointerleave(e){y(this,j,Xf).call(this,e)}get isResizable(){return!this.isEmpty()&&c(this,bs)}render(){if(this.div)return this.div;let e,s;this.width&&(e=this.x,s=this.y),super.render(),this.div.setAttribute("data-l10n-id","pdfjs-ink");const[i,n,r,o]=y(this,j,pv).call(this);if(this.setAt(i,n,0,0),this.setDims(r,o),y(this,j,nu).call(this),this.width){const[h,l]=this.parentDimensions;this.setAspectRatio(this.width*h,this.height*l),this.setAt(e*h,s*l,this.width*h,this.height*l),b(this,lo,!0),y(this,j,Ga).call(this),this.setDims(this.width*h,this.height*l),y(this,j,_o).call(this),this.div.classList.add("disabled")}else this.div.classList.add("editing"),this.enableEditMode();return y(this,j,ru).call(this),this.div}setDimensions(e,s){const i=Math.round(e),n=Math.round(s);if(c(this,co)===i&&c(this,uo)===n)return;b(this,co,i),b(this,uo,n),this.canvas.style.visibility="hidden";const[r,o]=this.parentDimensions;this.width=e/r,this.height=s/o,this.fixAndSetPosition(),c(this,bs)&&y(this,j,zf).call(this,e,s),y(this,j,Ga).call(this),y(this,j,_o).call(this),this.canvas.style.visibility="visible",this.fixDims()}static async deserialize(e,s,i){var w,v,x;if(e instanceof Vg)return null;const n=await super.deserialize(e,s,i);n.thickness=e.thickness,n.color=V.makeHexColor(...e.color),n.opacity=e.opacity;const[r,o]=n.pageDimensions,h=n.width*r,l=n.height*o,d=n.parentScale,u=e.thickness/2;b(n,bs,!0),b(n,co,Math.round(h)),b(n,uo,Math.round(l));const{paths:g,rect:f,rotation:p}=e;for(let{bezier:S}of g){S=y(w=Mt,tn,Sv).call(w,S,f,p);const C=[];n.paths.push(C);let E=d*(S[0]-u),k=d*(S[1]-u);for(let D=2,R=S.length;D<R;D+=6){const B=d*(S[D]-u),O=d*(S[D+1]-u),F=d*(S[D+2]-u),L=d*(S[D+3]-u),I=d*(S[D+4]-u),G=d*(S[D+5]-u);C.push([[E,k],[B,O],[F,L],[I,G]]),E=I,k=G}const P=y(this,tn,xv).call(this,C);n.bezierPath2D.push(P)}const m=y(v=n,j,Gf).call(v);return b(n,oo,Math.max(gt.MIN_SIZE,m[2]-m[0])),b(n,ro,Math.max(gt.MIN_SIZE,m[3]-m[1])),y(x=n,j,zf).call(x,h,l),n}serialize(){if(this.isEmpty())return null;const e=this.getRect(0,0),s=gt._colorManager.convert(this.ctx.strokeStyle);return{annotationType:tt.INK,color:s,thickness:this.thickness,opacity:this.opacity,paths:y(this,j,Cv).call(this,this.scaleFactor/this.parentScale,this.translationX,this.translationY,e),pageIndex:this.pageIndex,rect:e,rotation:this.rotation,structTreeParentId:this._structTreeParentId}}};ro=new WeakMap,oo=new WeakMap,hi=new WeakMap,Ji=new WeakMap,bs=new WeakMap,ao=new WeakMap,ho=new WeakMap,lo=new WeakMap,Zi=new WeakMap,La=new WeakMap,co=new WeakMap,uo=new WeakMap,Wn=new WeakMap,j=new WeakSet,uv=function(e){const s=n=>{this.thickness=n,y(this,j,ql).call(this)},i=this.thickness;this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:$.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0})},gv=function(e){const s=n=>{this.color=n,y(this,j,_o).call(this)},i=this.color;this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:$.INK_COLOR,overwriteIfSameType:!0,keepUndo:!0})},fv=function(e){const s=n=>{this.opacity=n,y(this,j,_o).call(this)};e/=100;const i=this.opacity;this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:$.INK_OPACITY,overwriteIfSameType:!0,keepUndo:!0})},pv=function(){const{parentRotation:e,parentDimensions:[s,i]}=this;switch(e){case 90:return[0,i,i,s];case 180:return[s,i,s,i];case 270:return[s,0,i,s];default:return[0,0,s,i]}},Nf=function(){const{ctx:e,color:s,opacity:i,thickness:n,parentScale:r,scaleFactor:o}=this;e.lineWidth=n*r/o,e.lineCap="round",e.lineJoin="round",e.miterLimit=10,e.strokeStyle=`${s}${Cw(i)}`},mv=function(e,s){this.canvas.addEventListener("contextmenu",as,{signal:this._uiManager._signal}),y(this,j,Wf).call(this),b(this,ao,new AbortController);const i=this._uiManager.combinedSignal(c(this,ao));this.canvas.addEventListener("pointerleave",this.canvasPointerleave.bind(this),{signal:i}),this.canvas.addEventListener("pointermove",this.canvasPointermove.bind(this),{signal:i}),this.canvas.addEventListener("pointerup",this.canvasPointerup.bind(this),{signal:i}),this.isEditing=!0,c(this,lo)||(b(this,lo,!0),y(this,j,Ga).call(this),this.thickness||(this.thickness=Mt._defaultThickness),this.color||(this.color=Mt._defaultColor||gt._defaultLineColor),this.opacity??(this.opacity=Mt._defaultOpacity)),this.currentPath.push([e,s]),b(this,ho,!1),y(this,j,Nf).call(this),b(this,Wn,()=>{y(this,j,yv).call(this),c(this,Wn)&&window.requestAnimationFrame(c(this,Wn))}),window.requestAnimationFrame(c(this,Wn))},Bf=function(e,s){const[i,n]=this.currentPath.at(-1);if(this.currentPath.length>1&&e===i&&s===n)return;const r=this.currentPath;let o=c(this,Ji);if(r.push([e,s]),b(this,ho,!0),r.length<=2){o.moveTo(...r[0]),o.lineTo(e,s);return}r.length===3&&(b(this,Ji,o=new Path2D),o.moveTo(...r[0])),y(this,j,_v).call(this,o,...r.at(-3),...r.at(-2),e,s)},bv=function(){if(this.currentPath.length===0)return;const e=this.currentPath.at(-1);c(this,Ji).lineTo(...e)},vv=function(e,s){b(this,Wn,null),e=Math.min(Math.max(e,0),this.canvas.width),s=Math.min(Math.max(s,0),this.canvas.height),y(this,j,Bf).call(this,e,s),y(this,j,bv).call(this);let i;if(this.currentPath.length!==1)i=y(this,j,wv).call(this);else{const l=[e,s];i=[[l,l.slice(),l.slice(),l]]}const n=c(this,Ji),r=this.currentPath;this.currentPath=[],b(this,Ji,new Path2D);const o=()=>{this.allRawPaths.push(r),this.paths.push(i),this.bezierPath2D.push(n),this._uiManager.rebuild(this)},h=()=>{this.allRawPaths.pop(),this.paths.pop(),this.bezierPath2D.pop(),this.paths.length===0?this.remove():(this.canvas||(y(this,j,nu).call(this),y(this,j,ru).call(this)),y(this,j,ql).call(this))};this.addCommands({cmd:o,undo:h,mustExec:!0})},yv=function(){if(!c(this,ho))return;b(this,ho,!1);const e=Math.ceil(this.thickness*this.parentScale),s=this.currentPath.slice(-3),i=s.map(o=>o[0]),n=s.map(o=>o[1]);Math.min(...i)-e,Math.max(...i)+e,Math.min(...n)-e,Math.max(...n)+e;const{ctx:r}=this;r.save(),r.clearRect(0,0,this.canvas.width,this.canvas.height);for(const o of this.bezierPath2D)r.stroke(o);r.stroke(c(this,Ji)),r.restore()},_v=function(e,s,i,n,r,o,h){const l=(s+n)/2,d=(i+r)/2,u=(n+o)/2,g=(r+h)/2;e.bezierCurveTo(l+2*(n-l)/3,d+2*(r-d)/3,u+2*(n-u)/3,g+2*(r-g)/3,u,g)},wv=function(){const e=this.currentPath;if(e.length<=2)return[[e[0],e[0],e.at(-1),e.at(-1)]];const s=[];let i,[n,r]=e[0];for(i=1;i<e.length-2;i++){const[f,p]=e[i],[m,w]=e[i+1],v=(f+m)/2,x=(p+w)/2,S=[n+2*(f-n)/3,r+2*(p-r)/3],C=[v+2*(f-v)/3,x+2*(p-x)/3];s.push([[n,r],S,C,[v,x]]),[n,r]=[v,x]}const[o,h]=e[i],[l,d]=e[i+1],u=[n+2*(o-n)/3,r+2*(h-r)/3],g=[l+2*(o-l)/3,d+2*(h-d)/3];return s.push([[n,r],u,g,[l,d]]),s},_o=function(){if(this.isEmpty()){y(this,j,ou).call(this);return}y(this,j,Nf).call(this);const{canvas:e,ctx:s}=this;s.setTransform(1,0,0,1,0,0),s.clearRect(0,0,e.width,e.height),y(this,j,ou).call(this);for(const i of this.bezierPath2D)s.stroke(i)},Hf=function(){if(c(this,La))return;b(this,La,new AbortController);const e=this._uiManager.combinedSignal(c(this,La));this.canvas.addEventListener("pointerdown",this.canvasPointerdown.bind(this),{signal:e})},Wf=function(){var e;(e=this.pointerdownAC)==null||e.abort(),this.pointerdownAC=null},Xf=function(e){var s;(s=c(this,ao))==null||s.abort(),b(this,ao,null),y(this,j,Hf).call(this),c(this,hi)&&clearTimeout(c(this,hi)),b(this,hi,setTimeout(()=>{b(this,hi,null),this.canvas.removeEventListener("contextmenu",as)},10)),y(this,j,vv).call(this,e.offsetX,e.offsetY),this.addToAnnotationStorage(),this.setInBackground()},nu=function(){this.canvas=document.createElement("canvas"),this.canvas.width=this.canvas.height=0,this.canvas.className="inkEditorCanvas",this.canvas.setAttribute("data-l10n-id","pdfjs-ink-canvas"),this.div.append(this.canvas),this.ctx=this.canvas.getContext("2d")},ru=function(){b(this,Zi,new ResizeObserver(e=>{const s=e[0].contentRect;s.width&&s.height&&this.setDimensions(s.width,s.height)})),c(this,Zi).observe(this.div),this._uiManager._signal.addEventListener("abort",()=>{var e;(e=c(this,Zi))==null||e.disconnect(),b(this,Zi,null)},{once:!0})},Ga=function(){if(!c(this,lo))return;const[e,s]=this.parentDimensions;this.canvas.width=Math.ceil(this.width*e),this.canvas.height=Math.ceil(this.height*s),y(this,j,ou).call(this)},zf=function(e,s){const i=y(this,j,au).call(this),n=(e-i)/c(this,oo),r=(s-i)/c(this,ro);this.scaleFactor=Math.min(n,r)},ou=function(){const e=y(this,j,au).call(this)/2;this.ctx.setTransform(this.scaleFactor,0,0,this.scaleFactor,this.translationX*this.scaleFactor+e,this.translationY*this.scaleFactor+e)},tn=new WeakSet,xv=function(e){const s=new Path2D;for(let i=0,n=e.length;i<n;i++){const[r,o,h,l]=e[i];i===0&&s.moveTo(...r),s.bezierCurveTo(o[0],o[1],h[0],h[1],l[0],l[1])}return s},Vf=function(e,s,i){const[n,r,o,h]=s;switch(i){case 0:for(let l=0,d=e.length;l<d;l+=2)e[l]+=n,e[l+1]=h-e[l+1];break;case 90:for(let l=0,d=e.length;l<d;l+=2){const u=e[l];e[l]=e[l+1]+n,e[l+1]=u+r}break;case 180:for(let l=0,d=e.length;l<d;l+=2)e[l]=o-e[l],e[l+1]+=r;break;case 270:for(let l=0,d=e.length;l<d;l+=2){const u=e[l];e[l]=o-e[l+1],e[l+1]=h-u}break;default:throw new Error("Invalid rotation")}return e},Sv=function(e,s,i){const[n,r,o,h]=s;switch(i){case 0:for(let l=0,d=e.length;l<d;l+=2)e[l]-=n,e[l+1]=h-e[l+1];break;case 90:for(let l=0,d=e.length;l<d;l+=2){const u=e[l];e[l]=e[l+1]-r,e[l+1]=u-n}break;case 180:for(let l=0,d=e.length;l<d;l+=2)e[l]=o-e[l],e[l+1]-=r;break;case 270:for(let l=0,d=e.length;l<d;l+=2){const u=e[l];e[l]=h-e[l+1],e[l+1]=o-u}break;default:throw new Error("Invalid rotation")}return e},Cv=function(e,s,i,n){var d,u;const r=[],o=this.thickness/2,h=e*s+o,l=e*i+o;for(const g of this.paths){const f=[],p=[];for(let m=0,w=g.length;m<w;m++){const[v,x,S,C]=g[m];if(v[0]===C[0]&&v[1]===C[1]&&w===1){const L=e*v[0]+h,I=e*v[1]+l;f.push(L,I),p.push(L,I);break}const E=e*v[0]+h,k=e*v[1]+l,P=e*x[0]+h,D=e*x[1]+l,R=e*S[0]+h,B=e*S[1]+l,O=e*C[0]+h,F=e*C[1]+l;m===0&&(f.push(E,k),p.push(E,k)),f.push(P,D,R,B,O,F),p.push(P,D),m===w-1&&p.push(O,F)}r.push({bezier:y(d=Mt,tn,Vf).call(d,f,n,this.rotation),points:y(u=Mt,tn,Vf).call(u,p,n,this.rotation)})}return r},Gf=function(){let e=1/0,s=-1/0,i=1/0,n=-1/0;for(const r of this.paths)for(const[o,h,l,d]of r){const u=V.bezierBoundingBox(...o,...h,...l,...d);e=Math.min(e,u[0]),i=Math.min(i,u[1]),s=Math.max(s,u[2]),n=Math.max(n,u[3])}return[e,i,s,n]},au=function(){return c(this,bs)?Math.ceil(this.thickness*this.parentScale):0},ql=function(e=!1){if(this.isEmpty())return;if(!c(this,bs)){y(this,j,_o).call(this);return}const s=y(this,j,Gf).call(this),i=y(this,j,au).call(this);b(this,oo,Math.max(gt.MIN_SIZE,s[2]-s[0])),b(this,ro,Math.max(gt.MIN_SIZE,s[3]-s[1]));const n=Math.ceil(i+c(this,oo)*this.scaleFactor),r=Math.ceil(i+c(this,ro)*this.scaleFactor),[o,h]=this.parentDimensions;this.width=n/o,this.height=r/h,this.setAspectRatio(n,r);const l=this.translationX,d=this.translationY;this.translationX=-s[0],this.translationY=-s[1],y(this,j,Ga).call(this),y(this,j,_o).call(this),b(this,co,n),b(this,uo,r),this.setDims(n,r);const u=e?i/this.scaleFactor/2:0;this.translate(l-this.translationX-u,d-this.translationY-u)},_(Mt,tn),K(Mt,"_defaultColor",null),K(Mt,"_defaultOpacity",1),K(Mt,"_defaultThickness",1),K(Mt,"_type","ink"),K(Mt,"_editorType",tt.INK);let Yg=Mt;const Fl=class Fl extends gt{constructor(e){super({...e,name:"stampEditor"});_(this,nt);_(this,Ot,null);_(this,he,null);_(this,Xn,null);_(this,en,null);_(this,zn,null);_(this,Fa,"");_(this,li,null);_(this,sn,null);_(this,ci,null);_(this,is,!1);_(this,Ra,!1);b(this,en,e.bitmapUrl),b(this,zn,e.bitmapFile)}static initialize(e,s){gt.initialize(e,s)}static get supportedTypes(){return ot(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return ot(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 l=h.output;return await this.setGuessedAltText(l),s&&!this.hasAltTextData()&&(this.altTextData={alt:l,decorative:!1}),l}remove(){var e,s;c(this,he)&&(b(this,Ot,null),this._uiManager.imageManager.deleteId(c(this,he)),(e=c(this,li))==null||e.remove(),b(this,li,null),(s=c(this,sn))==null||s.disconnect(),b(this,sn,null),c(this,ci)&&(clearTimeout(c(this,ci)),b(this,ci,null))),super.remove()}rebuild(){if(!this.parent){c(this,he)&&y(this,nt,hu).call(this);return}super.rebuild(),this.div!==null&&(c(this,he)&&c(this,li)===null&&y(this,nt,hu).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(){this._isDraggable=!0,this.div.focus()}isEmpty(){return!(c(this,Xn)||c(this,Ot)||c(this,en)||c(this,zn)||c(this,he))}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(),c(this,Ot)?y(this,nt,Uf).call(this):y(this,nt,hu).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.div}copyCanvas(e,s,i=!1){var f;e||(e=224);const{width:n,height:r}=c(this,Ot),o=new Cg;let h=c(this,Ot),l=n,d=r,u=null;if(s){if(n>s||r>s){const D=Math.min(s/n,s/r);l=Math.floor(n*D),d=Math.floor(r*D)}u=document.createElement("canvas");const p=u.width=Math.ceil(l*o.sx),m=u.height=Math.ceil(d*o.sy);c(this,is)||(h=y(this,nt,lu).call(this,p,m));const w=u.getContext("2d");w.filter=this._uiManager.hcmFilter;let v="white",x="#cfcfd8";this._uiManager.hcmFilter!=="none"?x="black":(f=window.matchMedia)!=null&&f.call(window,"(prefers-color-scheme: dark)").matches&&(v="#8f8f9d",x="#42414d");const S=15,C=S*o.sx,E=S*o.sy,k=new OffscreenCanvas(C*2,E*2),P=k.getContext("2d");P.fillStyle=v,P.fillRect(0,0,C*2,E*2),P.fillStyle=x,P.fillRect(0,0,C,E),P.fillRect(C,E,C,E),w.fillStyle=w.createPattern(k,"repeat"),w.fillRect(0,0,p,m),w.drawImage(h,0,0,h.width,h.height,0,0,p,m)}let g=null;if(i){let p,m;if(o.symmetric&&h.width<e&&h.height<e)p=h.width,m=h.height;else if(h=c(this,Ot),n>e||r>e){const x=Math.min(e/n,e/r);p=Math.floor(n*x),m=Math.floor(r*x),c(this,is)||(h=y(this,nt,lu).call(this,p,m))}const v=new OffscreenCanvas(p,m).getContext("2d",{willReadFrequently:!0});v.drawImage(h,0,0,h.width,h.height,0,0,p,m),g={width:p,height:m,data:v.getImageData(0,0,p,m).data}}return{canvas:u,width:l,height:d,imageData:g}}getImageForAltText(){return c(this,li)}static async deserialize(e,s,i){var m;let n=null;if(e instanceof Y0){const{data:{rect:w,rotation:v,id:x,structParent:S,popupRef:C},container:E,parent:{page:{pageNumber:k}}}=e,P=E.querySelector("canvas"),D=i.imageManager.getFromCanvas(E.id,P);P.remove();const R=((m=await s._structTree.getAriaAttributes(`${yg}${x}`))==null?void 0:m.get("aria-label"))||"";n=e={annotationType:tt.STAMP,bitmapId:D.id,bitmap:D.bitmap,pageIndex:k-1,rect:w.slice(0),rotation:v,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:l,bitmapId:d,isSvg:u,accessibilityData:g}=e;d&&i.imageManager.isValidId(d)?(b(r,he,d),h&&b(r,Ot,h)):b(r,en,l),b(r,is,u);const[f,p]=r.pageDimensions;return r.width=(o[2]-o[0])/f,r.height=(o[3]-o[1])/p,r.annotationElementId=e.id||null,g&&(r.altTextData=g),r._initialData=n,b(r,Ra,!!n),r}serialize(e=!1,s=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const i={annotationType:tt.STAMP,bitmapId:c(this,he),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:c(this,is),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=y(this,nt,cu).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=y(this,nt,Ev).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=c(this,is)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!s.stamps.has(c(this,he)))s.stamps.set(c(this,he),{area:o,serialized:i}),i.bitmap=y(this,nt,cu).call(this,!1);else if(c(this,is)){const h=s.stamps.get(c(this,he));o>h.area&&(h.area=o,h.serialized.bitmap.close(),h.serialized.bitmap=y(this,nt,cu).call(this,!1))}return i}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}};Ot=new WeakMap,he=new WeakMap,Xn=new WeakMap,en=new WeakMap,zn=new WeakMap,Fa=new WeakMap,li=new WeakMap,sn=new WeakMap,ci=new WeakMap,is=new WeakMap,Ra=new WeakMap,nt=new WeakSet,$l=function(e,s=!1){if(!e){this.remove();return}b(this,Ot,e.bitmap),s||(b(this,he,e.id),b(this,is,e.isSvg)),e.file&&b(this,Fa,e.file.name),y(this,nt,Uf).call(this)},Kl=function(){if(b(this,Xn,null),this._uiManager.enableWaiting(!1),!!c(this,li)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&c(this,Ot)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&c(this,Ot)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},hu=function(){if(c(this,he)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(c(this,he)).then(i=>y(this,nt,$l).call(this,i,!0)).finally(()=>y(this,nt,Kl).call(this));return}if(c(this,en)){const i=c(this,en);b(this,en,null),this._uiManager.enableWaiting(!0),b(this,Xn,this._uiManager.imageManager.getFromUrl(i).then(n=>y(this,nt,$l).call(this,n)).finally(()=>y(this,nt,Kl).call(this)));return}if(c(this,zn)){const i=c(this,zn);b(this,zn,null),this._uiManager.enableWaiting(!0),b(this,Xn,this._uiManager.imageManager.getFromFile(i).then(n=>y(this,nt,$l).call(this,n)).finally(()=>y(this,nt,Kl).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=Fl.supportedTypesStr;const s=this._uiManager._signal;b(this,Xn,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}}),y(this,nt,$l).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>y(this,nt,Kl).call(this))),e.click()},Uf=function(){const{div:e}=this;let{width:s,height:i}=c(this,Ot);const[n,r]=this.pageDimensions,o=.75;if(this.width)s=this.width*n,i=this.height*r;else if(s>o*n||i>o*r){const u=Math.min(o*n/s,o*r/i);s*=u,i*=u}const[h,l]=this.parentDimensions;this.setDims(s*h/n,i*l/r),this._uiManager.enableWaiting(!1);const d=b(this,li,document.createElement("canvas"));d.setAttribute("role","img"),this.addContainer(d),(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),y(this,nt,Yf).call(this,s,i),y(this,nt,Tv).call(this),c(this,Ra)||(this.parent.addUndoableEditor(this),b(this,Ra,!0)),this._reportTelemetry({action:"inserted_image"}),c(this,Fa)&&d.setAttribute("aria-label",c(this,Fa))},Av=function(e,s){var o;const[i,n]=this.parentDimensions;this.width=e/i,this.height=s/n,(o=this._initialOptions)!=null&&o.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,c(this,ci)!==null&&clearTimeout(c(this,ci)),b(this,ci,setTimeout(()=>{b(this,ci,null),y(this,nt,Yf).call(this,e,s)},200))},lu=function(e,s){const{width:i,height:n}=c(this,Ot);let r=i,o=n,h=c(this,Ot);for(;r>2*e||o>2*s;){const l=r,d=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 u=new OffscreenCanvas(r,o);u.getContext("2d").drawImage(h,0,0,l,d,0,0,r,o),h=u.transferToImageBitmap()}return h},Yf=function(e,s){const i=new Cg,n=Math.ceil(e*i.sx),r=Math.ceil(s*i.sy),o=c(this,li);if(!o||o.width===n&&o.height===r)return;o.width=n,o.height=r;const h=c(this,is)?c(this,Ot):y(this,nt,lu).call(this,n,r),l=o.getContext("2d");l.filter=this._uiManager.hcmFilter,l.drawImage(h,0,0,h.width,h.height,0,0,n,r)},cu=function(e){if(e){if(c(this,is)){const n=this._uiManager.imageManager.getSvgUrl(c(this,he));if(n)return n}const s=document.createElement("canvas");return{width:s.width,height:s.height}=c(this,Ot),s.getContext("2d").drawImage(c(this,Ot),0,0),s.toDataURL()}if(c(this,is)){const[s,i]=this.pageDimensions,n=Math.round(this.width*s*mn.PDF_TO_CSS_UNITS),r=Math.round(this.height*i*mn.PDF_TO_CSS_UNITS),o=new OffscreenCanvas(n,r);return o.getContext("2d").drawImage(c(this,Ot),0,0,c(this,Ot).width,c(this,Ot).height,0,0,n,r),o.transferToImageBitmap()}return structuredClone(c(this,Ot))},Tv=function(){this._uiManager._signal&&(b(this,sn,new ResizeObserver(e=>{const s=e[0].contentRect;s.width&&s.height&&y(this,nt,Av).call(this,s.width,s.height)})),c(this,sn).observe(this.div),this._uiManager._signal.addEventListener("abort",()=>{var e;(e=c(this,sn))==null||e.disconnect(),b(this,sn,null)},{once:!0}))},Ev=function(e){var l;const{rect:s,pageIndex:i,accessibilityData:{altText:n}}=this._initialData,r=e.rect.every((d,u)=>Math.abs(d-s[u])<1),o=e.pageIndex===i,h=(((l=e.accessibilityData)==null?void 0:l.alt)||"")===n;return{isSame:r&&o&&h,isSameAltText:h}},K(Fl,"_type","stamp"),K(Fl,"_editorType",tt.STAMP);let qg=Fl;const Ws=class Ws{constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:o,textLayer:h,viewport:l,l10n:d}){_(this,le);_(this,go);_(this,Ia,!1);_(this,di,null);_(this,Vn,null);_(this,nn,null);_(this,ns,new Map);_(this,Gn,!1);_(this,ja,!1);_(this,Na,!1);_(this,_e,null);_(this,rn,null);_(this,U);const u=[...c(Ws,Un).values()];if(!Ws._initialized){Ws._initialized=!0;for(const g of u)g.initialize(d,t)}t.registerEditorTypes(u),b(this,U,t),this.pageIndex=e,this.div=s,b(this,go,n),b(this,di,r),this.viewport=l,b(this,_e,h),this.drawLayer=o,this._structTree=i,c(this,U).addLayer(this)}get isEmpty(){return c(this,ns).size===0}get isInvisible(){return this.isEmpty&&c(this,U).getMode()===tt.NONE}updateToolbar(t){c(this,U).updateToolbar(t)}updateMode(t=c(this,U).getMode()){switch(y(this,le,du).call(this),t){case tt.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case tt.INK:this.addInkEditorIfNeeded(!1),this.disableTextSelection(),this.togglePointerEvents(!0),this.disableClick();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 c(Ws,Un).values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=c(this,_e))==null?void 0:e.div)}addInkEditorIfNeeded(t){if(c(this,U).getMode()!==tt.INK)return;if(!t){for(const s of c(this,ns).values())if(s.isEmpty()){s.setInBackground();return}}this.createAndAddNewEditor({offsetX:0,offsetY:0},!1).setInBackground()}setEditingState(t){c(this,U).setEditingState(t)}addCommands(t){c(this,U).addCommands(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=c(this,di))==null||e.div.classList.toggle("disabled",!t)}async enable(){this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of c(this,ns).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(c(this,U).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!c(this,di))return;const e=c(this,di).getEditableAnnotations();for(const s of e){if(s.hide(),c(this,U).isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}}disable(){var i;b(this,Na,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const n of c(this,ns).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(c(this,di)){const n=c(this,di).getEditableAnnotations();for(const r of n){const{id:o}=r.data;if(c(this,U).isDeletedAnnotationElement(o))continue;let h=e.get(o);if(h){h.resetAnnotationElement(r),h.show(!1),r.show();continue}h=t.get(o),h&&(c(this,U).addChangedExistingAnnotation(h),h.renderAnnotationElement(r)&&h.show(!1)),r.show()}}y(this,le,du).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of c(Ws,Un).values())s.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),b(this,Na,!1)}getEditableAnnotation(t){var e;return((e=c(this,di))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){c(this,U).getActive()!==t&&c(this,U).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=c(this,_e))!=null&&t.div&&!c(this,rn)){b(this,rn,new AbortController);const e=c(this,U).combinedSignal(c(this,rn));c(this,_e).div.addEventListener("pointerdown",y(this,le,kv).bind(this),{signal:e}),c(this,_e).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=c(this,_e))!=null&&t.div&&c(this,rn)&&(c(this,rn).abort(),b(this,rn,null),c(this,_e).div.classList.remove("highlighting"))}enableClick(){if(c(this,Vn))return;b(this,Vn,new AbortController);const t=c(this,U).combinedSignal(c(this,Vn));this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t}),this.div.addEventListener("pointerup",this.pointerup.bind(this),{signal:t})}disableClick(){var t;(t=c(this,Vn))==null||t.abort(),b(this,Vn,null)}attach(t){c(this,ns).set(t.id,t);const{annotationElementId:e}=t;e&&c(this,U).isDeletedAnnotationElement(e)&&c(this,U).removeDeletedAnnotationElement(t)}detach(t){var e;c(this,ns).delete(t.id),(e=c(this,go))==null||e.removePointerInTextLayer(t.contentDiv),!c(this,Na)&&t.annotationElementId&&c(this,U).addDeletedAnnotationElement(t)}remove(t){this.detach(t),c(this,U).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1,c(this,ja)||this.addInkEditorIfNeeded(!1)}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(c(this,U).addDeletedAnnotationElement(t.annotationElementId),gt.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),c(this,U).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(),c(this,U).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!c(this,nn)&&(t._focusEventsAllowed=!1,b(this,nn,setTimeout(()=>{b(this,nn,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:c(this,U)._signal}),e.focus())},0))),t._structTreeParentId=(s=c(this,go))==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 c(this,U).getId()}combinedSignal(t){return c(this,U).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=c(this,le,qf))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){c(this,U).updateToolbar(t),c(this,U).updateMode(t);const{offsetX:s,offsetY:i}=y(this,le,Kf).call(this),n=this.getNextId(),r=y(this,le,$f).call(this,{parent:this,id:n,x:s,y:i,uiManager:c(this,U),isCentered:!0,...e});r&&this.add(r)}async deserialize(t){var e;return await((e=c(Ws,Un).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,c(this,U)))||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=y(this,le,$f).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:c(this,U),isCentered:e,...s});return n&&this.add(n),n}addNewEditor(){this.createAndAddNewEditor(y(this,le,Kf).call(this),!0)}setSelected(t){c(this,U).setSelected(t)}toggleSelected(t){c(this,U).toggleSelected(t)}unselect(t){c(this,U).unselect(t)}pointerup(t){const{isMac:e}=ke.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&c(this,Gn)){if(b(this,Gn,!1),!c(this,Ia)){b(this,Ia,!0);return}if(c(this,U).getMode()===tt.STAMP){c(this,U).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){if(c(this,U).getMode()===tt.HIGHLIGHT&&this.enableTextSelection(),c(this,Gn)){b(this,Gn,!1);return}const{isMac:e}=ke.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;b(this,Gn,!0);const s=c(this,U).getActive();b(this,Ia,!s||s.isEmpty())}findNewParent(t,e,s){const i=c(this,U).findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}destroy(){var t,e;((t=c(this,U).getActive())==null?void 0:t.parent)===this&&(c(this,U).commitOrRemove(),c(this,U).setActiveEditor(null)),c(this,nn)&&(clearTimeout(c(this,nn)),b(this,nn,null));for(const s of c(this,ns).values())(e=c(this,go))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,c(this,ns).clear(),c(this,U).removeLayer(this)}render({viewport:t}){this.viewport=t,cr(this.div,t);for(const e of c(this,U).getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){c(this,U).commitOrRemove(),y(this,le,du).call(this);const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,cr(this.div,{rotation:s}),e!==s)for(const i of c(this,ns).values())i.rotate(s);this.addInkEditorIfNeeded(!1)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return c(this,U).viewParameters.realScale}};go=new WeakMap,Ia=new WeakMap,di=new WeakMap,Vn=new WeakMap,nn=new WeakMap,ns=new WeakMap,Gn=new WeakMap,ja=new WeakMap,Na=new WeakMap,_e=new WeakMap,rn=new WeakMap,U=new WeakMap,Un=new WeakMap,le=new WeakSet,kv=function(t){c(this,U).unselectAll();const{target:e}=t;if(e===c(this,_e).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&c(this,_e).div.contains(e)){const{isMac:s}=ke.platform;if(t.button!==0||t.ctrlKey&&s)return;c(this,U).showAllEditors("highlight",!0,!0),c(this,_e).div.classList.add("free"),this.toggleDrawing(),bd.startHighlighting(this,c(this,U).direction==="ltr",{target:c(this,_e).div,x:t.x,y:t.y}),c(this,_e).div.addEventListener("pointerup",()=>{c(this,_e).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:c(this,U)._signal}),t.preventDefault()}},qf=function(){return c(Ws,Un).get(c(this,U).getMode())},$f=function(t){const e=c(this,le,qf);return e?new e.prototype.constructor(t):null},Kf=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),l=(n+o)/2-t,d=(r+h)/2-e,[u,g]=this.viewport.rotation%180===0?[l,d]:[d,l];return{offsetX:u,offsetY:g}},du=function(){b(this,ja,!0);for(const t of c(this,ns).values())t.isEmpty()&&t.remove();b(this,ja,!1)},K(Ws,"_initialized",!1),_(Ws,Un,new Map([Gg,Yg,qg,bd].map(t=>[t._editorType,t])));let $g=Ws;const ce=class ce{constructor({pageIndex:t}){_(this,fo);_(this,ui,null);_(this,Rl,0);_(this,Gt,new Map);_(this,on,new Map);this.pageIndex=t}setParent(t){if(!c(this,ui)){b(this,ui,t);return}if(c(this,ui)!==t){if(c(this,Gt).size>0)for(const e of c(this,Gt).values())e.remove(),t.append(e);b(this,ui,t)}}static get _svgFactory(){return ot(this,"_svgFactory",new Xg)}draw(t,e,s,i=!1){const n=Fe(this,Rl)._++,r=y(this,fo,Jf).call(this,t.box);r.classList.add(...t.classNamesForDrawing);const o=ce._svgFactory.createElement("defs");r.append(o);const h=ce._svgFactory.createElement("path");o.append(h);const l=`path_p${this.pageIndex}_${n}`;h.setAttribute("id",l),h.setAttribute("d",t.toSVGPath()),i&&c(this,on).set(n,h);const d=y(this,fo,Mv).call(this,o,l),u=ce._svgFactory.createElement("use");return r.append(u),r.setAttribute("fill",e),r.setAttribute("fill-opacity",s),u.setAttribute("href",`#${l}`),c(this,Gt).set(n,r),{id:n,clipPathId:`url(#${d})`}}drawOutline(t){const e=Fe(this,Rl)._++,s=y(this,fo,Jf).call(this,t.box);s.classList.add(...t.classNamesForOutlining);const i=ce._svgFactory.createElement("defs");s.append(i);const n=ce._svgFactory.createElement("path");i.append(n);const r=`path_p${this.pageIndex}_${e}`;n.setAttribute("id",r),n.setAttribute("d",t.toSVGPath()),n.setAttribute("vector-effect","non-scaling-stroke");let o;if(t.mustRemoveSelfIntersections){const d=ce._svgFactory.createElement("mask");i.append(d),o=`mask_p${this.pageIndex}_${e}`,d.setAttribute("id",o),d.setAttribute("maskUnits","objectBoundingBox");const u=ce._svgFactory.createElement("rect");d.append(u),u.setAttribute("width","1"),u.setAttribute("height","1"),u.setAttribute("fill","white");const g=ce._svgFactory.createElement("use");d.append(g),g.setAttribute("href",`#${r}`),g.setAttribute("stroke","none"),g.setAttribute("fill","black"),g.setAttribute("fill-rule","nonzero"),g.classList.add("mask")}const h=ce._svgFactory.createElement("use");s.append(h),h.setAttribute("href",`#${r}`),o&&h.setAttribute("mask",`url(#${o})`);const l=h.cloneNode();return s.append(l),h.classList.add("mainOutline"),l.classList.add("secondaryOutline"),c(this,Gt).set(e,s),e}finalizeLine(t,e){const s=c(this,on).get(t);c(this,on).delete(t),this.updateBox(t,e.box),s.setAttribute("d",e.toSVGPath())}updateLine(t,e){c(this,Gt).get(t).firstChild.firstChild.setAttribute("d",e.toSVGPath())}updatePath(t,e){c(this,on).get(t).setAttribute("d",e.toSVGPath())}updateBox(t,e){var s;y(s=ce,Il,Qf).call(s,c(this,Gt).get(t),e)}show(t,e){c(this,Gt).get(t).classList.toggle("hidden",!e)}rotate(t,e){c(this,Gt).get(t).setAttribute("data-main-rotation",e)}changeColor(t,e){c(this,Gt).get(t).setAttribute("fill",e)}changeOpacity(t,e){c(this,Gt).get(t).setAttribute("fill-opacity",e)}addClass(t,e){c(this,Gt).get(t).classList.add(e)}removeClass(t,e){c(this,Gt).get(t).classList.remove(e)}getSVGRoot(t){return c(this,Gt).get(t)}remove(t){c(this,on).delete(t),c(this,ui)!==null&&(c(this,Gt).get(t).remove(),c(this,Gt).delete(t))}destroy(){b(this,ui,null);for(const t of c(this,Gt).values())t.remove();c(this,Gt).clear(),c(this,on).clear()}};ui=new WeakMap,Rl=new WeakMap,Gt=new WeakMap,on=new WeakMap,Il=new WeakSet,Qf=function(t,{x:e=0,y:s=0,width:i=1,height:n=1}={}){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`},fo=new WeakSet,Jf=function(t){var s;const e=ce._svgFactory.create(1,1,!0);return c(this,ui).append(e),e.setAttribute("aria-hidden",!0),y(s=ce,Il,Qf).call(s,e,t),e},Mv=function(t,e){const s=ce._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=ce._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i},_(ce,Il);let Kg=ce;Q.AbortException,Q.AnnotationEditorLayer,Q.AnnotationEditorParamsType,Q.AnnotationEditorType,Q.AnnotationEditorUIManager,Q.AnnotationLayer,Q.AnnotationMode,Q.ColorPicker,Q.DOMSVGFactory,Q.DrawLayer,Q.FeatureTest;var iS=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.UnexpectedResponseException,Q.Util,Q.VerbosityLevel,Q.XfaLayer,Q.build,Q.createValidAbsoluteUrl,Q.fetchData;var nS=Q.getDocument;Q.getFilenameFromUrl,Q.getPdfFilenameFromUrl,Q.getXfaPageViewport,Q.isDataScheme,Q.isPdfFile,Q.noContextMenu,Q.normalizeUnicode,Q.setLayerDimensions,Q.shadow,Q.version;const rS={fabric:"^6.4.3","pdfjs-dist":"^4.8.69"};function oS(a){return new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>t(s.result)),s.addEventListener("error",e),s.readAsDataURL(a)})}const aS=rS["pdfjs-dist"].replace("^","");iS.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${aS}/pdf.worker.min.mjs`;async function hS(a){const t="data:application/pdf;base64,",e=await oS(a);if(typeof e=="string")return window.atob(e.slice(t.length))}function lS(a,t){return nS({data:a,password:t}).promise}const cS="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2040%2040'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3ccircle%20cx='20'%20cy='20'%20r='10.75'%20stroke='currentColor'%20stroke-width='2.5'/%3e%3cpath%20d='M16%2024L23.7782%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3cpath%20d='M24%2024L16.2218%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3c/svg%3e";function dS(a){return new URL(Object.assign({"../assets/close.svg":cS})[`../assets/${a}`],typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Dt&&Dt.src||new URL("pdf-canvas.umd.js",document.baseURI).href).href}function uS(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 gS(i))}),i.addEventListener("error",n=>{window.URL.revokeObjectURL(s),e(n)})})}function gS(a){return new Promise(t=>{const e=document.createElement("canvas"),s=e.getContext("2d"),{naturalWidth:i,naturalHeight:n}=a;e.width=i,e.height=n,s==null||s.drawImage(a,0,0,i,n),t(e.toDataURL("image/jpeg",.8))})}let Q0=null;function fS(){const a=document.createElement("div");a.style.width="1in",document.body.append(a);const t=a.offsetWidth;return a.remove(),t}function pS(){const a=Q0??fS();return Q0=a,a/72}function mS(a,t=500){if(typeof a!="function")throw new TypeError("The first argument is not a function.");let e=null;return function(...s){e&&clearTimeout(e),e=setTimeout(()=>{e=null,a.apply(this,s)},t)}}const bS={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},vS={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},yS={stroke:"#000",hoverStroke:"#B7EC5D",src:""},ls=new Map;function J0(a=""){let t=0,e=null,s=null,i=1,n={...yS};function r(){if(!a||ls.has(a))return;const O=new Zu(a);return ls.set(a,O),O.on("selection:cleared",()=>D(O)),O}function o(O,F){const L=O.type;return{"application/pdf":h,"image/png":u,"image/jpeg":u}[L](O,F)??Promise.reject(new Error(`Unsupported ${L} file type.`))}async function h(O,F){const L=await hS(O);if(!L)return;const I=Date.now(),Y={PDFId:`${O.name}-${I}`,name:O.name.replace(/.pdf/,""),updateDate:I,PDFBase64:L};try{return await l({page:1,PDFBase64:L,scale:.8,password:F}),{...Y,pages:t}}catch(z){return Promise.reject(z)}}async function l({page:O,PDFBase64:F,scale:L,password:I}){try{const G=await lS(F,I),Y=await q.toRaw(G).getPage(O),z=Y.getViewport({scale:L}),H=document.createElement("canvas"),_t=H.getContext("2d"),vt=pS()/window.devicePixelRatio;H.width=Math.floor(z.width*vt),H.height=Math.floor(z.height*vt),t=G.numPages;const te={canvasContext:_t,viewport:z,transform:[vt,0,0,vt,0,0]};return Y.render(te).promise.then(()=>d(H))}catch(G){return Promise.reject(G)}}function d(O){if(!ls.get(a))return;const L=1/3,I=_S(O,L);f(I,L)}async function u(O){const F=await uS(O),L=Date.now(),G={PDFId:`${O.name}${L}`,name:O.name.replace(/.png|.jpg|.jpeg/,""),updateDate:L,PDFBase64:F};return g({url:F}),{...G,pages:1}}async function g({url:O,scale:F=.5}){if(!ls.get(a))return;const I=await fe.fromURL(O);I.scale(F),f(I,F)}function f(O,F){const L=ls.get(a);L&&(L.setWidth(O.width*F),L.setHeight(O.height*F),L.backgroundImage=O,L.renderAll())}async function p(O,F){const L=ls.get(a);if(!L)return;const I=await fe.fromURL(O,{},{...bS,...F});L.add(I),w(L,I)}function m(O,F){const L=ls.get(a);if(!L)return;const I=new ge(O,{...vS,...F});L.add(I),w(L,I)}function w(O,F){F.on("selected",L=>v({canvas:O,target:L.target})),F.on("modified",L=>S(L.target)),F.on("scaling",L=>S(L.transform.target)),F.on("moving",L=>S(L.transform.target)),F.on("rotating",L=>S(L.transform.target))}async function v({canvas:O,target:F,stroke:L=n.stroke,uuid:I=Date.now()}){if((e==null?void 0:e.stroke)===`${L}-${I}`)return;const G=n.src||dS("close.svg"),{objects:Y,options:z}=await Y_(G),H=Y.filter(vt=>vt!==null),_t=a_.groupSVGElements(H,z);H.forEach(vt=>{vt.stroke=L}),_t.hoverCursor="pointer",_t.stroke=`${L}-${I}`,D(O),e=_t,s=F,x(O,F,I),C(i,!0),O.add(_t)}function x(O,F,L){e&&(e.on("selected",()=>{O.remove(F),D(O)}),e.on("mouseover",()=>{v({canvas:O,target:F,stroke:n.hoverStroke,uuid:L})}),e.on("mouseout",()=>{v({canvas:O,target:F,stroke:n.stroke,uuid:L})}))}function S(O){if(!e)return;const{oCoords:F}=O;if(!F)return;const{x:L,y:I}=F.tl.touchCorner.tl,{height:G,width:Y,scaleY:z,scaleX:H}=e;e.top=I-G*z/2,e.left=L-Y*H/2,e.setCoords()}function C(O,F=!1){const L=ls.get(a);i=O,L&&(k(s,O),E(s,O),!F&&L.renderAll())}function E(O,F){!e||!O||(e.scale(1/F),S(O))}function k(O,F){O&&(O.borderScaleFactor=1/F,O.cornerSize=6*(1/F),O.touchCornerSize=24*(1/F),O.cornerStrokeColor=n.stroke,O.setCoords())}function P(O){if(!O)return;n={...n,...O};const F=ls.get(a);!e||!s||!F||v({target:s,canvas:F})}function D(O){e&&(O.remove(e),e=s=null)}function R(){const O=ls.get(a);O&&(O.discardActiveObject(),O.renderAll())}function B(){const O=ls.get(a);O&&(O.clear(),ls.delete(a))}return{createCanvas:r,loadFile:o,specifyPage:l,renderImage:g,addFabric:p,addTextFabric:m,clearActive:R,deleteCanvas:B,scaleFabric:C,setCloseSvgOptions:P}}function _S(a,t){return new fe(a,{scaleX:t,scaleY:t})}function wS(a){let t=0;const e=mS(()=>{t!==window.innerWidth&&(t=window.innerWidth,a())});q.onMounted(()=>{window.addEventListener("resize",e)}),q.onBeforeUnmount(()=>{window.removeEventListener("resize",e)})}const xS=q.defineComponent({__name:"pdf-canvas",props:{file:{},page:{default:1},canvasId:{default:"PDF-canvas"},fileZoom:{default:1},fileScale:{default:1},canvasScale:{default:1},canvasClass:{default:""},isDrop:{type:Boolean,default:!1},password:{},dropTextOptions:{},dropImageOptions:{},closeSvgOptions:{}},setup(a,{expose:t}){const e=a,s=q.ref(null),i=`${e.canvasId}-${e.page-1}`,n=q.computed(()=>e.fileZoom*e.canvasScale),{createCanvas:r,specifyPage:o,addFabric:h,addTextFabric:l,renderImage:d,clearActive:u,deleteCanvas:g,scaleFabric:f,setCloseSvgOptions:p}=J0(i);m(),wS(m);async function m(){const{file:S,page:C,fileScale:E}=e;window.requestAnimationFrame(async()=>{if(await q.nextTick(),r(),S.PDFBase64.startsWith("data:image")||S.canvas){const{canvas:k}=S,P=k?7:3,D=k!=null&&k.length?k[C-1]:S.PDFBase64;d({url:D,scale:E/P});return}await o({page:C,PDFBase64:S.PDFBase64,scale:E,password:e.password})})}function w(S){if(!e.isDrop||!S.dataTransfer)return;const{dataTransfer:C,offsetX:E,offsetY:k}=S,P=C.getData("text"),D=C.getData("image"),R={left:E-71,top:k-55};D&&v(D,R),P&&x(P,R)}function v(S,C){h(S,{...C,...e.dropImageOptions})}function x(S,C){l(S,{...C,...e.dropTextOptions})}return q.watch([()=>e.fileScale,()=>e.page,()=>e.file,()=>e.password],m),q.watch(n,S=>f(S),{immediate:!0}),q.watch(()=>e.closeSvgOptions,p,{immediate:!0}),q.onBeforeUnmount(g),t({addImage:v,addText:x,clearActive:u,deleteCanvas:g,canvasRef:s}),(S,C)=>(q.openBlock(),q.createElementBlock("div",{style:q.normalizeStyle({transform:`scale(${n.value})`}),onDragover:C[0]||(C[0]=q.withModifiers(()=>{},["stop","prevent"])),onDragenter:C[1]||(C[1]=q.withModifiers(()=>{},["stop","prevent"])),onDrop:q.withModifiers(w,["stop","prevent"])},[q.createElementVNode("canvas",{id:i,ref_key:"canvasRef",ref:s,class:q.normalizeClass(S.canvasClass)},null,2)],36))}}),vd=Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"}));rt.default=xS,rt.useFabric=J0,Object.defineProperties(rt,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
505
+ `)}`),y(this,Wt,eu).call(this);const g=new Range;let f=d.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(f<=x){g.setStart(v,f),g.setEnd(v,f);break}f-=x}r.removeAllRanges(),r.addRange(g)}get contentDiv(){return this.editorDiv}static async deserialize(e,s,i){var o;let n=null;if(e instanceof q0){const{data:{defaultAppearanceData:{fontSize:h,fontColor:l},rect:d,rotation:u,id:g,popupRef:f},textContent:p,textPosition:m,parent:{page:{pageNumber:_}}}=e;if(!p||p.length===0)return null;n=e={annotationType:Z.FREETEXT,color:Array.from(l),fontSize:h,value:p.join(`
506
+ `),position:m,pageIndex:_-1,rect:d.slice(0),rotation:u,id:g,deleted:!1,popupRef:f}}const r=await super.deserialize(e,s,i);return b(r,ts,e.fontSize),b(r,Rs,X.makeHexColor(...e.color)),b(r,Ze,y(o=vt,Yi,Pf).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=vt._internalPadding*this.parentScale,i=this.getRect(s,s),n=gt._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:c(this,Rs)),r={annotationType:Z.FREETEXT,color:n,fontSize:c(this,ts),value:y(this,Wt,Yb).call(this),pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?r:this.annotationElementId&&!y(this,Wt,qb).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(${c(this,ts)}px * var(--scale-factor))`,i.color=c(this,Rs),s.replaceChildren();for(const r of c(this,Ze).split(`
507
+ `)){const o=document.createElement("div");o.append(r?document.createTextNode(r):document.createElement("br")),s.append(o)}const n=vt._internalPadding*this.parentScale;return e.updateEdited({rect:this.getRect(n,n),popupContent:c(this,Ze)}),s}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}};Rs=new WeakMap,Ze=new WeakMap,yl=new WeakMap,Jr=new WeakMap,ts=new WeakMap,Wt=new WeakSet,Vb=function(e){const s=n=>{this.editorDiv.style.fontSize=`calc(${n}px * var(--scale-factor))`,this.translate(0,-(n-c(this,ts))*this.parentScale),b(this,ts,n),y(this,Wt,Zd).call(this)},i=c(this,ts);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Y.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})},Gb=function(e){const s=n=>{b(this,Rs,this.editorDiv.style.color=n)},i=c(this,Rs);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Y.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})},Ub=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(y(i=vt,Yi,tu).call(i,n)),s=n);return e.join(`
508
+ `)},Zd=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()},Yi=new WeakSet,tu=function(e){return(e.nodeType===Node.TEXT_NODE?e.nodeValue:e.innerText).replaceAll(pd,"")},eu=function(){if(this.editorDiv.replaceChildren(),!!c(this,Ze))for(const e of c(this,Ze).split(`
509
+ `)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},Yb=function(){return c(this,Ze).replaceAll(" "," ")},Pf=function(e){return e.replaceAll(" "," ")},qb=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},w(vt,Yi),q(vt,"_freeTextDefaultContent",""),q(vt,"_internalPadding",0),q(vt,"_defaultColor",null),q(vt,"_defaultFontSize",10),q(vt,"_type","freetext"),q(vt,"_editorType",Z.FREETEXT);let Ug=vt;class J0{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.")}get classNamesForDrawing(){yt("Abstract getter `classNamesForDrawing` must be implemented.")}get classNamesForOutlining(){yt("Abstract getter `classNamesForOutlining` must be implemented.")}get mustRemoveSelfIntersections(){return!1}}const qi=class qi{constructor({x:t,y:e},s,i,n,r,o=0){w(this,$t);w(this,es);w(this,Is,[]);w(this,_a);w(this,wa);w(this,ai,[]);w(this,it,new Float64Array(18));w(this,Zr);w(this,to);w(this,_l);w(this,wl);w(this,xa);w(this,Sa);w(this,Nn,[]);b(this,es,s),b(this,Sa,n*i),b(this,wa,r),c(this,it).set([NaN,NaN,NaN,NaN,t,e],6),b(this,_a,o),b(this,wl,c(qi,xl)*i),b(this,_l,c(qi,Id)*i),b(this,xa,i),c(this,Nn).push(t,e)}isEmpty(){return isNaN(c(this,it)[8])}add({x:t,y:e}){var P;b(this,Zr,t),b(this,to,e);const[s,i,n,r]=c(this,es);let[o,h,l,d]=c(this,it).subarray(8,12);const u=t-l,g=e-d,f=Math.hypot(u,g);if(f<c(this,_l))return!1;const p=f-c(this,wl),m=p/f,_=m*u,v=m*g;let x=o,S=h;o=l,h=d,l+=_,d+=v,(P=c(this,Nn))==null||P.push(t,e);const C=-v/p,E=_/p,M=C*c(this,Sa),k=E*c(this,Sa);return c(this,it).set(c(this,it).subarray(2,8),0),c(this,it).set([l+M,d+k],4),c(this,it).set(c(this,it).subarray(14,18),12),c(this,it).set([l-M,d-k],16),isNaN(c(this,it)[6])?(c(this,ai).length===0&&(c(this,it).set([o+M,h+k],2),c(this,ai).push(NaN,NaN,NaN,NaN,(o+M-s)/n,(h+k-i)/r),c(this,it).set([o-M,h-k],14),c(this,Is).push(NaN,NaN,NaN,NaN,(o-M-s)/n,(h-k-i)/r)),c(this,it).set([x,S,o,h,l,d],6),!this.isEmpty()):(c(this,it).set([x,S,o,h,l,d],6),Math.abs(Math.atan2(S-h,x-o)-Math.atan2(v,_))<Math.PI/2?([o,h,l,d]=c(this,it).subarray(2,6),c(this,ai).push(NaN,NaN,NaN,NaN,((o+l)/2-s)/n,((h+d)/2-i)/r),[o,h,x,S]=c(this,it).subarray(14,18),c(this,Is).push(NaN,NaN,NaN,NaN,((x+o)/2-s)/n,((S+h)/2-i)/r),!0):([x,S,o,h,l,d]=c(this,it).subarray(0,6),c(this,ai).push(((x+5*o)/6-s)/n,((S+5*h)/6-i)/r,((5*o+l)/6-s)/n,((5*h+d)/6-i)/r,((o+l)/2-s)/n,((h+d)/2-i)/r),[l,d,o,h,x,S]=c(this,it).subarray(12,18),c(this,Is).push(((x+5*o)/6-s)/n,((S+5*h)/6-i)/r,((5*o+l)/6-s)/n,((5*h+d)/6-i)/r,((o+l)/2-s)/n,((h+d)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=c(this,ai),e=c(this,Is);if(isNaN(c(this,it)[6])&&!this.isEmpty())return y(this,$t,$b).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]}`);y(this,$t,Qb).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 y(this,$t,Kb).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new Z0(t,e,s,i,n,r)}getOutlines(){var u;const t=c(this,ai),e=c(this,Is),s=c(this,it),[i,n,r,o]=c(this,es),h=new Float64Array((((u=c(this,Nn))==null?void 0:u.length)??0)+2);for(let g=0,f=h.length-2;g<f;g+=2)h[g]=(c(this,Nn)[g]-i)/r,h[g+1]=(c(this,Nn)[g+1]-n)/o;if(h[h.length-2]=(c(this,Zr)-i)/r,h[h.length-1]=(c(this,to)-n)/o,isNaN(s[6])&&!this.isEmpty())return y(this,$t,Jb).call(this,h);const l=new Float64Array(c(this,ai).length+24+c(this,Is).length);let d=t.length;for(let g=0;g<d;g+=2){if(isNaN(t[g])){l[g]=l[g+1]=NaN;continue}l[g]=t[g],l[g+1]=t[g+1]}d=y(this,$t,tv).call(this,l,d);for(let g=e.length-6;g>=6;g-=6)for(let f=0;f<6;f+=2){if(isNaN(e[g+f])){l[d]=l[d+1]=NaN,d+=2;continue}l[d]=e[g+f],l[d+1]=e[g+f+1],d+=2}return y(this,$t,Zb).call(this,l,d),this.newFreeDrawOutline(l,h,c(this,es),c(this,xa),c(this,_a),c(this,wa))}};es=new WeakMap,Is=new WeakMap,_a=new WeakMap,wa=new WeakMap,ai=new WeakMap,it=new WeakMap,Zr=new WeakMap,to=new WeakMap,_l=new WeakMap,wl=new WeakMap,xa=new WeakMap,Sa=new WeakMap,Nn=new WeakMap,xl=new WeakMap,Rd=new WeakMap,Id=new WeakMap,$t=new WeakSet,Gl=function(){const t=c(this,it).subarray(4,6),e=c(this,it).subarray(16,18),[s,i,n,r]=c(this,es);return[(c(this,Zr)+(t[0]-e[0])/2-s)/n,(c(this,to)+(t[1]-e[1])/2-i)/r,(c(this,Zr)+(e[0]-t[0])/2-s)/n,(c(this,to)+(e[1]-t[1])/2-i)/r]},$b=function(){const[t,e,s,i]=c(this,es),[n,r,o,h]=y(this,$t,Gl).call(this);return`M${(c(this,it)[2]-t)/s} ${(c(this,it)[3]-e)/i} L${(c(this,it)[4]-t)/s} ${(c(this,it)[5]-e)/i} L${n} ${r} L${o} ${h} L${(c(this,it)[16]-t)/s} ${(c(this,it)[17]-e)/i} L${(c(this,it)[14]-t)/s} ${(c(this,it)[15]-e)/i} Z`},Kb=function(t){const e=c(this,Is);t.push(`L${e[4]} ${e[5]} Z`)},Qb=function(t){const[e,s,i,n]=c(this,es),r=c(this,it).subarray(4,6),o=c(this,it).subarray(16,18),[h,l,d,u]=y(this,$t,Gl).call(this);t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${h} ${l} L${d} ${u} L${(o[0]-e)/i} ${(o[1]-s)/n}`)},Jb=function(t){const e=c(this,it),[s,i,n,r]=c(this,es),[o,h,l,d]=y(this,$t,Gl).call(this),u=new Float64Array(36);return u.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,l,d,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(u,t,c(this,es),c(this,xa),c(this,_a),c(this,wa))},Zb=function(t,e){const s=c(this,Is);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},tv=function(t,e){const s=c(this,it).subarray(4,6),i=c(this,it).subarray(16,18),[n,r,o,h]=c(this,es),[l,d,u,g]=y(this,$t,Gl).call(this);return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/o,(s[1]-r)/h,NaN,NaN,NaN,NaN,l,d,NaN,NaN,NaN,NaN,u,g,NaN,NaN,NaN,NaN,(i[0]-n)/o,(i[1]-r)/h],e),e+=24},w(qi,xl,8),w(qi,Rd,2),w(qi,Id,c(qi,xl)+c(qi,Rd));let md=qi;class Z0 extends J0{constructor(e,s,i,n,r,o){super();w(this,Xe);w(this,Ca);w(this,eo,null);w(this,$i);w(this,Sl);w(this,ss);w(this,Cl);w(this,Nt);b(this,Nt,e),b(this,ss,s),b(this,Ca,i),b(this,Cl,n),b(this,$i,r),b(this,Sl,o),y(this,Xe,ev).call(this,o);const{x:h,y:l,width:d,height:u}=c(this,eo);for(let g=0,f=e.length;g<f;g+=2)e[g]=(e[g]-h)/d,e[g+1]=(e[g+1]-l)/u;for(let g=0,f=s.length;g<f;g+=2)s[g]=(s[g]-h)/d,s[g+1]=(s[g+1]-l)/u}toSVGPath(){const e=[`M${c(this,Nt)[4]} ${c(this,Nt)[5]}`];for(let s=6,i=c(this,Nt).length;s<i;s+=6){if(isNaN(c(this,Nt)[s])){e.push(`L${c(this,Nt)[s+4]} ${c(this,Nt)[s+5]}`);continue}e.push(`C${c(this,Nt)[s]} ${c(this,Nt)[s+1]} ${c(this,Nt)[s+2]} ${c(this,Nt)[s+3]} ${c(this,Nt)[s+4]} ${c(this,Nt)[s+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,s,i,n],r){const o=i-e,h=n-s;let l,d;switch(r){case 0:l=y(this,Xe,Ul).call(this,c(this,Nt),e,n,o,-h),d=y(this,Xe,Ul).call(this,c(this,ss),e,n,o,-h);break;case 90:l=y(this,Xe,Yl).call(this,c(this,Nt),e,s,o,h),d=y(this,Xe,Yl).call(this,c(this,ss),e,s,o,h);break;case 180:l=y(this,Xe,Ul).call(this,c(this,Nt),i,s,-o,h),d=y(this,Xe,Ul).call(this,c(this,ss),i,s,-o,h);break;case 270:l=y(this,Xe,Yl).call(this,c(this,Nt),i,n,-o,-h),d=y(this,Xe,Yl).call(this,c(this,ss),i,n,-o,-h);break}return{outline:Array.from(l),points:[Array.from(d)]}}get box(){return c(this,eo)}newOutliner(e,s,i,n,r,o=0){return new md(e,s,i,n,r,o)}getNewOutline(e,s){const{x:i,y:n,width:r,height:o}=c(this,eo),[h,l,d,u]=c(this,Ca),g=r*d,f=o*u,p=i*d+h,m=n*u+l,_=this.newOutliner({x:c(this,ss)[0]*g+p,y:c(this,ss)[1]*f+m},c(this,Ca),c(this,Cl),e,c(this,Sl),s??c(this,$i));for(let v=2;v<c(this,ss).length;v+=2)_.add({x:c(this,ss)[v]*g+p,y:c(this,ss)[v+1]*f+m});return _.getOutlines()}get mustRemoveSelfIntersections(){return!0}}Ca=new WeakMap,eo=new WeakMap,$i=new WeakMap,Sl=new WeakMap,ss=new WeakMap,Cl=new WeakMap,Nt=new WeakMap,Xe=new WeakSet,Ul=function(e,s,i,n,r){const o=new Float64Array(e.length);for(let h=0,l=e.length;h<l;h+=2)o[h]=s+e[h]*n,o[h+1]=i+e[h+1]*r;return o},Yl=function(e,s,i,n,r){const o=new Float64Array(e.length);for(let h=0,l=e.length;h<l;h+=2)o[h]=s+e[h+1]*n,o[h+1]=i+e[h]*r;return o},ev=function(e){const s=c(this,Nt);let i=s[4],n=s[5],r=i,o=n,h=i,l=n,d=i,u=n;const g=e?Math.max:Math.min;for(let v=6,x=s.length;v<x;v+=6){if(isNaN(s[v]))r=Math.min(r,s[v+4]),o=Math.min(o,s[v+5]),h=Math.max(h,s[v+4]),l=Math.max(l,s[v+5]),u<s[v+5]?(d=s[v+4],u=s[v+5]):u===s[v+5]&&(d=g(d,s[v+4]));else{const S=X.bezierBoundingBox(i,n,...s.slice(v,v+6));r=Math.min(r,S[0]),o=Math.min(o,S[1]),h=Math.max(h,S[2]),l=Math.max(l,S[3]),u<S[3]?(d=S[2],u=S[3]):u===S[3]&&(d=g(d,S[2]))}i=s[v+4],n=s[v+5]}const f=r-c(this,$i),p=o-c(this,$i),m=h-r+2*c(this,$i),_=l-o+2*c(this,$i);b(this,eo,{x:f,y:p,width:m,height:_,lastPoint:[d,u]})};class tb{constructor(t,e=0,s=0,i=!0){w(this,Pe);w(this,Al);w(this,Bn,[]);w(this,js,[]);let n=1/0,r=-1/0,o=1/0,h=-1/0;const d=10**-4;for(const{x:v,y:x,width:S,height:C}of t){const E=Math.floor((v-e)/d)*d,M=Math.ceil((v+S+e)/d)*d,k=Math.floor((x-e)/d)*d,O=Math.ceil((x+C+e)/d)*d,P=[E,k,O,!0],L=[M,k,O,!1];c(this,Bn).push(P,L),n=Math.min(n,E),r=Math.max(r,M),o=Math.min(o,k),h=Math.max(h,O)}const u=r-n+2*s,g=h-o+2*s,f=n-s,p=o-s,m=c(this,Bn).at(i?-1:-2),_=[m[0],m[2]];for(const v of c(this,Bn)){const[x,S,C]=v;v[0]=(x-f)/u,v[1]=(S-p)/g,v[2]=(C-p)/g}b(this,Al,{x:f,y:p,width:u,height:g,lastPoint:_})}getOutlines(){c(this,Bn).sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of c(this,Bn))e[3]?(t.push(...y(this,Pe,Lf).call(this,e)),y(this,Pe,iv).call(this,e)):(y(this,Pe,nv).call(this,e),t.push(...y(this,Pe,Lf).call(this,e)));return y(this,Pe,sv).call(this,t)}}Al=new WeakMap,Bn=new WeakMap,js=new WeakMap,Pe=new WeakSet,sv=function(t){const e=[],s=new Set;for(const r of t){const[o,h,l]=r;e.push([o,h,r],[o,l,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],l=e[r+1][2];h.push(l),l.push(h),s.add(h),s.add(l)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[o,h,l,d,u]=r;s.delete(r);let g=o,f=h;for(n=[o,l],i.push(n);;){let p;if(s.has(d))p=d;else if(s.has(u))p=u;else break;s.delete(p),[o,h,l,d,u]=p,g!==o&&(n.push(g,f,o,f===h?h:l),g=o),f=f===h?l:h}n.push(g,f)}return new xS(i,c(this,Al))},su=function(t){const e=c(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},iv=function([,t,e]){const s=y(this,Pe,su).call(this,t);c(this,js).splice(s,0,[t,e])},nv=function([,t,e]){const s=y(this,Pe,su).call(this,t);for(let i=s;i<c(this,js).length;i++){const[n,r]=c(this,js)[i];if(n!==t)break;if(n===t&&r===e){c(this,js).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=c(this,js)[i];if(n!==t)break;if(n===t&&r===e){c(this,js).splice(i,1);return}}},Lf=function(t){const[e,s,i]=t,n=[[e,s,i]],r=y(this,Pe,su).call(this,i);for(let o=0;o<r;o++){const[h,l]=c(this,js)[o];for(let d=0,u=n.length;d<u;d++){const[,g,f]=n[d];if(!(l<=g||f<=h)){if(g>=h){if(f>l)n[d][1]=l;else{if(u===1)return[];n.splice(d,1),d--,u--}continue}n[d][2]=h,f>l&&n.push([e,l,f])}}}return n};class xS extends J0{constructor(e,s){super();w(this,Tl);w(this,Aa);b(this,Aa,e),b(this,Tl,s)}toSVGPath(){const e=[];for(const s of c(this,Aa)){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,l=n-s;for(const d of c(this,Aa)){const u=new Array(d.length);for(let g=0;g<d.length;g+=2)u[g]=e+d[g]*h,u[g+1]=n-d[g+1]*l;o.push(u)}return o}get box(){return c(this,Tl)}get classNamesForDrawing(){return["highlight"]}get classNamesForOutlining(){return["highlightOutline"]}}Tl=new WeakMap,Aa=new WeakMap;class Yg extends md{newFreeDrawOutline(t,e,s,i,n,r){return new SS(t,e,s,i,n,r)}get classNamesForDrawing(){return["highlight","free"]}}class SS extends Z0{get classNamesForDrawing(){return["highlight","free"]}get classNamesForOutlining(){return["highlightOutline","free"]}newOutliner(t,e,s,i,n,r=0){return new Yg(t,e,s,i,n,r)}}const ze=class ze{constructor({editor:t=null,uiManager:e=null}){w(this,bt);w(this,Ns,null);w(this,so,null);w(this,Ta);w(this,Kt,null);w(this,El,!1);w(this,Ea,!1);w(this,kl,null);w(this,Ml);w(this,Hn,null);w(this,Bs,null);w(this,ka);var s;t?(b(this,Ea,!1),b(this,ka,Y.HIGHLIGHT_COLOR),b(this,kl,t)):(b(this,Ea,!0),b(this,ka,Y.HIGHLIGHT_DEFAULT_COLOR)),b(this,Bs,(t==null?void 0:t._uiManager)||e),b(this,Ml,c(this,Bs)._eventBus),b(this,Ta,(t==null?void 0:t.color)||((s=c(this,Bs))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),c(ze,Ol)||b(ze,Ol,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 ot(this,"_keyboardManager",new fh([[["Escape","mac+Escape"],ze.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],ze.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],ze.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],ze.prototype._moveToPrevious],[["Home","mac+Home"],ze.prototype._moveToBeginning],[["End","mac+End"],ze.prototype._moveToEnd]]))}renderButton(){const t=b(this,Ns,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=c(this,Bs)._signal;t.addEventListener("click",y(this,bt,vo).bind(this),{signal:e}),t.addEventListener("keydown",y(this,bt,If).bind(this),{signal:e});const s=b(this,so,document.createElement("span"));return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=c(this,Ta),t.append(s),t}renderMainDropdown(){const t=b(this,Kt,y(this,bt,Ff).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===c(this,Ns)){y(this,bt,vo).call(this,t);return}const e=t.target.getAttribute("data-color");e&&y(this,bt,Rf).call(this,e,t)}_moveToNext(t){var e,s;if(!c(this,bt,qn)){y(this,bt,vo).call(this,t);return}if(t.target===c(this,Ns)){(e=c(this,Kt).firstChild)==null||e.focus();return}(s=t.target.nextSibling)==null||s.focus()}_moveToPrevious(t){var e,s;if(t.target===((e=c(this,Kt))==null?void 0:e.firstChild)||t.target===c(this,Ns)){c(this,bt,qn)&&this._hideDropdownFromKeyboard();return}c(this,bt,qn)||y(this,bt,vo).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!c(this,bt,qn)){y(this,bt,vo).call(this,t);return}(e=c(this,Kt).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!c(this,bt,qn)){y(this,bt,vo).call(this,t);return}(e=c(this,Kt).lastChild)==null||e.focus()}hideDropdown(){var t,e;(t=c(this,Kt))==null||t.classList.add("hidden"),(e=c(this,Hn))==null||e.abort(),b(this,Hn,null)}_hideDropdownFromKeyboard(){var t;if(!c(this,Ea)){if(!c(this,bt,qn)){(t=c(this,kl))==null||t.unselect();return}this.hideDropdown(),c(this,Ns).focus({preventScroll:!0,focusVisible:c(this,El)})}}updateColor(t){if(c(this,so)&&(c(this,so).style.backgroundColor=t),!c(this,Kt))return;const e=c(this,Bs).highlightColors.values();for(const s of c(this,Kt).children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){var t,e;(t=c(this,Ns))==null||t.remove(),b(this,Ns,null),b(this,so,null),(e=c(this,Kt))==null||e.remove(),b(this,Kt,null)}};Ns=new WeakMap,so=new WeakMap,Ta=new WeakMap,Kt=new WeakMap,El=new WeakMap,Ea=new WeakMap,kl=new WeakMap,Ml=new WeakMap,Hn=new WeakMap,Bs=new WeakMap,ka=new WeakMap,Ol=new WeakMap,bt=new WeakSet,Ff=function(){const t=document.createElement("div"),e=c(this,Bs)._signal;t.addEventListener("contextmenu",hs,{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 c(this,Bs).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",c(ze,Ol)[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===c(this,Ta)),n.addEventListener("click",y(this,bt,Rf).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",y(this,bt,If).bind(this),{signal:e}),t},Rf=function(t,e){e.stopPropagation(),c(this,Ml).dispatch("switchannotationeditorparams",{source:this,type:c(this,ka),value:t})},If=function(t){ze._keyboardManager.exec(this,t)},vo=function(t){if(c(this,bt,qn)){this.hideDropdown();return}if(b(this,El,t.detail===0),c(this,Hn)||(b(this,Hn,new AbortController),window.addEventListener("pointerdown",y(this,bt,rv).bind(this),{signal:c(this,Bs).combinedSignal(c(this,Hn))})),c(this,Kt)){c(this,Kt).classList.remove("hidden");return}const e=b(this,Kt,y(this,bt,Ff).call(this));c(this,Ns).append(e)},rv=function(t){var e;(e=c(this,Kt))!=null&&e.contains(t.target)||this.hideDropdown()},qn=function(){return c(this,Kt)&&!c(this,Kt).classList.contains("hidden")},w(ze,Ol,null);let bd=ze;const ht=class ht extends gt{constructor(e){super({...e,name:"highlightEditor"});w(this,J);w(this,Ma,null);w(this,Dl,0);w(this,Ki);w(this,io,null);w(this,Oa,null);w(this,fs,null);w(this,Pl,null);w(this,Ll,0);w(this,no,null);w(this,Hs,null);w(this,ye,null);w(this,Ve,!1);w(this,Da,null);w(this,Qi);w(this,Qt,null);w(this,Pa,"");w(this,ps);w(this,Fl,"");this.color=e.color||ht._defaultColor,b(this,ps,e.thickness||ht._defaultThickness),b(this,Qi,e.opacity||ht._defaultOpacity),b(this,Ki,e.boxes||null),b(this,Fl,e.methodOfCreation||""),b(this,Pa,e.text||""),this._isDraggable=!1,e.highlightId>-1?(b(this,Ve,!0),y(this,J,iu).call(this,e),y(this,J,yo).call(this)):c(this,Ki)&&(b(this,Ma,e.anchorNode),b(this,Dl,e.anchorOffset),b(this,Pl,e.focusNode),b(this,Ll,e.focusOffset),y(this,J,jf).call(this),y(this,J,yo).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=ht.prototype;return ot(this,"_keyboardManager",new fh([[["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:c(this,Ve)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:c(this,ps),methodOfCreation:c(this,Fl)}}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;gt.initialize(e,s),ht._defaultColor||(ht._defaultColor=((i=s.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,s){switch(e){case Y.HIGHLIGHT_DEFAULT_COLOR:ht._defaultColor=s;break;case Y.HIGHLIGHT_THICKNESS:ht._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return c(this,Da)}updateParams(e,s){switch(e){case Y.HIGHLIGHT_COLOR:y(this,J,ov).call(this,s);break;case Y.HIGHLIGHT_THICKNESS:y(this,J,av).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[Y.HIGHLIGHT_DEFAULT_COLOR,ht._defaultColor],[Y.HIGHLIGHT_THICKNESS,ht._defaultThickness]]}get propertiesToUpdate(){return[[Y.HIGHLIGHT_COLOR,this.color||ht._defaultColor],[Y.HIGHLIGHT_THICKNESS,c(this,ps)||ht._defaultThickness],[Y.HIGHLIGHT_FREE,c(this,Ve)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(b(this,Oa,new bd({editor:this})),e.addColorPicker(c(this,Oa))),e):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(y(this,J,ql).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,y(this,J,ql).call(this))}onceAdded(){this.annotationElementId||this.parent.addUndoableEditor(this),this.div.focus()}remove(){y(this,J,Nf).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(y(this,J,yo).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?y(this,J,Nf).call(this):e&&(y(this,J,yo).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;c(this,Ve)?(e=(e-this.rotation+360)%360,i=y(n=ht,ms,Va).call(n,c(this,Hs).box,e)):i=y(r=ht,ms,Va).call(r,this,e),s.rotate(c(this,ye),e),s.rotate(c(this,Qt),e),s.updateBox(c(this,ye),i),s.updateBox(c(this,Qt),y(o=ht,ms,Va).call(o,c(this,fs).box,e))}render(){if(this.div)return this.div;const e=super.render();c(this,Pa)&&(e.setAttribute("aria-label",c(this,Pa)),e.setAttribute("role","mark")),c(this,Ve)?e.classList.add("free"):this.div.addEventListener("keydown",y(this,J,lv).bind(this),{signal:this._uiManager._signal});const s=b(this,no,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=c(this,io);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),hd(this,c(this,no),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){this.isSelected||this.parent.drawLayer.addClass(c(this,Qt),"hovered")}pointerleave(){this.isSelected||this.parent.drawLayer.removeClass(c(this,Qt),"hovered")}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:y(this,J,nu).call(this,!0);break;case 1:case 3:y(this,J,nu).call(this,!1);break}}select(){var e,s;super.select(),c(this,Qt)&&((e=this.parent)==null||e.drawLayer.removeClass(c(this,Qt),"hovered"),(s=this.parent)==null||s.drawLayer.addClass(c(this,Qt),"selected"))}unselect(){var e;super.unselect(),c(this,Qt)&&((e=this.parent)==null||e.drawLayer.removeClass(c(this,Qt),"selected"),c(this,Ve)||y(this,J,nu).call(this,!1))}get _mustFixPosition(){return!c(this,Ve)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.show(c(this,ye),e),this.parent.drawLayer.show(c(this,Qt),e))}static startHighlighting(e,s,{target:i,x:n,y:r}){const{x:o,y:h,width:l,height:d}=i.getBoundingClientRect(),u=new AbortController,g=e.combinedSignal(u),f=m=>{m.preventDefault(),m.stopPropagation()},p=m=>{u.abort(),y(this,ms,gv).call(this,e,m)};window.addEventListener("blur",p,{signal:g}),window.addEventListener("pointerup",p,{signal:g}),window.addEventListener("pointerdown",f,{capture:!0,passive:!1,signal:g}),window.addEventListener("contextmenu",hs,{signal:g}),i.addEventListener("pointermove",y(this,ms,uv).bind(this,e),{signal:g}),this._freeHighlight=new Yg({x:n,y:r},[o,h,l,d],e.scale,this._defaultThickness/2,s,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw(this._freeHighlight,this._defaultColor,this._defaultOpacity,!0)}static async deserialize(e,s,i){var m,_,v,x;let n=null;if(e instanceof K0){const{data:{quadPoints:S,rect:C,rotation:E,id:M,color:k,opacity:O,popupRef:P},parent:{page:{pageNumber:L}}}=e;n=e={annotationType:Z.HIGHLIGHT,color:Array.from(k),opacity:O,quadPoints:S,boxes:null,pageIndex:L-1,rect:C.slice(0),rotation:E,id:M,deleted:!1,popupRef:P}}else if(e instanceof Gg){const{data:{inkLists:S,rect:C,rotation:E,id:M,color:k,borderStyle:{rawWidth:O},popupRef:P},parent:{page:{pageNumber:L}}}=e;n=e={annotationType:Z.HIGHLIGHT,color:Array.from(k),thickness:O,inkLists:S,boxes:null,pageIndex:L-1,rect:C.slice(0),rotation:E,id:M,deleted:!1,popupRef:P}}const{color:r,quadPoints:o,inkLists:h,opacity:l}=e,d=await super.deserialize(e,s,i);d.color=X.makeHexColor(...r),b(d,Qi,l||1),h&&b(d,ps,e.thickness),d.annotationElementId=e.id||null,d._initialData=n;const[u,g]=d.pageDimensions,[f,p]=d.pageTranslation;if(o){const S=b(d,Ki,[]);for(let C=0;C<o.length;C+=8)S.push({x:(o[C]-f)/u,y:1-(o[C+1]-p)/g,width:(o[C+2]-o[C])/u,height:(o[C+1]-o[C+5])/g});y(m=d,J,jf).call(m),y(_=d,J,yo).call(_),d.rotate(d.rotation)}else if(h){b(d,Ve,!0);const S=h[0],C={x:S[0]-f,y:g-(S[1]-p)},E=new Yg(C,[0,0,u,g],1,c(d,ps)/2,!0,.001);for(let O=0,P=S.length;O<P;O+=2)C.x=S[O]-f,C.y=g-(S[O+1]-p),E.add(C);const{id:M,clipPathId:k}=s.drawLayer.draw(E,d.color,d._defaultOpacity,!0);y(v=d,J,iu).call(v,{highlightOutlines:E.getOutlines(),highlightId:M,clipPathId:k}),y(x=d,J,yo).call(x)}return d}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();const s=this.getRect(0,0),i=gt._colorManager.convert(this.color),n={annotationType:Z.HIGHLIGHT,color:i,opacity:c(this,Qi),thickness:c(this,ps),quadPoints:y(this,J,cv).call(this),outlines:y(this,J,dv).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:y(this,J,ql).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!y(this,J,fv).call(this,n)?null:(n.id=this.annotationElementId,n)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};Ma=new WeakMap,Dl=new WeakMap,Ki=new WeakMap,io=new WeakMap,Oa=new WeakMap,fs=new WeakMap,Pl=new WeakMap,Ll=new WeakMap,no=new WeakMap,Hs=new WeakMap,ye=new WeakMap,Ve=new WeakMap,Da=new WeakMap,Qi=new WeakMap,Qt=new WeakMap,Pa=new WeakMap,ps=new WeakMap,Fl=new WeakMap,J=new WeakSet,jf=function(){const e=new tb(c(this,Ki),.001);b(this,Hs,e.getOutlines()),{x:this.x,y:this.y,width:this.width,height:this.height}=c(this,Hs).box;const s=new tb(c(this,Ki),.0025,.001,this._uiManager.direction==="ltr");b(this,fs,s.getOutlines());const{lastPoint:i}=c(this,fs).box;b(this,Da,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height])},iu=function({highlightOutlines:e,highlightId:s,clipPathId:i}){var u,g;if(b(this,Hs,e),b(this,fs,e.getNewOutline(c(this,ps)/2+1.5,.0025)),s>=0)b(this,ye,s),b(this,io,i),this.parent.drawLayer.finalizeLine(s,e),b(this,Qt,this.parent.drawLayer.drawOutline(c(this,fs)));else if(this.parent){const f=this.parent.viewport.rotation;this.parent.drawLayer.updateLine(c(this,ye),e),this.parent.drawLayer.updateBox(c(this,ye),y(u=ht,ms,Va).call(u,c(this,Hs).box,(f-this.rotation+360)%360)),this.parent.drawLayer.updateLine(c(this,Qt),c(this,fs)),this.parent.drawLayer.updateBox(c(this,Qt),y(g=ht,ms,Va).call(g,c(this,fs).box,f))}const{x:r,y:o,width:h,height:l}=e.box;switch(this.rotation){case 0:this.x=r,this.y=o,this.width=h,this.height=l;break;case 90:{const[f,p]=this.parentDimensions;this.x=o,this.y=1-r,this.width=h*p/f,this.height=l*f/p;break}case 180:this.x=1-r,this.y=1-o,this.width=h,this.height=l;break;case 270:{const[f,p]=this.parentDimensions;this.x=1-o,this.y=r,this.width=h*p/f,this.height=l*f/p;break}}const{lastPoint:d}=c(this,fs).box;b(this,Da,[(d[0]-r)/h,(d[1]-o)/l])},ov=function(e){const s=(r,o)=>{var h,l,d;this.color=r,(h=this.parent)==null||h.drawLayer.changeColor(c(this,ye),r),(l=c(this,Oa))==null||l.updateColor(r),b(this,Qi,o),(d=this.parent)==null||d.drawLayer.changeOpacity(c(this,ye),o)},i=this.color,n=c(this,Qi);this.addCommands({cmd:s.bind(this,e,ht._defaultOpacity),undo:s.bind(this,i,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Y.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},av=function(e){const s=c(this,ps),i=n=>{b(this,ps,n),y(this,J,hv).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:Y.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},hv=function(e){if(!c(this,Ve))return;y(this,J,iu).call(this,{highlightOutlines:c(this,Hs).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},Nf=function(){c(this,ye)===null||!this.parent||(this.parent.drawLayer.remove(c(this,ye)),b(this,ye,null),this.parent.drawLayer.remove(c(this,Qt)),b(this,Qt,null))},yo=function(e=this.parent){c(this,ye)===null&&({id:Fe(this,ye)._,clipPathId:Fe(this,io)._}=e.drawLayer.draw(c(this,Hs),this.color,c(this,Qi)),b(this,Qt,e.drawLayer.drawOutline(c(this,fs))),c(this,no)&&(c(this,no).style.clipPath=c(this,io)))},ms=new WeakSet,Va=function({x:e,y:s,width:i,height:n},r){switch(r){case 90:return{x:1-s-n,y:e,width:n,height:i};case 180:return{x:1-e-i,y:1-s-n,width:i,height:n};case 270:return{x:s,y:1-e-i,width:n,height:i}}return{x:e,y:s,width:i,height:n}},lv=function(e){ht._keyboardManager.exec(this,e)},nu=function(e){if(!c(this,Ma))return;const s=window.getSelection();e?s.setPosition(c(this,Ma),c(this,Dl)):s.setPosition(c(this,Pl),c(this,Ll))},ql=function(){return c(this,Ve)?this.rotation:0},cv=function(){if(c(this,Ve))return null;const[e,s]=this.pageDimensions,[i,n]=this.pageTranslation,r=c(this,Ki),o=new Float32Array(r.length*8);let h=0;for(const{x:l,y:d,width:u,height:g}of r){const f=l*e+i,p=(1-d-g)*s+n;o[h]=o[h+4]=f,o[h+1]=o[h+3]=p,o[h+2]=o[h+6]=f+u*e,o[h+5]=o[h+7]=p+g*s,h+=8}return o},dv=function(e){return c(this,Hs).serialize(e,y(this,J,ql).call(this))},uv=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updatePath(this._freeHighlightId,this._freeHighlight)},gv=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=""},fv=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},w(ht,ms),q(ht,"_defaultColor",null),q(ht,"_defaultOpacity",1),q(ht,"_defaultThickness",12),q(ht,"_type","highlight"),q(ht,"_editorType",Z.HIGHLIGHT),q(ht,"_freeHighlightId",-1),q(ht,"_freeHighlight",null),q(ht,"_freeHighlightClipId","");let vd=ht;const Et=class Et extends gt{constructor(e){super({...e,name:"inkEditor"});w(this,R);w(this,ro,0);w(this,oo,0);w(this,hi,null);w(this,Ji,new Path2D);w(this,bs,!1);w(this,ao,null);w(this,ho,!1);w(this,lo,!1);w(this,Zi,null);w(this,La,null);w(this,co,0);w(this,uo,0);w(this,Wn,null);this.color=e.color||null,this.thickness=e.thickness||null,this.opacity=e.opacity||null,this.paths=[],this.bezierPath2D=[],this.allRawPaths=[],this.currentPath=[],this.scaleFactor=1,this.translationX=this.translationY=0,this.x=0,this.y=0,this._willKeepAspectRatio=!0}static initialize(e,s){gt.initialize(e,s)}static updateDefaultParams(e,s){switch(e){case Y.INK_THICKNESS:Et._defaultThickness=s;break;case Y.INK_COLOR:Et._defaultColor=s;break;case Y.INK_OPACITY:Et._defaultOpacity=s/100;break}}updateParams(e,s){switch(e){case Y.INK_THICKNESS:y(this,R,pv).call(this,s);break;case Y.INK_COLOR:y(this,R,mv).call(this,s);break;case Y.INK_OPACITY:y(this,R,bv).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[Y.INK_THICKNESS,Et._defaultThickness],[Y.INK_COLOR,Et._defaultColor||gt._defaultLineColor],[Y.INK_OPACITY,Math.round(Et._defaultOpacity*100)]]}get propertiesToUpdate(){return[[Y.INK_THICKNESS,this.thickness||Et._defaultThickness],[Y.INK_COLOR,this.color||Et._defaultColor||gt._defaultLineColor],[Y.INK_OPACITY,Math.round(100*(this.opacity??Et._defaultOpacity))]]}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.canvas||(y(this,R,ru).call(this),y(this,R,ou).call(this)),this.isAttachedToDOM||(this.parent.add(this),y(this,R,Ga).call(this)),y(this,R,$l).call(this)))}remove(){var e;this.canvas!==null&&(this.isEmpty()||this.commit(),this.canvas.width=this.canvas.height=0,this.canvas.remove(),this.canvas=null,c(this,hi)&&(clearTimeout(c(this,hi)),b(this,hi,null)),(e=c(this,Zi))==null||e.disconnect(),b(this,Zi,null),super.remove())}setParent(e){!this.parent&&e?this._uiManager.removeShouldRescale(this):this.parent&&e===null&&this._uiManager.addShouldRescale(this),super.setParent(e)}onScaleChanging(){const[e,s]=this.parentDimensions,i=this.width*e,n=this.height*s;this.setDimensions(i,n)}enableEditMode(){c(this,bs)||this.canvas===null||(super.enableEditMode(),this._isDraggable=!1,y(this,R,Wf).call(this))}disableEditMode(){!this.isInEditMode()||this.canvas===null||(super.disableEditMode(),this._isDraggable=!this.isEmpty(),this.div.classList.remove("editing"),y(this,R,Xf).call(this))}onceAdded(){this._isDraggable=!this.isEmpty()}isEmpty(){return this.paths.length===0||this.paths.length===1&&this.paths[0].length===0}commit(){c(this,bs)||(super.commit(),this.isEditing=!1,this.disableEditMode(),this.setInForeground(),b(this,bs,!0),this.div.classList.add("disabled"),y(this,R,$l).call(this,!0),this.select(),this.parent.addInkEditorIfNeeded(!0),this.moveInDOM(),this.div.focus({preventScroll:!0}))}focusin(e){this._focusEventsAllowed&&(super.focusin(e),this.enableEditMode())}canvasPointerdown(e){e.button!==0||!this.isInEditMode()||c(this,bs)||(this.setInForeground(),e.preventDefault(),this.div.contains(document.activeElement)||this.div.focus({preventScroll:!0}),y(this,R,yv).call(this,e.offsetX,e.offsetY))}canvasPointermove(e){e.preventDefault(),y(this,R,Hf).call(this,e.offsetX,e.offsetY)}canvasPointerup(e){e.preventDefault(),y(this,R,zf).call(this,e)}canvasPointerleave(e){y(this,R,zf).call(this,e)}get isResizable(){return!this.isEmpty()&&c(this,bs)}render(){if(this.div)return this.div;let e,s;this.width&&(e=this.x,s=this.y),super.render(),this.div.setAttribute("data-l10n-id","pdfjs-ink");const[i,n,r,o]=y(this,R,vv).call(this);if(this.setAt(i,n,0,0),this.setDims(r,o),y(this,R,ru).call(this),this.width){const[h,l]=this.parentDimensions;this.setAspectRatio(this.width*h,this.height*l),this.setAt(e*h,s*l,this.width*h,this.height*l),b(this,lo,!0),y(this,R,Ga).call(this),this.setDims(this.width*h,this.height*l),y(this,R,_o).call(this),this.div.classList.add("disabled")}else this.div.classList.add("editing"),this.enableEditMode();return y(this,R,ou).call(this),this.div}setDimensions(e,s){const i=Math.round(e),n=Math.round(s);if(c(this,co)===i&&c(this,uo)===n)return;b(this,co,i),b(this,uo,n),this.canvas.style.visibility="hidden";const[r,o]=this.parentDimensions;this.width=e/r,this.height=s/o,this.fixAndSetPosition(),c(this,bs)&&y(this,R,Vf).call(this,e,s),y(this,R,Ga).call(this),y(this,R,_o).call(this),this.canvas.style.visibility="visible",this.fixDims()}static async deserialize(e,s,i){var _,v,x;if(e instanceof Gg)return null;const n=await super.deserialize(e,s,i);n.thickness=e.thickness,n.color=X.makeHexColor(...e.color),n.opacity=e.opacity;const[r,o]=n.pageDimensions,h=n.width*r,l=n.height*o,d=n.parentScale,u=e.thickness/2;b(n,bs,!0),b(n,co,Math.round(h)),b(n,uo,Math.round(l));const{paths:g,rect:f,rotation:p}=e;for(let{bezier:S}of g){S=y(_=Et,tn,Tv).call(_,S,f,p);const C=[];n.paths.push(C);let E=d*(S[0]-u),M=d*(S[1]-u);for(let O=2,P=S.length;O<P;O+=6){const L=d*(S[O]-u),F=d*(S[O+1]-u),W=d*(S[O+2]-u),B=d*(S[O+3]-u),z=d*(S[O+4]-u),K=d*(S[O+5]-u);C.push([[E,M],[L,F],[W,B],[z,K]]),E=z,M=K}const k=y(this,tn,Av).call(this,C);n.bezierPath2D.push(k)}const m=y(v=n,R,Uf).call(v);return b(n,oo,Math.max(gt.MIN_SIZE,m[2]-m[0])),b(n,ro,Math.max(gt.MIN_SIZE,m[3]-m[1])),y(x=n,R,Vf).call(x,h,l),n}serialize(){if(this.isEmpty())return null;const e=this.getRect(0,0),s=gt._colorManager.convert(this.ctx.strokeStyle);return{annotationType:Z.INK,color:s,thickness:this.thickness,opacity:this.opacity,paths:y(this,R,Ev).call(this,this.scaleFactor/this.parentScale,this.translationX,this.translationY,e),pageIndex:this.pageIndex,rect:e,rotation:this.rotation,structTreeParentId:this._structTreeParentId}}};ro=new WeakMap,oo=new WeakMap,hi=new WeakMap,Ji=new WeakMap,bs=new WeakMap,ao=new WeakMap,ho=new WeakMap,lo=new WeakMap,Zi=new WeakMap,La=new WeakMap,co=new WeakMap,uo=new WeakMap,Wn=new WeakMap,R=new WeakSet,pv=function(e){const s=n=>{this.thickness=n,y(this,R,$l).call(this)},i=this.thickness;this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Y.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0})},mv=function(e){const s=n=>{this.color=n,y(this,R,_o).call(this)},i=this.color;this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Y.INK_COLOR,overwriteIfSameType:!0,keepUndo:!0})},bv=function(e){const s=n=>{this.opacity=n,y(this,R,_o).call(this)};e/=100;const i=this.opacity;this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Y.INK_OPACITY,overwriteIfSameType:!0,keepUndo:!0})},vv=function(){const{parentRotation:e,parentDimensions:[s,i]}=this;switch(e){case 90:return[0,i,i,s];case 180:return[s,i,s,i];case 270:return[s,0,i,s];default:return[0,0,s,i]}},Bf=function(){const{ctx:e,color:s,opacity:i,thickness:n,parentScale:r,scaleFactor:o}=this;e.lineWidth=n*r/o,e.lineCap="round",e.lineJoin="round",e.miterLimit=10,e.strokeStyle=`${s}${Gw(i)}`},yv=function(e,s){this.canvas.addEventListener("contextmenu",hs,{signal:this._uiManager._signal}),y(this,R,Xf).call(this),b(this,ao,new AbortController);const i=this._uiManager.combinedSignal(c(this,ao));this.canvas.addEventListener("pointerleave",this.canvasPointerleave.bind(this),{signal:i}),this.canvas.addEventListener("pointermove",this.canvasPointermove.bind(this),{signal:i}),this.canvas.addEventListener("pointerup",this.canvasPointerup.bind(this),{signal:i}),this.isEditing=!0,c(this,lo)||(b(this,lo,!0),y(this,R,Ga).call(this),this.thickness||(this.thickness=Et._defaultThickness),this.color||(this.color=Et._defaultColor||gt._defaultLineColor),this.opacity??(this.opacity=Et._defaultOpacity)),this.currentPath.push([e,s]),b(this,ho,!1),y(this,R,Bf).call(this),b(this,Wn,()=>{y(this,R,xv).call(this),c(this,Wn)&&window.requestAnimationFrame(c(this,Wn))}),window.requestAnimationFrame(c(this,Wn))},Hf=function(e,s){const[i,n]=this.currentPath.at(-1);if(this.currentPath.length>1&&e===i&&s===n)return;const r=this.currentPath;let o=c(this,Ji);if(r.push([e,s]),b(this,ho,!0),r.length<=2){o.moveTo(...r[0]),o.lineTo(e,s);return}r.length===3&&(b(this,Ji,o=new Path2D),o.moveTo(...r[0])),y(this,R,Sv).call(this,o,...r.at(-3),...r.at(-2),e,s)},_v=function(){if(this.currentPath.length===0)return;const e=this.currentPath.at(-1);c(this,Ji).lineTo(...e)},wv=function(e,s){b(this,Wn,null),e=Math.min(Math.max(e,0),this.canvas.width),s=Math.min(Math.max(s,0),this.canvas.height),y(this,R,Hf).call(this,e,s),y(this,R,_v).call(this);let i;if(this.currentPath.length!==1)i=y(this,R,Cv).call(this);else{const l=[e,s];i=[[l,l.slice(),l.slice(),l]]}const n=c(this,Ji),r=this.currentPath;this.currentPath=[],b(this,Ji,new Path2D);const o=()=>{this.allRawPaths.push(r),this.paths.push(i),this.bezierPath2D.push(n),this._uiManager.rebuild(this)},h=()=>{this.allRawPaths.pop(),this.paths.pop(),this.bezierPath2D.pop(),this.paths.length===0?this.remove():(this.canvas||(y(this,R,ru).call(this),y(this,R,ou).call(this)),y(this,R,$l).call(this))};this.addCommands({cmd:o,undo:h,mustExec:!0})},xv=function(){if(!c(this,ho))return;b(this,ho,!1);const e=Math.ceil(this.thickness*this.parentScale),s=this.currentPath.slice(-3),i=s.map(o=>o[0]),n=s.map(o=>o[1]);Math.min(...i)-e,Math.max(...i)+e,Math.min(...n)-e,Math.max(...n)+e;const{ctx:r}=this;r.save(),r.clearRect(0,0,this.canvas.width,this.canvas.height);for(const o of this.bezierPath2D)r.stroke(o);r.stroke(c(this,Ji)),r.restore()},Sv=function(e,s,i,n,r,o,h){const l=(s+n)/2,d=(i+r)/2,u=(n+o)/2,g=(r+h)/2;e.bezierCurveTo(l+2*(n-l)/3,d+2*(r-d)/3,u+2*(n-u)/3,g+2*(r-g)/3,u,g)},Cv=function(){const e=this.currentPath;if(e.length<=2)return[[e[0],e[0],e.at(-1),e.at(-1)]];const s=[];let i,[n,r]=e[0];for(i=1;i<e.length-2;i++){const[f,p]=e[i],[m,_]=e[i+1],v=(f+m)/2,x=(p+_)/2,S=[n+2*(f-n)/3,r+2*(p-r)/3],C=[v+2*(f-v)/3,x+2*(p-x)/3];s.push([[n,r],S,C,[v,x]]),[n,r]=[v,x]}const[o,h]=e[i],[l,d]=e[i+1],u=[n+2*(o-n)/3,r+2*(h-r)/3],g=[l+2*(o-l)/3,d+2*(h-d)/3];return s.push([[n,r],u,g,[l,d]]),s},_o=function(){if(this.isEmpty()){y(this,R,au).call(this);return}y(this,R,Bf).call(this);const{canvas:e,ctx:s}=this;s.setTransform(1,0,0,1,0,0),s.clearRect(0,0,e.width,e.height),y(this,R,au).call(this);for(const i of this.bezierPath2D)s.stroke(i)},Wf=function(){if(c(this,La))return;b(this,La,new AbortController);const e=this._uiManager.combinedSignal(c(this,La));this.canvas.addEventListener("pointerdown",this.canvasPointerdown.bind(this),{signal:e})},Xf=function(){var e;(e=this.pointerdownAC)==null||e.abort(),this.pointerdownAC=null},zf=function(e){var s;(s=c(this,ao))==null||s.abort(),b(this,ao,null),y(this,R,Wf).call(this),c(this,hi)&&clearTimeout(c(this,hi)),b(this,hi,setTimeout(()=>{b(this,hi,null),this.canvas.removeEventListener("contextmenu",hs)},10)),y(this,R,wv).call(this,e.offsetX,e.offsetY),this.addToAnnotationStorage(),this.setInBackground()},ru=function(){this.canvas=document.createElement("canvas"),this.canvas.width=this.canvas.height=0,this.canvas.className="inkEditorCanvas",this.canvas.setAttribute("data-l10n-id","pdfjs-ink-canvas"),this.div.append(this.canvas),this.ctx=this.canvas.getContext("2d")},ou=function(){b(this,Zi,new ResizeObserver(e=>{const s=e[0].contentRect;s.width&&s.height&&this.setDimensions(s.width,s.height)})),c(this,Zi).observe(this.div),this._uiManager._signal.addEventListener("abort",()=>{var e;(e=c(this,Zi))==null||e.disconnect(),b(this,Zi,null)},{once:!0})},Ga=function(){if(!c(this,lo))return;const[e,s]=this.parentDimensions;this.canvas.width=Math.ceil(this.width*e),this.canvas.height=Math.ceil(this.height*s),y(this,R,au).call(this)},Vf=function(e,s){const i=y(this,R,hu).call(this),n=(e-i)/c(this,oo),r=(s-i)/c(this,ro);this.scaleFactor=Math.min(n,r)},au=function(){const e=y(this,R,hu).call(this)/2;this.ctx.setTransform(this.scaleFactor,0,0,this.scaleFactor,this.translationX*this.scaleFactor+e,this.translationY*this.scaleFactor+e)},tn=new WeakSet,Av=function(e){const s=new Path2D;for(let i=0,n=e.length;i<n;i++){const[r,o,h,l]=e[i];i===0&&s.moveTo(...r),s.bezierCurveTo(o[0],o[1],h[0],h[1],l[0],l[1])}return s},Gf=function(e,s,i){const[n,r,o,h]=s;switch(i){case 0:for(let l=0,d=e.length;l<d;l+=2)e[l]+=n,e[l+1]=h-e[l+1];break;case 90:for(let l=0,d=e.length;l<d;l+=2){const u=e[l];e[l]=e[l+1]+n,e[l+1]=u+r}break;case 180:for(let l=0,d=e.length;l<d;l+=2)e[l]=o-e[l],e[l+1]+=r;break;case 270:for(let l=0,d=e.length;l<d;l+=2){const u=e[l];e[l]=o-e[l+1],e[l+1]=h-u}break;default:throw new Error("Invalid rotation")}return e},Tv=function(e,s,i){const[n,r,o,h]=s;switch(i){case 0:for(let l=0,d=e.length;l<d;l+=2)e[l]-=n,e[l+1]=h-e[l+1];break;case 90:for(let l=0,d=e.length;l<d;l+=2){const u=e[l];e[l]=e[l+1]-r,e[l+1]=u-n}break;case 180:for(let l=0,d=e.length;l<d;l+=2)e[l]=o-e[l],e[l+1]-=r;break;case 270:for(let l=0,d=e.length;l<d;l+=2){const u=e[l];e[l]=h-e[l+1],e[l+1]=o-u}break;default:throw new Error("Invalid rotation")}return e},Ev=function(e,s,i,n){var d,u;const r=[],o=this.thickness/2,h=e*s+o,l=e*i+o;for(const g of this.paths){const f=[],p=[];for(let m=0,_=g.length;m<_;m++){const[v,x,S,C]=g[m];if(v[0]===C[0]&&v[1]===C[1]&&_===1){const B=e*v[0]+h,z=e*v[1]+l;f.push(B,z),p.push(B,z);break}const E=e*v[0]+h,M=e*v[1]+l,k=e*x[0]+h,O=e*x[1]+l,P=e*S[0]+h,L=e*S[1]+l,F=e*C[0]+h,W=e*C[1]+l;m===0&&(f.push(E,M),p.push(E,M)),f.push(k,O,P,L,F,W),p.push(k,O),m===_-1&&p.push(F,W)}r.push({bezier:y(d=Et,tn,Gf).call(d,f,n,this.rotation),points:y(u=Et,tn,Gf).call(u,p,n,this.rotation)})}return r},Uf=function(){let e=1/0,s=-1/0,i=1/0,n=-1/0;for(const r of this.paths)for(const[o,h,l,d]of r){const u=X.bezierBoundingBox(...o,...h,...l,...d);e=Math.min(e,u[0]),i=Math.min(i,u[1]),s=Math.max(s,u[2]),n=Math.max(n,u[3])}return[e,i,s,n]},hu=function(){return c(this,bs)?Math.ceil(this.thickness*this.parentScale):0},$l=function(e=!1){if(this.isEmpty())return;if(!c(this,bs)){y(this,R,_o).call(this);return}const s=y(this,R,Uf).call(this),i=y(this,R,hu).call(this);b(this,oo,Math.max(gt.MIN_SIZE,s[2]-s[0])),b(this,ro,Math.max(gt.MIN_SIZE,s[3]-s[1]));const n=Math.ceil(i+c(this,oo)*this.scaleFactor),r=Math.ceil(i+c(this,ro)*this.scaleFactor),[o,h]=this.parentDimensions;this.width=n/o,this.height=r/h,this.setAspectRatio(n,r);const l=this.translationX,d=this.translationY;this.translationX=-s[0],this.translationY=-s[1],y(this,R,Ga).call(this),y(this,R,_o).call(this),b(this,co,n),b(this,uo,r),this.setDims(n,r);const u=e?i/this.scaleFactor/2:0;this.translate(l-this.translationX-u,d-this.translationY-u)},w(Et,tn),q(Et,"_defaultColor",null),q(Et,"_defaultOpacity",1),q(Et,"_defaultThickness",1),q(Et,"_type","ink"),q(Et,"_editorType",Z.INK);let qg=Et;const Rl=class Rl extends gt{constructor(e){super({...e,name:"stampEditor"});w(this,nt);w(this,kt,null);w(this,ae,null);w(this,Xn,null);w(this,en,null);w(this,zn,null);w(this,Fa,"");w(this,li,null);w(this,sn,null);w(this,ci,null);w(this,is,!1);w(this,Ra,!1);b(this,en,e.bitmapUrl),b(this,zn,e.bitmapFile)}static initialize(e,s){gt.initialize(e,s)}static get supportedTypes(){return ot(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return ot(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(e){return this.supportedTypes.includes(e)}static paste(e,s){s.pasteEditor(Z.STAMP,{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){var e;return{type:"stamp",hasAltText:!!((e=this.altTextData)!=null&&e.altText)}}static computeTelemetryFinalData(e){const s=e.get("hasAltText");return{hasAltText:s.get(!0)??0,hasNoAltText:s.get(!1)??0}}async mlGuessAltText(e=null,s=!0){if(this.hasAltTextData())return null;const{mlManager:i}=this._uiManager;if(!i)throw new Error("No ML.");if(!await i.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:n,width:r,height:o}=e||this.copyCanvas(null,null,!0).imageData,h=await i.guess({name:"altText",request:{data:n,width:r,height:o,channels:n.length/(r*o)}});if(!h)throw new Error("No response from the AI service.");if(h.error)throw new Error("Error from the AI service.");if(h.cancel)return null;if(!h.output)throw new Error("No valid response from the AI service.");const l=h.output;return await this.setGuessedAltText(l),s&&!this.hasAltTextData()&&(this.altTextData={alt:l,decorative:!1}),l}remove(){var e,s;c(this,ae)&&(b(this,kt,null),this._uiManager.imageManager.deleteId(c(this,ae)),(e=c(this,li))==null||e.remove(),b(this,li,null),(s=c(this,sn))==null||s.disconnect(),b(this,sn,null),c(this,ci)&&(clearTimeout(c(this,ci)),b(this,ci,null))),super.remove()}rebuild(){if(!this.parent){c(this,ae)&&y(this,nt,lu).call(this);return}super.rebuild(),this.div!==null&&(c(this,ae)&&c(this,li)===null&&y(this,nt,lu).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(){this._isDraggable=!0,this.div.focus()}isEmpty(){return!(c(this,Xn)||c(this,kt)||c(this,en)||c(this,zn)||c(this,ae))}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(),c(this,kt)?y(this,nt,Yf).call(this):y(this,nt,lu).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.div}copyCanvas(e,s,i=!1){var f;e||(e=224);const{width:n,height:r}=c(this,kt),o=new Ag;let h=c(this,kt),l=n,d=r,u=null;if(s){if(n>s||r>s){const O=Math.min(s/n,s/r);l=Math.floor(n*O),d=Math.floor(r*O)}u=document.createElement("canvas");const p=u.width=Math.ceil(l*o.sx),m=u.height=Math.ceil(d*o.sy);c(this,is)||(h=y(this,nt,cu).call(this,p,m));const _=u.getContext("2d");_.filter=this._uiManager.hcmFilter;let v="white",x="#cfcfd8";this._uiManager.hcmFilter!=="none"?x="black":(f=window.matchMedia)!=null&&f.call(window,"(prefers-color-scheme: dark)").matches&&(v="#8f8f9d",x="#42414d");const S=15,C=S*o.sx,E=S*o.sy,M=new OffscreenCanvas(C*2,E*2),k=M.getContext("2d");k.fillStyle=v,k.fillRect(0,0,C*2,E*2),k.fillStyle=x,k.fillRect(0,0,C,E),k.fillRect(C,E,C,E),_.fillStyle=_.createPattern(M,"repeat"),_.fillRect(0,0,p,m),_.drawImage(h,0,0,h.width,h.height,0,0,p,m)}let g=null;if(i){let p,m;if(o.symmetric&&h.width<e&&h.height<e)p=h.width,m=h.height;else if(h=c(this,kt),n>e||r>e){const x=Math.min(e/n,e/r);p=Math.floor(n*x),m=Math.floor(r*x),c(this,is)||(h=y(this,nt,cu).call(this,p,m))}const v=new OffscreenCanvas(p,m).getContext("2d",{willReadFrequently:!0});v.drawImage(h,0,0,h.width,h.height,0,0,p,m),g={width:p,height:m,data:v.getImageData(0,0,p,m).data}}return{canvas:u,width:l,height:d,imageData:g}}getImageForAltText(){return c(this,li)}static async deserialize(e,s,i){var m;let n=null;if(e instanceof Q0){const{data:{rect:_,rotation:v,id:x,structParent:S,popupRef:C},container:E,parent:{page:{pageNumber:M}}}=e,k=E.querySelector("canvas"),O=i.imageManager.getFromCanvas(E.id,k);k.remove();const P=((m=await s._structTree.getAriaAttributes(`${_g}${x}`))==null?void 0:m.get("aria-label"))||"";n=e={annotationType:Z.STAMP,bitmapId:O.id,bitmap:O.bitmap,pageIndex:M-1,rect:_.slice(0),rotation:v,id:x,deleted:!1,accessibilityData:{decorative:!1,altText:P},isSvg:!1,structParent:S,popupRef:C}}const r=await super.deserialize(e,s,i),{rect:o,bitmap:h,bitmapUrl:l,bitmapId:d,isSvg:u,accessibilityData:g}=e;d&&i.imageManager.isValidId(d)?(b(r,ae,d),h&&b(r,kt,h)):b(r,en,l),b(r,is,u);const[f,p]=r.pageDimensions;return r.width=(o[2]-o[0])/f,r.height=(o[3]-o[1])/p,r.annotationElementId=e.id||null,g&&(r.altTextData=g),r._initialData=n,b(r,Ra,!!n),r}serialize(e=!1,s=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const i={annotationType:Z.STAMP,bitmapId:c(this,ae),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:c(this,is),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=y(this,nt,du).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=y(this,nt,Ov).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=c(this,is)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!s.stamps.has(c(this,ae)))s.stamps.set(c(this,ae),{area:o,serialized:i}),i.bitmap=y(this,nt,du).call(this,!1);else if(c(this,is)){const h=s.stamps.get(c(this,ae));o>h.area&&(h.area=o,h.serialized.bitmap.close(),h.serialized.bitmap=y(this,nt,du).call(this,!1))}return i}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}};kt=new WeakMap,ae=new WeakMap,Xn=new WeakMap,en=new WeakMap,zn=new WeakMap,Fa=new WeakMap,li=new WeakMap,sn=new WeakMap,ci=new WeakMap,is=new WeakMap,Ra=new WeakMap,nt=new WeakSet,Kl=function(e,s=!1){if(!e){this.remove();return}b(this,kt,e.bitmap),s||(b(this,ae,e.id),b(this,is,e.isSvg)),e.file&&b(this,Fa,e.file.name),y(this,nt,Yf).call(this)},Ql=function(){if(b(this,Xn,null),this._uiManager.enableWaiting(!1),!!c(this,li)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&c(this,kt)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&c(this,kt)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},lu=function(){if(c(this,ae)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(c(this,ae)).then(i=>y(this,nt,Kl).call(this,i,!0)).finally(()=>y(this,nt,Ql).call(this));return}if(c(this,en)){const i=c(this,en);b(this,en,null),this._uiManager.enableWaiting(!0),b(this,Xn,this._uiManager.imageManager.getFromUrl(i).then(n=>y(this,nt,Kl).call(this,n)).finally(()=>y(this,nt,Ql).call(this)));return}if(c(this,zn)){const i=c(this,zn);b(this,zn,null),this._uiManager.enableWaiting(!0),b(this,Xn,this._uiManager.imageManager.getFromFile(i).then(n=>y(this,nt,Kl).call(this,n)).finally(()=>y(this,nt,Ql).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=Rl.supportedTypesStr;const s=this._uiManager._signal;b(this,Xn,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}}),y(this,nt,Kl).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>y(this,nt,Ql).call(this))),e.click()},Yf=function(){const{div:e}=this;let{width:s,height:i}=c(this,kt);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 u=Math.min(o*n/s,o*r/i);s*=u,i*=u}const[h,l]=this.parentDimensions;this.setDims(s*h/n,i*l/r),this._uiManager.enableWaiting(!1);const d=b(this,li,document.createElement("canvas"));d.setAttribute("role","img"),this.addContainer(d),(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),y(this,nt,qf).call(this,s,i),y(this,nt,Mv).call(this),c(this,Ra)||(this.parent.addUndoableEditor(this),b(this,Ra,!0)),this._reportTelemetry({action:"inserted_image"}),c(this,Fa)&&d.setAttribute("aria-label",c(this,Fa))},kv=function(e,s){var o;const[i,n]=this.parentDimensions;this.width=e/i,this.height=s/n,(o=this._initialOptions)!=null&&o.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,c(this,ci)!==null&&clearTimeout(c(this,ci)),b(this,ci,setTimeout(()=>{b(this,ci,null),y(this,nt,qf).call(this,e,s)},200))},cu=function(e,s){const{width:i,height:n}=c(this,kt);let r=i,o=n,h=c(this,kt);for(;r>2*e||o>2*s;){const l=r,d=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 u=new OffscreenCanvas(r,o);u.getContext("2d").drawImage(h,0,0,l,d,0,0,r,o),h=u.transferToImageBitmap()}return h},qf=function(e,s){const i=new Ag,n=Math.ceil(e*i.sx),r=Math.ceil(s*i.sy),o=c(this,li);if(!o||o.width===n&&o.height===r)return;o.width=n,o.height=r;const h=c(this,is)?c(this,kt):y(this,nt,cu).call(this,n,r),l=o.getContext("2d");l.filter=this._uiManager.hcmFilter,l.drawImage(h,0,0,h.width,h.height,0,0,n,r)},du=function(e){if(e){if(c(this,is)){const n=this._uiManager.imageManager.getSvgUrl(c(this,ae));if(n)return n}const s=document.createElement("canvas");return{width:s.width,height:s.height}=c(this,kt),s.getContext("2d").drawImage(c(this,kt),0,0),s.toDataURL()}if(c(this,is)){const[s,i]=this.pageDimensions,n=Math.round(this.width*s*mn.PDF_TO_CSS_UNITS),r=Math.round(this.height*i*mn.PDF_TO_CSS_UNITS),o=new OffscreenCanvas(n,r);return o.getContext("2d").drawImage(c(this,kt),0,0,c(this,kt).width,c(this,kt).height,0,0,n,r),o.transferToImageBitmap()}return structuredClone(c(this,kt))},Mv=function(){this._uiManager._signal&&(b(this,sn,new ResizeObserver(e=>{const s=e[0].contentRect;s.width&&s.height&&y(this,nt,kv).call(this,s.width,s.height)})),c(this,sn).observe(this.div),this._uiManager._signal.addEventListener("abort",()=>{var e;(e=c(this,sn))==null||e.disconnect(),b(this,sn,null)},{once:!0}))},Ov=function(e){var l;const{rect:s,pageIndex:i,accessibilityData:{altText:n}}=this._initialData,r=e.rect.every((d,u)=>Math.abs(d-s[u])<1),o=e.pageIndex===i,h=(((l=e.accessibilityData)==null?void 0:l.alt)||"")===n;return{isSame:r&&o&&h,isSameAltText:h}},q(Rl,"_type","stamp"),q(Rl,"_editorType",Z.STAMP);let $g=Rl;const Ws=class Ws{constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:o,textLayer:h,viewport:l,l10n:d}){w(this,he);w(this,go);w(this,Ia,!1);w(this,di,null);w(this,Vn,null);w(this,nn,null);w(this,ns,new Map);w(this,Gn,!1);w(this,ja,!1);w(this,Na,!1);w(this,_e,null);w(this,rn,null);w(this,G);const u=[...c(Ws,Un).values()];if(!Ws._initialized){Ws._initialized=!0;for(const g of u)g.initialize(d,t)}t.registerEditorTypes(u),b(this,G,t),this.pageIndex=e,this.div=s,b(this,go,n),b(this,di,r),this.viewport=l,b(this,_e,h),this.drawLayer=o,this._structTree=i,c(this,G).addLayer(this)}get isEmpty(){return c(this,ns).size===0}get isInvisible(){return this.isEmpty&&c(this,G).getMode()===Z.NONE}updateToolbar(t){c(this,G).updateToolbar(t)}updateMode(t=c(this,G).getMode()){switch(y(this,he,uu).call(this),t){case Z.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case Z.INK:this.addInkEditorIfNeeded(!1),this.disableTextSelection(),this.togglePointerEvents(!0),this.disableClick();break;case Z.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:e}=this.div;for(const s of c(Ws,Un).values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=c(this,_e))==null?void 0:e.div)}addInkEditorIfNeeded(t){if(c(this,G).getMode()!==Z.INK)return;if(!t){for(const s of c(this,ns).values())if(s.isEmpty()){s.setInBackground();return}}this.createAndAddNewEditor({offsetX:0,offsetY:0},!1).setInBackground()}setEditingState(t){c(this,G).setEditingState(t)}addCommands(t){c(this,G).addCommands(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=c(this,di))==null||e.div.classList.toggle("disabled",!t)}async enable(){this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of c(this,ns).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(c(this,G).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!c(this,di))return;const e=c(this,di).getEditableAnnotations();for(const s of e){if(s.hide(),c(this,G).isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}}disable(){var i;b(this,Na,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const n of c(this,ns).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(c(this,di)){const n=c(this,di).getEditableAnnotations();for(const r of n){const{id:o}=r.data;if(c(this,G).isDeletedAnnotationElement(o))continue;let h=e.get(o);if(h){h.resetAnnotationElement(r),h.show(!1),r.show();continue}h=t.get(o),h&&(c(this,G).addChangedExistingAnnotation(h),h.renderAnnotationElement(r)&&h.show(!1)),r.show()}}y(this,he,uu).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of c(Ws,Un).values())s.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),b(this,Na,!1)}getEditableAnnotation(t){var e;return((e=c(this,di))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){c(this,G).getActive()!==t&&c(this,G).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=c(this,_e))!=null&&t.div&&!c(this,rn)){b(this,rn,new AbortController);const e=c(this,G).combinedSignal(c(this,rn));c(this,_e).div.addEventListener("pointerdown",y(this,he,Dv).bind(this),{signal:e}),c(this,_e).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=c(this,_e))!=null&&t.div&&c(this,rn)&&(c(this,rn).abort(),b(this,rn,null),c(this,_e).div.classList.remove("highlighting"))}enableClick(){if(c(this,Vn))return;b(this,Vn,new AbortController);const t=c(this,G).combinedSignal(c(this,Vn));this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t}),this.div.addEventListener("pointerup",this.pointerup.bind(this),{signal:t})}disableClick(){var t;(t=c(this,Vn))==null||t.abort(),b(this,Vn,null)}attach(t){c(this,ns).set(t.id,t);const{annotationElementId:e}=t;e&&c(this,G).isDeletedAnnotationElement(e)&&c(this,G).removeDeletedAnnotationElement(t)}detach(t){var e;c(this,ns).delete(t.id),(e=c(this,go))==null||e.removePointerInTextLayer(t.contentDiv),!c(this,Na)&&t.annotationElementId&&c(this,G).addDeletedAnnotationElement(t)}remove(t){this.detach(t),c(this,G).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1,c(this,ja)||this.addInkEditorIfNeeded(!1)}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(c(this,G).addDeletedAnnotationElement(t.annotationElementId),gt.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),c(this,G).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(),c(this,G).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!c(this,nn)&&(t._focusEventsAllowed=!1,b(this,nn,setTimeout(()=>{b(this,nn,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:c(this,G)._signal}),e.focus())},0))),t._structTreeParentId=(s=c(this,go))==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 c(this,G).getId()}combinedSignal(t){return c(this,G).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=c(this,he,$f))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){c(this,G).updateToolbar(t),c(this,G).updateMode(t);const{offsetX:s,offsetY:i}=y(this,he,Qf).call(this),n=this.getNextId(),r=y(this,he,Kf).call(this,{parent:this,id:n,x:s,y:i,uiManager:c(this,G),isCentered:!0,...e});r&&this.add(r)}async deserialize(t){var e;return await((e=c(Ws,Un).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,c(this,G)))||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=y(this,he,Kf).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:c(this,G),isCentered:e,...s});return n&&this.add(n),n}addNewEditor(){this.createAndAddNewEditor(y(this,he,Qf).call(this),!0)}setSelected(t){c(this,G).setSelected(t)}toggleSelected(t){c(this,G).toggleSelected(t)}unselect(t){c(this,G).unselect(t)}pointerup(t){const{isMac:e}=ke.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&c(this,Gn)){if(b(this,Gn,!1),!c(this,Ia)){b(this,Ia,!0);return}if(c(this,G).getMode()===Z.STAMP){c(this,G).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){if(c(this,G).getMode()===Z.HIGHLIGHT&&this.enableTextSelection(),c(this,Gn)){b(this,Gn,!1);return}const{isMac:e}=ke.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;b(this,Gn,!0);const s=c(this,G).getActive();b(this,Ia,!s||s.isEmpty())}findNewParent(t,e,s){const i=c(this,G).findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}destroy(){var t,e;((t=c(this,G).getActive())==null?void 0:t.parent)===this&&(c(this,G).commitOrRemove(),c(this,G).setActiveEditor(null)),c(this,nn)&&(clearTimeout(c(this,nn)),b(this,nn,null));for(const s of c(this,ns).values())(e=c(this,go))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,c(this,ns).clear(),c(this,G).removeLayer(this)}render({viewport:t}){this.viewport=t,cr(this.div,t);for(const e of c(this,G).getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){c(this,G).commitOrRemove(),y(this,he,uu).call(this);const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,cr(this.div,{rotation:s}),e!==s)for(const i of c(this,ns).values())i.rotate(s);this.addInkEditorIfNeeded(!1)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return c(this,G).viewParameters.realScale}};go=new WeakMap,Ia=new WeakMap,di=new WeakMap,Vn=new WeakMap,nn=new WeakMap,ns=new WeakMap,Gn=new WeakMap,ja=new WeakMap,Na=new WeakMap,_e=new WeakMap,rn=new WeakMap,G=new WeakMap,Un=new WeakMap,he=new WeakSet,Dv=function(t){c(this,G).unselectAll();const{target:e}=t;if(e===c(this,_e).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&c(this,_e).div.contains(e)){const{isMac:s}=ke.platform;if(t.button!==0||t.ctrlKey&&s)return;c(this,G).showAllEditors("highlight",!0,!0),c(this,_e).div.classList.add("free"),this.toggleDrawing(),vd.startHighlighting(this,c(this,G).direction==="ltr",{target:c(this,_e).div,x:t.x,y:t.y}),c(this,_e).div.addEventListener("pointerup",()=>{c(this,_e).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:c(this,G)._signal}),t.preventDefault()}},$f=function(){return c(Ws,Un).get(c(this,G).getMode())},Kf=function(t){const e=c(this,he,$f);return e?new e.prototype.constructor(t):null},Qf=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),l=(n+o)/2-t,d=(r+h)/2-e,[u,g]=this.viewport.rotation%180===0?[l,d]:[d,l];return{offsetX:u,offsetY:g}},uu=function(){b(this,ja,!0);for(const t of c(this,ns).values())t.isEmpty()&&t.remove();b(this,ja,!1)},q(Ws,"_initialized",!1),w(Ws,Un,new Map([Ug,qg,$g,vd].map(t=>[t._editorType,t])));let Kg=Ws;const le=class le{constructor({pageIndex:t}){w(this,fo);w(this,ui,null);w(this,Il,0);w(this,Xt,new Map);w(this,on,new Map);this.pageIndex=t}setParent(t){if(!c(this,ui)){b(this,ui,t);return}if(c(this,ui)!==t){if(c(this,Xt).size>0)for(const e of c(this,Xt).values())e.remove(),t.append(e);b(this,ui,t)}}static get _svgFactory(){return ot(this,"_svgFactory",new zg)}draw(t,e,s,i=!1){const n=Fe(this,Il)._++,r=y(this,fo,Zf).call(this,t.box);r.classList.add(...t.classNamesForDrawing);const o=le._svgFactory.createElement("defs");r.append(o);const h=le._svgFactory.createElement("path");o.append(h);const l=`path_p${this.pageIndex}_${n}`;h.setAttribute("id",l),h.setAttribute("d",t.toSVGPath()),i&&c(this,on).set(n,h);const d=y(this,fo,Pv).call(this,o,l),u=le._svgFactory.createElement("use");return r.append(u),r.setAttribute("fill",e),r.setAttribute("fill-opacity",s),u.setAttribute("href",`#${l}`),c(this,Xt).set(n,r),{id:n,clipPathId:`url(#${d})`}}drawOutline(t){const e=Fe(this,Il)._++,s=y(this,fo,Zf).call(this,t.box);s.classList.add(...t.classNamesForOutlining);const i=le._svgFactory.createElement("defs");s.append(i);const n=le._svgFactory.createElement("path");i.append(n);const r=`path_p${this.pageIndex}_${e}`;n.setAttribute("id",r),n.setAttribute("d",t.toSVGPath()),n.setAttribute("vector-effect","non-scaling-stroke");let o;if(t.mustRemoveSelfIntersections){const d=le._svgFactory.createElement("mask");i.append(d),o=`mask_p${this.pageIndex}_${e}`,d.setAttribute("id",o),d.setAttribute("maskUnits","objectBoundingBox");const u=le._svgFactory.createElement("rect");d.append(u),u.setAttribute("width","1"),u.setAttribute("height","1"),u.setAttribute("fill","white");const g=le._svgFactory.createElement("use");d.append(g),g.setAttribute("href",`#${r}`),g.setAttribute("stroke","none"),g.setAttribute("fill","black"),g.setAttribute("fill-rule","nonzero"),g.classList.add("mask")}const h=le._svgFactory.createElement("use");s.append(h),h.setAttribute("href",`#${r}`),o&&h.setAttribute("mask",`url(#${o})`);const l=h.cloneNode();return s.append(l),h.classList.add("mainOutline"),l.classList.add("secondaryOutline"),c(this,Xt).set(e,s),e}finalizeLine(t,e){const s=c(this,on).get(t);c(this,on).delete(t),this.updateBox(t,e.box),s.setAttribute("d",e.toSVGPath())}updateLine(t,e){c(this,Xt).get(t).firstChild.firstChild.setAttribute("d",e.toSVGPath())}updatePath(t,e){c(this,on).get(t).setAttribute("d",e.toSVGPath())}updateBox(t,e){var s;y(s=le,jl,Jf).call(s,c(this,Xt).get(t),e)}show(t,e){c(this,Xt).get(t).classList.toggle("hidden",!e)}rotate(t,e){c(this,Xt).get(t).setAttribute("data-main-rotation",e)}changeColor(t,e){c(this,Xt).get(t).setAttribute("fill",e)}changeOpacity(t,e){c(this,Xt).get(t).setAttribute("fill-opacity",e)}addClass(t,e){c(this,Xt).get(t).classList.add(e)}removeClass(t,e){c(this,Xt).get(t).classList.remove(e)}getSVGRoot(t){return c(this,Xt).get(t)}remove(t){c(this,on).delete(t),c(this,ui)!==null&&(c(this,Xt).get(t).remove(),c(this,Xt).delete(t))}destroy(){b(this,ui,null);for(const t of c(this,Xt).values())t.remove();c(this,Xt).clear(),c(this,on).clear()}};ui=new WeakMap,Il=new WeakMap,Xt=new WeakMap,on=new WeakMap,jl=new WeakSet,Jf=function(t,{x:e=0,y:s=0,width:i=1,height:n=1}={}){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`},fo=new WeakSet,Zf=function(t){var s;const e=le._svgFactory.create(1,1,!0);return c(this,ui).append(e),e.setAttribute("aria-hidden",!0),y(s=le,jl,Jf).call(s,e,t),e},Pv=function(t,e){const s=le._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=le._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i},w(le,jl);let Qg=le;$.AbortException,$.AnnotationEditorLayer,$.AnnotationEditorParamsType,$.AnnotationEditorType,$.AnnotationEditorUIManager,$.AnnotationLayer,$.AnnotationMode,$.ColorPicker,$.DOMSVGFactory,$.DrawLayer,$.FeatureTest;var CS=$.GlobalWorkerOptions;$.ImageKind,$.InvalidPDFException,$.MissingPDFException,$.OPS,$.OutputScale,$.PDFDataRangeTransport,$.PDFDateString,$.PDFWorker,$.PasswordResponses,$.PermissionFlag,$.PixelsPerInch,$.RenderingCancelledException,$.TextLayer,$.UnexpectedResponseException,$.Util,$.VerbosityLevel,$.XfaLayer,$.build,$.createValidAbsoluteUrl,$.fetchData;var AS=$.getDocument;$.getFilenameFromUrl,$.getPdfFilenameFromUrl,$.getXfaPageViewport,$.isDataScheme,$.isPdfFile,$.noContextMenu,$.normalizeUnicode,$.setLayerDimensions,$.shadow,$.version;const TS={fabric:"^6.4.3","pdfjs-dist":"^4.8.69"};function ES(a){return new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>t(s.result)),s.addEventListener("error",e),s.readAsDataURL(a)})}const kS=TS["pdfjs-dist"].replace("^","");CS.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${kS}/pdf.worker.min.mjs`;async function MS(a){const t="data:application/pdf;base64,",e=await ES(a);if(typeof e=="string")return window.atob(e.slice(t.length))}function OS(a,t){return AS({data:a,password:t}).promise}const DS={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},PS={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},LS={stroke:"#000",hoverStroke:"#B7EC5D",src:""};function eb(a=""){let t=0,e=null,s=null,i=1,n={...LS};function r(){if(!a||as.has(a))return;const k=gw(a);return k.on("selection:cleared",()=>C(k)),k}function o(k,O){const P=k.type;return{"application/pdf":h,"image/png":u,"image/jpeg":u}[P](k,O)??Promise.reject(new Error(`Unsupported ${P} file type.`))}async function h(k,O){const P=await MS(k);if(!P)return;const L=fw(k,P);try{return await l({page:1,PDFBase64:P,scale:.8,password:O}),{...L,pages:t}}catch(F){return Promise.reject(F)}}async function l({page:k,PDFBase64:O,scale:P,password:L}){try{const F=await OS(O,L),W=await U.toRaw(F).getPage(k),{renderTask:B,canvas:z}=pw(W,P);return t=F.numPages,B.promise.then(()=>d(z))}catch(F){return Promise.reject(F)}}function d(k){bw(a,k)}async function u(k){return await vw(a,k)}async function g({url:k,scale:O=.5}){await r0(a,{url:k,scale:O})}async function f(k,O){const P=as.get(a);if(!P)return;const L=await fe.fromURL(k,{},{...DS,...O});P.add(L),m(P,L)}function p(k,O){const P=as.get(a);if(!P)return;const L=new ge(k,{...PS,...O});P.add(L),m(P,L)}function m(k,O){O.on("selected",P=>_({canvas:k,target:P.target})),O.on("modified",P=>lh(P.target,e)),O.on("scaling",P=>lh(P.transform.target,e)),O.on("moving",P=>lh(P.transform.target,e)),O.on("rotating",P=>lh(P.transform.target,e))}async function _({canvas:k,target:O,stroke:P=n.stroke,uuid:L=Date.now()}){if((e==null?void 0:e.stroke)===`${P}-${L}`)return;const F=await mw(n.src,P,L);C(k),e=F,s=O,v(k,O,L),x(i,!0),k.add(F)}function v(k,O,P){e&&(e.on("selected",()=>{k.remove(O),C(k)}),e.on("mouseover",()=>{_({canvas:k,target:O,stroke:n.hoverStroke,uuid:P})}),e.on("mouseout",()=>{_({canvas:k,target:O,stroke:n.stroke,uuid:P})}))}function x(k,O=!1){const P=as.get(a);i=k,P&&(_w(s,k,n),yw(s,k,e),!O&&P.renderAll())}function S(k){if(!k)return;n={...n,...k};const O=as.get(a);!e||!s||!O||_({target:s,canvas:O})}function C(k){e&&(k.remove(e),e=s=null)}function E(){ww(a)}function M(){xw(a)}return{createCanvas:r,loadFile:o,specifyPage:l,renderImage:g,addFabric:f,addTextFabric:p,clearActive:E,deleteCanvas:M,scaleFabric:x,setCloseSvgOptions:S}}function FS(a){let t=0;const e=uw(()=>{t!==window.innerWidth&&(t=window.innerWidth,a())});U.onMounted(()=>{window.addEventListener("resize",e)}),U.onBeforeUnmount(()=>{window.removeEventListener("resize",e)})}const RS=U.defineComponent({__name:"pdf-canvas",props:{file:{},page:{default:1},canvasId:{default:"PDF-canvas"},fileZoom:{default:1},fileScale:{default:1},canvasScale:{default:1},canvasClass:{default:""},isDrop:{type:Boolean,default:!1},password:{},dropTextOptions:{},dropImageOptions:{},closeSvgOptions:{}},setup(a,{expose:t}){const e=a,s=U.ref(null),i=`${e.canvasId}-${e.page-1}`,n=U.computed(()=>e.fileZoom*e.canvasScale),{createCanvas:r,specifyPage:o,addFabric:h,addTextFabric:l,renderImage:d,clearActive:u,deleteCanvas:g,scaleFabric:f,setCloseSvgOptions:p}=eb(i);m(),FS(m);async function m(){const{file:S,page:C,fileScale:E}=e;window.requestAnimationFrame(async()=>{if(await U.nextTick(),r(),S.PDFBase64.startsWith("data:image")||S.canvas){const{canvas:M}=S,k=M?7:3,O=M!=null&&M.length?M[C-1]:S.PDFBase64;d({url:O,scale:E/k});return}await o({page:C,PDFBase64:S.PDFBase64,scale:E,password:e.password})})}function _(S){if(!e.isDrop||!S.dataTransfer)return;const{dataTransfer:C,offsetX:E,offsetY:M}=S,k=C.getData("text"),O=C.getData("image"),P={left:E-71,top:M-55};O&&v(O,P),k&&x(k,P)}function v(S,C){h(S,{...C,...e.dropImageOptions})}function x(S,C){l(S,{...C,...e.dropTextOptions})}return U.watch([()=>e.fileScale,()=>e.page,()=>e.file,()=>e.password],m),U.watch(n,S=>f(S),{immediate:!0}),U.watch(()=>e.closeSvgOptions,p,{immediate:!0}),U.onBeforeUnmount(g),t({addImage:v,addText:x,clearActive:u,deleteCanvas:g,canvasRef:s}),(S,C)=>(U.openBlock(),U.createElementBlock("div",{style:U.normalizeStyle({transform:`scale(${n.value})`}),onDragover:C[0]||(C[0]=U.withModifiers(()=>{},["stop","prevent"])),onDragenter:C[1]||(C[1]=U.withModifiers(()=>{},["stop","prevent"])),onDrop:U.withModifiers(_,["stop","prevent"])},[U.createElementVNode("canvas",{id:i,ref_key:"canvasRef",ref:s,class:U.normalizeClass(S.canvasClass)},null,2)],36))}}),yd=Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"}));rt.default=RS,rt.useFabric=eb,Object.defineProperties(rt,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});