@component-hook/pdf-canvas 0.2.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/react/pdf-canvas.es.js +7302 -7193
- package/dist/react/pdf-canvas.umd.js +77 -77
- package/dist/vue/pdf-canvas.es.d.ts +3 -1
- package/dist/vue/pdf-canvas.es.js +7387 -7274
- package/dist/vue/pdf-canvas.umd.js +70 -70
- package/package.json +6 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(ut,Q){typeof exports=="object"&&typeof module<"u"?Q(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],Q):(ut=typeof globalThis<"u"?globalThis:ut||self,Q(ut["pdf-canvas"]={},ut.React))})(this,function(ut,Q){"use strict";var jA=Object.defineProperty;var L0=ut=>{throw TypeError(ut)};var NA=(ut,Q,Mt)=>Q in ut?jA(ut,Q,{enumerable:!0,configurable:!0,writable:!0,value:Mt}):ut[Q]=Mt;var J=(ut,Q,Mt)=>NA(ut,typeof Q!="symbol"?Q+"":Q,Mt),_p=(ut,Q,Mt)=>Q.has(ut)||L0("Cannot "+Mt);var l=(ut,Q,Mt)=>(_p(ut,Q,"read from private field"),Mt?Mt.call(ut):Q.get(ut)),v=(ut,Q,Mt)=>Q.has(ut)?L0("Cannot add the same private member more than once"):Q instanceof WeakSet?Q.add(ut):Q.set(ut,Mt),m=(ut,Q,Mt,Bn)=>(_p(ut,Q,"write to private field"),Bn?Bn.call(ut,Mt):Q.set(ut,Mt),Mt),w=(ut,Q,Mt)=>(_p(ut,Q,"access private method"),Mt);var Ze=(ut,Q,Mt,Bn)=>({set _(Mr){m(ut,Q,Mr,Mt)},get _(){return l(ut,Q,Bn)}});var an,qd,wp,yl,Qn,qr,ni,Kr,vl,_l,Ed,F0,Xe,I0,j0,Kd,N0,xp,wl,Jr,Qr,Zn,B0,H0,V0,kd,Ao,xl,De,To,Jd,Kt,tr,Sl,Vt,Pd,W0,Eo,ps,he,ye,ko,hn,Po,Fs,er,Zr,Mo,ta,Ei,ri,ea,Cl,Al,Oo,Tl,ki,sr,Do,ir,Pi,Od,nr,El,rr,sa,kl,Pl,de,xt,ln,ia,Ml,Ol,ar,Mi,cn,Dl,Is,B,Qd,Sp,z0,G0,Zd,X0,U0,Y0,Cp,$0,Ap,Tp,q0,ts,jn,K0,J0,Ep,Q0,Xc,kp,fe,Oi,ai,Lo,Di,ms,Fo,Ri,as,un,na,Li,or,oi,Uc,tf,Rl,ra,Ll,Fl,Il,jl,Nl,Io,dn,aa,hr,fn,Z0,tv,Pp,oa,hi,Rt,jo,lr,Bl,ha,ve,la,gn,cr,Hl,ca,bs,Vl,ua,pn,Fi,No,Bo,js,da,Wl,Dd,K,Mp,zl,Op,ef,ev,sv,Dp,sf,Rp,iv,nv,rv,Lp,av,Fp,ov,hv,lv,Ip,Yc,fa,ga,ge,Rd,cv,Gl,Ho,Vo,Ns,uv,dv,fv,nf,Xl,pa,Wo,mn,bn,Re,ma,ba,W,je,$c,Lh,rf,Fh,gv,jp,Ih,qc,Kc,Np,Jc,li,Bp,Hp,Vp,Ul,Yl,ya,$l,ql,Kl,Jl,zo,ur,St,Go,Xo,Ql,Wp,y0,dr,os,Zl,tc,va,yn,ec,sc,_a,Uo,Yo,fr,$o,ic,qo,wa,nc,rc,xa,Sa,ac,gr,Ko,vn,pv,mv,zp,ys,af,Gp,bv,yv,Fd,pr,_n,Bs,jh,of,wn,jd,Nd,Ca,Aa,Jo,hf,Qo,lf,xn,Ii,Zo,th,Sn,Ta,Qc,vs,oc,Xp,mr,br,Ea,Pa,eh,sh,hc,Up,_s,so,vv,_v,ih,Bd,Hd,nh,Ma,Xt,Cn,rh,lc,cc,ah,An,ci,Tn,uc,En,dc,Oa,Da,Ct,cf,Yp,wv,xv,Sv,Cv,uf,df,$p,fc,gc,pc,mc,bc,Ra,yc,qp,vc,_c,Kp,wc,La,Fa,xc,Ia,Av,Jp,ui,ws,Sc,ja,xs,ie,Tv,Ev,kv,ff,kn,gf,pf,Pv,Qp,Mv,Ss,di,oh,hh,ji,lt,Na,Ba,Cc,Ac,lh,ch,yr,Tc,Vd,Wd,ce,Zc,Ov,Dv,Rv,Lv,Fv,Iv,uh,Ha,Mn,Ec,Cs,kc,Jt,zd,jv,Pc,Mc,vr,fi,Ye,Nv,mf,Bv,Hv,Zp,Oc,dh,gi,Va,fh,ue,Dc,gh,Rc,Lc,_r,pi,ph,Fc,At,tm,em,sm,io,Vv,Pr,mh,Ic,On,Wa,bh,ls,jc,Nc,za,Hs,As,_e,yh,Dn,Le,vh,Vs,Bc,st,im,bf,Wv,zv,Gv,nm,no,Ws,Nh,Xv,yf,tu,Uv,Yv,$v,qv,Kv,Ga,Ts,_h,pe,Xa,Ua,wr,xr,Sr,Ya,mt,rm,am,om,eu,Jv,vf,su,Bh,Ni,me,be,$a,wh,$e,we,zs,qa,Ka,Ja,xh,_f,qe,Hc,Vc,Es,Bi,Hi,Sh,Ch,Ah,xe,Nn,Qv,Zv,t_,Th,Gd,e_,Wt,Se,Cr,Rn,Ar,kh,Vi,Wi,ks,Ph,bt,iu,nu,wf,hm,xf,lm,Sf,s_,Qa,Mh,zi,Tr,Ln,Gs,Er,Oh,Za,mi,Fn,Fe,In,$,kr,Nt,i_,Ui,cm,um,Cf,yi,zc,Ke,to,Xd,n_,Gi,dm,r_,fm;var Mt=typeof document<"u"?document.currentScript:null,Bn={exports:{}},Mr={};/**
|
|
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
|
|
9
|
+
*/var gm;function a_(){if(gm)return Mr;gm=1;var o=Q,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 Mr.Fragment=e,Mr.jsx=r,Mr.jsxs=r,Mr}var Hh={};/**
|
|
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
|
|
18
|
-
`+
|
|
19
|
-
`),
|
|
20
|
-
`),
|
|
21
|
-
`+
|
|
17
|
+
*/var pm;function o_(){return pm||(pm=1,process.env.NODE_ENV!=="production"&&function(){var o=Q,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,b="@@iterator";function _(S){if(S===null||typeof S!="object")return null;var L=p&&S[p]||S[b];return typeof L=="function"?L:null}var y=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function x(S){{for(var L=arguments.length,G=new Array(L>1?L-1:0),tt=1;tt<L;tt++)G[tt-1]=arguments[tt];C("error",S,G)}}function C(S,L,G){{var tt=y.ReactDebugCurrentFrame,_t=tt.getStackAddendum();_t!==""&&(L+="%s",G=G.concat([_t]));var Pt=G.map(function(gt){return String(gt)});Pt.unshift("Warning: "+L),Function.prototype.apply.call(console[S],console,Pt)}}var A=!1,P=!1,D=!1,k=!1,M=!1,R;R=Symbol.for("react.module.reference");function F(S){return!!(typeof S=="string"||typeof S=="function"||S===s||S===n||M||S===i||S===c||S===u||k||S===g||A||P||D||typeof S=="object"&&S!==null&&(S.$$typeof===f||S.$$typeof===d||S.$$typeof===r||S.$$typeof===a||S.$$typeof===h||S.$$typeof===R||S.getModuleId!==void 0))}function I(S,L,G){var tt=S.displayName;if(tt)return tt;var _t=L.displayName||L.name||"";return _t!==""?G+"("+_t+")":G}function Y(S){return S.displayName||"Context"}function N(S){if(S==null)return null;if(typeof S.tag=="number"&&x("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof S=="function")return S.displayName||S.name||null;if(typeof S=="string")return S;switch(S){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 S=="object")switch(S.$$typeof){case a:var L=S;return Y(L)+".Consumer";case r:var G=S;return Y(G._context)+".Provider";case h:return I(S,S.render,"ForwardRef");case d:var tt=S.displayName||null;return tt!==null?tt:N(S.type)||"Memo";case f:{var _t=S,Pt=_t._payload,gt=_t._init;try{return N(gt(Pt))}catch{return null}}}return null}var H=Object.assign,at=0,j,z,it,kt,Ut,ne,zt;function Tt(){}Tt.__reactDisabledLog=!0;function Ce(){{if(at===0){j=console.log,z=console.info,it=console.warn,kt=console.error,Ut=console.group,ne=console.groupCollapsed,zt=console.groupEnd;var S={configurable:!0,enumerable:!0,value:Tt,writable:!0};Object.defineProperties(console,{info:S,log:S,warn:S,error:S,group:S,groupCollapsed:S,groupEnd:S})}at++}}function Xs(){{if(at--,at===0){var S={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:H({},S,{value:j}),info:H({},S,{value:z}),warn:H({},S,{value:it}),error:H({},S,{value:kt}),group:H({},S,{value:Ut}),groupCollapsed:H({},S,{value:ne}),groupEnd:H({},S,{value:zt})})}at<0&&x("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Dt=y.ReactCurrentDispatcher,ft;function Ps(S,L,G){{if(ft===void 0)try{throw Error()}catch(_t){var tt=_t.stack.trim().match(/\n( *(at )?)/);ft=tt&&tt[1]||""}return`
|
|
18
|
+
`+ft+S}}var Xi=!1,Je;{var dA=typeof WeakMap=="function"?WeakMap:Map;Je=new dA}function v0(S,L){if(!S||Xi)return"";{var G=Je.get(S);if(G!==void 0)return G}var tt;Xi=!0;var _t=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var Pt;Pt=Dt.current,Dt.current=null,Ce();try{if(L){var gt=function(){throw Error()};if(Object.defineProperty(gt.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(gt,[])}catch(cs){tt=cs}Reflect.construct(S,[],gt)}else{try{gt.call()}catch(cs){tt=cs}S.call(gt.prototype)}}else{try{throw Error()}catch(cs){tt=cs}S()}}catch(cs){if(cs&&tt&&typeof cs.stack=="string"){for(var ct=cs.stack.split(`
|
|
19
|
+
`),Qe=tt.stack.split(`
|
|
20
|
+
`),Qt=ct.length-1,re=Qe.length-1;Qt>=1&&re>=0&&ct[Qt]!==Qe[re];)re--;for(;Qt>=1&&re>=0;Qt--,re--)if(ct[Qt]!==Qe[re]){if(Qt!==1||re!==1)do if(Qt--,re--,re<0||ct[Qt]!==Qe[re]){var Us=`
|
|
21
|
+
`+ct[Qt].replace(" at new "," at ");return S.displayName&&Us.includes("<anonymous>")&&(Us=Us.replace("<anonymous>",S.displayName)),typeof S=="function"&&Je.set(S,Us),Us}while(Qt>=1&&re>=0);break}}}finally{Xi=!1,Dt.current=Pt,Xs(),Error.prepareStackTrace=_t}var Rh=S?S.displayName||S.name:"",eo=Rh?Ps(Rh):"";return typeof S=="function"&&Je.set(S,eo),eo}function fA(S,L,G){return v0(S,!1)}function gA(S){var L=S.prototype;return!!(L&&L.isReactComponent)}function Ud(S,L,G){if(S==null)return"";if(typeof S=="function")return v0(S,gA(S));if(typeof S=="string")return Ps(S);switch(S){case c:return Ps("Suspense");case u:return Ps("SuspenseList")}if(typeof S=="object")switch(S.$$typeof){case h:return fA(S.render);case d:return Ud(S.type,L,G);case f:{var tt=S,_t=tt._payload,Pt=tt._init;try{return Ud(Pt(_t),L,G)}catch{}}}return""}var Gc=Object.prototype.hasOwnProperty,_0={},w0=y.ReactDebugCurrentFrame;function Yd(S){if(S){var L=S._owner,G=Ud(S.type,S._source,L?L.type:null);w0.setExtraStackFrame(G)}else w0.setExtraStackFrame(null)}function pA(S,L,G,tt,_t){{var Pt=Function.call.bind(Gc);for(var gt in S)if(Pt(S,gt)){var ct=void 0;try{if(typeof S[gt]!="function"){var Qe=Error((tt||"React class")+": "+G+" type `"+gt+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof S[gt]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Qe.name="Invariant Violation",Qe}ct=S[gt](L,gt,tt,G,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(Qt){ct=Qt}ct&&!(ct instanceof Error)&&(Yd(_t),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).",tt||"React class",G,gt,typeof ct),Yd(null)),ct instanceof Error&&!(ct.message in _0)&&(_0[ct.message]=!0,Yd(_t),x("Failed %s type: %s",G,ct.message),Yd(null))}}}var mA=Array.isArray;function pp(S){return mA(S)}function bA(S){{var L=typeof Symbol=="function"&&Symbol.toStringTag,G=L&&S[Symbol.toStringTag]||S.constructor.name||"Object";return G}}function yA(S){try{return x0(S),!1}catch{return!0}}function x0(S){return""+S}function S0(S){if(yA(S))return x("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",bA(S)),x0(S)}var C0=y.ReactCurrentOwner,vA={key:!0,ref:!0,__self:!0,__source:!0},A0,T0;function _A(S){if(Gc.call(S,"ref")){var L=Object.getOwnPropertyDescriptor(S,"ref").get;if(L&&L.isReactWarning)return!1}return S.ref!==void 0}function wA(S){if(Gc.call(S,"key")){var L=Object.getOwnPropertyDescriptor(S,"key").get;if(L&&L.isReactWarning)return!1}return S.key!==void 0}function xA(S,L){typeof S.ref=="string"&&C0.current}function SA(S,L){{var G=function(){A0||(A0=!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)",L))};G.isReactWarning=!0,Object.defineProperty(S,"key",{get:G,configurable:!0})}}function CA(S,L){{var G=function(){T0||(T0=!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)",L))};G.isReactWarning=!0,Object.defineProperty(S,"ref",{get:G,configurable:!0})}}var AA=function(S,L,G,tt,_t,Pt,gt){var ct={$$typeof:t,type:S,key:L,ref:G,props:gt,_owner:Pt};return ct._store={},Object.defineProperty(ct._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(ct,"_self",{configurable:!1,enumerable:!1,writable:!1,value:tt}),Object.defineProperty(ct,"_source",{configurable:!1,enumerable:!1,writable:!1,value:_t}),Object.freeze&&(Object.freeze(ct.props),Object.freeze(ct)),ct};function TA(S,L,G,tt,_t){{var Pt,gt={},ct=null,Qe=null;G!==void 0&&(S0(G),ct=""+G),wA(L)&&(S0(L.key),ct=""+L.key),_A(L)&&(Qe=L.ref,xA(L,_t));for(Pt in L)Gc.call(L,Pt)&&!vA.hasOwnProperty(Pt)&&(gt[Pt]=L[Pt]);if(S&&S.defaultProps){var Qt=S.defaultProps;for(Pt in Qt)gt[Pt]===void 0&&(gt[Pt]=Qt[Pt])}if(ct||Qe){var re=typeof S=="function"?S.displayName||S.name||"Unknown":S;ct&&SA(gt,re),Qe&&CA(gt,re)}return AA(S,ct,Qe,_t,tt,C0.current,gt)}}var mp=y.ReactCurrentOwner,E0=y.ReactDebugCurrentFrame;function Dh(S){if(S){var L=S._owner,G=Ud(S.type,S._source,L?L.type:null);E0.setExtraStackFrame(G)}else E0.setExtraStackFrame(null)}var bp;bp=!1;function yp(S){return typeof S=="object"&&S!==null&&S.$$typeof===t}function k0(){{if(mp.current){var S=N(mp.current.type);if(S)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+S+"`."}return""}}function
|
|
23
|
+
Check the render method of \``+S+"`."}return""}}function EA(S){return""}var P0={};function kA(S){{var L=k0();if(!L){var G=typeof S=="string"?S:S.displayName||S.name;G&&(L=`
|
|
24
24
|
|
|
25
|
-
Check the top-level render call using <`+G+">.")}return L}}function
|
|
25
|
+
Check the top-level render call using <`+G+">.")}return L}}function M0(S,L){{if(!S._store||S._store.validated||S.key!=null)return;S._store.validated=!0;var G=kA(L);if(P0[G])return;P0[G]=!0;var tt="";S&&S._owner&&S._owner!==mp.current&&(tt=" It was passed a child from "+N(S._owner.type)+"."),Dh(S),x('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',G,tt),Dh(null)}}function O0(S,L){{if(typeof S!="object")return;if(pp(S))for(var G=0;G<S.length;G++){var tt=S[G];yp(tt)&&M0(tt,L)}else if(yp(S))S._store&&(S._store.validated=!0);else if(S){var _t=_(S);if(typeof _t=="function"&&_t!==S.entries)for(var Pt=_t.call(S),gt;!(gt=Pt.next()).done;)yp(gt.value)&&M0(gt.value,L)}}}function PA(S){{var L=S.type;if(L==null||typeof L=="string")return;var G;if(typeof L=="function")G=L.propTypes;else if(typeof L=="object"&&(L.$$typeof===h||L.$$typeof===d))G=L.propTypes;else return;if(G){var tt=N(L);pA(G,S.props,"prop",tt,S)}else if(L.PropTypes!==void 0&&!bp){bp=!0;var _t=N(L);x("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",_t||"Unknown")}typeof L.getDefaultProps=="function"&&!L.getDefaultProps.isReactClassApproved&&x("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function MA(S){{for(var L=Object.keys(S.props),G=0;G<L.length;G++){var tt=L[G];if(tt!=="children"&&tt!=="key"){Dh(S),x("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",tt),Dh(null);break}}S.ref!==null&&(Dh(S),x("Invalid attribute `ref` supplied to `React.Fragment`."),Dh(null))}}var D0={};function R0(S,L,G,tt,_t,Pt){{var gt=F(S);if(!gt){var ct="";(S===void 0||typeof S=="object"&&S!==null&&Object.keys(S).length===0)&&(ct+=" 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 Qe=EA();Qe?ct+=Qe:ct+=k0();var Qt;S===null?Qt="null":pp(S)?Qt="array":S!==void 0&&S.$$typeof===t?(Qt="<"+(N(S.type)||"Unknown")+" />",ct=" Did you accidentally export a JSX literal instead of a component?"):Qt=typeof S,x("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",Qt,ct)}var re=TA(S,L,G,_t,Pt);if(re==null)return re;if(gt){var Us=L.children;if(Us!==void 0)if(tt)if(pp(Us)){for(var Rh=0;Rh<Us.length;Rh++)O0(Us[Rh],S);Object.freeze&&Object.freeze(Us)}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 O0(Us,S)}if(Gc.call(L,"key")){var eo=N(S),cs=Object.keys(L).filter(function(IA){return IA!=="key"}),vp=cs.length>0?"{key: someKey, "+cs.join(": ..., ")+": ...}":"{key: someKey}";if(!D0[eo+vp]){var FA=cs.length>0?"{"+cs.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} />`,
|
|
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(),Ui("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const By={};let Jp;const bi=()=>Jp||(Jp={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new Ny,dispose(){},copyPasteData:By}),Yo=()=>bi().document,Bc=()=>bi().window,Qp=()=>{var a;return Math.max((a=ft.devicePixelRatio)!==null&&a!==void 0?a:Bc().devicePixelRatio,1)},Eh=new class{constructor(){E(this,"charWidthsCache",{}),E(this,"boundsOfCurveCache",{})}getFontCache(a){let{fontFamily:t,fontStyle:e,fontWeight:s}=a;t=t.toLowerCase(),this.charWidthsCache[t]||(this.charWidthsCache[t]={});const i=this.charWidthsCache[t],n="".concat(e.toLowerCase(),"_").concat((s+"").toLowerCase());return i[n]||(i[n]={}),i[n]}clearFontCache(a){(a=(a||"").toLowerCase())?this.charWidthsCache[a]&&delete this.charWidthsCache[a]:this.charWidthsCache={}}limitDimsByArea(a){const{perfLimitSizeTotal:t}=ft,e=Math.sqrt(t*a);return[Math.floor(e),Math.floor(t/e)]}},ig="6.5.3";function Cr(){}const jn=Math.PI/2,Yi=2*Math.PI,ng=Math.PI/180,Fe=Object.freeze([1,0,0,1,0,0]),rg=16,Nn=.4477152502,tt="center",vt="left",Qe="top",og="bottom",Ut="right",Ie="none",ag=/\r?\n/,Zp="moving",Hc="scaling",tm="rotating",hg="rotate",em="skewing",kh="resizing",Hy="modifyPoly",Vy="modifyPath",Vc="changed",Gc="scale",je="scaleX",hs="scaleY",$o="skewX",qo="skewY",Qt="fill",Ne="stroke",Wc="modified",Ko="json",lg="svg",W=new class{constructor(){this[Ko]=new Map,this[lg]=new Map}has(a){return this[Ko].has(a)}getClass(a){const t=this[Ko].get(a);if(!t)throw new vi("No class registered for ".concat(a));return t}setClass(a,t){t?this[Ko].set(t,a):(this[Ko].set(a.type,a),this[Ko].set(a.type.toLowerCase(),a))}getSVGClass(a){return this[lg].get(a)}setSVGClass(a,t){this[lg].set(t??a.type.toLowerCase(),a)}},zc=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 Gy{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 Ar=(a,t)=>{const e=a.indexOf(t);return e!==-1&&a.splice(e,1),a},zs=a=>{if(a===0)return 1;switch(Math.abs(a)/jn){case 1:case 3:return 0;case 2:return-1}return Math.cos(a)},Xs=a=>{if(a===0)return 0;const t=a/jn,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]:cg;const s=Xs(t),i=zs(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 cg=new O(0,0),Xc=a=>!!a&&Array.isArray(a._objects);function sm(a){class t extends a{constructor(){super(...arguments),E(this,"_objects",[])}_onObjectAdded(s){}_onObjectRemoved(s){}_onStackOrderChanged(s){}add(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];const r=this._objects.push(...i);return i.forEach(o=>this._onObjectAdded(o)),r}insertAt(s){for(var i=arguments.length,n=new Array(i>1?i-1:0),r=1;r<i;r++)n[r-1]=arguments[r];return this._objects.splice(s,0,...n),n.forEach(o=>this._onObjectAdded(o)),this._objects.length}remove(){const s=this._objects,i=[];for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return r.forEach(h=>{const c=s.indexOf(h);c!==-1&&(s.splice(c,1),i.push(h),this._onObjectRemoved(h))}),i}forEachObject(s){this.getObjects().forEach((i,n,r)=>s(i,n,r))}getObjects(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];return i.length===0?[...this._objects]:this._objects.filter(r=>r.isType(...i))}item(s){return this._objects[s]}isEmpty(){return this._objects.length===0}size(){return this._objects.length}contains(s,i){return!!this._objects.includes(s)||!!i&&this._objects.some(n=>n instanceof t&&n.contains(s,!0))}complexity(){return this._objects.reduce((s,i)=>s+=i.complexity?i.complexity():0,0)}sendObjectToBack(s){return!(!s||s===this._objects[0])&&(Ar(this._objects,s),this._objects.unshift(s),this._onStackOrderChanged(s),!0)}bringObjectToFront(s){return!(!s||s===this._objects[this._objects.length-1])&&(Ar(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 Ar(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 Ar(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}moveObjectTo(s,i){return s!==this._objects[i]&&(Ar(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 g=this._objects.length-1;g>=0;g--){const f=this._objects[g];f.selectable&&f.visible&&(h&&f.intersectsWithRect(u,d)||f.isContainedWithinRect(u,d)||h&&f.containsPoint(u)||h&&f.containsPoint(d))&&c.push(f)}return c}}return t}class im extends Gy{_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 Ph(a){return Bc().requestAnimationFrame(a)}function nm(a){return Bc().cancelAnimationFrame(a)}let Wy=0;const Bn=()=>Wy++,Cs=()=>{const a=Yo().createElement("canvas");if(!a||a.getContext===void 0)throw new vi("Failed to create `canvas` element");return a},rm=()=>Yo().createElement("img"),Us=a=>{const t=Cs();return t.width=a.width,t.height=a.height,t},ug=(a,t,e)=>a.toDataURL("image/".concat(t),e),zt=a=>a*ng,Hn=a=>a/ng,om=a=>a.every((t,e)=>t===Fe[e]),Se=(a,t,e)=>new O(a).transform(t,e),Ze=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},Yt=(a,t,e)=>[a[0]*t[0]+a[2]*t[1],a[1]*t[0]+a[3]*t[1],a[0]*t[2]+a[2]*t[3],a[1]*t[2]+a[3]*t[3],e?0:a[0]*t[4]+a[2]*t[5]+a[4],e?0:a[1]*t[4]+a[3]*t[5]+a[5]],Uc=(a,t)=>a.reduceRight((e,s)=>s&&e?Yt(s,e,t):s||e,void 0)||Fe.concat(),am=a=>{let[t,e]=a;return Math.atan2(e,t)},Tr=a=>{const t=am(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:Hn(t),scaleX:s,scaleY:i,skewX:Hn(n),skewY:0,translateX:a[4]||0,translateY:a[5]||0}},Jo=function(a){return[1,0,0,1,a,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function Qo(){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=zt(a),i=zs(s),n=Xs(s);return[i,n,-n,i,t?t-(i*t-n*e):0,e?e-(n*t+i*e):0]}const Yc=function(a){return[a,0,0,arguments.length>1&&arguments[1]!==void 0?arguments[1]:a,0,0]},hm=a=>Math.tan(zt(a)),dg=a=>[1,0,hm(a),1,0,0],gg=a=>[1,hm(a),0,1,0,0],Mh=a=>{let{scaleX:t=1,scaleY:e=1,flipX:s=!1,flipY:i=!1,skewX:n=0,skewY:r=0}=a,o=Yc(s?-t:t,i?-e:e);return n&&(o=Yt(o,dg(n),!0)),r&&(o=Yt(o,gg(r),!0)),o},lm=a=>{const{translateX:t=0,translateY:e=0,angle:s=0}=a;let i=Jo(t,e);s&&(i=Yt(i,Qo({angle:s})));const n=Mh(a);return om(n)||(i=Yt(i,n)),i},Oh=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 sg("loadImage"));const n=rm();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 vi("Error loading ".concat(n.src)))},e&&(n.crossOrigin=e),n.src=a):o()})},Zo=function(a){let{signal:t,reviver:e=Cr}=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=>W.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)})})},Dh=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&&W.has(o.type)?Zo([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)})})},Er=function(a){return(arguments.length>1&&arguments[1]!==void 0?arguments[1]:[]).reduce((t,e)=>(e in a&&(t[e]=a[e]),t),{})},fg=(a,t)=>Object.keys(a).reduce((e,s)=>(t(a[s],s,a)&&(e[s]=a[s]),e),{}),cm={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"},pg=(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),um=(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]},dm=function(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"1";return parseFloat(a)/(a.endsWith("%")?100:1)},$c=a=>Math.min(Math.round(a),255).toString(16).toUpperCase().padStart(2,"0"),gm=a=>{let[t,e,s,i=1]=a;const n=Math.round(.3*t+.59*e+.11*s);return[n,n,n,i]};class _t{constructor(t){if(E(this,"isUnrecognised",!1),t)if(t instanceof _t)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 cm&&(t=cm[t]),t==="transparent"?[255,255,255,0]:_t.sourceFromHex(t)||_t.sourceFromRgb(t)||_t.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]=um(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(s,"%)")}toHsla(){const[t,e,s,i]=um(...this.getSource());return"hsla(".concat(t,",").concat(e,"%,").concat(s,"%,").concat(i,")")}toHex(){return this.toHexa().slice(0,6)}toHexa(){const[t,e,s,i]=this.getSource();return"".concat($c(t)).concat($c(e)).concat($c(s)).concat($c(Math.round(255*i)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(gm(this.getSource())),this}toBlackWhite(t){const[e,,,s]=gm(this.getSource()),i=e<(t||127)?0:255;return this.setSource([i,i,i,s]),this}overlayWith(t){t instanceof _t||(t=new _t(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 _t.fromRgba(t)}static fromRgba(t){return new _t(_t.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,dm(e[4])]}}static fromHsl(t){return _t.fromHsla(t)}static fromHsla(t){return new _t(_t.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=(_t.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=pg(u,c,s+1/3),o=pg(u,c,s),h=pg(u,c,s-1/3)}return[Math.round(255*r),Math.round(255*o),Math.round(255*h),dm(e[4])]}static fromHex(t){return new _t(_t.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")?Hn(s):e.includes("turn")?360*s:s}}const Rt=(a,t)=>parseFloat(Number(a).toFixed(t)),Be=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:rg;const e=/\D{0,2}$/.exec(a),s=parseFloat(a),i=ft.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}},mg=a=>{const[t,e]=a.trim().split(" "),[s,i]=(n=t)&&n!==Ie?[n.slice(1,4),n.slice(5,8)]:n===Ie?[n,n]:["Mid","Mid"];var n;return{meetOrSlice:e||"meet",alignX:s,alignY:i}},Rh=a=>"matrix("+a.map(t=>Rt(t,ft.NUM_FRACTION_DIGITS)).join(" ")+")",Lh=function(a,t){let e,s,i=!(arguments.length>2&&arguments[2]!==void 0)||arguments[2];if(t)if(t.toLive)e="url(#SVGID_".concat(t.id,")");else{const n=new _t(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,'" '):"")},As=a=>!!a&&a.toLive!==void 0,fm=a=>!!a&&typeof a.toObject=="function",pm=a=>!!a&&a.offsetX!==void 0&&"source"in a,kr=a=>!!a&&"multiSelectionStacking"in a;function mm(a){const t=a&&Ys(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 Ys=a=>a.ownerDocument||null,vm=a=>{var t;return((t=a.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null},bm=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))},vg=(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 ym(a){return a.onselectstart!==void 0&&(a.onselectstart=()=>!1),a.style.userSelect=Ie,a}class _m{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&&Yo().getElementById(t)||Cs();var s;if(e.hasAttribute("data-fabric"))throw new vi("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){vg(this.lower.el,t)}calcOffset(){return function(t){var e;const s=t&&Ys(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=mm(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(){bi().dispose(this.lower.el),delete this.lower}}const zy={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...Fe]};class Fh extends sm(im){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 Fh.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 _m(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&&(Ui("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?
|
|
30
|
+
<%s key={someKey} {...props} />`,vp,eo,FA,eo),D0[eo+vp]=!0}}return S===s?MA(re):PA(re),re}}function OA(S,L,G){return R0(S,L,G,!0)}function DA(S,L,G){return R0(S,L,G,!1)}var RA=DA,LA=OA;Hh.Fragment=s,Hh.jsx=RA,Hh.jsxs=LA}()),Hh}process.env.NODE_ENV==="production"?Bn.exports=a_():Bn.exports=o_();var mm=Bn.exports;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||"default");if(typeof h!="object")return h;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(n)}(s,"string");return typeof i=="symbol"?i:i+""}(t))in o?Object.defineProperty(o,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):o[t]=e,o}function bm(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?bm(Object(e),!0).forEach(function(s){E(o,s,e[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(o,Object.getOwnPropertyDescriptors(e)):bm(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 Hn(o,t){return t||(t=o.slice(0)),Object.freeze(Object.defineProperties(o,{raw:{value:Object.freeze(t)}}))}class ym{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 pt=new class extends ym{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 ym,e=(o==null?void 0:o.reduce((s,i)=>(s[i]=t[i],s),{}))||t;this.configure(e)}},Yi=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 vi extends Error{constructor(t,e){super("fabric: ".concat(t),e)}}class Af extends vi{constructor(t){super("".concat(t," 'options.signal' is in 'aborted' state"))}}class h_{}class l_ extends h_{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(),Yi("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const c_={};let vm;const _i=()=>vm||(vm={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new l_,dispose(){},copyPasteData:c_}),ro=()=>_i().document,ru=()=>_i().window,_m=()=>{var o;return Math.max((o=pt.devicePixelRatio)!==null&&o!==void 0?o:ru().devicePixelRatio,1)},Vh=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}=pt,e=Math.sqrt(t*o);return[Math.floor(e),Math.floor(t/e)]}},Tf="6.5.4";function Or(){}const Vn=Math.PI/2,$i=2*Math.PI,Ef=Math.PI/180,Ne=Object.freeze([1,0,0,1,0,0]),kf=16,Wn=.4477152502,et="center",vt="left",es="top",Pf="bottom",Yt="right",Be="none",Mf=/\r?\n/,wm="moving",au="scaling",xm="rotating",Of="rotate",Sm="skewing",Wh="resizing",u_="modifyPoly",d_="modifyPath",ou="changed",hu="scale",He="scaleX",us="scaleY",ao="skewX",oo="skewY",Zt="fill",Ve="stroke",lu="modified",ho="json",Df="svg",V=new class{constructor(){this[ho]=new Map,this[Df]=new Map}has(o){return this[ho].has(o)}getClass(o){const t=this[ho].get(o);if(!t)throw new vi("No class registered for ".concat(o));return t}setClass(o,t){t?this[ho].set(t,o):(this[ho].set(o.type,o),this[ho].set(o.type.toLowerCase(),o))}getSVGClass(o){return this[Df].get(o)}setSVGClass(o,t){this[Df].set(t??o.type.toLowerCase(),o)}},cu=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 f_{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 Dr=(o,t)=>{const e=o.indexOf(t);return e!==-1&&o.splice(e,1),o},Ys=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)},$s=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 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]:Rf;const s=$s(t),i=Ys(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 Rf=new O(0,0),uu=o=>!!o&&Array.isArray(o._objects);function Cm(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])&&(Dr(this._objects,s),this._objects.unshift(s),this._onStackOrderChanged(s),!0)}bringObjectToFront(s){return!(!s||s===this._objects[this._objects.length-1])&&(Dr(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 Dr(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 Dr(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}moveObjectTo(s,i){return s!==this._objects[i]&&(Dr(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 O(i,n),d=u.add(new O(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 Am 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 zh(o){return ru().requestAnimationFrame(o)}function Tm(o){return ru().cancelAnimationFrame(o)}let g_=0;const zn=()=>g_++,Ms=()=>{const o=ro().createElement("canvas");if(!o||o.getContext===void 0)throw new vi("Failed to create `canvas` element");return o},Em=()=>ro().createElement("img"),qs=o=>{const t=Ms();return t.width=o.width,t.height=o.height,t},Lf=(o,t,e)=>o.toDataURL("image/".concat(t),e),Gt=o=>o*Ef,Gn=o=>o/Ef,km=o=>o.every((t,e)=>t===Ne[e]),Ae=(o,t,e)=>new O(o).transform(t,e),ss=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 O(o[4],o[5]).transform(e,!0);return e[4]=-s,e[5]=-i,e},$t=(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]],du=(o,t)=>o.reduceRight((e,s)=>s&&e?$t(s,e,t):s||e,void 0)||Ne.concat(),Pm=o=>{let[t,e]=o;return Math.atan2(e,t)},Rr=o=>{const t=Pm(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:Gn(t),scaleX:s,scaleY:i,skewX:Gn(n),skewY:0,translateX:o[4]||0,translateY:o[5]||0}},lo=function(o){return[1,0,0,1,o,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function co(){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=Gt(o),i=Ys(s),n=$s(s);return[i,n,-n,i,t?t-(i*t-n*e):0,e?e-(n*t+i*e):0]}const fu=function(o){return[o,0,0,arguments.length>1&&arguments[1]!==void 0?arguments[1]:o,0,0]},Mm=o=>Math.tan(Gt(o)),Ff=o=>[1,0,Mm(o),1,0,0],If=o=>[1,Mm(o),0,1,0,0],Gh=o=>{let{scaleX:t=1,scaleY:e=1,flipX:s=!1,flipY:i=!1,skewX:n=0,skewY:r=0}=o,a=fu(s?-t:t,i?-e:e);return n&&(a=$t(a,Ff(n),!0)),r&&(a=$t(a,If(r),!0)),a},Om=o=>{const{translateX:t=0,translateY:e=0,angle:s=0}=o;let i=lo(t,e);s&&(i=$t(i,co({angle:s})));const n=Gh(o);return km(n)||(i=$t(i,n)),i},Xh=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 Af("loadImage"));const n=Em();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 vi("Error loading ".concat(n.src)))},e&&(n.crossOrigin=e),n.src=o):a()})},uo=function(o){let{signal:t,reviver:e=Or}=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=>V.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)})})},Uh=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&&V.has(a.type)?uo([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)})})},Lr=function(o){return(arguments.length>1&&arguments[1]!==void 0?arguments[1]:[]).reduce((t,e)=>(e in o&&(t[e]=o[e]),t),{})},jf=(o,t)=>Object.keys(o).reduce((e,s)=>(t(o[s],s,o)&&(e[s]=o[s]),e),{}),Dm={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"},Nf=(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),Rm=(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]},Lm=function(){let o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"1";return parseFloat(o)/(o.endsWith("%")?100:1)},gu=o=>Math.min(Math.round(o),255).toString(16).toUpperCase().padStart(2,"0"),Fm=o=>{let[t,e,s,i=1]=o;const n=Math.round(.3*t+.59*e+.11*s);return[n,n,n,i]};class wt{constructor(t){if(E(this,"isUnrecognised",!1),t)if(t instanceof wt)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 Dm&&(t=Dm[t]),t==="transparent"?[255,255,255,0]:wt.sourceFromHex(t)||wt.sourceFromRgb(t)||wt.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]=Rm(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(s,"%)")}toHsla(){const[t,e,s,i]=Rm(...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(gu(t)).concat(gu(e)).concat(gu(s)).concat(gu(Math.round(255*i)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(Fm(this.getSource())),this}toBlackWhite(t){const[e,,,s]=Fm(this.getSource()),i=e<(t||127)?0:255;return this.setSource([i,i,i,s]),this}overlayWith(t){t instanceof wt||(t=new wt(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 wt.fromRgba(t)}static fromRgba(t){return new wt(wt.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,Lm(e[4])]}}static fromHsl(t){return wt.fromHsla(t)}static fromHsla(t){return new wt(wt.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=(wt.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=Nf(u,c,s+1/3),a=Nf(u,c,s),h=Nf(u,c,s-1/3)}return[Math.round(255*r),Math.round(255*a),Math.round(255*h),Lm(e[4])]}static fromHex(t){return new wt(wt.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")?Gn(s):e.includes("turn")?360*s:s}}const Ft=(o,t)=>parseFloat(Number(o).toFixed(t)),We=function(o){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:kf;const e=/\D{0,2}$/.exec(o),s=parseFloat(o),i=pt.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}},Bf=o=>{const[t,e]=o.trim().split(" "),[s,i]=(n=t)&&n!==Be?[n.slice(1,4),n.slice(5,8)]:n===Be?[n,n]:["Mid","Mid"];var n;return{meetOrSlice:e||"meet",alignX:s,alignY:i}},Yh=o=>"matrix("+o.map(t=>Ft(t,pt.NUM_FRACTION_DIGITS)).join(" ")+")",$h=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 wt(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,'" '):"")},Os=o=>!!o&&o.toLive!==void 0,Im=o=>!!o&&typeof o.toObject=="function",jm=o=>!!o&&o.offsetX!==void 0&&"source"in o,Fr=o=>!!o&&"multiSelectionStacking"in o;function Nm(o){const t=o&&Ks(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 Ks=o=>o.ownerDocument||null,Bm=o=>{var t;return((t=o.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null},Hm=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))},Hf=(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 Vm(o){return o.onselectstart!==void 0&&(o.onselectstart=()=>!1),o.style.userSelect=Be,o}class Wm{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&&ro().getElementById(t)||Ms();var s;if(e.hasAttribute("data-fabric"))throw new vi("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;Hm(s,i,t,e)}setCSSDimensions(t){Hf(this.lower.el,t)}calcOffset(){return function(t){var e;const s=t&&Ks(t),i={left:0,top:0};if(!s)return i;const n=((e=Bm(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=Nm(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(){_i().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:[...Ne]};class qh extends Cm(Am){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 qh.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 Wm(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&&(Yi("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?_m():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=Ae(t,ss(i));i[0]=e,i[3]=e;const r=Ae(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=zh(()=>this.renderAndReset()))}calcViewportBoundaries(){const t=this.width,e=this.height,s=ss(this.viewportTransform),i=Ae({x:0,y:0},s),n=Ae({x:t,y:e},s),r=i.min(n),a=i.max(n);return this.vptCoords={tl:r,tr:new O(a.x,r.y),bl:new O(r.x,a.y),br:a}}cancelRequestedRender(){this.nextRenderHandle&&(Tm(this.nextRenderHandle),this.nextRenderHandle=0)}drawControls(t){}renderCanvas(t,e){if(this.destroyed)return;const s=this.viewportTransform,i=this.clipPath;this.calcViewportBoundaries(),this.clearContext(t),t.imageSmoothingEnabled=this.imageSmoothingEnabled,t.patternQuality="best",this.fire("before:render",{ctx:t}),this._renderBackground(t),t.save(),t.transform(s[0],s[1],s[2],s[3],s[4],s[5]),this._renderObjects(t,e),t.restore(),this.controlsAboveOverlay||this.skipControlsDrawing||this.drawControls(t),i&&(i._set("canvas",this),i.shouldCache(),i._transformDone=!0,i.renderCache({forClipping:!0}),this.drawClipPathOnCanvas(t,i)),this._renderOverlay(t),this.controlsAboveOverlay&&!this.skipControlsDrawing&&this.drawControls(t),this.fire("after:render",{ctx:t}),this.__cleanupTask&&(this.__cleanupTask(),this.__cleanupTask=void 0)}drawClipPathOnCanvas(t,e){const s=this.viewportTransform;t.save(),t.transform(...s),t.globalCompositeOperation="destination-in",e.transform(t),t.scale(1/e.zoomX,1/e.zoomY),t.drawImage(e._cacheCanvas,-e.cacheTranslationX,-e.cacheTranslationY),t.restore()}_renderObjects(t,e){for(let s=0,i=e.length;s<i;++s)e[s]&&e[s].render(t)}_renderBackgroundOrOverlay(t,e){const s=this["".concat(e,"Color")],i=this["".concat(e,"Image")],n=this.viewportTransform,r=this["".concat(e,"Vpt")];if(!s&&!i)return;const a=Os(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 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 Ae(this.getCenterPoint(),ss(this.viewportTransform))}_centerObject(t,e){t.setXY(e,et,et),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:Tf},Lr(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 Os(r)?r.excludeFromExport||(s.background=r.toObject(e)):r&&(s.background=r),Os(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,`)" >
|
|
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=
|
|
37
|
-
`,"<desc>Created with Fabric.js ",
|
|
36
|
+
`)}_setSVGHeader(t,e){const s=e.width||"".concat(this.width),i=e.height||"".concat(this.height),n=pt.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(Ft(-h[4]/h[0],n)," ").concat(Ft(-h[5]/h[3],n)," ").concat(Ft(this.width/h[0],n)," ").concat(Ft(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 ",Tf,`</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(
|
|
40
|
+
`)}createSVGClipPathMarkup(t){const e=this.clipPath;return e?(e.clipPathId="CLIPPATH_".concat(zn()),'<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(
|
|
42
|
+
`)):""}createSVGRefElementsMarkup(){return["background","overlay"].map(t=>{const e=this["".concat(t,"Color")];if(Os(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?Yh(i):""})}}).join("")}createSVGFontFacesMarkup(){const t=[],e={},s=pt.fontPaths;this._objects.forEach(function n(r){t.push(r),uu(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 {
|
|
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(
|
|
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(Os(s)){const i=s.repeat||"",n=this.width,r=this.height,a=this["".concat(e,"Vpt")]?Yh(ss(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"||!jm(s)?n:s.source.width,'" height="').concat(i!=="repeat-x"&&i!=="no-repeat"||!jm(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 vi("`json` is undefined"));const i=typeof t=="string"?JSON.parse(t):t,{objects:n=[],backgroundImage:r,background:
|
|
50
|
+
`)}loadFromJSON(t,e){let{signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(!t)return Promise.reject(new vi("`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([uo(n,{reviver:e,signal:s}),Uh({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=qs(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 Lf(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,b=[g,0,0,g,(p[4]-(i||0))*t,(p[5]-(n||0))*t],_=this.enableRetinaScaling,y=qs({width:a,height:h}),x=r?this._objects.filter(C=>r(C)):this._objects;return this.enableRetinaScaling=!1,this.viewportTransform=b,this.width=a,this.height=h,this.skipControlsDrawing=!0,this.calcViewportBoundaries(),this.renderCanvas(y.getContext("2d"),x),this.viewportTransform=p,this.width=u,this.height=d,this.calcViewportBoundaries(),this.enableRetinaScaling=_,this.skipControlsDrawing=f,y}dispose(){return!this.disposed&&this.elements.cleanupDOM({width:this.width,height:this.height}),cu.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(qh,"ownDefaults",p_);const m_=["touchstart","touchmove","touchend"],zm=o=>{const t=Nm(o.target),e=function(s){const i=s.changedTouches;return i&&i[0]?i[0]:s}(o);return new O(e.clientX+t.left,e.clientY+t.top)},pu=o=>m_.includes(o.type)||o.pointerType==="touch",Vf=o=>{o.preventDefault(),o.stopPropagation()},wi=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}},b_=["translateX","translateY","scaleX","scaleY"],Gm=(o,t)=>fo(o,$t(t,o.calcOwnMatrix())),fo=(o,t)=>{const e=Rr(t),{translateX:s,translateY:i,scaleX:n,scaleY:r}=e,a=Lt(e,b_),h=new O(s,i);o.flipX=!1,o.flipY=!1,Object.assign(o,a),o.set({scaleX:n,scaleY:r}),o.setPositionByOrigin(h,et,et)},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}),mu=(o,t,e)=>{const s=o/2,i=t/2,n=[new O(-s,-i),new O(s,-i),new O(-s,i),new O(s,i)].map(a=>a.transform(e)),r=wi(n);return new O(r.width,r.height)},Kh=function(){let o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Ne;return $t(ss(arguments.length>1&&arguments[1]!==void 0?arguments[1]:Ne),o)},Ir=function(o){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Ne,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Ne;return o.transform(Kh(t,e))},Um=function(o){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Ne,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Ne;return o.transform(Kh(t,e),!0)},zf=(o,t,e)=>{const s=Kh(t,e);return fo(o,$t(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)},y_={left:-.5,top:-.5,center:0,bottom:.5,right:.5},te=o=>typeof o=="string"?y_[o]:o-.5,bu="not-allowed";function $m(o){return te(o.originX)===te(et)&&te(o.originY)===te(et)}function qm(o){return .5-te(o)}const Js=(o,t)=>o[t],Km=(o,t,e,s)=>({e:o,transform:t,pointer:new O(e,s)});function Jm(o,t){const e=o.getTotalAngle()+Gn(Math.atan2(t.y,t.x))+360;return Math.round(e%360/45)}function Gf(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,b){const _=f.getRelativeCenterPoint(),y=p!==void 0&&b!==void 0?f.translateToGivenOrigin(_,et,et,p,b):new O(f.left,f.top);return(f.angle?g.rotate(-Gt(f.angle),_):g).subtract(y)}(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 v_=(o,t,e,s)=>{const{target:i,offsetX:n,offsetY:r}=t,a=e-n,h=s-r,c=!Js(i,"lockMovementX")&&i.left!==a,u=!Js(i,"lockMovementY")&&i.top!==h;return c&&i.set(vt,a),u&&i.set(es,h),(c||u)&&Ym(wm,Km(o,t,e,s)),c||u};class Qm{getSvgStyles(t){const e=this.fillRule?this.fillRule:"nonzero",s=this.strokeWidth?this.strokeWidth:"0",i=this.strokeDashArray?this.strokeDashArray.join(" "):Be,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=$h(Zt,this.fill);return[$h(Ve,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(Yh(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=[],b=t.indexOf("COMMON_PARTS");let _;h&&(h.clipPathId="CLIPPATH_".concat(zn()),_='<clipPath id="'.concat(h.clipPathId,`" >
|
|
51
51
|
`).concat(h.toClipPathSVG(s),`</clipPath>
|
|
52
|
-
`)),u&&p.push("<g ",
|
|
53
|
-
`),p.push("<g ",this.getSvgTransform(!1),u?"":
|
|
54
|
-
`);const
|
|
52
|
+
`)),u&&p.push("<g ",a,this.getSvgCommons(),` >
|
|
53
|
+
`),p.push("<g ",this.getSvgTransform(!1),u?"":a+this.getSvgCommons(),` >
|
|
54
|
+
`);const y=[r,c,e?"":this.addPaintOrder()," ",n?'transform="'.concat(n,'" '):""].join("");return t[b]=y,Os(f)&&p.push(f.toSVG(this)),Os(d)&&p.push(d.toSVG(this)),g&&p.push(g.toSVG(this)),h&&p.push(_),p.push(t.join("")),p.push(`</g>
|
|
55
55
|
`),u&&p.push(`</g>
|
|
56
|
-
`),s?s(p.join("")):p.join("")}addPaintOrder(){return this.paintFirst!==
|
|
57
|
-
<feGaussianBlur in="SourceAlpha" stdDeviation="`).concat(
|
|
58
|
-
<feOffset dx="`).concat(
|
|
56
|
+
`),s?s(p.join("")):p.join("")}addPaintOrder(){return this.paintFirst!==Zt?' paint-order="'.concat(this.paintFirst,'" '):""}}function yu(o){return new RegExp("^("+o.join("|")+")\\b","i")}var Zm;const Qs=String.raw(Zm||(Zm=Hn(["(?:[-+]?(?:d*.d+|d+.?)(?:[eE][-+]?d+)?)"],["(?:[-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?)"]))),Xf="http://www.w3.org/2000/svg",__=new RegExp("(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*("+Qs+"(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|"+Qs+"))?\\s+(.*)"),w_={cx:vt,x:vt,r:"radius",cy:es,y:es,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"},Uf="font-size",Yf="clip-path",x_=yu(["path","circle","polygon","polyline","ellipse","rect","line","image","text"]),S_=yu(["symbol","image","marker","pattern","view","svg"]),tb=yu(["symbol","g","a","svg","clipPath","defs"]),eb=new RegExp("^\\s*("+Qs+"+)\\s*,?\\s*("+Qs+"+)\\s*,?\\s*("+Qs+"+)\\s*,?\\s*("+Qs+"+)\\s*$"),C_=new O(1,0),sb=new O,$f=(o,t)=>o.rotate(t),vu=(o,t)=>new O(t).subtract(o),_u=o=>o.distanceFrom(sb),wu=(o,t)=>Math.atan2(go(o,t),nb(o,t)),ib=o=>wu(C_,o),xu=o=>o.eq(sb)?o:o.scalarDivide(_u(o)),qf=function(o){let t=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];return xu(new O(-o.y,o.x).scalarMultiply(t?1:-1))},go=(o,t)=>o.x*t.y-o.y*t.x,nb=(o,t)=>o.x*t.x+o.y*t.y,Kf=(o,t,e)=>{if(o.eq(t)||o.eq(e))return!0;const s=go(t,e),i=go(t,o),n=go(e,o);return s>=0?i>=0&&n<=0:!(i<=0&&n>=0)},rb="(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?",ab=new RegExp("(?:\\s|^)"+rb+rb+"("+Qs+"?(?:px)?)?(?:\\s?|$)(?:$|\\s)");class qi{constructor(t){const e=typeof t=="string"?qi.parseShadow(t):t;Object.assign(this,qi.ownDefaults,e),this.id=zn()}static parseShadow(t){const e=t.trim(),[,s=0,i=0,n=0]=(ab.exec(e)||[]).map(r=>parseFloat(r)||0);return{color:(e.replace(ab,"")||"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=$f(new O(this.offsetX,this.offsetY),Gt(-t.angle)),s=new wt(this.color);let i=40,n=40;return t.width&&t.height&&(i=100*Ft((Math.abs(e.x)+this.blur)/t.width,pt.NUM_FRACTION_DIGITS)+20,n=100*Ft((Math.abs(e.y)+this.blur)/t.height,pt.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(Ft(this.blur?this.blur/2:0,pt.NUM_FRACTION_DIGITS),`"></feGaussianBlur>
|
|
58
|
+
<feOffset dx="`).concat(Ft(e.x,pt.NUM_FRACTION_DIGITS),'" dy="').concat(Ft(e.y,pt.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=$i.ownDefaults;return this.includeDefaultValues?t:fg(t,(s,i)=>s!==e[i])}static async fromObject(t){return new this(t)}}E($i,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),E($i,"type","shadow"),W.setClass($i,"shadow");const Mr=(a,t,e)=>Math.max(a,Math.min(t,e)),t_=[Qe,vt,je,hs,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",$o,qo],qi=[Qt,Ne,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],e_={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:vt,originY:Qe,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:Qt,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},kg=(a,t,e,s)=>(a<Math.abs(t)?(a=t,s=e/4):s=t===0&&a===0?e/Yi*Math.asin(1):e/Yi*Math.asin(t/a),{a,c:t,p:e,s}),Bm=(a,t,e,s,i)=>a*Math.pow(2,10*(s-=1))*Math.sin((s*i-t)*Yi/e),Hm=(a,t,e,s)=>-e*Math.cos(a/s*jn)+e+t,Pg=(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,Vm=(a,t,e,s)=>e-Pg(s-a,0,e,s)+t;var s_=Object.freeze({__proto__:null,defaultEasing:Hm,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:Vm,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}=kg(i,e,n,1.70158);return-Bm(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*Vm(2*a,0,e,s)+t:.5*Pg(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}=kg(i,e,n,1.70158);return a<1?-.5*Bm(r,o,h,a,s)+t:r*Math.pow(2,-10*(a-=1))*Math.sin((a*s-o)*Yi/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*jn)+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:Pg,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}=kg(i,e,n,1.70158);return r*2**(-10*a)*Math.sin((a*s-o)*Yi/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*jn)+t});const i_=()=>!1;class Mg{constructor(t){let{startValue:e,byValue:s,duration:i=500,delay:n=0,easing:r=Hm,onStart:o=Cr,onChange:h=Cr,onComplete:c=Cr,abort:u=i_,target:d}=t;E(this,"_state","pending"),E(this,"durationProgress",0),E(this,"valueProgress",0),this.tick=this.tick.bind(this),this.duration=i,this.delay=n,this.easing=r,this._onStart=o,this._onChange=h,this._onComplete=c,this._abort=u,this.target=d,this.startValue=e,this.byValue=s,this.value=this.startValue,this.endValue=Object.freeze(this.calculate(this.duration).value)}get state(){return this._state}isDone(){return this._state==="aborted"||this._state==="completed"}start(){const t=e=>{this._state==="pending"&&(this.startTime=e||+new Date,this._state="running",this._onStart(),this.tick(this.startTime))};this.register(),this.delay>0?setTimeout(()=>Ph(t),this.delay):Ph(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),Ph(this.tick)))}register(){zc.push(this)}unregister(){zc.remove(this)}abort(){this._state="aborted",this.unregister()}}const n_=["startValue","endValue"];class r_ extends Mg{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(T(T({},Dt(t,n_)),{},{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 o_=["startValue","endValue"];class a_ extends Mg{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(T(T({},Dt(t,o_)),{},{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 h_=["startValue","endValue","easing","onChange","onComplete","abort"],l_=(a,t,e,s)=>t+e*(1-Math.cos(a/s*jn)),Og=a=>a&&((t,e,s)=>a(new _t(t).toRgba(),e,s));class c_ extends Mg{constructor(t){let{startValue:e,endValue:s,easing:i=l_,onChange:n,onComplete:r,abort:o}=t,h=Dt(t,h_);const c=new _t(e).getSource(),u=new _t(s).getSource();super(T(T({},h),{},{startValue:c,byValue:u.map((d,g)=>d-c[g]),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),Mr(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 Dg(a){const t=(e=>Array.isArray(e.startValue)||Array.isArray(e.endValue))(a)?new a_(a):new r_(a);return t.start(),t}function Gm(a){const t=new c_(a);return t.start(),t}class Nt{constructor(t){this.status=t,this.points=[]}includes(t){return this.points.some(e=>e.eq(t))}append(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];return this.points=this.points.concat(e.filter(i=>!this.includes(i))),this}static isPointContained(t,e,s){let i=arguments.length>3&&arguments[3]!==void 0&&arguments[3];if(e.eq(s))return t.eq(e);if(e.x===s.x)return t.x===e.x&&(i||t.y>=Math.min(e.y,s.y)&&t.y<=Math.max(e.y,s.y));if(e.y===s.y)return t.y===e.y&&(i||t.x>=Math.min(e.x,s.x)&&t.x<=Math.max(e.x,s.x));{const n=Zc(e,s),r=Zc(e,t).divide(n);return i?Math.abs(r.x)===Math.abs(r.y):r.x===r.y&&r.x>=0&&r.x<=1}}static isPointInPolygon(t,e){const s=new 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,g=t.y-s.y,f=c*g-u*d,p=o*g-h*d,m=u*o-c*h;if(m!==0){const w=f/m,b=p/m;return(n||0<=w&&w<=1)&&(r||0<=b&&b<=1)?new Nt("Intersection").append(new O(t.x+w*o,t.y+w*h)):new Nt}if(f===0||p===0){const w=n||r||Nt.isPointContained(t,s,i)||Nt.isPointContained(e,s,i)||Nt.isPointContained(s,t,e)||Nt.isPointContained(i,t,e);return new Nt(w?"Coincident":void 0)}return new Nt("Parallel")}static intersectSegmentLine(t,e,s,i){return Nt.intersectLineLine(t,e,s,i,!1,!0)}static intersectSegmentSegment(t,e,s,i){return Nt.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 Nt,r=s.length;for(let o,h,c,u=0;u<r;u++){if(o=s[u],h=s[(u+1)%r],c=Nt.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 Nt.intersectLinePolygon(t,e,s,!1)}static intersectPolygonPolygon(t,e){const s=new Nt,i=t.length,n=[];for(let r=0;r<i;r++){const o=t[r],h=t[(r+1)%i],c=Nt.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 Nt("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 Nt.intersectPolygonPolygon(t,[i,r,n,o])}}class u_ extends im{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?Se(t,this.group.calcTransformMatrix()):t}setXY(t,e,s){this.group&&(t=Se(t,Ze(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=>Se(o,r))}return n}intersectsWithRect(t,e){return Nt.intersectPolygonRectangle(this.getCoords(),t,e).status==="Intersection"}intersectsWithObject(t){const e=Nt.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 Nt.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 yi(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(je,t),this._set(hs,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?Hn(am(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.viewportTransform)||Fe.concat()}calcACoords(){const t=Qo({angle:this.angle}),{x:e,y:s}=this.getRelativeCenterPoint(),i=Jo(e,s),n=Yt(i,t),r=this._getTransformedDimensions(),o=r.x/2,h=r.y/2;return{tl:Se({x:-o,y:-h},n),tr:Se({x:o,y:-h},n),bl:Se({x:-o,y:h},n),br:Se({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,Zt(this.originX),Zt(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=Yt(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=lm(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=T({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,width:this.width,height:this.height,strokeWidth:this.strokeWidth},t),s=e.strokeWidth;let i=s,n=0;this.strokeUniform&&(i=0,n=s);const r=e.width+i,o=e.height+i;let h;return h=e.skewX===0&&e.skewY===0?new O(r*e.scaleX,o*e.scaleY):Kc(r,o,Mh(e)),h.scalarAdd(n)}translateToGivenOrigin(t,e,s,i,n){let r=t.x,o=t.y;const h=Zt(i)-Zt(e),c=Zt(n)-Zt(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===tt&&s===tt)return t;const i=this.translateToGivenOrigin(t,e,s,tt,tt);return this.angle?i.rotate(zt(this.angle),t):i}translateToOriginPoint(t,e,s){const i=this.translateToGivenOrigin(t,tt,tt,e,s);return this.angle?i.rotate(zt(this.angle),t):i}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?Se(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(),vt,Qe)}}const d_=["type"],g_=["extraParam"];let Ki=class kd extends u_{static getDefaults(){return kd.ownDefaults}get type(){const t=this.constructor.type;return t==="FabricObject"?"object":t.toLowerCase()}set type(t){Ui("warn","Setting type has no effect",t)}constructor(t){super(),E(this,"_cacheContext",null),Object.assign(this,kd.ownDefaults),this.setOptions(t)}_createCacheCanvas(){this._cacheCanvas=Cs(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,s=t.height,i=ft.maxCacheSideLimit,n=ft.minCacheSideLimit;if(e<=i&&s<=i&&e*s<=ft.perfLimitSizeTotal)return e<n&&(t.width=n),s<n&&(t.height=n),t;const r=e/s,[o,h]=Eh.limitDimsByArea(r),c=Mr(n,o,i),u=Mr(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,g=h/2;return this.cacheTranslationX=Math.round(t.width/2-d)+d,this.cacheTranslationY=Math.round(t.height/2-g)+g,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=Tr(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!==je&&t!==hs||(e=this._constrainScale(e)),t===je&&e<0?(this.flipX=!this.flipX,e*=-1):t==="scaleY"&&e<0?(this.flipY=!this.flipY,e*=-1):t!=="shadow"||!e||e instanceof $i||(e=new $i(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===Ne&&this.hasFill()&&this.hasStroke()&&this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.needsItsOwnCache()||this.objectCaching&&(!this.parent||!this.parent.isOnACache()),this.ownCaching}willDrawShadow(){return!!this.shadow&&(this.shadow.offsetX!==0||this.shadow.offsetY!==0)}drawClipPathOnCache(t,e,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=Us(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=Ze(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,As(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&&(As(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)||Fe,o=n*i,h=r*i,c=e.nonScaling?new O(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*ft.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(!As(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===Ne?(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=Us({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(W.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=yg(this),s=this.group,i=this.shadow,n=Math.abs,r=t.enableRetinaScaling?Qp():1,o=(t.multiplier||1)*r,h=t.canvasProvider||(x=>new Fh(x,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&Sm(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&_g(this,this.getViewportTransform()),this.setCoords();const c=Cs(),u=this.getBoundingRect(),d=this.shadow,g=new O;if(d){const x=d.blur,C=d.nonScaling?new O(1,1):this.getObjectScaling();g.x=2*Math.round(n(d.offsetX)+x)*n(C.x),g.y=2*Math.round(n(d.offsetY)+x)*n(C.y)}const f=u.width+g.x,p=u.height+g.y;c.width=Math.ceil(f),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),tt,tt);const w=this.canvas;m._objects=[this],this.set("canvas",m),this.setCoords();const b=m.toCanvasElement(o||1,t);return this.set("canvas",w),this.shadow=i,s&&(this.group=s),this.set(e),this.setCoords(),m._objects=[],m.destroy(),b}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return ug(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=tt,this.originY=tt,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(){zc.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&bi().dispose(this._cacheCanvas),this._cacheCanvas=void 0,this._cacheContext=null}animate(t,e){return Object.entries(t).reduce((s,i)=>{let[n,r]=i;return s[n]=this._animate(n,r,e),s},{})}_animate(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const i=t.split("."),n=this.constructor.colorProperties.includes(i[i.length-1]),{abort:r,startValue:o,onChange:h,onComplete:c}=s,u=T(T({},s),{},{target:this,startValue:o??i.reduce((d,g)=>d[g],this),endValue:e,abort:r==null?void 0:r.bind(this),onChange:(d,g,f)=>{i.reduce((p,m,w)=>(w===i.length-1&&(p[m]=d),p[m]),this),h&&h(d,g,f)},onComplete:(d,g,f)=>{this.setCoords(),c&&c(d,g,f)}});return n?Gm(u):Dg(u)}isDescendantOf(t){const{parent:e,group:s}=this;return e===t||s===t||!!e&&e.isDescendantOf(t)||!!s&&s!==e&&s.isDescendantOf(t)}getAncestors(){const t=[];let e=this;do e=e.parent,e&&t.push(e);while(e);return t}findCommonAncestors(t){if(this===t)return{fork:[],otherFork:[],common:[this,...this.getAncestors()]};const e=this.getAncestors(),s=t.getAncestors();if(e.length===0&&s.length>0&&this===s[s.length-1])return{fork:[],otherFork:[t,...s.slice(0,s.length-1)],common:[this]};for(let i,n=0;n<e.length;n++){if(i=e[n],i===t)return{fork:[this,...e.slice(0,n)],otherFork:[],common:e.slice(n)};for(let r=0;r<s.length;r++){if(this===s[r])return{fork:[],otherFork:[t,...s.slice(0,r)],common:[this,...e]};if(i===s[r])return{fork:[this,...e.slice(0,n)],otherFork:[t,...s.slice(0,r)],common:e.slice(n)}}}return{fork:[this,...e],otherFork:[t,...s],common:[]}}hasCommonAncestors(t){const e=this.findCommonAncestors(t);return e&&!!e.common.length}isInFrontOf(t){if(this===t)return;const e=this.findCommonAncestors(t);if(e.fork.includes(t))return!0;if(e.otherFork.includes(this))return!1;const s=e.common[0]||this.canvas;if(!s)return;const i=e.fork.pop(),n=e.otherFork.pop(),r=s._objects.indexOf(i),o=s._objects.indexOf(n);return r>-1&&r>o}toObject(){const t=(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).concat(kd.customProperties,this.constructor.customProperties||[]);let e;const s=ft.NUM_FRACTION_DIGITS,{clipPath:i,fill:n,stroke:r,shadow:o,strokeDashArray:h,left:c,top:u,originX:d,originY:g,width:f,height:p,strokeWidth:m,strokeLineCap:w,strokeDashOffset:b,strokeLineJoin:x,strokeUniform:C,strokeMiterLimit:A,scaleX:P,scaleY:D,angle:k,flipX:M,flipY:R,opacity:F,visible:I,backgroundColor:X,fillRule:j,paintFirst:N,globalCompositeOperation:nt,skewX:K,skewY:V}=this;i&&!i.excludeFromExport&&(e=i.toObject(t.concat("inverted","absolutePositioned")));const H=jt=>Rt(jt,s),Et=T(T({},Er(this,t)),{},{type:this.constructor.type,version:ig,originX:d,originY:g,left:H(c),top:H(u),width:H(f),height:H(p),fill:fm(n)?n.toObject():n,stroke:fm(r)?r.toObject():r,strokeWidth:H(m),strokeDashArray:h&&h.concat(),strokeLineCap:w,strokeDashOffset:b,strokeLineJoin:x,strokeUniform:C,strokeMiterLimit:H(A),scaleX:H(P),scaleY:H(D),angle:H(k),flipX:M,flipY:R,opacity:H(F),shadow:o&&o.toObject(),visible:I,backgroundColor:X,fillRule:j,paintFirst:N,globalCompositeOperation:nt,skewX:H(K),skewY:H(V)},e?{clipPath:e}:null);return this.includeDefaultValues?Et:this._removeDefaultValues(Et)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),s=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return fg(t,(i,n)=>{if(n===vt||n===Qe||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=Dt(t,d_),s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{extraParam:i}=s,n=Dt(s,g_);return Dh(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(Ki,"stateProperties",t_),E(Ki,"cacheProperties",qi),E(Ki,"ownDefaults",e_),E(Ki,"type","FabricObject"),E(Ki,"colorProperties",[Qt,Ne,"backgroundColor"]),E(Ki,"customProperties",[]),W.setClass(Ki),W.setClass(Ki,"object");const sa=(a,t,e)=>(s,i,n,r)=>{const o=t(s,i,n,r);return o&&Am(a,T(T({},km(s,i,n,r)),e)),o};function ia(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 Wm=sa(kh,ia((a,t,e,s)=>{const i=wg(t,t.originX,t.originY,e,s);if(Zt(t.originX)===Zt(tt)||Zt(t.originX)===Zt(Ut)&&i.x<0||Zt(t.originX)===Zt(vt)&&i.x>0){const{target:n}=t,r=n.strokeWidth/(n.strokeUniform?n.scaleX:1),o=Tm(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 f_(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?Ne:Qt,c=!o&&(s.cornerStrokeColor||i.cornerStrokeColor);let u,d=t,g=e;a.save(),a.fillStyle=s.cornerColor||i.cornerColor||"",a.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",n>r?(u=n,a.scale(1,r/n),g=e*n/r):r>n?(u=r,a.scale(n/r,1),d=t*r/n):u=n,a.beginPath(),a.arc(d,g,u/2,0,Yi,!1),a[h](),c&&a.stroke(),a.restore()}function p_(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?Ne:Qt,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 g=i.getTotalAngle();a.rotate(zt(g)),a["".concat(h,"Rect")](-u,-d,n,r),c&&a.strokeRect(-u,-d,n,r),a.restore()}class Ks{constructor(t){E(this,"visible",!0),E(this,"actionName",Gc),E(this,"angle",0),E(this,"x",0),E(this,"y",0),E(this,"offsetX",0),E(this,"offsetY",0),E(this,"sizeX",0),E(this,"sizeY",0),E(this,"touchSizeX",0),E(this,"touchSizeY",0),E(this,"cursorStyle","crosshair"),E(this,"withConnection",!1),Object.assign(this,t)}shouldActivate(t,e,s,i){var n;let{tl:r,tr:o,br:h,bl:c}=i;return((n=e.canvas)===null||n===void 0?void 0:n.getActiveObject())===e&&e.isControlVisible(t)&&Nt.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=Uc([Jo(s,i),Qo({angle:t}),Yc((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"?f_.call(this,t,e,s,i,n):p_.call(this,t,e,s,i,n)}}const m_=(a,t,e)=>e.lockRotation?Jc:t.cursorStyle,v_=sa(tm,ia((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($s(i,"lockRotation"))return!1;const d=Math.atan2(r-u.y,n-u.x),g=Math.atan2(s-u.y,e-u.x);let f=Hn(g-d+o);if(i.snapAngle&&i.snapAngle>0){const m=i.snapAngle,w=i.snapThreshold||m,b=Math.ceil(f/m)*m,x=Math.floor(f/m)*m;Math.abs(f-x)<w?f=x:Math.abs(f-b)<w&&(f=b)}f<0&&(f=360+f),f%=360;const p=i.angle!==f;return i.angle=f,p}));function zm(a,t){const e=t.canvas,s=a[e.uniScaleKey];return e.uniformScaling&&!s||!e.uniformScaling&&s}function Xm(a,t,e){const s=$s(a,"lockScalingX"),i=$s(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 b_=["e","se","s","sw","w","nw","n","ne","e"],jh=(a,t,e)=>{const s=zm(a,e);if(Xm(e,t.x!==0&&t.y===0?"x":t.x===0&&t.y!==0?"y":"",s))return Jc;const i=Pm(e,t);return"".concat(b_[i],"-resize")};function Rg(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{};const n=t.target,r=i.by,o=zm(a,n);let h,c,u,d,g,f;if(Xm(n,r,o))return!1;if(t.gestureScale)c=t.scaleX*t.gestureScale,u=t.scaleY*t.gestureScale;else{if(h=wg(t,t.originX,t.originY,e,s),g=r!=="y"?Math.sign(h.x||t.signX||1):1,f=r!=="x"?Math.sign(h.y||t.signY||1):1,t.signX||(t.signX=g),t.signY||(t.signY=f),$s(n,"lockScalingFlip")&&(t.signX!==g||t.signY!==f))return!1;if(d=n._getTransformedDimensions(),o&&!r){const w=Math.abs(h.x)+Math.abs(h.y),{original:b}=t,x=w/(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);Tm(t)&&(c*=2,u*=2),t.signX!==g&&r!=="y"&&(t.originX=Em(t.originX),c*=-1,t.signX=g),t.signY!==f&&r!=="x"&&(t.originY=Em(t.originY),u*=-1,t.signY=f)}const p=n.scaleX,m=n.scaleY;return r?(r==="x"&&n.set(je,c),r==="y"&&n.set(hs,u)):(!$s(n,"lockScalingX")&&n.set(je,c),!$s(n,"lockScalingY")&&n.set(hs,u)),p!==n.scaleX||m!==n.scaleY}const iu=sa(Hc,ia((a,t,e,s)=>Rg(a,t,e,s))),y_=sa(Hc,ia((a,t,e,s)=>Rg(a,t,e,s,{by:"x"}))),__=sa(Hc,ia((a,t,e,s)=>Rg(a,t,e,s,{by:"y"}))),w_=["target","ex","ey","skewingSide"],Lg={x:{counterAxis:"y",scale:je,skew:$o,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:hs,skew:qo,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},x_=["ns","nesw","ew","nwse"],S_=(a,t,e)=>{if(t.x!==0&&$s(e,"lockSkewingY")||t.y!==0&&$s(e,"lockSkewingX"))return Jc;const s=Pm(e,t)%4;return"".concat(x_[s],"-resize")};function Um(a,t,e,s,i){const{target:n}=e,{counterAxis:r,origin:o,lockSkewing:h,skew:c,flip:u}=Lg[a];if($s(n,h))return!1;const{origin:d,flip:g}=Lg[r],f=Zt(e[d])*(n[g]?-1:1),p=-Math.sign(f)*(n[u]?-1:1),m=.5*-((n[c]===0&&wg(e,tt,tt,s,i)[a]>0||n[c]>0?1:-1)*p)+.5;return sa(em,ia((b,x,C,A)=>function(P,D,k){let{target:M,ex:R,ey:F,skewingSide:I}=D,X=Dt(D,w_);const{skew:j}=Lg[P],N=k.subtract(new O(R,F)).divide(new O(M.scaleX,M.scaleY))[P],nt=M[j],K=X[j],V=Math.tan(zt(K)),H=P==="y"?M._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:M._getTransformedDimensions({scaleX:1,scaleY:1}).y,Et=2*N*I/Math.max(H,1)+V,jt=Hn(Math.atan(Et));M.set(j,jt);const ie=nt!==M[j];if(ie&&P==="y"){const{skewX:Wt,scaleX:Tt}=M,xe=M._getTransformedDimensions({skewY:nt}),Gs=M._getTransformedDimensions(),Ot=Wt!==0?xe.x/Gs.x:1;Ot!==1&&M.set(je,Ot*Tt)}return ie}(a,x,new O(C,A))))(t,T(T({},e),{},{[o]:m,skewingSide:p}),s,i)}const C_=(a,t,e,s)=>Um("x",a,t,e,s),A_=(a,t,e,s)=>Um("y",a,t,e,s);function nu(a,t){return a[t.canvas.altActionKey]}const ru=(a,t,e)=>{const s=nu(a,e);return t.x===0?s?$o:hs:t.y===0?s?qo:je:""},na=(a,t,e)=>nu(a,e)?S_(0,t,e):jh(a,t,e),Ym=(a,t,e,s)=>nu(a,t.target)?A_(a,t,e,s):y_(a,t,e,s),$m=(a,t,e,s)=>nu(a,t.target)?C_(a,t,e,s):__(a,t,e,s),qm=()=>({ml:new Ks({x:-.5,y:0,cursorStyleHandler:na,actionHandler:Ym,getActionName:ru}),mr:new Ks({x:.5,y:0,cursorStyleHandler:na,actionHandler:Ym,getActionName:ru}),mb:new Ks({x:0,y:.5,cursorStyleHandler:na,actionHandler:$m,getActionName:ru}),mt:new Ks({x:0,y:-.5,cursorStyleHandler:na,actionHandler:$m,getActionName:ru}),tl:new Ks({x:-.5,y:-.5,cursorStyleHandler:jh,actionHandler:iu}),tr:new Ks({x:.5,y:-.5,cursorStyleHandler:jh,actionHandler:iu}),bl:new Ks({x:-.5,y:.5,cursorStyleHandler:jh,actionHandler:iu}),br:new Ks({x:.5,y:.5,cursorStyleHandler:jh,actionHandler:iu}),mtr:new Ks({x:0,y:-.5,actionHandler:v_,cursorStyleHandler:m_,offsetY:-40,withConnection:!0,actionName:hg})}),T_=()=>({mr:new Ks({x:.5,y:0,actionHandler:Wm,cursorStyleHandler:na,actionName:kh}),ml:new Ks({x:-.5,y:0,actionHandler:Wm,cursorStyleHandler:na,actionName:kh})}),E_=()=>T(T({},qm()),T_());class Nh extends Ki{static getDefaults(){return T(T({},super.getDefaults()),Nh.ownDefaults)}constructor(t){super(),Object.assign(this,this.constructor.createControls(),Nh.ownDefaults),this.setOptions(t)}static createControls(){return{controls:qm()}}_updateCacheCanvas(){const t=this.canvas;if(this.noScaleCache&&t&&t._currentTransform){const e=t._currentTransform,s=e.target,i=e.action;if(this===s&&i&&i.startsWith(Gc))return!1}return super._updateCacheCanvas()}getActiveControl(){const t=this.__corner;return t?{key:t,control:this.controls[t],coord:this.oCoords[t]}:void 0}findControl(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];if(!this.hasControls||!this.canvas)return;this.__corner=void 0;const s=Object.entries(this.oCoords);for(let i=s.length-1;i>=0;i--){const[n,r]=s[i],o=this.controls[n];if(o.shouldActivate(n,this,t,e?r.touchCorner:r.corner))return this.__corner=n,{key:n,control:o,coord:this.oCoords[n]}}}calcOCoords(){const t=this.getViewportTransform(),e=this.getCenterPoint(),s=Jo(e.x,e.y),i=Qo({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),n=Yt(s,i),r=Yt(t,n),o=Yt(r,[1/t[0],0,0,1/t[3],0,0]),h=this.group?Tr(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,g)=>{const f=d.positionHandler(c,o,this,d);u[g]=Object.assign(f,this._calcCornerCoords(d,f))}),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(zt(this.angle)),t.fillStyle=this.selectionBackgroundColor,t.fillRect(-s.x/2,-s.y/2,s.x,s.y),t.restore()}strokeBorders(t,e){t.strokeRect(-e.x/2,-e.y/2,e.x,e.y)}_drawBorders(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const i=T({hasControls:this.hasControls,borderColor:this.borderColor,borderDashArray:this.borderDashArray},s);t.save(),t.strokeStyle=i.borderColor,this._setLineDash(t,i.borderDashArray),this.strokeBorders(t,e),i.hasControls&&this.drawControlsConnectingLines(t,e),t.restore()}_renderControls(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const{hasBorders:s,hasControls:i}=this,n=T({hasBorders:s,hasControls:i},e),r=this.getViewportTransform(),o=n.hasBorders,h=n.hasControls,c=Yt(r,this.calcTransformMatrix()),u=Tr(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(zt(this.group?u.angle:this.angle)),o&&this.drawBorders(t,u,e),h&&this.drawControls(t,e),t.restore()}drawBorders(t,e,s){let i;if(s&&s.forActiveSelection||this.group){const n=Kc(this.width,this.height,Mh(e)),r=this.isStrokeAccountedForInDimensions()?cg:(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=T({cornerStrokeColor:i,cornerDashArray:n,cornerColor:r},e);t.setTransform(s,0,0,s,0,0),t.strokeStyle=t.fillStyle=o.cornerColor,this.transparentCorners||(t.strokeStyle=o.cornerStrokeColor),this._setLineDash(t,o.cornerDashArray),this.forEachControl((h,c)=>{if(h.getVisibility(this,c)){const u=this.oCoords[c];h.render(t,u.x,u.y,o,this)}}),t.restore()}isControlVisible(t){return this.controls[t]&&this.controls[t].getVisibility(this,t)}setControlVisible(t,e){this._controlsVisibility||(this._controlsVisibility={}),this._controlsVisibility[t]=e}setControlsVisibility(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Object.entries(t).forEach(e=>{let[s,i]=e;return this.setControlVisible(s,i)})}clearContextTop(t){if(!this.canvas)return;const e=this.canvas.contextTop;if(!e)return;const s=this.canvas.viewportTransform;e.save(),e.transform(s[0],s[1],s[2],s[3],s[4],s[5]),this.transform(e);const i=this.width+4,n=this.height+4;return e.clearRect(-i/2,-n/2,i,n),t||e.restore(),e}onDeselect(t){return!1}onSelect(t){return!1}shouldStartDragging(t){return!1}onDragStart(t){return!1}canDrop(t){return!1}renderDragSourceEffect(t){}renderDropTargetEffect(t){}}function Km(a,t){return t.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(s=>{s!=="constructor"&&Object.defineProperty(a.prototype,s,Object.getOwnPropertyDescriptor(e.prototype,s)||Object.create(null))})}),a}E(Nh,"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 Ce extends Nh{}Km(Ce,[Mm]),W.setClass(Ce),W.setClass(Ce,"object");const Jm=(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 Qm{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=Zc(t,e);return this.options.strokeUniform?s.multiply(this.scale):s}projectOrthogonally(t,e,s){return this.applySkew(t.add(this.calcOrthogonalProjection(t,e,s)))}isSkewed(){return this.options.skewX!==0||this.options.skewY!==0}applySkew(t){const e=new O(t);return e.y+=e.x*Math.tan(zt(this.options.skewY)),e.x+=e.y*Math.tan(zt(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}const k_=new O;class ra extends Qm{static getOrthogonalRotationFactor(t,e){const s=e?eu(t,e):Fm(t);return Math.abs(s)<jn?-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 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=eu(this.AB,this.AC),this.bisector=su(Ag(this.AB.eq(k_)?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=Tg(i),r=ra.getOrthogonalRotationFactor(n,this.bisector);return this.scaleUnitVector(n,s*r)}projectBevel(){const t=[];return(this.alpha%Yi==0?[this.B]:[this.B,this.C]).forEach(e=>{t.push(this.projectOrthogonally(this.A,e)),t.push(this.projectOrthogonally(this.A,e,-this.strokeProjectionMagnitude))}),t}projectMiter(){const t=[],e=Math.abs(this.alpha),s=1/Math.sin(e/2),i=this.scaleUnitVector(this.bisector,-this.strokeProjectionMagnitude*s),n=this.options.strokeUniform?tu(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return tu(i)/this.strokeProjectionMagnitude<=n&&t.push(this.applySkew(this.A.add(i))),t.push(...this.projectBevel()),t}projectRoundNoSkew(t,e){const s=[],i=new O(ra.getOrthogonalRotationFactor(this.bisector),ra.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=>{Eg(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(zt(i)),Math.tan(zt(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),g=new O(Math.sqrt(Math.max(u**2-d**2,0)),d),f=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(f,Math.sqrt(Math.max(u**2-f**2,0)));return[p,p.scalarMultiply(-1),g,g.scalarMultiply(-1)].map(m=>this.applySkew(h?m.multiply(this.strokeUniformScalar):m)).forEach(m=>{Eg(m,t,e)&&s.push(this.applySkew(this.A).add(m))}),s}projectRound(){const t=[];t.push(...this.projectBevel());const e=this.alpha%Yi==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=ea(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 Zm extends Qm{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(Tg(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 ra(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(su(this.createSideVector(this.A,this.T)),-this.strokeProjectionMagnitude),i=this.A.add(s);t.push(i.add(e),i.subtract(e))}return t.map(e=>this.applySkew(e))}projectPoints(){switch(this.options.strokeLineCap){case"round":return this.projectRound();case"square":return this.projectSquare();default:return this.projectButt()}}project(){return this.projectPoints().map(t=>({originPoint:this.A,projectedPoint:t}))}}const t0=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 Zm(n,n,t).project()):!e||r!==0&&r!==o.length-1?s.push(...new ra(n,h,c,t).project()):s.push(...new Zm(n,r===0?c:h,t).project())}),s},Fg=a=>{const t={};return Object.keys(a).forEach(e=>{t[e]={},Object.keys(a[e]).forEach(s=>{t[e][s]=T({},a[e][s])})}),t},e0=a=>a.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">"),ou=a=>{const t=[];for(let e,s=0;s<a.length;s++)(e=P_(a,s))!==!1&&t.push(e);return t},P_=(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 M_=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:e0,graphemeSplit:ou});const au=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];return a.fill!==t.fill||a.stroke!==t.stroke||a.strokeWidth!==t.strokeWidth||a.fontSize!==t.fontSize||a.fontFamily!==t.fontFamily||a.fontWeight!==t.fontWeight||a.fontStyle!==t.fontStyle||a.textBackgroundColor!==t.textBackgroundColor||a.deltaY!==t.deltaY||e&&(a.overline!==t.overline||a.underline!==t.underline||a.linethrough!==t.linethrough)},s0=(a,t)=>{const e=t.split(`
|
|
67
|
-
`),s=[];let i=-1,n={};
|
|
68
|
-
`)]}static async fromElement(t,e,s){const i=Ji(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,width:o=0,height:h=0,visible:c=!0}=i,u=Dt(i,K_);return new this(T(T(T({},e),u),{},{left:n,top:r,width:o,height:h,visible:!!(c&&o&&h)}))}}E(_i,"type","Rect"),E(_i,"cacheProperties",[...qi,...d0]),E(_i,"ownDefaults",{rx:0,ry:0}),E(_i,"ATTRIBUTE_NAMES",[...Vn,"x","y","rx","ry","width","height"]),W.setClass(_i),W.setSVGClass(_i);const Qi="initialization",lu="added",Ng="removed",cu="imperative",g0=(a,t)=>{const{strokeUniform:e,strokeWidth:s,width:i,height:n,group:r}=t,o=r&&r!==a?Ih(r.calcTransformMatrix(),a.calcTransformMatrix()):null,h=o?t.getRelativeCenterPoint().transform(o):t.getRelativeCenterPoint(),c=!t.isStrokeAccountedForInDimensions(),u=e&&c?Cm(new O(s,s),void 0,a.calcTransformMatrix()):cg,d=!e&&c?s:0,g=Kc(i+d,n+d,Uc([o,t.calcOwnMatrix()],!0)).add(u).scalarDivide(2);return[h.subtract(g),h.add(g)]};class uu{calcLayoutResult(t,e){if(this.shouldPerformLayout(t))return this.calcBoundingBox(e,t)}shouldPerformLayout(t){let{type:e,prevStrategy:s,strategy:i}=t;return e===Qi||e===cu||!!s&&i!==s}shouldLayoutClipPath(t){let{type:e,target:{clipPath:s}}=t;return e!==Qi&&s&&!s.absolutePositioned}getInitialSize(t,e){return e.size}calcBoundingBox(t,e){const{type:s,target:i}=e;if(s===cu&&e.overrides)return e.overrides;if(t.length===0)return;const{left:n,top:r,width:o,height:h}=yi(t.map(d=>g0(i,d)).reduce((d,g)=>d.concat(g),[])),c=new O(o,h),u=new O(n,r).add(c.scalarDivide(2));if(s===Qi){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}}}E(uu,"type","strategy");class Bg extends uu{shouldPerformLayout(t){return!0}}E(Bg,"type","fit-content"),W.setClass(Bg);const J_=["strategy"],Q_=["target","strategy","bubbles","prevStrategy"],f0="layoutManager";class Bh{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:new Bg;E(this,"strategy",void 0),this.strategy=t,this._subscriptions=new Map}performLayout(t){const e=T(T({bubbles:!0,strategy:this.strategy},t),{},{prevStrategy:this._prevLayoutStrategy,stopPropagation(){this.bubbles=!1}});this.onBeforeLayout(e);const s=this.getLayoutResult(e);s&&this.commitLayout(e,s),this.onAfterLayout(e,s),this._prevLayoutStrategy=e.strategy}attachHandlers(t,e){const{target:s}=e;return[Wc,Zp,kh,tm,Hc,em,Vc,Hy,Vy].map(i=>t.on(i,n=>this.performLayout(i===Wc?{type:"object_modified",trigger:i,e:n,target:s}:{type:"object_modifying",trigger:i,e:n,target:s})))}subscribe(t,e){this.unsubscribe(t,e);const s=this.attachHandlers(t,e);this._subscriptions.set(t,s)}unsubscribe(t,e){(this._subscriptions.get(t)||[]).forEach(s=>s()),this._subscriptions.delete(t)}unsubscribeTargets(t){t.targets.forEach(e=>this.unsubscribe(e,t))}subscribeTargets(t){t.targets.forEach(e=>this.subscribe(e,t))}onBeforeLayout(t){const{target:e,type:s}=t,{canvas:i}=e;if(s===Qi||s===lu?this.subscribeTargets(t):s===Ng&&this.unsubscribeTargets(t),e.fire("layout:before",{context:t}),i&&i.fire("object:layout:before",{target:e,context:t}),s===cu&&t.deep){const n=Dt(t,J_);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===Qi?new O:e.getRelativeCenterPoint(),{center:o,correction:h=new O,relativeCorrection:c=new O}=n,u=r.subtract(o).add(h).transform(i===Qi?Fe:Ze(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===Qi?s.set({left:(r=t.x)!==null&&r!==void 0?r:n.x+i.x*Zt(s.originX),top:(o=t.y)!==null&&o!==void 0?o:n.y+i.y*Zt(s.originY)}):(s.setPositionByOrigin(n,tt,tt),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=Dt(t,Q_),{canvas:h}=s;s.fire("layout:after",{context:t,result:e}),h&&h.fire("object:layout:after",{context:t,result:e,target:s});const c=s.parent;n&&c!=null&&c.layoutManager&&((o.path||(o.path=[])).push(s),c.layoutManager.performLayout(T(T({},o),{},{target:c}))),s.set("dirty",!0)}dispose(){const{_subscriptions:t}=this;t.forEach(e=>e.forEach(s=>s())),t.clear()}toObject(){return{type:f0,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}W.setClass(Bh,f0);const Z_=["type","objects","layoutManager"];class tw extends Bh{performLayout(){}}class wi extends sm(Ce){static getDefaults(){return T(T({},super.getDefaults()),wi.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,wi.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 Bh,this.layoutManager.performLayout({type:Qi,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(Ui("error","Group: circular object trees are not supported, this call has no effect"),!1):this._objects.indexOf(t)===-1||(Ui("error","Group: duplicate objects are not supported inside group, this call has no effect"),!1)}_filterObjectsBeforeEnteringGroup(t){return t.filter((e,s,i)=>this.canEnterGroup(e)&&i.indexOf(e)===s)}add(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];const i=this._filterObjectsBeforeEnteringGroup(e),n=super.add(...i);return this._onAfterObjectsChange(lu,i),n}insertAt(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),i=1;i<e;i++)s[i-1]=arguments[i];const n=this._filterObjectsBeforeEnteringGroup(s),r=super.insertAt(t,...n);return this._onAfterObjectsChange(lu,n),r}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange(Ng,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&&ta(t,Yt(Ze(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||(ta(t,Yt(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=Ce.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(...Ze(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:cu},t))}render(t){this._transformDone=!0,super.render(t),this._transformDone=!1}__serializeObjects(t,e){const s=this.includeDefaultValues;return this._objects.filter(function(i){return!i.excludeFromExport}).map(function(i){const n=i.includeDefaultValues;i.includeDefaultValues=s;const r=i[t||"toObject"](e);return i.includeDefaultValues=n,r})}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=this.layoutManager.toObject();return 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=_i.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:jf(t,(s,i)=>s!==e[i])}static async fromObject(t){return new this(t)}}E(qi,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),E(qi,"type","shadow"),V.setClass(qi,"shadow");const jr=(o,t,e)=>Math.max(o,Math.min(t,e)),A_=[es,vt,He,us,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",ao,oo],Ki=[Zt,Ve,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],T_={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:vt,originY:es,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:Zt,fill:"rgb(0,0,0)",fillRule:"nonzero",stroke:null,strokeDashArray:null,strokeDashOffset:0,strokeLineCap:"butt",strokeLineJoin:"miter",strokeMiterLimit:4,globalCompositeOperation:"source-over",backgroundColor:"",shadow:null,visible:!0,includeDefaultValues:!0,excludeFromExport:!1,objectCaching:!0,clipPath:void 0,inverted:!1,absolutePositioned:!1,centeredRotation:!0,centeredScaling:!1,dirty:!0},Jf=(o,t,e,s)=>(o<Math.abs(t)?(o=t,s=e/4):s=t===0&&o===0?e/$i*Math.asin(1):e/$i*Math.asin(t/o),{a:o,c:t,p:e,s}),ob=(o,t,e,s,i)=>o*Math.pow(2,10*(s-=1))*Math.sin((s*i-t)*$i/e),hb=(o,t,e,s)=>-e*Math.cos(o/s*Vn)+e+t,Qf=(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,lb=(o,t,e,s)=>e-Qf(s-o,0,e,s)+t;var E_=Object.freeze({__proto__:null,defaultEasing:hb,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:lb,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}=Jf(i,e,n,1.70158);return-ob(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*lb(2*o,0,e,s)+t:.5*Qf(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}=Jf(i,e,n,1.70158);return o<1?-.5*ob(r,a,h,o,s)+t:r*Math.pow(2,-10*(o-=1))*Math.sin((o*s-a)*$i/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:Qf,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}=Jf(i,e,n,1.70158);return r*2**(-10*o)*Math.sin((o*s-a)*$i/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 k_=()=>!1;class Zf{constructor(t){let{startValue:e,byValue:s,duration:i=500,delay:n=0,easing:r=hb,onStart:a=Or,onChange:h=Or,onComplete:c=Or,abort:u=k_,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(()=>zh(t),this.delay):zh(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),zh(this.tick)))}register(){cu.push(this)}unregister(){cu.remove(this)}abort(){this._state="aborted",this.unregister()}}const P_=["startValue","endValue"];class M_ extends Zf{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(T(T({},Lt(t,P_)),{},{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 O_=["startValue","endValue"];class D_ extends Zf{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(T(T({},Lt(t,O_)),{},{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 R_=["startValue","endValue","easing","onChange","onComplete","abort"],L_=(o,t,e,s)=>t+e*(1-Math.cos(o/s*Vn)),tg=o=>o&&((t,e,s)=>o(new wt(t).toRgba(),e,s));class F_ extends Zf{constructor(t){let{startValue:e,endValue:s,easing:i=L_,onChange:n,onComplete:r,abort:a}=t,h=Lt(t,R_);const c=new wt(e).getSource(),u=new wt(s).getSource();super(T(T({},h),{},{startValue:c,byValue:u.map((d,f)=>d-c[f]),easing:i,onChange:tg(n),onComplete:tg(r),abort:tg(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),jr(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 eg(o){const t=(e=>Array.isArray(e.startValue)||Array.isArray(e.endValue))(o)?new D_(o):new M_(o);return t.start(),t}function cb(o){const t=new F_(o);return t.start(),t}class Bt{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=vu(e,s),r=vu(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 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,b=u*a-c*h;if(b!==0){const _=g/b,y=p/b;return(n||0<=_&&_<=1)&&(r||0<=y&&y<=1)?new Bt("Intersection").append(new O(t.x+_*a,t.y+_*h)):new Bt}if(g===0||p===0){const _=n||r||Bt.isPointContained(t,s,i)||Bt.isPointContained(e,s,i)||Bt.isPointContained(s,t,e)||Bt.isPointContained(i,t,e);return new Bt(_?"Coincident":void 0)}return new Bt("Parallel")}static intersectSegmentLine(t,e,s,i){return Bt.intersectLineLine(t,e,s,i,!1,!0)}static intersectSegmentSegment(t,e,s,i){return Bt.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 Bt,r=s.length;for(let a,h,c,u=0;u<r;u++){if(a=s[u],h=s[(u+1)%r],c=Bt.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 Bt.intersectLinePolygon(t,e,s,!1)}static intersectPolygonPolygon(t,e){const s=new Bt,i=t.length,n=[];for(let r=0;r<i;r++){const a=t[r],h=t[(r+1)%i],c=Bt.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 Bt("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),a=new O(i.x,n.y);return Bt.intersectPolygonPolygon(t,[i,r,n,a])}}class I_ extends Am{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?Ae(t,this.group.calcTransformMatrix()):t}setXY(t,e,s){this.group&&(t=Ae(t,ss(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(a=>Ae(a,r))}return n}intersectsWithRect(t,e){return Bt.intersectPolygonRectangle(this.getCoords(),t,e).status==="Intersection"}intersectsWithObject(t){const e=Bt.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 Bt.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 wi(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(He,t),this._set(us,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?Gn(Pm(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.viewportTransform)||Ne.concat()}calcACoords(){const t=co({angle:this.angle}),{x:e,y:s}=this.getRelativeCenterPoint(),i=lo(e,s),n=$t(i,t),r=this._getTransformedDimensions(),a=r.x/2,h=r.y/2;return{tl:Ae({x:-a,y:-h},n),tr:Ae({x:a,y:-h},n),bl:Ae({x:-a,y:h},n),br:Ae({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,te(this.originX),te(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=$t(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=Om(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=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 O(r*e.scaleX,a*e.scaleY):mu(r,a,Gh(e)),h.scalarAdd(n)}translateToGivenOrigin(t,e,s,i,n){let r=t.x,a=t.y;const h=te(i)-te(e),c=te(n)-te(s);if(h||c){const u=this._getTransformedDimensions();r+=h*u.x,a+=c*u.y}return new O(r,a)}translateToCenterPoint(t,e,s){if(e===et&&s===et)return t;const i=this.translateToGivenOrigin(t,e,s,et,et);return this.angle?i.rotate(Gt(this.angle),t):i}translateToOriginPoint(t,e,s){const i=this.translateToGivenOrigin(t,et,et,e,s);return this.angle?i.rotate(Gt(this.angle),t):i}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?Ae(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(),vt,es)}}const j_=["type"],N_=["extraParam"];let Ji=class $d extends I_{static getDefaults(){return $d.ownDefaults}get type(){const t=this.constructor.type;return t==="FabricObject"?"object":t.toLowerCase()}set type(t){Yi("warn","Setting type has no effect",t)}constructor(t){super(),E(this,"_cacheContext",null),Object.assign(this,$d.ownDefaults),this.setOptions(t)}_createCacheCanvas(){this._cacheCanvas=Ms(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,s=t.height,i=pt.maxCacheSideLimit,n=pt.minCacheSideLimit;if(e<=i&&s<=i&&e*s<=pt.perfLimitSizeTotal)return e<n&&(t.width=n),s<n&&(t.height=n),t;const r=e/s,[a,h]=Vh.limitDimsByArea(r),c=jr(n,a,i),u=jr(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 O(Math.abs(this.scaleX),Math.abs(this.scaleY));const t=Rr(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!==He&&t!==us||(e=this._constrainScale(e)),t===He&&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: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===Ve&&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=qs(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=ss(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,Os(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&&(Os(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)||Ne,a=n*i,h=r*i,c=e.nonScaling?new O(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*pt.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(!Os(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===Ve?(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=qs({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 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(V.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?_m():1,a=(t.multiplier||1)*r,h=t.canvasProvider||(x=>new qh(x,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&Xm(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&zf(this,this.getViewportTransform()),this.setCoords();const c=Ms(),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 b=h(c);t.format==="jpeg"&&(b.backgroundColor="#fff"),this.setPositionByOrigin(new O(b.width/2,b.height/2),et,et);const _=this.canvas;b._objects=[this],this.set("canvas",b),this.setCoords();const y=b.toCanvasElement(a||1,t);return this.set("canvas",_),this.shadow=i,s&&(this.group=s),this.set(e),this.setCoords(),b._objects=[],b.destroy(),y}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return Lf(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=et,this.originY=et,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(){cu.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&_i().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,b,_)=>(_===i.length-1&&(p[b]=d),p[b]),this),h&&h(d,f,g)},onComplete:(d,f,g)=>{this.setCoords(),c&&c(d,f,g)}});return n?cb(u):eg(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($d.customProperties,this.constructor.customProperties||[]);let e;const s=pt.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:b,strokeLineCap:_,strokeDashOffset:y,strokeLineJoin:x,strokeUniform:C,strokeMiterLimit:A,scaleX:P,scaleY:D,angle:k,flipX:M,flipY:R,opacity:F,visible:I,backgroundColor:Y,fillRule:N,paintFirst:H,globalCompositeOperation:at,skewX:j,skewY:z}=this;i&&!i.excludeFromExport&&(e=i.toObject(t.concat("inverted","absolutePositioned")));const it=Ut=>Ft(Ut,s),kt=T(T({},Lr(this,t)),{},{type:this.constructor.type,version:Tf,originX:d,originY:f,left:it(c),top:it(u),width:it(g),height:it(p),fill:Im(n)?n.toObject():n,stroke:Im(r)?r.toObject():r,strokeWidth:it(b),strokeDashArray:h&&h.concat(),strokeLineCap:_,strokeDashOffset:y,strokeLineJoin:x,strokeUniform:C,strokeMiterLimit:it(A),scaleX:it(P),scaleY:it(D),angle:it(k),flipX:M,flipY:R,opacity:it(F),shadow:a&&a.toObject(),visible:I,backgroundColor:Y,fillRule:N,paintFirst:H,globalCompositeOperation:at,skewX:it(j),skewY:it(z)},e?{clipPath:e}:null);return this.includeDefaultValues?kt:this._removeDefaultValues(kt)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),s=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return jf(t,(i,n)=>{if(n===vt||n===es||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,N_);return Uh(e,n).then(r=>i?(delete r[i],new this(e[i],r)):new this(r))}static fromObject(t,e){return this._fromObject(t,e)}};E(Ji,"stateProperties",A_),E(Ji,"cacheProperties",Ki),E(Ji,"ownDefaults",T_),E(Ji,"type","FabricObject"),E(Ji,"colorProperties",[Zt,Ve,"backgroundColor"]),E(Ji,"customProperties",[]),V.setClass(Ji),V.setClass(Ji,"object");const po=(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 mo(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 ub=po(Wh,mo((o,t,e,s)=>{const i=Gf(t,t.originX,t.originY,e,s);if(te(t.originX)===te(et)||te(t.originX)===te(Yt)&&i.x<0||te(t.originX)===te(vt)&&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 B_(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?Ve:Zt,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,$i,!1),o[h](),c&&o.stroke(),o.restore()}function H_(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?Ve:Zt,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(Gt(f)),o["".concat(h,"Rect")](-u,-d,n,r),c&&o.strokeRect(-u,-d,n,r),o.restore()}class Zs{constructor(t){E(this,"visible",!0),E(this,"actionName",hu),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)&&Bt.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 O(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(e)}calcCornerCoords(t,e,s,i,n,r){const a=du([lo(s,i),co({angle:t}),fu((n?this.touchSizeX:this.sizeX)||e,(n?this.touchSizeY:this.sizeY)||e)]);return{tl:new O(-.5,-.5).transform(a),tr:new O(.5,-.5).transform(a),br:new O(.5,.5).transform(a),bl:new O(-.5,.5).transform(a)}}render(t,e,s,i,n){((i=i||{}).cornerStyle||n.cornerStyle)==="circle"?B_.call(this,t,e,s,i,n):H_.call(this,t,e,s,i,n)}}const V_=(o,t,e)=>e.lockRotation?bu:t.cursorStyle,W_=po(xm,mo((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(Js(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=Gn(f-d+a);if(i.snapAngle&&i.snapAngle>0){const b=i.snapAngle,_=i.snapThreshold||b,y=Math.ceil(g/b)*b,x=Math.floor(g/b)*b;Math.abs(g-x)<_?g=x:Math.abs(g-y)<_&&(g=y)}g<0&&(g=360+g),g%=360;const p=i.angle!==g;return i.angle=g,p}));function db(o,t){const e=t.canvas,s=o[e.uniScaleKey];return e.uniformScaling&&!s||!e.uniformScaling&&s}function fb(o,t,e){const s=Js(o,"lockScalingX"),i=Js(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 z_=["e","se","s","sw","w","nw","n","ne","e"],Jh=(o,t,e)=>{const s=db(o,e);if(fb(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(z_[i],"-resize")};function sg(o,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{};const n=t.target,r=i.by,a=db(o,n);let h,c,u,d,f,g;if(fb(n,r,a))return!1;if(t.gestureScale)c=t.scaleX*t.gestureScale,u=t.scaleY*t.gestureScale;else{if(h=Gf(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),Js(n,"lockScalingFlip")&&(t.signX!==f||t.signY!==g))return!1;if(d=n._getTransformedDimensions(),a&&!r){const _=Math.abs(h.x)+Math.abs(h.y),{original:y}=t,x=_/(Math.abs(d.x*y.scaleX/n.scaleX)+Math.abs(d.y*y.scaleY/n.scaleY));c=y.scaleX*x,u=y.scaleY*x}else c=Math.abs(h.x*n.scaleX/d.x),u=Math.abs(h.y*n.scaleY/d.y);$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,b=n.scaleY;return r?(r==="x"&&n.set(He,c),r==="y"&&n.set(us,u)):(!Js(n,"lockScalingX")&&n.set(He,c),!Js(n,"lockScalingY")&&n.set(us,u)),p!==n.scaleX||b!==n.scaleY}const Su=po(au,mo((o,t,e,s)=>sg(o,t,e,s))),G_=po(au,mo((o,t,e,s)=>sg(o,t,e,s,{by:"x"}))),X_=po(au,mo((o,t,e,s)=>sg(o,t,e,s,{by:"y"}))),U_=["target","ex","ey","skewingSide"],ig={x:{counterAxis:"y",scale:He,skew:ao,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:us,skew:oo,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},Y_=["ns","nesw","ew","nwse"],$_=(o,t,e)=>{if(t.x!==0&&Js(e,"lockSkewingY")||t.y!==0&&Js(e,"lockSkewingX"))return bu;const s=Jm(e,t)%4;return"".concat(Y_[s],"-resize")};function gb(o,t,e,s,i){const{target:n}=e,{counterAxis:r,origin:a,lockSkewing:h,skew:c,flip:u}=ig[o];if(Js(n,h))return!1;const{origin:d,flip:f}=ig[r],g=te(e[d])*(n[f]?-1:1),p=-Math.sign(g)*(n[u]?-1:1),b=.5*-((n[c]===0&&Gf(e,et,et,s,i)[o]>0||n[c]>0?1:-1)*p)+.5;return po(Sm,mo((y,x,C,A)=>function(P,D,k){let{target:M,ex:R,ey:F,skewingSide:I}=D,Y=Lt(D,U_);const{skew:N}=ig[P],H=k.subtract(new O(R,F)).divide(new O(M.scaleX,M.scaleY))[P],at=M[N],j=Y[N],z=Math.tan(Gt(j)),it=P==="y"?M._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:M._getTransformedDimensions({scaleX:1,scaleY:1}).y,kt=2*H*I/Math.max(it,1)+z,Ut=Gn(Math.atan(kt));M.set(N,Ut);const ne=at!==M[N];if(ne&&P==="y"){const{skewX:zt,scaleX:Tt}=M,Ce=M._getTransformedDimensions({skewY:at}),Xs=M._getTransformedDimensions(),Dt=zt!==0?Ce.x/Xs.x:1;Dt!==1&&M.set(He,Dt*Tt)}return ne}(o,x,new O(C,A))))(t,T(T({},e),{},{[a]:b,skewingSide:p}),s,i)}const q_=(o,t,e,s)=>gb("x",o,t,e,s),K_=(o,t,e,s)=>gb("y",o,t,e,s);function Cu(o,t){return o[t.canvas.altActionKey]}const Au=(o,t,e)=>{const s=Cu(o,e);return t.x===0?s?ao:us:t.y===0?s?oo:He:""},bo=(o,t,e)=>Cu(o,e)?$_(0,t,e):Jh(o,t,e),pb=(o,t,e,s)=>Cu(o,t.target)?K_(o,t,e,s):G_(o,t,e,s),mb=(o,t,e,s)=>Cu(o,t.target)?q_(o,t,e,s):X_(o,t,e,s),bb=()=>({ml:new Zs({x:-.5,y:0,cursorStyleHandler:bo,actionHandler:pb,getActionName:Au}),mr:new Zs({x:.5,y:0,cursorStyleHandler:bo,actionHandler:pb,getActionName:Au}),mb:new Zs({x:0,y:.5,cursorStyleHandler:bo,actionHandler:mb,getActionName:Au}),mt:new Zs({x:0,y:-.5,cursorStyleHandler:bo,actionHandler:mb,getActionName:Au}),tl:new Zs({x:-.5,y:-.5,cursorStyleHandler:Jh,actionHandler:Su}),tr:new Zs({x:.5,y:-.5,cursorStyleHandler:Jh,actionHandler:Su}),bl:new Zs({x:-.5,y:.5,cursorStyleHandler:Jh,actionHandler:Su}),br:new Zs({x:.5,y:.5,cursorStyleHandler:Jh,actionHandler:Su}),mtr:new Zs({x:0,y:-.5,actionHandler:W_,cursorStyleHandler:V_,offsetY:-40,withConnection:!0,actionName:Of})}),J_=()=>({mr:new Zs({x:.5,y:0,actionHandler:ub,cursorStyleHandler:bo,actionName:Wh}),ml:new Zs({x:-.5,y:0,actionHandler:ub,cursorStyleHandler:bo,actionName:Wh})}),Q_=()=>T(T({},bb()),J_());class Qh extends Ji{static getDefaults(){return T(T({},super.getDefaults()),Qh.ownDefaults)}constructor(t){super(),Object.assign(this,this.constructor.createControls(),Qh.ownDefaults),this.setOptions(t)}static createControls(){return{controls:bb()}}_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(hu))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=lo(e.x,e.y),i=co({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),n=$t(s,i),r=$t(t,n),a=$t(r,[1/t[0],0,0,1/t[3],0,0]),h=this.group?Rr(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(Gt(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=$t(r,this.calcTransformMatrix()),u=Rr(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(Gt(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=mu(this.width,this.height,Gh(e)),r=this.isStrokeAccountedForInDimensions()?Rf:(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,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 yb(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(Qh,"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 Te extends Qh{}yb(Te,[Qm]),V.setClass(Te),V.setClass(Te,"object");const vb=(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 _b{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=vu(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(Gt(this.options.skewY)),e.x+=e.y*Math.tan(Gt(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}const Z_=new O;class yo extends _b{static getOrthogonalRotationFactor(t,e){const s=e?wu(t,e):ib(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 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=wu(this.AB,this.AC),this.bisector=xu($f(this.AB.eq(Z_)?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=yo.getOrthogonalRotationFactor(n,this.bisector);return this.scaleUnitVector(n,s*r)}projectBevel(){const t=[];return(this.alpha%$i==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?_u(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return _u(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(yo.getOrthogonalRotationFactor(this.bisector),yo.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=>{Kf(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 O(Math.tan(Gt(i)),Math.tan(Gt(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 O(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 O(g,Math.sqrt(Math.max(u**2-g**2,0)));return[p,p.scalarMultiply(-1),f,f.scalarMultiply(-1)].map(b=>this.applySkew(h?b.multiply(this.strokeUniformScalar):b)).forEach(b=>{Kf(b,t,e)&&s.push(this.applySkew(this.A).add(b))}),s}projectRound(){const t=[];t.push(...this.projectBevel());const e=this.alpha%$i==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=go(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 wb extends _b{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(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 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 yo(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(xu(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 xb=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 O(r)),n),[new O(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 wb(n,n,t).project()):!e||r!==0&&r!==a.length-1?s.push(...new yo(n,h,c,t).project()):s.push(...new wb(n,r===0?c:h,t).project())}),s},ng=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},Sb=o=>o.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">"),Tu=o=>{const t=[];for(let e,s=0;s<o.length;s++)(e=tw(o,s))!==!1&&t.push(e);return t},tw=(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 ew=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:Sb,graphemeSplit:Tu});const Eu=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)},Cb=(o,t)=>{const e=t.split(`
|
|
67
|
+
`),s=[];let i=-1,n={};o=ng(o);for(let r=0;r<e.length;r++){const a=Tu(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&&(Eu(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},Ab=(o,t)=>{if(!Array.isArray(o))return ng(o);const e=t.split(Mf),s={};let i=-1,n=0;for(let r=0;r<e.length;r++){const a=Tu(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",Zt,"fill-opacity","fill-rule","opacity",Ve,"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 Tb(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 sw(o,t){let e=!0;const s=Tb(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=Tb(i=i.parentElement,r);return n.length===0}(o,t)),s&&e&&t.length===0}const iw=o=>{var t;return(t=w_[o])!==null&&t!==void 0?t:o},nw=new RegExp("(".concat(Qs,")"),"gi"),rw=o=>o.replace(nw," $1 ").replace(/,/gi," ").replace(/\s+/gi," ");var Eb,kb,Pb,Mb,Ob,Db,Rb;const ze="(".concat(Qs,")"),aw=String.raw(Eb||(Eb=Hn(["(skewX)(",")"],["(skewX)\\(","\\)"])),ze),ow=String.raw(kb||(kb=Hn(["(skewY)(",")"],["(skewY)\\(","\\)"])),ze),hw=String.raw(Pb||(Pb=Hn(["(rotate)(","(?: "," ",")?)"],["(rotate)\\(","(?: "," ",")?\\)"])),ze,ze,ze),lw=String.raw(Mb||(Mb=Hn(["(scale)(","(?: ",")?)"],["(scale)\\(","(?: ",")?\\)"])),ze,ze),cw=String.raw(Ob||(Ob=Hn(["(translate)(","(?: ",")?)"],["(translate)\\(","(?: ",")?\\)"])),ze,ze),uw=String.raw(Db||(Db=Hn(["(matrix)("," "," "," "," "," ",")"],["(matrix)\\("," "," "," "," "," ","\\)"])),ze,ze,ze,ze,ze,ze),rg="(?:".concat(uw,"|").concat(cw,"|").concat(hw,"|").concat(lw,"|").concat(aw,"|").concat(ow,")"),dw="(?:".concat(rg,"*)"),fw=String.raw(Rb||(Rb=Hn(["^s*(?:","?)s*$"],["^\\s*(?:","?)\\s*$"])),dw),gw=new RegExp(fw),pw=new RegExp(rg),mw=new RegExp(rg,"g");function ku(o){const t=[];if(!(o=rw(o).replace(/\s*([()])\s*/gi,"$1"))||o&&!gw.test(o))return[...Ne];for(const e of o.matchAll(mw)){const s=pw.exec(e[0]);if(!s)continue;let i=Ne;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=lo(h,c);break;case Of:i=co({angle:h},{x:c,y:u});break;case hu:i=fu(h,c);break;case ao:i=Ff(h);break;case oo:i=If(h);break;case"matrix":i=[h,c,u,d,f,g]}t.push(i)}return du(t)}function bw(o,t,e,s){const i=Array.isArray(t);let n,r=t;if(o!==Zt&&o!==Ve||t!==Be){if(o==="strokeUniform")return t==="non-scaling-stroke";if(o==="strokeDashArray")r=t===Be?null:t.replace(/,/g," ").split(/\s+/).map(parseFloat);else if(o==="transformMatrix")r=e&&e.transformMatrix?$t(e.transformMatrix,ku(t)):ku(t);else if(o==="visible")r=t!==Be&&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"?vt:t==="end"?Yt:et;else if(o==="charSpacing")n=We(t,s)/s*1e3;else if(o==="paintFirst"){const a=t.indexOf(Zt),h=t.indexOf(Ve);r=Zt,(a>-1&&h>-1&&h<a||a===-1&&h>-1)&&(r=Ve)}else{if(o==="href"||o==="xlink:href"||o==="font"||o==="id")return t;if(o==="imageSmoothing")return t==="optimizeQuality";n=i?t.map(We):We(t,s)}}else r="";return!i&&isNaN(n)?r:n}function yw(o,t){const e=o.match(__);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=We(n)),a&&(t.fontFamily=a),r&&(t.lineHeight=r==="normal"?1:r)}function ag(o,t){o.replace(/;\s*$/,"").split(";").forEach(e=>{if(!e)return;const[s,i]=e.split(":");t[s.trim().toLowerCase()]=i.trim()})}function vw(o){const t={},e=o.getAttribute("style");return e&&(typeof e=="string"?ag(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 _w={stroke:"strokeOpacity",fill:"fillOpacity"};function Qi(o,t,e){if(!o)return{};let s,i={},n=kf;o.parentNode&&tb.test(o.parentNode.nodeName)&&(i=Qi(o.parentElement,t,e),i.fontSize&&(s=n=We(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)sw(c,f.split(" "))&&(d=T(T({},d),u[f]));return d}(o,e)),vw(o));r[Yf]&&o.setAttribute(Yf,r[Yf]),r[Uf]&&(s=We(r[Uf],n),r[Uf]="".concat(s));const a={};for(const c in r){const u=iw(c),d=bw(u,r[c],i,s);a[u]=d}a.font&&yw(a.font,a);const h=T(T({},i),a);return tb.test(o.nodeName)?h:function(c){const u=Te.getDefaults();return Object.entries(_w).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 wt(c[f]);c[f]=p.setAlpha(Ft(p.getAlpha()*c[g],2)).toRgba()}),c}(h)}const ww=["left","top","width","height","visible"],Lb=["rx","ry"];class xi extends Te{static getDefaults(){return T(T({},super.getDefaults()),xi.ownDefaults)}constructor(t){super(),Object.assign(this,xi.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([...Lb,...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=Qi(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,width:a=0,height:h=0,visible:c=!0}=i,u=Lt(i,ww);return new this(T(T(T({},e),u),{},{left:n,top:r,width:a,height:h,visible:!!(c&&a&&h)}))}}E(xi,"type","Rect"),E(xi,"cacheProperties",[...Ki,...Lb]),E(xi,"ownDefaults",{rx:0,ry:0}),E(xi,"ATTRIBUTE_NAMES",[...Xn,"x","y","rx","ry","width","height"]),V.setClass(xi),V.setSVGClass(xi);const Zi="initialization",Pu="added",og="removed",Mu="imperative",Fb=(o,t)=>{const{strokeUniform:e,strokeWidth:s,width:i,height:n,group:r}=t,a=r&&r!==o?Kh(r.calcTransformMatrix(),o.calcTransformMatrix()):null,h=a?t.getRelativeCenterPoint().transform(a):t.getRelativeCenterPoint(),c=!t.isStrokeAccountedForInDimensions(),u=e&&c?Um(new O(s,s),void 0,o.calcTransformMatrix()):Rf,d=!e&&c?s:0,f=mu(i+d,n+d,du([a,t.calcOwnMatrix()],!0)).add(u).scalarDivide(2);return[h.subtract(f),h.add(f)]};class Ou{calcLayoutResult(t,e){if(this.shouldPerformLayout(t))return this.calcBoundingBox(e,t)}shouldPerformLayout(t){let{type:e,prevStrategy:s,strategy:i}=t;return e===Zi||e===Mu||!!s&&i!==s}shouldLayoutClipPath(t){let{type:e,target:{clipPath:s}}=t;return e!==Zi&&s&&!s.absolutePositioned}getInitialSize(t,e){return e.size}calcBoundingBox(t,e){const{type:s,target:i}=e;if(s===Mu&&e.overrides)return e.overrides;if(t.length===0)return;const{left:n,top:r,width:a,height:h}=wi(t.map(d=>Fb(i,d)).reduce((d,f)=>d.concat(f),[])),c=new O(a,h),u=new O(n,r).add(c.scalarDivide(2));if(s===Zi){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}}}E(Ou,"type","strategy");class hg extends Ou{shouldPerformLayout(t){return!0}}E(hg,"type","fit-content"),V.setClass(hg);const xw=["strategy"],Sw=["target","strategy","bubbles","prevStrategy"],Ib="layoutManager";class Zh{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:new hg;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[lu,wm,Wh,xm,au,Sm,ou,u_,d_].map(i=>t.on(i,n=>this.performLayout(i===lu?{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===Zi||s===Pu?this.subscribeTargets(t):s===og&&this.unsubscribeTargets(t),e.fire("layout:before",{context:t}),i&&i.fire("object:layout:before",{target:e,context:t}),s===Mu&&t.deep){const n=Lt(t,xw);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===Zi?new O:e.getRelativeCenterPoint(),{center:a,correction:h=new O,relativeCorrection:c=new O}=n,u=r.subtract(a).add(h).transform(i===Zi?Ne:ss(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===Zi?s.set({left:(r=t.x)!==null&&r!==void 0?r:n.x+i.x*te(s.originX),top:(a=t.y)!==null&&a!==void 0?a:n.y+i.y*te(s.originY)}):(s.setPositionByOrigin(n,et,et),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,Sw),{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:Ib,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}V.setClass(Zh,Ib);const Cw=["type","objects","layoutManager"];class Aw extends Zh{performLayout(){}}class Si extends Cm(Te){static getDefaults(){return T(T({},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(),E(this,"_activeObjects",[]),E(this,"__objectSelectionTracker",void 0),E(this,"__objectSelectionDisposer",void 0),Object.assign(this,Si.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 Zh,this.layoutManager.performLayout({type:Zi,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(Yi("error","Group: circular object trees are not supported, this call has no effect"),!1):this._objects.indexOf(t)===-1||(Yi("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(Pu,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(Pu,n),r}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange(og,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&&fo(t,$t(ss(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||(fo(t,$t(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=Te.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(...ss(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:Mu},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=xi.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=Dt(t,Z_);return Promise.all([Zo(i,e),Dh(r,e)]).then(o=>{let[h,c]=o;const u=new this(h,T(T(T({},r),c),{},{layoutManager:new tw}));if(n){const d=W.getClass(n.type),g=W.getClass(n.strategy);u.layoutManager=new d(new g)}else u.layoutManager=new Bh;return u.layoutManager.subscribeTargets({type:Qi,target:u,targets:u.getObjects()}),u.setCoords(),u})}}E(wi,"type","Group"),E(wi,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),W.setClass(wi);const p0=(a,t)=>Math.min(t.width/a.width,t.height/a.height),m0=(a,t)=>Math.max(t.width/a.width,t.height/a.height),Hg="\\s*,?\\s*",Hh="".concat(Hg,"(").concat(qs,")"),ew="".concat(Hh).concat(Hh).concat(Hh).concat(Hg,"([01])").concat(Hg,"([01])").concat(Hh).concat(Hh),sw={m:"l",M:"L"},iw=(a,t,e,s,i,n,r,o,h,c,u)=>{const d=zs(a),g=Xs(a),f=zs(t),p=Xs(t),m=e*i*f-s*n*p+r,w=s*i*f+e*n*p+o;return["C",c+h*(-e*i*g-s*n*d),u+h*(-s*i*g+e*n*d),m+h*(e*i*p+s*n*f),w+h*(s*i*p-e*n*f),m,w]},v0=(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 Vg(a,t,e,s,i,n,r,o){let h;if(ft.cachesBoundsOfCurve&&(h=[...arguments].join(),Eh.boundsOfCurveCache[h]))return Eh.boundsOfCurveCache[h];const c=Math.sqrt,u=Math.abs,d=[],g=[[0,0],[0,0]];let f=6*a-12*e+6*i,p=-3*a+9*e-9*i+3*r,m=3*e-3*a;for(let A=0;A<2;++A){if(A>0&&(f=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(f)<1e-12)continue;const R=-m/f;0<R&&R<1&&d.push(R);continue}const P=f*f-4*m*p;if(P<0)continue;const D=c(P),k=(-f+D)/(2*p);0<k&&k<1&&d.push(k);const M=(-f-D)/(2*p);0<M&&M<1&&d.push(M)}let w=d.length;const b=w,x=y0(a,t,e,s,i,n,r,o);for(;w--;){const{x:A,y:P}=x(d[w]);g[0][w]=A,g[1][w]=P}g[0][b]=a,g[1][b]=t,g[0][b+1]=r,g[1][b+1]=o;const C=[new O(Math.min(...g[0]),Math.min(...g[1])),new O(Math.max(...g[0]),Math.max(...g[1]))];return ft.cachesBoundsOfCurve&&(Eh.boundsOfCurveCache[h]=C),C}const nw=(a,t,e)=>{let[s,i,n,r,o,h,c,u]=e;const d=((g,f,p,m,w,b,x)=>{if(p===0||m===0)return[];let C=0,A=0,P=0;const D=Math.PI,k=x*ng,M=Xs(k),R=zs(k),F=.5*(-R*g-M*f),I=.5*(-R*f+M*g),X=p**2,j=m**2,N=I**2,nt=F**2,K=X*j-X*N-j*nt;let V=Math.abs(p),H=Math.abs(m);if(K<0){const $e=Math.sqrt(1-K/(X*j));V*=$e,H*=$e}else P=(w===b?-1:1)*Math.sqrt(K/(X*N+j*nt));const Et=P*V*I/H,jt=-P*H*F/V,ie=R*Et-M*jt+.5*g,Wt=M*Et+R*jt+.5*f;let Tt=v0(1,0,(F-Et)/V,(I-jt)/H),xe=v0((F-Et)/V,(I-jt)/H,(-F-Et)/V,(-I-jt)/H);b===0&&xe>0?xe-=2*D:b===1&&xe<0&&(xe+=2*D);const Gs=Math.ceil(Math.abs(xe/D*2)),Ot=[],dt=xe/Gs,Ss=8/3*Math.sin(dt/4)*Math.sin(dt/4)/Math.sin(dt/2);let zi=Tt+dt;for(let $e=0;$e<Gs;$e++)Ot[$e]=iw(Tt,zi,R,M,V,H,ie,Wt,Ss,C,A),C=Ot[$e][5],A=Ot[$e][6],Tt=zi,zi+=dt;return Ot})(c-a,u-t,i,n,o,h,r);for(let g=0,f=d.length;g<f;g++)d[g][1]+=a,d[g][2]+=t,d[g][3]+=a,d[g][4]+=t,d[g][5]+=a,d[g][6]+=t;return d},b0=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":nw(t,e,u).forEach(g=>n.push(g)),t=u[6],e=u[7];break;case"z":case"Z":t=s,e=i,d=["Z"]}d?(n.push(d),r=d[0]):r=""}return n},du=(a,t,e,s)=>Math.sqrt((e-a)**2+(s-t)**2),y0=(a,t,e,s,i,n,r,o)=>h=>{const c=h**3,u=(f=>3*f**2*(1-f))(h),d=(f=>3*f*(1-f)**2)(h),g=(f=>(1-f)**3)(h);return new O(r*c+i*u+e*d+a*g,o*c+n*u+s*d+t*g)},_0=a=>a**2,w0=a=>2*a*(1-a),x0=a=>(1-a)**2,rw=(a,t,e,s,i,n,r,o)=>h=>{const c=_0(h),u=w0(h),d=x0(h),g=3*(d*(e-a)+u*(i-e)+c*(r-i)),f=3*(d*(s-t)+u*(n-s)+c*(o-n));return Math.atan2(f,g)},ow=(a,t,e,s,i,n)=>r=>{const o=_0(r),h=w0(r),c=x0(r);return new O(i*o+e*h+a*c,n*o+s*h+t*c)},aw=(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)},S0=(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+=du(s.x,s.y,r.x,r.y),s=r}return i},hw=(a,t)=>{let e,s=0,i=0,n={x:a.x,y:a.y},r=T({},n),o=.01,h=0;const c=a.iterator,u=a.angleFinder;for(;i<t&&o>1e-4;)r=c(s),h=s,e=du(n.x,n.y,r.x,r.y),e+i>t?(s-=o,o/=2):(n=r,s+=o,i+=e);return T(T({},r),{},{angle:u(h)})},Gg=a=>{let t,e,s=0,i=0,n=0,r=0,o=0;const h=[];for(const c of a){const u={x:i,y:n,command:c[0],length:0};switch(c[0]){case"M":e=u,e.x=r=i=c[1],e.y=o=n=c[2];break;case"L":e=u,e.length=du(i,n,c[1],c[2]),i=c[1],n=c[2];break;case"C":t=y0(i,n,c[1],c[2],c[3],c[4],c[5],c[6]),e=u,e.iterator=t,e.angleFinder=rw(i,n,c[1],c[2],c[3],c[4],c[5],c[6]),e.length=S0(t,i,n),i=c[5],n=c[6];break;case"Q":t=ow(i,n,c[1],c[2],c[3],c[4]),e=u,e.iterator=t,e.angleFinder=aw(i,n,c[1],c[2],c[3],c[4]),e.length=S0(t,i,n),i=c[3],n=c[4];break;case"Z":e=u,e.destX=r,e.destY=o,e.length=du(i,n,r,o),i=r,n=o}s+=e.length,h.push(e)}return h.push({length:s,x:i,y:n}),h},C0=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Gg(a),s=0;for(;t-e[s].length>0&&s<e.length-2;)t-=e[s].length,s++;const i=e[s],n=t/i.length,r=a[s];switch(i.command){case"M":return{x:i.x,y:i.y,angle:0};case"Z":return T(T({},new 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 T(T({},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 hw(i,t)}},lw=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),A0=new RegExp(ew,"g"),cw=new RegExp(qs,"gi"),uw={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},T0=a=>{var t;const e=[],s=(t=a.match(lw))!==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=uw[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(cw)||[];for(let h=0;h<o.length;h+=r){const c=new Array(r),u=sw[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},dw=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},E0=(a,t)=>a.map(e=>e.map((s,i)=>i===0||t===void 0?s:Rt(s,t)).join(" ")).join(" ");function gu(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 gw=(a,t)=>Math.floor(Math.random()*(t-a+1))+a;function k0(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const e=t.onComplete||Cr,s=new(Bc()).XMLHttpRequest,i=t.signal,n=function(){s.abort()},r=function(){i&&i.removeEventListener("abort",n),s.onerror=s.ontimeout=Cr};if(i&&i.aborted)throw new sg("request");return i&&i.addEventListener("abort",n,{once:!0}),s.onreadystatechange=function(){s.readyState===4&&(r(),e(s),s.onreadystatechange=Cr)},s.onerror=s.ontimeout=r,s.open("get",a,!0),s.send(),s}const fu=(a,t)=>{let e=a._findCenterFromElement();a.transformMatrix&&((s=>{if(s.transformMatrix){const{scaleX:i,scaleY:n,angle:r,skewX:o}=Tr(s.transformMatrix);s.flipX=!1,s.flipY=!1,s.set(je,i),s.set(hs,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,tt,tt)};var fw=Object.freeze({__proto__:null,addTransformToObject:xm,animate:Dg,animateColor:Gm,applyTransformToObject:ta,calcAngleBetweenVectors:eu,calcDimensionsMatrix:Mh,calcPlaneChangeMatrix:Ih,calcVectorRotation:Fm,cancelAnimFrame:nm,capValue:Mr,composeMatrix:lm,copyCanvasElement:a=>{var t;const e=Us(a);return(t=e.getContext("2d"))===null||t===void 0||t.drawImage(a,0,0),e},cos:zs,createCanvasElement:Cs,createImage:rm,createRotateMatrix:Qo,createScaleMatrix:Yc,createSkewXMatrix:dg,createSkewYMatrix:gg,createTranslateMatrix:Jo,createVector:Zc,crossProduct:ea,degreesToRadians:zt,dotProduct:Im,ease:s_,enlivenObjectEnlivables:Dh,enlivenObjects:Zo,findScaleToCover:m0,findScaleToFit:p0,getBoundsOfCurve:Vg,getOrthonormalVector:Tg,getPathSegmentsInfo:Gg,getPointOnPath:C0,getPointer:wm,getRandomInt:gw,getRegularPolygonPath:(a,t)=>{const e=2*Math.PI/a;let s=-jn;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(zs(r),Xs(r)).scalarMultiply(t);i[n]=[n===0?"M":"L",o,h]}return i[a]=["Z"],i},getSmoothPathFromPoints:dw,getSvgAttributes:a=>{const t=["instantiated_by_use","style","id","class"];switch(a){case"linearGradient":return t.concat(["x1","y1","x2","y2","gradientUnits","gradientTransform"]);case"radialGradient":return t.concat(["gradientUnits","gradientTransform","cx","cy","r","fx","fy","fr"]);case"stop":return t.concat(["offset","stop-color","stop-opacity"])}return t},getUnitVector:su,groupSVGElements:(a,t)=>a&&a.length===1?a[0]:new wi(a,t),hasStyleChanged:au,invertTransform:Ze,isBetweenVectors:Eg,isIdentityMatrix:om,isTouchEvent:qc,isTransparent:Jm,joinPath:E0,loadImage:Oh,magnitude:tu,makeBoundingBoxFromPoints:yi,makePathSimpler:b0,matrixToSVG:Rh,mergeClipPaths:(a,t)=>{var e;let s=a,i=t;s.inverted&&!i.inverted&&(s=t,i=a),_g(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 wi([s],{clipPath:i,inverted:n})},multiplyTransformMatrices:Yt,multiplyTransformMatrixArray:Uc,parsePath:T0,parsePreserveAspectRatioAttribute:mg,parseUnit:Be,pick:Er,projectStrokeOnPoints:t0,qrDecompose:Tr,radiansToDegrees:Hn,removeFromArray:Ar,removeTransformFromObject:(a,t)=>{const e=Ze(t),s=Yt(e,a.calcOwnMatrix());ta(a,s)},removeTransformMatrixForSvgParsing:fu,request:k0,requestAnimFrame:Ph,resetObjectTransform:Sm,rotatePoint:(a,t,e)=>a.rotate(e,t),rotateVector:Ag,saveObjectTransform:yg,sendObjectToPlane:_g,sendPointToPlane:Pr,sendVectorToPlane:Cm,setStyle:gu,sin:Xs,sizeAfterTransform:Kc,string:M_,stylesFromArray:i0,stylesToArray:s0,toDataURL:ug,toFixed:Rt,transformPath:(a,t,e)=>(e&&(t=Yt(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}=Se({x:s[n],y:s[n+1]},t);i[n]=r,i[n+1]=o}return i})),transformPoint:Se});class pw extends _m{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=Cs();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=Yo().createElement("div");return t.setAttribute("data-fabric","wrapper"),gu(t,{position:"relative"}),ym(t),t}applyCanvasStyle(t,e){const{styles:s,allowTouchScrolling:i}=e;gu(t,T(T({},s),{},{"touch-action":i?"manipulation":Ie})),ym(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),vg(this.upper.el,t),vg(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(),bi().dispose(this.upper.el),delete this.upper,delete this.container}}class pu extends Fh{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()),pu.ownDefaults)}get upperCanvasEl(){var t;return(t=this.elements.upper)===null||t===void 0?void 0:t.el}get contextTop(){var t;return(t=this.elements.upper)===null||t===void 0?void 0:t.ctx}get wrapperEl(){return this.elements.container}initElements(t){this.elements=new pw(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 Jm(n,o,o,o)}_isSelectionKeyPressed(t){const e=this.selectionKey;return!!e&&(Array.isArray(e)?!!e.find(s=>!!s&&t[s]===!0):t[e])}_shouldClearSelection(t,e){const s=this.getActiveObjects(),i=this._activeObject;return!!(!e||e&&i&&s.length>1&&s.indexOf(e)===-1&&i!==e&&!this._isSelectionKeyPressed(t)||e&&!e.evented||e&&!e.selectable&&i&&i!==e)}_shouldCenterTransform(t,e,s){if(!t)return;let i;return e===Gc||e===je||e===hs||e===kh?i=this.centeredScaling||t.centeredScaling:e===hg&&(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=Ut:["mr","tr","br"].includes(e)&&(s.x=vt),["tl","mt","tr"].includes(e)?s.y=og:["bl","mb","br"].includes(e)&&(s.y=Qe)),s}_setupCurrentTransform(t,e,s){var i;const n=e.group?Pr(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):$y,c=((f,p,m,w)=>{if(!p||!f)return"drag";const b=w.controls[p];return b.getActionName(m,b,w)})(s,r,t,e),u=t[this.centeredKey],d=this._shouldCenterTransform(e,c,u)?{x:tt,y:tt}:this._getOriginFromCorner(e,r),g={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:zt(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:u,original:T(T({},yg(e)),{},{originX:d.x,originY:d.y})};this._currentTransform=g,this.fire("before:transform",{e:t,transform:g})}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new 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),g=Math.max(r.y,o.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(c,u,d-c,g-u)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,c+=h,u+=h,d-=h,g-=h,Ce.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(c,u,d-c,g-u))}findTarget(t){if(this.skipTargetFind)return;const e=this.getViewportPoint(t),s=this._activeObject,i=this.getActiveObjects();if(this.targets=[],s&&i.length>=1){if(s.findControl(e,qc(t))||i.length>1&&this.searchPossibleTargets([s],e))return s;if(s===this.searchPossibleTargets([s],e)){if(this.preserveObjectStacking){const n=this.targets;this.targets=[];const r=this.searchPossibleTargets(this._objects,e);return t[this.altSelectionKey]&&r&&r!==s?(this.targets=n,s):r}return s}}return this.searchPossibleTargets(this._objects,e)}_pointIsInObjectSelectionArea(t,e){let s=t.getCoords();const i=this.getZoom(),n=t.padding/i;if(n){const[r,o,h,c]=s,u=Math.atan2(o.y-r.y,o.x-r.x),d=zs(u)*n,g=Xs(u)*n,f=d+g,p=d-g;s=[new O(r.x-p,r.y-f),new O(o.x+f,o.y-p),new O(h.x+p,h.y+f),new O(c.x-f,c.y+p)]}return Nt.isPointInPolygon(e,s)}_checkTarget(t,e){return!!(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,Pr(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(Xc(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&&Xc(s)&&s.interactive&&this.targets[0]){const i=this.targets;for(let n=i.length-1;n>0;n--){const r=i[n];if(!Xc(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=wm(t),r=i.width||0,o=i.height||0;r&&o||(Qe in i&&og in i&&(o=Math.abs(i.top-i.bottom)),Ut in i&&vt 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=Pr(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=Cs(),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 kr(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,kr(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),kr(s)&&s===this._hoveredTarget&&(this._hoveredTarget=void 0),this._activeObject=void 0,!0)}discardActiveObject(t){const e=this.getActiveObjects(),s=this.getActiveObject();e.length&&this.fire("before:selection:cleared",{e:t,deselected:[s]});const i=this._discardActiveObject(t);return this._fireSelectionEvents(e,t),i}endCurrentTransform(t){const e=this._currentTransform;this._finalizeCurrentTransform(t),e&&e.target&&(e.target.isMoving=!1),this._currentTransform=null}_finalizeCurrentTransform(t){const e=this._currentTransform,s=e.target,i={e:t,target:s,transform:e,action:e.action};s._scaling&&(s._scaling=!1),s.setCoords(),e.actionPerformed&&(this.fire("object:modified",i),s.fire(Wc,i))}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeObject;kr(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&&kr(e)&&this._activeObject===e){const s=Er(t,["angle","flipX","flipY",vt,je,hs,$o,qo,Qe]);return xm(t,e.calcOwnMatrix()),s}return{}}_setSVGObject(t,e,s){const i=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,s),e.set(i)}}E(pu,"ownDefaults",{uniformScaling:!0,uniScaleKey:"shiftKey",centeredScaling:!1,centeredRotation:!1,centeredKey:"altKey",altActionKey:"shiftKey",selection:!0,selectionKey:"shiftKey",selectionColor:"rgba(100, 100, 255, 0.3)",selectionDashArray:[],selectionBorderColor:"rgba(255, 255, 255, 0.3)",selectionLineWidth:1,selectionFullyContained:!1,hoverCursor:"move",moveCursor:"move",defaultCursor:"default",freeDrawingCursor:"crosshair",notAllowedCursor:"not-allowed",perPixelTargetFind:!1,targetFindTolerance:0,skipTargetFind:!1,stopContextMenu:!1,fireRightClick:!1,fireMiddleClick:!1,enablePointerEvents:!1,containerClass:"canvas-container",preserveObjectStacking:!1});class mw{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),Ar(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 vw=["target","oldTarget","fireCanvas","e"],ls={passive:!1},oa=(a,t)=>{const e=a.getViewportPoint(t),s=a.getScenePoint(t);return{viewportPoint:e,scenePoint:s,pointer:e,absolutePointer:s}},Gn=function(a){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return a.addEventListener(...e)},Ts=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)},bw={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 Wg extends pu{constructor(t){super(t,arguments.length>1&&arguments[1]!==void 0?arguments[1]:{}),E(this,"_isClick",void 0),E(this,"textEditingManager",new mw(this)),["_onMouseDown","_onTouchStart","_onMouseMove","_onMouseUp","_onTouchEnd","_onResize","_onMouseWheel","_onMouseOut","_onMouseEnter","_onContextMenu","_onDoubleClick","_onDragStart","_onDragEnd","_onDragProgress","_onDragOver","_onDragEnter","_onDragLeave","_onDrop"].forEach(e=>{this[e]=this[e].bind(this)}),this.addOrRemove(Gn,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const s=this.upperCanvasEl,i=this._getEventPrefix();t(vm(s),"resize",this._onResize),t(s,i+"down",this._onMouseDown),t(s,"".concat(i,"move"),this._onMouseMove,ls),t(s,"".concat(i,"out"),this._onMouseOut),t(s,"".concat(i,"enter"),this._onMouseEnter),t(s,"wheel",this._onMouseWheel),t(s,"contextmenu",this._onContextMenu),t(s,"dblclick",this._onDoubleClick),t(s,"dragstart",this._onDragStart),t(s,"dragend",this._onDragEnd),t(s,"dragover",this._onDragOver),t(s,"dragenter",this._onDragEnter),t(s,"dragleave",this._onDragLeave),t(s,"drop",this._onDrop),this.enablePointerEvents||t(s,"touchstart",this._onTouchStart,ls)}removeListeners(){this.addOrRemove(Ts,"remove");const t=this._getEventPrefix(),e=Ys(this.upperCanvasEl);Ts(e,"".concat(t,"up"),this._onMouseUp),Ts(e,"touchend",this._onTouchEnd,ls),Ts(e,"".concat(t,"move"),this._onMouseMove,ls),Ts(e,"touchmove",this._onMouseMove,ls),clearTimeout(this._willAddMouseDown)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s=T({e:t},oa(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},oa(this,t))),this._hoveredTarget=void 0,this._hoveredTargets=[])}_onDragStart(t){this._isClick=!1;const e=this.getActiveObject();if(e&&e.onDragStart(t)){this._dragSource=e;const s={e:t,target:e};return this.fire("dragstart",s),e.fire("dragstart",s),void Gn(this.upperCanvasEl,"drag",this._onDragProgress)}bg(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!==Ie,s=e?this._activeObject:void 0,i={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:s};Ts(this.upperCanvasEl,"drag",this._onDragProgress),this.fire("dragend",i),this._dragSource&&this._dragSource.fire("dragend",i),delete this._dragSource,this._onMouseUp(t)}_onDragProgress(t){const e={e:t,target:this._dragSource,dragSource:this._dragSource,dropTarget:this._draggedoverTarget};this.fire("drag",e),this._dragSource&&this._dragSource.fire("drag",e)}findDragTargets(t){return this.targets=[],{target:this._searchPossibleTargets(this._objects,this.getViewportPoint(t)),targets:[...this.targets]}}_onDragOver(t){const e="dragover",{target:s,targets:i}=this.findDragTargets(t),n=this._dragSource,r={e:t,target:s,subTargets:i,dragSource:n,canDrop:!1,dropTarget:void 0};let o;this.fire(e,r),this._fireEnterLeaveEvents(s,r),s&&(s.canDrop(t)&&(o=s),s.fire(e,r));for(let h=0;h<i.length;h++){const c=i[h];c.canDrop(t)&&(o=c),c.fire(e,r)}this._renderDragEffects(t,n,o),this._dropTarget=o}_onDragEnter(t){const{target:e,targets:s}=this.findDragTargets(t),i={e:t,target:e,subTargets:s,dragSource:this._dragSource};this.fire("dragenter",i),this._fireEnterLeaveEvents(e,i)}_onDragLeave(t){const e={e:t,target:this._draggedoverTarget,subTargets:this.targets,dragSource:this._dragSource};this.fire("dragleave",e),this._fireEnterLeaveEvents(void 0,e),this._renderDragEffects(t,this._dragSource),this._dropTarget=void 0,this.targets=[],this._hoveredTargets=[]}_onDrop(t){const{target:e,targets:s}=this.findDragTargets(t),i=this._basicEventHandler("drop:before",T({e:t,target:e,subTargets:s,dragSource:this._dragSource},oa(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&&bg(t),this._basicEventHandler("contextmenu",i),!1}_onDoubleClick(t){this._cacheTransformEventData(t),this._handleEvent(t,"dblclick"),this._resetTransformEventData()}getPointerId(t){const e=t.changedTouches;return e?e[0]&&e[0].identifier:this.enablePointerEvents?t.pointerId:-1}_isMainEvent(t){return t.isPrimary===!0||t.isPrimary!==!1&&(t.type==="touchend"&&t.touches.length===0||!t.changedTouches||t.changedTouches[0].identifier===this.mainTouchId)}_onTouchStart(t){let e=!this.allowTouchScrolling;const s=this._activeObject;this.mainTouchId===void 0&&(this.mainTouchId=this.getPointerId(t)),this.__onMouseDown(t),(this.isDrawingMode||s&&this._target===s)&&(e=!0),e&&t.preventDefault(),this._resetTransformEventData();const i=this.upperCanvasEl,n=this._getEventPrefix(),r=Ys(i);Gn(r,"touchend",this._onTouchEnd,ls),e&&Gn(r,"touchmove",this._onMouseMove,ls),Ts(i,"".concat(n,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();Ts(e,"".concat(s,"move"),this._onMouseMove,ls);const i=Ys(e);Gn(i,"".concat(s,"up"),this._onMouseUp),Gn(i,"".concat(s,"move"),this._onMouseMove,ls)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),s=Ys(this.upperCanvasEl);Ts(s,"touchend",this._onTouchEnd,ls),Ts(s,"touchmove",this._onMouseMove,ls),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout(()=>{Gn(this.upperCanvasEl,"".concat(e,"down"),this._onMouseDown),this._willAddMouseDown=0},400)}_onMouseUp(t){this.__onMouseUp(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();if(this._isMainEvent(t)){const i=Ys(this.upperCanvasEl);Ts(i,"".concat(s,"up"),this._onMouseUp),Ts(i,"".concat(s,"move"),this._onMouseMove,ls),Gn(e,"".concat(s,"move"),this._onMouseMove,ls)}}_onMouseMove(t){const e=this.getActiveObject();!this.allowTouchScrolling&&(!e||!e.shouldStartDragging(t))&&t.preventDefault&&t.preventDefault(),this.__onMouseMove(t)}_onResize(){this.calcOffset(),this._resetTransformEventData()}_shouldRender(t){const e=this.getActiveObject();return!!e!=!!t||e&&t&&e!==t}__onMouseUp(t){var e;this._cacheTransformEventData(t),this._handleEvent(t,"up:before");const s=this._currentTransform,i=this._isClick,n=this._target,{button:r}=t;if(r)return(this.fireMiddleClick&&r===1||this.fireRightClick&&r===2)&&this._handleEvent(t,"up"),void this._resetTransformEventData();if(this.isDrawingMode&&this._isCurrentlyDrawing)return void this._onMouseUpInDrawingMode(t);if(!this._isMainEvent(t))return;let o,h,c=!1;if(s&&(this._finalizeCurrentTransform(t),c=s.actionPerformed),!i){const u=n===this._activeObject;this.handleSelection(t),c||(c=this._shouldRender(n)||!u&&n===this._activeObject)}if(n){const u=n.findControl(this.getViewportPoint(t),qc(t)),{key:d,control:g}=u||{};if(h=d,n.selectable&&n!==this._activeObject&&n.activeOn==="up")this.setActiveObject(n,t),c=!0;else if(g){const f=g.getMouseUpHandler(t,n,g);f&&(o=this.getScenePoint(t),f.call(g,t,s,o.x,o.y))}n.isMoving=!1}if(s&&(s.target!==n||s.corner!==h)){const u=s.target&&s.target.controls[s.corner],d=u&&u.getMouseUpHandler(t,s.target,u);o=o||this.getScenePoint(t),d&&d.call(u,t,s,o.x,o.y)}this._setCursorFromEvent(t,n),this._handleEvent(t,"up"),this._groupSelector=null,this._currentTransform=null,n&&(n.__corner=void 0),c?this.requestRenderAll():i||(e=this._activeObject)!==null&&e!==void 0&&e.isEditing||this.renderTop()}_basicEventHandler(t,e){const{target:s,subTargets:i=[]}=e;this.fire(t,e),s&&s.fire(t,e);for(let n=0;n<i.length;n++)i[n]!==s&&i[n].fire(t,e);return e}_handleEvent(t,e){const s=this._target,i=this.targets||[],n=T(T({e:t,target:s,subTargets:i},oa(this,t)),{},{transform:this._currentTransform},e==="up:before"||e==="up"?{isClick:this._isClick,currentTarget:this.findTarget(t),currentSubTargets:this.targets}:{});this.fire("mouse:".concat(e),n),s&&s.fire("mouse".concat(e),n);for(let r=0;r<i.length;r++)i[r]!==s&&i[r].fire("mouse".concat(e),n)}_onMouseDownInDrawingMode(t){this._isCurrentlyDrawing=!0,this.getActiveObject()&&(this.discardActiveObject(t),this.requestRenderAll());const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseDown(e,{e:t,pointer:e}),this._handleEvent(t,"down")}_onMouseMoveInDrawingMode(t){if(this._isCurrentlyDrawing){const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseMove(e,{e:t,pointer:e})}this.setCursor(this.freeDrawingCursor),this._handleEvent(t,"move")}_onMouseUpInDrawingMode(t){const e=this.getScenePoint(t);this.freeDrawingBrush?this._isCurrentlyDrawing=!!this.freeDrawingBrush.onMouseUp({e:t,pointer:e}):this._isCurrentlyDrawing=!1,this._handleEvent(t,"up")}__onMouseDown(t){this._isClick=!0,this._cacheTransformEventData(t),this._handleEvent(t,"down:before");let e=this._target;const{button:s}=t;if(s)return(this.fireMiddleClick&&s===1||this.fireRightClick&&s===2)&&this._handleEvent(t,"down"),void this._resetTransformEventData();if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t)||this._currentTransform)return;let i=this._shouldRender(e),n=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,n=!0,i=!0):this._shouldClearSelection(t,e)&&this.discardActiveObject(t),this.selection&&(!e||!e.selectable&&!e.isEditing&&e!==this._activeObject)){const r=this.getScenePoint(t);this._groupSelector={x:r.x,y:r.y,deltaY:0,deltaX:0}}if(e){const r=e===this._activeObject;e.selectable&&e.activeOn==="down"&&this.setActiveObject(e,t);const o=e.findControl(this.getViewportPoint(t),qc(t));if(e===this._activeObject&&(o||!n)){this._setupCurrentTransform(t,e,r);const h=o?o.control:void 0,c=this.getScenePoint(t),u=h&&h.getMouseDownHandler(t,e,h);u&&u.call(h,t,this._currentTransform,c.x,c.y)}}i&&(this._objectsToRender=void 0),this._handleEvent(t,"down"),i&&this.requestRenderAll()}_resetTransformEventData(){this._target=this._pointer=this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getViewportPoint(t),this._absolutePointer=Pr(this._pointer,void 0,this.viewportTransform),this._target=this._currentTransform?this._currentTransform.target:this.findTarget(t)}__onMouseMove(t){if(this._isClick=!1,this._cacheTransformEventData(t),this._handleEvent(t,"move:before"),this.isDrawingMode)return void this._onMouseMoveInDrawingMode(t);if(!this._isMainEvent(t))return;const e=this._groupSelector;if(e){const s=this.getScenePoint(t);e.deltaX=s.x-e.x,e.deltaY=s.y-e.y,this.renderTop()}else if(this._currentTransform)this._transformObject(t);else{const s=this.findTarget(t);this._setCursorFromEvent(t,s),this._fireOverOutEvents(t,s)}this.textEditingManager.onMouseMove(t),this._handleEvent(t,"move"),this._resetTransformEventData()}_fireOverOutEvents(t,e){const s=this._hoveredTarget,i=this._hoveredTargets,n=this.targets,r=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("mouse",{e:t,target:e,oldTarget:s,fireCanvas:!0});for(let o=0;o<r;o++)this.fireSyntheticInOutEvents("mouse",{e:t,target:n[o],oldTarget:i[o]});this._hoveredTarget=e,this._hoveredTargets=this.targets.concat()}_fireEnterLeaveEvents(t,e){const s=this._draggedoverTarget,i=this._hoveredTargets,n=this.targets,r=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("drag",T(T({},e),{},{target:t,oldTarget:s,fireCanvas:!0}));for(let o=0;o<r;o++)this.fireSyntheticInOutEvents("drag",T(T({},e),{},{target:n[o],oldTarget:i[o]}));this._draggedoverTarget=t}fireSyntheticInOutEvents(t,e){let{target:s,oldTarget:i,fireCanvas:n,e:r}=e,o=Dt(e,vw);const{targetIn:h,targetOut:c,canvasIn:u,canvasOut:d}=bw[t],g=i!==s;if(i&&g){const f=T(T({},o),{},{e:r,target:i,nextTarget:s},oa(this,r));n&&this.fire(d,f),i.fire(c,f)}if(s&&g){const f=T(T({},o),{},{e:r,target:s,previousTarget:i},oa(this,r));n&&this.fire(u,f),s.fire(h,f)}}__onMouseWheel(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()}_transformObject(t){const e=this.getScenePoint(t),s=this._currentTransform,i=s.target,n=i.group?Pr(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=kr(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=kr(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 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(g=>!g.onSelect({e:t})).reverse():u;if(d.length===1)this.setActiveObject(d[0],t);else if(d.length>1){const g=W.getClass("ActiveSelection");this.setActiveObject(new g(d,{canvas:this}),t)}return this._groupSelector=null,!0}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const P0={x1:0,y1:0,x2:0,y2:0},yw=T(T({},P0),{},{r1:0,r2:0}),aa=(a,t)=>isNaN(a)&&typeof t=="number"?t:a,_w=/^(\d+\.\d+)%|(\d+)%$/;function M0(a){return a&&_w.test(a)}function O0(a,t){const e=typeof a=="number"?a:typeof a=="string"?parseFloat(a)/(M0(a)?100:1):NaN;return Mr(0,aa(e,t),1)}const ww=/\s*;\s*/,xw=/\s*:\s*/;function Sw(a,t){let e,s;const i=a.getAttribute("style");if(i){const r=i.split(ww);r[r.length-1]===""&&r.pop();for(let o=r.length;o--;){const[h,c]=r[o].split(xw).map(u=>u.trim());h==="stop-color"?e=c:h==="stop-opacity"&&(s=c)}}const n=new _t(e||a.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:O0(a.getAttribute("offset"),0),color:n.toRgb(),opacity:aa(parseFloat(s||a.getAttribute("stop-opacity")||""),1)*n.getAlpha()*t}}function Cw(a,t){const e=[],s=a.getElementsByTagName("stop"),i=O0(t,1);for(let n=s.length;n--;)e.push(Sw(s[n],i));return e}function D0(a){return a.nodeName==="linearGradient"||a.nodeName==="LINEARGRADIENT"?"linear":"radial"}function R0(a){return a.getAttribute("gradientUnits")==="userSpaceOnUse"?"pixels":"percentage"}function Js(a,t){return a.getAttribute(t)}function Aw(a,t){return function(e,s){let i,{width:n,height:r,gradientUnits:o}=s;return Object.keys(e).reduce((h,c)=>{const u=e[c];return u==="Infinity"?i=1:u==="-Infinity"?i=0:(i=typeof u=="string"?parseFloat(u):u,typeof u=="string"&&M0(u)&&(i*=.01,o==="pixels"&&(c!=="x1"&&c!=="x2"&&c!=="r2"||(i*=n),c!=="y1"&&c!=="y2"||(i*=r)))),h[c]=i,h},{})}(D0(a)==="linear"?function(e){return{x1:Js(e,"x1")||0,y1:Js(e,"y1")||0,x2:Js(e,"x2")||"100%",y2:Js(e,"y2")||0}}(a):function(e){return{x1:Js(e,"fx")||Js(e,"cx")||"50%",y1:Js(e,"fy")||Js(e,"cy")||"50%",r1:0,x2:Js(e,"cx")||"50%",y2:Js(e,"cy")||"50%",r2:Js(e,"r")||"50%"}}(a),T(T({},t),{},{gradientUnits:R0(a)}))}class Vh{constructor(t){const{type:e="linear",gradientUnits:s="pixels",coords:i={},colorStops:n=[],offsetX:r=0,offsetY:o=0,gradientTransform:h,id:c}=t||{};Object.assign(this,{type:e,gradientUnits:s,coords:T(T({},e==="radial"?yw:P0),i),colorStops:n,offsetX:r,offsetY:o,gradientTransform:h,id:c?"".concat(c,"_").concat(Bn()):Bn()})}addColorStop(t){for(const e in t){const s=new _t(t[e]);this.colorStops.push({offset:parseFloat(e),color:s.toRgb(),opacity:s.getAlpha()})}return this}toObject(t){return T(T({},Er(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():Fe.concat(),n=this.gradientUnits==="pixels"?"userSpaceOnUse":"objectBoundingBox",r=this.colorStops.map(d=>T({},d)).sort((d,g)=>d.offset-g.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(Rh(i),'"'),""].join(" ");if(this.type==="linear"){const{x1:d,y1:g,x2:f,y2:p}=this.coords;s.push("<linearGradient ",u,' x1="',d,'" y1="',g,'" x2="',f,'" y2="',p,`">
|
|
71
|
-
`)}else if(this.type==="radial"){const{x1:d,y1:
|
|
72
|
-
`),
|
|
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,Cw);return Promise.all([uo(i,e),Uh(r,e)]).then(a=>{let[h,c]=a;const u=new this(h,T(T(T({},r),c),{},{layoutManager:new Aw}));if(n){const d=V.getClass(n.type),f=V.getClass(n.strategy);u.layoutManager=new d(new f)}else u.layoutManager=new Zh;return u.layoutManager.subscribeTargets({type:Zi,target:u,targets:u.getObjects()}),u.setCoords(),u})}}E(Si,"type","Group"),E(Si,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),V.setClass(Si);const jb=(o,t)=>Math.min(t.width/o.width,t.height/o.height),Nb=(o,t)=>Math.max(t.width/o.width,t.height/o.height),lg="\\s*,?\\s*",tl="".concat(lg,"(").concat(Qs,")"),Tw="".concat(tl).concat(tl).concat(tl).concat(lg,"([01])").concat(lg,"([01])").concat(tl).concat(tl),Ew={m:"l",M:"L"},kw=(o,t,e,s,i,n,r,a,h,c,u)=>{const d=Ys(o),f=$s(o),g=Ys(t),p=$s(t),b=e*i*g-s*n*p+r,_=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),b+h*(e*i*p+s*n*g),_+h*(s*i*p-e*n*g),b,_]},Bb=(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 cg(o,t,e,s,i,n,r,a){let h;if(pt.cachesBoundsOfCurve&&(h=[...arguments].join(),Vh.boundsOfCurveCache[h]))return Vh.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,b=3*e-3*o;for(let A=0;A<2;++A){if(A>0&&(g=6*t-12*s+6*n,p=-3*t+9*s-9*n+3*a,b=3*s-3*t),u(p)<1e-12){if(u(g)<1e-12)continue;const R=-b/g;0<R&&R<1&&d.push(R);continue}const P=g*g-4*b*p;if(P<0)continue;const D=c(P),k=(-g+D)/(2*p);0<k&&k<1&&d.push(k);const M=(-g-D)/(2*p);0<M&&M<1&&d.push(M)}let _=d.length;const y=_,x=Vb(o,t,e,s,i,n,r,a);for(;_--;){const{x:A,y:P}=x(d[_]);f[0][_]=A,f[1][_]=P}f[0][y]=o,f[1][y]=t,f[0][y+1]=r,f[1][y+1]=a;const C=[new O(Math.min(...f[0]),Math.min(...f[1])),new O(Math.max(...f[0]),Math.max(...f[1]))];return pt.cachesBoundsOfCurve&&(Vh.boundsOfCurveCache[h]=C),C}const Pw=(o,t,e)=>{let[s,i,n,r,a,h,c,u]=e;const d=((f,g,p,b,_,y,x)=>{if(p===0||b===0)return[];let C=0,A=0,P=0;const D=Math.PI,k=x*Ef,M=$s(k),R=Ys(k),F=.5*(-R*f-M*g),I=.5*(-R*g+M*f),Y=p**2,N=b**2,H=I**2,at=F**2,j=Y*N-Y*H-N*at;let z=Math.abs(p),it=Math.abs(b);if(j<0){const Je=Math.sqrt(1-j/(Y*N));z*=Je,it*=Je}else P=(_===y?-1:1)*Math.sqrt(j/(Y*H+N*at));const kt=P*z*I/it,Ut=-P*it*F/z,ne=R*kt-M*Ut+.5*f,zt=M*kt+R*Ut+.5*g;let Tt=Bb(1,0,(F-kt)/z,(I-Ut)/it),Ce=Bb((F-kt)/z,(I-Ut)/it,(-F-kt)/z,(-I-Ut)/it);y===0&&Ce>0?Ce-=2*D:y===1&&Ce<0&&(Ce+=2*D);const Xs=Math.ceil(Math.abs(Ce/D*2)),Dt=[],ft=Ce/Xs,Ps=8/3*Math.sin(ft/4)*Math.sin(ft/4)/Math.sin(ft/2);let Xi=Tt+ft;for(let Je=0;Je<Xs;Je++)Dt[Je]=kw(Tt,Xi,R,M,z,it,ne,zt,Ps,C,A),C=Dt[Je][5],A=Dt[Je][6],Tt=Xi,Xi+=ft;return Dt})(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},Hb=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":Pw(t,e,u).forEach(f=>n.push(f)),t=u[6],e=u[7];break;case"z":case"Z":t=s,e=i,d=["Z"]}d?(n.push(d),r=d[0]):r=""}return n},Du=(o,t,e,s)=>Math.sqrt((e-o)**2+(s-t)**2),Vb=(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 O(r*c+i*u+e*d+o*f,a*c+n*u+s*d+t*f)},Wb=o=>o**2,zb=o=>2*o*(1-o),Gb=o=>(1-o)**2,Mw=(o,t,e,s,i,n,r,a)=>h=>{const c=Wb(h),u=zb(h),d=Gb(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)},Ow=(o,t,e,s,i,n)=>r=>{const a=Wb(r),h=zb(r),c=Gb(r);return new O(i*a+e*h+o*c,n*a+s*h+t*c)},Dw=(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)},Xb=(o,t,e)=>{let s=new O(t,e),i=0;for(let n=1;n<=100;n+=1){const r=o(n/100);i+=Du(s.x,s.y,r.x,r.y),s=r}return i},Rw=(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=Du(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)})},ug=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=Du(i,n,c[1],c[2]),i=c[1],n=c[2];break;case"C":t=Vb(i,n,c[1],c[2],c[3],c[4],c[5],c[6]),e=u,e.iterator=t,e.angleFinder=Mw(i,n,c[1],c[2],c[3],c[4],c[5],c[6]),e.length=Xb(t,i,n),i=c[5],n=c[6];break;case"Q":t=Ow(i,n,c[1],c[2],c[3],c[4]),e=u,e.iterator=t,e.angleFinder=Dw(i,n,c[1],c[2],c[3],c[4]),e.length=Xb(t,i,n),i=c[3],n=c[4];break;case"Z":e=u,e.destX=r,e.destY=a,e.length=Du(i,n,r,a),i=r,n=a}s+=e.length,h.push(e)}return h.push({length:s,x:i,y:n}),h},Ub=function(o,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:ug(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 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 T(T({},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 Rw(i,t)}},Lw=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),Yb=new RegExp(Tw,"g"),Fw=new RegExp(Qs,"gi"),Iw={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},$b=o=>{var t;const e=[],s=(t=o.match(Lw))!==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=Iw[n.toLowerCase()];let a=[];if(n==="a"||n==="A"){Yb.lastIndex=0;for(let h=null;h=Yb.exec(i);)a.push(...h.slice(1))}else a=i.match(Fw)||[];for(let h=0;h<a.length;h+=r){const c=new Array(r),u=Ew[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 O(o[0]),s=new O(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},qb=(o,t)=>o.map(e=>e.map((s,i)=>i===0||t===void 0?s:Ft(s,t)).join(" ")).join(" ");function Ru(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 Nw=(o,t)=>Math.floor(Math.random()*(t-o+1))+o;function Kb(o){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const e=t.onComplete||Or,s=new(ru()).XMLHttpRequest,i=t.signal,n=function(){s.abort()},r=function(){i&&i.removeEventListener("abort",n),s.onerror=s.ontimeout=Or};if(i&&i.aborted)throw new Af("request");return i&&i.addEventListener("abort",n,{once:!0}),s.onreadystatechange=function(){s.readyState===4&&(r(),e(s),s.onreadystatechange=Or)},s.onerror=s.ontimeout=r,s.open("get",o,!0),s.send(),s}const Lu=(o,t)=>{let e=o._findCenterFromElement();o.transformMatrix&&((s=>{if(s.transformMatrix){const{scaleX:i,scaleY:n,angle:r,skewX:a}=Rr(s.transformMatrix);s.flipX=!1,s.flipY=!1,s.set(He,i),s.set(us,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,et,et)};var Bw=Object.freeze({__proto__:null,addTransformToObject:Gm,animate:eg,animateColor:cb,applyTransformToObject:fo,calcAngleBetweenVectors:wu,calcDimensionsMatrix:Gh,calcPlaneChangeMatrix:Kh,calcVectorRotation:ib,cancelAnimFrame:Tm,capValue:jr,composeMatrix:Om,copyCanvasElement:o=>{var t;const e=qs(o);return(t=e.getContext("2d"))===null||t===void 0||t.drawImage(o,0,0),e},cos:Ys,createCanvasElement:Ms,createImage:Em,createRotateMatrix:co,createScaleMatrix:fu,createSkewXMatrix:Ff,createSkewYMatrix:If,createTranslateMatrix:lo,createVector:vu,crossProduct:go,degreesToRadians:Gt,dotProduct:nb,ease:E_,enlivenObjectEnlivables:Uh,enlivenObjects:uo,findScaleToCover:Nb,findScaleToFit:jb,getBoundsOfCurve:cg,getOrthonormalVector:qf,getPathSegmentsInfo:ug,getPointOnPath:Ub,getPointer:zm,getRandomInt:Nw,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 O(Ys(r),$s(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:xu,groupSVGElements:(o,t)=>o&&o.length===1?o[0]:new Si(o,t),hasStyleChanged:Eu,invertTransform:ss,isBetweenVectors:Kf,isIdentityMatrix:km,isTouchEvent:pu,isTransparent:vb,joinPath:qb,loadImage:Xh,magnitude:_u,makeBoundingBoxFromPoints:wi,makePathSimpler:Hb,matrixToSVG:Yh,mergeClipPaths:(o,t)=>{var e;let s=o,i=t;s.inverted&&!i.inverted&&(s=t,i=o),zf(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 Si([s],{clipPath:i,inverted:n})},multiplyTransformMatrices:$t,multiplyTransformMatrixArray:du,parsePath:$b,parsePreserveAspectRatioAttribute:Bf,parseUnit:We,pick:Lr,projectStrokeOnPoints:xb,qrDecompose:Rr,radiansToDegrees:Gn,removeFromArray:Dr,removeTransformFromObject:(o,t)=>{const e=ss(t),s=$t(e,o.calcOwnMatrix());fo(o,s)},removeTransformMatrixForSvgParsing:Lu,request:Kb,requestAnimFrame:zh,resetObjectTransform:Xm,rotatePoint:(o,t,e)=>o.rotate(e,t),rotateVector:$f,saveObjectTransform:Wf,sendObjectToPlane:zf,sendPointToPlane:Ir,sendVectorToPlane:Um,setStyle:Ru,sin:$s,sizeAfterTransform:mu,string:ew,stylesFromArray:Ab,stylesToArray:Cb,toDataURL:Lf,toFixed:Ft,transformPath:(o,t,e)=>(e&&(t=$t(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}=Ae({x:s[n],y:s[n+1]},t);i[n]=r,i[n+1]=a}return i})),transformPoint:Ae});class Hw extends Wm{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=Ms();return e.className=t.className,e.classList.remove("lower-canvas"),e.classList.add("upper-canvas"),e.setAttribute("data-fabric","top"),e.style.cssText=t.style.cssText,e.setAttribute("draggable","true"),e}createContainerElement(){const t=ro().createElement("div");return t.setAttribute("data-fabric","wrapper"),Ru(t,{position:"relative"}),Vm(t),t}applyCanvasStyle(t,e){const{styles:s,allowTouchScrolling:i}=e;Ru(t,T(T({},s),{},{"touch-action":i?"manipulation":Be})),Vm(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:s,ctx:i}=this.upper;Hm(s,i,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),Hf(this.upper.el,t),Hf(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(),_i().dispose(this.upper.el),delete this.upper,delete this.container}}class Fu extends qh{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()),Fu.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 Hw(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 vb(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===hu||e===He||e===us||e===Wh?i=this.centeredScaling||t.centeredScaling:e===Of&&(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=Yt:["mr","tr","br"].includes(e)&&(s.x=vt),["tl","mt","tr"].includes(e)?s.y=Pf:["bl","mb","br"].includes(e)&&(s.y=es)),s}_setupCurrentTransform(t,e,s){var i;const n=e.group?Ir(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):v_,c=((g,p,b,_)=>{if(!p||!g)return"drag";const y=_.controls[p];return y.getActionName(b,y,_)})(s,r,t,e),u=t[this.centeredKey],d=this._shouldCenterTransform(e,c,u)?{x:et,y:et}: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:Gt(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 O(e,s).transform(this.viewportTransform),a=new O(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,Te.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,pu(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=Ys(u)*n,f=$s(u)*n,g=d+f,p=d-f;s=[new O(r.x-p,r.y-g),new O(a.x+g,a.y-p),new O(h.x+p,h.y+g),new O(c.x-g,c.y+p)]}return Bt.isPointInPolygon(e,s)}_checkTarget(t,e){return!!(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,Ir(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(uu(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&&uu(s)&&s.interactive&&this.targets[0]){const i=this.targets;for(let n=i.length-1;n>0;n--){const r=i[n];if(!uu(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=zm(t),r=i.width||0,a=i.height||0;r&&a||(es in i&&Pf in i&&(a=Math.abs(i.top-i.bottom)),Yt in i&&vt 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=Ir(n,void 0,this.viewportTransform));const h=this.getRetinaScaling();h!==1&&(n.x/=h,n.y/=h);const c=r===0||a===0?new O(1,1):new O(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=Ms(),this.pixelFindContext=this.pixelFindCanvasEl.getContext("2d",{willReadFrequently:!0}),this.setTargetFindTolerance(this.targetFindTolerance)}getTopContext(){return this.elements.upper.ctx}getSelectionContext(){return this.elements.upper.ctx}getSelectionElement(){return this.elements.upper.el}getActiveObject(){return this._activeObject}getActiveObjects(){const t=this._activeObject;return Fr(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,Fr(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),Fr(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(lu,i))}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeObject;Fr(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&&Fr(e)&&this._activeObject===e){const s=Lr(t,["angle","flipX","flipY",vt,He,us,ao,oo,es]);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(Fu,"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 Vw{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),Dr(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 Ww=["target","oldTarget","fireCanvas","e"],ds={passive:!1},vo=(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)},Ds=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)},zw={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 dg extends Fu{constructor(t){super(t,arguments.length>1&&arguments[1]!==void 0?arguments[1]:{}),E(this,"_isClick",void 0),E(this,"textEditingManager",new Vw(this)),["_onMouseDown","_onTouchStart","_onMouseMove","_onMouseUp","_onTouchEnd","_onResize","_onMouseWheel","_onMouseOut","_onMouseEnter","_onContextMenu","_onDoubleClick","_onDragStart","_onDragEnd","_onDragProgress","_onDragOver","_onDragEnter","_onDragLeave","_onDrop"].forEach(e=>{this[e]=this[e].bind(this)}),this.addOrRemove(Un,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const s=this.upperCanvasEl,i=this._getEventPrefix();t(Bm(s),"resize",this._onResize),t(s,i+"down",this._onMouseDown),t(s,"".concat(i,"move"),this._onMouseMove,ds),t(s,"".concat(i,"out"),this._onMouseOut),t(s,"".concat(i,"enter"),this._onMouseEnter),t(s,"wheel",this._onMouseWheel),t(s,"contextmenu",this._onContextMenu),t(s,"dblclick",this._onDoubleClick),t(s,"dragstart",this._onDragStart),t(s,"dragend",this._onDragEnd),t(s,"dragover",this._onDragOver),t(s,"dragenter",this._onDragEnter),t(s,"dragleave",this._onDragLeave),t(s,"drop",this._onDrop),this.enablePointerEvents||t(s,"touchstart",this._onTouchStart,ds)}removeListeners(){this.addOrRemove(Ds,"remove");const t=this._getEventPrefix(),e=Ks(this.upperCanvasEl);Ds(e,"".concat(t,"up"),this._onMouseUp),Ds(e,"touchend",this._onTouchEnd,ds),Ds(e,"".concat(t,"move"),this._onMouseMove,ds),Ds(e,"touchmove",this._onMouseMove,ds),clearTimeout(this._willAddMouseDown)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s=T({e:t},vo(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},vo(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)}Vf(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!==Be,s=e?this._activeObject:void 0,i={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:s};Ds(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},vo(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&&Vf(t),this._basicEventHandler("contextmenu",i),!1}_onDoubleClick(t){this._cacheTransformEventData(t),this._handleEvent(t,"dblclick"),this._resetTransformEventData()}getPointerId(t){const e=t.changedTouches;return e?e[0]&&e[0].identifier:this.enablePointerEvents?t.pointerId:-1}_isMainEvent(t){return t.isPrimary===!0||t.isPrimary!==!1&&(t.type==="touchend"&&t.touches.length===0||!t.changedTouches||t.changedTouches[0].identifier===this.mainTouchId)}_onTouchStart(t){let e=!this.allowTouchScrolling;const s=this._activeObject;this.mainTouchId===void 0&&(this.mainTouchId=this.getPointerId(t)),this.__onMouseDown(t),(this.isDrawingMode||s&&this._target===s)&&(e=!0),e&&t.preventDefault(),this._resetTransformEventData();const i=this.upperCanvasEl,n=this._getEventPrefix(),r=Ks(i);Un(r,"touchend",this._onTouchEnd,ds),e&&Un(r,"touchmove",this._onMouseMove,ds),Ds(i,"".concat(n,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();Ds(e,"".concat(s,"move"),this._onMouseMove,ds);const i=Ks(e);Un(i,"".concat(s,"up"),this._onMouseUp),Un(i,"".concat(s,"move"),this._onMouseMove,ds)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),s=Ks(this.upperCanvasEl);Ds(s,"touchend",this._onTouchEnd,ds),Ds(s,"touchmove",this._onMouseMove,ds),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=Ks(this.upperCanvasEl);Ds(i,"".concat(s,"up"),this._onMouseUp),Ds(i,"".concat(s,"move"),this._onMouseMove,ds),Un(e,"".concat(s,"move"),this._onMouseMove,ds)}}_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),pu(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){const s=this._target,i=this.targets||[],n=T(T({e:t,target:s,subTargets:i},vo(this,t)),{},{transform:this._currentTransform},e==="up:before"||e==="up"?{isClick:this._isClick,currentTarget:this.findTarget(t),currentSubTargets:this.targets}:{});this.fire("mouse:".concat(e),n),s&&s.fire("mouse".concat(e),n);for(let r=0;r<i.length;r++)i[r]!==s&&i[r].fire("mouse".concat(e),n)}_onMouseDownInDrawingMode(t){this._isCurrentlyDrawing=!0,this.getActiveObject()&&(this.discardActiveObject(t),this.requestRenderAll());const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseDown(e,{e:t,pointer:e}),this._handleEvent(t,"down")}_onMouseMoveInDrawingMode(t){if(this._isCurrentlyDrawing){const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseMove(e,{e:t,pointer:e})}this.setCursor(this.freeDrawingCursor),this._handleEvent(t,"move")}_onMouseUpInDrawingMode(t){const e=this.getScenePoint(t);this.freeDrawingBrush?this._isCurrentlyDrawing=!!this.freeDrawingBrush.onMouseUp({e:t,pointer:e}):this._isCurrentlyDrawing=!1,this._handleEvent(t,"up")}__onMouseDown(t){this._isClick=!0,this._cacheTransformEventData(t),this._handleEvent(t,"down:before");let e=this._target;const{button:s}=t;if(s)return(this.fireMiddleClick&&s===1||this.fireRightClick&&s===2)&&this._handleEvent(t,"down"),void this._resetTransformEventData();if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t)||this._currentTransform)return;let i=this._shouldRender(e),n=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,n=!0,i=!0):this._shouldClearSelection(t,e)&&this.discardActiveObject(t),this.selection&&(!e||!e.selectable&&!e.isEditing&&e!==this._activeObject)){const r=this.getScenePoint(t);this._groupSelector={x:r.x,y:r.y,deltaY:0,deltaX:0}}if(e){const r=e===this._activeObject;e.selectable&&e.activeOn==="down"&&this.setActiveObject(e,t);const a=e.findControl(this.getViewportPoint(t),pu(t));if(e===this._activeObject&&(a||!n)){this._setupCurrentTransform(t,e,r);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)}}i&&(this._objectsToRender=void 0),this._handleEvent(t,"down"),i&&this.requestRenderAll()}_resetTransformEventData(){this._target=this._pointer=this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getViewportPoint(t),this._absolutePointer=Ir(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,Ww);const{targetIn:h,targetOut:c,canvasIn:u,canvasOut:d}=zw[t],f=i!==s;if(i&&f){const g=T(T({},a),{},{e:r,target:i,nextTarget:s},vo(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},vo(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?Ir(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=Fr(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=Fr(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(V.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),a=r.add(new O(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=V.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 Jb={x1:0,y1:0,x2:0,y2:0},Gw=T(T({},Jb),{},{r1:0,r2:0}),_o=(o,t)=>isNaN(o)&&typeof t=="number"?t:o,Xw=/^(\d+\.\d+)%|(\d+)%$/;function Qb(o){return o&&Xw.test(o)}function Zb(o,t){const e=typeof o=="number"?o:typeof o=="string"?parseFloat(o)/(Qb(o)?100:1):NaN;return jr(0,_o(e,t),1)}const Uw=/\s*;\s*/,Yw=/\s*:\s*/;function $w(o,t){let e,s;const i=o.getAttribute("style");if(i){const r=i.split(Uw);r[r.length-1]===""&&r.pop();for(let a=r.length;a--;){const[h,c]=r[a].split(Yw).map(u=>u.trim());h==="stop-color"?e=c:h==="stop-opacity"&&(s=c)}}const n=new wt(e||o.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:Zb(o.getAttribute("offset"),0),color:n.toRgb(),opacity:_o(parseFloat(s||o.getAttribute("stop-opacity")||""),1)*n.getAlpha()*t}}function qw(o,t){const e=[],s=o.getElementsByTagName("stop"),i=Zb(t,1);for(let n=s.length;n--;)e.push($w(s[n],i));return e}function ty(o){return o.nodeName==="linearGradient"||o.nodeName==="LINEARGRADIENT"?"linear":"radial"}function ey(o){return o.getAttribute("gradientUnits")==="userSpaceOnUse"?"pixels":"percentage"}function ti(o,t){return o.getAttribute(t)}function Kw(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"&&Qb(u)&&(i*=.01,a==="pixels"&&(c!=="x1"&&c!=="x2"&&c!=="r2"||(i*=n),c!=="y1"&&c!=="y2"||(i*=r)))),h[c]=i,h},{})}(ty(o)==="linear"?function(e){return{x1:ti(e,"x1")||0,y1:ti(e,"y1")||0,x2:ti(e,"x2")||"100%",y2:ti(e,"y2")||0}}(o):function(e){return{x1:ti(e,"fx")||ti(e,"cx")||"50%",y1:ti(e,"fy")||ti(e,"cy")||"50%",r1:0,x2:ti(e,"cx")||"50%",y2:ti(e,"cy")||"50%",r2:ti(e,"r")||"50%"}}(o),T(T({},t),{},{gradientUnits:ey(o)}))}class el{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"?Gw:Jb),i),colorStops:n,offsetX:r,offsetY:a,gradientTransform:h,id:c?"".concat(c,"_").concat(zn()):zn()})}addColorStop(t){for(const e in t){const s=new wt(t[e]);this.colorStops.push({offset:parseFloat(e),color:s.toRgb(),opacity:s.getAlpha()})}return this}toObject(t){return T(T({},Lr(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():Ne.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(Yh(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
|
+
`)}else if(this.type==="radial"){const{x1:d,y1:f,x2:g,y2:p,r1:b,r2:_}=this.coords,y=b>_;s.push("<radialGradient ",u,' cx="',y?d:g,'" cy="',y?f:p,'" r="',y?b:_,'" fx="',y?g:d,'" fy="',y?p:f,`">
|
|
72
|
+
`),y&&(r.reverse(),r.forEach(C=>{C.offset=1-C.offset}));const x=Math.min(b,_);if(x>0){const C=x/Math.max(b,_);r.forEach(A=>{A.offset+=C*(1-A.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:
|
|
75
|
-
`)}static async fromObject(t,e){let{type:s,source:i,patternTransform:n}=t,r=
|
|
76
|
-
`)]}_getOffsetTransform(){const t=
|
|
77
|
-
`];{const{radius:e}=this,s=
|
|
78
|
-
`]}}static async fromElement(t,e,s){const i=
|
|
79
|
-
`)]}static async fromElement(t,e,s){const i=
|
|
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
|
|
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(
|
|
82
|
-
`)}const Nw=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let Yg;class Ae extends V0{static getDefaults(){return T(T({},super.getDefaults()),Ae.ownDefaults)}constructor(t,e){super(),E(this,"__charBounds",[]),Object.assign(this,Ae.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(xi)&&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===xi||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===Ne?(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 tt:t.textBaseline="middle";break;case"ascender":t.textBaseline=Qe;break;case"descender":t.textBaseline=og}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,g=0,f=0,p=this.getValueOfPropertyAt(n,0,"textBackgroundColor");for(let m=0;m<h;m++){const w=this.__charBounds[n][m];d=this.getValueOfPropertyAt(n,m,"textBackgroundColor"),this.path?(t.save(),t.translate(w.renderLeft,w.renderTop),t.rotate(w.angle),t.fillStyle=d,d&&t.fillRect(-w.width/2,-o/this.lineHeight*(1-this._fontSizeFraction),w.width,o/this.lineHeight),t.restore()):d!==p?(u=s+c+f,this.direction==="rtl"&&(u=this.width-u-g),t.fillStyle=p,p&&t.fillRect(u,i,g,o/this.lineHeight),f=w.left,g=w.width,p=d):g+=w.kernedWidth}d&&!this.path&&(u=s+c+f,this.direction==="rtl"&&(u=this.width-u-g),t.fillStyle=d,t.fillRect(u,i,g,o/this.lineHeight)),i+=o}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,s,i){const n=Eh.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,g,f;if(s&&n[s]!==void 0&&(g=n[s]),n[t]!==void 0&&(f=u=n[t]),h&&n[o]!==void 0&&(d=n[o],f=d-g),u===void 0||g===void 0||d===void 0){const p=function(){return Yg||(Yg=Us({width:0,height:0}).getContext("2d")),Yg}();this._setTextStyles(p,e,!0),u===void 0&&(f=u=p.measureText(t).width,n[t]=u),g===void 0&&h&&s&&(g=p.measureText(s).width,n[s]=g),h&&d===void 0&&(d=p.measureText(o).width,n[o]=d,f=d-g)}return{width:u*c,kernedWidth:f*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===Ut,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 vt:u=n?d-i:0;break;case tt:u=(d-i)/2;break;case Ut:u=n?0:d-i}u+=this.pathStartOffset*(n?-1:1);for(let g=n?h-1:0;n?g>=0:g<h;n?g--:g++)s=c[g],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=C0(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===Ut?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 g={width:d,left:0,height:r.fontSize,kernedWidth:u,deltaY:r.deltaY};if(s>0&&!n){const f=this.__charBounds[e][s-1];g.left=f.left+f.width+h.kernedWidth-h.width}return g}getHeightOfLine(t){if(this.__lineHeights[t])return this.__lineHeights[t];let e=this.getHeightOfChar(t,0);for(let s=1,i=this._textLines[t].length;s<i;s++)e=Math.max(this.getHeightOfChar(t,s),e);return this.__lineHeights[t]=e*this.lineHeight*this._fontSizeMult}calcTextHeight(){let t,e=0;for(let s=0,i=this._textLines.length;s<i;s++)t=this.getHeightOfLine(s),e+=s===i-1?t/this.lineHeight:t;return e}_getLeftOffset(){return this.direction==="ltr"?-this.width/2:this.width/2}_getTopOffset(){return-this.height/2}_renderTextCommon(t,e){t.save();let s=0;const i=this._getLeftOffset(),n=this._getTopOffset();for(let r=0,o=this._textLines.length;r<o;r++){const h=this.getHeightOfLine(r),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(Qt))&&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(xi),c=this.path,u=!h&&this.charSpacing===0&&this.isEmptyStyles(r)&&!c,d=this.direction==="ltr",g=this.direction==="ltr"?1:-1,f=e.direction;let p,m,w,b,x,C="",A=0;if(e.save(),f!==this.direction&&(e.canvas.setAttribute("dir",d?"ltr":"rtl"),e.direction=d?"ltr":"rtl",e.textAlign=d?vt:Ut),n-=o*this._fontSizeFraction/this.lineHeight,u)return this._renderChar(t,e,r,0,s.join(""),i,n),void e.restore();for(let P=0,D=s.length-1;P<=D;P++)b=P===D||this.charSpacing||c,C+=s[P],w=this.__charBounds[r][P],A===0?(i+=g*(w.kernedWidth-w.width),A+=w.width):A+=w.kernedWidth,h&&!b&&this._reSpaceAndTab.test(s[P])&&(b=!0),b||(p=p||this.getCompleteStyleDeclaration(r,P),m=this.getCompleteStyleDeclaration(r,P+1),b=au(p,m,!1)),b&&(c?(e.save(),e.translate(w.renderLeft,w.renderTop),e.rotate(w.angle),this._renderChar(t,e,r,P,C,-A/2,0),e.restore()):(x=i,this._renderChar(t,e,r,P,C,x,n)),C="",p=m,i+=g*A,A=0);e.restore()}_applyPatternGradientTransformText(t){const e=this.width+this.strokeWidth,s=this.height+this.strokeWidth,i=Us({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 As(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 g=this._setFillStyles(e,c);e.fillText(n,r-g.offsetX,o-g.offsetY)}if(d){const g=this._setStrokeStyles(e,c);e.strokeText(n,r-g.offsetX,o-g.offsetY)}e.restore()}}setSuperscript(t,e){this._setScript(t,e,this.superscript)}setSubscript(t,e){this._setScript(t,e,this.subscript)}_setScript(t,e,s){const i=this.get2DCursorLocation(t,!0),n=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"fontSize"),r=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"deltaY"),o={fontSize:n*s.size,deltaY:r+n*s.baseline};this.setSelectionStyles(o,t,e)}_getLineLeftOffset(t){const e=this.getLineWidth(t),s=this.width-e,i=this.textAlign,n=this.direction,r=this.isEndOfWrapping(t);let o=0;return i===xi||i===Wh&&!r||i===Gh&&!r||i===vu&&!r?0:(i===tt&&(o=s/2),i===Ut&&(o=s),i===Wh&&(o=s/2),i===Gh&&(o=s),n==="rtl"&&(i===Ut||i===xi||i===Gh?o=0:i===vt||i===vu?o=-s:i!==tt&&i!==Wh||(o=-s/2)),o)}_clearCache(){this._forceClearCache=!1,this.__lineWidths=[],this.__lineHeights=[],this.__charBounds=[]}getLineWidth(t){if(this.__lineWidths[t]!==void 0)return this.__lineWidths[t];const{width:e}=this.measureLine(t);return this.__lineWidths[t]=e,e}_getWidthOfCharSpacing(){return this.charSpacing!==0?this.fontSize*this.charSpacing/1e3:0}getValueOfPropertyAt(t,e,s){var i;return(i=this._getStyleDeclaration(t,e)[s])!==null&&i!==void 0?i:this[s]}_renderTextDecoration(t,e){if(!this[e]&&!this.styleHas(e))return;let s=this._getTopOffset();const i=this._getLeftOffset(),n=this.path,r=this._getWidthOfCharSpacing(),o=this.offsets[e];for(let h=0,c=this._textLines.length;h<c;h++){const u=this.getHeightOfLine(h);if(!this[e]&&!this.styleHas(e,h)){s+=u;continue}const d=this._textLines[h],g=u/this.lineHeight,f=this._getLineLeftOffset(h);let p,m,w=0,b=0,x=this.getValueOfPropertyAt(h,0,e),C=this.getValueOfPropertyAt(h,0,Qt);const A=s+g*(1-this._fontSizeFraction);let P=this.getHeightOfChar(h,0),D=this.getValueOfPropertyAt(h,0,"deltaY");for(let M=0,R=d.length;M<R;M++){const F=this.__charBounds[h][M];p=this.getValueOfPropertyAt(h,M,e),m=this.getValueOfPropertyAt(h,M,Qt);const I=this.getHeightOfChar(h,M),X=this.getValueOfPropertyAt(h,M,"deltaY");if(n&&p&&m)t.save(),t.fillStyle=C,t.translate(F.renderLeft,F.renderTop),t.rotate(F.angle),t.fillRect(-F.kernedWidth/2,o*I+X,F.kernedWidth,this.fontSize/15),t.restore();else if((p!==x||m!==C||I!==P||X!==D)&&b>0){let j=i+f+w;this.direction==="rtl"&&(j=this.width-j-b),x&&C&&(t.fillStyle=C,t.fillRect(j,A+o*P+D,b,this.fontSize/15)),w=F.left,b=F.width,x=p,C=m,P=I,D=X}else b+=F.kernedWidth}let k=i+f+w;this.direction==="rtl"&&(k=this.width-k-b),t.fillStyle=m,p&&m&&t.fillRect(k,A+o*P+D,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(",")||Ae.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 T(T({},super.toObject([...
|
|
84
|
-
`]}_getSVGTextAndBg(a,t){const e=[],s=[];let i,n=a;this.backgroundColor&&s.push(...Ug(this.backgroundColor,-this.width/2,-this.height/2,this.width,this.height));for(let r=0,o=this._textLines.length;r<o;r++)i=this._getLineLeftOffset(r),this.direction==="rtl"&&(i+=this.width),(this.textBackgroundColor||this.styleHas("textBackgroundColor",r))&&this._setSVGTextLineBg(s,r,t+i,n),this._setSVGTextLineText(e,r,t+i,n),n+=this.getHeightOfLine(r);return{textSpans:e,textBgRects:s}}_createTextCharSpan(a,t,e,s){const i=this.getSvgSpanStyles(t,a!==a.trim()||!!a.match(Iw)),n=i?'style="'.concat(i,'"'):"",r=t.deltaY,o=r?' dy="'.concat(Rt(r,ft.NUM_FRACTION_DIGITS),'" '):"";return'<tspan x="'.concat(Rt(e,ft.NUM_FRACTION_DIGITS),'" y="').concat(Rt(s,ft.NUM_FRACTION_DIGITS),'" ').concat(o).concat(n,">").concat(e0(a),"</tspan>")}_setSVGTextLineText(a,t,e,s){const i=this.getHeightOfLine(t),n=this.textAlign.includes(xi),r=this._textLines[t];let o,h,c,u,d,g="",f=0;s+=i*(1-this._fontSizeFraction)/this.lineHeight;for(let p=0,m=r.length-1;p<=m;p++)d=p===m||this.charSpacing,g+=r[p],c=this.__charBounds[t][p],f===0?(e+=c.kernedWidth-c.width,f+=c.width):f+=c.kernedWidth,n&&!d&&this._reSpaceAndTab.test(r[p])&&(d=!0),d||(o=o||this.getCompleteStyleDeclaration(t,p),h=this.getCompleteStyleDeclaration(t,p+1),d=au(o,h,!0)),d&&(u=this._getStyleDeclaration(t,p),a.push(this._createTextCharSpan(g,u,e,s)),g="",o=h,this.direction==="rtl"?e-=f:e+=f,f=0)}_setSVGTextLineBg(a,t,e,s){const i=this._textLines[t],n=this.getHeightOfLine(t)/this.lineHeight;let r,o=0,h=0,c=this.getValueOfPropertyAt(t,0,"textBackgroundColor");for(let u=0;u<i.length;u++){const{left:d,width:g,kernedWidth:f}=this.__charBounds[t][u];r=this.getValueOfPropertyAt(t,u,"textBackgroundColor"),r!==c?(c&&a.push(...Ug(c,e+h,s,o,n)),h=d,o=g,c=r):o+=f}r&&a.push(...Ug(c,e+h,s,o,n))}_getSVGLineTopOffset(a){let t,e=0;for(t=0;t<a;t++)e+=this.getHeightOfLine(t);const s=this.getHeightOfLine(t);return{lineTop:e,offset:(this._fontSizeMult-this._fontSizeFraction)*s/(this.lineHeight*this._fontSizeMult)}}getSvgStyles(a){return"".concat(super.getSvgStyles(a)," white-space: pre;")}getSvgSpanStyles(a,t){const{fontFamily:e,strokeWidth:s,stroke:i,fill:n,fontSize:r,fontStyle:o,fontWeight:h,deltaY:c}=a,u=this.getSvgTextDecoration(a);return[i?Lh(Ne,i):"",s?"stroke-width: ".concat(s,"; "):"",e?"font-family: ".concat(e.includes("'")||e.includes('"')?e:"'".concat(e,"'"),"; "):"",r?"font-size: ".concat(r,"px; "):"",o?"font-style: ".concat(o,"; "):"",h?"font-weight: ".concat(h,"; "):"",u&&"text-decoration: ".concat(u,"; "),n?Lh(Qt,n):"",c?"baseline-shift: ".concat(-c,"; "):"",t?"white-space: pre; ":""].join("")}getSvgTextDecoration(a){return["overline","underline","line-through"].filter(t=>a[t.replace("-","")]).join(" ")}}]),W.setClass(Ae),W.setSVGClass(Ae);class Bw{constructor(t){E(this,"target",void 0),E(this,"__mouseDownInPlace",!1),E(this,"__dragStartFired",!1),E(this,"__isDraggingOver",!1),E(this,"__dragStartSelection",void 0),E(this,"__dragImageDisposer",void 0),E(this,"_dispose",void 0),this.target=t;const e=[this.target.on("dragenter",this.dragEnterHandler.bind(this)),this.target.on("dragover",this.dragOverHandler.bind(this)),this.target.on("dragleave",this.dragLeaveHandler.bind(this)),this.target.on("dragend",this.dragEndHandler.bind(this)),this.target.on("drop",this.dropHandler.bind(this))];this._dispose=()=>{e.forEach(s=>s()),this._dispose=void 0}}isPointerOverSelection(t){const e=this.target,s=e.getSelectionStartFromPointer(t);return e.isEditing&&s>=e.selectionStart&&s<=e.selectionEnd&&e.selectionStart<e.selectionEnd}start(t){return this.__mouseDownInPlace=this.isPointerOverSelection(t)}isActive(){return this.__mouseDownInPlace}end(t){const e=this.isActive();return e&&!this.__dragStartFired&&(this.target.setCursorByClick(t),this.target.initDelayedCursor(!0)),this.__mouseDownInPlace=!1,this.__dragStartFired=!1,this.__isDraggingOver=!1,e}getDragStartSelection(){return this.__dragStartSelection}setDragImage(t,e){var s;let{selectionStart:i,selectionEnd:n}=e;const r=this.target,o=r.canvas,h=new 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),g=r.getCanvasRetinaScaling(),f=r.getBoundingRect(),p=u.subtract(new O(f.left,f.top)),m=o.viewportTransform,w=p.add(d).transform(m,!0),b=r.backgroundColor,x=Fg(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 A=r.toCanvasElement({enableRetinaScaling:o.enableRetinaScaling,viewportTransform:!0});r.backgroundColor=b,r.styles=x,r.dirty=!0,gu(A,{position:"fixed",left:"".concat(-A.width,"px"),border:Ie,width:"".concat(A.width/g,"px"),height:"".concat(A.height/g,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{A.remove()},Ys(t.target||this.target.hiddenTextarea).body.appendChild(A),(s=t.dataTransfer)===null||s===void 0||s.setDragImage(A,w.x,w.y)}onDragStart(t){this.__dragStartFired=!0;const e=this.target,s=this.isActive();if(s&&t.dataTransfer){const i=this.__dragStartSelection={selectionStart:e.selectionStart,selectionEnd:e.selectionEnd},n=e._text.slice(i.selectionStart,i.selectionEnd).join(""),r=T({text:e.text,value:n},i);t.dataTransfer.setData("text/plain",n),t.dataTransfer.setData("application/fabric",JSON.stringify({value:n,styles:e.getSelectionStyles(i.selectionStart,i.selectionEnd,!0)})),t.dataTransfer.effectAllowed="copyMove",this.setDragImage(t,r)}return e.abortCursorAnimation(),s}canDrop(t){if(this.target.editable&&!this.target.getActiveControl()&&!t.defaultPrevented){if(this.isActive()&&this.__dragStartSelection){const e=this.target.getSelectionStartFromPointer(t),s=this.__dragStartSelection;return e<s.selectionStart||e>s.selectionEnd}return!0}return!1}targetCanDrop(t){return this.target.canDrop(t)}dragEnterHandler(t){let{e}=t;const s=this.targetCanDrop(e);!this.__isDraggingOver&&s&&(this.__isDraggingOver=!0)}dragOverHandler(t){const{e}=t,s=this.targetCanDrop(e);!this.__isDraggingOver&&s?this.__isDraggingOver=!0:this.__isDraggingOver&&!s&&(this.__isDraggingOver=!1),this.__isDraggingOver&&(e.preventDefault(),t.canDrop=!0,t.dropTarget=this.target)}dragLeaveHandler(){(this.__isDraggingOver||this.isActive())&&(this.__isDraggingOver=!1)}dropHandler(t){var e;const{e:s}=t,i=s.defaultPrevented;this.__isDraggingOver=!1,s.preventDefault();let n=(e=s.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain");if(n&&!i){const r=this.target,o=r.canvas;let h=r.getSelectionStartFromPointer(s);const{styles: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 g=this.__dragStartSelection.selectionStart,f=this.__dragStartSelection.selectionEnd;h>g&&h<=f?h=g:h>f&&(h-=f-g),r.removeChars(g,f),delete this.__dragStartSelection}r._reNewline.test(u)&&(r._reNewline.test(r._text[h])||h===r._text.length)&&(n=n.trimEnd()),t.didDrop=!0,t.dropTarget=r,r.insertChars(n,c,h),o.setActiveObject(r),r.enterEditing(s),r.selectionStart=Math.min(h+d,r._text.length),r.selectionEnd=Math.min(r.selectionStart+n.length,r._text.length),r.hiddenTextarea.value=r.text,r._updateTextarea(),r.hiddenTextarea.focus(),r.fire(Vc,{index:h+d,action:"drop"}),o.fire("text:changed",{target:r}),o.contextTopDirty=!0,o.requestRenderAll()}}dragEndHandler(t){let{e}=t;if(this.isActive()&&this.__dragStartFired&&this.__dragStartSelection){var s;const i=this.target,n=this.target.canvas,{selectionStart:r,selectionEnd:o}=this.__dragStartSelection,h=((s=e.dataTransfer)===null||s===void 0?void 0:s.dropEffect)||Ie;h===Ie?(i.selectionStart=r,i.selectionEnd=o,i._updateTextarea(),i.hiddenTextarea.focus()):(i.clearContextTop(),h==="move"&&(i.removeChars(r,o),i.selectionStart=i.selectionEnd=r,i.hiddenTextarea&&(i.hiddenTextarea.value=i.text),i._updateTextarea(),i.fire(Vc,{index:r,action:"dragend"}),n.fire("text:changed",{target:i}),n.requestRenderAll()),i.exitEditing())}this.__dragImageDisposer&&this.__dragImageDisposer(),delete this.__dragImageDisposer,delete this.__dragStartSelection,this.__isDraggingOver=!1}dispose(){this._dispose&&this._dispose()}}const G0=/[ \n\.,;!\?\-]/;class Hw extends Ae{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 Dg({startValue:this._currentCursorOpacity,endValue:e,duration:s,delay:i,onComplete:n,abort:()=>!this.canvas||this.selectionStart!==this.selectionEnd,onChange:r=>{this._currentCursorOpacity=r,this.renderCursorOrSelection()}})}_tick(t){this._currentTickState=this._animateCursor({toValue:0,duration:this.cursorDuration/2,delay:Math.max(t||0,100),onComplete:this._onTickComplete})}_onTickComplete(){var t;(t=this._currentTickCompleteState)===null||t===void 0||t.abort(),this._currentTickCompleteState=this._animateCursor({toValue:1,duration:this.cursorDuration,onComplete:this._tick})}initDelayedCursor(t){this.abortCursorAnimation(),this._tick(t?0:this.cursorDelay)}abortCursorAnimation(){let t=!1;[this._currentTickState,this._currentTickCompleteState].forEach(e=>{e&&!e.isDone()&&(t=!0,e.abort())}),this._currentCursorOpacity=1,t&&this.clearContextTop()}restartCursorIfNeeded(){[this._currentTickState,this._currentTickCompleteState].some(t=>!t||t.isDone())&&this.initDelayedCursor()}selectAll(){return this.selectionStart=0,this.selectionEnd=this._text.length,this._fireSelectionChanged(),this._updateTextarea(),this}getSelectedText(){return this._text.slice(this.selectionStart,this.selectionEnd).join("")}findWordBoundaryLeft(t){let e=0,s=t-1;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s--;for(;/\S/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findWordBoundaryRight(t){let e=0,s=t;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s++;for(;/\S/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}findLineBoundaryLeft(t){let e=0,s=t-1;for(;!/\n/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findLineBoundaryRight(t){let e=0,s=t;for(;!/\n/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}searchWordBoundary(t,e){const s=this._text;let i=t>0&&this._reSpace.test(s[t])&&(e===-1||!ag.test(s[t-1]))?t-1:t,n=s[i];for(;i>0&&i<s.length&&!G0.test(n);)i+=e,n=s[i];return e===-1&&G0.test(n)&&i++,i}selectWord(t){t=t||this.selectionStart;const e=this.searchWordBoundary(t,-1),s=Math.max(e,this.searchWordBoundary(t,1));this.selectionStart=e,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(t){t=t||this.selectionStart;const e=this.findLineBoundaryLeft(t),s=this.findLineBoundaryRight(t);return this.selectionStart=e,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea(),this}enterEditing(t){!this.isEditing&&this.editable&&(this.enterEditingImpl(),this.fire("editing:entered",t?{e:t}:void 0),this._fireSelectionChanged(),this.canvas&&(this.canvas.fire("text:editing:entered",{target:this,e:t}),this.canvas.requestRenderAll()))}enterEditingImpl(){this.canvas&&(this.canvas.calcOffset(),this.canvas.textEditingManager.exitTextEditing()),this.isEditing=!0,this.initHiddenTextarea(),this.hiddenTextarea.focus(),this.hiddenTextarea.value=this.text,this._updateTextarea(),this._saveEditingProps(),this._setEditingProps(),this._textBeforeEdit=this.text,this._tick()}updateSelectionOnMouseMove(t){if(this.getActiveControl())return;const e=this.hiddenTextarea;Ys(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,g=u-r,f=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>g&&(p.x=g),p.y<0&&(p.y=0),p.y>f&&(p.y=f),p.x+=this.canvas._offset.left,p.y+=this.canvas._offset.top,{left:"".concat(p.x,"px"),top:"".concat(p.y,"px"),fontSize:"".concat(r,"px"),charHeight:r}}_saveEditingProps(){this._savedProps={hasControls:this.hasControls,borderColor:this.borderColor,lockMovementX:this.lockMovementX,lockMovementY:this.lockMovementY,hoverCursor:this.hoverCursor,selectable:this.selectable,defaultCursor:this.canvas&&this.canvas.defaultCursor,moveCursor:this.canvas&&this.canvas.moveCursor}}_restoreEditingProps(){this._savedProps&&(this.hoverCursor=this._savedProps.hoverCursor,this.hasControls=this._savedProps.hasControls,this.borderColor=this._savedProps.borderColor,this.selectable=this._savedProps.selectable,this.lockMovementX=this._savedProps.lockMovementX,this.lockMovementY=this._savedProps.lockMovementY,this.canvas&&(this.canvas.defaultCursor=this._savedProps.defaultCursor||this.canvas.defaultCursor,this.canvas.moveCursor=this._savedProps.moveCursor||this.canvas.moveCursor),delete this._savedProps)}_exitEditing(){const t=this.hiddenTextarea;this.selected=!1,this.isEditing=!1,t&&(t.blur&&t.blur(),t.parentNode&&t.parentNode.removeChild(t)),this.hiddenTextarea=null,this.abortCursorAnimation(),this.selectionStart!==this.selectionEnd&&this.clearContextTop()}exitEditingImpl(){this._exitEditing(),this.selectionEnd=this.selectionStart,this._restoreEditingProps(),this._forceClearCache&&(this.initDimensions(),this.setCoords())}exitEditing(){const t=this._textBeforeEdit!==this.text;return this.exitEditingImpl(),this.fire("editing:exited"),t&&this.fire(Wc),this.canvas&&(this.canvas.fire("text:editing:exited",{target:this}),t&&this.canvas.fire("object:modified",{target:this})),this}_removeExtraneousStyles(){for(const t in this.styles)this._textLines[t]||delete this.styles[t]}removeStyleFromTo(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t,!0),{lineIndex:n,charIndex:r}=this.get2DCursorLocation(e,!0);if(s!==n){if(this.styles[s])for(let o=i;o<this._unwrappedTextLines[s].length;o++)delete this.styles[s][o];if(this.styles[n])for(let o=r;o<this._unwrappedTextLines[n].length;o++){const h=this.styles[n][o];h&&(this.styles[s]||(this.styles[s]={}),this.styles[s][i+o-r]=h)}for(let o=s+1;o<=n;o++)delete this.styles[o];this.shiftLineStyles(n,s-n)}else if(this.styles[s]){const o=this.styles[s],h=r-i;for(let c=i;c<r;c++)delete o[c];for(const c in this.styles[s]){const u=parseInt(c,10);u>=r&&(o[u-h]=o[c],delete o[c])}}}shiftLineStyles(t,e){const s=Object.assign({},this.styles);for(const i in this.styles){const n=parseInt(i,10);n>t&&(this.styles[n+e]=s[n],s[n-e]||delete this.styles[n])}}insertNewlineStyleObject(t,e,s,i){const n={},r=this._unwrappedTextLines[t].length,o=r===e;let h=!1;s||(s=1),this.shiftLineStyles(t,s);const c=this.styles[t]?this.styles[t][e===0?e:e-1]:void 0;for(const d in this.styles[t]){const g=parseInt(d,10);g>=e&&(h=!0,n[g-e]=this.styles[t][d],o&&e===0||delete this.styles[t][d])}let u=!1;for(h&&!o&&(this.styles[t+s]=n,u=!0),(u||r>e)&&s--;s>0;)i&&i[s-1]?this.styles[t+s]={0:T({},i[s-1])}:c?this.styles[t+s]={0:T({},c)}:delete this.styles[t+s],s--;this._forceClearCache=!0}insertCharStyleObject(t,e,s,i){this.styles||(this.styles={});const n=this.styles[t],r=n?T({},n):{};s||(s=1);for(const h in r){const c=parseInt(h,10);c>=e&&(n[c+s]=r[c],r[c-s]||delete n[c])}if(this._forceClearCache=!0,i){for(;s--;)Object.keys(i[s]).length&&(this.styles[t]||(this.styles[t]={}),this.styles[t][e+s]=T({},i[s]));return}if(!n)return;const o=n[e?e-1:1];for(;o&&s--;)this.styles[t][e+s]=T({},o)}insertNewStyleBlock(t,e,s){const i=this.get2DCursorLocation(e,!0),n=[0];let r,o=0;for(let h=0;h<t.length;h++)t[h]===`
|
|
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=vt:this._selectionDirection===Ut&&(this._selectionDirection=vt,this.selectionEnd=t),this.selectionStart=s):s>t&&s<e?this._selectionDirection===Ut?this.selectionEnd=s:this.selectionStart=s:(e===t?this._selectionDirection=Ut:this._selectionDirection===vt&&(this._selectionDirection=Ut,this.selectionStart=e),this.selectionEnd=s)}}class Vw extends Hw{initHiddenTextarea(){const t=this.canvas&&Ys(this.canvas.getElement())||Yo(),e=t.createElement("textarea");Object.entries({autocapitalize:"off",autocorrect:"off",autocomplete:"off",spellcheck:"false","data-fabric":"textarea",wrap:"off"}).map(r=>{let[o,h]=r;return e.setAttribute(o,h)});const{top:s,left:i,fontSize:n}=this._calcTextareaPosition();e.style.cssText="position: absolute; top: ".concat(s,"; left: ").concat(i,"; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; padding-top: ").concat(n,";"),(this.hiddenTextareaContainer||t.body).appendChild(e),Object.entries({blur:"blur",keydown:"onKeyDown",keyup:"onKeyUp",input:"onInput",copy:"copy",cut:"copy",paste:"paste",compositionstart:"onCompositionStart",compositionupdate:"onCompositionUpdate",compositionend:"onCompositionEnd"}).map(r=>{let[o,h]=r;return e.addEventListener(o,this[h].bind(this))}),this.hiddenTextarea=e}blur(){this.abortCursorAnimation()}onKeyDown(t){if(!this.isEditing)return;const e=this.direction==="rtl"?this.keysMapRtl:this.keysMap;if(t.keyCode in e)this[e[t.keyCode]](t);else{if(!(t.keyCode in this.ctrlKeysMapDown)||!t.ctrlKey&&!t.metaKey)return;this[this.ctrlKeysMapDown[t.keyCode]](t)}t.stopImmediatePropagation(),t.preventDefault(),t.keyCode>=33&&t.keyCode<=40?(this.inCompositionMode=!1,this.clearContextTop(),this.renderCursorOrSelection()):this.canvas&&this.canvas.requestRenderAll()}onKeyUp(t){!this.isEditing||this._copyDone||this.inCompositionMode?this._copyDone=!1:t.keyCode in this.ctrlKeysMapUp&&(t.ctrlKey||t.metaKey)&&(this[this.ctrlKeysMapUp[t.keyCode]](t),t.stopImmediatePropagation(),t.preventDefault(),this.canvas&&this.canvas.requestRenderAll())}onInput(t){const e=this.fromPaste;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;const s=()=>{this.updateFromTextArea(),this.fire(Vc),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(this.hiddenTextarea.value==="")return this.styles={},void s();const i=this._splitTextIntoLines(this.hiddenTextarea.value).graphemeText,n=this._text.length,r=i.length,o=this.selectionStart,h=this.selectionEnd,c=o!==h;let u,d,g,f,p=r-n;const m=this.fromStringToGraphemeSelection(this.hiddenTextarea.selectionStart,this.hiddenTextarea.selectionEnd,this.hiddenTextarea.value),w=o>m.selectionStart;c?(d=this._text.slice(o,h),p+=h-o):r<n&&(d=w?this._text.slice(h+p,h):this._text.slice(o,o-p));const b=i.slice(m.selectionEnd-p,m.selectionEnd);if(d&&d.length&&(b.length&&(u=this.getSelectionStyles(o,o+1,!1),u=b.map(()=>u[0])),c?(g=o,f=h):w?(g=h-d.length,f=h):(g=h,f=h+d.length),this.removeStyleFromTo(g,f)),b.length){const{copyPasteData:x}=bi();e&&b.join("")===x.copiedText&&!ft.disableStyleCopyPaste&&(u=x.copiedTextStyle),this.insertNewStyleBlock(b,o,u)}s()}onCompositionStart(){this.inCompositionMode=!0}onCompositionEnd(){this.inCompositionMode=!1}onCompositionUpdate(t){let{target:e}=t;const{selectionStart:s,selectionEnd:i}=e;this.compositionStart=s,this.compositionEnd=i,this.updateTextareaPosition()}copy(){if(this.selectionStart===this.selectionEnd)return;const{copyPasteData:t}=bi();t.copiedText=this.getSelectedText(),ft.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,g=Math.abs(u-e);o=Math.abs(d-e)<g?h:h-1;break}return n||(o=s.length-1),o}moveCursorDown(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorUpOrDown("Down",t)}moveCursorUp(t){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorUpOrDown("Up",t)}_moveCursorUpOrDown(t,e){const s=this["get".concat(t,"CursorOffset")](e,this._selectionDirection===Ut);if(e.shiftKey?this.moveCursorWithShift(s):this.moveCursorWithoutShift(s),s!==0){const i=this.text.length;this.selectionStart=Mr(0,this.selectionStart,i),this.selectionEnd=Mr(0,this.selectionEnd,i),this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea()}}moveCursorWithShift(t){const e=this._selectionDirection===vt?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=vt,this.selectionEnd===this.selectionStart&&this.selectionStart!==0&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return this._selectionDirection===Ut&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):this.selectionStart!==0?(this._selectionDirection=vt,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===vt&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection=Ut,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=Ut,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}const $g=a=>!!a.button;class Gw extends Vw{constructor(){super(...arguments),E(this,"draggableTextDelegate",void 0)}initBehavior(){this.on("mousedown",this._mouseDownHandler),this.on("mousedown:before",this._mouseDownHandlerBefore),this.on("mouseup",this.mouseUpHandler),this.on("mousedblclick",this.doubleClickHandler),this.on("tripleclick",this.tripleClickHandler),this.__lastClickTime=+new Date,this.__lastLastClickTime=+new Date,this.__lastPointer={},this.on("mousedown",this.onMouseDown),this.draggableTextDelegate=new Bw(this),super.initBehavior()}shouldStartDragging(){return this.draggableTextDelegate.isActive()}onDragStart(t){return this.draggableTextDelegate.onDragStart(t)}canDrop(t){return this.draggableTextDelegate.canDrop(t)}onMouseDown(t){if(!this.canvas)return;this.__newClickTime=+new Date;const e=t.pointer;this.isTripleClick(e)&&(this.fire("tripleclick",t),bg(t.e)),this.__lastLastClickTime=this.__lastClickTime,this.__lastClickTime=this.__newClickTime,this.__lastPointer=e,this.__lastSelected=this.selected&&!this.getActiveControl()}isTripleClick(t){return this.__newClickTime-this.__lastClickTime<500&&this.__lastClickTime-this.__lastLastClickTime<500&&this.__lastPointer.x===t.x&&this.__lastPointer.y===t.y}doubleClickHandler(t){this.isEditing&&this.selectWord(this.getSelectionStartFromPointer(t.e))}tripleClickHandler(t){this.isEditing&&this.selectLine(this.getSelectionStartFromPointer(t.e))}_mouseDownHandler(t){let{e}=t;this.canvas&&this.editable&&!$g(e)&&!this.getActiveControl()&&(this.draggableTextDelegate.start(e)||(this.canvas.textEditingManager.register(this),this.selected&&(this.inCompositionMode=!1,this.setCursorByClick(e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection())))}_mouseDownHandlerBefore(t){let{e}=t;this.canvas&&this.editable&&!$g(e)&&(this.selected=this===this.canvas._activeObject)}mouseUpHandler(t){let{e,transform:s}=t;const i=this.draggableTextDelegate.end(e);if(this.canvas){this.canvas.textEditingManager.unregister(this);const n=this.canvas._activeObject;if(n&&n!==this)return}!this.editable||this.group&&!this.group.interactive||s&&s.actionPerformed||$g(e)||i||(this.__lastSelected&&!this.getActiveControl()?(this.selected=!1,this.__lastSelected=!1,this.enterEditing(e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection()):this.selected=!0)}setCursorByClick(t){const e=this.getSelectionStartFromPointer(t),s=this.selectionStart,i=this.selectionEnd;t.shiftKey?this.setSelectionStartEndWithShift(s,i,e):(this.selectionStart=e,this.selectionEnd=e),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())}getSelectionStartFromPointer(t){const e=this.canvas.getScenePoint(t).transform(Ze(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 bu="moveCursorUp",yu="moveCursorDown",_u="moveCursorLeft",wu="moveCursorRight",xu="exitEditing",Ww=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:xu,27:xu,33:bu,34:yu,35:wu,36:_u,37:_u,38:bu,39:wu,40:yu},keysMapRtl:{9:xu,27:xu,33:bu,34:yu,35:_u,36:wu,37:wu,38:bu,39:_u,40:yu},ctrlKeysMapDown:{65:"selectAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}},{_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1});class en extends Gw{static getDefaults(){return T(T({},super.getDefaults()),en.ownDefaults)}get type(){const t=super.type;return t==="itext"?"i-text":t}constructor(t,e){super(t,T(T({},en.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 Wg&&this.canvas.textEditingManager.remove(this),e instanceof Wg&&e.textEditingManager.add(this)),super._set(t,e))}setSelectionStart(t){t=Math.max(t,0),this._updateAndFire("selectionStart",t)}setSelectionEnd(t){t=Math.min(t,this.text.length),this._updateAndFire("selectionEnd",t)}_updateAndFire(t,e){this[t]!==e&&(this._fireSelectionChanged(),this[t]=e),this._updateTextarea()}_fireSelectionChanged(){this.fire("selection:changed"),this.canvas&&this.canvas.fire("text:selection:changed",{target:this})}initDimensions(){this.isEditing&&this.initDelayedCursor(),super.initDimensions()}getSelectionStyles(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart||0,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionEnd,s=arguments.length>2?arguments[2]:void 0;return super.getSelectionStyles(t,e,s)}setSelectionStyles(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionStart||0,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.selectionEnd;return super.setSelectionStyles(t,e,s)}get2DCursorLocation(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;return super.get2DCursorLocation(t,e)}render(t){super.render(t),this.cursorOffsetCache={},this.renderCursorOrSelection()}toCanvasElement(t){const e=this.isEditing;this.isEditing=!1;const s=super.toCanvasElement(t);return this.isEditing=e,s}renderCursorOrSelection(){if(!this.isEditing)return;const t=this.clearContextTop(!0);if(!t)return;const e=this._getCursorBoundaries();this.selectionStart!==this.selectionEnd||this.inCompositionMode?this.renderSelection(t,e):this.renderCursor(t,e),this.canvas.contextTopDirty=!0,t.restore()}_getCursorBoundaries(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;const s=this._getLeftOffset(),i=this._getTopOffset(),n=this._getCursorBoundariesOffsets(t,e);return{left:s,top:i,leftOffset:n.left,topOffset:n.top}}_getCursorBoundariesOffsets(t,e){return e?this.__getCursorBoundariesOffsets(t):this.cursorOffsetCache&&"top"in this.cursorOffsetCache?this.cursorOffsetCache:this.cursorOffsetCache=this.__getCursorBoundariesOffsets(t)}__getCursorBoundariesOffsets(t){let e=0,s=0;const{charIndex:i,lineIndex:n}=this.get2DCursorLocation(t);for(let c=0;c<n;c++)e+=this.getHeightOfLine(c);const r=this._getLineLeftOffset(n),o=this.__charBounds[n][i];o&&(s=o.left),this.charSpacing!==0&&i===this._textLines[n].length&&(s-=this._getWidthOfCharSpacing());const h={top:e,left:r+(s>0?s:0)};return this.direction==="rtl"&&(this.textAlign===Ut||this.textAlign===xi||this.textAlign===Gh?h.left*=-1:this.textAlign===vt||this.textAlign===vu?h.left=r-(s>0?s:0):this.textAlign!==tt&&this.textAlign!==Wh||(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(xi),o=this.get2DCursorLocation(i),h=this.get2DCursorLocation(n),c=o.lineIndex,u=h.lineIndex,d=o.charIndex<0?0:o.charIndex,g=h.charIndex<0?0:h.charIndex;for(let f=c;f<=u;f++){const p=this._getLineLeftOffset(f)||0;let m=this.getHeightOfLine(f),w=0,b=0,x=0;if(f===c&&(b=this.__charBounds[c][d].left),f>=c&&f<u)x=r&&!this.isEndOfWrapping(f)?this.width:this.getLineWidth(f)||5;else if(f===u)if(g===0)x=this.__charBounds[u][g].left;else{const k=this._getWidthOfCharSpacing();x=this.__charBounds[u][g-1].left+this.__charBounds[u][g-1].width-k}w=m,(this.lineHeight<1||f===u&&this.lineHeight>1)&&(m/=this.lineHeight);let C=s.left+p+b,A=m,P=0;const D=x-b;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",A=1,P=m):t.fillStyle=this.selectionColor,this.direction==="rtl"&&(this.textAlign===Ut||this.textAlign===xi||this.textAlign===Gh?C=this.width-C-D:this.textAlign===vt||this.textAlign===vu?C=s.left+p-x:this.textAlign!==tt&&this.textAlign!==Wh||(C=s.left+p-x)),t.fillRect(C,s.top+s.topOffset+P,D,A),s.topOffset+=w}}getCurrentCharFontSize(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,"fontSize")}getCurrentCharColor(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,Qt)}_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(en,"ownDefaults",Ww),E(en,"type","IText"),W.setClass(en),W.setClass(en,"i-text");class Lr extends en{static getDefaults(){return T(T({},super.getDefaults()),Lr.ownDefaults)}constructor(t,e){super(t,T(T({},Lr.ownDefaults),e))}static createControls(){return{controls:E_()}}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(xi)&&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 g 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,g=[],f=0,p=0,m=!0;e-=r;const w=Math.max(e,i,this.dynamicMinWidth),b=n[t];let x;for(f=0,x=0;x<b.length;x++){const{word:C,width:A}=b[x];f+=C.length,d+=p+A-o,d>w&&!m?(c.push(g),g=[],d=A,m=!0):d+=o,m||h||g.push(u),g=g.concat(C),p=h?0:this._measureWord([u],t,f),f++,m=!1}return x&&c.push(g),i+r>this.dynamicMinWidth&&(this.dynamicMinWidth=i-o+r),c}isEndOfWrapping(t){return!this._styleMap[t+1]||this._styleMap[t+1].line!==this._styleMap[t].line}missingNewlineOffset(t,e){return this.splitByGrapheme&&!e?this.isEndOfWrapping(t)?1:0:1}_splitTextIntoLines(t){const e=super._splitTextIntoLines(t),s=this._wrapText(e.lines,this.width),i=new Array(s.length);for(let n=0;n<s.length;n++)i[n]=s[n].join("");return e.lines=i,e.graphemeLines=s,e}getMinWidth(){return Math.max(this.minWidth,this.dynamicMinWidth)}_removeExtraneousStyles(){const t=new Map;for(const e in this._styleMap){const s=parseInt(e,10);if(this._textLines[s]){const i=this._styleMap[e].line;t.set("".concat(i),!0)}}for(const e in this.styles)t.has(e)||delete this.styles[e]}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject(["minWidth","splitByGrapheme",...t])}}E(Lr,"type","Textbox"),E(Lr,"textLayoutProperties",[...en.textLayoutProperties,"width"]),E(Lr,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),W.setClass(Lr);class W0 extends uu{shouldPerformLayout(t){return!!t.target.clipPath&&super.shouldPerformLayout(t)}shouldLayoutClipPath(){return!1}calcLayoutResult(t,e){const{target:s}=t,{clipPath:i,group:n}=s;if(!i||!this.shouldPerformLayout(t))return;const{width:r,height:o}=yi(g0(s,i)),h=new O(r,o);if(i.absolutePositioned)return{center:Pr(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}}}}E(W0,"type","clip-path"),W.setClass(W0);class z0 extends uu{getInitialSize(t,e){let{target:s}=t,{size:i}=e;return new O(s.width||i.x,s.height||i.y)}}E(z0,"type","fixed"),W.setClass(z0);class zw extends Bh{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 Fr extends wi{static getDefaults(){return T(T({},super.getDefaults()),Fr.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,Fr.ownDefaults),this.setOptions(e);const{left:s,top:i,layoutManager:n}=e;this.groupInit(t,{left:s,top:i,layoutManager:n??new zw})}_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))?(Ui("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===Ng?s.forEach(i=>{i._onAfterObjectsChange(lu,e)}):s.forEach(i=>{i._set("dirty",!0)})}onDeselect(){return this.removeAll(),!1}toString(){return"#<ActiveSelection: (".concat(this.complexity(),")>")}shouldCache(){return!1}isOnACache(){return!1}_renderControls(t,e,s){t.save(),t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1;const i=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(Fr,"type","ActiveSelection"),E(Fr,"ownDefaults",{multiSelectionStacking:"canvas-stacking"}),W.setClass(Fr),W.setClass(Fr,"activeSelection");class Xw{constructor(){E(this,"resources",{})}applyFilters(t,e,s,i,n){const r=n.getContext("2d");if(!r)return;r.drawImage(e,0,0,s,i);const o={sourceWidth:s,sourceHeight:i,imageData:r.getImageData(0,0,s,i),originalEl:e,originalImageData:r.getImageData(0,0,s,i),canvasEl:n,ctx:r,filterBackend:this};t.forEach(c=>{c.applyTo(o)});const{imageData:h}=o;return h.width===s&&h.height===i||(n.width=h.width,n.height=h.height),r.putImageData(h,0,0),o}}class X0{constructor(){let{tileSize:t=ft.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=Us({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(g=>{g&&g.applyTo(u)}),function(g){const f=g.targetCanvas,p=f.width,m=f.height,w=g.destinationWidth,b=g.destinationHeight;p===w&&m===b||(f.width=w,f.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:g,TEXTURE_WRAP_S:f,TEXTURE_WRAP_T:p}=t,m=t.createTexture();return t.bindTexture(o,m),t.texParameteri(o,d,n||r),t.texParameteri(o,g,n||r),t.texParameteri(o,f,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 qg;function Uw(){const{WebGLProbe:a}=bi();return a.queryWebGL(Cs()),ft.enableGLFiltering&&a.isSupported(ft.textureSize)?new X0({tileSize:ft.textureSize}):new Xw}function Kg(){return!qg&&(!(arguments.length>0&&arguments[0]!==void 0)||arguments[0])&&(qg=Uw()),qg}const Yw=["filters","resizeFilter","src","crossOrigin","type"],U0=["cropX","cropY"];class Te extends Ce{static getDefaults(){return T(T({},super.getDefaults()),Te.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,Te.ownDefaults),this.setOptions(e),this.cacheKey="texture".concat(Bn()),this.setElement(typeof t=="string"?(this.canvas&&Ys(this.canvas.getElement())||Yo()).getElementById(t):t,e)}getElement(){return this._element}setElement(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._element=t,this._originalElement=t,this._setWidthHeight(e),t.classList.add(Te.CSS_CANVAS),this.filters.length!==0&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){const e=Kg(!1);e instanceof X0&&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&&bi().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([...U0,...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=Bn();n.push('<clipPath id="imageCrop_'+c+`">
|
|
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 wt(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=ey(t),n=e._findCenterFromElement();return new this(T({id:t.getAttribute("id")||void 0,type:ty(t),coords:Kw(t,{width:s.viewBoxWidth||s.width,height:s.viewBoxHeight||s.height}),colorStops:qw(t,s.opacity),gradientUnits:i,gradientTransform:ku(t.getAttribute("gradientTransform")||"")},i==="pixels"?{offsetX:e.width/2-n.x,offsetY:e.height/2-n.y}:{offsetX:0,offsetY:0}))}}E(el,"type","Gradient"),V.setClass(el,"gradient"),V.setClass(el,"linear"),V.setClass(el,"radial");const Jw=["type","source","patternTransform"];class fg{get type(){return"pattern"}set type(t){Yi("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=zn(),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({},Lr(this,t)),{},{type:"pattern",source:this.sourceToString(),repeat:e,crossOrigin:s,offsetX:Ft(this.offsetX,pt.NUM_FRACTION_DIGITS),offsetY:Ft(this.offsetY,pt.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=_o(this.offsetX/e,0),h=_o(this.offsetY/s,0),c=n==="repeat-y"||n==="no-repeat"?1+Math.abs(a||0):_o(i.width/e,0),u=n==="repeat-x"||n==="no-repeat"?1+Math.abs(h||0):_o(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,Jw);const a=await Xh(i,T(T({},e),{},{crossOrigin:r.crossOrigin}));return new this(T(T({},r),{},{patternTransform:n&&n.slice(0),source:a}))}}E(fg,"type","Pattern"),V.setClass(fg),V.setClass(fg,"pattern");const Qw=["path","left","top"],Zw=["d"];class Nr extends Te{constructor(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{path:s,left:i,top:n}=e,r=Lt(e,Qw);super(),Object.assign(this,Nr.ownDefaults),this.setOptions(r),this._setPath(t||[],!0),typeof i=="number"&&this.set(vt,i),typeof n=="number"&&this.set(es,n)}_setPath(t,e){this.path=Hb(Array.isArray(t)?t:$b(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 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=qb(this.path,pt.NUM_FRACTION_DIGITS);return["<path ","COMMON_PARTS",'d="'.concat(t,`" stroke-linecap="round" />
|
|
76
|
+
`)]}_getOffsetTransform(){const t=pt.NUM_FRACTION_DIGITS;return" translate(".concat(Ft(-this.pathOffset.x,t),", ").concat(Ft(-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,et,et)}_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(...cg(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(...cg(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 wi(t)}_calcDimensions(){const t=this._calcBoundsFromPath();return T(T({},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=Qi(t,this.ATTRIBUTE_NAMES,s),{d:n}=i;return new this(n,T(T(T({},Lt(i,Zw)),e),{},{left:void 0,top:void 0}))}}E(Nr,"type","Path"),E(Nr,"cacheProperties",[...Ki,"path","fillRule"]),E(Nr,"ATTRIBUTE_NAMES",[...Xn,"d"]),V.setClass(Nr),V.setSVGClass(Nr);const tx=["left","top","radius"],sy=["radius","startAngle","endAngle","counterClockwise"];class tn extends Te{static getDefaults(){return T(T({},super.getDefaults()),tn.ownDefaults)}constructor(t){super(),Object.assign(this,tn.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,Gt(this.startAngle),Gt(this.endAngle),this.counterClockwise),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get(He)}getRadiusY(){return this.get("radius")*this.get(us)}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([...sy,...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=Gt(this.startAngle),i=Gt(this.endAngle),n=Ys(s)*e,r=$s(s)*e,a=Ys(i)*e,h=$s(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=Qi(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,radius:a=0}=i;return new this(T(T({},Lt(i,tx)),{},{radius:a,left:n-a,top:r-a}))}static fromObject(t){return super._fromObject(t)}}E(tn,"type","Circle"),E(tn,"cacheProperties",[...Ki,...sy]),E(tn,"ownDefaults",{radius:0,startAngle:0,endAngle:360,counterClockwise:!1}),E(tn,"ATTRIBUTE_NAMES",["cx","cy","r",...Xn]),V.setClass(tn),V.setSVGClass(tn);const ex=["x1","y1","x2","y2"],sx=["x1","y1","x2","y2"],gg=["x1","x2","y1","y2"];class Br extends Te{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,Br.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(vt,r),typeof a=="number"&&this.set(es,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}=wi([{x:t,y:e},{x:s,y:i}]),c=new O(n+a/2,r+h/2);this.setPositionByOrigin(c,et,et)}_set(t,e){return super._set(t,e),gg.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;Os(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 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=Qi(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,ex))}static fromObject(t){let{x1:e,y1:s,x2:i,y2:n}=t,r=Lt(t,sx);return this._fromObject(T(T({},r),{},{points:[e,s,i,n]}),{extraParam:"points"})}}E(Br,"type","Line"),E(Br,"cacheProperties",[...Ki,...gg]),E(Br,"ATTRIBUTE_NAMES",Xn.concat(gg)),V.setClass(Br),V.setSVGClass(Br);class Hr extends Te{static getDefaults(){return T(T({},super.getDefaults()),Hr.ownDefaults)}constructor(t){super(),Object.assign(this,Hr.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(Hr,"type","Triangle"),E(Hr,"ownDefaults",{width:100,height:100}),V.setClass(Hr),V.setSVGClass(Hr);const iy=["rx","ry"];class en extends Te{static getDefaults(){return T(T({},super.getDefaults()),en.ownDefaults)}constructor(t){super(),Object.assign(this,en.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(He)}getRy(){return this.get("ry")*this.get(us)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...iy,...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,$i,!1),t.restore(),this._renderPaintInOrder(t)}static async fromElement(t,e,s){const i=Qi(t,this.ATTRIBUTE_NAMES,s);return i.left=(i.left||0)-i.rx,i.top=(i.top||0)-i.ry,new this(i)}}function ix(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(en,"type","Ellipse"),E(en,"cacheProperties",[...Ki,...iy]),E(en,"ownDefaults",{rx:0,ry:0}),E(en,"ATTRIBUTE_NAMES",[...Xn,"cx","cy","rx","ry"]),V.setClass(en),V.setSVGClass(en);const nx=["left","top"],ny={exactBoundingBox:!1};class ei extends Te{static getDefaults(){return T(T({},super.getDefaults()),ei.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,ei.ownDefaults),this.setOptions(e),this.points=t;const{left:s,top:i}=e;this.initialized=!0,this.setBoundingBox(!0),typeof s=="number"&&this.set(vt,s),typeof i=="number"&&this.set(es,i)}isOpen(){return!0}_projectStrokeOnPoints(t){return xb(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 O,strokeOffset:new O,strokeDiff:new O};const s=wi(e),i=Gh(T(T({},t),{},{scaleX:1,scaleY:1})),n=wi(this.points.map(c=>Ae(c,i,!0))),r=new O(this.scaleX,this.scaleY);let a=s.left+s.width/2,h=s.top+s.height/2;return this.exactBoundingBox&&(a-=h*Math.tan(Gt(this.skewX)),h-=a*Math.tan(Gt(this.skewY))),T(T({},s),{},{pathOffset:new O(a,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=wi(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:a,strokeDiff:h}=this._calcDimensions();this.set({width:i,height:n,pathOffset:r,strokeOffset:a,strokeDiff:h}),t&&this.setPositionByOrigin(new O(e+i/2,s+n/2),et,et)}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(a=>this.strokeUniform||this.constructor.layoutProperties.includes(a))){var e,s;const{width:a,height:h}=this._calcDimensions(t);r=new O((e=t.width)!==null&&e!==void 0?e:a,(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===He||t===us)&&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=pt.NUM_FRACTION_DIGITS;for(let n=0,r=this.points.length;n<r;n++)t.push(Ft(this.points[n].x-e,i),",",Ft(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(ix(t.getAttribute("points")),T(T({},Lt(Qi(t,this.ATTRIBUTE_NAMES,s),nx)),e))}static fromObject(t){return this._fromObject(t,{extraParam:"points"})}}E(ei,"ownDefaults",ny),E(ei,"type","Polyline"),E(ei,"layoutProperties",[ao,oo,"strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeWidth","strokeUniform","points"]),E(ei,"cacheProperties",[...Ki,"points"]),E(ei,"ATTRIBUTE_NAMES",[...Xn]),V.setClass(ei),V.setSVGClass(ei);class Iu extends ei{isOpen(){return!1}}E(Iu,"ownDefaults",ny),E(Iu,"type","Polygon"),V.setClass(Iu),V.setSVGClass(Iu);const ry=["fontSize","fontWeight","fontFamily","fontStyle"],ay=["underline","overline","linethrough"],oy=[...ry,"lineHeight","text","charSpacing","textAlign","styles","path","pathStartOffset","pathSide","pathAlign"],hy=[...oy,...ay,"textBackgroundColor","direction"],rx=[...ry,...ay,Ve,"strokeWidth",Zt,"deltaY","textBackgroundColor"],ax={_reNewline:Mf,_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:vt,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:vt,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},Ci="justify",ju="justify-left",sl="justify-right",il="justify-center";class ly extends Te{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=jf(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({},Lr(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(ly,"_styleProperties",rx);const ox=/ +/g,hx=/"/g;function pg(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]:pt.NUM_FRACTION_DIGITS;const f=$h(Zt,n,!1),[g,p,b,_]=[a,h,c,u].map(y=>Ft(y,d));return"<rect ".concat(f,' x="').concat(g,'" y="').concat(p,'" width="').concat(b,'" height="').concat(_,'"></rect>')}(o,{left:t,top:e,width:s,height:i}),`
|
|
82
|
+
`)}const lx=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let mg;class Ee extends ly{static getDefaults(){return T(T({},super.getDefaults()),Ee.ownDefaults)}constructor(t,e){super(),E(this,"__charBounds",[]),Object.assign(this,Ee.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=ug(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(Ci)&&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===Ci||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===Ve?(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 et:t.textBaseline="middle";break;case"ascender":t.textBaseline=es;break;case"descender":t.textBaseline=Pf}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 b=0;b<h;b++){const _=this.__charBounds[n][b];d=this.getValueOfPropertyAt(n,b,"textBackgroundColor"),this.path?(t.save(),t.translate(_.renderLeft,_.renderTop),t.rotate(_.angle),t.fillStyle=d,d&&t.fillRect(-_.width/2,-a/this.lineHeight*(1-this._fontSizeFraction),_.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=_.left,f=_.width,p=d):f+=_.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=Vh.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 mg||(mg=qs({width:0,height:0}).getContext("2d")),mg}();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===Yt,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 vt:u=n?d-i:0;break;case et:u=(d-i)/2;break;case Yt: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=Ub(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===Yt?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(Zt))&&this._renderTextCommon(t,"fillText")}_renderTextStroke(t){(this.stroke&&this.strokeWidth!==0||!this.isEmptyStyles())&&(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this._setLineDash(t,this.strokeDashArray),t.beginPath(),this._renderTextCommon(t,"strokeText"),t.closePath(),t.restore())}_renderChars(t,e,s,i,n,r){const a=this.getHeightOfLine(r),h=this.textAlign.includes(Ci),c=this.path,u=!h&&this.charSpacing===0&&this.isEmptyStyles(r)&&!c,d=this.direction==="ltr",f=this.direction==="ltr"?1:-1,g=e.direction;let p,b,_,y,x,C="",A=0;if(e.save(),g!==this.direction&&(e.canvas.setAttribute("dir",d?"ltr":"rtl"),e.direction=d?"ltr":"rtl",e.textAlign=d?vt:Yt),n-=a*this._fontSizeFraction/this.lineHeight,u)return this._renderChar(t,e,r,0,s.join(""),i,n),void e.restore();for(let P=0,D=s.length-1;P<=D;P++)y=P===D||this.charSpacing||c,C+=s[P],_=this.__charBounds[r][P],A===0?(i+=f*(_.kernedWidth-_.width),A+=_.width):A+=_.kernedWidth,h&&!y&&this._reSpaceAndTab.test(s[P])&&(y=!0),y||(p=p||this.getCompleteStyleDeclaration(r,P),b=this.getCompleteStyleDeclaration(r,P+1),y=Eu(p,b,!1)),y&&(c?(e.save(),e.translate(_.renderLeft,_.renderTop),e.rotate(_.angle),this._renderChar(t,e,r,P,C,-A/2,0),e.restore()):(x=i,this._renderChar(t,e,r,P,C,x,n)),C="",p=b,i+=f*A,A=0);e.restore()}_applyPatternGradientTransformText(t){const e=this.width+this.strokeWidth,s=this.height+this.strokeWidth,i=qs({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 Os(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===Ci||i===il&&!r||i===sl&&!r||i===ju&&!r?0:(i===et&&(a=s/2),i===Yt&&(a=s),i===il&&(a=s/2),i===sl&&(a=s),n==="rtl"&&(i===Yt||i===Ci||i===sl?a=0:i===vt||i===ju?a=-s:i!==et&&i!==il||(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,b,_=0,y=0,x=this.getValueOfPropertyAt(h,0,e),C=this.getValueOfPropertyAt(h,0,Zt);const A=s+f*(1-this._fontSizeFraction);let P=this.getHeightOfChar(h,0),D=this.getValueOfPropertyAt(h,0,"deltaY");for(let M=0,R=d.length;M<R;M++){const F=this.__charBounds[h][M];p=this.getValueOfPropertyAt(h,M,e),b=this.getValueOfPropertyAt(h,M,Zt);const I=this.getHeightOfChar(h,M),Y=this.getValueOfPropertyAt(h,M,"deltaY");if(n&&p&&b)t.save(),t.fillStyle=C,t.translate(F.renderLeft,F.renderTop),t.rotate(F.angle),t.fillRect(-F.kernedWidth/2,a*I+Y,F.kernedWidth,this.fontSize/15),t.restore();else if((p!==x||b!==C||I!==P||Y!==D)&&y>0){let N=i+g+_;this.direction==="rtl"&&(N=this.width-N-y),x&&C&&(t.fillStyle=C,t.fillRect(N,A+a*P+D,y,this.fontSize/15)),_=F.left,y=F.width,x=p,C=b,P=I,D=Y}else y+=F.kernedWidth}let k=i+g+_;this.direction==="rtl"&&(k=this.width-k-y),t.fillStyle=b,p&&b&&t.fillRect(k,A+a*P+D,y-r,this.fontSize/15),s+=u}this._removeShadow(t)}_getFontDeclaration(){let{fontFamily:t=this.fontFamily,fontStyle:e=this.fontStyle,fontWeight:s=this.fontWeight,fontSize:i=this.fontSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;const r=t.includes("'")||t.includes('"')||t.includes(",")||Ee.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 Tu(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([...hy,...t])),{},{styles:Cb(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=Qi(t,Ee.ATTRIBUTE_NAMES,s),n=T(T({},e),i),{textAnchor:r=vt,textDecoration:a="",dx:h=0,dy:c=0,top:u=0,left:d=0,fontSize:f=kf,strokeWidth:g=1}=n,p=Lt(n,lx),b=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)),_=b.getScaledHeight()/b.height,y=((b.height+b.strokeWidth)*b.lineHeight-b.height)*_,x=b.getScaledHeight()+y;let C=0;return r===et&&(C=b.getScaledWidth()/2),r===Yt&&(C=b.getScaledWidth()),b.set({left:b.left-C,top:b.top-(x-b.fontSize*(.07+b._fontSizeFraction))/b.lineHeight,strokeWidth:g}),b}static fromObject(t){return this._fromObject(T(T({},t),{},{styles:Ab(t.styles||{},t.text)}),{extraParam:"text"})}}E(Ee,"textLayoutProperties",oy),E(Ee,"cacheProperties",[...Ki,...hy]),E(Ee,"ownDefaults",ax),E(Ee,"type","Text"),E(Ee,"genericFonts",["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong"]),E(Ee,"ATTRIBUTE_NAMES",Xn.concat("x","y","dx","dy","font-family","font-style","font-weight","font-size","letter-spacing","text-decoration","text-anchor")),yb(Ee,[class extends Qm{_toSVG(){const o=this._getSVGLeftTopOffsets(),t=this._getSVGTextAndBg(o.textTop,o.textLeft);return this._wrapSVGTextAndBg(t)}toSVG(o){return this._createBaseSVGMarkup(this._toSVG(),{reviver:o,noStyle:!0,withShadow:!0})}_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(hx,"'"),'" '):"",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(...pg(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){const i=this.getSvgSpanStyles(t,o!==o.trim()||!!o.match(ox)),n=i?'style="'.concat(i,'"'):"",r=t.deltaY,a=r?' dy="'.concat(Ft(r,pt.NUM_FRACTION_DIGITS),'" '):"";return'<tspan x="'.concat(Ft(e,pt.NUM_FRACTION_DIGITS),'" y="').concat(Ft(s,pt.NUM_FRACTION_DIGITS),'" ').concat(a).concat(n,">").concat(Sb(o),"</tspan>")}_setSVGTextLineText(o,t,e,s){const i=this.getHeightOfLine(t),n=this.textAlign.includes(Ci),r=this._textLines[t];let a,h,c,u,d,f="",g=0;s+=i*(1-this._fontSizeFraction)/this.lineHeight;for(let p=0,b=r.length-1;p<=b;p++)d=p===b||this.charSpacing,f+=r[p],c=this.__charBounds[t][p],g===0?(e+=c.kernedWidth-c.width,g+=c.width):g+=c.kernedWidth,n&&!d&&this._reSpaceAndTab.test(r[p])&&(d=!0),d||(a=a||this.getCompleteStyleDeclaration(t,p),h=this.getCompleteStyleDeclaration(t,p+1),d=Eu(a,h,!0)),d&&(u=this._getStyleDeclaration(t,p),o.push(this._createTextCharSpan(f,u,e,s)),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(...pg(c,e+h,s,a,n)),h=d,a=f,c=r):a+=g}r&&o.push(...pg(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?$h(Ve,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?$h(Zt,n):"",c?"baseline-shift: ".concat(-c,"; "):"",t?"white-space: pre; ":""].join("")}getSvgTextDecoration(o){return["overline","underline","line-through"].filter(t=>o[t.replace("-","")]).join(" ")}}]),V.setClass(Ee),V.setSVGClass(Ee);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 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=a.getScenePoint(t).subtract(u),f=r.getCanvasRetinaScaling(),g=r.getBoundingRect(),p=u.subtract(new O(g.left,g.top)),b=a.viewportTransform,_=p.add(d).transform(b,!0),y=r.backgroundColor,x=ng(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 A=r.toCanvasElement({enableRetinaScaling:a.enableRetinaScaling,viewportTransform:!0});r.backgroundColor=y,r.styles=x,r.dirty=!0,Ru(A,{position:"fixed",left:"".concat(-A.width,"px"),border:Be,width:"".concat(A.width/f,"px"),height:"".concat(A.height/f,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{A.remove()},Ks(t.target||this.target.hiddenTextarea).body.appendChild(A),(s=t.dataTransfer)===null||s===void 0||s.setDragImage(A,_.x,_.y)}onDragStart(t){this.__dragStartFired=!0;const e=this.target,s=this.isActive();if(s&&t.dataTransfer){const i=this.__dragStartSelection={selectionStart:e.selectionStart,selectionEnd:e.selectionEnd},n=e._text.slice(i.selectionStart,i.selectionEnd).join(""),r=T({text:e.text,value:n},i);t.dataTransfer.setData("text/plain",n),t.dataTransfer.setData("application/fabric",JSON.stringify({value:n,styles:e.getSelectionStyles(i.selectionStart,i.selectionEnd,!0)})),t.dataTransfer.effectAllowed="copyMove",this.setDragImage(t,r)}return e.abortCursorAnimation(),s}canDrop(t){if(this.target.editable&&!this.target.getActiveControl()&&!t.defaultPrevented){if(this.isActive()&&this.__dragStartSelection){const e=this.target.getSelectionStartFromPointer(t),s=this.__dragStartSelection;return e<s.selectionStart||e>s.selectionEnd}return!0}return!1}targetCanDrop(t){return this.target.canDrop(t)}dragEnterHandler(t){let{e}=t;const s=this.targetCanDrop(e);!this.__isDraggingOver&&s&&(this.__isDraggingOver=!0)}dragOverHandler(t){const{e}=t,s=this.targetCanDrop(e);!this.__isDraggingOver&&s?this.__isDraggingOver=!0:this.__isDraggingOver&&!s&&(this.__isDraggingOver=!1),this.__isDraggingOver&&(e.preventDefault(),t.canDrop=!0,t.dropTarget=this.target)}dragLeaveHandler(){(this.__isDraggingOver||this.isActive())&&(this.__isDraggingOver=!1)}dropHandler(t){var e;const{e:s}=t,i=s.defaultPrevented;this.__isDraggingOver=!1,s.preventDefault();let n=(e=s.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain");if(n&&!i){const r=this.target,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(ou,{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)||Be;h===Be?(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(ou,{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 cy=/[ \n\.,;!\?\-]/;class ux extends Ee{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 eg({startValue:this._currentCursorOpacity,endValue:e,duration:s,delay:i,onComplete:n,abort:()=>!this.canvas||this.selectionStart!==this.selectionEnd,onChange:r=>{this._currentCursorOpacity=r,this.renderCursorOrSelection()}})}_tick(t){this._currentTickState=this._animateCursor({toValue:0,duration:this.cursorDuration/2,delay:Math.max(t||0,100),onComplete:this._onTickComplete})}_onTickComplete(){var t;(t=this._currentTickCompleteState)===null||t===void 0||t.abort(),this._currentTickCompleteState=this._animateCursor({toValue:1,duration:this.cursorDuration,onComplete:this._tick})}initDelayedCursor(t){this.abortCursorAnimation(),this._tick(t?0:this.cursorDelay)}abortCursorAnimation(){let t=!1;[this._currentTickState,this._currentTickCompleteState].forEach(e=>{e&&!e.isDone()&&(t=!0,e.abort())}),this._currentCursorOpacity=1,t&&this.clearContextTop()}restartCursorIfNeeded(){[this._currentTickState,this._currentTickCompleteState].some(t=>!t||t.isDone())&&this.initDelayedCursor()}selectAll(){return this.selectionStart=0,this.selectionEnd=this._text.length,this._fireSelectionChanged(),this._updateTextarea(),this}getSelectedText(){return this._text.slice(this.selectionStart,this.selectionEnd).join("")}findWordBoundaryLeft(t){let e=0,s=t-1;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s--;for(;/\S/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findWordBoundaryRight(t){let e=0,s=t;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s++;for(;/\S/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}findLineBoundaryLeft(t){let e=0,s=t-1;for(;!/\n/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findLineBoundaryRight(t){let e=0,s=t;for(;!/\n/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}searchWordBoundary(t,e){const s=this._text;let i=t>0&&this._reSpace.test(s[t])&&(e===-1||!Mf.test(s[t-1]))?t-1:t,n=s[i];for(;i>0&&i<s.length&&!cy.test(n);)i+=e,n=s[i];return e===-1&&cy.test(n)&&i++,i}selectWord(t){t=t||this.selectionStart;const e=this.searchWordBoundary(t,-1),s=Math.max(e,this.searchWordBoundary(t,1));this.selectionStart=e,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(t){t=t||this.selectionStart;const e=this.findLineBoundaryLeft(t),s=this.findLineBoundaryRight(t);return this.selectionStart=e,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea(),this}enterEditing(t){!this.isEditing&&this.editable&&(this.enterEditingImpl(),this.fire("editing:entered",t?{e:t}:void 0),this._fireSelectionChanged(),this.canvas&&(this.canvas.fire("text:editing:entered",{target:this,e:t}),this.canvas.requestRenderAll()))}enterEditingImpl(){this.canvas&&(this.canvas.calcOffset(),this.canvas.textEditingManager.exitTextEditing()),this.isEditing=!0,this.initHiddenTextarea(),this.hiddenTextarea.focus(),this.hiddenTextarea.value=this.text,this._updateTextarea(),this._saveEditingProps(),this._setEditingProps(),this._textBeforeEdit=this.text,this._tick()}updateSelectionOnMouseMove(t){if(this.getActiveControl())return;const e=this.hiddenTextarea;Ks(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 O(e.left+a,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(lu),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=vt:this._selectionDirection===Yt&&(this._selectionDirection=vt,this.selectionEnd=t),this.selectionStart=s):s>t&&s<e?this._selectionDirection===Yt?this.selectionEnd=s:this.selectionStart=s:(e===t?this._selectionDirection=Yt:this._selectionDirection===vt&&(this._selectionDirection=Yt,this.selectionStart=e),this.selectionEnd=s)}}class dx extends ux{initHiddenTextarea(){const t=this.canvas&&Ks(this.canvas.getElement())||ro(),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;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;const s=()=>{this.updateFromTextArea(),this.fire(ou),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(this.hiddenTextarea.value==="")return this.styles={},void s();const i=this._splitTextIntoLines(this.hiddenTextarea.value).graphemeText,n=this._text.length,r=i.length,a=this.selectionStart,h=this.selectionEnd,c=a!==h;let u,d,f,g,p=r-n;const b=this.fromStringToGraphemeSelection(this.hiddenTextarea.selectionStart,this.hiddenTextarea.selectionEnd,this.hiddenTextarea.value),_=a>b.selectionStart;c?(d=this._text.slice(a,h),p+=h-a):r<n&&(d=_?this._text.slice(h+p,h):this._text.slice(a,a-p));const y=i.slice(b.selectionEnd-p,b.selectionEnd);if(d&&d.length&&(y.length&&(u=this.getSelectionStyles(a,a+1,!1),u=y.map(()=>u[0])),c?(f=a,g=h):_?(f=h-d.length,g=h):(f=h,g=h+d.length),this.removeStyleFromTo(f,g)),y.length){const{copyPasteData:x}=_i();e&&y.join("")===x.copiedText&&!pt.disableStyleCopyPaste&&(u=x.copiedTextStyle),this.insertNewStyleBlock(y,a,u)}s()}onCompositionStart(){this.inCompositionMode=!0}onCompositionEnd(){this.inCompositionMode=!1}onCompositionUpdate(t){let{target:e}=t;const{selectionStart:s,selectionEnd:i}=e;this.compositionStart=s,this.compositionEnd=i,this.updateTextareaPosition()}copy(){if(this.selectionStart===this.selectionEnd)return;const{copyPasteData:t}=_i();t.copiedText=this.getSelectedText(),pt.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===Yt);if(e.shiftKey?this.moveCursorWithShift(s):this.moveCursorWithoutShift(s),s!==0){const i=this.text.length;this.selectionStart=jr(0,this.selectionStart,i),this.selectionEnd=jr(0,this.selectionEnd,i),this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea()}}moveCursorWithShift(t){const e=this._selectionDirection===vt?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=vt,this.selectionEnd===this.selectionStart&&this.selectionStart!==0&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return this._selectionDirection===Yt&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):this.selectionStart!==0?(this._selectionDirection=vt,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===vt&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection=Yt,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=Yt,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}const bg=o=>!!o.button;class fx extends dx{constructor(){super(...arguments),E(this,"draggableTextDelegate",void 0)}initBehavior(){this.on("mousedown",this._mouseDownHandler),this.on("mousedown:before",this._mouseDownHandlerBefore),this.on("mouseup",this.mouseUpHandler),this.on("mousedblclick",this.doubleClickHandler),this.on("tripleclick",this.tripleClickHandler),this.__lastClickTime=+new Date,this.__lastLastClickTime=+new Date,this.__lastPointer={},this.on("mousedown",this.onMouseDown),this.draggableTextDelegate=new cx(this),super.initBehavior()}shouldStartDragging(){return this.draggableTextDelegate.isActive()}onDragStart(t){return this.draggableTextDelegate.onDragStart(t)}canDrop(t){return this.draggableTextDelegate.canDrop(t)}onMouseDown(t){if(!this.canvas)return;this.__newClickTime=+new Date;const e=t.pointer;this.isTripleClick(e)&&(this.fire("tripleclick",t),Vf(t.e)),this.__lastLastClickTime=this.__lastClickTime,this.__lastClickTime=this.__newClickTime,this.__lastPointer=e,this.__lastSelected=this.selected&&!this.getActiveControl()}isTripleClick(t){return this.__newClickTime-this.__lastClickTime<500&&this.__lastClickTime-this.__lastLastClickTime<500&&this.__lastPointer.x===t.x&&this.__lastPointer.y===t.y}doubleClickHandler(t){this.isEditing&&this.selectWord(this.getSelectionStartFromPointer(t.e))}tripleClickHandler(t){this.isEditing&&this.selectLine(this.getSelectionStartFromPointer(t.e))}_mouseDownHandler(t){let{e}=t;this.canvas&&this.editable&&!bg(e)&&!this.getActiveControl()&&(this.draggableTextDelegate.start(e)||(this.canvas.textEditingManager.register(this),this.selected&&(this.inCompositionMode=!1,this.setCursorByClick(e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection())))}_mouseDownHandlerBefore(t){let{e}=t;this.canvas&&this.editable&&!bg(e)&&(this.selected=this===this.canvas._activeObject)}mouseUpHandler(t){let{e,transform:s}=t;const i=this.draggableTextDelegate.end(e);if(this.canvas){this.canvas.textEditingManager.unregister(this);const n=this.canvas._activeObject;if(n&&n!==this)return}!this.editable||this.group&&!this.group.interactive||s&&s.actionPerformed||bg(e)||i||(this.__lastSelected&&!this.getActiveControl()?(this.selected=!1,this.__lastSelected=!1,this.enterEditing(e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection()):this.selected=!0)}setCursorByClick(t){const e=this.getSelectionStartFromPointer(t),s=this.selectionStart,i=this.selectionEnd;t.shiftKey?this.setSelectionStartEndWithShift(s,i,e):(this.selectionStart=e,this.selectionEnd=e),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())}getSelectionStartFromPointer(t){const e=this.canvas.getScenePoint(t).transform(ss(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 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 Nu="moveCursorUp",Bu="moveCursorDown",Hu="moveCursorLeft",Vu="moveCursorRight",Wu="exitEditing",gx=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:Wu,27:Wu,33:Nu,34:Bu,35:Vu,36:Hu,37:Hu,38:Nu,39:Vu,40:Bu},keysMapRtl:{9:Wu,27:Wu,33:Nu,34:Bu,35:Hu,36:Vu,37:Vu,38:Nu,39:Hu,40:Bu},ctrlKeysMapDown:{65:"selectAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}},{_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1});class sn extends fx{static getDefaults(){return T(T({},super.getDefaults()),sn.ownDefaults)}get type(){const t=super.type;return t==="itext"?"i-text":t}constructor(t,e){super(t,T(T({},sn.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 dg&&this.canvas.textEditingManager.remove(this),e instanceof dg&&e.textEditingManager.add(this)),super._set(t,e))}setSelectionStart(t){t=Math.max(t,0),this._updateAndFire("selectionStart",t)}setSelectionEnd(t){t=Math.min(t,this.text.length),this._updateAndFire("selectionEnd",t)}_updateAndFire(t,e){this[t]!==e&&(this._fireSelectionChanged(),this[t]=e),this._updateTextarea()}_fireSelectionChanged(){this.fire("selection:changed"),this.canvas&&this.canvas.fire("text:selection:changed",{target:this})}initDimensions(){this.isEditing&&this.initDelayedCursor(),super.initDimensions()}getSelectionStyles(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart||0,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionEnd,s=arguments.length>2?arguments[2]:void 0;return super.getSelectionStyles(t,e,s)}setSelectionStyles(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionStart||0,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.selectionEnd;return super.setSelectionStyles(t,e,s)}get2DCursorLocation(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;return super.get2DCursorLocation(t,e)}render(t){super.render(t),this.cursorOffsetCache={},this.renderCursorOrSelection()}toCanvasElement(t){const e=this.isEditing;this.isEditing=!1;const s=super.toCanvasElement(t);return this.isEditing=e,s}renderCursorOrSelection(){if(!this.isEditing)return;const t=this.clearContextTop(!0);if(!t)return;const e=this._getCursorBoundaries();this.selectionStart!==this.selectionEnd||this.inCompositionMode?this.renderSelection(t,e):this.renderCursor(t,e),this.canvas.contextTopDirty=!0,t.restore()}_getCursorBoundaries(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;const s=this._getLeftOffset(),i=this._getTopOffset(),n=this._getCursorBoundariesOffsets(t,e);return{left:s,top:i,leftOffset:n.left,topOffset:n.top}}_getCursorBoundariesOffsets(t,e){return e?this.__getCursorBoundariesOffsets(t):this.cursorOffsetCache&&"top"in this.cursorOffsetCache?this.cursorOffsetCache:this.cursorOffsetCache=this.__getCursorBoundariesOffsets(t)}__getCursorBoundariesOffsets(t){let e=0,s=0;const{charIndex:i,lineIndex:n}=this.get2DCursorLocation(t);for(let c=0;c<n;c++)e+=this.getHeightOfLine(c);const r=this._getLineLeftOffset(n),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===Yt||this.textAlign===Ci||this.textAlign===sl?h.left*=-1:this.textAlign===vt||this.textAlign===ju?h.left=r-(s>0?s:0):this.textAlign!==et&&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"),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(Ci),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 b=this.getHeightOfLine(g),_=0,y=0,x=0;if(g===c&&(y=this.__charBounds[c][d].left),g>=c&&g<u)x=r&&!this.isEndOfWrapping(g)?this.width:this.getLineWidth(g)||5;else if(g===u)if(f===0)x=this.__charBounds[u][f].left;else{const k=this._getWidthOfCharSpacing();x=this.__charBounds[u][f-1].left+this.__charBounds[u][f-1].width-k}_=b,(this.lineHeight<1||g===u&&this.lineHeight>1)&&(b/=this.lineHeight);let C=s.left+p+y,A=b,P=0;const D=x-y;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",A=1,P=b):t.fillStyle=this.selectionColor,this.direction==="rtl"&&(this.textAlign===Yt||this.textAlign===Ci||this.textAlign===sl?C=this.width-C-D:this.textAlign===vt||this.textAlign===ju?C=s.left+p-x:this.textAlign!==et&&this.textAlign!==il||(C=s.left+p-x)),t.fillRect(C,s.top+s.topOffset+P,D,A),s.topOffset+=_}}getCurrentCharFontSize(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,"fontSize")}getCurrentCharColor(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,Zt)}_getCurrentCharIndex(){const t=this.get2DCursorLocation(this.selectionStart,!0),e=t.charIndex>0?t.charIndex-1:0;return{l:t.lineIndex,c:e}}dispose(){this.exitEditingImpl(),this.draggableTextDelegate.dispose(),super.dispose()}}E(sn,"ownDefaults",gx),E(sn,"type","IText"),V.setClass(sn),V.setClass(sn,"i-text");class Vr extends sn{static getDefaults(){return T(T({},super.getDefaults()),Vr.ownDefaults)}constructor(t,e){super(t,T(T({},Vr.ownDefaults),e))}static createControls(){return{controls:Q_()}}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(Ci)&&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,b=!0;e-=r;const _=Math.max(e,i,this.dynamicMinWidth),y=n[t];let x;for(g=0,x=0;x<y.length;x++){const{word:C,width:A}=y[x];g+=C.length,d+=p+A-a,d>_&&!b?(c.push(f),f=[],d=A,b=!0):d+=a,b||h||f.push(u),f=f.concat(C),p=h?0:this._measureWord([u],t,g),g++,b=!1}return x&&c.push(f),i+r>this.dynamicMinWidth&&(this.dynamicMinWidth=i-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(Vr,"type","Textbox"),E(Vr,"textLayoutProperties",[...sn.textLayoutProperties,"width"]),E(Vr,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),V.setClass(Vr);class uy extends Ou{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}=wi(Fb(s,i)),h=new O(r,a);if(i.absolutePositioned)return{center:Ir(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}}}}E(uy,"type","clip-path"),V.setClass(uy);class dy extends Ou{getInitialSize(t,e){let{target:s}=t,{size:i}=e;return new O(s.width||i.x,s.height||i.y)}}E(dy,"type","fixed"),V.setClass(dy);class px extends Zh{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 Wr extends Si{static getDefaults(){return T(T({},super.getDefaults()),Wr.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,Wr.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))?(Yi("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===og?s.forEach(i=>{i._onAfterObjectsChange(Pu,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(Wr,"type","ActiveSelection"),E(Wr,"ownDefaults",{multiSelectionStacking:"canvas-stacking"}),V.setClass(Wr),V.setClass(Wr,"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 fy{constructor(){let{tileSize:t=pt.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=qs({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,b=g.height,_=f.destinationWidth,y=f.destinationHeight;p===_&&b===y||(g.width=_,g.height=y)}(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,b=t.createTexture();return t.bindTexture(a,b),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),b}getCachedTexture(t,e,s){const{textureCache:i}=this;if(i[t])return i[t];{const n=this.createTexture(this.gl,e.width,e.height,e,s);return n&&(i[t]=n),n}}evictCachesForKey(t){this.textureCache[t]&&(this.gl.deleteTexture(this.textureCache[t]),delete this.textureCache[t])}copyGLTo2D(t,e){const s=t.canvas,i=e.targetCanvas,n=i.getContext("2d");if(!n)return;n.translate(0,i.height),n.scale(1,-1);const r=s.height-i.height;n.drawImage(s,0,r,i.width,i.height,0,0,i.width,i.height)}copyGLTo2DPutImageData(t,e){const s=e.targetCanvas.getContext("2d"),i=e.destinationWidth,n=e.destinationHeight,r=i*n*4;if(!s)return;const 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 yg;function bx(){const{WebGLProbe:o}=_i();return o.queryWebGL(Ms()),pt.enableGLFiltering&&o.isSupported(pt.textureSize)?new fy({tileSize:pt.textureSize}):new mx}function vg(){return!yg&&(!(arguments.length>0&&arguments[0]!==void 0)||arguments[0])&&(yg=bx()),yg}const yx=["filters","resizeFilter","src","crossOrigin","type"],gy=["cropX","cropY"];class ke extends Te{static getDefaults(){return T(T({},super.getDefaults()),ke.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,ke.ownDefaults),this.setOptions(e),this.cacheKey="texture".concat(zn()),this.setElement(typeof t=="string"?(this.canvas&&Ks(this.canvas.getElement())||ro()).getElementById(t):t,e)}getElement(){return this._element}setElement(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._element=t,this._originalElement=t,this._setWidthHeight(e),t.classList.add(ke.CSS_CANVAS),this.filters.length!==0&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){const e=vg(!1);e instanceof fy&&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&&_i().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([...gy,...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=zn();n.push('<clipPath id="imageCrop_'+c+`">
|
|
87
87
|
`,' <rect x="'+s+'" y="'+i+'" width="'+this.width+'" height="'+this.height+`" />
|
|
88
88
|
`,`</clipPath>
|
|
89
|
-
`),
|
|
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>
|
|
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!==Qt?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 Oh(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=Us(r),{width:h,height:c}=r;this._element=o,this._lastScaleX=t.scaleX=i,this._lastScaleY=t.scaleY=n,Kg().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=Us({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);Kg().applyFilters(t,this._originalElement,s,i,this._element),this._originalElement.width===this._element.width&&this._originalElement.height===this._element.height||(this._filterScalingX=this._element.width/this._originalElement.width,this._filterScalingY=this._element.height/this._originalElement.height)}_render(t){t.imageSmoothingEnabled=this.imageSmoothing,this.isMoving!==!0&&this.resizeFilter&&this._needsResize()&&this.applyResizeFilters(),this._stroke(t),this._renderPaintInOrder(t)}drawCacheOnCanvas(t){t.imageSmoothingEnabled=this.imageSmoothing,super.drawCacheOnCanvas(t)}shouldCache(){return this.needsItsOwnCache()}_renderFill(t){const e=this._element;if(!e)return;const s=this._filterScalingX,i=this._filterScalingY,n=this.width,r=this.height,o=Math.max(this.cropX,0),h=Math.max(this.cropY,0),c=e.naturalWidth||e.width,u=e.naturalHeight||e.height,d=o*s,g=h*i,f=Math.min(n*s,c-d),p=Math.min(r*i,u-g),m=-n/2,w=-r/2,b=Math.min(n,c/s-o),x=Math.min(r,u/i-h);e&&t.drawImage(e,d,g,f,p,m,w,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=mg(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,g=0,f=0;return!t||t.alignX===Ie&&t.alignY===Ie?(h=e/r,c=s/o):(t.meetOrSlice==="meet"&&(h=c=p0(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=m0(this._element,i),n=r-e/h,t.alignX==="Mid"&&(g=n/2),t.alignX==="Max"&&(g=n),n=o-s/c,t.alignY==="Mid"&&(f=n/2),t.alignY==="Max"&&(f=n),r=e/h,o=s/c)),{width:r,height:o,scaleX:h,scaleY:c,offsetLeft:u,offsetTop:d,cropX:g,cropY:f}}static fromObject(t,e){let{filters:s,resizeFilter:i,src:n,crossOrigin:r,type:o}=t,h=Dt(t,Yw);return Promise.all([Oh(n,T(T({},e),{},{crossOrigin:r})),s&&Zo(s,e),i&&Zo([i],e),Dh(h,e)]).then(c=>{let[u,d=[],[g]=[],f={}]=c;return new this(u,T(T({},h),{},{src:n,filters:d,resizeFilter:g},f))})}static fromURL(t){let{crossOrigin:e=null,signal:s}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;return Oh(t,{crossOrigin:e,signal:s}).then(n=>new this(n,i))}static async fromElement(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0;const i=Ji(t,this.ATTRIBUTE_NAMES,s);return this.fromURL(i["xlink:href"],e,i).catch(n=>(Ui("log","Unable to parse Image",n),null))}}function Jg(a){if(!Qy.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,g=!(t&&Rm.test(t)),f=!h||!c||h==="100%"||c==="100%";let p="",m=0,w=0;if(g&&(u||d)&&a.parentNode&&a.parentNode.nodeName!=="#document"&&(p=" translate("+Be(u||"0")+" "+Be(d||"0")+") ",e=(a.getAttribute("transform")||"")+p,a.setAttribute("transform",e),a.removeAttribute("x"),a.removeAttribute("y")),g&&f)return{width:0,height:0};const b={width:0,height:0};if(g)return b.width=Be(h),b.height=Be(c),b;const x=t.match(Rm);r=-parseFloat(x[1]),o=-parseFloat(x[2]);const C=parseFloat(x[3]),A=parseFloat(x[4]);b.minX=r,b.minY=o,b.viewBoxWidth=C,b.viewBoxHeight=A,f?(b.width=C,b.height=A):(b.width=Be(h),b.height=Be(c),i=b.width/C,n=b.height/A);const P=mg(a.getAttribute("preserveAspectRatio")||"");if(P.alignX!==Ie&&(P.meetOrSlice==="meet"&&(n=i=i>n?n:i),P.meetOrSlice==="slice"&&(n=i=i>n?i:n),m=b.width-C*i,w=b.height-A*i,P.alignX==="Mid"&&(m/=2),P.alignY==="Mid"&&(w/=2),P.alignX==="Min"&&(m=0),P.alignY==="Min"&&(w=0)),i===1&&n===1&&r===0&&o===0&&u===0&&d===0)return b;if((u||d)&&a.parentNode.nodeName!=="#document"&&(p=" translate("+Be(u||"0")+" "+Be(d||"0")+") "),e=p+" matrix("+i+" 0 0 "+n+" "+(r*i+m)+" "+(o*n+w)+") ",a.nodeName==="svg"){for(s=a.ownerDocument.createElementNS(xg,"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}E(Te,"type","Image"),E(Te,"cacheProperties",[...qi,...U0]),E(Te,"ownDefaults",{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),E(Te,"CSS_CANVAS","canvas-img"),E(Te,"ATTRIBUTE_NAMES",[...Vn,"x","y","width","height","preserveAspectRatio","xlink:href","crossOrigin","image-rendering"]),W.setClass(Te),W.setSVGClass(Te);const Su=a=>a.tagName.replace("svg:",""),$w=Qc(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);function Y0(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 qw=["gradientTransform","x1","x2","y1","y2","gradientUnits","cx","cy","r","fx","fy"],Qg="xlink:href";function $0(a,t){var e;const s=((e=t.getAttribute(Qg))===null||e===void 0?void 0:e.slice(1))||"",i=a.getElementById(s);if(i&&i.getAttribute(Qg)&&$0(a,i),i&&(qw.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(Qg)}const Kw=["linearGradient","radialGradient","svg:linearGradient","svg:radialGradient"];function Jw(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(),g=u[1].trim();h[d]=g}(r=o[0].trim()).split(",").forEach(u=>{(u=u.replace(/^svg/i,"").trim())!==""&&(i[u]=T(T({},i[u]||{}),h))})})}return i}const q0=a=>W.getSVGClass(Su(a).toLowerCase());class Qw{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=Y0(r,Kw),h={};let c=o.length;for(;c--;){const u=o[c];u.getAttribute("xlink:href")&&$0(r,u);const d=u.getAttribute("id");d&&(h[d]=u)}return h}(i),this.cssRules=Jw(i)}parse(){return Promise.all(this.elements.map(t=>this.createObject(t)))}async createObject(t){const e=q0(t);if(e){const s=await e.fromElement(t,this.options,this.cssRules);return this.resolveGradient(s,t,Qt),this.resolveGradient(s,t,Ne),s instanceof Te&&s._originalElement?fu(s,s.parsePreserveAspectRatioAttribute()):fu(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=Vh.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=Ze(t.calcTransformMatrix()),r=i[0].parentElement;let o=e;for(;!s&&o.parentElement&&o.getAttribute("clip-path")!==t.clipPath;)o=o.parentElement;o.parentElement.appendChild(r);const h=hu("".concat(o.getAttribute("transform")||""," ").concat(r.getAttribute("originalTransform")||""));r.setAttribute("transform","matrix(".concat(h.join(","),")"));const c=await Promise.all(i.map(x=>q0(x).fromElement(x,this.options,this.cssRules).then(C=>(fu(C),C.fillRule=C.clipRule,delete C.clipRule,C)))),u=c.length===1?c[0]:new wi(c),d=Yt(n,u.calcTransformMatrix());u.clipPath&&await this.resolveClipPath(u,o,r.getAttribute("clip-path")?o:void 0);const{scaleX:g,scaleY:f,angle:p,skewX:m,translateX:w,translateY:b}=Tr(d);u.set({flipX:!1,flipY:!1}),u.set({scaleX:g,scaleY:f,angle:p,skewX:m,skewY:0}),u.setPositionByOrigin(new O(w,b),tt,tt),t.clipPath=u}else delete t.clipPath}}const K0=a=>Jy.test(Su(a)),Zg=()=>({objects:[],elements:[],options:{},allElements:[]});async function Zw(a,t){let{crossOrigin:e,signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(s&&s.aborted)return Ui("log",new sg("parseSVGDocument")),Zg();const i=a.documentElement;(function(u){const d=Y0(u,["use","svg:use"]),g=["x","y","xlink:href","href","transform"];for(const f of d){const p=f.attributes,m={};for(const R of p)R.value&&(m[R.name]=R.value);const w=(m["xlink:href"]||m.href||"").slice(1);if(w==="")return;const b=u.getElementById(w);if(b===null)return;let x=b.cloneNode(!0);const C=x.attributes,A={};for(const R of C)R.value&&(A[R.name]=R.value);const{x:P=0,y:D=0,transform:k=""}=m,M="".concat(k," ").concat(A.transform||""," translate(").concat(P,", ").concat(D,")");if(Jg(x),/^svg$/i.test(x.nodeName)){const R=x.ownerDocument.createElementNS(xg,"g");Object.entries(A).forEach(F=>{let[I,X]=F;return R.setAttributeNS(xg,I,X)}),R.append(...x.childNodes),x=R}for(const R of p){if(!R)continue;const{name:F,value:I}=R;if(!g.includes(F))if(F==="style"){const X={};jg(I,X),Object.entries(A).forEach(N=>{let[nt,K]=N;X[nt]=K}),jg(A.style||"",X);const j=Object.entries(X).map(N=>N.join(":")).join(";");x.setAttribute(F,j)}else!A[F]&&x.setAttribute(F,I)}x.setAttribute("transform",M),x.setAttribute("instantiated_by_use","1"),x.removeAttribute("id"),f.parentNode.replaceChild(x,f)}})(a);const n=Array.from(i.getElementsByTagName("*")),r=T(T({},Jg(i)),{},{crossOrigin:e,signal:s}),o=n.filter(u=>(Jg(u),K0(u)&&!function(d){let g=d;for(;g&&(g=g.parentElement);)if(g&&g.nodeName&&$w.test(Su(g))&&!g.getAttribute("instantiated_by_use"))return!0;return!1}(u)));if(!o||o&&!o.length)return T(T({},Zg()),{},{options:r,allElements:n});const h={};return n.filter(u=>Su(u)==="clipPath").forEach(u=>{u.setAttribute("originalTransform",u.getAttribute("transform")||"");const d=u.getAttribute("id");h[d]=Array.from(u.getElementsByTagName("*")).filter(g=>K0(g))}),{objects:await new Qw(o,r,t,a,h).parse(),elements:o,options:r,allElements:n}}function tx(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return new Promise((s,i)=>{k0(a.replace(/^\n\s*/,"").trim(),{onComplete:n=>{const r=n.responseXML;r&&s(r),i()},signal:e.signal})}).then(s=>Zw(s,t,e)).catch(()=>Zg())}const Cu=a=>a.webgl!==void 0,tf="precision highp float",ex=`
|
|
92
|
-
`.concat(
|
|
91
|
+
`)],this.fill=c}return n=this.paintFirst!==Zt?n.concat(r,t):n.concat(t,r),n}getSrc(t){const e=t?this._element:this._originalElement;return e?e.toDataURL?e.toDataURL():this.srcFromAttribute?e.getAttribute("src")||"":e.src:this.src||""}getSvgSrc(t){return this.getSrc(t)}setSrc(t){let{crossOrigin:e,signal:s}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return Xh(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=qs(r),{width:h,height:c}=r;this._element=a,this._lastScaleX=t.scaleX=i,this._lastScaleY=t.scaleY=n,vg().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=qs({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);vg().applyFilters(t,this._originalElement,s,i,this._element),this._originalElement.width===this._element.width&&this._originalElement.height===this._element.height||(this._filterScalingX=this._element.width/this._originalElement.width,this._filterScalingY=this._element.height/this._originalElement.height)}_render(t){t.imageSmoothingEnabled=this.imageSmoothing,this.isMoving!==!0&&this.resizeFilter&&this._needsResize()&&this.applyResizeFilters(),this._stroke(t),this._renderPaintInOrder(t)}drawCacheOnCanvas(t){t.imageSmoothingEnabled=this.imageSmoothing,super.drawCacheOnCanvas(t)}shouldCache(){return this.needsItsOwnCache()}_renderFill(t){const e=this._element;if(!e)return;const s=this._filterScalingX,i=this._filterScalingY,n=this.width,r=this.height,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),b=-n/2,_=-r/2,y=Math.min(n,c/s-a),x=Math.min(r,u/i-h);e&&t.drawImage(e,d,f,g,p,b,_,y,x)}_needsResize(){const t=this.getTotalObjectScaling();return t.x!==this._lastScaleX||t.y!==this._lastScaleY}_resetWidthHeight(){this.set(this.getOriginalSize())}_setWidthHeight(){let{width:t,height:e}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const s=this.getOriginalSize();this.width=t||s.width,this.height=e||s.height}parsePreserveAspectRatioAttribute(){const t=Bf(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===Be&&t.alignY===Be?(h=e/r,c=s/a):(t.meetOrSlice==="meet"&&(h=c=jb(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=Nb(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,yx);return Promise.all([Xh(n,T(T({},e),{},{crossOrigin:r})),s&&uo(s,e),i&&uo([i],e),Uh(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 Xh(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=Qi(t,this.ATTRIBUTE_NAMES,s);return this.fromURL(i["xlink:href"],e,i).catch(n=>(Yi("log","Unable to parse Image",n),null))}}function _g(o){if(!S_.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&&eb.test(t)),g=!h||!c||h==="100%"||c==="100%";let p="",b=0,_=0;if(f&&(u||d)&&o.parentNode&&o.parentNode.nodeName!=="#document"&&(p=" translate("+We(u||"0")+" "+We(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 y={width:0,height:0};if(f)return y.width=We(h),y.height=We(c),y;const x=t.match(eb);r=-parseFloat(x[1]),a=-parseFloat(x[2]);const C=parseFloat(x[3]),A=parseFloat(x[4]);y.minX=r,y.minY=a,y.viewBoxWidth=C,y.viewBoxHeight=A,g?(y.width=C,y.height=A):(y.width=We(h),y.height=We(c),i=y.width/C,n=y.height/A);const P=Bf(o.getAttribute("preserveAspectRatio")||"");if(P.alignX!==Be&&(P.meetOrSlice==="meet"&&(n=i=i>n?n:i),P.meetOrSlice==="slice"&&(n=i=i>n?i:n),b=y.width-C*i,_=y.height-A*i,P.alignX==="Mid"&&(b/=2),P.alignY==="Mid"&&(_/=2),P.alignX==="Min"&&(b=0),P.alignY==="Min"&&(_=0)),i===1&&n===1&&r===0&&a===0&&u===0&&d===0)return y;if((u||d)&&o.parentNode.nodeName!=="#document"&&(p=" translate("+We(u||"0")+" "+We(d||"0")+") "),e=p+" matrix("+i+" 0 0 "+n+" "+(r*i+b)+" "+(a*n+_)+") ",o.nodeName==="svg"){for(s=o.ownerDocument.createElementNS(Xf,"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),y}E(ke,"type","Image"),E(ke,"cacheProperties",[...Ki,...gy]),E(ke,"ownDefaults",{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),E(ke,"CSS_CANVAS","canvas-img"),E(ke,"ATTRIBUTE_NAMES",[...Xn,"x","y","width","height","preserveAspectRatio","xlink:href","crossOrigin","image-rendering"]),V.setClass(ke),V.setSVGClass(ke);const zu=o=>o.tagName.replace("svg:",""),vx=yu(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);function py(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 _x=["gradientTransform","x1","x2","y1","y2","gradientUnits","cx","cy","r","fx","fy"],wg="xlink:href";function my(o,t){var e;const s=((e=t.getAttribute(wg))===null||e===void 0?void 0:e.slice(1))||"",i=o.getElementById(s);if(i&&i.getAttribute(wg)&&my(o,i),i&&(_x.forEach(n=>{const r=i.getAttribute(n);!t.hasAttribute(n)&&r&&t.setAttribute(n,r)}),!t.children.length)){const n=i.cloneNode(!0);for(;n.firstChild;)t.appendChild(n.firstChild)}t.removeAttribute(wg)}const wx=["linearGradient","radialGradient","svg:linearGradient","svg:radialGradient"];function xx(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 by=o=>V.getSVGClass(zu(o).toLowerCase());class Sx{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=py(r,wx),h={};let c=a.length;for(;c--;){const u=a[c];u.getAttribute("xlink:href")&&my(r,u);const d=u.getAttribute("id");d&&(h[d]=u)}return h}(i),this.cssRules=xx(i)}parse(){return Promise.all(this.elements.map(t=>this.createObject(t)))}async createObject(t){const e=by(t);if(e){const s=await e.fromElement(t,this.options,this.cssRules);return this.resolveGradient(s,t,Zt),this.resolveGradient(s,t,Ve),s instanceof ke&&s._originalElement?Lu(s,s.parsePreserveAspectRatioAttribute()):Lu(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=el.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=ss(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=ku("".concat(a.getAttribute("transform")||""," ").concat(r.getAttribute("originalTransform")||""));r.setAttribute("transform","matrix(".concat(h.join(","),")"));const c=await Promise.all(i.map(x=>by(x).fromElement(x,this.options,this.cssRules).then(C=>(Lu(C),C.fillRule=C.clipRule,delete C.clipRule,C)))),u=c.length===1?c[0]:new Si(c),d=$t(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:b,translateX:_,translateY:y}=Rr(d);u.set({flipX:!1,flipY:!1}),u.set({scaleX:f,scaleY:g,angle:p,skewX:b,skewY:0}),u.setPositionByOrigin(new O(_,y),et,et),t.clipPath=u}else delete t.clipPath}}const yy=o=>x_.test(zu(o)),xg=()=>({objects:[],elements:[],options:{},allElements:[]});async function Cx(o,t){let{crossOrigin:e,signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(s&&s.aborted)return Yi("log",new Af("parseSVGDocument")),xg();const i=o.documentElement;(function(u){const d=py(u,["use","svg:use"]),f=["x","y","xlink:href","href","transform"];for(const g of d){const p=g.attributes,b={};for(const R of p)R.value&&(b[R.name]=R.value);const _=(b["xlink:href"]||b.href||"").slice(1);if(_==="")return;const y=u.getElementById(_);if(y===null)return;let x=y.cloneNode(!0);const C=x.attributes,A={};for(const R of C)R.value&&(A[R.name]=R.value);const{x:P=0,y:D=0,transform:k=""}=b,M="".concat(k," ").concat(A.transform||""," translate(").concat(P,", ").concat(D,")");if(_g(x),/^svg$/i.test(x.nodeName)){const R=x.ownerDocument.createElementNS(Xf,"g");Object.entries(A).forEach(F=>{let[I,Y]=F;return R.setAttributeNS(Xf,I,Y)}),R.append(...x.childNodes),x=R}for(const R of p){if(!R)continue;const{name:F,value:I}=R;if(!f.includes(F))if(F==="style"){const Y={};ag(I,Y),Object.entries(A).forEach(H=>{let[at,j]=H;Y[at]=j}),ag(A.style||"",Y);const N=Object.entries(Y).map(H=>H.join(":")).join(";");x.setAttribute(F,N)}else!A[F]&&x.setAttribute(F,I)}x.setAttribute("transform",M),x.setAttribute("instantiated_by_use","1"),x.removeAttribute("id"),g.parentNode.replaceChild(x,g)}})(o);const n=Array.from(i.getElementsByTagName("*")),r=T(T({},_g(i)),{},{crossOrigin:e,signal:s}),a=n.filter(u=>(_g(u),yy(u)&&!function(d){let f=d;for(;f&&(f=f.parentElement);)if(f&&f.nodeName&&vx.test(zu(f))&&!f.getAttribute("instantiated_by_use"))return!0;return!1}(u)));if(!a||a&&!a.length)return T(T({},xg()),{},{options:r,allElements:n});const h={};return n.filter(u=>zu(u)==="clipPath").forEach(u=>{u.setAttribute("originalTransform",u.getAttribute("transform")||"");const d=u.getAttribute("id");h[d]=Array.from(u.getElementsByTagName("*")).filter(f=>yy(f))}),{objects:await new Sx(a,r,t,o,h).parse(),elements:a,options:r,allElements:n}}function Ax(o,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return new Promise((s,i)=>{Kb(o.replace(/^\n\s*/,"").trim(),{onComplete:n=>{const r=n.responseXML;r&&s(r),i()},signal:e.signal})}).then(s=>Cx(s,t,e)).catch(()=>xg())}const Gu=o=>o.webgl!==void 0,Sg="precision highp float",Tx=`
|
|
92
|
+
`.concat(Sg,`;
|
|
93
93
|
varying vec2 vTexCoord;
|
|
94
94
|
uniform sampler2D uTexture;
|
|
95
95
|
void main() {
|
|
96
96
|
gl_FragColor = texture2D(uTexture, vTexCoord);
|
|
97
|
-
}`),
|
|
97
|
+
}`),Ex=["type"],kx=["type"],Px=new RegExp(Sg,"g");class ae{get type(){return this.constructor.type}constructor(){let t=Lt(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},Ex);Object.assign(this,this.constructor.defaults,t)}getFragmentSource(){return Tx}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"}}=
|
|
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"}}=_i();i!=="highp"&&(e=e.replace(Px,Sg.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 vi("Vertex, fragment shader or program creation error");if(t.shaderSource(n,s),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new vi("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 vi("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 vi('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){Gu(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=qs({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,kx))}}E(ae,"type","BaseFilter"),E(ae,"uniformLocations",[]);const Mx={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
|
|
130
|
+
`};class Xu extends ae{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(
|
|
139
|
+
`.concat(Mx[this.mode],`
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
`)}applyTo2d(t){let{imageData:{data:e}}=t;const s=new
|
|
142
|
+
`)}applyTo2d(t){let{imageData:{data:e}}=t;const s=new wt(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,b;switch(this.mode){case"multiply":g=u*n/255,p=d*r/255,b=f*a/255;break;case"screen":g=255-(255-u)*(255-n)/255,p=255-(255-d)*(255-r)/255,b=255-(255-f)*(255-a)/255;break;case"add":g=u+n,p=d+r,b=f+a;break;case"difference":g=Math.abs(u-n),p=Math.abs(d-r),b=Math.abs(f-a);break;case"subtract":g=u-n,p=d-r,b=f-a;break;case"darken":g=Math.min(u,n),p=Math.min(d,r),b=Math.min(f,a);break;case"lighten":g=Math.max(u,n),p=Math.max(d,r),b=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,b=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,b=a+f-2*a*f/255;break;case"tint":g=n+u*h,p=r+d*h,b=a+f*h}e[c]=g,e[c+1]=p,e[c+2]=b}}sendUniformData(t,e){const s=new wt(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(Xu,"defaults",{color:"#F95C63",mode:"multiply",alpha:1}),E(Xu,"type","BlendColor"),E(Xu,"uniformLocations",["uColor"]),V.setClass(Xu);const Ox={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
|
-
`},
|
|
168
|
+
`},Dx=["type","image"];class Uu extends ae{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return Ox[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=
|
|
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=Ms());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],b=c[u],_=c[u+1],y=c[u+2],x=c[u+3];switch(this.mode){case"multiply":e[u]=d*b/255,e[u+1]=f*_/255,e[u+2]=g*y/255,e[u+3]=p*x/255;break;case"mask":e[u+3]=x}}}sendUniformData(t,e){const s=this.calculateMatrix();t.uniform1i(e.uImage,1),t.uniformMatrix3fv(e.uTransformMatrix,!1,s)}toObject(){return T(T({},super.toObject()),{},{image:this.image&&this.image.toObject()})}static async fromObject(t,e){let{type:s,image:i}=t,n=Lt(t,Dx);return ke.fromObject(i,e).then(r=>new this(T(T({},n),{},{image:r})))}}E(Uu,"type","BlendImage"),E(Uu,"defaults",{mode:"multiply",alpha:1}),E(Uu,"uniformLocations",["uTransformMatrix","uImage"]),V.setClass(Uu);class Yu extends ae{getFragmentSource(){return`
|
|
179
179
|
precision highp float;
|
|
180
180
|
uniform sampler2D uTexture;
|
|
181
181
|
uniform vec2 uDelta;
|
|
@@ -198,7 +198,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
198
198
|
}
|
|
199
199
|
gl_FragColor = color / total;
|
|
200
200
|
}
|
|
201
|
-
`}applyTo(t){
|
|
201
|
+
`}applyTo(t){Gu(t)?(this.aspectRatio=t.sourceWidth/t.sourceHeight,t.passes++,this._setupFrameBuffer(t),this.horizontal=!0,this.applyToWebGL(t),this._swapTextures(t),this._setupFrameBuffer(t),this.horizontal=!1,this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){t.imageData=this.simpleBlur(t)}simpleBlur(t){let{ctx:e,imageData:s,filterBackend:{resources:i}}=t;const{width:n,height:r}=s;i.blurLayer1||(i.blurLayer1=Ms(),i.blurLayer2=Ms());const 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,b,_;for(c.putImageData(s,0,0),u.clearRect(0,0,n,r),_=-15;_<=d;_++)g=(Math.random()-.5)/4,p=_/d,b=f*p*n+g,u.globalAlpha=1-Math.abs(p),u.drawImage(a,b,g),c.drawImage(h,0,0),u.globalAlpha=1,u.clearRect(0,0,h.width,h.height);for(_=-15;_<=d;_++)g=(Math.random()-.5)/4,p=_/d,b=f*p*r+g,u.globalAlpha=1-Math.abs(p),u.drawImage(a,g,b),c.drawImage(h,0,0),u.globalAlpha=1,u.clearRect(0,0,h.width,h.height);e.drawImage(a,0,0);const y=e.getImageData(0,0,a.width,a.height);return c.globalAlpha=1,c.clearRect(0,0,a.width,a.height),y}sendUniformData(t,e){const s=this.chooseRightDelta();t.uniform2fv(e.uDelta,s)}isNeutralState(){return this.blur===0}chooseRightDelta(){let t=1;const e=[0,0];this.horizontal?this.aspectRatio>1&&(t=1/this.aspectRatio):this.aspectRatio<1&&(t=this.aspectRatio);const s=t*this.blur*.12;return this.horizontal?e[0]=s:e[1]=s,e}}E(Yu,"type","Blur"),E(Yu,"defaults",{blur:0}),E(Yu,"uniformLocations",["uDelta"]),V.setClass(Yu);class $u extends ae{getFragmentSource(){return`
|
|
202
202
|
precision highp float;
|
|
203
203
|
uniform sampler2D uTexture;
|
|
204
204
|
uniform float uBrightness;
|
|
@@ -208,7 +208,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
208
208
|
color.rgb += uBrightness;
|
|
209
209
|
gl_FragColor = color;
|
|
210
210
|
}
|
|
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(
|
|
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($u,"type","Brightness"),E($u,"defaults",{brightness:0}),E($u,"uniformLocations",["uBrightness"]),V.setClass($u);const vy={matrix:[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],colorsOnly:!0};class wo extends ae{getFragmentSource(){return`
|
|
212
212
|
precision highp float;
|
|
213
213
|
uniform sampler2D uTexture;
|
|
214
214
|
varying vec2 vTexCoord;
|
|
@@ -219,7 +219,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
219
219
|
color *= uColorMatrix;
|
|
220
220
|
color += uConstants;
|
|
221
221
|
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],
|
|
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 zr(o,t){var e;const s=(E(e=class extends wo{toObject(){return{type:this.type,colorsOnly:this.colorsOnly}}},"type",o),E(e,"defaults",{colorsOnly:!1,matrix:t}),e);return V.setClass(s,o),s}E(wo,"type","ColorMatrix"),E(wo,"defaults",vy),E(wo,"uniformLocations",["uColorMatrix","uConstants"]),V.setClass(wo),zr("Brownie",[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0]),zr("Vintage",[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0]),zr("Kodachrome",[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0]),zr("Technicolor",[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0]),zr("Polaroid",[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0]),zr("Sepia",[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0]),zr("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 _y extends ae{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.subFilters=t.subFilters||[]}applyTo(t){Gu(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=>V.getClass(s.type).fromObject(s,e))).then(s=>new this({subFilters:s}))}}E(_y,"type","Composed"),V.setClass(_y);class qu extends ae{getFragmentSource(){return`
|
|
223
223
|
precision highp float;
|
|
224
224
|
uniform sampler2D uTexture;
|
|
225
225
|
uniform float uContrast;
|
|
@@ -229,7 +229,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
229
229
|
float contrastF = 1.015 * (uContrast + 1.0) / (1.0 * (1.015 - uContrast));
|
|
230
230
|
color.rgb = contrastF * (color.rgb - 0.5) + 0.5;
|
|
231
231
|
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(
|
|
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(qu,"type","Contrast"),E(qu,"defaults",{contrast:0}),E(qu,"uniformLocations",["uContrast"]),V.setClass(qu);const Rx={Convolute_3_1:`
|
|
233
233
|
precision highp float;
|
|
234
234
|
uniform sampler2D uTexture;
|
|
235
235
|
uniform float uMatrix[9];
|
|
@@ -373,7 +373,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
373
373
|
gl_FragColor = color;
|
|
374
374
|
gl_FragColor.a = alpha;
|
|
375
375
|
}
|
|
376
|
-
`};class
|
|
376
|
+
`};class Ku extends ae{getCacheKey(){return"".concat(this.type,"_").concat(Math.sqrt(this.matrix.length),"_").concat(this.opaque?1:0)}getFragmentSource(){return Rx[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,b,_,y,x,C,A,P,D,k,M;for(D=0;D<h;D++)for(P=0;P<a;P++){for(_=4*(D*a+P),f=0,g=0,p=0,b=0,M=0;M<n;M++)for(k=0;k<n;k++)x=D+M-r,y=P+k-r,x<0||x>=h||y<0||y>=a||(C=4*(x*a+y),A=i[M*n+k],f+=s[C]*A,g+=s[C+1]*A,p+=s[C+2]*A,d||(b+=s[C+3]*A));u[_]=f,u[_+1]=g,u[_+2]=p,u[_+3]=d?s[_+3]:b}t.imageData=c}sendUniformData(t,e){t.uniform1fv(e.uMatrix,this.matrix)}toObject(){return T(T({},super.toObject()),{},{opaque:this.opaque,matrix:[...this.matrix]})}}E(Ku,"type","Convolute"),E(Ku,"defaults",{opaque:!1,matrix:[0,0,0,0,1,0,0,0,0]}),E(Ku,"uniformLocations",["uMatrix","uOpaque","uHalfSize","uSize"]),V.setClass(Ku);const wy="Gamma";class Ju extends ae{getFragmentSource(){return`
|
|
377
377
|
precision highp float;
|
|
378
378
|
uniform sampler2D uTexture;
|
|
379
379
|
uniform vec3 uGamma;
|
|
@@ -387,7 +387,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
387
387
|
gl_FragColor = color;
|
|
388
388
|
gl_FragColor.rgb *= color.a;
|
|
389
389
|
}
|
|
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
|
|
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:wy,gamma:this.gamma.concat()}}}E(Ju,"type",wy),E(Ju,"defaults",{gamma:[1,1,1]}),E(Ju,"uniformLocations",["uGamma"]),V.setClass(Ju);const Lx={average:`
|
|
391
391
|
precision highp float;
|
|
392
392
|
uniform sampler2D uTexture;
|
|
393
393
|
varying vec2 vTexCoord;
|
|
@@ -416,7 +416,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
416
416
|
float average = 0.21 * col.r + 0.72 * col.g + 0.07 * col.b;
|
|
417
417
|
gl_FragColor = vec4(average, average, average, col.a);
|
|
418
418
|
}
|
|
419
|
-
`};class
|
|
419
|
+
`};class Qu extends ae{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 Lx[this.mode]}sendUniformData(t,e){t.uniform1i(e.uMode,1)}isNeutralState(){return!1}}E(Qu,"type","Grayscale"),E(Qu,"defaults",{mode:"average"}),E(Qu,"uniformLocations",["uMode"]),V.setClass(Qu);const Fx=T(T({},vy),{},{rotation:0});class Cg extends wo{calculateMatrix(){const t=this.rotation*Math.PI,e=Ys(t),s=$s(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(Cg,"type","HueRotation"),E(Cg,"defaults",Fx),V.setClass(Cg);class Zu extends ae{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
420
|
precision highp float;
|
|
421
421
|
uniform sampler2D uTexture;
|
|
422
422
|
uniform int uInvert;
|
|
@@ -434,7 +434,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
434
434
|
gl_FragColor = color;
|
|
435
435
|
}
|
|
436
436
|
}
|
|
437
|
-
`}isNeutralState(){return!this.invert}sendUniformData(t,e){t.uniform1i(e.uInvert,Number(this.invert)),t.uniform1i(e.uAlpha,Number(this.alpha))}}E(
|
|
437
|
+
`}isNeutralState(){return!this.invert}sendUniformData(t,e){t.uniform1i(e.uInvert,Number(this.invert)),t.uniform1i(e.uAlpha,Number(this.alpha))}}E(Zu,"type","Invert"),E(Zu,"defaults",{alpha:!1,invert:!0}),E(Zu,"uniformLocations",["uInvert","uAlpha"]),V.setClass(Zu);class td extends ae{getFragmentSource(){return`
|
|
438
438
|
precision highp float;
|
|
439
439
|
uniform sampler2D uTexture;
|
|
440
440
|
uniform float uStepH;
|
|
@@ -449,7 +449,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
449
449
|
color.rgb += (0.5 - rand(vTexCoord, uSeed, 0.1 / uStepH)) * uNoise;
|
|
450
450
|
gl_FragColor = color;
|
|
451
451
|
}
|
|
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(
|
|
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(td,"type","Noise"),E(td,"defaults",{noise:0}),E(td,"uniformLocations",["uNoise","uSeed"]),V.setClass(td);class ed extends ae{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`
|
|
453
453
|
precision highp float;
|
|
454
454
|
uniform sampler2D uTexture;
|
|
455
455
|
uniform float uBlocksize;
|
|
@@ -467,7 +467,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
467
467
|
vec4 color = texture2D(uTexture, squareCoords);
|
|
468
468
|
gl_FragColor = color;
|
|
469
469
|
}
|
|
470
|
-
`}sendUniformData(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}}E(
|
|
470
|
+
`}sendUniformData(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}}E(ed,"type","Pixelate"),E(ed,"defaults",{blocksize:4}),E(ed,"uniformLocations",["uBlocksize"]),V.setClass(ed);class sd extends ae{getFragmentSource(){return`
|
|
471
471
|
precision highp float;
|
|
472
472
|
uniform sampler2D uTexture;
|
|
473
473
|
uniform vec4 uLow;
|
|
@@ -479,7 +479,7 @@ void main() {
|
|
|
479
479
|
gl_FragColor.a = 0.0;
|
|
480
480
|
}
|
|
481
481
|
}
|
|
482
|
-
`}applyTo2d(t){let{imageData:{data:e}}=t;const s=255*this.distance,i=new
|
|
482
|
+
`}applyTo2d(t){let{imageData:{data:e}}=t;const s=255*this.distance,i=new wt(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 wt(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(sd,"type","RemoveColor"),E(sd,"defaults",{color:"#FFFFFF",distance:.02,useAlpha:!1}),E(sd,"uniformLocations",["uLow","uHigh"]),V.setClass(sd);class id extends ae{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
483
|
precision highp float;
|
|
484
484
|
uniform sampler2D uTexture;
|
|
485
485
|
uniform vec2 uDelta;
|
|
@@ -495,7 +495,7 @@ void main() {
|
|
|
495
495
|
`),`
|
|
496
496
|
gl_FragColor = color / sum;
|
|
497
497
|
}
|
|
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){
|
|
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){Gu(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 b=e;let _=0;f.sliceByTwo||(f.sliceByTwo=Ms());const y=f.sliceByTwo;(y.width<1.5*e||y.height<s)&&(y.width=1.5*e,y.height=s);const x=y.getContext("2d");for(x.clearRect(0,0,1.5*e,s),x.putImageData(r,0,0),i=Math.floor(i),n=Math.floor(n);!h||!c;)e=u,s=d,i<Math.floor(u*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(y,g,p,e,s,b,_,u,d),g=b,p=_,_+=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),b=Math.ceil(d*this.lanczosLobes/2),_={},y={x:0,y:0},x={x:0,y:0};return function C(A){let P,D,k,M,R,F,I,Y,N,H,at;for(y.x=(A+.5)*u,x.x=Math.floor(y.x),P=0;P<n;P++){for(y.y=(P+.5)*d,x.y=Math.floor(y.y),R=0,F=0,I=0,Y=0,N=0,D=x.x-p;D<=x.x+p;D++)if(!(D<0||D>=e)){H=Math.floor(1e3*Math.abs(D-y.x)),_[H]||(_[H]={});for(let j=x.y-b;j<=x.y+b;j++)j<0||j>=s||(at=Math.floor(1e3*Math.abs(j-y.y)),_[H][at]||(_[H][at]=c(Math.sqrt(Math.pow(H*f,2)+Math.pow(at*g,2))/1e3)),k=_[H][at],k>0&&(M=4*(j*e+D),R+=k,F+=k*r[M],I+=k*r[M+1],Y+=k*r[M+2],N+=k*r[M+3]))}M=4*(P*i+A),h[M]=F/R,h[M+1]=I/R,h[M+2]=Y/R,h[M+3]=N/R}return++A<i?C(A):a}(0)}bilinearFiltering(t,e,s,i,n){let r,a,h,c,u,d,f,g,p,b,_,y,x,C=0;const A=this.rcpScaleX,P=this.rcpScaleY,D=4*(e-1),k=t.imageData.data,M=t.ctx.createImageData(i,n),R=M.data;for(f=0;f<n;f++)for(g=0;g<i;g++)for(u=Math.floor(A*g),d=Math.floor(P*f),p=A*g-u,b=P*f-d,x=4*(d*e+u),_=0;_<4;_++)r=k[x+_],a=k[x+4+_],h=k[x+D+_],c=k[x+D+4+_],y=r*(1-p)*(1-b)+a*p*(1-b)+h*b*(1-p)+c*p*b,R[C++]=y;return M}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 b=4*(p+g*i);let _=0,y=0,x=0,C=0,A=0,P=0,D=0;const k=(g+.5)*a;for(let M=Math.floor(g*a);M<(g+1)*a;M++){const R=Math.abs(k-(M+.5))/c,F=(p+.5)*r,I=R*R;for(let Y=Math.floor(p*r);Y<(p+1)*r;Y++){let N=Math.abs(F-(Y+.5))/h;const H=Math.sqrt(I+N*N);H>1&&H<-1||(_=2*H*H*H-3*H*H+1,_>0&&(N=4*(Y+M*e),D+=_*u[N+3],x+=_,u[N+3]<255&&(_=_*u[N+3]/250),C+=_*u[N],A+=_*u[N+1],P+=_*u[N+2],y+=_))}}f[b]=C/y,f[b+1]=A/y,f[b+2]=P/y,f[b+3]=D/x}return d}}E(id,"type","Resize"),E(id,"defaults",{resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3}),E(id,"uniformLocations",["uDelta","uTaps"]),V.setClass(id);class nd extends ae{getFragmentSource(){return`
|
|
499
499
|
precision highp float;
|
|
500
500
|
uniform sampler2D uTexture;
|
|
501
501
|
uniform float uSaturation;
|
|
@@ -509,7 +509,7 @@ void main() {
|
|
|
509
509
|
color.b += rgbMax != color.b ? (rgbMax - color.b) * uSaturation : 0.00;
|
|
510
510
|
gl_FragColor = color;
|
|
511
511
|
}
|
|
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],
|
|
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(nd,"type","Saturation"),E(nd,"defaults",{saturation:0}),E(nd,"uniformLocations",["uSaturation"]),V.setClass(nd);class rd extends ae{getFragmentSource(){return`
|
|
513
513
|
precision highp float;
|
|
514
514
|
uniform sampler2D uTexture;
|
|
515
515
|
uniform float uVibrance;
|
|
@@ -524,15 +524,15 @@ void main() {
|
|
|
524
524
|
color.b += max != color.b ? (max - color.b) * amt : 0.00;
|
|
525
525
|
gl_FragColor = color;
|
|
526
526
|
}
|
|
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],o=e[i+2],h=Math.max(n,r,o),c=(n+r+o)/3,u=2*Math.abs(h-c)/255*s;e[i]+=h!==n?(h-n)*u:0,e[i+1]+=h!==r?(h-r)*u:0,e[i+2]+=h!==o?(h-o)*u:0}}sendUniformData(t,e){t.uniform1f(e.uVibrance,-this.vibrance)}isNeutralState(){return this.vibrance===0}}E(Bu,"type","Vibrance"),E(Bu,"defaults",{vibrance:0}),E(Bu,"uniformLocations",["uVibrance"]),W.setClass(Bu);const ux="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2040%2040'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3ccircle%20cx='20'%20cy='20'%20r='10.75'%20stroke='currentColor'%20stroke-width='2.5'/%3e%3cpath%20d='M16%2024L23.7782%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3cpath%20d='M24%2024L16.2218%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3c/svg%3e";function dx(a){return new URL(Object.assign({"../assets/close.svg":ux})[`../assets/${a}`],typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Pt&&Pt.tagName.toUpperCase()==="SCRIPT"&&Pt.src||new URL("pdf-canvas.umd.js",document.baseURI).href).href}function gx(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 fx(i))}),i.addEventListener("error",n=>{window.URL.revokeObjectURL(s),e(n)})})}function fx(a){return new Promise(t=>{const e=document.createElement("canvas"),s=e.getContext("2d"),{naturalWidth:i,naturalHeight:n}=a;e.width=i,e.height=n,s==null||s.drawImage(a,0,0,i,n),t(e.toDataURL("image/jpeg",.8))})}let tv=null;function px(){const a=document.createElement("div");a.style.width="1in",document.body.append(a);const t=a.offsetWidth;return a.remove(),t}function mx(){const a=tv??px();return tv=a,a/72}function vx(a,t=500){if(typeof a!="function")throw new TypeError("The first argument is not a function.");let e=null;return function(...s){e&&clearTimeout(e),e=setTimeout(()=>{e=null,a.apply(this,s)},t)}}const Es=new Map;function bx(a){const t=new Wg(a);return Es.set(a,t),t}function yx(a,t){const e=Date.now();return{PDFId:`${a.name}-${e}`,name:a.name.replace(/.pdf/,""),updateDate:e,PDFBase64:t}}function _x(a,t){const e=a.getViewport({scale:t}),s=document.createElement("canvas"),i=s.getContext("2d"),n=mx()/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 wx(a,t,e){const s=a||dx("close.svg"),{objects:i,options:n}=await tx(s),r=i.filter(h=>h!==null),o=fw.groupSVGElements(r,n);return r.forEach(h=>{h.stroke=t}),o.hoverCursor="pointer",o.stroke=`${t}-${e}`,o}function xx(a,t){if(!Es.get(a))return;const s=1/3,i=kx(t,s);sv(a,i,s)}async function Sx(a,t){const e=await gx(t),s=Date.now(),n={PDFId:`${t.name}${s}`,name:t.name.replace(/.png|.jpg|.jpeg/,""),updateDate:s,PDFBase64:e};return ev(a,{url:e}),{...n,pages:1}}async function ev(a,{url:t,scale:e=.5}){if(!Es.get(a))return;const i=await Te.fromURL(t);i.scale(e),sv(a,i,e)}function sv(a,t,e){const s=Es.get(a);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function zh(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 Cx(a,t,e){!e||!a||(e.scale(1/t),zh(a,e))}function Ax(a,t,e){a&&(a.borderScaleFactor=1/t,a.cornerSize=6*(1/t),a.touchCornerSize=24*(1/t),a.cornerStrokeColor=e.stroke,a.setCoords())}function Tx(a){const t=Es.get(a);t&&(t.discardActiveObject(),t.renderAll())}function Ex(a){const t=Es.get(a);t&&(t.clear(),Es.delete(a))}function kx(a,t){return new Te(a,{scaleX:t,scaleY:t})}var Xh={};Xh.d=(a,t)=>{for(var e in t)Xh.o(t,e)&&!Xh.o(a,e)&&Object.defineProperty(a,e,{enumerable:!0,get:t[e]})},Xh.o=(a,t)=>Object.prototype.hasOwnProperty.call(a,t);var Z=globalThis.pdfjsLib={};Xh.d(Z,{AbortException:()=>jr,AnnotationEditorLayer:()=>Bf,AnnotationEditorParamsType:()=>ut,AnnotationEditorType:()=>it,AnnotationEditorUIManager:()=>Br,AnnotationLayer:()=>SC,AnnotationMode:()=>Wn,ColorPicker:()=>nd,DOMSVGFactory:()=>Pf,DrawLayer:()=>Hf,FeatureTest:()=>Ge,GlobalWorkerOptions:()=>rn,ImageKind:()=>Hu,InvalidPDFException:()=>nv,MissingPDFException:()=>Yh,OPS:()=>Zs,OutputScale:()=>pf,PDFDataRangeTransport:()=>Nv,PDFDateString:()=>gf,PDFWorker:()=>ua,PasswordResponses:()=>Dx,PermissionFlag:()=>Ox,PixelsPerInch:()=>Xn,RenderingCancelledException:()=>uf,TextLayer:()=>Zh,UnexpectedResponseException:()=>zu,Util:()=>$,VerbosityLevel:()=>Vu,XfaLayer:()=>Gv,build:()=>iC,createValidAbsoluteUrl:()=>Ix,fetchData:()=>Uu,getDocument:()=>$S,getFilenameFromUrl:()=>Xx,getPdfFilenameFromUrl:()=>Ux,getXfaPageViewport:()=>Yx,isDataScheme:()=>Yu,isPdfFile:()=>df,noContextMenu:()=>ti,normalizeUnicode:()=>Gx,setLayerDimensions:()=>Nr,shadow:()=>at,stopEvent:()=>ei,version:()=>sC});const Ve=typeof process=="object"&&process+""=="[object process]"&&!process.versions.nw&&!(process.versions.electron&&process.type&&process.type!=="browser"),iv=[1,0,0,1,0,0],sf=[.001,0,0,.001,0,0],Px=1e7,nf=1.35,cs={ANY:1,DISPLAY:2,PRINT:4,SAVE:8,ANNOTATIONS_FORMS:16,ANNOTATIONS_STORAGE:32,ANNOTATIONS_DISABLE:64,IS_EDITING:128,OPLIST:256},Wn={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},Mx="pdfjs_internal_editor_",it={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15},ut={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},Ox={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},Ee={FILL:0,STROKE:1,FILL_STROKE:2,INVISIBLE:3,FILL_ADD_TO_PATH:4,STROKE_ADD_TO_PATH:5,FILL_STROKE_ADD_TO_PATH:6,ADD_TO_PATH:7,FILL_STROKE_MASK:3,ADD_TO_PATH_FLAG:4},Hu={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},oe={TEXT:1,LINK:2,FREETEXT:3,LINE:4,SQUARE:5,CIRCLE:6,POLYGON:7,POLYLINE:8,HIGHLIGHT:9,UNDERLINE:10,SQUIGGLY:11,STRIKEOUT:12,STAMP:13,CARET:14,INK:15,POPUP:16,FILEATTACHMENT:17,SOUND:18,MOVIE:19,WIDGET:20,SCREEN:21,PRINTERMARK:22,TRAPNET:23,WATERMARK:24,THREED:25,REDACT:26},Uh={SOLID:1,DASHED:2,BEVELED:3,INSET:4,UNDERLINE:5},Vu={ERRORS:0,WARNINGS:1,INFOS:5},Zs={dependency:1,setLineWidth:2,setLineCap:3,setLineJoin:4,setMiterLimit:5,setDash:6,setRenderingIntent:7,setFlatness:8,setGState:9,save:10,restore:11,transform:12,moveTo:13,lineTo:14,curveTo:15,curveTo2:16,curveTo3:17,closePath:18,rectangle:19,stroke:20,closeStroke:21,fill:22,eoFill:23,fillStroke:24,eoFillStroke:25,closeFillStroke:26,closeEOFillStroke:27,endPath:28,clip:29,eoClip:30,beginText:31,endText:32,setCharSpacing:33,setWordSpacing:34,setHScale:35,setLeading:36,setFont:37,setTextRenderingMode:38,setTextRise:39,moveText:40,setLeadingMoveText:41,setTextMatrix:42,nextLine:43,showText:44,showSpacedText:45,nextLineShowText:46,nextLineSetSpacingShowText:47,setCharWidth:48,setCharWidthAndBounds:49,setStrokeColorSpace:50,setFillColorSpace:51,setStrokeColor:52,setStrokeColorN:53,setFillColor:54,setFillColorN:55,setStrokeGray:56,setFillGray:57,setStrokeRGBColor:58,setFillRGBColor:59,setStrokeCMYKColor:60,setFillCMYKColor:61,shadingFill:62,beginInlineImage:63,beginImageData:64,endInlineImage:65,paintXObject:66,markPoint:67,markPointProps:68,beginMarkedContent:69,beginMarkedContentProps:70,endMarkedContent:71,beginCompat:72,endCompat:73,paintFormXObjectBegin:74,paintFormXObjectEnd:75,beginGroup:76,endGroup:77,beginAnnotation:80,endAnnotation:81,paintImageMaskXObject:83,paintImageMaskXObjectGroup:84,paintImageXObject:85,paintInlineImageXObject:86,paintInlineImageXObjectGroup:87,paintImageXObjectRepeat:88,paintImageMaskXObjectRepeat:89,paintSolidColorImageMask:90,constructPath:91,setStrokeTransparent:92,setFillTransparent:93},Dx={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};let Gu=Vu.WARNINGS;function Rx(a){Number.isInteger(a)&&(Gu=a)}function Lx(){return Gu}function Wu(a){Gu>=Vu.INFOS&&console.log(`Info: ${a}`)}function rt(a){Gu>=Vu.WARNINGS&&console.log(`Warning: ${a}`)}function St(a){throw new Error(a)}function te(a,t){a||St(t)}function Fx(a){switch(a==null?void 0:a.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}function Ix(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=Vx(a)}catch{}}const s=t?new URL(a,t):new URL(a);if(Fx(s))return s}catch{}return null}function at(a,t,e,s=!1){return Object.defineProperty(a,t,{value:e,enumerable:!s,configurable:!0,writable:!1}),e}const zn=function(){function t(e,s){this.message=e,this.name=s}return t.prototype=new Error,t.constructor=t,t}();class rf extends zn{constructor(t,e){super(t,"PasswordException"),this.code=e}}class of extends zn{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}}class nv extends zn{constructor(t){super(t,"InvalidPDFException")}}class Yh extends zn{constructor(t){super(t,"MissingPDFException")}}class zu extends zn{constructor(t,e){super(t,"UnexpectedResponseException"),this.status=e}}class jx extends zn{constructor(t){super(t,"FormatError")}}class jr extends zn{constructor(t){super(t,"AbortException")}}function rv(a){(typeof a!="object"||(a==null?void 0:a.length)===void 0)&&St("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 Xu(a){typeof a!="string"&&St("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 Nx(a){return String.fromCharCode(a>>24&255,a>>16&255,a>>8&255,a&255)}function af(a){const t=Object.create(null);for(const[e,s]of a)t[e]=s;return t}function Bx(){const a=new Uint8Array(4);return a[0]=1,new Uint32Array(a.buffer,0,1)[0]===1}function Hx(){try{return new Function(""),!0}catch{return!1}}class Ge{static get isLittleEndian(){return at(this,"isLittleEndian",Bx())}static get isEvalSupported(){return at(this,"isEvalSupported",Hx())}static get isOffscreenCanvasSupported(){return at(this,"isOffscreenCanvasSupported",typeof OffscreenCanvas<"u")}static get isImageDecoderSupported(){return at(this,"isImageDecoderSupported",typeof ImageDecoder<"u")}static get platform(){return typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.platform)=="string"?at(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")}):at(this,"platform",{isMac:!1,isWindows:!1,isFirefox:!1})}static get isCSSRoundSupported(){var t,e;return at(this,"isCSSRoundSupported",(e=(t=globalThis.CSS)==null?void 0:t.supports)==null?void 0:e.call(t,"width: round(1.5px, 1px)"))}}const hf=Array.from(Array(256).keys(),a=>a.toString(16).padStart(2,"0"));class ${static makeHexColor(t,e,s){return`#${hf[t]}${hf[e]}${hf[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)],y(this,on,Zf).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),y(this,on,Zf).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}}on=new WeakSet,Pd=function(t,e,s,i,n,r,o,h,c,u){if(c<=0||c>=1)return;const d=1-c,g=c*c,f=g*c,p=d*(d*(d*t+3*c*e)+3*g*s)+f*i,m=d*(d*(d*n+3*c*r)+3*g*o)+f*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)},Zf=function(t,e,s,i,n,r,o,h,c,u,d,g){if(Math.abs(c)<1e-12){Math.abs(u)>=1e-12&&y(this,on,Pd).call(this,t,e,s,i,n,r,o,h,-d/u,g);return}const f=u**2-4*d*c;if(f<0)return;const p=Math.sqrt(f),m=2*c;y(this,on,Pd).call(this,t,e,s,i,n,r,o,h,(-u+p)/m,g),y(this,on,Pd).call(this,t,e,s,i,n,r,o,h,(-u-p)/m,g)},_($,on);function Vx(a){return decodeURIComponent(escape(a))}let lf=null,ov=null;function Gx(a){return lf||(lf=/([\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,ov=new Map([["ſt","ſt"]])),a.replaceAll(lf,(t,e,s)=>e?e.normalize("NFKC"):ov.get(s))}function Wx(){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();const a=new Uint8Array(32);return crypto.getRandomValues(a),rv(a)}const cf="pdfjs_internal_id_",sn={BEZIER_CURVE_TO:0,MOVE_TO:1,LINE_TO:2,QUADRATIC_CURVE_TO:3,RESTORE:4,SAVE:5,SCALE:6,TRANSFORM:7,TRANSLATE:8};function zx(a){return Uint8Array.prototype.toBase64?a.toBase64():btoa(rv(a))}typeof Promise.try!="function"&&(Promise.try=function(a,...t){return new Promise(e=>{e(a(...t))})});const nn="http://www.w3.org/2000/svg",Gr=class Gr{};q(Gr,"CSS",96),q(Gr,"PDF",72),q(Gr,"PDF_TO_CSS_UNITS",Gr.CSS/Gr.PDF);let Xn=Gr;async function Uu(a,t="text"){if(qh(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 $h{constructor({viewBox:t,scale:e,rotation:s,offsetX:i=0,offsetY:n=0,dontFlip:r=!1}){this.viewBox=t,this.scale=e,this.rotation=s,this.offsetX=i,this.offsetY=n;const o=(t[2]+t[0])/2,h=(t[3]+t[1])/2;let c,u,d,g;switch(s%=360,s<0&&(s+=360),s){case 180:c=-1,u=0,d=0,g=1;break;case 90:c=0,u=1,d=1,g=0;break;case 270:c=0,u=-1,d=-1,g=0;break;case 0:c=1,u=0,d=0,g=-1;break;default:throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.")}r&&(d=-d,g=-g);let f,p,m,w;c===0?(f=Math.abs(h-t[1])*e+i,p=Math.abs(o-t[0])*e+n,m=(t[3]-t[1])*e,w=(t[2]-t[0])*e):(f=Math.abs(o-t[0])*e+i,p=Math.abs(h-t[1])*e+n,m=(t[2]-t[0])*e,w=(t[3]-t[1])*e),this.transform=[c*e,u*e,d*e,g*e,f-c*e*o-d*e*h,p-u*e*o-g*e*h],this.width=m,this.height=w}get rawDims(){const{viewBox:t}=this;return at(this,"rawDims",{pageWidth:t[2]-t[0],pageHeight:t[3]-t[1],pageX:t[0],pageY:t[1]})}clone({scale:t=this.scale,rotation:e=this.rotation,offsetX:s=this.offsetX,offsetY:i=this.offsetY,dontFlip:n=!1}={}){return new $h({viewBox:this.viewBox.slice(),scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}convertToViewportPoint(t,e){return $.applyTransform([t,e],this.transform)}convertToViewportRectangle(t){const e=$.applyTransform([t[0],t[1]],this.transform),s=$.applyTransform([t[2],t[3]],this.transform);return[e[0],e[1],s[0],s[1]]}convertToPdfPoint(t,e){return $.applyInverseTransform([t,e],this.transform)}}class uf extends zn{constructor(t,e=0){super(t,"RenderingCancelledException"),this.extraDelay=e}}function Yu(a){const t=a.length;let e=0;for(;e<t&&a[e].trim()==="";)e++;return a.substring(e,e+5).toLowerCase()==="data:"}function df(a){return typeof a=="string"&&/\.pdf$/i.test(a)}function Xx(a){return[a]=a.split(/[#?]/,1),a.substring(a.lastIndexOf("/")+1)}function Ux(a,t="document.pdf"){if(typeof a!="string")return t;if(Yu(a))return rt('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 av{constructor(){q(this,"started",Object.create(null));q(this,"times",[])}time(t){t in this.started&&rt(`Timer is already running for ${t}`),this.started[t]=Date.now()}timeEnd(t){t in this.started||rt(`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 qh(a,t){try{const{protocol:e}=t?new URL(a,t):new URL(a);return e==="http:"||e==="https:"}catch{return!1}}function ti(a){a.preventDefault()}function ei(a){a.preventDefault(),a.stopPropagation()}function hv(a){console.log("Deprecated API usage: "+a)}class gf{static toDateObject(t){if(!t||typeof t!="string")return null;l(this,il)||v(this,il,new RegExp("^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+|-])?(\\d{2})?'?(\\d{2})?'?"));const e=l(this,il).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))}}il=new WeakMap,_(gf,il);function Yx(a,{scale:t=1,rotation:e=0}){const{width:s,height:i}=a.attributes.style,n=[0,0,parseInt(s),parseInt(i)];return new $h({viewBox:n,scale:t,rotation:e})}function ff(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):(rt(`Not a valid color format: "${a}"`),[0,0,0])}function $x(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,ff(s))}t.remove()}function Lt(a){const{a:t,b:e,c:s,d:i,e:n,f:r}=a.getTransform();return[t,e,s,i,n,r]}function Si(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 Nr(a,t,e=!1,s=!0){if(t instanceof $h){const{pageWidth:i,pageHeight:n}=t.rawDims,{style:r}=a,o=Ge.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 pf{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 an=class an{constructor(t){_(this,We);_(this,Yn,null);_(this,Wr,null);_(this,si);_(this,zr,null);_(this,nl,null);v(this,si,t),l(an,rl)||v(an,rl,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,Yn,document.createElement("div"));t.classList.add("editToolbar","hidden"),t.setAttribute("role","toolbar");const e=l(this,si)._uiManager._signal;t.addEventListener("contextmenu",ti,{signal:e}),t.addEventListener("pointerdown",y(an,ad,gb),{signal:e});const s=v(this,zr,document.createElement("div"));s.className="buttons",t.append(s);const i=l(this,si).toolbarPosition;if(i){const{style:n}=t,r=l(this,si)._uiManager.direction==="ltr"?1-i[0]:i[0];n.insetInlineEnd=`${100*r}%`,n.top=`calc(${100*i[1]}% + var(--editor-toolbar-vert-offset))`}return y(this,We,mb).call(this),t}get div(){return l(this,Yn)}hide(){var t;l(this,Yn).classList.add("hidden"),(t=l(this,Wr))==null||t.hideDropdown()}show(){var t;l(this,Yn).classList.remove("hidden"),(t=l(this,nl))==null||t.shown()}async addAltText(t){const e=await t.render();y(this,We,Md).call(this,e),l(this,zr).prepend(e,l(this,We,tp)),v(this,nl,t)}addColorPicker(t){v(this,Wr,t);const e=t.renderButton();y(this,We,Md).call(this,e),l(this,zr).prepend(e,l(this,We,tp))}remove(){var t;l(this,Yn).remove(),(t=l(this,Wr))==null||t.destroy(),v(this,Wr,null)}};Yn=new WeakMap,Wr=new WeakMap,si=new WeakMap,zr=new WeakMap,nl=new WeakMap,rl=new WeakMap,ad=new WeakSet,gb=function(t){t.stopPropagation()},We=new WeakSet,fb=function(t){l(this,si)._focusEventsAllowed=!1,ei(t)},pb=function(t){l(this,si)._focusEventsAllowed=!0,ei(t)},Md=function(t){const e=l(this,si)._uiManager._signal;t.addEventListener("focusin",y(this,We,fb).bind(this),{capture:!0,signal:e}),t.addEventListener("focusout",y(this,We,pb).bind(this),{capture:!0,signal:e}),t.addEventListener("contextmenu",ti,{signal:e})},mb=function(){const{editorType:t,_uiManager:e}=l(this,si),s=document.createElement("button");s.className="delete",s.tabIndex=0,s.setAttribute("data-l10n-id",l(an,rl)[t]),y(this,We,Md).call(this,s),s.addEventListener("click",i=>{e.delete()},{signal:e._signal}),l(this,zr).append(s)},tp=function(){const t=document.createElement("div");return t.className="divider",t},_(an,ad),_(an,rl,null);let mf=an;class qx{constructor(t){_(this,$n);_(this,ol,null);_(this,Xr,null);_(this,Ur);v(this,Ur,t)}show(t,e,s){const[i,n]=y(this,$n,bb).call(this,e,s),{style:r}=l(this,Xr)||v(this,Xr,y(this,$n,vb).call(this));t.append(l(this,Xr)),r.insetInlineEnd=`${100*i}%`,r.top=`calc(${100*n}% + var(--editor-toolbar-vert-offset))`}hide(){l(this,Xr).remove()}}ol=new WeakMap,Xr=new WeakMap,Ur=new WeakMap,$n=new WeakSet,vb=function(){const t=v(this,Xr,document.createElement("div"));t.className="editToolbar",t.setAttribute("role","toolbar"),t.addEventListener("contextmenu",ti,{signal:l(this,Ur)._signal});const e=v(this,ol,document.createElement("div"));return e.className="buttons",t.append(e),y(this,$n,yb).call(this),t},bb=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]},yb=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,Ur)._signal;t.addEventListener("contextmenu",ti,{signal:s}),t.addEventListener("click",()=>{l(this,Ur).highlightSelection("floating_button")},{signal:s}),l(this,ol).append(t)};function $u(a,t,e){for(const s of e)t.addEventListener(s,a[s].bind(a))}class Kx{constructor(){_(this,hd,0)}get id(){return`${Mx}${Ke(this,hd)._++}`}}hd=new WeakMap;const Vf=class Vf{constructor(){_(this,ga);_(this,da,Wx());_(this,al,0);_(this,Pe,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 at(this,"_isSVGFittingCanvas",n)}async getFromFile(t){const{lastModified:e,name:s,size:i,type:n}=t;return y(this,ga,Od).call(this,`${e}_${s}_${i}_${n}`,t)}async getFromUrl(t){return y(this,ga,Od).call(this,t,t)}async getFromBlob(t,e){const s=await e;return y(this,ga,Od).call(this,t,s)}async getFromId(t){l(this,Pe)||v(this,Pe,new Map);const e=l(this,Pe).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,Pe)||v(this,Pe,new Map);let s=l(this,Pe).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,da)}_${Ke(this,al)._++}`,refCounter:1,isSvg:!1},l(this,Pe).set(t,s),l(this,Pe).set(s.id,s),s}getSvgUrl(t){const e=l(this,Pe).get(t);return e!=null&&e.isSvg?e.svgUrl:null}deleteId(t){var i;l(this,Pe)||v(this,Pe,new Map);const e=l(this,Pe).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,da)}_`)}};da=new WeakMap,al=new WeakMap,Pe=new WeakMap,ga=new WeakSet,Od=async function(t,e){l(this,Pe)||v(this,Pe,new Map);let s=l(this,Pe).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,da)}_${Ke(this,al)._++}`,refCounter:0,isSvg:!1});let i;if(typeof e=="string"?(s.url=e,i=await Uu(e,"blob")):e instanceof File?i=s.file=e:e instanceof Blob&&(i=e),i.type==="image/svg+xml"){const n=Vf._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){rt(i),s=null}return l(this,Pe).set(t,s),s&&l(this,Pe).set(s.id,s),s};let vf=Vf;class Jx{constructor(t=128){_(this,qt,[]);_(this,qn,!1);_(this,hl);_(this,Ht,-1);v(this,hl,t)}add({cmd:t,undo:e,post:s,mustExec:i,type:n=NaN,overwriteIfSameType:r=!1,keepUndo:o=!1}){if(i&&t(),l(this,qn))return;const h={cmd:t,undo:e,post:s,type:n};if(l(this,Ht)===-1){l(this,qt).length>0&&(l(this,qt).length=0),v(this,Ht,0),l(this,qt).push(h);return}if(r&&l(this,qt)[l(this,Ht)].type===n){o&&(h.undo=l(this,qt)[l(this,Ht)].undo),l(this,qt)[l(this,Ht)]=h;return}const c=l(this,Ht)+1;c===l(this,hl)?l(this,qt).splice(0,1):(v(this,Ht,c),c<l(this,qt).length&&l(this,qt).splice(c)),l(this,qt).push(h)}undo(){if(l(this,Ht)===-1)return;v(this,qn,!0);const{undo:t,post:e}=l(this,qt)[l(this,Ht)];t(),e==null||e(),v(this,qn,!1),v(this,Ht,l(this,Ht)-1)}redo(){if(l(this,Ht)<l(this,qt).length-1){v(this,Ht,l(this,Ht)+1),v(this,qn,!0);const{cmd:t,post:e}=l(this,qt)[l(this,Ht)];t(),e==null||e(),v(this,qn,!1)}}hasSomethingToUndo(){return l(this,Ht)!==-1}hasSomethingToRedo(){return l(this,Ht)<l(this,qt).length-1}cleanType(t){if(l(this,Ht)!==-1){for(let e=l(this,Ht);e>=0;e--)if(l(this,qt)[e].type!==t){l(this,qt).splice(e+1,l(this,Ht)-e),v(this,Ht,e);return}l(this,qt).length=0,v(this,Ht,-1)}}destroy(){v(this,qt,null)}}qt=new WeakMap,qn=new WeakMap,hl=new WeakMap,Ht=new WeakMap;class Kh{constructor(t){_(this,ld);this.buffer=[],this.callbacks=new Map,this.allKeys=new Set;const{isMac:e}=Ge.platform;for(const[s,i,n={}]of t)for(const r of s){const o=r.startsWith("mac+");e&&o?(this.callbacks.set(r.slice(4),{callback:i,options:n}),this.allKeys.add(r.split("+").at(-1))):!e&&!o&&(this.callbacks.set(r,{callback:i,options:n}),this.allKeys.add(r.split("+").at(-1)))}}exec(t,e){if(!this.allKeys.has(e.key))return;const s=this.callbacks.get(y(this,ld,_b).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||ei(e))}}ld=new WeakSet,_b=function(t){t.altKey&&this.buffer.push("alt"),t.ctrlKey&&this.buffer.push("ctrl"),t.metaKey&&this.buffer.push("meta"),t.shiftKey&&this.buffer.push("shift"),this.buffer.push(t.key);const e=this.buffer.join("+");return this.buffer.length=0,e};const cd=class cd{get _colors(){const t=new Map([["CanvasText",null],["Canvas",null]]);return $x(t),at(this,"_colors",t)}convert(t){const e=ff(t);if(!window.matchMedia("(forced-colors: active)").matches)return e;for(const[s,i]of this._colors)if(i.every((n,r)=>n===e[r]))return cd._colorsMapping.get(s);return e}getHexCode(t){const e=this._colors.get(t);return e?$.makeHexColor(...e):t}};q(cd,"_colorsMapping",new Map([["CanvasText",[0,0,0]],["Canvas",[255,255,255]]]));let bf=cd;const _a=class _a{constructor(t,e,s,i,n,r,o,h,c,u,d,g){_(this,B);_(this,fa,new AbortController);_(this,us,null);_(this,ae,new Map);_(this,me,new Map);_(this,pa,null);_(this,hn,null);_(this,ma,null);_(this,Ms,new Jx);_(this,Kn,null);_(this,Yr,null);_(this,va,0);_(this,$r,new Set);_(this,Ai,null);_(this,ii,null);_(this,qr,new Set);q(this,"_editorUndoBar",null);_(this,ll,!1);_(this,cl,!1);_(this,ba,!1);_(this,ul,null);_(this,Ti,null);_(this,Jn,null);_(this,ya,null);_(this,Qn,!1);_(this,Ei,null);_(this,ud,new Kx);_(this,Zn,!1);_(this,dl,!1);_(this,tr,null);_(this,Kr,null);_(this,gl,null);_(this,fl,null);_(this,ue,it.NONE);_(this,wt,new Set);_(this,ln,null);_(this,Jr,null);_(this,pl,null);_(this,ml,{isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1});_(this,er,[0,0]);_(this,ki,null);_(this,cn,null);_(this,vl,null);_(this,Os,null);const f=this._signal=l(this,fa).signal;v(this,cn,t),v(this,vl,e),v(this,pa,s),this._eventBus=i,i._on("editingaction",this.onEditingAction.bind(this),{signal:f}),i._on("pagechanging",this.onPageChanging.bind(this),{signal:f}),i._on("scalechanging",this.onScaleChanging.bind(this),{signal:f}),i._on("rotationchanging",this.onRotationChanging.bind(this),{signal:f}),i._on("setpreference",this.onSetPreference.bind(this),{signal:f}),i._on("switchannotationeditorparams",p=>this.updateParams(p.type,p.value),{signal:f}),y(this,B,Sb).call(this),y(this,B,Eb).call(this),y(this,B,sp).call(this),v(this,hn,n.annotationStorage),v(this,ul,n.filterFactory),v(this,Jr,r),v(this,ya,o||null),v(this,ll,h),v(this,cl,c),v(this,ba,u),v(this,fl,d||null),this.viewParameters={realScale:Xn.PDF_TO_CSS_UNITS,rotation:0},this.isShiftKeyDown=!1,this._editorUndoBar=g||null}static get _keyboardManager(){const t=_a.prototype,e=r=>l(r,cn).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 at(this,"_keyboardManager",new Kh([[["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,cn).contains(o)&&!r.isEnterHandled}],[[" ","mac+ "],t.addNewEditorFromKeyboard,{checker:(r,{target:o})=>!(o instanceof HTMLButtonElement)&&l(r,cn).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,Os))==null||t.resolve(),v(this,Os,null),(e=l(this,fa))==null||e.abort(),v(this,fa,null),this._signal=null;for(const r of l(this,me).values())r.destroy();l(this,me).clear(),l(this,ae).clear(),l(this,qr).clear(),v(this,us,null),l(this,wt).clear(),l(this,Ms).destroy(),(s=l(this,pa))==null||s.destroy(),(i=l(this,Ei))==null||i.hide(),v(this,Ei,null),l(this,Ti)&&(clearTimeout(l(this,Ti)),v(this,Ti,null)),l(this,ki)&&(clearTimeout(l(this,ki)),v(this,ki,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,cl)}get useNewAltTextWhenAddingImage(){return l(this,ba)}get hcmFilter(){return at(this,"hcmFilter",l(this,Jr)?l(this,ul).addHCMFilter(l(this,Jr).foreground,l(this,Jr).background):"none")}get direction(){return at(this,"direction",getComputedStyle(l(this,cn)).direction)}get highlightColors(){return at(this,"highlightColors",l(this,ya)?new Map(l(this,ya).split(",").map(t=>t.split("=").map(e=>e.trim()))):null)}get highlightColorNames(){return at(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,Yr,t)}setMainHighlightColorPicker(t){v(this,gl,t)}editAltText(t,e=!1){var s;(s=l(this,pa))==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,ba,e);break}}onPageChanging({pageNumber:t}){v(this,va,t-1)}focusMainContainer(){l(this,cn).focus()}findParent(t,e){for(const s of l(this,me).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,vl).classList.toggle("noUserSelect",t)}addShouldRescale(t){l(this,qr).add(t)}removeShouldRescale(t){l(this,qr).delete(t)}onScaleChanging({scale:t}){var e;this.commitOrRemove(),this.viewParameters.realScale=t*Xn.PDF_TO_CSS_UNITS;for(const s of l(this,qr))s.onScaleChanging();(e=l(this,Yr))==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=y(this,B,Dd).call(this,e).closest(".textLayer"),u=this.getSelectionBoxes(c);if(!u)return;e.empty();const d=y(this,B,ep).call(this,c),g=l(this,ue)===it.NONE,f=()=>{d==null||d.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:t,boxes:u,anchorNode:s,anchorOffset:i,focusNode:n,focusOffset:r,text:o}),g&&this.showAllEditors("highlight",!0,!0)};if(g){this.switchToMode(it.HIGHLIGHT,f);return}f()}addToAnnotationStorage(t){!t.isEmpty()&&l(this,hn)&&!l(this,hn).has(t.id)&&l(this,hn).setValue(t.id,t)}blur(){if(this.isShiftKeyDown=!1,l(this,Qn)&&(v(this,Qn,!1),y(this,B,Rd).call(this,"main_toolbar")),!this.hasSelection)return;const{activeElement:t}=document;for(const e of l(this,wt))if(e.div.contains(t)){v(this,Kr,[e,t]),e._focusEventsAllowed=!1;break}}focus(){if(!l(this,Kr))return;const[t,e]=l(this,Kr);v(this,Kr,null),e.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this._signal}),e.focus()}addEditListeners(){y(this,B,sp).call(this),y(this,B,ip).call(this)}removeEditListeners(){y(this,B,Tb).call(this),y(this,B,np).call(this)}dragOver(t){for(const{type:e}of t.dataTransfer.items)for(const s of l(this,ii))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,ii))if(s.isHandlingMimeForPasting(e.type)){s.paste(e,this.currentLayer),t.preventDefault();return}}copy(t){var s;if(t.preventDefault(),(s=l(this,us))==null||s.commitOrRemove(),!this.hasSelection)return;const e=[];for(const i of l(this,wt)){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,ii))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){rt(`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)y(this,B,rp).call(this,h);y(this,B,op).call(this,n)},o=()=>{for(const h of n)h.remove()};this.addCommands({cmd:r,undo:o,mustExec:!0})}catch(n){rt(`paste: "${n.message}".`)}}keydown(t){!this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!0),l(this,ue)!==it.NONE&&!this.isEditorHandlingKeyboard&&_a._keyboardManager.exec(this,t)}keyup(t){this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!1,l(this,Qn)&&(v(this,Qn,!1),y(this,B,Rd).call(this,"main_toolbar")))}onEditingAction({name:t}){switch(t){case"undo":case"redo":case"delete":case"selectAll":this[t]();break;case"highlightSelection":this.highlightSelection("context_menu");break}}setEditingState(t){t?(y(this,B,Cb).call(this),y(this,B,ip).call(this),y(this,B,Je).call(this,{isEditing:l(this,ue)!==it.NONE,isEmpty:y(this,B,Ac).call(this),hasSomethingToUndo:l(this,Ms).hasSomethingToUndo(),hasSomethingToRedo:l(this,Ms).hasSomethingToRedo(),hasSelectedEditor:!1})):(y(this,B,Ab).call(this),y(this,B,np).call(this),y(this,B,Je).call(this,{isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(t){if(!l(this,ii)){v(this,ii,t);for(const e of l(this,ii))y(this,B,Rn).call(this,e.defaultPropertiesToUpdate)}}getId(){return l(this,ud).id}get currentLayer(){return l(this,me).get(l(this,va))}getLayer(t){return l(this,me).get(t)}get currentPageIndex(){return l(this,va)}addLayer(t){l(this,me).set(t.pageIndex,t),l(this,Zn)?t.enable():t.disable()}removeLayer(t){l(this,me).delete(t.pageIndex)}async updateMode(t,e=null,s=!1){var i;if(l(this,ue)!==t&&!(l(this,Os)&&(await l(this,Os).promise,!l(this,Os)))){if(v(this,Os,Promise.withResolvers()),v(this,ue,t),t===it.NONE){this.setEditingState(!1),y(this,B,Pb).call(this),(i=this._editorUndoBar)==null||i.hide(),l(this,Os).resolve();return}this.setEditingState(!0),await y(this,B,kb).call(this),this.unselectAll();for(const n of l(this,me).values())n.updateMode(t);if(!e){s&&this.addNewEditorFromKeyboard(),l(this,Os).resolve();return}for(const n of l(this,ae).values())n.annotationElementId===e?(this.setSelected(n),n.enterInEditMode()):n.unselect();l(this,Os).resolve()}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(t){t!==l(this,ue)&&this._eventBus.dispatch("switchannotationeditormode",{source:this,mode:t})}updateParams(t,e){var s;if(l(this,ii)){switch(t){case ut.CREATE:this.currentLayer.addNewEditor();return;case ut.HIGHLIGHT_DEFAULT_COLOR:(s=l(this,gl))==null||s.updateColor(e);break;case ut.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:{type:"highlight",action:"toggle_visibility"}}}),(l(this,pl)||v(this,pl,new Map)).set(t,e),this.showAllEditors("highlight",e);break}for(const i of l(this,wt))i.updateParams(t,e);for(const i of l(this,ii))i.updateDefaultParams(t,e)}}showAllEditors(t,e,s=!1){var n;for(const r of l(this,ae).values())r.editorType===t&&r.show(e);(((n=l(this,pl))==null?void 0:n.get(ut.HIGHLIGHT_SHOW_ALL))??!0)!==e&&y(this,B,Rn).call(this,[[ut.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(l(this,dl)!==t){v(this,dl,t);for(const e of l(this,me).values())t?e.disableClick():e.enableClick(),e.div.classList.toggle("waiting",t)}}getEditors(t){const e=[];for(const s of l(this,ae).values())s.pageIndex===t&&e.push(s);return e}getEditor(t){return l(this,ae).get(t)}addEditor(t){l(this,ae).set(t.id,t)}removeEditor(t){var e;t.div.contains(document.activeElement)&&(l(this,Ti)&&clearTimeout(l(this,Ti)),v(this,Ti,setTimeout(()=>{this.focusMainContainer(),v(this,Ti,null)},0))),l(this,ae).delete(t.id),this.unselect(t),(!t.annotationElementId||!l(this,$r).has(t.annotationElementId))&&((e=l(this,hn))==null||e.remove(t.id))}addDeletedAnnotationElement(t){l(this,$r).add(t.annotationElementId),this.addChangedExistingAnnotation(t),t.deleted=!0}isDeletedAnnotationElement(t){return l(this,$r).has(t)}removeDeletedAnnotationElement(t){l(this,$r).delete(t.annotationElementId),this.removeChangedExistingAnnotation(t),t.deleted=!1}setActiveEditor(t){l(this,us)!==t&&(v(this,us,t),t&&y(this,B,Rn).call(this,t.propertiesToUpdate))}updateUI(t){l(this,B,Mb)===t&&y(this,B,Rn).call(this,t.propertiesToUpdate)}updateUIForDefaultProperties(t){y(this,B,Rn).call(this,t.defaultPropertiesToUpdate)}toggleSelected(t){if(l(this,wt).has(t)){l(this,wt).delete(t),t.unselect(),y(this,B,Je).call(this,{hasSelectedEditor:this.hasSelection});return}l(this,wt).add(t),t.select(),y(this,B,Rn).call(this,t.propertiesToUpdate),y(this,B,Je).call(this,{hasSelectedEditor:!0})}setSelected(t){var e;(e=l(this,Yr))==null||e.commitOrRemove();for(const s of l(this,wt))s!==t&&s.unselect();l(this,wt).clear(),l(this,wt).add(t),t.select(),y(this,B,Rn).call(this,t.propertiesToUpdate),y(this,B,Je).call(this,{hasSelectedEditor:!0})}isSelected(t){return l(this,wt).has(t)}get firstSelectedEditor(){return l(this,wt).values().next().value}unselect(t){t.unselect(),l(this,wt).delete(t),y(this,B,Je).call(this,{hasSelectedEditor:this.hasSelection})}get hasSelection(){return l(this,wt).size!==0}get isEnterHandled(){return l(this,wt).size===1&&this.firstSelectedEditor.isEnterHandled}undo(){var t;l(this,Ms).undo(),y(this,B,Je).call(this,{hasSomethingToUndo:l(this,Ms).hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:y(this,B,Ac).call(this)}),(t=this._editorUndoBar)==null||t.hide()}redo(){l(this,Ms).redo(),y(this,B,Je).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:l(this,Ms).hasSomethingToRedo(),isEmpty:y(this,B,Ac).call(this)})}addCommands(t){l(this,Ms).add(t),y(this,B,Je).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:y(this,B,Ac).call(this)})}cleanUndoStack(t){l(this,Ms).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,wt)],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)y(this,B,rp).call(this,r)};this.addCommands({cmd:s,undo:i,mustExec:!0})}commitOrRemove(){var t;(t=l(this,us))==null||t.commitOrRemove()}hasSomethingToControl(){return l(this,us)||this.hasSelection}selectAll(){for(const t of l(this,wt))t.commit();y(this,B,op).call(this,l(this,ae).values())}unselectAll(){var t;if(!(l(this,us)&&(l(this,us).commitOrRemove(),l(this,ue)!==it.NONE))&&!((t=l(this,Yr))!=null&&t.commitOrRemove())&&this.hasSelection){for(const e of l(this,wt))e.unselect();l(this,wt).clear(),y(this,B,Je).call(this,{hasSelectedEditor:!1})}}translateSelectedEditors(t,e,s=!1){if(s||this.commitOrRemove(),!this.hasSelection)return;l(this,er)[0]+=t,l(this,er)[1]+=e;const[i,n]=l(this,er),r=[...l(this,wt)],o=1e3;l(this,ki)&&clearTimeout(l(this,ki)),v(this,ki,setTimeout(()=>{v(this,ki,null),l(this,er)[0]=l(this,er)[1]=0,this.addCommands({cmd:()=>{for(const h of r)l(this,ae).has(h.id)&&h.translateInPage(i,n)},undo:()=>{for(const h of r)l(this,ae).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,Ai,new Map);for(const t of l(this,wt))l(this,Ai).set(t,{savedX:t.x,savedY:t.y,savedPageIndex:t.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!l(this,Ai))return!1;this.disableUserSelect(!1);const t=l(this,Ai);v(this,Ai,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,ae).has(i.id)){const h=l(this,me).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,Ai))for(const s of l(this,Ai).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,wt).size===1&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(t){return l(this,us)===t}getActive(){return l(this,us)}getMode(){return l(this,ue)}get imageManager(){return at(this,"imageManager",new vf)}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,g)=>({x:(u-i)/r,y:1-(c+d-s)/n,width:g/r,height:d/n});break;case"180":o=(c,u,d,g)=>({x:1-(c+d-s)/n,y:1-(u+g-i)/r,width:d/n,height:g/r});break;case"270":o=(c,u,d,g)=>({x:1-(u+g-i)/r,y:(c-s)/n,width:g/r,height:d/n});break;default:o=(c,u,d,g)=>({x:(c-s)/n,y:(u-i)/r,width:d/n,height:g/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:g,y:f,width:p,height:m}of d.getClientRects())p===0||m===0||h.push(o(g,f,p,m))}return h.length===0?null:h}addChangedExistingAnnotation({annotationElementId:t,id:e}){(l(this,ma)||v(this,ma,new Map)).set(t,e)}removeChangedExistingAnnotation({annotationElementId:t}){var e;(e=l(this,ma))==null||e.delete(t)}renderAnnotationElement(t){var i;const e=(i=l(this,ma))==null?void 0:i.get(t.data.id);if(!e)return;const s=l(this,hn).getRawValue(e);s&&(l(this,ue)===it.NONE&&!s.hasBeenModified||s.renderAnnotationElement(t))}};fa=new WeakMap,us=new WeakMap,ae=new WeakMap,me=new WeakMap,pa=new WeakMap,hn=new WeakMap,ma=new WeakMap,Ms=new WeakMap,Kn=new WeakMap,Yr=new WeakMap,va=new WeakMap,$r=new WeakMap,Ai=new WeakMap,ii=new WeakMap,qr=new WeakMap,ll=new WeakMap,cl=new WeakMap,ba=new WeakMap,ul=new WeakMap,Ti=new WeakMap,Jn=new WeakMap,ya=new WeakMap,Qn=new WeakMap,Ei=new WeakMap,ud=new WeakMap,Zn=new WeakMap,dl=new WeakMap,tr=new WeakMap,Kr=new WeakMap,gl=new WeakMap,fl=new WeakMap,ue=new WeakMap,wt=new WeakMap,ln=new WeakMap,Jr=new WeakMap,pl=new WeakMap,ml=new WeakMap,er=new WeakMap,ki=new WeakMap,cn=new WeakMap,vl=new WeakMap,Os=new WeakMap,B=new WeakSet,Dd=function({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t},ep=function(t){const{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(const s of l(this,me).values())if(s.hasTextLayer(t))return s;return null},wb=function(){const t=document.getSelection();if(!t||t.isCollapsed)return;const s=y(this,B,Dd).call(this,t).closest(".textLayer"),i=this.getSelectionBoxes(s);i&&(l(this,Ei)||v(this,Ei,new qx(this)),l(this,Ei).show(s,i,this.direction==="ltr"))},xb=function(){var n,r,o;const t=document.getSelection();if(!t||t.isCollapsed){l(this,ln)&&((n=l(this,Ei))==null||n.hide(),v(this,ln,null),y(this,B,Je).call(this,{hasSelectedText:!1}));return}const{anchorNode:e}=t;if(e===l(this,ln))return;const i=y(this,B,Dd).call(this,t).closest(".textLayer");if(!i){l(this,ln)&&((r=l(this,Ei))==null||r.hide(),v(this,ln,null),y(this,B,Je).call(this,{hasSelectedText:!1}));return}if((o=l(this,Ei))==null||o.hide(),v(this,ln,e),y(this,B,Je).call(this,{hasSelectedText:!0}),!(l(this,ue)!==it.HIGHLIGHT&&l(this,ue)!==it.NONE)&&(l(this,ue)===it.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0),v(this,Qn,this.isShiftKeyDown),!this.isShiftKeyDown)){const h=l(this,ue)===it.HIGHLIGHT?y(this,B,ep).call(this,i):null;h==null||h.toggleDrawing();const c=new AbortController,u=this.combinedSignal(c),d=g=>{g.type==="pointerup"&&g.button!==0||(c.abort(),h==null||h.toggleDrawing(!0),g.type==="pointerup"&&y(this,B,Rd).call(this,"main_toolbar"))};window.addEventListener("pointerup",d,{signal:u}),window.addEventListener("blur",d,{signal:u})}},Rd=function(t=""){l(this,ue)===it.HIGHLIGHT?this.highlightSelection(t):l(this,ll)&&y(this,B,wb).call(this)},Sb=function(){document.addEventListener("selectionchange",y(this,B,xb).bind(this),{signal:this._signal})},Cb=function(){if(l(this,Jn))return;v(this,Jn,new AbortController);const t=this.combinedSignal(l(this,Jn));window.addEventListener("focus",this.focus.bind(this),{signal:t}),window.addEventListener("blur",this.blur.bind(this),{signal:t})},Ab=function(){var t;(t=l(this,Jn))==null||t.abort(),v(this,Jn,null)},sp=function(){if(l(this,tr))return;v(this,tr,new AbortController);const t=this.combinedSignal(l(this,tr));window.addEventListener("keydown",this.keydown.bind(this),{signal:t}),window.addEventListener("keyup",this.keyup.bind(this),{signal:t})},Tb=function(){var t;(t=l(this,tr))==null||t.abort(),v(this,tr,null)},ip=function(){if(l(this,Kn))return;v(this,Kn,new AbortController);const t=this.combinedSignal(l(this,Kn));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})},np=function(){var t;(t=l(this,Kn))==null||t.abort(),v(this,Kn,null)},Eb=function(){const t=this._signal;document.addEventListener("dragover",this.dragOver.bind(this),{signal:t}),document.addEventListener("drop",this.drop.bind(this),{signal:t})},Je=function(t){Object.entries(t).some(([s,i])=>l(this,ml)[s]!==i)&&(this._eventBus.dispatch("annotationeditorstateschanged",{source:this,details:Object.assign(l(this,ml),t)}),l(this,ue)===it.HIGHLIGHT&&t.hasSelectedEditor===!1&&y(this,B,Rn).call(this,[[ut.HIGHLIGHT_FREE,!0]]))},Rn=function(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})},kb=async function(){if(!l(this,Zn)){v(this,Zn,!0);const t=[];for(const e of l(this,me).values())t.push(e.enable());await Promise.all(t);for(const e of l(this,ae).values())e.enable()}},Pb=function(){if(this.unselectAll(),l(this,Zn)){v(this,Zn,!1);for(const t of l(this,me).values())t.disable();for(const t of l(this,ae).values())t.disable()}},rp=function(t){const e=l(this,me).get(t.pageIndex);e?e.addOrRebuild(t):(this.addEditor(t),this.addToAnnotationStorage(t))},Mb=function(){let t=null;for(t of l(this,wt));return t},Ac=function(){if(l(this,ae).size===0)return!0;if(l(this,ae).size===1)for(const t of l(this,ae).values())return t.isEmpty();return!1},op=function(t){for(const e of l(this,wt))e.unselect();l(this,wt).clear();for(const e of t)e.isEmpty()||(l(this,wt).add(e),e.select());y(this,B,Je).call(this,{hasSelectedEditor:this.hasSelection})},q(_a,"TRANSLATE_SMALL",1),q(_a,"TRANSLATE_BIG",10);let Br=_a;const ze=class ze{constructor(t){_(this,ri);_(this,de,null);_(this,Pi,!1);_(this,ni,null);_(this,wa,null);_(this,Mi,null);_(this,ds,null);_(this,xa,!1);_(this,Oi,null);_(this,ss,null);_(this,un,null);_(this,Qr,null);_(this,Di,!1);v(this,ss,t),v(this,Di,t._uiManager.useNewAltTextFlow),l(ze,sr)||v(ze,sr,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){ze._l10n??(ze._l10n=t)}async render(){const t=v(this,ni,document.createElement("button"));t.className="altText",t.tabIndex="0";const e=v(this,wa,document.createElement("span"));t.append(e),l(this,Di)?(t.classList.add("new"),t.setAttribute("data-l10n-id",l(ze,sr).missing),e.setAttribute("data-l10n-id",l(ze,sr)["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,ss)._uiManager._signal;t.addEventListener("contextmenu",ti,{signal:s}),t.addEventListener("pointerdown",n=>n.stopPropagation(),{signal:s});const i=n=>{n.preventDefault(),l(this,ss)._uiManager.editAltText(l(this,ss)),l(this,Di)&&l(this,ss)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_clicked",data:{label:l(this,ri,Tc)}})};return t.addEventListener("click",i,{capture:!0,signal:s}),t.addEventListener("keydown",n=>{n.target===t&&n.key==="Enter"&&(v(this,xa,!0),i(n))},{signal:s}),await y(this,ri,Ld).call(this),t}finish(){l(this,ni)&&(l(this,ni).focus({focusVisible:l(this,xa)}),v(this,xa,!1))}isEmpty(){return l(this,Di)?l(this,de)===null:!l(this,de)&&!l(this,Pi)}hasData(){return l(this,Di)?l(this,de)!==null||!!l(this,un):this.isEmpty()}get guessedText(){return l(this,un)}async setGuessedText(t){l(this,de)===null&&(v(this,un,t),v(this,Qr,await ze._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",{generatedAltText:t})),y(this,ri,Ld).call(this))}toggleAltTextBadge(t=!1){var e;if(!l(this,Di)||l(this,de)){(e=l(this,Oi))==null||e.remove(),v(this,Oi,null);return}if(!l(this,Oi)){const s=v(this,Oi,document.createElement("div"));s.className="noAltTextBadge",l(this,ss).div.append(s)}l(this,Oi).classList.toggle("hidden",!t)}serialize(t){let e=l(this,de);return!t&&l(this,un)===e&&(e=l(this,Qr)),{altText:e,decorative:l(this,Pi),guessedText:l(this,un),textWithDisclaimer:l(this,Qr)}}get data(){return{altText:l(this,de),decorative:l(this,Pi)}}set data({altText:t,decorative:e,guessedText:s,textWithDisclaimer:i,cancel:n=!1}){s&&(v(this,un,s),v(this,Qr,i)),!(l(this,de)===t&&l(this,Pi)===e)&&(n||(v(this,de,t),v(this,Pi,e)),y(this,ri,Ld).call(this))}toggle(t=!1){l(this,ni)&&(!t&&l(this,ds)&&(clearTimeout(l(this,ds)),v(this,ds,null)),l(this,ni).disabled=!t)}shown(){l(this,ss)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_displayed",data:{label:l(this,ri,Tc)}})}destroy(){var t,e;(t=l(this,ni))==null||t.remove(),v(this,ni,null),v(this,wa,null),v(this,Mi,null),(e=l(this,Oi))==null||e.remove(),v(this,Oi,null)}};de=new WeakMap,Pi=new WeakMap,ni=new WeakMap,wa=new WeakMap,Mi=new WeakMap,ds=new WeakMap,xa=new WeakMap,Oi=new WeakMap,ss=new WeakMap,un=new WeakMap,Qr=new WeakMap,Di=new WeakMap,sr=new WeakMap,ri=new WeakSet,Tc=function(){return l(this,de)&&"added"||l(this,de)===null&&this.guessedText&&"review"||"missing"},Ld=async function(){var i,n,r;const t=l(this,ni);if(!t)return;if(l(this,Di)){if(t.classList.toggle("done",!!l(this,de)),t.setAttribute("data-l10n-id",l(ze,sr)[l(this,ri,Tc)]),(i=l(this,wa))==null||i.setAttribute("data-l10n-id",l(ze,sr)[`${l(this,ri,Tc)}-label`]),!l(this,de)){(n=l(this,Mi))==null||n.remove();return}}else{if(!l(this,de)&&!l(this,Pi)){t.classList.remove("done"),(r=l(this,Mi))==null||r.remove();return}t.classList.add("done"),t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-edit-button")}let e=l(this,Mi);if(!e){v(this,Mi,e=document.createElement("span")),e.className="tooltip",e.setAttribute("role","tooltip"),e.id=`alt-text-tooltip-${l(this,ss).id}`;const o=100,h=l(this,ss)._uiManager._signal;h.addEventListener("abort",()=>{clearTimeout(l(this,ds)),v(this,ds,null)},{once:!0}),t.addEventListener("mouseenter",()=>{v(this,ds,setTimeout(()=>{v(this,ds,null),l(this,Mi).classList.add("show"),l(this,ss)._reportTelemetry({action:"alt_text_tooltip"})},o))},{signal:h}),t.addEventListener("mouseleave",()=>{var c;l(this,ds)&&(clearTimeout(l(this,ds)),v(this,ds,null)),(c=l(this,Mi))==null||c.classList.remove("show")},{signal:h})}l(this,Pi)?e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-decorative-tooltip"):(e.removeAttribute("data-l10n-id"),e.textContent=l(this,de)),e.parentNode||t.append(e);const s=l(this,ss).getImageForAltText();s==null||s.setAttribute("aria-describedby",e.id)},_(ze,sr,null),q(ze,"_l10n",null);let qu=ze;const bt=class bt{constructor(t){_(this,et);_(this,Zr,null);_(this,oi,null);_(this,Vt,null);_(this,Sa,!1);_(this,ir,null);_(this,bl,"");_(this,to,!1);_(this,ve,null);_(this,eo,null);_(this,nr,null);_(this,rr,null);_(this,yl,"");_(this,so,!1);_(this,Ds,null);_(this,_l,!1);_(this,io,!1);_(this,dn,!1);_(this,Ri,null);_(this,Ca,0);_(this,Aa,0);_(this,Rs,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,wl,!1);_(this,dd,bt._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=bt.prototype._resizeWithKeyboard,e=Br.TRANSLATE_SMALL,s=Br.TRANSLATE_BIG;return at(this,"_resizerKeyboardManager",new Kh([[["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"],bt.prototype._stopResizingWithKeyboard]]))}get editorType(){return Object.getPrototypeOf(this).constructor._type}static get isDrawer(){return!1}static get _defaultLineColor(){return at(this,"_defaultLineColor",this._colorManager.getHexCode("CanvasText"))}static deleteAnnotationElement(t){const e=new Qx({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(bt._l10n??(bt._l10n=t),bt._l10nResizer||(bt._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"})),bt._borderLineWidth!==-1)return;const s=getComputedStyle(document.documentElement);bt._borderLineWidth=parseFloat(s.getPropertyValue("--outline-width"))||0}static updateDefaultParams(t,e){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(t){return!1}static paste(t,e){St("Not implemented")}get propertiesToUpdate(){return[]}get _isDraggable(){return l(this,wl)}set _isDraggable(t){var e;v(this,wl,t),(e=this.div)==null||e.classList.toggle("draggable",t)}get isEnterHandled(){return!0}center(){const[t,e]=this.pageDimensions;switch(this.parentRotation){case 90:this.x-=this.height*e/(t*2),this.y+=this.width*t/(e*2);break;case 180:this.x+=this.width/2,this.y+=this.height/2;break;case 270:this.x+=this.height*e/(t*2),this.y-=this.width*t/(e*2);break;default:this.x-=this.width/2,this.y-=this.height/2;break}this.fixAndSetPosition()}addCommands(t){this._uiManager.addCommands(t)}get currentLayer(){return this._uiManager.currentLayer}setInBackground(){this.div.style.zIndex=0}setInForeground(){this.div.style.zIndex=l(this,dd)}setParent(t){t!==null?(this.pageIndex=t.pageIndex,this.pageDimensions=t.pageDimensions):y(this,et,Ec).call(this),this.parent=t}focusin(t){this._focusEventsAllowed&&(l(this,so)?v(this,so,!1):this.parent.setSelected(this))}focusout(t){var s;if(!this._focusEventsAllowed||!this.isAttachedToDOM)return;const e=t.relatedTarget;e!=null&&e.closest(`#${this.id}`)||(t.preventDefault(),(s=this.parent)!=null&&s.isMultipleSelection||this.commitOrRemove())}commitOrRemove(){this.isEmpty()?this.remove():this.commit()}commit(){this.addToAnnotationStorage()}addToAnnotationStorage(){this._uiManager.addToAnnotationStorage(this)}setAt(t,e,s,i){const[n,r]=this.parentDimensions;[s,i]=this.screenToPageTranslation(s,i),this.x=(t+s)/n,this.y=(e+i)/r,this.fixAndSetPosition()}translate(t,e){y(this,et,ap).call(this,this.parentDimensions,t,e)}translateInPage(t,e){l(this,Ds)||v(this,Ds,[this.x,this.y,this.width,this.height]),y(this,et,ap).call(this,this.pageDimensions,t,e),this.div.scrollIntoView({block:"nearest"})}drag(t,e){l(this,Ds)||v(this,Ds,[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:g}=this.div.getBoundingClientRect();this.parent.findNewParent(this,d,g)&&(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,Ds)&&(l(this,Ds)[0]!==this.x||l(this,Ds)[1]!==this.y)}get _hasBeenResized(){return!!l(this,Ds)&&(l(this,Ds)[2]!==this.width||l(this,Ds)[3]!==this.height)}getBaseTranslation(){const[t,e]=this.parentDimensions,{_borderLineWidth:s}=bt,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 y(s=bt,xl,hp).call(s,t,e,this.parentRotation)}pageTranslationToScreen(t,e){var s;return y(s=bt,xl,hp).call(s,t,e,360-this.parentRotation)}get parentScale(){return this._uiManager.viewParameters.realScale}get parentRotation(){return(this._uiManager.viewParameters.rotation+this.pageRotation)%360}get parentDimensions(){const{parentScale:t,pageDimensions:[e,s]}=this;return[e*t,s*t]}setDims(t,e){const[s,i]=this.parentDimensions,{style:n}=this.div;n.width=`${(100*t/s).toFixed(2)}%`,l(this,to)||(n.height=`${(100*e/i).toFixed(2)}%`)}fixDims(){const{style:t}=this.div,{height:e,width:s}=t,i=s.endsWith("%"),n=!l(this,to)&&e.endsWith("%");if(i&&n)return;const[r,o]=this.parentDimensions;i||(t.width=`${(100*parseFloat(s)/r).toFixed(2)}%`),!l(this,to)&&!n&&(t.height=`${(100*parseFloat(e)/o).toFixed(2)}%`)}getInitialTranslation(){return[0,0]}_onResized(){}_onResizing(){}altTextFinish(){var t;(t=l(this,Vt))==null||t.finish()}async addEditToolbar(){return this._editToolbar||l(this,io)?this._editToolbar:(this._editToolbar=new mf(this),this.div.append(this._editToolbar.render()),l(this,Vt)&&await this._editToolbar.addAltText(l(this,Vt)),this._editToolbar)}removeEditToolbar(){var t;this._editToolbar&&(this._editToolbar.remove(),this._editToolbar=null,(t=l(this,Vt))==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,Vt)||(qu.initialize(bt._l10n),v(this,Vt,new qu(this)),l(this,Zr)&&(l(this,Vt).data=l(this,Zr),v(this,Zr,null)),await this.addEditToolbar())}get altTextData(){var t;return(t=l(this,Vt))==null?void 0:t.data}set altTextData(t){l(this,Vt)&&(l(this,Vt).data=t)}get guessedAltText(){var t;return(t=l(this,Vt))==null?void 0:t.guessedText}async setGuessedAltText(t){var e;await((e=l(this,Vt))==null?void 0:e.setGuessedText(t))}serializeAltText(t){var e;return(e=l(this,Vt))==null?void 0:e.serialize(t)}hasAltText(){return!!l(this,Vt)&&!l(this,Vt).isEmpty()}hasAltTextData(){var t;return((t=l(this,Vt))==null?void 0:t.hasData())??!1}render(){var n;this.div=document.createElement("div"),this.div.setAttribute("data-editor-rotation",(360-this.rotation)%360),this.div.className=this.name,this.div.setAttribute("id",this.id),this.div.tabIndex=l(this,Sa)?-1:0,this._isVisible||this.div.classList.add("hidden"),this.setInForeground(),y(this,et,fp).call(this);const[t,e]=this.parentDimensions;this.parentRotation%180!==0&&(this.div.style.maxWidth=`${(100*e/t).toFixed(2)}%`,this.div.style.maxHeight=`${(100*t/e).toFixed(2)}%`);const[s,i]=this.getInitialTranslation();return this.translate(s,i),$u(this,this.div,["pointerdown"]),(n=this._uiManager._editorUndoBar)==null||n.hide(),this.div}pointerdown(t){const{isMac:e}=Ge.platform;if(t.button!==0||t.ctrlKey&&e){t.preventDefault();return}if(v(this,so,!0),this._isDraggable){y(this,et,Rb).call(this,t);return}y(this,et,gp).call(this,t)}get isSelected(){return this._uiManager.isSelected(this)}_onStartDragging(){}_onStopDragging(){}moveInDOM(){l(this,Ri)&&clearTimeout(l(this,Ri)),v(this,Ri,setTimeout(()=>{var t;v(this,Ri,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,g=this.y*r,f=this.width*n,p=this.height*r;switch(s){case 0:return[d+c+o,r-g-u-p+h,d+c+f+o,r-g-u+h];case 90:return[d+u+o,r-g+c+h,d+u+p+o,r-g+c+f+h];case 180:return[d-c-f+o,r-g+u+h,d-c+o,r-g+u+p+h];case 270:return[d-u-p+o,r-g-c-f+h,d-u+o,r-g-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(){}isEmpty(){return!1}enableEditMode(){v(this,io,!0)}disableEditMode(){v(this,io,!1)}isInEditMode(){return l(this,io)}shouldGetKeyboardEvents(){return l(this,dn)}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(){y(this,et,fp).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){St("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,Zr,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;if((t=l(this,rr))==null||t.abort(),v(this,rr,null),this.isEmpty()||this.commit(),this.parent?this.parent.remove(this):this._uiManager.removeEditor(this),l(this,Ri)&&(clearTimeout(l(this,Ri)),v(this,Ri,null)),y(this,et,Ec).call(this),this.removeEditToolbar(),l(this,Rs)){for(const e of l(this,Rs).values())clearTimeout(e);v(this,Rs,null)}this.parent=null}get isResizable(){return!1}makeResizable(){this.isResizable&&(y(this,et,Ob).call(this),l(this,ve).classList.remove("hidden"),$u(this,this.div,["keydown"]))}get toolbarPosition(){return null}keydown(t){if(!this.isResizable||t.target!==this.div||t.key!=="Enter")return;this._uiManager.setSelected(this),v(this,nr,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height});const e=l(this,ve).children;if(!l(this,oi)){v(this,oi,Array.from(e));const r=y(this,et,Lb).bind(this),o=y(this,et,Fb).bind(this),h=this._uiManager._signal;for(const c of l(this,oi)){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",y(this,et,Ib).bind(this,u),{signal:h}),c.setAttribute("data-l10n-id",bt._l10nResizer[u])}}const s=l(this,oi)[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,oi).length/4);if(n!==i){if(n<i)for(let o=0;o<i-n;o++)l(this,ve).append(l(this,ve).firstChild);else if(n>i)for(let o=0;o<n-i;o++)l(this,ve).firstChild.before(l(this,ve).lastChild);let r=0;for(const o of e){const c=l(this,oi)[r++].getAttribute("data-resizer-name");o.setAttribute("data-l10n-id",bt._l10nResizer[c])}}y(this,et,pp).call(this,0),v(this,dn,!0),l(this,ve).firstChild.focus({focusVisible:!0}),t.preventDefault(),t.stopImmediatePropagation()}_resizeWithKeyboard(t,e){l(this,dn)&&y(this,et,dp).call(this,l(this,yl),{deltaX:t,deltaY:e,fromKeyboard:!0})}_stopResizingWithKeyboard(){y(this,et,Ec).call(this),this.div.focus()}select(){var t,e,s;if(this.makeResizable(),(t=this.div)==null||t.classList.add("selectedEditor"),!this._editToolbar){this.addEditToolbar().then(()=>{var i,n;(i=this.div)!=null&&i.classList.contains("selectedEditor")&&((n=this._editToolbar)==null||n.show())});return}(e=this._editToolbar)==null||e.show(),(s=l(this,Vt))==null||s.toggleAltTextBadge(!1)}unselect(){var t,e,s,i,n;(t=l(this,ve))==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,Vt))==null||n.toggleAltTextBadge(!0)}updateParams(t,e){}disableEditing(){}enableEditing(){}enterInEditMode(){}getImageForAltText(){return null}get contentDiv(){return this.div}get isEditing(){return l(this,_l)}set isEditing(t){v(this,_l,t),this.parent&&(t?(this.parent.setSelected(this),this.parent.setActiveEditor(this)):this.parent.setActiveEditor(null))}setAspectRatio(t,e){v(this,to,!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,Rs)||v(this,Rs,new Map);const{action:s}=t;let i=l(this,Rs).get(s);i&&clearTimeout(i),i=setTimeout(()=>{this._reportTelemetry(t),l(this,Rs).delete(s),l(this,Rs).size===0&&v(this,Rs,null)},bt._telemetryTimeout),l(this,Rs).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,Sa,!1)}disable(){this.div&&(this.div.tabIndex=-1),v(this,Sa,!0)}renderAnnotationElement(t){let e=t.container.querySelector(".annotationContent");if(!e)e=document.createElement("div"),e.classList.add("annotationContent",this.editorType),t.container.prepend(e);else if(e.nodeName==="CANVAS"){const s=e;e=document.createElement("div"),e.classList.add("annotationContent",this.editorType),s.before(e)}return e}resetAnnotationElement(t){const{firstChild:e}=t.container;(e==null?void 0:e.nodeName)==="DIV"&&e.classList.contains("annotationContent")&&e.remove()}};Zr=new WeakMap,oi=new WeakMap,Vt=new WeakMap,Sa=new WeakMap,ir=new WeakMap,bl=new WeakMap,to=new WeakMap,ve=new WeakMap,eo=new WeakMap,nr=new WeakMap,rr=new WeakMap,yl=new WeakMap,so=new WeakMap,Ds=new WeakMap,_l=new WeakMap,io=new WeakMap,dn=new WeakMap,Ri=new WeakMap,Ca=new WeakMap,Aa=new WeakMap,Rs=new WeakMap,wl=new WeakMap,dd=new WeakMap,et=new WeakSet,ap=function([t,e],s,i){[s,i]=this.screenToPageTranslation(s,i),this.x+=s/t,this.y+=i/e,this._onTranslating(this.x,this.y),this.fixAndSetPosition()},xl=new WeakSet,hp=function(t,e,s){switch(s){case 90:return[e,-t];case 180:return[-t,-e];case 270:return[-e,t];default:return[t,e]}},lp=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]}},Ob=function(){if(l(this,ve))return;v(this,ve,document.createElement("div")),l(this,ve).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,ve).append(i),i.classList.add("resizer",s),i.setAttribute("data-resizer-name",s),i.addEventListener("pointerdown",y(this,et,Db).bind(this,s),{signal:e}),i.addEventListener("contextmenu",ti,{signal:e}),i.tabIndex=-1}this.div.prepend(l(this,ve))},Db=function(t,e){var u;e.preventDefault();const{isMac:s}=Ge.platform;if(e.button!==0||e.ctrlKey&&s)return;(u=l(this,Vt))==null||u.toggle(!1);const i=this._isDraggable;this._isDraggable=!1,v(this,eo,[e.screenX,e.screenY]);const n=new AbortController,r=this._uiManager.combinedSignal(n);this.parent.togglePointerEvents(!1),window.addEventListener("pointermove",y(this,et,dp).bind(this,t),{passive:!0,capture:!0,signal:r}),window.addEventListener("touchmove",ei,{passive:!1,signal:r}),window.addEventListener("contextmenu",ti,{signal:r}),v(this,nr,{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,Vt))==null||d.toggle(!0),this._isDraggable=i,this.parent.div.style.cursor=o,this.div.style.cursor=h,y(this,et,up).call(this)};window.addEventListener("pointerup",c,{signal:r}),window.addEventListener("blur",c,{signal:r})},cp=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()},up=function(){if(!l(this,nr))return;const{savedX:t,savedY:e,savedWidth:s,savedHeight:i}=l(this,nr);v(this,nr,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:y(this,et,cp).bind(this,n,r,o,h),undo:y(this,et,cp).bind(this,t,e,s,i),mustExec:!0})},dp=function(t,e){const[s,i]=this.parentDimensions,n=this.x,r=this.y,o=this.width,h=this.height,c=bt.MIN_SIZE/s,u=bt.MIN_SIZE/i,d=V=>Math.round(V*1e4)/1e4,g=y(this,et,lp).call(this,this.rotation),f=(V,H)=>[g[0]*V+g[2]*H,g[1]*V+g[3]*H],p=y(this,et,lp).call(this,360-this.rotation),m=(V,H)=>[p[0]*V+p[2]*H,p[1]*V+p[3]*H];let w,b,x=!1,C=!1;switch(t){case"topLeft":x=!0,w=(V,H)=>[0,0],b=(V,H)=>[V,H];break;case"topMiddle":w=(V,H)=>[V/2,0],b=(V,H)=>[V/2,H];break;case"topRight":x=!0,w=(V,H)=>[V,0],b=(V,H)=>[0,H];break;case"middleRight":C=!0,w=(V,H)=>[V,H/2],b=(V,H)=>[0,H/2];break;case"bottomRight":x=!0,w=(V,H)=>[V,H],b=(V,H)=>[0,0];break;case"bottomMiddle":w=(V,H)=>[V/2,H],b=(V,H)=>[V/2,0];break;case"bottomLeft":x=!0,w=(V,H)=>[0,H],b=(V,H)=>[V,0];break;case"middleLeft":C=!0,w=(V,H)=>[0,H/2],b=(V,H)=>[V,H/2];break}const A=w(o,h),P=b(o,h);let D=f(...P);const k=d(n+D[0]),M=d(r+D[1]);let R=1,F=1,I,X;if(e.fromKeyboard)({deltaX:I,deltaY:X}=e);else{const{screenX:V,screenY:H}=e,[Et,jt]=l(this,eo);[I,X]=this.screenToPageTranslation(V-Et,H-jt),l(this,eo)[0]=V,l(this,eo)[1]=H}if([I,X]=m(I/s,X/i),x){const V=Math.hypot(o,h);R=F=Math.max(Math.min(Math.hypot(P[0]-A[0]-I,P[1]-A[1]-X)/V,1/o,1/h),c/o,u/h)}else C?R=Math.max(c,Math.min(1,Math.abs(P[0]-A[0]-I)))/o:F=Math.max(u,Math.min(1,Math.abs(P[1]-A[1]-X)))/h;const j=d(o*R),N=d(h*F);D=f(...b(j,N));const nt=k-D[0],K=M-D[1];l(this,Ds)||v(this,Ds,[this.x,this.y,this.width,this.height]),this.width=j,this.height=N,this.x=nt,this.y=K,this.setDims(s*j,i*N),this.fixAndSetPosition(),this._onResizing()},gp=function(t){const{isMac:e}=Ge.platform;t.ctrlKey&&!e||t.shiftKey||t.metaKey&&e?this.parent.toggleSelected(this):this.parent.setSelected(this)},Rb=function(t){const{isSelected:e}=this;this._uiManager.setUpDragSession();const s=new AbortController,i=this._uiManager.combinedSignal(s),n={capture:!0,passive:!1,signal:i},r=h=>{s.abort(),v(this,ir,null),v(this,so,!1),this._uiManager.endDragSession()||y(this,et,gp).call(this,h)};e&&(v(this,Ca,t.clientX),v(this,Aa,t.clientY),v(this,ir,t.pointerId),v(this,bl,t.pointerType),window.addEventListener("pointermove",h=>{const{clientX:c,clientY:u,pointerId:d}=h;if(d!==l(this,ir)){ei(h);return}const[g,f]=this.screenToPageTranslation(c-l(this,Ca),u-l(this,Aa));v(this,Ca,c),v(this,Aa,u),this._uiManager.dragSelectedEditors(g,f)},n),window.addEventListener("touchmove",ei,n),window.addEventListener("pointerdown",h=>{h.isPrimary&&h.pointerType===l(this,bl)&&r(h),ei(h)},n)),this._onStartDragging();const o=h=>{if(!l(this,ir)||l(this,ir)===h.pointerId){r(h),this._onStopDragging();return}ei(h)};window.addEventListener("pointerup",o,{signal:i}),window.addEventListener("blur",o,{signal:i})},fp=function(){if(l(this,rr)||!this.div)return;v(this,rr,new AbortController);const t=this._uiManager.combinedSignal(l(this,rr));this.div.addEventListener("focusin",this.focusin.bind(this),{signal:t}),this.div.addEventListener("focusout",this.focusout.bind(this),{signal:t})},Lb=function(t){bt._resizerKeyboardManager.exec(this,t)},Fb=function(t){var e;l(this,dn)&&((e=t.relatedTarget)==null?void 0:e.parentNode)!==l(this,ve)&&y(this,et,Ec).call(this)},Ib=function(t){v(this,yl,l(this,dn)?t:"")},pp=function(t){if(l(this,oi))for(const e of l(this,oi))e.tabIndex=t},Ec=function(){v(this,dn,!1),y(this,et,pp).call(this,-1),y(this,et,up).call(this)},_(bt,xl),q(bt,"_l10n",null),q(bt,"_l10nResizer",null),q(bt,"_borderLineWidth",-1),q(bt,"_colorManager",new bf),q(bt,"_zIndex",1),q(bt,"_telemetryTimeout",1e3);let Bt=bt;class Qx extends Bt{constructor(t){super(t),this.annotationElementId=t.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}}const lv=3285377520,ks=4294901760,Ci=65535;class cv{constructor(t){this.h1=t?t&4294967295:lv,this.h2=t?t&4294967295:lv}update(t){let e,s;if(typeof t=="string"){e=new Uint8Array(t.length*2),s=0;for(let m=0,w=t.length;m<w;m++){const 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,g=461845907,f=d&Ci,p=g&Ci;for(let m=0;m<i;m++)m&1?(o=r[m],o=o*d&ks|o*f&Ci,o=o<<15|o>>>17,o=o*g&ks|o*p&Ci,c^=o,c=c<<13|c>>>19,c=c*5+3864292196):(h=r[m],h=h*d&ks|h*f&Ci,h=h<<15|h>>>17,h=h*g&ks|h*p&Ci,u^=h,u=u<<13|u>>>19,u=u*5+3864292196);switch(o=0,n){case 3:o^=e[i*4+2]<<16;case 2:o^=e[i*4+1]<<8;case 1:o^=e[i*4],o=o*d&ks|o*f&Ci,o=o<<15|o>>>17,o=o*g&ks|o*p&Ci,i&1?c^=o:u^=o}this.h1=c,this.h2=u}hexdigest(){let t=this.h1,e=this.h2;return t^=e>>>1,t=t*3981806797&ks|t*36045&Ci,e=e*4283543511&ks|((e<<16|t>>>16)*2950163797&ks)>>>16,t^=e>>>1,t=t*444984403&ks|t*60499&Ci,e=e*3301882366&ks|((e<<16|t>>>16)*3120437893&ks)>>>16,t^=e>>>1,(t>>>0).toString(16).padStart(8,"0")+(e>>>0).toString(16).padStart(8,"0")}}const yf=Object.freeze({map:null,hash:"",transfer:void 0});class _f{constructor(){_(this,gd);_(this,no,!1);_(this,ro,null);_(this,ge,new Map);this.onSetModified=null,this.onResetModified=null,this.onAnnotationEditor=null}getValue(t,e){const s=l(this,ge).get(t);return s===void 0?e:Object.assign(e,s)}getRawValue(t){return l(this,ge).get(t)}remove(t){if(l(this,ge).delete(t),l(this,ge).size===0&&this.resetModified(),typeof this.onAnnotationEditor=="function"){for(const e of l(this,ge).values())if(e instanceof Bt)return;this.onAnnotationEditor(null)}}setValue(t,e){const s=l(this,ge).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,ge).set(t,e);i&&y(this,gd,jb).call(this),e instanceof Bt&&typeof this.onAnnotationEditor=="function"&&this.onAnnotationEditor(e.constructor._type)}has(t){return l(this,ge).has(t)}getAll(){return l(this,ge).size>0?af(l(this,ge)):null}setAll(t){for(const[e,s]of Object.entries(t))this.setValue(e,s)}get size(){return l(this,ge).size}resetModified(){l(this,no)&&(v(this,no,!1),typeof this.onResetModified=="function"&&this.onResetModified())}get print(){return new uv(this)}get serializable(){if(l(this,ge).size===0)return yf;const t=new Map,e=new cv,s=[],i=Object.create(null);let n=!1;for(const[r,o]of l(this,ge)){const h=o instanceof Bt?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}:yf}get editorStats(){let t=null;const e=new Map;for(const s of l(this,ge).values()){if(!(s instanceof Bt))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,ro,null)}get modifiedIds(){if(l(this,ro))return l(this,ro);const t=[];for(const e of l(this,ge).values())!(e instanceof Bt)||!e.annotationElementId||!e.serialize()||t.push(e.annotationElementId);return v(this,ro,{ids:new Set(t),hash:t.join(",")})}}no=new WeakMap,ro=new WeakMap,ge=new WeakMap,gd=new WeakSet,jb=function(){l(this,no)||(v(this,no,!0),typeof this.onSetModified=="function"&&this.onSetModified())};class uv extends _f{constructor(e){super();_(this,Sl);const{map:s,hash:i,transfer:n}=e.serializable,r=structuredClone(s,n?{transfer:n}:null);v(this,Sl,{map:r,hash:i,transfer:n})}get print(){St("Should not call PrintAnnotationStorage.print")}get serializable(){return l(this,Sl)}get modifiedIds(){return at(this,"modifiedIds",{ids:new Set,hash:""})}}Sl=new WeakMap;class Zx{constructor({ownerDocument:t=globalThis.document,styleElement:e=null}){_(this,Ta,new Set);this._document=t,this.nativeFontFaces=new Set,this.styleElement=null,this.loadingRequests=[],this.loadTestFontId=0}addNativeFontFace(t){this.nativeFontFaces.add(t),this._document.fonts.add(t)}removeNativeFontFace(t){this.nativeFontFaces.delete(t),this._document.fonts.delete(t)}insertRule(t){this.styleElement||(this.styleElement=this._document.createElement("style"),this._document.documentElement.getElementsByTagName("head")[0].append(this.styleElement));const e=this.styleElement.sheet;e.insertRule(t,e.cssRules.length)}clear(){for(const t of this.nativeFontFaces)this._document.fonts.delete(t);this.nativeFontFaces.clear(),l(this,Ta).clear(),this.styleElement&&(this.styleElement.remove(),this.styleElement=null)}async loadSystemFont({systemFontInfo:t,_inspectFont:e}){if(!(!t||l(this,Ta).has(t.loadedName))){if(te(!this.disableFontFace,"loadSystemFont shouldn't be called when `disableFontFace` is set."),this.isFontLoadingAPISupported){const{loadedName:s,src:i,style:n}=t,r=new FontFace(s,i,n);this.addNativeFontFace(r);try{await r.load(),l(this,Ta).add(s),e==null||e(t)}catch{rt(`Cannot load system font: ${t.baseFontName}, installing it could help to improve PDF rendering.`),this.removeNativeFontFace(r)}return}St("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 rt(`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 at(this,"isFontLoadingAPISupported",t)}get isSyncFontLoadingSupported(){let t=!1;return(Ve||typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.userAgent)=="string"&&/Mozilla\/5.0.*?rv:\d+.*? Gecko/.test(navigator.userAgent))&&(t=!0),at(this,"isSyncFontLoadingSupported",t)}_queueLoadingCallback(t){function e(){for(te(!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 at(this,"_loadTestFont",t)}_prepareFontLoadEvent(t,e){function s(A,P){return A.charCodeAt(P)<<24|A.charCodeAt(P+1)<<16|A.charCodeAt(P+2)<<8|A.charCodeAt(P+3)&255}function i(A,P,D,k){const M=A.substring(0,P),R=A.substring(P+D);return M+k+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(A,P){if(++c>30){rt("Load test font never loaded."),P();return}if(h.font="30px "+A,h.fillText(".",0,20),h.getImageData(0,0,1,1).data[3]>0){P();return}setTimeout(u.bind(null,A,P))}const d=`lt${Date.now()}${this.loadTestFontId++}`;let g=this._loadTestFont;g=i(g,976,d.length,d);const p=16,m=1482184792;let w=s(g,p);for(n=0,r=d.length-3;n<r;n+=4)w=w-m+s(d,n)|0;n<d.length&&(w=w-m+s(d+"XXX",n)|0),g=i(g,p,4,Nx(w));const b=`url(data:font/opentype;base64,${btoa(g)});`,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 A of[t.loadedName,d]){const P=this._document.createElement("span");P.textContent="Hi",P.style.fontFamily=A,C.append(P)}this._document.body.append(C),u(d,()=>{C.remove(),e.complete()})}}Ta=new WeakMap;class tS{constructor(t,{disableFontFace:e=!1,inspectFont:s=null}){this.compiledGlyphs=Object.create(null);for(const i in t)this[i]=t[i];this.disableFontFace=e===!0,this._inspectFont=s}createNativeFontFace(){var e;if(!this.data||this.disableFontFace)return null;let t;if(!this.cssFontInfo)t=new FontFace(this.loadedName,this.data,{});else{const s={weight:this.cssFontInfo.fontWeight};this.cssFontInfo.italicAngle&&(s.style=`oblique ${this.cssFontInfo.italicAngle}deg`),t=new FontFace(this.cssFontInfo.fontFamily,this.data,s)}return(e=this._inspectFont)==null||e.call(this,this),t}createFontFaceRule(){var s;if(!this.data||this.disableFontFace)return null;const t=`url(data:${this.mimetype};base64,${zx(this.data)});`;let e;if(!this.cssFontInfo)e=`@font-face {font-family:"${this.loadedName}";src:${t}}`;else{let i=`font-weight: ${this.cssFontInfo.fontWeight};`;this.cssFontInfo.italicAngle&&(i+=`font-style: oblique ${this.cssFontInfo.italicAngle}deg;`),e=`@font-face {font-family:"${this.cssFontInfo.fontFamily}";${i}src:${t}}`}return(s=this._inspectFont)==null||s.call(this,this,t),e}getPathGenerator(t,e){if(this.compiledGlyphs[e]!==void 0)return this.compiledGlyphs[e];let s;try{s=t.get(this.loadedName+"_path_"+e)}catch(n){rt(`getPathGenerator - ignoring character: "${n}".`)}if(!Array.isArray(s)||s.length===0)return this.compiledGlyphs[e]=function(n,r){};const i=[];for(let n=0,r=s.length;n<r;)switch(s[n++]){case sn.BEZIER_CURVE_TO:{const[o,h,c,u,d,g]=s.slice(n,n+6);i.push(f=>f.bezierCurveTo(o,h,c,u,d,g)),n+=6}break;case sn.MOVE_TO:{const[o,h]=s.slice(n,n+2);i.push(c=>c.moveTo(o,h)),n+=2}break;case sn.LINE_TO:{const[o,h]=s.slice(n,n+2);i.push(c=>c.lineTo(o,h)),n+=2}break;case sn.QUADRATIC_CURVE_TO:{const[o,h,c,u]=s.slice(n,n+4);i.push(d=>d.quadraticCurveTo(o,h,c,u)),n+=4}break;case sn.RESTORE:i.push(o=>o.restore());break;case sn.SAVE:i.push(o=>o.save());break;case sn.SCALE:te(i.length===2,"Scale command is only valid at the third position.");break;case sn.TRANSFORM:{const[o,h,c,u,d,g]=s.slice(n,n+6);i.push(f=>f.transform(o,h,c,u,d,g)),n+=6}break;case sn.TRANSLATE:{const[o,h]=s.slice(n,n+2);i.push(c=>c.translate(o,h)),n+=2}break}return i.push(n=>n.closePath()),this.compiledGlyphs[e]=function(r,o){i[0](r),i[1](r),r.scale(o,-o);for(let h=2,c=i.length;h<c;h++)i[h](r)}}}class dv{constructor({enableHWA:t=!1}){_(this,Cl,!1);v(this,Cl,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,Cl)})}}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){St("Abstract method `_createCanvas` called.")}}Cl=new WeakMap;class eS extends dv{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 gv{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){St("Abstract method `_fetch` called.")}}class fv extends gv{async _fetch(t){const e=await Uu(t,this.isCompressed?"arraybuffer":"text");return e instanceof ArrayBuffer?new Uint8Array(e):Xu(e)}}class pv{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 sS extends pv{constructor({docId:e,ownerDocument:s=globalThis.document}){super();_(this,z);_(this,oo);_(this,Ea);_(this,gn);_(this,fn);_(this,Me);_(this,ao);_(this,ho,0);v(this,fn,e),v(this,Me,s)}addFilter(e){if(!e)return"none";let s=l(this,z,Le).get(e);if(s)return s;const[i,n,r]=y(this,z,Fd).call(this,e),o=e.length===1?i:`${i}${n}${r}`;if(s=l(this,z,Le).get(o),s)return l(this,z,Le).set(e,s),s;const h=`g_${l(this,fn)}_transfer_map_${Ke(this,ho)._++}`,c=y(this,z,wh).call(this,h);l(this,z,Le).set(e,c),l(this,z,Le).set(o,c);const u=y(this,z,xh).call(this,h);return y(this,z,Mc).call(this,i,n,r,u),c}addHCMFilter(e,s){var p;const i=`${e}-${s}`,n="base";let r=l(this,z,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,z,kc).set(n,r)),!e||!s))return r.url;const o=y(this,z,Oc).call(this,e);e=$.makeHexColor(...o);const h=y(this,z,Oc).call(this,s);if(s=$.makeHexColor(...h),l(this,z,_h).style.color="",e==="#000000"&&s==="#ffffff"||e===s)return r.url;const c=new Array(256);for(let m=0;m<=255;m++){const w=m/255;c[m]=w<=.03928?w/12.92:((w+.055)/1.055)**2.4}const u=c.join(","),d=`g_${l(this,fn)}_hcm_filter`,g=r.filter=y(this,z,xh).call(this,d);y(this,z,Mc).call(this,u,u,u,g),y(this,z,mp).call(this,g);const f=(m,w)=>{const b=o[m]/255,x=h[m]/255,C=new Array(w+1);for(let A=0;A<=w;A++)C[A]=b+A/w*(x-b);return C.join(",")};return y(this,z,Mc).call(this,f(0,5),f(1,5),f(2,5),g),r.url=y(this,z,wh).call(this,d),r.url}addAlphaFilter(e){let s=l(this,z,Le).get(e);if(s)return s;const[i]=y(this,z,Fd).call(this,[e]),n=`alpha_${i}`;if(s=l(this,z,Le).get(n),s)return l(this,z,Le).set(e,s),s;const r=`g_${l(this,fn)}_alpha_map_${Ke(this,ho)._++}`,o=y(this,z,wh).call(this,r);l(this,z,Le).set(e,o),l(this,z,Le).set(n,o);const h=y(this,z,xh).call(this,r);return y(this,z,vp).call(this,i,h),o}addLuminosityFilter(e){let s=l(this,z,Le).get(e||"luminosity");if(s)return s;let i,n;if(e?([i]=y(this,z,Fd).call(this,[e]),n=`luminosity_${i}`):n="luminosity",s=l(this,z,Le).get(n),s)return l(this,z,Le).set(e,s),s;const r=`g_${l(this,fn)}_luminosity_map_${Ke(this,ho)._++}`,o=y(this,z,wh).call(this,r);l(this,z,Le).set(e,o),l(this,z,Le).set(n,o);const h=y(this,z,xh).call(this,r);return y(this,z,Nb).call(this,h),e&&y(this,z,vp).call(this,i,h),o}addHighlightHCMFilter(e,s,i,n,r){var x;const o=`${s}-${i}-${n}-${r}`;let h=l(this,z,kc).get(e);if((h==null?void 0:h.key)===o||(h?((x=h.filter)==null||x.remove(),h.key=o,h.url="none",h.filter=null):(h={key:o,url:"none",filter:null},l(this,z,kc).set(e,h)),!s||!i))return h.url;const[c,u]=[s,i].map(y(this,z,Oc).bind(this));let d=Math.round(.2126*c[0]+.7152*c[1]+.0722*c[2]),g=Math.round(.2126*u[0]+.7152*u[1]+.0722*u[2]),[f,p]=[n,r].map(y(this,z,Oc).bind(this));g<d&&([d,g,f,p]=[g,d,p,f]),l(this,z,_h).style.color="";const m=(C,A,P)=>{const D=new Array(256),k=(g-d)/P,M=C/255,R=(A-C)/(255*P);let F=0;for(let I=0;I<=P;I++){const X=Math.round(d+I*k),j=M+I*R;for(let N=F;N<=X;N++)D[N]=j;F=X+1}for(let I=F;I<256;I++)D[I]=D[F-1];return D.join(",")},w=`g_${l(this,fn)}_hcm_${e}_filter`,b=h.filter=y(this,z,xh).call(this,w);return y(this,z,mp).call(this,b),y(this,z,Mc).call(this,m(f[0],p[0],5),m(f[1],p[1],5),m(f[2],p[2],5),b),h.url=y(this,z,wh).call(this,w),h.url}destroy(e=!1){var s,i,n,r;e&&((s=l(this,ao))!=null&&s.size)||((i=l(this,gn))==null||i.parentNode.parentNode.remove(),v(this,gn,null),(n=l(this,Ea))==null||n.clear(),v(this,Ea,null),(r=l(this,ao))==null||r.clear(),v(this,ao,null),v(this,ho,0))}}oo=new WeakMap,Ea=new WeakMap,gn=new WeakMap,fn=new WeakMap,Me=new WeakMap,ao=new WeakMap,ho=new WeakMap,z=new WeakSet,Le=function(){return l(this,Ea)||v(this,Ea,new Map)},kc=function(){return l(this,ao)||v(this,ao,new Map)},_h=function(){if(!l(this,gn)){const e=l(this,Me).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,Me).createElementNS(nn,"svg");i.setAttribute("width",0),i.setAttribute("height",0),v(this,gn,l(this,Me).createElementNS(nn,"defs")),e.append(i),i.append(l(this,gn)),l(this,Me).body.append(e)}return l(this,gn)},Fd=function(e){if(e.length===1){const c=e[0],u=new Array(256);for(let g=0;g<256;g++)u[g]=c[g]/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(",")]},wh=function(e){if(l(this,oo)===void 0){v(this,oo,"");const s=l(this,Me).URL;s!==l(this,Me).baseURI&&(Yu(s)?rt('#createUrl: ignore "data:"-URL for performance reasons.'):v(this,oo,s.split("#",1)[0]))}return`url(${l(this,oo)}#${e})`},Nb=function(e){const s=l(this,Me).createElementNS(nn,"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)},mp=function(e){const s=l(this,Me).createElementNS(nn,"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)},xh=function(e){const s=l(this,Me).createElementNS(nn,"filter");return s.setAttribute("color-interpolation-filters","sRGB"),s.setAttribute("id",e),l(this,z,_h).append(s),s},Pc=function(e,s,i){const n=l(this,Me).createElementNS(nn,s);n.setAttribute("type","discrete"),n.setAttribute("tableValues",i),e.append(n)},Mc=function(e,s,i,n){const r=l(this,Me).createElementNS(nn,"feComponentTransfer");n.append(r),y(this,z,Pc).call(this,r,"feFuncR",e),y(this,z,Pc).call(this,r,"feFuncG",s),y(this,z,Pc).call(this,r,"feFuncB",i)},vp=function(e,s){const i=l(this,Me).createElementNS(nn,"feComponentTransfer");s.append(i),y(this,z,Pc).call(this,i,"feFuncA",e)},Oc=function(e){return l(this,z,_h).style.color=e,ff(getComputedStyle(l(this,z,_h)).getPropertyValue("color"))};class mv{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){St("Abstract method `_fetch` called.")}}class vv extends mv{async _fetch(t){const e=await Uu(t,"arraybuffer");return new Uint8Array(e)}}async function bv(a){const e=await process.getBuiltinModule("fs").promises.readFile(a);return new Uint8Array(e)}class iS extends pv{}class nS extends dv{_createCanvas(t,e){return process.getBuiltinModule("module").createRequire(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Pt&&Pt.tagName.toUpperCase()==="SCRIPT"&&Pt.src||new URL("pdf-canvas.umd.js",document.baseURI).href)("@napi-rs/canvas").createCanvas(t,e)}}class rS extends gv{async _fetch(t){return bv(t)}}class oS extends mv{async _fetch(t){return bv(t)}}const ke={FILL:"Fill",STROKE:"Stroke",SHADING:"Shading"};function wf(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 xf{getPattern(){St("Abstract method `getPattern` called.")}}class aS extends xf{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===ke.STROKE||i===ke.FILL){const r=e.current.getClippedPathBoundingBox(i,Lt(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=$.transform(s,[1,0,0,1,r[0],r[1]]),u.transform(...e.baseTransform),this.matrix&&u.transform(...this.matrix),wf(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 wf(t,this._bbox),n=this._createGradient(t);return n}}function Sf(a,t,e,s,i,n,r,o){const h=t.coords,c=t.colors,u=a.data,d=a.width*4;let g;h[e+1]>h[s+1]&&(g=e,e=s,s=g,g=n,n=r,r=g),h[s+1]>h[i+1]&&(g=s,s=i,i=g,g=r,r=o,o=g),h[e+1]>h[s+1]&&(g=e,e=s,s=g,g=n,n=r,r=g);const f=(h[e]+t.offsetX)*t.scaleX,p=(h[e+1]+t.offsetY)*t.scaleY,m=(h[s]+t.offsetX)*t.scaleX,w=(h[s+1]+t.offsetY)*t.scaleY,b=(h[i]+t.offsetX)*t.scaleX,x=(h[i+1]+t.offsetY)*t.scaleY;if(p>=x)return;const C=c[n],A=c[n+1],P=c[n+2],D=c[r],k=c[r+1],M=c[r+2],R=c[o],F=c[o+1],I=c[o+2],X=Math.round(p),j=Math.round(x);let N,nt,K,V,H,Et,jt,ie;for(let Wt=X;Wt<=j;Wt++){if(Wt<w){const dt=Wt<p?0:(p-Wt)/(p-w);N=f-(f-m)*dt,nt=C-(C-D)*dt,K=A-(A-k)*dt,V=P-(P-M)*dt}else{let dt;Wt>x?dt=1:w===x?dt=0:dt=(w-Wt)/(w-x),N=m-(m-b)*dt,nt=D-(D-R)*dt,K=k-(k-F)*dt,V=M-(M-I)*dt}let Tt;Wt<p?Tt=0:Wt>x?Tt=1:Tt=(p-Wt)/(p-x),H=f-(f-b)*Tt,Et=C-(C-R)*Tt,jt=A-(A-F)*Tt,ie=P-(P-I)*Tt;const xe=Math.round(Math.min(N,H)),Gs=Math.round(Math.max(N,H));let Ot=d*Wt+xe*4;for(let dt=xe;dt<=Gs;dt++)Tt=(N-dt)/(N-H),Tt<0?Tt=0:Tt>1&&(Tt=1),u[Ot++]=nt-(nt-Et)*Tt|0,u[Ot++]=K-(K-jt)*Tt|0,u[Ot++]=V-(V-ie)*Tt|0,u[Ot++]=255}}function hS(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++)Sf(a,e,s[u],s[u+1],s[u+o],i[u],i[u+1],i[u+o]),Sf(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)Sf(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 lS extends xf{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),g=Math.min(Math.ceil(Math.abs(u*t[1]*1.1)),3e3),f=c/d,p=u/g,m={coords:this._coords,colors:this._colors,offsetX:-o,offsetY:-h,scaleX:1/f,scaleY:1/p},w=d+2*2,b=g+2*2,x=s.getCanvas("mesh",w,b),C=x.context,A=C.createImageData(d,g);if(e){const D=A.data;for(let k=0,M=D.length;k<M;k+=4)D[k]=e[0],D[k+1]=e[1],D[k+2]=e[2],D[k+3]=255}for(const D of this._figures)hS(A,D,m);return C.putImageData(A,2,2),{canvas:x.canvas,offsetX:o-2*f,offsetY:h-2*p,scaleX:f,scaleY:p}}getPattern(t,e,s,i){wf(t,this._bbox);let n;if(i===ke.SHADING)n=$.singularValueDecompose2dScale(Lt(t));else if(n=$.singularValueDecompose2dScale(e.baseTransform),this.matrix){const o=$.singularValueDecompose2dScale(this.matrix);n=[n[0]*o[0],n[1]*o[1]]}const r=this._createMeshCanvas(n,i===ke.SHADING?null:this._background,e.cachedCanvases);return i!==ke.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 cS extends xf{getPattern(){return"hotpink"}}function uS(a){switch(a[0]){case"RadialAxial":return new aS(a);case"Mesh":return new lS(a);case"Dummy":return new cS}throw new Error(`Unknown IR type: ${a[0]}`)}const yv={COLORED:1,UNCOLORED:2},fd=class fd{constructor(t,e,s,i,n){this.operatorList=t[2],this.matrix=t[3],this.bbox=t[4],this.xstep=t[5],this.ystep=t[6],this.paintType=t[7],this.tilingType=t[8],this.color=e,this.ctx=s,this.canvasGraphicsFactory=i,this.baseTransform=n}createPatternCanvas(t){const{bbox:e,operatorList:s,paintType:i,tilingType:n,color:r,canvasGraphicsFactory:o}=this;let{xstep:h,ystep:c}=this;h=Math.abs(h),c=Math.abs(c),Wu("TilingType: "+n);const u=e[0],d=e[1],g=e[2],f=e[3],p=g-u,m=f-d,w=$.singularValueDecompose2dScale(this.matrix),b=$.singularValueDecompose2dScale(this.baseTransform),x=w[0]*b[0],C=w[1]*b[1];let A=p,P=m,D=!1,k=!1;const M=Math.ceil(h*x),R=Math.ceil(c*C),F=Math.ceil(p*x),I=Math.ceil(m*C);M>=F?A=h:D=!0,R>=I?P=c:k=!0;const X=this.getSizeAndScale(A,this.ctx.canvas.width,x),j=this.getSizeAndScale(P,this.ctx.canvas.height,C),N=t.cachedCanvases.getCanvas("pattern",X.size,j.size),nt=N.context,K=o.createCanvasGraphics(nt);if(K.groupLevel=t.groupLevel,this.setFillAndStrokeStyleToContext(K,i,r),nt.translate(-X.scale*u,-j.scale*d),K.transform(X.scale,0,0,j.scale,0,0),nt.save(),this.clipBbox(K,u,d,g,f),K.baseTransform=Lt(K.ctx),K.executeOperatorList(s),K.endDrawing(),nt.restore(),D||k){const V=N.canvas;D&&(A=h),k&&(P=c);const H=this.getSizeAndScale(A,this.ctx.canvas.width,x),Et=this.getSizeAndScale(P,this.ctx.canvas.height,C),jt=H.size,ie=Et.size,Wt=t.cachedCanvases.getCanvas("pattern-workaround",jt,ie),Tt=Wt.context,xe=D?Math.floor(p/h):0,Gs=k?Math.floor(m/c):0;for(let Ot=0;Ot<=xe;Ot++)for(let dt=0;dt<=Gs;dt++)Tt.drawImage(V,jt*Ot,ie*dt,jt,ie,0,0,jt,ie);return{canvas:Wt.canvas,scaleX:H.scale,scaleY:Et.scale,offsetX:u,offsetY:d}}return{canvas:N.canvas,scaleX:X.scale,scaleY:j.scale,offsetX:u,offsetY:d}}getSizeAndScale(t,e,s){const i=Math.max(fd.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(Lt(t.ctx),[e,s,i,n]),t.clip(),t.endPath()}setFillAndStrokeStyleToContext(t,e,s){const i=t.ctx,n=t.current;switch(e){case yv.COLORED:const r=this.ctx;i.fillStyle=r.fillStyle,i.strokeStyle=r.strokeStyle,n.fillColor=r.fillStyle,n.strokeColor=r.strokeStyle;break;case yv.UNCOLORED:const o=$.makeHexColor(s[0],s[1],s[2]);i.fillStyle=o,i.strokeStyle=o,n.fillColor=o,n.strokeColor=o;break;default:throw new jx(`Unsupported paint type: ${e}`)}}getPattern(t,e,s,i){let n=s;i!==ke.SHADING&&(n=$.transform(n,e.baseTransform),this.matrix&&(n=$.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(fd,"MAX_PATTERN_SIZE",3e3);let Cf=fd;function dS({src:a,srcPos:t=0,dest:e,width:s,height:i,nonBlackColor:n=4294967295,inverseDecode:r=!1}){const o=Ge.isLittleEndian?4278190080:255,[h,c]=r?[n,o]:[o,n],u=s>>3,d=s&7,g=a.length;e=new Uint32Array(e.buffer);let f=0;for(let p=0;p<i;p++){for(const w=t+u;t<w;t++){const b=t<g?a[t]:255;e[f++]=b&128?c:h,e[f++]=b&64?c:h,e[f++]=b&32?c:h,e[f++]=b&16?c:h,e[f++]=b&8?c:h,e[f++]=b&4?c:h,e[f++]=b&2?c:h,e[f++]=b&1?c:h}if(d===0)continue;const m=t<g?a[t++]:255;for(let w=0;w<d;w++)e[f++]=m&1<<7-w?c:h}return{srcPos:t,destPos:f}}const _v=16,wv=100,gS=15,xv=10,Sv=1e3,ts=16;function fS(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 pS{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 Ku(a,t,e,s,i,n,r,o,h,c){const[u,d,g,f,p,m]=Lt(a);if(d===0&&g===0){const x=r*u+p,C=Math.round(x),A=o*f+m,P=Math.round(A),D=(r+h)*u+p,k=Math.abs(Math.round(D)-C)||1,M=(o+c)*f+m,R=Math.abs(Math.round(M)-P)||1;return a.setTransform(Math.sign(u),0,0,Math.sign(f),C,P),a.drawImage(t,e,s,i,n,0,0,k,R),a.setTransform(u,d,g,f,p,m),[k,R]}if(u===0&&f===0){const x=o*g+p,C=Math.round(x),A=r*d+m,P=Math.round(A),D=(o+c)*g+p,k=Math.abs(Math.round(D)-C)||1,M=(r+h)*d+m,R=Math.abs(Math.round(M)-P)||1;return a.setTransform(0,Math.sign(d),Math.sign(g),0,C,P),a.drawImage(t,e,s,i,n,0,0,R,k),a.setTransform(u,d,g,f,p,m),[R,k]}a.drawImage(t,e,s,i,n,r,o,h,c);const w=Math.hypot(u,d),b=Math.hypot(g,f);return[w*h,b*c]}function mS(a){const{width:t,height:e}=a;if(t>Sv||e>Sv)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),g=0;for(const b of a.data){let x=128;for(;x>0;)d[g++]=b&x?0:255,x>>=1}let f=0;for(g=0,d[g]!==0&&(r[0]=1,++f),h=1;h<t;h++)d[g]!==d[g+1]&&(r[h]=d[g]?2:1,++f),g++;for(d[g]!==0&&(r[h]=2,++f),o=1;o<e;o++){g=o*u,c=o*n,d[g-u]!==d[g]&&(r[c]=d[g]?1:8,++f);let b=(d[g]?4:0)+(d[g-u]?8:0);for(h=1;h<t;h++)b=(b>>2)+(d[g+1]?4:0)+(d[g-u+1]?8:0),i[b]&&(r[c+h]=i[b],++f),g++;if(d[g-u]!==d[g]&&(r[c+h]=d[g]?2:4,++f),f>s)return null}for(g=u*(e-1),c=o*n,d[g]!==0&&(r[c]=8,++f),h=1;h<t;h++)d[g]!==d[g+1]&&(r[c+h]=d[g]?4:8,++f),g++;if(d[g]!==0&&(r[c+h]=4,++f),f>s)return null;const p=new Int32Array([0,n,-1,0,-n,0,0,0,1]),m=new Path2D;for(o=0;f&&o<=e;o++){let 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 A=r[b];do{const P=p[A];do b+=P;while(!r[b]);const D=r[b];D!==5&&D!==10?(A=D,r[b]=0):(A=D&51*A>>4,r[b]&=A>>2|A<<2),m.lineTo(b%n,b/n|0),r[b]||--f}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 Cv{constructor(t,e){this.alphaIsShape=!1,this.fontSize=0,this.fontSizeScale=1,this.textMatrix=iv,this.textMatrixScale=1,this.fontMatrix=sf,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=Ee.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]=$.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=$.applyTransform(e,t),i=$.applyTransform(e.slice(2),t),n=$.applyTransform([e[0],e[3]],t),r=$.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){$.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=$.bezierBoundingBox(e,s,i,n,r,o,h,c,u);u||this.updateRectMinMax(t,d)}getPathBoundingBox(t=ke.FILL,e=null){const s=[this.minX,this.minY,this.maxX,this.maxY];if(t===ke.STROKE){e||St("Stroke bounding box must include transform.");const i=$.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=$.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=ke.FILL,e=null){return $.intersect(this.clipBox,this.getPathBoundingBox(t,e))}}function Av(a,t){if(t instanceof ImageData){a.putImageData(t,0,0);return}const e=t.height,s=t.width,i=e%ts,n=(e-i)/ts,r=i===0?n:n+1,o=a.createImageData(s,ts);let h=0,c;const u=t.data,d=o.data;let g,f,p,m;if(t.kind===Hu.GRAYSCALE_1BPP){const w=u.byteLength,b=new Uint32Array(d.buffer,0,d.byteLength>>2),x=b.length,C=s+7>>3,A=4294967295,P=Ge.isLittleEndian?4278190080:255;for(g=0;g<r;g++){for(p=g<n?ts:i,c=0,f=0;f<p;f++){const D=w-h;let k=0;const M=D>C?s:D*8-7,R=M&-8;let F=0,I=0;for(;k<R;k+=8)I=u[h++],b[c++]=I&128?A:P,b[c++]=I&64?A:P,b[c++]=I&32?A:P,b[c++]=I&16?A:P,b[c++]=I&8?A:P,b[c++]=I&4?A:P,b[c++]=I&2?A:P,b[c++]=I&1?A:P;for(;k<M;k++)F===0&&(I=u[h++],F=128),b[c++]=I&F?A:P,F>>=1}for(;c<x;)b[c++]=0;a.putImageData(o,0,g*ts)}}else if(t.kind===Hu.RGBA_32BPP){for(f=0,m=s*ts*4,g=0;g<n;g++)d.set(u.subarray(h,h+m)),h+=m,a.putImageData(o,0,f),f+=ts;g<r&&(m=s*i*4,d.set(u.subarray(h,h+m)),a.putImageData(o,0,f))}else if(t.kind===Hu.RGB_24BPP)for(p=ts,m=s*p,g=0;g<r;g++){for(g>=n&&(p=i,m=s*p),c=0,f=m;f--;)d[c++]=u[h++],d[c++]=u[h++],d[c++]=u[h++],d[c++]=255;a.putImageData(o,0,g*ts)}else throw new Error(`bad image kind: ${t.kind}`)}function Tv(a,t){if(t.bitmap){a.drawImage(t.bitmap,0,0);return}const e=t.height,s=t.width,i=e%ts,n=(e-i)/ts,r=i===0?n:n+1,o=a.createImageData(s,ts);let h=0;const c=t.data,u=o.data;for(let d=0;d<r;d++){const g=d<n?ts:i;({srcPos:h}=dS({src:c,srcPos:h,dest:u,width:s,height:g,nonBlackColor:0})),a.putImageData(o,0,d*ts)}}function Jh(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 Ju(a){if(a.strokeStyle=a.fillStyle="#000000",a.fillRule="nonzero",a.globalAlpha=1,a.lineWidth=1,a.lineCap="butt",a.lineJoin="miter",a.miterLimit=10,a.globalCompositeOperation="source-over",a.font="10px sans-serif",a.setLineDash!==void 0&&(a.setLineDash([]),a.lineDashOffset=0),!Ve){const{filter:t}=a;t!=="none"&&t!==""&&(a.filter="none")}}function Ev(a,t){if(t)return!0;const e=$.singularValueDecompose2dScale(a);e[0]=Math.fround(e[0]),e[1]=Math.fround(e[1]);const s=Math.fround((globalThis.devicePixelRatio||1)*Xn.PDF_TO_CSS_UNITS);return e[0]<=s&&e[1]<=s}const vS=["butt","round","square"],bS=["miter","round","bevel"],yS={},kv={},Gf=class Gf{constructor(t,e,s,i,n,{optionalContentConfig:r,markedContentStack:o=null},h,c){_(this,or);this.ctx=t,this.current=new Cv(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 pS(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(...Lt(this.compositeCtx))}this.ctx.save(),Ju(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=Lt(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>xv&&typeof s=="function",u=c?Date.now()+gS:0;let d=0;const g=this.commonObjs,f=this.objs;let p;for(;;){if(i!==void 0&&o===i.nextBreakPoint)return i.breakIt(o,s),o;if(p=r[o],p!==Zs.dependency)this[p].apply(this,n[o]);else for(const m of n[o]){const w=m.startsWith("g_")?g:f;if(!w.has(m))return w.get(m,s),o}if(o++,o===h)return o;if(c&&++d>xv){if(Date.now()>u)return s(),o;d=0}}}endDrawing(){y(this,or,bp).call(this),this.cachedCanvases.clear(),this.cachedPatterns.clear();for(const t of this._cachedBitmapsMap.values()){for(const e of t.values())typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement&&(e.width=e.height=0);t.clear()}this._cachedBitmapsMap.clear(),y(this,or,yp).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 g=o,f=h;n>2&&o>1&&(g=o>=16384?Math.floor(o/2)-1||1:Math.ceil(o/2),n/=o/g),r>2&&h>1&&(f=h>=16384?Math.floor(h/2)-1||1:Math.ceil(h)/2,r/=h/f),u=this.cachedCanvases.getCanvas(c,g,f),d=u.context,d.clearRect(0,0,g,f),d.drawImage(t,0,0,o,h,0,0,g,f),t=u.canvas,o=g,h=f,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=Lt(e);let h,c,u,d;if((t.bitmap||t.data)&&t.count>1){const M=t.bitmap||t.data.buffer;c=JSON.stringify(r?o:[o.slice(0,4),n]),h=this._cachedBitmapsMap.get(M),h||(h=new Map,this._cachedBitmapsMap.set(M,h));const R=h.get(c);if(R&&!r){const F=Math.round(Math.min(o[0],o[2])+o[4]),I=Math.round(Math.min(o[1],o[3])+o[5]);return{canvas:R,offsetX:F,offsetY:I}}u=R}u||(d=this.cachedCanvases.getCanvas("maskCanvas",s,i),Tv(d.context,t));let g=$.transform(o,[1/s,0,0,-1/i,0,0]);g=$.transform(g,[1,0,0,1,0,-i]);const[f,p,m,w]=$.getAxialAlignedBoundingBox([0,0,s,i],g),b=Math.round(m-f)||1,x=Math.round(w-p)||1,C=this.cachedCanvases.getCanvas("fillCanvas",b,x),A=C.context,P=f,D=p;A.translate(-P,-D),A.transform(...g),u||(u=this._scaleImage(d.canvas,Si(A)),u=u.img,h&&r&&h.set(c,u)),A.imageSmoothingEnabled=Ev(Lt(A),t.interpolate),Ku(A,u,0,0,u.width,u.height,0,0,s,i),A.globalCompositeOperation="source-in";const k=$.transform(Si(A),[1,0,0,1,-P,-D]);return A.fillStyle=r?n.getPattern(e,this,k,ke.FILL):n,A.fillRect(0,0,s,i),h&&!r&&(this.cachedCanvases.delete("fillCanvas"),h.set(c,C.canvas)),{canvas:C.canvas,offsetX:Math.round(P),offsetY:Math.round(D)}}setLineWidth(t){t!==this.current.lineWidth&&(this._cachedScaleForStroking[0]=-1),this.current.lineWidth=t,this.ctx.lineWidth=t}setLineCap(t){this.ctx.lineCap=vS[t]}setLineJoin(t){this.ctx.lineJoin=bS[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(...Lt(this.suspendedCtx)),Jh(this.suspendedCtx,n),fS(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(),Jh(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 g=t.canvas,f=h-u,p=c-d;if(r){const w=$.makeHexColor(...r);if(f<0||p<0||f+s>g.width||p+i>g.height){const b=this.cachedCanvases.getCanvas("maskExtension",s,i),x=b.context;x.drawImage(g,-f,-p),x.globalCompositeOperation="destination-atop",x.fillStyle=w,x.fillRect(0,0,s,i),x.globalCompositeOperation="source-over",g=b.canvas,f=p=0}else{t.save(),t.globalAlpha=1,t.setTransform(1,0,0,1,0,0);const b=new Path2D;b.rect(f,p,s,i),t.clip(b),t.globalCompositeOperation="destination-atop",t.fillStyle=w,t.fillRect(f,p,s,i),t.restore()}}e.save(),e.globalAlpha=1,e.setTransform(1,0,0,1,0,0),n==="Alpha"&&o?e.filter=this.filterFactory.addAlphaFilter(o):n==="Luminosity"&&(e.filter=this.filterFactory.addLuminosityFilter(o));const m=new Path2D;m.rect(h,c,s,i),e.clip(m),e.globalCompositeOperation="destination-in",e.drawImage(g,f,p,s,i,h,c,s,i),e.restore()}save(){this.inSMaskMode?(Jh(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(),Jh(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=Lt(i),d=u[0]===0&&u[3]===0||u[1]===0&&u[2]===0,g=d?s.slice(0):null;for(let f=0,p=0,m=t.length;f<m;f++)switch(t[f]|0){case Zs.rectangle:r=e[p++],o=e[p++];const w=e[p++],b=e[p++],x=r+w,C=o+b;i.moveTo(r,o),w===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 Zs.moveTo:r=e[p++],o=e[p++],i.moveTo(r,o),d||n.updatePathMinMax(u,r,o);break;case Zs.lineTo:r=e[p++],o=e[p++],i.lineTo(r,o),d||n.updatePathMinMax(u,r,o);break;case Zs.curveTo:h=r,c=o,r=e[p+4],o=e[p+5],i.bezierCurveTo(e[p],e[p+1],e[p+2],e[p+3],r,o),n.updateCurvePathMinMax(u,h,c,e[p],e[p+1],e[p+2],e[p+3],r,o,g),p+=6;break;case Zs.curveTo2:h=r,c=o,i.bezierCurveTo(r,o,e[p],e[p+1],e[p+2],e[p+3]),n.updateCurvePathMinMax(u,h,c,r,o,e[p],e[p+1],e[p+2],e[p+3],g),r=e[p+2],o=e[p+3],p+=4;break;case Zs.curveTo3:h=r,c=o,r=e[p+2],o=e[p+3],i.bezierCurveTo(e[p],e[p+1],r,o,r,o),n.updateCurvePathMinMax(u,h,c,e[p],e[p+1],r,o,r,o,g),p+=4;break;case Zs.closePath:i.closePath();break}d&&n.updateScalingPathMinMax(u,g),n.setCurrentPoint(r,o)}closePath(){this.ctx.closePath()}stroke(t=!0){const e=this.ctx,s=this.current.strokeColor;e.globalAlpha=this.current.strokeAlpha,this.contentVisible&&(typeof s=="object"&&(s!=null&&s.getPattern)?(e.save(),e.strokeStyle=s.getPattern(e,this,Si(e),ke.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,Si(e),ke.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=yS}eoClip(){this.pendingClip=kv}beginText(){this.current.textMatrix=iv,this.current.textMatrixScale=1,this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0}endText(){const t=this.pendingTextPaths,e=this.ctx;if(t===void 0){e.beginPath();return}e.save(),e.beginPath();for(const s of t)e.setTransform(...s.transform),e.translate(s.x,s.y),s.addToPath(e,s.fontSize);e.restore(),e.clip(),e.beginPath(),delete this.pendingTextPaths}setCharSpacing(t){this.current.charSpacing=t}setWordSpacing(t){this.current.wordSpacing=t}setHScale(t){this.current.textHScale=t/100}setLeading(t){this.current.leading=-t}setFont(t,e){var 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||sf,(i.fontMatrix[0]===0||i.fontMatrix[3]===0)&&rt("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<_v?c=_v:e>wv&&(c=wv),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&Ee.FILL_STROKE_MASK,g=!!(c&Ee.ADD_TO_PATH_FLAG),f=o.patternFill&&!h.missingFile,p=o.patternStroke&&!h.missingFile;let m;(h.disableFontFace||g||f||p)&&(m=h.getPathGenerator(this.commonObjs,t)),h.disableFontFace||f||p?(r.save(),r.translate(e,s),r.beginPath(),m(r,u),(d===Ee.FILL||d===Ee.FILL_STROKE)&&(i&&r.setTransform(...i),r.fill()),(d===Ee.STROKE||d===Ee.FILL_STROKE)&&(n&&r.setTransform(...n),r.stroke()),r.restore()):((d===Ee.FILL||d===Ee.FILL_STROKE)&&r.fillText(t,e,s),(d===Ee.STROKE||d===Ee.FILL_STROKE)&&r.strokeText(t,e,s)),g&&(this.pendingTextPaths||(this.pendingTextPaths=[])).push({transform:Lt(r),x:e,y:s,fontSize:u,addToPath: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 at(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,g=s.vertical,f=g?1:-1,p=s.defaultVMetrics,m=i*e.fontMatrix[0],w=e.textRenderingMode===Ee.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 k=e.fillColor.getPattern(n,this,Si(n),ke.FILL);b=Lt(n),n.restore(),n.fillStyle=k}if(e.patternStroke){n.save();const k=e.strokeColor.getPattern(n,this,Si(n),ke.STROKE);x=Lt(n),n.restore(),n.strokeStyle=k}let C=e.lineWidth;const A=e.textMatrixScale;if(A===0||C===0){const k=e.textRenderingMode&Ee.FILL_STROKE_MASK;(k===Ee.STROKE||k===Ee.FILL_STROKE)&&(C=this.getSinglePixelWidth())}else C/=A;if(r!==1&&(n.scale(r,r),C/=r),n.lineWidth=C,s.isInvalidPDFjsFont){const k=[];let M=0;for(const R of t)k.push(R.unicode),M+=R.width;n.fillText(k.join(""),0,0),e.x+=M*m*u,n.restore(),this.compose();return}let P=0,D;for(D=0;D<d;++D){const k=t[D];if(typeof k=="number"){P+=f*k*i/1e3;continue}let M=!1;const R=(k.isSpace?h:0)+o,F=k.fontChar,I=k.accent;let X,j,N=k.width;if(g){const K=k.vmetric||p,V=-(k.vmetric?K[1]:N*.5)*m,H=K[2]*m;N=K?-K[0]:N,X=V/r,j=(P+H)/r}else X=P/r,j=0;if(s.remeasure&&N>0){const K=n.measureText(F).width*1e3/i*r;if(N<K&&this.isFontSubpixelAAEnabled){const V=N/K;M=!0,n.save(),n.scale(V,1),X/=V}else N!==K&&(X+=(N-K)/2e3*i/r)}if(this.contentVisible&&(k.isInFont||s.missingFile)){if(w&&!I)n.fillText(F,X,j);else if(this.paintChar(F,X,j,b,x),I){const K=X+i*I.offset.x/r,V=j-i*I.offset.y/r;this.paintChar(I.fontChar,K,V,b,x)}}const nt=g?N*m-R*c:N*m+R*c;P+=nt,M&&n.restore()}g?e.y-=P:e.x+=P*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||sf,g=t.length,f=s.textRenderingMode===Ee.INVISIBLE;let p,m,w,b;if(!(f||n===0)){for(this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null,e.save(),e.transform(...s.textMatrix),e.translate(s.x,s.y),e.scale(u,r),p=0;p<g;++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){rt(`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()),w=$.applyTransform([m.width,0],d)[0]*n+x,e.translate(w,0),s.x+=w*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||Lt(this.ctx),n={createCanvasGraphics:r=>new Gf(r,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack})};e=new Cf(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=$.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=$.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=uS(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,Si(e),ke.SHADING);const i=Si(e);if(i){const{width:n,height:r}=e.canvas,[o,h,c,u]=$.getAxialAlignedBoundingBox([0,0,n,r],i);this.ctx.fillRect(o,h,c-o,u-h)}else this.ctx.fillRect(-1e10,-1e10,2e10,2e10);this.compose(this.current.getClippedPathBoundingBox()),this.restore()}beginInlineImage(){St("Should not call beginInlineImage")}beginImageData(){St("Should not call beginImageData")}paintFormXObjectBegin(t,e){if(this.contentVisible&&(this.save(),this.baseTransformStack.push(this.baseTransform),t&&this.transform(...t),this.baseTransform=Lt(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(Lt(this.ctx),e),this.clip(),this.endPath()}}paintFormXObjectEnd(){this.contentVisible&&(this.restore(),this.baseTransform=this.baseTransformStack.pop())}beginGroup(t){if(!this.contentVisible)return;this.save(),this.inSMaskMode&&(this.endSMaskMode(),this.current.activeSMask=null);const e=this.ctx;t.isolated||Wu("TODO: Support non-isolated groups."),t.knockout&&rt("Knockout groups not supported.");const s=Lt(e);if(t.matrix&&e.transform(...t.matrix),!t.bbox)throw new Error("Bounding box is required.");let i=$.getAxialAlignedBoundingBox(t.bbox,Lt(e));const n=[0,0,e.canvas.width,e.canvas.height];i=$.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),g=d.context;g.translate(-r,-o),g.transform(...s),t.smask?this.smaskStack.push({canvas:d.canvas,context:g,offsetX:r,offsetY:o,subtype:t.smask.subtype,backdrop:t.smask.backdrop,transferMap:t.smask.transferMap||null,startTransformInverse:null}):(e.setTransform(1,0,0,1,0,0),e.translate(r,o),e.save()),Jh(e,g),this.ctx=g,this.setGState([["BM","source-over"],["ca",1],["CA",1]]),this.groupStack.push(e),this.groupLevel++}endGroup(t){if(!this.contentVisible)return;this.groupLevel--;const e=this.ctx,s=this.groupStack.pop();if(this.ctx=s,this.ctx.imageSmoothingEnabled=!1,t.smask)this.tempSMask=this.smaskStack.pop(),this.restore();else{this.ctx.restore();const i=Lt(this.ctx);this.restore(),this.ctx.save(),this.ctx.setTransform(...i);const n=$.getAxialAlignedBoundingBox([0,0,e.canvas.width,e.canvas.height],i);this.ctx.drawImage(e.canvas,0,0),this.ctx.restore(),this.compose(n)}}beginAnnotation(t,e,s,i,n){if(y(this,or,bp).call(this),Ju(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]=$.singularValueDecompose2dScale(Lt(this.ctx)),{viewportScale:u}=this,d=Math.ceil(r*this.outputScaleX*u),g=Math.ceil(o*this.outputScaleY*u);this.annotationCanvas=this.canvasFactory.create(d,g);const{canvas:f,context:p}=this.annotationCanvas;this.annotationCanvasMap.set(t,f),this.annotationCanvas.savedCtx=this.ctx,this.ctx=p,this.ctx.save(),this.ctx.setTransform(h,0,0,-c,0,o*c),Ju(this.ctx)}else Ju(this.ctx),this.endPath(),this.ctx.rect(e[0],e[1],r,o),this.ctx.clip(),this.ctx.beginPath()}this.current=new Cv(this.ctx.canvas.width,this.ctx.canvas.height),this.transform(...s),this.transform(...i)}endAnnotation(){this.annotationCanvas&&(this.ctx.restore(),y(this,or,yp).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=mS(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=Lt(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 g=$.transform(h,[e,s,i,n,r[u],r[u+1]]),[f,p]=$.applyTransform([0,0],g);o.drawImage(c.canvas,f,p)}o.restore(),this.compose()}paintImageMaskXObjectGroup(t){if(!this.contentVisible)return;const e=this.ctx,s=this.current.fillColor,i=this.current.patternFill;for(const n of t){const{data:r,width:o,height:h,transform:c}=n,u=this.cachedCanvases.getCanvas("maskCanvas",o,h),d=u.context;d.save();const g=this.getObject(r,n);Tv(d,g),d.globalCompositeOperation="source-in",d.fillStyle=i?s.getPattern(d,this,Si(e),ke.FILL):s,d.fillRect(0,0,o,h),d.restore(),e.save(),e.transform(...c),e.scale(1,-1),Ku(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){rt("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){rt("Dependent image isn't ready yet");return}const r=n.width,o=n.height,h=[];for(let c=0,u=i.length;c<u;c+=2)h.push({transform:[e,0,0,s,i[c],i[c+1]],x:0,y:0,w:r,h:o});this.paintInlineImageXObjectGroup(n,h)}applyTransferMapsToCanvas(t){return this.current.transferMaps!=="none"&&(t.filter=this.current.transferMaps,t.drawImage(t.canvas,0,0),t.filter="none"),t.canvas}applyTransferMapsToBitmap(t){if(this.current.transferMaps==="none")return t.bitmap;const{bitmap:e,width:s,height:i}=t,n=this.cachedCanvases.getCanvas("inlineImage",s,i),r=n.context;return r.filter=this.current.transferMaps,r.drawImage(e,0,0),r.filter="none",n.canvas}paintInlineImageXObject(t){if(!this.contentVisible)return;const e=t.width,s=t.height,i=this.ctx;if(this.save(),!Ve){const{filter:o}=i;o!=="none"&&o!==""&&(i.filter="none")}i.scale(1/e,-1/s);let n;if(t.bitmap)n=this.applyTransferMapsToBitmap(t);else if(typeof HTMLElement=="function"&&t instanceof HTMLElement||!t.data)n=t;else{const h=this.cachedCanvases.getCanvas("inlineImage",e,s).context;Av(h,t),n=this.applyTransferMapsToCanvas(h)}const r=this._scaleImage(n,Si(i));i.imageSmoothingEnabled=Ev(Lt(i),t.interpolate),Ku(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;Av(h,t),i=this.applyTransferMapsToCanvas(h)}for(const n of e)s.save(),s.transform(...n.transform),s.scale(1,-1),Ku(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===kv?s.clip("evenodd"):s.clip()),this.pendingClip=null),this.current.startNewPathAndClipBox(this.current.clipBox),s.beginPath()}getSinglePixelWidth(){if(!this._cachedGetSinglePixelWidth){const t=Lt(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}};or=new WeakSet,bp=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)},yp=function(){if(this.pageColors){const t=this.filterFactory.addHCMFilter(this.pageColors.foreground,this.pageColors.background);if(t!=="none"){const e=this.ctx.filter;this.ctx.filter=t,this.ctx.drawImage(this.ctx.canvas,0,0),this.ctx.filter=e}}};let la=Gf;for(const a in Zs)la.prototype[a]!==void 0&&(la.prototype[Zs[a]]=la.prototype[a]);class rn{static get workerPort(){return l(this,Al)}static set workerPort(t){if(!(typeof Worker<"u"&&t instanceof Worker)&&t!==null)throw new Error("Invalid `workerPort` type.");v(this,Al,t)}static get workerSrc(){return l(this,Tl)}static set workerSrc(t){if(typeof t!="string")throw new Error("Invalid `workerSrc` type.");v(this,Tl,t)}}Al=new WeakMap,Tl=new WeakMap,_(rn,Al,null),_(rn,Tl,"");const Qu={UNKNOWN:0,DATA:1,ERROR:2},ee={UNKNOWN:0,CANCEL:1,CANCEL_COMPLETE:2,CLOSE:3,ENQUEUE:4,ERROR:5,PULL:6,PULL_COMPLETE:7,START_COMPLETE:8};function Pv(){}function Ps(a){switch(a instanceof Error||typeof a=="object"&&a!==null||St('wrapReason: Expected "reason" to be a (possibly cloned) Error.'),a.name){case"AbortException":return new jr(a.message);case"MissingPDFException":return new Yh(a.message);case"PasswordException":return new rf(a.message,a.code);case"UnexpectedResponseException":return new zu(a.message,a.status);case"UnknownErrorException":return new of(a.message,a.details);default:return new of(a.message,a.toString())}}class Qh{constructor(t,e,s){_(this,Ls);_(this,ka,new AbortController);this.sourceName=t,this.targetName=e,this.comObj=s,this.callbackId=1,this.streamId=1,this.streamSinks=Object.create(null),this.streamControllers=Object.create(null),this.callbackCapabilities=Object.create(null),this.actionHandler=Object.create(null),s.addEventListener("message",y(this,Ls,Bb).bind(this),{signal:l(this,ka).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:ee.PULL,streamId:n,desiredSize:c.desiredSize}),u.promise},cancel:c=>{te(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:ee.CANCEL,streamId:n,reason:Ps(c)}),u.promise}},s)}destroy(){var t;(t=l(this,ka))==null||t.abort(),v(this,ka,null)}}ka=new WeakMap,Ls=new WeakSet,Bb=function({data:t}){if(t.targetName!==this.sourceName)return;if(t.stream){y(this,Ls,Vb).call(this,t);return}if(t.callback){const s=t.callbackId,i=this.callbackCapabilities[s];if(!i)throw new Error(`Cannot resolve callback ${s}`);if(delete this.callbackCapabilities[s],t.callback===Qu.DATA)i.resolve(t.data);else if(t.callback===Qu.ERROR)i.reject(Ps(t.reason));else throw new Error("Unexpected callback case");return}const e=this.actionHandler[t.action];if(!e)throw new Error(`Unknown action from worker: ${t.action}`);if(t.callbackId){const s=this.sourceName,i=t.sourceName,n=this.comObj;Promise.try(e,t.data).then(function(r){n.postMessage({sourceName:s,targetName:i,callback:Qu.DATA,callbackId:t.callbackId,data:r})},function(r){n.postMessage({sourceName:s,targetName:i,callback:Qu.ERROR,callbackId:t.callbackId,reason:Ps(r)})});return}if(t.streamId){y(this,Ls,Hb).call(this,t);return}e(t.data)},Hb=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 g=this.desiredSize;this.desiredSize-=u,g>0&&this.desiredSize<=0&&(this.sinkCapability=Promise.withResolvers(),this.ready=this.sinkCapability.promise),n.postMessage({sourceName:s,targetName:i,stream:ee.ENQUEUE,streamId:e,chunk:c},d)},close(){this.isCancelled||(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:ee.CLOSE,streamId:e}),delete r.streamSinks[e])},error(c){te(c instanceof Error,"error must have a valid reason"),!this.isCancelled&&(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:ee.ERROR,streamId:e,reason:Ps(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:ee.START_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:ee.START_COMPLETE,streamId:e,reason:Ps(c)})})},Vb=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 ee.START_COMPLETE:t.success?r.startCall.resolve():r.startCall.reject(Ps(t.reason));break;case ee.PULL_COMPLETE:t.success?r.pullCall.resolve():r.pullCall.reject(Ps(t.reason));break;case ee.PULL:if(!o){n.postMessage({sourceName:s,targetName:i,stream:ee.PULL_COMPLETE,streamId:e,success:!0});break}o.desiredSize<=0&&t.desiredSize>0&&o.sinkCapability.resolve(),o.desiredSize=t.desiredSize,Promise.try(o.onPull||Pv).then(function(){n.postMessage({sourceName:s,targetName:i,stream:ee.PULL_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:ee.PULL_COMPLETE,streamId:e,reason:Ps(c)})});break;case ee.ENQUEUE:if(te(r,"enqueue should have stream controller"),r.isClosed)break;r.controller.enqueue(t.chunk);break;case ee.CLOSE:if(te(r,"close should have stream controller"),r.isClosed)break;r.isClosed=!0,r.controller.close(),y(this,Ls,Id).call(this,r,e);break;case ee.ERROR:te(r,"error should have stream controller"),r.controller.error(Ps(t.reason)),y(this,Ls,Id).call(this,r,e);break;case ee.CANCEL_COMPLETE:t.success?r.cancelCall.resolve():r.cancelCall.reject(Ps(t.reason)),y(this,Ls,Id).call(this,r,e);break;case ee.CANCEL:if(!o)break;const h=Ps(t.reason);Promise.try(o.onCancel||Pv,h).then(function(){n.postMessage({sourceName:s,targetName:i,stream:ee.CANCEL_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:ee.CANCEL_COMPLETE,streamId:e,reason:Ps(c)})}),o.sinkCapability.reject(h),o.isCancelled=!0,delete this.streamSinks[e];break;default:throw new Error("Unexpected stream case")}},Id=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 _S{constructor({parsedData:t,rawData:e}){_(this,lo);_(this,El);v(this,lo,t),v(this,El,e)}getRaw(){return l(this,El)}get(t){return l(this,lo).get(t)??null}getAll(){return af(l(this,lo))}has(t){return l(this,lo).has(t)}}lo=new WeakMap,El=new WeakMap;const ca=Symbol("INTERNAL");class wS{constructor(t,{name:e,intent:s,usage:i,rbGroups:n}){_(this,kl,!1);_(this,Pl,!1);_(this,Ml,!1);_(this,Pa,!0);v(this,kl,!!(t&cs.DISPLAY)),v(this,Pl,!!(t&cs.PRINT)),this.name=e,this.intent=s,this.usage=i,this.rbGroups=n}get visible(){if(l(this,Ml))return l(this,Pa);if(!l(this,Pa))return!1;const{print:t,view:e}=this.usage;return l(this,kl)?(e==null?void 0:e.viewState)!=="OFF":l(this,Pl)?(t==null?void 0:t.printState)!=="OFF":!0}_setVisible(t,e,s=!1){t!==ca&&St("Internal method `_setVisible` called."),v(this,Ml,s),v(this,Pa,e)}}kl=new WeakMap,Pl=new WeakMap,Ml=new WeakMap,Pa=new WeakMap;class xS{constructor(t,e=cs.DISPLAY){_(this,Ol);_(this,ar,null);_(this,xt,new Map);_(this,Ma,null);_(this,Oa,null);if(this.renderingIntent=e,this.name=null,this.creator=null,t!==null){this.name=t.name,this.creator=t.creator,v(this,Oa,t.order);for(const s of t.groups)l(this,xt).set(s.id,new wS(e,s));if(t.baseState==="OFF")for(const s of l(this,xt).values())s._setVisible(ca,!1);for(const s of t.on)l(this,xt).get(s)._setVisible(ca,!0);for(const s of t.off)l(this,xt).get(s)._setVisible(ca,!1);v(this,Ma,this.getHash())}}isVisible(t){if(l(this,xt).size===0)return!0;if(!t)return Wu("Optional content group not defined."),!0;if(t.type==="OCG")return l(this,xt).has(t.id)?l(this,xt).get(t.id).visible:(rt(`Optional content group not found: ${t.id}`),!0);if(t.type==="OCMD"){if(t.expression)return y(this,Ol,_p).call(this,t.expression);if(!t.policy||t.policy==="AnyOn"){for(const e of t.ids){if(!l(this,xt).has(e))return rt(`Optional content group not found: ${e}`),!0;if(l(this,xt).get(e).visible)return!0}return!1}else if(t.policy==="AllOn"){for(const e of t.ids){if(!l(this,xt).has(e))return rt(`Optional content group not found: ${e}`),!0;if(!l(this,xt).get(e).visible)return!1}return!0}else if(t.policy==="AnyOff"){for(const e of t.ids){if(!l(this,xt).has(e))return rt(`Optional content group not found: ${e}`),!0;if(!l(this,xt).get(e).visible)return!0}return!1}else if(t.policy==="AllOff"){for(const e of t.ids){if(!l(this,xt).has(e))return rt(`Optional content group not found: ${e}`),!0;if(l(this,xt).get(e).visible)return!1}return!0}return rt(`Unknown optional content policy ${t.policy}.`),!0}return rt(`Unknown group type ${t.type}.`),!0}setVisibility(t,e=!0,s=!0){var n;const i=l(this,xt).get(t);if(!i){rt(`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,xt).get(o))==null||n._setVisible(ca,!1,!0));i._setVisible(ca,!!e,!0),v(this,ar,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,xt).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,ar,null)}get hasInitialVisibility(){return l(this,Ma)===null||this.getHash()===l(this,Ma)}getOrder(){return l(this,xt).size?l(this,Oa)?l(this,Oa).slice():[...l(this,xt).keys()]:null}getGroups(){return l(this,xt).size>0?af(l(this,xt)):null}getGroup(t){return l(this,xt).get(t)||null}getHash(){if(l(this,ar)!==null)return l(this,ar);const t=new cv;for(const[e,s]of l(this,xt))t.update(`${e}:${s.visible}`);return v(this,ar,t.hexdigest())}}ar=new WeakMap,xt=new WeakMap,Ma=new WeakMap,Oa=new WeakMap,Ol=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=y(this,Ol,_p).call(this,n);else if(l(this,xt).has(n))r=l(this,xt).get(n).visible;else return rt(`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 SS{constructor(t,{disableRange:e=!1,disableStream:s=!1}){te(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)});te(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(){te(!this._fullRequestReader,"PDFDataTransportStream.getFullReader can only be called once.");const t=this._queuedChunks;return this._queuedChunks=null,new CS(this,t,this._progressiveDone,this._contentDispositionFilename)}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new AS(this,t,e);return this._pdfDataRangeTransport.requestDataRange(t,e),this._rangeReaders.push(s),s}cancelAllRequests(t){var e;(e=this._fullRequestReader)==null||e.cancel(t);for(const s of this._rangeReaders.slice(0))s.cancel(t);this._pdfDataRangeTransport.abort()}}class CS{constructor(t,e,s=!1,i=null){this._stream=t,this._done=s||!1,this._filename=df(i)?i:null,this._queuedChunks=e||[],this._loaded=0;for(const n of this._queuedChunks)this._loaded+=n.byteLength;this._requests=[],this._headersReady=Promise.resolve(),t._fullRequestReader=this,this.onProgress=null}_enqueue(t){this._done||(this._requests.length>0?this._requests.shift().resolve({value:t,done:!1}):this._queuedChunks.push(t),this._loaded+=t.byteLength)}get headersReady(){return this._headersReady}get filename(){return this._filename}get isRangeSupported(){return this._stream._isRangeSupported}get isStreamingSupported(){return this._stream._isStreamingSupported}get contentLength(){return this._stream._contentLength}async read(){if(this._queuedChunks.length>0)return{value:this._queuedChunks.shift(),done:!1};if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}progressiveDone(){this._done||(this._done=!0)}}class AS{constructor(t,e,s){this._stream=t,this._begin=e,this._end=s,this._queuedChunk=null,this._requests=[],this._done=!1,this.onProgress=null}_enqueue(t){if(!this._done){if(this._requests.length===0)this._queuedChunk=t;else{this._requests.shift().resolve({value:t,done:!1});for(const s of this._requests)s.resolve({value:void 0,done:!0});this._requests.length=0}this._done=!0,this._stream._removeRangeReader(this)}}get isStreamingSupported(){return!1}async read(){if(this._queuedChunk){const e=this._queuedChunk;return this._queuedChunk=null,{value:e,done:!1}}if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._stream._removeRangeReader(this)}}function TS(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 g=new TextDecoder(u,{fatal:!0}),f=Xu(d);d=g.decode(f),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 g;const f=s("filename\\*((?!0\\d)\\d+)(\\*?)","ig");for(;(g=f.exec(u))!==null;){let[,m,w,b]=g;if(m=parseInt(m,10),m in d){if(m===0)break;continue}d[m]=[w,b]}const p=[];for(let m=0;m<d.length&&m in d;++m){let[w,b]=d[m];b=o(b),w&&(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 g=0;g<d.length;++g){const f=d[g].indexOf('"');f!==-1&&(d[g]=d[g].slice(0,f),d.length=g+1),d[g]=d[g].replaceAll(/\\(.)/g,"$1")}u=d.join('"')}return u}function h(u){const d=u.indexOf("'");if(d===-1)return u;const g=u.slice(0,d),p=u.slice(d+1).replace(/^[^']*'/,"");return i(g,p)}function c(u){return!u.startsWith("=?")||/[\x00-\x19\x80-\xff]/.test(u)?u:u.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,function(d,g,f,p){if(f==="q"||f==="Q")return p=p.replaceAll("_"," "),p=p.replaceAll(/=([0-9a-fA-F]{2})/g,function(m,w){return String.fromCharCode(parseInt(w,16))}),i(g,p);try{p=atob(p)}catch{}return i(g,p)})}return""}function Mv(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 Zu(a){try{return new URL(a).origin}catch{}return null}function Ov({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 Dv(a){const t=a.get("Content-Disposition");if(t){let e=TS(t);if(e.includes("%"))try{e=decodeURIComponent(e)}catch{}if(df(e))return e}return null}function td(a,t){return a===404||a===0&&t.startsWith("file:")?new Yh('Missing PDF "'+t+'".'):new zu(`Unexpected server response (${a}) while retrieving PDF "${t}".`,a)}function Rv(a){return a===200||a===206}function Lv(a,t,e){return{method:"GET",headers:a,signal:e.signal,mode:"cors",credentials:t?"include":"same-origin",redirect:"follow"}}function Fv(a){return a instanceof Uint8Array?a.buffer:a instanceof ArrayBuffer?a:(rt(`getArrayBuffer - unexpected data format: ${a}`),new Uint8Array(a).buffer)}class Iv{constructor(t){q(this,"_responseOrigin",null);this.source=t,this.isHttp=/^https?:/i.test(t.url),this.headers=Mv(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 te(!this._fullRequestReader,"PDFFetchStream.getFullReader can only be called once."),this._fullRequestReader=new ES(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new kS(this,t,e);return this._rangeRequestReaders.push(s),s}cancelAllRequests(t){var e;(e=this._fullRequestReader)==null||e.cancel(t);for(const s of this._rangeRequestReaders.slice(0))s.cancel(t)}}class ES{constructor(t){this._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,Lv(s,this._withCredentials,this._abortController)).then(n=>{if(t._responseOrigin=Zu(n.url),!Rv(n.status))throw td(n.status,i);this._reader=n.body.getReader(),this._headersCapability.resolve();const r=n.headers,{allowRangeRequests:o,suggestedLength:h}=Ov({responseHeaders:r,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=o,this._contentLength=h||this._contentLength,this._filename=Dv(r),!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new jr("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:Fv(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}class kS{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,Lv(n,this._withCredentials,this._abortController)).then(o=>{const h=Zu(o.url);if(h!==t._responseOrigin)throw new Error(`Expected range response-origin "${h}" to match "${t._responseOrigin}".`);if(!Rv(o.status))throw td(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:Fv(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}const Af=200,Tf=206;function PS(a){const t=a.response;return typeof t!="string"?t:Xu(t).buffer}class MS{constructor({url:t,httpHeaders:e,withCredentials:s}){q(this,"_responseOrigin",null);this.url=t,this.isHttp=/^https?:/i.test(t),this.headers=Mv(this.isHttp,e),this.withCredentials=s||!1,this.currXhrId=0,this.pendingRequests=Object.create(null)}requestRange(t,e,s){const i={begin:t,end:e};for(const n in s)i[n]=s[n];return this.request(i)}requestFull(t){return this.request(t)}request(t){const e=new XMLHttpRequest,s=this.currXhrId++,i=this.pendingRequests[s]={xhr:e};e.open("GET",this.url),e.withCredentials=this.withCredentials;for(const[n,r]of this.headers)e.setRequestHeader(n,r);return this.isHttp&&"begin"in t&&"end"in t?(e.setRequestHeader("Range",`bytes=${t.begin}-${t.end-1}`),i.expectedStatus=Tf):i.expectedStatus=Af,e.responseType="arraybuffer",t.onError&&(e.onerror=function(n){t.onError(e.status)}),e.onreadystatechange=this.onStateChange.bind(this,s),e.onprogress=this.onProgress.bind(this,s),i.onHeadersReceived=t.onHeadersReceived,i.onDone=t.onDone,i.onError=t.onError,i.onProgress=t.onProgress,e.send(null),s}onProgress(t,e){var i;const s=this.pendingRequests[t];s&&((i=s.onProgress)==null||i.call(s,e))}onStateChange(t,e){var h,c,u;const s=this.pendingRequests[t];if(!s)return;const i=s.xhr;if(i.readyState>=2&&s.onHeadersReceived&&(s.onHeadersReceived(),delete s.onHeadersReceived),i.readyState!==4||!(t in this.pendingRequests))return;if(delete this.pendingRequests[t],i.status===0&&this.isHttp){(h=s.onError)==null||h.call(s,i.status);return}const n=i.status||Af;if(!(n===Af&&s.expectedStatus===Tf)&&n!==s.expectedStatus){(c=s.onError)==null||c.call(s,i.status);return}const o=PS(i);if(n===Tf){const d=i.getResponseHeader("Content-Range"),g=/bytes (\d+)-(\d+)\/(\d+)/.exec(d);s.onDone({begin:parseInt(g[1],10),chunk:o})}else o?s.onDone({begin:0,chunk:o}):(u=s.onError)==null||u.call(s,i.status)}getRequestXhr(t){return this.pendingRequests[t].xhr}isPendingRequest(t){return t in this.pendingRequests}abortRequest(t){const e=this.pendingRequests[t].xhr;delete this.pendingRequests[t],e.abort()}}class OS{constructor(t){this._source=t,this._manager=new MS(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 te(!this._fullRequestReader,"PDFNetworkStream.getFullReader can only be called once."),this._fullRequestReader=new DS(this._manager,this._source),this._fullRequestReader}getRangeReader(t,e){const s=new RS(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 DS{constructor(t,e){this._manager=t;const s={onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)};this._url=e.url,this._fullRequestId=t.requestFull(s),this._headersCapability=Promise.withResolvers(),this._disableRange=e.disableRange||!1,this._contentLength=e.length,this._rangeChunkSize=e.rangeChunkSize,!this._rangeChunkSize&&!this._disableRange&&(this._disableRange=!0),this._isStreamingSupported=!1,this._isRangeSupported=!1,this._cachedChunks=[],this._requests=[],this._done=!1,this._storedError=void 0,this._filename=null,this.onProgress=null}_onHeadersReceived(){const t=this._fullRequestId,e=this._manager.getRequestXhr(t);this._manager._responseOrigin=Zu(e.responseURL);const s=e.getAllResponseHeaders(),i=new Headers(s?s.trim().split(/[\r\n]+/).map(o=>{const[h,...c]=o.split(": ");return[h,c.join(": ")]}):[]),{allowRangeRequests:n,suggestedLength:r}=Ov({responseHeaders:i,isHttp:this._manager.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});n&&(this._isRangeSupported=!0),this._contentLength=r||this._contentLength,this._filename=Dv(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=td(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 RS{constructor(t,e,s){this._manager=t;const i={onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)};this._url=t.url,this._requestId=t.requestRange(e,s,i),this._requests=[],this._queuedChunk=null,this._done=!1,this._storedError=void 0,this.onProgress=null,this.onClosed=null}_onHeadersReceived(){var e;const t=Zu((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=td(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 LS=/^[a-z][a-z0-9\-+.]+:/i;function FS(a){if(LS.test(a))return new URL(a);const t=process.getBuiltinModule("url");return new URL(t.pathToFileURL(a))}class IS{constructor(t){this.source=t,this.url=FS(t.url),te(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 te(!this._fullRequestReader,"PDFNodeStream.getFullReader can only be called once."),this._fullRequestReader=new jS(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new NS(this,t,e);return this._rangeRequestReaders.push(s),s}cancelAllRequests(t){var e;(e=this._fullRequestReader)==null||e.cancel(t);for(const s of this._rangeRequestReaders.slice(0))s.cancel(t)}}class jS{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 Yh(`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 jr("streaming is disabled")),this._storedError&&this._readableStream.destroy(this._storedError)}}class NS{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 BS=1e5,es=30,HS=.8,he=class he{constructor({textContentSource:t,container:e,viewport:s}){_(this,mn);_(this,hr,Promise.withResolvers());_(this,is,null);_(this,Dl,!1);_(this,Rl,!!((Jv=globalThis.FontInspector)!=null&&Jv.enabled));_(this,co,null);_(this,pn,null);_(this,Ll,0);_(this,Fl,0);_(this,uo,null);_(this,Da,null);_(this,Ra,0);_(this,lr,0);_(this,La,Object.create(null));_(this,Il,[]);_(this,Fa,null);_(this,go,[]);_(this,jl,new WeakMap);_(this,Nl,null);var h;if(t instanceof ReadableStream)v(this,Fa,t);else if(typeof t=="object")v(this,Fa,new ReadableStream({start(c){c.enqueue(t),c.close()}}));else throw new Error('No "textContentSource" parameter specified.');v(this,is,v(this,Da,e)),v(this,lr,s.scale*(globalThis.devicePixelRatio||1)),v(this,Ra,s.rotation),v(this,pn,{div:null,properties:null,ctx:null});const{pageWidth:i,pageHeight:n,pageX:r,pageY:o}=s.rawDims;v(this,Nl,[1,0,0,-1,-r,o+n]),v(this,Fl,i),v(this,Ll,n),y(h=he,gs,zb).call(h),Nr(e,s),l(this,hr).promise.finally(()=>{l(he,Ia).delete(this),v(this,pn,null),v(this,La,null)}).catch(()=>{})}static get fontFamilyMap(){const{isWindows:t,isFirefox:e}=Ge.platform;return at(this,"fontFamilyMap",new Map([["sans-serif",`${t&&e?"Calibri, ":""}sans-serif`],["monospace",`${t&&e?"Lucida Console, ":""}monospace`]]))}render(){const t=()=>{l(this,uo).read().then(({value:e,done:s})=>{if(s){l(this,hr).resolve();return}l(this,co)??v(this,co,e.lang),Object.assign(l(this,La),e.styles),y(this,mn,Gb).call(this,e.items),t()},l(this,hr).reject)};return v(this,uo,l(this,Fa).getReader()),l(he,Ia).add(this),t(),l(this,hr).promise}update({viewport:t,onBefore:e=null}){var n;const s=t.scale*(globalThis.devicePixelRatio||1),i=t.rotation;if(i!==l(this,Ra)&&(e==null||e(),v(this,Ra,i),Nr(l(this,Da),{rotation:i})),s!==l(this,lr)){e==null||e(),v(this,lr,s);const r={div:null,properties:null,ctx:y(n=he,gs,jd).call(n,l(this,co))};for(const o of l(this,go))r.properties=l(this,jl).get(o),r.div=o,y(this,mn,wp).call(this,r)}}cancel(){var e;const t=new jr("TextLayer task cancelled.");(e=l(this,uo))==null||e.cancel(t).catch(()=>{}),v(this,uo,null),l(this,hr).reject(t)}get textDivs(){return l(this,go)}get textContentItemsStr(){return l(this,Il)}static cleanup(){if(!(l(this,Ia).size>0)){l(this,fo).clear();for(const{canvas:t}of l(this,po).values())t.remove();l(this,po).clear()}}};hr=new WeakMap,is=new WeakMap,Dl=new WeakMap,Rl=new WeakMap,co=new WeakMap,pn=new WeakMap,Ll=new WeakMap,Fl=new WeakMap,uo=new WeakMap,Da=new WeakMap,Ra=new WeakMap,lr=new WeakMap,La=new WeakMap,Il=new WeakMap,Fa=new WeakMap,go=new WeakMap,jl=new WeakMap,Nl=new WeakMap,fo=new WeakMap,po=new WeakMap,Bl=new WeakMap,cr=new WeakMap,Ia=new WeakMap,mn=new WeakSet,Gb=function(t){var i,n;if(l(this,Dl))return;(n=l(this,pn)).ctx??(n.ctx=y(i=he,gs,jd).call(i,l(this,co)));const e=l(this,go),s=l(this,Il);for(const r of t){if(e.length>BS){rt("Ignoring additional textDivs for performance reasons."),v(this,Dl,!0);return}if(r.str===void 0){if(r.type==="beginMarkedContentProps"||r.type==="beginMarkedContent"){const o=l(this,is);v(this,is,document.createElement("span")),l(this,is).classList.add("markedContent"),r.id!==null&&l(this,is).setAttribute("id",`${r.id}`),o.append(l(this,is))}else r.type==="endMarkedContent"&&v(this,is,l(this,is).parentNode);continue}s.push(r.str),y(this,mn,Wb).call(this,r)}},Wb=function(t){var m;const e=document.createElement("span"),s={angle:0,canvasWidth:0,hasText:t.str!=="",hasEOL:t.hasEOL,fontSize:0};l(this,go).push(e);const i=$.transform(l(this,Nl),t.transform);let n=Math.atan2(i[1],i[0]);const r=l(this,La)[t.fontName];r.vertical&&(n+=Math.PI/2);let o=l(this,Rl)&&r.fontSubstitution||r.fontFamily;o=he.fontFamilyMap.get(o)||o;const h=Math.hypot(i[2],i[3]),c=h*y(m=he,gs,Xb).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 g="calc(var(--scale-factor)*",f=e.style;l(this,is)===l(this,Da)?(f.left=`${(100*u/l(this,Fl)).toFixed(2)}%`,f.top=`${(100*d/l(this,Ll)).toFixed(2)}%`):(f.left=`${g}${u.toFixed(2)}px)`,f.top=`${g}${d.toFixed(2)}px)`),f.fontSize=`${g}${(l(he,cr)*h).toFixed(2)}px)`,f.fontFamily=o,s.fontSize=h,e.setAttribute("role","presentation"),e.textContent=t.str,e.dir=t.dir,l(this,Rl)&&(e.dataset.fontName=r.fontSubstitutionLoadedName||t.fontName),n!==0&&(s.angle=n*(180/Math.PI));let p=!1;if(t.str.length>1)p=!0;else if(t.str!==" "&&t.transform[0]!==t.transform[3]){const w=Math.abs(t.transform[0]),b=Math.abs(t.transform[3]);w!==b&&Math.max(w,b)/Math.min(w,b)>1.5&&(p=!0)}if(p&&(s.canvasWidth=r.vertical?t.height:t.width),l(this,jl).set(e,s),l(this,pn).div=e,l(this,pn).properties=s,y(this,mn,wp).call(this,l(this,pn)),s.hasText&&l(this,is).append(e),s.hasEOL){const w=document.createElement("br");w.setAttribute("role","presentation"),l(this,is).append(w)}},wp=function(t){var o;const{div:e,properties:s,ctx:i}=t,{style:n}=e;let r="";if(l(he,cr)>1&&(r=`scale(${1/l(he,cr)})`),s.canvasWidth!==0&&s.hasText){const{fontFamily:h}=n,{canvasWidth:c,fontSize:u}=s;y(o=he,gs,xp).call(o,i,u*l(this,lr),h);const{width:d}=i.measureText(e.textContent);d>0&&(r=`scaleX(${c*l(this,lr)/d}) ${r}`)}s.angle!==0&&(r=`rotate(${s.angle}deg) ${r}`),r.length>0&&(n.transform=r)},gs=new WeakSet,jd=function(t=null){let e=l(this,po).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,po).set(t,e),l(this,Bl).set(e,{size:0,family:""})}return e},xp=function(t,e,s){const i=l(this,Bl).get(t);e===i.size&&s===i.family||(t.font=`${e}px ${s}`,i.size=e,i.family=s)},zb=function(){if(l(this,cr)!==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,cr,t.getBoundingClientRect().height),t.remove()},Xb=function(t,e){const s=l(this,fo).get(t);if(s)return s;const i=y(this,gs,jd).call(this,e);i.canvas.width=i.canvas.height=es,y(this,gs,xp).call(this,i,es,t);const n=i.measureText("");let r=n.fontBoundingBoxAscent,o=Math.abs(n.fontBoundingBoxDescent);if(r){const u=r/(r+o);return l(this,fo).set(t,u),i.canvas.width=i.canvas.height=0,u}i.strokeStyle="red",i.clearRect(0,0,es,es),i.strokeText("g",0,0);let h=i.getImageData(0,0,es,es).data;o=0;for(let u=h.length-1-3;u>=0;u-=4)if(h[u]>0){o=Math.ceil(u/4/es);break}i.clearRect(0,0,es,es),i.strokeText("A",0,es),h=i.getImageData(0,0,es,es).data,r=0;for(let u=0,d=h.length;u<d;u+=4)if(h[u]>0){r=es-Math.floor(u/4/es);break}i.canvas.width=i.canvas.height=0;const c=r?r/(r+o):HS;return l(this,fo).set(t,c),c},_(he,gs),_(he,fo,new Map),_(he,po,new Map),_(he,Bl,new WeakMap),_(he,cr,null),_(he,Ia,new Set);let Zh=he;class tl{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(tl.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 VS=65536,GS=100,WS=5e3,zS=Ve?nS:eS,XS=Ve?rS:fv,US=Ve?iS:sS,YS=Ve?oS:vv;function $S(a={}){typeof a=="string"||a instanceof URL?a={url:a}:(a instanceof ArrayBuffer||ArrayBuffer.isView(a))&&(a={data:a});const t=new Ef,{docId:e}=t,s=a.url?qS(a.url):null,i=a.data?KS(a.data):null,n=a.httpHeaders||null,r=a.withCredentials===!0,o=a.password??null,h=a.range instanceof Nv?a.range:null,c=Number.isInteger(a.rangeChunkSize)&&a.rangeChunkSize>0?a.rangeChunkSize:VS;let u=a.worker instanceof ua?a.worker:null;const d=a.verbosity,g=typeof a.docBaseUrl=="string"&&!Yu(a.docBaseUrl)?a.docBaseUrl:null,f=typeof a.cMapUrl=="string"?a.cMapUrl:null,p=a.cMapPacked!==!1,m=a.CMapReaderFactory||XS,w=typeof a.standardFontDataUrl=="string"?a.standardFontDataUrl:null,b=a.StandardFontDataFactory||YS,x=a.stopAtErrors!==!0,C=Number.isInteger(a.maxImageSize)&&a.maxImageSize>-1?a.maxImageSize:-1,A=a.isEvalSupported!==!1,P=typeof a.isOffscreenCanvasSupported=="boolean"?a.isOffscreenCanvasSupported:!Ve,D=typeof a.isImageDecoderSupported=="boolean"?a.isImageDecoderSupported:!Ve&&(Ge.platform.isFirefox||!globalThis.chrome),k=Number.isInteger(a.canvasMaxAreaInBytes)?a.canvasMaxAreaInBytes:-1,M=typeof a.disableFontFace=="boolean"?a.disableFontFace:Ve,R=a.fontExtraProperties===!0,F=a.enableXfa===!0,I=a.ownerDocument||globalThis.document,X=a.disableRange===!0,j=a.disableStream===!0,N=a.disableAutoFetch===!0,nt=a.pdfBug===!0,K=a.CanvasFactory||zS,V=a.FilterFactory||US,H=a.enableHWA===!0,Et=h?h.length:a.length??NaN,jt=typeof a.useSystemFonts=="boolean"?a.useSystemFonts:!Ve&&!M,ie=typeof a.useWorkerFetch=="boolean"?a.useWorkerFetch:m===fv&&b===vv&&f&&w&&qh(f,document.baseURI)&&qh(w,document.baseURI);a.canvasFactory&&hv("`canvasFactory`-instance option, please use `CanvasFactory` instead."),a.filterFactory&&hv("`filterFactory`-instance option, please use `FilterFactory` instead.");const Wt=null;Rx(d);const Tt={canvasFactory:new K({ownerDocument:I,enableHWA:H}),filterFactory:new V({docId:e,ownerDocument:I}),cMapReaderFactory:ie?null:new m({baseUrl:f,isCompressed:p}),standardFontDataFactory:ie?null:new b({baseUrl:w})};if(!u){const Ot={verbosity:d,port:rn.workerPort};u=Ot.port?ua.fromPort(Ot):new ua(Ot),t._worker=u}const xe={docId:e,apiVersion:"4.9.155",data:i,password:o,disableAutoFetch:N,rangeChunkSize:c,length:Et,docBaseUrl:g,enableXfa:F,evaluatorOptions:{maxImageSize:C,disableFontFace:M,ignoreErrors:x,isEvalSupported:A,isOffscreenCanvasSupported:P,isImageDecoderSupported:D,canvasMaxAreaInBytes:k,fontExtraProperties:R,useSystemFonts:jt,cMapUrl:ie?f:null,standardFontDataUrl:ie?w:null}},Gs={disableFontFace:M,fontExtraProperties:R,ownerDocument:I,pdfBug:nt,styleElement:Wt,loadingParams:{disableAutoFetch:N,enableXfa:F}};return u.promise.then(function(){if(t.destroyed)throw new Error("Loading aborted");if(u.destroyed)throw new Error("Worker was destroyed");const Ot=u.messageHandler.sendWithPromise("GetDocRequest",xe,i?[i.buffer]:null);let dt;if(h)dt=new SS(h,{disableRange:X,disableStream:j});else if(!i){if(!s)throw new Error("getDocument - no `url` parameter provided.");let Ss;if(Ve)if(qh(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`.");Ss=Iv}else Ss=IS;else Ss=qh(s)?Iv:OS;dt=new Ss({url:s,length:Et,httpHeaders:n,withCredentials:r,rangeChunkSize:c,disableRange:X,disableStream:j})}return Ot.then(Ss=>{if(t.destroyed)throw new Error("Loading aborted");if(u.destroyed)throw new Error("Worker was destroyed");const zi=new Qh(e,Ss,u.port),$e=new tC(zi,t,dt,Gs,Tt);t._transport=$e,zi.send("Ready",null)})}).catch(t._capability.reject),t}function qS(a){if(a instanceof URL)return a.href;try{return new URL(a,window.location).href}catch{if(Ve&&typeof a=="string")return a}throw new Error("Invalid PDF url data: either string or URL-object is expected in the url property.")}function KS(a){if(Ve&&typeof Buffer<"u"&&a instanceof Buffer)throw new Error("Please provide binary data as `Uint8Array`, rather than `Buffer`.");if(a instanceof Uint8Array&&a.byteLength===a.buffer.byteLength)return a;if(typeof a=="string")return Xu(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 jv(a){return typeof a=="object"&&Number.isInteger(a==null?void 0:a.num)&&a.num>=0&&Number.isInteger(a==null?void 0:a.gen)&&a.gen>=0}const md=class md{constructor(){this._capability=Promise.withResolvers(),this._transport=null,this._worker=null,this.docId=`d${Ke(md,pd)._++}`,this.destroyed=!1,this.onPassword=null,this.onProgress=null}get promise(){return this._capability.promise}async destroy(){var t,e,s,i;this.destroyed=!0;try{(t=this._worker)!=null&&t.port&&(this._worker._pendingDestroy=!0),await((e=this._transport)==null?void 0:e.destroy())}catch(n){throw(s=this._worker)!=null&&s.port&&delete this._worker._pendingDestroy,n}this._transport=null,(i=this._worker)==null||i.destroy(),this._worker=null}};pd=new WeakMap,_(md,pd,0);let Ef=md;class Nv{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){St("Abstract method PDFDataRangeTransport.requestDataRange")}abort(){}}class JS{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 at(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 QS{constructor(t,e,s,i=!1){_(this,Fs);_(this,ur,null);_(this,vn,!1);this._pageIndex=t,this._pageInfo=e,this._transport=s,this._stats=i?new av:null,this._pdfBug=i,this.commonObjs=s.commonObjs,this.objs=new Bv,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 $h({viewBox:this.view,scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}getAnnotations({intent:t="display"}={}){const{renderingIntent:e}=this._transport.getRenderingIntent(t);return this._transport.getAnnotations(this._pageIndex,e)}getJSActions(){return this._transport.getPageJSActions(this._pageIndex)}get filterFactory(){return this._transport.filterFactory}get isPureXfa(){return at(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=Wn.ENABLE,transform:n=null,background:r=null,optionalContentConfigPromise:o=null,annotationCanvasMap:h=null,pageColors:c=null,printAnnotationStorage:u=null,isEditing:d=!1}){var A,P;(A=this._stats)==null||A.time("Overall");const g=this._transport.getRenderingIntent(s,i,u,d),{renderingIntent:f,cacheKey:p}=g;v(this,vn,!1),y(this,Fs,Nd).call(this),o||(o=this._transport.getOptionalContentConfig(f));let m=this._intentStates.get(p);m||(m=Object.create(null),this._intentStates.set(p,m)),m.streamReaderCancelTimeout&&(clearTimeout(m.streamReaderCancelTimeout),m.streamReaderCancelTimeout=null);const w=!!(f&cs.PRINT);m.displayReadyCapability||(m.displayReadyCapability=Promise.withResolvers(),m.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(P=this._stats)==null||P.time("Page Request"),this._pumpOperatorList(g));const b=D=>{var k;m.renderTasks.delete(x),(this._maybeCleanupAfterRender||w)&&v(this,vn,!0),y(this,Fs,Sh).call(this,!w),D?(x.capability.reject(D),this._abortOperatorList({intentState:m,reason:D instanceof Error?D:new Error(D)})):x.capability.resolve(),this._stats&&(this._stats.timeEnd("Rendering"),this._stats.timeEnd("Overall"),(k=globalThis.Stats)!=null&&k.enabled&&globalThis.Stats.add(this.pageNumber,this._stats))},x=new kf({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:!w,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(([D,k])=>{var M;if(this.destroyed){b();return}if((M=this._stats)==null||M.time("Rendering"),!(k.renderingIntent&f))throw new Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");x.initializeGraphics({transparency:D,optionalContentConfig:k}),x.operatorListChanged()}).catch(b),C}getOperatorList({intent:t="display",annotationMode:e=Wn.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=>tl.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,vn,!1),y(this,Fs,Nd).call(this),Promise.all(t)}cleanup(t=!1){v(this,vn,!0);const e=y(this,Fs,Sh).call(this,!1);return t&&e&&this._stats&&(this._stats=new av),e}_startRenderPage(t,e){var i,n;const s=this._intentStates.get(e);s&&((i=this._stats)==null||i.timeEnd("Page Request"),(n=s.displayReadyCapability)==null||n.resolve(t))}_renderPageChunk(t,e){for(let s=0,i=t.length;s<i;s++)e.operatorList.fnArray.push(t.fnArray[s]),e.operatorList.argsArray.push(t.argsArray[s]);e.operatorList.lastChunk=t.lastChunk,e.operatorList.separateAnnots=t.separateAnnots;for(const s of e.renderTasks)s.operatorListChanged();t.lastChunk&&y(this,Fs,Sh).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:g})=>{if(g){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 g of c.renderTasks)g.operatorListChanged();y(this,Fs,Sh).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 uf){let i=GS;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 jr(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}}ur=new WeakMap,vn=new WeakMap,Fs=new WeakSet,Sh=function(t=!1){if(y(this,Fs,Nd).call(this),!l(this,vn)||this.destroyed)return!1;if(t)return v(this,ur,setTimeout(()=>{v(this,ur,null),y(this,Fs,Sh).call(this,!1)},WS)),!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,vn,!1),!0},Nd=function(){l(this,ur)&&(clearTimeout(l(this,ur)),v(this,ur,null))};class ZS{constructor(){_(this,bn,new Map);_(this,vd,Promise.resolve())}postMessage(t,e){const s={data:structuredClone(t,e?{transfer:e}:null)};l(this,vd).then(()=>{for(const[i]of l(this,bn))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){rt("LoopbackPort - cannot use an `aborted` signal.");return}const r=()=>this.removeEventListener(t,e);i=()=>n.removeEventListener("abort",r),n.addEventListener("abort",r)}l(this,bn).set(e,i)}removeEventListener(t,e){const s=l(this,bn).get(e);s==null||s(),l(this,bn).delete(e)}terminate(){for(const[,t]of l(this,bn))t==null||t();l(this,bn).clear()}}bn=new WeakMap,vd=new WeakMap;const Ft=class Ft{constructor({name:t=null,port:e=null,verbosity:s=Lx()}={}){_(this,ja);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(Ft,vo))!=null&&i.has(e))throw new Error("Cannot use more than one PDFWorker per port.");(l(Ft,vo)||v(Ft,vo,new WeakMap)).set(e,this),this._initializeFromPort(e);return}this._initialize()}get promise(){return this._readyCapability.promise}get port(){return this._port}get messageHandler(){return this._messageHandler}_initializeFromPort(t){this._port=t,this._messageHandler=new Qh("main","worker",t),this._messageHandler.on("ready",function(){}),y(this,ja,Bd).call(this)}_initialize(){if(l(Ft,mo)||l(Ft,Na,Hd)){this._setupFakeWorker();return}let{workerSrc:t}=Ft;try{Ft._isSameOrigin(window.location.href,t)||(t=Ft._createCDNWrapper(new URL(t,window.location).href));const e=new Worker(t,{type:"module"}),s=new Qh("main","worker",e),i=()=>{n.abort(),s.destroy(),e.terminate(),this.destroyed?this._readyCapability.reject(new Error("Worker was destroyed")):this._setupFakeWorker()},n=new AbortController;e.addEventListener("error",()=>{this._webWorker||i()},{signal:n.signal}),s.on("test",o=>{if(n.abort(),this.destroyed||!o){i();return}this._messageHandler=s,this._port=e,this._webWorker=e,y(this,ja,Bd).call(this)}),s.on("ready",o=>{if(n.abort(),this.destroyed){i();return}try{r()}catch{this._setupFakeWorker()}});const r=()=>{const o=new Uint8Array;s.send("test",o,[o.buffer])};r();return}catch{Wu("The worker has been disabled.")}this._setupFakeWorker()}_setupFakeWorker(){l(Ft,mo)||(rt("Setting up fake worker."),v(Ft,mo,!0)),Ft._setupFakeWorkerGlobal.then(t=>{if(this.destroyed){this._readyCapability.reject(new Error("Worker was destroyed"));return}const e=new ZS;this._port=e;const s=`fake${Ke(Ft,bd)._++}`,i=new Qh(s+"_worker",s,e);t.setup(i,e),this._messageHandler=new Qh(s,s+"_worker",e),y(this,ja,Bd).call(this)}).catch(t=>{this._readyCapability.reject(new Error(`Setting up fake worker failed: "${t.message}".`))})}destroy(){var t,e,s;this.destroyed=!0,(t=this._webWorker)==null||t.terminate(),this._webWorker=null,(e=l(Ft,vo))==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,vo))==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 Ft(t)}static get workerSrc(){if(rn.workerSrc)return rn.workerSrc;throw new Error('No "GlobalWorkerOptions.workerSrc" specified.')}static get _setupFakeWorkerGlobal(){return at(this,"_setupFakeWorkerGlobal",(async()=>l(this,Na,Hd)?l(this,Na,Hd):(await import(this.workerSrc)).WorkerMessageHandler)())}};bd=new WeakMap,mo=new WeakMap,vo=new WeakMap,ja=new WeakSet,Bd=function(){this._readyCapability.resolve(),this._messageHandler.send("configure",{verbosity:this.verbosity})},Na=new WeakSet,Hd=function(){var t;try{return((t=globalThis.pdfjsWorker)==null?void 0:t.WorkerMessageHandler)||null}catch{return null}},_(Ft,Na),_(Ft,bd,0),_(Ft,mo,!1),_(Ft,vo),Ve&&(v(Ft,mo,!0),rn.workerSrc||(rn.workerSrc="./pdf.worker.mjs")),Ft._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},Ft._createCDNWrapper=t=>{const e=`await import("${t}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))};let ua=Ft;class tC{constructor(t,e,s,i,n){_(this,bo);_(this,yn,new Map);_(this,Li,new Map);_(this,Ba,new Map);_(this,Ha,new Map);_(this,Fi,null);this.messageHandler=t,this.loadingTask=e,this.commonObjs=new Bv,this.fontLoader=new Zx({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 at(this,"annotationStorage",new _f)}getRenderingIntent(t,e=Wn.ENABLE,s=null,i=!1,n=!1){let r=cs.DISPLAY,o=yf;switch(t){case"any":r=cs.ANY;break;case"display":break;case"print":r=cs.PRINT;break;default:rt(`getRenderingIntent - invalid intent: ${t}`)}const h=r&cs.PRINT&&s instanceof uv?s:this.annotationStorage;switch(e){case Wn.DISABLE:r+=cs.ANNOTATIONS_DISABLE;break;case Wn.ENABLE:break;case Wn.ENABLE_FORMS:r+=cs.ANNOTATIONS_FORMS;break;case Wn.ENABLE_STORAGE:r+=cs.ANNOTATIONS_STORAGE,o=h.serializable;break;default:rt(`getRenderingIntent - invalid annotationMode: ${e}`)}i&&(r+=cs.IS_EDITING),n&&(r+=cs.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,Fi))==null||s.reject(new Error("Worker was destroyed during onPassword callback"));const t=[];for(const i of l(this,Li).values())t.push(i._destroy());l(this,Li).clear(),l(this,Ba).clear(),l(this,Ha).clear(),this.hasOwnProperty("annotationStorage")&&this.annotationStorage.resetModified();const e=this.messageHandler.sendWithPromise("Terminate",null);return t.push(e),Promise.all(t).then(()=>{var i,n;this.commonObjs.clear(),this.fontLoader.clear(),l(this,yn).clear(),this.filterFactory.destroy(),Zh.cleanup(),(i=this._networkStream)==null||i.cancelAllRequests(new jr("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)=>{te(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}te(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)=>{te(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}te(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 JS(s,this))}),t.on("DocException",function(s){let i;switch(s.name){case"PasswordException":i=new rf(s.message,s.code);break;case"InvalidPDFException":i=new nv(s.message);break;case"MissingPDFException":i=new Yh(s.message);break;case"UnexpectedResponseException":i=new zu(s.message,s.status);break;case"UnknownErrorException":i=new of(s.message,s.details);break;default:St("DocException - expected a valid Error.")}e._capability.reject(i)}),t.on("PasswordRequest",s=>{if(v(this,Fi,Promise.withResolvers()),e.onPassword){const i=n=>{n instanceof Error?l(this,Fi).reject(n):l(this,Fi).resolve({password:n})};try{e.onPassword(i,s.code)}catch(n){l(this,Fi).reject(n)}}else l(this,Fi).reject(new rf(s.message,s.code));return l(this,Fi).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,Li).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 f=n.error;rt(`Error during font loading: ${f}`),this.commonObjs.resolve(s,f);break}const u=c&&((r=globalThis.FontInspector)!=null&&r.enabled)?(f,p)=>globalThis.FontInspector.fontAdded(f,p):null,d=new tS(n,{disableFontFace:o,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:g}=n;te(g,"The imageRef must be defined.");for(const f of l(this,Li).values())for(const[,p]of f.objs)if((p==null?void 0:p.ref)===g)return p.dataLen?(this.commonObjs.resolve(s,structuredClone(p)),p.dataLen):null;break;case"FontPath":case"Image":case"Pattern":this.commonObjs.resolve(s,n);break;default:throw new Error(`Got unknown common object type ${i}`)}return null}),t.on("obj",([s,i,n,r])=>{var h;if(this.destroyed)return;const o=l(this,Li).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)>Px&&(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&&rt("saveDocument called while `annotationStorage` is empty, please use the getData-method instead.");const{map:t,transfer:e}=this.annotationStorage.serializable;return this.messageHandler.sendWithPromise("SaveDocument",{isPureXfa:!!this._htmlForXfa,numPages:this._numPages,annotationStorage:t,filename:((s=this._fullReader)==null?void 0:s.filename)??null},e).finally(()=>{this.annotationStorage.resetModified()})}getPage(t){if(!Number.isInteger(t)||t<=0||t>this._numPages)return Promise.reject(new Error("Invalid page request."));const e=t-1,s=l(this,Ba).get(e);if(s)return s;const i=this.messageHandler.sendWithPromise("GetPage",{pageIndex:e}).then(n=>{if(this.destroyed)throw new Error("Transport destroyed");n.refStr&&l(this,Ha).set(n.refStr,t);const r=new QS(e,n,this,this._params.pdfBug);return l(this,Li).set(e,r),r});return l(this,Ba).set(e,i),i}getPageIndex(t){return jv(t)?this.messageHandler.sendWithPromise("GetPageIndex",{num:t.num,gen:t.gen}):Promise.reject(new Error("Invalid pageIndex request."))}getAnnotations(t,e){return this.messageHandler.sendWithPromise("GetAnnotations",{pageIndex:t,intent:e})}getFieldObjects(){return y(this,bo,Dc).call(this,"GetFieldObjects")}hasJSActions(){return y(this,bo,Dc).call(this,"HasJSActions")}getCalculationOrderIds(){return this.messageHandler.sendWithPromise("GetCalculationOrderIds",null)}getDestinations(){return this.messageHandler.sendWithPromise("GetDestinations",null)}getDestination(t){return typeof t!="string"?Promise.reject(new Error("Invalid destination request.")):this.messageHandler.sendWithPromise("GetDestination",{id:t})}getPageLabels(){return this.messageHandler.sendWithPromise("GetPageLabels",null)}getPageLayout(){return this.messageHandler.sendWithPromise("GetPageLayout",null)}getPageMode(){return this.messageHandler.sendWithPromise("GetPageMode",null)}getViewerPreferences(){return this.messageHandler.sendWithPromise("GetViewerPreferences",null)}getOpenAction(){return this.messageHandler.sendWithPromise("GetOpenAction",null)}getAttachments(){return this.messageHandler.sendWithPromise("GetAttachments",null)}getDocJSActions(){return y(this,bo,Dc).call(this,"GetDocJSActions")}getPageJSActions(t){return this.messageHandler.sendWithPromise("GetPageJSActions",{pageIndex:t})}getStructTree(t){return this.messageHandler.sendWithPromise("GetStructTree",{pageIndex:t})}getOutline(){return this.messageHandler.sendWithPromise("GetOutline",null)}getOptionalContentConfig(t){return y(this,bo,Dc).call(this,"GetOptionalContentConfig").then(e=>new xS(e,t))}getPermissions(){return this.messageHandler.sendWithPromise("GetPermissions",null)}getMetadata(){const t="GetMetadata",e=l(this,yn).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 _S(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,yn).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,Li).values())if(!e.cleanup())throw new Error(`startCleanup: Page ${e.pageNumber} is currently rendering.`);this.commonObjs.clear(),t||this.fontLoader.clear(),l(this,yn).clear(),this.filterFactory.destroy(!0),Zh.cleanup()}}cachedPageNumber(t){if(!jv(t))return null;const e=t.gen===0?`${t.num}R`:`${t.num}R${t.gen}`;return l(this,Ha).get(e)??null}}yn=new WeakMap,Li=new WeakMap,Ba=new WeakMap,Ha=new WeakMap,Fi=new WeakMap,bo=new WeakSet,Dc=function(t,e=null){const s=l(this,yn).get(t);if(s)return s;const i=this.messageHandler.sendWithPromise(t,e);return l(this,yn).set(t,i),i};const ed=Symbol("INITIAL_DATA");class Bv{constructor(){_(this,Hl);_(this,ai,Object.create(null))}get(t,e=null){if(e){const i=y(this,Hl,Sp).call(this,t);return i.promise.then(()=>e(i.data)),null}const s=l(this,ai)[t];if(!s||s.data===ed)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return s.data}has(t){const e=l(this,ai)[t];return!!e&&e.data!==ed}resolve(t,e=null){const s=y(this,Hl,Sp).call(this,t);s.data=e,s.resolve()}clear(){var t;for(const e in l(this,ai)){const{data:s}=l(this,ai)[e];(t=s==null?void 0:s.bitmap)==null||t.close()}v(this,ai,Object.create(null))}*[Symbol.iterator](){for(const t in l(this,ai)){const{data:e}=l(this,ai)[t];e!==ed&&(yield[t,e])}}}ai=new WeakMap,Hl=new WeakSet,Sp=function(t){var e;return(e=l(this,ai))[t]||(e[t]={...Promise.withResolvers(),data:ed})};class eC{constructor(t){_(this,dr,null);v(this,dr,t),this.onContinue=null}get promise(){return l(this,dr).capability.promise}cancel(t=0){l(this,dr).cancel(null,t)}get separateAnnots(){const{separateAnnots:t}=l(this,dr).operatorList;if(!t)return!1;const{annotationCanvasMap:e}=l(this,dr);return t.form||t.canvas&&(e==null?void 0:e.size)>0}}dr=new WeakMap;const _o=class _o{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:g=null}){_(this,gr,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=g,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 o,h;if(this.cancelled)return;if(this._canvas){if(l(_o,yo).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(_o,yo).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 la(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,gr)&&(window.cancelAnimationFrame(l(this,gr)),v(this,gr,null)),l(_o,yo).delete(this._canvas),this.callback(t||new uf(`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,gr,window.requestAnimationFrame(()=>{v(this,gr,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(_o,yo).delete(this._canvas),this.callback())))}};gr=new WeakMap,yo=new WeakMap,_(_o,yo,new WeakSet);let kf=_o;const sC="4.9.155",iC="a4eb8407c";function Hv(a){return Math.floor(Math.max(0,Math.min(1,a))*255).toString(16).padStart(2,"0")}function el(a){return Math.max(0,Math.min(255,255*a))}class Vv{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=el(t),[t,t,t]}static G_HTML([t]){const e=Hv(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(el)}static RGB_HTML(t){return`#${t.map(Hv).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[el(1-Math.min(1,t+i)),el(1-Math.min(1,s+i)),el(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){St("Abstract method `_createSVG` called.")}}class Pf extends nC{_createSVG(t){return document.createElementNS(nn,t)}}class Gv{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,g;const e=t.annotationStorage,s=t.linkService,i=t.xfaHtml,n=t.intent||"display",r=document.createElement(i.name);i.attributes&&this.setAttributes({html:r,element:i,intent:n,linkService:s});const o=n!=="richText",h=t.div;if(h.append(r),t.viewport){const f=`matrix(${t.viewport.transform.join(",")})`;h.style.transform=f}o&&h.setAttribute("class","xfaLayer xfaFont");const c=[];if(i.children.length===0){if(i.value){const f=document.createTextNode(i.value);r.append(f),o&&tl.shouldBuildText(i.name)&&c.push(f)}return{textDivs:c}}const u=[[i,-1,r]];for(;u.length>0;){const[f,p,m]=u.at(-1);if(p+1===f.children.length){u.pop();continue}const w=f.children[++u.at(-1)[1]];if(w===null)continue;const{name:b}=w;if(b==="#text"){const C=document.createTextNode(w.value);c.push(C),m.append(C);continue}const x=(d=w==null?void 0:w.attributes)!=null&&d.xmlns?document.createElementNS(w.attributes.xmlns,b):document.createElement(b);if(m.append(x),w.attributes&&this.setAttributes({html:x,element:w,storage:e,intent:n,linkService:s}),((g=w.children)==null?void 0:g.length)>0)u.push([w,-1,x]);else if(w.value){const C=document.createTextNode(w.value);o&&tl.shouldBuildText(b)&&c.push(C),x.append(C)}}for(const f of h.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea"))f.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 sl=1e3,rC=9,Hr=new WeakSet;function Un(a){return{width:a[2]-a[0],height:a[3]-a[1]}}class oC{static create(t){switch(t.data.annotationType){case oe.LINK:return new Wv(t);case oe.TEXT:return new aC(t);case oe.WIDGET:switch(t.data.fieldType){case"Tx":return new hC(t);case"Btn":return t.data.radioButton?new zv(t):t.data.checkBox?new cC(t):new uC(t);case"Ch":return new dC(t);case"Sig":return new lC(t)}return new Vr(t);case oe.POPUP:return new Mf(t);case oe.FREETEXT:return new Xv(t);case oe.LINE:return new fC(t);case oe.SQUARE:return new pC(t);case oe.CIRCLE:return new mC(t);case oe.POLYLINE:return new Uv(t);case oe.CARET:return new bC(t);case oe.INK:return new Of(t);case oe.POLYGON:return new vC(t);case oe.HIGHLIGHT:return new Yv(t);case oe.UNDERLINE:return new yC(t);case oe.SQUIGGLY:return new _C(t);case oe.STRIKEOUT:return new wC(t);case oe.STAMP:return new $v(t);case oe.FILEATTACHMENT:return new xC(t);default:return new $t(t)}}}const Wf=class Wf{constructor(t,{isRenderable:e=!1,ignoreBorder:s=!1,createQuadrilaterals:i=!1}={}){_(this,Vl);_(this,wo,null);_(this,Va,!1);_(this,Ga,null);this.isRenderable=e,this.data=t.data,this.layer=t.layer,this.linkService=t.linkService,this.downloadManager=t.downloadManager,this.imageResourcesPath=t.imageResourcesPath,this.renderForms=t.renderForms,this.svgFactory=t.svgFactory,this.annotationStorage=t.annotationStorage,this.enableScripting=t.enableScripting,this.hasJSActions=t.hasJSActions,this._fieldObjects=t.fieldObjects,this.parent=t.parent,e&&(this.container=this._createContainer(s)),i&&this._createQuadrilaterals()}static _hasPopupData({titleObj:t,contentsObj:e,richText:s}){return!!(t!=null&&t.str||e!=null&&e.str||s!=null&&s.str)}get _isEditable(){return this.data.isEditable}get hasPopupData(){return Wf._hasPopupData(this.data)}updateEdited(t){var s;if(!this.container)return;l(this,wo)||v(this,wo,{rect:this.data.rect.slice(0)});const{rect:e}=t;e&&y(this,Vl,Cp).call(this,e),(s=l(this,Ga))==null||s.popup.updateEdited(t)}resetEdited(){var t;l(this,wo)&&(y(this,Vl,Cp).call(this,l(this,wo).rect),(t=l(this,Ga))==null||t.popup.resetEdited(),v(this,wo,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 Vr||(n.tabIndex=sl);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 Mf){const{rotation:m}=e;return!e.hasOwnCanvas&&m!==0&&this.setRotation(m,n),n}const{width:o,height:h}=Un(e.rect);if(!t&&e.borderStyle.width>0){r.borderWidth=`${e.borderStyle.width}px`;const m=e.borderStyle.horizontalCornerRadius,w=e.borderStyle.verticalCornerRadius;if(m>0||w>0){const x=`calc(${m}px * var(--scale-factor)) / calc(${w}px * var(--scale-factor))`;r.borderRadius=x}else if(this instanceof zv){const x=`calc(${o}px * var(--scale-factor)) / calc(${h}px * var(--scale-factor))`;r.borderRadius=x}switch(e.borderStyle.style){case Uh.SOLID:r.borderStyle="solid";break;case Uh.DASHED:r.borderStyle="dashed";break;case Uh.BEVELED:rt("Unimplemented border style: beveled");break;case Uh.INSET:rt("Unimplemented border style: inset");break;case Uh.UNDERLINE:r.borderBottomStyle="solid";break}const b=e.borderColor||null;b?(v(this,Va,!0),r.borderColor=$.makeHexColor(b[0]|0,b[1]|0,b[2]|0)):r.borderWidth=0}const c=$.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:g,pageY:f}=i.rawDims;r.left=`${100*(c[0]-g)/u}%`,r.top=`${100*(c[1]-f)/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}=Un(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]=Vv[`${r}_HTML`](o),this.annotationStorage.setValue(this.data.id,{[s]:Vv[`${r}_rgb`](o)})};return at(this,"_commonActions",{display:e=>{const{display:s}=e.detail,i=s%2===1;this.container.style.visibility=i?"hidden":"visible",this.annotationStorage.setValue(this.data.id,{noView:i,noPrint:s===1||s===2})},print:e=>{this.annotationStorage.setValue(this.data.id,{noPrint:!e.detail.print})},hidden:e=>{const{hidden:s}=e.detail;this.container.style.visibility=s?"hidden":"visible",this.annotationStorage.setValue(this.data.id,{noPrint:s,noView:s})},focus:e=>{setTimeout(()=>e.target.focus({preventScroll:!1}),0)},userName:e=>{e.target.title=e.detail.userName},readonly:e=>{e.target.disabled=e.detail.readonly},required:e=>{this._setRequired(e.target,e.detail.required)},bgColor:e=>{t("bgColor","backgroundColor",e)},fillColor:e=>{t("fillColor","backgroundColor",e)},fgColor:e=>{t("fgColor","color",e)},textColor:e=>{t("textColor","color",e)},borderColor:e=>{t("borderColor","borderColor",e)},strokeColor:e=>{t("strokeColor","borderColor",e)},rotation:e=>{const s=e.detail.rotation;this.setRotation(s),this.annotationStorage.setValue(this.data.id,{rotation:s})}})}_dispatchEventFromSandbox(t,e){const s=this._commonActions;for(const i of Object.keys(e.detail)){const n=t[i]||s[i];n==null||n(e)}}_setDefaultPropertiesFromJS(t){if(!this.enableScripting)return;const e=this.annotationStorage.getRawValue(this.data.id);if(!e)return;const s=this._commonActions;for(const[i,n]of Object.entries(e)){const r=s[i];if(r){const o={detail:{[i]:n},target:t};r(o),delete e[i]}}}_createQuadrilaterals(){if(!this.container)return;const{quadPoints:t}=this.data;if(!t)return;const[e,s,i,n]=this.data.rect.map(m=>Math.fround(m));if(t.length===8){const[m,w,b,x]=t.subarray(2,6);if(i===m&&n===w&&e===b&&s===x)return}const{style:r}=this.container;let o;if(l(this,Va)){const{borderColor:m,borderWidth:w}=r;r.borderWidth=0,o=["url('data:image/svg+xml;utf8,",'<svg xmlns="http://www.w3.org/2000/svg"',' preserveAspectRatio="none" viewBox="0 0 1 1">',`<g fill="transparent" stroke="${m}" stroke-width="${w}">`],this.container.classList.add("hasBorder")}const h=i-e,c=n-s,{svgFactory:u}=this,d=u.createElement("svg");d.classList.add("quadrilateralsContainer"),d.setAttribute("width",0),d.setAttribute("height",0);const g=u.createElement("defs");d.append(g);const f=u.createElement("clipPath"),p=`clippath_${this.data.id}`;f.setAttribute("id",p),f.setAttribute("clipPathUnits","objectBoundingBox"),g.append(f);for(let m=2,w=t.length;m<w;m+=8){const b=t[m],x=t[m+1],C=t[m+2],A=t[m+3],P=u.createElement("rect"),D=(C-e)/h,k=(n-x)/c,M=(b-C)/h,R=(x-A)/c;P.setAttribute("x",D),P.setAttribute("y",k),P.setAttribute("width",M),P.setAttribute("height",R),f.append(P),o==null||o.push(`<rect vector-effect="non-scaling-stroke" x="${D}" y="${k}" width="${M}" height="${R}"/>`)}l(this,Va)&&(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,Ga,new Mf({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(){St("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&&!Hr.has(c)){rt(`_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&&Hr.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})})}};wo=new WeakMap,Va=new WeakMap,Ga=new WeakMap,Vl=new WeakSet,Cp=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}=Un(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 $t=Wf;class Wv extends $t{constructor(e,s=null){super(e,{isRenderable:!0,ignoreBorder:!!(s!=null&&s.ignoreBorder),createQuadrilaterals:!0});_(this,fs);this.isTooltipOnly=e.data.isTooltipOnly}render(){const{data:e,linkService:s}=this,i=document.createElement("a");i.setAttribute("data-element-id",e.id);let n=!1;return e.url?(s.addLinkAttributes(i,e.url,e.newWindow),n=!0):e.action?(this._bindNamedAction(i,e.action),n=!0):e.attachment?(y(this,fs,Ub).call(this,i,e.attachment,e.attachmentDest),n=!0):e.setOCGState?(y(this,fs,Yb).call(this,i,e.setOCGState),n=!0):e.dest?(this._bindLink(i,e.dest),n=!0):(e.actions&&(e.actions.Action||e.actions["Mouse Up"]||e.actions["Mouse Down"])&&this.enableScripting&&this.hasJSActions&&(this._bindJSAction(i,e),n=!0),e.resetForm?(this._bindResetFormAction(i,e.resetForm),n=!0):this.isTooltipOnly&&!n&&(this._bindLink(i,""),n=!0)),this.container.classList.add("linkAnnotation"),n&&this.container.append(i),this.container}_bindLink(e,s){e.href=this.linkService.getDestinationHash(s),e.onclick=()=>(s&&this.linkService.goToDestination(s),!1),(s||s==="")&&y(this,fs,zo).call(this)}_bindNamedAction(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeNamedAction(s),!1),y(this,fs,zo).call(this)}_bindJSAction(e,s){e.href=this.linkService.getAnchorUrl("");const i=new Map([["Action","onclick"],["Mouse Up","onmouseup"],["Mouse Down","onmousedown"]]);for(const n of Object.keys(s.actions)){const r=i.get(n);r&&(e[r]=()=>{var o;return(o=this.linkService.eventBus)==null||o.dispatch("dispatcheventinsandbox",{source:this,detail:{id:s.id,name:n}}),!1})}e.onclick||(e.onclick=()=>!1),y(this,fs,zo).call(this)}_bindResetFormAction(e,s){const i=e.onclick;if(i||(e.href=this.linkService.getAnchorUrl("")),y(this,fs,zo).call(this),!this._fieldObjects){rt('_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 g=new Set(r);for(const f of n){const p=this._fieldObjects[f]||[];for(const{id:m}of p)g.add(m)}for(const f of Object.values(this._fieldObjects))for(const p of f)g.has(p.id)===o&&h.push(p)}else for(const g of Object.values(this._fieldObjects))h.push(...g);const c=this.annotationStorage,u=[];for(const g of h){const{id:f}=g;switch(u.push(f),g.type){case"text":{const m=g.defaultValue||"";c.setValue(f,{value:m});break}case"checkbox":case"radiobutton":{const m=g.defaultValue===g.exportValues;c.setValue(f,{value:m});break}case"combobox":case"listbox":{const m=g.defaultValue||"";c.setValue(f,{value:m});break}default:continue}const p=document.querySelector(`[data-element-id="${f}"]`);if(p){if(!Hr.has(p)){rt(`_bindResetFormAction - element not allowed: ${f}`);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}}}fs=new WeakSet,zo=function(){this.container.setAttribute("data-internal-link","")},Ub=function(e,s,i=null){e.href=this.linkService.getAnchorUrl(""),s.description&&(e.title=s.description),e.onclick=()=>{var n;return(n=this.downloadManager)==null||n.openOrDownloadData(s.content,s.filename,i),!1},y(this,fs,zo).call(this)},Yb=function(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeSetOCGState(s),!1),y(this,fs,zo).call(this)};class aC extends $t{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 Vr extends $t{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 Ge.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":$.makeHexColor(e[0],e[1],e[2])}_setTextStyle(t){const e=["left","center","right"],{fontColor:s}=this.data.defaultAppearanceData,i=this.data.defaultAppearanceData.fontSize||rC,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/(nf*i))||1,d=c/u;r=Math.min(i,h(d/nf))}else{const c=Math.abs(this.data.rect[3]-this.data.rect[1]-o);r=Math.min(i,h(c/nf))}n.fontSize=`calc(${r}px * var(--scale-factor))`,n.color=$.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 hC extends Vr{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(`
|
|
529
|
-
`))||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),Hr.add(s),s.setAttribute("data-element-id",e),s.disabled=this.data.readOnly,s.name=this.data.fieldName,s.tabIndex=sl,this._setRequired(s,this.data.required),h&&(s.maxLength=h),s.addEventListener("input",g=>{t.setValue(e,{value:g.target.value}),this.setPropertyOnSiblings(s,"value",g.target.value,"value"),u.formattedValue=null}),s.addEventListener("resetform",g=>{const f=this.data.defaultFieldValue??"";s.value=u.userValue=f,u.formattedValue=null});let d=g=>{const{formattedValue:f}=u;f!=null&&(g.target.value=f),g.target.scrollLeft=0};if(this.enableScripting&&this.hasJSActions){s.addEventListener("focus",f=>{var m;if(u.focused)return;const{target:p}=f;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",f=>{this.showElementAndHideCanvas(f.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:w}=m.detail;u.formattedValue=w,w!=null&&m.target!==document.activeElement&&(m.target.value=w),t.setValue(e,{formattedValue:w})},selRange(m){m.target.setSelectionRange(...m.detail.selRange)},charLimit:m=>{var C;const{charLimit:w}=m.detail,{target:b}=m;if(w===0){b.removeAttribute("maxLength");return}b.setAttribute("maxLength",w);let x=u.userValue;!x||x.length<=w||(x=x.slice(0,w),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,f)}),s.addEventListener("keydown",f=>{var w;u.commitKey=1;let p=-1;if(f.key==="Escape"?p=0:f.key==="Enter"&&!this.data.multiLine?p=2:f.key==="Tab"&&(u.commitKey=3),p===-1)return;const{value:m}=f.target;u.lastCommittedValue!==m&&(u.lastCommittedValue=m,u.userValue=m,(w=this.linkService.eventBus)==null||w.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:m,willCommit:!0,commitKey:p,selStart:f.target.selectionStart,selEnd:f.target.selectionEnd}}))});const g=d;d=null,s.addEventListener("blur",f=>{var m,w;if(!u.focused||!f.relatedTarget)return;(m=this.data.actions)!=null&&m.Blur||(u.focused=!1);const{value:p}=f.target;u.userValue=p,u.lastCommittedValue!==p&&((w=this.linkService.eventBus)==null||w.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:p,willCommit:!0,commitKey:u.commitKey,selStart:f.target.selectionStart,selEnd:f.target.selectionEnd}})),g(f)}),(n=this.data.actions)!=null&&n.Keystroke&&s.addEventListener("beforeinput",f=>{var P;u.lastCommittedValue=null;const{data:p,target:m}=f,{value:w,selectionStart:b,selectionEnd:x}=m;let C=b,A=x;switch(f.inputType){case"deleteWordBackward":{const D=w.substring(0,b).match(/\w*[^\w]*$/);D&&(C-=D[0].length);break}case"deleteWordForward":{const D=w.substring(b).match(/^[^\w]*\w*/);D&&(A+=D[0].length);break}case"deleteContentBackward":b===x&&(C-=1);break;case"deleteContentForward":b===x&&(A+=1);break}f.preventDefault(),(P=this.linkService.eventBus)==null||P.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:w,change:p||"",willCommit:!1,selStart:C,selEnd:A}})}),this._setEventListeners(s,u,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],f=>f.target.value)}if(d&&s.addEventListener("blur",d),this.data.comb){const f=(this.data.rect[2]-this.data.rect[0])/h;s.classList.add("comb"),s.style.letterSpacing=`calc(${f}px * var(--scale-factor) - 1ch)`}}else s=document.createElement("div"),s.textContent=this.data.fieldValue,s.style.verticalAlign="middle",s.style.display="table-cell",this.data.hasOwnCanvas&&(s.hidden=!0);return this._setTextStyle(s),this._setBackgroundColor(s),this._setDefaultPropertiesFromJS(s),this.container.append(s),this.container}}class lC extends Vr{constructor(t){super(t,{isRenderable:!!t.data.hasOwnCanvas})}}class cC extends Vr{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 Hr.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=sl,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 zv extends Vr{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(Hr.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=sl,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 g=u&&d.id===s;d.domElement&&(d.domElement.checked=g),t.setValue(d.id,{value:g})}}};this._dispatchEventFromSandbox(h,o)}),this._setEventListeners(n,null,[["change","Validate"],["change","Action"],["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],o=>o.target.checked)}return this._setBackgroundColor(n),this._setDefaultPropertiesFromJS(n),this.container.append(n),this.container}}class uC extends Wv{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 dC extends Vr{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");Hr.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=sl;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 g of i.options)g.selected=g.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:g,multiple:f}=i;return f?Array.prototype.filter.call(g,p=>p.selected).map(p=>p[d]):g.selectedIndex===-1?null:g[g.selectedIndex][d]};let h=o(!1);const c=u=>{const d=u.target.options;return Array.prototype.map.call(d,g=>({displayValue:g.textContent,exportValue:g.value}))};return this.enableScripting&&this.hasJSActions?(i.addEventListener("updatefromsandbox",u=>{const d={value(g){r==null||r();const f=g.detail.value,p=new Set(Array.isArray(f)?f:[f]);for(const m of i.options)m.selected=p.has(m.value);t.setValue(e,{value:o(!0)}),h=o(!1)},multipleSelection(g){i.multiple=!0},remove(g){const f=i.options,p=g.detail.remove;f[p].selected=!1,i.remove(p),f.length>0&&Array.prototype.findIndex.call(f,w=>w.selected)===-1&&(f[0].selected=!0),t.setValue(e,{value:o(!0),items:c(g)}),h=o(!1)},clear(g){for(;i.length!==0;)i.remove(0);t.setValue(e,{value:null,items:[]}),h=o(!1)},insert(g){const{index:f,displayValue:p,exportValue:m}=g.detail.insert,w=i.children[f],b=document.createElement("option");b.textContent=p,b.value=m,w?w.before(b):i.append(b),t.setValue(e,{value:o(!0),items:c(g)}),h=o(!1)},items(g){const{items:f}=g.detail;for(;i.length!==0;)i.remove(0);for(const p of f){const{displayValue:m,exportValue:w}=p,b=document.createElement("option");b.textContent=m,b.value=w,i.append(b)}i.options.length>0&&(i.options[0].selected=!0),t.setValue(e,{value:o(!0),items:c(g)}),h=o(!1)},indices(g){const f=new Set(g.detail.indices);for(const p of g.target.options)p.selected=f.has(p.index);t.setValue(e,{value:o(!0)}),h=o(!1)},editable(g){g.target.disabled=!g.detail.editable}};this._dispatchEventFromSandbox(d,u)}),i.addEventListener("input",u=>{var f;const d=o(!0),g=o(!1);t.setValue(e,{value:d}),u.preventDefault(),(f=this.linkService.eventBus)==null||f.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:h,change:g,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 Mf extends $t{constructor(t){const{data:e,elements:s}=t;super(t,{isRenderable:$t._hasPopupData(e)}),this.elements=s,this.popup=null}render(){this.container.classList.add("popupAnnotation");const t=this.popup=new gC({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=>`${cf}${s}`).join(",")),this.container}}class gC{constructor({container:t,color:e,elements:s,titleObj:i,modificationDate:n,contentsObj:r,richText:o,parent:h,rect:c,parentRect:u,open:d}){_(this,Ct);_(this,Wa,y(this,Ct,Kb).bind(this));_(this,yd,y(this,Ct,Tp).bind(this));_(this,_d,y(this,Ct,Wd).bind(this));_(this,za,y(this,Ct,Gd).bind(this));_(this,xo,null);_(this,Xt,null);_(this,_n,null);_(this,Xa,null);_(this,Gl,null);_(this,Wl,null);_(this,Ua,null);_(this,wn,!1);_(this,hi,null);_(this,xn,null);_(this,zl,null);_(this,Sn,null);_(this,Xl,null);_(this,So,null);_(this,Co,!1);var g;v(this,Xt,t),v(this,Xl,i),v(this,_n,r),v(this,Sn,o),v(this,Wl,h),v(this,xo,e),v(this,zl,c),v(this,Ua,u),v(this,Gl,s),v(this,Xa,gf.toDateObject(n)),this.trigger=s.flatMap(f=>f.getElementsToTriggerPopup());for(const f of this.trigger)f.addEventListener("click",l(this,za)),f.addEventListener("mouseenter",l(this,_d)),f.addEventListener("mouseleave",l(this,yd)),f.classList.add("popupTriggerArea");for(const f of s)(g=f.container)==null||g.addEventListener("keydown",l(this,Wa));l(this,Xt).hidden=!0,d&&y(this,Ct,Gd).call(this)}render(){if(l(this,hi))return;const t=v(this,hi,document.createElement("div"));if(t.className="popup",l(this,xo)){const n=t.style.outlineColor=$.makeHexColor(...l(this,xo));CSS.supports("background-color","color-mix(in srgb, red 30%, white)")?t.style.backgroundColor=`color-mix(in srgb, ${n} 30%, white)`:t.style.backgroundColor=$.makeHexColor(...l(this,xo).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,Xl),t.append(e),l(this,Xa)){const n=document.createElement("span");n.classList.add("popupDate"),n.setAttribute("data-l10n-id","pdfjs-annotation-date-time-string"),n.setAttribute("data-l10n-args",JSON.stringify({dateObj:l(this,Xa).valueOf()})),e.append(n)}const i=l(this,Ct,Vd);if(i)Gv.render({xfaHtml:i,intent:"richText",div:t}),t.lastChild.classList.add("richText","popupContent");else{const n=this._formatContents(l(this,_n));t.append(n)}l(this,Xt).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,So)||v(this,So,{contentsObj:l(this,_n),richText:l(this,Sn)}),t&&v(this,xn,null),e&&(v(this,Sn,y(this,Ct,qb).call(this,e)),v(this,_n,null)),(s=l(this,hi))==null||s.remove(),v(this,hi,null)}resetEdited(){var t;l(this,So)&&({contentsObj:Ke(this,_n)._,richText:Ke(this,Sn)._}=l(this,So),v(this,So,null),(t=l(this,hi))==null||t.remove(),v(this,hi,null),v(this,xn,null))}forceHide(){v(this,Co,this.isVisible),l(this,Co)&&(l(this,Xt).hidden=!0)}maybeShow(){l(this,Co)&&(l(this,hi)||y(this,Ct,Wd).call(this),v(this,Co,!1),l(this,Xt).hidden=!1)}get isVisible(){return l(this,Xt).hidden===!1}}Wa=new WeakMap,yd=new WeakMap,_d=new WeakMap,za=new WeakMap,xo=new WeakMap,Xt=new WeakMap,_n=new WeakMap,Xa=new WeakMap,Gl=new WeakMap,Wl=new WeakMap,Ua=new WeakMap,wn=new WeakMap,hi=new WeakMap,xn=new WeakMap,zl=new WeakMap,Sn=new WeakMap,Xl=new WeakMap,So=new WeakMap,Co=new WeakMap,Ct=new WeakSet,Vd=function(){const t=l(this,Sn),e=l(this,_n);return t!=null&&t.str&&(!(e!=null&&e.str)||e.str===t.str)&&l(this,Sn).html||null},Ap=function(){var t,e,s;return((s=(e=(t=l(this,Ct,Vd))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.fontSize)||0},$b=function(){var t,e,s;return((s=(e=(t=l(this,Ct,Vd))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.color)||null},qb=function(t){const e=[],s={str:t,html:{name:"div",attributes:{dir:"auto"},children:[{name:"p",children:e}]}},i={style:{color:l(this,Ct,$b),fontSize:l(this,Ct,Ap)?`calc(${l(this,Ct,Ap)}px * var(--scale-factor))`:""}};for(const n of t.split(`
|
|
530
|
-
`))e.push({name:"span",value:n,attributes:i});return s},Kb=function(t){t.altKey||t.shiftKey||t.ctrlKey||t.metaKey||(t.key==="Enter"||t.key==="Escape"&&l(this,wn))&&y(this,Ct,Gd).call(this)},Jb=function(){if(l(this,xn)!==null)return;const{page:{view:t},viewport:{rawDims:{pageWidth:e,pageHeight:s,pageX:i,pageY:n}}}=l(this,Wl);let r=!!l(this,Ua),o=r?l(this,Ua):l(this,zl);for(const p of l(this,Gl))if(!o||$.intersect(p.data.rect,o)!==null){o=p.data.rect,r=!0;break}const h=$.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,g=h[1];v(this,xn,[100*(d-i)/e,100*(g-n)/s]);const{style:f}=l(this,Xt);f.left=`${l(this,xn)[0]}%`,f.top=`${l(this,xn)[1]}%`},Gd=function(){v(this,wn,!l(this,wn)),l(this,wn)?(y(this,Ct,Wd).call(this),l(this,Xt).addEventListener("click",l(this,za)),l(this,Xt).addEventListener("keydown",l(this,Wa))):(y(this,Ct,Tp).call(this),l(this,Xt).removeEventListener("click",l(this,za)),l(this,Xt).removeEventListener("keydown",l(this,Wa)))},Wd=function(){l(this,hi)||this.render(),this.isVisible?l(this,wn)&&l(this,Xt).classList.add("focused"):(y(this,Ct,Jb).call(this),l(this,Xt).hidden=!1,l(this,Xt).style.zIndex=parseInt(l(this,Xt).style.zIndex)+1e3)},Tp=function(){l(this,Xt).classList.remove("focused"),!(l(this,wn)||!this.isVisible)&&(l(this,Xt).hidden=!0,l(this,Xt).style.zIndex=parseInt(l(this,Xt).style.zIndex)-1e3)};class Xv extends $t{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.textContent=t.data.textContent,this.textPosition=t.data.textPosition,this.annotationEditorType=it.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 fC extends $t{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,Ul,null)}render(){this.container.classList.add("lineAnnotation");const e=this.data,{width:s,height:i}=Un(e.rect),n=this.svgFactory.create(s,i,!0),r=v(this,Ul,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,Ul)}addHighlightArea(){this.container.classList.add("highlightArea")}}Ul=new WeakMap;class pC extends $t{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,Yl,null)}render(){this.container.classList.add("squareAnnotation");const e=this.data,{width:s,height:i}=Un(e.rect),n=this.svgFactory.create(s,i,!0),r=e.borderStyle.width,o=v(this,Yl,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,Yl)}addHighlightArea(){this.container.classList.add("highlightArea")}}Yl=new WeakMap;class mC extends $t{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,$l,null)}render(){this.container.classList.add("circleAnnotation");const e=this.data,{width:s,height:i}=Un(e.rect),n=this.svgFactory.create(s,i,!0),r=e.borderStyle.width,o=v(this,$l,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,$l)}addHighlightArea(){this.container.classList.add("highlightArea")}}$l=new WeakMap;class Uv extends $t{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,ql,null);this.containerClassName="polylineAnnotation",this.svgElementName="svg:polyline"}render(){this.container.classList.add(this.containerClassName);const{data:{rect:e,vertices:s,borderStyle:i,popupRef:n}}=this;if(!s)return this.container;const{width:r,height:o}=Un(e),h=this.svgFactory.create(r,o,!0);let c=[];for(let d=0,g=s.length;d<g;d+=2){const f=s[d]-e[0],p=e[3]-s[d+1];c.push(`${f},${p}`)}c=c.join(" ");const u=v(this,ql,this.svgFactory.createElement(this.svgElementName));return u.setAttribute("points",c),u.setAttribute("stroke-width",i.width||1),u.setAttribute("stroke","transparent"),u.setAttribute("fill","transparent"),h.append(u),this.container.append(h),!n&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,ql)}addHighlightArea(){this.container.classList.add("highlightArea")}}ql=new WeakMap;class vC extends Uv{constructor(t){super(t),this.containerClassName="polygonAnnotation",this.svgElementName="svg:polygon"}}class bC extends $t{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 Of extends $t{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,Jl);_(this,Kl,null);_(this,Ao,[]);this.containerClassName="inkAnnotation",this.svgElementName="svg:polyline",this.annotationEditorType=this.data.it==="InkHighlight"?it.HIGHLIGHT:it.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}=y(this,Jl,Ep).call(this,s,e),u=this.svgFactory.create(h,c,!0),d=v(this,Kl,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 g=0,f=i.length;g<f;g++){const p=this.svgFactory.createElement(this.svgElementName);l(this,Ao).push(p),p.setAttribute("points",i[g].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,Kl);if(s>=0&&r.setAttribute("stroke-width",s||1),i)for(let o=0,h=l(this,Ao).length;o<h;o++)l(this,Ao)[o].setAttribute("points",i[o].join(","));if(n){const{transform:o,width:h,height:c}=y(this,Jl,Ep).call(this,this.data.rotation,n);r.parentElement.setAttribute("viewBox",`0 0 ${h} ${c}`),r.setAttribute("transform",o)}}getElementsToTriggerPopup(){return l(this,Ao)}addHighlightArea(){this.container.classList.add("highlightArea")}}Kl=new WeakMap,Ao=new WeakMap,Jl=new WeakSet,Ep=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 Yv extends $t{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0}),this.annotationEditorType=it.HIGHLIGHT}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("highlightAnnotation"),this._editOnDoubleClick(),this.container}}class yC extends $t{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 _C extends $t{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 wC extends $t{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 $v extends $t{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.annotationEditorType=it.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 xC extends $t{constructor(e){var i;super(e,{isRenderable:!0});_(this,Zl);_(this,Ql,null);const{file:s}=this.data;this.filename=s.filename,this.content=s.content,(i=this.linkService.eventBus)==null||i.dispatch("fileattachmentannotation",{source:this,...s})}render(){this.container.classList.add("fileAttachmentAnnotation");const{container:e,data:s}=this;let i;s.hasAppearance||s.fillAlpha===0?i=document.createElement("div"):(i=document.createElement("img"),i.src=`${this.imageResourcesPath}annotation-${/paperclip/i.test(s.name)?"paperclip":"pushpin"}.svg`,s.fillAlpha&&s.fillAlpha<1&&(i.style=`filter: opacity(${Math.round(s.fillAlpha*100)}%);`)),i.addEventListener("dblclick",y(this,Zl,kp).bind(this)),v(this,Ql,i);const{isMac:n}=Ge.platform;return e.addEventListener("keydown",r=>{r.key==="Enter"&&(n?r.metaKey:r.ctrlKey)&&y(this,Zl,kp).call(this)}),!s.popupRef&&this.hasPopupData?this._createPopup():i.classList.add("popupTriggerArea"),e.append(i),e}getElementsToTriggerPopup(){return l(this,Ql)}addHighlightArea(){this.container.classList.add("highlightArea")}}Ql=new WeakMap,Zl=new WeakSet,kp=function(){var e;(e=this.downloadManager)==null||e.openOrDownloadData(this.content,this.filename)};class SC{constructor({div:t,accessibilityManager:e,annotationCanvasMap:s,annotationEditorUIManager:i,page:n,viewport:r,structTreeLayer:o}){_(this,ko);_(this,tc,null);_(this,To,null);_(this,Eo,new Map);_(this,ec,null);this.div=t,v(this,tc,e),v(this,To,s),v(this,ec,o||null),this.page=n,this.viewport=r,this.zIndex=0,this._annotationEditorUIManager=i}hasEditableAnnotations(){return l(this,Eo).size>0}async render(t){var r;const{annotations:e}=t,s=this.div;Nr(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 Pf,annotationStorage:t.annotationStorage||new _f,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===oe.POPUP;if(h){const d=i.get(o.id);if(!d)continue;n.elements=d}else{const{width:d,height:g}=Un(o.rect);if(d<=0||g<=0)continue}n.data=o;const c=oC.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 y(this,ko,Qb).call(this,u,o.id),c._isEditable&&(l(this,Eo).set(c.data.id,c),(r=this._annotationEditorUIManager)==null||r.renderAnnotationElement(c))}y(this,ko,Pp).call(this)}update({viewport:t}){const e=this.div;this.viewport=t,Nr(e,{rotation:t.rotation}),y(this,ko,Pp).call(this),e.hidden=!1}getEditableAnnotations(){return Array.from(l(this,Eo).values())}getEditableAnnotation(t){return l(this,Eo).get(t)}}tc=new WeakMap,To=new WeakMap,Eo=new WeakMap,ec=new WeakMap,ko=new WeakSet,Qb=async function(t,e){var r,o;const s=t.firstChild||t,i=s.id=`${cf}${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)},Pp=function(){if(!l(this,To))return;const t=this.div;for(const[e,s]of l(this,To)){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,To).clear()};const sd=/\r\n?|\n/g,Mt=class Mt extends Bt{constructor(e){super({...e,name:"freeTextEditor"});_(this,se);_(this,li);_(this,ps,"");_(this,sc,`${this.id}-editor`);_(this,Po,null);_(this,ms);v(this,li,e.color||Mt._defaultColor||Bt._defaultLineColor),v(this,ms,e.fontSize||Mt._defaultFontSize)}static get _keyboardManager(){const e=Mt.prototype,s=r=>r.isEmpty(),i=Br.TRANSLATE_SMALL,n=Br.TRANSLATE_BIG;return at(this,"_keyboardManager",new Kh([[["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){Bt.initialize(e,s);const i=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(i.getPropertyValue("--freetext-padding"))}static updateDefaultParams(e,s){switch(e){case ut.FREETEXT_SIZE:Mt._defaultFontSize=s;break;case ut.FREETEXT_COLOR:Mt._defaultColor=s;break}}updateParams(e,s){switch(e){case ut.FREETEXT_SIZE:y(this,se,Zb).call(this,s);break;case ut.FREETEXT_COLOR:y(this,se,ty).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[ut.FREETEXT_SIZE,Mt._defaultFontSize],[ut.FREETEXT_COLOR,Mt._defaultColor||Bt._defaultLineColor]]}get propertiesToUpdate(){return[[ut.FREETEXT_SIZE,l(this,ms)],[ut.FREETEXT_COLOR,l(this,li)]]}_translateEmpty(e,s){this._uiManager.translateSelectedEditors(e,s,!0)}getInitialTranslation(){const e=this.parentScale;return[-Mt._internalPadding*e,-(Mt._internalPadding+l(this,ms))*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(it.FREETEXT),super.enableEditMode(),this.overlayDiv.classList.remove("enabled"),this.editorDiv.contentEditable=!0,this._isDraggable=!1,this.div.removeAttribute("aria-activedescendant"),v(this,Po,new AbortController);const e=this._uiManager.combinedSignal(l(this,Po));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,sc)),this._isDraggable=!0,(e=l(this,Po))==null||e.abort(),v(this,Po,null),this.div.focus({preventScroll:!0}),this.isEditing=!1,this.parent.div.classList.add("freetextEditing"))}focusin(e){this._focusEventsAllowed&&(super.focusin(e),e.target!==this.editorDiv&&this.editorDiv.focus())}onceAdded(){var e;this.width||(this.enableEditMode(),this.editorDiv.focus(),(e=this._initialOptions)!=null&&e.isCentered&&this.center(),this._initialOptions=null)}isEmpty(){return!this.editorDiv||this.editorDiv.innerText.trim()===""}remove(){this.isEditing=!1,this.parent&&(this.parent.setEditingState(!0),this.parent.div.classList.add("freetextEditing")),super.remove()}commit(){if(!this.isInEditMode())return;super.commit(),this.disableEditMode();const e=l(this,ps),s=v(this,ps,y(this,se,ey).call(this).trimEnd());if(e===s)return;const i=n=>{if(v(this,ps,n),!n){this.remove();return}y(this,se,Ud).call(this),this._uiManager.rebuild(this),y(this,se,zd).call(this)};this.addCommands({cmd:()=>{i(s)},undo:()=>{i(e)},mustExec:!1}),y(this,se,zd).call(this)}shouldGetKeyboardEvents(){return this.isInEditMode()}enterInEditMode(){this.enableEditMode(),this.editorDiv.focus()}dblclick(e){this.enterInEditMode()}keydown(e){e.target===this.div&&e.key==="Enter"&&(this.enterInEditMode(),e.preventDefault())}editorDivKeydown(e){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,sc)),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,ms)}px * var(--scale-factor))`,i.color=l(this,li),this.div.append(this.editorDiv),this.overlayDiv=document.createElement("div"),this.overlayDiv.classList.add("overlay","enabled"),this.div.append(this.overlayDiv),$u(this,this.div,["dblclick","keydown"]),this.width){const[n,r]=this.parentDimensions;if(this.annotationElementId){const{position:o}=this._initialData;let[h,c]=this.getInitialTranslation();[h,c]=this.pageTranslationToScreen(h,c);const[u,d]=this.pageDimensions,[g,f]=this.pageTranslation;let p,m;switch(this.rotation){case 0:p=e+(o[0]-g)/u,m=s+this.height-(o[1]-f)/d;break;case 90:p=e+(o[0]-g)/u,m=s-(o[1]-f)/d,[h,c]=[c,-h];break;case 180:p=e-this.width+(o[0]-g)/u,m=s-(o[1]-f)/d,[h,c]=[-h,-c];break;case 270:p=e+(o[0]-g-this.height*d)/u,m=s+(o[1]-f-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);y(this,se,Ud).call(this),this._isDraggable=!0,this.editorDiv.contentEditable=!1}else this._isDraggable=!1,this.editorDiv.contentEditable=!0;return this.div}editorDivPaste(e){var p,m,w;const s=e.clipboardData||window.clipboardData,{types:i}=s;if(i.length===1&&i[0]==="text/plain")return;e.preventDefault();const n=y(p=Mt,Cn,Mp).call(p,s.getData("text")||"").replaceAll(sd,`
|
|
531
|
-
`);if(!n)return;const r=window.getSelection();if(!r.rangeCount)return;this.editorDiv.normalize(),r.deleteFromDocument();const
|
|
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(rd,"type","Vibrance"),E(rd,"defaults",{vibrance:0}),E(rd,"uniformLocations",["uVibrance"]),V.setClass(rd);const Ix="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2040%2040'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3ccircle%20cx='20'%20cy='20'%20r='10.75'%20stroke='currentColor'%20stroke-width='2.5'/%3e%3cpath%20d='M16%2024L23.7782%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3cpath%20d='M24%2024L16.2218%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3c/svg%3e";function jx(o){return new URL(Object.assign({"../assets/close.svg":Ix})[`../assets/${o}`],typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Mt&&Mt.tagName.toUpperCase()==="SCRIPT"&&Mt.src||new URL("pdf-canvas.umd.js",document.baseURI).href).href}function Nx(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 Bx(i))}),i.addEventListener("error",n=>{window.URL.revokeObjectURL(s),e(n)})})}function Bx(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))})}let xy=null;function Hx(){const o=document.createElement("div");o.style.width="1in",document.body.append(o);const t=o.offsetWidth;return o.remove(),t}function Vx(){const o=xy??Hx();return xy=o,o/72}function Wx(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)}}const Rs=new Map;function zx(o){const t=new dg(o);return Rs.set(o,t),t}function Gx(o,t){const e=Date.now();return{PDFId:`${o.name}-${e}`,name:o.name.replace(/.pdf/,""),updateDate:e,PDFBase64:t}}function Xx(o,t){const e=o.getViewport({scale:t}),s=document.createElement("canvas"),i=s.getContext("2d"),n=Vx()/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 Ux(o,t,e){const s=o||jx("close.svg"),{objects:i,options:n}=await Ax(s),r=i.filter(h=>h!==null),a=Bw.groupSVGElements(r,n);return r.forEach(h=>{h.stroke=t}),a.hoverCursor="pointer",a.stroke=`${t}-${e}`,a}function Yx(o,t){if(!Rs.get(o))return;const s=1/3,i=Zx(t,s);Cy(o,i,s)}async function $x(o,t){const e=await Nx(t),s=Date.now(),n={PDFId:`${t.name}${s}`,name:t.name.replace(/.png|.jpg|.jpeg/,""),updateDate:s,PDFBase64:e};return Sy(o,{url:e}),{...n,pages:1}}async function Sy(o,{url:t,scale:e=.5}){if(!Rs.get(o))return;const i=await ke.fromURL(t);i.scale(e),Cy(o,i,e)}function Cy(o,t,e){const s=Rs.get(o);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function nl(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 qx(o,t,e){!e||!o||(e.scale(1/t),nl(o,e))}function Kx(o,t,e){o&&(o.borderScaleFactor=1/t,o.cornerSize=6*(1/t),o.touchCornerSize=24*(1/t),o.cornerStrokeColor=e.stroke,o.setCoords())}function Jx(o){const t=Rs.get(o);t&&(t.discardActiveObject(),t.renderAll())}function Qx(o){const t=Rs.get(o);t&&(t.clear(),Rs.delete(o))}function Zx(o,t){return new ke(o,{scaleX:t,scaleY:t})}var rl={};rl.d=(o,t)=>{for(var e in t)rl.o(t,e)&&!rl.o(o,e)&&Object.defineProperty(o,e,{enumerable:!0,get:t[e]})},rl.o=(o,t)=>Object.prototype.hasOwnProperty.call(o,t);var Z=globalThis.pdfjsLib={};rl.d(Z,{AbortException:()=>qn,AnnotationEditorLayer:()=>op,AnnotationEditorParamsType:()=>dt,AnnotationEditorType:()=>nt,AnnotationEditorUIManager:()=>Xr,AnnotationLayer:()=>$C,AnnotationMode:()=>Yn,ColorPicker:()=>Cd,DOMSVGFactory:()=>Jg,DrawLayer:()=>hp,FeatureTest:()=>Ge,GlobalWorkerOptions:()=>rn,ImageKind:()=>ad,InvalidPDFException:()=>kg,MissingPDFException:()=>ol,OPS:()=>si,OutputScale:()=>jg,PDFDataRangeTransport:()=>r0,PDFDateString:()=>Fg,PDFWorker:()=>Co,PasswordResponses:()=>iS,PermissionFlag:()=>sS,PixelsPerInch:()=>Kn,RenderingCancelledException:()=>Rg,TextLayer:()=>fl,TouchManager:()=>md,UnexpectedResponseException:()=>cd,Util:()=>q,VerbosityLevel:()=>od,XfaLayer:()=>l0,build:()=>kC,createValidAbsoluteUrl:()=>oS,fetchData:()=>dd,getDocument:()=>vC,getFilenameFromUrl:()=>mS,getPdfFilenameFromUrl:()=>bS,getXfaPageViewport:()=>yS,isDataScheme:()=>fd,isPdfFile:()=>Lg,noContextMenu:()=>ii,normalizeUnicode:()=>fS,setLayerDimensions:()=>Gr,shadow:()=>ht,stopEvent:()=>gs,version:()=>EC});const Pe=typeof process=="object"&&process+""=="[object process]"&&!process.versions.nw&&!(process.versions.electron&&process.type&&process.type!=="browser"),Ay=[1,0,0,1,0,0],Ag=[.001,0,0,.001,0,0],tS=1e7,Tg=1.35,fs={ANY:1,DISPLAY:2,PRINT:4,SAVE:8,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},eS="pdfjs_internal_editor_",nt={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15},dt={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},sS={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},Me={FILL:0,STROKE:1,FILL_STROKE:2,INVISIBLE:3,FILL_ADD_TO_PATH:4,STROKE_ADD_TO_PATH:5,FILL_STROKE_ADD_TO_PATH:6,ADD_TO_PATH:7,FILL_STROKE_MASK:3,ADD_TO_PATH_FLAG:4},ad={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},oe={TEXT:1,LINK:2,FREETEXT:3,LINE:4,SQUARE:5,CIRCLE:6,POLYGON:7,POLYLINE:8,HIGHLIGHT:9,UNDERLINE:10,SQUIGGLY:11,STRIKEOUT:12,STAMP:13,CARET:14,INK:15,POPUP:16,FILEATTACHMENT:17,SOUND:18,MOVIE:19,WIDGET:20,SCREEN:21,PRINTERMARK:22,TRAPNET:23,WATERMARK:24,THREED:25,REDACT:26},al={SOLID:1,DASHED:2,BEVELED:3,INSET:4,UNDERLINE:5},od={ERRORS:0,WARNINGS:1,INFOS:5},si={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},iS={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};let hd=od.WARNINGS;function nS(o){Number.isInteger(o)&&(hd=o)}function rS(){return hd}function ld(o){hd>=od.INFOS&&console.log(`Info: ${o}`)}function rt(o){hd>=od.WARNINGS&&console.log(`Warning: ${o}`)}function Et(o){throw new Error(o)}function ee(o,t){o||Et(t)}function aS(o){switch(o==null?void 0:o.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}function oS(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=dS(o)}catch{}}const s=t?new URL(o,t):new URL(o);if(aS(s))return s}catch{}return null}function ht(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 Ty extends $n{constructor(t,e){super(t,"PasswordException"),this.code=e}}class Eg extends $n{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}}class kg extends $n{constructor(t){super(t,"InvalidPDFException")}}class ol extends $n{constructor(t){super(t,"MissingPDFException")}}class cd extends $n{constructor(t,e){super(t,"UnexpectedResponseException"),this.status=e}}class hS extends $n{constructor(t){super(t,"FormatError")}}class qn extends $n{constructor(t){super(t,"AbortException")}}function Ey(o){(typeof o!="object"||(o==null?void 0:o.length)===void 0)&&Et("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 ud(o){typeof o!="string"&&Et("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 lS(o){return String.fromCharCode(o>>24&255,o>>16&255,o>>8&255,o&255)}function Pg(o){const t=Object.create(null);for(const[e,s]of o)t[e]=s;return t}function cS(){const o=new Uint8Array(4);return o[0]=1,new Uint32Array(o.buffer,0,1)[0]===1}function uS(){try{return new Function(""),!0}catch{return!1}}class Ge{static get isLittleEndian(){return ht(this,"isLittleEndian",cS())}static get isEvalSupported(){return ht(this,"isEvalSupported",uS())}static get isOffscreenCanvasSupported(){return ht(this,"isOffscreenCanvasSupported",typeof OffscreenCanvas<"u")}static get isImageDecoderSupported(){return ht(this,"isImageDecoderSupported",typeof ImageDecoder<"u")}static get platform(){return typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.platform)=="string"?ht(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")}):ht(this,"platform",{isMac:!1,isWindows:!1,isFirefox:!1})}static get isCSSRoundSupported(){var t,e;return ht(this,"isCSSRoundSupported",(e=(t=globalThis.CSS)==null?void 0:t.supports)==null?void 0:e.call(t,"width: round(1.5px, 1px)"))}}const Mg=Array.from(Array(256).keys(),o=>o.toString(16).padStart(2,"0"));class q{static makeHexColor(t,e,s){return`#${Mg[t]}${Mg[e]}${Mg[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,an,wp).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,an,wp).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}}an=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,b=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],b),u[2]=Math.max(u[2],p),u[3]=Math.max(u[3],b)},wp=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,an,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),b=2*c;w(this,an,qd).call(this,t,e,s,i,n,r,a,h,(-u+p)/b,f),w(this,an,qd).call(this,t,e,s,i,n,r,a,h,(-u-p)/b,f)},v(q,an);function dS(o){return decodeURIComponent(escape(o))}let Og=null,ky=null;function fS(o){return Og||(Og=/([\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,ky=new Map([["ſt","ſt"]])),o.replaceAll(Og,(t,e,s)=>e?e.normalize("NFKC"):ky.get(s))}function gS(){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();const o=new Uint8Array(32);return crypto.getRandomValues(o),Ey(o)}const Dg="pdfjs_internal_id_";function pS(o){return Uint8Array.prototype.toBase64?o.toBase64():btoa(Ey(o))}typeof Promise.try!="function"&&(Promise.try=function(o,...t){return new Promise(e=>{e(o(...t))})});const nn="http://www.w3.org/2000/svg",$r=class $r{};J($r,"CSS",96),J($r,"PDF",72),J($r,"PDF_TO_CSS_UNITS",$r.CSS/$r.PDF);let Kn=$r;async function dd(o,t="text"){if(ll(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 hl{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,b,_,y;u===0?(p=Math.abs(c-t[1])*s+n,b=Math.abs(h-t[0])*s+r,_=(t[3]-t[1])*s,y=(t[2]-t[0])*s):(p=Math.abs(h-t[0])*s+n,b=Math.abs(c-t[1])*s+r,_=(t[2]-t[0])*s,y=(t[3]-t[1])*s),this.transform=[u*s,d*s,f*s,g*s,p-u*s*h-f*s*c,b-d*s*h-g*s*c],this.width=_,this.height=y}get rawDims(){const{userUnit:t,viewBox:e}=this,s=e.map(i=>i*t);return ht(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 hl({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 Rg extends $n{constructor(t,e=0){super(t,"RenderingCancelledException"),this.extraDelay=e}}function fd(o){const t=o.length;let e=0;for(;e<t&&o[e].trim()==="";)e++;return o.substring(e,e+5).toLowerCase()==="data:"}function Lg(o){return typeof o=="string"&&/\.pdf$/i.test(o)}function mS(o){return[o]=o.split(/[#?]/,1),o.substring(o.lastIndexOf("/")+1)}function bS(o,t="document.pdf"){if(typeof o!="string")return t;if(fd(o))return rt('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 Py{constructor(){J(this,"started",Object.create(null));J(this,"times",[])}time(t){t in this.started&&rt(`Timer is already running for ${t}`),this.started[t]=Date.now()}timeEnd(t){t in this.started||rt(`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 ll(o,t){try{const{protocol:e}=t?new URL(o,t):new URL(o);return e==="http:"||e==="https:"}catch{return!1}}function ii(o){o.preventDefault()}function gs(o){o.preventDefault(),o.stopPropagation()}class Fg{static toDateObject(t){if(!t||typeof t!="string")return null;l(this,yl)||m(this,yl,new RegExp("^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+|-])?(\\d{2})?'?(\\d{2})?'?"));const e=l(this,yl).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))}}yl=new WeakMap,v(Fg,yl);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 hl({viewBox:n,userUnit:1,scale:t,rotation:e})}function Ig(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):(rt(`Not a valid color format: "${o}"`),[0,0,0])}function vS(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,Ig(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 Ai(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 Gr(o,t,e=!1,s=!0){if(t instanceof hl){const{pageWidth:i,pageHeight:n}=t.rawDims,{style:r}=o,a=Ge.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 jg{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 on=class on{constructor(t){v(this,Xe);v(this,Qn,null);v(this,qr,null);v(this,ni);v(this,Kr,null);v(this,vl,null);m(this,ni,t),l(on,_l)||m(on,_l,Object.freeze({freetext:"pdfjs-editor-remove-freetext-button",highlight:"pdfjs-editor-remove-highlight-button",ink:"pdfjs-editor-remove-ink-button",stamp:"pdfjs-editor-remove-stamp-button"}))}render(){const t=m(this,Qn,document.createElement("div"));t.classList.add("editToolbar","hidden"),t.setAttribute("role","toolbar");const e=l(this,ni)._uiManager._signal;t.addEventListener("contextmenu",ii,{signal:e}),t.addEventListener("pointerdown",w(on,Ed,F0),{signal:e});const s=m(this,Kr,document.createElement("div"));s.className="buttons",t.append(s);const i=l(this,ni).toolbarPosition;if(i){const{style:n}=t,r=l(this,ni)._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,Xe,N0).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,vl))==null||t.shown()}async addAltText(t){const e=await t.render();w(this,Xe,Kd).call(this,e),l(this,Kr).prepend(e,l(this,Xe,xp)),m(this,vl,t)}addColorPicker(t){m(this,qr,t);const e=t.renderButton();w(this,Xe,Kd).call(this,e),l(this,Kr).prepend(e,l(this,Xe,xp))}remove(){var t;l(this,Qn).remove(),(t=l(this,qr))==null||t.destroy(),m(this,qr,null)}};Qn=new WeakMap,qr=new WeakMap,ni=new WeakMap,Kr=new WeakMap,vl=new WeakMap,_l=new WeakMap,Ed=new WeakSet,F0=function(t){t.stopPropagation()},Xe=new WeakSet,I0=function(t){l(this,ni)._focusEventsAllowed=!1,gs(t)},j0=function(t){l(this,ni)._focusEventsAllowed=!0,gs(t)},Kd=function(t){const e=l(this,ni)._uiManager._signal;t.addEventListener("focusin",w(this,Xe,I0).bind(this),{capture:!0,signal:e}),t.addEventListener("focusout",w(this,Xe,j0).bind(this),{capture:!0,signal:e}),t.addEventListener("contextmenu",ii,{signal:e})},N0=function(){const{editorType:t,_uiManager:e}=l(this,ni),s=document.createElement("button");s.className="delete",s.tabIndex=0,s.setAttribute("data-l10n-id",l(on,_l)[t]),w(this,Xe,Kd).call(this,s),s.addEventListener("click",i=>{e.delete()},{signal:e._signal}),l(this,Kr).append(s)},xp=function(){const t=document.createElement("div");return t.className="divider",t},v(on,Ed),v(on,_l,null);let Ng=on;class _S{constructor(t){v(this,Zn);v(this,wl,null);v(this,Jr,null);v(this,Qr);m(this,Qr,t)}show(t,e,s){const[i,n]=w(this,Zn,H0).call(this,e,s),{style:r}=l(this,Jr)||m(this,Jr,w(this,Zn,B0).call(this));t.append(l(this,Jr)),r.insetInlineEnd=`${100*i}%`,r.top=`calc(${100*n}% + var(--editor-toolbar-vert-offset))`}hide(){l(this,Jr).remove()}}wl=new WeakMap,Jr=new WeakMap,Qr=new WeakMap,Zn=new WeakSet,B0=function(){const t=m(this,Jr,document.createElement("div"));t.className="editToolbar",t.setAttribute("role","toolbar"),t.addEventListener("contextmenu",ii,{signal:l(this,Qr)._signal});const e=m(this,wl,document.createElement("div"));return e.className="buttons",t.append(e),w(this,Zn,V0).call(this),t},H0=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]},V0=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,Qr)._signal;t.addEventListener("contextmenu",ii,{signal:s}),t.addEventListener("click",()=>{l(this,Qr).highlightSelection("floating_button")},{signal:s}),l(this,wl).append(t)};function gd(o,t,e){for(const s of e)t.addEventListener(s,o[s].bind(o))}class wS{constructor(){v(this,kd,0)}get id(){return`${eS}${Ze(this,kd)._++}`}}kd=new WeakMap;const lp=class lp{constructor(){v(this,To);v(this,Ao,gS());v(this,xl,0);v(this,De,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 ht(this,"_isSVGFittingCanvas",n)}async getFromFile(t){const{lastModified:e,name:s,size:i,type:n}=t;return w(this,To,Jd).call(this,`${e}_${s}_${i}_${n}`,t)}async getFromUrl(t){return w(this,To,Jd).call(this,t,t)}async getFromBlob(t,e){const s=await e;return w(this,To,Jd).call(this,t,s)}async getFromId(t){l(this,De)||m(this,De,new Map);const e=l(this,De).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,De)||m(this,De,new Map);let s=l(this,De).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,Ao)}_${Ze(this,xl)._++}`,refCounter:1,isSvg:!1},l(this,De).set(t,s),l(this,De).set(s.id,s),s}getSvgUrl(t){const e=l(this,De).get(t);return e!=null&&e.isSvg?e.svgUrl:null}deleteId(t){var i;l(this,De)||m(this,De,new Map);const e=l(this,De).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,Ao)}_`)}};Ao=new WeakMap,xl=new WeakMap,De=new WeakMap,To=new WeakSet,Jd=async function(t,e){l(this,De)||m(this,De,new Map);let s=l(this,De).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,Ao)}_${Ze(this,xl)._++}`,refCounter:0,isSvg:!1});let i;if(typeof e=="string"?(s.url=e,i=await dd(e,"blob")):e instanceof File?i=s.file=e:e instanceof Blob&&(i=e),i.type==="image/svg+xml"){const n=lp._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){rt(i),s=null}return l(this,De).set(t,s),s&&l(this,De).set(s.id,s),s};let Bg=lp;class xS{constructor(t=128){v(this,Kt,[]);v(this,tr,!1);v(this,Sl);v(this,Vt,-1);m(this,Sl,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,Vt)===-1){l(this,Kt).length>0&&(l(this,Kt).length=0),m(this,Vt,0),l(this,Kt).push(h);return}if(r&&l(this,Kt)[l(this,Vt)].type===n){a&&(h.undo=l(this,Kt)[l(this,Vt)].undo),l(this,Kt)[l(this,Vt)]=h;return}const c=l(this,Vt)+1;c===l(this,Sl)?l(this,Kt).splice(0,1):(m(this,Vt,c),c<l(this,Kt).length&&l(this,Kt).splice(c)),l(this,Kt).push(h)}undo(){if(l(this,Vt)===-1)return;m(this,tr,!0);const{undo:t,post:e}=l(this,Kt)[l(this,Vt)];t(),e==null||e(),m(this,tr,!1),m(this,Vt,l(this,Vt)-1)}redo(){if(l(this,Vt)<l(this,Kt).length-1){m(this,Vt,l(this,Vt)+1),m(this,tr,!0);const{cmd:t,post:e}=l(this,Kt)[l(this,Vt)];t(),e==null||e(),m(this,tr,!1)}}hasSomethingToUndo(){return l(this,Vt)!==-1}hasSomethingToRedo(){return l(this,Vt)<l(this,Kt).length-1}cleanType(t){if(l(this,Vt)!==-1){for(let e=l(this,Vt);e>=0;e--)if(l(this,Kt)[e].type!==t){l(this,Kt).splice(e+1,l(this,Vt)-e),m(this,Vt,e);return}l(this,Kt).length=0,m(this,Vt,-1)}}destroy(){m(this,Kt,null)}}Kt=new WeakMap,tr=new WeakMap,Sl=new WeakMap,Vt=new WeakMap;class cl{constructor(t){v(this,Pd);this.buffer=[],this.callbacks=new Map,this.allKeys=new Set;const{isMac:e}=Ge.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,Pd,W0).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||gs(e))}}Pd=new WeakSet,W0=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 Md=class Md{get _colors(){const t=new Map([["CanvasText",null],["Canvas",null]]);return vS(t),ht(this,"_colors",t)}convert(t){const e=Ig(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 Md._colorsMapping.get(s);return e}getHexCode(t){const e=this._colors.get(t);return e?q.makeHexColor(...e):t}};J(Md,"_colorsMapping",new Map([["CanvasText",[0,0,0]],["Canvas",[255,255,255]]]));let Hg=Md;const Ro=class Ro{constructor(t,e,s,i,n,r,a,h,c,u,d,f,g){v(this,B);v(this,Eo,new AbortController);v(this,ps,null);v(this,he,new Map);v(this,ye,new Map);v(this,ko,null);v(this,hn,null);v(this,Po,null);v(this,Fs,new xS);v(this,er,null);v(this,Zr,null);v(this,Mo,0);v(this,ta,new Set);v(this,Ei,null);v(this,ri,null);v(this,ea,new Set);J(this,"_editorUndoBar",null);v(this,Cl,!1);v(this,Al,!1);v(this,Oo,!1);v(this,Tl,null);v(this,ki,null);v(this,sr,null);v(this,Do,null);v(this,ir,!1);v(this,Pi,null);v(this,Od,new wS);v(this,nr,!1);v(this,El,!1);v(this,rr,null);v(this,sa,null);v(this,kl,null);v(this,Pl,null);v(this,de,nt.NONE);v(this,xt,new Set);v(this,ln,null);v(this,ia,null);v(this,Ml,null);v(this,Ol,{isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1});v(this,ar,[0,0]);v(this,Mi,null);v(this,cn,null);v(this,Dl,null);v(this,Is,null);const p=this._signal=l(this,Eo).signal;m(this,cn,t),m(this,Dl,e),m(this,ko,s),this._eventBus=i,i._on("editingaction",this.onEditingAction.bind(this),{signal:p}),i._on("pagechanging",this.onPageChanging.bind(this),{signal:p}),i._on("scalechanging",this.onScaleChanging.bind(this),{signal:p}),i._on("rotationchanging",this.onRotationChanging.bind(this),{signal:p}),i._on("setpreference",this.onSetPreference.bind(this),{signal:p}),i._on("switchannotationeditorparams",b=>this.updateParams(b.type,b.value),{signal:p}),w(this,B,X0).call(this),w(this,B,q0).call(this),w(this,B,Cp).call(this),m(this,hn,n.annotationStorage),m(this,Tl,n.filterFactory),m(this,ia,r),m(this,Do,a||null),m(this,Cl,h),m(this,Al,c),m(this,Oo,u),m(this,Pl,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=Ro.prototype,e=r=>l(r,cn).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 ht(this,"_keyboardManager",new cl([[["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,cn).contains(a)&&!r.isEnterHandled}],[[" ","mac+ "],t.addNewEditorFromKeyboard,{checker:(r,{target:a})=>!(a instanceof HTMLButtonElement)&&l(r,cn).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,Is))==null||t.resolve(),m(this,Is,null),(e=l(this,Eo))==null||e.abort(),m(this,Eo,null),this._signal=null;for(const r of l(this,ye).values())r.destroy();l(this,ye).clear(),l(this,he).clear(),l(this,ea).clear(),m(this,ps,null),l(this,xt).clear(),l(this,Fs).destroy(),(s=l(this,ko))==null||s.destroy(),(i=l(this,Pi))==null||i.hide(),m(this,Pi,null),l(this,ki)&&(clearTimeout(l(this,ki)),m(this,ki,null)),l(this,Mi)&&(clearTimeout(l(this,Mi)),m(this,Mi,null)),(n=this._editorUndoBar)==null||n.destroy()}combinedSignal(t){return AbortSignal.any([this._signal,t.signal])}get mlManager(){return l(this,Pl)}get useNewAltTextFlow(){return l(this,Al)}get useNewAltTextWhenAddingImage(){return l(this,Oo)}get hcmFilter(){return ht(this,"hcmFilter",l(this,ia)?l(this,Tl).addHCMFilter(l(this,ia).foreground,l(this,ia).background):"none")}get direction(){return ht(this,"direction",getComputedStyle(l(this,cn)).direction)}get highlightColors(){return ht(this,"highlightColors",l(this,Do)?new Map(l(this,Do).split(",").map(t=>t.split("=").map(e=>e.trim()))):null)}get highlightColorNames(){return ht(this,"highlightColorNames",this.highlightColors?new Map(Array.from(this.highlightColors,t=>t.reverse())):null)}setCurrentDrawingSession(t){t?(this.unselectAll(),this.disableUserSelect(!0)):this.disableUserSelect(!1),m(this,Zr,t)}setMainHighlightColorPicker(t){m(this,kl,t)}editAltText(t,e=!1){var s;(s=l(this,ko))==null||s.editAltText(this,t,e)}switchToMode(t,e){this._eventBus.on("annotationeditormodechanged",e,{once:!0,signal:this._signal}),this._eventBus.dispatch("showannotationeditorui",{source:this,mode:t})}setPreference(t,e){this._eventBus.dispatch("setpreference",{source:this,name:t,value:e})}onSetPreference({name:t,value:e}){switch(t){case"enableNewAltTextWhenAddingImage":m(this,Oo,e);break}}onPageChanging({pageNumber:t}){m(this,Mo,t-1)}focusMainContainer(){l(this,cn).focus()}findParent(t,e){for(const s of l(this,ye).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,Dl).classList.toggle("noUserSelect",t)}addShouldRescale(t){l(this,ea).add(t)}removeShouldRescale(t){l(this,ea).delete(t)}onScaleChanging({scale:t}){var e;this.commitOrRemove(),this.viewParameters.realScale=t*Kn.PDF_TO_CSS_UNITS;for(const s of l(this,ea))s.onScaleChanging();(e=l(this,Zr))==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,B,Qd).call(this,e).closest(".textLayer"),u=this.getSelectionBoxes(c);if(!u)return;e.empty();const d=w(this,B,Sp).call(this,c),f=l(this,de)===nt.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(nt.HIGHLIGHT,g);return}g()}addToAnnotationStorage(t){!t.isEmpty()&&l(this,hn)&&!l(this,hn).has(t.id)&&l(this,hn).setValue(t.id,t)}blur(){if(this.isShiftKeyDown=!1,l(this,ir)&&(m(this,ir,!1),w(this,B,Zd).call(this,"main_toolbar")),!this.hasSelection)return;const{activeElement:t}=document;for(const e of l(this,xt))if(e.div.contains(t)){m(this,sa,[e,t]),e._focusEventsAllowed=!1;break}}focus(){if(!l(this,sa))return;const[t,e]=l(this,sa);m(this,sa,null),e.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this._signal}),e.focus()}addEditListeners(){w(this,B,Cp).call(this),w(this,B,Ap).call(this)}removeEditListeners(){w(this,B,$0).call(this),w(this,B,Tp).call(this)}dragOver(t){for(const{type:e}of t.dataTransfer.items)for(const s of l(this,ri))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,ri))if(s.isHandlingMimeForPasting(e.type)){s.paste(e,this.currentLayer),t.preventDefault();return}}copy(t){var s;if(t.preventDefault(),(s=l(this,ps))==null||s.commitOrRemove(),!this.hasSelection)return;const e=[];for(const i of l(this,xt)){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,ri))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){rt(`paste: "${n.message}".`);return}if(!Array.isArray(s))return;this.unselectAll();const i=this.currentLayer;try{const n=[];for(const h of s){const c=await i.deserialize(h);if(!c)return;n.push(c)}const r=()=>{for(const h of n)w(this,B,Ep).call(this,h);w(this,B,kp).call(this,n)},a=()=>{for(const h of n)h.remove()};this.addCommands({cmd:r,undo:a,mustExec:!0})}catch(n){rt(`paste: "${n.message}".`)}}keydown(t){!this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!0),l(this,de)!==nt.NONE&&!this.isEditorHandlingKeyboard&&Ro._keyboardManager.exec(this,t)}keyup(t){this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!1,l(this,ir)&&(m(this,ir,!1),w(this,B,Zd).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,U0).call(this),w(this,B,Ap).call(this),w(this,B,ts).call(this,{isEditing:l(this,de)!==nt.NONE,isEmpty:w(this,B,Xc).call(this),hasSomethingToUndo:l(this,Fs).hasSomethingToUndo(),hasSomethingToRedo:l(this,Fs).hasSomethingToRedo(),hasSelectedEditor:!1})):(w(this,B,Y0).call(this),w(this,B,Tp).call(this),w(this,B,ts).call(this,{isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(t){if(!l(this,ri)){m(this,ri,t);for(const e of l(this,ri))w(this,B,jn).call(this,e.defaultPropertiesToUpdate)}}getId(){return l(this,Od).id}get currentLayer(){return l(this,ye).get(l(this,Mo))}getLayer(t){return l(this,ye).get(t)}get currentPageIndex(){return l(this,Mo)}addLayer(t){l(this,ye).set(t.pageIndex,t),l(this,nr)?t.enable():t.disable()}removeLayer(t){l(this,ye).delete(t.pageIndex)}async updateMode(t,e=null,s=!1){var i;if(l(this,de)!==t&&!(l(this,Is)&&(await l(this,Is).promise,!l(this,Is)))){if(m(this,Is,Promise.withResolvers()),m(this,de,t),t===nt.NONE){this.setEditingState(!1),w(this,B,J0).call(this),(i=this._editorUndoBar)==null||i.hide(),l(this,Is).resolve();return}this.setEditingState(!0),await w(this,B,K0).call(this),this.unselectAll();for(const n of l(this,ye).values())n.updateMode(t);if(!e){s&&this.addNewEditorFromKeyboard(),l(this,Is).resolve();return}for(const n of l(this,he).values())n.annotationElementId===e?(this.setSelected(n),n.enterInEditMode()):n.unselect();l(this,Is).resolve()}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(t){t!==l(this,de)&&this._eventBus.dispatch("switchannotationeditormode",{source:this,mode:t})}updateParams(t,e){var s;if(l(this,ri)){switch(t){case dt.CREATE:this.currentLayer.addNewEditor();return;case dt.HIGHLIGHT_DEFAULT_COLOR:(s=l(this,kl))==null||s.updateColor(e);break;case dt.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:{type:"highlight",action:"toggle_visibility"}}}),(l(this,Ml)||m(this,Ml,new Map)).set(t,e),this.showAllEditors("highlight",e);break}for(const i of l(this,xt))i.updateParams(t,e);for(const i of l(this,ri))i.updateDefaultParams(t,e)}}showAllEditors(t,e,s=!1){var n;for(const r of l(this,he).values())r.editorType===t&&r.show(e);(((n=l(this,Ml))==null?void 0:n.get(dt.HIGHLIGHT_SHOW_ALL))??!0)!==e&&w(this,B,jn).call(this,[[dt.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(l(this,El)!==t){m(this,El,t);for(const e of l(this,ye).values())t?e.disableClick():e.enableClick(),e.div.classList.toggle("waiting",t)}}getEditors(t){const e=[];for(const s of l(this,he).values())s.pageIndex===t&&e.push(s);return e}getEditor(t){return l(this,he).get(t)}addEditor(t){l(this,he).set(t.id,t)}removeEditor(t){var e;t.div.contains(document.activeElement)&&(l(this,ki)&&clearTimeout(l(this,ki)),m(this,ki,setTimeout(()=>{this.focusMainContainer(),m(this,ki,null)},0))),l(this,he).delete(t.id),this.unselect(t),(!t.annotationElementId||!l(this,ta).has(t.annotationElementId))&&((e=l(this,hn))==null||e.remove(t.id))}addDeletedAnnotationElement(t){l(this,ta).add(t.annotationElementId),this.addChangedExistingAnnotation(t),t.deleted=!0}isDeletedAnnotationElement(t){return l(this,ta).has(t)}removeDeletedAnnotationElement(t){l(this,ta).delete(t.annotationElementId),this.removeChangedExistingAnnotation(t),t.deleted=!1}setActiveEditor(t){l(this,ps)!==t&&(m(this,ps,t),t&&w(this,B,jn).call(this,t.propertiesToUpdate))}updateUI(t){l(this,B,Q0)===t&&w(this,B,jn).call(this,t.propertiesToUpdate)}updateUIForDefaultProperties(t){w(this,B,jn).call(this,t.defaultPropertiesToUpdate)}toggleSelected(t){if(l(this,xt).has(t)){l(this,xt).delete(t),t.unselect(),w(this,B,ts).call(this,{hasSelectedEditor:this.hasSelection});return}l(this,xt).add(t),t.select(),w(this,B,jn).call(this,t.propertiesToUpdate),w(this,B,ts).call(this,{hasSelectedEditor:!0})}setSelected(t){var e;(e=l(this,Zr))==null||e.commitOrRemove();for(const s of l(this,xt))s!==t&&s.unselect();l(this,xt).clear(),l(this,xt).add(t),t.select(),w(this,B,jn).call(this,t.propertiesToUpdate),w(this,B,ts).call(this,{hasSelectedEditor:!0})}isSelected(t){return l(this,xt).has(t)}get firstSelectedEditor(){return l(this,xt).values().next().value}unselect(t){t.unselect(),l(this,xt).delete(t),w(this,B,ts).call(this,{hasSelectedEditor:this.hasSelection})}get hasSelection(){return l(this,xt).size!==0}get isEnterHandled(){return l(this,xt).size===1&&this.firstSelectedEditor.isEnterHandled}undo(){var t;l(this,Fs).undo(),w(this,B,ts).call(this,{hasSomethingToUndo:l(this,Fs).hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:w(this,B,Xc).call(this)}),(t=this._editorUndoBar)==null||t.hide()}redo(){l(this,Fs).redo(),w(this,B,ts).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:l(this,Fs).hasSomethingToRedo(),isEmpty:w(this,B,Xc).call(this)})}addCommands(t){l(this,Fs).add(t),w(this,B,ts).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:w(this,B,Xc).call(this)})}cleanUndoStack(t){l(this,Fs).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,xt)],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,B,Ep).call(this,r)};this.addCommands({cmd:s,undo:i,mustExec:!0})}commitOrRemove(){var t;(t=l(this,ps))==null||t.commitOrRemove()}hasSomethingToControl(){return l(this,ps)||this.hasSelection}selectAll(){for(const t of l(this,xt))t.commit();w(this,B,kp).call(this,l(this,he).values())}unselectAll(){var t;if(!(l(this,ps)&&(l(this,ps).commitOrRemove(),l(this,de)!==nt.NONE))&&!((t=l(this,Zr))!=null&&t.commitOrRemove())&&this.hasSelection){for(const e of l(this,xt))e.unselect();l(this,xt).clear(),w(this,B,ts).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,xt)],a=1e3;l(this,Mi)&&clearTimeout(l(this,Mi)),m(this,Mi,setTimeout(()=>{m(this,Mi,null),l(this,ar)[0]=l(this,ar)[1]=0,this.addCommands({cmd:()=>{for(const h of r)l(this,he).has(h.id)&&h.translateInPage(i,n)},undo:()=>{for(const h of r)l(this,he).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),m(this,Ei,new Map);for(const t of l(this,xt))l(this,Ei).set(t,{savedX:t.x,savedY:t.y,savedPageIndex:t.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!l(this,Ei))return!1;this.disableUserSelect(!1);const t=l(this,Ei);m(this,Ei,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,he).has(i.id)){const h=l(this,ye).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,Ei))for(const s of l(this,Ei).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,xt).size===1&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(t){return l(this,ps)===t}getActive(){return l(this,ps)}getMode(){return l(this,de)}get imageManager(){return ht(this,"imageManager",new Bg)}getSelectionBoxes(t){if(!t)return null;const e=document.getSelection();for(let c=0,u=e.rangeCount;c<u;c++)if(!t.contains(e.getRangeAt(c).commonAncestorContainer))return null;const{x:s,y:i,width:n,height:r}=t.getBoundingClientRect();let 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:b}of d.getClientRects())p===0||b===0||h.push(a(f,g,p,b))}return h.length===0?null:h}addChangedExistingAnnotation({annotationElementId:t,id:e}){(l(this,Po)||m(this,Po,new Map)).set(t,e)}removeChangedExistingAnnotation({annotationElementId:t}){var e;(e=l(this,Po))==null||e.delete(t)}renderAnnotationElement(t){var i;const e=(i=l(this,Po))==null?void 0:i.get(t.data.id);if(!e)return;const s=l(this,hn).getRawValue(e);s&&(l(this,de)===nt.NONE&&!s.hasBeenModified||s.renderAnnotationElement(t))}};Eo=new WeakMap,ps=new WeakMap,he=new WeakMap,ye=new WeakMap,ko=new WeakMap,hn=new WeakMap,Po=new WeakMap,Fs=new WeakMap,er=new WeakMap,Zr=new WeakMap,Mo=new WeakMap,ta=new WeakMap,Ei=new WeakMap,ri=new WeakMap,ea=new WeakMap,Cl=new WeakMap,Al=new WeakMap,Oo=new WeakMap,Tl=new WeakMap,ki=new WeakMap,sr=new WeakMap,Do=new WeakMap,ir=new WeakMap,Pi=new WeakMap,Od=new WeakMap,nr=new WeakMap,El=new WeakMap,rr=new WeakMap,sa=new WeakMap,kl=new WeakMap,Pl=new WeakMap,de=new WeakMap,xt=new WeakMap,ln=new WeakMap,ia=new WeakMap,Ml=new WeakMap,Ol=new WeakMap,ar=new WeakMap,Mi=new WeakMap,cn=new WeakMap,Dl=new WeakMap,Is=new WeakMap,B=new WeakSet,Qd=function({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t},Sp=function(t){const{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(const s of l(this,ye).values())if(s.hasTextLayer(t))return s;return null},z0=function(){const t=document.getSelection();if(!t||t.isCollapsed)return;const s=w(this,B,Qd).call(this,t).closest(".textLayer"),i=this.getSelectionBoxes(s);i&&(l(this,Pi)||m(this,Pi,new _S(this)),l(this,Pi).show(s,i,this.direction==="ltr"))},G0=function(){var n,r,a;const t=document.getSelection();if(!t||t.isCollapsed){l(this,ln)&&((n=l(this,Pi))==null||n.hide(),m(this,ln,null),w(this,B,ts).call(this,{hasSelectedText:!1}));return}const{anchorNode:e}=t;if(e===l(this,ln))return;const i=w(this,B,Qd).call(this,t).closest(".textLayer");if(!i){l(this,ln)&&((r=l(this,Pi))==null||r.hide(),m(this,ln,null),w(this,B,ts).call(this,{hasSelectedText:!1}));return}if((a=l(this,Pi))==null||a.hide(),m(this,ln,e),w(this,B,ts).call(this,{hasSelectedText:!0}),!(l(this,de)!==nt.HIGHLIGHT&&l(this,de)!==nt.NONE)&&(l(this,de)===nt.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0),m(this,ir,this.isShiftKeyDown),!this.isShiftKeyDown)){const h=l(this,de)===nt.HIGHLIGHT?w(this,B,Sp).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,Zd).call(this,"main_toolbar"))};window.addEventListener("pointerup",d,{signal:u}),window.addEventListener("blur",d,{signal:u})}},Zd=function(t=""){l(this,de)===nt.HIGHLIGHT?this.highlightSelection(t):l(this,Cl)&&w(this,B,z0).call(this)},X0=function(){document.addEventListener("selectionchange",w(this,B,G0).bind(this),{signal:this._signal})},U0=function(){if(l(this,sr))return;m(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})},Y0=function(){var t;(t=l(this,sr))==null||t.abort(),m(this,sr,null)},Cp=function(){if(l(this,rr))return;m(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})},$0=function(){var t;(t=l(this,rr))==null||t.abort(),m(this,rr,null)},Ap=function(){if(l(this,er))return;m(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})},Tp=function(){var t;(t=l(this,er))==null||t.abort(),m(this,er,null)},q0=function(){const t=this._signal;document.addEventListener("dragover",this.dragOver.bind(this),{signal:t}),document.addEventListener("drop",this.drop.bind(this),{signal:t})},ts=function(t){Object.entries(t).some(([s,i])=>l(this,Ol)[s]!==i)&&(this._eventBus.dispatch("annotationeditorstateschanged",{source:this,details:Object.assign(l(this,Ol),t)}),l(this,de)===nt.HIGHLIGHT&&t.hasSelectedEditor===!1&&w(this,B,jn).call(this,[[dt.HIGHLIGHT_FREE,!0]]))},jn=function(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})},K0=async function(){if(!l(this,nr)){m(this,nr,!0);const t=[];for(const e of l(this,ye).values())t.push(e.enable());await Promise.all(t);for(const e of l(this,he).values())e.enable()}},J0=function(){if(this.unselectAll(),l(this,nr)){m(this,nr,!1);for(const t of l(this,ye).values())t.disable();for(const t of l(this,he).values())t.disable()}},Ep=function(t){const e=l(this,ye).get(t.pageIndex);e?e.addOrRebuild(t):(this.addEditor(t),this.addToAnnotationStorage(t))},Q0=function(){let t=null;for(t of l(this,xt));return t},Xc=function(){if(l(this,he).size===0)return!0;if(l(this,he).size===1)for(const t of l(this,he).values())return t.isEmpty();return!1},kp=function(t){for(const e of l(this,xt))e.unselect();l(this,xt).clear();for(const e of t)e.isEmpty()||(l(this,xt).add(e),e.select());w(this,B,ts).call(this,{hasSelectedEditor:this.hasSelection})},J(Ro,"TRANSLATE_SMALL",1),J(Ro,"TRANSLATE_BIG",10);let Xr=Ro;const Ue=class Ue{constructor(t){v(this,oi);v(this,fe,null);v(this,Oi,!1);v(this,ai,null);v(this,Lo,null);v(this,Di,null);v(this,ms,null);v(this,Fo,!1);v(this,Ri,null);v(this,as,null);v(this,un,null);v(this,na,null);v(this,Li,!1);m(this,as,t),m(this,Li,t._uiManager.useNewAltTextFlow),l(Ue,or)||m(Ue,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){Ue._l10n??(Ue._l10n=t)}async render(){const t=m(this,ai,document.createElement("button"));t.className="altText",t.tabIndex="0";const e=m(this,Lo,document.createElement("span"));t.append(e),l(this,Li)?(t.classList.add("new"),t.setAttribute("data-l10n-id",l(Ue,or).missing),e.setAttribute("data-l10n-id",l(Ue,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,as)._uiManager._signal;t.addEventListener("contextmenu",ii,{signal:s}),t.addEventListener("pointerdown",n=>n.stopPropagation(),{signal:s});const i=n=>{n.preventDefault(),l(this,as)._uiManager.editAltText(l(this,as)),l(this,Li)&&l(this,as)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_clicked",data:{label:l(this,oi,Uc)}})};return t.addEventListener("click",i,{capture:!0,signal:s}),t.addEventListener("keydown",n=>{n.target===t&&n.key==="Enter"&&(m(this,Fo,!0),i(n))},{signal:s}),await w(this,oi,tf).call(this),t}finish(){l(this,ai)&&(l(this,ai).focus({focusVisible:l(this,Fo)}),m(this,Fo,!1))}isEmpty(){return l(this,Li)?l(this,fe)===null:!l(this,fe)&&!l(this,Oi)}hasData(){return l(this,Li)?l(this,fe)!==null||!!l(this,un):this.isEmpty()}get guessedText(){return l(this,un)}async setGuessedText(t){l(this,fe)===null&&(m(this,un,t),m(this,na,await Ue._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",{generatedAltText:t})),w(this,oi,tf).call(this))}toggleAltTextBadge(t=!1){var e;if(!l(this,Li)||l(this,fe)){(e=l(this,Ri))==null||e.remove(),m(this,Ri,null);return}if(!l(this,Ri)){const s=m(this,Ri,document.createElement("div"));s.className="noAltTextBadge",l(this,as).div.append(s)}l(this,Ri).classList.toggle("hidden",!t)}serialize(t){let e=l(this,fe);return!t&&l(this,un)===e&&(e=l(this,na)),{altText:e,decorative:l(this,Oi),guessedText:l(this,un),textWithDisclaimer:l(this,na)}}get data(){return{altText:l(this,fe),decorative:l(this,Oi)}}set data({altText:t,decorative:e,guessedText:s,textWithDisclaimer:i,cancel:n=!1}){s&&(m(this,un,s),m(this,na,i)),!(l(this,fe)===t&&l(this,Oi)===e)&&(n||(m(this,fe,t),m(this,Oi,e)),w(this,oi,tf).call(this))}toggle(t=!1){l(this,ai)&&(!t&&l(this,ms)&&(clearTimeout(l(this,ms)),m(this,ms,null)),l(this,ai).disabled=!t)}shown(){l(this,as)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_displayed",data:{label:l(this,oi,Uc)}})}destroy(){var t,e;(t=l(this,ai))==null||t.remove(),m(this,ai,null),m(this,Lo,null),m(this,Di,null),(e=l(this,Ri))==null||e.remove(),m(this,Ri,null)}};fe=new WeakMap,Oi=new WeakMap,ai=new WeakMap,Lo=new WeakMap,Di=new WeakMap,ms=new WeakMap,Fo=new WeakMap,Ri=new WeakMap,as=new WeakMap,un=new WeakMap,na=new WeakMap,Li=new WeakMap,or=new WeakMap,oi=new WeakSet,Uc=function(){return l(this,fe)&&"added"||l(this,fe)===null&&this.guessedText&&"review"||"missing"},tf=async function(){var i,n,r;const t=l(this,ai);if(!t)return;if(l(this,Li)){if(t.classList.toggle("done",!!l(this,fe)),t.setAttribute("data-l10n-id",l(Ue,or)[l(this,oi,Uc)]),(i=l(this,Lo))==null||i.setAttribute("data-l10n-id",l(Ue,or)[`${l(this,oi,Uc)}-label`]),!l(this,fe)){(n=l(this,Di))==null||n.remove();return}}else{if(!l(this,fe)&&!l(this,Oi)){t.classList.remove("done"),(r=l(this,Di))==null||r.remove();return}t.classList.add("done"),t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-edit-button")}let e=l(this,Di);if(!e){m(this,Di,e=document.createElement("span")),e.className="tooltip",e.setAttribute("role","tooltip"),e.id=`alt-text-tooltip-${l(this,as).id}`;const a=100,h=l(this,as)._uiManager._signal;h.addEventListener("abort",()=>{clearTimeout(l(this,ms)),m(this,ms,null)},{once:!0}),t.addEventListener("mouseenter",()=>{m(this,ms,setTimeout(()=>{m(this,ms,null),l(this,Di).classList.add("show"),l(this,as)._reportTelemetry({action:"alt_text_tooltip"})},a))},{signal:h}),t.addEventListener("mouseleave",()=>{var c;l(this,ms)&&(clearTimeout(l(this,ms)),m(this,ms,null)),(c=l(this,Di))==null||c.classList.remove("show")},{signal:h})}l(this,Oi)?e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-decorative-tooltip"):(e.removeAttribute("data-l10n-id"),e.textContent=l(this,fe)),e.parentNode||t.append(e);const s=l(this,as).getImageForAltText();s==null||s.setAttribute("aria-describedby",e.id)},v(Ue,or,null),J(Ue,"_l10n",null);let pd=Ue;const cp=class cp{constructor({container:t,isPinchingDisabled:e=null,isPinchingStopped:s=null,onPinchStart:i=null,onPinching:n=null,onPinchEnd:r=null,signal:a}){v(this,fn);v(this,Rl);v(this,ra,!1);v(this,Ll,null);v(this,Fl);v(this,Il);v(this,jl);v(this,Nl);v(this,Io);v(this,dn,null);v(this,aa);v(this,hr,null);m(this,Rl,t),m(this,Ll,s),m(this,Fl,e),m(this,Il,i),m(this,jl,n),m(this,Nl,r),m(this,aa,new AbortController),m(this,Io,AbortSignal.any([a,l(this,aa).signal])),t.addEventListener("touchstart",w(this,fn,Z0).bind(this),{passive:!1,signal:l(this,Io)})}get MIN_TOUCH_DISTANCE_TO_PINCH(){return ht(this,"MIN_TOUCH_DISTANCE_TO_PINCH",35/(window.devicePixelRatio||1))}destroy(){var t;(t=l(this,aa))==null||t.abort(),m(this,aa,null)}};Rl=new WeakMap,ra=new WeakMap,Ll=new WeakMap,Fl=new WeakMap,Il=new WeakMap,jl=new WeakMap,Nl=new WeakMap,Io=new WeakMap,dn=new WeakMap,aa=new WeakMap,hr=new WeakMap,fn=new WeakSet,Z0=function(t){var i,n,r;if((i=l(this,Fl))!=null&&i.call(this)||t.touches.length<2)return;if(!l(this,hr)){m(this,hr,new AbortController);const a=AbortSignal.any([l(this,Io),l(this,hr).signal]),h=l(this,Rl),c={signal:a,passive:!1};h.addEventListener("touchmove",w(this,fn,tv).bind(this),c),h.addEventListener("touchend",w(this,fn,Pp).bind(this),c),h.addEventListener("touchcancel",w(this,fn,Pp).bind(this),c),(n=l(this,Il))==null||n.call(this)}if(gs(t),t.touches.length!==2||(r=l(this,Ll))!=null&&r.call(this)){m(this,dn,null);return}let[e,s]=t.touches;e.identifier>s.identifier&&([e,s]=[s,e]),m(this,dn,{touch0X:e.screenX,touch0Y:e.screenY,touch1X:s.screenX,touch1Y:s.screenY})},tv=function(t){var A;if(!l(this,dn)||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,dn),{touch0X:c,touch0Y:u,touch1X:d,touch1Y:f}=h,g=d-c,p=f-u,b=r-i,_=a-n,y=Math.hypot(b,_)||1,x=Math.hypot(g,p)||1;if(!l(this,ra)&&Math.abs(x-y)<=cp.MIN_TOUCH_DISTANCE_TO_PINCH)return;if(h.touch0X=i,h.touch0Y=n,h.touch1X=r,h.touch1Y=a,t.preventDefault(),!l(this,ra)){m(this,ra,!0);return}const C=[(i+r)/2,(n+a)/2];(A=l(this,jl))==null||A.call(this,C,x,y)},Pp=function(t){var e;l(this,hr).abort(),m(this,hr,null),(e=l(this,Nl))==null||e.call(this),l(this,dn)&&(t.preventDefault(),m(this,dn,null),m(this,ra,!1))};let md=cp;const ot=class ot{constructor(t){v(this,K);v(this,oa,null);v(this,hi,null);v(this,Rt,null);v(this,jo,!1);v(this,lr,null);v(this,Bl,"");v(this,ha,!1);v(this,ve,null);v(this,la,null);v(this,gn,null);v(this,cr,null);v(this,Hl,"");v(this,ca,!1);v(this,bs,null);v(this,Vl,!1);v(this,ua,!1);v(this,pn,!1);v(this,Fi,null);v(this,No,0);v(this,Bo,0);v(this,js,null);v(this,da,null);J(this,"_editToolbar",null);J(this,"_initialOptions",Object.create(null));J(this,"_initialData",null);J(this,"_isVisible",!0);J(this,"_uiManager",null);J(this,"_focusEventsAllowed",!0);v(this,Wl,!1);v(this,Dd,ot._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=ot.prototype._resizeWithKeyboard,e=Xr.TRANSLATE_SMALL,s=Xr.TRANSLATE_BIG;return ht(this,"_resizerKeyboardManager",new cl([[["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"],ot.prototype._stopResizingWithKeyboard]]))}get editorType(){return Object.getPrototypeOf(this).constructor._type}static get isDrawer(){return!1}static get _defaultLineColor(){return ht(this,"_defaultLineColor",this._colorManager.getHexCode("CanvasText"))}static deleteAnnotationElement(t){const e=new SS({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(ot._l10n??(ot._l10n=t),ot._l10nResizer||(ot._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"})),ot._borderLineWidth!==-1)return;const s=getComputedStyle(document.documentElement);ot._borderLineWidth=parseFloat(s.getPropertyValue("--outline-width"))||0}static updateDefaultParams(t,e){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(t){return!1}static paste(t,e){Et("Not implemented")}get propertiesToUpdate(){return[]}get _isDraggable(){return l(this,Wl)}set _isDraggable(t){var e;m(this,Wl,t),(e=this.div)==null||e.classList.toggle("draggable",t)}get isEnterHandled(){return!0}center(){const[t,e]=this.pageDimensions;switch(this.parentRotation){case 90:this.x-=this.height*e/(t*2),this.y+=this.width*t/(e*2);break;case 180:this.x+=this.width/2,this.y+=this.height/2;break;case 270:this.x+=this.height*e/(t*2),this.y-=this.width*t/(e*2);break;default:this.x-=this.width/2,this.y-=this.height/2;break}this.fixAndSetPosition()}addCommands(t){this._uiManager.addCommands(t)}get currentLayer(){return this._uiManager.currentLayer}setInBackground(){this.div.style.zIndex=0}setInForeground(){this.div.style.zIndex=l(this,Dd)}setParent(t){t!==null?(this.pageIndex=t.pageIndex,this.pageDimensions=t.pageDimensions):w(this,K,Yc).call(this),this.parent=t}focusin(t){this._focusEventsAllowed&&(l(this,ca)?m(this,ca,!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,K,Mp).call(this,this.parentDimensions,t,e)}translateInPage(t,e){l(this,bs)||m(this,bs,[this.x,this.y,this.width,this.height]),w(this,K,Mp).call(this,this.pageDimensions,t,e),this.div.scrollIntoView({block:"nearest"})}drag(t,e){l(this,bs)||m(this,bs,[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,bs)&&(l(this,bs)[0]!==this.x||l(this,bs)[1]!==this.y)}get _hasBeenResized(){return!!l(this,bs)&&(l(this,bs)[2]!==this.width||l(this,bs)[3]!==this.height)}getBaseTranslation(){const[t,e]=this.parentDimensions,{_borderLineWidth:s}=ot,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=ot,zl,Op).call(s,t,e,this.parentRotation)}pageTranslationToScreen(t,e){var s;return w(s=ot,zl,Op).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,ha)||(n.height=`${(100*e/i).toFixed(2)}%`)}fixDims(){const{style:t}=this.div,{height:e,width:s}=t,i=s.endsWith("%"),n=!l(this,ha)&&e.endsWith("%");if(i&&n)return;const[r,a]=this.parentDimensions;i||(t.width=`${(100*parseFloat(s)/r).toFixed(2)}%`),!l(this,ha)&&!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,ua)?this._editToolbar:(this._editToolbar=new Ng(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)||(pd.initialize(ot._l10n),m(this,Rt,new pd(this)),l(this,oa)&&(l(this,Rt).data=l(this,oa),m(this,oa,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,jo)?-1:0,this._isVisible||this.div.classList.add("hidden"),this.setInForeground(),w(this,K,Fp).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),gd(this,this.div,["pointerdown"]),this.isResizable&&this._uiManager._supportsPinchToZoom&&(l(this,da)||m(this,da,new md({container:this.div,isPinchingDisabled:()=>!this.isSelected,onPinchStart:w(this,K,iv).bind(this),onPinching:w(this,K,nv).bind(this),onPinchEnd:w(this,K,rv).bind(this),signal:this._uiManager._signal}))),(n=this._uiManager._editorUndoBar)==null||n.hide(),this.div}pointerdown(t){const{isMac:e}=Ge.platform;if(t.button!==0||t.ctrlKey&&e){t.preventDefault();return}if(m(this,ca,!0),this._isDraggable){w(this,K,av).call(this,t);return}w(this,K,Lp).call(this,t)}get isSelected(){return this._uiManager.isSelected(this)}_onStartDragging(){}_onStopDragging(){}moveInDOM(){l(this,Fi)&&clearTimeout(l(this,Fi)),m(this,Fi,setTimeout(()=>{var t;m(this,Fi,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(){m(this,ua,!0)}disableEditMode(){m(this,ua,!1)}isInEditMode(){return l(this,ua)}shouldGetKeyboardEvents(){return l(this,pn)}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,K,Fp).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){Et("An editor must be serializable")}static async deserialize(t,e,s){const i=new this.prototype.constructor({parent:e,id:e.getNextId(),uiManager:s});i.rotation=t.rotation,m(i,oa,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(),m(this,cr,null),this.isEmpty()||this.commit(),this.parent?this.parent.remove(this):this._uiManager.removeEditor(this),l(this,Fi)&&(clearTimeout(l(this,Fi)),m(this,Fi,null)),w(this,K,Yc).call(this),this.removeEditToolbar(),l(this,js)){for(const s of l(this,js).values())clearTimeout(s);m(this,js,null)}this.parent=null,(e=l(this,da))==null||e.destroy(),m(this,da,null)}get isResizable(){return!1}makeResizable(){this.isResizable&&(w(this,K,ev).call(this),l(this,ve).classList.remove("hidden"),gd(this,this.div,["keydown"]))}get toolbarPosition(){return null}keydown(t){if(!this.isResizable||t.target!==this.div||t.key!=="Enter")return;this._uiManager.setSelected(this),m(this,gn,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height});const e=l(this,ve).children;if(!l(this,hi)){m(this,hi,Array.from(e));const r=w(this,K,ov).bind(this),a=w(this,K,hv).bind(this),h=this._uiManager._signal;for(const c of l(this,hi)){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,K,lv).bind(this,u),{signal:h}),c.setAttribute("data-l10n-id",ot._l10nResizer[u])}}const s=l(this,hi)[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,hi).length/4);if(n!==i){if(n<i)for(let a=0;a<i-n;a++)l(this,ve).append(l(this,ve).firstChild);else if(n>i)for(let a=0;a<n-i;a++)l(this,ve).firstChild.before(l(this,ve).lastChild);let r=0;for(const a of e){const c=l(this,hi)[r++].getAttribute("data-resizer-name");a.setAttribute("data-l10n-id",ot._l10nResizer[c])}}w(this,K,Ip).call(this,0),m(this,pn,!0),l(this,ve).firstChild.focus({focusVisible:!0}),t.preventDefault(),t.stopImmediatePropagation()}_resizeWithKeyboard(t,e){l(this,pn)&&w(this,K,Rp).call(this,l(this,Hl),{deltaX:t,deltaY:e,fromKeyboard:!0})}_stopResizingWithKeyboard(){w(this,K,Yc).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,ve))==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,Vl)}set isEditing(t){m(this,Vl,t),this.parent&&(t?(this.parent.setSelected(this),this.parent.setActiveEditor(this)):this.parent.setActiveEditor(null))}setAspectRatio(t,e){m(this,ha,!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,js)||m(this,js,new Map);const{action:s}=t;let i=l(this,js).get(s);i&&clearTimeout(i),i=setTimeout(()=>{this._reportTelemetry(t),l(this,js).delete(s),l(this,js).size===0&&m(this,js,null)},ot._telemetryTimeout),l(this,js).set(s,i);return}t.type||(t.type=this.editorType),this._uiManager._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:t}})}show(t=this._isVisible){this.div.classList.toggle("hidden",!t),this._isVisible=t}enable(){this.div&&(this.div.tabIndex=0),m(this,jo,!1)}disable(){this.div&&(this.div.tabIndex=-1),m(this,jo,!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()}};oa=new WeakMap,hi=new WeakMap,Rt=new WeakMap,jo=new WeakMap,lr=new WeakMap,Bl=new WeakMap,ha=new WeakMap,ve=new WeakMap,la=new WeakMap,gn=new WeakMap,cr=new WeakMap,Hl=new WeakMap,ca=new WeakMap,bs=new WeakMap,Vl=new WeakMap,ua=new WeakMap,pn=new WeakMap,Fi=new WeakMap,No=new WeakMap,Bo=new WeakMap,js=new WeakMap,da=new WeakMap,Wl=new WeakMap,Dd=new WeakMap,K=new WeakSet,Mp=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()},zl=new WeakSet,Op=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]}},ef=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]}},ev=function(){if(l(this,ve))return;m(this,ve,document.createElement("div")),l(this,ve).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,ve).append(i),i.classList.add("resizer",s),i.setAttribute("data-resizer-name",s),i.addEventListener("pointerdown",w(this,K,sv).bind(this,s),{signal:e}),i.addEventListener("contextmenu",ii,{signal:e}),i.tabIndex=-1}this.div.prepend(l(this,ve))},sv=function(t,e){var u;e.preventDefault();const{isMac:s}=Ge.platform;if(e.button!==0||e.ctrlKey&&s)return;(u=l(this,Rt))==null||u.toggle(!1);const i=this._isDraggable;this._isDraggable=!1,m(this,la,[e.screenX,e.screenY]);const n=new AbortController,r=this._uiManager.combinedSignal(n);this.parent.togglePointerEvents(!1),window.addEventListener("pointermove",w(this,K,Rp).bind(this,t),{passive:!0,capture:!0,signal:r}),window.addEventListener("touchmove",gs,{passive:!1,signal:r}),window.addEventListener("contextmenu",ii,{signal:r}),m(this,gn,{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,K,sf).call(this)};window.addEventListener("pointerup",c,{signal:r}),window.addEventListener("blur",c,{signal:r})},Dp=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()},sf=function(){if(!l(this,gn))return;const{savedX:t,savedY:e,savedWidth:s,savedHeight:i}=l(this,gn);m(this,gn,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,K,Dp).bind(this,n,r,a,h),undo:w(this,K,Dp).bind(this,t,e,s,i),mustExec:!0})},Rp=function(t,e){const[s,i]=this.parentDimensions,n=this.x,r=this.y,a=this.width,h=this.height,c=ot.MIN_SIZE/s,u=ot.MIN_SIZE/i,d=w(this,K,ef).call(this,this.rotation),f=(j,z)=>[d[0]*j+d[2]*z,d[1]*j+d[3]*z],g=w(this,K,ef).call(this,360-this.rotation),p=(j,z)=>[g[0]*j+g[2]*z,g[1]*j+g[3]*z];let b,_,y=!1,x=!1;switch(t){case"topLeft":y=!0,b=(j,z)=>[0,0],_=(j,z)=>[j,z];break;case"topMiddle":b=(j,z)=>[j/2,0],_=(j,z)=>[j/2,z];break;case"topRight":y=!0,b=(j,z)=>[j,0],_=(j,z)=>[0,z];break;case"middleRight":x=!0,b=(j,z)=>[j,z/2],_=(j,z)=>[0,z/2];break;case"bottomRight":y=!0,b=(j,z)=>[j,z],_=(j,z)=>[0,0];break;case"bottomMiddle":b=(j,z)=>[j/2,z],_=(j,z)=>[j/2,0];break;case"bottomLeft":y=!0,b=(j,z)=>[0,z],_=(j,z)=>[j,0];break;case"middleLeft":x=!0,b=(j,z)=>[0,z/2],_=(j,z)=>[j,z/2];break}const C=b(a,h),A=_(a,h);let P=f(...A);const D=ot._round(n+P[0]),k=ot._round(r+P[1]);let M=1,R=1,F,I;if(e.fromKeyboard)({deltaX:F,deltaY:I}=e);else{const{screenX:j,screenY:z}=e,[it,kt]=l(this,la);[F,I]=this.screenToPageTranslation(j-it,z-kt),l(this,la)[0]=j,l(this,la)[1]=z}if([F,I]=p(F/s,I/i),y){const j=Math.hypot(a,h);M=R=Math.max(Math.min(Math.hypot(A[0]-C[0]-F,A[1]-C[1]-I)/j,1/a,1/h),c/a,u/h)}else x?M=Math.max(c,Math.min(1,Math.abs(A[0]-C[0]-F)))/a:R=Math.max(u,Math.min(1,Math.abs(A[1]-C[1]-I)))/h;const Y=ot._round(a*M),N=ot._round(h*R);P=f(..._(Y,N));const H=D-P[0],at=k-P[1];l(this,bs)||m(this,bs,[this.x,this.y,this.width,this.height]),this.width=Y,this.height=N,this.x=H,this.y=at,this.setDims(s*Y,i*N),this.fixAndSetPosition(),this._onResizing()},iv=function(){var t;m(this,gn,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height}),(t=l(this,Rt))==null||t.toggle(!1),this.parent.togglePointerEvents(!1)},nv=function(t,e,s){let n=.7*(s/e)+1-.7;if(n===1)return;const r=w(this,K,ef).call(this,this.rotation),a=(D,k)=>[r[0]*D+r[2]*k,r[1]*D+r[3]*k],[h,c]=this.parentDimensions,u=this.x,d=this.y,f=this.width,g=this.height,p=ot.MIN_SIZE/h,b=ot.MIN_SIZE/c;n=Math.max(Math.min(n,1/f,1/g),p/f,b/g);const _=ot._round(f*n),y=ot._round(g*n);if(_===f&&y===g)return;l(this,bs)||m(this,bs,[u,d,f,g]);const x=a(f/2,g/2),C=ot._round(u+x[0]),A=ot._round(d+x[1]),P=a(_/2,y/2);this.x=C-P[0],this.y=A-P[1],this.width=_,this.height=y,this.setDims(h*_,c*y),this.fixAndSetPosition(),this._onResizing()},rv=function(){var t;(t=l(this,Rt))==null||t.toggle(!0),this.parent.togglePointerEvents(!0),w(this,K,sf).call(this)},Lp=function(t){const{isMac:e}=Ge.platform;t.ctrlKey&&!e||t.shiftKey||t.metaKey&&e?this.parent.toggleSelected(this):this.parent.setSelected(this)},av=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(),m(this,lr,null),m(this,ca,!1),this._uiManager.endDragSession()||w(this,K,Lp).call(this,c),s&&this._onStopDragging()};e&&(m(this,No,t.clientX),m(this,Bo,t.clientY),m(this,lr,t.pointerId),m(this,Bl,t.pointerType),window.addEventListener("pointermove",c=>{s||(s=!0,this._onStartDragging());const{clientX:u,clientY:d,pointerId:f}=c;if(f!==l(this,lr)){gs(c);return}const[g,p]=this.screenToPageTranslation(u-l(this,No),d-l(this,Bo));m(this,No,u),m(this,Bo,d),this._uiManager.dragSelectedEditors(g,p)},r),window.addEventListener("touchmove",gs,r),window.addEventListener("pointerdown",c=>{c.pointerType===l(this,Bl)&&(l(this,da)||c.isPrimary)&&a(c),gs(c)},r));const h=c=>{if(!l(this,lr)||l(this,lr)===c.pointerId){a(c);return}gs(c)};window.addEventListener("pointerup",h,{signal:n}),window.addEventListener("blur",h,{signal:n})},Fp=function(){if(l(this,cr)||!this.div)return;m(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})},ov=function(t){ot._resizerKeyboardManager.exec(this,t)},hv=function(t){var e;l(this,pn)&&((e=t.relatedTarget)==null?void 0:e.parentNode)!==l(this,ve)&&w(this,K,Yc).call(this)},lv=function(t){m(this,Hl,l(this,pn)?t:"")},Ip=function(t){if(l(this,hi))for(const e of l(this,hi))e.tabIndex=t},Yc=function(){m(this,pn,!1),w(this,K,Ip).call(this,-1),w(this,K,sf).call(this)},v(ot,zl),J(ot,"_l10n",null),J(ot,"_l10nResizer",null),J(ot,"_borderLineWidth",-1),J(ot,"_colorManager",new Hg),J(ot,"_zIndex",1),J(ot,"_telemetryTimeout",1e3);let Ht=ot;class SS extends Ht{constructor(t){super(t),this.annotationElementId=t.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}}const My=3285377520,Ls=4294901760,Ti=65535;class Oy{constructor(t){this.h1=t?t&4294967295:My,this.h2=t?t&4294967295:My}update(t){let e,s;if(typeof t=="string"){e=new Uint8Array(t.length*2),s=0;for(let b=0,_=t.length;b<_;b++){const y=t.charCodeAt(b);y<=255?e[s++]=y:(e[s++]=y>>>8,e[s++]=y&255)}}else if(ArrayBuffer.isView(t))e=t.slice(),s=e.byteLength;else throw new Error("Invalid data format, must be a string or TypedArray.");const i=s>>2,n=s-i*4,r=new Uint32Array(e.buffer,0,i);let a=0,h=0,c=this.h1,u=this.h2;const d=3432918353,f=461845907,g=d&Ti,p=f&Ti;for(let b=0;b<i;b++)b&1?(a=r[b],a=a*d&Ls|a*g&Ti,a=a<<15|a>>>17,a=a*f&Ls|a*p&Ti,c^=a,c=c<<13|c>>>19,c=c*5+3864292196):(h=r[b],h=h*d&Ls|h*g&Ti,h=h<<15|h>>>17,h=h*f&Ls|h*p&Ti,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&Ls|a*g&Ti,a=a<<15|a>>>17,a=a*f&Ls|a*p&Ti,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&Ls|t*36045&Ti,e=e*4283543511&Ls|((e<<16|t>>>16)*2950163797&Ls)>>>16,t^=e>>>1,t=t*444984403&Ls|t*60499&Ti,e=e*3301882366&Ls|((e<<16|t>>>16)*3120437893&Ls)>>>16,t^=e>>>1,(t>>>0).toString(16).padStart(8,"0")+(e>>>0).toString(16).padStart(8,"0")}}const Vg=Object.freeze({map:null,hash:"",transfer:void 0});class Wg{constructor(){v(this,Rd);v(this,fa,!1);v(this,ga,null);v(this,ge,new Map);this.onSetModified=null,this.onResetModified=null,this.onAnnotationEditor=null}getValue(t,e){const s=l(this,ge).get(t);return s===void 0?e:Object.assign(e,s)}getRawValue(t){return l(this,ge).get(t)}remove(t){if(l(this,ge).delete(t),l(this,ge).size===0&&this.resetModified(),typeof this.onAnnotationEditor=="function"){for(const e of l(this,ge).values())if(e instanceof Ht)return;this.onAnnotationEditor(null)}}setValue(t,e){const s=l(this,ge).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,ge).set(t,e);i&&w(this,Rd,cv).call(this),e instanceof Ht&&typeof this.onAnnotationEditor=="function"&&this.onAnnotationEditor(e.constructor._type)}has(t){return l(this,ge).has(t)}getAll(){return l(this,ge).size>0?Pg(l(this,ge)):null}setAll(t){for(const[e,s]of Object.entries(t))this.setValue(e,s)}get size(){return l(this,ge).size}resetModified(){l(this,fa)&&(m(this,fa,!1),typeof this.onResetModified=="function"&&this.onResetModified())}get print(){return new Dy(this)}get serializable(){if(l(this,ge).size===0)return Vg;const t=new Map,e=new Oy,s=[],i=Object.create(null);let n=!1;for(const[r,a]of l(this,ge)){const h=a instanceof Ht?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}:Vg}get editorStats(){let t=null;const e=new Map;for(const s of l(this,ge).values()){if(!(s instanceof Ht))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(){m(this,ga,null)}get modifiedIds(){if(l(this,ga))return l(this,ga);const t=[];for(const e of l(this,ge).values())!(e instanceof Ht)||!e.annotationElementId||!e.serialize()||t.push(e.annotationElementId);return m(this,ga,{ids:new Set(t),hash:t.join(",")})}}fa=new WeakMap,ga=new WeakMap,ge=new WeakMap,Rd=new WeakSet,cv=function(){l(this,fa)||(m(this,fa,!0),typeof this.onSetModified=="function"&&this.onSetModified())};class Dy extends Wg{constructor(e){super();v(this,Gl);const{map:s,hash:i,transfer:n}=e.serializable,r=structuredClone(s,n?{transfer:n}:null);m(this,Gl,{map:r,hash:i,transfer:n})}get print(){Et("Should not call PrintAnnotationStorage.print")}get serializable(){return l(this,Gl)}get modifiedIds(){return ht(this,"modifiedIds",{ids:new Set,hash:""})}}Gl=new WeakMap;class CS{constructor({ownerDocument:t=globalThis.document,styleElement:e=null}){v(this,Ho,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,Ho).clear(),this.styleElement&&(this.styleElement.remove(),this.styleElement=null)}async loadSystemFont({systemFontInfo:t,_inspectFont:e}){if(!(!t||l(this,Ho).has(t.loadedName))){if(ee(!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,Ho).add(s),e==null||e(t)}catch{rt(`Cannot load system font: ${t.baseFontName}, installing it could help to improve PDF rendering.`),this.removeNativeFontFace(r)}return}Et("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 rt(`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 ht(this,"isFontLoadingAPISupported",t)}get isSyncFontLoadingSupported(){let t=!1;return(Pe||typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.userAgent)=="string"&&/Mozilla\/5.0.*?rv:\d+.*? Gecko/.test(navigator.userAgent))&&(t=!0),ht(this,"isSyncFontLoadingSupported",t)}_queueLoadingCallback(t){function e(){for(ee(!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 ht(this,"_loadTestFont",t)}_prepareFontLoadEvent(t,e){function s(A,P){return A.charCodeAt(P)<<24|A.charCodeAt(P+1)<<16|A.charCodeAt(P+2)<<8|A.charCodeAt(P+3)&255}function i(A,P,D,k){const M=A.substring(0,P),R=A.substring(P+D);return M+k+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(A,P){if(++c>30){rt("Load test font never loaded."),P();return}if(h.font="30px "+A,h.fillText(".",0,20),h.getImageData(0,0,1,1).data[3]>0){P();return}setTimeout(u.bind(null,A,P))}const d=`lt${Date.now()}${this.loadTestFontId++}`;let f=this._loadTestFont;f=i(f,976,d.length,d);const p=16,b=1482184792;let _=s(f,p);for(n=0,r=d.length-3;n<r;n+=4)_=_-b+s(d,n)|0;n<d.length&&(_=_-b+s(d+"XXX",n)|0),f=i(f,p,4,lS(_));const y=`url(data:font/opentype;base64,${btoa(f)});`,x=`@font-face {font-family:"${d}";src:${y}}`;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 A of[t.loadedName,d]){const P=this._document.createElement("span");P.textContent="Hi",P.style.fontFamily=A,C.append(P)}this._document.body.append(C),u(d,()=>{C.remove(),e.complete()})}}Ho=new WeakMap;class AS{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,${pS(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){rt(`getPathGenerator - ignoring character: "${r}".`)}const n=new Path2D(i||"");return this.fontExtraProperties||t.delete(s),this.compiledGlyphs[e]=n}}const bd={DATA:1,ERROR:2},se={CANCEL:1,CANCEL_COMPLETE:2,CLOSE:3,ENQUEUE:4,ERROR:5,PULL:6,PULL_COMPLETE:7,START_COMPLETE:8};function Ry(){}function is(o){if(o instanceof qn||o instanceof kg||o instanceof ol||o instanceof Ty||o instanceof cd||o instanceof Eg)return o;switch(o instanceof Error||typeof o=="object"&&o!==null||Et('wrapReason: Expected "reason" to be a (possibly cloned) Error.'),o.name){case"AbortException":return new qn(o.message);case"InvalidPDFException":return new kg(o.message);case"MissingPDFException":return new ol(o.message);case"PasswordException":return new Ty(o.message,o.code);case"UnexpectedResponseException":return new cd(o.message,o.status);case"UnknownErrorException":return new Eg(o.message,o.details)}return new Eg(o.message,o.toString())}class ul{constructor(t,e,s){v(this,Ns);v(this,Vo,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,Ns,uv).bind(this),{signal:l(this,Vo).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:se.PULL,streamId:n,desiredSize:c.desiredSize}),u.promise},cancel:c=>{ee(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:se.CANCEL,streamId:n,reason:is(c)}),u.promise}},s)}destroy(){var t;(t=l(this,Vo))==null||t.abort(),m(this,Vo,null)}}Vo=new WeakMap,Ns=new WeakSet,uv=function({data:t}){if(t.targetName!==this.sourceName)return;if(t.stream){w(this,Ns,fv).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===bd.DATA)i.resolve(t.data);else if(t.callback===bd.ERROR)i.reject(is(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:bd.DATA,callbackId:t.callbackId,data:r})},function(r){n.postMessage({sourceName:s,targetName:i,callback:bd.ERROR,callbackId:t.callbackId,reason:is(r)})});return}if(t.streamId){w(this,Ns,dv).call(this,t);return}e(t.data)},dv=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:se.ENQUEUE,streamId:e,chunk:c},d)},close(){this.isCancelled||(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:se.CLOSE,streamId:e}),delete r.streamSinks[e])},error(c){ee(c instanceof Error,"error must have a valid reason"),!this.isCancelled&&(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:se.ERROR,streamId:e,reason:is(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:se.START_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:se.START_COMPLETE,streamId:e,reason:is(c)})})},fv=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 se.START_COMPLETE:t.success?r.startCall.resolve():r.startCall.reject(is(t.reason));break;case se.PULL_COMPLETE:t.success?r.pullCall.resolve():r.pullCall.reject(is(t.reason));break;case se.PULL:if(!a){n.postMessage({sourceName:s,targetName:i,stream:se.PULL_COMPLETE,streamId:e,success:!0});break}a.desiredSize<=0&&t.desiredSize>0&&a.sinkCapability.resolve(),a.desiredSize=t.desiredSize,Promise.try(a.onPull||Ry).then(function(){n.postMessage({sourceName:s,targetName:i,stream:se.PULL_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:se.PULL_COMPLETE,streamId:e,reason:is(c)})});break;case se.ENQUEUE:if(ee(r,"enqueue should have stream controller"),r.isClosed)break;r.controller.enqueue(t.chunk);break;case se.CLOSE:if(ee(r,"close should have stream controller"),r.isClosed)break;r.isClosed=!0,r.controller.close(),w(this,Ns,nf).call(this,r,e);break;case se.ERROR:ee(r,"error should have stream controller"),r.controller.error(is(t.reason)),w(this,Ns,nf).call(this,r,e);break;case se.CANCEL_COMPLETE:t.success?r.cancelCall.resolve():r.cancelCall.reject(is(t.reason)),w(this,Ns,nf).call(this,r,e);break;case se.CANCEL:if(!a)break;const h=is(t.reason);Promise.try(a.onCancel||Ry,h).then(function(){n.postMessage({sourceName:s,targetName:i,stream:se.CANCEL_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:se.CANCEL_COMPLETE,streamId:e,reason:is(c)})}),a.sinkCapability.reject(h),a.isCancelled=!0,delete this.streamSinks[e];break;default:throw new Error("Unexpected stream case")}},nf=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 Ly{constructor({enableHWA:t=!1}){v(this,Xl,!1);m(this,Xl,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,Xl)})}}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){Et("Abstract method `_createCanvas` called.")}}Xl=new WeakMap;class TS extends Ly{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 Fy{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){Et("Abstract method `_fetch` called.")}}class Iy extends Fy{async _fetch(t){const e=await dd(t,this.isCompressed?"arraybuffer":"text");return e instanceof ArrayBuffer?new Uint8Array(e):ud(e)}}class jy{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 ES extends jy{constructor({docId:e,ownerDocument:s=globalThis.document}){super();v(this,W);v(this,pa);v(this,Wo);v(this,mn);v(this,bn);v(this,Re);v(this,ma);v(this,ba,0);m(this,bn,e),m(this,Re,s)}addFilter(e){if(!e)return"none";let s=l(this,W,je).get(e);if(s)return s;const[i,n,r]=w(this,W,rf).call(this,e),a=e.length===1?i:`${i}${n}${r}`;if(s=l(this,W,je).get(a),s)return l(this,W,je).set(e,s),s;const h=`g_${l(this,bn)}_transfer_map_${Ze(this,ba)._++}`,c=w(this,W,Fh).call(this,h);l(this,W,je).set(e,c),l(this,W,je).set(a,c);const u=w(this,W,Ih).call(this,h);return w(this,W,Kc).call(this,i,n,r,u),c}addHCMFilter(e,s){var p;const i=`${e}-${s}`,n="base";let r=l(this,W,$c).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,$c).set(n,r)),!e||!s))return r.url;const a=w(this,W,Jc).call(this,e);e=q.makeHexColor(...a);const h=w(this,W,Jc).call(this,s);if(s=q.makeHexColor(...h),l(this,W,Lh).style.color="",e==="#000000"&&s==="#ffffff"||e===s)return r.url;const c=new Array(256);for(let b=0;b<=255;b++){const _=b/255;c[b]=_<=.03928?_/12.92:((_+.055)/1.055)**2.4}const u=c.join(","),d=`g_${l(this,bn)}_hcm_filter`,f=r.filter=w(this,W,Ih).call(this,d);w(this,W,Kc).call(this,u,u,u,f),w(this,W,jp).call(this,f);const g=(b,_)=>{const y=a[b]/255,x=h[b]/255,C=new Array(_+1);for(let A=0;A<=_;A++)C[A]=y+A/_*(x-y);return C.join(",")};return w(this,W,Kc).call(this,g(0,5),g(1,5),g(2,5),f),r.url=w(this,W,Fh).call(this,d),r.url}addAlphaFilter(e){let s=l(this,W,je).get(e);if(s)return s;const[i]=w(this,W,rf).call(this,[e]),n=`alpha_${i}`;if(s=l(this,W,je).get(n),s)return l(this,W,je).set(e,s),s;const r=`g_${l(this,bn)}_alpha_map_${Ze(this,ba)._++}`,a=w(this,W,Fh).call(this,r);l(this,W,je).set(e,a),l(this,W,je).set(n,a);const h=w(this,W,Ih).call(this,r);return w(this,W,Np).call(this,i,h),a}addLuminosityFilter(e){let s=l(this,W,je).get(e||"luminosity");if(s)return s;let i,n;if(e?([i]=w(this,W,rf).call(this,[e]),n=`luminosity_${i}`):n="luminosity",s=l(this,W,je).get(n),s)return l(this,W,je).set(e,s),s;const r=`g_${l(this,bn)}_luminosity_map_${Ze(this,ba)._++}`,a=w(this,W,Fh).call(this,r);l(this,W,je).set(e,a),l(this,W,je).set(n,a);const h=w(this,W,Ih).call(this,r);return w(this,W,gv).call(this,h),e&&w(this,W,Np).call(this,i,h),a}addHighlightHCMFilter(e,s,i,n,r){var x;const a=`${s}-${i}-${n}-${r}`;let h=l(this,W,$c).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,W,$c).set(e,h)),!s||!i))return h.url;const[c,u]=[s,i].map(w(this,W,Jc).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,Jc).bind(this));f<d&&([d,f,g,p]=[f,d,p,g]),l(this,W,Lh).style.color="";const b=(C,A,P)=>{const D=new Array(256),k=(f-d)/P,M=C/255,R=(A-C)/(255*P);let F=0;for(let I=0;I<=P;I++){const Y=Math.round(d+I*k),N=M+I*R;for(let H=F;H<=Y;H++)D[H]=N;F=Y+1}for(let I=F;I<256;I++)D[I]=D[F-1];return D.join(",")},_=`g_${l(this,bn)}_hcm_${e}_filter`,y=h.filter=w(this,W,Ih).call(this,_);return w(this,W,jp).call(this,y),w(this,W,Kc).call(this,b(g[0],p[0],5),b(g[1],p[1],5),b(g[2],p[2],5),y),h.url=w(this,W,Fh).call(this,_),h.url}destroy(e=!1){var s,i,n,r;e&&((s=l(this,ma))!=null&&s.size)||((i=l(this,mn))==null||i.parentNode.parentNode.remove(),m(this,mn,null),(n=l(this,Wo))==null||n.clear(),m(this,Wo,null),(r=l(this,ma))==null||r.clear(),m(this,ma,null),m(this,ba,0))}}pa=new WeakMap,Wo=new WeakMap,mn=new WeakMap,bn=new WeakMap,Re=new WeakMap,ma=new WeakMap,ba=new WeakMap,W=new WeakSet,je=function(){return l(this,Wo)||m(this,Wo,new Map)},$c=function(){return l(this,ma)||m(this,ma,new Map)},Lh=function(){if(!l(this,mn)){const e=l(this,Re).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,Re).createElementNS(nn,"svg");i.setAttribute("width",0),i.setAttribute("height",0),m(this,mn,l(this,Re).createElementNS(nn,"defs")),e.append(i),i.append(l(this,mn)),l(this,Re).body.append(e)}return l(this,mn)},rf=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(",")]},Fh=function(e){if(l(this,pa)===void 0){m(this,pa,"");const s=l(this,Re).URL;s!==l(this,Re).baseURI&&(fd(s)?rt('#createUrl: ignore "data:"-URL for performance reasons.'):m(this,pa,s.split("#",1)[0]))}return`url(${l(this,pa)}#${e})`},gv=function(e){const s=l(this,Re).createElementNS(nn,"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)},jp=function(e){const s=l(this,Re).createElementNS(nn,"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)},Ih=function(e){const s=l(this,Re).createElementNS(nn,"filter");return s.setAttribute("color-interpolation-filters","sRGB"),s.setAttribute("id",e),l(this,W,Lh).append(s),s},qc=function(e,s,i){const n=l(this,Re).createElementNS(nn,s);n.setAttribute("type","discrete"),n.setAttribute("tableValues",i),e.append(n)},Kc=function(e,s,i,n){const r=l(this,Re).createElementNS(nn,"feComponentTransfer");n.append(r),w(this,W,qc).call(this,r,"feFuncR",e),w(this,W,qc).call(this,r,"feFuncG",s),w(this,W,qc).call(this,r,"feFuncB",i)},Np=function(e,s){const i=l(this,Re).createElementNS(nn,"feComponentTransfer");s.append(i),w(this,W,qc).call(this,i,"feFuncA",e)},Jc=function(e){return l(this,W,Lh).style.color=e,Ig(getComputedStyle(l(this,W,Lh)).getPropertyValue("color"))};class Ny{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){Et("Abstract method `_fetch` called.")}}class By extends Ny{async _fetch(t){const e=await dd(t,"arraybuffer");return new Uint8Array(e)}}Pe&&rt("Please use the `legacy` build in Node.js environments.");async function Hy(o){const e=await process.getBuiltinModule("fs").promises.readFile(o);return new Uint8Array(e)}class kS extends jy{}class PS extends Ly{_createCanvas(t,e){return process.getBuiltinModule("module").createRequire(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Mt&&Mt.tagName.toUpperCase()==="SCRIPT"&&Mt.src||new URL("pdf-canvas.umd.js",document.baseURI).href)("@napi-rs/canvas").createCanvas(t,e)}}class MS extends Fy{async _fetch(t){return Hy(t)}}class OS extends Ny{async _fetch(t){return Hy(t)}}const Oe={FILL:"Fill",STROKE:"Stroke",SHADING:"Shading"};function zg(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 Gg{getPattern(){Et("Abstract method `getPattern` called.")}}class DS extends Gg{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===Oe.STROKE||i===Oe.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),zg(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 zg(t,this._bbox),n=this._createGradient(t);return n}}function Xg(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,b=(h[s]+t.offsetX)*t.scaleX,_=(h[s+1]+t.offsetY)*t.scaleY,y=(h[i]+t.offsetX)*t.scaleX,x=(h[i+1]+t.offsetY)*t.scaleY;if(p>=x)return;const C=c[n],A=c[n+1],P=c[n+2],D=c[r],k=c[r+1],M=c[r+2],R=c[a],F=c[a+1],I=c[a+2],Y=Math.round(p),N=Math.round(x);let H,at,j,z,it,kt,Ut,ne;for(let zt=Y;zt<=N;zt++){if(zt<_){const ft=zt<p?0:(p-zt)/(p-_);H=g-(g-b)*ft,at=C-(C-D)*ft,j=A-(A-k)*ft,z=P-(P-M)*ft}else{let ft;zt>x?ft=1:_===x?ft=0:ft=(_-zt)/(_-x),H=b-(b-y)*ft,at=D-(D-R)*ft,j=k-(k-F)*ft,z=M-(M-I)*ft}let Tt;zt<p?Tt=0:zt>x?Tt=1:Tt=(p-zt)/(p-x),it=g-(g-y)*Tt,kt=C-(C-R)*Tt,Ut=A-(A-F)*Tt,ne=P-(P-I)*Tt;const Ce=Math.round(Math.min(H,it)),Xs=Math.round(Math.max(H,it));let Dt=d*zt+Ce*4;for(let ft=Ce;ft<=Xs;ft++)Tt=(H-ft)/(H-it),Tt<0?Tt=0:Tt>1&&(Tt=1),u[Dt++]=at-(at-kt)*Tt|0,u[Dt++]=j-(j-Ut)*Tt|0,u[Dt++]=z-(z-ne)*Tt|0,u[Dt++]=255}}function RS(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++)Xg(o,e,s[u],s[u+1],s[u+a],i[u],i[u+1],i[u+a]),Xg(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)Xg(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 Gg{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,b={coords:this._coords,colors:this._colors,offsetX:-a,offsetY:-h,scaleX:1/g,scaleY:1/p},_=d+2*2,y=f+2*2,x=s.getCanvas("mesh",_,y),C=x.context,A=C.createImageData(d,f);if(e){const D=A.data;for(let k=0,M=D.length;k<M;k+=4)D[k]=e[0],D[k+1]=e[1],D[k+2]=e[2],D[k+3]=255}for(const D of this._figures)RS(A,D,b);return C.putImageData(A,2,2),{canvas:x.canvas,offsetX:a-2*g,offsetY:h-2*p,scaleX:g,scaleY:p}}getPattern(t,e,s,i){zg(t,this._bbox);let n;if(i===Oe.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===Oe.SHADING?null:this._background,e.cachedCanvases);return i!==Oe.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 FS extends Gg{getPattern(){return"hotpink"}}function IS(o){switch(o[0]){case"RadialAxial":return new DS(o);case"Mesh":return new LS(o);case"Dummy":return new FS}throw new Error(`Unknown IR type: ${o[0]}`)}const Vy={COLORED:1,UNCOLORED:2},Ld=class Ld{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),ld("TilingType: "+n);const u=e[0],d=e[1],f=e[2],g=e[3],p=f-u,b=g-d,_=q.singularValueDecompose2dScale(this.matrix),y=q.singularValueDecompose2dScale(this.baseTransform),x=_[0]*y[0],C=_[1]*y[1];let A=p,P=b,D=!1,k=!1;const M=Math.ceil(h*x),R=Math.ceil(c*C),F=Math.ceil(p*x),I=Math.ceil(b*C);M>=F?A=h:D=!0,R>=I?P=c:k=!0;const Y=this.getSizeAndScale(A,this.ctx.canvas.width,x),N=this.getSizeAndScale(P,this.ctx.canvas.height,C),H=t.cachedCanvases.getCanvas("pattern",Y.size,N.size),at=H.context,j=a.createCanvasGraphics(at);if(j.groupLevel=t.groupLevel,this.setFillAndStrokeStyleToContext(j,i,r),at.translate(-Y.scale*u,-N.scale*d),j.transform(Y.scale,0,0,N.scale,0,0),at.save(),this.clipBbox(j,u,d,f,g),j.baseTransform=It(j.ctx),j.executeOperatorList(s),j.endDrawing(),at.restore(),D||k){const z=H.canvas;D&&(A=h),k&&(P=c);const it=this.getSizeAndScale(A,this.ctx.canvas.width,x),kt=this.getSizeAndScale(P,this.ctx.canvas.height,C),Ut=it.size,ne=kt.size,zt=t.cachedCanvases.getCanvas("pattern-workaround",Ut,ne),Tt=zt.context,Ce=D?Math.floor(p/h):0,Xs=k?Math.floor(b/c):0;for(let Dt=0;Dt<=Ce;Dt++)for(let ft=0;ft<=Xs;ft++)Tt.drawImage(z,Ut*Dt,ne*ft,Ut,ne,0,0,Ut,ne);return{canvas:zt.canvas,scaleX:it.scale,scaleY:kt.scale,offsetX:u,offsetY:d}}return{canvas:H.canvas,scaleX:Y.scale,scaleY:N.scale,offsetX:u,offsetY:d}}getSizeAndScale(t,e,s){const i=Math.max(Ld.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 Vy.COLORED:const r=this.ctx;i.fillStyle=r.fillStyle,i.strokeStyle=r.strokeStyle,n.fillColor=r.fillStyle,n.strokeColor=r.strokeStyle;break;case Vy.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 hS(`Unsupported paint type: ${e}`)}}getPattern(t,e,s,i){let n=s;i!==Oe.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}};J(Ld,"MAX_PATTERN_SIZE",3e3);let Ug=Ld;function jS({src:o,srcPos:t=0,dest:e,width:s,height:i,nonBlackColor:n=4294967295,inverseDecode:r=!1}){const a=Ge.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 _=t+u;t<_;t++){const y=t<f?o[t]:255;e[g++]=y&128?c:h,e[g++]=y&64?c:h,e[g++]=y&32?c:h,e[g++]=y&16?c:h,e[g++]=y&8?c:h,e[g++]=y&4?c:h,e[g++]=y&2?c:h,e[g++]=y&1?c:h}if(d===0)continue;const b=t<f?o[t++]:255;for(let _=0;_<d;_++)e[g++]=b&1<<7-_?c:h}return{srcPos:t,destPos:g}}const Wy=16,zy=100,NS=15,Gy=10,Xy=1e3,ns=16;function BS(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 HS{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 yd(o,t,e,s,i,n,r,a,h,c){const[u,d,f,g,p,b]=It(o);if(d===0&&f===0){const x=r*u+p,C=Math.round(x),A=a*g+b,P=Math.round(A),D=(r+h)*u+p,k=Math.abs(Math.round(D)-C)||1,M=(a+c)*g+b,R=Math.abs(Math.round(M)-P)||1;return o.setTransform(Math.sign(u),0,0,Math.sign(g),C,P),o.drawImage(t,e,s,i,n,0,0,k,R),o.setTransform(u,d,f,g,p,b),[k,R]}if(u===0&&g===0){const x=a*f+p,C=Math.round(x),A=r*d+b,P=Math.round(A),D=(a+c)*f+p,k=Math.abs(Math.round(D)-C)||1,M=(r+h)*d+b,R=Math.abs(Math.round(M)-P)||1;return o.setTransform(0,Math.sign(d),Math.sign(f),0,C,P),o.drawImage(t,e,s,i,n,0,0,R,k),o.setTransform(u,d,f,g,p,b),[R,k]}o.drawImage(t,e,s,i,n,r,a,h,c);const _=Math.hypot(u,d),y=Math.hypot(f,g);return[_*h,y*c]}function VS(o){const{width:t,height:e}=o;if(t>Xy||e>Xy)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 y of o.data){let x=128;for(;x>0;)d[f++]=y&x?0:255,x>>=1}let g=0;for(f=0,d[f]!==0&&(r[0]=1,++g),h=1;h<t;h++)d[f]!==d[f+1]&&(r[h]=d[f]?2:1,++g),f++;for(d[f]!==0&&(r[h]=2,++g),a=1;a<e;a++){f=a*u,c=a*n,d[f-u]!==d[f]&&(r[c]=d[f]?1:8,++g);let y=(d[f]?4:0)+(d[f-u]?8:0);for(h=1;h<t;h++)y=(y>>2)+(d[f+1]?4:0)+(d[f-u+1]?8:0),i[y]&&(r[c+h]=i[y],++g),f++;if(d[f-u]!==d[f]&&(r[c+h]=d[f]?2:4,++g),g>s)return null}for(f=u*(e-1),c=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]),b=new Path2D;for(a=0;g&&a<=e;a++){let y=a*n;const x=y+t;for(;y<x&&!r[y];)y++;if(y===x)continue;b.moveTo(y%n,a);const C=y;let A=r[y];do{const P=p[A];do y+=P;while(!r[y]);const D=r[y];D!==5&&D!==10?(A=D,r[y]=0):(A=D&51*A>>4,r[y]&=A>>2|A<<2),b.lineTo(y%n,y/n|0),r[y]||--g}while(C!==y);--a}return d=null,r=null,function(y){y.save(),y.scale(1/t,-1/e),y.translate(0,-e),y.fill(b),y.beginPath(),y.restore()}}class Uy{constructor(t,e){this.alphaIsShape=!1,this.fontSize=0,this.fontSizeScale=1,this.textMatrix=Ay,this.textMatrixScale=1,this.fontMatrix=Ag,this.leading=0,this.x=0,this.y=0,this.lineX=0,this.lineY=0,this.charSpacing=0,this.wordSpacing=0,this.textHScale=1,this.textRenderingMode=Me.FILL,this.textRise=0,this.fillColor="#000000",this.strokeColor="#000000",this.patternFill=!1,this.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=Oe.FILL,e=null){const s=[this.minX,this.minY,this.maxX,this.maxY];if(t===Oe.STROKE){e||Et("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=Oe.FILL,e=null){return q.intersect(this.clipBox,this.getPathBoundingBox(t,e))}}function Yy(o,t){if(t instanceof ImageData){o.putImageData(t,0,0);return}const e=t.height,s=t.width,i=e%ns,n=(e-i)/ns,r=i===0?n:n+1,a=o.createImageData(s,ns);let h=0,c;const u=t.data,d=a.data;let f,g,p,b;if(t.kind===ad.GRAYSCALE_1BPP){const _=u.byteLength,y=new Uint32Array(d.buffer,0,d.byteLength>>2),x=y.length,C=s+7>>3,A=4294967295,P=Ge.isLittleEndian?4278190080:255;for(f=0;f<r;f++){for(p=f<n?ns:i,c=0,g=0;g<p;g++){const D=_-h;let k=0;const M=D>C?s:D*8-7,R=M&-8;let F=0,I=0;for(;k<R;k+=8)I=u[h++],y[c++]=I&128?A:P,y[c++]=I&64?A:P,y[c++]=I&32?A:P,y[c++]=I&16?A:P,y[c++]=I&8?A:P,y[c++]=I&4?A:P,y[c++]=I&2?A:P,y[c++]=I&1?A:P;for(;k<M;k++)F===0&&(I=u[h++],F=128),y[c++]=I&F?A:P,F>>=1}for(;c<x;)y[c++]=0;o.putImageData(a,0,f*ns)}}else if(t.kind===ad.RGBA_32BPP){for(g=0,b=s*ns*4,f=0;f<n;f++)d.set(u.subarray(h,h+b)),h+=b,o.putImageData(a,0,g),g+=ns;f<r&&(b=s*i*4,d.set(u.subarray(h,h+b)),o.putImageData(a,0,g))}else if(t.kind===ad.RGB_24BPP)for(p=ns,b=s*p,f=0;f<r;f++){for(f>=n&&(p=i,b=s*p),c=0,g=b;g--;)d[c++]=u[h++],d[c++]=u[h++],d[c++]=u[h++],d[c++]=255;o.putImageData(a,0,f*ns)}else throw new Error(`bad image kind: ${t.kind}`)}function $y(o,t){if(t.bitmap){o.drawImage(t.bitmap,0,0);return}const e=t.height,s=t.width,i=e%ns,n=(e-i)/ns,r=i===0?n:n+1,a=o.createImageData(s,ns);let h=0;const c=t.data,u=a.data;for(let d=0;d<r;d++){const f=d<n?ns:i;({srcPos:h}=jS({src:c,srcPos:h,dest:u,width:s,height:f,nonBlackColor:0})),o.putImageData(a,0,d*ns)}}function dl(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 vd(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),!Pe){const{filter:t}=o;t!=="none"&&t!==""&&(o.filter="none")}}function qy(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"],zS=["miter","round","bevel"],GS={},Ky={},up=class up{constructor(t,e,s,i,n,{optionalContentConfig:r,markedContentStack:a=null},h,c){v(this,li);this.ctx=t,this.current=new Uy(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 HS(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(),vd(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>Gy&&typeof s=="function",u=c?Date.now()+NS: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!==si.dependency)this[p].apply(this,n[a]);else for(const b of n[a]){const _=b.startsWith("g_")?f:g;if(!_.has(b))return _.get(b,s),a}if(a++,a===h)return a;if(c&&++d>Gy){if(Date.now()>u)return s(),a;d=0}}}endDrawing(){w(this,li,Bp).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,li,Hp).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 M=t.bitmap||t.data.buffer;c=JSON.stringify(r?a:[a.slice(0,4),n]),h=this._cachedBitmapsMap.get(M),h||(h=new Map,this._cachedBitmapsMap.set(M,h));const R=h.get(c);if(R&&!r){const F=Math.round(Math.min(a[0],a[2])+a[4]),I=Math.round(Math.min(a[1],a[3])+a[5]);return{canvas:R,offsetX:F,offsetY:I}}u=R}u||(d=this.cachedCanvases.getCanvas("maskCanvas",s,i),$y(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,b,_]=q.getAxialAlignedBoundingBox([0,0,s,i],f),y=Math.round(b-g)||1,x=Math.round(_-p)||1,C=this.cachedCanvases.getCanvas("fillCanvas",y,x),A=C.context,P=g,D=p;A.translate(-P,-D),A.transform(...f),u||(u=this._scaleImage(d.canvas,Ai(A)),u=u.img,h&&r&&h.set(c,u)),A.imageSmoothingEnabled=qy(It(A),t.interpolate),yd(A,u,0,0,u.width,u.height,0,0,s,i),A.globalCompositeOperation="source-in";const k=q.transform(Ai(A),[1,0,0,1,-P,-D]);return A.fillStyle=r?n.getPattern(e,this,k,Oe.FILL):n,A.fillRect(0,0,s,i),h&&!r&&(this.cachedCanvases.delete("fillCanvas"),h.set(c,C.canvas)),{canvas:C.canvas,offsetX:Math.round(P),offsetY:Math.round(D)}}setLineWidth(t){t!==this.current.lineWidth&&(this._cachedScaleForStroking[0]=-1),this.current.lineWidth=t,this.ctx.lineWidth=t}setLineCap(t){this.ctx.lineCap=WS[t]}setLineJoin(t){this.ctx.lineJoin=zS[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)),dl(this.suspendedCtx,n),BS(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(),dl(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 _=q.makeHexColor(...r);if(g<0||p<0||g+s>f.width||p+i>f.height){const y=this.cachedCanvases.getCanvas("maskExtension",s,i),x=y.context;x.drawImage(f,-g,-p),x.globalCompositeOperation="destination-atop",x.fillStyle=_,x.fillRect(0,0,s,i),x.globalCompositeOperation="source-over",f=y.canvas,g=p=0}else{t.save(),t.globalAlpha=1,t.setTransform(1,0,0,1,0,0);const y=new Path2D;y.rect(g,p,s,i),t.clip(y),t.globalCompositeOperation="destination-atop",t.fillStyle=_,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 b=new Path2D;b.rect(h,c,s,i),e.clip(b),e.globalCompositeOperation="destination-in",e.drawImage(f,g,p,s,i,h,c,s,i),e.restore()}save(){this.inSMaskMode?(dl(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(),dl(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,b=t.length;g<b;g++)switch(t[g]|0){case si.rectangle:r=e[p++],a=e[p++];const _=e[p++],y=e[p++],x=r+_,C=a+y;i.moveTo(r,a),_===0||y===0?i.lineTo(x,C):(i.lineTo(x,a),i.lineTo(x,C),i.lineTo(r,C)),d||n.updateRectMinMax(u,[r,a,x,C]),i.closePath();break;case si.moveTo:r=e[p++],a=e[p++],i.moveTo(r,a),d||n.updatePathMinMax(u,r,a);break;case si.lineTo:r=e[p++],a=e[p++],i.lineTo(r,a),d||n.updatePathMinMax(u,r,a);break;case si.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 si.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 si.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 si.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,Ai(e),Oe.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,Ai(e),Oe.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=GS}eoClip(){this.pendingClip=Ky}beginText(){this.current.textMatrix=Ay,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||Ag,(i.fontMatrix[0]===0||i.fontMatrix[3]===0)&&rt("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<Wy?c=Wy:e>zy&&(c=zy),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&Me.FILL_STROKE_MASK,f=!!(c&Me.ADD_TO_PATH_FLAG),g=a.patternFill&&!h.missingFile,p=a.patternStroke&&!h.missingFile;let b;if((h.disableFontFace||f||g||p)&&(b=h.getPathGenerator(this.commonObjs,t)),h.disableFontFace||g||p){if(r.save(),r.translate(e,s),r.scale(u,-u),d===Me.FILL||d===Me.FILL_STROKE)if(i){const _=r.getTransform();r.setTransform(...i),r.fill(w(this,li,Vp).call(this,b,_,i))}else r.fill(b);if(d===Me.STROKE||d===Me.FILL_STROKE)if(n){const _=r.getTransform();r.setTransform(...n),r.stroke(w(this,li,Vp).call(this,b,_,n))}else r.lineWidth/=u,r.stroke(b);r.restore()}else(d===Me.FILL||d===Me.FILL_STROKE)&&r.fillText(t,e,s),(d===Me.STROKE||d===Me.FILL_STROKE)&&r.strokeText(t,e,s);f&&(this.pendingTextPaths||(this.pendingTextPaths=[])).push({transform:It(r),x:e,y:s,fontSize:u,path:b})}get isFontSubpixelAAEnabled(){const{context:t}=this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled",10,10);t.scale(1.5,1),t.fillText("I",0,10);const e=t.getImageData(0,0,10,10).data;let s=!1;for(let i=3;i<e.length;i+=4)if(e[i]>0&&e[i]<255){s=!0;break}return ht(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,b=i*e.fontMatrix[0],_=e.textRenderingMode===Me.FILL&&!s.disableFontFace&&!e.patternFill;n.save(),n.transform(...e.textMatrix),n.translate(e.x,e.y+e.textRise),c>0?n.scale(u,-1):n.scale(u,1);let y,x;if(e.patternFill){n.save();const k=e.fillColor.getPattern(n,this,Ai(n),Oe.FILL);y=It(n),n.restore(),n.fillStyle=k}if(e.patternStroke){n.save();const k=e.strokeColor.getPattern(n,this,Ai(n),Oe.STROKE);x=It(n),n.restore(),n.strokeStyle=k}let C=e.lineWidth;const A=e.textMatrixScale;if(A===0||C===0){const k=e.textRenderingMode&Me.FILL_STROKE_MASK;(k===Me.STROKE||k===Me.FILL_STROKE)&&(C=this.getSinglePixelWidth())}else C/=A;if(r!==1&&(n.scale(r,r),C/=r),n.lineWidth=C,s.isInvalidPDFjsFont){const k=[];let M=0;for(const R of t)k.push(R.unicode),M+=R.width;n.fillText(k.join(""),0,0),e.x+=M*b*u,n.restore(),this.compose();return}let P=0,D;for(D=0;D<d;++D){const k=t[D];if(typeof k=="number"){P+=g*k*i/1e3;continue}let M=!1;const R=(k.isSpace?h:0)+a,F=k.fontChar,I=k.accent;let Y,N,H=k.width;if(f){const j=k.vmetric||p,z=-(k.vmetric?j[1]:H*.5)*b,it=j[2]*b;H=j?-j[0]:H,Y=z/r,N=(P+it)/r}else Y=P/r,N=0;if(s.remeasure&&H>0){const j=n.measureText(F).width*1e3/i*r;if(H<j&&this.isFontSubpixelAAEnabled){const z=H/j;M=!0,n.save(),n.scale(z,1),Y/=z}else H!==j&&(Y+=(H-j)/2e3*i/r)}if(this.contentVisible&&(k.isInFont||s.missingFile)){if(_&&!I)n.fillText(F,Y,N);else if(this.paintChar(F,Y,N,y,x),I){const j=Y+i*I.offset.x/r,z=N-i*I.offset.y/r;this.paintChar(I.fontChar,j,z,y,x)}}const at=f?H*b-R*c:H*b+R*c;P+=at,M&&n.restore()}f?e.y-=P:e.x+=P*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||Ag,f=t.length,g=s.textRenderingMode===Me.INVISIBLE;let p,b,_,y;if(!(g||n===0)){for(this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null,e.save(),e.transform(...s.textMatrix),e.translate(s.x,s.y),e.scale(u,r),p=0;p<f;++p){if(b=t[p],typeof b=="number"){y=a*b*n/1e3,this.ctx.translate(y,0),s.x+=y*u;continue}const x=(b.isSpace?c:0)+h,C=i.charProcOperatorList[b.operatorListId];if(!C){rt(`Type3 character "${b.operatorListId}" is not available.`);continue}this.contentVisible&&(this.processingType3=b,this.save(),e.scale(n,n),e.transform(...d),this.executeOperatorList(C),this.restore()),_=q.applyTransform([b.width,0],d)[0]*n+x,e.translate(_,0),s.x+=_*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 up(r,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack})};e=new Ug(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=IS(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,Ai(e),Oe.SHADING);const i=Ai(e);{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)}this.compose(this.current.getClippedPathBoundingBox()),this.restore()}beginInlineImage(){Et("Should not call beginInlineImage")}beginImageData(){Et("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||ld("TODO: Support non-isolated groups."),t.knockout&&rt("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()),dl(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,li,Bp).call(this),vd(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),vd(this.ctx)}else vd(this.ctx),this.endPath(),this.ctx.rect(e[0],e[1],r,a),this.ctx.clip(),this.ctx.beginPath()}this.current=new Uy(this.ctx.canvas.width,this.ctx.canvas.height),this.transform(...s),this.transform(...i)}endAnnotation(){this.annotationCanvas&&(this.ctx.restore(),w(this,li,Hp).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);$y(d,f),d.globalCompositeOperation="source-in",d.fillStyle=i?s.getPattern(d,this,Ai(e),Oe.FILL):s,d.fillRect(0,0,a,h),d.restore(),e.save(),e.transform(...c),e.scale(1,-1),yd(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){rt("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){rt("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(),!Pe){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;Yy(h,t),n=this.applyTransferMapsToCanvas(h)}const r=this._scaleImage(n,Ai(i));i.imageSmoothingEnabled=qy(It(i),t.interpolate),yd(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;Yy(h,t),i=this.applyTransferMapsToCanvas(h)}for(const n of e)s.save(),s.transform(...n.transform),s.scale(1,-1),yd(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===Ky?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}};li=new WeakSet,Bp=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)},Hp=function(){if(this.pageColors){const t=this.filterFactory.addHCMFilter(this.pageColors.foreground,this.pageColors.background);if(t!=="none"){const e=this.ctx.filter;this.ctx.filter=t,this.ctx.drawImage(this.ctx.canvas,0,0),this.ctx.filter=e}}},Vp=function(t,e,s){const i=new Path2D;return i.addPath(t,new DOMMatrix(s).invertSelf().multiplySelf(e)),i};let xo=up;for(const o in si)xo.prototype[o]!==void 0&&(xo.prototype[si[o]]=xo.prototype[o]);class rn{static get workerPort(){return l(this,Ul)}static set workerPort(t){if(!(typeof Worker<"u"&&t instanceof Worker)&&t!==null)throw new Error("Invalid `workerPort` type.");m(this,Ul,t)}static get workerSrc(){return l(this,Yl)}static set workerSrc(t){if(typeof t!="string")throw new Error("Invalid `workerSrc` type.");m(this,Yl,t)}}Ul=new WeakMap,Yl=new WeakMap,v(rn,Ul,null),v(rn,Yl,"");class XS{constructor({parsedData:t,rawData:e}){v(this,ya);v(this,$l);m(this,ya,t),m(this,$l,e)}getRaw(){return l(this,$l)}get(t){return l(this,ya).get(t)??null}getAll(){return Pg(l(this,ya))}has(t){return l(this,ya).has(t)}}ya=new WeakMap,$l=new WeakMap;const So=Symbol("INTERNAL");class US{constructor(t,{name:e,intent:s,usage:i,rbGroups:n}){v(this,ql,!1);v(this,Kl,!1);v(this,Jl,!1);v(this,zo,!0);m(this,ql,!!(t&fs.DISPLAY)),m(this,Kl,!!(t&fs.PRINT)),this.name=e,this.intent=s,this.usage=i,this.rbGroups=n}get visible(){if(l(this,Jl))return l(this,zo);if(!l(this,zo))return!1;const{print:t,view:e}=this.usage;return l(this,ql)?(e==null?void 0:e.viewState)!=="OFF":l(this,Kl)?(t==null?void 0:t.printState)!=="OFF":!0}_setVisible(t,e,s=!1){t!==So&&Et("Internal method `_setVisible` called."),m(this,Jl,s),m(this,zo,e)}}ql=new WeakMap,Kl=new WeakMap,Jl=new WeakMap,zo=new WeakMap;class YS{constructor(t,e=fs.DISPLAY){v(this,Ql);v(this,ur,null);v(this,St,new Map);v(this,Go,null);v(this,Xo,null);if(this.renderingIntent=e,this.name=null,this.creator=null,t!==null){this.name=t.name,this.creator=t.creator,m(this,Xo,t.order);for(const s of t.groups)l(this,St).set(s.id,new US(e,s));if(t.baseState==="OFF")for(const s of l(this,St).values())s._setVisible(So,!1);for(const s of t.on)l(this,St).get(s)._setVisible(So,!0);for(const s of t.off)l(this,St).get(s)._setVisible(So,!1);m(this,Go,this.getHash())}}isVisible(t){if(l(this,St).size===0)return!0;if(!t)return ld("Optional content group not defined."),!0;if(t.type==="OCG")return l(this,St).has(t.id)?l(this,St).get(t.id).visible:(rt(`Optional content group not found: ${t.id}`),!0);if(t.type==="OCMD"){if(t.expression)return w(this,Ql,Wp).call(this,t.expression);if(!t.policy||t.policy==="AnyOn"){for(const e of t.ids){if(!l(this,St).has(e))return rt(`Optional content group not found: ${e}`),!0;if(l(this,St).get(e).visible)return!0}return!1}else if(t.policy==="AllOn"){for(const e of t.ids){if(!l(this,St).has(e))return rt(`Optional content group not found: ${e}`),!0;if(!l(this,St).get(e).visible)return!1}return!0}else if(t.policy==="AnyOff"){for(const e of t.ids){if(!l(this,St).has(e))return rt(`Optional content group not found: ${e}`),!0;if(!l(this,St).get(e).visible)return!0}return!1}else if(t.policy==="AllOff"){for(const e of t.ids){if(!l(this,St).has(e))return rt(`Optional content group not found: ${e}`),!0;if(l(this,St).get(e).visible)return!1}return!0}return rt(`Unknown optional content policy ${t.policy}.`),!0}return rt(`Unknown group type ${t.type}.`),!0}setVisibility(t,e=!0,s=!0){var n;const i=l(this,St).get(t);if(!i){rt(`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,St).get(a))==null||n._setVisible(So,!1,!0));i._setVisible(So,!!e,!0),m(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,St).get(i);if(n)switch(s){case"ON":this.setVisibility(i,!0,e);break;case"OFF":this.setVisibility(i,!1,e);break;case"Toggle":this.setVisibility(i,!n.visible,e);break}}m(this,ur,null)}get hasInitialVisibility(){return l(this,Go)===null||this.getHash()===l(this,Go)}getOrder(){return l(this,St).size?l(this,Xo)?l(this,Xo).slice():[...l(this,St).keys()]:null}getGroups(){return l(this,St).size>0?Pg(l(this,St)):null}getGroup(t){return l(this,St).get(t)||null}getHash(){if(l(this,ur)!==null)return l(this,ur);const t=new Oy;for(const[e,s]of l(this,St))t.update(`${e}:${s.visible}`);return m(this,ur,t.hexdigest())}}ur=new WeakMap,St=new WeakMap,Go=new WeakMap,Xo=new WeakMap,Ql=new WeakSet,Wp=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,Ql,Wp).call(this,n);else if(l(this,St).has(n))r=l(this,St).get(n).visible;else return rt(`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 $S{constructor(t,{disableRange:e=!1,disableStream:s=!1}){ee(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)});ee(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(){ee(!this._fullRequestReader,"PDFDataTransportStream.getFullReader can only be called once.");const t=this._queuedChunks;return this._queuedChunks=null,new qS(this,t,this._progressiveDone,this._contentDispositionFilename)}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new KS(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 qS{constructor(t,e,s=!1,i=null){this._stream=t,this._done=s||!1,this._filename=Lg(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 KS{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 JS(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=ud(d);d=f.decode(g),t=!1}catch{}}return d}function n(u){return t&&/[\x80-\xff]/.test(u)&&(u=i("utf-8",u),t&&(u=i("iso-8859-1",u))),u}function r(u){const d=[];let f;const g=s("filename\\*((?!0\\d)\\d+)(\\*?)","ig");for(;(f=g.exec(u))!==null;){let[,b,_,y]=f;if(b=parseInt(b,10),b in d){if(b===0)break;continue}d[b]=[_,y]}const p=[];for(let b=0;b<d.length&&b in d;++b){let[_,y]=d[b];y=a(y),_&&(y=unescape(y),b===0&&(y=h(y))),p.push(y)}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(b,_){return String.fromCharCode(parseInt(_,16))}),i(f,p);try{p=atob(p)}catch{}return i(f,p)})}return""}function Jy(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 _d(o){try{return new URL(o).origin}catch{}return null}function Qy({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 Zy(o){const t=o.get("Content-Disposition");if(t){let e=JS(t);if(e.includes("%"))try{e=decodeURIComponent(e)}catch{}if(Lg(e))return e}return null}function wd(o,t){return o===404||o===0&&t.startsWith("file:")?new ol('Missing PDF "'+t+'".'):new cd(`Unexpected server response (${o}) while retrieving PDF "${t}".`,o)}function t0(o){return o===200||o===206}function e0(o,t,e){return{method:"GET",headers:o,signal:e.signal,mode:"cors",credentials:t?"include":"same-origin",redirect:"follow"}}function s0(o){return o instanceof Uint8Array?o.buffer:o instanceof ArrayBuffer?o:(rt(`getArrayBuffer - unexpected data format: ${o}`),new Uint8Array(o).buffer)}class i0{constructor(t){J(this,"_responseOrigin",null);this.source=t,this.isHttp=/^https?:/i.test(t.url),this.headers=Jy(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 ee(!this._fullRequestReader,"PDFFetchStream.getFullReader can only be called once."),this._fullRequestReader=new QS(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new ZS(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 QS{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,e0(s,this._withCredentials,this._abortController)).then(n=>{if(t._responseOrigin=_d(n.url),!t0(n.status))throw wd(n.status,i);this._reader=n.body.getReader(),this._headersCapability.resolve();const r=n.headers,{allowRangeRequests:a,suggestedLength:h}=Qy({responseHeaders:r,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=a,this._contentLength=h||this._contentLength,this._filename=Zy(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:s0(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}class ZS{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,e0(n,this._withCredentials,this._abortController)).then(a=>{const h=_d(a.url);if(h!==t._responseOrigin)throw new Error(`Expected range response-origin "${h}" to match "${t._responseOrigin}".`);if(!t0(a.status))throw wd(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:s0(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}const Yg=200,$g=206;function tC(o){const t=o.response;return typeof t!="string"?t:ud(t).buffer}class eC{constructor({url:t,httpHeaders:e,withCredentials:s}){J(this,"_responseOrigin",null);this.url=t,this.isHttp=/^https?:/i.test(t),this.headers=Jy(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=$g):i.expectedStatus=Yg,e.responseType="arraybuffer",ee(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||Yg;if(!(n===Yg&&s.expectedStatus===$g)&&n!==s.expectedStatus){s.onError(i.status);return}const a=tC(i);if(n===$g){const h=i.getResponseHeader("Content-Range"),c=/bytes (\d+)-(\d+)\/(\d+)/.exec(h);c?s.onDone({begin:parseInt(c[1],10),chunk:a}):(rt('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 sC{constructor(t){this._source=t,this._manager=new eC(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 ee(!this._fullRequestReader,"PDFNetworkStream.getFullReader can only be called once."),this._fullRequestReader=new iC(this._manager,this._source),this._fullRequestReader}getRangeReader(t,e){const s=new nC(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 iC{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=_d(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}=Qy({responseHeaders:i,isHttp:this._manager.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});n&&(this._isRangeSupported=!0),this._contentLength=r||this._contentLength,this._filename=Zy(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=wd(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 nC{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=_d((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=wd(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 rC=/^[a-z][a-z0-9\-+.]+:/i;function aC(o){if(rC.test(o))return new URL(o);const t=process.getBuiltinModule("url");return new URL(t.pathToFileURL(o))}class oC{constructor(t){this.source=t,this.url=aC(t.url),ee(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 ee(!this._fullRequestReader,"PDFNodeStream.getFullReader can only be called once."),this._fullRequestReader=new hC(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new lC(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 hC{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 ol(`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 lC{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 cC=1e5,rs=30,uC=.8,le=class le{constructor({textContentSource:t,container:e,viewport:s}){v(this,vn);v(this,dr,Promise.withResolvers());v(this,os,null);v(this,Zl,!1);v(this,tc,!!((y0=globalThis.FontInspector)!=null&&y0.enabled));v(this,va,null);v(this,yn,null);v(this,ec,0);v(this,sc,0);v(this,_a,null);v(this,Uo,null);v(this,Yo,0);v(this,fr,0);v(this,$o,Object.create(null));v(this,ic,[]);v(this,qo,null);v(this,wa,[]);v(this,nc,new WeakMap);v(this,rc,null);var h;if(t instanceof ReadableStream)m(this,qo,t);else if(typeof t=="object")m(this,qo,new ReadableStream({start(c){c.enqueue(t),c.close()}}));else throw new Error('No "textContentSource" parameter specified.');m(this,os,m(this,Uo,e)),m(this,fr,s.scale*(globalThis.devicePixelRatio||1)),m(this,Yo,s.rotation),m(this,yn,{div:null,properties:null,ctx:null});const{pageWidth:i,pageHeight:n,pageX:r,pageY:a}=s.rawDims;m(this,rc,[1,0,0,-1,-r,a+n]),m(this,sc,i),m(this,ec,n),w(h=le,ys,bv).call(h),Gr(e,s),l(this,dr).promise.finally(()=>{l(le,Ko).delete(this),m(this,yn,null),m(this,$o,null)}).catch(()=>{})}static get fontFamilyMap(){const{isWindows:t,isFirefox:e}=Ge.platform;return ht(this,"fontFamilyMap",new Map([["sans-serif",`${t&&e?"Calibri, ":""}sans-serif`],["monospace",`${t&&e?"Lucida Console, ":""}monospace`]]))}render(){const t=()=>{l(this,_a).read().then(({value:e,done:s})=>{if(s){l(this,dr).resolve();return}l(this,va)??m(this,va,e.lang),Object.assign(l(this,$o),e.styles),w(this,vn,pv).call(this,e.items),t()},l(this,dr).reject)};return m(this,_a,l(this,qo).getReader()),l(le,Ko).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,Yo)&&(e==null||e(),m(this,Yo,i),Gr(l(this,Uo),{rotation:i})),s!==l(this,fr)){e==null||e(),m(this,fr,s);const r={div:null,properties:null,ctx:w(n=le,ys,af).call(n,l(this,va))};for(const a of l(this,wa))r.properties=l(this,nc).get(a),r.div=a,w(this,vn,zp).call(this,r)}}cancel(){var e;const t=new qn("TextLayer task cancelled.");(e=l(this,_a))==null||e.cancel(t).catch(()=>{}),m(this,_a,null),l(this,dr).reject(t)}get textDivs(){return l(this,wa)}get textContentItemsStr(){return l(this,ic)}static cleanup(){if(!(l(this,Ko).size>0)){l(this,xa).clear();for(const{canvas:t}of l(this,Sa).values())t.remove();l(this,Sa).clear()}}};dr=new WeakMap,os=new WeakMap,Zl=new WeakMap,tc=new WeakMap,va=new WeakMap,yn=new WeakMap,ec=new WeakMap,sc=new WeakMap,_a=new WeakMap,Uo=new WeakMap,Yo=new WeakMap,fr=new WeakMap,$o=new WeakMap,ic=new WeakMap,qo=new WeakMap,wa=new WeakMap,nc=new WeakMap,rc=new WeakMap,xa=new WeakMap,Sa=new WeakMap,ac=new WeakMap,gr=new WeakMap,Ko=new WeakMap,vn=new WeakSet,pv=function(t){var i,n;if(l(this,Zl))return;(n=l(this,yn)).ctx??(n.ctx=w(i=le,ys,af).call(i,l(this,va)));const e=l(this,wa),s=l(this,ic);for(const r of t){if(e.length>cC){rt("Ignoring additional textDivs for performance reasons."),m(this,Zl,!0);return}if(r.str===void 0){if(r.type==="beginMarkedContentProps"||r.type==="beginMarkedContent"){const a=l(this,os);m(this,os,document.createElement("span")),l(this,os).classList.add("markedContent"),r.id!==null&&l(this,os).setAttribute("id",`${r.id}`),a.append(l(this,os))}else r.type==="endMarkedContent"&&m(this,os,l(this,os).parentNode);continue}s.push(r.str),w(this,vn,mv).call(this,r)}},mv=function(t){var b;const e=document.createElement("span"),s={angle:0,canvasWidth:0,hasText:t.str!=="",hasEOL:t.hasEOL,fontSize:0};l(this,wa).push(e);const i=q.transform(l(this,rc),t.transform);let n=Math.atan2(i[1],i[0]);const r=l(this,$o)[t.fontName];r.vertical&&(n+=Math.PI/2);let a=l(this,tc)&&r.fontSubstitution||r.fontFamily;a=le.fontFamilyMap.get(a)||a;const h=Math.hypot(i[2],i[3]),c=h*w(b=le,ys,yv).call(b,a,l(this,va));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,os)===l(this,Uo)?(g.left=`${(100*u/l(this,sc)).toFixed(2)}%`,g.top=`${(100*d/l(this,ec)).toFixed(2)}%`):(g.left=`${f}${u.toFixed(2)}px)`,g.top=`${f}${d.toFixed(2)}px)`),g.fontSize=`${f}${(l(le,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,tc)&&(e.dataset.fontName=r.fontSubstitutionLoadedName||t.fontName),n!==0&&(s.angle=n*(180/Math.PI));let p=!1;if(t.str.length>1)p=!0;else if(t.str!==" "&&t.transform[0]!==t.transform[3]){const _=Math.abs(t.transform[0]),y=Math.abs(t.transform[3]);_!==y&&Math.max(_,y)/Math.min(_,y)>1.5&&(p=!0)}if(p&&(s.canvasWidth=r.vertical?t.height:t.width),l(this,nc).set(e,s),l(this,yn).div=e,l(this,yn).properties=s,w(this,vn,zp).call(this,l(this,yn)),s.hasText&&l(this,os).append(e),s.hasEOL){const _=document.createElement("br");_.setAttribute("role","presentation"),l(this,os).append(_)}},zp=function(t){var a;const{div:e,properties:s,ctx:i}=t,{style:n}=e;let r="";if(l(le,gr)>1&&(r=`scale(${1/l(le,gr)})`),s.canvasWidth!==0&&s.hasText){const{fontFamily:h}=n,{canvasWidth:c,fontSize:u}=s;w(a=le,ys,Gp).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)},ys=new WeakSet,af=function(t=null){let e=l(this,Sa).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,Sa).set(t,e),l(this,ac).set(e,{size:0,family:""})}return e},Gp=function(t,e,s){const i=l(this,ac).get(t);e===i.size&&s===i.family||(t.font=`${e}px ${s}`,i.size=e,i.family=s)},bv=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),m(this,gr,t.getBoundingClientRect().height),t.remove()},yv=function(t,e){const s=l(this,xa).get(t);if(s)return s;const i=w(this,ys,af).call(this,e);i.canvas.width=i.canvas.height=rs,w(this,ys,Gp).call(this,i,rs,t);const n=i.measureText("");let r=n.fontBoundingBoxAscent,a=Math.abs(n.fontBoundingBoxDescent);if(r){const u=r/(r+a);return l(this,xa).set(t,u),i.canvas.width=i.canvas.height=0,u}i.strokeStyle="red",i.clearRect(0,0,rs,rs),i.strokeText("g",0,0);let h=i.getImageData(0,0,rs,rs).data;a=0;for(let u=h.length-1-3;u>=0;u-=4)if(h[u]>0){a=Math.ceil(u/4/rs);break}i.clearRect(0,0,rs,rs),i.strokeText("A",0,rs),h=i.getImageData(0,0,rs,rs).data,r=0;for(let u=0,d=h.length;u<d;u+=4)if(h[u]>0){r=rs-Math.floor(u/4/rs);break}i.canvas.width=i.canvas.height=0;const c=r?r/(r+a):uC;return l(this,xa).set(t,c),c},v(le,ys),v(le,xa,new Map),v(le,Sa,new Map),v(le,ac,new WeakMap),v(le,gr,null),v(le,Ko,new Set);let fl=le;class gl{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(gl.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 dC=65536,fC=100,gC=5e3,pC=Pe?PS:TS,mC=Pe?MS:Iy,bC=Pe?kS:ES,yC=Pe?OS:By;function vC(o={}){typeof o=="string"||o instanceof URL?o={url:o}:(o instanceof ArrayBuffer||ArrayBuffer.isView(o))&&(o={data:o});const t=new qg,{docId:e}=t,s=o.url?_C(o.url):null,i=o.data?wC(o.data):null,n=o.httpHeaders||null,r=o.withCredentials===!0,a=o.password??null,h=o.range instanceof r0?o.range:null,c=Number.isInteger(o.rangeChunkSize)&&o.rangeChunkSize>0?o.rangeChunkSize:dC;let u=o.worker instanceof Co?o.worker:null;const d=o.verbosity,f=typeof o.docBaseUrl=="string"&&!fd(o.docBaseUrl)?o.docBaseUrl:null,g=typeof o.cMapUrl=="string"?o.cMapUrl:null,p=o.cMapPacked!==!1,b=o.CMapReaderFactory||mC,_=typeof o.standardFontDataUrl=="string"?o.standardFontDataUrl:null,y=o.StandardFontDataFactory||yC,x=o.stopAtErrors!==!0,C=Number.isInteger(o.maxImageSize)&&o.maxImageSize>-1?o.maxImageSize:-1,A=o.isEvalSupported!==!1,P=typeof o.isOffscreenCanvasSupported=="boolean"?o.isOffscreenCanvasSupported:!Pe,D=typeof o.isImageDecoderSupported=="boolean"?o.isImageDecoderSupported:!Pe&&(Ge.platform.isFirefox||!globalThis.chrome),k=Number.isInteger(o.canvasMaxAreaInBytes)?o.canvasMaxAreaInBytes:-1,M=typeof o.disableFontFace=="boolean"?o.disableFontFace:Pe,R=o.fontExtraProperties===!0,F=o.enableXfa===!0,I=o.ownerDocument||globalThis.document,Y=o.disableRange===!0,N=o.disableStream===!0,H=o.disableAutoFetch===!0,at=o.pdfBug===!0,j=o.CanvasFactory||pC,z=o.FilterFactory||bC,it=o.enableHWA===!0,kt=h?h.length:o.length??NaN,Ut=typeof o.useSystemFonts=="boolean"?o.useSystemFonts:!Pe&&!M,ne=typeof o.useWorkerFetch=="boolean"?o.useWorkerFetch:b===Iy&&y===By&&g&&_&&ll(g,document.baseURI)&&ll(_,document.baseURI),zt=null;nS(d);const Tt={canvasFactory:new j({ownerDocument:I,enableHWA:it}),filterFactory:new z({docId:e,ownerDocument:I}),cMapReaderFactory:ne?null:new b({baseUrl:g,isCompressed:p}),standardFontDataFactory:ne?null:new y({baseUrl:_})};if(!u){const Dt={verbosity:d,port:rn.workerPort};u=Dt.port?Co.fromPort(Dt):new Co(Dt),t._worker=u}const Ce={docId:e,apiVersion:"4.10.38",data:i,password:a,disableAutoFetch:H,rangeChunkSize:c,length:kt,docBaseUrl:f,enableXfa:F,evaluatorOptions:{maxImageSize:C,disableFontFace:M,ignoreErrors:x,isEvalSupported:A,isOffscreenCanvasSupported:P,isImageDecoderSupported:D,canvasMaxAreaInBytes:k,fontExtraProperties:R,useSystemFonts:Ut,cMapUrl:ne?g:null,standardFontDataUrl:ne?_:null}},Xs={disableFontFace:M,fontExtraProperties:R,ownerDocument:I,pdfBug:at,styleElement:zt,loadingParams:{disableAutoFetch:H,enableXfa:F}};return u.promise.then(function(){if(t.destroyed)throw new Error("Loading aborted");if(u.destroyed)throw new Error("Worker was destroyed");const Dt=u.messageHandler.sendWithPromise("GetDocRequest",Ce,i?[i.buffer]:null);let ft;if(h)ft=new $S(h,{disableRange:Y,disableStream:N});else if(!i){if(!s)throw new Error("getDocument - no `url` parameter provided.");let Ps;if(Pe)if(ll(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`.");Ps=i0}else Ps=oC;else Ps=ll(s)?i0:sC;ft=new Ps({url:s,length:kt,httpHeaders:n,withCredentials:r,rangeChunkSize:c,disableRange:Y,disableStream:N})}return Dt.then(Ps=>{if(t.destroyed)throw new Error("Loading aborted");if(u.destroyed)throw new Error("Worker was destroyed");const Xi=new ul(e,Ps,u.port),Je=new AC(Xi,t,ft,Xs,Tt);t._transport=Je,Xi.send("Ready",null)})}).catch(t._capability.reject),t}function _C(o){if(o instanceof URL)return o.href;try{return new URL(o,window.location).href}catch{if(Pe&&typeof o=="string")return o}throw new Error("Invalid PDF url data: either string or URL-object is expected in the url property.")}function wC(o){if(Pe&&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 ud(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 n0(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 Id=class Id{constructor(){this._capability=Promise.withResolvers(),this._transport=null,this._worker=null,this.docId=`d${Ze(Id,Fd)._++}`,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}};Fd=new WeakMap,v(Id,Fd,0);let qg=Id;class r0{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){Et("Abstract method PDFDataRangeTransport.requestDataRange")}abort(){}}class xC{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 ht(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 SC{constructor(t,e,s,i=!1){v(this,Bs);v(this,pr,null);v(this,_n,!1);this._pageIndex=t,this._pageInfo=e,this._transport=s,this._stats=i?new Py:null,this._pdfBug=i,this.commonObjs=s.commonObjs,this.objs=new a0,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 hl({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 ht(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 A,P;(A=this._stats)==null||A.time("Overall");const f=this._transport.getRenderingIntent(s,i,u,d),{renderingIntent:g,cacheKey:p}=f;m(this,_n,!1),w(this,Bs,of).call(this),a||(a=this._transport.getOptionalContentConfig(g));let b=this._intentStates.get(p);b||(b=Object.create(null),this._intentStates.set(p,b)),b.streamReaderCancelTimeout&&(clearTimeout(b.streamReaderCancelTimeout),b.streamReaderCancelTimeout=null);const _=!!(g&fs.PRINT);b.displayReadyCapability||(b.displayReadyCapability=Promise.withResolvers(),b.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(P=this._stats)==null||P.time("Page Request"),this._pumpOperatorList(f));const y=D=>{var k;b.renderTasks.delete(x),(this._maybeCleanupAfterRender||_)&&m(this,_n,!0),w(this,Bs,jh).call(this,!_),D?(x.capability.reject(D),this._abortOperatorList({intentState:b,reason:D instanceof Error?D:new Error(D)})):x.capability.resolve(),this._stats&&(this._stats.timeEnd("Rendering"),this._stats.timeEnd("Overall"),(k=globalThis.Stats)!=null&&k.enabled&&globalThis.Stats.add(this.pageNumber,this._stats))},x=new Kg({callback:y,params:{canvasContext:t,viewport:e,transform:n,background:r},objs:this.objs,commonObjs:this.commonObjs,annotationCanvasMap:h,operatorList:b.operatorList,pageIndex:this._pageIndex,canvasFactory:this._transport.canvasFactory,filterFactory:this._transport.filterFactory,useRequestAnimationFrame:!_,pdfBug:this._pdfBug,pageColors:c});(b.renderTasks||(b.renderTasks=new Set)).add(x);const C=x.task;return Promise.all([b.displayReadyCapability.promise,a]).then(([D,k])=>{var M;if(this.destroyed){y();return}if((M=this._stats)==null||M.time("Rendering"),!(k.renderingIntent&g))throw new Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");x.initializeGraphics({transparency:D,optionalContentConfig:k}),x.operatorListChanged()}).catch(y),C}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=>gl.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(),m(this,_n,!1),w(this,Bs,of).call(this),Promise.all(t)}cleanup(t=!1){m(this,_n,!0);const e=w(this,Bs,jh).call(this,!1);return t&&e&&this._stats&&(this._stats=new Py),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,Bs,jh).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,Bs,jh).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 Rg){let i=fC;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,_n=new WeakMap,Bs=new WeakSet,jh=function(t=!1){if(w(this,Bs,of).call(this),!l(this,_n)||this.destroyed)return!1;if(t)return m(this,pr,setTimeout(()=>{m(this,pr,null),w(this,Bs,jh).call(this,!1)},gC)),!1;for(const{renderTasks:e,operatorList:s}of this._intentStates.values())if(e.size>0||!s.lastChunk)return!1;return this._intentStates.clear(),this.objs.clear(),m(this,_n,!1),!0},of=function(){l(this,pr)&&(clearTimeout(l(this,pr)),m(this,pr,null))};class CC{constructor(){v(this,wn,new Map);v(this,jd,Promise.resolve())}postMessage(t,e){const s={data:structuredClone(t,e?{transfer:e}:null)};l(this,jd).then(()=>{for(const[i]of l(this,wn))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){rt("LoopbackPort - cannot use an `aborted` signal.");return}const r=()=>this.removeEventListener(t,e);i=()=>n.removeEventListener("abort",r),n.addEventListener("abort",r)}l(this,wn).set(e,i)}removeEventListener(t,e){const s=l(this,wn).get(e);s==null||s(),l(this,wn).delete(e)}terminate(){for(const[,t]of l(this,wn))t==null||t();l(this,wn).clear()}}wn=new WeakMap,jd=new WeakMap;const jt=class jt{constructor({name:t=null,port:e=null,verbosity:s=rS()}={}){v(this,Jo);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,Aa))!=null&&i.has(e))throw new Error("Cannot use more than one PDFWorker per port.");(l(jt,Aa)||m(jt,Aa,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 ul("main","worker",t),this._messageHandler.on("ready",function(){}),w(this,Jo,hf).call(this)}_initialize(){if(l(jt,Ca)||l(jt,Qo,lf)){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 ul("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,Jo,hf).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{ld("The worker has been disabled.")}this._setupFakeWorker()}_setupFakeWorker(){l(jt,Ca)||(rt("Setting up fake worker."),m(jt,Ca,!0)),jt._setupFakeWorkerGlobal.then(t=>{if(this.destroyed){this._readyCapability.reject(new Error("Worker was destroyed"));return}const e=new CC;this._port=e;const s=`fake${Ze(jt,Nd)._++}`,i=new ul(s+"_worker",s,e);t.setup(i,e),this._messageHandler=new ul(s,s+"_worker",e),w(this,Jo,hf).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,Aa))==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,Aa))==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(rn.workerSrc)return rn.workerSrc;throw new Error('No "GlobalWorkerOptions.workerSrc" specified.')}static get _setupFakeWorkerGlobal(){return ht(this,"_setupFakeWorkerGlobal",(async()=>l(this,Qo,lf)?l(this,Qo,lf):(await import(this.workerSrc)).WorkerMessageHandler)())}};Nd=new WeakMap,Ca=new WeakMap,Aa=new WeakMap,Jo=new WeakSet,hf=function(){this._readyCapability.resolve(),this._messageHandler.send("configure",{verbosity:this.verbosity})},Qo=new WeakSet,lf=function(){var t;try{return((t=globalThis.pdfjsWorker)==null?void 0:t.WorkerMessageHandler)||null}catch{return null}},v(jt,Qo),v(jt,Nd,0),v(jt,Ca,!1),v(jt,Aa),Pe&&(m(jt,Ca,!0),rn.workerSrc||(rn.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 Co=jt;class AC{constructor(t,e,s,i,n){v(this,Ta);v(this,xn,new Map);v(this,Ii,new Map);v(this,Zo,new Map);v(this,th,new Map);v(this,Sn,null);this.messageHandler=t,this.loadingTask=e,this.commonObjs=new a0,this.fontLoader=new CS({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 ht(this,"annotationStorage",new Wg)}getRenderingIntent(t,e=Yn.ENABLE,s=null,i=!1,n=!1){let r=fs.DISPLAY,a=Vg;switch(t){case"any":r=fs.ANY;break;case"display":break;case"print":r=fs.PRINT;break;default:rt(`getRenderingIntent - invalid intent: ${t}`)}const h=r&fs.PRINT&&s instanceof Dy?s:this.annotationStorage;switch(e){case Yn.DISABLE:r+=fs.ANNOTATIONS_DISABLE;break;case Yn.ENABLE:break;case Yn.ENABLE_FORMS:r+=fs.ANNOTATIONS_FORMS;break;case Yn.ENABLE_STORAGE:r+=fs.ANNOTATIONS_STORAGE,a=h.serializable;break;default:rt(`getRenderingIntent - invalid annotationMode: ${e}`)}i&&(r+=fs.IS_EDITING),n&&(r+=fs.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,Sn))==null||s.reject(new Error("Worker was destroyed during onPassword callback"));const t=[];for(const i of l(this,Ii).values())t.push(i._destroy());l(this,Ii).clear(),l(this,Zo).clear(),l(this,th).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,xn).clear(),this.filterFactory.destroy(),fl.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)=>{ee(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}ee(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)=>{ee(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}ee(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 xC(s,this))}),t.on("DocException",s=>{e._capability.reject(is(s))}),t.on("PasswordRequest",s=>{m(this,Sn,Promise.withResolvers());try{if(!e.onPassword)throw is(s);const i=n=>{n instanceof Error?l(this,Sn).reject(n):l(this,Sn).resolve({password:n})};e.onPassword(i,s.code)}catch(i){l(this,Sn).reject(i)}return l(this,Sn).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,Ii).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;rt(`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 AS(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;ee(f,"The imageRef must be defined.");for(const g of l(this,Ii).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,Ii).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)>tS&&(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&&rt("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,Zo).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,th).set(n.refStr,t);const r=new SC(e,n,this,this._params.pdfBug);return l(this,Ii).set(e,r),r});return l(this,Zo).set(e,i),i}getPageIndex(t){return n0(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,Ta,Qc).call(this,"GetFieldObjects")}hasJSActions(){return w(this,Ta,Qc).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,Ta,Qc).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,Ta,Qc).call(this,"GetOptionalContentConfig").then(e=>new YS(e,t))}getPermissions(){return this.messageHandler.sendWithPromise("GetPermissions",null)}getMetadata(){const t="GetMetadata",e=l(this,xn).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 XS(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,xn).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,Ii).values())if(!e.cleanup())throw new Error(`startCleanup: Page ${e.pageNumber} is currently rendering.`);this.commonObjs.clear(),t||this.fontLoader.clear(),l(this,xn).clear(),this.filterFactory.destroy(!0),fl.cleanup()}}cachedPageNumber(t){if(!n0(t))return null;const e=t.gen===0?`${t.num}R`:`${t.num}R${t.gen}`;return l(this,th).get(e)??null}}xn=new WeakMap,Ii=new WeakMap,Zo=new WeakMap,th=new WeakMap,Sn=new WeakMap,Ta=new WeakSet,Qc=function(t,e=null){const s=l(this,xn).get(t);if(s)return s;const i=this.messageHandler.sendWithPromise(t,e);return l(this,xn).set(t,i),i};const pl=Symbol("INITIAL_DATA");class a0{constructor(){v(this,oc);v(this,vs,Object.create(null))}get(t,e=null){if(e){const i=w(this,oc,Xp).call(this,t);return i.promise.then(()=>e(i.data)),null}const s=l(this,vs)[t];if(!s||s.data===pl)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return s.data}has(t){const e=l(this,vs)[t];return!!e&&e.data!==pl}delete(t){const e=l(this,vs)[t];return!e||e.data===pl?!1:(delete l(this,vs)[t],!0)}resolve(t,e=null){const s=w(this,oc,Xp).call(this,t);s.data=e,s.resolve()}clear(){var t;for(const e in l(this,vs)){const{data:s}=l(this,vs)[e];(t=s==null?void 0:s.bitmap)==null||t.close()}m(this,vs,Object.create(null))}*[Symbol.iterator](){for(const t in l(this,vs)){const{data:e}=l(this,vs)[t];e!==pl&&(yield[t,e])}}}vs=new WeakMap,oc=new WeakSet,Xp=function(t){var e;return(e=l(this,vs))[t]||(e[t]={...Promise.withResolvers(),data:pl})};class TC{constructor(t){v(this,mr,null);m(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 ka=class ka{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}){v(this,br,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 TC(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(ka,Ea).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(ka,Ea).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 xo(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,br)&&(window.cancelAnimationFrame(l(this,br)),m(this,br,null)),l(ka,Ea).delete(this._canvas),this.callback(t||new Rg(`Rendering cancelled, page ${this._pageIndex+1}`,e))}operatorListChanged(){var t;if(!this.graphicsReady){this.graphicsReadyCallback||(this.graphicsReadyCallback=this._continueBound);return}(t=this.stepper)==null||t.updateOperatorList(this.operatorList),!this.running&&this._continue()}_continue(){this.running=!0,!this.cancelled&&(this.task.onContinue?this.task.onContinue(this._scheduleNextBound):this._scheduleNext())}_scheduleNext(){this._useRequestAnimationFrame?m(this,br,window.requestAnimationFrame(()=>{m(this,br,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(ka,Ea).delete(this._canvas),this.callback())))}};br=new WeakMap,Ea=new WeakMap,v(ka,Ea,new WeakSet);let Kg=ka;const EC="4.10.38",kC="f9bea397f";function o0(o){return Math.floor(Math.max(0,Math.min(1,o))*255).toString(16).padStart(2,"0")}function ml(o){return Math.max(0,Math.min(255,255*o))}class h0{static CMYK_G([t,e,s,i]){return["G",1-Math.min(1,.3*t+.59*s+.11*e+i)]}static G_CMYK([t]){return["CMYK",0,0,0,1-t]}static G_RGB([t]){return["RGB",t,t,t]}static G_rgb([t]){return t=ml(t),[t,t,t]}static G_HTML([t]){const e=o0(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(ml)}static RGB_HTML(t){return`#${t.map(o0).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[ml(1-Math.min(1,t+i)),ml(1-Math.min(1,s+i)),ml(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 PC{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){Et("Abstract method `_createSVG` called.")}}class Jg extends PC{_createSVG(t){return document.createElementNS(nn,t)}}class l0{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&&gl.shouldBuildText(i.name)&&c.push(g)}return{textDivs:c}}const u=[[i,-1,r]];for(;u.length>0;){const[g,p,b]=u.at(-1);if(p+1===g.children.length){u.pop();continue}const _=g.children[++u.at(-1)[1]];if(_===null)continue;const{name:y}=_;if(y==="#text"){const C=document.createTextNode(_.value);c.push(C),b.append(C);continue}const x=(d=_==null?void 0:_.attributes)!=null&&d.xmlns?document.createElementNS(_.attributes.xmlns,y):document.createElement(y);if(b.append(x),_.attributes&&this.setAttributes({html:x,element:_,storage:e,intent:n,linkService:s}),((f=_.children)==null?void 0:f.length)>0)u.push([_,-1,x]);else if(_.value){const C=document.createTextNode(_.value);a&&gl.shouldBuildText(y)&&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 bl=1e3,MC=9,Ur=new WeakSet;function Jn(o){return{width:o[2]-o[0],height:o[3]-o[1]}}class OC{static create(t){switch(t.data.annotationType){case oe.LINK:return new c0(t);case oe.TEXT:return new DC(t);case oe.WIDGET:switch(t.data.fieldType){case"Tx":return new RC(t);case"Btn":return t.data.radioButton?new u0(t):t.data.checkBox?new FC(t):new IC(t);case"Ch":return new jC(t);case"Sig":return new LC(t)}return new Yr(t);case oe.POPUP:return new Qg(t);case oe.FREETEXT:return new d0(t);case oe.LINE:return new BC(t);case oe.SQUARE:return new HC(t);case oe.CIRCLE:return new VC(t);case oe.POLYLINE:return new f0(t);case oe.CARET:return new zC(t);case oe.INK:return new Zg(t);case oe.POLYGON:return new WC(t);case oe.HIGHLIGHT:return new g0(t);case oe.UNDERLINE:return new GC(t);case oe.SQUIGGLY:return new XC(t);case oe.STRIKEOUT:return new UC(t);case oe.STAMP:return new p0(t);case oe.FILEATTACHMENT:return new YC(t);default:return new qt(t)}}}const dp=class dp{constructor(t,{isRenderable:e=!1,ignoreBorder:s=!1,createQuadrilaterals:i=!1}={}){v(this,hc);v(this,Pa,null);v(this,eh,!1);v(this,sh,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 dp._hasPopupData(this.data)}updateEdited(t){var s;if(!this.container)return;l(this,Pa)||m(this,Pa,{rect:this.data.rect.slice(0)});const{rect:e}=t;e&&w(this,hc,Up).call(this,e),(s=l(this,sh))==null||s.popup.updateEdited(t)}resetEdited(){var t;l(this,Pa)&&(w(this,hc,Up).call(this,l(this,Pa).rect),(t=l(this,sh))==null||t.popup.resetEdited(),m(this,Pa,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 Yr||(n.tabIndex=bl);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 Qg){const{rotation:b}=e;return!e.hasOwnCanvas&&b!==0&&this.setRotation(b,n),n}const{width:a,height:h}=Jn(e.rect);if(!t&&e.borderStyle.width>0){r.borderWidth=`${e.borderStyle.width}px`;const b=e.borderStyle.horizontalCornerRadius,_=e.borderStyle.verticalCornerRadius;if(b>0||_>0){const x=`calc(${b}px * var(--scale-factor)) / calc(${_}px * var(--scale-factor))`;r.borderRadius=x}else if(this instanceof u0){const x=`calc(${a}px * var(--scale-factor)) / calc(${h}px * var(--scale-factor))`;r.borderRadius=x}switch(e.borderStyle.style){case al.SOLID:r.borderStyle="solid";break;case al.DASHED:r.borderStyle="dashed";break;case al.BEVELED:rt("Unimplemented border style: beveled");break;case al.INSET:rt("Unimplemented border style: inset");break;case al.UNDERLINE:r.borderBottomStyle="solid";break}const y=e.borderColor||null;y?(m(this,eh,!0),r.borderColor=q.makeHexColor(y[0]|0,y[1]|0,y[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]=h0[`${r}_HTML`](a),this.annotationStorage.setValue(this.data.id,{[s]:h0[`${r}_rgb`](a)})};return ht(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(b=>Math.fround(b));if(t.length===8){const[b,_,y,x]=t.subarray(2,6);if(i===b&&n===_&&e===y&&s===x)return}const{style:r}=this.container;let a;if(l(this,eh)){const{borderColor:b,borderWidth:_}=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="${b}" stroke-width="${_}">`],this.container.classList.add("hasBorder")}const h=i-e,c=n-s,{svgFactory:u}=this,d=u.createElement("svg");d.classList.add("quadrilateralsContainer"),d.setAttribute("width",0),d.setAttribute("height",0);const f=u.createElement("defs");d.append(f);const g=u.createElement("clipPath"),p=`clippath_${this.data.id}`;g.setAttribute("id",p),g.setAttribute("clipPathUnits","objectBoundingBox"),f.append(g);for(let b=2,_=t.length;b<_;b+=8){const y=t[b],x=t[b+1],C=t[b+2],A=t[b+3],P=u.createElement("rect"),D=(C-e)/h,k=(n-x)/c,M=(y-C)/h,R=(x-A)/c;P.setAttribute("x",D),P.setAttribute("y",k),P.setAttribute("width",M),P.setAttribute("height",R),g.append(P),a==null||a.push(`<rect vector-effect="non-scaling-stroke" x="${D}" y="${k}" width="${M}" height="${R}"/>`)}l(this,eh)&&(a.push("</g></svg>')"),r.backgroundImage=a.join("")),this.container.append(d),this.container.style.clipPath=`url(#${p})`}_createPopup(){const{data:t}=this,e=m(this,sh,new Qg({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(){Et("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&&!Ur.has(c)){rt(`_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&&Ur.has(i)&&s.push({id:r,exportValue:n,domElement:i})}return s}show(){var t;this.container&&(this.container.hidden=!1),(t=this.popup)==null||t.maybeShow()}hide(){var t;this.container&&(this.container.hidden=!0),(t=this.popup)==null||t.forceHide()}getElementsToTriggerPopup(){return this.container}addHighlightArea(){const t=this.getElementsToTriggerPopup();if(Array.isArray(t))for(const e of t)e.classList.add("highlightArea");else t.classList.add("highlightArea")}_editOnDoubleClick(){if(!this._isEditable)return;const{annotationEditorType:t,data:{id:e}}=this;this.container.addEventListener("dblclick",()=>{var s;(s=this.linkService.eventBus)==null||s.dispatch("switchannotationeditormode",{source:this,mode:t,editId:e})})}};Pa=new WeakMap,eh=new WeakMap,sh=new WeakMap,hc=new WeakSet,Up=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 qt=dp;class c0 extends qt{constructor(e,s=null){super(e,{isRenderable:!0,ignoreBorder:!!(s!=null&&s.ignoreBorder),createQuadrilaterals:!0});v(this,_s);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,_s,vv).call(this,i,e.attachment,e.attachmentDest),n=!0):e.setOCGState?(w(this,_s,_v).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,_s,so).call(this)}_bindNamedAction(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeNamedAction(s),!1),w(this,_s,so).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,_s,so).call(this)}_bindResetFormAction(e,s){const i=e.onclick;if(i||(e.href=this.linkService.getAnchorUrl("")),w(this,_s,so).call(this),!this._fieldObjects){rt('_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:b}of p)f.add(b)}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 b=f.defaultValue||"";c.setValue(g,{value:b});break}case"checkbox":case"radiobutton":{const b=f.defaultValue===f.exportValues;c.setValue(g,{value:b});break}case"combobox":case"listbox":{const b=f.defaultValue||"";c.setValue(g,{value:b});break}default:continue}const p=document.querySelector(`[data-element-id="${g}"]`);if(p){if(!Ur.has(p)){rt(`_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}}}_s=new WeakSet,so=function(){this.container.setAttribute("data-internal-link","")},vv=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,_s,so).call(this)},_v=function(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeSetOCGState(s),!1),w(this,_s,so).call(this)};class DC extends qt{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 Yr extends qt{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 Ge.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||MC,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/(Tg*i))||1,d=c/u;r=Math.min(i,h(d/Tg))}else{const c=Math.abs(this.data.rect[3]-this.data.rect[1]-a);r=Math.min(i,h(c/Tg))}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 RC extends Yr{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),Ur.add(s),s.setAttribute("data-element-id",e),s.disabled=this.data.readOnly,s.name=this.data.fieldName,s.tabIndex=bl,this._setRequired(s,this.data.required),h&&(s.maxLength=h),s.addEventListener("input",f=>{t.setValue(e,{value:f.target.value}),this.setPropertyOnSiblings(s,"value",f.target.value,"value"),u.formattedValue=null}),s.addEventListener("resetform",f=>{const g=this.data.defaultFieldValue??"";s.value=u.userValue=g,u.formattedValue=null});let d=f=>{const{formattedValue:g}=u;g!=null&&(f.target.value=g),f.target.scrollLeft=0};if(this.enableScripting&&this.hasJSActions){s.addEventListener("focus",g=>{var b;if(u.focused)return;const{target:p}=g;u.userValue&&(p.value=u.userValue),u.lastCommittedValue=p.value,u.commitKey=1,(b=this.data.actions)!=null&&b.Focus||(u.focused=!0)}),s.addEventListener("updatefromsandbox",g=>{this.showElementAndHideCanvas(g.target);const p={value(b){u.userValue=b.detail.value??"",t.setValue(e,{value:u.userValue.toString()}),b.target.value=u.userValue},formattedValue(b){const{formattedValue:_}=b.detail;u.formattedValue=_,_!=null&&b.target!==document.activeElement&&(b.target.value=_),t.setValue(e,{formattedValue:_})},selRange(b){b.target.setSelectionRange(...b.detail.selRange)},charLimit:b=>{var C;const{charLimit:_}=b.detail,{target:y}=b;if(_===0){y.removeAttribute("maxLength");return}y.setAttribute("maxLength",_);let x=u.userValue;!x||x.length<=_||(x=x.slice(0,_),y.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:y.selectionStart,selEnd:y.selectionEnd}}))}};this._dispatchEventFromSandbox(p,g)}),s.addEventListener("keydown",g=>{var _;u.commitKey=1;let p=-1;if(g.key==="Escape"?p=0:g.key==="Enter"&&!this.data.multiLine?p=2:g.key==="Tab"&&(u.commitKey=3),p===-1)return;const{value:b}=g.target;u.lastCommittedValue!==b&&(u.lastCommittedValue=b,u.userValue=b,(_=this.linkService.eventBus)==null||_.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:b,willCommit:!0,commitKey:p,selStart:g.target.selectionStart,selEnd:g.target.selectionEnd}}))});const f=d;d=null,s.addEventListener("blur",g=>{var b,_;if(!u.focused||!g.relatedTarget)return;(b=this.data.actions)!=null&&b.Blur||(u.focused=!1);const{value:p}=g.target;u.userValue=p,u.lastCommittedValue!==p&&((_=this.linkService.eventBus)==null||_.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 P;u.lastCommittedValue=null;const{data:p,target:b}=g,{value:_,selectionStart:y,selectionEnd:x}=b;let C=y,A=x;switch(g.inputType){case"deleteWordBackward":{const D=_.substring(0,y).match(/\w*[^\w]*$/);D&&(C-=D[0].length);break}case"deleteWordForward":{const D=_.substring(y).match(/^[^\w]*\w*/);D&&(A+=D[0].length);break}case"deleteContentBackward":y===x&&(C-=1);break;case"deleteContentForward":y===x&&(A+=1);break}g.preventDefault(),(P=this.linkService.eventBus)==null||P.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:_,change:p||"",willCommit:!1,selStart:C,selEnd:A}})}),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 Yr{constructor(t){super(t,{isRenderable:!!t.data.hasOwnCanvas})}}class FC extends Yr{constructor(t){super(t,{isRenderable:t.renderForms})}render(){const t=this.annotationStorage,e=this.data,s=e.id;let i=t.getValue(s,{value:e.exportValue===e.fieldValue}).value;typeof i=="string"&&(i=i!=="Off",t.setValue(s,{value:i})),this.container.classList.add("buttonWidgetAnnotation","checkBox");const n=document.createElement("input");return Ur.add(n),n.setAttribute("data-element-id",s),n.disabled=e.readOnly,this._setRequired(n,this.data.required),n.type="checkbox",n.name=e.fieldName,i&&n.setAttribute("checked",!0),n.setAttribute("exportValue",e.exportValue),n.tabIndex=bl,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 u0 extends Yr{constructor(t){super(t,{isRenderable:t.renderForms})}render(){this.container.classList.add("buttonWidgetAnnotation","radioButton");const t=this.annotationStorage,e=this.data,s=e.id;let i=t.getValue(s,{value:e.fieldValue===e.buttonValue}).value;if(typeof i=="string"&&(i=i!==e.buttonValue,t.setValue(s,{value:i})),i)for(const r of this._getElementsByName(e.fieldName,s))t.setValue(r.id,{value:!1});const n=document.createElement("input");if(Ur.add(n),n.setAttribute("data-element-id",s),n.disabled=e.readOnly,this._setRequired(n,this.data.required),n.type="radio",n.name=e.fieldName,i&&n.setAttribute("checked",!0),n.tabIndex=bl,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 IC extends c0{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 jC extends Yr{constructor(t){super(t,{isRenderable:t.renderForms})}render(){this.container.classList.add("choiceWidgetAnnotation");const t=this.annotationStorage,e=this.data.id,s=t.getValue(e,{value:this.data.fieldValue}),i=document.createElement("select");Ur.add(i),i.setAttribute("data-element-id",e),i.disabled=this.data.readOnly,this._setRequired(i,this.data.required),i.name=this.data.fieldName,i.tabIndex=bl;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 b of i.options)b.selected=p.has(b.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,_=>_.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:b}=f.detail.insert,_=i.children[g],y=document.createElement("option");y.textContent=p,y.value=b,_?_.before(y):i.append(y),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:b,exportValue:_}=p,y=document.createElement("option");y.textContent=b,y.value=_,i.append(y)}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 Qg extends qt{constructor(t){const{data:e,elements:s}=t;super(t,{isRenderable:qt._hasPopupData(e)}),this.elements=s,this.popup=null}render(){this.container.classList.add("popupAnnotation");const t=this.popup=new NC({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=>`${Dg}${s}`).join(",")),this.container}}class NC{constructor({container:t,color:e,elements:s,titleObj:i,modificationDate:n,contentsObj:r,richText:a,parent:h,rect:c,parentRect:u,open:d}){v(this,Ct);v(this,ih,w(this,Ct,Sv).bind(this));v(this,Bd,w(this,Ct,$p).bind(this));v(this,Hd,w(this,Ct,df).bind(this));v(this,nh,w(this,Ct,uf).bind(this));v(this,Ma,null);v(this,Xt,null);v(this,Cn,null);v(this,rh,null);v(this,lc,null);v(this,cc,null);v(this,ah,null);v(this,An,!1);v(this,ci,null);v(this,Tn,null);v(this,uc,null);v(this,En,null);v(this,dc,null);v(this,Oa,null);v(this,Da,!1);var f;m(this,Xt,t),m(this,dc,i),m(this,Cn,r),m(this,En,a),m(this,cc,h),m(this,Ma,e),m(this,uc,c),m(this,ah,u),m(this,lc,s),m(this,rh,Fg.toDateObject(n)),this.trigger=s.flatMap(g=>g.getElementsToTriggerPopup());for(const g of this.trigger)g.addEventListener("click",l(this,nh)),g.addEventListener("mouseenter",l(this,Hd)),g.addEventListener("mouseleave",l(this,Bd)),g.classList.add("popupTriggerArea");for(const g of s)(f=g.container)==null||f.addEventListener("keydown",l(this,ih));l(this,Xt).hidden=!0,d&&w(this,Ct,uf).call(this)}render(){if(l(this,ci))return;const t=m(this,ci,document.createElement("div"));if(t.className="popup",l(this,Ma)){const n=t.style.outlineColor=q.makeHexColor(...l(this,Ma));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,Ma).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,dc),t.append(e),l(this,rh)){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,rh).valueOf()})),e.append(n)}const i=l(this,Ct,cf);if(i)l0.render({xfaHtml:i,intent:"richText",div:t}),t.lastChild.classList.add("richText","popupContent");else{const n=this._formatContents(l(this,Cn));t.append(n)}l(this,Xt).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,Oa)||m(this,Oa,{contentsObj:l(this,Cn),richText:l(this,En)}),t&&m(this,Tn,null),e&&(m(this,En,w(this,Ct,xv).call(this,e)),m(this,Cn,null)),(s=l(this,ci))==null||s.remove(),m(this,ci,null)}resetEdited(){var t;l(this,Oa)&&({contentsObj:Ze(this,Cn)._,richText:Ze(this,En)._}=l(this,Oa),m(this,Oa,null),(t=l(this,ci))==null||t.remove(),m(this,ci,null),m(this,Tn,null))}forceHide(){m(this,Da,this.isVisible),l(this,Da)&&(l(this,Xt).hidden=!0)}maybeShow(){l(this,Da)&&(l(this,ci)||w(this,Ct,df).call(this),m(this,Da,!1),l(this,Xt).hidden=!1)}get isVisible(){return l(this,Xt).hidden===!1}}ih=new WeakMap,Bd=new WeakMap,Hd=new WeakMap,nh=new WeakMap,Ma=new WeakMap,Xt=new WeakMap,Cn=new WeakMap,rh=new WeakMap,lc=new WeakMap,cc=new WeakMap,ah=new WeakMap,An=new WeakMap,ci=new WeakMap,Tn=new WeakMap,uc=new WeakMap,En=new WeakMap,dc=new WeakMap,Oa=new WeakMap,Da=new WeakMap,Ct=new WeakSet,cf=function(){const t=l(this,En),e=l(this,Cn);return t!=null&&t.str&&(!(e!=null&&e.str)||e.str===t.str)&&l(this,En).html||null},Yp=function(){var t,e,s;return((s=(e=(t=l(this,Ct,cf))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.fontSize)||0},wv=function(){var t,e,s;return((s=(e=(t=l(this,Ct,cf))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.color)||null},xv=function(t){const e=[],s={str:t,html:{name:"div",attributes:{dir:"auto"},children:[{name:"p",children:e}]}},i={style:{color:l(this,Ct,wv),fontSize:l(this,Ct,Yp)?`calc(${l(this,Ct,Yp)}px * var(--scale-factor))`:""}};for(const n of t.split(`
|
|
530
|
+
`))e.push({name:"span",value:n,attributes:i});return s},Sv=function(t){t.altKey||t.shiftKey||t.ctrlKey||t.metaKey||(t.key==="Enter"||t.key==="Escape"&&l(this,An))&&w(this,Ct,uf).call(this)},Cv=function(){if(l(this,Tn)!==null)return;const{page:{view:t},viewport:{rawDims:{pageWidth:e,pageHeight:s,pageX:i,pageY:n}}}=l(this,cc);let r=!!l(this,ah),a=r?l(this,ah):l(this,uc);for(const p of l(this,lc))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];m(this,Tn,[100*(d-i)/e,100*(f-n)/s]);const{style:g}=l(this,Xt);g.left=`${l(this,Tn)[0]}%`,g.top=`${l(this,Tn)[1]}%`},uf=function(){m(this,An,!l(this,An)),l(this,An)?(w(this,Ct,df).call(this),l(this,Xt).addEventListener("click",l(this,nh)),l(this,Xt).addEventListener("keydown",l(this,ih))):(w(this,Ct,$p).call(this),l(this,Xt).removeEventListener("click",l(this,nh)),l(this,Xt).removeEventListener("keydown",l(this,ih)))},df=function(){l(this,ci)||this.render(),this.isVisible?l(this,An)&&l(this,Xt).classList.add("focused"):(w(this,Ct,Cv).call(this),l(this,Xt).hidden=!1,l(this,Xt).style.zIndex=parseInt(l(this,Xt).style.zIndex)+1e3)},$p=function(){l(this,Xt).classList.remove("focused"),!(l(this,An)||!this.isVisible)&&(l(this,Xt).hidden=!0,l(this,Xt).style.zIndex=parseInt(l(this,Xt).style.zIndex)-1e3)};class d0 extends qt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.textContent=t.data.textContent,this.textPosition=t.data.textPosition,this.annotationEditorType=nt.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 BC extends qt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});v(this,fc,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=m(this,fc,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,fc)}addHighlightArea(){this.container.classList.add("highlightArea")}}fc=new WeakMap;class HC extends qt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});v(this,gc,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=m(this,gc,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,gc)}addHighlightArea(){this.container.classList.add("highlightArea")}}gc=new WeakMap;class VC extends qt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});v(this,pc,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=m(this,pc,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,pc)}addHighlightArea(){this.container.classList.add("highlightArea")}}pc=new WeakMap;class f0 extends qt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});v(this,mc,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=m(this,mc,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,mc)}addHighlightArea(){this.container.classList.add("highlightArea")}}mc=new WeakMap;class WC extends f0{constructor(t){super(t),this.containerClassName="polygonAnnotation",this.svgElementName="svg:polygon"}}class zC extends qt{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 Zg extends qt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});v(this,yc);v(this,bc,null);v(this,Ra,[]);this.containerClassName="inkAnnotation",this.svgElementName="svg:polyline",this.annotationEditorType=this.data.it==="InkHighlight"?nt.HIGHLIGHT:nt.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,yc,qp).call(this,s,e),u=this.svgFactory.create(h,c,!0),d=m(this,bc,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,Ra).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,bc);if(s>=0&&r.setAttribute("stroke-width",s||1),i)for(let a=0,h=l(this,Ra).length;a<h;a++)l(this,Ra)[a].setAttribute("points",i[a].join(","));if(n){const{transform:a,width:h,height:c}=w(this,yc,qp).call(this,this.data.rotation,n);r.parentElement.setAttribute("viewBox",`0 0 ${h} ${c}`),r.setAttribute("transform",a)}}getElementsToTriggerPopup(){return l(this,Ra)}addHighlightArea(){this.container.classList.add("highlightArea")}}bc=new WeakMap,Ra=new WeakMap,yc=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 g0 extends qt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0}),this.annotationEditorType=nt.HIGHLIGHT}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("highlightAnnotation"),this._editOnDoubleClick(),this.container}}class GC extends qt{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 XC extends qt{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 UC extends qt{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 p0 extends qt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.annotationEditorType=nt.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 YC extends qt{constructor(e){var i;super(e,{isRenderable:!0});v(this,_c);v(this,vc,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,_c,Kp).bind(this)),m(this,vc,i);const{isMac:n}=Ge.platform;return e.addEventListener("keydown",r=>{r.key==="Enter"&&(n?r.metaKey:r.ctrlKey)&&w(this,_c,Kp).call(this)}),!s.popupRef&&this.hasPopupData?this._createPopup():i.classList.add("popupTriggerArea"),e.append(i),e}getElementsToTriggerPopup(){return l(this,vc)}addHighlightArea(){this.container.classList.add("highlightArea")}}vc=new WeakMap,_c=new WeakSet,Kp=function(){var e;(e=this.downloadManager)==null||e.openOrDownloadData(this.content,this.filename)};class $C{constructor({div:t,accessibilityManager:e,annotationCanvasMap:s,annotationEditorUIManager:i,page:n,viewport:r,structTreeLayer:a}){v(this,Ia);v(this,wc,null);v(this,La,null);v(this,Fa,new Map);v(this,xc,null);this.div=t,m(this,wc,e),m(this,La,s),m(this,xc,a||null),this.page=n,this.viewport=r,this.zIndex=0,this._annotationEditorUIManager=i}hasEditableAnnotations(){return l(this,Fa).size>0}async render(t){var r;const{annotations:e}=t,s=this.div;Gr(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 Jg,annotationStorage:t.annotationStorage||new Wg,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===oe.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=OC.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,Ia,Av).call(this,u,a.id),c._isEditable&&(l(this,Fa).set(c.data.id,c),(r=this._annotationEditorUIManager)==null||r.renderAnnotationElement(c))}w(this,Ia,Jp).call(this)}update({viewport:t}){const e=this.div;this.viewport=t,Gr(e,{rotation:t.rotation}),w(this,Ia,Jp).call(this),e.hidden=!1}getEditableAnnotations(){return Array.from(l(this,Fa).values())}getEditableAnnotation(t){return l(this,Fa).get(t)}}wc=new WeakMap,La=new WeakMap,Fa=new WeakMap,xc=new WeakMap,Ia=new WeakSet,Av=async function(t,e){var r,a;const s=t.firstChild||t,i=s.id=`${Dg}${e}`,n=await((r=l(this,xc))==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,wc))==null||a.moveElementInDOM(this.div,t,s,!1)},Jp=function(){if(!l(this,La))return;const t=this.div;for(const[e,s]of l(this,La)){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,La).clear()};const xd=/\r\n?|\n/g,Ot=class Ot extends Ht{constructor(e){super({...e,name:"freeTextEditor"});v(this,ie);v(this,ui);v(this,ws,"");v(this,Sc,`${this.id}-editor`);v(this,ja,null);v(this,xs);m(this,ui,e.color||Ot._defaultColor||Ht._defaultLineColor),m(this,xs,e.fontSize||Ot._defaultFontSize)}static get _keyboardManager(){const e=Ot.prototype,s=r=>r.isEmpty(),i=Xr.TRANSLATE_SMALL,n=Xr.TRANSLATE_BIG;return ht(this,"_keyboardManager",new cl([[["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){Ht.initialize(e,s);const i=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(i.getPropertyValue("--freetext-padding"))}static updateDefaultParams(e,s){switch(e){case dt.FREETEXT_SIZE:Ot._defaultFontSize=s;break;case dt.FREETEXT_COLOR:Ot._defaultColor=s;break}}updateParams(e,s){switch(e){case dt.FREETEXT_SIZE:w(this,ie,Tv).call(this,s);break;case dt.FREETEXT_COLOR:w(this,ie,Ev).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[dt.FREETEXT_SIZE,Ot._defaultFontSize],[dt.FREETEXT_COLOR,Ot._defaultColor||Ht._defaultLineColor]]}get propertiesToUpdate(){return[[dt.FREETEXT_SIZE,l(this,xs)],[dt.FREETEXT_COLOR,l(this,ui)]]}_translateEmpty(e,s){this._uiManager.translateSelectedEditors(e,s,!0)}getInitialTranslation(){const e=this.parentScale;return[-Ot._internalPadding*e,-(Ot._internalPadding+l(this,xs))*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(nt.FREETEXT),super.enableEditMode(),this.overlayDiv.classList.remove("enabled"),this.editorDiv.contentEditable=!0,this._isDraggable=!1,this.div.removeAttribute("aria-activedescendant"),m(this,ja,new AbortController);const e=this._uiManager.combinedSignal(l(this,ja));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,Sc)),this._isDraggable=!0,(e=l(this,ja))==null||e.abort(),m(this,ja,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,ws),s=m(this,ws,w(this,ie,kv).call(this).trimEnd());if(e===s)return;const i=n=>{if(m(this,ws,n),!n){this.remove();return}w(this,ie,pf).call(this),this._uiManager.rebuild(this),w(this,ie,ff).call(this)};this.addCommands({cmd:()=>{i(s)},undo:()=>{i(e)},mustExec:!1}),w(this,ie,ff).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,Sc)),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,xs)}px * var(--scale-factor))`,i.color=l(this,ui),this.div.append(this.editorDiv),this.overlayDiv=document.createElement("div"),this.overlayDiv.classList.add("overlay","enabled"),this.div.append(this.overlayDiv),gd(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,b;switch(this.rotation){case 0:p=e+(a[0]-f)/u,b=s+this.height-(a[1]-g)/d;break;case 90:p=e+(a[0]-f)/u,b=s-(a[1]-g)/d,[h,c]=[c,-h];break;case 180:p=e-this.width+(a[0]-f)/u,b=s-(a[1]-g)/d,[h,c]=[-h,-c];break;case 270:p=e+(a[0]-f-this.height*d)/u,b=s+(a[1]-g-this.width*u)/d,[h,c]=[-c,h];break}this.setAt(p*n,b*r,h,c)}else this.setAt(e*n,s*r,this.width*n,this.height*r);w(this,ie,pf).call(this),this._isDraggable=!0,this.editorDiv.contentEditable=!1}else this._isDraggable=!1,this.editorDiv.contentEditable=!0;return this.div}editorDivPaste(e){var p,b,_;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,kn,Qp).call(p,s.getData("text")||"").replaceAll(xd,`
|
|
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 y=h.parentElement;if(d.push(h.nodeValue.slice(c).replaceAll(xd,"")),y!==this.editorDiv){let x=u;for(const C of this.editorDiv.childNodes){if(C===y){x=d;continue}x.push(w(b=Ot,kn,gf).call(b,C))}}u.push(h.nodeValue.slice(0,c).replaceAll(xd,""))}else if(h===this.editorDiv){let y=u,x=0;for(const C of this.editorDiv.childNodes)x++===c&&(y=d),y.push(w(_=Ot,kn,gf).call(_,C))}m(this,ws,`${u.join(`
|
|
533
533
|
`)}${n}${d.join(`
|
|
534
|
-
`)}`),
|
|
535
|
-
`),position:
|
|
536
|
-
`)){const
|
|
537
|
-
`)},
|
|
538
|
-
`)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},sy=function(){return l(this,ps).replaceAll(" "," ")},Mp=function(e){return e.replaceAll(" "," ")},iy=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},_(Mt,Cn),q(Mt,"_freeTextDefaultContent",""),q(Mt,"_internalPadding",0),q(Mt,"_defaultColor",null),q(Mt,"_defaultFontSize",10),q(Mt,"_type","freetext"),q(Mt,"_editorType",it.FREETEXT);let Df=Mt;class U{toSVGPath(){St("Abstract method `toSVGPath` must be implemented.")}get box(){St("Abstract getter `box` must be implemented.")}serialize(t,e){St("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 An=class An{constructor({x:t,y:e},s,i,n,r,o=0){_(this,le);_(this,vs);_(this,ci,[]);_(this,Ya);_(this,$a);_(this,Ii,[]);_(this,ot,new Float32Array(18));_(this,Mo);_(this,Oo);_(this,ic);_(this,nc);_(this,qa);_(this,Ka);_(this,fr,[]);v(this,vs,s),v(this,Ka,n*i),v(this,$a,r),l(this,ot).set([NaN,NaN,NaN,NaN,t,e],6),v(this,Ya,o),v(this,nc,l(An,rc)*i),v(this,ic,l(An,xd)*i),v(this,qa,i),l(this,fr).push(t,e)}isEmpty(){return isNaN(l(this,ot)[8])}add({x:t,y:e}){var R;v(this,Mo,t),v(this,Oo,e);const[s,i,n,r]=l(this,vs);let[o,h,c,u]=l(this,ot).subarray(8,12);const d=t-c,g=e-u,f=Math.hypot(d,g);if(f<l(this,ic))return!1;const p=f-l(this,nc),m=p/f,w=m*d,b=m*g;let x=o,C=h;o=c,h=u,c+=w,u+=b,(R=l(this,fr))==null||R.push(t,e);const A=-b/p,P=w/p,D=A*l(this,Ka),k=P*l(this,Ka);return l(this,ot).set(l(this,ot).subarray(2,8),0),l(this,ot).set([c+D,u+k],4),l(this,ot).set(l(this,ot).subarray(14,18),12),l(this,ot).set([c-D,u-k],16),isNaN(l(this,ot)[6])?(l(this,Ii).length===0&&(l(this,ot).set([o+D,h+k],2),l(this,Ii).push(NaN,NaN,NaN,NaN,(o+D-s)/n,(h+k-i)/r),l(this,ot).set([o-D,h-k],14),l(this,ci).push(NaN,NaN,NaN,NaN,(o-D-s)/n,(h-k-i)/r)),l(this,ot).set([x,C,o,h,c,u],6),!this.isEmpty()):(l(this,ot).set([x,C,o,h,c,u],6),Math.abs(Math.atan2(C-h,x-o)-Math.atan2(b,w))<Math.PI/2?([o,h,c,u]=l(this,ot).subarray(2,6),l(this,Ii).push(NaN,NaN,NaN,NaN,((o+c)/2-s)/n,((h+u)/2-i)/r),[o,h,x,C]=l(this,ot).subarray(14,18),l(this,ci).push(NaN,NaN,NaN,NaN,((x+o)/2-s)/n,((C+h)/2-i)/r),!0):([x,C,o,h,c,u]=l(this,ot).subarray(0,6),l(this,Ii).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,ot).subarray(12,18),l(this,ci).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,Ii),e=l(this,ci);if(isNaN(l(this,ot)[6])&&!this.isEmpty())return y(this,le,ny).call(this);const s=[];s.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)isNaN(t[i])?s.push(`L${t[i+4]} ${t[i+5]}`):s.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);y(this,le,oy).call(this,s);for(let i=e.length-6;i>=6;i-=6)isNaN(e[i])?s.push(`L${e[i+4]} ${e[i+5]}`):s.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return y(this,le,ry).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new qv(t,e,s,i,n,r)}getOutlines(){var d;const t=l(this,Ii),e=l(this,ci),s=l(this,ot),[i,n,r,o]=l(this,vs),h=new Float32Array((((d=l(this,fr))==null?void 0:d.length)??0)+2);for(let g=0,f=h.length-2;g<f;g+=2)h[g]=(l(this,fr)[g]-i)/r,h[g+1]=(l(this,fr)[g+1]-n)/o;if(h[h.length-2]=(l(this,Mo)-i)/r,h[h.length-1]=(l(this,Oo)-n)/o,isNaN(s[6])&&!this.isEmpty())return y(this,le,ay).call(this,h);const c=new Float32Array(l(this,Ii).length+24+l(this,ci).length);let u=t.length;for(let g=0;g<u;g+=2){if(isNaN(t[g])){c[g]=c[g+1]=NaN;continue}c[g]=t[g],c[g+1]=t[g+1]}u=y(this,le,ly).call(this,c,u);for(let g=e.length-6;g>=6;g-=6)for(let f=0;f<6;f+=2){if(isNaN(e[g+f])){c[u]=c[u+1]=NaN,u+=2;continue}c[u]=e[g+f],c[u+1]=e[g+f+1],u+=2}return y(this,le,hy).call(this,c,u),this.newFreeDrawOutline(c,h,l(this,vs),l(this,qa),l(this,Ya),l(this,$a))}};vs=new WeakMap,ci=new WeakMap,Ya=new WeakMap,$a=new WeakMap,Ii=new WeakMap,ot=new WeakMap,Mo=new WeakMap,Oo=new WeakMap,ic=new WeakMap,nc=new WeakMap,qa=new WeakMap,Ka=new WeakMap,fr=new WeakMap,rc=new WeakMap,wd=new WeakMap,xd=new WeakMap,le=new WeakSet,Rc=function(){const t=l(this,ot).subarray(4,6),e=l(this,ot).subarray(16,18),[s,i,n,r]=l(this,vs);return[(l(this,Mo)+(t[0]-e[0])/2-s)/n,(l(this,Oo)+(t[1]-e[1])/2-i)/r,(l(this,Mo)+(e[0]-t[0])/2-s)/n,(l(this,Oo)+(e[1]-t[1])/2-i)/r]},ny=function(){const[t,e,s,i]=l(this,vs),[n,r,o,h]=y(this,le,Rc).call(this);return`M${(l(this,ot)[2]-t)/s} ${(l(this,ot)[3]-e)/i} L${(l(this,ot)[4]-t)/s} ${(l(this,ot)[5]-e)/i} L${n} ${r} L${o} ${h} L${(l(this,ot)[16]-t)/s} ${(l(this,ot)[17]-e)/i} L${(l(this,ot)[14]-t)/s} ${(l(this,ot)[15]-e)/i} Z`},ry=function(t){const e=l(this,ci);t.push(`L${e[4]} ${e[5]} Z`)},oy=function(t){const[e,s,i,n]=l(this,vs),r=l(this,ot).subarray(4,6),o=l(this,ot).subarray(16,18),[h,c,u,d]=y(this,le,Rc).call(this);t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${h} ${c} L${u} ${d} L${(o[0]-e)/i} ${(o[1]-s)/n}`)},ay=function(t){const e=l(this,ot),[s,i,n,r]=l(this,vs),[o,h,c,u]=y(this,le,Rc).call(this),d=new Float32Array(36);return d.set([NaN,NaN,NaN,NaN,(e[2]-s)/n,(e[3]-i)/r,NaN,NaN,NaN,NaN,(e[4]-s)/n,(e[5]-i)/r,NaN,NaN,NaN,NaN,o,h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,(e[16]-s)/n,(e[17]-i)/r,NaN,NaN,NaN,NaN,(e[14]-s)/n,(e[15]-i)/r],0),this.newFreeDrawOutline(d,t,l(this,vs),l(this,qa),l(this,Ya),l(this,$a))},hy=function(t,e){const s=l(this,ci);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},ly=function(t,e){const s=l(this,ot).subarray(4,6),i=l(this,ot).subarray(16,18),[n,r,o,h]=l(this,vs),[c,u,d,g]=y(this,le,Rc).call(this);return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/o,(s[1]-r)/h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,d,g,NaN,NaN,NaN,NaN,(i[0]-n)/o,(i[1]-r)/h],e),e+=24},_(An,rc,8),_(An,wd,2),_(An,xd,l(An,rc)+l(An,wd));let id=An;class qv extends U{constructor(e,s,i,n,r,o){super();_(this,Sd);_(this,Ja);_(this,Do,new Float32Array(4));_(this,Tn);_(this,oc);_(this,bs);_(this,ac);_(this,Kt);v(this,Kt,e),v(this,bs,s),v(this,Ja,i),v(this,ac,n),v(this,Tn,r),v(this,oc,o),this.lastPoint=[NaN,NaN],y(this,Sd,cy).call(this,o);const[h,c,u,d]=l(this,Do);for(let g=0,f=e.length;g<f;g+=2)e[g]=(e[g]-h)/u,e[g+1]=(e[g+1]-c)/d;for(let g=0,f=s.length;g<f;g+=2)s[g]=(s[g]-h)/u,s[g+1]=(s[g+1]-c)/d}toSVGPath(){const e=[`M${l(this,Kt)[4]} ${l(this,Kt)[5]}`];for(let s=6,i=l(this,Kt).length;s<i;s+=6){if(isNaN(l(this,Kt)[s])){e.push(`L${l(this,Kt)[s+4]} ${l(this,Kt)[s+5]}`);continue}e.push(`C${l(this,Kt)[s]} ${l(this,Kt)[s+1]} ${l(this,Kt)[s+2]} ${l(this,Kt)[s+3]} ${l(this,Kt)[s+4]} ${l(this,Kt)[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,Kt),e,n,o,-h),u=U._rescale(l(this,bs),e,n,o,-h);break;case 90:c=U._rescaleAndSwap(l(this,Kt),e,s,o,h),u=U._rescaleAndSwap(l(this,bs),e,s,o,h);break;case 180:c=U._rescale(l(this,Kt),i,s,-o,h),u=U._rescale(l(this,bs),i,s,-o,h);break;case 270:c=U._rescaleAndSwap(l(this,Kt),i,n,-o,-h),u=U._rescaleAndSwap(l(this,bs),i,n,-o,-h);break}return{outline:Array.from(c),points:[Array.from(u)]}}get box(){return l(this,Do)}newOutliner(e,s,i,n,r,o=0){return new id(e,s,i,n,r,o)}getNewOutline(e,s){const[i,n,r,o]=l(this,Do),[h,c,u,d]=l(this,Ja),g=r*u,f=o*d,p=i*u+h,m=n*d+c,w=this.newOutliner({x:l(this,bs)[0]*g+p,y:l(this,bs)[1]*f+m},l(this,Ja),l(this,ac),e,l(this,oc),s??l(this,Tn));for(let b=2;b<l(this,bs).length;b+=2)w.add({x:l(this,bs)[b]*g+p,y:l(this,bs)[b+1]*f+m});return w.getOutlines()}}Ja=new WeakMap,Do=new WeakMap,Tn=new WeakMap,oc=new WeakMap,bs=new WeakMap,ac=new WeakMap,Kt=new WeakMap,Sd=new WeakSet,cy=function(e){const s=l(this,Kt);let i=s[4],n=s[5],r=i,o=n,h=i,c=n,u=i,d=n;const g=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=g(u,s[p+4]));else{const w=$.bezierBoundingBox(i,n,...s.slice(p,p+6));r=Math.min(r,w[0]),o=Math.min(o,w[1]),h=Math.max(h,w[2]),c=Math.max(c,w[3]),d<w[3]?(u=w[2],d=w[3]):d===w[3]&&(u=g(u,w[2]))}i=s[p+4],n=s[p+5]}const f=l(this,Do);f[0]=r-l(this,Tn),f[1]=o-l(this,Tn),f[2]=h-r+2*l(this,Tn),f[3]=c-o+2*l(this,Tn),this.lastPoint=[u,d]};class Rf{constructor(t,e=0,s=0,i=!0){_(this,Xe);_(this,hc);_(this,lc);_(this,pr,[]);_(this,ui,[]);let n=1/0,r=-1/0,o=1/0,h=-1/0;const u=10**-4;for(const{x:b,y:x,width:C,height:A}of t){const P=Math.floor((b-e)/u)*u,D=Math.ceil((b+C+e)/u)*u,k=Math.floor((x-e)/u)*u,M=Math.ceil((x+A+e)/u)*u,R=[P,k,M,!0],F=[D,k,M,!1];l(this,pr).push(R,F),n=Math.min(n,P),r=Math.max(r,D),o=Math.min(o,k),h=Math.max(h,M)}const d=r-n+2*s,g=h-o+2*s,f=n-s,p=o-s,m=l(this,pr).at(i?-1:-2),w=[m[0],m[2]];for(const b of l(this,pr)){const[x,C,A]=b;b[0]=(x-f)/d,b[1]=(C-p)/g,b[2]=(A-p)/g}v(this,hc,new Float32Array([f,p,d,g])),v(this,lc,w)}getOutlines(){l(this,pr).sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of l(this,pr))e[3]?(t.push(...y(this,Xe,Op).call(this,e)),y(this,Xe,dy).call(this,e)):(y(this,Xe,gy).call(this,e),t.push(...y(this,Xe,Op).call(this,e)));return y(this,Xe,uy).call(this,t)}}hc=new WeakMap,lc=new WeakMap,pr=new WeakMap,ui=new WeakMap,Xe=new WeakSet,uy=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 g=o,f=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,g!==o&&(n.push(g,f,o,f===h?h:c),g=o),f=f===h?c:h}n.push(g,f)}return new CC(i,l(this,hc),l(this,lc))},Yd=function(t){const e=l(this,ui);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},dy=function([,t,e]){const s=y(this,Xe,Yd).call(this,t);l(this,ui).splice(s,0,[t,e])},gy=function([,t,e]){const s=y(this,Xe,Yd).call(this,t);for(let i=s;i<l(this,ui).length;i++){const[n,r]=l(this,ui)[i];if(n!==t)break;if(n===t&&r===e){l(this,ui).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=l(this,ui)[i];if(n!==t)break;if(n===t&&r===e){l(this,ui).splice(i,1);return}}},Op=function(t){const[e,s,i]=t,n=[[e,s,i]],r=y(this,Xe,Yd).call(this,i);for(let o=0;o<r;o++){const[h,c]=l(this,ui)[o];for(let u=0,d=n.length;u<d;u++){const[,g,f]=n[u];if(!(c<=g||f<=h)){if(g>=h){if(f>c)n[u][1]=c;else{if(d===1)return[];n.splice(u,1),u--,d--}continue}n[u][2]=h,f>c&&n.push([e,c,f])}}}return n};class CC extends U{constructor(e,s,i){super();_(this,cc);_(this,Qa);v(this,Qa,e),v(this,cc,s),this.lastPoint=i}toSVGPath(){const e=[];for(const s of l(this,Qa)){let[i,n]=s;e.push(`M${i} ${n}`);for(let r=2;r<s.length;r+=2){const o=s[r],h=s[r+1];o===i?(e.push(`V${h}`),n=h):h===n&&(e.push(`H${o}`),i=o)}e.push("Z")}return e.join(" ")}serialize([e,s,i,n],r){const o=[],h=i-e,c=n-s;for(const u of l(this,Qa)){const d=new Array(u.length);for(let g=0;g<u.length;g+=2)d[g]=e+u[g]*h,d[g+1]=n-u[g+1]*c;o.push(d)}return o}get box(){return l(this,cc)}get classNamesForOutlining(){return["highlightOutline"]}}cc=new WeakMap,Qa=new WeakMap;class Lf extends id{newFreeDrawOutline(t,e,s,i,n,r){return new AC(t,e,s,i,n,r)}}class AC extends qv{newOutliner(t,e,s,i,n,r=0){return new Lf(t,e,s,i,n,r)}}const ns=class ns{constructor({editor:t=null,uiManager:e=null}){_(this,At);_(this,di,null);_(this,Ro,null);_(this,Za);_(this,ce,null);_(this,uc,!1);_(this,th,!1);_(this,dc,null);_(this,gc);_(this,mr,null);_(this,gi,null);_(this,eh);var s;t?(v(this,th,!1),v(this,eh,ut.HIGHLIGHT_COLOR),v(this,dc,t)):(v(this,th,!0),v(this,eh,ut.HIGHLIGHT_DEFAULT_COLOR)),v(this,gi,(t==null?void 0:t._uiManager)||e),v(this,gc,l(this,gi)._eventBus),v(this,Za,(t==null?void 0:t.color)||((s=l(this,gi))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),l(ns,fc)||v(ns,fc,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 at(this,"_keyboardManager",new Kh([[["Escape","mac+Escape"],ns.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],ns.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],ns.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],ns.prototype._moveToPrevious],[["Home","mac+Home"],ns.prototype._moveToBeginning],[["End","mac+End"],ns.prototype._moveToEnd]]))}renderButton(){const t=v(this,di,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,gi)._signal;t.addEventListener("click",y(this,At,Xo).bind(this),{signal:e}),t.addEventListener("keydown",y(this,At,Lp).bind(this),{signal:e});const s=v(this,Ro,document.createElement("span"));return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=l(this,Za),t.append(s),t}renderMainDropdown(){const t=v(this,ce,y(this,At,Dp).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===l(this,di)){y(this,At,Xo).call(this,t);return}const e=t.target.getAttribute("data-color");e&&y(this,At,Rp).call(this,e,t)}_moveToNext(t){var e,s;if(!l(this,At,xr)){y(this,At,Xo).call(this,t);return}if(t.target===l(this,di)){(e=l(this,ce).firstChild)==null||e.focus();return}(s=t.target.nextSibling)==null||s.focus()}_moveToPrevious(t){var e,s;if(t.target===((e=l(this,ce))==null?void 0:e.firstChild)||t.target===l(this,di)){l(this,At,xr)&&this._hideDropdownFromKeyboard();return}l(this,At,xr)||y(this,At,Xo).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!l(this,At,xr)){y(this,At,Xo).call(this,t);return}(e=l(this,ce).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!l(this,At,xr)){y(this,At,Xo).call(this,t);return}(e=l(this,ce).lastChild)==null||e.focus()}hideDropdown(){var t,e;(t=l(this,ce))==null||t.classList.add("hidden"),(e=l(this,mr))==null||e.abort(),v(this,mr,null)}_hideDropdownFromKeyboard(){var t;if(!l(this,th)){if(!l(this,At,xr)){(t=l(this,dc))==null||t.unselect();return}this.hideDropdown(),l(this,di).focus({preventScroll:!0,focusVisible:l(this,uc)})}}updateColor(t){if(l(this,Ro)&&(l(this,Ro).style.backgroundColor=t),!l(this,ce))return;const e=l(this,gi).highlightColors.values();for(const s of l(this,ce).children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){var t,e;(t=l(this,di))==null||t.remove(),v(this,di,null),v(this,Ro,null),(e=l(this,ce))==null||e.remove(),v(this,ce,null)}};di=new WeakMap,Ro=new WeakMap,Za=new WeakMap,ce=new WeakMap,uc=new WeakMap,th=new WeakMap,dc=new WeakMap,gc=new WeakMap,mr=new WeakMap,gi=new WeakMap,eh=new WeakMap,fc=new WeakMap,At=new WeakSet,Dp=function(){const t=document.createElement("div"),e=l(this,gi)._signal;t.addEventListener("contextmenu",ti,{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,gi).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(ns,fc)[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===l(this,Za)),n.addEventListener("click",y(this,At,Rp).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",y(this,At,Lp).bind(this),{signal:e}),t},Rp=function(t,e){e.stopPropagation(),l(this,gc).dispatch("switchannotationeditorparams",{source:this,type:l(this,eh),value:t})},Lp=function(t){ns._keyboardManager.exec(this,t)},Xo=function(t){if(l(this,At,xr)){this.hideDropdown();return}if(v(this,uc,t.detail===0),l(this,mr)||(v(this,mr,new AbortController),window.addEventListener("pointerdown",y(this,At,fy).bind(this),{signal:l(this,gi).combinedSignal(l(this,mr))})),l(this,ce)){l(this,ce).classList.remove("hidden");return}const e=v(this,ce,y(this,At,Dp).call(this));l(this,di).append(e)},fy=function(t){var e;(e=l(this,ce))!=null&&e.contains(t.target)||this.hideDropdown()},xr=function(){return l(this,ce)&&!l(this,ce).classList.contains("hidden")},_(ns,fc,null);let nd=ns;const mt=class mt extends Bt{constructor(e){super({...e,name:"highlightEditor"});_(this,st);_(this,sh,null);_(this,pc,0);_(this,En);_(this,Lo,null);_(this,ih,null);_(this,rs,null);_(this,mc,null);_(this,vc,0);_(this,Fo,null);_(this,Is,null);_(this,ys,null);_(this,be,!1);_(this,nh,null);_(this,kn);_(this,Oe,null);_(this,rh,"");_(this,js);_(this,bc,"");this.color=e.color||mt._defaultColor,v(this,js,e.thickness||mt._defaultThickness),v(this,kn,e.opacity||mt._defaultOpacity),v(this,En,e.boxes||null),v(this,bc,e.methodOfCreation||""),v(this,rh,e.text||""),this._isDraggable=!1,e.highlightId>-1?(v(this,be,!0),y(this,st,$d).call(this,e),y(this,st,Uo).call(this)):l(this,En)&&(v(this,sh,e.anchorNode),v(this,pc,e.anchorOffset),v(this,mc,e.focusNode),v(this,vc,e.focusOffset),y(this,st,Fp).call(this),y(this,st,Uo).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=mt.prototype;return at(this,"_keyboardManager",new Kh([[["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,be)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:l(this,js),methodOfCreation:l(this,bc)}}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;Bt.initialize(e,s),mt._defaultColor||(mt._defaultColor=((i=s.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,s){switch(e){case ut.HIGHLIGHT_DEFAULT_COLOR:mt._defaultColor=s;break;case ut.HIGHLIGHT_THICKNESS:mt._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return l(this,nh)}updateParams(e,s){switch(e){case ut.HIGHLIGHT_COLOR:y(this,st,py).call(this,s);break;case ut.HIGHLIGHT_THICKNESS:y(this,st,my).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[ut.HIGHLIGHT_DEFAULT_COLOR,mt._defaultColor],[ut.HIGHLIGHT_THICKNESS,mt._defaultThickness]]}get propertiesToUpdate(){return[[ut.HIGHLIGHT_COLOR,this.color||mt._defaultColor],[ut.HIGHLIGHT_THICKNESS,l(this,js)||mt._defaultThickness],[ut.HIGHLIGHT_FREE,l(this,be)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(v(this,ih,new nd({editor:this})),e.addColorPicker(l(this,ih))),e):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(y(this,st,Lc).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,y(this,st,Lc).call(this))}onceAdded(){this.annotationElementId||this.parent.addUndoableEditor(this),this.div.focus()}remove(){y(this,st,Ip).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(y(this,st,Uo).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?y(this,st,Ip).call(this):e&&(y(this,st,Uo).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,be)?(e=(e-this.rotation+360)%360,i=y(n=mt,Ns,Ch).call(n,l(this,Is).box,e)):i=y(r=mt,Ns,Ch).call(r,[this.x,this.y,this.width,this.height],e),s.updateProperties(l(this,ys),{bbox:i,root:{"data-main-rotation":e}}),s.updateProperties(l(this,Oe),{bbox:y(o=mt,Ns,Ch).call(o,l(this,rs).box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();l(this,rh)&&(e.setAttribute("aria-label",l(this,rh)),e.setAttribute("role","mark")),l(this,be)?e.classList.add("free"):this.div.addEventListener("keydown",y(this,st,by).bind(this),{signal:this._uiManager._signal});const s=v(this,Fo,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=l(this,Lo);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),$u(this,l(this,Fo),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Oe),{rootClass:{hovered:!0}})}pointerleave(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Oe),{rootClass:{hovered:!1}})}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:y(this,st,qd).call(this,!0);break;case 1:case 3:y(this,st,qd).call(this,!1);break}}select(){var e;super.select(),l(this,Oe)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Oe),{rootClass:{hovered:!1,selected:!0}}))}unselect(){var e;super.unselect(),l(this,Oe)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Oe),{rootClass:{selected:!1}}),l(this,be)||y(this,st,qd).call(this,!1))}get _mustFixPosition(){return!l(this,be)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(l(this,ys),{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(l(this,Oe),{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,g=e.combinedSignal(d),f=p=>{d.abort(),y(this,Ns,xy).call(this,e,p)};window.addEventListener("blur",f,{signal:g}),window.addEventListener("pointerup",f,{signal:g}),window.addEventListener("pointerdown",ei,{capture:!0,passive:!1,signal:g}),window.addEventListener("contextmenu",ti,{signal:g}),i.addEventListener("pointermove",y(this,Ns,wy).bind(this,e),{signal:g}),this._freeHighlight=new Lf({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,w,b,x;let n=null;if(e instanceof Yv){const{data:{quadPoints:C,rect:A,rotation:P,id:D,color:k,opacity:M,popupRef:R},parent:{page:{pageNumber:F}}}=e;n=e={annotationType:it.HIGHLIGHT,color:Array.from(k),opacity:M,quadPoints:C,boxes:null,pageIndex:F-1,rect:A.slice(0),rotation:P,id:D,deleted:!1,popupRef:R}}else if(e instanceof Of){const{data:{inkLists:C,rect:A,rotation:P,id:D,color:k,borderStyle:{rawWidth:M},popupRef:R},parent:{page:{pageNumber:F}}}=e;n=e={annotationType:it.HIGHLIGHT,color:Array.from(k),thickness:M,inkLists:C,boxes:null,pageIndex:F-1,rect:A.slice(0),rotation:P,id:D,deleted:!1,popupRef:R}}const{color:r,quadPoints:o,inkLists:h,opacity:c}=e,u=await super.deserialize(e,s,i);u.color=$.makeHexColor(...r),v(u,kn,c||1),h&&v(u,js,e.thickness),u.annotationElementId=e.id||null,u._initialData=n;const[d,g]=u.pageDimensions,[f,p]=u.pageTranslation;if(o){const C=v(u,En,[]);for(let A=0;A<o.length;A+=8)C.push({x:(o[A]-f)/d,y:1-(o[A+1]-p)/g,width:(o[A+2]-o[A])/d,height:(o[A+1]-o[A+5])/g});y(m=u,st,Fp).call(m),y(w=u,st,Uo).call(w),u.rotate(u.rotation)}else if(h){v(u,be,!0);const C=h[0],A={x:C[0]-f,y:g-(C[1]-p)},P=new Lf(A,[0,0,d,g],1,l(u,js)/2,!0,.001);for(let M=0,R=C.length;M<R;M+=2)A.x=C[M]-f,A.y=g-(C[M+1]-p),P.add(A);const{id:D,clipPathId:k}=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:P.toSVGPath()}},!0,!0);y(b=u,st,$d).call(b,{highlightOutlines:P.getOutlines(),highlightId:D,clipPathId:k}),y(x=u,st,Uo).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=Bt._colorManager.convert(this.color),n={annotationType:it.HIGHLIGHT,color:i,opacity:l(this,kn),thickness:l(this,js),quadPoints:y(this,st,yy).call(this),outlines:y(this,st,_y).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:y(this,st,Lc).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!y(this,st,Sy).call(this,n)?null:(n.id=this.annotationElementId,n)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};sh=new WeakMap,pc=new WeakMap,En=new WeakMap,Lo=new WeakMap,ih=new WeakMap,rs=new WeakMap,mc=new WeakMap,vc=new WeakMap,Fo=new WeakMap,Is=new WeakMap,ys=new WeakMap,be=new WeakMap,nh=new WeakMap,kn=new WeakMap,Oe=new WeakMap,rh=new WeakMap,js=new WeakMap,bc=new WeakMap,st=new WeakSet,Fp=function(){const e=new Rf(l(this,En),.001);v(this,Is,e.getOutlines()),[this.x,this.y,this.width,this.height]=l(this,Is).box;const s=new Rf(l(this,En),.0025,.001,this._uiManager.direction==="ltr");v(this,rs,s.getOutlines());const{lastPoint:i}=l(this,rs);v(this,nh,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height])},$d=function({highlightOutlines:e,highlightId:s,clipPathId:i}){var d,g;if(v(this,Is,e),v(this,rs,e.getNewOutline(l(this,js)/2+1.5,.0025)),s>=0)v(this,ys,s),v(this,Lo,i),this.parent.drawLayer.finalizeDraw(s,{bbox:e.box,path:{d:e.toSVGPath()}}),v(this,Oe,this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:l(this,rs).box,path:{d:l(this,rs).toSVGPath()}},!0));else if(this.parent){const f=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(l(this,ys),{bbox:y(d=mt,Ns,Ch).call(d,l(this,Is).box,(f-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(l(this,Oe),{bbox:y(g=mt,Ns,Ch).call(g,l(this,rs).box,f),path:{d:l(this,rs).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[f,p]=this.parentDimensions;this.x=o,this.y=1-r,this.width=h*p/f,this.height=c*f/p;break}case 180:this.x=1-r,this.y=1-o,this.width=h,this.height=c;break;case 270:{const[f,p]=this.parentDimensions;this.x=1-o,this.y=r,this.width=h*p/f,this.height=c*f/p;break}}const{lastPoint:u}=l(this,rs);v(this,nh,[(u[0]-r)/h,(u[1]-o)/c])},py=function(e){const s=(r,o)=>{var h,c;this.color=r,v(this,kn,o),(h=this.parent)==null||h.drawLayer.updateProperties(l(this,ys),{root:{fill:r,"fill-opacity":o}}),(c=l(this,ih))==null||c.updateColor(r)},i=this.color,n=l(this,kn);this.addCommands({cmd:s.bind(this,e,mt._defaultOpacity),undo:s.bind(this,i,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ut.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},my=function(e){const s=l(this,js),i=n=>{v(this,js,n),y(this,st,vy).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:ut.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},vy=function(e){if(!l(this,be))return;y(this,st,$d).call(this,{highlightOutlines:l(this,Is).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},Ip=function(){l(this,ys)===null||!this.parent||(this.parent.drawLayer.remove(l(this,ys)),v(this,ys,null),this.parent.drawLayer.remove(l(this,Oe)),v(this,Oe,null))},Uo=function(e=this.parent){l(this,ys)===null&&({id:Ke(this,ys)._,clipPathId:Ke(this,Lo)._}=e.drawLayer.draw({bbox:l(this,Is).box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":l(this,kn)},rootClass:{highlight:!0,free:l(this,be)},path:{d:l(this,Is).toSVGPath()}},!1,!0),v(this,Oe,e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:l(this,be)},bbox:l(this,rs).box,path:{d:l(this,rs).toSVGPath()}},l(this,be))),l(this,Fo)&&(l(this,Fo).style.clipPath=l(this,Lo)))},Ns=new WeakSet,Ch=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]},by=function(e){mt._keyboardManager.exec(this,e)},qd=function(e){if(!l(this,sh))return;const s=window.getSelection();e?s.setPosition(l(this,sh),l(this,pc)):s.setPosition(l(this,mc),l(this,vc))},Lc=function(){return l(this,be)?this.rotation:0},yy=function(){if(l(this,be))return null;const[e,s]=this.pageDimensions,[i,n]=this.pageTranslation,r=l(this,En),o=new Float32Array(r.length*8);let h=0;for(const{x:c,y:u,width:d,height:g}of r){const f=c*e+i,p=(1-u)*s+n;o[h]=o[h+4]=f,o[h+1]=o[h+3]=p,o[h+2]=o[h+6]=f+d*e,o[h+5]=o[h+7]=p-g*s,h+=8}return o},_y=function(e){return l(this,Is).serialize(e,y(this,st,Lc).call(this))},wy=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},xy=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=""},Sy=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},_(mt,Ns),q(mt,"_defaultColor",null),q(mt,"_defaultOpacity",1),q(mt,"_defaultThickness",12),q(mt,"_type","highlight"),q(mt,"_editorType",it.HIGHLIGHT),q(mt,"_freeHighlightId",-1),q(mt,"_freeHighlight",null),q(mt,"_freeHighlightClipId","");let rd=mt;class TC{constructor(){_(this,Io,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,Io)[t]=e}toSVGProperties(){const t=l(this,Io);return v(this,Io,Object.create(null)),{root:t}}reset(){v(this,Io,Object.create(null))}updateAll(t=this){this.updateProperties(t)}clone(){St("Not implemented")}}Io=new WeakMap;const Bs=class Bs extends Bt{constructor(e){super(e);_(this,pt);_(this,_s,null);_(this,oh);q(this,"_drawId",null);v(this,oh,e.mustBeCommitted||!1),e.drawOutlines&&(y(this,pt,jp).call(this,e),y(this,pt,Fc).call(this))}static _mergeSVGProperties(e,s){const i=new Set(Object.keys(e));for(const[n,r]of Object.entries(s))i.has(n)?Object.assign(e[n],r):e[n]=r;return e}static getDefaultDrawingOptions(e){St("Not implemented")}static get typesMap(){St("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&&(this._currentDraw.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,_s).updateProperty(s,h);c&&y(this,pt,Ic).call(this,c),(u=this.parent)==null||u.drawLayer.updateProperties(this._drawId,n.toSVGProperties())};this.addCommands({cmd:o.bind(this,i),undo:o.bind(this,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,Bs._mergeSVGProperties(l(this,_s).getPathResizingSVGProperties(y(this,pt,Kd).call(this)),{bbox:y(this,pt,Ah).call(this)}))}_onResized(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,Bs._mergeSVGProperties(l(this,_s).getPathResizedSVGProperties(y(this,pt,Kd).call(this)),{bbox:y(this,pt,Ah).call(this)}))}_onTranslating(e,s){var i;(i=this.parent)==null||i.drawLayer.updateProperties(this._drawId,{bbox:y(this,pt,Ah).call(this,e,s)})}_onTranslated(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,Bs._mergeSVGProperties(l(this,_s).getPathTranslatedSVGProperties(y(this,pt,Kd).call(this),this.parentDimensions),{bbox:y(this,pt,Ah).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(){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,l(this,oh)&&(v(this,oh,!1),this.commit(),this.parent.setSelected(this),this.isOnScreen&&this.div.focus())}remove(){y(this,pt,Bp).call(this),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(y(this,pt,Fc).call(this),y(this,pt,Ic).call(this,l(this,_s).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),y(this,pt,Bp).call(this)):e&&(this._uiManager.addShouldRescale(this),y(this,pt,Fc).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),s&&this.select()}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,Bs._mergeSVGProperties({bbox:y(this,pt,Ah).call(this)},l(this,_s).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&y(this,pt,Ic).call(this,l(this,_s).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){St("Not implemented")}static startDrawing(e,s,i,{target:n,offsetX:r,offsetY:o}){var f;const{viewport:{rotation:h}}=e,{width:c,height:u}=n.getBoundingClientRect(),d=new AbortController,g=e.combinedSignal(d);if(window.addEventListener("pointerup",p=>{d.abort(),e.toggleDrawing(!0),this._endDraw(p)},{signal:g}),window.addEventListener("pointerdown",ei,{capture:!0,passive:!1,signal:g}),window.addEventListener("contextmenu",ti,{signal:g}),n.addEventListener("pointermove",this._drawMove.bind(this),{signal:g}),e.toggleDrawing(),(f=s._editorUndoBar)==null||f.hide(),this._currentDraw){e.drawLayer.updateProperties(this._currentDrawId,this._currentDraw.startNew(r,o,c,u,h));return}s.updateUIForDefaultProperties(this),this._currentDraw=this.createDrawerInstance(r,o,c,u,h),this._currentDrawingOptions=this.getDefaultDrawingOptions(),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(this._currentDrawingOptions.toSVGProperties(),this._currentDraw.defaultSVGProperties),!0,!1)}static _drawMove({offsetX:e,offsetY:s}){this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._currentDraw.add(e,s))}static _endDraw({offsetX:e,offsetY:s}){const i=this._currentParent;if(i.drawLayer.updateProperties(this._currentDrawId,this._currentDraw.end(e,s)),this.supportMultipleDrawings){const n=this._currentDraw,r=this._currentDrawId,o=n.getLastElement();i.addCommands({cmd:()=>{i.drawLayer.updateProperties(r,n.setLastElement(o))},undo:()=>{i.drawLayer.updateProperties(r,n.removeLastElement())},mustExec:!1,type:ut.DRAW_STEP});return}this.endDrawing(!1)}static endDrawing(e){const s=this._currentParent;if(!s)return null;if(s.toggleDrawing(!0),s.cleanUndoStack(ut.DRAW_STEP),!this._currentDraw.isEmpty()){const{pageDimensions:[i,n],scale:r}=s,o=s.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:this._currentDraw.getOutlines(i*r,n*r,r,this._INNER_MARGIN),drawingOptions:this._currentDrawingOptions,mustBeCommitted:!e});return this._cleanup(),o}return s.drawLayer.remove(this._currentDrawId),this._cleanup(),null}static _cleanup(){this._currentDrawId=-1,this._currentDraw=null,this._currentDrawingOptions=null,this._currentParent=null}createDrawingOptions(e){}static deserializeDraw(e,s,i,n,r,o){St("Not implemented")}static async deserialize(e,s,i){var d,g;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),y(d=u,pt,jp).call(d,{drawOutlines:c}),y(g=u,pt,Fc).call(g),u.onScaleChanging(),u.rotate(),u}serializeDraw(e){const[s,i]=this.pageTranslation,[n,r]=this.pageDimensions;return l(this,_s).serialize([s,i,n,r],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};_s=new WeakMap,oh=new WeakMap,pt=new WeakSet,jp=function({drawOutlines:e,drawId:s,drawingOptions:i}){v(this,_s,e),this._drawingOptions||(this._drawingOptions=i),s>=0?(this._drawId=s,this.parent.drawLayer.finalizeDraw(s,e.defaultProperties)):this._drawId=y(this,pt,Np).call(this,e,this.parent),y(this,pt,Ic).call(this,e.box)},Np=function(e,s){const{id:i}=s.drawLayer.draw(Bs._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return i},Bp=function(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())},Fc=function(e=this.parent){if(!(this._drawId!==null&&this.parent===e)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,e.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=y(this,pt,Np).call(this,l(this,_s),e)}},Cy=function([e,s,i,n]){const{parentDimensions:[r,o],rotation:h}=this;switch(h){case 90:return[s,1-e,i*(o/r),n*(r/o)];case 180:return[1-e,1-s,i,n];case 270:return[1-s,e,i*(o/r),n*(r/o)];default:return[e,s,i,n]}},Kd=function(){const{x:e,y:s,width:i,height:n,parentDimensions:[r,o],rotation:h}=this;switch(h){case 90:return[1-s,e,i*(r/o),n*(o/r)];case 180:return[1-e,1-s,i,n];case 270:return[s,1-e,i*(r/o),n*(o/r)];default:return[e,s,i,n]}},Ic=function(e){if([this.x,this.y,this.width,this.height]=y(this,pt,Cy).call(this,e),this.div){this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)}this._onResized()},Ah=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(Bs,"_currentDrawId",-1),q(Bs,"_currentDraw",null),q(Bs,"_currentDrawingOptions",null),q(Bs,"_currentParent",null),q(Bs,"_INNER_MARGIN",3);let Ff=Bs;class EC{constructor(t,e,s,i,n,r){_(this,hh);_(this,ji,new Float64Array(6));_(this,fe);_(this,pe);_(this,jo);_(this,ah);_(this,os);_(this,ye,"");_(this,Hs,0);_(this,No,new od);_(this,Bo);_(this,Ho);v(this,Bo,s),v(this,Ho,i),v(this,jo,n),v(this,ah,r),[t,e]=y(this,hh,Jd).call(this,t,e);const o=v(this,fe,[NaN,NaN,NaN,NaN,t,e]);v(this,os,[t,e]),v(this,pe,[{line:o,points:l(this,os)}]),l(this,ji).set(o,0)}updateProperty(t,e){t==="stroke-width"&&v(this,ah,e)}isEmpty(){return!l(this,pe)||l(this,pe).length===0}add(t,e){[t,e]=y(this,hh,Jd).call(this,t,e);const[s,i,n,r]=l(this,ji).subarray(2,6),o=t-n,h=e-r;return Math.hypot(l(this,Bo)*o,l(this,Ho)*h)<=2?null:(l(this,os).push(t,e),isNaN(s)?(l(this,ji).set([n,r,t,e],2),l(this,fe).push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(l(this,ji)[0])&&l(this,fe).splice(6,6),l(this,ji).set([s,i,n,r,t,e],0),l(this,fe).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,os).length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){v(this,Bo,s),v(this,Ho,i),v(this,jo,n),[t,e]=y(this,hh,Jd).call(this,t,e);const r=v(this,fe,[NaN,NaN,NaN,NaN,t,e]);v(this,os,[t,e]);const o=l(this,pe).at(-1);return o&&(o.line=new Float32Array(o.line),o.points=new Float32Array(o.points)),l(this,pe).push({line:r,points:l(this,os)}),l(this,ji).set(r,0),v(this,Hs,0),this.toSVGPath(),null}getLastElement(){return l(this,pe).at(-1)}setLastElement(t){return l(this,pe)?(l(this,pe).push(t),v(this,fe,t.line),v(this,os,t.points),v(this,Hs,0),{path:{d:this.toSVGPath()}}):l(this,No).setLastElement(t)}removeLastElement(){if(!l(this,pe))return l(this,No).removeLastElement();l(this,pe).pop(),v(this,ye,"");for(let t=0,e=l(this,pe).length;t<e;t++){const{line:s,points:i}=l(this,pe)[t];v(this,fe,s),v(this,os,i),v(this,Hs,0),this.toSVGPath()}return{path:{d:l(this,ye)}}}toSVGPath(){const t=U.svgRound(l(this,fe)[4]),e=U.svgRound(l(this,fe)[5]);if(l(this,os).length===2)return v(this,ye,`${l(this,ye)} M ${t} ${e} Z`),l(this,ye);if(l(this,os).length<=6){const i=l(this,ye).lastIndexOf("M");v(this,ye,`${l(this,ye).slice(0,i)} M ${t} ${e}`),v(this,Hs,6)}if(l(this,os).length===4){const i=U.svgRound(l(this,fe)[10]),n=U.svgRound(l(this,fe)[11]);return v(this,ye,`${l(this,ye)} L ${i} ${n}`),v(this,Hs,12),l(this,ye)}const s=[];l(this,Hs)===0&&(s.push(`M ${t} ${e}`),v(this,Hs,6));for(let i=l(this,Hs),n=l(this,fe).length;i<n;i+=6){const[r,o,h,c,u,d]=l(this,fe).slice(i,i+6).map(U.svgRound);s.push(`C${r} ${o} ${h} ${c} ${u} ${d}`)}return v(this,ye,l(this,ye)+s.join(" ")),v(this,Hs,l(this,fe).length),l(this,ye)}getOutlines(t,e,s,i){const n=l(this,pe).at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),l(this,No).build(l(this,pe),t,e,s,l(this,jo),l(this,ah),i),v(this,ji,null),v(this,fe,null),v(this,pe,null),v(this,ye,null),l(this,No)}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}ji=new WeakMap,fe=new WeakMap,pe=new WeakMap,jo=new WeakMap,ah=new WeakMap,os=new WeakMap,ye=new WeakMap,Hs=new WeakMap,No=new WeakMap,Bo=new WeakMap,Ho=new WeakMap,hh=new WeakSet,Jd=function(t,e){return U._normalizePoint(t,e,l(this,Bo),l(this,Ho),l(this,jo))};const zf=class zf extends U{constructor(){super(...arguments);_(this,_e);_(this,Ue);_(this,yc,0);_(this,_c);_(this,ws);_(this,Ni);_(this,Bi);_(this,lh);_(this,ch);_(this,uh)}build(e,s,i,n,r,o,h){v(this,Ni,s),v(this,Bi,i),v(this,lh,n),v(this,ch,r),v(this,uh,o),v(this,_c,h??0),v(this,ws,e),y(this,_e,Ty).call(this)}setLastElement(e){return l(this,ws).push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return l(this,ws).pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:s}of l(this,ws)){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,g]=y(this,_e,Ay).call(this);let f,p,m,w,b,x,C,A,P;switch(l(this,ch)){case 0:P=U._rescale,f=e,p=s+n,m=i,w=-n,b=e+c*i,x=s+(1-u-g)*n,C=e+(c+d)*i,A=s+(1-u)*n;break;case 90:P=U._rescaleAndSwap,f=e,p=s,m=i,w=n,b=e+u*i,x=s+c*n,C=e+(u+g)*i,A=s+(c+d)*n;break;case 180:P=U._rescale,f=e+i,p=s,m=-i,w=n,b=e+(1-c-d)*i,x=s+u*n,C=e+(1-c)*i,A=s+(u+g)*n;break;case 270:P=U._rescaleAndSwap,f=e+i,p=s+n,m=-i,w=-n,b=e+(1-u-g)*i,x=s+(1-c-d)*n,C=e+(1-u)*i,A=s+(1-c)*n;break}for(const{line:D,points:k}of l(this,ws))o.push(P(D,f,p,m,w,r?new Array(D.length):null)),h.push(P(k,f,p,m,w,r?new Array(k.length):null));return{lines:o,points:h,rect:[b,x,C,A]}}static deserialize(e,s,i,n,r,{paths:{lines:o,points:h},rotation:c,thickness:u}){const d=[];let g,f,p,m,w;switch(c){case 0:w=U._rescale,g=-e/i,f=s/n+1,p=1/i,m=-1/n;break;case 90:w=U._rescaleAndSwap,g=-s/n,f=-e/i,p=1/n,m=1/i;break;case 180:w=U._rescale,g=e/i+1,f=-s/n,p=-1/i,m=1/n;break;case 270:w=U._rescaleAndSwap,g=s/n+1,f=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 A=new Float32Array(3*(C-2));o.push(A);let[P,D,k,M]=x.subarray(0,4);A.set([NaN,NaN,NaN,NaN,P,D],0);for(let R=4;R<C;R+=2){const F=x[R],I=x[R+1];A.set(U.createBezierPoints(P,D,k,M,F,I),(R-2)*3),[P,D,k,M]=[k,M,F,I]}}}for(let x=0,C=o.length;x<C;x++)d.push({line:w(o[x].map(A=>A??NaN),g,f,p,m),points:w(h[x].map(A=>A??NaN),g,f,p,m)});const b=new zf;return b.build(d,i,n,1,c,u,r),b}get box(){return l(this,Ue)}updateProperty(e,s){return e==="stroke-width"?y(this,_e,Ey).call(this,s):null}updateParentDimensions([e,s],i){const[n,r]=y(this,_e,Ln).call(this);v(this,Ni,e),v(this,Bi,s),v(this,lh,i);const[o,h]=y(this,_e,Ln).call(this),c=o-n,u=h-r,d=l(this,Ue);return d[0]-=c,d[1]-=u,d[2]+=2*c,d[3]+=2*u,d}updateRotation(e){return v(this,yc,e),{path:{transform:this.rotationTransform}}}get viewBox(){return l(this,Ue).map(U.svgRound).join(" ")}get defaultProperties(){const[e,s]=l(this,Ue);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${U.svgRound(e)} ${U.svgRound(s)}`}}}get rotationTransform(){const[,,e,s]=l(this,Ue);let i=0,n=0,r=0,o=0,h=0,c=0;switch(l(this,yc)){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]=y(this,_e,Ln).call(this),[h,c,u,d]=l(this,Ue);if(Math.abs(u-r)<=U.PRECISION||Math.abs(d-o)<=U.PRECISION){const w=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(${w} ${b})`}}}const g=(i-2*r)/(u-2*r),f=(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(${g} ${f}) translate(${U.svgRound(-r)} ${U.svgRound(-o)})`}}}getPathResizedSVGProperties([e,s,i,n]){const[r,o]=y(this,_e,Ln).call(this),h=l(this,Ue),[c,u,d,g]=h;if(h[0]=e,h[1]=s,h[2]=i,h[3]=n,Math.abs(d-r)<=U.PRECISION||Math.abs(g-o)<=U.PRECISION){const b=e+i/2-(c+d/2),x=s+n/2-(u+g/2);for(const{line:C,points:A}of l(this,ws))U._translate(C,b,x,C),U._translate(A,b,x,A);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${U.svgRound(e)} ${U.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const f=(i-2*r)/(d-2*r),p=(n-2*o)/(g-2*o),m=-f*(c+r)+e+r,w=-p*(u+o)+s+o;if(f!==1||p!==1||m!==0||w!==0)for(const{line:b,points:x}of l(this,ws))U._rescale(b,m,w,f,p,b),U._rescale(x,m,w,f,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,Ue),h=e-o[0],c=s-o[1];if(l(this,Ni)===n&&l(this,Bi)===r)for(const{line:u,points:d}of l(this,ws))U._translate(u,h,c,u),U._translate(d,h,c,d);else{const u=l(this,Ni)/n,d=l(this,Bi)/r;v(this,Ni,n),v(this,Bi,r);for(const{line:g,points:f}of l(this,ws))U._rescale(g,h,c,u,d,g),U._rescale(f,h,c,u,d,f);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,Ue);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}}};Ue=new WeakMap,yc=new WeakMap,_c=new WeakMap,ws=new WeakMap,Ni=new WeakMap,Bi=new WeakMap,lh=new WeakMap,ch=new WeakMap,uh=new WeakMap,_e=new WeakSet,Ln=function(e=l(this,uh)){const s=l(this,_c)+e/2*l(this,lh);return l(this,ch)%180===0?[s/l(this,Ni),s/l(this,Bi)]:[s/l(this,Bi),s/l(this,Ni)]},Ay=function(){const[e,s,i,n]=l(this,Ue),[r,o]=y(this,_e,Ln).call(this,0);return[e+r,s+o,i-2*r,n-2*o]},Ty=function(){const e=v(this,Ue,new Float32Array([1/0,1/0,-1/0,-1/0]));for(const{line:n}of l(this,ws)){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,g,f,p,m]=n.subarray(h,h+6);$.bezierBoundingBox(r,o,u,d,g,f,p,m,e),r=p,o=m}}const[s,i]=y(this,_e,Ln).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]},Ey=function(e){const[s,i]=y(this,_e,Ln).call(this);v(this,uh,e);const[n,r]=y(this,_e,Ln).call(this),[o,h]=[n-s,r-i],c=l(this,Ue);return c[0]-=o,c[1]-=h,c[2]+=2*o,c[3]+=2*h,c};let od=zf;const Xf=class Xf extends TC{constructor(e){super();_(this,dh);v(this,dh,e),super.updateProperties({fill:"none",stroke:Bt._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(e,s){e==="stroke-width"&&(s??(s=this["stroke-width"]),s*=l(this,dh).realScale),super.updateSVGProperty(e,s)}clone(){const e=new Xf(l(this,dh));return e.updateAll(this),e}};dh=new WeakMap;let If=Xf;const gh=class gh extends Ff{constructor(e){super({...e,name:"inkEditor"});_(this,Cd);this._willKeepAspectRatio=!0}static initialize(e,s){Bt.initialize(e,s),this._defaultDrawingOptions=new If(s.viewParameters)}static getDefaultDrawingOptions(e){const s=this._defaultDrawingOptions.clone();return s.updateProperties(e),s}static get supportMultipleDrawings(){return!0}static get typesMap(){return at(this,"typesMap",new Map([[ut.INK_THICKNESS,"stroke-width"],[ut.INK_COLOR,"stroke"],[ut.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(e,s,i,n,r){return new EC(e,s,i,n,r,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(e,s,i,n,r,o){return od.deserialize(e,s,i,n,r,o)}static async deserialize(e,s,i){let n=null;if(e instanceof Of){const{data:{inkLists:o,rect:h,rotation:c,id:u,color:d,opacity:g,borderStyle:{rawWidth:f},popupRef:p},parent:{page:{pageNumber:m}}}=e;n=e={annotationType:it.INK,color:Array.from(d),thickness:f,opacity:g,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=gh.getDefaultDrawingOptions({stroke:$.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:it.INK,color:Bt._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&&!y(this,Cd,ky).call(this,c)?null:(c.id=this.annotationElementId,c)}renderAnnotationElement(e){const{points:s,rect:i}=this.serializeDraw(!1);return e.updateEdited({rect:i,thickness:this._drawingOptions["stroke-width"],points:s}),null}};Cd=new WeakSet,ky=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(gh,"_type","ink"),q(gh,"_editorType",it.INK),q(gh,"_defaultDrawingOptions",null);let jf=gh;const wc=class wc extends Bt{constructor(e){super({...e,name:"stampEditor"});_(this,ht);_(this,Gt,null);_(this,we,null);_(this,vr,null);_(this,Pn,null);_(this,br,null);_(this,fh,"");_(this,Hi,null);_(this,Mn,null);_(this,Vi,null);_(this,xs,!1);_(this,ph,!1);v(this,Pn,e.bitmapUrl),v(this,br,e.bitmapFile)}static initialize(e,s){Bt.initialize(e,s)}static get supportedTypes(){return at(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return at(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(e){return this.supportedTypes.includes(e)}static paste(e,s){s.pasteEditor(it.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,s;l(this,we)&&(v(this,Gt,null),this._uiManager.imageManager.deleteId(l(this,we)),(e=l(this,Hi))==null||e.remove(),v(this,Hi,null),(s=l(this,Mn))==null||s.disconnect(),v(this,Mn,null),l(this,Vi)&&(clearTimeout(l(this,Vi)),v(this,Vi,null))),super.remove()}rebuild(){if(!this.parent){l(this,we)&&y(this,ht,Qd).call(this);return}super.rebuild(),this.div!==null&&(l(this,we)&&l(this,Hi)===null&&y(this,ht,Qd).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(){this._isDraggable=!0,this.div.focus()}isEmpty(){return!(l(this,vr)||l(this,Gt)||l(this,Pn)||l(this,br)||l(this,we))}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)?y(this,ht,Hp).call(this):y(this,ht,Qd).call(this),this.width&&!this.annotationElementId){const[i,n]=this.parentDimensions;this.setAt(e*i,s*n,this.width*i,this.height*n)}return this.div}copyCanvas(e,s,i=!1){var f;e||(e=224);const{width:n,height:r}=l(this,Gt),o=new pf;let h=l(this,Gt),c=n,u=r,d=null;if(s){if(n>s||r>s){const M=Math.min(s/n,s/r);c=Math.floor(n*M),u=Math.floor(r*M)}d=document.createElement("canvas");const p=d.width=Math.ceil(c*o.sx),m=d.height=Math.ceil(u*o.sy);l(this,xs)||(h=y(this,ht,Zd).call(this,p,m));const w=d.getContext("2d");w.filter=this._uiManager.hcmFilter;let b="white",x="#cfcfd8";this._uiManager.hcmFilter!=="none"?x="black":(f=window.matchMedia)!=null&&f.call(window,"(prefers-color-scheme: dark)").matches&&(b="#8f8f9d",x="#42414d");const C=15,A=C*o.sx,P=C*o.sy,D=new OffscreenCanvas(A*2,P*2),k=D.getContext("2d");k.fillStyle=b,k.fillRect(0,0,A*2,P*2),k.fillStyle=x,k.fillRect(0,0,A,P),k.fillRect(A,P,A,P),w.fillStyle=w.createPattern(D,"repeat"),w.fillRect(0,0,p,m),w.drawImage(h,0,0,h.width,h.height,0,0,p,m)}let g=null;if(i){let p,m;if(o.symmetric&&h.width<e&&h.height<e)p=h.width,m=h.height;else if(h=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,xs)||(h=y(this,ht,Zd).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),g={width:p,height:m,data:b.getImageData(0,0,p,m).data}}return{canvas:d,width:c,height:u,imageData:g}}getImageForAltText(){return l(this,Hi)}static async deserialize(e,s,i){var m;let n=null;if(e instanceof $v){const{data:{rect:w,rotation:b,id:x,structParent:C,popupRef:A},container:P,parent:{page:{pageNumber:D}}}=e,k=P.querySelector("canvas"),M=i.imageManager.getFromCanvas(P.id,k);k.remove();const R=((m=await s._structTree.getAriaAttributes(`${cf}${x}`))==null?void 0:m.get("aria-label"))||"";n=e={annotationType:it.STAMP,bitmapId:M.id,bitmap:M.bitmap,pageIndex:D-1,rect:w.slice(0),rotation:b,id:x,deleted:!1,accessibilityData:{decorative:!1,altText:R},isSvg:!1,structParent:C,popupRef:A}}const r=await super.deserialize(e,s,i),{rect:o,bitmap:h,bitmapUrl:c,bitmapId:u,isSvg:d,accessibilityData:g}=e;u&&i.imageManager.isValidId(u)?(v(r,we,u),h&&v(r,Gt,h)):v(r,Pn,c),v(r,xs,d);const[f,p]=r.pageDimensions;return r.width=(o[2]-o[0])/f,r.height=(o[3]-o[1])/p,r.annotationElementId=e.id||null,g&&(r.altTextData=g),r._initialData=n,v(r,ph,!!n),r}serialize(e=!1,s=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const i={annotationType:it.STAMP,bitmapId:l(this,we),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:l(this,xs),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=y(this,ht,tg).call(this,!0),i.accessibilityData=this.serializeAltText(!0),i;const{decorative:n,altText:r}=this.serializeAltText(!1);if(!n&&r&&(i.accessibilityData={type:"Figure",alt:r}),this.annotationElementId){const h=y(this,ht,Oy).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,xs)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!s.stamps.has(l(this,we)))s.stamps.set(l(this,we),{area:o,serialized:i}),i.bitmap=y(this,ht,tg).call(this,!1);else if(l(this,xs)){const h=s.stamps.get(l(this,we));o>h.area&&(h.area=o,h.serialized.bitmap.close(),h.serialized.bitmap=y(this,ht,tg).call(this,!1))}return i}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}};Gt=new WeakMap,we=new WeakMap,vr=new WeakMap,Pn=new WeakMap,br=new WeakMap,fh=new WeakMap,Hi=new WeakMap,Mn=new WeakMap,Vi=new WeakMap,xs=new WeakMap,ph=new WeakMap,ht=new WeakSet,jc=function(e,s=!1){if(!e){this.remove();return}v(this,Gt,e.bitmap),s||(v(this,we,e.id),v(this,xs,e.isSvg)),e.file&&v(this,fh,e.file.name),y(this,ht,Hp).call(this)},Nc=function(){if(v(this,vr,null),this._uiManager.enableWaiting(!1),!!l(this,Hi)){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()}},Qd=function(){if(l(this,we)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(l(this,we)).then(i=>y(this,ht,jc).call(this,i,!0)).finally(()=>y(this,ht,Nc).call(this));return}if(l(this,Pn)){const i=l(this,Pn);v(this,Pn,null),this._uiManager.enableWaiting(!0),v(this,vr,this._uiManager.imageManager.getFromUrl(i).then(n=>y(this,ht,jc).call(this,n)).finally(()=>y(this,ht,Nc).call(this)));return}if(l(this,br)){const i=l(this,br);v(this,br,null),this._uiManager.enableWaiting(!0),v(this,vr,this._uiManager.imageManager.getFromFile(i).then(n=>y(this,ht,jc).call(this,n)).finally(()=>y(this,ht,Nc).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=wc.supportedTypesStr;const s=this._uiManager._signal;v(this,vr,new Promise(i=>{e.addEventListener("change",async()=>{if(!e.files||e.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const n=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),y(this,ht,jc).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>y(this,ht,Nc).call(this))),e.click()},Hp=function(){const{div:e}=this;let{width:s,height:i}=l(this,Gt);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 d=Math.min(o*n/s,o*r/i);s*=d,i*=d}const[h,c]=this.parentDimensions;this.setDims(s*h/n,i*c/r),this._uiManager.enableWaiting(!1);const u=v(this,Hi,document.createElement("canvas"));u.setAttribute("role","img"),this.addContainer(u),(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),y(this,ht,Vp).call(this,s,i),y(this,ht,My).call(this),l(this,ph)||(this.parent.addUndoableEditor(this),v(this,ph,!0)),this._reportTelemetry({action:"inserted_image"}),l(this,fh)&&u.setAttribute("aria-label",l(this,fh))},Py=function(e,s){var o;const[i,n]=this.parentDimensions;this.width=e/i,this.height=s/n,(o=this._initialOptions)!=null&&o.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,l(this,Vi)!==null&&clearTimeout(l(this,Vi)),v(this,Vi,setTimeout(()=>{v(this,Vi,null),y(this,ht,Vp).call(this,e,s)},200))},Zd=function(e,s){const{width:i,height:n}=l(this,Gt);let r=i,o=n,h=l(this,Gt);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},Vp=function(e,s){const i=new pf,n=Math.ceil(e*i.sx),r=Math.ceil(s*i.sy),o=l(this,Hi);if(!o||o.width===n&&o.height===r)return;o.width=n,o.height=r;const h=l(this,xs)?l(this,Gt):y(this,ht,Zd).call(this,n,r),c=o.getContext("2d");c.filter=this._uiManager.hcmFilter,c.drawImage(h,0,0,h.width,h.height,0,0,n,r)},tg=function(e){if(e){if(l(this,xs)){const n=this._uiManager.imageManager.getSvgUrl(l(this,we));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,xs)){const[s,i]=this.pageDimensions,n=Math.round(this.width*s*Xn.PDF_TO_CSS_UNITS),r=Math.round(this.height*i*Xn.PDF_TO_CSS_UNITS),o=new OffscreenCanvas(n,r);return o.getContext("2d").drawImage(l(this,Gt),0,0,l(this,Gt).width,l(this,Gt).height,0,0,n,r),o.transferToImageBitmap()}return structuredClone(l(this,Gt))},My=function(){this._uiManager._signal&&(v(this,Mn,new ResizeObserver(e=>{const s=e[0].contentRect;s.width&&s.height&&y(this,ht,Py).call(this,s.width,s.height)})),l(this,Mn).observe(this.div),this._uiManager._signal.addEventListener("abort",()=>{var e;(e=l(this,Mn))==null||e.disconnect(),v(this,Mn,null)},{once:!0}))},Oy=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(wc,"_type","stamp"),q(wc,"_editorType",it.STAMP);let Nf=wc;const pi=class pi{constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:o,textLayer:h,viewport:c,l10n:u}){_(this,It);_(this,Vo);_(this,mh,!1);_(this,Gi,null);_(this,yr,null);_(this,On,null);_(this,Vs,new Map);_(this,_r,!1);_(this,vh,!1);_(this,fi,null);_(this,De,null);_(this,Dn,null);_(this,Y);const d=[...l(pi,wr).values()];if(!pi._initialized){pi._initialized=!0;for(const g of d)g.initialize(u,t)}t.registerEditorTypes(d),v(this,Y,t),this.pageIndex=e,this.div=s,v(this,Vo,n),v(this,Gi,r),this.viewport=c,v(this,De,h),this.drawLayer=o,this._structTree=i,l(this,Y).addLayer(this)}get isEmpty(){return l(this,Vs).size===0}get isInvisible(){return this.isEmpty&&l(this,Y).getMode()===it.NONE}updateToolbar(t){l(this,Y).updateToolbar(t)}updateMode(t=l(this,Y).getMode()){switch(y(this,It,eg).call(this),t){case it.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case it.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case it.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(pi,wr).values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=l(this,De))==null?void 0:e.div)}setEditingState(t){l(this,Y).setEditingState(t)}addCommands(t){l(this,Y).addCommands(t)}cleanUndoStack(t){l(this,Y).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,Gi))==null||e.div.classList.toggle("disabled",!t)}async enable(){this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of l(this,Vs).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(l(this,Y).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!l(this,Gi))return;const e=l(this,Gi).getEditableAnnotations();for(const s of e){if(s.hide(),l(this,Y).isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}}disable(){var i;v(this,vh,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const n of l(this,Vs).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,Gi)){const n=l(this,Gi).getEditableAnnotations();for(const r of n){const{id:o}=r.data;if(l(this,Y).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,Y).addChangedExistingAnnotation(h),h.renderAnnotationElement(r)&&h.show(!1)),r.show()}}y(this,It,eg).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of l(pi,wr).values())s.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),v(this,vh,!1)}getEditableAnnotation(t){var e;return((e=l(this,Gi))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){l(this,Y).getActive()!==t&&l(this,Y).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=l(this,De))!=null&&t.div&&!l(this,Dn)){v(this,Dn,new AbortController);const e=l(this,Y).combinedSignal(l(this,Dn));l(this,De).div.addEventListener("pointerdown",y(this,It,Dy).bind(this),{signal:e}),l(this,De).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=l(this,De))!=null&&t.div&&l(this,Dn)&&(l(this,Dn).abort(),v(this,Dn,null),l(this,De).div.classList.remove("highlighting"))}enableClick(){if(l(this,yr))return;v(this,yr,new AbortController);const t=l(this,Y).combinedSignal(l(this,yr));this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t}),this.div.addEventListener("pointerup",this.pointerup.bind(this),{signal:t})}disableClick(){var t;(t=l(this,yr))==null||t.abort(),v(this,yr,null)}attach(t){l(this,Vs).set(t.id,t);const{annotationElementId:e}=t;e&&l(this,Y).isDeletedAnnotationElement(e)&&l(this,Y).removeDeletedAnnotationElement(t)}detach(t){var e;l(this,Vs).delete(t.id),(e=l(this,Vo))==null||e.removePointerInTextLayer(t.contentDiv),!l(this,vh)&&t.annotationElementId&&l(this,Y).addDeletedAnnotationElement(t)}remove(t){this.detach(t),l(this,Y).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(l(this,Y).addDeletedAnnotationElement(t.annotationElementId),Bt.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,Y).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(),l(this,Y).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!l(this,On)&&(t._focusEventsAllowed=!1,v(this,On,setTimeout(()=>{v(this,On,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:l(this,Y)._signal}),e.focus())},0))),t._structTreeParentId=(s=l(this,Vo))==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,Y).getId()}combinedSignal(t){return l(this,Y).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=l(this,It,Xi))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){l(this,Y).updateToolbar(t),l(this,Y).updateMode(t);const{offsetX:s,offsetY:i}=y(this,It,Wp).call(this),n=this.getNextId(),r=y(this,It,Gp).call(this,{parent:this,id:n,x:s,y:i,uiManager:l(this,Y),isCentered:!0,...e});r&&this.add(r)}async deserialize(t){var e;return await((e=l(pi,wr).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,l(this,Y)))||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=y(this,It,Gp).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:l(this,Y),isCentered:e,...s});return n&&this.add(n),n}addNewEditor(){this.createAndAddNewEditor(y(this,It,Wp).call(this),!0)}setSelected(t){l(this,Y).setSelected(t)}toggleSelected(t){l(this,Y).toggleSelected(t)}unselect(t){l(this,Y).unselect(t)}pointerup(t){var s;const{isMac:e}=Ge.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&l(this,_r)&&(v(this,_r,!1),!((s=l(this,It,Xi))!=null&&s.isDrawer&&l(this,It,Xi).supportMultipleDrawings))){if(!l(this,mh)){v(this,mh,!0);return}if(l(this,Y).getMode()===it.STAMP){l(this,Y).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){var i;if(l(this,Y).getMode()===it.HIGHLIGHT&&this.enableTextSelection(),l(this,_r)){v(this,_r,!1);return}const{isMac:e}=Ge.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(v(this,_r,!0),(i=l(this,It,Xi))!=null&&i.isDrawer){this.startDrawingSession(t);return}const s=l(this,Y).getActive();v(this,mh,!s||s.isEmpty())}startDrawingSession(t){if(this.div.focus(),l(this,fi)){l(this,It,Xi).startDrawing(this,l(this,Y),!1,t);return}l(this,Y).setCurrentDrawingSession(this),v(this,fi,new AbortController);const e=l(this,Y).combinedSignal(l(this,fi));this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&this.commitOrRemove()},{signal:e}),l(this,It,Xi).startDrawing(this,l(this,Y),!1,t)}endDrawingSession(t=!1){return l(this,fi)?(l(this,Y).setCurrentDrawingSession(null),l(this,fi).abort(),v(this,fi,null),l(this,It,Xi).endDrawing(t)):null}findNewParent(t,e,s){const i=l(this,Y).findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return l(this,fi)?(this.endDrawingSession(),!0):!1}onScaleChanging(){l(this,fi)&&l(this,It,Xi).onScaleChangingWhenDrawing(this)}destroy(){var t,e;this.commitOrRemove(),((t=l(this,Y).getActive())==null?void 0:t.parent)===this&&(l(this,Y).commitOrRemove(),l(this,Y).setActiveEditor(null)),l(this,On)&&(clearTimeout(l(this,On)),v(this,On,null));for(const s of l(this,Vs).values())(e=l(this,Vo))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,l(this,Vs).clear(),l(this,Y).removeLayer(this)}render({viewport:t}){this.viewport=t,Nr(this.div,t);for(const e of l(this,Y).getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){l(this,Y).commitOrRemove(),y(this,It,eg).call(this);const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,Nr(this.div,{rotation:s}),e!==s)for(const i of l(this,Vs).values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return l(this,Y).viewParameters.realScale}};Vo=new WeakMap,mh=new WeakMap,Gi=new WeakMap,yr=new WeakMap,On=new WeakMap,Vs=new WeakMap,_r=new WeakMap,vh=new WeakMap,fi=new WeakMap,De=new WeakMap,Dn=new WeakMap,Y=new WeakMap,wr=new WeakMap,It=new WeakSet,Dy=function(t){l(this,Y).unselectAll();const{target:e}=t;if(e===l(this,De).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&l(this,De).div.contains(e)){const{isMac:s}=Ge.platform;if(t.button!==0||t.ctrlKey&&s)return;l(this,Y).showAllEditors("highlight",!0,!0),l(this,De).div.classList.add("free"),this.toggleDrawing(),rd.startHighlighting(this,l(this,Y).direction==="ltr",{target:l(this,De).div,x:t.x,y:t.y}),l(this,De).div.addEventListener("pointerup",()=>{l(this,De).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:l(this,Y)._signal}),t.preventDefault()}},Xi=function(){return l(pi,wr).get(l(this,Y).getMode())},Gp=function(t){const e=l(this,It,Xi);return e?new e.prototype.constructor(t):null},Wp=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,g]=this.viewport.rotation%180===0?[c,u]:[u,c];return{offsetX:d,offsetY:g}},eg=function(){for(const t of l(this,Vs).values())t.isEmpty()&&t.remove()},q(pi,"_initialized",!1),_(pi,wr,new Map([Df,jf,Nf,rd].map(t=>[t._editorType,t])));let Bf=pi;const Re=class Re{constructor({pageIndex:t}){_(this,Wi);_(this,mi,null);_(this,xc,0);_(this,Ye,new Map);_(this,Go,new Map);this.pageIndex=t}setParent(t){if(!l(this,mi)){v(this,mi,t);return}if(l(this,mi)!==t){if(l(this,Ye).size>0)for(const e of l(this,Ye).values())e.remove(),t.append(e);v(this,mi,t)}}static get _svgFactory(){return at(this,"_svgFactory",new Pf)}draw(t,e=!1,s=!1){const i=Ke(this,xc)._++,n=y(this,Wi,zp).call(this),r=Re._svgFactory.createElement("defs");n.append(r);const o=Re._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,Go).set(i,o);const c=s?y(this,Wi,Ly).call(this,r,h):null,u=Re._svgFactory.createElement("use");return n.append(u),u.setAttribute("href",`#${h}`),this.updateProperties(n,t),l(this,Ye).set(i,n),{id:i,clipPathId:`url(#${c})`}}drawOutline(t,e){const s=Ke(this,xc)._++,i=y(this,Wi,zp).call(this),n=Re._svgFactory.createElement("defs");i.append(n);const r=Re._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=Re._svgFactory.createElement("mask");n.append(d),h=`mask_p${this.pageIndex}_${s}`,d.setAttribute("id",h),d.setAttribute("maskUnits","objectBoundingBox");const g=Re._svgFactory.createElement("rect");d.append(g),g.setAttribute("width","1"),g.setAttribute("height","1"),g.setAttribute("fill","white");const f=Re._svgFactory.createElement("use");d.append(f),f.setAttribute("href",`#${o}`),f.setAttribute("stroke","none"),f.setAttribute("fill","black"),f.setAttribute("fill-rule","nonzero"),f.classList.add("mask")}const c=Re._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,Ye).set(s,i),s}finalizeDraw(t,e){l(this,Go).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,Ye).get(t):t;if(o){if(s&&y(this,Wi,Xp).call(this,o,s),i&&y(h=Re,Ad,Ry).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;y(this,Wi,Xp).call(this,u,r)}}}updateParent(t,e){if(e===this)return;const s=l(this,Ye).get(t);s&&(l(e,mi).append(s),l(this,Ye).delete(t),l(e,Ye).set(t,s))}remove(t){l(this,Go).delete(t),l(this,mi)!==null&&(l(this,Ye).get(t).remove(),l(this,Ye).delete(t))}destroy(){v(this,mi,null);for(const t of l(this,Ye).values())t.remove();l(this,Ye).clear(),l(this,Go).clear()}};mi=new WeakMap,xc=new WeakMap,Ye=new WeakMap,Go=new WeakMap,Ad=new WeakSet,Ry=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}%`},Wi=new WeakSet,zp=function(){const t=Re._svgFactory.create(1,1,!0);return l(this,mi).append(t),t.setAttribute("aria-hidden",!0),t},Ly=function(t,e){const s=Re._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=Re._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i},Xp=function(t,e){for(const[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)},_(Re,Ad);let Hf=Re;globalThis.pdfjsTestingUtils={HighlightOutliner:Rf},Z.AbortException,Z.AnnotationEditorLayer,Z.AnnotationEditorParamsType,Z.AnnotationEditorType,Z.AnnotationEditorUIManager,Z.AnnotationLayer,Z.AnnotationMode,Z.ColorPicker,Z.DOMSVGFactory,Z.DrawLayer,Z.FeatureTest;var kC=Z.GlobalWorkerOptions;Z.ImageKind,Z.InvalidPDFException,Z.MissingPDFException,Z.OPS,Z.OutputScale,Z.PDFDataRangeTransport,Z.PDFDateString,Z.PDFWorker,Z.PasswordResponses,Z.PermissionFlag,Z.PixelsPerInch,Z.RenderingCancelledException,Z.TextLayer,Z.UnexpectedResponseException,Z.Util,Z.VerbosityLevel,Z.XfaLayer,Z.build,Z.createValidAbsoluteUrl,Z.fetchData;var PC=Z.getDocument;Z.getFilenameFromUrl,Z.getPdfFilenameFromUrl,Z.getXfaPageViewport,Z.isDataScheme,Z.isPdfFile,Z.noContextMenu,Z.normalizeUnicode,Z.setLayerDimensions,Z.shadow,Z.stopEvent,Z.version;const MC={fabric:"^6.5.3","pdfjs-dist":"4.9.155"};function OC(a){return new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>t(s.result)),s.addEventListener("error",e),s.readAsDataURL(a)})}const DC=MC["pdfjs-dist"].replace("^","");kC.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${DC}/pdf.worker.min.mjs`;async function RC(a){const t="data:application/pdf;base64,",e=await OC(a);if(typeof e=="string")return window.atob(e.slice(t.length))}function LC(a,t){return PC({data:a,password:t}).promise}const FC={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},IC={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},jC={stroke:"#000",hoverStroke:"#B7EC5D",src:""};function Kv(a=""){const t=J.useRef(0),e=J.useRef(null),s=J.useRef(null),i=J.useRef(1),n=J.useRef({...jC});function r(){if(!a||Es.has(a))return;const k=bx(a);return k.on("selection:cleared",()=>A(k)),k}function o(k,M){var I;const R=k.type,F={"application/pdf":h,"image/png":d,"image/jpeg":d};return((I=F[R])==null?void 0:I.call(F,k,M))??Promise.reject(new Error(`Unsupported ${R} file type.`))}async function h(k,M){const R=await RC(k);if(!R)return;const F=yx(k,R);try{return await c({page:1,PDFBase64:R,scale:.8,password:M}),{...F,pages:t.current}}catch(I){return Promise.reject(I)}}async function c({page:k,PDFBase64:M,scale:R,password:F}){try{const I=await LC(M,F),X=await I.getPage(k),{renderTask:j,canvas:N}=_x(X,R);return t.current=I.numPages,j.promise.then(()=>u(N))}catch(I){return Promise.reject(I)}}function u(k){xx(a,k)}async function d(k){return await Sx(a,k)}async function g({url:k,scale:M=.5}){await ev(a,{url:k,scale:M})}async function f(k,M){const R=Es.get(a);if(!R)return;const F=await Te.fromURL(k,{},{...FC,...M});R.add(F),m(R,F)}function p(k,M){const R=Es.get(a);if(!R)return;const F=new Ae(k,{...IC,...M});R.add(F),m(R,F)}function m(k,M){M.on("selected",R=>w({canvas:k,target:R.target})),M.on("modified",R=>zh(R.target,e.current)),M.on("scaling",R=>zh(R.transform.target,e.current)),M.on("moving",R=>zh(R.transform.target,e.current)),M.on("rotating",R=>zh(R.transform.target,e.current))}async function w({canvas:k,target:M,stroke:R=n.current.stroke,uuid:F=Date.now()}){var X;if(((X=e.current)==null?void 0:X.stroke)===`${R}-${F}`)return;const I=await wx(n.current.src,R,F);A(k),e.current=I,s.current=M,b(k,M,F),x(i.current,!0),k.add(I)}function b(k,M,R){e.current&&(e.current.on("selected",()=>{k.remove(M),A(k)}),e.current.on("mouseover",()=>{w({canvas:k,target:M,stroke:n.current.hoverStroke,uuid:R})}),e.current.on("mouseout",()=>{w({canvas:k,target:M,stroke:n.current.stroke,uuid:R})}))}function x(k,M=!1){const R=Es.get(a);i.current=k,R&&(Ax(s.current,k,n.current),Cx(s.current,k,e.current),!M&&R.renderAll())}function C(k){if(!k)return;n.current={...n.current,...k};const M=Es.get(a);!e||!s.current||!M||w({target:s.current,canvas:M})}function A(k){e.current&&(k.remove(e.current),e.current=s.current=null)}function P(){Tx(a)}function D(){Ex(a)}return{createCanvas:r,loadFile:o,specifyPage:c,renderImage:g,addFabric:f,addTextFabric:p,clearActive:P,deleteCanvas:D,scaleFabric:x,setCloseSvgOptions:C}}function NC(a){let t=0;const e=vx(()=>{t!==window.innerWidth&&(t=window.innerWidth,a())});J.useEffect(()=>(window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)),[])}const BC=J.forwardRef(HC);function HC({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},g){const f=J.useRef(null),p=`${e}-${t-1}`,m=J.useMemo(()=>s*n,[s,n]),{createCanvas:w,specifyPage:b,addFabric:x,addTextFabric:C,renderImage:A,clearActive:P,deleteCanvas:D,scaleFabric:k,setCloseSvgOptions:M}=Kv(p);NC(R);async function R(){window.requestAnimationFrame(async()=>{if(w(),a.PDFBase64.startsWith("data:image")||a.canvas){const{canvas:j}=a,N=j?7:3,nt=j!=null&&j.length?j[t-1]:a.PDFBase64;A({url:nt,scale:i/N});return}await b({page:t,PDFBase64:a.PDFBase64,scale:i,password:h})})}function F(j){if(j.preventDefault(),j.stopPropagation(),!o||!j.dataTransfer)return;const{dataTransfer:N,clientX:nt,clientY:K}=j,V=N.getData("text"),H=N.getData("image"),Et={left:nt-71,top:K-55};H&&I(H,Et),V&&X(V,Et)}function I(j,N){x(j,{...N,...u})}function X(j,N){C(j,{...N,...c})}return J.useImperativeHandle(g,()=>({addImage:I,addText:X,clearActive:P,deleteCanvas:D,canvasRef:f})),J.useEffect(()=>{R()},[i,t,a,h]),J.useEffect(()=>{k(m)},[m]),J.useEffect(()=>{M(d)},[d]),J.useEffect(()=>()=>D(),[]),$p.jsx("div",{style:{transform:`scale(${m})`},onDragOver:j=>j.preventDefault(),onDragEnter:j=>j.preventDefault(),onDrop:F,children:$p.jsx("canvas",{id:p,ref:f,className:r})})}ct.default=BC,ct.useFabric=Kv,Object.defineProperties(ct,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
534
|
+
`)}`),w(this,ie,pf).call(this);const f=new Range;let g=u.reduce((y,x)=>y+x.length,0);for(const{firstChild:y}of this.editorDiv.childNodes)if(y.nodeType===Node.TEXT_NODE){const x=y.nodeValue.length;if(g<=x){f.setStart(y,g),f.setEnd(y,g);break}g-=x}r.removeAllRanges(),r.addRange(f)}get contentDiv(){return this.editorDiv}static async deserialize(e,s,i){var a;let n=null;if(e instanceof d0){const{data:{defaultAppearanceData:{fontSize:h,fontColor:c},rect:u,rotation:d,id:f,popupRef:g},textContent:p,textPosition:b,parent:{page:{pageNumber:_}}}=e;if(!p||p.length===0)return null;n=e={annotationType:nt.FREETEXT,color:Array.from(c),fontSize:h,value:p.join(`
|
|
535
|
+
`),position:b,pageIndex:_-1,rect:u.slice(0),rotation:d,id:f,deleted:!1,popupRef:g}}const r=await super.deserialize(e,s,i);return m(r,xs,e.fontSize),m(r,ui,q.makeHexColor(...e.color)),m(r,ws,w(a=Ot,kn,Qp).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=Ot._internalPadding*this.parentScale,i=this.getRect(s,s),n=Ht._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:l(this,ui)),r={annotationType:nt.FREETEXT,color:n,fontSize:l(this,xs),value:w(this,ie,Pv).call(this),pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?r:this.annotationElementId&&!w(this,ie,Mv).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,xs)}px * var(--scale-factor))`,i.color=l(this,ui),s.replaceChildren();for(const r of l(this,ws).split(`
|
|
536
|
+
`)){const a=document.createElement("div");a.append(r?document.createTextNode(r):document.createElement("br")),s.append(a)}const n=Ot._internalPadding*this.parentScale;return e.updateEdited({rect:this.getRect(n,n),popupContent:l(this,ws)}),s}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}};ui=new WeakMap,ws=new WeakMap,Sc=new WeakMap,ja=new WeakMap,xs=new WeakMap,ie=new WeakSet,Tv=function(e){const s=n=>{this.editorDiv.style.fontSize=`calc(${n}px * var(--scale-factor))`,this.translate(0,-(n-l(this,xs))*this.parentScale),m(this,xs,n),w(this,ie,ff).call(this)},i=l(this,xs);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:dt.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})},Ev=function(e){const s=n=>{m(this,ui,this.editorDiv.style.color=n)},i=l(this,ui);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:dt.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})},kv=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,kn,gf).call(i,n)),s=n);return e.join(`
|
|
537
|
+
`)},ff=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()},kn=new WeakSet,gf=function(e){return(e.nodeType===Node.TEXT_NODE?e.nodeValue:e.innerText).replaceAll(xd,"")},pf=function(){if(this.editorDiv.replaceChildren(),!!l(this,ws))for(const e of l(this,ws).split(`
|
|
538
|
+
`)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},Pv=function(){return l(this,ws).replaceAll(" "," ")},Qp=function(e){return e.replaceAll(" "," ")},Mv=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},v(Ot,kn),J(Ot,"_freeTextDefaultContent",""),J(Ot,"_internalPadding",0),J(Ot,"_defaultColor",null),J(Ot,"_defaultFontSize",10),J(Ot,"_type","freetext"),J(Ot,"_editorType",nt.FREETEXT);let tp=Ot;class X{toSVGPath(){Et("Abstract method `toSVGPath` must be implemented.")}get box(){Et("Abstract getter `box` must be implemented.")}serialize(t,e){Et("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]}}J(X,"PRECISION",1e-4);const Pn=class Pn{constructor({x:t,y:e},s,i,n,r,a=0){v(this,ce);v(this,Ss);v(this,di,[]);v(this,oh);v(this,hh);v(this,ji,[]);v(this,lt,new Float32Array(18));v(this,Na);v(this,Ba);v(this,Cc);v(this,Ac);v(this,lh);v(this,ch);v(this,yr,[]);m(this,Ss,s),m(this,ch,n*i),m(this,hh,r),l(this,lt).set([NaN,NaN,NaN,NaN,t,e],6),m(this,oh,a),m(this,Ac,l(Pn,Tc)*i),m(this,Cc,l(Pn,Wd)*i),m(this,lh,i),l(this,yr).push(t,e)}isEmpty(){return isNaN(l(this,lt)[8])}add({x:t,y:e}){var R;m(this,Na,t),m(this,Ba,e);const[s,i,n,r]=l(this,Ss);let[a,h,c,u]=l(this,lt).subarray(8,12);const d=t-c,f=e-u,g=Math.hypot(d,f);if(g<l(this,Cc))return!1;const p=g-l(this,Ac),b=p/g,_=b*d,y=b*f;let x=a,C=h;a=c,h=u,c+=_,u+=y,(R=l(this,yr))==null||R.push(t,e);const A=-y/p,P=_/p,D=A*l(this,ch),k=P*l(this,ch);return l(this,lt).set(l(this,lt).subarray(2,8),0),l(this,lt).set([c+D,u+k],4),l(this,lt).set(l(this,lt).subarray(14,18),12),l(this,lt).set([c-D,u-k],16),isNaN(l(this,lt)[6])?(l(this,ji).length===0&&(l(this,lt).set([a+D,h+k],2),l(this,ji).push(NaN,NaN,NaN,NaN,(a+D-s)/n,(h+k-i)/r),l(this,lt).set([a-D,h-k],14),l(this,di).push(NaN,NaN,NaN,NaN,(a-D-s)/n,(h-k-i)/r)),l(this,lt).set([x,C,a,h,c,u],6),!this.isEmpty()):(l(this,lt).set([x,C,a,h,c,u],6),Math.abs(Math.atan2(C-h,x-a)-Math.atan2(y,_))<Math.PI/2?([a,h,c,u]=l(this,lt).subarray(2,6),l(this,ji).push(NaN,NaN,NaN,NaN,((a+c)/2-s)/n,((h+u)/2-i)/r),[a,h,x,C]=l(this,lt).subarray(14,18),l(this,di).push(NaN,NaN,NaN,NaN,((x+a)/2-s)/n,((C+h)/2-i)/r),!0):([x,C,a,h,c,u]=l(this,lt).subarray(0,6),l(this,ji).push(((x+5*a)/6-s)/n,((C+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,C]=l(this,lt).subarray(12,18),l(this,di).push(((x+5*a)/6-s)/n,((C+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,ji),e=l(this,di);if(isNaN(l(this,lt)[6])&&!this.isEmpty())return w(this,ce,Ov).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,ce,Rv).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,ce,Dv).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new m0(t,e,s,i,n,r)}getOutlines(){var d;const t=l(this,ji),e=l(this,di),s=l(this,lt),[i,n,r,a]=l(this,Ss),h=new Float32Array((((d=l(this,yr))==null?void 0:d.length)??0)+2);for(let f=0,g=h.length-2;f<g;f+=2)h[f]=(l(this,yr)[f]-i)/r,h[f+1]=(l(this,yr)[f+1]-n)/a;if(h[h.length-2]=(l(this,Na)-i)/r,h[h.length-1]=(l(this,Ba)-n)/a,isNaN(s[6])&&!this.isEmpty())return w(this,ce,Lv).call(this,h);const c=new Float32Array(l(this,ji).length+24+l(this,di).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,ce,Iv).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,ce,Fv).call(this,c,u),this.newFreeDrawOutline(c,h,l(this,Ss),l(this,lh),l(this,oh),l(this,hh))}};Ss=new WeakMap,di=new WeakMap,oh=new WeakMap,hh=new WeakMap,ji=new WeakMap,lt=new WeakMap,Na=new WeakMap,Ba=new WeakMap,Cc=new WeakMap,Ac=new WeakMap,lh=new WeakMap,ch=new WeakMap,yr=new WeakMap,Tc=new WeakMap,Vd=new WeakMap,Wd=new WeakMap,ce=new WeakSet,Zc=function(){const t=l(this,lt).subarray(4,6),e=l(this,lt).subarray(16,18),[s,i,n,r]=l(this,Ss);return[(l(this,Na)+(t[0]-e[0])/2-s)/n,(l(this,Ba)+(t[1]-e[1])/2-i)/r,(l(this,Na)+(e[0]-t[0])/2-s)/n,(l(this,Ba)+(e[1]-t[1])/2-i)/r]},Ov=function(){const[t,e,s,i]=l(this,Ss),[n,r,a,h]=w(this,ce,Zc).call(this);return`M${(l(this,lt)[2]-t)/s} ${(l(this,lt)[3]-e)/i} L${(l(this,lt)[4]-t)/s} ${(l(this,lt)[5]-e)/i} L${n} ${r} L${a} ${h} L${(l(this,lt)[16]-t)/s} ${(l(this,lt)[17]-e)/i} L${(l(this,lt)[14]-t)/s} ${(l(this,lt)[15]-e)/i} Z`},Dv=function(t){const e=l(this,di);t.push(`L${e[4]} ${e[5]} Z`)},Rv=function(t){const[e,s,i,n]=l(this,Ss),r=l(this,lt).subarray(4,6),a=l(this,lt).subarray(16,18),[h,c,u,d]=w(this,ce,Zc).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}`)},Lv=function(t){const e=l(this,lt),[s,i,n,r]=l(this,Ss),[a,h,c,u]=w(this,ce,Zc).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,Ss),l(this,lh),l(this,oh),l(this,hh))},Fv=function(t,e){const s=l(this,di);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},Iv=function(t,e){const s=l(this,lt).subarray(4,6),i=l(this,lt).subarray(16,18),[n,r,a,h]=l(this,Ss),[c,u,d,f]=w(this,ce,Zc).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},v(Pn,Tc,8),v(Pn,Vd,2),v(Pn,Wd,l(Pn,Tc)+l(Pn,Vd));let Sd=Pn;class m0 extends X{constructor(e,s,i,n,r,a){super();v(this,zd);v(this,uh);v(this,Ha,new Float32Array(4));v(this,Mn);v(this,Ec);v(this,Cs);v(this,kc);v(this,Jt);m(this,Jt,e),m(this,Cs,s),m(this,uh,i),m(this,kc,n),m(this,Mn,r),m(this,Ec,a),this.lastPoint=[NaN,NaN],w(this,zd,jv).call(this,a);const[h,c,u,d]=l(this,Ha);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,Jt)[4]} ${l(this,Jt)[5]}`];for(let s=6,i=l(this,Jt).length;s<i;s+=6){if(isNaN(l(this,Jt)[s])){e.push(`L${l(this,Jt)[s+4]} ${l(this,Jt)[s+5]}`);continue}e.push(`C${l(this,Jt)[s]} ${l(this,Jt)[s+1]} ${l(this,Jt)[s+2]} ${l(this,Jt)[s+3]} ${l(this,Jt)[s+4]} ${l(this,Jt)[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=X._rescale(l(this,Jt),e,n,a,-h),u=X._rescale(l(this,Cs),e,n,a,-h);break;case 90:c=X._rescaleAndSwap(l(this,Jt),e,s,a,h),u=X._rescaleAndSwap(l(this,Cs),e,s,a,h);break;case 180:c=X._rescale(l(this,Jt),i,s,-a,h),u=X._rescale(l(this,Cs),i,s,-a,h);break;case 270:c=X._rescaleAndSwap(l(this,Jt),i,n,-a,-h),u=X._rescaleAndSwap(l(this,Cs),i,n,-a,-h);break}return{outline:Array.from(c),points:[Array.from(u)]}}get box(){return l(this,Ha)}newOutliner(e,s,i,n,r,a=0){return new Sd(e,s,i,n,r,a)}getNewOutline(e,s){const[i,n,r,a]=l(this,Ha),[h,c,u,d]=l(this,uh),f=r*u,g=a*d,p=i*u+h,b=n*d+c,_=this.newOutliner({x:l(this,Cs)[0]*f+p,y:l(this,Cs)[1]*g+b},l(this,uh),l(this,kc),e,l(this,Ec),s??l(this,Mn));for(let y=2;y<l(this,Cs).length;y+=2)_.add({x:l(this,Cs)[y]*f+p,y:l(this,Cs)[y+1]*g+b});return _.getOutlines()}}uh=new WeakMap,Ha=new WeakMap,Mn=new WeakMap,Ec=new WeakMap,Cs=new WeakMap,kc=new WeakMap,Jt=new WeakMap,zd=new WeakSet,jv=function(e){const s=l(this,Jt);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,b=s.length;p<b;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 _=q.bezierBoundingBox(i,n,...s.slice(p,p+6));r=Math.min(r,_[0]),a=Math.min(a,_[1]),h=Math.max(h,_[2]),c=Math.max(c,_[3]),d<_[3]?(u=_[2],d=_[3]):d===_[3]&&(u=f(u,_[2]))}i=s[p+4],n=s[p+5]}const g=l(this,Ha);g[0]=r-l(this,Mn),g[1]=a-l(this,Mn),g[2]=h-r+2*l(this,Mn),g[3]=c-a+2*l(this,Mn),this.lastPoint=[u,d]};class ep{constructor(t,e=0,s=0,i=!0){v(this,Ye);v(this,Pc);v(this,Mc);v(this,vr,[]);v(this,fi,[]);let n=1/0,r=-1/0,a=1/0,h=-1/0;const c=10**-4;for(const{x:_,y,width:x,height:C}of t){const A=Math.floor((_-e)/c)*c,P=Math.ceil((_+x+e)/c)*c,D=Math.floor((y-e)/c)*c,k=Math.ceil((y+C+e)/c)*c,M=[A,D,k,!0],R=[P,D,k,!1];l(this,vr).push(M,R),n=Math.min(n,A),r=Math.max(r,P),a=Math.min(a,D),h=Math.max(h,k)}const u=r-n+2*s,d=h-a+2*s,f=n-s,g=a-s,p=l(this,vr).at(i?-1:-2),b=[p[0],p[2]];for(const _ of l(this,vr)){const[y,x,C]=_;_[0]=(y-f)/u,_[1]=(x-g)/d,_[2]=(C-g)/d}m(this,Pc,new Float32Array([f,g,u,d])),m(this,Mc,b)}getOutlines(){l(this,vr).sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of l(this,vr))e[3]?(t.push(...w(this,Ye,Zp).call(this,e)),w(this,Ye,Bv).call(this,e)):(w(this,Ye,Hv).call(this,e),t.push(...w(this,Ye,Zp).call(this,e)));return w(this,Ye,Nv).call(this,t)}}Pc=new WeakMap,Mc=new WeakMap,vr=new WeakMap,fi=new WeakMap,Ye=new WeakSet,Nv=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 qC(i,l(this,Pc),l(this,Mc))},mf=function(t){const e=l(this,fi);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},Bv=function([,t,e]){const s=w(this,Ye,mf).call(this,t);l(this,fi).splice(s,0,[t,e])},Hv=function([,t,e]){const s=w(this,Ye,mf).call(this,t);for(let i=s;i<l(this,fi).length;i++){const[n,r]=l(this,fi)[i];if(n!==t)break;if(n===t&&r===e){l(this,fi).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=l(this,fi)[i];if(n!==t)break;if(n===t&&r===e){l(this,fi).splice(i,1);return}}},Zp=function(t){const[e,s,i]=t,n=[[e,s,i]],r=w(this,Ye,mf).call(this,i);for(let a=0;a<r;a++){const[h,c]=l(this,fi)[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 qC extends X{constructor(e,s,i){super();v(this,Oc);v(this,dh);m(this,dh,e),m(this,Oc,s),this.lastPoint=i}toSVGPath(){const e=[];for(const s of l(this,dh)){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,dh)){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,Oc)}get classNamesForOutlining(){return["highlightOutline"]}}Oc=new WeakMap,dh=new WeakMap;class sp extends Sd{newFreeDrawOutline(t,e,s,i,n,r){return new KC(t,e,s,i,n,r)}}class KC extends m0{newOutliner(t,e,s,i,n,r=0){return new sp(t,e,s,i,n,r)}}const hs=class hs{constructor({editor:t=null,uiManager:e=null}){v(this,At);v(this,gi,null);v(this,Va,null);v(this,fh);v(this,ue,null);v(this,Dc,!1);v(this,gh,!1);v(this,Rc,null);v(this,Lc);v(this,_r,null);v(this,pi,null);v(this,ph);var s;t?(m(this,gh,!1),m(this,ph,dt.HIGHLIGHT_COLOR),m(this,Rc,t)):(m(this,gh,!0),m(this,ph,dt.HIGHLIGHT_DEFAULT_COLOR)),m(this,pi,(t==null?void 0:t._uiManager)||e),m(this,Lc,l(this,pi)._eventBus),m(this,fh,(t==null?void 0:t.color)||((s=l(this,pi))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),l(hs,Fc)||m(hs,Fc,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 ht(this,"_keyboardManager",new cl([[["Escape","mac+Escape"],hs.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],hs.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],hs.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],hs.prototype._moveToPrevious],[["Home","mac+Home"],hs.prototype._moveToBeginning],[["End","mac+End"],hs.prototype._moveToEnd]]))}renderButton(){const t=m(this,gi,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,pi)._signal;t.addEventListener("click",w(this,At,io).bind(this),{signal:e}),t.addEventListener("keydown",w(this,At,sm).bind(this),{signal:e});const s=m(this,Va,document.createElement("span"));return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=l(this,fh),t.append(s),t}renderMainDropdown(){const t=m(this,ue,w(this,At,tm).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===l(this,gi)){w(this,At,io).call(this,t);return}const e=t.target.getAttribute("data-color");e&&w(this,At,em).call(this,e,t)}_moveToNext(t){var e,s;if(!l(this,At,Pr)){w(this,At,io).call(this,t);return}if(t.target===l(this,gi)){(e=l(this,ue).firstChild)==null||e.focus();return}(s=t.target.nextSibling)==null||s.focus()}_moveToPrevious(t){var e,s;if(t.target===((e=l(this,ue))==null?void 0:e.firstChild)||t.target===l(this,gi)){l(this,At,Pr)&&this._hideDropdownFromKeyboard();return}l(this,At,Pr)||w(this,At,io).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!l(this,At,Pr)){w(this,At,io).call(this,t);return}(e=l(this,ue).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!l(this,At,Pr)){w(this,At,io).call(this,t);return}(e=l(this,ue).lastChild)==null||e.focus()}hideDropdown(){var t,e;(t=l(this,ue))==null||t.classList.add("hidden"),(e=l(this,_r))==null||e.abort(),m(this,_r,null)}_hideDropdownFromKeyboard(){var t;if(!l(this,gh)){if(!l(this,At,Pr)){(t=l(this,Rc))==null||t.unselect();return}this.hideDropdown(),l(this,gi).focus({preventScroll:!0,focusVisible:l(this,Dc)})}}updateColor(t){if(l(this,Va)&&(l(this,Va).style.backgroundColor=t),!l(this,ue))return;const e=l(this,pi).highlightColors.values();for(const s of l(this,ue).children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){var t,e;(t=l(this,gi))==null||t.remove(),m(this,gi,null),m(this,Va,null),(e=l(this,ue))==null||e.remove(),m(this,ue,null)}};gi=new WeakMap,Va=new WeakMap,fh=new WeakMap,ue=new WeakMap,Dc=new WeakMap,gh=new WeakMap,Rc=new WeakMap,Lc=new WeakMap,_r=new WeakMap,pi=new WeakMap,ph=new WeakMap,Fc=new WeakMap,At=new WeakSet,tm=function(){const t=document.createElement("div"),e=l(this,pi)._signal;t.addEventListener("contextmenu",ii,{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,pi).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(hs,Fc)[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===l(this,fh)),n.addEventListener("click",w(this,At,em).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",w(this,At,sm).bind(this),{signal:e}),t},em=function(t,e){e.stopPropagation(),l(this,Lc).dispatch("switchannotationeditorparams",{source:this,type:l(this,ph),value:t})},sm=function(t){hs._keyboardManager.exec(this,t)},io=function(t){if(l(this,At,Pr)){this.hideDropdown();return}if(m(this,Dc,t.detail===0),l(this,_r)||(m(this,_r,new AbortController),window.addEventListener("pointerdown",w(this,At,Vv).bind(this),{signal:l(this,pi).combinedSignal(l(this,_r))})),l(this,ue)){l(this,ue).classList.remove("hidden");return}const e=m(this,ue,w(this,At,tm).call(this));l(this,gi).append(e)},Vv=function(t){var e;(e=l(this,ue))!=null&&e.contains(t.target)||this.hideDropdown()},Pr=function(){return l(this,ue)&&!l(this,ue).classList.contains("hidden")},v(hs,Fc,null);let Cd=hs;const yt=class yt extends Ht{constructor(e){super({...e,name:"highlightEditor"});v(this,st);v(this,mh,null);v(this,Ic,0);v(this,On);v(this,Wa,null);v(this,bh,null);v(this,ls,null);v(this,jc,null);v(this,Nc,0);v(this,za,null);v(this,Hs,null);v(this,As,null);v(this,_e,!1);v(this,yh,null);v(this,Dn);v(this,Le,null);v(this,vh,"");v(this,Vs);v(this,Bc,"");this.color=e.color||yt._defaultColor,m(this,Vs,e.thickness||yt._defaultThickness),m(this,Dn,e.opacity||yt._defaultOpacity),m(this,On,e.boxes||null),m(this,Bc,e.methodOfCreation||""),m(this,vh,e.text||""),this._isDraggable=!1,e.highlightId>-1?(m(this,_e,!0),w(this,st,bf).call(this,e),w(this,st,no).call(this)):l(this,On)&&(m(this,mh,e.anchorNode),m(this,Ic,e.anchorOffset),m(this,jc,e.focusNode),m(this,Nc,e.focusOffset),w(this,st,im).call(this),w(this,st,no).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=yt.prototype;return ht(this,"_keyboardManager",new cl([[["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,_e)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:l(this,Vs),methodOfCreation:l(this,Bc)}}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;Ht.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 dt.HIGHLIGHT_DEFAULT_COLOR:yt._defaultColor=s;break;case dt.HIGHLIGHT_THICKNESS:yt._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return l(this,yh)}updateParams(e,s){switch(e){case dt.HIGHLIGHT_COLOR:w(this,st,Wv).call(this,s);break;case dt.HIGHLIGHT_THICKNESS:w(this,st,zv).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[dt.HIGHLIGHT_DEFAULT_COLOR,yt._defaultColor],[dt.HIGHLIGHT_THICKNESS,yt._defaultThickness]]}get propertiesToUpdate(){return[[dt.HIGHLIGHT_COLOR,this.color||yt._defaultColor],[dt.HIGHLIGHT_THICKNESS,l(this,Vs)||yt._defaultThickness],[dt.HIGHLIGHT_FREE,l(this,_e)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(m(this,bh,new Cd({editor:this})),e.addColorPicker(l(this,bh))),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,st,tu).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,w(this,st,tu).call(this))}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),e&&this.div.focus()}remove(){w(this,st,nm).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,st,no).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?w(this,st,nm).call(this):e&&(w(this,st,no).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,_e)?(e=(e-this.rotation+360)%360,i=w(n=yt,Ws,Nh).call(n,l(this,Hs).box,e)):i=w(r=yt,Ws,Nh).call(r,[this.x,this.y,this.width,this.height],e),s.updateProperties(l(this,As),{bbox:i,root:{"data-main-rotation":e}}),s.updateProperties(l(this,Le),{bbox:w(a=yt,Ws,Nh).call(a,l(this,ls).box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();l(this,vh)&&(e.setAttribute("aria-label",l(this,vh)),e.setAttribute("role","mark")),l(this,_e)?e.classList.add("free"):this.div.addEventListener("keydown",w(this,st,Xv).bind(this),{signal:this._uiManager._signal});const s=m(this,za,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=l(this,Wa);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),gd(this,l(this,za),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Le),{rootClass:{hovered:!0}})}pointerleave(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Le),{rootClass:{hovered:!1}})}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:w(this,st,yf).call(this,!0);break;case 1:case 3:w(this,st,yf).call(this,!1);break}}select(){var e;super.select(),l(this,Le)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Le),{rootClass:{hovered:!1,selected:!0}}))}unselect(){var e;super.unselect(),l(this,Le)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Le),{rootClass:{selected:!1}}),l(this,_e)||w(this,st,yf).call(this,!1))}get _mustFixPosition(){return!l(this,_e)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(l(this,As),{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(l(this,Le),{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,Ws,qv).call(this,e,p)};window.addEventListener("blur",g,{signal:f}),window.addEventListener("pointerup",g,{signal:f}),window.addEventListener("pointerdown",gs,{capture:!0,passive:!1,signal:f}),window.addEventListener("contextmenu",ii,{signal:f}),i.addEventListener("pointermove",w(this,Ws,$v).bind(this,e),{signal:f}),this._freeHighlight=new sp({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 b,_,y,x;let n=null;if(e instanceof g0){const{data:{quadPoints:C,rect:A,rotation:P,id:D,color:k,opacity:M,popupRef:R},parent:{page:{pageNumber:F}}}=e;n=e={annotationType:nt.HIGHLIGHT,color:Array.from(k),opacity:M,quadPoints:C,boxes:null,pageIndex:F-1,rect:A.slice(0),rotation:P,id:D,deleted:!1,popupRef:R}}else if(e instanceof Zg){const{data:{inkLists:C,rect:A,rotation:P,id:D,color:k,borderStyle:{rawWidth:M},popupRef:R},parent:{page:{pageNumber:F}}}=e;n=e={annotationType:nt.HIGHLIGHT,color:Array.from(k),thickness:M,inkLists:C,boxes:null,pageIndex:F-1,rect:A.slice(0),rotation:P,id:D,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),m(u,Dn,c||1),h&&m(u,Vs,e.thickness),u.annotationElementId=e.id||null,u._initialData=n;const[d,f]=u.pageDimensions,[g,p]=u.pageTranslation;if(a){const C=m(u,On,[]);for(let A=0;A<a.length;A+=8)C.push({x:(a[A]-g)/d,y:1-(a[A+1]-p)/f,width:(a[A+2]-a[A])/d,height:(a[A+1]-a[A+5])/f});w(b=u,st,im).call(b),w(_=u,st,no).call(_),u.rotate(u.rotation)}else if(h){m(u,_e,!0);const C=h[0],A={x:C[0]-g,y:f-(C[1]-p)},P=new sp(A,[0,0,d,f],1,l(u,Vs)/2,!0,.001);for(let M=0,R=C.length;M<R;M+=2)A.x=C[M]-g,A.y=f-(C[M+1]-p),P.add(A);const{id:D,clipPathId:k}=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:P.toSVGPath()}},!0,!0);w(y=u,st,bf).call(y,{highlightOutlines:P.getOutlines(),highlightId:D,clipPathId:k}),w(x=u,st,no).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=Ht._colorManager.convert(this.color),n={annotationType:nt.HIGHLIGHT,color:i,opacity:l(this,Dn),thickness:l(this,Vs),quadPoints:w(this,st,Uv).call(this),outlines:w(this,st,Yv).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:w(this,st,tu).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!w(this,st,Kv).call(this,n)?null:(n.id=this.annotationElementId,n)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};mh=new WeakMap,Ic=new WeakMap,On=new WeakMap,Wa=new WeakMap,bh=new WeakMap,ls=new WeakMap,jc=new WeakMap,Nc=new WeakMap,za=new WeakMap,Hs=new WeakMap,As=new WeakMap,_e=new WeakMap,yh=new WeakMap,Dn=new WeakMap,Le=new WeakMap,vh=new WeakMap,Vs=new WeakMap,Bc=new WeakMap,st=new WeakSet,im=function(){const e=new ep(l(this,On),.001);m(this,Hs,e.getOutlines()),[this.x,this.y,this.width,this.height]=l(this,Hs).box;const s=new ep(l(this,On),.0025,.001,this._uiManager.direction==="ltr");m(this,ls,s.getOutlines());const{lastPoint:i}=l(this,ls);m(this,yh,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height])},bf=function({highlightOutlines:e,highlightId:s,clipPathId:i}){var d,f;if(m(this,Hs,e),m(this,ls,e.getNewOutline(l(this,Vs)/2+1.5,.0025)),s>=0)m(this,As,s),m(this,Wa,i),this.parent.drawLayer.finalizeDraw(s,{bbox:e.box,path:{d:e.toSVGPath()}}),m(this,Le,this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:l(this,ls).box,path:{d:l(this,ls).toSVGPath()}},!0));else if(this.parent){const g=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(l(this,As),{bbox:w(d=yt,Ws,Nh).call(d,l(this,Hs).box,(g-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(l(this,Le),{bbox:w(f=yt,Ws,Nh).call(f,l(this,ls).box,g),path:{d:l(this,ls).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,ls);m(this,yh,[(u[0]-r)/h,(u[1]-a)/c])},Wv=function(e){const s=(r,a)=>{var h,c;this.color=r,m(this,Dn,a),(h=this.parent)==null||h.drawLayer.updateProperties(l(this,As),{root:{fill:r,"fill-opacity":a}}),(c=l(this,bh))==null||c.updateColor(r)},i=this.color,n=l(this,Dn);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:dt.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},zv=function(e){const s=l(this,Vs),i=n=>{m(this,Vs,n),w(this,st,Gv).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:dt.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},Gv=function(e){if(!l(this,_e))return;w(this,st,bf).call(this,{highlightOutlines:l(this,Hs).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},nm=function(){l(this,As)===null||!this.parent||(this.parent.drawLayer.remove(l(this,As)),m(this,As,null),this.parent.drawLayer.remove(l(this,Le)),m(this,Le,null))},no=function(e=this.parent){l(this,As)===null&&({id:Ze(this,As)._,clipPathId:Ze(this,Wa)._}=e.drawLayer.draw({bbox:l(this,Hs).box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":l(this,Dn)},rootClass:{highlight:!0,free:l(this,_e)},path:{d:l(this,Hs).toSVGPath()}},!1,!0),m(this,Le,e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:l(this,_e)},bbox:l(this,ls).box,path:{d:l(this,ls).toSVGPath()}},l(this,_e))),l(this,za)&&(l(this,za).style.clipPath=l(this,Wa)))},Ws=new WeakSet,Nh=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]},Xv=function(e){yt._keyboardManager.exec(this,e)},yf=function(e){if(!l(this,mh))return;const s=window.getSelection();e?s.setPosition(l(this,mh),l(this,Ic)):s.setPosition(l(this,jc),l(this,Nc))},tu=function(){return l(this,_e)?this.rotation:0},Uv=function(){if(l(this,_e))return null;const[e,s]=this.pageDimensions,[i,n]=this.pageTranslation,r=l(this,On),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},Yv=function(e){return l(this,Hs).serialize(e,w(this,st,tu).call(this))},$v=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},qv=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=""},Kv=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},v(yt,Ws),J(yt,"_defaultColor",null),J(yt,"_defaultOpacity",1),J(yt,"_defaultThickness",12),J(yt,"_type","highlight"),J(yt,"_editorType",nt.HIGHLIGHT),J(yt,"_freeHighlightId",-1),J(yt,"_freeHighlight",null),J(yt,"_freeHighlightClipId","");let Ad=yt;class JC{constructor(){v(this,Ga,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,Ga)[t]=e}toSVGProperties(){const t=l(this,Ga);return m(this,Ga,Object.create(null)),{root:t}}reset(){m(this,Ga,Object.create(null))}updateAll(t=this){this.updateProperties(t)}clone(){Et("Not implemented")}}Ga=new WeakMap;const U=class U extends Ht{constructor(e){super(e);v(this,mt);v(this,Ts,null);v(this,_h);J(this,"_drawId",null);m(this,_h,e.mustBeCommitted||!1),e.drawOutlines&&(w(this,mt,rm).call(this,e),w(this,mt,eu).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){Et("Not implemented")}static get typesMap(){Et("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(U,pe).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,Ts).updateProperty(s,h);c&&w(this,mt,su).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,U._mergeSVGProperties(l(this,Ts).getPathResizingSVGProperties(w(this,mt,vf).call(this)),{bbox:w(this,mt,Bh).call(this)}))}_onResized(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,U._mergeSVGProperties(l(this,Ts).getPathResizedSVGProperties(w(this,mt,vf).call(this)),{bbox:w(this,mt,Bh).call(this)}))}_onTranslating(e,s){var i;(i=this.parent)==null||i.drawLayer.updateProperties(this._drawId,{bbox:w(this,mt,Bh).call(this,e,s)})}_onTranslated(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,U._mergeSVGProperties(l(this,Ts).getPathTranslatedSVGProperties(w(this,mt,vf).call(this),this.parentDimensions),{bbox:w(this,mt,Bh).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,_h)&&(m(this,_h,!1),this.commit(),this.parent.setSelected(this),e&&this.isOnScreen&&this.div.focus())}remove(){w(this,mt,om).call(this),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,mt,eu).call(this),w(this,mt,su).call(this,l(this,Ts).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),w(this,mt,om).call(this)):e&&(this._uiManager.addShouldRescale(this),w(this,mt,eu).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,U._mergeSVGProperties({bbox:w(this,mt,Bh).call(this)},l(this,Ts).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&w(this,mt,su).call(this,l(this,Ts).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){Et("Not implemented")}static startDrawing(e,s,i,n){var _;const{target:r,offsetX:a,offsetY:h,pointerId:c,pointerType:u}=n;if(l(U,xr)&&l(U,xr)!==u)return;const{viewport:{rotation:d}}=e,{width:f,height:g}=r.getBoundingClientRect(),p=m(U,Xa,new AbortController),b=e.combinedSignal(p);if(l(U,wr)||m(U,wr,c),l(U,xr)??m(U,xr,u),window.addEventListener("pointerup",y=>{var x;l(U,wr)===y.pointerId?this._endDraw(y):(x=l(U,Sr))==null||x.delete(y.pointerId)},{signal:b}),window.addEventListener("pointercancel",y=>{var x;l(U,wr)===y.pointerId?this._currentParent.endDrawingSession():(x=l(U,Sr))==null||x.delete(y.pointerId)},{signal:b}),window.addEventListener("pointerdown",y=>{l(U,xr)===y.pointerType&&((l(U,Sr)||m(U,Sr,new Set)).add(y.pointerId),l(U,pe).isCancellable()&&(l(U,pe).removeLastElement(),l(U,pe).isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:b}),window.addEventListener("contextmenu",ii,{signal:b}),r.addEventListener("pointermove",this._drawMove.bind(this),{signal:b}),r.addEventListener("touchmove",y=>{y.timeStamp===l(U,Ya)&&gs(y)},{signal:b}),e.toggleDrawing(),(_=s._editorUndoBar)==null||_.hide(),l(U,pe)){e.drawLayer.updateProperties(this._currentDrawId,l(U,pe).startNew(a,h,f,g,d));return}s.updateUIForDefaultProperties(this),m(U,pe,this.createDrawerInstance(a,h,f,g,d)),m(U,Ua,this.getDefaultDrawingOptions()),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(l(U,Ua).toSVGProperties(),l(U,pe).defaultSVGProperties),!0,!1)}static _drawMove(e){var r;if(m(U,Ya,-1),!l(U,pe))return;const{offsetX:s,offsetY:i,pointerId:n}=e;if(l(U,wr)===n){if(((r=l(U,Sr))==null?void 0:r.size)>=1){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,l(U,pe).add(s,i)),m(U,Ya,e.timeStamp),gs(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,m(U,pe,null),m(U,Ua,null),m(U,xr,null),m(U,Ya,NaN)),l(U,Xa)&&(l(U,Xa).abort(),m(U,Xa,null),m(U,wr,NaN),m(U,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(U,pe).end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const i=l(U,pe),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:dt.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const s=this._currentParent;if(!s)return null;if(s.toggleDrawing(!0),s.cleanUndoStack(dt.DRAW_STEP),!l(U,pe).isEmpty()){const{pageDimensions:[i,n],scale:r}=s,a=s.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:l(U,pe).getOutlines(i*r,n*r,r,this._INNER_MARGIN),drawingOptions:l(U,Ua),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){Et("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,rm).call(d,{drawOutlines:c}),w(f=u,mt,eu).call(f),u.onScaleChanging(),u.rotate(),u}serializeDraw(e){const[s,i]=this.pageTranslation,[n,r]=this.pageDimensions;return l(this,Ts).serialize([s,i,n,r],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};Ts=new WeakMap,_h=new WeakMap,pe=new WeakMap,Xa=new WeakMap,Ua=new WeakMap,wr=new WeakMap,xr=new WeakMap,Sr=new WeakMap,Ya=new WeakMap,mt=new WeakSet,rm=function({drawOutlines:e,drawId:s,drawingOptions:i}){m(this,Ts,e),this._drawingOptions||(this._drawingOptions=i),s>=0?(this._drawId=s,this.parent.drawLayer.finalizeDraw(s,e.defaultProperties)):this._drawId=w(this,mt,am).call(this,e,this.parent),w(this,mt,su).call(this,e.box)},am=function(e,s){const{id:i}=s.drawLayer.draw(U._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return i},om=function(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())},eu=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,am).call(this,l(this,Ts),e)}},Jv=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]}},vf=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]}},su=function(e){if([this.x,this.y,this.width,this.height]=w(this,mt,Jv).call(this,e),this.div){this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)}this._onResized()},Bh=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]}},J(U,"_currentDrawId",-1),J(U,"_currentParent",null),v(U,pe,null),v(U,Xa,null),v(U,Ua,null),v(U,wr,NaN),v(U,xr,null),v(U,Sr,null),v(U,Ya,NaN),J(U,"_INNER_MARGIN",3);let ip=U;class QC{constructor(t,e,s,i,n,r){v(this,xh);v(this,Ni,new Float64Array(6));v(this,me);v(this,be);v(this,$a);v(this,wh);v(this,$e);v(this,we,"");v(this,zs,0);v(this,qa,new Td);v(this,Ka);v(this,Ja);m(this,Ka,s),m(this,Ja,i),m(this,$a,n),m(this,wh,r),[t,e]=w(this,xh,_f).call(this,t,e);const a=m(this,me,[NaN,NaN,NaN,NaN,t,e]);m(this,$e,[t,e]),m(this,be,[{line:a,points:l(this,$e)}]),l(this,Ni).set(a,0)}updateProperty(t,e){t==="stroke-width"&&m(this,wh,e)}isEmpty(){return!l(this,be)||l(this,be).length===0}isCancellable(){return l(this,$e).length<=10}add(t,e){[t,e]=w(this,xh,_f).call(this,t,e);const[s,i,n,r]=l(this,Ni).subarray(2,6),a=t-n,h=e-r;return Math.hypot(l(this,Ka)*a,l(this,Ja)*h)<=2?null:(l(this,$e).push(t,e),isNaN(s)?(l(this,Ni).set([n,r,t,e],2),l(this,me).push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(l(this,Ni)[0])&&l(this,me).splice(6,6),l(this,Ni).set([s,i,n,r,t,e],0),l(this,me).push(...X.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const s=this.add(t,e);return s||(l(this,$e).length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){m(this,Ka,s),m(this,Ja,i),m(this,$a,n),[t,e]=w(this,xh,_f).call(this,t,e);const r=m(this,me,[NaN,NaN,NaN,NaN,t,e]);m(this,$e,[t,e]);const a=l(this,be).at(-1);return a&&(a.line=new Float32Array(a.line),a.points=new Float32Array(a.points)),l(this,be).push({line:r,points:l(this,$e)}),l(this,Ni).set(r,0),m(this,zs,0),this.toSVGPath(),null}getLastElement(){return l(this,be).at(-1)}setLastElement(t){return l(this,be)?(l(this,be).push(t),m(this,me,t.line),m(this,$e,t.points),m(this,zs,0),{path:{d:this.toSVGPath()}}):l(this,qa).setLastElement(t)}removeLastElement(){if(!l(this,be))return l(this,qa).removeLastElement();l(this,be).pop(),m(this,we,"");for(let t=0,e=l(this,be).length;t<e;t++){const{line:s,points:i}=l(this,be)[t];m(this,me,s),m(this,$e,i),m(this,zs,0),this.toSVGPath()}return{path:{d:l(this,we)}}}toSVGPath(){const t=X.svgRound(l(this,me)[4]),e=X.svgRound(l(this,me)[5]);if(l(this,$e).length===2)return m(this,we,`${l(this,we)} M ${t} ${e} Z`),l(this,we);if(l(this,$e).length<=6){const i=l(this,we).lastIndexOf("M");m(this,we,`${l(this,we).slice(0,i)} M ${t} ${e}`),m(this,zs,6)}if(l(this,$e).length===4){const i=X.svgRound(l(this,me)[10]),n=X.svgRound(l(this,me)[11]);return m(this,we,`${l(this,we)} L ${i} ${n}`),m(this,zs,12),l(this,we)}const s=[];l(this,zs)===0&&(s.push(`M ${t} ${e}`),m(this,zs,6));for(let i=l(this,zs),n=l(this,me).length;i<n;i+=6){const[r,a,h,c,u,d]=l(this,me).slice(i,i+6).map(X.svgRound);s.push(`C${r} ${a} ${h} ${c} ${u} ${d}`)}return m(this,we,l(this,we)+s.join(" ")),m(this,zs,l(this,me).length),l(this,we)}getOutlines(t,e,s,i){const n=l(this,be).at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),l(this,qa).build(l(this,be),t,e,s,l(this,$a),l(this,wh),i),m(this,Ni,null),m(this,me,null),m(this,be,null),m(this,we,null),l(this,qa)}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}Ni=new WeakMap,me=new WeakMap,be=new WeakMap,$a=new WeakMap,wh=new WeakMap,$e=new WeakMap,we=new WeakMap,zs=new WeakMap,qa=new WeakMap,Ka=new WeakMap,Ja=new WeakMap,xh=new WeakSet,_f=function(t,e){return X._normalizePoint(t,e,l(this,Ka),l(this,Ja),l(this,$a))};const fp=class fp extends X{constructor(){super(...arguments);v(this,xe);v(this,qe);v(this,Hc,0);v(this,Vc);v(this,Es);v(this,Bi);v(this,Hi);v(this,Sh);v(this,Ch);v(this,Ah)}build(e,s,i,n,r,a,h){m(this,Bi,s),m(this,Hi,i),m(this,Sh,n),m(this,Ch,r),m(this,Ah,a),m(this,Vc,h??0),m(this,Es,e),w(this,xe,Zv).call(this)}setLastElement(e){return l(this,Es).push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return l(this,Es).pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:s}of l(this,Es)){if(e.push(`M${X.svgRound(s[4])} ${X.svgRound(s[5])}`),s.length===6){e.push("Z");continue}if(s.length===12){e.push(`L${X.svgRound(s[10])} ${X.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(X.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,xe,Qv).call(this);let g,p,b,_,y,x,C,A,P;switch(l(this,Ch)){case 0:P=X._rescale,g=e,p=s+n,b=i,_=-n,y=e+c*i,x=s+(1-u-f)*n,C=e+(c+d)*i,A=s+(1-u)*n;break;case 90:P=X._rescaleAndSwap,g=e,p=s,b=i,_=n,y=e+u*i,x=s+c*n,C=e+(u+f)*i,A=s+(c+d)*n;break;case 180:P=X._rescale,g=e+i,p=s,b=-i,_=n,y=e+(1-c-d)*i,x=s+u*n,C=e+(1-c)*i,A=s+(u+f)*n;break;case 270:P=X._rescaleAndSwap,g=e+i,p=s+n,b=-i,_=-n,y=e+(1-u-f)*i,x=s+(1-c-d)*n,C=e+(1-u)*i,A=s+(1-c)*n;break}for(const{line:D,points:k}of l(this,Es))a.push(P(D,g,p,b,_,r?new Array(D.length):null)),h.push(P(k,g,p,b,_,r?new Array(k.length):null));return{lines:a,points:h,rect:[y,x,C,A]}}static deserialize(e,s,i,n,r,{paths:{lines:a,points:h},rotation:c,thickness:u}){const d=[];let f,g,p,b,_;switch(c){case 0:_=X._rescale,f=-e/i,g=s/n+1,p=1/i,b=-1/n;break;case 90:_=X._rescaleAndSwap,f=-s/n,g=-e/i,p=1/n,b=1/i;break;case 180:_=X._rescale,f=e/i+1,g=-s/n,p=-1/i,b=1/n;break;case 270:_=X._rescaleAndSwap,f=s/n+1,g=e/i+1,p=-1/n,b=-1/i;break}if(!a){a=[];for(const x of h){const C=x.length;if(C===2){a.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1]]));continue}if(C===4){a.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1],NaN,NaN,NaN,NaN,x[2],x[3]]));continue}const A=new Float32Array(3*(C-2));a.push(A);let[P,D,k,M]=x.subarray(0,4);A.set([NaN,NaN,NaN,NaN,P,D],0);for(let R=4;R<C;R+=2){const F=x[R],I=x[R+1];A.set(X.createBezierPoints(P,D,k,M,F,I),(R-2)*3),[P,D,k,M]=[k,M,F,I]}}}for(let x=0,C=a.length;x<C;x++)d.push({line:_(a[x].map(A=>A??NaN),f,g,p,b),points:_(h[x].map(A=>A??NaN),f,g,p,b)});const y=new fp;return y.build(d,i,n,1,c,u,r),y}get box(){return l(this,qe)}updateProperty(e,s){return e==="stroke-width"?w(this,xe,t_).call(this,s):null}updateParentDimensions([e,s],i){const[n,r]=w(this,xe,Nn).call(this);m(this,Bi,e),m(this,Hi,s),m(this,Sh,i);const[a,h]=w(this,xe,Nn).call(this),c=a-n,u=h-r,d=l(this,qe);return d[0]-=c,d[1]-=u,d[2]+=2*c,d[3]+=2*u,d}updateRotation(e){return m(this,Hc,e),{path:{transform:this.rotationTransform}}}get viewBox(){return l(this,qe).map(X.svgRound).join(" ")}get defaultProperties(){const[e,s]=l(this,qe);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${X.svgRound(e)} ${X.svgRound(s)}`}}}get rotationTransform(){const[,,e,s]=l(this,qe);let i=0,n=0,r=0,a=0,h=0,c=0;switch(l(this,Hc)){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} ${X.svgRound(h)} ${X.svgRound(c)})`}getPathResizingSVGProperties([e,s,i,n]){const[r,a]=w(this,xe,Nn).call(this),[h,c,u,d]=l(this,qe);if(Math.abs(u-r)<=X.PRECISION||Math.abs(d-a)<=X.PRECISION){const _=e+i/2-(h+u/2),y=s+n/2-(c+d/2);return{path:{"transform-origin":`${X.svgRound(e)} ${X.svgRound(s)}`,transform:`${this.rotationTransform} translate(${_} ${y})`}}}const f=(i-2*r)/(u-2*r),g=(n-2*a)/(d-2*a),p=u/i,b=d/n;return{path:{"transform-origin":`${X.svgRound(h)} ${X.svgRound(c)}`,transform:`${this.rotationTransform} scale(${p} ${b}) translate(${X.svgRound(r)} ${X.svgRound(a)}) scale(${f} ${g}) translate(${X.svgRound(-r)} ${X.svgRound(-a)})`}}}getPathResizedSVGProperties([e,s,i,n]){const[r,a]=w(this,xe,Nn).call(this),h=l(this,qe),[c,u,d,f]=h;if(h[0]=e,h[1]=s,h[2]=i,h[3]=n,Math.abs(d-r)<=X.PRECISION||Math.abs(f-a)<=X.PRECISION){const y=e+i/2-(c+d/2),x=s+n/2-(u+f/2);for(const{line:C,points:A}of l(this,Es))X._translate(C,y,x,C),X._translate(A,y,x,A);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${X.svgRound(e)} ${X.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const g=(i-2*r)/(d-2*r),p=(n-2*a)/(f-2*a),b=-g*(c+r)+e+r,_=-p*(u+a)+s+a;if(g!==1||p!==1||b!==0||_!==0)for(const{line:y,points:x}of l(this,Es))X._rescale(y,b,_,g,p,y),X._rescale(x,b,_,g,p,x);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${X.svgRound(e)} ${X.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,s],i){const[n,r]=i,a=l(this,qe),h=e-a[0],c=s-a[1];if(l(this,Bi)===n&&l(this,Hi)===r)for(const{line:u,points:d}of l(this,Es))X._translate(u,h,c,u),X._translate(d,h,c,d);else{const u=l(this,Bi)/n,d=l(this,Hi)/r;m(this,Bi,n),m(this,Hi,r);for(const{line:f,points:g}of l(this,Es))X._rescale(f,h,c,u,d,f),X._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":`${X.svgRound(e)} ${X.svgRound(s)}`}}}get defaultSVGProperties(){const e=l(this,qe);return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${X.svgRound(e[0])} ${X.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}};qe=new WeakMap,Hc=new WeakMap,Vc=new WeakMap,Es=new WeakMap,Bi=new WeakMap,Hi=new WeakMap,Sh=new WeakMap,Ch=new WeakMap,Ah=new WeakMap,xe=new WeakSet,Nn=function(e=l(this,Ah)){const s=l(this,Vc)+e/2*l(this,Sh);return l(this,Ch)%180===0?[s/l(this,Bi),s/l(this,Hi)]:[s/l(this,Hi),s/l(this,Bi)]},Qv=function(){const[e,s,i,n]=l(this,qe),[r,a]=w(this,xe,Nn).call(this,0);return[e+r,s+a,i-2*r,n-2*a]},Zv=function(){const e=m(this,qe,new Float32Array([1/0,1/0,-1/0,-1/0]));for(const{line:n}of l(this,Es)){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,b]=n.subarray(h,h+6);q.bezierBoundingBox(r,a,u,d,f,g,p,b,e),r=p,a=b}}const[s,i]=w(this,xe,Nn).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]},t_=function(e){const[s,i]=w(this,xe,Nn).call(this);m(this,Ah,e);const[n,r]=w(this,xe,Nn).call(this),[a,h]=[n-s,r-i],c=l(this,qe);return c[0]-=a,c[1]-=h,c[2]+=2*a,c[3]+=2*h,c};let Td=fp;const gp=class gp extends JC{constructor(e){super();v(this,Th);m(this,Th,e),super.updateProperties({fill:"none",stroke:Ht._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,Th).realScale),super.updateSVGProperty(e,s)}clone(){const e=new gp(l(this,Th));return e.updateAll(this),e}};Th=new WeakMap;let np=gp;const Eh=class Eh extends ip{constructor(e){super({...e,name:"inkEditor"});v(this,Gd);this._willKeepAspectRatio=!0}static initialize(e,s){Ht.initialize(e,s),this._defaultDrawingOptions=new np(s.viewParameters)}static getDefaultDrawingOptions(e){const s=this._defaultDrawingOptions.clone();return s.updateProperties(e),s}static get supportMultipleDrawings(){return!0}static get typesMap(){return ht(this,"typesMap",new Map([[dt.INK_THICKNESS,"stroke-width"],[dt.INK_COLOR,"stroke"],[dt.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(e,s,i,n,r){return new QC(e,s,i,n,r,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(e,s,i,n,r,a){return Td.deserialize(e,s,i,n,r,a)}static async deserialize(e,s,i){let n=null;if(e instanceof Zg){const{data:{inkLists:a,rect:h,rotation:c,id:u,color:d,opacity:f,borderStyle:{rawWidth:g},popupRef:p},parent:{page:{pageNumber:b}}}=e;n=e={annotationType:nt.INK,color:Array.from(d),thickness:g,opacity:f,paths:{points:a},boxes:null,pageIndex:b-1,rect:h.slice(0),rotation:c,id:u,deleted:!1,popupRef:p}}const r=await super.deserialize(e,s,i);return r.annotationElementId=e.id||null,r._initialData=n,r}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:e,_drawingOptions:s,parent:i}=this;s.updateSVGProperty("stroke-width"),i.drawLayer.updateProperties(e,s.toSVGProperties())}static onScaleChangingWhenDrawing(){const e=this._currentParent;e&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:e,thickness:s,opacity:i}){this._drawingOptions=Eh.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:nt.INK,color:Ht._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,Gd,e_).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}};Gd=new WeakSet,e_=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},J(Eh,"_type","ink"),J(Eh,"_editorType",nt.INK),J(Eh,"_defaultDrawingOptions",null);let rp=Eh;const Wc=class Wc extends Ht{constructor(e){super({...e,name:"stampEditor"});v(this,bt);v(this,Wt,null);v(this,Se,null);v(this,Cr,null);v(this,Rn,null);v(this,Ar,null);v(this,kh,"");v(this,Vi,null);v(this,Wi,null);v(this,ks,!1);v(this,Ph,!1);m(this,Rn,e.bitmapUrl),m(this,Ar,e.bitmapFile)}static initialize(e,s){Ht.initialize(e,s)}static get supportedTypes(){return ht(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return ht(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(e){return this.supportedTypes.includes(e)}static paste(e,s){s.pasteEditor(nt.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,Se)&&(m(this,Wt,null),this._uiManager.imageManager.deleteId(l(this,Se)),(e=l(this,Vi))==null||e.remove(),m(this,Vi,null),l(this,Wi)&&(clearTimeout(l(this,Wi)),m(this,Wi,null))),super.remove()}rebuild(){if(!this.parent){l(this,Se)&&w(this,bt,wf).call(this);return}super.rebuild(),this.div!==null&&(l(this,Se)&&l(this,Vi)===null&&w(this,bt,wf).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,Rn)||l(this,Ar)||l(this,Se))}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,hm).call(this):w(this,bt,wf).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,Wi)!==null&&clearTimeout(l(this,Wi)),m(this,Wi,setTimeout(()=>{m(this,Wi,null),w(this,bt,lm).call(this)},200))}copyCanvas(e,s,i=!1){var g;e||(e=224);const{width:n,height:r}=l(this,Wt),a=new jg;let h=l(this,Wt),c=n,u=r,d=null;if(s){if(n>s||r>s){const M=Math.min(s/n,s/r);c=Math.floor(n*M),u=Math.floor(r*M)}d=document.createElement("canvas");const p=d.width=Math.ceil(c*a.sx),b=d.height=Math.ceil(u*a.sy);l(this,ks)||(h=w(this,bt,xf).call(this,p,b));const _=d.getContext("2d");_.filter=this._uiManager.hcmFilter;let y="white",x="#cfcfd8";this._uiManager.hcmFilter!=="none"?x="black":(g=window.matchMedia)!=null&&g.call(window,"(prefers-color-scheme: dark)").matches&&(y="#8f8f9d",x="#42414d");const C=15,A=C*a.sx,P=C*a.sy,D=new OffscreenCanvas(A*2,P*2),k=D.getContext("2d");k.fillStyle=y,k.fillRect(0,0,A*2,P*2),k.fillStyle=x,k.fillRect(0,0,A,P),k.fillRect(A,P,A,P),_.fillStyle=_.createPattern(D,"repeat"),_.fillRect(0,0,p,b),_.drawImage(h,0,0,h.width,h.height,0,0,p,b)}let f=null;if(i){let p,b;if(a.symmetric&&h.width<e&&h.height<e)p=h.width,b=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),b=Math.floor(r*x),l(this,ks)||(h=w(this,bt,xf).call(this,p,b))}const y=new OffscreenCanvas(p,b).getContext("2d",{willReadFrequently:!0});y.drawImage(h,0,0,h.width,h.height,0,0,p,b),f={width:p,height:b,data:y.getImageData(0,0,p,b).data}}return{canvas:d,width:c,height:u,imageData:f}}getImageForAltText(){return l(this,Vi)}static async deserialize(e,s,i){var b;let n=null;if(e instanceof p0){const{data:{rect:_,rotation:y,id:x,structParent:C,popupRef:A},container:P,parent:{page:{pageNumber:D}}}=e,k=P.querySelector("canvas"),M=i.imageManager.getFromCanvas(P.id,k);k.remove();const R=((b=await s._structTree.getAriaAttributes(`${Dg}${x}`))==null?void 0:b.get("aria-label"))||"";n=e={annotationType:nt.STAMP,bitmapId:M.id,bitmap:M.bitmap,pageIndex:D-1,rect:_.slice(0),rotation:y,id:x,deleted:!1,accessibilityData:{decorative:!1,altText:R},isSvg:!1,structParent:C,popupRef:A}}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)?(m(r,Se,u),h&&m(r,Wt,h)):m(r,Rn,c),m(r,ks,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,m(r,Ph,!!n),r}serialize(e=!1,s=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const i={annotationType:nt.STAMP,bitmapId:l(this,Se),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:l(this,ks),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=w(this,bt,Sf).call(this,!0),i.accessibilityData=this.serializeAltText(!0),i;const{decorative:n,altText:r}=this.serializeAltText(!1);if(!n&&r&&(i.accessibilityData={type:"Figure",alt:r}),this.annotationElementId){const h=w(this,bt,s_).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,ks)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!s.stamps.has(l(this,Se)))s.stamps.set(l(this,Se),{area:a,serialized:i}),i.bitmap=w(this,bt,Sf).call(this,!1);else if(l(this,ks)){const h=s.stamps.get(l(this,Se));a>h.area&&(h.area=a,h.serialized.bitmap.close(),h.serialized.bitmap=w(this,bt,Sf).call(this,!1))}return i}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}};Wt=new WeakMap,Se=new WeakMap,Cr=new WeakMap,Rn=new WeakMap,Ar=new WeakMap,kh=new WeakMap,Vi=new WeakMap,Wi=new WeakMap,ks=new WeakMap,Ph=new WeakMap,bt=new WeakSet,iu=function(e,s=!1){if(!e){this.remove();return}m(this,Wt,e.bitmap),s||(m(this,Se,e.id),m(this,ks,e.isSvg)),e.file&&m(this,kh,e.file.name),w(this,bt,hm).call(this)},nu=function(){if(m(this,Cr,null),this._uiManager.enableWaiting(!1),!!l(this,Vi)){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()}},wf=function(){if(l(this,Se)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(l(this,Se)).then(i=>w(this,bt,iu).call(this,i,!0)).finally(()=>w(this,bt,nu).call(this));return}if(l(this,Rn)){const i=l(this,Rn);m(this,Rn,null),this._uiManager.enableWaiting(!0),m(this,Cr,this._uiManager.imageManager.getFromUrl(i).then(n=>w(this,bt,iu).call(this,n)).finally(()=>w(this,bt,nu).call(this)));return}if(l(this,Ar)){const i=l(this,Ar);m(this,Ar,null),this._uiManager.enableWaiting(!0),m(this,Cr,this._uiManager.imageManager.getFromFile(i).then(n=>w(this,bt,iu).call(this,n)).finally(()=>w(this,bt,nu).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=Wc.supportedTypesStr;const s=this._uiManager._signal;m(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,iu).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>w(this,bt,nu).call(this))),e.click()},hm=function(){var d;const{div:e}=this;let{width:s,height:i}=l(this,Wt);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=m(this,Vi,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,lm).call(this),l(this,Ph)||(this.parent.addUndoableEditor(this),m(this,Ph,!0)),this._reportTelemetry({action:"inserted_image"}),l(this,kh)&&u.setAttribute("aria-label",l(this,kh))},xf=function(e,s){const{width:i,height:n}=l(this,Wt);let r=i,a=n,h=l(this,Wt);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},lm=function(){const[e,s]=this.parentDimensions,{width:i,height:n}=this,r=new jg,a=Math.ceil(i*e*r.sx),h=Math.ceil(n*s*r.sy),c=l(this,Vi);if(!c||c.width===a&&c.height===h)return;c.width=a,c.height=h;const u=l(this,ks)?l(this,Wt):w(this,bt,xf).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)},Sf=function(e){if(e){if(l(this,ks)){const n=this._uiManager.imageManager.getSvgUrl(l(this,Se));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,ks)){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,Wt),0,0,l(this,Wt).width,l(this,Wt).height,0,0,n,r),a.transferToImageBitmap()}return structuredClone(l(this,Wt))},s_=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}},J(Wc,"_type","stamp"),J(Wc,"_editorType",nt.STAMP);let ap=Wc;const bi=class bi{constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:a,textLayer:h,viewport:c,l10n:u}){v(this,Nt);v(this,Qa);v(this,Mh,!1);v(this,zi,null);v(this,Tr,null);v(this,Ln,null);v(this,Gs,new Map);v(this,Er,!1);v(this,Oh,!1);v(this,Za,!1);v(this,mi,null);v(this,Fn,null);v(this,Fe,null);v(this,In,null);v(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),m(this,$,t),this.pageIndex=e,this.div=s,m(this,Qa,n),m(this,zi,r),this.viewport=c,m(this,Fe,h),this.drawLayer=a,this._structTree=i,l(this,$).addLayer(this)}get isEmpty(){return l(this,Gs).size===0}get isInvisible(){return this.isEmpty&&l(this,$).getMode()===nt.NONE}updateToolbar(t){l(this,$).updateToolbar(t)}updateMode(t=l(this,$).getMode()){switch(w(this,Nt,Cf).call(this),t){case nt.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case nt.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case nt.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,Fe))==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,zi))==null||e.div.classList.toggle("disabled",!t)}async enable(){m(this,Za,!0),this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of l(this,Gs).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(l(this,$).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!l(this,zi)){m(this,Za,!1);return}const e=l(this,zi).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())}m(this,Za,!1)}disable(){var i;m(this,Oh,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const n of l(this,Gs).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,zi)){const n=l(this,zi).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,Cf).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),m(this,Oh,!1)}getEditableAnnotation(t){var e;return((e=l(this,zi))==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,Fe))!=null&&t.div&&!l(this,In)){m(this,In,new AbortController);const e=l(this,$).combinedSignal(l(this,In));l(this,Fe).div.addEventListener("pointerdown",w(this,Nt,i_).bind(this),{signal:e}),l(this,Fe).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=l(this,Fe))!=null&&t.div&&l(this,In)&&(l(this,In).abort(),m(this,In,null),l(this,Fe).div.classList.remove("highlighting"))}enableClick(){if(l(this,Tr))return;m(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(),m(this,Tr,null)}attach(t){l(this,Gs).set(t.id,t);const{annotationElementId:e}=t;e&&l(this,$).isDeletedAnnotationElement(e)&&l(this,$).removeDeletedAnnotationElement(t)}detach(t){var e;l(this,Gs).delete(t.id),(e=l(this,Qa))==null||e.removePointerInTextLayer(t.contentDiv),!l(this,Oh)&&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),Ht.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,Za)),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,m(this,Ln,setTimeout(()=>{m(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,Qa))==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,Ui))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){l(this,$).updateToolbar(t),l(this,$).updateMode(t);const{offsetX:s,offsetY:i}=w(this,Nt,um).call(this),n=this.getNextId(),r=w(this,Nt,cm).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,cm).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,um).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}=Ge.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&l(this,Er)&&(m(this,Er,!1),!((s=l(this,Nt,Ui))!=null&&s.isDrawer&&l(this,Nt,Ui).supportMultipleDrawings))){if(!l(this,Mh)){m(this,Mh,!0);return}if(l(this,$).getMode()===nt.STAMP){l(this,$).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){var i;if(l(this,$).getMode()===nt.HIGHLIGHT&&this.enableTextSelection(),l(this,Er)){m(this,Er,!1);return}const{isMac:e}=Ge.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(m(this,Er,!0),(i=l(this,Nt,Ui))!=null&&i.isDrawer){this.startDrawingSession(t);return}const s=l(this,$).getActive();m(this,Mh,!s||s.isEmpty())}startDrawingSession(t){if(this.div.focus(),l(this,mi)){l(this,Nt,Ui).startDrawing(this,l(this,$),!1,t);return}l(this,$).setCurrentDrawingSession(this),m(this,mi,new AbortController);const e=l(this,$).combinedSignal(l(this,mi));this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(m(this,Fn,null),this.commitOrRemove())},{signal:e}),l(this,Nt,Ui).startDrawing(this,l(this,$),!1,t)}pause(t){if(t){const{activeElement:e}=document;this.div.contains(e)&&m(this,Fn,e);return}l(this,Fn)&&setTimeout(()=>{var e;(e=l(this,Fn))==null||e.focus(),m(this,Fn,null)},0)}endDrawingSession(t=!1){return l(this,mi)?(l(this,$).setCurrentDrawingSession(null),l(this,mi).abort(),m(this,mi,null),m(this,Fn,null),l(this,Nt,Ui).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,mi)?(this.endDrawingSession(),!0):!1}onScaleChanging(){l(this,mi)&&l(this,Nt,Ui).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)),m(this,Ln,null));for(const s of l(this,Gs).values())(e=l(this,Qa))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,l(this,Gs).clear(),l(this,$).removeLayer(this)}render({viewport:t}){this.viewport=t,Gr(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,Cf).call(this);const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,Gr(this.div,{rotation:s}),e!==s)for(const i of l(this,Gs).values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return l(this,$).viewParameters.realScale}};Qa=new WeakMap,Mh=new WeakMap,zi=new WeakMap,Tr=new WeakMap,Ln=new WeakMap,Gs=new WeakMap,Er=new WeakMap,Oh=new WeakMap,Za=new WeakMap,mi=new WeakMap,Fn=new WeakMap,Fe=new WeakMap,In=new WeakMap,$=new WeakMap,kr=new WeakMap,Nt=new WeakSet,i_=function(t){l(this,$).unselectAll();const{target:e}=t;if(e===l(this,Fe).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&l(this,Fe).div.contains(e)){const{isMac:s}=Ge.platform;if(t.button!==0||t.ctrlKey&&s)return;l(this,$).showAllEditors("highlight",!0,!0),l(this,Fe).div.classList.add("free"),this.toggleDrawing(),Ad.startHighlighting(this,l(this,$).direction==="ltr",{target:l(this,Fe).div,x:t.x,y:t.y}),l(this,Fe).div.addEventListener("pointerup",()=>{l(this,Fe).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:l(this,$)._signal}),t.preventDefault()}},Ui=function(){return l(bi,kr).get(l(this,$).getMode())},cm=function(t){const e=l(this,Nt,Ui);return e?new e.prototype.constructor(t):null},um=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}},Cf=function(){for(const t of l(this,Gs).values())t.isEmpty()&&t.remove()},J(bi,"_initialized",!1),v(bi,kr,new Map([tp,rp,ap,Ad].map(t=>[t._editorType,t])));let op=bi;const Ie=class Ie{constructor({pageIndex:t}){v(this,Gi);v(this,yi,null);v(this,zc,0);v(this,Ke,new Map);v(this,to,new Map);this.pageIndex=t}setParent(t){if(!l(this,yi)){m(this,yi,t);return}if(l(this,yi)!==t){if(l(this,Ke).size>0)for(const e of l(this,Ke).values())e.remove(),t.append(e);m(this,yi,t)}}static get _svgFactory(){return ht(this,"_svgFactory",new Jg)}draw(t,e=!1,s=!1){const i=Ze(this,zc)._++,n=w(this,Gi,dm).call(this),r=Ie._svgFactory.createElement("defs");n.append(r);const a=Ie._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,to).set(i,a);const c=s?w(this,Gi,r_).call(this,r,h):null,u=Ie._svgFactory.createElement("use");return n.append(u),u.setAttribute("href",`#${h}`),this.updateProperties(n,t),l(this,Ke).set(i,n),{id:i,clipPathId:`url(#${c})`}}drawOutline(t,e){const s=Ze(this,zc)._++,i=w(this,Gi,dm).call(this),n=Ie._svgFactory.createElement("defs");i.append(n);const r=Ie._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=Ie._svgFactory.createElement("mask");n.append(d),h=`mask_p${this.pageIndex}_${s}`,d.setAttribute("id",h),d.setAttribute("maskUnits","objectBoundingBox");const f=Ie._svgFactory.createElement("rect");d.append(f),f.setAttribute("width","1"),f.setAttribute("height","1"),f.setAttribute("fill","white");const g=Ie._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=Ie._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,Ke).set(s,i),s}finalizeDraw(t,e){l(this,to).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,Ke).get(t):t;if(a){if(s&&w(this,Gi,fm).call(this,a,s),i&&w(h=Ie,Xd,n_).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,Gi,fm).call(this,u,r)}}}updateParent(t,e){if(e===this)return;const s=l(this,Ke).get(t);s&&(l(e,yi).append(s),l(this,Ke).delete(t),l(e,Ke).set(t,s))}remove(t){l(this,to).delete(t),l(this,yi)!==null&&(l(this,Ke).get(t).remove(),l(this,Ke).delete(t))}destroy(){m(this,yi,null);for(const t of l(this,Ke).values())t.remove();l(this,Ke).clear(),l(this,to).clear()}};yi=new WeakMap,zc=new WeakMap,Ke=new WeakMap,to=new WeakMap,Xd=new WeakSet,n_=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}%`},Gi=new WeakSet,dm=function(){const t=Ie._svgFactory.create(1,1,!0);return l(this,yi).append(t),t.setAttribute("aria-hidden",!0),t},r_=function(t,e){const s=Ie._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=Ie._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i},fm=function(t,e){for(const[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)},v(Ie,Xd);let hp=Ie;globalThis.pdfjsTestingUtils={HighlightOutliner:ep},Z.AbortException,Z.AnnotationEditorLayer,Z.AnnotationEditorParamsType,Z.AnnotationEditorType,Z.AnnotationEditorUIManager,Z.AnnotationLayer,Z.AnnotationMode,Z.ColorPicker,Z.DOMSVGFactory,Z.DrawLayer,Z.FeatureTest;var ZC=Z.GlobalWorkerOptions;Z.ImageKind,Z.InvalidPDFException,Z.MissingPDFException,Z.OPS,Z.OutputScale,Z.PDFDataRangeTransport,Z.PDFDateString,Z.PDFWorker,Z.PasswordResponses,Z.PermissionFlag,Z.PixelsPerInch,Z.RenderingCancelledException,Z.TextLayer,Z.TouchManager,Z.UnexpectedResponseException,Z.Util,Z.VerbosityLevel,Z.XfaLayer,Z.build,Z.createValidAbsoluteUrl,Z.fetchData;var tA=Z.getDocument;Z.getFilenameFromUrl,Z.getPdfFilenameFromUrl,Z.getXfaPageViewport,Z.isDataScheme,Z.isPdfFile,Z.noContextMenu,Z.normalizeUnicode,Z.setLayerDimensions,Z.shadow,Z.stopEvent,Z.version;const eA={fabric:"^6.5.4","pdfjs-dist":"4.10.38"};function sA(o){return new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>t(s.result)),s.addEventListener("error",e),s.readAsDataURL(o)})}const iA=eA["pdfjs-dist"].replace("^","");ZC.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${iA}/pdf.worker.min.mjs`;async function nA(o){const t="data:application/pdf;base64,",e=await sA(o);if(typeof e=="string")return window.atob(e.slice(t.length))}function rA(o,t){return tA({data:o,password:t}).promise}const aA={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},oA={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},hA={stroke:"#000",hoverStroke:"#B7EC5D",src:""};function b0(o=""){const t=Q.useRef(0),e=Q.useRef(null),s=Q.useRef(null),i=Q.useRef(1),n=Q.useRef({...hA});function r(){if(!o||Rs.has(o))return;const k=zx(o);return k.on("selection:cleared",()=>A(k)),k}function a(k,M){var I;const R=k.type,F={"application/pdf":h,"image/png":d,"image/jpeg":d};return((I=F[R])==null?void 0:I.call(F,k,M))??Promise.reject(new Error(`Unsupported ${R} file type.`))}async function h(k,M){const R=await nA(k);if(!R)return;const F=Gx(k,R);try{return await c({page:1,PDFBase64:R,scale:.8,password:M}),{...F,pages:t.current}}catch(I){return Promise.reject(I)}}async function c({page:k,PDFBase64:M,scale:R,password:F}){try{const I=await rA(M,F),Y=await I.getPage(k),{renderTask:N,canvas:H}=Xx(Y,R);return t.current=I.numPages,N.promise.then(()=>u(H))}catch(I){return Promise.reject(I)}}function u(k){Yx(o,k)}async function d(k){return await $x(o,k)}async function f({url:k,scale:M=.5}){await Sy(o,{url:k,scale:M})}async function g(k,M){const R=Rs.get(o);if(!R)return;const F=await ke.fromURL(k,{},{...aA,...M});R.add(F),b(R,F)}function p(k,M){const R=Rs.get(o);if(!R)return;const F=new Ee(k,{...oA,...M});R.add(F),b(R,F)}function b(k,M){M.on("selected",R=>_({canvas:k,target:R.target})),M.on("modified",R=>nl(R.target,e.current)),M.on("scaling",R=>nl(R.transform.target,e.current)),M.on("moving",R=>nl(R.transform.target,e.current)),M.on("rotating",R=>nl(R.transform.target,e.current))}async function _({canvas:k,target:M,stroke:R=n.current.stroke,uuid:F=Date.now()}){var Y;if(((Y=e.current)==null?void 0:Y.stroke)===`${R}-${F}`)return;const I=await Ux(n.current.src,R,F);A(k),e.current=I,s.current=M,y(k,M,F),x(i.current,!0),k.add(I)}function y(k,M,R){e.current&&(e.current.on("selected",()=>{k.remove(M),A(k)}),e.current.on("mouseover",()=>{_({canvas:k,target:M,stroke:n.current.hoverStroke,uuid:R})}),e.current.on("mouseout",()=>{_({canvas:k,target:M,stroke:n.current.stroke,uuid:R})}))}function x(k,M=!1){const R=Rs.get(o);i.current=k,R&&(Kx(s.current,k,n.current),qx(s.current,k,e.current),!M&&R.renderAll())}function C(k){if(!k)return;n.current={...n.current,...k};const M=Rs.get(o);!e||!s.current||!M||_({target:s.current,canvas:M})}function A(k){e.current&&(k.remove(e.current),e.current=s.current=null)}function P(){Jx(o)}function D(){Qx(o)}return{createCanvas:r,loadFile:a,specifyPage:c,renderImage:f,addFabric:g,addTextFabric:p,clearActive:P,deleteCanvas:D,scaleFabric:x,setCloseSvgOptions:C}}function lA(o){let t=0;const e=Wx(()=>{t!==window.innerWidth&&(t=window.innerWidth,o())});Q.useEffect(()=>(window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)),[])}const cA=Q.forwardRef(uA);function uA({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},f){const g=Q.useRef(null),p=`${e}-${t-1}`,b=Q.useMemo(()=>s*n,[s,n]),{createCanvas:_,specifyPage:y,addFabric:x,addTextFabric:C,renderImage:A,clearActive:P,deleteCanvas:D,scaleFabric:k,setCloseSvgOptions:M}=b0(p);lA(R);async function R(){window.requestAnimationFrame(async()=>{if(_(),o.PDFBase64.startsWith("data:image")||o.canvas){const{canvas:N}=o,H=N?7:3,at=N!=null&&N.length?N[t-1]:o.PDFBase64;A({url:at,scale:i/H});return}await y({page:t,PDFBase64:o.PDFBase64,scale:i,password:h})})}function F(N){if(N.preventDefault(),N.stopPropagation(),!a||!N.dataTransfer)return;const{dataTransfer:H,clientX:at,clientY:j}=N,z=H.getData("text"),it=H.getData("image"),kt={left:at-71,top:j-55};it&&I(it,kt),z&&Y(z,kt)}function I(N,H){x(N,{...H,...u})}function Y(N,H){C(N,{...H,...c})}return Q.useImperativeHandle(f,()=>({addImage:I,addText:Y,clearActive:P,deleteCanvas:D,canvasRef:g})),Q.useEffect(()=>{R()},[i,t,o,h]),Q.useEffect(()=>{k(b)},[b]),Q.useEffect(()=>{M(d)},[d]),Q.useEffect(()=>()=>D(),[]),mm.jsx("div",{style:{transform:`scale(${b})`},onDragOver:N=>N.preventDefault(),onDragEnter:N=>N.preventDefault(),onDrop:F,children:mm.jsx("canvas",{id:p,ref:g,className:r})})}ut.default=cA,ut.useFabric=b0,Object.defineProperties(ut,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|