@component-hook/pdf-canvas 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- (function(dt,Z){typeof exports=="object"&&typeof module<"u"?Z(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],Z):(dt=typeof globalThis<"u"?globalThis:dt||self,Z(dt["pdf-canvas"]={},dt.React))})(this,function(dt,Z){"use strict";var YA=Object.defineProperty;var Vb=dt=>{throw TypeError(dt)};var $A=(dt,Z,Ht)=>Z in dt?YA(dt,Z,{enumerable:!0,configurable:!0,writable:!0,value:Ht}):dt[Z]=Ht;var Q=(dt,Z,Ht)=>$A(dt,typeof Z!="symbol"?Z+"":Z,Ht),Sp=(dt,Z,Ht)=>Z.has(dt)||Vb("Cannot "+Ht);var l=(dt,Z,Ht)=>(Sp(dt,Z,"read from private field"),Ht?Ht.call(dt):Z.get(dt)),_=(dt,Z,Ht)=>Z.has(dt)?Vb("Cannot add the same private member more than once"):Z instanceof WeakSet?Z.add(dt):Z.set(dt,Ht),v=(dt,Z,Ht,Hn)=>(Sp(dt,Z,"write to private field"),Hn?Hn.call(dt,Ht):Z.set(dt,Ht),Ht),w=(dt,Z,Ht)=>(Sp(dt,Z,"access private method"),Ht);var es=(dt,Z,Ht,Hn)=>({set _(Dr){v(dt,Z,Dr,Ht)},get _(){return l(dt,Z,Hn)}});var on,Qd,Cp,_l,Qn,Qr,ai,Zr,wl,xl,Pd,Wb,Ye,Gb,Xb,Zd,Ub,Ap,Sl,ta,ea,Zn,Yb,$b,qb,Md,Po,Cl,Fe,Mo,tf,Jt,tr,Al,Wt,Od,Kb,Oo,ys,ce,_e,Do,ln,Ro,Ns,er,sa,Fo,ia,Pi,oi,na,Tl,El,Lo,kl,Mi,sr,Io,ir,Oi,Rd,nr,Pl,rr,ra,Ml,Ol,ge,Ct,cn,aa,Dl,Rl,ar,Di,un,Fl,Bs,H,ef,Tp,Jb,Qb,sf,Zb,ty,ey,Ep,sy,kp,Pp,iy,ss,Nn,ny,ry,Mp,ay,Yc,Op,pe,Ri,hi,No,Fi,_s,Bo,Li,ls,dn,oa,Ii,or,li,$c,nf,Ll,ha,Il,jl,Nl,Bl,Hl,Ho,fn,la,hr,gn,oy,hy,Dp,ca,ci,Rt,zo,lr,zl,ua,we,da,pn,cr,Vl,fa,ws,Wl,ga,mn,ji,Vo,Wo,Hs,pa,Gl,Fd,J,Rp,Xl,Fp,rf,ly,cy,Lp,af,Ip,uy,dy,fy,jp,gy,Np,py,my,vy,Bp,qc,ma,va,me,Ld,by,Ul,Go,Xo,zs,yy,_y,wy,of,Yl,ba,Uo,vn,bn,Le,ya,_a,G,Be,Kc,Nh,hf,Bh,xy,Hp,Hh,Jc,Qc,zp,Zc,ui,Vp,Wp,Gp,$l,ql,wa,Kl,Jl,Ql,Zl,Yo,ur,At,$o,qo,tc,Xp,Eb,dr,cs,ec,sc,xa,yn,ic,nc,Sa,Ko,Jo,fr,Qo,rc,Zo,Ca,ac,oc,Aa,Ta,hc,gr,th,_n,Sy,Cy,Up,xs,lf,Yp,Ay,Ty,jd,pr,wn,Vs,zh,cf,xn,Bd,Hd,Ea,ka,eh,uf,sh,df,Sn,Ni,ih,nh,Cn,Pa,tu,Ss,lc,$p,mr,vr,Ma,Da,rh,ah,cc,qp,Cs,ao,Ey,ky,oh,zd,Vd,hh,Ra,Yt,An,lh,uc,dc,ch,Tn,di,En,fc,kn,gc,Fa,La,Tt,ff,Kp,Py,My,Oy,Dy,gf,pf,Jp,pc,mc,vc,bc,yc,Ia,_c,Qp,wc,xc,Zp,Sc,ja,Na,Cc,Ba,Ry,tm,fi,As,Ac,Ha,Ts,re,Fy,Ly,Iy,mf,Pn,vf,bf,jy,em,Ny,Es,gi,uh,dh,Bi,ut,za,Va,Tc,Ec,fh,gh,br,kc,Wd,Gd,de,eu,By,Hy,zy,Vy,Wy,Gy,ph,Wa,On,Pc,ks,Mc,Qt,Xd,Xy,Oc,Dc,yr,pi,qe,Uy,yf,Yy,$y,sm,Rc,mh,mi,Ga,vh,fe,Fc,bh,Lc,Ic,_r,vi,yh,jc,Et,im,nm,rm,oo,qy,Or,_h,Nc,Dn,Xa,wh,ds,Bc,Hc,Ua,Ws,Ps,xe,xh,Rn,Ie,Sh,Gs,zc,at,am,_f,Ky,Jy,Qy,om,ho,Xs,Vh,Zy,wf,su,t_,e_,s_,i_,n_,Ya,Ms,Ch,ve,$a,qa,wr,xr,Sr,Ka,mt,hm,lm,cm,iu,r_,xf,nu,Wh,Hi,be,ye,Ja,Ah,Ke,Se,Us,Qa,Za,to,Th,Sf,Je,Vc,Wc,Os,zi,Vi,Eh,kh,Ph,Ce,Bn,a_,o_,h_,Mh,Ud,l_,Gt,Ae,Cr,Fn,Ar,Dh,Wi,Gi,Ds,Rh,vt,ru,au,Cf,um,Af,dm,Tf,c_,eo,Fh,Xi,Tr,Ln,Ys,Er,Lh,so,bi,In,je,jn,$,kr,Nt,u_,Yi,fm,gm,Ef,_i,Xc,Qe,io,Yd,d_,Ui,pm,f_,mm;var Ht=typeof document<"u"?document.currentScript:null,Hn={exports:{}},Dr={};/**
1
+ (function(dt,tt){typeof exports=="object"&&typeof module<"u"?tt(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],tt):(dt=typeof globalThis<"u"?globalThis:dt||self,tt(dt["pdf-canvas"]={},dt.React))})(this,function(dt,tt){"use strict";var eT=Object.defineProperty;var $b=dt=>{throw TypeError(dt)};var sT=(dt,tt,Ht)=>tt in dt?eT(dt,tt,{enumerable:!0,configurable:!0,writable:!0,value:Ht}):dt[tt]=Ht;var Q=(dt,tt,Ht)=>sT(dt,typeof tt!="symbol"?tt+"":tt,Ht),Tp=(dt,tt,Ht)=>tt.has(dt)||$b("Cannot "+Ht);var l=(dt,tt,Ht)=>(Tp(dt,tt,"read from private field"),Ht?Ht.call(dt):tt.get(dt)),_=(dt,tt,Ht)=>tt.has(dt)?$b("Cannot add the same private member more than once"):tt instanceof WeakSet?tt.add(dt):tt.set(dt,Ht),v=(dt,tt,Ht,qi)=>(Tp(dt,tt,"write to private field"),qi?qi.call(dt,Ht):tt.set(dt,Ht),Ht),w=(dt,tt,Ht)=>(Tp(dt,tt,"access private method"),Ht);var es=(dt,tt,Ht,qi)=>({set _(Dr){v(dt,tt,Dr,Ht)},get _(){return l(dt,tt,qi)}});var ln,tf,Ep,Sl,Qn,Zr,ri,to,Cl,Al,Od,qb,Ye,Kb,Jb,ef,Qb,kp,Tl,eo,so,Zn,Zb,ty,ey,Dd,Ma,El,Fe,Oa,sf,Jt,tr,kl,Gt,Rd,sy,Da,ys,ce,_e,Ra,un,Fa,js,er,io,La,no,Mi,oi,ro,Pl,Ml,Ia,Ol,Oi,sr,ja,ir,Di,Ld,nr,Dl,rr,oo,Rl,Fl,ge,Ct,dn,ao,Ll,Il,or,Ri,fn,jl,Ns,B,nf,Pp,iy,ny,rf,ry,oy,ay,Mp,hy,Op,Dp,ly,ss,Hn,cy,uy,Rp,dy,Kc,Fp,pe,Fi,ai,Ba,Li,_s,Ha,Ii,ls,gn,ho,ji,ar,hi,Jc,of,Nl,lo,Bl,Hl,zl,Vl,Gl,za,pn,co,hr,mn,fy,gy,Lp,uo,li,Rt,Va,lr,Wl,fo,we,go,vn,cr,Xl,po,ws,Ul,mo,bn,Ni,Ga,Wa,Bs,vo,Yl,Id,J,Ip,$l,jp,af,py,my,Np,hf,Bp,vy,by,yy,Hp,_y,zp,wy,xy,Sy,Vp,Qc,bo,yo,me,jd,Cy,ql,Xa,Ua,Hs,Ay,Ty,Ey,lf,Kl,_o,Ya,yn,_n,Le,wo,xo,W,Be,Zc,Bh,cf,Hh,ky,Gp,zh,tu,eu,Wp,su,ci,Xp,Up,Yp,Jl,Ql,So,Zl,tc,ec,sc,$a,ur,At,qa,Ka,ic,$p,Rb,dr,cs,nc,rc,Co,wn,oc,ac,Ao,Ja,Qa,fr,Za,hc,th,To,lc,cc,Eo,ko,uc,gr,eh,xn,Py,My,qp,xs,uf,Kp,Oy,Dy,Bd,pr,Sn,zs,Vh,df,Cn,zd,Vd,Po,Mo,sh,ff,ih,gf,An,Bi,nh,rh,Tn,Oo,iu,Ss,dc,Jp,mr,vr,Do,Fo,oh,ah,fc,Qp,Cs,ha,Ry,Fy,hh,Gd,Wd,lh,Lo,Yt,En,ch,gc,pc,uh,kn,ui,Pn,mc,Mn,vc,Io,jo,Tt,pf,Zp,Ly,Iy,jy,Ny,mf,vf,tm,bc,yc,_c,wc,xc,No,Sc,em,Cc,Ac,sm,Tc,Bo,Ho,Ec,zo,By,im,di,As,kc,Vo,Ts,re,Hy,zy,Vy,bf,On,yf,_f,Gy,nm,Wy,Es,fi,dh,fh,Hi,ut,Go,Wo,Pc,Mc,gh,ph,br,Oc,Xd,Ud,de,nu,Xy,Uy,Yy,$y,qy,Ky,mh,Xo,Rn,Dc,ks,Rc,Qt,Yd,Jy,Fc,Lc,yr,gi,qe,Qy,wf,Zy,t_,rm,Ic,vh,pi,Uo,bh,fe,jc,yh,Nc,Bc,_r,mi,_h,Hc,Et,om,am,hm,la,e_,Or,wh,zc,Fn,Yo,xh,ds,Vc,Gc,$o,Vs,Ps,xe,Sh,Ln,Ie,Ch,Gs,Wc,ot,lm,xf,s_,i_,n_,cm,ca,Ws,Gh,r_,Sf,ru,o_,a_,h_,l_,c_,qo,Ms,Ah,ve,Ko,Jo,wr,xr,Sr,Qo,vt,um,dm,fm,ou,u_,Cf,au,Wh,zi,be,ye,Zo,Th,Ke,Se,Xs,ta,ea,sa,Eh,Af,Je,Xc,Uc,Os,Vi,Gi,kh,Ph,Mh,Ce,zn,d_,f_,g_,Oh,$d,p_,Wt,Ae,Cr,In,Ar,Rh,Wi,Xi,Ds,Fh,bt,hu,lu,Tf,gm,Ef,pm,kf,m_,ia,Lh,Ui,Tr,jn,Us,Er,Ih,na,vi,Nn,je,Bn,$,kr,Nt,v_,$i,mm,vm,Pf,yi,$c,Qe,ra,qd,b_,Yi,bm,y_,ym;var Ht=typeof document<"u"?document.currentScript:null,qi={exports:{}},Dr={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var vm;function g_(){if(vm)return Dr;vm=1;var o=Z,t=Symbol.for("react.element"),e=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,i=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,n={key:!0,ref:!0,__self:!0,__source:!0};function r(a,h,c){var u,d={},f=null,g=null;c!==void 0&&(f=""+c),h.key!==void 0&&(f=""+h.key),h.ref!==void 0&&(g=h.ref);for(u in h)s.call(h,u)&&!n.hasOwnProperty(u)&&(d[u]=h[u]);if(a&&a.defaultProps)for(u in h=a.defaultProps,h)d[u]===void 0&&(d[u]=h[u]);return{$$typeof:t,type:a,key:f,ref:g,props:d,_owner:i.current}}return Dr.Fragment=e,Dr.jsx=r,Dr.jsxs=r,Dr}var Gh={};/**
9
+ */var _m;function __(){if(_m)return Dr;_m=1;var a=tt,t=Symbol.for("react.element"),e=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,i=a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,n={key:!0,ref:!0,__self:!0,__source:!0};function r(o,h,c){var u,d={},f=null,g=null;c!==void 0&&(f=""+c),h.key!==void 0&&(f=""+h.key),h.ref!==void 0&&(g=h.ref);for(u in h)s.call(h,u)&&!n.hasOwnProperty(u)&&(d[u]=h[u]);if(o&&o.defaultProps)for(u in h=o.defaultProps,h)d[u]===void 0&&(d[u]=h[u]);return{$$typeof:t,type:o,key:f,ref:g,props:d,_owner:i.current}}return Dr.Fragment=e,Dr.jsx=r,Dr.jsxs=r,Dr}var Xh={};/**
10
10
  * @license React
11
11
  * react-jsx-runtime.development.js
12
12
  *
@@ -14,48 +14,48 @@
14
14
  *
15
15
  * This source code is licensed under the MIT license found in the
16
16
  * LICENSE file in the root directory of this source tree.
17
- */var bm;function p_(){return bm||(bm=1,process.env.NODE_ENV!=="production"&&function(){var o=Z,t=Symbol.for("react.element"),e=Symbol.for("react.portal"),s=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),n=Symbol.for("react.profiler"),r=Symbol.for("react.provider"),a=Symbol.for("react.context"),h=Symbol.for("react.forward_ref"),c=Symbol.for("react.suspense"),u=Symbol.for("react.suspense_list"),d=Symbol.for("react.memo"),f=Symbol.for("react.lazy"),g=Symbol.for("react.offscreen"),p=Symbol.iterator,m="@@iterator";function y(A){if(A===null||typeof A!="object")return null;var j=p&&A[p]||A[m];return typeof j=="function"?j:null}var b=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function x(A){{for(var j=arguments.length,X=new Array(j>1?j-1:0),et=1;et<j;et++)X[et-1]=arguments[et];S("error",A,X)}}function S(A,j,X){{var et=b.ReactDebugCurrentFrame,xt=et.getStackAddendum();xt!==""&&(j+="%s",X=X.concat([xt]));var Pt=X.map(function(pt){return String(pt)});Pt.unshift("Warning: "+j),Function.prototype.apply.call(console[A],console,Pt)}}var C=!1,k=!1,O=!1,P=!1,D=!1,R;R=Symbol.for("react.module.reference");function z(A){return!!(typeof A=="string"||typeof A=="function"||A===s||A===n||D||A===i||A===c||A===u||P||A===g||C||k||O||typeof A=="object"&&A!==null&&(A.$$typeof===f||A.$$typeof===d||A.$$typeof===r||A.$$typeof===a||A.$$typeof===h||A.$$typeof===R||A.getModuleId!==void 0))}function B(A,j,X){var et=A.displayName;if(et)return et;var xt=j.displayName||j.name||"";return xt!==""?X+"("+xt+")":X}function F(A){return A.displayName||"Context"}function L(A){if(A==null)return null;if(typeof A.tag=="number"&&x("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof A=="function")return A.displayName||A.name||null;if(typeof A=="string")return A;switch(A){case s:return"Fragment";case e:return"Portal";case n:return"Profiler";case i:return"StrictMode";case c:return"Suspense";case u:return"SuspenseList"}if(typeof A=="object")switch(A.$$typeof){case a:var j=A;return F(j)+".Consumer";case r:var X=A;return F(X._context)+".Provider";case h:return B(A,A.render,"ForwardRef");case d:var et=A.displayName||null;return et!==null?et:L(A.type)||"Memo";case f:{var xt=A,Pt=xt._payload,pt=xt._init;try{return L(pt(Pt))}catch{return null}}}return null}var N=Object.assign,K=0,I,V,it,Ot,Bt,Xt,Ft;function _t(){}_t.__reactDisabledLog=!0;function ae(){{if(K===0){I=console.log,V=console.info,it=console.warn,Ot=console.error,Bt=console.group,Xt=console.groupCollapsed,Ft=console.groupEnd;var A={configurable:!0,enumerable:!0,value:_t,writable:!0};Object.defineProperties(console,{info:A,log:A,warn:A,error:A,group:A,groupCollapsed:A,groupEnd:A})}K++}}function Ze(){{if(K--,K===0){var A={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:N({},A,{value:I}),info:N({},A,{value:V}),warn:N({},A,{value:it}),error:N({},A,{value:Ot}),group:N({},A,{value:Bt}),groupCollapsed:N({},A,{value:Xt}),groupEnd:N({},A,{value:Ft})})}K<0&&x("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var st=b.ReactCurrentDispatcher,nt;function Zt(A,j,X){{if(nt===void 0)try{throw Error()}catch(xt){var et=xt.stack.trim().match(/\n( *(at )?)/);nt=et&&et[1]||""}return`
18
- `+nt+A}}var $s=!1,Te;{var $d=typeof WeakMap=="function"?WeakMap:Map;Te=new $d}function Uc(A,j){if(!A||$s)return"";{var X=Te.get(A);if(X!==void 0)return X}var et;$s=!0;var xt=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var Pt;Pt=st.current,st.current=null,ae();try{if(j){var pt=function(){throw Error()};if(Object.defineProperty(pt.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(pt,[])}catch(fs){et=fs}Reflect.construct(A,[],pt)}else{try{pt.call()}catch(fs){et=fs}A.call(pt.prototype)}}else{try{throw Error()}catch(fs){et=fs}A()}}catch(fs){if(fs&&et&&typeof fs.stack=="string"){for(var ft=fs.stack.split(`
19
- `),ts=et.stack.split(`
20
- `),te=ft.length-1,oe=ts.length-1;te>=1&&oe>=0&&ft[te]!==ts[oe];)oe--;for(;te>=1&&oe>=0;te--,oe--)if(ft[te]!==ts[oe]){if(te!==1||oe!==1)do if(te--,oe--,oe<0||ft[te]!==ts[oe]){var qs=`
21
- `+ft[te].replace(" at new "," at ");return A.displayName&&qs.includes("<anonymous>")&&(qs=qs.replace("<anonymous>",A.displayName)),typeof A=="function"&&Te.set(A,qs),qs}while(te>=1&&oe>=0);break}}}finally{$s=!1,st.current=Pt,Ze(),Error.prepareStackTrace=xt}var jh=A?A.displayName||A.name:"",ro=jh?Zt(jh):"";return typeof A=="function"&&Te.set(A,ro),ro}function qd(A,j,X){return Uc(A,!1)}function Pr(A){var j=A.prototype;return!!(j&&j.isReactComponent)}function no(A,j,X){if(A==null)return"";if(typeof A=="function")return Uc(A,Pr(A));if(typeof A=="string")return Zt(A);switch(A){case c:return Zt("Suspense");case u:return Zt("SuspenseList")}if(typeof A=="object")switch(A.$$typeof){case h:return qd(A.render);case d:return no(A.type,j,X);case f:{var et=A,xt=et._payload,Pt=et._init;try{return no(Pt(xt),j,X)}catch{}}}return""}var Mr=Object.prototype.hasOwnProperty,kb={},Pb=b.ReactDebugCurrentFrame;function Kd(A){if(A){var j=A._owner,X=no(A.type,A._source,j?j.type:null);Pb.setExtraStackFrame(X)}else Pb.setExtraStackFrame(null)}function AA(A,j,X,et,xt){{var Pt=Function.call.bind(Mr);for(var pt in A)if(Pt(A,pt)){var ft=void 0;try{if(typeof A[pt]!="function"){var ts=Error((et||"React class")+": "+X+" type `"+pt+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof A[pt]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw ts.name="Invariant Violation",ts}ft=A[pt](j,pt,et,X,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(te){ft=te}ft&&!(ft instanceof Error)&&(Kd(xt),x("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",et||"React class",X,pt,typeof ft),Kd(null)),ft instanceof Error&&!(ft.message in kb)&&(kb[ft.message]=!0,Kd(xt),x("Failed %s type: %s",X,ft.message),Kd(null))}}}var TA=Array.isArray;function bp(A){return TA(A)}function EA(A){{var j=typeof Symbol=="function"&&Symbol.toStringTag,X=j&&A[Symbol.toStringTag]||A.constructor.name||"Object";return X}}function kA(A){try{return Mb(A),!1}catch{return!0}}function Mb(A){return""+A}function Ob(A){if(kA(A))return x("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",EA(A)),Mb(A)}var Db=b.ReactCurrentOwner,PA={key:!0,ref:!0,__self:!0,__source:!0},Rb,Fb;function MA(A){if(Mr.call(A,"ref")){var j=Object.getOwnPropertyDescriptor(A,"ref").get;if(j&&j.isReactWarning)return!1}return A.ref!==void 0}function OA(A){if(Mr.call(A,"key")){var j=Object.getOwnPropertyDescriptor(A,"key").get;if(j&&j.isReactWarning)return!1}return A.key!==void 0}function DA(A,j){typeof A.ref=="string"&&Db.current}function RA(A,j){{var X=function(){Rb||(Rb=!0,x("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",j))};X.isReactWarning=!0,Object.defineProperty(A,"key",{get:X,configurable:!0})}}function FA(A,j){{var X=function(){Fb||(Fb=!0,x("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",j))};X.isReactWarning=!0,Object.defineProperty(A,"ref",{get:X,configurable:!0})}}var LA=function(A,j,X,et,xt,Pt,pt){var ft={$$typeof:t,type:A,key:j,ref:X,props:pt,_owner:Pt};return ft._store={},Object.defineProperty(ft._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(ft,"_self",{configurable:!1,enumerable:!1,writable:!1,value:et}),Object.defineProperty(ft,"_source",{configurable:!1,enumerable:!1,writable:!1,value:xt}),Object.freeze&&(Object.freeze(ft.props),Object.freeze(ft)),ft};function IA(A,j,X,et,xt){{var Pt,pt={},ft=null,ts=null;X!==void 0&&(Ob(X),ft=""+X),OA(j)&&(Ob(j.key),ft=""+j.key),MA(j)&&(ts=j.ref,DA(j,xt));for(Pt in j)Mr.call(j,Pt)&&!PA.hasOwnProperty(Pt)&&(pt[Pt]=j[Pt]);if(A&&A.defaultProps){var te=A.defaultProps;for(Pt in te)pt[Pt]===void 0&&(pt[Pt]=te[Pt])}if(ft||ts){var oe=typeof A=="function"?A.displayName||A.name||"Unknown":A;ft&&RA(pt,oe),ts&&FA(pt,oe)}return LA(A,ft,ts,xt,et,Db.current,pt)}}var yp=b.ReactCurrentOwner,Lb=b.ReactDebugCurrentFrame;function Ih(A){if(A){var j=A._owner,X=no(A.type,A._source,j?j.type:null);Lb.setExtraStackFrame(X)}else Lb.setExtraStackFrame(null)}var _p;_p=!1;function wp(A){return typeof A=="object"&&A!==null&&A.$$typeof===t}function Ib(){{if(yp.current){var A=L(yp.current.type);if(A)return`
17
+ */var wm;function w_(){return wm||(wm=1,process.env.NODE_ENV!=="production"&&function(){var a=tt,t=Symbol.for("react.element"),e=Symbol.for("react.portal"),s=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),n=Symbol.for("react.profiler"),r=Symbol.for("react.provider"),o=Symbol.for("react.context"),h=Symbol.for("react.forward_ref"),c=Symbol.for("react.suspense"),u=Symbol.for("react.suspense_list"),d=Symbol.for("react.memo"),f=Symbol.for("react.lazy"),g=Symbol.for("react.offscreen"),p=Symbol.iterator,m="@@iterator";function y(A){if(A===null||typeof A!="object")return null;var N=p&&A[p]||A[m];return typeof N=="function"?N:null}var b=a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function x(A){{for(var N=arguments.length,X=new Array(N>1?N-1:0),st=1;st<N;st++)X[st-1]=arguments[st];C("error",A,X)}}function C(A,N,X){{var st=b.ReactDebugCurrentFrame,xt=st.getStackAddendum();xt!==""&&(N+="%s",X=X.concat([xt]));var Mt=X.map(function(pt){return String(pt)});Mt.unshift("Warning: "+N),Function.prototype.apply.call(console[A],console,Mt)}}var S=!1,T=!1,P=!1,M=!1,D=!1,R;R=Symbol.for("react.module.reference");function V(A){return!!(typeof A=="string"||typeof A=="function"||A===s||A===n||D||A===i||A===c||A===u||M||A===g||S||T||P||typeof A=="object"&&A!==null&&(A.$$typeof===f||A.$$typeof===d||A.$$typeof===r||A.$$typeof===o||A.$$typeof===h||A.$$typeof===R||A.getModuleId!==void 0))}function H(A,N,X){var st=A.displayName;if(st)return st;var xt=N.displayName||N.name||"";return xt!==""?X+"("+xt+")":X}function F(A){return A.displayName||"Context"}function I(A){if(A==null)return null;if(typeof A.tag=="number"&&x("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof A=="function")return A.displayName||A.name||null;if(typeof A=="string")return A;switch(A){case s:return"Fragment";case e:return"Portal";case n:return"Profiler";case i:return"StrictMode";case c:return"Suspense";case u:return"SuspenseList"}if(typeof A=="object")switch(A.$$typeof){case o:var N=A;return F(N)+".Consumer";case r:var X=A;return F(X._context)+".Provider";case h:return H(A,A.render,"ForwardRef");case d:var st=A.displayName||null;return st!==null?st:I(A.type)||"Memo";case f:{var xt=A,Mt=xt._payload,pt=xt._init;try{return I(pt(Mt))}catch{return null}}}return null}var j=Object.assign,K=0,L,z,Z,Dt,Bt,Xt,Ft;function _t(){}_t.__reactDisabledLog=!0;function oe(){{if(K===0){L=console.log,z=console.info,Z=console.warn,Dt=console.error,Bt=console.group,Xt=console.groupCollapsed,Ft=console.groupEnd;var A={configurable:!0,enumerable:!0,value:_t,writable:!0};Object.defineProperties(console,{info:A,log:A,warn:A,error:A,group:A,groupCollapsed:A,groupEnd:A})}K++}}function Ze(){{if(K--,K===0){var A={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:j({},A,{value:L}),info:j({},A,{value:z}),warn:j({},A,{value:Z}),error:j({},A,{value:Dt}),group:j({},A,{value:Bt}),groupCollapsed:j({},A,{value:Xt}),groupEnd:j({},A,{value:Ft})})}K<0&&x("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var it=b.ReactCurrentDispatcher,nt;function Zt(A,N,X){{if(nt===void 0)try{throw Error()}catch(xt){var st=xt.stack.trim().match(/\n( *(at )?)/);nt=st&&st[1]||""}return`
18
+ `+nt+A}}var Ys=!1,Te;{var Kd=typeof WeakMap=="function"?WeakMap:Map;Te=new Kd}function qc(A,N){if(!A||Ys)return"";{var X=Te.get(A);if(X!==void 0)return X}var st;Ys=!0;var xt=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var Mt;Mt=it.current,it.current=null,oe();try{if(N){var pt=function(){throw Error()};if(Object.defineProperty(pt.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(pt,[])}catch(fs){st=fs}Reflect.construct(A,[],pt)}else{try{pt.call()}catch(fs){st=fs}A.call(pt.prototype)}}else{try{throw Error()}catch(fs){st=fs}A()}}catch(fs){if(fs&&st&&typeof fs.stack=="string"){for(var ft=fs.stack.split(`
19
+ `),ts=st.stack.split(`
20
+ `),te=ft.length-1,ae=ts.length-1;te>=1&&ae>=0&&ft[te]!==ts[ae];)ae--;for(;te>=1&&ae>=0;te--,ae--)if(ft[te]!==ts[ae]){if(te!==1||ae!==1)do if(te--,ae--,ae<0||ft[te]!==ts[ae]){var $s=`
21
+ `+ft[te].replace(" at new "," at ");return A.displayName&&$s.includes("<anonymous>")&&($s=$s.replace("<anonymous>",A.displayName)),typeof A=="function"&&Te.set(A,$s),$s}while(te>=1&&ae>=0);break}}}finally{Ys=!1,it.current=Mt,Ze(),Error.prepareStackTrace=xt}var Nh=A?A.displayName||A.name:"",aa=Nh?Zt(Nh):"";return typeof A=="function"&&Te.set(A,aa),aa}function Jd(A,N,X){return qc(A,!1)}function Pr(A){var N=A.prototype;return!!(N&&N.isReactComponent)}function oa(A,N,X){if(A==null)return"";if(typeof A=="function")return qc(A,Pr(A));if(typeof A=="string")return Zt(A);switch(A){case c:return Zt("Suspense");case u:return Zt("SuspenseList")}if(typeof A=="object")switch(A.$$typeof){case h:return Jd(A.render);case d:return oa(A.type,N,X);case f:{var st=A,xt=st._payload,Mt=st._init;try{return oa(Mt(xt),N,X)}catch{}}}return""}var Mr=Object.prototype.hasOwnProperty,Fb={},Lb=b.ReactDebugCurrentFrame;function Qd(A){if(A){var N=A._owner,X=oa(A.type,A._source,N?N.type:null);Lb.setExtraStackFrame(X)}else Lb.setExtraStackFrame(null)}function RA(A,N,X,st,xt){{var Mt=Function.call.bind(Mr);for(var pt in A)if(Mt(A,pt)){var ft=void 0;try{if(typeof A[pt]!="function"){var ts=Error((st||"React class")+": "+X+" type `"+pt+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof A[pt]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw ts.name="Invariant Violation",ts}ft=A[pt](N,pt,st,X,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(te){ft=te}ft&&!(ft instanceof Error)&&(Qd(xt),x("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",st||"React class",X,pt,typeof ft),Qd(null)),ft instanceof Error&&!(ft.message in Fb)&&(Fb[ft.message]=!0,Qd(xt),x("Failed %s type: %s",X,ft.message),Qd(null))}}}var FA=Array.isArray;function wp(A){return FA(A)}function LA(A){{var N=typeof Symbol=="function"&&Symbol.toStringTag,X=N&&A[Symbol.toStringTag]||A.constructor.name||"Object";return X}}function IA(A){try{return Ib(A),!1}catch{return!0}}function Ib(A){return""+A}function jb(A){if(IA(A))return x("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",LA(A)),Ib(A)}var Nb=b.ReactCurrentOwner,jA={key:!0,ref:!0,__self:!0,__source:!0},Bb,Hb;function NA(A){if(Mr.call(A,"ref")){var N=Object.getOwnPropertyDescriptor(A,"ref").get;if(N&&N.isReactWarning)return!1}return A.ref!==void 0}function BA(A){if(Mr.call(A,"key")){var N=Object.getOwnPropertyDescriptor(A,"key").get;if(N&&N.isReactWarning)return!1}return A.key!==void 0}function HA(A,N){typeof A.ref=="string"&&Nb.current}function zA(A,N){{var X=function(){Bb||(Bb=!0,x("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",N))};X.isReactWarning=!0,Object.defineProperty(A,"key",{get:X,configurable:!0})}}function VA(A,N){{var X=function(){Hb||(Hb=!0,x("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",N))};X.isReactWarning=!0,Object.defineProperty(A,"ref",{get:X,configurable:!0})}}var GA=function(A,N,X,st,xt,Mt,pt){var ft={$$typeof:t,type:A,key:N,ref:X,props:pt,_owner:Mt};return ft._store={},Object.defineProperty(ft._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(ft,"_self",{configurable:!1,enumerable:!1,writable:!1,value:st}),Object.defineProperty(ft,"_source",{configurable:!1,enumerable:!1,writable:!1,value:xt}),Object.freeze&&(Object.freeze(ft.props),Object.freeze(ft)),ft};function WA(A,N,X,st,xt){{var Mt,pt={},ft=null,ts=null;X!==void 0&&(jb(X),ft=""+X),BA(N)&&(jb(N.key),ft=""+N.key),NA(N)&&(ts=N.ref,HA(N,xt));for(Mt in N)Mr.call(N,Mt)&&!jA.hasOwnProperty(Mt)&&(pt[Mt]=N[Mt]);if(A&&A.defaultProps){var te=A.defaultProps;for(Mt in te)pt[Mt]===void 0&&(pt[Mt]=te[Mt])}if(ft||ts){var ae=typeof A=="function"?A.displayName||A.name||"Unknown":A;ft&&zA(pt,ae),ts&&VA(pt,ae)}return GA(A,ft,ts,xt,st,Nb.current,pt)}}var xp=b.ReactCurrentOwner,zb=b.ReactDebugCurrentFrame;function jh(A){if(A){var N=A._owner,X=oa(A.type,A._source,N?N.type:null);zb.setExtraStackFrame(X)}else zb.setExtraStackFrame(null)}var Sp;Sp=!1;function Cp(A){return typeof A=="object"&&A!==null&&A.$$typeof===t}function Vb(){{if(xp.current){var A=I(xp.current.type);if(A)return`
22
22
 
23
- Check the render method of \``+A+"`."}return""}}function jA(A){return""}var jb={};function NA(A){{var j=Ib();if(!j){var X=typeof A=="string"?A:A.displayName||A.name;X&&(j=`
23
+ Check the render method of \``+A+"`."}return""}}function XA(A){return""}var Gb={};function UA(A){{var N=Vb();if(!N){var X=typeof A=="string"?A:A.displayName||A.name;X&&(N=`
24
24
 
25
- Check the top-level render call using <`+X+">.")}return j}}function Nb(A,j){{if(!A._store||A._store.validated||A.key!=null)return;A._store.validated=!0;var X=NA(j);if(jb[X])return;jb[X]=!0;var et="";A&&A._owner&&A._owner!==yp.current&&(et=" It was passed a child from "+L(A._owner.type)+"."),Ih(A),x('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',X,et),Ih(null)}}function Bb(A,j){{if(typeof A!="object")return;if(bp(A))for(var X=0;X<A.length;X++){var et=A[X];wp(et)&&Nb(et,j)}else if(wp(A))A._store&&(A._store.validated=!0);else if(A){var xt=y(A);if(typeof xt=="function"&&xt!==A.entries)for(var Pt=xt.call(A),pt;!(pt=Pt.next()).done;)wp(pt.value)&&Nb(pt.value,j)}}}function BA(A){{var j=A.type;if(j==null||typeof j=="string")return;var X;if(typeof j=="function")X=j.propTypes;else if(typeof j=="object"&&(j.$$typeof===h||j.$$typeof===d))X=j.propTypes;else return;if(X){var et=L(j);AA(X,A.props,"prop",et,A)}else if(j.PropTypes!==void 0&&!_p){_p=!0;var xt=L(j);x("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",xt||"Unknown")}typeof j.getDefaultProps=="function"&&!j.getDefaultProps.isReactClassApproved&&x("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function HA(A){{for(var j=Object.keys(A.props),X=0;X<j.length;X++){var et=j[X];if(et!=="children"&&et!=="key"){Ih(A),x("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",et),Ih(null);break}}A.ref!==null&&(Ih(A),x("Invalid attribute `ref` supplied to `React.Fragment`."),Ih(null))}}var Hb={};function zb(A,j,X,et,xt,Pt){{var pt=z(A);if(!pt){var ft="";(A===void 0||typeof A=="object"&&A!==null&&Object.keys(A).length===0)&&(ft+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var ts=jA();ts?ft+=ts:ft+=Ib();var te;A===null?te="null":bp(A)?te="array":A!==void 0&&A.$$typeof===t?(te="<"+(L(A.type)||"Unknown")+" />",ft=" Did you accidentally export a JSX literal instead of a component?"):te=typeof A,x("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",te,ft)}var oe=IA(A,j,X,xt,Pt);if(oe==null)return oe;if(pt){var qs=j.children;if(qs!==void 0)if(et)if(bp(qs)){for(var jh=0;jh<qs.length;jh++)Bb(qs[jh],A);Object.freeze&&Object.freeze(qs)}else x("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Bb(qs,A)}if(Mr.call(j,"key")){var ro=L(A),fs=Object.keys(j).filter(function(UA){return UA!=="key"}),xp=fs.length>0?"{key: someKey, "+fs.join(": ..., ")+": ...}":"{key: someKey}";if(!Hb[ro+xp]){var XA=fs.length>0?"{"+fs.join(": ..., ")+": ...}":"{}";x(`A props object containing a "key" prop is being spread into JSX:
25
+ Check the top-level render call using <`+X+">.")}return N}}function Wb(A,N){{if(!A._store||A._store.validated||A.key!=null)return;A._store.validated=!0;var X=UA(N);if(Gb[X])return;Gb[X]=!0;var st="";A&&A._owner&&A._owner!==xp.current&&(st=" It was passed a child from "+I(A._owner.type)+"."),jh(A),x('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',X,st),jh(null)}}function Xb(A,N){{if(typeof A!="object")return;if(wp(A))for(var X=0;X<A.length;X++){var st=A[X];Cp(st)&&Wb(st,N)}else if(Cp(A))A._store&&(A._store.validated=!0);else if(A){var xt=y(A);if(typeof xt=="function"&&xt!==A.entries)for(var Mt=xt.call(A),pt;!(pt=Mt.next()).done;)Cp(pt.value)&&Wb(pt.value,N)}}}function YA(A){{var N=A.type;if(N==null||typeof N=="string")return;var X;if(typeof N=="function")X=N.propTypes;else if(typeof N=="object"&&(N.$$typeof===h||N.$$typeof===d))X=N.propTypes;else return;if(X){var st=I(N);RA(X,A.props,"prop",st,A)}else if(N.PropTypes!==void 0&&!Sp){Sp=!0;var xt=I(N);x("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",xt||"Unknown")}typeof N.getDefaultProps=="function"&&!N.getDefaultProps.isReactClassApproved&&x("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function $A(A){{for(var N=Object.keys(A.props),X=0;X<N.length;X++){var st=N[X];if(st!=="children"&&st!=="key"){jh(A),x("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",st),jh(null);break}}A.ref!==null&&(jh(A),x("Invalid attribute `ref` supplied to `React.Fragment`."),jh(null))}}var Ub={};function Yb(A,N,X,st,xt,Mt){{var pt=V(A);if(!pt){var ft="";(A===void 0||typeof A=="object"&&A!==null&&Object.keys(A).length===0)&&(ft+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var ts=XA();ts?ft+=ts:ft+=Vb();var te;A===null?te="null":wp(A)?te="array":A!==void 0&&A.$$typeof===t?(te="<"+(I(A.type)||"Unknown")+" />",ft=" Did you accidentally export a JSX literal instead of a component?"):te=typeof A,x("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",te,ft)}var ae=WA(A,N,X,xt,Mt);if(ae==null)return ae;if(pt){var $s=N.children;if($s!==void 0)if(st)if(wp($s)){for(var Nh=0;Nh<$s.length;Nh++)Xb($s[Nh],A);Object.freeze&&Object.freeze($s)}else x("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Xb($s,A)}if(Mr.call(N,"key")){var aa=I(A),fs=Object.keys(N).filter(function(tT){return tT!=="key"}),Ap=fs.length>0?"{key: someKey, "+fs.join(": ..., ")+": ...}":"{key: someKey}";if(!Ub[aa+Ap]){var ZA=fs.length>0?"{"+fs.join(": ..., ")+": ...}":"{}";x(`A props object containing a "key" prop is being spread into JSX:
26
26
  let props = %s;
27
27
  <%s {...props} />
28
28
  React keys must be passed directly to JSX without using spread:
29
29
  let props = %s;
30
- <%s key={someKey} {...props} />`,xp,ro,XA,ro),Hb[ro+xp]=!0}}return A===s?HA(oe):BA(oe),oe}}function zA(A,j,X){return zb(A,j,X,!0)}function VA(A,j,X){return zb(A,j,X,!1)}var WA=VA,GA=zA;Gh.Fragment=s,Gh.jsx=WA,Gh.jsxs=GA}()),Gh}process.env.NODE_ENV==="production"?Hn.exports=g_():Hn.exports=p_();var ym=Hn.exports;const m_="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",v_={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:6,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},b_={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:6,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},y_={borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},__={stroke:"#000",hoverStroke:"#B7EC5D",src:m_},w_=["borderColor","cornerStrokeColor","cornerSize","_cornerSize","selectionBackgroundColor"];function E(o,t,e){return(t=function(s){var i=function(n,r){if(typeof n!="object"||!n)return n;var a=n[Symbol.toPrimitive];if(a!==void 0){var h=a.call(n,r);if(typeof h!="object")return h;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(n)}(s,"string");return typeof i=="symbol"?i:i+""}(t))in o?Object.defineProperty(o,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):o[t]=e,o}function _m(o,t){var e=Object.keys(o);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(o);t&&(s=s.filter(function(i){return Object.getOwnPropertyDescriptor(o,i).enumerable})),e.push.apply(e,s)}return e}function T(o){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?_m(Object(e),!0).forEach(function(s){E(o,s,e[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(o,Object.getOwnPropertyDescriptors(e)):_m(Object(e)).forEach(function(s){Object.defineProperty(o,s,Object.getOwnPropertyDescriptor(e,s))})}return o}function Lt(o,t){if(o==null)return{};var e,s,i=function(r,a){if(r==null)return{};var h={};for(var c in r)if({}.hasOwnProperty.call(r,c)){if(a.indexOf(c)>=0)continue;h[c]=r[c]}return h}(o,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(o);for(s=0;s<n.length;s++)e=n[s],t.indexOf(e)>=0||{}.propertyIsEnumerable.call(o,e)&&(i[e]=o[e])}return i}function zn(o,t){return t||(t=o.slice(0)),Object.freeze(Object.defineProperties(o,{raw:{value:Object.freeze(t)}}))}class wm{constructor(){E(this,"browserShadowBlurConstant",1),E(this,"DPI",96),E(this,"devicePixelRatio",typeof window<"u"?window.devicePixelRatio:1),E(this,"perfLimitSizeTotal",2097152),E(this,"maxCacheSideLimit",4096),E(this,"minCacheSideLimit",256),E(this,"disableStyleCopyPaste",!1),E(this,"enableGLFiltering",!0),E(this,"textureSize",4096),E(this,"forceGLPutImageData",!1),E(this,"cachesBoundsOfCurve",!1),E(this,"fontPaths",{}),E(this,"NUM_FRACTION_DIGITS",4)}}const bt=new class extends wm{constructor(o){super(),this.configure(o)}configure(){let o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Object.assign(this,o)}addFonts(){let o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.fontPaths=T(T({},this.fontPaths),o)}removeFonts(){(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).forEach(o=>{delete this.fontPaths[o]})}clearFonts(){this.fontPaths={}}restoreDefaults(o){const t=new wm,e=(o==null?void 0:o.reduce((s,i)=>(s[i]=t[i],s),{}))||t;this.configure(e)}},$i=function(o){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[o]("fabric",...e)};class wi extends Error{constructor(t,e){super("fabric: ".concat(t),e)}}class kf extends wi{constructor(t){super("".concat(t," 'options.signal' is in 'aborted' state"))}}class x_{}class S_ extends x_{testPrecision(t,e){const s="precision ".concat(e,` float;
31
- 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(),$i("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const C_={};let xm;const xi=()=>xm||(xm={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new S_,dispose(){},copyPasteData:C_}),lo=()=>xi().document,ou=()=>xi().window,Sm=()=>{var o;return Math.max((o=bt.devicePixelRatio)!==null&&o!==void 0?o:ou().devicePixelRatio,1)},Xh=new class{constructor(){E(this,"charWidthsCache",{}),E(this,"boundsOfCurveCache",{})}getFontCache(o){let{fontFamily:t,fontStyle:e,fontWeight:s}=o;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(o){(o=(o||"").toLowerCase())?this.charWidthsCache[o]&&delete this.charWidthsCache[o]:this.charWidthsCache={}}limitDimsByArea(o){const{perfLimitSizeTotal:t}=bt,e=Math.sqrt(t*o);return[Math.floor(e),Math.floor(t/e)]}},Pf="6.6.4";function Rr(){}const Vn=Math.PI/2,qi=2*Math.PI,Mf=Math.PI/180,He=Object.freeze([1,0,0,1,0,0]),Of=16,Wn=.4477152502,rt="center",wt="left",is="top",Df="bottom",$t="right",ze="none",Rf=/\r?\n/,Cm="moving",hu="scaling",Am="rotating",Ff="rotate",Tm="skewing",Uh="resizing",A_="modifyPoly",T_="modifyPath",lu="changed",cu="scale",Ve="scaleX",gs="scaleY",co="skewX",uo="skewY",ee="fill",We="stroke",uu="modified",fo="json",Lf="svg",W=new class{constructor(){this[fo]=new Map,this[Lf]=new Map}has(o){return this[fo].has(o)}getClass(o){const t=this[fo].get(o);if(!t)throw new wi("No class registered for ".concat(o));return t}setClass(o,t){t?this[fo].set(t,o):(this[fo].set(o.type,o),this[fo].set(o.type.toLowerCase(),o))}getSVGClass(o){return this[Lf].get(o)}setSVGClass(o,t){this[Lf].set(t??o.type.toLowerCase(),o)}},du=new class extends Array{remove(o){const t=this.indexOf(o);t>-1&&this.splice(t,1)}cancelAll(){const o=this.splice(0);return o.forEach(t=>t.abort()),o}cancelByCanvas(o){if(!o)return[];const t=this.filter(e=>{var s;return e.target===o||typeof e.target=="object"&&((s=e.target)===null||s===void 0?void 0:s.canvas)===o});return t.forEach(e=>e.abort()),t}cancelByTarget(o){if(!o)return[];const t=this.filter(e=>e.target===o);return t.forEach(e=>e.abort()),t}};class E_{constructor(){E(this,"__eventListeners",{})}on(t,e){if(this.__eventListeners||(this.__eventListeners={}),typeof t=="object")return Object.entries(t).forEach(s=>{let[i,n]=s;this.on(i,n)}),()=>this.off(t);if(e){const s=t;return this.__eventListeners[s]||(this.__eventListeners[s]=[]),this.__eventListeners[s].push(e),()=>this.off(s,e)}return()=>!1}once(t,e){if(typeof t=="object"){const s=[];return Object.entries(t).forEach(i=>{let[n,r]=i;s.push(this.once(n,r))}),()=>s.forEach(i=>i())}if(e){const s=this.on(t,function(){for(var i=arguments.length,n=new Array(i),r=0;r<i;r++)n[r]=arguments[r];e.call(this,...n),s()});return s}return()=>!1}_removeEventListener(t,e){if(this.__eventListeners[t])if(e){const s=this.__eventListeners[t],i=s.indexOf(e);i>-1&&s.splice(i,1)}else this.__eventListeners[t]=[]}off(t,e){if(this.__eventListeners)if(t===void 0)for(const s in this.__eventListeners)this._removeEventListener(s);else typeof t=="object"?Object.entries(t).forEach(s=>{let[i,n]=s;this._removeEventListener(i,n)}):this._removeEventListener(t,e)}fire(t,e){var s;if(!this.__eventListeners)return;const i=(s=this.__eventListeners[t])===null||s===void 0?void 0:s.concat();if(i)for(let n=0;n<i.length;n++)i[n].call(this,e||{})}}const Fr=(o,t)=>{const e=o.indexOf(t);return e!==-1&&o.splice(e,1),o},Ks=o=>{if(o===0)return 1;switch(Math.abs(o)/Vn){case 1:case 3:return 0;case 2:return-1}return Math.cos(o)},Js=o=>{if(o===0)return 0;const t=o/Vn,e=Math.sign(o);switch(t){case 1:return e;case 2:return 0;case 3:return-e}return Math.sin(o)};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]:If;const s=Js(t),i=Ks(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 If=new M(0,0),fu=o=>!!o&&Array.isArray(o._objects);function Em(o){class t extends o{constructor(){super(...arguments),E(this,"_objects",[])}_onObjectAdded(s){}_onObjectRemoved(s){}_onStackOrderChanged(s){}add(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];const r=this._objects.push(...i);return i.forEach(a=>this._onObjectAdded(a)),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(a=>this._onObjectAdded(a)),this._objects.length}remove(){const s=this._objects,i=[];for(var n=arguments.length,r=new Array(n),a=0;a<n;a++)r[a]=arguments[a];return r.forEach(h=>{const c=s.indexOf(h);c!==-1&&(s.splice(c,1),i.push(h),this._onObjectRemoved(h))}),i}forEachObject(s){this.getObjects().forEach((i,n,r)=>s(i,n,r))}getObjects(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];return i.length===0?[...this._objects]:this._objects.filter(r=>r.isType(...i))}item(s){return this._objects[s]}isEmpty(){return this._objects.length===0}size(){return this._objects.length}contains(s,i){return!!this._objects.includes(s)||!!i&&this._objects.some(n=>n instanceof t&&n.contains(s,!0))}complexity(){return this._objects.reduce((s,i)=>s+=i.complexity?i.complexity():0,0)}sendObjectToBack(s){return!(!s||s===this._objects[0])&&(Fr(this._objects,s),this._objects.unshift(s),this._onStackOrderChanged(s),!0)}bringObjectToFront(s){return!(!s||s===this._objects[this._objects.length-1])&&(Fr(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 Fr(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 Fr(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}moveObjectTo(s,i){return s!==this._objects[i]&&(Fr(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 a=i-1;a>=0;--a)if(s.isOverlapping(this._objects[a])){r=a;break}}else r=i-1;return r}findNewUpperIndex(s,i,n){let r;if(n){r=i;for(let a=i+1;a<this._objects.length;++a)if(s.isOverlapping(this._objects[a])){r=a;break}}else r=i+1;return r}collectObjects(s){let{left:i,top:n,width:r,height:a}=s,{includeIntersecting:h=!0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const c=[],u=new M(i,n),d=u.add(new M(r,a));for(let f=this._objects.length-1;f>=0;f--){const g=this._objects[f];g.selectable&&g.visible&&(h&&g.intersectsWithRect(u,d)||g.isContainedWithinRect(u,d)||h&&g.containsPoint(u)||h&&g.containsPoint(d))&&c.push(g)}return c}}return t}class km extends E_{_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 Yh(o){return ou().requestAnimationFrame(o)}function Pm(o){return ou().cancelAnimationFrame(o)}let k_=0;const Gn=()=>k_++,Rs=()=>{const o=lo().createElement("canvas");if(!o||o.getContext===void 0)throw new wi("Failed to create `canvas` element");return o},Mm=()=>lo().createElement("img"),ps=o=>{const t=Rs();return t.width=o.width,t.height=o.height,t},jf=(o,t,e)=>o.toDataURL("image/".concat(t),e),Nf=(o,t,e)=>new Promise((s,i)=>{o.toBlob(s,"image/".concat(t),e)}),Ut=o=>o*Mf,Si=o=>o/Mf,Om=o=>o.every((t,e)=>t===He[e]),Ee=(o,t,e)=>new M(o).transform(t,e),ns=o=>{const t=1/(o[0]*o[3]-o[1]*o[2]),e=[t*o[3],-t*o[1],-t*o[2],t*o[0],0,0],{x:s,y:i}=new M(o[4],o[5]).transform(e,!0);return e[4]=-s,e[5]=-i,e},qt=(o,t,e)=>[o[0]*t[0]+o[2]*t[1],o[1]*t[0]+o[3]*t[1],o[0]*t[2]+o[2]*t[3],o[1]*t[2]+o[3]*t[3],e?0:o[0]*t[4]+o[2]*t[5]+o[4],e?0:o[1]*t[4]+o[3]*t[5]+o[5]],gu=(o,t)=>o.reduceRight((e,s)=>s&&e?qt(s,e,t):s||e,void 0)||He.concat(),Dm=o=>{let[t,e]=o;return Math.atan2(e,t)},Lr=o=>{const t=Dm(o),e=Math.pow(o[0],2)+Math.pow(o[1],2),s=Math.sqrt(e),i=(o[0]*o[3]-o[2]*o[1])/s,n=Math.atan2(o[0]*o[2]+o[1]*o[3],e);return{angle:Si(t),scaleX:s,scaleY:i,skewX:Si(n),skewY:0,translateX:o[4]||0,translateY:o[5]||0}},go=function(o){return[1,0,0,1,o,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function Ir(){let{angle:o=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=Ut(o),i=Ks(s),n=Js(s);return[i,n,-n,i,t?t-(i*t-n*e):0,e?e-(n*t+i*e):0]}const pu=function(o){return[o,0,0,arguments.length>1&&arguments[1]!==void 0?arguments[1]:o,0,0]},Rm=o=>Math.tan(Ut(o)),Bf=o=>[1,0,Rm(o),1,0,0],Hf=o=>[1,Rm(o),0,1,0,0],$h=o=>{let{scaleX:t=1,scaleY:e=1,flipX:s=!1,flipY:i=!1,skewX:n=0,skewY:r=0}=o,a=pu(s?-t:t,i?-e:e);return n&&(a=qt(a,Bf(n),!0)),r&&(a=qt(a,Hf(r),!0)),a},Fm=o=>{const{translateX:t=0,translateY:e=0,angle:s=0}=o;let i=go(t,e);s&&(i=qt(i,Ir({angle:s})));const n=$h(o);return Om(n)||(i=qt(i,n)),i},qh=function(o){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 kf("loadImage"));const n=Mm();let r;t&&(r=function(h){n.src="",i(h)},t.addEventListener("abort",r,{once:!0}));const a=function(){n.onload=n.onerror=null,r&&(t==null||t.removeEventListener("abort",r)),s(n)};o?(n.onload=a,n.onerror=function(){r&&(t==null||t.removeEventListener("abort",r)),i(new wi("Error loading ".concat(n.src)))},e&&(n.crossOrigin=e),n.src=o):a()})},po=function(o){let{signal:t,reviver:e=Rr}=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(o.map(r=>W.getClass(r.type).fromObject(r,{signal:t}).then(a=>(e(r,a),n.push(a),a)))).then(s).catch(r=>{n.forEach(a=>{a.dispose&&a.dispose()}),i(r)}).finally(()=>{t&&t.removeEventListener("abort",i)})})},Kh=function(o){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(o).map(a=>a&&a.type&&W.has(a.type)?po([a],{signal:t}).then(h=>{let[c]=h;return i.push(c),c}):a),r=Object.keys(o);Promise.all(n).then(a=>a.reduce((h,c,u)=>(h[r[u]]=c,h),{})).then(e).catch(a=>{i.forEach(h=>{h.dispose&&h.dispose()}),s(a)}).finally(()=>{t&&t.removeEventListener("abort",s)})})},jr=function(o){return(arguments.length>1&&arguments[1]!==void 0?arguments[1]:[]).reduce((t,e)=>(e in o&&(t[e]=o[e]),t),{})},zf=(o,t)=>Object.keys(o).reduce((e,s)=>(t(o[s],s,o)&&(e[s]=o[s]),e),{}),Dt=(o,t)=>parseFloat(Number(o).toFixed(t)),mo=o=>"matrix("+o.map(t=>Dt(t,bt.NUM_FRACTION_DIGITS)).join(" ")+")",Fs=o=>!!o&&o.toLive!==void 0,Lm=o=>!!o&&typeof o.toObject=="function",Im=o=>!!o&&o.offsetX!==void 0&&"source"in o,Nr=o=>!!o&&"multiSelectionStacking"in o;function jm(o){const t=o&&Qs(o);let e=0,s=0;if(!o||!t)return{left:e,top:s};let i=o;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 Qs=o=>o.ownerDocument||null,Nm=o=>{var t;return((t=o.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null},Bm=function(o,t,e){let{width:s,height:i}=e,n=arguments.length>3&&arguments[3]!==void 0?arguments[3]:1;o.width=s,o.height=i,n>1&&(o.setAttribute("width",(s*n).toString()),o.setAttribute("height",(i*n).toString()),t.scale(n,n))},Vf=(o,t)=>{let{width:e,height:s}=t;e&&(o.style.width=typeof e=="number"?"".concat(e,"px"):e),s&&(o.style.height=typeof s=="number"?"".concat(s,"px"):s)};function Hm(o){return o.onselectstart!==void 0&&(o.onselectstart=()=>!1),o.style.userSelect=ze,o}class zm{constructor(t){E(this,"_originalCanvasStyle",void 0),E(this,"lower",void 0);const e=this.createLowerCanvas(t);this.lower={el:e,ctx:e.getContext("2d")}}createLowerCanvas(t){const e=(s=t)&&s.getContext!==void 0?t:t&&lo().getElementById(t)||Rs();var s;if(e.hasAttribute("data-fabric"))throw new wi("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;Bm(s,i,t,e)}setCSSDimensions(t){Vf(this.lower.el,t)}calcOffset(){return function(t){var e;const s=t&&Qs(t),i={left:0,top:0};if(!s)return i;const n=((e=Nm(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 a=s.documentElement;t.getBoundingClientRect!==void 0&&(r=t.getBoundingClientRect());const h=jm(t);return{left:r.left+h.left-(a.clientLeft||0)+i.left,top:r.top+h.top-(a.clientTop||0)+i.top}}(this.lower.el)}dispose(){xi().dispose(this.lower.el),delete this.lower}}const P_={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...He]};class Jh extends Em(km){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 Jh.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 zm(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&&($i("warn",`Canvas is trying to add an object that belongs to a different canvas.
32
- 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?Sm():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=Ee(t,ns(i));i[0]=e,i[3]=e;const r=Ee(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=Yh(()=>this.renderAndReset()))}calcViewportBoundaries(){const t=this.width,e=this.height,s=ns(this.viewportTransform),i=Ee({x:0,y:0},s),n=Ee({x:t,y:e},s),r=i.min(n),a=i.max(n);return this.vptCoords={tl:r,tr:new M(a.x,r.y),bl:new M(r.x,a.y),br:a}}cancelRequestedRender(){this.nextRenderHandle&&(Pm(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 a=Fs(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=a?s.toLive(t):s,r&&t.transform(...n),a){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 Ee(this.getCenterPoint(),ns(this.viewportTransform))}_centerObject(t,e){t.setXY(e,rt,rt),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:Pf},jr(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,a=this.overlayColor;return Fs(r)?r.excludeFromExport||(s.background=r.toObject(e)):r&&(s.background=r),Fs(a)?a.excludeFromExport||(s.overlay=a.toObject(e)):a&&(s.overlay=a),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,`)" >
30
+ <%s key={someKey} {...props} />`,Ap,aa,ZA,aa),Ub[aa+Ap]=!0}}return A===s?$A(ae):YA(ae),ae}}function qA(A,N,X){return Yb(A,N,X,!0)}function KA(A,N,X){return Yb(A,N,X,!1)}var JA=KA,QA=qA;Xh.Fragment=s,Xh.jsx=JA,Xh.jsxs=QA}()),Xh}var xm;function x_(){return xm||(xm=1,process.env.NODE_ENV==="production"?qi.exports=__():qi.exports=w_()),qi.exports}var Sm=x_();const S_="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",C_={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:6,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},A_={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:6,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},T_={borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},E_={stroke:"#000",hoverStroke:"#B7EC5D",src:S_},k_=["borderColor","cornerStrokeColor","cornerSize","_cornerSize","selectionBackgroundColor"];function k(a,t,e){return(t=function(s){var i=function(n,r){if(typeof n!="object"||!n)return n;var o=n[Symbol.toPrimitive];if(o!==void 0){var h=o.call(n,r);if(typeof h!="object")return h;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(n)}(s,"string");return typeof i=="symbol"?i:i+""}(t))in a?Object.defineProperty(a,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):a[t]=e,a}function Cm(a,t){var e=Object.keys(a);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(a);t&&(s=s.filter(function(i){return Object.getOwnPropertyDescriptor(a,i).enumerable})),e.push.apply(e,s)}return e}function E(a){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?Cm(Object(e),!0).forEach(function(s){k(a,s,e[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(e)):Cm(Object(e)).forEach(function(s){Object.defineProperty(a,s,Object.getOwnPropertyDescriptor(e,s))})}return a}function Lt(a,t){if(a==null)return{};var e,s,i=function(r,o){if(r==null)return{};var h={};for(var c in r)if({}.hasOwnProperty.call(r,c)){if(o.indexOf(c)>=0)continue;h[c]=r[c]}return h}(a,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(a);for(s=0;s<n.length;s++)e=n[s],t.indexOf(e)>=0||{}.propertyIsEnumerable.call(a,e)&&(i[e]=a[e])}return i}function _i(a,t){return t||(t=a.slice(0)),Object.freeze(Object.defineProperties(a,{raw:{value:Object.freeze(t)}}))}class Am{constructor(){k(this,"browserShadowBlurConstant",1),k(this,"DPI",96),k(this,"devicePixelRatio",typeof window<"u"?window.devicePixelRatio:1),k(this,"perfLimitSizeTotal",2097152),k(this,"maxCacheSideLimit",4096),k(this,"minCacheSideLimit",256),k(this,"disableStyleCopyPaste",!1),k(this,"enableGLFiltering",!0),k(this,"textureSize",4096),k(this,"forceGLPutImageData",!1),k(this,"cachesBoundsOfCurve",!1),k(this,"fontPaths",{}),k(this,"NUM_FRACTION_DIGITS",4)}}const mt=new class extends Am{constructor(a){super(),this.configure(a)}configure(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Object.assign(this,a)}addFonts(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.fontPaths=E(E({},this.fontPaths),a)}removeFonts(){(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).forEach(a=>{delete this.fontPaths[a]})}clearFonts(){this.fontPaths={}}restoreDefaults(a){const t=new Am,e=(a==null?void 0:a.reduce((s,i)=>(s[i]=t[i],s),{}))||t;this.configure(e)}},Ki=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 wi extends Error{constructor(t,e){super("fabric: ".concat(t),e)}}class Mf extends wi{constructor(t){super("".concat(t," 'options.signal' is in 'aborted' state"))}}class P_{}class M_ extends P_{testPrecision(t,e){const s="precision ".concat(e,` float;
31
+ 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(),Ki("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const O_={};let Tm;const xi=()=>Tm||(Tm={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new M_,dispose(){},copyPasteData:O_}),ua=()=>xi().document,Uh=()=>xi().window,Em=()=>{var a;return Math.max((a=mt.devicePixelRatio)!==null&&a!==void 0?a:Uh().devicePixelRatio,1)},Yh=new class{constructor(){k(this,"charWidthsCache",{}),k(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}=mt,e=Math.sqrt(t*a);return[Math.floor(e),Math.floor(t/e)]}},Of="6.7.0";function Rr(){}const Vn=Math.PI/2,Ji=2*Math.PI,Df=Math.PI/180,He=Object.freeze([1,0,0,1,0,0]),Rf=16,Gn=.4477152502,rt="center",wt="left",is="top",Ff="bottom",$t="right",ze="none",Lf=/\r?\n/,km="moving",cu="scaling",Pm="rotating",If="rotate",Mm="skewing",$h="resizing",D_="modifyPoly",R_="modifyPath",uu="changed",du="scale",Ve="scaleX",gs="scaleY",da="skewX",fa="skewY",ee="fill",Ge="stroke",fu="modified",ga="json",jf="svg",G=new class{constructor(){this[ga]=new Map,this[jf]=new Map}has(a){return this[ga].has(a)}getClass(a){const t=this[ga].get(a);if(!t)throw new wi("No class registered for ".concat(a));return t}setClass(a,t){t?this[ga].set(t,a):(this[ga].set(a.type,a),this[ga].set(a.type.toLowerCase(),a))}getSVGClass(a){return this[jf].get(a)}setSVGClass(a,t){this[jf].set(t??a.type.toLowerCase(),a)}},gu=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 F_{constructor(){k(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 Fr=(a,t)=>{const e=a.indexOf(t);return e!==-1&&a.splice(e,1),a},qs=a=>{if(a===0)return 1;switch(Math.abs(a)/Vn){case 1:case 3:return 0;case 2:return-1}return Math.cos(a)},Ks=a=>{if(a===0)return 0;const t=a/Vn,e=Math.sign(a);switch(t){case 1:return e;case 2:return 0;case 3:return-e}return Math.sin(a)};class O{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 O(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new O(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new O(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new O(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new O(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new O(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new O(this.x/t.x,this.y/t.y)}scalarDivide(t){return new O(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 O(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 O(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new O(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 O(this.x,this.y)}rotate(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Nf;const s=Ks(t),i=qs(t),n=this.subtract(e);return new O(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 O(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 Nf=new O(0,0),pu=a=>!!a&&Array.isArray(a._objects);function Om(a){class t extends a{constructor(){super(...arguments),k(this,"_objects",[])}_onObjectAdded(s){}_onObjectRemoved(s){}_onStackOrderChanged(s){}add(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];const r=this._objects.push(...i);return i.forEach(o=>this._onObjectAdded(o)),r}insertAt(s){for(var i=arguments.length,n=new Array(i>1?i-1:0),r=1;r<i;r++)n[r-1]=arguments[r];return this._objects.splice(s,0,...n),n.forEach(o=>this._onObjectAdded(o)),this._objects.length}remove(){const s=this._objects,i=[];for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return r.forEach(h=>{const c=s.indexOf(h);c!==-1&&(s.splice(c,1),i.push(h),this._onObjectRemoved(h))}),i}forEachObject(s){this.getObjects().forEach((i,n,r)=>s(i,n,r))}getObjects(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];return i.length===0?[...this._objects]:this._objects.filter(r=>r.isType(...i))}item(s){return this._objects[s]}isEmpty(){return this._objects.length===0}size(){return this._objects.length}contains(s,i){return!!this._objects.includes(s)||!!i&&this._objects.some(n=>n instanceof t&&n.contains(s,!0))}complexity(){return this._objects.reduce((s,i)=>s+=i.complexity?i.complexity():0,0)}sendObjectToBack(s){return!(!s||s===this._objects[0])&&(Fr(this._objects,s),this._objects.unshift(s),this._onStackOrderChanged(s),!0)}bringObjectToFront(s){return!(!s||s===this._objects[this._objects.length-1])&&(Fr(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 Fr(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 Fr(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}moveObjectTo(s,i){return s!==this._objects[i]&&(Fr(this._objects,s),this._objects.splice(i,0,s),this._onStackOrderChanged(s),!0)}findNewLowerIndex(s,i,n){let r;if(n){r=i;for(let o=i-1;o>=0;--o)if(s.isOverlapping(this._objects[o])){r=o;break}}else r=i-1;return r}findNewUpperIndex(s,i,n){let r;if(n){r=i;for(let o=i+1;o<this._objects.length;++o)if(s.isOverlapping(this._objects[o])){r=o;break}}else r=i+1;return r}collectObjects(s){let{left:i,top:n,width:r,height:o}=s,{includeIntersecting:h=!0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const c=[],u=new O(i,n),d=u.add(new O(r,o));for(let f=this._objects.length-1;f>=0;f--){const g=this._objects[f];g.selectable&&g.visible&&(h&&g.intersectsWithRect(u,d)||g.isContainedWithinRect(u,d)||h&&g.containsPoint(u)||h&&g.containsPoint(d))&&c.push(g)}return c}}return t}class Dm extends F_{_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 qh(a){return Uh().requestAnimationFrame(a)}function Rm(a){return Uh().cancelAnimationFrame(a)}let L_=0;const Wn=()=>L_++,Si=()=>{const a=ua().createElement("canvas");if(!a||a.getContext===void 0)throw new wi("Failed to create `canvas` element");return a},Fm=()=>ua().createElement("img"),ps=a=>{const t=Si();return t.width=a.width,t.height=a.height,t},Bf=(a,t,e)=>a.toDataURL("image/".concat(t),e),Hf=(a,t,e)=>new Promise((s,i)=>{a.toBlob(s,"image/".concat(t),e)}),Ut=a=>a*Df,Ci=a=>a/Df,Lm=a=>a.every((t,e)=>t===He[e]),Ee=(a,t,e)=>new O(a).transform(t,e),ns=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 O(a[4],a[5]).transform(e,!0);return e[4]=-s,e[5]=-i,e},qt=(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]],mu=(a,t)=>a.reduceRight((e,s)=>s&&e?qt(s,e,t):s||e,void 0)||He.concat(),Im=a=>{let[t,e]=a;return Math.atan2(e,t)},Lr=a=>{const t=Im(a),e=Math.pow(a[0],2)+Math.pow(a[1],2),s=Math.sqrt(e),i=(a[0]*a[3]-a[2]*a[1])/s,n=Math.atan2(a[0]*a[2]+a[1]*a[3],e);return{angle:Ci(t),scaleX:s,scaleY:i,skewX:Ci(n),skewY:0,translateX:a[4]||0,translateY:a[5]||0}},pa=function(a){return[1,0,0,1,a,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function Ir(){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=Ut(a),i=qs(s),n=Ks(s);return[i,n,-n,i,t?t-(i*t-n*e):0,e?e-(n*t+i*e):0]}const vu=function(a){return[a,0,0,arguments.length>1&&arguments[1]!==void 0?arguments[1]:a,0,0]},jm=a=>Math.tan(Ut(a)),zf=a=>[1,0,jm(a),1,0,0],Vf=a=>[1,jm(a),0,1,0,0],Kh=a=>{let{scaleX:t=1,scaleY:e=1,flipX:s=!1,flipY:i=!1,skewX:n=0,skewY:r=0}=a,o=vu(s?-t:t,i?-e:e);return n&&(o=qt(o,zf(n),!0)),r&&(o=qt(o,Vf(r),!0)),o},Nm=a=>{const{translateX:t=0,translateY:e=0,angle:s=0}=a;let i=pa(t,e);s&&(i=qt(i,Ir({angle:s})));const n=Kh(a);return Lm(n)||(i=qt(i,n)),i},Jh=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 Mf("loadImage"));const n=Fm();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 wi("Error loading ".concat(n.src)))},e&&(n.crossOrigin=e),n.src=a):o()})},ma=function(a){let{signal:t,reviver:e=Rr}=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=>G.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)})})},Qh=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&&G.has(o.type)?ma([o],{signal:t}).then(h=>{let[c]=h;return i.push(c),c}):o),r=Object.keys(a);Promise.all(n).then(o=>o.reduce((h,c,u)=>(h[r[u]]=c,h),{})).then(e).catch(o=>{i.forEach(h=>{h.dispose&&h.dispose()}),s(o)}).finally(()=>{t&&t.removeEventListener("abort",s)})})},jr=function(a){return(arguments.length>1&&arguments[1]!==void 0?arguments[1]:[]).reduce((t,e)=>(e in a&&(t[e]=a[e]),t),{})},Gf=(a,t)=>Object.keys(a).reduce((e,s)=>(t(a[s],s,a)&&(e[s]=a[s]),e),{}),kt=(a,t)=>parseFloat(Number(a).toFixed(t)),va=a=>"matrix("+a.map(t=>kt(t,mt.NUM_FRACTION_DIGITS)).join(" ")+")",Rs=a=>!!a&&a.toLive!==void 0,Bm=a=>!!a&&typeof a.toObject=="function",Hm=a=>!!a&&a.offsetX!==void 0&&"source"in a,Nr=a=>!!a&&"multiSelectionStacking"in a;function zm(a){const t=a&&Js(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 Js=a=>a.ownerDocument||null,Vm=a=>{var t;return((t=a.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null},Gm=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))},Wf=(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 Wm(a){return a.onselectstart!==void 0&&(a.onselectstart=()=>!1),a.style.userSelect=ze,a}class Xm{constructor(t){k(this,"_originalCanvasStyle",void 0),k(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&&ua().getElementById(t)||Si();var s;if(e.hasAttribute("data-fabric"))throw new wi("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;Gm(s,i,t,e)}setCSSDimensions(t){Wf(this.lower.el,t)}calcOffset(){return function(t){var e;const s=t&&Js(t),i={left:0,top:0};if(!s)return i;const n=((e=Vm(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=zm(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(){xi().dispose(this.lower.el),delete this.lower}}const I_={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...He]};class Zh extends Om(Dm){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 Zh.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 Xm(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&&(Ki("warn",`Canvas is trying to add an object that belongs to a different canvas.
32
+ 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?Em():1}calcOffset(){return this._offset=this.elements.calcOffset()}getWidth(){return this.width}getHeight(){return this.height}setWidth(t,e){return this.setDimensions({width:t},e)}setHeight(t,e){return this.setDimensions({height:t},e)}_setDimensionsImpl(t){let{cssOnly:e=!1,backstoreOnly:s=!1}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!e){const i=E({width:this.width,height:this.height},t);this.elements.setDimensions(i,this.getRetinaScaling()),this.hasLostContext=!0,this.width=i.width,this.height=i.height}s||this.elements.setCSSDimensions(t),this.calcOffset()}setDimensions(t,e){this._setDimensionsImpl(t,e),e&&e.cssOnly||this.requestRenderAll()}getZoom(){return this.viewportTransform[0]}setViewportTransform(t){this.viewportTransform=t,this.calcViewportBoundaries(),this.renderOnAddRemove&&this.requestRenderAll()}zoomToPoint(t,e){const s=t,i=[...this.viewportTransform],n=Ee(t,ns(i));i[0]=e,i[3]=e;const r=Ee(n,i);i[4]+=s.x-r.x,i[5]+=s.y-r.y,this.setViewportTransform(i)}setZoom(t){this.zoomToPoint(new O(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 O(-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=qh(()=>this.renderAndReset()))}calcViewportBoundaries(){const t=this.width,e=this.height,s=ns(this.viewportTransform),i=Ee({x:0,y:0},s),n=Ee({x:t,y:e},s),r=i.min(n),o=i.max(n);return this.vptCoords={tl:r,tr:new O(o.x,r.y),bl:new O(r.x,o.y),br:o}}cancelRequestedRender(){this.nextRenderHandle&&(Rm(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 O(this.width/2,this.height/2)}centerObjectH(t){return this._centerObject(t,new O(this.getCenterPoint().x,t.getCenterPoint().y))}centerObjectV(t){return this._centerObject(t,new O(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 O(this.getVpCenter().x,t.getCenterPoint().y))}viewportCenterObjectV(t){return this._centerObject(t,new O(t.getCenterPoint().x,this.getVpCenter().y))}getVpCenter(){return Ee(this.getCenterPoint(),ns(this.viewportTransform))}_centerObject(t,e){t.setXY(e,rt,rt),t.setCoords(),this.renderOnAddRemove&&this.requestRenderAll()}toDatalessJSON(t){return this.toDatalessObject(t)}toObject(t){return this._toObjectMethod("toObject",t)}toJSON(){return this.toObject()}toDatalessObject(t){return this._toObjectMethod("toDatalessObject",t)}_toObjectMethod(t,e){const s=this.clipPath,i=s&&!s.excludeFromExport?this._toObject(s,t,e):null;return E(E(E({version:Of},jr(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,`)" >
33
33
  `)),this._setSVGBgOverlayColor(s,"background"),this._setSVGBgOverlayImage(s,"backgroundImage",e),this._setSVGObjects(s,e),this.clipPath&&s.push(`</g>
34
34
  `),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" ?>
35
35
  `,'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" ',`"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
36
- `)}_setSVGHeader(t,e){const s=e.width||"".concat(this.width),i=e.height||"".concat(this.height),n=bt.NUM_FRACTION_DIGITS,r=e.viewBox;let a;if(r)a='viewBox="'.concat(r.x," ").concat(r.y," ").concat(r.width," ").concat(r.height,'" ');else if(this.svgViewportTransformation){const h=this.viewportTransform;a='viewBox="'.concat(Dt(-h[4]/h[0],n)," ").concat(Dt(-h[5]/h[3],n)," ").concat(Dt(this.width/h[0],n)," ").concat(Dt(this.height/h[3],n),'" ')}else a='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,'" ',a,`xml:space="preserve">
37
- `,"<desc>Created with Fabric.js ",Pf,`</desc>
36
+ `)}_setSVGHeader(t,e){const s=e.width||"".concat(this.width),i=e.height||"".concat(this.height),n=mt.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(kt(-h[4]/h[0],n)," ").concat(kt(-h[5]/h[3],n)," ").concat(kt(this.width/h[0],n)," ").concat(kt(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">
37
+ `,"<desc>Created with Fabric.js ",Of,`</desc>
38
38
  `,`<defs>
39
39
  `,this.createSVGFontFacesMarkup(),this.createSVGRefElementsMarkup(),this.createSVGClipPathMarkup(e),`</defs>
40
- `)}createSVGClipPathMarkup(t){const e=this.clipPath;return e?(e.clipPathId="CLIPPATH_".concat(Gn()),'<clipPath id="'.concat(e.clipPathId,`" >
40
+ `)}createSVGClipPathMarkup(t){const e=this.clipPath;return e?(e.clipPathId="CLIPPATH_".concat(Wn()),'<clipPath id="'.concat(e.clipPathId,`" >
41
41
  `).concat(e.toClipPathSVG(t.reviver),`</clipPath>
42
- `)):""}createSVGRefElementsMarkup(){return["background","overlay"].map(t=>{const e=this["".concat(t,"Color")];if(Fs(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?mo(i):""})}}).join("")}createSVGFontFacesMarkup(){const t=[],e={},s=bt.fontPaths;this._objects.forEach(function n(r){t.push(r),fu(r)&&r._objects.forEach(n)}),t.forEach(n=>{if(!(r=n)||typeof r._renderText!="function")return;var r;const{styles:a,fontFamily:h}=n;!e[h]&&s[h]&&(e[h]=!0,a&&Object.values(a).forEach(c=>{Object.values(c).forEach(u=>{let{fontFamily:d=""}=u;!e[d]&&s[d]&&(e[d]=!0)})}))});const i=Object.keys(e).map(n=>` @font-face {
42
+ `)):""}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?va(i):""})}}).join("")}createSVGFontFacesMarkup(){const t=[],e={},s=mt.fontPaths;this._objects.forEach(function n(r){t.push(r),pu(r)&&r._objects.forEach(n)}),t.forEach(n=>{if(!(r=n)||typeof r._renderText!="function")return;var r;const{styles:o,fontFamily:h}=n;!e[h]&&s[h]&&(e[h]=!0,o&&Object.values(o).forEach(c=>{Object.values(c).forEach(u=>{let{fontFamily:d=""}=u;!e[d]&&s[d]&&(e[d]=!0)})}))});const i=Object.keys(e).map(n=>` @font-face {
43
43
  font-family: '`.concat(n,`';
44
44
  src: url('`).concat(s[n],`');
45
45
  }
46
46
  `)).join("");return i?` <style type="text/css"><![CDATA[
47
47
  `.concat(i,`]]></style>
48
- `):""}_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(Fs(s)){const i=s.repeat||"",n=this.width,r=this.height,a=this["".concat(e,"Vpt")]?mo(ns(this.viewportTransform)):"";t.push('<rect transform="'.concat(a," 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"||!Im(s)?n:s.source.width,'" height="').concat(i!=="repeat-x"&&i!=="no-repeat"||!Im(s)?r:s.source.height,'" fill="url(#SVGID_').concat(s.id,`)"></rect>
48
+ `):""}_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")]?va(ns(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"||!Hm(s)?n:s.source.width,'" height="').concat(i!=="repeat-x"&&i!=="no-repeat"||!Hm(s)?r:s.source.height,'" fill="url(#SVGID_').concat(s.id,`)"></rect>
49
49
  `))}else t.push('<rect x="0" y="0" width="100%" height="100%" ','fill="',s,'"',`></rect>
50
- `)}loadFromJSON(t,e){let{signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(!t)return Promise.reject(new wi("`json` is undefined"));const i=typeof t=="string"?JSON.parse(t):t,{objects:n=[],backgroundImage:r,background:a,overlayImage:h,overlay:c,clipPath:u}=i,d=this.renderOnAddRemove;return this.renderOnAddRemove=!1,Promise.all([po(n,{reviver:e,signal:s}),Kh({backgroundImage:r,backgroundColor:a,overlayImage:h,overlayColor:c,clipPath:u},{signal:s})]).then(f=>{let[g,p]=f;return this.clear(),this.add(...g),this.set(i),this.set(p),this.renderOnAddRemove=d,this})}clone(t){const e=this.toObject(t);return this.cloneWithoutData().loadFromJSON(e)}cloneWithoutData(){const t=ps(this);return new this.constructor(t)}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const{format:e="png",quality:s=1,multiplier:i=1,enableRetinaScaling:n=!1}=t,r=i*(n?this.getRetinaScaling():1);return jf(this.toCanvasElement(r,t),e,s)}toBlob(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const{format:e="png",quality:s=1,multiplier:i=1,enableRetinaScaling:n=!1}=t,r=i*(n?this.getRetinaScaling():1);return Nf(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 a=(e||this.width)*t,h=(s||this.height)*t,c=this.getZoom(),u=this.width,d=this.height,f=this.skipControlsDrawing,g=c*t,p=this.viewportTransform,m=[g,0,0,g,(p[4]-(i||0))*t,(p[5]-(n||0))*t],y=this.enableRetinaScaling,b=ps({width:a,height:h}),x=r?this._objects.filter(S=>r(S)):this._objects;return this.enableRetinaScaling=!1,this.viewportTransform=m,this.width=a,this.height=h,this.skipControlsDrawing=!0,this.calcViewportBoundaries(),this.renderCanvas(b.getContext("2d"),x),this.viewportTransform=p,this.width=u,this.height=d,this.calcViewportBoundaries(),this.enableRetinaScaling=y,this.skipControlsDrawing=f,b}dispose(){return!this.disposed&&this.elements.cleanupDOM({width:this.width,height:this.height}),du.cancelByCanvas(this),this.disposed=!0,new Promise((t,e)=>{const s=()=>{this.destroy(),t(!0)};s.kill=e,this.__cleanupTask&&this.__cleanupTask.kill("aborted"),this.destroyed?t(!1):this.nextRenderHandle?this.__cleanupTask=s:s()})}destroy(){this.destroyed=!0,this.cancelRequestedRender(),this.forEachObject(t=>t.dispose()),this._objects=[],this.backgroundImage&&this.backgroundImage.dispose(),this.backgroundImage=void 0,this.overlayImage&&this.overlayImage.dispose(),this.overlayImage=void 0,this.elements.dispose()}toString(){return"#<Canvas (".concat(this.complexity(),"): { objects: ").concat(this._objects.length," }>")}}E(Jh,"ownDefaults",P_);const M_=["touchstart","touchmove","touchend"],Vm=o=>{const t=jm(o.target),e=function(s){const i=s.changedTouches;return i&&i[0]?i[0]:s}(o);return new M(e.clientX+t.left,e.clientY+t.top)},mu=o=>M_.includes(o.type)||o.pointerType==="touch",Wm=o=>{o.preventDefault(),o.stopPropagation()},Ci=o=>{let t=0,e=0,s=0,i=0;for(let n=0,r=o.length;n<r;n++){const{x:a,y:h}=o[n];(a>s||!n)&&(s=a),(a<t||!n)&&(t=a),(h>i||!n)&&(i=h),(h<e||!n)&&(e=h)}return{left:t,top:e,width:s-t,height:i-e}},O_=["translateX","translateY","scaleX","scaleY"],Gm=(o,t)=>vo(o,qt(t,o.calcOwnMatrix())),vo=(o,t)=>{const e=Lr(t),{translateX:s,translateY:i,scaleX:n,scaleY:r}=e,a=Lt(e,O_),h=new M(s,i);o.flipX=!1,o.flipY=!1,Object.assign(o,a),o.set({scaleX:n,scaleY:r}),o.setPositionByOrigin(h,rt,rt)},Xm=o=>{o.scaleX=1,o.scaleY=1,o.skewX=0,o.skewY=0,o.flipX=!1,o.flipY=!1,o.rotate(0)},Wf=o=>({scaleX:o.scaleX,scaleY:o.scaleY,skewX:o.skewX,skewY:o.skewY,angle:o.angle,left:o.left,flipX:o.flipX,flipY:o.flipY,top:o.top}),vu=(o,t,e)=>{const s=o/2,i=t/2,n=[new M(-s,-i),new M(s,-i),new M(-s,i),new M(s,i)].map(a=>a.transform(e)),r=Ci(n);return new M(r.width,r.height)},Qh=function(){let o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:He;return qt(ns(arguments.length>1&&arguments[1]!==void 0?arguments[1]:He),o)},Br=function(o){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:He,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:He;return o.transform(Qh(t,e))},Um=function(o){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:He,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:He;return o.transform(Qh(t,e),!0)},Gf=(o,t,e)=>{const s=Qh(t,e);return vo(o,qt(s,o.calcOwnMatrix())),s},Ym=(o,t)=>{var e;const{transform:{target:s}}=t;(e=s.canvas)===null||e===void 0||e.fire("object:".concat(o),T(T({},t),{},{target:s})),s.fire(o,t)},D_={left:-.5,top:-.5,center:0,bottom:.5,right:.5},se=o=>typeof o=="string"?D_[o]:o-.5,bu="not-allowed";function $m(o){return se(o.originX)===se(rt)&&se(o.originY)===se(rt)}function qm(o){return .5-se(o)}const Zs=(o,t)=>o[t],Km=(o,t,e,s)=>({e:o,transform:t,pointer:new M(e,s)});function Jm(o,t){const e=o.getTotalAngle()+Si(Math.atan2(t.y,t.x))+360;return Math.round(e%360/45)}function Xf(o,t,e,s,i){var n;let{target:r,corner:a}=o;const h=r.controls[a],c=((n=r.canvas)===null||n===void 0?void 0:n.getZoom())||1,u=r.padding/c,d=function(f,g,p,m){const y=f.getRelativeCenterPoint(),b=p!==void 0&&m!==void 0?f.translateToGivenOrigin(y,rt,rt,p,m):new M(f.left,f.top);return(f.angle?g.rotate(-Ut(f.angle),y):g).subtract(b)}(r,new M(s,i),t,e);return d.x>=u&&(d.x-=u),d.x<=-u&&(d.x+=u),d.y>=u&&(d.y-=u),d.y<=u&&(d.y+=u),d.x-=h.offsetX,d.y-=h.offsetY,d}const R_=(o,t,e,s)=>{const{target:i,offsetX:n,offsetY:r}=t,a=e-n,h=s-r,c=!Zs(i,"lockMovementX")&&i.left!==a,u=!Zs(i,"lockMovementY")&&i.top!==h;return c&&i.set(wt,a),u&&i.set(is,h),(c||u)&&Ym(Cm,Km(o,t,e,s)),c||u},Qm={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"},Uf=(o,t,e)=>(e<0&&(e+=1),e>1&&(e-=1),e<1/6?o+6*(t-o)*e:e<.5?t:e<2/3?o+(t-o)*(2/3-e)*6:o),Zm=(o,t,e,s)=>{o/=255,t/=255,e/=255;const i=Math.max(o,t,e),n=Math.min(o,t,e);let r,a;const h=(i+n)/2;if(i===n)r=a=0;else{const c=i-n;switch(a=h>.5?c/(2-i-n):c/(i+n),i){case o:r=(t-e)/c+(t<e?6:0);break;case t:r=(e-o)/c+2;break;case e:r=(o-t)/c+4}r/=6}return[Math.round(360*r),Math.round(100*a),Math.round(100*h),s]},t0=function(){let o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"1";return parseFloat(o)/(o.endsWith("%")?100:1)},yu=o=>Math.min(Math.round(o),255).toString(16).toUpperCase().padStart(2,"0"),e0=o=>{let[t,e,s,i=1]=o;const n=Math.round(.3*t+.59*e+.11*s);return[n,n,n,i]};class St{constructor(t){if(E(this,"isUnrecognised",!1),t)if(t instanceof St)this.setSource([...t._source]);else if(Array.isArray(t)){const[e,s,i,n=1]=t;this.setSource([e,s,i,n])}else this.setSource(this._tryParsingColor(t));else this.setSource([0,0,0,1])}_tryParsingColor(t){return(t=t.toLowerCase())in Qm&&(t=Qm[t]),t==="transparent"?[255,255,255,0]:St.sourceFromHex(t)||St.sourceFromRgb(t)||St.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]=Zm(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(s,"%)")}toHsla(){const[t,e,s,i]=Zm(...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(yu(t)).concat(yu(e)).concat(yu(s)).concat(yu(Math.round(255*i)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(e0(this.getSource())),this}toBlackWhite(t){const[e,,,s]=e0(this.getSource()),i=e<(t||127)?0:255;return this.setSource([i,i,i,s]),this}overlayWith(t){t instanceof St||(t=new St(t));const e=this.getSource(),s=t.getSource(),[i,n,r]=e.map((a,h)=>Math.round(.5*a+.5*s[h]));return this.setSource([i,n,r,e[3]]),this}static fromRgb(t){return St.fromRgba(t)}static fromRgba(t){return new St(St.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 a=parseFloat(r);return r.endsWith("%")?Math.round(2.55*a):a});return[s,i,n,t0(e[4])]}}static fromHsl(t){return St.fromHsla(t)}static fromHsla(t){return new St(St.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=(St.parseAngletoDegrees(e[1])%360+360)%360/360,i=parseFloat(e[2])/100,n=parseFloat(e[3])/100;let r,a,h;if(i===0)r=a=h=n;else{const c=n<=.5?n*(i+1):n+i-n*i,u=2*n-c;r=Uf(u,c,s+1/3),a=Uf(u,c,s),h=Uf(u,c,s-1/3)}return[Math.round(255*r),Math.round(255*a),Math.round(255*h),t0(e[4])]}static fromHex(t){return new St(St.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,a=255]=s.map(h=>parseInt(h,16));return[i,n,r,a/255]}}static parseAngletoDegrees(t){const e=t.toLowerCase(),s=parseFloat(e);return e.includes("rad")?Si(s):e.includes("turn")?360*s:s}}const Ge=function(o){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Of;const e=/\D{0,2}$/.exec(o),s=parseFloat(o),i=bt.DPI;switch(e==null?void 0:e[0]){case"mm":return s*i/25.4;case"cm":return s*i/2.54;case"in":return s*i;case"pt":return s*i/72;case"pc":return s*i/72*12;case"em":return s*t;default:return s}},Yf=o=>{const[t,e]=o.trim().split(" "),[s,i]=(n=t)&&n!==ze?[n.slice(1,4),n.slice(5,8)]:n===ze?[n,n]:["Mid","Mid"];var n;return{meetOrSlice:e||"meet",alignX:s,alignY:i}},Zh=function(o,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 St(t),r=n.getAlpha();e=n.toRgb(),r!==1&&(s=r.toString())}else e="none";return i?"".concat(o,": ").concat(e,"; ").concat(s?"".concat(o,"-opacity: ").concat(s,"; "):""):"".concat(o,'="').concat(e,'" ').concat(s?"".concat(o,'-opacity="').concat(s,'" '):"")};class s0{getSvgStyles(t){const e=this.fillRule?this.fillRule:"nonzero",s=this.strokeWidth?this.strokeWidth:"0",i=this.strokeDashArray?this.strokeDashArray.join(" "):ze,n=this.strokeDashOffset?this.strokeDashOffset:"0",r=this.strokeLineCap?this.strokeLineCap:"butt",a=this.strokeLineJoin?this.strokeLineJoin:"miter",h=this.strokeMiterLimit?this.strokeMiterLimit:"4",c=this.opacity!==void 0?this.opacity:"1",u=this.visible?"":" visibility: hidden;",d=t?"":this.getSvgFilter(),f=Zh(ee,this.fill);return[Zh(We,this.stroke),"stroke-width: ",s,"; ","stroke-dasharray: ",i,"; ","stroke-linecap: ",r,"; ","stroke-dashoffset: ",n,"; ","stroke-linejoin: ",a,"; ","stroke-miterlimit: ",h,"; ",f,"fill-rule: ",e,"; ","opacity: ",c,";",d,u].join("")}getSvgFilter(){return this.shadow?"filter: url(#SVGID_".concat(this.shadow.id,");"):""}getSvgCommons(){return[this.id?'id="'.concat(this.id,'" '):"",this.clipPath?'clip-path="url(#'.concat(this.clipPath.clipPathId,')" '):""].join("")}getSvgTransform(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"";const s=t?this.calcTransformMatrix():this.calcOwnMatrix(),i='transform="'.concat(mo(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(),'" '),a=i?'style="'.concat(this.getSvgFilter(),'" '):"",h=this.clipPath,c=this.strokeUniform?'vector-effect="non-scaling-stroke" ':"",u=h&&h.absolutePositioned,d=this.stroke,f=this.fill,g=this.shadow,p=[],m=t.indexOf("COMMON_PARTS");let y;h&&(h.clipPathId="CLIPPATH_".concat(Gn()),y='<clipPath id="'.concat(h.clipPathId,`" >
50
+ `)}loadFromJSON(t,e){let{signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(!t)return Promise.reject(new wi("`json` is undefined"));const i=typeof t=="string"?JSON.parse(t):t,{objects:n=[],backgroundImage:r,background:o,overlayImage:h,overlay:c,clipPath:u}=i,d=this.renderOnAddRemove;return this.renderOnAddRemove=!1,Promise.all([ma(n,{reviver:e,signal:s}),Qh({backgroundImage:r,backgroundColor:o,overlayImage:h,overlayColor:c,clipPath:u},{signal:s})]).then(f=>{let[g,p]=f;return this.clear(),this.add(...g),this.set(i),this.set(p),this.renderOnAddRemove=d,this})}clone(t){const e=this.toObject(t);return this.cloneWithoutData().loadFromJSON(e)}cloneWithoutData(){const t=ps(this);return new this.constructor(t)}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const{format:e="png",quality:s=1,multiplier:i=1,enableRetinaScaling:n=!1}=t,r=i*(n?this.getRetinaScaling():1);return Bf(this.toCanvasElement(r,t),e,s)}toBlob(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const{format:e="png",quality:s=1,multiplier:i=1,enableRetinaScaling:n=!1}=t,r=i*(n?this.getRetinaScaling():1);return Hf(this.toCanvasElement(r,t),e,s)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:1,{width:e,height:s,left:i,top:n,filter:r}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const o=(e||this.width)*t,h=(s||this.height)*t,c=this.getZoom(),u=this.width,d=this.height,f=this.skipControlsDrawing,g=c*t,p=this.viewportTransform,m=[g,0,0,g,(p[4]-(i||0))*t,(p[5]-(n||0))*t],y=this.enableRetinaScaling,b=ps({width:o,height:h}),x=r?this._objects.filter(C=>r(C)):this._objects;return this.enableRetinaScaling=!1,this.viewportTransform=m,this.width=o,this.height=h,this.skipControlsDrawing=!0,this.calcViewportBoundaries(),this.renderCanvas(b.getContext("2d"),x),this.viewportTransform=p,this.width=u,this.height=d,this.calcViewportBoundaries(),this.enableRetinaScaling=y,this.skipControlsDrawing=f,b}dispose(){return!this.disposed&&this.elements.cleanupDOM({width:this.width,height:this.height}),gu.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," }>")}}k(Zh,"ownDefaults",I_);const j_=["touchstart","touchmove","touchend"],Um=a=>{const t=zm(a.target),e=function(s){const i=s.changedTouches;return i&&i[0]?i[0]:s}(a);return new O(e.clientX+t.left,e.clientY+t.top)},bu=a=>j_.includes(a.type)||a.pointerType==="touch",Ym=a=>{a.preventDefault(),a.stopPropagation()},Ai=a=>{let t=0,e=0,s=0,i=0;for(let n=0,r=a.length;n<r;n++){const{x:o,y:h}=a[n];(o>s||!n)&&(s=o),(o<t||!n)&&(t=o),(h>i||!n)&&(i=h),(h<e||!n)&&(e=h)}return{left:t,top:e,width:s-t,height:i-e}},N_=["translateX","translateY","scaleX","scaleY"],$m=(a,t)=>ba(a,qt(t,a.calcOwnMatrix())),ba=(a,t)=>{const e=Lr(t),{translateX:s,translateY:i,scaleX:n,scaleY:r}=e,o=Lt(e,N_),h=new O(s,i);a.flipX=!1,a.flipY=!1,Object.assign(a,o),a.set({scaleX:n,scaleY:r}),a.setPositionByOrigin(h,rt,rt)},qm=a=>{a.scaleX=1,a.scaleY=1,a.skewX=0,a.skewY=0,a.flipX=!1,a.flipY=!1,a.rotate(0)},Xf=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}),yu=(a,t,e)=>{const s=a/2,i=t/2,n=[new O(-s,-i),new O(s,-i),new O(-s,i),new O(s,i)].map(o=>o.transform(e)),r=Ai(n);return new O(r.width,r.height)},tl=function(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:He;return qt(ns(arguments.length>1&&arguments[1]!==void 0?arguments[1]:He),a)},Br=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:He,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:He;return a.transform(tl(t,e))},Km=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:He,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:He;return a.transform(tl(t,e),!0)},Uf=(a,t,e)=>{const s=tl(t,e);return ba(a,qt(s,a.calcOwnMatrix())),s},Jm=(a,t)=>{var e;const{transform:{target:s}}=t;(e=s.canvas)===null||e===void 0||e.fire("object:".concat(a),E(E({},t),{},{target:s})),s.fire(a,t)},B_={left:-.5,top:-.5,center:0,bottom:.5,right:.5},se=a=>typeof a=="string"?B_[a]:a-.5,_u="not-allowed";function Qm(a){return se(a.originX)===se(rt)&&se(a.originY)===se(rt)}function Zm(a){return .5-se(a)}const Qs=(a,t)=>a[t],tv=(a,t,e,s)=>({e:a,transform:t,pointer:new O(e,s)});function ev(a,t){const e=a.getTotalAngle()+Ci(Math.atan2(t.y,t.x))+360;return Math.round(e%360/45)}function Yf(a,t,e,s,i){var n;let{target:r,corner:o}=a;const h=r.controls[o],c=((n=r.canvas)===null||n===void 0?void 0:n.getZoom())||1,u=r.padding/c,d=function(f,g,p,m){const y=f.getRelativeCenterPoint(),b=p!==void 0&&m!==void 0?f.translateToGivenOrigin(y,rt,rt,p,m):new O(f.left,f.top);return(f.angle?g.rotate(-Ut(f.angle),y):g).subtract(b)}(r,new O(s,i),t,e);return d.x>=u&&(d.x-=u),d.x<=-u&&(d.x+=u),d.y>=u&&(d.y-=u),d.y<=u&&(d.y+=u),d.x-=h.offsetX,d.y-=h.offsetY,d}const H_=(a,t,e,s)=>{const{target:i,offsetX:n,offsetY:r}=t,o=e-n,h=s-r,c=!Qs(i,"lockMovementX")&&i.left!==o,u=!Qs(i,"lockMovementY")&&i.top!==h;return c&&i.set(wt,o),u&&i.set(is,h),(c||u)&&Jm(km,tv(a,t,e,s)),c||u},sv={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"},$f=(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),iv=(a,t,e,s)=>{a/=255,t/=255,e/=255;const i=Math.max(a,t,e),n=Math.min(a,t,e);let r,o;const h=(i+n)/2;if(i===n)r=o=0;else{const c=i-n;switch(o=h>.5?c/(2-i-n):c/(i+n),i){case a:r=(t-e)/c+(t<e?6:0);break;case t:r=(e-a)/c+2;break;case e:r=(a-t)/c+4}r/=6}return[Math.round(360*r),Math.round(100*o),Math.round(100*h),s]},nv=function(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"1";return parseFloat(a)/(a.endsWith("%")?100:1)},wu=a=>Math.min(Math.round(a),255).toString(16).toUpperCase().padStart(2,"0"),rv=a=>{let[t,e,s,i=1]=a;const n=Math.round(.3*t+.59*e+.11*s);return[n,n,n,i]};class St{constructor(t){if(k(this,"isUnrecognised",!1),t)if(t instanceof St)this.setSource([...t._source]);else if(Array.isArray(t)){const[e,s,i,n=1]=t;this.setSource([e,s,i,n])}else this.setSource(this._tryParsingColor(t));else this.setSource([0,0,0,1])}_tryParsingColor(t){return(t=t.toLowerCase())in sv&&(t=sv[t]),t==="transparent"?[255,255,255,0]:St.sourceFromHex(t)||St.sourceFromRgb(t)||St.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]=iv(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(s,"%)")}toHsla(){const[t,e,s,i]=iv(...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(wu(t)).concat(wu(e)).concat(wu(s)).concat(wu(Math.round(255*i)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(rv(this.getSource())),this}toBlackWhite(t){const[e,,,s]=rv(this.getSource()),i=e<(t||127)?0:255;return this.setSource([i,i,i,s]),this}overlayWith(t){t instanceof St||(t=new St(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 St.fromRgba(t)}static fromRgba(t){return new St(St.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,nv(e[4])]}}static fromHsl(t){return St.fromHsla(t)}static fromHsla(t){return new St(St.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=(St.parseAngletoDegrees(e[1])%360+360)%360/360,i=parseFloat(e[2])/100,n=parseFloat(e[3])/100;let r,o,h;if(i===0)r=o=h=n;else{const c=n<=.5?n*(i+1):n+i-n*i,u=2*n-c;r=$f(u,c,s+1/3),o=$f(u,c,s),h=$f(u,c,s-1/3)}return[Math.round(255*r),Math.round(255*o),Math.round(255*h),nv(e[4])]}static fromHex(t){return new St(St.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")?Ci(s):e.includes("turn")?360*s:s}}const We=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Rf;const e=/\D{0,2}$/.exec(a),s=parseFloat(a),i=mt.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}},qf=a=>{const[t,e]=a.trim().split(" "),[s,i]=(n=t)&&n!==ze?[n.slice(1,4),n.slice(5,8)]:n===ze?[n,n]:["Mid","Mid"];var n;return{meetOrSlice:e||"meet",alignX:s,alignY:i}},el=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 St(t),r=n.getAlpha();e=n.toRgb(),r!==1&&(s=r.toString())}else e="none";return i?"".concat(a,": ").concat(e,"; ").concat(s?"".concat(a,"-opacity: ").concat(s,"; "):""):"".concat(a,'="').concat(e,'" ').concat(s?"".concat(a,'-opacity="').concat(s,'" '):"")};class ov{getSvgStyles(t){const e=this.fillRule?this.fillRule:"nonzero",s=this.strokeWidth?this.strokeWidth:"0",i=this.strokeDashArray?this.strokeDashArray.join(" "):ze,n=this.strokeDashOffset?this.strokeDashOffset:"0",r=this.strokeLineCap?this.strokeLineCap:"butt",o=this.strokeLineJoin?this.strokeLineJoin:"miter",h=this.strokeMiterLimit?this.strokeMiterLimit:"4",c=this.opacity!==void 0?this.opacity:"1",u=this.visible?"":" visibility: hidden;",d=t?"":this.getSvgFilter(),f=el(ee,this.fill);return[el(Ge,this.stroke),"stroke-width: ",s,"; ","stroke-dasharray: ",i,"; ","stroke-linecap: ",r,"; ","stroke-dashoffset: ",n,"; ","stroke-linejoin: ",o,"; ","stroke-miterlimit: ",h,"; ",f,"fill-rule: ",e,"; ","opacity: ",c,";",d,u].join("")}getSvgFilter(){return this.shadow?"filter: url(#SVGID_".concat(this.shadow.id,");"):""}getSvgCommons(){return[this.id?'id="'.concat(this.id,'" '):"",this.clipPath?'clip-path="url(#'.concat(this.clipPath.clipPathId,')" '):""].join("")}getSvgTransform(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"";const s=t?this.calcTransformMatrix():this.calcOwnMatrix(),i='transform="'.concat(va(s));return"".concat(i).concat(e,'" ')}_toSVG(t){return[""]}toSVG(t){return this._createBaseSVGMarkup(this._toSVG(t),{reviver:t})}toClipPathSVG(t){return" "+this._createBaseClipPathSVGMarkup(this._toSVG(t),{reviver:t})}_createBaseClipPathSVGMarkup(t){let{reviver:e,additionalTransform:s=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const i=[this.getSvgTransform(!0,s),this.getSvgCommons()].join(""),n=t.indexOf("COMMON_PARTS");return t[n]=i,e?e(t.join("")):t.join("")}_createBaseSVGMarkup(t){let{noStyle:e,reviver:s,withShadow:i,additionalTransform:n}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const r=e?"":'style="'.concat(this.getSvgStyles(),'" '),o=i?'style="'.concat(this.getSvgFilter(),'" '):"",h=this.clipPath,c=this.strokeUniform?'vector-effect="non-scaling-stroke" ':"",u=h&&h.absolutePositioned,d=this.stroke,f=this.fill,g=this.shadow,p=[],m=t.indexOf("COMMON_PARTS");let y;h&&(h.clipPathId="CLIPPATH_".concat(Wn()),y='<clipPath id="'.concat(h.clipPathId,`" >
51
51
  `).concat(h.toClipPathSVG(s),`</clipPath>
52
- `)),u&&p.push("<g ",a,this.getSvgCommons(),` >
53
- `),p.push("<g ",this.getSvgTransform(!1),u?"":a+this.getSvgCommons(),` >
54
- `);const b=[r,c,e?"":this.addPaintOrder()," ",n?'transform="'.concat(n,'" '):""].join("");return t[m]=b,Fs(f)&&p.push(f.toSVG(this)),Fs(d)&&p.push(d.toSVG(this)),g&&p.push(g.toSVG(this)),h&&p.push(y),p.push(t.join("")),p.push(`</g>
52
+ `)),u&&p.push("<g ",o,this.getSvgCommons(),` >
53
+ `),p.push("<g ",this.getSvgTransform(!1),u?"":o+this.getSvgCommons(),` >
54
+ `);const b=[r,c,e?"":this.addPaintOrder()," ",n?'transform="'.concat(n,'" '):""].join("");return t[m]=b,Rs(f)&&p.push(f.toSVG(this)),Rs(d)&&p.push(d.toSVG(this)),g&&p.push(g.toSVG(this)),h&&p.push(y),p.push(t.join("")),p.push(`</g>
55
55
  `),u&&p.push(`</g>
56
- `),s?s(p.join("")):p.join("")}addPaintOrder(){return this.paintFirst!==ee?' paint-order="'.concat(this.paintFirst,'" '):""}}function _u(o){return new RegExp("^("+o.join("|")+")\\b","i")}var i0;const ti=String.raw(i0||(i0=zn(["(?:[-+]?(?:d*.d+|d+.?)(?:[eE][-+]?d+)?)"],["(?:[-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?)"]))),$f="http://www.w3.org/2000/svg",F_=new RegExp("(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*("+ti+"(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|"+ti+"))?\\s+(.*)"),L_={cx:wt,x:wt,r:"radius",cy:is,y:is,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"},qf="font-size",Kf="clip-path",I_=_u(["path","circle","polygon","polyline","ellipse","rect","line","image","text"]),j_=_u(["symbol","image","marker","pattern","view","svg"]),n0=_u(["symbol","g","a","svg","clipPath","defs"]),r0=new RegExp("^\\s*("+ti+"+)\\s*,?\\s*("+ti+"+)\\s*,?\\s*("+ti+"+)\\s*,?\\s*("+ti+"+)\\s*$"),N_=new M(1,0),a0=new M,Jf=(o,t)=>o.rotate(t),wu=(o,t)=>new M(t).subtract(o),xu=o=>o.distanceFrom(a0),Su=(o,t)=>Math.atan2(bo(o,t),h0(o,t)),o0=o=>Su(N_,o),Cu=o=>o.eq(a0)?o:o.scalarDivide(xu(o)),Qf=function(o){let t=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];return Cu(new M(-o.y,o.x).scalarMultiply(t?1:-1))},bo=(o,t)=>o.x*t.y-o.y*t.x,h0=(o,t)=>o.x*t.x+o.y*t.y,Zf=(o,t,e)=>{if(o.eq(t)||o.eq(e))return!0;const s=bo(t,e),i=bo(t,o),n=bo(e,o);return s>=0?i>=0&&n<=0:!(i<=0&&n>=0)},l0="(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?",c0=new RegExp("(?:\\s|^)"+l0+l0+"("+ti+"?(?:px)?)?(?:\\s?|$)(?:$|\\s)");class Ki{constructor(t){const e=typeof t=="string"?Ki.parseShadow(t):t;Object.assign(this,Ki.ownDefaults,e),this.id=Gn()}static parseShadow(t){const e=t.trim(),[,s=0,i=0,n=0]=(c0.exec(e)||[]).map(r=>parseFloat(r)||0);return{color:(e.replace(c0,"")||"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=Jf(new M(this.offsetX,this.offsetY),Ut(-t.angle)),s=new St(this.color);let i=40,n=40;return t.width&&t.height&&(i=100*Dt((Math.abs(e.x)+this.blur)/t.width,bt.NUM_FRACTION_DIGITS)+20,n=100*Dt((Math.abs(e.y)+this.blur)/t.height,bt.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,`%" >
57
- <feGaussianBlur in="SourceAlpha" stdDeviation="`).concat(Dt(this.blur?this.blur/2:0,bt.NUM_FRACTION_DIGITS),`"></feGaussianBlur>
58
- <feOffset dx="`).concat(Dt(e.x,bt.NUM_FRACTION_DIGITS),'" dy="').concat(Dt(e.y,bt.NUM_FRACTION_DIGITS),`" result="oBlur" ></feOffset>
56
+ `),s?s(p.join("")):p.join("")}addPaintOrder(){return this.paintFirst!==ee?' paint-order="'.concat(this.paintFirst,'" '):""}}function xu(a){return new RegExp("^("+a.join("|")+")\\b","i")}const Hr="textDecorationThickness",av=["fontSize","fontWeight","fontFamily","fontStyle"],hv=["underline","overline","linethrough"],lv=[...av,"lineHeight","text","charSpacing","textAlign","styles","path","pathStartOffset","pathSide","pathAlign"],cv=[...lv,...hv,"textBackgroundColor","direction",Hr],z_=[...av,...hv,Ge,"strokeWidth",ee,"deltaY","textBackgroundColor",Hr],V_={_reNewline:Lf,_reSpacesAndTabs:/[ \t\r]/g,_reSpaceAndTab:/[ \t\r]/,_reWords:/\S+/g,fontSize:40,fontWeight:"normal",fontFamily:"Times New Roman",underline:!1,overline:!1,linethrough:!1,textAlign:wt,fontStyle:"normal",lineHeight:1.16,textBackgroundColor:"",stroke:null,shadow:null,path:void 0,pathStartOffset:0,pathSide:wt,pathAlign:"baseline",charSpacing:0,deltaY:0,direction:"ltr",CACHE_FONT_SIZE:400,MIN_TEXT_WIDTH:2,superscript:{size:.6,baseline:-.35},subscript:{size:.6,baseline:.11},_fontSizeFraction:.222,offsets:{underline:.1,linethrough:-.28167,overline:-.81333},_fontSizeMult:1.13,[Hr]:66.667},Ti="justify",Su="justify-left",sl="justify-right",il="justify-center";var uv,dv,fv;const Zs=String.raw(uv||(uv=_i(["[-+]?(?:d*.d+|d+.?)(?:[eE][-+]?d+)?"],["[-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?"]))),Kf=String.raw(dv||(dv=_i(["(?:s*,?s+|s*,s*)"],["(?:\\s*,?\\s+|\\s*,\\s*)"]))),Jf="http://www.w3.org/2000/svg",G_=new RegExp("(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*("+Zs+"(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|"+Zs+"))?\\s+(.*)"),W_={cx:wt,x:wt,r:"radius",cy:is,y:is,display:"visible",visibility:"visible",transform:"transformMatrix","fill-opacity":"fillOpacity","fill-rule":"fillRule","font-family":"fontFamily","font-size":"fontSize","font-style":"fontStyle","font-weight":"fontWeight","letter-spacing":"charSpacing","paint-order":"paintFirst","stroke-dasharray":"strokeDashArray","stroke-dashoffset":"strokeDashOffset","stroke-linecap":"strokeLineCap","stroke-linejoin":"strokeLineJoin","stroke-miterlimit":"strokeMiterLimit","stroke-opacity":"strokeOpacity","stroke-width":"strokeWidth","text-decoration":"textDecoration","text-anchor":"textAnchor",opacity:"opacity","clip-path":"clipPath","clip-rule":"clipRule","vector-effect":"strokeUniform","image-rendering":"imageSmoothing","text-decoration-thickness":Hr},Qf="font-size",Zf="clip-path",X_=xu(["path","circle","polygon","polyline","ellipse","rect","line","image","text"]),U_=xu(["symbol","image","marker","pattern","view","svg"]),gv=xu(["symbol","g","a","svg","clipPath","defs"]),pv=new RegExp(String.raw(fv||(fv=_i(["^s*(",")","(",")","(",")","(",")s*$"],["^\\s*(",")","(",")","(",")","(",")\\s*$"])),Zs,Kf,Zs,Kf,Zs,Kf,Zs)),Y_=new O(1,0),mv=new O,tg=(a,t)=>a.rotate(t),Cu=(a,t)=>new O(t).subtract(a),Au=a=>a.distanceFrom(mv),Tu=(a,t)=>Math.atan2(ya(a,t),bv(a,t)),vv=a=>Tu(Y_,a),Eu=a=>a.eq(mv)?a:a.scalarDivide(Au(a)),eg=function(a){let t=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];return Eu(new O(-a.y,a.x).scalarMultiply(t?1:-1))},ya=(a,t)=>a.x*t.y-a.y*t.x,bv=(a,t)=>a.x*t.x+a.y*t.y,sg=(a,t,e)=>{if(a.eq(t)||a.eq(e))return!0;const s=ya(t,e),i=ya(t,a),n=ya(e,a);return s>=0?i>=0&&n<=0:!(i<=0&&n>=0)},yv="(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?",_v=new RegExp("(?:\\s|^)"+yv+yv+"("+Zs+"?(?:px)?)?(?:\\s?|$)(?:$|\\s)");class Qi{constructor(t){const e=typeof t=="string"?Qi.parseShadow(t):t;Object.assign(this,Qi.ownDefaults,e),this.id=Wn()}static parseShadow(t){const e=t.trim(),[,s=0,i=0,n=0]=(_v.exec(e)||[]).map(r=>parseFloat(r)||0);return{color:(e.replace(_v,"")||"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=tg(new O(this.offsetX,this.offsetY),Ut(-t.angle)),s=new St(this.color);let i=40,n=40;return t.width&&t.height&&(i=100*kt((Math.abs(e.x)+this.blur)/t.width,mt.NUM_FRACTION_DIGITS)+20,n=100*kt((Math.abs(e.y)+this.blur)/t.height,mt.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,`%" >
57
+ <feGaussianBlur in="SourceAlpha" stdDeviation="`).concat(kt(this.blur?this.blur/2:0,mt.NUM_FRACTION_DIGITS),`"></feGaussianBlur>
58
+ <feOffset dx="`).concat(kt(e.x,mt.NUM_FRACTION_DIGITS),'" dy="').concat(kt(e.y,mt.NUM_FRACTION_DIGITS),`" result="oBlur" ></feOffset>
59
59
  <feFlood flood-color="`).concat(s.toRgb(),'" flood-opacity="').concat(s.getAlpha(),`"/>
60
60
  <feComposite in2="oBlur" operator="in" />
61
61
  <feMerge>
@@ -63,44 +63,44 @@ Resulting to default behavior: removing object from previous canvas and adding t
63
63
  <feMergeNode in="SourceGraphic"></feMergeNode>
64
64
  </feMerge>
65
65
  </filter>
66
- `)}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=Ki.ownDefaults;return this.includeDefaultValues?t:zf(t,(s,i)=>s!==e[i])}static async fromObject(t){return new this(t)}}E(Ki,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),E(Ki,"type","shadow"),W.setClass(Ki,"shadow");const Hr=(o,t,e)=>Math.max(o,Math.min(t,e)),B_=[is,wt,Ve,gs,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",co,uo],Ji=[ee,We,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],H_={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:wt,originY:is,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:ee,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},tg=(o,t,e,s)=>(o<Math.abs(t)?(o=t,s=e/4):s=t===0&&o===0?e/qi*Math.asin(1):e/qi*Math.asin(t/o),{a:o,c:t,p:e,s}),u0=(o,t,e,s,i)=>o*Math.pow(2,10*(s-=1))*Math.sin((s*i-t)*qi/e),d0=(o,t,e,s)=>-e*Math.cos(o/s*Vn)+e+t,eg=(o,t,e,s)=>(o/=s)<1/2.75?e*(7.5625*o*o)+t:o<2/2.75?e*(7.5625*(o-=1.5/2.75)*o+.75)+t:o<2.5/2.75?e*(7.5625*(o-=2.25/2.75)*o+.9375)+t:e*(7.5625*(o-=2.625/2.75)*o+.984375)+t,f0=(o,t,e,s)=>e-eg(s-o,0,e,s)+t;var z_=Object.freeze({__proto__:null,defaultEasing:d0,easeInBack:function(o,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return e*(o/=s)*o*((i+1)*o-i)+t},easeInBounce:f0,easeInCirc:(o,t,e,s)=>-e*(Math.sqrt(1-(o/=s)*o)-1)+t,easeInCubic:(o,t,e,s)=>e*(o/s)**3+t,easeInElastic:(o,t,e,s)=>{const i=e;let n=0;if(o===0)return t;if((o/=s)===1)return t+e;n||(n=.3*s);const{a:r,s:a,p:h}=tg(i,e,n,1.70158);return-u0(r,a,h,o,s)+t},easeInExpo:(o,t,e,s)=>o===0?t:e*2**(10*(o/s-1))+t,easeInOutBack:function(o,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return(o/=s/2)<1?e/2*(o*o*((1+(i*=1.525))*o-i))+t:e/2*((o-=2)*o*((1+(i*=1.525))*o+i)+2)+t},easeInOutBounce:(o,t,e,s)=>o<s/2?.5*f0(2*o,0,e,s)+t:.5*eg(2*o-s,0,e,s)+.5*e+t,easeInOutCirc:(o,t,e,s)=>(o/=s/2)<1?-e/2*(Math.sqrt(1-o**2)-1)+t:e/2*(Math.sqrt(1-(o-=2)*o)+1)+t,easeInOutCubic:(o,t,e,s)=>(o/=s/2)<1?e/2*o**3+t:e/2*((o-2)**3+2)+t,easeInOutElastic:(o,t,e,s)=>{const i=e;let n=0;if(o===0)return t;if((o/=s/2)===2)return t+e;n||(n=s*(.3*1.5));const{a:r,s:a,p:h,c}=tg(i,e,n,1.70158);return o<1?-.5*u0(r,a,h,o,s)+t:r*Math.pow(2,-10*(o-=1))*Math.sin((o*s-a)*qi/h)*.5+c+t},easeInOutExpo:(o,t,e,s)=>o===0?t:o===s?t+e:(o/=s/2)<1?e/2*2**(10*(o-1))+t:e/2*-(2**(-10*--o)+2)+t,easeInOutQuad:(o,t,e,s)=>(o/=s/2)<1?e/2*o**2+t:-e/2*(--o*(o-2)-1)+t,easeInOutQuart:(o,t,e,s)=>(o/=s/2)<1?e/2*o**4+t:-e/2*((o-=2)*o**3-2)+t,easeInOutQuint:(o,t,e,s)=>(o/=s/2)<1?e/2*o**5+t:e/2*((o-2)**5+2)+t,easeInOutSine:(o,t,e,s)=>-e/2*(Math.cos(Math.PI*o/s)-1)+t,easeInQuad:(o,t,e,s)=>e*(o/=s)*o+t,easeInQuart:(o,t,e,s)=>e*(o/=s)*o**3+t,easeInQuint:(o,t,e,s)=>e*(o/s)**5+t,easeInSine:(o,t,e,s)=>-e*Math.cos(o/s*Vn)+e+t,easeOutBack:function(o,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return e*((o=o/s-1)*o*((i+1)*o+i)+1)+t},easeOutBounce:eg,easeOutCirc:(o,t,e,s)=>e*Math.sqrt(1-(o=o/s-1)*o)+t,easeOutCubic:(o,t,e,s)=>e*((o/s-1)**3+1)+t,easeOutElastic:(o,t,e,s)=>{const i=e;let n=0;if(o===0)return t;if((o/=s)===1)return t+e;n||(n=.3*s);const{a:r,s:a,p:h,c}=tg(i,e,n,1.70158);return r*2**(-10*o)*Math.sin((o*s-a)*qi/h)+c+t},easeOutExpo:(o,t,e,s)=>o===s?t+e:e*-(2**(-10*o/s)+1)+t,easeOutQuad:(o,t,e,s)=>-e*(o/=s)*(o-2)+t,easeOutQuart:(o,t,e,s)=>-e*((o=o/s-1)*o**3-1)+t,easeOutQuint:(o,t,e,s)=>e*((o/s-1)**5+1)+t,easeOutSine:(o,t,e,s)=>e*Math.sin(o/s*Vn)+t});const V_=()=>!1;class sg{constructor(t){let{startValue:e,byValue:s,duration:i=500,delay:n=0,easing:r=d0,onStart:a=Rr,onChange:h=Rr,onComplete:c=Rr,abort:u=V_,target:d}=t;E(this,"_state","pending"),E(this,"durationProgress",0),E(this,"valueProgress",0),this.tick=this.tick.bind(this),this.duration=i,this.delay=n,this.easing=r,this._onStart=a,this._onChange=h,this._onComplete=c,this._abort=u,this.target=d,this.startValue=e,this.byValue=s,this.value=this.startValue,this.endValue=Object.freeze(this.calculate(this.duration).value)}get state(){return this._state}isDone(){return this._state==="aborted"||this._state==="completed"}start(){const t=e=>{this._state==="pending"&&(this.startTime=e||+new Date,this._state="running",this._onStart(),this.tick(this.startTime))};this.register(),this.delay>0?setTimeout(()=>Yh(t),this.delay):Yh(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),Yh(this.tick)))}register(){du.push(this)}unregister(){du.remove(this)}abort(){this._state="aborted",this.unregister()}}const W_=["startValue","endValue"];class G_ extends sg{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(T(T({},Lt(t,W_)),{},{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 X_=["startValue","endValue"];class U_ extends sg{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(T(T({},Lt(t,X_)),{},{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 Y_=["startValue","endValue","easing","onChange","onComplete","abort"],$_=(o,t,e,s)=>t+e*(1-Math.cos(o/s*Vn)),ig=o=>o&&((t,e,s)=>o(new St(t).toRgba(),e,s));class q_ extends sg{constructor(t){let{startValue:e,endValue:s,easing:i=$_,onChange:n,onComplete:r,abort:a}=t,h=Lt(t,Y_);const c=new St(e).getSource(),u=new St(s).getSource();super(T(T({},h),{},{startValue:c,byValue:u.map((d,f)=>d-c[f]),easing:i,onChange:ig(n),onComplete:ig(r),abort:ig(a)}))}calculate(t){const[e,s,i,n]=this.startValue.map((a,h)=>this.easing(t,a,this.byValue[h],this.duration,h)),r=[...[e,s,i].map(Math.round),Hr(0,n,1)];return{value:r,valueProgress:r.map((a,h)=>this.byValue[h]!==0?Math.abs((a-this.startValue[h])/this.byValue[h]):0).find(a=>a!==0)||0}}}function ng(o){const t=(e=>Array.isArray(e.startValue)||Array.isArray(e.endValue))(o)?new U_(o):new G_(o);return t.start(),t}function g0(o){const t=new q_(o);return t.start(),t}class zt{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=wu(e,s),r=wu(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 a=e.x-t.x,h=e.y-t.y,c=i.x-s.x,u=i.y-s.y,d=t.x-s.x,f=t.y-s.y,g=c*f-u*d,p=a*f-h*d,m=u*a-c*h;if(m!==0){const y=g/m,b=p/m;return(n||0<=y&&y<=1)&&(r||0<=b&&b<=1)?new zt("Intersection").append(new M(t.x+y*a,t.y+y*h)):new zt}if(g===0||p===0){const y=n||r||zt.isPointContained(t,s,i)||zt.isPointContained(e,s,i)||zt.isPointContained(s,t,e)||zt.isPointContained(i,t,e);return new zt(y?"Coincident":void 0)}return new zt("Parallel")}static intersectSegmentLine(t,e,s,i){return zt.intersectLineLine(t,e,s,i,!1,!0)}static intersectSegmentSegment(t,e,s,i){return zt.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 zt,r=s.length;for(let a,h,c,u=0;u<r;u++){if(a=s[u],h=s[(u+1)%r],c=zt.intersectLineLine(t,e,a,h,i,!1),c.status==="Coincident")return c;n.append(...c.points)}return n.points.length>0&&(n.status="Intersection"),n}static intersectSegmentPolygon(t,e,s){return zt.intersectLinePolygon(t,e,s,!1)}static intersectPolygonPolygon(t,e){const s=new zt,i=t.length,n=[];for(let r=0;r<i;r++){const a=t[r],h=t[(r+1)%i],c=zt.intersectSegmentPolygon(a,h,e);c.status==="Coincident"?(n.push(c),s.append(a,h)):s.append(...c.points)}return n.length>0&&n.length===t.length?new zt("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),a=new M(i.x,n.y);return zt.intersectPolygonPolygon(t,[i,r,n,a])}}class K_ extends km{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?Ee(t,this.group.calcTransformMatrix()):t}setXY(t,e,s){this.group&&(t=Ee(t,ns(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(a=>Ee(a,r))}return n}intersectsWithRect(t,e){return zt.intersectPolygonRectangle(this.getCoords(),t,e).status==="Intersection"}intersectsWithObject(t){const e=zt.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 zt.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 Ci(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(Ve,t),this._set(gs,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?Si(Dm(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.viewportTransform)||He.concat()}calcACoords(){const t=Ir({angle:this.angle}),{x:e,y:s}=this.getRelativeCenterPoint(),i=go(e,s),n=qt(i,t),r=this._getTransformedDimensions(),a=r.x/2,h=r.y/2;return{tl:Ee({x:-a,y:-h},n),tr:Ee({x:a,y:-h},n),bl:Ee({x:-a,y:h},n),br:Ee({x:a,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,se(this.originX),se(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=qt(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=Fm(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,a=e.height+i;let h;return h=e.skewX===0&&e.skewY===0?new M(r*e.scaleX,a*e.scaleY):vu(r,a,$h(e)),h.scalarAdd(n)}translateToGivenOrigin(t,e,s,i,n){let r=t.x,a=t.y;const h=se(i)-se(e),c=se(n)-se(s);if(h||c){const u=this._getTransformedDimensions();r+=h*u.x,a+=c*u.y}return new M(r,a)}translateToCenterPoint(t,e,s){if(e===rt&&s===rt)return t;const i=this.translateToGivenOrigin(t,e,s,rt,rt);return this.angle?i.rotate(Ut(this.angle),t):i}translateToOriginPoint(t,e,s){const i=this.translateToGivenOrigin(t,rt,rt,e,s);return this.angle?i.rotate(Ut(this.angle),t):i}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?Ee(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(),wt,is)}}const J_=["type"],Q_=["extraParam"];let Qi=class Jd extends K_{static getDefaults(){return Jd.ownDefaults}get type(){const t=this.constructor.type;return t==="FabricObject"?"object":t.toLowerCase()}set type(t){$i("warn","Setting type has no effect",t)}constructor(t){super(),E(this,"_cacheContext",null),Object.assign(this,Jd.ownDefaults),this.setOptions(t)}_createCacheCanvas(){this._cacheCanvas=Rs(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,s=t.height,i=bt.maxCacheSideLimit,n=bt.minCacheSideLimit;if(e<=i&&s<=i&&e*s<=bt.perfLimitSizeTotal)return e<n&&(t.width=n),s<n&&(t.height=n),t;const r=e/s,[a,h]=Xh.limitDimsByArea(r),c=Hr(n,a,i),u=Hr(n,h,i);return e>c&&(t.zoomX/=e/c,t.width=c,t.capped=!0),s>u&&(t.zoomY/=s/u,t.height=u,t.capped=!0),t}_getCacheCanvasDimensions(){const t=this.getTotalObjectScaling(),e=this._getTransformedDimensions({skewX:0,skewY:0}),s=e.x*t.x/this.scaleX,i=e.y*t.y/this.scaleY;return{width:Math.ceil(s+2),height:Math.ceil(i+2),zoomX:t.x,zoomY:t.y,x:s,y:i}}_updateCacheCanvas(){const t=this._cacheCanvas,e=this._cacheContext,{width:s,height:i,zoomX:n,zoomY:r,x:a,y:h}=this._limitCacheSize(this._getCacheCanvasDimensions()),c=s!==t.width||i!==t.height,u=this.zoomX!==n||this.zoomY!==r;if(!t||!e)return!1;if(c||u){s!==t.width||i!==t.height?(t.width=s,t.height=i):(e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,t.width,t.height));const d=a/2,f=h/2;return this.cacheTranslationX=Math.round(t.width/2-d)+d,this.cacheTranslationY=Math.round(t.height/2-f)+f,e.translate(this.cacheTranslationX,this.cacheTranslationY),e.scale(n,r),this.zoomX=n,this.zoomY=r,!0}return!1}setOptions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this._setOptions(t)}transform(t){const e=this.group&&!this.group._transformDone||this.group&&this.canvas&&t===this.canvas.contextTop,s=this.calcTransformMatrix(!e);t.transform(s[0],s[1],s[2],s[3],s[4],s[5])}getObjectScaling(){if(!this.group)return new M(Math.abs(this.scaleX),Math.abs(this.scaleY));const t=Lr(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!==Ve&&t!==gs||(e=this._constrainScale(e)),t===Ve&&e<0?(this.flipX=!this.flipX,e*=-1):t==="scaleY"&&e<0?(this.flipY=!this.flipY,e*=-1):t!=="shadow"||!e||e instanceof Ki||(e=new Ki(e));const s=this[t]!==e;return this[t]=e,s&&this.constructor.cacheProperties.includes(t)&&(this.dirty=!0),this.parent&&(this.dirty||s&&this.constructor.stateProperties.includes(t))&&this.parent._set("dirty",!0),this}isNotVisible(){return this.opacity===0||!this.width&&!this.height&&this.strokeWidth===0||!this.visible}render(t){this.isNotVisible()||this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(t.save(),this._setupCompositeOperation(t),this.drawSelectionBackground(t),this.transform(t),this._setOpacity(t),this._setShadow(t),this.shouldCache()?(this.renderCache(),this.drawCacheOnCanvas(t)):(this._removeCacheCanvas(),this.drawObject(t,!1,{}),this.dirty=!1),t.restore())}drawSelectionBackground(t){}renderCache(t){if(t=t||{},this._cacheCanvas&&this._cacheContext||this._createCacheCanvas(),this.isCacheDirty()&&this._cacheContext){const{zoomX:e,zoomY:s,cacheTranslationX:i,cacheTranslationY:n}=this,{width:r,height:a}=this._cacheCanvas;this.drawObject(this._cacheContext,t.forClipping,{zoomX:e,zoomY:s,cacheTranslationX:i,cacheTranslationY:n,width:r,height:a,parentClipPaths:[]}),this.dirty=!1}}_removeCacheCanvas(){this._cacheCanvas=void 0,this._cacheContext=null}hasStroke(){return this.stroke&&this.stroke!=="transparent"&&this.strokeWidth!==0}hasFill(){return this.fill&&this.fill!=="transparent"}needsItsOwnCache(){return!!(this.paintFirst===We&&this.hasFill()&&this.hasStroke()&&this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.objectCaching&&(!this.parent||!this.parent.isOnACache())||this.needsItsOwnCache(),this.ownCaching}willDrawShadow(){return!!this.shadow&&(this.shadow.offsetX!==0||this.shadow.offsetY!==0)}drawClipPathOnCache(t,e,s){t.save(),e.inverted?t.globalCompositeOperation="destination-out":t.globalCompositeOperation="destination-in",t.setTransform(1,0,0,1,0,0),t.drawImage(s,0,0),t.restore()}drawObject(t,e,s){const i=this.fill,n=this.stroke;e?(this.fill="black",this.stroke="",this._setClippingProperties(t)):this._renderBackground(t),this._render(t),this._drawClipPath(t,this.clipPath,s),this.fill=i,this.stroke=n}createClipPathLayer(t,e){const s=ps(e),i=s.getContext("2d");if(i.translate(e.cacheTranslationX,e.cacheTranslationY),i.scale(e.zoomX,e.zoomY),t._cacheCanvas=s,e.parentClipPaths.forEach(n=>{n.transform(i)}),e.parentClipPaths.push(t),t.absolutePositioned){const n=ns(this.calcTransformMatrix());i.transform(n[0],n[1],n[2],n[3],n[4],n[5])}return t.transform(i),t.drawObject(i,!0,e),s}_drawClipPath(t,e,s){if(!e)return;e._transformDone=!0;const i=this.createClipPathLayer(e,s);this.drawClipPathOnCache(t,e,i)}drawCacheOnCanvas(t){t.scale(1/this.zoomX,1/this.zoomY),t.drawImage(this._cacheCanvas,-this.cacheTranslationX,-this.cacheTranslationY)}isCacheDirty(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0];if(this.isNotVisible())return!1;const e=this._cacheCanvas,s=this._cacheContext;return!(!e||!s||t||!this._updateCacheCanvas())||!!(this.dirty||this.clipPath&&this.clipPath.absolutePositioned)&&(e&&s&&!t&&(s.save(),s.setTransform(1,0,0,1,0,0),s.clearRect(0,0,e.width,e.height),s.restore()),!0)}_renderBackground(t){if(!this.backgroundColor)return;const e=this._getNonTransformedDimensions();t.fillStyle=this.backgroundColor,t.fillRect(-e.x/2,-e.y/2,e.x,e.y),this._removeShadow(t)}_setOpacity(t){this.group&&!this.group._transformDone?t.globalAlpha=this.getObjectOpacity():t.globalAlpha*=this.opacity}_setStrokeStyles(t,e){const s=e.stroke;s&&(t.lineWidth=e.strokeWidth,t.lineCap=e.strokeLineCap,t.lineDashOffset=e.strokeDashOffset,t.lineJoin=e.strokeLineJoin,t.miterLimit=e.strokeMiterLimit,Fs(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&&(Fs(s)?(t.fillStyle=s.toLive(t),this._applyPatternGradientTransform(t,s)):t.fillStyle=s)}_setClippingProperties(t){t.globalAlpha=1,t.strokeStyle="transparent",t.fillStyle="#000000"}_setLineDash(t,e){e&&e.length!==0&&t.setLineDash(e)}_setShadow(t){if(!this.shadow)return;const e=this.shadow,s=this.canvas,i=this.getCanvasRetinaScaling(),[n,,,r]=(s==null?void 0:s.viewportTransform)||He,a=n*i,h=r*i,c=e.nonScaling?new M(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*bt.browserShadowBlurConstant*(a+h)*(c.x+c.y)/4,t.shadowOffsetX=e.offsetX*a*c.x,t.shadowOffsetY=e.offsetY*h*c.y}_removeShadow(t){this.shadow&&(t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0)}_applyPatternGradientTransform(t,e){if(!Fs(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===We?(this._renderStroke(t),this._renderFill(t)):(this._renderFill(t),this._renderStroke(t))}_render(t){}_renderFill(t){this.fill&&(t.save(),this._setFillStyles(t,this),this.fillRule==="evenodd"?t.fill("evenodd"):t.fill(),t.restore())}_renderStroke(t){if(this.stroke&&this.strokeWidth!==0){if(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this.strokeUniform){const e=this.getObjectScaling();t.scale(1/e.x,1/e.y)}this._setLineDash(t,this.strokeDashArray),this._setStrokeStyles(t,this),t.stroke(),t.restore()}}_applyPatternForTransformedGradient(t,e){var s;const i=this._limitCacheSize(this._getCacheCanvasDimensions()),n=this.getCanvasRetinaScaling(),r=i.x/this.scaleX/n,a=i.y/this.scaleY/n,h=ps({width:Math.ceil(r),height:Math.ceil(a)}),c=h.getContext("2d");c&&(c.beginPath(),c.moveTo(0,0),c.lineTo(r,0),c.lineTo(r,a),c.lineTo(0,a),c.closePath(),c.translate(r/2,a/2),c.scale(i.zoomX/this.scaleX/n,i.zoomY/this.scaleY/n),this._applyPatternGradientTransform(c,e),c.fillStyle=e.toLive(t),c.fill(),t.translate(-this.width/2-this.strokeWidth/2,-this.height/2-this.strokeWidth/2),t.scale(n*this.scaleX/i.zoomX,n*this.scaleY/i.zoomY),t.strokeStyle=(s=c.createPattern(h,"no-repeat"))!==null&&s!==void 0?s:"")}_findCenterFromElement(){return new M(this.left+this.width/2,this.top+this.height/2)}clone(t){const e=this.toObject(t);return this.constructor.fromObject(e)}cloneAsImage(t){const e=this.toCanvasElement(t);return new(W.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=Wf(this),s=this.group,i=this.shadow,n=Math.abs,r=t.enableRetinaScaling?Sm():1,a=(t.multiplier||1)*r,h=t.canvasProvider||(x=>new Jh(x,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&Xm(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&Gf(this,this.getViewportTransform()),this.setCoords();const c=Rs(),u=this.getBoundingRect(),d=this.shadow,f=new M;if(d){const x=d.blur,S=d.nonScaling?new M(1,1):this.getObjectScaling();f.x=2*Math.round(n(d.offsetX)+x)*n(S.x),f.y=2*Math.round(n(d.offsetY)+x)*n(S.y)}const g=u.width+f.x,p=u.height+f.y;c.width=Math.ceil(g),c.height=Math.ceil(p);const m=h(c);t.format==="jpeg"&&(m.backgroundColor="#fff"),this.setPositionByOrigin(new M(m.width/2,m.height/2),rt,rt);const y=this.canvas;m._objects=[this],this.set("canvas",m),this.setCoords();const b=m.toCanvasElement(a||1,t);return this.set("canvas",y),this.shadow=i,s&&(this.group=s),this.set(e),this.setCoords(),m._objects=[],m.destroy(),b}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return jf(this.toCanvasElement(t),t.format||"png",t.quality||1)}toBlob(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return Nf(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=rt,this.originY=rt,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(){du.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&xi().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:a,onChange:h,onComplete:c}=s,u=T(T({},s),{},{target:this,startValue:a??i.reduce((d,f)=>d[f],this),endValue:e,abort:r==null?void 0:r.bind(this),onChange:(d,f,g)=>{i.reduce((p,m,y)=>(y===i.length-1&&(p[m]=d),p[m]),this),h&&h(d,f,g)},onComplete:(d,f,g)=>{this.setCoords(),c&&c(d,f,g)}});return n?g0(u):ng(u)}isDescendantOf(t){const{parent:e,group:s}=this;return e===t||s===t||!!e&&e.isDescendantOf(t)||!!s&&s!==e&&s.isDescendantOf(t)}getAncestors(){const t=[];let e=this;do e=e.parent,e&&t.push(e);while(e);return t}findCommonAncestors(t){if(this===t)return{fork:[],otherFork:[],common:[this,...this.getAncestors()]};const e=this.getAncestors(),s=t.getAncestors();if(e.length===0&&s.length>0&&this===s[s.length-1])return{fork:[],otherFork:[t,...s.slice(0,s.length-1)],common:[this]};for(let i,n=0;n<e.length;n++){if(i=e[n],i===t)return{fork:[this,...e.slice(0,n)],otherFork:[],common:e.slice(n)};for(let r=0;r<s.length;r++){if(this===s[r])return{fork:[],otherFork:[t,...s.slice(0,r)],common:[this,...e]};if(i===s[r])return{fork:[this,...e.slice(0,n)],otherFork:[t,...s.slice(0,r)],common:e.slice(n)}}}return{fork:[this,...e],otherFork:[t,...s],common:[]}}hasCommonAncestors(t){const e=this.findCommonAncestors(t);return e&&!!e.common.length}isInFrontOf(t){if(this===t)return;const e=this.findCommonAncestors(t);if(e.fork.includes(t))return!0;if(e.otherFork.includes(this))return!1;const s=e.common[0]||this.canvas;if(!s)return;const i=e.fork.pop(),n=e.otherFork.pop(),r=s._objects.indexOf(i),a=s._objects.indexOf(n);return r>-1&&r>a}toObject(){const t=(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).concat(Jd.customProperties,this.constructor.customProperties||[]);let e;const s=bt.NUM_FRACTION_DIGITS,{clipPath:i,fill:n,stroke:r,shadow:a,strokeDashArray:h,left:c,top:u,originX:d,originY:f,width:g,height:p,strokeWidth:m,strokeLineCap:y,strokeDashOffset:b,strokeLineJoin:x,strokeUniform:S,strokeMiterLimit:C,scaleX:k,scaleY:O,angle:P,flipX:D,flipY:R,opacity:z,visible:B,backgroundColor:F,fillRule:L,paintFirst:N,globalCompositeOperation:K,skewX:I,skewY:V}=this;i&&!i.excludeFromExport&&(e=i.toObject(t.concat("inverted","absolutePositioned")));const it=Bt=>Dt(Bt,s),Ot=T(T({},jr(this,t)),{},{type:this.constructor.type,version:Pf,originX:d,originY:f,left:it(c),top:it(u),width:it(g),height:it(p),fill:Lm(n)?n.toObject():n,stroke:Lm(r)?r.toObject():r,strokeWidth:it(m),strokeDashArray:h&&h.concat(),strokeLineCap:y,strokeDashOffset:b,strokeLineJoin:x,strokeUniform:S,strokeMiterLimit:it(C),scaleX:it(k),scaleY:it(O),angle:it(P),flipX:D,flipY:R,opacity:it(z),shadow:a&&a.toObject(),visible:B,backgroundColor:F,fillRule:L,paintFirst:N,globalCompositeOperation:K,skewX:it(I),skewY:it(V)},e?{clipPath:e}:null);return this.includeDefaultValues?Ot:this._removeDefaultValues(Ot)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),s=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return zf(t,(i,n)=>{if(n===wt||n===is||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=Lt(t,J_),s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{extraParam:i}=s,n=Lt(s,Q_);return Kh(e,n).then(r=>i?(delete r[i],new this(e[i],r)):new this(r))}static fromObject(t,e){return this._fromObject(t,e)}};E(Qi,"stateProperties",B_),E(Qi,"cacheProperties",Ji),E(Qi,"ownDefaults",H_),E(Qi,"type","FabricObject"),E(Qi,"colorProperties",[ee,We,"backgroundColor"]),E(Qi,"customProperties",[]),W.setClass(Qi),W.setClass(Qi,"object");const yo=(o,t,e)=>(s,i,n,r)=>{const a=t(s,i,n,r);return a&&Ym(o,T(T({},Km(s,i,n,r)),e)),a};function _o(o){return(t,e,s,i)=>{const{target:n,originX:r,originY:a}=e,h=n.getRelativeCenterPoint(),c=n.translateToOriginPoint(h,r,a),u=o(t,e,s,i);return n.setPositionByOrigin(c,e.originX,e.originY),u}}const p0=yo(Uh,_o((o,t,e,s)=>{const i=Xf(t,t.originX,t.originY,e,s);if(se(t.originX)===se(rt)||se(t.originX)===se($t)&&i.x<0||se(t.originX)===se(wt)&&i.x>0){const{target:n}=t,r=n.strokeWidth/(n.strokeUniform?n.scaleX:1),a=$m(t)?2:1,h=n.width,c=Math.abs(i.x*a/n.scaleX)-r;return n.set("width",Math.max(c,1)),h!==n.width}return!1}));function Z_(o,t,e,s,i){s=s||{};const n=this.sizeX||s.cornerSize||i.cornerSize,r=this.sizeY||s.cornerSize||i.cornerSize,a=s.transparentCorners!==void 0?s.transparentCorners:i.transparentCorners,h=a?We:ee,c=!a&&(s.cornerStrokeColor||i.cornerStrokeColor);let u,d=t,f=e;o.save(),o.fillStyle=s.cornerColor||i.cornerColor||"",o.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",n>r?(u=n,o.scale(1,r/n),f=e*n/r):r>n?(u=r,o.scale(n/r,1),d=t*r/n):u=n,o.beginPath(),o.arc(d,f,u/2,0,qi,!1),o[h](),c&&o.stroke(),o.restore()}function tw(o,t,e,s,i){s=s||{};const n=this.sizeX||s.cornerSize||i.cornerSize,r=this.sizeY||s.cornerSize||i.cornerSize,a=s.transparentCorners!==void 0?s.transparentCorners:i.transparentCorners,h=a?We:ee,c=!a&&(s.cornerStrokeColor||i.cornerStrokeColor),u=n/2,d=r/2;o.save(),o.fillStyle=s.cornerColor||i.cornerColor||"",o.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",o.translate(t,e);const f=i.getTotalAngle();o.rotate(Ut(f)),o["".concat(h,"Rect")](-u,-d,n,r),c&&o.strokeRect(-u,-d,n,r),o.restore()}class ei{constructor(t){E(this,"visible",!0),E(this,"actionName",cu),E(this,"angle",0),E(this,"x",0),E(this,"y",0),E(this,"offsetX",0),E(this,"offsetY",0),E(this,"sizeX",0),E(this,"sizeY",0),E(this,"touchSizeX",0),E(this,"touchSizeY",0),E(this,"cursorStyle","crosshair"),E(this,"withConnection",!1),Object.assign(this,t)}shouldActivate(t,e,s,i){var n;let{tl:r,tr:a,br:h,bl:c}=i;return((n=e.canvas)===null||n===void 0?void 0:n.getActiveObject())===e&&e.isControlVisible(t)&&zt.isPointInPolygon(s,[r,a,h,c])}getActionHandler(t,e,s){return this.actionHandler}getMouseDownHandler(t,e,s){return this.mouseDownHandler}getMouseUpHandler(t,e,s){return this.mouseUpHandler}cursorStyleHandler(t,e,s){return e.cursorStyle}getActionName(t,e,s){return e.actionName}getVisibility(t,e){var s,i;return(s=(i=t._controlsVisibility)===null||i===void 0?void 0:i[e])!==null&&s!==void 0?s:this.visible}setVisibility(t,e,s){this.visible=t}positionHandler(t,e,s,i){return new M(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(e)}calcCornerCoords(t,e,s,i,n,r){const a=gu([go(s,i),Ir({angle:t}),pu((n?this.touchSizeX:this.sizeX)||e,(n?this.touchSizeY:this.sizeY)||e)]);return{tl:new M(-.5,-.5).transform(a),tr:new M(.5,-.5).transform(a),br:new M(.5,.5).transform(a),bl:new M(-.5,.5).transform(a)}}render(t,e,s,i,n){((i=i||{}).cornerStyle||n.cornerStyle)==="circle"?Z_.call(this,t,e,s,i,n):tw.call(this,t,e,s,i,n)}}const ew=(o,t,e)=>e.lockRotation?bu:t.cursorStyle,sw=yo(Am,_o((o,t,e,s)=>{let{target:i,ex:n,ey:r,theta:a,originX:h,originY:c}=t;const u=i.translateToOriginPoint(i.getRelativeCenterPoint(),h,c);if(Zs(i,"lockRotation"))return!1;const d=Math.atan2(r-u.y,n-u.x),f=Math.atan2(s-u.y,e-u.x);let g=Si(f-d+a);if(i.snapAngle&&i.snapAngle>0){const m=i.snapAngle,y=i.snapThreshold||m,b=Math.ceil(g/m)*m,x=Math.floor(g/m)*m;Math.abs(g-x)<y?g=x:Math.abs(g-b)<y&&(g=b)}g<0&&(g=360+g),g%=360;const p=i.angle!==g;return i.angle=g,p}));function m0(o,t){const e=t.canvas,s=o[e.uniScaleKey];return e.uniformScaling&&!s||!e.uniformScaling&&s}function v0(o,t,e){const s=Zs(o,"lockScalingX"),i=Zs(o,"lockScalingY");if(s&&i||!t&&(s||i)&&e||s&&t==="x"||i&&t==="y")return!0;const{width:n,height:r,strokeWidth:a}=o;return n===0&&a===0&&t!=="y"||r===0&&a===0&&t!=="x"}const iw=["e","se","s","sw","w","nw","n","ne","e"],tl=(o,t,e)=>{const s=m0(o,e);if(v0(e,t.x!==0&&t.y===0?"x":t.x===0&&t.y!==0?"y":"",s))return bu;const i=Jm(e,t);return"".concat(iw[i],"-resize")};function rg(o,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{};const n=t.target,r=i.by,a=m0(o,n);let h,c,u,d,f,g;if(v0(n,r,a))return!1;if(t.gestureScale)c=t.scaleX*t.gestureScale,u=t.scaleY*t.gestureScale;else{if(h=Xf(t,t.originX,t.originY,e,s),f=r!=="y"?Math.sign(h.x||t.signX||1):1,g=r!=="x"?Math.sign(h.y||t.signY||1):1,t.signX||(t.signX=f),t.signY||(t.signY=g),Zs(n,"lockScalingFlip")&&(t.signX!==f||t.signY!==g))return!1;if(d=n._getTransformedDimensions(),a&&!r){const y=Math.abs(h.x)+Math.abs(h.y),{original:b}=t,x=y/(Math.abs(d.x*b.scaleX/n.scaleX)+Math.abs(d.y*b.scaleY/n.scaleY));c=b.scaleX*x,u=b.scaleY*x}else c=Math.abs(h.x*n.scaleX/d.x),u=Math.abs(h.y*n.scaleY/d.y);$m(t)&&(c*=2,u*=2),t.signX!==f&&r!=="y"&&(t.originX=qm(t.originX),c*=-1,t.signX=f),t.signY!==g&&r!=="x"&&(t.originY=qm(t.originY),u*=-1,t.signY=g)}const p=n.scaleX,m=n.scaleY;return r?(r==="x"&&n.set(Ve,c),r==="y"&&n.set(gs,u)):(!Zs(n,"lockScalingX")&&n.set(Ve,c),!Zs(n,"lockScalingY")&&n.set(gs,u)),p!==n.scaleX||m!==n.scaleY}const Au=yo(hu,_o((o,t,e,s)=>rg(o,t,e,s))),nw=yo(hu,_o((o,t,e,s)=>rg(o,t,e,s,{by:"x"}))),rw=yo(hu,_o((o,t,e,s)=>rg(o,t,e,s,{by:"y"}))),aw=["target","ex","ey","skewingSide"],ag={x:{counterAxis:"y",scale:Ve,skew:co,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:gs,skew:uo,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},ow=["ns","nesw","ew","nwse"],hw=(o,t,e)=>{if(t.x!==0&&Zs(e,"lockSkewingY")||t.y!==0&&Zs(e,"lockSkewingX"))return bu;const s=Jm(e,t)%4;return"".concat(ow[s],"-resize")};function b0(o,t,e,s,i){const{target:n}=e,{counterAxis:r,origin:a,lockSkewing:h,skew:c,flip:u}=ag[o];if(Zs(n,h))return!1;const{origin:d,flip:f}=ag[r],g=se(e[d])*(n[f]?-1:1),p=-Math.sign(g)*(n[u]?-1:1),m=.5*-((n[c]===0&&Xf(e,rt,rt,s,i)[o]>0||n[c]>0?1:-1)*p)+.5;return yo(Tm,_o((b,x,S,C)=>function(k,O,P){let{target:D,ex:R,ey:z,skewingSide:B}=O,F=Lt(O,aw);const{skew:L}=ag[k],N=P.subtract(new M(R,z)).divide(new M(D.scaleX,D.scaleY))[k],K=D[L],I=F[L],V=Math.tan(Ut(I)),it=k==="y"?D._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:D._getTransformedDimensions({scaleX:1,scaleY:1}).y,Ot=2*N*B/Math.max(it,1)+V,Bt=Si(Math.atan(Ot));D.set(L,Bt);const Xt=K!==D[L];if(Xt&&k==="y"){const{skewX:Ft,scaleX:_t}=D,ae=D._getTransformedDimensions({skewY:K}),Ze=D._getTransformedDimensions(),st=Ft!==0?ae.x/Ze.x:1;st!==1&&D.set(Ve,st*_t)}return Xt}(o,x,new M(S,C))))(t,T(T({},e),{},{[a]:m,skewingSide:p}),s,i)}const lw=(o,t,e,s)=>b0("x",o,t,e,s),cw=(o,t,e,s)=>b0("y",o,t,e,s);function Tu(o,t){return o[t.canvas.altActionKey]}const Eu=(o,t,e)=>{const s=Tu(o,e);return t.x===0?s?co:gs:t.y===0?s?uo:Ve:""},wo=(o,t,e)=>Tu(o,e)?hw(0,t,e):tl(o,t,e),y0=(o,t,e,s)=>Tu(o,t.target)?cw(o,t,e,s):nw(o,t,e,s),_0=(o,t,e,s)=>Tu(o,t.target)?lw(o,t,e,s):rw(o,t,e,s),w0=()=>({ml:new ei({x:-.5,y:0,cursorStyleHandler:wo,actionHandler:y0,getActionName:Eu}),mr:new ei({x:.5,y:0,cursorStyleHandler:wo,actionHandler:y0,getActionName:Eu}),mb:new ei({x:0,y:.5,cursorStyleHandler:wo,actionHandler:_0,getActionName:Eu}),mt:new ei({x:0,y:-.5,cursorStyleHandler:wo,actionHandler:_0,getActionName:Eu}),tl:new ei({x:-.5,y:-.5,cursorStyleHandler:tl,actionHandler:Au}),tr:new ei({x:.5,y:-.5,cursorStyleHandler:tl,actionHandler:Au}),bl:new ei({x:-.5,y:.5,cursorStyleHandler:tl,actionHandler:Au}),br:new ei({x:.5,y:.5,cursorStyleHandler:tl,actionHandler:Au}),mtr:new ei({x:0,y:-.5,actionHandler:sw,cursorStyleHandler:ew,offsetY:-40,withConnection:!0,actionName:Ff})}),uw=()=>({mr:new ei({x:.5,y:0,actionHandler:p0,cursorStyleHandler:wo,actionName:Uh}),ml:new ei({x:-.5,y:0,actionHandler:p0,cursorStyleHandler:wo,actionName:Uh})}),dw=()=>T(T({},w0()),uw());class el extends Qi{static getDefaults(){return T(T({},super.getDefaults()),el.ownDefaults)}constructor(t){super(),Object.assign(this,this.constructor.createControls(),el.ownDefaults),this.setOptions(t)}static createControls(){return{controls:w0()}}_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(cu))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],a=this.controls[n];if(a.shouldActivate(n,this,t,e?r.touchCorner:r.corner))return this.__corner=n,{key:n,control:a,coord:this.oCoords[n]}}}calcOCoords(){const t=this.getViewportTransform(),e=this.getCenterPoint(),s=go(e.x,e.y),i=Ir({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),n=qt(s,i),r=qt(t,n),a=qt(r,[1/t[0],0,0,1/t[3],0,0]),h=this.group?Lr(this.calcTransformMatrix()):void 0;h&&(h.scaleX=Math.abs(h.scaleX),h.scaleY=Math.abs(h.scaleY));const c=this._calculateCurrentDimensions(h),u={};return this.forEachControl((d,f)=>{const g=d.positionHandler(c,a,this,d);u[f]=Object.assign(g,this._calcCornerCoords(d,g))}),u}_calcCornerCoords(t,e){const s=this.getTotalAngle();return{corner:t.calcCornerCoords(s,this.cornerSize,e.x,e.y,!1,this),touchCorner:t.calcCornerCoords(s,this.touchCornerSize,e.x,e.y,!0,this)}}setCoords(){super.setCoords(),this.canvas&&(this.oCoords=this.calcOCoords())}forEachControl(t){for(const e in this.controls)t(this.controls[e],e,this)}drawSelectionBackground(t){if(!this.selectionBackgroundColor||this.canvas&&this.canvas._activeObject!==this)return;t.save();const e=this.getRelativeCenterPoint(),s=this._calculateCurrentDimensions(),i=this.getViewportTransform();t.translate(e.x,e.y),t.scale(1/i[0],1/i[3]),t.rotate(Ut(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(),a=n.hasBorders,h=n.hasControls,c=qt(r,this.calcTransformMatrix()),u=Lr(c);t.save(),t.translate(u.translateX,u.translateY),t.lineWidth=this.borderScaleFactor,this.group===this.parent&&(t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1),this.flipX&&(u.angle-=180),t.rotate(Ut(this.group?u.angle:this.angle)),a&&this.drawBorders(t,u,e),h&&this.drawControls(t,e),t.restore()}drawBorders(t,e,s){let i;if(s&&s.forActiveSelection||this.group){const n=vu(this.width,this.height,$h(e)),r=this.isStrokeAccountedForInDimensions()?If:(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,a=T({cornerStrokeColor:i,cornerDashArray:n,cornerColor:r},e);t.setTransform(s,0,0,s,0,0),t.strokeStyle=t.fillStyle=a.cornerColor,this.transparentCorners||(t.strokeStyle=a.cornerStrokeColor),this._setLineDash(t,a.cornerDashArray),this.forEachControl((h,c)=>{if(h.getVisibility(this,c)){const u=this.oCoords[c];h.render(t,u.x,u.y,a,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 x0(o,t){return t.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(s=>{s!=="constructor"&&Object.defineProperty(o.prototype,s,Object.getOwnPropertyDescriptor(e.prototype,s)||Object.create(null))})}),o}E(el,"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 ke extends el{}x0(ke,[s0]),W.setClass(ke),W.setClass(ke,"object");const S0=(o,t,e,s)=>{const i=2*(s=Math.round(s))+1,{data:n}=o.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 C0{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=wu(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(Ut(this.options.skewY)),e.x+=e.y*Math.tan(Ut(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}const fw=new M;class xo extends C0{static getOrthogonalRotationFactor(t,e){const s=e?Su(t,e):o0(t);return Math.abs(s)<Vn?-1:1}constructor(t,e,s,i){super(i),E(this,"AB",void 0),E(this,"AC",void 0),E(this,"alpha",void 0),E(this,"bisector",void 0),this.A=new M(t),this.B=new M(e),this.C=new M(s),this.AB=this.createSideVector(this.A,this.B),this.AC=this.createSideVector(this.A,this.C),this.alpha=Su(this.AB,this.AC),this.bisector=Cu(Jf(this.AB.eq(fw)?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=Qf(i),r=xo.getOrthogonalRotationFactor(n,this.bisector);return this.scaleUnitVector(n,s*r)}projectBevel(){const t=[];return(this.alpha%qi==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?xu(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return xu(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(xo.getOrthogonalRotationFactor(this.bisector),xo.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=>{Zf(n,t,e)&&s.push(this.A.add(n))}),s}projectRoundWithSkew(t,e){const s=[],{skewX:i,skewY:n,scaleX:r,scaleY:a,strokeUniform:h}=this.options,c=new M(Math.tan(Ut(i)),Math.tan(Ut(n))),u=this.strokeProjectionMagnitude,d=h?u/a/Math.sqrt(1/a**2+1/r**2*c.y**2):u/Math.sqrt(1+c.y**2),f=new M(Math.sqrt(Math.max(u**2-d**2,0)),d),g=h?u/Math.sqrt(1+c.x**2*(1/a)**2/(1/r+1/r*c.x*c.y)**2):u/Math.sqrt(1+c.x**2/(1+c.x*c.y)**2),p=new M(g,Math.sqrt(Math.max(u**2-g**2,0)));return[p,p.scalarMultiply(-1),f,f.scalarMultiply(-1)].map(m=>this.applySkew(h?m.multiply(this.strokeUniformScalar):m)).forEach(m=>{Zf(m,t,e)&&s.push(this.applySkew(this.A).add(m))}),s}projectRound(){const t=[];t.push(...this.projectBevel());const e=this.alpha%qi==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)),a=bo(i,r)>0,h=a?i:n,c=a?n:i;return this.isSkewed()?t.push(...this.projectRoundWithSkew(h,c)):t.push(...this.projectRoundNoSkew(h,c)),t}projectPoints(){switch(this.options.strokeLineJoin){case"miter":return this.projectMiter();case"round":return this.projectRound();default:return this.projectBevel()}}project(){return this.projectPoints().map(t=>({originPoint:this.A,projectedPoint:t,angle:this.alpha,bisector:this.bisector}))}}class A0 extends C0{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(Qf(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 xo(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(Cu(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 T0=function(o,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];const s=[];if(o.length===0)return s;const i=o.reduce((n,r)=>(n[n.length-1].eq(r)||n.push(new M(r)),n),[new M(o[0])]);if(i.length===1)e=!0;else if(!e){const n=i[0],r=((a,h)=>{for(let c=a.length-1;c>=0;c--)if(h(a[c],c,a))return c;return-1})(i,a=>!a.eq(n));i.splice(r+1)}return i.forEach((n,r,a)=>{let h,c;r===0?(c=a[1],h=e?n:a[a.length-1]):r===a.length-1?(h=a[r-1],c=e?n:a[0]):(h=a[r-1],c=a[r+1]),e&&a.length===1?s.push(...new A0(n,n,t).project()):!e||r!==0&&r!==a.length-1?s.push(...new xo(n,h,c,t).project()):s.push(...new A0(n,r===0?c:h,t).project())}),s},og=o=>{const t={};return Object.keys(o).forEach(e=>{t[e]={},Object.keys(o[e]).forEach(s=>{t[e][s]=T({},o[e][s])})}),t},E0=o=>o.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&apos;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),ku=o=>{const t=[];for(let e,s=0;s<o.length;s++)(e=gw(o,s))!==!1&&t.push(e);return t},gw=(o,t)=>{const e=o.charCodeAt(t);if(isNaN(e))return"";if(e<55296||e>57343)return o.charAt(t);if(55296<=e&&e<=56319){if(o.length<=t+1)throw"High surrogate without following low surrogate";const i=o.charCodeAt(t+1);if(56320>i||i>57343)throw"High surrogate without following low surrogate";return o.charAt(t)+o.charAt(t+1)}if(t===0)throw"Low surrogate without preceding high surrogate";const s=o.charCodeAt(t-1);if(55296>s||s>56319)throw"Low surrogate without preceding high surrogate";return!1};var pw=Object.freeze({__proto__:null,capitalize:function(o){let t=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return"".concat(o.charAt(0).toUpperCase()).concat(t?o.slice(1):o.slice(1).toLowerCase())},escapeXml:E0,graphemeSplit:ku});const Pu=function(o,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];return o.fill!==t.fill||o.stroke!==t.stroke||o.strokeWidth!==t.strokeWidth||o.fontSize!==t.fontSize||o.fontFamily!==t.fontFamily||o.fontWeight!==t.fontWeight||o.fontStyle!==t.fontStyle||o.textBackgroundColor!==t.textBackgroundColor||o.deltaY!==t.deltaY||e&&(o.overline!==t.overline||o.underline!==t.underline||o.linethrough!==t.linethrough)},k0=(o,t)=>{const e=t.split(`
67
- `),s=[];let i=-1,n={};o=og(o);for(let r=0;r<e.length;r++){const a=ku(e[r]);if(o[r])for(let h=0;h<a.length;h++){i++;const c=o[r][h];c&&Object.keys(c).length>0&&(Pu(n,c,!0)?s.push({start:i,end:i+1,style:c}):s[s.length-1].end++),n=c||{}}else i+=a.length,n={}}return s},P0=(o,t)=>{if(!Array.isArray(o))return og(o);const e=t.split(Rf),s={};let i=-1,n=0;for(let r=0;r<e.length;r++){const a=ku(e[r]);for(let h=0;h<a.length;h++)i++,o[n]&&o[n].start<=i&&i<o[n].end&&(s[r]=s[r]||{},s[r][h]=T({},o[n].style),i===o[n].end-1&&n++)}return s},Xn=["display","transform",ee,"fill-opacity","fill-rule","opacity",We,"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 M0(o,t){const e=o.nodeName,s=o.getAttribute("class"),i=o.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 a=s.split(" ");for(let h=a.length;h--;)r=new RegExp("\\."+a[h]+n,"i"),t=t.replace(r,"")}return t.length===0}function mw(o,t){let e=!0;const s=M0(o,t.pop());return s&&t.length&&(e=function(i,n){let r,a=!0;for(;i.parentElement&&i.parentElement.nodeType===1&&n.length;)a&&(r=n.pop()),a=M0(i=i.parentElement,r);return n.length===0}(o,t)),s&&e&&t.length===0}const vw=o=>{var t;return(t=L_[o])!==null&&t!==void 0?t:o},bw=new RegExp("(".concat(ti,")"),"gi"),yw=o=>o.replace(bw," $1 ").replace(/,/gi," ").replace(/\s+/gi," ");var O0,D0,R0,F0,L0,I0,j0;const Xe="(".concat(ti,")"),_w=String.raw(O0||(O0=zn(["(skewX)(",")"],["(skewX)\\(","\\)"])),Xe),ww=String.raw(D0||(D0=zn(["(skewY)(",")"],["(skewY)\\(","\\)"])),Xe),xw=String.raw(R0||(R0=zn(["(rotate)(","(?: "," ",")?)"],["(rotate)\\(","(?: "," ",")?\\)"])),Xe,Xe,Xe),Sw=String.raw(F0||(F0=zn(["(scale)(","(?: ",")?)"],["(scale)\\(","(?: ",")?\\)"])),Xe,Xe),Cw=String.raw(L0||(L0=zn(["(translate)(","(?: ",")?)"],["(translate)\\(","(?: ",")?\\)"])),Xe,Xe),Aw=String.raw(I0||(I0=zn(["(matrix)("," "," "," "," "," ",")"],["(matrix)\\("," "," "," "," "," ","\\)"])),Xe,Xe,Xe,Xe,Xe,Xe),hg="(?:".concat(Aw,"|").concat(Cw,"|").concat(xw,"|").concat(Sw,"|").concat(_w,"|").concat(ww,")"),Tw="(?:".concat(hg,"*)"),Ew=String.raw(j0||(j0=zn(["^s*(?:","?)s*$"],["^\\s*(?:","?)\\s*$"])),Tw),kw=new RegExp(Ew),Pw=new RegExp(hg),Mw=new RegExp(hg,"g");function Mu(o){const t=[];if(!(o=yw(o).replace(/\s*([()])\s*/gi,"$1"))||o&&!kw.test(o))return[...He];for(const e of o.matchAll(Mw)){const s=Pw.exec(e[0]);if(!s)continue;let i=He;const n=s.filter(p=>!!p),[,r,...a]=n,[h,c,u,d,f,g]=a.map(p=>parseFloat(p));switch(r){case"translate":i=go(h,c);break;case Ff:i=Ir({angle:h},{x:c,y:u});break;case cu:i=pu(h,c);break;case co:i=Bf(h);break;case uo:i=Hf(h);break;case"matrix":i=[h,c,u,d,f,g]}t.push(i)}return gu(t)}function Ow(o,t,e,s){const i=Array.isArray(t);let n,r=t;if(o!==ee&&o!==We||t!==ze){if(o==="strokeUniform")return t==="non-scaling-stroke";if(o==="strokeDashArray")r=t===ze?null:t.replace(/,/g," ").split(/\s+/).map(parseFloat);else if(o==="transformMatrix")r=e&&e.transformMatrix?qt(e.transformMatrix,Mu(t)):Mu(t);else if(o==="visible")r=t!==ze&&t!=="hidden",e&&e.visible===!1&&(r=!1);else if(o==="opacity")r=parseFloat(t),e&&e.opacity!==void 0&&(r*=e.opacity);else if(o==="textAnchor")r=t==="start"?wt:t==="end"?$t:rt;else if(o==="charSpacing")n=Ge(t,s)/s*1e3;else if(o==="paintFirst"){const a=t.indexOf(ee),h=t.indexOf(We);r=ee,(a>-1&&h>-1&&h<a||a===-1&&h>-1)&&(r=We)}else{if(o==="href"||o==="xlink:href"||o==="font"||o==="id")return t;if(o==="imageSmoothing")return t==="optimizeQuality";n=i?t.map(Ge):Ge(t,s)}}else r="";return!i&&isNaN(n)?r:n}function Dw(o,t){const e=o.match(F_);if(!e)return;const s=e[1],i=e[3],n=e[4],r=e[5],a=e[6];s&&(t.fontStyle=s),i&&(t.fontWeight=isNaN(parseFloat(i))?i:parseFloat(i)),n&&(t.fontSize=Ge(n)),a&&(t.fontFamily=a),r&&(t.lineHeight=r==="normal"?1:r)}function lg(o,t){o.replace(/;\s*$/,"").split(";").forEach(e=>{if(!e)return;const[s,i]=e.split(":");t[s.trim().toLowerCase()]=i.trim()})}function Rw(o){const t={},e=o.getAttribute("style");return e&&(typeof e=="string"?lg(e,t):function(s,i){Object.entries(s).forEach(n=>{let[r,a]=n;a!==void 0&&(i[r.toLowerCase()]=a)})}(e,t)),t}const Fw={stroke:"strokeOpacity",fill:"fillOpacity"};function Zi(o,t,e){if(!o)return{};let s,i={},n=Of;o.parentNode&&n0.test(o.parentNode.nodeName)&&(i=Zi(o.parentElement,t,e),i.fontSize&&(s=n=Ge(i.fontSize)));const r=T(T(T({},t.reduce((c,u)=>{const d=o.getAttribute(u);return d&&(c[u]=d),c},{})),function(c){let u=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},d={};for(const f in u)mw(c,f.split(" "))&&(d=T(T({},d),u[f]));return d}(o,e)),Rw(o));r[Kf]&&o.setAttribute(Kf,r[Kf]),r[qf]&&(s=Ge(r[qf],n),r[qf]="".concat(s));const a={};for(const c in r){const u=vw(c),d=Ow(u,r[c],i,s);a[u]=d}a&&a.font&&Dw(a.font,a);const h=T(T({},i),a);return n0.test(o.nodeName)?h:function(c){const u=ke.getDefaults();return Object.entries(Fw).forEach(d=>{let[f,g]=d;if(c[g]===void 0||c[f]==="")return;if(c[f]===void 0){if(!u[f])return;c[f]=u[f]}if(c[f].indexOf("url(")===0)return;const p=new St(c[f]);c[f]=p.setAlpha(Dt(p.getAlpha()*c[g],2)).toRgba()}),c}(h)}const Lw=["left","top","width","height","visible"],N0=["rx","ry"];class Ai extends ke{static getDefaults(){return T(T({},super.getDefaults()),Ai.ownDefaults)}constructor(t){super(),Object.assign(this,Ai.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,a=this.ry?Math.min(this.ry,s/2):0,h=r!==0||a!==0;t.beginPath(),t.moveTo(i+r,n),t.lineTo(i+e-r,n),h&&t.bezierCurveTo(i+e-Wn*r,n,i+e,n+Wn*a,i+e,n+a),t.lineTo(i+e,n+s-a),h&&t.bezierCurveTo(i+e,n+s-Wn*a,i+e-Wn*r,n+s,i+e-r,n+s),t.lineTo(i+r,n+s),h&&t.bezierCurveTo(i+Wn*r,n+s,i,n+s-Wn*a,i,n+s-a),t.lineTo(i,n+a),h&&t.bezierCurveTo(i,n+Wn*a,i+Wn*r,n,i+r,n),t.closePath(),this._renderPaintInOrder(t)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...N0,...t])}_toSVG(){const{width:t,height:e,rx:s,ry:i}=this;return["<rect ","COMMON_PARTS",'x="'.concat(-t/2,'" y="').concat(-e/2,'" rx="').concat(s,'" ry="').concat(i,'" width="').concat(t,'" height="').concat(e,`" />
68
- `)]}static async fromElement(t,e,s){const i=Zi(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,width:a=0,height:h=0,visible:c=!0}=i,u=Lt(i,Lw);return new this(T(T(T({},e),u),{},{left:n,top:r,width:a,height:h,visible:!!(c&&a&&h)}))}}E(Ai,"type","Rect"),E(Ai,"cacheProperties",[...Ji,...N0]),E(Ai,"ownDefaults",{rx:0,ry:0}),E(Ai,"ATTRIBUTE_NAMES",[...Xn,"x","y","rx","ry","width","height"]),W.setClass(Ai),W.setSVGClass(Ai);const tn="initialization",Ou="added",cg="removed",Du="imperative",B0=(o,t)=>{const{strokeUniform:e,strokeWidth:s,width:i,height:n,group:r}=t,a=r&&r!==o?Qh(r.calcTransformMatrix(),o.calcTransformMatrix()):null,h=a?t.getRelativeCenterPoint().transform(a):t.getRelativeCenterPoint(),c=!t.isStrokeAccountedForInDimensions(),u=e&&c?Um(new M(s,s),void 0,o.calcTransformMatrix()):If,d=!e&&c?s:0,f=vu(i+d,n+d,gu([a,t.calcOwnMatrix()],!0)).add(u).scalarDivide(2);return[h.subtract(f),h.add(f)]};class Ru{calcLayoutResult(t,e){if(this.shouldPerformLayout(t))return this.calcBoundingBox(e,t)}shouldPerformLayout(t){let{type:e,prevStrategy:s,strategy:i}=t;return e===tn||e===Du||!!s&&i!==s}shouldLayoutClipPath(t){let{type:e,target:{clipPath:s}}=t;return e!==tn&&s&&!s.absolutePositioned}getInitialSize(t,e){return e.size}calcBoundingBox(t,e){const{type:s,target:i}=e;if(s===Du&&e.overrides)return e.overrides;if(t.length===0)return;const{left:n,top:r,width:a,height:h}=Ci(t.map(d=>B0(i,d)).reduce((d,f)=>d.concat(f),[])),c=new M(a,h),u=new M(n,r).add(c.scalarDivide(2));if(s===tn){const d=this.getInitialSize(e,{size:c,center:u});return{center:u,relativeCorrection:new M(0,0),size:d}}return{center:u.transform(i.calcOwnMatrix()),size:c}}}E(Ru,"type","strategy");class ug extends Ru{shouldPerformLayout(t){return!0}}E(ug,"type","fit-content"),W.setClass(ug);const Iw=["strategy"],jw=["target","strategy","bubbles","prevStrategy"],H0="layoutManager";class sl{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:new ug;E(this,"strategy",void 0),this.strategy=t,this._subscriptions=new Map}performLayout(t){const e=T(T({bubbles:!0,strategy:this.strategy},t),{},{prevStrategy:this._prevLayoutStrategy,stopPropagation(){this.bubbles=!1}});this.onBeforeLayout(e);const s=this.getLayoutResult(e);s&&this.commitLayout(e,s),this.onAfterLayout(e,s),this._prevLayoutStrategy=e.strategy}attachHandlers(t,e){const{target:s}=e;return[uu,Cm,Uh,Am,hu,Tm,lu,A_,T_].map(i=>t.on(i,n=>this.performLayout(i===uu?{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===tn||s===Ou?this.subscribeTargets(t):s===cg&&this.unsubscribeTargets(t),e.fire("layout:before",{context:t}),i&&i.fire("object:layout:before",{target:e,context:t}),s===Du&&t.deep){const n=Lt(t,Iw);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===tn?new M:e.getRelativeCenterPoint(),{center:a,correction:h=new M,relativeCorrection:c=new M}=n,u=r.subtract(a).add(h).transform(i===tn?He:ns(e.calcOwnMatrix()),!0).add(c);return{result:n,prevCenter:r,nextCenter:a,offset:u}}commitLayout(t,e){const{target:s}=t,{result:{size:i},nextCenter:n}=e;var r,a;s.set({width:i.x,height:i.y}),this.layoutObjects(t,e),t.type===tn?s.set({left:(r=t.x)!==null&&r!==void 0?r:n.x+i.x*se(s.originX),top:(a=t.y)!==null&&a!==void 0?a:n.y+i.y*se(s.originY)}):(s.setPositionByOrigin(n,rt,rt),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,a=Lt(t,jw),{canvas:h}=s;s.fire("layout:after",{context:t,result:e}),h&&h.fire("object:layout:after",{context:t,result:e,target:s});const c=s.parent;n&&c!=null&&c.layoutManager&&((a.path||(a.path=[])).push(s),c.layoutManager.performLayout(T(T({},a),{},{target:c}))),s.set("dirty",!0)}dispose(){const{_subscriptions:t}=this;t.forEach(e=>e.forEach(s=>s())),t.clear()}toObject(){return{type:H0,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}W.setClass(sl,H0);const Nw=["type","objects","layoutManager"];class Bw extends sl{performLayout(){}}class Ls extends Em(ke){static getDefaults(){return T(T({},super.getDefaults()),Ls.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),E(this,"_activeObjects",[]),E(this,"__objectSelectionTracker",void 0),E(this,"__objectSelectionDisposer",void 0),Object.assign(this,Ls.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 sl,this.layoutManager.performLayout({type:tn,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?($i("error","Group: circular object trees are not supported, this call has no effect"),!1):this._objects.indexOf(t)===-1||($i("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(Ou,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(Ou,n),r}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange(cg,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&&vo(t,qt(ns(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||(vo(t,qt(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=ke.prototype.shouldCache.call(this);if(t){for(let e=0;e<this._objects.length;e++)if(this._objects[e].willDrawShadow())return this.ownCaching=!1,!1}return t}willDrawShadow(){if(super.willDrawShadow())return!0;for(let t=0;t<this._objects.length;t++)if(this._objects[t].willDrawShadow())return!0;return!1}isOnACache(){return this.ownCaching||!!this.parent&&this.parent.isOnACache()}drawObject(t,e,s){this._renderBackground(t);for(let n=0;n<this._objects.length;n++){var i;const r=this._objects[n];(i=this.canvas)!==null&&i!==void 0&&i.preserveObjectStacking&&r.group!==this?(t.save(),t.transform(...ns(this.calcTransformMatrix())),r.render(t),t.restore()):r.group===this&&r.render(t)}this._drawClipPath(t,this.clipPath,s)}setCoords(){super.setCoords(),this._shouldSetNestedCoords()&&this.forEachObject(t=>t.setCoords())}triggerLayout(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.layoutManager.performLayout(T({target:this,type:Du},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=Ai.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",` >
66
+ `)}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=Qi.ownDefaults;return this.includeDefaultValues?t:Gf(t,(s,i)=>s!==e[i])}static async fromObject(t){return new this(t)}}k(Qi,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),k(Qi,"type","shadow"),G.setClass(Qi,"shadow");const zr=(a,t,e)=>Math.max(a,Math.min(t,e)),$_=[is,wt,Ve,gs,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",da,fa],Zi=[ee,Ge,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],q_={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:wt,originY:is,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:ee,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},ig=(a,t,e,s)=>(a<Math.abs(t)?(a=t,s=e/4):s=t===0&&a===0?e/Ji*Math.asin(1):e/Ji*Math.asin(t/a),{a,c:t,p:e,s}),wv=(a,t,e,s,i)=>a*Math.pow(2,10*(s-=1))*Math.sin((s*i-t)*Ji/e),xv=(a,t,e,s)=>-e*Math.cos(a/s*Vn)+e+t,ng=(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,Sv=(a,t,e,s)=>e-ng(s-a,0,e,s)+t;var K_=Object.freeze({__proto__:null,defaultEasing:xv,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:Sv,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}=ig(i,e,n,1.70158);return-wv(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*Sv(2*a,0,e,s)+t:.5*ng(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}=ig(i,e,n,1.70158);return a<1?-.5*wv(r,o,h,a,s)+t:r*Math.pow(2,-10*(a-=1))*Math.sin((a*s-o)*Ji/h)*.5+c+t},easeInOutExpo:(a,t,e,s)=>a===0?t:a===s?t+e:(a/=s/2)<1?e/2*2**(10*(a-1))+t:e/2*-(2**(-10*--a)+2)+t,easeInOutQuad:(a,t,e,s)=>(a/=s/2)<1?e/2*a**2+t:-e/2*(--a*(a-2)-1)+t,easeInOutQuart:(a,t,e,s)=>(a/=s/2)<1?e/2*a**4+t:-e/2*((a-=2)*a**3-2)+t,easeInOutQuint:(a,t,e,s)=>(a/=s/2)<1?e/2*a**5+t:e/2*((a-2)**5+2)+t,easeInOutSine:(a,t,e,s)=>-e/2*(Math.cos(Math.PI*a/s)-1)+t,easeInQuad:(a,t,e,s)=>e*(a/=s)*a+t,easeInQuart:(a,t,e,s)=>e*(a/=s)*a**3+t,easeInQuint:(a,t,e,s)=>e*(a/s)**5+t,easeInSine:(a,t,e,s)=>-e*Math.cos(a/s*Vn)+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:ng,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}=ig(i,e,n,1.70158);return r*2**(-10*a)*Math.sin((a*s-o)*Ji/h)+c+t},easeOutExpo:(a,t,e,s)=>a===s?t+e:e*-(2**(-10*a/s)+1)+t,easeOutQuad:(a,t,e,s)=>-e*(a/=s)*(a-2)+t,easeOutQuart:(a,t,e,s)=>-e*((a=a/s-1)*a**3-1)+t,easeOutQuint:(a,t,e,s)=>e*((a/s-1)**5+1)+t,easeOutSine:(a,t,e,s)=>e*Math.sin(a/s*Vn)+t});const J_=()=>!1;class rg{constructor(t){let{startValue:e,byValue:s,duration:i=500,delay:n=0,easing:r=xv,onStart:o=Rr,onChange:h=Rr,onComplete:c=Rr,abort:u=J_,target:d}=t;k(this,"_state","pending"),k(this,"durationProgress",0),k(this,"valueProgress",0),this.tick=this.tick.bind(this),this.duration=i,this.delay=n,this.easing=r,this._onStart=o,this._onChange=h,this._onComplete=c,this._abort=u,this.target=d,this.startValue=e,this.byValue=s,this.value=this.startValue,this.endValue=Object.freeze(this.calculate(this.duration).value)}get state(){return this._state}isDone(){return this._state==="aborted"||this._state==="completed"}start(){const t=e=>{this._state==="pending"&&(this.startTime=e||+new Date,this._state="running",this._onStart(),this.tick(this.startTime))};this.register(),this.delay>0?setTimeout(()=>qh(t),this.delay):qh(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),qh(this.tick)))}register(){gu.push(this)}unregister(){gu.remove(this)}abort(){this._state="aborted",this.unregister()}}const Q_=["startValue","endValue"];class Z_ extends rg{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(E(E({},Lt(t,Q_)),{},{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 tw=["startValue","endValue"];class ew extends rg{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(E(E({},Lt(t,tw)),{},{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 sw=["startValue","endValue","easing","onChange","onComplete","abort"],iw=(a,t,e,s)=>t+e*(1-Math.cos(a/s*Vn)),og=a=>a&&((t,e,s)=>a(new St(t).toRgba(),e,s));class nw extends rg{constructor(t){let{startValue:e,endValue:s,easing:i=iw,onChange:n,onComplete:r,abort:o}=t,h=Lt(t,sw);const c=new St(e).getSource(),u=new St(s).getSource();super(E(E({},h),{},{startValue:c,byValue:u.map((d,f)=>d-c[f]),easing:i,onChange:og(n),onComplete:og(r),abort:og(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),zr(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 ag(a){const t=(e=>Array.isArray(e.startValue)||Array.isArray(e.endValue))(a)?new ew(a):new Z_(a);return t.start(),t}function Cv(a){const t=new nw(a);return t.start(),t}class zt{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=Cu(e,s),r=Cu(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 O(t).setX(Math.min(t.x-1,...e.map(n=>n.x)));let i=0;for(let n=0;n<e.length;n++){const r=this.intersectSegmentSegment(e[n],e[(n+1)%e.length],t,s);if(r.includes(t))return!0;i+=+(r.status==="Intersection")}return i%2==1}static intersectLineLine(t,e,s,i){let n=!(arguments.length>4&&arguments[4]!==void 0)||arguments[4],r=!(arguments.length>5&&arguments[5]!==void 0)||arguments[5];const o=e.x-t.x,h=e.y-t.y,c=i.x-s.x,u=i.y-s.y,d=t.x-s.x,f=t.y-s.y,g=c*f-u*d,p=o*f-h*d,m=u*o-c*h;if(m!==0){const y=g/m,b=p/m;return(n||0<=y&&y<=1)&&(r||0<=b&&b<=1)?new zt("Intersection").append(new O(t.x+y*o,t.y+y*h)):new zt}if(g===0||p===0){const y=n||r||zt.isPointContained(t,s,i)||zt.isPointContained(e,s,i)||zt.isPointContained(s,t,e)||zt.isPointContained(i,t,e);return new zt(y?"Coincident":void 0)}return new zt("Parallel")}static intersectSegmentLine(t,e,s,i){return zt.intersectLineLine(t,e,s,i,!1,!0)}static intersectSegmentSegment(t,e,s,i){return zt.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 zt,r=s.length;for(let o,h,c,u=0;u<r;u++){if(o=s[u],h=s[(u+1)%r],c=zt.intersectLineLine(t,e,o,h,i,!1),c.status==="Coincident")return c;n.append(...c.points)}return n.points.length>0&&(n.status="Intersection"),n}static intersectSegmentPolygon(t,e,s){return zt.intersectLinePolygon(t,e,s,!1)}static intersectPolygonPolygon(t,e){const s=new zt,i=t.length,n=[];for(let r=0;r<i;r++){const o=t[r],h=t[(r+1)%i],c=zt.intersectSegmentPolygon(o,h,e);c.status==="Coincident"?(n.push(c),s.append(o,h)):s.append(...c.points)}return n.length>0&&n.length===t.length?new zt("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 O(n.x,i.y),o=new O(i.x,n.y);return zt.intersectPolygonPolygon(t,[i,r,n,o])}}class rw extends Dm{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?Ee(t,this.group.calcTransformMatrix()):t}setXY(t,e,s){this.group&&(t=Ee(t,ns(this.group.calcTransformMatrix()))),this.setRelativeXY(t,e,s)}getRelativeXY(){return new O(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=>Ee(o,r))}return n}intersectsWithRect(t,e){return zt.intersectPolygonRectangle(this.getCoords(),t,e).status==="Intersection"}intersectsWithObject(t){const e=zt.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 zt.isPointInPolygon(t,this.getCoords())}isOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return!!this.getCoords().some(s=>s.x<=e.x&&s.x>=t.x&&s.y<=e.y&&s.y>=t.y)||!!this.intersectsWithRect(t,e)||this.containsPoint(t.midPointFrom(e))}isPartiallyOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return this.intersectsWithRect(t,e)?!0:this.getCoords().every(s=>(s.x>=e.x||s.x<=t.x)&&(s.y>=e.y||s.y<=t.y))&&this.containsPoint(t.midPointFrom(e))}getBoundingRect(){return Ai(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(Ve,t),this._set(gs,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?Ci(Im(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.viewportTransform)||He.concat()}calcACoords(){const t=Ir({angle:this.angle}),{x:e,y:s}=this.getRelativeCenterPoint(),i=pa(e,s),n=qt(i,t),r=this._getTransformedDimensions(),o=r.x/2,h=r.y/2;return{tl:Ee({x:-o,y:-h},n),tr:Ee({x:o,y:-h},n),bl:Ee({x:-o,y:h},n),br:Ee({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,se(this.originX),se(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=qt(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=Nm(i);return this.ownMatrixCache={key:t,value:n},n}_getNonTransformedDimensions(){return new O(this.width,this.height).scalarAdd(this.strokeWidth)}_calculateCurrentDimensions(t){return this._getTransformedDimensions(t).transform(this.getViewportTransform(),!0).scalarAdd(2*this.padding)}_getTransformedDimensions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=E({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,width:this.width,height:this.height,strokeWidth:this.strokeWidth},t),s=e.strokeWidth;let i=s,n=0;this.strokeUniform&&(i=0,n=s);const r=e.width+i,o=e.height+i;let h;return h=e.skewX===0&&e.skewY===0?new O(r*e.scaleX,o*e.scaleY):yu(r,o,Kh(e)),h.scalarAdd(n)}translateToGivenOrigin(t,e,s,i,n){let r=t.x,o=t.y;const h=se(i)-se(e),c=se(n)-se(s);if(h||c){const u=this._getTransformedDimensions();r+=h*u.x,o+=c*u.y}return new O(r,o)}translateToCenterPoint(t,e,s){if(e===rt&&s===rt)return t;const i=this.translateToGivenOrigin(t,e,s,rt,rt);return this.angle?i.rotate(Ut(this.angle),t):i}translateToOriginPoint(t,e,s){const i=this.translateToGivenOrigin(t,rt,rt,e,s);return this.angle?i.rotate(Ut(this.angle),t):i}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?Ee(t,this.group.calcTransformMatrix()):t}getRelativeCenterPoint(){return this.translateToCenterPoint(new O(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(),wt,is)}}const ow=["type"],aw=["extraParam"];let tn=class Zd extends rw{static getDefaults(){return Zd.ownDefaults}get type(){const t=this.constructor.type;return t==="FabricObject"?"object":t.toLowerCase()}set type(t){Ki("warn","Setting type has no effect",t)}constructor(t){super(),k(this,"_cacheContext",null),Object.assign(this,Zd.ownDefaults),this.setOptions(t)}_createCacheCanvas(){this._cacheCanvas=Si(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,s=t.height,i=mt.maxCacheSideLimit,n=mt.minCacheSideLimit;if(e<=i&&s<=i&&e*s<=mt.perfLimitSizeTotal)return e<n&&(t.width=n),s<n&&(t.height=n),t;const r=e/s,[o,h]=Yh.limitDimsByArea(r),c=zr(n,o,i),u=zr(n,h,i);return e>c&&(t.zoomX/=e/c,t.width=c,t.capped=!0),s>u&&(t.zoomY/=s/u,t.height=u,t.capped=!0),t}_getCacheCanvasDimensions(){const t=this.getTotalObjectScaling(),e=this._getTransformedDimensions({skewX:0,skewY:0}),s=e.x*t.x/this.scaleX,i=e.y*t.y/this.scaleY;return{width:Math.ceil(s+2),height:Math.ceil(i+2),zoomX:t.x,zoomY:t.y,x:s,y:i}}_updateCacheCanvas(){const t=this._cacheCanvas,e=this._cacheContext,{width:s,height:i,zoomX:n,zoomY:r,x:o,y:h}=this._limitCacheSize(this._getCacheCanvasDimensions()),c=s!==t.width||i!==t.height,u=this.zoomX!==n||this.zoomY!==r;if(!t||!e)return!1;if(c||u){s!==t.width||i!==t.height?(t.width=s,t.height=i):(e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,t.width,t.height));const d=o/2,f=h/2;return this.cacheTranslationX=Math.round(t.width/2-d)+d,this.cacheTranslationY=Math.round(t.height/2-f)+f,e.translate(this.cacheTranslationX,this.cacheTranslationY),e.scale(n,r),this.zoomX=n,this.zoomY=r,!0}return!1}setOptions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this._setOptions(t)}transform(t){const e=this.group&&!this.group._transformDone||this.group&&this.canvas&&t===this.canvas.contextTop,s=this.calcTransformMatrix(!e);t.transform(s[0],s[1],s[2],s[3],s[4],s[5])}getObjectScaling(){if(!this.group)return new O(Math.abs(this.scaleX),Math.abs(this.scaleY));const t=Lr(this.calcTransformMatrix());return new O(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!==Ve&&t!==gs||(e=this._constrainScale(e)),t===Ve&&e<0?(this.flipX=!this.flipX,e*=-1):t==="scaleY"&&e<0?(this.flipY=!this.flipY,e*=-1):t!=="shadow"||!e||e instanceof Qi||(e=new Qi(e));const s=this[t]!==e;return this[t]=e,s&&this.constructor.cacheProperties.includes(t)&&(this.dirty=!0),this.parent&&(this.dirty||s&&this.constructor.stateProperties.includes(t))&&this.parent._set("dirty",!0),this}isNotVisible(){return this.opacity===0||!this.width&&!this.height&&this.strokeWidth===0||!this.visible}render(t){this.isNotVisible()||this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(t.save(),this._setupCompositeOperation(t),this.drawSelectionBackground(t),this.transform(t),this._setOpacity(t),this._setShadow(t),this.shouldCache()?(this.renderCache(),this.drawCacheOnCanvas(t)):(this._removeCacheCanvas(),this.drawObject(t,!1,{}),this.dirty=!1),t.restore())}drawSelectionBackground(t){}renderCache(t){if(t=t||{},this._cacheCanvas&&this._cacheContext||this._createCacheCanvas(),this.isCacheDirty()&&this._cacheContext){const{zoomX:e,zoomY:s,cacheTranslationX:i,cacheTranslationY:n}=this,{width:r,height:o}=this._cacheCanvas;this.drawObject(this._cacheContext,t.forClipping,{zoomX:e,zoomY:s,cacheTranslationX:i,cacheTranslationY:n,width:r,height:o,parentClipPaths:[]}),this.dirty=!1}}_removeCacheCanvas(){this._cacheCanvas=void 0,this._cacheContext=null}hasStroke(){return this.stroke&&this.stroke!=="transparent"&&this.strokeWidth!==0}hasFill(){return this.fill&&this.fill!=="transparent"}needsItsOwnCache(){return!!(this.paintFirst===Ge&&this.hasFill()&&this.hasStroke()&&this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.objectCaching&&(!this.parent||!this.parent.isOnACache())||this.needsItsOwnCache(),this.ownCaching}willDrawShadow(){return!!this.shadow&&(this.shadow.offsetX!==0||this.shadow.offsetY!==0)}drawClipPathOnCache(t,e,s){t.save(),e.inverted?t.globalCompositeOperation="destination-out":t.globalCompositeOperation="destination-in",t.setTransform(1,0,0,1,0,0),t.drawImage(s,0,0),t.restore()}drawObject(t,e,s){const i=this.fill,n=this.stroke;e?(this.fill="black",this.stroke="",this._setClippingProperties(t)):this._renderBackground(t),this._render(t),this._drawClipPath(t,this.clipPath,s),this.fill=i,this.stroke=n}createClipPathLayer(t,e){const s=ps(e),i=s.getContext("2d");if(i.translate(e.cacheTranslationX,e.cacheTranslationY),i.scale(e.zoomX,e.zoomY),t._cacheCanvas=s,e.parentClipPaths.forEach(n=>{n.transform(i)}),e.parentClipPaths.push(t),t.absolutePositioned){const n=ns(this.calcTransformMatrix());i.transform(n[0],n[1],n[2],n[3],n[4],n[5])}return t.transform(i),t.drawObject(i,!0,e),s}_drawClipPath(t,e,s){if(!e)return;e._transformDone=!0;const i=this.createClipPathLayer(e,s);this.drawClipPathOnCache(t,e,i)}drawCacheOnCanvas(t){t.scale(1/this.zoomX,1/this.zoomY),t.drawImage(this._cacheCanvas,-this.cacheTranslationX,-this.cacheTranslationY)}isCacheDirty(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0];if(this.isNotVisible())return!1;const e=this._cacheCanvas,s=this._cacheContext;return!(!e||!s||t||!this._updateCacheCanvas())||!!(this.dirty||this.clipPath&&this.clipPath.absolutePositioned)&&(e&&s&&!t&&(s.save(),s.setTransform(1,0,0,1,0,0),s.clearRect(0,0,e.width,e.height),s.restore()),!0)}_renderBackground(t){if(!this.backgroundColor)return;const e=this._getNonTransformedDimensions();t.fillStyle=this.backgroundColor,t.fillRect(-e.x/2,-e.y/2,e.x,e.y),this._removeShadow(t)}_setOpacity(t){this.group&&!this.group._transformDone?t.globalAlpha=this.getObjectOpacity():t.globalAlpha*=this.opacity}_setStrokeStyles(t,e){const s=e.stroke;s&&(t.lineWidth=e.strokeWidth,t.lineCap=e.strokeLineCap,t.lineDashOffset=e.strokeDashOffset,t.lineJoin=e.strokeLineJoin,t.miterLimit=e.strokeMiterLimit,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&&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)||He,o=n*i,h=r*i,c=e.nonScaling?new O(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*mt.browserShadowBlurConstant*(o+h)*(c.x+c.y)/4,t.shadowOffsetX=e.offsetX*o*c.x,t.shadowOffsetY=e.offsetY*h*c.y}_removeShadow(t){this.shadow&&(t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0)}_applyPatternGradientTransform(t,e){if(!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===Ge?(this._renderStroke(t),this._renderFill(t)):(this._renderFill(t),this._renderStroke(t))}_render(t){}_renderFill(t){this.fill&&(t.save(),this._setFillStyles(t,this),this.fillRule==="evenodd"?t.fill("evenodd"):t.fill(),t.restore())}_renderStroke(t){if(this.stroke&&this.strokeWidth!==0){if(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this.strokeUniform){const e=this.getObjectScaling();t.scale(1/e.x,1/e.y)}this._setLineDash(t,this.strokeDashArray),this._setStrokeStyles(t,this),t.stroke(),t.restore()}}_applyPatternForTransformedGradient(t,e){var s;const i=this._limitCacheSize(this._getCacheCanvasDimensions()),n=this.getCanvasRetinaScaling(),r=i.x/this.scaleX/n,o=i.y/this.scaleY/n,h=ps({width:Math.ceil(r),height:Math.ceil(o)}),c=h.getContext("2d");c&&(c.beginPath(),c.moveTo(0,0),c.lineTo(r,0),c.lineTo(r,o),c.lineTo(0,o),c.closePath(),c.translate(r/2,o/2),c.scale(i.zoomX/this.scaleX/n,i.zoomY/this.scaleY/n),this._applyPatternGradientTransform(c,e),c.fillStyle=e.toLive(t),c.fill(),t.translate(-this.width/2-this.strokeWidth/2,-this.height/2-this.strokeWidth/2),t.scale(n*this.scaleX/i.zoomX,n*this.scaleY/i.zoomY),t.strokeStyle=(s=c.createPattern(h,"no-repeat"))!==null&&s!==void 0?s:"")}_findCenterFromElement(){return new O(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(G.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=Xf(this),s=this.group,i=this.shadow,n=Math.abs,r=t.enableRetinaScaling?Em():1,o=(t.multiplier||1)*r,h=t.canvasProvider||(x=>new Zh(x,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&qm(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&Uf(this,this.getViewportTransform()),this.setCoords();const c=Si(),u=this.getBoundingRect(),d=this.shadow,f=new O;if(d){const x=d.blur,C=d.nonScaling?new O(1,1):this.getObjectScaling();f.x=2*Math.round(n(d.offsetX)+x)*n(C.x),f.y=2*Math.round(n(d.offsetY)+x)*n(C.y)}const g=u.width+f.x,p=u.height+f.y;c.width=Math.ceil(g),c.height=Math.ceil(p);const m=h(c);t.format==="jpeg"&&(m.backgroundColor="#fff"),this.setPositionByOrigin(new O(m.width/2,m.height/2),rt,rt);const y=this.canvas;m._objects=[this],this.set("canvas",m),this.setCoords();const b=m.toCanvasElement(o||1,t);return this.set("canvas",y),this.shadow=i,s&&(this.group=s),this.set(e),this.setCoords(),m._objects=[],m.destroy(),b}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return Bf(this.toCanvasElement(t),t.format||"png",t.quality||1)}toBlob(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return Hf(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=rt,this.originY=rt,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(){gu.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&xi().dispose(this._cacheCanvas),this._cacheCanvas=void 0,this._cacheContext=null}animate(t,e){return Object.entries(t).reduce((s,i)=>{let[n,r]=i;return s[n]=this._animate(n,r,e),s},{})}_animate(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const i=t.split("."),n=this.constructor.colorProperties.includes(i[i.length-1]),{abort:r,startValue:o,onChange:h,onComplete:c}=s,u=E(E({},s),{},{target:this,startValue:o??i.reduce((d,f)=>d[f],this),endValue:e,abort:r==null?void 0:r.bind(this),onChange:(d,f,g)=>{i.reduce((p,m,y)=>(y===i.length-1&&(p[m]=d),p[m]),this),h&&h(d,f,g)},onComplete:(d,f,g)=>{this.setCoords(),c&&c(d,f,g)}});return n?Cv(u):ag(u)}isDescendantOf(t){const{parent:e,group:s}=this;return e===t||s===t||!!e&&e.isDescendantOf(t)||!!s&&s!==e&&s.isDescendantOf(t)}getAncestors(){const t=[];let e=this;do e=e.parent,e&&t.push(e);while(e);return t}findCommonAncestors(t){if(this===t)return{fork:[],otherFork:[],common:[this,...this.getAncestors()]};const e=this.getAncestors(),s=t.getAncestors();if(e.length===0&&s.length>0&&this===s[s.length-1])return{fork:[],otherFork:[t,...s.slice(0,s.length-1)],common:[this]};for(let i,n=0;n<e.length;n++){if(i=e[n],i===t)return{fork:[this,...e.slice(0,n)],otherFork:[],common:e.slice(n)};for(let r=0;r<s.length;r++){if(this===s[r])return{fork:[],otherFork:[t,...s.slice(0,r)],common:[this,...e]};if(i===s[r])return{fork:[this,...e.slice(0,n)],otherFork:[t,...s.slice(0,r)],common:e.slice(n)}}}return{fork:[this,...e],otherFork:[t,...s],common:[]}}hasCommonAncestors(t){const e=this.findCommonAncestors(t);return e&&!!e.common.length}isInFrontOf(t){if(this===t)return;const e=this.findCommonAncestors(t);if(e.fork.includes(t))return!0;if(e.otherFork.includes(this))return!1;const s=e.common[0]||this.canvas;if(!s)return;const i=e.fork.pop(),n=e.otherFork.pop(),r=s._objects.indexOf(i),o=s._objects.indexOf(n);return r>-1&&r>o}toObject(){const t=(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).concat(Zd.customProperties,this.constructor.customProperties||[]);let e;const s=mt.NUM_FRACTION_DIGITS,{clipPath:i,fill:n,stroke:r,shadow:o,strokeDashArray:h,left:c,top:u,originX:d,originY:f,width:g,height:p,strokeWidth:m,strokeLineCap:y,strokeDashOffset:b,strokeLineJoin:x,strokeUniform:C,strokeMiterLimit:S,scaleX:T,scaleY:P,angle:M,flipX:D,flipY:R,opacity:V,visible:H,backgroundColor:F,fillRule:I,paintFirst:j,globalCompositeOperation:K,skewX:L,skewY:z}=this;i&&!i.excludeFromExport&&(e=i.toObject(t.concat("inverted","absolutePositioned")));const Z=Bt=>kt(Bt,s),Dt=E(E({},jr(this,t)),{},{type:this.constructor.type,version:Of,originX:d,originY:f,left:Z(c),top:Z(u),width:Z(g),height:Z(p),fill:Bm(n)?n.toObject():n,stroke:Bm(r)?r.toObject():r,strokeWidth:Z(m),strokeDashArray:h&&h.concat(),strokeLineCap:y,strokeDashOffset:b,strokeLineJoin:x,strokeUniform:C,strokeMiterLimit:Z(S),scaleX:Z(T),scaleY:Z(P),angle:Z(M),flipX:D,flipY:R,opacity:Z(V),shadow:o&&o.toObject(),visible:H,backgroundColor:F,fillRule:I,paintFirst:j,globalCompositeOperation:K,skewX:Z(L),skewY:Z(z)},e?{clipPath:e}:null);return this.includeDefaultValues?Dt:this._removeDefaultValues(Dt)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),s=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return Gf(t,(i,n)=>{if(n===wt||n===is||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=Lt(t,ow),s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{extraParam:i}=s,n=Lt(s,aw);return Qh(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)}};k(tn,"stateProperties",$_),k(tn,"cacheProperties",Zi),k(tn,"ownDefaults",q_),k(tn,"type","FabricObject"),k(tn,"colorProperties",[ee,Ge,"backgroundColor"]),k(tn,"customProperties",[]),G.setClass(tn),G.setClass(tn,"object");const _a=(a,t,e)=>(s,i,n,r)=>{const o=t(s,i,n,r);return o&&Jm(a,E(E({},tv(s,i,n,r)),e)),o};function wa(a){return(t,e,s,i)=>{const{target:n,originX:r,originY:o}=e,h=n.getRelativeCenterPoint(),c=n.translateToOriginPoint(h,r,o),u=a(t,e,s,i);return n.setPositionByOrigin(c,e.originX,e.originY),u}}const Av=_a($h,wa((a,t,e,s)=>{const i=Yf(t,t.originX,t.originY,e,s);if(se(t.originX)===se(rt)||se(t.originX)===se($t)&&i.x<0||se(t.originX)===se(wt)&&i.x>0){const{target:n}=t,r=n.strokeWidth/(n.strokeUniform?n.scaleX:1),o=Qm(t)?2:1,h=n.width,c=Math.abs(i.x*o/n.scaleX)-r;return n.set("width",Math.max(c,1)),h!==n.width}return!1}));function hw(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?Ge:ee,c=!o&&(s.cornerStrokeColor||i.cornerStrokeColor);let u,d=t,f=e;a.save(),a.fillStyle=s.cornerColor||i.cornerColor||"",a.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",n>r?(u=n,a.scale(1,r/n),f=e*n/r):r>n?(u=r,a.scale(n/r,1),d=t*r/n):u=n,a.beginPath(),a.arc(d,f,u/2,0,Ji,!1),a[h](),c&&a.stroke(),a.restore()}function lw(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?Ge:ee,c=!o&&(s.cornerStrokeColor||i.cornerStrokeColor),u=n/2,d=r/2;a.save(),a.fillStyle=s.cornerColor||i.cornerColor||"",a.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",a.translate(t,e);const f=i.getTotalAngle();a.rotate(Ut(f)),a["".concat(h,"Rect")](-u,-d,n,r),c&&a.strokeRect(-u,-d,n,r),a.restore()}class ti{constructor(t){k(this,"visible",!0),k(this,"actionName",du),k(this,"angle",0),k(this,"x",0),k(this,"y",0),k(this,"offsetX",0),k(this,"offsetY",0),k(this,"sizeX",0),k(this,"sizeY",0),k(this,"touchSizeX",0),k(this,"touchSizeY",0),k(this,"cursorStyle","crosshair"),k(this,"withConnection",!1),Object.assign(this,t)}shouldActivate(t,e,s,i){var n;let{tl:r,tr:o,br:h,bl:c}=i;return((n=e.canvas)===null||n===void 0?void 0:n.getActiveObject())===e&&e.isControlVisible(t)&&zt.isPointInPolygon(s,[r,o,h,c])}getActionHandler(t,e,s){return this.actionHandler}getMouseDownHandler(t,e,s){return this.mouseDownHandler}getMouseUpHandler(t,e,s){return this.mouseUpHandler}cursorStyleHandler(t,e,s){return e.cursorStyle}getActionName(t,e,s){return e.actionName}getVisibility(t,e){var s,i;return(s=(i=t._controlsVisibility)===null||i===void 0?void 0:i[e])!==null&&s!==void 0?s:this.visible}setVisibility(t,e,s){this.visible=t}positionHandler(t,e,s,i){return new O(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(e)}calcCornerCoords(t,e,s,i,n,r){const o=mu([pa(s,i),Ir({angle:t}),vu((n?this.touchSizeX:this.sizeX)||e,(n?this.touchSizeY:this.sizeY)||e)]);return{tl:new O(-.5,-.5).transform(o),tr:new O(.5,-.5).transform(o),br:new O(.5,.5).transform(o),bl:new O(-.5,.5).transform(o)}}render(t,e,s,i,n){((i=i||{}).cornerStyle||n.cornerStyle)==="circle"?hw.call(this,t,e,s,i,n):lw.call(this,t,e,s,i,n)}}const cw=(a,t,e)=>e.lockRotation?_u:t.cursorStyle,uw=_a(Pm,wa((a,t,e,s)=>{let{target:i,ex:n,ey:r,theta:o,originX:h,originY:c}=t;const u=i.translateToOriginPoint(i.getRelativeCenterPoint(),h,c);if(Qs(i,"lockRotation"))return!1;const d=Math.atan2(r-u.y,n-u.x),f=Math.atan2(s-u.y,e-u.x);let g=Ci(f-d+o);if(i.snapAngle&&i.snapAngle>0){const m=i.snapAngle,y=i.snapThreshold||m,b=Math.ceil(g/m)*m,x=Math.floor(g/m)*m;Math.abs(g-x)<y?g=x:Math.abs(g-b)<y&&(g=b)}g<0&&(g=360+g),g%=360;const p=i.angle!==g;return i.angle=g,p}));function Tv(a,t){const e=t.canvas,s=a[e.uniScaleKey];return e.uniformScaling&&!s||!e.uniformScaling&&s}function Ev(a,t,e){const s=Qs(a,"lockScalingX"),i=Qs(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 dw=["e","se","s","sw","w","nw","n","ne","e"],nl=(a,t,e)=>{const s=Tv(a,e);if(Ev(e,t.x!==0&&t.y===0?"x":t.x===0&&t.y!==0?"y":"",s))return _u;const i=ev(e,t);return"".concat(dw[i],"-resize")};function hg(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{};const n=t.target,r=i.by,o=Tv(a,n);let h,c,u,d,f,g;if(Ev(n,r,o))return!1;if(t.gestureScale)c=t.scaleX*t.gestureScale,u=t.scaleY*t.gestureScale;else{if(h=Yf(t,t.originX,t.originY,e,s),f=r!=="y"?Math.sign(h.x||t.signX||1):1,g=r!=="x"?Math.sign(h.y||t.signY||1):1,t.signX||(t.signX=f),t.signY||(t.signY=g),Qs(n,"lockScalingFlip")&&(t.signX!==f||t.signY!==g))return!1;if(d=n._getTransformedDimensions(),o&&!r){const y=Math.abs(h.x)+Math.abs(h.y),{original:b}=t,x=y/(Math.abs(d.x*b.scaleX/n.scaleX)+Math.abs(d.y*b.scaleY/n.scaleY));c=b.scaleX*x,u=b.scaleY*x}else c=Math.abs(h.x*n.scaleX/d.x),u=Math.abs(h.y*n.scaleY/d.y);Qm(t)&&(c*=2,u*=2),t.signX!==f&&r!=="y"&&(t.originX=Zm(t.originX),c*=-1,t.signX=f),t.signY!==g&&r!=="x"&&(t.originY=Zm(t.originY),u*=-1,t.signY=g)}const p=n.scaleX,m=n.scaleY;return r?(r==="x"&&n.set(Ve,c),r==="y"&&n.set(gs,u)):(!Qs(n,"lockScalingX")&&n.set(Ve,c),!Qs(n,"lockScalingY")&&n.set(gs,u)),p!==n.scaleX||m!==n.scaleY}const ku=_a(cu,wa((a,t,e,s)=>hg(a,t,e,s))),fw=_a(cu,wa((a,t,e,s)=>hg(a,t,e,s,{by:"x"}))),gw=_a(cu,wa((a,t,e,s)=>hg(a,t,e,s,{by:"y"}))),pw=["target","ex","ey","skewingSide"],lg={x:{counterAxis:"y",scale:Ve,skew:da,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:gs,skew:fa,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},mw=["ns","nesw","ew","nwse"],vw=(a,t,e)=>{if(t.x!==0&&Qs(e,"lockSkewingY")||t.y!==0&&Qs(e,"lockSkewingX"))return _u;const s=ev(e,t)%4;return"".concat(mw[s],"-resize")};function kv(a,t,e,s,i){const{target:n}=e,{counterAxis:r,origin:o,lockSkewing:h,skew:c,flip:u}=lg[a];if(Qs(n,h))return!1;const{origin:d,flip:f}=lg[r],g=se(e[d])*(n[f]?-1:1),p=-Math.sign(g)*(n[u]?-1:1),m=.5*-((n[c]===0&&Yf(e,rt,rt,s,i)[a]>0||n[c]>0?1:-1)*p)+.5;return _a(Mm,wa((b,x,C,S)=>function(T,P,M){let{target:D,ex:R,ey:V,skewingSide:H}=P,F=Lt(P,pw);const{skew:I}=lg[T],j=M.subtract(new O(R,V)).divide(new O(D.scaleX,D.scaleY))[T],K=D[I],L=F[I],z=Math.tan(Ut(L)),Z=T==="y"?D._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:D._getTransformedDimensions({scaleX:1,scaleY:1}).y,Dt=2*j*H/Math.max(Z,1)+z,Bt=Ci(Math.atan(Dt));D.set(I,Bt);const Xt=K!==D[I];if(Xt&&T==="y"){const{skewX:Ft,scaleX:_t}=D,oe=D._getTransformedDimensions({skewY:K}),Ze=D._getTransformedDimensions(),it=Ft!==0?oe.x/Ze.x:1;it!==1&&D.set(Ve,it*_t)}return Xt}(a,x,new O(C,S))))(t,E(E({},e),{},{[o]:m,skewingSide:p}),s,i)}const bw=(a,t,e,s)=>kv("x",a,t,e,s),yw=(a,t,e,s)=>kv("y",a,t,e,s);function Pu(a,t){return a[t.canvas.altActionKey]}const Mu=(a,t,e)=>{const s=Pu(a,e);return t.x===0?s?da:gs:t.y===0?s?fa:Ve:""},xa=(a,t,e)=>Pu(a,e)?vw(0,t,e):nl(a,t,e),Pv=(a,t,e,s)=>Pu(a,t.target)?yw(a,t,e,s):fw(a,t,e,s),Mv=(a,t,e,s)=>Pu(a,t.target)?bw(a,t,e,s):gw(a,t,e,s),Ov=()=>({ml:new ti({x:-.5,y:0,cursorStyleHandler:xa,actionHandler:Pv,getActionName:Mu}),mr:new ti({x:.5,y:0,cursorStyleHandler:xa,actionHandler:Pv,getActionName:Mu}),mb:new ti({x:0,y:.5,cursorStyleHandler:xa,actionHandler:Mv,getActionName:Mu}),mt:new ti({x:0,y:-.5,cursorStyleHandler:xa,actionHandler:Mv,getActionName:Mu}),tl:new ti({x:-.5,y:-.5,cursorStyleHandler:nl,actionHandler:ku}),tr:new ti({x:.5,y:-.5,cursorStyleHandler:nl,actionHandler:ku}),bl:new ti({x:-.5,y:.5,cursorStyleHandler:nl,actionHandler:ku}),br:new ti({x:.5,y:.5,cursorStyleHandler:nl,actionHandler:ku}),mtr:new ti({x:0,y:-.5,actionHandler:uw,cursorStyleHandler:cw,offsetY:-40,withConnection:!0,actionName:If})}),_w=()=>({mr:new ti({x:.5,y:0,actionHandler:Av,cursorStyleHandler:xa,actionName:$h}),ml:new ti({x:-.5,y:0,actionHandler:Av,cursorStyleHandler:xa,actionName:$h})}),ww=()=>E(E({},Ov()),_w());class rl extends tn{static getDefaults(){return E(E({},super.getDefaults()),rl.ownDefaults)}constructor(t){super(),Object.assign(this,this.constructor.createControls(),rl.ownDefaults),this.setOptions(t)}static createControls(){return{controls:Ov()}}_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(du))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=pa(e.x,e.y),i=Ir({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),n=qt(s,i),r=qt(t,n),o=qt(r,[1/t[0],0,0,1/t[3],0,0]),h=this.group?Lr(this.calcTransformMatrix()):void 0;h&&(h.scaleX=Math.abs(h.scaleX),h.scaleY=Math.abs(h.scaleY));const c=this._calculateCurrentDimensions(h),u={};return this.forEachControl((d,f)=>{const g=d.positionHandler(c,o,this,d);u[f]=Object.assign(g,this._calcCornerCoords(d,g))}),u}_calcCornerCoords(t,e){const s=this.getTotalAngle();return{corner:t.calcCornerCoords(s,this.cornerSize,e.x,e.y,!1,this),touchCorner:t.calcCornerCoords(s,this.touchCornerSize,e.x,e.y,!0,this)}}setCoords(){super.setCoords(),this.canvas&&(this.oCoords=this.calcOCoords())}forEachControl(t){for(const e in this.controls)t(this.controls[e],e,this)}drawSelectionBackground(t){if(!this.selectionBackgroundColor||this.canvas&&this.canvas._activeObject!==this)return;t.save();const e=this.getRelativeCenterPoint(),s=this._calculateCurrentDimensions(),i=this.getViewportTransform();t.translate(e.x,e.y),t.scale(1/i[0],1/i[3]),t.rotate(Ut(this.angle)),t.fillStyle=this.selectionBackgroundColor,t.fillRect(-s.x/2,-s.y/2,s.x,s.y),t.restore()}strokeBorders(t,e){t.strokeRect(-e.x/2,-e.y/2,e.x,e.y)}_drawBorders(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const i=E({hasControls:this.hasControls,borderColor:this.borderColor,borderDashArray:this.borderDashArray},s);t.save(),t.strokeStyle=i.borderColor,this._setLineDash(t,i.borderDashArray),this.strokeBorders(t,e),i.hasControls&&this.drawControlsConnectingLines(t,e),t.restore()}_renderControls(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const{hasBorders:s,hasControls:i}=this,n=E({hasBorders:s,hasControls:i},e),r=this.getViewportTransform(),o=n.hasBorders,h=n.hasControls,c=qt(r,this.calcTransformMatrix()),u=Lr(c);t.save(),t.translate(u.translateX,u.translateY),t.lineWidth=this.borderScaleFactor,this.group===this.parent&&(t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1),this.flipX&&(u.angle-=180),t.rotate(Ut(this.group?u.angle:this.angle)),o&&this.drawBorders(t,u,e),h&&this.drawControls(t,e),t.restore()}drawBorders(t,e,s){let i;if(s&&s.forActiveSelection||this.group){const n=yu(this.width,this.height,Kh(e)),r=this.isStrokeAccountedForInDimensions()?Nf:(this.strokeUniform?new O().scalarAdd(this.canvas?this.canvas.getZoom():1):new O(e.scaleX,e.scaleY)).scalarMultiply(this.strokeWidth);i=n.add(r).scalarAdd(this.borderScaleFactor).scalarAdd(2*this.padding)}else i=this._calculateCurrentDimensions().scalarAdd(this.borderScaleFactor);this._drawBorders(t,i,s)}drawControlsConnectingLines(t,e){let s=!1;t.beginPath(),this.forEachControl((i,n)=>{i.withConnection&&i.getVisibility(this,n)&&(s=!0,t.moveTo(i.x*e.x,i.y*e.y),t.lineTo(i.x*e.x+i.offsetX,i.y*e.y+i.offsetY))}),s&&t.stroke()}drawControls(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};t.save();const s=this.getCanvasRetinaScaling(),{cornerStrokeColor:i,cornerDashArray:n,cornerColor:r}=this,o=E({cornerStrokeColor:i,cornerDashArray:n,cornerColor:r},e);t.setTransform(s,0,0,s,0,0),t.strokeStyle=t.fillStyle=o.cornerColor,this.transparentCorners||(t.strokeStyle=o.cornerStrokeColor),this._setLineDash(t,o.cornerDashArray),this.forEachControl((h,c)=>{if(h.getVisibility(this,c)){const u=this.oCoords[c];h.render(t,u.x,u.y,o,this)}}),t.restore()}isControlVisible(t){return this.controls[t]&&this.controls[t].getVisibility(this,t)}setControlVisible(t,e){this._controlsVisibility||(this._controlsVisibility={}),this._controlsVisibility[t]=e}setControlsVisibility(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Object.entries(t).forEach(e=>{let[s,i]=e;return this.setControlVisible(s,i)})}clearContextTop(t){if(!this.canvas)return;const e=this.canvas.contextTop;if(!e)return;const s=this.canvas.viewportTransform;e.save(),e.transform(s[0],s[1],s[2],s[3],s[4],s[5]),this.transform(e);const i=this.width+4,n=this.height+4;return e.clearRect(-i/2,-n/2,i,n),t||e.restore(),e}onDeselect(t){return!1}onSelect(t){return!1}shouldStartDragging(t){return!1}onDragStart(t){return!1}canDrop(t){return!1}renderDragSourceEffect(t){}renderDropTargetEffect(t){}}function Dv(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}k(rl,"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 ke extends rl{}Dv(ke,[ov]),G.setClass(ke),G.setClass(ke,"object");const Rv=(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 Fv{constructor(t){this.options=t,this.strokeProjectionMagnitude=this.options.strokeWidth/2,this.scale=new O(this.options.scaleX,this.options.scaleY),this.strokeUniformScalar=this.options.strokeUniform?new O(1/this.options.scaleX,1/this.options.scaleY):new O(1,1)}createSideVector(t,e){const s=Cu(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 O(t);return e.y+=e.x*Math.tan(Ut(this.options.skewY)),e.x+=e.y*Math.tan(Ut(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}const xw=new O;class Sa extends Fv{static getOrthogonalRotationFactor(t,e){const s=e?Tu(t,e):vv(t);return Math.abs(s)<Vn?-1:1}constructor(t,e,s,i){super(i),k(this,"AB",void 0),k(this,"AC",void 0),k(this,"alpha",void 0),k(this,"bisector",void 0),this.A=new O(t),this.B=new O(e),this.C=new O(s),this.AB=this.createSideVector(this.A,this.B),this.AC=this.createSideVector(this.A,this.C),this.alpha=Tu(this.AB,this.AC),this.bisector=Eu(tg(this.AB.eq(xw)?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=eg(i),r=Sa.getOrthogonalRotationFactor(n,this.bisector);return this.scaleUnitVector(n,s*r)}projectBevel(){const t=[];return(this.alpha%Ji==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?Au(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return Au(i)/this.strokeProjectionMagnitude<=n&&t.push(this.applySkew(this.A.add(i))),t.push(...this.projectBevel()),t}projectRoundNoSkew(t,e){const s=[],i=new O(Sa.getOrthogonalRotationFactor(this.bisector),Sa.getOrthogonalRotationFactor(new O(this.bisector.y,this.bisector.x)));return[new O(1,0).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i),new O(0,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i)].forEach(n=>{sg(n,t,e)&&s.push(this.A.add(n))}),s}projectRoundWithSkew(t,e){const s=[],{skewX:i,skewY:n,scaleX:r,scaleY:o,strokeUniform:h}=this.options,c=new O(Math.tan(Ut(i)),Math.tan(Ut(n))),u=this.strokeProjectionMagnitude,d=h?u/o/Math.sqrt(1/o**2+1/r**2*c.y**2):u/Math.sqrt(1+c.y**2),f=new O(Math.sqrt(Math.max(u**2-d**2,0)),d),g=h?u/Math.sqrt(1+c.x**2*(1/o)**2/(1/r+1/r*c.x*c.y)**2):u/Math.sqrt(1+c.x**2/(1+c.x*c.y)**2),p=new O(g,Math.sqrt(Math.max(u**2-g**2,0)));return[p,p.scalarMultiply(-1),f,f.scalarMultiply(-1)].map(m=>this.applySkew(h?m.multiply(this.strokeUniformScalar):m)).forEach(m=>{sg(m,t,e)&&s.push(this.applySkew(this.A).add(m))}),s}projectRound(){const t=[];t.push(...this.projectBevel());const e=this.alpha%Ji==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=ya(i,r)>0,h=o?i:n,c=o?n:i;return this.isSkewed()?t.push(...this.projectRoundWithSkew(h,c)):t.push(...this.projectRoundNoSkew(h,c)),t}projectPoints(){switch(this.options.strokeLineJoin){case"miter":return this.projectMiter();case"round":return this.projectRound();default:return this.projectBevel()}}project(){return this.projectPoints().map(t=>({originPoint:this.A,projectedPoint:t,angle:this.alpha,bisector:this.bisector}))}}class Lv extends Fv{constructor(t,e,s){super(s),this.A=new O(t),this.T=new O(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(eg(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 O(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 Sa(this.A,this.T,this.T,this.options).projectRound());return t}projectSquare(){const t=[];if(this.A.eq(this.T)){const e=new O(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(Eu(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 Iv=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 O(r)),n),[new O(a[0])]);if(i.length===1)e=!0;else if(!e){const n=i[0],r=((o,h)=>{for(let c=o.length-1;c>=0;c--)if(h(o[c],c,o))return c;return-1})(i,o=>!o.eq(n));i.splice(r+1)}return i.forEach((n,r,o)=>{let h,c;r===0?(c=o[1],h=e?n:o[o.length-1]):r===o.length-1?(h=o[r-1],c=e?n:o[0]):(h=o[r-1],c=o[r+1]),e&&o.length===1?s.push(...new Lv(n,n,t).project()):!e||r!==0&&r!==o.length-1?s.push(...new Sa(n,h,c,t).project()):s.push(...new Lv(n,r===0?c:h,t).project())}),s},cg=a=>{const t={};return Object.keys(a).forEach(e=>{t[e]={},Object.keys(a[e]).forEach(s=>{t[e][s]=E({},a[e][s])})}),t},jv=a=>a.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&apos;").replace(/</g,"&lt;").replace(/>/g,"&gt;");let ol;const Ou=a=>{if(ol||ol||(ol="Intl"in Uh()&&"Segmenter"in Intl&&new Intl.Segmenter(void 0,{granularity:"grapheme"})),ol){const t=ol.segment(a);return Array.from(t).map(e=>{let{segment:s}=e;return s})}return Sw(a)},Sw=a=>{const t=[];for(let e,s=0;s<a.length;s++)(e=Cw(a,s))!==!1&&t.push(e);return t},Cw=(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 Aw=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:jv,graphemeSplit:Ou});const Du=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];return a.fill!==t.fill||a.stroke!==t.stroke||a.strokeWidth!==t.strokeWidth||a.fontSize!==t.fontSize||a.fontFamily!==t.fontFamily||a.fontWeight!==t.fontWeight||a.fontStyle!==t.fontStyle||a.textDecorationThickness!==t.textDecorationThickness||a.textBackgroundColor!==t.textBackgroundColor||a.deltaY!==t.deltaY||e&&(a.overline!==t.overline||a.underline!==t.underline||a.linethrough!==t.linethrough)},Nv=(a,t)=>{const e=t.split(`
67
+ `),s=[];let i=-1,n={};a=cg(a);for(let r=0;r<e.length;r++){const o=Ou(e[r]);if(a[r])for(let h=0;h<o.length;h++){i++;const c=a[r][h];c&&Object.keys(c).length>0&&(Du(n,c,!0)?s.push({start:i,end:i+1,style:c}):s[s.length-1].end++),n=c||{}}else i+=o.length,n={}}return s},Bv=(a,t)=>{if(!Array.isArray(a))return cg(a);const e=t.split(Lf),s={};let i=-1,n=0;for(let r=0;r<e.length;r++){const o=Ou(e[r]);for(let h=0;h<o.length;h++)i++,a[n]&&a[n].start<=i&&i<a[n].end&&(s[r]=s[r]||{},s[r][h]=E({},a[n].style),i===a[n].end-1&&n++)}return s},Xn=["display","transform",ee,"fill-opacity","fill-rule","opacity",Ge,"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 Hv(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 Tw(a,t){let e=!0;const s=Hv(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=Hv(i=i.parentElement,r);return n.length===0}(a,t)),s&&e&&t.length===0}const Ew=a=>{var t;return(t=W_[a])!==null&&t!==void 0?t:a},kw=new RegExp("(".concat(Zs,")"),"gi"),Pw=a=>a.replace(kw," $1 ").replace(/,/gi," ").replace(/\s+/gi," ");var zv,Vv,Gv,Wv,Xv,Uv,Yv;const Xe="(".concat(Zs,")"),Mw=String.raw(zv||(zv=_i(["(skewX)(",")"],["(skewX)\\(","\\)"])),Xe),Ow=String.raw(Vv||(Vv=_i(["(skewY)(",")"],["(skewY)\\(","\\)"])),Xe),Dw=String.raw(Gv||(Gv=_i(["(rotate)(","(?: "," ",")?)"],["(rotate)\\(","(?: "," ",")?\\)"])),Xe,Xe,Xe),Rw=String.raw(Wv||(Wv=_i(["(scale)(","(?: ",")?)"],["(scale)\\(","(?: ",")?\\)"])),Xe,Xe),Fw=String.raw(Xv||(Xv=_i(["(translate)(","(?: ",")?)"],["(translate)\\(","(?: ",")?\\)"])),Xe,Xe),Lw=String.raw(Uv||(Uv=_i(["(matrix)("," "," "," "," "," ",")"],["(matrix)\\("," "," "," "," "," ","\\)"])),Xe,Xe,Xe,Xe,Xe,Xe),ug="(?:".concat(Lw,"|").concat(Fw,"|").concat(Dw,"|").concat(Rw,"|").concat(Mw,"|").concat(Ow,")"),Iw="(?:".concat(ug,"*)"),jw=String.raw(Yv||(Yv=_i(["^s*(?:","?)s*$"],["^\\s*(?:","?)\\s*$"])),Iw),Nw=new RegExp(jw),Bw=new RegExp(ug),Hw=new RegExp(ug,"g");function Ru(a){const t=[];if(!(a=Pw(a).replace(/\s*([()])\s*/gi,"$1"))||a&&!Nw.test(a))return[...He];for(const e of a.matchAll(Hw)){const s=Bw.exec(e[0]);if(!s)continue;let i=He;const n=s.filter(p=>!!p),[,r,...o]=n,[h,c,u,d,f,g]=o.map(p=>parseFloat(p));switch(r){case"translate":i=pa(h,c);break;case If:i=Ir({angle:h},{x:c,y:u});break;case du:i=vu(h,c);break;case da:i=zf(h);break;case fa:i=Vf(h);break;case"matrix":i=[h,c,u,d,f,g]}t.push(i)}return mu(t)}function zw(a,t,e,s){const i=Array.isArray(t);let n,r=t;if(a!==ee&&a!==Ge||t!==ze){if(a==="strokeUniform")return t==="non-scaling-stroke";if(a==="strokeDashArray")r=t===ze?null:t.replace(/,/g," ").split(/\s+/).map(parseFloat);else if(a==="transformMatrix")r=e&&e.transformMatrix?qt(e.transformMatrix,Ru(t)):Ru(t);else if(a==="visible")r=t!==ze&&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"?wt:t==="end"?$t:rt;else if(a==="charSpacing"||a===Hr)n=We(t,s)/s*1e3;else if(a==="paintFirst"){const o=t.indexOf(ee),h=t.indexOf(Ge);r=ee,(o>-1&&h>-1&&h<o||o===-1&&h>-1)&&(r=Ge)}else{if(a==="href"||a==="xlink:href"||a==="font"||a==="id")return t;if(a==="imageSmoothing")return t==="optimizeQuality";n=i?t.map(We):We(t,s)}}else r="";return!i&&isNaN(n)?r:n}function Vw(a,t){const e=a.match(G_);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=We(n)),o&&(t.fontFamily=o),r&&(t.lineHeight=r==="normal"?1:r)}function dg(a,t){a.replace(/;\s*$/,"").split(";").forEach(e=>{if(!e)return;const[s,i]=e.split(":");t[s.trim().toLowerCase()]=i.trim()})}function Gw(a){const t={},e=a.getAttribute("style");return e&&(typeof e=="string"?dg(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 Ww={stroke:"strokeOpacity",fill:"fillOpacity"};function en(a,t,e){if(!a)return{};let s,i={},n=Rf;a.parentNode&&gv.test(a.parentNode.nodeName)&&(i=en(a.parentElement,t,e),i.fontSize&&(s=n=We(i.fontSize)));const r=E(E(E({},t.reduce((c,u)=>{const d=a.getAttribute(u);return d&&(c[u]=d),c},{})),function(c){let u=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},d={};for(const f in u)Tw(c,f.split(" "))&&(d=E(E({},d),u[f]));return d}(a,e)),Gw(a));r[Zf]&&a.setAttribute(Zf,r[Zf]),r[Qf]&&(s=We(r[Qf],n),r[Qf]="".concat(s));const o={};for(const c in r){const u=Ew(c),d=zw(u,r[c],i,s);o[u]=d}o&&o.font&&Vw(o.font,o);const h=E(E({},i),o);return gv.test(a.nodeName)?h:function(c){const u=ke.getDefaults();return Object.entries(Ww).forEach(d=>{let[f,g]=d;if(c[g]===void 0||c[f]==="")return;if(c[f]===void 0){if(!u[f])return;c[f]=u[f]}if(c[f].indexOf("url(")===0)return;const p=new St(c[f]);c[f]=p.setAlpha(kt(p.getAlpha()*c[g],2)).toRgba()}),c}(h)}const Xw=["left","top","width","height","visible"],$v=["rx","ry"];class Ei extends ke{static getDefaults(){return E(E({},super.getDefaults()),Ei.ownDefaults)}constructor(t){super(),Object.assign(this,Ei.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-Gn*r,n,i+e,n+Gn*o,i+e,n+o),t.lineTo(i+e,n+s-o),h&&t.bezierCurveTo(i+e,n+s-Gn*o,i+e-Gn*r,n+s,i+e-r,n+s),t.lineTo(i+r,n+s),h&&t.bezierCurveTo(i+Gn*r,n+s,i,n+s-Gn*o,i,n+s-o),t.lineTo(i,n+o),h&&t.bezierCurveTo(i,n+Gn*o,i+Gn*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([...$v,...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,`" />
68
+ `)]}static async fromElement(t,e,s){const i=en(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,width:o=0,height:h=0,visible:c=!0}=i,u=Lt(i,Xw);return new this(E(E(E({},e),u),{},{left:n,top:r,width:o,height:h,visible:!!(c&&o&&h)}))}}k(Ei,"type","Rect"),k(Ei,"cacheProperties",[...Zi,...$v]),k(Ei,"ownDefaults",{rx:0,ry:0}),k(Ei,"ATTRIBUTE_NAMES",[...Xn,"x","y","rx","ry","width","height"]),G.setClass(Ei),G.setSVGClass(Ei);const sn="initialization",Fu="added",fg="removed",Lu="imperative",qv=(a,t)=>{const{strokeUniform:e,strokeWidth:s,width:i,height:n,group:r}=t,o=r&&r!==a?tl(r.calcTransformMatrix(),a.calcTransformMatrix()):null,h=o?t.getRelativeCenterPoint().transform(o):t.getRelativeCenterPoint(),c=!t.isStrokeAccountedForInDimensions(),u=e&&c?Km(new O(s,s),void 0,a.calcTransformMatrix()):Nf,d=!e&&c?s:0,f=yu(i+d,n+d,mu([o,t.calcOwnMatrix()],!0)).add(u).scalarDivide(2);return[h.subtract(f),h.add(f)]};class Iu{calcLayoutResult(t,e){if(this.shouldPerformLayout(t))return this.calcBoundingBox(e,t)}shouldPerformLayout(t){let{type:e,prevStrategy:s,strategy:i}=t;return e===sn||e===Lu||!!s&&i!==s}shouldLayoutClipPath(t){let{type:e,target:{clipPath:s}}=t;return e!==sn&&s&&!s.absolutePositioned}getInitialSize(t,e){return e.size}calcBoundingBox(t,e){const{type:s,target:i}=e;if(s===Lu&&e.overrides)return e.overrides;if(t.length===0)return;const{left:n,top:r,width:o,height:h}=Ai(t.map(d=>qv(i,d)).reduce((d,f)=>d.concat(f),[])),c=new O(o,h),u=new O(n,r).add(c.scalarDivide(2));if(s===sn){const d=this.getInitialSize(e,{size:c,center:u});return{center:u,relativeCorrection:new O(0,0),size:d}}return{center:u.transform(i.calcOwnMatrix()),size:c}}}k(Iu,"type","strategy");class gg extends Iu{shouldPerformLayout(t){return!0}}k(gg,"type","fit-content"),G.setClass(gg);const Uw=["strategy"],Yw=["target","strategy","bubbles","prevStrategy"],Kv="layoutManager";class al{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:new gg;k(this,"strategy",void 0),this.strategy=t,this._subscriptions=new Map}performLayout(t){const e=E(E({bubbles:!0,strategy:this.strategy},t),{},{prevStrategy:this._prevLayoutStrategy,stopPropagation(){this.bubbles=!1}});this.onBeforeLayout(e);const s=this.getLayoutResult(e);s&&this.commitLayout(e,s),this.onAfterLayout(e,s),this._prevLayoutStrategy=e.strategy}attachHandlers(t,e){const{target:s}=e;return[fu,km,$h,Pm,cu,Mm,uu,D_,R_].map(i=>t.on(i,n=>this.performLayout(i===fu?{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===sn||s===Fu?this.subscribeTargets(t):s===fg&&this.unsubscribeTargets(t),e.fire("layout:before",{context:t}),i&&i.fire("object:layout:before",{target:e,context:t}),s===Lu&&t.deep){const n=Lt(t,Uw);e.forEachObject(r=>r.layoutManager&&r.layoutManager.performLayout(E(E({},n),{},{bubbles:!1,target:r})))}}getLayoutResult(t){const{target:e,strategy:s,type:i}=t,n=s.calcLayoutResult(t,e.getObjects());if(!n)return;const r=i===sn?new O:e.getRelativeCenterPoint(),{center:o,correction:h=new O,relativeCorrection:c=new O}=n,u=r.subtract(o).add(h).transform(i===sn?He:ns(e.calcOwnMatrix()),!0).add(c);return{result:n,prevCenter:r,nextCenter:o,offset:u}}commitLayout(t,e){const{target:s}=t,{result:{size:i},nextCenter:n}=e;var r,o;s.set({width:i.x,height:i.y}),this.layoutObjects(t,e),t.type===sn?s.set({left:(r=t.x)!==null&&r!==void 0?r:n.x+i.x*se(s.originX),top:(o=t.y)!==null&&o!==void 0?o:n.y+i.y*se(s.originY)}):(s.setPositionByOrigin(n,rt,rt),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=Lt(t,Yw),{canvas:h}=s;s.fire("layout:after",{context:t,result:e}),h&&h.fire("object:layout:after",{context:t,result:e,target:s});const c=s.parent;n&&c!=null&&c.layoutManager&&((o.path||(o.path=[])).push(s),c.layoutManager.performLayout(E(E({},o),{},{target:c}))),s.set("dirty",!0)}dispose(){const{_subscriptions:t}=this;t.forEach(e=>e.forEach(s=>s())),t.clear()}toObject(){return{type:Kv,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}G.setClass(al,Kv);const $w=["type","objects","layoutManager"];class qw extends al{performLayout(){}}class Fs extends Om(ke){static getDefaults(){return E(E({},super.getDefaults()),Fs.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),k(this,"_activeObjects",[]),k(this,"__objectSelectionTracker",void 0),k(this,"__objectSelectionDisposer",void 0),Object.assign(this,Fs.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 al,this.layoutManager.performLayout({type:sn,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(Ki("error","Group: circular object trees are not supported, this call has no effect"),!1):this._objects.indexOf(t)===-1||(Ki("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(Fu,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(Fu,n),r}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange(fg,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&&ba(t,qt(ns(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||(ba(t,qt(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=ke.prototype.shouldCache.call(this);if(t){for(let e=0;e<this._objects.length;e++)if(this._objects[e].willDrawShadow())return this.ownCaching=!1,!1}return t}willDrawShadow(){if(super.willDrawShadow())return!0;for(let t=0;t<this._objects.length;t++)if(this._objects[t].willDrawShadow())return!0;return!1}isOnACache(){return this.ownCaching||!!this.parent&&this.parent.isOnACache()}drawObject(t,e,s){this._renderBackground(t);for(let n=0;n<this._objects.length;n++){var i;const r=this._objects[n];(i=this.canvas)!==null&&i!==void 0&&i.preserveObjectStacking&&r.group!==this?(t.save(),t.transform(...ns(this.calcTransformMatrix())),r.render(t),t.restore()):r.group===this&&r.render(t)}this._drawClipPath(t,this.clipPath,s)}setCoords(){super.setCoords(),this._shouldSetNestedCoords()&&this.forEachObject(t=>t.setCoords())}triggerLayout(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.layoutManager.performLayout(E({target:this,type:Lu},t))}render(t){this._transformDone=!0,super.render(t),this._transformDone=!1}__serializeObjects(t,e){const s=this.includeDefaultValues;return this._objects.filter(function(i){return!i.excludeFromExport}).map(function(i){const n=i.includeDefaultValues;i.includeDefaultValues=s;const r=i[t||"toObject"](e);return i.includeDefaultValues=n,r})}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=this.layoutManager.toObject();return E(E(E({},super.toObject(["subTargetCheck","interactive",...t])),e.strategy!=="fit-content"||this.includeDefaultValues?{layoutManager:e}:{}),{},{objects:this.__serializeObjects("toObject",t)})}toString(){return"#<Group: (".concat(this.complexity(),")>")}dispose(){this.layoutManager.unsubscribeTargets({targets:this.getObjects(),target:this}),this._activeObjects=[],this.forEachObject(t=>{this._watchObject(!1,t),t.dispose()}),super.dispose()}_createSVGBgRect(t){if(!this.backgroundColor)return"";const e=Ei.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",` >
69
69
  `],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>
70
- `),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=Lt(t,Nw);return Promise.all([po(i,e),Kh(r,e)]).then(a=>{let[h,c]=a;const u=new this(h,T(T(T({},r),c),{},{layoutManager:new Bw}));if(n){const d=W.getClass(n.type),f=W.getClass(n.strategy);u.layoutManager=new d(new f)}else u.layoutManager=new sl;return u.layoutManager.subscribeTargets({type:tn,target:u,targets:u.getObjects()}),u.setCoords(),u})}}E(Ls,"type","Group"),E(Ls,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),W.setClass(Ls);const z0=(o,t)=>Math.min(t.width/o.width,t.height/o.height),V0=(o,t)=>Math.max(t.width/o.width,t.height/o.height),dg="\\s*,?\\s*",il="".concat(dg,"(").concat(ti,")"),Hw="".concat(il).concat(il).concat(il).concat(dg,"([01])").concat(dg,"([01])").concat(il).concat(il),zw={m:"l",M:"L"},Vw=(o,t,e,s,i,n,r,a,h,c,u)=>{const d=Ks(o),f=Js(o),g=Ks(t),p=Js(t),m=e*i*g-s*n*p+r,y=s*i*g+e*n*p+a;return["C",c+h*(-e*i*f-s*n*d),u+h*(-s*i*f+e*n*d),m+h*(e*i*p+s*n*g),y+h*(s*i*p-e*n*g),m,y]},W0=(o,t,e,s)=>{const i=Math.atan2(t,o),n=Math.atan2(s,e);return n>=i?n-i:2*Math.PI-(i-n)};function fg(o,t,e,s,i,n,r,a){let h;if(bt.cachesBoundsOfCurve&&(h=[...arguments].join(),Xh.boundsOfCurveCache[h]))return Xh.boundsOfCurveCache[h];const c=Math.sqrt,u=Math.abs,d=[],f=[[0,0],[0,0]];let g=6*o-12*e+6*i,p=-3*o+9*e-9*i+3*r,m=3*e-3*o;for(let C=0;C<2;++C){if(C>0&&(g=6*t-12*s+6*n,p=-3*t+9*s-9*n+3*a,m=3*s-3*t),u(p)<1e-12){if(u(g)<1e-12)continue;const R=-m/g;0<R&&R<1&&d.push(R);continue}const k=g*g-4*m*p;if(k<0)continue;const O=c(k),P=(-g+O)/(2*p);0<P&&P<1&&d.push(P);const D=(-g-O)/(2*p);0<D&&D<1&&d.push(D)}let y=d.length;const b=y,x=X0(o,t,e,s,i,n,r,a);for(;y--;){const{x:C,y:k}=x(d[y]);f[0][y]=C,f[1][y]=k}f[0][b]=o,f[1][b]=t,f[0][b+1]=r,f[1][b+1]=a;const S=[new M(Math.min(...f[0]),Math.min(...f[1])),new M(Math.max(...f[0]),Math.max(...f[1]))];return bt.cachesBoundsOfCurve&&(Xh.boundsOfCurveCache[h]=S),S}const Ww=(o,t,e)=>{let[s,i,n,r,a,h,c,u]=e;const d=((f,g,p,m,y,b,x)=>{if(p===0||m===0)return[];let S=0,C=0,k=0;const O=Math.PI,P=x*Mf,D=Js(P),R=Ks(P),z=.5*(-R*f-D*g),B=.5*(-R*g+D*f),F=p**2,L=m**2,N=B**2,K=z**2,I=F*L-F*N-L*K;let V=Math.abs(p),it=Math.abs(m);if(I<0){const Te=Math.sqrt(1-I/(F*L));V*=Te,it*=Te}else k=(y===b?-1:1)*Math.sqrt(I/(F*N+L*K));const Ot=k*V*B/it,Bt=-k*it*z/V,Xt=R*Ot-D*Bt+.5*f,Ft=D*Ot+R*Bt+.5*g;let _t=W0(1,0,(z-Ot)/V,(B-Bt)/it),ae=W0((z-Ot)/V,(B-Bt)/it,(-z-Ot)/V,(-B-Bt)/it);b===0&&ae>0?ae-=2*O:b===1&&ae<0&&(ae+=2*O);const Ze=Math.ceil(Math.abs(ae/O*2)),st=[],nt=ae/Ze,Zt=8/3*Math.sin(nt/4)*Math.sin(nt/4)/Math.sin(nt/2);let $s=_t+nt;for(let Te=0;Te<Ze;Te++)st[Te]=Vw(_t,$s,R,D,V,it,Xt,Ft,Zt,S,C),S=st[Te][5],C=st[Te][6],_t=$s,$s+=nt;return st})(c-o,u-t,i,n,a,h,r);for(let f=0,g=d.length;f<g;f++)d[f][1]+=o,d[f][2]+=t,d[f][3]+=o,d[f][4]+=t,d[f][5]+=o,d[f][6]+=t;return d},G0=o=>{let t=0,e=0,s=0,i=0;const n=[];let r,a=0,h=0;for(const c of o){const u=[...c];let d;switch(u[0]){case"l":u[1]+=t,u[2]+=e;case"L":t=u[1],e=u[2],d=["L",t,e];break;case"h":u[1]+=t;case"H":t=u[1],d=["L",t,e];break;case"v":u[1]+=e;case"V":e=u[1],d=["L",t,e];break;case"m":u[1]+=t,u[2]+=e;case"M":t=u[1],e=u[2],s=u[1],i=u[2],d=["M",t,e];break;case"c":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e,u[5]+=t,u[6]+=e;case"C":a=u[3],h=u[4],t=u[5],e=u[6],d=["C",u[1],u[2],a,h,t,e];break;case"s":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e;case"S":r==="C"?(a=2*t-a,h=2*e-h):(a=t,h=e),t=u[3],e=u[4],d=["C",a,h,u[1],u[2],t,e],a=d[3],h=d[4];break;case"q":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e;case"Q":a=u[1],h=u[2],t=u[3],e=u[4],d=["Q",a,h,t,e];break;case"t":u[1]+=t,u[2]+=e;case"T":r==="Q"?(a=2*t-a,h=2*e-h):(a=t,h=e),t=u[1],e=u[2],d=["Q",a,h,t,e];break;case"a":u[6]+=t,u[7]+=e;case"A":Ww(t,e,u).forEach(f=>n.push(f)),t=u[6],e=u[7];break;case"z":case"Z":t=s,e=i,d=["Z"]}d?(n.push(d),r=d[0]):r=""}return n},Fu=(o,t,e,s)=>Math.sqrt((e-o)**2+(s-t)**2),X0=(o,t,e,s,i,n,r,a)=>h=>{const c=h**3,u=(g=>3*g**2*(1-g))(h),d=(g=>3*g*(1-g)**2)(h),f=(g=>(1-g)**3)(h);return new M(r*c+i*u+e*d+o*f,a*c+n*u+s*d+t*f)},U0=o=>o**2,Y0=o=>2*o*(1-o),$0=o=>(1-o)**2,Gw=(o,t,e,s,i,n,r,a)=>h=>{const c=U0(h),u=Y0(h),d=$0(h),f=3*(d*(e-o)+u*(i-e)+c*(r-i)),g=3*(d*(s-t)+u*(n-s)+c*(a-n));return Math.atan2(g,f)},Xw=(o,t,e,s,i,n)=>r=>{const a=U0(r),h=Y0(r),c=$0(r);return new M(i*a+e*h+o*c,n*a+s*h+t*c)},Uw=(o,t,e,s,i,n)=>r=>{const a=1-r,h=2*(a*(e-o)+r*(i-e)),c=2*(a*(s-t)+r*(n-s));return Math.atan2(c,h)},q0=(o,t,e)=>{let s=new M(t,e),i=0;for(let n=1;n<=100;n+=1){const r=o(n/100);i+=Fu(s.x,s.y,r.x,r.y),s=r}return i},Yw=(o,t)=>{let e,s=0,i=0,n={x:o.x,y:o.y},r=T({},n),a=.01,h=0;const c=o.iterator,u=o.angleFinder;for(;i<t&&a>1e-4;)r=c(s),h=s,e=Fu(n.x,n.y,r.x,r.y),e+i>t?(s-=a,a/=2):(n=r,s+=a,i+=e);return T(T({},r),{},{angle:u(h)})},gg=o=>{let t,e,s=0,i=0,n=0,r=0,a=0;const h=[];for(const c of o){const u={x:i,y:n,command:c[0],length:0};switch(c[0]){case"M":e=u,e.x=r=i=c[1],e.y=a=n=c[2];break;case"L":e=u,e.length=Fu(i,n,c[1],c[2]),i=c[1],n=c[2];break;case"C":t=X0(i,n,c[1],c[2],c[3],c[4],c[5],c[6]),e=u,e.iterator=t,e.angleFinder=Gw(i,n,c[1],c[2],c[3],c[4],c[5],c[6]),e.length=q0(t,i,n),i=c[5],n=c[6];break;case"Q":t=Xw(i,n,c[1],c[2],c[3],c[4]),e=u,e.iterator=t,e.angleFinder=Uw(i,n,c[1],c[2],c[3],c[4]),e.length=q0(t,i,n),i=c[3],n=c[4];break;case"Z":e=u,e.destX=r,e.destY=a,e.length=Fu(i,n,r,a),i=r,n=a}s+=e.length,h.push(e)}return h.push({length:s,x:i,y:n}),h},K0=function(o,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:gg(o),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=o[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 Yw(i,t)}},$w=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),J0=new RegExp(Hw,"g"),qw=new RegExp(ti,"gi"),Kw={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},Q0=o=>{var t;const e=[],s=(t=o.match($w))!==null&&t!==void 0?t:[];for(const i of s){const n=i[0];if(n==="z"||n==="Z"){e.push([n]);continue}const r=Kw[n.toLowerCase()];let a=[];if(n==="a"||n==="A"){J0.lastIndex=0;for(let h=null;h=J0.exec(i);)a.push(...h.slice(1))}else a=i.match(qw)||[];for(let h=0;h<a.length;h+=r){const c=new Array(r),u=zw[n];c[0]=h>0&&u?u:n;for(let d=0;d<r;d++)c[d+1]=parseFloat(a[h+d]);e.push(c)}}return e},Jw=function(o){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=new M(o[0]),s=new M(o[1]),i=1,n=0;const r=[],a=o.length,h=a>2;let c;for(h&&(i=o[2].x<s.x?-1:o[2].x===s.x?0:1,n=o[2].y<s.y?-1:o[2].y===s.y?0:1),r.push(["M",e.x-i*t,e.y-n*t]),c=1;c<a;c++){if(!e.eq(s)){const u=e.midPointFrom(s);r.push(["Q",e.x,e.y,u.x,u.y])}e=o[c],c+1<o.length&&(s=o[c+1])}return h&&(i=e.x>o[c-2].x?1:e.x===o[c-2].x?0:-1,n=e.y>o[c-2].y?1:e.y===o[c-2].y?0:-1),r.push(["L",e.x+i*t,e.y+n*t]),r},Z0=(o,t)=>o.map(e=>e.map((s,i)=>i===0||t===void 0?s:Dt(s,t)).join(" ")).join(" ");function Lu(o,t){const e=o.style;e&&t&&(typeof t=="string"?e.cssText+=";"+t:Object.entries(t).forEach(s=>{let[i,n]=s;return e.setProperty(i,n)}))}const Qw=(o,t)=>Math.floor(Math.random()*(t-o+1))+o;function tv(o){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const e=t.onComplete||Rr,s=new(ou()).XMLHttpRequest,i=t.signal,n=function(){s.abort()},r=function(){i&&i.removeEventListener("abort",n),s.onerror=s.ontimeout=Rr};if(i&&i.aborted)throw new kf("request");return i&&i.addEventListener("abort",n,{once:!0}),s.onreadystatechange=function(){s.readyState===4&&(r(),e(s),s.onreadystatechange=Rr)},s.onerror=s.ontimeout=r,s.open("get",o,!0),s.send(),s}const Iu=(o,t)=>{let e=o._findCenterFromElement();o.transformMatrix&&((s=>{if(s.transformMatrix){const{scaleX:i,scaleY:n,angle:r,skewX:a}=Lr(s.transformMatrix);s.flipX=!1,s.flipY=!1,s.set(Ve,i),s.set(gs,n),s.angle=r,s.skewX=a,s.skewY=0}})(o),e=e.transform(o.transformMatrix)),delete o.transformMatrix,t&&(o.scaleX*=t.scaleX,o.scaleY*=t.scaleY,o.cropX=t.cropX,o.cropY=t.cropY,e.x+=t.offsetLeft,e.y+=t.offsetTop,o.width=t.width,o.height=t.height),o.setPositionByOrigin(e,rt,rt)};var Zw=Object.freeze({__proto__:null,addTransformToObject:Gm,animate:ng,animateColor:g0,applyTransformToObject:vo,calcAngleBetweenVectors:Su,calcDimensionsMatrix:$h,calcPlaneChangeMatrix:Qh,calcVectorRotation:o0,cancelAnimFrame:Pm,capValue:Hr,composeMatrix:Fm,copyCanvasElement:o=>{var t;const e=ps(o);return(t=e.getContext("2d"))===null||t===void 0||t.drawImage(o,0,0),e},cos:Ks,createCanvasElement:Rs,createImage:Mm,createRotateMatrix:Ir,createScaleMatrix:pu,createSkewXMatrix:Bf,createSkewYMatrix:Hf,createTranslateMatrix:go,createVector:wu,crossProduct:bo,degreesToRadians:Ut,dotProduct:h0,ease:z_,enlivenObjectEnlivables:Kh,enlivenObjects:po,findScaleToCover:V0,findScaleToFit:z0,getBoundsOfCurve:fg,getOrthonormalVector:Qf,getPathSegmentsInfo:gg,getPointOnPath:K0,getPointer:Vm,getRandomInt:Qw,getRegularPolygonPath:(o,t)=>{const e=2*Math.PI/o;let s=-Vn;o%2==0&&(s+=e/2);const i=new Array(o+1);for(let n=0;n<o;n++){const r=n*e+s,{x:a,y:h}=new M(Ks(r),Js(r)).scalarMultiply(t);i[n]=[n===0?"M":"L",a,h]}return i[o]=["Z"],i},getSmoothPathFromPoints:Jw,getSvgAttributes:o=>{const t=["instantiated_by_use","style","id","class"];switch(o){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:Cu,groupSVGElements:(o,t)=>o&&o.length===1?o[0]:new Ls(o,t),hasStyleChanged:Pu,invertTransform:ns,isBetweenVectors:Zf,isIdentityMatrix:Om,isTouchEvent:mu,isTransparent:S0,joinPath:Z0,loadImage:qh,magnitude:xu,makeBoundingBoxFromPoints:Ci,makePathSimpler:G0,matrixToSVG:mo,mergeClipPaths:(o,t)=>{var e;let s=o,i=t;s.inverted&&!i.inverted&&(s=t,i=o),Gf(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 Ls([s],{clipPath:i,inverted:n})},multiplyTransformMatrices:qt,multiplyTransformMatrixArray:gu,parsePath:Q0,parsePreserveAspectRatioAttribute:Yf,parseUnit:Ge,pick:jr,projectStrokeOnPoints:T0,qrDecompose:Lr,radiansToDegrees:Si,removeFromArray:Fr,removeTransformFromObject:(o,t)=>{const e=ns(t),s=qt(e,o.calcOwnMatrix());vo(o,s)},removeTransformMatrixForSvgParsing:Iu,request:tv,requestAnimFrame:Yh,resetObjectTransform:Xm,rotatePoint:(o,t,e)=>o.rotate(e,t),rotateVector:Jf,saveObjectTransform:Wf,sendObjectToPlane:Gf,sendPointToPlane:Br,sendVectorToPlane:Um,setStyle:Lu,sin:Js,sizeAfterTransform:vu,string:pw,stylesFromArray:P0,stylesToArray:k0,toBlob:Nf,toDataURL:jf,toFixed:Dt,transformPath:(o,t,e)=>(e&&(t=qt(t,[1,0,0,1,-e.x,-e.y])),o.map(s=>{const i=[...s];for(let n=1;n<s.length-1;n+=2){const{x:r,y:a}=Ee({x:s[n],y:s[n+1]},t);i[n]=r,i[n+1]=a}return i})),transformPoint:Ee});class tx extends zm{constructor(t){let{allowTouchScrolling:e=!1,containerClass:s=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(t),E(this,"upper",void 0),E(this,"container",void 0);const{el:i}=this.lower,n=this.createUpperCanvas();this.upper={el:n,ctx:n.getContext("2d")},this.applyCanvasStyle(i,{allowTouchScrolling:e}),this.applyCanvasStyle(n,{allowTouchScrolling:e,styles:{position:"absolute",left:"0",top:"0"}});const r=this.createContainerElement();r.classList.add(s),i.parentNode&&i.parentNode.replaceChild(r,i),r.append(i,n),this.container=r}createUpperCanvas(){const{el:t}=this.lower,e=Rs();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=lo().createElement("div");return t.setAttribute("data-fabric","wrapper"),Lu(t,{position:"relative"}),Hm(t),t}applyCanvasStyle(t,e){const{styles:s,allowTouchScrolling:i}=e;Lu(t,T(T({},s),{},{"touch-action":i?"manipulation":ze})),Hm(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:s,ctx:i}=this.upper;Bm(s,i,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),Vf(this.upper.el,t),Vf(this.container,t)}cleanupDOM(t){const e=this.container,{el:s}=this.lower,{el:i}=this.upper;super.cleanupDOM(t),e.removeChild(i),e.removeChild(s),e.parentNode&&e.parentNode.replaceChild(s,e)}dispose(){super.dispose(),xi().dispose(this.upper.el),delete this.upper,delete this.container}}class ju extends Jh{constructor(){super(...arguments),E(this,"targets",[]),E(this,"_hoveredTargets",[]),E(this,"_objectsToRender",void 0),E(this,"_currentTransform",null),E(this,"_groupSelector",null),E(this,"contextTopDirty",!1)}static getDefaults(){return T(T({},super.getDefaults()),ju.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 tx(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 a=Math.round(i*this.getRetinaScaling());return S0(n,a,a,a)}_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===cu||e===Ve||e===gs||e===Uh?i=this.centeredScaling||t.centeredScaling:e===Ff&&(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=$t:["mr","tr","br"].includes(e)&&(s.x=wt),["tl","mt","tr"].includes(e)?s.y=Df:["bl","mb","br"].includes(e)&&(s.y=is)),s}_setupCurrentTransform(t,e,s){var i;const n=e.group?Br(this.getScenePoint(t),void 0,e.group.calcTransformMatrix()):this.getScenePoint(t),{key:r="",control:a}=e.getActiveControl()||{},h=s&&a?(i=a.getActionHandler(t,e,a))===null||i===void 0?void 0:i.bind(a):R_,c=((g,p,m,y)=>{if(!p||!g)return"drag";const b=y.controls[p];return b.getActionName(m,b,y)})(s,r,t,e),u=t[this.centeredKey],d=this._shouldCenterTransform(e,c,u)?{x:rt,y:rt}:this._getOriginFromCorner(e,r),f={target:e,action:c,actionHandler:h,actionPerformed:!1,corner:r,scaleX:e.scaleX,scaleY:e.scaleY,skewX:e.skewX,skewY:e.skewY,offsetX:n.x-e.left,offsetY:n.y-e.top,originX:d.x,originY:d.y,ex:n.x,ey:n.y,lastX:n.x,lastY:n.y,theta:Ut(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:u,original:T(T({},Wf(e)),{},{originX:d.x,originY:d.y})};this._currentTransform=f,this.fire("before:transform",{e:t,transform:f})}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new M(e,s).transform(this.viewportTransform),a=new M(e+i,s+n).transform(this.viewportTransform),h=this.selectionLineWidth/2;let c=Math.min(r.x,a.x),u=Math.min(r.y,a.y),d=Math.max(r.x,a.x),f=Math.max(r.y,a.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(c,u,d-c,f-u)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,c+=h,u+=h,d-=h,f-=h,ke.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(c,u,d-c,f-u))}findTarget(t){if(this.skipTargetFind)return;const e=this.getViewportPoint(t),s=this._activeObject,i=this.getActiveObjects();if(this.targets=[],s&&i.length>=1){if(s.findControl(e,mu(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,a,h,c]=s,u=Math.atan2(a.y-r.y,a.x-r.x),d=Ks(u)*n,f=Js(u)*n,g=d+f,p=d-f;s=[new M(r.x-p,r.y-g),new M(a.x+g,a.y-p),new M(h.x+p,h.y+g),new M(c.x-g,c.y+p)]}return zt.isPointInPolygon(e,s)}_checkTarget(t,e){return!!(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,Br(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(fu(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&&fu(s)&&s.interactive&&this.targets[0]){const i=this.targets;for(let n=i.length-1;n>0;n--){const r=i[n];if(!fu(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=Vm(t),r=i.width||0,a=i.height||0;r&&a||(is in i&&Df in i&&(a=Math.abs(i.top-i.bottom)),$t in i&&wt 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=Br(n,void 0,this.viewportTransform));const h=this.getRetinaScaling();h!==1&&(n.x/=h,n.y/=h);const c=r===0||a===0?new M(1,1):new M(s.width/r,s.height/a);return n.multiply(c)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=Rs(),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 Nr(t)?t.getObjects():t?[t]:[]}_fireSelectionEvents(t,e){let s=!1,i=!1;const n=this.getActiveObjects(),r=[],a=[];t.forEach(h=>{n.includes(h)||(s=!0,h.fire("deselected",{e,target:h}),a.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:a})):n.length>0?(i=!0,this.fire("selection:created",{e,selected:r})):t.length>0&&(i=!0,this.fire("selection:cleared",{e,deselected:a})),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,Nr(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),Nr(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(uu,i))}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeObject;Nr(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&&Nr(e)&&this._activeObject===e){const s=jr(t,["angle","flipX","flipY",wt,Ve,gs,co,uo,is]);return Gm(t,e.calcOwnMatrix()),s}return{}}_setSVGObject(t,e,s){const i=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,s),e.set(i)}}E(ju,"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 ex{constructor(t){E(this,"targets",[]),E(this,"__disposer",void 0);const e=()=>{const{hiddenTextarea:i}=t.getActiveObject()||{};i&&i.focus()},s=t.upperCanvasEl;s.addEventListener("click",e),this.__disposer=()=>s.removeEventListener("click",e)}exitTextEditing(){this.target=void 0,this.targets.forEach(t=>{t.isEditing&&t.exitEditing()})}add(t){this.targets.push(t)}remove(t){this.unregister(t),Fr(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 sx=["target","oldTarget","fireCanvas","e"],ms={passive:!1},So=(o,t)=>{const e=o.getViewportPoint(t),s=o.getScenePoint(t);return{viewportPoint:e,scenePoint:s,pointer:e,absolutePointer:s}},Un=function(o){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return o.addEventListener(...e)},Is=function(o){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return o.removeEventListener(...e)},ix={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 pg extends ju{constructor(t){super(t,arguments.length>1&&arguments[1]!==void 0?arguments[1]:{}),E(this,"_isClick",void 0),E(this,"textEditingManager",new ex(this)),["_onMouseDown","_onTouchStart","_onMouseMove","_onMouseUp","_onTouchEnd","_onResize","_onMouseWheel","_onMouseOut","_onMouseEnter","_onContextMenu","_onClick","_onDragStart","_onDragEnd","_onDragProgress","_onDragOver","_onDragEnter","_onDragLeave","_onDrop"].forEach(e=>{this[e]=this[e].bind(this)}),this.addOrRemove(Un,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const s=this.upperCanvasEl,i=this._getEventPrefix();t(Nm(s),"resize",this._onResize),t(s,i+"down",this._onMouseDown),t(s,"".concat(i,"move"),this._onMouseMove,ms),t(s,"".concat(i,"out"),this._onMouseOut),t(s,"".concat(i,"enter"),this._onMouseEnter),t(s,"wheel",this._onMouseWheel),t(s,"contextmenu",this._onContextMenu),t(s,"click",this._onClick),t(s,"dblclick",this._onClick),t(s,"dragstart",this._onDragStart),t(s,"dragend",this._onDragEnd),t(s,"dragover",this._onDragOver),t(s,"dragenter",this._onDragEnter),t(s,"dragleave",this._onDragLeave),t(s,"drop",this._onDrop),this.enablePointerEvents||t(s,"touchstart",this._onTouchStart,ms)}removeListeners(){this.addOrRemove(Is,"remove");const t=this._getEventPrefix(),e=Qs(this.upperCanvasEl);Is(e,"".concat(t,"up"),this._onMouseUp),Is(e,"touchend",this._onTouchEnd,ms),Is(e,"".concat(t,"move"),this._onMouseMove,ms),Is(e,"touchmove",this._onMouseMove,ms),clearTimeout(this._willAddMouseDown)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s=T({e:t},So(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},So(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 Un(this.upperCanvasEl,"drag",this._onDragProgress)}Wm(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!==ze,s=e?this._activeObject:void 0,i={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:s};Is(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 a;this.fire(e,r),this._fireEnterLeaveEvents(s,r),s&&(s.canDrop(t)&&(a=s),s.fire(e,r));for(let h=0;h<i.length;h++){const c=i[h];c.canDrop(t)&&(a=c),c.fire(e,r)}this._renderDragEffects(t,n,a),this._dropTarget=a}_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},So(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&&Wm(t),this._basicEventHandler("contextmenu",i),!1}_onClick(t){const e=t.detail;e>3||e<2||(this._cacheTransformEventData(t),e==2&&t.type==="dblclick"&&this._handleEvent(t,"dblclick"),e==3&&this._handleEvent(t,"tripleclick"),this._resetTransformEventData())}getPointerId(t){const e=t.changedTouches;return e?e[0]&&e[0].identifier:this.enablePointerEvents?t.pointerId:-1}_isMainEvent(t){return t.isPrimary===!0||t.isPrimary!==!1&&(t.type==="touchend"&&t.touches.length===0||!t.changedTouches||t.changedTouches[0].identifier===this.mainTouchId)}_onTouchStart(t){let e=!this.allowTouchScrolling;const s=this._activeObject;this.mainTouchId===void 0&&(this.mainTouchId=this.getPointerId(t)),this.__onMouseDown(t),(this.isDrawingMode||s&&this._target===s)&&(e=!0),e&&t.preventDefault(),this._resetTransformEventData();const i=this.upperCanvasEl,n=this._getEventPrefix(),r=Qs(i);Un(r,"touchend",this._onTouchEnd,ms),e&&Un(r,"touchmove",this._onMouseMove,ms),Is(i,"".concat(n,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();Is(e,"".concat(s,"move"),this._onMouseMove,ms);const i=Qs(e);Un(i,"".concat(s,"up"),this._onMouseUp),Un(i,"".concat(s,"move"),this._onMouseMove,ms)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),s=Qs(this.upperCanvasEl);Is(s,"touchend",this._onTouchEnd,ms),Is(s,"touchmove",this._onMouseMove,ms),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout(()=>{Un(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=Qs(this.upperCanvasEl);Is(i,"".concat(s,"up"),this._onMouseUp),Is(i,"".concat(s,"move"),this._onMouseMove,ms),Un(e,"".concat(s,"move"),this._onMouseMove,ms)}}_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 a,h,c=!1;if(s&&(this._finalizeCurrentTransform(t),c=s.actionPerformed),!i){const u=n===this._activeObject;this.handleSelection(t),c||(c=this._shouldRender(n)||!u&&n===this._activeObject)}if(n){const u=n.findControl(this.getViewportPoint(t),mu(t)),{key:d,control:f}=u||{};if(h=d,n.selectable&&n!==this._activeObject&&n.activeOn==="up")this.setActiveObject(n,t),c=!0;else if(f){const g=f.getMouseUpHandler(t,n,f);g&&(a=this.getScenePoint(t),g.call(f,t,s,a.x,a.y))}n.isMoving=!1}if(s&&(s.target!==n||s.corner!==h)){const u=s.target&&s.target.controls[s.corner],d=u&&u.getMouseUpHandler(t,s.target,u);a=a||this.getScenePoint(t),d&&d.call(u,t,s,a.x,a.y)}this._setCursorFromEvent(t,n),this._handleEvent(t,"up"),this._groupSelector=null,this._currentTransform=null,n&&(n.__corner=void 0),c?this.requestRenderAll():i||(e=this._activeObject)!==null&&e!==void 0&&e.isEditing||this.renderTop()}_basicEventHandler(t,e){const{target:s,subTargets:i=[]}=e;this.fire(t,e),s&&s.fire(t,e);for(let n=0;n<i.length;n++)i[n]!==s&&i[n].fire(t,e);return e}_handleEvent(t,e,s){const i=this._target,n=this.targets||[],r=T(T(T({e:t,target:i,subTargets:n},So(this,t)),{},{transform:this._currentTransform},e==="up:before"||e==="up"?{isClick:this._isClick,currentTarget:this.findTarget(t),currentSubTargets:this.targets}:{}),e==="down:before"||e==="down"?s:{});this.fire("mouse:".concat(e),r),i&&i.fire("mouse".concat(e),r);for(let a=0;a<n.length;a++)n[a]!==i&&n[a].fire("mouse".concat(e),r)}_onMouseDownInDrawingMode(t){this._isCurrentlyDrawing=!0,this.getActiveObject()&&(this.discardActiveObject(t),this.requestRenderAll());const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseDown(e,{e:t,pointer:e}),this._handleEvent(t,"down",{alreadySelected:!1})}_onMouseMoveInDrawingMode(t){if(this._isCurrentlyDrawing){const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseMove(e,{e:t,pointer:e})}this.setCursor(this.freeDrawingCursor),this._handleEvent(t,"move")}_onMouseUpInDrawingMode(t){const e=this.getScenePoint(t);this.freeDrawingBrush?this._isCurrentlyDrawing=!!this.freeDrawingBrush.onMouseUp({e:t,pointer:e}):this._isCurrentlyDrawing=!1,this._handleEvent(t,"up")}__onMouseDown(t){this._isClick=!0,this._cacheTransformEventData(t),this._handleEvent(t,"down:before");let e=this._target,s=!!e&&e===this._activeObject;const{button:i}=t;if(i)return(this.fireMiddleClick&&i===1||this.fireRightClick&&i===2)&&this._handleEvent(t,"down",{alreadySelected:s}),void this._resetTransformEventData();if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t)||this._currentTransform)return;let n=this._shouldRender(e),r=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,r=!0,n=!0):this._shouldClearSelection(t,e)&&this.discardActiveObject(t),this.selection&&(!e||!e.selectable&&!e.isEditing&&e!==this._activeObject)){const a=this.getScenePoint(t);this._groupSelector={x:a.x,y:a.y,deltaY:0,deltaX:0}}if(s=!!e&&e===this._activeObject,e){e.selectable&&e.activeOn==="down"&&this.setActiveObject(e,t);const a=e.findControl(this.getViewportPoint(t),mu(t));if(e===this._activeObject&&(a||!r)){this._setupCurrentTransform(t,e,s);const h=a?a.control:void 0,c=this.getScenePoint(t),u=h&&h.getMouseDownHandler(t,e,h);u&&u.call(h,t,this._currentTransform,c.x,c.y)}}n&&(this._objectsToRender=void 0),this._handleEvent(t,"down",{alreadySelected:s}),n&&this.requestRenderAll()}_resetTransformEventData(){this._target=this._pointer=this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getViewportPoint(t),this._absolutePointer=Br(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 a=0;a<r;a++)this.fireSyntheticInOutEvents("mouse",{e:t,target:n[a],oldTarget:i[a]});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 a=0;a<r;a++)this.fireSyntheticInOutEvents("drag",T(T({},e),{},{target:n[a],oldTarget:i[a]}));this._draggedoverTarget=t}fireSyntheticInOutEvents(t,e){let{target:s,oldTarget:i,fireCanvas:n,e:r}=e,a=Lt(e,sx);const{targetIn:h,targetOut:c,canvasIn:u,canvasOut:d}=ix[t],f=i!==s;if(i&&f){const g=T(T({},a),{},{e:r,target:i,nextTarget:s},So(this,r));n&&this.fire(d,g),i.fire(c,g)}if(s&&f){const g=T(T({},a),{},{e:r,target:s,previousTarget:i},So(this,r));n&&this.fire(u,g),s.fire(h,g)}}__onMouseWheel(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()}_transformObject(t){const e=this.getScenePoint(t),s=this._currentTransform,i=s.target,n=i.group?Br(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,a=!!n&&n(t,e,s.x,s.y);a&&r.setCoords(),i==="drag"&&a&&(e.target.isMoving=!0,this.setCursor(e.target.moveCursor||this.moveCursor)),e.actionPerformed=e.actionPerformed||a}_setCursorFromEvent(t,e){if(!e)return void this.setCursor(this.defaultCursor);let s=e.hoverCursor||this.hoverCursor;const i=Nr(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=Nr(s);if(s&&this._isSelectionKeyPressed(t)&&this.selection&&e&&e.selectable&&(s!==e||i)&&(i||!e.isDescendantOf(s)&&!s.isDescendantOf(e))&&!e.onSelect({e:t})&&!s.getActiveControl()){if(i){const n=s.getObjects();if(e===s){const r=this.getViewportPoint(t);if(!(e=this.searchPossibleTargets(n,r)||this.searchPossibleTargets(this._objects,r))||!e.selectable)return!1}e.group===s?(s.remove(e),this._hoveredTarget=e,this._hoveredTargets=[...this.targets],s.size()===1&&this._setActiveObject(s.item(0),t)):(s.multiSelectAdd(e),this._hoveredTarget=s,this._hoveredTargets=[...this.targets]),this._fireSelectionEvents(n,t)}else{s.isEditing&&s.exitEditing();const n=new(W.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),a=r.add(new M(i,n)),h=r.min(a),c=r.max(a).subtract(h),u=this.collectObjects({left:h.x,top:h.y,width:c.x,height:c.y},{includeIntersecting:!this.selectionFullyContained}),d=r.eq(a)?u[0]?[u[0]]:[]:u.length>1?u.filter(f=>!f.onSelect({e:t})).reverse():u;if(d.length===1)this.setActiveObject(d[0],t);else if(d.length>1){const f=W.getClass("ActiveSelection");this.setActiveObject(new f(d,{canvas:this}),t)}return this._groupSelector=null,!0}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const ev={x1:0,y1:0,x2:0,y2:0},nx=T(T({},ev),{},{r1:0,r2:0}),Co=(o,t)=>isNaN(o)&&typeof t=="number"?t:o,rx=/^(\d+\.\d+)%|(\d+)%$/;function sv(o){return o&&rx.test(o)}function iv(o,t){const e=typeof o=="number"?o:typeof o=="string"?parseFloat(o)/(sv(o)?100:1):NaN;return Hr(0,Co(e,t),1)}const ax=/\s*;\s*/,ox=/\s*:\s*/;function hx(o,t){let e,s;const i=o.getAttribute("style");if(i){const r=i.split(ax);r[r.length-1]===""&&r.pop();for(let a=r.length;a--;){const[h,c]=r[a].split(ox).map(u=>u.trim());h==="stop-color"?e=c:h==="stop-opacity"&&(s=c)}}const n=new St(e||o.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:iv(o.getAttribute("offset"),0),color:n.toRgb(),opacity:Co(parseFloat(s||o.getAttribute("stop-opacity")||""),1)*n.getAlpha()*t}}function lx(o,t){const e=[],s=o.getElementsByTagName("stop"),i=iv(t,1);for(let n=s.length;n--;)e.push(hx(s[n],i));return e}function nv(o){return o.nodeName==="linearGradient"||o.nodeName==="LINEARGRADIENT"?"linear":"radial"}function rv(o){return o.getAttribute("gradientUnits")==="userSpaceOnUse"?"pixels":"percentage"}function si(o,t){return o.getAttribute(t)}function cx(o,t){return function(e,s){let i,{width:n,height:r,gradientUnits:a}=s;return Object.keys(e).reduce((h,c)=>{const u=e[c];return u==="Infinity"?i=1:u==="-Infinity"?i=0:(i=typeof u=="string"?parseFloat(u):u,typeof u=="string"&&sv(u)&&(i*=.01,a==="pixels"&&(c!=="x1"&&c!=="x2"&&c!=="r2"||(i*=n),c!=="y1"&&c!=="y2"||(i*=r)))),h[c]=i,h},{})}(nv(o)==="linear"?function(e){return{x1:si(e,"x1")||0,y1:si(e,"y1")||0,x2:si(e,"x2")||"100%",y2:si(e,"y2")||0}}(o):function(e){return{x1:si(e,"fx")||si(e,"cx")||"50%",y1:si(e,"fy")||si(e,"cy")||"50%",r1:0,x2:si(e,"cx")||"50%",y2:si(e,"cy")||"50%",r2:si(e,"r")||"50%"}}(o),T(T({},t),{},{gradientUnits:rv(o)}))}class nl{constructor(t){const{type:e="linear",gradientUnits:s="pixels",coords:i={},colorStops:n=[],offsetX:r=0,offsetY:a=0,gradientTransform:h,id:c}=t||{};Object.assign(this,{type:e,gradientUnits:s,coords:T(T({},e==="radial"?nx:ev),i),colorStops:n,offsetX:r,offsetY:a,gradientTransform:h,id:c?"".concat(c,"_").concat(Gn()):Gn()})}addColorStop(t){for(const e in t){const s=new St(t[e]);this.colorStops.push({offset:parseFloat(e),color:s.toRgb(),opacity:s.getAlpha()})}return this}toObject(t){return T(T({},jr(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():He.concat(),n=this.gradientUnits==="pixels"?"userSpaceOnUse":"objectBoundingBox",r=this.colorStops.map(d=>T({},d)).sort((d,f)=>d.offset-f.offset);let a=-this.offsetX,h=-this.offsetY;var c;n==="objectBoundingBox"?(a/=t.width,h/=t.height):(a+=t.width/2,h+=t.height/2),(c=t)&&typeof c._renderPathCommands=="function"&&this.gradientUnits!=="percentage"&&(a-=t.pathOffset.x,h-=t.pathOffset.y),i[4]-=a,i[5]-=h;const u=['id="SVGID_'.concat(this.id,'"'),'gradientUnits="'.concat(n,'"'),'gradientTransform="'.concat(e?e+" ":"").concat(mo(i),'"'),""].join(" ");if(this.type==="linear"){const{x1:d,y1:f,x2:g,y2:p}=this.coords;s.push("<linearGradient ",u,' x1="',d,'" y1="',f,'" x2="',g,'" y2="',p,`">
70
+ `),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=Lt(t,$w);return Promise.all([ma(i,e),Qh(r,e)]).then(o=>{let[h,c]=o;const u=new this(h,E(E(E({},r),c),{},{layoutManager:new qw}));if(n){const d=G.getClass(n.type),f=G.getClass(n.strategy);u.layoutManager=new d(new f)}else u.layoutManager=new al;return u.layoutManager.subscribeTargets({type:sn,target:u,targets:u.getObjects()}),u.setCoords(),u})}}k(Fs,"type","Group"),k(Fs,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),G.setClass(Fs);const Jv=(a,t)=>Math.min(t.width/a.width,t.height/a.height),Qv=(a,t)=>Math.max(t.width/a.width,t.height/a.height),pg="\\s*,?\\s*",hl="".concat(pg,"(").concat(Zs,")"),Kw="".concat(hl).concat(hl).concat(hl).concat(pg,"([01])").concat(pg,"([01])").concat(hl).concat(hl),Jw={m:"l",M:"L"},Qw=(a,t,e,s,i,n,r,o,h,c,u)=>{const d=qs(a),f=Ks(a),g=qs(t),p=Ks(t),m=e*i*g-s*n*p+r,y=s*i*g+e*n*p+o;return["C",c+h*(-e*i*f-s*n*d),u+h*(-s*i*f+e*n*d),m+h*(e*i*p+s*n*g),y+h*(s*i*p-e*n*g),m,y]},Zv=(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 mg(a,t,e,s,i,n,r,o){let h;if(mt.cachesBoundsOfCurve&&(h=[...arguments].join(),Yh.boundsOfCurveCache[h]))return Yh.boundsOfCurveCache[h];const c=Math.sqrt,u=Math.abs,d=[],f=[[0,0],[0,0]];let g=6*a-12*e+6*i,p=-3*a+9*e-9*i+3*r,m=3*e-3*a;for(let S=0;S<2;++S){if(S>0&&(g=6*t-12*s+6*n,p=-3*t+9*s-9*n+3*o,m=3*s-3*t),u(p)<1e-12){if(u(g)<1e-12)continue;const R=-m/g;0<R&&R<1&&d.push(R);continue}const T=g*g-4*m*p;if(T<0)continue;const P=c(T),M=(-g+P)/(2*p);0<M&&M<1&&d.push(M);const D=(-g-P)/(2*p);0<D&&D<1&&d.push(D)}let y=d.length;const b=y,x=e0(a,t,e,s,i,n,r,o);for(;y--;){const{x:S,y:T}=x(d[y]);f[0][y]=S,f[1][y]=T}f[0][b]=a,f[1][b]=t,f[0][b+1]=r,f[1][b+1]=o;const C=[new O(Math.min(...f[0]),Math.min(...f[1])),new O(Math.max(...f[0]),Math.max(...f[1]))];return mt.cachesBoundsOfCurve&&(Yh.boundsOfCurveCache[h]=C),C}const Zw=(a,t,e)=>{let[s,i,n,r,o,h,c,u]=e;const d=((f,g,p,m,y,b,x)=>{if(p===0||m===0)return[];let C=0,S=0,T=0;const P=Math.PI,M=x*Df,D=Ks(M),R=qs(M),V=.5*(-R*f-D*g),H=.5*(-R*g+D*f),F=p**2,I=m**2,j=H**2,K=V**2,L=F*I-F*j-I*K;let z=Math.abs(p),Z=Math.abs(m);if(L<0){const Te=Math.sqrt(1-L/(F*I));z*=Te,Z*=Te}else T=(y===b?-1:1)*Math.sqrt(L/(F*j+I*K));const Dt=T*z*H/Z,Bt=-T*Z*V/z,Xt=R*Dt-D*Bt+.5*f,Ft=D*Dt+R*Bt+.5*g;let _t=Zv(1,0,(V-Dt)/z,(H-Bt)/Z),oe=Zv((V-Dt)/z,(H-Bt)/Z,(-V-Dt)/z,(-H-Bt)/Z);b===0&&oe>0?oe-=2*P:b===1&&oe<0&&(oe+=2*P);const Ze=Math.ceil(Math.abs(oe/P*2)),it=[],nt=oe/Ze,Zt=8/3*Math.sin(nt/4)*Math.sin(nt/4)/Math.sin(nt/2);let Ys=_t+nt;for(let Te=0;Te<Ze;Te++)it[Te]=Qw(_t,Ys,R,D,z,Z,Xt,Ft,Zt,C,S),C=it[Te][5],S=it[Te][6],_t=Ys,Ys+=nt;return it})(c-a,u-t,i,n,o,h,r);for(let f=0,g=d.length;f<g;f++)d[f][1]+=a,d[f][2]+=t,d[f][3]+=a,d[f][4]+=t,d[f][5]+=a,d[f][6]+=t;return d},t0=a=>{let t=0,e=0,s=0,i=0;const n=[];let r,o=0,h=0;for(const c of a){const u=[...c];let d;switch(u[0]){case"l":u[1]+=t,u[2]+=e;case"L":t=u[1],e=u[2],d=["L",t,e];break;case"h":u[1]+=t;case"H":t=u[1],d=["L",t,e];break;case"v":u[1]+=e;case"V":e=u[1],d=["L",t,e];break;case"m":u[1]+=t,u[2]+=e;case"M":t=u[1],e=u[2],s=u[1],i=u[2],d=["M",t,e];break;case"c":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e,u[5]+=t,u[6]+=e;case"C":o=u[3],h=u[4],t=u[5],e=u[6],d=["C",u[1],u[2],o,h,t,e];break;case"s":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e;case"S":r==="C"?(o=2*t-o,h=2*e-h):(o=t,h=e),t=u[3],e=u[4],d=["C",o,h,u[1],u[2],t,e],o=d[3],h=d[4];break;case"q":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e;case"Q":o=u[1],h=u[2],t=u[3],e=u[4],d=["Q",o,h,t,e];break;case"t":u[1]+=t,u[2]+=e;case"T":r==="Q"?(o=2*t-o,h=2*e-h):(o=t,h=e),t=u[1],e=u[2],d=["Q",o,h,t,e];break;case"a":u[6]+=t,u[7]+=e;case"A":Zw(t,e,u).forEach(f=>n.push(f)),t=u[6],e=u[7];break;case"z":case"Z":t=s,e=i,d=["Z"]}d?(n.push(d),r=d[0]):r=""}return n},ju=(a,t,e,s)=>Math.sqrt((e-a)**2+(s-t)**2),e0=(a,t,e,s,i,n,r,o)=>h=>{const c=h**3,u=(g=>3*g**2*(1-g))(h),d=(g=>3*g*(1-g)**2)(h),f=(g=>(1-g)**3)(h);return new O(r*c+i*u+e*d+a*f,o*c+n*u+s*d+t*f)},s0=a=>a**2,i0=a=>2*a*(1-a),n0=a=>(1-a)**2,tx=(a,t,e,s,i,n,r,o)=>h=>{const c=s0(h),u=i0(h),d=n0(h),f=3*(d*(e-a)+u*(i-e)+c*(r-i)),g=3*(d*(s-t)+u*(n-s)+c*(o-n));return Math.atan2(g,f)},ex=(a,t,e,s,i,n)=>r=>{const o=s0(r),h=i0(r),c=n0(r);return new O(i*o+e*h+a*c,n*o+s*h+t*c)},sx=(a,t,e,s,i,n)=>r=>{const o=1-r,h=2*(o*(e-a)+r*(i-e)),c=2*(o*(s-t)+r*(n-s));return Math.atan2(c,h)},r0=(a,t,e)=>{let s=new O(t,e),i=0;for(let n=1;n<=100;n+=1){const r=a(n/100);i+=ju(s.x,s.y,r.x,r.y),s=r}return i},ix=(a,t)=>{let e,s=0,i=0,n={x:a.x,y:a.y},r=E({},n),o=.01,h=0;const c=a.iterator,u=a.angleFinder;for(;i<t&&o>1e-4;)r=c(s),h=s,e=ju(n.x,n.y,r.x,r.y),e+i>t?(s-=o,o/=2):(n=r,s+=o,i+=e);return E(E({},r),{},{angle:u(h)})},vg=a=>{let t,e,s=0,i=0,n=0,r=0,o=0;const h=[];for(const c of a){const u={x:i,y:n,command:c[0],length:0};switch(c[0]){case"M":e=u,e.x=r=i=c[1],e.y=o=n=c[2];break;case"L":e=u,e.length=ju(i,n,c[1],c[2]),i=c[1],n=c[2];break;case"C":t=e0(i,n,c[1],c[2],c[3],c[4],c[5],c[6]),e=u,e.iterator=t,e.angleFinder=tx(i,n,c[1],c[2],c[3],c[4],c[5],c[6]),e.length=r0(t,i,n),i=c[5],n=c[6];break;case"Q":t=ex(i,n,c[1],c[2],c[3],c[4]),e=u,e.iterator=t,e.angleFinder=sx(i,n,c[1],c[2],c[3],c[4]),e.length=r0(t,i,n),i=c[3],n=c[4];break;case"Z":e=u,e.destX=r,e.destY=o,e.length=ju(i,n,r,o),i=r,n=o}s+=e.length,h.push(e)}return h.push({length:s,x:i,y:n}),h},o0=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:vg(a),s=0;for(;t-e[s].length>0&&s<e.length-2;)t-=e[s].length,s++;const i=e[s],n=t/i.length,r=a[s];switch(i.command){case"M":return{x:i.x,y:i.y,angle:0};case"Z":return E(E({},new O(i.x,i.y).lerp(new O(i.destX,i.destY),n)),{},{angle:Math.atan2(i.destY-i.y,i.destX-i.x)});case"L":return E(E({},new O(i.x,i.y).lerp(new O(r[1],r[2]),n)),{},{angle:Math.atan2(r[2]-i.y,r[1]-i.x)});case"C":case"Q":return ix(i,t)}},nx=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),a0=new RegExp(Kw,"g"),rx=new RegExp(Zs,"gi"),ox={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},h0=a=>{var t;const e=[],s=(t=a.match(nx))!==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=ox[n.toLowerCase()];let o=[];if(n==="a"||n==="A"){a0.lastIndex=0;for(let h=null;h=a0.exec(i);)o.push(...h.slice(1))}else o=i.match(rx)||[];for(let h=0;h<o.length;h+=r){const c=new Array(r),u=Jw[n];c[0]=h>0&&u?u:n;for(let d=0;d<r;d++)c[d+1]=parseFloat(o[h+d]);e.push(c)}}return e},ax=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=new O(a[0]),s=new O(a[1]),i=1,n=0;const r=[],o=a.length,h=o>2;let c;for(h&&(i=a[2].x<s.x?-1:a[2].x===s.x?0:1,n=a[2].y<s.y?-1:a[2].y===s.y?0:1),r.push(["M",e.x-i*t,e.y-n*t]),c=1;c<o;c++){if(!e.eq(s)){const u=e.midPointFrom(s);r.push(["Q",e.x,e.y,u.x,u.y])}e=a[c],c+1<a.length&&(s=a[c+1])}return h&&(i=e.x>a[c-2].x?1:e.x===a[c-2].x?0:-1,n=e.y>a[c-2].y?1:e.y===a[c-2].y?0:-1),r.push(["L",e.x+i*t,e.y+n*t]),r},l0=(a,t)=>a.map(e=>e.map((s,i)=>i===0||t===void 0?s:kt(s,t)).join(" ")).join(" ");function Nu(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 hx=(a,t)=>Math.floor(Math.random()*(t-a+1))+a;function c0(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const e=t.onComplete||Rr,s=new(Uh()).XMLHttpRequest,i=t.signal,n=function(){s.abort()},r=function(){i&&i.removeEventListener("abort",n),s.onerror=s.ontimeout=Rr};if(i&&i.aborted)throw new Mf("request");return i&&i.addEventListener("abort",n,{once:!0}),s.onreadystatechange=function(){s.readyState===4&&(r(),e(s),s.onreadystatechange=Rr)},s.onerror=s.ontimeout=r,s.open("get",a,!0),s.send(),s}const Bu=(a,t)=>{let e=a._findCenterFromElement();a.transformMatrix&&((s=>{if(s.transformMatrix){const{scaleX:i,scaleY:n,angle:r,skewX:o}=Lr(s.transformMatrix);s.flipX=!1,s.flipY=!1,s.set(Ve,i),s.set(gs,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,rt,rt)};var lx=Object.freeze({__proto__:null,addTransformToObject:$m,animate:ag,animateColor:Cv,applyTransformToObject:ba,calcAngleBetweenVectors:Tu,calcDimensionsMatrix:Kh,calcPlaneChangeMatrix:tl,calcVectorRotation:vv,cancelAnimFrame:Rm,capValue:zr,composeMatrix:Nm,copyCanvasElement:a=>{var t;const e=ps(a);return(t=e.getContext("2d"))===null||t===void 0||t.drawImage(a,0,0),e},cos:qs,createCanvasElement:Si,createImage:Fm,createRotateMatrix:Ir,createScaleMatrix:vu,createSkewXMatrix:zf,createSkewYMatrix:Vf,createTranslateMatrix:pa,createVector:Cu,crossProduct:ya,degreesToRadians:Ut,dotProduct:bv,ease:K_,enlivenObjectEnlivables:Qh,enlivenObjects:ma,findScaleToCover:Qv,findScaleToFit:Jv,getBoundsOfCurve:mg,getOrthonormalVector:eg,getPathSegmentsInfo:vg,getPointOnPath:o0,getPointer:Um,getRandomInt:hx,getRegularPolygonPath:(a,t)=>{const e=2*Math.PI/a;let s=-Vn;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 O(qs(r),Ks(r)).scalarMultiply(t);i[n]=[n===0?"M":"L",o,h]}return i[a]=["Z"],i},getSmoothPathFromPoints:ax,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:Eu,groupSVGElements:(a,t)=>a&&a.length===1?a[0]:new Fs(a,t),hasStyleChanged:Du,invertTransform:ns,isBetweenVectors:sg,isIdentityMatrix:Lm,isTouchEvent:bu,isTransparent:Rv,joinPath:l0,loadImage:Jh,magnitude:Au,makeBoundingBoxFromPoints:Ai,makePathSimpler:t0,matrixToSVG:va,mergeClipPaths:(a,t)=>{var e;let s=a,i=t;s.inverted&&!i.inverted&&(s=t,i=a),Uf(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 Fs([s],{clipPath:i,inverted:n})},multiplyTransformMatrices:qt,multiplyTransformMatrixArray:mu,parsePath:h0,parsePreserveAspectRatioAttribute:qf,parseUnit:We,pick:jr,projectStrokeOnPoints:Iv,qrDecompose:Lr,radiansToDegrees:Ci,removeFromArray:Fr,removeTransformFromObject:(a,t)=>{const e=ns(t),s=qt(e,a.calcOwnMatrix());ba(a,s)},removeTransformMatrixForSvgParsing:Bu,request:c0,requestAnimFrame:qh,resetObjectTransform:qm,rotatePoint:(a,t,e)=>a.rotate(e,t),rotateVector:tg,saveObjectTransform:Xf,sendObjectToPlane:Uf,sendPointToPlane:Br,sendVectorToPlane:Km,setStyle:Nu,sin:Ks,sizeAfterTransform:yu,string:Aw,stylesFromArray:Bv,stylesToArray:Nv,toBlob:Hf,toDataURL:Bf,toFixed:kt,transformPath:(a,t,e)=>(e&&(t=qt(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}=Ee({x:s[n],y:s[n+1]},t);i[n]=r,i[n+1]=o}return i})),transformPoint:Ee});class cx extends Xm{constructor(t){let{allowTouchScrolling:e=!1,containerClass:s=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(t),k(this,"upper",void 0),k(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=Si();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=ua().createElement("div");return t.setAttribute("data-fabric","wrapper"),Nu(t,{position:"relative"}),Wm(t),t}applyCanvasStyle(t,e){const{styles:s,allowTouchScrolling:i}=e;Nu(t,E(E({},s),{},{"touch-action":i?"manipulation":ze})),Wm(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:s,ctx:i}=this.upper;Gm(s,i,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),Wf(this.upper.el,t),Wf(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(),xi().dispose(this.upper.el),delete this.upper,delete this.container}}class Hu extends Zh{constructor(){super(...arguments),k(this,"targets",[]),k(this,"_hoveredTargets",[]),k(this,"_objectsToRender",void 0),k(this,"_currentTransform",null),k(this,"_groupSelector",null),k(this,"contextTopDirty",!1)}static getDefaults(){return E(E({},super.getDefaults()),Hu.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 cx(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 Rv(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===du||e===Ve||e===gs||e===$h?i=this.centeredScaling||t.centeredScaling:e===If&&(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=$t:["mr","tr","br"].includes(e)&&(s.x=wt),["tl","mt","tr"].includes(e)?s.y=Ff:["bl","mb","br"].includes(e)&&(s.y=is)),s}_setupCurrentTransform(t,e,s){var i;const n=e.group?Br(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):H_,c=((g,p,m,y)=>{if(!p||!g)return"drag";const b=y.controls[p];return b.getActionName(m,b,y)})(s,r,t,e),u=t[this.centeredKey],d=this._shouldCenterTransform(e,c,u)?{x:rt,y:rt}:this._getOriginFromCorner(e,r),f={target:e,action:c,actionHandler:h,actionPerformed:!1,corner:r,scaleX:e.scaleX,scaleY:e.scaleY,skewX:e.skewX,skewY:e.skewY,offsetX:n.x-e.left,offsetY:n.y-e.top,originX:d.x,originY:d.y,ex:n.x,ey:n.y,lastX:n.x,lastY:n.y,theta:Ut(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:u,original:E(E({},Xf(e)),{},{originX:d.x,originY:d.y})};this._currentTransform=f,this.fire("before:transform",{e:t,transform:f})}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new O(e,s).transform(this.viewportTransform),o=new O(e+i,s+n).transform(this.viewportTransform),h=this.selectionLineWidth/2;let c=Math.min(r.x,o.x),u=Math.min(r.y,o.y),d=Math.max(r.x,o.x),f=Math.max(r.y,o.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(c,u,d-c,f-u)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,c+=h,u+=h,d-=h,f-=h,ke.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(c,u,d-c,f-u))}findTarget(t){if(this.skipTargetFind)return;const e=this.getViewportPoint(t),s=this._activeObject,i=this.getActiveObjects();if(this.targets=[],s&&i.length>=1){if(s.findControl(e,bu(t))||i.length>1&&this.searchPossibleTargets([s],e))return s;if(s===this.searchPossibleTargets([s],e)){if(this.preserveObjectStacking){const n=this.targets;this.targets=[];const r=this.searchPossibleTargets(this._objects,e);return t[this.altSelectionKey]&&r&&r!==s?(this.targets=n,s):r}return s}}return this.searchPossibleTargets(this._objects,e)}_pointIsInObjectSelectionArea(t,e){let s=t.getCoords();const i=this.getZoom(),n=t.padding/i;if(n){const[r,o,h,c]=s,u=Math.atan2(o.y-r.y,o.x-r.x),d=qs(u)*n,f=Ks(u)*n,g=d+f,p=d-f;s=[new O(r.x-p,r.y-g),new O(o.x+g,o.y-p),new O(h.x+p,h.y+g),new O(c.x-g,c.y+p)]}return zt.isPointInPolygon(e,s)}_checkTarget(t,e){return!!(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,Br(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(pu(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&&pu(s)&&s.interactive&&this.targets[0]){const i=this.targets;for(let n=i.length-1;n>0;n--){const r=i[n];if(!pu(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=Um(t),r=i.width||0,o=i.height||0;r&&o||(is in i&&Ff in i&&(o=Math.abs(i.top-i.bottom)),$t in i&&wt 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=Br(n,void 0,this.viewportTransform));const h=this.getRetinaScaling();h!==1&&(n.x/=h,n.y/=h);const c=r===0||o===0?new O(1,1):new O(s.width/r,s.height/o);return n.multiply(c)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=Si(),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 Nr(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,Nr(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),Nr(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(fu,i))}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeObject;Nr(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&&Nr(e)&&this._activeObject===e){const s=jr(t,["angle","flipX","flipY",wt,Ve,gs,da,fa,is]);return $m(t,e.calcOwnMatrix()),s}return{}}_setSVGObject(t,e,s){const i=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,s),e.set(i)}}k(Hu,"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 ux{constructor(t){k(this,"targets",[]),k(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),Fr(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 dx=["target","oldTarget","fireCanvas","e"],ms={passive:!1},Ca=(a,t)=>{const e=a.getViewportPoint(t),s=a.getScenePoint(t);return{viewportPoint:e,scenePoint:s,pointer:e,absolutePointer:s}},Un=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)},Ls=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)},fx={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 bg extends Hu{constructor(t){super(t,arguments.length>1&&arguments[1]!==void 0?arguments[1]:{}),k(this,"_isClick",void 0),k(this,"textEditingManager",new ux(this)),["_onMouseDown","_onTouchStart","_onMouseMove","_onMouseUp","_onTouchEnd","_onResize","_onMouseWheel","_onMouseOut","_onMouseEnter","_onContextMenu","_onClick","_onDragStart","_onDragEnd","_onDragProgress","_onDragOver","_onDragEnter","_onDragLeave","_onDrop"].forEach(e=>{this[e]=this[e].bind(this)}),this.addOrRemove(Un,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const s=this.upperCanvasEl,i=this._getEventPrefix();t(Vm(s),"resize",this._onResize),t(s,i+"down",this._onMouseDown),t(s,"".concat(i,"move"),this._onMouseMove,ms),t(s,"".concat(i,"out"),this._onMouseOut),t(s,"".concat(i,"enter"),this._onMouseEnter),t(s,"wheel",this._onMouseWheel),t(s,"contextmenu",this._onContextMenu),t(s,"click",this._onClick),t(s,"dblclick",this._onClick),t(s,"dragstart",this._onDragStart),t(s,"dragend",this._onDragEnd),t(s,"dragover",this._onDragOver),t(s,"dragenter",this._onDragEnter),t(s,"dragleave",this._onDragLeave),t(s,"drop",this._onDrop),this.enablePointerEvents||t(s,"touchstart",this._onTouchStart,ms)}removeListeners(){this.addOrRemove(Ls,"remove");const t=this._getEventPrefix(),e=Js(this.upperCanvasEl);Ls(e,"".concat(t,"up"),this._onMouseUp),Ls(e,"touchend",this._onTouchEnd,ms),Ls(e,"".concat(t,"move"),this._onMouseMove,ms),Ls(e,"touchmove",this._onMouseMove,ms),clearTimeout(this._willAddMouseDown)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s=E({e:t},Ca(this,t));this.fire("mouse:out",E(E({},s),{},{target:e})),this._hoveredTarget=void 0,e&&e.fire("mouseout",E({},s)),this._hoveredTargets.forEach(i=>{this.fire("mouse:out",E(E({},s),{},{target:i})),i&&i.fire("mouseout",E({},s))}),this._hoveredTargets=[]}_onMouseEnter(t){this._currentTransform||this.findTarget(t)||(this.fire("mouse:over",E({e:t},Ca(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 Un(this.upperCanvasEl,"drag",this._onDragProgress)}Ym(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!==ze,s=e?this._activeObject:void 0,i={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:s};Ls(this.upperCanvasEl,"drag",this._onDragProgress),this.fire("dragend",i),this._dragSource&&this._dragSource.fire("dragend",i),delete this._dragSource,this._onMouseUp(t)}_onDragProgress(t){const e={e:t,target:this._dragSource,dragSource:this._dragSource,dropTarget:this._draggedoverTarget};this.fire("drag",e),this._dragSource&&this._dragSource.fire("drag",e)}findDragTargets(t){return this.targets=[],{target:this._searchPossibleTargets(this._objects,this.getViewportPoint(t)),targets:[...this.targets]}}_onDragOver(t){const e="dragover",{target:s,targets:i}=this.findDragTargets(t),n=this._dragSource,r={e:t,target:s,subTargets:i,dragSource:n,canDrop:!1,dropTarget:void 0};let o;this.fire(e,r),this._fireEnterLeaveEvents(s,r),s&&(s.canDrop(t)&&(o=s),s.fire(e,r));for(let h=0;h<i.length;h++){const c=i[h];c.canDrop(t)&&(o=c),c.fire(e,r)}this._renderDragEffects(t,n,o),this._dropTarget=o}_onDragEnter(t){const{target:e,targets:s}=this.findDragTargets(t),i={e:t,target:e,subTargets:s,dragSource:this._dragSource};this.fire("dragenter",i),this._fireEnterLeaveEvents(e,i)}_onDragLeave(t){const e={e:t,target:this._draggedoverTarget,subTargets:this.targets,dragSource:this._dragSource};this.fire("dragleave",e),this._fireEnterLeaveEvents(void 0,e),this._renderDragEffects(t,this._dragSource),this._dropTarget=void 0,this.targets=[],this._hoveredTargets=[]}_onDrop(t){const{target:e,targets:s}=this.findDragTargets(t),i=this._basicEventHandler("drop:before",E({e:t,target:e,subTargets:s,dragSource:this._dragSource},Ca(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&&Ym(t),this._basicEventHandler("contextmenu",i),!1}_onClick(t){const e=t.detail;e>3||e<2||(this._cacheTransformEventData(t),e==2&&t.type==="dblclick"&&this._handleEvent(t,"dblclick"),e==3&&this._handleEvent(t,"tripleclick"),this._resetTransformEventData())}getPointerId(t){const e=t.changedTouches;return e?e[0]&&e[0].identifier:this.enablePointerEvents?t.pointerId:-1}_isMainEvent(t){return t.isPrimary===!0||t.isPrimary!==!1&&(t.type==="touchend"&&t.touches.length===0||!t.changedTouches||t.changedTouches[0].identifier===this.mainTouchId)}_onTouchStart(t){let e=!this.allowTouchScrolling;const s=this._activeObject;this.mainTouchId===void 0&&(this.mainTouchId=this.getPointerId(t)),this.__onMouseDown(t),(this.isDrawingMode||s&&this._target===s)&&(e=!0),e&&t.preventDefault(),this._resetTransformEventData();const i=this.upperCanvasEl,n=this._getEventPrefix(),r=Js(i);Un(r,"touchend",this._onTouchEnd,ms),e&&Un(r,"touchmove",this._onMouseMove,ms),Ls(i,"".concat(n,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();Ls(e,"".concat(s,"move"),this._onMouseMove,ms);const i=Js(e);Un(i,"".concat(s,"up"),this._onMouseUp),Un(i,"".concat(s,"move"),this._onMouseMove,ms)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),s=Js(this.upperCanvasEl);Ls(s,"touchend",this._onTouchEnd,ms),Ls(s,"touchmove",this._onMouseMove,ms),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout(()=>{Un(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=Js(this.upperCanvasEl);Ls(i,"".concat(s,"up"),this._onMouseUp),Ls(i,"".concat(s,"move"),this._onMouseMove,ms),Un(e,"".concat(s,"move"),this._onMouseMove,ms)}}_onMouseMove(t){const e=this.getActiveObject();!this.allowTouchScrolling&&(!e||!e.shouldStartDragging(t))&&t.preventDefault&&t.preventDefault(),this.__onMouseMove(t)}_onResize(){this.calcOffset(),this._resetTransformEventData()}_shouldRender(t){const e=this.getActiveObject();return!!e!=!!t||e&&t&&e!==t}__onMouseUp(t){var e;this._cacheTransformEventData(t),this._handleEvent(t,"up:before");const s=this._currentTransform,i=this._isClick,n=this._target,{button:r}=t;if(r)return(this.fireMiddleClick&&r===1||this.fireRightClick&&r===2)&&this._handleEvent(t,"up"),void this._resetTransformEventData();if(this.isDrawingMode&&this._isCurrentlyDrawing)return void this._onMouseUpInDrawingMode(t);if(!this._isMainEvent(t))return;let o,h,c=!1;if(s&&(this._finalizeCurrentTransform(t),c=s.actionPerformed),!i){const u=n===this._activeObject;this.handleSelection(t),c||(c=this._shouldRender(n)||!u&&n===this._activeObject)}if(n){const u=n.findControl(this.getViewportPoint(t),bu(t)),{key:d,control:f}=u||{};if(h=d,n.selectable&&n!==this._activeObject&&n.activeOn==="up")this.setActiveObject(n,t),c=!0;else if(f){const g=f.getMouseUpHandler(t,n,f);g&&(o=this.getScenePoint(t),g.call(f,t,s,o.x,o.y))}n.isMoving=!1}if(s&&(s.target!==n||s.corner!==h)){const u=s.target&&s.target.controls[s.corner],d=u&&u.getMouseUpHandler(t,s.target,u);o=o||this.getScenePoint(t),d&&d.call(u,t,s,o.x,o.y)}this._setCursorFromEvent(t,n),this._handleEvent(t,"up"),this._groupSelector=null,this._currentTransform=null,n&&(n.__corner=void 0),c?this.requestRenderAll():i||(e=this._activeObject)!==null&&e!==void 0&&e.isEditing||this.renderTop()}_basicEventHandler(t,e){const{target:s,subTargets:i=[]}=e;this.fire(t,e),s&&s.fire(t,e);for(let n=0;n<i.length;n++)i[n]!==s&&i[n].fire(t,e);return e}_handleEvent(t,e,s){const i=this._target,n=this.targets||[],r=E(E(E({e:t,target:i,subTargets:n},Ca(this,t)),{},{transform:this._currentTransform},e==="up:before"||e==="up"?{isClick:this._isClick,currentTarget:this.findTarget(t),currentSubTargets:this.targets}:{}),e==="down:before"||e==="down"?s:{});this.fire("mouse:".concat(e),r),i&&i.fire("mouse".concat(e),r);for(let o=0;o<n.length;o++)n[o]!==i&&n[o].fire("mouse".concat(e),r)}_onMouseDownInDrawingMode(t){this._isCurrentlyDrawing=!0,this.getActiveObject()&&(this.discardActiveObject(t),this.requestRenderAll());const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseDown(e,{e:t,pointer:e}),this._handleEvent(t,"down",{alreadySelected:!1})}_onMouseMoveInDrawingMode(t){if(this._isCurrentlyDrawing){const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseMove(e,{e:t,pointer:e})}this.setCursor(this.freeDrawingCursor),this._handleEvent(t,"move")}_onMouseUpInDrawingMode(t){const e=this.getScenePoint(t);this.freeDrawingBrush?this._isCurrentlyDrawing=!!this.freeDrawingBrush.onMouseUp({e:t,pointer:e}):this._isCurrentlyDrawing=!1,this._handleEvent(t,"up")}__onMouseDown(t){this._isClick=!0,this._cacheTransformEventData(t),this._handleEvent(t,"down:before");let e=this._target,s=!!e&&e===this._activeObject;const{button:i}=t;if(i)return(this.fireMiddleClick&&i===1||this.fireRightClick&&i===2)&&this._handleEvent(t,"down",{alreadySelected:s}),void this._resetTransformEventData();if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t)||this._currentTransform)return;let n=this._shouldRender(e),r=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,r=!0,n=!0):this._shouldClearSelection(t,e)&&this.discardActiveObject(t),this.selection&&(!e||!e.selectable&&!e.isEditing&&e!==this._activeObject)){const o=this.getScenePoint(t);this._groupSelector={x:o.x,y:o.y,deltaY:0,deltaX:0}}if(s=!!e&&e===this._activeObject,e){e.selectable&&e.activeOn==="down"&&this.setActiveObject(e,t);const o=e.findControl(this.getViewportPoint(t),bu(t));if(e===this._activeObject&&(o||!r)){this._setupCurrentTransform(t,e,s);const h=o?o.control:void 0,c=this.getScenePoint(t),u=h&&h.getMouseDownHandler(t,e,h);u&&u.call(h,t,this._currentTransform,c.x,c.y)}}n&&(this._objectsToRender=void 0),this._handleEvent(t,"down",{alreadySelected:s}),n&&this.requestRenderAll()}_resetTransformEventData(){this._target=this._pointer=this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getViewportPoint(t),this._absolutePointer=Br(this._pointer,void 0,this.viewportTransform),this._target=this._currentTransform?this._currentTransform.target:this.findTarget(t)}__onMouseMove(t){if(this._isClick=!1,this._cacheTransformEventData(t),this._handleEvent(t,"move:before"),this.isDrawingMode)return void this._onMouseMoveInDrawingMode(t);if(!this._isMainEvent(t))return;const e=this._groupSelector;if(e){const s=this.getScenePoint(t);e.deltaX=s.x-e.x,e.deltaY=s.y-e.y,this.renderTop()}else if(this._currentTransform)this._transformObject(t);else{const s=this.findTarget(t);this._setCursorFromEvent(t,s),this._fireOverOutEvents(t,s)}this.textEditingManager.onMouseMove(t),this._handleEvent(t,"move"),this._resetTransformEventData()}_fireOverOutEvents(t,e){const s=this._hoveredTarget,i=this._hoveredTargets,n=this.targets,r=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("mouse",{e:t,target:e,oldTarget:s,fireCanvas:!0});for(let o=0;o<r;o++)this.fireSyntheticInOutEvents("mouse",{e:t,target:n[o],oldTarget:i[o]});this._hoveredTarget=e,this._hoveredTargets=this.targets.concat()}_fireEnterLeaveEvents(t,e){const s=this._draggedoverTarget,i=this._hoveredTargets,n=this.targets,r=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("drag",E(E({},e),{},{target:t,oldTarget:s,fireCanvas:!0}));for(let o=0;o<r;o++)this.fireSyntheticInOutEvents("drag",E(E({},e),{},{target:n[o],oldTarget:i[o]}));this._draggedoverTarget=t}fireSyntheticInOutEvents(t,e){let{target:s,oldTarget:i,fireCanvas:n,e:r}=e,o=Lt(e,dx);const{targetIn:h,targetOut:c,canvasIn:u,canvasOut:d}=fx[t],f=i!==s;if(i&&f){const g=E(E({},o),{},{e:r,target:i,nextTarget:s},Ca(this,r));n&&this.fire(d,g),i.fire(c,g)}if(s&&f){const g=E(E({},o),{},{e:r,target:s,previousTarget:i},Ca(this,r));n&&this.fire(u,g),s.fire(h,g)}}__onMouseWheel(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()}_transformObject(t){const e=this.getScenePoint(t),s=this._currentTransform,i=s.target,n=i.group?Br(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=Nr(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=Nr(s);if(s&&this._isSelectionKeyPressed(t)&&this.selection&&e&&e.selectable&&(s!==e||i)&&(i||!e.isDescendantOf(s)&&!s.isDescendantOf(e))&&!e.onSelect({e:t})&&!s.getActiveControl()){if(i){const n=s.getObjects();if(e===s){const r=this.getViewportPoint(t);if(!(e=this.searchPossibleTargets(n,r)||this.searchPossibleTargets(this._objects,r))||!e.selectable)return!1}e.group===s?(s.remove(e),this._hoveredTarget=e,this._hoveredTargets=[...this.targets],s.size()===1&&this._setActiveObject(s.item(0),t)):(s.multiSelectAdd(e),this._hoveredTarget=s,this._hoveredTargets=[...this.targets]),this._fireSelectionEvents(n,t)}else{s.isEditing&&s.exitEditing();const n=new(G.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 O(e,s),o=r.add(new O(i,n)),h=r.min(o),c=r.max(o).subtract(h),u=this.collectObjects({left:h.x,top:h.y,width:c.x,height:c.y},{includeIntersecting:!this.selectionFullyContained}),d=r.eq(o)?u[0]?[u[0]]:[]:u.length>1?u.filter(f=>!f.onSelect({e:t})).reverse():u;if(d.length===1)this.setActiveObject(d[0],t);else if(d.length>1){const f=G.getClass("ActiveSelection");this.setActiveObject(new f(d,{canvas:this}),t)}return this._groupSelector=null,!0}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const u0={x1:0,y1:0,x2:0,y2:0},gx=E(E({},u0),{},{r1:0,r2:0}),Aa=(a,t)=>isNaN(a)&&typeof t=="number"?t:a,px=/^(\d+\.\d+)%|(\d+)%$/;function d0(a){return a&&px.test(a)}function f0(a,t){const e=typeof a=="number"?a:typeof a=="string"?parseFloat(a)/(d0(a)?100:1):NaN;return zr(0,Aa(e,t),1)}const mx=/\s*;\s*/,vx=/\s*:\s*/;function bx(a,t){let e,s;const i=a.getAttribute("style");if(i){const r=i.split(mx);r[r.length-1]===""&&r.pop();for(let o=r.length;o--;){const[h,c]=r[o].split(vx).map(u=>u.trim());h==="stop-color"?e=c:h==="stop-opacity"&&(s=c)}}const n=new St(e||a.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:f0(a.getAttribute("offset"),0),color:n.toRgb(),opacity:Aa(parseFloat(s||a.getAttribute("stop-opacity")||""),1)*n.getAlpha()*t}}function yx(a,t){const e=[],s=a.getElementsByTagName("stop"),i=f0(t,1);for(let n=s.length;n--;)e.push(bx(s[n],i));return e}function g0(a){return a.nodeName==="linearGradient"||a.nodeName==="LINEARGRADIENT"?"linear":"radial"}function p0(a){return a.getAttribute("gradientUnits")==="userSpaceOnUse"?"pixels":"percentage"}function ei(a,t){return a.getAttribute(t)}function _x(a,t){return function(e,s){let i,{width:n,height:r,gradientUnits:o}=s;return Object.keys(e).reduce((h,c)=>{const u=e[c];return u==="Infinity"?i=1:u==="-Infinity"?i=0:(i=typeof u=="string"?parseFloat(u):u,typeof u=="string"&&d0(u)&&(i*=.01,o==="pixels"&&(c!=="x1"&&c!=="x2"&&c!=="r2"||(i*=n),c!=="y1"&&c!=="y2"||(i*=r)))),h[c]=i,h},{})}(g0(a)==="linear"?function(e){return{x1:ei(e,"x1")||0,y1:ei(e,"y1")||0,x2:ei(e,"x2")||"100%",y2:ei(e,"y2")||0}}(a):function(e){return{x1:ei(e,"fx")||ei(e,"cx")||"50%",y1:ei(e,"fy")||ei(e,"cy")||"50%",r1:0,x2:ei(e,"cx")||"50%",y2:ei(e,"cy")||"50%",r2:ei(e,"r")||"50%"}}(a),E(E({},t),{},{gradientUnits:p0(a)}))}class ll{constructor(t){const{type:e="linear",gradientUnits:s="pixels",coords:i={},colorStops:n=[],offsetX:r=0,offsetY:o=0,gradientTransform:h,id:c}=t||{};Object.assign(this,{type:e,gradientUnits:s,coords:E(E({},e==="radial"?gx:u0),i),colorStops:n,offsetX:r,offsetY:o,gradientTransform:h,id:c?"".concat(c,"_").concat(Wn()):Wn()})}addColorStop(t){for(const e in t){const s=new St(t[e]);this.colorStops.push({offset:parseFloat(e),color:s.toRgb(),opacity:s.getAlpha()})}return this}toObject(t){return E(E({},jr(this,t)),{},{type:this.type,coords:E({},this.coords),colorStops:this.colorStops.map(e=>E({},e)),offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?[...this.gradientTransform]:void 0})}toSVG(t){let{additionalTransform:e}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const s=[],i=this.gradientTransform?this.gradientTransform.concat():He.concat(),n=this.gradientUnits==="pixels"?"userSpaceOnUse":"objectBoundingBox",r=this.colorStops.map(d=>E({},d)).sort((d,f)=>d.offset-f.offset);let o=-this.offsetX,h=-this.offsetY;var c;n==="objectBoundingBox"?(o/=t.width,h/=t.height):(o+=t.width/2,h+=t.height/2),(c=t)&&typeof c._renderPathCommands=="function"&&this.gradientUnits!=="percentage"&&(o-=t.pathOffset.x,h-=t.pathOffset.y),i[4]-=o,i[5]-=h;const u=['id="SVGID_'.concat(this.id,'"'),'gradientUnits="'.concat(n,'"'),'gradientTransform="'.concat(e?e+" ":"").concat(va(i),'"'),""].join(" ");if(this.type==="linear"){const{x1:d,y1:f,x2:g,y2:p}=this.coords;s.push("<linearGradient ",u,' x1="',d,'" y1="',f,'" x2="',g,'" y2="',p,`">
71
71
  `)}else if(this.type==="radial"){const{x1:d,y1:f,x2:g,y2:p,r1:m,r2:y}=this.coords,b=m>y;s.push("<radialGradient ",u,' cx="',b?d:g,'" cy="',b?f:p,'" r="',b?m:y,'" fx="',b?g:d,'" fy="',b?p:f,`">
72
- `),b&&(r.reverse(),r.forEach(S=>{S.offset=1-S.offset}));const x=Math.min(m,y);if(x>0){const S=x/Math.max(m,y);r.forEach(C=>{C.offset+=S*(1-C.offset)})}}return r.forEach(d=>{let{color:f,offset:g,opacity:p}=d;s.push("<stop ",'offset="',100*g+"%",'" style="stop-color:',f,p!==void 0?";stop-opacity: "+p:";",`"/>
72
+ `),b&&(r.reverse(),r.forEach(C=>{C.offset=1-C.offset}));const x=Math.min(m,y);if(x>0){const C=x/Math.max(m,y);r.forEach(S=>{S.offset+=C*(1-S.offset)})}}return r.forEach(d=>{let{color:f,offset:g,opacity:p}=d;s.push("<stop ",'offset="',100*g+"%",'" style="stop-color:',f,p!==void 0?";stop-opacity: "+p:";",`"/>
73
73
  `)}),s.push(this.type==="linear"?"</linearGradient>":"</radialGradient>",`
74
- `),s.join("")}toLive(t){const{x1:e,y1:s,x2:i,y2:n,r1:r,r2:a}=this.coords,h=this.type==="linear"?t.createLinearGradient(e,s,i,n):t.createRadialGradient(e,s,r,i,n,a);return this.colorStops.forEach(c=>{let{color:u,opacity:d,offset:f}=c;h.addColorStop(f,d!==void 0?new St(u).setAlpha(d).toRgba():u)}),h}static async fromObject(t){const{colorStops:e,gradientTransform:s}=t;return new this(T(T({},t),{},{colorStops:e?e.map(i=>T({},i)):void 0,gradientTransform:s?[...s]:void 0}))}static fromElement(t,e,s){const i=rv(t),n=e._findCenterFromElement();return new this(T({id:t.getAttribute("id")||void 0,type:nv(t),coords:cx(t,{width:s.viewBoxWidth||s.width,height:s.viewBoxHeight||s.height}),colorStops:lx(t,s.opacity),gradientUnits:i,gradientTransform:Mu(t.getAttribute("gradientTransform")||"")},i==="pixels"?{offsetX:e.width/2-n.x,offsetY:e.height/2-n.y}:{offsetX:0,offsetY:0}))}}E(nl,"type","Gradient"),W.setClass(nl,"gradient"),W.setClass(nl,"linear"),W.setClass(nl,"radial");const ux=["type","source","patternTransform"];class mg{get type(){return"pattern"}set type(t){$i("warn","Setting type has no effect",t)}constructor(t){E(this,"repeat","repeat"),E(this,"offsetX",0),E(this,"offsetY",0),E(this,"crossOrigin",""),this.id=Gn(),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({},jr(this,t)),{},{type:"pattern",source:this.sourceToString(),repeat:e,crossOrigin:s,offsetX:Dt(this.offsetX,bt.NUM_FRACTION_DIGITS),offsetY:Dt(this.offsetY,bt.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,a=Co(this.offsetX/e,0),h=Co(this.offsetY/s,0),c=n==="repeat-y"||n==="no-repeat"?1+Math.abs(a||0):Co(i.width/e,0),u=n==="repeat-x"||n==="no-repeat"?1+Math.abs(h||0):Co(i.height/s,0);return['<pattern id="SVGID_'.concat(r,'" x="').concat(a,'" y="').concat(h,'" width="').concat(c,'" height="').concat(u,'">'),'<image x="0" y="0" width="'.concat(i.width,'" height="').concat(i.height,'" xlink:href="').concat(this.sourceToString(),'"></image>'),"</pattern>",""].join(`
75
- `)}static async fromObject(t,e){let{type:s,source:i,patternTransform:n}=t,r=Lt(t,ux);const a=await qh(i,T(T({},e),{},{crossOrigin:r.crossOrigin}));return new this(T(T({},r),{},{patternTransform:n&&n.slice(0),source:a}))}}E(mg,"type","Pattern"),W.setClass(mg),W.setClass(mg,"pattern");const dx=["path","left","top"],fx=["d"];class zr extends ke{constructor(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{path:s,left:i,top:n}=e,r=Lt(e,dx);super(),Object.assign(this,zr.ownDefaults),this.setOptions(r),this._setPath(t||[],!0),typeof i=="number"&&this.set(wt,i),typeof n=="number"&&this.set(is,n)}_setPath(t,e){this.path=G0(Array.isArray(t)?t:Q0(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=Z0(this.path,bt.NUM_FRACTION_DIGITS);return["<path ","COMMON_PARTS",'d="'.concat(t,`" stroke-linecap="round" />
76
- `)]}_getOffsetTransform(){const t=bt.NUM_FRACTION_DIGITS;return" translate(".concat(Dt(-this.pathOffset.x,t),", ").concat(Dt(-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,rt,rt)}_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(...fg(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(...fg(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 Ci(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=Zi(t,this.ATTRIBUTE_NAMES,s),{d:n}=i;return new this(n,T(T(T({},Lt(i,fx)),e),{},{left:void 0,top:void 0}))}}E(zr,"type","Path"),E(zr,"cacheProperties",[...Ji,"path","fillRule"]),E(zr,"ATTRIBUTE_NAMES",[...Xn,"d"]),W.setClass(zr),W.setSVGClass(zr);const gx=["left","top","radius"],av=["radius","startAngle","endAngle","counterClockwise"];class en extends ke{static getDefaults(){return T(T({},super.getDefaults()),en.ownDefaults)}constructor(t){super(),Object.assign(this,en.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,Ut(this.startAngle),Ut(this.endAngle),this.counterClockwise),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get(Ve)}getRadiusY(){return this.get("radius")*this.get(gs)}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([...av,...t])}_toSVG(){const t=(this.endAngle-this.startAngle)%360;if(t===0)return["<circle ","COMMON_PARTS",'cx="0" cy="0" ','r="',"".concat(this.radius),`" />
77
- `];{const{radius:e}=this,s=Ut(this.startAngle),i=Ut(this.endAngle),n=Ks(s)*e,r=Js(s)*e,a=Ks(i)*e,h=Js(i)*e,c=t>180?1:0,u=this.counterClockwise?0:1;return['<path d="M '.concat(n," ").concat(r," A ").concat(e," ").concat(e," 0 ").concat(c," ").concat(u," ").concat(a," ").concat(h,'" '),"COMMON_PARTS",` />
78
- `]}}static async fromElement(t,e,s){const i=Zi(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,radius:a=0}=i;return new this(T(T({},Lt(i,gx)),{},{radius:a,left:n-a,top:r-a}))}static fromObject(t){return super._fromObject(t)}}E(en,"type","Circle"),E(en,"cacheProperties",[...Ji,...av]),E(en,"ownDefaults",{radius:0,startAngle:0,endAngle:360,counterClockwise:!1}),E(en,"ATTRIBUTE_NAMES",["cx","cy","r",...Xn]),W.setClass(en),W.setSVGClass(en);const px=["x1","y1","x2","y2"],mx=["x1","y1","x2","y2"],vg=["x1","x2","y1","y2"];class Vr extends ke{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,Vr.ownDefaults),this.setOptions(n),this.x1=t,this.x2=s,this.y1=e,this.y2=i,this._setWidthHeight();const{left:r,top:a}=n;typeof r=="number"&&this.set(wt,r),typeof a=="number"&&this.set(is,a)}_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:a,height:h}=Ci([{x:t,y:e},{x:s,y:i}]),c=new M(n+a/2,r+h/2);this.setPositionByOrigin(c,rt,rt)}_set(t,e){return super._set(t,e),vg.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;Fs(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,a=t<=e?-1:1,h=s<=i?-1:1;return{x1:a*n/2,x2:a*-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,`" />
79
- `)]}static async fromElement(t,e,s){const i=Zi(t,this.ATTRIBUTE_NAMES,s),{x1:n=0,y1:r=0,x2:a=0,y2:h=0}=i;return new this([n,r,a,h],Lt(i,px))}static fromObject(t){let{x1:e,y1:s,x2:i,y2:n}=t,r=Lt(t,mx);return this._fromObject(T(T({},r),{},{points:[e,s,i,n]}),{extraParam:"points"})}}E(Vr,"type","Line"),E(Vr,"cacheProperties",[...Ji,...vg]),E(Vr,"ATTRIBUTE_NAMES",Xn.concat(vg)),W.setClass(Vr),W.setSVGClass(Vr);class Wr extends ke{static getDefaults(){return T(T({},super.getDefaults()),Wr.ownDefaults)}constructor(t){super(),Object.assign(this,Wr.ownDefaults),this.setOptions(t)}_render(t){const e=this.width/2,s=this.height/2;t.beginPath(),t.moveTo(-e,s),t.lineTo(0,-s),t.lineTo(e,s),t.closePath(),this._renderPaintInOrder(t)}_toSVG(){const t=this.width/2,e=this.height/2;return["<polygon ","COMMON_PARTS",'points="',"".concat(-t," ").concat(e,",0 ").concat(-e,",").concat(t," ").concat(e),'" />']}}E(Wr,"type","Triangle"),E(Wr,"ownDefaults",{width:100,height:100}),W.setClass(Wr),W.setSVGClass(Wr);const ov=["rx","ry"];class sn extends ke{static getDefaults(){return T(T({},super.getDefaults()),sn.ownDefaults)}constructor(t){super(),Object.assign(this,sn.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(Ve)}getRy(){return this.get("ry")*this.get(gs)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...ov,...t])}_toSVG(){return["<ellipse ","COMMON_PARTS",'cx="0" cy="0" rx="'.concat(this.rx,'" ry="').concat(this.ry,`" />
80
- `)]}_render(t){t.beginPath(),t.save(),t.transform(1,0,0,this.ry/this.rx,0,0),t.arc(0,0,this.rx,0,qi,!1),t.restore(),this._renderPaintInOrder(t)}static async fromElement(t,e,s){const i=Zi(t,this.ATTRIBUTE_NAMES,s);return i.left=(i.left||0)-i.rx,i.top=(i.top||0)-i.ry,new this(i)}}function vx(o){if(!o)return[];const t=o.replace(/,/g," ").trim().split(/\s+/),e=[];for(let s=0;s<t.length;s+=2)e.push({x:parseFloat(t[s]),y:parseFloat(t[s+1])});return e}E(sn,"type","Ellipse"),E(sn,"cacheProperties",[...Ji,...ov]),E(sn,"ownDefaults",{rx:0,ry:0}),E(sn,"ATTRIBUTE_NAMES",[...Xn,"cx","cy","rx","ry"]),W.setClass(sn),W.setSVGClass(sn);const bx=["left","top"],hv={exactBoundingBox:!1};class ii extends ke{static getDefaults(){return T(T({},super.getDefaults()),ii.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),E(this,"strokeDiff",void 0),Object.assign(this,ii.ownDefaults),this.setOptions(e),this.points=t;const{left:s,top:i}=e;this.initialized=!0,this.setBoundingBox(!0),typeof s=="number"&&this.set(wt,s),typeof i=="number"&&this.set(is,i)}isOpen(){return!0}_projectStrokeOnPoints(t){return T0(this.points,t,this.isOpen())}_calcDimensions(t){t=T({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,strokeLineCap:this.strokeLineCap,strokeLineJoin:this.strokeLineJoin,strokeMiterLimit:this.strokeMiterLimit,strokeUniform:this.strokeUniform,strokeWidth:this.strokeWidth},t||{});const e=this.exactBoundingBox?this._projectStrokeOnPoints(t).map(c=>c.projectedPoint):this.points;if(e.length===0)return{left:0,top:0,width:0,height:0,pathOffset:new M,strokeOffset:new M,strokeDiff:new M};const s=Ci(e),i=$h(T(T({},t),{},{scaleX:1,scaleY:1})),n=Ci(this.points.map(c=>Ee(c,i,!0))),r=new M(this.scaleX,this.scaleY);let a=s.left+s.width/2,h=s.top+s.height/2;return this.exactBoundingBox&&(a-=h*Math.tan(Ut(this.skewX)),h-=a*Math.tan(Ut(this.skewY))),T(T({},s),{},{pathOffset:new M(a,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=Ci(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:a,strokeDiff:h}=this._calcDimensions();this.set({width:i,height:n,pathOffset:r,strokeOffset:a,strokeDiff:h}),t&&this.setPositionByOrigin(new M(e+i/2,s+n/2),rt,rt)}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(a=>this.strokeUniform||this.constructor.layoutProperties.includes(a))){var e,s;const{width:a,height:h}=this._calcDimensions(t);r=new M((e=t.width)!==null&&e!==void 0?e:a,(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===Ve||t===gs)&&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=bt.NUM_FRACTION_DIGITS;for(let n=0,r=this.points.length;n<r;n++)t.push(Dt(this.points[n].x-e,i),",",Dt(this.points[n].y-s,i)," ");return["<".concat(this.constructor.type.toLowerCase()," "),"COMMON_PARTS",'points="'.concat(t.join(""),`" />
81
- `)]}_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(vx(t.getAttribute("points")),T(T({},Lt(Zi(t,this.ATTRIBUTE_NAMES,s),bx)),e))}static fromObject(t){return this._fromObject(t,{extraParam:"points"})}}E(ii,"ownDefaults",hv),E(ii,"type","Polyline"),E(ii,"layoutProperties",[co,uo,"strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeWidth","strokeUniform","points"]),E(ii,"cacheProperties",[...Ji,"points"]),E(ii,"ATTRIBUTE_NAMES",[...Xn]),W.setClass(ii),W.setSVGClass(ii);class Nu extends ii{isOpen(){return!1}}E(Nu,"ownDefaults",hv),E(Nu,"type","Polygon"),W.setClass(Nu),W.setSVGClass(Nu);const lv=["fontSize","fontWeight","fontFamily","fontStyle"],cv=["underline","overline","linethrough"],uv=[...lv,"lineHeight","text","charSpacing","textAlign","styles","path","pathStartOffset","pathSide","pathAlign"],dv=[...uv,...cv,"textBackgroundColor","direction"],yx=[...lv,...cv,We,"strokeWidth",ee,"deltaY","textBackgroundColor"],_x={_reNewline:Rf,_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:wt,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:wt,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},Ti="justify",Bu="justify-left",rl="justify-right",al="justify-center";class fv extends ke{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,a=0;for(const h in e){s=0;for(const c in e[h]){const u=e[h][c]||{};n++,u[t]!==void 0?(i?u[t]!==i&&(r=!1):i=u[t],u[t]===this[t]&&delete u[t]):r=!1,Object.keys(u).length!==0?s++:delete e[h][c]}s===0&&delete e[h]}for(let h=0;h<this._textLines.length;h++)a+=this._textLines[h].length;r&&n===a&&(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=zf(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({},jr(this,this.constructor._styleProperties)),this._getStyleDeclaration(t,e))}_setStyleDeclaration(t,e,s){this.styles[t][e]=s}_deleteStyleDeclaration(t,e){delete this.styles[t][e]}_getLineStyle(t){return!!this.styles[t]}_setLineStyle(t){this.styles[t]={}}_deleteLineStyle(t){delete this.styles[t]}}E(fv,"_styleProperties",yx);const wx=/ +/g,xx=/"/g;function bg(o,t,e,s,i){return" ".concat(function(n,r){let{left:a,top:h,width:c,height:u}=r,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:bt.NUM_FRACTION_DIGITS;const f=Zh(ee,n,!1),[g,p,m,y]=[a,h,c,u].map(b=>Dt(b,d));return"<rect ".concat(f,' x="').concat(g,'" y="').concat(p,'" width="').concat(m,'" height="').concat(y,'"></rect>')}(o,{left:t,top:e,width:s,height:i}),`
82
- `)}const Sx=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let yg;class Pe extends fv{static getDefaults(){return T(T({},super.getDefaults()),Pe.ownDefaults)}constructor(t,e){super(),E(this,"__charBounds",[]),Object.assign(this,Pe.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=gg(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(Ti)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,s,i,n,r,a;for(let h=0,c=this._textLines.length;h<c;h++)if((this.textAlign===Ti||h!==c-1&&!this.isEndOfWrapping(h))&&(i=0,n=this._textLines[h],e=this.getLineWidth(h),e<this.width&&(a=this.textLines[h].match(this._reSpacesAndTabs)))){s=a.length,t=(this.width-e)/s;for(let u=0;u<=n.length;u++)r=this.__charBounds[h][u],this._reSpaceAndTab.test(n[u])?(r.width+=t,r.kernedWidth+=t,r.left+=i,i+=t):r.left+=i}}isEndOfWrapping(t){return t===this._textLines.length-1}missingNewlineOffset(t){return 1}get2DCursorLocation(t,e){const s=e?this._unwrappedTextLines:this._textLines;let i;for(i=0;i<s.length;i++){if(t<=s[i].length)return{lineIndex:i,charIndex:t};t-=s[i].length+this.missingNewlineOffset(i,e)}return{lineIndex:i-1,charIndex:s[i-1].length<t?s[i-1].length:t}}toString(){return"#<Text (".concat(this.complexity(),'): { "text": "').concat(this.text,'", "fontFamily": "').concat(this.fontFamily,'" }>')}_getCacheCanvasDimensions(){const t=super._getCacheCanvasDimensions(),e=this.fontSize;return t.width+=e*t.zoomX,t.height+=e*t.zoomY,t}_render(t){const e=this.path;e&&!e.isNotVisible()&&e._render(t),this._setTextStyles(t),this._renderTextLinesBackground(t),this._renderTextDecoration(t,"underline"),this._renderText(t),this._renderTextDecoration(t,"overline"),this._renderTextDecoration(t,"linethrough")}_renderText(t){this.paintFirst===We?(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 rt:t.textBaseline="middle";break;case"ascender":t.textBaseline=is;break;case"descender":t.textBaseline=Df}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 a=this.getHeightOfLine(n);if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor",n)){i+=a;continue}const h=this._textLines[n].length,c=this._getLineLeftOffset(n);let u,d,f=0,g=0,p=this.getValueOfPropertyAt(n,0,"textBackgroundColor");for(let m=0;m<h;m++){const y=this.__charBounds[n][m];d=this.getValueOfPropertyAt(n,m,"textBackgroundColor"),this.path?(t.save(),t.translate(y.renderLeft,y.renderTop),t.rotate(y.angle),t.fillStyle=d,d&&t.fillRect(-y.width/2,-a/this.lineHeight*(1-this._fontSizeFraction),y.width,a/this.lineHeight),t.restore()):d!==p?(u=s+c+g,this.direction==="rtl"&&(u=this.width-u-f),t.fillStyle=p,p&&t.fillRect(u,i,f,a/this.lineHeight),g=y.left,f=y.width,p=d):f+=y.kernedWidth}d&&!this.path&&(u=s+c+g,this.direction==="rtl"&&(u=this.width-u-f),t.fillStyle=d,t.fillRect(u,i,f,a/this.lineHeight)),i+=a}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,s,i){const n=Xh.getFontCache(e),r=this._getFontDeclaration(e),a=s+t,h=s&&r===this._getFontDeclaration(i),c=e.fontSize/this.CACHE_FONT_SIZE;let u,d,f,g;if(s&&n[s]!==void 0&&(f=n[s]),n[t]!==void 0&&(g=u=n[t]),h&&n[a]!==void 0&&(d=n[a],g=d-f),u===void 0||f===void 0||d===void 0){const p=function(){return yg||(yg=ps({width:0,height:0}).getContext("2d")),yg}();this._setTextStyles(p,e,!0),u===void 0&&(g=u=p.measureText(t).width,n[t]=u),f===void 0&&h&&s&&(f=p.measureText(s).width,n[s]=f),h&&d===void 0&&(d=p.measureText(a).width,n[a]=d,g=d-f)}return{width:u*c,kernedWidth:g*c}}getHeightOfChar(t,e){return this.getValueOfPropertyAt(t,e,"fontSize")}measureLine(t){const e=this._measureLine(t);return this.charSpacing!==0&&(e.width-=this._getWidthOfCharSpacing()),e.width<0&&(e.width=0),e}_measureLine(t){let e,s,i=0;const n=this.pathSide===$t,r=this.path,a=this._textLines[t],h=a.length,c=new Array(h);this.__charBounds[t]=c;for(let u=0;u<h;u++){const d=a[u];s=this._getGraphemeBox(d,t,u,e),c[u]=s,i+=s.kernedWidth,e=d}if(c[h]={left:s?s.left+s.width:0,width:0,kernedWidth:0,height:this.fontSize,deltaY:0},r&&r.segmentsInfo){let u=0;const d=r.segmentsInfo[r.segmentsInfo.length-1].length;switch(this.textAlign){case wt:u=n?d-i:0;break;case rt:u=(d-i)/2;break;case $t:u=n?0:d-i}u+=this.pathStartOffset*(n?-1:1);for(let f=n?h-1:0;n?f>=0:f<h;n?f--:f++)s=c[f],u>d?u%=d:u<0&&(u+=d),this._setGraphemeOnPath(u,s),u+=s.kernedWidth}return{width:i,numOfSpaces:0}}_setGraphemeOnPath(t,e){const s=t+e.kernedWidth/2,i=this.path,n=K0(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===$t?Math.PI:0)}_getGraphemeBox(t,e,s,i,n){const r=this.getCompleteStyleDeclaration(e,s),a=i?this.getCompleteStyleDeclaration(e,s-1):{},h=this._measureChar(t,r,i,a);let c,u=h.kernedWidth,d=h.width;this.charSpacing!==0&&(c=this._getWidthOfCharSpacing(),d+=c,u+=c);const f={width:d,left:0,height:r.fontSize,kernedWidth:u,deltaY:r.deltaY};if(s>0&&!n){const g=this.__charBounds[e][s-1];f.left=g.left+g.width+h.kernedWidth-h.width}return f}getHeightOfLine(t){if(this.__lineHeights[t])return this.__lineHeights[t];let e=this.getHeightOfChar(t,0);for(let s=1,i=this._textLines[t].length;s<i;s++)e=Math.max(this.getHeightOfChar(t,s),e);return this.__lineHeights[t]=e*this.lineHeight*this._fontSizeMult}calcTextHeight(){let t,e=0;for(let s=0,i=this._textLines.length;s<i;s++)t=this.getHeightOfLine(s),e+=s===i-1?t/this.lineHeight:t;return e}_getLeftOffset(){return this.direction==="ltr"?-this.width/2:this.width/2}_getTopOffset(){return-this.height/2}_renderTextCommon(t,e){t.save();let s=0;const i=this._getLeftOffset(),n=this._getTopOffset();for(let r=0,a=this._textLines.length;r<a;r++){const h=this.getHeightOfLine(r),c=h/this.lineHeight,u=this._getLineLeftOffset(r);this._renderTextLine(e,t,this._textLines[r],i+u,n+s+c,r),s+=h}t.restore()}_renderTextFill(t){(this.fill||this.styleHas(ee))&&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 a=this.getHeightOfLine(r),h=this.textAlign.includes(Ti),c=this.path,u=!h&&this.charSpacing===0&&this.isEmptyStyles(r)&&!c,d=this.direction==="ltr",f=this.direction==="ltr"?1:-1,g=e.direction;let p,m,y,b,x,S="",C=0;if(e.save(),g!==this.direction&&(e.canvas.setAttribute("dir",d?"ltr":"rtl"),e.direction=d?"ltr":"rtl",e.textAlign=d?wt:$t),n-=a*this._fontSizeFraction/this.lineHeight,u)return this._renderChar(t,e,r,0,s.join(""),i,n),void e.restore();for(let k=0,O=s.length-1;k<=O;k++)b=k===O||this.charSpacing||c,S+=s[k],y=this.__charBounds[r][k],C===0?(i+=f*(y.kernedWidth-y.width),C+=y.width):C+=y.kernedWidth,h&&!b&&this._reSpaceAndTab.test(s[k])&&(b=!0),b||(p=p||this.getCompleteStyleDeclaration(r,k),m=this.getCompleteStyleDeclaration(r,k+1),b=Pu(p,m,!1)),b&&(c?(e.save(),e.translate(y.renderLeft,y.renderTop),e.rotate(y.angle),this._renderChar(t,e,r,k,S,-C/2,0),e.restore()):(x=i,this._renderChar(t,e,r,k,S,x,n)),S="",p=m,i+=f*C,C=0);e.restore()}_applyPatternGradientTransformText(t){const e=this.width+this.strokeWidth,s=this.height+this.strokeWidth,i=ps({width:e,height:s}),n=i.getContext("2d");return i.width=e,i.height=s,n.beginPath(),n.moveTo(0,0),n.lineTo(e,0),n.lineTo(e,s),n.lineTo(0,s),n.closePath(),n.translate(e/2,s/2),n.fillStyle=t.toLive(n),this._applyPatternGradientTransform(n,t),n.fill(),n.createPattern(i,"no-repeat")}handleFiller(t,e,s){let i,n;return Fs(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,a){const h=this._getStyleDeclaration(s,i),c=this.getCompleteStyleDeclaration(s,i),u=t==="fillText"&&c.fill,d=t==="strokeText"&&c.stroke&&c.strokeWidth;if(d||u){if(e.save(),e.font=this._getFontDeclaration(c),h.textBackgroundColor&&this._removeShadow(e),h.deltaY&&(a+=h.deltaY),u){const f=this._setFillStyles(e,c);e.fillText(n,r-f.offsetX,a-f.offsetY)}if(d){const f=this._setStrokeStyles(e,c);e.strokeText(n,r-f.offsetX,a-f.offsetY)}e.restore()}}setSuperscript(t,e){this._setScript(t,e,this.superscript)}setSubscript(t,e){this._setScript(t,e,this.subscript)}_setScript(t,e,s){const i=this.get2DCursorLocation(t,!0),n=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"fontSize"),r=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"deltaY"),a={fontSize:n*s.size,deltaY:r+n*s.baseline};this.setSelectionStyles(a,t,e)}_getLineLeftOffset(t){const e=this.getLineWidth(t),s=this.width-e,i=this.textAlign,n=this.direction,r=this.isEndOfWrapping(t);let a=0;return i===Ti||i===al&&!r||i===rl&&!r||i===Bu&&!r?0:(i===rt&&(a=s/2),i===$t&&(a=s),i===al&&(a=s/2),i===rl&&(a=s),n==="rtl"&&(i===$t||i===Ti||i===rl?a=0:i===wt||i===Bu?a=-s:i!==rt&&i!==al||(a=-s/2)),a)}_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(),a=this.offsets[e];for(let h=0,c=this._textLines.length;h<c;h++){const u=this.getHeightOfLine(h);if(!this[e]&&!this.styleHas(e,h)){s+=u;continue}const d=this._textLines[h],f=u/this.lineHeight,g=this._getLineLeftOffset(h);let p,m,y=0,b=0,x=this.getValueOfPropertyAt(h,0,e),S=this.getValueOfPropertyAt(h,0,ee);const C=s+f*(1-this._fontSizeFraction);let k=this.getHeightOfChar(h,0),O=this.getValueOfPropertyAt(h,0,"deltaY");for(let D=0,R=d.length;D<R;D++){const z=this.__charBounds[h][D];p=this.getValueOfPropertyAt(h,D,e),m=this.getValueOfPropertyAt(h,D,ee);const B=this.getHeightOfChar(h,D),F=this.getValueOfPropertyAt(h,D,"deltaY");if(n&&p&&m)t.save(),t.fillStyle=S,t.translate(z.renderLeft,z.renderTop),t.rotate(z.angle),t.fillRect(-z.kernedWidth/2,a*B+F,z.kernedWidth,this.fontSize/15),t.restore();else if((p!==x||m!==S||B!==k||F!==O)&&b>0){let L=i+g+y;this.direction==="rtl"&&(L=this.width-L-b),x&&S&&(t.fillStyle=S,t.fillRect(L,C+a*k+O,b,this.fontSize/15)),y=z.left,b=z.width,x=p,S=m,k=B,O=F}else b+=z.kernedWidth}let P=i+g+y;this.direction==="rtl"&&(P=this.width-P-b),t.fillStyle=m,p&&m&&t.fillRect(P,C+a*k+O,b-r,this.fontSize/15),s+=u}this._removeShadow(t)}_getFontDeclaration(){let{fontFamily:t=this.fontFamily,fontStyle:e=this.fontStyle,fontWeight:s=this.fontWeight,fontSize:i=this.fontSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;const r=t.includes("'")||t.includes('"')||t.includes(",")||Pe.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 ku(t)}_splitTextIntoLines(t){const e=t.split(this._reNewline),s=new Array(e.length),i=[`
83
- `];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([...dv,...t])),{},{styles:k0(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=Zi(t,Pe.ATTRIBUTE_NAMES,s),n=T(T({},e),i),{textAnchor:r=wt,textDecoration:a="",dx:h=0,dy:c=0,top:u=0,left:d=0,fontSize:f=Of,strokeWidth:g=1}=n,p=Lt(n,Sx),m=new this((t.textContent||"").replace(/^\s+|\s+$|\n+/g,"").replace(/\s+/g," "),T({left:d+h,top:u+c,underline:a.includes("underline"),overline:a.includes("overline"),linethrough:a.includes("line-through"),strokeWidth:0,fontSize:f},p)),y=m.getScaledHeight()/m.height,b=((m.height+m.strokeWidth)*m.lineHeight-m.height)*y,x=m.getScaledHeight()+b;let S=0;return r===rt&&(S=m.getScaledWidth()/2),r===$t&&(S=m.getScaledWidth()),m.set({left:m.left-S,top:m.top-(x-m.fontSize*(.07+m._fontSizeFraction))/m.lineHeight,strokeWidth:g}),m}static fromObject(t){return this._fromObject(T(T({},t),{},{styles:P0(t.styles||{},t.text)}),{extraParam:"text"})}}E(Pe,"textLayoutProperties",uv),E(Pe,"cacheProperties",[...Ji,...dv]),E(Pe,"ownDefaults",_x),E(Pe,"type","Text"),E(Pe,"genericFonts",["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong"]),E(Pe,"ATTRIBUTE_NAMES",Xn.concat("x","y","dx","dy","font-family","font-style","font-weight","font-size","letter-spacing","text-decoration","text-anchor")),x0(Pe,[class extends s0{_toSVG(){const o=this._getSVGLeftTopOffsets(),t=this._getSVGTextAndBg(o.textTop,o.textLeft);return this._wrapSVGTextAndBg(t)}toSVG(o){const t=this._createBaseSVGMarkup(this._toSVG(),{reviver:o,noStyle:!0,withShadow:!0}),e=this.path;return e?t+e._createBaseSVGMarkup(e._toSVG(),{reviver:o,withShadow:!0,additionalTransform:mo(this.calcOwnMatrix())}):t}_getSVGLeftTopOffsets(){return{textLeft:-this.width/2,textTop:-this.height/2,lineTop:this.getHeightOfLine(0)}}_wrapSVGTextAndBg(o){let{textBgRects:t,textSpans:e}=o;const s=this.getSvgTextDecoration(this);return[t.join(""),' <text xml:space="preserve" ',this.fontFamily?'font-family="'.concat(this.fontFamily.replace(xx,"'"),'" '):"",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>
84
- `]}_getSVGTextAndBg(o,t){const e=[],s=[];let i,n=o;this.backgroundColor&&s.push(...bg(this.backgroundColor,-this.width/2,-this.height/2,this.width,this.height));for(let r=0,a=this._textLines.length;r<a;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(o,t,e,s,i){const n=bt.NUM_FRACTION_DIGITS,r=this.getSvgSpanStyles(t,o!==o.trim()||!!o.match(wx)),a=r?'style="'.concat(r,'"'):"",h=t.deltaY,c=h?' dy="'.concat(Dt(h,n),'" '):"",{angle:u,renderLeft:d,renderTop:f,width:g}=i;let p="";if(d!==void 0){const m=g/2;u&&(p=' rotate="'.concat(Dt(Si(u),n),'"'));const y=Ir({angle:Si(u)});y[4]=d,y[5]=f;const b=new M(-m,0).transform(y);e=b.x,s=b.y}return'<tspan x="'.concat(Dt(e,n),'" y="').concat(Dt(s,n),'" ').concat(c).concat(p).concat(a,">").concat(E0(o),"</tspan>")}_setSVGTextLineText(o,t,e,s){const i=this.getHeightOfLine(t),n=this.textAlign.includes(Ti),r=this._textLines[t];let a,h,c,u,d,f="",g=0;s+=i*(1-this._fontSizeFraction)/this.lineHeight;for(let p=0,m=r.length-1;p<=m;p++)d=p===m||this.charSpacing||this.path,f+=r[p],c=this.__charBounds[t][p],g===0?(e+=c.kernedWidth-c.width,g+=c.width):g+=c.kernedWidth,n&&!d&&this._reSpaceAndTab.test(r[p])&&(d=!0),d||(a=a||this.getCompleteStyleDeclaration(t,p),h=this.getCompleteStyleDeclaration(t,p+1),d=Pu(a,h,!0)),d&&(u=this._getStyleDeclaration(t,p),o.push(this._createTextCharSpan(f,u,e,s,c)),f="",a=h,this.direction==="rtl"?e-=g:e+=g,g=0)}_setSVGTextLineBg(o,t,e,s){const i=this._textLines[t],n=this.getHeightOfLine(t)/this.lineHeight;let r,a=0,h=0,c=this.getValueOfPropertyAt(t,0,"textBackgroundColor");for(let u=0;u<i.length;u++){const{left:d,width:f,kernedWidth:g}=this.__charBounds[t][u];r=this.getValueOfPropertyAt(t,u,"textBackgroundColor"),r!==c?(c&&o.push(...bg(c,e+h,s,a,n)),h=d,a=f,c=r):a+=g}r&&o.push(...bg(c,e+h,s,a,n))}_getSVGLineTopOffset(o){let t,e=0;for(t=0;t<o;t++)e+=this.getHeightOfLine(t);const s=this.getHeightOfLine(t);return{lineTop:e,offset:(this._fontSizeMult-this._fontSizeFraction)*s/(this.lineHeight*this._fontSizeMult)}}getSvgStyles(o){return"".concat(super.getSvgStyles(o)," white-space: pre;")}getSvgSpanStyles(o,t){const{fontFamily:e,strokeWidth:s,stroke:i,fill:n,fontSize:r,fontStyle:a,fontWeight:h,deltaY:c}=o,u=this.getSvgTextDecoration(o);return[i?Zh(We,i):"",s?"stroke-width: ".concat(s,"; "):"",e?"font-family: ".concat(e.includes("'")||e.includes('"')?e:"'".concat(e,"'"),"; "):"",r?"font-size: ".concat(r,"px; "):"",a?"font-style: ".concat(a,"; "):"",h?"font-weight: ".concat(h,"; "):"",u&&"text-decoration: ".concat(u,"; "),n?Zh(ee,n):"",c?"baseline-shift: ".concat(-c,"; "):"",t?"white-space: pre; ":""].join("")}getSvgTextDecoration(o){return["overline","underline","line-through"].filter(t=>o[t.replace("-","")]).join(" ")}}]),W.setClass(Pe),W.setSVGClass(Pe);class Cx{constructor(t){E(this,"target",void 0),E(this,"__mouseDownInPlace",!1),E(this,"__dragStartFired",!1),E(this,"__isDraggingOver",!1),E(this,"__dragStartSelection",void 0),E(this,"__dragImageDisposer",void 0),E(this,"_dispose",void 0),this.target=t;const e=[this.target.on("dragenter",this.dragEnterHandler.bind(this)),this.target.on("dragover",this.dragOverHandler.bind(this)),this.target.on("dragleave",this.dragLeaveHandler.bind(this)),this.target.on("dragend",this.dragEndHandler.bind(this)),this.target.on("drop",this.dropHandler.bind(this))];this._dispose=()=>{e.forEach(s=>s()),this._dispose=void 0}}isPointerOverSelection(t){const e=this.target,s=e.getSelectionStartFromPointer(t);return e.isEditing&&s>=e.selectionStart&&s<=e.selectionEnd&&e.selectionStart<e.selectionEnd}start(t){return this.__mouseDownInPlace=this.isPointerOverSelection(t)}isActive(){return this.__mouseDownInPlace}end(t){const e=this.isActive();return e&&!this.__dragStartFired&&(this.target.setCursorByClick(t),this.target.initDelayedCursor(!0)),this.__mouseDownInPlace=!1,this.__dragStartFired=!1,this.__isDraggingOver=!1,e}getDragStartSelection(){return this.__dragStartSelection}setDragImage(t,e){var s;let{selectionStart:i,selectionEnd:n}=e;const r=this.target,a=r.canvas,h=new M(r.flipX?-1:1,r.flipY?-1:1),c=r._getCursorBoundaries(i),u=new M(c.left+c.leftOffset,c.top+c.topOffset).multiply(h).transform(r.calcTransformMatrix()),d=a.getScenePoint(t).subtract(u),f=r.getCanvasRetinaScaling(),g=r.getBoundingRect(),p=u.subtract(new M(g.left,g.top)),m=a.viewportTransform,y=p.add(d).transform(m,!0),b=r.backgroundColor,x=og(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:a.enableRetinaScaling,viewportTransform:!0});r.backgroundColor=b,r.styles=x,r.dirty=!0,Lu(C,{position:"fixed",left:"".concat(-C.width,"px"),border:ze,width:"".concat(C.width/f,"px"),height:"".concat(C.height/f,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{C.remove()},Qs(t.target||this.target.hiddenTextarea).body.appendChild(C),(s=t.dataTransfer)===null||s===void 0||s.setDragImage(C,y.x,y.y)}onDragStart(t){this.__dragStartFired=!0;const e=this.target,s=this.isActive();if(s&&t.dataTransfer){const i=this.__dragStartSelection={selectionStart:e.selectionStart,selectionEnd:e.selectionEnd},n=e._text.slice(i.selectionStart,i.selectionEnd).join(""),r=T({text:e.text,value:n},i);t.dataTransfer.setData("text/plain",n),t.dataTransfer.setData("application/fabric",JSON.stringify({value:n,styles:e.getSelectionStyles(i.selectionStart,i.selectionEnd,!0)})),t.dataTransfer.effectAllowed="copyMove",this.setDragImage(t,r)}return e.abortCursorAnimation(),s}canDrop(t){if(this.target.editable&&!this.target.getActiveControl()&&!t.defaultPrevented){if(this.isActive()&&this.__dragStartSelection){const e=this.target.getSelectionStartFromPointer(t),s=this.__dragStartSelection;return e<s.selectionStart||e>s.selectionEnd}return!0}return!1}targetCanDrop(t){return this.target.canDrop(t)}dragEnterHandler(t){let{e}=t;const s=this.targetCanDrop(e);!this.__isDraggingOver&&s&&(this.__isDraggingOver=!0)}dragOverHandler(t){const{e}=t,s=this.targetCanDrop(e);!this.__isDraggingOver&&s?this.__isDraggingOver=!0:this.__isDraggingOver&&!s&&(this.__isDraggingOver=!1),this.__isDraggingOver&&(e.preventDefault(),t.canDrop=!0,t.dropTarget=this.target)}dragLeaveHandler(){(this.__isDraggingOver||this.isActive())&&(this.__isDraggingOver=!1)}dropHandler(t){var e;const{e:s}=t,i=s.defaultPrevented;this.__isDraggingOver=!1,s.preventDefault();let n=(e=s.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain");if(n&&!i){const r=this.target,a=r.canvas;let h=r.getSelectionStartFromPointer(s);const{styles:c}=s.dataTransfer.types.includes("application/fabric")?JSON.parse(s.dataTransfer.getData("application/fabric")):{},u=n[Math.max(0,n.length-1)],d=0;if(this.__dragStartSelection){const f=this.__dragStartSelection.selectionStart,g=this.__dragStartSelection.selectionEnd;h>f&&h<=g?h=f:h>g&&(h-=g-f),r.removeChars(f,g),delete this.__dragStartSelection}r._reNewline.test(u)&&(r._reNewline.test(r._text[h])||h===r._text.length)&&(n=n.trimEnd()),t.didDrop=!0,t.dropTarget=r,r.insertChars(n,c,h),a.setActiveObject(r),r.enterEditing(s),r.selectionStart=Math.min(h+d,r._text.length),r.selectionEnd=Math.min(r.selectionStart+n.length,r._text.length),r.hiddenTextarea.value=r.text,r._updateTextarea(),r.hiddenTextarea.focus(),r.fire(lu,{index:h+d,action:"drop"}),a.fire("text:changed",{target:r}),a.contextTopDirty=!0,a.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:a}=this.__dragStartSelection,h=((s=e.dataTransfer)===null||s===void 0?void 0:s.dropEffect)||ze;h===ze?(i.selectionStart=r,i.selectionEnd=a,i._updateTextarea(),i.hiddenTextarea.focus()):(i.clearContextTop(),h==="move"&&(i.removeChars(r,a),i.selectionStart=i.selectionEnd=r,i.hiddenTextarea&&(i.hiddenTextarea.value=i.text),i._updateTextarea(),i.fire(lu,{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 gv=/[ \n\.,;!\?\-]/;class Ax extends Pe{constructor(){super(...arguments),E(this,"_currentCursorOpacity",1)}initBehavior(){this._tick=this._tick.bind(this),this._onTickComplete=this._onTickComplete.bind(this),this.updateSelectionOnMouseMove=this.updateSelectionOnMouseMove.bind(this)}onDeselect(t){return this.isEditing&&this.exitEditing(),this.selected=!1,super.onDeselect(t)}_animateCursor(t){let{toValue:e,duration:s,delay:i,onComplete:n}=t;return ng({startValue:this._currentCursorOpacity,endValue:e,duration:s,delay:i,onComplete:n,abort:()=>!this.canvas||this.selectionStart!==this.selectionEnd,onChange:r=>{this._currentCursorOpacity=r,this.renderCursorOrSelection()}})}_tick(t){this._currentTickState=this._animateCursor({toValue:0,duration:this.cursorDuration/2,delay:Math.max(t||0,100),onComplete:this._onTickComplete})}_onTickComplete(){var t;(t=this._currentTickCompleteState)===null||t===void 0||t.abort(),this._currentTickCompleteState=this._animateCursor({toValue:1,duration:this.cursorDuration,onComplete:this._tick})}initDelayedCursor(t){this.abortCursorAnimation(),this._tick(t?0:this.cursorDelay)}abortCursorAnimation(){let t=!1;[this._currentTickState,this._currentTickCompleteState].forEach(e=>{e&&!e.isDone()&&(t=!0,e.abort())}),this._currentCursorOpacity=1,t&&this.clearContextTop()}restartCursorIfNeeded(){[this._currentTickState,this._currentTickCompleteState].some(t=>!t||t.isDone())&&this.initDelayedCursor()}selectAll(){return this.selectionStart=0,this.selectionEnd=this._text.length,this._fireSelectionChanged(),this._updateTextarea(),this}cmdAll(){this.selectAll(),this.renderCursorOrSelection()}getSelectedText(){return this._text.slice(this.selectionStart,this.selectionEnd).join("")}findWordBoundaryLeft(t){let e=0,s=t-1;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s--;for(;/\S/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findWordBoundaryRight(t){let e=0,s=t;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s++;for(;/\S/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}findLineBoundaryLeft(t){let e=0,s=t-1;for(;!/\n/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findLineBoundaryRight(t){let e=0,s=t;for(;!/\n/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}searchWordBoundary(t,e){const s=this._text;let i=t>0&&this._reSpace.test(s[t])&&(e===-1||!Rf.test(s[t-1]))?t-1:t,n=s[i];for(;i>0&&i<s.length&&!gv.test(n);)i+=e,n=s[i];return e===-1&&gv.test(n)&&i++,i}selectWord(t){var e;t=(e=t)!==null&&e!==void 0?e:this.selectionStart;const s=this.searchWordBoundary(t,-1),i=Math.max(s,this.searchWordBoundary(t,1));this.selectionStart=s,this.selectionEnd=i,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(t){var e;t=(e=t)!==null&&e!==void 0?e:this.selectionStart;const s=this.findLineBoundaryLeft(t),i=this.findLineBoundaryRight(t);this.selectionStart=s,this.selectionEnd=i,this._fireSelectionChanged(),this._updateTextarea()}enterEditing(t){!this.isEditing&&this.editable&&(this.enterEditingImpl(),this.fire("editing:entered",t?{e:t}:void 0),this._fireSelectionChanged(),this.canvas&&(this.canvas.fire("text:editing:entered",{target:this,e:t}),this.canvas.requestRenderAll()))}enterEditingImpl(){this.canvas&&(this.canvas.calcOffset(),this.canvas.textEditingManager.exitTextEditing()),this.isEditing=!0,this.initHiddenTextarea(),this.hiddenTextarea.focus(),this.hiddenTextarea.value=this.text,this._updateTextarea(),this._saveEditingProps(),this._setEditingProps(),this._textBeforeEdit=this.text,this._tick()}updateSelectionOnMouseMove(t){if(this.getActiveControl())return;const e=this.hiddenTextarea;Qs(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,a=e.leftOffset,h=this.getCanvasRetinaScaling(),c=this.canvas.upperCanvasEl,u=c.width/h,d=c.height/h,f=u-r,g=d-r,p=new M(e.left+a,e.top+e.topOffset+r).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new M(c.clientWidth/u,c.clientHeight/d));return p.x<0&&(p.x=0),p.x>f&&(p.x=f),p.y<0&&(p.y=0),p.y>g&&(p.y=g),p.x+=this.canvas._offset.left,p.y+=this.canvas._offset.top,{left:"".concat(p.x,"px"),top:"".concat(p.y,"px"),fontSize:"".concat(r,"px"),charHeight:r}}_saveEditingProps(){this._savedProps={hasControls:this.hasControls,borderColor:this.borderColor,lockMovementX:this.lockMovementX,lockMovementY:this.lockMovementY,hoverCursor:this.hoverCursor,selectable:this.selectable,defaultCursor:this.canvas&&this.canvas.defaultCursor,moveCursor:this.canvas&&this.canvas.moveCursor}}_restoreEditingProps(){this._savedProps&&(this.hoverCursor=this._savedProps.hoverCursor,this.hasControls=this._savedProps.hasControls,this.borderColor=this._savedProps.borderColor,this.selectable=this._savedProps.selectable,this.lockMovementX=this._savedProps.lockMovementX,this.lockMovementY=this._savedProps.lockMovementY,this.canvas&&(this.canvas.defaultCursor=this._savedProps.defaultCursor||this.canvas.defaultCursor,this.canvas.moveCursor=this._savedProps.moveCursor||this.canvas.moveCursor),delete this._savedProps)}_exitEditing(){const t=this.hiddenTextarea;this.selected=!1,this.isEditing=!1,t&&(t.blur&&t.blur(),t.parentNode&&t.parentNode.removeChild(t)),this.hiddenTextarea=null,this.abortCursorAnimation(),this.selectionStart!==this.selectionEnd&&this.clearContextTop()}exitEditingImpl(){this._exitEditing(),this.selectionEnd=this.selectionStart,this._restoreEditingProps(),this._forceClearCache&&(this.initDimensions(),this.setCoords())}exitEditing(){const t=this._textBeforeEdit!==this.text;return this.exitEditingImpl(),this.fire("editing:exited"),t&&this.fire(uu),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 a=i;a<this._unwrappedTextLines[s].length;a++)delete this.styles[s][a];if(this.styles[n])for(let a=r;a<this._unwrappedTextLines[n].length;a++){const h=this.styles[n][a];h&&(this.styles[s]||(this.styles[s]={}),this.styles[s][i+a-r]=h)}for(let a=s+1;a<=n;a++)delete this.styles[a];this.shiftLineStyles(n,s-n)}else if(this.styles[s]){const a=this.styles[s],h=r-i;for(let c=i;c<r;c++)delete a[c];for(const c in this.styles[s]){const u=parseInt(c,10);u>=r&&(a[u-h]=a[c],delete a[c])}}}shiftLineStyles(t,e){const s=Object.assign({},this.styles);for(const i in this.styles){const n=parseInt(i,10);n>t&&(this.styles[n+e]=s[n],s[n-e]||delete this.styles[n])}}insertNewlineStyleObject(t,e,s,i){const n={},r=this._unwrappedTextLines[t].length,a=r===e;let h=!1;s||(s=1),this.shiftLineStyles(t,s);const c=this.styles[t]?this.styles[t][e===0?e:e-1]:void 0;for(const d in this.styles[t]){const f=parseInt(d,10);f>=e&&(h=!0,n[f-e]=this.styles[t][d],a&&e===0||delete this.styles[t][d])}let u=!1;for(h&&!a&&(this.styles[t+s]=n,u=!0),(u||r>e)&&s--;s>0;)i&&i[s-1]?this.styles[t+s]={0:T({},i[s-1])}:c?this.styles[t+s]={0:T({},c)}:delete this.styles[t+s],s--;this._forceClearCache=!0}insertCharStyleObject(t,e,s,i){this.styles||(this.styles={});const n=this.styles[t],r=n?T({},n):{};s||(s=1);for(const h in r){const c=parseInt(h,10);c>=e&&(n[c+s]=r[c],r[c-s]||delete n[c])}if(this._forceClearCache=!0,i){for(;s--;)Object.keys(i[s]).length&&(this.styles[t]||(this.styles[t]={}),this.styles[t][e+s]=T({},i[s]));return}if(!n)return;const a=n[e?e-1:1];for(;a&&s--;)this.styles[t][e+s]=T({},a)}insertNewStyleBlock(t,e,s){const i=this.get2DCursorLocation(e,!0),n=[0];let r,a=0;for(let h=0;h<t.length;h++)t[h]===`
85
- `?(a++,n[a]=0):n[a]++;for(n[0]>0&&(this.insertCharStyleObject(i.lineIndex,i.charIndex,n[0],s),s=s&&s.slice(n[0]+1)),a&&this.insertNewlineStyleObject(i.lineIndex,i.charIndex+n[0],a),r=1;r<a;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=wt:this._selectionDirection===$t&&(this._selectionDirection=wt,this.selectionEnd=t),this.selectionStart=s):s>t&&s<e?this._selectionDirection===$t?this.selectionEnd=s:this.selectionStart=s:(e===t?this._selectionDirection=$t:this._selectionDirection===wt&&(this._selectionDirection=$t,this.selectionStart=e),this.selectionEnd=s)}}class Tx extends Ax{initHiddenTextarea(){const t=this.canvas&&Qs(this.canvas.getElement())||lo(),e=t.createElement("textarea");Object.entries({autocapitalize:"off",autocorrect:"off",autocomplete:"off",spellcheck:"false","data-fabric":"textarea",wrap:"off"}).map(r=>{let[a,h]=r;return e.setAttribute(a,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[a,h]=r;return e.addEventListener(a,this[h].bind(this))}),this.hiddenTextarea=e}blur(){this.abortCursorAnimation()}onKeyDown(t){if(!this.isEditing)return;const e=this.direction==="rtl"?this.keysMapRtl:this.keysMap;if(t.keyCode in e)this[e[t.keyCode]](t);else{if(!(t.keyCode in this.ctrlKeysMapDown)||!t.ctrlKey&&!t.metaKey)return;this[this.ctrlKeysMapDown[t.keyCode]](t)}t.stopImmediatePropagation(),t.preventDefault(),t.keyCode>=33&&t.keyCode<=40?(this.inCompositionMode=!1,this.clearContextTop(),this.renderCursorOrSelection()):this.canvas&&this.canvas.requestRenderAll()}onKeyUp(t){!this.isEditing||this._copyDone||this.inCompositionMode?this._copyDone=!1:t.keyCode in this.ctrlKeysMapUp&&(t.ctrlKey||t.metaKey)&&(this[this.ctrlKeysMapUp[t.keyCode]](t),t.stopImmediatePropagation(),t.preventDefault(),this.canvas&&this.canvas.requestRenderAll())}onInput(t){const e=this.fromPaste,{value:s,selectionStart:i,selectionEnd:n}=this.hiddenTextarea;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;const r=()=>{this.updateFromTextArea(),this.fire(lu),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(this.hiddenTextarea.value==="")return this.styles={},void r();const a=this._splitTextIntoLines(s).graphemeText,h=this._text.length,c=a.length,u=this.selectionStart,d=this.selectionEnd,f=u!==d;let g,p,m,y,b=c-h;const x=this.fromStringToGraphemeSelection(i,n,s),S=u>x.selectionStart;f?(p=this._text.slice(u,d),b+=d-u):c<h&&(p=S?this._text.slice(d+b,d):this._text.slice(u,u-b));const C=a.slice(x.selectionEnd-b,x.selectionEnd);if(p&&p.length&&(C.length&&(g=this.getSelectionStyles(u,u+1,!1),g=C.map(()=>g[0])),f?(m=u,y=d):S?(m=d-p.length,y=d):(m=d,y=d+p.length),this.removeStyleFromTo(m,y)),C.length){const{copyPasteData:k}=xi();e&&C.join("")===k.copiedText&&!bt.disableStyleCopyPaste&&(g=k.copiedTextStyle),this.insertNewStyleBlock(C,u,g)}r()}onCompositionStart(){this.inCompositionMode=!0}onCompositionEnd(){this.inCompositionMode=!1}onCompositionUpdate(t){let{target:e}=t;const{selectionStart:s,selectionEnd:i}=e;this.compositionStart=s,this.compositionEnd=i,this.updateTextareaPosition()}copy(){if(this.selectionStart===this.selectionEnd)return;const{copyPasteData:t}=xi();t.copiedText=this.getSelectedText(),bt.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,a=this._getWidthBeforeCursor(n,r),h=this._getIndexOnLine(n+1,a);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,a=this._getWidthBeforeCursor(n,r),h=this._getIndexOnLine(n-1,a),c=this._textLines[n].slice(0,r),u=this.missingNewlineOffset(n-1);return-this._textLines[n-1].length+h-c.length+(1-u)}_getIndexOnLine(t,e){const s=this._textLines[t];let i,n,r=this._getLineLeftOffset(t),a=0;for(let h=0,c=s.length;h<c;h++)if(i=this.__charBounds[t][h].width,r+=i,r>e){n=!0;const u=r-i,d=r,f=Math.abs(u-e);a=Math.abs(d-e)<f?h:h-1;break}return n||(a=s.length-1),a}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===$t);if(e.shiftKey?this.moveCursorWithShift(s):this.moveCursorWithoutShift(s),s!==0){const i=this.text.length;this.selectionStart=Hr(0,this.selectionStart,i),this.selectionEnd=Hr(0,this.selectionEnd,i),this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea()}}moveCursorWithShift(t){const e=this._selectionDirection===wt?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=wt,this.selectionEnd===this.selectionStart&&this.selectionStart!==0&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return this._selectionDirection===$t&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):this.selectionStart!==0?(this._selectionDirection=wt,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===wt&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection=$t,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=$t,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}const pv=o=>!!o.button;class Ex extends Tx{constructor(){super(...arguments),E(this,"draggableTextDelegate",void 0)}initBehavior(){this.on("mousedown",this._mouseDownHandler),this.on("mouseup",this.mouseUpHandler),this.on("mousedblclick",this.doubleClickHandler),this.on("mousetripleclick",this.tripleClickHandler),this.draggableTextDelegate=new Cx(this),super.initBehavior()}shouldStartDragging(){return this.draggableTextDelegate.isActive()}onDragStart(t){return this.draggableTextDelegate.onDragStart(t)}canDrop(t){return this.draggableTextDelegate.canDrop(t)}doubleClickHandler(t){this.isEditing&&(this.selectWord(this.getSelectionStartFromPointer(t.e)),this.renderCursorOrSelection())}tripleClickHandler(t){this.isEditing&&(this.selectLine(this.getSelectionStartFromPointer(t.e)),this.renderCursorOrSelection())}_mouseDownHandler(t){let{e,alreadySelected:s}=t;this.canvas&&this.editable&&!pv(e)&&!this.getActiveControl()&&(this.draggableTextDelegate.start(e)||(this.canvas.textEditingManager.register(this),s&&(this.inCompositionMode=!1,this.setCursorByClick(e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection()),this.selected||(this.selected=s||this.isEditing)))}mouseUpHandler(t){let{e,transform:s}=t;const i=this.draggableTextDelegate.end(e);if(this.canvas){this.canvas.textEditingManager.unregister(this);const n=this.canvas._activeObject;if(n&&n!==this)return}!this.editable||this.group&&!this.group.interactive||s&&s.actionPerformed||pv(e)||i||this.selected&&!this.getActiveControl()&&(this.enterEditing(e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection())}setCursorByClick(t){const e=this.getSelectionStartFromPointer(t),s=this.selectionStart,i=this.selectionEnd;t.shiftKey?this.setSelectionStartEndWithShift(s,i,e):(this.selectionStart=e,this.selectionEnd=e),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())}getSelectionStartFromPointer(t){const e=this.canvas.getScenePoint(t).transform(ns(this.calcTransformMatrix())).add(new M(-this._getLeftOffset(),-this._getTopOffset()));let s=0,i=0,n=0;for(let c=0;c<this._textLines.length&&s<=e.y;c++)s+=this.getHeightOfLine(c),n=c,c>0&&(i+=this._textLines[c-1].length+this.missingNewlineOffset(c-1));let r=Math.abs(this._getLineLeftOffset(n));const a=this._textLines[n].length,h=this.__charBounds[n];for(let c=0;c<a;c++){const u=r+h[c].kernedWidth;if(e.x<=u){Math.abs(e.x-u)<=Math.abs(e.x-r)&&i++;break}r=u,i++}return Math.min(this.flipX?a-i:i,this._text.length)}}const Hu="moveCursorUp",zu="moveCursorDown",Vu="moveCursorLeft",Wu="moveCursorRight",Gu="exitEditing",mv=(o,t)=>{const e=t.getRetinaScaling();o.setTransform(e,0,0,e,0,0);const s=t.viewportTransform;o.transform(s[0],s[1],s[2],s[3],s[4],s[5])},kx=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:Gu,27:Gu,33:Hu,34:zu,35:Wu,36:Vu,37:Vu,38:Hu,39:Wu,40:zu},keysMapRtl:{9:Gu,27:Gu,33:Hu,34:zu,35:Vu,36:Wu,37:Wu,38:Hu,39:Vu,40:zu},ctrlKeysMapDown:{65:"cmdAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}},{_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1});class nn extends Ex{static getDefaults(){return T(T({},super.getDefaults()),nn.ownDefaults)}get type(){const t=super.type;return t==="itext"?"i-text":t}constructor(t,e){super(t,T(T({},nn.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 pg&&this.canvas.textEditingManager.remove(this),e instanceof pg&&e.textEditingManager.add(this)),super._set(t,e))}setSelectionStart(t){t=Math.max(t,0),this._updateAndFire("selectionStart",t)}setSelectionEnd(t){t=Math.min(t,this.text.length),this._updateAndFire("selectionEnd",t)}_updateAndFire(t,e){this[t]!==e&&(this._fireSelectionChanged(),this[t]=e),this._updateTextarea()}_fireSelectionChanged(){this.fire("selection:changed"),this.canvas&&this.canvas.fire("text:selection:changed",{target:this})}initDimensions(){this.isEditing&&this.initDelayedCursor(),super.initDimensions()}getSelectionStyles(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart||0,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionEnd,s=arguments.length>2?arguments[2]:void 0;return super.getSelectionStyles(t,e,s)}setSelectionStyles(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionStart||0,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.selectionEnd;return super.setSelectionStyles(t,e,s)}get2DCursorLocation(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;return super.get2DCursorLocation(t,e)}render(t){super.render(t),this.cursorOffsetCache={},this.renderCursorOrSelection()}toCanvasElement(t){const e=this.isEditing;this.isEditing=!1;const s=super.toCanvasElement(t);return this.isEditing=e,s}renderCursorOrSelection(){if(!this.isEditing||!this.canvas)return;const t=this.clearContextTop(!0);if(!t)return;const e=this._getCursorBoundaries(),s=this.findAncestorsWithClipPath(),i=s.length>0;let n,r=t;if(i){n=ps(t.canvas),r=n.getContext("2d"),mv(r,this.canvas);const a=this.calcTransformMatrix();r.transform(a[0],a[1],a[2],a[3],a[4],a[5])}if(this.selectionStart!==this.selectionEnd||this.inCompositionMode?this.renderSelection(r,e):this.renderCursor(r,e),i)for(const a of s){const h=a.clipPath,c=ps(t.canvas),u=c.getContext("2d");if(mv(u,this.canvas),!h.absolutePositioned){const d=a.calcTransformMatrix();u.transform(d[0],d[1],d[2],d[3],d[4],d[5])}h.transform(u),h.drawObject(u,!0,{}),this.drawClipPathOnCache(r,h,c)}i&&(t.setTransform(1,0,0,1,0,0),t.drawImage(n,0,0)),this.canvas.contextTopDirty=!0,t.restore()}findAncestorsWithClipPath(){const t=[];let e=this;for(;e;)e.clipPath&&t.push(e),e=e.parent;return t}_getCursorBoundaries(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;const s=this._getLeftOffset(),i=this._getTopOffset(),n=this._getCursorBoundariesOffsets(t,e);return{left:s,top:i,leftOffset:n.left,topOffset:n.top}}_getCursorBoundariesOffsets(t,e){return e?this.__getCursorBoundariesOffsets(t):this.cursorOffsetCache&&"top"in this.cursorOffsetCache?this.cursorOffsetCache:this.cursorOffsetCache=this.__getCursorBoundariesOffsets(t)}__getCursorBoundariesOffsets(t){let e=0,s=0;const{charIndex:i,lineIndex:n}=this.get2DCursorLocation(t);for(let c=0;c<n;c++)e+=this.getHeightOfLine(c);const r=this._getLineLeftOffset(n),a=this.__charBounds[n][i];a&&(s=a.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===$t||this.textAlign===Ti||this.textAlign===rl?h.left*=-1:this.textAlign===wt||this.textAlign===Bu?h.left=r-(s>0?s:0):this.textAlign!==rt&&this.textAlign!==al||(h.left=r-(s>0?s:0))),h}renderCursorAt(t){this._renderCursor(this.canvas.contextTop,this._getCursorBoundaries(t,!0),t)}renderCursor(t,e){this._renderCursor(t,e,this.selectionStart)}getCursorRenderingData(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this._getCursorBoundaries(t);const s=this.get2DCursorLocation(t),i=s.lineIndex,n=s.charIndex>0?s.charIndex-1:0,r=this.getValueOfPropertyAt(i,n,"fontSize"),a=this.getObjectScaling().x*this.canvas.getZoom(),h=this.cursorWidth/a,c=this.getValueOfPropertyAt(i,n,"deltaY"),u=e.topOffset+(1-this._fontSizeFraction)*this.getHeightOfLine(i)/this.lineHeight-r*(1-this._fontSizeFraction);return{color:this.cursorColor||this.getValueOfPropertyAt(i,n,"fill"),opacity:this._currentCursorOpacity,left:e.left+e.leftOffset-h/2,top:u+e.top+c,width:h,height:r}}_renderCursor(t,e,s){const{color:i,opacity:n,left:r,top:a,width:h,height:c}=this.getCursorRenderingData(s,e);t.fillStyle=i,t.globalAlpha=n,t.fillRect(r,a,h,c)}renderSelection(t,e){const s={selectionStart:this.inCompositionMode?this.hiddenTextarea.selectionStart:this.selectionStart,selectionEnd:this.inCompositionMode?this.hiddenTextarea.selectionEnd:this.selectionEnd};this._renderSelection(t,s,e)}renderDragSourceEffect(){const t=this.draggableTextDelegate.getDragStartSelection();this._renderSelection(this.canvas.contextTop,t,this._getCursorBoundaries(t.selectionStart,!0))}renderDropTargetEffect(t){const e=this.getSelectionStartFromPointer(t);this.renderCursorAt(e)}_renderSelection(t,e,s){const i=e.selectionStart,n=e.selectionEnd,r=this.textAlign.includes(Ti),a=this.get2DCursorLocation(i),h=this.get2DCursorLocation(n),c=a.lineIndex,u=h.lineIndex,d=a.charIndex<0?0:a.charIndex,f=h.charIndex<0?0:h.charIndex;for(let g=c;g<=u;g++){const p=this._getLineLeftOffset(g)||0;let m=this.getHeightOfLine(g),y=0,b=0,x=0;if(g===c&&(b=this.__charBounds[c][d].left),g>=c&&g<u)x=r&&!this.isEndOfWrapping(g)?this.width:this.getLineWidth(g)||5;else if(g===u)if(f===0)x=this.__charBounds[u][f].left;else{const P=this._getWidthOfCharSpacing();x=this.__charBounds[u][f-1].left+this.__charBounds[u][f-1].width-P}y=m,(this.lineHeight<1||g===u&&this.lineHeight>1)&&(m/=this.lineHeight);let S=s.left+p+b,C=m,k=0;const O=x-b;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",C=1,k=m):t.fillStyle=this.selectionColor,this.direction==="rtl"&&(this.textAlign===$t||this.textAlign===Ti||this.textAlign===rl?S=this.width-S-O:this.textAlign===wt||this.textAlign===Bu?S=s.left+p-x:this.textAlign!==rt&&this.textAlign!==al||(S=s.left+p-x)),t.fillRect(S,s.top+s.topOffset+k,O,C),s.topOffset+=y}}getCurrentCharFontSize(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,"fontSize")}getCurrentCharColor(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,ee)}_getCurrentCharIndex(){const t=this.get2DCursorLocation(this.selectionStart,!0),e=t.charIndex>0?t.charIndex-1:0;return{l:t.lineIndex,c:e}}dispose(){this.exitEditingImpl(),this.draggableTextDelegate.dispose(),super.dispose()}}E(nn,"ownDefaults",kx),E(nn,"type","IText"),W.setClass(nn),W.setClass(nn,"i-text");class Gr extends nn{static getDefaults(){return T(T({},super.getDefaults()),Gr.ownDefaults)}constructor(t,e){super(t,T(T({},Gr.ownDefaults),e))}static createControls(){return{controls:dw()}}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(Ti)&&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]===`
86
- `&&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],a=this._styleMap[t+1];r&&(t=r.line,s=r.offset),a&&(i=a.line,n=i===t,e=a.offset);const h=t===void 0?this.styles:{line:this.styles[t]};for(const c in h)for(const u in h[c]){const d=parseInt(u,10);if(d>=s&&(!n||d<e))for(const f in h[c][u])return!1}return!0}_getStyleDeclaration(t,e){if(this._styleMap&&!this.isWrapping){const s=this._styleMap[t];if(!s)return{};t=s.line,e=s.offset+e}return super._getStyleDeclaration(t,e)}_setStyleDeclaration(t,e,s){const i=this._styleMap[t];super._setStyleDeclaration(i.line,i.offset+e,s)}_deleteStyleDeclaration(t,e){const s=this._styleMap[t];super._deleteStyleDeclaration(s.line,s.offset+e)}_getLineStyle(t){const e=this._styleMap[t];return!!this.styles[e.line]}_setLineStyle(t){const e=this._styleMap[t];super._setLineStyle(e.line)}_wrapText(t,e){this.isWrapping=!0;const s=this.getGraphemeDataForRender(t),i=[];for(let n=0;n<s.wordsData.length;n++)i.push(...this._wrapLine(n,e,s));return this.isWrapping=!1,i}getGraphemeDataForRender(t){const e=this.splitByGrapheme,s=e?"":" ";let i=0;return{wordsData:t.map((n,r)=>{let a=0;const h=e?this.graphemeSplit(n):this.wordSplit(n);return h.length===0?[{word:[],width:0}]:h.map(c=>{const u=e?[c]:this.graphemeSplit(c),d=this._measureWord(u,r,a);return i=Math.max(d,i),a+=u.length+s.length,{word:u,width:d}})}),largestWordWidth:i}}_measureWord(t,e){let s,i=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,n=0;for(let r=0,a=t.length;r<a;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 a=this._getWidthOfCharSpacing(),h=this.splitByGrapheme,c=[],u=h?"":" ";let d=0,f=[],g=0,p=0,m=!0;e-=r;const y=Math.max(e,i,this.dynamicMinWidth),b=n[t];let x;for(g=0,x=0;x<b.length;x++){const{word:S,width:C}=b[x];g+=S.length,d+=p+C-a,d>y&&!m?(c.push(f),f=[],d=C,m=!0):d+=a,m||h||f.push(u),f=f.concat(S),p=h?0:this._measureWord([u],t,g),g++,m=!1}return x&&c.push(f),i+r>this.dynamicMinWidth&&(this.dynamicMinWidth=i-a+r),c}isEndOfWrapping(t){return!this._styleMap[t+1]||this._styleMap[t+1].line!==this._styleMap[t].line}missingNewlineOffset(t,e){return this.splitByGrapheme&&!e?this.isEndOfWrapping(t)?1:0:1}_splitTextIntoLines(t){const e=super._splitTextIntoLines(t),s=this._wrapText(e.lines,this.width),i=new Array(s.length);for(let n=0;n<s.length;n++)i[n]=s[n].join("");return e.lines=i,e.graphemeLines=s,e}getMinWidth(){return Math.max(this.minWidth,this.dynamicMinWidth)}_removeExtraneousStyles(){const t=new Map;for(const e in this._styleMap){const s=parseInt(e,10);if(this._textLines[s]){const i=this._styleMap[e].line;t.set("".concat(i),!0)}}for(const e in this.styles)t.has(e)||delete this.styles[e]}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject(["minWidth","splitByGrapheme",...t])}}E(Gr,"type","Textbox"),E(Gr,"textLayoutProperties",[...nn.textLayoutProperties,"width"]),E(Gr,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),W.setClass(Gr);class vv extends Ru{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:a}=Ci(B0(s,i)),h=new M(r,a);if(i.absolutePositioned)return{center:Br(i.getRelativeCenterPoint(),void 0,n?n.calcTransformMatrix():void 0),size:h};{const c=i.getRelativeCenterPoint().transform(s.calcOwnMatrix(),!0);if(this.shouldPerformLayout(t)){const{center:u=new M,correction:d=new M}=this.calcBoundingBox(e,t)||{};return{center:u.add(c),correction:d.subtract(c),size:h}}return{center:s.getRelativeCenterPoint().add(c),size:h}}}}E(vv,"type","clip-path"),W.setClass(vv);class bv extends Ru{getInitialSize(t,e){let{target:s}=t,{size:i}=e;return new M(s.width||i.x,s.height||i.y)}}E(bv,"type","fixed"),W.setClass(bv);class Px extends sl{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 Xr extends Ls{static getDefaults(){return T(T({},super.getDefaults()),Xr.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,Xr.ownDefaults),this.setOptions(e);const{left:s,top:i,layoutManager:n}=e;this.groupInit(t,{left:s,top:i,layoutManager:n??new Px})}_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(a=>a.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))?($i("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===cg?s.forEach(i=>{i._onAfterObjectsChange(Ou,e)}):s.forEach(i=>{i._set("dirty",!0)})}onDeselect(){return this.removeAll(),!1}toString(){return"#<ActiveSelection: (".concat(this.complexity(),")>")}shouldCache(){return!1}isOnACache(){return!1}_renderControls(t,e,s){t.save(),t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1;const i=T(T({hasControls:!1},s),{},{forActiveSelection:!0});for(let n=0;n<this._objects.length;n++)this._objects[n]._renderControls(t,i);super._renderControls(t,e),t.restore()}}E(Xr,"type","ActiveSelection"),E(Xr,"ownDefaults",{multiSelectionStacking:"canvas-stacking"}),W.setClass(Xr),W.setClass(Xr,"activeSelection");class Mx{constructor(){E(this,"resources",{})}applyFilters(t,e,s,i,n){const r=n.getContext("2d");if(!r)return;r.drawImage(e,0,0,s,i);const a={sourceWidth:s,sourceHeight:i,imageData:r.getImageData(0,0,s,i),originalEl:e,originalImageData:r.getImageData(0,0,s,i),canvasEl:n,ctx:r,filterBackend:this};t.forEach(c=>{c.applyTo(a)});const{imageData:h}=a;return h.width===s&&h.height===i||(n.width=h.width,n.height=h.height),r.putImageData(h,0,0),a}}class yv{constructor(){let{tileSize:t=bt.textureSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};E(this,"aPosition",new Float32Array([0,0,0,1,1,0,1,1])),E(this,"resources",{}),this.tileSize=t,this.setupGLContext(t,t),this.captureGPUInfo()}setupGLContext(t,e){this.dispose(),this.createWebGLCanvas(t,e)}createWebGLCanvas(t,e){const s=ps({width:t,height:e}),i=s.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,depth:!1,stencil:!1,antialias:!1});i&&(i.clearColor(0,0,0,0),this.canvas=s,this.gl=i)}applyFilters(t,e,s,i,n,r){const a=this.gl,h=n.getContext("2d");if(!a||!h)return;let c;r&&(c=this.getCachedTexture(r,e));const u={originalWidth:e.width||e.naturalWidth||0,originalHeight:e.height||e.naturalHeight||0,sourceWidth:s,sourceHeight:i,destinationWidth:s,destinationHeight:i,context:a,sourceTexture:this.createTexture(a,s,i,c?void 0:e),targetTexture:this.createTexture(a,s,i),originalTexture:c||this.createTexture(a,s,i,c?void 0:e),passes:t.length,webgl:!0,aPosition:this.aPosition,programCache:this.programCache,pass:0,filterBackend:this,targetCanvas:n},d=a.createFramebuffer();return a.bindFramebuffer(a.FRAMEBUFFER,d),t.forEach(f=>{f&&f.applyTo(u)}),function(f){const g=f.targetCanvas,p=g.width,m=g.height,y=f.destinationWidth,b=f.destinationHeight;p===y&&m===b||(g.width=y,g.height=b)}(u),this.copyGLTo2D(a,u),a.bindTexture(a.TEXTURE_2D,null),a.deleteTexture(u.sourceTexture),a.deleteTexture(u.targetTexture),a.deleteFramebuffer(d),h.setTransform(1,0,0,1,0,0),u}dispose(){this.canvas&&(this.canvas=null,this.gl=null),this.clearWebGLCaches()}clearWebGLCaches(){this.programCache={},this.textureCache={}}createTexture(t,e,s,i,n){const{NEAREST:r,TEXTURE_2D:a,RGBA:h,UNSIGNED_BYTE:c,CLAMP_TO_EDGE:u,TEXTURE_MAG_FILTER:d,TEXTURE_MIN_FILTER:f,TEXTURE_WRAP_S:g,TEXTURE_WRAP_T:p}=t,m=t.createTexture();return t.bindTexture(a,m),t.texParameteri(a,d,n||r),t.texParameteri(a,f,n||r),t.texParameteri(a,g,u),t.texParameteri(a,p,u),i?t.texImage2D(a,0,h,h,c,i):t.texImage2D(a,0,h,e,s,0,h,c,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 a=new Uint8Array(this.imageBuffer,0,r),h=new Uint8ClampedArray(this.imageBuffer,0,r);t.readPixels(0,0,i,n,t.RGBA,t.UNSIGNED_BYTE,a);const c=new ImageData(h,i,n);s.putImageData(c,0,0)}captureGPUInfo(){if(this.gpuInfo)return this.gpuInfo;const t=this.gl,e={renderer:"",vendor:""};if(!t)return e;const s=t.getExtension("WEBGL_debug_renderer_info");if(s){const i=t.getParameter(s.UNMASKED_RENDERER_WEBGL),n=t.getParameter(s.UNMASKED_VENDOR_WEBGL);i&&(e.renderer=i.toLowerCase()),n&&(e.vendor=n.toLowerCase())}return this.gpuInfo=e,e}}let _g;function Ox(){const{WebGLProbe:o}=xi();return o.queryWebGL(Rs()),bt.enableGLFiltering&&o.isSupported(bt.textureSize)?new yv({tileSize:bt.textureSize}):new Mx}function wg(){return!_g&&(!(arguments.length>0&&arguments[0]!==void 0)||arguments[0])&&(_g=Ox()),_g}const Dx=["filters","resizeFilter","src","crossOrigin","type"],_v=["cropX","cropY"];class Me extends ke{static getDefaults(){return T(T({},super.getDefaults()),Me.ownDefaults)}constructor(t,e){super(),E(this,"_lastScaleX",1),E(this,"_lastScaleY",1),E(this,"_filterScalingX",1),E(this,"_filterScalingY",1),this.filters=[],Object.assign(this,Me.ownDefaults),this.setOptions(e),this.cacheKey="texture".concat(Gn()),this.setElement(typeof t=="string"?(this.canvas&&Qs(this.canvas.getElement())||lo()).getElementById(t):t,e)}getElement(){return this._element}setElement(t){var e;let s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._element=t,this._originalElement=t,this._setWidthHeight(s),(e=t.classList)===null||e===void 0||e.add(Me.CSS_CANVAS),this.filters.length!==0&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){const e=wg(!1);e instanceof yv&&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&&xi().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([..._v,...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=[],a="",h="";if(!e)return[];if(this.hasCrop()){const c=Gn();n.push('<clipPath id="imageCrop_'+c+`">
74
+ `),s.join("")}toLive(t){const{x1:e,y1:s,x2:i,y2:n,r1:r,r2:o}=this.coords,h=this.type==="linear"?t.createLinearGradient(e,s,i,n):t.createRadialGradient(e,s,r,i,n,o);return this.colorStops.forEach(c=>{let{color:u,opacity:d,offset:f}=c;h.addColorStop(f,d!==void 0?new St(u).setAlpha(d).toRgba():u)}),h}static async fromObject(t){const{colorStops:e,gradientTransform:s}=t;return new this(E(E({},t),{},{colorStops:e?e.map(i=>E({},i)):void 0,gradientTransform:s?[...s]:void 0}))}static fromElement(t,e,s){const i=p0(t),n=e._findCenterFromElement();return new this(E({id:t.getAttribute("id")||void 0,type:g0(t),coords:_x(t,{width:s.viewBoxWidth||s.width,height:s.viewBoxHeight||s.height}),colorStops:yx(t,s.opacity),gradientUnits:i,gradientTransform:Ru(t.getAttribute("gradientTransform")||"")},i==="pixels"?{offsetX:e.width/2-n.x,offsetY:e.height/2-n.y}:{offsetX:0,offsetY:0}))}}k(ll,"type","Gradient"),G.setClass(ll,"gradient"),G.setClass(ll,"linear"),G.setClass(ll,"radial");const wx=["type","source","patternTransform"];class yg{get type(){return"pattern"}set type(t){Ki("warn","Setting type has no effect",t)}constructor(t){k(this,"repeat","repeat"),k(this,"offsetX",0),k(this,"offsetY",0),k(this,"crossOrigin",""),this.id=Wn(),Object.assign(this,t)}isImageSource(){return!!this.source&&typeof this.source.src=="string"}isCanvasSource(){return!!this.source&&!!this.source.toDataURL}sourceToString(){return this.isImageSource()?this.source.src:this.isCanvasSource()?this.source.toDataURL():""}toLive(t){return this.source&&(!this.isImageSource()||this.source.complete&&this.source.naturalWidth!==0&&this.source.naturalHeight!==0)?t.createPattern(this.source,this.repeat):null}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const{repeat:e,crossOrigin:s}=this;return E(E({},jr(this,t)),{},{type:"pattern",source:this.sourceToString(),repeat:e,crossOrigin:s,offsetX:kt(this.offsetX,mt.NUM_FRACTION_DIGITS),offsetY:kt(this.offsetY,mt.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=Aa(this.offsetX/e,0),h=Aa(this.offsetY/s,0),c=n==="repeat-y"||n==="no-repeat"?1+Math.abs(o||0):Aa(i.width/e,0),u=n==="repeat-x"||n==="no-repeat"?1+Math.abs(h||0):Aa(i.height/s,0);return['<pattern id="SVGID_'.concat(r,'" x="').concat(o,'" y="').concat(h,'" width="').concat(c,'" height="').concat(u,'">'),'<image x="0" y="0" width="'.concat(i.width,'" height="').concat(i.height,'" xlink:href="').concat(this.sourceToString(),'"></image>'),"</pattern>",""].join(`
75
+ `)}static async fromObject(t,e){let{type:s,source:i,patternTransform:n}=t,r=Lt(t,wx);const o=await Jh(i,E(E({},e),{},{crossOrigin:r.crossOrigin}));return new this(E(E({},r),{},{patternTransform:n&&n.slice(0),source:o}))}}k(yg,"type","Pattern"),G.setClass(yg),G.setClass(yg,"pattern");const xx=["path","left","top"],Sx=["d"];class Vr extends ke{constructor(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{path:s,left:i,top:n}=e,r=Lt(e,xx);super(),Object.assign(this,Vr.ownDefaults),this.setOptions(r),this._setPath(t||[],!0),typeof i=="number"&&this.set(wt,i),typeof n=="number"&&this.set(is,n)}_setPath(t,e){this.path=t0(Array.isArray(t)?t:h0(t)),this.setBoundingBox(e)}_findCenterFromElement(){const t=this._calcBoundsFromPath();return new O(t.left+t.width/2,t.top+t.height/2)}_renderPathCommands(t){const e=-this.pathOffset.x,s=-this.pathOffset.y;t.beginPath();for(const i of this.path)switch(i[0]){case"L":t.lineTo(i[1]+e,i[2]+s);break;case"M":t.moveTo(i[1]+e,i[2]+s);break;case"C":t.bezierCurveTo(i[1]+e,i[2]+s,i[3]+e,i[4]+s,i[5]+e,i[6]+s);break;case"Q":t.quadraticCurveTo(i[1]+e,i[2]+s,i[3]+e,i[4]+s);break;case"Z":t.closePath()}}_render(t){this._renderPathCommands(t),this._renderPaintInOrder(t)}toString(){return"#<Path (".concat(this.complexity(),'): { "top": ').concat(this.top,', "left": ').concat(this.left," }>")}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return E(E({},super.toObject(t)),{},{path:this.path.map(e=>e.slice())})}toDatalessObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=this.toObject(t);return this.sourcePath&&(delete e.path,e.sourcePath=this.sourcePath),e}_toSVG(){const t=l0(this.path,mt.NUM_FRACTION_DIGITS);return["<path ","COMMON_PARTS",'d="'.concat(t,`" stroke-linecap="round" />
76
+ `)]}_getOffsetTransform(){const t=mt.NUM_FRACTION_DIGITS;return" translate(".concat(kt(-this.pathOffset.x,t),", ").concat(kt(-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,rt,rt)}_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(...mg(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(...mg(i,n,r[1],r[2],r[1],r[2],r[3],r[4])),i=r[3],n=r[4];break;case"Z":i=e,n=s}return Ai(t)}_calcDimensions(){const t=this._calcBoundsFromPath();return E(E({},t),{},{pathOffset:new O(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=en(t,this.ATTRIBUTE_NAMES,s),{d:n}=i;return new this(n,E(E(E({},Lt(i,Sx)),e),{},{left:void 0,top:void 0}))}}k(Vr,"type","Path"),k(Vr,"cacheProperties",[...Zi,"path","fillRule"]),k(Vr,"ATTRIBUTE_NAMES",[...Xn,"d"]),G.setClass(Vr),G.setSVGClass(Vr);const Cx=["left","top","radius"],m0=["radius","startAngle","endAngle","counterClockwise"];class nn extends ke{static getDefaults(){return E(E({},super.getDefaults()),nn.ownDefaults)}constructor(t){super(),Object.assign(this,nn.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,Ut(this.startAngle),Ut(this.endAngle),this.counterClockwise),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get(Ve)}getRadiusY(){return this.get("radius")*this.get(gs)}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([...m0,...t])}_toSVG(){const t=(this.endAngle-this.startAngle)%360;if(t===0)return["<circle ","COMMON_PARTS",'cx="0" cy="0" ','r="',"".concat(this.radius),`" />
77
+ `];{const{radius:e}=this,s=Ut(this.startAngle),i=Ut(this.endAngle),n=qs(s)*e,r=Ks(s)*e,o=qs(i)*e,h=Ks(i)*e,c=t>180?1:0,u=this.counterClockwise?0:1;return['<path d="M '.concat(n," ").concat(r," A ").concat(e," ").concat(e," 0 ").concat(c," ").concat(u," ").concat(o," ").concat(h,'" '),"COMMON_PARTS",` />
78
+ `]}}static async fromElement(t,e,s){const i=en(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,radius:o=0}=i;return new this(E(E({},Lt(i,Cx)),{},{radius:o,left:n-o,top:r-o}))}static fromObject(t){return super._fromObject(t)}}k(nn,"type","Circle"),k(nn,"cacheProperties",[...Zi,...m0]),k(nn,"ownDefaults",{radius:0,startAngle:0,endAngle:360,counterClockwise:!1}),k(nn,"ATTRIBUTE_NAMES",["cx","cy","r",...Xn]),G.setClass(nn),G.setSVGClass(nn);const Ax=["x1","y1","x2","y2"],Tx=["x1","y1","x2","y2"],_g=["x1","x2","y1","y2"];class Gr extends ke{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,Gr.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(wt,r),typeof o=="number"&&this.set(is,o)}_setWidthHeight(){const{x1:t,y1:e,x2:s,y2:i}=this;this.width=Math.abs(s-t),this.height=Math.abs(i-e);const{left:n,top:r,width:o,height:h}=Ai([{x:t,y:e},{x:s,y:i}]),c=new O(n+o/2,r+h/2);this.setPositionByOrigin(c,rt,rt)}_set(t,e){return super._set(t,e),_g.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 O((this.x1+this.x2)/2,(this.y1+this.y2)/2)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return E(E({},super.toObject(t)),this.calcLinePoints())}_getNonTransformedDimensions(){const t=super._getNonTransformedDimensions();return this.strokeLineCap==="butt"&&(this.width===0&&(t.y-=this.strokeWidth),this.height===0&&(t.x-=this.strokeWidth)),t}calcLinePoints(){const{x1:t,x2:e,y1:s,y2:i,width:n,height:r}=this,o=t<=e?-1:1,h=s<=i?-1:1;return{x1:o*n/2,x2:o*-n/2,y1:h*r/2,y2:h*-r/2}}_toSVG(){const{x1:t,x2:e,y1:s,y2:i}=this.calcLinePoints();return["<line ","COMMON_PARTS",'x1="'.concat(t,'" y1="').concat(s,'" x2="').concat(e,'" y2="').concat(i,`" />
79
+ `)]}static async fromElement(t,e,s){const i=en(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],Lt(i,Ax))}static fromObject(t){let{x1:e,y1:s,x2:i,y2:n}=t,r=Lt(t,Tx);return this._fromObject(E(E({},r),{},{points:[e,s,i,n]}),{extraParam:"points"})}}k(Gr,"type","Line"),k(Gr,"cacheProperties",[...Zi,..._g]),k(Gr,"ATTRIBUTE_NAMES",Xn.concat(_g)),G.setClass(Gr),G.setSVGClass(Gr);class Wr extends ke{static getDefaults(){return E(E({},super.getDefaults()),Wr.ownDefaults)}constructor(t){super(),Object.assign(this,Wr.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),'" />']}}k(Wr,"type","Triangle"),k(Wr,"ownDefaults",{width:100,height:100}),G.setClass(Wr),G.setSVGClass(Wr);const v0=["rx","ry"];class rn extends ke{static getDefaults(){return E(E({},super.getDefaults()),rn.ownDefaults)}constructor(t){super(),Object.assign(this,rn.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(Ve)}getRy(){return this.get("ry")*this.get(gs)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...v0,...t])}_toSVG(){return["<ellipse ","COMMON_PARTS",'cx="0" cy="0" rx="'.concat(this.rx,'" ry="').concat(this.ry,`" />
80
+ `)]}_render(t){t.beginPath(),t.save(),t.transform(1,0,0,this.ry/this.rx,0,0),t.arc(0,0,this.rx,0,Ji,!1),t.restore(),this._renderPaintInOrder(t)}static async fromElement(t,e,s){const i=en(t,this.ATTRIBUTE_NAMES,s);return i.left=(i.left||0)-i.rx,i.top=(i.top||0)-i.ry,new this(i)}}function Ex(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}k(rn,"type","Ellipse"),k(rn,"cacheProperties",[...Zi,...v0]),k(rn,"ownDefaults",{rx:0,ry:0}),k(rn,"ATTRIBUTE_NAMES",[...Xn,"cx","cy","rx","ry"]),G.setClass(rn),G.setSVGClass(rn);const kx=["left","top"],b0={exactBoundingBox:!1};class si extends ke{static getDefaults(){return E(E({},super.getDefaults()),si.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),k(this,"strokeDiff",void 0),Object.assign(this,si.ownDefaults),this.setOptions(e),this.points=t;const{left:s,top:i}=e;this.initialized=!0,this.setBoundingBox(!0),typeof s=="number"&&this.set(wt,s),typeof i=="number"&&this.set(is,i)}isOpen(){return!0}_projectStrokeOnPoints(t){return Iv(this.points,t,this.isOpen())}_calcDimensions(t){t=E({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,strokeLineCap:this.strokeLineCap,strokeLineJoin:this.strokeLineJoin,strokeMiterLimit:this.strokeMiterLimit,strokeUniform:this.strokeUniform,strokeWidth:this.strokeWidth},t||{});const e=this.exactBoundingBox?this._projectStrokeOnPoints(t).map(c=>c.projectedPoint):this.points;if(e.length===0)return{left:0,top:0,width:0,height:0,pathOffset:new O,strokeOffset:new O,strokeDiff:new O};const s=Ai(e),i=Kh(E(E({},t),{},{scaleX:1,scaleY:1})),n=Ai(this.points.map(c=>Ee(c,i,!0))),r=new O(this.scaleX,this.scaleY);let o=s.left+s.width/2,h=s.top+s.height/2;return this.exactBoundingBox&&(o-=h*Math.tan(Ut(this.skewX)),h-=o*Math.tan(Ut(this.skewY))),E(E({},s),{},{pathOffset:new O(o,h),strokeOffset:new O(n.left,n.top).subtract(new O(s.left,s.top)).multiply(r),strokeDiff:new O(s.width,s.height).subtract(new O(n.width,n.height)).multiply(r)})}_findCenterFromElement(){const t=Ai(this.points);return new O(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 O(e+i/2,s+n/2),rt,rt)}isStrokeAccountedForInDimensions(){return this.exactBoundingBox}_getNonTransformedDimensions(){return this.exactBoundingBox?new O(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 O((e=t.width)!==null&&e!==void 0?e:o,(s=t.height)!==null&&s!==void 0?s:h)}else{var i,n;r=new O((i=t.width)!==null&&i!==void 0?i:this.width,(n=t.height)!==null&&n!==void 0?n:this.height)}return r.multiply(new O(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===Ve||t===gs)&&this.strokeUniform&&this.constructor.layoutProperties.includes("strokeUniform")||this.constructor.layoutProperties.includes(t))&&this.setDimensions(),i}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return E(E({},super.toObject(t)),{},{points:this.points.map(e=>{let{x:s,y:i}=e;return{x:s,y:i}})})}_toSVG(){const t=[],e=this.pathOffset.x,s=this.pathOffset.y,i=mt.NUM_FRACTION_DIGITS;for(let n=0,r=this.points.length;n<r;n++)t.push(kt(this.points[n].x-e,i),",",kt(this.points[n].y-s,i)," ");return["<".concat(this.constructor.type.toLowerCase()," "),"COMMON_PARTS",'points="'.concat(t.join(""),`" />
81
+ `)]}_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(Ex(t.getAttribute("points")),E(E({},Lt(en(t,this.ATTRIBUTE_NAMES,s),kx)),e))}static fromObject(t){return this._fromObject(t,{extraParam:"points"})}}k(si,"ownDefaults",b0),k(si,"type","Polyline"),k(si,"layoutProperties",[da,fa,"strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeWidth","strokeUniform","points"]),k(si,"cacheProperties",[...Zi,"points"]),k(si,"ATTRIBUTE_NAMES",[...Xn]),G.setClass(si),G.setSVGClass(si);class zu extends si{isOpen(){return!1}}k(zu,"ownDefaults",b0),k(zu,"type","Polygon"),G.setClass(zu),G.setSVGClass(zu);class y0 extends ke{isEmptyStyles(t){if(!this.styles||t!==void 0&&!this.styles[t])return!0;const e=t===void 0?this.styles:{line:this.styles[t]};for(const s in e)for(const i in e[s])for(const n in e[s][i])return!1;return!0}styleHas(t,e){if(!this.styles||e!==void 0&&!this.styles[e])return!1;const s=e===void 0?this.styles:{0:this.styles[e]};for(const i in s)for(const n in s[i])if(s[i][n][t]!==void 0)return!0;return!1}cleanStyle(t){if(!this.styles)return!1;const e=this.styles;let s,i,n=0,r=!0,o=0;for(const h in e){s=0;for(const c in e[h]){const u=e[h][c]||{};n++,u[t]!==void 0?(i?u[t]!==i&&(r=!1):i=u[t],u[t]===this[t]&&delete u[t]):r=!1,Object.keys(u).length!==0?s++:delete e[h][c]}s===0&&delete e[h]}for(let h=0;h<this._textLines.length;h++)o+=this._textLines[h].length;r&&n===o&&(this[t]=i,this.removeStyle(t))}removeStyle(t){if(!this.styles)return;const e=this.styles;let s,i,n;for(i in e){for(n in s=e[i],s)delete s[n][t],Object.keys(s[n]).length===0&&delete s[n];Object.keys(s).length===0&&delete e[i]}}_extendStyles(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t);this._getLineStyle(s)||this._setLineStyle(s);const n=Gf(E(E({},this._getStyleDeclaration(s,i)),e),r=>r!==void 0);this._setStyleDeclaration(s,i,n)}getSelectionStyles(t,e,s){const i=[];for(let n=t;n<(e||t);n++)i.push(this.getStyleAtPosition(n,s));return i}getStyleAtPosition(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t);return e?this.getCompleteStyleDeclaration(s,i):this._getStyleDeclaration(s,i)}setSelectionStyles(t,e,s){for(let i=e;i<(s||e);i++)this._extendStyles(i,t);this._forceClearCache=!0}_getStyleDeclaration(t,e){var s;const i=this.styles&&this.styles[t];return i&&(s=i[e])!==null&&s!==void 0?s:{}}getCompleteStyleDeclaration(t,e){return E(E({},jr(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]}}k(y0,"_styleProperties",z_);const Px=/ +/g,Mx=/"/g;function wg(a,t,e,s,i){return" ".concat(function(n,r){let{left:o,top:h,width:c,height:u}=r,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:mt.NUM_FRACTION_DIGITS;const f=el(ee,n,!1),[g,p,m,y]=[o,h,c,u].map(b=>kt(b,d));return"<rect ".concat(f,' x="').concat(g,'" y="').concat(p,'" width="').concat(m,'" height="').concat(y,'"></rect>')}(a,{left:t,top:e,width:s,height:i}),`
82
+ `)}const Ox=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let xg;class Pe extends y0{static getDefaults(){return E(E({},super.getDefaults()),Pe.ownDefaults)}constructor(t,e){super(),k(this,"__charBounds",[]),Object.assign(this,Pe.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=vg(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(Ti)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,s,i,n,r,o;for(let h=0,c=this._textLines.length;h<c;h++)if((this.textAlign===Ti||h!==c-1&&!this.isEndOfWrapping(h))&&(i=0,n=this._textLines[h],e=this.getLineWidth(h),e<this.width&&(o=this.textLines[h].match(this._reSpacesAndTabs)))){s=o.length,t=(this.width-e)/s;for(let u=0;u<=n.length;u++)r=this.__charBounds[h][u],this._reSpaceAndTab.test(n[u])?(r.width+=t,r.kernedWidth+=t,r.left+=i,i+=t):r.left+=i}}isEndOfWrapping(t){return t===this._textLines.length-1}missingNewlineOffset(t){return 1}get2DCursorLocation(t,e){const s=e?this._unwrappedTextLines:this._textLines;let i;for(i=0;i<s.length;i++){if(t<=s[i].length)return{lineIndex:i,charIndex:t};t-=s[i].length+this.missingNewlineOffset(i,e)}return{lineIndex:i-1,charIndex:s[i-1].length<t?s[i-1].length:t}}toString(){return"#<Text (".concat(this.complexity(),'): { "text": "').concat(this.text,'", "fontFamily": "').concat(this.fontFamily,'" }>')}_getCacheCanvasDimensions(){const t=super._getCacheCanvasDimensions(),e=this.fontSize;return t.width+=e*t.zoomX,t.height+=e*t.zoomY,t}_render(t){const e=this.path;e&&!e.isNotVisible()&&e._render(t),this._setTextStyles(t),this._renderTextLinesBackground(t),this._renderTextDecoration(t,"underline"),this._renderText(t),this._renderTextDecoration(t,"overline"),this._renderTextDecoration(t,"linethrough")}_renderText(t){this.paintFirst===Ge?(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 rt:t.textBaseline="middle";break;case"ascender":t.textBaseline=is;break;case"descender":t.textBaseline=Ff}t.font=this._getFontDeclaration(e,s)}calcTextWidth(){let t=this.getLineWidth(0);for(let e=1,s=this._textLines.length;e<s;e++){const i=this.getLineWidth(e);i>t&&(t=i)}return t}_renderTextLine(t,e,s,i,n,r){this._renderChars(t,e,s,i,n,r)}_renderTextLinesBackground(t){if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor"))return;const e=t.fillStyle,s=this._getLeftOffset();let i=this._getTopOffset();for(let n=0,r=this._textLines.length;n<r;n++){const o=this.getHeightOfLine(n);if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor",n)){i+=o;continue}const h=this._textLines[n].length,c=this._getLineLeftOffset(n);let u,d,f=0,g=0,p=this.getValueOfPropertyAt(n,0,"textBackgroundColor");for(let m=0;m<h;m++){const y=this.__charBounds[n][m];d=this.getValueOfPropertyAt(n,m,"textBackgroundColor"),this.path?(t.save(),t.translate(y.renderLeft,y.renderTop),t.rotate(y.angle),t.fillStyle=d,d&&t.fillRect(-y.width/2,-o/this.lineHeight*(1-this._fontSizeFraction),y.width,o/this.lineHeight),t.restore()):d!==p?(u=s+c+g,this.direction==="rtl"&&(u=this.width-u-f),t.fillStyle=p,p&&t.fillRect(u,i,f,o/this.lineHeight),g=y.left,f=y.width,p=d):f+=y.kernedWidth}d&&!this.path&&(u=s+c+g,this.direction==="rtl"&&(u=this.width-u-f),t.fillStyle=d,t.fillRect(u,i,f,o/this.lineHeight)),i+=o}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,s,i){const n=Yh.getFontCache(e),r=this._getFontDeclaration(e),o=s+t,h=s&&r===this._getFontDeclaration(i),c=e.fontSize/this.CACHE_FONT_SIZE;let u,d,f,g;if(s&&n[s]!==void 0&&(f=n[s]),n[t]!==void 0&&(g=u=n[t]),h&&n[o]!==void 0&&(d=n[o],g=d-f),u===void 0||f===void 0||d===void 0){const p=function(){return xg||(xg=ps({width:0,height:0}).getContext("2d")),xg}();this._setTextStyles(p,e,!0),u===void 0&&(g=u=p.measureText(t).width,n[t]=u),f===void 0&&h&&s&&(f=p.measureText(s).width,n[s]=f),h&&d===void 0&&(d=p.measureText(o).width,n[o]=d,g=d-f)}return{width:u*c,kernedWidth:g*c}}getHeightOfChar(t,e){return this.getValueOfPropertyAt(t,e,"fontSize")}measureLine(t){const e=this._measureLine(t);return this.charSpacing!==0&&(e.width-=this._getWidthOfCharSpacing()),e.width<0&&(e.width=0),e}_measureLine(t){let e,s,i=0;const n=this.pathSide===$t,r=this.path,o=this._textLines[t],h=o.length,c=new Array(h);this.__charBounds[t]=c;for(let u=0;u<h;u++){const d=o[u];s=this._getGraphemeBox(d,t,u,e),c[u]=s,i+=s.kernedWidth,e=d}if(c[h]={left:s?s.left+s.width:0,width:0,kernedWidth:0,height:this.fontSize,deltaY:0},r&&r.segmentsInfo){let u=0;const d=r.segmentsInfo[r.segmentsInfo.length-1].length;switch(this.textAlign){case wt:u=n?d-i:0;break;case rt:u=(d-i)/2;break;case $t:u=n?0:d-i}u+=this.pathStartOffset*(n?-1:1);for(let f=n?h-1:0;n?f>=0:f<h;n?f--:f++)s=c[f],u>d?u%=d:u<0&&(u+=d),this._setGraphemeOnPath(u,s),u+=s.kernedWidth}return{width:i,numOfSpaces:0}}_setGraphemeOnPath(t,e){const s=t+e.kernedWidth/2,i=this.path,n=o0(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===$t?Math.PI:0)}_getGraphemeBox(t,e,s,i,n){const r=this.getCompleteStyleDeclaration(e,s),o=i?this.getCompleteStyleDeclaration(e,s-1):{},h=this._measureChar(t,r,i,o);let c,u=h.kernedWidth,d=h.width;this.charSpacing!==0&&(c=this._getWidthOfCharSpacing(),d+=c,u+=c);const f={width:d,left:0,height:r.fontSize,kernedWidth:u,deltaY:r.deltaY};if(s>0&&!n){const g=this.__charBounds[e][s-1];f.left=g.left+g.width+h.kernedWidth-h.width}return f}getHeightOfLine(t){if(this.__lineHeights[t])return this.__lineHeights[t];let e=this.getHeightOfChar(t,0);for(let s=1,i=this._textLines[t].length;s<i;s++)e=Math.max(this.getHeightOfChar(t,s),e);return this.__lineHeights[t]=e*this.lineHeight*this._fontSizeMult}calcTextHeight(){let t,e=0;for(let s=0,i=this._textLines.length;s<i;s++)t=this.getHeightOfLine(s),e+=s===i-1?t/this.lineHeight:t;return e}_getLeftOffset(){return this.direction==="ltr"?-this.width/2:this.width/2}_getTopOffset(){return-this.height/2}_renderTextCommon(t,e){t.save();let s=0;const i=this._getLeftOffset(),n=this._getTopOffset();for(let r=0,o=this._textLines.length;r<o;r++){const h=this.getHeightOfLine(r),c=h/this.lineHeight,u=this._getLineLeftOffset(r);this._renderTextLine(e,t,this._textLines[r],i+u,n+s+c,r),s+=h}t.restore()}_renderTextFill(t){(this.fill||this.styleHas(ee))&&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(Ti),c=this.path,u=!h&&this.charSpacing===0&&this.isEmptyStyles(r)&&!c,d=this.direction==="ltr",f=this.direction==="ltr"?1:-1,g=e.direction;let p,m,y,b,x,C="",S=0;if(e.save(),g!==this.direction&&(e.canvas.setAttribute("dir",d?"ltr":"rtl"),e.direction=d?"ltr":"rtl",e.textAlign=d?wt:$t),n-=o*this._fontSizeFraction/this.lineHeight,u)return this._renderChar(t,e,r,0,s.join(""),i,n),void e.restore();for(let T=0,P=s.length-1;T<=P;T++)b=T===P||this.charSpacing||c,C+=s[T],y=this.__charBounds[r][T],S===0?(i+=f*(y.kernedWidth-y.width),S+=y.width):S+=y.kernedWidth,h&&!b&&this._reSpaceAndTab.test(s[T])&&(b=!0),b||(p=p||this.getCompleteStyleDeclaration(r,T),m=this.getCompleteStyleDeclaration(r,T+1),b=Du(p,m,!1)),b&&(c?(e.save(),e.translate(y.renderLeft,y.renderTop),e.rotate(y.angle),this._renderChar(t,e,r,T,C,-S/2,0),e.restore()):(x=i,this._renderChar(t,e,r,T,C,x,n)),C="",p=m,i+=f*S,S=0);e.restore()}_applyPatternGradientTransformText(t){const e=this.width+this.strokeWidth,s=this.height+this.strokeWidth,i=ps({width:e,height:s}),n=i.getContext("2d");return i.width=e,i.height=s,n.beginPath(),n.moveTo(0,0),n.lineTo(e,0),n.lineTo(e,s),n.lineTo(0,s),n.closePath(),n.translate(e/2,s/2),n.fillStyle=t.toLive(n),this._applyPatternGradientTransform(n,t),n.fill(),n.createPattern(i,"no-repeat")}handleFiller(t,e,s){let i,n;return 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),c=this.getCompleteStyleDeclaration(s,i),u=t==="fillText"&&c.fill,d=t==="strokeText"&&c.stroke&&c.strokeWidth;if(d||u){if(e.save(),e.font=this._getFontDeclaration(c),h.textBackgroundColor&&this._removeShadow(e),h.deltaY&&(o+=h.deltaY),u){const f=this._setFillStyles(e,c);e.fillText(n,r-f.offsetX,o-f.offsetY)}if(d){const f=this._setStrokeStyles(e,c);e.strokeText(n,r-f.offsetX,o-f.offsetY)}e.restore()}}setSuperscript(t,e){this._setScript(t,e,this.superscript)}setSubscript(t,e){this._setScript(t,e,this.subscript)}_setScript(t,e,s){const i=this.get2DCursorLocation(t,!0),n=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"fontSize"),r=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"deltaY"),o={fontSize:n*s.size,deltaY:r+n*s.baseline};this.setSelectionStyles(o,t,e)}_getLineLeftOffset(t){const e=this.getLineWidth(t),s=this.width-e,i=this.textAlign,n=this.direction,r=this.isEndOfWrapping(t);let o=0;return i===Ti||i===il&&!r||i===sl&&!r||i===Su&&!r?0:(i===rt&&(o=s/2),i===$t&&(o=s),i===il&&(o=s/2),i===sl&&(o=s),n==="rtl"&&(i===$t||i===Ti||i===sl?o=0:i===wt||i===Su?o=-s:i!==rt&&i!==il||(o=-s/2)),o)}_clearCache(){this._forceClearCache=!1,this.__lineWidths=[],this.__lineHeights=[],this.__charBounds=[]}getLineWidth(t){if(this.__lineWidths[t]!==void 0)return this.__lineWidths[t];const{width:e}=this.measureLine(t);return this.__lineWidths[t]=e,e}_getWidthOfCharSpacing(){return this.charSpacing!==0?this.fontSize*this.charSpacing/1e3:0}getValueOfPropertyAt(t,e,s){var i;return(i=this._getStyleDeclaration(t,e)[s])!==null&&i!==void 0?i:this[s]}_renderTextDecoration(t,e){if(!this[e]&&!this.styleHas(e))return;let s=this._getTopOffset();const i=this._getLeftOffset(),n=this.path,r=this._getWidthOfCharSpacing(),o=e==="linethrough"?.5:e==="overline"?1:0,h=this.offsets[e];for(let c=0,u=this._textLines.length;c<u;c++){const d=this.getHeightOfLine(c);if(!this[e]&&!this.styleHas(e,c)){s+=d;continue}const f=this._textLines[c],g=d/this.lineHeight,p=this._getLineLeftOffset(c);let m=0,y=0,b=this.getValueOfPropertyAt(c,0,e),x=this.getValueOfPropertyAt(c,0,ee),C=this.getValueOfPropertyAt(c,0,Hr),S=b,T=x,P=C;const M=s+g*(1-this._fontSizeFraction);let D=this.getHeightOfChar(c,0),R=this.getValueOfPropertyAt(c,0,"deltaY");for(let F=0,I=f.length;F<I;F++){const j=this.__charBounds[c][F];S=this.getValueOfPropertyAt(c,F,e),T=this.getValueOfPropertyAt(c,F,ee),P=this.getValueOfPropertyAt(c,F,Hr);const K=this.getHeightOfChar(c,F),L=this.getValueOfPropertyAt(c,F,"deltaY");if(n&&S&&T){const z=this.fontSize*P/1e3;t.save(),t.fillStyle=x,t.translate(j.renderLeft,j.renderTop),t.rotate(j.angle),t.fillRect(-j.kernedWidth/2,h*K+L-o*z,j.kernedWidth,z),t.restore()}else if((S!==b||T!==x||K!==D||P!==C||L!==R)&&y>0){const z=this.fontSize*C/1e3;let Z=i+p+m;this.direction==="rtl"&&(Z=this.width-Z-y),b&&x&&C&&(t.fillStyle=x,t.fillRect(Z,M+h*D+R-o*z,y,z)),m=j.left,y=j.width,b=S,C=P,x=T,D=K,R=L}else y+=j.kernedWidth}let V=i+p+m;this.direction==="rtl"&&(V=this.width-V-y),t.fillStyle=T;const H=this.fontSize*P/1e3;S&&T&&P&&t.fillRect(V,M+h*D+R-o*H,y-r,H),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(",")||Pe.genericFonts.includes(t.toLowerCase())?t:'"'.concat(t,'"');return[e,s,"".concat(n?this.CACHE_FONT_SIZE:i,"px"),r].join(" ")}render(t){this.visible&&(this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(this._forceClearCache&&this.initDimensions(),super.render(t)))}graphemeSplit(t){return Ou(t)}_splitTextIntoLines(t){const e=t.split(this._reNewline),s=new Array(e.length),i=[`
83
+ `];let n=[];for(let r=0;r<e.length;r++)s[r]=this.graphemeSplit(e[r]),n=n.concat(s[r],i);return n.pop(),{_unwrappedLines:s,lines:e,graphemeText:n,graphemeLines:s}}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return E(E({},super.toObject([...cv,...t])),{},{styles:Nv(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=en(t,Pe.ATTRIBUTE_NAMES,s),n=E(E({},e),i),{textAnchor:r=wt,textDecoration:o="",dx:h=0,dy:c=0,top:u=0,left:d=0,fontSize:f=Rf,strokeWidth:g=1}=n,p=Lt(n,Ox),m=new this((t.textContent||"").replace(/^\s+|\s+$|\n+/g,"").replace(/\s+/g," "),E({left:d+h,top:u+c,underline:o.includes("underline"),overline:o.includes("overline"),linethrough:o.includes("line-through"),strokeWidth:0,fontSize:f},p)),y=m.getScaledHeight()/m.height,b=((m.height+m.strokeWidth)*m.lineHeight-m.height)*y,x=m.getScaledHeight()+b;let C=0;return r===rt&&(C=m.getScaledWidth()/2),r===$t&&(C=m.getScaledWidth()),m.set({left:m.left-C,top:m.top-(x-m.fontSize*(.07+m._fontSizeFraction))/m.lineHeight,strokeWidth:g}),m}static fromObject(t){return this._fromObject(E(E({},t),{},{styles:Bv(t.styles||{},t.text)}),{extraParam:"text"})}}k(Pe,"textLayoutProperties",lv),k(Pe,"cacheProperties",[...Zi,...cv]),k(Pe,"ownDefaults",V_),k(Pe,"type","Text"),k(Pe,"genericFonts",["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong"]),k(Pe,"ATTRIBUTE_NAMES",Xn.concat("x","y","dx","dy","font-family","font-style","font-weight","font-size","letter-spacing","text-decoration","text-anchor")),Dv(Pe,[class extends ov{_toSVG(){const a=this._getSVGLeftTopOffsets(),t=this._getSVGTextAndBg(a.textTop,a.textLeft);return this._wrapSVGTextAndBg(t)}toSVG(a){const t=this._createBaseSVGMarkup(this._toSVG(),{reviver:a,noStyle:!0,withShadow:!0}),e=this.path;return e?t+e._createBaseSVGMarkup(e._toSVG(),{reviver:a,withShadow:!0,additionalTransform:va(this.calcOwnMatrix())}):t}_getSVGLeftTopOffsets(){return{textLeft:-this.width/2,textTop:-this.height/2,lineTop:this.getHeightOfLine(0)}}_wrapSVGTextAndBg(a){let{textBgRects:t,textSpans:e}=a;const s=this.getSvgTextDecoration(this);return[t.join(""),' <text xml:space="preserve" ','font-family="'.concat(this.fontFamily.replace(Mx,"'"),'" '),'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>
84
+ `]}_getSVGTextAndBg(a,t){const e=[],s=[];let i,n=a;this.backgroundColor&&s.push(...wg(this.backgroundColor,-this.width/2,-this.height/2,this.width,this.height));for(let r=0,o=this._textLines.length;r<o;r++)i=this._getLineLeftOffset(r),this.direction==="rtl"&&(i+=this.width),(this.textBackgroundColor||this.styleHas("textBackgroundColor",r))&&this._setSVGTextLineBg(s,r,t+i,n),this._setSVGTextLineText(e,r,t+i,n),n+=this.getHeightOfLine(r);return{textSpans:e,textBgRects:s}}_createTextCharSpan(a,t,e,s,i){const n=mt.NUM_FRACTION_DIGITS,r=this.getSvgSpanStyles(t,a!==a.trim()||!!a.match(Px)),o=r?'style="'.concat(r,'"'):"",h=t.deltaY,c=h?' dy="'.concat(kt(h,n),'" '):"",{angle:u,renderLeft:d,renderTop:f,width:g}=i;let p="";if(d!==void 0){const m=g/2;u&&(p=' rotate="'.concat(kt(Ci(u),n),'"'));const y=Ir({angle:Ci(u)});y[4]=d,y[5]=f;const b=new O(-m,0).transform(y);e=b.x,s=b.y}return'<tspan x="'.concat(kt(e,n),'" y="').concat(kt(s,n),'" ').concat(c).concat(p).concat(o,">").concat(jv(a),"</tspan>")}_setSVGTextLineText(a,t,e,s){const i=this.getHeightOfLine(t),n=this.textAlign.includes(Ti),r=this._textLines[t];let o,h,c,u,d,f="",g=0;s+=i*(1-this._fontSizeFraction)/this.lineHeight;for(let p=0,m=r.length-1;p<=m;p++)d=p===m||this.charSpacing||this.path,f+=r[p],c=this.__charBounds[t][p],g===0?(e+=c.kernedWidth-c.width,g+=c.width):g+=c.kernedWidth,n&&!d&&this._reSpaceAndTab.test(r[p])&&(d=!0),d||(o=o||this.getCompleteStyleDeclaration(t,p),h=this.getCompleteStyleDeclaration(t,p+1),d=Du(o,h,!0)),d&&(u=this._getStyleDeclaration(t,p),a.push(this._createTextCharSpan(f,u,e,s,c)),f="",o=h,this.direction==="rtl"?e-=g:e+=g,g=0)}_setSVGTextLineBg(a,t,e,s){const i=this._textLines[t],n=this.getHeightOfLine(t)/this.lineHeight;let r,o=0,h=0,c=this.getValueOfPropertyAt(t,0,"textBackgroundColor");for(let u=0;u<i.length;u++){const{left:d,width:f,kernedWidth:g}=this.__charBounds[t][u];r=this.getValueOfPropertyAt(t,u,"textBackgroundColor"),r!==c?(c&&a.push(...wg(c,e+h,s,o,n)),h=d,o=f,c=r):o+=g}r&&a.push(...wg(c,e+h,s,o,n))}_getSVGLineTopOffset(a){let t,e=0;for(t=0;t<a;t++)e+=this.getHeightOfLine(t);const s=this.getHeightOfLine(t);return{lineTop:e,offset:(this._fontSizeMult-this._fontSizeFraction)*s/(this.lineHeight*this._fontSizeMult)}}getSvgStyles(a){return"".concat(super.getSvgStyles(a)," text-decoration-thickness: ").concat(kt(this.textDecorationThickness*this.getObjectScaling().y/10,mt.NUM_FRACTION_DIGITS),"%; white-space: pre;")}getSvgSpanStyles(a,t){const{fontFamily:e,strokeWidth:s,stroke:i,fill:n,fontSize:r,fontStyle:o,fontWeight:h,deltaY:c,textDecorationThickness:u,linethrough:d,overline:f,underline:g}=a,p=this.getSvgTextDecoration({underline:g??this.underline,overline:f??this.overline,linethrough:d??this.linethrough}),m=u||this.textDecorationThickness;return[i?el(Ge,i):"",s?"stroke-width: ".concat(s,"; "):"",e?"font-family: ".concat(e.includes("'")||e.includes('"')?e:"'".concat(e,"'"),"; "):"",r?"font-size: ".concat(r,"px; "):"",o?"font-style: ".concat(o,"; "):"",h?"font-weight: ".concat(h,"; "):"",p?"text-decoration: ".concat(p,"; text-decoration-thickness: ").concat(kt(m*this.getObjectScaling().y/10,mt.NUM_FRACTION_DIGITS),"%; "):"",n?el(ee,n):"",c?"baseline-shift: ".concat(-c,"; "):"",t?"white-space: pre; ":""].join("")}getSvgTextDecoration(a){return["overline","underline","line-through"].filter(t=>a[t.replace("-","")]).join(" ")}}]),G.setClass(Pe),G.setSVGClass(Pe);class Dx{constructor(t){k(this,"target",void 0),k(this,"__mouseDownInPlace",!1),k(this,"__dragStartFired",!1),k(this,"__isDraggingOver",!1),k(this,"__dragStartSelection",void 0),k(this,"__dragImageDisposer",void 0),k(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 O(r.flipX?-1:1,r.flipY?-1:1),c=r._getCursorBoundaries(i),u=new O(c.left+c.leftOffset,c.top+c.topOffset).multiply(h).transform(r.calcTransformMatrix()),d=o.getScenePoint(t).subtract(u),f=r.getCanvasRetinaScaling(),g=r.getBoundingRect(),p=u.subtract(new O(g.left,g.top)),m=o.viewportTransform,y=p.add(d).transform(m,!0),b=r.backgroundColor,x=cg(r.styles);r.backgroundColor="";const C={stroke:"transparent",fill:"transparent",textBackgroundColor:"transparent"};r.setSelectionStyles(C,0,i),r.setSelectionStyles(C,n,r.text.length),r.dirty=!0;const S=r.toCanvasElement({enableRetinaScaling:o.enableRetinaScaling,viewportTransform:!0});r.backgroundColor=b,r.styles=x,r.dirty=!0,Nu(S,{position:"fixed",left:"".concat(-S.width,"px"),border:ze,width:"".concat(S.width/f,"px"),height:"".concat(S.height/f,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{S.remove()},Js(t.target||this.target.hiddenTextarea).body.appendChild(S),(s=t.dataTransfer)===null||s===void 0||s.setDragImage(S,y.x,y.y)}onDragStart(t){this.__dragStartFired=!0;const e=this.target,s=this.isActive();if(s&&t.dataTransfer){const i=this.__dragStartSelection={selectionStart:e.selectionStart,selectionEnd:e.selectionEnd},n=e._text.slice(i.selectionStart,i.selectionEnd).join(""),r=E({text:e.text,value:n},i);t.dataTransfer.setData("text/plain",n),t.dataTransfer.setData("application/fabric",JSON.stringify({value:n,styles:e.getSelectionStyles(i.selectionStart,i.selectionEnd,!0)})),t.dataTransfer.effectAllowed="copyMove",this.setDragImage(t,r)}return e.abortCursorAnimation(),s}canDrop(t){if(this.target.editable&&!this.target.getActiveControl()&&!t.defaultPrevented){if(this.isActive()&&this.__dragStartSelection){const e=this.target.getSelectionStartFromPointer(t),s=this.__dragStartSelection;return e<s.selectionStart||e>s.selectionEnd}return!0}return!1}targetCanDrop(t){return this.target.canDrop(t)}dragEnterHandler(t){let{e}=t;const s=this.targetCanDrop(e);!this.__isDraggingOver&&s&&(this.__isDraggingOver=!0)}dragOverHandler(t){const{e}=t,s=this.targetCanDrop(e);!this.__isDraggingOver&&s?this.__isDraggingOver=!0:this.__isDraggingOver&&!s&&(this.__isDraggingOver=!1),this.__isDraggingOver&&(e.preventDefault(),t.canDrop=!0,t.dropTarget=this.target)}dragLeaveHandler(){(this.__isDraggingOver||this.isActive())&&(this.__isDraggingOver=!1)}dropHandler(t){var e;const{e:s}=t,i=s.defaultPrevented;this.__isDraggingOver=!1,s.preventDefault();let n=(e=s.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain");if(n&&!i){const r=this.target,o=r.canvas;let h=r.getSelectionStartFromPointer(s);const{styles:c}=s.dataTransfer.types.includes("application/fabric")?JSON.parse(s.dataTransfer.getData("application/fabric")):{},u=n[Math.max(0,n.length-1)],d=0;if(this.__dragStartSelection){const f=this.__dragStartSelection.selectionStart,g=this.__dragStartSelection.selectionEnd;h>f&&h<=g?h=f:h>g&&(h-=g-f),r.removeChars(f,g),delete this.__dragStartSelection}r._reNewline.test(u)&&(r._reNewline.test(r._text[h])||h===r._text.length)&&(n=n.trimEnd()),t.didDrop=!0,t.dropTarget=r,r.insertChars(n,c,h),o.setActiveObject(r),r.enterEditing(s),r.selectionStart=Math.min(h+d,r._text.length),r.selectionEnd=Math.min(r.selectionStart+n.length,r._text.length),r.hiddenTextarea.value=r.text,r._updateTextarea(),r.hiddenTextarea.focus(),r.fire(uu,{index:h+d,action:"drop"}),o.fire("text:changed",{target:r}),o.contextTopDirty=!0,o.requestRenderAll()}}dragEndHandler(t){let{e}=t;if(this.isActive()&&this.__dragStartFired&&this.__dragStartSelection){var s;const i=this.target,n=this.target.canvas,{selectionStart:r,selectionEnd:o}=this.__dragStartSelection,h=((s=e.dataTransfer)===null||s===void 0?void 0:s.dropEffect)||ze;h===ze?(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(uu,{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 _0=/[ \n\.,;!\?\-]/;class Rx extends Pe{constructor(){super(...arguments),k(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 ag({startValue:this._currentCursorOpacity,endValue:e,duration:s,delay:i,onComplete:n,abort:()=>!this.canvas||this.selectionStart!==this.selectionEnd,onChange:r=>{this._currentCursorOpacity=r,this.renderCursorOrSelection()}})}_tick(t){this._currentTickState=this._animateCursor({toValue:0,duration:this.cursorDuration/2,delay:Math.max(t||0,100),onComplete:this._onTickComplete})}_onTickComplete(){var t;(t=this._currentTickCompleteState)===null||t===void 0||t.abort(),this._currentTickCompleteState=this._animateCursor({toValue:1,duration:this.cursorDuration,onComplete:this._tick})}initDelayedCursor(t){this.abortCursorAnimation(),this._tick(t?0:this.cursorDelay)}abortCursorAnimation(){let t=!1;[this._currentTickState,this._currentTickCompleteState].forEach(e=>{e&&!e.isDone()&&(t=!0,e.abort())}),this._currentCursorOpacity=1,t&&this.clearContextTop()}restartCursorIfNeeded(){[this._currentTickState,this._currentTickCompleteState].some(t=>!t||t.isDone())&&this.initDelayedCursor()}selectAll(){return this.selectionStart=0,this.selectionEnd=this._text.length,this._fireSelectionChanged(),this._updateTextarea(),this}cmdAll(){this.selectAll(),this.renderCursorOrSelection()}getSelectedText(){return this._text.slice(this.selectionStart,this.selectionEnd).join("")}findWordBoundaryLeft(t){let e=0,s=t-1;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s--;for(;/\S/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findWordBoundaryRight(t){let e=0,s=t;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s++;for(;/\S/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}findLineBoundaryLeft(t){let e=0,s=t-1;for(;!/\n/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findLineBoundaryRight(t){let e=0,s=t;for(;!/\n/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}searchWordBoundary(t,e){const s=this._text;let i=t>0&&this._reSpace.test(s[t])&&(e===-1||!Lf.test(s[t-1]))?t-1:t,n=s[i];for(;i>0&&i<s.length&&!_0.test(n);)i+=e,n=s[i];return e===-1&&_0.test(n)&&i++,i}selectWord(t){var e;t=(e=t)!==null&&e!==void 0?e:this.selectionStart;const s=this.searchWordBoundary(t,-1),i=Math.max(s,this.searchWordBoundary(t,1));this.selectionStart=s,this.selectionEnd=i,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(t){var e;t=(e=t)!==null&&e!==void 0?e:this.selectionStart;const s=this.findLineBoundaryLeft(t),i=this.findLineBoundaryRight(t);this.selectionStart=s,this.selectionEnd=i,this._fireSelectionChanged(),this._updateTextarea()}enterEditing(t){!this.isEditing&&this.editable&&(this.enterEditingImpl(),this.fire("editing:entered",t?{e:t}:void 0),this._fireSelectionChanged(),this.canvas&&(this.canvas.fire("text:editing:entered",{target:this,e:t}),this.canvas.requestRenderAll()))}enterEditingImpl(){this.canvas&&(this.canvas.calcOffset(),this.canvas.textEditingManager.exitTextEditing()),this.isEditing=!0,this.initHiddenTextarea(),this.hiddenTextarea.focus(),this.hiddenTextarea.value=this.text,this._updateTextarea(),this._saveEditingProps(),this._setEditingProps(),this._textBeforeEdit=this.text,this._tick()}updateSelectionOnMouseMove(t){if(this.getActiveControl())return;const e=this.hiddenTextarea;Js(e).activeElement!==e&&e.focus();const s=this.getSelectionStartFromPointer(t),i=this.selectionStart,n=this.selectionEnd;(s===this.__selectionStartOnMouseDown&&i!==n||i!==s&&n!==s)&&(s>this.__selectionStartOnMouseDown?(this.selectionStart=this.__selectionStartOnMouseDown,this.selectionEnd=s):(this.selectionStart=s,this.selectionEnd=this.__selectionStartOnMouseDown),this.selectionStart===i&&this.selectionEnd===n||(this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()))}_setEditingProps(){this.hoverCursor="text",this.canvas&&(this.canvas.defaultCursor=this.canvas.moveCursor="text"),this.borderColor=this.editingBorderColor,this.hasControls=this.selectable=!1,this.lockMovementX=this.lockMovementY=!0}fromStringToGraphemeSelection(t,e,s){const i=s.slice(0,t),n=this.graphemeSplit(i).length;if(t===e)return{selectionStart:n,selectionEnd:n};const r=s.slice(t,e);return{selectionStart:n,selectionEnd:n+this.graphemeSplit(r).length}}fromGraphemeToStringSelection(t,e,s){const i=s.slice(0,t).join("").length;return t===e?{selectionStart:i,selectionEnd:i}:{selectionStart:i,selectionEnd:i+s.slice(t,e).join("").length}}_updateTextarea(){if(this.cursorOffsetCache={},this.hiddenTextarea){if(!this.inCompositionMode){const t=this.fromGraphemeToStringSelection(this.selectionStart,this.selectionEnd,this._text);this.hiddenTextarea.selectionStart=t.selectionStart,this.hiddenTextarea.selectionEnd=t.selectionEnd}this.updateTextareaPosition()}}updateFromTextArea(){if(!this.hiddenTextarea)return;this.cursorOffsetCache={};const t=this.hiddenTextarea;this.text=t.value,this.set("dirty",!0),this.initDimensions(),this.setCoords();const e=this.fromStringToGraphemeSelection(t.selectionStart,t.selectionEnd,t.value);this.selectionEnd=this.selectionStart=e.selectionEnd,this.inCompositionMode||(this.selectionStart=e.selectionStart),this.updateTextareaPosition()}updateTextareaPosition(){if(this.selectionStart===this.selectionEnd){const t=this._calcTextareaPosition();this.hiddenTextarea.style.left=t.left,this.hiddenTextarea.style.top=t.top}}_calcTextareaPosition(){if(!this.canvas)return{left:"1px",top:"1px"};const t=this.inCompositionMode?this.compositionStart:this.selectionStart,e=this._getCursorBoundaries(t),s=this.get2DCursorLocation(t),i=s.lineIndex,n=s.charIndex,r=this.getValueOfPropertyAt(i,n,"fontSize")*this.lineHeight,o=e.leftOffset,h=this.getCanvasRetinaScaling(),c=this.canvas.upperCanvasEl,u=c.width/h,d=c.height/h,f=u-r,g=d-r,p=new O(e.left+o,e.top+e.topOffset+r).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new O(c.clientWidth/u,c.clientHeight/d));return p.x<0&&(p.x=0),p.x>f&&(p.x=f),p.y<0&&(p.y=0),p.y>g&&(p.y=g),p.x+=this.canvas._offset.left,p.y+=this.canvas._offset.top,{left:"".concat(p.x,"px"),top:"".concat(p.y,"px"),fontSize:"".concat(r,"px"),charHeight:r}}_saveEditingProps(){this._savedProps={hasControls:this.hasControls,borderColor:this.borderColor,lockMovementX:this.lockMovementX,lockMovementY:this.lockMovementY,hoverCursor:this.hoverCursor,selectable:this.selectable,defaultCursor:this.canvas&&this.canvas.defaultCursor,moveCursor:this.canvas&&this.canvas.moveCursor}}_restoreEditingProps(){this._savedProps&&(this.hoverCursor=this._savedProps.hoverCursor,this.hasControls=this._savedProps.hasControls,this.borderColor=this._savedProps.borderColor,this.selectable=this._savedProps.selectable,this.lockMovementX=this._savedProps.lockMovementX,this.lockMovementY=this._savedProps.lockMovementY,this.canvas&&(this.canvas.defaultCursor=this._savedProps.defaultCursor||this.canvas.defaultCursor,this.canvas.moveCursor=this._savedProps.moveCursor||this.canvas.moveCursor),delete this._savedProps)}_exitEditing(){const t=this.hiddenTextarea;this.selected=!1,this.isEditing=!1,t&&(t.blur&&t.blur(),t.parentNode&&t.parentNode.removeChild(t)),this.hiddenTextarea=null,this.abortCursorAnimation(),this.selectionStart!==this.selectionEnd&&this.clearContextTop()}exitEditingImpl(){this._exitEditing(),this.selectionEnd=this.selectionStart,this._restoreEditingProps(),this._forceClearCache&&(this.initDimensions(),this.setCoords())}exitEditing(){const t=this._textBeforeEdit!==this.text;return this.exitEditingImpl(),this.fire("editing:exited"),t&&this.fire(fu),this.canvas&&(this.canvas.fire("text:editing:exited",{target:this}),t&&this.canvas.fire("object:modified",{target:this})),this}_removeExtraneousStyles(){for(const t in this.styles)this._textLines[t]||delete this.styles[t]}removeStyleFromTo(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t,!0),{lineIndex:n,charIndex:r}=this.get2DCursorLocation(e,!0);if(s!==n){if(this.styles[s])for(let o=i;o<this._unwrappedTextLines[s].length;o++)delete this.styles[s][o];if(this.styles[n])for(let o=r;o<this._unwrappedTextLines[n].length;o++){const h=this.styles[n][o];h&&(this.styles[s]||(this.styles[s]={}),this.styles[s][i+o-r]=h)}for(let o=s+1;o<=n;o++)delete this.styles[o];this.shiftLineStyles(n,s-n)}else if(this.styles[s]){const o=this.styles[s],h=r-i;for(let c=i;c<r;c++)delete o[c];for(const c in this.styles[s]){const u=parseInt(c,10);u>=r&&(o[u-h]=o[c],delete o[c])}}}shiftLineStyles(t,e){const s=Object.assign({},this.styles);for(const i in this.styles){const n=parseInt(i,10);n>t&&(this.styles[n+e]=s[n],s[n-e]||delete this.styles[n])}}insertNewlineStyleObject(t,e,s,i){const n={},r=this._unwrappedTextLines[t].length,o=r===e;let h=!1;s||(s=1),this.shiftLineStyles(t,s);const c=this.styles[t]?this.styles[t][e===0?e:e-1]:void 0;for(const d in this.styles[t]){const f=parseInt(d,10);f>=e&&(h=!0,n[f-e]=this.styles[t][d],o&&e===0||delete this.styles[t][d])}let u=!1;for(h&&!o&&(this.styles[t+s]=n,u=!0),(u||r>e)&&s--;s>0;)i&&i[s-1]?this.styles[t+s]={0:E({},i[s-1])}:c?this.styles[t+s]={0:E({},c)}:delete this.styles[t+s],s--;this._forceClearCache=!0}insertCharStyleObject(t,e,s,i){this.styles||(this.styles={});const n=this.styles[t],r=n?E({},n):{};s||(s=1);for(const h in r){const c=parseInt(h,10);c>=e&&(n[c+s]=r[c],r[c-s]||delete n[c])}if(this._forceClearCache=!0,i){for(;s--;)Object.keys(i[s]).length&&(this.styles[t]||(this.styles[t]={}),this.styles[t][e+s]=E({},i[s]));return}if(!n)return;const o=n[e?e-1:1];for(;o&&s--;)this.styles[t][e+s]=E({},o)}insertNewStyleBlock(t,e,s){const i=this.get2DCursorLocation(e,!0),n=[0];let r,o=0;for(let h=0;h<t.length;h++)t[h]===`
85
+ `?(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=wt:this._selectionDirection===$t&&(this._selectionDirection=wt,this.selectionEnd=t),this.selectionStart=s):s>t&&s<e?this._selectionDirection===$t?this.selectionEnd=s:this.selectionStart=s:(e===t?this._selectionDirection=$t:this._selectionDirection===wt&&(this._selectionDirection=$t,this.selectionStart=e),this.selectionEnd=s)}}class Fx extends Rx{initHiddenTextarea(){const t=this.canvas&&Js(this.canvas.getElement())||ua(),e=t.createElement("textarea");Object.entries({autocapitalize:"off",autocorrect:"off",autocomplete:"off",spellcheck:"false","data-fabric":"textarea",wrap:"off"}).map(r=>{let[o,h]=r;return e.setAttribute(o,h)});const{top:s,left:i,fontSize:n}=this._calcTextareaPosition();e.style.cssText="position: absolute; top: ".concat(s,"; left: ").concat(i,"; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; padding-top: ").concat(n,";"),(this.hiddenTextareaContainer||t.body).appendChild(e),Object.entries({blur:"blur",keydown:"onKeyDown",keyup:"onKeyUp",input:"onInput",copy:"copy",cut:"copy",paste:"paste",compositionstart:"onCompositionStart",compositionupdate:"onCompositionUpdate",compositionend:"onCompositionEnd"}).map(r=>{let[o,h]=r;return e.addEventListener(o,this[h].bind(this))}),this.hiddenTextarea=e}blur(){this.abortCursorAnimation()}onKeyDown(t){if(!this.isEditing)return;const e=this.direction==="rtl"?this.keysMapRtl:this.keysMap;if(t.keyCode in e)this[e[t.keyCode]](t);else{if(!(t.keyCode in this.ctrlKeysMapDown)||!t.ctrlKey&&!t.metaKey)return;this[this.ctrlKeysMapDown[t.keyCode]](t)}t.stopImmediatePropagation(),t.preventDefault(),t.keyCode>=33&&t.keyCode<=40?(this.inCompositionMode=!1,this.clearContextTop(),this.renderCursorOrSelection()):this.canvas&&this.canvas.requestRenderAll()}onKeyUp(t){!this.isEditing||this._copyDone||this.inCompositionMode?this._copyDone=!1:t.keyCode in this.ctrlKeysMapUp&&(t.ctrlKey||t.metaKey)&&(this[this.ctrlKeysMapUp[t.keyCode]](t),t.stopImmediatePropagation(),t.preventDefault(),this.canvas&&this.canvas.requestRenderAll())}onInput(t){const e=this.fromPaste,{value:s,selectionStart:i,selectionEnd:n}=this.hiddenTextarea;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;const r=()=>{this.updateFromTextArea(),this.fire(uu),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(this.hiddenTextarea.value==="")return this.styles={},void r();const o=this._splitTextIntoLines(s).graphemeText,h=this._text.length,c=o.length,u=this.selectionStart,d=this.selectionEnd,f=u!==d;let g,p,m,y,b=c-h;const x=this.fromStringToGraphemeSelection(i,n,s),C=u>x.selectionStart;f?(p=this._text.slice(u,d),b+=d-u):c<h&&(p=C?this._text.slice(d+b,d):this._text.slice(u,u-b));const S=o.slice(x.selectionEnd-b,x.selectionEnd);if(p&&p.length&&(S.length&&(g=this.getSelectionStyles(u,u+1,!1),g=S.map(()=>g[0])),f?(m=u,y=d):C?(m=d-p.length,y=d):(m=d,y=d+p.length),this.removeStyleFromTo(m,y)),S.length){const{copyPasteData:T}=xi();e&&S.join("")===T.copiedText&&!mt.disableStyleCopyPaste&&(g=T.copiedTextStyle),this.insertNewStyleBlock(S,u,g)}r()}onCompositionStart(){this.inCompositionMode=!0}onCompositionEnd(){this.inCompositionMode=!1}onCompositionUpdate(t){let{target:e}=t;const{selectionStart:s,selectionEnd:i}=e;this.compositionStart=s,this.compositionEnd=i,this.updateTextareaPosition()}copy(){if(this.selectionStart===this.selectionEnd)return;const{copyPasteData:t}=xi();t.copiedText=this.getSelectedText(),mt.disableStyleCopyPaste?t.copiedTextStyle=void 0:t.copiedTextStyle=this.getSelectionStyles(this.selectionStart,this.selectionEnd,!0),this._copyDone=!0}paste(){this.fromPaste=!0}_getWidthBeforeCursor(t,e){let s,i=this._getLineLeftOffset(t);return e>0&&(s=this.__charBounds[t][e-1],i+=s.left+s.width),i}getDownCursorOffset(t,e){const s=this._getSelectionForOffset(t,e),i=this.get2DCursorLocation(s),n=i.lineIndex;if(n===this._textLines.length-1||t.metaKey||t.keyCode===34)return this._text.length-s;const r=i.charIndex,o=this._getWidthBeforeCursor(n,r),h=this._getIndexOnLine(n+1,o);return this._textLines[n].slice(r).length+h+1+this.missingNewlineOffset(n)}_getSelectionForOffset(t,e){return t.shiftKey&&this.selectionStart!==this.selectionEnd&&e?this.selectionEnd:this.selectionStart}getUpCursorOffset(t,e){const s=this._getSelectionForOffset(t,e),i=this.get2DCursorLocation(s),n=i.lineIndex;if(n===0||t.metaKey||t.keyCode===33)return-s;const r=i.charIndex,o=this._getWidthBeforeCursor(n,r),h=this._getIndexOnLine(n-1,o),c=this._textLines[n].slice(0,r),u=this.missingNewlineOffset(n-1);return-this._textLines[n-1].length+h-c.length+(1-u)}_getIndexOnLine(t,e){const s=this._textLines[t];let i,n,r=this._getLineLeftOffset(t),o=0;for(let h=0,c=s.length;h<c;h++)if(i=this.__charBounds[t][h].width,r+=i,r>e){n=!0;const u=r-i,d=r,f=Math.abs(u-e);o=Math.abs(d-e)<f?h:h-1;break}return n||(o=s.length-1),o}moveCursorDown(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorUpOrDown("Down",t)}moveCursorUp(t){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorUpOrDown("Up",t)}_moveCursorUpOrDown(t,e){const s=this["get".concat(t,"CursorOffset")](e,this._selectionDirection===$t);if(e.shiftKey?this.moveCursorWithShift(s):this.moveCursorWithoutShift(s),s!==0){const i=this.text.length;this.selectionStart=zr(0,this.selectionStart,i),this.selectionEnd=zr(0,this.selectionEnd,i),this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea()}}moveCursorWithShift(t){const e=this._selectionDirection===wt?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=wt,this.selectionEnd===this.selectionStart&&this.selectionStart!==0&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return this._selectionDirection===$t&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):this.selectionStart!==0?(this._selectionDirection=wt,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===wt&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection=$t,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=$t,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}const w0=a=>!!a.button;class Lx extends Fx{constructor(){super(...arguments),k(this,"draggableTextDelegate",void 0)}initBehavior(){this.on("mousedown",this._mouseDownHandler),this.on("mouseup",this.mouseUpHandler),this.on("mousedblclick",this.doubleClickHandler),this.on("mousetripleclick",this.tripleClickHandler),this.draggableTextDelegate=new Dx(this),super.initBehavior()}shouldStartDragging(){return this.draggableTextDelegate.isActive()}onDragStart(t){return this.draggableTextDelegate.onDragStart(t)}canDrop(t){return this.draggableTextDelegate.canDrop(t)}doubleClickHandler(t){this.isEditing&&(this.selectWord(this.getSelectionStartFromPointer(t.e)),this.renderCursorOrSelection())}tripleClickHandler(t){this.isEditing&&(this.selectLine(this.getSelectionStartFromPointer(t.e)),this.renderCursorOrSelection())}_mouseDownHandler(t){let{e,alreadySelected:s}=t;this.canvas&&this.editable&&!w0(e)&&!this.getActiveControl()&&(this.draggableTextDelegate.start(e)||(this.canvas.textEditingManager.register(this),s&&(this.inCompositionMode=!1,this.setCursorByClick(e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection()),this.selected||(this.selected=s||this.isEditing)))}mouseUpHandler(t){let{e,transform:s}=t;const i=this.draggableTextDelegate.end(e);if(this.canvas){this.canvas.textEditingManager.unregister(this);const n=this.canvas._activeObject;if(n&&n!==this)return}!this.editable||this.group&&!this.group.interactive||s&&s.actionPerformed||w0(e)||i||this.selected&&!this.getActiveControl()&&(this.enterEditing(e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection())}setCursorByClick(t){const e=this.getSelectionStartFromPointer(t),s=this.selectionStart,i=this.selectionEnd;t.shiftKey?this.setSelectionStartEndWithShift(s,i,e):(this.selectionStart=e,this.selectionEnd=e),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())}getSelectionStartFromPointer(t){const e=this.canvas.getScenePoint(t).transform(ns(this.calcTransformMatrix())).add(new O(-this._getLeftOffset(),-this._getTopOffset()));let s=0,i=0,n=0;for(let c=0;c<this._textLines.length&&s<=e.y;c++)s+=this.getHeightOfLine(c),n=c,c>0&&(i+=this._textLines[c-1].length+this.missingNewlineOffset(c-1));let r=Math.abs(this._getLineLeftOffset(n));const o=this._textLines[n].length,h=this.__charBounds[n];for(let c=0;c<o;c++){const u=r+h[c].kernedWidth;if(e.x<=u){Math.abs(e.x-u)<=Math.abs(e.x-r)&&i++;break}r=u,i++}return Math.min(this.flipX?o-i:i,this._text.length)}}const Vu="moveCursorUp",Gu="moveCursorDown",Wu="moveCursorLeft",Xu="moveCursorRight",Uu="exitEditing",x0=(a,t)=>{const e=t.getRetinaScaling();a.setTransform(e,0,0,e,0,0);const s=t.viewportTransform;a.transform(s[0],s[1],s[2],s[3],s[4],s[5])},Ix=E({selectionStart:0,selectionEnd:0,selectionColor:"rgba(17,119,255,0.3)",isEditing:!1,editable:!0,editingBorderColor:"rgba(102,153,255,0.25)",cursorWidth:2,cursorColor:"",cursorDelay:1e3,cursorDuration:600,caching:!0,hiddenTextareaContainer:null,keysMap:{9:Uu,27:Uu,33:Vu,34:Gu,35:Xu,36:Wu,37:Wu,38:Vu,39:Xu,40:Gu},keysMapRtl:{9:Uu,27:Uu,33:Vu,34:Gu,35:Wu,36:Xu,37:Xu,38:Vu,39:Wu,40:Gu},ctrlKeysMapDown:{65:"cmdAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}},{_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1});class on extends Lx{static getDefaults(){return E(E({},super.getDefaults()),on.ownDefaults)}get type(){const t=super.type;return t==="itext"?"i-text":t}constructor(t,e){super(t,E(E({},on.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 bg&&this.canvas.textEditingManager.remove(this),e instanceof bg&&e.textEditingManager.add(this)),super._set(t,e))}setSelectionStart(t){t=Math.max(t,0),this._updateAndFire("selectionStart",t)}setSelectionEnd(t){t=Math.min(t,this.text.length),this._updateAndFire("selectionEnd",t)}_updateAndFire(t,e){this[t]!==e&&(this._fireSelectionChanged(),this[t]=e),this._updateTextarea()}_fireSelectionChanged(){this.fire("selection:changed"),this.canvas&&this.canvas.fire("text:selection:changed",{target:this})}initDimensions(){this.isEditing&&this.initDelayedCursor(),super.initDimensions()}getSelectionStyles(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart||0,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionEnd,s=arguments.length>2?arguments[2]:void 0;return super.getSelectionStyles(t,e,s)}setSelectionStyles(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionStart||0,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.selectionEnd;return super.setSelectionStyles(t,e,s)}get2DCursorLocation(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;return super.get2DCursorLocation(t,e)}render(t){super.render(t),this.cursorOffsetCache={},this.renderCursorOrSelection()}toCanvasElement(t){const e=this.isEditing;this.isEditing=!1;const s=super.toCanvasElement(t);return this.isEditing=e,s}renderCursorOrSelection(){if(!this.isEditing||!this.canvas)return;const t=this.clearContextTop(!0);if(!t)return;const e=this._getCursorBoundaries(),s=this.findAncestorsWithClipPath(),i=s.length>0;let n,r=t;if(i){n=ps(t.canvas),r=n.getContext("2d"),x0(r,this.canvas);const o=this.calcTransformMatrix();r.transform(o[0],o[1],o[2],o[3],o[4],o[5])}if(this.selectionStart!==this.selectionEnd||this.inCompositionMode?this.renderSelection(r,e):this.renderCursor(r,e),i)for(const o of s){const h=o.clipPath,c=ps(t.canvas),u=c.getContext("2d");if(x0(u,this.canvas),!h.absolutePositioned){const d=o.calcTransformMatrix();u.transform(d[0],d[1],d[2],d[3],d[4],d[5])}h.transform(u),h.drawObject(u,!0,{}),this.drawClipPathOnCache(r,h,c)}i&&(t.setTransform(1,0,0,1,0,0),t.drawImage(n,0,0)),this.canvas.contextTopDirty=!0,t.restore()}findAncestorsWithClipPath(){const t=[];let e=this;for(;e;)e.clipPath&&t.push(e),e=e.parent;return t}_getCursorBoundaries(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;const s=this._getLeftOffset(),i=this._getTopOffset(),n=this._getCursorBoundariesOffsets(t,e);return{left:s,top:i,leftOffset:n.left,topOffset:n.top}}_getCursorBoundariesOffsets(t,e){return e?this.__getCursorBoundariesOffsets(t):this.cursorOffsetCache&&"top"in this.cursorOffsetCache?this.cursorOffsetCache:this.cursorOffsetCache=this.__getCursorBoundariesOffsets(t)}__getCursorBoundariesOffsets(t){let e=0,s=0;const{charIndex:i,lineIndex:n}=this.get2DCursorLocation(t);for(let c=0;c<n;c++)e+=this.getHeightOfLine(c);const r=this._getLineLeftOffset(n),o=this.__charBounds[n][i];o&&(s=o.left),this.charSpacing!==0&&i===this._textLines[n].length&&(s-=this._getWidthOfCharSpacing());const h={top:e,left:r+(s>0?s:0)};return this.direction==="rtl"&&(this.textAlign===$t||this.textAlign===Ti||this.textAlign===sl?h.left*=-1:this.textAlign===wt||this.textAlign===Su?h.left=r-(s>0?s:0):this.textAlign!==rt&&this.textAlign!==il||(h.left=r-(s>0?s:0))),h}renderCursorAt(t){this._renderCursor(this.canvas.contextTop,this._getCursorBoundaries(t,!0),t)}renderCursor(t,e){this._renderCursor(t,e,this.selectionStart)}getCursorRenderingData(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this._getCursorBoundaries(t);const s=this.get2DCursorLocation(t),i=s.lineIndex,n=s.charIndex>0?s.charIndex-1:0,r=this.getValueOfPropertyAt(i,n,"fontSize"),o=this.getObjectScaling().x*this.canvas.getZoom(),h=this.cursorWidth/o,c=this.getValueOfPropertyAt(i,n,"deltaY"),u=e.topOffset+(1-this._fontSizeFraction)*this.getHeightOfLine(i)/this.lineHeight-r*(1-this._fontSizeFraction);return{color:this.cursorColor||this.getValueOfPropertyAt(i,n,"fill"),opacity:this._currentCursorOpacity,left:e.left+e.leftOffset-h/2,top:u+e.top+c,width:h,height:r}}_renderCursor(t,e,s){const{color:i,opacity:n,left:r,top:o,width:h,height:c}=this.getCursorRenderingData(s,e);t.fillStyle=i,t.globalAlpha=n,t.fillRect(r,o,h,c)}renderSelection(t,e){const s={selectionStart:this.inCompositionMode?this.hiddenTextarea.selectionStart:this.selectionStart,selectionEnd:this.inCompositionMode?this.hiddenTextarea.selectionEnd:this.selectionEnd};this._renderSelection(t,s,e)}renderDragSourceEffect(){const t=this.draggableTextDelegate.getDragStartSelection();this._renderSelection(this.canvas.contextTop,t,this._getCursorBoundaries(t.selectionStart,!0))}renderDropTargetEffect(t){const e=this.getSelectionStartFromPointer(t);this.renderCursorAt(e)}_renderSelection(t,e,s){const i=e.selectionStart,n=e.selectionEnd,r=this.textAlign.includes(Ti),o=this.get2DCursorLocation(i),h=this.get2DCursorLocation(n),c=o.lineIndex,u=h.lineIndex,d=o.charIndex<0?0:o.charIndex,f=h.charIndex<0?0:h.charIndex;for(let g=c;g<=u;g++){const p=this._getLineLeftOffset(g)||0;let m=this.getHeightOfLine(g),y=0,b=0,x=0;if(g===c&&(b=this.__charBounds[c][d].left),g>=c&&g<u)x=r&&!this.isEndOfWrapping(g)?this.width:this.getLineWidth(g)||5;else if(g===u)if(f===0)x=this.__charBounds[u][f].left;else{const M=this._getWidthOfCharSpacing();x=this.__charBounds[u][f-1].left+this.__charBounds[u][f-1].width-M}y=m,(this.lineHeight<1||g===u&&this.lineHeight>1)&&(m/=this.lineHeight);let C=s.left+p+b,S=m,T=0;const P=x-b;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",S=1,T=m):t.fillStyle=this.selectionColor,this.direction==="rtl"&&(this.textAlign===$t||this.textAlign===Ti||this.textAlign===sl?C=this.width-C-P:this.textAlign===wt||this.textAlign===Su?C=s.left+p-x:this.textAlign!==rt&&this.textAlign!==il||(C=s.left+p-x)),t.fillRect(C,s.top+s.topOffset+T,P,S),s.topOffset+=y}}getCurrentCharFontSize(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,"fontSize")}getCurrentCharColor(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,ee)}_getCurrentCharIndex(){const t=this.get2DCursorLocation(this.selectionStart,!0),e=t.charIndex>0?t.charIndex-1:0;return{l:t.lineIndex,c:e}}dispose(){this.exitEditingImpl(),this.draggableTextDelegate.dispose(),super.dispose()}}k(on,"ownDefaults",Ix),k(on,"type","IText"),G.setClass(on),G.setClass(on,"i-text");class Xr extends on{static getDefaults(){return E(E({},super.getDefaults()),Xr.ownDefaults)}constructor(t,e){super(t,E(E({},Xr.ownDefaults),e))}static createControls(){return{controls:ww()}}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(Ti)&&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]===`
86
+ `&&r>0?(s=0,i++,e++):!this.splitByGrapheme&&this._reSpaceAndTab.test(t.graphemeText[i])&&r>0&&(s++,i++),n[r]={line:e,offset:s},i+=t.graphemeLines[r].length,s+=t.graphemeLines[r].length;return n}styleHas(t,e){if(this._styleMap&&!this.isWrapping){const s=this._styleMap[e];s&&(e=s.line)}return super.styleHas(t,e)}isEmptyStyles(t){if(!this.styles)return!0;let e,s=0,i=t+1,n=!1;const r=this._styleMap[t],o=this._styleMap[t+1];r&&(t=r.line,s=r.offset),o&&(i=o.line,n=i===t,e=o.offset);const h=t===void 0?this.styles:{line:this.styles[t]};for(const c in h)for(const u in h[c]){const d=parseInt(u,10);if(d>=s&&(!n||d<e))for(const f in h[c][u])return!1}return!0}_getStyleDeclaration(t,e){if(this._styleMap&&!this.isWrapping){const s=this._styleMap[t];if(!s)return{};t=s.line,e=s.offset+e}return super._getStyleDeclaration(t,e)}_setStyleDeclaration(t,e,s){const i=this._styleMap[t];super._setStyleDeclaration(i.line,i.offset+e,s)}_deleteStyleDeclaration(t,e){const s=this._styleMap[t];super._deleteStyleDeclaration(s.line,s.offset+e)}_getLineStyle(t){const e=this._styleMap[t];return!!this.styles[e.line]}_setLineStyle(t){const e=this._styleMap[t];super._setLineStyle(e.line)}_wrapText(t,e){this.isWrapping=!0;const s=this.getGraphemeDataForRender(t),i=[];for(let n=0;n<s.wordsData.length;n++)i.push(...this._wrapLine(n,e,s));return this.isWrapping=!1,i}getGraphemeDataForRender(t){const e=this.splitByGrapheme,s=e?"":" ";let i=0;return{wordsData:t.map((n,r)=>{let o=0;const h=e?this.graphemeSplit(n):this.wordSplit(n);return h.length===0?[{word:[],width:0}]:h.map(c=>{const u=e?[c]:this.graphemeSplit(c),d=this._measureWord(u,r,o);return i=Math.max(d,i),o+=u.length+s.length,{word:u,width:d}})}),largestWordWidth:i}}_measureWord(t,e){let s,i=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,n=0;for(let r=0,o=t.length;r<o;r++)n+=this._getGraphemeBox(t[r],e,r+i,s,!0).kernedWidth,s=t[r];return n}wordSplit(t){return t.split(this._wordJoiners)}_wrapLine(t,e,s){let{largestWordWidth:i,wordsData:n}=s,r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:0;const o=this._getWidthOfCharSpacing(),h=this.splitByGrapheme,c=[],u=h?"":" ";let d=0,f=[],g=0,p=0,m=!0;e-=r;const y=Math.max(e,i,this.dynamicMinWidth),b=n[t];let x;for(g=0,x=0;x<b.length;x++){const{word:C,width:S}=b[x];g+=C.length,d+=p+S-o,d>y&&!m?(c.push(f),f=[],d=S,m=!0):d+=o,m||h||f.push(u),f=f.concat(C),p=h?0:this._measureWord([u],t,g),g++,m=!1}return x&&c.push(f),i+r>this.dynamicMinWidth&&(this.dynamicMinWidth=i-o+r),c}isEndOfWrapping(t){return!this._styleMap[t+1]||this._styleMap[t+1].line!==this._styleMap[t].line}missingNewlineOffset(t,e){return this.splitByGrapheme&&!e?this.isEndOfWrapping(t)?1:0:1}_splitTextIntoLines(t){const e=super._splitTextIntoLines(t),s=this._wrapText(e.lines,this.width),i=new Array(s.length);for(let n=0;n<s.length;n++)i[n]=s[n].join("");return e.lines=i,e.graphemeLines=s,e}getMinWidth(){return Math.max(this.minWidth,this.dynamicMinWidth)}_removeExtraneousStyles(){const t=new Map;for(const e in this._styleMap){const s=parseInt(e,10);if(this._textLines[s]){const i=this._styleMap[e].line;t.set("".concat(i),!0)}}for(const e in this.styles)t.has(e)||delete this.styles[e]}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject(["minWidth","splitByGrapheme",...t])}}k(Xr,"type","Textbox"),k(Xr,"textLayoutProperties",[...on.textLayoutProperties,"width"]),k(Xr,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),G.setClass(Xr);class S0 extends Iu{shouldPerformLayout(t){return!!t.target.clipPath&&super.shouldPerformLayout(t)}shouldLayoutClipPath(){return!1}calcLayoutResult(t,e){const{target:s}=t,{clipPath:i,group:n}=s;if(!i||!this.shouldPerformLayout(t))return;const{width:r,height:o}=Ai(qv(s,i)),h=new O(r,o);if(i.absolutePositioned)return{center:Br(i.getRelativeCenterPoint(),void 0,n?n.calcTransformMatrix():void 0),size:h};{const c=i.getRelativeCenterPoint().transform(s.calcOwnMatrix(),!0);if(this.shouldPerformLayout(t)){const{center:u=new O,correction:d=new O}=this.calcBoundingBox(e,t)||{};return{center:u.add(c),correction:d.subtract(c),size:h}}return{center:s.getRelativeCenterPoint().add(c),size:h}}}}k(S0,"type","clip-path"),G.setClass(S0);class C0 extends Iu{getInitialSize(t,e){let{target:s}=t,{size:i}=e;return new O(s.width||i.x,s.height||i.y)}}k(C0,"type","fixed"),G.setClass(C0);class jx extends al{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 Ur extends Fs{static getDefaults(){return E(E({},super.getDefaults()),Ur.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,Ur.ownDefaults),this.setOptions(e);const{left:s,top:i,layoutManager:n}=e;this.groupInit(t,{left:s,top:i,layoutManager:n??new jx})}_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))?(Ki("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===fg?s.forEach(i=>{i._onAfterObjectsChange(Fu,e)}):s.forEach(i=>{i._set("dirty",!0)})}onDeselect(){return this.removeAll(),!1}toString(){return"#<ActiveSelection: (".concat(this.complexity(),")>")}shouldCache(){return!1}isOnACache(){return!1}_renderControls(t,e,s){t.save(),t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1;const i=E(E({hasControls:!1},s),{},{forActiveSelection:!0});for(let n=0;n<this._objects.length;n++)this._objects[n]._renderControls(t,i);super._renderControls(t,e),t.restore()}}k(Ur,"type","ActiveSelection"),k(Ur,"ownDefaults",{multiSelectionStacking:"canvas-stacking"}),G.setClass(Ur),G.setClass(Ur,"activeSelection");class Nx{constructor(){k(this,"resources",{})}applyFilters(t,e,s,i,n){const r=n.getContext("2d");if(!r)return;r.drawImage(e,0,0,s,i);const o={sourceWidth:s,sourceHeight:i,imageData:r.getImageData(0,0,s,i),originalEl:e,originalImageData:r.getImageData(0,0,s,i),canvasEl:n,ctx:r,filterBackend:this};t.forEach(c=>{c.applyTo(o)});const{imageData:h}=o;return h.width===s&&h.height===i||(n.width=h.width,n.height=h.height),r.putImageData(h,0,0),o}}class A0{constructor(){let{tileSize:t=mt.textureSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};k(this,"aPosition",new Float32Array([0,0,0,1,1,0,1,1])),k(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=ps({width:t,height:e}),i=s.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,depth:!1,stencil:!1,antialias:!1});i&&(i.clearColor(0,0,0,0),this.canvas=s,this.gl=i)}applyFilters(t,e,s,i,n,r){const o=this.gl,h=n.getContext("2d");if(!o||!h)return;let c;r&&(c=this.getCachedTexture(r,e));const u={originalWidth:e.width||e.naturalWidth||0,originalHeight:e.height||e.naturalHeight||0,sourceWidth:s,sourceHeight:i,destinationWidth:s,destinationHeight:i,context:o,sourceTexture:this.createTexture(o,s,i,c?void 0:e),targetTexture:this.createTexture(o,s,i),originalTexture:c||this.createTexture(o,s,i,c?void 0:e),passes:t.length,webgl:!0,aPosition:this.aPosition,programCache:this.programCache,pass:0,filterBackend:this,targetCanvas:n},d=o.createFramebuffer();return o.bindFramebuffer(o.FRAMEBUFFER,d),t.forEach(f=>{f&&f.applyTo(u)}),function(f){const g=f.targetCanvas,p=g.width,m=g.height,y=f.destinationWidth,b=f.destinationHeight;p===y&&m===b||(g.width=y,g.height=b)}(u),this.copyGLTo2D(o,u),o.bindTexture(o.TEXTURE_2D,null),o.deleteTexture(u.sourceTexture),o.deleteTexture(u.targetTexture),o.deleteFramebuffer(d),h.setTransform(1,0,0,1,0,0),u}dispose(){this.canvas&&(this.canvas=null,this.gl=null),this.clearWebGLCaches()}clearWebGLCaches(){this.programCache={},this.textureCache={}}createTexture(t,e,s,i,n){const{NEAREST:r,TEXTURE_2D:o,RGBA:h,UNSIGNED_BYTE:c,CLAMP_TO_EDGE:u,TEXTURE_MAG_FILTER:d,TEXTURE_MIN_FILTER:f,TEXTURE_WRAP_S:g,TEXTURE_WRAP_T:p}=t,m=t.createTexture();return t.bindTexture(o,m),t.texParameteri(o,d,n||r),t.texParameteri(o,f,n||r),t.texParameteri(o,g,u),t.texParameteri(o,p,u),i?t.texImage2D(o,0,h,h,c,i):t.texImage2D(o,0,h,e,s,0,h,c,null),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 c=new ImageData(h,i,n);s.putImageData(c,0,0)}captureGPUInfo(){if(this.gpuInfo)return this.gpuInfo;const t=this.gl,e={renderer:"",vendor:""};if(!t)return e;const s=t.getExtension("WEBGL_debug_renderer_info");if(s){const i=t.getParameter(s.UNMASKED_RENDERER_WEBGL),n=t.getParameter(s.UNMASKED_VENDOR_WEBGL);i&&(e.renderer=i.toLowerCase()),n&&(e.vendor=n.toLowerCase())}return this.gpuInfo=e,e}}let Sg;function Bx(){const{WebGLProbe:a}=xi();return a.queryWebGL(Si()),mt.enableGLFiltering&&a.isSupported(mt.textureSize)?new A0({tileSize:mt.textureSize}):new Nx}function Cg(){return!Sg&&(!(arguments.length>0&&arguments[0]!==void 0)||arguments[0])&&(Sg=Bx()),Sg}const Hx=["filters","resizeFilter","src","crossOrigin","type"],T0=["cropX","cropY"];class Me extends ke{static getDefaults(){return E(E({},super.getDefaults()),Me.ownDefaults)}constructor(t,e){super(),k(this,"_lastScaleX",1),k(this,"_lastScaleY",1),k(this,"_filterScalingX",1),k(this,"_filterScalingY",1),this.filters=[],Object.assign(this,Me.ownDefaults),this.setOptions(e),this.cacheKey="texture".concat(Wn()),this.setElement(typeof t=="string"?(this.canvas&&Js(this.canvas.getElement())||ua()).getElementById(t):t,e)}getElement(){return this._element}setElement(t){var e;let s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._element=t,this._originalElement=t,this._setWidthHeight(s),(e=t.classList)===null||e===void 0||e.add(Me.CSS_CANVAS),this.filters.length!==0&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){const e=Cg(!1);e instanceof A0&&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&&xi().dispose(e),this[t]=void 0})}getCrossOrigin(){return this._originalElement&&(this._originalElement.crossOrigin||null)}getOriginalSize(){const t=this.getElement();return t?{width:t.naturalWidth||t.width,height:t.naturalHeight||t.height}:{width:0,height:0}}_stroke(t){if(!this.stroke||this.strokeWidth===0)return;const e=this.width/2,s=this.height/2;t.beginPath(),t.moveTo(-e,-s),t.lineTo(e,-s),t.lineTo(e,s),t.lineTo(-e,s),t.lineTo(-e,-s),t.closePath()}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=[];return this.filters.forEach(s=>{s&&e.push(s.toObject())}),E(E({},super.toObject([...T0,...t])),{},{src:this.getSrc(),crossOrigin:this.getCrossOrigin(),filters:e},this.resizeFilter?{resizeFilter:this.resizeFilter.toObject()}:{})}hasCrop(){return!!this.cropX||!!this.cropY||this.width<this._element.width||this.height<this._element.height}_toSVG(){const t=[],e=this._element,s=-this.width/2,i=-this.height/2;let n=[],r=[],o="",h="";if(!e)return[];if(this.hasCrop()){const c=Wn();n.push('<clipPath id="imageCrop_'+c+`">
87
87
  `,' <rect x="'+s+'" y="'+i+'" width="'+this.width+'" height="'+this.height+`" />
88
88
  `,`</clipPath>
89
- `),a=' clip-path="url(#imageCrop_'+c+')" '}if(this.imageSmoothing||(h=' image-rendering="optimizeSpeed"'),t.push(" <image ","COMMON_PARTS",'xlink:href="'.concat(this.getSvgSrc(!0),'" x="').concat(s-this.cropX,'" y="').concat(i-this.cropY,'" width="').concat(e.width||e.naturalWidth,'" height="').concat(e.height||e.naturalHeight,'"').concat(h).concat(a,`></image>
89
+ `),o=' clip-path="url(#imageCrop_'+c+')" '}if(this.imageSmoothing||(h=' image-rendering="optimizeSpeed"'),t.push(" <image ","COMMON_PARTS",'xlink:href="'.concat(this.getSvgSrc(!0),'" x="').concat(s-this.cropX,'" y="').concat(i-this.cropY,'" width="').concat(e.width||e.naturalWidth,'" height="').concat(e.height||e.naturalHeight,'"').concat(h).concat(o,`></image>
90
90
  `)),this.stroke||this.strokeDashArray){const c=this.fill;this.fill=null,r=[' <rect x="'.concat(s,'" y="').concat(i,'" width="').concat(this.width,'" height="').concat(this.height,'" style="').concat(this.getSvgStyles(),`" />
91
- `)],this.fill=c}return n=this.paintFirst!==ee?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 qh(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 a=ps(r),{width:h,height:c}=r;this._element=a,this._lastScaleX=t.scaleX=i,this._lastScaleY=t.scaleY=n,wg().applyFilters([t],r,h,c,this._element),this._filterScalingX=a.width/this._originalElement.width,this._filterScalingY=a.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=ps({width:s,height:i});this._element=n,this._filteredEl=n}else this._filteredEl&&(this._element=this._filteredEl,this._filteredEl.getContext("2d").clearRect(0,0,s,i),this._lastScaleX=1,this._lastScaleY=1);wg().applyFilters(t,this._originalElement,s,i,this._element,this.cacheKey),this._originalElement.width===this._element.width&&this._originalElement.height===this._element.height||(this._filterScalingX=this._element.width/this._originalElement.width,this._filterScalingY=this._element.height/this._originalElement.height)}_render(t){t.imageSmoothingEnabled=this.imageSmoothing,this.isMoving!==!0&&this.resizeFilter&&this._needsResize()&&this.applyResizeFilters(),this._stroke(t),this._renderPaintInOrder(t)}drawCacheOnCanvas(t){t.imageSmoothingEnabled=this.imageSmoothing,super.drawCacheOnCanvas(t)}shouldCache(){return this.needsItsOwnCache()}_renderFill(t){const e=this._element;if(!e)return;const s=this._filterScalingX,i=this._filterScalingY,n=this.width,r=this.height,a=Math.max(this.cropX,0),h=Math.max(this.cropY,0),c=e.naturalWidth||e.width,u=e.naturalHeight||e.height,d=a*s,f=h*i,g=Math.min(n*s,c-d),p=Math.min(r*i,u-f),m=-n/2,y=-r/2,b=Math.min(n,c/s-a),x=Math.min(r,u/i-h);e&&t.drawImage(e,d,f,g,p,m,y,b,x)}_needsResize(){const t=this.getTotalObjectScaling();return t.x!==this._lastScaleX||t.y!==this._lastScaleY}_resetWidthHeight(){this.set(this.getOriginalSize())}_setWidthHeight(){let{width:t,height:e}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const s=this.getOriginalSize();this.width=t||s.width,this.height=e||s.height}parsePreserveAspectRatioAttribute(){const t=Yf(this.preserveAspectRatio||""),e=this.width,s=this.height,i={width:e,height:s};let n,r=this._element.width,a=this._element.height,h=1,c=1,u=0,d=0,f=0,g=0;return!t||t.alignX===ze&&t.alignY===ze?(h=e/r,c=s/a):(t.meetOrSlice==="meet"&&(h=c=z0(this._element,i),n=(e-r*h)/2,t.alignX==="Min"&&(u=-n),t.alignX==="Max"&&(u=n),n=(s-a*c)/2,t.alignY==="Min"&&(d=-n),t.alignY==="Max"&&(d=n)),t.meetOrSlice==="slice"&&(h=c=V0(this._element,i),n=r-e/h,t.alignX==="Mid"&&(f=n/2),t.alignX==="Max"&&(f=n),n=a-s/c,t.alignY==="Mid"&&(g=n/2),t.alignY==="Max"&&(g=n),r=e/h,a=s/c)),{width:r,height:a,scaleX:h,scaleY:c,offsetLeft:u,offsetTop:d,cropX:f,cropY:g}}static fromObject(t,e){let{filters:s,resizeFilter:i,src:n,crossOrigin:r,type:a}=t,h=Lt(t,Dx);return Promise.all([qh(n,T(T({},e),{},{crossOrigin:r})),s&&po(s,e),i&&po([i],e),Kh(h,e)]).then(c=>{let[u,d=[],[f]=[],g={}]=c;return new this(u,T(T({},h),{},{src:n,filters:d,resizeFilter:f},g))})}static fromURL(t){let{crossOrigin:e=null,signal:s}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;return qh(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=Zi(t,this.ATTRIBUTE_NAMES,s);return this.fromURL(i["xlink:href"]||i.href,e,i).catch(n=>($i("log","Unable to parse Image",n),null))}}function xg(o){if(!j_.test(o.nodeName))return{};const t=o.getAttribute("viewBox");let e,s,i=1,n=1,r=0,a=0;const h=o.getAttribute("width"),c=o.getAttribute("height"),u=o.getAttribute("x")||0,d=o.getAttribute("y")||0,f=!(t&&r0.test(t)),g=!h||!c||h==="100%"||c==="100%";let p="",m=0,y=0;if(f&&(u||d)&&o.parentNode&&o.parentNode.nodeName!=="#document"&&(p=" translate("+Ge(u||"0")+" "+Ge(d||"0")+") ",e=(o.getAttribute("transform")||"")+p,o.setAttribute("transform",e),o.removeAttribute("x"),o.removeAttribute("y")),f&&g)return{width:0,height:0};const b={width:0,height:0};if(f)return b.width=Ge(h),b.height=Ge(c),b;const x=t.match(r0);r=-parseFloat(x[1]),a=-parseFloat(x[2]);const S=parseFloat(x[3]),C=parseFloat(x[4]);b.minX=r,b.minY=a,b.viewBoxWidth=S,b.viewBoxHeight=C,g?(b.width=S,b.height=C):(b.width=Ge(h),b.height=Ge(c),i=b.width/S,n=b.height/C);const k=Yf(o.getAttribute("preserveAspectRatio")||"");if(k.alignX!==ze&&(k.meetOrSlice==="meet"&&(n=i=i>n?n:i),k.meetOrSlice==="slice"&&(n=i=i>n?i:n),m=b.width-S*i,y=b.height-C*i,k.alignX==="Mid"&&(m/=2),k.alignY==="Mid"&&(y/=2),k.alignX==="Min"&&(m=0),k.alignY==="Min"&&(y=0)),i===1&&n===1&&r===0&&a===0&&u===0&&d===0)return b;if((u||d)&&o.parentNode.nodeName!=="#document"&&(p=" translate("+Ge(u||"0")+" "+Ge(d||"0")+") "),e=p+" matrix("+i+" 0 0 "+n+" "+(r*i+m)+" "+(a*n+y)+") ",o.nodeName==="svg"){for(s=o.ownerDocument.createElementNS($f,"g");o.firstChild;)s.appendChild(o.firstChild);o.appendChild(s)}else s=o,s.removeAttribute("x"),s.removeAttribute("y"),e=s.getAttribute("transform")+e;return s.setAttribute("transform",e),b}E(Me,"type","Image"),E(Me,"cacheProperties",[...Ji,..._v]),E(Me,"ownDefaults",{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),E(Me,"CSS_CANVAS","canvas-img"),E(Me,"ATTRIBUTE_NAMES",[...Xn,"x","y","width","height","preserveAspectRatio","xlink:href","href","crossOrigin","image-rendering"]),W.setClass(Me),W.setSVGClass(Me);const Xu=o=>o.tagName.replace("svg:",""),Rx=_u(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);function wv(o,t){let e,s,i,n,r=[];for(i=0,n=t.length;i<n;i++)e=t[i],s=o.getElementsByTagNameNS("http://www.w3.org/2000/svg",e),r=r.concat(Array.from(s));return r}const Fx=["gradientTransform","x1","x2","y1","y2","gradientUnits","cx","cy","r","fx","fy"],Sg="xlink:href";function xv(o,t){var e;const s=((e=t.getAttribute(Sg))===null||e===void 0?void 0:e.slice(1))||"",i=o.getElementById(s);if(i&&i.getAttribute(Sg)&&xv(o,i),i&&(Fx.forEach(n=>{const r=i.getAttribute(n);!t.hasAttribute(n)&&r&&t.setAttribute(n,r)}),!t.children.length)){const n=i.cloneNode(!0);for(;n.firstChild;)t.appendChild(n.firstChild)}t.removeAttribute(Sg)}const Lx=["linearGradient","radialGradient","svg:linearGradient","svg:radialGradient"];function Ix(o){const t=o.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,a,h)=>h.length>1&&r.trim()).forEach(r=>{if((r.match(/{/g)||[]).length>1&&r.trim().startsWith("@"))return;const a=r.split("{"),h={},c=a[1].trim().split(";").filter(function(u){return u.trim()});for(e=0,s=c.length;e<s;e++){const u=c[e].split(":"),d=u[0].trim(),f=u[1].trim();h[d]=f}(r=a[0].trim()).split(",").forEach(u=>{(u=u.replace(/^svg/i,"").trim())!==""&&(i[u]=T(T({},i[u]||{}),h))})})}return i}const Sv=o=>W.getSVGClass(Xu(o).toLowerCase());class jx{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 a=wv(r,Lx),h={};let c=a.length;for(;c--;){const u=a[c];u.getAttribute("xlink:href")&&xv(r,u);const d=u.getAttribute("id");d&&(h[d]=u)}return h}(i),this.cssRules=Ix(i)}parse(){return Promise.all(this.elements.map(t=>this.createObject(t)))}async createObject(t){const e=Sv(t);if(e){const s=await e.fromElement(t,this.options,this.cssRules);return this.resolveGradient(s,t,ee),this.resolveGradient(s,t,We),s instanceof Me&&s._originalElement?Iu(s,s.parsePreserveAspectRatioAttribute()):Iu(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=nl.fromElement(i,t,T(T({},this.options),{},{opacity:n}));t.set(s,r)}}async resolveClipPath(t,e,s){const i=this.extractPropertyDefinition(t,"clipPath",this.clipPaths);if(i){const n=ns(t.calcTransformMatrix()),r=i[0].parentElement;let a=e;for(;!s&&a.parentElement&&a.getAttribute("clip-path")!==t.clipPath;)a=a.parentElement;a.parentElement.appendChild(r);const h=Mu("".concat(a.getAttribute("transform")||""," ").concat(r.getAttribute("originalTransform")||""));r.setAttribute("transform","matrix(".concat(h.join(","),")"));const c=await Promise.all(i.map(x=>Sv(x).fromElement(x,this.options,this.cssRules).then(S=>(Iu(S),S.fillRule=S.clipRule,delete S.clipRule,S)))),u=c.length===1?c[0]:new Ls(c),d=qt(n,u.calcTransformMatrix());u.clipPath&&await this.resolveClipPath(u,a,r.getAttribute("clip-path")?a:void 0);const{scaleX:f,scaleY:g,angle:p,skewX:m,translateX:y,translateY:b}=Lr(d);u.set({flipX:!1,flipY:!1}),u.set({scaleX:f,scaleY:g,angle:p,skewX:m,skewY:0}),u.setPositionByOrigin(new M(y,b),rt,rt),t.clipPath=u}else delete t.clipPath}}const Cv=o=>I_.test(Xu(o)),Cg=()=>({objects:[],elements:[],options:{},allElements:[]});async function Nx(o,t){let{crossOrigin:e,signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(s&&s.aborted)return $i("log",new kf("parseSVGDocument")),Cg();const i=o.documentElement;(function(u){const d=wv(u,["use","svg:use"]),f=["x","y","xlink:href","href","transform"];for(const g of d){const p=g.attributes,m={};for(const R of p)R.value&&(m[R.name]=R.value);const y=(m["xlink:href"]||m.href||"").slice(1);if(y==="")return;const b=u.getElementById(y);if(b===null)return;let x=b.cloneNode(!0);const S=x.attributes,C={};for(const R of S)R.value&&(C[R.name]=R.value);const{x:k=0,y:O=0,transform:P=""}=m,D="".concat(P," ").concat(C.transform||""," translate(").concat(k,", ").concat(O,")");if(xg(x),/^svg$/i.test(x.nodeName)){const R=x.ownerDocument.createElementNS($f,"g");Object.entries(C).forEach(z=>{let[B,F]=z;return R.setAttributeNS($f,B,F)}),R.append(...x.childNodes),x=R}for(const R of p){if(!R)continue;const{name:z,value:B}=R;if(!f.includes(z))if(z==="style"){const F={};lg(B,F),Object.entries(C).forEach(N=>{let[K,I]=N;F[K]=I}),lg(C.style||"",F);const L=Object.entries(F).map(N=>N.join(":")).join(";");x.setAttribute(z,L)}else!C[z]&&x.setAttribute(z,B)}x.setAttribute("transform",D),x.setAttribute("instantiated_by_use","1"),x.removeAttribute("id"),g.parentNode.replaceChild(x,g)}})(o);const n=Array.from(i.getElementsByTagName("*")),r=T(T({},xg(i)),{},{crossOrigin:e,signal:s}),a=n.filter(u=>(xg(u),Cv(u)&&!function(d){let f=d;for(;f&&(f=f.parentElement);)if(f&&f.nodeName&&Rx.test(Xu(f))&&!f.getAttribute("instantiated_by_use"))return!0;return!1}(u)));if(!a||a&&!a.length)return T(T({},Cg()),{},{options:r,allElements:n});const h={};return n.filter(u=>Xu(u)==="clipPath").forEach(u=>{u.setAttribute("originalTransform",u.getAttribute("transform")||"");const d=u.getAttribute("id");h[d]=Array.from(u.getElementsByTagName("*")).filter(f=>Cv(f))}),{objects:await new jx(a,r,t,o,h).parse(),elements:a,options:r,allElements:n}}function Bx(o,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return new Promise((s,i)=>{tv(o.replace(/^\n\s*/,"").trim(),{onComplete:n=>{const r=n.responseXML;r&&s(r),i()},signal:e.signal})}).then(s=>Nx(s,t,e)).catch(()=>Cg())}const Uu=o=>o.webgl!==void 0,Ag="precision highp float",Hx=`
92
- `.concat(Ag,`;
91
+ `)],this.fill=c}return n=this.paintFirst!==ee?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 Jh(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=ps(r),{width:h,height:c}=r;this._element=o,this._lastScaleX=t.scaleX=i,this._lastScaleY=t.scaleY=n,Cg().applyFilters([t],r,h,c,this._element),this._filterScalingX=o.width/this._originalElement.width,this._filterScalingY=o.height/this._originalElement.height}applyFilters(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.filters||[];if(t=t.filter(n=>n&&!n.isNeutralState()),this.set("dirty",!0),this.removeTexture("".concat(this.cacheKey,"_filtered")),t.length===0)return this._element=this._originalElement,this._filteredEl=void 0,this._filterScalingX=1,void(this._filterScalingY=1);const e=this._originalElement,s=e.naturalWidth||e.width,i=e.naturalHeight||e.height;if(this._element===this._originalElement){const n=ps({width:s,height:i});this._element=n,this._filteredEl=n}else this._filteredEl&&(this._element=this._filteredEl,this._filteredEl.getContext("2d").clearRect(0,0,s,i),this._lastScaleX=1,this._lastScaleY=1);Cg().applyFilters(t,this._originalElement,s,i,this._element,this.cacheKey),this._originalElement.width===this._element.width&&this._originalElement.height===this._element.height||(this._filterScalingX=this._element.width/this._originalElement.width,this._filterScalingY=this._element.height/this._originalElement.height)}_render(t){t.imageSmoothingEnabled=this.imageSmoothing,this.isMoving!==!0&&this.resizeFilter&&this._needsResize()&&this.applyResizeFilters(),this._stroke(t),this._renderPaintInOrder(t)}drawCacheOnCanvas(t){t.imageSmoothingEnabled=this.imageSmoothing,super.drawCacheOnCanvas(t)}shouldCache(){return this.needsItsOwnCache()}_renderFill(t){const e=this._element;if(!e)return;const s=this._filterScalingX,i=this._filterScalingY,n=this.width,r=this.height,o=Math.max(this.cropX,0),h=Math.max(this.cropY,0),c=e.naturalWidth||e.width,u=e.naturalHeight||e.height,d=o*s,f=h*i,g=Math.min(n*s,c-d),p=Math.min(r*i,u-f),m=-n/2,y=-r/2,b=Math.min(n,c/s-o),x=Math.min(r,u/i-h);e&&t.drawImage(e,d,f,g,p,m,y,b,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=qf(this.preserveAspectRatio||""),e=this.width,s=this.height,i={width:e,height:s};let n,r=this._element.width,o=this._element.height,h=1,c=1,u=0,d=0,f=0,g=0;return!t||t.alignX===ze&&t.alignY===ze?(h=e/r,c=s/o):(t.meetOrSlice==="meet"&&(h=c=Jv(this._element,i),n=(e-r*h)/2,t.alignX==="Min"&&(u=-n),t.alignX==="Max"&&(u=n),n=(s-o*c)/2,t.alignY==="Min"&&(d=-n),t.alignY==="Max"&&(d=n)),t.meetOrSlice==="slice"&&(h=c=Qv(this._element,i),n=r-e/h,t.alignX==="Mid"&&(f=n/2),t.alignX==="Max"&&(f=n),n=o-s/c,t.alignY==="Mid"&&(g=n/2),t.alignY==="Max"&&(g=n),r=e/h,o=s/c)),{width:r,height:o,scaleX:h,scaleY:c,offsetLeft:u,offsetTop:d,cropX:f,cropY:g}}static fromObject(t,e){let{filters:s,resizeFilter:i,src:n,crossOrigin:r,type:o}=t,h=Lt(t,Hx);return Promise.all([Jh(n,E(E({},e),{},{crossOrigin:r})),s&&ma(s,e),i&&ma([i],e),Qh(h,e)]).then(c=>{let[u,d=[],[f]=[],g={}]=c;return new this(u,E(E({},h),{},{src:n,filters:d,resizeFilter:f},g))})}static fromURL(t){let{crossOrigin:e=null,signal:s}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;return Jh(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=en(t,this.ATTRIBUTE_NAMES,s);return this.fromURL(i["xlink:href"]||i.href,e,i).catch(n=>(Ki("log","Unable to parse Image",n),null))}}function Ag(a){if(!U_.test(a.nodeName))return{};const t=a.getAttribute("viewBox");let e,s,i=1,n=1,r=0,o=0;const h=a.getAttribute("width"),c=a.getAttribute("height"),u=a.getAttribute("x")||0,d=a.getAttribute("y")||0,f=!(t&&pv.test(t)),g=!h||!c||h==="100%"||c==="100%";let p="",m=0,y=0;if(f&&(u||d)&&a.parentNode&&a.parentNode.nodeName!=="#document"&&(p=" translate("+We(u||"0")+" "+We(d||"0")+") ",e=(a.getAttribute("transform")||"")+p,a.setAttribute("transform",e),a.removeAttribute("x"),a.removeAttribute("y")),f&&g)return{width:0,height:0};const b={width:0,height:0};if(f)return b.width=We(h),b.height=We(c),b;const x=t.match(pv);r=-parseFloat(x[1]),o=-parseFloat(x[2]);const C=parseFloat(x[3]),S=parseFloat(x[4]);b.minX=r,b.minY=o,b.viewBoxWidth=C,b.viewBoxHeight=S,g?(b.width=C,b.height=S):(b.width=We(h),b.height=We(c),i=b.width/C,n=b.height/S);const T=qf(a.getAttribute("preserveAspectRatio")||"");if(T.alignX!==ze&&(T.meetOrSlice==="meet"&&(n=i=i>n?n:i),T.meetOrSlice==="slice"&&(n=i=i>n?i:n),m=b.width-C*i,y=b.height-S*i,T.alignX==="Mid"&&(m/=2),T.alignY==="Mid"&&(y/=2),T.alignX==="Min"&&(m=0),T.alignY==="Min"&&(y=0)),i===1&&n===1&&r===0&&o===0&&u===0&&d===0)return b;if((u||d)&&a.parentNode.nodeName!=="#document"&&(p=" translate("+We(u||"0")+" "+We(d||"0")+") "),e=p+" matrix("+i+" 0 0 "+n+" "+(r*i+m)+" "+(o*n+y)+") ",a.nodeName==="svg"){for(s=a.ownerDocument.createElementNS(Jf,"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),b}k(Me,"type","Image"),k(Me,"cacheProperties",[...Zi,...T0]),k(Me,"ownDefaults",{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),k(Me,"CSS_CANVAS","canvas-img"),k(Me,"ATTRIBUTE_NAMES",[...Xn,"x","y","width","height","preserveAspectRatio","xlink:href","href","crossOrigin","image-rendering"]),G.setClass(Me),G.setSVGClass(Me);const Yu=a=>a.tagName.replace("svg:",""),zx=xu(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);function E0(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 Vx=["gradientTransform","x1","x2","y1","y2","gradientUnits","cx","cy","r","fx","fy"],Tg="xlink:href";function k0(a,t){var e;const s=((e=t.getAttribute(Tg))===null||e===void 0?void 0:e.slice(1))||"",i=a.getElementById(s);if(i&&i.getAttribute(Tg)&&k0(a,i),i&&(Vx.forEach(n=>{const r=i.getAttribute(n);!t.hasAttribute(n)&&r&&t.setAttribute(n,r)}),!t.children.length)){const n=i.cloneNode(!0);for(;n.firstChild;)t.appendChild(n.firstChild)}t.removeAttribute(Tg)}const Gx=["linearGradient","radialGradient","svg:linearGradient","svg:radialGradient"];function Wx(a){const t=a.getElementsByTagName("style");let e,s;const i={};for(e=0,s=t.length;e<s;e++){const n=(t[e].textContent||"").replace(/\/\*[\s\S]*?\*\//g,"");n.trim()!==""&&n.split("}").filter((r,o,h)=>h.length>1&&r.trim()).forEach(r=>{if((r.match(/{/g)||[]).length>1&&r.trim().startsWith("@"))return;const o=r.split("{"),h={},c=o[1].trim().split(";").filter(function(u){return u.trim()});for(e=0,s=c.length;e<s;e++){const u=c[e].split(":"),d=u[0].trim(),f=u[1].trim();h[d]=f}(r=o[0].trim()).split(",").forEach(u=>{(u=u.replace(/^svg/i,"").trim())!==""&&(i[u]=E(E({},i[u]||{}),h))})})}return i}const P0=a=>G.getSVGClass(Yu(a).toLowerCase());class Xx{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=E0(r,Gx),h={};let c=o.length;for(;c--;){const u=o[c];u.getAttribute("xlink:href")&&k0(r,u);const d=u.getAttribute("id");d&&(h[d]=u)}return h}(i),this.cssRules=Wx(i)}parse(){return Promise.all(this.elements.map(t=>this.createObject(t)))}async createObject(t){const e=P0(t);if(e){const s=await e.fromElement(t,this.options,this.cssRules);return this.resolveGradient(s,t,ee),this.resolveGradient(s,t,Ge),s instanceof Me&&s._originalElement?Bu(s,s.parsePreserveAspectRatioAttribute()):Bu(s),await this.resolveClipPath(s,t),this.reviver&&this.reviver(t,s),s}return null}extractPropertyDefinition(t,e,s){const i=t[e],n=this.regexUrl;if(!n.test(i))return;n.lastIndex=0;const r=n.exec(i)[1];return n.lastIndex=0,s[r]}resolveGradient(t,e,s){const i=this.extractPropertyDefinition(t,s,this.gradientDefs);if(i){const n=e.getAttribute(s+"-opacity"),r=ll.fromElement(i,t,E(E({},this.options),{},{opacity:n}));t.set(s,r)}}async resolveClipPath(t,e,s){const i=this.extractPropertyDefinition(t,"clipPath",this.clipPaths);if(i){const n=ns(t.calcTransformMatrix()),r=i[0].parentElement;let o=e;for(;!s&&o.parentElement&&o.getAttribute("clip-path")!==t.clipPath;)o=o.parentElement;o.parentElement.appendChild(r);const h=Ru("".concat(o.getAttribute("transform")||""," ").concat(r.getAttribute("originalTransform")||""));r.setAttribute("transform","matrix(".concat(h.join(","),")"));const c=await Promise.all(i.map(x=>P0(x).fromElement(x,this.options,this.cssRules).then(C=>(Bu(C),C.fillRule=C.clipRule,delete C.clipRule,C)))),u=c.length===1?c[0]:new Fs(c),d=qt(n,u.calcTransformMatrix());u.clipPath&&await this.resolveClipPath(u,o,r.getAttribute("clip-path")?o:void 0);const{scaleX:f,scaleY:g,angle:p,skewX:m,translateX:y,translateY:b}=Lr(d);u.set({flipX:!1,flipY:!1}),u.set({scaleX:f,scaleY:g,angle:p,skewX:m,skewY:0}),u.setPositionByOrigin(new O(y,b),rt,rt),t.clipPath=u}else delete t.clipPath}}const M0=a=>X_.test(Yu(a)),Eg=()=>({objects:[],elements:[],options:{},allElements:[]});async function Ux(a,t){let{crossOrigin:e,signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(s&&s.aborted)return Ki("log",new Mf("parseSVGDocument")),Eg();const i=a.documentElement;(function(u){const d=E0(u,["use","svg:use"]),f=["x","y","xlink:href","href","transform"];for(const g of d){const p=g.attributes,m={};for(const R of p)R.value&&(m[R.name]=R.value);const y=(m["xlink:href"]||m.href||"").slice(1);if(y==="")return;const b=u.getElementById(y);if(b===null)return;let x=b.cloneNode(!0);const C=x.attributes,S={};for(const R of C)R.value&&(S[R.name]=R.value);const{x:T=0,y:P=0,transform:M=""}=m,D="".concat(M," ").concat(S.transform||""," translate(").concat(T,", ").concat(P,")");if(Ag(x),/^svg$/i.test(x.nodeName)){const R=x.ownerDocument.createElementNS(Jf,"g");Object.entries(S).forEach(V=>{let[H,F]=V;return R.setAttributeNS(Jf,H,F)}),R.append(...x.childNodes),x=R}for(const R of p){if(!R)continue;const{name:V,value:H}=R;if(!f.includes(V))if(V==="style"){const F={};dg(H,F),Object.entries(S).forEach(j=>{let[K,L]=j;F[K]=L}),dg(S.style||"",F);const I=Object.entries(F).map(j=>j.join(":")).join(";");x.setAttribute(V,I)}else!S[V]&&x.setAttribute(V,H)}x.setAttribute("transform",D),x.setAttribute("instantiated_by_use","1"),x.removeAttribute("id"),g.parentNode.replaceChild(x,g)}})(a);const n=Array.from(i.getElementsByTagName("*")),r=E(E({},Ag(i)),{},{crossOrigin:e,signal:s}),o=n.filter(u=>(Ag(u),M0(u)&&!function(d){let f=d;for(;f&&(f=f.parentElement);)if(f&&f.nodeName&&zx.test(Yu(f))&&!f.getAttribute("instantiated_by_use"))return!0;return!1}(u)));if(!o||o&&!o.length)return E(E({},Eg()),{},{options:r,allElements:n});const h={};return n.filter(u=>Yu(u)==="clipPath").forEach(u=>{u.setAttribute("originalTransform",u.getAttribute("transform")||"");const d=u.getAttribute("id");h[d]=Array.from(u.getElementsByTagName("*")).filter(f=>M0(f))}),{objects:await new Xx(o,r,t,a,h).parse(),elements:o,options:r,allElements:n}}function Yx(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return new Promise((s,i)=>{c0(a.replace(/^\n\s*/,"").trim(),{onComplete:n=>{const r=n.responseXML;r&&s(r),i()},signal:e.signal})}).then(s=>Ux(s,t,e)).catch(()=>Eg())}const $u=a=>a.webgl!==void 0,kg="precision highp float",$x=`
92
+ `.concat(kg,`;
93
93
  varying vec2 vTexCoord;
94
94
  uniform sampler2D uTexture;
95
95
  void main() {
96
96
  gl_FragColor = texture2D(uTexture, vTexCoord);
97
- }`),zx=["type"],Vx=["type"],Wx=new RegExp(Ag,"g");class he{get type(){return this.constructor.type}constructor(){let t=Lt(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},zx);Object.assign(this,this.constructor.defaults,t)}getFragmentSource(){return Hx}getVertexSource(){return`
97
+ }`),qx=["type"],Kx=["type"],Jx=new RegExp(kg,"g");class he{get type(){return this.constructor.type}constructor(){let t=Lt(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},qx);Object.assign(this,this.constructor.defaults,t)}getFragmentSource(){return $x}getVertexSource(){return`
98
98
  attribute vec2 aPosition;
99
99
  varying vec2 vTexCoord;
100
100
  void main() {
101
101
  vTexCoord = aPosition;
102
102
  gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);
103
- }`}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"}}=xi();i!=="highp"&&(e=e.replace(Wx,Ag.replace("highp",i)));const n=t.createShader(t.VERTEX_SHADER),r=t.createShader(t.FRAGMENT_SHADER),a=t.createProgram();if(!n||!r||!a)throw new wi("Vertex, fragment shader or program creation error");if(t.shaderSource(n,s),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new wi("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 wi("Fragment shader compile error for ".concat(this.type,": ").concat(t.getShaderInfoLog(r)));if(t.attachShader(a,n),t.attachShader(a,r),t.linkProgram(a),!t.getProgramParameter(a,t.LINK_STATUS))throw new wi('Shader link error for "'.concat(this.type,'" ').concat(t.getProgramInfoLog(a)));const h=this.getUniformLocations(t,a)||{};return h.uStepW=t.getUniformLocation(a,"uStepW"),h.uStepH=t.getUniformLocation(a,"uStepH"),{program:a,attributeLocations:this.getAttributeLocations(t,a),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){Uu(t)?(this._setupFrameBuffer(t),this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){}getCacheKey(){return this.type}retrieveShader(t){const e=this.getCacheKey();return t.programCache[e]||(t.programCache[e]=this.createProgram(t.context)),t.programCache[e]}applyToWebGL(t){const e=t.context,s=this.retrieveShader(t);t.pass===0&&t.originalTexture?e.bindTexture(e.TEXTURE_2D,t.originalTexture):e.bindTexture(e.TEXTURE_2D,t.sourceTexture),e.useProgram(s.program),this.sendAttributeData(e,s.attributeLocations,t.aPosition),e.uniform1f(s.uniformLocations.uStepW,1/t.sourceWidth),e.uniform1f(s.uniformLocations.uStepH,1/t.sourceHeight),this.sendUniformData(e,s.uniformLocations),e.viewport(0,0,t.destinationWidth,t.destinationHeight),e.drawArrays(e.TRIANGLE_STRIP,0,4)}bindAdditionalTexture(t,e,s){t.activeTexture(s),t.bindTexture(t.TEXTURE_2D,e),t.activeTexture(t.TEXTURE0)}unbindAdditionalTexture(t,e){t.activeTexture(e),t.bindTexture(t.TEXTURE_2D,null),t.activeTexture(t.TEXTURE0)}sendUniformData(t,e){}createHelpLayer(t){if(!t.helpLayer){const{sourceWidth:e,sourceHeight:s}=t,i=ps({width:e,height:s});t.helpLayer=i}}toObject(){const t=Object.keys(this.constructor.defaults||{});return T({type:this.type},t.reduce((e,s)=>(e[s]=this[s],e),{}))}toJSON(){return this.toObject()}static async fromObject(t,e){return new this(Lt(t,Vx))}}E(he,"type","BaseFilter"),E(he,"uniformLocations",[]);const Gx={multiply:`gl_FragColor.rgb *= uColor.rgb;
103
+ }`}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"}}=xi();i!=="highp"&&(e=e.replace(Jx,kg.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 wi("Vertex, fragment shader or program creation error");if(t.shaderSource(n,s),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new wi("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 wi("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 wi('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){$u(t)?(this._setupFrameBuffer(t),this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){}getCacheKey(){return this.type}retrieveShader(t){const e=this.getCacheKey();return t.programCache[e]||(t.programCache[e]=this.createProgram(t.context)),t.programCache[e]}applyToWebGL(t){const e=t.context,s=this.retrieveShader(t);t.pass===0&&t.originalTexture?e.bindTexture(e.TEXTURE_2D,t.originalTexture):e.bindTexture(e.TEXTURE_2D,t.sourceTexture),e.useProgram(s.program),this.sendAttributeData(e,s.attributeLocations,t.aPosition),e.uniform1f(s.uniformLocations.uStepW,1/t.sourceWidth),e.uniform1f(s.uniformLocations.uStepH,1/t.sourceHeight),this.sendUniformData(e,s.uniformLocations),e.viewport(0,0,t.destinationWidth,t.destinationHeight),e.drawArrays(e.TRIANGLE_STRIP,0,4)}bindAdditionalTexture(t,e,s){t.activeTexture(s),t.bindTexture(t.TEXTURE_2D,e),t.activeTexture(t.TEXTURE0)}unbindAdditionalTexture(t,e){t.activeTexture(e),t.bindTexture(t.TEXTURE_2D,null),t.activeTexture(t.TEXTURE0)}sendUniformData(t,e){}createHelpLayer(t){if(!t.helpLayer){const{sourceWidth:e,sourceHeight:s}=t,i=ps({width:e,height:s});t.helpLayer=i}}toObject(){const t=Object.keys(this.constructor.defaults||{});return E({type:this.type},t.reduce((e,s)=>(e[s]=this[s],e),{}))}toJSON(){return this.toObject()}static async fromObject(t,e){return new this(Lt(t,Kx))}}k(he,"type","BaseFilter"),k(he,"uniformLocations",[]);const Qx={multiply:`gl_FragColor.rgb *= uColor.rgb;
104
104
  `,screen:`gl_FragColor.rgb = 1.0 - (1.0 - gl_FragColor.rgb) * (1.0 - uColor.rgb);
105
105
  `,add:`gl_FragColor.rgb += uColor.rgb;
106
106
  `,difference:`gl_FragColor.rgb = abs(gl_FragColor.rgb - uColor.rgb);
@@ -127,7 +127,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
127
127
  `,tint:`
128
128
  gl_FragColor.rgb *= (1.0 - uColor.a);
129
129
  gl_FragColor.rgb += uColor.rgb;
130
- `};class Yu extends he{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return`
130
+ `};class qu extends he{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return`
131
131
  precision highp float;
132
132
  uniform sampler2D uTexture;
133
133
  uniform vec4 uColor;
@@ -136,10 +136,10 @@ Resulting to default behavior: removing object from previous canvas and adding t
136
136
  vec4 color = texture2D(uTexture, vTexCoord);
137
137
  gl_FragColor = color;
138
138
  if (color.a > 0.0) {
139
- `.concat(Gx[this.mode],`
139
+ `.concat(Qx[this.mode],`
140
140
  }
141
141
  }
142
- `)}applyTo2d(t){let{imageData:{data:e}}=t;const s=new St(this.color).getSource(),i=this.alpha,n=s[0]*i,r=s[1]*i,a=s[2]*i,h=1-i;for(let c=0;c<e.length;c+=4){const u=e[c],d=e[c+1],f=e[c+2];let g,p,m;switch(this.mode){case"multiply":g=u*n/255,p=d*r/255,m=f*a/255;break;case"screen":g=255-(255-u)*(255-n)/255,p=255-(255-d)*(255-r)/255,m=255-(255-f)*(255-a)/255;break;case"add":g=u+n,p=d+r,m=f+a;break;case"difference":g=Math.abs(u-n),p=Math.abs(d-r),m=Math.abs(f-a);break;case"subtract":g=u-n,p=d-r,m=f-a;break;case"darken":g=Math.min(u,n),p=Math.min(d,r),m=Math.min(f,a);break;case"lighten":g=Math.max(u,n),p=Math.max(d,r),m=Math.max(f,a);break;case"overlay":g=n<128?2*u*n/255:255-2*(255-u)*(255-n)/255,p=r<128?2*d*r/255:255-2*(255-d)*(255-r)/255,m=a<128?2*f*a/255:255-2*(255-f)*(255-a)/255;break;case"exclusion":g=n+u-2*n*u/255,p=r+d-2*r*d/255,m=a+f-2*a*f/255;break;case"tint":g=n+u*h,p=r+d*h,m=a+f*h}e[c]=g,e[c+1]=p,e[c+2]=m}}sendUniformData(t,e){const s=new St(this.color).getSource();s[0]=this.alpha*s[0]/255,s[1]=this.alpha*s[1]/255,s[2]=this.alpha*s[2]/255,s[3]=this.alpha,t.uniform4fv(e.uColor,s)}}E(Yu,"defaults",{color:"#F95C63",mode:"multiply",alpha:1}),E(Yu,"type","BlendColor"),E(Yu,"uniformLocations",["uColor"]),W.setClass(Yu);const Xx={multiply:`
142
+ `)}applyTo2d(t){let{imageData:{data:e}}=t;const s=new St(this.color).getSource(),i=this.alpha,n=s[0]*i,r=s[1]*i,o=s[2]*i,h=1-i;for(let c=0;c<e.length;c+=4){const u=e[c],d=e[c+1],f=e[c+2];let g,p,m;switch(this.mode){case"multiply":g=u*n/255,p=d*r/255,m=f*o/255;break;case"screen":g=255-(255-u)*(255-n)/255,p=255-(255-d)*(255-r)/255,m=255-(255-f)*(255-o)/255;break;case"add":g=u+n,p=d+r,m=f+o;break;case"difference":g=Math.abs(u-n),p=Math.abs(d-r),m=Math.abs(f-o);break;case"subtract":g=u-n,p=d-r,m=f-o;break;case"darken":g=Math.min(u,n),p=Math.min(d,r),m=Math.min(f,o);break;case"lighten":g=Math.max(u,n),p=Math.max(d,r),m=Math.max(f,o);break;case"overlay":g=n<128?2*u*n/255:255-2*(255-u)*(255-n)/255,p=r<128?2*d*r/255:255-2*(255-d)*(255-r)/255,m=o<128?2*f*o/255:255-2*(255-f)*(255-o)/255;break;case"exclusion":g=n+u-2*n*u/255,p=r+d-2*r*d/255,m=o+f-2*o*f/255;break;case"tint":g=n+u*h,p=r+d*h,m=o+f*h}e[c]=g,e[c+1]=p,e[c+2]=m}}sendUniformData(t,e){const s=new St(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)}}k(qu,"defaults",{color:"#F95C63",mode:"multiply",alpha:1}),k(qu,"type","BlendColor"),k(qu,"uniformLocations",["uColor"]),G.setClass(qu);const Zx={multiply:`
143
143
  precision highp float;
144
144
  uniform sampler2D uTexture;
145
145
  uniform sampler2D uImage;
@@ -165,7 +165,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
165
165
  color.a = color2.a;
166
166
  gl_FragColor = color;
167
167
  }
168
- `},Ux=["type","image"];class $u extends he{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return Xx[this.mode]}getVertexSource(){return`
168
+ `},tS=["type","image"];class Ku extends he{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return Zx[this.mode]}getVertexSource(){return`
169
169
  attribute vec2 aPosition;
170
170
  varying vec2 vTexCoord;
171
171
  varying vec2 vTexCoord2;
@@ -175,7 +175,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
175
175
  vTexCoord2 = (uTransformMatrix * vec3(aPosition, 1.0)).xy;
176
176
  gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);
177
177
  }
178
- `}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=Rs());const a=n.blendImage,h=a.getContext("2d");a.width!==s||a.height!==i?(a.width=s,a.height=i):h.clearRect(0,0,s,i),h.setTransform(r.scaleX,0,0,r.scaleY,r.left,r.top),h.drawImage(r.getElement(),0,0,s,i);const c=h.getImageData(0,0,s,i).data;for(let u=0;u<e.length;u+=4){const d=e[u],f=e[u+1],g=e[u+2],p=e[u+3],m=c[u],y=c[u+1],b=c[u+2],x=c[u+3];switch(this.mode){case"multiply":e[u]=d*m/255,e[u+1]=f*y/255,e[u+2]=g*b/255,e[u+3]=p*x/255;break;case"mask":e[u+3]=x}}}sendUniformData(t,e){const s=this.calculateMatrix();t.uniform1i(e.uImage,1),t.uniformMatrix3fv(e.uTransformMatrix,!1,s)}toObject(){return T(T({},super.toObject()),{},{image:this.image&&this.image.toObject()})}static async fromObject(t,e){let{type:s,image:i}=t,n=Lt(t,Ux);return Me.fromObject(i,e).then(r=>new this(T(T({},n),{},{image:r})))}}E($u,"type","BlendImage"),E($u,"defaults",{mode:"multiply",alpha:1}),E($u,"uniformLocations",["uTransformMatrix","uImage"]),W.setClass($u);class qu extends he{getFragmentSource(){return`
178
+ `}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=Si());const o=n.blendImage,h=o.getContext("2d");o.width!==s||o.height!==i?(o.width=s,o.height=i):h.clearRect(0,0,s,i),h.setTransform(r.scaleX,0,0,r.scaleY,r.left,r.top),h.drawImage(r.getElement(),0,0,s,i);const c=h.getImageData(0,0,s,i).data;for(let u=0;u<e.length;u+=4){const d=e[u],f=e[u+1],g=e[u+2],p=e[u+3],m=c[u],y=c[u+1],b=c[u+2],x=c[u+3];switch(this.mode){case"multiply":e[u]=d*m/255,e[u+1]=f*y/255,e[u+2]=g*b/255,e[u+3]=p*x/255;break;case"mask":e[u+3]=x}}}sendUniformData(t,e){const s=this.calculateMatrix();t.uniform1i(e.uImage,1),t.uniformMatrix3fv(e.uTransformMatrix,!1,s)}toObject(){return E(E({},super.toObject()),{},{image:this.image&&this.image.toObject()})}static async fromObject(t,e){let{type:s,image:i}=t,n=Lt(t,tS);return Me.fromObject(i,e).then(r=>new this(E(E({},n),{},{image:r})))}}k(Ku,"type","BlendImage"),k(Ku,"defaults",{mode:"multiply",alpha:1}),k(Ku,"uniformLocations",["uTransformMatrix","uImage"]),G.setClass(Ku);class Ju extends he{getFragmentSource(){return`
179
179
  precision highp float;
180
180
  uniform sampler2D uTexture;
181
181
  uniform vec2 uDelta;
@@ -188,17 +188,23 @@ Resulting to default behavior: removing object from previous canvas and adding t
188
188
  }
189
189
  void main() {
190
190
  vec4 color = vec4(0.0);
191
- float total = 0.0;
191
+ float totalC = 0.0;
192
+ float totalA = 0.0;
192
193
  float offset = random(v3offset);
193
194
  for (float t = -nSamples; t <= nSamples; t++) {
194
195
  float percent = (t + offset - 0.5) / nSamples;
196
+ vec4 sample = texture2D(uTexture, vTexCoord + uDelta * percent);
195
197
  float weight = 1.0 - abs(percent);
196
- color += texture2D(uTexture, vTexCoord + uDelta * percent) * weight;
197
- total += weight;
198
+ float alpha = weight * sample.a;
199
+ color.rgb += sample.rgb * alpha;
200
+ color.a += alpha;
201
+ totalA += weight;
202
+ totalC += alpha;
198
203
  }
199
- gl_FragColor = color / total;
204
+ gl_FragColor.rgb = color.rgb / totalC;
205
+ gl_FragColor.a = color.a / totalA;
200
206
  }
201
- `}applyTo(t){Uu(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=Rs(),i.blurLayer2=Rs());const a=i.blurLayer1,h=i.blurLayer2;a.width===n&&a.height===r||(h.width=a.width=n,h.height=a.height=r);const c=a.getContext("2d"),u=h.getContext("2d"),d=15,f=.06*this.blur*.5;let g,p,m,y;for(c.putImageData(s,0,0),u.clearRect(0,0,n,r),y=-15;y<=d;y++)g=(Math.random()-.5)/4,p=y/d,m=f*p*n+g,u.globalAlpha=1-Math.abs(p),u.drawImage(a,m,g),c.drawImage(h,0,0),u.globalAlpha=1,u.clearRect(0,0,h.width,h.height);for(y=-15;y<=d;y++)g=(Math.random()-.5)/4,p=y/d,m=f*p*r+g,u.globalAlpha=1-Math.abs(p),u.drawImage(a,g,m),c.drawImage(h,0,0),u.globalAlpha=1,u.clearRect(0,0,h.width,h.height);e.drawImage(a,0,0);const b=e.getImageData(0,0,a.width,a.height);return c.globalAlpha=1,c.clearRect(0,0,a.width,a.height),b}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}}E(qu,"type","Blur"),E(qu,"defaults",{blur:0}),E(qu,"uniformLocations",["uDelta"]),W.setClass(qu);class Ku extends he{getFragmentSource(){return`
207
+ `}applyTo(t){$u(t)?(this.aspectRatio=t.sourceWidth/t.sourceHeight,t.passes++,this._setupFrameBuffer(t),this.horizontal=!0,this.applyToWebGL(t),this._swapTextures(t),this._setupFrameBuffer(t),this.horizontal=!1,this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){let{imageData:{data:e,width:s,height:i}}=t;this.aspectRatio=s/i,this.horizontal=!0;let n=this.getBlurValue()*s;const r=new Uint8ClampedArray(e),o=15,h=4*s;for(let c=0;c<e.length;c+=4){let u=0,d=0,f=0,g=0,p=0;const m=c-c%h,y=m+h;for(let b=-14;b<o;b++){const x=b/o,C=4*Math.floor(n*x),S=1-Math.abs(x);let T=c+C;T<m?T=m:T>y&&(T=y);const P=e[T+3]*S;u+=e[T]*P,d+=e[T+1]*P,f+=e[T+2]*P,g+=P,p+=S}r[c]=u/g,r[c+1]=d/g,r[c+2]=f/g,r[c+3]=g/p}this.horizontal=!1,n=this.getBlurValue()*i;for(let c=0;c<r.length;c+=4){let u=0,d=0,f=0,g=0,p=0;const m=c%h,y=r.length-h+m;for(let b=-14;b<o;b++){const x=b/o,C=Math.floor(n*x)*h,S=1-Math.abs(x);let T=c+C;T<m?T=m:T>y&&(T=y);const P=r[T+3]*S;u+=r[T]*P,d+=r[T+1]*P,f+=r[T+2]*P,g+=P,p+=S}e[c]=u/g,e[c+1]=d/g,e[c+2]=f/g,e[c+3]=g/p}}sendUniformData(t,e){const s=this.chooseRightDelta();t.uniform2fv(e.uDelta,s)}isNeutralState(){return this.blur===0}getBlurValue(){let t=1;const{horizontal:e,aspectRatio:s}=this;return e?s>1&&(t=1/s):s<1&&(t=s),t*this.blur*.12}chooseRightDelta(){const t=this.getBlurValue();return this.horizontal?[t,0]:[0,t]}}k(Ju,"type","Blur"),k(Ju,"defaults",{blur:0}),k(Ju,"uniformLocations",["uDelta"]),G.setClass(Ju);class Qu extends he{getFragmentSource(){return`
202
208
  precision highp float;
203
209
  uniform sampler2D uTexture;
204
210
  uniform float uBrightness;
@@ -208,7 +214,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
208
214
  color.rgb += uBrightness;
209
215
  gl_FragColor = color;
210
216
  }
211
- `}applyTo2d(t){let{imageData:{data:e}}=t;const s=Math.round(255*this.brightness);for(let i=0;i<e.length;i+=4)e[i]+=s,e[i+1]+=s,e[i+2]+=s}isNeutralState(){return this.brightness===0}sendUniformData(t,e){t.uniform1f(e.uBrightness,this.brightness)}}E(Ku,"type","Brightness"),E(Ku,"defaults",{brightness:0}),E(Ku,"uniformLocations",["uBrightness"]),W.setClass(Ku);const Av={matrix:[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],colorsOnly:!0};class Ao extends he{getFragmentSource(){return`
217
+ `}applyTo2d(t){let{imageData:{data:e}}=t;const s=Math.round(255*this.brightness);for(let i=0;i<e.length;i+=4)e[i]+=s,e[i+1]+=s,e[i+2]+=s}isNeutralState(){return this.brightness===0}sendUniformData(t,e){t.uniform1f(e.uBrightness,this.brightness)}}k(Qu,"type","Brightness"),k(Qu,"defaults",{brightness:0}),k(Qu,"uniformLocations",["uBrightness"]),G.setClass(Qu);const O0={matrix:[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],colorsOnly:!0};class Ta extends he{getFragmentSource(){return`
212
218
  precision highp float;
213
219
  uniform sampler2D uTexture;
214
220
  varying vec2 vTexCoord;
@@ -219,7 +225,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
219
225
  color *= uColorMatrix;
220
226
  color += uConstants;
221
227
  gl_FragColor = color;
222
- }`}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],a=e[n+1],h=e[n+2];if(e[n]=r*s[0]+a*s[1]+h*s[2]+255*s[4],e[n+1]=r*s[5]+a*s[6]+h*s[7]+255*s[9],e[n+2]=r*s[10]+a*s[11]+h*s[12]+255*s[14],!i){const c=e[n+3];e[n]+=c*s[3],e[n+1]+=c*s[8],e[n+2]+=c*s[13],e[n+3]=r*s[15]+a*s[16]+h*s[17]+c*s[18]+255*s[19]}}}sendUniformData(t,e){const s=this.matrix,i=[s[0],s[1],s[2],s[3],s[5],s[6],s[7],s[8],s[10],s[11],s[12],s[13],s[15],s[16],s[17],s[18]],n=[s[4],s[9],s[14],s[19]];t.uniformMatrix4fv(e.uColorMatrix,!1,i),t.uniform4fv(e.uConstants,n)}toObject(){return T(T({},super.toObject()),{},{matrix:[...this.matrix]})}}function Ur(o,t){var e;const s=(E(e=class extends Ao{toObject(){return{type:this.type,colorsOnly:this.colorsOnly}}},"type",o),E(e,"defaults",{colorsOnly:!1,matrix:t}),e);return W.setClass(s,o),s}E(Ao,"type","ColorMatrix"),E(Ao,"defaults",Av),E(Ao,"uniformLocations",["uColorMatrix","uConstants"]),W.setClass(Ao),Ur("Brownie",[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0]),Ur("Vintage",[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0]),Ur("Kodachrome",[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0]),Ur("Technicolor",[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0]),Ur("Polaroid",[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0]),Ur("Sepia",[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0]),Ur("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 Tv extends he{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.subFilters=t.subFilters||[]}applyTo(t){Uu(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=>W.getClass(s.type).fromObject(s,e))).then(s=>new this({subFilters:s}))}}E(Tv,"type","Composed"),W.setClass(Tv);class Ju extends he{getFragmentSource(){return`
228
+ }`}applyTo2d(t){const e=t.imageData.data,s=this.matrix,i=this.colorsOnly;for(let n=0;n<e.length;n+=4){const r=e[n],o=e[n+1],h=e[n+2];if(e[n]=r*s[0]+o*s[1]+h*s[2]+255*s[4],e[n+1]=r*s[5]+o*s[6]+h*s[7]+255*s[9],e[n+2]=r*s[10]+o*s[11]+h*s[12]+255*s[14],!i){const c=e[n+3];e[n]+=c*s[3],e[n+1]+=c*s[8],e[n+2]+=c*s[13],e[n+3]=r*s[15]+o*s[16]+h*s[17]+c*s[18]+255*s[19]}}}sendUniformData(t,e){const s=this.matrix,i=[s[0],s[1],s[2],s[3],s[5],s[6],s[7],s[8],s[10],s[11],s[12],s[13],s[15],s[16],s[17],s[18]],n=[s[4],s[9],s[14],s[19]];t.uniformMatrix4fv(e.uColorMatrix,!1,i),t.uniform4fv(e.uConstants,n)}toObject(){return E(E({},super.toObject()),{},{matrix:[...this.matrix]})}}function Yr(a,t){var e;const s=(k(e=class extends Ta{toObject(){return{type:this.type,colorsOnly:this.colorsOnly}}},"type",a),k(e,"defaults",{colorsOnly:!1,matrix:t}),e);return G.setClass(s,a),s}k(Ta,"type","ColorMatrix"),k(Ta,"defaults",O0),k(Ta,"uniformLocations",["uColorMatrix","uConstants"]),G.setClass(Ta),Yr("Brownie",[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0]),Yr("Vintage",[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0]),Yr("Kodachrome",[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0]),Yr("Technicolor",[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0]),Yr("Polaroid",[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0]),Yr("Sepia",[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0]),Yr("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 D0 extends he{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.subFilters=t.subFilters||[]}applyTo(t){$u(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=>G.getClass(s.type).fromObject(s,e))).then(s=>new this({subFilters:s}))}}k(D0,"type","Composed"),G.setClass(D0);class Zu extends he{getFragmentSource(){return`
223
229
  precision highp float;
224
230
  uniform sampler2D uTexture;
225
231
  uniform float uContrast;
@@ -229,7 +235,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
229
235
  float contrastF = 1.015 * (uContrast + 1.0) / (1.0 * (1.015 - uContrast));
230
236
  color.rgb = contrastF * (color.rgb - 0.5) + 0.5;
231
237
  gl_FragColor = color;
232
- }`}isNeutralState(){return this.contrast===0}applyTo2d(t){let{imageData:{data:e}}=t;const s=Math.floor(255*this.contrast),i=259*(s+255)/(255*(259-s));for(let n=0;n<e.length;n+=4)e[n]=i*(e[n]-128)+128,e[n+1]=i*(e[n+1]-128)+128,e[n+2]=i*(e[n+2]-128)+128}sendUniformData(t,e){t.uniform1f(e.uContrast,this.contrast)}}E(Ju,"type","Contrast"),E(Ju,"defaults",{contrast:0}),E(Ju,"uniformLocations",["uContrast"]),W.setClass(Ju);const Yx={Convolute_3_1:`
238
+ }`}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)}}k(Zu,"type","Contrast"),k(Zu,"defaults",{contrast:0}),k(Zu,"uniformLocations",["uContrast"]),G.setClass(Zu);const eS={Convolute_3_1:`
233
239
  precision highp float;
234
240
  uniform sampler2D uTexture;
235
241
  uniform float uMatrix[9];
@@ -373,7 +379,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
373
379
  gl_FragColor = color;
374
380
  gl_FragColor.a = alpha;
375
381
  }
376
- `};class Qu extends he{getCacheKey(){return"".concat(this.type,"_").concat(Math.sqrt(this.matrix.length),"_").concat(this.opaque?1:0)}getFragmentSource(){return Yx[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),a=e.width,h=e.height,c=t.ctx.createImageData(a,h),u=c.data,d=this.opaque?1:0;let f,g,p,m,y,b,x,S,C,k,O,P,D;for(O=0;O<h;O++)for(k=0;k<a;k++){for(y=4*(O*a+k),f=0,g=0,p=0,m=0,D=0;D<n;D++)for(P=0;P<n;P++)x=O+D-r,b=k+P-r,x<0||x>=h||b<0||b>=a||(S=4*(x*a+b),C=i[D*n+P],f+=s[S]*C,g+=s[S+1]*C,p+=s[S+2]*C,d||(m+=s[S+3]*C));u[y]=f,u[y+1]=g,u[y+2]=p,u[y+3]=d?s[y+3]:m}t.imageData=c}sendUniformData(t,e){t.uniform1fv(e.uMatrix,this.matrix)}toObject(){return T(T({},super.toObject()),{},{opaque:this.opaque,matrix:[...this.matrix]})}}E(Qu,"type","Convolute"),E(Qu,"defaults",{opaque:!1,matrix:[0,0,0,0,1,0,0,0,0]}),E(Qu,"uniformLocations",["uMatrix","uOpaque","uHalfSize","uSize"]),W.setClass(Qu);const Ev="Gamma";class Zu extends he{getFragmentSource(){return`
382
+ `};class td extends he{getCacheKey(){return"".concat(this.type,"_").concat(Math.sqrt(this.matrix.length),"_").concat(this.opaque?1:0)}getFragmentSource(){return eS[this.getCacheKey()]}applyTo2d(t){const e=t.imageData,s=e.data,i=this.matrix,n=Math.round(Math.sqrt(i.length)),r=Math.floor(n/2),o=e.width,h=e.height,c=t.ctx.createImageData(o,h),u=c.data,d=this.opaque?1:0;let f,g,p,m,y,b,x,C,S,T,P,M,D;for(P=0;P<h;P++)for(T=0;T<o;T++){for(y=4*(P*o+T),f=0,g=0,p=0,m=0,D=0;D<n;D++)for(M=0;M<n;M++)x=P+D-r,b=T+M-r,x<0||x>=h||b<0||b>=o||(C=4*(x*o+b),S=i[D*n+M],f+=s[C]*S,g+=s[C+1]*S,p+=s[C+2]*S,d||(m+=s[C+3]*S));u[y]=f,u[y+1]=g,u[y+2]=p,u[y+3]=d?s[y+3]:m}t.imageData=c}sendUniformData(t,e){t.uniform1fv(e.uMatrix,this.matrix)}toObject(){return E(E({},super.toObject()),{},{opaque:this.opaque,matrix:[...this.matrix]})}}k(td,"type","Convolute"),k(td,"defaults",{opaque:!1,matrix:[0,0,0,0,1,0,0,0,0]}),k(td,"uniformLocations",["uMatrix","uOpaque","uHalfSize","uSize"]),G.setClass(td);const R0="Gamma";class ed extends he{getFragmentSource(){return`
377
383
  precision highp float;
378
384
  uniform sampler2D uTexture;
379
385
  uniform vec3 uGamma;
@@ -387,7 +393,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
387
393
  gl_FragColor = color;
388
394
  gl_FragColor.rgb *= color.a;
389
395
  }
390
- `}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 a=this.rgbValues;for(let h=0;h<256;h++)a.r[h]=255*Math.pow(h/255,i),a.g[h]=255*Math.pow(h/255,n),a.b[h]=255*Math.pow(h/255,r);for(let h=0;h<e.length;h+=4)e[h]=a.r[e[h]],e[h+1]=a.g[e[h+1]],e[h+2]=a.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:Ev,gamma:this.gamma.concat()}}}E(Zu,"type",Ev),E(Zu,"defaults",{gamma:[1,1,1]}),E(Zu,"uniformLocations",["uGamma"]),W.setClass(Zu);const $x={average:`
396
+ `}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:R0,gamma:this.gamma.concat()}}}k(ed,"type",R0),k(ed,"defaults",{gamma:[1,1,1]}),k(ed,"uniformLocations",["uGamma"]),G.setClass(ed);const sS={average:`
391
397
  precision highp float;
392
398
  uniform sampler2D uTexture;
393
399
  varying vec2 vTexCoord;
@@ -416,7 +422,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
416
422
  float average = 0.21 * col.r + 0.72 * col.g + 0.07 * col.b;
417
423
  gl_FragColor = vec4(average, average, average, col.a);
418
424
  }
419
- `};class td extends he{applyTo2d(t){let{imageData:{data:e}}=t;for(let s,i=0;i<e.length;i+=4){const n=e[i],r=e[i+1],a=e[i+2];switch(this.mode){case"average":s=(n+r+a)/3;break;case"lightness":s=(Math.min(n,r,a)+Math.max(n,r,a))/2;break;case"luminosity":s=.21*n+.72*r+.07*a}e[i+2]=e[i+1]=e[i]=s}}getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return $x[this.mode]}sendUniformData(t,e){t.uniform1i(e.uMode,1)}isNeutralState(){return!1}}E(td,"type","Grayscale"),E(td,"defaults",{mode:"average"}),E(td,"uniformLocations",["uMode"]),W.setClass(td);const qx=T(T({},Av),{},{rotation:0});class Tg extends Ao{calculateMatrix(){const t=this.rotation*Math.PI,e=Ks(t),s=Js(t),i=1/3,n=Math.sqrt(i)*s,r=1-e;this.matrix=[e+r/3,i*r-n,i*r+n,0,0,i*r+n,e+i*r,i*r-n,0,0,i*r-n,i*r+n,e+i*r,0,0,0,0,0,1,0]}isNeutralState(){return this.rotation===0}applyTo(t){this.calculateMatrix(),super.applyTo(t)}toObject(){return{type:this.type,rotation:this.rotation}}}E(Tg,"type","HueRotation"),E(Tg,"defaults",qx),W.setClass(Tg);class ed extends he{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`
425
+ `};class sd extends he{applyTo2d(t){let{imageData:{data:e}}=t;for(let s,i=0;i<e.length;i+=4){const n=e[i],r=e[i+1],o=e[i+2];switch(this.mode){case"average":s=(n+r+o)/3;break;case"lightness":s=(Math.min(n,r,o)+Math.max(n,r,o))/2;break;case"luminosity":s=.21*n+.72*r+.07*o}e[i+2]=e[i+1]=e[i]=s}}getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return sS[this.mode]}sendUniformData(t,e){t.uniform1i(e.uMode,1)}isNeutralState(){return!1}}k(sd,"type","Grayscale"),k(sd,"defaults",{mode:"average"}),k(sd,"uniformLocations",["uMode"]),G.setClass(sd);const iS=E(E({},O0),{},{rotation:0});class Pg extends Ta{calculateMatrix(){const t=this.rotation*Math.PI,e=qs(t),s=Ks(t),i=1/3,n=Math.sqrt(i)*s,r=1-e;this.matrix=[e+r/3,i*r-n,i*r+n,0,0,i*r+n,e+i*r,i*r-n,0,0,i*r-n,i*r+n,e+i*r,0,0,0,0,0,1,0]}isNeutralState(){return this.rotation===0}applyTo(t){this.calculateMatrix(),super.applyTo(t)}toObject(){return{type:this.type,rotation:this.rotation}}}k(Pg,"type","HueRotation"),k(Pg,"defaults",iS),G.setClass(Pg);class id extends he{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`
420
426
  precision highp float;
421
427
  uniform sampler2D uTexture;
422
428
  uniform int uInvert;
@@ -434,7 +440,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
434
440
  gl_FragColor = color;
435
441
  }
436
442
  }
437
- `}isNeutralState(){return!this.invert}sendUniformData(t,e){t.uniform1i(e.uInvert,Number(this.invert)),t.uniform1i(e.uAlpha,Number(this.alpha))}}E(ed,"type","Invert"),E(ed,"defaults",{alpha:!1,invert:!0}),E(ed,"uniformLocations",["uInvert","uAlpha"]),W.setClass(ed);class sd extends he{getFragmentSource(){return`
443
+ `}isNeutralState(){return!this.invert}sendUniformData(t,e){t.uniform1i(e.uInvert,Number(this.invert)),t.uniform1i(e.uAlpha,Number(this.alpha))}}k(id,"type","Invert"),k(id,"defaults",{alpha:!1,invert:!0}),k(id,"uniformLocations",["uInvert","uAlpha"]),G.setClass(id);class nd extends he{getFragmentSource(){return`
438
444
  precision highp float;
439
445
  uniform sampler2D uTexture;
440
446
  uniform float uStepH;
@@ -449,7 +455,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
449
455
  color.rgb += (0.5 - rand(vTexCoord, uSeed, 0.1 / uStepH)) * uNoise;
450
456
  gl_FragColor = color;
451
457
  }
452
- `}applyTo2d(t){let{imageData:{data:e}}=t;const s=this.noise;for(let i=0;i<e.length;i+=4){const n=(.5-Math.random())*s;e[i]+=n,e[i+1]+=n,e[i+2]+=n}}sendUniformData(t,e){t.uniform1f(e.uNoise,this.noise/255),t.uniform1f(e.uSeed,Math.random())}isNeutralState(){return this.noise===0}}E(sd,"type","Noise"),E(sd,"defaults",{noise:0}),E(sd,"uniformLocations",["uNoise","uSeed"]),W.setClass(sd);class id extends he{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 a=4*n*s+4*r,h=e[a],c=e[a+1],u=e[a+2],d=e[a+3];for(let f=n;f<Math.min(n+this.blocksize,i);f++)for(let g=r;g<Math.min(r+this.blocksize,s);g++){const p=4*f*s+4*g;e[p]=h,e[p+1]=c,e[p+2]=u,e[p+3]=d}}}isNeutralState(){return this.blocksize===1}getFragmentSource(){return`
458
+ `}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}}k(nd,"type","Noise"),k(nd,"defaults",{noise:0}),k(nd,"uniformLocations",["uNoise","uSeed"]),G.setClass(nd);class rd extends he{applyTo2d(t){let{imageData:{data:e,width:s,height:i}}=t;for(let n=0;n<i;n+=this.blocksize)for(let r=0;r<s;r+=this.blocksize){const o=4*n*s+4*r,h=e[o],c=e[o+1],u=e[o+2],d=e[o+3];for(let f=n;f<Math.min(n+this.blocksize,i);f++)for(let g=r;g<Math.min(r+this.blocksize,s);g++){const p=4*f*s+4*g;e[p]=h,e[p+1]=c,e[p+2]=u,e[p+3]=d}}}isNeutralState(){return this.blocksize===1}getFragmentSource(){return`
453
459
  precision highp float;
454
460
  uniform sampler2D uTexture;
455
461
  uniform float uBlocksize;
@@ -467,7 +473,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
467
473
  vec4 color = texture2D(uTexture, squareCoords);
468
474
  gl_FragColor = color;
469
475
  }
470
- `}sendUniformData(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}}E(id,"type","Pixelate"),E(id,"defaults",{blocksize:4}),E(id,"uniformLocations",["uBlocksize"]),W.setClass(id);class nd extends he{getFragmentSource(){return`
476
+ `}sendUniformData(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}}k(rd,"type","Pixelate"),k(rd,"defaults",{blocksize:4}),k(rd,"uniformLocations",["uBlocksize"]),G.setClass(rd);class od extends he{getFragmentSource(){return`
471
477
  precision highp float;
472
478
  uniform sampler2D uTexture;
473
479
  uniform vec4 uLow;
@@ -479,7 +485,7 @@ void main() {
479
485
  gl_FragColor.a = 0.0;
480
486
  }
481
487
  }
482
- `}applyTo2d(t){let{imageData:{data:e}}=t;const s=255*this.distance,i=new St(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 a=0;a<e.length;a+=4){const h=e[a],c=e[a+1],u=e[a+2];h>n[0]&&c>n[1]&&u>n[2]&&h<r[0]&&c<r[1]&&u<r[2]&&(e[a+3]=0)}}sendUniformData(t,e){const s=new St(this.color).getSource(),i=this.distance,n=[0+s[0]/255-i,0+s[1]/255-i,0+s[2]/255-i,1],r=[s[0]/255+i,s[1]/255+i,s[2]/255+i,1];t.uniform4fv(e.uLow,n),t.uniform4fv(e.uHigh,r)}}E(nd,"type","RemoveColor"),E(nd,"defaults",{color:"#FFFFFF",distance:.02,useAlpha:!1}),E(nd,"uniformLocations",["uLow","uHigh"]),W.setClass(nd);class rd extends he{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`
488
+ `}applyTo2d(t){let{imageData:{data:e}}=t;const s=255*this.distance,i=new St(this.color).getSource(),n=[i[0]-s,i[1]-s,i[2]-s],r=[i[0]+s,i[1]+s,i[2]+s];for(let o=0;o<e.length;o+=4){const h=e[o],c=e[o+1],u=e[o+2];h>n[0]&&c>n[1]&&u>n[2]&&h<r[0]&&c<r[1]&&u<r[2]&&(e[o+3]=0)}}sendUniformData(t,e){const s=new St(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)}}k(od,"type","RemoveColor"),k(od,"defaults",{color:"#FFFFFF",distance:.02,useAlpha:!1}),k(od,"uniformLocations",["uLow","uHigh"]),G.setClass(od);class ad extends he{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`
483
489
  precision highp float;
484
490
  uniform sampler2D uTexture;
485
491
  uniform vec2 uDelta;
@@ -495,7 +501,7 @@ void main() {
495
501
  `),`
496
502
  gl_FragColor = color / sum;
497
503
  }
498
- `)}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){Uu(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,a=Math.round(n*s),h=Math.round(r*i);let c;c=this.resizeType==="sliceHack"?this.sliceByTwo(t,n,r,a,h):this.resizeType==="hermite"?this.hermiteFastResize(t,n,r,a,h):this.resizeType==="bilinear"?this.bilinearFiltering(t,n,r,a,h):this.resizeType==="lanczos"?this.lanczosResize(t,n,r,a,h):new ImageData(a,h),t.imageData=c}sliceByTwo(t,e,s,i,n){const r=t.imageData,a=.5;let h=!1,c=!1,u=e*a,d=s*a;const f=t.filterBackend.resources;let g=0,p=0;const m=e;let y=0;f.sliceByTwo||(f.sliceByTwo=Rs());const b=f.sliceByTwo;(b.width<1.5*e||b.height<s)&&(b.width=1.5*e,b.height=s);const x=b.getContext("2d");for(x.clearRect(0,0,1.5*e,s),x.putImageData(r,0,0),i=Math.floor(i),n=Math.floor(n);!h||!c;)e=u,s=d,i<Math.floor(u*a)?u=Math.floor(u*a):(u=i,h=!0),n<Math.floor(d*a)?d=Math.floor(d*a):(d=n,c=!0),x.drawImage(b,g,p,e,s,m,y,u,d),g=m,p=y,y+=d;return x.getImageData(g,p,i,n)}lanczosResize(t,e,s,i,n){const r=t.imageData.data,a=t.ctx.createImageData(i,n),h=a.data,c=this.lanczosCreate(this.lanczosLobes),u=this.rcpScaleX,d=this.rcpScaleY,f=2/this.rcpScaleX,g=2/this.rcpScaleY,p=Math.ceil(u*this.lanczosLobes/2),m=Math.ceil(d*this.lanczosLobes/2),y={},b={x:0,y:0},x={x:0,y:0};return function S(C){let k,O,P,D,R,z,B,F,L,N,K;for(b.x=(C+.5)*u,x.x=Math.floor(b.x),k=0;k<n;k++){for(b.y=(k+.5)*d,x.y=Math.floor(b.y),R=0,z=0,B=0,F=0,L=0,O=x.x-p;O<=x.x+p;O++)if(!(O<0||O>=e)){N=Math.floor(1e3*Math.abs(O-b.x)),y[N]||(y[N]={});for(let I=x.y-m;I<=x.y+m;I++)I<0||I>=s||(K=Math.floor(1e3*Math.abs(I-b.y)),y[N][K]||(y[N][K]=c(Math.sqrt(Math.pow(N*f,2)+Math.pow(K*g,2))/1e3)),P=y[N][K],P>0&&(D=4*(I*e+O),R+=P,z+=P*r[D],B+=P*r[D+1],F+=P*r[D+2],L+=P*r[D+3]))}D=4*(k*i+C),h[D]=z/R,h[D+1]=B/R,h[D+2]=F/R,h[D+3]=L/R}return++C<i?S(C):a}(0)}bilinearFiltering(t,e,s,i,n){let r,a,h,c,u,d,f,g,p,m,y,b,x,S=0;const C=this.rcpScaleX,k=this.rcpScaleY,O=4*(e-1),P=t.imageData.data,D=t.ctx.createImageData(i,n),R=D.data;for(f=0;f<n;f++)for(g=0;g<i;g++)for(u=Math.floor(C*g),d=Math.floor(k*f),p=C*g-u,m=k*f-d,x=4*(d*e+u),y=0;y<4;y++)r=P[x+y],a=P[x+4+y],h=P[x+O+y],c=P[x+O+4+y],b=r*(1-p)*(1-m)+a*p*(1-m)+h*m*(1-p)+c*p*m,R[S++]=b;return D}hermiteFastResize(t,e,s,i,n){const r=this.rcpScaleX,a=this.rcpScaleY,h=Math.ceil(r/2),c=Math.ceil(a/2),u=t.imageData.data,d=t.ctx.createImageData(i,n),f=d.data;for(let g=0;g<n;g++)for(let p=0;p<i;p++){const m=4*(p+g*i);let y=0,b=0,x=0,S=0,C=0,k=0,O=0;const P=(g+.5)*a;for(let D=Math.floor(g*a);D<(g+1)*a;D++){const R=Math.abs(P-(D+.5))/c,z=(p+.5)*r,B=R*R;for(let F=Math.floor(p*r);F<(p+1)*r;F++){let L=Math.abs(z-(F+.5))/h;const N=Math.sqrt(B+L*L);N>1&&N<-1||(y=2*N*N*N-3*N*N+1,y>0&&(L=4*(F+D*e),O+=y*u[L+3],x+=y,u[L+3]<255&&(y=y*u[L+3]/250),S+=y*u[L],C+=y*u[L+1],k+=y*u[L+2],b+=y))}}f[m]=S/b,f[m+1]=C/b,f[m+2]=k/b,f[m+3]=O/x}return d}}E(rd,"type","Resize"),E(rd,"defaults",{resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3}),E(rd,"uniformLocations",["uDelta","uTaps"]),W.setClass(rd);class ad extends he{getFragmentSource(){return`
504
+ `)}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){$u(t)?this.applyToForWebgl(t):this.applyTo2d(t)}isNeutralState(){return this.scaleX===1&&this.scaleY===1}lanczosCreate(t){return e=>{if(e>=t||e<=-t)return 0;if(e<11920929e-14&&e>-11920929e-14)return 1;const s=(e*=Math.PI)/t;return Math.sin(e)/e*Math.sin(s)/s}}applyTo2d(t){const e=t.imageData,s=this.scaleX,i=this.scaleY;this.rcpScaleX=1/s,this.rcpScaleY=1/i;const n=e.width,r=e.height,o=Math.round(n*s),h=Math.round(r*i);let c;c=this.resizeType==="sliceHack"?this.sliceByTwo(t,n,r,o,h):this.resizeType==="hermite"?this.hermiteFastResize(t,n,r,o,h):this.resizeType==="bilinear"?this.bilinearFiltering(t,n,r,o,h):this.resizeType==="lanczos"?this.lanczosResize(t,n,r,o,h):new ImageData(o,h),t.imageData=c}sliceByTwo(t,e,s,i,n){const r=t.imageData,o=.5;let h=!1,c=!1,u=e*o,d=s*o;const f=t.filterBackend.resources;let g=0,p=0;const m=e;let y=0;f.sliceByTwo||(f.sliceByTwo=Si());const b=f.sliceByTwo;(b.width<1.5*e||b.height<s)&&(b.width=1.5*e,b.height=s);const x=b.getContext("2d");for(x.clearRect(0,0,1.5*e,s),x.putImageData(r,0,0),i=Math.floor(i),n=Math.floor(n);!h||!c;)e=u,s=d,i<Math.floor(u*o)?u=Math.floor(u*o):(u=i,h=!0),n<Math.floor(d*o)?d=Math.floor(d*o):(d=n,c=!0),x.drawImage(b,g,p,e,s,m,y,u,d),g=m,p=y,y+=d;return x.getImageData(g,p,i,n)}lanczosResize(t,e,s,i,n){const r=t.imageData.data,o=t.ctx.createImageData(i,n),h=o.data,c=this.lanczosCreate(this.lanczosLobes),u=this.rcpScaleX,d=this.rcpScaleY,f=2/this.rcpScaleX,g=2/this.rcpScaleY,p=Math.ceil(u*this.lanczosLobes/2),m=Math.ceil(d*this.lanczosLobes/2),y={},b={x:0,y:0},x={x:0,y:0};return function C(S){let T,P,M,D,R,V,H,F,I,j,K;for(b.x=(S+.5)*u,x.x=Math.floor(b.x),T=0;T<n;T++){for(b.y=(T+.5)*d,x.y=Math.floor(b.y),R=0,V=0,H=0,F=0,I=0,P=x.x-p;P<=x.x+p;P++)if(!(P<0||P>=e)){j=Math.floor(1e3*Math.abs(P-b.x)),y[j]||(y[j]={});for(let L=x.y-m;L<=x.y+m;L++)L<0||L>=s||(K=Math.floor(1e3*Math.abs(L-b.y)),y[j][K]||(y[j][K]=c(Math.sqrt(Math.pow(j*f,2)+Math.pow(K*g,2))/1e3)),M=y[j][K],M>0&&(D=4*(L*e+P),R+=M,V+=M*r[D],H+=M*r[D+1],F+=M*r[D+2],I+=M*r[D+3]))}D=4*(T*i+S),h[D]=V/R,h[D+1]=H/R,h[D+2]=F/R,h[D+3]=I/R}return++S<i?C(S):o}(0)}bilinearFiltering(t,e,s,i,n){let r,o,h,c,u,d,f,g,p,m,y,b,x,C=0;const S=this.rcpScaleX,T=this.rcpScaleY,P=4*(e-1),M=t.imageData.data,D=t.ctx.createImageData(i,n),R=D.data;for(f=0;f<n;f++)for(g=0;g<i;g++)for(u=Math.floor(S*g),d=Math.floor(T*f),p=S*g-u,m=T*f-d,x=4*(d*e+u),y=0;y<4;y++)r=M[x+y],o=M[x+4+y],h=M[x+P+y],c=M[x+P+4+y],b=r*(1-p)*(1-m)+o*p*(1-m)+h*m*(1-p)+c*p*m,R[C++]=b;return D}hermiteFastResize(t,e,s,i,n){const r=this.rcpScaleX,o=this.rcpScaleY,h=Math.ceil(r/2),c=Math.ceil(o/2),u=t.imageData.data,d=t.ctx.createImageData(i,n),f=d.data;for(let g=0;g<n;g++)for(let p=0;p<i;p++){const m=4*(p+g*i);let y=0,b=0,x=0,C=0,S=0,T=0,P=0;const M=(g+.5)*o;for(let D=Math.floor(g*o);D<(g+1)*o;D++){const R=Math.abs(M-(D+.5))/c,V=(p+.5)*r,H=R*R;for(let F=Math.floor(p*r);F<(p+1)*r;F++){let I=Math.abs(V-(F+.5))/h;const j=Math.sqrt(H+I*I);j>1&&j<-1||(y=2*j*j*j-3*j*j+1,y>0&&(I=4*(F+D*e),P+=y*u[I+3],x+=y,u[I+3]<255&&(y=y*u[I+3]/250),C+=y*u[I],S+=y*u[I+1],T+=y*u[I+2],b+=y))}}f[m]=C/b,f[m+1]=S/b,f[m+2]=T/b,f[m+3]=P/x}return d}}k(ad,"type","Resize"),k(ad,"defaults",{resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3}),k(ad,"uniformLocations",["uDelta","uTaps"]),G.setClass(ad);class hd extends he{getFragmentSource(){return`
499
505
  precision highp float;
500
506
  uniform sampler2D uTexture;
501
507
  uniform float uSaturation;
@@ -509,7 +515,7 @@ void main() {
509
515
  color.b += rgbMax != color.b ? (rgbMax - color.b) * uSaturation : 0.00;
510
516
  gl_FragColor = color;
511
517
  }
512
- `}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.saturation;for(let i=0;i<e.length;i+=4){const n=e[i],r=e[i+1],a=e[i+2],h=Math.max(n,r,a);e[i]+=h!==n?(h-n)*s:0,e[i+1]+=h!==r?(h-r)*s:0,e[i+2]+=h!==a?(h-a)*s:0}}sendUniformData(t,e){t.uniform1f(e.uSaturation,-this.saturation)}isNeutralState(){return this.saturation===0}}E(ad,"type","Saturation"),E(ad,"defaults",{saturation:0}),E(ad,"uniformLocations",["uSaturation"]),W.setClass(ad);class od extends he{getFragmentSource(){return`
518
+ `}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.saturation;for(let i=0;i<e.length;i+=4){const n=e[i],r=e[i+1],o=e[i+2],h=Math.max(n,r,o);e[i]+=h!==n?(h-n)*s:0,e[i+1]+=h!==r?(h-r)*s:0,e[i+2]+=h!==o?(h-o)*s:0}}sendUniformData(t,e){t.uniform1f(e.uSaturation,-this.saturation)}isNeutralState(){return this.saturation===0}}k(hd,"type","Saturation"),k(hd,"defaults",{saturation:0}),k(hd,"uniformLocations",["uSaturation"]),G.setClass(hd);class ld extends he{getFragmentSource(){return`
513
519
  precision highp float;
514
520
  uniform sampler2D uTexture;
515
521
  uniform float uVibrance;
@@ -524,15 +530,15 @@ void main() {
524
530
  color.b += max != color.b ? (max - color.b) * amt : 0.00;
525
531
  gl_FragColor = color;
526
532
  }
527
- `}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.vibrance;for(let i=0;i<e.length;i+=4){const n=e[i],r=e[i+1],a=e[i+2],h=Math.max(n,r,a),c=(n+r+a)/3,u=2*Math.abs(h-c)/255*s;e[i]+=h!==n?(h-n)*u:0,e[i+1]+=h!==r?(h-r)*u:0,e[i+2]+=h!==a?(h-a)*u:0}}sendUniformData(t,e){t.uniform1f(e.uVibrance,-this.vibrance)}isNeutralState(){return this.vibrance===0}}E(od,"type","Vibrance"),E(od,"defaults",{vibrance:0}),E(od,"uniformLocations",["uVibrance"]),W.setClass(od);let kv=null;function Kx(){const o=document.createElement("div");o.style.width="1in",document.body.append(o);const t=o.offsetWidth;return o.remove(),t}function Jx(){const o=kv??Kx();return kv=o,o/72}function Qx(o,t=500){if(typeof o!="function")throw new TypeError("The first argument is not a function.");let e=null;return function(...s){e&&clearTimeout(e),e=setTimeout(()=>{e=null,o.apply(this,s)},t)}}function Zx(o){return new Promise((t,e)=>{const s=window.URL.createObjectURL(o),i=new Image;i.src=s,i.addEventListener("load",async()=>{window.URL.revokeObjectURL(s),t(await tS(i))}),i.addEventListener("error",n=>{window.URL.revokeObjectURL(s),e(n)})})}function tS(o){return new Promise(t=>{const e=document.createElement("canvas"),s=e.getContext("2d"),{naturalWidth:i,naturalHeight:n}=o;e.width=i,e.height=n,s==null||s.drawImage(o,0,0,i,n),t(e.toDataURL("image/jpeg",.8))})}var ol={};ol.d=(o,t)=>{for(var e in t)ol.o(t,e)&&!ol.o(o,e)&&Object.defineProperty(o,e,{enumerable:!0,get:t[e]})},ol.o=(o,t)=>Object.prototype.hasOwnProperty.call(o,t);var tt=globalThis.pdfjsLib={};ol.d(tt,{AbortException:()=>qn,AnnotationEditorLayer:()=>lp,AnnotationEditorParamsType:()=>gt,AnnotationEditorType:()=>ot,AnnotationEditorUIManager:()=>$r,AnnotationLayer:()=>qC,AnnotationMode:()=>Yn,ColorPicker:()=>Td,DOMSVGFactory:()=>Zg,DrawLayer:()=>cp,FeatureTest:()=>Ue,GlobalWorkerOptions:()=>an,ImageKind:()=>hd,InvalidPDFException:()=>Mg,MissingPDFException:()=>ll,OPS:()=>ni,OutputScale:()=>Bg,PDFDataRangeTransport:()=>lb,PDFDateString:()=>jg,PDFWorker:()=>ko,PasswordResponses:()=>nS,PermissionFlag:()=>iS,PixelsPerInch:()=>Kn,RenderingCancelledException:()=>Lg,TextLayer:()=>pl,TouchManager:()=>bd,UnexpectedResponseException:()=>dd,Util:()=>q,VerbosityLevel:()=>ld,XfaLayer:()=>fb,build:()=>PC,createValidAbsoluteUrl:()=>hS,fetchData:()=>gd,getDocument:()=>_C,getFilenameFromUrl:()=>vS,getPdfFilenameFromUrl:()=>bS,getXfaPageViewport:()=>yS,isDataScheme:()=>pd,isPdfFile:()=>Ig,noContextMenu:()=>ri,normalizeUnicode:()=>gS,setLayerDimensions:()=>Yr,shadow:()=>ct,stopEvent:()=>bs,version:()=>kC});const Oe=typeof process=="object"&&process+""=="[object process]"&&!process.versions.nw&&!(process.versions.electron&&process.type&&process.type!=="browser"),Pv=[1,0,0,1,0,0],Eg=[.001,0,0,.001,0,0],eS=1e7,kg=1.35,vs={ANY:1,DISPLAY:2,PRINT:4,ANNOTATIONS_FORMS:16,ANNOTATIONS_STORAGE:32,ANNOTATIONS_DISABLE:64,IS_EDITING:128,OPLIST:256},Yn={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},sS="pdfjs_internal_editor_",ot={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15},gt={RESIZE:1,CREATE:2,FREETEXT_SIZE:11,FREETEXT_COLOR:12,FREETEXT_OPACITY:13,INK_COLOR:21,INK_THICKNESS:22,INK_OPACITY:23,HIGHLIGHT_COLOR:31,HIGHLIGHT_DEFAULT_COLOR:32,HIGHLIGHT_THICKNESS:33,HIGHLIGHT_FREE:34,HIGHLIGHT_SHOW_ALL:35,DRAW_STEP:41},iS={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},De={FILL:0,STROKE:1,FILL_STROKE:2,INVISIBLE:3,FILL_STROKE_MASK:3,ADD_TO_PATH_FLAG:4},hd={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},le={TEXT:1,LINK:2,FREETEXT:3,LINE:4,SQUARE:5,CIRCLE:6,POLYGON:7,POLYLINE:8,HIGHLIGHT:9,UNDERLINE:10,SQUIGGLY:11,STRIKEOUT:12,STAMP:13,CARET:14,INK:15,POPUP:16,FILEATTACHMENT:17,WIDGET:20},hl={SOLID:1,DASHED:2,BEVELED:3,INSET:4,UNDERLINE:5},ld={ERRORS:0,WARNINGS:1,INFOS:5},ni={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},nS={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};let cd=ld.WARNINGS;function rS(o){Number.isInteger(o)&&(cd=o)}function aS(){return cd}function ud(o){cd>=ld.INFOS&&console.log(`Info: ${o}`)}function ht(o){cd>=ld.WARNINGS&&console.log(`Warning: ${o}`)}function kt(o){throw new Error(o)}function ie(o,t){o||kt(t)}function oS(o){switch(o==null?void 0:o.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}function hS(o,t=null,e=null){if(!o)return null;try{if(e&&typeof o=="string"){if(e.addDefaultProtocol&&o.startsWith("www.")){const i=o.match(/\./g);(i==null?void 0:i.length)>=2&&(o=`http://${o}`)}if(e.tryConvertEncoding)try{o=fS(o)}catch{}}const s=t?new URL(o,t):new URL(o);if(oS(s))return s}catch{}return null}function ct(o,t,e,s=!1){return Object.defineProperty(o,t,{value:e,enumerable:!s,configurable:!0,writable:!1}),e}const $n=function(){function t(e,s){this.message=e,this.name=s}return t.prototype=new Error,t.constructor=t,t}();class Mv extends $n{constructor(t,e){super(t,"PasswordException"),this.code=e}}class Pg extends $n{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}}class Mg extends $n{constructor(t){super(t,"InvalidPDFException")}}class ll extends $n{constructor(t){super(t,"MissingPDFException")}}class dd extends $n{constructor(t,e){super(t,"UnexpectedResponseException"),this.status=e}}class lS extends $n{constructor(t){super(t,"FormatError")}}class qn extends $n{constructor(t){super(t,"AbortException")}}function Ov(o){(typeof o!="object"||(o==null?void 0:o.length)===void 0)&&kt("Invalid argument for bytesToString");const t=o.length,e=8192;if(t<e)return String.fromCharCode.apply(null,o);const s=[];for(let i=0;i<t;i+=e){const n=Math.min(i+e,t),r=o.subarray(i,n);s.push(String.fromCharCode.apply(null,r))}return s.join("")}function fd(o){typeof o!="string"&&kt("Invalid argument for stringToBytes");const t=o.length,e=new Uint8Array(t);for(let s=0;s<t;++s)e[s]=o.charCodeAt(s)&255;return e}function cS(o){return String.fromCharCode(o>>24&255,o>>16&255,o>>8&255,o&255)}function Og(o){const t=Object.create(null);for(const[e,s]of o)t[e]=s;return t}function uS(){const o=new Uint8Array(4);return o[0]=1,new Uint32Array(o.buffer,0,1)[0]===1}function dS(){try{return new Function(""),!0}catch{return!1}}class Ue{static get isLittleEndian(){return ct(this,"isLittleEndian",uS())}static get isEvalSupported(){return ct(this,"isEvalSupported",dS())}static get isOffscreenCanvasSupported(){return ct(this,"isOffscreenCanvasSupported",typeof OffscreenCanvas<"u")}static get isImageDecoderSupported(){return ct(this,"isImageDecoderSupported",typeof ImageDecoder<"u")}static get platform(){return typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.platform)=="string"?ct(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")}):ct(this,"platform",{isMac:!1,isWindows:!1,isFirefox:!1})}static get isCSSRoundSupported(){var t,e;return ct(this,"isCSSRoundSupported",(e=(t=globalThis.CSS)==null?void 0:t.supports)==null?void 0:e.call(t,"width: round(1.5px, 1px)"))}}const Dg=Array.from(Array(256).keys(),o=>o.toString(16).padStart(2,"0"));class q{static makeHexColor(t,e,s){return`#${Dg[t]}${Dg[e]}${Dg[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],a=(s+r)/2,h=Math.sqrt((s+r)**2-4*(s*r-n*i))/2,c=a+h||1,u=a-h||1;return[Math.sqrt(c),Math.sqrt(u)]}static normalizeRect(t){const e=t.slice(0);return t[0]>t[2]&&(e[0]=t[2],e[2]=t[0]),t[1]>t[3]&&(e[1]=t[3],e[3]=t[1]),e}static intersect(t,e){const s=Math.max(Math.min(t[0],t[2]),Math.min(e[0],e[2])),i=Math.min(Math.max(t[0],t[2]),Math.max(e[0],e[2]));if(s>i)return null;const n=Math.max(Math.min(t[1],t[3]),Math.min(e[1],e[3])),r=Math.min(Math.max(t[1],t[3]),Math.max(e[1],e[3]));return n>r?null:[s,n,i,r]}static bezierBoundingBox(t,e,s,i,n,r,a,h,c){return c?(c[0]=Math.min(c[0],t,a),c[1]=Math.min(c[1],e,h),c[2]=Math.max(c[2],t,a),c[3]=Math.max(c[3],e,h)):c=[Math.min(t,a),Math.min(e,h),Math.max(t,a),Math.max(e,h)],w(this,on,Cp).call(this,t,s,n,a,e,i,r,h,3*(-t+3*(s-n)+a),6*(t-2*s+n),3*(s-t),c),w(this,on,Cp).call(this,t,s,n,a,e,i,r,h,3*(-e+3*(i-r)+h),6*(e-2*i+r),3*(i-e),c),c}}on=new WeakSet,Qd=function(t,e,s,i,n,r,a,h,c,u){if(c<=0||c>=1)return;const d=1-c,f=c*c,g=f*c,p=d*(d*(d*t+3*c*e)+3*f*s)+g*i,m=d*(d*(d*n+3*c*r)+3*f*a)+g*h;u[0]=Math.min(u[0],p),u[1]=Math.min(u[1],m),u[2]=Math.max(u[2],p),u[3]=Math.max(u[3],m)},Cp=function(t,e,s,i,n,r,a,h,c,u,d,f){if(Math.abs(c)<1e-12){Math.abs(u)>=1e-12&&w(this,on,Qd).call(this,t,e,s,i,n,r,a,h,-d/u,f);return}const g=u**2-4*d*c;if(g<0)return;const p=Math.sqrt(g),m=2*c;w(this,on,Qd).call(this,t,e,s,i,n,r,a,h,(-u+p)/m,f),w(this,on,Qd).call(this,t,e,s,i,n,r,a,h,(-u-p)/m,f)},_(q,on);function fS(o){return decodeURIComponent(escape(o))}let Rg=null,Dv=null;function gS(o){return Rg||(Rg=/([\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,Dv=new Map([["ſt","ſt"]])),o.replaceAll(Rg,(t,e,s)=>e?e.normalize("NFKC"):Dv.get(s))}function pS(){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();const o=new Uint8Array(32);return crypto.getRandomValues(o),Ov(o)}const Fg="pdfjs_internal_id_";function mS(o){return Uint8Array.prototype.toBase64?o.toBase64():btoa(Ov(o))}typeof Promise.try!="function"&&(Promise.try=function(o,...t){return new Promise(e=>{e(o(...t))})});const rn="http://www.w3.org/2000/svg",Jr=class Jr{};Q(Jr,"CSS",96),Q(Jr,"PDF",72),Q(Jr,"PDF_TO_CSS_UNITS",Jr.CSS/Jr.PDF);let Kn=Jr;async function gd(o,t="text"){if(ul(o,document.baseURI)){const e=await fetch(o);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",o,!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 cl{constructor({viewBox:t,userUnit:e,scale:s,rotation:i,offsetX:n=0,offsetY:r=0,dontFlip:a=!1}){this.viewBox=t,this.userUnit=e,this.scale=s,this.rotation=i,this.offsetX=n,this.offsetY=r,s*=e;const h=(t[2]+t[0])/2,c=(t[3]+t[1])/2;let u,d,f,g;switch(i%=360,i<0&&(i+=360),i){case 180:u=-1,d=0,f=0,g=1;break;case 90:u=0,d=1,f=1,g=0;break;case 270:u=0,d=-1,f=-1,g=0;break;case 0:u=1,d=0,f=0,g=-1;break;default:throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.")}a&&(f=-f,g=-g);let p,m,y,b;u===0?(p=Math.abs(c-t[1])*s+n,m=Math.abs(h-t[0])*s+r,y=(t[3]-t[1])*s,b=(t[2]-t[0])*s):(p=Math.abs(h-t[0])*s+n,m=Math.abs(c-t[1])*s+r,y=(t[2]-t[0])*s,b=(t[3]-t[1])*s),this.transform=[u*s,d*s,f*s,g*s,p-u*s*h-f*s*c,m-d*s*h-g*s*c],this.width=y,this.height=b}get rawDims(){const{userUnit:t,viewBox:e}=this,s=e.map(i=>i*t);return ct(this,"rawDims",{pageWidth:s[2]-s[0],pageHeight:s[3]-s[1],pageX:s[0],pageY:s[1]})}clone({scale:t=this.scale,rotation:e=this.rotation,offsetX:s=this.offsetX,offsetY:i=this.offsetY,dontFlip:n=!1}={}){return new cl({viewBox:this.viewBox.slice(),userUnit:this.userUnit,scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}convertToViewportPoint(t,e){return q.applyTransform([t,e],this.transform)}convertToViewportRectangle(t){const e=q.applyTransform([t[0],t[1]],this.transform),s=q.applyTransform([t[2],t[3]],this.transform);return[e[0],e[1],s[0],s[1]]}convertToPdfPoint(t,e){return q.applyInverseTransform([t,e],this.transform)}}class Lg extends $n{constructor(t,e=0){super(t,"RenderingCancelledException"),this.extraDelay=e}}function pd(o){const t=o.length;let e=0;for(;e<t&&o[e].trim()==="";)e++;return o.substring(e,e+5).toLowerCase()==="data:"}function Ig(o){return typeof o=="string"&&/\.pdf$/i.test(o)}function vS(o){return[o]=o.split(/[#?]/,1),o.substring(o.lastIndexOf("/")+1)}function bS(o,t="document.pdf"){if(typeof o!="string")return t;if(pd(o))return ht('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.'),t;const e=/^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/,s=/[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i,i=e.exec(o);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 Rv{constructor(){Q(this,"started",Object.create(null));Q(this,"times",[])}time(t){t in this.started&&ht(`Timer is already running for ${t}`),this.started[t]=Date.now()}timeEnd(t){t in this.started||ht(`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
528
- `);return t.join("")}}function ul(o,t){try{const{protocol:e}=t?new URL(o,t):new URL(o);return e==="http:"||e==="https:"}catch{return!1}}function ri(o){o.preventDefault()}function bs(o){o.preventDefault(),o.stopPropagation()}class jg{static toDateObject(t){if(!t||typeof t!="string")return null;l(this,_l)||v(this,_l,new RegExp("^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+|-])?(\\d{2})?'?(\\d{2})?'?"));const e=l(this,_l).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 a=parseInt(e[5],10);a=a>=0&&a<=59?a:0;let h=parseInt(e[6],10);h=h>=0&&h<=59?h:0;const c=e[7]||"Z";let u=parseInt(e[8],10);u=u>=0&&u<=23?u:0;let d=parseInt(e[9],10)||0;return d=d>=0&&d<=59?d:0,c==="-"?(r+=u,a+=d):c==="+"&&(r-=u,a-=d),new Date(Date.UTC(s,i,n,r,a,h))}}_l=new WeakMap,_(jg,_l);function yS(o,{scale:t=1,rotation:e=0}){const{width:s,height:i}=o.attributes.style,n=[0,0,parseInt(s),parseInt(i)];return new cl({viewBox:n,userUnit:1,scale:t,rotation:e})}function Ng(o){if(o.startsWith("#")){const t=parseInt(o.slice(1),16);return[(t&16711680)>>16,(t&65280)>>8,t&255]}return o.startsWith("rgb(")?o.slice(4,-1).split(",").map(t=>parseInt(t)):o.startsWith("rgba(")?o.slice(5,-1).split(",").map(t=>parseInt(t)).slice(0,3):(ht(`Not a valid color format: "${o}"`),[0,0,0])}function _S(o){const t=document.createElement("span");t.style.visibility="hidden",document.body.append(t);for(const e of o.keys()){t.style.color=e;const s=window.getComputedStyle(t).color;o.set(e,Ng(s))}t.remove()}function It(o){const{a:t,b:e,c:s,d:i,e:n,f:r}=o.getTransform();return[t,e,s,i,n,r]}function Ei(o){const{a:t,b:e,c:s,d:i,e:n,f:r}=o.getTransform().invertSelf();return[t,e,s,i,n,r]}function Yr(o,t,e=!1,s=!0){if(t instanceof cl){const{pageWidth:i,pageHeight:n}=t.rawDims,{style:r}=o,a=Ue.isCSSRoundSupported,h=`var(--scale-factor) * ${i}px`,c=`var(--scale-factor) * ${n}px`,u=a?`round(down, ${h}, var(--scale-round-x, 1px))`:`calc(${h})`,d=a?`round(down, ${c}, var(--scale-round-y, 1px))`:`calc(${c})`;!e||t.rotation%180===0?(r.width=u,r.height=d):(r.width=d,r.height=u)}s&&o.setAttribute("data-main-rotation",t.rotation)}class Bg{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 hn=class hn{constructor(t){_(this,Ye);_(this,Qn,null);_(this,Qr,null);_(this,ai);_(this,Zr,null);_(this,wl,null);v(this,ai,t),l(hn,xl)||v(hn,xl,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=v(this,Qn,document.createElement("div"));t.classList.add("editToolbar","hidden"),t.setAttribute("role","toolbar");const e=l(this,ai)._uiManager._signal;t.addEventListener("contextmenu",ri,{signal:e}),t.addEventListener("pointerdown",w(hn,Pd,Wb),{signal:e});const s=v(this,Zr,document.createElement("div"));s.className="buttons",t.append(s);const i=l(this,ai).toolbarPosition;if(i){const{style:n}=t,r=l(this,ai)._uiManager.direction==="ltr"?1-i[0]:i[0];n.insetInlineEnd=`${100*r}%`,n.top=`calc(${100*i[1]}% + var(--editor-toolbar-vert-offset))`}return w(this,Ye,Ub).call(this),t}get div(){return l(this,Qn)}hide(){var t;l(this,Qn).classList.add("hidden"),(t=l(this,Qr))==null||t.hideDropdown()}show(){var t;l(this,Qn).classList.remove("hidden"),(t=l(this,wl))==null||t.shown()}async addAltText(t){const e=await t.render();w(this,Ye,Zd).call(this,e),l(this,Zr).prepend(e,l(this,Ye,Ap)),v(this,wl,t)}addColorPicker(t){v(this,Qr,t);const e=t.renderButton();w(this,Ye,Zd).call(this,e),l(this,Zr).prepend(e,l(this,Ye,Ap))}remove(){var t;l(this,Qn).remove(),(t=l(this,Qr))==null||t.destroy(),v(this,Qr,null)}};Qn=new WeakMap,Qr=new WeakMap,ai=new WeakMap,Zr=new WeakMap,wl=new WeakMap,xl=new WeakMap,Pd=new WeakSet,Wb=function(t){t.stopPropagation()},Ye=new WeakSet,Gb=function(t){l(this,ai)._focusEventsAllowed=!1,bs(t)},Xb=function(t){l(this,ai)._focusEventsAllowed=!0,bs(t)},Zd=function(t){const e=l(this,ai)._uiManager._signal;t.addEventListener("focusin",w(this,Ye,Gb).bind(this),{capture:!0,signal:e}),t.addEventListener("focusout",w(this,Ye,Xb).bind(this),{capture:!0,signal:e}),t.addEventListener("contextmenu",ri,{signal:e})},Ub=function(){const{editorType:t,_uiManager:e}=l(this,ai),s=document.createElement("button");s.className="delete",s.tabIndex=0,s.setAttribute("data-l10n-id",l(hn,xl)[t]),w(this,Ye,Zd).call(this,s),s.addEventListener("click",i=>{e.delete()},{signal:e._signal}),l(this,Zr).append(s)},Ap=function(){const t=document.createElement("div");return t.className="divider",t},_(hn,Pd),_(hn,xl,null);let Hg=hn;class wS{constructor(t){_(this,Zn);_(this,Sl,null);_(this,ta,null);_(this,ea);v(this,ea,t)}show(t,e,s){const[i,n]=w(this,Zn,$b).call(this,e,s),{style:r}=l(this,ta)||v(this,ta,w(this,Zn,Yb).call(this));t.append(l(this,ta)),r.insetInlineEnd=`${100*i}%`,r.top=`calc(${100*n}% + var(--editor-toolbar-vert-offset))`}hide(){l(this,ta).remove()}}Sl=new WeakMap,ta=new WeakMap,ea=new WeakMap,Zn=new WeakSet,Yb=function(){const t=v(this,ta,document.createElement("div"));t.className="editToolbar",t.setAttribute("role","toolbar"),t.addEventListener("contextmenu",ri,{signal:l(this,ea)._signal});const e=v(this,Sl,document.createElement("div"));return e.className="buttons",t.append(e),w(this,Zn,qb).call(this),t},$b=function(t,e){let s=0,i=0;for(const n of t){const r=n.y+n.height;if(r<s)continue;const a=n.x+(e?n.width:0);if(r>s){i=a,s=r;continue}e?a>i&&(i=a):a<i&&(i=a)}return[e?1-i:i,s]},qb=function(){const t=document.createElement("button");t.className="highlightButton",t.tabIndex=0,t.setAttribute("data-l10n-id","pdfjs-highlight-floating-button1");const e=document.createElement("span");t.append(e),e.className="visuallyHidden",e.setAttribute("data-l10n-id","pdfjs-highlight-floating-button-label");const s=l(this,ea)._signal;t.addEventListener("contextmenu",ri,{signal:s}),t.addEventListener("click",()=>{l(this,ea).highlightSelection("floating_button")},{signal:s}),l(this,Sl).append(t)};function md(o,t,e){for(const s of e)t.addEventListener(s,o[s].bind(o))}class xS{constructor(){_(this,Md,0)}get id(){return`${sS}${es(this,Md)._++}`}}Md=new WeakMap;const dp=class dp{constructor(){_(this,Mo);_(this,Po,pS());_(this,Cl,0);_(this,Fe,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 ct(this,"_isSVGFittingCanvas",n)}async getFromFile(t){const{lastModified:e,name:s,size:i,type:n}=t;return w(this,Mo,tf).call(this,`${e}_${s}_${i}_${n}`,t)}async getFromUrl(t){return w(this,Mo,tf).call(this,t,t)}async getFromBlob(t,e){const s=await e;return w(this,Mo,tf).call(this,t,s)}async getFromId(t){l(this,Fe)||v(this,Fe,new Map);const e=l(this,Fe).get(t);if(!e)return null;if(e.bitmap)return e.refCounter+=1,e;if(e.file)return this.getFromFile(e.file);if(e.blobPromise){const{blobPromise:s}=e;return delete e.blobPromise,this.getFromBlob(e.id,s)}return this.getFromUrl(e.url)}getFromCanvas(t,e){l(this,Fe)||v(this,Fe,new Map);let s=l(this,Fe).get(t);if(s!=null&&s.bitmap)return s.refCounter+=1,s;const i=new OffscreenCanvas(e.width,e.height);return i.getContext("2d").drawImage(e,0,0),s={bitmap:i.transferToImageBitmap(),id:`image_${l(this,Po)}_${es(this,Cl)._++}`,refCounter:1,isSvg:!1},l(this,Fe).set(t,s),l(this,Fe).set(s.id,s),s}getSvgUrl(t){const e=l(this,Fe).get(t);return e!=null&&e.isSvg?e.svgUrl:null}deleteId(t){var i;l(this,Fe)||v(this,Fe,new Map);const e=l(this,Fe).get(t);if(!e||(e.refCounter-=1,e.refCounter!==0))return;const{bitmap:s}=e;if(!e.url&&!e.file){const n=new OffscreenCanvas(s.width,s.height);n.getContext("bitmaprenderer").transferFromImageBitmap(s),e.blobPromise=n.convertToBlob()}(i=s.close)==null||i.call(s),e.bitmap=null}isValidId(t){return t.startsWith(`image_${l(this,Po)}_`)}};Po=new WeakMap,Cl=new WeakMap,Fe=new WeakMap,Mo=new WeakSet,tf=async function(t,e){l(this,Fe)||v(this,Fe,new Map);let s=l(this,Fe).get(t);if(s===null)return null;if(s!=null&&s.bitmap)return s.refCounter+=1,s;try{s||(s={bitmap:null,id:`image_${l(this,Po)}_${es(this,Cl)._++}`,refCounter:0,isSvg:!1});let i;if(typeof e=="string"?(s.url=e,i=await gd(e,"blob")):e instanceof File?i=s.file=e:e instanceof Blob&&(i=e),i.type==="image/svg+xml"){const n=dp._isSVGFittingCanvas,r=new FileReader,a=new Image,h=new Promise((c,u)=>{a.onload=()=>{s.bitmap=a,s.isSvg=!0,c()},r.onload=async()=>{const d=s.svgUrl=r.result;a.src=await n?`${d}#svgView(preserveAspectRatio(none))`:d},a.onerror=r.onerror=u});r.readAsDataURL(i),await h}else s.bitmap=await createImageBitmap(i);s.refCounter=1}catch(i){ht(i),s=null}return l(this,Fe).set(t,s),s&&l(this,Fe).set(s.id,s),s};let zg=dp;class SS{constructor(t=128){_(this,Jt,[]);_(this,tr,!1);_(this,Al);_(this,Wt,-1);v(this,Al,t)}add({cmd:t,undo:e,post:s,mustExec:i,type:n=NaN,overwriteIfSameType:r=!1,keepUndo:a=!1}){if(i&&t(),l(this,tr))return;const h={cmd:t,undo:e,post:s,type:n};if(l(this,Wt)===-1){l(this,Jt).length>0&&(l(this,Jt).length=0),v(this,Wt,0),l(this,Jt).push(h);return}if(r&&l(this,Jt)[l(this,Wt)].type===n){a&&(h.undo=l(this,Jt)[l(this,Wt)].undo),l(this,Jt)[l(this,Wt)]=h;return}const c=l(this,Wt)+1;c===l(this,Al)?l(this,Jt).splice(0,1):(v(this,Wt,c),c<l(this,Jt).length&&l(this,Jt).splice(c)),l(this,Jt).push(h)}undo(){if(l(this,Wt)===-1)return;v(this,tr,!0);const{undo:t,post:e}=l(this,Jt)[l(this,Wt)];t(),e==null||e(),v(this,tr,!1),v(this,Wt,l(this,Wt)-1)}redo(){if(l(this,Wt)<l(this,Jt).length-1){v(this,Wt,l(this,Wt)+1),v(this,tr,!0);const{cmd:t,post:e}=l(this,Jt)[l(this,Wt)];t(),e==null||e(),v(this,tr,!1)}}hasSomethingToUndo(){return l(this,Wt)!==-1}hasSomethingToRedo(){return l(this,Wt)<l(this,Jt).length-1}cleanType(t){if(l(this,Wt)!==-1){for(let e=l(this,Wt);e>=0;e--)if(l(this,Jt)[e].type!==t){l(this,Jt).splice(e+1,l(this,Wt)-e),v(this,Wt,e);return}l(this,Jt).length=0,v(this,Wt,-1)}}destroy(){v(this,Jt,null)}}Jt=new WeakMap,tr=new WeakMap,Al=new WeakMap,Wt=new WeakMap;class dl{constructor(t){_(this,Od);this.buffer=[],this.callbacks=new Map,this.allKeys=new Set;const{isMac:e}=Ue.platform;for(const[s,i,n={}]of t)for(const r of s){const a=r.startsWith("mac+");e&&a?(this.callbacks.set(r.slice(4),{callback:i,options:n}),this.allKeys.add(r.split("+").at(-1))):!e&&!a&&(this.callbacks.set(r,{callback:i,options:n}),this.allKeys.add(r.split("+").at(-1)))}}exec(t,e){if(!this.allKeys.has(e.key))return;const s=this.callbacks.get(w(this,Od,Kb).call(this,e));if(!s)return;const{callback:i,options:{bubbles:n=!1,args:r=[],checker:a=null}}=s;a&&!a(t,e)||(i.bind(t,...r,e)(),n||bs(e))}}Od=new WeakSet,Kb=function(t){t.altKey&&this.buffer.push("alt"),t.ctrlKey&&this.buffer.push("ctrl"),t.metaKey&&this.buffer.push("meta"),t.shiftKey&&this.buffer.push("shift"),this.buffer.push(t.key);const e=this.buffer.join("+");return this.buffer.length=0,e};const Dd=class Dd{get _colors(){const t=new Map([["CanvasText",null],["Canvas",null]]);return _S(t),ct(this,"_colors",t)}convert(t){const e=Ng(t);if(!window.matchMedia("(forced-colors: active)").matches)return e;for(const[s,i]of this._colors)if(i.every((n,r)=>n===e[r]))return Dd._colorsMapping.get(s);return e}getHexCode(t){const e=this._colors.get(t);return e?q.makeHexColor(...e):t}};Q(Dd,"_colorsMapping",new Map([["CanvasText",[0,0,0]],["Canvas",[255,255,255]]]));let Vg=Dd;const jo=class jo{constructor(t,e,s,i,n,r,a,h,c,u,d,f,g){_(this,H);_(this,Oo,new AbortController);_(this,ys,null);_(this,ce,new Map);_(this,_e,new Map);_(this,Do,null);_(this,ln,null);_(this,Ro,null);_(this,Ns,new SS);_(this,er,null);_(this,sa,null);_(this,Fo,0);_(this,ia,new Set);_(this,Pi,null);_(this,oi,null);_(this,na,new Set);Q(this,"_editorUndoBar",null);_(this,Tl,!1);_(this,El,!1);_(this,Lo,!1);_(this,kl,null);_(this,Mi,null);_(this,sr,null);_(this,Io,null);_(this,ir,!1);_(this,Oi,null);_(this,Rd,new xS);_(this,nr,!1);_(this,Pl,!1);_(this,rr,null);_(this,ra,null);_(this,Ml,null);_(this,Ol,null);_(this,ge,ot.NONE);_(this,Ct,new Set);_(this,cn,null);_(this,aa,null);_(this,Dl,null);_(this,Rl,{isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1});_(this,ar,[0,0]);_(this,Di,null);_(this,un,null);_(this,Fl,null);_(this,Bs,null);const p=this._signal=l(this,Oo).signal;v(this,un,t),v(this,Fl,e),v(this,Do,s),this._eventBus=i,i._on("editingaction",this.onEditingAction.bind(this),{signal:p}),i._on("pagechanging",this.onPageChanging.bind(this),{signal:p}),i._on("scalechanging",this.onScaleChanging.bind(this),{signal:p}),i._on("rotationchanging",this.onRotationChanging.bind(this),{signal:p}),i._on("setpreference",this.onSetPreference.bind(this),{signal:p}),i._on("switchannotationeditorparams",m=>this.updateParams(m.type,m.value),{signal:p}),w(this,H,Zb).call(this),w(this,H,iy).call(this),w(this,H,Ep).call(this),v(this,ln,n.annotationStorage),v(this,kl,n.filterFactory),v(this,aa,r),v(this,Io,a||null),v(this,Tl,h),v(this,El,c),v(this,Lo,u),v(this,Ol,d||null),this.viewParameters={realScale:Kn.PDF_TO_CSS_UNITS,rotation:0},this.isShiftKeyDown=!1,this._editorUndoBar=f||null,this._supportsPinchToZoom=g!==!1}static get _keyboardManager(){const t=jo.prototype,e=r=>l(r,un).contains(document.activeElement)&&document.activeElement.tagName!=="BUTTON"&&r.hasSomethingToControl(),s=(r,{target:a})=>{if(a instanceof HTMLInputElement){const{type:h}=a;return h!=="text"&&h!=="number"}return!0},i=this.TRANSLATE_SMALL,n=this.TRANSLATE_BIG;return ct(this,"_keyboardManager",new dl([[["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:a})=>!(a instanceof HTMLButtonElement)&&l(r,un).contains(a)&&!r.isEnterHandled}],[[" ","mac+ "],t.addNewEditorFromKeyboard,{checker:(r,{target:a})=>!(a instanceof HTMLButtonElement)&&l(r,un).contains(document.activeElement)}],[["Escape","mac+Escape"],t.unselectAll],[["ArrowLeft","mac+ArrowLeft"],t.translateSelectedEditors,{args:[-i,0],checker:e}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t.translateSelectedEditors,{args:[-n,0],checker:e}],[["ArrowRight","mac+ArrowRight"],t.translateSelectedEditors,{args:[i,0],checker:e}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t.translateSelectedEditors,{args:[n,0],checker:e}],[["ArrowUp","mac+ArrowUp"],t.translateSelectedEditors,{args:[0,-i],checker:e}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t.translateSelectedEditors,{args:[0,-n],checker:e}],[["ArrowDown","mac+ArrowDown"],t.translateSelectedEditors,{args:[0,i],checker:e}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t.translateSelectedEditors,{args:[0,n],checker:e}]]))}destroy(){var t,e,s,i,n;(t=l(this,Bs))==null||t.resolve(),v(this,Bs,null),(e=l(this,Oo))==null||e.abort(),v(this,Oo,null),this._signal=null;for(const r of l(this,_e).values())r.destroy();l(this,_e).clear(),l(this,ce).clear(),l(this,na).clear(),v(this,ys,null),l(this,Ct).clear(),l(this,Ns).destroy(),(s=l(this,Do))==null||s.destroy(),(i=l(this,Oi))==null||i.hide(),v(this,Oi,null),l(this,Mi)&&(clearTimeout(l(this,Mi)),v(this,Mi,null)),l(this,Di)&&(clearTimeout(l(this,Di)),v(this,Di,null)),(n=this._editorUndoBar)==null||n.destroy()}combinedSignal(t){return AbortSignal.any([this._signal,t.signal])}get mlManager(){return l(this,Ol)}get useNewAltTextFlow(){return l(this,El)}get useNewAltTextWhenAddingImage(){return l(this,Lo)}get hcmFilter(){return ct(this,"hcmFilter",l(this,aa)?l(this,kl).addHCMFilter(l(this,aa).foreground,l(this,aa).background):"none")}get direction(){return ct(this,"direction",getComputedStyle(l(this,un)).direction)}get highlightColors(){return ct(this,"highlightColors",l(this,Io)?new Map(l(this,Io).split(",").map(t=>t.split("=").map(e=>e.trim()))):null)}get highlightColorNames(){return ct(this,"highlightColorNames",this.highlightColors?new Map(Array.from(this.highlightColors,t=>t.reverse())):null)}setCurrentDrawingSession(t){t?(this.unselectAll(),this.disableUserSelect(!0)):this.disableUserSelect(!1),v(this,sa,t)}setMainHighlightColorPicker(t){v(this,Ml,t)}editAltText(t,e=!1){var s;(s=l(this,Do))==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":v(this,Lo,e);break}}onPageChanging({pageNumber:t}){v(this,Fo,t-1)}focusMainContainer(){l(this,un).focus()}findParent(t,e){for(const s of l(this,_e).values()){const{x:i,y:n,width:r,height:a}=s.div.getBoundingClientRect();if(t>=i&&t<=i+r&&e>=n&&e<=n+a)return s}return null}disableUserSelect(t=!1){l(this,Fl).classList.toggle("noUserSelect",t)}addShouldRescale(t){l(this,na).add(t)}removeShouldRescale(t){l(this,na).delete(t)}onScaleChanging({scale:t}){var e;this.commitOrRemove(),this.viewParameters.realScale=t*Kn.PDF_TO_CSS_UNITS;for(const s of l(this,na))s.onScaleChanging();(e=l(this,sa))==null||e.onScaleChanging()}onRotationChanging({pagesRotation:t}){this.commitOrRemove(),this.viewParameters.rotation=t}highlightSelection(t=""){const e=document.getSelection();if(!e||e.isCollapsed)return;const{anchorNode:s,anchorOffset:i,focusNode:n,focusOffset:r}=e,a=e.toString(),c=w(this,H,ef).call(this,e).closest(".textLayer"),u=this.getSelectionBoxes(c);if(!u)return;e.empty();const d=w(this,H,Tp).call(this,c),f=l(this,ge)===ot.NONE,g=()=>{d==null||d.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:t,boxes:u,anchorNode:s,anchorOffset:i,focusNode:n,focusOffset:r,text:a}),f&&this.showAllEditors("highlight",!0,!0)};if(f){this.switchToMode(ot.HIGHLIGHT,g);return}g()}addToAnnotationStorage(t){!t.isEmpty()&&l(this,ln)&&!l(this,ln).has(t.id)&&l(this,ln).setValue(t.id,t)}blur(){if(this.isShiftKeyDown=!1,l(this,ir)&&(v(this,ir,!1),w(this,H,sf).call(this,"main_toolbar")),!this.hasSelection)return;const{activeElement:t}=document;for(const e of l(this,Ct))if(e.div.contains(t)){v(this,ra,[e,t]),e._focusEventsAllowed=!1;break}}focus(){if(!l(this,ra))return;const[t,e]=l(this,ra);v(this,ra,null),e.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this._signal}),e.focus()}addEditListeners(){w(this,H,Ep).call(this),w(this,H,kp).call(this)}removeEditListeners(){w(this,H,sy).call(this),w(this,H,Pp).call(this)}dragOver(t){for(const{type:e}of t.dataTransfer.items)for(const s of l(this,oi))if(s.isHandlingMimeForPasting(e)){t.dataTransfer.dropEffect="copy",t.preventDefault();return}}drop(t){for(const e of t.dataTransfer.items)for(const s of l(this,oi))if(s.isHandlingMimeForPasting(e.type)){s.paste(e,this.currentLayer),t.preventDefault();return}}copy(t){var s;if(t.preventDefault(),(s=l(this,ys))==null||s.commitOrRemove(),!this.hasSelection)return;const e=[];for(const i of l(this,Ct)){const n=i.serialize(!0);n&&e.push(n)}e.length!==0&&t.clipboardData.setData("application/pdfjs",JSON.stringify(e))}cut(t){this.copy(t),this.delete()}async paste(t){t.preventDefault();const{clipboardData:e}=t;for(const n of e.items)for(const r of l(this,oi))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){ht(`paste: "${n.message}".`);return}if(!Array.isArray(s))return;this.unselectAll();const i=this.currentLayer;try{const n=[];for(const h of s){const c=await i.deserialize(h);if(!c)return;n.push(c)}const r=()=>{for(const h of n)w(this,H,Mp).call(this,h);w(this,H,Op).call(this,n)},a=()=>{for(const h of n)h.remove()};this.addCommands({cmd:r,undo:a,mustExec:!0})}catch(n){ht(`paste: "${n.message}".`)}}keydown(t){!this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!0),l(this,ge)!==ot.NONE&&!this.isEditorHandlingKeyboard&&jo._keyboardManager.exec(this,t)}keyup(t){this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!1,l(this,ir)&&(v(this,ir,!1),w(this,H,sf).call(this,"main_toolbar")))}onEditingAction({name:t}){switch(t){case"undo":case"redo":case"delete":case"selectAll":this[t]();break;case"highlightSelection":this.highlightSelection("context_menu");break}}setEditingState(t){t?(w(this,H,ty).call(this),w(this,H,kp).call(this),w(this,H,ss).call(this,{isEditing:l(this,ge)!==ot.NONE,isEmpty:w(this,H,Yc).call(this),hasSomethingToUndo:l(this,Ns).hasSomethingToUndo(),hasSomethingToRedo:l(this,Ns).hasSomethingToRedo(),hasSelectedEditor:!1})):(w(this,H,ey).call(this),w(this,H,Pp).call(this),w(this,H,ss).call(this,{isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(t){if(!l(this,oi)){v(this,oi,t);for(const e of l(this,oi))w(this,H,Nn).call(this,e.defaultPropertiesToUpdate)}}getId(){return l(this,Rd).id}get currentLayer(){return l(this,_e).get(l(this,Fo))}getLayer(t){return l(this,_e).get(t)}get currentPageIndex(){return l(this,Fo)}addLayer(t){l(this,_e).set(t.pageIndex,t),l(this,nr)?t.enable():t.disable()}removeLayer(t){l(this,_e).delete(t.pageIndex)}async updateMode(t,e=null,s=!1){var i;if(l(this,ge)!==t&&!(l(this,Bs)&&(await l(this,Bs).promise,!l(this,Bs)))){if(v(this,Bs,Promise.withResolvers()),v(this,ge,t),t===ot.NONE){this.setEditingState(!1),w(this,H,ry).call(this),(i=this._editorUndoBar)==null||i.hide(),l(this,Bs).resolve();return}this.setEditingState(!0),await w(this,H,ny).call(this),this.unselectAll();for(const n of l(this,_e).values())n.updateMode(t);if(!e){s&&this.addNewEditorFromKeyboard(),l(this,Bs).resolve();return}for(const n of l(this,ce).values())n.annotationElementId===e?(this.setSelected(n),n.enterInEditMode()):n.unselect();l(this,Bs).resolve()}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(t){t!==l(this,ge)&&this._eventBus.dispatch("switchannotationeditormode",{source:this,mode:t})}updateParams(t,e){var s;if(l(this,oi)){switch(t){case gt.CREATE:this.currentLayer.addNewEditor();return;case gt.HIGHLIGHT_DEFAULT_COLOR:(s=l(this,Ml))==null||s.updateColor(e);break;case gt.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:{type:"highlight",action:"toggle_visibility"}}}),(l(this,Dl)||v(this,Dl,new Map)).set(t,e),this.showAllEditors("highlight",e);break}for(const i of l(this,Ct))i.updateParams(t,e);for(const i of l(this,oi))i.updateDefaultParams(t,e)}}showAllEditors(t,e,s=!1){var n;for(const r of l(this,ce).values())r.editorType===t&&r.show(e);(((n=l(this,Dl))==null?void 0:n.get(gt.HIGHLIGHT_SHOW_ALL))??!0)!==e&&w(this,H,Nn).call(this,[[gt.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(l(this,Pl)!==t){v(this,Pl,t);for(const e of l(this,_e).values())t?e.disableClick():e.enableClick(),e.div.classList.toggle("waiting",t)}}getEditors(t){const e=[];for(const s of l(this,ce).values())s.pageIndex===t&&e.push(s);return e}getEditor(t){return l(this,ce).get(t)}addEditor(t){l(this,ce).set(t.id,t)}removeEditor(t){var e;t.div.contains(document.activeElement)&&(l(this,Mi)&&clearTimeout(l(this,Mi)),v(this,Mi,setTimeout(()=>{this.focusMainContainer(),v(this,Mi,null)},0))),l(this,ce).delete(t.id),this.unselect(t),(!t.annotationElementId||!l(this,ia).has(t.annotationElementId))&&((e=l(this,ln))==null||e.remove(t.id))}addDeletedAnnotationElement(t){l(this,ia).add(t.annotationElementId),this.addChangedExistingAnnotation(t),t.deleted=!0}isDeletedAnnotationElement(t){return l(this,ia).has(t)}removeDeletedAnnotationElement(t){l(this,ia).delete(t.annotationElementId),this.removeChangedExistingAnnotation(t),t.deleted=!1}setActiveEditor(t){l(this,ys)!==t&&(v(this,ys,t),t&&w(this,H,Nn).call(this,t.propertiesToUpdate))}updateUI(t){l(this,H,ay)===t&&w(this,H,Nn).call(this,t.propertiesToUpdate)}updateUIForDefaultProperties(t){w(this,H,Nn).call(this,t.defaultPropertiesToUpdate)}toggleSelected(t){if(l(this,Ct).has(t)){l(this,Ct).delete(t),t.unselect(),w(this,H,ss).call(this,{hasSelectedEditor:this.hasSelection});return}l(this,Ct).add(t),t.select(),w(this,H,Nn).call(this,t.propertiesToUpdate),w(this,H,ss).call(this,{hasSelectedEditor:!0})}setSelected(t){var e;(e=l(this,sa))==null||e.commitOrRemove();for(const s of l(this,Ct))s!==t&&s.unselect();l(this,Ct).clear(),l(this,Ct).add(t),t.select(),w(this,H,Nn).call(this,t.propertiesToUpdate),w(this,H,ss).call(this,{hasSelectedEditor:!0})}isSelected(t){return l(this,Ct).has(t)}get firstSelectedEditor(){return l(this,Ct).values().next().value}unselect(t){t.unselect(),l(this,Ct).delete(t),w(this,H,ss).call(this,{hasSelectedEditor:this.hasSelection})}get hasSelection(){return l(this,Ct).size!==0}get isEnterHandled(){return l(this,Ct).size===1&&this.firstSelectedEditor.isEnterHandled}undo(){var t;l(this,Ns).undo(),w(this,H,ss).call(this,{hasSomethingToUndo:l(this,Ns).hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:w(this,H,Yc).call(this)}),(t=this._editorUndoBar)==null||t.hide()}redo(){l(this,Ns).redo(),w(this,H,ss).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:l(this,Ns).hasSomethingToRedo(),isEmpty:w(this,H,Yc).call(this)})}addCommands(t){l(this,Ns).add(t),w(this,H,ss).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:w(this,H,Yc).call(this)})}cleanUndoStack(t){l(this,Ns).cleanType(t)}delete(){var n;this.commitOrRemove();const t=(n=this.currentLayer)==null?void 0:n.endDrawingSession(!0);if(!this.hasSelection&&!t)return;const e=t?[t]:[...l(this,Ct)],s=()=>{var r;(r=this._editorUndoBar)==null||r.show(i,e.length===1?e[0].editorType:e.length);for(const a of e)a.remove()},i=()=>{for(const r of e)w(this,H,Mp).call(this,r)};this.addCommands({cmd:s,undo:i,mustExec:!0})}commitOrRemove(){var t;(t=l(this,ys))==null||t.commitOrRemove()}hasSomethingToControl(){return l(this,ys)||this.hasSelection}selectAll(){for(const t of l(this,Ct))t.commit();w(this,H,Op).call(this,l(this,ce).values())}unselectAll(){var t;if(!(l(this,ys)&&(l(this,ys).commitOrRemove(),l(this,ge)!==ot.NONE))&&!((t=l(this,sa))!=null&&t.commitOrRemove())&&this.hasSelection){for(const e of l(this,Ct))e.unselect();l(this,Ct).clear(),w(this,H,ss).call(this,{hasSelectedEditor:!1})}}translateSelectedEditors(t,e,s=!1){if(s||this.commitOrRemove(),!this.hasSelection)return;l(this,ar)[0]+=t,l(this,ar)[1]+=e;const[i,n]=l(this,ar),r=[...l(this,Ct)],a=1e3;l(this,Di)&&clearTimeout(l(this,Di)),v(this,Di,setTimeout(()=>{v(this,Di,null),l(this,ar)[0]=l(this,ar)[1]=0,this.addCommands({cmd:()=>{for(const h of r)l(this,ce).has(h.id)&&h.translateInPage(i,n)},undo:()=>{for(const h of r)l(this,ce).has(h.id)&&h.translateInPage(-i,-n)},mustExec:!1})},a));for(const h of r)h.translateInPage(t,e)}setUpDragSession(){if(this.hasSelection){this.disableUserSelect(!0),v(this,Pi,new Map);for(const t of l(this,Ct))l(this,Pi).set(t,{savedX:t.x,savedY:t.y,savedPageIndex:t.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!l(this,Pi))return!1;this.disableUserSelect(!1);const t=l(this,Pi);v(this,Pi,null);let e=!1;for(const[{x:i,y:n,pageIndex:r},a]of t)a.newX=i,a.newY=n,a.newPageIndex=r,e||(e=i!==a.savedX||n!==a.savedY||r!==a.savedPageIndex);if(!e)return!1;const s=(i,n,r,a)=>{if(l(this,ce).has(i.id)){const h=l(this,_e).get(a);h?i._setParentAndPosition(h,n,r):(i.pageIndex=a,i.x=n,i.y=r)}};return this.addCommands({cmd:()=>{for(const[i,{newX:n,newY:r,newPageIndex:a}]of t)s(i,n,r,a)},undo:()=>{for(const[i,{savedX:n,savedY:r,savedPageIndex:a}]of t)s(i,n,r,a)},mustExec:!0}),!0}dragSelectedEditors(t,e){if(l(this,Pi))for(const s of l(this,Pi).keys())s.drag(t,e)}rebuild(t){if(t.parent===null){const e=this.getLayer(t.pageIndex);e?(e.changeParent(t),e.addOrRebuild(t)):(this.addEditor(t),this.addToAnnotationStorage(t),t.rebuild())}else t.parent.addOrRebuild(t)}get isEditorHandlingKeyboard(){var t;return((t=this.getActive())==null?void 0:t.shouldGetKeyboardEvents())||l(this,Ct).size===1&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(t){return l(this,ys)===t}getActive(){return l(this,ys)}getMode(){return l(this,ge)}get imageManager(){return ct(this,"imageManager",new zg)}getSelectionBoxes(t){if(!t)return null;const e=document.getSelection();for(let c=0,u=e.rangeCount;c<u;c++)if(!t.contains(e.getRangeAt(c).commonAncestorContainer))return null;const{x:s,y:i,width:n,height:r}=t.getBoundingClientRect();let a;switch(t.getAttribute("data-main-rotation")){case"90":a=(c,u,d,f)=>({x:(u-i)/r,y:1-(c+d-s)/n,width:f/r,height:d/n});break;case"180":a=(c,u,d,f)=>({x:1-(c+d-s)/n,y:1-(u+f-i)/r,width:d/n,height:f/r});break;case"270":a=(c,u,d,f)=>({x:1-(u+f-i)/r,y:(c-s)/n,width:f/r,height:d/n});break;default:a=(c,u,d,f)=>({x:(c-s)/n,y:(u-i)/r,width:d/n,height:f/r});break}const h=[];for(let c=0,u=e.rangeCount;c<u;c++){const d=e.getRangeAt(c);if(!d.collapsed)for(const{x:f,y:g,width:p,height:m}of d.getClientRects())p===0||m===0||h.push(a(f,g,p,m))}return h.length===0?null:h}addChangedExistingAnnotation({annotationElementId:t,id:e}){(l(this,Ro)||v(this,Ro,new Map)).set(t,e)}removeChangedExistingAnnotation({annotationElementId:t}){var e;(e=l(this,Ro))==null||e.delete(t)}renderAnnotationElement(t){var i;const e=(i=l(this,Ro))==null?void 0:i.get(t.data.id);if(!e)return;const s=l(this,ln).getRawValue(e);s&&(l(this,ge)===ot.NONE&&!s.hasBeenModified||s.renderAnnotationElement(t))}};Oo=new WeakMap,ys=new WeakMap,ce=new WeakMap,_e=new WeakMap,Do=new WeakMap,ln=new WeakMap,Ro=new WeakMap,Ns=new WeakMap,er=new WeakMap,sa=new WeakMap,Fo=new WeakMap,ia=new WeakMap,Pi=new WeakMap,oi=new WeakMap,na=new WeakMap,Tl=new WeakMap,El=new WeakMap,Lo=new WeakMap,kl=new WeakMap,Mi=new WeakMap,sr=new WeakMap,Io=new WeakMap,ir=new WeakMap,Oi=new WeakMap,Rd=new WeakMap,nr=new WeakMap,Pl=new WeakMap,rr=new WeakMap,ra=new WeakMap,Ml=new WeakMap,Ol=new WeakMap,ge=new WeakMap,Ct=new WeakMap,cn=new WeakMap,aa=new WeakMap,Dl=new WeakMap,Rl=new WeakMap,ar=new WeakMap,Di=new WeakMap,un=new WeakMap,Fl=new WeakMap,Bs=new WeakMap,H=new WeakSet,ef=function({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t},Tp=function(t){const{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(const s of l(this,_e).values())if(s.hasTextLayer(t))return s;return null},Jb=function(){const t=document.getSelection();if(!t||t.isCollapsed)return;const s=w(this,H,ef).call(this,t).closest(".textLayer"),i=this.getSelectionBoxes(s);i&&(l(this,Oi)||v(this,Oi,new wS(this)),l(this,Oi).show(s,i,this.direction==="ltr"))},Qb=function(){var n,r,a;const t=document.getSelection();if(!t||t.isCollapsed){l(this,cn)&&((n=l(this,Oi))==null||n.hide(),v(this,cn,null),w(this,H,ss).call(this,{hasSelectedText:!1}));return}const{anchorNode:e}=t;if(e===l(this,cn))return;const i=w(this,H,ef).call(this,t).closest(".textLayer");if(!i){l(this,cn)&&((r=l(this,Oi))==null||r.hide(),v(this,cn,null),w(this,H,ss).call(this,{hasSelectedText:!1}));return}if((a=l(this,Oi))==null||a.hide(),v(this,cn,e),w(this,H,ss).call(this,{hasSelectedText:!0}),!(l(this,ge)!==ot.HIGHLIGHT&&l(this,ge)!==ot.NONE)&&(l(this,ge)===ot.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0),v(this,ir,this.isShiftKeyDown),!this.isShiftKeyDown)){const h=l(this,ge)===ot.HIGHLIGHT?w(this,H,Tp).call(this,i):null;h==null||h.toggleDrawing();const c=new AbortController,u=this.combinedSignal(c),d=f=>{f.type==="pointerup"&&f.button!==0||(c.abort(),h==null||h.toggleDrawing(!0),f.type==="pointerup"&&w(this,H,sf).call(this,"main_toolbar"))};window.addEventListener("pointerup",d,{signal:u}),window.addEventListener("blur",d,{signal:u})}},sf=function(t=""){l(this,ge)===ot.HIGHLIGHT?this.highlightSelection(t):l(this,Tl)&&w(this,H,Jb).call(this)},Zb=function(){document.addEventListener("selectionchange",w(this,H,Qb).bind(this),{signal:this._signal})},ty=function(){if(l(this,sr))return;v(this,sr,new AbortController);const t=this.combinedSignal(l(this,sr));window.addEventListener("focus",this.focus.bind(this),{signal:t}),window.addEventListener("blur",this.blur.bind(this),{signal:t})},ey=function(){var t;(t=l(this,sr))==null||t.abort(),v(this,sr,null)},Ep=function(){if(l(this,rr))return;v(this,rr,new AbortController);const t=this.combinedSignal(l(this,rr));window.addEventListener("keydown",this.keydown.bind(this),{signal:t}),window.addEventListener("keyup",this.keyup.bind(this),{signal:t})},sy=function(){var t;(t=l(this,rr))==null||t.abort(),v(this,rr,null)},kp=function(){if(l(this,er))return;v(this,er,new AbortController);const t=this.combinedSignal(l(this,er));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})},Pp=function(){var t;(t=l(this,er))==null||t.abort(),v(this,er,null)},iy=function(){const t=this._signal;document.addEventListener("dragover",this.dragOver.bind(this),{signal:t}),document.addEventListener("drop",this.drop.bind(this),{signal:t})},ss=function(t){Object.entries(t).some(([s,i])=>l(this,Rl)[s]!==i)&&(this._eventBus.dispatch("annotationeditorstateschanged",{source:this,details:Object.assign(l(this,Rl),t)}),l(this,ge)===ot.HIGHLIGHT&&t.hasSelectedEditor===!1&&w(this,H,Nn).call(this,[[gt.HIGHLIGHT_FREE,!0]]))},Nn=function(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})},ny=async function(){if(!l(this,nr)){v(this,nr,!0);const t=[];for(const e of l(this,_e).values())t.push(e.enable());await Promise.all(t);for(const e of l(this,ce).values())e.enable()}},ry=function(){if(this.unselectAll(),l(this,nr)){v(this,nr,!1);for(const t of l(this,_e).values())t.disable();for(const t of l(this,ce).values())t.disable()}},Mp=function(t){const e=l(this,_e).get(t.pageIndex);e?e.addOrRebuild(t):(this.addEditor(t),this.addToAnnotationStorage(t))},ay=function(){let t=null;for(t of l(this,Ct));return t},Yc=function(){if(l(this,ce).size===0)return!0;if(l(this,ce).size===1)for(const t of l(this,ce).values())return t.isEmpty();return!1},Op=function(t){for(const e of l(this,Ct))e.unselect();l(this,Ct).clear();for(const e of t)e.isEmpty()||(l(this,Ct).add(e),e.select());w(this,H,ss).call(this,{hasSelectedEditor:this.hasSelection})},Q(jo,"TRANSLATE_SMALL",1),Q(jo,"TRANSLATE_BIG",10);let $r=jo;const $e=class $e{constructor(t){_(this,li);_(this,pe,null);_(this,Ri,!1);_(this,hi,null);_(this,No,null);_(this,Fi,null);_(this,_s,null);_(this,Bo,!1);_(this,Li,null);_(this,ls,null);_(this,dn,null);_(this,oa,null);_(this,Ii,!1);v(this,ls,t),v(this,Ii,t._uiManager.useNewAltTextFlow),l($e,or)||v($e,or,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){$e._l10n??($e._l10n=t)}async render(){const t=v(this,hi,document.createElement("button"));t.className="altText",t.tabIndex="0";const e=v(this,No,document.createElement("span"));t.append(e),l(this,Ii)?(t.classList.add("new"),t.setAttribute("data-l10n-id",l($e,or).missing),e.setAttribute("data-l10n-id",l($e,or)["missing-label"])):(t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button"),e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button-label"));const s=l(this,ls)._uiManager._signal;t.addEventListener("contextmenu",ri,{signal:s}),t.addEventListener("pointerdown",n=>n.stopPropagation(),{signal:s});const i=n=>{n.preventDefault(),l(this,ls)._uiManager.editAltText(l(this,ls)),l(this,Ii)&&l(this,ls)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_clicked",data:{label:l(this,li,$c)}})};return t.addEventListener("click",i,{capture:!0,signal:s}),t.addEventListener("keydown",n=>{n.target===t&&n.key==="Enter"&&(v(this,Bo,!0),i(n))},{signal:s}),await w(this,li,nf).call(this),t}finish(){l(this,hi)&&(l(this,hi).focus({focusVisible:l(this,Bo)}),v(this,Bo,!1))}isEmpty(){return l(this,Ii)?l(this,pe)===null:!l(this,pe)&&!l(this,Ri)}hasData(){return l(this,Ii)?l(this,pe)!==null||!!l(this,dn):this.isEmpty()}get guessedText(){return l(this,dn)}async setGuessedText(t){l(this,pe)===null&&(v(this,dn,t),v(this,oa,await $e._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",{generatedAltText:t})),w(this,li,nf).call(this))}toggleAltTextBadge(t=!1){var e;if(!l(this,Ii)||l(this,pe)){(e=l(this,Li))==null||e.remove(),v(this,Li,null);return}if(!l(this,Li)){const s=v(this,Li,document.createElement("div"));s.className="noAltTextBadge",l(this,ls).div.append(s)}l(this,Li).classList.toggle("hidden",!t)}serialize(t){let e=l(this,pe);return!t&&l(this,dn)===e&&(e=l(this,oa)),{altText:e,decorative:l(this,Ri),guessedText:l(this,dn),textWithDisclaimer:l(this,oa)}}get data(){return{altText:l(this,pe),decorative:l(this,Ri)}}set data({altText:t,decorative:e,guessedText:s,textWithDisclaimer:i,cancel:n=!1}){s&&(v(this,dn,s),v(this,oa,i)),!(l(this,pe)===t&&l(this,Ri)===e)&&(n||(v(this,pe,t),v(this,Ri,e)),w(this,li,nf).call(this))}toggle(t=!1){l(this,hi)&&(!t&&l(this,_s)&&(clearTimeout(l(this,_s)),v(this,_s,null)),l(this,hi).disabled=!t)}shown(){l(this,ls)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_displayed",data:{label:l(this,li,$c)}})}destroy(){var t,e;(t=l(this,hi))==null||t.remove(),v(this,hi,null),v(this,No,null),v(this,Fi,null),(e=l(this,Li))==null||e.remove(),v(this,Li,null)}};pe=new WeakMap,Ri=new WeakMap,hi=new WeakMap,No=new WeakMap,Fi=new WeakMap,_s=new WeakMap,Bo=new WeakMap,Li=new WeakMap,ls=new WeakMap,dn=new WeakMap,oa=new WeakMap,Ii=new WeakMap,or=new WeakMap,li=new WeakSet,$c=function(){return l(this,pe)&&"added"||l(this,pe)===null&&this.guessedText&&"review"||"missing"},nf=async function(){var i,n,r;const t=l(this,hi);if(!t)return;if(l(this,Ii)){if(t.classList.toggle("done",!!l(this,pe)),t.setAttribute("data-l10n-id",l($e,or)[l(this,li,$c)]),(i=l(this,No))==null||i.setAttribute("data-l10n-id",l($e,or)[`${l(this,li,$c)}-label`]),!l(this,pe)){(n=l(this,Fi))==null||n.remove();return}}else{if(!l(this,pe)&&!l(this,Ri)){t.classList.remove("done"),(r=l(this,Fi))==null||r.remove();return}t.classList.add("done"),t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-edit-button")}let e=l(this,Fi);if(!e){v(this,Fi,e=document.createElement("span")),e.className="tooltip",e.setAttribute("role","tooltip"),e.id=`alt-text-tooltip-${l(this,ls).id}`;const a=100,h=l(this,ls)._uiManager._signal;h.addEventListener("abort",()=>{clearTimeout(l(this,_s)),v(this,_s,null)},{once:!0}),t.addEventListener("mouseenter",()=>{v(this,_s,setTimeout(()=>{v(this,_s,null),l(this,Fi).classList.add("show"),l(this,ls)._reportTelemetry({action:"alt_text_tooltip"})},a))},{signal:h}),t.addEventListener("mouseleave",()=>{var c;l(this,_s)&&(clearTimeout(l(this,_s)),v(this,_s,null)),(c=l(this,Fi))==null||c.classList.remove("show")},{signal:h})}l(this,Ri)?e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-decorative-tooltip"):(e.removeAttribute("data-l10n-id"),e.textContent=l(this,pe)),e.parentNode||t.append(e);const s=l(this,ls).getImageForAltText();s==null||s.setAttribute("aria-describedby",e.id)},_($e,or,null),Q($e,"_l10n",null);let vd=$e;const fp=class fp{constructor({container:t,isPinchingDisabled:e=null,isPinchingStopped:s=null,onPinchStart:i=null,onPinching:n=null,onPinchEnd:r=null,signal:a}){_(this,gn);_(this,Ll);_(this,ha,!1);_(this,Il,null);_(this,jl);_(this,Nl);_(this,Bl);_(this,Hl);_(this,Ho);_(this,fn,null);_(this,la);_(this,hr,null);v(this,Ll,t),v(this,Il,s),v(this,jl,e),v(this,Nl,i),v(this,Bl,n),v(this,Hl,r),v(this,la,new AbortController),v(this,Ho,AbortSignal.any([a,l(this,la).signal])),t.addEventListener("touchstart",w(this,gn,oy).bind(this),{passive:!1,signal:l(this,Ho)})}get MIN_TOUCH_DISTANCE_TO_PINCH(){return ct(this,"MIN_TOUCH_DISTANCE_TO_PINCH",35/(window.devicePixelRatio||1))}destroy(){var t;(t=l(this,la))==null||t.abort(),v(this,la,null)}};Ll=new WeakMap,ha=new WeakMap,Il=new WeakMap,jl=new WeakMap,Nl=new WeakMap,Bl=new WeakMap,Hl=new WeakMap,Ho=new WeakMap,fn=new WeakMap,la=new WeakMap,hr=new WeakMap,gn=new WeakSet,oy=function(t){var i,n,r;if((i=l(this,jl))!=null&&i.call(this)||t.touches.length<2)return;if(!l(this,hr)){v(this,hr,new AbortController);const a=AbortSignal.any([l(this,Ho),l(this,hr).signal]),h=l(this,Ll),c={signal:a,passive:!1};h.addEventListener("touchmove",w(this,gn,hy).bind(this),c),h.addEventListener("touchend",w(this,gn,Dp).bind(this),c),h.addEventListener("touchcancel",w(this,gn,Dp).bind(this),c),(n=l(this,Nl))==null||n.call(this)}if(bs(t),t.touches.length!==2||(r=l(this,Il))!=null&&r.call(this)){v(this,fn,null);return}let[e,s]=t.touches;e.identifier>s.identifier&&([e,s]=[s,e]),v(this,fn,{touch0X:e.screenX,touch0Y:e.screenY,touch1X:s.screenX,touch1Y:s.screenY})},hy=function(t){var C;if(!l(this,fn)||t.touches.length!==2)return;let[e,s]=t.touches;e.identifier>s.identifier&&([e,s]=[s,e]);const{screenX:i,screenY:n}=e,{screenX:r,screenY:a}=s,h=l(this,fn),{touch0X:c,touch0Y:u,touch1X:d,touch1Y:f}=h,g=d-c,p=f-u,m=r-i,y=a-n,b=Math.hypot(m,y)||1,x=Math.hypot(g,p)||1;if(!l(this,ha)&&Math.abs(x-b)<=fp.MIN_TOUCH_DISTANCE_TO_PINCH)return;if(h.touch0X=i,h.touch0Y=n,h.touch1X=r,h.touch1Y=a,t.preventDefault(),!l(this,ha)){v(this,ha,!0);return}const S=[(i+r)/2,(n+a)/2];(C=l(this,Bl))==null||C.call(this,S,x,b)},Dp=function(t){var e;l(this,hr).abort(),v(this,hr,null),(e=l(this,Hl))==null||e.call(this),l(this,fn)&&(t.preventDefault(),v(this,fn,null),v(this,ha,!1))};let bd=fp;const lt=class lt{constructor(t){_(this,J);_(this,ca,null);_(this,ci,null);_(this,Rt,null);_(this,zo,!1);_(this,lr,null);_(this,zl,"");_(this,ua,!1);_(this,we,null);_(this,da,null);_(this,pn,null);_(this,cr,null);_(this,Vl,"");_(this,fa,!1);_(this,ws,null);_(this,Wl,!1);_(this,ga,!1);_(this,mn,!1);_(this,ji,null);_(this,Vo,0);_(this,Wo,0);_(this,Hs,null);_(this,pa,null);Q(this,"_editToolbar",null);Q(this,"_initialOptions",Object.create(null));Q(this,"_initialData",null);Q(this,"_isVisible",!0);Q(this,"_uiManager",null);Q(this,"_focusEventsAllowed",!0);_(this,Gl,!1);_(this,Fd,lt._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[a,h]=this.parentDimensions;this.x=t.x/a,this.y=t.y/h,this.isAttachedToDOM=!1,this.deleted=!1}static get _resizerKeyboardManager(){const t=lt.prototype._resizeWithKeyboard,e=$r.TRANSLATE_SMALL,s=$r.TRANSLATE_BIG;return ct(this,"_resizerKeyboardManager",new dl([[["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"],lt.prototype._stopResizingWithKeyboard]]))}get editorType(){return Object.getPrototypeOf(this).constructor._type}static get isDrawer(){return!1}static get _defaultLineColor(){return ct(this,"_defaultLineColor",this._colorManager.getHexCode("CanvasText"))}static deleteAnnotationElement(t){const e=new CS({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(lt._l10n??(lt._l10n=t),lt._l10nResizer||(lt._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"})),lt._borderLineWidth!==-1)return;const s=getComputedStyle(document.documentElement);lt._borderLineWidth=parseFloat(s.getPropertyValue("--outline-width"))||0}static updateDefaultParams(t,e){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(t){return!1}static paste(t,e){kt("Not implemented")}get propertiesToUpdate(){return[]}get _isDraggable(){return l(this,Gl)}set _isDraggable(t){var e;v(this,Gl,t),(e=this.div)==null||e.classList.toggle("draggable",t)}get isEnterHandled(){return!0}center(){const[t,e]=this.pageDimensions;switch(this.parentRotation){case 90:this.x-=this.height*e/(t*2),this.y+=this.width*t/(e*2);break;case 180:this.x+=this.width/2,this.y+=this.height/2;break;case 270:this.x+=this.height*e/(t*2),this.y-=this.width*t/(e*2);break;default:this.x-=this.width/2,this.y-=this.height/2;break}this.fixAndSetPosition()}addCommands(t){this._uiManager.addCommands(t)}get currentLayer(){return this._uiManager.currentLayer}setInBackground(){this.div.style.zIndex=0}setInForeground(){this.div.style.zIndex=l(this,Fd)}setParent(t){t!==null?(this.pageIndex=t.pageIndex,this.pageDimensions=t.pageDimensions):w(this,J,qc).call(this),this.parent=t}focusin(t){this._focusEventsAllowed&&(l(this,fa)?v(this,fa,!1):this.parent.setSelected(this))}focusout(t){var s;if(!this._focusEventsAllowed||!this.isAttachedToDOM)return;const e=t.relatedTarget;e!=null&&e.closest(`#${this.id}`)||(t.preventDefault(),(s=this.parent)!=null&&s.isMultipleSelection||this.commitOrRemove())}commitOrRemove(){this.isEmpty()?this.remove():this.commit()}commit(){this.addToAnnotationStorage()}addToAnnotationStorage(){this._uiManager.addToAnnotationStorage(this)}setAt(t,e,s,i){const[n,r]=this.parentDimensions;[s,i]=this.screenToPageTranslation(s,i),this.x=(t+s)/n,this.y=(e+i)/r,this.fixAndSetPosition()}translate(t,e){w(this,J,Rp).call(this,this.parentDimensions,t,e)}translateInPage(t,e){l(this,ws)||v(this,ws,[this.x,this.y,this.width,this.height]),w(this,J,Rp).call(this,this.pageDimensions,t,e),this.div.scrollIntoView({block:"nearest"})}drag(t,e){l(this,ws)||v(this,ws,[this.x,this.y,this.width,this.height]);const{div:s,parentDimensions:[i,n]}=this;if(this.x+=t/i,this.y+=e/n,this.parent&&(this.x<0||this.x>1||this.y<0||this.y>1)){const{x:d,y:f}=this.div.getBoundingClientRect();this.parent.findNewParent(this,d,f)&&(this.x-=Math.floor(this.x),this.y-=Math.floor(this.y))}let{x:r,y:a}=this;const[h,c]=this.getBaseTranslation();r+=h,a+=c;const{style:u}=s;u.left=`${(100*r).toFixed(2)}%`,u.top=`${(100*a).toFixed(2)}%`,this._onTranslating(r,a),s.scrollIntoView({block:"nearest"})}_onTranslating(t,e){}_onTranslated(t,e){}get _hasBeenMoved(){return!!l(this,ws)&&(l(this,ws)[0]!==this.x||l(this,ws)[1]!==this.y)}get _hasBeenResized(){return!!l(this,ws)&&(l(this,ws)[2]!==this.width||l(this,ws)[3]!==this.height)}getBaseTranslation(){const[t,e]=this.parentDimensions,{_borderLineWidth:s}=lt,i=s/t,n=s/e;switch(this.rotation){case 90:return[-i,n];case 180:return[i,n];case 270:return[i,-n];default:return[-i,-n]}}get _mustFixPosition(){return!0}fixAndSetPosition(t=this.rotation){const{div:{style:e},pageDimensions:[s,i]}=this;let{x:n,y:r,width:a,height:h}=this;if(a*=s,h*=i,n*=s,r*=i,this._mustFixPosition)switch(t){case 0:n=Math.max(0,Math.min(s-a,n)),r=Math.max(0,Math.min(i-h,r));break;case 90:n=Math.max(0,Math.min(s-h,n)),r=Math.min(i,Math.max(a,r));break;case 180:n=Math.min(s,Math.max(a,n)),r=Math.min(i,Math.max(h,r));break;case 270:n=Math.min(s,Math.max(h,n)),r=Math.max(0,Math.min(i-a,r));break}this.x=n/=s,this.y=r/=i;const[c,u]=this.getBaseTranslation();n+=c,r+=u,e.left=`${(100*n).toFixed(2)}%`,e.top=`${(100*r).toFixed(2)}%`,this.moveInDOM()}screenToPageTranslation(t,e){var s;return w(s=lt,Xl,Fp).call(s,t,e,this.parentRotation)}pageTranslationToScreen(t,e){var s;return w(s=lt,Xl,Fp).call(s,t,e,360-this.parentRotation)}get parentScale(){return this._uiManager.viewParameters.realScale}get parentRotation(){return(this._uiManager.viewParameters.rotation+this.pageRotation)%360}get parentDimensions(){const{parentScale:t,pageDimensions:[e,s]}=this;return[e*t,s*t]}setDims(t,e){const[s,i]=this.parentDimensions,{style:n}=this.div;n.width=`${(100*t/s).toFixed(2)}%`,l(this,ua)||(n.height=`${(100*e/i).toFixed(2)}%`)}fixDims(){const{style:t}=this.div,{height:e,width:s}=t,i=s.endsWith("%"),n=!l(this,ua)&&e.endsWith("%");if(i&&n)return;const[r,a]=this.parentDimensions;i||(t.width=`${(100*parseFloat(s)/r).toFixed(2)}%`),!l(this,ua)&&!n&&(t.height=`${(100*parseFloat(e)/a).toFixed(2)}%`)}getInitialTranslation(){return[0,0]}_onResized(){}static _round(t){return Math.round(t*1e4)/1e4}_onResizing(){}altTextFinish(){var t;(t=l(this,Rt))==null||t.finish()}async addEditToolbar(){return this._editToolbar||l(this,ga)?this._editToolbar:(this._editToolbar=new Hg(this),this.div.append(this._editToolbar.render()),l(this,Rt)&&await this._editToolbar.addAltText(l(this,Rt)),this._editToolbar)}removeEditToolbar(){var t;this._editToolbar&&(this._editToolbar.remove(),this._editToolbar=null,(t=l(this,Rt))==null||t.destroy())}addContainer(t){var s;const e=(s=this._editToolbar)==null?void 0:s.div;e?e.before(t):this.div.append(t)}getClientDimensions(){return this.div.getBoundingClientRect()}async addAltTextButton(){l(this,Rt)||(vd.initialize(lt._l10n),v(this,Rt,new vd(this)),l(this,ca)&&(l(this,Rt).data=l(this,ca),v(this,ca,null)),await this.addEditToolbar())}get altTextData(){var t;return(t=l(this,Rt))==null?void 0:t.data}set altTextData(t){l(this,Rt)&&(l(this,Rt).data=t)}get guessedAltText(){var t;return(t=l(this,Rt))==null?void 0:t.guessedText}async setGuessedAltText(t){var e;await((e=l(this,Rt))==null?void 0:e.setGuessedText(t))}serializeAltText(t){var e;return(e=l(this,Rt))==null?void 0:e.serialize(t)}hasAltText(){return!!l(this,Rt)&&!l(this,Rt).isEmpty()}hasAltTextData(){var t;return((t=l(this,Rt))==null?void 0:t.hasData())??!1}render(){var n;this.div=document.createElement("div"),this.div.setAttribute("data-editor-rotation",(360-this.rotation)%360),this.div.className=this.name,this.div.setAttribute("id",this.id),this.div.tabIndex=l(this,zo)?-1:0,this._isVisible||this.div.classList.add("hidden"),this.setInForeground(),w(this,J,Np).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),md(this,this.div,["pointerdown"]),this.isResizable&&this._uiManager._supportsPinchToZoom&&(l(this,pa)||v(this,pa,new bd({container:this.div,isPinchingDisabled:()=>!this.isSelected,onPinchStart:w(this,J,uy).bind(this),onPinching:w(this,J,dy).bind(this),onPinchEnd:w(this,J,fy).bind(this),signal:this._uiManager._signal}))),(n=this._uiManager._editorUndoBar)==null||n.hide(),this.div}pointerdown(t){const{isMac:e}=Ue.platform;if(t.button!==0||t.ctrlKey&&e){t.preventDefault();return}if(v(this,fa,!0),this._isDraggable){w(this,J,gy).call(this,t);return}w(this,J,jp).call(this,t)}get isSelected(){return this._uiManager.isSelected(this)}_onStartDragging(){}_onStopDragging(){}moveInDOM(){l(this,ji)&&clearTimeout(l(this,ji)),v(this,ji,setTimeout(()=>{var t;v(this,ji,null),(t=this.parent)==null||t.moveEditorInDOM(this)},0))}_setParentAndPosition(t,e,s){t.changeParent(this),this.x=e,this.y=s,this.fixAndSetPosition(),this._onTranslated()}getRect(t,e,s=this.rotation){const i=this.parentScale,[n,r]=this.pageDimensions,[a,h]=this.pageTranslation,c=t/i,u=e/i,d=this.x*n,f=this.y*r,g=this.width*n,p=this.height*r;switch(s){case 0:return[d+c+a,r-f-u-p+h,d+c+g+a,r-f-u+h];case 90:return[d+u+a,r-f+c+h,d+u+p+a,r-f+c+g+h];case 180:return[d-c-g+a,r-f+u+h,d-c+a,r-f+u+p+h];case 270:return[d-u-p+a,r-f-c-g+h,d-u+a,r-f-c+h];default:throw new Error("Invalid rotation")}}getRectInCurrentCoords(t,e){const[s,i,n,r]=t,a=n-s,h=r-i;switch(this.rotation){case 0:return[s,e-r,a,h];case 90:return[s,e-i,h,a];case 180:return[n,e-i,a,h];case 270:return[n,e-r,h,a];default:throw new Error("Invalid rotation")}}onceAdded(t){}isEmpty(){return!1}enableEditMode(){v(this,ga,!0)}disableEditMode(){v(this,ga,!1)}isInEditMode(){return l(this,ga)}shouldGetKeyboardEvents(){return l(this,mn)}needsToBeRebuilt(){return this.div&&!this.isAttachedToDOM}get isOnScreen(){const{top:t,left:e,bottom:s,right:i}=this.getClientDimensions(),{innerHeight:n,innerWidth:r}=window;return e<r&&i>0&&t<n&&s>0}rebuild(){w(this,J,Np).call(this)}rotate(t){}resize(){}serializeDeleted(){var t;return{id:this.annotationElementId,deleted:!0,pageIndex:this.pageIndex,popupRef:((t=this._initialData)==null?void 0:t.popupRef)||""}}serialize(t=!1,e=null){kt("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,v(i,ca,t.accessibilityData);const[n,r]=i.pageDimensions,[a,h,c,u]=i.getRectInCurrentCoords(t.rect,r);return i.x=a/n,i.y=h/r,i.width=c/n,i.height=u/r,i}get hasBeenModified(){return!!this.annotationElementId&&(this.deleted||this.serialize()!==null)}remove(){var t,e;if((t=l(this,cr))==null||t.abort(),v(this,cr,null),this.isEmpty()||this.commit(),this.parent?this.parent.remove(this):this._uiManager.removeEditor(this),l(this,ji)&&(clearTimeout(l(this,ji)),v(this,ji,null)),w(this,J,qc).call(this),this.removeEditToolbar(),l(this,Hs)){for(const s of l(this,Hs).values())clearTimeout(s);v(this,Hs,null)}this.parent=null,(e=l(this,pa))==null||e.destroy(),v(this,pa,null)}get isResizable(){return!1}makeResizable(){this.isResizable&&(w(this,J,ly).call(this),l(this,we).classList.remove("hidden"),md(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),v(this,pn,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height});const e=l(this,we).children;if(!l(this,ci)){v(this,ci,Array.from(e));const r=w(this,J,py).bind(this),a=w(this,J,my).bind(this),h=this._uiManager._signal;for(const c of l(this,ci)){const u=c.getAttribute("data-resizer-name");c.setAttribute("role","spinbutton"),c.addEventListener("keydown",r,{signal:h}),c.addEventListener("blur",a,{signal:h}),c.addEventListener("focus",w(this,J,vy).bind(this,u),{signal:h}),c.setAttribute("data-l10n-id",lt._l10nResizer[u])}}const s=l(this,ci)[0];let i=0;for(const r of e){if(r===s)break;i++}const n=(360-this.rotation+this.parentRotation)%360/90*(l(this,ci).length/4);if(n!==i){if(n<i)for(let a=0;a<i-n;a++)l(this,we).append(l(this,we).firstChild);else if(n>i)for(let a=0;a<n-i;a++)l(this,we).firstChild.before(l(this,we).lastChild);let r=0;for(const a of e){const c=l(this,ci)[r++].getAttribute("data-resizer-name");a.setAttribute("data-l10n-id",lt._l10nResizer[c])}}w(this,J,Bp).call(this,0),v(this,mn,!0),l(this,we).firstChild.focus({focusVisible:!0}),t.preventDefault(),t.stopImmediatePropagation()}_resizeWithKeyboard(t,e){l(this,mn)&&w(this,J,Ip).call(this,l(this,Vl),{deltaX:t,deltaY:e,fromKeyboard:!0})}_stopResizingWithKeyboard(){w(this,J,qc).call(this),this.div.focus()}select(){var t,e,s;if(this.makeResizable(),(t=this.div)==null||t.classList.add("selectedEditor"),!this._editToolbar){this.addEditToolbar().then(()=>{var i,n;(i=this.div)!=null&&i.classList.contains("selectedEditor")&&((n=this._editToolbar)==null||n.show())});return}(e=this._editToolbar)==null||e.show(),(s=l(this,Rt))==null||s.toggleAltTextBadge(!1)}unselect(){var t,e,s,i,n;(t=l(this,we))==null||t.classList.add("hidden"),(e=this.div)==null||e.classList.remove("selectedEditor"),(s=this.div)!=null&&s.contains(document.activeElement)&&this._uiManager.currentLayer.div.focus({preventScroll:!0}),(i=this._editToolbar)==null||i.hide(),(n=l(this,Rt))==null||n.toggleAltTextBadge(!0)}updateParams(t,e){}disableEditing(){}enableEditing(){}enterInEditMode(){}getImageForAltText(){return null}get contentDiv(){return this.div}get isEditing(){return l(this,Wl)}set isEditing(t){v(this,Wl,t),this.parent&&(t?(this.parent.setSelected(this),this.parent.setActiveEditor(this)):this.parent.setActiveEditor(null))}setAspectRatio(t,e){v(this,ua,!0);const s=t/e,{style:i}=this.div;i.aspectRatio=s,i.height="auto"}static get MIN_SIZE(){return 16}static canCreateNewEmptyEditor(){return!0}get telemetryInitialData(){return{action:"added"}}get telemetryFinalData(){return null}_reportTelemetry(t,e=!1){if(e){l(this,Hs)||v(this,Hs,new Map);const{action:s}=t;let i=l(this,Hs).get(s);i&&clearTimeout(i),i=setTimeout(()=>{this._reportTelemetry(t),l(this,Hs).delete(s),l(this,Hs).size===0&&v(this,Hs,null)},lt._telemetryTimeout),l(this,Hs).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),v(this,zo,!1)}disable(){this.div&&(this.div.tabIndex=-1),v(this,zo,!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()}};ca=new WeakMap,ci=new WeakMap,Rt=new WeakMap,zo=new WeakMap,lr=new WeakMap,zl=new WeakMap,ua=new WeakMap,we=new WeakMap,da=new WeakMap,pn=new WeakMap,cr=new WeakMap,Vl=new WeakMap,fa=new WeakMap,ws=new WeakMap,Wl=new WeakMap,ga=new WeakMap,mn=new WeakMap,ji=new WeakMap,Vo=new WeakMap,Wo=new WeakMap,Hs=new WeakMap,pa=new WeakMap,Gl=new WeakMap,Fd=new WeakMap,J=new WeakSet,Rp=function([t,e],s,i){[s,i]=this.screenToPageTranslation(s,i),this.x+=s/t,this.y+=i/e,this._onTranslating(this.x,this.y),this.fixAndSetPosition()},Xl=new WeakSet,Fp=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]}},rf=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]}},ly=function(){if(l(this,we))return;v(this,we,document.createElement("div")),l(this,we).classList.add("resizers");const t=this._willKeepAspectRatio?["topLeft","topRight","bottomRight","bottomLeft"]:["topLeft","topMiddle","topRight","middleRight","bottomRight","bottomMiddle","bottomLeft","middleLeft"],e=this._uiManager._signal;for(const s of t){const i=document.createElement("div");l(this,we).append(i),i.classList.add("resizer",s),i.setAttribute("data-resizer-name",s),i.addEventListener("pointerdown",w(this,J,cy).bind(this,s),{signal:e}),i.addEventListener("contextmenu",ri,{signal:e}),i.tabIndex=-1}this.div.prepend(l(this,we))},cy=function(t,e){var u;e.preventDefault();const{isMac:s}=Ue.platform;if(e.button!==0||e.ctrlKey&&s)return;(u=l(this,Rt))==null||u.toggle(!1);const i=this._isDraggable;this._isDraggable=!1,v(this,da,[e.screenX,e.screenY]);const n=new AbortController,r=this._uiManager.combinedSignal(n);this.parent.togglePointerEvents(!1),window.addEventListener("pointermove",w(this,J,Ip).bind(this,t),{passive:!0,capture:!0,signal:r}),window.addEventListener("touchmove",bs,{passive:!1,signal:r}),window.addEventListener("contextmenu",ri,{signal:r}),v(this,pn,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height});const a=this.parent.div.style.cursor,h=this.div.style.cursor;this.div.style.cursor=this.parent.div.style.cursor=window.getComputedStyle(e.target).cursor;const c=()=>{var d;n.abort(),this.parent.togglePointerEvents(!0),(d=l(this,Rt))==null||d.toggle(!0),this._isDraggable=i,this.parent.div.style.cursor=a,this.div.style.cursor=h,w(this,J,af).call(this)};window.addEventListener("pointerup",c,{signal:r}),window.addEventListener("blur",c,{signal:r})},Lp=function(t,e,s,i){this.width=s,this.height=i,this.x=t,this.y=e;const[n,r]=this.parentDimensions;this.setDims(n*s,r*i),this.fixAndSetPosition(),this._onResized()},af=function(){if(!l(this,pn))return;const{savedX:t,savedY:e,savedWidth:s,savedHeight:i}=l(this,pn);v(this,pn,null);const n=this.x,r=this.y,a=this.width,h=this.height;n===t&&r===e&&a===s&&h===i||this.addCommands({cmd:w(this,J,Lp).bind(this,n,r,a,h),undo:w(this,J,Lp).bind(this,t,e,s,i),mustExec:!0})},Ip=function(t,e){const[s,i]=this.parentDimensions,n=this.x,r=this.y,a=this.width,h=this.height,c=lt.MIN_SIZE/s,u=lt.MIN_SIZE/i,d=w(this,J,rf).call(this,this.rotation),f=(I,V)=>[d[0]*I+d[2]*V,d[1]*I+d[3]*V],g=w(this,J,rf).call(this,360-this.rotation),p=(I,V)=>[g[0]*I+g[2]*V,g[1]*I+g[3]*V];let m,y,b=!1,x=!1;switch(t){case"topLeft":b=!0,m=(I,V)=>[0,0],y=(I,V)=>[I,V];break;case"topMiddle":m=(I,V)=>[I/2,0],y=(I,V)=>[I/2,V];break;case"topRight":b=!0,m=(I,V)=>[I,0],y=(I,V)=>[0,V];break;case"middleRight":x=!0,m=(I,V)=>[I,V/2],y=(I,V)=>[0,V/2];break;case"bottomRight":b=!0,m=(I,V)=>[I,V],y=(I,V)=>[0,0];break;case"bottomMiddle":m=(I,V)=>[I/2,V],y=(I,V)=>[I/2,0];break;case"bottomLeft":b=!0,m=(I,V)=>[0,V],y=(I,V)=>[I,0];break;case"middleLeft":x=!0,m=(I,V)=>[0,V/2],y=(I,V)=>[I,V/2];break}const S=m(a,h),C=y(a,h);let k=f(...C);const O=lt._round(n+k[0]),P=lt._round(r+k[1]);let D=1,R=1,z,B;if(e.fromKeyboard)({deltaX:z,deltaY:B}=e);else{const{screenX:I,screenY:V}=e,[it,Ot]=l(this,da);[z,B]=this.screenToPageTranslation(I-it,V-Ot),l(this,da)[0]=I,l(this,da)[1]=V}if([z,B]=p(z/s,B/i),b){const I=Math.hypot(a,h);D=R=Math.max(Math.min(Math.hypot(C[0]-S[0]-z,C[1]-S[1]-B)/I,1/a,1/h),c/a,u/h)}else x?D=Math.max(c,Math.min(1,Math.abs(C[0]-S[0]-z)))/a:R=Math.max(u,Math.min(1,Math.abs(C[1]-S[1]-B)))/h;const F=lt._round(a*D),L=lt._round(h*R);k=f(...y(F,L));const N=O-k[0],K=P-k[1];l(this,ws)||v(this,ws,[this.x,this.y,this.width,this.height]),this.width=F,this.height=L,this.x=N,this.y=K,this.setDims(s*F,i*L),this.fixAndSetPosition(),this._onResizing()},uy=function(){var t;v(this,pn,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height}),(t=l(this,Rt))==null||t.toggle(!1),this.parent.togglePointerEvents(!1)},dy=function(t,e,s){let n=.7*(s/e)+1-.7;if(n===1)return;const r=w(this,J,rf).call(this,this.rotation),a=(O,P)=>[r[0]*O+r[2]*P,r[1]*O+r[3]*P],[h,c]=this.parentDimensions,u=this.x,d=this.y,f=this.width,g=this.height,p=lt.MIN_SIZE/h,m=lt.MIN_SIZE/c;n=Math.max(Math.min(n,1/f,1/g),p/f,m/g);const y=lt._round(f*n),b=lt._round(g*n);if(y===f&&b===g)return;l(this,ws)||v(this,ws,[u,d,f,g]);const x=a(f/2,g/2),S=lt._round(u+x[0]),C=lt._round(d+x[1]),k=a(y/2,b/2);this.x=S-k[0],this.y=C-k[1],this.width=y,this.height=b,this.setDims(h*y,c*b),this.fixAndSetPosition(),this._onResizing()},fy=function(){var t;(t=l(this,Rt))==null||t.toggle(!0),this.parent.togglePointerEvents(!0),w(this,J,af).call(this)},jp=function(t){const{isMac:e}=Ue.platform;t.ctrlKey&&!e||t.shiftKey||t.metaKey&&e?this.parent.toggleSelected(this):this.parent.setSelected(this)},gy=function(t){const{isSelected:e}=this;this._uiManager.setUpDragSession();let s=!1;const i=new AbortController,n=this._uiManager.combinedSignal(i),r={capture:!0,passive:!1,signal:n},a=c=>{i.abort(),v(this,lr,null),v(this,fa,!1),this._uiManager.endDragSession()||w(this,J,jp).call(this,c),s&&this._onStopDragging()};e&&(v(this,Vo,t.clientX),v(this,Wo,t.clientY),v(this,lr,t.pointerId),v(this,zl,t.pointerType),window.addEventListener("pointermove",c=>{s||(s=!0,this._onStartDragging());const{clientX:u,clientY:d,pointerId:f}=c;if(f!==l(this,lr)){bs(c);return}const[g,p]=this.screenToPageTranslation(u-l(this,Vo),d-l(this,Wo));v(this,Vo,u),v(this,Wo,d),this._uiManager.dragSelectedEditors(g,p)},r),window.addEventListener("touchmove",bs,r),window.addEventListener("pointerdown",c=>{c.pointerType===l(this,zl)&&(l(this,pa)||c.isPrimary)&&a(c),bs(c)},r));const h=c=>{if(!l(this,lr)||l(this,lr)===c.pointerId){a(c);return}bs(c)};window.addEventListener("pointerup",h,{signal:n}),window.addEventListener("blur",h,{signal:n})},Np=function(){if(l(this,cr)||!this.div)return;v(this,cr,new AbortController);const t=this._uiManager.combinedSignal(l(this,cr));this.div.addEventListener("focusin",this.focusin.bind(this),{signal:t}),this.div.addEventListener("focusout",this.focusout.bind(this),{signal:t})},py=function(t){lt._resizerKeyboardManager.exec(this,t)},my=function(t){var e;l(this,mn)&&((e=t.relatedTarget)==null?void 0:e.parentNode)!==l(this,we)&&w(this,J,qc).call(this)},vy=function(t){v(this,Vl,l(this,mn)?t:"")},Bp=function(t){if(l(this,ci))for(const e of l(this,ci))e.tabIndex=t},qc=function(){v(this,mn,!1),w(this,J,Bp).call(this,-1),w(this,J,af).call(this)},_(lt,Xl),Q(lt,"_l10n",null),Q(lt,"_l10nResizer",null),Q(lt,"_borderLineWidth",-1),Q(lt,"_colorManager",new Vg),Q(lt,"_zIndex",1),Q(lt,"_telemetryTimeout",1e3);let Vt=lt;class CS extends Vt{constructor(t){super(t),this.annotationElementId=t.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}}const Fv=3285377520,js=4294901760,ki=65535;class Lv{constructor(t){this.h1=t?t&4294967295:Fv,this.h2=t?t&4294967295:Fv}update(t){let e,s;if(typeof t=="string"){e=new Uint8Array(t.length*2),s=0;for(let m=0,y=t.length;m<y;m++){const b=t.charCodeAt(m);b<=255?e[s++]=b:(e[s++]=b>>>8,e[s++]=b&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 a=0,h=0,c=this.h1,u=this.h2;const d=3432918353,f=461845907,g=d&ki,p=f&ki;for(let m=0;m<i;m++)m&1?(a=r[m],a=a*d&js|a*g&ki,a=a<<15|a>>>17,a=a*f&js|a*p&ki,c^=a,c=c<<13|c>>>19,c=c*5+3864292196):(h=r[m],h=h*d&js|h*g&ki,h=h<<15|h>>>17,h=h*f&js|h*p&ki,u^=h,u=u<<13|u>>>19,u=u*5+3864292196);switch(a=0,n){case 3:a^=e[i*4+2]<<16;case 2:a^=e[i*4+1]<<8;case 1:a^=e[i*4],a=a*d&js|a*g&ki,a=a<<15|a>>>17,a=a*f&js|a*p&ki,i&1?c^=a:u^=a}this.h1=c,this.h2=u}hexdigest(){let t=this.h1,e=this.h2;return t^=e>>>1,t=t*3981806797&js|t*36045&ki,e=e*4283543511&js|((e<<16|t>>>16)*2950163797&js)>>>16,t^=e>>>1,t=t*444984403&js|t*60499&ki,e=e*3301882366&js|((e<<16|t>>>16)*3120437893&js)>>>16,t^=e>>>1,(t>>>0).toString(16).padStart(8,"0")+(e>>>0).toString(16).padStart(8,"0")}}const Wg=Object.freeze({map:null,hash:"",transfer:void 0});class Gg{constructor(){_(this,Ld);_(this,ma,!1);_(this,va,null);_(this,me,new Map);this.onSetModified=null,this.onResetModified=null,this.onAnnotationEditor=null}getValue(t,e){const s=l(this,me).get(t);return s===void 0?e:Object.assign(e,s)}getRawValue(t){return l(this,me).get(t)}remove(t){if(l(this,me).delete(t),l(this,me).size===0&&this.resetModified(),typeof this.onAnnotationEditor=="function"){for(const e of l(this,me).values())if(e instanceof Vt)return;this.onAnnotationEditor(null)}}setValue(t,e){const s=l(this,me).get(t);let i=!1;if(s!==void 0)for(const[n,r]of Object.entries(e))s[n]!==r&&(i=!0,s[n]=r);else i=!0,l(this,me).set(t,e);i&&w(this,Ld,by).call(this),e instanceof Vt&&typeof this.onAnnotationEditor=="function"&&this.onAnnotationEditor(e.constructor._type)}has(t){return l(this,me).has(t)}getAll(){return l(this,me).size>0?Og(l(this,me)):null}setAll(t){for(const[e,s]of Object.entries(t))this.setValue(e,s)}get size(){return l(this,me).size}resetModified(){l(this,ma)&&(v(this,ma,!1),typeof this.onResetModified=="function"&&this.onResetModified())}get print(){return new Iv(this)}get serializable(){if(l(this,me).size===0)return Wg;const t=new Map,e=new Lv,s=[],i=Object.create(null);let n=!1;for(const[r,a]of l(this,me)){const h=a instanceof Vt?a.serialize(!1,i):a;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}:Wg}get editorStats(){let t=null;const e=new Map;for(const s of l(this,me).values()){if(!(s instanceof Vt))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[a,h]of Object.entries(i)){if(a==="type")continue;let c=r.get(a);c||(c=new Map,r.set(a,c));const u=c.get(h)??0;c.set(h,u+1)}}for(const[s,i]of e)t[s]=i.computeTelemetryFinalData(t[s]);return t}resetModifiedIds(){v(this,va,null)}get modifiedIds(){if(l(this,va))return l(this,va);const t=[];for(const e of l(this,me).values())!(e instanceof Vt)||!e.annotationElementId||!e.serialize()||t.push(e.annotationElementId);return v(this,va,{ids:new Set(t),hash:t.join(",")})}}ma=new WeakMap,va=new WeakMap,me=new WeakMap,Ld=new WeakSet,by=function(){l(this,ma)||(v(this,ma,!0),typeof this.onSetModified=="function"&&this.onSetModified())};class Iv extends Gg{constructor(e){super();_(this,Ul);const{map:s,hash:i,transfer:n}=e.serializable,r=structuredClone(s,n?{transfer:n}:null);v(this,Ul,{map:r,hash:i,transfer:n})}get print(){kt("Should not call PrintAnnotationStorage.print")}get serializable(){return l(this,Ul)}get modifiedIds(){return ct(this,"modifiedIds",{ids:new Set,hash:""})}}Ul=new WeakMap;class AS{constructor({ownerDocument:t=globalThis.document,styleElement:e=null}){_(this,Go,new Set);this._document=t,this.nativeFontFaces=new Set,this.styleElement=null,this.loadingRequests=[],this.loadTestFontId=0}addNativeFontFace(t){this.nativeFontFaces.add(t),this._document.fonts.add(t)}removeNativeFontFace(t){this.nativeFontFaces.delete(t),this._document.fonts.delete(t)}insertRule(t){this.styleElement||(this.styleElement=this._document.createElement("style"),this._document.documentElement.getElementsByTagName("head")[0].append(this.styleElement));const e=this.styleElement.sheet;e.insertRule(t,e.cssRules.length)}clear(){for(const t of this.nativeFontFaces)this._document.fonts.delete(t);this.nativeFontFaces.clear(),l(this,Go).clear(),this.styleElement&&(this.styleElement.remove(),this.styleElement=null)}async loadSystemFont({systemFontInfo:t,_inspectFont:e}){if(!(!t||l(this,Go).has(t.loadedName))){if(ie(!this.disableFontFace,"loadSystemFont shouldn't be called when `disableFontFace` is set."),this.isFontLoadingAPISupported){const{loadedName:s,src:i,style:n}=t,r=new FontFace(s,i,n);this.addNativeFontFace(r);try{await r.load(),l(this,Go).add(s),e==null||e(t)}catch{ht(`Cannot load system font: ${t.baseFontName}, installing it could help to improve PDF rendering.`),this.removeNativeFontFace(r)}return}kt("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 ht(`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 ct(this,"isFontLoadingAPISupported",t)}get isSyncFontLoadingSupported(){let t=!1;return(Oe||typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.userAgent)=="string"&&/Mozilla\/5.0.*?rv:\d+.*? Gecko/.test(navigator.userAgent))&&(t=!0),ct(this,"isSyncFontLoadingSupported",t)}_queueLoadingCallback(t){function e(){for(ie(!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 ct(this,"_loadTestFont",t)}_prepareFontLoadEvent(t,e){function s(C,k){return C.charCodeAt(k)<<24|C.charCodeAt(k+1)<<16|C.charCodeAt(k+2)<<8|C.charCodeAt(k+3)&255}function i(C,k,O,P){const D=C.substring(0,k),R=C.substring(k+O);return D+P+R}let n,r;const a=this._document.createElement("canvas");a.width=1,a.height=1;const h=a.getContext("2d");let c=0;function u(C,k){if(++c>30){ht("Load test font never loaded."),k();return}if(h.font="30px "+C,h.fillText(".",0,20),h.getImageData(0,0,1,1).data[3]>0){k();return}setTimeout(u.bind(null,C,k))}const d=`lt${Date.now()}${this.loadTestFontId++}`;let f=this._loadTestFont;f=i(f,976,d.length,d);const p=16,m=1482184792;let y=s(f,p);for(n=0,r=d.length-3;n<r;n+=4)y=y-m+s(d,n)|0;n<d.length&&(y=y-m+s(d+"XXX",n)|0),f=i(f,p,4,cS(y));const b=`url(data:font/opentype;base64,${btoa(f)});`,x=`@font-face {font-family:"${d}";src:${b}}`;this.insertRule(x);const S=this._document.createElement("div");S.style.visibility="hidden",S.style.width=S.style.height="10px",S.style.position="absolute",S.style.top=S.style.left="0px";for(const C of[t.loadedName,d]){const k=this._document.createElement("span");k.textContent="Hi",k.style.fontFamily=C,S.append(k)}this._document.body.append(S),u(d,()=>{S.remove(),e.complete()})}}Go=new WeakMap;class TS{constructor(t,{disableFontFace:e=!1,fontExtraProperties:s=!1,inspectFont:i=null}){this.compiledGlyphs=Object.create(null);for(const n in t)this[n]=t[n];this.disableFontFace=e===!0,this.fontExtraProperties=s===!0,this._inspectFont=i}createNativeFontFace(){var e;if(!this.data||this.disableFontFace)return null;let t;if(!this.cssFontInfo)t=new FontFace(this.loadedName,this.data,{});else{const s={weight:this.cssFontInfo.fontWeight};this.cssFontInfo.italicAngle&&(s.style=`oblique ${this.cssFontInfo.italicAngle}deg`),t=new FontFace(this.cssFontInfo.fontFamily,this.data,s)}return(e=this._inspectFont)==null||e.call(this,this),t}createFontFaceRule(){var s;if(!this.data||this.disableFontFace)return null;const t=`url(data:${this.mimetype};base64,${mS(this.data)});`;let e;if(!this.cssFontInfo)e=`@font-face {font-family:"${this.loadedName}";src:${t}}`;else{let i=`font-weight: ${this.cssFontInfo.fontWeight};`;this.cssFontInfo.italicAngle&&(i+=`font-style: oblique ${this.cssFontInfo.italicAngle}deg;`),e=`@font-face {font-family:"${this.cssFontInfo.fontFamily}";${i}src:${t}}`}return(s=this._inspectFont)==null||s.call(this,this,t),e}getPathGenerator(t,e){if(this.compiledGlyphs[e]!==void 0)return this.compiledGlyphs[e];const s=this.loadedName+"_path_"+e;let i;try{i=t.get(s)}catch(r){ht(`getPathGenerator - ignoring character: "${r}".`)}const n=new Path2D(i||"");return this.fontExtraProperties||t.delete(s),this.compiledGlyphs[e]=n}}const yd={DATA:1,ERROR:2},ne={CANCEL:1,CANCEL_COMPLETE:2,CLOSE:3,ENQUEUE:4,ERROR:5,PULL:6,PULL_COMPLETE:7,START_COMPLETE:8};function jv(){}function rs(o){if(o instanceof qn||o instanceof Mg||o instanceof ll||o instanceof Mv||o instanceof dd||o instanceof Pg)return o;switch(o instanceof Error||typeof o=="object"&&o!==null||kt('wrapReason: Expected "reason" to be a (possibly cloned) Error.'),o.name){case"AbortException":return new qn(o.message);case"InvalidPDFException":return new Mg(o.message);case"MissingPDFException":return new ll(o.message);case"PasswordException":return new Mv(o.message,o.code);case"UnexpectedResponseException":return new dd(o.message,o.status);case"UnknownErrorException":return new Pg(o.message,o.details)}return new Pg(o.message,o.toString())}class fl{constructor(t,e,s){_(this,zs);_(this,Xo,new AbortController);this.sourceName=t,this.targetName=e,this.comObj=s,this.callbackId=1,this.streamId=1,this.streamSinks=Object.create(null),this.streamControllers=Object.create(null),this.callbackCapabilities=Object.create(null),this.actionHandler=Object.create(null),s.addEventListener("message",w(this,zs,yy).bind(this),{signal:l(this,Xo).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,a=this.targetName,h=this.comObj;return new ReadableStream({start:c=>{const u=Promise.withResolvers();return this.streamControllers[n]={controller:c,startCall:u,pullCall:null,cancelCall:null,isClosed:!1},h.postMessage({sourceName:r,targetName:a,action:t,streamId:n,data:e,desiredSize:c.desiredSize},i),u.promise},pull:c=>{const u=Promise.withResolvers();return this.streamControllers[n].pullCall=u,h.postMessage({sourceName:r,targetName:a,stream:ne.PULL,streamId:n,desiredSize:c.desiredSize}),u.promise},cancel:c=>{ie(c instanceof Error,"cancel must have a valid reason");const u=Promise.withResolvers();return this.streamControllers[n].cancelCall=u,this.streamControllers[n].isClosed=!0,h.postMessage({sourceName:r,targetName:a,stream:ne.CANCEL,streamId:n,reason:rs(c)}),u.promise}},s)}destroy(){var t;(t=l(this,Xo))==null||t.abort(),v(this,Xo,null)}}Xo=new WeakMap,zs=new WeakSet,yy=function({data:t}){if(t.targetName!==this.sourceName)return;if(t.stream){w(this,zs,wy).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===yd.DATA)i.resolve(t.data);else if(t.callback===yd.ERROR)i.reject(rs(t.reason));else throw new Error("Unexpected callback case");return}const e=this.actionHandler[t.action];if(!e)throw new Error(`Unknown action from worker: ${t.action}`);if(t.callbackId){const s=this.sourceName,i=t.sourceName,n=this.comObj;Promise.try(e,t.data).then(function(r){n.postMessage({sourceName:s,targetName:i,callback:yd.DATA,callbackId:t.callbackId,data:r})},function(r){n.postMessage({sourceName:s,targetName:i,callback:yd.ERROR,callbackId:t.callbackId,reason:rs(r)})});return}if(t.streamId){w(this,zs,_y).call(this,t);return}e(t.data)},_y=function(t){const e=t.streamId,s=this.sourceName,i=t.sourceName,n=this.comObj,r=this,a=this.actionHandler[t.action],h={enqueue(c,u=1,d){if(this.isCancelled)return;const f=this.desiredSize;this.desiredSize-=u,f>0&&this.desiredSize<=0&&(this.sinkCapability=Promise.withResolvers(),this.ready=this.sinkCapability.promise),n.postMessage({sourceName:s,targetName:i,stream:ne.ENQUEUE,streamId:e,chunk:c},d)},close(){this.isCancelled||(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:ne.CLOSE,streamId:e}),delete r.streamSinks[e])},error(c){ie(c instanceof Error,"error must have a valid reason"),!this.isCancelled&&(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:ne.ERROR,streamId:e,reason:rs(c)}))},sinkCapability:Promise.withResolvers(),onPull:null,onCancel:null,isCancelled:!1,desiredSize:t.desiredSize,ready:null};h.sinkCapability.resolve(),h.ready=h.sinkCapability.promise,this.streamSinks[e]=h,Promise.try(a,t.data,h).then(function(){n.postMessage({sourceName:s,targetName:i,stream:ne.START_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:ne.START_COMPLETE,streamId:e,reason:rs(c)})})},wy=function(t){const e=t.streamId,s=this.sourceName,i=t.sourceName,n=this.comObj,r=this.streamControllers[e],a=this.streamSinks[e];switch(t.stream){case ne.START_COMPLETE:t.success?r.startCall.resolve():r.startCall.reject(rs(t.reason));break;case ne.PULL_COMPLETE:t.success?r.pullCall.resolve():r.pullCall.reject(rs(t.reason));break;case ne.PULL:if(!a){n.postMessage({sourceName:s,targetName:i,stream:ne.PULL_COMPLETE,streamId:e,success:!0});break}a.desiredSize<=0&&t.desiredSize>0&&a.sinkCapability.resolve(),a.desiredSize=t.desiredSize,Promise.try(a.onPull||jv).then(function(){n.postMessage({sourceName:s,targetName:i,stream:ne.PULL_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:ne.PULL_COMPLETE,streamId:e,reason:rs(c)})});break;case ne.ENQUEUE:if(ie(r,"enqueue should have stream controller"),r.isClosed)break;r.controller.enqueue(t.chunk);break;case ne.CLOSE:if(ie(r,"close should have stream controller"),r.isClosed)break;r.isClosed=!0,r.controller.close(),w(this,zs,of).call(this,r,e);break;case ne.ERROR:ie(r,"error should have stream controller"),r.controller.error(rs(t.reason)),w(this,zs,of).call(this,r,e);break;case ne.CANCEL_COMPLETE:t.success?r.cancelCall.resolve():r.cancelCall.reject(rs(t.reason)),w(this,zs,of).call(this,r,e);break;case ne.CANCEL:if(!a)break;const h=rs(t.reason);Promise.try(a.onCancel||jv,h).then(function(){n.postMessage({sourceName:s,targetName:i,stream:ne.CANCEL_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:ne.CANCEL_COMPLETE,streamId:e,reason:rs(c)})}),a.sinkCapability.reject(h),a.isCancelled=!0,delete this.streamSinks[e];break;default:throw new Error("Unexpected stream case")}},of=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 Nv{constructor({enableHWA:t=!1}){_(this,Yl,!1);v(this,Yl,t)}create(t,e){if(t<=0||e<=0)throw new Error("Invalid canvas size");const s=this._createCanvas(t,e);return{canvas:s,context:s.getContext("2d",{willReadFrequently:!l(this,Yl)})}}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){kt("Abstract method `_createCanvas` called.")}}Yl=new WeakMap;class ES extends Nv{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 Bv{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){kt("Abstract method `_fetch` called.")}}class Hv extends Bv{async _fetch(t){const e=await gd(t,this.isCompressed?"arraybuffer":"text");return e instanceof ArrayBuffer?new Uint8Array(e):fd(e)}}class zv{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 kS extends zv{constructor({docId:e,ownerDocument:s=globalThis.document}){super();_(this,G);_(this,ba);_(this,Uo);_(this,vn);_(this,bn);_(this,Le);_(this,ya);_(this,_a,0);v(this,bn,e),v(this,Le,s)}addFilter(e){if(!e)return"none";let s=l(this,G,Be).get(e);if(s)return s;const[i,n,r]=w(this,G,hf).call(this,e),a=e.length===1?i:`${i}${n}${r}`;if(s=l(this,G,Be).get(a),s)return l(this,G,Be).set(e,s),s;const h=`g_${l(this,bn)}_transfer_map_${es(this,_a)._++}`,c=w(this,G,Bh).call(this,h);l(this,G,Be).set(e,c),l(this,G,Be).set(a,c);const u=w(this,G,Hh).call(this,h);return w(this,G,Qc).call(this,i,n,r,u),c}addHCMFilter(e,s){var p;const i=`${e}-${s}`,n="base";let r=l(this,G,Kc).get(n);if((r==null?void 0:r.key)===i||(r?((p=r.filter)==null||p.remove(),r.key=i,r.url="none",r.filter=null):(r={key:i,url:"none",filter:null},l(this,G,Kc).set(n,r)),!e||!s))return r.url;const a=w(this,G,Zc).call(this,e);e=q.makeHexColor(...a);const h=w(this,G,Zc).call(this,s);if(s=q.makeHexColor(...h),l(this,G,Nh).style.color="",e==="#000000"&&s==="#ffffff"||e===s)return r.url;const c=new Array(256);for(let m=0;m<=255;m++){const y=m/255;c[m]=y<=.03928?y/12.92:((y+.055)/1.055)**2.4}const u=c.join(","),d=`g_${l(this,bn)}_hcm_filter`,f=r.filter=w(this,G,Hh).call(this,d);w(this,G,Qc).call(this,u,u,u,f),w(this,G,Hp).call(this,f);const g=(m,y)=>{const b=a[m]/255,x=h[m]/255,S=new Array(y+1);for(let C=0;C<=y;C++)S[C]=b+C/y*(x-b);return S.join(",")};return w(this,G,Qc).call(this,g(0,5),g(1,5),g(2,5),f),r.url=w(this,G,Bh).call(this,d),r.url}addAlphaFilter(e){let s=l(this,G,Be).get(e);if(s)return s;const[i]=w(this,G,hf).call(this,[e]),n=`alpha_${i}`;if(s=l(this,G,Be).get(n),s)return l(this,G,Be).set(e,s),s;const r=`g_${l(this,bn)}_alpha_map_${es(this,_a)._++}`,a=w(this,G,Bh).call(this,r);l(this,G,Be).set(e,a),l(this,G,Be).set(n,a);const h=w(this,G,Hh).call(this,r);return w(this,G,zp).call(this,i,h),a}addLuminosityFilter(e){let s=l(this,G,Be).get(e||"luminosity");if(s)return s;let i,n;if(e?([i]=w(this,G,hf).call(this,[e]),n=`luminosity_${i}`):n="luminosity",s=l(this,G,Be).get(n),s)return l(this,G,Be).set(e,s),s;const r=`g_${l(this,bn)}_luminosity_map_${es(this,_a)._++}`,a=w(this,G,Bh).call(this,r);l(this,G,Be).set(e,a),l(this,G,Be).set(n,a);const h=w(this,G,Hh).call(this,r);return w(this,G,xy).call(this,h),e&&w(this,G,zp).call(this,i,h),a}addHighlightHCMFilter(e,s,i,n,r){var x;const a=`${s}-${i}-${n}-${r}`;let h=l(this,G,Kc).get(e);if((h==null?void 0:h.key)===a||(h?((x=h.filter)==null||x.remove(),h.key=a,h.url="none",h.filter=null):(h={key:a,url:"none",filter:null},l(this,G,Kc).set(e,h)),!s||!i))return h.url;const[c,u]=[s,i].map(w(this,G,Zc).bind(this));let d=Math.round(.2126*c[0]+.7152*c[1]+.0722*c[2]),f=Math.round(.2126*u[0]+.7152*u[1]+.0722*u[2]),[g,p]=[n,r].map(w(this,G,Zc).bind(this));f<d&&([d,f,g,p]=[f,d,p,g]),l(this,G,Nh).style.color="";const m=(S,C,k)=>{const O=new Array(256),P=(f-d)/k,D=S/255,R=(C-S)/(255*k);let z=0;for(let B=0;B<=k;B++){const F=Math.round(d+B*P),L=D+B*R;for(let N=z;N<=F;N++)O[N]=L;z=F+1}for(let B=z;B<256;B++)O[B]=O[z-1];return O.join(",")},y=`g_${l(this,bn)}_hcm_${e}_filter`,b=h.filter=w(this,G,Hh).call(this,y);return w(this,G,Hp).call(this,b),w(this,G,Qc).call(this,m(g[0],p[0],5),m(g[1],p[1],5),m(g[2],p[2],5),b),h.url=w(this,G,Bh).call(this,y),h.url}destroy(e=!1){var s,i,n,r;e&&((s=l(this,ya))!=null&&s.size)||((i=l(this,vn))==null||i.parentNode.parentNode.remove(),v(this,vn,null),(n=l(this,Uo))==null||n.clear(),v(this,Uo,null),(r=l(this,ya))==null||r.clear(),v(this,ya,null),v(this,_a,0))}}ba=new WeakMap,Uo=new WeakMap,vn=new WeakMap,bn=new WeakMap,Le=new WeakMap,ya=new WeakMap,_a=new WeakMap,G=new WeakSet,Be=function(){return l(this,Uo)||v(this,Uo,new Map)},Kc=function(){return l(this,ya)||v(this,ya,new Map)},Nh=function(){if(!l(this,vn)){const e=l(this,Le).createElement("div"),{style:s}=e;s.visibility="hidden",s.contain="strict",s.width=s.height=0,s.position="absolute",s.top=s.left=0,s.zIndex=-1;const i=l(this,Le).createElementNS(rn,"svg");i.setAttribute("width",0),i.setAttribute("height",0),v(this,vn,l(this,Le).createElementNS(rn,"defs")),e.append(i),i.append(l(this,vn)),l(this,Le).body.append(e)}return l(this,vn)},hf=function(e){if(e.length===1){const c=e[0],u=new Array(256);for(let f=0;f<256;f++)u[f]=c[f]/255;const d=u.join(",");return[d,d,d]}const[s,i,n]=e,r=new Array(256),a=new Array(256),h=new Array(256);for(let c=0;c<256;c++)r[c]=s[c]/255,a[c]=i[c]/255,h[c]=n[c]/255;return[r.join(","),a.join(","),h.join(",")]},Bh=function(e){if(l(this,ba)===void 0){v(this,ba,"");const s=l(this,Le).URL;s!==l(this,Le).baseURI&&(pd(s)?ht('#createUrl: ignore "data:"-URL for performance reasons.'):v(this,ba,s.split("#",1)[0]))}return`url(${l(this,ba)}#${e})`},xy=function(e){const s=l(this,Le).createElementNS(rn,"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)},Hp=function(e){const s=l(this,Le).createElementNS(rn,"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)},Hh=function(e){const s=l(this,Le).createElementNS(rn,"filter");return s.setAttribute("color-interpolation-filters","sRGB"),s.setAttribute("id",e),l(this,G,Nh).append(s),s},Jc=function(e,s,i){const n=l(this,Le).createElementNS(rn,s);n.setAttribute("type","discrete"),n.setAttribute("tableValues",i),e.append(n)},Qc=function(e,s,i,n){const r=l(this,Le).createElementNS(rn,"feComponentTransfer");n.append(r),w(this,G,Jc).call(this,r,"feFuncR",e),w(this,G,Jc).call(this,r,"feFuncG",s),w(this,G,Jc).call(this,r,"feFuncB",i)},zp=function(e,s){const i=l(this,Le).createElementNS(rn,"feComponentTransfer");s.append(i),w(this,G,Jc).call(this,i,"feFuncA",e)},Zc=function(e){return l(this,G,Nh).style.color=e,Ng(getComputedStyle(l(this,G,Nh)).getPropertyValue("color"))};class Vv{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){kt("Abstract method `_fetch` called.")}}class Wv extends Vv{async _fetch(t){const e=await gd(t,"arraybuffer");return new Uint8Array(e)}}Oe&&ht("Please use the `legacy` build in Node.js environments.");async function Gv(o){const e=await process.getBuiltinModule("fs").promises.readFile(o);return new Uint8Array(e)}class PS extends zv{}class MS extends Nv{_createCanvas(t,e){return process.getBuiltinModule("module").createRequire(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ht&&Ht.tagName.toUpperCase()==="SCRIPT"&&Ht.src||new URL("pdf-canvas.umd.js",document.baseURI).href)("@napi-rs/canvas").createCanvas(t,e)}}class OS extends Bv{async _fetch(t){return Gv(t)}}class DS extends Vv{async _fetch(t){return Gv(t)}}const Re={FILL:"Fill",STROKE:"Stroke",SHADING:"Shading"};function Xg(o,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),o.clip(i)}class Ug{getPattern(){kt("Abstract method `getPattern` called.")}}class RS extends Ug{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===Re.STROKE||i===Re.FILL){const r=e.current.getClippedPathBoundingBox(i,It(t))||[0,0,0,0],a=Math.ceil(r[2]-r[0])||1,h=Math.ceil(r[3]-r[1])||1,c=e.cachedCanvases.getCanvas("pattern",a,h),u=c.context;u.clearRect(0,0,u.canvas.width,u.canvas.height),u.beginPath(),u.rect(0,0,u.canvas.width,u.canvas.height),u.translate(-r[0],-r[1]),s=q.transform(s,[1,0,0,1,r[0],r[1]]),u.transform(...e.baseTransform),this.matrix&&u.transform(...this.matrix),Xg(u,this._bbox),u.fillStyle=this._createGradient(u),u.fill(),n=t.createPattern(c.canvas,"no-repeat");const d=new DOMMatrix(s);n.setTransform(d)}else Xg(t,this._bbox),n=this._createGradient(t);return n}}function Yg(o,t,e,s,i,n,r,a){const h=t.coords,c=t.colors,u=o.data,d=o.width*4;let f;h[e+1]>h[s+1]&&(f=e,e=s,s=f,f=n,n=r,r=f),h[s+1]>h[i+1]&&(f=s,s=i,i=f,f=r,r=a,a=f),h[e+1]>h[s+1]&&(f=e,e=s,s=f,f=n,n=r,r=f);const g=(h[e]+t.offsetX)*t.scaleX,p=(h[e+1]+t.offsetY)*t.scaleY,m=(h[s]+t.offsetX)*t.scaleX,y=(h[s+1]+t.offsetY)*t.scaleY,b=(h[i]+t.offsetX)*t.scaleX,x=(h[i+1]+t.offsetY)*t.scaleY;if(p>=x)return;const S=c[n],C=c[n+1],k=c[n+2],O=c[r],P=c[r+1],D=c[r+2],R=c[a],z=c[a+1],B=c[a+2],F=Math.round(p),L=Math.round(x);let N,K,I,V,it,Ot,Bt,Xt;for(let Ft=F;Ft<=L;Ft++){if(Ft<y){const nt=Ft<p?0:(p-Ft)/(p-y);N=g-(g-m)*nt,K=S-(S-O)*nt,I=C-(C-P)*nt,V=k-(k-D)*nt}else{let nt;Ft>x?nt=1:y===x?nt=0:nt=(y-Ft)/(y-x),N=m-(m-b)*nt,K=O-(O-R)*nt,I=P-(P-z)*nt,V=D-(D-B)*nt}let _t;Ft<p?_t=0:Ft>x?_t=1:_t=(p-Ft)/(p-x),it=g-(g-b)*_t,Ot=S-(S-R)*_t,Bt=C-(C-z)*_t,Xt=k-(k-B)*_t;const ae=Math.round(Math.min(N,it)),Ze=Math.round(Math.max(N,it));let st=d*Ft+ae*4;for(let nt=ae;nt<=Ze;nt++)_t=(N-nt)/(N-it),_t<0?_t=0:_t>1&&(_t=1),u[st++]=K-(K-Ot)*_t|0,u[st++]=I-(I-Bt)*_t|0,u[st++]=V-(V-Xt)*_t|0,u[st++]=255}}function FS(o,t,e){const s=t.coords,i=t.colors;let n,r;switch(t.type){case"lattice":const a=t.verticesPerRow,h=Math.floor(s.length/a)-1,c=a-1;for(n=0;n<h;n++){let u=n*a;for(let d=0;d<c;d++,u++)Yg(o,e,s[u],s[u+1],s[u+a],i[u],i[u+1],i[u+a]),Yg(o,e,s[u+a+1],s[u+1],s[u+a],i[u+a+1],i[u+1],i[u+a])}break;case"triangles":for(n=0,r=s.length;n<r;n+=3)Yg(o,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 LS extends Ug{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 a=Math.floor(this._bounds[0]),h=Math.floor(this._bounds[1]),c=Math.ceil(this._bounds[2])-a,u=Math.ceil(this._bounds[3])-h,d=Math.min(Math.ceil(Math.abs(c*t[0]*1.1)),3e3),f=Math.min(Math.ceil(Math.abs(u*t[1]*1.1)),3e3),g=c/d,p=u/f,m={coords:this._coords,colors:this._colors,offsetX:-a,offsetY:-h,scaleX:1/g,scaleY:1/p},y=d+2*2,b=f+2*2,x=s.getCanvas("mesh",y,b),S=x.context,C=S.createImageData(d,f);if(e){const O=C.data;for(let P=0,D=O.length;P<D;P+=4)O[P]=e[0],O[P+1]=e[1],O[P+2]=e[2],O[P+3]=255}for(const O of this._figures)FS(C,O,m);return S.putImageData(C,2,2),{canvas:x.canvas,offsetX:a-2*g,offsetY:h-2*p,scaleX:g,scaleY:p}}getPattern(t,e,s,i){Xg(t,this._bbox);let n;if(i===Re.SHADING)n=q.singularValueDecompose2dScale(It(t));else if(n=q.singularValueDecompose2dScale(e.baseTransform),this.matrix){const a=q.singularValueDecompose2dScale(this.matrix);n=[n[0]*a[0],n[1]*a[1]]}const r=this._createMeshCanvas(n,i===Re.SHADING?null:this._background,e.cachedCanvases);return i!==Re.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 IS extends Ug{getPattern(){return"hotpink"}}function jS(o){switch(o[0]){case"RadialAxial":return new RS(o);case"Mesh":return new LS(o);case"Dummy":return new IS}throw new Error(`Unknown IR type: ${o[0]}`)}const Xv={COLORED:1,UNCOLORED:2},Id=class Id{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:a}=this;let{xstep:h,ystep:c}=this;h=Math.abs(h),c=Math.abs(c),ud("TilingType: "+n);const u=e[0],d=e[1],f=e[2],g=e[3],p=f-u,m=g-d,y=q.singularValueDecompose2dScale(this.matrix),b=q.singularValueDecompose2dScale(this.baseTransform),x=y[0]*b[0],S=y[1]*b[1];let C=p,k=m,O=!1,P=!1;const D=Math.ceil(h*x),R=Math.ceil(c*S),z=Math.ceil(p*x),B=Math.ceil(m*S);D>=z?C=h:O=!0,R>=B?k=c:P=!0;const F=this.getSizeAndScale(C,this.ctx.canvas.width,x),L=this.getSizeAndScale(k,this.ctx.canvas.height,S),N=t.cachedCanvases.getCanvas("pattern",F.size,L.size),K=N.context,I=a.createCanvasGraphics(K);if(I.groupLevel=t.groupLevel,this.setFillAndStrokeStyleToContext(I,i,r),K.translate(-F.scale*u,-L.scale*d),I.transform(F.scale,0,0,L.scale,0,0),K.save(),this.clipBbox(I,u,d,f,g),I.baseTransform=It(I.ctx),I.executeOperatorList(s),I.endDrawing(),K.restore(),O||P){const V=N.canvas;O&&(C=h),P&&(k=c);const it=this.getSizeAndScale(C,this.ctx.canvas.width,x),Ot=this.getSizeAndScale(k,this.ctx.canvas.height,S),Bt=it.size,Xt=Ot.size,Ft=t.cachedCanvases.getCanvas("pattern-workaround",Bt,Xt),_t=Ft.context,ae=O?Math.floor(p/h):0,Ze=P?Math.floor(m/c):0;for(let st=0;st<=ae;st++)for(let nt=0;nt<=Ze;nt++)_t.drawImage(V,Bt*st,Xt*nt,Bt,Xt,0,0,Bt,Xt);return{canvas:Ft.canvas,scaleX:it.scale,scaleY:Ot.scale,offsetX:u,offsetY:d}}return{canvas:N.canvas,scaleX:F.scale,scaleY:L.scale,offsetX:u,offsetY:d}}getSizeAndScale(t,e,s){const i=Math.max(Id.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,a=n-s;t.ctx.rect(e,s,r,a),t.current.updateRectMinMax(It(t.ctx),[e,s,i,n]),t.clip(),t.endPath()}setFillAndStrokeStyleToContext(t,e,s){const i=t.ctx,n=t.current;switch(e){case Xv.COLORED:const r=this.ctx;i.fillStyle=r.fillStyle,i.strokeStyle=r.strokeStyle,n.fillColor=r.fillStyle,n.strokeColor=r.strokeStyle;break;case Xv.UNCOLORED:const a=q.makeHexColor(s[0],s[1],s[2]);i.fillStyle=a,i.strokeStyle=a,n.fillColor=a,n.strokeColor=a;break;default:throw new lS(`Unsupported paint type: ${e}`)}}getPattern(t,e,s,i){let n=s;i!==Re.SHADING&&(n=q.transform(n,e.baseTransform),this.matrix&&(n=q.transform(n,this.matrix)));const r=this.createPatternCanvas(e);let a=new DOMMatrix(n);a=a.translate(r.offsetX,r.offsetY),a=a.scale(1/r.scaleX,1/r.scaleY);const h=t.createPattern(r.canvas,"repeat");return h.setTransform(a),h}};Q(Id,"MAX_PATTERN_SIZE",3e3);let $g=Id;function NS({src:o,srcPos:t=0,dest:e,width:s,height:i,nonBlackColor:n=4294967295,inverseDecode:r=!1}){const a=Ue.isLittleEndian?4278190080:255,[h,c]=r?[n,a]:[a,n],u=s>>3,d=s&7,f=o.length;e=new Uint32Array(e.buffer);let g=0;for(let p=0;p<i;p++){for(const y=t+u;t<y;t++){const b=t<f?o[t]:255;e[g++]=b&128?c:h,e[g++]=b&64?c:h,e[g++]=b&32?c:h,e[g++]=b&16?c:h,e[g++]=b&8?c:h,e[g++]=b&4?c:h,e[g++]=b&2?c:h,e[g++]=b&1?c:h}if(d===0)continue;const m=t<f?o[t++]:255;for(let y=0;y<d;y++)e[g++]=m&1<<7-y?c:h}return{srcPos:t,destPos:g}}const Uv=16,Yv=100,BS=15,$v=10,qv=1e3,as=16;function HS(o,t){if(o._removeMirroring)throw new Error("Context is already forwarding operations.");o.__originalSave=o.save,o.__originalRestore=o.restore,o.__originalRotate=o.rotate,o.__originalScale=o.scale,o.__originalTranslate=o.translate,o.__originalTransform=o.transform,o.__originalSetTransform=o.setTransform,o.__originalResetTransform=o.resetTransform,o.__originalClip=o.clip,o.__originalMoveTo=o.moveTo,o.__originalLineTo=o.lineTo,o.__originalBezierCurveTo=o.bezierCurveTo,o.__originalRect=o.rect,o.__originalClosePath=o.closePath,o.__originalBeginPath=o.beginPath,o._removeMirroring=()=>{o.save=o.__originalSave,o.restore=o.__originalRestore,o.rotate=o.__originalRotate,o.scale=o.__originalScale,o.translate=o.__originalTranslate,o.transform=o.__originalTransform,o.setTransform=o.__originalSetTransform,o.resetTransform=o.__originalResetTransform,o.clip=o.__originalClip,o.moveTo=o.__originalMoveTo,o.lineTo=o.__originalLineTo,o.bezierCurveTo=o.__originalBezierCurveTo,o.rect=o.__originalRect,o.closePath=o.__originalClosePath,o.beginPath=o.__originalBeginPath,delete o._removeMirroring},o.save=function(){t.save(),this.__originalSave()},o.restore=function(){t.restore(),this.__originalRestore()},o.translate=function(s,i){t.translate(s,i),this.__originalTranslate(s,i)},o.scale=function(s,i){t.scale(s,i),this.__originalScale(s,i)},o.transform=function(s,i,n,r,a,h){t.transform(s,i,n,r,a,h),this.__originalTransform(s,i,n,r,a,h)},o.setTransform=function(s,i,n,r,a,h){t.setTransform(s,i,n,r,a,h),this.__originalSetTransform(s,i,n,r,a,h)},o.resetTransform=function(){t.resetTransform(),this.__originalResetTransform()},o.rotate=function(s){t.rotate(s),this.__originalRotate(s)},o.clip=function(s){t.clip(s),this.__originalClip(s)},o.moveTo=function(e,s){t.moveTo(e,s),this.__originalMoveTo(e,s)},o.lineTo=function(e,s){t.lineTo(e,s),this.__originalLineTo(e,s)},o.bezierCurveTo=function(e,s,i,n,r,a){t.bezierCurveTo(e,s,i,n,r,a),this.__originalBezierCurveTo(e,s,i,n,r,a)},o.rect=function(e,s,i,n){t.rect(e,s,i,n),this.__originalRect(e,s,i,n)},o.closePath=function(){t.closePath(),this.__originalClosePath()},o.beginPath=function(){t.beginPath(),this.__originalBeginPath()}}class zS{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 _d(o,t,e,s,i,n,r,a,h,c){const[u,d,f,g,p,m]=It(o);if(d===0&&f===0){const x=r*u+p,S=Math.round(x),C=a*g+m,k=Math.round(C),O=(r+h)*u+p,P=Math.abs(Math.round(O)-S)||1,D=(a+c)*g+m,R=Math.abs(Math.round(D)-k)||1;return o.setTransform(Math.sign(u),0,0,Math.sign(g),S,k),o.drawImage(t,e,s,i,n,0,0,P,R),o.setTransform(u,d,f,g,p,m),[P,R]}if(u===0&&g===0){const x=a*f+p,S=Math.round(x),C=r*d+m,k=Math.round(C),O=(a+c)*f+p,P=Math.abs(Math.round(O)-S)||1,D=(r+h)*d+m,R=Math.abs(Math.round(D)-k)||1;return o.setTransform(0,Math.sign(d),Math.sign(f),0,S,k),o.drawImage(t,e,s,i,n,0,0,R,P),o.setTransform(u,d,f,g,p,m),[R,P]}o.drawImage(t,e,s,i,n,r,a,h,c);const y=Math.hypot(u,d),b=Math.hypot(f,g);return[y*h,b*c]}function VS(o){const{width:t,height:e}=o;if(t>qv||e>qv)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)),a,h,c;const u=t+7&-8;let d=new Uint8Array(u*e),f=0;for(const b of o.data){let x=128;for(;x>0;)d[f++]=b&x?0:255,x>>=1}let g=0;for(f=0,d[f]!==0&&(r[0]=1,++g),h=1;h<t;h++)d[f]!==d[f+1]&&(r[h]=d[f]?2:1,++g),f++;for(d[f]!==0&&(r[h]=2,++g),a=1;a<e;a++){f=a*u,c=a*n,d[f-u]!==d[f]&&(r[c]=d[f]?1:8,++g);let b=(d[f]?4:0)+(d[f-u]?8:0);for(h=1;h<t;h++)b=(b>>2)+(d[f+1]?4:0)+(d[f-u+1]?8:0),i[b]&&(r[c+h]=i[b],++g),f++;if(d[f-u]!==d[f]&&(r[c+h]=d[f]?2:4,++g),g>s)return null}for(f=u*(e-1),c=a*n,d[f]!==0&&(r[c]=8,++g),h=1;h<t;h++)d[f]!==d[f+1]&&(r[c+h]=d[f]?4:8,++g),f++;if(d[f]!==0&&(r[c+h]=4,++g),g>s)return null;const p=new Int32Array([0,n,-1,0,-n,0,0,0,1]),m=new Path2D;for(a=0;g&&a<=e;a++){let b=a*n;const x=b+t;for(;b<x&&!r[b];)b++;if(b===x)continue;m.moveTo(b%n,a);const S=b;let C=r[b];do{const k=p[C];do b+=k;while(!r[b]);const O=r[b];O!==5&&O!==10?(C=O,r[b]=0):(C=O&51*C>>4,r[b]&=C>>2|C<<2),m.lineTo(b%n,b/n|0),r[b]||--g}while(S!==b);--a}return d=null,r=null,function(b){b.save(),b.scale(1/t,-1/e),b.translate(0,-e),b.fill(m),b.beginPath(),b.restore()}}class Kv{constructor(t,e){this.alphaIsShape=!1,this.fontSize=0,this.fontSizeScale=1,this.textMatrix=Pv,this.textMatrixScale=1,this.fontMatrix=Eg,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=De.FILL,this.textRise=0,this.fillColor="#000000",this.strokeColor="#000000",this.patternFill=!1,this.patternStroke=!1,this.fillAlpha=1,this.strokeAlpha=1,this.lineWidth=1,this.activeSMask=null,this.transferMaps="none",this.startNewPathAndClipBox([0,0,t,e])}clone(){const t=Object.create(this);return t.clipBox=this.clipBox.slice(),t}setCurrentPoint(t,e){this.x=t,this.y=e}updatePathMinMax(t,e,s){[e,s]=q.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=q.applyTransform(e,t),i=q.applyTransform(e.slice(2),t),n=q.applyTransform([e[0],e[3]],t),r=q.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){q.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,a,h,c,u){const d=q.bezierBoundingBox(e,s,i,n,r,a,h,c,u);u||this.updateRectMinMax(t,d)}getPathBoundingBox(t=Re.FILL,e=null){const s=[this.minX,this.minY,this.maxX,this.maxY];if(t===Re.STROKE){e||kt("Stroke bounding box must include transform.");const i=q.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=q.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=Re.FILL,e=null){return q.intersect(this.clipBox,this.getPathBoundingBox(t,e))}}function Jv(o,t){if(t instanceof ImageData){o.putImageData(t,0,0);return}const e=t.height,s=t.width,i=e%as,n=(e-i)/as,r=i===0?n:n+1,a=o.createImageData(s,as);let h=0,c;const u=t.data,d=a.data;let f,g,p,m;if(t.kind===hd.GRAYSCALE_1BPP){const y=u.byteLength,b=new Uint32Array(d.buffer,0,d.byteLength>>2),x=b.length,S=s+7>>3,C=4294967295,k=Ue.isLittleEndian?4278190080:255;for(f=0;f<r;f++){for(p=f<n?as:i,c=0,g=0;g<p;g++){const O=y-h;let P=0;const D=O>S?s:O*8-7,R=D&-8;let z=0,B=0;for(;P<R;P+=8)B=u[h++],b[c++]=B&128?C:k,b[c++]=B&64?C:k,b[c++]=B&32?C:k,b[c++]=B&16?C:k,b[c++]=B&8?C:k,b[c++]=B&4?C:k,b[c++]=B&2?C:k,b[c++]=B&1?C:k;for(;P<D;P++)z===0&&(B=u[h++],z=128),b[c++]=B&z?C:k,z>>=1}for(;c<x;)b[c++]=0;o.putImageData(a,0,f*as)}}else if(t.kind===hd.RGBA_32BPP){for(g=0,m=s*as*4,f=0;f<n;f++)d.set(u.subarray(h,h+m)),h+=m,o.putImageData(a,0,g),g+=as;f<r&&(m=s*i*4,d.set(u.subarray(h,h+m)),o.putImageData(a,0,g))}else if(t.kind===hd.RGB_24BPP)for(p=as,m=s*p,f=0;f<r;f++){for(f>=n&&(p=i,m=s*p),c=0,g=m;g--;)d[c++]=u[h++],d[c++]=u[h++],d[c++]=u[h++],d[c++]=255;o.putImageData(a,0,f*as)}else throw new Error(`bad image kind: ${t.kind}`)}function Qv(o,t){if(t.bitmap){o.drawImage(t.bitmap,0,0);return}const e=t.height,s=t.width,i=e%as,n=(e-i)/as,r=i===0?n:n+1,a=o.createImageData(s,as);let h=0;const c=t.data,u=a.data;for(let d=0;d<r;d++){const f=d<n?as:i;({srcPos:h}=NS({src:c,srcPos:h,dest:u,width:s,height:f,nonBlackColor:0})),o.putImageData(a,0,d*as)}}function gl(o,t){const e=["strokeStyle","fillStyle","fillRule","globalAlpha","lineWidth","lineCap","lineJoin","miterLimit","globalCompositeOperation","font","filter"];for(const s of e)o[s]!==void 0&&(t[s]=o[s]);o.setLineDash!==void 0&&(t.setLineDash(o.getLineDash()),t.lineDashOffset=o.lineDashOffset)}function wd(o){if(o.strokeStyle=o.fillStyle="#000000",o.fillRule="nonzero",o.globalAlpha=1,o.lineWidth=1,o.lineCap="butt",o.lineJoin="miter",o.miterLimit=10,o.globalCompositeOperation="source-over",o.font="10px sans-serif",o.setLineDash!==void 0&&(o.setLineDash([]),o.lineDashOffset=0),!Oe){const{filter:t}=o;t!=="none"&&t!==""&&(o.filter="none")}}function Zv(o,t){if(t)return!0;const e=q.singularValueDecompose2dScale(o);e[0]=Math.fround(e[0]),e[1]=Math.fround(e[1]);const s=Math.fround((globalThis.devicePixelRatio||1)*Kn.PDF_TO_CSS_UNITS);return e[0]<=s&&e[1]<=s}const WS=["butt","round","square"],GS=["miter","round","bevel"],XS={},tb={},gp=class gp{constructor(t,e,s,i,n,{optionalContentConfig:r,markedContentStack:a=null},h,c){_(this,ui);this.ctx=t,this.current=new Kv(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=a||[],this.optionalContentConfig=r,this.cachedCanvases=new zS(this.canvasFactory),this.cachedPatterns=new Map,this.annotationCanvasMap=h,this.viewportScale=1,this.outputScaleX=1,this.outputScaleY=1,this.pageColors=c,this._cachedScaleForStroking=[-1,0],this._cachedGetSinglePixelWidth=null,this._cachedBitmapsMap=new Map}getObject(t,e=null){return typeof t=="string"?t.startsWith("g_")?this.commonObjs.get(t):this.objs.get(t):e}beginDrawing({transform:t,viewport:e,transparency:s=!1,background:i=null}){const n=this.ctx.canvas.width,r=this.ctx.canvas.height,a=this.ctx.fillStyle;if(this.ctx.fillStyle=i||"#ffffff",this.ctx.fillRect(0,0,n,r),this.ctx.fillStyle=a,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(...It(this.compositeCtx))}this.ctx.save(),wd(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=It(this.ctx)}executeOperatorList(t,e,s,i){const n=t.argsArray,r=t.fnArray;let a=e||0;const h=n.length;if(h===a)return a;const c=h-a>$v&&typeof s=="function",u=c?Date.now()+BS:0;let d=0;const f=this.commonObjs,g=this.objs;let p;for(;;){if(i!==void 0&&a===i.nextBreakPoint)return i.breakIt(a,s),a;if(p=r[a],p!==ni.dependency)this[p].apply(this,n[a]);else for(const m of n[a]){const y=m.startsWith("g_")?f:g;if(!y.has(m))return y.get(m,s),a}if(a++,a===h)return a;if(c&&++d>$v){if(Date.now()>u)return s(),a;d=0}}}endDrawing(){w(this,ui,Vp).call(this),this.cachedCanvases.clear(),this.cachedPatterns.clear();for(const t of this._cachedBitmapsMap.values()){for(const e of t.values())typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement&&(e.width=e.height=0);t.clear()}this._cachedBitmapsMap.clear(),w(this,ui,Wp).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),a=s,h=i,c="prescale1",u,d;for(;n>2&&a>1||r>2&&h>1;){let f=a,g=h;n>2&&a>1&&(f=a>=16384?Math.floor(a/2)-1||1:Math.ceil(a/2),n/=a/f),r>2&&h>1&&(g=h>=16384?Math.floor(h/2)-1||1:Math.ceil(h)/2,r/=h/g),u=this.cachedCanvases.getCanvas(c,f,g),d=u.context,d.clearRect(0,0,f,g),d.drawImage(t,0,0,a,h,0,0,f,g),t=u.canvas,a=f,h=g,c=c==="prescale1"?"prescale2":"prescale1"}return{img:t,paintWidth:a,paintHeight:h}}_createMaskCanvas(t){const e=this.ctx,{width:s,height:i}=t,n=this.current.fillColor,r=this.current.patternFill,a=It(e);let h,c,u,d;if((t.bitmap||t.data)&&t.count>1){const D=t.bitmap||t.data.buffer;c=JSON.stringify(r?a:[a.slice(0,4),n]),h=this._cachedBitmapsMap.get(D),h||(h=new Map,this._cachedBitmapsMap.set(D,h));const R=h.get(c);if(R&&!r){const z=Math.round(Math.min(a[0],a[2])+a[4]),B=Math.round(Math.min(a[1],a[3])+a[5]);return{canvas:R,offsetX:z,offsetY:B}}u=R}u||(d=this.cachedCanvases.getCanvas("maskCanvas",s,i),Qv(d.context,t));let f=q.transform(a,[1/s,0,0,-1/i,0,0]);f=q.transform(f,[1,0,0,1,0,-i]);const[g,p,m,y]=q.getAxialAlignedBoundingBox([0,0,s,i],f),b=Math.round(m-g)||1,x=Math.round(y-p)||1,S=this.cachedCanvases.getCanvas("fillCanvas",b,x),C=S.context,k=g,O=p;C.translate(-k,-O),C.transform(...f),u||(u=this._scaleImage(d.canvas,Ei(C)),u=u.img,h&&r&&h.set(c,u)),C.imageSmoothingEnabled=Zv(It(C),t.interpolate),_d(C,u,0,0,u.width,u.height,0,0,s,i),C.globalCompositeOperation="source-in";const P=q.transform(Ei(C),[1,0,0,1,-k,-O]);return C.fillStyle=r?n.getPattern(e,this,P,Re.FILL):n,C.fillRect(0,0,s,i),h&&!r&&(this.cachedCanvases.delete("fillCanvas"),h.set(c,S.canvas)),{canvas:S.canvas,offsetX:Math.round(k),offsetY:Math.round(O)}}setLineWidth(t){t!==this.current.lineWidth&&(this._cachedScaleForStroking[0]=-1),this.current.lineWidth=t,this.ctx.lineWidth=t}setLineCap(t){this.ctx.lineCap=WS[t]}setLineJoin(t){this.ctx.lineJoin=GS[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(...It(this.suspendedCtx)),gl(this.suspendedCtx,n),HS(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(),gl(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],a=i[2]-n,h=i[3]-r;a===0||h===0||(this.genericComposeSMask(e.context,s,a,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,a,h,c,u,d){let f=t.canvas,g=h-u,p=c-d;if(r){const y=q.makeHexColor(...r);if(g<0||p<0||g+s>f.width||p+i>f.height){const b=this.cachedCanvases.getCanvas("maskExtension",s,i),x=b.context;x.drawImage(f,-g,-p),x.globalCompositeOperation="destination-atop",x.fillStyle=y,x.fillRect(0,0,s,i),x.globalCompositeOperation="source-over",f=b.canvas,g=p=0}else{t.save(),t.globalAlpha=1,t.setTransform(1,0,0,1,0,0);const b=new Path2D;b.rect(g,p,s,i),t.clip(b),t.globalCompositeOperation="destination-atop",t.fillStyle=y,t.fillRect(g,p,s,i),t.restore()}}e.save(),e.globalAlpha=1,e.setTransform(1,0,0,1,0,0),n==="Alpha"&&a?e.filter=this.filterFactory.addAlphaFilter(a):n==="Luminosity"&&(e.filter=this.filterFactory.addLuminosityFilter(a));const m=new Path2D;m.rect(h,c,s,i),e.clip(m),e.globalCompositeOperation="destination-in",e.drawImage(f,g,p,s,i,h,c,s,i),e.restore()}save(){this.inSMaskMode?(gl(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(),gl(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,a=n.y,h,c;const u=It(i),d=u[0]===0&&u[3]===0||u[1]===0&&u[2]===0,f=d?s.slice(0):null;for(let g=0,p=0,m=t.length;g<m;g++)switch(t[g]|0){case ni.rectangle:r=e[p++],a=e[p++];const y=e[p++],b=e[p++],x=r+y,S=a+b;i.moveTo(r,a),y===0||b===0?i.lineTo(x,S):(i.lineTo(x,a),i.lineTo(x,S),i.lineTo(r,S)),d||n.updateRectMinMax(u,[r,a,x,S]),i.closePath();break;case ni.moveTo:r=e[p++],a=e[p++],i.moveTo(r,a),d||n.updatePathMinMax(u,r,a);break;case ni.lineTo:r=e[p++],a=e[p++],i.lineTo(r,a),d||n.updatePathMinMax(u,r,a);break;case ni.curveTo:h=r,c=a,r=e[p+4],a=e[p+5],i.bezierCurveTo(e[p],e[p+1],e[p+2],e[p+3],r,a),n.updateCurvePathMinMax(u,h,c,e[p],e[p+1],e[p+2],e[p+3],r,a,f),p+=6;break;case ni.curveTo2:h=r,c=a,i.bezierCurveTo(r,a,e[p],e[p+1],e[p+2],e[p+3]),n.updateCurvePathMinMax(u,h,c,r,a,e[p],e[p+1],e[p+2],e[p+3],f),r=e[p+2],a=e[p+3],p+=4;break;case ni.curveTo3:h=r,c=a,r=e[p+2],a=e[p+3],i.bezierCurveTo(e[p],e[p+1],r,a,r,a),n.updateCurvePathMinMax(u,h,c,e[p],e[p+1],r,a,r,a,f),p+=4;break;case ni.closePath:i.closePath();break}d&&n.updateScalingPathMinMax(u,f),n.setCurrentPoint(r,a)}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),Re.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),Re.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=XS}eoClip(){this.pendingClip=tb}beginText(){this.current.textMatrix=Pv,this.current.textMatrixScale=1,this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0}endText(){const t=this.pendingTextPaths,e=this.ctx;if(t===void 0){e.beginPath();return}const s=new Path2D,i=e.getTransform().invertSelf();for(const{transform:n,x:r,y:a,fontSize:h,path:c}of t)s.addPath(c,new DOMMatrix(n).preMultiplySelf(i).translate(r,a).scale(h,-h));e.clip(s),e.beginPath(),delete this.pendingTextPaths}setCharSpacing(t){this.current.charSpacing=t}setWordSpacing(t){this.current.wordSpacing=t}setHScale(t){this.current.textHScale=t/100}setLeading(t){this.current.leading=-t}setFont(t,e){var u;const s=this.commonObjs.get(t),i=this.current;if(!s)throw new Error(`Can't find font for ${t}`);if(i.fontMatrix=s.fontMatrix||Eg,(i.fontMatrix[0]===0||i.fontMatrix[3]===0)&&ht("Invalid font matrix for font "+t),e<0?(e=-e,i.fontDirection=-1):i.fontDirection=1,this.current.font=s,this.current.fontSize=e,s.isType3Font)return;const n=s.loadedName||"sans-serif",r=((u=s.systemFontInfo)==null?void 0:u.css)||`"${n}", ${s.fallbackName}`;let a="normal";s.black?a="900":s.bold&&(a="bold");const h=s.italic?"italic":"normal";let c=e;e<Uv?c=Uv:e>Yv&&(c=Yv),this.current.fontSizeScale=e/c,this.ctx.font=`${h} ${a} ${c}px ${r}`}setTextRenderingMode(t){this.current.textRenderingMode=t}setTextRise(t){this.current.textRise=t}moveText(t,e){this.current.x=this.current.lineX+=t,this.current.y=this.current.lineY+=e}setLeadingMoveText(t,e){this.setLeading(-e),this.moveText(t,e)}setTextMatrix(t,e,s,i,n,r){this.current.textMatrix=[t,e,s,i,n,r],this.current.textMatrixScale=Math.hypot(t,e),this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0}nextLine(){this.moveText(0,this.current.leading)}paintChar(t,e,s,i,n){const r=this.ctx,a=this.current,h=a.font,c=a.textRenderingMode,u=a.fontSize/a.fontSizeScale,d=c&De.FILL_STROKE_MASK,f=!!(c&De.ADD_TO_PATH_FLAG),g=a.patternFill&&!h.missingFile,p=a.patternStroke&&!h.missingFile;let m;if((h.disableFontFace||f||g||p)&&(m=h.getPathGenerator(this.commonObjs,t)),h.disableFontFace||g||p){if(r.save(),r.translate(e,s),r.scale(u,-u),d===De.FILL||d===De.FILL_STROKE)if(i){const y=r.getTransform();r.setTransform(...i),r.fill(w(this,ui,Gp).call(this,m,y,i))}else r.fill(m);if(d===De.STROKE||d===De.FILL_STROKE)if(n){const y=r.getTransform();r.setTransform(...n),r.stroke(w(this,ui,Gp).call(this,m,y,n))}else r.lineWidth/=u,r.stroke(m);r.restore()}else(d===De.FILL||d===De.FILL_STROKE)&&r.fillText(t,e,s),(d===De.STROKE||d===De.FILL_STROKE)&&r.strokeText(t,e,s);f&&(this.pendingTextPaths||(this.pendingTextPaths=[])).push({transform:It(r),x:e,y:s,fontSize:u,path:m})}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 ct(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,a=e.charSpacing,h=e.wordSpacing,c=e.fontDirection,u=e.textHScale*c,d=t.length,f=s.vertical,g=f?1:-1,p=s.defaultVMetrics,m=i*e.fontMatrix[0],y=e.textRenderingMode===De.FILL&&!s.disableFontFace&&!e.patternFill;n.save(),n.transform(...e.textMatrix),n.translate(e.x,e.y+e.textRise),c>0?n.scale(u,-1):n.scale(u,1);let b,x;if(e.patternFill){n.save();const P=e.fillColor.getPattern(n,this,Ei(n),Re.FILL);b=It(n),n.restore(),n.fillStyle=P}if(e.patternStroke){n.save();const P=e.strokeColor.getPattern(n,this,Ei(n),Re.STROKE);x=It(n),n.restore(),n.strokeStyle=P}let S=e.lineWidth;const C=e.textMatrixScale;if(C===0||S===0){const P=e.textRenderingMode&De.FILL_STROKE_MASK;(P===De.STROKE||P===De.FILL_STROKE)&&(S=this.getSinglePixelWidth())}else S/=C;if(r!==1&&(n.scale(r,r),S/=r),n.lineWidth=S,s.isInvalidPDFjsFont){const P=[];let D=0;for(const R of t)P.push(R.unicode),D+=R.width;n.fillText(P.join(""),0,0),e.x+=D*m*u,n.restore(),this.compose();return}let k=0,O;for(O=0;O<d;++O){const P=t[O];if(typeof P=="number"){k+=g*P*i/1e3;continue}let D=!1;const R=(P.isSpace?h:0)+a,z=P.fontChar,B=P.accent;let F,L,N=P.width;if(f){const I=P.vmetric||p,V=-(P.vmetric?I[1]:N*.5)*m,it=I[2]*m;N=I?-I[0]:N,F=V/r,L=(k+it)/r}else F=k/r,L=0;if(s.remeasure&&N>0){const I=n.measureText(z).width*1e3/i*r;if(N<I&&this.isFontSubpixelAAEnabled){const V=N/I;D=!0,n.save(),n.scale(V,1),F/=V}else N!==I&&(F+=(N-I)/2e3*i/r)}if(this.contentVisible&&(P.isInFont||s.missingFile)){if(y&&!B)n.fillText(z,F,L);else if(this.paintChar(z,F,L,b,x),B){const I=F+i*B.offset.x/r,V=L-i*B.offset.y/r;this.paintChar(B.fontChar,I,V,b,x)}}const K=f?N*m-R*c:N*m+R*c;k+=K,D&&n.restore()}f?e.y-=k:e.x+=k*u,n.restore(),this.compose()}showType3Text(t){const e=this.ctx,s=this.current,i=s.font,n=s.fontSize,r=s.fontDirection,a=i.vertical?1:-1,h=s.charSpacing,c=s.wordSpacing,u=s.textHScale*r,d=s.fontMatrix||Eg,f=t.length,g=s.textRenderingMode===De.INVISIBLE;let p,m,y,b;if(!(g||n===0)){for(this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null,e.save(),e.transform(...s.textMatrix),e.translate(s.x,s.y),e.scale(u,r),p=0;p<f;++p){if(m=t[p],typeof m=="number"){b=a*m*n/1e3,this.ctx.translate(b,0),s.x+=b*u;continue}const x=(m.isSpace?c:0)+h,S=i.charProcOperatorList[m.operatorListId];if(!S){ht(`Type3 character "${m.operatorListId}" is not available.`);continue}this.contentVisible&&(this.processingType3=m,this.save(),e.scale(n,n),e.transform(...d),this.executeOperatorList(S),this.restore()),y=q.applyTransform([m.width,0],d)[0]*n+x,e.translate(y,0),s.x+=y*u}e.restore(),this.processingType3=null}}setCharWidth(t,e){}setCharWidthAndBounds(t,e,s,i,n,r){this.ctx.rect(s,i,n-s,r-i),this.ctx.clip(),this.endPath()}getColorN_Pattern(t){let e;if(t[0]==="TilingPattern"){const s=t[1],i=this.baseTransform||It(this.ctx),n={createCanvasGraphics:r=>new gp(r,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack})};e=new $g(t,s,this.ctx,n,i)}else e=this._getPattern(t[1],t[2]);return e}setStrokeColorN(){this.current.strokeColor=this.getColorN_Pattern(arguments),this.current.patternStroke=!0}setFillColorN(){this.current.fillColor=this.getColorN_Pattern(arguments),this.current.patternFill=!0}setStrokeRGBColor(t,e,s){this.ctx.strokeStyle=this.current.strokeColor=q.makeHexColor(t,e,s),this.current.patternStroke=!1}setStrokeTransparent(){this.ctx.strokeStyle=this.current.strokeColor="transparent",this.current.patternStroke=!1}setFillRGBColor(t,e,s){this.ctx.fillStyle=this.current.fillColor=q.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=jS(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),Re.SHADING);const i=Ei(e);if(i){const{width:n,height:r}=e.canvas,[a,h,c,u]=q.getAxialAlignedBoundingBox([0,0,n,r],i);this.ctx.fillRect(a,h,c-a,u-h)}else this.ctx.fillRect(-1e10,-1e10,2e10,2e10);this.compose(this.current.getClippedPathBoundingBox()),this.restore()}beginInlineImage(){kt("Should not call beginInlineImage")}beginImageData(){kt("Should not call beginImageData")}paintFormXObjectBegin(t,e){if(this.contentVisible&&(this.save(),this.baseTransformStack.push(this.baseTransform),t&&this.transform(...t),this.baseTransform=It(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(It(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||ud("TODO: Support non-isolated groups."),t.knockout&&ht("Knockout groups not supported.");const s=It(e);if(t.matrix&&e.transform(...t.matrix),!t.bbox)throw new Error("Bounding box is required.");let i=q.getAxialAlignedBoundingBox(t.bbox,It(e));const n=[0,0,e.canvas.width,e.canvas.height];i=q.intersect(i,n)||[0,0,0,0];const r=Math.floor(i[0]),a=Math.floor(i[1]),h=Math.max(Math.ceil(i[2])-r,1),c=Math.max(Math.ceil(i[3])-a,1);this.current.startNewPathAndClipBox([0,0,h,c]);let u="groupAt"+this.groupLevel;t.smask&&(u+="_smask_"+this.smaskCounter++%2);const d=this.cachedCanvases.getCanvas(u,h,c),f=d.context;f.translate(-r,-a),f.transform(...s),t.smask?this.smaskStack.push({canvas:d.canvas,context:f,offsetX:r,offsetY:a,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,a),e.save()),gl(e,f),this.ctx=f,this.setGState([["BM","source-over"],["ca",1],["CA",1]]),this.groupStack.push(e),this.groupLevel++}endGroup(t){if(!this.contentVisible)return;this.groupLevel--;const e=this.ctx,s=this.groupStack.pop();if(this.ctx=s,this.ctx.imageSmoothingEnabled=!1,t.smask)this.tempSMask=this.smaskStack.pop(),this.restore();else{this.ctx.restore();const i=It(this.ctx);this.restore(),this.ctx.save(),this.ctx.setTransform(...i);const n=q.getAxialAlignedBoundingBox([0,0,e.canvas.width,e.canvas.height],i);this.ctx.drawImage(e.canvas,0,0),this.ctx.restore(),this.compose(n)}}beginAnnotation(t,e,s,i,n){if(w(this,ui,Vp).call(this),wd(this.ctx),this.ctx.save(),this.save(),this.baseTransform&&this.ctx.setTransform(...this.baseTransform),e){const r=e[2]-e[0],a=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]=a;const[h,c]=q.singularValueDecompose2dScale(It(this.ctx)),{viewportScale:u}=this,d=Math.ceil(r*this.outputScaleX*u),f=Math.ceil(a*this.outputScaleY*u);this.annotationCanvas=this.canvasFactory.create(d,f);const{canvas:g,context:p}=this.annotationCanvas;this.annotationCanvasMap.set(t,g),this.annotationCanvas.savedCtx=this.ctx,this.ctx=p,this.ctx.save(),this.ctx.setTransform(h,0,0,-c,0,a*c),wd(this.ctx)}else wd(this.ctx),this.endPath(),this.ctx.rect(e[0],e[1],r,a),this.ctx.clip(),this.ctx.beginPath()}this.current=new Kv(this.ctx.canvas.width,this.ctx.canvas.height),this.transform(...s),this.transform(...i)}endAnnotation(){this.annotationCanvas&&(this.ctx.restore(),w(this,ui,Wp).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=VS(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 a=this.ctx;a.save();const h=It(a);a.transform(e,s,i,n,0,0);const c=this._createMaskCanvas(t);a.setTransform(1,0,0,1,c.offsetX-h[4],c.offsetY-h[5]);for(let u=0,d=r.length;u<d;u+=2){const f=q.transform(h,[e,s,i,n,r[u],r[u+1]]),[g,p]=q.applyTransform([0,0],f);a.drawImage(c.canvas,g,p)}a.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:a,height:h,transform:c}=n,u=this.cachedCanvases.getCanvas("maskCanvas",a,h),d=u.context;d.save();const f=this.getObject(r,n);Qv(d,f),d.globalCompositeOperation="source-in",d.fillStyle=i?s.getPattern(d,this,Ei(e),Re.FILL):s,d.fillRect(0,0,a,h),d.restore(),e.save(),e.transform(...c),e.scale(1,-1),_d(e,u.canvas,0,0,a,h,0,-1,1,1),e.restore()}this.compose()}paintImageXObject(t){if(!this.contentVisible)return;const e=this.getObject(t);if(!e){ht("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){ht("Dependent image isn't ready yet");return}const r=n.width,a=n.height,h=[];for(let c=0,u=i.length;c<u;c+=2)h.push({transform:[e,0,0,s,i[c],i[c+1]],x:0,y:0,w:r,h:a});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(),!Oe){const{filter:a}=i;a!=="none"&&a!==""&&(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;Jv(h,t),n=this.applyTransferMapsToCanvas(h)}const r=this._scaleImage(n,Ei(i));i.imageSmoothingEnabled=Zv(It(i),t.interpolate),_d(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;Jv(h,t),i=this.applyTransferMapsToCanvas(h)}for(const n of e)s.save(),s.transform(...n.transform),s.scale(1,-1),_d(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===tb?s.clip("evenodd"):s.clip()),this.pendingClip=null),this.current.startNewPathAndClipBox(this.current.clipBox),s.beginPath()}getSinglePixelWidth(){if(!this._cachedGetSinglePixelWidth){const t=It(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,a;if(s===0&&i===0){const h=Math.abs(e),c=Math.abs(n);if(h===c)if(t===0)r=a=1/h;else{const u=h*t;r=a=u<1?1/u:1}else if(t===0)r=1/h,a=1/c;else{const u=h*t,d=c*t;r=u<1?1/u:1,a=d<1?1/d:1}}else{const h=Math.abs(e*n-s*i),c=Math.hypot(e,s),u=Math.hypot(i,n);if(t===0)r=u/h,a=c/h;else{const d=t*h;r=u>d?u/d:1,a=c>d?c/d:1}}this._cachedScaleForStroking[0]=r,this._cachedScaleForStroking[1]=a}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 a=Math.max(i,n);e.setLineDash(r.map(h=>h/a)),e.lineDashOffset/=a}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}};ui=new WeakSet,Vp=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)},Wp=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}}},Gp=function(t,e,s){const i=new Path2D;return i.addPath(t,new DOMMatrix(s).invertSelf().multiplySelf(e)),i};let To=gp;for(const o in ni)To.prototype[o]!==void 0&&(To.prototype[ni[o]]=To.prototype[o]);class an{static get workerPort(){return l(this,$l)}static set workerPort(t){if(!(typeof Worker<"u"&&t instanceof Worker)&&t!==null)throw new Error("Invalid `workerPort` type.");v(this,$l,t)}static get workerSrc(){return l(this,ql)}static set workerSrc(t){if(typeof t!="string")throw new Error("Invalid `workerSrc` type.");v(this,ql,t)}}$l=new WeakMap,ql=new WeakMap,_(an,$l,null),_(an,ql,"");class US{constructor({parsedData:t,rawData:e}){_(this,wa);_(this,Kl);v(this,wa,t),v(this,Kl,e)}getRaw(){return l(this,Kl)}get(t){return l(this,wa).get(t)??null}getAll(){return Og(l(this,wa))}has(t){return l(this,wa).has(t)}}wa=new WeakMap,Kl=new WeakMap;const Eo=Symbol("INTERNAL");class YS{constructor(t,{name:e,intent:s,usage:i,rbGroups:n}){_(this,Jl,!1);_(this,Ql,!1);_(this,Zl,!1);_(this,Yo,!0);v(this,Jl,!!(t&vs.DISPLAY)),v(this,Ql,!!(t&vs.PRINT)),this.name=e,this.intent=s,this.usage=i,this.rbGroups=n}get visible(){if(l(this,Zl))return l(this,Yo);if(!l(this,Yo))return!1;const{print:t,view:e}=this.usage;return l(this,Jl)?(e==null?void 0:e.viewState)!=="OFF":l(this,Ql)?(t==null?void 0:t.printState)!=="OFF":!0}_setVisible(t,e,s=!1){t!==Eo&&kt("Internal method `_setVisible` called."),v(this,Zl,s),v(this,Yo,e)}}Jl=new WeakMap,Ql=new WeakMap,Zl=new WeakMap,Yo=new WeakMap;class $S{constructor(t,e=vs.DISPLAY){_(this,tc);_(this,ur,null);_(this,At,new Map);_(this,$o,null);_(this,qo,null);if(this.renderingIntent=e,this.name=null,this.creator=null,t!==null){this.name=t.name,this.creator=t.creator,v(this,qo,t.order);for(const s of t.groups)l(this,At).set(s.id,new YS(e,s));if(t.baseState==="OFF")for(const s of l(this,At).values())s._setVisible(Eo,!1);for(const s of t.on)l(this,At).get(s)._setVisible(Eo,!0);for(const s of t.off)l(this,At).get(s)._setVisible(Eo,!1);v(this,$o,this.getHash())}}isVisible(t){if(l(this,At).size===0)return!0;if(!t)return ud("Optional content group not defined."),!0;if(t.type==="OCG")return l(this,At).has(t.id)?l(this,At).get(t.id).visible:(ht(`Optional content group not found: ${t.id}`),!0);if(t.type==="OCMD"){if(t.expression)return w(this,tc,Xp).call(this,t.expression);if(!t.policy||t.policy==="AnyOn"){for(const e of t.ids){if(!l(this,At).has(e))return ht(`Optional content group not found: ${e}`),!0;if(l(this,At).get(e).visible)return!0}return!1}else if(t.policy==="AllOn"){for(const e of t.ids){if(!l(this,At).has(e))return ht(`Optional content group not found: ${e}`),!0;if(!l(this,At).get(e).visible)return!1}return!0}else if(t.policy==="AnyOff"){for(const e of t.ids){if(!l(this,At).has(e))return ht(`Optional content group not found: ${e}`),!0;if(!l(this,At).get(e).visible)return!0}return!1}else if(t.policy==="AllOff"){for(const e of t.ids){if(!l(this,At).has(e))return ht(`Optional content group not found: ${e}`),!0;if(l(this,At).get(e).visible)return!1}return!0}return ht(`Unknown optional content policy ${t.policy}.`),!0}return ht(`Unknown group type ${t.type}.`),!0}setVisibility(t,e=!0,s=!0){var n;const i=l(this,At).get(t);if(!i){ht(`Optional content group not found: ${t}`);return}if(s&&e&&i.rbGroups.length)for(const r of i.rbGroups)for(const a of r)a!==t&&((n=l(this,At).get(a))==null||n._setVisible(Eo,!1,!0));i._setVisible(Eo,!!e,!0),v(this,ur,null)}setOCGState({state:t,preserveRB:e}){let s;for(const i of t){switch(i){case"ON":case"OFF":case"Toggle":s=i;continue}const n=l(this,At).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}}v(this,ur,null)}get hasInitialVisibility(){return l(this,$o)===null||this.getHash()===l(this,$o)}getOrder(){return l(this,At).size?l(this,qo)?l(this,qo).slice():[...l(this,At).keys()]:null}getGroups(){return l(this,At).size>0?Og(l(this,At)):null}getGroup(t){return l(this,At).get(t)||null}getHash(){if(l(this,ur)!==null)return l(this,ur);const t=new Lv;for(const[e,s]of l(this,At))t.update(`${e}:${s.visible}`);return v(this,ur,t.hexdigest())}}ur=new WeakMap,At=new WeakMap,$o=new WeakMap,qo=new WeakMap,tc=new WeakSet,Xp=function(t){const e=t.length;if(e<2)return!0;const s=t[0];for(let i=1;i<e;i++){const n=t[i];let r;if(Array.isArray(n))r=w(this,tc,Xp).call(this,n);else if(l(this,At).has(n))r=l(this,At).get(n).visible;else return ht(`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 qS{constructor(t,{disableRange:e=!1,disableStream:s=!1}){ie(t,'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');const{length:i,initialData:n,progressiveDone:r,contentDispositionFilename:a}=t;if(this._queuedChunks=[],this._progressiveDone=r,this._contentDispositionFilename=a,(n==null?void 0:n.length)>0){const h=n instanceof Uint8Array&&n.byteLength===n.buffer.byteLength?n.buffer:new Uint8Array(n).buffer;this._queuedChunks.push(h)}this._pdfDataRangeTransport=t,this._isStreamingSupported=!s,this._isRangeSupported=!e,this._contentLength=i,this._fullRequestReader=null,this._rangeReaders=[],t.addRangeListener((h,c)=>{this._onReceiveData({begin:h,chunk:c})}),t.addProgressListener((h,c)=>{this._onProgress({loaded:h,total:c})}),t.addProgressiveReadListener(h=>{this._onReceiveData({chunk:h})}),t.addProgressiveDoneListener(()=>{this._onProgressiveDone()}),t.transportReady()}_onReceiveData({begin:t,chunk:e}){const s=e instanceof Uint8Array&&e.byteLength===e.buffer.byteLength?e.buffer:new Uint8Array(e).buffer;if(t===void 0)this._fullRequestReader?this._fullRequestReader._enqueue(s):this._queuedChunks.push(s);else{const i=this._rangeReaders.some(function(n){return n._begin!==t?!1:(n._enqueue(s),!0)});ie(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(){ie(!this._fullRequestReader,"PDFDataTransportStream.getFullReader can only be called once.");const t=this._queuedChunks;return this._queuedChunks=null,new KS(this,t,this._progressiveDone,this._contentDispositionFilename)}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new JS(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 KS{constructor(t,e,s=!1,i=null){this._stream=t,this._done=s||!1,this._filename=Ig(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 JS{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 QS(o){let t=!0,e=s("filename\\*","i").exec(o);if(e){e=e[1];let u=a(e);return u=unescape(u),u=h(u),u=c(u),n(u)}if(e=r(o),e){const u=c(e);return n(u)}if(e=s("filename","i").exec(o),e){e=e[1];let u=a(e);return u=c(u),n(u)}function s(u,d){return new RegExp("(?:^|;)\\s*"+u+'\\s*=\\s*([^";\\s][^;\\s]*|"(?:[^"\\\\]|\\\\"?)+"?)',d)}function i(u,d){if(u){if(!/^[\x00-\xFF]+$/.test(d))return d;try{const f=new TextDecoder(u,{fatal:!0}),g=fd(d);d=f.decode(g),t=!1}catch{}}return d}function n(u){return t&&/[\x80-\xff]/.test(u)&&(u=i("utf-8",u),t&&(u=i("iso-8859-1",u))),u}function r(u){const d=[];let f;const g=s("filename\\*((?!0\\d)\\d+)(\\*?)","ig");for(;(f=g.exec(u))!==null;){let[,m,y,b]=f;if(m=parseInt(m,10),m in d){if(m===0)break;continue}d[m]=[y,b]}const p=[];for(let m=0;m<d.length&&m in d;++m){let[y,b]=d[m];b=a(b),y&&(b=unescape(b),m===0&&(b=h(b))),p.push(b)}return p.join("")}function a(u){if(u.startsWith('"')){const d=u.slice(1).split('\\"');for(let f=0;f<d.length;++f){const g=d[f].indexOf('"');g!==-1&&(d[f]=d[f].slice(0,g),d.length=f+1),d[f]=d[f].replaceAll(/\\(.)/g,"$1")}u=d.join('"')}return u}function h(u){const d=u.indexOf("'");if(d===-1)return u;const f=u.slice(0,d),p=u.slice(d+1).replace(/^[^']*'/,"");return i(f,p)}function c(u){return!u.startsWith("=?")||/[\x00-\x19\x80-\xff]/.test(u)?u:u.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,function(d,f,g,p){if(g==="q"||g==="Q")return p=p.replaceAll("_"," "),p=p.replaceAll(/=([0-9a-fA-F]{2})/g,function(m,y){return String.fromCharCode(parseInt(y,16))}),i(f,p);try{p=atob(p)}catch{}return i(f,p)})}return""}function eb(o,t){const e=new Headers;if(!o||!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 xd(o){try{return new URL(o).origin}catch{}return null}function sb({responseHeaders:o,isHttp:t,rangeChunkSize:e,disableRange:s}){const i={allowRangeRequests:!1,suggestedLength:void 0},n=parseInt(o.get("Content-Length"),10);return!Number.isInteger(n)||(i.suggestedLength=n,n<=2*e)||s||!t||o.get("Accept-Ranges")!=="bytes"||(o.get("Content-Encoding")||"identity")!=="identity"||(i.allowRangeRequests=!0),i}function ib(o){const t=o.get("Content-Disposition");if(t){let e=QS(t);if(e.includes("%"))try{e=decodeURIComponent(e)}catch{}if(Ig(e))return e}return null}function Sd(o,t){return o===404||o===0&&t.startsWith("file:")?new ll('Missing PDF "'+t+'".'):new dd(`Unexpected server response (${o}) while retrieving PDF "${t}".`,o)}function nb(o){return o===200||o===206}function rb(o,t,e){return{method:"GET",headers:o,signal:e.signal,mode:"cors",credentials:t?"include":"same-origin",redirect:"follow"}}function ab(o){return o instanceof Uint8Array?o.buffer:o instanceof ArrayBuffer?o:(ht(`getArrayBuffer - unexpected data format: ${o}`),new Uint8Array(o).buffer)}class ob{constructor(t){Q(this,"_responseOrigin",null);this.source=t,this.isHttp=/^https?:/i.test(t.url),this.headers=eb(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 ie(!this._fullRequestReader,"PDFFetchStream.getFullReader can only be called once."),this._fullRequestReader=new ZS(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new tC(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 ZS{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,rb(s,this._withCredentials,this._abortController)).then(n=>{if(t._responseOrigin=xd(n.url),!nb(n.status))throw Sd(n.status,i);this._reader=n.body.getReader(),this._headersCapability.resolve();const r=n.headers,{allowRangeRequests:a,suggestedLength:h}=sb({responseHeaders:r,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=a,this._contentLength=h||this._contentLength,this._filename=ib(r),!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new qn("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:ab(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}class tC{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,rb(n,this._withCredentials,this._abortController)).then(a=>{const h=xd(a.url);if(h!==t._responseOrigin)throw new Error(`Expected range response-origin "${h}" to match "${t._responseOrigin}".`);if(!nb(a.status))throw Sd(a.status,r);this._readCapability.resolve(),this._reader=a.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:ab(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}const qg=200,Kg=206;function eC(o){const t=o.response;return typeof t!="string"?t:fd(t).buffer}class sC{constructor({url:t,httpHeaders:e,withCredentials:s}){Q(this,"_responseOrigin",null);this.url=t,this.isHttp=/^https?:/i.test(t),this.headers=eb(this.isHttp,e),this.withCredentials=s||!1,this.currXhrId=0,this.pendingRequests=Object.create(null)}request(t){const e=new XMLHttpRequest,s=this.currXhrId++,i=this.pendingRequests[s]={xhr:e};e.open("GET",this.url),e.withCredentials=this.withCredentials;for(const[n,r]of this.headers)e.setRequestHeader(n,r);return this.isHttp&&"begin"in t&&"end"in t?(e.setRequestHeader("Range",`bytes=${t.begin}-${t.end-1}`),i.expectedStatus=Kg):i.expectedStatus=qg,e.responseType="arraybuffer",ie(t.onError,"Expected `onError` callback to be provided."),e.onerror=()=>{t.onError(e.status)},e.onreadystatechange=this.onStateChange.bind(this,s),e.onprogress=this.onProgress.bind(this,s),i.onHeadersReceived=t.onHeadersReceived,i.onDone=t.onDone,i.onError=t.onError,i.onProgress=t.onProgress,e.send(null),s}onProgress(t,e){var i;const s=this.pendingRequests[t];s&&((i=s.onProgress)==null||i.call(s,e))}onStateChange(t,e){const s=this.pendingRequests[t];if(!s)return;const i=s.xhr;if(i.readyState>=2&&s.onHeadersReceived&&(s.onHeadersReceived(),delete s.onHeadersReceived),i.readyState!==4||!(t in this.pendingRequests))return;if(delete this.pendingRequests[t],i.status===0&&this.isHttp){s.onError(i.status);return}const n=i.status||qg;if(!(n===qg&&s.expectedStatus===Kg)&&n!==s.expectedStatus){s.onError(i.status);return}const a=eC(i);if(n===Kg){const h=i.getResponseHeader("Content-Range"),c=/bytes (\d+)-(\d+)\/(\d+)/.exec(h);c?s.onDone({begin:parseInt(c[1],10),chunk:a}):(ht('Missing or invalid "Content-Range" header.'),s.onError(0))}else a?s.onDone({begin:0,chunk:a}):s.onError(i.status)}getRequestXhr(t){return this.pendingRequests[t].xhr}isPendingRequest(t){return t in this.pendingRequests}abortRequest(t){const e=this.pendingRequests[t].xhr;delete this.pendingRequests[t],e.abort()}}class iC{constructor(t){this._source=t,this._manager=new sC(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 ie(!this._fullRequestReader,"PDFNetworkStream.getFullReader can only be called once."),this._fullRequestReader=new nC(this._manager,this._source),this._fullRequestReader}getRangeReader(t,e){const s=new rC(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 nC{constructor(t,e){this._manager=t,this._url=e.url,this._fullRequestId=t.request({onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)}),this._headersCapability=Promise.withResolvers(),this._disableRange=e.disableRange||!1,this._contentLength=e.length,this._rangeChunkSize=e.rangeChunkSize,!this._rangeChunkSize&&!this._disableRange&&(this._disableRange=!0),this._isStreamingSupported=!1,this._isRangeSupported=!1,this._cachedChunks=[],this._requests=[],this._done=!1,this._storedError=void 0,this._filename=null,this.onProgress=null}_onHeadersReceived(){const t=this._fullRequestId,e=this._manager.getRequestXhr(t);this._manager._responseOrigin=xd(e.responseURL);const s=e.getAllResponseHeaders(),i=new Headers(s?s.trimStart().replace(/[^\S ]+$/,"").split(/[\r\n]+/).map(a=>{const[h,...c]=a.split(": ");return[h,c.join(": ")]}):[]),{allowRangeRequests:n,suggestedLength:r}=sb({responseHeaders:i,isHttp:this._manager.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});n&&(this._isRangeSupported=!0),this._contentLength=r||this._contentLength,this._filename=ib(i),this._isRangeSupported&&this._manager.abortRequest(t),this._headersCapability.resolve()}_onDone(t){if(t&&(this._requests.length>0?this._requests.shift().resolve({value:t.chunk,done:!1}):this._cachedChunks.push(t.chunk)),this._done=!0,!(this._cachedChunks.length>0)){for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}}_onError(t){this._storedError=Sd(t,this._url),this._headersCapability.reject(this._storedError);for(const e of this._requests)e.reject(this._storedError);this._requests.length=0,this._cachedChunks.length=0}_onProgress(t){var e;(e=this.onProgress)==null||e.call(this,{loaded:t.loaded,total:t.lengthComputable?t.total:this._contentLength})}get filename(){return this._filename}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}get contentLength(){return this._contentLength}get headersReady(){return this._headersCapability.promise}async read(){if(await this._headersCapability.promise,this._storedError)throw this._storedError;if(this._cachedChunks.length>0)return{value:this._cachedChunks.shift(),done:!1};if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0,this._headersCapability.reject(t);for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._manager.isPendingRequest(this._fullRequestId)&&this._manager.abortRequest(this._fullRequestId),this._fullRequestReader=null}}class rC{constructor(t,e,s){this._manager=t,this._url=t.url,this._requestId=t.request({begin:e,end:s,onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)}),this._requests=[],this._queuedChunk=null,this._done=!1,this._storedError=void 0,this.onProgress=null,this.onClosed=null}_onHeadersReceived(){var e;const t=xd((e=this._manager.getRequestXhr(this._requestId))==null?void 0:e.responseURL);t!==this._manager._responseOrigin&&(this._storedError=new Error(`Expected range response-origin "${t}" to match "${this._manager._responseOrigin}".`),this._onError(0))}_close(){var t;(t=this.onClosed)==null||t.call(this,this)}_onDone(t){const e=t.chunk;this._requests.length>0?this._requests.shift().resolve({value:e,done:!1}):this._queuedChunk=e,this._done=!0;for(const s of this._requests)s.resolve({value:void 0,done:!0});this._requests.length=0,this._close()}_onError(t){this._storedError??(this._storedError=Sd(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 aC=/^[a-z][a-z0-9\-+.]+:/i;function oC(o){if(aC.test(o))return new URL(o);const t=process.getBuiltinModule("url");return new URL(t.pathToFileURL(o))}class hC{constructor(t){this.source=t,this.url=oC(t.url),ie(this.url.protocol==="file:","PDFNodeStream only supports file:// URLs."),this._fullRequestReader=null,this._rangeRequestReaders=[]}get _progressiveDataLength(){var t;return((t=this._fullRequestReader)==null?void 0:t._loaded)??0}getFullReader(){return ie(!this._fullRequestReader,"PDFNodeStream.getFullReader can only be called once."),this._fullRequestReader=new lC(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new cC(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 lC{constructor(t){this._url=t.url,this._done=!1,this._storedError=null,this.onProgress=null;const e=t.source;this._contentLength=e.length,this._loaded=0,this._filename=null,this._disableRange=e.disableRange||!1,this._rangeChunkSize=e.rangeChunkSize,!this._rangeChunkSize&&!this._disableRange&&(this._disableRange=!0),this._isStreamingSupported=!e.disableStream,this._isRangeSupported=!e.disableRange,this._readableStream=null,this._readCapability=Promise.withResolvers(),this._headersCapability=Promise.withResolvers();const s=process.getBuiltinModule("fs");s.promises.lstat(this._url).then(i=>{this._contentLength=i.size,this._setReadableStream(s.createReadStream(this._url)),this._headersCapability.resolve()},i=>{i.code==="ENOENT"&&(i=new ll(`Missing PDF "${this._url}".`)),this._storedError=i,this._headersCapability.reject(i)})}get headersReady(){return this._headersCapability.promise}get filename(){return this._filename}get contentLength(){return this._contentLength}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;if(await this._readCapability.promise,this._done)return{value:void 0,done:!0};if(this._storedError)throw this._storedError;const t=this._readableStream.read();return t===null?(this._readCapability=Promise.withResolvers(),this.read()):(this._loaded+=t.length,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded,total:this._contentLength}),{value:new Uint8Array(t).buffer,done:!1})}cancel(t){if(!this._readableStream){this._error(t);return}this._readableStream.destroy(t)}_error(t){this._storedError=t,this._readCapability.resolve()}_setReadableStream(t){this._readableStream=t,t.on("readable",()=>{this._readCapability.resolve()}),t.on("end",()=>{t.destroy(),this._done=!0,this._readCapability.resolve()}),t.on("error",e=>{this._error(e)}),!this._isStreamingSupported&&this._isRangeSupported&&this._error(new qn("streaming is disabled")),this._storedError&&this._readableStream.destroy(this._storedError)}}class cC{constructor(t,e,s){this._url=t.url,this._done=!1,this._storedError=null,this.onProgress=null,this._loaded=0,this._readableStream=null,this._readCapability=Promise.withResolvers();const i=t.source;this._isStreamingSupported=!i.disableStream;const n=process.getBuiltinModule("fs");this._setReadableStream(n.createReadStream(this._url,{start:e,end:s-1}))}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;if(await this._readCapability.promise,this._done)return{value:void 0,done:!0};if(this._storedError)throw this._storedError;const t=this._readableStream.read();return t===null?(this._readCapability=Promise.withResolvers(),this.read()):(this._loaded+=t.length,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded}),{value:new Uint8Array(t).buffer,done:!1})}cancel(t){if(!this._readableStream){this._error(t);return}this._readableStream.destroy(t)}_error(t){this._storedError=t,this._readCapability.resolve()}_setReadableStream(t){this._readableStream=t,t.on("readable",()=>{this._readCapability.resolve()}),t.on("end",()=>{t.destroy(),this._done=!0,this._readCapability.resolve()}),t.on("error",e=>{this._error(e)}),this._storedError&&this._readableStream.destroy(this._storedError)}}const uC=1e5,os=30,dC=.8,ue=class ue{constructor({textContentSource:t,container:e,viewport:s}){_(this,_n);_(this,dr,Promise.withResolvers());_(this,cs,null);_(this,ec,!1);_(this,sc,!!((Eb=globalThis.FontInspector)!=null&&Eb.enabled));_(this,xa,null);_(this,yn,null);_(this,ic,0);_(this,nc,0);_(this,Sa,null);_(this,Ko,null);_(this,Jo,0);_(this,fr,0);_(this,Qo,Object.create(null));_(this,rc,[]);_(this,Zo,null);_(this,Ca,[]);_(this,ac,new WeakMap);_(this,oc,null);var h;if(t instanceof ReadableStream)v(this,Zo,t);else if(typeof t=="object")v(this,Zo,new ReadableStream({start(c){c.enqueue(t),c.close()}}));else throw new Error('No "textContentSource" parameter specified.');v(this,cs,v(this,Ko,e)),v(this,fr,s.scale*(globalThis.devicePixelRatio||1)),v(this,Jo,s.rotation),v(this,yn,{div:null,properties:null,ctx:null});const{pageWidth:i,pageHeight:n,pageX:r,pageY:a}=s.rawDims;v(this,oc,[1,0,0,-1,-r,a+n]),v(this,nc,i),v(this,ic,n),w(h=ue,xs,Ay).call(h),Yr(e,s),l(this,dr).promise.finally(()=>{l(ue,th).delete(this),v(this,yn,null),v(this,Qo,null)}).catch(()=>{})}static get fontFamilyMap(){const{isWindows:t,isFirefox:e}=Ue.platform;return ct(this,"fontFamilyMap",new Map([["sans-serif",`${t&&e?"Calibri, ":""}sans-serif`],["monospace",`${t&&e?"Lucida Console, ":""}monospace`]]))}render(){const t=()=>{l(this,Sa).read().then(({value:e,done:s})=>{if(s){l(this,dr).resolve();return}l(this,xa)??v(this,xa,e.lang),Object.assign(l(this,Qo),e.styles),w(this,_n,Sy).call(this,e.items),t()},l(this,dr).reject)};return v(this,Sa,l(this,Zo).getReader()),l(ue,th).add(this),t(),l(this,dr).promise}update({viewport:t,onBefore:e=null}){var n;const s=t.scale*(globalThis.devicePixelRatio||1),i=t.rotation;if(i!==l(this,Jo)&&(e==null||e(),v(this,Jo,i),Yr(l(this,Ko),{rotation:i})),s!==l(this,fr)){e==null||e(),v(this,fr,s);const r={div:null,properties:null,ctx:w(n=ue,xs,lf).call(n,l(this,xa))};for(const a of l(this,Ca))r.properties=l(this,ac).get(a),r.div=a,w(this,_n,Up).call(this,r)}}cancel(){var e;const t=new qn("TextLayer task cancelled.");(e=l(this,Sa))==null||e.cancel(t).catch(()=>{}),v(this,Sa,null),l(this,dr).reject(t)}get textDivs(){return l(this,Ca)}get textContentItemsStr(){return l(this,rc)}static cleanup(){if(!(l(this,th).size>0)){l(this,Aa).clear();for(const{canvas:t}of l(this,Ta).values())t.remove();l(this,Ta).clear()}}};dr=new WeakMap,cs=new WeakMap,ec=new WeakMap,sc=new WeakMap,xa=new WeakMap,yn=new WeakMap,ic=new WeakMap,nc=new WeakMap,Sa=new WeakMap,Ko=new WeakMap,Jo=new WeakMap,fr=new WeakMap,Qo=new WeakMap,rc=new WeakMap,Zo=new WeakMap,Ca=new WeakMap,ac=new WeakMap,oc=new WeakMap,Aa=new WeakMap,Ta=new WeakMap,hc=new WeakMap,gr=new WeakMap,th=new WeakMap,_n=new WeakSet,Sy=function(t){var i,n;if(l(this,ec))return;(n=l(this,yn)).ctx??(n.ctx=w(i=ue,xs,lf).call(i,l(this,xa)));const e=l(this,Ca),s=l(this,rc);for(const r of t){if(e.length>uC){ht("Ignoring additional textDivs for performance reasons."),v(this,ec,!0);return}if(r.str===void 0){if(r.type==="beginMarkedContentProps"||r.type==="beginMarkedContent"){const a=l(this,cs);v(this,cs,document.createElement("span")),l(this,cs).classList.add("markedContent"),r.id!==null&&l(this,cs).setAttribute("id",`${r.id}`),a.append(l(this,cs))}else r.type==="endMarkedContent"&&v(this,cs,l(this,cs).parentNode);continue}s.push(r.str),w(this,_n,Cy).call(this,r)}},Cy=function(t){var m;const e=document.createElement("span"),s={angle:0,canvasWidth:0,hasText:t.str!=="",hasEOL:t.hasEOL,fontSize:0};l(this,Ca).push(e);const i=q.transform(l(this,oc),t.transform);let n=Math.atan2(i[1],i[0]);const r=l(this,Qo)[t.fontName];r.vertical&&(n+=Math.PI/2);let a=l(this,sc)&&r.fontSubstitution||r.fontFamily;a=ue.fontFamilyMap.get(a)||a;const h=Math.hypot(i[2],i[3]),c=h*w(m=ue,xs,Ty).call(m,a,l(this,xa));let u,d;n===0?(u=i[4],d=i[5]-c):(u=i[4]+c*Math.sin(n),d=i[5]-c*Math.cos(n));const f="calc(var(--scale-factor)*",g=e.style;l(this,cs)===l(this,Ko)?(g.left=`${(100*u/l(this,nc)).toFixed(2)}%`,g.top=`${(100*d/l(this,ic)).toFixed(2)}%`):(g.left=`${f}${u.toFixed(2)}px)`,g.top=`${f}${d.toFixed(2)}px)`),g.fontSize=`${f}${(l(ue,gr)*h).toFixed(2)}px)`,g.fontFamily=a,s.fontSize=h,e.setAttribute("role","presentation"),e.textContent=t.str,e.dir=t.dir,l(this,sc)&&(e.dataset.fontName=r.fontSubstitutionLoadedName||t.fontName),n!==0&&(s.angle=n*(180/Math.PI));let p=!1;if(t.str.length>1)p=!0;else if(t.str!==" "&&t.transform[0]!==t.transform[3]){const y=Math.abs(t.transform[0]),b=Math.abs(t.transform[3]);y!==b&&Math.max(y,b)/Math.min(y,b)>1.5&&(p=!0)}if(p&&(s.canvasWidth=r.vertical?t.height:t.width),l(this,ac).set(e,s),l(this,yn).div=e,l(this,yn).properties=s,w(this,_n,Up).call(this,l(this,yn)),s.hasText&&l(this,cs).append(e),s.hasEOL){const y=document.createElement("br");y.setAttribute("role","presentation"),l(this,cs).append(y)}},Up=function(t){var a;const{div:e,properties:s,ctx:i}=t,{style:n}=e;let r="";if(l(ue,gr)>1&&(r=`scale(${1/l(ue,gr)})`),s.canvasWidth!==0&&s.hasText){const{fontFamily:h}=n,{canvasWidth:c,fontSize:u}=s;w(a=ue,xs,Yp).call(a,i,u*l(this,fr),h);const{width:d}=i.measureText(e.textContent);d>0&&(r=`scaleX(${c*l(this,fr)/d}) ${r}`)}s.angle!==0&&(r=`rotate(${s.angle}deg) ${r}`),r.length>0&&(n.transform=r)},xs=new WeakSet,lf=function(t=null){let e=l(this,Ta).get(t||(t=""));if(!e){const s=document.createElement("canvas");s.className="hiddenCanvasElement",s.lang=t,document.body.append(s),e=s.getContext("2d",{alpha:!1,willReadFrequently:!0}),l(this,Ta).set(t,e),l(this,hc).set(e,{size:0,family:""})}return e},Yp=function(t,e,s){const i=l(this,hc).get(t);e===i.size&&s===i.family||(t.font=`${e}px ${s}`,i.size=e,i.family=s)},Ay=function(){if(l(this,gr)!==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),v(this,gr,t.getBoundingClientRect().height),t.remove()},Ty=function(t,e){const s=l(this,Aa).get(t);if(s)return s;const i=w(this,xs,lf).call(this,e);i.canvas.width=i.canvas.height=os,w(this,xs,Yp).call(this,i,os,t);const n=i.measureText("");let r=n.fontBoundingBoxAscent,a=Math.abs(n.fontBoundingBoxDescent);if(r){const u=r/(r+a);return l(this,Aa).set(t,u),i.canvas.width=i.canvas.height=0,u}i.strokeStyle="red",i.clearRect(0,0,os,os),i.strokeText("g",0,0);let h=i.getImageData(0,0,os,os).data;a=0;for(let u=h.length-1-3;u>=0;u-=4)if(h[u]>0){a=Math.ceil(u/4/os);break}i.clearRect(0,0,os,os),i.strokeText("A",0,os),h=i.getImageData(0,0,os,os).data,r=0;for(let u=0,d=h.length;u<d;u+=4)if(h[u]>0){r=os-Math.floor(u/4/os);break}i.canvas.width=i.canvas.height=0;const c=r?r/(r+a):dC;return l(this,Aa).set(t,c),c},_(ue,xs),_(ue,Aa,new Map),_(ue,Ta,new Map),_(ue,hc,new WeakMap),_(ue,gr,null),_(ue,th,new Set);let pl=ue;class ml{static textContent(t){const e=[],s={items:e,styles:Object.create(null)};function i(n){var h;if(!n)return;let r=null;const a=n.name;if(a==="#text")r=n.value;else if(ml.shouldBuildText(a))(h=n==null?void 0:n.attributes)!=null&&h.textContent?r=n.attributes.textContent:n.value&&(r=n.value);else return;if(r!==null&&e.push({str:r}),!!n.children)for(const c of n.children)i(c)}return i(t),s}static shouldBuildText(t){return!(t==="textarea"||t==="input"||t==="option"||t==="select")}}const fC=65536,gC=100,pC=5e3,mC=Oe?MS:ES,vC=Oe?OS:Hv,bC=Oe?PS:kS,yC=Oe?DS:Wv;function _C(o={}){typeof o=="string"||o instanceof URL?o={url:o}:(o instanceof ArrayBuffer||ArrayBuffer.isView(o))&&(o={data:o});const t=new Jg,{docId:e}=t,s=o.url?wC(o.url):null,i=o.data?xC(o.data):null,n=o.httpHeaders||null,r=o.withCredentials===!0,a=o.password??null,h=o.range instanceof lb?o.range:null,c=Number.isInteger(o.rangeChunkSize)&&o.rangeChunkSize>0?o.rangeChunkSize:fC;let u=o.worker instanceof ko?o.worker:null;const d=o.verbosity,f=typeof o.docBaseUrl=="string"&&!pd(o.docBaseUrl)?o.docBaseUrl:null,g=typeof o.cMapUrl=="string"?o.cMapUrl:null,p=o.cMapPacked!==!1,m=o.CMapReaderFactory||vC,y=typeof o.standardFontDataUrl=="string"?o.standardFontDataUrl:null,b=o.StandardFontDataFactory||yC,x=o.stopAtErrors!==!0,S=Number.isInteger(o.maxImageSize)&&o.maxImageSize>-1?o.maxImageSize:-1,C=o.isEvalSupported!==!1,k=typeof o.isOffscreenCanvasSupported=="boolean"?o.isOffscreenCanvasSupported:!Oe,O=typeof o.isImageDecoderSupported=="boolean"?o.isImageDecoderSupported:!Oe&&(Ue.platform.isFirefox||!globalThis.chrome),P=Number.isInteger(o.canvasMaxAreaInBytes)?o.canvasMaxAreaInBytes:-1,D=typeof o.disableFontFace=="boolean"?o.disableFontFace:Oe,R=o.fontExtraProperties===!0,z=o.enableXfa===!0,B=o.ownerDocument||globalThis.document,F=o.disableRange===!0,L=o.disableStream===!0,N=o.disableAutoFetch===!0,K=o.pdfBug===!0,I=o.CanvasFactory||mC,V=o.FilterFactory||bC,it=o.enableHWA===!0,Ot=h?h.length:o.length??NaN,Bt=typeof o.useSystemFonts=="boolean"?o.useSystemFonts:!Oe&&!D,Xt=typeof o.useWorkerFetch=="boolean"?o.useWorkerFetch:m===Hv&&b===Wv&&g&&y&&ul(g,document.baseURI)&&ul(y,document.baseURI),Ft=null;rS(d);const _t={canvasFactory:new I({ownerDocument:B,enableHWA:it}),filterFactory:new V({docId:e,ownerDocument:B}),cMapReaderFactory:Xt?null:new m({baseUrl:g,isCompressed:p}),standardFontDataFactory:Xt?null:new b({baseUrl:y})};if(!u){const st={verbosity:d,port:an.workerPort};u=st.port?ko.fromPort(st):new ko(st),t._worker=u}const ae={docId:e,apiVersion:"4.10.38",data:i,password:a,disableAutoFetch:N,rangeChunkSize:c,length:Ot,docBaseUrl:f,enableXfa:z,evaluatorOptions:{maxImageSize:S,disableFontFace:D,ignoreErrors:x,isEvalSupported:C,isOffscreenCanvasSupported:k,isImageDecoderSupported:O,canvasMaxAreaInBytes:P,fontExtraProperties:R,useSystemFonts:Bt,cMapUrl:Xt?g:null,standardFontDataUrl:Xt?y:null}},Ze={disableFontFace:D,fontExtraProperties:R,ownerDocument:B,pdfBug:K,styleElement:Ft,loadingParams:{disableAutoFetch:N,enableXfa:z}};return u.promise.then(function(){if(t.destroyed)throw new Error("Loading aborted");if(u.destroyed)throw new Error("Worker was destroyed");const st=u.messageHandler.sendWithPromise("GetDocRequest",ae,i?[i.buffer]:null);let nt;if(h)nt=new qS(h,{disableRange:F,disableStream:L});else if(!i){if(!s)throw new Error("getDocument - no `url` parameter provided.");let Zt;if(Oe)if(ul(s)){if(typeof fetch>"u"||typeof Response>"u"||!("body"in Response.prototype))throw new Error("getDocument - the Fetch API was disabled in Node.js, see `--no-experimental-fetch`.");Zt=ob}else Zt=hC;else Zt=ul(s)?ob:iC;nt=new Zt({url:s,length:Ot,httpHeaders:n,withCredentials:r,rangeChunkSize:c,disableRange:F,disableStream:L})}return st.then(Zt=>{if(t.destroyed)throw new Error("Loading aborted");if(u.destroyed)throw new Error("Worker was destroyed");const $s=new fl(e,Zt,u.port),Te=new TC($s,t,nt,Ze,_t);t._transport=Te,$s.send("Ready",null)})}).catch(t._capability.reject),t}function wC(o){if(o instanceof URL)return o.href;try{return new URL(o,window.location).href}catch{if(Oe&&typeof o=="string")return o}throw new Error("Invalid PDF url data: either string or URL-object is expected in the url property.")}function xC(o){if(Oe&&typeof Buffer<"u"&&o instanceof Buffer)throw new Error("Please provide binary data as `Uint8Array`, rather than `Buffer`.");if(o instanceof Uint8Array&&o.byteLength===o.buffer.byteLength)return o;if(typeof o=="string")return fd(o);if(o instanceof ArrayBuffer||ArrayBuffer.isView(o)||typeof o=="object"&&!isNaN(o==null?void 0:o.length))return new Uint8Array(o);throw new Error("Invalid PDF binary data: either TypedArray, string, or array-like object is expected in the data property.")}function hb(o){return typeof o=="object"&&Number.isInteger(o==null?void 0:o.num)&&o.num>=0&&Number.isInteger(o==null?void 0:o.gen)&&o.gen>=0}const Nd=class Nd{constructor(){this._capability=Promise.withResolvers(),this._transport=null,this._worker=null,this.docId=`d${es(Nd,jd)._++}`,this.destroyed=!1,this.onPassword=null,this.onProgress=null}get promise(){return this._capability.promise}async destroy(){var t,e,s,i;this.destroyed=!0;try{(t=this._worker)!=null&&t.port&&(this._worker._pendingDestroy=!0),await((e=this._transport)==null?void 0:e.destroy())}catch(n){throw(s=this._worker)!=null&&s.port&&delete this._worker._pendingDestroy,n}this._transport=null,(i=this._worker)==null||i.destroy(),this._worker=null}};jd=new WeakMap,_(Nd,jd,0);let Jg=Nd;class lb{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){kt("Abstract method PDFDataRangeTransport.requestDataRange")}abort(){}}class SC{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 ct(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 CC{constructor(t,e,s,i=!1){_(this,Vs);_(this,pr,null);_(this,wn,!1);this._pageIndex=t,this._pageInfo=e,this._transport=s,this._stats=i?new Rv:null,this._pdfBug=i,this.commonObjs=s.commonObjs,this.objs=new cb,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 cl({viewBox:this.view,userUnit:this.userUnit,scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}getAnnotations({intent:t="display"}={}){const{renderingIntent:e}=this._transport.getRenderingIntent(t);return this._transport.getAnnotations(this._pageIndex,e)}getJSActions(){return this._transport.getPageJSActions(this._pageIndex)}get filterFactory(){return this._transport.filterFactory}get isPureXfa(){return ct(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=Yn.ENABLE,transform:n=null,background:r=null,optionalContentConfigPromise:a=null,annotationCanvasMap:h=null,pageColors:c=null,printAnnotationStorage:u=null,isEditing:d=!1}){var C,k;(C=this._stats)==null||C.time("Overall");const f=this._transport.getRenderingIntent(s,i,u,d),{renderingIntent:g,cacheKey:p}=f;v(this,wn,!1),w(this,Vs,cf).call(this),a||(a=this._transport.getOptionalContentConfig(g));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 y=!!(g&vs.PRINT);m.displayReadyCapability||(m.displayReadyCapability=Promise.withResolvers(),m.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(k=this._stats)==null||k.time("Page Request"),this._pumpOperatorList(f));const b=O=>{var P;m.renderTasks.delete(x),(this._maybeCleanupAfterRender||y)&&v(this,wn,!0),w(this,Vs,zh).call(this,!y),O?(x.capability.reject(O),this._abortOperatorList({intentState:m,reason:O instanceof Error?O:new Error(O)})):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 Qg({callback:b,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:!y,pdfBug:this._pdfBug,pageColors:c});(m.renderTasks||(m.renderTasks=new Set)).add(x);const S=x.task;return Promise.all([m.displayReadyCapability.promise,a]).then(([O,P])=>{var D;if(this.destroyed){b();return}if((D=this._stats)==null||D.time("Rendering"),!(P.renderingIntent&g))throw new Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");x.initializeGraphics({transparency:O,optionalContentConfig:P}),x.operatorListChanged()}).catch(b),S}getOperatorList({intent:t="display",annotationMode:e=Yn.ENABLE,printAnnotationStorage:s=null,isEditing:i=!1}={}){var c;function n(){a.operatorList.lastChunk&&(a.opListReadCapability.resolve(a.operatorList),a.renderTasks.delete(h))}const r=this._transport.getRenderingIntent(t,e,s,i,!0);let a=this._intentStates.get(r.cacheKey);a||(a=Object.create(null),this._intentStates.set(r.cacheKey,a));let h;return a.opListReadCapability||(h=Object.create(null),h.operatorListChanged=n,a.opListReadCapability=Promise.withResolvers(),(a.renderTasks||(a.renderTasks=new Set)).add(h),a.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(c=this._stats)==null||c.time("Page Request"),this._pumpOperatorList(r)),a.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=>ml.textContent(s));const e=this.streamTextContent(t);return new Promise(function(s,i){function n(){r.read().then(function({value:h,done:c}){if(c){s(a);return}a.lang??(a.lang=h.lang),Object.assign(a.styles,h.styles),a.items.push(...h.items),n()},i)}const r=e.getReader(),a={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(),v(this,wn,!1),w(this,Vs,cf).call(this),Promise.all(t)}cleanup(t=!1){v(this,wn,!0);const e=w(this,Vs,zh).call(this,!1);return t&&e&&this._stats&&(this._stats=new Rv),e}_startRenderPage(t,e){var i,n;const s=this._intentStates.get(e);s&&((i=this._stats)==null||i.timeEnd("Page Request"),(n=s.displayReadyCapability)==null||n.resolve(t))}_renderPageChunk(t,e){for(let s=0,i=t.length;s<i;s++)e.operatorList.fnArray.push(t.fnArray[s]),e.operatorList.argsArray.push(t.argsArray[s]);e.operatorList.lastChunk=t.lastChunk,e.operatorList.separateAnnots=t.separateAnnots;for(const s of e.renderTasks)s.operatorListChanged();t.lastChunk&&w(this,Vs,zh).call(this,!0)}_pumpOperatorList({renderingIntent:t,cacheKey:e,annotationStorageSerializable:s,modifiedIds:i}){const{map:n,transfer:r}=s,h=this._transport.messageHandler.sendWithStream("GetOperatorList",{pageIndex:this._pageIndex,intent:t,cacheKey:e,annotationStorage:n,modifiedIds:i},r).getReader(),c=this._intentStates.get(e);c.streamReader=h;const u=()=>{h.read().then(({value:d,done:f})=>{if(f){c.streamReader=null;return}this._transport.destroyed||(this._renderPageChunk(d,c),u())},d=>{if(c.streamReader=null,!this._transport.destroyed){if(c.operatorList){c.operatorList.lastChunk=!0;for(const f of c.renderTasks)f.operatorListChanged();w(this,Vs,zh).call(this,!0)}if(c.displayReadyCapability)c.displayReadyCapability.reject(d);else if(c.opListReadCapability)c.opListReadCapability.reject(d);else throw d}})};u()}_abortOperatorList({intentState:t,reason:e,force:s=!1}){if(t.streamReader){if(t.streamReaderCancelTimeout&&(clearTimeout(t.streamReaderCancelTimeout),t.streamReaderCancelTimeout=null),!s){if(t.renderTasks.size>0)return;if(e instanceof Lg){let i=gC;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 qn(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}}pr=new WeakMap,wn=new WeakMap,Vs=new WeakSet,zh=function(t=!1){if(w(this,Vs,cf).call(this),!l(this,wn)||this.destroyed)return!1;if(t)return v(this,pr,setTimeout(()=>{v(this,pr,null),w(this,Vs,zh).call(this,!1)},pC)),!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(),v(this,wn,!1),!0},cf=function(){l(this,pr)&&(clearTimeout(l(this,pr)),v(this,pr,null))};class AC{constructor(){_(this,xn,new Map);_(this,Bd,Promise.resolve())}postMessage(t,e){const s={data:structuredClone(t,e?{transfer:e}:null)};l(this,Bd).then(()=>{for(const[i]of l(this,xn))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){ht("LoopbackPort - cannot use an `aborted` signal.");return}const r=()=>this.removeEventListener(t,e);i=()=>n.removeEventListener("abort",r),n.addEventListener("abort",r)}l(this,xn).set(e,i)}removeEventListener(t,e){const s=l(this,xn).get(e);s==null||s(),l(this,xn).delete(e)}terminate(){for(const[,t]of l(this,xn))t==null||t();l(this,xn).clear()}}xn=new WeakMap,Bd=new WeakMap;const jt=class jt{constructor({name:t=null,port:e=null,verbosity:s=aS()}={}){_(this,eh);var i;if(this.name=t,this.destroyed=!1,this.verbosity=s,this._readyCapability=Promise.withResolvers(),this._port=null,this._webWorker=null,this._messageHandler=null,e){if((i=l(jt,ka))!=null&&i.has(e))throw new Error("Cannot use more than one PDFWorker per port.");(l(jt,ka)||v(jt,ka,new WeakMap)).set(e,this),this._initializeFromPort(e);return}this._initialize()}get promise(){return this._readyCapability.promise}get port(){return this._port}get messageHandler(){return this._messageHandler}_initializeFromPort(t){this._port=t,this._messageHandler=new fl("main","worker",t),this._messageHandler.on("ready",function(){}),w(this,eh,uf).call(this)}_initialize(){if(l(jt,Ea)||l(jt,sh,df)){this._setupFakeWorker();return}let{workerSrc:t}=jt;try{jt._isSameOrigin(window.location.href,t)||(t=jt._createCDNWrapper(new URL(t,window.location).href));const e=new Worker(t,{type:"module"}),s=new fl("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",a=>{if(n.abort(),this.destroyed||!a){i();return}this._messageHandler=s,this._port=e,this._webWorker=e,w(this,eh,uf).call(this)}),s.on("ready",a=>{if(n.abort(),this.destroyed){i();return}try{r()}catch{this._setupFakeWorker()}});const r=()=>{const a=new Uint8Array;s.send("test",a,[a.buffer])};r();return}catch{ud("The worker has been disabled.")}this._setupFakeWorker()}_setupFakeWorker(){l(jt,Ea)||(ht("Setting up fake worker."),v(jt,Ea,!0)),jt._setupFakeWorkerGlobal.then(t=>{if(this.destroyed){this._readyCapability.reject(new Error("Worker was destroyed"));return}const e=new AC;this._port=e;const s=`fake${es(jt,Hd)._++}`,i=new fl(s+"_worker",s,e);t.setup(i,e),this._messageHandler=new fl(s,s+"_worker",e),w(this,eh,uf).call(this)}).catch(t=>{this._readyCapability.reject(new Error(`Setting up fake worker failed: "${t.message}".`))})}destroy(){var t,e,s;this.destroyed=!0,(t=this._webWorker)==null||t.terminate(),this._webWorker=null,(e=l(jt,ka))==null||e.delete(this._port),this._port=null,(s=this._messageHandler)==null||s.destroy(),this._messageHandler=null}static fromPort(t){var s;if(!(t!=null&&t.port))throw new Error("PDFWorker.fromPort - invalid method signature.");const e=(s=l(this,ka))==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 jt(t)}static get workerSrc(){if(an.workerSrc)return an.workerSrc;throw new Error('No "GlobalWorkerOptions.workerSrc" specified.')}static get _setupFakeWorkerGlobal(){return ct(this,"_setupFakeWorkerGlobal",(async()=>l(this,sh,df)?l(this,sh,df):(await import(this.workerSrc)).WorkerMessageHandler)())}};Hd=new WeakMap,Ea=new WeakMap,ka=new WeakMap,eh=new WeakSet,uf=function(){this._readyCapability.resolve(),this._messageHandler.send("configure",{verbosity:this.verbosity})},sh=new WeakSet,df=function(){var t;try{return((t=globalThis.pdfjsWorker)==null?void 0:t.WorkerMessageHandler)||null}catch{return null}},_(jt,sh),_(jt,Hd,0),_(jt,Ea,!1),_(jt,ka),Oe&&(v(jt,Ea,!0),an.workerSrc||(an.workerSrc="./pdf.worker.mjs")),jt._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},jt._createCDNWrapper=t=>{const e=`await import("${t}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))};let ko=jt;class TC{constructor(t,e,s,i,n){_(this,Pa);_(this,Sn,new Map);_(this,Ni,new Map);_(this,ih,new Map);_(this,nh,new Map);_(this,Cn,null);this.messageHandler=t,this.loadingTask=e,this.commonObjs=new cb,this.fontLoader=new AS({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 ct(this,"annotationStorage",new Gg)}getRenderingIntent(t,e=Yn.ENABLE,s=null,i=!1,n=!1){let r=vs.DISPLAY,a=Wg;switch(t){case"any":r=vs.ANY;break;case"display":break;case"print":r=vs.PRINT;break;default:ht(`getRenderingIntent - invalid intent: ${t}`)}const h=r&vs.PRINT&&s instanceof Iv?s:this.annotationStorage;switch(e){case Yn.DISABLE:r+=vs.ANNOTATIONS_DISABLE;break;case Yn.ENABLE:break;case Yn.ENABLE_FORMS:r+=vs.ANNOTATIONS_FORMS;break;case Yn.ENABLE_STORAGE:r+=vs.ANNOTATIONS_STORAGE,a=h.serializable;break;default:ht(`getRenderingIntent - invalid annotationMode: ${e}`)}i&&(r+=vs.IS_EDITING),n&&(r+=vs.OPLIST);const{ids:c,hash:u}=h.modifiedIds,d=[r,a.hash,u];return{renderingIntent:r,cacheKey:d.join("_"),annotationStorageSerializable:a,modifiedIds:c}}destroy(){var s;if(this.destroyCapability)return this.destroyCapability.promise;this.destroyed=!0,this.destroyCapability=Promise.withResolvers(),(s=l(this,Cn))==null||s.reject(new Error("Worker was destroyed during onPassword callback"));const t=[];for(const i of l(this,Ni).values())t.push(i._destroy());l(this,Ni).clear(),l(this,ih).clear(),l(this,nh).clear(),this.hasOwnProperty("annotationStorage")&&this.annotationStorage.resetModified();const e=this.messageHandler.sendWithPromise("Terminate",null);return t.push(e),Promise.all(t).then(()=>{var i,n;this.commonObjs.clear(),this.fontLoader.clear(),l(this,Sn).clear(),this.filterFactory.destroy(),pl.cleanup(),(i=this._networkStream)==null||i.cancelAllRequests(new qn("Worker was terminated.")),(n=this.messageHandler)==null||n.destroy(),this.messageHandler=null,this.destroyCapability.resolve()},this.destroyCapability.reject),this.destroyCapability.promise}setupMessageHandler(){const{messageHandler:t,loadingTask:e}=this;t.on("GetReader",(s,i)=>{ie(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}ie(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 a;await this._fullReader.headersReady;const{isStreamingSupported:i,isRangeSupported:n,contentLength:r}=this._fullReader;return(!i||!n)&&(this._lastProgress&&((a=e.onProgress)==null||a.call(e,this._lastProgress)),this._fullReader.onProgress=h=>{var c;(c=e.onProgress)==null||c.call(e,{loaded:h.loaded,total:h.total})}),{isStreamingSupported:i,isRangeSupported:n,contentLength:r}}),t.on("GetRangeReader",(s,i)=>{ie(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:a}){if(a){i.close();return}ie(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(a=>{if(!this.destroyed)throw a})}}),t.on("GetDoc",({pdfInfo:s})=>{this._numPages=s.numPages,this._htmlForXfa=s.htmlForXfa,delete s.htmlForXfa,e._capability.resolve(new SC(s,this))}),t.on("DocException",s=>{e._capability.reject(rs(s))}),t.on("PasswordRequest",s=>{v(this,Cn,Promise.withResolvers());try{if(!e.onPassword)throw rs(s);const i=n=>{n instanceof Error?l(this,Cn).reject(n):l(this,Cn).resolve({password:n})};e.onPassword(i,s.code)}catch(i){l(this,Cn).reject(i)}return l(this,Cn).promise}),t.on("DataLoaded",s=>{var i;(i=e.onProgress)==null||i.call(e,{loaded:s.length,total:s.length}),this.downloadInfoCapability.resolve(s)}),t.on("StartRenderPage",s=>{if(this.destroyed)return;l(this,Ni).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:a,fontExtraProperties:h,pdfBug:c}=this._params;if("error"in n){const g=n.error;ht(`Error during font loading: ${g}`),this.commonObjs.resolve(s,g);break}const u=c&&((r=globalThis.FontInspector)!=null&&r.enabled)?(g,p)=>globalThis.FontInspector.fontAdded(g,p):null,d=new TS(n,{disableFontFace:a,fontExtraProperties:h,inspectFont:u});this.fontLoader.bind(d).catch(()=>t.sendWithPromise("FontFallback",{id:s})).finally(()=>{!h&&d.data&&(d.data=null),this.commonObjs.resolve(s,d)});break;case"CopyLocalImage":const{imageRef:f}=n;ie(f,"The imageRef must be defined.");for(const g of l(this,Ni).values())for(const[,p]of g.objs)if((p==null?void 0:p.ref)===f)return p.dataLen?(this.commonObjs.resolve(s,structuredClone(p)),p.dataLen):null;break;case"FontPath":case"Image":case"Pattern":this.commonObjs.resolve(s,n);break;default:throw new Error(`Got unknown common object type ${i}`)}return null}),t.on("obj",([s,i,n,r])=>{var h;if(this.destroyed)return;const a=l(this,Ni).get(i);if(!a.objs.has(s)){if(a._intentStates.size===0){(h=r==null?void 0:r.bitmap)==null||h.close();return}switch(n){case"Image":a.objs.resolve(s,r),(r==null?void 0:r.dataLen)>eS&&(a._maybeCleanupAfterRender=!0);break;case"Pattern":a.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&&ht("saveDocument called while `annotationStorage` is empty, please use the getData-method instead.");const{map:t,transfer:e}=this.annotationStorage.serializable;return this.messageHandler.sendWithPromise("SaveDocument",{isPureXfa:!!this._htmlForXfa,numPages:this._numPages,annotationStorage:t,filename:((s=this._fullReader)==null?void 0:s.filename)??null},e).finally(()=>{this.annotationStorage.resetModified()})}getPage(t){if(!Number.isInteger(t)||t<=0||t>this._numPages)return Promise.reject(new Error("Invalid page request."));const e=t-1,s=l(this,ih).get(e);if(s)return s;const i=this.messageHandler.sendWithPromise("GetPage",{pageIndex:e}).then(n=>{if(this.destroyed)throw new Error("Transport destroyed");n.refStr&&l(this,nh).set(n.refStr,t);const r=new CC(e,n,this,this._params.pdfBug);return l(this,Ni).set(e,r),r});return l(this,ih).set(e,i),i}getPageIndex(t){return hb(t)?this.messageHandler.sendWithPromise("GetPageIndex",{num:t.num,gen:t.gen}):Promise.reject(new Error("Invalid pageIndex request."))}getAnnotations(t,e){return this.messageHandler.sendWithPromise("GetAnnotations",{pageIndex:t,intent:e})}getFieldObjects(){return w(this,Pa,tu).call(this,"GetFieldObjects")}hasJSActions(){return w(this,Pa,tu).call(this,"HasJSActions")}getCalculationOrderIds(){return this.messageHandler.sendWithPromise("GetCalculationOrderIds",null)}getDestinations(){return this.messageHandler.sendWithPromise("GetDestinations",null)}getDestination(t){return typeof t!="string"?Promise.reject(new Error("Invalid destination request.")):this.messageHandler.sendWithPromise("GetDestination",{id:t})}getPageLabels(){return this.messageHandler.sendWithPromise("GetPageLabels",null)}getPageLayout(){return this.messageHandler.sendWithPromise("GetPageLayout",null)}getPageMode(){return this.messageHandler.sendWithPromise("GetPageMode",null)}getViewerPreferences(){return this.messageHandler.sendWithPromise("GetViewerPreferences",null)}getOpenAction(){return this.messageHandler.sendWithPromise("GetOpenAction",null)}getAttachments(){return this.messageHandler.sendWithPromise("GetAttachments",null)}getDocJSActions(){return w(this,Pa,tu).call(this,"GetDocJSActions")}getPageJSActions(t){return this.messageHandler.sendWithPromise("GetPageJSActions",{pageIndex:t})}getStructTree(t){return this.messageHandler.sendWithPromise("GetStructTree",{pageIndex:t})}getOutline(){return this.messageHandler.sendWithPromise("GetOutline",null)}getOptionalContentConfig(t){return w(this,Pa,tu).call(this,"GetOptionalContentConfig").then(e=>new $S(e,t))}getPermissions(){return this.messageHandler.sendWithPromise("GetPermissions",null)}getMetadata(){const t="GetMetadata",e=l(this,Sn).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 US(i[1]):null,contentDispositionFilename:((n=this._fullReader)==null?void 0:n.filename)??null,contentLength:((r=this._fullReader)==null?void 0:r.contentLength)??null}});return l(this,Sn).set(t,s),s}getMarkInfo(){return this.messageHandler.sendWithPromise("GetMarkInfo",null)}async startCleanup(t=!1){if(!this.destroyed){await this.messageHandler.sendWithPromise("Cleanup",null);for(const e of l(this,Ni).values())if(!e.cleanup())throw new Error(`startCleanup: Page ${e.pageNumber} is currently rendering.`);this.commonObjs.clear(),t||this.fontLoader.clear(),l(this,Sn).clear(),this.filterFactory.destroy(!0),pl.cleanup()}}cachedPageNumber(t){if(!hb(t))return null;const e=t.gen===0?`${t.num}R`:`${t.num}R${t.gen}`;return l(this,nh).get(e)??null}}Sn=new WeakMap,Ni=new WeakMap,ih=new WeakMap,nh=new WeakMap,Cn=new WeakMap,Pa=new WeakSet,tu=function(t,e=null){const s=l(this,Sn).get(t);if(s)return s;const i=this.messageHandler.sendWithPromise(t,e);return l(this,Sn).set(t,i),i};const vl=Symbol("INITIAL_DATA");class cb{constructor(){_(this,lc);_(this,Ss,Object.create(null))}get(t,e=null){if(e){const i=w(this,lc,$p).call(this,t);return i.promise.then(()=>e(i.data)),null}const s=l(this,Ss)[t];if(!s||s.data===vl)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return s.data}has(t){const e=l(this,Ss)[t];return!!e&&e.data!==vl}delete(t){const e=l(this,Ss)[t];return!e||e.data===vl?!1:(delete l(this,Ss)[t],!0)}resolve(t,e=null){const s=w(this,lc,$p).call(this,t);s.data=e,s.resolve()}clear(){var t;for(const e in l(this,Ss)){const{data:s}=l(this,Ss)[e];(t=s==null?void 0:s.bitmap)==null||t.close()}v(this,Ss,Object.create(null))}*[Symbol.iterator](){for(const t in l(this,Ss)){const{data:e}=l(this,Ss)[t];e!==vl&&(yield[t,e])}}}Ss=new WeakMap,lc=new WeakSet,$p=function(t){var e;return(e=l(this,Ss))[t]||(e[t]={...Promise.withResolvers(),data:vl})};class EC{constructor(t){_(this,mr,null);v(this,mr,t),this.onContinue=null}get promise(){return l(this,mr).capability.promise}cancel(t=0){l(this,mr).cancel(null,t)}get separateAnnots(){const{separateAnnots:t}=l(this,mr).operatorList;if(!t)return!1;const{annotationCanvasMap:e}=l(this,mr);return t.form||t.canvas&&(e==null?void 0:e.size)>0}}mr=new WeakMap;const Oa=class Oa{constructor({callback:t,params:e,objs:s,commonObjs:i,annotationCanvasMap:n,operatorList:r,pageIndex:a,canvasFactory:h,filterFactory:c,useRequestAnimationFrame:u=!1,pdfBug:d=!1,pageColors:f=null}){_(this,vr,null);this.callback=t,this.params=e,this.objs=s,this.commonObjs=i,this.annotationCanvasMap=n,this.operatorListIdx=null,this.operatorList=r,this._pageIndex=a,this.canvasFactory=h,this.filterFactory=c,this._pdfBug=d,this.pageColors=f,this.running=!1,this.graphicsReadyCallback=null,this.graphicsReady=!1,this._useRequestAnimationFrame=u===!0&&typeof window<"u",this.cancelled=!1,this.capability=Promise.withResolvers(),this.task=new EC(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 a,h;if(this.cancelled)return;if(this._canvas){if(l(Oa,Ma).has(this._canvas))throw new Error("Cannot use the same canvas during multiple render() operations. Use different canvas or ensure previous operations were cancelled or completed.");l(Oa,Ma).add(this._canvas)}this._pdfBug&&((a=globalThis.StepperManager)!=null&&a.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 To(s,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:e},this.annotationCanvasMap,this.pageColors),this.gfx.beginDrawing({transform:n,viewport:i,transparency:t,background:r}),this.operatorListIdx=0,this.graphicsReady=!0,(h=this.graphicsReadyCallback)==null||h.call(this)}cancel(t=null,e=0){var s;this.running=!1,this.cancelled=!0,(s=this.gfx)==null||s.endDrawing(),l(this,vr)&&(window.cancelAnimationFrame(l(this,vr)),v(this,vr,null)),l(Oa,Ma).delete(this._canvas),this.callback(t||new Lg(`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?v(this,vr,window.requestAnimationFrame(()=>{v(this,vr,null),this._nextBound().catch(this._cancelBound)})):Promise.resolve().then(this._nextBound).catch(this._cancelBound)}async _next(){this.cancelled||(this.operatorListIdx=this.gfx.executeOperatorList(this.operatorList,this.operatorListIdx,this._continueBound,this.stepper),this.operatorListIdx===this.operatorList.argsArray.length&&(this.running=!1,this.operatorList.lastChunk&&(this.gfx.endDrawing(),l(Oa,Ma).delete(this._canvas),this.callback())))}};vr=new WeakMap,Ma=new WeakMap,_(Oa,Ma,new WeakSet);let Qg=Oa;const kC="4.10.38",PC="f9bea397f";function ub(o){return Math.floor(Math.max(0,Math.min(1,o))*255).toString(16).padStart(2,"0")}function bl(o){return Math.max(0,Math.min(255,255*o))}class db{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=bl(t),[t,t,t]}static G_HTML([t]){const e=ub(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(bl)}static RGB_HTML(t){return`#${t.map(ub).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[bl(1-Math.min(1,t+i)),bl(1-Math.min(1,s+i)),bl(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,a=Math.min(i,n,r);return["CMYK",i,n,r,a]}}class MC{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){kt("Abstract method `_createSVG` called.")}}class Zg extends MC{_createSVG(t){return document.createElementNS(rn,t)}}class fb{static setupStorage(t,e,s,i,n){const r=i.getValue(e,{value:null});switch(s.name){case"textarea":if(r.value!==null&&(t.textContent=r.value),n==="print")break;t.addEventListener("input",a=>{i.setValue(e,{value:a.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",a=>{i.setValue(e,{value:a.target.checked?a.target.getAttribute("xfaOn"):a.target.getAttribute("xfaOff")})})}else{if(r.value!==null&&t.setAttribute("value",r.value),n==="print")break;t.addEventListener("input",a=>{i.setValue(e,{value:a.target.value})})}break;case"select":if(r.value!==null){t.setAttribute("value",r.value);for(const a of s.children)a.attributes.value===r.value?a.attributes.selected=!0:a.attributes.hasOwnProperty("selected")&&delete a.attributes.selected}t.addEventListener("input",a=>{const h=a.target.options,c=h.selectedIndex===-1?"":h[h.selectedIndex].value;i.setValue(e,{value:c})});break}}static setAttributes({html:t,element:e,storage:s=null,intent:i,linkService:n}){const{attributes:r}=e,a=t instanceof HTMLAnchorElement;r.type==="radio"&&(r.name=`${r.name}-${i}`);for(const[h,c]of Object.entries(r))if(c!=null)switch(h){case"class":c.length&&t.setAttribute(h,c.join(" "));break;case"dataId":break;case"id":t.setAttribute("data-element-id",c);break;case"style":Object.assign(t.style,c);break;case"textContent":t.textContent=c;break;default:(!a||h!=="href"&&h!=="newWindow")&&t.setAttribute(h,c)}a&&n.addLinkAttributes(t,r.href,r.newWindow),s&&r.dataId&&this.setupStorage(t,r.dataId,e,s)}static render(t){var d,f;const e=t.annotationStorage,s=t.linkService,i=t.xfaHtml,n=t.intent||"display",r=document.createElement(i.name);i.attributes&&this.setAttributes({html:r,element:i,intent:n,linkService:s});const a=n!=="richText",h=t.div;if(h.append(r),t.viewport){const g=`matrix(${t.viewport.transform.join(",")})`;h.style.transform=g}a&&h.setAttribute("class","xfaLayer xfaFont");const c=[];if(i.children.length===0){if(i.value){const g=document.createTextNode(i.value);r.append(g),a&&ml.shouldBuildText(i.name)&&c.push(g)}return{textDivs:c}}const u=[[i,-1,r]];for(;u.length>0;){const[g,p,m]=u.at(-1);if(p+1===g.children.length){u.pop();continue}const y=g.children[++u.at(-1)[1]];if(y===null)continue;const{name:b}=y;if(b==="#text"){const S=document.createTextNode(y.value);c.push(S),m.append(S);continue}const x=(d=y==null?void 0:y.attributes)!=null&&d.xmlns?document.createElementNS(y.attributes.xmlns,b):document.createElement(b);if(m.append(x),y.attributes&&this.setAttributes({html:x,element:y,storage:e,intent:n,linkService:s}),((f=y.children)==null?void 0:f.length)>0)u.push([y,-1,x]);else if(y.value){const S=document.createTextNode(y.value);a&&ml.shouldBuildText(b)&&c.push(S),x.append(S)}}for(const g of h.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea"))g.setAttribute("readOnly",!0);return{textDivs:c}}static update(t){const e=`matrix(${t.viewport.transform.join(",")})`;t.div.style.transform=e,t.div.hidden=!1}}const yl=1e3,OC=9,qr=new WeakSet;function Jn(o){return{width:o[2]-o[0],height:o[3]-o[1]}}class DC{static create(t){switch(t.data.annotationType){case le.LINK:return new gb(t);case le.TEXT:return new RC(t);case le.WIDGET:switch(t.data.fieldType){case"Tx":return new FC(t);case"Btn":return t.data.radioButton?new pb(t):t.data.checkBox?new IC(t):new jC(t);case"Ch":return new NC(t);case"Sig":return new LC(t)}return new Kr(t);case le.POPUP:return new tp(t);case le.FREETEXT:return new mb(t);case le.LINE:return new HC(t);case le.SQUARE:return new zC(t);case le.CIRCLE:return new VC(t);case le.POLYLINE:return new vb(t);case le.CARET:return new GC(t);case le.INK:return new ep(t);case le.POLYGON:return new WC(t);case le.HIGHLIGHT:return new bb(t);case le.UNDERLINE:return new XC(t);case le.SQUIGGLY:return new UC(t);case le.STRIKEOUT:return new YC(t);case le.STAMP:return new yb(t);case le.FILEATTACHMENT:return new $C(t);default:return new Kt(t)}}}const pp=class pp{constructor(t,{isRenderable:e=!1,ignoreBorder:s=!1,createQuadrilaterals:i=!1}={}){_(this,cc);_(this,Da,null);_(this,rh,!1);_(this,ah,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 pp._hasPopupData(this.data)}updateEdited(t){var s;if(!this.container)return;l(this,Da)||v(this,Da,{rect:this.data.rect.slice(0)});const{rect:e}=t;e&&w(this,cc,qp).call(this,e),(s=l(this,ah))==null||s.popup.updateEdited(t)}resetEdited(){var t;l(this,Da)&&(w(this,cc,qp).call(this,l(this,Da).rect),(t=l(this,ah))==null||t.popup.resetEdited(),v(this,Da,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 Kr||(n.tabIndex=yl);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 tp){const{rotation:m}=e;return!e.hasOwnCanvas&&m!==0&&this.setRotation(m,n),n}const{width:a,height:h}=Jn(e.rect);if(!t&&e.borderStyle.width>0){r.borderWidth=`${e.borderStyle.width}px`;const m=e.borderStyle.horizontalCornerRadius,y=e.borderStyle.verticalCornerRadius;if(m>0||y>0){const x=`calc(${m}px * var(--scale-factor)) / calc(${y}px * var(--scale-factor))`;r.borderRadius=x}else if(this instanceof pb){const x=`calc(${a}px * var(--scale-factor)) / calc(${h}px * var(--scale-factor))`;r.borderRadius=x}switch(e.borderStyle.style){case hl.SOLID:r.borderStyle="solid";break;case hl.DASHED:r.borderStyle="dashed";break;case hl.BEVELED:ht("Unimplemented border style: beveled");break;case hl.INSET:ht("Unimplemented border style: inset");break;case hl.UNDERLINE:r.borderBottomStyle="solid";break}const b=e.borderColor||null;b?(v(this,rh,!0),r.borderColor=q.makeHexColor(b[0]|0,b[1]|0,b[2]|0)):r.borderWidth=0}const c=q.normalizeRect([e.rect[0],s.view[3]-e.rect[1]+s.view[1],e.rect[2],s.view[3]-e.rect[3]+s.view[1]]),{pageWidth:u,pageHeight:d,pageX:f,pageY:g}=i.rawDims;r.left=`${100*(c[0]-f)/u}%`,r.top=`${100*(c[1]-g)/d}%`;const{rotation:p}=e;return e.hasOwnCanvas||p===0?(r.width=`${100*a/u}%`,r.height=`${100*h/d}%`):this.setRotation(p,n),n}setRotation(t,e=this.container){if(!this.data.rect)return;const{pageWidth:s,pageHeight:i}=this.parent.viewport.rawDims,{width:n,height:r}=Jn(this.data.rect);let a,h;t%180===0?(a=100*n/s,h=100*r/i):(a=100*r/s,h=100*n/i),e.style.width=`${a}%`,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],a=n.slice(1);i.target.style[s]=db[`${r}_HTML`](a),this.annotationStorage.setValue(this.data.id,{[s]:db[`${r}_rgb`](a)})};return ct(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 a={detail:{[i]:n},target:t};r(a),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,y,b,x]=t.subarray(2,6);if(i===m&&n===y&&e===b&&s===x)return}const{style:r}=this.container;let a;if(l(this,rh)){const{borderColor:m,borderWidth:y}=r;r.borderWidth=0,a=["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="${y}">`],this.container.classList.add("hasBorder")}const h=i-e,c=n-s,{svgFactory:u}=this,d=u.createElement("svg");d.classList.add("quadrilateralsContainer"),d.setAttribute("width",0),d.setAttribute("height",0);const f=u.createElement("defs");d.append(f);const g=u.createElement("clipPath"),p=`clippath_${this.data.id}`;g.setAttribute("id",p),g.setAttribute("clipPathUnits","objectBoundingBox"),f.append(g);for(let m=2,y=t.length;m<y;m+=8){const b=t[m],x=t[m+1],S=t[m+2],C=t[m+3],k=u.createElement("rect"),O=(S-e)/h,P=(n-x)/c,D=(b-S)/h,R=(x-C)/c;k.setAttribute("x",O),k.setAttribute("y",P),k.setAttribute("width",D),k.setAttribute("height",R),g.append(k),a==null||a.push(`<rect vector-effect="non-scaling-stroke" x="${O}" y="${P}" width="${D}" height="${R}"/>`)}l(this,rh)&&(a.push("</g></svg>')"),r.backgroundImage=a.join("")),this.container.append(d),this.container.style.clipPath=`url(#${p})`}_createPopup(){const{data:t}=this,e=v(this,ah,new tp({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(){kt("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:a}of i){if(n===-1||r===e)continue;const h=typeof a=="string"?a:null,c=document.querySelector(`[data-element-id="${r}"]`);if(c&&!qr.has(c)){ht(`_getElementsByName - element not allowed: ${r}`);continue}s.push({id:r,exportValue:h,domElement:c})}return s}for(const i of document.getElementsByName(t)){const{exportValue:n}=i,r=i.getAttribute("data-element-id");r!==e&&qr.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})})}};Da=new WeakMap,rh=new WeakMap,ah=new WeakMap,cc=new WeakSet,qp=function(t){const{container:{style:e},data:{rect:s,rotation:i},parent:{viewport:{rawDims:{pageWidth:n,pageHeight:r,pageX:a,pageY:h}}}}=this;s==null||s.splice(0,4,...t);const{width:c,height:u}=Jn(t);e.left=`${100*(t[0]-a)/n}%`,e.top=`${100*(r-t[3]+h)/r}%`,i===0?(e.width=`${100*c/n}%`,e.height=`${100*u/r}%`):this.setRotation(i)};let Kt=pp;class gb extends Kt{constructor(e,s=null){super(e,{isRenderable:!0,ignoreBorder:!!(s!=null&&s.ignoreBorder),createQuadrilaterals:!0});_(this,Cs);this.isTooltipOnly=e.data.isTooltipOnly}render(){const{data:e,linkService:s}=this,i=document.createElement("a");i.setAttribute("data-element-id",e.id);let n=!1;return e.url?(s.addLinkAttributes(i,e.url,e.newWindow),n=!0):e.action?(this._bindNamedAction(i,e.action),n=!0):e.attachment?(w(this,Cs,Ey).call(this,i,e.attachment,e.attachmentDest),n=!0):e.setOCGState?(w(this,Cs,ky).call(this,i,e.setOCGState),n=!0):e.dest?(this._bindLink(i,e.dest),n=!0):(e.actions&&(e.actions.Action||e.actions["Mouse Up"]||e.actions["Mouse Down"])&&this.enableScripting&&this.hasJSActions&&(this._bindJSAction(i,e),n=!0),e.resetForm?(this._bindResetFormAction(i,e.resetForm),n=!0):this.isTooltipOnly&&!n&&(this._bindLink(i,""),n=!0)),this.container.classList.add("linkAnnotation"),n&&this.container.append(i),this.container}_bindLink(e,s){e.href=this.linkService.getDestinationHash(s),e.onclick=()=>(s&&this.linkService.goToDestination(s),!1),(s||s==="")&&w(this,Cs,ao).call(this)}_bindNamedAction(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeNamedAction(s),!1),w(this,Cs,ao).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 a;return(a=this.linkService.eventBus)==null||a.dispatch("dispatcheventinsandbox",{source:this,detail:{id:s.id,name:n}}),!1})}e.onclick||(e.onclick=()=>!1),w(this,Cs,ao).call(this)}_bindResetFormAction(e,s){const i=e.onclick;if(i||(e.href=this.linkService.getAnchorUrl("")),w(this,Cs,ao).call(this),!this._fieldObjects){ht('_bindResetFormAction - "resetForm" action not supported, ensure that the `fieldObjects` parameter is provided.'),i||(e.onclick=()=>!1);return}e.onclick=()=>{var d;i==null||i();const{fields:n,refs:r,include:a}=s,h=[];if(n.length!==0||r.length!==0){const f=new Set(r);for(const g of n){const p=this._fieldObjects[g]||[];for(const{id:m}of p)f.add(m)}for(const g of Object.values(this._fieldObjects))for(const p of g)f.has(p.id)===a&&h.push(p)}else for(const f of Object.values(this._fieldObjects))h.push(...f);const c=this.annotationStorage,u=[];for(const f of h){const{id:g}=f;switch(u.push(g),f.type){case"text":{const m=f.defaultValue||"";c.setValue(g,{value:m});break}case"checkbox":case"radiobutton":{const m=f.defaultValue===f.exportValues;c.setValue(g,{value:m});break}case"combobox":case"listbox":{const m=f.defaultValue||"";c.setValue(g,{value:m});break}default:continue}const p=document.querySelector(`[data-element-id="${g}"]`);if(p){if(!qr.has(p)){ht(`_bindResetFormAction - element not allowed: ${g}`);continue}}else continue;p.dispatchEvent(new Event("resetform"))}return this.enableScripting&&((d=this.linkService.eventBus)==null||d.dispatch("dispatcheventinsandbox",{source:this,detail:{id:"app",ids:u,name:"ResetForm"}})),!1}}}Cs=new WeakSet,ao=function(){this.container.setAttribute("data-internal-link","")},Ey=function(e,s,i=null){e.href=this.linkService.getAnchorUrl(""),s.description&&(e.title=s.description),e.onclick=()=>{var n;return(n=this.downloadManager)==null||n.openOrDownloadData(s.content,s.filename,i),!1},w(this,Cs,ao).call(this)},ky=function(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeSetOCGState(s),!1),w(this,Cs,ao).call(this)};class RC extends Kt{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 Kr extends Kt{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 Ue.platform.isMac?t.metaKey:t.ctrlKey}_setEventListener(t,e,s,i,n){s.includes("mouse")?t.addEventListener(s,r=>{var a;(a=this.linkService.eventBus)==null||a.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 a;if(s==="blur"){if(!e.focused||!r.relatedTarget)return;e.focused=!1}else if(s==="focus"){if(e.focused)return;e.focused=!0}n&&((a=this.linkService.eventBus)==null||a.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:i,value:n(r)}}))})}_setEventListeners(t,e,s,i){var n,r,a;for(const[h,c]of s)(c==="Action"||(n=this.data.actions)!=null&&n[c])&&((c==="Focus"||c==="Blur")&&(e||(e={focused:!1})),this._setEventListener(t,e,h,c,i),c==="Focus"&&!((r=this.data.actions)!=null&&r.Blur)?this._setEventListener(t,e,"blur","Blur",null):c==="Blur"&&!((a=this.data.actions)!=null&&a.Focus)&&this._setEventListener(t,e,"focus","Focus",null))}_setBackgroundColor(t){const e=this.data.backgroundColor||null;t.style.backgroundColor=e===null?"transparent":q.makeHexColor(e[0],e[1],e[2])}_setTextStyle(t){const e=["left","center","right"],{fontColor:s}=this.data.defaultAppearanceData,i=this.data.defaultAppearanceData.fontSize||OC,n=t.style;let r;const a=2,h=c=>Math.round(10*c)/10;if(this.data.multiLine){const c=Math.abs(this.data.rect[3]-this.data.rect[1]-a),u=Math.round(c/(kg*i))||1,d=c/u;r=Math.min(i,h(d/kg))}else{const c=Math.abs(this.data.rect[3]-this.data.rect[1]-a);r=Math.min(i,h(c/kg))}n.fontSize=`calc(${r}px * var(--scale-factor))`,n.color=q.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 FC extends Kr{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 a=r.value||"";const h=t.getValue(e,{charLimit:this.data.maxLen}).charLimit;h&&a.length>h&&(a=a.slice(0,h));let c=r.formattedValue||((i=this.data.textContent)==null?void 0:i.join(`
529
- `))||null;c&&this.data.comb&&(c=c.replaceAll(/\s+/g,""));const u={userValue:a,formattedValue:c,lastCommittedValue:null,commitKey:1,focused:!1};this.data.multiLine?(s=document.createElement("textarea"),s.textContent=c??a,this.data.doNotScroll&&(s.style.overflowY="hidden")):(s=document.createElement("input"),s.type="text",s.setAttribute("value",c??a),this.data.doNotScroll&&(s.style.overflowX="hidden")),this.data.hasOwnCanvas&&(s.hidden=!0),qr.add(s),s.setAttribute("data-element-id",e),s.disabled=this.data.readOnly,s.name=this.data.fieldName,s.tabIndex=yl,this._setRequired(s,this.data.required),h&&(s.maxLength=h),s.addEventListener("input",f=>{t.setValue(e,{value:f.target.value}),this.setPropertyOnSiblings(s,"value",f.target.value,"value"),u.formattedValue=null}),s.addEventListener("resetform",f=>{const g=this.data.defaultFieldValue??"";s.value=u.userValue=g,u.formattedValue=null});let d=f=>{const{formattedValue:g}=u;g!=null&&(f.target.value=g),f.target.scrollLeft=0};if(this.enableScripting&&this.hasJSActions){s.addEventListener("focus",g=>{var m;if(u.focused)return;const{target:p}=g;u.userValue&&(p.value=u.userValue),u.lastCommittedValue=p.value,u.commitKey=1,(m=this.data.actions)!=null&&m.Focus||(u.focused=!0)}),s.addEventListener("updatefromsandbox",g=>{this.showElementAndHideCanvas(g.target);const p={value(m){u.userValue=m.detail.value??"",t.setValue(e,{value:u.userValue.toString()}),m.target.value=u.userValue},formattedValue(m){const{formattedValue:y}=m.detail;u.formattedValue=y,y!=null&&m.target!==document.activeElement&&(m.target.value=y),t.setValue(e,{formattedValue:y})},selRange(m){m.target.setSelectionRange(...m.detail.selRange)},charLimit:m=>{var S;const{charLimit:y}=m.detail,{target:b}=m;if(y===0){b.removeAttribute("maxLength");return}b.setAttribute("maxLength",y);let x=u.userValue;!x||x.length<=y||(x=x.slice(0,y),b.value=u.userValue=x,t.setValue(e,{value:x}),(S=this.linkService.eventBus)==null||S.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:x,willCommit:!0,commitKey:1,selStart:b.selectionStart,selEnd:b.selectionEnd}}))}};this._dispatchEventFromSandbox(p,g)}),s.addEventListener("keydown",g=>{var y;u.commitKey=1;let p=-1;if(g.key==="Escape"?p=0:g.key==="Enter"&&!this.data.multiLine?p=2:g.key==="Tab"&&(u.commitKey=3),p===-1)return;const{value:m}=g.target;u.lastCommittedValue!==m&&(u.lastCommittedValue=m,u.userValue=m,(y=this.linkService.eventBus)==null||y.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:m,willCommit:!0,commitKey:p,selStart:g.target.selectionStart,selEnd:g.target.selectionEnd}}))});const f=d;d=null,s.addEventListener("blur",g=>{var m,y;if(!u.focused||!g.relatedTarget)return;(m=this.data.actions)!=null&&m.Blur||(u.focused=!1);const{value:p}=g.target;u.userValue=p,u.lastCommittedValue!==p&&((y=this.linkService.eventBus)==null||y.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:p,willCommit:!0,commitKey:u.commitKey,selStart:g.target.selectionStart,selEnd:g.target.selectionEnd}})),f(g)}),(n=this.data.actions)!=null&&n.Keystroke&&s.addEventListener("beforeinput",g=>{var k;u.lastCommittedValue=null;const{data:p,target:m}=g,{value:y,selectionStart:b,selectionEnd:x}=m;let S=b,C=x;switch(g.inputType){case"deleteWordBackward":{const O=y.substring(0,b).match(/\w*[^\w]*$/);O&&(S-=O[0].length);break}case"deleteWordForward":{const O=y.substring(b).match(/^[^\w]*\w*/);O&&(C+=O[0].length);break}case"deleteContentBackward":b===x&&(S-=1);break;case"deleteContentForward":b===x&&(C+=1);break}g.preventDefault(),(k=this.linkService.eventBus)==null||k.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:y,change:p||"",willCommit:!1,selStart:S,selEnd:C}})}),this._setEventListeners(s,u,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],g=>g.target.value)}if(d&&s.addEventListener("blur",d),this.data.comb){const g=(this.data.rect[2]-this.data.rect[0])/h;s.classList.add("comb"),s.style.letterSpacing=`calc(${g}px * var(--scale-factor) - 1ch)`}}else s=document.createElement("div"),s.textContent=this.data.fieldValue,s.style.verticalAlign="middle",s.style.display="table-cell",this.data.hasOwnCanvas&&(s.hidden=!0);return this._setTextStyle(s),this._setBackgroundColor(s),this._setDefaultPropertiesFromJS(s),this.container.append(s),this.container}}class LC extends Kr{constructor(t){super(t,{isRenderable:!!t.data.hasOwnCanvas})}}class IC extends Kr{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 qr.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=yl,n.addEventListener("change",r=>{const{name:a,checked:h}=r.target;for(const c of this._getElementsByName(a,s)){const u=h&&c.exportValue===e.exportValue;c.domElement&&(c.domElement.checked=u),t.setValue(c.id,{value:u})}t.setValue(s,{value:h})}),n.addEventListener("resetform",r=>{const a=e.defaultFieldValue||"Off";r.target.checked=a===e.exportValue}),this.enableScripting&&this.hasJSActions&&(n.addEventListener("updatefromsandbox",r=>{const a={value(h){h.target.checked=h.detail.value!=="Off",t.setValue(s,{value:h.target.checked})}};this._dispatchEventFromSandbox(a,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 pb extends Kr{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(qr.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=yl,n.addEventListener("change",r=>{const{name:a,checked:h}=r.target;for(const c of this._getElementsByName(a,s))t.setValue(c.id,{value:!1});t.setValue(s,{value:h})}),n.addEventListener("resetform",r=>{const a=e.defaultFieldValue;r.target.checked=a!=null&&a===e.buttonValue}),this.enableScripting&&this.hasJSActions){const r=e.buttonValue;n.addEventListener("updatefromsandbox",a=>{const h={value:c=>{const u=r===c.detail.value;for(const d of this._getElementsByName(c.target.name)){const f=u&&d.id===s;d.domElement&&(d.domElement.checked=f),t.setValue(d.id,{value:f})}}};this._dispatchEventFromSandbox(h,a)}),this._setEventListeners(n,null,[["change","Validate"],["change","Action"],["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],a=>a.target.checked)}return this._setBackgroundColor(n),this._setDefaultPropertiesFromJS(n),this.container.append(n),this.container}}class jC extends gb{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 NC extends Kr{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");qr.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=yl;let n=this.data.combo&&this.data.options.length>0;this.data.combo||(i.size=this.data.options.length,this.data.multiSelect&&(i.multiple=!0)),i.addEventListener("resetform",u=>{const d=this.data.defaultFieldValue;for(const f of i.options)f.selected=f.value===d});for(const u of this.data.options){const d=document.createElement("option");d.textContent=u.displayValue,d.value=u.exportValue,s.value.includes(u.exportValue)&&(d.setAttribute("selected",!0),n=!1),i.append(d)}let r=null;if(n){const u=document.createElement("option");u.value=" ",u.setAttribute("hidden",!0),u.setAttribute("selected",!0),i.prepend(u),r=()=>{u.remove(),i.removeEventListener("input",r),r=null},i.addEventListener("input",r)}const a=u=>{const d=u?"value":"textContent",{options:f,multiple:g}=i;return g?Array.prototype.filter.call(f,p=>p.selected).map(p=>p[d]):f.selectedIndex===-1?null:f[f.selectedIndex][d]};let h=a(!1);const c=u=>{const d=u.target.options;return Array.prototype.map.call(d,f=>({displayValue:f.textContent,exportValue:f.value}))};return this.enableScripting&&this.hasJSActions?(i.addEventListener("updatefromsandbox",u=>{const d={value(f){r==null||r();const g=f.detail.value,p=new Set(Array.isArray(g)?g:[g]);for(const m of i.options)m.selected=p.has(m.value);t.setValue(e,{value:a(!0)}),h=a(!1)},multipleSelection(f){i.multiple=!0},remove(f){const g=i.options,p=f.detail.remove;g[p].selected=!1,i.remove(p),g.length>0&&Array.prototype.findIndex.call(g,y=>y.selected)===-1&&(g[0].selected=!0),t.setValue(e,{value:a(!0),items:c(f)}),h=a(!1)},clear(f){for(;i.length!==0;)i.remove(0);t.setValue(e,{value:null,items:[]}),h=a(!1)},insert(f){const{index:g,displayValue:p,exportValue:m}=f.detail.insert,y=i.children[g],b=document.createElement("option");b.textContent=p,b.value=m,y?y.before(b):i.append(b),t.setValue(e,{value:a(!0),items:c(f)}),h=a(!1)},items(f){const{items:g}=f.detail;for(;i.length!==0;)i.remove(0);for(const p of g){const{displayValue:m,exportValue:y}=p,b=document.createElement("option");b.textContent=m,b.value=y,i.append(b)}i.options.length>0&&(i.options[0].selected=!0),t.setValue(e,{value:a(!0),items:c(f)}),h=a(!1)},indices(f){const g=new Set(f.detail.indices);for(const p of f.target.options)p.selected=g.has(p.index);t.setValue(e,{value:a(!0)}),h=a(!1)},editable(f){f.target.disabled=!f.detail.editable}};this._dispatchEventFromSandbox(d,u)}),i.addEventListener("input",u=>{var g;const d=a(!0),f=a(!1);t.setValue(e,{value:d}),u.preventDefault(),(g=this.linkService.eventBus)==null||g.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:h,change:f,changeEx:d,willCommit:!1,commitKey:1,keyDown:!1}})}),this._setEventListeners(i,null,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"],["input","Action"],["input","Validate"]],u=>u.target.value)):i.addEventListener("input",function(u){t.setValue(e,{value:a(!0)})}),this.data.combo&&this._setTextStyle(i),this._setBackgroundColor(i),this._setDefaultPropertiesFromJS(i),this.container.append(i),this.container}}class tp extends Kt{constructor(t){const{data:e,elements:s}=t;super(t,{isRenderable:Kt._hasPopupData(e)}),this.elements=s,this.popup=null}render(){this.container.classList.add("popupAnnotation");const t=this.popup=new BC({container:this.container,color:this.data.color,titleObj:this.data.titleObj,modificationDate:this.data.modificationDate,contentsObj:this.data.contentsObj,richText:this.data.richText,rect:this.data.rect,parentRect:this.data.parentRect||null,parent:this.parent,elements:this.elements,open:this.data.open}),e=[];for(const s of this.elements)s.popup=t,s.container.ariaHasPopup="dialog",e.push(s.data.id),s.addHighlightArea();return this.container.setAttribute("aria-controls",e.map(s=>`${Fg}${s}`).join(",")),this.container}}class BC{constructor({container:t,color:e,elements:s,titleObj:i,modificationDate:n,contentsObj:r,richText:a,parent:h,rect:c,parentRect:u,open:d}){_(this,Tt);_(this,oh,w(this,Tt,Oy).bind(this));_(this,zd,w(this,Tt,Jp).bind(this));_(this,Vd,w(this,Tt,pf).bind(this));_(this,hh,w(this,Tt,gf).bind(this));_(this,Ra,null);_(this,Yt,null);_(this,An,null);_(this,lh,null);_(this,uc,null);_(this,dc,null);_(this,ch,null);_(this,Tn,!1);_(this,di,null);_(this,En,null);_(this,fc,null);_(this,kn,null);_(this,gc,null);_(this,Fa,null);_(this,La,!1);var f;v(this,Yt,t),v(this,gc,i),v(this,An,r),v(this,kn,a),v(this,dc,h),v(this,Ra,e),v(this,fc,c),v(this,ch,u),v(this,uc,s),v(this,lh,jg.toDateObject(n)),this.trigger=s.flatMap(g=>g.getElementsToTriggerPopup());for(const g of this.trigger)g.addEventListener("click",l(this,hh)),g.addEventListener("mouseenter",l(this,Vd)),g.addEventListener("mouseleave",l(this,zd)),g.classList.add("popupTriggerArea");for(const g of s)(f=g.container)==null||f.addEventListener("keydown",l(this,oh));l(this,Yt).hidden=!0,d&&w(this,Tt,gf).call(this)}render(){if(l(this,di))return;const t=v(this,di,document.createElement("div"));if(t.className="popup",l(this,Ra)){const n=t.style.outlineColor=q.makeHexColor(...l(this,Ra));CSS.supports("background-color","color-mix(in srgb, red 30%, white)")?t.style.backgroundColor=`color-mix(in srgb, ${n} 30%, white)`:t.style.backgroundColor=q.makeHexColor(...l(this,Ra).map(a=>Math.floor(.7*(255-a)+a)))}const e=document.createElement("span");e.className="header";const s=document.createElement("h1");if(e.append(s),{dir:s.dir,str:s.textContent}=l(this,gc),t.append(e),l(this,lh)){const n=document.createElement("span");n.classList.add("popupDate"),n.setAttribute("data-l10n-id","pdfjs-annotation-date-time-string"),n.setAttribute("data-l10n-args",JSON.stringify({dateObj:l(this,lh).valueOf()})),e.append(n)}const i=l(this,Tt,ff);if(i)fb.render({xfaHtml:i,intent:"richText",div:t}),t.lastChild.classList.add("richText","popupContent");else{const n=this._formatContents(l(this,An));t.append(n)}l(this,Yt).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 a=i[n];s.append(document.createTextNode(a)),n<r-1&&s.append(document.createElement("br"))}return s}updateEdited({rect:t,popupContent:e}){var s;l(this,Fa)||v(this,Fa,{contentsObj:l(this,An),richText:l(this,kn)}),t&&v(this,En,null),e&&(v(this,kn,w(this,Tt,My).call(this,e)),v(this,An,null)),(s=l(this,di))==null||s.remove(),v(this,di,null)}resetEdited(){var t;l(this,Fa)&&({contentsObj:es(this,An)._,richText:es(this,kn)._}=l(this,Fa),v(this,Fa,null),(t=l(this,di))==null||t.remove(),v(this,di,null),v(this,En,null))}forceHide(){v(this,La,this.isVisible),l(this,La)&&(l(this,Yt).hidden=!0)}maybeShow(){l(this,La)&&(l(this,di)||w(this,Tt,pf).call(this),v(this,La,!1),l(this,Yt).hidden=!1)}get isVisible(){return l(this,Yt).hidden===!1}}oh=new WeakMap,zd=new WeakMap,Vd=new WeakMap,hh=new WeakMap,Ra=new WeakMap,Yt=new WeakMap,An=new WeakMap,lh=new WeakMap,uc=new WeakMap,dc=new WeakMap,ch=new WeakMap,Tn=new WeakMap,di=new WeakMap,En=new WeakMap,fc=new WeakMap,kn=new WeakMap,gc=new WeakMap,Fa=new WeakMap,La=new WeakMap,Tt=new WeakSet,ff=function(){const t=l(this,kn),e=l(this,An);return t!=null&&t.str&&(!(e!=null&&e.str)||e.str===t.str)&&l(this,kn).html||null},Kp=function(){var t,e,s;return((s=(e=(t=l(this,Tt,ff))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.fontSize)||0},Py=function(){var t,e,s;return((s=(e=(t=l(this,Tt,ff))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.color)||null},My=function(t){const e=[],s={str:t,html:{name:"div",attributes:{dir:"auto"},children:[{name:"p",children:e}]}},i={style:{color:l(this,Tt,Py),fontSize:l(this,Tt,Kp)?`calc(${l(this,Tt,Kp)}px * var(--scale-factor))`:""}};for(const n of t.split(`
530
- `))e.push({name:"span",value:n,attributes:i});return s},Oy=function(t){t.altKey||t.shiftKey||t.ctrlKey||t.metaKey||(t.key==="Enter"||t.key==="Escape"&&l(this,Tn))&&w(this,Tt,gf).call(this)},Dy=function(){if(l(this,En)!==null)return;const{page:{view:t},viewport:{rawDims:{pageWidth:e,pageHeight:s,pageX:i,pageY:n}}}=l(this,dc);let r=!!l(this,ch),a=r?l(this,ch):l(this,fc);for(const p of l(this,uc))if(!a||q.intersect(p.data.rect,a)!==null){a=p.data.rect,r=!0;break}const h=q.normalizeRect([a[0],t[3]-a[1]+t[1],a[2],t[3]-a[3]+t[1]]),u=r?a[2]-a[0]+5:0,d=h[0]+u,f=h[1];v(this,En,[100*(d-i)/e,100*(f-n)/s]);const{style:g}=l(this,Yt);g.left=`${l(this,En)[0]}%`,g.top=`${l(this,En)[1]}%`},gf=function(){v(this,Tn,!l(this,Tn)),l(this,Tn)?(w(this,Tt,pf).call(this),l(this,Yt).addEventListener("click",l(this,hh)),l(this,Yt).addEventListener("keydown",l(this,oh))):(w(this,Tt,Jp).call(this),l(this,Yt).removeEventListener("click",l(this,hh)),l(this,Yt).removeEventListener("keydown",l(this,oh)))},pf=function(){l(this,di)||this.render(),this.isVisible?l(this,Tn)&&l(this,Yt).classList.add("focused"):(w(this,Tt,Dy).call(this),l(this,Yt).hidden=!1,l(this,Yt).style.zIndex=parseInt(l(this,Yt).style.zIndex)+1e3)},Jp=function(){l(this,Yt).classList.remove("focused"),!(l(this,Tn)||!this.isVisible)&&(l(this,Yt).hidden=!0,l(this,Yt).style.zIndex=parseInt(l(this,Yt).style.zIndex)-1e3)};class mb extends Kt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.textContent=t.data.textContent,this.textPosition=t.data.textPosition,this.annotationEditorType=ot.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 HC extends Kt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,pc,null)}render(){this.container.classList.add("lineAnnotation");const e=this.data,{width:s,height:i}=Jn(e.rect),n=this.svgFactory.create(s,i,!0),r=v(this,pc,this.svgFactory.createElement("svg:line"));return r.setAttribute("x1",e.rect[2]-e.lineCoordinates[0]),r.setAttribute("y1",e.rect[3]-e.lineCoordinates[1]),r.setAttribute("x2",e.rect[2]-e.lineCoordinates[2]),r.setAttribute("y2",e.rect[3]-e.lineCoordinates[3]),r.setAttribute("stroke-width",e.borderStyle.width||1),r.setAttribute("stroke","transparent"),r.setAttribute("fill","transparent"),n.append(r),this.container.append(n),!e.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,pc)}addHighlightArea(){this.container.classList.add("highlightArea")}}pc=new WeakMap;class zC extends Kt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,mc,null)}render(){this.container.classList.add("squareAnnotation");const e=this.data,{width:s,height:i}=Jn(e.rect),n=this.svgFactory.create(s,i,!0),r=e.borderStyle.width,a=v(this,mc,this.svgFactory.createElement("svg:rect"));return a.setAttribute("x",r/2),a.setAttribute("y",r/2),a.setAttribute("width",s-r),a.setAttribute("height",i-r),a.setAttribute("stroke-width",r||1),a.setAttribute("stroke","transparent"),a.setAttribute("fill","transparent"),n.append(a),this.container.append(n),!e.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,mc)}addHighlightArea(){this.container.classList.add("highlightArea")}}mc=new WeakMap;class VC extends Kt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,vc,null)}render(){this.container.classList.add("circleAnnotation");const e=this.data,{width:s,height:i}=Jn(e.rect),n=this.svgFactory.create(s,i,!0),r=e.borderStyle.width,a=v(this,vc,this.svgFactory.createElement("svg:ellipse"));return a.setAttribute("cx",s/2),a.setAttribute("cy",i/2),a.setAttribute("rx",s/2-r/2),a.setAttribute("ry",i/2-r/2),a.setAttribute("stroke-width",r||1),a.setAttribute("stroke","transparent"),a.setAttribute("fill","transparent"),n.append(a),this.container.append(n),!e.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,vc)}addHighlightArea(){this.container.classList.add("highlightArea")}}vc=new WeakMap;class vb extends Kt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,bc,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:a}=Jn(e),h=this.svgFactory.create(r,a,!0);let c=[];for(let d=0,f=s.length;d<f;d+=2){const g=s[d]-e[0],p=e[3]-s[d+1];c.push(`${g},${p}`)}c=c.join(" ");const u=v(this,bc,this.svgFactory.createElement(this.svgElementName));return u.setAttribute("points",c),u.setAttribute("stroke-width",i.width||1),u.setAttribute("stroke","transparent"),u.setAttribute("fill","transparent"),h.append(u),this.container.append(h),!n&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,bc)}addHighlightArea(){this.container.classList.add("highlightArea")}}bc=new WeakMap;class WC extends vb{constructor(t){super(t),this.containerClassName="polygonAnnotation",this.svgElementName="svg:polygon"}}class GC extends Kt{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 ep extends Kt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,_c);_(this,yc,null);_(this,Ia,[]);this.containerClassName="inkAnnotation",this.svgElementName="svg:polyline",this.annotationEditorType=this.data.it==="InkHighlight"?ot.HIGHLIGHT:ot.INK}render(){this.container.classList.add(this.containerClassName);const{data:{rect:e,rotation:s,inkLists:i,borderStyle:n,popupRef:r}}=this,{transform:a,width:h,height:c}=w(this,_c,Qp).call(this,s,e),u=this.svgFactory.create(h,c,!0),d=v(this,yc,this.svgFactory.createElement("svg:g"));u.append(d),d.setAttribute("stroke-width",n.width||1),d.setAttribute("stroke-linecap","round"),d.setAttribute("stroke-linejoin","round"),d.setAttribute("stroke-miterlimit",10),d.setAttribute("stroke","transparent"),d.setAttribute("fill","transparent"),d.setAttribute("transform",a);for(let f=0,g=i.length;f<g;f++){const p=this.svgFactory.createElement(this.svgElementName);l(this,Ia).push(p),p.setAttribute("points",i[f].join(",")),d.append(p)}return!r&&this.hasPopupData&&this._createPopup(),this.container.append(u),this._editOnDoubleClick(),this.container}updateEdited(e){super.updateEdited(e);const{thickness:s,points:i,rect:n}=e,r=l(this,yc);if(s>=0&&r.setAttribute("stroke-width",s||1),i)for(let a=0,h=l(this,Ia).length;a<h;a++)l(this,Ia)[a].setAttribute("points",i[a].join(","));if(n){const{transform:a,width:h,height:c}=w(this,_c,Qp).call(this,this.data.rotation,n);r.parentElement.setAttribute("viewBox",`0 0 ${h} ${c}`),r.setAttribute("transform",a)}}getElementsToTriggerPopup(){return l(this,Ia)}addHighlightArea(){this.container.classList.add("highlightArea")}}yc=new WeakMap,Ia=new WeakMap,_c=new WeakSet,Qp=function(e,s){switch(e){case 90:return{transform:`rotate(90) translate(${-s[0]},${s[1]}) scale(1,-1)`,width:s[3]-s[1],height:s[2]-s[0]};case 180:return{transform:`rotate(180) translate(${-s[2]},${s[1]}) scale(1,-1)`,width:s[2]-s[0],height:s[3]-s[1]};case 270:return{transform:`rotate(270) translate(${-s[2]},${s[3]}) scale(1,-1)`,width:s[3]-s[1],height:s[2]-s[0]};default:return{transform:`translate(${-s[0]},${s[3]}) scale(1,-1)`,width:s[2]-s[0],height:s[3]-s[1]}}};class bb extends Kt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0}),this.annotationEditorType=ot.HIGHLIGHT}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("highlightAnnotation"),this._editOnDoubleClick(),this.container}}class XC extends Kt{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 UC extends Kt{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 YC extends Kt{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 yb extends Kt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.annotationEditorType=ot.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 $C extends Kt{constructor(e){var i;super(e,{isRenderable:!0});_(this,xc);_(this,wc,null);const{file:s}=this.data;this.filename=s.filename,this.content=s.content,(i=this.linkService.eventBus)==null||i.dispatch("fileattachmentannotation",{source:this,...s})}render(){this.container.classList.add("fileAttachmentAnnotation");const{container:e,data:s}=this;let i;s.hasAppearance||s.fillAlpha===0?i=document.createElement("div"):(i=document.createElement("img"),i.src=`${this.imageResourcesPath}annotation-${/paperclip/i.test(s.name)?"paperclip":"pushpin"}.svg`,s.fillAlpha&&s.fillAlpha<1&&(i.style=`filter: opacity(${Math.round(s.fillAlpha*100)}%);`)),i.addEventListener("dblclick",w(this,xc,Zp).bind(this)),v(this,wc,i);const{isMac:n}=Ue.platform;return e.addEventListener("keydown",r=>{r.key==="Enter"&&(n?r.metaKey:r.ctrlKey)&&w(this,xc,Zp).call(this)}),!s.popupRef&&this.hasPopupData?this._createPopup():i.classList.add("popupTriggerArea"),e.append(i),e}getElementsToTriggerPopup(){return l(this,wc)}addHighlightArea(){this.container.classList.add("highlightArea")}}wc=new WeakMap,xc=new WeakSet,Zp=function(){var e;(e=this.downloadManager)==null||e.openOrDownloadData(this.content,this.filename)};class qC{constructor({div:t,accessibilityManager:e,annotationCanvasMap:s,annotationEditorUIManager:i,page:n,viewport:r,structTreeLayer:a}){_(this,Ba);_(this,Sc,null);_(this,ja,null);_(this,Na,new Map);_(this,Cc,null);this.div=t,v(this,Sc,e),v(this,ja,s),v(this,Cc,a||null),this.page=n,this.viewport=r,this.zIndex=0,this._annotationEditorUIManager=i}hasEditableAnnotations(){return l(this,Na).size>0}async render(t){var r;const{annotations:e}=t,s=this.div;Yr(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 Gg,enableScripting:t.enableScripting===!0,hasJSActions:t.hasJSActions,fieldObjects:t.fieldObjects,parent:this,elements:null};for(const a of e){if(a.noHTML)continue;const h=a.annotationType===le.POPUP;if(h){const d=i.get(a.id);if(!d)continue;n.elements=d}else{const{width:d,height:f}=Jn(a.rect);if(d<=0||f<=0)continue}n.data=a;const c=DC.create(n);if(!c.isRenderable)continue;if(!h&&a.popupRef){const d=i.get(a.popupRef);d?d.push(c):i.set(a.popupRef,[c])}const u=c.render();a.hidden&&(u.style.visibility="hidden"),await w(this,Ba,Ry).call(this,u,a.id),c._isEditable&&(l(this,Na).set(c.data.id,c),(r=this._annotationEditorUIManager)==null||r.renderAnnotationElement(c))}w(this,Ba,tm).call(this)}update({viewport:t}){const e=this.div;this.viewport=t,Yr(e,{rotation:t.rotation}),w(this,Ba,tm).call(this),e.hidden=!1}getEditableAnnotations(){return Array.from(l(this,Na).values())}getEditableAnnotation(t){return l(this,Na).get(t)}}Sc=new WeakMap,ja=new WeakMap,Na=new WeakMap,Cc=new WeakMap,Ba=new WeakSet,Ry=async function(t,e){var r,a;const s=t.firstChild||t,i=s.id=`${Fg}${e}`,n=await((r=l(this,Cc))==null?void 0:r.getAriaAttributes(i));if(n)for(const[h,c]of n)s.setAttribute(h,c);this.div.append(t),(a=l(this,Sc))==null||a.moveElementInDOM(this.div,t,s,!1)},tm=function(){if(!l(this,ja))return;const t=this.div;for(const[e,s]of l(this,ja)){const i=t.querySelector(`[data-annotation-id="${e}"]`);if(!i)continue;s.className="annotationContent";const{firstChild:n}=i;n?n.nodeName==="CANVAS"?n.replaceWith(s):n.classList.contains("annotationContent")?n.after(s):n.before(s):i.append(s)}l(this,ja).clear()};const Cd=/\r\n?|\n/g,Mt=class Mt extends Vt{constructor(e){super({...e,name:"freeTextEditor"});_(this,re);_(this,fi);_(this,As,"");_(this,Ac,`${this.id}-editor`);_(this,Ha,null);_(this,Ts);v(this,fi,e.color||Mt._defaultColor||Vt._defaultLineColor),v(this,Ts,e.fontSize||Mt._defaultFontSize)}static get _keyboardManager(){const e=Mt.prototype,s=r=>r.isEmpty(),i=$r.TRANSLATE_SMALL,n=$r.TRANSLATE_BIG;return ct(this,"_keyboardManager",new dl([[["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){Vt.initialize(e,s);const i=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(i.getPropertyValue("--freetext-padding"))}static updateDefaultParams(e,s){switch(e){case gt.FREETEXT_SIZE:Mt._defaultFontSize=s;break;case gt.FREETEXT_COLOR:Mt._defaultColor=s;break}}updateParams(e,s){switch(e){case gt.FREETEXT_SIZE:w(this,re,Fy).call(this,s);break;case gt.FREETEXT_COLOR:w(this,re,Ly).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[gt.FREETEXT_SIZE,Mt._defaultFontSize],[gt.FREETEXT_COLOR,Mt._defaultColor||Vt._defaultLineColor]]}get propertiesToUpdate(){return[[gt.FREETEXT_SIZE,l(this,Ts)],[gt.FREETEXT_COLOR,l(this,fi)]]}_translateEmpty(e,s){this._uiManager.translateSelectedEditors(e,s,!0)}getInitialTranslation(){const e=this.parentScale;return[-Mt._internalPadding*e,-(Mt._internalPadding+l(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(ot.FREETEXT),super.enableEditMode(),this.overlayDiv.classList.remove("enabled"),this.editorDiv.contentEditable=!0,this._isDraggable=!1,this.div.removeAttribute("aria-activedescendant"),v(this,Ha,new AbortController);const e=this._uiManager.combinedSignal(l(this,Ha));this.editorDiv.addEventListener("keydown",this.editorDivKeydown.bind(this),{signal:e}),this.editorDiv.addEventListener("focus",this.editorDivFocus.bind(this),{signal:e}),this.editorDiv.addEventListener("blur",this.editorDivBlur.bind(this),{signal:e}),this.editorDiv.addEventListener("input",this.editorDivInput.bind(this),{signal:e}),this.editorDiv.addEventListener("paste",this.editorDivPaste.bind(this),{signal:e})}disableEditMode(){var e;this.isInEditMode()&&(this.parent.setEditingState(!0),super.disableEditMode(),this.overlayDiv.classList.add("enabled"),this.editorDiv.contentEditable=!1,this.div.setAttribute("aria-activedescendant",l(this,Ac)),this._isDraggable=!0,(e=l(this,Ha))==null||e.abort(),v(this,Ha,null),this.div.focus({preventScroll:!0}),this.isEditing=!1,this.parent.div.classList.add("freetextEditing"))}focusin(e){this._focusEventsAllowed&&(super.focusin(e),e.target!==this.editorDiv&&this.editorDiv.focus())}onceAdded(e){var s;this.width||(this.enableEditMode(),e&&this.editorDiv.focus(),(s=this._initialOptions)!=null&&s.isCentered&&this.center(),this._initialOptions=null)}isEmpty(){return!this.editorDiv||this.editorDiv.innerText.trim()===""}remove(){this.isEditing=!1,this.parent&&(this.parent.setEditingState(!0),this.parent.div.classList.add("freetextEditing")),super.remove()}commit(){if(!this.isInEditMode())return;super.commit(),this.disableEditMode();const e=l(this,As),s=v(this,As,w(this,re,Iy).call(this).trimEnd());if(e===s)return;const i=n=>{if(v(this,As,n),!n){this.remove();return}w(this,re,bf).call(this),this._uiManager.rebuild(this),w(this,re,mf).call(this)};this.addCommands({cmd:()=>{i(s)},undo:()=>{i(e)},mustExec:!1}),w(this,re,mf).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){Mt._keyboardManager.exec(this,e)}editorDivFocus(e){this.isEditing=!0}editorDivBlur(e){this.isEditing=!1}editorDivInput(e){this.parent.div.classList.toggle("freetextEditing",this.isEmpty())}disableEditing(){this.editorDiv.setAttribute("role","comment"),this.editorDiv.removeAttribute("aria-multiline")}enableEditing(){this.editorDiv.setAttribute("role","textbox"),this.editorDiv.setAttribute("aria-multiline",!0)}render(){if(this.div)return this.div;let e,s;this.width&&(e=this.x,s=this.y),super.render(),this.editorDiv=document.createElement("div"),this.editorDiv.className="internal",this.editorDiv.setAttribute("id",l(this,Ac)),this.editorDiv.setAttribute("data-l10n-id","pdfjs-free-text2"),this.editorDiv.setAttribute("data-l10n-attrs","default-content"),this.enableEditing(),this.editorDiv.contentEditable=!0;const{style:i}=this.editorDiv;if(i.fontSize=`calc(${l(this,Ts)}px * var(--scale-factor))`,i.color=l(this,fi),this.div.append(this.editorDiv),this.overlayDiv=document.createElement("div"),this.overlayDiv.classList.add("overlay","enabled"),this.div.append(this.overlayDiv),md(this,this.div,["dblclick","keydown"]),this.width){const[n,r]=this.parentDimensions;if(this.annotationElementId){const{position:a}=this._initialData;let[h,c]=this.getInitialTranslation();[h,c]=this.pageTranslationToScreen(h,c);const[u,d]=this.pageDimensions,[f,g]=this.pageTranslation;let p,m;switch(this.rotation){case 0:p=e+(a[0]-f)/u,m=s+this.height-(a[1]-g)/d;break;case 90:p=e+(a[0]-f)/u,m=s-(a[1]-g)/d,[h,c]=[c,-h];break;case 180:p=e-this.width+(a[0]-f)/u,m=s-(a[1]-g)/d,[h,c]=[-h,-c];break;case 270:p=e+(a[0]-f-this.height*d)/u,m=s+(a[1]-g-this.width*u)/d,[h,c]=[-c,h];break}this.setAt(p*n,m*r,h,c)}else this.setAt(e*n,s*r,this.width*n,this.height*r);w(this,re,bf).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,y;const s=e.clipboardData||window.clipboardData,{types:i}=s;if(i.length===1&&i[0]==="text/plain")return;e.preventDefault();const n=w(p=Mt,Pn,em).call(p,s.getData("text")||"").replaceAll(Cd,`
531
- `);if(!n)return;const r=window.getSelection();if(!r.rangeCount)return;this.editorDiv.normalize(),r.deleteFromDocument();const a=r.getRangeAt(0);if(!n.includes(`
532
- `)){a.insertNode(document.createTextNode(n)),this.editorDiv.normalize(),r.collapseToStart();return}const{startContainer:h,startOffset:c}=a,u=[],d=[];if(h.nodeType===Node.TEXT_NODE){const b=h.parentElement;if(d.push(h.nodeValue.slice(c).replaceAll(Cd,"")),b!==this.editorDiv){let x=u;for(const S of this.editorDiv.childNodes){if(S===b){x=d;continue}x.push(w(m=Mt,Pn,vf).call(m,S))}}u.push(h.nodeValue.slice(0,c).replaceAll(Cd,""))}else if(h===this.editorDiv){let b=u,x=0;for(const S of this.editorDiv.childNodes)x++===c&&(b=d),b.push(w(y=Mt,Pn,vf).call(y,S))}v(this,As,`${u.join(`
533
+ `}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.vibrance;for(let i=0;i<e.length;i+=4){const n=e[i],r=e[i+1],o=e[i+2],h=Math.max(n,r,o),c=(n+r+o)/3,u=2*Math.abs(h-c)/255*s;e[i]+=h!==n?(h-n)*u:0,e[i+1]+=h!==r?(h-r)*u:0,e[i+2]+=h!==o?(h-o)*u:0}}sendUniformData(t,e){t.uniform1f(e.uVibrance,-this.vibrance)}isNeutralState(){return this.vibrance===0}}k(ld,"type","Vibrance"),k(ld,"defaults",{vibrance:0}),k(ld,"uniformLocations",["uVibrance"]),G.setClass(ld);let F0=null;function nS(){const a=document.createElement("div");a.style.width="1in",document.body.append(a);const t=a.offsetWidth;return a.remove(),t}function rS(){const a=F0??nS();return F0=a,a/72}function oS(a,t=500){if(typeof a!="function")throw new TypeError("The first argument is not a function.");let e=null;return function(...s){e&&clearTimeout(e),e=setTimeout(()=>{e=null,a.apply(this,s)},t)}}function aS(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 hS(i))}),i.addEventListener("error",n=>{window.URL.revokeObjectURL(s),e(n)})})}function hS(a){return new Promise(t=>{const e=document.createElement("canvas"),s=e.getContext("2d"),{naturalWidth:i,naturalHeight:n}=a;e.width=i,e.height=n,s==null||s.drawImage(a,0,0,i,n),t(e.toDataURL("image/jpeg",.8))})}var cl={};cl.d=(a,t)=>{for(var e in t)cl.o(t,e)&&!cl.o(a,e)&&Object.defineProperty(a,e,{enumerable:!0,get:t[e]})},cl.o=(a,t)=>Object.prototype.hasOwnProperty.call(a,t);var et=globalThis.pdfjsLib={};cl.d(et,{AbortException:()=>qn,AnnotationEditorLayer:()=>dp,AnnotationEditorParamsType:()=>gt,AnnotationEditorType:()=>at,AnnotationEditorUIManager:()=>qr,AnnotationLayer:()=>iA,AnnotationMode:()=>Yn,ColorPicker:()=>kd,DOMSVGFactory:()=>sp,DrawLayer:()=>fp,FeatureTest:()=>Ue,GlobalWorkerOptions:()=>hn,ImageKind:()=>cd,InvalidPDFException:()=>Rg,MissingPDFException:()=>dl,OPS:()=>ii,OutputScale:()=>Vg,PDFDataRangeTransport:()=>pb,PDFDateString:()=>Hg,PDFWorker:()=>Pa,PasswordResponses:()=>dS,PermissionFlag:()=>uS,PixelsPerInch:()=>Kn,RenderingCancelledException:()=>Ng,TextLayer:()=>bl,TouchManager:()=>_d,UnexpectedResponseException:()=>gd,Util:()=>q,VerbosityLevel:()=>ud,XfaLayer:()=>yb,build:()=>jC,createValidAbsoluteUrl:()=>mS,fetchData:()=>md,getDocument:()=>kC,getFilenameFromUrl:()=>AS,getPdfFilenameFromUrl:()=>TS,getXfaPageViewport:()=>ES,isDataScheme:()=>vd,isPdfFile:()=>Bg,noContextMenu:()=>ni,normalizeUnicode:()=>xS,setLayerDimensions:()=>$r,shadow:()=>ct,stopEvent:()=>bs,version:()=>IC});const Oe=typeof process=="object"&&process+""=="[object process]"&&!process.versions.nw&&!(process.versions.electron&&process.type&&process.type!=="browser"),L0=[1,0,0,1,0,0],Mg=[.001,0,0,.001,0,0],lS=1e7,Og=1.35,vs={ANY:1,DISPLAY:2,PRINT:4,ANNOTATIONS_FORMS:16,ANNOTATIONS_STORAGE:32,ANNOTATIONS_DISABLE:64,IS_EDITING:128,OPLIST:256},Yn={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},cS="pdfjs_internal_editor_",at={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15},gt={RESIZE:1,CREATE:2,FREETEXT_SIZE:11,FREETEXT_COLOR:12,FREETEXT_OPACITY:13,INK_COLOR:21,INK_THICKNESS:22,INK_OPACITY:23,HIGHLIGHT_COLOR:31,HIGHLIGHT_DEFAULT_COLOR:32,HIGHLIGHT_THICKNESS:33,HIGHLIGHT_FREE:34,HIGHLIGHT_SHOW_ALL:35,DRAW_STEP:41},uS={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},De={FILL:0,STROKE:1,FILL_STROKE:2,INVISIBLE:3,FILL_STROKE_MASK:3,ADD_TO_PATH_FLAG:4},cd={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},le={TEXT:1,LINK:2,FREETEXT:3,LINE:4,SQUARE:5,CIRCLE:6,POLYGON:7,POLYLINE:8,HIGHLIGHT:9,UNDERLINE:10,SQUIGGLY:11,STRIKEOUT:12,STAMP:13,CARET:14,INK:15,POPUP:16,FILEATTACHMENT:17,WIDGET:20},ul={SOLID:1,DASHED:2,BEVELED:3,INSET:4,UNDERLINE:5},ud={ERRORS:0,WARNINGS:1,INFOS:5},ii={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},dS={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};let dd=ud.WARNINGS;function fS(a){Number.isInteger(a)&&(dd=a)}function gS(){return dd}function fd(a){dd>=ud.INFOS&&console.log(`Info: ${a}`)}function ht(a){dd>=ud.WARNINGS&&console.log(`Warning: ${a}`)}function Pt(a){throw new Error(a)}function ie(a,t){a||Pt(t)}function pS(a){switch(a==null?void 0:a.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}function mS(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=wS(a)}catch{}}const s=t?new URL(a,t):new URL(a);if(pS(s))return s}catch{}return null}function ct(a,t,e,s=!1){return Object.defineProperty(a,t,{value:e,enumerable:!s,configurable:!0,writable:!1}),e}const $n=function(){function t(e,s){this.message=e,this.name=s}return t.prototype=new Error,t.constructor=t,t}();class I0 extends $n{constructor(t,e){super(t,"PasswordException"),this.code=e}}class Dg extends $n{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}}class Rg extends $n{constructor(t){super(t,"InvalidPDFException")}}class dl extends $n{constructor(t){super(t,"MissingPDFException")}}class gd extends $n{constructor(t,e){super(t,"UnexpectedResponseException"),this.status=e}}class vS extends $n{constructor(t){super(t,"FormatError")}}class qn extends $n{constructor(t){super(t,"AbortException")}}function j0(a){(typeof a!="object"||(a==null?void 0:a.length)===void 0)&&Pt("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 pd(a){typeof a!="string"&&Pt("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 bS(a){return String.fromCharCode(a>>24&255,a>>16&255,a>>8&255,a&255)}function Fg(a){const t=Object.create(null);for(const[e,s]of a)t[e]=s;return t}function yS(){const a=new Uint8Array(4);return a[0]=1,new Uint32Array(a.buffer,0,1)[0]===1}function _S(){try{return new Function(""),!0}catch{return!1}}class Ue{static get isLittleEndian(){return ct(this,"isLittleEndian",yS())}static get isEvalSupported(){return ct(this,"isEvalSupported",_S())}static get isOffscreenCanvasSupported(){return ct(this,"isOffscreenCanvasSupported",typeof OffscreenCanvas<"u")}static get isImageDecoderSupported(){return ct(this,"isImageDecoderSupported",typeof ImageDecoder<"u")}static get platform(){return typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.platform)=="string"?ct(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")}):ct(this,"platform",{isMac:!1,isWindows:!1,isFirefox:!1})}static get isCSSRoundSupported(){var t,e;return ct(this,"isCSSRoundSupported",(e=(t=globalThis.CSS)==null?void 0:t.supports)==null?void 0:e.call(t,"width: round(1.5px, 1px)"))}}const Lg=Array.from(Array(256).keys(),a=>a.toString(16).padStart(2,"0"));class q{static makeHexColor(t,e,s){return`#${Lg[t]}${Lg[e]}${Lg[s]}`}static scaleMinMax(t,e){let s;t[0]?(t[0]<0&&(s=e[0],e[0]=e[2],e[2]=s),e[0]*=t[0],e[2]*=t[0],t[3]<0&&(s=e[1],e[1]=e[3],e[3]=s),e[1]*=t[3],e[3]*=t[3]):(s=e[0],e[0]=e[1],e[1]=s,s=e[2],e[2]=e[3],e[3]=s,t[1]<0&&(s=e[1],e[1]=e[3],e[3]=s),e[1]*=t[1],e[3]*=t[1],t[2]<0&&(s=e[0],e[0]=e[2],e[2]=s),e[0]*=t[2],e[2]*=t[2]),e[0]+=t[4],e[1]+=t[5],e[2]+=t[4],e[3]+=t[5]}static transform(t,e){return[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],t[0]*e[4]+t[2]*e[5]+t[4],t[1]*e[4]+t[3]*e[5]+t[5]]}static applyTransform(t,e){const s=t[0]*e[0]+t[1]*e[2]+e[4],i=t[0]*e[1]+t[1]*e[3]+e[5];return[s,i]}static applyInverseTransform(t,e){const s=e[0]*e[3]-e[1]*e[2],i=(t[0]*e[3]-t[1]*e[2]+e[2]*e[5]-e[4]*e[3])/s,n=(-t[0]*e[1]+t[1]*e[0]+e[4]*e[1]-e[5]*e[0])/s;return[i,n]}static getAxialAlignedBoundingBox(t,e){const s=this.applyTransform(t,e),i=this.applyTransform(t.slice(2,4),e),n=this.applyTransform([t[0],t[3]],e),r=this.applyTransform([t[2],t[1]],e);return[Math.min(s[0],i[0],n[0],r[0]),Math.min(s[1],i[1],n[1],r[1]),Math.max(s[0],i[0],n[0],r[0]),Math.max(s[1],i[1],n[1],r[1])]}static inverseTransform(t){const e=t[0]*t[3]-t[1]*t[2];return[t[3]/e,-t[1]/e,-t[2]/e,t[0]/e,(t[2]*t[5]-t[4]*t[3])/e,(t[4]*t[1]-t[5]*t[0])/e]}static singularValueDecompose2dScale(t){const e=[t[0],t[2],t[1],t[3]],s=t[0]*e[0]+t[1]*e[2],i=t[0]*e[1]+t[1]*e[3],n=t[2]*e[0]+t[3]*e[2],r=t[2]*e[1]+t[3]*e[3],o=(s+r)/2,h=Math.sqrt((s+r)**2-4*(s*r-n*i))/2,c=o+h||1,u=o-h||1;return[Math.sqrt(c),Math.sqrt(u)]}static normalizeRect(t){const e=t.slice(0);return t[0]>t[2]&&(e[0]=t[2],e[2]=t[0]),t[1]>t[3]&&(e[1]=t[3],e[3]=t[1]),e}static intersect(t,e){const s=Math.max(Math.min(t[0],t[2]),Math.min(e[0],e[2])),i=Math.min(Math.max(t[0],t[2]),Math.max(e[0],e[2]));if(s>i)return null;const n=Math.max(Math.min(t[1],t[3]),Math.min(e[1],e[3])),r=Math.min(Math.max(t[1],t[3]),Math.max(e[1],e[3]));return n>r?null:[s,n,i,r]}static bezierBoundingBox(t,e,s,i,n,r,o,h,c){return c?(c[0]=Math.min(c[0],t,o),c[1]=Math.min(c[1],e,h),c[2]=Math.max(c[2],t,o),c[3]=Math.max(c[3],e,h)):c=[Math.min(t,o),Math.min(e,h),Math.max(t,o),Math.max(e,h)],w(this,ln,Ep).call(this,t,s,n,o,e,i,r,h,3*(-t+3*(s-n)+o),6*(t-2*s+n),3*(s-t),c),w(this,ln,Ep).call(this,t,s,n,o,e,i,r,h,3*(-e+3*(i-r)+h),6*(e-2*i+r),3*(i-e),c),c}}ln=new WeakSet,tf=function(t,e,s,i,n,r,o,h,c,u){if(c<=0||c>=1)return;const d=1-c,f=c*c,g=f*c,p=d*(d*(d*t+3*c*e)+3*f*s)+g*i,m=d*(d*(d*n+3*c*r)+3*f*o)+g*h;u[0]=Math.min(u[0],p),u[1]=Math.min(u[1],m),u[2]=Math.max(u[2],p),u[3]=Math.max(u[3],m)},Ep=function(t,e,s,i,n,r,o,h,c,u,d,f){if(Math.abs(c)<1e-12){Math.abs(u)>=1e-12&&w(this,ln,tf).call(this,t,e,s,i,n,r,o,h,-d/u,f);return}const g=u**2-4*d*c;if(g<0)return;const p=Math.sqrt(g),m=2*c;w(this,ln,tf).call(this,t,e,s,i,n,r,o,h,(-u+p)/m,f),w(this,ln,tf).call(this,t,e,s,i,n,r,o,h,(-u-p)/m,f)},_(q,ln);function wS(a){return decodeURIComponent(escape(a))}let Ig=null,N0=null;function xS(a){return Ig||(Ig=/([\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,N0=new Map([["ſt","ſt"]])),a.replaceAll(Ig,(t,e,s)=>e?e.normalize("NFKC"):N0.get(s))}function SS(){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();const a=new Uint8Array(32);return crypto.getRandomValues(a),j0(a)}const jg="pdfjs_internal_id_";function CS(a){return Uint8Array.prototype.toBase64?a.toBase64():btoa(j0(a))}typeof Promise.try!="function"&&(Promise.try=function(a,...t){return new Promise(e=>{e(a(...t))})});const an="http://www.w3.org/2000/svg",Qr=class Qr{};Q(Qr,"CSS",96),Q(Qr,"PDF",72),Q(Qr,"PDF_TO_CSS_UNITS",Qr.CSS/Qr.PDF);let Kn=Qr;async function md(a,t="text"){if(gl(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 fl{constructor({viewBox:t,userUnit:e,scale:s,rotation:i,offsetX:n=0,offsetY:r=0,dontFlip:o=!1}){this.viewBox=t,this.userUnit=e,this.scale=s,this.rotation=i,this.offsetX=n,this.offsetY=r,s*=e;const h=(t[2]+t[0])/2,c=(t[3]+t[1])/2;let u,d,f,g;switch(i%=360,i<0&&(i+=360),i){case 180:u=-1,d=0,f=0,g=1;break;case 90:u=0,d=1,f=1,g=0;break;case 270:u=0,d=-1,f=-1,g=0;break;case 0:u=1,d=0,f=0,g=-1;break;default:throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.")}o&&(f=-f,g=-g);let p,m,y,b;u===0?(p=Math.abs(c-t[1])*s+n,m=Math.abs(h-t[0])*s+r,y=(t[3]-t[1])*s,b=(t[2]-t[0])*s):(p=Math.abs(h-t[0])*s+n,m=Math.abs(c-t[1])*s+r,y=(t[2]-t[0])*s,b=(t[3]-t[1])*s),this.transform=[u*s,d*s,f*s,g*s,p-u*s*h-f*s*c,m-d*s*h-g*s*c],this.width=y,this.height=b}get rawDims(){const{userUnit:t,viewBox:e}=this,s=e.map(i=>i*t);return ct(this,"rawDims",{pageWidth:s[2]-s[0],pageHeight:s[3]-s[1],pageX:s[0],pageY:s[1]})}clone({scale:t=this.scale,rotation:e=this.rotation,offsetX:s=this.offsetX,offsetY:i=this.offsetY,dontFlip:n=!1}={}){return new fl({viewBox:this.viewBox.slice(),userUnit:this.userUnit,scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}convertToViewportPoint(t,e){return q.applyTransform([t,e],this.transform)}convertToViewportRectangle(t){const e=q.applyTransform([t[0],t[1]],this.transform),s=q.applyTransform([t[2],t[3]],this.transform);return[e[0],e[1],s[0],s[1]]}convertToPdfPoint(t,e){return q.applyInverseTransform([t,e],this.transform)}}class Ng extends $n{constructor(t,e=0){super(t,"RenderingCancelledException"),this.extraDelay=e}}function vd(a){const t=a.length;let e=0;for(;e<t&&a[e].trim()==="";)e++;return a.substring(e,e+5).toLowerCase()==="data:"}function Bg(a){return typeof a=="string"&&/\.pdf$/i.test(a)}function AS(a){return[a]=a.split(/[#?]/,1),a.substring(a.lastIndexOf("/")+1)}function TS(a,t="document.pdf"){if(typeof a!="string")return t;if(vd(a))return ht('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 B0{constructor(){Q(this,"started",Object.create(null));Q(this,"times",[])}time(t){t in this.started&&ht(`Timer is already running for ${t}`),this.started[t]=Date.now()}timeEnd(t){t in this.started||ht(`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
534
+ `);return t.join("")}}function gl(a,t){try{const{protocol:e}=t?new URL(a,t):new URL(a);return e==="http:"||e==="https:"}catch{return!1}}function ni(a){a.preventDefault()}function bs(a){a.preventDefault(),a.stopPropagation()}class Hg{static toDateObject(t){if(!t||typeof t!="string")return null;l(this,Sl)||v(this,Sl,new RegExp("^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+|-])?(\\d{2})?'?(\\d{2})?'?"));const e=l(this,Sl).exec(t);if(!e)return null;const s=parseInt(e[1],10);let i=parseInt(e[2],10);i=i>=1&&i<=12?i-1:0;let n=parseInt(e[3],10);n=n>=1&&n<=31?n:1;let r=parseInt(e[4],10);r=r>=0&&r<=23?r:0;let o=parseInt(e[5],10);o=o>=0&&o<=59?o:0;let h=parseInt(e[6],10);h=h>=0&&h<=59?h:0;const c=e[7]||"Z";let u=parseInt(e[8],10);u=u>=0&&u<=23?u:0;let d=parseInt(e[9],10)||0;return d=d>=0&&d<=59?d:0,c==="-"?(r+=u,o+=d):c==="+"&&(r-=u,o-=d),new Date(Date.UTC(s,i,n,r,o,h))}}Sl=new WeakMap,_(Hg,Sl);function ES(a,{scale:t=1,rotation:e=0}){const{width:s,height:i}=a.attributes.style,n=[0,0,parseInt(s),parseInt(i)];return new fl({viewBox:n,userUnit:1,scale:t,rotation:e})}function zg(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):(ht(`Not a valid color format: "${a}"`),[0,0,0])}function kS(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,zg(s))}t.remove()}function It(a){const{a:t,b:e,c:s,d:i,e:n,f:r}=a.getTransform();return[t,e,s,i,n,r]}function ki(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 $r(a,t,e=!1,s=!0){if(t instanceof fl){const{pageWidth:i,pageHeight:n}=t.rawDims,{style:r}=a,o=Ue.isCSSRoundSupported,h=`var(--scale-factor) * ${i}px`,c=`var(--scale-factor) * ${n}px`,u=o?`round(down, ${h}, var(--scale-round-x, 1px))`:`calc(${h})`,d=o?`round(down, ${c}, var(--scale-round-y, 1px))`:`calc(${c})`;!e||t.rotation%180===0?(r.width=u,r.height=d):(r.width=d,r.height=u)}s&&a.setAttribute("data-main-rotation",t.rotation)}class Vg{constructor(){const t=window.devicePixelRatio||1;this.sx=t,this.sy=t}get scaled(){return this.sx!==1||this.sy!==1}get symmetric(){return this.sx===this.sy}}const cn=class cn{constructor(t){_(this,Ye);_(this,Qn,null);_(this,Zr,null);_(this,ri);_(this,to,null);_(this,Cl,null);v(this,ri,t),l(cn,Al)||v(cn,Al,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=v(this,Qn,document.createElement("div"));t.classList.add("editToolbar","hidden"),t.setAttribute("role","toolbar");const e=l(this,ri)._uiManager._signal;t.addEventListener("contextmenu",ni,{signal:e}),t.addEventListener("pointerdown",w(cn,Od,qb),{signal:e});const s=v(this,to,document.createElement("div"));s.className="buttons",t.append(s);const i=l(this,ri).toolbarPosition;if(i){const{style:n}=t,r=l(this,ri)._uiManager.direction==="ltr"?1-i[0]:i[0];n.insetInlineEnd=`${100*r}%`,n.top=`calc(${100*i[1]}% + var(--editor-toolbar-vert-offset))`}return w(this,Ye,Qb).call(this),t}get div(){return l(this,Qn)}hide(){var t;l(this,Qn).classList.add("hidden"),(t=l(this,Zr))==null||t.hideDropdown()}show(){var t;l(this,Qn).classList.remove("hidden"),(t=l(this,Cl))==null||t.shown()}async addAltText(t){const e=await t.render();w(this,Ye,ef).call(this,e),l(this,to).prepend(e,l(this,Ye,kp)),v(this,Cl,t)}addColorPicker(t){v(this,Zr,t);const e=t.renderButton();w(this,Ye,ef).call(this,e),l(this,to).prepend(e,l(this,Ye,kp))}remove(){var t;l(this,Qn).remove(),(t=l(this,Zr))==null||t.destroy(),v(this,Zr,null)}};Qn=new WeakMap,Zr=new WeakMap,ri=new WeakMap,to=new WeakMap,Cl=new WeakMap,Al=new WeakMap,Od=new WeakSet,qb=function(t){t.stopPropagation()},Ye=new WeakSet,Kb=function(t){l(this,ri)._focusEventsAllowed=!1,bs(t)},Jb=function(t){l(this,ri)._focusEventsAllowed=!0,bs(t)},ef=function(t){const e=l(this,ri)._uiManager._signal;t.addEventListener("focusin",w(this,Ye,Kb).bind(this),{capture:!0,signal:e}),t.addEventListener("focusout",w(this,Ye,Jb).bind(this),{capture:!0,signal:e}),t.addEventListener("contextmenu",ni,{signal:e})},Qb=function(){const{editorType:t,_uiManager:e}=l(this,ri),s=document.createElement("button");s.className="delete",s.tabIndex=0,s.setAttribute("data-l10n-id",l(cn,Al)[t]),w(this,Ye,ef).call(this,s),s.addEventListener("click",i=>{e.delete()},{signal:e._signal}),l(this,to).append(s)},kp=function(){const t=document.createElement("div");return t.className="divider",t},_(cn,Od),_(cn,Al,null);let Gg=cn;class PS{constructor(t){_(this,Zn);_(this,Tl,null);_(this,eo,null);_(this,so);v(this,so,t)}show(t,e,s){const[i,n]=w(this,Zn,ty).call(this,e,s),{style:r}=l(this,eo)||v(this,eo,w(this,Zn,Zb).call(this));t.append(l(this,eo)),r.insetInlineEnd=`${100*i}%`,r.top=`calc(${100*n}% + var(--editor-toolbar-vert-offset))`}hide(){l(this,eo).remove()}}Tl=new WeakMap,eo=new WeakMap,so=new WeakMap,Zn=new WeakSet,Zb=function(){const t=v(this,eo,document.createElement("div"));t.className="editToolbar",t.setAttribute("role","toolbar"),t.addEventListener("contextmenu",ni,{signal:l(this,so)._signal});const e=v(this,Tl,document.createElement("div"));return e.className="buttons",t.append(e),w(this,Zn,ey).call(this),t},ty=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]},ey=function(){const t=document.createElement("button");t.className="highlightButton",t.tabIndex=0,t.setAttribute("data-l10n-id","pdfjs-highlight-floating-button1");const e=document.createElement("span");t.append(e),e.className="visuallyHidden",e.setAttribute("data-l10n-id","pdfjs-highlight-floating-button-label");const s=l(this,so)._signal;t.addEventListener("contextmenu",ni,{signal:s}),t.addEventListener("click",()=>{l(this,so).highlightSelection("floating_button")},{signal:s}),l(this,Tl).append(t)};function bd(a,t,e){for(const s of e)t.addEventListener(s,a[s].bind(a))}class MS{constructor(){_(this,Dd,0)}get id(){return`${cS}${es(this,Dd)._++}`}}Dd=new WeakMap;const pp=class pp{constructor(){_(this,Oa);_(this,Ma,SS());_(this,El,0);_(this,Fe,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 ct(this,"_isSVGFittingCanvas",n)}async getFromFile(t){const{lastModified:e,name:s,size:i,type:n}=t;return w(this,Oa,sf).call(this,`${e}_${s}_${i}_${n}`,t)}async getFromUrl(t){return w(this,Oa,sf).call(this,t,t)}async getFromBlob(t,e){const s=await e;return w(this,Oa,sf).call(this,t,s)}async getFromId(t){l(this,Fe)||v(this,Fe,new Map);const e=l(this,Fe).get(t);if(!e)return null;if(e.bitmap)return e.refCounter+=1,e;if(e.file)return this.getFromFile(e.file);if(e.blobPromise){const{blobPromise:s}=e;return delete e.blobPromise,this.getFromBlob(e.id,s)}return this.getFromUrl(e.url)}getFromCanvas(t,e){l(this,Fe)||v(this,Fe,new Map);let s=l(this,Fe).get(t);if(s!=null&&s.bitmap)return s.refCounter+=1,s;const i=new OffscreenCanvas(e.width,e.height);return i.getContext("2d").drawImage(e,0,0),s={bitmap:i.transferToImageBitmap(),id:`image_${l(this,Ma)}_${es(this,El)._++}`,refCounter:1,isSvg:!1},l(this,Fe).set(t,s),l(this,Fe).set(s.id,s),s}getSvgUrl(t){const e=l(this,Fe).get(t);return e!=null&&e.isSvg?e.svgUrl:null}deleteId(t){var i;l(this,Fe)||v(this,Fe,new Map);const e=l(this,Fe).get(t);if(!e||(e.refCounter-=1,e.refCounter!==0))return;const{bitmap:s}=e;if(!e.url&&!e.file){const n=new OffscreenCanvas(s.width,s.height);n.getContext("bitmaprenderer").transferFromImageBitmap(s),e.blobPromise=n.convertToBlob()}(i=s.close)==null||i.call(s),e.bitmap=null}isValidId(t){return t.startsWith(`image_${l(this,Ma)}_`)}};Ma=new WeakMap,El=new WeakMap,Fe=new WeakMap,Oa=new WeakSet,sf=async function(t,e){l(this,Fe)||v(this,Fe,new Map);let s=l(this,Fe).get(t);if(s===null)return null;if(s!=null&&s.bitmap)return s.refCounter+=1,s;try{s||(s={bitmap:null,id:`image_${l(this,Ma)}_${es(this,El)._++}`,refCounter:0,isSvg:!1});let i;if(typeof e=="string"?(s.url=e,i=await md(e,"blob")):e instanceof File?i=s.file=e:e instanceof Blob&&(i=e),i.type==="image/svg+xml"){const n=pp._isSVGFittingCanvas,r=new FileReader,o=new Image,h=new Promise((c,u)=>{o.onload=()=>{s.bitmap=o,s.isSvg=!0,c()},r.onload=async()=>{const d=s.svgUrl=r.result;o.src=await n?`${d}#svgView(preserveAspectRatio(none))`:d},o.onerror=r.onerror=u});r.readAsDataURL(i),await h}else s.bitmap=await createImageBitmap(i);s.refCounter=1}catch(i){ht(i),s=null}return l(this,Fe).set(t,s),s&&l(this,Fe).set(s.id,s),s};let Wg=pp;class OS{constructor(t=128){_(this,Jt,[]);_(this,tr,!1);_(this,kl);_(this,Gt,-1);v(this,kl,t)}add({cmd:t,undo:e,post:s,mustExec:i,type:n=NaN,overwriteIfSameType:r=!1,keepUndo:o=!1}){if(i&&t(),l(this,tr))return;const h={cmd:t,undo:e,post:s,type:n};if(l(this,Gt)===-1){l(this,Jt).length>0&&(l(this,Jt).length=0),v(this,Gt,0),l(this,Jt).push(h);return}if(r&&l(this,Jt)[l(this,Gt)].type===n){o&&(h.undo=l(this,Jt)[l(this,Gt)].undo),l(this,Jt)[l(this,Gt)]=h;return}const c=l(this,Gt)+1;c===l(this,kl)?l(this,Jt).splice(0,1):(v(this,Gt,c),c<l(this,Jt).length&&l(this,Jt).splice(c)),l(this,Jt).push(h)}undo(){if(l(this,Gt)===-1)return;v(this,tr,!0);const{undo:t,post:e}=l(this,Jt)[l(this,Gt)];t(),e==null||e(),v(this,tr,!1),v(this,Gt,l(this,Gt)-1)}redo(){if(l(this,Gt)<l(this,Jt).length-1){v(this,Gt,l(this,Gt)+1),v(this,tr,!0);const{cmd:t,post:e}=l(this,Jt)[l(this,Gt)];t(),e==null||e(),v(this,tr,!1)}}hasSomethingToUndo(){return l(this,Gt)!==-1}hasSomethingToRedo(){return l(this,Gt)<l(this,Jt).length-1}cleanType(t){if(l(this,Gt)!==-1){for(let e=l(this,Gt);e>=0;e--)if(l(this,Jt)[e].type!==t){l(this,Jt).splice(e+1,l(this,Gt)-e),v(this,Gt,e);return}l(this,Jt).length=0,v(this,Gt,-1)}}destroy(){v(this,Jt,null)}}Jt=new WeakMap,tr=new WeakMap,kl=new WeakMap,Gt=new WeakMap;class pl{constructor(t){_(this,Rd);this.buffer=[],this.callbacks=new Map,this.allKeys=new Set;const{isMac:e}=Ue.platform;for(const[s,i,n={}]of t)for(const r of s){const o=r.startsWith("mac+");e&&o?(this.callbacks.set(r.slice(4),{callback:i,options:n}),this.allKeys.add(r.split("+").at(-1))):!e&&!o&&(this.callbacks.set(r,{callback:i,options:n}),this.allKeys.add(r.split("+").at(-1)))}}exec(t,e){if(!this.allKeys.has(e.key))return;const s=this.callbacks.get(w(this,Rd,sy).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||bs(e))}}Rd=new WeakSet,sy=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 Fd=class Fd{get _colors(){const t=new Map([["CanvasText",null],["Canvas",null]]);return kS(t),ct(this,"_colors",t)}convert(t){const e=zg(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 Fd._colorsMapping.get(s);return e}getHexCode(t){const e=this._colors.get(t);return e?q.makeHexColor(...e):t}};Q(Fd,"_colorsMapping",new Map([["CanvasText",[0,0,0]],["Canvas",[255,255,255]]]));let Xg=Fd;const Na=class Na{constructor(t,e,s,i,n,r,o,h,c,u,d,f,g){_(this,B);_(this,Da,new AbortController);_(this,ys,null);_(this,ce,new Map);_(this,_e,new Map);_(this,Ra,null);_(this,un,null);_(this,Fa,null);_(this,js,new OS);_(this,er,null);_(this,io,null);_(this,La,0);_(this,no,new Set);_(this,Mi,null);_(this,oi,null);_(this,ro,new Set);Q(this,"_editorUndoBar",null);_(this,Pl,!1);_(this,Ml,!1);_(this,Ia,!1);_(this,Ol,null);_(this,Oi,null);_(this,sr,null);_(this,ja,null);_(this,ir,!1);_(this,Di,null);_(this,Ld,new MS);_(this,nr,!1);_(this,Dl,!1);_(this,rr,null);_(this,oo,null);_(this,Rl,null);_(this,Fl,null);_(this,ge,at.NONE);_(this,Ct,new Set);_(this,dn,null);_(this,ao,null);_(this,Ll,null);_(this,Il,{isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1});_(this,or,[0,0]);_(this,Ri,null);_(this,fn,null);_(this,jl,null);_(this,Ns,null);const p=this._signal=l(this,Da).signal;v(this,fn,t),v(this,jl,e),v(this,Ra,s),this._eventBus=i,i._on("editingaction",this.onEditingAction.bind(this),{signal:p}),i._on("pagechanging",this.onPageChanging.bind(this),{signal:p}),i._on("scalechanging",this.onScaleChanging.bind(this),{signal:p}),i._on("rotationchanging",this.onRotationChanging.bind(this),{signal:p}),i._on("setpreference",this.onSetPreference.bind(this),{signal:p}),i._on("switchannotationeditorparams",m=>this.updateParams(m.type,m.value),{signal:p}),w(this,B,ry).call(this),w(this,B,ly).call(this),w(this,B,Mp).call(this),v(this,un,n.annotationStorage),v(this,Ol,n.filterFactory),v(this,ao,r),v(this,ja,o||null),v(this,Pl,h),v(this,Ml,c),v(this,Ia,u),v(this,Fl,d||null),this.viewParameters={realScale:Kn.PDF_TO_CSS_UNITS,rotation:0},this.isShiftKeyDown=!1,this._editorUndoBar=f||null,this._supportsPinchToZoom=g!==!1}static get _keyboardManager(){const t=Na.prototype,e=r=>l(r,fn).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 ct(this,"_keyboardManager",new pl([[["ctrl+a","mac+meta+a"],t.selectAll,{checker:s}],[["ctrl+z","mac+meta+z"],t.undo,{checker:s}],[["ctrl+y","ctrl+shift+z","mac+meta+shift+z","ctrl+shift+Z","mac+meta+shift+Z"],t.redo,{checker:s}],[["Backspace","alt+Backspace","ctrl+Backspace","shift+Backspace","mac+Backspace","mac+alt+Backspace","mac+ctrl+Backspace","Delete","ctrl+Delete","shift+Delete","mac+Delete"],t.delete,{checker:s}],[["Enter","mac+Enter"],t.addNewEditorFromKeyboard,{checker:(r,{target:o})=>!(o instanceof HTMLButtonElement)&&l(r,fn).contains(o)&&!r.isEnterHandled}],[[" ","mac+ "],t.addNewEditorFromKeyboard,{checker:(r,{target:o})=>!(o instanceof HTMLButtonElement)&&l(r,fn).contains(document.activeElement)}],[["Escape","mac+Escape"],t.unselectAll],[["ArrowLeft","mac+ArrowLeft"],t.translateSelectedEditors,{args:[-i,0],checker:e}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t.translateSelectedEditors,{args:[-n,0],checker:e}],[["ArrowRight","mac+ArrowRight"],t.translateSelectedEditors,{args:[i,0],checker:e}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t.translateSelectedEditors,{args:[n,0],checker:e}],[["ArrowUp","mac+ArrowUp"],t.translateSelectedEditors,{args:[0,-i],checker:e}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t.translateSelectedEditors,{args:[0,-n],checker:e}],[["ArrowDown","mac+ArrowDown"],t.translateSelectedEditors,{args:[0,i],checker:e}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t.translateSelectedEditors,{args:[0,n],checker:e}]]))}destroy(){var t,e,s,i,n;(t=l(this,Ns))==null||t.resolve(),v(this,Ns,null),(e=l(this,Da))==null||e.abort(),v(this,Da,null),this._signal=null;for(const r of l(this,_e).values())r.destroy();l(this,_e).clear(),l(this,ce).clear(),l(this,ro).clear(),v(this,ys,null),l(this,Ct).clear(),l(this,js).destroy(),(s=l(this,Ra))==null||s.destroy(),(i=l(this,Di))==null||i.hide(),v(this,Di,null),l(this,Oi)&&(clearTimeout(l(this,Oi)),v(this,Oi,null)),l(this,Ri)&&(clearTimeout(l(this,Ri)),v(this,Ri,null)),(n=this._editorUndoBar)==null||n.destroy()}combinedSignal(t){return AbortSignal.any([this._signal,t.signal])}get mlManager(){return l(this,Fl)}get useNewAltTextFlow(){return l(this,Ml)}get useNewAltTextWhenAddingImage(){return l(this,Ia)}get hcmFilter(){return ct(this,"hcmFilter",l(this,ao)?l(this,Ol).addHCMFilter(l(this,ao).foreground,l(this,ao).background):"none")}get direction(){return ct(this,"direction",getComputedStyle(l(this,fn)).direction)}get highlightColors(){return ct(this,"highlightColors",l(this,ja)?new Map(l(this,ja).split(",").map(t=>t.split("=").map(e=>e.trim()))):null)}get highlightColorNames(){return ct(this,"highlightColorNames",this.highlightColors?new Map(Array.from(this.highlightColors,t=>t.reverse())):null)}setCurrentDrawingSession(t){t?(this.unselectAll(),this.disableUserSelect(!0)):this.disableUserSelect(!1),v(this,io,t)}setMainHighlightColorPicker(t){v(this,Rl,t)}editAltText(t,e=!1){var s;(s=l(this,Ra))==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":v(this,Ia,e);break}}onPageChanging({pageNumber:t}){v(this,La,t-1)}focusMainContainer(){l(this,fn).focus()}findParent(t,e){for(const s of l(this,_e).values()){const{x:i,y:n,width:r,height:o}=s.div.getBoundingClientRect();if(t>=i&&t<=i+r&&e>=n&&e<=n+o)return s}return null}disableUserSelect(t=!1){l(this,jl).classList.toggle("noUserSelect",t)}addShouldRescale(t){l(this,ro).add(t)}removeShouldRescale(t){l(this,ro).delete(t)}onScaleChanging({scale:t}){var e;this.commitOrRemove(),this.viewParameters.realScale=t*Kn.PDF_TO_CSS_UNITS;for(const s of l(this,ro))s.onScaleChanging();(e=l(this,io))==null||e.onScaleChanging()}onRotationChanging({pagesRotation:t}){this.commitOrRemove(),this.viewParameters.rotation=t}highlightSelection(t=""){const e=document.getSelection();if(!e||e.isCollapsed)return;const{anchorNode:s,anchorOffset:i,focusNode:n,focusOffset:r}=e,o=e.toString(),c=w(this,B,nf).call(this,e).closest(".textLayer"),u=this.getSelectionBoxes(c);if(!u)return;e.empty();const d=w(this,B,Pp).call(this,c),f=l(this,ge)===at.NONE,g=()=>{d==null||d.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:t,boxes:u,anchorNode:s,anchorOffset:i,focusNode:n,focusOffset:r,text:o}),f&&this.showAllEditors("highlight",!0,!0)};if(f){this.switchToMode(at.HIGHLIGHT,g);return}g()}addToAnnotationStorage(t){!t.isEmpty()&&l(this,un)&&!l(this,un).has(t.id)&&l(this,un).setValue(t.id,t)}blur(){if(this.isShiftKeyDown=!1,l(this,ir)&&(v(this,ir,!1),w(this,B,rf).call(this,"main_toolbar")),!this.hasSelection)return;const{activeElement:t}=document;for(const e of l(this,Ct))if(e.div.contains(t)){v(this,oo,[e,t]),e._focusEventsAllowed=!1;break}}focus(){if(!l(this,oo))return;const[t,e]=l(this,oo);v(this,oo,null),e.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this._signal}),e.focus()}addEditListeners(){w(this,B,Mp).call(this),w(this,B,Op).call(this)}removeEditListeners(){w(this,B,hy).call(this),w(this,B,Dp).call(this)}dragOver(t){for(const{type:e}of t.dataTransfer.items)for(const s of l(this,oi))if(s.isHandlingMimeForPasting(e)){t.dataTransfer.dropEffect="copy",t.preventDefault();return}}drop(t){for(const e of t.dataTransfer.items)for(const s of l(this,oi))if(s.isHandlingMimeForPasting(e.type)){s.paste(e,this.currentLayer),t.preventDefault();return}}copy(t){var s;if(t.preventDefault(),(s=l(this,ys))==null||s.commitOrRemove(),!this.hasSelection)return;const e=[];for(const i of l(this,Ct)){const n=i.serialize(!0);n&&e.push(n)}e.length!==0&&t.clipboardData.setData("application/pdfjs",JSON.stringify(e))}cut(t){this.copy(t),this.delete()}async paste(t){t.preventDefault();const{clipboardData:e}=t;for(const n of e.items)for(const r of l(this,oi))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){ht(`paste: "${n.message}".`);return}if(!Array.isArray(s))return;this.unselectAll();const i=this.currentLayer;try{const n=[];for(const h of s){const c=await i.deserialize(h);if(!c)return;n.push(c)}const r=()=>{for(const h of n)w(this,B,Rp).call(this,h);w(this,B,Fp).call(this,n)},o=()=>{for(const h of n)h.remove()};this.addCommands({cmd:r,undo:o,mustExec:!0})}catch(n){ht(`paste: "${n.message}".`)}}keydown(t){!this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!0),l(this,ge)!==at.NONE&&!this.isEditorHandlingKeyboard&&Na._keyboardManager.exec(this,t)}keyup(t){this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!1,l(this,ir)&&(v(this,ir,!1),w(this,B,rf).call(this,"main_toolbar")))}onEditingAction({name:t}){switch(t){case"undo":case"redo":case"delete":case"selectAll":this[t]();break;case"highlightSelection":this.highlightSelection("context_menu");break}}setEditingState(t){t?(w(this,B,oy).call(this),w(this,B,Op).call(this),w(this,B,ss).call(this,{isEditing:l(this,ge)!==at.NONE,isEmpty:w(this,B,Kc).call(this),hasSomethingToUndo:l(this,js).hasSomethingToUndo(),hasSomethingToRedo:l(this,js).hasSomethingToRedo(),hasSelectedEditor:!1})):(w(this,B,ay).call(this),w(this,B,Dp).call(this),w(this,B,ss).call(this,{isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(t){if(!l(this,oi)){v(this,oi,t);for(const e of l(this,oi))w(this,B,Hn).call(this,e.defaultPropertiesToUpdate)}}getId(){return l(this,Ld).id}get currentLayer(){return l(this,_e).get(l(this,La))}getLayer(t){return l(this,_e).get(t)}get currentPageIndex(){return l(this,La)}addLayer(t){l(this,_e).set(t.pageIndex,t),l(this,nr)?t.enable():t.disable()}removeLayer(t){l(this,_e).delete(t.pageIndex)}async updateMode(t,e=null,s=!1){var i;if(l(this,ge)!==t&&!(l(this,Ns)&&(await l(this,Ns).promise,!l(this,Ns)))){if(v(this,Ns,Promise.withResolvers()),v(this,ge,t),t===at.NONE){this.setEditingState(!1),w(this,B,uy).call(this),(i=this._editorUndoBar)==null||i.hide(),l(this,Ns).resolve();return}this.setEditingState(!0),await w(this,B,cy).call(this),this.unselectAll();for(const n of l(this,_e).values())n.updateMode(t);if(!e){s&&this.addNewEditorFromKeyboard(),l(this,Ns).resolve();return}for(const n of l(this,ce).values())n.annotationElementId===e?(this.setSelected(n),n.enterInEditMode()):n.unselect();l(this,Ns).resolve()}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(t){t!==l(this,ge)&&this._eventBus.dispatch("switchannotationeditormode",{source:this,mode:t})}updateParams(t,e){var s;if(l(this,oi)){switch(t){case gt.CREATE:this.currentLayer.addNewEditor();return;case gt.HIGHLIGHT_DEFAULT_COLOR:(s=l(this,Rl))==null||s.updateColor(e);break;case gt.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:{type:"highlight",action:"toggle_visibility"}}}),(l(this,Ll)||v(this,Ll,new Map)).set(t,e),this.showAllEditors("highlight",e);break}for(const i of l(this,Ct))i.updateParams(t,e);for(const i of l(this,oi))i.updateDefaultParams(t,e)}}showAllEditors(t,e,s=!1){var n;for(const r of l(this,ce).values())r.editorType===t&&r.show(e);(((n=l(this,Ll))==null?void 0:n.get(gt.HIGHLIGHT_SHOW_ALL))??!0)!==e&&w(this,B,Hn).call(this,[[gt.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(l(this,Dl)!==t){v(this,Dl,t);for(const e of l(this,_e).values())t?e.disableClick():e.enableClick(),e.div.classList.toggle("waiting",t)}}getEditors(t){const e=[];for(const s of l(this,ce).values())s.pageIndex===t&&e.push(s);return e}getEditor(t){return l(this,ce).get(t)}addEditor(t){l(this,ce).set(t.id,t)}removeEditor(t){var e;t.div.contains(document.activeElement)&&(l(this,Oi)&&clearTimeout(l(this,Oi)),v(this,Oi,setTimeout(()=>{this.focusMainContainer(),v(this,Oi,null)},0))),l(this,ce).delete(t.id),this.unselect(t),(!t.annotationElementId||!l(this,no).has(t.annotationElementId))&&((e=l(this,un))==null||e.remove(t.id))}addDeletedAnnotationElement(t){l(this,no).add(t.annotationElementId),this.addChangedExistingAnnotation(t),t.deleted=!0}isDeletedAnnotationElement(t){return l(this,no).has(t)}removeDeletedAnnotationElement(t){l(this,no).delete(t.annotationElementId),this.removeChangedExistingAnnotation(t),t.deleted=!1}setActiveEditor(t){l(this,ys)!==t&&(v(this,ys,t),t&&w(this,B,Hn).call(this,t.propertiesToUpdate))}updateUI(t){l(this,B,dy)===t&&w(this,B,Hn).call(this,t.propertiesToUpdate)}updateUIForDefaultProperties(t){w(this,B,Hn).call(this,t.defaultPropertiesToUpdate)}toggleSelected(t){if(l(this,Ct).has(t)){l(this,Ct).delete(t),t.unselect(),w(this,B,ss).call(this,{hasSelectedEditor:this.hasSelection});return}l(this,Ct).add(t),t.select(),w(this,B,Hn).call(this,t.propertiesToUpdate),w(this,B,ss).call(this,{hasSelectedEditor:!0})}setSelected(t){var e;(e=l(this,io))==null||e.commitOrRemove();for(const s of l(this,Ct))s!==t&&s.unselect();l(this,Ct).clear(),l(this,Ct).add(t),t.select(),w(this,B,Hn).call(this,t.propertiesToUpdate),w(this,B,ss).call(this,{hasSelectedEditor:!0})}isSelected(t){return l(this,Ct).has(t)}get firstSelectedEditor(){return l(this,Ct).values().next().value}unselect(t){t.unselect(),l(this,Ct).delete(t),w(this,B,ss).call(this,{hasSelectedEditor:this.hasSelection})}get hasSelection(){return l(this,Ct).size!==0}get isEnterHandled(){return l(this,Ct).size===1&&this.firstSelectedEditor.isEnterHandled}undo(){var t;l(this,js).undo(),w(this,B,ss).call(this,{hasSomethingToUndo:l(this,js).hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:w(this,B,Kc).call(this)}),(t=this._editorUndoBar)==null||t.hide()}redo(){l(this,js).redo(),w(this,B,ss).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:l(this,js).hasSomethingToRedo(),isEmpty:w(this,B,Kc).call(this)})}addCommands(t){l(this,js).add(t),w(this,B,ss).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:w(this,B,Kc).call(this)})}cleanUndoStack(t){l(this,js).cleanType(t)}delete(){var n;this.commitOrRemove();const t=(n=this.currentLayer)==null?void 0:n.endDrawingSession(!0);if(!this.hasSelection&&!t)return;const e=t?[t]:[...l(this,Ct)],s=()=>{var r;(r=this._editorUndoBar)==null||r.show(i,e.length===1?e[0].editorType:e.length);for(const o of e)o.remove()},i=()=>{for(const r of e)w(this,B,Rp).call(this,r)};this.addCommands({cmd:s,undo:i,mustExec:!0})}commitOrRemove(){var t;(t=l(this,ys))==null||t.commitOrRemove()}hasSomethingToControl(){return l(this,ys)||this.hasSelection}selectAll(){for(const t of l(this,Ct))t.commit();w(this,B,Fp).call(this,l(this,ce).values())}unselectAll(){var t;if(!(l(this,ys)&&(l(this,ys).commitOrRemove(),l(this,ge)!==at.NONE))&&!((t=l(this,io))!=null&&t.commitOrRemove())&&this.hasSelection){for(const e of l(this,Ct))e.unselect();l(this,Ct).clear(),w(this,B,ss).call(this,{hasSelectedEditor:!1})}}translateSelectedEditors(t,e,s=!1){if(s||this.commitOrRemove(),!this.hasSelection)return;l(this,or)[0]+=t,l(this,or)[1]+=e;const[i,n]=l(this,or),r=[...l(this,Ct)],o=1e3;l(this,Ri)&&clearTimeout(l(this,Ri)),v(this,Ri,setTimeout(()=>{v(this,Ri,null),l(this,or)[0]=l(this,or)[1]=0,this.addCommands({cmd:()=>{for(const h of r)l(this,ce).has(h.id)&&h.translateInPage(i,n)},undo:()=>{for(const h of r)l(this,ce).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),v(this,Mi,new Map);for(const t of l(this,Ct))l(this,Mi).set(t,{savedX:t.x,savedY:t.y,savedPageIndex:t.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!l(this,Mi))return!1;this.disableUserSelect(!1);const t=l(this,Mi);v(this,Mi,null);let e=!1;for(const[{x:i,y:n,pageIndex:r},o]of t)o.newX=i,o.newY=n,o.newPageIndex=r,e||(e=i!==o.savedX||n!==o.savedY||r!==o.savedPageIndex);if(!e)return!1;const s=(i,n,r,o)=>{if(l(this,ce).has(i.id)){const h=l(this,_e).get(o);h?i._setParentAndPosition(h,n,r):(i.pageIndex=o,i.x=n,i.y=r)}};return this.addCommands({cmd:()=>{for(const[i,{newX:n,newY:r,newPageIndex:o}]of t)s(i,n,r,o)},undo:()=>{for(const[i,{savedX:n,savedY:r,savedPageIndex:o}]of t)s(i,n,r,o)},mustExec:!0}),!0}dragSelectedEditors(t,e){if(l(this,Mi))for(const s of l(this,Mi).keys())s.drag(t,e)}rebuild(t){if(t.parent===null){const e=this.getLayer(t.pageIndex);e?(e.changeParent(t),e.addOrRebuild(t)):(this.addEditor(t),this.addToAnnotationStorage(t),t.rebuild())}else t.parent.addOrRebuild(t)}get isEditorHandlingKeyboard(){var t;return((t=this.getActive())==null?void 0:t.shouldGetKeyboardEvents())||l(this,Ct).size===1&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(t){return l(this,ys)===t}getActive(){return l(this,ys)}getMode(){return l(this,ge)}get imageManager(){return ct(this,"imageManager",new Wg)}getSelectionBoxes(t){if(!t)return null;const e=document.getSelection();for(let c=0,u=e.rangeCount;c<u;c++)if(!t.contains(e.getRangeAt(c).commonAncestorContainer))return null;const{x:s,y:i,width:n,height:r}=t.getBoundingClientRect();let o;switch(t.getAttribute("data-main-rotation")){case"90":o=(c,u,d,f)=>({x:(u-i)/r,y:1-(c+d-s)/n,width:f/r,height:d/n});break;case"180":o=(c,u,d,f)=>({x:1-(c+d-s)/n,y:1-(u+f-i)/r,width:d/n,height:f/r});break;case"270":o=(c,u,d,f)=>({x:1-(u+f-i)/r,y:(c-s)/n,width:f/r,height:d/n});break;default:o=(c,u,d,f)=>({x:(c-s)/n,y:(u-i)/r,width:d/n,height:f/r});break}const h=[];for(let c=0,u=e.rangeCount;c<u;c++){const d=e.getRangeAt(c);if(!d.collapsed)for(const{x:f,y:g,width:p,height:m}of d.getClientRects())p===0||m===0||h.push(o(f,g,p,m))}return h.length===0?null:h}addChangedExistingAnnotation({annotationElementId:t,id:e}){(l(this,Fa)||v(this,Fa,new Map)).set(t,e)}removeChangedExistingAnnotation({annotationElementId:t}){var e;(e=l(this,Fa))==null||e.delete(t)}renderAnnotationElement(t){var i;const e=(i=l(this,Fa))==null?void 0:i.get(t.data.id);if(!e)return;const s=l(this,un).getRawValue(e);s&&(l(this,ge)===at.NONE&&!s.hasBeenModified||s.renderAnnotationElement(t))}};Da=new WeakMap,ys=new WeakMap,ce=new WeakMap,_e=new WeakMap,Ra=new WeakMap,un=new WeakMap,Fa=new WeakMap,js=new WeakMap,er=new WeakMap,io=new WeakMap,La=new WeakMap,no=new WeakMap,Mi=new WeakMap,oi=new WeakMap,ro=new WeakMap,Pl=new WeakMap,Ml=new WeakMap,Ia=new WeakMap,Ol=new WeakMap,Oi=new WeakMap,sr=new WeakMap,ja=new WeakMap,ir=new WeakMap,Di=new WeakMap,Ld=new WeakMap,nr=new WeakMap,Dl=new WeakMap,rr=new WeakMap,oo=new WeakMap,Rl=new WeakMap,Fl=new WeakMap,ge=new WeakMap,Ct=new WeakMap,dn=new WeakMap,ao=new WeakMap,Ll=new WeakMap,Il=new WeakMap,or=new WeakMap,Ri=new WeakMap,fn=new WeakMap,jl=new WeakMap,Ns=new WeakMap,B=new WeakSet,nf=function({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t},Pp=function(t){const{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(const s of l(this,_e).values())if(s.hasTextLayer(t))return s;return null},iy=function(){const t=document.getSelection();if(!t||t.isCollapsed)return;const s=w(this,B,nf).call(this,t).closest(".textLayer"),i=this.getSelectionBoxes(s);i&&(l(this,Di)||v(this,Di,new PS(this)),l(this,Di).show(s,i,this.direction==="ltr"))},ny=function(){var n,r,o;const t=document.getSelection();if(!t||t.isCollapsed){l(this,dn)&&((n=l(this,Di))==null||n.hide(),v(this,dn,null),w(this,B,ss).call(this,{hasSelectedText:!1}));return}const{anchorNode:e}=t;if(e===l(this,dn))return;const i=w(this,B,nf).call(this,t).closest(".textLayer");if(!i){l(this,dn)&&((r=l(this,Di))==null||r.hide(),v(this,dn,null),w(this,B,ss).call(this,{hasSelectedText:!1}));return}if((o=l(this,Di))==null||o.hide(),v(this,dn,e),w(this,B,ss).call(this,{hasSelectedText:!0}),!(l(this,ge)!==at.HIGHLIGHT&&l(this,ge)!==at.NONE)&&(l(this,ge)===at.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0),v(this,ir,this.isShiftKeyDown),!this.isShiftKeyDown)){const h=l(this,ge)===at.HIGHLIGHT?w(this,B,Pp).call(this,i):null;h==null||h.toggleDrawing();const c=new AbortController,u=this.combinedSignal(c),d=f=>{f.type==="pointerup"&&f.button!==0||(c.abort(),h==null||h.toggleDrawing(!0),f.type==="pointerup"&&w(this,B,rf).call(this,"main_toolbar"))};window.addEventListener("pointerup",d,{signal:u}),window.addEventListener("blur",d,{signal:u})}},rf=function(t=""){l(this,ge)===at.HIGHLIGHT?this.highlightSelection(t):l(this,Pl)&&w(this,B,iy).call(this)},ry=function(){document.addEventListener("selectionchange",w(this,B,ny).bind(this),{signal:this._signal})},oy=function(){if(l(this,sr))return;v(this,sr,new AbortController);const t=this.combinedSignal(l(this,sr));window.addEventListener("focus",this.focus.bind(this),{signal:t}),window.addEventListener("blur",this.blur.bind(this),{signal:t})},ay=function(){var t;(t=l(this,sr))==null||t.abort(),v(this,sr,null)},Mp=function(){if(l(this,rr))return;v(this,rr,new AbortController);const t=this.combinedSignal(l(this,rr));window.addEventListener("keydown",this.keydown.bind(this),{signal:t}),window.addEventListener("keyup",this.keyup.bind(this),{signal:t})},hy=function(){var t;(t=l(this,rr))==null||t.abort(),v(this,rr,null)},Op=function(){if(l(this,er))return;v(this,er,new AbortController);const t=this.combinedSignal(l(this,er));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})},Dp=function(){var t;(t=l(this,er))==null||t.abort(),v(this,er,null)},ly=function(){const t=this._signal;document.addEventListener("dragover",this.dragOver.bind(this),{signal:t}),document.addEventListener("drop",this.drop.bind(this),{signal:t})},ss=function(t){Object.entries(t).some(([s,i])=>l(this,Il)[s]!==i)&&(this._eventBus.dispatch("annotationeditorstateschanged",{source:this,details:Object.assign(l(this,Il),t)}),l(this,ge)===at.HIGHLIGHT&&t.hasSelectedEditor===!1&&w(this,B,Hn).call(this,[[gt.HIGHLIGHT_FREE,!0]]))},Hn=function(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})},cy=async function(){if(!l(this,nr)){v(this,nr,!0);const t=[];for(const e of l(this,_e).values())t.push(e.enable());await Promise.all(t);for(const e of l(this,ce).values())e.enable()}},uy=function(){if(this.unselectAll(),l(this,nr)){v(this,nr,!1);for(const t of l(this,_e).values())t.disable();for(const t of l(this,ce).values())t.disable()}},Rp=function(t){const e=l(this,_e).get(t.pageIndex);e?e.addOrRebuild(t):(this.addEditor(t),this.addToAnnotationStorage(t))},dy=function(){let t=null;for(t of l(this,Ct));return t},Kc=function(){if(l(this,ce).size===0)return!0;if(l(this,ce).size===1)for(const t of l(this,ce).values())return t.isEmpty();return!1},Fp=function(t){for(const e of l(this,Ct))e.unselect();l(this,Ct).clear();for(const e of t)e.isEmpty()||(l(this,Ct).add(e),e.select());w(this,B,ss).call(this,{hasSelectedEditor:this.hasSelection})},Q(Na,"TRANSLATE_SMALL",1),Q(Na,"TRANSLATE_BIG",10);let qr=Na;const $e=class $e{constructor(t){_(this,hi);_(this,pe,null);_(this,Fi,!1);_(this,ai,null);_(this,Ba,null);_(this,Li,null);_(this,_s,null);_(this,Ha,!1);_(this,Ii,null);_(this,ls,null);_(this,gn,null);_(this,ho,null);_(this,ji,!1);v(this,ls,t),v(this,ji,t._uiManager.useNewAltTextFlow),l($e,ar)||v($e,ar,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){$e._l10n??($e._l10n=t)}async render(){const t=v(this,ai,document.createElement("button"));t.className="altText",t.tabIndex="0";const e=v(this,Ba,document.createElement("span"));t.append(e),l(this,ji)?(t.classList.add("new"),t.setAttribute("data-l10n-id",l($e,ar).missing),e.setAttribute("data-l10n-id",l($e,ar)["missing-label"])):(t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button"),e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button-label"));const s=l(this,ls)._uiManager._signal;t.addEventListener("contextmenu",ni,{signal:s}),t.addEventListener("pointerdown",n=>n.stopPropagation(),{signal:s});const i=n=>{n.preventDefault(),l(this,ls)._uiManager.editAltText(l(this,ls)),l(this,ji)&&l(this,ls)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_clicked",data:{label:l(this,hi,Jc)}})};return t.addEventListener("click",i,{capture:!0,signal:s}),t.addEventListener("keydown",n=>{n.target===t&&n.key==="Enter"&&(v(this,Ha,!0),i(n))},{signal:s}),await w(this,hi,of).call(this),t}finish(){l(this,ai)&&(l(this,ai).focus({focusVisible:l(this,Ha)}),v(this,Ha,!1))}isEmpty(){return l(this,ji)?l(this,pe)===null:!l(this,pe)&&!l(this,Fi)}hasData(){return l(this,ji)?l(this,pe)!==null||!!l(this,gn):this.isEmpty()}get guessedText(){return l(this,gn)}async setGuessedText(t){l(this,pe)===null&&(v(this,gn,t),v(this,ho,await $e._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",{generatedAltText:t})),w(this,hi,of).call(this))}toggleAltTextBadge(t=!1){var e;if(!l(this,ji)||l(this,pe)){(e=l(this,Ii))==null||e.remove(),v(this,Ii,null);return}if(!l(this,Ii)){const s=v(this,Ii,document.createElement("div"));s.className="noAltTextBadge",l(this,ls).div.append(s)}l(this,Ii).classList.toggle("hidden",!t)}serialize(t){let e=l(this,pe);return!t&&l(this,gn)===e&&(e=l(this,ho)),{altText:e,decorative:l(this,Fi),guessedText:l(this,gn),textWithDisclaimer:l(this,ho)}}get data(){return{altText:l(this,pe),decorative:l(this,Fi)}}set data({altText:t,decorative:e,guessedText:s,textWithDisclaimer:i,cancel:n=!1}){s&&(v(this,gn,s),v(this,ho,i)),!(l(this,pe)===t&&l(this,Fi)===e)&&(n||(v(this,pe,t),v(this,Fi,e)),w(this,hi,of).call(this))}toggle(t=!1){l(this,ai)&&(!t&&l(this,_s)&&(clearTimeout(l(this,_s)),v(this,_s,null)),l(this,ai).disabled=!t)}shown(){l(this,ls)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_displayed",data:{label:l(this,hi,Jc)}})}destroy(){var t,e;(t=l(this,ai))==null||t.remove(),v(this,ai,null),v(this,Ba,null),v(this,Li,null),(e=l(this,Ii))==null||e.remove(),v(this,Ii,null)}};pe=new WeakMap,Fi=new WeakMap,ai=new WeakMap,Ba=new WeakMap,Li=new WeakMap,_s=new WeakMap,Ha=new WeakMap,Ii=new WeakMap,ls=new WeakMap,gn=new WeakMap,ho=new WeakMap,ji=new WeakMap,ar=new WeakMap,hi=new WeakSet,Jc=function(){return l(this,pe)&&"added"||l(this,pe)===null&&this.guessedText&&"review"||"missing"},of=async function(){var i,n,r;const t=l(this,ai);if(!t)return;if(l(this,ji)){if(t.classList.toggle("done",!!l(this,pe)),t.setAttribute("data-l10n-id",l($e,ar)[l(this,hi,Jc)]),(i=l(this,Ba))==null||i.setAttribute("data-l10n-id",l($e,ar)[`${l(this,hi,Jc)}-label`]),!l(this,pe)){(n=l(this,Li))==null||n.remove();return}}else{if(!l(this,pe)&&!l(this,Fi)){t.classList.remove("done"),(r=l(this,Li))==null||r.remove();return}t.classList.add("done"),t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-edit-button")}let e=l(this,Li);if(!e){v(this,Li,e=document.createElement("span")),e.className="tooltip",e.setAttribute("role","tooltip"),e.id=`alt-text-tooltip-${l(this,ls).id}`;const o=100,h=l(this,ls)._uiManager._signal;h.addEventListener("abort",()=>{clearTimeout(l(this,_s)),v(this,_s,null)},{once:!0}),t.addEventListener("mouseenter",()=>{v(this,_s,setTimeout(()=>{v(this,_s,null),l(this,Li).classList.add("show"),l(this,ls)._reportTelemetry({action:"alt_text_tooltip"})},o))},{signal:h}),t.addEventListener("mouseleave",()=>{var c;l(this,_s)&&(clearTimeout(l(this,_s)),v(this,_s,null)),(c=l(this,Li))==null||c.classList.remove("show")},{signal:h})}l(this,Fi)?e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-decorative-tooltip"):(e.removeAttribute("data-l10n-id"),e.textContent=l(this,pe)),e.parentNode||t.append(e);const s=l(this,ls).getImageForAltText();s==null||s.setAttribute("aria-describedby",e.id)},_($e,ar,null),Q($e,"_l10n",null);let yd=$e;const mp=class mp{constructor({container:t,isPinchingDisabled:e=null,isPinchingStopped:s=null,onPinchStart:i=null,onPinching:n=null,onPinchEnd:r=null,signal:o}){_(this,mn);_(this,Nl);_(this,lo,!1);_(this,Bl,null);_(this,Hl);_(this,zl);_(this,Vl);_(this,Gl);_(this,za);_(this,pn,null);_(this,co);_(this,hr,null);v(this,Nl,t),v(this,Bl,s),v(this,Hl,e),v(this,zl,i),v(this,Vl,n),v(this,Gl,r),v(this,co,new AbortController),v(this,za,AbortSignal.any([o,l(this,co).signal])),t.addEventListener("touchstart",w(this,mn,fy).bind(this),{passive:!1,signal:l(this,za)})}get MIN_TOUCH_DISTANCE_TO_PINCH(){return ct(this,"MIN_TOUCH_DISTANCE_TO_PINCH",35/(window.devicePixelRatio||1))}destroy(){var t;(t=l(this,co))==null||t.abort(),v(this,co,null)}};Nl=new WeakMap,lo=new WeakMap,Bl=new WeakMap,Hl=new WeakMap,zl=new WeakMap,Vl=new WeakMap,Gl=new WeakMap,za=new WeakMap,pn=new WeakMap,co=new WeakMap,hr=new WeakMap,mn=new WeakSet,fy=function(t){var i,n,r;if((i=l(this,Hl))!=null&&i.call(this)||t.touches.length<2)return;if(!l(this,hr)){v(this,hr,new AbortController);const o=AbortSignal.any([l(this,za),l(this,hr).signal]),h=l(this,Nl),c={signal:o,passive:!1};h.addEventListener("touchmove",w(this,mn,gy).bind(this),c),h.addEventListener("touchend",w(this,mn,Lp).bind(this),c),h.addEventListener("touchcancel",w(this,mn,Lp).bind(this),c),(n=l(this,zl))==null||n.call(this)}if(bs(t),t.touches.length!==2||(r=l(this,Bl))!=null&&r.call(this)){v(this,pn,null);return}let[e,s]=t.touches;e.identifier>s.identifier&&([e,s]=[s,e]),v(this,pn,{touch0X:e.screenX,touch0Y:e.screenY,touch1X:s.screenX,touch1Y:s.screenY})},gy=function(t){var S;if(!l(this,pn)||t.touches.length!==2)return;let[e,s]=t.touches;e.identifier>s.identifier&&([e,s]=[s,e]);const{screenX:i,screenY:n}=e,{screenX:r,screenY:o}=s,h=l(this,pn),{touch0X:c,touch0Y:u,touch1X:d,touch1Y:f}=h,g=d-c,p=f-u,m=r-i,y=o-n,b=Math.hypot(m,y)||1,x=Math.hypot(g,p)||1;if(!l(this,lo)&&Math.abs(x-b)<=mp.MIN_TOUCH_DISTANCE_TO_PINCH)return;if(h.touch0X=i,h.touch0Y=n,h.touch1X=r,h.touch1Y=o,t.preventDefault(),!l(this,lo)){v(this,lo,!0);return}const C=[(i+r)/2,(n+o)/2];(S=l(this,Vl))==null||S.call(this,C,x,b)},Lp=function(t){var e;l(this,hr).abort(),v(this,hr,null),(e=l(this,Gl))==null||e.call(this),l(this,pn)&&(t.preventDefault(),v(this,pn,null),v(this,lo,!1))};let _d=mp;const lt=class lt{constructor(t){_(this,J);_(this,uo,null);_(this,li,null);_(this,Rt,null);_(this,Va,!1);_(this,lr,null);_(this,Wl,"");_(this,fo,!1);_(this,we,null);_(this,go,null);_(this,vn,null);_(this,cr,null);_(this,Xl,"");_(this,po,!1);_(this,ws,null);_(this,Ul,!1);_(this,mo,!1);_(this,bn,!1);_(this,Ni,null);_(this,Ga,0);_(this,Wa,0);_(this,Bs,null);_(this,vo,null);Q(this,"_editToolbar",null);Q(this,"_initialOptions",Object.create(null));Q(this,"_initialData",null);Q(this,"_isVisible",!0);Q(this,"_uiManager",null);Q(this,"_focusEventsAllowed",!0);_(this,Yl,!1);_(this,Id,lt._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=lt.prototype._resizeWithKeyboard,e=qr.TRANSLATE_SMALL,s=qr.TRANSLATE_BIG;return ct(this,"_resizerKeyboardManager",new pl([[["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"],lt.prototype._stopResizingWithKeyboard]]))}get editorType(){return Object.getPrototypeOf(this).constructor._type}static get isDrawer(){return!1}static get _defaultLineColor(){return ct(this,"_defaultLineColor",this._colorManager.getHexCode("CanvasText"))}static deleteAnnotationElement(t){const e=new DS({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(lt._l10n??(lt._l10n=t),lt._l10nResizer||(lt._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"})),lt._borderLineWidth!==-1)return;const s=getComputedStyle(document.documentElement);lt._borderLineWidth=parseFloat(s.getPropertyValue("--outline-width"))||0}static updateDefaultParams(t,e){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(t){return!1}static paste(t,e){Pt("Not implemented")}get propertiesToUpdate(){return[]}get _isDraggable(){return l(this,Yl)}set _isDraggable(t){var e;v(this,Yl,t),(e=this.div)==null||e.classList.toggle("draggable",t)}get isEnterHandled(){return!0}center(){const[t,e]=this.pageDimensions;switch(this.parentRotation){case 90:this.x-=this.height*e/(t*2),this.y+=this.width*t/(e*2);break;case 180:this.x+=this.width/2,this.y+=this.height/2;break;case 270:this.x+=this.height*e/(t*2),this.y-=this.width*t/(e*2);break;default:this.x-=this.width/2,this.y-=this.height/2;break}this.fixAndSetPosition()}addCommands(t){this._uiManager.addCommands(t)}get currentLayer(){return this._uiManager.currentLayer}setInBackground(){this.div.style.zIndex=0}setInForeground(){this.div.style.zIndex=l(this,Id)}setParent(t){t!==null?(this.pageIndex=t.pageIndex,this.pageDimensions=t.pageDimensions):w(this,J,Qc).call(this),this.parent=t}focusin(t){this._focusEventsAllowed&&(l(this,po)?v(this,po,!1):this.parent.setSelected(this))}focusout(t){var s;if(!this._focusEventsAllowed||!this.isAttachedToDOM)return;const e=t.relatedTarget;e!=null&&e.closest(`#${this.id}`)||(t.preventDefault(),(s=this.parent)!=null&&s.isMultipleSelection||this.commitOrRemove())}commitOrRemove(){this.isEmpty()?this.remove():this.commit()}commit(){this.addToAnnotationStorage()}addToAnnotationStorage(){this._uiManager.addToAnnotationStorage(this)}setAt(t,e,s,i){const[n,r]=this.parentDimensions;[s,i]=this.screenToPageTranslation(s,i),this.x=(t+s)/n,this.y=(e+i)/r,this.fixAndSetPosition()}translate(t,e){w(this,J,Ip).call(this,this.parentDimensions,t,e)}translateInPage(t,e){l(this,ws)||v(this,ws,[this.x,this.y,this.width,this.height]),w(this,J,Ip).call(this,this.pageDimensions,t,e),this.div.scrollIntoView({block:"nearest"})}drag(t,e){l(this,ws)||v(this,ws,[this.x,this.y,this.width,this.height]);const{div:s,parentDimensions:[i,n]}=this;if(this.x+=t/i,this.y+=e/n,this.parent&&(this.x<0||this.x>1||this.y<0||this.y>1)){const{x:d,y:f}=this.div.getBoundingClientRect();this.parent.findNewParent(this,d,f)&&(this.x-=Math.floor(this.x),this.y-=Math.floor(this.y))}let{x:r,y:o}=this;const[h,c]=this.getBaseTranslation();r+=h,o+=c;const{style:u}=s;u.left=`${(100*r).toFixed(2)}%`,u.top=`${(100*o).toFixed(2)}%`,this._onTranslating(r,o),s.scrollIntoView({block:"nearest"})}_onTranslating(t,e){}_onTranslated(t,e){}get _hasBeenMoved(){return!!l(this,ws)&&(l(this,ws)[0]!==this.x||l(this,ws)[1]!==this.y)}get _hasBeenResized(){return!!l(this,ws)&&(l(this,ws)[2]!==this.width||l(this,ws)[3]!==this.height)}getBaseTranslation(){const[t,e]=this.parentDimensions,{_borderLineWidth:s}=lt,i=s/t,n=s/e;switch(this.rotation){case 90:return[-i,n];case 180:return[i,n];case 270:return[i,-n];default:return[-i,-n]}}get _mustFixPosition(){return!0}fixAndSetPosition(t=this.rotation){const{div:{style:e},pageDimensions:[s,i]}=this;let{x:n,y:r,width:o,height:h}=this;if(o*=s,h*=i,n*=s,r*=i,this._mustFixPosition)switch(t){case 0:n=Math.max(0,Math.min(s-o,n)),r=Math.max(0,Math.min(i-h,r));break;case 90:n=Math.max(0,Math.min(s-h,n)),r=Math.min(i,Math.max(o,r));break;case 180:n=Math.min(s,Math.max(o,n)),r=Math.min(i,Math.max(h,r));break;case 270:n=Math.min(s,Math.max(h,n)),r=Math.max(0,Math.min(i-o,r));break}this.x=n/=s,this.y=r/=i;const[c,u]=this.getBaseTranslation();n+=c,r+=u,e.left=`${(100*n).toFixed(2)}%`,e.top=`${(100*r).toFixed(2)}%`,this.moveInDOM()}screenToPageTranslation(t,e){var s;return w(s=lt,$l,jp).call(s,t,e,this.parentRotation)}pageTranslationToScreen(t,e){var s;return w(s=lt,$l,jp).call(s,t,e,360-this.parentRotation)}get parentScale(){return this._uiManager.viewParameters.realScale}get parentRotation(){return(this._uiManager.viewParameters.rotation+this.pageRotation)%360}get parentDimensions(){const{parentScale:t,pageDimensions:[e,s]}=this;return[e*t,s*t]}setDims(t,e){const[s,i]=this.parentDimensions,{style:n}=this.div;n.width=`${(100*t/s).toFixed(2)}%`,l(this,fo)||(n.height=`${(100*e/i).toFixed(2)}%`)}fixDims(){const{style:t}=this.div,{height:e,width:s}=t,i=s.endsWith("%"),n=!l(this,fo)&&e.endsWith("%");if(i&&n)return;const[r,o]=this.parentDimensions;i||(t.width=`${(100*parseFloat(s)/r).toFixed(2)}%`),!l(this,fo)&&!n&&(t.height=`${(100*parseFloat(e)/o).toFixed(2)}%`)}getInitialTranslation(){return[0,0]}_onResized(){}static _round(t){return Math.round(t*1e4)/1e4}_onResizing(){}altTextFinish(){var t;(t=l(this,Rt))==null||t.finish()}async addEditToolbar(){return this._editToolbar||l(this,mo)?this._editToolbar:(this._editToolbar=new Gg(this),this.div.append(this._editToolbar.render()),l(this,Rt)&&await this._editToolbar.addAltText(l(this,Rt)),this._editToolbar)}removeEditToolbar(){var t;this._editToolbar&&(this._editToolbar.remove(),this._editToolbar=null,(t=l(this,Rt))==null||t.destroy())}addContainer(t){var s;const e=(s=this._editToolbar)==null?void 0:s.div;e?e.before(t):this.div.append(t)}getClientDimensions(){return this.div.getBoundingClientRect()}async addAltTextButton(){l(this,Rt)||(yd.initialize(lt._l10n),v(this,Rt,new yd(this)),l(this,uo)&&(l(this,Rt).data=l(this,uo),v(this,uo,null)),await this.addEditToolbar())}get altTextData(){var t;return(t=l(this,Rt))==null?void 0:t.data}set altTextData(t){l(this,Rt)&&(l(this,Rt).data=t)}get guessedAltText(){var t;return(t=l(this,Rt))==null?void 0:t.guessedText}async setGuessedAltText(t){var e;await((e=l(this,Rt))==null?void 0:e.setGuessedText(t))}serializeAltText(t){var e;return(e=l(this,Rt))==null?void 0:e.serialize(t)}hasAltText(){return!!l(this,Rt)&&!l(this,Rt).isEmpty()}hasAltTextData(){var t;return((t=l(this,Rt))==null?void 0:t.hasData())??!1}render(){var n;this.div=document.createElement("div"),this.div.setAttribute("data-editor-rotation",(360-this.rotation)%360),this.div.className=this.name,this.div.setAttribute("id",this.id),this.div.tabIndex=l(this,Va)?-1:0,this._isVisible||this.div.classList.add("hidden"),this.setInForeground(),w(this,J,zp).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),bd(this,this.div,["pointerdown"]),this.isResizable&&this._uiManager._supportsPinchToZoom&&(l(this,vo)||v(this,vo,new _d({container:this.div,isPinchingDisabled:()=>!this.isSelected,onPinchStart:w(this,J,vy).bind(this),onPinching:w(this,J,by).bind(this),onPinchEnd:w(this,J,yy).bind(this),signal:this._uiManager._signal}))),(n=this._uiManager._editorUndoBar)==null||n.hide(),this.div}pointerdown(t){const{isMac:e}=Ue.platform;if(t.button!==0||t.ctrlKey&&e){t.preventDefault();return}if(v(this,po,!0),this._isDraggable){w(this,J,_y).call(this,t);return}w(this,J,Hp).call(this,t)}get isSelected(){return this._uiManager.isSelected(this)}_onStartDragging(){}_onStopDragging(){}moveInDOM(){l(this,Ni)&&clearTimeout(l(this,Ni)),v(this,Ni,setTimeout(()=>{var t;v(this,Ni,null),(t=this.parent)==null||t.moveEditorInDOM(this)},0))}_setParentAndPosition(t,e,s){t.changeParent(this),this.x=e,this.y=s,this.fixAndSetPosition(),this._onTranslated()}getRect(t,e,s=this.rotation){const i=this.parentScale,[n,r]=this.pageDimensions,[o,h]=this.pageTranslation,c=t/i,u=e/i,d=this.x*n,f=this.y*r,g=this.width*n,p=this.height*r;switch(s){case 0:return[d+c+o,r-f-u-p+h,d+c+g+o,r-f-u+h];case 90:return[d+u+o,r-f+c+h,d+u+p+o,r-f+c+g+h];case 180:return[d-c-g+o,r-f+u+h,d-c+o,r-f+u+p+h];case 270:return[d-u-p+o,r-f-c-g+h,d-u+o,r-f-c+h];default:throw new Error("Invalid rotation")}}getRectInCurrentCoords(t,e){const[s,i,n,r]=t,o=n-s,h=r-i;switch(this.rotation){case 0:return[s,e-r,o,h];case 90:return[s,e-i,h,o];case 180:return[n,e-i,o,h];case 270:return[n,e-r,h,o];default:throw new Error("Invalid rotation")}}onceAdded(t){}isEmpty(){return!1}enableEditMode(){v(this,mo,!0)}disableEditMode(){v(this,mo,!1)}isInEditMode(){return l(this,mo)}shouldGetKeyboardEvents(){return l(this,bn)}needsToBeRebuilt(){return this.div&&!this.isAttachedToDOM}get isOnScreen(){const{top:t,left:e,bottom:s,right:i}=this.getClientDimensions(),{innerHeight:n,innerWidth:r}=window;return e<r&&i>0&&t<n&&s>0}rebuild(){w(this,J,zp).call(this)}rotate(t){}resize(){}serializeDeleted(){var t;return{id:this.annotationElementId,deleted:!0,pageIndex:this.pageIndex,popupRef:((t=this._initialData)==null?void 0:t.popupRef)||""}}serialize(t=!1,e=null){Pt("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,v(i,uo,t.accessibilityData);const[n,r]=i.pageDimensions,[o,h,c,u]=i.getRectInCurrentCoords(t.rect,r);return i.x=o/n,i.y=h/r,i.width=c/n,i.height=u/r,i}get hasBeenModified(){return!!this.annotationElementId&&(this.deleted||this.serialize()!==null)}remove(){var t,e;if((t=l(this,cr))==null||t.abort(),v(this,cr,null),this.isEmpty()||this.commit(),this.parent?this.parent.remove(this):this._uiManager.removeEditor(this),l(this,Ni)&&(clearTimeout(l(this,Ni)),v(this,Ni,null)),w(this,J,Qc).call(this),this.removeEditToolbar(),l(this,Bs)){for(const s of l(this,Bs).values())clearTimeout(s);v(this,Bs,null)}this.parent=null,(e=l(this,vo))==null||e.destroy(),v(this,vo,null)}get isResizable(){return!1}makeResizable(){this.isResizable&&(w(this,J,py).call(this),l(this,we).classList.remove("hidden"),bd(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),v(this,vn,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height});const e=l(this,we).children;if(!l(this,li)){v(this,li,Array.from(e));const r=w(this,J,wy).bind(this),o=w(this,J,xy).bind(this),h=this._uiManager._signal;for(const c of l(this,li)){const u=c.getAttribute("data-resizer-name");c.setAttribute("role","spinbutton"),c.addEventListener("keydown",r,{signal:h}),c.addEventListener("blur",o,{signal:h}),c.addEventListener("focus",w(this,J,Sy).bind(this,u),{signal:h}),c.setAttribute("data-l10n-id",lt._l10nResizer[u])}}const s=l(this,li)[0];let i=0;for(const r of e){if(r===s)break;i++}const n=(360-this.rotation+this.parentRotation)%360/90*(l(this,li).length/4);if(n!==i){if(n<i)for(let o=0;o<i-n;o++)l(this,we).append(l(this,we).firstChild);else if(n>i)for(let o=0;o<n-i;o++)l(this,we).firstChild.before(l(this,we).lastChild);let r=0;for(const o of e){const c=l(this,li)[r++].getAttribute("data-resizer-name");o.setAttribute("data-l10n-id",lt._l10nResizer[c])}}w(this,J,Vp).call(this,0),v(this,bn,!0),l(this,we).firstChild.focus({focusVisible:!0}),t.preventDefault(),t.stopImmediatePropagation()}_resizeWithKeyboard(t,e){l(this,bn)&&w(this,J,Bp).call(this,l(this,Xl),{deltaX:t,deltaY:e,fromKeyboard:!0})}_stopResizingWithKeyboard(){w(this,J,Qc).call(this),this.div.focus()}select(){var t,e,s;if(this.makeResizable(),(t=this.div)==null||t.classList.add("selectedEditor"),!this._editToolbar){this.addEditToolbar().then(()=>{var i,n;(i=this.div)!=null&&i.classList.contains("selectedEditor")&&((n=this._editToolbar)==null||n.show())});return}(e=this._editToolbar)==null||e.show(),(s=l(this,Rt))==null||s.toggleAltTextBadge(!1)}unselect(){var t,e,s,i,n;(t=l(this,we))==null||t.classList.add("hidden"),(e=this.div)==null||e.classList.remove("selectedEditor"),(s=this.div)!=null&&s.contains(document.activeElement)&&this._uiManager.currentLayer.div.focus({preventScroll:!0}),(i=this._editToolbar)==null||i.hide(),(n=l(this,Rt))==null||n.toggleAltTextBadge(!0)}updateParams(t,e){}disableEditing(){}enableEditing(){}enterInEditMode(){}getImageForAltText(){return null}get contentDiv(){return this.div}get isEditing(){return l(this,Ul)}set isEditing(t){v(this,Ul,t),this.parent&&(t?(this.parent.setSelected(this),this.parent.setActiveEditor(this)):this.parent.setActiveEditor(null))}setAspectRatio(t,e){v(this,fo,!0);const s=t/e,{style:i}=this.div;i.aspectRatio=s,i.height="auto"}static get MIN_SIZE(){return 16}static canCreateNewEmptyEditor(){return!0}get telemetryInitialData(){return{action:"added"}}get telemetryFinalData(){return null}_reportTelemetry(t,e=!1){if(e){l(this,Bs)||v(this,Bs,new Map);const{action:s}=t;let i=l(this,Bs).get(s);i&&clearTimeout(i),i=setTimeout(()=>{this._reportTelemetry(t),l(this,Bs).delete(s),l(this,Bs).size===0&&v(this,Bs,null)},lt._telemetryTimeout),l(this,Bs).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),v(this,Va,!1)}disable(){this.div&&(this.div.tabIndex=-1),v(this,Va,!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()}};uo=new WeakMap,li=new WeakMap,Rt=new WeakMap,Va=new WeakMap,lr=new WeakMap,Wl=new WeakMap,fo=new WeakMap,we=new WeakMap,go=new WeakMap,vn=new WeakMap,cr=new WeakMap,Xl=new WeakMap,po=new WeakMap,ws=new WeakMap,Ul=new WeakMap,mo=new WeakMap,bn=new WeakMap,Ni=new WeakMap,Ga=new WeakMap,Wa=new WeakMap,Bs=new WeakMap,vo=new WeakMap,Yl=new WeakMap,Id=new WeakMap,J=new WeakSet,Ip=function([t,e],s,i){[s,i]=this.screenToPageTranslation(s,i),this.x+=s/t,this.y+=i/e,this._onTranslating(this.x,this.y),this.fixAndSetPosition()},$l=new WeakSet,jp=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]}},af=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]}},py=function(){if(l(this,we))return;v(this,we,document.createElement("div")),l(this,we).classList.add("resizers");const t=this._willKeepAspectRatio?["topLeft","topRight","bottomRight","bottomLeft"]:["topLeft","topMiddle","topRight","middleRight","bottomRight","bottomMiddle","bottomLeft","middleLeft"],e=this._uiManager._signal;for(const s of t){const i=document.createElement("div");l(this,we).append(i),i.classList.add("resizer",s),i.setAttribute("data-resizer-name",s),i.addEventListener("pointerdown",w(this,J,my).bind(this,s),{signal:e}),i.addEventListener("contextmenu",ni,{signal:e}),i.tabIndex=-1}this.div.prepend(l(this,we))},my=function(t,e){var u;e.preventDefault();const{isMac:s}=Ue.platform;if(e.button!==0||e.ctrlKey&&s)return;(u=l(this,Rt))==null||u.toggle(!1);const i=this._isDraggable;this._isDraggable=!1,v(this,go,[e.screenX,e.screenY]);const n=new AbortController,r=this._uiManager.combinedSignal(n);this.parent.togglePointerEvents(!1),window.addEventListener("pointermove",w(this,J,Bp).bind(this,t),{passive:!0,capture:!0,signal:r}),window.addEventListener("touchmove",bs,{passive:!1,signal:r}),window.addEventListener("contextmenu",ni,{signal:r}),v(this,vn,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height});const o=this.parent.div.style.cursor,h=this.div.style.cursor;this.div.style.cursor=this.parent.div.style.cursor=window.getComputedStyle(e.target).cursor;const c=()=>{var d;n.abort(),this.parent.togglePointerEvents(!0),(d=l(this,Rt))==null||d.toggle(!0),this._isDraggable=i,this.parent.div.style.cursor=o,this.div.style.cursor=h,w(this,J,hf).call(this)};window.addEventListener("pointerup",c,{signal:r}),window.addEventListener("blur",c,{signal:r})},Np=function(t,e,s,i){this.width=s,this.height=i,this.x=t,this.y=e;const[n,r]=this.parentDimensions;this.setDims(n*s,r*i),this.fixAndSetPosition(),this._onResized()},hf=function(){if(!l(this,vn))return;const{savedX:t,savedY:e,savedWidth:s,savedHeight:i}=l(this,vn);v(this,vn,null);const n=this.x,r=this.y,o=this.width,h=this.height;n===t&&r===e&&o===s&&h===i||this.addCommands({cmd:w(this,J,Np).bind(this,n,r,o,h),undo:w(this,J,Np).bind(this,t,e,s,i),mustExec:!0})},Bp=function(t,e){const[s,i]=this.parentDimensions,n=this.x,r=this.y,o=this.width,h=this.height,c=lt.MIN_SIZE/s,u=lt.MIN_SIZE/i,d=w(this,J,af).call(this,this.rotation),f=(L,z)=>[d[0]*L+d[2]*z,d[1]*L+d[3]*z],g=w(this,J,af).call(this,360-this.rotation),p=(L,z)=>[g[0]*L+g[2]*z,g[1]*L+g[3]*z];let m,y,b=!1,x=!1;switch(t){case"topLeft":b=!0,m=(L,z)=>[0,0],y=(L,z)=>[L,z];break;case"topMiddle":m=(L,z)=>[L/2,0],y=(L,z)=>[L/2,z];break;case"topRight":b=!0,m=(L,z)=>[L,0],y=(L,z)=>[0,z];break;case"middleRight":x=!0,m=(L,z)=>[L,z/2],y=(L,z)=>[0,z/2];break;case"bottomRight":b=!0,m=(L,z)=>[L,z],y=(L,z)=>[0,0];break;case"bottomMiddle":m=(L,z)=>[L/2,z],y=(L,z)=>[L/2,0];break;case"bottomLeft":b=!0,m=(L,z)=>[0,z],y=(L,z)=>[L,0];break;case"middleLeft":x=!0,m=(L,z)=>[0,z/2],y=(L,z)=>[L,z/2];break}const C=m(o,h),S=y(o,h);let T=f(...S);const P=lt._round(n+T[0]),M=lt._round(r+T[1]);let D=1,R=1,V,H;if(e.fromKeyboard)({deltaX:V,deltaY:H}=e);else{const{screenX:L,screenY:z}=e,[Z,Dt]=l(this,go);[V,H]=this.screenToPageTranslation(L-Z,z-Dt),l(this,go)[0]=L,l(this,go)[1]=z}if([V,H]=p(V/s,H/i),b){const L=Math.hypot(o,h);D=R=Math.max(Math.min(Math.hypot(S[0]-C[0]-V,S[1]-C[1]-H)/L,1/o,1/h),c/o,u/h)}else x?D=Math.max(c,Math.min(1,Math.abs(S[0]-C[0]-V)))/o:R=Math.max(u,Math.min(1,Math.abs(S[1]-C[1]-H)))/h;const F=lt._round(o*D),I=lt._round(h*R);T=f(...y(F,I));const j=P-T[0],K=M-T[1];l(this,ws)||v(this,ws,[this.x,this.y,this.width,this.height]),this.width=F,this.height=I,this.x=j,this.y=K,this.setDims(s*F,i*I),this.fixAndSetPosition(),this._onResizing()},vy=function(){var t;v(this,vn,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height}),(t=l(this,Rt))==null||t.toggle(!1),this.parent.togglePointerEvents(!1)},by=function(t,e,s){let n=.7*(s/e)+1-.7;if(n===1)return;const r=w(this,J,af).call(this,this.rotation),o=(P,M)=>[r[0]*P+r[2]*M,r[1]*P+r[3]*M],[h,c]=this.parentDimensions,u=this.x,d=this.y,f=this.width,g=this.height,p=lt.MIN_SIZE/h,m=lt.MIN_SIZE/c;n=Math.max(Math.min(n,1/f,1/g),p/f,m/g);const y=lt._round(f*n),b=lt._round(g*n);if(y===f&&b===g)return;l(this,ws)||v(this,ws,[u,d,f,g]);const x=o(f/2,g/2),C=lt._round(u+x[0]),S=lt._round(d+x[1]),T=o(y/2,b/2);this.x=C-T[0],this.y=S-T[1],this.width=y,this.height=b,this.setDims(h*y,c*b),this.fixAndSetPosition(),this._onResizing()},yy=function(){var t;(t=l(this,Rt))==null||t.toggle(!0),this.parent.togglePointerEvents(!0),w(this,J,hf).call(this)},Hp=function(t){const{isMac:e}=Ue.platform;t.ctrlKey&&!e||t.shiftKey||t.metaKey&&e?this.parent.toggleSelected(this):this.parent.setSelected(this)},_y=function(t){const{isSelected:e}=this;this._uiManager.setUpDragSession();let s=!1;const i=new AbortController,n=this._uiManager.combinedSignal(i),r={capture:!0,passive:!1,signal:n},o=c=>{i.abort(),v(this,lr,null),v(this,po,!1),this._uiManager.endDragSession()||w(this,J,Hp).call(this,c),s&&this._onStopDragging()};e&&(v(this,Ga,t.clientX),v(this,Wa,t.clientY),v(this,lr,t.pointerId),v(this,Wl,t.pointerType),window.addEventListener("pointermove",c=>{s||(s=!0,this._onStartDragging());const{clientX:u,clientY:d,pointerId:f}=c;if(f!==l(this,lr)){bs(c);return}const[g,p]=this.screenToPageTranslation(u-l(this,Ga),d-l(this,Wa));v(this,Ga,u),v(this,Wa,d),this._uiManager.dragSelectedEditors(g,p)},r),window.addEventListener("touchmove",bs,r),window.addEventListener("pointerdown",c=>{c.pointerType===l(this,Wl)&&(l(this,vo)||c.isPrimary)&&o(c),bs(c)},r));const h=c=>{if(!l(this,lr)||l(this,lr)===c.pointerId){o(c);return}bs(c)};window.addEventListener("pointerup",h,{signal:n}),window.addEventListener("blur",h,{signal:n})},zp=function(){if(l(this,cr)||!this.div)return;v(this,cr,new AbortController);const t=this._uiManager.combinedSignal(l(this,cr));this.div.addEventListener("focusin",this.focusin.bind(this),{signal:t}),this.div.addEventListener("focusout",this.focusout.bind(this),{signal:t})},wy=function(t){lt._resizerKeyboardManager.exec(this,t)},xy=function(t){var e;l(this,bn)&&((e=t.relatedTarget)==null?void 0:e.parentNode)!==l(this,we)&&w(this,J,Qc).call(this)},Sy=function(t){v(this,Xl,l(this,bn)?t:"")},Vp=function(t){if(l(this,li))for(const e of l(this,li))e.tabIndex=t},Qc=function(){v(this,bn,!1),w(this,J,Vp).call(this,-1),w(this,J,hf).call(this)},_(lt,$l),Q(lt,"_l10n",null),Q(lt,"_l10nResizer",null),Q(lt,"_borderLineWidth",-1),Q(lt,"_colorManager",new Xg),Q(lt,"_zIndex",1),Q(lt,"_telemetryTimeout",1e3);let Vt=lt;class DS extends Vt{constructor(t){super(t),this.annotationElementId=t.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}}const H0=3285377520,Is=4294901760,Pi=65535;class z0{constructor(t){this.h1=t?t&4294967295:H0,this.h2=t?t&4294967295:H0}update(t){let e,s;if(typeof t=="string"){e=new Uint8Array(t.length*2),s=0;for(let m=0,y=t.length;m<y;m++){const b=t.charCodeAt(m);b<=255?e[s++]=b:(e[s++]=b>>>8,e[s++]=b&255)}}else if(ArrayBuffer.isView(t))e=t.slice(),s=e.byteLength;else throw new Error("Invalid data format, must be a string or TypedArray.");const i=s>>2,n=s-i*4,r=new Uint32Array(e.buffer,0,i);let o=0,h=0,c=this.h1,u=this.h2;const d=3432918353,f=461845907,g=d&Pi,p=f&Pi;for(let m=0;m<i;m++)m&1?(o=r[m],o=o*d&Is|o*g&Pi,o=o<<15|o>>>17,o=o*f&Is|o*p&Pi,c^=o,c=c<<13|c>>>19,c=c*5+3864292196):(h=r[m],h=h*d&Is|h*g&Pi,h=h<<15|h>>>17,h=h*f&Is|h*p&Pi,u^=h,u=u<<13|u>>>19,u=u*5+3864292196);switch(o=0,n){case 3:o^=e[i*4+2]<<16;case 2:o^=e[i*4+1]<<8;case 1:o^=e[i*4],o=o*d&Is|o*g&Pi,o=o<<15|o>>>17,o=o*f&Is|o*p&Pi,i&1?c^=o:u^=o}this.h1=c,this.h2=u}hexdigest(){let t=this.h1,e=this.h2;return t^=e>>>1,t=t*3981806797&Is|t*36045&Pi,e=e*4283543511&Is|((e<<16|t>>>16)*2950163797&Is)>>>16,t^=e>>>1,t=t*444984403&Is|t*60499&Pi,e=e*3301882366&Is|((e<<16|t>>>16)*3120437893&Is)>>>16,t^=e>>>1,(t>>>0).toString(16).padStart(8,"0")+(e>>>0).toString(16).padStart(8,"0")}}const Ug=Object.freeze({map:null,hash:"",transfer:void 0});class Yg{constructor(){_(this,jd);_(this,bo,!1);_(this,yo,null);_(this,me,new Map);this.onSetModified=null,this.onResetModified=null,this.onAnnotationEditor=null}getValue(t,e){const s=l(this,me).get(t);return s===void 0?e:Object.assign(e,s)}getRawValue(t){return l(this,me).get(t)}remove(t){if(l(this,me).delete(t),l(this,me).size===0&&this.resetModified(),typeof this.onAnnotationEditor=="function"){for(const e of l(this,me).values())if(e instanceof Vt)return;this.onAnnotationEditor(null)}}setValue(t,e){const s=l(this,me).get(t);let i=!1;if(s!==void 0)for(const[n,r]of Object.entries(e))s[n]!==r&&(i=!0,s[n]=r);else i=!0,l(this,me).set(t,e);i&&w(this,jd,Cy).call(this),e instanceof Vt&&typeof this.onAnnotationEditor=="function"&&this.onAnnotationEditor(e.constructor._type)}has(t){return l(this,me).has(t)}getAll(){return l(this,me).size>0?Fg(l(this,me)):null}setAll(t){for(const[e,s]of Object.entries(t))this.setValue(e,s)}get size(){return l(this,me).size}resetModified(){l(this,bo)&&(v(this,bo,!1),typeof this.onResetModified=="function"&&this.onResetModified())}get print(){return new V0(this)}get serializable(){if(l(this,me).size===0)return Ug;const t=new Map,e=new z0,s=[],i=Object.create(null);let n=!1;for(const[r,o]of l(this,me)){const h=o instanceof Vt?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}:Ug}get editorStats(){let t=null;const e=new Map;for(const s of l(this,me).values()){if(!(s instanceof Vt))continue;const i=s.telemetryFinalData;if(!i)continue;const{type:n}=i;e.has(n)||e.set(n,Object.getPrototypeOf(s).constructor),t||(t=Object.create(null));const r=t[n]||(t[n]=new Map);for(const[o,h]of Object.entries(i)){if(o==="type")continue;let c=r.get(o);c||(c=new Map,r.set(o,c));const u=c.get(h)??0;c.set(h,u+1)}}for(const[s,i]of e)t[s]=i.computeTelemetryFinalData(t[s]);return t}resetModifiedIds(){v(this,yo,null)}get modifiedIds(){if(l(this,yo))return l(this,yo);const t=[];for(const e of l(this,me).values())!(e instanceof Vt)||!e.annotationElementId||!e.serialize()||t.push(e.annotationElementId);return v(this,yo,{ids:new Set(t),hash:t.join(",")})}}bo=new WeakMap,yo=new WeakMap,me=new WeakMap,jd=new WeakSet,Cy=function(){l(this,bo)||(v(this,bo,!0),typeof this.onSetModified=="function"&&this.onSetModified())};class V0 extends Yg{constructor(e){super();_(this,ql);const{map:s,hash:i,transfer:n}=e.serializable,r=structuredClone(s,n?{transfer:n}:null);v(this,ql,{map:r,hash:i,transfer:n})}get print(){Pt("Should not call PrintAnnotationStorage.print")}get serializable(){return l(this,ql)}get modifiedIds(){return ct(this,"modifiedIds",{ids:new Set,hash:""})}}ql=new WeakMap;class RS{constructor({ownerDocument:t=globalThis.document,styleElement:e=null}){_(this,Xa,new Set);this._document=t,this.nativeFontFaces=new Set,this.styleElement=null,this.loadingRequests=[],this.loadTestFontId=0}addNativeFontFace(t){this.nativeFontFaces.add(t),this._document.fonts.add(t)}removeNativeFontFace(t){this.nativeFontFaces.delete(t),this._document.fonts.delete(t)}insertRule(t){this.styleElement||(this.styleElement=this._document.createElement("style"),this._document.documentElement.getElementsByTagName("head")[0].append(this.styleElement));const e=this.styleElement.sheet;e.insertRule(t,e.cssRules.length)}clear(){for(const t of this.nativeFontFaces)this._document.fonts.delete(t);this.nativeFontFaces.clear(),l(this,Xa).clear(),this.styleElement&&(this.styleElement.remove(),this.styleElement=null)}async loadSystemFont({systemFontInfo:t,_inspectFont:e}){if(!(!t||l(this,Xa).has(t.loadedName))){if(ie(!this.disableFontFace,"loadSystemFont shouldn't be called when `disableFontFace` is set."),this.isFontLoadingAPISupported){const{loadedName:s,src:i,style:n}=t,r=new FontFace(s,i,n);this.addNativeFontFace(r);try{await r.load(),l(this,Xa).add(s),e==null||e(t)}catch{ht(`Cannot load system font: ${t.baseFontName}, installing it could help to improve PDF rendering.`),this.removeNativeFontFace(r)}return}Pt("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 ht(`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 ct(this,"isFontLoadingAPISupported",t)}get isSyncFontLoadingSupported(){let t=!1;return(Oe||typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.userAgent)=="string"&&/Mozilla\/5.0.*?rv:\d+.*? Gecko/.test(navigator.userAgent))&&(t=!0),ct(this,"isSyncFontLoadingSupported",t)}_queueLoadingCallback(t){function e(){for(ie(!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 ct(this,"_loadTestFont",t)}_prepareFontLoadEvent(t,e){function s(S,T){return S.charCodeAt(T)<<24|S.charCodeAt(T+1)<<16|S.charCodeAt(T+2)<<8|S.charCodeAt(T+3)&255}function i(S,T,P,M){const D=S.substring(0,T),R=S.substring(T+P);return D+M+R}let n,r;const o=this._document.createElement("canvas");o.width=1,o.height=1;const h=o.getContext("2d");let c=0;function u(S,T){if(++c>30){ht("Load test font never loaded."),T();return}if(h.font="30px "+S,h.fillText(".",0,20),h.getImageData(0,0,1,1).data[3]>0){T();return}setTimeout(u.bind(null,S,T))}const d=`lt${Date.now()}${this.loadTestFontId++}`;let f=this._loadTestFont;f=i(f,976,d.length,d);const p=16,m=1482184792;let y=s(f,p);for(n=0,r=d.length-3;n<r;n+=4)y=y-m+s(d,n)|0;n<d.length&&(y=y-m+s(d+"XXX",n)|0),f=i(f,p,4,bS(y));const b=`url(data:font/opentype;base64,${btoa(f)});`,x=`@font-face {font-family:"${d}";src:${b}}`;this.insertRule(x);const C=this._document.createElement("div");C.style.visibility="hidden",C.style.width=C.style.height="10px",C.style.position="absolute",C.style.top=C.style.left="0px";for(const S of[t.loadedName,d]){const T=this._document.createElement("span");T.textContent="Hi",T.style.fontFamily=S,C.append(T)}this._document.body.append(C),u(d,()=>{C.remove(),e.complete()})}}Xa=new WeakMap;class FS{constructor(t,{disableFontFace:e=!1,fontExtraProperties:s=!1,inspectFont:i=null}){this.compiledGlyphs=Object.create(null);for(const n in t)this[n]=t[n];this.disableFontFace=e===!0,this.fontExtraProperties=s===!0,this._inspectFont=i}createNativeFontFace(){var e;if(!this.data||this.disableFontFace)return null;let t;if(!this.cssFontInfo)t=new FontFace(this.loadedName,this.data,{});else{const s={weight:this.cssFontInfo.fontWeight};this.cssFontInfo.italicAngle&&(s.style=`oblique ${this.cssFontInfo.italicAngle}deg`),t=new FontFace(this.cssFontInfo.fontFamily,this.data,s)}return(e=this._inspectFont)==null||e.call(this,this),t}createFontFaceRule(){var s;if(!this.data||this.disableFontFace)return null;const t=`url(data:${this.mimetype};base64,${CS(this.data)});`;let e;if(!this.cssFontInfo)e=`@font-face {font-family:"${this.loadedName}";src:${t}}`;else{let i=`font-weight: ${this.cssFontInfo.fontWeight};`;this.cssFontInfo.italicAngle&&(i+=`font-style: oblique ${this.cssFontInfo.italicAngle}deg;`),e=`@font-face {font-family:"${this.cssFontInfo.fontFamily}";${i}src:${t}}`}return(s=this._inspectFont)==null||s.call(this,this,t),e}getPathGenerator(t,e){if(this.compiledGlyphs[e]!==void 0)return this.compiledGlyphs[e];const s=this.loadedName+"_path_"+e;let i;try{i=t.get(s)}catch(r){ht(`getPathGenerator - ignoring character: "${r}".`)}const n=new Path2D(i||"");return this.fontExtraProperties||t.delete(s),this.compiledGlyphs[e]=n}}const wd={DATA:1,ERROR:2},ne={CANCEL:1,CANCEL_COMPLETE:2,CLOSE:3,ENQUEUE:4,ERROR:5,PULL:6,PULL_COMPLETE:7,START_COMPLETE:8};function G0(){}function rs(a){if(a instanceof qn||a instanceof Rg||a instanceof dl||a instanceof I0||a instanceof gd||a instanceof Dg)return a;switch(a instanceof Error||typeof a=="object"&&a!==null||Pt('wrapReason: Expected "reason" to be a (possibly cloned) Error.'),a.name){case"AbortException":return new qn(a.message);case"InvalidPDFException":return new Rg(a.message);case"MissingPDFException":return new dl(a.message);case"PasswordException":return new I0(a.message,a.code);case"UnexpectedResponseException":return new gd(a.message,a.status);case"UnknownErrorException":return new Dg(a.message,a.details)}return new Dg(a.message,a.toString())}class ml{constructor(t,e,s){_(this,Hs);_(this,Ua,new AbortController);this.sourceName=t,this.targetName=e,this.comObj=s,this.callbackId=1,this.streamId=1,this.streamSinks=Object.create(null),this.streamControllers=Object.create(null),this.callbackCapabilities=Object.create(null),this.actionHandler=Object.create(null),s.addEventListener("message",w(this,Hs,Ay).bind(this),{signal:l(this,Ua).signal})}on(t,e){const s=this.actionHandler;if(s[t])throw new Error(`There is already an actionName called "${t}"`);s[t]=e}send(t,e,s){this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:t,data:e},s)}sendWithPromise(t,e,s){const i=this.callbackId++,n=Promise.withResolvers();this.callbackCapabilities[i]=n;try{this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:t,callbackId:i,data:e},s)}catch(r){n.reject(r)}return n.promise}sendWithStream(t,e,s,i){const n=this.streamId++,r=this.sourceName,o=this.targetName,h=this.comObj;return new ReadableStream({start:c=>{const u=Promise.withResolvers();return this.streamControllers[n]={controller:c,startCall:u,pullCall:null,cancelCall:null,isClosed:!1},h.postMessage({sourceName:r,targetName:o,action:t,streamId:n,data:e,desiredSize:c.desiredSize},i),u.promise},pull:c=>{const u=Promise.withResolvers();return this.streamControllers[n].pullCall=u,h.postMessage({sourceName:r,targetName:o,stream:ne.PULL,streamId:n,desiredSize:c.desiredSize}),u.promise},cancel:c=>{ie(c instanceof Error,"cancel must have a valid reason");const u=Promise.withResolvers();return this.streamControllers[n].cancelCall=u,this.streamControllers[n].isClosed=!0,h.postMessage({sourceName:r,targetName:o,stream:ne.CANCEL,streamId:n,reason:rs(c)}),u.promise}},s)}destroy(){var t;(t=l(this,Ua))==null||t.abort(),v(this,Ua,null)}}Ua=new WeakMap,Hs=new WeakSet,Ay=function({data:t}){if(t.targetName!==this.sourceName)return;if(t.stream){w(this,Hs,Ey).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===wd.DATA)i.resolve(t.data);else if(t.callback===wd.ERROR)i.reject(rs(t.reason));else throw new Error("Unexpected callback case");return}const e=this.actionHandler[t.action];if(!e)throw new Error(`Unknown action from worker: ${t.action}`);if(t.callbackId){const s=this.sourceName,i=t.sourceName,n=this.comObj;Promise.try(e,t.data).then(function(r){n.postMessage({sourceName:s,targetName:i,callback:wd.DATA,callbackId:t.callbackId,data:r})},function(r){n.postMessage({sourceName:s,targetName:i,callback:wd.ERROR,callbackId:t.callbackId,reason:rs(r)})});return}if(t.streamId){w(this,Hs,Ty).call(this,t);return}e(t.data)},Ty=function(t){const e=t.streamId,s=this.sourceName,i=t.sourceName,n=this.comObj,r=this,o=this.actionHandler[t.action],h={enqueue(c,u=1,d){if(this.isCancelled)return;const f=this.desiredSize;this.desiredSize-=u,f>0&&this.desiredSize<=0&&(this.sinkCapability=Promise.withResolvers(),this.ready=this.sinkCapability.promise),n.postMessage({sourceName:s,targetName:i,stream:ne.ENQUEUE,streamId:e,chunk:c},d)},close(){this.isCancelled||(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:ne.CLOSE,streamId:e}),delete r.streamSinks[e])},error(c){ie(c instanceof Error,"error must have a valid reason"),!this.isCancelled&&(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:ne.ERROR,streamId:e,reason:rs(c)}))},sinkCapability:Promise.withResolvers(),onPull:null,onCancel:null,isCancelled:!1,desiredSize:t.desiredSize,ready:null};h.sinkCapability.resolve(),h.ready=h.sinkCapability.promise,this.streamSinks[e]=h,Promise.try(o,t.data,h).then(function(){n.postMessage({sourceName:s,targetName:i,stream:ne.START_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:ne.START_COMPLETE,streamId:e,reason:rs(c)})})},Ey=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 ne.START_COMPLETE:t.success?r.startCall.resolve():r.startCall.reject(rs(t.reason));break;case ne.PULL_COMPLETE:t.success?r.pullCall.resolve():r.pullCall.reject(rs(t.reason));break;case ne.PULL:if(!o){n.postMessage({sourceName:s,targetName:i,stream:ne.PULL_COMPLETE,streamId:e,success:!0});break}o.desiredSize<=0&&t.desiredSize>0&&o.sinkCapability.resolve(),o.desiredSize=t.desiredSize,Promise.try(o.onPull||G0).then(function(){n.postMessage({sourceName:s,targetName:i,stream:ne.PULL_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:ne.PULL_COMPLETE,streamId:e,reason:rs(c)})});break;case ne.ENQUEUE:if(ie(r,"enqueue should have stream controller"),r.isClosed)break;r.controller.enqueue(t.chunk);break;case ne.CLOSE:if(ie(r,"close should have stream controller"),r.isClosed)break;r.isClosed=!0,r.controller.close(),w(this,Hs,lf).call(this,r,e);break;case ne.ERROR:ie(r,"error should have stream controller"),r.controller.error(rs(t.reason)),w(this,Hs,lf).call(this,r,e);break;case ne.CANCEL_COMPLETE:t.success?r.cancelCall.resolve():r.cancelCall.reject(rs(t.reason)),w(this,Hs,lf).call(this,r,e);break;case ne.CANCEL:if(!o)break;const h=rs(t.reason);Promise.try(o.onCancel||G0,h).then(function(){n.postMessage({sourceName:s,targetName:i,stream:ne.CANCEL_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:ne.CANCEL_COMPLETE,streamId:e,reason:rs(c)})}),o.sinkCapability.reject(h),o.isCancelled=!0,delete this.streamSinks[e];break;default:throw new Error("Unexpected stream case")}},lf=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 W0{constructor({enableHWA:t=!1}){_(this,Kl,!1);v(this,Kl,t)}create(t,e){if(t<=0||e<=0)throw new Error("Invalid canvas size");const s=this._createCanvas(t,e);return{canvas:s,context:s.getContext("2d",{willReadFrequently:!l(this,Kl)})}}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){Pt("Abstract method `_createCanvas` called.")}}Kl=new WeakMap;class LS extends W0{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 X0{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){Pt("Abstract method `_fetch` called.")}}class U0 extends X0{async _fetch(t){const e=await md(t,this.isCompressed?"arraybuffer":"text");return e instanceof ArrayBuffer?new Uint8Array(e):pd(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 IS extends Y0{constructor({docId:e,ownerDocument:s=globalThis.document}){super();_(this,W);_(this,_o);_(this,Ya);_(this,yn);_(this,_n);_(this,Le);_(this,wo);_(this,xo,0);v(this,_n,e),v(this,Le,s)}addFilter(e){if(!e)return"none";let s=l(this,W,Be).get(e);if(s)return s;const[i,n,r]=w(this,W,cf).call(this,e),o=e.length===1?i:`${i}${n}${r}`;if(s=l(this,W,Be).get(o),s)return l(this,W,Be).set(e,s),s;const h=`g_${l(this,_n)}_transfer_map_${es(this,xo)._++}`,c=w(this,W,Hh).call(this,h);l(this,W,Be).set(e,c),l(this,W,Be).set(o,c);const u=w(this,W,zh).call(this,h);return w(this,W,eu).call(this,i,n,r,u),c}addHCMFilter(e,s){var p;const i=`${e}-${s}`,n="base";let r=l(this,W,Zc).get(n);if((r==null?void 0:r.key)===i||(r?((p=r.filter)==null||p.remove(),r.key=i,r.url="none",r.filter=null):(r={key:i,url:"none",filter:null},l(this,W,Zc).set(n,r)),!e||!s))return r.url;const o=w(this,W,su).call(this,e);e=q.makeHexColor(...o);const h=w(this,W,su).call(this,s);if(s=q.makeHexColor(...h),l(this,W,Bh).style.color="",e==="#000000"&&s==="#ffffff"||e===s)return r.url;const c=new Array(256);for(let m=0;m<=255;m++){const y=m/255;c[m]=y<=.03928?y/12.92:((y+.055)/1.055)**2.4}const u=c.join(","),d=`g_${l(this,_n)}_hcm_filter`,f=r.filter=w(this,W,zh).call(this,d);w(this,W,eu).call(this,u,u,u,f),w(this,W,Gp).call(this,f);const g=(m,y)=>{const b=o[m]/255,x=h[m]/255,C=new Array(y+1);for(let S=0;S<=y;S++)C[S]=b+S/y*(x-b);return C.join(",")};return w(this,W,eu).call(this,g(0,5),g(1,5),g(2,5),f),r.url=w(this,W,Hh).call(this,d),r.url}addAlphaFilter(e){let s=l(this,W,Be).get(e);if(s)return s;const[i]=w(this,W,cf).call(this,[e]),n=`alpha_${i}`;if(s=l(this,W,Be).get(n),s)return l(this,W,Be).set(e,s),s;const r=`g_${l(this,_n)}_alpha_map_${es(this,xo)._++}`,o=w(this,W,Hh).call(this,r);l(this,W,Be).set(e,o),l(this,W,Be).set(n,o);const h=w(this,W,zh).call(this,r);return w(this,W,Wp).call(this,i,h),o}addLuminosityFilter(e){let s=l(this,W,Be).get(e||"luminosity");if(s)return s;let i,n;if(e?([i]=w(this,W,cf).call(this,[e]),n=`luminosity_${i}`):n="luminosity",s=l(this,W,Be).get(n),s)return l(this,W,Be).set(e,s),s;const r=`g_${l(this,_n)}_luminosity_map_${es(this,xo)._++}`,o=w(this,W,Hh).call(this,r);l(this,W,Be).set(e,o),l(this,W,Be).set(n,o);const h=w(this,W,zh).call(this,r);return w(this,W,ky).call(this,h),e&&w(this,W,Wp).call(this,i,h),o}addHighlightHCMFilter(e,s,i,n,r){var x;const o=`${s}-${i}-${n}-${r}`;let h=l(this,W,Zc).get(e);if((h==null?void 0:h.key)===o||(h?((x=h.filter)==null||x.remove(),h.key=o,h.url="none",h.filter=null):(h={key:o,url:"none",filter:null},l(this,W,Zc).set(e,h)),!s||!i))return h.url;const[c,u]=[s,i].map(w(this,W,su).bind(this));let d=Math.round(.2126*c[0]+.7152*c[1]+.0722*c[2]),f=Math.round(.2126*u[0]+.7152*u[1]+.0722*u[2]),[g,p]=[n,r].map(w(this,W,su).bind(this));f<d&&([d,f,g,p]=[f,d,p,g]),l(this,W,Bh).style.color="";const m=(C,S,T)=>{const P=new Array(256),M=(f-d)/T,D=C/255,R=(S-C)/(255*T);let V=0;for(let H=0;H<=T;H++){const F=Math.round(d+H*M),I=D+H*R;for(let j=V;j<=F;j++)P[j]=I;V=F+1}for(let H=V;H<256;H++)P[H]=P[V-1];return P.join(",")},y=`g_${l(this,_n)}_hcm_${e}_filter`,b=h.filter=w(this,W,zh).call(this,y);return w(this,W,Gp).call(this,b),w(this,W,eu).call(this,m(g[0],p[0],5),m(g[1],p[1],5),m(g[2],p[2],5),b),h.url=w(this,W,Hh).call(this,y),h.url}destroy(e=!1){var s,i,n,r;e&&((s=l(this,wo))!=null&&s.size)||((i=l(this,yn))==null||i.parentNode.parentNode.remove(),v(this,yn,null),(n=l(this,Ya))==null||n.clear(),v(this,Ya,null),(r=l(this,wo))==null||r.clear(),v(this,wo,null),v(this,xo,0))}}_o=new WeakMap,Ya=new WeakMap,yn=new WeakMap,_n=new WeakMap,Le=new WeakMap,wo=new WeakMap,xo=new WeakMap,W=new WeakSet,Be=function(){return l(this,Ya)||v(this,Ya,new Map)},Zc=function(){return l(this,wo)||v(this,wo,new Map)},Bh=function(){if(!l(this,yn)){const e=l(this,Le).createElement("div"),{style:s}=e;s.visibility="hidden",s.contain="strict",s.width=s.height=0,s.position="absolute",s.top=s.left=0,s.zIndex=-1;const i=l(this,Le).createElementNS(an,"svg");i.setAttribute("width",0),i.setAttribute("height",0),v(this,yn,l(this,Le).createElementNS(an,"defs")),e.append(i),i.append(l(this,yn)),l(this,Le).body.append(e)}return l(this,yn)},cf=function(e){if(e.length===1){const c=e[0],u=new Array(256);for(let f=0;f<256;f++)u[f]=c[f]/255;const d=u.join(",");return[d,d,d]}const[s,i,n]=e,r=new Array(256),o=new Array(256),h=new Array(256);for(let c=0;c<256;c++)r[c]=s[c]/255,o[c]=i[c]/255,h[c]=n[c]/255;return[r.join(","),o.join(","),h.join(",")]},Hh=function(e){if(l(this,_o)===void 0){v(this,_o,"");const s=l(this,Le).URL;s!==l(this,Le).baseURI&&(vd(s)?ht('#createUrl: ignore "data:"-URL for performance reasons.'):v(this,_o,s.split("#",1)[0]))}return`url(${l(this,_o)}#${e})`},ky=function(e){const s=l(this,Le).createElementNS(an,"feColorMatrix");s.setAttribute("type","matrix"),s.setAttribute("values","0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.59 0.11 0 0"),e.append(s)},Gp=function(e){const s=l(this,Le).createElementNS(an,"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)},zh=function(e){const s=l(this,Le).createElementNS(an,"filter");return s.setAttribute("color-interpolation-filters","sRGB"),s.setAttribute("id",e),l(this,W,Bh).append(s),s},tu=function(e,s,i){const n=l(this,Le).createElementNS(an,s);n.setAttribute("type","discrete"),n.setAttribute("tableValues",i),e.append(n)},eu=function(e,s,i,n){const r=l(this,Le).createElementNS(an,"feComponentTransfer");n.append(r),w(this,W,tu).call(this,r,"feFuncR",e),w(this,W,tu).call(this,r,"feFuncG",s),w(this,W,tu).call(this,r,"feFuncB",i)},Wp=function(e,s){const i=l(this,Le).createElementNS(an,"feComponentTransfer");s.append(i),w(this,W,tu).call(this,i,"feFuncA",e)},su=function(e){return l(this,W,Bh).style.color=e,zg(getComputedStyle(l(this,W,Bh)).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){Pt("Abstract method `_fetch` called.")}}class q0 extends $0{async _fetch(t){const e=await md(t,"arraybuffer");return new Uint8Array(e)}}Oe&&ht("Please use the `legacy` build in Node.js environments.");async function K0(a){const e=await process.getBuiltinModule("fs").promises.readFile(a);return new Uint8Array(e)}class jS extends Y0{}class NS extends W0{_createCanvas(t,e){return process.getBuiltinModule("module").createRequire(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ht&&Ht.tagName.toUpperCase()==="SCRIPT"&&Ht.src||new URL("pdf-canvas.umd.js",document.baseURI).href)("@napi-rs/canvas").createCanvas(t,e)}}class BS extends X0{async _fetch(t){return K0(t)}}class HS extends $0{async _fetch(t){return K0(t)}}const Re={FILL:"Fill",STROKE:"Stroke",SHADING:"Shading"};function $g(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 qg{getPattern(){Pt("Abstract method `getPattern` called.")}}class zS extends qg{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===Re.STROKE||i===Re.FILL){const r=e.current.getClippedPathBoundingBox(i,It(t))||[0,0,0,0],o=Math.ceil(r[2]-r[0])||1,h=Math.ceil(r[3]-r[1])||1,c=e.cachedCanvases.getCanvas("pattern",o,h),u=c.context;u.clearRect(0,0,u.canvas.width,u.canvas.height),u.beginPath(),u.rect(0,0,u.canvas.width,u.canvas.height),u.translate(-r[0],-r[1]),s=q.transform(s,[1,0,0,1,r[0],r[1]]),u.transform(...e.baseTransform),this.matrix&&u.transform(...this.matrix),$g(u,this._bbox),u.fillStyle=this._createGradient(u),u.fill(),n=t.createPattern(c.canvas,"no-repeat");const d=new DOMMatrix(s);n.setTransform(d)}else $g(t,this._bbox),n=this._createGradient(t);return n}}function Kg(a,t,e,s,i,n,r,o){const h=t.coords,c=t.colors,u=a.data,d=a.width*4;let f;h[e+1]>h[s+1]&&(f=e,e=s,s=f,f=n,n=r,r=f),h[s+1]>h[i+1]&&(f=s,s=i,i=f,f=r,r=o,o=f),h[e+1]>h[s+1]&&(f=e,e=s,s=f,f=n,n=r,r=f);const g=(h[e]+t.offsetX)*t.scaleX,p=(h[e+1]+t.offsetY)*t.scaleY,m=(h[s]+t.offsetX)*t.scaleX,y=(h[s+1]+t.offsetY)*t.scaleY,b=(h[i]+t.offsetX)*t.scaleX,x=(h[i+1]+t.offsetY)*t.scaleY;if(p>=x)return;const C=c[n],S=c[n+1],T=c[n+2],P=c[r],M=c[r+1],D=c[r+2],R=c[o],V=c[o+1],H=c[o+2],F=Math.round(p),I=Math.round(x);let j,K,L,z,Z,Dt,Bt,Xt;for(let Ft=F;Ft<=I;Ft++){if(Ft<y){const nt=Ft<p?0:(p-Ft)/(p-y);j=g-(g-m)*nt,K=C-(C-P)*nt,L=S-(S-M)*nt,z=T-(T-D)*nt}else{let nt;Ft>x?nt=1:y===x?nt=0:nt=(y-Ft)/(y-x),j=m-(m-b)*nt,K=P-(P-R)*nt,L=M-(M-V)*nt,z=D-(D-H)*nt}let _t;Ft<p?_t=0:Ft>x?_t=1:_t=(p-Ft)/(p-x),Z=g-(g-b)*_t,Dt=C-(C-R)*_t,Bt=S-(S-V)*_t,Xt=T-(T-H)*_t;const oe=Math.round(Math.min(j,Z)),Ze=Math.round(Math.max(j,Z));let it=d*Ft+oe*4;for(let nt=oe;nt<=Ze;nt++)_t=(j-nt)/(j-Z),_t<0?_t=0:_t>1&&(_t=1),u[it++]=K-(K-Dt)*_t|0,u[it++]=L-(L-Bt)*_t|0,u[it++]=z-(z-Xt)*_t|0,u[it++]=255}}function VS(a,t,e){const s=t.coords,i=t.colors;let n,r;switch(t.type){case"lattice":const o=t.verticesPerRow,h=Math.floor(s.length/o)-1,c=o-1;for(n=0;n<h;n++){let u=n*o;for(let d=0;d<c;d++,u++)Kg(a,e,s[u],s[u+1],s[u+o],i[u],i[u+1],i[u+o]),Kg(a,e,s[u+o+1],s[u+1],s[u+o],i[u+o+1],i[u+1],i[u+o])}break;case"triangles":for(n=0,r=s.length;n<r;n+=3)Kg(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 GS extends qg{constructor(t){super(),this._coords=t[2],this._colors=t[3],this._figures=t[4],this._bounds=t[5],this._bbox=t[7],this._background=t[8],this.matrix=null}_createMeshCanvas(t,e,s){const o=Math.floor(this._bounds[0]),h=Math.floor(this._bounds[1]),c=Math.ceil(this._bounds[2])-o,u=Math.ceil(this._bounds[3])-h,d=Math.min(Math.ceil(Math.abs(c*t[0]*1.1)),3e3),f=Math.min(Math.ceil(Math.abs(u*t[1]*1.1)),3e3),g=c/d,p=u/f,m={coords:this._coords,colors:this._colors,offsetX:-o,offsetY:-h,scaleX:1/g,scaleY:1/p},y=d+2*2,b=f+2*2,x=s.getCanvas("mesh",y,b),C=x.context,S=C.createImageData(d,f);if(e){const P=S.data;for(let M=0,D=P.length;M<D;M+=4)P[M]=e[0],P[M+1]=e[1],P[M+2]=e[2],P[M+3]=255}for(const P of this._figures)VS(S,P,m);return C.putImageData(S,2,2),{canvas:x.canvas,offsetX:o-2*g,offsetY:h-2*p,scaleX:g,scaleY:p}}getPattern(t,e,s,i){$g(t,this._bbox);let n;if(i===Re.SHADING)n=q.singularValueDecompose2dScale(It(t));else if(n=q.singularValueDecompose2dScale(e.baseTransform),this.matrix){const o=q.singularValueDecompose2dScale(this.matrix);n=[n[0]*o[0],n[1]*o[1]]}const r=this._createMeshCanvas(n,i===Re.SHADING?null:this._background,e.cachedCanvases);return i!==Re.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 WS extends qg{getPattern(){return"hotpink"}}function XS(a){switch(a[0]){case"RadialAxial":return new zS(a);case"Mesh":return new GS(a);case"Dummy":return new WS}throw new Error(`Unknown IR type: ${a[0]}`)}const J0={COLORED:1,UNCOLORED:2},Nd=class Nd{constructor(t,e,s,i,n){this.operatorList=t[2],this.matrix=t[3],this.bbox=t[4],this.xstep=t[5],this.ystep=t[6],this.paintType=t[7],this.tilingType=t[8],this.color=e,this.ctx=s,this.canvasGraphicsFactory=i,this.baseTransform=n}createPatternCanvas(t){const{bbox:e,operatorList:s,paintType:i,tilingType:n,color:r,canvasGraphicsFactory:o}=this;let{xstep:h,ystep:c}=this;h=Math.abs(h),c=Math.abs(c),fd("TilingType: "+n);const u=e[0],d=e[1],f=e[2],g=e[3],p=f-u,m=g-d,y=q.singularValueDecompose2dScale(this.matrix),b=q.singularValueDecompose2dScale(this.baseTransform),x=y[0]*b[0],C=y[1]*b[1];let S=p,T=m,P=!1,M=!1;const D=Math.ceil(h*x),R=Math.ceil(c*C),V=Math.ceil(p*x),H=Math.ceil(m*C);D>=V?S=h:P=!0,R>=H?T=c:M=!0;const F=this.getSizeAndScale(S,this.ctx.canvas.width,x),I=this.getSizeAndScale(T,this.ctx.canvas.height,C),j=t.cachedCanvases.getCanvas("pattern",F.size,I.size),K=j.context,L=o.createCanvasGraphics(K);if(L.groupLevel=t.groupLevel,this.setFillAndStrokeStyleToContext(L,i,r),K.translate(-F.scale*u,-I.scale*d),L.transform(F.scale,0,0,I.scale,0,0),K.save(),this.clipBbox(L,u,d,f,g),L.baseTransform=It(L.ctx),L.executeOperatorList(s),L.endDrawing(),K.restore(),P||M){const z=j.canvas;P&&(S=h),M&&(T=c);const Z=this.getSizeAndScale(S,this.ctx.canvas.width,x),Dt=this.getSizeAndScale(T,this.ctx.canvas.height,C),Bt=Z.size,Xt=Dt.size,Ft=t.cachedCanvases.getCanvas("pattern-workaround",Bt,Xt),_t=Ft.context,oe=P?Math.floor(p/h):0,Ze=M?Math.floor(m/c):0;for(let it=0;it<=oe;it++)for(let nt=0;nt<=Ze;nt++)_t.drawImage(z,Bt*it,Xt*nt,Bt,Xt,0,0,Bt,Xt);return{canvas:Ft.canvas,scaleX:Z.scale,scaleY:Dt.scale,offsetX:u,offsetY:d}}return{canvas:j.canvas,scaleX:F.scale,scaleY:I.scale,offsetX:u,offsetY:d}}getSizeAndScale(t,e,s){const i=Math.max(Nd.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(It(t.ctx),[e,s,i,n]),t.clip(),t.endPath()}setFillAndStrokeStyleToContext(t,e,s){const i=t.ctx,n=t.current;switch(e){case J0.COLORED:const r=this.ctx;i.fillStyle=r.fillStyle,i.strokeStyle=r.strokeStyle,n.fillColor=r.fillStyle,n.strokeColor=r.strokeStyle;break;case J0.UNCOLORED:const o=q.makeHexColor(s[0],s[1],s[2]);i.fillStyle=o,i.strokeStyle=o,n.fillColor=o,n.strokeColor=o;break;default:throw new vS(`Unsupported paint type: ${e}`)}}getPattern(t,e,s,i){let n=s;i!==Re.SHADING&&(n=q.transform(n,e.baseTransform),this.matrix&&(n=q.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(Nd,"MAX_PATTERN_SIZE",3e3);let Jg=Nd;function US({src:a,srcPos:t=0,dest:e,width:s,height:i,nonBlackColor:n=4294967295,inverseDecode:r=!1}){const o=Ue.isLittleEndian?4278190080:255,[h,c]=r?[n,o]:[o,n],u=s>>3,d=s&7,f=a.length;e=new Uint32Array(e.buffer);let g=0;for(let p=0;p<i;p++){for(const y=t+u;t<y;t++){const b=t<f?a[t]:255;e[g++]=b&128?c:h,e[g++]=b&64?c:h,e[g++]=b&32?c:h,e[g++]=b&16?c:h,e[g++]=b&8?c:h,e[g++]=b&4?c:h,e[g++]=b&2?c:h,e[g++]=b&1?c:h}if(d===0)continue;const m=t<f?a[t++]:255;for(let y=0;y<d;y++)e[g++]=m&1<<7-y?c:h}return{srcPos:t,destPos:g}}const Q0=16,Z0=100,YS=15,tb=10,eb=1e3,os=16;function $S(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 qS{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 xd(a,t,e,s,i,n,r,o,h,c){const[u,d,f,g,p,m]=It(a);if(d===0&&f===0){const x=r*u+p,C=Math.round(x),S=o*g+m,T=Math.round(S),P=(r+h)*u+p,M=Math.abs(Math.round(P)-C)||1,D=(o+c)*g+m,R=Math.abs(Math.round(D)-T)||1;return a.setTransform(Math.sign(u),0,0,Math.sign(g),C,T),a.drawImage(t,e,s,i,n,0,0,M,R),a.setTransform(u,d,f,g,p,m),[M,R]}if(u===0&&g===0){const x=o*f+p,C=Math.round(x),S=r*d+m,T=Math.round(S),P=(o+c)*f+p,M=Math.abs(Math.round(P)-C)||1,D=(r+h)*d+m,R=Math.abs(Math.round(D)-T)||1;return a.setTransform(0,Math.sign(d),Math.sign(f),0,C,T),a.drawImage(t,e,s,i,n,0,0,R,M),a.setTransform(u,d,f,g,p,m),[R,M]}a.drawImage(t,e,s,i,n,r,o,h,c);const y=Math.hypot(u,d),b=Math.hypot(f,g);return[y*h,b*c]}function KS(a){const{width:t,height:e}=a;if(t>eb||e>eb)return null;const s=1e3,i=new Uint8Array([0,2,4,0,1,0,5,4,8,10,0,8,0,2,1,0]),n=t+1;let r=new Uint8Array(n*(e+1)),o,h,c;const u=t+7&-8;let d=new Uint8Array(u*e),f=0;for(const b of a.data){let x=128;for(;x>0;)d[f++]=b&x?0:255,x>>=1}let g=0;for(f=0,d[f]!==0&&(r[0]=1,++g),h=1;h<t;h++)d[f]!==d[f+1]&&(r[h]=d[f]?2:1,++g),f++;for(d[f]!==0&&(r[h]=2,++g),o=1;o<e;o++){f=o*u,c=o*n,d[f-u]!==d[f]&&(r[c]=d[f]?1:8,++g);let b=(d[f]?4:0)+(d[f-u]?8:0);for(h=1;h<t;h++)b=(b>>2)+(d[f+1]?4:0)+(d[f-u+1]?8:0),i[b]&&(r[c+h]=i[b],++g),f++;if(d[f-u]!==d[f]&&(r[c+h]=d[f]?2:4,++g),g>s)return null}for(f=u*(e-1),c=o*n,d[f]!==0&&(r[c]=8,++g),h=1;h<t;h++)d[f]!==d[f+1]&&(r[c+h]=d[f]?4:8,++g),f++;if(d[f]!==0&&(r[c+h]=4,++g),g>s)return null;const p=new Int32Array([0,n,-1,0,-n,0,0,0,1]),m=new Path2D;for(o=0;g&&o<=e;o++){let b=o*n;const x=b+t;for(;b<x&&!r[b];)b++;if(b===x)continue;m.moveTo(b%n,o);const C=b;let S=r[b];do{const T=p[S];do b+=T;while(!r[b]);const P=r[b];P!==5&&P!==10?(S=P,r[b]=0):(S=P&51*S>>4,r[b]&=S>>2|S<<2),m.lineTo(b%n,b/n|0),r[b]||--g}while(C!==b);--o}return d=null,r=null,function(b){b.save(),b.scale(1/t,-1/e),b.translate(0,-e),b.fill(m),b.beginPath(),b.restore()}}class sb{constructor(t,e){this.alphaIsShape=!1,this.fontSize=0,this.fontSizeScale=1,this.textMatrix=L0,this.textMatrixScale=1,this.fontMatrix=Mg,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=De.FILL,this.textRise=0,this.fillColor="#000000",this.strokeColor="#000000",this.patternFill=!1,this.patternStroke=!1,this.fillAlpha=1,this.strokeAlpha=1,this.lineWidth=1,this.activeSMask=null,this.transferMaps="none",this.startNewPathAndClipBox([0,0,t,e])}clone(){const t=Object.create(this);return t.clipBox=this.clipBox.slice(),t}setCurrentPoint(t,e){this.x=t,this.y=e}updatePathMinMax(t,e,s){[e,s]=q.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=q.applyTransform(e,t),i=q.applyTransform(e.slice(2),t),n=q.applyTransform([e[0],e[3]],t),r=q.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){q.scaleMinMax(t,e),this.minX=Math.min(this.minX,e[0]),this.minY=Math.min(this.minY,e[1]),this.maxX=Math.max(this.maxX,e[2]),this.maxY=Math.max(this.maxY,e[3])}updateCurvePathMinMax(t,e,s,i,n,r,o,h,c,u){const d=q.bezierBoundingBox(e,s,i,n,r,o,h,c,u);u||this.updateRectMinMax(t,d)}getPathBoundingBox(t=Re.FILL,e=null){const s=[this.minX,this.minY,this.maxX,this.maxY];if(t===Re.STROKE){e||Pt("Stroke bounding box must include transform.");const i=q.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=q.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=Re.FILL,e=null){return q.intersect(this.clipBox,this.getPathBoundingBox(t,e))}}function ib(a,t){if(t instanceof ImageData){a.putImageData(t,0,0);return}const e=t.height,s=t.width,i=e%os,n=(e-i)/os,r=i===0?n:n+1,o=a.createImageData(s,os);let h=0,c;const u=t.data,d=o.data;let f,g,p,m;if(t.kind===cd.GRAYSCALE_1BPP){const y=u.byteLength,b=new Uint32Array(d.buffer,0,d.byteLength>>2),x=b.length,C=s+7>>3,S=4294967295,T=Ue.isLittleEndian?4278190080:255;for(f=0;f<r;f++){for(p=f<n?os:i,c=0,g=0;g<p;g++){const P=y-h;let M=0;const D=P>C?s:P*8-7,R=D&-8;let V=0,H=0;for(;M<R;M+=8)H=u[h++],b[c++]=H&128?S:T,b[c++]=H&64?S:T,b[c++]=H&32?S:T,b[c++]=H&16?S:T,b[c++]=H&8?S:T,b[c++]=H&4?S:T,b[c++]=H&2?S:T,b[c++]=H&1?S:T;for(;M<D;M++)V===0&&(H=u[h++],V=128),b[c++]=H&V?S:T,V>>=1}for(;c<x;)b[c++]=0;a.putImageData(o,0,f*os)}}else if(t.kind===cd.RGBA_32BPP){for(g=0,m=s*os*4,f=0;f<n;f++)d.set(u.subarray(h,h+m)),h+=m,a.putImageData(o,0,g),g+=os;f<r&&(m=s*i*4,d.set(u.subarray(h,h+m)),a.putImageData(o,0,g))}else if(t.kind===cd.RGB_24BPP)for(p=os,m=s*p,f=0;f<r;f++){for(f>=n&&(p=i,m=s*p),c=0,g=m;g--;)d[c++]=u[h++],d[c++]=u[h++],d[c++]=u[h++],d[c++]=255;a.putImageData(o,0,f*os)}else throw new Error(`bad image kind: ${t.kind}`)}function nb(a,t){if(t.bitmap){a.drawImage(t.bitmap,0,0);return}const e=t.height,s=t.width,i=e%os,n=(e-i)/os,r=i===0?n:n+1,o=a.createImageData(s,os);let h=0;const c=t.data,u=o.data;for(let d=0;d<r;d++){const f=d<n?os:i;({srcPos:h}=US({src:c,srcPos:h,dest:u,width:s,height:f,nonBlackColor:0})),a.putImageData(o,0,d*os)}}function vl(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 Sd(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),!Oe){const{filter:t}=a;t!=="none"&&t!==""&&(a.filter="none")}}function rb(a,t){if(t)return!0;const e=q.singularValueDecompose2dScale(a);e[0]=Math.fround(e[0]),e[1]=Math.fround(e[1]);const s=Math.fround((globalThis.devicePixelRatio||1)*Kn.PDF_TO_CSS_UNITS);return e[0]<=s&&e[1]<=s}const JS=["butt","round","square"],QS=["miter","round","bevel"],ZS={},ob={},vp=class vp{constructor(t,e,s,i,n,{optionalContentConfig:r,markedContentStack:o=null},h,c){_(this,ci);this.ctx=t,this.current=new sb(this.ctx.canvas.width,this.ctx.canvas.height),this.stateStack=[],this.pendingClip=null,this.pendingEOFill=!1,this.res=null,this.xobjs=null,this.commonObjs=e,this.objs=s,this.canvasFactory=i,this.filterFactory=n,this.groupStack=[],this.processingType3=null,this.baseTransform=null,this.baseTransformStack=[],this.groupLevel=0,this.smaskStack=[],this.smaskCounter=0,this.tempSMask=null,this.suspendedCtx=null,this.contentVisible=!0,this.markedContentStack=o||[],this.optionalContentConfig=r,this.cachedCanvases=new qS(this.canvasFactory),this.cachedPatterns=new Map,this.annotationCanvasMap=h,this.viewportScale=1,this.outputScaleX=1,this.outputScaleY=1,this.pageColors=c,this._cachedScaleForStroking=[-1,0],this._cachedGetSinglePixelWidth=null,this._cachedBitmapsMap=new Map}getObject(t,e=null){return typeof t=="string"?t.startsWith("g_")?this.commonObjs.get(t):this.objs.get(t):e}beginDrawing({transform:t,viewport:e,transparency:s=!1,background:i=null}){const n=this.ctx.canvas.width,r=this.ctx.canvas.height,o=this.ctx.fillStyle;if(this.ctx.fillStyle=i||"#ffffff",this.ctx.fillRect(0,0,n,r),this.ctx.fillStyle=o,s){const h=this.cachedCanvases.getCanvas("transparent",n,r);this.compositeCtx=this.ctx,this.transparentCanvas=h.canvas,this.ctx=h.context,this.ctx.save(),this.ctx.transform(...It(this.compositeCtx))}this.ctx.save(),Sd(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=It(this.ctx)}executeOperatorList(t,e,s,i){const n=t.argsArray,r=t.fnArray;let o=e||0;const h=n.length;if(h===o)return o;const c=h-o>tb&&typeof s=="function",u=c?Date.now()+YS:0;let d=0;const f=this.commonObjs,g=this.objs;let p;for(;;){if(i!==void 0&&o===i.nextBreakPoint)return i.breakIt(o,s),o;if(p=r[o],p!==ii.dependency)this[p].apply(this,n[o]);else for(const m of n[o]){const y=m.startsWith("g_")?f:g;if(!y.has(m))return y.get(m,s),o}if(o++,o===h)return o;if(c&&++d>tb){if(Date.now()>u)return s(),o;d=0}}}endDrawing(){w(this,ci,Xp).call(this),this.cachedCanvases.clear(),this.cachedPatterns.clear();for(const t of this._cachedBitmapsMap.values()){for(const e of t.values())typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement&&(e.width=e.height=0);t.clear()}this._cachedBitmapsMap.clear(),w(this,ci,Up).call(this)}_scaleImage(t,e){const s=t.width??t.displayWidth,i=t.height??t.displayHeight;let n=Math.max(Math.hypot(e[0],e[1]),1),r=Math.max(Math.hypot(e[2],e[3]),1),o=s,h=i,c="prescale1",u,d;for(;n>2&&o>1||r>2&&h>1;){let f=o,g=h;n>2&&o>1&&(f=o>=16384?Math.floor(o/2)-1||1:Math.ceil(o/2),n/=o/f),r>2&&h>1&&(g=h>=16384?Math.floor(h/2)-1||1:Math.ceil(h)/2,r/=h/g),u=this.cachedCanvases.getCanvas(c,f,g),d=u.context,d.clearRect(0,0,f,g),d.drawImage(t,0,0,o,h,0,0,f,g),t=u.canvas,o=f,h=g,c=c==="prescale1"?"prescale2":"prescale1"}return{img:t,paintWidth:o,paintHeight:h}}_createMaskCanvas(t){const e=this.ctx,{width:s,height:i}=t,n=this.current.fillColor,r=this.current.patternFill,o=It(e);let h,c,u,d;if((t.bitmap||t.data)&&t.count>1){const D=t.bitmap||t.data.buffer;c=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(c);if(R&&!r){const V=Math.round(Math.min(o[0],o[2])+o[4]),H=Math.round(Math.min(o[1],o[3])+o[5]);return{canvas:R,offsetX:V,offsetY:H}}u=R}u||(d=this.cachedCanvases.getCanvas("maskCanvas",s,i),nb(d.context,t));let f=q.transform(o,[1/s,0,0,-1/i,0,0]);f=q.transform(f,[1,0,0,1,0,-i]);const[g,p,m,y]=q.getAxialAlignedBoundingBox([0,0,s,i],f),b=Math.round(m-g)||1,x=Math.round(y-p)||1,C=this.cachedCanvases.getCanvas("fillCanvas",b,x),S=C.context,T=g,P=p;S.translate(-T,-P),S.transform(...f),u||(u=this._scaleImage(d.canvas,ki(S)),u=u.img,h&&r&&h.set(c,u)),S.imageSmoothingEnabled=rb(It(S),t.interpolate),xd(S,u,0,0,u.width,u.height,0,0,s,i),S.globalCompositeOperation="source-in";const M=q.transform(ki(S),[1,0,0,1,-T,-P]);return S.fillStyle=r?n.getPattern(e,this,M,Re.FILL):n,S.fillRect(0,0,s,i),h&&!r&&(this.cachedCanvases.delete("fillCanvas"),h.set(c,C.canvas)),{canvas:C.canvas,offsetX:Math.round(T),offsetY:Math.round(P)}}setLineWidth(t){t!==this.current.lineWidth&&(this._cachedScaleForStroking[0]=-1),this.current.lineWidth=t,this.ctx.lineWidth=t}setLineCap(t){this.ctx.lineCap=JS[t]}setLineJoin(t){this.ctx.lineJoin=QS[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(...It(this.suspendedCtx)),vl(this.suspendedCtx,n),$S(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(),vl(this.ctx,this.suspendedCtx),this.ctx=this.suspendedCtx,this.suspendedCtx=null}compose(t){if(!this.current.activeSMask)return;t?(t[0]=Math.floor(t[0]),t[1]=Math.floor(t[1]),t[2]=Math.ceil(t[2]),t[3]=Math.ceil(t[3])):t=[0,0,this.ctx.canvas.width,this.ctx.canvas.height];const e=this.current.activeSMask,s=this.suspendedCtx;this.composeSMask(s,e,this.ctx,t),this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.ctx.restore()}composeSMask(t,e,s,i){const n=i[0],r=i[1],o=i[2]-n,h=i[3]-r;o===0||h===0||(this.genericComposeSMask(e.context,s,o,h,e.subtype,e.backdrop,e.transferMap,n,r,e.offsetX,e.offsetY),t.save(),t.globalAlpha=1,t.globalCompositeOperation="source-over",t.setTransform(1,0,0,1,0,0),t.drawImage(s.canvas,0,0),t.restore())}genericComposeSMask(t,e,s,i,n,r,o,h,c,u,d){let f=t.canvas,g=h-u,p=c-d;if(r){const y=q.makeHexColor(...r);if(g<0||p<0||g+s>f.width||p+i>f.height){const b=this.cachedCanvases.getCanvas("maskExtension",s,i),x=b.context;x.drawImage(f,-g,-p),x.globalCompositeOperation="destination-atop",x.fillStyle=y,x.fillRect(0,0,s,i),x.globalCompositeOperation="source-over",f=b.canvas,g=p=0}else{t.save(),t.globalAlpha=1,t.setTransform(1,0,0,1,0,0);const b=new Path2D;b.rect(g,p,s,i),t.clip(b),t.globalCompositeOperation="destination-atop",t.fillStyle=y,t.fillRect(g,p,s,i),t.restore()}}e.save(),e.globalAlpha=1,e.setTransform(1,0,0,1,0,0),n==="Alpha"&&o?e.filter=this.filterFactory.addAlphaFilter(o):n==="Luminosity"&&(e.filter=this.filterFactory.addLuminosityFilter(o));const m=new Path2D;m.rect(h,c,s,i),e.clip(m),e.globalCompositeOperation="destination-in",e.drawImage(f,g,p,s,i,h,c,s,i),e.restore()}save(){this.inSMaskMode?(vl(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(),vl(this.suspendedCtx,this.ctx)):this.ctx.restore(),this.checkSMaskState(),this.pendingClip=null,this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null)}transform(t,e,s,i,n,r){this.ctx.transform(t,e,s,i,n,r),this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null}constructPath(t,e,s){const i=this.ctx,n=this.current;let r=n.x,o=n.y,h,c;const u=It(i),d=u[0]===0&&u[3]===0||u[1]===0&&u[2]===0,f=d?s.slice(0):null;for(let g=0,p=0,m=t.length;g<m;g++)switch(t[g]|0){case ii.rectangle:r=e[p++],o=e[p++];const y=e[p++],b=e[p++],x=r+y,C=o+b;i.moveTo(r,o),y===0||b===0?i.lineTo(x,C):(i.lineTo(x,o),i.lineTo(x,C),i.lineTo(r,C)),d||n.updateRectMinMax(u,[r,o,x,C]),i.closePath();break;case ii.moveTo:r=e[p++],o=e[p++],i.moveTo(r,o),d||n.updatePathMinMax(u,r,o);break;case ii.lineTo:r=e[p++],o=e[p++],i.lineTo(r,o),d||n.updatePathMinMax(u,r,o);break;case ii.curveTo:h=r,c=o,r=e[p+4],o=e[p+5],i.bezierCurveTo(e[p],e[p+1],e[p+2],e[p+3],r,o),n.updateCurvePathMinMax(u,h,c,e[p],e[p+1],e[p+2],e[p+3],r,o,f),p+=6;break;case ii.curveTo2:h=r,c=o,i.bezierCurveTo(r,o,e[p],e[p+1],e[p+2],e[p+3]),n.updateCurvePathMinMax(u,h,c,r,o,e[p],e[p+1],e[p+2],e[p+3],f),r=e[p+2],o=e[p+3],p+=4;break;case ii.curveTo3:h=r,c=o,r=e[p+2],o=e[p+3],i.bezierCurveTo(e[p],e[p+1],r,o,r,o),n.updateCurvePathMinMax(u,h,c,e[p],e[p+1],r,o,r,o,f),p+=4;break;case ii.closePath:i.closePath();break}d&&n.updateScalingPathMinMax(u,f),n.setCurrentPoint(r,o)}closePath(){this.ctx.closePath()}stroke(t=!0){const e=this.ctx,s=this.current.strokeColor;e.globalAlpha=this.current.strokeAlpha,this.contentVisible&&(typeof s=="object"&&(s!=null&&s.getPattern)?(e.save(),e.strokeStyle=s.getPattern(e,this,ki(e),Re.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,ki(e),Re.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=ZS}eoClip(){this.pendingClip=ob}beginText(){this.current.textMatrix=L0,this.current.textMatrixScale=1,this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0}endText(){const t=this.pendingTextPaths,e=this.ctx;if(t===void 0){e.beginPath();return}const s=new Path2D,i=e.getTransform().invertSelf();for(const{transform:n,x:r,y:o,fontSize:h,path:c}of t)s.addPath(c,new DOMMatrix(n).preMultiplySelf(i).translate(r,o).scale(h,-h));e.clip(s),e.beginPath(),delete this.pendingTextPaths}setCharSpacing(t){this.current.charSpacing=t}setWordSpacing(t){this.current.wordSpacing=t}setHScale(t){this.current.textHScale=t/100}setLeading(t){this.current.leading=-t}setFont(t,e){var u;const s=this.commonObjs.get(t),i=this.current;if(!s)throw new Error(`Can't find font for ${t}`);if(i.fontMatrix=s.fontMatrix||Mg,(i.fontMatrix[0]===0||i.fontMatrix[3]===0)&&ht("Invalid font matrix for font "+t),e<0?(e=-e,i.fontDirection=-1):i.fontDirection=1,this.current.font=s,this.current.fontSize=e,s.isType3Font)return;const n=s.loadedName||"sans-serif",r=((u=s.systemFontInfo)==null?void 0:u.css)||`"${n}", ${s.fallbackName}`;let o="normal";s.black?o="900":s.bold&&(o="bold");const h=s.italic?"italic":"normal";let c=e;e<Q0?c=Q0:e>Z0&&(c=Z0),this.current.fontSizeScale=e/c,this.ctx.font=`${h} ${o} ${c}px ${r}`}setTextRenderingMode(t){this.current.textRenderingMode=t}setTextRise(t){this.current.textRise=t}moveText(t,e){this.current.x=this.current.lineX+=t,this.current.y=this.current.lineY+=e}setLeadingMoveText(t,e){this.setLeading(-e),this.moveText(t,e)}setTextMatrix(t,e,s,i,n,r){this.current.textMatrix=[t,e,s,i,n,r],this.current.textMatrixScale=Math.hypot(t,e),this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0}nextLine(){this.moveText(0,this.current.leading)}paintChar(t,e,s,i,n){const r=this.ctx,o=this.current,h=o.font,c=o.textRenderingMode,u=o.fontSize/o.fontSizeScale,d=c&De.FILL_STROKE_MASK,f=!!(c&De.ADD_TO_PATH_FLAG),g=o.patternFill&&!h.missingFile,p=o.patternStroke&&!h.missingFile;let m;if((h.disableFontFace||f||g||p)&&(m=h.getPathGenerator(this.commonObjs,t)),h.disableFontFace||g||p){if(r.save(),r.translate(e,s),r.scale(u,-u),d===De.FILL||d===De.FILL_STROKE)if(i){const y=r.getTransform();r.setTransform(...i),r.fill(w(this,ci,Yp).call(this,m,y,i))}else r.fill(m);if(d===De.STROKE||d===De.FILL_STROKE)if(n){const y=r.getTransform();r.setTransform(...n),r.stroke(w(this,ci,Yp).call(this,m,y,n))}else r.lineWidth/=u,r.stroke(m);r.restore()}else(d===De.FILL||d===De.FILL_STROKE)&&r.fillText(t,e,s),(d===De.STROKE||d===De.FILL_STROKE)&&r.strokeText(t,e,s);f&&(this.pendingTextPaths||(this.pendingTextPaths=[])).push({transform:It(r),x:e,y:s,fontSize:u,path:m})}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 ct(this,"isFontSubpixelAAEnabled",s)}showText(t){const e=this.current,s=e.font;if(s.isType3Font)return this.showType3Text(t);const i=e.fontSize;if(i===0)return;const n=this.ctx,r=e.fontSizeScale,o=e.charSpacing,h=e.wordSpacing,c=e.fontDirection,u=e.textHScale*c,d=t.length,f=s.vertical,g=f?1:-1,p=s.defaultVMetrics,m=i*e.fontMatrix[0],y=e.textRenderingMode===De.FILL&&!s.disableFontFace&&!e.patternFill;n.save(),n.transform(...e.textMatrix),n.translate(e.x,e.y+e.textRise),c>0?n.scale(u,-1):n.scale(u,1);let b,x;if(e.patternFill){n.save();const M=e.fillColor.getPattern(n,this,ki(n),Re.FILL);b=It(n),n.restore(),n.fillStyle=M}if(e.patternStroke){n.save();const M=e.strokeColor.getPattern(n,this,ki(n),Re.STROKE);x=It(n),n.restore(),n.strokeStyle=M}let C=e.lineWidth;const S=e.textMatrixScale;if(S===0||C===0){const M=e.textRenderingMode&De.FILL_STROKE_MASK;(M===De.STROKE||M===De.FILL_STROKE)&&(C=this.getSinglePixelWidth())}else C/=S;if(r!==1&&(n.scale(r,r),C/=r),n.lineWidth=C,s.isInvalidPDFjsFont){const M=[];let D=0;for(const R of t)M.push(R.unicode),D+=R.width;n.fillText(M.join(""),0,0),e.x+=D*m*u,n.restore(),this.compose();return}let T=0,P;for(P=0;P<d;++P){const M=t[P];if(typeof M=="number"){T+=g*M*i/1e3;continue}let D=!1;const R=(M.isSpace?h:0)+o,V=M.fontChar,H=M.accent;let F,I,j=M.width;if(f){const L=M.vmetric||p,z=-(M.vmetric?L[1]:j*.5)*m,Z=L[2]*m;j=L?-L[0]:j,F=z/r,I=(T+Z)/r}else F=T/r,I=0;if(s.remeasure&&j>0){const L=n.measureText(V).width*1e3/i*r;if(j<L&&this.isFontSubpixelAAEnabled){const z=j/L;D=!0,n.save(),n.scale(z,1),F/=z}else j!==L&&(F+=(j-L)/2e3*i/r)}if(this.contentVisible&&(M.isInFont||s.missingFile)){if(y&&!H)n.fillText(V,F,I);else if(this.paintChar(V,F,I,b,x),H){const L=F+i*H.offset.x/r,z=I-i*H.offset.y/r;this.paintChar(H.fontChar,L,z,b,x)}}const K=f?j*m-R*c:j*m+R*c;T+=K,D&&n.restore()}f?e.y-=T:e.x+=T*u,n.restore(),this.compose()}showType3Text(t){const e=this.ctx,s=this.current,i=s.font,n=s.fontSize,r=s.fontDirection,o=i.vertical?1:-1,h=s.charSpacing,c=s.wordSpacing,u=s.textHScale*r,d=s.fontMatrix||Mg,f=t.length,g=s.textRenderingMode===De.INVISIBLE;let p,m,y,b;if(!(g||n===0)){for(this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null,e.save(),e.transform(...s.textMatrix),e.translate(s.x,s.y),e.scale(u,r),p=0;p<f;++p){if(m=t[p],typeof m=="number"){b=o*m*n/1e3,this.ctx.translate(b,0),s.x+=b*u;continue}const x=(m.isSpace?c:0)+h,C=i.charProcOperatorList[m.operatorListId];if(!C){ht(`Type3 character "${m.operatorListId}" is not available.`);continue}this.contentVisible&&(this.processingType3=m,this.save(),e.scale(n,n),e.transform(...d),this.executeOperatorList(C),this.restore()),y=q.applyTransform([m.width,0],d)[0]*n+x,e.translate(y,0),s.x+=y*u}e.restore(),this.processingType3=null}}setCharWidth(t,e){}setCharWidthAndBounds(t,e,s,i,n,r){this.ctx.rect(s,i,n-s,r-i),this.ctx.clip(),this.endPath()}getColorN_Pattern(t){let e;if(t[0]==="TilingPattern"){const s=t[1],i=this.baseTransform||It(this.ctx),n={createCanvasGraphics:r=>new vp(r,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack})};e=new Jg(t,s,this.ctx,n,i)}else e=this._getPattern(t[1],t[2]);return e}setStrokeColorN(){this.current.strokeColor=this.getColorN_Pattern(arguments),this.current.patternStroke=!0}setFillColorN(){this.current.fillColor=this.getColorN_Pattern(arguments),this.current.patternFill=!0}setStrokeRGBColor(t,e,s){this.ctx.strokeStyle=this.current.strokeColor=q.makeHexColor(t,e,s),this.current.patternStroke=!1}setStrokeTransparent(){this.ctx.strokeStyle=this.current.strokeColor="transparent",this.current.patternStroke=!1}setFillRGBColor(t,e,s){this.ctx.fillStyle=this.current.fillColor=q.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=XS(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,ki(e),Re.SHADING);const i=ki(e);if(i){const{width:n,height:r}=e.canvas,[o,h,c,u]=q.getAxialAlignedBoundingBox([0,0,n,r],i);this.ctx.fillRect(o,h,c-o,u-h)}else this.ctx.fillRect(-1e10,-1e10,2e10,2e10);this.compose(this.current.getClippedPathBoundingBox()),this.restore()}beginInlineImage(){Pt("Should not call beginInlineImage")}beginImageData(){Pt("Should not call beginImageData")}paintFormXObjectBegin(t,e){if(this.contentVisible&&(this.save(),this.baseTransformStack.push(this.baseTransform),t&&this.transform(...t),this.baseTransform=It(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(It(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||fd("TODO: Support non-isolated groups."),t.knockout&&ht("Knockout groups not supported.");const s=It(e);if(t.matrix&&e.transform(...t.matrix),!t.bbox)throw new Error("Bounding box is required.");let i=q.getAxialAlignedBoundingBox(t.bbox,It(e));const n=[0,0,e.canvas.width,e.canvas.height];i=q.intersect(i,n)||[0,0,0,0];const r=Math.floor(i[0]),o=Math.floor(i[1]),h=Math.max(Math.ceil(i[2])-r,1),c=Math.max(Math.ceil(i[3])-o,1);this.current.startNewPathAndClipBox([0,0,h,c]);let u="groupAt"+this.groupLevel;t.smask&&(u+="_smask_"+this.smaskCounter++%2);const d=this.cachedCanvases.getCanvas(u,h,c),f=d.context;f.translate(-r,-o),f.transform(...s),t.smask?this.smaskStack.push({canvas:d.canvas,context:f,offsetX:r,offsetY:o,subtype:t.smask.subtype,backdrop:t.smask.backdrop,transferMap:t.smask.transferMap||null,startTransformInverse:null}):(e.setTransform(1,0,0,1,0,0),e.translate(r,o),e.save()),vl(e,f),this.ctx=f,this.setGState([["BM","source-over"],["ca",1],["CA",1]]),this.groupStack.push(e),this.groupLevel++}endGroup(t){if(!this.contentVisible)return;this.groupLevel--;const e=this.ctx,s=this.groupStack.pop();if(this.ctx=s,this.ctx.imageSmoothingEnabled=!1,t.smask)this.tempSMask=this.smaskStack.pop(),this.restore();else{this.ctx.restore();const i=It(this.ctx);this.restore(),this.ctx.save(),this.ctx.setTransform(...i);const n=q.getAxialAlignedBoundingBox([0,0,e.canvas.width,e.canvas.height],i);this.ctx.drawImage(e.canvas,0,0),this.ctx.restore(),this.compose(n)}}beginAnnotation(t,e,s,i,n){if(w(this,ci,Xp).call(this),Sd(this.ctx),this.ctx.save(),this.save(),this.baseTransform&&this.ctx.setTransform(...this.baseTransform),e){const r=e[2]-e[0],o=e[3]-e[1];if(n&&this.annotationCanvasMap){s=s.slice(),s[4]-=e[0],s[5]-=e[1],e=e.slice(),e[0]=e[1]=0,e[2]=r,e[3]=o;const[h,c]=q.singularValueDecompose2dScale(It(this.ctx)),{viewportScale:u}=this,d=Math.ceil(r*this.outputScaleX*u),f=Math.ceil(o*this.outputScaleY*u);this.annotationCanvas=this.canvasFactory.create(d,f);const{canvas:g,context:p}=this.annotationCanvas;this.annotationCanvasMap.set(t,g),this.annotationCanvas.savedCtx=this.ctx,this.ctx=p,this.ctx.save(),this.ctx.setTransform(h,0,0,-c,0,o*c),Sd(this.ctx)}else Sd(this.ctx),this.endPath(),this.ctx.rect(e[0],e[1],r,o),this.ctx.clip(),this.ctx.beginPath()}this.current=new sb(this.ctx.canvas.width,this.ctx.canvas.height),this.transform(...s),this.transform(...i)}endAnnotation(){this.annotationCanvas&&(this.ctx.restore(),w(this,ci,Up).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=KS(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=It(o);o.transform(e,s,i,n,0,0);const c=this._createMaskCanvas(t);o.setTransform(1,0,0,1,c.offsetX-h[4],c.offsetY-h[5]);for(let u=0,d=r.length;u<d;u+=2){const f=q.transform(h,[e,s,i,n,r[u],r[u+1]]),[g,p]=q.applyTransform([0,0],f);o.drawImage(c.canvas,g,p)}o.restore(),this.compose()}paintImageMaskXObjectGroup(t){if(!this.contentVisible)return;const e=this.ctx,s=this.current.fillColor,i=this.current.patternFill;for(const n of t){const{data:r,width:o,height:h,transform:c}=n,u=this.cachedCanvases.getCanvas("maskCanvas",o,h),d=u.context;d.save();const f=this.getObject(r,n);nb(d,f),d.globalCompositeOperation="source-in",d.fillStyle=i?s.getPattern(d,this,ki(e),Re.FILL):s,d.fillRect(0,0,o,h),d.restore(),e.save(),e.transform(...c),e.scale(1,-1),xd(e,u.canvas,0,0,o,h,0,-1,1,1),e.restore()}this.compose()}paintImageXObject(t){if(!this.contentVisible)return;const e=this.getObject(t);if(!e){ht("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){ht("Dependent image isn't ready yet");return}const r=n.width,o=n.height,h=[];for(let c=0,u=i.length;c<u;c+=2)h.push({transform:[e,0,0,s,i[c],i[c+1]],x:0,y:0,w:r,h:o});this.paintInlineImageXObjectGroup(n,h)}applyTransferMapsToCanvas(t){return this.current.transferMaps!=="none"&&(t.filter=this.current.transferMaps,t.drawImage(t.canvas,0,0),t.filter="none"),t.canvas}applyTransferMapsToBitmap(t){if(this.current.transferMaps==="none")return t.bitmap;const{bitmap:e,width:s,height:i}=t,n=this.cachedCanvases.getCanvas("inlineImage",s,i),r=n.context;return r.filter=this.current.transferMaps,r.drawImage(e,0,0),r.filter="none",n.canvas}paintInlineImageXObject(t){if(!this.contentVisible)return;const e=t.width,s=t.height,i=this.ctx;if(this.save(),!Oe){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;ib(h,t),n=this.applyTransferMapsToCanvas(h)}const r=this._scaleImage(n,ki(i));i.imageSmoothingEnabled=rb(It(i),t.interpolate),xd(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;ib(h,t),i=this.applyTransferMapsToCanvas(h)}for(const n of e)s.save(),s.transform(...n.transform),s.scale(1,-1),xd(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===ob?s.clip("evenodd"):s.clip()),this.pendingClip=null),this.current.startNewPathAndClipBox(this.current.clipBox),s.beginPath()}getSinglePixelWidth(){if(!this._cachedGetSinglePixelWidth){const t=It(this.ctx);if(t[1]===0&&t[2]===0)this._cachedGetSinglePixelWidth=1/Math.min(Math.abs(t[0]),Math.abs(t[3]));else{const e=Math.abs(t[0]*t[3]-t[2]*t[1]),s=Math.hypot(t[0],t[2]),i=Math.hypot(t[1],t[3]);this._cachedGetSinglePixelWidth=Math.max(s,i)/e}}return this._cachedGetSinglePixelWidth}getScaleForStroking(){if(this._cachedScaleForStroking[0]===-1){const{lineWidth:t}=this.current,{a:e,b:s,c:i,d:n}=this.ctx.getTransform();let r,o;if(s===0&&i===0){const h=Math.abs(e),c=Math.abs(n);if(h===c)if(t===0)r=o=1/h;else{const u=h*t;r=o=u<1?1/u:1}else if(t===0)r=1/h,o=1/c;else{const u=h*t,d=c*t;r=u<1?1/u:1,o=d<1?1/d:1}}else{const h=Math.abs(e*n-s*i),c=Math.hypot(e,s),u=Math.hypot(i,n);if(t===0)r=u/h,o=c/h;else{const d=t*h;r=u>d?u/d:1,o=c>d?c/d:1}}this._cachedScaleForStroking[0]=r,this._cachedScaleForStroking[1]=o}return this._cachedScaleForStroking}rescaleAndStroke(t){const{ctx:e}=this,{lineWidth:s}=this.current,[i,n]=this.getScaleForStroking();if(e.lineWidth=s||1,i===1&&n===1){e.stroke();return}const r=e.getLineDash();if(t&&e.save(),e.scale(i,n),r.length>0){const o=Math.max(i,n);e.setLineDash(r.map(h=>h/o)),e.lineDashOffset/=o}e.stroke(),t&&e.restore()}isContentVisible(){for(let t=this.markedContentStack.length-1;t>=0;t--)if(!this.markedContentStack[t].visible)return!1;return!0}};ci=new WeakSet,Xp=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)},Up=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}}},Yp=function(t,e,s){const i=new Path2D;return i.addPath(t,new DOMMatrix(s).invertSelf().multiplySelf(e)),i};let Ea=vp;for(const a in ii)Ea.prototype[a]!==void 0&&(Ea.prototype[ii[a]]=Ea.prototype[a]);class hn{static get workerPort(){return l(this,Jl)}static set workerPort(t){if(!(typeof Worker<"u"&&t instanceof Worker)&&t!==null)throw new Error("Invalid `workerPort` type.");v(this,Jl,t)}static get workerSrc(){return l(this,Ql)}static set workerSrc(t){if(typeof t!="string")throw new Error("Invalid `workerSrc` type.");v(this,Ql,t)}}Jl=new WeakMap,Ql=new WeakMap,_(hn,Jl,null),_(hn,Ql,"");class tC{constructor({parsedData:t,rawData:e}){_(this,So);_(this,Zl);v(this,So,t),v(this,Zl,e)}getRaw(){return l(this,Zl)}get(t){return l(this,So).get(t)??null}getAll(){return Fg(l(this,So))}has(t){return l(this,So).has(t)}}So=new WeakMap,Zl=new WeakMap;const ka=Symbol("INTERNAL");class eC{constructor(t,{name:e,intent:s,usage:i,rbGroups:n}){_(this,tc,!1);_(this,ec,!1);_(this,sc,!1);_(this,$a,!0);v(this,tc,!!(t&vs.DISPLAY)),v(this,ec,!!(t&vs.PRINT)),this.name=e,this.intent=s,this.usage=i,this.rbGroups=n}get visible(){if(l(this,sc))return l(this,$a);if(!l(this,$a))return!1;const{print:t,view:e}=this.usage;return l(this,tc)?(e==null?void 0:e.viewState)!=="OFF":l(this,ec)?(t==null?void 0:t.printState)!=="OFF":!0}_setVisible(t,e,s=!1){t!==ka&&Pt("Internal method `_setVisible` called."),v(this,sc,s),v(this,$a,e)}}tc=new WeakMap,ec=new WeakMap,sc=new WeakMap,$a=new WeakMap;class sC{constructor(t,e=vs.DISPLAY){_(this,ic);_(this,ur,null);_(this,At,new Map);_(this,qa,null);_(this,Ka,null);if(this.renderingIntent=e,this.name=null,this.creator=null,t!==null){this.name=t.name,this.creator=t.creator,v(this,Ka,t.order);for(const s of t.groups)l(this,At).set(s.id,new eC(e,s));if(t.baseState==="OFF")for(const s of l(this,At).values())s._setVisible(ka,!1);for(const s of t.on)l(this,At).get(s)._setVisible(ka,!0);for(const s of t.off)l(this,At).get(s)._setVisible(ka,!1);v(this,qa,this.getHash())}}isVisible(t){if(l(this,At).size===0)return!0;if(!t)return fd("Optional content group not defined."),!0;if(t.type==="OCG")return l(this,At).has(t.id)?l(this,At).get(t.id).visible:(ht(`Optional content group not found: ${t.id}`),!0);if(t.type==="OCMD"){if(t.expression)return w(this,ic,$p).call(this,t.expression);if(!t.policy||t.policy==="AnyOn"){for(const e of t.ids){if(!l(this,At).has(e))return ht(`Optional content group not found: ${e}`),!0;if(l(this,At).get(e).visible)return!0}return!1}else if(t.policy==="AllOn"){for(const e of t.ids){if(!l(this,At).has(e))return ht(`Optional content group not found: ${e}`),!0;if(!l(this,At).get(e).visible)return!1}return!0}else if(t.policy==="AnyOff"){for(const e of t.ids){if(!l(this,At).has(e))return ht(`Optional content group not found: ${e}`),!0;if(!l(this,At).get(e).visible)return!0}return!1}else if(t.policy==="AllOff"){for(const e of t.ids){if(!l(this,At).has(e))return ht(`Optional content group not found: ${e}`),!0;if(l(this,At).get(e).visible)return!1}return!0}return ht(`Unknown optional content policy ${t.policy}.`),!0}return ht(`Unknown group type ${t.type}.`),!0}setVisibility(t,e=!0,s=!0){var n;const i=l(this,At).get(t);if(!i){ht(`Optional content group not found: ${t}`);return}if(s&&e&&i.rbGroups.length)for(const r of i.rbGroups)for(const o of r)o!==t&&((n=l(this,At).get(o))==null||n._setVisible(ka,!1,!0));i._setVisible(ka,!!e,!0),v(this,ur,null)}setOCGState({state:t,preserveRB:e}){let s;for(const i of t){switch(i){case"ON":case"OFF":case"Toggle":s=i;continue}const n=l(this,At).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}}v(this,ur,null)}get hasInitialVisibility(){return l(this,qa)===null||this.getHash()===l(this,qa)}getOrder(){return l(this,At).size?l(this,Ka)?l(this,Ka).slice():[...l(this,At).keys()]:null}getGroups(){return l(this,At).size>0?Fg(l(this,At)):null}getGroup(t){return l(this,At).get(t)||null}getHash(){if(l(this,ur)!==null)return l(this,ur);const t=new z0;for(const[e,s]of l(this,At))t.update(`${e}:${s.visible}`);return v(this,ur,t.hexdigest())}}ur=new WeakMap,At=new WeakMap,qa=new WeakMap,Ka=new WeakMap,ic=new WeakSet,$p=function(t){const e=t.length;if(e<2)return!0;const s=t[0];for(let i=1;i<e;i++){const n=t[i];let r;if(Array.isArray(n))r=w(this,ic,$p).call(this,n);else if(l(this,At).has(n))r=l(this,At).get(n).visible;else return ht(`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 iC{constructor(t,{disableRange:e=!1,disableStream:s=!1}){ie(t,'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');const{length:i,initialData:n,progressiveDone:r,contentDispositionFilename:o}=t;if(this._queuedChunks=[],this._progressiveDone=r,this._contentDispositionFilename=o,(n==null?void 0:n.length)>0){const h=n instanceof Uint8Array&&n.byteLength===n.buffer.byteLength?n.buffer:new Uint8Array(n).buffer;this._queuedChunks.push(h)}this._pdfDataRangeTransport=t,this._isStreamingSupported=!s,this._isRangeSupported=!e,this._contentLength=i,this._fullRequestReader=null,this._rangeReaders=[],t.addRangeListener((h,c)=>{this._onReceiveData({begin:h,chunk:c})}),t.addProgressListener((h,c)=>{this._onProgress({loaded:h,total:c})}),t.addProgressiveReadListener(h=>{this._onReceiveData({chunk:h})}),t.addProgressiveDoneListener(()=>{this._onProgressiveDone()}),t.transportReady()}_onReceiveData({begin:t,chunk:e}){const s=e instanceof Uint8Array&&e.byteLength===e.buffer.byteLength?e.buffer:new Uint8Array(e).buffer;if(t===void 0)this._fullRequestReader?this._fullRequestReader._enqueue(s):this._queuedChunks.push(s);else{const i=this._rangeReaders.some(function(n){return n._begin!==t?!1:(n._enqueue(s),!0)});ie(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(){ie(!this._fullRequestReader,"PDFDataTransportStream.getFullReader can only be called once.");const t=this._queuedChunks;return this._queuedChunks=null,new nC(this,t,this._progressiveDone,this._contentDispositionFilename)}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new rC(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 nC{constructor(t,e,s=!1,i=null){this._stream=t,this._done=s||!1,this._filename=Bg(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 rC{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 oC(a){let t=!0,e=s("filename\\*","i").exec(a);if(e){e=e[1];let u=o(e);return u=unescape(u),u=h(u),u=c(u),n(u)}if(e=r(a),e){const u=c(e);return n(u)}if(e=s("filename","i").exec(a),e){e=e[1];let u=o(e);return u=c(u),n(u)}function s(u,d){return new RegExp("(?:^|;)\\s*"+u+'\\s*=\\s*([^";\\s][^;\\s]*|"(?:[^"\\\\]|\\\\"?)+"?)',d)}function i(u,d){if(u){if(!/^[\x00-\xFF]+$/.test(d))return d;try{const f=new TextDecoder(u,{fatal:!0}),g=pd(d);d=f.decode(g),t=!1}catch{}}return d}function n(u){return t&&/[\x80-\xff]/.test(u)&&(u=i("utf-8",u),t&&(u=i("iso-8859-1",u))),u}function r(u){const d=[];let f;const g=s("filename\\*((?!0\\d)\\d+)(\\*?)","ig");for(;(f=g.exec(u))!==null;){let[,m,y,b]=f;if(m=parseInt(m,10),m in d){if(m===0)break;continue}d[m]=[y,b]}const p=[];for(let m=0;m<d.length&&m in d;++m){let[y,b]=d[m];b=o(b),y&&(b=unescape(b),m===0&&(b=h(b))),p.push(b)}return p.join("")}function o(u){if(u.startsWith('"')){const d=u.slice(1).split('\\"');for(let f=0;f<d.length;++f){const g=d[f].indexOf('"');g!==-1&&(d[f]=d[f].slice(0,g),d.length=f+1),d[f]=d[f].replaceAll(/\\(.)/g,"$1")}u=d.join('"')}return u}function h(u){const d=u.indexOf("'");if(d===-1)return u;const f=u.slice(0,d),p=u.slice(d+1).replace(/^[^']*'/,"");return i(f,p)}function c(u){return!u.startsWith("=?")||/[\x00-\x19\x80-\xff]/.test(u)?u:u.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,function(d,f,g,p){if(g==="q"||g==="Q")return p=p.replaceAll("_"," "),p=p.replaceAll(/=([0-9a-fA-F]{2})/g,function(m,y){return String.fromCharCode(parseInt(y,16))}),i(f,p);try{p=atob(p)}catch{}return i(f,p)})}return""}function ab(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 Cd(a){try{return new URL(a).origin}catch{}return null}function hb({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 lb(a){const t=a.get("Content-Disposition");if(t){let e=oC(t);if(e.includes("%"))try{e=decodeURIComponent(e)}catch{}if(Bg(e))return e}return null}function Ad(a,t){return a===404||a===0&&t.startsWith("file:")?new dl('Missing PDF "'+t+'".'):new gd(`Unexpected server response (${a}) while retrieving PDF "${t}".`,a)}function cb(a){return a===200||a===206}function ub(a,t,e){return{method:"GET",headers:a,signal:e.signal,mode:"cors",credentials:t?"include":"same-origin",redirect:"follow"}}function db(a){return a instanceof Uint8Array?a.buffer:a instanceof ArrayBuffer?a:(ht(`getArrayBuffer - unexpected data format: ${a}`),new Uint8Array(a).buffer)}class fb{constructor(t){Q(this,"_responseOrigin",null);this.source=t,this.isHttp=/^https?:/i.test(t.url),this.headers=ab(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 ie(!this._fullRequestReader,"PDFFetchStream.getFullReader can only be called once."),this._fullRequestReader=new aC(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new hC(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 aC{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,ub(s,this._withCredentials,this._abortController)).then(n=>{if(t._responseOrigin=Cd(n.url),!cb(n.status))throw Ad(n.status,i);this._reader=n.body.getReader(),this._headersCapability.resolve();const r=n.headers,{allowRangeRequests:o,suggestedLength:h}=hb({responseHeaders:r,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=o,this._contentLength=h||this._contentLength,this._filename=lb(r),!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new qn("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:db(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}class hC{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,ub(n,this._withCredentials,this._abortController)).then(o=>{const h=Cd(o.url);if(h!==t._responseOrigin)throw new Error(`Expected range response-origin "${h}" to match "${t._responseOrigin}".`);if(!cb(o.status))throw Ad(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:db(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}const Qg=200,Zg=206;function lC(a){const t=a.response;return typeof t!="string"?t:pd(t).buffer}class cC{constructor({url:t,httpHeaders:e,withCredentials:s}){Q(this,"_responseOrigin",null);this.url=t,this.isHttp=/^https?:/i.test(t),this.headers=ab(this.isHttp,e),this.withCredentials=s||!1,this.currXhrId=0,this.pendingRequests=Object.create(null)}request(t){const e=new XMLHttpRequest,s=this.currXhrId++,i=this.pendingRequests[s]={xhr:e};e.open("GET",this.url),e.withCredentials=this.withCredentials;for(const[n,r]of this.headers)e.setRequestHeader(n,r);return this.isHttp&&"begin"in t&&"end"in t?(e.setRequestHeader("Range",`bytes=${t.begin}-${t.end-1}`),i.expectedStatus=Zg):i.expectedStatus=Qg,e.responseType="arraybuffer",ie(t.onError,"Expected `onError` callback to be provided."),e.onerror=()=>{t.onError(e.status)},e.onreadystatechange=this.onStateChange.bind(this,s),e.onprogress=this.onProgress.bind(this,s),i.onHeadersReceived=t.onHeadersReceived,i.onDone=t.onDone,i.onError=t.onError,i.onProgress=t.onProgress,e.send(null),s}onProgress(t,e){var i;const s=this.pendingRequests[t];s&&((i=s.onProgress)==null||i.call(s,e))}onStateChange(t,e){const s=this.pendingRequests[t];if(!s)return;const i=s.xhr;if(i.readyState>=2&&s.onHeadersReceived&&(s.onHeadersReceived(),delete s.onHeadersReceived),i.readyState!==4||!(t in this.pendingRequests))return;if(delete this.pendingRequests[t],i.status===0&&this.isHttp){s.onError(i.status);return}const n=i.status||Qg;if(!(n===Qg&&s.expectedStatus===Zg)&&n!==s.expectedStatus){s.onError(i.status);return}const o=lC(i);if(n===Zg){const h=i.getResponseHeader("Content-Range"),c=/bytes (\d+)-(\d+)\/(\d+)/.exec(h);c?s.onDone({begin:parseInt(c[1],10),chunk:o}):(ht('Missing or invalid "Content-Range" header.'),s.onError(0))}else o?s.onDone({begin:0,chunk:o}):s.onError(i.status)}getRequestXhr(t){return this.pendingRequests[t].xhr}isPendingRequest(t){return t in this.pendingRequests}abortRequest(t){const e=this.pendingRequests[t].xhr;delete this.pendingRequests[t],e.abort()}}class uC{constructor(t){this._source=t,this._manager=new cC(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 ie(!this._fullRequestReader,"PDFNetworkStream.getFullReader can only be called once."),this._fullRequestReader=new dC(this._manager,this._source),this._fullRequestReader}getRangeReader(t,e){const s=new fC(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 dC{constructor(t,e){this._manager=t,this._url=e.url,this._fullRequestId=t.request({onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)}),this._headersCapability=Promise.withResolvers(),this._disableRange=e.disableRange||!1,this._contentLength=e.length,this._rangeChunkSize=e.rangeChunkSize,!this._rangeChunkSize&&!this._disableRange&&(this._disableRange=!0),this._isStreamingSupported=!1,this._isRangeSupported=!1,this._cachedChunks=[],this._requests=[],this._done=!1,this._storedError=void 0,this._filename=null,this.onProgress=null}_onHeadersReceived(){const t=this._fullRequestId,e=this._manager.getRequestXhr(t);this._manager._responseOrigin=Cd(e.responseURL);const s=e.getAllResponseHeaders(),i=new Headers(s?s.trimStart().replace(/[^\S ]+$/,"").split(/[\r\n]+/).map(o=>{const[h,...c]=o.split(": ");return[h,c.join(": ")]}):[]),{allowRangeRequests:n,suggestedLength:r}=hb({responseHeaders:i,isHttp:this._manager.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});n&&(this._isRangeSupported=!0),this._contentLength=r||this._contentLength,this._filename=lb(i),this._isRangeSupported&&this._manager.abortRequest(t),this._headersCapability.resolve()}_onDone(t){if(t&&(this._requests.length>0?this._requests.shift().resolve({value:t.chunk,done:!1}):this._cachedChunks.push(t.chunk)),this._done=!0,!(this._cachedChunks.length>0)){for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}}_onError(t){this._storedError=Ad(t,this._url),this._headersCapability.reject(this._storedError);for(const e of this._requests)e.reject(this._storedError);this._requests.length=0,this._cachedChunks.length=0}_onProgress(t){var e;(e=this.onProgress)==null||e.call(this,{loaded:t.loaded,total:t.lengthComputable?t.total:this._contentLength})}get filename(){return this._filename}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}get contentLength(){return this._contentLength}get headersReady(){return this._headersCapability.promise}async read(){if(await this._headersCapability.promise,this._storedError)throw this._storedError;if(this._cachedChunks.length>0)return{value:this._cachedChunks.shift(),done:!1};if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0,this._headersCapability.reject(t);for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._manager.isPendingRequest(this._fullRequestId)&&this._manager.abortRequest(this._fullRequestId),this._fullRequestReader=null}}class fC{constructor(t,e,s){this._manager=t,this._url=t.url,this._requestId=t.request({begin:e,end:s,onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)}),this._requests=[],this._queuedChunk=null,this._done=!1,this._storedError=void 0,this.onProgress=null,this.onClosed=null}_onHeadersReceived(){var e;const t=Cd((e=this._manager.getRequestXhr(this._requestId))==null?void 0:e.responseURL);t!==this._manager._responseOrigin&&(this._storedError=new Error(`Expected range response-origin "${t}" to match "${this._manager._responseOrigin}".`),this._onError(0))}_close(){var t;(t=this.onClosed)==null||t.call(this,this)}_onDone(t){const e=t.chunk;this._requests.length>0?this._requests.shift().resolve({value:e,done:!1}):this._queuedChunk=e,this._done=!0;for(const s of this._requests)s.resolve({value:void 0,done:!0});this._requests.length=0,this._close()}_onError(t){this._storedError??(this._storedError=Ad(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 gC=/^[a-z][a-z0-9\-+.]+:/i;function pC(a){if(gC.test(a))return new URL(a);const t=process.getBuiltinModule("url");return new URL(t.pathToFileURL(a))}class mC{constructor(t){this.source=t,this.url=pC(t.url),ie(this.url.protocol==="file:","PDFNodeStream only supports file:// URLs."),this._fullRequestReader=null,this._rangeRequestReaders=[]}get _progressiveDataLength(){var t;return((t=this._fullRequestReader)==null?void 0:t._loaded)??0}getFullReader(){return ie(!this._fullRequestReader,"PDFNodeStream.getFullReader can only be called once."),this._fullRequestReader=new vC(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new bC(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 vC{constructor(t){this._url=t.url,this._done=!1,this._storedError=null,this.onProgress=null;const e=t.source;this._contentLength=e.length,this._loaded=0,this._filename=null,this._disableRange=e.disableRange||!1,this._rangeChunkSize=e.rangeChunkSize,!this._rangeChunkSize&&!this._disableRange&&(this._disableRange=!0),this._isStreamingSupported=!e.disableStream,this._isRangeSupported=!e.disableRange,this._readableStream=null,this._readCapability=Promise.withResolvers(),this._headersCapability=Promise.withResolvers();const s=process.getBuiltinModule("fs");s.promises.lstat(this._url).then(i=>{this._contentLength=i.size,this._setReadableStream(s.createReadStream(this._url)),this._headersCapability.resolve()},i=>{i.code==="ENOENT"&&(i=new dl(`Missing PDF "${this._url}".`)),this._storedError=i,this._headersCapability.reject(i)})}get headersReady(){return this._headersCapability.promise}get filename(){return this._filename}get contentLength(){return this._contentLength}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;if(await this._readCapability.promise,this._done)return{value:void 0,done:!0};if(this._storedError)throw this._storedError;const t=this._readableStream.read();return t===null?(this._readCapability=Promise.withResolvers(),this.read()):(this._loaded+=t.length,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded,total:this._contentLength}),{value:new Uint8Array(t).buffer,done:!1})}cancel(t){if(!this._readableStream){this._error(t);return}this._readableStream.destroy(t)}_error(t){this._storedError=t,this._readCapability.resolve()}_setReadableStream(t){this._readableStream=t,t.on("readable",()=>{this._readCapability.resolve()}),t.on("end",()=>{t.destroy(),this._done=!0,this._readCapability.resolve()}),t.on("error",e=>{this._error(e)}),!this._isStreamingSupported&&this._isRangeSupported&&this._error(new qn("streaming is disabled")),this._storedError&&this._readableStream.destroy(this._storedError)}}class bC{constructor(t,e,s){this._url=t.url,this._done=!1,this._storedError=null,this.onProgress=null,this._loaded=0,this._readableStream=null,this._readCapability=Promise.withResolvers();const i=t.source;this._isStreamingSupported=!i.disableStream;const n=process.getBuiltinModule("fs");this._setReadableStream(n.createReadStream(this._url,{start:e,end:s-1}))}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;if(await this._readCapability.promise,this._done)return{value:void 0,done:!0};if(this._storedError)throw this._storedError;const t=this._readableStream.read();return t===null?(this._readCapability=Promise.withResolvers(),this.read()):(this._loaded+=t.length,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded}),{value:new Uint8Array(t).buffer,done:!1})}cancel(t){if(!this._readableStream){this._error(t);return}this._readableStream.destroy(t)}_error(t){this._storedError=t,this._readCapability.resolve()}_setReadableStream(t){this._readableStream=t,t.on("readable",()=>{this._readCapability.resolve()}),t.on("end",()=>{t.destroy(),this._done=!0,this._readCapability.resolve()}),t.on("error",e=>{this._error(e)}),this._storedError&&this._readableStream.destroy(this._storedError)}}const yC=1e5,as=30,_C=.8,ue=class ue{constructor({textContentSource:t,container:e,viewport:s}){_(this,xn);_(this,dr,Promise.withResolvers());_(this,cs,null);_(this,nc,!1);_(this,rc,!!((Rb=globalThis.FontInspector)!=null&&Rb.enabled));_(this,Co,null);_(this,wn,null);_(this,oc,0);_(this,ac,0);_(this,Ao,null);_(this,Ja,null);_(this,Qa,0);_(this,fr,0);_(this,Za,Object.create(null));_(this,hc,[]);_(this,th,null);_(this,To,[]);_(this,lc,new WeakMap);_(this,cc,null);var h;if(t instanceof ReadableStream)v(this,th,t);else if(typeof t=="object")v(this,th,new ReadableStream({start(c){c.enqueue(t),c.close()}}));else throw new Error('No "textContentSource" parameter specified.');v(this,cs,v(this,Ja,e)),v(this,fr,s.scale*(globalThis.devicePixelRatio||1)),v(this,Qa,s.rotation),v(this,wn,{div:null,properties:null,ctx:null});const{pageWidth:i,pageHeight:n,pageX:r,pageY:o}=s.rawDims;v(this,cc,[1,0,0,-1,-r,o+n]),v(this,ac,i),v(this,oc,n),w(h=ue,xs,Oy).call(h),$r(e,s),l(this,dr).promise.finally(()=>{l(ue,eh).delete(this),v(this,wn,null),v(this,Za,null)}).catch(()=>{})}static get fontFamilyMap(){const{isWindows:t,isFirefox:e}=Ue.platform;return ct(this,"fontFamilyMap",new Map([["sans-serif",`${t&&e?"Calibri, ":""}sans-serif`],["monospace",`${t&&e?"Lucida Console, ":""}monospace`]]))}render(){const t=()=>{l(this,Ao).read().then(({value:e,done:s})=>{if(s){l(this,dr).resolve();return}l(this,Co)??v(this,Co,e.lang),Object.assign(l(this,Za),e.styles),w(this,xn,Py).call(this,e.items),t()},l(this,dr).reject)};return v(this,Ao,l(this,th).getReader()),l(ue,eh).add(this),t(),l(this,dr).promise}update({viewport:t,onBefore:e=null}){var n;const s=t.scale*(globalThis.devicePixelRatio||1),i=t.rotation;if(i!==l(this,Qa)&&(e==null||e(),v(this,Qa,i),$r(l(this,Ja),{rotation:i})),s!==l(this,fr)){e==null||e(),v(this,fr,s);const r={div:null,properties:null,ctx:w(n=ue,xs,uf).call(n,l(this,Co))};for(const o of l(this,To))r.properties=l(this,lc).get(o),r.div=o,w(this,xn,qp).call(this,r)}}cancel(){var e;const t=new qn("TextLayer task cancelled.");(e=l(this,Ao))==null||e.cancel(t).catch(()=>{}),v(this,Ao,null),l(this,dr).reject(t)}get textDivs(){return l(this,To)}get textContentItemsStr(){return l(this,hc)}static cleanup(){if(!(l(this,eh).size>0)){l(this,Eo).clear();for(const{canvas:t}of l(this,ko).values())t.remove();l(this,ko).clear()}}};dr=new WeakMap,cs=new WeakMap,nc=new WeakMap,rc=new WeakMap,Co=new WeakMap,wn=new WeakMap,oc=new WeakMap,ac=new WeakMap,Ao=new WeakMap,Ja=new WeakMap,Qa=new WeakMap,fr=new WeakMap,Za=new WeakMap,hc=new WeakMap,th=new WeakMap,To=new WeakMap,lc=new WeakMap,cc=new WeakMap,Eo=new WeakMap,ko=new WeakMap,uc=new WeakMap,gr=new WeakMap,eh=new WeakMap,xn=new WeakSet,Py=function(t){var i,n;if(l(this,nc))return;(n=l(this,wn)).ctx??(n.ctx=w(i=ue,xs,uf).call(i,l(this,Co)));const e=l(this,To),s=l(this,hc);for(const r of t){if(e.length>yC){ht("Ignoring additional textDivs for performance reasons."),v(this,nc,!0);return}if(r.str===void 0){if(r.type==="beginMarkedContentProps"||r.type==="beginMarkedContent"){const o=l(this,cs);v(this,cs,document.createElement("span")),l(this,cs).classList.add("markedContent"),r.id!==null&&l(this,cs).setAttribute("id",`${r.id}`),o.append(l(this,cs))}else r.type==="endMarkedContent"&&v(this,cs,l(this,cs).parentNode);continue}s.push(r.str),w(this,xn,My).call(this,r)}},My=function(t){var m;const e=document.createElement("span"),s={angle:0,canvasWidth:0,hasText:t.str!=="",hasEOL:t.hasEOL,fontSize:0};l(this,To).push(e);const i=q.transform(l(this,cc),t.transform);let n=Math.atan2(i[1],i[0]);const r=l(this,Za)[t.fontName];r.vertical&&(n+=Math.PI/2);let o=l(this,rc)&&r.fontSubstitution||r.fontFamily;o=ue.fontFamilyMap.get(o)||o;const h=Math.hypot(i[2],i[3]),c=h*w(m=ue,xs,Dy).call(m,o,l(this,Co));let u,d;n===0?(u=i[4],d=i[5]-c):(u=i[4]+c*Math.sin(n),d=i[5]-c*Math.cos(n));const f="calc(var(--scale-factor)*",g=e.style;l(this,cs)===l(this,Ja)?(g.left=`${(100*u/l(this,ac)).toFixed(2)}%`,g.top=`${(100*d/l(this,oc)).toFixed(2)}%`):(g.left=`${f}${u.toFixed(2)}px)`,g.top=`${f}${d.toFixed(2)}px)`),g.fontSize=`${f}${(l(ue,gr)*h).toFixed(2)}px)`,g.fontFamily=o,s.fontSize=h,e.setAttribute("role","presentation"),e.textContent=t.str,e.dir=t.dir,l(this,rc)&&(e.dataset.fontName=r.fontSubstitutionLoadedName||t.fontName),n!==0&&(s.angle=n*(180/Math.PI));let p=!1;if(t.str.length>1)p=!0;else if(t.str!==" "&&t.transform[0]!==t.transform[3]){const y=Math.abs(t.transform[0]),b=Math.abs(t.transform[3]);y!==b&&Math.max(y,b)/Math.min(y,b)>1.5&&(p=!0)}if(p&&(s.canvasWidth=r.vertical?t.height:t.width),l(this,lc).set(e,s),l(this,wn).div=e,l(this,wn).properties=s,w(this,xn,qp).call(this,l(this,wn)),s.hasText&&l(this,cs).append(e),s.hasEOL){const y=document.createElement("br");y.setAttribute("role","presentation"),l(this,cs).append(y)}},qp=function(t){var o;const{div:e,properties:s,ctx:i}=t,{style:n}=e;let r="";if(l(ue,gr)>1&&(r=`scale(${1/l(ue,gr)})`),s.canvasWidth!==0&&s.hasText){const{fontFamily:h}=n,{canvasWidth:c,fontSize:u}=s;w(o=ue,xs,Kp).call(o,i,u*l(this,fr),h);const{width:d}=i.measureText(e.textContent);d>0&&(r=`scaleX(${c*l(this,fr)/d}) ${r}`)}s.angle!==0&&(r=`rotate(${s.angle}deg) ${r}`),r.length>0&&(n.transform=r)},xs=new WeakSet,uf=function(t=null){let e=l(this,ko).get(t||(t=""));if(!e){const s=document.createElement("canvas");s.className="hiddenCanvasElement",s.lang=t,document.body.append(s),e=s.getContext("2d",{alpha:!1,willReadFrequently:!0}),l(this,ko).set(t,e),l(this,uc).set(e,{size:0,family:""})}return e},Kp=function(t,e,s){const i=l(this,uc).get(t);e===i.size&&s===i.family||(t.font=`${e}px ${s}`,i.size=e,i.family=s)},Oy=function(){if(l(this,gr)!==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),v(this,gr,t.getBoundingClientRect().height),t.remove()},Dy=function(t,e){const s=l(this,Eo).get(t);if(s)return s;const i=w(this,xs,uf).call(this,e);i.canvas.width=i.canvas.height=as,w(this,xs,Kp).call(this,i,as,t);const n=i.measureText("");let r=n.fontBoundingBoxAscent,o=Math.abs(n.fontBoundingBoxDescent);if(r){const u=r/(r+o);return l(this,Eo).set(t,u),i.canvas.width=i.canvas.height=0,u}i.strokeStyle="red",i.clearRect(0,0,as,as),i.strokeText("g",0,0);let h=i.getImageData(0,0,as,as).data;o=0;for(let u=h.length-1-3;u>=0;u-=4)if(h[u]>0){o=Math.ceil(u/4/as);break}i.clearRect(0,0,as,as),i.strokeText("A",0,as),h=i.getImageData(0,0,as,as).data,r=0;for(let u=0,d=h.length;u<d;u+=4)if(h[u]>0){r=as-Math.floor(u/4/as);break}i.canvas.width=i.canvas.height=0;const c=r?r/(r+o):_C;return l(this,Eo).set(t,c),c},_(ue,xs),_(ue,Eo,new Map),_(ue,ko,new Map),_(ue,uc,new WeakMap),_(ue,gr,null),_(ue,eh,new Set);let bl=ue;class yl{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(yl.shouldBuildText(o))(h=n==null?void 0:n.attributes)!=null&&h.textContent?r=n.attributes.textContent:n.value&&(r=n.value);else return;if(r!==null&&e.push({str:r}),!!n.children)for(const c of n.children)i(c)}return i(t),s}static shouldBuildText(t){return!(t==="textarea"||t==="input"||t==="option"||t==="select")}}const wC=65536,xC=100,SC=5e3,CC=Oe?NS:LS,AC=Oe?BS:U0,TC=Oe?jS:IS,EC=Oe?HS:q0;function kC(a={}){typeof a=="string"||a instanceof URL?a={url:a}:(a instanceof ArrayBuffer||ArrayBuffer.isView(a))&&(a={data:a});const t=new tp,{docId:e}=t,s=a.url?PC(a.url):null,i=a.data?MC(a.data):null,n=a.httpHeaders||null,r=a.withCredentials===!0,o=a.password??null,h=a.range instanceof pb?a.range:null,c=Number.isInteger(a.rangeChunkSize)&&a.rangeChunkSize>0?a.rangeChunkSize:wC;let u=a.worker instanceof Pa?a.worker:null;const d=a.verbosity,f=typeof a.docBaseUrl=="string"&&!vd(a.docBaseUrl)?a.docBaseUrl:null,g=typeof a.cMapUrl=="string"?a.cMapUrl:null,p=a.cMapPacked!==!1,m=a.CMapReaderFactory||AC,y=typeof a.standardFontDataUrl=="string"?a.standardFontDataUrl:null,b=a.StandardFontDataFactory||EC,x=a.stopAtErrors!==!0,C=Number.isInteger(a.maxImageSize)&&a.maxImageSize>-1?a.maxImageSize:-1,S=a.isEvalSupported!==!1,T=typeof a.isOffscreenCanvasSupported=="boolean"?a.isOffscreenCanvasSupported:!Oe,P=typeof a.isImageDecoderSupported=="boolean"?a.isImageDecoderSupported:!Oe&&(Ue.platform.isFirefox||!globalThis.chrome),M=Number.isInteger(a.canvasMaxAreaInBytes)?a.canvasMaxAreaInBytes:-1,D=typeof a.disableFontFace=="boolean"?a.disableFontFace:Oe,R=a.fontExtraProperties===!0,V=a.enableXfa===!0,H=a.ownerDocument||globalThis.document,F=a.disableRange===!0,I=a.disableStream===!0,j=a.disableAutoFetch===!0,K=a.pdfBug===!0,L=a.CanvasFactory||CC,z=a.FilterFactory||TC,Z=a.enableHWA===!0,Dt=h?h.length:a.length??NaN,Bt=typeof a.useSystemFonts=="boolean"?a.useSystemFonts:!Oe&&!D,Xt=typeof a.useWorkerFetch=="boolean"?a.useWorkerFetch:m===U0&&b===q0&&g&&y&&gl(g,document.baseURI)&&gl(y,document.baseURI),Ft=null;fS(d);const _t={canvasFactory:new L({ownerDocument:H,enableHWA:Z}),filterFactory:new z({docId:e,ownerDocument:H}),cMapReaderFactory:Xt?null:new m({baseUrl:g,isCompressed:p}),standardFontDataFactory:Xt?null:new b({baseUrl:y})};if(!u){const it={verbosity:d,port:hn.workerPort};u=it.port?Pa.fromPort(it):new Pa(it),t._worker=u}const oe={docId:e,apiVersion:"4.10.38",data:i,password:o,disableAutoFetch:j,rangeChunkSize:c,length:Dt,docBaseUrl:f,enableXfa:V,evaluatorOptions:{maxImageSize:C,disableFontFace:D,ignoreErrors:x,isEvalSupported:S,isOffscreenCanvasSupported:T,isImageDecoderSupported:P,canvasMaxAreaInBytes:M,fontExtraProperties:R,useSystemFonts:Bt,cMapUrl:Xt?g:null,standardFontDataUrl:Xt?y:null}},Ze={disableFontFace:D,fontExtraProperties:R,ownerDocument:H,pdfBug:K,styleElement:Ft,loadingParams:{disableAutoFetch:j,enableXfa:V}};return u.promise.then(function(){if(t.destroyed)throw new Error("Loading aborted");if(u.destroyed)throw new Error("Worker was destroyed");const it=u.messageHandler.sendWithPromise("GetDocRequest",oe,i?[i.buffer]:null);let nt;if(h)nt=new iC(h,{disableRange:F,disableStream:I});else if(!i){if(!s)throw new Error("getDocument - no `url` parameter provided.");let Zt;if(Oe)if(gl(s)){if(typeof fetch>"u"||typeof Response>"u"||!("body"in Response.prototype))throw new Error("getDocument - the Fetch API was disabled in Node.js, see `--no-experimental-fetch`.");Zt=fb}else Zt=mC;else Zt=gl(s)?fb:uC;nt=new Zt({url:s,length:Dt,httpHeaders:n,withCredentials:r,rangeChunkSize:c,disableRange:F,disableStream:I})}return it.then(Zt=>{if(t.destroyed)throw new Error("Loading aborted");if(u.destroyed)throw new Error("Worker was destroyed");const Ys=new ml(e,Zt,u.port),Te=new FC(Ys,t,nt,Ze,_t);t._transport=Te,Ys.send("Ready",null)})}).catch(t._capability.reject),t}function PC(a){if(a instanceof URL)return a.href;try{return new URL(a,window.location).href}catch{if(Oe&&typeof a=="string")return a}throw new Error("Invalid PDF url data: either string or URL-object is expected in the url property.")}function MC(a){if(Oe&&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 pd(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 gb(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 Hd=class Hd{constructor(){this._capability=Promise.withResolvers(),this._transport=null,this._worker=null,this.docId=`d${es(Hd,Bd)._++}`,this.destroyed=!1,this.onPassword=null,this.onProgress=null}get promise(){return this._capability.promise}async destroy(){var t,e,s,i;this.destroyed=!0;try{(t=this._worker)!=null&&t.port&&(this._worker._pendingDestroy=!0),await((e=this._transport)==null?void 0:e.destroy())}catch(n){throw(s=this._worker)!=null&&s.port&&delete this._worker._pendingDestroy,n}this._transport=null,(i=this._worker)==null||i.destroy(),this._worker=null}};Bd=new WeakMap,_(Hd,Bd,0);let tp=Hd;class pb{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){Pt("Abstract method PDFDataRangeTransport.requestDataRange")}abort(){}}class OC{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 ct(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 DC{constructor(t,e,s,i=!1){_(this,zs);_(this,pr,null);_(this,Sn,!1);this._pageIndex=t,this._pageInfo=e,this._transport=s,this._stats=i?new B0:null,this._pdfBug=i,this.commonObjs=s.commonObjs,this.objs=new mb,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 fl({viewBox:this.view,userUnit:this.userUnit,scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}getAnnotations({intent:t="display"}={}){const{renderingIntent:e}=this._transport.getRenderingIntent(t);return this._transport.getAnnotations(this._pageIndex,e)}getJSActions(){return this._transport.getPageJSActions(this._pageIndex)}get filterFactory(){return this._transport.filterFactory}get isPureXfa(){return ct(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=Yn.ENABLE,transform:n=null,background:r=null,optionalContentConfigPromise:o=null,annotationCanvasMap:h=null,pageColors:c=null,printAnnotationStorage:u=null,isEditing:d=!1}){var S,T;(S=this._stats)==null||S.time("Overall");const f=this._transport.getRenderingIntent(s,i,u,d),{renderingIntent:g,cacheKey:p}=f;v(this,Sn,!1),w(this,zs,df).call(this),o||(o=this._transport.getOptionalContentConfig(g));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 y=!!(g&vs.PRINT);m.displayReadyCapability||(m.displayReadyCapability=Promise.withResolvers(),m.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(T=this._stats)==null||T.time("Page Request"),this._pumpOperatorList(f));const b=P=>{var M;m.renderTasks.delete(x),(this._maybeCleanupAfterRender||y)&&v(this,Sn,!0),w(this,zs,Vh).call(this,!y),P?(x.capability.reject(P),this._abortOperatorList({intentState:m,reason:P instanceof Error?P:new Error(P)})):x.capability.resolve(),this._stats&&(this._stats.timeEnd("Rendering"),this._stats.timeEnd("Overall"),(M=globalThis.Stats)!=null&&M.enabled&&globalThis.Stats.add(this.pageNumber,this._stats))},x=new ep({callback:b,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:!y,pdfBug:this._pdfBug,pageColors:c});(m.renderTasks||(m.renderTasks=new Set)).add(x);const C=x.task;return Promise.all([m.displayReadyCapability.promise,o]).then(([P,M])=>{var D;if(this.destroyed){b();return}if((D=this._stats)==null||D.time("Rendering"),!(M.renderingIntent&g))throw new Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");x.initializeGraphics({transparency:P,optionalContentConfig:M}),x.operatorListChanged()}).catch(b),C}getOperatorList({intent:t="display",annotationMode:e=Yn.ENABLE,printAnnotationStorage:s=null,isEditing:i=!1}={}){var c;function n(){o.operatorList.lastChunk&&(o.opListReadCapability.resolve(o.operatorList),o.renderTasks.delete(h))}const r=this._transport.getRenderingIntent(t,e,s,i,!0);let o=this._intentStates.get(r.cacheKey);o||(o=Object.create(null),this._intentStates.set(r.cacheKey,o));let h;return o.opListReadCapability||(h=Object.create(null),h.operatorListChanged=n,o.opListReadCapability=Promise.withResolvers(),(o.renderTasks||(o.renderTasks=new Set)).add(h),o.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(c=this._stats)==null||c.time("Page Request"),this._pumpOperatorList(r)),o.opListReadCapability.promise}streamTextContent({includeMarkedContent:t=!1,disableNormalization:e=!1}={}){return this._transport.messageHandler.sendWithStream("GetTextContent",{pageIndex:this._pageIndex,includeMarkedContent:t===!0,disableNormalization:e===!0},{highWaterMark:100,size(i){return i.items.length}})}getTextContent(t={}){if(this._transport._htmlForXfa)return this.getXfa().then(s=>yl.textContent(s));const e=this.streamTextContent(t);return new Promise(function(s,i){function n(){r.read().then(function({value:h,done:c}){if(c){s(o);return}o.lang??(o.lang=h.lang),Object.assign(o.styles,h.styles),o.items.push(...h.items),n()},i)}const r=e.getReader(),o={items:[],styles:Object.create(null),lang:null};n()})}getStructTree(){return this._transport.getStructTree(this._pageIndex)}_destroy(){this.destroyed=!0;const t=[];for(const e of this._intentStates.values())if(this._abortOperatorList({intentState:e,reason:new Error("Page was destroyed."),force:!0}),!e.opListReadCapability)for(const s of e.renderTasks)t.push(s.completed),s.cancel();return this.objs.clear(),v(this,Sn,!1),w(this,zs,df).call(this),Promise.all(t)}cleanup(t=!1){v(this,Sn,!0);const e=w(this,zs,Vh).call(this,!1);return t&&e&&this._stats&&(this._stats=new B0),e}_startRenderPage(t,e){var i,n;const s=this._intentStates.get(e);s&&((i=this._stats)==null||i.timeEnd("Page Request"),(n=s.displayReadyCapability)==null||n.resolve(t))}_renderPageChunk(t,e){for(let s=0,i=t.length;s<i;s++)e.operatorList.fnArray.push(t.fnArray[s]),e.operatorList.argsArray.push(t.argsArray[s]);e.operatorList.lastChunk=t.lastChunk,e.operatorList.separateAnnots=t.separateAnnots;for(const s of e.renderTasks)s.operatorListChanged();t.lastChunk&&w(this,zs,Vh).call(this,!0)}_pumpOperatorList({renderingIntent:t,cacheKey:e,annotationStorageSerializable:s,modifiedIds:i}){const{map:n,transfer:r}=s,h=this._transport.messageHandler.sendWithStream("GetOperatorList",{pageIndex:this._pageIndex,intent:t,cacheKey:e,annotationStorage:n,modifiedIds:i},r).getReader(),c=this._intentStates.get(e);c.streamReader=h;const u=()=>{h.read().then(({value:d,done:f})=>{if(f){c.streamReader=null;return}this._transport.destroyed||(this._renderPageChunk(d,c),u())},d=>{if(c.streamReader=null,!this._transport.destroyed){if(c.operatorList){c.operatorList.lastChunk=!0;for(const f of c.renderTasks)f.operatorListChanged();w(this,zs,Vh).call(this,!0)}if(c.displayReadyCapability)c.displayReadyCapability.reject(d);else if(c.opListReadCapability)c.opListReadCapability.reject(d);else throw d}})};u()}_abortOperatorList({intentState:t,reason:e,force:s=!1}){if(t.streamReader){if(t.streamReaderCancelTimeout&&(clearTimeout(t.streamReaderCancelTimeout),t.streamReaderCancelTimeout=null),!s){if(t.renderTasks.size>0)return;if(e instanceof Ng){let i=xC;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 qn(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}}pr=new WeakMap,Sn=new WeakMap,zs=new WeakSet,Vh=function(t=!1){if(w(this,zs,df).call(this),!l(this,Sn)||this.destroyed)return!1;if(t)return v(this,pr,setTimeout(()=>{v(this,pr,null),w(this,zs,Vh).call(this,!1)},SC)),!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(),v(this,Sn,!1),!0},df=function(){l(this,pr)&&(clearTimeout(l(this,pr)),v(this,pr,null))};class RC{constructor(){_(this,Cn,new Map);_(this,zd,Promise.resolve())}postMessage(t,e){const s={data:structuredClone(t,e?{transfer:e}:null)};l(this,zd).then(()=>{for(const[i]of l(this,Cn))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){ht("LoopbackPort - cannot use an `aborted` signal.");return}const r=()=>this.removeEventListener(t,e);i=()=>n.removeEventListener("abort",r),n.addEventListener("abort",r)}l(this,Cn).set(e,i)}removeEventListener(t,e){const s=l(this,Cn).get(e);s==null||s(),l(this,Cn).delete(e)}terminate(){for(const[,t]of l(this,Cn))t==null||t();l(this,Cn).clear()}}Cn=new WeakMap,zd=new WeakMap;const jt=class jt{constructor({name:t=null,port:e=null,verbosity:s=gS()}={}){_(this,sh);var i;if(this.name=t,this.destroyed=!1,this.verbosity=s,this._readyCapability=Promise.withResolvers(),this._port=null,this._webWorker=null,this._messageHandler=null,e){if((i=l(jt,Mo))!=null&&i.has(e))throw new Error("Cannot use more than one PDFWorker per port.");(l(jt,Mo)||v(jt,Mo,new WeakMap)).set(e,this),this._initializeFromPort(e);return}this._initialize()}get promise(){return this._readyCapability.promise}get port(){return this._port}get messageHandler(){return this._messageHandler}_initializeFromPort(t){this._port=t,this._messageHandler=new ml("main","worker",t),this._messageHandler.on("ready",function(){}),w(this,sh,ff).call(this)}_initialize(){if(l(jt,Po)||l(jt,ih,gf)){this._setupFakeWorker();return}let{workerSrc:t}=jt;try{jt._isSameOrigin(window.location.href,t)||(t=jt._createCDNWrapper(new URL(t,window.location).href));const e=new Worker(t,{type:"module"}),s=new ml("main","worker",e),i=()=>{n.abort(),s.destroy(),e.terminate(),this.destroyed?this._readyCapability.reject(new Error("Worker was destroyed")):this._setupFakeWorker()},n=new AbortController;e.addEventListener("error",()=>{this._webWorker||i()},{signal:n.signal}),s.on("test",o=>{if(n.abort(),this.destroyed||!o){i();return}this._messageHandler=s,this._port=e,this._webWorker=e,w(this,sh,ff).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{fd("The worker has been disabled.")}this._setupFakeWorker()}_setupFakeWorker(){l(jt,Po)||(ht("Setting up fake worker."),v(jt,Po,!0)),jt._setupFakeWorkerGlobal.then(t=>{if(this.destroyed){this._readyCapability.reject(new Error("Worker was destroyed"));return}const e=new RC;this._port=e;const s=`fake${es(jt,Vd)._++}`,i=new ml(s+"_worker",s,e);t.setup(i,e),this._messageHandler=new ml(s,s+"_worker",e),w(this,sh,ff).call(this)}).catch(t=>{this._readyCapability.reject(new Error(`Setting up fake worker failed: "${t.message}".`))})}destroy(){var t,e,s;this.destroyed=!0,(t=this._webWorker)==null||t.terminate(),this._webWorker=null,(e=l(jt,Mo))==null||e.delete(this._port),this._port=null,(s=this._messageHandler)==null||s.destroy(),this._messageHandler=null}static fromPort(t){var s;if(!(t!=null&&t.port))throw new Error("PDFWorker.fromPort - invalid method signature.");const e=(s=l(this,Mo))==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 jt(t)}static get workerSrc(){if(hn.workerSrc)return hn.workerSrc;throw new Error('No "GlobalWorkerOptions.workerSrc" specified.')}static get _setupFakeWorkerGlobal(){return ct(this,"_setupFakeWorkerGlobal",(async()=>l(this,ih,gf)?l(this,ih,gf):(await import(this.workerSrc)).WorkerMessageHandler)())}};Vd=new WeakMap,Po=new WeakMap,Mo=new WeakMap,sh=new WeakSet,ff=function(){this._readyCapability.resolve(),this._messageHandler.send("configure",{verbosity:this.verbosity})},ih=new WeakSet,gf=function(){var t;try{return((t=globalThis.pdfjsWorker)==null?void 0:t.WorkerMessageHandler)||null}catch{return null}},_(jt,ih),_(jt,Vd,0),_(jt,Po,!1),_(jt,Mo),Oe&&(v(jt,Po,!0),hn.workerSrc||(hn.workerSrc="./pdf.worker.mjs")),jt._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},jt._createCDNWrapper=t=>{const e=`await import("${t}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))};let Pa=jt;class FC{constructor(t,e,s,i,n){_(this,Oo);_(this,An,new Map);_(this,Bi,new Map);_(this,nh,new Map);_(this,rh,new Map);_(this,Tn,null);this.messageHandler=t,this.loadingTask=e,this.commonObjs=new mb,this.fontLoader=new RS({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 ct(this,"annotationStorage",new Yg)}getRenderingIntent(t,e=Yn.ENABLE,s=null,i=!1,n=!1){let r=vs.DISPLAY,o=Ug;switch(t){case"any":r=vs.ANY;break;case"display":break;case"print":r=vs.PRINT;break;default:ht(`getRenderingIntent - invalid intent: ${t}`)}const h=r&vs.PRINT&&s instanceof V0?s:this.annotationStorage;switch(e){case Yn.DISABLE:r+=vs.ANNOTATIONS_DISABLE;break;case Yn.ENABLE:break;case Yn.ENABLE_FORMS:r+=vs.ANNOTATIONS_FORMS;break;case Yn.ENABLE_STORAGE:r+=vs.ANNOTATIONS_STORAGE,o=h.serializable;break;default:ht(`getRenderingIntent - invalid annotationMode: ${e}`)}i&&(r+=vs.IS_EDITING),n&&(r+=vs.OPLIST);const{ids:c,hash:u}=h.modifiedIds,d=[r,o.hash,u];return{renderingIntent:r,cacheKey:d.join("_"),annotationStorageSerializable:o,modifiedIds:c}}destroy(){var s;if(this.destroyCapability)return this.destroyCapability.promise;this.destroyed=!0,this.destroyCapability=Promise.withResolvers(),(s=l(this,Tn))==null||s.reject(new Error("Worker was destroyed during onPassword callback"));const t=[];for(const i of l(this,Bi).values())t.push(i._destroy());l(this,Bi).clear(),l(this,nh).clear(),l(this,rh).clear(),this.hasOwnProperty("annotationStorage")&&this.annotationStorage.resetModified();const e=this.messageHandler.sendWithPromise("Terminate",null);return t.push(e),Promise.all(t).then(()=>{var i,n;this.commonObjs.clear(),this.fontLoader.clear(),l(this,An).clear(),this.filterFactory.destroy(),bl.cleanup(),(i=this._networkStream)==null||i.cancelAllRequests(new qn("Worker was terminated.")),(n=this.messageHandler)==null||n.destroy(),this.messageHandler=null,this.destroyCapability.resolve()},this.destroyCapability.reject),this.destroyCapability.promise}setupMessageHandler(){const{messageHandler:t,loadingTask:e}=this;t.on("GetReader",(s,i)=>{ie(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}ie(n instanceof ArrayBuffer,"GetReader - expected an ArrayBuffer."),i.enqueue(new Uint8Array(n),1,[n])}).catch(n=>{i.error(n)})},i.onCancel=n=>{this._fullReader.cancel(n),i.ready.catch(r=>{if(!this.destroyed)throw r})}}),t.on("ReaderHeadersReady",async s=>{var o;await this._fullReader.headersReady;const{isStreamingSupported:i,isRangeSupported:n,contentLength:r}=this._fullReader;return(!i||!n)&&(this._lastProgress&&((o=e.onProgress)==null||o.call(e,this._lastProgress)),this._fullReader.onProgress=h=>{var c;(c=e.onProgress)==null||c.call(e,{loaded:h.loaded,total:h.total})}),{isStreamingSupported:i,isRangeSupported:n,contentLength:r}}),t.on("GetRangeReader",(s,i)=>{ie(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}ie(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 OC(s,this))}),t.on("DocException",s=>{e._capability.reject(rs(s))}),t.on("PasswordRequest",s=>{v(this,Tn,Promise.withResolvers());try{if(!e.onPassword)throw rs(s);const i=n=>{n instanceof Error?l(this,Tn).reject(n):l(this,Tn).resolve({password:n})};e.onPassword(i,s.code)}catch(i){l(this,Tn).reject(i)}return l(this,Tn).promise}),t.on("DataLoaded",s=>{var i;(i=e.onProgress)==null||i.call(e,{loaded:s.length,total:s.length}),this.downloadInfoCapability.resolve(s)}),t.on("StartRenderPage",s=>{if(this.destroyed)return;l(this,Bi).get(s.pageIndex)._startRenderPage(s.transparency,s.cacheKey)}),t.on("commonobj",([s,i,n])=>{var r;if(this.destroyed||this.commonObjs.has(s))return null;switch(i){case"Font":const{disableFontFace:o,fontExtraProperties:h,pdfBug:c}=this._params;if("error"in n){const g=n.error;ht(`Error during font loading: ${g}`),this.commonObjs.resolve(s,g);break}const u=c&&((r=globalThis.FontInspector)!=null&&r.enabled)?(g,p)=>globalThis.FontInspector.fontAdded(g,p):null,d=new FS(n,{disableFontFace:o,fontExtraProperties:h,inspectFont:u});this.fontLoader.bind(d).catch(()=>t.sendWithPromise("FontFallback",{id:s})).finally(()=>{!h&&d.data&&(d.data=null),this.commonObjs.resolve(s,d)});break;case"CopyLocalImage":const{imageRef:f}=n;ie(f,"The imageRef must be defined.");for(const g of l(this,Bi).values())for(const[,p]of g.objs)if((p==null?void 0:p.ref)===f)return p.dataLen?(this.commonObjs.resolve(s,structuredClone(p)),p.dataLen):null;break;case"FontPath":case"Image":case"Pattern":this.commonObjs.resolve(s,n);break;default:throw new Error(`Got unknown common object type ${i}`)}return null}),t.on("obj",([s,i,n,r])=>{var h;if(this.destroyed)return;const o=l(this,Bi).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)>lS&&(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&&ht("saveDocument called while `annotationStorage` is empty, please use the getData-method instead.");const{map:t,transfer:e}=this.annotationStorage.serializable;return this.messageHandler.sendWithPromise("SaveDocument",{isPureXfa:!!this._htmlForXfa,numPages:this._numPages,annotationStorage:t,filename:((s=this._fullReader)==null?void 0:s.filename)??null},e).finally(()=>{this.annotationStorage.resetModified()})}getPage(t){if(!Number.isInteger(t)||t<=0||t>this._numPages)return Promise.reject(new Error("Invalid page request."));const e=t-1,s=l(this,nh).get(e);if(s)return s;const i=this.messageHandler.sendWithPromise("GetPage",{pageIndex:e}).then(n=>{if(this.destroyed)throw new Error("Transport destroyed");n.refStr&&l(this,rh).set(n.refStr,t);const r=new DC(e,n,this,this._params.pdfBug);return l(this,Bi).set(e,r),r});return l(this,nh).set(e,i),i}getPageIndex(t){return gb(t)?this.messageHandler.sendWithPromise("GetPageIndex",{num:t.num,gen:t.gen}):Promise.reject(new Error("Invalid pageIndex request."))}getAnnotations(t,e){return this.messageHandler.sendWithPromise("GetAnnotations",{pageIndex:t,intent:e})}getFieldObjects(){return w(this,Oo,iu).call(this,"GetFieldObjects")}hasJSActions(){return w(this,Oo,iu).call(this,"HasJSActions")}getCalculationOrderIds(){return this.messageHandler.sendWithPromise("GetCalculationOrderIds",null)}getDestinations(){return this.messageHandler.sendWithPromise("GetDestinations",null)}getDestination(t){return typeof t!="string"?Promise.reject(new Error("Invalid destination request.")):this.messageHandler.sendWithPromise("GetDestination",{id:t})}getPageLabels(){return this.messageHandler.sendWithPromise("GetPageLabels",null)}getPageLayout(){return this.messageHandler.sendWithPromise("GetPageLayout",null)}getPageMode(){return this.messageHandler.sendWithPromise("GetPageMode",null)}getViewerPreferences(){return this.messageHandler.sendWithPromise("GetViewerPreferences",null)}getOpenAction(){return this.messageHandler.sendWithPromise("GetOpenAction",null)}getAttachments(){return this.messageHandler.sendWithPromise("GetAttachments",null)}getDocJSActions(){return w(this,Oo,iu).call(this,"GetDocJSActions")}getPageJSActions(t){return this.messageHandler.sendWithPromise("GetPageJSActions",{pageIndex:t})}getStructTree(t){return this.messageHandler.sendWithPromise("GetStructTree",{pageIndex:t})}getOutline(){return this.messageHandler.sendWithPromise("GetOutline",null)}getOptionalContentConfig(t){return w(this,Oo,iu).call(this,"GetOptionalContentConfig").then(e=>new sC(e,t))}getPermissions(){return this.messageHandler.sendWithPromise("GetPermissions",null)}getMetadata(){const t="GetMetadata",e=l(this,An).get(t);if(e)return e;const s=this.messageHandler.sendWithPromise(t,null).then(i=>{var n,r;return{info:i[0],metadata:i[1]?new tC(i[1]):null,contentDispositionFilename:((n=this._fullReader)==null?void 0:n.filename)??null,contentLength:((r=this._fullReader)==null?void 0:r.contentLength)??null}});return l(this,An).set(t,s),s}getMarkInfo(){return this.messageHandler.sendWithPromise("GetMarkInfo",null)}async startCleanup(t=!1){if(!this.destroyed){await this.messageHandler.sendWithPromise("Cleanup",null);for(const e of l(this,Bi).values())if(!e.cleanup())throw new Error(`startCleanup: Page ${e.pageNumber} is currently rendering.`);this.commonObjs.clear(),t||this.fontLoader.clear(),l(this,An).clear(),this.filterFactory.destroy(!0),bl.cleanup()}}cachedPageNumber(t){if(!gb(t))return null;const e=t.gen===0?`${t.num}R`:`${t.num}R${t.gen}`;return l(this,rh).get(e)??null}}An=new WeakMap,Bi=new WeakMap,nh=new WeakMap,rh=new WeakMap,Tn=new WeakMap,Oo=new WeakSet,iu=function(t,e=null){const s=l(this,An).get(t);if(s)return s;const i=this.messageHandler.sendWithPromise(t,e);return l(this,An).set(t,i),i};const _l=Symbol("INITIAL_DATA");class mb{constructor(){_(this,dc);_(this,Ss,Object.create(null))}get(t,e=null){if(e){const i=w(this,dc,Jp).call(this,t);return i.promise.then(()=>e(i.data)),null}const s=l(this,Ss)[t];if(!s||s.data===_l)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return s.data}has(t){const e=l(this,Ss)[t];return!!e&&e.data!==_l}delete(t){const e=l(this,Ss)[t];return!e||e.data===_l?!1:(delete l(this,Ss)[t],!0)}resolve(t,e=null){const s=w(this,dc,Jp).call(this,t);s.data=e,s.resolve()}clear(){var t;for(const e in l(this,Ss)){const{data:s}=l(this,Ss)[e];(t=s==null?void 0:s.bitmap)==null||t.close()}v(this,Ss,Object.create(null))}*[Symbol.iterator](){for(const t in l(this,Ss)){const{data:e}=l(this,Ss)[t];e!==_l&&(yield[t,e])}}}Ss=new WeakMap,dc=new WeakSet,Jp=function(t){var e;return(e=l(this,Ss))[t]||(e[t]={...Promise.withResolvers(),data:_l})};class LC{constructor(t){_(this,mr,null);v(this,mr,t),this.onContinue=null}get promise(){return l(this,mr).capability.promise}cancel(t=0){l(this,mr).cancel(null,t)}get separateAnnots(){const{separateAnnots:t}=l(this,mr).operatorList;if(!t)return!1;const{annotationCanvasMap:e}=l(this,mr);return t.form||t.canvas&&(e==null?void 0:e.size)>0}}mr=new WeakMap;const Ro=class Ro{constructor({callback:t,params:e,objs:s,commonObjs:i,annotationCanvasMap:n,operatorList:r,pageIndex:o,canvasFactory:h,filterFactory:c,useRequestAnimationFrame:u=!1,pdfBug:d=!1,pageColors:f=null}){_(this,vr,null);this.callback=t,this.params=e,this.objs=s,this.commonObjs=i,this.annotationCanvasMap=n,this.operatorListIdx=null,this.operatorList=r,this._pageIndex=o,this.canvasFactory=h,this.filterFactory=c,this._pdfBug=d,this.pageColors=f,this.running=!1,this.graphicsReadyCallback=null,this.graphicsReady=!1,this._useRequestAnimationFrame=u===!0&&typeof window<"u",this.cancelled=!1,this.capability=Promise.withResolvers(),this.task=new LC(this),this._cancelBound=this.cancel.bind(this),this._continueBound=this._continue.bind(this),this._scheduleNextBound=this._scheduleNext.bind(this),this._nextBound=this._next.bind(this),this._canvas=e.canvasContext.canvas}get completed(){return this.capability.promise.catch(function(){})}initializeGraphics({transparency:t=!1,optionalContentConfig:e}){var o,h;if(this.cancelled)return;if(this._canvas){if(l(Ro,Do).has(this._canvas))throw new Error("Cannot use the same canvas during multiple render() operations. Use different canvas or ensure previous operations were cancelled or completed.");l(Ro,Do).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 Ea(s,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:e},this.annotationCanvasMap,this.pageColors),this.gfx.beginDrawing({transform:n,viewport:i,transparency:t,background:r}),this.operatorListIdx=0,this.graphicsReady=!0,(h=this.graphicsReadyCallback)==null||h.call(this)}cancel(t=null,e=0){var s;this.running=!1,this.cancelled=!0,(s=this.gfx)==null||s.endDrawing(),l(this,vr)&&(window.cancelAnimationFrame(l(this,vr)),v(this,vr,null)),l(Ro,Do).delete(this._canvas),this.callback(t||new Ng(`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?v(this,vr,window.requestAnimationFrame(()=>{v(this,vr,null),this._nextBound().catch(this._cancelBound)})):Promise.resolve().then(this._nextBound).catch(this._cancelBound)}async _next(){this.cancelled||(this.operatorListIdx=this.gfx.executeOperatorList(this.operatorList,this.operatorListIdx,this._continueBound,this.stepper),this.operatorListIdx===this.operatorList.argsArray.length&&(this.running=!1,this.operatorList.lastChunk&&(this.gfx.endDrawing(),l(Ro,Do).delete(this._canvas),this.callback())))}};vr=new WeakMap,Do=new WeakMap,_(Ro,Do,new WeakSet);let ep=Ro;const IC="4.10.38",jC="f9bea397f";function vb(a){return Math.floor(Math.max(0,Math.min(1,a))*255).toString(16).padStart(2,"0")}function wl(a){return Math.max(0,Math.min(255,255*a))}class bb{static CMYK_G([t,e,s,i]){return["G",1-Math.min(1,.3*t+.59*s+.11*e+i)]}static G_CMYK([t]){return["CMYK",0,0,0,1-t]}static G_RGB([t]){return["RGB",t,t,t]}static G_rgb([t]){return t=wl(t),[t,t,t]}static G_HTML([t]){const e=vb(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(wl)}static RGB_HTML(t){return`#${t.map(vb).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[wl(1-Math.min(1,t+i)),wl(1-Math.min(1,s+i)),wl(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 NC{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){Pt("Abstract method `_createSVG` called.")}}class sp extends NC{_createSVG(t){return document.createElementNS(an,t)}}class yb{static setupStorage(t,e,s,i,n){const r=i.getValue(e,{value:null});switch(s.name){case"textarea":if(r.value!==null&&(t.textContent=r.value),n==="print")break;t.addEventListener("input",o=>{i.setValue(e,{value:o.target.value})});break;case"input":if(s.attributes.type==="radio"||s.attributes.type==="checkbox"){if(r.value===s.attributes.xfaOn?t.setAttribute("checked",!0):r.value===s.attributes.xfaOff&&t.removeAttribute("checked"),n==="print")break;t.addEventListener("change",o=>{i.setValue(e,{value:o.target.checked?o.target.getAttribute("xfaOn"):o.target.getAttribute("xfaOff")})})}else{if(r.value!==null&&t.setAttribute("value",r.value),n==="print")break;t.addEventListener("input",o=>{i.setValue(e,{value:o.target.value})})}break;case"select":if(r.value!==null){t.setAttribute("value",r.value);for(const o of s.children)o.attributes.value===r.value?o.attributes.selected=!0:o.attributes.hasOwnProperty("selected")&&delete o.attributes.selected}t.addEventListener("input",o=>{const h=o.target.options,c=h.selectedIndex===-1?"":h[h.selectedIndex].value;i.setValue(e,{value:c})});break}}static setAttributes({html:t,element:e,storage:s=null,intent:i,linkService:n}){const{attributes:r}=e,o=t instanceof HTMLAnchorElement;r.type==="radio"&&(r.name=`${r.name}-${i}`);for(const[h,c]of Object.entries(r))if(c!=null)switch(h){case"class":c.length&&t.setAttribute(h,c.join(" "));break;case"dataId":break;case"id":t.setAttribute("data-element-id",c);break;case"style":Object.assign(t.style,c);break;case"textContent":t.textContent=c;break;default:(!o||h!=="href"&&h!=="newWindow")&&t.setAttribute(h,c)}o&&n.addLinkAttributes(t,r.href,r.newWindow),s&&r.dataId&&this.setupStorage(t,r.dataId,e,s)}static render(t){var d,f;const e=t.annotationStorage,s=t.linkService,i=t.xfaHtml,n=t.intent||"display",r=document.createElement(i.name);i.attributes&&this.setAttributes({html:r,element:i,intent:n,linkService:s});const o=n!=="richText",h=t.div;if(h.append(r),t.viewport){const g=`matrix(${t.viewport.transform.join(",")})`;h.style.transform=g}o&&h.setAttribute("class","xfaLayer xfaFont");const c=[];if(i.children.length===0){if(i.value){const g=document.createTextNode(i.value);r.append(g),o&&yl.shouldBuildText(i.name)&&c.push(g)}return{textDivs:c}}const u=[[i,-1,r]];for(;u.length>0;){const[g,p,m]=u.at(-1);if(p+1===g.children.length){u.pop();continue}const y=g.children[++u.at(-1)[1]];if(y===null)continue;const{name:b}=y;if(b==="#text"){const C=document.createTextNode(y.value);c.push(C),m.append(C);continue}const x=(d=y==null?void 0:y.attributes)!=null&&d.xmlns?document.createElementNS(y.attributes.xmlns,b):document.createElement(b);if(m.append(x),y.attributes&&this.setAttributes({html:x,element:y,storage:e,intent:n,linkService:s}),((f=y.children)==null?void 0:f.length)>0)u.push([y,-1,x]);else if(y.value){const C=document.createTextNode(y.value);o&&yl.shouldBuildText(b)&&c.push(C),x.append(C)}}for(const g of h.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea"))g.setAttribute("readOnly",!0);return{textDivs:c}}static update(t){const e=`matrix(${t.viewport.transform.join(",")})`;t.div.style.transform=e,t.div.hidden=!1}}const xl=1e3,BC=9,Kr=new WeakSet;function Jn(a){return{width:a[2]-a[0],height:a[3]-a[1]}}class HC{static create(t){switch(t.data.annotationType){case le.LINK:return new _b(t);case le.TEXT:return new zC(t);case le.WIDGET:switch(t.data.fieldType){case"Tx":return new VC(t);case"Btn":return t.data.radioButton?new wb(t):t.data.checkBox?new WC(t):new XC(t);case"Ch":return new UC(t);case"Sig":return new GC(t)}return new Jr(t);case le.POPUP:return new ip(t);case le.FREETEXT:return new xb(t);case le.LINE:return new $C(t);case le.SQUARE:return new qC(t);case le.CIRCLE:return new KC(t);case le.POLYLINE:return new Sb(t);case le.CARET:return new QC(t);case le.INK:return new np(t);case le.POLYGON:return new JC(t);case le.HIGHLIGHT:return new Cb(t);case le.UNDERLINE:return new ZC(t);case le.SQUIGGLY:return new tA(t);case le.STRIKEOUT:return new eA(t);case le.STAMP:return new Ab(t);case le.FILEATTACHMENT:return new sA(t);default:return new Kt(t)}}}const bp=class bp{constructor(t,{isRenderable:e=!1,ignoreBorder:s=!1,createQuadrilaterals:i=!1}={}){_(this,fc);_(this,Fo,null);_(this,oh,!1);_(this,ah,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 bp._hasPopupData(this.data)}updateEdited(t){var s;if(!this.container)return;l(this,Fo)||v(this,Fo,{rect:this.data.rect.slice(0)});const{rect:e}=t;e&&w(this,fc,Qp).call(this,e),(s=l(this,ah))==null||s.popup.updateEdited(t)}resetEdited(){var t;l(this,Fo)&&(w(this,fc,Qp).call(this,l(this,Fo).rect),(t=l(this,ah))==null||t.popup.resetEdited(),v(this,Fo,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 Jr||(n.tabIndex=xl);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 ip){const{rotation:m}=e;return!e.hasOwnCanvas&&m!==0&&this.setRotation(m,n),n}const{width:o,height:h}=Jn(e.rect);if(!t&&e.borderStyle.width>0){r.borderWidth=`${e.borderStyle.width}px`;const m=e.borderStyle.horizontalCornerRadius,y=e.borderStyle.verticalCornerRadius;if(m>0||y>0){const x=`calc(${m}px * var(--scale-factor)) / calc(${y}px * var(--scale-factor))`;r.borderRadius=x}else if(this instanceof wb){const x=`calc(${o}px * var(--scale-factor)) / calc(${h}px * var(--scale-factor))`;r.borderRadius=x}switch(e.borderStyle.style){case ul.SOLID:r.borderStyle="solid";break;case ul.DASHED:r.borderStyle="dashed";break;case ul.BEVELED:ht("Unimplemented border style: beveled");break;case ul.INSET:ht("Unimplemented border style: inset");break;case ul.UNDERLINE:r.borderBottomStyle="solid";break}const b=e.borderColor||null;b?(v(this,oh,!0),r.borderColor=q.makeHexColor(b[0]|0,b[1]|0,b[2]|0)):r.borderWidth=0}const c=q.normalizeRect([e.rect[0],s.view[3]-e.rect[1]+s.view[1],e.rect[2],s.view[3]-e.rect[3]+s.view[1]]),{pageWidth:u,pageHeight:d,pageX:f,pageY:g}=i.rawDims;r.left=`${100*(c[0]-f)/u}%`,r.top=`${100*(c[1]-g)/d}%`;const{rotation:p}=e;return e.hasOwnCanvas||p===0?(r.width=`${100*o/u}%`,r.height=`${100*h/d}%`):this.setRotation(p,n),n}setRotation(t,e=this.container){if(!this.data.rect)return;const{pageWidth:s,pageHeight:i}=this.parent.viewport.rawDims,{width:n,height:r}=Jn(this.data.rect);let o,h;t%180===0?(o=100*n/s,h=100*r/i):(o=100*r/s,h=100*n/i),e.style.width=`${o}%`,e.style.height=`${h}%`,e.setAttribute("data-main-rotation",(360-t)%360)}get _commonActions(){const t=(e,s,i)=>{const n=i.detail[e],r=n[0],o=n.slice(1);i.target.style[s]=bb[`${r}_HTML`](o),this.annotationStorage.setValue(this.data.id,{[s]:bb[`${r}_rgb`](o)})};return ct(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,y,b,x]=t.subarray(2,6);if(i===m&&n===y&&e===b&&s===x)return}const{style:r}=this.container;let o;if(l(this,oh)){const{borderColor:m,borderWidth:y}=r;r.borderWidth=0,o=["url('data:image/svg+xml;utf8,",'<svg xmlns="http://www.w3.org/2000/svg"',' preserveAspectRatio="none" viewBox="0 0 1 1">',`<g fill="transparent" stroke="${m}" stroke-width="${y}">`],this.container.classList.add("hasBorder")}const h=i-e,c=n-s,{svgFactory:u}=this,d=u.createElement("svg");d.classList.add("quadrilateralsContainer"),d.setAttribute("width",0),d.setAttribute("height",0);const f=u.createElement("defs");d.append(f);const g=u.createElement("clipPath"),p=`clippath_${this.data.id}`;g.setAttribute("id",p),g.setAttribute("clipPathUnits","objectBoundingBox"),f.append(g);for(let m=2,y=t.length;m<y;m+=8){const b=t[m],x=t[m+1],C=t[m+2],S=t[m+3],T=u.createElement("rect"),P=(C-e)/h,M=(n-x)/c,D=(b-C)/h,R=(x-S)/c;T.setAttribute("x",P),T.setAttribute("y",M),T.setAttribute("width",D),T.setAttribute("height",R),g.append(T),o==null||o.push(`<rect vector-effect="non-scaling-stroke" x="${P}" y="${M}" width="${D}" height="${R}"/>`)}l(this,oh)&&(o.push("</g></svg>')"),r.backgroundImage=o.join("")),this.container.append(d),this.container.style.clipPath=`url(#${p})`}_createPopup(){const{data:t}=this,e=v(this,ah,new ip({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(){Pt("Abstract method `AnnotationElement.render` called")}_getElementsByName(t,e=null){const s=[];if(this._fieldObjects){const i=this._fieldObjects[t];if(i)for(const{page:n,id:r,exportValues:o}of i){if(n===-1||r===e)continue;const h=typeof o=="string"?o:null,c=document.querySelector(`[data-element-id="${r}"]`);if(c&&!Kr.has(c)){ht(`_getElementsByName - element not allowed: ${r}`);continue}s.push({id:r,exportValue:h,domElement:c})}return s}for(const i of document.getElementsByName(t)){const{exportValue:n}=i,r=i.getAttribute("data-element-id");r!==e&&Kr.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})})}};Fo=new WeakMap,oh=new WeakMap,ah=new WeakMap,fc=new WeakSet,Qp=function(t){const{container:{style:e},data:{rect:s,rotation:i},parent:{viewport:{rawDims:{pageWidth:n,pageHeight:r,pageX:o,pageY:h}}}}=this;s==null||s.splice(0,4,...t);const{width:c,height:u}=Jn(t);e.left=`${100*(t[0]-o)/n}%`,e.top=`${100*(r-t[3]+h)/r}%`,i===0?(e.width=`${100*c/n}%`,e.height=`${100*u/r}%`):this.setRotation(i)};let Kt=bp;class _b extends Kt{constructor(e,s=null){super(e,{isRenderable:!0,ignoreBorder:!!(s!=null&&s.ignoreBorder),createQuadrilaterals:!0});_(this,Cs);this.isTooltipOnly=e.data.isTooltipOnly}render(){const{data:e,linkService:s}=this,i=document.createElement("a");i.setAttribute("data-element-id",e.id);let n=!1;return e.url?(s.addLinkAttributes(i,e.url,e.newWindow),n=!0):e.action?(this._bindNamedAction(i,e.action),n=!0):e.attachment?(w(this,Cs,Ry).call(this,i,e.attachment,e.attachmentDest),n=!0):e.setOCGState?(w(this,Cs,Fy).call(this,i,e.setOCGState),n=!0):e.dest?(this._bindLink(i,e.dest),n=!0):(e.actions&&(e.actions.Action||e.actions["Mouse Up"]||e.actions["Mouse Down"])&&this.enableScripting&&this.hasJSActions&&(this._bindJSAction(i,e),n=!0),e.resetForm?(this._bindResetFormAction(i,e.resetForm),n=!0):this.isTooltipOnly&&!n&&(this._bindLink(i,""),n=!0)),this.container.classList.add("linkAnnotation"),n&&this.container.append(i),this.container}_bindLink(e,s){e.href=this.linkService.getDestinationHash(s),e.onclick=()=>(s&&this.linkService.goToDestination(s),!1),(s||s==="")&&w(this,Cs,ha).call(this)}_bindNamedAction(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeNamedAction(s),!1),w(this,Cs,ha).call(this)}_bindJSAction(e,s){e.href=this.linkService.getAnchorUrl("");const i=new Map([["Action","onclick"],["Mouse Up","onmouseup"],["Mouse Down","onmousedown"]]);for(const n of Object.keys(s.actions)){const r=i.get(n);r&&(e[r]=()=>{var o;return(o=this.linkService.eventBus)==null||o.dispatch("dispatcheventinsandbox",{source:this,detail:{id:s.id,name:n}}),!1})}e.onclick||(e.onclick=()=>!1),w(this,Cs,ha).call(this)}_bindResetFormAction(e,s){const i=e.onclick;if(i||(e.href=this.linkService.getAnchorUrl("")),w(this,Cs,ha).call(this),!this._fieldObjects){ht('_bindResetFormAction - "resetForm" action not supported, ensure that the `fieldObjects` parameter is provided.'),i||(e.onclick=()=>!1);return}e.onclick=()=>{var d;i==null||i();const{fields:n,refs:r,include:o}=s,h=[];if(n.length!==0||r.length!==0){const f=new Set(r);for(const g of n){const p=this._fieldObjects[g]||[];for(const{id:m}of p)f.add(m)}for(const g of Object.values(this._fieldObjects))for(const p of g)f.has(p.id)===o&&h.push(p)}else for(const f of Object.values(this._fieldObjects))h.push(...f);const c=this.annotationStorage,u=[];for(const f of h){const{id:g}=f;switch(u.push(g),f.type){case"text":{const m=f.defaultValue||"";c.setValue(g,{value:m});break}case"checkbox":case"radiobutton":{const m=f.defaultValue===f.exportValues;c.setValue(g,{value:m});break}case"combobox":case"listbox":{const m=f.defaultValue||"";c.setValue(g,{value:m});break}default:continue}const p=document.querySelector(`[data-element-id="${g}"]`);if(p){if(!Kr.has(p)){ht(`_bindResetFormAction - element not allowed: ${g}`);continue}}else continue;p.dispatchEvent(new Event("resetform"))}return this.enableScripting&&((d=this.linkService.eventBus)==null||d.dispatch("dispatcheventinsandbox",{source:this,detail:{id:"app",ids:u,name:"ResetForm"}})),!1}}}Cs=new WeakSet,ha=function(){this.container.setAttribute("data-internal-link","")},Ry=function(e,s,i=null){e.href=this.linkService.getAnchorUrl(""),s.description&&(e.title=s.description),e.onclick=()=>{var n;return(n=this.downloadManager)==null||n.openOrDownloadData(s.content,s.filename,i),!1},w(this,Cs,ha).call(this)},Fy=function(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeSetOCGState(s),!1),w(this,Cs,ha).call(this)};class zC extends Kt{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 Jr extends Kt{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 Ue.platform.isMac?t.metaKey:t.ctrlKey}_setEventListener(t,e,s,i,n){s.includes("mouse")?t.addEventListener(s,r=>{var o;(o=this.linkService.eventBus)==null||o.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:i,value:n(r),shift:r.shiftKey,modifier:this._getKeyModifier(r)}})}):t.addEventListener(s,r=>{var o;if(s==="blur"){if(!e.focused||!r.relatedTarget)return;e.focused=!1}else if(s==="focus"){if(e.focused)return;e.focused=!0}n&&((o=this.linkService.eventBus)==null||o.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:i,value:n(r)}}))})}_setEventListeners(t,e,s,i){var n,r,o;for(const[h,c]of s)(c==="Action"||(n=this.data.actions)!=null&&n[c])&&((c==="Focus"||c==="Blur")&&(e||(e={focused:!1})),this._setEventListener(t,e,h,c,i),c==="Focus"&&!((r=this.data.actions)!=null&&r.Blur)?this._setEventListener(t,e,"blur","Blur",null):c==="Blur"&&!((o=this.data.actions)!=null&&o.Focus)&&this._setEventListener(t,e,"focus","Focus",null))}_setBackgroundColor(t){const e=this.data.backgroundColor||null;t.style.backgroundColor=e===null?"transparent":q.makeHexColor(e[0],e[1],e[2])}_setTextStyle(t){const e=["left","center","right"],{fontColor:s}=this.data.defaultAppearanceData,i=this.data.defaultAppearanceData.fontSize||BC,n=t.style;let r;const o=2,h=c=>Math.round(10*c)/10;if(this.data.multiLine){const c=Math.abs(this.data.rect[3]-this.data.rect[1]-o),u=Math.round(c/(Og*i))||1,d=c/u;r=Math.min(i,h(d/Og))}else{const c=Math.abs(this.data.rect[3]-this.data.rect[1]-o);r=Math.min(i,h(c/Og))}n.fontSize=`calc(${r}px * var(--scale-factor))`,n.color=q.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 VC extends Jr{constructor(t){const e=t.renderForms||t.data.hasOwnCanvas||!t.data.hasAppearance&&!!t.data.fieldValue;super(t,{isRenderable:e})}setPropertyOnSiblings(t,e,s,i){const n=this.annotationStorage;for(const r of this._getElementsByName(t.name,t.id))r.domElement&&(r.domElement[e]=s),n.setValue(r.id,{[i]:s})}render(){var i,n;const t=this.annotationStorage,e=this.data.id;this.container.classList.add("textWidgetAnnotation");let s=null;if(this.renderForms){const r=t.getValue(e,{value:this.data.fieldValue});let o=r.value||"";const h=t.getValue(e,{charLimit:this.data.maxLen}).charLimit;h&&o.length>h&&(o=o.slice(0,h));let c=r.formattedValue||((i=this.data.textContent)==null?void 0:i.join(`
535
+ `))||null;c&&this.data.comb&&(c=c.replaceAll(/\s+/g,""));const u={userValue:o,formattedValue:c,lastCommittedValue:null,commitKey:1,focused:!1};this.data.multiLine?(s=document.createElement("textarea"),s.textContent=c??o,this.data.doNotScroll&&(s.style.overflowY="hidden")):(s=document.createElement("input"),s.type="text",s.setAttribute("value",c??o),this.data.doNotScroll&&(s.style.overflowX="hidden")),this.data.hasOwnCanvas&&(s.hidden=!0),Kr.add(s),s.setAttribute("data-element-id",e),s.disabled=this.data.readOnly,s.name=this.data.fieldName,s.tabIndex=xl,this._setRequired(s,this.data.required),h&&(s.maxLength=h),s.addEventListener("input",f=>{t.setValue(e,{value:f.target.value}),this.setPropertyOnSiblings(s,"value",f.target.value,"value"),u.formattedValue=null}),s.addEventListener("resetform",f=>{const g=this.data.defaultFieldValue??"";s.value=u.userValue=g,u.formattedValue=null});let d=f=>{const{formattedValue:g}=u;g!=null&&(f.target.value=g),f.target.scrollLeft=0};if(this.enableScripting&&this.hasJSActions){s.addEventListener("focus",g=>{var m;if(u.focused)return;const{target:p}=g;u.userValue&&(p.value=u.userValue),u.lastCommittedValue=p.value,u.commitKey=1,(m=this.data.actions)!=null&&m.Focus||(u.focused=!0)}),s.addEventListener("updatefromsandbox",g=>{this.showElementAndHideCanvas(g.target);const p={value(m){u.userValue=m.detail.value??"",t.setValue(e,{value:u.userValue.toString()}),m.target.value=u.userValue},formattedValue(m){const{formattedValue:y}=m.detail;u.formattedValue=y,y!=null&&m.target!==document.activeElement&&(m.target.value=y),t.setValue(e,{formattedValue:y})},selRange(m){m.target.setSelectionRange(...m.detail.selRange)},charLimit:m=>{var C;const{charLimit:y}=m.detail,{target:b}=m;if(y===0){b.removeAttribute("maxLength");return}b.setAttribute("maxLength",y);let x=u.userValue;!x||x.length<=y||(x=x.slice(0,y),b.value=u.userValue=x,t.setValue(e,{value:x}),(C=this.linkService.eventBus)==null||C.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:x,willCommit:!0,commitKey:1,selStart:b.selectionStart,selEnd:b.selectionEnd}}))}};this._dispatchEventFromSandbox(p,g)}),s.addEventListener("keydown",g=>{var y;u.commitKey=1;let p=-1;if(g.key==="Escape"?p=0:g.key==="Enter"&&!this.data.multiLine?p=2:g.key==="Tab"&&(u.commitKey=3),p===-1)return;const{value:m}=g.target;u.lastCommittedValue!==m&&(u.lastCommittedValue=m,u.userValue=m,(y=this.linkService.eventBus)==null||y.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:m,willCommit:!0,commitKey:p,selStart:g.target.selectionStart,selEnd:g.target.selectionEnd}}))});const f=d;d=null,s.addEventListener("blur",g=>{var m,y;if(!u.focused||!g.relatedTarget)return;(m=this.data.actions)!=null&&m.Blur||(u.focused=!1);const{value:p}=g.target;u.userValue=p,u.lastCommittedValue!==p&&((y=this.linkService.eventBus)==null||y.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:p,willCommit:!0,commitKey:u.commitKey,selStart:g.target.selectionStart,selEnd:g.target.selectionEnd}})),f(g)}),(n=this.data.actions)!=null&&n.Keystroke&&s.addEventListener("beforeinput",g=>{var T;u.lastCommittedValue=null;const{data:p,target:m}=g,{value:y,selectionStart:b,selectionEnd:x}=m;let C=b,S=x;switch(g.inputType){case"deleteWordBackward":{const P=y.substring(0,b).match(/\w*[^\w]*$/);P&&(C-=P[0].length);break}case"deleteWordForward":{const P=y.substring(b).match(/^[^\w]*\w*/);P&&(S+=P[0].length);break}case"deleteContentBackward":b===x&&(C-=1);break;case"deleteContentForward":b===x&&(S+=1);break}g.preventDefault(),(T=this.linkService.eventBus)==null||T.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:y,change:p||"",willCommit:!1,selStart:C,selEnd:S}})}),this._setEventListeners(s,u,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],g=>g.target.value)}if(d&&s.addEventListener("blur",d),this.data.comb){const g=(this.data.rect[2]-this.data.rect[0])/h;s.classList.add("comb"),s.style.letterSpacing=`calc(${g}px * var(--scale-factor) - 1ch)`}}else s=document.createElement("div"),s.textContent=this.data.fieldValue,s.style.verticalAlign="middle",s.style.display="table-cell",this.data.hasOwnCanvas&&(s.hidden=!0);return this._setTextStyle(s),this._setBackgroundColor(s),this._setDefaultPropertiesFromJS(s),this.container.append(s),this.container}}class GC extends Jr{constructor(t){super(t,{isRenderable:!!t.data.hasOwnCanvas})}}class WC extends Jr{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 Kr.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=xl,n.addEventListener("change",r=>{const{name:o,checked:h}=r.target;for(const c of this._getElementsByName(o,s)){const u=h&&c.exportValue===e.exportValue;c.domElement&&(c.domElement.checked=u),t.setValue(c.id,{value:u})}t.setValue(s,{value:h})}),n.addEventListener("resetform",r=>{const o=e.defaultFieldValue||"Off";r.target.checked=o===e.exportValue}),this.enableScripting&&this.hasJSActions&&(n.addEventListener("updatefromsandbox",r=>{const o={value(h){h.target.checked=h.detail.value!=="Off",t.setValue(s,{value:h.target.checked})}};this._dispatchEventFromSandbox(o,r)}),this._setEventListeners(n,null,[["change","Validate"],["change","Action"],["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],r=>r.target.checked)),this._setBackgroundColor(n),this._setDefaultPropertiesFromJS(n),this.container.append(n),this.container}}class wb extends Jr{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(Kr.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=xl,n.addEventListener("change",r=>{const{name:o,checked:h}=r.target;for(const c of this._getElementsByName(o,s))t.setValue(c.id,{value:!1});t.setValue(s,{value:h})}),n.addEventListener("resetform",r=>{const o=e.defaultFieldValue;r.target.checked=o!=null&&o===e.buttonValue}),this.enableScripting&&this.hasJSActions){const r=e.buttonValue;n.addEventListener("updatefromsandbox",o=>{const h={value:c=>{const u=r===c.detail.value;for(const d of this._getElementsByName(c.target.name)){const f=u&&d.id===s;d.domElement&&(d.domElement.checked=f),t.setValue(d.id,{value:f})}}};this._dispatchEventFromSandbox(h,o)}),this._setEventListeners(n,null,[["change","Validate"],["change","Action"],["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],o=>o.target.checked)}return this._setBackgroundColor(n),this._setDefaultPropertiesFromJS(n),this.container.append(n),this.container}}class XC extends _b{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 UC extends Jr{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");Kr.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=xl;let n=this.data.combo&&this.data.options.length>0;this.data.combo||(i.size=this.data.options.length,this.data.multiSelect&&(i.multiple=!0)),i.addEventListener("resetform",u=>{const d=this.data.defaultFieldValue;for(const f of i.options)f.selected=f.value===d});for(const u of this.data.options){const d=document.createElement("option");d.textContent=u.displayValue,d.value=u.exportValue,s.value.includes(u.exportValue)&&(d.setAttribute("selected",!0),n=!1),i.append(d)}let r=null;if(n){const u=document.createElement("option");u.value=" ",u.setAttribute("hidden",!0),u.setAttribute("selected",!0),i.prepend(u),r=()=>{u.remove(),i.removeEventListener("input",r),r=null},i.addEventListener("input",r)}const o=u=>{const d=u?"value":"textContent",{options:f,multiple:g}=i;return g?Array.prototype.filter.call(f,p=>p.selected).map(p=>p[d]):f.selectedIndex===-1?null:f[f.selectedIndex][d]};let h=o(!1);const c=u=>{const d=u.target.options;return Array.prototype.map.call(d,f=>({displayValue:f.textContent,exportValue:f.value}))};return this.enableScripting&&this.hasJSActions?(i.addEventListener("updatefromsandbox",u=>{const d={value(f){r==null||r();const g=f.detail.value,p=new Set(Array.isArray(g)?g:[g]);for(const m of i.options)m.selected=p.has(m.value);t.setValue(e,{value:o(!0)}),h=o(!1)},multipleSelection(f){i.multiple=!0},remove(f){const g=i.options,p=f.detail.remove;g[p].selected=!1,i.remove(p),g.length>0&&Array.prototype.findIndex.call(g,y=>y.selected)===-1&&(g[0].selected=!0),t.setValue(e,{value:o(!0),items:c(f)}),h=o(!1)},clear(f){for(;i.length!==0;)i.remove(0);t.setValue(e,{value:null,items:[]}),h=o(!1)},insert(f){const{index:g,displayValue:p,exportValue:m}=f.detail.insert,y=i.children[g],b=document.createElement("option");b.textContent=p,b.value=m,y?y.before(b):i.append(b),t.setValue(e,{value:o(!0),items:c(f)}),h=o(!1)},items(f){const{items:g}=f.detail;for(;i.length!==0;)i.remove(0);for(const p of g){const{displayValue:m,exportValue:y}=p,b=document.createElement("option");b.textContent=m,b.value=y,i.append(b)}i.options.length>0&&(i.options[0].selected=!0),t.setValue(e,{value:o(!0),items:c(f)}),h=o(!1)},indices(f){const g=new Set(f.detail.indices);for(const p of f.target.options)p.selected=g.has(p.index);t.setValue(e,{value:o(!0)}),h=o(!1)},editable(f){f.target.disabled=!f.detail.editable}};this._dispatchEventFromSandbox(d,u)}),i.addEventListener("input",u=>{var g;const d=o(!0),f=o(!1);t.setValue(e,{value:d}),u.preventDefault(),(g=this.linkService.eventBus)==null||g.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:h,change:f,changeEx:d,willCommit:!1,commitKey:1,keyDown:!1}})}),this._setEventListeners(i,null,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"],["input","Action"],["input","Validate"]],u=>u.target.value)):i.addEventListener("input",function(u){t.setValue(e,{value:o(!0)})}),this.data.combo&&this._setTextStyle(i),this._setBackgroundColor(i),this._setDefaultPropertiesFromJS(i),this.container.append(i),this.container}}class ip extends Kt{constructor(t){const{data:e,elements:s}=t;super(t,{isRenderable:Kt._hasPopupData(e)}),this.elements=s,this.popup=null}render(){this.container.classList.add("popupAnnotation");const t=this.popup=new YC({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=>`${jg}${s}`).join(",")),this.container}}class YC{constructor({container:t,color:e,elements:s,titleObj:i,modificationDate:n,contentsObj:r,richText:o,parent:h,rect:c,parentRect:u,open:d}){_(this,Tt);_(this,hh,w(this,Tt,jy).bind(this));_(this,Gd,w(this,Tt,tm).bind(this));_(this,Wd,w(this,Tt,vf).bind(this));_(this,lh,w(this,Tt,mf).bind(this));_(this,Lo,null);_(this,Yt,null);_(this,En,null);_(this,ch,null);_(this,gc,null);_(this,pc,null);_(this,uh,null);_(this,kn,!1);_(this,ui,null);_(this,Pn,null);_(this,mc,null);_(this,Mn,null);_(this,vc,null);_(this,Io,null);_(this,jo,!1);var f;v(this,Yt,t),v(this,vc,i),v(this,En,r),v(this,Mn,o),v(this,pc,h),v(this,Lo,e),v(this,mc,c),v(this,uh,u),v(this,gc,s),v(this,ch,Hg.toDateObject(n)),this.trigger=s.flatMap(g=>g.getElementsToTriggerPopup());for(const g of this.trigger)g.addEventListener("click",l(this,lh)),g.addEventListener("mouseenter",l(this,Wd)),g.addEventListener("mouseleave",l(this,Gd)),g.classList.add("popupTriggerArea");for(const g of s)(f=g.container)==null||f.addEventListener("keydown",l(this,hh));l(this,Yt).hidden=!0,d&&w(this,Tt,mf).call(this)}render(){if(l(this,ui))return;const t=v(this,ui,document.createElement("div"));if(t.className="popup",l(this,Lo)){const n=t.style.outlineColor=q.makeHexColor(...l(this,Lo));CSS.supports("background-color","color-mix(in srgb, red 30%, white)")?t.style.backgroundColor=`color-mix(in srgb, ${n} 30%, white)`:t.style.backgroundColor=q.makeHexColor(...l(this,Lo).map(o=>Math.floor(.7*(255-o)+o)))}const e=document.createElement("span");e.className="header";const s=document.createElement("h1");if(e.append(s),{dir:s.dir,str:s.textContent}=l(this,vc),t.append(e),l(this,ch)){const n=document.createElement("span");n.classList.add("popupDate"),n.setAttribute("data-l10n-id","pdfjs-annotation-date-time-string"),n.setAttribute("data-l10n-args",JSON.stringify({dateObj:l(this,ch).valueOf()})),e.append(n)}const i=l(this,Tt,pf);if(i)yb.render({xfaHtml:i,intent:"richText",div:t}),t.lastChild.classList.add("richText","popupContent");else{const n=this._formatContents(l(this,En));t.append(n)}l(this,Yt).append(t)}_formatContents({str:t,dir:e}){const s=document.createElement("p");s.classList.add("popupContent"),s.dir=e;const i=t.split(/(?:\r\n?|\n)/);for(let n=0,r=i.length;n<r;++n){const o=i[n];s.append(document.createTextNode(o)),n<r-1&&s.append(document.createElement("br"))}return s}updateEdited({rect:t,popupContent:e}){var s;l(this,Io)||v(this,Io,{contentsObj:l(this,En),richText:l(this,Mn)}),t&&v(this,Pn,null),e&&(v(this,Mn,w(this,Tt,Iy).call(this,e)),v(this,En,null)),(s=l(this,ui))==null||s.remove(),v(this,ui,null)}resetEdited(){var t;l(this,Io)&&({contentsObj:es(this,En)._,richText:es(this,Mn)._}=l(this,Io),v(this,Io,null),(t=l(this,ui))==null||t.remove(),v(this,ui,null),v(this,Pn,null))}forceHide(){v(this,jo,this.isVisible),l(this,jo)&&(l(this,Yt).hidden=!0)}maybeShow(){l(this,jo)&&(l(this,ui)||w(this,Tt,vf).call(this),v(this,jo,!1),l(this,Yt).hidden=!1)}get isVisible(){return l(this,Yt).hidden===!1}}hh=new WeakMap,Gd=new WeakMap,Wd=new WeakMap,lh=new WeakMap,Lo=new WeakMap,Yt=new WeakMap,En=new WeakMap,ch=new WeakMap,gc=new WeakMap,pc=new WeakMap,uh=new WeakMap,kn=new WeakMap,ui=new WeakMap,Pn=new WeakMap,mc=new WeakMap,Mn=new WeakMap,vc=new WeakMap,Io=new WeakMap,jo=new WeakMap,Tt=new WeakSet,pf=function(){const t=l(this,Mn),e=l(this,En);return t!=null&&t.str&&(!(e!=null&&e.str)||e.str===t.str)&&l(this,Mn).html||null},Zp=function(){var t,e,s;return((s=(e=(t=l(this,Tt,pf))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.fontSize)||0},Ly=function(){var t,e,s;return((s=(e=(t=l(this,Tt,pf))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.color)||null},Iy=function(t){const e=[],s={str:t,html:{name:"div",attributes:{dir:"auto"},children:[{name:"p",children:e}]}},i={style:{color:l(this,Tt,Ly),fontSize:l(this,Tt,Zp)?`calc(${l(this,Tt,Zp)}px * var(--scale-factor))`:""}};for(const n of t.split(`
536
+ `))e.push({name:"span",value:n,attributes:i});return s},jy=function(t){t.altKey||t.shiftKey||t.ctrlKey||t.metaKey||(t.key==="Enter"||t.key==="Escape"&&l(this,kn))&&w(this,Tt,mf).call(this)},Ny=function(){if(l(this,Pn)!==null)return;const{page:{view:t},viewport:{rawDims:{pageWidth:e,pageHeight:s,pageX:i,pageY:n}}}=l(this,pc);let r=!!l(this,uh),o=r?l(this,uh):l(this,mc);for(const p of l(this,gc))if(!o||q.intersect(p.data.rect,o)!==null){o=p.data.rect,r=!0;break}const h=q.normalizeRect([o[0],t[3]-o[1]+t[1],o[2],t[3]-o[3]+t[1]]),u=r?o[2]-o[0]+5:0,d=h[0]+u,f=h[1];v(this,Pn,[100*(d-i)/e,100*(f-n)/s]);const{style:g}=l(this,Yt);g.left=`${l(this,Pn)[0]}%`,g.top=`${l(this,Pn)[1]}%`},mf=function(){v(this,kn,!l(this,kn)),l(this,kn)?(w(this,Tt,vf).call(this),l(this,Yt).addEventListener("click",l(this,lh)),l(this,Yt).addEventListener("keydown",l(this,hh))):(w(this,Tt,tm).call(this),l(this,Yt).removeEventListener("click",l(this,lh)),l(this,Yt).removeEventListener("keydown",l(this,hh)))},vf=function(){l(this,ui)||this.render(),this.isVisible?l(this,kn)&&l(this,Yt).classList.add("focused"):(w(this,Tt,Ny).call(this),l(this,Yt).hidden=!1,l(this,Yt).style.zIndex=parseInt(l(this,Yt).style.zIndex)+1e3)},tm=function(){l(this,Yt).classList.remove("focused"),!(l(this,kn)||!this.isVisible)&&(l(this,Yt).hidden=!0,l(this,Yt).style.zIndex=parseInt(l(this,Yt).style.zIndex)-1e3)};class xb extends Kt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.textContent=t.data.textContent,this.textPosition=t.data.textPosition,this.annotationEditorType=at.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 $C extends Kt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,bc,null)}render(){this.container.classList.add("lineAnnotation");const e=this.data,{width:s,height:i}=Jn(e.rect),n=this.svgFactory.create(s,i,!0),r=v(this,bc,this.svgFactory.createElement("svg:line"));return r.setAttribute("x1",e.rect[2]-e.lineCoordinates[0]),r.setAttribute("y1",e.rect[3]-e.lineCoordinates[1]),r.setAttribute("x2",e.rect[2]-e.lineCoordinates[2]),r.setAttribute("y2",e.rect[3]-e.lineCoordinates[3]),r.setAttribute("stroke-width",e.borderStyle.width||1),r.setAttribute("stroke","transparent"),r.setAttribute("fill","transparent"),n.append(r),this.container.append(n),!e.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,bc)}addHighlightArea(){this.container.classList.add("highlightArea")}}bc=new WeakMap;class qC extends Kt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,yc,null)}render(){this.container.classList.add("squareAnnotation");const e=this.data,{width:s,height:i}=Jn(e.rect),n=this.svgFactory.create(s,i,!0),r=e.borderStyle.width,o=v(this,yc,this.svgFactory.createElement("svg:rect"));return o.setAttribute("x",r/2),o.setAttribute("y",r/2),o.setAttribute("width",s-r),o.setAttribute("height",i-r),o.setAttribute("stroke-width",r||1),o.setAttribute("stroke","transparent"),o.setAttribute("fill","transparent"),n.append(o),this.container.append(n),!e.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,yc)}addHighlightArea(){this.container.classList.add("highlightArea")}}yc=new WeakMap;class KC extends Kt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,_c,null)}render(){this.container.classList.add("circleAnnotation");const e=this.data,{width:s,height:i}=Jn(e.rect),n=this.svgFactory.create(s,i,!0),r=e.borderStyle.width,o=v(this,_c,this.svgFactory.createElement("svg:ellipse"));return o.setAttribute("cx",s/2),o.setAttribute("cy",i/2),o.setAttribute("rx",s/2-r/2),o.setAttribute("ry",i/2-r/2),o.setAttribute("stroke-width",r||1),o.setAttribute("stroke","transparent"),o.setAttribute("fill","transparent"),n.append(o),this.container.append(n),!e.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,_c)}addHighlightArea(){this.container.classList.add("highlightArea")}}_c=new WeakMap;class Sb extends Kt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,wc,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}=Jn(e),h=this.svgFactory.create(r,o,!0);let c=[];for(let d=0,f=s.length;d<f;d+=2){const g=s[d]-e[0],p=e[3]-s[d+1];c.push(`${g},${p}`)}c=c.join(" ");const u=v(this,wc,this.svgFactory.createElement(this.svgElementName));return u.setAttribute("points",c),u.setAttribute("stroke-width",i.width||1),u.setAttribute("stroke","transparent"),u.setAttribute("fill","transparent"),h.append(u),this.container.append(h),!n&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,wc)}addHighlightArea(){this.container.classList.add("highlightArea")}}wc=new WeakMap;class JC extends Sb{constructor(t){super(t),this.containerClassName="polygonAnnotation",this.svgElementName="svg:polygon"}}class QC extends Kt{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 np extends Kt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,Sc);_(this,xc,null);_(this,No,[]);this.containerClassName="inkAnnotation",this.svgElementName="svg:polyline",this.annotationEditorType=this.data.it==="InkHighlight"?at.HIGHLIGHT:at.INK}render(){this.container.classList.add(this.containerClassName);const{data:{rect:e,rotation:s,inkLists:i,borderStyle:n,popupRef:r}}=this,{transform:o,width:h,height:c}=w(this,Sc,em).call(this,s,e),u=this.svgFactory.create(h,c,!0),d=v(this,xc,this.svgFactory.createElement("svg:g"));u.append(d),d.setAttribute("stroke-width",n.width||1),d.setAttribute("stroke-linecap","round"),d.setAttribute("stroke-linejoin","round"),d.setAttribute("stroke-miterlimit",10),d.setAttribute("stroke","transparent"),d.setAttribute("fill","transparent"),d.setAttribute("transform",o);for(let f=0,g=i.length;f<g;f++){const p=this.svgFactory.createElement(this.svgElementName);l(this,No).push(p),p.setAttribute("points",i[f].join(",")),d.append(p)}return!r&&this.hasPopupData&&this._createPopup(),this.container.append(u),this._editOnDoubleClick(),this.container}updateEdited(e){super.updateEdited(e);const{thickness:s,points:i,rect:n}=e,r=l(this,xc);if(s>=0&&r.setAttribute("stroke-width",s||1),i)for(let o=0,h=l(this,No).length;o<h;o++)l(this,No)[o].setAttribute("points",i[o].join(","));if(n){const{transform:o,width:h,height:c}=w(this,Sc,em).call(this,this.data.rotation,n);r.parentElement.setAttribute("viewBox",`0 0 ${h} ${c}`),r.setAttribute("transform",o)}}getElementsToTriggerPopup(){return l(this,No)}addHighlightArea(){this.container.classList.add("highlightArea")}}xc=new WeakMap,No=new WeakMap,Sc=new WeakSet,em=function(e,s){switch(e){case 90:return{transform:`rotate(90) translate(${-s[0]},${s[1]}) scale(1,-1)`,width:s[3]-s[1],height:s[2]-s[0]};case 180:return{transform:`rotate(180) translate(${-s[2]},${s[1]}) scale(1,-1)`,width:s[2]-s[0],height:s[3]-s[1]};case 270:return{transform:`rotate(270) translate(${-s[2]},${s[3]}) scale(1,-1)`,width:s[3]-s[1],height:s[2]-s[0]};default:return{transform:`translate(${-s[0]},${s[3]}) scale(1,-1)`,width:s[2]-s[0],height:s[3]-s[1]}}};class Cb extends Kt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0}),this.annotationEditorType=at.HIGHLIGHT}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("highlightAnnotation"),this._editOnDoubleClick(),this.container}}class ZC extends Kt{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 tA extends Kt{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 eA extends Kt{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 Ab extends Kt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.annotationEditorType=at.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 sA extends Kt{constructor(e){var i;super(e,{isRenderable:!0});_(this,Ac);_(this,Cc,null);const{file:s}=this.data;this.filename=s.filename,this.content=s.content,(i=this.linkService.eventBus)==null||i.dispatch("fileattachmentannotation",{source:this,...s})}render(){this.container.classList.add("fileAttachmentAnnotation");const{container:e,data:s}=this;let i;s.hasAppearance||s.fillAlpha===0?i=document.createElement("div"):(i=document.createElement("img"),i.src=`${this.imageResourcesPath}annotation-${/paperclip/i.test(s.name)?"paperclip":"pushpin"}.svg`,s.fillAlpha&&s.fillAlpha<1&&(i.style=`filter: opacity(${Math.round(s.fillAlpha*100)}%);`)),i.addEventListener("dblclick",w(this,Ac,sm).bind(this)),v(this,Cc,i);const{isMac:n}=Ue.platform;return e.addEventListener("keydown",r=>{r.key==="Enter"&&(n?r.metaKey:r.ctrlKey)&&w(this,Ac,sm).call(this)}),!s.popupRef&&this.hasPopupData?this._createPopup():i.classList.add("popupTriggerArea"),e.append(i),e}getElementsToTriggerPopup(){return l(this,Cc)}addHighlightArea(){this.container.classList.add("highlightArea")}}Cc=new WeakMap,Ac=new WeakSet,sm=function(){var e;(e=this.downloadManager)==null||e.openOrDownloadData(this.content,this.filename)};class iA{constructor({div:t,accessibilityManager:e,annotationCanvasMap:s,annotationEditorUIManager:i,page:n,viewport:r,structTreeLayer:o}){_(this,zo);_(this,Tc,null);_(this,Bo,null);_(this,Ho,new Map);_(this,Ec,null);this.div=t,v(this,Tc,e),v(this,Bo,s),v(this,Ec,o||null),this.page=n,this.viewport=r,this.zIndex=0,this._annotationEditorUIManager=i}hasEditableAnnotations(){return l(this,Ho).size>0}async render(t){var r;const{annotations:e}=t,s=this.div;$r(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 sp,annotationStorage:t.annotationStorage||new Yg,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===le.POPUP;if(h){const d=i.get(o.id);if(!d)continue;n.elements=d}else{const{width:d,height:f}=Jn(o.rect);if(d<=0||f<=0)continue}n.data=o;const c=HC.create(n);if(!c.isRenderable)continue;if(!h&&o.popupRef){const d=i.get(o.popupRef);d?d.push(c):i.set(o.popupRef,[c])}const u=c.render();o.hidden&&(u.style.visibility="hidden"),await w(this,zo,By).call(this,u,o.id),c._isEditable&&(l(this,Ho).set(c.data.id,c),(r=this._annotationEditorUIManager)==null||r.renderAnnotationElement(c))}w(this,zo,im).call(this)}update({viewport:t}){const e=this.div;this.viewport=t,$r(e,{rotation:t.rotation}),w(this,zo,im).call(this),e.hidden=!1}getEditableAnnotations(){return Array.from(l(this,Ho).values())}getEditableAnnotation(t){return l(this,Ho).get(t)}}Tc=new WeakMap,Bo=new WeakMap,Ho=new WeakMap,Ec=new WeakMap,zo=new WeakSet,By=async function(t,e){var r,o;const s=t.firstChild||t,i=s.id=`${jg}${e}`,n=await((r=l(this,Ec))==null?void 0:r.getAriaAttributes(i));if(n)for(const[h,c]of n)s.setAttribute(h,c);this.div.append(t),(o=l(this,Tc))==null||o.moveElementInDOM(this.div,t,s,!1)},im=function(){if(!l(this,Bo))return;const t=this.div;for(const[e,s]of l(this,Bo)){const i=t.querySelector(`[data-annotation-id="${e}"]`);if(!i)continue;s.className="annotationContent";const{firstChild:n}=i;n?n.nodeName==="CANVAS"?n.replaceWith(s):n.classList.contains("annotationContent")?n.after(s):n.before(s):i.append(s)}l(this,Bo).clear()};const Td=/\r\n?|\n/g,Ot=class Ot extends Vt{constructor(e){super({...e,name:"freeTextEditor"});_(this,re);_(this,di);_(this,As,"");_(this,kc,`${this.id}-editor`);_(this,Vo,null);_(this,Ts);v(this,di,e.color||Ot._defaultColor||Vt._defaultLineColor),v(this,Ts,e.fontSize||Ot._defaultFontSize)}static get _keyboardManager(){const e=Ot.prototype,s=r=>r.isEmpty(),i=qr.TRANSLATE_SMALL,n=qr.TRANSLATE_BIG;return ct(this,"_keyboardManager",new pl([[["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){Vt.initialize(e,s);const i=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(i.getPropertyValue("--freetext-padding"))}static updateDefaultParams(e,s){switch(e){case gt.FREETEXT_SIZE:Ot._defaultFontSize=s;break;case gt.FREETEXT_COLOR:Ot._defaultColor=s;break}}updateParams(e,s){switch(e){case gt.FREETEXT_SIZE:w(this,re,Hy).call(this,s);break;case gt.FREETEXT_COLOR:w(this,re,zy).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[gt.FREETEXT_SIZE,Ot._defaultFontSize],[gt.FREETEXT_COLOR,Ot._defaultColor||Vt._defaultLineColor]]}get propertiesToUpdate(){return[[gt.FREETEXT_SIZE,l(this,Ts)],[gt.FREETEXT_COLOR,l(this,di)]]}_translateEmpty(e,s){this._uiManager.translateSelectedEditors(e,s,!0)}getInitialTranslation(){const e=this.parentScale;return[-Ot._internalPadding*e,-(Ot._internalPadding+l(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(at.FREETEXT),super.enableEditMode(),this.overlayDiv.classList.remove("enabled"),this.editorDiv.contentEditable=!0,this._isDraggable=!1,this.div.removeAttribute("aria-activedescendant"),v(this,Vo,new AbortController);const e=this._uiManager.combinedSignal(l(this,Vo));this.editorDiv.addEventListener("keydown",this.editorDivKeydown.bind(this),{signal:e}),this.editorDiv.addEventListener("focus",this.editorDivFocus.bind(this),{signal:e}),this.editorDiv.addEventListener("blur",this.editorDivBlur.bind(this),{signal:e}),this.editorDiv.addEventListener("input",this.editorDivInput.bind(this),{signal:e}),this.editorDiv.addEventListener("paste",this.editorDivPaste.bind(this),{signal:e})}disableEditMode(){var e;this.isInEditMode()&&(this.parent.setEditingState(!0),super.disableEditMode(),this.overlayDiv.classList.add("enabled"),this.editorDiv.contentEditable=!1,this.div.setAttribute("aria-activedescendant",l(this,kc)),this._isDraggable=!0,(e=l(this,Vo))==null||e.abort(),v(this,Vo,null),this.div.focus({preventScroll:!0}),this.isEditing=!1,this.parent.div.classList.add("freetextEditing"))}focusin(e){this._focusEventsAllowed&&(super.focusin(e),e.target!==this.editorDiv&&this.editorDiv.focus())}onceAdded(e){var s;this.width||(this.enableEditMode(),e&&this.editorDiv.focus(),(s=this._initialOptions)!=null&&s.isCentered&&this.center(),this._initialOptions=null)}isEmpty(){return!this.editorDiv||this.editorDiv.innerText.trim()===""}remove(){this.isEditing=!1,this.parent&&(this.parent.setEditingState(!0),this.parent.div.classList.add("freetextEditing")),super.remove()}commit(){if(!this.isInEditMode())return;super.commit(),this.disableEditMode();const e=l(this,As),s=v(this,As,w(this,re,Vy).call(this).trimEnd());if(e===s)return;const i=n=>{if(v(this,As,n),!n){this.remove();return}w(this,re,_f).call(this),this._uiManager.rebuild(this),w(this,re,bf).call(this)};this.addCommands({cmd:()=>{i(s)},undo:()=>{i(e)},mustExec:!1}),w(this,re,bf).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){Ot._keyboardManager.exec(this,e)}editorDivFocus(e){this.isEditing=!0}editorDivBlur(e){this.isEditing=!1}editorDivInput(e){this.parent.div.classList.toggle("freetextEditing",this.isEmpty())}disableEditing(){this.editorDiv.setAttribute("role","comment"),this.editorDiv.removeAttribute("aria-multiline")}enableEditing(){this.editorDiv.setAttribute("role","textbox"),this.editorDiv.setAttribute("aria-multiline",!0)}render(){if(this.div)return this.div;let e,s;this.width&&(e=this.x,s=this.y),super.render(),this.editorDiv=document.createElement("div"),this.editorDiv.className="internal",this.editorDiv.setAttribute("id",l(this,kc)),this.editorDiv.setAttribute("data-l10n-id","pdfjs-free-text2"),this.editorDiv.setAttribute("data-l10n-attrs","default-content"),this.enableEditing(),this.editorDiv.contentEditable=!0;const{style:i}=this.editorDiv;if(i.fontSize=`calc(${l(this,Ts)}px * var(--scale-factor))`,i.color=l(this,di),this.div.append(this.editorDiv),this.overlayDiv=document.createElement("div"),this.overlayDiv.classList.add("overlay","enabled"),this.div.append(this.overlayDiv),bd(this,this.div,["dblclick","keydown"]),this.width){const[n,r]=this.parentDimensions;if(this.annotationElementId){const{position:o}=this._initialData;let[h,c]=this.getInitialTranslation();[h,c]=this.pageTranslationToScreen(h,c);const[u,d]=this.pageDimensions,[f,g]=this.pageTranslation;let p,m;switch(this.rotation){case 0:p=e+(o[0]-f)/u,m=s+this.height-(o[1]-g)/d;break;case 90:p=e+(o[0]-f)/u,m=s-(o[1]-g)/d,[h,c]=[c,-h];break;case 180:p=e-this.width+(o[0]-f)/u,m=s-(o[1]-g)/d,[h,c]=[-h,-c];break;case 270:p=e+(o[0]-f-this.height*d)/u,m=s+(o[1]-g-this.width*u)/d,[h,c]=[-c,h];break}this.setAt(p*n,m*r,h,c)}else this.setAt(e*n,s*r,this.width*n,this.height*r);w(this,re,_f).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,y;const s=e.clipboardData||window.clipboardData,{types:i}=s;if(i.length===1&&i[0]==="text/plain")return;e.preventDefault();const n=w(p=Ot,On,nm).call(p,s.getData("text")||"").replaceAll(Td,`
537
+ `);if(!n)return;const r=window.getSelection();if(!r.rangeCount)return;this.editorDiv.normalize(),r.deleteFromDocument();const o=r.getRangeAt(0);if(!n.includes(`
538
+ `)){o.insertNode(document.createTextNode(n)),this.editorDiv.normalize(),r.collapseToStart();return}const{startContainer:h,startOffset:c}=o,u=[],d=[];if(h.nodeType===Node.TEXT_NODE){const b=h.parentElement;if(d.push(h.nodeValue.slice(c).replaceAll(Td,"")),b!==this.editorDiv){let x=u;for(const C of this.editorDiv.childNodes){if(C===b){x=d;continue}x.push(w(m=Ot,On,yf).call(m,C))}}u.push(h.nodeValue.slice(0,c).replaceAll(Td,""))}else if(h===this.editorDiv){let b=u,x=0;for(const C of this.editorDiv.childNodes)x++===c&&(b=d),b.push(w(y=Ot,On,yf).call(y,C))}v(this,As,`${u.join(`
533
539
  `)}${n}${d.join(`
534
- `)}`),w(this,re,bf).call(this);const f=new Range;let g=u.reduce((b,x)=>b+x.length,0);for(const{firstChild:b}of this.editorDiv.childNodes)if(b.nodeType===Node.TEXT_NODE){const x=b.nodeValue.length;if(g<=x){f.setStart(b,g),f.setEnd(b,g);break}g-=x}r.removeAllRanges(),r.addRange(f)}get contentDiv(){return this.editorDiv}static async deserialize(e,s,i){var a;let n=null;if(e instanceof mb){const{data:{defaultAppearanceData:{fontSize:h,fontColor:c},rect:u,rotation:d,id:f,popupRef:g},textContent:p,textPosition:m,parent:{page:{pageNumber:y}}}=e;if(!p||p.length===0)return null;n=e={annotationType:ot.FREETEXT,color:Array.from(c),fontSize:h,value:p.join(`
535
- `),position:m,pageIndex:y-1,rect:u.slice(0),rotation:d,id:f,deleted:!1,popupRef:g}}const r=await super.deserialize(e,s,i);return v(r,Ts,e.fontSize),v(r,fi,q.makeHexColor(...e.color)),v(r,As,w(a=Mt,Pn,em).call(a,e.value)),r.annotationElementId=e.id||null,r._initialData=n,r}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const s=Mt._internalPadding*this.parentScale,i=this.getRect(s,s),n=Vt._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:l(this,fi)),r={annotationType:ot.FREETEXT,color:n,fontSize:l(this,Ts),value:w(this,re,jy).call(this),pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?r:this.annotationElementId&&!w(this,re,Ny).call(this,r)?null:(r.id=this.annotationElementId,r)}renderAnnotationElement(e){const s=super.renderAnnotationElement(e);if(this.deleted)return s;const{style:i}=s;i.fontSize=`calc(${l(this,Ts)}px * var(--scale-factor))`,i.color=l(this,fi),s.replaceChildren();for(const r of l(this,As).split(`
536
- `)){const a=document.createElement("div");a.append(r?document.createTextNode(r):document.createElement("br")),s.append(a)}const n=Mt._internalPadding*this.parentScale;return e.updateEdited({rect:this.getRect(n,n),popupContent:l(this,As)}),s}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}};fi=new WeakMap,As=new WeakMap,Ac=new WeakMap,Ha=new WeakMap,Ts=new WeakMap,re=new WeakSet,Fy=function(e){const s=n=>{this.editorDiv.style.fontSize=`calc(${n}px * var(--scale-factor))`,this.translate(0,-(n-l(this,Ts))*this.parentScale),v(this,Ts,n),w(this,re,mf).call(this)},i=l(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:gt.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})},Ly=function(e){const s=n=>{v(this,fi,this.editorDiv.style.color=n)},i=l(this,fi);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:gt.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})},Iy=function(){var i;const e=[];this.editorDiv.normalize();let s=null;for(const n of this.editorDiv.childNodes)(s==null?void 0:s.nodeType)===Node.TEXT_NODE&&n.nodeName==="BR"||(e.push(w(i=Mt,Pn,vf).call(i,n)),s=n);return e.join(`
537
- `)},mf=function(){const[e,s]=this.parentDimensions;let i;if(this.isAttachedToDOM)i=this.div.getBoundingClientRect();else{const{currentLayer:n,div:r}=this,a=r.style.display,h=r.classList.contains("hidden");r.classList.remove("hidden"),r.style.display="hidden",n.div.append(this.div),i=r.getBoundingClientRect(),r.remove(),r.style.display=a,r.classList.toggle("hidden",h)}this.rotation%180===this.parentRotation%180?(this.width=i.width/e,this.height=i.height/s):(this.width=i.height/e,this.height=i.width/s),this.fixAndSetPosition()},Pn=new WeakSet,vf=function(e){return(e.nodeType===Node.TEXT_NODE?e.nodeValue:e.innerText).replaceAll(Cd,"")},bf=function(){if(this.editorDiv.replaceChildren(),!!l(this,As))for(const e of l(this,As).split(`
538
- `)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},jy=function(){return l(this,As).replaceAll(" "," ")},em=function(e){return e.replaceAll(" "," ")},Ny=function(e){const{value:s,fontSize:i,color:n,pageIndex:r}=this._initialData;return this._hasBeenMoved||e.value!==s||e.fontSize!==i||e.color.some((a,h)=>a!==n[h])||e.pageIndex!==r},_(Mt,Pn),Q(Mt,"_freeTextDefaultContent",""),Q(Mt,"_internalPadding",0),Q(Mt,"_defaultColor",null),Q(Mt,"_defaultFontSize",10),Q(Mt,"_type","freetext"),Q(Mt,"_editorType",ot.FREETEXT);let sp=Mt;class U{toSVGPath(){kt("Abstract method `toSVGPath` must be implemented.")}get box(){kt("Abstract getter `box` must be implemented.")}serialize(t,e){kt("Abstract method `serialize` must be implemented.")}static _rescale(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let a=0,h=t.length;a<h;a+=2)r[a]=e+t[a]*i,r[a+1]=s+t[a+1]*n;return r}static _rescaleAndSwap(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let a=0,h=t.length;a<h;a+=2)r[a]=e+t[a+1]*i,r[a+1]=s+t[a]*n;return r}static _translate(t,e,s,i){i||(i=new Float32Array(t.length));for(let n=0,r=t.length;n<r;n+=2)i[n]=e+t[n],i[n+1]=s+t[n+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,s,i,n){switch(n){case 90:return[1-e/s,t/i];case 180:return[1-t/s,1-e/i];case 270:return[e/s,1-t/i];default:return[t/s,e/i]}}static _normalizePagePoint(t,e,s){switch(s){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}static createBezierPoints(t,e,s,i,n,r){return[(t+5*s)/6,(e+5*i)/6,(5*s+n)/6,(5*i+r)/6,(s+n)/2,(i+r)/2]}}Q(U,"PRECISION",1e-4);const Mn=class Mn{constructor({x:t,y:e},s,i,n,r,a=0){_(this,de);_(this,Es);_(this,gi,[]);_(this,uh);_(this,dh);_(this,Bi,[]);_(this,ut,new Float32Array(18));_(this,za);_(this,Va);_(this,Tc);_(this,Ec);_(this,fh);_(this,gh);_(this,br,[]);v(this,Es,s),v(this,gh,n*i),v(this,dh,r),l(this,ut).set([NaN,NaN,NaN,NaN,t,e],6),v(this,uh,a),v(this,Ec,l(Mn,kc)*i),v(this,Tc,l(Mn,Gd)*i),v(this,fh,i),l(this,br).push(t,e)}isEmpty(){return isNaN(l(this,ut)[8])}add({x:t,y:e}){var R;v(this,za,t),v(this,Va,e);const[s,i,n,r]=l(this,Es);let[a,h,c,u]=l(this,ut).subarray(8,12);const d=t-c,f=e-u,g=Math.hypot(d,f);if(g<l(this,Tc))return!1;const p=g-l(this,Ec),m=p/g,y=m*d,b=m*f;let x=a,S=h;a=c,h=u,c+=y,u+=b,(R=l(this,br))==null||R.push(t,e);const C=-b/p,k=y/p,O=C*l(this,gh),P=k*l(this,gh);return l(this,ut).set(l(this,ut).subarray(2,8),0),l(this,ut).set([c+O,u+P],4),l(this,ut).set(l(this,ut).subarray(14,18),12),l(this,ut).set([c-O,u-P],16),isNaN(l(this,ut)[6])?(l(this,Bi).length===0&&(l(this,ut).set([a+O,h+P],2),l(this,Bi).push(NaN,NaN,NaN,NaN,(a+O-s)/n,(h+P-i)/r),l(this,ut).set([a-O,h-P],14),l(this,gi).push(NaN,NaN,NaN,NaN,(a-O-s)/n,(h-P-i)/r)),l(this,ut).set([x,S,a,h,c,u],6),!this.isEmpty()):(l(this,ut).set([x,S,a,h,c,u],6),Math.abs(Math.atan2(S-h,x-a)-Math.atan2(b,y))<Math.PI/2?([a,h,c,u]=l(this,ut).subarray(2,6),l(this,Bi).push(NaN,NaN,NaN,NaN,((a+c)/2-s)/n,((h+u)/2-i)/r),[a,h,x,S]=l(this,ut).subarray(14,18),l(this,gi).push(NaN,NaN,NaN,NaN,((x+a)/2-s)/n,((S+h)/2-i)/r),!0):([x,S,a,h,c,u]=l(this,ut).subarray(0,6),l(this,Bi).push(((x+5*a)/6-s)/n,((S+5*h)/6-i)/r,((5*a+c)/6-s)/n,((5*h+u)/6-i)/r,((a+c)/2-s)/n,((h+u)/2-i)/r),[c,u,a,h,x,S]=l(this,ut).subarray(12,18),l(this,gi).push(((x+5*a)/6-s)/n,((S+5*h)/6-i)/r,((5*a+c)/6-s)/n,((5*h+u)/6-i)/r,((a+c)/2-s)/n,((h+u)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=l(this,Bi),e=l(this,gi);if(isNaN(l(this,ut)[6])&&!this.isEmpty())return w(this,de,By).call(this);const s=[];s.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)isNaN(t[i])?s.push(`L${t[i+4]} ${t[i+5]}`):s.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);w(this,de,zy).call(this,s);for(let i=e.length-6;i>=6;i-=6)isNaN(e[i])?s.push(`L${e[i+4]} ${e[i+5]}`):s.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return w(this,de,Hy).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new _b(t,e,s,i,n,r)}getOutlines(){var d;const t=l(this,Bi),e=l(this,gi),s=l(this,ut),[i,n,r,a]=l(this,Es),h=new Float32Array((((d=l(this,br))==null?void 0:d.length)??0)+2);for(let f=0,g=h.length-2;f<g;f+=2)h[f]=(l(this,br)[f]-i)/r,h[f+1]=(l(this,br)[f+1]-n)/a;if(h[h.length-2]=(l(this,za)-i)/r,h[h.length-1]=(l(this,Va)-n)/a,isNaN(s[6])&&!this.isEmpty())return w(this,de,Vy).call(this,h);const c=new Float32Array(l(this,Bi).length+24+l(this,gi).length);let u=t.length;for(let f=0;f<u;f+=2){if(isNaN(t[f])){c[f]=c[f+1]=NaN;continue}c[f]=t[f],c[f+1]=t[f+1]}u=w(this,de,Gy).call(this,c,u);for(let f=e.length-6;f>=6;f-=6)for(let g=0;g<6;g+=2){if(isNaN(e[f+g])){c[u]=c[u+1]=NaN,u+=2;continue}c[u]=e[f+g],c[u+1]=e[f+g+1],u+=2}return w(this,de,Wy).call(this,c,u),this.newFreeDrawOutline(c,h,l(this,Es),l(this,fh),l(this,uh),l(this,dh))}};Es=new WeakMap,gi=new WeakMap,uh=new WeakMap,dh=new WeakMap,Bi=new WeakMap,ut=new WeakMap,za=new WeakMap,Va=new WeakMap,Tc=new WeakMap,Ec=new WeakMap,fh=new WeakMap,gh=new WeakMap,br=new WeakMap,kc=new WeakMap,Wd=new WeakMap,Gd=new WeakMap,de=new WeakSet,eu=function(){const t=l(this,ut).subarray(4,6),e=l(this,ut).subarray(16,18),[s,i,n,r]=l(this,Es);return[(l(this,za)+(t[0]-e[0])/2-s)/n,(l(this,Va)+(t[1]-e[1])/2-i)/r,(l(this,za)+(e[0]-t[0])/2-s)/n,(l(this,Va)+(e[1]-t[1])/2-i)/r]},By=function(){const[t,e,s,i]=l(this,Es),[n,r,a,h]=w(this,de,eu).call(this);return`M${(l(this,ut)[2]-t)/s} ${(l(this,ut)[3]-e)/i} L${(l(this,ut)[4]-t)/s} ${(l(this,ut)[5]-e)/i} L${n} ${r} L${a} ${h} L${(l(this,ut)[16]-t)/s} ${(l(this,ut)[17]-e)/i} L${(l(this,ut)[14]-t)/s} ${(l(this,ut)[15]-e)/i} Z`},Hy=function(t){const e=l(this,gi);t.push(`L${e[4]} ${e[5]} Z`)},zy=function(t){const[e,s,i,n]=l(this,Es),r=l(this,ut).subarray(4,6),a=l(this,ut).subarray(16,18),[h,c,u,d]=w(this,de,eu).call(this);t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${h} ${c} L${u} ${d} L${(a[0]-e)/i} ${(a[1]-s)/n}`)},Vy=function(t){const e=l(this,ut),[s,i,n,r]=l(this,Es),[a,h,c,u]=w(this,de,eu).call(this),d=new Float32Array(36);return d.set([NaN,NaN,NaN,NaN,(e[2]-s)/n,(e[3]-i)/r,NaN,NaN,NaN,NaN,(e[4]-s)/n,(e[5]-i)/r,NaN,NaN,NaN,NaN,a,h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,(e[16]-s)/n,(e[17]-i)/r,NaN,NaN,NaN,NaN,(e[14]-s)/n,(e[15]-i)/r],0),this.newFreeDrawOutline(d,t,l(this,Es),l(this,fh),l(this,uh),l(this,dh))},Wy=function(t,e){const s=l(this,gi);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},Gy=function(t,e){const s=l(this,ut).subarray(4,6),i=l(this,ut).subarray(16,18),[n,r,a,h]=l(this,Es),[c,u,d,f]=w(this,de,eu).call(this);return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/a,(s[1]-r)/h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,d,f,NaN,NaN,NaN,NaN,(i[0]-n)/a,(i[1]-r)/h],e),e+=24},_(Mn,kc,8),_(Mn,Wd,2),_(Mn,Gd,l(Mn,kc)+l(Mn,Wd));let Ad=Mn;class _b extends U{constructor(e,s,i,n,r,a){super();_(this,Xd);_(this,ph);_(this,Wa,new Float32Array(4));_(this,On);_(this,Pc);_(this,ks);_(this,Mc);_(this,Qt);v(this,Qt,e),v(this,ks,s),v(this,ph,i),v(this,Mc,n),v(this,On,r),v(this,Pc,a),this.lastPoint=[NaN,NaN],w(this,Xd,Xy).call(this,a);const[h,c,u,d]=l(this,Wa);for(let f=0,g=e.length;f<g;f+=2)e[f]=(e[f]-h)/u,e[f+1]=(e[f+1]-c)/d;for(let f=0,g=s.length;f<g;f+=2)s[f]=(s[f]-h)/u,s[f+1]=(s[f+1]-c)/d}toSVGPath(){const e=[`M${l(this,Qt)[4]} ${l(this,Qt)[5]}`];for(let s=6,i=l(this,Qt).length;s<i;s+=6){if(isNaN(l(this,Qt)[s])){e.push(`L${l(this,Qt)[s+4]} ${l(this,Qt)[s+5]}`);continue}e.push(`C${l(this,Qt)[s]} ${l(this,Qt)[s+1]} ${l(this,Qt)[s+2]} ${l(this,Qt)[s+3]} ${l(this,Qt)[s+4]} ${l(this,Qt)[s+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,s,i,n],r){const a=i-e,h=n-s;let c,u;switch(r){case 0:c=U._rescale(l(this,Qt),e,n,a,-h),u=U._rescale(l(this,ks),e,n,a,-h);break;case 90:c=U._rescaleAndSwap(l(this,Qt),e,s,a,h),u=U._rescaleAndSwap(l(this,ks),e,s,a,h);break;case 180:c=U._rescale(l(this,Qt),i,s,-a,h),u=U._rescale(l(this,ks),i,s,-a,h);break;case 270:c=U._rescaleAndSwap(l(this,Qt),i,n,-a,-h),u=U._rescaleAndSwap(l(this,ks),i,n,-a,-h);break}return{outline:Array.from(c),points:[Array.from(u)]}}get box(){return l(this,Wa)}newOutliner(e,s,i,n,r,a=0){return new Ad(e,s,i,n,r,a)}getNewOutline(e,s){const[i,n,r,a]=l(this,Wa),[h,c,u,d]=l(this,ph),f=r*u,g=a*d,p=i*u+h,m=n*d+c,y=this.newOutliner({x:l(this,ks)[0]*f+p,y:l(this,ks)[1]*g+m},l(this,ph),l(this,Mc),e,l(this,Pc),s??l(this,On));for(let b=2;b<l(this,ks).length;b+=2)y.add({x:l(this,ks)[b]*f+p,y:l(this,ks)[b+1]*g+m});return y.getOutlines()}}ph=new WeakMap,Wa=new WeakMap,On=new WeakMap,Pc=new WeakMap,ks=new WeakMap,Mc=new WeakMap,Qt=new WeakMap,Xd=new WeakSet,Xy=function(e){const s=l(this,Qt);let i=s[4],n=s[5],r=i,a=n,h=i,c=n,u=i,d=n;const f=e?Math.max:Math.min;for(let p=6,m=s.length;p<m;p+=6){if(isNaN(s[p]))r=Math.min(r,s[p+4]),a=Math.min(a,s[p+5]),h=Math.max(h,s[p+4]),c=Math.max(c,s[p+5]),d<s[p+5]?(u=s[p+4],d=s[p+5]):d===s[p+5]&&(u=f(u,s[p+4]));else{const y=q.bezierBoundingBox(i,n,...s.slice(p,p+6));r=Math.min(r,y[0]),a=Math.min(a,y[1]),h=Math.max(h,y[2]),c=Math.max(c,y[3]),d<y[3]?(u=y[2],d=y[3]):d===y[3]&&(u=f(u,y[2]))}i=s[p+4],n=s[p+5]}const g=l(this,Wa);g[0]=r-l(this,On),g[1]=a-l(this,On),g[2]=h-r+2*l(this,On),g[3]=c-a+2*l(this,On),this.lastPoint=[u,d]};class ip{constructor(t,e=0,s=0,i=!0){_(this,qe);_(this,Oc);_(this,Dc);_(this,yr,[]);_(this,pi,[]);let n=1/0,r=-1/0,a=1/0,h=-1/0;const c=10**-4;for(const{x:y,y:b,width:x,height:S}of t){const C=Math.floor((y-e)/c)*c,k=Math.ceil((y+x+e)/c)*c,O=Math.floor((b-e)/c)*c,P=Math.ceil((b+S+e)/c)*c,D=[C,O,P,!0],R=[k,O,P,!1];l(this,yr).push(D,R),n=Math.min(n,C),r=Math.max(r,k),a=Math.min(a,O),h=Math.max(h,P)}const u=r-n+2*s,d=h-a+2*s,f=n-s,g=a-s,p=l(this,yr).at(i?-1:-2),m=[p[0],p[2]];for(const y of l(this,yr)){const[b,x,S]=y;y[0]=(b-f)/u,y[1]=(x-g)/d,y[2]=(S-g)/d}v(this,Oc,new Float32Array([f,g,u,d])),v(this,Dc,m)}getOutlines(){l(this,yr).sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of l(this,yr))e[3]?(t.push(...w(this,qe,sm).call(this,e)),w(this,qe,Yy).call(this,e)):(w(this,qe,$y).call(this,e),t.push(...w(this,qe,sm).call(this,e)));return w(this,qe,Uy).call(this,t)}}Oc=new WeakMap,Dc=new WeakMap,yr=new WeakMap,pi=new WeakMap,qe=new WeakSet,Uy=function(t){const e=[],s=new Set;for(const r of t){const[a,h,c]=r;e.push([a,h,r],[a,c,r])}e.sort((r,a)=>r[1]-a[1]||r[0]-a[0]);for(let r=0,a=e.length;r<a;r+=2){const h=e[r][2],c=e[r+1][2];h.push(c),c.push(h),s.add(h),s.add(c)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[a,h,c,u,d]=r;s.delete(r);let f=a,g=h;for(n=[a,c],i.push(n);;){let p;if(s.has(u))p=u;else if(s.has(d))p=d;else break;s.delete(p),[a,h,c,u,d]=p,f!==a&&(n.push(f,g,a,g===h?h:c),f=a),g=g===h?c:h}n.push(f,g)}return new KC(i,l(this,Oc),l(this,Dc))},yf=function(t){const e=l(this,pi);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},Yy=function([,t,e]){const s=w(this,qe,yf).call(this,t);l(this,pi).splice(s,0,[t,e])},$y=function([,t,e]){const s=w(this,qe,yf).call(this,t);for(let i=s;i<l(this,pi).length;i++){const[n,r]=l(this,pi)[i];if(n!==t)break;if(n===t&&r===e){l(this,pi).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=l(this,pi)[i];if(n!==t)break;if(n===t&&r===e){l(this,pi).splice(i,1);return}}},sm=function(t){const[e,s,i]=t,n=[[e,s,i]],r=w(this,qe,yf).call(this,i);for(let a=0;a<r;a++){const[h,c]=l(this,pi)[a];for(let u=0,d=n.length;u<d;u++){const[,f,g]=n[u];if(!(c<=f||g<=h)){if(f>=h){if(g>c)n[u][1]=c;else{if(d===1)return[];n.splice(u,1),u--,d--}continue}n[u][2]=h,g>c&&n.push([e,c,g])}}}return n};class KC extends U{constructor(e,s,i){super();_(this,Rc);_(this,mh);v(this,mh,e),v(this,Rc,s),this.lastPoint=i}toSVGPath(){const e=[];for(const s of l(this,mh)){let[i,n]=s;e.push(`M${i} ${n}`);for(let r=2;r<s.length;r+=2){const a=s[r],h=s[r+1];a===i?(e.push(`V${h}`),n=h):h===n&&(e.push(`H${a}`),i=a)}e.push("Z")}return e.join(" ")}serialize([e,s,i,n],r){const a=[],h=i-e,c=n-s;for(const u of l(this,mh)){const d=new Array(u.length);for(let f=0;f<u.length;f+=2)d[f]=e+u[f]*h,d[f+1]=n-u[f+1]*c;a.push(d)}return a}get box(){return l(this,Rc)}get classNamesForOutlining(){return["highlightOutline"]}}Rc=new WeakMap,mh=new WeakMap;class np extends Ad{newFreeDrawOutline(t,e,s,i,n,r){return new JC(t,e,s,i,n,r)}}class JC extends _b{newOutliner(t,e,s,i,n,r=0){return new np(t,e,s,i,n,r)}}const us=class us{constructor({editor:t=null,uiManager:e=null}){_(this,Et);_(this,mi,null);_(this,Ga,null);_(this,vh);_(this,fe,null);_(this,Fc,!1);_(this,bh,!1);_(this,Lc,null);_(this,Ic);_(this,_r,null);_(this,vi,null);_(this,yh);var s;t?(v(this,bh,!1),v(this,yh,gt.HIGHLIGHT_COLOR),v(this,Lc,t)):(v(this,bh,!0),v(this,yh,gt.HIGHLIGHT_DEFAULT_COLOR)),v(this,vi,(t==null?void 0:t._uiManager)||e),v(this,Ic,l(this,vi)._eventBus),v(this,vh,(t==null?void 0:t.color)||((s=l(this,vi))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),l(us,jc)||v(us,jc,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 ct(this,"_keyboardManager",new dl([[["Escape","mac+Escape"],us.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],us.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],us.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],us.prototype._moveToPrevious],[["Home","mac+Home"],us.prototype._moveToBeginning],[["End","mac+End"],us.prototype._moveToEnd]]))}renderButton(){const t=v(this,mi,document.createElement("button"));t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.setAttribute("aria-haspopup",!0);const e=l(this,vi)._signal;t.addEventListener("click",w(this,Et,oo).bind(this),{signal:e}),t.addEventListener("keydown",w(this,Et,rm).bind(this),{signal:e});const s=v(this,Ga,document.createElement("span"));return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=l(this,vh),t.append(s),t}renderMainDropdown(){const t=v(this,fe,w(this,Et,im).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===l(this,mi)){w(this,Et,oo).call(this,t);return}const e=t.target.getAttribute("data-color");e&&w(this,Et,nm).call(this,e,t)}_moveToNext(t){var e,s;if(!l(this,Et,Or)){w(this,Et,oo).call(this,t);return}if(t.target===l(this,mi)){(e=l(this,fe).firstChild)==null||e.focus();return}(s=t.target.nextSibling)==null||s.focus()}_moveToPrevious(t){var e,s;if(t.target===((e=l(this,fe))==null?void 0:e.firstChild)||t.target===l(this,mi)){l(this,Et,Or)&&this._hideDropdownFromKeyboard();return}l(this,Et,Or)||w(this,Et,oo).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!l(this,Et,Or)){w(this,Et,oo).call(this,t);return}(e=l(this,fe).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!l(this,Et,Or)){w(this,Et,oo).call(this,t);return}(e=l(this,fe).lastChild)==null||e.focus()}hideDropdown(){var t,e;(t=l(this,fe))==null||t.classList.add("hidden"),(e=l(this,_r))==null||e.abort(),v(this,_r,null)}_hideDropdownFromKeyboard(){var t;if(!l(this,bh)){if(!l(this,Et,Or)){(t=l(this,Lc))==null||t.unselect();return}this.hideDropdown(),l(this,mi).focus({preventScroll:!0,focusVisible:l(this,Fc)})}}updateColor(t){if(l(this,Ga)&&(l(this,Ga).style.backgroundColor=t),!l(this,fe))return;const e=l(this,vi).highlightColors.values();for(const s of l(this,fe).children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){var t,e;(t=l(this,mi))==null||t.remove(),v(this,mi,null),v(this,Ga,null),(e=l(this,fe))==null||e.remove(),v(this,fe,null)}};mi=new WeakMap,Ga=new WeakMap,vh=new WeakMap,fe=new WeakMap,Fc=new WeakMap,bh=new WeakMap,Lc=new WeakMap,Ic=new WeakMap,_r=new WeakMap,vi=new WeakMap,yh=new WeakMap,jc=new WeakMap,Et=new WeakSet,im=function(){const t=document.createElement("div"),e=l(this,vi)._signal;t.addEventListener("contextmenu",ri,{signal:e}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[s,i]of l(this,vi).highlightColors){const n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",l(us,jc)[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===l(this,vh)),n.addEventListener("click",w(this,Et,nm).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",w(this,Et,rm).bind(this),{signal:e}),t},nm=function(t,e){e.stopPropagation(),l(this,Ic).dispatch("switchannotationeditorparams",{source:this,type:l(this,yh),value:t})},rm=function(t){us._keyboardManager.exec(this,t)},oo=function(t){if(l(this,Et,Or)){this.hideDropdown();return}if(v(this,Fc,t.detail===0),l(this,_r)||(v(this,_r,new AbortController),window.addEventListener("pointerdown",w(this,Et,qy).bind(this),{signal:l(this,vi).combinedSignal(l(this,_r))})),l(this,fe)){l(this,fe).classList.remove("hidden");return}const e=v(this,fe,w(this,Et,im).call(this));l(this,mi).append(e)},qy=function(t){var e;(e=l(this,fe))!=null&&e.contains(t.target)||this.hideDropdown()},Or=function(){return l(this,fe)&&!l(this,fe).classList.contains("hidden")},_(us,jc,null);let Td=us;const yt=class yt extends Vt{constructor(e){super({...e,name:"highlightEditor"});_(this,at);_(this,_h,null);_(this,Nc,0);_(this,Dn);_(this,Xa,null);_(this,wh,null);_(this,ds,null);_(this,Bc,null);_(this,Hc,0);_(this,Ua,null);_(this,Ws,null);_(this,Ps,null);_(this,xe,!1);_(this,xh,null);_(this,Rn);_(this,Ie,null);_(this,Sh,"");_(this,Gs);_(this,zc,"");this.color=e.color||yt._defaultColor,v(this,Gs,e.thickness||yt._defaultThickness),v(this,Rn,e.opacity||yt._defaultOpacity),v(this,Dn,e.boxes||null),v(this,zc,e.methodOfCreation||""),v(this,Sh,e.text||""),this._isDraggable=!1,e.highlightId>-1?(v(this,xe,!0),w(this,at,_f).call(this,e),w(this,at,ho).call(this)):l(this,Dn)&&(v(this,_h,e.anchorNode),v(this,Nc,e.anchorOffset),v(this,Bc,e.focusNode),v(this,Hc,e.focusOffset),w(this,at,am).call(this),w(this,at,ho).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=yt.prototype;return ct(this,"_keyboardManager",new dl([[["ArrowLeft","mac+ArrowLeft"],e._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],e._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],e._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],e._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:l(this,xe)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:l(this,Gs),methodOfCreation:l(this,zc)}}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;Vt.initialize(e,s),yt._defaultColor||(yt._defaultColor=((i=s.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,s){switch(e){case gt.HIGHLIGHT_DEFAULT_COLOR:yt._defaultColor=s;break;case gt.HIGHLIGHT_THICKNESS:yt._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return l(this,xh)}updateParams(e,s){switch(e){case gt.HIGHLIGHT_COLOR:w(this,at,Ky).call(this,s);break;case gt.HIGHLIGHT_THICKNESS:w(this,at,Jy).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[gt.HIGHLIGHT_DEFAULT_COLOR,yt._defaultColor],[gt.HIGHLIGHT_THICKNESS,yt._defaultThickness]]}get propertiesToUpdate(){return[[gt.HIGHLIGHT_COLOR,this.color||yt._defaultColor],[gt.HIGHLIGHT_THICKNESS,l(this,Gs)||yt._defaultThickness],[gt.HIGHLIGHT_FREE,l(this,xe)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(v(this,wh,new Td({editor:this})),e.addColorPicker(l(this,wh))),e):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(w(this,at,su).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,w(this,at,su).call(this))}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),e&&this.div.focus()}remove(){w(this,at,om).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,at,ho).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?w(this,at,om).call(this):e&&(w(this,at,ho).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),this.show(this._isVisible),s&&this.select()}rotate(e){var n,r,a;const{drawLayer:s}=this.parent;let i;l(this,xe)?(e=(e-this.rotation+360)%360,i=w(n=yt,Xs,Vh).call(n,l(this,Ws).box,e)):i=w(r=yt,Xs,Vh).call(r,[this.x,this.y,this.width,this.height],e),s.updateProperties(l(this,Ps),{bbox:i,root:{"data-main-rotation":e}}),s.updateProperties(l(this,Ie),{bbox:w(a=yt,Xs,Vh).call(a,l(this,ds).box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();l(this,Sh)&&(e.setAttribute("aria-label",l(this,Sh)),e.setAttribute("role","mark")),l(this,xe)?e.classList.add("free"):this.div.addEventListener("keydown",w(this,at,Zy).bind(this),{signal:this._uiManager._signal});const s=v(this,Ua,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=l(this,Xa);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),md(this,l(this,Ua),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Ie),{rootClass:{hovered:!0}})}pointerleave(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Ie),{rootClass:{hovered:!1}})}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:w(this,at,wf).call(this,!0);break;case 1:case 3:w(this,at,wf).call(this,!1);break}}select(){var e;super.select(),l(this,Ie)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Ie),{rootClass:{hovered:!1,selected:!0}}))}unselect(){var e;super.unselect(),l(this,Ie)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Ie),{rootClass:{selected:!1}}),l(this,xe)||w(this,at,wf).call(this,!1))}get _mustFixPosition(){return!l(this,xe)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(l(this,Ps),{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(l(this,Ie),{rootClass:{hidden:!e}}))}static startHighlighting(e,s,{target:i,x:n,y:r}){const{x:a,y:h,width:c,height:u}=i.getBoundingClientRect(),d=new AbortController,f=e.combinedSignal(d),g=p=>{d.abort(),w(this,Xs,i_).call(this,e,p)};window.addEventListener("blur",g,{signal:f}),window.addEventListener("pointerup",g,{signal:f}),window.addEventListener("pointerdown",bs,{capture:!0,passive:!1,signal:f}),window.addEventListener("contextmenu",ri,{signal:f}),i.addEventListener("pointermove",w(this,Xs,s_).bind(this,e),{signal:f}),this._freeHighlight=new np({x:n,y:r},[a,h,c,u],e.scale,this._defaultThickness/2,s,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static async deserialize(e,s,i){var m,y,b,x;let n=null;if(e instanceof bb){const{data:{quadPoints:S,rect:C,rotation:k,id:O,color:P,opacity:D,popupRef:R},parent:{page:{pageNumber:z}}}=e;n=e={annotationType:ot.HIGHLIGHT,color:Array.from(P),opacity:D,quadPoints:S,boxes:null,pageIndex:z-1,rect:C.slice(0),rotation:k,id:O,deleted:!1,popupRef:R}}else if(e instanceof ep){const{data:{inkLists:S,rect:C,rotation:k,id:O,color:P,borderStyle:{rawWidth:D},popupRef:R},parent:{page:{pageNumber:z}}}=e;n=e={annotationType:ot.HIGHLIGHT,color:Array.from(P),thickness:D,inkLists:S,boxes:null,pageIndex:z-1,rect:C.slice(0),rotation:k,id:O,deleted:!1,popupRef:R}}const{color:r,quadPoints:a,inkLists:h,opacity:c}=e,u=await super.deserialize(e,s,i);u.color=q.makeHexColor(...r),v(u,Rn,c||1),h&&v(u,Gs,e.thickness),u.annotationElementId=e.id||null,u._initialData=n;const[d,f]=u.pageDimensions,[g,p]=u.pageTranslation;if(a){const S=v(u,Dn,[]);for(let C=0;C<a.length;C+=8)S.push({x:(a[C]-g)/d,y:1-(a[C+1]-p)/f,width:(a[C+2]-a[C])/d,height:(a[C+1]-a[C+5])/f});w(m=u,at,am).call(m),w(y=u,at,ho).call(y),u.rotate(u.rotation)}else if(h){v(u,xe,!0);const S=h[0],C={x:S[0]-g,y:f-(S[1]-p)},k=new np(C,[0,0,d,f],1,l(u,Gs)/2,!0,.001);for(let D=0,R=S.length;D<R;D+=2)C.x=S[D]-g,C.y=f-(S[D+1]-p),k.add(C);const{id:O,clipPathId:P}=s.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:u.color,"fill-opacity":u._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:k.toSVGPath()}},!0,!0);w(b=u,at,_f).call(b,{highlightOutlines:k.getOutlines(),highlightId:O,clipPathId:P}),w(x=u,at,ho).call(x)}return u}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();const s=this.getRect(0,0),i=Vt._colorManager.convert(this.color),n={annotationType:ot.HIGHLIGHT,color:i,opacity:l(this,Rn),thickness:l(this,Gs),quadPoints:w(this,at,t_).call(this),outlines:w(this,at,e_).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:w(this,at,su).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!w(this,at,n_).call(this,n)?null:(n.id=this.annotationElementId,n)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};_h=new WeakMap,Nc=new WeakMap,Dn=new WeakMap,Xa=new WeakMap,wh=new WeakMap,ds=new WeakMap,Bc=new WeakMap,Hc=new WeakMap,Ua=new WeakMap,Ws=new WeakMap,Ps=new WeakMap,xe=new WeakMap,xh=new WeakMap,Rn=new WeakMap,Ie=new WeakMap,Sh=new WeakMap,Gs=new WeakMap,zc=new WeakMap,at=new WeakSet,am=function(){const e=new ip(l(this,Dn),.001);v(this,Ws,e.getOutlines()),[this.x,this.y,this.width,this.height]=l(this,Ws).box;const s=new ip(l(this,Dn),.0025,.001,this._uiManager.direction==="ltr");v(this,ds,s.getOutlines());const{lastPoint:i}=l(this,ds);v(this,xh,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height])},_f=function({highlightOutlines:e,highlightId:s,clipPathId:i}){var d,f;if(v(this,Ws,e),v(this,ds,e.getNewOutline(l(this,Gs)/2+1.5,.0025)),s>=0)v(this,Ps,s),v(this,Xa,i),this.parent.drawLayer.finalizeDraw(s,{bbox:e.box,path:{d:e.toSVGPath()}}),v(this,Ie,this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:l(this,ds).box,path:{d:l(this,ds).toSVGPath()}},!0));else if(this.parent){const g=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(l(this,Ps),{bbox:w(d=yt,Xs,Vh).call(d,l(this,Ws).box,(g-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(l(this,Ie),{bbox:w(f=yt,Xs,Vh).call(f,l(this,ds).box,g),path:{d:l(this,ds).toSVGPath()}})}const[r,a,h,c]=e.box;switch(this.rotation){case 0:this.x=r,this.y=a,this.width=h,this.height=c;break;case 90:{const[g,p]=this.parentDimensions;this.x=a,this.y=1-r,this.width=h*p/g,this.height=c*g/p;break}case 180:this.x=1-r,this.y=1-a,this.width=h,this.height=c;break;case 270:{const[g,p]=this.parentDimensions;this.x=1-a,this.y=r,this.width=h*p/g,this.height=c*g/p;break}}const{lastPoint:u}=l(this,ds);v(this,xh,[(u[0]-r)/h,(u[1]-a)/c])},Ky=function(e){const s=(r,a)=>{var h,c;this.color=r,v(this,Rn,a),(h=this.parent)==null||h.drawLayer.updateProperties(l(this,Ps),{root:{fill:r,"fill-opacity":a}}),(c=l(this,wh))==null||c.updateColor(r)},i=this.color,n=l(this,Rn);this.addCommands({cmd:s.bind(this,e,yt._defaultOpacity),undo:s.bind(this,i,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:gt.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},Jy=function(e){const s=l(this,Gs),i=n=>{v(this,Gs,n),w(this,at,Qy).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:gt.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},Qy=function(e){if(!l(this,xe))return;w(this,at,_f).call(this,{highlightOutlines:l(this,Ws).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},om=function(){l(this,Ps)===null||!this.parent||(this.parent.drawLayer.remove(l(this,Ps)),v(this,Ps,null),this.parent.drawLayer.remove(l(this,Ie)),v(this,Ie,null))},ho=function(e=this.parent){l(this,Ps)===null&&({id:es(this,Ps)._,clipPathId:es(this,Xa)._}=e.drawLayer.draw({bbox:l(this,Ws).box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":l(this,Rn)},rootClass:{highlight:!0,free:l(this,xe)},path:{d:l(this,Ws).toSVGPath()}},!1,!0),v(this,Ie,e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:l(this,xe)},bbox:l(this,ds).box,path:{d:l(this,ds).toSVGPath()}},l(this,xe))),l(this,Ua)&&(l(this,Ua).style.clipPath=l(this,Xa)))},Xs=new WeakSet,Vh=function([e,s,i,n],r){switch(r){case 90:return[1-s-n,e,n,i];case 180:return[1-e-i,1-s-n,i,n];case 270:return[s,1-e-i,n,i]}return[e,s,i,n]},Zy=function(e){yt._keyboardManager.exec(this,e)},wf=function(e){if(!l(this,_h))return;const s=window.getSelection();e?s.setPosition(l(this,_h),l(this,Nc)):s.setPosition(l(this,Bc),l(this,Hc))},su=function(){return l(this,xe)?this.rotation:0},t_=function(){if(l(this,xe))return null;const[e,s]=this.pageDimensions,[i,n]=this.pageTranslation,r=l(this,Dn),a=new Float32Array(r.length*8);let h=0;for(const{x:c,y:u,width:d,height:f}of r){const g=c*e+i,p=(1-u)*s+n;a[h]=a[h+4]=g,a[h+1]=a[h+3]=p,a[h+2]=a[h+6]=g+d*e,a[h+5]=a[h+7]=p-f*s,h+=8}return a},e_=function(e){return l(this,Ws).serialize(e,w(this,at,su).call(this))},s_=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},i_=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=""},n_=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},_(yt,Xs),Q(yt,"_defaultColor",null),Q(yt,"_defaultOpacity",1),Q(yt,"_defaultThickness",12),Q(yt,"_type","highlight"),Q(yt,"_editorType",ot.HIGHLIGHT),Q(yt,"_freeHighlightId",-1),Q(yt,"_freeHighlight",null),Q(yt,"_freeHighlightClipId","");let Ed=yt;class QC{constructor(){_(this,Ya,Object.create(null))}updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(const[e,s]of Object.entries(t))this.updateProperty(e,s)}updateSVGProperty(t,e){l(this,Ya)[t]=e}toSVGProperties(){const t=l(this,Ya);return v(this,Ya,Object.create(null)),{root:t}}reset(){v(this,Ya,Object.create(null))}updateAll(t=this){this.updateProperties(t)}clone(){kt("Not implemented")}}Ya=new WeakMap;const Y=class Y extends Vt{constructor(e){super(e);_(this,mt);_(this,Ms,null);_(this,Ch);Q(this,"_drawId",null);v(this,Ch,e.mustBeCommitted||!1),e.drawOutlines&&(w(this,mt,hm).call(this,e),w(this,mt,iu).call(this))}static _mergeSVGProperties(e,s){const i=new Set(Object.keys(e));for(const[n,r]of Object.entries(s))i.has(n)?Object.assign(e[n],r):e[n]=r;return e}static getDefaultDrawingOptions(e){kt("Not implemented")}static get typesMap(){kt("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,s){const i=this.typesMap.get(e);i&&this._defaultDrawingOptions.updateProperty(i,s),this._currentParent&&(l(Y,ve).updateProperty(i,s),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,s){const i=this.constructor.typesMap.get(e);i&&this._updateProperty(e,i,s)}static get defaultPropertiesToUpdate(){const e=[],s=this._defaultDrawingOptions;for(const[i,n]of this.typesMap)e.push([i,s[n]]);return e}get propertiesToUpdate(){const e=[],{_drawingOptions:s}=this;for(const[i,n]of this.constructor.typesMap)e.push([i,s[n]]);return e}_updateProperty(e,s,i){const n=this._drawingOptions,r=n[s],a=h=>{var u;n.updateProperty(s,h);const c=l(this,Ms).updateProperty(s,h);c&&w(this,mt,nu).call(this,c),(u=this.parent)==null||u.drawLayer.updateProperties(this._drawId,n.toSVGProperties())};this.addCommands({cmd:a.bind(this,i),undo:a.bind(this,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,Y._mergeSVGProperties(l(this,Ms).getPathResizingSVGProperties(w(this,mt,xf).call(this)),{bbox:w(this,mt,Wh).call(this)}))}_onResized(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,Y._mergeSVGProperties(l(this,Ms).getPathResizedSVGProperties(w(this,mt,xf).call(this)),{bbox:w(this,mt,Wh).call(this)}))}_onTranslating(e,s){var i;(i=this.parent)==null||i.drawLayer.updateProperties(this._drawId,{bbox:w(this,mt,Wh).call(this,e,s)})}_onTranslated(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,Y._mergeSVGProperties(l(this,Ms).getPathTranslatedSVGProperties(w(this,mt,xf).call(this),this.parentDimensions),{bbox:w(this,mt,Wh).call(this)}))}_onStartDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit(),this.disableEditMode(),this.disableEditing()}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,l(this,Ch)&&(v(this,Ch,!1),this.commit(),this.parent.setSelected(this),e&&this.isOnScreen&&this.div.focus())}remove(){w(this,mt,cm).call(this),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,mt,iu).call(this),w(this,mt,nu).call(this,l(this,Ms).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),w(this,mt,cm).call(this)):e&&(this._uiManager.addShouldRescale(this),w(this,mt,iu).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),s&&this.select()}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,Y._mergeSVGProperties({bbox:w(this,mt,Wh).call(this)},l(this,Ms).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&w(this,mt,nu).call(this,l(this,Ms).updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;const e=super.render();e.classList.add("draw");const s=document.createElement("div");e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal";const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),this._uiManager.addShouldRescale(this),this.disableEditing(),e}static createDrawerInstance(e,s,i,n,r){kt("Not implemented")}static startDrawing(e,s,i,n){var y;const{target:r,offsetX:a,offsetY:h,pointerId:c,pointerType:u}=n;if(l(Y,xr)&&l(Y,xr)!==u)return;const{viewport:{rotation:d}}=e,{width:f,height:g}=r.getBoundingClientRect(),p=v(Y,$a,new AbortController),m=e.combinedSignal(p);if(l(Y,wr)||v(Y,wr,c),l(Y,xr)??v(Y,xr,u),window.addEventListener("pointerup",b=>{var x;l(Y,wr)===b.pointerId?this._endDraw(b):(x=l(Y,Sr))==null||x.delete(b.pointerId)},{signal:m}),window.addEventListener("pointercancel",b=>{var x;l(Y,wr)===b.pointerId?this._currentParent.endDrawingSession():(x=l(Y,Sr))==null||x.delete(b.pointerId)},{signal:m}),window.addEventListener("pointerdown",b=>{l(Y,xr)===b.pointerType&&((l(Y,Sr)||v(Y,Sr,new Set)).add(b.pointerId),l(Y,ve).isCancellable()&&(l(Y,ve).removeLastElement(),l(Y,ve).isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:m}),window.addEventListener("contextmenu",ri,{signal:m}),r.addEventListener("pointermove",this._drawMove.bind(this),{signal:m}),r.addEventListener("touchmove",b=>{b.timeStamp===l(Y,Ka)&&bs(b)},{signal:m}),e.toggleDrawing(),(y=s._editorUndoBar)==null||y.hide(),l(Y,ve)){e.drawLayer.updateProperties(this._currentDrawId,l(Y,ve).startNew(a,h,f,g,d));return}s.updateUIForDefaultProperties(this),v(Y,ve,this.createDrawerInstance(a,h,f,g,d)),v(Y,qa,this.getDefaultDrawingOptions()),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(l(Y,qa).toSVGProperties(),l(Y,ve).defaultSVGProperties),!0,!1)}static _drawMove(e){var r;if(v(Y,Ka,-1),!l(Y,ve))return;const{offsetX:s,offsetY:i,pointerId:n}=e;if(l(Y,wr)===n){if(((r=l(Y,Sr))==null?void 0:r.size)>=1){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,l(Y,ve).add(s,i)),v(Y,Ka,e.timeStamp),bs(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,v(Y,ve,null),v(Y,qa,null),v(Y,xr,null),v(Y,Ka,NaN)),l(Y,$a)&&(l(Y,$a).abort(),v(Y,$a,null),v(Y,wr,NaN),v(Y,Sr,null))}static _endDraw(e){const s=this._currentParent;if(s){if(s.toggleDrawing(!0),this._cleanup(!1),e&&s.drawLayer.updateProperties(this._currentDrawId,l(Y,ve).end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const i=l(Y,ve),n=this._currentDrawId,r=i.getLastElement();s.addCommands({cmd:()=>{s.drawLayer.updateProperties(n,i.setLastElement(r))},undo:()=>{s.drawLayer.updateProperties(n,i.removeLastElement())},mustExec:!1,type:gt.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const s=this._currentParent;if(!s)return null;if(s.toggleDrawing(!0),s.cleanUndoStack(gt.DRAW_STEP),!l(Y,ve).isEmpty()){const{pageDimensions:[i,n],scale:r}=s,a=s.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:l(Y,ve).getOutlines(i*r,n*r,r,this._INNER_MARGIN),drawingOptions:l(Y,qa),mustBeCommitted:!e});return this._cleanup(!0),a}return s.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(e){}static deserializeDraw(e,s,i,n,r,a){kt("Not implemented")}static async deserialize(e,s,i){var d,f;const{rawDims:{pageWidth:n,pageHeight:r,pageX:a,pageY:h}}=s.viewport,c=this.deserializeDraw(a,h,n,r,this._INNER_MARGIN,e),u=await super.deserialize(e,s,i);return u.createDrawingOptions(e),w(d=u,mt,hm).call(d,{drawOutlines:c}),w(f=u,mt,iu).call(f),u.onScaleChanging(),u.rotate(),u}serializeDraw(e){const[s,i]=this.pageTranslation,[n,r]=this.pageDimensions;return l(this,Ms).serialize([s,i,n,r],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};Ms=new WeakMap,Ch=new WeakMap,ve=new WeakMap,$a=new WeakMap,qa=new WeakMap,wr=new WeakMap,xr=new WeakMap,Sr=new WeakMap,Ka=new WeakMap,mt=new WeakSet,hm=function({drawOutlines:e,drawId:s,drawingOptions:i}){v(this,Ms,e),this._drawingOptions||(this._drawingOptions=i),s>=0?(this._drawId=s,this.parent.drawLayer.finalizeDraw(s,e.defaultProperties)):this._drawId=w(this,mt,lm).call(this,e,this.parent),w(this,mt,nu).call(this,e.box)},lm=function(e,s){const{id:i}=s.drawLayer.draw(Y._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return i},cm=function(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())},iu=function(e=this.parent){if(!(this._drawId!==null&&this.parent===e)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,e.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=w(this,mt,lm).call(this,l(this,Ms),e)}},r_=function([e,s,i,n]){const{parentDimensions:[r,a],rotation:h}=this;switch(h){case 90:return[s,1-e,i*(a/r),n*(r/a)];case 180:return[1-e,1-s,i,n];case 270:return[1-s,e,i*(a/r),n*(r/a)];default:return[e,s,i,n]}},xf=function(){const{x:e,y:s,width:i,height:n,parentDimensions:[r,a],rotation:h}=this;switch(h){case 90:return[1-s,e,i*(r/a),n*(a/r)];case 180:return[1-e,1-s,i,n];case 270:return[s,1-e,i*(r/a),n*(a/r)];default:return[e,s,i,n]}},nu=function(e){if([this.x,this.y,this.width,this.height]=w(this,mt,r_).call(this,e),this.div){this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)}this._onResized()},Wh=function(){const{x:e,y:s,width:i,height:n,rotation:r,parentRotation:a,parentDimensions:[h,c]}=this;switch((r*4+a)/90){case 1:return[1-s-n,e,n,i];case 2:return[1-e-i,1-s-n,i,n];case 3:return[s,1-e-i,n,i];case 4:return[e,s-i*(h/c),n*(c/h),i*(h/c)];case 5:return[1-s,e,i*(h/c),n*(c/h)];case 6:return[1-e-n*(c/h),1-s,n*(c/h),i*(h/c)];case 7:return[s-i*(h/c),1-e-n*(c/h),i*(h/c),n*(c/h)];case 8:return[e-i,s-n,i,n];case 9:return[1-s,e-i,n,i];case 10:return[1-e,1-s,i,n];case 11:return[s-n,1-e,n,i];case 12:return[e-n*(c/h),s,n*(c/h),i*(h/c)];case 13:return[1-s-i*(h/c),e-n*(c/h),i*(h/c),n*(c/h)];case 14:return[1-e,1-s-i*(h/c),n*(c/h),i*(h/c)];case 15:return[s,1-e,i*(h/c),n*(c/h)];default:return[e,s,i,n]}},Q(Y,"_currentDrawId",-1),Q(Y,"_currentParent",null),_(Y,ve,null),_(Y,$a,null),_(Y,qa,null),_(Y,wr,NaN),_(Y,xr,null),_(Y,Sr,null),_(Y,Ka,NaN),Q(Y,"_INNER_MARGIN",3);let rp=Y;class ZC{constructor(t,e,s,i,n,r){_(this,Th);_(this,Hi,new Float64Array(6));_(this,be);_(this,ye);_(this,Ja);_(this,Ah);_(this,Ke);_(this,Se,"");_(this,Us,0);_(this,Qa,new kd);_(this,Za);_(this,to);v(this,Za,s),v(this,to,i),v(this,Ja,n),v(this,Ah,r),[t,e]=w(this,Th,Sf).call(this,t,e);const a=v(this,be,[NaN,NaN,NaN,NaN,t,e]);v(this,Ke,[t,e]),v(this,ye,[{line:a,points:l(this,Ke)}]),l(this,Hi).set(a,0)}updateProperty(t,e){t==="stroke-width"&&v(this,Ah,e)}isEmpty(){return!l(this,ye)||l(this,ye).length===0}isCancellable(){return l(this,Ke).length<=10}add(t,e){[t,e]=w(this,Th,Sf).call(this,t,e);const[s,i,n,r]=l(this,Hi).subarray(2,6),a=t-n,h=e-r;return Math.hypot(l(this,Za)*a,l(this,to)*h)<=2?null:(l(this,Ke).push(t,e),isNaN(s)?(l(this,Hi).set([n,r,t,e],2),l(this,be).push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(l(this,Hi)[0])&&l(this,be).splice(6,6),l(this,Hi).set([s,i,n,r,t,e],0),l(this,be).push(...U.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const s=this.add(t,e);return s||(l(this,Ke).length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){v(this,Za,s),v(this,to,i),v(this,Ja,n),[t,e]=w(this,Th,Sf).call(this,t,e);const r=v(this,be,[NaN,NaN,NaN,NaN,t,e]);v(this,Ke,[t,e]);const a=l(this,ye).at(-1);return a&&(a.line=new Float32Array(a.line),a.points=new Float32Array(a.points)),l(this,ye).push({line:r,points:l(this,Ke)}),l(this,Hi).set(r,0),v(this,Us,0),this.toSVGPath(),null}getLastElement(){return l(this,ye).at(-1)}setLastElement(t){return l(this,ye)?(l(this,ye).push(t),v(this,be,t.line),v(this,Ke,t.points),v(this,Us,0),{path:{d:this.toSVGPath()}}):l(this,Qa).setLastElement(t)}removeLastElement(){if(!l(this,ye))return l(this,Qa).removeLastElement();l(this,ye).pop(),v(this,Se,"");for(let t=0,e=l(this,ye).length;t<e;t++){const{line:s,points:i}=l(this,ye)[t];v(this,be,s),v(this,Ke,i),v(this,Us,0),this.toSVGPath()}return{path:{d:l(this,Se)}}}toSVGPath(){const t=U.svgRound(l(this,be)[4]),e=U.svgRound(l(this,be)[5]);if(l(this,Ke).length===2)return v(this,Se,`${l(this,Se)} M ${t} ${e} Z`),l(this,Se);if(l(this,Ke).length<=6){const i=l(this,Se).lastIndexOf("M");v(this,Se,`${l(this,Se).slice(0,i)} M ${t} ${e}`),v(this,Us,6)}if(l(this,Ke).length===4){const i=U.svgRound(l(this,be)[10]),n=U.svgRound(l(this,be)[11]);return v(this,Se,`${l(this,Se)} L ${i} ${n}`),v(this,Us,12),l(this,Se)}const s=[];l(this,Us)===0&&(s.push(`M ${t} ${e}`),v(this,Us,6));for(let i=l(this,Us),n=l(this,be).length;i<n;i+=6){const[r,a,h,c,u,d]=l(this,be).slice(i,i+6).map(U.svgRound);s.push(`C${r} ${a} ${h} ${c} ${u} ${d}`)}return v(this,Se,l(this,Se)+s.join(" ")),v(this,Us,l(this,be).length),l(this,Se)}getOutlines(t,e,s,i){const n=l(this,ye).at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),l(this,Qa).build(l(this,ye),t,e,s,l(this,Ja),l(this,Ah),i),v(this,Hi,null),v(this,be,null),v(this,ye,null),v(this,Se,null),l(this,Qa)}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}Hi=new WeakMap,be=new WeakMap,ye=new WeakMap,Ja=new WeakMap,Ah=new WeakMap,Ke=new WeakMap,Se=new WeakMap,Us=new WeakMap,Qa=new WeakMap,Za=new WeakMap,to=new WeakMap,Th=new WeakSet,Sf=function(t,e){return U._normalizePoint(t,e,l(this,Za),l(this,to),l(this,Ja))};const mp=class mp extends U{constructor(){super(...arguments);_(this,Ce);_(this,Je);_(this,Vc,0);_(this,Wc);_(this,Os);_(this,zi);_(this,Vi);_(this,Eh);_(this,kh);_(this,Ph)}build(e,s,i,n,r,a,h){v(this,zi,s),v(this,Vi,i),v(this,Eh,n),v(this,kh,r),v(this,Ph,a),v(this,Wc,h??0),v(this,Os,e),w(this,Ce,o_).call(this)}setLastElement(e){return l(this,Os).push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return l(this,Os).pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:s}of l(this,Os)){if(e.push(`M${U.svgRound(s[4])} ${U.svgRound(s[5])}`),s.length===6){e.push("Z");continue}if(s.length===12){e.push(`L${U.svgRound(s[10])} ${U.svgRound(s[11])}`);continue}for(let i=6,n=s.length;i<n;i+=6){const[r,a,h,c,u,d]=s.subarray(i,i+6).map(U.svgRound);e.push(`C${r} ${a} ${h} ${c} ${u} ${d}`)}}return e.join("")}serialize([e,s,i,n],r){const a=[],h=[],[c,u,d,f]=w(this,Ce,a_).call(this);let g,p,m,y,b,x,S,C,k;switch(l(this,kh)){case 0:k=U._rescale,g=e,p=s+n,m=i,y=-n,b=e+c*i,x=s+(1-u-f)*n,S=e+(c+d)*i,C=s+(1-u)*n;break;case 90:k=U._rescaleAndSwap,g=e,p=s,m=i,y=n,b=e+u*i,x=s+c*n,S=e+(u+f)*i,C=s+(c+d)*n;break;case 180:k=U._rescale,g=e+i,p=s,m=-i,y=n,b=e+(1-c-d)*i,x=s+u*n,S=e+(1-c)*i,C=s+(u+f)*n;break;case 270:k=U._rescaleAndSwap,g=e+i,p=s+n,m=-i,y=-n,b=e+(1-u-f)*i,x=s+(1-c-d)*n,S=e+(1-u)*i,C=s+(1-c)*n;break}for(const{line:O,points:P}of l(this,Os))a.push(k(O,g,p,m,y,r?new Array(O.length):null)),h.push(k(P,g,p,m,y,r?new Array(P.length):null));return{lines:a,points:h,rect:[b,x,S,C]}}static deserialize(e,s,i,n,r,{paths:{lines:a,points:h},rotation:c,thickness:u}){const d=[];let f,g,p,m,y;switch(c){case 0:y=U._rescale,f=-e/i,g=s/n+1,p=1/i,m=-1/n;break;case 90:y=U._rescaleAndSwap,f=-s/n,g=-e/i,p=1/n,m=1/i;break;case 180:y=U._rescale,f=e/i+1,g=-s/n,p=-1/i,m=1/n;break;case 270:y=U._rescaleAndSwap,f=s/n+1,g=e/i+1,p=-1/n,m=-1/i;break}if(!a){a=[];for(const x of h){const S=x.length;if(S===2){a.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1]]));continue}if(S===4){a.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1],NaN,NaN,NaN,NaN,x[2],x[3]]));continue}const C=new Float32Array(3*(S-2));a.push(C);let[k,O,P,D]=x.subarray(0,4);C.set([NaN,NaN,NaN,NaN,k,O],0);for(let R=4;R<S;R+=2){const z=x[R],B=x[R+1];C.set(U.createBezierPoints(k,O,P,D,z,B),(R-2)*3),[k,O,P,D]=[P,D,z,B]}}}for(let x=0,S=a.length;x<S;x++)d.push({line:y(a[x].map(C=>C??NaN),f,g,p,m),points:y(h[x].map(C=>C??NaN),f,g,p,m)});const b=new mp;return b.build(d,i,n,1,c,u,r),b}get box(){return l(this,Je)}updateProperty(e,s){return e==="stroke-width"?w(this,Ce,h_).call(this,s):null}updateParentDimensions([e,s],i){const[n,r]=w(this,Ce,Bn).call(this);v(this,zi,e),v(this,Vi,s),v(this,Eh,i);const[a,h]=w(this,Ce,Bn).call(this),c=a-n,u=h-r,d=l(this,Je);return d[0]-=c,d[1]-=u,d[2]+=2*c,d[3]+=2*u,d}updateRotation(e){return v(this,Vc,e),{path:{transform:this.rotationTransform}}}get viewBox(){return l(this,Je).map(U.svgRound).join(" ")}get defaultProperties(){const[e,s]=l(this,Je);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${U.svgRound(e)} ${U.svgRound(s)}`}}}get rotationTransform(){const[,,e,s]=l(this,Je);let i=0,n=0,r=0,a=0,h=0,c=0;switch(l(this,Vc)){case 90:n=s/e,r=-e/s,h=e;break;case 180:i=-1,a=-1,h=e,c=s;break;case 270:n=-s/e,r=e/s,c=s;break;default:return""}return`matrix(${i} ${n} ${r} ${a} ${U.svgRound(h)} ${U.svgRound(c)})`}getPathResizingSVGProperties([e,s,i,n]){const[r,a]=w(this,Ce,Bn).call(this),[h,c,u,d]=l(this,Je);if(Math.abs(u-r)<=U.PRECISION||Math.abs(d-a)<=U.PRECISION){const y=e+i/2-(h+u/2),b=s+n/2-(c+d/2);return{path:{"transform-origin":`${U.svgRound(e)} ${U.svgRound(s)}`,transform:`${this.rotationTransform} translate(${y} ${b})`}}}const f=(i-2*r)/(u-2*r),g=(n-2*a)/(d-2*a),p=u/i,m=d/n;return{path:{"transform-origin":`${U.svgRound(h)} ${U.svgRound(c)}`,transform:`${this.rotationTransform} scale(${p} ${m}) translate(${U.svgRound(r)} ${U.svgRound(a)}) scale(${f} ${g}) translate(${U.svgRound(-r)} ${U.svgRound(-a)})`}}}getPathResizedSVGProperties([e,s,i,n]){const[r,a]=w(this,Ce,Bn).call(this),h=l(this,Je),[c,u,d,f]=h;if(h[0]=e,h[1]=s,h[2]=i,h[3]=n,Math.abs(d-r)<=U.PRECISION||Math.abs(f-a)<=U.PRECISION){const b=e+i/2-(c+d/2),x=s+n/2-(u+f/2);for(const{line:S,points:C}of l(this,Os))U._translate(S,b,x,S),U._translate(C,b,x,C);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${U.svgRound(e)} ${U.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const g=(i-2*r)/(d-2*r),p=(n-2*a)/(f-2*a),m=-g*(c+r)+e+r,y=-p*(u+a)+s+a;if(g!==1||p!==1||m!==0||y!==0)for(const{line:b,points:x}of l(this,Os))U._rescale(b,m,y,g,p,b),U._rescale(x,m,y,g,p,x);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${U.svgRound(e)} ${U.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,s],i){const[n,r]=i,a=l(this,Je),h=e-a[0],c=s-a[1];if(l(this,zi)===n&&l(this,Vi)===r)for(const{line:u,points:d}of l(this,Os))U._translate(u,h,c,u),U._translate(d,h,c,d);else{const u=l(this,zi)/n,d=l(this,Vi)/r;v(this,zi,n),v(this,Vi,r);for(const{line:f,points:g}of l(this,Os))U._rescale(f,h,c,u,d,f),U._rescale(g,h,c,u,d,g);a[2]*=u,a[3]*=d}return a[0]=e,a[1]=s,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${U.svgRound(e)} ${U.svgRound(s)}`}}}get defaultSVGProperties(){const e=l(this,Je);return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${U.svgRound(e[0])} ${U.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}};Je=new WeakMap,Vc=new WeakMap,Wc=new WeakMap,Os=new WeakMap,zi=new WeakMap,Vi=new WeakMap,Eh=new WeakMap,kh=new WeakMap,Ph=new WeakMap,Ce=new WeakSet,Bn=function(e=l(this,Ph)){const s=l(this,Wc)+e/2*l(this,Eh);return l(this,kh)%180===0?[s/l(this,zi),s/l(this,Vi)]:[s/l(this,Vi),s/l(this,zi)]},a_=function(){const[e,s,i,n]=l(this,Je),[r,a]=w(this,Ce,Bn).call(this,0);return[e+r,s+a,i-2*r,n-2*a]},o_=function(){const e=v(this,Je,new Float32Array([1/0,1/0,-1/0,-1/0]));for(const{line:n}of l(this,Os)){if(n.length<=12){for(let h=4,c=n.length;h<c;h+=6){const[u,d]=n.subarray(h,h+2);e[0]=Math.min(e[0],u),e[1]=Math.min(e[1],d),e[2]=Math.max(e[2],u),e[3]=Math.max(e[3],d)}continue}let r=n[4],a=n[5];for(let h=6,c=n.length;h<c;h+=6){const[u,d,f,g,p,m]=n.subarray(h,h+6);q.bezierBoundingBox(r,a,u,d,f,g,p,m,e),r=p,a=m}}const[s,i]=w(this,Ce,Bn).call(this);e[0]=Math.min(1,Math.max(0,e[0]-s)),e[1]=Math.min(1,Math.max(0,e[1]-i)),e[2]=Math.min(1,Math.max(0,e[2]+s)),e[3]=Math.min(1,Math.max(0,e[3]+i)),e[2]-=e[0],e[3]-=e[1]},h_=function(e){const[s,i]=w(this,Ce,Bn).call(this);v(this,Ph,e);const[n,r]=w(this,Ce,Bn).call(this),[a,h]=[n-s,r-i],c=l(this,Je);return c[0]-=a,c[1]-=h,c[2]+=2*a,c[3]+=2*h,c};let kd=mp;const vp=class vp extends QC{constructor(e){super();_(this,Mh);v(this,Mh,e),super.updateProperties({fill:"none",stroke:Vt._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(e,s){e==="stroke-width"&&(s??(s=this["stroke-width"]),s*=l(this,Mh).realScale),super.updateSVGProperty(e,s)}clone(){const e=new vp(l(this,Mh));return e.updateAll(this),e}};Mh=new WeakMap;let ap=vp;const Oh=class Oh extends rp{constructor(e){super({...e,name:"inkEditor"});_(this,Ud);this._willKeepAspectRatio=!0}static initialize(e,s){Vt.initialize(e,s),this._defaultDrawingOptions=new ap(s.viewParameters)}static getDefaultDrawingOptions(e){const s=this._defaultDrawingOptions.clone();return s.updateProperties(e),s}static get supportMultipleDrawings(){return!0}static get typesMap(){return ct(this,"typesMap",new Map([[gt.INK_THICKNESS,"stroke-width"],[gt.INK_COLOR,"stroke"],[gt.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(e,s,i,n,r){return new ZC(e,s,i,n,r,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(e,s,i,n,r,a){return kd.deserialize(e,s,i,n,r,a)}static async deserialize(e,s,i){let n=null;if(e instanceof ep){const{data:{inkLists:a,rect:h,rotation:c,id:u,color:d,opacity:f,borderStyle:{rawWidth:g},popupRef:p},parent:{page:{pageNumber:m}}}=e;n=e={annotationType:ot.INK,color:Array.from(d),thickness:g,opacity:f,paths:{points:a},boxes:null,pageIndex:m-1,rect:h.slice(0),rotation:c,id:u,deleted:!1,popupRef:p}}const r=await super.deserialize(e,s,i);return r.annotationElementId=e.id||null,r._initialData=n,r}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:e,_drawingOptions:s,parent:i}=this;s.updateSVGProperty("stroke-width"),i.drawLayer.updateProperties(e,s.toSVGProperties())}static onScaleChangingWhenDrawing(){const e=this._currentParent;e&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:e,thickness:s,opacity:i}){this._drawingOptions=Oh.getDefaultDrawingOptions({stroke:q.makeHexColor(...e),"stroke-width":s,"stroke-opacity":i})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:s,points:i,rect:n}=this.serializeDraw(e),{_drawingOptions:{stroke:r,"stroke-opacity":a,"stroke-width":h}}=this,c={annotationType:ot.INK,color:Vt._colorManager.convert(r),opacity:a,thickness:h,paths:{lines:s,points:i},pageIndex:this.pageIndex,rect:n,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?c:this.annotationElementId&&!w(this,Ud,l_).call(this,c)?null:(c.id=this.annotationElementId,c)}renderAnnotationElement(e){const{points:s,rect:i}=this.serializeDraw(!1);return e.updateEdited({rect:i,thickness:this._drawingOptions["stroke-width"],points:s}),null}};Ud=new WeakSet,l_=function(e){const{color:s,thickness:i,opacity:n,pageIndex:r}=this._initialData;return this._hasBeenMoved||this._hasBeenResized||e.color.some((a,h)=>a!==s[h])||e.thickness!==i||e.opacity!==n||e.pageIndex!==r},Q(Oh,"_type","ink"),Q(Oh,"_editorType",ot.INK),Q(Oh,"_defaultDrawingOptions",null);let op=Oh;const Gc=class Gc extends Vt{constructor(e){super({...e,name:"stampEditor"});_(this,vt);_(this,Gt,null);_(this,Ae,null);_(this,Cr,null);_(this,Fn,null);_(this,Ar,null);_(this,Dh,"");_(this,Wi,null);_(this,Gi,null);_(this,Ds,!1);_(this,Rh,!1);v(this,Fn,e.bitmapUrl),v(this,Ar,e.bitmapFile)}static initialize(e,s){Vt.initialize(e,s)}static get supportedTypes(){return ct(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return ct(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(e){return this.supportedTypes.includes(e)}static paste(e,s){s.pasteEditor(ot.STAMP,{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){var e;return{type:"stamp",hasAltText:!!((e=this.altTextData)!=null&&e.altText)}}static computeTelemetryFinalData(e){const s=e.get("hasAltText");return{hasAltText:s.get(!0)??0,hasNoAltText:s.get(!1)??0}}async mlGuessAltText(e=null,s=!0){if(this.hasAltTextData())return null;const{mlManager:i}=this._uiManager;if(!i)throw new Error("No ML.");if(!await i.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:n,width:r,height:a}=e||this.copyCanvas(null,null,!0).imageData,h=await i.guess({name:"altText",request:{data:n,width:r,height:a,channels:n.length/(r*a)}});if(!h)throw new Error("No response from the AI service.");if(h.error)throw new Error("Error from the AI service.");if(h.cancel)return null;if(!h.output)throw new Error("No valid response from the AI service.");const c=h.output;return await this.setGuessedAltText(c),s&&!this.hasAltTextData()&&(this.altTextData={alt:c,decorative:!1}),c}remove(){var e;l(this,Ae)&&(v(this,Gt,null),this._uiManager.imageManager.deleteId(l(this,Ae)),(e=l(this,Wi))==null||e.remove(),v(this,Wi,null),l(this,Gi)&&(clearTimeout(l(this,Gi)),v(this,Gi,null))),super.remove()}rebuild(){if(!this.parent){l(this,Ae)&&w(this,vt,Cf).call(this);return}super.rebuild(),this.div!==null&&(l(this,Ae)&&l(this,Wi)===null&&w(this,vt,Cf).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(e){this._isDraggable=!0,e&&this.div.focus()}isEmpty(){return!(l(this,Cr)||l(this,Gt)||l(this,Fn)||l(this,Ar)||l(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(),l(this,Gt)?w(this,vt,um).call(this):w(this,vt,Cf).call(this),this.width&&!this.annotationElementId){const[i,n]=this.parentDimensions;this.setAt(e*i,s*n,this.width*i,this.height*n)}return this._uiManager.addShouldRescale(this),this.div}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;l(this,Gi)!==null&&clearTimeout(l(this,Gi)),v(this,Gi,setTimeout(()=>{v(this,Gi,null),w(this,vt,dm).call(this)},200))}copyCanvas(e,s,i=!1){var g;e||(e=224);const{width:n,height:r}=l(this,Gt),a=new Bg;let h=l(this,Gt),c=n,u=r,d=null;if(s){if(n>s||r>s){const D=Math.min(s/n,s/r);c=Math.floor(n*D),u=Math.floor(r*D)}d=document.createElement("canvas");const p=d.width=Math.ceil(c*a.sx),m=d.height=Math.ceil(u*a.sy);l(this,Ds)||(h=w(this,vt,Af).call(this,p,m));const y=d.getContext("2d");y.filter=this._uiManager.hcmFilter;let b="white",x="#cfcfd8";this._uiManager.hcmFilter!=="none"?x="black":(g=window.matchMedia)!=null&&g.call(window,"(prefers-color-scheme: dark)").matches&&(b="#8f8f9d",x="#42414d");const S=15,C=S*a.sx,k=S*a.sy,O=new OffscreenCanvas(C*2,k*2),P=O.getContext("2d");P.fillStyle=b,P.fillRect(0,0,C*2,k*2),P.fillStyle=x,P.fillRect(0,0,C,k),P.fillRect(C,k,C,k),y.fillStyle=y.createPattern(O,"repeat"),y.fillRect(0,0,p,m),y.drawImage(h,0,0,h.width,h.height,0,0,p,m)}let f=null;if(i){let p,m;if(a.symmetric&&h.width<e&&h.height<e)p=h.width,m=h.height;else if(h=l(this,Gt),n>e||r>e){const x=Math.min(e/n,e/r);p=Math.floor(n*x),m=Math.floor(r*x),l(this,Ds)||(h=w(this,vt,Af).call(this,p,m))}const b=new OffscreenCanvas(p,m).getContext("2d",{willReadFrequently:!0});b.drawImage(h,0,0,h.width,h.height,0,0,p,m),f={width:p,height:m,data:b.getImageData(0,0,p,m).data}}return{canvas:d,width:c,height:u,imageData:f}}getImageForAltText(){return l(this,Wi)}static async deserialize(e,s,i){var m;let n=null;if(e instanceof yb){const{data:{rect:y,rotation:b,id:x,structParent:S,popupRef:C},container:k,parent:{page:{pageNumber:O}}}=e,P=k.querySelector("canvas"),D=i.imageManager.getFromCanvas(k.id,P);P.remove();const R=((m=await s._structTree.getAriaAttributes(`${Fg}${x}`))==null?void 0:m.get("aria-label"))||"";n=e={annotationType:ot.STAMP,bitmapId:D.id,bitmap:D.bitmap,pageIndex:O-1,rect:y.slice(0),rotation:b,id:x,deleted:!1,accessibilityData:{decorative:!1,altText:R},isSvg:!1,structParent:S,popupRef:C}}const r=await super.deserialize(e,s,i),{rect:a,bitmap:h,bitmapUrl:c,bitmapId:u,isSvg:d,accessibilityData:f}=e;u&&i.imageManager.isValidId(u)?(v(r,Ae,u),h&&v(r,Gt,h)):v(r,Fn,c),v(r,Ds,d);const[g,p]=r.pageDimensions;return r.width=(a[2]-a[0])/g,r.height=(a[3]-a[1])/p,r.annotationElementId=e.id||null,f&&(r.altTextData=f),r._initialData=n,v(r,Rh,!!n),r}serialize(e=!1,s=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const i={annotationType:ot.STAMP,bitmapId:l(this,Ae),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:l(this,Ds),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=w(this,vt,Tf).call(this,!0),i.accessibilityData=this.serializeAltText(!0),i;const{decorative:n,altText:r}=this.serializeAltText(!1);if(!n&&r&&(i.accessibilityData={type:"Figure",alt:r}),this.annotationElementId){const h=w(this,vt,c_).call(this,i);if(h.isSame)return null;h.isSameAltText?delete i.accessibilityData:i.accessibilityData.structParent=this._initialData.structParent??-1}if(i.id=this.annotationElementId,s===null)return i;s.stamps||(s.stamps=new Map);const a=l(this,Ds)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!s.stamps.has(l(this,Ae)))s.stamps.set(l(this,Ae),{area:a,serialized:i}),i.bitmap=w(this,vt,Tf).call(this,!1);else if(l(this,Ds)){const h=s.stamps.get(l(this,Ae));a>h.area&&(h.area=a,h.serialized.bitmap.close(),h.serialized.bitmap=w(this,vt,Tf).call(this,!1))}return i}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}};Gt=new WeakMap,Ae=new WeakMap,Cr=new WeakMap,Fn=new WeakMap,Ar=new WeakMap,Dh=new WeakMap,Wi=new WeakMap,Gi=new WeakMap,Ds=new WeakMap,Rh=new WeakMap,vt=new WeakSet,ru=function(e,s=!1){if(!e){this.remove();return}v(this,Gt,e.bitmap),s||(v(this,Ae,e.id),v(this,Ds,e.isSvg)),e.file&&v(this,Dh,e.file.name),w(this,vt,um).call(this)},au=function(){if(v(this,Cr,null),this._uiManager.enableWaiting(!1),!!l(this,Wi)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Gt)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Gt)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},Cf=function(){if(l(this,Ae)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(l(this,Ae)).then(i=>w(this,vt,ru).call(this,i,!0)).finally(()=>w(this,vt,au).call(this));return}if(l(this,Fn)){const i=l(this,Fn);v(this,Fn,null),this._uiManager.enableWaiting(!0),v(this,Cr,this._uiManager.imageManager.getFromUrl(i).then(n=>w(this,vt,ru).call(this,n)).finally(()=>w(this,vt,au).call(this)));return}if(l(this,Ar)){const i=l(this,Ar);v(this,Ar,null),this._uiManager.enableWaiting(!0),v(this,Cr,this._uiManager.imageManager.getFromFile(i).then(n=>w(this,vt,ru).call(this,n)).finally(()=>w(this,vt,au).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=Gc.supportedTypesStr;const s=this._uiManager._signal;v(this,Cr,new Promise(i=>{e.addEventListener("change",async()=>{if(!e.files||e.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const n=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),w(this,vt,ru).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>w(this,vt,au).call(this))),e.click()},um=function(){var d;const{div:e}=this;let{width:s,height:i}=l(this,Gt);const[n,r]=this.pageDimensions,a=.75;if(this.width)s=this.width*n,i=this.height*r;else if(s>a*n||i>a*r){const f=Math.min(a*n/s,a*r/i);s*=f,i*=f}const[h,c]=this.parentDimensions;this.setDims(s*h/n,i*c/r),this._uiManager.enableWaiting(!1);const u=v(this,Wi,document.createElement("canvas"));u.setAttribute("role","img"),this.addContainer(u),this.width=s/n,this.height=i/r,(d=this._initialOptions)!=null&&d.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),w(this,vt,dm).call(this),l(this,Rh)||(this.parent.addUndoableEditor(this),v(this,Rh,!0)),this._reportTelemetry({action:"inserted_image"}),l(this,Dh)&&u.setAttribute("aria-label",l(this,Dh))},Af=function(e,s){const{width:i,height:n}=l(this,Gt);let r=i,a=n,h=l(this,Gt);for(;r>2*e||a>2*s;){const c=r,u=a;r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2)),a>2*s&&(a=a>=16384?Math.floor(a/2)-1:Math.ceil(a/2));const d=new OffscreenCanvas(r,a);d.getContext("2d").drawImage(h,0,0,c,u,0,0,r,a),h=d.transferToImageBitmap()}return h},dm=function(){const[e,s]=this.parentDimensions,{width:i,height:n}=this,r=new Bg,a=Math.ceil(i*e*r.sx),h=Math.ceil(n*s*r.sy),c=l(this,Wi);if(!c||c.width===a&&c.height===h)return;c.width=a,c.height=h;const u=l(this,Ds)?l(this,Gt):w(this,vt,Af).call(this,a,h),d=c.getContext("2d");d.filter=this._uiManager.hcmFilter,d.drawImage(u,0,0,u.width,u.height,0,0,a,h)},Tf=function(e){if(e){if(l(this,Ds)){const n=this._uiManager.imageManager.getSvgUrl(l(this,Ae));if(n)return n}const s=document.createElement("canvas");return{width:s.width,height:s.height}=l(this,Gt),s.getContext("2d").drawImage(l(this,Gt),0,0),s.toDataURL()}if(l(this,Ds)){const[s,i]=this.pageDimensions,n=Math.round(this.width*s*Kn.PDF_TO_CSS_UNITS),r=Math.round(this.height*i*Kn.PDF_TO_CSS_UNITS),a=new OffscreenCanvas(n,r);return a.getContext("2d").drawImage(l(this,Gt),0,0,l(this,Gt).width,l(this,Gt).height,0,0,n,r),a.transferToImageBitmap()}return structuredClone(l(this,Gt))},c_=function(e){var a;const{pageIndex:s,accessibilityData:{altText:i}}=this._initialData,n=e.pageIndex===s,r=(((a=e.accessibilityData)==null?void 0:a.alt)||"")===i;return{isSame:!this._hasBeenMoved&&!this._hasBeenResized&&n&&r,isSameAltText:r}},Q(Gc,"_type","stamp"),Q(Gc,"_editorType",ot.STAMP);let hp=Gc;const yi=class yi{constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:a,textLayer:h,viewport:c,l10n:u}){_(this,Nt);_(this,eo);_(this,Fh,!1);_(this,Xi,null);_(this,Tr,null);_(this,Ln,null);_(this,Ys,new Map);_(this,Er,!1);_(this,Lh,!1);_(this,so,!1);_(this,bi,null);_(this,In,null);_(this,je,null);_(this,jn,null);_(this,$);const d=[...l(yi,kr).values()];if(!yi._initialized){yi._initialized=!0;for(const f of d)f.initialize(u,t)}t.registerEditorTypes(d),v(this,$,t),this.pageIndex=e,this.div=s,v(this,eo,n),v(this,Xi,r),this.viewport=c,v(this,je,h),this.drawLayer=a,this._structTree=i,l(this,$).addLayer(this)}get isEmpty(){return l(this,Ys).size===0}get isInvisible(){return this.isEmpty&&l(this,$).getMode()===ot.NONE}updateToolbar(t){l(this,$).updateToolbar(t)}updateMode(t=l(this,$).getMode()){switch(w(this,Nt,Ef).call(this),t){case ot.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case ot.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case ot.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:e}=this.div;for(const s of l(yi,kr).values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=l(this,je))==null?void 0:e.div)}setEditingState(t){l(this,$).setEditingState(t)}addCommands(t){l(this,$).addCommands(t)}cleanUndoStack(t){l(this,$).cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){var e;(e=l(this,Xi))==null||e.div.classList.toggle("disabled",!t)}async enable(){v(this,so,!0),this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of l(this,Ys).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(l(this,$).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!l(this,Xi)){v(this,so,!1);return}const e=l(this,Xi).getEditableAnnotations();for(const s of e){if(s.hide(),l(this,$).isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}v(this,so,!1)}disable(){var i;v(this,Lh,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const n of l(this,Ys).values())if(n.disableEditing(),!!n.annotationElementId){if(n.serialize()!==null){t.set(n.annotationElementId,n);continue}else e.set(n.annotationElementId,n);(i=this.getEditableAnnotation(n.annotationElementId))==null||i.show(),n.remove()}if(l(this,Xi)){const n=l(this,Xi).getEditableAnnotations();for(const r of n){const{id:a}=r.data;if(l(this,$).isDeletedAnnotationElement(a))continue;let h=e.get(a);if(h){h.resetAnnotationElement(r),h.show(!1),r.show();continue}h=t.get(a),h&&(l(this,$).addChangedExistingAnnotation(h),h.renderAnnotationElement(r)&&h.show(!1)),r.show()}}w(this,Nt,Ef).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of l(yi,kr).values())s.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),v(this,Lh,!1)}getEditableAnnotation(t){var e;return((e=l(this,Xi))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){l(this,$).getActive()!==t&&l(this,$).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=l(this,je))!=null&&t.div&&!l(this,jn)){v(this,jn,new AbortController);const e=l(this,$).combinedSignal(l(this,jn));l(this,je).div.addEventListener("pointerdown",w(this,Nt,u_).bind(this),{signal:e}),l(this,je).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=l(this,je))!=null&&t.div&&l(this,jn)&&(l(this,jn).abort(),v(this,jn,null),l(this,je).div.classList.remove("highlighting"))}enableClick(){if(l(this,Tr))return;v(this,Tr,new AbortController);const t=l(this,$).combinedSignal(l(this,Tr));this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){var t;(t=l(this,Tr))==null||t.abort(),v(this,Tr,null)}attach(t){l(this,Ys).set(t.id,t);const{annotationElementId:e}=t;e&&l(this,$).isDeletedAnnotationElement(e)&&l(this,$).removeDeletedAnnotationElement(t)}detach(t){var e;l(this,Ys).delete(t.id),(e=l(this,eo))==null||e.removePointerInTextLayer(t.contentDiv),!l(this,Lh)&&t.annotationElementId&&l(this,$).addDeletedAnnotationElement(t)}remove(t){this.detach(t),l(this,$).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(l(this,$).addDeletedAnnotationElement(t.annotationElementId),Vt.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),(e=t.parent)==null||e.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(!(t.parent===this&&t.isAttachedToDOM)){if(this.changeParent(t),l(this,$).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!l(this,so)),l(this,$).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!l(this,Ln)&&(t._focusEventsAllowed=!1,v(this,Ln,setTimeout(()=>{v(this,Ln,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:l(this,$)._signal}),e.focus())},0))),t._structTreeParentId=(s=l(this,eo))==null?void 0:s.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||(t.parent=this),t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getNextId(){return l(this,$).getId()}combinedSignal(t){return l(this,$).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=l(this,Nt,Yi))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){l(this,$).updateToolbar(t),l(this,$).updateMode(t);const{offsetX:s,offsetY:i}=w(this,Nt,gm).call(this),n=this.getNextId(),r=w(this,Nt,fm).call(this,{parent:this,id:n,x:s,y:i,uiManager:l(this,$),isCentered:!0,...e});r&&this.add(r)}async deserialize(t){var e;return await((e=l(yi,kr).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,l(this,$)))||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=w(this,Nt,fm).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:l(this,$),isCentered:e,...s});return n&&this.add(n),n}addNewEditor(){this.createAndAddNewEditor(w(this,Nt,gm).call(this),!0)}setSelected(t){l(this,$).setSelected(t)}toggleSelected(t){l(this,$).toggleSelected(t)}unselect(t){l(this,$).unselect(t)}pointerup(t){var s;const{isMac:e}=Ue.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&l(this,Er)&&(v(this,Er,!1),!((s=l(this,Nt,Yi))!=null&&s.isDrawer&&l(this,Nt,Yi).supportMultipleDrawings))){if(!l(this,Fh)){v(this,Fh,!0);return}if(l(this,$).getMode()===ot.STAMP){l(this,$).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){var i;if(l(this,$).getMode()===ot.HIGHLIGHT&&this.enableTextSelection(),l(this,Er)){v(this,Er,!1);return}const{isMac:e}=Ue.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(v(this,Er,!0),(i=l(this,Nt,Yi))!=null&&i.isDrawer){this.startDrawingSession(t);return}const s=l(this,$).getActive();v(this,Fh,!s||s.isEmpty())}startDrawingSession(t){if(this.div.focus(),l(this,bi)){l(this,Nt,Yi).startDrawing(this,l(this,$),!1,t);return}l(this,$).setCurrentDrawingSession(this),v(this,bi,new AbortController);const e=l(this,$).combinedSignal(l(this,bi));this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(v(this,In,null),this.commitOrRemove())},{signal:e}),l(this,Nt,Yi).startDrawing(this,l(this,$),!1,t)}pause(t){if(t){const{activeElement:e}=document;this.div.contains(e)&&v(this,In,e);return}l(this,In)&&setTimeout(()=>{var e;(e=l(this,In))==null||e.focus(),v(this,In,null)},0)}endDrawingSession(t=!1){return l(this,bi)?(l(this,$).setCurrentDrawingSession(null),l(this,bi).abort(),v(this,bi,null),v(this,In,null),l(this,Nt,Yi).endDrawing(t)):null}findNewParent(t,e,s){const i=l(this,$).findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return l(this,bi)?(this.endDrawingSession(),!0):!1}onScaleChanging(){l(this,bi)&&l(this,Nt,Yi).onScaleChangingWhenDrawing(this)}destroy(){var t,e;this.commitOrRemove(),((t=l(this,$).getActive())==null?void 0:t.parent)===this&&(l(this,$).commitOrRemove(),l(this,$).setActiveEditor(null)),l(this,Ln)&&(clearTimeout(l(this,Ln)),v(this,Ln,null));for(const s of l(this,Ys).values())(e=l(this,eo))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,l(this,Ys).clear(),l(this,$).removeLayer(this)}render({viewport:t}){this.viewport=t,Yr(this.div,t);for(const e of l(this,$).getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){l(this,$).commitOrRemove(),w(this,Nt,Ef).call(this);const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,Yr(this.div,{rotation:s}),e!==s)for(const i of l(this,Ys).values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return l(this,$).viewParameters.realScale}};eo=new WeakMap,Fh=new WeakMap,Xi=new WeakMap,Tr=new WeakMap,Ln=new WeakMap,Ys=new WeakMap,Er=new WeakMap,Lh=new WeakMap,so=new WeakMap,bi=new WeakMap,In=new WeakMap,je=new WeakMap,jn=new WeakMap,$=new WeakMap,kr=new WeakMap,Nt=new WeakSet,u_=function(t){l(this,$).unselectAll();const{target:e}=t;if(e===l(this,je).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&l(this,je).div.contains(e)){const{isMac:s}=Ue.platform;if(t.button!==0||t.ctrlKey&&s)return;l(this,$).showAllEditors("highlight",!0,!0),l(this,je).div.classList.add("free"),this.toggleDrawing(),Ed.startHighlighting(this,l(this,$).direction==="ltr",{target:l(this,je).div,x:t.x,y:t.y}),l(this,je).div.addEventListener("pointerup",()=>{l(this,je).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:l(this,$)._signal}),t.preventDefault()}},Yi=function(){return l(yi,kr).get(l(this,$).getMode())},fm=function(t){const e=l(this,Nt,Yi);return e?new e.prototype.constructor(t):null},gm=function(){const{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),a=Math.min(window.innerWidth,t+s),h=Math.min(window.innerHeight,e+i),c=(n+a)/2-t,u=(r+h)/2-e,[d,f]=this.viewport.rotation%180===0?[c,u]:[u,c];return{offsetX:d,offsetY:f}},Ef=function(){for(const t of l(this,Ys).values())t.isEmpty()&&t.remove()},Q(yi,"_initialized",!1),_(yi,kr,new Map([sp,op,hp,Ed].map(t=>[t._editorType,t])));let lp=yi;const Ne=class Ne{constructor({pageIndex:t}){_(this,Ui);_(this,_i,null);_(this,Xc,0);_(this,Qe,new Map);_(this,io,new Map);this.pageIndex=t}setParent(t){if(!l(this,_i)){v(this,_i,t);return}if(l(this,_i)!==t){if(l(this,Qe).size>0)for(const e of l(this,Qe).values())e.remove(),t.append(e);v(this,_i,t)}}static get _svgFactory(){return ct(this,"_svgFactory",new Zg)}draw(t,e=!1,s=!1){const i=es(this,Xc)._++,n=w(this,Ui,pm).call(this),r=Ne._svgFactory.createElement("defs");n.append(r);const a=Ne._svgFactory.createElement("path");r.append(a);const h=`path_p${this.pageIndex}_${i}`;a.setAttribute("id",h),a.setAttribute("vector-effect","non-scaling-stroke"),e&&l(this,io).set(i,a);const c=s?w(this,Ui,f_).call(this,r,h):null,u=Ne._svgFactory.createElement("use");return n.append(u),u.setAttribute("href",`#${h}`),this.updateProperties(n,t),l(this,Qe).set(i,n),{id:i,clipPathId:`url(#${c})`}}drawOutline(t,e){const s=es(this,Xc)._++,i=w(this,Ui,pm).call(this),n=Ne._svgFactory.createElement("defs");i.append(n);const r=Ne._svgFactory.createElement("path");n.append(r);const a=`path_p${this.pageIndex}_${s}`;r.setAttribute("id",a),r.setAttribute("vector-effect","non-scaling-stroke");let h;if(e){const d=Ne._svgFactory.createElement("mask");n.append(d),h=`mask_p${this.pageIndex}_${s}`,d.setAttribute("id",h),d.setAttribute("maskUnits","objectBoundingBox");const f=Ne._svgFactory.createElement("rect");d.append(f),f.setAttribute("width","1"),f.setAttribute("height","1"),f.setAttribute("fill","white");const g=Ne._svgFactory.createElement("use");d.append(g),g.setAttribute("href",`#${a}`),g.setAttribute("stroke","none"),g.setAttribute("fill","black"),g.setAttribute("fill-rule","nonzero"),g.classList.add("mask")}const c=Ne._svgFactory.createElement("use");i.append(c),c.setAttribute("href",`#${a}`),h&&c.setAttribute("mask",`url(#${h})`);const u=c.cloneNode();return i.append(u),c.classList.add("mainOutline"),u.classList.add("secondaryOutline"),this.updateProperties(i,t),l(this,Qe).set(s,i),s}finalizeDraw(t,e){l(this,io).delete(t),this.updateProperties(t,e)}updateProperties(t,e){var h;if(!e)return;const{root:s,bbox:i,rootClass:n,path:r}=e,a=typeof t=="number"?l(this,Qe).get(t):t;if(a){if(s&&w(this,Ui,mm).call(this,a,s),i&&w(h=Ne,Yd,d_).call(h,a,i),n){const{classList:c}=a;for(const[u,d]of Object.entries(n))c.toggle(u,d)}if(r){const u=a.firstChild.firstChild;w(this,Ui,mm).call(this,u,r)}}}updateParent(t,e){if(e===this)return;const s=l(this,Qe).get(t);s&&(l(e,_i).append(s),l(this,Qe).delete(t),l(e,Qe).set(t,s))}remove(t){l(this,io).delete(t),l(this,_i)!==null&&(l(this,Qe).get(t).remove(),l(this,Qe).delete(t))}destroy(){v(this,_i,null);for(const t of l(this,Qe).values())t.remove();l(this,Qe).clear(),l(this,io).clear()}};_i=new WeakMap,Xc=new WeakMap,Qe=new WeakMap,io=new WeakMap,Yd=new WeakSet,d_=function(t,[e,s,i,n]){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`},Ui=new WeakSet,pm=function(){const t=Ne._svgFactory.create(1,1,!0);return l(this,_i).append(t),t.setAttribute("aria-hidden",!0),t},f_=function(t,e){const s=Ne._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=Ne._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i},mm=function(t,e){for(const[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)},_(Ne,Yd);let cp=Ne;globalThis.pdfjsTestingUtils={HighlightOutliner:ip},tt.AbortException,tt.AnnotationEditorLayer,tt.AnnotationEditorParamsType,tt.AnnotationEditorType,tt.AnnotationEditorUIManager,tt.AnnotationLayer,tt.AnnotationMode,tt.ColorPicker,tt.DOMSVGFactory,tt.DrawLayer,tt.FeatureTest;var tA=tt.GlobalWorkerOptions;tt.ImageKind,tt.InvalidPDFException,tt.MissingPDFException,tt.OPS,tt.OutputScale,tt.PDFDataRangeTransport,tt.PDFDateString,tt.PDFWorker,tt.PasswordResponses,tt.PermissionFlag,tt.PixelsPerInch,tt.RenderingCancelledException,tt.TextLayer,tt.TouchManager,tt.UnexpectedResponseException,tt.Util,tt.VerbosityLevel,tt.XfaLayer,tt.build,tt.createValidAbsoluteUrl,tt.fetchData;var eA=tt.getDocument;tt.getFilenameFromUrl,tt.getPdfFilenameFromUrl,tt.getXfaPageViewport,tt.isDataScheme,tt.isPdfFile,tt.noContextMenu,tt.normalizeUnicode,tt.setLayerDimensions,tt.shadow,tt.stopEvent,tt.version;const sA={"pdfjs-dist":"4.10.38"};function iA(o){return new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>t(s.result)),s.addEventListener("error",e),s.readAsDataURL(o)})}const nA=sA["pdfjs-dist"].replace("^","");tA.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${nA}/pdf.worker.min.mjs`;async function rA(o){const t="data:application/pdf;base64,",e=await iA(o);if(typeof e=="string")return window.atob(e.slice(t.length))}function aA(o,t){return eA({data:o,password:t}).promise}const hs=new Map;function oA(o){const t=new pg(o);return hs.set(o,t),t}function hA(o,t){const e=Date.now();return{PDFId:`${o.name}-${e}`,name:o.name.replace(/.pdf/,""),updateDate:e,PDFBase64:t}}function lA(o,t){const e=o.getViewport({scale:t}),s=document.createElement("canvas"),i=s.getContext("2d"),n=Jx()/window.devicePixelRatio;s.width=Math.floor(e.width*n),s.height=Math.floor(e.height*n);const r={canvasContext:i,viewport:e,transform:[n,0,0,n,0,0]},a=o.render(r);return{canvas:s,renderTask:a}}async function cA({src:o},t,e){if(!o||!e)return null;const{objects:s,options:i}=await Bx(o),n=s.filter(a=>a!==null),r=Zw.groupSVGElements(n,i);return n.forEach(a=>{a.stroke=e}),r.hoverCursor="pointer",r.stroke=`${e}-${t}`,r}function uA(o,t){if(!hs.get(o))return;const s=1/3,i=bA(t,s);xb(o,i,s)}async function dA(o,t){const e=await Zx(t),s=Date.now(),n={PDFId:`${t.name}${s}`,name:t.name.replace(/.png|.jpg|.jpeg/,""),updateDate:s,PDFBase64:e};return wb(o,{url:e}),{...n,pages:1}}async function wb(o,{url:t,scale:e=.5}){if(!hs.get(o))return;const i=await Me.fromURL(t);i.scale(e),xb(o,i,e)}function xb(o,t,e){const s=hs.get(o);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function fA(o,t){if(!t)return;const{oCoords:e}=o;if(!e)return;const{x:s,y:i}=e.tl.touchCorner.tl,{height:n,width:r,scaleY:a,scaleX:h}=t;t.top=i-n*a/2,t.left=s-r*h/2,t.setCoords()}function gA(o,t,e){!e||!o||(e.scale(1/t),fA(o,e))}function pA(o,t){if(!o)return;const e=o._cornerSize||6;o.borderScaleFactor=1/t,o.cornerSize=e*(1/t),o.touchCornerSize=e*4*(1/t),o.setCoords()}function mA(o){const t=hs.get(o);t&&(t.discardActiveObject(),t.renderAll())}function vA(o){const t=hs.get(o);t&&(t.clear(),hs.delete(o))}function bA(o,t){return new Me(o,{scaleX:t,scaleY:t})}function up(o,t){if(!t)return;const{left:e,top:s,scaleX:i,scaleY:n,width:r,height:a}=o,h=t.x*r*i,c=t.y*a*n;o.set({left:e-h,top:s-c})}function Sb(o,t,e){var n;const s=o.type,i={"application/pdf":yA,"image/png":Ab,"image/jpeg":Ab};return((n=i[s])==null?void 0:n.call(i,o,t,e))??Promise.reject(new Error(`Unsupported ${s} file type.`))}async function yA(o,t,e){const s=await rA(o);if(!s)return;const i=hA(o,s);try{const n=await Cb({page:1,PDFBase64:s,scale:.8,password:t},e);return{...i,pages:n}}catch(n){return Promise.reject(n)}}async function Cb({page:o,PDFBase64:t,scale:e,password:s},i){try{const n=await aA(t,s),r=await n.getPage(o),{renderTask:a,canvas:h}=lA(r,e);return a.promise.then(()=>(i&&uA(i,h),n.numPages))}catch(n){return Promise.reject(n)}}async function Ab(o,t,e){if(e)return await dA(e,o)}async function _A(o,t){const e=hs.get(o);if(!e)return;const s=e==null?void 0:e.getActiveObject();if(!s)return;const i=await s.clone(w_);i instanceof Ls?i.forEachObject(n=>{e.add(n),t(e,n)}):(e.add(i),t(e,i)),up(i,{x:-.1,y:-.1}),e.setActiveObject(i)}function wA(o){const t=hs.get(o);if(!t)return;const e=t.getActiveObject();e&&(e instanceof Ls?(e.forEachObject(s=>{t.remove(s)}),t.discardActiveObject()):t.remove(e))}function Tb(o){const{id:t="",selectionOptions:e,pointerDown:s,pointerMove:i,pointerUp:n,selectionCreated:r,selectionCleared:a}=o||{},h=Z.useRef(null),c=Z.useRef(null),u=Z.useRef(1),d=Z.useRef({...__});function f(){if(!t||hs.has(t))return;const F=oA(t);return F.on("selection:created",L=>{if(r==null||r(L),L.selected.length<=1)return;const N=F.getActiveObject();N&&(c.current=N,e!=null&&e.value&&c.current.set(e.value),c.current._cornerSize=c.current.cornerSize,k(u.current))}),F.on("selection:cleared",L=>{a==null||a(L),P(F)}),s&&F.on("mouse:down",s),i&&F.on("mouse:move",i),n&&F.on("mouse:up",n),F}function g(F,L){return Sb(F,L,t)}function p(F){return Cb(F,t)}function m({url:F,scale:L=.5}){return wb(t,{url:F,scale:L})}async function y(F,L,N){const K=hs.get(t);if(!K)return;const I=await Me.fromURL(F,{},{...v_,...L});up(I,N),K.add(I),x(K,I),K.setActiveObject(I)}function b(F,L,N){const K=hs.get(t);if(!K)return;const I=new Pe(F,{...b_,...L});up(I,N),K.add(I),x(K,I),K.setActiveObject(I)}function x(F,L){L.on("selected",N=>S({canvas:F,target:N.target})),L.on("modified",N=>S({canvas:F,target:N.target})),L.on("scaling",()=>P(F)),L.on("moving",()=>P(F)),L.on("rotating",()=>P(F)),L._cornerSize=L._cornerSize??L.cornerSize}async function S({canvas:F,target:L,stroke:N=d.current.stroke,uuid:K=Date.now()}){var it;if(F.getActiveObjects().length>1||((it=h.current)==null?void 0:it.stroke)===`${N}-${K}`)return;const V=await cA(d.current,K,N);P(F),h.current=V,c.current=L,C(F,L,K),k(u.current,!0),V&&F.add(V)}function C(F,L,N){h.current&&(h.current.on("selected",()=>{F.remove(L),P(F)}),h.current.on("mouseover",()=>{S({canvas:F,target:L,stroke:d.current.hoverStroke,uuid:N})}),h.current.on("mouseout",()=>{S({canvas:F,target:L,stroke:d.current.stroke,uuid:N})}))}function k(F,L=!1){const N=hs.get(t);u.current=F,N&&(pA(c.current,F),gA(c.current,F,h.current),!L&&N.renderAll())}function O(F){if(!F)return;d.current={...d.current,...F};const L=hs.get(t);!h||!c.current||!L||S({target:c.current,canvas:L})}function P(F){c.current=null,h.current&&(F.remove(h.current),h.current=null)}function D(){mA(t)}function R(){vA(t)}function z(){return _A(t,x)}function B(){wA(t)}return{createCanvas:f,loadFile:g,specifyPage:p,renderImage:m,addFabric:y,addTextFabric:b,clearActive:D,deleteCanvas:R,scaleFabric:k,setCloseSvgOptions:O,copyActiveFabric:z,deleteActiveFabric:B}}function xA(o){let t=0;const e=Qx(()=>{t!==window.innerWidth&&(t=window.innerWidth,o())});Z.useEffect(()=>(window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)),[])}const SA=Z.forwardRef(CA);function CA({file:o,page:t=1,canvasId:e="PDF-canvas",fileZoom:s=1,fileScale:i=1,canvasScale:n=1,canvasClass:r="",isDrop:a=!1,password:h,dropTextOptions:c,dropImageOptions:u,closeSvgOptions:d,selectionOptions:f,manualReload:g,onLoaded:p,onReload:m,onPointerDown:y,onPointerMove:b,onPointerUp:x,onSelectionCreated:S,onSelectionCleared:C},k){const O=Z.useRef(null),P=`${e}-${t-1}`,D=Z.useMemo(()=>s*n,[s,n]),R=Z.useMemo(()=>({...y_,...f}),[f]),{createCanvas:z,specifyPage:B,addFabric:F,addTextFabric:L,renderImage:N,clearActive:K,deleteCanvas:I,scaleFabric:V,setCloseSvgOptions:it,copyActiveFabric:Ot,deleteActiveFabric:Bt}=Tb({id:P,selectionOptions:R,pointerDown:y,pointerMove:b,pointerUp:x,selectionCreated:S,selectionCleared:C});xA(Ze);async function Xt(){window.requestAnimationFrame(async()=>{if(z(),o.PDFBase64.startsWith("data:image")||o.canvas){const{canvas:st}=o,nt=st?7:3,Zt=st!=null&&st.length?st[t-1]:o.PDFBase64;N({url:Zt,scale:i/nt});return}await B({page:t,PDFBase64:o.PDFBase64,scale:i,password:h}),p==null||p()})}function Ft(st){if(st.preventDefault(),st.stopPropagation(),!a||!st.dataTransfer)return;const{dataTransfer:nt,nativeEvent:Zt}=st,{offsetX:$s,offsetY:Te}=Zt,$d=nt.getData("text/plain"),Uc=nt.getData("text/uri-list"),qd=nt.getData("custom/offset"),Pr=qd?JSON.parse(qd):null,no={top:Te,left:$s},Mr={x:(Pr==null?void 0:Pr.offsetX)??0,y:(Pr==null?void 0:Pr.offsetY)??0};Uc?_t(Uc,no,Mr):$d&&ae($d,no,Mr)}function _t(st,nt,Zt){F(st,{...u,...nt},Zt)}function ae(st,nt,Zt){L(st,{...c,...nt},Zt)}function Ze(){g||Xt(),m==null||m()}return Z.useImperativeHandle(k,()=>({reload:Xt,addImage:_t,addText:ae,clearActive:K,deleteCanvas:I,copyActiveFabric:Ot,deleteActiveFabric:Bt,canvasRef:O})),Z.useEffect(()=>{Ze()},[i,t,o,h]),Z.useEffect(()=>{V(D)},[D]),Z.useEffect(()=>{it(d)},[d]),Z.useEffect(()=>()=>I(),[]),ym.jsx("div",{style:{transform:`scale(${D})`},onDragOver:st=>st.preventDefault(),onDragEnter:st=>st.preventDefault(),onDrop:Ft,children:ym.jsx("canvas",{id:P,ref:O,className:r})})}dt.default=SA,dt.loadFile=Sb,dt.useFabric=Tb,Object.defineProperties(dt,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
540
+ `)}`),w(this,re,_f).call(this);const f=new Range;let g=u.reduce((b,x)=>b+x.length,0);for(const{firstChild:b}of this.editorDiv.childNodes)if(b.nodeType===Node.TEXT_NODE){const x=b.nodeValue.length;if(g<=x){f.setStart(b,g),f.setEnd(b,g);break}g-=x}r.removeAllRanges(),r.addRange(f)}get contentDiv(){return this.editorDiv}static async deserialize(e,s,i){var o;let n=null;if(e instanceof xb){const{data:{defaultAppearanceData:{fontSize:h,fontColor:c},rect:u,rotation:d,id:f,popupRef:g},textContent:p,textPosition:m,parent:{page:{pageNumber:y}}}=e;if(!p||p.length===0)return null;n=e={annotationType:at.FREETEXT,color:Array.from(c),fontSize:h,value:p.join(`
541
+ `),position:m,pageIndex:y-1,rect:u.slice(0),rotation:d,id:f,deleted:!1,popupRef:g}}const r=await super.deserialize(e,s,i);return v(r,Ts,e.fontSize),v(r,di,q.makeHexColor(...e.color)),v(r,As,w(o=Ot,On,nm).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=Ot._internalPadding*this.parentScale,i=this.getRect(s,s),n=Vt._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:l(this,di)),r={annotationType:at.FREETEXT,color:n,fontSize:l(this,Ts),value:w(this,re,Gy).call(this),pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?r:this.annotationElementId&&!w(this,re,Wy).call(this,r)?null:(r.id=this.annotationElementId,r)}renderAnnotationElement(e){const s=super.renderAnnotationElement(e);if(this.deleted)return s;const{style:i}=s;i.fontSize=`calc(${l(this,Ts)}px * var(--scale-factor))`,i.color=l(this,di),s.replaceChildren();for(const r of l(this,As).split(`
542
+ `)){const o=document.createElement("div");o.append(r?document.createTextNode(r):document.createElement("br")),s.append(o)}const n=Ot._internalPadding*this.parentScale;return e.updateEdited({rect:this.getRect(n,n),popupContent:l(this,As)}),s}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}};di=new WeakMap,As=new WeakMap,kc=new WeakMap,Vo=new WeakMap,Ts=new WeakMap,re=new WeakSet,Hy=function(e){const s=n=>{this.editorDiv.style.fontSize=`calc(${n}px * var(--scale-factor))`,this.translate(0,-(n-l(this,Ts))*this.parentScale),v(this,Ts,n),w(this,re,bf).call(this)},i=l(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:gt.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})},zy=function(e){const s=n=>{v(this,di,this.editorDiv.style.color=n)},i=l(this,di);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:gt.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})},Vy=function(){var i;const e=[];this.editorDiv.normalize();let s=null;for(const n of this.editorDiv.childNodes)(s==null?void 0:s.nodeType)===Node.TEXT_NODE&&n.nodeName==="BR"||(e.push(w(i=Ot,On,yf).call(i,n)),s=n);return e.join(`
543
+ `)},bf=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()},On=new WeakSet,yf=function(e){return(e.nodeType===Node.TEXT_NODE?e.nodeValue:e.innerText).replaceAll(Td,"")},_f=function(){if(this.editorDiv.replaceChildren(),!!l(this,As))for(const e of l(this,As).split(`
544
+ `)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},Gy=function(){return l(this,As).replaceAll(" "," ")},nm=function(e){return e.replaceAll(" "," ")},Wy=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},_(Ot,On),Q(Ot,"_freeTextDefaultContent",""),Q(Ot,"_internalPadding",0),Q(Ot,"_defaultColor",null),Q(Ot,"_defaultFontSize",10),Q(Ot,"_type","freetext"),Q(Ot,"_editorType",at.FREETEXT);let rp=Ot;class U{toSVGPath(){Pt("Abstract method `toSVGPath` must be implemented.")}get box(){Pt("Abstract getter `box` must be implemented.")}serialize(t,e){Pt("Abstract method `serialize` must be implemented.")}static _rescale(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o]*i,r[o+1]=s+t[o+1]*n;return r}static _rescaleAndSwap(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o+1]*i,r[o+1]=s+t[o]*n;return r}static _translate(t,e,s,i){i||(i=new Float32Array(t.length));for(let n=0,r=t.length;n<r;n+=2)i[n]=e+t[n],i[n+1]=s+t[n+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,s,i,n){switch(n){case 90:return[1-e/s,t/i];case 180:return[1-t/s,1-e/i];case 270:return[e/s,1-t/i];default:return[t/s,e/i]}}static _normalizePagePoint(t,e,s){switch(s){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}static createBezierPoints(t,e,s,i,n,r){return[(t+5*s)/6,(e+5*i)/6,(5*s+n)/6,(5*i+r)/6,(s+n)/2,(i+r)/2]}}Q(U,"PRECISION",1e-4);const Dn=class Dn{constructor({x:t,y:e},s,i,n,r,o=0){_(this,de);_(this,Es);_(this,fi,[]);_(this,dh);_(this,fh);_(this,Hi,[]);_(this,ut,new Float32Array(18));_(this,Go);_(this,Wo);_(this,Pc);_(this,Mc);_(this,gh);_(this,ph);_(this,br,[]);v(this,Es,s),v(this,ph,n*i),v(this,fh,r),l(this,ut).set([NaN,NaN,NaN,NaN,t,e],6),v(this,dh,o),v(this,Mc,l(Dn,Oc)*i),v(this,Pc,l(Dn,Ud)*i),v(this,gh,i),l(this,br).push(t,e)}isEmpty(){return isNaN(l(this,ut)[8])}add({x:t,y:e}){var R;v(this,Go,t),v(this,Wo,e);const[s,i,n,r]=l(this,Es);let[o,h,c,u]=l(this,ut).subarray(8,12);const d=t-c,f=e-u,g=Math.hypot(d,f);if(g<l(this,Pc))return!1;const p=g-l(this,Mc),m=p/g,y=m*d,b=m*f;let x=o,C=h;o=c,h=u,c+=y,u+=b,(R=l(this,br))==null||R.push(t,e);const S=-b/p,T=y/p,P=S*l(this,ph),M=T*l(this,ph);return l(this,ut).set(l(this,ut).subarray(2,8),0),l(this,ut).set([c+P,u+M],4),l(this,ut).set(l(this,ut).subarray(14,18),12),l(this,ut).set([c-P,u-M],16),isNaN(l(this,ut)[6])?(l(this,Hi).length===0&&(l(this,ut).set([o+P,h+M],2),l(this,Hi).push(NaN,NaN,NaN,NaN,(o+P-s)/n,(h+M-i)/r),l(this,ut).set([o-P,h-M],14),l(this,fi).push(NaN,NaN,NaN,NaN,(o-P-s)/n,(h-M-i)/r)),l(this,ut).set([x,C,o,h,c,u],6),!this.isEmpty()):(l(this,ut).set([x,C,o,h,c,u],6),Math.abs(Math.atan2(C-h,x-o)-Math.atan2(b,y))<Math.PI/2?([o,h,c,u]=l(this,ut).subarray(2,6),l(this,Hi).push(NaN,NaN,NaN,NaN,((o+c)/2-s)/n,((h+u)/2-i)/r),[o,h,x,C]=l(this,ut).subarray(14,18),l(this,fi).push(NaN,NaN,NaN,NaN,((x+o)/2-s)/n,((C+h)/2-i)/r),!0):([x,C,o,h,c,u]=l(this,ut).subarray(0,6),l(this,Hi).push(((x+5*o)/6-s)/n,((C+5*h)/6-i)/r,((5*o+c)/6-s)/n,((5*h+u)/6-i)/r,((o+c)/2-s)/n,((h+u)/2-i)/r),[c,u,o,h,x,C]=l(this,ut).subarray(12,18),l(this,fi).push(((x+5*o)/6-s)/n,((C+5*h)/6-i)/r,((5*o+c)/6-s)/n,((5*h+u)/6-i)/r,((o+c)/2-s)/n,((h+u)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=l(this,Hi),e=l(this,fi);if(isNaN(l(this,ut)[6])&&!this.isEmpty())return w(this,de,Xy).call(this);const s=[];s.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)isNaN(t[i])?s.push(`L${t[i+4]} ${t[i+5]}`):s.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);w(this,de,Yy).call(this,s);for(let i=e.length-6;i>=6;i-=6)isNaN(e[i])?s.push(`L${e[i+4]} ${e[i+5]}`):s.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return w(this,de,Uy).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new Tb(t,e,s,i,n,r)}getOutlines(){var d;const t=l(this,Hi),e=l(this,fi),s=l(this,ut),[i,n,r,o]=l(this,Es),h=new Float32Array((((d=l(this,br))==null?void 0:d.length)??0)+2);for(let f=0,g=h.length-2;f<g;f+=2)h[f]=(l(this,br)[f]-i)/r,h[f+1]=(l(this,br)[f+1]-n)/o;if(h[h.length-2]=(l(this,Go)-i)/r,h[h.length-1]=(l(this,Wo)-n)/o,isNaN(s[6])&&!this.isEmpty())return w(this,de,$y).call(this,h);const c=new Float32Array(l(this,Hi).length+24+l(this,fi).length);let u=t.length;for(let f=0;f<u;f+=2){if(isNaN(t[f])){c[f]=c[f+1]=NaN;continue}c[f]=t[f],c[f+1]=t[f+1]}u=w(this,de,Ky).call(this,c,u);for(let f=e.length-6;f>=6;f-=6)for(let g=0;g<6;g+=2){if(isNaN(e[f+g])){c[u]=c[u+1]=NaN,u+=2;continue}c[u]=e[f+g],c[u+1]=e[f+g+1],u+=2}return w(this,de,qy).call(this,c,u),this.newFreeDrawOutline(c,h,l(this,Es),l(this,gh),l(this,dh),l(this,fh))}};Es=new WeakMap,fi=new WeakMap,dh=new WeakMap,fh=new WeakMap,Hi=new WeakMap,ut=new WeakMap,Go=new WeakMap,Wo=new WeakMap,Pc=new WeakMap,Mc=new WeakMap,gh=new WeakMap,ph=new WeakMap,br=new WeakMap,Oc=new WeakMap,Xd=new WeakMap,Ud=new WeakMap,de=new WeakSet,nu=function(){const t=l(this,ut).subarray(4,6),e=l(this,ut).subarray(16,18),[s,i,n,r]=l(this,Es);return[(l(this,Go)+(t[0]-e[0])/2-s)/n,(l(this,Wo)+(t[1]-e[1])/2-i)/r,(l(this,Go)+(e[0]-t[0])/2-s)/n,(l(this,Wo)+(e[1]-t[1])/2-i)/r]},Xy=function(){const[t,e,s,i]=l(this,Es),[n,r,o,h]=w(this,de,nu).call(this);return`M${(l(this,ut)[2]-t)/s} ${(l(this,ut)[3]-e)/i} L${(l(this,ut)[4]-t)/s} ${(l(this,ut)[5]-e)/i} L${n} ${r} L${o} ${h} L${(l(this,ut)[16]-t)/s} ${(l(this,ut)[17]-e)/i} L${(l(this,ut)[14]-t)/s} ${(l(this,ut)[15]-e)/i} Z`},Uy=function(t){const e=l(this,fi);t.push(`L${e[4]} ${e[5]} Z`)},Yy=function(t){const[e,s,i,n]=l(this,Es),r=l(this,ut).subarray(4,6),o=l(this,ut).subarray(16,18),[h,c,u,d]=w(this,de,nu).call(this);t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${h} ${c} L${u} ${d} L${(o[0]-e)/i} ${(o[1]-s)/n}`)},$y=function(t){const e=l(this,ut),[s,i,n,r]=l(this,Es),[o,h,c,u]=w(this,de,nu).call(this),d=new Float32Array(36);return d.set([NaN,NaN,NaN,NaN,(e[2]-s)/n,(e[3]-i)/r,NaN,NaN,NaN,NaN,(e[4]-s)/n,(e[5]-i)/r,NaN,NaN,NaN,NaN,o,h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,(e[16]-s)/n,(e[17]-i)/r,NaN,NaN,NaN,NaN,(e[14]-s)/n,(e[15]-i)/r],0),this.newFreeDrawOutline(d,t,l(this,Es),l(this,gh),l(this,dh),l(this,fh))},qy=function(t,e){const s=l(this,fi);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},Ky=function(t,e){const s=l(this,ut).subarray(4,6),i=l(this,ut).subarray(16,18),[n,r,o,h]=l(this,Es),[c,u,d,f]=w(this,de,nu).call(this);return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/o,(s[1]-r)/h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,d,f,NaN,NaN,NaN,NaN,(i[0]-n)/o,(i[1]-r)/h],e),e+=24},_(Dn,Oc,8),_(Dn,Xd,2),_(Dn,Ud,l(Dn,Oc)+l(Dn,Xd));let Ed=Dn;class Tb extends U{constructor(e,s,i,n,r,o){super();_(this,Yd);_(this,mh);_(this,Xo,new Float32Array(4));_(this,Rn);_(this,Dc);_(this,ks);_(this,Rc);_(this,Qt);v(this,Qt,e),v(this,ks,s),v(this,mh,i),v(this,Rc,n),v(this,Rn,r),v(this,Dc,o),this.lastPoint=[NaN,NaN],w(this,Yd,Jy).call(this,o);const[h,c,u,d]=l(this,Xo);for(let f=0,g=e.length;f<g;f+=2)e[f]=(e[f]-h)/u,e[f+1]=(e[f+1]-c)/d;for(let f=0,g=s.length;f<g;f+=2)s[f]=(s[f]-h)/u,s[f+1]=(s[f+1]-c)/d}toSVGPath(){const e=[`M${l(this,Qt)[4]} ${l(this,Qt)[5]}`];for(let s=6,i=l(this,Qt).length;s<i;s+=6){if(isNaN(l(this,Qt)[s])){e.push(`L${l(this,Qt)[s+4]} ${l(this,Qt)[s+5]}`);continue}e.push(`C${l(this,Qt)[s]} ${l(this,Qt)[s+1]} ${l(this,Qt)[s+2]} ${l(this,Qt)[s+3]} ${l(this,Qt)[s+4]} ${l(this,Qt)[s+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,s,i,n],r){const o=i-e,h=n-s;let c,u;switch(r){case 0:c=U._rescale(l(this,Qt),e,n,o,-h),u=U._rescale(l(this,ks),e,n,o,-h);break;case 90:c=U._rescaleAndSwap(l(this,Qt),e,s,o,h),u=U._rescaleAndSwap(l(this,ks),e,s,o,h);break;case 180:c=U._rescale(l(this,Qt),i,s,-o,h),u=U._rescale(l(this,ks),i,s,-o,h);break;case 270:c=U._rescaleAndSwap(l(this,Qt),i,n,-o,-h),u=U._rescaleAndSwap(l(this,ks),i,n,-o,-h);break}return{outline:Array.from(c),points:[Array.from(u)]}}get box(){return l(this,Xo)}newOutliner(e,s,i,n,r,o=0){return new Ed(e,s,i,n,r,o)}getNewOutline(e,s){const[i,n,r,o]=l(this,Xo),[h,c,u,d]=l(this,mh),f=r*u,g=o*d,p=i*u+h,m=n*d+c,y=this.newOutliner({x:l(this,ks)[0]*f+p,y:l(this,ks)[1]*g+m},l(this,mh),l(this,Rc),e,l(this,Dc),s??l(this,Rn));for(let b=2;b<l(this,ks).length;b+=2)y.add({x:l(this,ks)[b]*f+p,y:l(this,ks)[b+1]*g+m});return y.getOutlines()}}mh=new WeakMap,Xo=new WeakMap,Rn=new WeakMap,Dc=new WeakMap,ks=new WeakMap,Rc=new WeakMap,Qt=new WeakMap,Yd=new WeakSet,Jy=function(e){const s=l(this,Qt);let i=s[4],n=s[5],r=i,o=n,h=i,c=n,u=i,d=n;const f=e?Math.max:Math.min;for(let p=6,m=s.length;p<m;p+=6){if(isNaN(s[p]))r=Math.min(r,s[p+4]),o=Math.min(o,s[p+5]),h=Math.max(h,s[p+4]),c=Math.max(c,s[p+5]),d<s[p+5]?(u=s[p+4],d=s[p+5]):d===s[p+5]&&(u=f(u,s[p+4]));else{const y=q.bezierBoundingBox(i,n,...s.slice(p,p+6));r=Math.min(r,y[0]),o=Math.min(o,y[1]),h=Math.max(h,y[2]),c=Math.max(c,y[3]),d<y[3]?(u=y[2],d=y[3]):d===y[3]&&(u=f(u,y[2]))}i=s[p+4],n=s[p+5]}const g=l(this,Xo);g[0]=r-l(this,Rn),g[1]=o-l(this,Rn),g[2]=h-r+2*l(this,Rn),g[3]=c-o+2*l(this,Rn),this.lastPoint=[u,d]};class op{constructor(t,e=0,s=0,i=!0){_(this,qe);_(this,Fc);_(this,Lc);_(this,yr,[]);_(this,gi,[]);let n=1/0,r=-1/0,o=1/0,h=-1/0;const c=10**-4;for(const{x:y,y:b,width:x,height:C}of t){const S=Math.floor((y-e)/c)*c,T=Math.ceil((y+x+e)/c)*c,P=Math.floor((b-e)/c)*c,M=Math.ceil((b+C+e)/c)*c,D=[S,P,M,!0],R=[T,P,M,!1];l(this,yr).push(D,R),n=Math.min(n,S),r=Math.max(r,T),o=Math.min(o,P),h=Math.max(h,M)}const u=r-n+2*s,d=h-o+2*s,f=n-s,g=o-s,p=l(this,yr).at(i?-1:-2),m=[p[0],p[2]];for(const y of l(this,yr)){const[b,x,C]=y;y[0]=(b-f)/u,y[1]=(x-g)/d,y[2]=(C-g)/d}v(this,Fc,new Float32Array([f,g,u,d])),v(this,Lc,m)}getOutlines(){l(this,yr).sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of l(this,yr))e[3]?(t.push(...w(this,qe,rm).call(this,e)),w(this,qe,Zy).call(this,e)):(w(this,qe,t_).call(this,e),t.push(...w(this,qe,rm).call(this,e)));return w(this,qe,Qy).call(this,t)}}Fc=new WeakMap,Lc=new WeakMap,yr=new WeakMap,gi=new WeakMap,qe=new WeakSet,Qy=function(t){const e=[],s=new Set;for(const r of t){const[o,h,c]=r;e.push([o,h,r],[o,c,r])}e.sort((r,o)=>r[1]-o[1]||r[0]-o[0]);for(let r=0,o=e.length;r<o;r+=2){const h=e[r][2],c=e[r+1][2];h.push(c),c.push(h),s.add(h),s.add(c)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[o,h,c,u,d]=r;s.delete(r);let f=o,g=h;for(n=[o,c],i.push(n);;){let p;if(s.has(u))p=u;else if(s.has(d))p=d;else break;s.delete(p),[o,h,c,u,d]=p,f!==o&&(n.push(f,g,o,g===h?h:c),f=o),g=g===h?c:h}n.push(f,g)}return new nA(i,l(this,Fc),l(this,Lc))},wf=function(t){const e=l(this,gi);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},Zy=function([,t,e]){const s=w(this,qe,wf).call(this,t);l(this,gi).splice(s,0,[t,e])},t_=function([,t,e]){const s=w(this,qe,wf).call(this,t);for(let i=s;i<l(this,gi).length;i++){const[n,r]=l(this,gi)[i];if(n!==t)break;if(n===t&&r===e){l(this,gi).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=l(this,gi)[i];if(n!==t)break;if(n===t&&r===e){l(this,gi).splice(i,1);return}}},rm=function(t){const[e,s,i]=t,n=[[e,s,i]],r=w(this,qe,wf).call(this,i);for(let o=0;o<r;o++){const[h,c]=l(this,gi)[o];for(let u=0,d=n.length;u<d;u++){const[,f,g]=n[u];if(!(c<=f||g<=h)){if(f>=h){if(g>c)n[u][1]=c;else{if(d===1)return[];n.splice(u,1),u--,d--}continue}n[u][2]=h,g>c&&n.push([e,c,g])}}}return n};class nA extends U{constructor(e,s,i){super();_(this,Ic);_(this,vh);v(this,vh,e),v(this,Ic,s),this.lastPoint=i}toSVGPath(){const e=[];for(const s of l(this,vh)){let[i,n]=s;e.push(`M${i} ${n}`);for(let r=2;r<s.length;r+=2){const o=s[r],h=s[r+1];o===i?(e.push(`V${h}`),n=h):h===n&&(e.push(`H${o}`),i=o)}e.push("Z")}return e.join(" ")}serialize([e,s,i,n],r){const o=[],h=i-e,c=n-s;for(const u of l(this,vh)){const d=new Array(u.length);for(let f=0;f<u.length;f+=2)d[f]=e+u[f]*h,d[f+1]=n-u[f+1]*c;o.push(d)}return o}get box(){return l(this,Ic)}get classNamesForOutlining(){return["highlightOutline"]}}Ic=new WeakMap,vh=new WeakMap;class ap extends Ed{newFreeDrawOutline(t,e,s,i,n,r){return new rA(t,e,s,i,n,r)}}class rA extends Tb{newOutliner(t,e,s,i,n,r=0){return new ap(t,e,s,i,n,r)}}const us=class us{constructor({editor:t=null,uiManager:e=null}){_(this,Et);_(this,pi,null);_(this,Uo,null);_(this,bh);_(this,fe,null);_(this,jc,!1);_(this,yh,!1);_(this,Nc,null);_(this,Bc);_(this,_r,null);_(this,mi,null);_(this,_h);var s;t?(v(this,yh,!1),v(this,_h,gt.HIGHLIGHT_COLOR),v(this,Nc,t)):(v(this,yh,!0),v(this,_h,gt.HIGHLIGHT_DEFAULT_COLOR)),v(this,mi,(t==null?void 0:t._uiManager)||e),v(this,Bc,l(this,mi)._eventBus),v(this,bh,(t==null?void 0:t.color)||((s=l(this,mi))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),l(us,Hc)||v(us,Hc,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 ct(this,"_keyboardManager",new pl([[["Escape","mac+Escape"],us.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],us.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],us.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],us.prototype._moveToPrevious],[["Home","mac+Home"],us.prototype._moveToBeginning],[["End","mac+End"],us.prototype._moveToEnd]]))}renderButton(){const t=v(this,pi,document.createElement("button"));t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.setAttribute("aria-haspopup",!0);const e=l(this,mi)._signal;t.addEventListener("click",w(this,Et,la).bind(this),{signal:e}),t.addEventListener("keydown",w(this,Et,hm).bind(this),{signal:e});const s=v(this,Uo,document.createElement("span"));return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=l(this,bh),t.append(s),t}renderMainDropdown(){const t=v(this,fe,w(this,Et,om).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===l(this,pi)){w(this,Et,la).call(this,t);return}const e=t.target.getAttribute("data-color");e&&w(this,Et,am).call(this,e,t)}_moveToNext(t){var e,s;if(!l(this,Et,Or)){w(this,Et,la).call(this,t);return}if(t.target===l(this,pi)){(e=l(this,fe).firstChild)==null||e.focus();return}(s=t.target.nextSibling)==null||s.focus()}_moveToPrevious(t){var e,s;if(t.target===((e=l(this,fe))==null?void 0:e.firstChild)||t.target===l(this,pi)){l(this,Et,Or)&&this._hideDropdownFromKeyboard();return}l(this,Et,Or)||w(this,Et,la).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!l(this,Et,Or)){w(this,Et,la).call(this,t);return}(e=l(this,fe).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!l(this,Et,Or)){w(this,Et,la).call(this,t);return}(e=l(this,fe).lastChild)==null||e.focus()}hideDropdown(){var t,e;(t=l(this,fe))==null||t.classList.add("hidden"),(e=l(this,_r))==null||e.abort(),v(this,_r,null)}_hideDropdownFromKeyboard(){var t;if(!l(this,yh)){if(!l(this,Et,Or)){(t=l(this,Nc))==null||t.unselect();return}this.hideDropdown(),l(this,pi).focus({preventScroll:!0,focusVisible:l(this,jc)})}}updateColor(t){if(l(this,Uo)&&(l(this,Uo).style.backgroundColor=t),!l(this,fe))return;const e=l(this,mi).highlightColors.values();for(const s of l(this,fe).children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){var t,e;(t=l(this,pi))==null||t.remove(),v(this,pi,null),v(this,Uo,null),(e=l(this,fe))==null||e.remove(),v(this,fe,null)}};pi=new WeakMap,Uo=new WeakMap,bh=new WeakMap,fe=new WeakMap,jc=new WeakMap,yh=new WeakMap,Nc=new WeakMap,Bc=new WeakMap,_r=new WeakMap,mi=new WeakMap,_h=new WeakMap,Hc=new WeakMap,Et=new WeakSet,om=function(){const t=document.createElement("div"),e=l(this,mi)._signal;t.addEventListener("contextmenu",ni,{signal:e}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[s,i]of l(this,mi).highlightColors){const n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",l(us,Hc)[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===l(this,bh)),n.addEventListener("click",w(this,Et,am).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",w(this,Et,hm).bind(this),{signal:e}),t},am=function(t,e){e.stopPropagation(),l(this,Bc).dispatch("switchannotationeditorparams",{source:this,type:l(this,_h),value:t})},hm=function(t){us._keyboardManager.exec(this,t)},la=function(t){if(l(this,Et,Or)){this.hideDropdown();return}if(v(this,jc,t.detail===0),l(this,_r)||(v(this,_r,new AbortController),window.addEventListener("pointerdown",w(this,Et,e_).bind(this),{signal:l(this,mi).combinedSignal(l(this,_r))})),l(this,fe)){l(this,fe).classList.remove("hidden");return}const e=v(this,fe,w(this,Et,om).call(this));l(this,pi).append(e)},e_=function(t){var e;(e=l(this,fe))!=null&&e.contains(t.target)||this.hideDropdown()},Or=function(){return l(this,fe)&&!l(this,fe).classList.contains("hidden")},_(us,Hc,null);let kd=us;const yt=class yt extends Vt{constructor(e){super({...e,name:"highlightEditor"});_(this,ot);_(this,wh,null);_(this,zc,0);_(this,Fn);_(this,Yo,null);_(this,xh,null);_(this,ds,null);_(this,Vc,null);_(this,Gc,0);_(this,$o,null);_(this,Vs,null);_(this,Ps,null);_(this,xe,!1);_(this,Sh,null);_(this,Ln);_(this,Ie,null);_(this,Ch,"");_(this,Gs);_(this,Wc,"");this.color=e.color||yt._defaultColor,v(this,Gs,e.thickness||yt._defaultThickness),v(this,Ln,e.opacity||yt._defaultOpacity),v(this,Fn,e.boxes||null),v(this,Wc,e.methodOfCreation||""),v(this,Ch,e.text||""),this._isDraggable=!1,e.highlightId>-1?(v(this,xe,!0),w(this,ot,xf).call(this,e),w(this,ot,ca).call(this)):l(this,Fn)&&(v(this,wh,e.anchorNode),v(this,zc,e.anchorOffset),v(this,Vc,e.focusNode),v(this,Gc,e.focusOffset),w(this,ot,lm).call(this),w(this,ot,ca).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=yt.prototype;return ct(this,"_keyboardManager",new pl([[["ArrowLeft","mac+ArrowLeft"],e._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],e._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],e._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],e._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:l(this,xe)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:l(this,Gs),methodOfCreation:l(this,Wc)}}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;Vt.initialize(e,s),yt._defaultColor||(yt._defaultColor=((i=s.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,s){switch(e){case gt.HIGHLIGHT_DEFAULT_COLOR:yt._defaultColor=s;break;case gt.HIGHLIGHT_THICKNESS:yt._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return l(this,Sh)}updateParams(e,s){switch(e){case gt.HIGHLIGHT_COLOR:w(this,ot,s_).call(this,s);break;case gt.HIGHLIGHT_THICKNESS:w(this,ot,i_).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[gt.HIGHLIGHT_DEFAULT_COLOR,yt._defaultColor],[gt.HIGHLIGHT_THICKNESS,yt._defaultThickness]]}get propertiesToUpdate(){return[[gt.HIGHLIGHT_COLOR,this.color||yt._defaultColor],[gt.HIGHLIGHT_THICKNESS,l(this,Gs)||yt._defaultThickness],[gt.HIGHLIGHT_FREE,l(this,xe)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(v(this,xh,new kd({editor:this})),e.addColorPicker(l(this,xh))),e):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(w(this,ot,ru).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,w(this,ot,ru).call(this))}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),e&&this.div.focus()}remove(){w(this,ot,cm).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,ot,ca).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?w(this,ot,cm).call(this):e&&(w(this,ot,ca).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),this.show(this._isVisible),s&&this.select()}rotate(e){var n,r,o;const{drawLayer:s}=this.parent;let i;l(this,xe)?(e=(e-this.rotation+360)%360,i=w(n=yt,Ws,Gh).call(n,l(this,Vs).box,e)):i=w(r=yt,Ws,Gh).call(r,[this.x,this.y,this.width,this.height],e),s.updateProperties(l(this,Ps),{bbox:i,root:{"data-main-rotation":e}}),s.updateProperties(l(this,Ie),{bbox:w(o=yt,Ws,Gh).call(o,l(this,ds).box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();l(this,Ch)&&(e.setAttribute("aria-label",l(this,Ch)),e.setAttribute("role","mark")),l(this,xe)?e.classList.add("free"):this.div.addEventListener("keydown",w(this,ot,r_).bind(this),{signal:this._uiManager._signal});const s=v(this,$o,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=l(this,Yo);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),bd(this,l(this,$o),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Ie),{rootClass:{hovered:!0}})}pointerleave(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Ie),{rootClass:{hovered:!1}})}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:w(this,ot,Sf).call(this,!0);break;case 1:case 3:w(this,ot,Sf).call(this,!1);break}}select(){var e;super.select(),l(this,Ie)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Ie),{rootClass:{hovered:!1,selected:!0}}))}unselect(){var e;super.unselect(),l(this,Ie)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Ie),{rootClass:{selected:!1}}),l(this,xe)||w(this,ot,Sf).call(this,!1))}get _mustFixPosition(){return!l(this,xe)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(l(this,Ps),{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(l(this,Ie),{rootClass:{hidden:!e}}))}static startHighlighting(e,s,{target:i,x:n,y:r}){const{x:o,y:h,width:c,height:u}=i.getBoundingClientRect(),d=new AbortController,f=e.combinedSignal(d),g=p=>{d.abort(),w(this,Ws,l_).call(this,e,p)};window.addEventListener("blur",g,{signal:f}),window.addEventListener("pointerup",g,{signal:f}),window.addEventListener("pointerdown",bs,{capture:!0,passive:!1,signal:f}),window.addEventListener("contextmenu",ni,{signal:f}),i.addEventListener("pointermove",w(this,Ws,h_).bind(this,e),{signal:f}),this._freeHighlight=new ap({x:n,y:r},[o,h,c,u],e.scale,this._defaultThickness/2,s,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static async deserialize(e,s,i){var m,y,b,x;let n=null;if(e instanceof Cb){const{data:{quadPoints:C,rect:S,rotation:T,id:P,color:M,opacity:D,popupRef:R},parent:{page:{pageNumber:V}}}=e;n=e={annotationType:at.HIGHLIGHT,color:Array.from(M),opacity:D,quadPoints:C,boxes:null,pageIndex:V-1,rect:S.slice(0),rotation:T,id:P,deleted:!1,popupRef:R}}else if(e instanceof np){const{data:{inkLists:C,rect:S,rotation:T,id:P,color:M,borderStyle:{rawWidth:D},popupRef:R},parent:{page:{pageNumber:V}}}=e;n=e={annotationType:at.HIGHLIGHT,color:Array.from(M),thickness:D,inkLists:C,boxes:null,pageIndex:V-1,rect:S.slice(0),rotation:T,id:P,deleted:!1,popupRef:R}}const{color:r,quadPoints:o,inkLists:h,opacity:c}=e,u=await super.deserialize(e,s,i);u.color=q.makeHexColor(...r),v(u,Ln,c||1),h&&v(u,Gs,e.thickness),u.annotationElementId=e.id||null,u._initialData=n;const[d,f]=u.pageDimensions,[g,p]=u.pageTranslation;if(o){const C=v(u,Fn,[]);for(let S=0;S<o.length;S+=8)C.push({x:(o[S]-g)/d,y:1-(o[S+1]-p)/f,width:(o[S+2]-o[S])/d,height:(o[S+1]-o[S+5])/f});w(m=u,ot,lm).call(m),w(y=u,ot,ca).call(y),u.rotate(u.rotation)}else if(h){v(u,xe,!0);const C=h[0],S={x:C[0]-g,y:f-(C[1]-p)},T=new ap(S,[0,0,d,f],1,l(u,Gs)/2,!0,.001);for(let D=0,R=C.length;D<R;D+=2)S.x=C[D]-g,S.y=f-(C[D+1]-p),T.add(S);const{id:P,clipPathId:M}=s.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:u.color,"fill-opacity":u._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:T.toSVGPath()}},!0,!0);w(b=u,ot,xf).call(b,{highlightOutlines:T.getOutlines(),highlightId:P,clipPathId:M}),w(x=u,ot,ca).call(x)}return u}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();const s=this.getRect(0,0),i=Vt._colorManager.convert(this.color),n={annotationType:at.HIGHLIGHT,color:i,opacity:l(this,Ln),thickness:l(this,Gs),quadPoints:w(this,ot,o_).call(this),outlines:w(this,ot,a_).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:w(this,ot,ru).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!w(this,ot,c_).call(this,n)?null:(n.id=this.annotationElementId,n)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};wh=new WeakMap,zc=new WeakMap,Fn=new WeakMap,Yo=new WeakMap,xh=new WeakMap,ds=new WeakMap,Vc=new WeakMap,Gc=new WeakMap,$o=new WeakMap,Vs=new WeakMap,Ps=new WeakMap,xe=new WeakMap,Sh=new WeakMap,Ln=new WeakMap,Ie=new WeakMap,Ch=new WeakMap,Gs=new WeakMap,Wc=new WeakMap,ot=new WeakSet,lm=function(){const e=new op(l(this,Fn),.001);v(this,Vs,e.getOutlines()),[this.x,this.y,this.width,this.height]=l(this,Vs).box;const s=new op(l(this,Fn),.0025,.001,this._uiManager.direction==="ltr");v(this,ds,s.getOutlines());const{lastPoint:i}=l(this,ds);v(this,Sh,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height])},xf=function({highlightOutlines:e,highlightId:s,clipPathId:i}){var d,f;if(v(this,Vs,e),v(this,ds,e.getNewOutline(l(this,Gs)/2+1.5,.0025)),s>=0)v(this,Ps,s),v(this,Yo,i),this.parent.drawLayer.finalizeDraw(s,{bbox:e.box,path:{d:e.toSVGPath()}}),v(this,Ie,this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:l(this,ds).box,path:{d:l(this,ds).toSVGPath()}},!0));else if(this.parent){const g=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(l(this,Ps),{bbox:w(d=yt,Ws,Gh).call(d,l(this,Vs).box,(g-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(l(this,Ie),{bbox:w(f=yt,Ws,Gh).call(f,l(this,ds).box,g),path:{d:l(this,ds).toSVGPath()}})}const[r,o,h,c]=e.box;switch(this.rotation){case 0:this.x=r,this.y=o,this.width=h,this.height=c;break;case 90:{const[g,p]=this.parentDimensions;this.x=o,this.y=1-r,this.width=h*p/g,this.height=c*g/p;break}case 180:this.x=1-r,this.y=1-o,this.width=h,this.height=c;break;case 270:{const[g,p]=this.parentDimensions;this.x=1-o,this.y=r,this.width=h*p/g,this.height=c*g/p;break}}const{lastPoint:u}=l(this,ds);v(this,Sh,[(u[0]-r)/h,(u[1]-o)/c])},s_=function(e){const s=(r,o)=>{var h,c;this.color=r,v(this,Ln,o),(h=this.parent)==null||h.drawLayer.updateProperties(l(this,Ps),{root:{fill:r,"fill-opacity":o}}),(c=l(this,xh))==null||c.updateColor(r)},i=this.color,n=l(this,Ln);this.addCommands({cmd:s.bind(this,e,yt._defaultOpacity),undo:s.bind(this,i,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:gt.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},i_=function(e){const s=l(this,Gs),i=n=>{v(this,Gs,n),w(this,ot,n_).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:gt.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},n_=function(e){if(!l(this,xe))return;w(this,ot,xf).call(this,{highlightOutlines:l(this,Vs).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},cm=function(){l(this,Ps)===null||!this.parent||(this.parent.drawLayer.remove(l(this,Ps)),v(this,Ps,null),this.parent.drawLayer.remove(l(this,Ie)),v(this,Ie,null))},ca=function(e=this.parent){l(this,Ps)===null&&({id:es(this,Ps)._,clipPathId:es(this,Yo)._}=e.drawLayer.draw({bbox:l(this,Vs).box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":l(this,Ln)},rootClass:{highlight:!0,free:l(this,xe)},path:{d:l(this,Vs).toSVGPath()}},!1,!0),v(this,Ie,e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:l(this,xe)},bbox:l(this,ds).box,path:{d:l(this,ds).toSVGPath()}},l(this,xe))),l(this,$o)&&(l(this,$o).style.clipPath=l(this,Yo)))},Ws=new WeakSet,Gh=function([e,s,i,n],r){switch(r){case 90:return[1-s-n,e,n,i];case 180:return[1-e-i,1-s-n,i,n];case 270:return[s,1-e-i,n,i]}return[e,s,i,n]},r_=function(e){yt._keyboardManager.exec(this,e)},Sf=function(e){if(!l(this,wh))return;const s=window.getSelection();e?s.setPosition(l(this,wh),l(this,zc)):s.setPosition(l(this,Vc),l(this,Gc))},ru=function(){return l(this,xe)?this.rotation:0},o_=function(){if(l(this,xe))return null;const[e,s]=this.pageDimensions,[i,n]=this.pageTranslation,r=l(this,Fn),o=new Float32Array(r.length*8);let h=0;for(const{x:c,y:u,width:d,height:f}of r){const g=c*e+i,p=(1-u)*s+n;o[h]=o[h+4]=g,o[h+1]=o[h+3]=p,o[h+2]=o[h+6]=g+d*e,o[h+5]=o[h+7]=p-f*s,h+=8}return o},a_=function(e){return l(this,Vs).serialize(e,w(this,ot,ru).call(this))},h_=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},l_=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=""},c_=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},_(yt,Ws),Q(yt,"_defaultColor",null),Q(yt,"_defaultOpacity",1),Q(yt,"_defaultThickness",12),Q(yt,"_type","highlight"),Q(yt,"_editorType",at.HIGHLIGHT),Q(yt,"_freeHighlightId",-1),Q(yt,"_freeHighlight",null),Q(yt,"_freeHighlightClipId","");let Pd=yt;class oA{constructor(){_(this,qo,Object.create(null))}updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(const[e,s]of Object.entries(t))this.updateProperty(e,s)}updateSVGProperty(t,e){l(this,qo)[t]=e}toSVGProperties(){const t=l(this,qo);return v(this,qo,Object.create(null)),{root:t}}reset(){v(this,qo,Object.create(null))}updateAll(t=this){this.updateProperties(t)}clone(){Pt("Not implemented")}}qo=new WeakMap;const Y=class Y extends Vt{constructor(e){super(e);_(this,vt);_(this,Ms,null);_(this,Ah);Q(this,"_drawId",null);v(this,Ah,e.mustBeCommitted||!1),e.drawOutlines&&(w(this,vt,um).call(this,e),w(this,vt,ou).call(this))}static _mergeSVGProperties(e,s){const i=new Set(Object.keys(e));for(const[n,r]of Object.entries(s))i.has(n)?Object.assign(e[n],r):e[n]=r;return e}static getDefaultDrawingOptions(e){Pt("Not implemented")}static get typesMap(){Pt("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,s){const i=this.typesMap.get(e);i&&this._defaultDrawingOptions.updateProperty(i,s),this._currentParent&&(l(Y,ve).updateProperty(i,s),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,s){const i=this.constructor.typesMap.get(e);i&&this._updateProperty(e,i,s)}static get defaultPropertiesToUpdate(){const e=[],s=this._defaultDrawingOptions;for(const[i,n]of this.typesMap)e.push([i,s[n]]);return e}get propertiesToUpdate(){const e=[],{_drawingOptions:s}=this;for(const[i,n]of this.constructor.typesMap)e.push([i,s[n]]);return e}_updateProperty(e,s,i){const n=this._drawingOptions,r=n[s],o=h=>{var u;n.updateProperty(s,h);const c=l(this,Ms).updateProperty(s,h);c&&w(this,vt,au).call(this,c),(u=this.parent)==null||u.drawLayer.updateProperties(this._drawId,n.toSVGProperties())};this.addCommands({cmd:o.bind(this,i),undo:o.bind(this,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,Y._mergeSVGProperties(l(this,Ms).getPathResizingSVGProperties(w(this,vt,Cf).call(this)),{bbox:w(this,vt,Wh).call(this)}))}_onResized(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,Y._mergeSVGProperties(l(this,Ms).getPathResizedSVGProperties(w(this,vt,Cf).call(this)),{bbox:w(this,vt,Wh).call(this)}))}_onTranslating(e,s){var i;(i=this.parent)==null||i.drawLayer.updateProperties(this._drawId,{bbox:w(this,vt,Wh).call(this,e,s)})}_onTranslated(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,Y._mergeSVGProperties(l(this,Ms).getPathTranslatedSVGProperties(w(this,vt,Cf).call(this),this.parentDimensions),{bbox:w(this,vt,Wh).call(this)}))}_onStartDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit(),this.disableEditMode(),this.disableEditing()}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,l(this,Ah)&&(v(this,Ah,!1),this.commit(),this.parent.setSelected(this),e&&this.isOnScreen&&this.div.focus())}remove(){w(this,vt,fm).call(this),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,vt,ou).call(this),w(this,vt,au).call(this,l(this,Ms).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),w(this,vt,fm).call(this)):e&&(this._uiManager.addShouldRescale(this),w(this,vt,ou).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),s&&this.select()}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,Y._mergeSVGProperties({bbox:w(this,vt,Wh).call(this)},l(this,Ms).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&w(this,vt,au).call(this,l(this,Ms).updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;const e=super.render();e.classList.add("draw");const s=document.createElement("div");e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal";const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),this._uiManager.addShouldRescale(this),this.disableEditing(),e}static createDrawerInstance(e,s,i,n,r){Pt("Not implemented")}static startDrawing(e,s,i,n){var y;const{target:r,offsetX:o,offsetY:h,pointerId:c,pointerType:u}=n;if(l(Y,xr)&&l(Y,xr)!==u)return;const{viewport:{rotation:d}}=e,{width:f,height:g}=r.getBoundingClientRect(),p=v(Y,Ko,new AbortController),m=e.combinedSignal(p);if(l(Y,wr)||v(Y,wr,c),l(Y,xr)??v(Y,xr,u),window.addEventListener("pointerup",b=>{var x;l(Y,wr)===b.pointerId?this._endDraw(b):(x=l(Y,Sr))==null||x.delete(b.pointerId)},{signal:m}),window.addEventListener("pointercancel",b=>{var x;l(Y,wr)===b.pointerId?this._currentParent.endDrawingSession():(x=l(Y,Sr))==null||x.delete(b.pointerId)},{signal:m}),window.addEventListener("pointerdown",b=>{l(Y,xr)===b.pointerType&&((l(Y,Sr)||v(Y,Sr,new Set)).add(b.pointerId),l(Y,ve).isCancellable()&&(l(Y,ve).removeLastElement(),l(Y,ve).isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:m}),window.addEventListener("contextmenu",ni,{signal:m}),r.addEventListener("pointermove",this._drawMove.bind(this),{signal:m}),r.addEventListener("touchmove",b=>{b.timeStamp===l(Y,Qo)&&bs(b)},{signal:m}),e.toggleDrawing(),(y=s._editorUndoBar)==null||y.hide(),l(Y,ve)){e.drawLayer.updateProperties(this._currentDrawId,l(Y,ve).startNew(o,h,f,g,d));return}s.updateUIForDefaultProperties(this),v(Y,ve,this.createDrawerInstance(o,h,f,g,d)),v(Y,Jo,this.getDefaultDrawingOptions()),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(l(Y,Jo).toSVGProperties(),l(Y,ve).defaultSVGProperties),!0,!1)}static _drawMove(e){var r;if(v(Y,Qo,-1),!l(Y,ve))return;const{offsetX:s,offsetY:i,pointerId:n}=e;if(l(Y,wr)===n){if(((r=l(Y,Sr))==null?void 0:r.size)>=1){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,l(Y,ve).add(s,i)),v(Y,Qo,e.timeStamp),bs(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,v(Y,ve,null),v(Y,Jo,null),v(Y,xr,null),v(Y,Qo,NaN)),l(Y,Ko)&&(l(Y,Ko).abort(),v(Y,Ko,null),v(Y,wr,NaN),v(Y,Sr,null))}static _endDraw(e){const s=this._currentParent;if(s){if(s.toggleDrawing(!0),this._cleanup(!1),e&&s.drawLayer.updateProperties(this._currentDrawId,l(Y,ve).end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const i=l(Y,ve),n=this._currentDrawId,r=i.getLastElement();s.addCommands({cmd:()=>{s.drawLayer.updateProperties(n,i.setLastElement(r))},undo:()=>{s.drawLayer.updateProperties(n,i.removeLastElement())},mustExec:!1,type:gt.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const s=this._currentParent;if(!s)return null;if(s.toggleDrawing(!0),s.cleanUndoStack(gt.DRAW_STEP),!l(Y,ve).isEmpty()){const{pageDimensions:[i,n],scale:r}=s,o=s.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:l(Y,ve).getOutlines(i*r,n*r,r,this._INNER_MARGIN),drawingOptions:l(Y,Jo),mustBeCommitted:!e});return this._cleanup(!0),o}return s.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(e){}static deserializeDraw(e,s,i,n,r,o){Pt("Not implemented")}static async deserialize(e,s,i){var d,f;const{rawDims:{pageWidth:n,pageHeight:r,pageX:o,pageY:h}}=s.viewport,c=this.deserializeDraw(o,h,n,r,this._INNER_MARGIN,e),u=await super.deserialize(e,s,i);return u.createDrawingOptions(e),w(d=u,vt,um).call(d,{drawOutlines:c}),w(f=u,vt,ou).call(f),u.onScaleChanging(),u.rotate(),u}serializeDraw(e){const[s,i]=this.pageTranslation,[n,r]=this.pageDimensions;return l(this,Ms).serialize([s,i,n,r],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};Ms=new WeakMap,Ah=new WeakMap,ve=new WeakMap,Ko=new WeakMap,Jo=new WeakMap,wr=new WeakMap,xr=new WeakMap,Sr=new WeakMap,Qo=new WeakMap,vt=new WeakSet,um=function({drawOutlines:e,drawId:s,drawingOptions:i}){v(this,Ms,e),this._drawingOptions||(this._drawingOptions=i),s>=0?(this._drawId=s,this.parent.drawLayer.finalizeDraw(s,e.defaultProperties)):this._drawId=w(this,vt,dm).call(this,e,this.parent),w(this,vt,au).call(this,e.box)},dm=function(e,s){const{id:i}=s.drawLayer.draw(Y._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return i},fm=function(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())},ou=function(e=this.parent){if(!(this._drawId!==null&&this.parent===e)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,e.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=w(this,vt,dm).call(this,l(this,Ms),e)}},u_=function([e,s,i,n]){const{parentDimensions:[r,o],rotation:h}=this;switch(h){case 90:return[s,1-e,i*(o/r),n*(r/o)];case 180:return[1-e,1-s,i,n];case 270:return[1-s,e,i*(o/r),n*(r/o)];default:return[e,s,i,n]}},Cf=function(){const{x:e,y:s,width:i,height:n,parentDimensions:[r,o],rotation:h}=this;switch(h){case 90:return[1-s,e,i*(r/o),n*(o/r)];case 180:return[1-e,1-s,i,n];case 270:return[s,1-e,i*(r/o),n*(o/r)];default:return[e,s,i,n]}},au=function(e){if([this.x,this.y,this.width,this.height]=w(this,vt,u_).call(this,e),this.div){this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)}this._onResized()},Wh=function(){const{x:e,y:s,width:i,height:n,rotation:r,parentRotation:o,parentDimensions:[h,c]}=this;switch((r*4+o)/90){case 1:return[1-s-n,e,n,i];case 2:return[1-e-i,1-s-n,i,n];case 3:return[s,1-e-i,n,i];case 4:return[e,s-i*(h/c),n*(c/h),i*(h/c)];case 5:return[1-s,e,i*(h/c),n*(c/h)];case 6:return[1-e-n*(c/h),1-s,n*(c/h),i*(h/c)];case 7:return[s-i*(h/c),1-e-n*(c/h),i*(h/c),n*(c/h)];case 8:return[e-i,s-n,i,n];case 9:return[1-s,e-i,n,i];case 10:return[1-e,1-s,i,n];case 11:return[s-n,1-e,n,i];case 12:return[e-n*(c/h),s,n*(c/h),i*(h/c)];case 13:return[1-s-i*(h/c),e-n*(c/h),i*(h/c),n*(c/h)];case 14:return[1-e,1-s-i*(h/c),n*(c/h),i*(h/c)];case 15:return[s,1-e,i*(h/c),n*(c/h)];default:return[e,s,i,n]}},Q(Y,"_currentDrawId",-1),Q(Y,"_currentParent",null),_(Y,ve,null),_(Y,Ko,null),_(Y,Jo,null),_(Y,wr,NaN),_(Y,xr,null),_(Y,Sr,null),_(Y,Qo,NaN),Q(Y,"_INNER_MARGIN",3);let hp=Y;class aA{constructor(t,e,s,i,n,r){_(this,Eh);_(this,zi,new Float64Array(6));_(this,be);_(this,ye);_(this,Zo);_(this,Th);_(this,Ke);_(this,Se,"");_(this,Xs,0);_(this,ta,new Md);_(this,ea);_(this,sa);v(this,ea,s),v(this,sa,i),v(this,Zo,n),v(this,Th,r),[t,e]=w(this,Eh,Af).call(this,t,e);const o=v(this,be,[NaN,NaN,NaN,NaN,t,e]);v(this,Ke,[t,e]),v(this,ye,[{line:o,points:l(this,Ke)}]),l(this,zi).set(o,0)}updateProperty(t,e){t==="stroke-width"&&v(this,Th,e)}isEmpty(){return!l(this,ye)||l(this,ye).length===0}isCancellable(){return l(this,Ke).length<=10}add(t,e){[t,e]=w(this,Eh,Af).call(this,t,e);const[s,i,n,r]=l(this,zi).subarray(2,6),o=t-n,h=e-r;return Math.hypot(l(this,ea)*o,l(this,sa)*h)<=2?null:(l(this,Ke).push(t,e),isNaN(s)?(l(this,zi).set([n,r,t,e],2),l(this,be).push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(l(this,zi)[0])&&l(this,be).splice(6,6),l(this,zi).set([s,i,n,r,t,e],0),l(this,be).push(...U.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const s=this.add(t,e);return s||(l(this,Ke).length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){v(this,ea,s),v(this,sa,i),v(this,Zo,n),[t,e]=w(this,Eh,Af).call(this,t,e);const r=v(this,be,[NaN,NaN,NaN,NaN,t,e]);v(this,Ke,[t,e]);const o=l(this,ye).at(-1);return o&&(o.line=new Float32Array(o.line),o.points=new Float32Array(o.points)),l(this,ye).push({line:r,points:l(this,Ke)}),l(this,zi).set(r,0),v(this,Xs,0),this.toSVGPath(),null}getLastElement(){return l(this,ye).at(-1)}setLastElement(t){return l(this,ye)?(l(this,ye).push(t),v(this,be,t.line),v(this,Ke,t.points),v(this,Xs,0),{path:{d:this.toSVGPath()}}):l(this,ta).setLastElement(t)}removeLastElement(){if(!l(this,ye))return l(this,ta).removeLastElement();l(this,ye).pop(),v(this,Se,"");for(let t=0,e=l(this,ye).length;t<e;t++){const{line:s,points:i}=l(this,ye)[t];v(this,be,s),v(this,Ke,i),v(this,Xs,0),this.toSVGPath()}return{path:{d:l(this,Se)}}}toSVGPath(){const t=U.svgRound(l(this,be)[4]),e=U.svgRound(l(this,be)[5]);if(l(this,Ke).length===2)return v(this,Se,`${l(this,Se)} M ${t} ${e} Z`),l(this,Se);if(l(this,Ke).length<=6){const i=l(this,Se).lastIndexOf("M");v(this,Se,`${l(this,Se).slice(0,i)} M ${t} ${e}`),v(this,Xs,6)}if(l(this,Ke).length===4){const i=U.svgRound(l(this,be)[10]),n=U.svgRound(l(this,be)[11]);return v(this,Se,`${l(this,Se)} L ${i} ${n}`),v(this,Xs,12),l(this,Se)}const s=[];l(this,Xs)===0&&(s.push(`M ${t} ${e}`),v(this,Xs,6));for(let i=l(this,Xs),n=l(this,be).length;i<n;i+=6){const[r,o,h,c,u,d]=l(this,be).slice(i,i+6).map(U.svgRound);s.push(`C${r} ${o} ${h} ${c} ${u} ${d}`)}return v(this,Se,l(this,Se)+s.join(" ")),v(this,Xs,l(this,be).length),l(this,Se)}getOutlines(t,e,s,i){const n=l(this,ye).at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),l(this,ta).build(l(this,ye),t,e,s,l(this,Zo),l(this,Th),i),v(this,zi,null),v(this,be,null),v(this,ye,null),v(this,Se,null),l(this,ta)}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}zi=new WeakMap,be=new WeakMap,ye=new WeakMap,Zo=new WeakMap,Th=new WeakMap,Ke=new WeakMap,Se=new WeakMap,Xs=new WeakMap,ta=new WeakMap,ea=new WeakMap,sa=new WeakMap,Eh=new WeakSet,Af=function(t,e){return U._normalizePoint(t,e,l(this,ea),l(this,sa),l(this,Zo))};const yp=class yp extends U{constructor(){super(...arguments);_(this,Ce);_(this,Je);_(this,Xc,0);_(this,Uc);_(this,Os);_(this,Vi);_(this,Gi);_(this,kh);_(this,Ph);_(this,Mh)}build(e,s,i,n,r,o,h){v(this,Vi,s),v(this,Gi,i),v(this,kh,n),v(this,Ph,r),v(this,Mh,o),v(this,Uc,h??0),v(this,Os,e),w(this,Ce,f_).call(this)}setLastElement(e){return l(this,Os).push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return l(this,Os).pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:s}of l(this,Os)){if(e.push(`M${U.svgRound(s[4])} ${U.svgRound(s[5])}`),s.length===6){e.push("Z");continue}if(s.length===12){e.push(`L${U.svgRound(s[10])} ${U.svgRound(s[11])}`);continue}for(let i=6,n=s.length;i<n;i+=6){const[r,o,h,c,u,d]=s.subarray(i,i+6).map(U.svgRound);e.push(`C${r} ${o} ${h} ${c} ${u} ${d}`)}}return e.join("")}serialize([e,s,i,n],r){const o=[],h=[],[c,u,d,f]=w(this,Ce,d_).call(this);let g,p,m,y,b,x,C,S,T;switch(l(this,Ph)){case 0:T=U._rescale,g=e,p=s+n,m=i,y=-n,b=e+c*i,x=s+(1-u-f)*n,C=e+(c+d)*i,S=s+(1-u)*n;break;case 90:T=U._rescaleAndSwap,g=e,p=s,m=i,y=n,b=e+u*i,x=s+c*n,C=e+(u+f)*i,S=s+(c+d)*n;break;case 180:T=U._rescale,g=e+i,p=s,m=-i,y=n,b=e+(1-c-d)*i,x=s+u*n,C=e+(1-c)*i,S=s+(u+f)*n;break;case 270:T=U._rescaleAndSwap,g=e+i,p=s+n,m=-i,y=-n,b=e+(1-u-f)*i,x=s+(1-c-d)*n,C=e+(1-u)*i,S=s+(1-c)*n;break}for(const{line:P,points:M}of l(this,Os))o.push(T(P,g,p,m,y,r?new Array(P.length):null)),h.push(T(M,g,p,m,y,r?new Array(M.length):null));return{lines:o,points:h,rect:[b,x,C,S]}}static deserialize(e,s,i,n,r,{paths:{lines:o,points:h},rotation:c,thickness:u}){const d=[];let f,g,p,m,y;switch(c){case 0:y=U._rescale,f=-e/i,g=s/n+1,p=1/i,m=-1/n;break;case 90:y=U._rescaleAndSwap,f=-s/n,g=-e/i,p=1/n,m=1/i;break;case 180:y=U._rescale,f=e/i+1,g=-s/n,p=-1/i,m=1/n;break;case 270:y=U._rescaleAndSwap,f=s/n+1,g=e/i+1,p=-1/n,m=-1/i;break}if(!o){o=[];for(const x of h){const C=x.length;if(C===2){o.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1]]));continue}if(C===4){o.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1],NaN,NaN,NaN,NaN,x[2],x[3]]));continue}const S=new Float32Array(3*(C-2));o.push(S);let[T,P,M,D]=x.subarray(0,4);S.set([NaN,NaN,NaN,NaN,T,P],0);for(let R=4;R<C;R+=2){const V=x[R],H=x[R+1];S.set(U.createBezierPoints(T,P,M,D,V,H),(R-2)*3),[T,P,M,D]=[M,D,V,H]}}}for(let x=0,C=o.length;x<C;x++)d.push({line:y(o[x].map(S=>S??NaN),f,g,p,m),points:y(h[x].map(S=>S??NaN),f,g,p,m)});const b=new yp;return b.build(d,i,n,1,c,u,r),b}get box(){return l(this,Je)}updateProperty(e,s){return e==="stroke-width"?w(this,Ce,g_).call(this,s):null}updateParentDimensions([e,s],i){const[n,r]=w(this,Ce,zn).call(this);v(this,Vi,e),v(this,Gi,s),v(this,kh,i);const[o,h]=w(this,Ce,zn).call(this),c=o-n,u=h-r,d=l(this,Je);return d[0]-=c,d[1]-=u,d[2]+=2*c,d[3]+=2*u,d}updateRotation(e){return v(this,Xc,e),{path:{transform:this.rotationTransform}}}get viewBox(){return l(this,Je).map(U.svgRound).join(" ")}get defaultProperties(){const[e,s]=l(this,Je);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${U.svgRound(e)} ${U.svgRound(s)}`}}}get rotationTransform(){const[,,e,s]=l(this,Je);let i=0,n=0,r=0,o=0,h=0,c=0;switch(l(this,Xc)){case 90:n=s/e,r=-e/s,h=e;break;case 180:i=-1,o=-1,h=e,c=s;break;case 270:n=-s/e,r=e/s,c=s;break;default:return""}return`matrix(${i} ${n} ${r} ${o} ${U.svgRound(h)} ${U.svgRound(c)})`}getPathResizingSVGProperties([e,s,i,n]){const[r,o]=w(this,Ce,zn).call(this),[h,c,u,d]=l(this,Je);if(Math.abs(u-r)<=U.PRECISION||Math.abs(d-o)<=U.PRECISION){const y=e+i/2-(h+u/2),b=s+n/2-(c+d/2);return{path:{"transform-origin":`${U.svgRound(e)} ${U.svgRound(s)}`,transform:`${this.rotationTransform} translate(${y} ${b})`}}}const f=(i-2*r)/(u-2*r),g=(n-2*o)/(d-2*o),p=u/i,m=d/n;return{path:{"transform-origin":`${U.svgRound(h)} ${U.svgRound(c)}`,transform:`${this.rotationTransform} scale(${p} ${m}) translate(${U.svgRound(r)} ${U.svgRound(o)}) scale(${f} ${g}) translate(${U.svgRound(-r)} ${U.svgRound(-o)})`}}}getPathResizedSVGProperties([e,s,i,n]){const[r,o]=w(this,Ce,zn).call(this),h=l(this,Je),[c,u,d,f]=h;if(h[0]=e,h[1]=s,h[2]=i,h[3]=n,Math.abs(d-r)<=U.PRECISION||Math.abs(f-o)<=U.PRECISION){const b=e+i/2-(c+d/2),x=s+n/2-(u+f/2);for(const{line:C,points:S}of l(this,Os))U._translate(C,b,x,C),U._translate(S,b,x,S);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${U.svgRound(e)} ${U.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const g=(i-2*r)/(d-2*r),p=(n-2*o)/(f-2*o),m=-g*(c+r)+e+r,y=-p*(u+o)+s+o;if(g!==1||p!==1||m!==0||y!==0)for(const{line:b,points:x}of l(this,Os))U._rescale(b,m,y,g,p,b),U._rescale(x,m,y,g,p,x);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${U.svgRound(e)} ${U.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,s],i){const[n,r]=i,o=l(this,Je),h=e-o[0],c=s-o[1];if(l(this,Vi)===n&&l(this,Gi)===r)for(const{line:u,points:d}of l(this,Os))U._translate(u,h,c,u),U._translate(d,h,c,d);else{const u=l(this,Vi)/n,d=l(this,Gi)/r;v(this,Vi,n),v(this,Gi,r);for(const{line:f,points:g}of l(this,Os))U._rescale(f,h,c,u,d,f),U._rescale(g,h,c,u,d,g);o[2]*=u,o[3]*=d}return o[0]=e,o[1]=s,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${U.svgRound(e)} ${U.svgRound(s)}`}}}get defaultSVGProperties(){const e=l(this,Je);return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${U.svgRound(e[0])} ${U.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}};Je=new WeakMap,Xc=new WeakMap,Uc=new WeakMap,Os=new WeakMap,Vi=new WeakMap,Gi=new WeakMap,kh=new WeakMap,Ph=new WeakMap,Mh=new WeakMap,Ce=new WeakSet,zn=function(e=l(this,Mh)){const s=l(this,Uc)+e/2*l(this,kh);return l(this,Ph)%180===0?[s/l(this,Vi),s/l(this,Gi)]:[s/l(this,Gi),s/l(this,Vi)]},d_=function(){const[e,s,i,n]=l(this,Je),[r,o]=w(this,Ce,zn).call(this,0);return[e+r,s+o,i-2*r,n-2*o]},f_=function(){const e=v(this,Je,new Float32Array([1/0,1/0,-1/0,-1/0]));for(const{line:n}of l(this,Os)){if(n.length<=12){for(let h=4,c=n.length;h<c;h+=6){const[u,d]=n.subarray(h,h+2);e[0]=Math.min(e[0],u),e[1]=Math.min(e[1],d),e[2]=Math.max(e[2],u),e[3]=Math.max(e[3],d)}continue}let r=n[4],o=n[5];for(let h=6,c=n.length;h<c;h+=6){const[u,d,f,g,p,m]=n.subarray(h,h+6);q.bezierBoundingBox(r,o,u,d,f,g,p,m,e),r=p,o=m}}const[s,i]=w(this,Ce,zn).call(this);e[0]=Math.min(1,Math.max(0,e[0]-s)),e[1]=Math.min(1,Math.max(0,e[1]-i)),e[2]=Math.min(1,Math.max(0,e[2]+s)),e[3]=Math.min(1,Math.max(0,e[3]+i)),e[2]-=e[0],e[3]-=e[1]},g_=function(e){const[s,i]=w(this,Ce,zn).call(this);v(this,Mh,e);const[n,r]=w(this,Ce,zn).call(this),[o,h]=[n-s,r-i],c=l(this,Je);return c[0]-=o,c[1]-=h,c[2]+=2*o,c[3]+=2*h,c};let Md=yp;const _p=class _p extends oA{constructor(e){super();_(this,Oh);v(this,Oh,e),super.updateProperties({fill:"none",stroke:Vt._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(e,s){e==="stroke-width"&&(s??(s=this["stroke-width"]),s*=l(this,Oh).realScale),super.updateSVGProperty(e,s)}clone(){const e=new _p(l(this,Oh));return e.updateAll(this),e}};Oh=new WeakMap;let lp=_p;const Dh=class Dh extends hp{constructor(e){super({...e,name:"inkEditor"});_(this,$d);this._willKeepAspectRatio=!0}static initialize(e,s){Vt.initialize(e,s),this._defaultDrawingOptions=new lp(s.viewParameters)}static getDefaultDrawingOptions(e){const s=this._defaultDrawingOptions.clone();return s.updateProperties(e),s}static get supportMultipleDrawings(){return!0}static get typesMap(){return ct(this,"typesMap",new Map([[gt.INK_THICKNESS,"stroke-width"],[gt.INK_COLOR,"stroke"],[gt.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(e,s,i,n,r){return new aA(e,s,i,n,r,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(e,s,i,n,r,o){return Md.deserialize(e,s,i,n,r,o)}static async deserialize(e,s,i){let n=null;if(e instanceof np){const{data:{inkLists:o,rect:h,rotation:c,id:u,color:d,opacity:f,borderStyle:{rawWidth:g},popupRef:p},parent:{page:{pageNumber:m}}}=e;n=e={annotationType:at.INK,color:Array.from(d),thickness:g,opacity:f,paths:{points:o},boxes:null,pageIndex:m-1,rect:h.slice(0),rotation:c,id:u,deleted:!1,popupRef:p}}const r=await super.deserialize(e,s,i);return r.annotationElementId=e.id||null,r._initialData=n,r}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:e,_drawingOptions:s,parent:i}=this;s.updateSVGProperty("stroke-width"),i.drawLayer.updateProperties(e,s.toSVGProperties())}static onScaleChangingWhenDrawing(){const e=this._currentParent;e&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:e,thickness:s,opacity:i}){this._drawingOptions=Dh.getDefaultDrawingOptions({stroke:q.makeHexColor(...e),"stroke-width":s,"stroke-opacity":i})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:s,points:i,rect:n}=this.serializeDraw(e),{_drawingOptions:{stroke:r,"stroke-opacity":o,"stroke-width":h}}=this,c={annotationType:at.INK,color:Vt._colorManager.convert(r),opacity:o,thickness:h,paths:{lines:s,points:i},pageIndex:this.pageIndex,rect:n,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?c:this.annotationElementId&&!w(this,$d,p_).call(this,c)?null:(c.id=this.annotationElementId,c)}renderAnnotationElement(e){const{points:s,rect:i}=this.serializeDraw(!1);return e.updateEdited({rect:i,thickness:this._drawingOptions["stroke-width"],points:s}),null}};$d=new WeakSet,p_=function(e){const{color:s,thickness:i,opacity:n,pageIndex:r}=this._initialData;return this._hasBeenMoved||this._hasBeenResized||e.color.some((o,h)=>o!==s[h])||e.thickness!==i||e.opacity!==n||e.pageIndex!==r},Q(Dh,"_type","ink"),Q(Dh,"_editorType",at.INK),Q(Dh,"_defaultDrawingOptions",null);let cp=Dh;const Yc=class Yc extends Vt{constructor(e){super({...e,name:"stampEditor"});_(this,bt);_(this,Wt,null);_(this,Ae,null);_(this,Cr,null);_(this,In,null);_(this,Ar,null);_(this,Rh,"");_(this,Wi,null);_(this,Xi,null);_(this,Ds,!1);_(this,Fh,!1);v(this,In,e.bitmapUrl),v(this,Ar,e.bitmapFile)}static initialize(e,s){Vt.initialize(e,s)}static get supportedTypes(){return ct(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return ct(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(e){return this.supportedTypes.includes(e)}static paste(e,s){s.pasteEditor(at.STAMP,{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){var e;return{type:"stamp",hasAltText:!!((e=this.altTextData)!=null&&e.altText)}}static computeTelemetryFinalData(e){const s=e.get("hasAltText");return{hasAltText:s.get(!0)??0,hasNoAltText:s.get(!1)??0}}async mlGuessAltText(e=null,s=!0){if(this.hasAltTextData())return null;const{mlManager:i}=this._uiManager;if(!i)throw new Error("No ML.");if(!await i.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:n,width:r,height:o}=e||this.copyCanvas(null,null,!0).imageData,h=await i.guess({name:"altText",request:{data:n,width:r,height:o,channels:n.length/(r*o)}});if(!h)throw new Error("No response from the AI service.");if(h.error)throw new Error("Error from the AI service.");if(h.cancel)return null;if(!h.output)throw new Error("No valid response from the AI service.");const c=h.output;return await this.setGuessedAltText(c),s&&!this.hasAltTextData()&&(this.altTextData={alt:c,decorative:!1}),c}remove(){var e;l(this,Ae)&&(v(this,Wt,null),this._uiManager.imageManager.deleteId(l(this,Ae)),(e=l(this,Wi))==null||e.remove(),v(this,Wi,null),l(this,Xi)&&(clearTimeout(l(this,Xi)),v(this,Xi,null))),super.remove()}rebuild(){if(!this.parent){l(this,Ae)&&w(this,bt,Tf).call(this);return}super.rebuild(),this.div!==null&&(l(this,Ae)&&l(this,Wi)===null&&w(this,bt,Tf).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(e){this._isDraggable=!0,e&&this.div.focus()}isEmpty(){return!(l(this,Cr)||l(this,Wt)||l(this,In)||l(this,Ar)||l(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(),l(this,Wt)?w(this,bt,gm).call(this):w(this,bt,Tf).call(this),this.width&&!this.annotationElementId){const[i,n]=this.parentDimensions;this.setAt(e*i,s*n,this.width*i,this.height*n)}return this._uiManager.addShouldRescale(this),this.div}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;l(this,Xi)!==null&&clearTimeout(l(this,Xi)),v(this,Xi,setTimeout(()=>{v(this,Xi,null),w(this,bt,pm).call(this)},200))}copyCanvas(e,s,i=!1){var g;e||(e=224);const{width:n,height:r}=l(this,Wt),o=new Vg;let h=l(this,Wt),c=n,u=r,d=null;if(s){if(n>s||r>s){const D=Math.min(s/n,s/r);c=Math.floor(n*D),u=Math.floor(r*D)}d=document.createElement("canvas");const p=d.width=Math.ceil(c*o.sx),m=d.height=Math.ceil(u*o.sy);l(this,Ds)||(h=w(this,bt,Ef).call(this,p,m));const y=d.getContext("2d");y.filter=this._uiManager.hcmFilter;let b="white",x="#cfcfd8";this._uiManager.hcmFilter!=="none"?x="black":(g=window.matchMedia)!=null&&g.call(window,"(prefers-color-scheme: dark)").matches&&(b="#8f8f9d",x="#42414d");const C=15,S=C*o.sx,T=C*o.sy,P=new OffscreenCanvas(S*2,T*2),M=P.getContext("2d");M.fillStyle=b,M.fillRect(0,0,S*2,T*2),M.fillStyle=x,M.fillRect(0,0,S,T),M.fillRect(S,T,S,T),y.fillStyle=y.createPattern(P,"repeat"),y.fillRect(0,0,p,m),y.drawImage(h,0,0,h.width,h.height,0,0,p,m)}let f=null;if(i){let p,m;if(o.symmetric&&h.width<e&&h.height<e)p=h.width,m=h.height;else if(h=l(this,Wt),n>e||r>e){const x=Math.min(e/n,e/r);p=Math.floor(n*x),m=Math.floor(r*x),l(this,Ds)||(h=w(this,bt,Ef).call(this,p,m))}const b=new OffscreenCanvas(p,m).getContext("2d",{willReadFrequently:!0});b.drawImage(h,0,0,h.width,h.height,0,0,p,m),f={width:p,height:m,data:b.getImageData(0,0,p,m).data}}return{canvas:d,width:c,height:u,imageData:f}}getImageForAltText(){return l(this,Wi)}static async deserialize(e,s,i){var m;let n=null;if(e instanceof Ab){const{data:{rect:y,rotation:b,id:x,structParent:C,popupRef:S},container:T,parent:{page:{pageNumber:P}}}=e,M=T.querySelector("canvas"),D=i.imageManager.getFromCanvas(T.id,M);M.remove();const R=((m=await s._structTree.getAriaAttributes(`${jg}${x}`))==null?void 0:m.get("aria-label"))||"";n=e={annotationType:at.STAMP,bitmapId:D.id,bitmap:D.bitmap,pageIndex:P-1,rect:y.slice(0),rotation:b,id:x,deleted:!1,accessibilityData:{decorative:!1,altText:R},isSvg:!1,structParent:C,popupRef:S}}const r=await super.deserialize(e,s,i),{rect:o,bitmap:h,bitmapUrl:c,bitmapId:u,isSvg:d,accessibilityData:f}=e;u&&i.imageManager.isValidId(u)?(v(r,Ae,u),h&&v(r,Wt,h)):v(r,In,c),v(r,Ds,d);const[g,p]=r.pageDimensions;return r.width=(o[2]-o[0])/g,r.height=(o[3]-o[1])/p,r.annotationElementId=e.id||null,f&&(r.altTextData=f),r._initialData=n,v(r,Fh,!!n),r}serialize(e=!1,s=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const i={annotationType:at.STAMP,bitmapId:l(this,Ae),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:l(this,Ds),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=w(this,bt,kf).call(this,!0),i.accessibilityData=this.serializeAltText(!0),i;const{decorative:n,altText:r}=this.serializeAltText(!1);if(!n&&r&&(i.accessibilityData={type:"Figure",alt:r}),this.annotationElementId){const h=w(this,bt,m_).call(this,i);if(h.isSame)return null;h.isSameAltText?delete i.accessibilityData:i.accessibilityData.structParent=this._initialData.structParent??-1}if(i.id=this.annotationElementId,s===null)return i;s.stamps||(s.stamps=new Map);const o=l(this,Ds)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!s.stamps.has(l(this,Ae)))s.stamps.set(l(this,Ae),{area:o,serialized:i}),i.bitmap=w(this,bt,kf).call(this,!1);else if(l(this,Ds)){const h=s.stamps.get(l(this,Ae));o>h.area&&(h.area=o,h.serialized.bitmap.close(),h.serialized.bitmap=w(this,bt,kf).call(this,!1))}return i}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}};Wt=new WeakMap,Ae=new WeakMap,Cr=new WeakMap,In=new WeakMap,Ar=new WeakMap,Rh=new WeakMap,Wi=new WeakMap,Xi=new WeakMap,Ds=new WeakMap,Fh=new WeakMap,bt=new WeakSet,hu=function(e,s=!1){if(!e){this.remove();return}v(this,Wt,e.bitmap),s||(v(this,Ae,e.id),v(this,Ds,e.isSvg)),e.file&&v(this,Rh,e.file.name),w(this,bt,gm).call(this)},lu=function(){if(v(this,Cr,null),this._uiManager.enableWaiting(!1),!!l(this,Wi)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Wt)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Wt)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},Tf=function(){if(l(this,Ae)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(l(this,Ae)).then(i=>w(this,bt,hu).call(this,i,!0)).finally(()=>w(this,bt,lu).call(this));return}if(l(this,In)){const i=l(this,In);v(this,In,null),this._uiManager.enableWaiting(!0),v(this,Cr,this._uiManager.imageManager.getFromUrl(i).then(n=>w(this,bt,hu).call(this,n)).finally(()=>w(this,bt,lu).call(this)));return}if(l(this,Ar)){const i=l(this,Ar);v(this,Ar,null),this._uiManager.enableWaiting(!0),v(this,Cr,this._uiManager.imageManager.getFromFile(i).then(n=>w(this,bt,hu).call(this,n)).finally(()=>w(this,bt,lu).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=Yc.supportedTypesStr;const s=this._uiManager._signal;v(this,Cr,new Promise(i=>{e.addEventListener("change",async()=>{if(!e.files||e.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const n=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),w(this,bt,hu).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>w(this,bt,lu).call(this))),e.click()},gm=function(){var d;const{div:e}=this;let{width:s,height:i}=l(this,Wt);const[n,r]=this.pageDimensions,o=.75;if(this.width)s=this.width*n,i=this.height*r;else if(s>o*n||i>o*r){const f=Math.min(o*n/s,o*r/i);s*=f,i*=f}const[h,c]=this.parentDimensions;this.setDims(s*h/n,i*c/r),this._uiManager.enableWaiting(!1);const u=v(this,Wi,document.createElement("canvas"));u.setAttribute("role","img"),this.addContainer(u),this.width=s/n,this.height=i/r,(d=this._initialOptions)!=null&&d.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),w(this,bt,pm).call(this),l(this,Fh)||(this.parent.addUndoableEditor(this),v(this,Fh,!0)),this._reportTelemetry({action:"inserted_image"}),l(this,Rh)&&u.setAttribute("aria-label",l(this,Rh))},Ef=function(e,s){const{width:i,height:n}=l(this,Wt);let r=i,o=n,h=l(this,Wt);for(;r>2*e||o>2*s;){const c=r,u=o;r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2)),o>2*s&&(o=o>=16384?Math.floor(o/2)-1:Math.ceil(o/2));const d=new OffscreenCanvas(r,o);d.getContext("2d").drawImage(h,0,0,c,u,0,0,r,o),h=d.transferToImageBitmap()}return h},pm=function(){const[e,s]=this.parentDimensions,{width:i,height:n}=this,r=new Vg,o=Math.ceil(i*e*r.sx),h=Math.ceil(n*s*r.sy),c=l(this,Wi);if(!c||c.width===o&&c.height===h)return;c.width=o,c.height=h;const u=l(this,Ds)?l(this,Wt):w(this,bt,Ef).call(this,o,h),d=c.getContext("2d");d.filter=this._uiManager.hcmFilter,d.drawImage(u,0,0,u.width,u.height,0,0,o,h)},kf=function(e){if(e){if(l(this,Ds)){const n=this._uiManager.imageManager.getSvgUrl(l(this,Ae));if(n)return n}const s=document.createElement("canvas");return{width:s.width,height:s.height}=l(this,Wt),s.getContext("2d").drawImage(l(this,Wt),0,0),s.toDataURL()}if(l(this,Ds)){const[s,i]=this.pageDimensions,n=Math.round(this.width*s*Kn.PDF_TO_CSS_UNITS),r=Math.round(this.height*i*Kn.PDF_TO_CSS_UNITS),o=new OffscreenCanvas(n,r);return o.getContext("2d").drawImage(l(this,Wt),0,0,l(this,Wt).width,l(this,Wt).height,0,0,n,r),o.transferToImageBitmap()}return structuredClone(l(this,Wt))},m_=function(e){var o;const{pageIndex:s,accessibilityData:{altText:i}}=this._initialData,n=e.pageIndex===s,r=(((o=e.accessibilityData)==null?void 0:o.alt)||"")===i;return{isSame:!this._hasBeenMoved&&!this._hasBeenResized&&n&&r,isSameAltText:r}},Q(Yc,"_type","stamp"),Q(Yc,"_editorType",at.STAMP);let up=Yc;const bi=class bi{constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:o,textLayer:h,viewport:c,l10n:u}){_(this,Nt);_(this,ia);_(this,Lh,!1);_(this,Ui,null);_(this,Tr,null);_(this,jn,null);_(this,Us,new Map);_(this,Er,!1);_(this,Ih,!1);_(this,na,!1);_(this,vi,null);_(this,Nn,null);_(this,je,null);_(this,Bn,null);_(this,$);const d=[...l(bi,kr).values()];if(!bi._initialized){bi._initialized=!0;for(const f of d)f.initialize(u,t)}t.registerEditorTypes(d),v(this,$,t),this.pageIndex=e,this.div=s,v(this,ia,n),v(this,Ui,r),this.viewport=c,v(this,je,h),this.drawLayer=o,this._structTree=i,l(this,$).addLayer(this)}get isEmpty(){return l(this,Us).size===0}get isInvisible(){return this.isEmpty&&l(this,$).getMode()===at.NONE}updateToolbar(t){l(this,$).updateToolbar(t)}updateMode(t=l(this,$).getMode()){switch(w(this,Nt,Pf).call(this),t){case at.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case at.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case at.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:e}=this.div;for(const s of l(bi,kr).values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=l(this,je))==null?void 0:e.div)}setEditingState(t){l(this,$).setEditingState(t)}addCommands(t){l(this,$).addCommands(t)}cleanUndoStack(t){l(this,$).cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){var e;(e=l(this,Ui))==null||e.div.classList.toggle("disabled",!t)}async enable(){v(this,na,!0),this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of l(this,Us).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(l(this,$).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!l(this,Ui)){v(this,na,!1);return}const e=l(this,Ui).getEditableAnnotations();for(const s of e){if(s.hide(),l(this,$).isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}v(this,na,!1)}disable(){var i;v(this,Ih,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const n of l(this,Us).values())if(n.disableEditing(),!!n.annotationElementId){if(n.serialize()!==null){t.set(n.annotationElementId,n);continue}else e.set(n.annotationElementId,n);(i=this.getEditableAnnotation(n.annotationElementId))==null||i.show(),n.remove()}if(l(this,Ui)){const n=l(this,Ui).getEditableAnnotations();for(const r of n){const{id:o}=r.data;if(l(this,$).isDeletedAnnotationElement(o))continue;let h=e.get(o);if(h){h.resetAnnotationElement(r),h.show(!1),r.show();continue}h=t.get(o),h&&(l(this,$).addChangedExistingAnnotation(h),h.renderAnnotationElement(r)&&h.show(!1)),r.show()}}w(this,Nt,Pf).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of l(bi,kr).values())s.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),v(this,Ih,!1)}getEditableAnnotation(t){var e;return((e=l(this,Ui))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){l(this,$).getActive()!==t&&l(this,$).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=l(this,je))!=null&&t.div&&!l(this,Bn)){v(this,Bn,new AbortController);const e=l(this,$).combinedSignal(l(this,Bn));l(this,je).div.addEventListener("pointerdown",w(this,Nt,v_).bind(this),{signal:e}),l(this,je).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=l(this,je))!=null&&t.div&&l(this,Bn)&&(l(this,Bn).abort(),v(this,Bn,null),l(this,je).div.classList.remove("highlighting"))}enableClick(){if(l(this,Tr))return;v(this,Tr,new AbortController);const t=l(this,$).combinedSignal(l(this,Tr));this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){var t;(t=l(this,Tr))==null||t.abort(),v(this,Tr,null)}attach(t){l(this,Us).set(t.id,t);const{annotationElementId:e}=t;e&&l(this,$).isDeletedAnnotationElement(e)&&l(this,$).removeDeletedAnnotationElement(t)}detach(t){var e;l(this,Us).delete(t.id),(e=l(this,ia))==null||e.removePointerInTextLayer(t.contentDiv),!l(this,Ih)&&t.annotationElementId&&l(this,$).addDeletedAnnotationElement(t)}remove(t){this.detach(t),l(this,$).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(l(this,$).addDeletedAnnotationElement(t.annotationElementId),Vt.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),(e=t.parent)==null||e.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(!(t.parent===this&&t.isAttachedToDOM)){if(this.changeParent(t),l(this,$).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!l(this,na)),l(this,$).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!l(this,jn)&&(t._focusEventsAllowed=!1,v(this,jn,setTimeout(()=>{v(this,jn,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:l(this,$)._signal}),e.focus())},0))),t._structTreeParentId=(s=l(this,ia))==null?void 0:s.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||(t.parent=this),t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getNextId(){return l(this,$).getId()}combinedSignal(t){return l(this,$).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=l(this,Nt,$i))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){l(this,$).updateToolbar(t),l(this,$).updateMode(t);const{offsetX:s,offsetY:i}=w(this,Nt,vm).call(this),n=this.getNextId(),r=w(this,Nt,mm).call(this,{parent:this,id:n,x:s,y:i,uiManager:l(this,$),isCentered:!0,...e});r&&this.add(r)}async deserialize(t){var e;return await((e=l(bi,kr).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,l(this,$)))||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=w(this,Nt,mm).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:l(this,$),isCentered:e,...s});return n&&this.add(n),n}addNewEditor(){this.createAndAddNewEditor(w(this,Nt,vm).call(this),!0)}setSelected(t){l(this,$).setSelected(t)}toggleSelected(t){l(this,$).toggleSelected(t)}unselect(t){l(this,$).unselect(t)}pointerup(t){var s;const{isMac:e}=Ue.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&l(this,Er)&&(v(this,Er,!1),!((s=l(this,Nt,$i))!=null&&s.isDrawer&&l(this,Nt,$i).supportMultipleDrawings))){if(!l(this,Lh)){v(this,Lh,!0);return}if(l(this,$).getMode()===at.STAMP){l(this,$).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){var i;if(l(this,$).getMode()===at.HIGHLIGHT&&this.enableTextSelection(),l(this,Er)){v(this,Er,!1);return}const{isMac:e}=Ue.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(v(this,Er,!0),(i=l(this,Nt,$i))!=null&&i.isDrawer){this.startDrawingSession(t);return}const s=l(this,$).getActive();v(this,Lh,!s||s.isEmpty())}startDrawingSession(t){if(this.div.focus(),l(this,vi)){l(this,Nt,$i).startDrawing(this,l(this,$),!1,t);return}l(this,$).setCurrentDrawingSession(this),v(this,vi,new AbortController);const e=l(this,$).combinedSignal(l(this,vi));this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(v(this,Nn,null),this.commitOrRemove())},{signal:e}),l(this,Nt,$i).startDrawing(this,l(this,$),!1,t)}pause(t){if(t){const{activeElement:e}=document;this.div.contains(e)&&v(this,Nn,e);return}l(this,Nn)&&setTimeout(()=>{var e;(e=l(this,Nn))==null||e.focus(),v(this,Nn,null)},0)}endDrawingSession(t=!1){return l(this,vi)?(l(this,$).setCurrentDrawingSession(null),l(this,vi).abort(),v(this,vi,null),v(this,Nn,null),l(this,Nt,$i).endDrawing(t)):null}findNewParent(t,e,s){const i=l(this,$).findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return l(this,vi)?(this.endDrawingSession(),!0):!1}onScaleChanging(){l(this,vi)&&l(this,Nt,$i).onScaleChangingWhenDrawing(this)}destroy(){var t,e;this.commitOrRemove(),((t=l(this,$).getActive())==null?void 0:t.parent)===this&&(l(this,$).commitOrRemove(),l(this,$).setActiveEditor(null)),l(this,jn)&&(clearTimeout(l(this,jn)),v(this,jn,null));for(const s of l(this,Us).values())(e=l(this,ia))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,l(this,Us).clear(),l(this,$).removeLayer(this)}render({viewport:t}){this.viewport=t,$r(this.div,t);for(const e of l(this,$).getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){l(this,$).commitOrRemove(),w(this,Nt,Pf).call(this);const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,$r(this.div,{rotation:s}),e!==s)for(const i of l(this,Us).values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return l(this,$).viewParameters.realScale}};ia=new WeakMap,Lh=new WeakMap,Ui=new WeakMap,Tr=new WeakMap,jn=new WeakMap,Us=new WeakMap,Er=new WeakMap,Ih=new WeakMap,na=new WeakMap,vi=new WeakMap,Nn=new WeakMap,je=new WeakMap,Bn=new WeakMap,$=new WeakMap,kr=new WeakMap,Nt=new WeakSet,v_=function(t){l(this,$).unselectAll();const{target:e}=t;if(e===l(this,je).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&l(this,je).div.contains(e)){const{isMac:s}=Ue.platform;if(t.button!==0||t.ctrlKey&&s)return;l(this,$).showAllEditors("highlight",!0,!0),l(this,je).div.classList.add("free"),this.toggleDrawing(),Pd.startHighlighting(this,l(this,$).direction==="ltr",{target:l(this,je).div,x:t.x,y:t.y}),l(this,je).div.addEventListener("pointerup",()=>{l(this,je).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:l(this,$)._signal}),t.preventDefault()}},$i=function(){return l(bi,kr).get(l(this,$).getMode())},mm=function(t){const e=l(this,Nt,$i);return e?new e.prototype.constructor(t):null},vm=function(){const{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),o=Math.min(window.innerWidth,t+s),h=Math.min(window.innerHeight,e+i),c=(n+o)/2-t,u=(r+h)/2-e,[d,f]=this.viewport.rotation%180===0?[c,u]:[u,c];return{offsetX:d,offsetY:f}},Pf=function(){for(const t of l(this,Us).values())t.isEmpty()&&t.remove()},Q(bi,"_initialized",!1),_(bi,kr,new Map([rp,cp,up,Pd].map(t=>[t._editorType,t])));let dp=bi;const Ne=class Ne{constructor({pageIndex:t}){_(this,Yi);_(this,yi,null);_(this,$c,0);_(this,Qe,new Map);_(this,ra,new Map);this.pageIndex=t}setParent(t){if(!l(this,yi)){v(this,yi,t);return}if(l(this,yi)!==t){if(l(this,Qe).size>0)for(const e of l(this,Qe).values())e.remove(),t.append(e);v(this,yi,t)}}static get _svgFactory(){return ct(this,"_svgFactory",new sp)}draw(t,e=!1,s=!1){const i=es(this,$c)._++,n=w(this,Yi,bm).call(this),r=Ne._svgFactory.createElement("defs");n.append(r);const o=Ne._svgFactory.createElement("path");r.append(o);const h=`path_p${this.pageIndex}_${i}`;o.setAttribute("id",h),o.setAttribute("vector-effect","non-scaling-stroke"),e&&l(this,ra).set(i,o);const c=s?w(this,Yi,y_).call(this,r,h):null,u=Ne._svgFactory.createElement("use");return n.append(u),u.setAttribute("href",`#${h}`),this.updateProperties(n,t),l(this,Qe).set(i,n),{id:i,clipPathId:`url(#${c})`}}drawOutline(t,e){const s=es(this,$c)._++,i=w(this,Yi,bm).call(this),n=Ne._svgFactory.createElement("defs");i.append(n);const r=Ne._svgFactory.createElement("path");n.append(r);const o=`path_p${this.pageIndex}_${s}`;r.setAttribute("id",o),r.setAttribute("vector-effect","non-scaling-stroke");let h;if(e){const d=Ne._svgFactory.createElement("mask");n.append(d),h=`mask_p${this.pageIndex}_${s}`,d.setAttribute("id",h),d.setAttribute("maskUnits","objectBoundingBox");const f=Ne._svgFactory.createElement("rect");d.append(f),f.setAttribute("width","1"),f.setAttribute("height","1"),f.setAttribute("fill","white");const g=Ne._svgFactory.createElement("use");d.append(g),g.setAttribute("href",`#${o}`),g.setAttribute("stroke","none"),g.setAttribute("fill","black"),g.setAttribute("fill-rule","nonzero"),g.classList.add("mask")}const c=Ne._svgFactory.createElement("use");i.append(c),c.setAttribute("href",`#${o}`),h&&c.setAttribute("mask",`url(#${h})`);const u=c.cloneNode();return i.append(u),c.classList.add("mainOutline"),u.classList.add("secondaryOutline"),this.updateProperties(i,t),l(this,Qe).set(s,i),s}finalizeDraw(t,e){l(this,ra).delete(t),this.updateProperties(t,e)}updateProperties(t,e){var h;if(!e)return;const{root:s,bbox:i,rootClass:n,path:r}=e,o=typeof t=="number"?l(this,Qe).get(t):t;if(o){if(s&&w(this,Yi,ym).call(this,o,s),i&&w(h=Ne,qd,b_).call(h,o,i),n){const{classList:c}=o;for(const[u,d]of Object.entries(n))c.toggle(u,d)}if(r){const u=o.firstChild.firstChild;w(this,Yi,ym).call(this,u,r)}}}updateParent(t,e){if(e===this)return;const s=l(this,Qe).get(t);s&&(l(e,yi).append(s),l(this,Qe).delete(t),l(e,Qe).set(t,s))}remove(t){l(this,ra).delete(t),l(this,yi)!==null&&(l(this,Qe).get(t).remove(),l(this,Qe).delete(t))}destroy(){v(this,yi,null);for(const t of l(this,Qe).values())t.remove();l(this,Qe).clear(),l(this,ra).clear()}};yi=new WeakMap,$c=new WeakMap,Qe=new WeakMap,ra=new WeakMap,qd=new WeakSet,b_=function(t,[e,s,i,n]){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`},Yi=new WeakSet,bm=function(){const t=Ne._svgFactory.create(1,1,!0);return l(this,yi).append(t),t.setAttribute("aria-hidden",!0),t},y_=function(t,e){const s=Ne._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=Ne._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i},ym=function(t,e){for(const[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)},_(Ne,qd);let fp=Ne;globalThis.pdfjsTestingUtils={HighlightOutliner:op},et.AbortException,et.AnnotationEditorLayer,et.AnnotationEditorParamsType,et.AnnotationEditorType,et.AnnotationEditorUIManager,et.AnnotationLayer,et.AnnotationMode,et.ColorPicker,et.DOMSVGFactory,et.DrawLayer,et.FeatureTest;var hA=et.GlobalWorkerOptions;et.ImageKind,et.InvalidPDFException,et.MissingPDFException,et.OPS,et.OutputScale,et.PDFDataRangeTransport,et.PDFDateString,et.PDFWorker,et.PasswordResponses,et.PermissionFlag,et.PixelsPerInch,et.RenderingCancelledException,et.TextLayer,et.TouchManager,et.UnexpectedResponseException,et.Util,et.VerbosityLevel,et.XfaLayer,et.build,et.createValidAbsoluteUrl,et.fetchData;var lA=et.getDocument;et.getFilenameFromUrl,et.getPdfFilenameFromUrl,et.getXfaPageViewport,et.isDataScheme,et.isPdfFile,et.noContextMenu,et.normalizeUnicode,et.setLayerDimensions,et.shadow,et.stopEvent,et.version;const cA={"pdfjs-dist":"4.10.38"};function uA(a){return new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>t(s.result)),s.addEventListener("error",e),s.readAsDataURL(a)})}const dA=cA["pdfjs-dist"].replace("^","");hA.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${dA}/pdf.worker.min.mjs`;async function fA(a){const t="data:application/pdf;base64,",e=await uA(a);if(typeof e=="string")return window.atob(e.slice(t.length))}function gA(a,t){return lA({data:a,password:t}).promise}const hs=new Map;function pA(a){const t=new bg(a);return hs.set(a,t),t}function mA(a,t){const e=Date.now();return{PDFId:`${a.name}-${e}`,name:a.name.replace(/.pdf/,""),updateDate:e,PDFBase64:t}}function vA(a,t){const e=a.getViewport({scale:t}),s=document.createElement("canvas"),i=s.getContext("2d"),n=rS()/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 bA({src:a},t,e){if(!a||!e)return null;const{objects:s,options:i}=await Yx(a),n=s.filter(o=>o!==null),r=lx.groupSVGElements(n,i);return n.forEach(o=>{o.stroke=e}),r.hoverCursor="pointer",r.stroke=`${e}-${t}`,r}function yA(a,t){if(!hs.get(a))return;const s=1/3,i=TA(t,s);kb(a,i,s)}async function _A(a,t){const e=await aS(t),s=Date.now(),n={PDFId:`${t.name}${s}`,name:t.name.replace(/.png|.jpg|.jpeg/,""),updateDate:s,PDFBase64:e};return Eb(a,{url:e}),{...n,pages:1}}async function Eb(a,{url:t,scale:e=.5}){if(!hs.get(a))return;const i=await Me.fromURL(t);i.scale(e),kb(a,i,e)}function kb(a,t,e){const s=hs.get(a);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function wA(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 xA(a,t,e){!e||!a||(e.scale(1/t),wA(a,e))}function SA(a,t){if(!a)return;const e=a._cornerSize||6;a.borderScaleFactor=1/t,a.cornerSize=e*(1/t),a.touchCornerSize=e*4*(1/t),a.setCoords()}function CA(a){const t=hs.get(a);t&&(t.discardActiveObject(),t.renderAll())}function AA(a){const t=hs.get(a);t&&(t.clear(),hs.delete(a))}function TA(a,t){return new Me(a,{scaleX:t,scaleY:t})}function gp(a,t){if(!t)return;const{left:e,top:s,scaleX:i,scaleY:n,width:r,height:o}=a,h=t.x*r*i,c=t.y*o*n;a.set({left:e-h,top:s-c})}function Pb(a,t,e){var n;const s=a.type,i={"application/pdf":EA,"image/png":Ob,"image/jpeg":Ob};return((n=i[s])==null?void 0:n.call(i,a,t,e))??Promise.reject(new Error(`Unsupported ${s} file type.`))}async function EA(a,t,e){const s=await fA(a);if(!s)return;const i=mA(a,s);try{const n=await Mb({page:1,PDFBase64:s,scale:.8,password:t},e);return{...i,pages:n}}catch(n){return Promise.reject(n)}}async function Mb({page:a,PDFBase64:t,scale:e,password:s},i){try{const n=await gA(t,s),r=await n.getPage(a),{renderTask:o,canvas:h}=vA(r,e);return o.promise.then(()=>(i&&yA(i,h),n.numPages))}catch(n){return Promise.reject(n)}}async function Ob(a,t,e){if(e)return await _A(e,a)}async function kA(a,t){const e=hs.get(a);if(!e)return;const s=e==null?void 0:e.getActiveObject();if(!s)return;const i=await s.clone(k_);i instanceof Fs?i.forEachObject(n=>{e.add(n),t(e,n)}):(e.add(i),t(e,i)),gp(i,{x:-.1,y:-.1}),e.setActiveObject(i)}function PA(a){const t=hs.get(a);if(!t)return;const e=t.getActiveObject();e&&(e instanceof Fs?(e.forEachObject(s=>{t.remove(s)}),t.discardActiveObject()):t.remove(e))}function Db(a){const{id:t="",selectionOptions:e,pointerDown:s,pointerMove:i,pointerUp:n,selectionCreated:r,selectionCleared:o}=a||{},h=tt.useRef(null),c=tt.useRef(null),u=tt.useRef(1),d=tt.useRef({...E_});function f(){if(!t||hs.has(t))return;const F=pA(t);return F.on("selection:created",I=>{if(r==null||r(I),I.selected.length<=1)return;const j=F.getActiveObject();j&&(c.current=j,e!=null&&e.value&&c.current.set(e.value),c.current._cornerSize=c.current.cornerSize,T(u.current))}),F.on("selection:cleared",I=>{o==null||o(I),M(F)}),s&&F.on("mouse:down",s),i&&F.on("mouse:move",i),n&&F.on("mouse:up",n),F}function g(F,I){return Pb(F,I,t)}function p(F){return Mb(F,t)}function m({url:F,scale:I=.5}){return Eb(t,{url:F,scale:I})}async function y(F,I,j){const K=hs.get(t);if(!K)return;const L=await Me.fromURL(F,{},{...C_,...I});gp(L,j),K.add(L),x(K,L),K.setActiveObject(L)}function b(F,I,j){const K=hs.get(t);if(!K)return;const L=new Pe(F,{...A_,...I});gp(L,j),K.add(L),x(K,L),K.setActiveObject(L)}function x(F,I){I.on("selected",j=>C({canvas:F,target:j.target})),I.on("modified",j=>C({canvas:F,target:j.target})),I.on("scaling",()=>M(F)),I.on("moving",()=>M(F)),I.on("rotating",()=>M(F)),I._cornerSize=I._cornerSize??I.cornerSize}async function C({canvas:F,target:I,stroke:j=d.current.stroke,uuid:K=Date.now()}){var Z;if(F.getActiveObjects().length>1||((Z=h.current)==null?void 0:Z.stroke)===`${j}-${K}`)return;const z=await bA(d.current,K,j);M(F),h.current=z,c.current=I,S(F,I,K),T(u.current,!0),z&&F.add(z)}function S(F,I,j){h.current&&(h.current.on("selected",()=>{F.remove(I),M(F)}),h.current.on("mouseover",()=>{C({canvas:F,target:I,stroke:d.current.hoverStroke,uuid:j})}),h.current.on("mouseout",()=>{C({canvas:F,target:I,stroke:d.current.stroke,uuid:j})}))}function T(F,I=!1){const j=hs.get(t);u.current=F,j&&(SA(c.current,F),xA(c.current,F,h.current),!I&&j.renderAll())}function P(F){if(!F)return;d.current={...d.current,...F};const I=hs.get(t);!h||!c.current||!I||C({target:c.current,canvas:I})}function M(F){c.current=null,h.current&&(F.remove(h.current),h.current=null)}function D(){CA(t)}function R(){AA(t)}function V(){return kA(t,x)}function H(){PA(t)}return{createCanvas:f,loadFile:g,specifyPage:p,renderImage:m,addFabric:y,addTextFabric:b,clearActive:D,deleteCanvas:R,scaleFabric:T,setCloseSvgOptions:P,copyActiveFabric:V,deleteActiveFabric:H}}function MA(a){let t=0;const e=oS(()=>{t!==window.innerWidth&&(t=window.innerWidth,a())});tt.useEffect(()=>(window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)),[])}const OA=tt.forwardRef(DA);function DA({file:a,page:t=1,canvasId:e="PDF-canvas",fileZoom:s=1,fileScale:i=1,canvasScale:n=1,canvasClass:r="",isDrop:o=!1,password:h,dropTextOptions:c,dropImageOptions:u,closeSvgOptions:d,selectionOptions:f,manualReload:g,onLoaded:p,onReload:m,onPointerDown:y,onPointerMove:b,onPointerUp:x,onSelectionCreated:C,onSelectionCleared:S},T){const P=tt.useRef(null),M=`${e}-${t-1}`,D=tt.useMemo(()=>s*n,[s,n]),R=tt.useMemo(()=>({...T_,...f}),[f]),{createCanvas:V,specifyPage:H,addFabric:F,addTextFabric:I,renderImage:j,clearActive:K,deleteCanvas:L,scaleFabric:z,setCloseSvgOptions:Z,copyActiveFabric:Dt,deleteActiveFabric:Bt}=Db({id:M,selectionOptions:R,pointerDown:y,pointerMove:b,pointerUp:x,selectionCreated:C,selectionCleared:S});MA(Ze);async function Xt(){window.requestAnimationFrame(async()=>{if(V(),a.PDFBase64.startsWith("data:image")||a.canvas){const{canvas:it}=a,nt=it?7:3,Zt=it!=null&&it.length?it[t-1]:a.PDFBase64;j({url:Zt,scale:i/nt});return}await H({page:t,PDFBase64:a.PDFBase64,scale:i,password:h}),p==null||p()})}function Ft(it){if(it.preventDefault(),it.stopPropagation(),!o||!it.dataTransfer)return;const{dataTransfer:nt,nativeEvent:Zt}=it,{offsetX:Ys,offsetY:Te}=Zt,Kd=nt.getData("text/plain"),qc=nt.getData("text/uri-list"),Jd=nt.getData("custom/offset"),Pr=Jd?JSON.parse(Jd):null,oa={top:Te,left:Ys},Mr={x:(Pr==null?void 0:Pr.offsetX)??0,y:(Pr==null?void 0:Pr.offsetY)??0};qc?_t(qc,oa,Mr):Kd&&oe(Kd,oa,Mr)}function _t(it,nt,Zt){F(it,{...u,...nt},Zt)}function oe(it,nt,Zt){I(it,{...c,...nt},Zt)}function Ze(){g||Xt(),m==null||m()}return tt.useImperativeHandle(T,()=>({reload:Xt,addImage:_t,addText:oe,clearActive:K,deleteCanvas:L,copyActiveFabric:Dt,deleteActiveFabric:Bt,canvasRef:P})),tt.useEffect(()=>{Ze()},[i,t,a,h]),tt.useEffect(()=>{z(D)},[D]),tt.useEffect(()=>{Z(d)},[d]),tt.useEffect(()=>()=>L(),[]),Sm.jsx("div",{style:{transform:`scale(${D})`},onDragOver:it=>it.preventDefault(),onDragEnter:it=>it.preventDefault(),onDrop:Ft,children:Sm.jsx("canvas",{id:M,ref:P,className:r})})}dt.default=OA,dt.loadFile=Pb,dt.useFabric=Db,Object.defineProperties(dt,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});