@component-hook/pdf-canvas 1.1.0-alpha.10 → 1.1.0-alpha.12
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.d.ts +37 -8
- package/dist/react/pdf-canvas.es.js +4158 -4125
- package/dist/react/pdf-canvas.umd.js +72 -72
- package/dist/vue/pdf-canvas.es.d.ts +22 -5
- package/dist/vue/pdf-canvas.es.js +3362 -3316
- package/dist/vue/pdf-canvas.umd.js +56 -56
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(ft,Q){typeof exports=="object"&&typeof module<"u"?Q(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],Q):(ft=typeof globalThis<"u"?globalThis:ft||self,Q(ft["pdf-canvas"]={},ft.React))})(this,function(ft,Q){"use strict";var VA=Object.defineProperty;var Bb=ft=>{throw TypeError(ft)};var WA=(ft,Q,zt)=>Q in ft?VA(ft,Q,{enumerable:!0,configurable:!0,writable:!0,value:zt}):ft[Q]=zt;var J=(ft,Q,zt)=>WA(ft,typeof Q!="symbol"?Q+"":Q,zt),xp=(ft,Q,zt)=>Q.has(ft)||Bb("Cannot "+zt);var l=(ft,Q,zt)=>(xp(ft,Q,"read from private field"),zt?zt.call(ft):Q.get(ft)),y=(ft,Q,zt)=>Q.has(ft)?Bb("Cannot add the same private member more than once"):Q instanceof WeakSet?Q.add(ft):Q.set(ft,zt),m=(ft,Q,zt,Bn)=>(xp(ft,Q,"write to private field"),Bn?Bn.call(ft,zt):Q.set(ft,zt),zt),w=(ft,Q,zt)=>(xp(ft,Q,"access private method"),zt);var ts=(ft,Q,zt,Bn)=>({set _(Mr){m(ft,Q,Mr,zt)},get _(){return l(ft,Q,Bn)}});var an,Kd,Sp,vl,Qn,qr,ri,Kr,bl,yl,Ed,Hb,Ye,zb,Gb,Jd,Vb,Cp,_l,Jr,Qr,Zn,Wb,Xb,Ub,kd,Ao,wl,Re,To,Qd,Zt,tr,xl,Wt,Pd,Yb,Eo,vs,ce,_e,ko,hn,Po,js,er,Zr,Mo,ta,ki,ai,ea,Sl,Cl,Oo,Al,Pi,sr,Do,ir,Mi,Od,nr,Tl,rr,sa,El,kl,ge,Ct,ln,ia,Pl,Ml,ar,Oi,cn,Ol,Ns,N,Zd,Ap,$b,qb,tf,Kb,Jb,Qb,Tp,Zb,Ep,kp,ty,es,jn,ey,sy,Pp,iy,Xc,Mp,pe,Di,oi,Lo,Ri,bs,Fo,Li,os,un,na,Fi,or,hi,Uc,ef,Dl,ra,Rl,Ll,Fl,Il,jl,Io,dn,aa,hr,fn,ny,ry,Op,oa,li,Rt,jo,lr,Nl,ha,we,la,gn,cr,Bl,ca,ys,Hl,ua,pn,Ii,No,Bo,Bs,da,zl,Dd,K,Dp,Gl,Rp,sf,ay,oy,Lp,nf,Fp,hy,ly,cy,Ip,uy,jp,dy,fy,gy,Np,Yc,fa,ga,me,Rd,py,Vl,Ho,zo,Hs,my,vy,by,rf,Wl,pa,Go,mn,vn,Le,ma,va,V,Be,$c,Lh,af,Fh,yy,Bp,Ih,qc,Kc,Hp,Jc,ci,zp,Gp,Vp,Xl,Ul,ba,Yl,$l,ql,Kl,Vo,ur,At,Wo,Xo,Jl,Wp,Cb,dr,hs,Ql,Zl,ya,bn,tc,ec,_a,Uo,Yo,fr,$o,sc,qo,wa,ic,nc,xa,Sa,rc,gr,Ko,yn,_y,wy,Xp,_s,of,Up,xy,Sy,Fd,pr,_n,zs,jh,hf,wn,jd,Nd,Ca,Aa,Jo,lf,Qo,cf,xn,ji,Zo,th,Sn,Ta,Qc,ws,ac,Yp,mr,vr,Ea,Pa,eh,sh,oc,$p,xs,so,Cy,Ay,ih,Bd,Hd,nh,Ma,Yt,Cn,rh,hc,lc,ah,An,ui,Tn,cc,En,uc,Oa,Da,Tt,uf,qp,Ty,Ey,ky,Py,df,ff,Kp,dc,fc,gc,pc,mc,Ra,vc,Jp,bc,yc,Qp,_c,La,Fa,wc,Ia,My,Zp,di,Ss,xc,ja,Cs,ae,Oy,Dy,Ry,gf,kn,pf,mf,Ly,tm,Fy,As,fi,oh,hh,Ni,ct,Na,Ba,Sc,Cc,lh,ch,br,Ac,zd,Gd,de,Zc,Iy,jy,Ny,By,Hy,zy,uh,Ha,Mn,Tc,Ts,Ec,te,Vd,Gy,kc,Pc,yr,gi,qe,Vy,vf,Wy,Xy,em,Mc,dh,pi,za,fh,fe,Oc,gh,Dc,Rc,_r,mi,ph,Lc,Et,sm,im,nm,io,Uy,Pr,mh,Fc,On,Ga,vh,cs,Ic,jc,Va,Gs,Es,xe,bh,Dn,Fe,yh,Vs,Nc,st,rm,bf,Yy,$y,qy,am,no,Ws,Nh,Ky,yf,tu,Jy,Qy,Zy,t_,e_,Wa,ks,_h,ve,Xa,Ua,wr,xr,Sr,Ya,bt,om,hm,lm,eu,s_,_f,su,Bh,Bi,be,ye,$a,wh,Ke,Se,Xs,qa,Ka,Ja,xh,wf,Je,Bc,Hc,Ps,Hi,zi,Sh,Ch,Ah,Ce,Nn,i_,n_,r_,Th,Wd,a_,Xt,Ae,Cr,Rn,Ar,kh,Gi,Vi,Ms,Ph,yt,iu,nu,xf,cm,Sf,um,Cf,o_,Qa,Mh,Wi,Tr,Ln,Us,Er,Oh,Za,vi,Fn,Ie,In,$,kr,Ht,h_,Ui,dm,fm,Af,yi,Gc,Qe,to,Xd,l_,Xi,gm,c_,pm;var zt=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 mm;function u_(){if(mm)return Mr;mm=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 vm;function d_(){return vm||(vm=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,v="@@iterator";function _(C){if(C===null||typeof C!="object")return null;var L=p&&C[p]||C[v];return typeof L=="function"?L:null}var b=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function x(C){{for(var L=arguments.length,X=new Array(L>1?L-1:0),tt=1;tt<L;tt++)X[tt-1]=arguments[tt];S("error",C,X)}}function S(C,L,X){{var tt=b.ReactDebugCurrentFrame,xt=tt.getStackAddendum();xt!==""&&(L+="%s",X=X.concat([xt]));var Ot=X.map(function(mt){return String(mt)});Ot.unshift("Warning: "+L),Function.prototype.apply.call(console[C],console,Ot)}}var A=!1,k=!1,M=!1,D=!1,P=!1,R;R=Symbol.for("react.module.reference");function F(C){return!!(typeof C=="string"||typeof C=="function"||C===s||C===n||P||C===i||C===c||C===u||D||C===g||A||k||M||typeof C=="object"&&C!==null&&(C.$$typeof===f||C.$$typeof===d||C.$$typeof===r||C.$$typeof===a||C.$$typeof===h||C.$$typeof===R||C.getModuleId!==void 0))}function I(C,L,X){var tt=C.displayName;if(tt)return tt;var xt=L.displayName||L.name||"";return xt!==""?X+"("+xt+")":X}function H(C){return C.displayName||"Context"}function W(C){if(C==null)return null;if(typeof C.tag=="number"&&x("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof C=="function")return C.displayName||C.name||null;if(typeof C=="string")return C;switch(C){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 C=="object")switch(C.$$typeof){case a:var L=C;return H(L)+".Consumer";case r:var X=C;return H(X._context)+".Provider";case h:return I(C,C.render,"ForwardRef");case d:var tt=C.displayName||null;return tt!==null?tt:W(C.type)||"Memo";case f:{var xt=C,Ot=xt._payload,mt=xt._init;try{return W(mt(Ot))}catch{return null}}}return null}var B=Object.assign,ht=0,j,z,at,Mt,Lt,$t,it;function ut(){}ut.__reactDisabledLog=!0;function Ft(){{if(ht===0){j=console.log,z=console.info,at=console.warn,Mt=console.error,Lt=console.group,$t=console.groupCollapsed,it=console.groupEnd;var C={configurable:!0,enumerable:!0,value:ut,writable:!0};Object.defineProperties(console,{info:C,log:C,warn:C,error:C,group:C,groupCollapsed:C,groupEnd:C})}ht++}}function us(){{if(ht--,ht===0){var C={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:B({},C,{value:j}),info:B({},C,{value:z}),warn:B({},C,{value:at}),error:B({},C,{value:Mt}),group:B({},C,{value:Lt}),groupCollapsed:B({},C,{value:$t}),groupEnd:B({},C,{value:it})})}ht<0&&x("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var kt=b.ReactCurrentDispatcher,dt;function Ne(C,L,X){{if(dt===void 0)try{throw Error()}catch(xt){var tt=xt.stack.trim().match(/\n( *(at )?)/);dt=tt&&tt[1]||""}return`
|
|
18
|
+
`+dt+C}}var Os=!1,qt;{var Ud=typeof WeakMap=="function"?WeakMap:Map;qt=new Ud}function Vc(C,L){if(!C||Os)return"";{var X=qt.get(C);if(X!==void 0)return X}var tt;Os=!0;var xt=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var Ot;Ot=kt.current,kt.current=null,Ft();try{if(L){var mt=function(){throw Error()};if(Object.defineProperty(mt.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(mt,[])}catch(ds){tt=ds}Reflect.construct(C,[],mt)}else{try{mt.call()}catch(ds){tt=ds}C.call(mt.prototype)}}else{try{throw Error()}catch(ds){tt=ds}C()}}catch(ds){if(ds&&tt&&typeof ds.stack=="string"){for(var gt=ds.stack.split(`
|
|
19
|
+
`),Ze=tt.stack.split(`
|
|
20
|
+
`),ee=gt.length-1,oe=Ze.length-1;ee>=1&&oe>=0&>[ee]!==Ze[oe];)oe--;for(;ee>=1&&oe>=0;ee--,oe--)if(gt[ee]!==Ze[oe]){if(ee!==1||oe!==1)do if(ee--,oe--,oe<0||gt[ee]!==Ze[oe]){var Ys=`
|
|
21
|
+
`+gt[ee].replace(" at new "," at ");return C.displayName&&Ys.includes("<anonymous>")&&(Ys=Ys.replace("<anonymous>",C.displayName)),typeof C=="function"&&qt.set(C,Ys),Ys}while(ee>=1&&oe>=0);break}}}finally{Os=!1,kt.current=Ot,us(),Error.prepareStackTrace=xt}var Rh=C?C.displayName||C.name:"",eo=Rh?Ne(Rh):"";return typeof C=="function"&&qt.set(C,eo),eo}function yA(C,L,X){return Vc(C,!1)}function _A(C){var L=C.prototype;return!!(L&&L.isReactComponent)}function Yd(C,L,X){if(C==null)return"";if(typeof C=="function")return Vc(C,_A(C));if(typeof C=="string")return Ne(C);switch(C){case c:return Ne("Suspense");case u:return Ne("SuspenseList")}if(typeof C=="object")switch(C.$$typeof){case h:return yA(C.render);case d:return Yd(C.type,L,X);case f:{var tt=C,xt=tt._payload,Ot=tt._init;try{return Yd(Ot(xt),L,X)}catch{}}}return""}var Wc=Object.prototype.hasOwnProperty,Ab={},Tb=b.ReactDebugCurrentFrame;function $d(C){if(C){var L=C._owner,X=Yd(C.type,C._source,L?L.type:null);Tb.setExtraStackFrame(X)}else Tb.setExtraStackFrame(null)}function wA(C,L,X,tt,xt){{var Ot=Function.call.bind(Wc);for(var mt in C)if(Ot(C,mt)){var gt=void 0;try{if(typeof C[mt]!="function"){var Ze=Error((tt||"React class")+": "+X+" type `"+mt+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof C[mt]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Ze.name="Invariant Violation",Ze}gt=C[mt](L,mt,tt,X,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(ee){gt=ee}gt&&!(gt instanceof Error)&&($d(xt),x("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",tt||"React class",X,mt,typeof gt),$d(null)),gt instanceof Error&&!(gt.message in Ab)&&(Ab[gt.message]=!0,$d(xt),x("Failed %s type: %s",X,gt.message),$d(null))}}}var xA=Array.isArray;function vp(C){return xA(C)}function SA(C){{var L=typeof Symbol=="function"&&Symbol.toStringTag,X=L&&C[Symbol.toStringTag]||C.constructor.name||"Object";return X}}function CA(C){try{return Eb(C),!1}catch{return!0}}function Eb(C){return""+C}function kb(C){if(CA(C))return x("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",SA(C)),Eb(C)}var Pb=b.ReactCurrentOwner,AA={key:!0,ref:!0,__self:!0,__source:!0},Mb,Ob;function TA(C){if(Wc.call(C,"ref")){var L=Object.getOwnPropertyDescriptor(C,"ref").get;if(L&&L.isReactWarning)return!1}return C.ref!==void 0}function EA(C){if(Wc.call(C,"key")){var L=Object.getOwnPropertyDescriptor(C,"key").get;if(L&&L.isReactWarning)return!1}return C.key!==void 0}function kA(C,L){typeof C.ref=="string"&&Pb.current}function PA(C,L){{var X=function(){Mb||(Mb=!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))};X.isReactWarning=!0,Object.defineProperty(C,"key",{get:X,configurable:!0})}}function MA(C,L){{var X=function(){Ob||(Ob=!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))};X.isReactWarning=!0,Object.defineProperty(C,"ref",{get:X,configurable:!0})}}var OA=function(C,L,X,tt,xt,Ot,mt){var gt={$$typeof:t,type:C,key:L,ref:X,props:mt,_owner:Ot};return gt._store={},Object.defineProperty(gt._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(gt,"_self",{configurable:!1,enumerable:!1,writable:!1,value:tt}),Object.defineProperty(gt,"_source",{configurable:!1,enumerable:!1,writable:!1,value:xt}),Object.freeze&&(Object.freeze(gt.props),Object.freeze(gt)),gt};function DA(C,L,X,tt,xt){{var Ot,mt={},gt=null,Ze=null;X!==void 0&&(kb(X),gt=""+X),EA(L)&&(kb(L.key),gt=""+L.key),TA(L)&&(Ze=L.ref,kA(L,xt));for(Ot in L)Wc.call(L,Ot)&&!AA.hasOwnProperty(Ot)&&(mt[Ot]=L[Ot]);if(C&&C.defaultProps){var ee=C.defaultProps;for(Ot in ee)mt[Ot]===void 0&&(mt[Ot]=ee[Ot])}if(gt||Ze){var oe=typeof C=="function"?C.displayName||C.name||"Unknown":C;gt&&PA(mt,oe),Ze&&MA(mt,oe)}return OA(C,gt,Ze,xt,tt,Pb.current,mt)}}var bp=b.ReactCurrentOwner,Db=b.ReactDebugCurrentFrame;function Dh(C){if(C){var L=C._owner,X=Yd(C.type,C._source,L?L.type:null);Db.setExtraStackFrame(X)}else Db.setExtraStackFrame(null)}var yp;yp=!1;function _p(C){return typeof C=="object"&&C!==null&&C.$$typeof===t}function Rb(){{if(bp.current){var C=W(bp.current.type);if(C)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+
|
|
23
|
+
Check the render method of \``+C+"`."}return""}}function RA(C){return""}var Lb={};function LA(C){{var L=Rb();if(!L){var X=typeof C=="string"?C:C.displayName||C.name;X&&(L=`
|
|
24
24
|
|
|
25
|
-
Check the top-level render call using <`+
|
|
25
|
+
Check the top-level render call using <`+X+">.")}return L}}function Fb(C,L){{if(!C._store||C._store.validated||C.key!=null)return;C._store.validated=!0;var X=LA(L);if(Lb[X])return;Lb[X]=!0;var tt="";C&&C._owner&&C._owner!==bp.current&&(tt=" It was passed a child from "+W(C._owner.type)+"."),Dh(C),x('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',X,tt),Dh(null)}}function Ib(C,L){{if(typeof C!="object")return;if(vp(C))for(var X=0;X<C.length;X++){var tt=C[X];_p(tt)&&Fb(tt,L)}else if(_p(C))C._store&&(C._store.validated=!0);else if(C){var xt=_(C);if(typeof xt=="function"&&xt!==C.entries)for(var Ot=xt.call(C),mt;!(mt=Ot.next()).done;)_p(mt.value)&&Fb(mt.value,L)}}}function FA(C){{var L=C.type;if(L==null||typeof L=="string")return;var X;if(typeof L=="function")X=L.propTypes;else if(typeof L=="object"&&(L.$$typeof===h||L.$$typeof===d))X=L.propTypes;else return;if(X){var tt=W(L);wA(X,C.props,"prop",tt,C)}else if(L.PropTypes!==void 0&&!yp){yp=!0;var xt=W(L);x("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",xt||"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 IA(C){{for(var L=Object.keys(C.props),X=0;X<L.length;X++){var tt=L[X];if(tt!=="children"&&tt!=="key"){Dh(C),x("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",tt),Dh(null);break}}C.ref!==null&&(Dh(C),x("Invalid attribute `ref` supplied to `React.Fragment`."),Dh(null))}}var jb={};function Nb(C,L,X,tt,xt,Ot){{var mt=F(C);if(!mt){var gt="";(C===void 0||typeof C=="object"&&C!==null&&Object.keys(C).length===0)&&(gt+=" 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 Ze=RA();Ze?gt+=Ze:gt+=Rb();var ee;C===null?ee="null":vp(C)?ee="array":C!==void 0&&C.$$typeof===t?(ee="<"+(W(C.type)||"Unknown")+" />",gt=" Did you accidentally export a JSX literal instead of a component?"):ee=typeof C,x("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",ee,gt)}var oe=DA(C,L,X,xt,Ot);if(oe==null)return oe;if(mt){var Ys=L.children;if(Ys!==void 0)if(tt)if(vp(Ys)){for(var Rh=0;Rh<Ys.length;Rh++)Ib(Ys[Rh],C);Object.freeze&&Object.freeze(Ys)}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 Ib(Ys,C)}if(Wc.call(L,"key")){var eo=W(C),ds=Object.keys(L).filter(function(GA){return GA!=="key"}),wp=ds.length>0?"{key: someKey, "+ds.join(": ..., ")+": ...}":"{key: someKey}";if(!jb[eo+wp]){var zA=ds.length>0?"{"+ds.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(),Yi("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const u_={};let _m;const _i=()=>_m||(_m={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new c_,dispose(){},copyPasteData:u_}),ro=()=>_i().document,ru=()=>_i().window,wm=()=>{var o;return Math.max((o=pt.devicePixelRatio)!==null&&o!==void 0?o:ru().devicePixelRatio,1)},Gh=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.6.1";function Or(){}const Gn=Math.PI/2,$i=2*Math.PI,Ef=Math.PI/180,Ne=Object.freeze([1,0,0,1,0,0]),kf=16,Vn=.4477152502,et="center",yt="left",es="top",Pf="bottom",Yt="right",Be="none",Mf=/\r?\n/,xm="moving",au="scaling",Sm="rotating",Of="rotate",Cm="skewing",Vh="resizing",d_="modifyPoly",f_="modifyPath",ou="changed",hu="scale",He="scaleX",us="scaleY",ao="skewX",oo="skewY",Zt="fill",Ge="stroke",lu="modified",ho="json",Df="svg",G=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 yi("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 g_{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)/Gn){case 1:case 3:return 0;case 2:return-1}return Math.cos(o)},$s=o=>{if(o===0)return 0;const t=o/Gn,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 Am(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 Tm extends g_{_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 Wh(o){return ru().requestAnimationFrame(o)}function Em(o){return ru().cancelAnimationFrame(o)}let p_=0;const Wn=()=>p_++,Ms=()=>{const o=ro().createElement("canvas");if(!o||o.getContext===void 0)throw new yi("Failed to create `canvas` element");return o},km=()=>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),Ff=(o,t,e)=>new Promise((s,i)=>{o.toBlob(s,"image/".concat(t),e)}),zt=o=>o*Ef,zn=o=>o/Ef,Pm=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(),Mm=o=>{let[t,e]=o;return Math.atan2(e,t)},Rr=o=>{const t=Mm(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:zn(t),scaleX:s,scaleY:i,skewX:zn(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=zt(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]},Om=o=>Math.tan(zt(o)),If=o=>[1,0,Om(o),1,0,0],jf=o=>[1,Om(o),0,1,0,0],zh=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,If(n),!0)),r&&(a=$t(a,jf(r),!0)),a},Dm=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=zh(o);return Pm(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=km();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 yi("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=>G.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&&G.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),{})},Nf=(o,t)=>Object.keys(o).reduce((e,s)=>(t(o[s],s,o)&&(e[s]=o[s]),e),{}),Rm={aliceblue:"#F0F8FF",antiquewhite:"#FAEBD7",aqua:"#0FF",aquamarine:"#7FFFD4",azure:"#F0FFFF",beige:"#F5F5DC",bisque:"#FFE4C4",black:"#000",blanchedalmond:"#FFEBCD",blue:"#00F",blueviolet:"#8A2BE2",brown:"#A52A2A",burlywood:"#DEB887",cadetblue:"#5F9EA0",chartreuse:"#7FFF00",chocolate:"#D2691E",coral:"#FF7F50",cornflowerblue:"#6495ED",cornsilk:"#FFF8DC",crimson:"#DC143C",cyan:"#0FF",darkblue:"#00008B",darkcyan:"#008B8B",darkgoldenrod:"#B8860B",darkgray:"#A9A9A9",darkgrey:"#A9A9A9",darkgreen:"#006400",darkkhaki:"#BDB76B",darkmagenta:"#8B008B",darkolivegreen:"#556B2F",darkorange:"#FF8C00",darkorchid:"#9932CC",darkred:"#8B0000",darksalmon:"#E9967A",darkseagreen:"#8FBC8F",darkslateblue:"#483D8B",darkslategray:"#2F4F4F",darkslategrey:"#2F4F4F",darkturquoise:"#00CED1",darkviolet:"#9400D3",deeppink:"#FF1493",deepskyblue:"#00BFFF",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1E90FF",firebrick:"#B22222",floralwhite:"#FFFAF0",forestgreen:"#228B22",fuchsia:"#F0F",gainsboro:"#DCDCDC",ghostwhite:"#F8F8FF",gold:"#FFD700",goldenrod:"#DAA520",gray:"#808080",grey:"#808080",green:"#008000",greenyellow:"#ADFF2F",honeydew:"#F0FFF0",hotpink:"#FF69B4",indianred:"#CD5C5C",indigo:"#4B0082",ivory:"#FFFFF0",khaki:"#F0E68C",lavender:"#E6E6FA",lavenderblush:"#FFF0F5",lawngreen:"#7CFC00",lemonchiffon:"#FFFACD",lightblue:"#ADD8E6",lightcoral:"#F08080",lightcyan:"#E0FFFF",lightgoldenrodyellow:"#FAFAD2",lightgray:"#D3D3D3",lightgrey:"#D3D3D3",lightgreen:"#90EE90",lightpink:"#FFB6C1",lightsalmon:"#FFA07A",lightseagreen:"#20B2AA",lightskyblue:"#87CEFA",lightslategray:"#789",lightslategrey:"#789",lightsteelblue:"#B0C4DE",lightyellow:"#FFFFE0",lime:"#0F0",limegreen:"#32CD32",linen:"#FAF0E6",magenta:"#F0F",maroon:"#800000",mediumaquamarine:"#66CDAA",mediumblue:"#0000CD",mediumorchid:"#BA55D3",mediumpurple:"#9370DB",mediumseagreen:"#3CB371",mediumslateblue:"#7B68EE",mediumspringgreen:"#00FA9A",mediumturquoise:"#48D1CC",mediumvioletred:"#C71585",midnightblue:"#191970",mintcream:"#F5FFFA",mistyrose:"#FFE4E1",moccasin:"#FFE4B5",navajowhite:"#FFDEAD",navy:"#000080",oldlace:"#FDF5E6",olive:"#808000",olivedrab:"#6B8E23",orange:"#FFA500",orangered:"#FF4500",orchid:"#DA70D6",palegoldenrod:"#EEE8AA",palegreen:"#98FB98",paleturquoise:"#AFEEEE",palevioletred:"#DB7093",papayawhip:"#FFEFD5",peachpuff:"#FFDAB9",peru:"#CD853F",pink:"#FFC0CB",plum:"#DDA0DD",powderblue:"#B0E0E6",purple:"#800080",rebeccapurple:"#639",red:"#F00",rosybrown:"#BC8F8F",royalblue:"#4169E1",saddlebrown:"#8B4513",salmon:"#FA8072",sandybrown:"#F4A460",seagreen:"#2E8B57",seashell:"#FFF5EE",sienna:"#A0522D",silver:"#C0C0C0",skyblue:"#87CEEB",slateblue:"#6A5ACD",slategray:"#708090",slategrey:"#708090",snow:"#FFFAFA",springgreen:"#00FF7F",steelblue:"#4682B4",tan:"#D2B48C",teal:"#008080",thistle:"#D8BFD8",tomato:"#FF6347",turquoise:"#40E0D0",violet:"#EE82EE",wheat:"#F5DEB3",white:"#FFF",whitesmoke:"#F5F5F5",yellow:"#FF0",yellowgreen:"#9ACD32"},Bf=(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),Lm=(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]},Fm=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"),Im=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 Rm&&(t=Rm[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]=Lm(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(s,"%)")}toHsla(){const[t,e,s,i]=Lm(...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(Im(this.getSource())),this}toBlackWhite(t){const[e,,,s]=Im(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,Fm(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=Bf(u,c,s+1/3),a=Bf(u,c,s),h=Bf(u,c,s-1/3)}return[Math.round(255*r),Math.round(255*a),Math.round(255*h),Fm(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")?zn(s):e.includes("turn")?360*s:s}}const Ft=(o,t)=>parseFloat(Number(o).toFixed(t)),Ve=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}},Hf=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,jm=o=>!!o&&typeof o.toObject=="function",Nm=o=>!!o&&o.offsetX!==void 0&&"source"in o,Fr=o=>!!o&&"multiSelectionStacking"in o;function Bm(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,Hm=o=>{var t;return((t=o.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null},Gm=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))},Gf=(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 yi("Trying to initialize a canvas that has already been initialized. Did you forget to dispose the canvas?");return this._originalCanvasStyle=e.style.cssText,e.setAttribute("data-fabric","main"),e.classList.add("lower-canvas"),e}cleanupDOM(t){let{width:e,height:s}=t;const{el:i}=this.lower;i.classList.remove("lower-canvas"),i.removeAttribute("data-fabric"),i.setAttribute("width","".concat(e)),i.setAttribute("height","".concat(s)),i.style.cssText=this._originalCanvasStyle||"",this._originalCanvasStyle=void 0}setDimensions(t,e){const{el:s,ctx:i}=this.lower;Gm(s,i,t,e)}setCSSDimensions(t){Gf(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=Hm(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=Bm(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 m_={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 Am(Tm){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?
|
|
30
|
+
<%s key={someKey} {...props} />`,wp,eo,zA,eo),jb[eo+wp]=!0}}return C===s?IA(oe):FA(oe),oe}}function jA(C,L,X){return Nb(C,L,X,!0)}function NA(C,L,X){return Nb(C,L,X,!1)}var BA=NA,HA=jA;Hh.Fragment=s,Hh.jsx=BA,Hh.jsxs=HA}()),Hh}process.env.NODE_ENV==="production"?Bn.exports=u_():Bn.exports=d_();var bm=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);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 ym(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?ym(Object(e),!0).forEach(function(s){E(o,s,e[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(o,Object.getOwnPropertyDescriptors(e)):ym(Object(e)).forEach(function(s){Object.defineProperty(o,s,Object.getOwnPropertyDescriptor(e,s))})}return o}function It(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 _m{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 vt=new class extends _m{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 _m,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 _i extends Error{constructor(t,e){super("fabric: ".concat(t),e)}}class Tf extends _i{constructor(t){super("".concat(t," 'options.signal' is in 'aborted' state"))}}class f_{}class g_ extends f_{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 p_={};let wm;const wi=()=>wm||(wm={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new g_,dispose(){},copyPasteData:p_}),ro=()=>wi().document,ru=()=>wi().window,xm=()=>{var o;return Math.max((o=vt.devicePixelRatio)!==null&&o!==void 0?o:ru().devicePixelRatio,1)},zh=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}=vt,e=Math.sqrt(t*o);return[Math.floor(e),Math.floor(t/e)]}},Ef="6.6.1";function Or(){}const zn=Math.PI/2,$i=2*Math.PI,kf=Math.PI/180,He=Object.freeze([1,0,0,1,0,0]),Pf=16,Gn=.4477152502,et="center",wt="left",ss="top",Mf="bottom",Kt="right",ze="none",Of=/\r?\n/,Sm="moving",au="scaling",Cm="rotating",Df="rotate",Am="skewing",Gh="resizing",m_="modifyPoly",v_="modifyPath",ou="changed",hu="scale",Ge="scaleX",fs="scaleY",ao="skewX",oo="skewY",se="fill",Ve="stroke",lu="modified",ho="json",Rf="svg",G=new class{constructor(){this[ho]=new Map,this[Rf]=new Map}has(o){return this[ho].has(o)}getClass(o){const t=this[ho].get(o);if(!t)throw new _i("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[Rf].get(o)}setSVGClass(o,t){this[Rf].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 b_{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},$s=o=>{if(o===0)return 1;switch(Math.abs(o)/zn){case 1:case 3:return 0;case 2:return-1}return Math.cos(o)},qs=o=>{if(o===0)return 0;const t=o/zn,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]:Lf;const s=qs(t),i=$s(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 Lf=new O(0,0),uu=o=>!!o&&Array.isArray(o._objects);function Tm(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 Em extends b_{_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 Vh(o){return ru().requestAnimationFrame(o)}function km(o){return ru().cancelAnimationFrame(o)}let y_=0;const Vn=()=>y_++,Ds=()=>{const o=ro().createElement("canvas");if(!o||o.getContext===void 0)throw new _i("Failed to create `canvas` element");return o},Pm=()=>ro().createElement("img"),Ks=o=>{const t=Ds();return t.width=o.width,t.height=o.height,t},Ff=(o,t,e)=>o.toDataURL("image/".concat(t),e),If=(o,t,e)=>new Promise((s,i)=>{o.toBlob(s,"image/".concat(t),e)}),Ut=o=>o*kf,Wn=o=>o/kf,Mm=o=>o.every((t,e)=>t===He[e]),Te=(o,t,e)=>new O(o).transform(t,e),is=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},Jt=(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?Jt(s,e,t):s||e,void 0)||He.concat(),Om=o=>{let[t,e]=o;return Math.atan2(e,t)},Rr=o=>{const t=Om(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:Wn(t),scaleX:s,scaleY:i,skewX:Wn(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=Ut(o),i=$s(s),n=qs(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]},Dm=o=>Math.tan(Ut(o)),jf=o=>[1,0,Dm(o),1,0,0],Nf=o=>[1,Dm(o),0,1,0,0],Wh=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=Jt(a,jf(n),!0)),r&&(a=Jt(a,Nf(r),!0)),a},Rm=o=>{const{translateX:t=0,translateY:e=0,angle:s=0}=o;let i=lo(t,e);s&&(i=Jt(i,co({angle:s})));const n=Wh(o);return Mm(n)||(i=Jt(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 Tf("loadImage"));const n=Pm();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 _i("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=>G.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&&G.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),{})},Bf=(o,t)=>Object.keys(o).reduce((e,s)=>(t(o[s],s,o)&&(e[s]=o[s]),e),{}),Lm={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"},Hf=(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),Fm=(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]},Im=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"),jm=o=>{let[t,e,s,i=1]=o;const n=Math.round(.3*t+.59*e+.11*s);return[n,n,n,i]};class St{constructor(t){if(E(this,"isUnrecognised",!1),t)if(t instanceof St)this.setSource([...t._source]);else if(Array.isArray(t)){const[e,s,i,n=1]=t;this.setSource([e,s,i,n])}else this.setSource(this._tryParsingColor(t));else this.setSource([0,0,0,1])}_tryParsingColor(t){return(t=t.toLowerCase())in Lm&&(t=Lm[t]),t==="transparent"?[255,255,255,0]:St.sourceFromHex(t)||St.sourceFromRgb(t)||St.sourceFromHsl(t)||(this.isUnrecognised=!0)&&[0,0,0,1]}getSource(){return this._source}setSource(t){this._source=t}toRgb(){const[t,e,s]=this.getSource();return"rgb(".concat(t,",").concat(e,",").concat(s,")")}toRgba(){return"rgba(".concat(this.getSource().join(","),")")}toHsl(){const[t,e,s]=Fm(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(s,"%)")}toHsla(){const[t,e,s,i]=Fm(...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(jm(this.getSource())),this}toBlackWhite(t){const[e,,,s]=jm(this.getSource()),i=e<(t||127)?0:255;return this.setSource([i,i,i,s]),this}overlayWith(t){t instanceof St||(t=new St(t));const e=this.getSource(),s=t.getSource(),[i,n,r]=e.map((a,h)=>Math.round(.5*a+.5*s[h]));return this.setSource([i,n,r,e[3]]),this}static fromRgb(t){return St.fromRgba(t)}static fromRgba(t){return new St(St.sourceFromRgb(t))}static sourceFromRgb(t){const e=t.match(/^rgba?\(\s*(\d{0,3}(?:\.\d+)?%?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*(?:\s*[,/]\s*(\d{0,3}(?:\.\d+)?%?)\s*)?\)$/i);if(e){const[s,i,n]=e.slice(1,4).map(r=>{const a=parseFloat(r);return r.endsWith("%")?Math.round(2.55*a):a});return[s,i,n,Im(e[4])]}}static fromHsl(t){return St.fromHsla(t)}static fromHsla(t){return new St(St.sourceFromHsl(t))}static sourceFromHsl(t){const e=t.match(/^hsla?\(\s*([+-]?\d{0,3}(?:\.\d+)?(?:deg|turn|rad)?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*(?:\s*[,/]\s*(\d*(?:\.\d+)?%?)\s*)?\)$/i);if(!e)return;const s=(St.parseAngletoDegrees(e[1])%360+360)%360/360,i=parseFloat(e[2])/100,n=parseFloat(e[3])/100;let r,a,h;if(i===0)r=a=h=n;else{const c=n<=.5?n*(i+1):n+i-n*i,u=2*n-c;r=Hf(u,c,s+1/3),a=Hf(u,c,s),h=Hf(u,c,s-1/3)}return[Math.round(255*r),Math.round(255*a),Math.round(255*h),Im(e[4])]}static fromHex(t){return new St(St.sourceFromHex(t))}static sourceFromHex(t){if(t.match(/^#?(([0-9a-f]){3,4}|([0-9a-f]{2}){3,4})$/i)){const e=t.slice(t.indexOf("#")+1);let s;s=e.length<=4?e.split("").map(h=>h+h):e.match(/.{2}/g);const[i,n,r,a=255]=s.map(h=>parseInt(h,16));return[i,n,r,a/255]}}static parseAngletoDegrees(t){const e=t.toLowerCase(),s=parseFloat(e);return e.includes("rad")?Wn(s):e.includes("turn")?360*s:s}}const jt=(o,t)=>parseFloat(Number(o).toFixed(t)),We=function(o){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Pf;const e=/\D{0,2}$/.exec(o),s=parseFloat(o),i=vt.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}},zf=o=>{const[t,e]=o.trim().split(" "),[s,i]=(n=t)&&n!==ze?[n.slice(1,4),n.slice(5,8)]:n===ze?[n,n]:["Mid","Mid"];var n;return{meetOrSlice:e||"meet",alignX:s,alignY:i}},Yh=o=>"matrix("+o.map(t=>jt(t,vt.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 St(t),r=n.getAlpha();e=n.toRgb(),r!==1&&(s=r.toString())}else e="none";return i?"".concat(o,": ").concat(e,"; ").concat(s?"".concat(o,"-opacity: ").concat(s,"; "):""):"".concat(o,'="').concat(e,'" ').concat(s?"".concat(o,'-opacity="').concat(s,'" '):"")},Rs=o=>!!o&&o.toLive!==void 0,Nm=o=>!!o&&typeof o.toObject=="function",Bm=o=>!!o&&o.offsetX!==void 0&&"source"in o,Fr=o=>!!o&&"multiSelectionStacking"in o;function Hm(o){const t=o&&Js(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 Js=o=>o.ownerDocument||null,zm=o=>{var t;return((t=o.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null},Gm=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))},Gf=(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=ze,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)||Ds();var s;if(e.hasAttribute("data-fabric"))throw new _i("Trying to initialize a canvas that has already been initialized. Did you forget to dispose the canvas?");return this._originalCanvasStyle=e.style.cssText,e.setAttribute("data-fabric","main"),e.classList.add("lower-canvas"),e}cleanupDOM(t){let{width:e,height:s}=t;const{el:i}=this.lower;i.classList.remove("lower-canvas"),i.removeAttribute("data-fabric"),i.setAttribute("width","".concat(e)),i.setAttribute("height","".concat(s)),i.style.cssText=this._originalCanvasStyle||"",this._originalCanvasStyle=void 0}setDimensions(t,e){const{el:s,ctx:i}=this.lower;Gm(s,i,t,e)}setCSSDimensions(t){Gf(this.lower.el,t)}calcOffset(){return function(t){var e;const s=t&&Js(t),i={left:0,top:0};if(!s)return i;const n=((e=zm(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=Hm(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(){wi().dispose(this.lower.el),delete this.lower}}const __={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...He]};class qh extends Tm(Em){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?xm():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=Te(t,is(i));i[0]=e,i[3]=e;const r=Te(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=Vh(()=>this.renderAndReset()))}calcViewportBoundaries(){const t=this.width,e=this.height,s=is(this.viewportTransform),i=Te({x:0,y:0},s),n=Te({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&&(km(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=Rs(s);if(s){if(t.save(),t.beginPath(),t.moveTo(0,0),t.lineTo(this.width,0),t.lineTo(this.width,this.height),t.lineTo(0,this.height),t.closePath(),t.fillStyle=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 Te(this.getCenterPoint(),is(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:Ef},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 Rs(r)?r.excludeFromExport||(s.background=r.toObject(e)):r&&(s.background=r),Rs(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=vt.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(jt(-h[4]/h[0],n)," ").concat(jt(-h[5]/h[3],n)," ").concat(jt(this.width/h[0],n)," ").concat(jt(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 ",Ef,`</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(Vn()),'<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(Rs(e)){const s=this["".concat(t,"Vpt")],i=this.viewportTransform,n={isType:()=>!1,width:this.width/(s?i[0]:1),height:this.height/(s?i[3]:1)};return e.toSVG(n,{additionalTransform:s?Yh(i):""})}}).join("")}createSVGFontFacesMarkup(){const t=[],e={},s=vt.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(Rs(s)){const i=s.repeat||"",n=this.width,r=this.height,a=this["".concat(e,"Vpt")]?Yh(is(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"||!Bm(s)?n:s.source.width,'" height="').concat(i!=="repeat-x"&&i!=="no-repeat"||!Bm(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
|
|
50
|
+
`)}loadFromJSON(t,e){let{signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(!t)return Promise.reject(new _i("`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=Ks(this);return new this.constructor(t)}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const{format:e="png",quality:s=1,multiplier:i=1,enableRetinaScaling:n=!1}=t,r=i*(n?this.getRetinaScaling():1);return Ff(this.toCanvasElement(r,t),e,s)}toBlob(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const{format:e="png",quality:s=1,multiplier:i=1,enableRetinaScaling:n=!1}=t,r=i*(n?this.getRetinaScaling():1);return If(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,v=[g,0,0,g,(p[4]-(i||0))*t,(p[5]-(n||0))*t],_=this.enableRetinaScaling,b=Ks({width:a,height:h}),x=r?this._objects.filter(S=>r(S)):this._objects;return this.enableRetinaScaling=!1,this.viewportTransform=v,this.width=a,this.height=h,this.skipControlsDrawing=!0,this.calcViewportBoundaries(),this.renderCanvas(b.getContext("2d"),x),this.viewportTransform=p,this.width=u,this.height=d,this.calcViewportBoundaries(),this.enableRetinaScaling=_,this.skipControlsDrawing=f,b}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",__);const w_=["touchstart","touchmove","touchend"],Xm=o=>{const t=Hm(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=>w_.includes(o.type)||o.pointerType==="touch",Vf=o=>{o.preventDefault(),o.stopPropagation()},xi=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}},x_=["translateX","translateY","scaleX","scaleY"],Um=(o,t)=>fo(o,Jt(t,o.calcOwnMatrix())),fo=(o,t)=>{const e=Rr(t),{translateX:s,translateY:i,scaleX:n,scaleY:r}=e,a=It(e,x_),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)},Ym=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=xi(n);return new O(r.width,r.height)},Kh=function(){let o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:He;return Jt(is(arguments.length>1&&arguments[1]!==void 0?arguments[1]:He),o)},Ir=function(o){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:He,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:He;return o.transform(Kh(t,e))},$m=function(o){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:He,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:He;return o.transform(Kh(t,e),!0)},Xf=(o,t,e)=>{const s=Kh(t,e);return fo(o,Jt(s,o.calcOwnMatrix())),s},qm=(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)},S_={left:-.5,top:-.5,center:0,bottom:.5,right:.5},ie=o=>typeof o=="string"?S_[o]:o-.5,vu="not-allowed";function Km(o){return ie(o.originX)===ie(et)&&ie(o.originY)===ie(et)}function Jm(o){return .5-ie(o)}const Qs=(o,t)=>o[t],Qm=(o,t,e,s)=>({e:o,transform:t,pointer:new O(e,s)});function Zm(o,t){const e=o.getTotalAngle()+Wn(Math.atan2(t.y,t.x))+360;return Math.round(e%360/45)}function Uf(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,v){const _=f.getRelativeCenterPoint(),b=p!==void 0&&v!==void 0?f.translateToGivenOrigin(_,et,et,p,v):new O(f.left,f.top);return(f.angle?g.rotate(-Ut(f.angle),_):g).subtract(b)}(r,new O(s,i),t,e);return d.x>=u&&(d.x-=u),d.x<=-u&&(d.x+=u),d.y>=u&&(d.y-=u),d.y<=u&&(d.y+=u),d.x-=h.offsetX,d.y-=h.offsetY,d}const C_=(o,t,e,s)=>{const{target:i,offsetX:n,offsetY:r}=t,a=e-n,h=s-r,c=!Qs(i,"lockMovementX")&&i.left!==a,u=!Qs(i,"lockMovementY")&&i.top!==h;return c&&i.set(wt,a),u&&i.set(ss,h),(c||u)&&qm(Sm,Qm(o,t,e,s)),c||u};class t0{getSvgStyles(t){const e=this.fillRule?this.fillRule:"nonzero",s=this.strokeWidth?this.strokeWidth:"0",i=this.strokeDashArray?this.strokeDashArray.join(" "):ze,n=this.strokeDashOffset?this.strokeDashOffset:"0",r=this.strokeLineCap?this.strokeLineCap:"butt",a=this.strokeLineJoin?this.strokeLineJoin:"miter",h=this.strokeMiterLimit?this.strokeMiterLimit:"4",c=this.opacity!==void 0?this.opacity:"1",u=this.visible?"":" visibility: hidden;",d=t?"":this.getSvgFilter(),f=$h(se,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=[],v=t.indexOf("COMMON_PARTS");let _;h&&(h.clipPathId="CLIPPATH_".concat(Vn()),_='<clipPath id="'.concat(h.clipPathId,`" >
|
|
51
51
|
`).concat(h.toClipPathSVG(s),`</clipPath>
|
|
52
52
|
`)),u&&p.push("<g ",a,this.getSvgCommons(),` >
|
|
53
53
|
`),p.push("<g ",this.getSvgTransform(!1),u?"":a+this.getSvgCommons(),` >
|
|
54
|
-
`);const b=[r,c,e?"":this.addPaintOrder()," ",n?'transform="'.concat(n,'" '):""].join("");return t[v]=b,
|
|
54
|
+
`);const b=[r,c,e?"":this.addPaintOrder()," ",n?'transform="'.concat(n,'" '):""].join("");return t[v]=b,Rs(f)&&p.push(f.toSVG(this)),Rs(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!==se?' paint-order="'.concat(this.paintFirst,'" '):""}}function bu(o){return new RegExp("^("+o.join("|")+")\\b","i")}var e0;const Zs=String.raw(e0||(e0=Hn(["(?:[-+]?(?:d*.d+|d+.?)(?:[eE][-+]?d+)?)"],["(?:[-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?)"]))),Yf="http://www.w3.org/2000/svg",A_=new RegExp("(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*("+Zs+"(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|"+Zs+"))?\\s+(.*)"),T_={cx:wt,x:wt,r:"radius",cy:ss,y:ss,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"},$f="font-size",qf="clip-path",E_=bu(["path","circle","polygon","polyline","ellipse","rect","line","image","text"]),k_=bu(["symbol","image","marker","pattern","view","svg"]),s0=bu(["symbol","g","a","svg","clipPath","defs"]),i0=new RegExp("^\\s*("+Zs+"+)\\s*,?\\s*("+Zs+"+)\\s*,?\\s*("+Zs+"+)\\s*,?\\s*("+Zs+"+)\\s*$"),P_=new O(1,0),n0=new O,Kf=(o,t)=>o.rotate(t),yu=(o,t)=>new O(t).subtract(o),_u=o=>o.distanceFrom(n0),wu=(o,t)=>Math.atan2(go(o,t),a0(o,t)),r0=o=>wu(P_,o),xu=o=>o.eq(n0)?o:o.scalarDivide(_u(o)),Jf=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,a0=(o,t)=>o.x*t.x+o.y*t.y,Qf=(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)},o0="(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?",h0=new RegExp("(?:\\s|^)"+o0+o0+"("+Zs+"?(?:px)?)?(?:\\s?|$)(?:$|\\s)");class qi{constructor(t){const e=typeof t=="string"?qi.parseShadow(t):t;Object.assign(this,qi.ownDefaults,e),this.id=Vn()}static parseShadow(t){const e=t.trim(),[,s=0,i=0,n=0]=(h0.exec(e)||[]).map(r=>parseFloat(r)||0);return{color:(e.replace(h0,"")||"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=Kf(new O(this.offsetX,this.offsetY),Ut(-t.angle)),s=new St(this.color);let i=40,n=40;return t.width&&t.height&&(i=100*jt((Math.abs(e.x)+this.blur)/t.width,vt.NUM_FRACTION_DIGITS)+20,n=100*jt((Math.abs(e.y)+this.blur)/t.height,vt.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(jt(this.blur?this.blur/2:0,vt.NUM_FRACTION_DIGITS),`"></feGaussianBlur>
|
|
58
|
+
<feOffset dx="`).concat(jt(e.x,vt.NUM_FRACTION_DIGITS),'" dy="').concat(jt(e.y,vt.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=qi.ownDefaults;return this.includeDefaultValues?t:Nf(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"),G.setClass(qi,"shadow");const jr=(o,t,e)=>Math.max(o,Math.min(t,e)),T_=[es,yt,He,us,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",ao,oo],Ki=[Zt,Ge,"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:yt,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},Qf=(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}),h0=(o,t,e,s,i)=>o*Math.pow(2,10*(s-=1))*Math.sin((s*i-t)*$i/e),l0=(o,t,e,s)=>-e*Math.cos(o/s*Gn)+e+t,Zf=(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,c0=(o,t,e,s)=>e-Zf(s-o,0,e,s)+t;var k_=Object.freeze({__proto__:null,defaultEasing:l0,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:c0,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}=Qf(i,e,n,1.70158);return-h0(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*c0(2*o,0,e,s)+t:.5*Zf(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}=Qf(i,e,n,1.70158);return o<1?-.5*h0(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*Gn)+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:Zf,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}=Qf(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*Gn)+t});const P_=()=>!1;class tg{constructor(t){let{startValue:e,byValue:s,duration:i=500,delay:n=0,easing:r=l0,onStart:a=Or,onChange:h=Or,onComplete:c=Or,abort:u=P_,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(()=>Wh(t),this.delay):Wh(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),Wh(this.tick)))}register(){cu.push(this)}unregister(){cu.remove(this)}abort(){this._state="aborted",this.unregister()}}const M_=["startValue","endValue"];class O_ extends tg{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(T(T({},Lt(t,M_)),{},{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 D_=["startValue","endValue"];class R_ extends tg{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(T(T({},Lt(t,D_)),{},{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 L_=["startValue","endValue","easing","onChange","onComplete","abort"],F_=(o,t,e,s)=>t+e*(1-Math.cos(o/s*Gn)),eg=o=>o&&((t,e,s)=>o(new wt(t).toRgba(),e,s));class I_ extends tg{constructor(t){let{startValue:e,endValue:s,easing:i=F_,onChange:n,onComplete:r,abort:a}=t,h=Lt(t,L_);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:eg(n),onComplete:eg(r),abort:eg(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 sg(o){const t=(e=>Array.isArray(e.startValue)||Array.isArray(e.endValue))(o)?new R_(o):new O_(o);return t.start(),t}function u0(o){const t=new I_(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=yu(e,s),r=yu(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,v=u*a-c*h;if(v!==0){const _=g/v,b=p/v;return(n||0<=_&&_<=1)&&(r||0<=b&&b<=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 j_ extends Tm{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?zn(Mm(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=Dm(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,zh(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(zt(this.angle),t):i}translateToOriginPoint(t,e,s){const i=this.translateToGivenOrigin(t,et,et,e,s);return this.angle?i.rotate(zt(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(),yt,es)}}const N_=["type"],B_=["extraParam"];let Ji=class $d extends j_{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]=Gh.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===Ge&&this.hasFill()&&this.hasStroke()&&this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.objectCaching&&(!this.parent||!this.parent.isOnACache())||this.needsItsOwnCache(),this.ownCaching}willDrawShadow(){return!!this.shadow&&(this.shadow.offsetX!==0||this.shadow.offsetY!==0)}drawClipPathOnCache(t,e,s){t.save(),e.inverted?t.globalCompositeOperation="destination-out":t.globalCompositeOperation="destination-in",t.setTransform(1,0,0,1,0,0),t.drawImage(s,0,0),t.restore()}drawObject(t,e,s){const i=this.fill,n=this.stroke;e?(this.fill="black",this.stroke="",this._setClippingProperties(t)):this._renderBackground(t),this._render(t),this._drawClipPath(t,this.clipPath,s),this.fill=i,this.stroke=n}createClipPathLayer(t,e){const s=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===Ge?(this._renderStroke(t),this._renderFill(t)):(this._renderFill(t),this._renderStroke(t))}_render(t){}_renderFill(t){this.fill&&(t.save(),this._setFillStyles(t,this),this.fillRule==="evenodd"?t.fill("evenodd"):t.fill(),t.restore())}_renderStroke(t){if(this.stroke&&this.strokeWidth!==0){if(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this.strokeUniform){const e=this.getObjectScaling();t.scale(1/e.x,1/e.y)}this._setLineDash(t,this.strokeDashArray),this._setStrokeStyles(t,this),t.stroke(),t.restore()}}_applyPatternForTransformedGradient(t,e){var s;const i=this._limitCacheSize(this._getCacheCanvasDimensions()),n=this.getCanvasRetinaScaling(),r=i.x/this.scaleX/n,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(G.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?wm():1,a=(t.multiplier||1)*r,h=t.canvasProvider||(x=>new qh(x,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&Um(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 v=h(c);t.format==="jpeg"&&(v.backgroundColor="#fff"),this.setPositionByOrigin(new O(v.width/2,v.height/2),et,et);const _=this.canvas;v._objects=[this],this.set("canvas",v),this.setCoords();const b=v.toCanvasElement(a||1,t);return this.set("canvas",_),this.shadow=i,s&&(this.group=s),this.set(e),this.setCoords(),v._objects=[],v.destroy(),b}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return Lf(this.toCanvasElement(t),t.format||"png",t.quality||1)}toBlob(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return Ff(this.toCanvasElement(t),t.format||"png",t.quality||1)}isType(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];return e.includes(this.constructor.type)||e.includes(this.type)}complexity(){return 1}toJSON(){return this.toObject()}rotate(t){const{centeredRotation:e,originX:s,originY:i}=this;if(e){const{x:n,y:r}=this.getRelativeCenterPoint();this.originX=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,v,_)=>(_===i.length-1&&(p[v]=d),p[v]),this),h&&h(d,f,g)},onComplete:(d,f,g)=>{this.setCoords(),c&&c(d,f,g)}});return n?u0(u):sg(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:v,strokeLineCap:_,strokeDashOffset:b,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:W}=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:jm(n)?n.toObject():n,stroke:jm(r)?r.toObject():r,strokeWidth:it(v),strokeDashArray:h&&h.concat(),strokeLineCap:_,strokeDashOffset:b,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(W)},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 Nf(t,(i,n)=>{if(n===yt||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,N_),s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{extraParam:i}=s,n=Lt(s,B_);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",T_),E(Ji,"cacheProperties",Ki),E(Ji,"ownDefaults",E_),E(Ji,"type","FabricObject"),E(Ji,"colorProperties",[Zt,Ge,"backgroundColor"]),E(Ji,"customProperties",[]),G.setClass(Ji),G.setClass(Ji,"object");const po=(o,t,e)=>(s,i,n,r)=>{const a=t(s,i,n,r);return a&&$m(o,T(T({},Jm(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 d0=po(Vh,mo((o,t,e,s)=>{const i=Xf(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(yt)&&i.x>0){const{target:n}=t,r=n.strokeWidth/(n.strokeUniform?n.scaleX:1),a=qm(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 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?Ge: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 G_(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?Ge: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(zt(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"?H_.call(this,t,e,s,i,n):G_.call(this,t,e,s,i,n)}}const V_=(o,t,e)=>e.lockRotation?vu:t.cursorStyle,W_=po(Sm,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=zn(f-d+a);if(i.snapAngle&&i.snapAngle>0){const v=i.snapAngle,_=i.snapThreshold||v,b=Math.ceil(g/v)*v,x=Math.floor(g/v)*v;Math.abs(g-x)<_?g=x:Math.abs(g-b)<_&&(g=b)}g<0&&(g=360+g),g%=360;const p=i.angle!==g;return i.angle=g,p}));function f0(o,t){const e=t.canvas,s=o[e.uniScaleKey];return e.uniformScaling&&!s||!e.uniformScaling&&s}function g0(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=f0(o,e);if(g0(e,t.x!==0&&t.y===0?"x":t.x===0&&t.y!==0?"y":"",s))return vu;const i=Qm(e,t);return"".concat(z_[i],"-resize")};function ig(o,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{};const n=t.target,r=i.by,a=f0(o,n);let h,c,u,d,f,g;if(g0(n,r,a))return!1;if(t.gestureScale)c=t.scaleX*t.gestureScale,u=t.scaleY*t.gestureScale;else{if(h=Xf(t,t.originX,t.originY,e,s),f=r!=="y"?Math.sign(h.x||t.signX||1):1,g=r!=="x"?Math.sign(h.y||t.signY||1):1,t.signX||(t.signX=f),t.signY||(t.signY=g),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:b}=t,x=_/(Math.abs(d.x*b.scaleX/n.scaleX)+Math.abs(d.y*b.scaleY/n.scaleY));c=b.scaleX*x,u=b.scaleY*x}else c=Math.abs(h.x*n.scaleX/d.x),u=Math.abs(h.y*n.scaleY/d.y);qm(t)&&(c*=2,u*=2),t.signX!==f&&r!=="y"&&(t.originX=Km(t.originX),c*=-1,t.signX=f),t.signY!==g&&r!=="x"&&(t.originY=Km(t.originY),u*=-1,t.signY=g)}const p=n.scaleX,v=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||v!==n.scaleY}const Su=po(au,mo((o,t,e,s)=>ig(o,t,e,s))),X_=po(au,mo((o,t,e,s)=>ig(o,t,e,s,{by:"x"}))),U_=po(au,mo((o,t,e,s)=>ig(o,t,e,s,{by:"y"}))),Y_=["target","ex","ey","skewingSide"],ng={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"}},$_=["ns","nesw","ew","nwse"],q_=(o,t,e)=>{if(t.x!==0&&Js(e,"lockSkewingY")||t.y!==0&&Js(e,"lockSkewingX"))return vu;const s=Qm(e,t)%4;return"".concat($_[s],"-resize")};function p0(o,t,e,s,i){const{target:n}=e,{counterAxis:r,origin:a,lockSkewing:h,skew:c,flip:u}=ng[o];if(Js(n,h))return!1;const{origin:d,flip:f}=ng[r],g=te(e[d])*(n[f]?-1:1),p=-Math.sign(g)*(n[u]?-1:1),v=.5*-((n[c]===0&&Xf(e,et,et,s,i)[o]>0||n[c]>0?1:-1)*p)+.5;return po(Cm,mo((b,x,C,A)=>function(P,D,k){let{target:M,ex:R,ey:F,skewingSide:I}=D,Y=Lt(D,Y_);const{skew:N}=ng[P],H=k.subtract(new O(R,F)).divide(new O(M.scaleX,M.scaleY))[P],at=M[N],j=Y[N],W=Math.tan(zt(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)+W,Ut=zn(Math.atan(kt));M.set(N,Ut);const ne=at!==M[N];if(ne&&P==="y"){const{skewX:Wt,scaleX:Tt}=M,Ce=M._getTransformedDimensions({skewY:at}),Xs=M._getTransformedDimensions(),Dt=Wt!==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]:v,skewingSide:p}),s,i)}const K_=(o,t,e,s)=>p0("x",o,t,e,s),J_=(o,t,e,s)=>p0("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:""},vo=(o,t,e)=>Cu(o,e)?q_(0,t,e):Jh(o,t,e),m0=(o,t,e,s)=>Cu(o,t.target)?J_(o,t,e,s):X_(o,t,e,s),v0=(o,t,e,s)=>Cu(o,t.target)?K_(o,t,e,s):U_(o,t,e,s),b0=()=>({ml:new Zs({x:-.5,y:0,cursorStyleHandler:vo,actionHandler:m0,getActionName:Au}),mr:new Zs({x:.5,y:0,cursorStyleHandler:vo,actionHandler:m0,getActionName:Au}),mb:new Zs({x:0,y:.5,cursorStyleHandler:vo,actionHandler:v0,getActionName:Au}),mt:new Zs({x:0,y:-.5,cursorStyleHandler:vo,actionHandler:v0,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})}),Q_=()=>({mr:new Zs({x:.5,y:0,actionHandler:d0,cursorStyleHandler:vo,actionName:Vh}),ml:new Zs({x:-.5,y:0,actionHandler:d0,cursorStyleHandler:vo,actionName:Vh})}),Z_=()=>T(T({},b0()),Q_());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:b0()}}_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(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(),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(zt(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,zh(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 y0(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{}y0(Te,[Zm]),G.setClass(Te),G.setClass(Te,"object");const _0=(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 w0{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=yu(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 tw=new O;class bo extends w0{static getOrthogonalRotationFactor(t,e){const s=e?wu(t,e):n0(t);return Math.abs(s)<Gn?-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(qf(this.AB.eq(tw)?this.AC:this.AB,this.alpha/2))}calcOrthogonalProjection(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.strokeProjectionMagnitude;const i=this.createSideVector(t,e),n=Kf(i),r=bo.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(bo.getOrthogonalRotationFactor(this.bisector),bo.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=>{Jf(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(zt(i)),Math.tan(zt(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(v=>this.applySkew(h?v.multiply(this.strokeUniformScalar):v)).forEach(v=>{Jf(v,t,e)&&s.push(this.applySkew(this.A).add(v))}),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 x0 extends w0{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(Kf(i),s)}projectButt(){return[this.projectOrthogonally(this.A,this.T,this.strokeProjectionMagnitude),this.projectOrthogonally(this.A,this.T,-this.strokeProjectionMagnitude)]}projectRound(){const t=[];if(!this.isSkewed()&&this.A.eq(this.T)){const e=new 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 bo(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 S0=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 x0(n,n,t).project()):!e||r!==0&&r!==a.length-1?s.push(...new bo(n,h,c,t).project()):s.push(...new x0(n,r===0?c:h,t).project())}),s},rg=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},C0=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=ew(o,s))!==!1&&t.push(e);return t},ew=(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 sw=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:C0,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)},A0=(o,t)=>{const e=t.split(`
|
|
67
|
-
`),s=[];let i=-1,n={};o=
|
|
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,xw);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,...F0]),E(xi,"ownDefaults",{rx:0,ry:0}),E(xi,"ATTRIBUTE_NAMES",[...Xn,"x","y","rx","ry","width","height"]),G.setClass(xi),G.setSVGClass(xi);const Zi="initialization",Pu="added",hg="removed",Mu="imperative",I0=(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?Ym(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=>I0(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 lg extends Ou{shouldPerformLayout(t){return!0}}E(lg,"type","fit-content"),G.setClass(lg);const Sw=["strategy"],Cw=["target","strategy","bubbles","prevStrategy"],j0="layoutManager";class Zh{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:new lg;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,xm,Vh,Sm,au,Cm,ou,d_,f_].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===hg&&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,Sw);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,Cw),{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:j0,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}G.setClass(Zh,j0);const Aw=["type","objects","layoutManager"];class Tw extends Zh{performLayout(){}}class Si extends Am(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(hg,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",` >
|
|
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:Bf(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"),G.setClass(qi,"shadow");const jr=(o,t,e)=>Math.max(o,Math.min(t,e)),M_=[ss,wt,Ge,fs,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",ao,oo],Ki=[se,Ve,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],O_={top:0,left:0,width:0,height:0,angle:0,flipX:!1,flipY:!1,scaleX:1,scaleY:1,minScaleLimit:0,skewX:0,skewY:0,originX:wt,originY:ss,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:se,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},Zf=(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}),l0=(o,t,e,s,i)=>o*Math.pow(2,10*(s-=1))*Math.sin((s*i-t)*$i/e),c0=(o,t,e,s)=>-e*Math.cos(o/s*zn)+e+t,tg=(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,u0=(o,t,e,s)=>e-tg(s-o,0,e,s)+t;var D_=Object.freeze({__proto__:null,defaultEasing:c0,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:u0,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}=Zf(i,e,n,1.70158);return-l0(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*u0(2*o,0,e,s)+t:.5*tg(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}=Zf(i,e,n,1.70158);return o<1?-.5*l0(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*zn)+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:tg,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}=Zf(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*zn)+t});const R_=()=>!1;class eg{constructor(t){let{startValue:e,byValue:s,duration:i=500,delay:n=0,easing:r=c0,onStart:a=Or,onChange:h=Or,onComplete:c=Or,abort:u=R_,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(()=>Vh(t),this.delay):Vh(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),Vh(this.tick)))}register(){cu.push(this)}unregister(){cu.remove(this)}abort(){this._state="aborted",this.unregister()}}const L_=["startValue","endValue"];class F_ extends eg{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(T(T({},It(t,L_)),{},{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 I_=["startValue","endValue"];class j_ extends eg{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(T(T({},It(t,I_)),{},{startValue:e,byValue:s.map((i,n)=>i-e[n])}))}calculate(t){const e=this.startValue.map((s,i)=>this.easing(t,s,this.byValue[i],this.duration,i));return{value:e,valueProgress:Math.abs((e[0]-this.startValue[0])/this.byValue[0])}}}const N_=["startValue","endValue","easing","onChange","onComplete","abort"],B_=(o,t,e,s)=>t+e*(1-Math.cos(o/s*zn)),sg=o=>o&&((t,e,s)=>o(new St(t).toRgba(),e,s));class H_ extends eg{constructor(t){let{startValue:e,endValue:s,easing:i=B_,onChange:n,onComplete:r,abort:a}=t,h=It(t,N_);const c=new St(e).getSource(),u=new St(s).getSource();super(T(T({},h),{},{startValue:c,byValue:u.map((d,f)=>d-c[f]),easing:i,onChange:sg(n),onComplete:sg(r),abort:sg(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 ig(o){const t=(e=>Array.isArray(e.startValue)||Array.isArray(e.endValue))(o)?new j_(o):new F_(o);return t.start(),t}function d0(o){const t=new H_(o);return t.start(),t}class Gt{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=yu(e,s),r=yu(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,v=u*a-c*h;if(v!==0){const _=g/v,b=p/v;return(n||0<=_&&_<=1)&&(r||0<=b&&b<=1)?new Gt("Intersection").append(new O(t.x+_*a,t.y+_*h)):new Gt}if(g===0||p===0){const _=n||r||Gt.isPointContained(t,s,i)||Gt.isPointContained(e,s,i)||Gt.isPointContained(s,t,e)||Gt.isPointContained(i,t,e);return new Gt(_?"Coincident":void 0)}return new Gt("Parallel")}static intersectSegmentLine(t,e,s,i){return Gt.intersectLineLine(t,e,s,i,!1,!0)}static intersectSegmentSegment(t,e,s,i){return Gt.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 Gt,r=s.length;for(let a,h,c,u=0;u<r;u++){if(a=s[u],h=s[(u+1)%r],c=Gt.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 Gt.intersectLinePolygon(t,e,s,!1)}static intersectPolygonPolygon(t,e){const s=new Gt,i=t.length,n=[];for(let r=0;r<i;r++){const a=t[r],h=t[(r+1)%i],c=Gt.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 Gt("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 Gt.intersectPolygonPolygon(t,[i,r,n,a])}}class z_ extends Em{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?Te(t,this.group.calcTransformMatrix()):t}setXY(t,e,s){this.group&&(t=Te(t,is(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=>Te(a,r))}return n}intersectsWithRect(t,e){return Gt.intersectPolygonRectangle(this.getCoords(),t,e).status==="Intersection"}intersectsWithObject(t){const e=Gt.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 Gt.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 xi(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(Ge,t),this._set(fs,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?Wn(Om(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.viewportTransform)||He.concat()}calcACoords(){const t=co({angle:this.angle}),{x:e,y:s}=this.getRelativeCenterPoint(),i=lo(e,s),n=Jt(i,t),r=this._getTransformedDimensions(),a=r.x/2,h=r.y/2;return{tl:Te({x:-a,y:-h},n),tr:Te({x:a,y:-h},n),bl:Te({x:-a,y:h},n),br:Te({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,ie(this.originX),ie(this.originY)),e}calcTransformMatrix(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0],e=this.calcOwnMatrix();if(t||!this.group)return e;const s=this.transformMatrixKey(t),i=this.matrixCache;return i&&i.key.every((n,r)=>n===s[r])?i.value:(this.group&&(e=Jt(this.group.calcTransformMatrix(!1),e)),this.matrixCache={key:s,value:e},e)}calcOwnMatrix(){const t=this.transformMatrixKey(!0),e=this.ownMatrixCache;if(e&&e.key===t)return e.value;const s=this.getRelativeCenterPoint(),i={angle:this.angle,translateX:s.x,translateY:s.y,scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,flipX:this.flipX,flipY:this.flipY},n=Rm(i);return this.ownMatrixCache={key:t,value:n},n}_getNonTransformedDimensions(){return new 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,Wh(e)),h.scalarAdd(n)}translateToGivenOrigin(t,e,s,i,n){let r=t.x,a=t.y;const h=ie(i)-ie(e),c=ie(n)-ie(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(Ut(this.angle),t):i}translateToOriginPoint(t,e,s){const i=this.translateToGivenOrigin(t,et,et,e,s);return this.angle?i.rotate(Ut(this.angle),t):i}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?Te(t,this.group.calcTransformMatrix()):t}getRelativeCenterPoint(){return this.translateToCenterPoint(new O(this.left,this.top),this.originX,this.originY)}getPointByOrigin(t,e){return this.translateToOriginPoint(this.getRelativeCenterPoint(),t,e)}setPositionByOrigin(t,e,s){const i=this.translateToCenterPoint(t,e,s),n=this.translateToOriginPoint(i,this.originX,this.originY);this.set({left:n.x,top:n.y})}_getLeftTopCoords(){return this.translateToOriginPoint(this.getRelativeCenterPoint(),wt,ss)}}const G_=["type"],V_=["extraParam"];let Ji=class qd extends z_{static getDefaults(){return qd.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,qd.ownDefaults),this.setOptions(t)}_createCacheCanvas(){this._cacheCanvas=Ds(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,s=t.height,i=vt.maxCacheSideLimit,n=vt.minCacheSideLimit;if(e<=i&&s<=i&&e*s<=vt.perfLimitSizeTotal)return e<n&&(t.width=n),s<n&&(t.height=n),t;const r=e/s,[a,h]=zh.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!==Ge&&t!==fs||(e=this._constrainScale(e)),t===Ge&&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=Ks(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=is(this.calcTransformMatrix());i.transform(n[0],n[1],n[2],n[3],n[4],n[5])}return t.transform(i),t.drawObject(i,!0,e),s}_drawClipPath(t,e,s){if(!e)return;e._transformDone=!0;const i=this.createClipPathLayer(e,s);this.drawClipPathOnCache(t,e,i)}drawCacheOnCanvas(t){t.scale(1/this.zoomX,1/this.zoomY),t.drawImage(this._cacheCanvas,-this.cacheTranslationX,-this.cacheTranslationY)}isCacheDirty(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0];if(this.isNotVisible())return!1;const e=this._cacheCanvas,s=this._cacheContext;return!(!e||!s||t||!this._updateCacheCanvas())||!!(this.dirty||this.clipPath&&this.clipPath.absolutePositioned)&&(e&&s&&!t&&(s.save(),s.setTransform(1,0,0,1,0,0),s.clearRect(0,0,e.width,e.height),s.restore()),!0)}_renderBackground(t){if(!this.backgroundColor)return;const e=this._getNonTransformedDimensions();t.fillStyle=this.backgroundColor,t.fillRect(-e.x/2,-e.y/2,e.x,e.y),this._removeShadow(t)}_setOpacity(t){this.group&&!this.group._transformDone?t.globalAlpha=this.getObjectOpacity():t.globalAlpha*=this.opacity}_setStrokeStyles(t,e){const s=e.stroke;s&&(t.lineWidth=e.strokeWidth,t.lineCap=e.strokeLineCap,t.lineDashOffset=e.strokeDashOffset,t.lineJoin=e.strokeLineJoin,t.miterLimit=e.strokeMiterLimit,Rs(s)?s.gradientUnits==="percentage"||s.gradientTransform||s.patternTransform?this._applyPatternForTransformedGradient(t,s):(t.strokeStyle=s.toLive(t),this._applyPatternGradientTransform(t,s)):t.strokeStyle=e.stroke)}_setFillStyles(t,e){let{fill:s}=e;s&&(Rs(s)?(t.fillStyle=s.toLive(t),this._applyPatternGradientTransform(t,s)):t.fillStyle=s)}_setClippingProperties(t){t.globalAlpha=1,t.strokeStyle="transparent",t.fillStyle="#000000"}_setLineDash(t,e){e&&e.length!==0&&t.setLineDash(e)}_setShadow(t){if(!this.shadow)return;const e=this.shadow,s=this.canvas,i=this.getCanvasRetinaScaling(),[n,,,r]=(s==null?void 0:s.viewportTransform)||He,a=n*i,h=r*i,c=e.nonScaling?new O(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*vt.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(!Rs(e))return{offsetX:0,offsetY:0};const s=e.gradientTransform||e.patternTransform,i=-this.width/2+e.offsetX||0,n=-this.height/2+e.offsetY||0;return e.gradientUnits==="percentage"?t.transform(this.width,0,0,this.height,i,n):t.transform(1,0,0,1,i,n),s&&t.transform(s[0],s[1],s[2],s[3],s[4],s[5]),{offsetX:i,offsetY:n}}_renderPaintInOrder(t){this.paintFirst===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=Ks({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(G.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?xm():1,a=(t.multiplier||1)*r,h=t.canvasProvider||(x=>new qh(x,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&Ym(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&Xf(this,this.getViewportTransform()),this.setCoords();const c=Ds(),u=this.getBoundingRect(),d=this.shadow,f=new O;if(d){const x=d.blur,S=d.nonScaling?new O(1,1):this.getObjectScaling();f.x=2*Math.round(n(d.offsetX)+x)*n(S.x),f.y=2*Math.round(n(d.offsetY)+x)*n(S.y)}const g=u.width+f.x,p=u.height+f.y;c.width=Math.ceil(g),c.height=Math.ceil(p);const v=h(c);t.format==="jpeg"&&(v.backgroundColor="#fff"),this.setPositionByOrigin(new O(v.width/2,v.height/2),et,et);const _=this.canvas;v._objects=[this],this.set("canvas",v),this.setCoords();const b=v.toCanvasElement(a||1,t);return this.set("canvas",_),this.shadow=i,s&&(this.group=s),this.set(e),this.setCoords(),v._objects=[],v.destroy(),b}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return Ff(this.toCanvasElement(t),t.format||"png",t.quality||1)}toBlob(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return If(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&&wi().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,v,_)=>(_===i.length-1&&(p[v]=d),p[v]),this),h&&h(d,f,g)},onComplete:(d,f,g)=>{this.setCoords(),c&&c(d,f,g)}});return n?d0(u):ig(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(qd.customProperties,this.constructor.customProperties||[]);let e;const s=vt.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:v,strokeLineCap:_,strokeDashOffset:b,strokeLineJoin:x,strokeUniform:S,strokeMiterLimit:A,scaleX:k,scaleY:M,angle:D,flipX:P,flipY:R,opacity:F,visible:I,backgroundColor:H,fillRule:W,paintFirst:B,globalCompositeOperation:ht,skewX:j,skewY:z}=this;i&&!i.excludeFromExport&&(e=i.toObject(t.concat("inverted","absolutePositioned")));const at=Lt=>jt(Lt,s),Mt=T(T({},Lr(this,t)),{},{type:this.constructor.type,version:Ef,originX:d,originY:f,left:at(c),top:at(u),width:at(g),height:at(p),fill:Nm(n)?n.toObject():n,stroke:Nm(r)?r.toObject():r,strokeWidth:at(v),strokeDashArray:h&&h.concat(),strokeLineCap:_,strokeDashOffset:b,strokeLineJoin:x,strokeUniform:S,strokeMiterLimit:at(A),scaleX:at(k),scaleY:at(M),angle:at(D),flipX:P,flipY:R,opacity:at(F),shadow:a&&a.toObject(),visible:I,backgroundColor:H,fillRule:W,paintFirst:B,globalCompositeOperation:ht,skewX:at(j),skewY:at(z)},e?{clipPath:e}:null);return this.includeDefaultValues?Mt:this._removeDefaultValues(Mt)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),s=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return Bf(t,(i,n)=>{if(n===wt||n===ss||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=It(t,G_),s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{extraParam:i}=s,n=It(s,V_);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",M_),E(Ji,"cacheProperties",Ki),E(Ji,"ownDefaults",O_),E(Ji,"type","FabricObject"),E(Ji,"colorProperties",[se,Ve,"backgroundColor"]),E(Ji,"customProperties",[]),G.setClass(Ji),G.setClass(Ji,"object");const po=(o,t,e)=>(s,i,n,r)=>{const a=t(s,i,n,r);return a&&qm(o,T(T({},Qm(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 f0=po(Gh,mo((o,t,e,s)=>{const i=Uf(t,t.originX,t.originY,e,s);if(ie(t.originX)===ie(et)||ie(t.originX)===ie(Kt)&&i.x<0||ie(t.originX)===ie(wt)&&i.x>0){const{target:n}=t,r=n.strokeWidth/(n.strokeUniform?n.scaleX:1),a=Km(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 W_(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:se,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 X_(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:se,c=!a&&(s.cornerStrokeColor||i.cornerStrokeColor),u=n/2,d=r/2;o.save(),o.fillStyle=s.cornerColor||i.cornerColor||"",o.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",o.translate(t,e);const f=i.getTotalAngle();o.rotate(Ut(f)),o["".concat(h,"Rect")](-u,-d,n,r),c&&o.strokeRect(-u,-d,n,r),o.restore()}class ti{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)&&Gt.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"?W_.call(this,t,e,s,i,n):X_.call(this,t,e,s,i,n)}}const U_=(o,t,e)=>e.lockRotation?vu:t.cursorStyle,Y_=po(Cm,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(Qs(i,"lockRotation"))return!1;const d=Math.atan2(r-u.y,n-u.x),f=Math.atan2(s-u.y,e-u.x);let g=Wn(f-d+a);if(i.snapAngle&&i.snapAngle>0){const v=i.snapAngle,_=i.snapThreshold||v,b=Math.ceil(g/v)*v,x=Math.floor(g/v)*v;Math.abs(g-x)<_?g=x:Math.abs(g-b)<_&&(g=b)}g<0&&(g=360+g),g%=360;const p=i.angle!==g;return i.angle=g,p}));function g0(o,t){const e=t.canvas,s=o[e.uniScaleKey];return e.uniformScaling&&!s||!e.uniformScaling&&s}function p0(o,t,e){const s=Qs(o,"lockScalingX"),i=Qs(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 $_=["e","se","s","sw","w","nw","n","ne","e"],Jh=(o,t,e)=>{const s=g0(o,e);if(p0(e,t.x!==0&&t.y===0?"x":t.x===0&&t.y!==0?"y":"",s))return vu;const i=Zm(e,t);return"".concat($_[i],"-resize")};function ng(o,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{};const n=t.target,r=i.by,a=g0(o,n);let h,c,u,d,f,g;if(p0(n,r,a))return!1;if(t.gestureScale)c=t.scaleX*t.gestureScale,u=t.scaleY*t.gestureScale;else{if(h=Uf(t,t.originX,t.originY,e,s),f=r!=="y"?Math.sign(h.x||t.signX||1):1,g=r!=="x"?Math.sign(h.y||t.signY||1):1,t.signX||(t.signX=f),t.signY||(t.signY=g),Qs(n,"lockScalingFlip")&&(t.signX!==f||t.signY!==g))return!1;if(d=n._getTransformedDimensions(),a&&!r){const _=Math.abs(h.x)+Math.abs(h.y),{original:b}=t,x=_/(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);Km(t)&&(c*=2,u*=2),t.signX!==f&&r!=="y"&&(t.originX=Jm(t.originX),c*=-1,t.signX=f),t.signY!==g&&r!=="x"&&(t.originY=Jm(t.originY),u*=-1,t.signY=g)}const p=n.scaleX,v=n.scaleY;return r?(r==="x"&&n.set(Ge,c),r==="y"&&n.set(fs,u)):(!Qs(n,"lockScalingX")&&n.set(Ge,c),!Qs(n,"lockScalingY")&&n.set(fs,u)),p!==n.scaleX||v!==n.scaleY}const Su=po(au,mo((o,t,e,s)=>ng(o,t,e,s))),q_=po(au,mo((o,t,e,s)=>ng(o,t,e,s,{by:"x"}))),K_=po(au,mo((o,t,e,s)=>ng(o,t,e,s,{by:"y"}))),J_=["target","ex","ey","skewingSide"],rg={x:{counterAxis:"y",scale:Ge,skew:ao,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:fs,skew:oo,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},Q_=["ns","nesw","ew","nwse"],Z_=(o,t,e)=>{if(t.x!==0&&Qs(e,"lockSkewingY")||t.y!==0&&Qs(e,"lockSkewingX"))return vu;const s=Zm(e,t)%4;return"".concat(Q_[s],"-resize")};function m0(o,t,e,s,i){const{target:n}=e,{counterAxis:r,origin:a,lockSkewing:h,skew:c,flip:u}=rg[o];if(Qs(n,h))return!1;const{origin:d,flip:f}=rg[r],g=ie(e[d])*(n[f]?-1:1),p=-Math.sign(g)*(n[u]?-1:1),v=.5*-((n[c]===0&&Uf(e,et,et,s,i)[o]>0||n[c]>0?1:-1)*p)+.5;return po(Am,mo((b,x,S,A)=>function(k,M,D){let{target:P,ex:R,ey:F,skewingSide:I}=M,H=It(M,J_);const{skew:W}=rg[k],B=D.subtract(new O(R,F)).divide(new O(P.scaleX,P.scaleY))[k],ht=P[W],j=H[W],z=Math.tan(Ut(j)),at=k==="y"?P._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:P._getTransformedDimensions({scaleX:1,scaleY:1}).y,Mt=2*B*I/Math.max(at,1)+z,Lt=Wn(Math.atan(Mt));P.set(W,Lt);const $t=ht!==P[W];if($t&&k==="y"){const{skewX:it,scaleX:ut}=P,Ft=P._getTransformedDimensions({skewY:ht}),us=P._getTransformedDimensions(),kt=it!==0?Ft.x/us.x:1;kt!==1&&P.set(Ge,kt*ut)}return $t}(o,x,new O(S,A))))(t,T(T({},e),{},{[a]:v,skewingSide:p}),s,i)}const tw=(o,t,e,s)=>m0("x",o,t,e,s),ew=(o,t,e,s)=>m0("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:fs:t.y===0?s?oo:Ge:""},vo=(o,t,e)=>Cu(o,e)?Z_(0,t,e):Jh(o,t,e),v0=(o,t,e,s)=>Cu(o,t.target)?ew(o,t,e,s):q_(o,t,e,s),b0=(o,t,e,s)=>Cu(o,t.target)?tw(o,t,e,s):K_(o,t,e,s),y0=()=>({ml:new ti({x:-.5,y:0,cursorStyleHandler:vo,actionHandler:v0,getActionName:Au}),mr:new ti({x:.5,y:0,cursorStyleHandler:vo,actionHandler:v0,getActionName:Au}),mb:new ti({x:0,y:.5,cursorStyleHandler:vo,actionHandler:b0,getActionName:Au}),mt:new ti({x:0,y:-.5,cursorStyleHandler:vo,actionHandler:b0,getActionName:Au}),tl:new ti({x:-.5,y:-.5,cursorStyleHandler:Jh,actionHandler:Su}),tr:new ti({x:.5,y:-.5,cursorStyleHandler:Jh,actionHandler:Su}),bl:new ti({x:-.5,y:.5,cursorStyleHandler:Jh,actionHandler:Su}),br:new ti({x:.5,y:.5,cursorStyleHandler:Jh,actionHandler:Su}),mtr:new ti({x:0,y:-.5,actionHandler:Y_,cursorStyleHandler:U_,offsetY:-40,withConnection:!0,actionName:Df})}),sw=()=>({mr:new ti({x:.5,y:0,actionHandler:f0,cursorStyleHandler:vo,actionName:Gh}),ml:new ti({x:-.5,y:0,actionHandler:f0,cursorStyleHandler:vo,actionName:Gh})}),iw=()=>T(T({},y0()),sw());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:y0()}}_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=Jt(s,i),r=Jt(t,n),a=Jt(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(Ut(this.angle)),t.fillStyle=this.selectionBackgroundColor,t.fillRect(-s.x/2,-s.y/2,s.x,s.y),t.restore()}strokeBorders(t,e){t.strokeRect(-e.x/2,-e.y/2,e.x,e.y)}_drawBorders(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const i=T({hasControls:this.hasControls,borderColor:this.borderColor,borderDashArray:this.borderDashArray},s);t.save(),t.strokeStyle=i.borderColor,this._setLineDash(t,i.borderDashArray),this.strokeBorders(t,e),i.hasControls&&this.drawControlsConnectingLines(t,e),t.restore()}_renderControls(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const{hasBorders:s,hasControls:i}=this,n=T({hasBorders:s,hasControls:i},e),r=this.getViewportTransform(),a=n.hasBorders,h=n.hasControls,c=Jt(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(Ut(this.group?u.angle:this.angle)),a&&this.drawBorders(t,u,e),h&&this.drawControls(t,e),t.restore()}drawBorders(t,e,s){let i;if(s&&s.forActiveSelection||this.group){const n=mu(this.width,this.height,Wh(e)),r=this.isStrokeAccountedForInDimensions()?Lf:(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 _0(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 Ee extends Qh{}_0(Ee,[t0]),G.setClass(Ee),G.setClass(Ee,"object");const w0=(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 x0{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=yu(t,e);return this.options.strokeUniform?s.multiply(this.scale):s}projectOrthogonally(t,e,s){return this.applySkew(t.add(this.calcOrthogonalProjection(t,e,s)))}isSkewed(){return this.options.skewX!==0||this.options.skewY!==0}applySkew(t){const e=new O(t);return e.y+=e.x*Math.tan(Ut(this.options.skewY)),e.x+=e.y*Math.tan(Ut(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}const nw=new O;class bo extends x0{static getOrthogonalRotationFactor(t,e){const s=e?wu(t,e):r0(t);return Math.abs(s)<zn?-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(Kf(this.AB.eq(nw)?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=Jf(i),r=bo.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(bo.getOrthogonalRotationFactor(this.bisector),bo.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=>{Qf(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(Ut(i)),Math.tan(Ut(n))),u=this.strokeProjectionMagnitude,d=h?u/a/Math.sqrt(1/a**2+1/r**2*c.y**2):u/Math.sqrt(1+c.y**2),f=new 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(v=>this.applySkew(h?v.multiply(this.strokeUniformScalar):v)).forEach(v=>{Qf(v,t,e)&&s.push(this.applySkew(this.A).add(v))}),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 S0 extends x0{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(Jf(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 bo(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 C0=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 S0(n,n,t).project()):!e||r!==0&&r!==a.length-1?s.push(...new bo(n,h,c,t).project()):s.push(...new S0(n,r===0?c:h,t).project())}),s},ag=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},A0=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=rw(o,s))!==!1&&t.push(e);return t},rw=(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 aw=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:A0,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)},T0=(o,t)=>{const e=t.split(`
|
|
67
|
+
`),s=[];let i=-1,n={};o=ag(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},E0=(o,t)=>{if(!Array.isArray(o))return ag(o);const e=t.split(Of),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",se,"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 k0(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 ow(o,t){let e=!0;const s=k0(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=k0(i=i.parentElement,r);return n.length===0}(o,t)),s&&e&&t.length===0}const hw=o=>{var t;return(t=T_[o])!==null&&t!==void 0?t:o},lw=new RegExp("(".concat(Zs,")"),"gi"),cw=o=>o.replace(lw," $1 ").replace(/,/gi," ").replace(/\s+/gi," ");var P0,M0,O0,D0,R0,L0,F0;const Xe="(".concat(Zs,")"),uw=String.raw(P0||(P0=Hn(["(skewX)(",")"],["(skewX)\\(","\\)"])),Xe),dw=String.raw(M0||(M0=Hn(["(skewY)(",")"],["(skewY)\\(","\\)"])),Xe),fw=String.raw(O0||(O0=Hn(["(rotate)(","(?: "," ",")?)"],["(rotate)\\(","(?: "," ",")?\\)"])),Xe,Xe,Xe),gw=String.raw(D0||(D0=Hn(["(scale)(","(?: ",")?)"],["(scale)\\(","(?: ",")?\\)"])),Xe,Xe),pw=String.raw(R0||(R0=Hn(["(translate)(","(?: ",")?)"],["(translate)\\(","(?: ",")?\\)"])),Xe,Xe),mw=String.raw(L0||(L0=Hn(["(matrix)("," "," "," "," "," ",")"],["(matrix)\\("," "," "," "," "," ","\\)"])),Xe,Xe,Xe,Xe,Xe,Xe),og="(?:".concat(mw,"|").concat(pw,"|").concat(fw,"|").concat(gw,"|").concat(uw,"|").concat(dw,")"),vw="(?:".concat(og,"*)"),bw=String.raw(F0||(F0=Hn(["^s*(?:","?)s*$"],["^\\s*(?:","?)\\s*$"])),vw),yw=new RegExp(bw),_w=new RegExp(og),ww=new RegExp(og,"g");function ku(o){const t=[];if(!(o=cw(o).replace(/\s*([()])\s*/gi,"$1"))||o&&!yw.test(o))return[...He];for(const e of o.matchAll(ww)){const s=_w.exec(e[0]);if(!s)continue;let i=He;const n=s.filter(p=>!!p),[,r,...a]=n,[h,c,u,d,f,g]=a.map(p=>parseFloat(p));switch(r){case"translate":i=lo(h,c);break;case Df:i=co({angle:h},{x:c,y:u});break;case hu:i=fu(h,c);break;case ao:i=jf(h);break;case oo:i=Nf(h);break;case"matrix":i=[h,c,u,d,f,g]}t.push(i)}return du(t)}function xw(o,t,e,s){const i=Array.isArray(t);let n,r=t;if(o!==se&&o!==Ve||t!==ze){if(o==="strokeUniform")return t==="non-scaling-stroke";if(o==="strokeDashArray")r=t===ze?null:t.replace(/,/g," ").split(/\s+/).map(parseFloat);else if(o==="transformMatrix")r=e&&e.transformMatrix?Jt(e.transformMatrix,ku(t)):ku(t);else if(o==="visible")r=t!==ze&&t!=="hidden",e&&e.visible===!1&&(r=!1);else if(o==="opacity")r=parseFloat(t),e&&e.opacity!==void 0&&(r*=e.opacity);else if(o==="textAnchor")r=t==="start"?wt:t==="end"?Kt:et;else if(o==="charSpacing")n=We(t,s)/s*1e3;else if(o==="paintFirst"){const a=t.indexOf(se),h=t.indexOf(Ve);r=se,(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 Sw(o,t){const e=o.match(A_);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 hg(o,t){o.replace(/;\s*$/,"").split(";").forEach(e=>{if(!e)return;const[s,i]=e.split(":");t[s.trim().toLowerCase()]=i.trim()})}function Cw(o){const t={},e=o.getAttribute("style");return e&&(typeof e=="string"?hg(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 Aw={stroke:"strokeOpacity",fill:"fillOpacity"};function Qi(o,t,e){if(!o)return{};let s,i={},n=Pf;o.parentNode&&s0.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)ow(c,f.split(" "))&&(d=T(T({},d),u[f]));return d}(o,e)),Cw(o));r[qf]&&o.setAttribute(qf,r[qf]),r[$f]&&(s=We(r[$f],n),r[$f]="".concat(s));const a={};for(const c in r){const u=hw(c),d=xw(u,r[c],i,s);a[u]=d}a&&a.font&&Sw(a.font,a);const h=T(T({},i),a);return s0.test(o.nodeName)?h:function(c){const u=Ee.getDefaults();return Object.entries(Aw).forEach(d=>{let[f,g]=d;if(c[g]===void 0||c[f]==="")return;if(c[f]===void 0){if(!u[f])return;c[f]=u[f]}if(c[f].indexOf("url(")===0)return;const p=new St(c[f]);c[f]=p.setAlpha(jt(p.getAlpha()*c[g],2)).toRgba()}),c}(h)}const Tw=["left","top","width","height","visible"],I0=["rx","ry"];class Si extends Ee{static getDefaults(){return T(T({},super.getDefaults()),Si.ownDefaults)}constructor(t){super(),Object.assign(this,Si.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-Gn*r,n,i+e,n+Gn*a,i+e,n+a),t.lineTo(i+e,n+s-a),h&&t.bezierCurveTo(i+e,n+s-Gn*a,i+e-Gn*r,n+s,i+e-r,n+s),t.lineTo(i+r,n+s),h&&t.bezierCurveTo(i+Gn*r,n+s,i,n+s-Gn*a,i,n+s-a),t.lineTo(i,n+a),h&&t.bezierCurveTo(i,n+Gn*a,i+Gn*r,n,i+r,n),t.closePath(),this._renderPaintInOrder(t)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...I0,...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=It(i,Tw);return new this(T(T(T({},e),u),{},{left:n,top:r,width:a,height:h,visible:!!(c&&a&&h)}))}}E(Si,"type","Rect"),E(Si,"cacheProperties",[...Ki,...I0]),E(Si,"ownDefaults",{rx:0,ry:0}),E(Si,"ATTRIBUTE_NAMES",[...Xn,"x","y","rx","ry","width","height"]),G.setClass(Si),G.setSVGClass(Si);const Zi="initialization",Pu="added",lg="removed",Mu="imperative",j0=(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?$m(new O(s,s),void 0,o.calcTransformMatrix()):Lf,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}=xi(t.map(d=>j0(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 cg extends Ou{shouldPerformLayout(t){return!0}}E(cg,"type","fit-content"),G.setClass(cg);const Ew=["strategy"],kw=["target","strategy","bubbles","prevStrategy"],N0="layoutManager";class Zh{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:new cg;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,Sm,Gh,Cm,au,Am,ou,m_,v_].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===lg&&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=It(t,Ew);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?He:is(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*ie(s.originX),top:(a=t.y)!==null&&a!==void 0?a:n.y+i.y*ie(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=It(t,kw),{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:N0,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}G.setClass(Zh,N0);const Pw=["type","objects","layoutManager"];class Mw extends Zh{performLayout(){}}class Ci extends Tm(Ee){static getDefaults(){return T(T({},super.getDefaults()),Ci.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,Ci.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(lg,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,Jt(is(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,Jt(this.calcTransformMatrix(),t.calcTransformMatrix())),t.setCoords()),this._watchObject(!1,t);const s=this._activeObjects.length>0?this._activeObjects.indexOf(t):-1;s>-1&&this._activeObjects.splice(s,1)}shouldCache(){const t=Ee.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(...is(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=Si.prototype._toSVG.call(this),s=e.indexOf("COMMON_PARTS");e[s]='for="group" ';const i=e.join("");return t?t(i):i}_toSVG(t){const e=["<g ","COMMON_PARTS",` >
|
|
69
69
|
`],s=this._createSVGBgRect(t);s&&e.push(" ",s);for(let i=0;i<this._objects.length;i++)e.push(" ",this._objects[i].toSVG(t));return e.push(`</g>
|
|
70
|
-
`),e}getSvgStyles(){const t=this.opacity!==void 0&&this.opacity!==1?"opacity: ".concat(this.opacity,";"):"",e=this.visible?"":" visibility: hidden;";return[t,this.getSvgFilter(),e].join("")}toClipPathSVG(t){const e=[],s=this._createSVGBgRect(t);s&&e.push(" ",s);for(let i=0;i<this._objects.length;i++)e.push(" ",this._objects[i].toClipPathSVG(t));return this._createBaseClipPathSVGMarkup(e,{reviver:t})}static fromObject(t,e){let{type:s,objects:i=[],layoutManager:n}=t,r=Lt(t,Aw);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 Tw}));if(n){const d=G.getClass(n.type),f=G.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}),G.setClass(Si);const N0=(o,t)=>Math.min(t.width/o.width,t.height/o.height),B0=(o,t)=>Math.max(t.width/o.width,t.height/o.height),cg="\\s*,?\\s*",tl="".concat(cg,"(").concat(Qs,")"),Ew="".concat(tl).concat(tl).concat(tl).concat(cg,"([01])").concat(cg,"([01])").concat(tl).concat(tl),kw={m:"l",M:"L"},Pw=(o,t,e,s,i,n,r,a,h,c,u)=>{const d=Ys(o),f=$s(o),g=Ys(t),p=$s(t),v=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),v+h*(e*i*p+s*n*g),_+h*(s*i*p-e*n*g),v,_]},H0=(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 ug(o,t,e,s,i,n,r,a){let h;if(pt.cachesBoundsOfCurve&&(h=[...arguments].join(),Gh.boundsOfCurveCache[h]))return Gh.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,v=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,v=3*s-3*t),u(p)<1e-12){if(u(g)<1e-12)continue;const R=-v/g;0<R&&R<1&&d.push(R);continue}const P=g*g-4*v*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 b=_,x=V0(o,t,e,s,i,n,r,a);for(;_--;){const{x:A,y:P}=x(d[_]);f[0][_]=A,f[1][_]=P}f[0][b]=o,f[1][b]=t,f[0][b+1]=r,f[1][b+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&&(Gh.boundsOfCurveCache[h]=C),C}const Mw=(o,t,e)=>{let[s,i,n,r,a,h,c,u]=e;const d=((f,g,p,v,_,b,x)=>{if(p===0||v===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=v**2,H=I**2,at=F**2,j=Y*N-Y*H-N*at;let W=Math.abs(p),it=Math.abs(v);if(j<0){const Je=Math.sqrt(1-j/(Y*N));W*=Je,it*=Je}else P=(_===b?-1:1)*Math.sqrt(j/(Y*H+N*at));const kt=P*W*I/it,Ut=-P*it*F/W,ne=R*kt-M*Ut+.5*f,Wt=M*kt+R*Ut+.5*g;let Tt=H0(1,0,(F-kt)/W,(I-Ut)/it),Ce=H0((F-kt)/W,(I-Ut)/it,(-F-kt)/W,(-I-Ut)/it);b===0&&Ce>0?Ce-=2*D:b===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]=Pw(Tt,Xi,R,M,W,it,ne,Wt,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},G0=o=>{let t=0,e=0,s=0,i=0;const n=[];let r,a=0,h=0;for(const c of o){const u=[...c];let d;switch(u[0]){case"l":u[1]+=t,u[2]+=e;case"L":t=u[1],e=u[2],d=["L",t,e];break;case"h":u[1]+=t;case"H":t=u[1],d=["L",t,e];break;case"v":u[1]+=e;case"V":e=u[1],d=["L",t,e];break;case"m":u[1]+=t,u[2]+=e;case"M":t=u[1],e=u[2],s=u[1],i=u[2],d=["M",t,e];break;case"c":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e,u[5]+=t,u[6]+=e;case"C":a=u[3],h=u[4],t=u[5],e=u[6],d=["C",u[1],u[2],a,h,t,e];break;case"s":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e;case"S":r==="C"?(a=2*t-a,h=2*e-h):(a=t,h=e),t=u[3],e=u[4],d=["C",a,h,u[1],u[2],t,e],a=d[3],h=d[4];break;case"q":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e;case"Q":a=u[1],h=u[2],t=u[3],e=u[4],d=["Q",a,h,t,e];break;case"t":u[1]+=t,u[2]+=e;case"T":r==="Q"?(a=2*t-a,h=2*e-h):(a=t,h=e),t=u[1],e=u[2],d=["Q",a,h,t,e];break;case"a":u[6]+=t,u[7]+=e;case"A":Mw(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),V0=(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)},W0=o=>o**2,z0=o=>2*o*(1-o),X0=o=>(1-o)**2,Ow=(o,t,e,s,i,n,r,a)=>h=>{const c=W0(h),u=z0(h),d=X0(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)},Dw=(o,t,e,s,i,n)=>r=>{const a=W0(r),h=z0(r),c=X0(r);return new O(i*a+e*h+o*c,n*a+s*h+t*c)},Rw=(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)},U0=(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},Lw=(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)})},dg=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=V0(i,n,c[1],c[2],c[3],c[4],c[5],c[6]),e=u,e.iterator=t,e.angleFinder=Ow(i,n,c[1],c[2],c[3],c[4],c[5],c[6]),e.length=U0(t,i,n),i=c[5],n=c[6];break;case"Q":t=Dw(i,n,c[1],c[2],c[3],c[4]),e=u,e.iterator=t,e.angleFinder=Rw(i,n,c[1],c[2],c[3],c[4]),e.length=U0(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},Y0=function(o,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:dg(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 Lw(i,t)}},Fw=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),$0=new RegExp(Ew,"g"),Iw=new RegExp(Qs,"gi"),jw={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},q0=o=>{var t;const e=[],s=(t=o.match(Fw))!==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=jw[n.toLowerCase()];let a=[];if(n==="a"||n==="A"){$0.lastIndex=0;for(let h=null;h=$0.exec(i);)a.push(...h.slice(1))}else a=i.match(Iw)||[];for(let h=0;h<a.length;h+=r){const c=new Array(r),u=kw[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},Nw=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},K0=(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 Bw=(o,t)=>Math.floor(Math.random()*(t-o+1))+o;function J0(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 Hw=Object.freeze({__proto__:null,addTransformToObject:Xm,animate:sg,animateColor:u0,applyTransformToObject:fo,calcAngleBetweenVectors:wu,calcDimensionsMatrix:zh,calcPlaneChangeMatrix:Kh,calcVectorRotation:n0,cancelAnimFrame:Em,capValue:jr,composeMatrix:Dm,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:km,createRotateMatrix:co,createScaleMatrix:fu,createSkewXMatrix:If,createSkewYMatrix:jf,createTranslateMatrix:lo,createVector:yu,crossProduct:go,degreesToRadians:zt,dotProduct:r0,ease:k_,enlivenObjectEnlivables:Uh,enlivenObjects:uo,findScaleToCover:B0,findScaleToFit:N0,getBoundsOfCurve:ug,getOrthonormalVector:Kf,getPathSegmentsInfo:dg,getPointOnPath:Y0,getPointer:zm,getRandomInt:Bw,getRegularPolygonPath:(o,t)=>{const e=2*Math.PI/o;let s=-Gn;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:Nw,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:Jf,isIdentityMatrix:Pm,isTouchEvent:pu,isTransparent:_0,joinPath:K0,loadImage:Xh,magnitude:_u,makeBoundingBoxFromPoints:wi,makePathSimpler:G0,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:q0,parsePreserveAspectRatioAttribute:Hf,parseUnit:Ve,pick:Lr,projectStrokeOnPoints:S0,qrDecompose:Rr,radiansToDegrees:zn,removeFromArray:Dr,removeTransformFromObject:(o,t)=>{const e=ss(t),s=$t(e,o.calcOwnMatrix());fo(o,s)},removeTransformMatrixForSvgParsing:Lu,request:J0,requestAnimFrame:Wh,resetObjectTransform:Um,rotatePoint:(o,t,e)=>o.rotate(e,t),rotateVector:qf,saveObjectTransform:Wf,sendObjectToPlane:zf,sendPointToPlane:Ir,sendVectorToPlane:Ym,setStyle:Ru,sin:$s,sizeAfterTransform:mu,string:sw,stylesFromArray:T0,stylesToArray:A0,toBlob:Ff,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 Gw 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;Gm(s,i,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),Gf(this.upper.el,t),Gf(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 Gw(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 _0(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===Vh?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=yt),["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):__,c=((g,p,v,_)=>{if(!p||!g)return"drag";const b=_.controls[p];return b.getActionName(v,b,_)})(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:zt(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&&yt 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",yt,He,us,ao,oo,es]);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(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},yo=(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 fg 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(Hm(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},yo(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},yo(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},yo(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},yo(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},yo(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},yo(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(G.getClass("ActiveSelection"))([],{canvas:this});n.multiSelectAdd(s,e),this._hoveredTarget=n,this._setActiveObject(n,t),this._fireSelectionEvents([s],t)}return!0}return!1}handleSelection(t){if(!this.selection||!this._groupSelector)return!1;const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new O(e,s),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=G.getClass("ActiveSelection");this.setActiveObject(new f(d,{canvas:this}),t)}return this._groupSelector=null,!0}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const Q0={x1:0,y1:0,x2:0,y2:0},Xw=T(T({},Q0),{},{r1:0,r2:0}),_o=(o,t)=>isNaN(o)&&typeof t=="number"?t:o,Uw=/^(\d+\.\d+)%|(\d+)%$/;function Z0(o){return o&&Uw.test(o)}function tv(o,t){const e=typeof o=="number"?o:typeof o=="string"?parseFloat(o)/(Z0(o)?100:1):NaN;return jr(0,_o(e,t),1)}const Yw=/\s*;\s*/,$w=/\s*:\s*/;function qw(o,t){let e,s;const i=o.getAttribute("style");if(i){const r=i.split(Yw);r[r.length-1]===""&&r.pop();for(let a=r.length;a--;){const[h,c]=r[a].split($w).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:tv(o.getAttribute("offset"),0),color:n.toRgb(),opacity:_o(parseFloat(s||o.getAttribute("stop-opacity")||""),1)*n.getAlpha()*t}}function Kw(o,t){const e=[],s=o.getElementsByTagName("stop"),i=tv(t,1);for(let n=s.length;n--;)e.push(qw(s[n],i));return e}function ev(o){return o.nodeName==="linearGradient"||o.nodeName==="LINEARGRADIENT"?"linear":"radial"}function sv(o){return o.getAttribute("gradientUnits")==="userSpaceOnUse"?"pixels":"percentage"}function ti(o,t){return o.getAttribute(t)}function Jw(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"&&Z0(u)&&(i*=.01,a==="pixels"&&(c!=="x1"&&c!=="x2"&&c!=="r2"||(i*=n),c!=="y1"&&c!=="y2"||(i*=r)))),h[c]=i,h},{})}(ev(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:sv(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"?Xw:Q0),i),colorStops:n,offsetX:r,offsetY:a,gradientTransform:h,id:c?"".concat(c,"_").concat(Wn()):Wn()})}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,`">
|
|
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=It(t,Pw);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 Mw}));if(n){const d=G.getClass(n.type),f=G.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(Ci,"type","Group"),E(Ci,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),G.setClass(Ci);const B0=(o,t)=>Math.min(t.width/o.width,t.height/o.height),H0=(o,t)=>Math.max(t.width/o.width,t.height/o.height),ug="\\s*,?\\s*",tl="".concat(ug,"(").concat(Zs,")"),Ow="".concat(tl).concat(tl).concat(tl).concat(ug,"([01])").concat(ug,"([01])").concat(tl).concat(tl),Dw={m:"l",M:"L"},Rw=(o,t,e,s,i,n,r,a,h,c,u)=>{const d=$s(o),f=qs(o),g=$s(t),p=qs(t),v=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),v+h*(e*i*p+s*n*g),_+h*(s*i*p-e*n*g),v,_]},z0=(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 dg(o,t,e,s,i,n,r,a){let h;if(vt.cachesBoundsOfCurve&&(h=[...arguments].join(),zh.boundsOfCurveCache[h]))return zh.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,v=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,v=3*s-3*t),u(p)<1e-12){if(u(g)<1e-12)continue;const R=-v/g;0<R&&R<1&&d.push(R);continue}const k=g*g-4*v*p;if(k<0)continue;const M=c(k),D=(-g+M)/(2*p);0<D&&D<1&&d.push(D);const P=(-g-M)/(2*p);0<P&&P<1&&d.push(P)}let _=d.length;const b=_,x=V0(o,t,e,s,i,n,r,a);for(;_--;){const{x:A,y:k}=x(d[_]);f[0][_]=A,f[1][_]=k}f[0][b]=o,f[1][b]=t,f[0][b+1]=r,f[1][b+1]=a;const S=[new O(Math.min(...f[0]),Math.min(...f[1])),new O(Math.max(...f[0]),Math.max(...f[1]))];return vt.cachesBoundsOfCurve&&(zh.boundsOfCurveCache[h]=S),S}const Lw=(o,t,e)=>{let[s,i,n,r,a,h,c,u]=e;const d=((f,g,p,v,_,b,x)=>{if(p===0||v===0)return[];let S=0,A=0,k=0;const M=Math.PI,D=x*kf,P=qs(D),R=$s(D),F=.5*(-R*f-P*g),I=.5*(-R*g+P*f),H=p**2,W=v**2,B=I**2,ht=F**2,j=H*W-H*B-W*ht;let z=Math.abs(p),at=Math.abs(v);if(j<0){const qt=Math.sqrt(1-j/(H*W));z*=qt,at*=qt}else k=(_===b?-1:1)*Math.sqrt(j/(H*B+W*ht));const Mt=k*z*I/at,Lt=-k*at*F/z,$t=R*Mt-P*Lt+.5*f,it=P*Mt+R*Lt+.5*g;let ut=z0(1,0,(F-Mt)/z,(I-Lt)/at),Ft=z0((F-Mt)/z,(I-Lt)/at,(-F-Mt)/z,(-I-Lt)/at);b===0&&Ft>0?Ft-=2*M:b===1&&Ft<0&&(Ft+=2*M);const us=Math.ceil(Math.abs(Ft/M*2)),kt=[],dt=Ft/us,Ne=8/3*Math.sin(dt/4)*Math.sin(dt/4)/Math.sin(dt/2);let Os=ut+dt;for(let qt=0;qt<us;qt++)kt[qt]=Rw(ut,Os,R,P,z,at,$t,it,Ne,S,A),S=kt[qt][5],A=kt[qt][6],ut=Os,Os+=dt;return kt})(c-o,u-t,i,n,a,h,r);for(let f=0,g=d.length;f<g;f++)d[f][1]+=o,d[f][2]+=t,d[f][3]+=o,d[f][4]+=t,d[f][5]+=o,d[f][6]+=t;return d},G0=o=>{let t=0,e=0,s=0,i=0;const n=[];let r,a=0,h=0;for(const c of o){const u=[...c];let d;switch(u[0]){case"l":u[1]+=t,u[2]+=e;case"L":t=u[1],e=u[2],d=["L",t,e];break;case"h":u[1]+=t;case"H":t=u[1],d=["L",t,e];break;case"v":u[1]+=e;case"V":e=u[1],d=["L",t,e];break;case"m":u[1]+=t,u[2]+=e;case"M":t=u[1],e=u[2],s=u[1],i=u[2],d=["M",t,e];break;case"c":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e,u[5]+=t,u[6]+=e;case"C":a=u[3],h=u[4],t=u[5],e=u[6],d=["C",u[1],u[2],a,h,t,e];break;case"s":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e;case"S":r==="C"?(a=2*t-a,h=2*e-h):(a=t,h=e),t=u[3],e=u[4],d=["C",a,h,u[1],u[2],t,e],a=d[3],h=d[4];break;case"q":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e;case"Q":a=u[1],h=u[2],t=u[3],e=u[4],d=["Q",a,h,t,e];break;case"t":u[1]+=t,u[2]+=e;case"T":r==="Q"?(a=2*t-a,h=2*e-h):(a=t,h=e),t=u[1],e=u[2],d=["Q",a,h,t,e];break;case"a":u[6]+=t,u[7]+=e;case"A":Lw(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),V0=(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)},W0=o=>o**2,X0=o=>2*o*(1-o),U0=o=>(1-o)**2,Fw=(o,t,e,s,i,n,r,a)=>h=>{const c=W0(h),u=X0(h),d=U0(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)},Iw=(o,t,e,s,i,n)=>r=>{const a=W0(r),h=X0(r),c=U0(r);return new O(i*a+e*h+o*c,n*a+s*h+t*c)},jw=(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)},Y0=(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},Nw=(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)})},fg=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=V0(i,n,c[1],c[2],c[3],c[4],c[5],c[6]),e=u,e.iterator=t,e.angleFinder=Fw(i,n,c[1],c[2],c[3],c[4],c[5],c[6]),e.length=Y0(t,i,n),i=c[5],n=c[6];break;case"Q":t=Iw(i,n,c[1],c[2],c[3],c[4]),e=u,e.iterator=t,e.angleFinder=jw(i,n,c[1],c[2],c[3],c[4]),e.length=Y0(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},$0=function(o,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:fg(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 Nw(i,t)}},Bw=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),q0=new RegExp(Ow,"g"),Hw=new RegExp(Zs,"gi"),zw={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},K0=o=>{var t;const e=[],s=(t=o.match(Bw))!==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=zw[n.toLowerCase()];let a=[];if(n==="a"||n==="A"){q0.lastIndex=0;for(let h=null;h=q0.exec(i);)a.push(...h.slice(1))}else a=i.match(Hw)||[];for(let h=0;h<a.length;h+=r){const c=new Array(r),u=Dw[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},Gw=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},J0=(o,t)=>o.map(e=>e.map((s,i)=>i===0||t===void 0?s:jt(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 Vw=(o,t)=>Math.floor(Math.random()*(t-o+1))+o;function Q0(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 Tf("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(Ge,i),s.set(fs,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 Ww=Object.freeze({__proto__:null,addTransformToObject:Um,animate:ig,animateColor:d0,applyTransformToObject:fo,calcAngleBetweenVectors:wu,calcDimensionsMatrix:Wh,calcPlaneChangeMatrix:Kh,calcVectorRotation:r0,cancelAnimFrame:km,capValue:jr,composeMatrix:Rm,copyCanvasElement:o=>{var t;const e=Ks(o);return(t=e.getContext("2d"))===null||t===void 0||t.drawImage(o,0,0),e},cos:$s,createCanvasElement:Ds,createImage:Pm,createRotateMatrix:co,createScaleMatrix:fu,createSkewXMatrix:jf,createSkewYMatrix:Nf,createTranslateMatrix:lo,createVector:yu,crossProduct:go,degreesToRadians:Ut,dotProduct:a0,ease:D_,enlivenObjectEnlivables:Uh,enlivenObjects:uo,findScaleToCover:H0,findScaleToFit:B0,getBoundsOfCurve:dg,getOrthonormalVector:Jf,getPathSegmentsInfo:fg,getPointOnPath:$0,getPointer:Xm,getRandomInt:Vw,getRegularPolygonPath:(o,t)=>{const e=2*Math.PI/o;let s=-zn;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($s(r),qs(r)).scalarMultiply(t);i[n]=[n===0?"M":"L",a,h]}return i[o]=["Z"],i},getSmoothPathFromPoints:Gw,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 Ci(o,t),hasStyleChanged:Eu,invertTransform:is,isBetweenVectors:Qf,isIdentityMatrix:Mm,isTouchEvent:pu,isTransparent:w0,joinPath:J0,loadImage:Xh,magnitude:_u,makeBoundingBoxFromPoints:xi,makePathSimpler:G0,matrixToSVG:Yh,mergeClipPaths:(o,t)=>{var e;let s=o,i=t;s.inverted&&!i.inverted&&(s=t,i=o),Xf(i,(e=i.group)===null||e===void 0?void 0:e.calcTransformMatrix(),s.calcTransformMatrix());const n=s.inverted&&i.inverted;return n&&(s.inverted=i.inverted=!1),new Ci([s],{clipPath:i,inverted:n})},multiplyTransformMatrices:Jt,multiplyTransformMatrixArray:du,parsePath:K0,parsePreserveAspectRatioAttribute:zf,parseUnit:We,pick:Lr,projectStrokeOnPoints:C0,qrDecompose:Rr,radiansToDegrees:Wn,removeFromArray:Dr,removeTransformFromObject:(o,t)=>{const e=is(t),s=Jt(e,o.calcOwnMatrix());fo(o,s)},removeTransformMatrixForSvgParsing:Lu,request:Q0,requestAnimFrame:Vh,resetObjectTransform:Ym,rotatePoint:(o,t,e)=>o.rotate(e,t),rotateVector:Kf,saveObjectTransform:Wf,sendObjectToPlane:Xf,sendPointToPlane:Ir,sendVectorToPlane:$m,setStyle:Ru,sin:qs,sizeAfterTransform:mu,string:aw,stylesFromArray:E0,stylesToArray:T0,toBlob:If,toDataURL:Ff,toFixed:jt,transformPath:(o,t,e)=>(e&&(t=Jt(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}=Te({x:s[n],y:s[n+1]},t);i[n]=r,i[n+1]=a}return i})),transformPoint:Te});class Xw 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=Ds();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":ze})),Vm(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:s,ctx:i}=this.upper;Gm(s,i,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),Gf(this.upper.el,t),Gf(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(),wi().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 Xw(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 w0(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===Ge||e===fs||e===Gh?i=this.centeredScaling||t.centeredScaling:e===Df&&(i=this.centeredRotation||t.centeredRotation),i?!s:s}_getOriginFromCorner(t,e){const s={x:t.originX,y:t.originY};return e&&(["ml","tl","bl"].includes(e)?s.x=Kt:["mr","tr","br"].includes(e)&&(s.x=wt),["tl","mt","tr"].includes(e)?s.y=Mf:["bl","mb","br"].includes(e)&&(s.y=ss)),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):C_,c=((g,p,v,_)=>{if(!p||!g)return"drag";const b=_.controls[p];return b.getActionName(v,b,_)})(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:Ut(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:u,original:T(T({},Wf(e)),{},{originX:d.x,originY:d.y})};this._currentTransform=f,this.fire("before:transform",{e:t,transform:f})}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new 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,Ee.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=$s(u)*n,f=qs(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 Gt.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=Xm(t),r=i.width||0,a=i.height||0;r&&a||(ss in i&&Mf in i&&(a=Math.abs(i.top-i.bottom)),Kt in i&&wt in i&&(r=Math.abs(i.right-i.left))),this.calcOffset(),n.x=n.x-this._offset.left,n.y=n.y-this._offset.top,e||(n=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=Ds(),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",wt,Ge,fs,ao,oo,ss]);return Um(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 Uw{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 Yw=["target","oldTarget","fireCanvas","e"],gs={passive:!1},yo=(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)},Ls=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)},$w={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 gg extends Fu{constructor(t){super(t,arguments.length>1&&arguments[1]!==void 0?arguments[1]:{}),E(this,"_isClick",void 0),E(this,"textEditingManager",new Uw(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(zm(s),"resize",this._onResize),t(s,i+"down",this._onMouseDown),t(s,"".concat(i,"move"),this._onMouseMove,gs),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,gs)}removeListeners(){this.addOrRemove(Ls,"remove");const t=this._getEventPrefix(),e=Js(this.upperCanvasEl);Ls(e,"".concat(t,"up"),this._onMouseUp),Ls(e,"touchend",this._onTouchEnd,gs),Ls(e,"".concat(t,"move"),this._onMouseMove,gs),Ls(e,"touchmove",this._onMouseMove,gs),clearTimeout(this._willAddMouseDown)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s=T({e:t},yo(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},yo(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!==ze,s=e?this._activeObject:void 0,i={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:s};Ls(this.upperCanvasEl,"drag",this._onDragProgress),this.fire("dragend",i),this._dragSource&&this._dragSource.fire("dragend",i),delete this._dragSource,this._onMouseUp(t)}_onDragProgress(t){const e={e:t,target:this._dragSource,dragSource:this._dragSource,dropTarget:this._draggedoverTarget};this.fire("drag",e),this._dragSource&&this._dragSource.fire("drag",e)}findDragTargets(t){return this.targets=[],{target:this._searchPossibleTargets(this._objects,this.getViewportPoint(t)),targets:[...this.targets]}}_onDragOver(t){const e="dragover",{target:s,targets:i}=this.findDragTargets(t),n=this._dragSource,r={e:t,target:s,subTargets:i,dragSource:n,canDrop:!1,dropTarget:void 0};let 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},yo(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=Js(i);Un(r,"touchend",this._onTouchEnd,gs),e&&Un(r,"touchmove",this._onMouseMove,gs),Ls(i,"".concat(n,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();Ls(e,"".concat(s,"move"),this._onMouseMove,gs);const i=Js(e);Un(i,"".concat(s,"up"),this._onMouseUp),Un(i,"".concat(s,"move"),this._onMouseMove,gs)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),s=Js(this.upperCanvasEl);Ls(s,"touchend",this._onTouchEnd,gs),Ls(s,"touchmove",this._onMouseMove,gs),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout(()=>{Un(this.upperCanvasEl,"".concat(e,"down"),this._onMouseDown),this._willAddMouseDown=0},400)}_onMouseUp(t){this.__onMouseUp(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();if(this._isMainEvent(t)){const i=Js(this.upperCanvasEl);Ls(i,"".concat(s,"up"),this._onMouseUp),Ls(i,"".concat(s,"move"),this._onMouseMove,gs),Un(e,"".concat(s,"move"),this._onMouseMove,gs)}}_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},yo(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=It(e,Yw);const{targetIn:h,targetOut:c,canvasIn:u,canvasOut:d}=$w[t],f=i!==s;if(i&&f){const g=T(T({},a),{},{e:r,target:i,nextTarget:s},yo(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},yo(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(G.getClass("ActiveSelection"))([],{canvas:this});n.multiSelectAdd(s,e),this._hoveredTarget=n,this._setActiveObject(n,t),this._fireSelectionEvents([s],t)}return!0}return!1}handleSelection(t){if(!this.selection||!this._groupSelector)return!1;const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new O(e,s),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=G.getClass("ActiveSelection");this.setActiveObject(new f(d,{canvas:this}),t)}return this._groupSelector=null,!0}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const Z0={x1:0,y1:0,x2:0,y2:0},qw=T(T({},Z0),{},{r1:0,r2:0}),_o=(o,t)=>isNaN(o)&&typeof t=="number"?t:o,Kw=/^(\d+\.\d+)%|(\d+)%$/;function tv(o){return o&&Kw.test(o)}function ev(o,t){const e=typeof o=="number"?o:typeof o=="string"?parseFloat(o)/(tv(o)?100:1):NaN;return jr(0,_o(e,t),1)}const Jw=/\s*;\s*/,Qw=/\s*:\s*/;function Zw(o,t){let e,s;const i=o.getAttribute("style");if(i){const r=i.split(Jw);r[r.length-1]===""&&r.pop();for(let a=r.length;a--;){const[h,c]=r[a].split(Qw).map(u=>u.trim());h==="stop-color"?e=c:h==="stop-opacity"&&(s=c)}}const n=new St(e||o.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:ev(o.getAttribute("offset"),0),color:n.toRgb(),opacity:_o(parseFloat(s||o.getAttribute("stop-opacity")||""),1)*n.getAlpha()*t}}function tx(o,t){const e=[],s=o.getElementsByTagName("stop"),i=ev(t,1);for(let n=s.length;n--;)e.push(Zw(s[n],i));return e}function sv(o){return o.nodeName==="linearGradient"||o.nodeName==="LINEARGRADIENT"?"linear":"radial"}function iv(o){return o.getAttribute("gradientUnits")==="userSpaceOnUse"?"pixels":"percentage"}function ei(o,t){return o.getAttribute(t)}function ex(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"&&tv(u)&&(i*=.01,a==="pixels"&&(c!=="x1"&&c!=="x2"&&c!=="r2"||(i*=n),c!=="y1"&&c!=="y2"||(i*=r)))),h[c]=i,h},{})}(sv(o)==="linear"?function(e){return{x1:ei(e,"x1")||0,y1:ei(e,"y1")||0,x2:ei(e,"x2")||"100%",y2:ei(e,"y2")||0}}(o):function(e){return{x1:ei(e,"fx")||ei(e,"cx")||"50%",y1:ei(e,"fy")||ei(e,"cy")||"50%",r1:0,x2:ei(e,"cx")||"50%",y2:ei(e,"cy")||"50%",r2:ei(e,"r")||"50%"}}(o),T(T({},t),{},{gradientUnits:iv(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"?qw:Z0),i),colorStops:n,offsetX:r,offsetY:a,gradientTransform:h,id:c?"".concat(c,"_").concat(Vn()):Vn()})}addColorStop(t){for(const e in t){const s=new St(t[e]);this.colorStops.push({offset:parseFloat(e),color:s.toRgb(),opacity:s.getAlpha()})}return this}toObject(t){return T(T({},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():He.concat(),n=this.gradientUnits==="pixels"?"userSpaceOnUse":"objectBoundingBox",r=this.colorStops.map(d=>T({},d)).sort((d,f)=>d.offset-f.offset);let a=-this.offsetX,h=-this.offsetY;var c;n==="objectBoundingBox"?(a/=t.width,h/=t.height):(a+=t.width/2,h+=t.height/2),(c=t)&&typeof c._renderPathCommands=="function"&&this.gradientUnits!=="percentage"&&(a-=t.pathOffset.x,h-=t.pathOffset.y),i[4]-=a,i[5]-=h;const u=['id="SVGID_'.concat(this.id,'"'),'gradientUnits="'.concat(n,'"'),'gradientTransform="'.concat(e?e+" ":"").concat(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
71
|
`)}else if(this.type==="radial"){const{x1:d,y1:f,x2:g,y2:p,r1:v,r2:_}=this.coords,b=v>_;s.push("<radialGradient ",u,' cx="',b?d:g,'" cy="',b?f:p,'" r="',b?v:_,'" fx="',b?g:d,'" fy="',b?p:f,`">
|
|
72
|
-
`),b&&(r.reverse(),r.forEach(
|
|
72
|
+
`),b&&(r.reverse(),r.forEach(S=>{S.offset=1-S.offset}));const x=Math.min(v,_);if(x>0){const S=x/Math.max(v,_);r.forEach(A=>{A.offset+=S*(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: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
|
|
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=Qi(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,radius:a=0}=i;return new this(T(T({},
|
|
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],
|
|
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
|
|
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 cx=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let vg;class Ee extends cv{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=dg(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===Ge?(this._renderTextStroke(t),this._renderTextFill(t)):(this._renderTextFill(t),this._renderTextStroke(t))}_setTextStyles(t,e,s){if(t.textBaseline="alphabetic",this.path)switch(this.pathAlign){case 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 v=0;v<h;v++){const _=this.__charBounds[n][v];d=this.getValueOfPropertyAt(n,v,"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=Gh.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 vg||(vg=qs({width:0,height:0}).getContext("2d")),vg}();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 yt: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=Y0(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,v,_,b,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?yt: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++)b=P===D||this.charSpacing||c,C+=s[P],_=this.__charBounds[r][P],A===0?(i+=f*(_.kernedWidth-_.width),A+=_.width):A+=_.kernedWidth,h&&!b&&this._reSpaceAndTab.test(s[P])&&(b=!0),b||(p=p||this.getCompleteStyleDeclaration(r,P),v=this.getCompleteStyleDeclaration(r,P+1),b=Eu(p,v,!1)),b&&(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=v,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===yt||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,v,_=0,b=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),v=this.getValueOfPropertyAt(h,M,Zt);const I=this.getHeightOfChar(h,M),Y=this.getValueOfPropertyAt(h,M,"deltaY");if(n&&p&&v)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||v!==C||I!==P||Y!==D)&&b>0){let N=i+g+_;this.direction==="rtl"&&(N=this.width-N-b),x&&C&&(t.fillStyle=C,t.fillRect(N,A+a*P+D,b,this.fontSize/15)),_=F.left,b=F.width,x=p,C=v,P=I,D=Y}else b+=F.kernedWidth}let k=i+g+_;this.direction==="rtl"&&(k=this.width-k-b),t.fillStyle=v,p&&v&&t.fillRect(k,A+a*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(",")||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([...
|
|
84
|
-
`]}_getSVGTextAndBg(o,t){const e=[],s=[];let i,n=o;this.backgroundColor&&s.push(...mg(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(hx)),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(C0(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,v=r.length-1;p<=v;p++)d=p===v||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(...mg(c,e+h,s,a,n)),h=d,a=f,c=r):a+=g}r&&o.push(...mg(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(Ge,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(" ")}}]),G.setClass(Ee),G.setSVGClass(Ee);class ux{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)),v=a.viewportTransform,_=p.add(d).transform(v,!0),b=r.backgroundColor,x=rg(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=b,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 uv=/[ \n\.,;!\?\-]/;class dx 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 sg({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&&!uv.test(n);)i+=e,n=s[i];return e===-1&&uv.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=yt:this._selectionDirection===Yt&&(this._selectionDirection=yt,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===yt&&(this._selectionDirection=Yt,this.selectionStart=e),this.selectionEnd=s)}}class fx extends dx{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 v=this.fromStringToGraphemeSelection(this.hiddenTextarea.selectionStart,this.hiddenTextarea.selectionEnd,this.hiddenTextarea.value),_=a>v.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 b=i.slice(v.selectionEnd-p,v.selectionEnd);if(d&&d.length&&(b.length&&(u=this.getSelectionStyles(a,a+1,!1),u=b.map(()=>u[0])),c?(f=a,g=h):_?(f=h-d.length,g=h):(f=h,g=h+d.length),this.removeStyleFromTo(f,g)),b.length){const{copyPasteData:x}=_i();e&&b.join("")===x.copiedText&&!pt.disableStyleCopyPaste&&(u=x.copiedTextStyle),this.insertNewStyleBlock(b,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===yt?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=yt,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=yt,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===yt&&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 gx extends fx{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 ux(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",Gu="moveCursorRight",Vu="exitEditing",px=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:Vu,27:Vu,33:Nu,34:Bu,35:Gu,36:Hu,37:Hu,38:Nu,39:Gu,40:Bu},keysMapRtl:{9:Vu,27:Vu,33:Nu,34:Bu,35:Hu,36:Gu,37:Gu,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 gx{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 fg&&this.canvas.textEditingManager.remove(this),e instanceof fg&&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===yt||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 v=this.getHeightOfLine(g),_=0,b=0,x=0;if(g===c&&(b=this.__charBounds[c][d].left),g>=c&&g<u)x=r&&!this.isEndOfWrapping(g)?this.width:this.getLineWidth(g)||5;else if(g===u)if(f===0)x=this.__charBounds[u][f].left;else{const k=this._getWidthOfCharSpacing();x=this.__charBounds[u][f-1].left+this.__charBounds[u][f-1].width-k}_=v,(this.lineHeight<1||g===u&&this.lineHeight>1)&&(v/=this.lineHeight);let C=s.left+p+b,A=v,P=0;const D=x-b;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",A=1,P=v):t.fillStyle=this.selectionColor,this.direction==="rtl"&&(this.textAlign===Yt||this.textAlign===Ci||this.textAlign===sl?C=this.width-C-D:this.textAlign===yt||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",px),E(sn,"type","IText"),G.setClass(sn),G.setClass(sn,"i-text");class Gr extends sn{static getDefaults(){return T(T({},super.getDefaults()),Gr.ownDefaults)}constructor(t,e){super(t,T(T({},Gr.ownDefaults),e))}static createControls(){return{controls:Z_()}}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,v=!0;e-=r;const _=Math.max(e,i,this.dynamicMinWidth),b=n[t];let x;for(g=0,x=0;x<b.length;x++){const{word:C,width:A}=b[x];g+=C.length,d+=p+A-a,d>_&&!v?(c.push(f),f=[],d=A,v=!0):d+=a,v||h||f.push(u),f=f.concat(C),p=h?0:this._measureWord([u],t,g),g++,v=!1}return x&&c.push(f),i+r>this.dynamicMinWidth&&(this.dynamicMinWidth=i-a+r),c}isEndOfWrapping(t){return!this._styleMap[t+1]||this._styleMap[t+1].line!==this._styleMap[t].line}missingNewlineOffset(t,e){return this.splitByGrapheme&&!e?this.isEndOfWrapping(t)?1:0:1}_splitTextIntoLines(t){const e=super._splitTextIntoLines(t),s=this._wrapText(e.lines,this.width),i=new Array(s.length);for(let n=0;n<s.length;n++)i[n]=s[n].join("");return e.lines=i,e.graphemeLines=s,e}getMinWidth(){return Math.max(this.minWidth,this.dynamicMinWidth)}_removeExtraneousStyles(){const t=new Map;for(const e in this._styleMap){const s=parseInt(e,10);if(this._textLines[s]){const i=this._styleMap[e].line;t.set("".concat(i),!0)}}for(const e in this.styles)t.has(e)||delete this.styles[e]}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject(["minWidth","splitByGrapheme",...t])}}E(Gr,"type","Textbox"),E(Gr,"textLayoutProperties",[...sn.textLayoutProperties,"width"]),E(Gr,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),G.setClass(Gr);class dv 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(I0(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(dv,"type","clip-path"),G.setClass(dv);class fv extends Ou{getInitialSize(t,e){let{target:s}=t,{size:i}=e;return new O(s.width||i.x,s.height||i.y)}}E(fv,"type","fixed"),G.setClass(fv);class mx 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 Vr extends Si{static getDefaults(){return T(T({},super.getDefaults()),Vr.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,Vr.ownDefaults),this.setOptions(e);const{left:s,top:i,layoutManager:n}=e;this.groupInit(t,{left:s,top:i,layoutManager:n??new mx})}_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===hg?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(Vr,"type","ActiveSelection"),E(Vr,"ownDefaults",{multiSelectionStacking:"canvas-stacking"}),G.setClass(Vr),G.setClass(Vr,"activeSelection");class vx{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 gv{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,v=g.height,_=f.destinationWidth,b=f.destinationHeight;p===_&&v===b||(g.width=_,g.height=b)}(u),this.copyGLTo2D(a,u),a.bindTexture(a.TEXTURE_2D,null),a.deleteTexture(u.sourceTexture),a.deleteTexture(u.targetTexture),a.deleteFramebuffer(d),h.setTransform(1,0,0,1,0,0),u}dispose(){this.canvas&&(this.canvas=null,this.gl=null),this.clearWebGLCaches()}clearWebGLCaches(){this.programCache={},this.textureCache={}}createTexture(t,e,s,i,n){const{NEAREST:r,TEXTURE_2D:a,RGBA:h,UNSIGNED_BYTE:c,CLAMP_TO_EDGE:u,TEXTURE_MAG_FILTER:d,TEXTURE_MIN_FILTER:f,TEXTURE_WRAP_S:g,TEXTURE_WRAP_T:p}=t,v=t.createTexture();return t.bindTexture(a,v),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),v}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 gv({tileSize:pt.textureSize}):new vx}function _g(){return!yg&&(!(arguments.length>0&&arguments[0]!==void 0)||arguments[0])&&(yg=bx()),yg}const yx=["filters","resizeFilter","src","crossOrigin","type"],pv=["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(Wn()),this.setElement(typeof t=="string"?(this.canvas&&Ks(this.canvas.getElement())||ro()).getElementById(t):t,e)}getElement(){return this._element}setElement(t){var e;let s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._element=t,this._originalElement=t,this._setWidthHeight(s),(e=t.classList)===null||e===void 0||e.add(ke.CSS_CANVAS),this.filters.length!==0&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){const e=_g(!1);e instanceof gv&&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([...pv,...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=Wn();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 St(u).setAlpha(d).toRgba():u)}),h}static async fromObject(t){const{colorStops:e,gradientTransform:s}=t;return new this(T(T({},t),{},{colorStops:e?e.map(i=>T({},i)):void 0,gradientTransform:s?[...s]:void 0}))}static fromElement(t,e,s){const i=iv(t),n=e._findCenterFromElement();return new this(T({id:t.getAttribute("id")||void 0,type:sv(t),coords:ex(t,{width:s.viewBoxWidth||s.width,height:s.viewBoxHeight||s.height}),colorStops:tx(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"),G.setClass(el,"gradient"),G.setClass(el,"linear"),G.setClass(el,"radial");const sx=["type","source","patternTransform"];class pg{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=Vn(),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:jt(this.offsetX,vt.NUM_FRACTION_DIGITS),offsetY:jt(this.offsetY,vt.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=It(t,sx);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(pg,"type","Pattern"),G.setClass(pg),G.setClass(pg,"pattern");const ix=["path","left","top"],nx=["d"];class Nr extends Ee{constructor(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{path:s,left:i,top:n}=e,r=It(e,ix);super(),Object.assign(this,Nr.ownDefaults),this.setOptions(r),this._setPath(t||[],!0),typeof i=="number"&&this.set(wt,i),typeof n=="number"&&this.set(ss,n)}_setPath(t,e){this.path=G0(Array.isArray(t)?t:K0(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=J0(this.path,vt.NUM_FRACTION_DIGITS);return["<path ","COMMON_PARTS",'d="'.concat(t,`" stroke-linecap="round" />
|
|
76
|
+
`)]}_getOffsetTransform(){const t=vt.NUM_FRACTION_DIGITS;return" translate(".concat(jt(-this.pathOffset.x,t),", ").concat(jt(-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(...dg(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(...dg(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 xi(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({},It(i,nx)),e),{},{left:void 0,top:void 0}))}}E(Nr,"type","Path"),E(Nr,"cacheProperties",[...Ki,"path","fillRule"]),E(Nr,"ATTRIBUTE_NAMES",[...Xn,"d"]),G.setClass(Nr),G.setSVGClass(Nr);const rx=["left","top","radius"],nv=["radius","startAngle","endAngle","counterClockwise"];class tn extends Ee{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,Ut(this.startAngle),Ut(this.endAngle),this.counterClockwise),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get(Ge)}getRadiusY(){return this.get("radius")*this.get(fs)}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([...nv,...t])}_toSVG(){const t=(this.endAngle-this.startAngle)%360;if(t===0)return["<circle ","COMMON_PARTS",'cx="0" cy="0" ','r="',"".concat(this.radius),`" />
|
|
77
|
+
`];{const{radius:e}=this,s=Ut(this.startAngle),i=Ut(this.endAngle),n=$s(s)*e,r=qs(s)*e,a=$s(i)*e,h=qs(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({},It(i,rx)),{},{radius:a,left:n-a,top:r-a}))}static fromObject(t){return super._fromObject(t)}}E(tn,"type","Circle"),E(tn,"cacheProperties",[...Ki,...nv]),E(tn,"ownDefaults",{radius:0,startAngle:0,endAngle:360,counterClockwise:!1}),E(tn,"ATTRIBUTE_NAMES",["cx","cy","r",...Xn]),G.setClass(tn),G.setSVGClass(tn);const ax=["x1","y1","x2","y2"],ox=["x1","y1","x2","y2"],mg=["x1","x2","y1","y2"];class Br extends Ee{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(wt,r),typeof a=="number"&&this.set(ss,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}=xi([{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),mg.includes(t)&&this._setWidthHeight(),this}_render(t){t.beginPath();const e=this.calcLinePoints();t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2),t.lineWidth=this.strokeWidth;const s=t.strokeStyle;var i;Rs(this.stroke)?t.strokeStyle=this.stroke.toLive(t):t.strokeStyle=(i=this.stroke)!==null&&i!==void 0?i:t.fillStyle,this.stroke&&this._renderStroke(t),t.strokeStyle=s}_findCenterFromElement(){return new O((this.x1+this.x2)/2,(this.y1+this.y2)/2)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return 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],It(i,ax))}static fromObject(t){let{x1:e,y1:s,x2:i,y2:n}=t,r=It(t,ox);return this._fromObject(T(T({},r),{},{points:[e,s,i,n]}),{extraParam:"points"})}}E(Br,"type","Line"),E(Br,"cacheProperties",[...Ki,...mg]),E(Br,"ATTRIBUTE_NAMES",Xn.concat(mg)),G.setClass(Br),G.setSVGClass(Br);class Hr extends Ee{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}),G.setClass(Hr),G.setSVGClass(Hr);const rv=["rx","ry"];class en extends Ee{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(Ge)}getRy(){return this.get("ry")*this.get(fs)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...rv,...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 hx(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,...rv]),E(en,"ownDefaults",{rx:0,ry:0}),E(en,"ATTRIBUTE_NAMES",[...Xn,"cx","cy","rx","ry"]),G.setClass(en),G.setSVGClass(en);const lx=["left","top"],av={exactBoundingBox:!1};class si extends Ee{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,"strokeDiff",void 0),Object.assign(this,si.ownDefaults),this.setOptions(e),this.points=t;const{left:s,top:i}=e;this.initialized=!0,this.setBoundingBox(!0),typeof s=="number"&&this.set(wt,s),typeof i=="number"&&this.set(ss,i)}isOpen(){return!0}_projectStrokeOnPoints(t){return C0(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=xi(e),i=Wh(T(T({},t),{},{scaleX:1,scaleY:1})),n=xi(this.points.map(c=>Te(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(Ut(this.skewX)),h-=a*Math.tan(Ut(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=xi(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===Ge||t===fs)&&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=vt.NUM_FRACTION_DIGITS;for(let n=0,r=this.points.length;n<r;n++)t.push(jt(this.points[n].x-e,i),",",jt(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(hx(t.getAttribute("points")),T(T({},It(Qi(t,this.ATTRIBUTE_NAMES,s),lx)),e))}static fromObject(t){return this._fromObject(t,{extraParam:"points"})}}E(si,"ownDefaults",av),E(si,"type","Polyline"),E(si,"layoutProperties",[ao,oo,"strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeWidth","strokeUniform","points"]),E(si,"cacheProperties",[...Ki,"points"]),E(si,"ATTRIBUTE_NAMES",[...Xn]),G.setClass(si),G.setSVGClass(si);class Iu extends si{isOpen(){return!1}}E(Iu,"ownDefaults",av),E(Iu,"type","Polygon"),G.setClass(Iu),G.setSVGClass(Iu);const ov=["fontSize","fontWeight","fontFamily","fontStyle"],hv=["underline","overline","linethrough"],lv=[...ov,"lineHeight","text","charSpacing","textAlign","styles","path","pathStartOffset","pathSide","pathAlign"],cv=[...lv,...hv,"textBackgroundColor","direction"],cx=[...ov,...hv,Ve,"strokeWidth",se,"deltaY","textBackgroundColor"],ux={_reNewline:Of,_reSpacesAndTabs:/[ \t\r]/g,_reSpaceAndTab:/[ \t\r]/,_reWords:/\S+/g,fontSize:40,fontWeight:"normal",fontFamily:"Times New Roman",underline:!1,overline:!1,linethrough:!1,textAlign:wt,fontStyle:"normal",lineHeight:1.16,superscript:{size:.6,baseline:-.35},subscript:{size:.6,baseline:.11},textBackgroundColor:"",stroke:null,shadow:null,path:void 0,pathStartOffset:0,pathSide:wt,pathAlign:"baseline",_fontSizeFraction:.222,offsets:{underline:.1,linethrough:-.315,overline:-.88},_fontSizeMult:1.13,charSpacing:0,deltaY:0,direction:"ltr",CACHE_FONT_SIZE:400,MIN_TEXT_WIDTH:2},Ai="justify",ju="justify-left",sl="justify-right",il="justify-center";class uv extends Ee{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=Bf(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(uv,"_styleProperties",cx);const dx=/ +/g,fx=/"/g;function vg(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]:vt.NUM_FRACTION_DIGITS;const f=$h(se,n,!1),[g,p,v,_]=[a,h,c,u].map(b=>jt(b,d));return"<rect ".concat(f,' x="').concat(g,'" y="').concat(p,'" width="').concat(v,'" height="').concat(_,'"></rect>')}(o,{left:t,top:e,width:s,height:i}),`
|
|
82
|
+
`)}const gx=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let bg;class ke extends uv{static getDefaults(){return T(T({},super.getDefaults()),ke.ownDefaults)}constructor(t,e){super(),E(this,"__charBounds",[]),Object.assign(this,ke.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=fg(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(Ai)&&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===Ai||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=ss;break;case"descender":t.textBaseline=Mf}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 v=0;v<h;v++){const _=this.__charBounds[n][v];d=this.getValueOfPropertyAt(n,v,"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=zh.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 bg||(bg=Ks({width:0,height:0}).getContext("2d")),bg}();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===Kt,r=this.path,a=this._textLines[t],h=a.length,c=new Array(h);this.__charBounds[t]=c;for(let u=0;u<h;u++){const d=a[u];s=this._getGraphemeBox(d,t,u,e),c[u]=s,i+=s.kernedWidth,e=d}if(c[h]={left:s?s.left+s.width:0,width:0,kernedWidth:0,height:this.fontSize,deltaY:0},r&&r.segmentsInfo){let u=0;const d=r.segmentsInfo[r.segmentsInfo.length-1].length;switch(this.textAlign){case wt:u=n?d-i:0;break;case et:u=(d-i)/2;break;case Kt: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=$0(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===Kt?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(se))&&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(Ai),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,v,_,b,x,S="",A=0;if(e.save(),g!==this.direction&&(e.canvas.setAttribute("dir",d?"ltr":"rtl"),e.direction=d?"ltr":"rtl",e.textAlign=d?wt:Kt),n-=a*this._fontSizeFraction/this.lineHeight,u)return this._renderChar(t,e,r,0,s.join(""),i,n),void e.restore();for(let k=0,M=s.length-1;k<=M;k++)b=k===M||this.charSpacing||c,S+=s[k],_=this.__charBounds[r][k],A===0?(i+=f*(_.kernedWidth-_.width),A+=_.width):A+=_.kernedWidth,h&&!b&&this._reSpaceAndTab.test(s[k])&&(b=!0),b||(p=p||this.getCompleteStyleDeclaration(r,k),v=this.getCompleteStyleDeclaration(r,k+1),b=Eu(p,v,!1)),b&&(c?(e.save(),e.translate(_.renderLeft,_.renderTop),e.rotate(_.angle),this._renderChar(t,e,r,k,S,-A/2,0),e.restore()):(x=i,this._renderChar(t,e,r,k,S,x,n)),S="",p=v,i+=f*A,A=0);e.restore()}_applyPatternGradientTransformText(t){const e=this.width+this.strokeWidth,s=this.height+this.strokeWidth,i=Ks({width:e,height:s}),n=i.getContext("2d");return i.width=e,i.height=s,n.beginPath(),n.moveTo(0,0),n.lineTo(e,0),n.lineTo(e,s),n.lineTo(0,s),n.closePath(),n.translate(e/2,s/2),n.fillStyle=t.toLive(n),this._applyPatternGradientTransform(n,t),n.fill(),n.createPattern(i,"no-repeat")}handleFiller(t,e,s){let i,n;return Rs(s)?s.gradientUnits==="percentage"||s.gradientTransform||s.patternTransform?(i=-this.width/2,n=-this.height/2,t.translate(i,n),t[e]=this._applyPatternGradientTransformText(s),{offsetX:i,offsetY:n}):(t[e]=s.toLive(t),this._applyPatternGradientTransform(t,s)):(t[e]=s,{offsetX:0,offsetY:0})}_setStrokeStyles(t,e){let{stroke:s,strokeWidth:i}=e;return t.lineWidth=i,t.lineCap=this.strokeLineCap,t.lineDashOffset=this.strokeDashOffset,t.lineJoin=this.strokeLineJoin,t.miterLimit=this.strokeMiterLimit,this.handleFiller(t,"strokeStyle",s)}_setFillStyles(t,e){let{fill:s}=e;return this.handleFiller(t,"fillStyle",s)}_renderChar(t,e,s,i,n,r,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===Ai||i===il&&!r||i===sl&&!r||i===ju&&!r?0:(i===et&&(a=s/2),i===Kt&&(a=s),i===il&&(a=s/2),i===sl&&(a=s),n==="rtl"&&(i===Kt||i===Ai||i===sl?a=0:i===wt||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,v,_=0,b=0,x=this.getValueOfPropertyAt(h,0,e),S=this.getValueOfPropertyAt(h,0,se);const A=s+f*(1-this._fontSizeFraction);let k=this.getHeightOfChar(h,0),M=this.getValueOfPropertyAt(h,0,"deltaY");for(let P=0,R=d.length;P<R;P++){const F=this.__charBounds[h][P];p=this.getValueOfPropertyAt(h,P,e),v=this.getValueOfPropertyAt(h,P,se);const I=this.getHeightOfChar(h,P),H=this.getValueOfPropertyAt(h,P,"deltaY");if(n&&p&&v)t.save(),t.fillStyle=S,t.translate(F.renderLeft,F.renderTop),t.rotate(F.angle),t.fillRect(-F.kernedWidth/2,a*I+H,F.kernedWidth,this.fontSize/15),t.restore();else if((p!==x||v!==S||I!==k||H!==M)&&b>0){let W=i+g+_;this.direction==="rtl"&&(W=this.width-W-b),x&&S&&(t.fillStyle=S,t.fillRect(W,A+a*k+M,b,this.fontSize/15)),_=F.left,b=F.width,x=p,S=v,k=I,M=H}else b+=F.kernedWidth}let D=i+g+_;this.direction==="rtl"&&(D=this.width-D-b),t.fillStyle=v,p&&v&&t.fillRect(D,A+a*k+M,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(",")||ke.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([...cv,...t])),{},{styles:T0(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,ke.ATTRIBUTE_NAMES,s),n=T(T({},e),i),{textAnchor:r=wt,textDecoration:a="",dx:h=0,dy:c=0,top:u=0,left:d=0,fontSize:f=Pf,strokeWidth:g=1}=n,p=It(n,gx),v=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)),_=v.getScaledHeight()/v.height,b=((v.height+v.strokeWidth)*v.lineHeight-v.height)*_,x=v.getScaledHeight()+b;let S=0;return r===et&&(S=v.getScaledWidth()/2),r===Kt&&(S=v.getScaledWidth()),v.set({left:v.left-S,top:v.top-(x-v.fontSize*(.07+v._fontSizeFraction))/v.lineHeight,strokeWidth:g}),v}static fromObject(t){return this._fromObject(T(T({},t),{},{styles:E0(t.styles||{},t.text)}),{extraParam:"text"})}}E(ke,"textLayoutProperties",lv),E(ke,"cacheProperties",[...Ki,...cv]),E(ke,"ownDefaults",ux),E(ke,"type","Text"),E(ke,"genericFonts",["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong"]),E(ke,"ATTRIBUTE_NAMES",Xn.concat("x","y","dx","dy","font-family","font-style","font-weight","font-size","letter-spacing","text-decoration","text-anchor")),_0(ke,[class extends t0{_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(fx,"'"),'" '):"",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(...vg(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(dx)),n=i?'style="'.concat(i,'"'):"",r=t.deltaY,a=r?' dy="'.concat(jt(r,vt.NUM_FRACTION_DIGITS),'" '):"";return'<tspan x="'.concat(jt(e,vt.NUM_FRACTION_DIGITS),'" y="').concat(jt(s,vt.NUM_FRACTION_DIGITS),'" ').concat(a).concat(n,">").concat(A0(o),"</tspan>")}_setSVGTextLineText(o,t,e,s){const i=this.getHeightOfLine(t),n=this.textAlign.includes(Ai),r=this._textLines[t];let a,h,c,u,d,f="",g=0;s+=i*(1-this._fontSizeFraction)/this.lineHeight;for(let p=0,v=r.length-1;p<=v;p++)d=p===v||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(...vg(c,e+h,s,a,n)),h=d,a=f,c=r):a+=g}r&&o.push(...vg(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(se,n):"",c?"baseline-shift: ".concat(-c,"; "):"",t?"white-space: pre; ":""].join("")}getSvgTextDecoration(o){return["overline","underline","line-through"].filter(t=>o[t.replace("-","")]).join(" ")}}]),G.setClass(ke),G.setSVGClass(ke);class px{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)),v=a.viewportTransform,_=p.add(d).transform(v,!0),b=r.backgroundColor,x=ag(r.styles);r.backgroundColor="";const S={stroke:"transparent",fill:"transparent",textBackgroundColor:"transparent"};r.setSelectionStyles(S,0,i),r.setSelectionStyles(S,n,r.text.length),r.dirty=!0;const A=r.toCanvasElement({enableRetinaScaling:a.enableRetinaScaling,viewportTransform:!0});r.backgroundColor=b,r.styles=x,r.dirty=!0,Ru(A,{position:"fixed",left:"".concat(-A.width,"px"),border:ze,width:"".concat(A.width/f,"px"),height:"".concat(A.height/f,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{A.remove()},Js(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)||ze;h===ze?(i.selectionStart=r,i.selectionEnd=a,i._updateTextarea(),i.hiddenTextarea.focus()):(i.clearContextTop(),h==="move"&&(i.removeChars(r,a),i.selectionStart=i.selectionEnd=r,i.hiddenTextarea&&(i.hiddenTextarea.value=i.text),i._updateTextarea(),i.fire(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 dv=/[ \n\.,;!\?\-]/;class mx extends ke{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 ig({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||!Of.test(s[t-1]))?t-1:t,n=s[i];for(;i>0&&i<s.length&&!dv.test(n);)i+=e,n=s[i];return e===-1&&dv.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;Js(e).activeElement!==e&&e.focus();const s=this.getSelectionStartFromPointer(t),i=this.selectionStart,n=this.selectionEnd;(s===this.__selectionStartOnMouseDown&&i!==n||i!==s&&n!==s)&&(s>this.__selectionStartOnMouseDown?(this.selectionStart=this.__selectionStartOnMouseDown,this.selectionEnd=s):(this.selectionStart=s,this.selectionEnd=this.__selectionStartOnMouseDown),this.selectionStart===i&&this.selectionEnd===n||(this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()))}_setEditingProps(){this.hoverCursor="text",this.canvas&&(this.canvas.defaultCursor=this.canvas.moveCursor="text"),this.borderColor=this.editingBorderColor,this.hasControls=this.selectable=!1,this.lockMovementX=this.lockMovementY=!0}fromStringToGraphemeSelection(t,e,s){const i=s.slice(0,t),n=this.graphemeSplit(i).length;if(t===e)return{selectionStart:n,selectionEnd:n};const r=s.slice(t,e);return{selectionStart:n,selectionEnd:n+this.graphemeSplit(r).length}}fromGraphemeToStringSelection(t,e,s){const i=s.slice(0,t).join("").length;return t===e?{selectionStart:i,selectionEnd:i}:{selectionStart:i,selectionEnd:i+s.slice(t,e).join("").length}}_updateTextarea(){if(this.cursorOffsetCache={},this.hiddenTextarea){if(!this.inCompositionMode){const t=this.fromGraphemeToStringSelection(this.selectionStart,this.selectionEnd,this._text);this.hiddenTextarea.selectionStart=t.selectionStart,this.hiddenTextarea.selectionEnd=t.selectionEnd}this.updateTextareaPosition()}}updateFromTextArea(){if(!this.hiddenTextarea)return;this.cursorOffsetCache={};const t=this.hiddenTextarea;this.text=t.value,this.set("dirty",!0),this.initDimensions(),this.setCoords();const e=this.fromStringToGraphemeSelection(t.selectionStart,t.selectionEnd,t.value);this.selectionEnd=this.selectionStart=e.selectionEnd,this.inCompositionMode||(this.selectionStart=e.selectionStart),this.updateTextareaPosition()}updateTextareaPosition(){if(this.selectionStart===this.selectionEnd){const t=this._calcTextareaPosition();this.hiddenTextarea.style.left=t.left,this.hiddenTextarea.style.top=t.top}}_calcTextareaPosition(){if(!this.canvas)return{left:"1px",top:"1px"};const t=this.inCompositionMode?this.compositionStart:this.selectionStart,e=this._getCursorBoundaries(t),s=this.get2DCursorLocation(t),i=s.lineIndex,n=s.charIndex,r=this.getValueOfPropertyAt(i,n,"fontSize")*this.lineHeight,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=wt:this._selectionDirection===Kt&&(this._selectionDirection=wt,this.selectionEnd=t),this.selectionStart=s):s>t&&s<e?this._selectionDirection===Kt?this.selectionEnd=s:this.selectionStart=s:(e===t?this._selectionDirection=Kt:this._selectionDirection===wt&&(this._selectionDirection=Kt,this.selectionStart=e),this.selectionEnd=s)}}class vx extends mx{initHiddenTextarea(){const t=this.canvas&&Js(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 v=this.fromStringToGraphemeSelection(this.hiddenTextarea.selectionStart,this.hiddenTextarea.selectionEnd,this.hiddenTextarea.value),_=a>v.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 b=i.slice(v.selectionEnd-p,v.selectionEnd);if(d&&d.length&&(b.length&&(u=this.getSelectionStyles(a,a+1,!1),u=b.map(()=>u[0])),c?(f=a,g=h):_?(f=h-d.length,g=h):(f=h,g=h+d.length),this.removeStyleFromTo(f,g)),b.length){const{copyPasteData:x}=wi();e&&b.join("")===x.copiedText&&!vt.disableStyleCopyPaste&&(u=x.copiedTextStyle),this.insertNewStyleBlock(b,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}=wi();t.copiedText=this.getSelectedText(),vt.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===Kt);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===wt?this.selectionStart+t:this.selectionEnd+t;return this.setSelectionStartEndWithShift(this.selectionStart,this.selectionEnd,e),t!==0}moveCursorWithoutShift(t){return t<0?(this.selectionStart+=t,this.selectionEnd=this.selectionStart):(this.selectionEnd+=t,this.selectionStart=this.selectionEnd),t!==0}moveCursorLeft(t){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorLeftOrRight("Left",t)}_move(t,e,s){let i;if(t.altKey)i=this["findWordBoundary".concat(s)](this[e]);else{if(!t.metaKey&&t.keyCode!==35&&t.keyCode!==36)return this[e]+=s==="Left"?-1:1,!0;i=this["findLineBoundary".concat(s)](this[e])}return i!==void 0&&this[e]!==i&&(this[e]=i,!0)}_moveLeft(t,e){return this._move(t,e,"Left")}_moveRight(t,e){return this._move(t,e,"Right")}moveCursorLeftWithoutShift(t){let e=!0;return this._selectionDirection=wt,this.selectionEnd===this.selectionStart&&this.selectionStart!==0&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return this._selectionDirection===Kt&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):this.selectionStart!==0?(this._selectionDirection=wt,this._moveLeft(t,"selectionStart")):void 0}moveCursorRight(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorLeftOrRight("Right",t)}_moveCursorLeftOrRight(t,e){const s="moveCursor".concat(t).concat(e.shiftKey?"WithShift":"WithoutShift");this._currentCursorOpacity=1,this[s](e)&&(this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())}moveCursorRightWithShift(t){return this._selectionDirection===wt&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection=Kt,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=Kt,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}const yg=o=>!!o.button;class bx extends vx{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 px(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&&!yg(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&&!yg(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||yg(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(is(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",zu="moveCursorRight",Gu="exitEditing",yx=T({selectionStart:0,selectionEnd:0,selectionColor:"rgba(17,119,255,0.3)",isEditing:!1,editable:!0,editingBorderColor:"rgba(102,153,255,0.25)",cursorWidth:2,cursorColor:"",cursorDelay:1e3,cursorDuration:600,caching:!0,hiddenTextareaContainer:null,keysMap:{9:Gu,27:Gu,33:Nu,34:Bu,35:zu,36:Hu,37:Hu,38:Nu,39:zu,40:Bu},keysMapRtl:{9:Gu,27:Gu,33:Nu,34:Bu,35:Hu,36:zu,37:zu,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 bx{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 gg&&this.canvas.textEditingManager.remove(this),e instanceof gg&&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===Kt||this.textAlign===Ai||this.textAlign===sl?h.left*=-1:this.textAlign===wt||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(Ai),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 v=this.getHeightOfLine(g),_=0,b=0,x=0;if(g===c&&(b=this.__charBounds[c][d].left),g>=c&&g<u)x=r&&!this.isEndOfWrapping(g)?this.width:this.getLineWidth(g)||5;else if(g===u)if(f===0)x=this.__charBounds[u][f].left;else{const D=this._getWidthOfCharSpacing();x=this.__charBounds[u][f-1].left+this.__charBounds[u][f-1].width-D}_=v,(this.lineHeight<1||g===u&&this.lineHeight>1)&&(v/=this.lineHeight);let S=s.left+p+b,A=v,k=0;const M=x-b;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",A=1,k=v):t.fillStyle=this.selectionColor,this.direction==="rtl"&&(this.textAlign===Kt||this.textAlign===Ai||this.textAlign===sl?S=this.width-S-M:this.textAlign===wt||this.textAlign===ju?S=s.left+p-x:this.textAlign!==et&&this.textAlign!==il||(S=s.left+p-x)),t.fillRect(S,s.top+s.topOffset+k,M,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,se)}_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",yx),E(sn,"type","IText"),G.setClass(sn),G.setClass(sn,"i-text");class zr extends sn{static getDefaults(){return T(T({},super.getDefaults()),zr.ownDefaults)}constructor(t,e){super(t,T(T({},zr.ownDefaults),e))}static createControls(){return{controls:iw()}}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(Ai)&&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,v=!0;e-=r;const _=Math.max(e,i,this.dynamicMinWidth),b=n[t];let x;for(g=0,x=0;x<b.length;x++){const{word:S,width:A}=b[x];g+=S.length,d+=p+A-a,d>_&&!v?(c.push(f),f=[],d=A,v=!0):d+=a,v||h||f.push(u),f=f.concat(S),p=h?0:this._measureWord([u],t,g),g++,v=!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(zr,"type","Textbox"),E(zr,"textLayoutProperties",[...sn.textLayoutProperties,"width"]),E(zr,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),G.setClass(zr);class fv 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}=xi(j0(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(fv,"type","clip-path"),G.setClass(fv);class gv extends Ou{getInitialSize(t,e){let{target:s}=t,{size:i}=e;return new O(s.width||i.x,s.height||i.y)}}E(gv,"type","fixed"),G.setClass(gv);class _x 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 Gr extends Ci{static getDefaults(){return T(T({},super.getDefaults()),Gr.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,Gr.ownDefaults),this.setOptions(e);const{left:s,top:i,layoutManager:n}=e;this.groupInit(t,{left:s,top:i,layoutManager:n??new _x})}_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===lg?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(Gr,"type","ActiveSelection"),E(Gr,"ownDefaults",{multiSelectionStacking:"canvas-stacking"}),G.setClass(Gr),G.setClass(Gr,"activeSelection");class wx{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 pv{constructor(){let{tileSize:t=vt.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=Ks({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,v=g.height,_=f.destinationWidth,b=f.destinationHeight;p===_&&v===b||(g.width=_,g.height=b)}(u),this.copyGLTo2D(a,u),a.bindTexture(a.TEXTURE_2D,null),a.deleteTexture(u.sourceTexture),a.deleteTexture(u.targetTexture),a.deleteFramebuffer(d),h.setTransform(1,0,0,1,0,0),u}dispose(){this.canvas&&(this.canvas=null,this.gl=null),this.clearWebGLCaches()}clearWebGLCaches(){this.programCache={},this.textureCache={}}createTexture(t,e,s,i,n){const{NEAREST:r,TEXTURE_2D:a,RGBA:h,UNSIGNED_BYTE:c,CLAMP_TO_EDGE:u,TEXTURE_MAG_FILTER:d,TEXTURE_MIN_FILTER:f,TEXTURE_WRAP_S:g,TEXTURE_WRAP_T:p}=t,v=t.createTexture();return t.bindTexture(a,v),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),v}getCachedTexture(t,e,s){const{textureCache:i}=this;if(i[t])return i[t];{const n=this.createTexture(this.gl,e.width,e.height,e,s);return n&&(i[t]=n),n}}evictCachesForKey(t){this.textureCache[t]&&(this.gl.deleteTexture(this.textureCache[t]),delete this.textureCache[t])}copyGLTo2D(t,e){const s=t.canvas,i=e.targetCanvas,n=i.getContext("2d");if(!n)return;n.translate(0,i.height),n.scale(1,-1);const r=s.height-i.height;n.drawImage(s,0,r,i.width,i.height,0,0,i.width,i.height)}copyGLTo2DPutImageData(t,e){const s=e.targetCanvas.getContext("2d"),i=e.destinationWidth,n=e.destinationHeight,r=i*n*4;if(!s)return;const a=new Uint8Array(this.imageBuffer,0,r),h=new Uint8ClampedArray(this.imageBuffer,0,r);t.readPixels(0,0,i,n,t.RGBA,t.UNSIGNED_BYTE,a);const c=new ImageData(h,i,n);s.putImageData(c,0,0)}captureGPUInfo(){if(this.gpuInfo)return this.gpuInfo;const t=this.gl,e={renderer:"",vendor:""};if(!t)return e;const s=t.getExtension("WEBGL_debug_renderer_info");if(s){const i=t.getParameter(s.UNMASKED_RENDERER_WEBGL),n=t.getParameter(s.UNMASKED_VENDOR_WEBGL);i&&(e.renderer=i.toLowerCase()),n&&(e.vendor=n.toLowerCase())}return this.gpuInfo=e,e}}let _g;function xx(){const{WebGLProbe:o}=wi();return o.queryWebGL(Ds()),vt.enableGLFiltering&&o.isSupported(vt.textureSize)?new pv({tileSize:vt.textureSize}):new wx}function wg(){return!_g&&(!(arguments.length>0&&arguments[0]!==void 0)||arguments[0])&&(_g=xx()),_g}const Sx=["filters","resizeFilter","src","crossOrigin","type"],mv=["cropX","cropY"];class Pe extends Ee{static getDefaults(){return T(T({},super.getDefaults()),Pe.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,Pe.ownDefaults),this.setOptions(e),this.cacheKey="texture".concat(Vn()),this.setElement(typeof t=="string"?(this.canvas&&Js(this.canvas.getElement())||ro()).getElementById(t):t,e)}getElement(){return this._element}setElement(t){var e;let s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._element=t,this._originalElement=t,this._setWidthHeight(s),(e=t.classList)===null||e===void 0||e.add(Pe.CSS_CANVAS),this.filters.length!==0&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){const e=wg(!1);e instanceof pv&&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&&wi().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([...mv,...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=Vn();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!==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,_g().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);_g().applyFilters(t,this._originalElement,s,i,this._element,this.cacheKey),this._originalElement.width===this._element.width&&this._originalElement.height===this._element.height||(this._filterScalingX=this._element.width/this._originalElement.width,this._filterScalingY=this._element.height/this._originalElement.height)}_render(t){t.imageSmoothingEnabled=this.imageSmoothing,this.isMoving!==!0&&this.resizeFilter&&this._needsResize()&&this.applyResizeFilters(),this._stroke(t),this._renderPaintInOrder(t)}drawCacheOnCanvas(t){t.imageSmoothingEnabled=this.imageSmoothing,super.drawCacheOnCanvas(t)}shouldCache(){return this.needsItsOwnCache()}_renderFill(t){const e=this._element;if(!e)return;const s=this._filterScalingX,i=this._filterScalingY,n=this.width,r=this.height,a=Math.max(this.cropX,0),h=Math.max(this.cropY,0),c=e.naturalWidth||e.width,u=e.naturalHeight||e.height,d=a*s,f=h*i,g=Math.min(n*s,c-d),p=Math.min(r*i,u-f),v=-n/2,_=-r/2,b=Math.min(n,c/s-a),x=Math.min(r,u/i-h);e&&t.drawImage(e,d,f,g,p,v,_,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=Hf(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=N0(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=B0(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 wg(o){if(!C_.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&&s0.test(t)),g=!h||!c||h==="100%"||c==="100%";let p="",v=0,_=0;if(f&&(u||d)&&o.parentNode&&o.parentNode.nodeName!=="#document"&&(p=" translate("+Ve(u||"0")+" "+Ve(d||"0")+") ",e=(o.getAttribute("transform")||"")+p,o.setAttribute("transform",e),o.removeAttribute("x"),o.removeAttribute("y")),f&&g)return{width:0,height:0};const b={width:0,height:0};if(f)return b.width=Ve(h),b.height=Ve(c),b;const x=t.match(s0);r=-parseFloat(x[1]),a=-parseFloat(x[2]);const C=parseFloat(x[3]),A=parseFloat(x[4]);b.minX=r,b.minY=a,b.viewBoxWidth=C,b.viewBoxHeight=A,g?(b.width=C,b.height=A):(b.width=Ve(h),b.height=Ve(c),i=b.width/C,n=b.height/A);const P=Hf(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),v=b.width-C*i,_=b.height-A*i,P.alignX==="Mid"&&(v/=2),P.alignY==="Mid"&&(_/=2),P.alignX==="Min"&&(v=0),P.alignY==="Min"&&(_=0)),i===1&&n===1&&r===0&&a===0&&u===0&&d===0)return b;if((u||d)&&o.parentNode.nodeName!=="#document"&&(p=" translate("+Ve(u||"0")+" "+Ve(d||"0")+") "),e=p+" matrix("+i+" 0 0 "+n+" "+(r*i+v)+" "+(a*n+_)+") ",o.nodeName==="svg"){for(s=o.ownerDocument.createElementNS(Uf,"g");o.firstChild;)s.appendChild(o.firstChild);o.appendChild(s)}else s=o,s.removeAttribute("x"),s.removeAttribute("y"),e=s.getAttribute("transform")+e;return s.setAttribute("transform",e),b}E(ke,"type","Image"),E(ke,"cacheProperties",[...Ki,...pv]),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"]),G.setClass(ke),G.setSVGClass(ke);const Wu=o=>o.tagName.replace("svg:",""),_x=bu(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);function mv(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 wx=["gradientTransform","x1","x2","y1","y2","gradientUnits","cx","cy","r","fx","fy"],xg="xlink:href";function vv(o,t){var e;const s=((e=t.getAttribute(xg))===null||e===void 0?void 0:e.slice(1))||"",i=o.getElementById(s);if(i&&i.getAttribute(xg)&&vv(o,i),i&&(wx.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(xg)}const xx=["linearGradient","radialGradient","svg:linearGradient","svg:radialGradient"];function Sx(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 bv=o=>G.getSVGClass(Wu(o).toLowerCase());class Cx{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=mv(r,xx),h={};let c=a.length;for(;c--;){const u=a[c];u.getAttribute("xlink:href")&&vv(r,u);const d=u.getAttribute("id");d&&(h[d]=u)}return h}(i),this.cssRules=Sx(i)}parse(){return Promise.all(this.elements.map(t=>this.createObject(t)))}async createObject(t){const e=bv(t);if(e){const s=await e.fromElement(t,this.options,this.cssRules);return this.resolveGradient(s,t,Zt),this.resolveGradient(s,t,Ge),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=>bv(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:v,translateX:_,translateY:b}=Rr(d);u.set({flipX:!1,flipY:!1}),u.set({scaleX:f,scaleY:g,angle:p,skewX:v,skewY:0}),u.setPositionByOrigin(new O(_,b),et,et),t.clipPath=u}else delete t.clipPath}}const yv=o=>S_.test(Wu(o)),Sg=()=>({objects:[],elements:[],options:{},allElements:[]});async function Ax(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")),Sg();const i=o.documentElement;(function(u){const d=mv(u,["use","svg:use"]),f=["x","y","xlink:href","href","transform"];for(const g of d){const p=g.attributes,v={};for(const R of p)R.value&&(v[R.name]=R.value);const _=(v["xlink:href"]||v.href||"").slice(1);if(_==="")return;const b=u.getElementById(_);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=""}=v,M="".concat(k," ").concat(A.transform||""," translate(").concat(P,", ").concat(D,")");if(wg(x),/^svg$/i.test(x.nodeName)){const R=x.ownerDocument.createElementNS(Uf,"g");Object.entries(A).forEach(F=>{let[I,Y]=F;return R.setAttributeNS(Uf,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={};og(I,Y),Object.entries(A).forEach(H=>{let[at,j]=H;Y[at]=j}),og(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({},wg(i)),{},{crossOrigin:e,signal:s}),a=n.filter(u=>(wg(u),yv(u)&&!function(d){let f=d;for(;f&&(f=f.parentElement);)if(f&&f.nodeName&&_x.test(Wu(f))&&!f.getAttribute("instantiated_by_use"))return!0;return!1}(u)));if(!a||a&&!a.length)return T(T({},Sg()),{},{options:r,allElements:n});const h={};return n.filter(u=>Wu(u)==="clipPath").forEach(u=>{u.setAttribute("originalTransform",u.getAttribute("transform")||"");const d=u.getAttribute("id");h[d]=Array.from(u.getElementsByTagName("*")).filter(f=>yv(f))}),{objects:await new Cx(a,r,t,o,h).parse(),elements:a,options:r,allElements:n}}function Tx(o,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return new Promise((s,i)=>{J0(o.replace(/^\n\s*/,"").trim(),{onComplete:n=>{const r=n.responseXML;r&&s(r),i()},signal:e.signal})}).then(s=>Ax(s,t,e)).catch(()=>Sg())}const zu=o=>o.webgl!==void 0,Cg="precision highp float",Ex=`
|
|
92
|
-
`.concat(
|
|
91
|
+
`)],this.fill=c}return n=this.paintFirst!==se?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=Ks(r),{width:h,height:c}=r;this._element=a,this._lastScaleX=t.scaleX=i,this._lastScaleY=t.scaleY=n,wg().applyFilters([t],r,h,c,this._element),this._filterScalingX=a.width/this._originalElement.width,this._filterScalingY=a.height/this._originalElement.height}applyFilters(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.filters||[];if(t=t.filter(n=>n&&!n.isNeutralState()),this.set("dirty",!0),this.removeTexture("".concat(this.cacheKey,"_filtered")),t.length===0)return this._element=this._originalElement,this._filteredEl=void 0,this._filterScalingX=1,void(this._filterScalingY=1);const e=this._originalElement,s=e.naturalWidth||e.width,i=e.naturalHeight||e.height;if(this._element===this._originalElement){const n=Ks({width:s,height:i});this._element=n,this._filteredEl=n}else this._filteredEl&&(this._element=this._filteredEl,this._filteredEl.getContext("2d").clearRect(0,0,s,i),this._lastScaleX=1,this._lastScaleY=1);wg().applyFilters(t,this._originalElement,s,i,this._element,this.cacheKey),this._originalElement.width===this._element.width&&this._originalElement.height===this._element.height||(this._filterScalingX=this._element.width/this._originalElement.width,this._filterScalingY=this._element.height/this._originalElement.height)}_render(t){t.imageSmoothingEnabled=this.imageSmoothing,this.isMoving!==!0&&this.resizeFilter&&this._needsResize()&&this.applyResizeFilters(),this._stroke(t),this._renderPaintInOrder(t)}drawCacheOnCanvas(t){t.imageSmoothingEnabled=this.imageSmoothing,super.drawCacheOnCanvas(t)}shouldCache(){return this.needsItsOwnCache()}_renderFill(t){const e=this._element;if(!e)return;const s=this._filterScalingX,i=this._filterScalingY,n=this.width,r=this.height,a=Math.max(this.cropX,0),h=Math.max(this.cropY,0),c=e.naturalWidth||e.width,u=e.naturalHeight||e.height,d=a*s,f=h*i,g=Math.min(n*s,c-d),p=Math.min(r*i,u-f),v=-n/2,_=-r/2,b=Math.min(n,c/s-a),x=Math.min(r,u/i-h);e&&t.drawImage(e,d,f,g,p,v,_,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=zf(this.preserveAspectRatio||""),e=this.width,s=this.height,i={width:e,height:s};let n,r=this._element.width,a=this._element.height,h=1,c=1,u=0,d=0,f=0,g=0;return!t||t.alignX===ze&&t.alignY===ze?(h=e/r,c=s/a):(t.meetOrSlice==="meet"&&(h=c=B0(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=H0(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=It(t,Sx);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 xg(o){if(!k_.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&&i0.test(t)),g=!h||!c||h==="100%"||c==="100%";let p="",v=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 b={width:0,height:0};if(f)return b.width=We(h),b.height=We(c),b;const x=t.match(i0);r=-parseFloat(x[1]),a=-parseFloat(x[2]);const S=parseFloat(x[3]),A=parseFloat(x[4]);b.minX=r,b.minY=a,b.viewBoxWidth=S,b.viewBoxHeight=A,g?(b.width=S,b.height=A):(b.width=We(h),b.height=We(c),i=b.width/S,n=b.height/A);const k=zf(o.getAttribute("preserveAspectRatio")||"");if(k.alignX!==ze&&(k.meetOrSlice==="meet"&&(n=i=i>n?n:i),k.meetOrSlice==="slice"&&(n=i=i>n?i:n),v=b.width-S*i,_=b.height-A*i,k.alignX==="Mid"&&(v/=2),k.alignY==="Mid"&&(_/=2),k.alignX==="Min"&&(v=0),k.alignY==="Min"&&(_=0)),i===1&&n===1&&r===0&&a===0&&u===0&&d===0)return b;if((u||d)&&o.parentNode.nodeName!=="#document"&&(p=" translate("+We(u||"0")+" "+We(d||"0")+") "),e=p+" matrix("+i+" 0 0 "+n+" "+(r*i+v)+" "+(a*n+_)+") ",o.nodeName==="svg"){for(s=o.ownerDocument.createElementNS(Yf,"g");o.firstChild;)s.appendChild(o.firstChild);o.appendChild(s)}else s=o,s.removeAttribute("x"),s.removeAttribute("y"),e=s.getAttribute("transform")+e;return s.setAttribute("transform",e),b}E(Pe,"type","Image"),E(Pe,"cacheProperties",[...Ki,...mv]),E(Pe,"ownDefaults",{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),E(Pe,"CSS_CANVAS","canvas-img"),E(Pe,"ATTRIBUTE_NAMES",[...Xn,"x","y","width","height","preserveAspectRatio","xlink:href","crossOrigin","image-rendering"]),G.setClass(Pe),G.setSVGClass(Pe);const Vu=o=>o.tagName.replace("svg:",""),Cx=bu(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);function vv(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 Ax=["gradientTransform","x1","x2","y1","y2","gradientUnits","cx","cy","r","fx","fy"],Sg="xlink:href";function bv(o,t){var e;const s=((e=t.getAttribute(Sg))===null||e===void 0?void 0:e.slice(1))||"",i=o.getElementById(s);if(i&&i.getAttribute(Sg)&&bv(o,i),i&&(Ax.forEach(n=>{const r=i.getAttribute(n);!t.hasAttribute(n)&&r&&t.setAttribute(n,r)}),!t.children.length)){const n=i.cloneNode(!0);for(;n.firstChild;)t.appendChild(n.firstChild)}t.removeAttribute(Sg)}const Tx=["linearGradient","radialGradient","svg:linearGradient","svg:radialGradient"];function Ex(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 yv=o=>G.getSVGClass(Vu(o).toLowerCase());class kx{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=vv(r,Tx),h={};let c=a.length;for(;c--;){const u=a[c];u.getAttribute("xlink:href")&&bv(r,u);const d=u.getAttribute("id");d&&(h[d]=u)}return h}(i),this.cssRules=Ex(i)}parse(){return Promise.all(this.elements.map(t=>this.createObject(t)))}async createObject(t){const e=yv(t);if(e){const s=await e.fromElement(t,this.options,this.cssRules);return this.resolveGradient(s,t,se),this.resolveGradient(s,t,Ve),s instanceof Pe&&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=is(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=>yv(x).fromElement(x,this.options,this.cssRules).then(S=>(Lu(S),S.fillRule=S.clipRule,delete S.clipRule,S)))),u=c.length===1?c[0]:new Ci(c),d=Jt(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:v,translateX:_,translateY:b}=Rr(d);u.set({flipX:!1,flipY:!1}),u.set({scaleX:f,scaleY:g,angle:p,skewX:v,skewY:0}),u.setPositionByOrigin(new O(_,b),et,et),t.clipPath=u}else delete t.clipPath}}const _v=o=>E_.test(Vu(o)),Cg=()=>({objects:[],elements:[],options:{},allElements:[]});async function Px(o,t){let{crossOrigin:e,signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(s&&s.aborted)return Yi("log",new Tf("parseSVGDocument")),Cg();const i=o.documentElement;(function(u){const d=vv(u,["use","svg:use"]),f=["x","y","xlink:href","href","transform"];for(const g of d){const p=g.attributes,v={};for(const R of p)R.value&&(v[R.name]=R.value);const _=(v["xlink:href"]||v.href||"").slice(1);if(_==="")return;const b=u.getElementById(_);if(b===null)return;let x=b.cloneNode(!0);const S=x.attributes,A={};for(const R of S)R.value&&(A[R.name]=R.value);const{x:k=0,y:M=0,transform:D=""}=v,P="".concat(D," ").concat(A.transform||""," translate(").concat(k,", ").concat(M,")");if(xg(x),/^svg$/i.test(x.nodeName)){const R=x.ownerDocument.createElementNS(Yf,"g");Object.entries(A).forEach(F=>{let[I,H]=F;return R.setAttributeNS(Yf,I,H)}),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 H={};hg(I,H),Object.entries(A).forEach(B=>{let[ht,j]=B;H[ht]=j}),hg(A.style||"",H);const W=Object.entries(H).map(B=>B.join(":")).join(";");x.setAttribute(F,W)}else!A[F]&&x.setAttribute(F,I)}x.setAttribute("transform",P),x.setAttribute("instantiated_by_use","1"),x.removeAttribute("id"),g.parentNode.replaceChild(x,g)}})(o);const n=Array.from(i.getElementsByTagName("*")),r=T(T({},xg(i)),{},{crossOrigin:e,signal:s}),a=n.filter(u=>(xg(u),_v(u)&&!function(d){let f=d;for(;f&&(f=f.parentElement);)if(f&&f.nodeName&&Cx.test(Vu(f))&&!f.getAttribute("instantiated_by_use"))return!0;return!1}(u)));if(!a||a&&!a.length)return T(T({},Cg()),{},{options:r,allElements:n});const h={};return n.filter(u=>Vu(u)==="clipPath").forEach(u=>{u.setAttribute("originalTransform",u.getAttribute("transform")||"");const d=u.getAttribute("id");h[d]=Array.from(u.getElementsByTagName("*")).filter(f=>_v(f))}),{objects:await new kx(a,r,t,o,h).parse(),elements:a,options:r,allElements:n}}function Mx(o,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return new Promise((s,i)=>{Q0(o.replace(/^\n\s*/,"").trim(),{onComplete:n=>{const r=n.responseXML;r&&s(r),i()},signal:e.signal})}).then(s=>Px(s,t,e)).catch(()=>Cg())}const Wu=o=>o.webgl!==void 0,Ag="precision highp float",Ox=`
|
|
92
|
+
`.concat(Ag,`;
|
|
93
93
|
varying vec2 vTexCoord;
|
|
94
94
|
uniform sampler2D uTexture;
|
|
95
95
|
void main() {
|
|
96
96
|
gl_FragColor = texture2D(uTexture, vTexCoord);
|
|
97
|
-
}`),
|
|
97
|
+
}`),Dx=["type"],Rx=["type"],Lx=new RegExp(Ag,"g");class he{get type(){return this.constructor.type}constructor(){let t=It(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},Dx);Object.assign(this,this.constructor.defaults,t)}getFragmentSource(){return Ox}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"}}=wi();i!=="highp"&&(e=e.replace(Lx,Ag.replace("highp",i)));const n=t.createShader(t.VERTEX_SHADER),r=t.createShader(t.FRAGMENT_SHADER),a=t.createProgram();if(!n||!r||!a)throw new _i("Vertex, fragment shader or program creation error");if(t.shaderSource(n,s),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new _i("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 _i("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 _i('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){Wu(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=Ks({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(It(t,Rx))}}E(he,"type","BaseFilter"),E(he,"uniformLocations",[]);const Fx={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 Xu extends
|
|
130
|
+
`};class Xu extends he{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return`
|
|
131
131
|
precision highp float;
|
|
132
132
|
uniform sampler2D uTexture;
|
|
133
133
|
uniform vec4 uColor;
|
|
@@ -136,10 +136,10 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
136
136
|
vec4 color = texture2D(uTexture, vTexCoord);
|
|
137
137
|
gl_FragColor = color;
|
|
138
138
|
if (color.a > 0.0) {
|
|
139
|
-
`.concat(
|
|
139
|
+
`.concat(Fx[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 St(this.color).getSource(),i=this.alpha,n=s[0]*i,r=s[1]*i,a=s[2]*i,h=1-i;for(let c=0;c<e.length;c+=4){const u=e[c],d=e[c+1],f=e[c+2];let g,p,v;switch(this.mode){case"multiply":g=u*n/255,p=d*r/255,v=f*a/255;break;case"screen":g=255-(255-u)*(255-n)/255,p=255-(255-d)*(255-r)/255,v=255-(255-f)*(255-a)/255;break;case"add":g=u+n,p=d+r,v=f+a;break;case"difference":g=Math.abs(u-n),p=Math.abs(d-r),v=Math.abs(f-a);break;case"subtract":g=u-n,p=d-r,v=f-a;break;case"darken":g=Math.min(u,n),p=Math.min(d,r),v=Math.min(f,a);break;case"lighten":g=Math.max(u,n),p=Math.max(d,r),v=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,v=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,v=a+f-2*a*f/255;break;case"tint":g=n+u*h,p=r+d*h,v=a+f*h}e[c]=g,e[c+1]=p,e[c+2]=v}}sendUniformData(t,e){const s=new St(this.color).getSource();s[0]=this.alpha*s[0]/255,s[1]=this.alpha*s[1]/255,s[2]=this.alpha*s[2]/255,s[3]=this.alpha,t.uniform4fv(e.uColor,s)}}E(Xu,"defaults",{color:"#F95C63",mode:"multiply",alpha:1}),E(Xu,"type","BlendColor"),E(Xu,"uniformLocations",["uColor"]),G.setClass(Xu);const Ix={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
|
+
`},jx=["type","image"];class Uu extends he{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return Ix[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=Ds());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],v=c[u],_=c[u+1],b=c[u+2],x=c[u+3];switch(this.mode){case"multiply":e[u]=d*v/255,e[u+1]=f*_/255,e[u+2]=g*b/255,e[u+3]=p*x/255;break;case"mask":e[u+3]=x}}}sendUniformData(t,e){const s=this.calculateMatrix();t.uniform1i(e.uImage,1),t.uniformMatrix3fv(e.uTransformMatrix,!1,s)}toObject(){return T(T({},super.toObject()),{},{image:this.image&&this.image.toObject()})}static async fromObject(t,e){let{type:s,image:i}=t,n=It(t,jx);return Pe.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"]),G.setClass(Uu);class Yu extends he{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){Wu(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=Ds(),i.blurLayer2=Ds());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,v,_;for(c.putImageData(s,0,0),u.clearRect(0,0,n,r),_=-15;_<=d;_++)g=(Math.random()-.5)/4,p=_/d,v=f*p*n+g,u.globalAlpha=1-Math.abs(p),u.drawImage(a,v,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,v=f*p*r+g,u.globalAlpha=1-Math.abs(p),u.drawImage(a,g,v),c.drawImage(h,0,0),u.globalAlpha=1,u.clearRect(0,0,h.width,h.height);e.drawImage(a,0,0);const b=e.getImageData(0,0,a.width,a.height);return c.globalAlpha=1,c.clearRect(0,0,a.width,a.height),b}sendUniformData(t,e){const s=this.chooseRightDelta();t.uniform2fv(e.uDelta,s)}isNeutralState(){return this.blur===0}chooseRightDelta(){let t=1;const e=[0,0];this.horizontal?this.aspectRatio>1&&(t=1/this.aspectRatio):this.aspectRatio<1&&(t=this.aspectRatio);const s=t*this.blur*.12;return this.horizontal?e[0]=s:e[1]=s,e}}E(Yu,"type","Blur"),E(Yu,"defaults",{blur:0}),E(Yu,"uniformLocations",["uDelta"]),G.setClass(Yu);class $u extends he{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($u,"type","Brightness"),E($u,"defaults",{brightness:0}),E($u,"uniformLocations",["uBrightness"]),G.setClass($u);const
|
|
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"]),G.setClass($u);const wv={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 he{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],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
|
|
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 Vr(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 G.setClass(s,o),s}E(wo,"type","ColorMatrix"),E(wo,"defaults",wv),E(wo,"uniformLocations",["uColorMatrix","uConstants"]),G.setClass(wo),Vr("Brownie",[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0]),Vr("Vintage",[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0]),Vr("Kodachrome",[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0]),Vr("Technicolor",[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0]),Vr("Polaroid",[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0]),Vr("Sepia",[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0]),Vr("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 xv extends he{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.subFilters=t.subFilters||[]}applyTo(t){Wu(t)&&(t.passes+=this.subFilters.length-1),this.subFilters.forEach(e=>{e.applyTo(t)})}toObject(){return{type:this.type,subFilters:this.subFilters.map(t=>t.toObject())}}isNeutralState(){return!this.subFilters.some(t=>!t.isNeutralState())}static fromObject(t,e){return Promise.all((t.subFilters||[]).map(s=>G.getClass(s.type).fromObject(s,e))).then(s=>new this({subFilters:s}))}}E(xv,"type","Composed"),G.setClass(xv);class qu extends he{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(qu,"type","Contrast"),E(qu,"defaults",{contrast:0}),E(qu,"uniformLocations",["uContrast"]),G.setClass(qu);const
|
|
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"]),G.setClass(qu);const Nx={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 Ku extends
|
|
376
|
+
`};class Ku extends he{getCacheKey(){return"".concat(this.type,"_").concat(Math.sqrt(this.matrix.length),"_").concat(this.opaque?1:0)}getFragmentSource(){return Nx[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,v,_,b,x,S,A,k,M,D,P;for(M=0;M<h;M++)for(k=0;k<a;k++){for(_=4*(M*a+k),f=0,g=0,p=0,v=0,P=0;P<n;P++)for(D=0;D<n;D++)x=M+P-r,b=k+D-r,x<0||x>=h||b<0||b>=a||(S=4*(x*a+b),A=i[P*n+D],f+=s[S]*A,g+=s[S+1]*A,p+=s[S+2]*A,d||(v+=s[S+3]*A));u[_]=f,u[_+1]=g,u[_+2]=p,u[_+3]=d?s[_+3]:v}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"]),G.setClass(Ku);const Sv="Gamma";class Ju extends he{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 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:
|
|
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:Sv,gamma:this.gamma.concat()}}}E(Ju,"type",Sv),E(Ju,"defaults",{gamma:[1,1,1]}),E(Ju,"uniformLocations",["uGamma"]),G.setClass(Ju);const Bx={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 Qu extends
|
|
419
|
+
`};class Qu extends he{applyTo2d(t){let{imageData:{data:e}}=t;for(let s,i=0;i<e.length;i+=4){const n=e[i],r=e[i+1],a=e[i+2];switch(this.mode){case"average":s=(n+r+a)/3;break;case"lightness":s=(Math.min(n,r,a)+Math.max(n,r,a))/2;break;case"luminosity":s=.21*n+.72*r+.07*a}e[i+2]=e[i+1]=e[i]=s}}getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return Bx[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"]),G.setClass(Qu);const Hx=T(T({},wv),{},{rotation:0});class Tg extends wo{calculateMatrix(){const t=this.rotation*Math.PI,e=$s(t),s=qs(t),i=1/3,n=Math.sqrt(i)*s,r=1-e;this.matrix=[e+r/3,i*r-n,i*r+n,0,0,i*r+n,e+i*r,i*r-n,0,0,i*r-n,i*r+n,e+i*r,0,0,0,0,0,1,0]}isNeutralState(){return this.rotation===0}applyTo(t){this.calculateMatrix(),super.applyTo(t)}toObject(){return{type:this.type,rotation:this.rotation}}}E(Tg,"type","HueRotation"),E(Tg,"defaults",Hx),G.setClass(Tg);class Zu extends he{applyTo2d(t){let{imageData:{data:e}}=t;for(let s=0;s<e.length;s+=4)e[s]=255-e[s],e[s+1]=255-e[s+1],e[s+2]=255-e[s+2],this.alpha&&(e[s+3]=255-e[s+3])}getFragmentSource(){return`
|
|
420
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(Zu,"type","Invert"),E(Zu,"defaults",{alpha:!1,invert:!0}),E(Zu,"uniformLocations",["uInvert","uAlpha"]),G.setClass(Zu);class td extends
|
|
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"]),G.setClass(Zu);class td extends he{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(td,"type","Noise"),E(td,"defaults",{noise:0}),E(td,"uniformLocations",["uNoise","uSeed"]),G.setClass(td);class ed extends
|
|
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"]),G.setClass(td);class ed extends he{applyTo2d(t){let{imageData:{data:e,width:s,height:i}}=t;for(let n=0;n<i;n+=this.blocksize)for(let r=0;r<s;r+=this.blocksize){const a=4*n*s+4*r,h=e[a],c=e[a+1],u=e[a+2],d=e[a+3];for(let f=n;f<Math.min(n+this.blocksize,i);f++)for(let g=r;g<Math.min(r+this.blocksize,s);g++){const p=4*f*s+4*g;e[p]=h,e[p+1]=c,e[p+2]=u,e[p+3]=d}}}isNeutralState(){return this.blocksize===1}getFragmentSource(){return`
|
|
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(ed,"type","Pixelate"),E(ed,"defaults",{blocksize:4}),E(ed,"uniformLocations",["uBlocksize"]),G.setClass(ed);class sd extends
|
|
470
|
+
`}sendUniformData(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}}E(ed,"type","Pixelate"),E(ed,"defaults",{blocksize:4}),E(ed,"uniformLocations",["uBlocksize"]),G.setClass(ed);class sd extends he{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 St(this.color).getSource(),n=[i[0]-s,i[1]-s,i[2]-s],r=[i[0]+s,i[1]+s,i[2]+s];for(let a=0;a<e.length;a+=4){const h=e[a],c=e[a+1],u=e[a+2];h>n[0]&&c>n[1]&&u>n[2]&&h<r[0]&&c<r[1]&&u<r[2]&&(e[a+3]=0)}}sendUniformData(t,e){const s=new St(this.color).getSource(),i=this.distance,n=[0+s[0]/255-i,0+s[1]/255-i,0+s[2]/255-i,1],r=[s[0]/255+i,s[1]/255+i,s[2]/255+i,1];t.uniform4fv(e.uLow,n),t.uniform4fv(e.uHigh,r)}}E(sd,"type","RemoveColor"),E(sd,"defaults",{color:"#FFFFFF",distance:.02,useAlpha:!1}),E(sd,"uniformLocations",["uLow","uHigh"]),G.setClass(sd);class id extends he{sendUniformData(t,e){t.uniform2fv(e.uDelta,this.horizontal?[1/this.width,0]:[0,1/this.height]),t.uniform1fv(e.uTaps,this.taps)}getFilterWindow(){const t=this.tempScale;return Math.ceil(this.lanczosLobes/t)}getCacheKey(){const t=this.getFilterWindow();return"".concat(this.type,"_").concat(t)}getFragmentSource(){const t=this.getFilterWindow();return this.generateShader(t)}getTaps(){const t=this.lanczosCreate(this.lanczosLobes),e=this.tempScale,s=this.getFilterWindow(),i=new Array(s);for(let n=1;n<=s;n++)i[n-1]=t(n*e);return i}generateShader(t){const e=new Array(t);for(let s=1;s<=t;s++)e[s-1]="".concat(s,".0 * uDelta");return`
|
|
483
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){Wu(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 v=e;let _=0;f.sliceByTwo||(f.sliceByTwo=Ds());const b=f.sliceByTwo;(b.width<1.5*e||b.height<s)&&(b.width=1.5*e,b.height=s);const x=b.getContext("2d");for(x.clearRect(0,0,1.5*e,s),x.putImageData(r,0,0),i=Math.floor(i),n=Math.floor(n);!h||!c;)e=u,s=d,i<Math.floor(u*a)?u=Math.floor(u*a):(u=i,h=!0),n<Math.floor(d*a)?d=Math.floor(d*a):(d=n,c=!0),x.drawImage(b,g,p,e,s,v,_,u,d),g=v,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),v=Math.ceil(d*this.lanczosLobes/2),_={},b={x:0,y:0},x={x:0,y:0};return function S(A){let k,M,D,P,R,F,I,H,W,B,ht;for(b.x=(A+.5)*u,x.x=Math.floor(b.x),k=0;k<n;k++){for(b.y=(k+.5)*d,x.y=Math.floor(b.y),R=0,F=0,I=0,H=0,W=0,M=x.x-p;M<=x.x+p;M++)if(!(M<0||M>=e)){B=Math.floor(1e3*Math.abs(M-b.x)),_[B]||(_[B]={});for(let j=x.y-v;j<=x.y+v;j++)j<0||j>=s||(ht=Math.floor(1e3*Math.abs(j-b.y)),_[B][ht]||(_[B][ht]=c(Math.sqrt(Math.pow(B*f,2)+Math.pow(ht*g,2))/1e3)),D=_[B][ht],D>0&&(P=4*(j*e+M),R+=D,F+=D*r[P],I+=D*r[P+1],H+=D*r[P+2],W+=D*r[P+3]))}P=4*(k*i+A),h[P]=F/R,h[P+1]=I/R,h[P+2]=H/R,h[P+3]=W/R}return++A<i?S(A):a}(0)}bilinearFiltering(t,e,s,i,n){let r,a,h,c,u,d,f,g,p,v,_,b,x,S=0;const A=this.rcpScaleX,k=this.rcpScaleY,M=4*(e-1),D=t.imageData.data,P=t.ctx.createImageData(i,n),R=P.data;for(f=0;f<n;f++)for(g=0;g<i;g++)for(u=Math.floor(A*g),d=Math.floor(k*f),p=A*g-u,v=k*f-d,x=4*(d*e+u),_=0;_<4;_++)r=D[x+_],a=D[x+4+_],h=D[x+M+_],c=D[x+M+4+_],b=r*(1-p)*(1-v)+a*p*(1-v)+h*v*(1-p)+c*p*v,R[S++]=b;return P}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 v=4*(p+g*i);let _=0,b=0,x=0,S=0,A=0,k=0,M=0;const D=(g+.5)*a;for(let P=Math.floor(g*a);P<(g+1)*a;P++){const R=Math.abs(D-(P+.5))/c,F=(p+.5)*r,I=R*R;for(let H=Math.floor(p*r);H<(p+1)*r;H++){let W=Math.abs(F-(H+.5))/h;const B=Math.sqrt(I+W*W);B>1&&B<-1||(_=2*B*B*B-3*B*B+1,_>0&&(W=4*(H+P*e),M+=_*u[W+3],x+=_,u[W+3]<255&&(_=_*u[W+3]/250),S+=_*u[W],A+=_*u[W+1],k+=_*u[W+2],b+=_))}}f[v]=S/b,f[v+1]=A/b,f[v+2]=k/b,f[v+3]=M/x}return d}}E(id,"type","Resize"),E(id,"defaults",{resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3}),E(id,"uniformLocations",["uDelta","uTaps"]),G.setClass(id);class nd extends he{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],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"]),G.setClass(nd);class rd extends
|
|
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"]),G.setClass(nd);class rd extends he{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],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"]),G.setClass(rd);var nl={};nl.d=(o,t)=>{for(var e in t)nl.o(t,e)&&!nl.o(o,e)&&Object.defineProperty(o,e,{enumerable:!0,get:t[e]})},nl.o=(o,t)=>Object.prototype.hasOwnProperty.call(o,t);var Z=globalThis.pdfjsLib={};nl.d(Z,{AbortException:()=>qn,AnnotationEditorLayer:()=>hp,AnnotationEditorParamsType:()=>dt,AnnotationEditorType:()=>nt,AnnotationEditorUIManager:()=>Xr,AnnotationLayer:()=>OC,AnnotationMode:()=>Yn,ColorPicker:()=>Cd,DOMSVGFactory:()=>Qg,DrawLayer:()=>lp,FeatureTest:()=>ze,GlobalWorkerOptions:()=>rn,ImageKind:()=>ad,InvalidPDFException:()=>Pg,MissingPDFException:()=>al,OPS:()=>si,OutputScale:()=>Ng,PDFDataRangeTransport:()=>ib,PDFDateString:()=>Ig,PDFWorker:()=>Co,PasswordResponses:()=>Hx,PermissionFlag:()=>Bx,PixelsPerInch:()=>Kn,RenderingCancelledException:()=>Lg,TextLayer:()=>dl,TouchManager:()=>md,UnexpectedResponseException:()=>cd,Util:()=>q,VerbosityLevel:()=>od,XfaLayer:()=>ob,build:()=>uC,createValidAbsoluteUrl:()=>zx,fetchData:()=>dd,getDocument:()=>sC,getFilenameFromUrl:()=>Zx,getPdfFilenameFromUrl:()=>tS,getXfaPageViewport:()=>eS,isDataScheme:()=>fd,isPdfFile:()=>Fg,noContextMenu:()=>ii,normalizeUnicode:()=>Kx,setLayerDimensions:()=>zr,shadow:()=>ht,stopEvent:()=>gs,version:()=>cC});const Pe=typeof process=="object"&&process+""=="[object process]"&&!process.versions.nw&&!(process.versions.electron&&process.type&&process.type!=="browser"),Sv=[1,0,0,1,0,0],Tg=[.001,0,0,.001,0,0],jx=1e7,Eg=1.35,fs={ANY:1,DISPLAY:2,PRINT:4,ANNOTATIONS_FORMS:16,ANNOTATIONS_STORAGE:32,ANNOTATIONS_DISABLE:64,IS_EDITING:128,OPLIST:256},Yn={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},Nx="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},Bx={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_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,WIDGET:20},rl={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},Hx={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};let hd=od.WARNINGS;function Gx(o){Number.isInteger(o)&&(hd=o)}function Vx(){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 Wx(o){switch(o==null?void 0:o.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}function zx(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=qx(o)}catch{}}const s=t?new URL(o,t):new URL(o);if(Wx(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 Cv extends $n{constructor(t,e){super(t,"PasswordException"),this.code=e}}class kg extends $n{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}}class Pg extends $n{constructor(t){super(t,"InvalidPDFException")}}class al extends $n{constructor(t){super(t,"MissingPDFException")}}class cd extends $n{constructor(t,e){super(t,"UnexpectedResponseException"),this.status=e}}class Xx extends $n{constructor(t){super(t,"FormatError")}}class qn extends $n{constructor(t){super(t,"AbortException")}}function Av(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 Ux(o){return String.fromCharCode(o>>24&255,o>>16&255,o>>8&255,o&255)}function Mg(o){const t=Object.create(null);for(const[e,s]of o)t[e]=s;return t}function Yx(){const o=new Uint8Array(4);return o[0]=1,new Uint32Array(o.buffer,0,1)[0]===1}function $x(){try{return new Function(""),!0}catch{return!1}}class ze{static get isLittleEndian(){return ht(this,"isLittleEndian",Yx())}static get isEvalSupported(){return ht(this,"isEvalSupported",$x())}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 Og=Array.from(Array(256).keys(),o=>o.toString(16).padStart(2,"0"));class q{static makeHexColor(t,e,s){return`#${Og[t]}${Og[e]}${Og[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,xp).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,xp).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,v=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],v),u[2]=Math.max(u[2],p),u[3]=Math.max(u[3],v)},xp=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),v=2*c;w(this,an,qd).call(this,t,e,s,i,n,r,a,h,(-u+p)/v,f),w(this,an,qd).call(this,t,e,s,i,n,r,a,h,(-u-p)/v,f)},y(q,an);function qx(o){return decodeURIComponent(escape(o))}let Dg=null,Tv=null;function Kx(o){return Dg||(Dg=/([\u00a0\u00b5\u037e\u0eb3\u2000-\u200a\u202f\u2126\ufb00-\ufb04\ufb06\ufb20-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufba1\ufba4-\ufba9\ufbae-\ufbb1\ufbd3-\ufbdc\ufbde-\ufbe7\ufbea-\ufbf8\ufbfc-\ufbfd\ufc00-\ufc5d\ufc64-\ufcf1\ufcf5-\ufd3d\ufd88\ufdf4\ufdfa-\ufdfb\ufe71\ufe77\ufe79\ufe7b\ufe7d]+)|(\ufb05+)/gu,Tv=new Map([["ſt","ſt"]])),o.replaceAll(Dg,(t,e,s)=>e?e.normalize("NFKC"):Tv.get(s))}function Jx(){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();const o=new Uint8Array(32);return crypto.getRandomValues(o),Av(o)}const Rg="pdfjs_internal_id_";function Qx(o){return Uint8Array.prototype.toBase64?o.toBase64():btoa(Av(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(hl(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 ol{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,v,_,b;u===0?(p=Math.abs(c-t[1])*s+n,v=Math.abs(h-t[0])*s+r,_=(t[3]-t[1])*s,b=(t[2]-t[0])*s):(p=Math.abs(h-t[0])*s+n,v=Math.abs(c-t[1])*s+r,_=(t[2]-t[0])*s,b=(t[3]-t[1])*s),this.transform=[u*s,d*s,f*s,g*s,p-u*s*h-f*s*c,v-d*s*h-g*s*c],this.width=_,this.height=b}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 ol({viewBox:this.viewBox.slice(),userUnit:this.userUnit,scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}convertToViewportPoint(t,e){return q.applyTransform([t,e],this.transform)}convertToViewportRectangle(t){const e=q.applyTransform([t[0],t[1]],this.transform),s=q.applyTransform([t[2],t[3]],this.transform);return[e[0],e[1],s[0],s[1]]}convertToPdfPoint(t,e){return q.applyInverseTransform([t,e],this.transform)}}class Lg extends $n{constructor(t,e=0){super(t,"RenderingCancelledException"),this.extraDelay=e}}function 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 Fg(o){return typeof o=="string"&&/\.pdf$/i.test(o)}function Zx(o){return[o]=o.split(/[#?]/,1),o.substring(o.lastIndexOf("/")+1)}function tS(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 Ev{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 hl(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 Ig{static toDateObject(t){if(!t||typeof t!="string")return null;l(this,bl)||m(this,bl,new RegExp("^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+|-])?(\\d{2})?'?(\\d{2})?'?"));const e=l(this,bl).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))}}bl=new WeakMap,y(Ig,bl);function eS(o,{scale:t=1,rotation:e=0}){const{width:s,height:i}=o.attributes.style,n=[0,0,parseInt(s),parseInt(i)];return new ol({viewBox:n,userUnit:1,scale:t,rotation:e})}function jg(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 sS(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,jg(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 zr(o,t,e=!1,s=!0){if(t instanceof ol){const{pageWidth:i,pageHeight:n}=t.rawDims,{style:r}=o,a=ze.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 Ng{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){y(this,Xe);y(this,Qn,null);y(this,qr,null);y(this,ni);y(this,Kr,null);y(this,yl,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,Ib),{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,Bb).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,yl))==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,Sp)),m(this,yl,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,Sp))}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,yl=new WeakMap,_l=new WeakMap,Ed=new WeakSet,Ib=function(t){t.stopPropagation()},Xe=new WeakSet,jb=function(t){l(this,ni)._focusEventsAllowed=!1,gs(t)},Nb=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,jb).bind(this),{capture:!0,signal:e}),t.addEventListener("focusout",w(this,Xe,Nb).bind(this),{capture:!0,signal:e}),t.addEventListener("contextmenu",ii,{signal:e})},Bb=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)},Sp=function(){const t=document.createElement("div");return t.className="divider",t},y(on,Ed),y(on,_l,null);let Bg=on;class iS{constructor(t){y(this,Zn);y(this,wl,null);y(this,Jr,null);y(this,Qr);m(this,Qr,t)}show(t,e,s){const[i,n]=w(this,Zn,Gb).call(this,e,s),{style:r}=l(this,Jr)||m(this,Jr,w(this,Zn,Hb).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,Hb=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,Vb).call(this),t},Gb=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]},Vb=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 nS{constructor(){y(this,kd,0)}get id(){return`${Nx}${Ze(this,kd)._++}`}}kd=new WeakMap;const cp=class cp{constructor(){y(this,To);y(this,Ao,Jx());y(this,xl,0);y(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=cp._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 Hg=cp;class rS{constructor(t=128){y(this,Kt,[]);y(this,tr,!1);y(this,Sl);y(this,Gt,-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,Gt)===-1){l(this,Kt).length>0&&(l(this,Kt).length=0),m(this,Gt,0),l(this,Kt).push(h);return}if(r&&l(this,Kt)[l(this,Gt)].type===n){a&&(h.undo=l(this,Kt)[l(this,Gt)].undo),l(this,Kt)[l(this,Gt)]=h;return}const c=l(this,Gt)+1;c===l(this,Sl)?l(this,Kt).splice(0,1):(m(this,Gt,c),c<l(this,Kt).length&&l(this,Kt).splice(c)),l(this,Kt).push(h)}undo(){if(l(this,Gt)===-1)return;m(this,tr,!0);const{undo:t,post:e}=l(this,Kt)[l(this,Gt)];t(),e==null||e(),m(this,tr,!1),m(this,Gt,l(this,Gt)-1)}redo(){if(l(this,Gt)<l(this,Kt).length-1){m(this,Gt,l(this,Gt)+1),m(this,tr,!0);const{cmd:t,post:e}=l(this,Kt)[l(this,Gt)];t(),e==null||e(),m(this,tr,!1)}}hasSomethingToUndo(){return l(this,Gt)!==-1}hasSomethingToRedo(){return l(this,Gt)<l(this,Kt).length-1}cleanType(t){if(l(this,Gt)!==-1){for(let e=l(this,Gt);e>=0;e--)if(l(this,Kt)[e].type!==t){l(this,Kt).splice(e+1,l(this,Gt)-e),m(this,Gt,e);return}l(this,Kt).length=0,m(this,Gt,-1)}}destroy(){m(this,Kt,null)}}Kt=new WeakMap,tr=new WeakMap,Sl=new WeakMap,Gt=new WeakMap;class ll{constructor(t){y(this,Pd);this.buffer=[],this.callbacks=new Map,this.allKeys=new Set;const{isMac:e}=ze.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,Wb).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,Wb=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 sS(t),ht(this,"_colors",t)}convert(t){const e=jg(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 Gg=Md;const Ro=class Ro{constructor(t,e,s,i,n,r,a,h,c,u,d,f,g){y(this,B);y(this,Eo,new AbortController);y(this,ps,null);y(this,he,new Map);y(this,be,new Map);y(this,ko,null);y(this,hn,null);y(this,Po,null);y(this,Fs,new rS);y(this,er,null);y(this,Zr,null);y(this,Mo,0);y(this,ta,new Set);y(this,Ei,null);y(this,ri,null);y(this,ea,new Set);J(this,"_editorUndoBar",null);y(this,Cl,!1);y(this,Al,!1);y(this,Oo,!1);y(this,Tl,null);y(this,ki,null);y(this,sr,null);y(this,Do,null);y(this,ir,!1);y(this,Pi,null);y(this,Od,new nS);y(this,nr,!1);y(this,El,!1);y(this,rr,null);y(this,sa,null);y(this,kl,null);y(this,Pl,null);y(this,de,nt.NONE);y(this,xt,new Set);y(this,ln,null);y(this,ia,null);y(this,Ml,null);y(this,Ol,{isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1});y(this,ar,[0,0]);y(this,Mi,null);y(this,cn,null);y(this,Dl,null);y(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",v=>this.updateParams(v.type,v.value),{signal:p}),w(this,B,Ub).call(this),w(this,B,Kb).call(this),w(this,B,Ap).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 ll([[["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,be).values())r.destroy();l(this,be).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,be).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,Cp).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,Ap).call(this),w(this,B,Tp).call(this)}removeEditListeners(){w(this,B,qb).call(this),w(this,B,Ep).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,kp).call(this,h);w(this,B,Pp).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,Yb).call(this),w(this,B,Tp).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,$b).call(this),w(this,B,Ep).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,be).get(l(this,Mo))}getLayer(t){return l(this,be).get(t)}get currentPageIndex(){return l(this,Mo)}addLayer(t){l(this,be).set(t.pageIndex,t),l(this,nr)?t.enable():t.disable()}removeLayer(t){l(this,be).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,Qb).call(this),(i=this._editorUndoBar)==null||i.hide(),l(this,Is).resolve();return}this.setEditingState(!0),await w(this,B,Jb).call(this),this.unselectAll();for(const n of l(this,be).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,be).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,Zb)===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,kp).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,Pp).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,be).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 Hg)}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:v}of d.getClientRects())p===0||v===0||h.push(a(f,g,p,v))}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,be=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},Cp=function(t){const{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(const s of l(this,be).values())if(s.hasTextLayer(t))return s;return null},zb=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 iS(this)),l(this,Pi).show(s,i,this.direction==="ltr"))},Xb=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,Cp).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,zb).call(this)},Ub=function(){document.addEventListener("selectionchange",w(this,B,Xb).bind(this),{signal:this._signal})},Yb=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})},$b=function(){var t;(t=l(this,sr))==null||t.abort(),m(this,sr,null)},Ap=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})},qb=function(){var t;(t=l(this,rr))==null||t.abort(),m(this,rr,null)},Tp=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})},Ep=function(){var t;(t=l(this,er))==null||t.abort(),m(this,er,null)},Kb=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})},Jb=async function(){if(!l(this,nr)){m(this,nr,!0);const t=[];for(const e of l(this,be).values())t.push(e.enable());await Promise.all(t);for(const e of l(this,he).values())e.enable()}},Qb=function(){if(this.unselectAll(),l(this,nr)){m(this,nr,!1);for(const t of l(this,be).values())t.disable();for(const t of l(this,he).values())t.disable()}},kp=function(t){const e=l(this,be).get(t.pageIndex);e?e.addOrRebuild(t):(this.addEditor(t),this.addToAnnotationStorage(t))},Zb=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},Pp=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){y(this,oi);y(this,fe,null);y(this,Oi,!1);y(this,ai,null);y(this,Lo,null);y(this,Di,null);y(this,ms,null);y(this,Fo,!1);y(this,Ri,null);y(this,as,null);y(this,un,null);y(this,na,null);y(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)},y(Ue,or,null),J(Ue,"_l10n",null);let pd=Ue;const up=class up{constructor({container:t,isPinchingDisabled:e=null,isPinchingStopped:s=null,onPinchStart:i=null,onPinching:n=null,onPinchEnd:r=null,signal:a}){y(this,fn);y(this,Rl);y(this,ra,!1);y(this,Ll,null);y(this,Fl);y(this,Il);y(this,jl);y(this,Nl);y(this,Io);y(this,dn,null);y(this,aa);y(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,ty).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,ty=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,ey).bind(this),c),h.addEventListener("touchend",w(this,fn,Mp).bind(this),c),h.addEventListener("touchcancel",w(this,fn,Mp).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})},ey=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,v=r-i,_=a-n,b=Math.hypot(v,_)||1,x=Math.hypot(g,p)||1;if(!l(this,ra)&&Math.abs(x-b)<=up.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,b)},Mp=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=up;const ot=class ot{constructor(t){y(this,K);y(this,oa,null);y(this,hi,null);y(this,Rt,null);y(this,jo,!1);y(this,lr,null);y(this,Bl,"");y(this,ha,!1);y(this,ye,null);y(this,la,null);y(this,gn,null);y(this,cr,null);y(this,Hl,"");y(this,ca,!1);y(this,vs,null);y(this,Gl,!1);y(this,ua,!1);y(this,pn,!1);y(this,Fi,null);y(this,No,0);y(this,Bo,0);y(this,js,null);y(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);y(this,Vl,!1);y(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 ll([[["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 aS({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,Vl)}set _isDraggable(t){var e;m(this,Vl,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,Op).call(this,this.parentDimensions,t,e)}translateInPage(t,e){l(this,vs)||m(this,vs,[this.x,this.y,this.width,this.height]),w(this,K,Op).call(this,this.pageDimensions,t,e),this.div.scrollIntoView({block:"nearest"})}drag(t,e){l(this,vs)||m(this,vs,[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,vs)&&(l(this,vs)[0]!==this.x||l(this,vs)[1]!==this.y)}get _hasBeenResized(){return!!l(this,vs)&&(l(this,vs)[2]!==this.width||l(this,vs)[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,Wl,Dp).call(s,t,e,this.parentRotation)}pageTranslationToScreen(t,e){var s;return w(s=ot,Wl,Dp).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 Bg(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,Ip).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,ny).bind(this),onPinching:w(this,K,ry).bind(this),onPinchEnd:w(this,K,ay).bind(this),signal:this._uiManager._signal}))),(n=this._uiManager._editorUndoBar)==null||n.hide(),this.div}pointerdown(t){const{isMac:e}=ze.platform;if(t.button!==0||t.ctrlKey&&e){t.preventDefault();return}if(m(this,ca,!0),this._isDraggable){w(this,K,oy).call(this,t);return}w(this,K,Fp).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,Ip).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,sy).call(this),l(this,ye).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,ye).children;if(!l(this,hi)){m(this,hi,Array.from(e));const r=w(this,K,hy).bind(this),a=w(this,K,ly).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,cy).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,ye).append(l(this,ye).firstChild);else if(n>i)for(let a=0;a<n-i;a++)l(this,ye).firstChild.before(l(this,ye).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,jp).call(this,0),m(this,pn,!0),l(this,ye).firstChild.focus({focusVisible:!0}),t.preventDefault(),t.stopImmediatePropagation()}_resizeWithKeyboard(t,e){l(this,pn)&&w(this,K,Lp).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,ye))==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,Gl)}set isEditing(t){m(this,Gl,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,ye=new WeakMap,la=new WeakMap,gn=new WeakMap,cr=new WeakMap,Hl=new WeakMap,ca=new WeakMap,vs=new WeakMap,Gl=new WeakMap,ua=new WeakMap,pn=new WeakMap,Fi=new WeakMap,No=new WeakMap,Bo=new WeakMap,js=new WeakMap,da=new WeakMap,Vl=new WeakMap,Dd=new WeakMap,K=new WeakSet,Op=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()},Wl=new WeakSet,Dp=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]}},sy=function(){if(l(this,ye))return;m(this,ye,document.createElement("div")),l(this,ye).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,ye).append(i),i.classList.add("resizer",s),i.setAttribute("data-resizer-name",s),i.addEventListener("pointerdown",w(this,K,iy).bind(this,s),{signal:e}),i.addEventListener("contextmenu",ii,{signal:e}),i.tabIndex=-1}this.div.prepend(l(this,ye))},iy=function(t,e){var u;e.preventDefault();const{isMac:s}=ze.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,Lp).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})},Rp=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,Rp).bind(this,n,r,a,h),undo:w(this,K,Rp).bind(this,t,e,s,i),mustExec:!0})},Lp=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,W)=>[d[0]*j+d[2]*W,d[1]*j+d[3]*W],g=w(this,K,ef).call(this,360-this.rotation),p=(j,W)=>[g[0]*j+g[2]*W,g[1]*j+g[3]*W];let v,_,b=!1,x=!1;switch(t){case"topLeft":b=!0,v=(j,W)=>[0,0],_=(j,W)=>[j,W];break;case"topMiddle":v=(j,W)=>[j/2,0],_=(j,W)=>[j/2,W];break;case"topRight":b=!0,v=(j,W)=>[j,0],_=(j,W)=>[0,W];break;case"middleRight":x=!0,v=(j,W)=>[j,W/2],_=(j,W)=>[0,W/2];break;case"bottomRight":b=!0,v=(j,W)=>[j,W],_=(j,W)=>[0,0];break;case"bottomMiddle":v=(j,W)=>[j/2,W],_=(j,W)=>[j/2,0];break;case"bottomLeft":b=!0,v=(j,W)=>[0,W],_=(j,W)=>[j,0];break;case"middleLeft":x=!0,v=(j,W)=>[0,W/2],_=(j,W)=>[j,W/2];break}const C=v(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:W}=e,[it,kt]=l(this,la);[F,I]=this.screenToPageTranslation(j-it,W-kt),l(this,la)[0]=j,l(this,la)[1]=W}if([F,I]=p(F/s,I/i),b){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,vs)||m(this,vs,[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()},ny=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)},ry=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,v=ot.MIN_SIZE/c;n=Math.max(Math.min(n,1/f,1/g),p/f,v/g);const _=ot._round(f*n),b=ot._round(g*n);if(_===f&&b===g)return;l(this,vs)||m(this,vs,[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,b/2);this.x=C-P[0],this.y=A-P[1],this.width=_,this.height=b,this.setDims(h*_,c*b),this.fixAndSetPosition(),this._onResizing()},ay=function(){var t;(t=l(this,Rt))==null||t.toggle(!0),this.parent.togglePointerEvents(!0),w(this,K,sf).call(this)},Fp=function(t){const{isMac:e}=ze.platform;t.ctrlKey&&!e||t.shiftKey||t.metaKey&&e?this.parent.toggleSelected(this):this.parent.setSelected(this)},oy=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,Fp).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})},Ip=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})},hy=function(t){ot._resizerKeyboardManager.exec(this,t)},ly=function(t){var e;l(this,pn)&&((e=t.relatedTarget)==null?void 0:e.parentNode)!==l(this,ye)&&w(this,K,Yc).call(this)},cy=function(t){m(this,Hl,l(this,pn)?t:"")},jp=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,jp).call(this,-1),w(this,K,sf).call(this)},y(ot,Wl),J(ot,"_l10n",null),J(ot,"_l10nResizer",null),J(ot,"_borderLineWidth",-1),J(ot,"_colorManager",new Gg),J(ot,"_zIndex",1),J(ot,"_telemetryTimeout",1e3);let Ht=ot;class aS extends Ht{constructor(t){super(t),this.annotationElementId=t.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}}const kv=3285377520,Rs=4294901760,Ti=65535;class Pv{constructor(t){this.h1=t?t&4294967295:kv,this.h2=t?t&4294967295:kv}update(t){let e,s;if(typeof t=="string"){e=new Uint8Array(t.length*2),s=0;for(let v=0,_=t.length;v<_;v++){const b=t.charCodeAt(v);b<=255?e[s++]=b:(e[s++]=b>>>8,e[s++]=b&255)}}else if(ArrayBuffer.isView(t))e=t.slice(),s=e.byteLength;else throw new Error("Invalid data format, must be a string or TypedArray.");const i=s>>2,n=s-i*4,r=new Uint32Array(e.buffer,0,i);let a=0,h=0,c=this.h1,u=this.h2;const d=3432918353,f=461845907,g=d&Ti,p=f&Ti;for(let v=0;v<i;v++)v&1?(a=r[v],a=a*d&Rs|a*g&Ti,a=a<<15|a>>>17,a=a*f&Rs|a*p&Ti,c^=a,c=c<<13|c>>>19,c=c*5+3864292196):(h=r[v],h=h*d&Rs|h*g&Ti,h=h<<15|h>>>17,h=h*f&Rs|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&Rs|a*g&Ti,a=a<<15|a>>>17,a=a*f&Rs|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&Rs|t*36045&Ti,e=e*4283543511&Rs|((e<<16|t>>>16)*2950163797&Rs)>>>16,t^=e>>>1,t=t*444984403&Rs|t*60499&Ti,e=e*3301882366&Rs|((e<<16|t>>>16)*3120437893&Rs)>>>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(){y(this,Rd);y(this,fa,!1);y(this,ga,null);y(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,uy).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?Mg(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 Mv(this)}get serializable(){if(l(this,ge).size===0)return Vg;const t=new Map,e=new Pv,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,uy=function(){l(this,fa)||(m(this,fa,!0),typeof this.onSetModified=="function"&&this.onSetModified())};class Mv extends Wg{constructor(e){super();y(this,zl);const{map:s,hash:i,transfer:n}=e.serializable,r=structuredClone(s,n?{transfer:n}:null);m(this,zl,{map:r,hash:i,transfer:n})}get print(){Et("Should not call PrintAnnotationStorage.print")}get serializable(){return l(this,zl)}get modifiedIds(){return ht(this,"modifiedIds",{ids:new Set,hash:""})}}zl=new WeakMap;class oS{constructor({ownerDocument:t=globalThis.document,styleElement:e=null}){y(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,v=1482184792;let _=s(f,p);for(n=0,r=d.length-3;n<r;n+=4)_=_-v+s(d,n)|0;n<d.length&&(_=_-v+s(d+"XXX",n)|0),f=i(f,p,4,Ux(_));const b=`url(data:font/opentype;base64,${btoa(f)});`,x=`@font-face {font-family:"${d}";src:${b}}`;this.insertRule(x);const C=this._document.createElement("div");C.style.visibility="hidden",C.style.width=C.style.height="10px",C.style.position="absolute",C.style.top=C.style.left="0px";for(const 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 hS{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,${Qx(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 vd={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 Ov(){}function is(o){if(o instanceof qn||o instanceof Pg||o instanceof al||o instanceof Cv||o instanceof cd||o instanceof kg)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 Pg(o.message);case"MissingPDFException":return new al(o.message);case"PasswordException":return new Cv(o.message,o.code);case"UnexpectedResponseException":return new cd(o.message,o.status);case"UnknownErrorException":return new kg(o.message,o.details)}return new kg(o.message,o.toString())}class cl{constructor(t,e,s){y(this,Ns);y(this,Go,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,dy).bind(this),{signal:l(this,Go).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,Go))==null||t.abort(),m(this,Go,null)}}Go=new WeakMap,Ns=new WeakSet,dy=function({data:t}){if(t.targetName!==this.sourceName)return;if(t.stream){w(this,Ns,gy).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===vd.DATA)i.resolve(t.data);else if(t.callback===vd.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:vd.DATA,callbackId:t.callbackId,data:r})},function(r){n.postMessage({sourceName:s,targetName:i,callback:vd.ERROR,callbackId:t.callbackId,reason:is(r)})});return}if(t.streamId){w(this,Ns,fy).call(this,t);return}e(t.data)},fy=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)})})},gy=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||Ov).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||Ov,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 Dv{constructor({enableHWA:t=!1}){y(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 lS 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 Rv{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 Lv extends Rv{async _fetch(t){const e=await dd(t,this.isCompressed?"arraybuffer":"text");return e instanceof ArrayBuffer?new Uint8Array(e):ud(e)}}class Fv{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 cS extends Fv{constructor({docId:e,ownerDocument:s=globalThis.document}){super();y(this,V);y(this,pa);y(this,Vo);y(this,mn);y(this,vn);y(this,Re);y(this,ma);y(this,va,0);m(this,vn,e),m(this,Re,s)}addFilter(e){if(!e)return"none";let s=l(this,V,je).get(e);if(s)return s;const[i,n,r]=w(this,V,rf).call(this,e),a=e.length===1?i:`${i}${n}${r}`;if(s=l(this,V,je).get(a),s)return l(this,V,je).set(e,s),s;const h=`g_${l(this,vn)}_transfer_map_${Ze(this,va)._++}`,c=w(this,V,Fh).call(this,h);l(this,V,je).set(e,c),l(this,V,je).set(a,c);const u=w(this,V,Ih).call(this,h);return w(this,V,Kc).call(this,i,n,r,u),c}addHCMFilter(e,s){var p;const i=`${e}-${s}`,n="base";let r=l(this,V,$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,V,$c).set(n,r)),!e||!s))return r.url;const a=w(this,V,Jc).call(this,e);e=q.makeHexColor(...a);const h=w(this,V,Jc).call(this,s);if(s=q.makeHexColor(...h),l(this,V,Lh).style.color="",e==="#000000"&&s==="#ffffff"||e===s)return r.url;const c=new Array(256);for(let v=0;v<=255;v++){const _=v/255;c[v]=_<=.03928?_/12.92:((_+.055)/1.055)**2.4}const u=c.join(","),d=`g_${l(this,vn)}_hcm_filter`,f=r.filter=w(this,V,Ih).call(this,d);w(this,V,Kc).call(this,u,u,u,f),w(this,V,Np).call(this,f);const g=(v,_)=>{const b=a[v]/255,x=h[v]/255,C=new Array(_+1);for(let A=0;A<=_;A++)C[A]=b+A/_*(x-b);return C.join(",")};return w(this,V,Kc).call(this,g(0,5),g(1,5),g(2,5),f),r.url=w(this,V,Fh).call(this,d),r.url}addAlphaFilter(e){let s=l(this,V,je).get(e);if(s)return s;const[i]=w(this,V,rf).call(this,[e]),n=`alpha_${i}`;if(s=l(this,V,je).get(n),s)return l(this,V,je).set(e,s),s;const r=`g_${l(this,vn)}_alpha_map_${Ze(this,va)._++}`,a=w(this,V,Fh).call(this,r);l(this,V,je).set(e,a),l(this,V,je).set(n,a);const h=w(this,V,Ih).call(this,r);return w(this,V,Bp).call(this,i,h),a}addLuminosityFilter(e){let s=l(this,V,je).get(e||"luminosity");if(s)return s;let i,n;if(e?([i]=w(this,V,rf).call(this,[e]),n=`luminosity_${i}`):n="luminosity",s=l(this,V,je).get(n),s)return l(this,V,je).set(e,s),s;const r=`g_${l(this,vn)}_luminosity_map_${Ze(this,va)._++}`,a=w(this,V,Fh).call(this,r);l(this,V,je).set(e,a),l(this,V,je).set(n,a);const h=w(this,V,Ih).call(this,r);return w(this,V,py).call(this,h),e&&w(this,V,Bp).call(this,i,h),a}addHighlightHCMFilter(e,s,i,n,r){var x;const a=`${s}-${i}-${n}-${r}`;let h=l(this,V,$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,V,$c).set(e,h)),!s||!i))return h.url;const[c,u]=[s,i].map(w(this,V,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,V,Jc).bind(this));f<d&&([d,f,g,p]=[f,d,p,g]),l(this,V,Lh).style.color="";const v=(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,vn)}_hcm_${e}_filter`,b=h.filter=w(this,V,Ih).call(this,_);return w(this,V,Np).call(this,b),w(this,V,Kc).call(this,v(g[0],p[0],5),v(g[1],p[1],5),v(g[2],p[2],5),b),h.url=w(this,V,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,Vo))==null||n.clear(),m(this,Vo,null),(r=l(this,ma))==null||r.clear(),m(this,ma,null),m(this,va,0))}}pa=new WeakMap,Vo=new WeakMap,mn=new WeakMap,vn=new WeakMap,Re=new WeakMap,ma=new WeakMap,va=new WeakMap,V=new WeakSet,je=function(){return l(this,Vo)||m(this,Vo,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})`},py=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)},Np=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,V,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,V,qc).call(this,r,"feFuncR",e),w(this,V,qc).call(this,r,"feFuncG",s),w(this,V,qc).call(this,r,"feFuncB",i)},Bp=function(e,s){const i=l(this,Re).createElementNS(nn,"feComponentTransfer");s.append(i),w(this,V,qc).call(this,i,"feFuncA",e)},Jc=function(e){return l(this,V,Lh).style.color=e,jg(getComputedStyle(l(this,V,Lh)).getPropertyValue("color"))};class Iv{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 jv extends Iv{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 Nv(o){const e=await process.getBuiltinModule("fs").promises.readFile(o);return new Uint8Array(e)}class uS extends Fv{}class dS 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:Mt&&Mt.tagName.toUpperCase()==="SCRIPT"&&Mt.src||new URL("pdf-canvas.umd.js",document.baseURI).href)("@napi-rs/canvas").createCanvas(t,e)}}class fS extends Rv{async _fetch(t){return Nv(t)}}class gS extends Iv{async _fetch(t){return Nv(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 Xg{getPattern(){Et("Abstract method `getPattern` called.")}}class pS extends Xg{constructor(t){super(),this._type=t[1],this._bbox=t[2],this._colorStops=t[3],this._p0=t[4],this._p1=t[5],this._r0=t[6],this._r1=t[7],this.matrix=null}_createGradient(t){let e;this._type==="axial"?e=t.createLinearGradient(this._p0[0],this._p0[1],this._p1[0],this._p1[1]):this._type==="radial"&&(e=t.createRadialGradient(this._p0[0],this._p0[1],this._r0,this._p1[0],this._p1[1],this._r1));for(const s of this._colorStops)e.addColorStop(s[0],s[1]);return e}getPattern(t,e,s,i){let n;if(i===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 Ug(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,v=(h[s]+t.offsetX)*t.scaleX,_=(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[a],F=c[a+1],I=c[a+2],Y=Math.round(p),N=Math.round(x);let H,at,j,W,it,kt,Ut,ne;for(let Wt=Y;Wt<=N;Wt++){if(Wt<_){const ft=Wt<p?0:(p-Wt)/(p-_);H=g-(g-v)*ft,at=C-(C-D)*ft,j=A-(A-k)*ft,W=P-(P-M)*ft}else{let ft;Wt>x?ft=1:_===x?ft=0:ft=(_-Wt)/(_-x),H=v-(v-b)*ft,at=D-(D-R)*ft,j=k-(k-F)*ft,W=M-(M-I)*ft}let Tt;Wt<p?Tt=0:Wt>x?Tt=1:Tt=(p-Wt)/(p-x),it=g-(g-b)*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*Wt+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++]=W-(W-ne)*Tt|0,u[Dt++]=255}}function mS(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++)Ug(o,e,s[u],s[u+1],s[u+a],i[u],i[u+1],i[u+a]),Ug(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)Ug(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 vS extends Xg{constructor(t){super(),this._coords=t[2],this._colors=t[3],this._figures=t[4],this._bounds=t[5],this._bbox=t[7],this._background=t[8],this.matrix=null}_createMeshCanvas(t,e,s){const 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,v={coords:this._coords,colors:this._colors,offsetX:-a,offsetY:-h,scaleX:1/g,scaleY:1/p},_=d+2*2,b=f+2*2,x=s.getCanvas("mesh",_,b),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)mS(A,D,v);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 bS extends Xg{getPattern(){return"hotpink"}}function yS(o){switch(o[0]){case"RadialAxial":return new pS(o);case"Mesh":return new vS(o);case"Dummy":return new bS}throw new Error(`Unknown IR type: ${o[0]}`)}const Bv={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,v=g-d,_=q.singularValueDecompose2dScale(this.matrix),b=q.singularValueDecompose2dScale(this.baseTransform),x=_[0]*b[0],C=_[1]*b[1];let A=p,P=v,D=!1,k=!1;const M=Math.ceil(h*x),R=Math.ceil(c*C),F=Math.ceil(p*x),I=Math.ceil(v*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 W=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,Wt=t.cachedCanvases.getCanvas("pattern-workaround",Ut,ne),Tt=Wt.context,Ce=D?Math.floor(p/h):0,Xs=k?Math.floor(v/c):0;for(let Dt=0;Dt<=Ce;Dt++)for(let ft=0;ft<=Xs;ft++)Tt.drawImage(W,Ut*Dt,ne*ft,Ut,ne,0,0,Ut,ne);return{canvas:Wt.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 Bv.COLORED:const r=this.ctx;i.fillStyle=r.fillStyle,i.strokeStyle=r.strokeStyle,n.fillColor=r.fillStyle,n.strokeColor=r.strokeStyle;break;case Bv.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 Xx(`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 Yg=Ld;function _S({src:o,srcPos:t=0,dest:e,width:s,height:i,nonBlackColor:n=4294967295,inverseDecode:r=!1}){const a=ze.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 b=t<f?o[t]:255;e[g++]=b&128?c:h,e[g++]=b&64?c:h,e[g++]=b&32?c:h,e[g++]=b&16?c:h,e[g++]=b&8?c:h,e[g++]=b&4?c:h,e[g++]=b&2?c:h,e[g++]=b&1?c:h}if(d===0)continue;const v=t<f?o[t++]:255;for(let _=0;_<d;_++)e[g++]=v&1<<7-_?c:h}return{srcPos:t,destPos:g}}const Hv=16,Gv=100,wS=15,Vv=10,Wv=1e3,ns=16;function xS(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 SS{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 bd(o,t,e,s,i,n,r,a,h,c){const[u,d,f,g,p,v]=It(o);if(d===0&&f===0){const x=r*u+p,C=Math.round(x),A=a*g+v,P=Math.round(A),D=(r+h)*u+p,k=Math.abs(Math.round(D)-C)||1,M=(a+c)*g+v,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,v),[k,R]}if(u===0&&g===0){const x=a*f+p,C=Math.round(x),A=r*d+v,P=Math.round(A),D=(a+c)*f+p,k=Math.abs(Math.round(D)-C)||1,M=(r+h)*d+v,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,v),[R,k]}o.drawImage(t,e,s,i,n,r,a,h,c);const _=Math.hypot(u,d),b=Math.hypot(f,g);return[_*h,b*c]}function CS(o){const{width:t,height:e}=o;if(t>Wv||e>Wv)return null;const s=1e3,i=new Uint8Array([0,2,4,0,1,0,5,4,8,10,0,8,0,2,1,0]),n=t+1;let r=new Uint8Array(n*(e+1)),a,h,c;const u=t+7&-8;let d=new Uint8Array(u*e),f=0;for(const b of o.data){let x=128;for(;x>0;)d[f++]=b&x?0:255,x>>=1}let g=0;for(f=0,d[f]!==0&&(r[0]=1,++g),h=1;h<t;h++)d[f]!==d[f+1]&&(r[h]=d[f]?2:1,++g),f++;for(d[f]!==0&&(r[h]=2,++g),a=1;a<e;a++){f=a*u,c=a*n,d[f-u]!==d[f]&&(r[c]=d[f]?1:8,++g);let b=(d[f]?4:0)+(d[f-u]?8:0);for(h=1;h<t;h++)b=(b>>2)+(d[f+1]?4:0)+(d[f-u+1]?8:0),i[b]&&(r[c+h]=i[b],++g),f++;if(d[f-u]!==d[f]&&(r[c+h]=d[f]?2:4,++g),g>s)return null}for(f=u*(e-1),c=a*n,d[f]!==0&&(r[c]=8,++g),h=1;h<t;h++)d[f]!==d[f+1]&&(r[c+h]=d[f]?4:8,++g),f++;if(d[f]!==0&&(r[c+h]=4,++g),g>s)return null;const p=new Int32Array([0,n,-1,0,-n,0,0,0,1]),v=new Path2D;for(a=0;g&&a<=e;a++){let b=a*n;const x=b+t;for(;b<x&&!r[b];)b++;if(b===x)continue;v.moveTo(b%n,a);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),v.lineTo(b%n,b/n|0),r[b]||--g}while(C!==b);--a}return d=null,r=null,function(b){b.save(),b.scale(1/t,-1/e),b.translate(0,-e),b.fill(v),b.beginPath(),b.restore()}}class zv{constructor(t,e){this.alphaIsShape=!1,this.fontSize=0,this.fontSizeScale=1,this.textMatrix=Sv,this.textMatrixScale=1,this.fontMatrix=Tg,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 Xv(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,v;if(t.kind===ad.GRAYSCALE_1BPP){const _=u.byteLength,b=new Uint32Array(d.buffer,0,d.byteLength>>2),x=b.length,C=s+7>>3,A=4294967295,P=ze.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++],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;o.putImageData(a,0,f*ns)}}else if(t.kind===ad.RGBA_32BPP){for(g=0,v=s*ns*4,f=0;f<n;f++)d.set(u.subarray(h,h+v)),h+=v,o.putImageData(a,0,g),g+=ns;f<r&&(v=s*i*4,d.set(u.subarray(h,h+v)),o.putImageData(a,0,g))}else if(t.kind===ad.RGB_24BPP)for(p=ns,v=s*p,f=0;f<r;f++){for(f>=n&&(p=i,v=s*p),c=0,g=v;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 Uv(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}=_S({src:c,srcPos:h,dest:u,width:s,height:f,nonBlackColor:0})),o.putImageData(a,0,d*ns)}}function ul(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 yd(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 Yv(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 AS=["butt","round","square"],TS=["miter","round","bevel"],ES={},$v={},dp=class dp{constructor(t,e,s,i,n,{optionalContentConfig:r,markedContentStack:a=null},h,c){y(this,li);this.ctx=t,this.current=new zv(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 SS(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(),yd(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>Vv&&typeof s=="function",u=c?Date.now()+wS: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 v of n[a]){const _=v.startsWith("g_")?f:g;if(!_.has(v))return _.get(v,s),a}if(a++,a===h)return a;if(c&&++d>Vv){if(Date.now()>u)return s(),a;d=0}}}endDrawing(){w(this,li,Hp).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,Gp).call(this)}_scaleImage(t,e){const s=t.width??t.displayWidth,i=t.height??t.displayHeight;let n=Math.max(Math.hypot(e[0],e[1]),1),r=Math.max(Math.hypot(e[2],e[3]),1),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),Uv(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,v,_]=q.getAxialAlignedBoundingBox([0,0,s,i],f),b=Math.round(v-g)||1,x=Math.round(_-p)||1,C=this.cachedCanvases.getCanvas("fillCanvas",b,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=Yv(It(A),t.interpolate),bd(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=AS[t]}setLineJoin(t){this.ctx.lineJoin=TS[t]}setMiterLimit(t){this.ctx.miterLimit=t}setDash(t,e){const s=this.ctx;s.setLineDash!==void 0&&(s.setLineDash(t),s.lineDashOffset=e)}setRenderingIntent(t){}setFlatness(t){}setGState(t){for(const[e,s]of t)switch(e){case"LW":this.setLineWidth(s);break;case"LC":this.setLineCap(s);break;case"LJ":this.setLineJoin(s);break;case"ML":this.setMiterLimit(s);break;case"D":this.setDash(s[0],s[1]);break;case"RI":this.setRenderingIntent(s);break;case"FL":this.setFlatness(s);break;case"Font":this.setFont(s[0],s[1]);break;case"CA":this.current.strokeAlpha=s;break;case"ca":this.current.fillAlpha=s,this.ctx.globalAlpha=s;break;case"BM":this.ctx.globalCompositeOperation=s;break;case"SMask":this.current.activeSMask=s?this.tempSMask:null,this.tempSMask=null,this.checkSMaskState();break;case"TR":this.ctx.filter=this.current.transferMaps=this.filterFactory.addFilter(s);break}}get inSMaskMode(){return!!this.suspendedCtx}checkSMaskState(){const t=this.inSMaskMode;this.current.activeSMask&&!t?this.beginSMaskMode():!this.current.activeSMask&&t&&this.endSMaskMode()}beginSMaskMode(){if(this.inSMaskMode)throw new Error("beginSMaskMode called while already in smask mode");const t=this.ctx.canvas.width,e=this.ctx.canvas.height,s="smaskGroupAt"+this.groupLevel,i=this.cachedCanvases.getCanvas(s,t,e);this.suspendedCtx=this.ctx,this.ctx=i.context;const n=this.ctx;n.setTransform(...It(this.suspendedCtx)),ul(this.suspendedCtx,n),xS(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(),ul(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 b=this.cachedCanvases.getCanvas("maskExtension",s,i),x=b.context;x.drawImage(f,-g,-p),x.globalCompositeOperation="destination-atop",x.fillStyle=_,x.fillRect(0,0,s,i),x.globalCompositeOperation="source-over",f=b.canvas,g=p=0}else{t.save(),t.globalAlpha=1,t.setTransform(1,0,0,1,0,0);const b=new Path2D;b.rect(g,p,s,i),t.clip(b),t.globalCompositeOperation="destination-atop",t.fillStyle=_,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 v=new Path2D;v.rect(h,c,s,i),e.clip(v),e.globalCompositeOperation="destination-in",e.drawImage(f,g,p,s,i,h,c,s,i),e.restore()}save(){this.inSMaskMode?(ul(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(),ul(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,v=t.length;g<v;g++)switch(t[g]|0){case si.rectangle:r=e[p++],a=e[p++];const _=e[p++],b=e[p++],x=r+_,C=a+b;i.moveTo(r,a),_===0||b===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=ES}eoClip(){this.pendingClip=$v}beginText(){this.current.textMatrix=Sv,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||Tg,(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<Hv?c=Hv:e>Gv&&(c=Gv),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 v;if((h.disableFontFace||f||g||p)&&(v=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,v,_,i))}else r.fill(v);if(d===Me.STROKE||d===Me.FILL_STROKE)if(n){const _=r.getTransform();r.setTransform(...n),r.stroke(w(this,li,Vp).call(this,v,_,n))}else r.lineWidth/=u,r.stroke(v);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:v})}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,v=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 b,x;if(e.patternFill){n.save();const k=e.fillColor.getPattern(n,this,Ai(n),Oe.FILL);b=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*v*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,W=-(k.vmetric?j[1]:H*.5)*v,it=j[2]*v;H=j?-j[0]:H,Y=W/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 W=H/j;M=!0,n.save(),n.scale(W,1),Y/=W}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,b,x),I){const j=Y+i*I.offset.x/r,W=N-i*I.offset.y/r;this.paintChar(I.fontChar,j,W,b,x)}}const at=f?H*v-R*c:H*v+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||Tg,f=t.length,g=s.textRenderingMode===Me.INVISIBLE;let p,v,_,b;if(!(g||n===0)){for(this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null,e.save(),e.transform(...s.textMatrix),e.translate(s.x,s.y),e.scale(u,r),p=0;p<f;++p){if(v=t[p],typeof v=="number"){b=a*v*n/1e3,this.ctx.translate(b,0),s.x+=b*u;continue}const x=(v.isSpace?c:0)+h,C=i.charProcOperatorList[v.operatorListId];if(!C){rt(`Type3 character "${v.operatorListId}" is not available.`);continue}this.contentVisible&&(this.processingType3=v,this.save(),e.scale(n,n),e.transform(...d),this.executeOperatorList(C),this.restore()),_=q.applyTransform([v.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 dp(r,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack})};e=new Yg(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=yS(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);if(i){const{width:n,height:r}=e.canvas,[a,h,c,u]=q.getAxialAlignedBoundingBox([0,0,n,r],i);this.ctx.fillRect(a,h,c-a,u-h)}else this.ctx.fillRect(-1e10,-1e10,2e10,2e10);this.compose(this.current.getClippedPathBoundingBox()),this.restore()}beginInlineImage(){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()),ul(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,Hp).call(this),yd(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),yd(this.ctx)}else yd(this.ctx),this.endPath(),this.ctx.rect(e[0],e[1],r,a),this.ctx.clip(),this.ctx.beginPath()}this.current=new zv(this.ctx.canvas.width,this.ctx.canvas.height),this.transform(...s),this.transform(...i)}endAnnotation(){this.annotationCanvas&&(this.ctx.restore(),w(this,li,Gp).call(this),this.ctx=this.annotationCanvas.savedCtx,delete this.annotationCanvas.savedCtx,delete this.annotationCanvas)}paintImageMaskXObject(t){if(!this.contentVisible)return;const e=t.count;t=this.getObject(t.data,t),t.count=e;const s=this.ctx,i=this.processingType3;if(i&&(i.compiled===void 0&&(i.compiled=CS(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);Uv(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),bd(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;Xv(h,t),n=this.applyTransferMapsToCanvas(h)}const r=this._scaleImage(n,Ai(i));i.imageSmoothingEnabled=Yv(It(i),t.interpolate),bd(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;Xv(h,t),i=this.applyTransferMapsToCanvas(h)}for(const n of e)s.save(),s.transform(...n.transform),s.scale(1,-1),bd(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===$v?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,Hp=function(){for(;this.stateStack.length||this.inSMaskMode;)this.restore();this.current.activeSMask=null,this.ctx.restore(),this.transparentCanvas&&(this.ctx=this.compositeCtx,this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.drawImage(this.transparentCanvas,0,0),this.ctx.restore(),this.transparentCanvas=null)},Gp=function(){if(this.pageColors){const t=this.filterFactory.addHCMFilter(this.pageColors.foreground,this.pageColors.background);if(t!=="none"){const e=this.ctx.filter;this.ctx.filter=t,this.ctx.drawImage(this.ctx.canvas,0,0),this.ctx.filter=e}}},Vp=function(t,e,s){const i=new Path2D;return i.addPath(t,new DOMMatrix(s).invertSelf().multiplySelf(e)),i};let xo=dp;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,y(rn,Ul,null),y(rn,Yl,"");class kS{constructor({parsedData:t,rawData:e}){y(this,ba);y(this,$l);m(this,ba,t),m(this,$l,e)}getRaw(){return l(this,$l)}get(t){return l(this,ba).get(t)??null}getAll(){return Mg(l(this,ba))}has(t){return l(this,ba).has(t)}}ba=new WeakMap,$l=new WeakMap;const So=Symbol("INTERNAL");class PS{constructor(t,{name:e,intent:s,usage:i,rbGroups:n}){y(this,ql,!1);y(this,Kl,!1);y(this,Jl,!1);y(this,Wo,!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,Wo);if(!l(this,Wo))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,Wo,e)}}ql=new WeakMap,Kl=new WeakMap,Jl=new WeakMap,Wo=new WeakMap;class MS{constructor(t,e=fs.DISPLAY){y(this,Ql);y(this,ur,null);y(this,St,new Map);y(this,zo,null);y(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 PS(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,zo,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,zo)===null||this.getHash()===l(this,zo)}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?Mg(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 Pv;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,zo=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 OS{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 DS(this,t,this._progressiveDone,this._contentDispositionFilename)}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new RS(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 DS{constructor(t,e,s=!1,i=null){this._stream=t,this._done=s||!1,this._filename=Fg(i)?i:null,this._queuedChunks=e||[],this._loaded=0;for(const n of this._queuedChunks)this._loaded+=n.byteLength;this._requests=[],this._headersReady=Promise.resolve(),t._fullRequestReader=this,this.onProgress=null}_enqueue(t){this._done||(this._requests.length>0?this._requests.shift().resolve({value:t,done:!1}):this._queuedChunks.push(t),this._loaded+=t.byteLength)}get headersReady(){return this._headersReady}get filename(){return this._filename}get isRangeSupported(){return this._stream._isRangeSupported}get isStreamingSupported(){return this._stream._isStreamingSupported}get contentLength(){return this._stream._contentLength}async read(){if(this._queuedChunks.length>0)return{value:this._queuedChunks.shift(),done:!1};if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}progressiveDone(){this._done||(this._done=!0)}}class RS{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 LS(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[,v,_,b]=f;if(v=parseInt(v,10),v in d){if(v===0)break;continue}d[v]=[_,b]}const p=[];for(let v=0;v<d.length&&v in d;++v){let[_,b]=d[v];b=a(b),_&&(b=unescape(b),v===0&&(b=h(b))),p.push(b)}return p.join("")}function a(u){if(u.startsWith('"')){const d=u.slice(1).split('\\"');for(let f=0;f<d.length;++f){const g=d[f].indexOf('"');g!==-1&&(d[f]=d[f].slice(0,g),d.length=f+1),d[f]=d[f].replaceAll(/\\(.)/g,"$1")}u=d.join('"')}return u}function h(u){const d=u.indexOf("'");if(d===-1)return u;const f=u.slice(0,d),p=u.slice(d+1).replace(/^[^']*'/,"");return i(f,p)}function c(u){return!u.startsWith("=?")||/[\x00-\x19\x80-\xff]/.test(u)?u:u.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,function(d,f,g,p){if(g==="q"||g==="Q")return p=p.replaceAll("_"," "),p=p.replaceAll(/=([0-9a-fA-F]{2})/g,function(v,_){return String.fromCharCode(parseInt(_,16))}),i(f,p);try{p=atob(p)}catch{}return i(f,p)})}return""}function qv(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 Kv({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 Jv(o){const t=o.get("Content-Disposition");if(t){let e=LS(t);if(e.includes("%"))try{e=decodeURIComponent(e)}catch{}if(Fg(e))return e}return null}function wd(o,t){return o===404||o===0&&t.startsWith("file:")?new al('Missing PDF "'+t+'".'):new cd(`Unexpected server response (${o}) while retrieving PDF "${t}".`,o)}function Qv(o){return o===200||o===206}function Zv(o,t,e){return{method:"GET",headers:o,signal:e.signal,mode:"cors",credentials:t?"include":"same-origin",redirect:"follow"}}function tb(o){return o instanceof Uint8Array?o.buffer:o instanceof ArrayBuffer?o:(rt(`getArrayBuffer - unexpected data format: ${o}`),new Uint8Array(o).buffer)}class eb{constructor(t){J(this,"_responseOrigin",null);this.source=t,this.isHttp=/^https?:/i.test(t.url),this.headers=qv(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 FS(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new IS(this,t,e);return this._rangeRequestReaders.push(s),s}cancelAllRequests(t){var e;(e=this._fullRequestReader)==null||e.cancel(t);for(const s of this._rangeRequestReaders.slice(0))s.cancel(t)}}class FS{constructor(t){this._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,Zv(s,this._withCredentials,this._abortController)).then(n=>{if(t._responseOrigin=_d(n.url),!Qv(n.status))throw wd(n.status,i);this._reader=n.body.getReader(),this._headersCapability.resolve();const r=n.headers,{allowRangeRequests:a,suggestedLength:h}=Kv({responseHeaders:r,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=a,this._contentLength=h||this._contentLength,this._filename=Jv(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:tb(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}class IS{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,Zv(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(!Qv(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:tb(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}const $g=200,qg=206;function jS(o){const t=o.response;return typeof t!="string"?t:ud(t).buffer}class NS{constructor({url:t,httpHeaders:e,withCredentials:s}){J(this,"_responseOrigin",null);this.url=t,this.isHttp=/^https?:/i.test(t),this.headers=qv(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=qg):i.expectedStatus=$g,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||$g;if(!(n===$g&&s.expectedStatus===qg)&&n!==s.expectedStatus){s.onError(i.status);return}const a=jS(i);if(n===qg){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 BS{constructor(t){this._source=t,this._manager=new NS(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 HS(this._manager,this._source),this._fullRequestReader}getRangeReader(t,e){const s=new GS(this._manager,t,e);return s.onClosed=this._onRangeRequestReaderClosed.bind(this),this._rangeRequestReaders.push(s),s}cancelAllRequests(t){var e;(e=this._fullRequestReader)==null||e.cancel(t);for(const s of this._rangeRequestReaders.slice(0))s.cancel(t)}}class HS{constructor(t,e){this._manager=t,this._url=e.url,this._fullRequestId=t.request({onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)}),this._headersCapability=Promise.withResolvers(),this._disableRange=e.disableRange||!1,this._contentLength=e.length,this._rangeChunkSize=e.rangeChunkSize,!this._rangeChunkSize&&!this._disableRange&&(this._disableRange=!0),this._isStreamingSupported=!1,this._isRangeSupported=!1,this._cachedChunks=[],this._requests=[],this._done=!1,this._storedError=void 0,this._filename=null,this.onProgress=null}_onHeadersReceived(){const t=this._fullRequestId,e=this._manager.getRequestXhr(t);this._manager._responseOrigin=_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}=Kv({responseHeaders:i,isHttp:this._manager.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});n&&(this._isRangeSupported=!0),this._contentLength=r||this._contentLength,this._filename=Jv(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 GS{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 VS=/^[a-z][a-z0-9\-+.]+:/i;function WS(o){if(VS.test(o))return new URL(o);const t=process.getBuiltinModule("url");return new URL(t.pathToFileURL(o))}class zS{constructor(t){this.source=t,this.url=WS(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 XS(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new US(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 XS{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 al(`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 US{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 YS=1e5,rs=30,$S=.8,le=class le{constructor({textContentSource:t,container:e,viewport:s}){y(this,yn);y(this,dr,Promise.withResolvers());y(this,os,null);y(this,Zl,!1);y(this,tc,!!((yb=globalThis.FontInspector)!=null&&yb.enabled));y(this,ya,null);y(this,bn,null);y(this,ec,0);y(this,sc,0);y(this,_a,null);y(this,Uo,null);y(this,Yo,0);y(this,fr,0);y(this,$o,Object.create(null));y(this,ic,[]);y(this,qo,null);y(this,wa,[]);y(this,nc,new WeakMap);y(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,bn,{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,bs,by).call(h),zr(e,s),l(this,dr).promise.finally(()=>{l(le,Ko).delete(this),m(this,bn,null),m(this,$o,null)}).catch(()=>{})}static get fontFamilyMap(){const{isWindows:t,isFirefox:e}=ze.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,ya)??m(this,ya,e.lang),Object.assign(l(this,$o),e.styles),w(this,yn,my).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),zr(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,bs,af).call(n,l(this,ya))};for(const a of l(this,wa))r.properties=l(this,nc).get(a),r.div=a,w(this,yn,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,ya=new WeakMap,bn=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,yn=new WeakSet,my=function(t){var i,n;if(l(this,Zl))return;(n=l(this,bn)).ctx??(n.ctx=w(i=le,bs,af).call(i,l(this,ya)));const e=l(this,wa),s=l(this,ic);for(const r of t){if(e.length>YS){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,yn,vy).call(this,r)}},vy=function(t){var v;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(v=le,bs,yy).call(v,a,l(this,ya));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]),b=Math.abs(t.transform[3]);_!==b&&Math.max(_,b)/Math.min(_,b)>1.5&&(p=!0)}if(p&&(s.canvasWidth=r.vertical?t.height:t.width),l(this,nc).set(e,s),l(this,bn).div=e,l(this,bn).properties=s,w(this,yn,zp).call(this,l(this,bn)),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,bs,Xp).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)},bs=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},Xp=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)},by=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()},yy=function(t,e){const s=l(this,xa).get(t);if(s)return s;const i=w(this,bs,af).call(this,e);i.canvas.width=i.canvas.height=rs,w(this,bs,Xp).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):$S;return l(this,xa).set(t,c),c},y(le,bs),y(le,xa,new Map),y(le,Sa,new Map),y(le,ac,new WeakMap),y(le,gr,null),y(le,Ko,new Set);let dl=le;class fl{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(fl.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 qS=65536,KS=100,JS=5e3,QS=Pe?dS:lS,ZS=Pe?fS:Lv,tC=Pe?uS:cS,eC=Pe?gS:jv;function sC(o={}){typeof o=="string"||o instanceof URL?o={url:o}:(o instanceof ArrayBuffer||ArrayBuffer.isView(o))&&(o={data:o});const t=new Kg,{docId:e}=t,s=o.url?iC(o.url):null,i=o.data?nC(o.data):null,n=o.httpHeaders||null,r=o.withCredentials===!0,a=o.password??null,h=o.range instanceof ib?o.range:null,c=Number.isInteger(o.rangeChunkSize)&&o.rangeChunkSize>0?o.rangeChunkSize:qS;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,v=o.CMapReaderFactory||ZS,_=typeof o.standardFontDataUrl=="string"?o.standardFontDataUrl:null,b=o.StandardFontDataFactory||eC,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&&(ze.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||QS,W=o.FilterFactory||tC,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:v===Lv&&b===jv&&g&&_&&hl(g,document.baseURI)&&hl(_,document.baseURI),Wt=null;Gx(d);const Tt={canvasFactory:new j({ownerDocument:I,enableHWA:it}),filterFactory:new W({docId:e,ownerDocument:I}),cMapReaderFactory:ne?null:new v({baseUrl:g,isCompressed:p}),standardFontDataFactory:ne?null:new b({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:Wt,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 OS(h,{disableRange:Y,disableStream:N});else if(!i){if(!s)throw new Error("getDocument - no `url` parameter provided.");let Ps;if(Pe)if(hl(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=eb}else Ps=zS;else Ps=hl(s)?eb:BS;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 cl(e,Ps,u.port),Je=new hC(Xi,t,ft,Xs,Tt);t._transport=Je,Xi.send("Ready",null)})}).catch(t._capability.reject),t}function iC(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 nC(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 sb(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,y(Id,Fd,0);let Kg=Id;class ib{constructor(t,e,s=!1,i=null){this.length=t,this.initialData=e,this.progressiveDone=s,this.contentDispositionFilename=i,this._rangeListeners=[],this._progressListeners=[],this._progressiveReadListeners=[],this._progressiveDoneListeners=[],this._readyCapability=Promise.withResolvers()}addRangeListener(t){this._rangeListeners.push(t)}addProgressListener(t){this._progressListeners.push(t)}addProgressiveReadListener(t){this._progressiveReadListeners.push(t)}addProgressiveDoneListener(t){this._progressiveDoneListeners.push(t)}onDataRange(t,e){for(const s of this._rangeListeners)s(t,e)}onDataProgress(t,e){this._readyCapability.promise.then(()=>{for(const s of this._progressListeners)s(t,e)})}onDataProgressiveRead(t){this._readyCapability.promise.then(()=>{for(const e of this._progressiveReadListeners)e(t)})}onDataProgressiveDone(){this._readyCapability.promise.then(()=>{for(const t of this._progressiveDoneListeners)t()})}transportReady(){this._readyCapability.resolve()}requestDataRange(t,e){Et("Abstract method PDFDataRangeTransport.requestDataRange")}abort(){}}class rC{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 aC{constructor(t,e,s,i=!1){y(this,Bs);y(this,pr,null);y(this,_n,!1);this._pageIndex=t,this._pageInfo=e,this._transport=s,this._stats=i?new Ev:null,this._pdfBug=i,this.commonObjs=s.commonObjs,this.objs=new nb,this._maybeCleanupAfterRender=!1,this._intentStates=new Map,this.destroyed=!1}get pageNumber(){return this._pageIndex+1}get rotate(){return this._pageInfo.rotate}get ref(){return this._pageInfo.ref}get userUnit(){return this._pageInfo.userUnit}get view(){return this._pageInfo.view}getViewport({scale:t,rotation:e=this.rotate,offsetX:s=0,offsetY:i=0,dontFlip:n=!1}={}){return new ol({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 v=this._intentStates.get(p);v||(v=Object.create(null),this._intentStates.set(p,v)),v.streamReaderCancelTimeout&&(clearTimeout(v.streamReaderCancelTimeout),v.streamReaderCancelTimeout=null);const _=!!(g&fs.PRINT);v.displayReadyCapability||(v.displayReadyCapability=Promise.withResolvers(),v.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(P=this._stats)==null||P.time("Page Request"),this._pumpOperatorList(f));const b=D=>{var k;v.renderTasks.delete(x),(this._maybeCleanupAfterRender||_)&&m(this,_n,!0),w(this,Bs,jh).call(this,!_),D?(x.capability.reject(D),this._abortOperatorList({intentState:v,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 Jg({callback:b,params:{canvasContext:t,viewport:e,transform:n,background:r},objs:this.objs,commonObjs:this.commonObjs,annotationCanvasMap:h,operatorList:v.operatorList,pageIndex:this._pageIndex,canvasFactory:this._transport.canvasFactory,filterFactory:this._transport.filterFactory,useRequestAnimationFrame:!_,pdfBug:this._pdfBug,pageColors:c});(v.renderTasks||(v.renderTasks=new Set)).add(x);const C=x.task;return Promise.all([v.displayReadyCapability.promise,a]).then(([D,k])=>{var M;if(this.destroyed){b();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(b),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=>fl.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 Ev),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 Lg){let i=KS;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)},JS)),!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 oC{constructor(){y(this,wn,new Map);y(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=Vx()}={}){y(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 cl("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 cl("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 oC;this._port=e;const s=`fake${Ze(jt,Nd)._++}`,i=new cl(s+"_worker",s,e);t.setup(i,e),this._messageHandler=new cl(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}},y(jt,Qo),y(jt,Nd,0),y(jt,Ca,!1),y(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 hC{constructor(t,e,s,i,n){y(this,Ta);y(this,xn,new Map);y(this,Ii,new Map);y(this,Zo,new Map);y(this,th,new Map);y(this,Sn,null);this.messageHandler=t,this.loadingTask=e,this.commonObjs=new nb,this.fontLoader=new oS({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 Mv?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(),dl.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 rC(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 hS(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)>jx&&(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 aC(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 sb(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 MS(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 kS(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),dl.cleanup()}}cachedPageNumber(t){if(!sb(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 gl=Symbol("INITIAL_DATA");class nb{constructor(){y(this,oc);y(this,ys,Object.create(null))}get(t,e=null){if(e){const i=w(this,oc,Up).call(this,t);return i.promise.then(()=>e(i.data)),null}const s=l(this,ys)[t];if(!s||s.data===gl)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return s.data}has(t){const e=l(this,ys)[t];return!!e&&e.data!==gl}delete(t){const e=l(this,ys)[t];return!e||e.data===gl?!1:(delete l(this,ys)[t],!0)}resolve(t,e=null){const s=w(this,oc,Up).call(this,t);s.data=e,s.resolve()}clear(){var t;for(const e in l(this,ys)){const{data:s}=l(this,ys)[e];(t=s==null?void 0:s.bitmap)==null||t.close()}m(this,ys,Object.create(null))}*[Symbol.iterator](){for(const t in l(this,ys)){const{data:e}=l(this,ys)[t];e!==gl&&(yield[t,e])}}}ys=new WeakMap,oc=new WeakSet,Up=function(t){var e;return(e=l(this,ys))[t]||(e[t]={...Promise.withResolvers(),data:gl})};class lC{constructor(t){y(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}){y(this,vr,null);this.callback=t,this.params=e,this.objs=s,this.commonObjs=i,this.annotationCanvasMap=n,this.operatorListIdx=null,this.operatorList=r,this._pageIndex=a,this.canvasFactory=h,this.filterFactory=c,this._pdfBug=d,this.pageColors=f,this.running=!1,this.graphicsReadyCallback=null,this.graphicsReady=!1,this._useRequestAnimationFrame=u===!0&&typeof window<"u",this.cancelled=!1,this.capability=Promise.withResolvers(),this.task=new lC(this),this._cancelBound=this.cancel.bind(this),this._continueBound=this._continue.bind(this),this._scheduleNextBound=this._scheduleNext.bind(this),this._nextBound=this._next.bind(this),this._canvas=e.canvasContext.canvas}get completed(){return this.capability.promise.catch(function(){})}initializeGraphics({transparency:t=!1,optionalContentConfig:e}){var 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,vr)&&(window.cancelAnimationFrame(l(this,vr)),m(this,vr,null)),l(ka,Ea).delete(this._canvas),this.callback(t||new Lg(`Rendering cancelled, page ${this._pageIndex+1}`,e))}operatorListChanged(){var t;if(!this.graphicsReady){this.graphicsReadyCallback||(this.graphicsReadyCallback=this._continueBound);return}(t=this.stepper)==null||t.updateOperatorList(this.operatorList),!this.running&&this._continue()}_continue(){this.running=!0,!this.cancelled&&(this.task.onContinue?this.task.onContinue(this._scheduleNextBound):this._scheduleNext())}_scheduleNext(){this._useRequestAnimationFrame?m(this,vr,window.requestAnimationFrame(()=>{m(this,vr,null),this._nextBound().catch(this._cancelBound)})):Promise.resolve().then(this._nextBound).catch(this._cancelBound)}async _next(){this.cancelled||(this.operatorListIdx=this.gfx.executeOperatorList(this.operatorList,this.operatorListIdx,this._continueBound,this.stepper),this.operatorListIdx===this.operatorList.argsArray.length&&(this.running=!1,this.operatorList.lastChunk&&(this.gfx.endDrawing(),l(ka,Ea).delete(this._canvas),this.callback())))}};vr=new WeakMap,Ea=new WeakMap,y(ka,Ea,new WeakSet);let Jg=ka;const cC="4.10.38",uC="f9bea397f";function rb(o){return Math.floor(Math.max(0,Math.min(1,o))*255).toString(16).padStart(2,"0")}function pl(o){return Math.max(0,Math.min(255,255*o))}class ab{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=pl(t),[t,t,t]}static G_HTML([t]){const e=rb(t);return`#${e}${e}${e}`}static RGB_G([t,e,s]){return["G",.3*t+.59*e+.11*s]}static RGB_rgb(t){return t.map(pl)}static RGB_HTML(t){return`#${t.map(rb).join("")}`}static T_HTML(){return"#00000000"}static T_rgb(){return[null]}static CMYK_RGB([t,e,s,i]){return["RGB",1-Math.min(1,t+i),1-Math.min(1,s+i),1-Math.min(1,e+i)]}static CMYK_rgb([t,e,s,i]){return[pl(1-Math.min(1,t+i)),pl(1-Math.min(1,s+i)),pl(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 dC{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 Qg extends dC{_createSVG(t){return document.createElementNS(nn,t)}}class ob{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&&fl.shouldBuildText(i.name)&&c.push(g)}return{textDivs:c}}const u=[[i,-1,r]];for(;u.length>0;){const[g,p,v]=u.at(-1);if(p+1===g.children.length){u.pop();continue}const _=g.children[++u.at(-1)[1]];if(_===null)continue;const{name:b}=_;if(b==="#text"){const C=document.createTextNode(_.value);c.push(C),v.append(C);continue}const x=(d=_==null?void 0:_.attributes)!=null&&d.xmlns?document.createElementNS(_.attributes.xmlns,b):document.createElement(b);if(v.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&&fl.shouldBuildText(b)&&c.push(C),x.append(C)}}for(const g of h.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea"))g.setAttribute("readOnly",!0);return{textDivs:c}}static update(t){const e=`matrix(${t.viewport.transform.join(",")})`;t.div.style.transform=e,t.div.hidden=!1}}const ml=1e3,fC=9,Ur=new WeakSet;function Jn(o){return{width:o[2]-o[0],height:o[3]-o[1]}}class gC{static create(t){switch(t.data.annotationType){case oe.LINK:return new hb(t);case oe.TEXT:return new pC(t);case oe.WIDGET:switch(t.data.fieldType){case"Tx":return new mC(t);case"Btn":return t.data.radioButton?new lb(t):t.data.checkBox?new bC(t):new yC(t);case"Ch":return new _C(t);case"Sig":return new vC(t)}return new Yr(t);case oe.POPUP:return new Zg(t);case oe.FREETEXT:return new cb(t);case oe.LINE:return new xC(t);case oe.SQUARE:return new SC(t);case oe.CIRCLE:return new CC(t);case oe.POLYLINE:return new ub(t);case oe.CARET:return new TC(t);case oe.INK:return new tp(t);case oe.POLYGON:return new AC(t);case oe.HIGHLIGHT:return new db(t);case oe.UNDERLINE:return new EC(t);case oe.SQUIGGLY:return new kC(t);case oe.STRIKEOUT:return new PC(t);case oe.STAMP:return new fb(t);case oe.FILEATTACHMENT:return new MC(t);default:return new qt(t)}}}const fp=class fp{constructor(t,{isRenderable:e=!1,ignoreBorder:s=!1,createQuadrilaterals:i=!1}={}){y(this,hc);y(this,Pa,null);y(this,eh,!1);y(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 fp._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,Yp).call(this,e),(s=l(this,sh))==null||s.popup.updateEdited(t)}resetEdited(){var t;l(this,Pa)&&(w(this,hc,Yp).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=ml);const{style:r}=n;if(r.zIndex=this.parent.zIndex++,e.alternativeText&&(n.title=e.alternativeText),e.noRotate&&n.classList.add("norotate"),!e.rect||this instanceof Zg){const{rotation:v}=e;return!e.hasOwnCanvas&&v!==0&&this.setRotation(v,n),n}const{width:a,height:h}=Jn(e.rect);if(!t&&e.borderStyle.width>0){r.borderWidth=`${e.borderStyle.width}px`;const v=e.borderStyle.horizontalCornerRadius,_=e.borderStyle.verticalCornerRadius;if(v>0||_>0){const x=`calc(${v}px * var(--scale-factor)) / calc(${_}px * var(--scale-factor))`;r.borderRadius=x}else if(this instanceof lb){const x=`calc(${a}px * var(--scale-factor)) / calc(${h}px * var(--scale-factor))`;r.borderRadius=x}switch(e.borderStyle.style){case rl.SOLID:r.borderStyle="solid";break;case rl.DASHED:r.borderStyle="dashed";break;case rl.BEVELED:rt("Unimplemented border style: beveled");break;case rl.INSET:rt("Unimplemented border style: inset");break;case rl.UNDERLINE:r.borderBottomStyle="solid";break}const b=e.borderColor||null;b?(m(this,eh,!0),r.borderColor=q.makeHexColor(b[0]|0,b[1]|0,b[2]|0)):r.borderWidth=0}const c=q.normalizeRect([e.rect[0],s.view[3]-e.rect[1]+s.view[1],e.rect[2],s.view[3]-e.rect[3]+s.view[1]]),{pageWidth:u,pageHeight:d,pageX:f,pageY:g}=i.rawDims;r.left=`${100*(c[0]-f)/u}%`,r.top=`${100*(c[1]-g)/d}%`;const{rotation:p}=e;return e.hasOwnCanvas||p===0?(r.width=`${100*a/u}%`,r.height=`${100*h/d}%`):this.setRotation(p,n),n}setRotation(t,e=this.container){if(!this.data.rect)return;const{pageWidth:s,pageHeight:i}=this.parent.viewport.rawDims,{width:n,height:r}=Jn(this.data.rect);let a,h;t%180===0?(a=100*n/s,h=100*r/i):(a=100*r/s,h=100*n/i),e.style.width=`${a}%`,e.style.height=`${h}%`,e.setAttribute("data-main-rotation",(360-t)%360)}get _commonActions(){const t=(e,s,i)=>{const n=i.detail[e],r=n[0],a=n.slice(1);i.target.style[s]=ab[`${r}_HTML`](a),this.annotationStorage.setValue(this.data.id,{[s]:ab[`${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(v=>Math.fround(v));if(t.length===8){const[v,_,b,x]=t.subarray(2,6);if(i===v&&n===_&&e===b&&s===x)return}const{style:r}=this.container;let a;if(l(this,eh)){const{borderColor:v,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="${v}" 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 v=2,_=t.length;v<_;v+=8){const b=t[v],x=t[v+1],C=t[v+2],A=t[v+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),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 Zg({data:{color:t.color,titleObj:t.titleObj,modificationDate:t.modificationDate,contentsObj:t.contentsObj,richText:t.richText,parentRect:t.rect,borderStyle:0,id:`popup_${t.id}`,rotation:t.rotation},parent:this.parent,elements:[this]}));this.parent.div.append(e.render())}render(){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,Yp=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=fp;class hb extends qt{constructor(e,s=null){super(e,{isRenderable:!0,ignoreBorder:!!(s!=null&&s.ignoreBorder),createQuadrilaterals:!0});y(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,_y).call(this,i,e.attachment,e.attachmentDest),n=!0):e.setOCGState?(w(this,_s,wy).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:v}of p)f.add(v)}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 v=f.defaultValue||"";c.setValue(g,{value:v});break}case"checkbox":case"radiobutton":{const v=f.defaultValue===f.exportValues;c.setValue(g,{value:v});break}case"combobox":case"listbox":{const v=f.defaultValue||"";c.setValue(g,{value:v});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","")},_y=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)},wy=function(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeSetOCGState(s),!1),w(this,_s,so).call(this)};class pC 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 ze.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||fC,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/(Eg*i))||1,d=c/u;r=Math.min(i,h(d/Eg))}else{const c=Math.abs(this.data.rect[3]-this.data.rect[1]-a);r=Math.min(i,h(c/Eg))}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 mC 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=ml,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 v;if(u.focused)return;const{target:p}=g;u.userValue&&(p.value=u.userValue),u.lastCommittedValue=p.value,u.commitKey=1,(v=this.data.actions)!=null&&v.Focus||(u.focused=!0)}),s.addEventListener("updatefromsandbox",g=>{this.showElementAndHideCanvas(g.target);const p={value(v){u.userValue=v.detail.value??"",t.setValue(e,{value:u.userValue.toString()}),v.target.value=u.userValue},formattedValue(v){const{formattedValue:_}=v.detail;u.formattedValue=_,_!=null&&v.target!==document.activeElement&&(v.target.value=_),t.setValue(e,{formattedValue:_})},selRange(v){v.target.setSelectionRange(...v.detail.selRange)},charLimit:v=>{var C;const{charLimit:_}=v.detail,{target:b}=v;if(_===0){b.removeAttribute("maxLength");return}b.setAttribute("maxLength",_);let x=u.userValue;!x||x.length<=_||(x=x.slice(0,_),b.value=u.userValue=x,t.setValue(e,{value:x}),(C=this.linkService.eventBus)==null||C.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:x,willCommit:!0,commitKey:1,selStart:b.selectionStart,selEnd:b.selectionEnd}}))}};this._dispatchEventFromSandbox(p,g)}),s.addEventListener("keydown",g=>{var _;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:v}=g.target;u.lastCommittedValue!==v&&(u.lastCommittedValue=v,u.userValue=v,(_=this.linkService.eventBus)==null||_.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:v,willCommit:!0,commitKey:p,selStart:g.target.selectionStart,selEnd:g.target.selectionEnd}}))});const f=d;d=null,s.addEventListener("blur",g=>{var v,_;if(!u.focused||!g.relatedTarget)return;(v=this.data.actions)!=null&&v.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:v}=g,{value:_,selectionStart:b,selectionEnd:x}=v;let C=b,A=x;switch(g.inputType){case"deleteWordBackward":{const D=_.substring(0,b).match(/\w*[^\w]*$/);D&&(C-=D[0].length);break}case"deleteWordForward":{const D=_.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}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 vC extends Yr{constructor(t){super(t,{isRenderable:!!t.data.hasOwnCanvas})}}class bC 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=ml,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 lb 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=ml,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 yC extends hb{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 _C 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=ml;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 v of i.options)v.selected=p.has(v.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:v}=f.detail.insert,_=i.children[g],b=document.createElement("option");b.textContent=p,b.value=v,_?_.before(b):i.append(b),t.setValue(e,{value:a(!0),items:c(f)}),h=a(!1)},items(f){const{items:g}=f.detail;for(;i.length!==0;)i.remove(0);for(const p of g){const{displayValue:v,exportValue:_}=p,b=document.createElement("option");b.textContent=v,b.value=_,i.append(b)}i.options.length>0&&(i.options[0].selected=!0),t.setValue(e,{value:a(!0),items:c(f)}),h=a(!1)},indices(f){const g=new Set(f.detail.indices);for(const p of f.target.options)p.selected=g.has(p.index);t.setValue(e,{value:a(!0)}),h=a(!1)},editable(f){f.target.disabled=!f.detail.editable}};this._dispatchEventFromSandbox(d,u)}),i.addEventListener("input",u=>{var g;const d=a(!0),f=a(!1);t.setValue(e,{value:d}),u.preventDefault(),(g=this.linkService.eventBus)==null||g.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:h,change:f,changeEx:d,willCommit:!1,commitKey:1,keyDown:!1}})}),this._setEventListeners(i,null,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"],["input","Action"],["input","Validate"]],u=>u.target.value)):i.addEventListener("input",function(u){t.setValue(e,{value:a(!0)})}),this.data.combo&&this._setTextStyle(i),this._setBackgroundColor(i),this._setDefaultPropertiesFromJS(i),this.container.append(i),this.container}}class Zg 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 wC({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=>`${Rg}${s}`).join(",")),this.container}}class wC{constructor({container:t,color:e,elements:s,titleObj:i,modificationDate:n,contentsObj:r,richText:a,parent:h,rect:c,parentRect:u,open:d}){y(this,Ct);y(this,ih,w(this,Ct,Cy).bind(this));y(this,Bd,w(this,Ct,qp).bind(this));y(this,Hd,w(this,Ct,df).bind(this));y(this,nh,w(this,Ct,uf).bind(this));y(this,Ma,null);y(this,Xt,null);y(this,Cn,null);y(this,rh,null);y(this,lc,null);y(this,cc,null);y(this,ah,null);y(this,An,!1);y(this,ci,null);y(this,Tn,null);y(this,uc,null);y(this,En,null);y(this,dc,null);y(this,Oa,null);y(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,Ig.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)ob.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,Sy).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},$p=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},xy=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},Sy=function(t){const e=[],s={str:t,html:{name:"div",attributes:{dir:"auto"},children:[{name:"p",children:e}]}},i={style:{color:l(this,Ct,xy),fontSize:l(this,Ct,$p)?`calc(${l(this,Ct,$p)}px * var(--scale-factor))`:""}};for(const n of t.split(`
|
|
530
|
-
`))e.push({name:"span",value:n,attributes:i});return s},Cy=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)},Ay=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,qp).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,Ay).call(this),l(this,Xt).hidden=!1,l(this,Xt).style.zIndex=parseInt(l(this,Xt).style.zIndex)+1e3)},qp=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 cb 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 xC extends qt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(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 SC extends qt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(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 CC extends qt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(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 ub extends qt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(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 AC extends ub{constructor(t){super(t),this.containerClassName="polygonAnnotation",this.svgElementName="svg:polygon"}}class TC 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 tp extends qt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,bc);y(this,vc,null);y(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,bc,Kp).call(this,s,e),u=this.svgFactory.create(h,c,!0),d=m(this,vc,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,vc);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,bc,Kp).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")}}vc=new WeakMap,Ra=new WeakMap,bc=new WeakSet,Kp=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 db 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 EC 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 kC 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 PC 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 fb 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 MC extends qt{constructor(e){var i;super(e,{isRenderable:!0});y(this,_c);y(this,yc,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,Jp).bind(this)),m(this,yc,i);const{isMac:n}=ze.platform;return e.addEventListener("keydown",r=>{r.key==="Enter"&&(n?r.metaKey:r.ctrlKey)&&w(this,_c,Jp).call(this)}),!s.popupRef&&this.hasPopupData?this._createPopup():i.classList.add("popupTriggerArea"),e.append(i),e}getElementsToTriggerPopup(){return l(this,yc)}addHighlightArea(){this.container.classList.add("highlightArea")}}yc=new WeakMap,_c=new WeakSet,Jp=function(){var e;(e=this.downloadManager)==null||e.openOrDownloadData(this.content,this.filename)};class OC{constructor({div:t,accessibilityManager:e,annotationCanvasMap:s,annotationEditorUIManager:i,page:n,viewport:r,structTreeLayer:a}){y(this,Ia);y(this,wc,null);y(this,La,null);y(this,Fa,new Map);y(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;zr(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 Qg,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=gC.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,Ty).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,Qp).call(this)}update({viewport:t}){const e=this.div;this.viewport=t,zr(e,{rotation:t.rotation}),w(this,Ia,Qp).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,Ty=async function(t,e){var r,a;const s=t.firstChild||t,i=s.id=`${Rg}${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)},Qp=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"});y(this,ie);y(this,ui);y(this,ws,"");y(this,Sc,`${this.id}-editor`);y(this,ja,null);y(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 ll([[["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,Ey).call(this,s);break;case dt.FREETEXT_COLOR:w(this,ie,ky).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,Py).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,v;switch(this.rotation){case 0:p=e+(a[0]-f)/u,v=s+this.height-(a[1]-g)/d;break;case 90:p=e+(a[0]-f)/u,v=s-(a[1]-g)/d,[h,c]=[c,-h];break;case 180:p=e-this.width+(a[0]-f)/u,v=s-(a[1]-g)/d,[h,c]=[-h,-c];break;case 270:p=e+(a[0]-f-this.height*d)/u,v=s+(a[1]-g-this.width*u)/d,[h,c]=[-c,h];break}this.setAt(p*n,v*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,v,_;const s=e.clipboardData||window.clipboardData,{types:i}=s;if(i.length===1&&i[0]==="text/plain")return;e.preventDefault();const n=w(p=Ot,kn,Zp).call(p,s.getData("text")||"").replaceAll(xd,`
|
|
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"]),G.setClass(rd);var nl={};nl.d=(o,t)=>{for(var e in t)nl.o(t,e)&&!nl.o(o,e)&&Object.defineProperty(o,e,{enumerable:!0,get:t[e]})},nl.o=(o,t)=>Object.prototype.hasOwnProperty.call(o,t);var Z=globalThis.pdfjsLib={};nl.d(Z,{AbortException:()=>qn,AnnotationEditorLayer:()=>lp,AnnotationEditorParamsType:()=>pt,AnnotationEditorType:()=>nt,AnnotationEditorUIManager:()=>Xr,AnnotationLayer:()=>FC,AnnotationMode:()=>Yn,ColorPicker:()=>Cd,DOMSVGFactory:()=>Zg,DrawLayer:()=>cp,FeatureTest:()=>Ue,GlobalWorkerOptions:()=>rn,ImageKind:()=>ad,InvalidPDFException:()=>Mg,MissingPDFException:()=>al,OPS:()=>ii,OutputScale:()=>Bg,PDFDataRangeTransport:()=>nb,PDFDateString:()=>jg,PDFWorker:()=>Co,PasswordResponses:()=>Wx,PermissionFlag:()=>Vx,PixelsPerInch:()=>Kn,RenderingCancelledException:()=>Fg,TextLayer:()=>dl,TouchManager:()=>md,UnexpectedResponseException:()=>cd,Util:()=>q,VerbosityLevel:()=>od,XfaLayer:()=>hb,build:()=>pC,createValidAbsoluteUrl:()=>$x,fetchData:()=>dd,getDocument:()=>aC,getFilenameFromUrl:()=>iS,getPdfFilenameFromUrl:()=>nS,getXfaPageViewport:()=>rS,isDataScheme:()=>fd,isPdfFile:()=>Ig,noContextMenu:()=>ni,normalizeUnicode:()=>tS,setLayerDimensions:()=>Wr,shadow:()=>lt,stopEvent:()=>ms,version:()=>gC});const Me=typeof process=="object"&&process+""=="[object process]"&&!process.versions.nw&&!(process.versions.electron&&process.type&&process.type!=="browser"),Cv=[1,0,0,1,0,0],Eg=[.001,0,0,.001,0,0],zx=1e7,kg=1.35,ps={ANY:1,DISPLAY:2,PRINT:4,ANNOTATIONS_FORMS:16,ANNOTATIONS_STORAGE:32,ANNOTATIONS_DISABLE:64,IS_EDITING:128,OPLIST:256},Yn={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},Gx="pdfjs_internal_editor_",nt={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15},pt={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},Vx={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},Oe={FILL:0,STROKE:1,FILL_STROKE:2,INVISIBLE:3,FILL_STROKE_MASK:3,ADD_TO_PATH_FLAG:4},ad={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},le={TEXT:1,LINK:2,FREETEXT:3,LINE:4,SQUARE:5,CIRCLE:6,POLYGON:7,POLYLINE:8,HIGHLIGHT:9,UNDERLINE:10,SQUIGGLY:11,STRIKEOUT:12,STAMP:13,CARET:14,INK:15,POPUP:16,FILEATTACHMENT:17,WIDGET:20},rl={SOLID:1,DASHED:2,BEVELED:3,INSET:4,UNDERLINE:5},od={ERRORS:0,WARNINGS:1,INFOS:5},ii={dependency:1,setLineWidth:2,setLineCap:3,setLineJoin:4,setMiterLimit:5,setDash:6,setRenderingIntent:7,setFlatness:8,setGState:9,save:10,restore:11,transform:12,moveTo:13,lineTo:14,curveTo:15,curveTo2:16,curveTo3:17,closePath:18,rectangle:19,stroke:20,closeStroke:21,fill:22,eoFill:23,fillStroke:24,eoFillStroke:25,closeFillStroke:26,closeEOFillStroke:27,endPath:28,clip:29,eoClip:30,beginText:31,endText:32,setCharSpacing:33,setWordSpacing:34,setHScale:35,setLeading:36,setFont:37,setTextRenderingMode:38,setTextRise:39,moveText:40,setLeadingMoveText:41,setTextMatrix:42,nextLine:43,showText:44,showSpacedText:45,nextLineShowText:46,nextLineSetSpacingShowText:47,setCharWidth:48,setCharWidthAndBounds:49,setStrokeColorSpace:50,setFillColorSpace:51,setStrokeColor:52,setStrokeColorN:53,setFillColor:54,setFillColorN:55,setStrokeGray:56,setFillGray:57,setStrokeRGBColor:58,setFillRGBColor:59,setStrokeCMYKColor:60,setFillCMYKColor:61,shadingFill:62,beginInlineImage:63,beginImageData:64,endInlineImage:65,paintXObject:66,markPoint:67,markPointProps:68,beginMarkedContent:69,beginMarkedContentProps:70,endMarkedContent:71,beginCompat:72,endCompat:73,paintFormXObjectBegin:74,paintFormXObjectEnd:75,beginGroup:76,endGroup:77,beginAnnotation:80,endAnnotation:81,paintImageMaskXObject:83,paintImageMaskXObjectGroup:84,paintImageXObject:85,paintInlineImageXObject:86,paintInlineImageXObjectGroup:87,paintImageXObjectRepeat:88,paintImageMaskXObjectRepeat:89,paintSolidColorImageMask:90,constructPath:91,setStrokeTransparent:92,setFillTransparent:93},Wx={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};let hd=od.WARNINGS;function Xx(o){Number.isInteger(o)&&(hd=o)}function Ux(){return hd}function ld(o){hd>=od.INFOS&&console.log(`Info: ${o}`)}function rt(o){hd>=od.WARNINGS&&console.log(`Warning: ${o}`)}function Pt(o){throw new Error(o)}function ne(o,t){o||Pt(t)}function Yx(o){switch(o==null?void 0:o.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}function $x(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=Zx(o)}catch{}}const s=t?new URL(o,t):new URL(o);if(Yx(s))return s}catch{}return null}function lt(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 Av extends $n{constructor(t,e){super(t,"PasswordException"),this.code=e}}class Pg extends $n{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}}class Mg extends $n{constructor(t){super(t,"InvalidPDFException")}}class al extends $n{constructor(t){super(t,"MissingPDFException")}}class cd extends $n{constructor(t,e){super(t,"UnexpectedResponseException"),this.status=e}}class qx extends $n{constructor(t){super(t,"FormatError")}}class qn extends $n{constructor(t){super(t,"AbortException")}}function Tv(o){(typeof o!="object"||(o==null?void 0:o.length)===void 0)&&Pt("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"&&Pt("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 Kx(o){return String.fromCharCode(o>>24&255,o>>16&255,o>>8&255,o&255)}function Og(o){const t=Object.create(null);for(const[e,s]of o)t[e]=s;return t}function Jx(){const o=new Uint8Array(4);return o[0]=1,new Uint32Array(o.buffer,0,1)[0]===1}function Qx(){try{return new Function(""),!0}catch{return!1}}class Ue{static get isLittleEndian(){return lt(this,"isLittleEndian",Jx())}static get isEvalSupported(){return lt(this,"isEvalSupported",Qx())}static get isOffscreenCanvasSupported(){return lt(this,"isOffscreenCanvasSupported",typeof OffscreenCanvas<"u")}static get isImageDecoderSupported(){return lt(this,"isImageDecoderSupported",typeof ImageDecoder<"u")}static get platform(){return typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.platform)=="string"?lt(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")}):lt(this,"platform",{isMac:!1,isWindows:!1,isFirefox:!1})}static get isCSSRoundSupported(){var t,e;return lt(this,"isCSSRoundSupported",(e=(t=globalThis.CSS)==null?void 0:t.supports)==null?void 0:e.call(t,"width: round(1.5px, 1px)"))}}const Dg=Array.from(Array(256).keys(),o=>o.toString(16).padStart(2,"0"));class q{static makeHexColor(t,e,s){return`#${Dg[t]}${Dg[e]}${Dg[s]}`}static scaleMinMax(t,e){let s;t[0]?(t[0]<0&&(s=e[0],e[0]=e[2],e[2]=s),e[0]*=t[0],e[2]*=t[0],t[3]<0&&(s=e[1],e[1]=e[3],e[3]=s),e[1]*=t[3],e[3]*=t[3]):(s=e[0],e[0]=e[1],e[1]=s,s=e[2],e[2]=e[3],e[3]=s,t[1]<0&&(s=e[1],e[1]=e[3],e[3]=s),e[1]*=t[1],e[3]*=t[1],t[2]<0&&(s=e[0],e[0]=e[2],e[2]=s),e[0]*=t[2],e[2]*=t[2]),e[0]+=t[4],e[1]+=t[5],e[2]+=t[4],e[3]+=t[5]}static transform(t,e){return[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],t[0]*e[4]+t[2]*e[5]+t[4],t[1]*e[4]+t[3]*e[5]+t[5]]}static applyTransform(t,e){const s=t[0]*e[0]+t[1]*e[2]+e[4],i=t[0]*e[1]+t[1]*e[3]+e[5];return[s,i]}static applyInverseTransform(t,e){const s=e[0]*e[3]-e[1]*e[2],i=(t[0]*e[3]-t[1]*e[2]+e[2]*e[5]-e[4]*e[3])/s,n=(-t[0]*e[1]+t[1]*e[0]+e[4]*e[1]-e[5]*e[0])/s;return[i,n]}static getAxialAlignedBoundingBox(t,e){const s=this.applyTransform(t,e),i=this.applyTransform(t.slice(2,4),e),n=this.applyTransform([t[0],t[3]],e),r=this.applyTransform([t[2],t[1]],e);return[Math.min(s[0],i[0],n[0],r[0]),Math.min(s[1],i[1],n[1],r[1]),Math.max(s[0],i[0],n[0],r[0]),Math.max(s[1],i[1],n[1],r[1])]}static inverseTransform(t){const e=t[0]*t[3]-t[1]*t[2];return[t[3]/e,-t[1]/e,-t[2]/e,t[0]/e,(t[2]*t[5]-t[4]*t[3])/e,(t[4]*t[1]-t[5]*t[0])/e]}static singularValueDecompose2dScale(t){const e=[t[0],t[2],t[1],t[3]],s=t[0]*e[0]+t[1]*e[2],i=t[0]*e[1]+t[1]*e[3],n=t[2]*e[0]+t[3]*e[2],r=t[2]*e[1]+t[3]*e[3],a=(s+r)/2,h=Math.sqrt((s+r)**2-4*(s*r-n*i))/2,c=a+h||1,u=a-h||1;return[Math.sqrt(c),Math.sqrt(u)]}static normalizeRect(t){const e=t.slice(0);return t[0]>t[2]&&(e[0]=t[2],e[2]=t[0]),t[1]>t[3]&&(e[1]=t[3],e[3]=t[1]),e}static intersect(t,e){const s=Math.max(Math.min(t[0],t[2]),Math.min(e[0],e[2])),i=Math.min(Math.max(t[0],t[2]),Math.max(e[0],e[2]));if(s>i)return null;const n=Math.max(Math.min(t[1],t[3]),Math.min(e[1],e[3])),r=Math.min(Math.max(t[1],t[3]),Math.max(e[1],e[3]));return n>r?null:[s,n,i,r]}static bezierBoundingBox(t,e,s,i,n,r,a,h,c){return c?(c[0]=Math.min(c[0],t,a),c[1]=Math.min(c[1],e,h),c[2]=Math.max(c[2],t,a),c[3]=Math.max(c[3],e,h)):c=[Math.min(t,a),Math.min(e,h),Math.max(t,a),Math.max(e,h)],w(this,an,Sp).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,Sp).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,Kd=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,v=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],v),u[2]=Math.max(u[2],p),u[3]=Math.max(u[3],v)},Sp=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,Kd).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),v=2*c;w(this,an,Kd).call(this,t,e,s,i,n,r,a,h,(-u+p)/v,f),w(this,an,Kd).call(this,t,e,s,i,n,r,a,h,(-u-p)/v,f)},y(q,an);function Zx(o){return decodeURIComponent(escape(o))}let Rg=null,Ev=null;function tS(o){return Rg||(Rg=/([\u00a0\u00b5\u037e\u0eb3\u2000-\u200a\u202f\u2126\ufb00-\ufb04\ufb06\ufb20-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufba1\ufba4-\ufba9\ufbae-\ufbb1\ufbd3-\ufbdc\ufbde-\ufbe7\ufbea-\ufbf8\ufbfc-\ufbfd\ufc00-\ufc5d\ufc64-\ufcf1\ufcf5-\ufd3d\ufd88\ufdf4\ufdfa-\ufdfb\ufe71\ufe77\ufe79\ufe7b\ufe7d]+)|(\ufb05+)/gu,Ev=new Map([["ſt","ſt"]])),o.replaceAll(Rg,(t,e,s)=>e?e.normalize("NFKC"):Ev.get(s))}function eS(){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();const o=new Uint8Array(32);return crypto.getRandomValues(o),Tv(o)}const Lg="pdfjs_internal_id_";function sS(o){return Uint8Array.prototype.toBase64?o.toBase64():btoa(Tv(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(hl(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 ol{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,v,_,b;u===0?(p=Math.abs(c-t[1])*s+n,v=Math.abs(h-t[0])*s+r,_=(t[3]-t[1])*s,b=(t[2]-t[0])*s):(p=Math.abs(h-t[0])*s+n,v=Math.abs(c-t[1])*s+r,_=(t[2]-t[0])*s,b=(t[3]-t[1])*s),this.transform=[u*s,d*s,f*s,g*s,p-u*s*h-f*s*c,v-d*s*h-g*s*c],this.width=_,this.height=b}get rawDims(){const{userUnit:t,viewBox:e}=this,s=e.map(i=>i*t);return lt(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 ol({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 Fg 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 Ig(o){return typeof o=="string"&&/\.pdf$/i.test(o)}function iS(o){return[o]=o.split(/[#?]/,1),o.substring(o.lastIndexOf("/")+1)}function nS(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 kv{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 hl(o,t){try{const{protocol:e}=t?new URL(o,t):new URL(o);return e==="http:"||e==="https:"}catch{return!1}}function ni(o){o.preventDefault()}function ms(o){o.preventDefault(),o.stopPropagation()}class jg{static toDateObject(t){if(!t||typeof t!="string")return null;l(this,vl)||m(this,vl,new RegExp("^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+|-])?(\\d{2})?'?(\\d{2})?'?"));const e=l(this,vl).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))}}vl=new WeakMap,y(jg,vl);function rS(o,{scale:t=1,rotation:e=0}){const{width:s,height:i}=o.attributes.style,n=[0,0,parseInt(s),parseInt(i)];return new ol({viewBox:n,userUnit:1,scale:t,rotation:e})}function Ng(o){if(o.startsWith("#")){const t=parseInt(o.slice(1),16);return[(t&16711680)>>16,(t&65280)>>8,t&255]}return o.startsWith("rgb(")?o.slice(4,-1).split(",").map(t=>parseInt(t)):o.startsWith("rgba(")?o.slice(5,-1).split(",").map(t=>parseInt(t)).slice(0,3):(rt(`Not a valid color format: "${o}"`),[0,0,0])}function aS(o){const t=document.createElement("span");t.style.visibility="hidden",document.body.append(t);for(const e of o.keys()){t.style.color=e;const s=window.getComputedStyle(t).color;o.set(e,Ng(s))}t.remove()}function Nt(o){const{a:t,b:e,c:s,d:i,e:n,f:r}=o.getTransform();return[t,e,s,i,n,r]}function Ti(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 Wr(o,t,e=!1,s=!0){if(t instanceof ol){const{pageWidth:i,pageHeight:n}=t.rawDims,{style:r}=o,a=Ue.isCSSRoundSupported,h=`var(--scale-factor) * ${i}px`,c=`var(--scale-factor) * ${n}px`,u=a?`round(down, ${h}, var(--scale-round-x, 1px))`:`calc(${h})`,d=a?`round(down, ${c}, var(--scale-round-y, 1px))`:`calc(${c})`;!e||t.rotation%180===0?(r.width=u,r.height=d):(r.width=d,r.height=u)}s&&o.setAttribute("data-main-rotation",t.rotation)}class Bg{constructor(){const t=window.devicePixelRatio||1;this.sx=t,this.sy=t}get scaled(){return this.sx!==1||this.sy!==1}get symmetric(){return this.sx===this.sy}}const on=class on{constructor(t){y(this,Ye);y(this,Qn,null);y(this,qr,null);y(this,ri);y(this,Kr,null);y(this,bl,null);m(this,ri,t),l(on,yl)||m(on,yl,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,ri)._uiManager._signal;t.addEventListener("contextmenu",ni,{signal:e}),t.addEventListener("pointerdown",w(on,Ed,Hb),{signal:e});const s=m(this,Kr,document.createElement("div"));s.className="buttons",t.append(s);const i=l(this,ri).toolbarPosition;if(i){const{style:n}=t,r=l(this,ri)._uiManager.direction==="ltr"?1-i[0]:i[0];n.insetInlineEnd=`${100*r}%`,n.top=`calc(${100*i[1]}% + var(--editor-toolbar-vert-offset))`}return w(this,Ye,Vb).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,bl))==null||t.shown()}async addAltText(t){const e=await t.render();w(this,Ye,Jd).call(this,e),l(this,Kr).prepend(e,l(this,Ye,Cp)),m(this,bl,t)}addColorPicker(t){m(this,qr,t);const e=t.renderButton();w(this,Ye,Jd).call(this,e),l(this,Kr).prepend(e,l(this,Ye,Cp))}remove(){var t;l(this,Qn).remove(),(t=l(this,qr))==null||t.destroy(),m(this,qr,null)}};Qn=new WeakMap,qr=new WeakMap,ri=new WeakMap,Kr=new WeakMap,bl=new WeakMap,yl=new WeakMap,Ed=new WeakSet,Hb=function(t){t.stopPropagation()},Ye=new WeakSet,zb=function(t){l(this,ri)._focusEventsAllowed=!1,ms(t)},Gb=function(t){l(this,ri)._focusEventsAllowed=!0,ms(t)},Jd=function(t){const e=l(this,ri)._uiManager._signal;t.addEventListener("focusin",w(this,Ye,zb).bind(this),{capture:!0,signal:e}),t.addEventListener("focusout",w(this,Ye,Gb).bind(this),{capture:!0,signal:e}),t.addEventListener("contextmenu",ni,{signal:e})},Vb=function(){const{editorType:t,_uiManager:e}=l(this,ri),s=document.createElement("button");s.className="delete",s.tabIndex=0,s.setAttribute("data-l10n-id",l(on,yl)[t]),w(this,Ye,Jd).call(this,s),s.addEventListener("click",i=>{e.delete()},{signal:e._signal}),l(this,Kr).append(s)},Cp=function(){const t=document.createElement("div");return t.className="divider",t},y(on,Ed),y(on,yl,null);let Hg=on;class oS{constructor(t){y(this,Zn);y(this,_l,null);y(this,Jr,null);y(this,Qr);m(this,Qr,t)}show(t,e,s){const[i,n]=w(this,Zn,Xb).call(this,e,s),{style:r}=l(this,Jr)||m(this,Jr,w(this,Zn,Wb).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()}}_l=new WeakMap,Jr=new WeakMap,Qr=new WeakMap,Zn=new WeakSet,Wb=function(){const t=m(this,Jr,document.createElement("div"));t.className="editToolbar",t.setAttribute("role","toolbar"),t.addEventListener("contextmenu",ni,{signal:l(this,Qr)._signal});const e=m(this,_l,document.createElement("div"));return e.className="buttons",t.append(e),w(this,Zn,Ub).call(this),t},Xb=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]},Ub=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",ni,{signal:s}),t.addEventListener("click",()=>{l(this,Qr).highlightSelection("floating_button")},{signal:s}),l(this,_l).append(t)};function gd(o,t,e){for(const s of e)t.addEventListener(s,o[s].bind(o))}class hS{constructor(){y(this,kd,0)}get id(){return`${Gx}${ts(this,kd)._++}`}}kd=new WeakMap;const up=class up{constructor(){y(this,To);y(this,Ao,eS());y(this,wl,0);y(this,Re,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 lt(this,"_isSVGFittingCanvas",n)}async getFromFile(t){const{lastModified:e,name:s,size:i,type:n}=t;return w(this,To,Qd).call(this,`${e}_${s}_${i}_${n}`,t)}async getFromUrl(t){return w(this,To,Qd).call(this,t,t)}async getFromBlob(t,e){const s=await e;return w(this,To,Qd).call(this,t,s)}async getFromId(t){l(this,Re)||m(this,Re,new Map);const e=l(this,Re).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,Re)||m(this,Re,new Map);let s=l(this,Re).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)}_${ts(this,wl)._++}`,refCounter:1,isSvg:!1},l(this,Re).set(t,s),l(this,Re).set(s.id,s),s}getSvgUrl(t){const e=l(this,Re).get(t);return e!=null&&e.isSvg?e.svgUrl:null}deleteId(t){var i;l(this,Re)||m(this,Re,new Map);const e=l(this,Re).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,wl=new WeakMap,Re=new WeakMap,To=new WeakSet,Qd=async function(t,e){l(this,Re)||m(this,Re,new Map);let s=l(this,Re).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)}_${ts(this,wl)._++}`,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=up._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,Re).set(t,s),s&&l(this,Re).set(s.id,s),s};let zg=up;class lS{constructor(t=128){y(this,Zt,[]);y(this,tr,!1);y(this,xl);y(this,Wt,-1);m(this,xl,t)}add({cmd:t,undo:e,post:s,mustExec:i,type:n=NaN,overwriteIfSameType:r=!1,keepUndo:a=!1}){if(i&&t(),l(this,tr))return;const h={cmd:t,undo:e,post:s,type:n};if(l(this,Wt)===-1){l(this,Zt).length>0&&(l(this,Zt).length=0),m(this,Wt,0),l(this,Zt).push(h);return}if(r&&l(this,Zt)[l(this,Wt)].type===n){a&&(h.undo=l(this,Zt)[l(this,Wt)].undo),l(this,Zt)[l(this,Wt)]=h;return}const c=l(this,Wt)+1;c===l(this,xl)?l(this,Zt).splice(0,1):(m(this,Wt,c),c<l(this,Zt).length&&l(this,Zt).splice(c)),l(this,Zt).push(h)}undo(){if(l(this,Wt)===-1)return;m(this,tr,!0);const{undo:t,post:e}=l(this,Zt)[l(this,Wt)];t(),e==null||e(),m(this,tr,!1),m(this,Wt,l(this,Wt)-1)}redo(){if(l(this,Wt)<l(this,Zt).length-1){m(this,Wt,l(this,Wt)+1),m(this,tr,!0);const{cmd:t,post:e}=l(this,Zt)[l(this,Wt)];t(),e==null||e(),m(this,tr,!1)}}hasSomethingToUndo(){return l(this,Wt)!==-1}hasSomethingToRedo(){return l(this,Wt)<l(this,Zt).length-1}cleanType(t){if(l(this,Wt)!==-1){for(let e=l(this,Wt);e>=0;e--)if(l(this,Zt)[e].type!==t){l(this,Zt).splice(e+1,l(this,Wt)-e),m(this,Wt,e);return}l(this,Zt).length=0,m(this,Wt,-1)}}destroy(){m(this,Zt,null)}}Zt=new WeakMap,tr=new WeakMap,xl=new WeakMap,Wt=new WeakMap;class ll{constructor(t){y(this,Pd);this.buffer=[],this.callbacks=new Map,this.allKeys=new Set;const{isMac:e}=Ue.platform;for(const[s,i,n={}]of t)for(const r of s){const a=r.startsWith("mac+");e&&a?(this.callbacks.set(r.slice(4),{callback:i,options:n}),this.allKeys.add(r.split("+").at(-1))):!e&&!a&&(this.callbacks.set(r,{callback:i,options:n}),this.allKeys.add(r.split("+").at(-1)))}}exec(t,e){if(!this.allKeys.has(e.key))return;const s=this.callbacks.get(w(this,Pd,Yb).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||ms(e))}}Pd=new WeakSet,Yb=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 aS(t),lt(this,"_colors",t)}convert(t){const e=Ng(t);if(!window.matchMedia("(forced-colors: active)").matches)return e;for(const[s,i]of this._colors)if(i.every((n,r)=>n===e[r]))return 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 Gg=Md;const Ro=class Ro{constructor(t,e,s,i,n,r,a,h,c,u,d,f,g){y(this,N);y(this,Eo,new AbortController);y(this,vs,null);y(this,ce,new Map);y(this,_e,new Map);y(this,ko,null);y(this,hn,null);y(this,Po,null);y(this,js,new lS);y(this,er,null);y(this,Zr,null);y(this,Mo,0);y(this,ta,new Set);y(this,ki,null);y(this,ai,null);y(this,ea,new Set);J(this,"_editorUndoBar",null);y(this,Sl,!1);y(this,Cl,!1);y(this,Oo,!1);y(this,Al,null);y(this,Pi,null);y(this,sr,null);y(this,Do,null);y(this,ir,!1);y(this,Mi,null);y(this,Od,new hS);y(this,nr,!1);y(this,Tl,!1);y(this,rr,null);y(this,sa,null);y(this,El,null);y(this,kl,null);y(this,ge,nt.NONE);y(this,Ct,new Set);y(this,ln,null);y(this,ia,null);y(this,Pl,null);y(this,Ml,{isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1});y(this,ar,[0,0]);y(this,Oi,null);y(this,cn,null);y(this,Ol,null);y(this,Ns,null);const p=this._signal=l(this,Eo).signal;m(this,cn,t),m(this,Ol,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",v=>this.updateParams(v.type,v.value),{signal:p}),w(this,N,Kb).call(this),w(this,N,ty).call(this),w(this,N,Tp).call(this),m(this,hn,n.annotationStorage),m(this,Al,n.filterFactory),m(this,ia,r),m(this,Do,a||null),m(this,Sl,h),m(this,Cl,c),m(this,Oo,u),m(this,kl,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 lt(this,"_keyboardManager",new ll([[["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,Ns))==null||t.resolve(),m(this,Ns,null),(e=l(this,Eo))==null||e.abort(),m(this,Eo,null),this._signal=null;for(const r of l(this,_e).values())r.destroy();l(this,_e).clear(),l(this,ce).clear(),l(this,ea).clear(),m(this,vs,null),l(this,Ct).clear(),l(this,js).destroy(),(s=l(this,ko))==null||s.destroy(),(i=l(this,Mi))==null||i.hide(),m(this,Mi,null),l(this,Pi)&&(clearTimeout(l(this,Pi)),m(this,Pi,null)),l(this,Oi)&&(clearTimeout(l(this,Oi)),m(this,Oi,null)),(n=this._editorUndoBar)==null||n.destroy()}combinedSignal(t){return AbortSignal.any([this._signal,t.signal])}get mlManager(){return l(this,kl)}get useNewAltTextFlow(){return l(this,Cl)}get useNewAltTextWhenAddingImage(){return l(this,Oo)}get hcmFilter(){return lt(this,"hcmFilter",l(this,ia)?l(this,Al).addHCMFilter(l(this,ia).foreground,l(this,ia).background):"none")}get direction(){return lt(this,"direction",getComputedStyle(l(this,cn)).direction)}get highlightColors(){return lt(this,"highlightColors",l(this,Do)?new Map(l(this,Do).split(",").map(t=>t.split("=").map(e=>e.trim()))):null)}get highlightColorNames(){return lt(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,El,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,_e).values()){const{x:i,y:n,width:r,height:a}=s.div.getBoundingClientRect();if(t>=i&&t<=i+r&&e>=n&&e<=n+a)return s}return null}disableUserSelect(t=!1){l(this,Ol).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,N,Zd).call(this,e).closest(".textLayer"),u=this.getSelectionBoxes(c);if(!u)return;e.empty();const d=w(this,N,Ap).call(this,c),f=l(this,ge)===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,N,tf).call(this,"main_toolbar")),!this.hasSelection)return;const{activeElement:t}=document;for(const e of l(this,Ct))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,N,Tp).call(this),w(this,N,Ep).call(this)}removeEditListeners(){w(this,N,Zb).call(this),w(this,N,kp).call(this)}dragOver(t){for(const{type:e}of t.dataTransfer.items)for(const s of l(this,ai))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,ai))if(s.isHandlingMimeForPasting(e.type)){s.paste(e,this.currentLayer),t.preventDefault();return}}copy(t){var s;if(t.preventDefault(),(s=l(this,vs))==null||s.commitOrRemove(),!this.hasSelection)return;const e=[];for(const i of l(this,Ct)){const n=i.serialize(!0);n&&e.push(n)}e.length!==0&&t.clipboardData.setData("application/pdfjs",JSON.stringify(e))}cut(t){this.copy(t),this.delete()}async paste(t){t.preventDefault();const{clipboardData:e}=t;for(const n of e.items)for(const r of l(this,ai))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,N,Pp).call(this,h);w(this,N,Mp).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,ge)!==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,N,tf).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,N,Jb).call(this),w(this,N,Ep).call(this),w(this,N,es).call(this,{isEditing:l(this,ge)!==nt.NONE,isEmpty:w(this,N,Xc).call(this),hasSomethingToUndo:l(this,js).hasSomethingToUndo(),hasSomethingToRedo:l(this,js).hasSomethingToRedo(),hasSelectedEditor:!1})):(w(this,N,Qb).call(this),w(this,N,kp).call(this),w(this,N,es).call(this,{isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(t){if(!l(this,ai)){m(this,ai,t);for(const e of l(this,ai))w(this,N,jn).call(this,e.defaultPropertiesToUpdate)}}getId(){return l(this,Od).id}get currentLayer(){return l(this,_e).get(l(this,Mo))}getLayer(t){return l(this,_e).get(t)}get currentPageIndex(){return l(this,Mo)}addLayer(t){l(this,_e).set(t.pageIndex,t),l(this,nr)?t.enable():t.disable()}removeLayer(t){l(this,_e).delete(t.pageIndex)}async updateMode(t,e=null,s=!1){var i;if(l(this,ge)!==t&&!(l(this,Ns)&&(await l(this,Ns).promise,!l(this,Ns)))){if(m(this,Ns,Promise.withResolvers()),m(this,ge,t),t===nt.NONE){this.setEditingState(!1),w(this,N,sy).call(this),(i=this._editorUndoBar)==null||i.hide(),l(this,Ns).resolve();return}this.setEditingState(!0),await w(this,N,ey).call(this),this.unselectAll();for(const n of l(this,_e).values())n.updateMode(t);if(!e){s&&this.addNewEditorFromKeyboard(),l(this,Ns).resolve();return}for(const n of l(this,ce).values())n.annotationElementId===e?(this.setSelected(n),n.enterInEditMode()):n.unselect();l(this,Ns).resolve()}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(t){t!==l(this,ge)&&this._eventBus.dispatch("switchannotationeditormode",{source:this,mode:t})}updateParams(t,e){var s;if(l(this,ai)){switch(t){case pt.CREATE:this.currentLayer.addNewEditor();return;case pt.HIGHLIGHT_DEFAULT_COLOR:(s=l(this,El))==null||s.updateColor(e);break;case pt.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:{type:"highlight",action:"toggle_visibility"}}}),(l(this,Pl)||m(this,Pl,new Map)).set(t,e),this.showAllEditors("highlight",e);break}for(const i of l(this,Ct))i.updateParams(t,e);for(const i of l(this,ai))i.updateDefaultParams(t,e)}}showAllEditors(t,e,s=!1){var n;for(const r of l(this,ce).values())r.editorType===t&&r.show(e);(((n=l(this,Pl))==null?void 0:n.get(pt.HIGHLIGHT_SHOW_ALL))??!0)!==e&&w(this,N,jn).call(this,[[pt.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(l(this,Tl)!==t){m(this,Tl,t);for(const e of l(this,_e).values())t?e.disableClick():e.enableClick(),e.div.classList.toggle("waiting",t)}}getEditors(t){const e=[];for(const s of l(this,ce).values())s.pageIndex===t&&e.push(s);return e}getEditor(t){return l(this,ce).get(t)}addEditor(t){l(this,ce).set(t.id,t)}removeEditor(t){var e;t.div.contains(document.activeElement)&&(l(this,Pi)&&clearTimeout(l(this,Pi)),m(this,Pi,setTimeout(()=>{this.focusMainContainer(),m(this,Pi,null)},0))),l(this,ce).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,vs)!==t&&(m(this,vs,t),t&&w(this,N,jn).call(this,t.propertiesToUpdate))}updateUI(t){l(this,N,iy)===t&&w(this,N,jn).call(this,t.propertiesToUpdate)}updateUIForDefaultProperties(t){w(this,N,jn).call(this,t.defaultPropertiesToUpdate)}toggleSelected(t){if(l(this,Ct).has(t)){l(this,Ct).delete(t),t.unselect(),w(this,N,es).call(this,{hasSelectedEditor:this.hasSelection});return}l(this,Ct).add(t),t.select(),w(this,N,jn).call(this,t.propertiesToUpdate),w(this,N,es).call(this,{hasSelectedEditor:!0})}setSelected(t){var e;(e=l(this,Zr))==null||e.commitOrRemove();for(const s of l(this,Ct))s!==t&&s.unselect();l(this,Ct).clear(),l(this,Ct).add(t),t.select(),w(this,N,jn).call(this,t.propertiesToUpdate),w(this,N,es).call(this,{hasSelectedEditor:!0})}isSelected(t){return l(this,Ct).has(t)}get firstSelectedEditor(){return l(this,Ct).values().next().value}unselect(t){t.unselect(),l(this,Ct).delete(t),w(this,N,es).call(this,{hasSelectedEditor:this.hasSelection})}get hasSelection(){return l(this,Ct).size!==0}get isEnterHandled(){return l(this,Ct).size===1&&this.firstSelectedEditor.isEnterHandled}undo(){var t;l(this,js).undo(),w(this,N,es).call(this,{hasSomethingToUndo:l(this,js).hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:w(this,N,Xc).call(this)}),(t=this._editorUndoBar)==null||t.hide()}redo(){l(this,js).redo(),w(this,N,es).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:l(this,js).hasSomethingToRedo(),isEmpty:w(this,N,Xc).call(this)})}addCommands(t){l(this,js).add(t),w(this,N,es).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:w(this,N,Xc).call(this)})}cleanUndoStack(t){l(this,js).cleanType(t)}delete(){var n;this.commitOrRemove();const t=(n=this.currentLayer)==null?void 0:n.endDrawingSession(!0);if(!this.hasSelection&&!t)return;const e=t?[t]:[...l(this,Ct)],s=()=>{var r;(r=this._editorUndoBar)==null||r.show(i,e.length===1?e[0].editorType:e.length);for(const a of e)a.remove()},i=()=>{for(const r of e)w(this,N,Pp).call(this,r)};this.addCommands({cmd:s,undo:i,mustExec:!0})}commitOrRemove(){var t;(t=l(this,vs))==null||t.commitOrRemove()}hasSomethingToControl(){return l(this,vs)||this.hasSelection}selectAll(){for(const t of l(this,Ct))t.commit();w(this,N,Mp).call(this,l(this,ce).values())}unselectAll(){var t;if(!(l(this,vs)&&(l(this,vs).commitOrRemove(),l(this,ge)!==nt.NONE))&&!((t=l(this,Zr))!=null&&t.commitOrRemove())&&this.hasSelection){for(const e of l(this,Ct))e.unselect();l(this,Ct).clear(),w(this,N,es).call(this,{hasSelectedEditor:!1})}}translateSelectedEditors(t,e,s=!1){if(s||this.commitOrRemove(),!this.hasSelection)return;l(this,ar)[0]+=t,l(this,ar)[1]+=e;const[i,n]=l(this,ar),r=[...l(this,Ct)],a=1e3;l(this,Oi)&&clearTimeout(l(this,Oi)),m(this,Oi,setTimeout(()=>{m(this,Oi,null),l(this,ar)[0]=l(this,ar)[1]=0,this.addCommands({cmd:()=>{for(const h of r)l(this,ce).has(h.id)&&h.translateInPage(i,n)},undo:()=>{for(const h of r)l(this,ce).has(h.id)&&h.translateInPage(-i,-n)},mustExec:!1})},a));for(const h of r)h.translateInPage(t,e)}setUpDragSession(){if(this.hasSelection){this.disableUserSelect(!0),m(this,ki,new Map);for(const t of l(this,Ct))l(this,ki).set(t,{savedX:t.x,savedY:t.y,savedPageIndex:t.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!l(this,ki))return!1;this.disableUserSelect(!1);const t=l(this,ki);m(this,ki,null);let e=!1;for(const[{x:i,y:n,pageIndex:r},a]of t)a.newX=i,a.newY=n,a.newPageIndex=r,e||(e=i!==a.savedX||n!==a.savedY||r!==a.savedPageIndex);if(!e)return!1;const s=(i,n,r,a)=>{if(l(this,ce).has(i.id)){const h=l(this,_e).get(a);h?i._setParentAndPosition(h,n,r):(i.pageIndex=a,i.x=n,i.y=r)}};return this.addCommands({cmd:()=>{for(const[i,{newX:n,newY:r,newPageIndex:a}]of t)s(i,n,r,a)},undo:()=>{for(const[i,{savedX:n,savedY:r,savedPageIndex:a}]of t)s(i,n,r,a)},mustExec:!0}),!0}dragSelectedEditors(t,e){if(l(this,ki))for(const s of l(this,ki).keys())s.drag(t,e)}rebuild(t){if(t.parent===null){const e=this.getLayer(t.pageIndex);e?(e.changeParent(t),e.addOrRebuild(t)):(this.addEditor(t),this.addToAnnotationStorage(t),t.rebuild())}else t.parent.addOrRebuild(t)}get isEditorHandlingKeyboard(){var t;return((t=this.getActive())==null?void 0:t.shouldGetKeyboardEvents())||l(this,Ct).size===1&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(t){return l(this,vs)===t}getActive(){return l(this,vs)}getMode(){return l(this,ge)}get imageManager(){return lt(this,"imageManager",new zg)}getSelectionBoxes(t){if(!t)return null;const e=document.getSelection();for(let c=0,u=e.rangeCount;c<u;c++)if(!t.contains(e.getRangeAt(c).commonAncestorContainer))return null;const{x:s,y:i,width:n,height:r}=t.getBoundingClientRect();let a;switch(t.getAttribute("data-main-rotation")){case"90":a=(c,u,d,f)=>({x:(u-i)/r,y:1-(c+d-s)/n,width:f/r,height:d/n});break;case"180":a=(c,u,d,f)=>({x:1-(c+d-s)/n,y:1-(u+f-i)/r,width:d/n,height:f/r});break;case"270":a=(c,u,d,f)=>({x:1-(u+f-i)/r,y:(c-s)/n,width:f/r,height:d/n});break;default:a=(c,u,d,f)=>({x:(c-s)/n,y:(u-i)/r,width:d/n,height:f/r});break}const h=[];for(let c=0,u=e.rangeCount;c<u;c++){const d=e.getRangeAt(c);if(!d.collapsed)for(const{x:f,y:g,width:p,height:v}of d.getClientRects())p===0||v===0||h.push(a(f,g,p,v))}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,ge)===nt.NONE&&!s.hasBeenModified||s.renderAnnotationElement(t))}};Eo=new WeakMap,vs=new WeakMap,ce=new WeakMap,_e=new WeakMap,ko=new WeakMap,hn=new WeakMap,Po=new WeakMap,js=new WeakMap,er=new WeakMap,Zr=new WeakMap,Mo=new WeakMap,ta=new WeakMap,ki=new WeakMap,ai=new WeakMap,ea=new WeakMap,Sl=new WeakMap,Cl=new WeakMap,Oo=new WeakMap,Al=new WeakMap,Pi=new WeakMap,sr=new WeakMap,Do=new WeakMap,ir=new WeakMap,Mi=new WeakMap,Od=new WeakMap,nr=new WeakMap,Tl=new WeakMap,rr=new WeakMap,sa=new WeakMap,El=new WeakMap,kl=new WeakMap,ge=new WeakMap,Ct=new WeakMap,ln=new WeakMap,ia=new WeakMap,Pl=new WeakMap,Ml=new WeakMap,ar=new WeakMap,Oi=new WeakMap,cn=new WeakMap,Ol=new WeakMap,Ns=new WeakMap,N=new WeakSet,Zd=function({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t},Ap=function(t){const{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(const s of l(this,_e).values())if(s.hasTextLayer(t))return s;return null},$b=function(){const t=document.getSelection();if(!t||t.isCollapsed)return;const s=w(this,N,Zd).call(this,t).closest(".textLayer"),i=this.getSelectionBoxes(s);i&&(l(this,Mi)||m(this,Mi,new oS(this)),l(this,Mi).show(s,i,this.direction==="ltr"))},qb=function(){var n,r,a;const t=document.getSelection();if(!t||t.isCollapsed){l(this,ln)&&((n=l(this,Mi))==null||n.hide(),m(this,ln,null),w(this,N,es).call(this,{hasSelectedText:!1}));return}const{anchorNode:e}=t;if(e===l(this,ln))return;const i=w(this,N,Zd).call(this,t).closest(".textLayer");if(!i){l(this,ln)&&((r=l(this,Mi))==null||r.hide(),m(this,ln,null),w(this,N,es).call(this,{hasSelectedText:!1}));return}if((a=l(this,Mi))==null||a.hide(),m(this,ln,e),w(this,N,es).call(this,{hasSelectedText:!0}),!(l(this,ge)!==nt.HIGHLIGHT&&l(this,ge)!==nt.NONE)&&(l(this,ge)===nt.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0),m(this,ir,this.isShiftKeyDown),!this.isShiftKeyDown)){const h=l(this,ge)===nt.HIGHLIGHT?w(this,N,Ap).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,N,tf).call(this,"main_toolbar"))};window.addEventListener("pointerup",d,{signal:u}),window.addEventListener("blur",d,{signal:u})}},tf=function(t=""){l(this,ge)===nt.HIGHLIGHT?this.highlightSelection(t):l(this,Sl)&&w(this,N,$b).call(this)},Kb=function(){document.addEventListener("selectionchange",w(this,N,qb).bind(this),{signal:this._signal})},Jb=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})},Qb=function(){var t;(t=l(this,sr))==null||t.abort(),m(this,sr,null)},Tp=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})},Zb=function(){var t;(t=l(this,rr))==null||t.abort(),m(this,rr,null)},Ep=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})},kp=function(){var t;(t=l(this,er))==null||t.abort(),m(this,er,null)},ty=function(){const t=this._signal;document.addEventListener("dragover",this.dragOver.bind(this),{signal:t}),document.addEventListener("drop",this.drop.bind(this),{signal:t})},es=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,ge)===nt.HIGHLIGHT&&t.hasSelectedEditor===!1&&w(this,N,jn).call(this,[[pt.HIGHLIGHT_FREE,!0]]))},jn=function(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})},ey=async function(){if(!l(this,nr)){m(this,nr,!0);const t=[];for(const e of l(this,_e).values())t.push(e.enable());await Promise.all(t);for(const e of l(this,ce).values())e.enable()}},sy=function(){if(this.unselectAll(),l(this,nr)){m(this,nr,!1);for(const t of l(this,_e).values())t.disable();for(const t of l(this,ce).values())t.disable()}},Pp=function(t){const e=l(this,_e).get(t.pageIndex);e?e.addOrRebuild(t):(this.addEditor(t),this.addToAnnotationStorage(t))},iy=function(){let t=null;for(t of l(this,Ct));return t},Xc=function(){if(l(this,ce).size===0)return!0;if(l(this,ce).size===1)for(const t of l(this,ce).values())return t.isEmpty();return!1},Mp=function(t){for(const e of l(this,Ct))e.unselect();l(this,Ct).clear();for(const e of t)e.isEmpty()||(l(this,Ct).add(e),e.select());w(this,N,es).call(this,{hasSelectedEditor:this.hasSelection})},J(Ro,"TRANSLATE_SMALL",1),J(Ro,"TRANSLATE_BIG",10);let Xr=Ro;const $e=class $e{constructor(t){y(this,hi);y(this,pe,null);y(this,Di,!1);y(this,oi,null);y(this,Lo,null);y(this,Ri,null);y(this,bs,null);y(this,Fo,!1);y(this,Li,null);y(this,os,null);y(this,un,null);y(this,na,null);y(this,Fi,!1);m(this,os,t),m(this,Fi,t._uiManager.useNewAltTextFlow),l($e,or)||m($e,or,Object.freeze({added:"pdfjs-editor-new-alt-text-added-button","added-label":"pdfjs-editor-new-alt-text-added-button-label",missing:"pdfjs-editor-new-alt-text-missing-button","missing-label":"pdfjs-editor-new-alt-text-missing-button-label",review:"pdfjs-editor-new-alt-text-to-review-button","review-label":"pdfjs-editor-new-alt-text-to-review-button-label"}))}static initialize(t){$e._l10n??($e._l10n=t)}async render(){const t=m(this,oi,document.createElement("button"));t.className="altText",t.tabIndex="0";const e=m(this,Lo,document.createElement("span"));t.append(e),l(this,Fi)?(t.classList.add("new"),t.setAttribute("data-l10n-id",l($e,or).missing),e.setAttribute("data-l10n-id",l($e,or)["missing-label"])):(t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button"),e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button-label"));const s=l(this,os)._uiManager._signal;t.addEventListener("contextmenu",ni,{signal:s}),t.addEventListener("pointerdown",n=>n.stopPropagation(),{signal:s});const i=n=>{n.preventDefault(),l(this,os)._uiManager.editAltText(l(this,os)),l(this,Fi)&&l(this,os)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_clicked",data:{label:l(this,hi,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,hi,ef).call(this),t}finish(){l(this,oi)&&(l(this,oi).focus({focusVisible:l(this,Fo)}),m(this,Fo,!1))}isEmpty(){return l(this,Fi)?l(this,pe)===null:!l(this,pe)&&!l(this,Di)}hasData(){return l(this,Fi)?l(this,pe)!==null||!!l(this,un):this.isEmpty()}get guessedText(){return l(this,un)}async setGuessedText(t){l(this,pe)===null&&(m(this,un,t),m(this,na,await $e._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",{generatedAltText:t})),w(this,hi,ef).call(this))}toggleAltTextBadge(t=!1){var e;if(!l(this,Fi)||l(this,pe)){(e=l(this,Li))==null||e.remove(),m(this,Li,null);return}if(!l(this,Li)){const s=m(this,Li,document.createElement("div"));s.className="noAltTextBadge",l(this,os).div.append(s)}l(this,Li).classList.toggle("hidden",!t)}serialize(t){let e=l(this,pe);return!t&&l(this,un)===e&&(e=l(this,na)),{altText:e,decorative:l(this,Di),guessedText:l(this,un),textWithDisclaimer:l(this,na)}}get data(){return{altText:l(this,pe),decorative:l(this,Di)}}set data({altText:t,decorative:e,guessedText:s,textWithDisclaimer:i,cancel:n=!1}){s&&(m(this,un,s),m(this,na,i)),!(l(this,pe)===t&&l(this,Di)===e)&&(n||(m(this,pe,t),m(this,Di,e)),w(this,hi,ef).call(this))}toggle(t=!1){l(this,oi)&&(!t&&l(this,bs)&&(clearTimeout(l(this,bs)),m(this,bs,null)),l(this,oi).disabled=!t)}shown(){l(this,os)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_displayed",data:{label:l(this,hi,Uc)}})}destroy(){var t,e;(t=l(this,oi))==null||t.remove(),m(this,oi,null),m(this,Lo,null),m(this,Ri,null),(e=l(this,Li))==null||e.remove(),m(this,Li,null)}};pe=new WeakMap,Di=new WeakMap,oi=new WeakMap,Lo=new WeakMap,Ri=new WeakMap,bs=new WeakMap,Fo=new WeakMap,Li=new WeakMap,os=new WeakMap,un=new WeakMap,na=new WeakMap,Fi=new WeakMap,or=new WeakMap,hi=new WeakSet,Uc=function(){return l(this,pe)&&"added"||l(this,pe)===null&&this.guessedText&&"review"||"missing"},ef=async function(){var i,n,r;const t=l(this,oi);if(!t)return;if(l(this,Fi)){if(t.classList.toggle("done",!!l(this,pe)),t.setAttribute("data-l10n-id",l($e,or)[l(this,hi,Uc)]),(i=l(this,Lo))==null||i.setAttribute("data-l10n-id",l($e,or)[`${l(this,hi,Uc)}-label`]),!l(this,pe)){(n=l(this,Ri))==null||n.remove();return}}else{if(!l(this,pe)&&!l(this,Di)){t.classList.remove("done"),(r=l(this,Ri))==null||r.remove();return}t.classList.add("done"),t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-edit-button")}let e=l(this,Ri);if(!e){m(this,Ri,e=document.createElement("span")),e.className="tooltip",e.setAttribute("role","tooltip"),e.id=`alt-text-tooltip-${l(this,os).id}`;const a=100,h=l(this,os)._uiManager._signal;h.addEventListener("abort",()=>{clearTimeout(l(this,bs)),m(this,bs,null)},{once:!0}),t.addEventListener("mouseenter",()=>{m(this,bs,setTimeout(()=>{m(this,bs,null),l(this,Ri).classList.add("show"),l(this,os)._reportTelemetry({action:"alt_text_tooltip"})},a))},{signal:h}),t.addEventListener("mouseleave",()=>{var c;l(this,bs)&&(clearTimeout(l(this,bs)),m(this,bs,null)),(c=l(this,Ri))==null||c.classList.remove("show")},{signal:h})}l(this,Di)?e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-decorative-tooltip"):(e.removeAttribute("data-l10n-id"),e.textContent=l(this,pe)),e.parentNode||t.append(e);const s=l(this,os).getImageForAltText();s==null||s.setAttribute("aria-describedby",e.id)},y($e,or,null),J($e,"_l10n",null);let pd=$e;const dp=class dp{constructor({container:t,isPinchingDisabled:e=null,isPinchingStopped:s=null,onPinchStart:i=null,onPinching:n=null,onPinchEnd:r=null,signal:a}){y(this,fn);y(this,Dl);y(this,ra,!1);y(this,Rl,null);y(this,Ll);y(this,Fl);y(this,Il);y(this,jl);y(this,Io);y(this,dn,null);y(this,aa);y(this,hr,null);m(this,Dl,t),m(this,Rl,s),m(this,Ll,e),m(this,Fl,i),m(this,Il,n),m(this,jl,r),m(this,aa,new AbortController),m(this,Io,AbortSignal.any([a,l(this,aa).signal])),t.addEventListener("touchstart",w(this,fn,ny).bind(this),{passive:!1,signal:l(this,Io)})}get MIN_TOUCH_DISTANCE_TO_PINCH(){return lt(this,"MIN_TOUCH_DISTANCE_TO_PINCH",35/(window.devicePixelRatio||1))}destroy(){var t;(t=l(this,aa))==null||t.abort(),m(this,aa,null)}};Dl=new WeakMap,ra=new WeakMap,Rl=new WeakMap,Ll=new WeakMap,Fl=new WeakMap,Il=new WeakMap,jl=new WeakMap,Io=new WeakMap,dn=new WeakMap,aa=new WeakMap,hr=new WeakMap,fn=new WeakSet,ny=function(t){var i,n,r;if((i=l(this,Ll))!=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,Dl),c={signal:a,passive:!1};h.addEventListener("touchmove",w(this,fn,ry).bind(this),c),h.addEventListener("touchend",w(this,fn,Op).bind(this),c),h.addEventListener("touchcancel",w(this,fn,Op).bind(this),c),(n=l(this,Fl))==null||n.call(this)}if(ms(t),t.touches.length!==2||(r=l(this,Rl))!=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})},ry=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,v=r-i,_=a-n,b=Math.hypot(v,_)||1,x=Math.hypot(g,p)||1;if(!l(this,ra)&&Math.abs(x-b)<=dp.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 S=[(i+r)/2,(n+a)/2];(A=l(this,Il))==null||A.call(this,S,x,b)},Op=function(t){var e;l(this,hr).abort(),m(this,hr,null),(e=l(this,jl))==null||e.call(this),l(this,dn)&&(t.preventDefault(),m(this,dn,null),m(this,ra,!1))};let md=dp;const ot=class ot{constructor(t){y(this,K);y(this,oa,null);y(this,li,null);y(this,Rt,null);y(this,jo,!1);y(this,lr,null);y(this,Nl,"");y(this,ha,!1);y(this,we,null);y(this,la,null);y(this,gn,null);y(this,cr,null);y(this,Bl,"");y(this,ca,!1);y(this,ys,null);y(this,Hl,!1);y(this,ua,!1);y(this,pn,!1);y(this,Ii,null);y(this,No,0);y(this,Bo,0);y(this,Bs,null);y(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);y(this,zl,!1);y(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 lt(this,"_resizerKeyboardManager",new ll([[["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 lt(this,"_defaultLineColor",this._colorManager.getHexCode("CanvasText"))}static deleteAnnotationElement(t){const e=new cS({id:t.parent.getNextId(),parent:t.parent,uiManager:t._uiManager});e.annotationElementId=t.annotationElementId,e.deleted=!0,e._uiManager.addToAnnotationStorage(e)}static initialize(t,e){if(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){Pt("Not implemented")}get propertiesToUpdate(){return[]}get _isDraggable(){return l(this,zl)}set _isDraggable(t){var e;m(this,zl,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,Dp).call(this,this.parentDimensions,t,e)}translateInPage(t,e){l(this,ys)||m(this,ys,[this.x,this.y,this.width,this.height]),w(this,K,Dp).call(this,this.pageDimensions,t,e),this.div.scrollIntoView({block:"nearest"})}drag(t,e){l(this,ys)||m(this,ys,[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,ys)&&(l(this,ys)[0]!==this.x||l(this,ys)[1]!==this.y)}get _hasBeenResized(){return!!l(this,ys)&&(l(this,ys)[2]!==this.width||l(this,ys)[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,Gl,Rp).call(s,t,e,this.parentRotation)}pageTranslationToScreen(t,e){var s;return w(s=ot,Gl,Rp).call(s,t,e,360-this.parentRotation)}get parentScale(){return this._uiManager.viewParameters.realScale}get parentRotation(){return(this._uiManager.viewParameters.rotation+this.pageRotation)%360}get parentDimensions(){const{parentScale:t,pageDimensions:[e,s]}=this;return[e*t,s*t]}setDims(t,e){const[s,i]=this.parentDimensions,{style:n}=this.div;n.width=`${(100*t/s).toFixed(2)}%`,l(this,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 Hg(this),this.div.append(this._editToolbar.render()),l(this,Rt)&&await this._editToolbar.addAltText(l(this,Rt)),this._editToolbar)}removeEditToolbar(){var t;this._editToolbar&&(this._editToolbar.remove(),this._editToolbar=null,(t=l(this,Rt))==null||t.destroy())}addContainer(t){var s;const e=(s=this._editToolbar)==null?void 0:s.div;e?e.before(t):this.div.append(t)}getClientDimensions(){return this.div.getBoundingClientRect()}async addAltTextButton(){l(this,Rt)||(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,jp).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,hy).bind(this),onPinching:w(this,K,ly).bind(this),onPinchEnd:w(this,K,cy).bind(this),signal:this._uiManager._signal}))),(n=this._uiManager._editorUndoBar)==null||n.hide(),this.div}pointerdown(t){const{isMac:e}=Ue.platform;if(t.button!==0||t.ctrlKey&&e){t.preventDefault();return}if(m(this,ca,!0),this._isDraggable){w(this,K,uy).call(this,t);return}w(this,K,Ip).call(this,t)}get isSelected(){return this._uiManager.isSelected(this)}_onStartDragging(){}_onStopDragging(){}moveInDOM(){l(this,Ii)&&clearTimeout(l(this,Ii)),m(this,Ii,setTimeout(()=>{var t;m(this,Ii,null),(t=this.parent)==null||t.moveEditorInDOM(this)},0))}_setParentAndPosition(t,e,s){t.changeParent(this),this.x=e,this.y=s,this.fixAndSetPosition(),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,jp).call(this)}rotate(t){}resize(){}serializeDeleted(){var t;return{id:this.annotationElementId,deleted:!0,pageIndex:this.pageIndex,popupRef:((t=this._initialData)==null?void 0:t.popupRef)||""}}serialize(t=!1,e=null){Pt("An editor must be serializable")}static async deserialize(t,e,s){const i=new this.prototype.constructor({parent:e,id:e.getNextId(),uiManager:s});i.rotation=t.rotation,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,Ii)&&(clearTimeout(l(this,Ii)),m(this,Ii,null)),w(this,K,Yc).call(this),this.removeEditToolbar(),l(this,Bs)){for(const s of l(this,Bs).values())clearTimeout(s);m(this,Bs,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,ay).call(this),l(this,we).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,we).children;if(!l(this,li)){m(this,li,Array.from(e));const r=w(this,K,dy).bind(this),a=w(this,K,fy).bind(this),h=this._uiManager._signal;for(const c of l(this,li)){const u=c.getAttribute("data-resizer-name");c.setAttribute("role","spinbutton"),c.addEventListener("keydown",r,{signal:h}),c.addEventListener("blur",a,{signal:h}),c.addEventListener("focus",w(this,K,gy).bind(this,u),{signal:h}),c.setAttribute("data-l10n-id",ot._l10nResizer[u])}}const s=l(this,li)[0];let i=0;for(const r of e){if(r===s)break;i++}const n=(360-this.rotation+this.parentRotation)%360/90*(l(this,li).length/4);if(n!==i){if(n<i)for(let a=0;a<i-n;a++)l(this,we).append(l(this,we).firstChild);else if(n>i)for(let a=0;a<n-i;a++)l(this,we).firstChild.before(l(this,we).lastChild);let r=0;for(const a of e){const c=l(this,li)[r++].getAttribute("data-resizer-name");a.setAttribute("data-l10n-id",ot._l10nResizer[c])}}w(this,K,Np).call(this,0),m(this,pn,!0),l(this,we).firstChild.focus({focusVisible:!0}),t.preventDefault(),t.stopImmediatePropagation()}_resizeWithKeyboard(t,e){l(this,pn)&&w(this,K,Fp).call(this,l(this,Bl),{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,we))==null||t.classList.add("hidden"),(e=this.div)==null||e.classList.remove("selectedEditor"),(s=this.div)!=null&&s.contains(document.activeElement)&&this._uiManager.currentLayer.div.focus({preventScroll:!0}),(i=this._editToolbar)==null||i.hide(),(n=l(this,Rt))==null||n.toggleAltTextBadge(!0)}updateParams(t,e){}disableEditing(){}enableEditing(){}enterInEditMode(){}getImageForAltText(){return null}get contentDiv(){return this.div}get isEditing(){return l(this,Hl)}set isEditing(t){m(this,Hl,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,Bs)||m(this,Bs,new Map);const{action:s}=t;let i=l(this,Bs).get(s);i&&clearTimeout(i),i=setTimeout(()=>{this._reportTelemetry(t),l(this,Bs).delete(s),l(this,Bs).size===0&&m(this,Bs,null)},ot._telemetryTimeout),l(this,Bs).set(s,i);return}t.type||(t.type=this.editorType),this._uiManager._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:t}})}show(t=this._isVisible){this.div.classList.toggle("hidden",!t),this._isVisible=t}enable(){this.div&&(this.div.tabIndex=0),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,li=new WeakMap,Rt=new WeakMap,jo=new WeakMap,lr=new WeakMap,Nl=new WeakMap,ha=new WeakMap,we=new WeakMap,la=new WeakMap,gn=new WeakMap,cr=new WeakMap,Bl=new WeakMap,ca=new WeakMap,ys=new WeakMap,Hl=new WeakMap,ua=new WeakMap,pn=new WeakMap,Ii=new WeakMap,No=new WeakMap,Bo=new WeakMap,Bs=new WeakMap,da=new WeakMap,zl=new WeakMap,Dd=new WeakMap,K=new WeakSet,Dp=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()},Gl=new WeakSet,Rp=function(t,e,s){switch(s){case 90:return[e,-t];case 180:return[-t,-e];case 270:return[-e,t];default:return[t,e]}},sf=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]}},ay=function(){if(l(this,we))return;m(this,we,document.createElement("div")),l(this,we).classList.add("resizers");const t=this._willKeepAspectRatio?["topLeft","topRight","bottomRight","bottomLeft"]:["topLeft","topMiddle","topRight","middleRight","bottomRight","bottomMiddle","bottomLeft","middleLeft"],e=this._uiManager._signal;for(const s of t){const i=document.createElement("div");l(this,we).append(i),i.classList.add("resizer",s),i.setAttribute("data-resizer-name",s),i.addEventListener("pointerdown",w(this,K,oy).bind(this,s),{signal:e}),i.addEventListener("contextmenu",ni,{signal:e}),i.tabIndex=-1}this.div.prepend(l(this,we))},oy=function(t,e){var u;e.preventDefault();const{isMac:s}=Ue.platform;if(e.button!==0||e.ctrlKey&&s)return;(u=l(this,Rt))==null||u.toggle(!1);const i=this._isDraggable;this._isDraggable=!1,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,Fp).bind(this,t),{passive:!0,capture:!0,signal:r}),window.addEventListener("touchmove",ms,{passive:!1,signal:r}),window.addEventListener("contextmenu",ni,{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,nf).call(this)};window.addEventListener("pointerup",c,{signal:r}),window.addEventListener("blur",c,{signal:r})},Lp=function(t,e,s,i){this.width=s,this.height=i,this.x=t,this.y=e;const[n,r]=this.parentDimensions;this.setDims(n*s,r*i),this.fixAndSetPosition(),this._onResized()},nf=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,Lp).bind(this,n,r,a,h),undo:w(this,K,Lp).bind(this,t,e,s,i),mustExec:!0})},Fp=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,sf).call(this,this.rotation),f=(j,z)=>[d[0]*j+d[2]*z,d[1]*j+d[3]*z],g=w(this,K,sf).call(this,360-this.rotation),p=(j,z)=>[g[0]*j+g[2]*z,g[1]*j+g[3]*z];let v,_,b=!1,x=!1;switch(t){case"topLeft":b=!0,v=(j,z)=>[0,0],_=(j,z)=>[j,z];break;case"topMiddle":v=(j,z)=>[j/2,0],_=(j,z)=>[j/2,z];break;case"topRight":b=!0,v=(j,z)=>[j,0],_=(j,z)=>[0,z];break;case"middleRight":x=!0,v=(j,z)=>[j,z/2],_=(j,z)=>[0,z/2];break;case"bottomRight":b=!0,v=(j,z)=>[j,z],_=(j,z)=>[0,0];break;case"bottomMiddle":v=(j,z)=>[j/2,z],_=(j,z)=>[j/2,0];break;case"bottomLeft":b=!0,v=(j,z)=>[0,z],_=(j,z)=>[j,0];break;case"middleLeft":x=!0,v=(j,z)=>[0,z/2],_=(j,z)=>[j,z/2];break}const S=v(a,h),A=_(a,h);let k=f(...A);const M=ot._round(n+k[0]),D=ot._round(r+k[1]);let P=1,R=1,F,I;if(e.fromKeyboard)({deltaX:F,deltaY:I}=e);else{const{screenX:j,screenY:z}=e,[at,Mt]=l(this,la);[F,I]=this.screenToPageTranslation(j-at,z-Mt),l(this,la)[0]=j,l(this,la)[1]=z}if([F,I]=p(F/s,I/i),b){const j=Math.hypot(a,h);P=R=Math.max(Math.min(Math.hypot(A[0]-S[0]-F,A[1]-S[1]-I)/j,1/a,1/h),c/a,u/h)}else x?P=Math.max(c,Math.min(1,Math.abs(A[0]-S[0]-F)))/a:R=Math.max(u,Math.min(1,Math.abs(A[1]-S[1]-I)))/h;const H=ot._round(a*P),W=ot._round(h*R);k=f(..._(H,W));const B=M-k[0],ht=D-k[1];l(this,ys)||m(this,ys,[this.x,this.y,this.width,this.height]),this.width=H,this.height=W,this.x=B,this.y=ht,this.setDims(s*H,i*W),this.fixAndSetPosition(),this._onResizing()},hy=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)},ly=function(t,e,s){let n=.7*(s/e)+1-.7;if(n===1)return;const r=w(this,K,sf).call(this,this.rotation),a=(M,D)=>[r[0]*M+r[2]*D,r[1]*M+r[3]*D],[h,c]=this.parentDimensions,u=this.x,d=this.y,f=this.width,g=this.height,p=ot.MIN_SIZE/h,v=ot.MIN_SIZE/c;n=Math.max(Math.min(n,1/f,1/g),p/f,v/g);const _=ot._round(f*n),b=ot._round(g*n);if(_===f&&b===g)return;l(this,ys)||m(this,ys,[u,d,f,g]);const x=a(f/2,g/2),S=ot._round(u+x[0]),A=ot._round(d+x[1]),k=a(_/2,b/2);this.x=S-k[0],this.y=A-k[1],this.width=_,this.height=b,this.setDims(h*_,c*b),this.fixAndSetPosition(),this._onResizing()},cy=function(){var t;(t=l(this,Rt))==null||t.toggle(!0),this.parent.togglePointerEvents(!0),w(this,K,nf).call(this)},Ip=function(t){const{isMac:e}=Ue.platform;t.ctrlKey&&!e||t.shiftKey||t.metaKey&&e?this.parent.toggleSelected(this):this.parent.setSelected(this)},uy=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,Ip).call(this,c),s&&this._onStopDragging()};e&&(m(this,No,t.clientX),m(this,Bo,t.clientY),m(this,lr,t.pointerId),m(this,Nl,t.pointerType),window.addEventListener("pointermove",c=>{s||(s=!0,this._onStartDragging());const{clientX:u,clientY:d,pointerId:f}=c;if(f!==l(this,lr)){ms(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",ms,r),window.addEventListener("pointerdown",c=>{c.pointerType===l(this,Nl)&&(l(this,da)||c.isPrimary)&&a(c),ms(c)},r));const h=c=>{if(!l(this,lr)||l(this,lr)===c.pointerId){a(c);return}ms(c)};window.addEventListener("pointerup",h,{signal:n}),window.addEventListener("blur",h,{signal:n})},jp=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})},dy=function(t){ot._resizerKeyboardManager.exec(this,t)},fy=function(t){var e;l(this,pn)&&((e=t.relatedTarget)==null?void 0:e.parentNode)!==l(this,we)&&w(this,K,Yc).call(this)},gy=function(t){m(this,Bl,l(this,pn)?t:"")},Np=function(t){if(l(this,li))for(const e of l(this,li))e.tabIndex=t},Yc=function(){m(this,pn,!1),w(this,K,Np).call(this,-1),w(this,K,nf).call(this)},y(ot,Gl),J(ot,"_l10n",null),J(ot,"_l10nResizer",null),J(ot,"_borderLineWidth",-1),J(ot,"_colorManager",new Gg),J(ot,"_zIndex",1),J(ot,"_telemetryTimeout",1e3);let Vt=ot;class cS extends Vt{constructor(t){super(t),this.annotationElementId=t.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}}const Pv=3285377520,Fs=4294901760,Ei=65535;class Mv{constructor(t){this.h1=t?t&4294967295:Pv,this.h2=t?t&4294967295:Pv}update(t){let e,s;if(typeof t=="string"){e=new Uint8Array(t.length*2),s=0;for(let v=0,_=t.length;v<_;v++){const b=t.charCodeAt(v);b<=255?e[s++]=b:(e[s++]=b>>>8,e[s++]=b&255)}}else if(ArrayBuffer.isView(t))e=t.slice(),s=e.byteLength;else throw new Error("Invalid data format, must be a string or TypedArray.");const i=s>>2,n=s-i*4,r=new Uint32Array(e.buffer,0,i);let a=0,h=0,c=this.h1,u=this.h2;const d=3432918353,f=461845907,g=d&Ei,p=f&Ei;for(let v=0;v<i;v++)v&1?(a=r[v],a=a*d&Fs|a*g&Ei,a=a<<15|a>>>17,a=a*f&Fs|a*p&Ei,c^=a,c=c<<13|c>>>19,c=c*5+3864292196):(h=r[v],h=h*d&Fs|h*g&Ei,h=h<<15|h>>>17,h=h*f&Fs|h*p&Ei,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&Fs|a*g&Ei,a=a<<15|a>>>17,a=a*f&Fs|a*p&Ei,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&Fs|t*36045&Ei,e=e*4283543511&Fs|((e<<16|t>>>16)*2950163797&Fs)>>>16,t^=e>>>1,t=t*444984403&Fs|t*60499&Ei,e=e*3301882366&Fs|((e<<16|t>>>16)*3120437893&Fs)>>>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(){y(this,Rd);y(this,fa,!1);y(this,ga,null);y(this,me,new Map);this.onSetModified=null,this.onResetModified=null,this.onAnnotationEditor=null}getValue(t,e){const s=l(this,me).get(t);return s===void 0?e:Object.assign(e,s)}getRawValue(t){return l(this,me).get(t)}remove(t){if(l(this,me).delete(t),l(this,me).size===0&&this.resetModified(),typeof this.onAnnotationEditor=="function"){for(const e of l(this,me).values())if(e instanceof Vt)return;this.onAnnotationEditor(null)}}setValue(t,e){const s=l(this,me).get(t);let i=!1;if(s!==void 0)for(const[n,r]of Object.entries(e))s[n]!==r&&(i=!0,s[n]=r);else i=!0,l(this,me).set(t,e);i&&w(this,Rd,py).call(this),e instanceof Vt&&typeof this.onAnnotationEditor=="function"&&this.onAnnotationEditor(e.constructor._type)}has(t){return l(this,me).has(t)}getAll(){return l(this,me).size>0?Og(l(this,me)):null}setAll(t){for(const[e,s]of Object.entries(t))this.setValue(e,s)}get size(){return l(this,me).size}resetModified(){l(this,fa)&&(m(this,fa,!1),typeof this.onResetModified=="function"&&this.onResetModified())}get print(){return new Ov(this)}get serializable(){if(l(this,me).size===0)return Vg;const t=new Map,e=new Mv,s=[],i=Object.create(null);let n=!1;for(const[r,a]of l(this,me)){const h=a instanceof Vt?a.serialize(!1,i):a;h&&(t.set(r,h),e.update(`${r}:${JSON.stringify(h)}`),n||(n=!!h.bitmap))}if(n)for(const r of t.values())r.bitmap&&s.push(r.bitmap);return t.size>0?{map:t,hash:e.hexdigest(),transfer:s}:Vg}get editorStats(){let t=null;const e=new Map;for(const s of l(this,me).values()){if(!(s instanceof Vt))continue;const i=s.telemetryFinalData;if(!i)continue;const{type:n}=i;e.has(n)||e.set(n,Object.getPrototypeOf(s).constructor),t||(t=Object.create(null));const r=t[n]||(t[n]=new Map);for(const[a,h]of Object.entries(i)){if(a==="type")continue;let c=r.get(a);c||(c=new Map,r.set(a,c));const u=c.get(h)??0;c.set(h,u+1)}}for(const[s,i]of e)t[s]=i.computeTelemetryFinalData(t[s]);return t}resetModifiedIds(){m(this,ga,null)}get modifiedIds(){if(l(this,ga))return l(this,ga);const t=[];for(const e of l(this,me).values())!(e instanceof Vt)||!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,me=new WeakMap,Rd=new WeakSet,py=function(){l(this,fa)||(m(this,fa,!0),typeof this.onSetModified=="function"&&this.onSetModified())};class Ov extends Wg{constructor(e){super();y(this,Vl);const{map:s,hash:i,transfer:n}=e.serializable,r=structuredClone(s,n?{transfer:n}:null);m(this,Vl,{map:r,hash:i,transfer:n})}get print(){Pt("Should not call PrintAnnotationStorage.print")}get serializable(){return l(this,Vl)}get modifiedIds(){return lt(this,"modifiedIds",{ids:new Set,hash:""})}}Vl=new WeakMap;class uS{constructor({ownerDocument:t=globalThis.document,styleElement:e=null}){y(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(ne(!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}Pt("Not implemented: loadSystemFont without the Font Loading API.")}}async bind(t){if(t.attached||t.missingFile&&!t.systemFontInfo)return;if(t.attached=!0,t.systemFontInfo){await this.loadSystemFont(t);return}if(this.isFontLoadingAPISupported){const s=t.createNativeFontFace();if(s){this.addNativeFontFace(s);try{await s.loaded}catch(i){throw 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 lt(this,"isFontLoadingAPISupported",t)}get isSyncFontLoadingSupported(){let t=!1;return(Me||typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.userAgent)=="string"&&/Mozilla\/5.0.*?rv:\d+.*? Gecko/.test(navigator.userAgent))&&(t=!0),lt(this,"isSyncFontLoadingSupported",t)}_queueLoadingCallback(t){function e(){for(ne(!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 lt(this,"_loadTestFont",t)}_prepareFontLoadEvent(t,e){function s(A,k){return A.charCodeAt(k)<<24|A.charCodeAt(k+1)<<16|A.charCodeAt(k+2)<<8|A.charCodeAt(k+3)&255}function i(A,k,M,D){const P=A.substring(0,k),R=A.substring(k+M);return P+D+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,k){if(++c>30){rt("Load test font never loaded."),k();return}if(h.font="30px "+A,h.fillText(".",0,20),h.getImageData(0,0,1,1).data[3]>0){k();return}setTimeout(u.bind(null,A,k))}const d=`lt${Date.now()}${this.loadTestFontId++}`;let f=this._loadTestFont;f=i(f,976,d.length,d);const p=16,v=1482184792;let _=s(f,p);for(n=0,r=d.length-3;n<r;n+=4)_=_-v+s(d,n)|0;n<d.length&&(_=_-v+s(d+"XXX",n)|0),f=i(f,p,4,Kx(_));const b=`url(data:font/opentype;base64,${btoa(f)});`,x=`@font-face {font-family:"${d}";src:${b}}`;this.insertRule(x);const S=this._document.createElement("div");S.style.visibility="hidden",S.style.width=S.style.height="10px",S.style.position="absolute",S.style.top=S.style.left="0px";for(const A of[t.loadedName,d]){const k=this._document.createElement("span");k.textContent="Hi",k.style.fontFamily=A,S.append(k)}this._document.body.append(S),u(d,()=>{S.remove(),e.complete()})}}Ho=new WeakMap;class dS{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,${sS(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 vd={DATA:1,ERROR:2},re={CANCEL:1,CANCEL_COMPLETE:2,CLOSE:3,ENQUEUE:4,ERROR:5,PULL:6,PULL_COMPLETE:7,START_COMPLETE:8};function Dv(){}function ns(o){if(o instanceof qn||o instanceof Mg||o instanceof al||o instanceof Av||o instanceof cd||o instanceof Pg)return o;switch(o instanceof Error||typeof o=="object"&&o!==null||Pt('wrapReason: Expected "reason" to be a (possibly cloned) Error.'),o.name){case"AbortException":return new qn(o.message);case"InvalidPDFException":return new Mg(o.message);case"MissingPDFException":return new al(o.message);case"PasswordException":return new Av(o.message,o.code);case"UnexpectedResponseException":return new cd(o.message,o.status);case"UnknownErrorException":return new Pg(o.message,o.details)}return new Pg(o.message,o.toString())}class cl{constructor(t,e,s){y(this,Hs);y(this,zo,new AbortController);this.sourceName=t,this.targetName=e,this.comObj=s,this.callbackId=1,this.streamId=1,this.streamSinks=Object.create(null),this.streamControllers=Object.create(null),this.callbackCapabilities=Object.create(null),this.actionHandler=Object.create(null),s.addEventListener("message",w(this,Hs,my).bind(this),{signal:l(this,zo).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:re.PULL,streamId:n,desiredSize:c.desiredSize}),u.promise},cancel:c=>{ne(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:re.CANCEL,streamId:n,reason:ns(c)}),u.promise}},s)}destroy(){var t;(t=l(this,zo))==null||t.abort(),m(this,zo,null)}}zo=new WeakMap,Hs=new WeakSet,my=function({data:t}){if(t.targetName!==this.sourceName)return;if(t.stream){w(this,Hs,by).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===vd.DATA)i.resolve(t.data);else if(t.callback===vd.ERROR)i.reject(ns(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:vd.DATA,callbackId:t.callbackId,data:r})},function(r){n.postMessage({sourceName:s,targetName:i,callback:vd.ERROR,callbackId:t.callbackId,reason:ns(r)})});return}if(t.streamId){w(this,Hs,vy).call(this,t);return}e(t.data)},vy=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:re.ENQUEUE,streamId:e,chunk:c},d)},close(){this.isCancelled||(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:re.CLOSE,streamId:e}),delete r.streamSinks[e])},error(c){ne(c instanceof Error,"error must have a valid reason"),!this.isCancelled&&(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:re.ERROR,streamId:e,reason:ns(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:re.START_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:re.START_COMPLETE,streamId:e,reason:ns(c)})})},by=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 re.START_COMPLETE:t.success?r.startCall.resolve():r.startCall.reject(ns(t.reason));break;case re.PULL_COMPLETE:t.success?r.pullCall.resolve():r.pullCall.reject(ns(t.reason));break;case re.PULL:if(!a){n.postMessage({sourceName:s,targetName:i,stream:re.PULL_COMPLETE,streamId:e,success:!0});break}a.desiredSize<=0&&t.desiredSize>0&&a.sinkCapability.resolve(),a.desiredSize=t.desiredSize,Promise.try(a.onPull||Dv).then(function(){n.postMessage({sourceName:s,targetName:i,stream:re.PULL_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:re.PULL_COMPLETE,streamId:e,reason:ns(c)})});break;case re.ENQUEUE:if(ne(r,"enqueue should have stream controller"),r.isClosed)break;r.controller.enqueue(t.chunk);break;case re.CLOSE:if(ne(r,"close should have stream controller"),r.isClosed)break;r.isClosed=!0,r.controller.close(),w(this,Hs,rf).call(this,r,e);break;case re.ERROR:ne(r,"error should have stream controller"),r.controller.error(ns(t.reason)),w(this,Hs,rf).call(this,r,e);break;case re.CANCEL_COMPLETE:t.success?r.cancelCall.resolve():r.cancelCall.reject(ns(t.reason)),w(this,Hs,rf).call(this,r,e);break;case re.CANCEL:if(!a)break;const h=ns(t.reason);Promise.try(a.onCancel||Dv,h).then(function(){n.postMessage({sourceName:s,targetName:i,stream:re.CANCEL_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:re.CANCEL_COMPLETE,streamId:e,reason:ns(c)})}),a.sinkCapability.reject(h),a.isCancelled=!0,delete this.streamSinks[e];break;default:throw new Error("Unexpected stream case")}},rf=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 Rv{constructor({enableHWA:t=!1}){y(this,Wl,!1);m(this,Wl,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,Wl)})}}reset(t,e,s){if(!t.canvas)throw new Error("Canvas is not specified");if(e<=0||s<=0)throw new Error("Invalid canvas size");t.canvas.width=e,t.canvas.height=s}destroy(t){if(!t.canvas)throw new Error("Canvas is not specified");t.canvas.width=0,t.canvas.height=0,t.canvas=null,t.context=null}_createCanvas(t,e){Pt("Abstract method `_createCanvas` called.")}}Wl=new WeakMap;class fS extends Rv{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 Lv{constructor({baseUrl:t=null,isCompressed:e=!0}){this.baseUrl=t,this.isCompressed=e}async fetch({name:t}){if(!this.baseUrl)throw new Error("Ensure that the `cMapUrl` and `cMapPacked` API parameters are provided.");if(!t)throw new Error("CMap name must be specified.");const e=this.baseUrl+t+(this.isCompressed?".bcmap":"");return this._fetch(e).then(s=>({cMapData:s,isCompressed:this.isCompressed})).catch(s=>{throw new Error(`Unable to load ${this.isCompressed?"binary ":""}CMap at: ${e}`)})}async _fetch(t){Pt("Abstract method `_fetch` called.")}}class Fv extends Lv{async _fetch(t){const e=await dd(t,this.isCompressed?"arraybuffer":"text");return e instanceof ArrayBuffer?new Uint8Array(e):ud(e)}}class Iv{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 gS extends Iv{constructor({docId:e,ownerDocument:s=globalThis.document}){super();y(this,V);y(this,pa);y(this,Go);y(this,mn);y(this,vn);y(this,Le);y(this,ma);y(this,va,0);m(this,vn,e),m(this,Le,s)}addFilter(e){if(!e)return"none";let s=l(this,V,Be).get(e);if(s)return s;const[i,n,r]=w(this,V,af).call(this,e),a=e.length===1?i:`${i}${n}${r}`;if(s=l(this,V,Be).get(a),s)return l(this,V,Be).set(e,s),s;const h=`g_${l(this,vn)}_transfer_map_${ts(this,va)._++}`,c=w(this,V,Fh).call(this,h);l(this,V,Be).set(e,c),l(this,V,Be).set(a,c);const u=w(this,V,Ih).call(this,h);return w(this,V,Kc).call(this,i,n,r,u),c}addHCMFilter(e,s){var p;const i=`${e}-${s}`,n="base";let r=l(this,V,$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,V,$c).set(n,r)),!e||!s))return r.url;const a=w(this,V,Jc).call(this,e);e=q.makeHexColor(...a);const h=w(this,V,Jc).call(this,s);if(s=q.makeHexColor(...h),l(this,V,Lh).style.color="",e==="#000000"&&s==="#ffffff"||e===s)return r.url;const c=new Array(256);for(let v=0;v<=255;v++){const _=v/255;c[v]=_<=.03928?_/12.92:((_+.055)/1.055)**2.4}const u=c.join(","),d=`g_${l(this,vn)}_hcm_filter`,f=r.filter=w(this,V,Ih).call(this,d);w(this,V,Kc).call(this,u,u,u,f),w(this,V,Bp).call(this,f);const g=(v,_)=>{const b=a[v]/255,x=h[v]/255,S=new Array(_+1);for(let A=0;A<=_;A++)S[A]=b+A/_*(x-b);return S.join(",")};return w(this,V,Kc).call(this,g(0,5),g(1,5),g(2,5),f),r.url=w(this,V,Fh).call(this,d),r.url}addAlphaFilter(e){let s=l(this,V,Be).get(e);if(s)return s;const[i]=w(this,V,af).call(this,[e]),n=`alpha_${i}`;if(s=l(this,V,Be).get(n),s)return l(this,V,Be).set(e,s),s;const r=`g_${l(this,vn)}_alpha_map_${ts(this,va)._++}`,a=w(this,V,Fh).call(this,r);l(this,V,Be).set(e,a),l(this,V,Be).set(n,a);const h=w(this,V,Ih).call(this,r);return w(this,V,Hp).call(this,i,h),a}addLuminosityFilter(e){let s=l(this,V,Be).get(e||"luminosity");if(s)return s;let i,n;if(e?([i]=w(this,V,af).call(this,[e]),n=`luminosity_${i}`):n="luminosity",s=l(this,V,Be).get(n),s)return l(this,V,Be).set(e,s),s;const r=`g_${l(this,vn)}_luminosity_map_${ts(this,va)._++}`,a=w(this,V,Fh).call(this,r);l(this,V,Be).set(e,a),l(this,V,Be).set(n,a);const h=w(this,V,Ih).call(this,r);return w(this,V,yy).call(this,h),e&&w(this,V,Hp).call(this,i,h),a}addHighlightHCMFilter(e,s,i,n,r){var x;const a=`${s}-${i}-${n}-${r}`;let h=l(this,V,$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,V,$c).set(e,h)),!s||!i))return h.url;const[c,u]=[s,i].map(w(this,V,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,V,Jc).bind(this));f<d&&([d,f,g,p]=[f,d,p,g]),l(this,V,Lh).style.color="";const v=(S,A,k)=>{const M=new Array(256),D=(f-d)/k,P=S/255,R=(A-S)/(255*k);let F=0;for(let I=0;I<=k;I++){const H=Math.round(d+I*D),W=P+I*R;for(let B=F;B<=H;B++)M[B]=W;F=H+1}for(let I=F;I<256;I++)M[I]=M[F-1];return M.join(",")},_=`g_${l(this,vn)}_hcm_${e}_filter`,b=h.filter=w(this,V,Ih).call(this,_);return w(this,V,Bp).call(this,b),w(this,V,Kc).call(this,v(g[0],p[0],5),v(g[1],p[1],5),v(g[2],p[2],5),b),h.url=w(this,V,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,Go))==null||n.clear(),m(this,Go,null),(r=l(this,ma))==null||r.clear(),m(this,ma,null),m(this,va,0))}}pa=new WeakMap,Go=new WeakMap,mn=new WeakMap,vn=new WeakMap,Le=new WeakMap,ma=new WeakMap,va=new WeakMap,V=new WeakSet,Be=function(){return l(this,Go)||m(this,Go,new Map)},$c=function(){return l(this,ma)||m(this,ma,new Map)},Lh=function(){if(!l(this,mn)){const e=l(this,Le).createElement("div"),{style:s}=e;s.visibility="hidden",s.contain="strict",s.width=s.height=0,s.position="absolute",s.top=s.left=0,s.zIndex=-1;const i=l(this,Le).createElementNS(nn,"svg");i.setAttribute("width",0),i.setAttribute("height",0),m(this,mn,l(this,Le).createElementNS(nn,"defs")),e.append(i),i.append(l(this,mn)),l(this,Le).body.append(e)}return l(this,mn)},af=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,Le).URL;s!==l(this,Le).baseURI&&(fd(s)?rt('#createUrl: ignore "data:"-URL for performance reasons.'):m(this,pa,s.split("#",1)[0]))}return`url(${l(this,pa)}#${e})`},yy=function(e){const s=l(this,Le).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)},Bp=function(e){const s=l(this,Le).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,Le).createElementNS(nn,"filter");return s.setAttribute("color-interpolation-filters","sRGB"),s.setAttribute("id",e),l(this,V,Lh).append(s),s},qc=function(e,s,i){const n=l(this,Le).createElementNS(nn,s);n.setAttribute("type","discrete"),n.setAttribute("tableValues",i),e.append(n)},Kc=function(e,s,i,n){const r=l(this,Le).createElementNS(nn,"feComponentTransfer");n.append(r),w(this,V,qc).call(this,r,"feFuncR",e),w(this,V,qc).call(this,r,"feFuncG",s),w(this,V,qc).call(this,r,"feFuncB",i)},Hp=function(e,s){const i=l(this,Le).createElementNS(nn,"feComponentTransfer");s.append(i),w(this,V,qc).call(this,i,"feFuncA",e)},Jc=function(e){return l(this,V,Lh).style.color=e,Ng(getComputedStyle(l(this,V,Lh)).getPropertyValue("color"))};class jv{constructor({baseUrl:t=null}){this.baseUrl=t}async fetch({filename:t}){if(!this.baseUrl)throw new Error("Ensure that the `standardFontDataUrl` API parameter is provided.");if(!t)throw new Error("Font filename must be specified.");const e=`${this.baseUrl}${t}`;return this._fetch(e).catch(s=>{throw new Error(`Unable to load font data at: ${e}`)})}async _fetch(t){Pt("Abstract method `_fetch` called.")}}class Nv extends jv{async _fetch(t){const e=await dd(t,"arraybuffer");return new Uint8Array(e)}}Me&&rt("Please use the `legacy` build in Node.js environments.");async function Bv(o){const e=await process.getBuiltinModule("fs").promises.readFile(o);return new Uint8Array(e)}class pS extends Iv{}class mS extends Rv{_createCanvas(t,e){return process.getBuiltinModule("module").createRequire(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:zt&&zt.tagName.toUpperCase()==="SCRIPT"&&zt.src||new URL("pdf-canvas.umd.js",document.baseURI).href)("@napi-rs/canvas").createCanvas(t,e)}}class vS extends Lv{async _fetch(t){return Bv(t)}}class bS extends jv{async _fetch(t){return Bv(t)}}const De={FILL:"Fill",STROKE:"Stroke",SHADING:"Shading"};function Xg(o,t){if(!t)return;const e=t[2]-t[0],s=t[3]-t[1],i=new Path2D;i.rect(t[0],t[1],e,s),o.clip(i)}class Ug{getPattern(){Pt("Abstract method `getPattern` called.")}}class yS extends Ug{constructor(t){super(),this._type=t[1],this._bbox=t[2],this._colorStops=t[3],this._p0=t[4],this._p1=t[5],this._r0=t[6],this._r1=t[7],this.matrix=null}_createGradient(t){let e;this._type==="axial"?e=t.createLinearGradient(this._p0[0],this._p0[1],this._p1[0],this._p1[1]):this._type==="radial"&&(e=t.createRadialGradient(this._p0[0],this._p0[1],this._r0,this._p1[0],this._p1[1],this._r1));for(const s of this._colorStops)e.addColorStop(s[0],s[1]);return e}getPattern(t,e,s,i){let n;if(i===De.STROKE||i===De.FILL){const r=e.current.getClippedPathBoundingBox(i,Nt(t))||[0,0,0,0],a=Math.ceil(r[2]-r[0])||1,h=Math.ceil(r[3]-r[1])||1,c=e.cachedCanvases.getCanvas("pattern",a,h),u=c.context;u.clearRect(0,0,u.canvas.width,u.canvas.height),u.beginPath(),u.rect(0,0,u.canvas.width,u.canvas.height),u.translate(-r[0],-r[1]),s=q.transform(s,[1,0,0,1,r[0],r[1]]),u.transform(...e.baseTransform),this.matrix&&u.transform(...this.matrix),Xg(u,this._bbox),u.fillStyle=this._createGradient(u),u.fill(),n=t.createPattern(c.canvas,"no-repeat");const d=new DOMMatrix(s);n.setTransform(d)}else Xg(t,this._bbox),n=this._createGradient(t);return n}}function Yg(o,t,e,s,i,n,r,a){const h=t.coords,c=t.colors,u=o.data,d=o.width*4;let f;h[e+1]>h[s+1]&&(f=e,e=s,s=f,f=n,n=r,r=f),h[s+1]>h[i+1]&&(f=s,s=i,i=f,f=r,r=a,a=f),h[e+1]>h[s+1]&&(f=e,e=s,s=f,f=n,n=r,r=f);const g=(h[e]+t.offsetX)*t.scaleX,p=(h[e+1]+t.offsetY)*t.scaleY,v=(h[s]+t.offsetX)*t.scaleX,_=(h[s+1]+t.offsetY)*t.scaleY,b=(h[i]+t.offsetX)*t.scaleX,x=(h[i+1]+t.offsetY)*t.scaleY;if(p>=x)return;const S=c[n],A=c[n+1],k=c[n+2],M=c[r],D=c[r+1],P=c[r+2],R=c[a],F=c[a+1],I=c[a+2],H=Math.round(p),W=Math.round(x);let B,ht,j,z,at,Mt,Lt,$t;for(let it=H;it<=W;it++){if(it<_){const dt=it<p?0:(p-it)/(p-_);B=g-(g-v)*dt,ht=S-(S-M)*dt,j=A-(A-D)*dt,z=k-(k-P)*dt}else{let dt;it>x?dt=1:_===x?dt=0:dt=(_-it)/(_-x),B=v-(v-b)*dt,ht=M-(M-R)*dt,j=D-(D-F)*dt,z=P-(P-I)*dt}let ut;it<p?ut=0:it>x?ut=1:ut=(p-it)/(p-x),at=g-(g-b)*ut,Mt=S-(S-R)*ut,Lt=A-(A-F)*ut,$t=k-(k-I)*ut;const Ft=Math.round(Math.min(B,at)),us=Math.round(Math.max(B,at));let kt=d*it+Ft*4;for(let dt=Ft;dt<=us;dt++)ut=(B-dt)/(B-at),ut<0?ut=0:ut>1&&(ut=1),u[kt++]=ht-(ht-Mt)*ut|0,u[kt++]=j-(j-Lt)*ut|0,u[kt++]=z-(z-$t)*ut|0,u[kt++]=255}}function _S(o,t,e){const s=t.coords,i=t.colors;let n,r;switch(t.type){case"lattice":const a=t.verticesPerRow,h=Math.floor(s.length/a)-1,c=a-1;for(n=0;n<h;n++){let u=n*a;for(let d=0;d<c;d++,u++)Yg(o,e,s[u],s[u+1],s[u+a],i[u],i[u+1],i[u+a]),Yg(o,e,s[u+a+1],s[u+1],s[u+a],i[u+a+1],i[u+1],i[u+a])}break;case"triangles":for(n=0,r=s.length;n<r;n+=3)Yg(o,e,s[n],s[n+1],s[n+2],i[n],i[n+1],i[n+2]);break;default:throw new Error("illegal figure")}}class wS extends Ug{constructor(t){super(),this._coords=t[2],this._colors=t[3],this._figures=t[4],this._bounds=t[5],this._bbox=t[7],this._background=t[8],this.matrix=null}_createMeshCanvas(t,e,s){const a=Math.floor(this._bounds[0]),h=Math.floor(this._bounds[1]),c=Math.ceil(this._bounds[2])-a,u=Math.ceil(this._bounds[3])-h,d=Math.min(Math.ceil(Math.abs(c*t[0]*1.1)),3e3),f=Math.min(Math.ceil(Math.abs(u*t[1]*1.1)),3e3),g=c/d,p=u/f,v={coords:this._coords,colors:this._colors,offsetX:-a,offsetY:-h,scaleX:1/g,scaleY:1/p},_=d+2*2,b=f+2*2,x=s.getCanvas("mesh",_,b),S=x.context,A=S.createImageData(d,f);if(e){const M=A.data;for(let D=0,P=M.length;D<P;D+=4)M[D]=e[0],M[D+1]=e[1],M[D+2]=e[2],M[D+3]=255}for(const M of this._figures)_S(A,M,v);return S.putImageData(A,2,2),{canvas:x.canvas,offsetX:a-2*g,offsetY:h-2*p,scaleX:g,scaleY:p}}getPattern(t,e,s,i){Xg(t,this._bbox);let n;if(i===De.SHADING)n=q.singularValueDecompose2dScale(Nt(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===De.SHADING?null:this._background,e.cachedCanvases);return i!==De.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 xS extends Ug{getPattern(){return"hotpink"}}function SS(o){switch(o[0]){case"RadialAxial":return new yS(o);case"Mesh":return new wS(o);case"Dummy":return new xS}throw new Error(`Unknown IR type: ${o[0]}`)}const Hv={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,v=g-d,_=q.singularValueDecompose2dScale(this.matrix),b=q.singularValueDecompose2dScale(this.baseTransform),x=_[0]*b[0],S=_[1]*b[1];let A=p,k=v,M=!1,D=!1;const P=Math.ceil(h*x),R=Math.ceil(c*S),F=Math.ceil(p*x),I=Math.ceil(v*S);P>=F?A=h:M=!0,R>=I?k=c:D=!0;const H=this.getSizeAndScale(A,this.ctx.canvas.width,x),W=this.getSizeAndScale(k,this.ctx.canvas.height,S),B=t.cachedCanvases.getCanvas("pattern",H.size,W.size),ht=B.context,j=a.createCanvasGraphics(ht);if(j.groupLevel=t.groupLevel,this.setFillAndStrokeStyleToContext(j,i,r),ht.translate(-H.scale*u,-W.scale*d),j.transform(H.scale,0,0,W.scale,0,0),ht.save(),this.clipBbox(j,u,d,f,g),j.baseTransform=Nt(j.ctx),j.executeOperatorList(s),j.endDrawing(),ht.restore(),M||D){const z=B.canvas;M&&(A=h),D&&(k=c);const at=this.getSizeAndScale(A,this.ctx.canvas.width,x),Mt=this.getSizeAndScale(k,this.ctx.canvas.height,S),Lt=at.size,$t=Mt.size,it=t.cachedCanvases.getCanvas("pattern-workaround",Lt,$t),ut=it.context,Ft=M?Math.floor(p/h):0,us=D?Math.floor(v/c):0;for(let kt=0;kt<=Ft;kt++)for(let dt=0;dt<=us;dt++)ut.drawImage(z,Lt*kt,$t*dt,Lt,$t,0,0,Lt,$t);return{canvas:it.canvas,scaleX:at.scale,scaleY:Mt.scale,offsetX:u,offsetY:d}}return{canvas:B.canvas,scaleX:H.scale,scaleY:W.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(Nt(t.ctx),[e,s,i,n]),t.clip(),t.endPath()}setFillAndStrokeStyleToContext(t,e,s){const i=t.ctx,n=t.current;switch(e){case Hv.COLORED:const r=this.ctx;i.fillStyle=r.fillStyle,i.strokeStyle=r.strokeStyle,n.fillColor=r.fillStyle,n.strokeColor=r.strokeStyle;break;case Hv.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 qx(`Unsupported paint type: ${e}`)}}getPattern(t,e,s,i){let n=s;i!==De.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 $g=Ld;function CS({src:o,srcPos:t=0,dest:e,width:s,height:i,nonBlackColor:n=4294967295,inverseDecode:r=!1}){const a=Ue.isLittleEndian?4278190080:255,[h,c]=r?[n,a]:[a,n],u=s>>3,d=s&7,f=o.length;e=new Uint32Array(e.buffer);let g=0;for(let p=0;p<i;p++){for(const _=t+u;t<_;t++){const b=t<f?o[t]:255;e[g++]=b&128?c:h,e[g++]=b&64?c:h,e[g++]=b&32?c:h,e[g++]=b&16?c:h,e[g++]=b&8?c:h,e[g++]=b&4?c:h,e[g++]=b&2?c:h,e[g++]=b&1?c:h}if(d===0)continue;const v=t<f?o[t++]:255;for(let _=0;_<d;_++)e[g++]=v&1<<7-_?c:h}return{srcPos:t,destPos:g}}const zv=16,Gv=100,AS=15,Vv=10,Wv=1e3,rs=16;function TS(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 ES{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 bd(o,t,e,s,i,n,r,a,h,c){const[u,d,f,g,p,v]=Nt(o);if(d===0&&f===0){const x=r*u+p,S=Math.round(x),A=a*g+v,k=Math.round(A),M=(r+h)*u+p,D=Math.abs(Math.round(M)-S)||1,P=(a+c)*g+v,R=Math.abs(Math.round(P)-k)||1;return o.setTransform(Math.sign(u),0,0,Math.sign(g),S,k),o.drawImage(t,e,s,i,n,0,0,D,R),o.setTransform(u,d,f,g,p,v),[D,R]}if(u===0&&g===0){const x=a*f+p,S=Math.round(x),A=r*d+v,k=Math.round(A),M=(a+c)*f+p,D=Math.abs(Math.round(M)-S)||1,P=(r+h)*d+v,R=Math.abs(Math.round(P)-k)||1;return o.setTransform(0,Math.sign(d),Math.sign(f),0,S,k),o.drawImage(t,e,s,i,n,0,0,R,D),o.setTransform(u,d,f,g,p,v),[R,D]}o.drawImage(t,e,s,i,n,r,a,h,c);const _=Math.hypot(u,d),b=Math.hypot(f,g);return[_*h,b*c]}function kS(o){const{width:t,height:e}=o;if(t>Wv||e>Wv)return null;const s=1e3,i=new Uint8Array([0,2,4,0,1,0,5,4,8,10,0,8,0,2,1,0]),n=t+1;let r=new Uint8Array(n*(e+1)),a,h,c;const u=t+7&-8;let d=new Uint8Array(u*e),f=0;for(const b of o.data){let x=128;for(;x>0;)d[f++]=b&x?0:255,x>>=1}let g=0;for(f=0,d[f]!==0&&(r[0]=1,++g),h=1;h<t;h++)d[f]!==d[f+1]&&(r[h]=d[f]?2:1,++g),f++;for(d[f]!==0&&(r[h]=2,++g),a=1;a<e;a++){f=a*u,c=a*n,d[f-u]!==d[f]&&(r[c]=d[f]?1:8,++g);let b=(d[f]?4:0)+(d[f-u]?8:0);for(h=1;h<t;h++)b=(b>>2)+(d[f+1]?4:0)+(d[f-u+1]?8:0),i[b]&&(r[c+h]=i[b],++g),f++;if(d[f-u]!==d[f]&&(r[c+h]=d[f]?2:4,++g),g>s)return null}for(f=u*(e-1),c=a*n,d[f]!==0&&(r[c]=8,++g),h=1;h<t;h++)d[f]!==d[f+1]&&(r[c+h]=d[f]?4:8,++g),f++;if(d[f]!==0&&(r[c+h]=4,++g),g>s)return null;const p=new Int32Array([0,n,-1,0,-n,0,0,0,1]),v=new Path2D;for(a=0;g&&a<=e;a++){let b=a*n;const x=b+t;for(;b<x&&!r[b];)b++;if(b===x)continue;v.moveTo(b%n,a);const S=b;let A=r[b];do{const k=p[A];do b+=k;while(!r[b]);const M=r[b];M!==5&&M!==10?(A=M,r[b]=0):(A=M&51*A>>4,r[b]&=A>>2|A<<2),v.lineTo(b%n,b/n|0),r[b]||--g}while(S!==b);--a}return d=null,r=null,function(b){b.save(),b.scale(1/t,-1/e),b.translate(0,-e),b.fill(v),b.beginPath(),b.restore()}}class Xv{constructor(t,e){this.alphaIsShape=!1,this.fontSize=0,this.fontSizeScale=1,this.textMatrix=Cv,this.textMatrixScale=1,this.fontMatrix=Eg,this.leading=0,this.x=0,this.y=0,this.lineX=0,this.lineY=0,this.charSpacing=0,this.wordSpacing=0,this.textHScale=1,this.textRenderingMode=Oe.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=De.FILL,e=null){const s=[this.minX,this.minY,this.maxX,this.maxY];if(t===De.STROKE){e||Pt("Stroke bounding box must include transform.");const i=q.singularValueDecompose2dScale(e),n=i[0]*this.lineWidth/2,r=i[1]*this.lineWidth/2;s[0]-=n,s[1]-=r,s[2]+=n,s[3]+=r}return s}updateClipFromPath(){const t=q.intersect(this.clipBox,this.getPathBoundingBox());this.startNewPathAndClipBox(t||[0,0,0,0])}isEmptyClip(){return this.minX===1/0}startNewPathAndClipBox(t){this.clipBox=t,this.minX=1/0,this.minY=1/0,this.maxX=0,this.maxY=0}getClippedPathBoundingBox(t=De.FILL,e=null){return q.intersect(this.clipBox,this.getPathBoundingBox(t,e))}}function Uv(o,t){if(t instanceof ImageData){o.putImageData(t,0,0);return}const e=t.height,s=t.width,i=e%rs,n=(e-i)/rs,r=i===0?n:n+1,a=o.createImageData(s,rs);let h=0,c;const u=t.data,d=a.data;let f,g,p,v;if(t.kind===ad.GRAYSCALE_1BPP){const _=u.byteLength,b=new Uint32Array(d.buffer,0,d.byteLength>>2),x=b.length,S=s+7>>3,A=4294967295,k=Ue.isLittleEndian?4278190080:255;for(f=0;f<r;f++){for(p=f<n?rs:i,c=0,g=0;g<p;g++){const M=_-h;let D=0;const P=M>S?s:M*8-7,R=P&-8;let F=0,I=0;for(;D<R;D+=8)I=u[h++],b[c++]=I&128?A:k,b[c++]=I&64?A:k,b[c++]=I&32?A:k,b[c++]=I&16?A:k,b[c++]=I&8?A:k,b[c++]=I&4?A:k,b[c++]=I&2?A:k,b[c++]=I&1?A:k;for(;D<P;D++)F===0&&(I=u[h++],F=128),b[c++]=I&F?A:k,F>>=1}for(;c<x;)b[c++]=0;o.putImageData(a,0,f*rs)}}else if(t.kind===ad.RGBA_32BPP){for(g=0,v=s*rs*4,f=0;f<n;f++)d.set(u.subarray(h,h+v)),h+=v,o.putImageData(a,0,g),g+=rs;f<r&&(v=s*i*4,d.set(u.subarray(h,h+v)),o.putImageData(a,0,g))}else if(t.kind===ad.RGB_24BPP)for(p=rs,v=s*p,f=0;f<r;f++){for(f>=n&&(p=i,v=s*p),c=0,g=v;g--;)d[c++]=u[h++],d[c++]=u[h++],d[c++]=u[h++],d[c++]=255;o.putImageData(a,0,f*rs)}else throw new Error(`bad image kind: ${t.kind}`)}function Yv(o,t){if(t.bitmap){o.drawImage(t.bitmap,0,0);return}const e=t.height,s=t.width,i=e%rs,n=(e-i)/rs,r=i===0?n:n+1,a=o.createImageData(s,rs);let h=0;const c=t.data,u=a.data;for(let d=0;d<r;d++){const f=d<n?rs:i;({srcPos:h}=CS({src:c,srcPos:h,dest:u,width:s,height:f,nonBlackColor:0})),o.putImageData(a,0,d*rs)}}function ul(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 yd(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),!Me){const{filter:t}=o;t!=="none"&&t!==""&&(o.filter="none")}}function $v(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 PS=["butt","round","square"],MS=["miter","round","bevel"],OS={},qv={},fp=class fp{constructor(t,e,s,i,n,{optionalContentConfig:r,markedContentStack:a=null},h,c){y(this,ci);this.ctx=t,this.current=new Xv(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 ES(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(...Nt(this.compositeCtx))}this.ctx.save(),yd(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=Nt(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>Vv&&typeof s=="function",u=c?Date.now()+AS: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!==ii.dependency)this[p].apply(this,n[a]);else for(const v of n[a]){const _=v.startsWith("g_")?f:g;if(!_.has(v))return _.get(v,s),a}if(a++,a===h)return a;if(c&&++d>Vv){if(Date.now()>u)return s(),a;d=0}}}endDrawing(){w(this,ci,zp).call(this),this.cachedCanvases.clear(),this.cachedPatterns.clear();for(const t of this._cachedBitmapsMap.values()){for(const e of t.values())typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement&&(e.width=e.height=0);t.clear()}this._cachedBitmapsMap.clear(),w(this,ci,Gp).call(this)}_scaleImage(t,e){const s=t.width??t.displayWidth,i=t.height??t.displayHeight;let n=Math.max(Math.hypot(e[0],e[1]),1),r=Math.max(Math.hypot(e[2],e[3]),1),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=Nt(e);let h,c,u,d;if((t.bitmap||t.data)&&t.count>1){const P=t.bitmap||t.data.buffer;c=JSON.stringify(r?a:[a.slice(0,4),n]),h=this._cachedBitmapsMap.get(P),h||(h=new Map,this._cachedBitmapsMap.set(P,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),Yv(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,v,_]=q.getAxialAlignedBoundingBox([0,0,s,i],f),b=Math.round(v-g)||1,x=Math.round(_-p)||1,S=this.cachedCanvases.getCanvas("fillCanvas",b,x),A=S.context,k=g,M=p;A.translate(-k,-M),A.transform(...f),u||(u=this._scaleImage(d.canvas,Ti(A)),u=u.img,h&&r&&h.set(c,u)),A.imageSmoothingEnabled=$v(Nt(A),t.interpolate),bd(A,u,0,0,u.width,u.height,0,0,s,i),A.globalCompositeOperation="source-in";const D=q.transform(Ti(A),[1,0,0,1,-k,-M]);return A.fillStyle=r?n.getPattern(e,this,D,De.FILL):n,A.fillRect(0,0,s,i),h&&!r&&(this.cachedCanvases.delete("fillCanvas"),h.set(c,S.canvas)),{canvas:S.canvas,offsetX:Math.round(k),offsetY:Math.round(M)}}setLineWidth(t){t!==this.current.lineWidth&&(this._cachedScaleForStroking[0]=-1),this.current.lineWidth=t,this.ctx.lineWidth=t}setLineCap(t){this.ctx.lineCap=PS[t]}setLineJoin(t){this.ctx.lineJoin=MS[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(...Nt(this.suspendedCtx)),ul(this.suspendedCtx,n),TS(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(),ul(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 b=this.cachedCanvases.getCanvas("maskExtension",s,i),x=b.context;x.drawImage(f,-g,-p),x.globalCompositeOperation="destination-atop",x.fillStyle=_,x.fillRect(0,0,s,i),x.globalCompositeOperation="source-over",f=b.canvas,g=p=0}else{t.save(),t.globalAlpha=1,t.setTransform(1,0,0,1,0,0);const b=new Path2D;b.rect(g,p,s,i),t.clip(b),t.globalCompositeOperation="destination-atop",t.fillStyle=_,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 v=new Path2D;v.rect(h,c,s,i),e.clip(v),e.globalCompositeOperation="destination-in",e.drawImage(f,g,p,s,i,h,c,s,i),e.restore()}save(){this.inSMaskMode?(ul(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(),ul(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=Nt(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,v=t.length;g<v;g++)switch(t[g]|0){case ii.rectangle:r=e[p++],a=e[p++];const _=e[p++],b=e[p++],x=r+_,S=a+b;i.moveTo(r,a),_===0||b===0?i.lineTo(x,S):(i.lineTo(x,a),i.lineTo(x,S),i.lineTo(r,S)),d||n.updateRectMinMax(u,[r,a,x,S]),i.closePath();break;case ii.moveTo:r=e[p++],a=e[p++],i.moveTo(r,a),d||n.updatePathMinMax(u,r,a);break;case ii.lineTo:r=e[p++],a=e[p++],i.lineTo(r,a),d||n.updatePathMinMax(u,r,a);break;case ii.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 ii.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 ii.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 ii.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,Ti(e),De.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,Ti(e),De.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=OS}eoClip(){this.pendingClip=qv}beginText(){this.current.textMatrix=Cv,this.current.textMatrixScale=1,this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0}endText(){const t=this.pendingTextPaths,e=this.ctx;if(t===void 0){e.beginPath();return}const s=new Path2D,i=e.getTransform().invertSelf();for(const{transform:n,x:r,y:a,fontSize:h,path:c}of t)s.addPath(c,new DOMMatrix(n).preMultiplySelf(i).translate(r,a).scale(h,-h));e.clip(s),e.beginPath(),delete this.pendingTextPaths}setCharSpacing(t){this.current.charSpacing=t}setWordSpacing(t){this.current.wordSpacing=t}setHScale(t){this.current.textHScale=t/100}setLeading(t){this.current.leading=-t}setFont(t,e){var u;const s=this.commonObjs.get(t),i=this.current;if(!s)throw new Error(`Can't find font for ${t}`);if(i.fontMatrix=s.fontMatrix||Eg,(i.fontMatrix[0]===0||i.fontMatrix[3]===0)&&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<zv?c=zv:e>Gv&&(c=Gv),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&Oe.FILL_STROKE_MASK,f=!!(c&Oe.ADD_TO_PATH_FLAG),g=a.patternFill&&!h.missingFile,p=a.patternStroke&&!h.missingFile;let v;if((h.disableFontFace||f||g||p)&&(v=h.getPathGenerator(this.commonObjs,t)),h.disableFontFace||g||p){if(r.save(),r.translate(e,s),r.scale(u,-u),d===Oe.FILL||d===Oe.FILL_STROKE)if(i){const _=r.getTransform();r.setTransform(...i),r.fill(w(this,ci,Vp).call(this,v,_,i))}else r.fill(v);if(d===Oe.STROKE||d===Oe.FILL_STROKE)if(n){const _=r.getTransform();r.setTransform(...n),r.stroke(w(this,ci,Vp).call(this,v,_,n))}else r.lineWidth/=u,r.stroke(v);r.restore()}else(d===Oe.FILL||d===Oe.FILL_STROKE)&&r.fillText(t,e,s),(d===Oe.STROKE||d===Oe.FILL_STROKE)&&r.strokeText(t,e,s);f&&(this.pendingTextPaths||(this.pendingTextPaths=[])).push({transform:Nt(r),x:e,y:s,fontSize:u,path:v})}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 lt(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,v=i*e.fontMatrix[0],_=e.textRenderingMode===Oe.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 D=e.fillColor.getPattern(n,this,Ti(n),De.FILL);b=Nt(n),n.restore(),n.fillStyle=D}if(e.patternStroke){n.save();const D=e.strokeColor.getPattern(n,this,Ti(n),De.STROKE);x=Nt(n),n.restore(),n.strokeStyle=D}let S=e.lineWidth;const A=e.textMatrixScale;if(A===0||S===0){const D=e.textRenderingMode&Oe.FILL_STROKE_MASK;(D===Oe.STROKE||D===Oe.FILL_STROKE)&&(S=this.getSinglePixelWidth())}else S/=A;if(r!==1&&(n.scale(r,r),S/=r),n.lineWidth=S,s.isInvalidPDFjsFont){const D=[];let P=0;for(const R of t)D.push(R.unicode),P+=R.width;n.fillText(D.join(""),0,0),e.x+=P*v*u,n.restore(),this.compose();return}let k=0,M;for(M=0;M<d;++M){const D=t[M];if(typeof D=="number"){k+=g*D*i/1e3;continue}let P=!1;const R=(D.isSpace?h:0)+a,F=D.fontChar,I=D.accent;let H,W,B=D.width;if(f){const j=D.vmetric||p,z=-(D.vmetric?j[1]:B*.5)*v,at=j[2]*v;B=j?-j[0]:B,H=z/r,W=(k+at)/r}else H=k/r,W=0;if(s.remeasure&&B>0){const j=n.measureText(F).width*1e3/i*r;if(B<j&&this.isFontSubpixelAAEnabled){const z=B/j;P=!0,n.save(),n.scale(z,1),H/=z}else B!==j&&(H+=(B-j)/2e3*i/r)}if(this.contentVisible&&(D.isInFont||s.missingFile)){if(_&&!I)n.fillText(F,H,W);else if(this.paintChar(F,H,W,b,x),I){const j=H+i*I.offset.x/r,z=W-i*I.offset.y/r;this.paintChar(I.fontChar,j,z,b,x)}}const ht=f?B*v-R*c:B*v+R*c;k+=ht,P&&n.restore()}f?e.y-=k:e.x+=k*u,n.restore(),this.compose()}showType3Text(t){const e=this.ctx,s=this.current,i=s.font,n=s.fontSize,r=s.fontDirection,a=i.vertical?1:-1,h=s.charSpacing,c=s.wordSpacing,u=s.textHScale*r,d=s.fontMatrix||Eg,f=t.length,g=s.textRenderingMode===Oe.INVISIBLE;let p,v,_,b;if(!(g||n===0)){for(this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null,e.save(),e.transform(...s.textMatrix),e.translate(s.x,s.y),e.scale(u,r),p=0;p<f;++p){if(v=t[p],typeof v=="number"){b=a*v*n/1e3,this.ctx.translate(b,0),s.x+=b*u;continue}const x=(v.isSpace?c:0)+h,S=i.charProcOperatorList[v.operatorListId];if(!S){rt(`Type3 character "${v.operatorListId}" is not available.`);continue}this.contentVisible&&(this.processingType3=v,this.save(),e.scale(n,n),e.transform(...d),this.executeOperatorList(S),this.restore()),_=q.applyTransform([v.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||Nt(this.ctx),n={createCanvasGraphics:r=>new fp(r,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack})};e=new $g(t,s,this.ctx,n,i)}else e=this._getPattern(t[1],t[2]);return e}setStrokeColorN(){this.current.strokeColor=this.getColorN_Pattern(arguments),this.current.patternStroke=!0}setFillColorN(){this.current.fillColor=this.getColorN_Pattern(arguments),this.current.patternFill=!0}setStrokeRGBColor(t,e,s){this.ctx.strokeStyle=this.current.strokeColor=q.makeHexColor(t,e,s),this.current.patternStroke=!1}setStrokeTransparent(){this.ctx.strokeStyle=this.current.strokeColor="transparent",this.current.patternStroke=!1}setFillRGBColor(t,e,s){this.ctx.fillStyle=this.current.fillColor=q.makeHexColor(t,e,s),this.current.patternFill=!1}setFillTransparent(){this.ctx.fillStyle=this.current.fillColor="transparent",this.current.patternFill=!1}_getPattern(t,e=null){let s;return this.cachedPatterns.has(t)?s=this.cachedPatterns.get(t):(s=SS(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,Ti(e),De.SHADING);const i=Ti(e);if(i){const{width:n,height:r}=e.canvas,[a,h,c,u]=q.getAxialAlignedBoundingBox([0,0,n,r],i);this.ctx.fillRect(a,h,c-a,u-h)}else this.ctx.fillRect(-1e10,-1e10,2e10,2e10);this.compose(this.current.getClippedPathBoundingBox()),this.restore()}beginInlineImage(){Pt("Should not call beginInlineImage")}beginImageData(){Pt("Should not call beginImageData")}paintFormXObjectBegin(t,e){if(this.contentVisible&&(this.save(),this.baseTransformStack.push(this.baseTransform),t&&this.transform(...t),this.baseTransform=Nt(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(Nt(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=Nt(e);if(t.matrix&&e.transform(...t.matrix),!t.bbox)throw new Error("Bounding box is required.");let i=q.getAxialAlignedBoundingBox(t.bbox,Nt(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()),ul(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=Nt(this.ctx);this.restore(),this.ctx.save(),this.ctx.setTransform(...i);const n=q.getAxialAlignedBoundingBox([0,0,e.canvas.width,e.canvas.height],i);this.ctx.drawImage(e.canvas,0,0),this.ctx.restore(),this.compose(n)}}beginAnnotation(t,e,s,i,n){if(w(this,ci,zp).call(this),yd(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(Nt(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),yd(this.ctx)}else yd(this.ctx),this.endPath(),this.ctx.rect(e[0],e[1],r,a),this.ctx.clip(),this.ctx.beginPath()}this.current=new Xv(this.ctx.canvas.width,this.ctx.canvas.height),this.transform(...s),this.transform(...i)}endAnnotation(){this.annotationCanvas&&(this.ctx.restore(),w(this,ci,Gp).call(this),this.ctx=this.annotationCanvas.savedCtx,delete this.annotationCanvas.savedCtx,delete this.annotationCanvas)}paintImageMaskXObject(t){if(!this.contentVisible)return;const e=t.count;t=this.getObject(t.data,t),t.count=e;const s=this.ctx,i=this.processingType3;if(i&&(i.compiled===void 0&&(i.compiled=kS(t)),i.compiled)){i.compiled(s);return}const n=this._createMaskCanvas(t),r=n.canvas;s.save(),s.setTransform(1,0,0,1,0,0),s.drawImage(r,n.offsetX,n.offsetY),s.restore(),this.compose()}paintImageMaskXObjectRepeat(t,e,s=0,i=0,n,r){if(!this.contentVisible)return;t=this.getObject(t.data,t);const a=this.ctx;a.save();const h=Nt(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);Yv(d,f),d.globalCompositeOperation="source-in",d.fillStyle=i?s.getPattern(d,this,Ti(e),De.FILL):s,d.fillRect(0,0,a,h),d.restore(),e.save(),e.transform(...c),e.scale(1,-1),bd(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(),!Me){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;Uv(h,t),n=this.applyTransferMapsToCanvas(h)}const r=this._scaleImage(n,Ti(i));i.imageSmoothingEnabled=$v(Nt(i),t.interpolate),bd(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;Uv(h,t),i=this.applyTransferMapsToCanvas(h)}for(const n of e)s.save(),s.transform(...n.transform),s.scale(1,-1),bd(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===qv?s.clip("evenodd"):s.clip()),this.pendingClip=null),this.current.startNewPathAndClipBox(this.current.clipBox),s.beginPath()}getSinglePixelWidth(){if(!this._cachedGetSinglePixelWidth){const t=Nt(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}};ci=new WeakSet,zp=function(){for(;this.stateStack.length||this.inSMaskMode;)this.restore();this.current.activeSMask=null,this.ctx.restore(),this.transparentCanvas&&(this.ctx=this.compositeCtx,this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.drawImage(this.transparentCanvas,0,0),this.ctx.restore(),this.transparentCanvas=null)},Gp=function(){if(this.pageColors){const t=this.filterFactory.addHCMFilter(this.pageColors.foreground,this.pageColors.background);if(t!=="none"){const e=this.ctx.filter;this.ctx.filter=t,this.ctx.drawImage(this.ctx.canvas,0,0),this.ctx.filter=e}}},Vp=function(t,e,s){const i=new Path2D;return i.addPath(t,new DOMMatrix(s).invertSelf().multiplySelf(e)),i};let xo=fp;for(const o in ii)xo.prototype[o]!==void 0&&(xo.prototype[ii[o]]=xo.prototype[o]);class rn{static get workerPort(){return l(this,Xl)}static set workerPort(t){if(!(typeof Worker<"u"&&t instanceof Worker)&&t!==null)throw new Error("Invalid `workerPort` type.");m(this,Xl,t)}static get workerSrc(){return l(this,Ul)}static set workerSrc(t){if(typeof t!="string")throw new Error("Invalid `workerSrc` type.");m(this,Ul,t)}}Xl=new WeakMap,Ul=new WeakMap,y(rn,Xl,null),y(rn,Ul,"");class DS{constructor({parsedData:t,rawData:e}){y(this,ba);y(this,Yl);m(this,ba,t),m(this,Yl,e)}getRaw(){return l(this,Yl)}get(t){return l(this,ba).get(t)??null}getAll(){return Og(l(this,ba))}has(t){return l(this,ba).has(t)}}ba=new WeakMap,Yl=new WeakMap;const So=Symbol("INTERNAL");class RS{constructor(t,{name:e,intent:s,usage:i,rbGroups:n}){y(this,$l,!1);y(this,ql,!1);y(this,Kl,!1);y(this,Vo,!0);m(this,$l,!!(t&ps.DISPLAY)),m(this,ql,!!(t&ps.PRINT)),this.name=e,this.intent=s,this.usage=i,this.rbGroups=n}get visible(){if(l(this,Kl))return l(this,Vo);if(!l(this,Vo))return!1;const{print:t,view:e}=this.usage;return l(this,$l)?(e==null?void 0:e.viewState)!=="OFF":l(this,ql)?(t==null?void 0:t.printState)!=="OFF":!0}_setVisible(t,e,s=!1){t!==So&&Pt("Internal method `_setVisible` called."),m(this,Kl,s),m(this,Vo,e)}}$l=new WeakMap,ql=new WeakMap,Kl=new WeakMap,Vo=new WeakMap;class LS{constructor(t,e=ps.DISPLAY){y(this,Jl);y(this,ur,null);y(this,At,new Map);y(this,Wo,null);y(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,At).set(s.id,new RS(e,s));if(t.baseState==="OFF")for(const s of l(this,At).values())s._setVisible(So,!1);for(const s of t.on)l(this,At).get(s)._setVisible(So,!0);for(const s of t.off)l(this,At).get(s)._setVisible(So,!1);m(this,Wo,this.getHash())}}isVisible(t){if(l(this,At).size===0)return!0;if(!t)return ld("Optional content group not defined."),!0;if(t.type==="OCG")return l(this,At).has(t.id)?l(this,At).get(t.id).visible:(rt(`Optional content group not found: ${t.id}`),!0);if(t.type==="OCMD"){if(t.expression)return w(this,Jl,Wp).call(this,t.expression);if(!t.policy||t.policy==="AnyOn"){for(const e of t.ids){if(!l(this,At).has(e))return rt(`Optional content group not found: ${e}`),!0;if(l(this,At).get(e).visible)return!0}return!1}else if(t.policy==="AllOn"){for(const e of t.ids){if(!l(this,At).has(e))return rt(`Optional content group not found: ${e}`),!0;if(!l(this,At).get(e).visible)return!1}return!0}else if(t.policy==="AnyOff"){for(const e of t.ids){if(!l(this,At).has(e))return rt(`Optional content group not found: ${e}`),!0;if(!l(this,At).get(e).visible)return!0}return!1}else if(t.policy==="AllOff"){for(const e of t.ids){if(!l(this,At).has(e))return rt(`Optional content group not found: ${e}`),!0;if(l(this,At).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,At).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,At).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,At).get(i);if(n)switch(s){case"ON":this.setVisibility(i,!0,e);break;case"OFF":this.setVisibility(i,!1,e);break;case"Toggle":this.setVisibility(i,!n.visible,e);break}}m(this,ur,null)}get hasInitialVisibility(){return l(this,Wo)===null||this.getHash()===l(this,Wo)}getOrder(){return l(this,At).size?l(this,Xo)?l(this,Xo).slice():[...l(this,At).keys()]:null}getGroups(){return l(this,At).size>0?Og(l(this,At)):null}getGroup(t){return l(this,At).get(t)||null}getHash(){if(l(this,ur)!==null)return l(this,ur);const t=new Mv;for(const[e,s]of l(this,At))t.update(`${e}:${s.visible}`);return m(this,ur,t.hexdigest())}}ur=new WeakMap,At=new WeakMap,Wo=new WeakMap,Xo=new WeakMap,Jl=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,Jl,Wp).call(this,n);else if(l(this,At).has(n))r=l(this,At).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 FS{constructor(t,{disableRange:e=!1,disableStream:s=!1}){ne(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)});ne(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(){ne(!this._fullRequestReader,"PDFDataTransportStream.getFullReader can only be called once.");const t=this._queuedChunks;return this._queuedChunks=null,new IS(this,t,this._progressiveDone,this._contentDispositionFilename)}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new jS(this,t,e);return this._pdfDataRangeTransport.requestDataRange(t,e),this._rangeReaders.push(s),s}cancelAllRequests(t){var e;(e=this._fullRequestReader)==null||e.cancel(t);for(const s of this._rangeReaders.slice(0))s.cancel(t);this._pdfDataRangeTransport.abort()}}class IS{constructor(t,e,s=!1,i=null){this._stream=t,this._done=s||!1,this._filename=Ig(i)?i:null,this._queuedChunks=e||[],this._loaded=0;for(const n of this._queuedChunks)this._loaded+=n.byteLength;this._requests=[],this._headersReady=Promise.resolve(),t._fullRequestReader=this,this.onProgress=null}_enqueue(t){this._done||(this._requests.length>0?this._requests.shift().resolve({value:t,done:!1}):this._queuedChunks.push(t),this._loaded+=t.byteLength)}get headersReady(){return this._headersReady}get filename(){return this._filename}get isRangeSupported(){return this._stream._isRangeSupported}get isStreamingSupported(){return this._stream._isStreamingSupported}get contentLength(){return this._stream._contentLength}async read(){if(this._queuedChunks.length>0)return{value:this._queuedChunks.shift(),done:!1};if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}progressiveDone(){this._done||(this._done=!0)}}class jS{constructor(t,e,s){this._stream=t,this._begin=e,this._end=s,this._queuedChunk=null,this._requests=[],this._done=!1,this.onProgress=null}_enqueue(t){if(!this._done){if(this._requests.length===0)this._queuedChunk=t;else{this._requests.shift().resolve({value:t,done:!1});for(const s of this._requests)s.resolve({value:void 0,done:!0});this._requests.length=0}this._done=!0,this._stream._removeRangeReader(this)}}get isStreamingSupported(){return!1}async read(){if(this._queuedChunk){const e=this._queuedChunk;return this._queuedChunk=null,{value:e,done:!1}}if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._stream._removeRangeReader(this)}}function NS(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[,v,_,b]=f;if(v=parseInt(v,10),v in d){if(v===0)break;continue}d[v]=[_,b]}const p=[];for(let v=0;v<d.length&&v in d;++v){let[_,b]=d[v];b=a(b),_&&(b=unescape(b),v===0&&(b=h(b))),p.push(b)}return p.join("")}function a(u){if(u.startsWith('"')){const d=u.slice(1).split('\\"');for(let f=0;f<d.length;++f){const g=d[f].indexOf('"');g!==-1&&(d[f]=d[f].slice(0,g),d.length=f+1),d[f]=d[f].replaceAll(/\\(.)/g,"$1")}u=d.join('"')}return u}function h(u){const d=u.indexOf("'");if(d===-1)return u;const f=u.slice(0,d),p=u.slice(d+1).replace(/^[^']*'/,"");return i(f,p)}function c(u){return!u.startsWith("=?")||/[\x00-\x19\x80-\xff]/.test(u)?u:u.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,function(d,f,g,p){if(g==="q"||g==="Q")return p=p.replaceAll("_"," "),p=p.replaceAll(/=([0-9a-fA-F]{2})/g,function(v,_){return String.fromCharCode(parseInt(_,16))}),i(f,p);try{p=atob(p)}catch{}return i(f,p)})}return""}function Kv(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 Jv({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 Qv(o){const t=o.get("Content-Disposition");if(t){let e=NS(t);if(e.includes("%"))try{e=decodeURIComponent(e)}catch{}if(Ig(e))return e}return null}function wd(o,t){return o===404||o===0&&t.startsWith("file:")?new al('Missing PDF "'+t+'".'):new cd(`Unexpected server response (${o}) while retrieving PDF "${t}".`,o)}function Zv(o){return o===200||o===206}function tb(o,t,e){return{method:"GET",headers:o,signal:e.signal,mode:"cors",credentials:t?"include":"same-origin",redirect:"follow"}}function eb(o){return o instanceof Uint8Array?o.buffer:o instanceof ArrayBuffer?o:(rt(`getArrayBuffer - unexpected data format: ${o}`),new Uint8Array(o).buffer)}class sb{constructor(t){J(this,"_responseOrigin",null);this.source=t,this.isHttp=/^https?:/i.test(t.url),this.headers=Kv(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 ne(!this._fullRequestReader,"PDFFetchStream.getFullReader can only be called once."),this._fullRequestReader=new BS(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new HS(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 BS{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,tb(s,this._withCredentials,this._abortController)).then(n=>{if(t._responseOrigin=_d(n.url),!Zv(n.status))throw wd(n.status,i);this._reader=n.body.getReader(),this._headersCapability.resolve();const r=n.headers,{allowRangeRequests:a,suggestedLength:h}=Jv({responseHeaders:r,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=a,this._contentLength=h||this._contentLength,this._filename=Qv(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:eb(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}class HS{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,tb(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(!Zv(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:eb(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}const qg=200,Kg=206;function zS(o){const t=o.response;return typeof t!="string"?t:ud(t).buffer}class GS{constructor({url:t,httpHeaders:e,withCredentials:s}){J(this,"_responseOrigin",null);this.url=t,this.isHttp=/^https?:/i.test(t),this.headers=Kv(this.isHttp,e),this.withCredentials=s||!1,this.currXhrId=0,this.pendingRequests=Object.create(null)}request(t){const e=new XMLHttpRequest,s=this.currXhrId++,i=this.pendingRequests[s]={xhr:e};e.open("GET",this.url),e.withCredentials=this.withCredentials;for(const[n,r]of this.headers)e.setRequestHeader(n,r);return this.isHttp&&"begin"in t&&"end"in t?(e.setRequestHeader("Range",`bytes=${t.begin}-${t.end-1}`),i.expectedStatus=Kg):i.expectedStatus=qg,e.responseType="arraybuffer",ne(t.onError,"Expected `onError` callback to be provided."),e.onerror=()=>{t.onError(e.status)},e.onreadystatechange=this.onStateChange.bind(this,s),e.onprogress=this.onProgress.bind(this,s),i.onHeadersReceived=t.onHeadersReceived,i.onDone=t.onDone,i.onError=t.onError,i.onProgress=t.onProgress,e.send(null),s}onProgress(t,e){var i;const s=this.pendingRequests[t];s&&((i=s.onProgress)==null||i.call(s,e))}onStateChange(t,e){const s=this.pendingRequests[t];if(!s)return;const i=s.xhr;if(i.readyState>=2&&s.onHeadersReceived&&(s.onHeadersReceived(),delete s.onHeadersReceived),i.readyState!==4||!(t in this.pendingRequests))return;if(delete this.pendingRequests[t],i.status===0&&this.isHttp){s.onError(i.status);return}const n=i.status||qg;if(!(n===qg&&s.expectedStatus===Kg)&&n!==s.expectedStatus){s.onError(i.status);return}const a=zS(i);if(n===Kg){const h=i.getResponseHeader("Content-Range"),c=/bytes (\d+)-(\d+)\/(\d+)/.exec(h);c?s.onDone({begin:parseInt(c[1],10),chunk:a}):(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 VS{constructor(t){this._source=t,this._manager=new GS(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 ne(!this._fullRequestReader,"PDFNetworkStream.getFullReader can only be called once."),this._fullRequestReader=new WS(this._manager,this._source),this._fullRequestReader}getRangeReader(t,e){const s=new XS(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 WS{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}=Jv({responseHeaders:i,isHttp:this._manager.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});n&&(this._isRangeSupported=!0),this._contentLength=r||this._contentLength,this._filename=Qv(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 XS{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 US=/^[a-z][a-z0-9\-+.]+:/i;function YS(o){if(US.test(o))return new URL(o);const t=process.getBuiltinModule("url");return new URL(t.pathToFileURL(o))}class $S{constructor(t){this.source=t,this.url=YS(t.url),ne(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 ne(!this._fullRequestReader,"PDFNodeStream.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 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 qS{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 al(`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 KS{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 JS=1e5,as=30,QS=.8,ue=class ue{constructor({textContentSource:t,container:e,viewport:s}){y(this,yn);y(this,dr,Promise.withResolvers());y(this,hs,null);y(this,Ql,!1);y(this,Zl,!!((Cb=globalThis.FontInspector)!=null&&Cb.enabled));y(this,ya,null);y(this,bn,null);y(this,tc,0);y(this,ec,0);y(this,_a,null);y(this,Uo,null);y(this,Yo,0);y(this,fr,0);y(this,$o,Object.create(null));y(this,sc,[]);y(this,qo,null);y(this,wa,[]);y(this,ic,new WeakMap);y(this,nc,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,hs,m(this,Uo,e)),m(this,fr,s.scale*(globalThis.devicePixelRatio||1)),m(this,Yo,s.rotation),m(this,bn,{div:null,properties:null,ctx:null});const{pageWidth:i,pageHeight:n,pageX:r,pageY:a}=s.rawDims;m(this,nc,[1,0,0,-1,-r,a+n]),m(this,ec,i),m(this,tc,n),w(h=ue,_s,xy).call(h),Wr(e,s),l(this,dr).promise.finally(()=>{l(ue,Ko).delete(this),m(this,bn,null),m(this,$o,null)}).catch(()=>{})}static get fontFamilyMap(){const{isWindows:t,isFirefox:e}=Ue.platform;return lt(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,ya)??m(this,ya,e.lang),Object.assign(l(this,$o),e.styles),w(this,yn,_y).call(this,e.items),t()},l(this,dr).reject)};return m(this,_a,l(this,qo).getReader()),l(ue,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),Wr(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=ue,_s,of).call(n,l(this,ya))};for(const a of l(this,wa))r.properties=l(this,ic).get(a),r.div=a,w(this,yn,Xp).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,sc)}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,hs=new WeakMap,Ql=new WeakMap,Zl=new WeakMap,ya=new WeakMap,bn=new WeakMap,tc=new WeakMap,ec=new WeakMap,_a=new WeakMap,Uo=new WeakMap,Yo=new WeakMap,fr=new WeakMap,$o=new WeakMap,sc=new WeakMap,qo=new WeakMap,wa=new WeakMap,ic=new WeakMap,nc=new WeakMap,xa=new WeakMap,Sa=new WeakMap,rc=new WeakMap,gr=new WeakMap,Ko=new WeakMap,yn=new WeakSet,_y=function(t){var i,n;if(l(this,Ql))return;(n=l(this,bn)).ctx??(n.ctx=w(i=ue,_s,of).call(i,l(this,ya)));const e=l(this,wa),s=l(this,sc);for(const r of t){if(e.length>JS){rt("Ignoring additional textDivs for performance reasons."),m(this,Ql,!0);return}if(r.str===void 0){if(r.type==="beginMarkedContentProps"||r.type==="beginMarkedContent"){const a=l(this,hs);m(this,hs,document.createElement("span")),l(this,hs).classList.add("markedContent"),r.id!==null&&l(this,hs).setAttribute("id",`${r.id}`),a.append(l(this,hs))}else r.type==="endMarkedContent"&&m(this,hs,l(this,hs).parentNode);continue}s.push(r.str),w(this,yn,wy).call(this,r)}},wy=function(t){var v;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,nc),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,Zl)&&r.fontSubstitution||r.fontFamily;a=ue.fontFamilyMap.get(a)||a;const h=Math.hypot(i[2],i[3]),c=h*w(v=ue,_s,Sy).call(v,a,l(this,ya));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,hs)===l(this,Uo)?(g.left=`${(100*u/l(this,ec)).toFixed(2)}%`,g.top=`${(100*d/l(this,tc)).toFixed(2)}%`):(g.left=`${f}${u.toFixed(2)}px)`,g.top=`${f}${d.toFixed(2)}px)`),g.fontSize=`${f}${(l(ue,gr)*h).toFixed(2)}px)`,g.fontFamily=a,s.fontSize=h,e.setAttribute("role","presentation"),e.textContent=t.str,e.dir=t.dir,l(this,Zl)&&(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]),b=Math.abs(t.transform[3]);_!==b&&Math.max(_,b)/Math.min(_,b)>1.5&&(p=!0)}if(p&&(s.canvasWidth=r.vertical?t.height:t.width),l(this,ic).set(e,s),l(this,bn).div=e,l(this,bn).properties=s,w(this,yn,Xp).call(this,l(this,bn)),s.hasText&&l(this,hs).append(e),s.hasEOL){const _=document.createElement("br");_.setAttribute("role","presentation"),l(this,hs).append(_)}},Xp=function(t){var a;const{div:e,properties:s,ctx:i}=t,{style:n}=e;let r="";if(l(ue,gr)>1&&(r=`scale(${1/l(ue,gr)})`),s.canvasWidth!==0&&s.hasText){const{fontFamily:h}=n,{canvasWidth:c,fontSize:u}=s;w(a=ue,_s,Up).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)},_s=new WeakSet,of=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,rc).set(e,{size:0,family:""})}return e},Up=function(t,e,s){const i=l(this,rc).get(t);e===i.size&&s===i.family||(t.font=`${e}px ${s}`,i.size=e,i.family=s)},xy=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()},Sy=function(t,e){const s=l(this,xa).get(t);if(s)return s;const i=w(this,_s,of).call(this,e);i.canvas.width=i.canvas.height=as,w(this,_s,Up).call(this,i,as,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,as,as),i.strokeText("g",0,0);let h=i.getImageData(0,0,as,as).data;a=0;for(let u=h.length-1-3;u>=0;u-=4)if(h[u]>0){a=Math.ceil(u/4/as);break}i.clearRect(0,0,as,as),i.strokeText("A",0,as),h=i.getImageData(0,0,as,as).data,r=0;for(let u=0,d=h.length;u<d;u+=4)if(h[u]>0){r=as-Math.floor(u/4/as);break}i.canvas.width=i.canvas.height=0;const c=r?r/(r+a):QS;return l(this,xa).set(t,c),c},y(ue,_s),y(ue,xa,new Map),y(ue,Sa,new Map),y(ue,rc,new WeakMap),y(ue,gr,null),y(ue,Ko,new Set);let dl=ue;class fl{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(fl.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 ZS=65536,tC=100,eC=5e3,sC=Me?mS:fS,iC=Me?vS:Fv,nC=Me?pS:gS,rC=Me?bS:Nv;function aC(o={}){typeof o=="string"||o instanceof URL?o={url:o}:(o instanceof ArrayBuffer||ArrayBuffer.isView(o))&&(o={data:o});const t=new Jg,{docId:e}=t,s=o.url?oC(o.url):null,i=o.data?hC(o.data):null,n=o.httpHeaders||null,r=o.withCredentials===!0,a=o.password??null,h=o.range instanceof nb?o.range:null,c=Number.isInteger(o.rangeChunkSize)&&o.rangeChunkSize>0?o.rangeChunkSize:ZS;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,v=o.CMapReaderFactory||iC,_=typeof o.standardFontDataUrl=="string"?o.standardFontDataUrl:null,b=o.StandardFontDataFactory||rC,x=o.stopAtErrors!==!0,S=Number.isInteger(o.maxImageSize)&&o.maxImageSize>-1?o.maxImageSize:-1,A=o.isEvalSupported!==!1,k=typeof o.isOffscreenCanvasSupported=="boolean"?o.isOffscreenCanvasSupported:!Me,M=typeof o.isImageDecoderSupported=="boolean"?o.isImageDecoderSupported:!Me&&(Ue.platform.isFirefox||!globalThis.chrome),D=Number.isInteger(o.canvasMaxAreaInBytes)?o.canvasMaxAreaInBytes:-1,P=typeof o.disableFontFace=="boolean"?o.disableFontFace:Me,R=o.fontExtraProperties===!0,F=o.enableXfa===!0,I=o.ownerDocument||globalThis.document,H=o.disableRange===!0,W=o.disableStream===!0,B=o.disableAutoFetch===!0,ht=o.pdfBug===!0,j=o.CanvasFactory||sC,z=o.FilterFactory||nC,at=o.enableHWA===!0,Mt=h?h.length:o.length??NaN,Lt=typeof o.useSystemFonts=="boolean"?o.useSystemFonts:!Me&&!P,$t=typeof o.useWorkerFetch=="boolean"?o.useWorkerFetch:v===Fv&&b===Nv&&g&&_&&hl(g,document.baseURI)&&hl(_,document.baseURI),it=null;Xx(d);const ut={canvasFactory:new j({ownerDocument:I,enableHWA:at}),filterFactory:new z({docId:e,ownerDocument:I}),cMapReaderFactory:$t?null:new v({baseUrl:g,isCompressed:p}),standardFontDataFactory:$t?null:new b({baseUrl:_})};if(!u){const kt={verbosity:d,port:rn.workerPort};u=kt.port?Co.fromPort(kt):new Co(kt),t._worker=u}const Ft={docId:e,apiVersion:"4.10.38",data:i,password:a,disableAutoFetch:B,rangeChunkSize:c,length:Mt,docBaseUrl:f,enableXfa:F,evaluatorOptions:{maxImageSize:S,disableFontFace:P,ignoreErrors:x,isEvalSupported:A,isOffscreenCanvasSupported:k,isImageDecoderSupported:M,canvasMaxAreaInBytes:D,fontExtraProperties:R,useSystemFonts:Lt,cMapUrl:$t?g:null,standardFontDataUrl:$t?_:null}},us={disableFontFace:P,fontExtraProperties:R,ownerDocument:I,pdfBug:ht,styleElement:it,loadingParams:{disableAutoFetch:B,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 kt=u.messageHandler.sendWithPromise("GetDocRequest",Ft,i?[i.buffer]:null);let dt;if(h)dt=new FS(h,{disableRange:H,disableStream:W});else if(!i){if(!s)throw new Error("getDocument - no `url` parameter provided.");let Ne;if(Me)if(hl(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`.");Ne=sb}else Ne=$S;else Ne=hl(s)?sb:VS;dt=new Ne({url:s,length:Mt,httpHeaders:n,withCredentials:r,rangeChunkSize:c,disableRange:H,disableStream:W})}return kt.then(Ne=>{if(t.destroyed)throw new Error("Loading aborted");if(u.destroyed)throw new Error("Worker was destroyed");const Os=new cl(e,Ne,u.port),qt=new dC(Os,t,dt,us,ut);t._transport=qt,Os.send("Ready",null)})}).catch(t._capability.reject),t}function oC(o){if(o instanceof URL)return o.href;try{return new URL(o,window.location).href}catch{if(Me&&typeof o=="string")return o}throw new Error("Invalid PDF url data: either string or URL-object is expected in the url property.")}function hC(o){if(Me&&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 ib(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${ts(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,y(Id,Fd,0);let Jg=Id;class nb{constructor(t,e,s=!1,i=null){this.length=t,this.initialData=e,this.progressiveDone=s,this.contentDispositionFilename=i,this._rangeListeners=[],this._progressListeners=[],this._progressiveReadListeners=[],this._progressiveDoneListeners=[],this._readyCapability=Promise.withResolvers()}addRangeListener(t){this._rangeListeners.push(t)}addProgressListener(t){this._progressListeners.push(t)}addProgressiveReadListener(t){this._progressiveReadListeners.push(t)}addProgressiveDoneListener(t){this._progressiveDoneListeners.push(t)}onDataRange(t,e){for(const s of this._rangeListeners)s(t,e)}onDataProgress(t,e){this._readyCapability.promise.then(()=>{for(const s of this._progressListeners)s(t,e)})}onDataProgressiveRead(t){this._readyCapability.promise.then(()=>{for(const e of this._progressiveReadListeners)e(t)})}onDataProgressiveDone(){this._readyCapability.promise.then(()=>{for(const t of this._progressiveDoneListeners)t()})}transportReady(){this._readyCapability.resolve()}requestDataRange(t,e){Pt("Abstract method PDFDataRangeTransport.requestDataRange")}abort(){}}class lC{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 lt(this,"isPureXfa",!!this._transport._htmlForXfa)}get allXfaHtml(){return this._transport._htmlForXfa}getPage(t){return this._transport.getPage(t)}getPageIndex(t){return this._transport.getPageIndex(t)}getDestinations(){return this._transport.getDestinations()}getDestination(t){return this._transport.getDestination(t)}getPageLabels(){return this._transport.getPageLabels()}getPageLayout(){return this._transport.getPageLayout()}getPageMode(){return this._transport.getPageMode()}getViewerPreferences(){return this._transport.getViewerPreferences()}getOpenAction(){return this._transport.getOpenAction()}getAttachments(){return this._transport.getAttachments()}getJSActions(){return this._transport.getDocJSActions()}getOutline(){return this._transport.getOutline()}getOptionalContentConfig({intent:t="display"}={}){const{renderingIntent:e}=this._transport.getRenderingIntent(t);return this._transport.getOptionalContentConfig(e)}getPermissions(){return this._transport.getPermissions()}getMetadata(){return this._transport.getMetadata()}getMarkInfo(){return this._transport.getMarkInfo()}getData(){return this._transport.getData()}saveDocument(){return this._transport.saveDocument()}getDownloadInfo(){return this._transport.downloadInfoCapability.promise}cleanup(t=!1){return this._transport.startCleanup(t||this.isPureXfa)}destroy(){return this.loadingTask.destroy()}cachedPageNumber(t){return this._transport.cachedPageNumber(t)}get loadingParams(){return this._transport.loadingParams}get loadingTask(){return this._transport.loadingTask}getFieldObjects(){return this._transport.getFieldObjects()}hasJSActions(){return this._transport.hasJSActions()}getCalculationOrderIds(){return this._transport.getCalculationOrderIds()}}class cC{constructor(t,e,s,i=!1){y(this,zs);y(this,pr,null);y(this,_n,!1);this._pageIndex=t,this._pageInfo=e,this._transport=s,this._stats=i?new kv:null,this._pdfBug=i,this.commonObjs=s.commonObjs,this.objs=new rb,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 ol({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 lt(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,k;(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,zs,hf).call(this),a||(a=this._transport.getOptionalContentConfig(g));let v=this._intentStates.get(p);v||(v=Object.create(null),this._intentStates.set(p,v)),v.streamReaderCancelTimeout&&(clearTimeout(v.streamReaderCancelTimeout),v.streamReaderCancelTimeout=null);const _=!!(g&ps.PRINT);v.displayReadyCapability||(v.displayReadyCapability=Promise.withResolvers(),v.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(k=this._stats)==null||k.time("Page Request"),this._pumpOperatorList(f));const b=M=>{var D;v.renderTasks.delete(x),(this._maybeCleanupAfterRender||_)&&m(this,_n,!0),w(this,zs,jh).call(this,!_),M?(x.capability.reject(M),this._abortOperatorList({intentState:v,reason:M instanceof Error?M:new Error(M)})):x.capability.resolve(),this._stats&&(this._stats.timeEnd("Rendering"),this._stats.timeEnd("Overall"),(D=globalThis.Stats)!=null&&D.enabled&&globalThis.Stats.add(this.pageNumber,this._stats))},x=new Qg({callback:b,params:{canvasContext:t,viewport:e,transform:n,background:r},objs:this.objs,commonObjs:this.commonObjs,annotationCanvasMap:h,operatorList:v.operatorList,pageIndex:this._pageIndex,canvasFactory:this._transport.canvasFactory,filterFactory:this._transport.filterFactory,useRequestAnimationFrame:!_,pdfBug:this._pdfBug,pageColors:c});(v.renderTasks||(v.renderTasks=new Set)).add(x);const S=x.task;return Promise.all([v.displayReadyCapability.promise,a]).then(([M,D])=>{var P;if(this.destroyed){b();return}if((P=this._stats)==null||P.time("Rendering"),!(D.renderingIntent&g))throw new Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");x.initializeGraphics({transparency:M,optionalContentConfig:D}),x.operatorListChanged()}).catch(b),S}getOperatorList({intent:t="display",annotationMode:e=Yn.ENABLE,printAnnotationStorage:s=null,isEditing:i=!1}={}){var c;function n(){a.operatorList.lastChunk&&(a.opListReadCapability.resolve(a.operatorList),a.renderTasks.delete(h))}const r=this._transport.getRenderingIntent(t,e,s,i,!0);let a=this._intentStates.get(r.cacheKey);a||(a=Object.create(null),this._intentStates.set(r.cacheKey,a));let h;return a.opListReadCapability||(h=Object.create(null),h.operatorListChanged=n,a.opListReadCapability=Promise.withResolvers(),(a.renderTasks||(a.renderTasks=new Set)).add(h),a.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(c=this._stats)==null||c.time("Page Request"),this._pumpOperatorList(r)),a.opListReadCapability.promise}streamTextContent({includeMarkedContent:t=!1,disableNormalization:e=!1}={}){return this._transport.messageHandler.sendWithStream("GetTextContent",{pageIndex:this._pageIndex,includeMarkedContent:t===!0,disableNormalization:e===!0},{highWaterMark:100,size(i){return i.items.length}})}getTextContent(t={}){if(this._transport._htmlForXfa)return this.getXfa().then(s=>fl.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,zs,hf).call(this),Promise.all(t)}cleanup(t=!1){m(this,_n,!0);const e=w(this,zs,jh).call(this,!1);return t&&e&&this._stats&&(this._stats=new kv),e}_startRenderPage(t,e){var i,n;const s=this._intentStates.get(e);s&&((i=this._stats)==null||i.timeEnd("Page Request"),(n=s.displayReadyCapability)==null||n.resolve(t))}_renderPageChunk(t,e){for(let s=0,i=t.length;s<i;s++)e.operatorList.fnArray.push(t.fnArray[s]),e.operatorList.argsArray.push(t.argsArray[s]);e.operatorList.lastChunk=t.lastChunk,e.operatorList.separateAnnots=t.separateAnnots;for(const s of e.renderTasks)s.operatorListChanged();t.lastChunk&&w(this,zs,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,zs,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 Fg){let i=tC;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,zs=new WeakSet,jh=function(t=!1){if(w(this,zs,hf).call(this),!l(this,_n)||this.destroyed)return!1;if(t)return m(this,pr,setTimeout(()=>{m(this,pr,null),w(this,zs,jh).call(this,!1)},eC)),!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},hf=function(){l(this,pr)&&(clearTimeout(l(this,pr)),m(this,pr,null))};class uC{constructor(){y(this,wn,new Map);y(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 Bt=class Bt{constructor({name:t=null,port:e=null,verbosity:s=Ux()}={}){y(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(Bt,Aa))!=null&&i.has(e))throw new Error("Cannot use more than one PDFWorker per port.");(l(Bt,Aa)||m(Bt,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 cl("main","worker",t),this._messageHandler.on("ready",function(){}),w(this,Jo,lf).call(this)}_initialize(){if(l(Bt,Ca)||l(Bt,Qo,cf)){this._setupFakeWorker();return}let{workerSrc:t}=Bt;try{Bt._isSameOrigin(window.location.href,t)||(t=Bt._createCDNWrapper(new URL(t,window.location).href));const e=new Worker(t,{type:"module"}),s=new cl("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,lf).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(Bt,Ca)||(rt("Setting up fake worker."),m(Bt,Ca,!0)),Bt._setupFakeWorkerGlobal.then(t=>{if(this.destroyed){this._readyCapability.reject(new Error("Worker was destroyed"));return}const e=new uC;this._port=e;const s=`fake${ts(Bt,Nd)._++}`,i=new cl(s+"_worker",s,e);t.setup(i,e),this._messageHandler=new cl(s,s+"_worker",e),w(this,Jo,lf).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(Bt,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 Bt(t)}static get workerSrc(){if(rn.workerSrc)return rn.workerSrc;throw new Error('No "GlobalWorkerOptions.workerSrc" specified.')}static get _setupFakeWorkerGlobal(){return lt(this,"_setupFakeWorkerGlobal",(async()=>l(this,Qo,cf)?l(this,Qo,cf):(await import(this.workerSrc)).WorkerMessageHandler)())}};Nd=new WeakMap,Ca=new WeakMap,Aa=new WeakMap,Jo=new WeakSet,lf=function(){this._readyCapability.resolve(),this._messageHandler.send("configure",{verbosity:this.verbosity})},Qo=new WeakSet,cf=function(){var t;try{return((t=globalThis.pdfjsWorker)==null?void 0:t.WorkerMessageHandler)||null}catch{return null}},y(Bt,Qo),y(Bt,Nd,0),y(Bt,Ca,!1),y(Bt,Aa),Me&&(m(Bt,Ca,!0),rn.workerSrc||(rn.workerSrc="./pdf.worker.mjs")),Bt._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},Bt._createCDNWrapper=t=>{const e=`await import("${t}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))};let Co=Bt;class dC{constructor(t,e,s,i,n){y(this,Ta);y(this,xn,new Map);y(this,ji,new Map);y(this,Zo,new Map);y(this,th,new Map);y(this,Sn,null);this.messageHandler=t,this.loadingTask=e,this.commonObjs=new rb,this.fontLoader=new uS({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 lt(this,"annotationStorage",new Wg)}getRenderingIntent(t,e=Yn.ENABLE,s=null,i=!1,n=!1){let r=ps.DISPLAY,a=Vg;switch(t){case"any":r=ps.ANY;break;case"display":break;case"print":r=ps.PRINT;break;default:rt(`getRenderingIntent - invalid intent: ${t}`)}const h=r&ps.PRINT&&s instanceof Ov?s:this.annotationStorage;switch(e){case Yn.DISABLE:r+=ps.ANNOTATIONS_DISABLE;break;case Yn.ENABLE:break;case Yn.ENABLE_FORMS:r+=ps.ANNOTATIONS_FORMS;break;case Yn.ENABLE_STORAGE:r+=ps.ANNOTATIONS_STORAGE,a=h.serializable;break;default:rt(`getRenderingIntent - invalid annotationMode: ${e}`)}i&&(r+=ps.IS_EDITING),n&&(r+=ps.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,ji).values())t.push(i._destroy());l(this,ji).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(),dl.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)=>{ne(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}ne(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)=>{ne(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}ne(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 lC(s,this))}),t.on("DocException",s=>{e._capability.reject(ns(s))}),t.on("PasswordRequest",s=>{m(this,Sn,Promise.withResolvers());try{if(!e.onPassword)throw ns(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,ji).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 dS(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;ne(f,"The imageRef must be defined.");for(const g of l(this,ji).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,ji).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)>zx&&(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 cC(e,n,this,this._params.pdfBug);return l(this,ji).set(e,r),r});return l(this,Zo).set(e,i),i}getPageIndex(t){return ib(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 LS(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 DS(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,ji).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),dl.cleanup()}}cachedPageNumber(t){if(!ib(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,ji=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 gl=Symbol("INITIAL_DATA");class rb{constructor(){y(this,ac);y(this,ws,Object.create(null))}get(t,e=null){if(e){const i=w(this,ac,Yp).call(this,t);return i.promise.then(()=>e(i.data)),null}const s=l(this,ws)[t];if(!s||s.data===gl)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return s.data}has(t){const e=l(this,ws)[t];return!!e&&e.data!==gl}delete(t){const e=l(this,ws)[t];return!e||e.data===gl?!1:(delete l(this,ws)[t],!0)}resolve(t,e=null){const s=w(this,ac,Yp).call(this,t);s.data=e,s.resolve()}clear(){var t;for(const e in l(this,ws)){const{data:s}=l(this,ws)[e];(t=s==null?void 0:s.bitmap)==null||t.close()}m(this,ws,Object.create(null))}*[Symbol.iterator](){for(const t in l(this,ws)){const{data:e}=l(this,ws)[t];e!==gl&&(yield[t,e])}}}ws=new WeakMap,ac=new WeakSet,Yp=function(t){var e;return(e=l(this,ws))[t]||(e[t]={...Promise.withResolvers(),data:gl})};class fC{constructor(t){y(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}){y(this,vr,null);this.callback=t,this.params=e,this.objs=s,this.commonObjs=i,this.annotationCanvasMap=n,this.operatorListIdx=null,this.operatorList=r,this._pageIndex=a,this.canvasFactory=h,this.filterFactory=c,this._pdfBug=d,this.pageColors=f,this.running=!1,this.graphicsReadyCallback=null,this.graphicsReady=!1,this._useRequestAnimationFrame=u===!0&&typeof window<"u",this.cancelled=!1,this.capability=Promise.withResolvers(),this.task=new fC(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,vr)&&(window.cancelAnimationFrame(l(this,vr)),m(this,vr,null)),l(ka,Ea).delete(this._canvas),this.callback(t||new Fg(`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,vr,window.requestAnimationFrame(()=>{m(this,vr,null),this._nextBound().catch(this._cancelBound)})):Promise.resolve().then(this._nextBound).catch(this._cancelBound)}async _next(){this.cancelled||(this.operatorListIdx=this.gfx.executeOperatorList(this.operatorList,this.operatorListIdx,this._continueBound,this.stepper),this.operatorListIdx===this.operatorList.argsArray.length&&(this.running=!1,this.operatorList.lastChunk&&(this.gfx.endDrawing(),l(ka,Ea).delete(this._canvas),this.callback())))}};vr=new WeakMap,Ea=new WeakMap,y(ka,Ea,new WeakSet);let Qg=ka;const gC="4.10.38",pC="f9bea397f";function ab(o){return Math.floor(Math.max(0,Math.min(1,o))*255).toString(16).padStart(2,"0")}function pl(o){return Math.max(0,Math.min(255,255*o))}class ob{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=pl(t),[t,t,t]}static G_HTML([t]){const e=ab(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(pl)}static RGB_HTML(t){return`#${t.map(ab).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[pl(1-Math.min(1,t+i)),pl(1-Math.min(1,s+i)),pl(1-Math.min(1,e+i))]}static CMYK_HTML(t){const e=this.CMYK_RGB(t).slice(1);return this.RGB_HTML(e)}static RGB_CMYK([t,e,s]){const i=1-t,n=1-e,r=1-s,a=Math.min(i,n,r);return["CMYK",i,n,r,a]}}class mC{create(t,e,s=!1){if(t<=0||e<=0)throw new Error("Invalid SVG dimensions");const i=this._createSVG("svg:svg");return i.setAttribute("version","1.1"),s||(i.setAttribute("width",`${t}px`),i.setAttribute("height",`${e}px`)),i.setAttribute("preserveAspectRatio","none"),i.setAttribute("viewBox",`0 0 ${t} ${e}`),i}createElement(t){if(typeof t!="string")throw new Error("Invalid SVG element type");return this._createSVG(t)}_createSVG(t){Pt("Abstract method `_createSVG` called.")}}class Zg extends mC{_createSVG(t){return document.createElementNS(nn,t)}}class hb{static setupStorage(t,e,s,i,n){const r=i.getValue(e,{value:null});switch(s.name){case"textarea":if(r.value!==null&&(t.textContent=r.value),n==="print")break;t.addEventListener("input",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&&fl.shouldBuildText(i.name)&&c.push(g)}return{textDivs:c}}const u=[[i,-1,r]];for(;u.length>0;){const[g,p,v]=u.at(-1);if(p+1===g.children.length){u.pop();continue}const _=g.children[++u.at(-1)[1]];if(_===null)continue;const{name:b}=_;if(b==="#text"){const S=document.createTextNode(_.value);c.push(S),v.append(S);continue}const x=(d=_==null?void 0:_.attributes)!=null&&d.xmlns?document.createElementNS(_.attributes.xmlns,b):document.createElement(b);if(v.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 S=document.createTextNode(_.value);a&&fl.shouldBuildText(b)&&c.push(S),x.append(S)}}for(const g of h.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea"))g.setAttribute("readOnly",!0);return{textDivs:c}}static update(t){const e=`matrix(${t.viewport.transform.join(",")})`;t.div.style.transform=e,t.div.hidden=!1}}const ml=1e3,vC=9,Ur=new WeakSet;function Jn(o){return{width:o[2]-o[0],height:o[3]-o[1]}}class bC{static create(t){switch(t.data.annotationType){case le.LINK:return new lb(t);case le.TEXT:return new yC(t);case le.WIDGET:switch(t.data.fieldType){case"Tx":return new _C(t);case"Btn":return t.data.radioButton?new cb(t):t.data.checkBox?new xC(t):new SC(t);case"Ch":return new CC(t);case"Sig":return new wC(t)}return new Yr(t);case le.POPUP:return new tp(t);case le.FREETEXT:return new ub(t);case le.LINE:return new TC(t);case le.SQUARE:return new EC(t);case le.CIRCLE:return new kC(t);case le.POLYLINE:return new db(t);case le.CARET:return new MC(t);case le.INK:return new ep(t);case le.POLYGON:return new PC(t);case le.HIGHLIGHT:return new fb(t);case le.UNDERLINE:return new OC(t);case le.SQUIGGLY:return new DC(t);case le.STRIKEOUT:return new RC(t);case le.STAMP:return new gb(t);case le.FILEATTACHMENT:return new LC(t);default:return new Qt(t)}}}const gp=class gp{constructor(t,{isRenderable:e=!1,ignoreBorder:s=!1,createQuadrilaterals:i=!1}={}){y(this,oc);y(this,Pa,null);y(this,eh,!1);y(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 gp._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,oc,$p).call(this,e),(s=l(this,sh))==null||s.popup.updateEdited(t)}resetEdited(){var t;l(this,Pa)&&(w(this,oc,$p).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=ml);const{style:r}=n;if(r.zIndex=this.parent.zIndex++,e.alternativeText&&(n.title=e.alternativeText),e.noRotate&&n.classList.add("norotate"),!e.rect||this instanceof tp){const{rotation:v}=e;return!e.hasOwnCanvas&&v!==0&&this.setRotation(v,n),n}const{width:a,height:h}=Jn(e.rect);if(!t&&e.borderStyle.width>0){r.borderWidth=`${e.borderStyle.width}px`;const v=e.borderStyle.horizontalCornerRadius,_=e.borderStyle.verticalCornerRadius;if(v>0||_>0){const x=`calc(${v}px * var(--scale-factor)) / calc(${_}px * var(--scale-factor))`;r.borderRadius=x}else if(this instanceof cb){const x=`calc(${a}px * var(--scale-factor)) / calc(${h}px * var(--scale-factor))`;r.borderRadius=x}switch(e.borderStyle.style){case rl.SOLID:r.borderStyle="solid";break;case rl.DASHED:r.borderStyle="dashed";break;case rl.BEVELED:rt("Unimplemented border style: beveled");break;case rl.INSET:rt("Unimplemented border style: inset");break;case rl.UNDERLINE:r.borderBottomStyle="solid";break}const b=e.borderColor||null;b?(m(this,eh,!0),r.borderColor=q.makeHexColor(b[0]|0,b[1]|0,b[2]|0)):r.borderWidth=0}const c=q.normalizeRect([e.rect[0],s.view[3]-e.rect[1]+s.view[1],e.rect[2],s.view[3]-e.rect[3]+s.view[1]]),{pageWidth:u,pageHeight:d,pageX:f,pageY:g}=i.rawDims;r.left=`${100*(c[0]-f)/u}%`,r.top=`${100*(c[1]-g)/d}%`;const{rotation:p}=e;return e.hasOwnCanvas||p===0?(r.width=`${100*a/u}%`,r.height=`${100*h/d}%`):this.setRotation(p,n),n}setRotation(t,e=this.container){if(!this.data.rect)return;const{pageWidth:s,pageHeight:i}=this.parent.viewport.rawDims,{width:n,height:r}=Jn(this.data.rect);let a,h;t%180===0?(a=100*n/s,h=100*r/i):(a=100*r/s,h=100*n/i),e.style.width=`${a}%`,e.style.height=`${h}%`,e.setAttribute("data-main-rotation",(360-t)%360)}get _commonActions(){const t=(e,s,i)=>{const n=i.detail[e],r=n[0],a=n.slice(1);i.target.style[s]=ob[`${r}_HTML`](a),this.annotationStorage.setValue(this.data.id,{[s]:ob[`${r}_rgb`](a)})};return lt(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(v=>Math.fround(v));if(t.length===8){const[v,_,b,x]=t.subarray(2,6);if(i===v&&n===_&&e===b&&s===x)return}const{style:r}=this.container;let a;if(l(this,eh)){const{borderColor:v,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="${v}" 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 v=2,_=t.length;v<_;v+=8){const b=t[v],x=t[v+1],S=t[v+2],A=t[v+3],k=u.createElement("rect"),M=(S-e)/h,D=(n-x)/c,P=(b-S)/h,R=(x-A)/c;k.setAttribute("x",M),k.setAttribute("y",D),k.setAttribute("width",P),k.setAttribute("height",R),g.append(k),a==null||a.push(`<rect vector-effect="non-scaling-stroke" x="${M}" y="${D}" width="${P}" 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 tp({data:{color:t.color,titleObj:t.titleObj,modificationDate:t.modificationDate,contentsObj:t.contentsObj,richText:t.richText,parentRect:t.rect,borderStyle:0,id:`popup_${t.id}`,rotation:t.rotation},parent:this.parent,elements:[this]}));this.parent.div.append(e.render())}render(){Pt("Abstract method `AnnotationElement.render` called")}_getElementsByName(t,e=null){const s=[];if(this._fieldObjects){const i=this._fieldObjects[t];if(i)for(const{page:n,id:r,exportValues: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,oc=new WeakSet,$p=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=gp;class lb extends Qt{constructor(e,s=null){super(e,{isRenderable:!0,ignoreBorder:!!(s!=null&&s.ignoreBorder),createQuadrilaterals:!0});y(this,xs);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,xs,Cy).call(this,i,e.attachment,e.attachmentDest),n=!0):e.setOCGState?(w(this,xs,Ay).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,xs,so).call(this)}_bindNamedAction(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeNamedAction(s),!1),w(this,xs,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,xs,so).call(this)}_bindResetFormAction(e,s){const i=e.onclick;if(i||(e.href=this.linkService.getAnchorUrl("")),w(this,xs,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:v}of p)f.add(v)}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 v=f.defaultValue||"";c.setValue(g,{value:v});break}case"checkbox":case"radiobutton":{const v=f.defaultValue===f.exportValues;c.setValue(g,{value:v});break}case"combobox":case"listbox":{const v=f.defaultValue||"";c.setValue(g,{value:v});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}}}xs=new WeakSet,so=function(){this.container.setAttribute("data-internal-link","")},Cy=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,xs,so).call(this)},Ay=function(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeSetOCGState(s),!1),w(this,xs,so).call(this)};class yC 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 Ue.platform.isMac?t.metaKey:t.ctrlKey}_setEventListener(t,e,s,i,n){s.includes("mouse")?t.addEventListener(s,r=>{var a;(a=this.linkService.eventBus)==null||a.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:i,value:n(r),shift:r.shiftKey,modifier:this._getKeyModifier(r)}})}):t.addEventListener(s,r=>{var a;if(s==="blur"){if(!e.focused||!r.relatedTarget)return;e.focused=!1}else if(s==="focus"){if(e.focused)return;e.focused=!0}n&&((a=this.linkService.eventBus)==null||a.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:i,value:n(r)}}))})}_setEventListeners(t,e,s,i){var n,r,a;for(const[h,c]of s)(c==="Action"||(n=this.data.actions)!=null&&n[c])&&((c==="Focus"||c==="Blur")&&(e||(e={focused:!1})),this._setEventListener(t,e,h,c,i),c==="Focus"&&!((r=this.data.actions)!=null&&r.Blur)?this._setEventListener(t,e,"blur","Blur",null):c==="Blur"&&!((a=this.data.actions)!=null&&a.Focus)&&this._setEventListener(t,e,"focus","Focus",null))}_setBackgroundColor(t){const e=this.data.backgroundColor||null;t.style.backgroundColor=e===null?"transparent":q.makeHexColor(e[0],e[1],e[2])}_setTextStyle(t){const e=["left","center","right"],{fontColor:s}=this.data.defaultAppearanceData,i=this.data.defaultAppearanceData.fontSize||vC,n=t.style;let r;const a=2,h=c=>Math.round(10*c)/10;if(this.data.multiLine){const c=Math.abs(this.data.rect[3]-this.data.rect[1]-a),u=Math.round(c/(kg*i))||1,d=c/u;r=Math.min(i,h(d/kg))}else{const c=Math.abs(this.data.rect[3]-this.data.rect[1]-a);r=Math.min(i,h(c/kg))}n.fontSize=`calc(${r}px * var(--scale-factor))`,n.color=q.makeHexColor(s[0],s[1],s[2]),this.data.textAlignment!==null&&(n.textAlign=e[this.data.textAlignment])}_setRequired(t,e){e?t.setAttribute("required",!0):t.removeAttribute("required"),t.setAttribute("aria-required",e)}}class _C 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=ml,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 v;if(u.focused)return;const{target:p}=g;u.userValue&&(p.value=u.userValue),u.lastCommittedValue=p.value,u.commitKey=1,(v=this.data.actions)!=null&&v.Focus||(u.focused=!0)}),s.addEventListener("updatefromsandbox",g=>{this.showElementAndHideCanvas(g.target);const p={value(v){u.userValue=v.detail.value??"",t.setValue(e,{value:u.userValue.toString()}),v.target.value=u.userValue},formattedValue(v){const{formattedValue:_}=v.detail;u.formattedValue=_,_!=null&&v.target!==document.activeElement&&(v.target.value=_),t.setValue(e,{formattedValue:_})},selRange(v){v.target.setSelectionRange(...v.detail.selRange)},charLimit:v=>{var S;const{charLimit:_}=v.detail,{target:b}=v;if(_===0){b.removeAttribute("maxLength");return}b.setAttribute("maxLength",_);let x=u.userValue;!x||x.length<=_||(x=x.slice(0,_),b.value=u.userValue=x,t.setValue(e,{value:x}),(S=this.linkService.eventBus)==null||S.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:x,willCommit:!0,commitKey:1,selStart:b.selectionStart,selEnd:b.selectionEnd}}))}};this._dispatchEventFromSandbox(p,g)}),s.addEventListener("keydown",g=>{var _;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:v}=g.target;u.lastCommittedValue!==v&&(u.lastCommittedValue=v,u.userValue=v,(_=this.linkService.eventBus)==null||_.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:v,willCommit:!0,commitKey:p,selStart:g.target.selectionStart,selEnd:g.target.selectionEnd}}))});const f=d;d=null,s.addEventListener("blur",g=>{var v,_;if(!u.focused||!g.relatedTarget)return;(v=this.data.actions)!=null&&v.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 k;u.lastCommittedValue=null;const{data:p,target:v}=g,{value:_,selectionStart:b,selectionEnd:x}=v;let S=b,A=x;switch(g.inputType){case"deleteWordBackward":{const M=_.substring(0,b).match(/\w*[^\w]*$/);M&&(S-=M[0].length);break}case"deleteWordForward":{const M=_.substring(b).match(/^[^\w]*\w*/);M&&(A+=M[0].length);break}case"deleteContentBackward":b===x&&(S-=1);break;case"deleteContentForward":b===x&&(A+=1);break}g.preventDefault(),(k=this.linkService.eventBus)==null||k.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:_,change:p||"",willCommit:!1,selStart:S,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 wC extends Yr{constructor(t){super(t,{isRenderable:!!t.data.hasOwnCanvas})}}class xC 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=ml,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 cb 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=ml,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 SC extends lb{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 CC 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=ml;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 v of i.options)v.selected=p.has(v.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:v}=f.detail.insert,_=i.children[g],b=document.createElement("option");b.textContent=p,b.value=v,_?_.before(b):i.append(b),t.setValue(e,{value:a(!0),items:c(f)}),h=a(!1)},items(f){const{items:g}=f.detail;for(;i.length!==0;)i.remove(0);for(const p of g){const{displayValue:v,exportValue:_}=p,b=document.createElement("option");b.textContent=v,b.value=_,i.append(b)}i.options.length>0&&(i.options[0].selected=!0),t.setValue(e,{value:a(!0),items:c(f)}),h=a(!1)},indices(f){const g=new Set(f.detail.indices);for(const p of f.target.options)p.selected=g.has(p.index);t.setValue(e,{value:a(!0)}),h=a(!1)},editable(f){f.target.disabled=!f.detail.editable}};this._dispatchEventFromSandbox(d,u)}),i.addEventListener("input",u=>{var g;const d=a(!0),f=a(!1);t.setValue(e,{value:d}),u.preventDefault(),(g=this.linkService.eventBus)==null||g.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:h,change:f,changeEx:d,willCommit:!1,commitKey:1,keyDown:!1}})}),this._setEventListeners(i,null,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"],["input","Action"],["input","Validate"]],u=>u.target.value)):i.addEventListener("input",function(u){t.setValue(e,{value:a(!0)})}),this.data.combo&&this._setTextStyle(i),this._setBackgroundColor(i),this._setDefaultPropertiesFromJS(i),this.container.append(i),this.container}}class tp extends 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 AC({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=>`${Lg}${s}`).join(",")),this.container}}class AC{constructor({container:t,color:e,elements:s,titleObj:i,modificationDate:n,contentsObj:r,richText:a,parent:h,rect:c,parentRect:u,open:d}){y(this,Tt);y(this,ih,w(this,Tt,ky).bind(this));y(this,Bd,w(this,Tt,Kp).bind(this));y(this,Hd,w(this,Tt,ff).bind(this));y(this,nh,w(this,Tt,df).bind(this));y(this,Ma,null);y(this,Yt,null);y(this,Cn,null);y(this,rh,null);y(this,hc,null);y(this,lc,null);y(this,ah,null);y(this,An,!1);y(this,ui,null);y(this,Tn,null);y(this,cc,null);y(this,En,null);y(this,uc,null);y(this,Oa,null);y(this,Da,!1);var f;m(this,Yt,t),m(this,uc,i),m(this,Cn,r),m(this,En,a),m(this,lc,h),m(this,Ma,e),m(this,cc,c),m(this,ah,u),m(this,hc,s),m(this,rh,jg.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,Yt).hidden=!0,d&&w(this,Tt,df).call(this)}render(){if(l(this,ui))return;const t=m(this,ui,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,uc),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,Tt,uf);if(i)hb.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,Yt).append(t)}_formatContents({str:t,dir:e}){const s=document.createElement("p");s.classList.add("popupContent"),s.dir=e;const i=t.split(/(?:\r\n?|\n)/);for(let n=0,r=i.length;n<r;++n){const a=i[n];s.append(document.createTextNode(a)),n<r-1&&s.append(document.createElement("br"))}return s}updateEdited({rect:t,popupContent:e}){var s;l(this,Oa)||m(this,Oa,{contentsObj:l(this,Cn),richText:l(this,En)}),t&&m(this,Tn,null),e&&(m(this,En,w(this,Tt,Ey).call(this,e)),m(this,Cn,null)),(s=l(this,ui))==null||s.remove(),m(this,ui,null)}resetEdited(){var t;l(this,Oa)&&({contentsObj:ts(this,Cn)._,richText:ts(this,En)._}=l(this,Oa),m(this,Oa,null),(t=l(this,ui))==null||t.remove(),m(this,ui,null),m(this,Tn,null))}forceHide(){m(this,Da,this.isVisible),l(this,Da)&&(l(this,Yt).hidden=!0)}maybeShow(){l(this,Da)&&(l(this,ui)||w(this,Tt,ff).call(this),m(this,Da,!1),l(this,Yt).hidden=!1)}get isVisible(){return l(this,Yt).hidden===!1}}ih=new WeakMap,Bd=new WeakMap,Hd=new WeakMap,nh=new WeakMap,Ma=new WeakMap,Yt=new WeakMap,Cn=new WeakMap,rh=new WeakMap,hc=new WeakMap,lc=new WeakMap,ah=new WeakMap,An=new WeakMap,ui=new WeakMap,Tn=new WeakMap,cc=new WeakMap,En=new WeakMap,uc=new WeakMap,Oa=new WeakMap,Da=new WeakMap,Tt=new WeakSet,uf=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},qp=function(){var t,e,s;return((s=(e=(t=l(this,Tt,uf))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.fontSize)||0},Ty=function(){var t,e,s;return((s=(e=(t=l(this,Tt,uf))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.color)||null},Ey=function(t){const e=[],s={str:t,html:{name:"div",attributes:{dir:"auto"},children:[{name:"p",children:e}]}},i={style:{color:l(this,Tt,Ty),fontSize:l(this,Tt,qp)?`calc(${l(this,Tt,qp)}px * var(--scale-factor))`:""}};for(const n of t.split(`
|
|
530
|
+
`))e.push({name:"span",value:n,attributes:i});return s},ky=function(t){t.altKey||t.shiftKey||t.ctrlKey||t.metaKey||(t.key==="Enter"||t.key==="Escape"&&l(this,An))&&w(this,Tt,df).call(this)},Py=function(){if(l(this,Tn)!==null)return;const{page:{view:t},viewport:{rawDims:{pageWidth:e,pageHeight:s,pageX:i,pageY:n}}}=l(this,lc);let r=!!l(this,ah),a=r?l(this,ah):l(this,cc);for(const p of l(this,hc))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,Yt);g.left=`${l(this,Tn)[0]}%`,g.top=`${l(this,Tn)[1]}%`},df=function(){m(this,An,!l(this,An)),l(this,An)?(w(this,Tt,ff).call(this),l(this,Yt).addEventListener("click",l(this,nh)),l(this,Yt).addEventListener("keydown",l(this,ih))):(w(this,Tt,Kp).call(this),l(this,Yt).removeEventListener("click",l(this,nh)),l(this,Yt).removeEventListener("keydown",l(this,ih)))},ff=function(){l(this,ui)||this.render(),this.isVisible?l(this,An)&&l(this,Yt).classList.add("focused"):(w(this,Tt,Py).call(this),l(this,Yt).hidden=!1,l(this,Yt).style.zIndex=parseInt(l(this,Yt).style.zIndex)+1e3)},Kp=function(){l(this,Yt).classList.remove("focused"),!(l(this,An)||!this.isVisible)&&(l(this,Yt).hidden=!0,l(this,Yt).style.zIndex=parseInt(l(this,Yt).style.zIndex)-1e3)};class ub 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 TC extends Qt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,dc,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,dc,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,dc)}addHighlightArea(){this.container.classList.add("highlightArea")}}dc=new WeakMap;class EC extends Qt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,fc,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,fc,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,fc)}addHighlightArea(){this.container.classList.add("highlightArea")}}fc=new WeakMap;class kC extends Qt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,gc,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,gc,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,gc)}addHighlightArea(){this.container.classList.add("highlightArea")}}gc=new WeakMap;class db extends Qt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,pc,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,pc,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,pc)}addHighlightArea(){this.container.classList.add("highlightArea")}}pc=new WeakMap;class PC extends db{constructor(t){super(t),this.containerClassName="polygonAnnotation",this.svgElementName="svg:polygon"}}class MC 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 ep extends Qt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,vc);y(this,mc,null);y(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,vc,Jp).call(this,s,e),u=this.svgFactory.create(h,c,!0),d=m(this,mc,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,mc);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,vc,Jp).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")}}mc=new WeakMap,Ra=new WeakMap,vc=new WeakSet,Jp=function(e,s){switch(e){case 90:return{transform:`rotate(90) translate(${-s[0]},${s[1]}) scale(1,-1)`,width:s[3]-s[1],height:s[2]-s[0]};case 180:return{transform:`rotate(180) translate(${-s[2]},${s[1]}) scale(1,-1)`,width:s[2]-s[0],height:s[3]-s[1]};case 270:return{transform:`rotate(270) translate(${-s[2]},${s[3]}) scale(1,-1)`,width:s[3]-s[1],height:s[2]-s[0]};default:return{transform:`translate(${-s[0]},${s[3]}) scale(1,-1)`,width:s[2]-s[0],height:s[3]-s[1]}}};class fb extends 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 OC 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 DC 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 RC 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 gb 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 LC extends Qt{constructor(e){var i;super(e,{isRenderable:!0});y(this,yc);y(this,bc,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,yc,Qp).bind(this)),m(this,bc,i);const{isMac:n}=Ue.platform;return e.addEventListener("keydown",r=>{r.key==="Enter"&&(n?r.metaKey:r.ctrlKey)&&w(this,yc,Qp).call(this)}),!s.popupRef&&this.hasPopupData?this._createPopup():i.classList.add("popupTriggerArea"),e.append(i),e}getElementsToTriggerPopup(){return l(this,bc)}addHighlightArea(){this.container.classList.add("highlightArea")}}bc=new WeakMap,yc=new WeakSet,Qp=function(){var e;(e=this.downloadManager)==null||e.openOrDownloadData(this.content,this.filename)};class FC{constructor({div:t,accessibilityManager:e,annotationCanvasMap:s,annotationEditorUIManager:i,page:n,viewport:r,structTreeLayer:a}){y(this,Ia);y(this,_c,null);y(this,La,null);y(this,Fa,new Map);y(this,wc,null);this.div=t,m(this,_c,e),m(this,La,s),m(this,wc,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;Wr(s,this.viewport);const i=new Map,n={data:null,layer:s,linkService:t.linkService,downloadManager:t.downloadManager,imageResourcesPath:t.imageResourcesPath||"",renderForms:t.renderForms!==!1,svgFactory:new Zg,annotationStorage:t.annotationStorage||new 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===le.POPUP;if(h){const d=i.get(a.id);if(!d)continue;n.elements=d}else{const{width:d,height:f}=Jn(a.rect);if(d<=0||f<=0)continue}n.data=a;const c=bC.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,My).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,Zp).call(this)}update({viewport:t}){const e=this.div;this.viewport=t,Wr(e,{rotation:t.rotation}),w(this,Ia,Zp).call(this),e.hidden=!1}getEditableAnnotations(){return Array.from(l(this,Fa).values())}getEditableAnnotation(t){return l(this,Fa).get(t)}}_c=new WeakMap,La=new WeakMap,Fa=new WeakMap,wc=new WeakMap,Ia=new WeakSet,My=async function(t,e){var r,a;const s=t.firstChild||t,i=s.id=`${Lg}${e}`,n=await((r=l(this,wc))==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,_c))==null||a.moveElementInDOM(this.div,t,s,!1)},Zp=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,Dt=class Dt extends Vt{constructor(e){super({...e,name:"freeTextEditor"});y(this,ae);y(this,di);y(this,Ss,"");y(this,xc,`${this.id}-editor`);y(this,ja,null);y(this,Cs);m(this,di,e.color||Dt._defaultColor||Vt._defaultLineColor),m(this,Cs,e.fontSize||Dt._defaultFontSize)}static get _keyboardManager(){const e=Dt.prototype,s=r=>r.isEmpty(),i=Xr.TRANSLATE_SMALL,n=Xr.TRANSLATE_BIG;return lt(this,"_keyboardManager",new ll([[["ctrl+s","mac+meta+s","ctrl+p","mac+meta+p"],e.commitOrRemove,{bubbles:!0}],[["ctrl+Enter","mac+meta+Enter","Escape","mac+Escape"],e.commitOrRemove],[["ArrowLeft","mac+ArrowLeft"],e._translateEmpty,{args:[-i,0],checker:s}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],e._translateEmpty,{args:[-n,0],checker:s}],[["ArrowRight","mac+ArrowRight"],e._translateEmpty,{args:[i,0],checker:s}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],e._translateEmpty,{args:[n,0],checker:s}],[["ArrowUp","mac+ArrowUp"],e._translateEmpty,{args:[0,-i],checker:s}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],e._translateEmpty,{args:[0,-n],checker:s}],[["ArrowDown","mac+ArrowDown"],e._translateEmpty,{args:[0,i],checker:s}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],e._translateEmpty,{args:[0,n],checker:s}]]))}static initialize(e,s){Vt.initialize(e,s);const i=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(i.getPropertyValue("--freetext-padding"))}static updateDefaultParams(e,s){switch(e){case pt.FREETEXT_SIZE:Dt._defaultFontSize=s;break;case pt.FREETEXT_COLOR:Dt._defaultColor=s;break}}updateParams(e,s){switch(e){case pt.FREETEXT_SIZE:w(this,ae,Oy).call(this,s);break;case pt.FREETEXT_COLOR:w(this,ae,Dy).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[pt.FREETEXT_SIZE,Dt._defaultFontSize],[pt.FREETEXT_COLOR,Dt._defaultColor||Vt._defaultLineColor]]}get propertiesToUpdate(){return[[pt.FREETEXT_SIZE,l(this,Cs)],[pt.FREETEXT_COLOR,l(this,di)]]}_translateEmpty(e,s){this._uiManager.translateSelectedEditors(e,s,!0)}getInitialTranslation(){const e=this.parentScale;return[-Dt._internalPadding*e,-(Dt._internalPadding+l(this,Cs))*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,xc)),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,Ss),s=m(this,Ss,w(this,ae,Ry).call(this).trimEnd());if(e===s)return;const i=n=>{if(m(this,Ss,n),!n){this.remove();return}w(this,ae,mf).call(this),this._uiManager.rebuild(this),w(this,ae,gf).call(this)};this.addCommands({cmd:()=>{i(s)},undo:()=>{i(e)},mustExec:!1}),w(this,ae,gf).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){Dt._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,xc)),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,Cs)}px * var(--scale-factor))`,i.color=l(this,di),this.div.append(this.editorDiv),this.overlayDiv=document.createElement("div"),this.overlayDiv.classList.add("overlay","enabled"),this.div.append(this.overlayDiv),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,v;switch(this.rotation){case 0:p=e+(a[0]-f)/u,v=s+this.height-(a[1]-g)/d;break;case 90:p=e+(a[0]-f)/u,v=s-(a[1]-g)/d,[h,c]=[c,-h];break;case 180:p=e-this.width+(a[0]-f)/u,v=s-(a[1]-g)/d,[h,c]=[-h,-c];break;case 270:p=e+(a[0]-f-this.height*d)/u,v=s+(a[1]-g-this.width*u)/d,[h,c]=[-c,h];break}this.setAt(p*n,v*r,h,c)}else this.setAt(e*n,s*r,this.width*n,this.height*r);w(this,ae,mf).call(this),this._isDraggable=!0,this.editorDiv.contentEditable=!1}else this._isDraggable=!1,this.editorDiv.contentEditable=!0;return this.div}editorDivPaste(e){var p,v,_;const s=e.clipboardData||window.clipboardData,{types:i}=s;if(i.length===1&&i[0]==="text/plain")return;e.preventDefault();const n=w(p=Dt,kn,tm).call(p,s.getData("text")||"").replaceAll(xd,`
|
|
531
531
|
`);if(!n)return;const r=window.getSelection();if(!r.rangeCount)return;this.editorDiv.normalize(),r.deleteFromDocument();const a=r.getRangeAt(0);if(!n.includes(`
|
|
532
|
-
`)){a.insertNode(document.createTextNode(n)),this.editorDiv.normalize(),r.collapseToStart();return}const{startContainer:h,startOffset:c}=a,u=[],d=[];if(h.nodeType===Node.TEXT_NODE){const b=h.parentElement;if(d.push(h.nodeValue.slice(c).replaceAll(xd,"")),b!==this.editorDiv){let x=u;for(const
|
|
532
|
+
`)){a.insertNode(document.createTextNode(n)),this.editorDiv.normalize(),r.collapseToStart();return}const{startContainer:h,startOffset:c}=a,u=[],d=[];if(h.nodeType===Node.TEXT_NODE){const b=h.parentElement;if(d.push(h.nodeValue.slice(c).replaceAll(xd,"")),b!==this.editorDiv){let x=u;for(const S of this.editorDiv.childNodes){if(S===b){x=d;continue}x.push(w(v=Dt,kn,pf).call(v,S))}}u.push(h.nodeValue.slice(0,c).replaceAll(xd,""))}else if(h===this.editorDiv){let b=u,x=0;for(const S of this.editorDiv.childNodes)x++===c&&(b=d),b.push(w(_=Dt,kn,pf).call(_,S))}m(this,Ss,`${u.join(`
|
|
533
533
|
`)}${n}${d.join(`
|
|
534
|
-
`)}`),w(this,
|
|
535
|
-
`),position:v,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,
|
|
536
|
-
`)){const a=document.createElement("div");a.append(r?document.createTextNode(r):document.createElement("br")),s.append(a)}const n=
|
|
537
|
-
`)},
|
|
538
|
-
`)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},My=function(){return l(this,ws).replaceAll(" "," ")},Zp=function(e){return e.replaceAll(" "," ")},Oy=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},y(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 ep=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){y(this,ce);y(this,Ss);y(this,di,[]);y(this,oh);y(this,hh);y(this,ji,[]);y(this,lt,new Float32Array(18));y(this,Na);y(this,Ba);y(this,Cc);y(this,Ac);y(this,lh);y(this,ch);y(this,br,[]);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,Vd)*i),m(this,lh,i),l(this,br).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),v=p/g,_=v*d,b=v*f;let x=a,C=h;a=c,h=u,c+=_,u+=b,(R=l(this,br))==null||R.push(t,e);const A=-b/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(b,_))<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,Dy).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,Ly).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,Ry).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new gb(t,e,s,i,n,r)}getOutlines(){var d;const t=l(this,ji),e=l(this,di),s=l(this,lt),[i,n,r,a]=l(this,Ss),h=new Float32Array((((d=l(this,br))==null?void 0:d.length)??0)+2);for(let f=0,g=h.length-2;f<g;f+=2)h[f]=(l(this,br)[f]-i)/r,h[f+1]=(l(this,br)[f+1]-n)/a;if(h[h.length-2]=(l(this,Na)-i)/r,h[h.length-1]=(l(this,Ba)-n)/a,isNaN(s[6])&&!this.isEmpty())return w(this,ce,Fy).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,jy).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,Iy).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,br=new WeakMap,Tc=new WeakMap,Gd=new WeakMap,Vd=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]},Dy=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`},Ry=function(t){const e=l(this,di);t.push(`L${e[4]} ${e[5]} Z`)},Ly=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}`)},Fy=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))},Iy=function(t,e){const s=l(this,di);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},jy=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},y(Pn,Tc,8),y(Pn,Gd,2),y(Pn,Vd,l(Pn,Tc)+l(Pn,Gd));let Sd=Pn;class gb extends X{constructor(e,s,i,n,r,a){super();y(this,Wd);y(this,uh);y(this,Ha,new Float32Array(4));y(this,Mn);y(this,Ec);y(this,Cs);y(this,kc);y(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,Wd,Ny).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,v=n*d+c,_=this.newOutliner({x:l(this,Cs)[0]*f+p,y:l(this,Cs)[1]*g+v},l(this,uh),l(this,kc),e,l(this,Ec),s??l(this,Mn));for(let b=2;b<l(this,Cs).length;b+=2)_.add({x:l(this,Cs)[b]*f+p,y:l(this,Cs)[b+1]*g+v});return _.getOutlines()}}uh=new WeakMap,Ha=new WeakMap,Mn=new WeakMap,Ec=new WeakMap,Cs=new WeakMap,kc=new WeakMap,Jt=new WeakMap,Wd=new WeakSet,Ny=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,v=s.length;p<v;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 sp{constructor(t,e=0,s=0,i=!0){y(this,Ye);y(this,Pc);y(this,Mc);y(this,yr,[]);y(this,fi,[]);let n=1/0,r=-1/0,a=1/0,h=-1/0;const c=10**-4;for(const{x:_,y:b,width:x,height:C}of t){const A=Math.floor((_-e)/c)*c,P=Math.ceil((_+x+e)/c)*c,D=Math.floor((b-e)/c)*c,k=Math.ceil((b+C+e)/c)*c,M=[A,D,k,!0],R=[P,D,k,!1];l(this,yr).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,yr).at(i?-1:-2),v=[p[0],p[2]];for(const _ of l(this,yr)){const[b,x,C]=_;_[0]=(b-f)/u,_[1]=(x-g)/d,_[2]=(C-g)/d}m(this,Pc,new Float32Array([f,g,u,d])),m(this,Mc,v)}getOutlines(){l(this,yr).sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of l(this,yr))e[3]?(t.push(...w(this,Ye,tm).call(this,e)),w(this,Ye,Hy).call(this,e)):(w(this,Ye,Gy).call(this,e),t.push(...w(this,Ye,tm).call(this,e)));return w(this,Ye,By).call(this,t)}}Pc=new WeakMap,Mc=new WeakMap,yr=new WeakMap,fi=new WeakMap,Ye=new WeakSet,By=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 DC(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},Hy=function([,t,e]){const s=w(this,Ye,mf).call(this,t);l(this,fi).splice(s,0,[t,e])},Gy=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}}},tm=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 DC extends X{constructor(e,s,i){super();y(this,Oc);y(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 ip extends Sd{newFreeDrawOutline(t,e,s,i,n,r){return new RC(t,e,s,i,n,r)}}class RC extends gb{newOutliner(t,e,s,i,n,r=0){return new ip(t,e,s,i,n,r)}}const hs=class hs{constructor({editor:t=null,uiManager:e=null}){y(this,At);y(this,gi,null);y(this,Ga,null);y(this,fh);y(this,ue,null);y(this,Dc,!1);y(this,gh,!1);y(this,Rc,null);y(this,Lc);y(this,_r,null);y(this,pi,null);y(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 ll([[["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,im).bind(this),{signal:e});const s=m(this,Ga,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,em).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,sm).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,Ga)&&(l(this,Ga).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,Ga,null),(e=l(this,ue))==null||e.remove(),m(this,ue,null)}};gi=new WeakMap,Ga=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,em=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,sm).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",w(this,At,im).bind(this),{signal:e}),t},sm=function(t,e){e.stopPropagation(),l(this,Lc).dispatch("switchannotationeditorparams",{source:this,type:l(this,ph),value:t})},im=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,Vy).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,em).call(this));l(this,gi).append(e)},Vy=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")},y(hs,Fc,null);let Cd=hs;const bt=class bt extends Ht{constructor(e){super({...e,name:"highlightEditor"});y(this,st);y(this,mh,null);y(this,Ic,0);y(this,On);y(this,Va,null);y(this,vh,null);y(this,ls,null);y(this,jc,null);y(this,Nc,0);y(this,Wa,null);y(this,Hs,null);y(this,As,null);y(this,_e,!1);y(this,bh,null);y(this,Dn);y(this,Le,null);y(this,yh,"");y(this,Gs);y(this,Bc,"");this.color=e.color||bt._defaultColor,m(this,Gs,e.thickness||bt._defaultThickness),m(this,Dn,e.opacity||bt._defaultOpacity),m(this,On,e.boxes||null),m(this,Bc,e.methodOfCreation||""),m(this,yh,e.text||""),this._isDraggable=!1,e.highlightId>-1?(m(this,_e,!0),w(this,st,vf).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,nm).call(this),w(this,st,no).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=bt.prototype;return ht(this,"_keyboardManager",new ll([[["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,Gs),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),bt._defaultColor||(bt._defaultColor=((i=s.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,s){switch(e){case dt.HIGHLIGHT_DEFAULT_COLOR:bt._defaultColor=s;break;case dt.HIGHLIGHT_THICKNESS:bt._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return l(this,bh)}updateParams(e,s){switch(e){case dt.HIGHLIGHT_COLOR:w(this,st,Wy).call(this,s);break;case dt.HIGHLIGHT_THICKNESS:w(this,st,zy).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[dt.HIGHLIGHT_DEFAULT_COLOR,bt._defaultColor],[dt.HIGHLIGHT_THICKNESS,bt._defaultThickness]]}get propertiesToUpdate(){return[[dt.HIGHLIGHT_COLOR,this.color||bt._defaultColor],[dt.HIGHLIGHT_THICKNESS,l(this,Gs)||bt._defaultThickness],[dt.HIGHLIGHT_FREE,l(this,_e)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(m(this,vh,new Cd({editor:this})),e.addColorPicker(l(this,vh))),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,rm).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,rm).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=bt,Vs,Nh).call(n,l(this,Hs).box,e)):i=w(r=bt,Vs,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=bt,Vs,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,yh)&&(e.setAttribute("aria-label",l(this,yh)),e.setAttribute("role","mark")),l(this,_e)?e.classList.add("free"):this.div.addEventListener("keydown",w(this,st,Uy).bind(this),{signal:this._uiManager._signal});const s=m(this,Wa,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=l(this,Va);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),gd(this,l(this,Wa),["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,bf).call(this,!0);break;case 1:case 3:w(this,st,bf).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,bf).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,Vs,Ky).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,Vs,qy).bind(this,e),{signal:f}),this._freeHighlight=new ip({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 v,_,b,x;let n=null;if(e instanceof db){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 tp){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,Gs,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(v=u,st,nm).call(v),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 ip(A,[0,0,d,f],1,l(u,Gs)/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(b=u,st,vf).call(b,{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,Gs),quadPoints:w(this,st,Yy).call(this),outlines:w(this,st,$y).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:w(this,st,tu).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!w(this,st,Jy).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,Va=new WeakMap,vh=new WeakMap,ls=new WeakMap,jc=new WeakMap,Nc=new WeakMap,Wa=new WeakMap,Hs=new WeakMap,As=new WeakMap,_e=new WeakMap,bh=new WeakMap,Dn=new WeakMap,Le=new WeakMap,yh=new WeakMap,Gs=new WeakMap,Bc=new WeakMap,st=new WeakSet,nm=function(){const e=new sp(l(this,On),.001);m(this,Hs,e.getOutlines()),[this.x,this.y,this.width,this.height]=l(this,Hs).box;const s=new sp(l(this,On),.0025,.001,this._uiManager.direction==="ltr");m(this,ls,s.getOutlines());const{lastPoint:i}=l(this,ls);m(this,bh,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height])},vf=function({highlightOutlines:e,highlightId:s,clipPathId:i}){var d,f;if(m(this,Hs,e),m(this,ls,e.getNewOutline(l(this,Gs)/2+1.5,.0025)),s>=0)m(this,As,s),m(this,Va,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=bt,Vs,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=bt,Vs,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,bh,[(u[0]-r)/h,(u[1]-a)/c])},Wy=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,vh))==null||c.updateColor(r)},i=this.color,n=l(this,Dn);this.addCommands({cmd:s.bind(this,e,bt._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)},zy=function(e){const s=l(this,Gs),i=n=>{m(this,Gs,n),w(this,st,Xy).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)},Xy=function(e){if(!l(this,_e))return;w(this,st,vf).call(this,{highlightOutlines:l(this,Hs).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},rm=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,Va)._}=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,Wa)&&(l(this,Wa).style.clipPath=l(this,Va)))},Vs=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]},Uy=function(e){bt._keyboardManager.exec(this,e)},bf=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},Yy=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},$y=function(e){return l(this,Hs).serialize(e,w(this,st,tu).call(this))},qy=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},Ky=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=""},Jy=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},y(bt,Vs),J(bt,"_defaultColor",null),J(bt,"_defaultOpacity",1),J(bt,"_defaultThickness",12),J(bt,"_type","highlight"),J(bt,"_editorType",nt.HIGHLIGHT),J(bt,"_freeHighlightId",-1),J(bt,"_freeHighlight",null),J(bt,"_freeHighlightClipId","");let Ad=bt;class LC{constructor(){y(this,za,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,za)[t]=e}toSVGProperties(){const t=l(this,za);return m(this,za,Object.create(null)),{root:t}}reset(){m(this,za,Object.create(null))}updateAll(t=this){this.updateProperties(t)}clone(){Et("Not implemented")}}za=new WeakMap;const U=class U extends Ht{constructor(e){super(e);y(this,mt);y(this,Ts,null);y(this,_h);J(this,"_drawId",null);m(this,_h,e.mustBeCommitted||!1),e.drawOutlines&&(w(this,mt,am).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,yf).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,yf).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,yf).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,hm).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,hm).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),v=e.combinedSignal(p);if(l(U,wr)||m(U,wr,c),l(U,xr)??m(U,xr,u),window.addEventListener("pointerup",b=>{var x;l(U,wr)===b.pointerId?this._endDraw(b):(x=l(U,Sr))==null||x.delete(b.pointerId)},{signal:v}),window.addEventListener("pointercancel",b=>{var x;l(U,wr)===b.pointerId?this._currentParent.endDrawingSession():(x=l(U,Sr))==null||x.delete(b.pointerId)},{signal:v}),window.addEventListener("pointerdown",b=>{l(U,xr)===b.pointerType&&((l(U,Sr)||m(U,Sr,new Set)).add(b.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:v}),window.addEventListener("contextmenu",ii,{signal:v}),r.addEventListener("pointermove",this._drawMove.bind(this),{signal:v}),r.addEventListener("touchmove",b=>{b.timeStamp===l(U,Ya)&&gs(b)},{signal:v}),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,am).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,am=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,om).call(this,e,this.parent),w(this,mt,su).call(this,e.box)},om=function(e,s){const{id:i}=s.drawLayer.draw(U._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return i},hm=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,om).call(this,l(this,Ts),e)}},Qy=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]}},yf=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,Qy).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),y(U,pe,null),y(U,Xa,null),y(U,Ua,null),y(U,wr,NaN),y(U,xr,null),y(U,Sr,null),y(U,Ya,NaN),J(U,"_INNER_MARGIN",3);let np=U;class FC{constructor(t,e,s,i,n,r){y(this,xh);y(this,Ni,new Float64Array(6));y(this,me);y(this,ve);y(this,$a);y(this,wh);y(this,$e);y(this,we,"");y(this,Ws,0);y(this,qa,new Td);y(this,Ka);y(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,ve,[{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,ve)||l(this,ve).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,ve).at(-1);return a&&(a.line=new Float32Array(a.line),a.points=new Float32Array(a.points)),l(this,ve).push({line:r,points:l(this,$e)}),l(this,Ni).set(r,0),m(this,Ws,0),this.toSVGPath(),null}getLastElement(){return l(this,ve).at(-1)}setLastElement(t){return l(this,ve)?(l(this,ve).push(t),m(this,me,t.line),m(this,$e,t.points),m(this,Ws,0),{path:{d:this.toSVGPath()}}):l(this,qa).setLastElement(t)}removeLastElement(){if(!l(this,ve))return l(this,qa).removeLastElement();l(this,ve).pop(),m(this,we,"");for(let t=0,e=l(this,ve).length;t<e;t++){const{line:s,points:i}=l(this,ve)[t];m(this,me,s),m(this,$e,i),m(this,Ws,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,Ws,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,Ws,12),l(this,we)}const s=[];l(this,Ws)===0&&(s.push(`M ${t} ${e}`),m(this,Ws,6));for(let i=l(this,Ws),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,Ws,l(this,me).length),l(this,we)}getOutlines(t,e,s,i){const n=l(this,ve).at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),l(this,qa).build(l(this,ve),t,e,s,l(this,$a),l(this,wh),i),m(this,Ni,null),m(this,me,null),m(this,ve,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,ve=new WeakMap,$a=new WeakMap,wh=new WeakMap,$e=new WeakMap,we=new WeakMap,Ws=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 gp=class gp extends X{constructor(){super(...arguments);y(this,xe);y(this,qe);y(this,Hc,0);y(this,Gc);y(this,Es);y(this,Bi);y(this,Hi);y(this,Sh);y(this,Ch);y(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,Gc,h??0),m(this,Es,e),w(this,xe,t_).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,Zy).call(this);let g,p,v,_,b,x,C,A,P;switch(l(this,Ch)){case 0:P=X._rescale,g=e,p=s+n,v=i,_=-n,b=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,v=i,_=n,b=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,v=-i,_=n,b=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,v=-i,_=-n,b=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,v,_,r?new Array(D.length):null)),h.push(P(k,g,p,v,_,r?new Array(k.length):null));return{lines:a,points:h,rect:[b,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,v,_;switch(c){case 0:_=X._rescale,f=-e/i,g=s/n+1,p=1/i,v=-1/n;break;case 90:_=X._rescaleAndSwap,f=-s/n,g=-e/i,p=1/n,v=1/i;break;case 180:_=X._rescale,f=e/i+1,g=-s/n,p=-1/i,v=1/n;break;case 270:_=X._rescaleAndSwap,f=s/n+1,g=e/i+1,p=-1/n,v=-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,v),points:_(h[x].map(A=>A??NaN),f,g,p,v)});const b=new gp;return b.build(d,i,n,1,c,u,r),b}get box(){return l(this,qe)}updateProperty(e,s){return e==="stroke-width"?w(this,xe,e_).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),b=s+n/2-(c+d/2);return{path:{"transform-origin":`${X.svgRound(e)} ${X.svgRound(s)}`,transform:`${this.rotationTransform} translate(${_} ${b})`}}}const f=(i-2*r)/(u-2*r),g=(n-2*a)/(d-2*a),p=u/i,v=d/n;return{path:{"transform-origin":`${X.svgRound(h)} ${X.svgRound(c)}`,transform:`${this.rotationTransform} scale(${p} ${v}) 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 b=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,b,x,C),X._translate(A,b,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),v=-g*(c+r)+e+r,_=-p*(u+a)+s+a;if(g!==1||p!==1||v!==0||_!==0)for(const{line:b,points:x}of l(this,Es))X._rescale(b,v,_,g,p,b),X._rescale(x,v,_,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,Gc=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,Gc)+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)]},Zy=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]},t_=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,v]=n.subarray(h,h+6);q.bezierBoundingBox(r,a,u,d,f,g,p,v,e),r=p,a=v}}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]},e_=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=gp;const pp=class pp extends LC{constructor(e){super();y(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 pp(l(this,Th));return e.updateAll(this),e}};Th=new WeakMap;let rp=pp;const Eh=class Eh extends np{constructor(e){super({...e,name:"inkEditor"});y(this,zd);this._willKeepAspectRatio=!0}static initialize(e,s){Ht.initialize(e,s),this._defaultDrawingOptions=new rp(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 FC(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 tp){const{data:{inkLists:a,rect:h,rotation:c,id:u,color:d,opacity:f,borderStyle:{rawWidth:g},popupRef:p},parent:{page:{pageNumber:v}}}=e;n=e={annotationType:nt.INK,color:Array.from(d),thickness:g,opacity:f,paths:{points:a},boxes:null,pageIndex:v-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,zd,s_).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}};zd=new WeakSet,s_=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 ap=Eh;const Vc=class Vc extends Ht{constructor(e){super({...e,name:"stampEditor"});y(this,vt);y(this,Vt,null);y(this,Se,null);y(this,Cr,null);y(this,Rn,null);y(this,Ar,null);y(this,kh,"");y(this,Gi,null);y(this,Vi,null);y(this,ks,!1);y(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,Vt,null),this._uiManager.imageManager.deleteId(l(this,Se)),(e=l(this,Gi))==null||e.remove(),m(this,Gi,null),l(this,Vi)&&(clearTimeout(l(this,Vi)),m(this,Vi,null))),super.remove()}rebuild(){if(!this.parent){l(this,Se)&&w(this,vt,wf).call(this);return}super.rebuild(),this.div!==null&&(l(this,Se)&&l(this,Gi)===null&&w(this,vt,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,Vt)||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,Vt)?w(this,vt,lm).call(this):w(this,vt,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,Vi)!==null&&clearTimeout(l(this,Vi)),m(this,Vi,setTimeout(()=>{m(this,Vi,null),w(this,vt,cm).call(this)},200))}copyCanvas(e,s,i=!1){var g;e||(e=224);const{width:n,height:r}=l(this,Vt),a=new Ng;let h=l(this,Vt),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),v=d.height=Math.ceil(u*a.sy);l(this,ks)||(h=w(this,vt,xf).call(this,p,v));const _=d.getContext("2d");_.filter=this._uiManager.hcmFilter;let b="white",x="#cfcfd8";this._uiManager.hcmFilter!=="none"?x="black":(g=window.matchMedia)!=null&&g.call(window,"(prefers-color-scheme: dark)").matches&&(b="#8f8f9d",x="#42414d");const C=15,A=C*a.sx,P=C*a.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),_.fillStyle=_.createPattern(D,"repeat"),_.fillRect(0,0,p,v),_.drawImage(h,0,0,h.width,h.height,0,0,p,v)}let f=null;if(i){let p,v;if(a.symmetric&&h.width<e&&h.height<e)p=h.width,v=h.height;else if(h=l(this,Vt),n>e||r>e){const x=Math.min(e/n,e/r);p=Math.floor(n*x),v=Math.floor(r*x),l(this,ks)||(h=w(this,vt,xf).call(this,p,v))}const b=new OffscreenCanvas(p,v).getContext("2d",{willReadFrequently:!0});b.drawImage(h,0,0,h.width,h.height,0,0,p,v),f={width:p,height:v,data:b.getImageData(0,0,p,v).data}}return{canvas:d,width:c,height:u,imageData:f}}getImageForAltText(){return l(this,Gi)}static async deserialize(e,s,i){var v;let n=null;if(e instanceof fb){const{data:{rect:_,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=((v=await s._structTree.getAriaAttributes(`${Rg}${x}`))==null?void 0:v.get("aria-label"))||"";n=e={annotationType:nt.STAMP,bitmapId:M.id,bitmap:M.bitmap,pageIndex:D-1,rect:_.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:a,bitmap:h,bitmapUrl:c,bitmapId:u,isSvg:d,accessibilityData:f}=e;u&&i.imageManager.isValidId(u)?(m(r,Se,u),h&&m(r,Vt,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,vt,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,vt,i_).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,vt,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,vt,Sf).call(this,!1))}return i}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}};Vt=new WeakMap,Se=new WeakMap,Cr=new WeakMap,Rn=new WeakMap,Ar=new WeakMap,kh=new WeakMap,Gi=new WeakMap,Vi=new WeakMap,ks=new WeakMap,Ph=new WeakMap,vt=new WeakSet,iu=function(e,s=!1){if(!e){this.remove();return}m(this,Vt,e.bitmap),s||(m(this,Se,e.id),m(this,ks,e.isSvg)),e.file&&m(this,kh,e.file.name),w(this,vt,lm).call(this)},nu=function(){if(m(this,Cr,null),this._uiManager.enableWaiting(!1),!!l(this,Gi)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Vt)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Vt)){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,vt,iu).call(this,i,!0)).finally(()=>w(this,vt,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,vt,iu).call(this,n)).finally(()=>w(this,vt,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,vt,iu).call(this,n)).finally(()=>w(this,vt,nu).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=Vc.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,vt,iu).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>w(this,vt,nu).call(this))),e.click()},lm=function(){var d;const{div:e}=this;let{width:s,height:i}=l(this,Vt);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,Gi,document.createElement("canvas"));u.setAttribute("role","img"),this.addContainer(u),this.width=s/n,this.height=i/r,(d=this._initialOptions)!=null&&d.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),w(this,vt,cm).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,Vt);let r=i,a=n,h=l(this,Vt);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},cm=function(){const[e,s]=this.parentDimensions,{width:i,height:n}=this,r=new Ng,a=Math.ceil(i*e*r.sx),h=Math.ceil(n*s*r.sy),c=l(this,Gi);if(!c||c.width===a&&c.height===h)return;c.width=a,c.height=h;const u=l(this,ks)?l(this,Vt):w(this,vt,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,Vt),s.getContext("2d").drawImage(l(this,Vt),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,Vt),0,0,l(this,Vt).width,l(this,Vt).height,0,0,n,r),a.transferToImageBitmap()}return structuredClone(l(this,Vt))},i_=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(Vc,"_type","stamp"),J(Vc,"_editorType",nt.STAMP);let op=Vc;const vi=class vi{constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:a,textLayer:h,viewport:c,l10n:u}){y(this,Nt);y(this,Qa);y(this,Mh,!1);y(this,Wi,null);y(this,Tr,null);y(this,Ln,null);y(this,zs,new Map);y(this,Er,!1);y(this,Oh,!1);y(this,Za,!1);y(this,mi,null);y(this,Fn,null);y(this,Fe,null);y(this,In,null);y(this,$);const d=[...l(vi,kr).values()];if(!vi._initialized){vi._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,Wi,r),this.viewport=c,m(this,Fe,h),this.drawLayer=a,this._structTree=i,l(this,$).addLayer(this)}get isEmpty(){return l(this,zs).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(vi,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,Wi))==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,zs).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(l(this,$).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!l(this,Wi)){m(this,Za,!1);return}const e=l(this,Wi).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,zs).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,Wi)){const n=l(this,Wi).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(vi,kr).values())s.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),m(this,Oh,!1)}getEditableAnnotation(t){var e;return((e=l(this,Wi))==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,n_).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,zs).set(t.id,t);const{annotationElementId:e}=t;e&&l(this,$).isDeletedAnnotationElement(e)&&l(this,$).removeDeletedAnnotationElement(t)}detach(t){var e;l(this,zs).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,dm).call(this),n=this.getNextId(),r=w(this,Nt,um).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(vi,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,um).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,dm).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}=ze.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}=ze.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,zs).values())(e=l(this,Qa))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,l(this,zs).clear(),l(this,$).removeLayer(this)}render({viewport:t}){this.viewport=t,zr(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,zr(this.div,{rotation:s}),e!==s)for(const i of l(this,zs).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,Wi=new WeakMap,Tr=new WeakMap,Ln=new WeakMap,zs=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,n_=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}=ze.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(vi,kr).get(l(this,$).getMode())},um=function(t){const e=l(this,Nt,Ui);return e?new e.prototype.constructor(t):null},dm=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,zs).values())t.isEmpty()&&t.remove()},J(vi,"_initialized",!1),y(vi,kr,new Map([ep,ap,op,Ad].map(t=>[t._editorType,t])));let hp=vi;const Ie=class Ie{constructor({pageIndex:t}){y(this,zi);y(this,bi,null);y(this,Wc,0);y(this,Ke,new Map);y(this,to,new Map);this.pageIndex=t}setParent(t){if(!l(this,bi)){m(this,bi,t);return}if(l(this,bi)!==t){if(l(this,Ke).size>0)for(const e of l(this,Ke).values())e.remove(),t.append(e);m(this,bi,t)}}static get _svgFactory(){return ht(this,"_svgFactory",new Qg)}draw(t,e=!1,s=!1){const i=Ze(this,Wc)._++,n=w(this,zi,fm).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,zi,a_).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,Wc)._++,i=w(this,zi,fm).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,zi,gm).call(this,a,s),i&&w(h=Ie,Xd,r_).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,zi,gm).call(this,u,r)}}}updateParent(t,e){if(e===this)return;const s=l(this,Ke).get(t);s&&(l(e,bi).append(s),l(this,Ke).delete(t),l(e,Ke).set(t,s))}remove(t){l(this,to).delete(t),l(this,bi)!==null&&(l(this,Ke).get(t).remove(),l(this,Ke).delete(t))}destroy(){m(this,bi,null);for(const t of l(this,Ke).values())t.remove();l(this,Ke).clear(),l(this,to).clear()}};bi=new WeakMap,Wc=new WeakMap,Ke=new WeakMap,to=new WeakMap,Xd=new WeakSet,r_=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}%`},zi=new WeakSet,fm=function(){const t=Ie._svgFactory.create(1,1,!0);return l(this,bi).append(t),t.setAttribute("aria-hidden",!0),t},a_=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},gm=function(t,e){for(const[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)},y(Ie,Xd);let lp=Ie;globalThis.pdfjsTestingUtils={HighlightOutliner:sp},Z.AbortException,Z.AnnotationEditorLayer,Z.AnnotationEditorParamsType,Z.AnnotationEditorType,Z.AnnotationEditorUIManager,Z.AnnotationLayer,Z.AnnotationMode,Z.ColorPicker,Z.DOMSVGFactory,Z.DrawLayer,Z.FeatureTest;var IC=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 jC=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 NC={"pdfjs-dist":"4.10.38"};function BC(o){return new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>t(s.result)),s.addEventListener("error",e),s.readAsDataURL(o)})}const HC=NC["pdfjs-dist"].replace("^","");IC.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${HC}/pdf.worker.min.mjs`;async function GC(o){const t="data:application/pdf;base64,",e=await BC(o);if(typeof e=="string")return window.atob(e.slice(t.length))}function VC(o,t){return jC({data:o,password:t}).promise}const WC="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 zC(o){return new URL(Object.assign({"../assets/close.svg":WC})[`../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 XC(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 UC(i))}),i.addEventListener("error",n=>{window.URL.revokeObjectURL(s),e(n)})})}function UC(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 pb=null;function YC(){const o=document.createElement("div");o.style.width="1in",document.body.append(o);const t=o.offsetWidth;return o.remove(),t}function $C(){const o=pb??YC();return pb=o,o/72}function qC(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 Ls=new Map;function KC(o){const t=new fg(o);return Ls.set(o,t),t}function JC(o,t){const e=Date.now();return{PDFId:`${o.name}-${e}`,name:o.name.replace(/.pdf/,""),updateDate:e,PDFBase64:t}}function QC(o,t){const e=o.getViewport({scale:t}),s=document.createElement("canvas"),i=s.getContext("2d"),n=$C()/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 ZC(o,t,e){const s=o||zC("close.svg"),{objects:i,options:n}=await Tx(s),r=i.filter(h=>h!==null),a=Hw.groupSVGElements(r,n);return r.forEach(h=>{h.stroke=t}),a.hoverCursor="pointer",a.stroke=`${t}-${e}`,a}function tA(o,t){if(!Ls.get(o))return;const s=1/3,i=aA(t,s);vb(o,i,s)}async function eA(o,t){const e=await XC(t),s=Date.now(),n={PDFId:`${t.name}${s}`,name:t.name.replace(/.png|.jpg|.jpeg/,""),updateDate:s,PDFBase64:e};return mb(o,{url:e}),{...n,pages:1}}async function mb(o,{url:t,scale:e=.5}){if(!Ls.get(o))return;const i=await ke.fromURL(t);i.scale(e),vb(o,i,e)}function vb(o,t,e){const s=Ls.get(o);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function vl(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 sA(o,t,e){!e||!o||(e.scale(1/t),vl(o,e))}function iA(o,t){if(!o)return;const e=o._cornerSize||6;o.borderScaleFactor=1/t,o.cornerSize=e*(1/t),o.touchCornerSize=e*4*(1/t),o.setCoords()}function nA(o){const t=Ls.get(o);t&&(t.discardActiveObject(),t.renderAll())}function rA(o){const t=Ls.get(o);t&&(t.clear(),Ls.delete(o))}function aA(o,t){return new ke(o,{scaleX:t,scaleY:t})}const oA={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:6,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},hA={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:6,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},lA={stroke:"#000",hoverStroke:"#B7EC5D",src:""};function bb(o=""){const t=Q.useRef(0),e=Q.useRef(null),s=Q.useRef(null),i=Q.useRef(1),n=Q.useRef({...lA});function r(){if(!o||Ls.has(o))return;const k=KC(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 GC(k);if(!R)return;const F=JC(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 VC(M,F),Y=await I.getPage(k),{renderTask:N,canvas:H}=QC(Y,R);return t.current=I.numPages,N.promise.then(()=>u(H))}catch(I){return Promise.reject(I)}}function u(k){tA(o,k)}async function d(k){return await eA(o,k)}async function f({url:k,scale:M=.5}){await mb(o,{url:k,scale:M})}async function g(k,M){const R=Ls.get(o);if(!R)return;const F=await ke.fromURL(k,{},{...oA,...M});R.add(F),v(R,F)}function p(k,M){const R=Ls.get(o);if(!R)return;const F=new Ee(k,{...hA,...M});R.add(F),v(R,F)}function v(k,M){M.on("selected",R=>_({canvas:k,target:R.target})),M.on("modified",R=>vl(R.target,e.current)),M.on("scaling",R=>vl(R.transform.target,e.current)),M.on("moving",R=>vl(R.transform.target,e.current)),M.on("rotating",R=>vl(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 ZC(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",()=>{_({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=Ls.get(o);i.current=k,R&&(iA(s.current,k),sA(s.current,k,e.current),!M&&R.renderAll())}function C(k){if(!k)return;n.current={...n.current,...k};const M=Ls.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(){nA(o)}function D(){rA(o)}return{createCanvas:r,loadFile:a,specifyPage:c,renderImage:f,addFabric:g,addTextFabric:p,clearActive:P,deleteCanvas:D,scaleFabric:x,setCloseSvgOptions:C}}function cA(o){let t=0;const e=qC(()=>{t!==window.innerWidth&&(t=window.innerWidth,o())});Q.useEffect(()=>(window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)),[])}const uA=Q.forwardRef(dA);function dA({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}`,v=Q.useMemo(()=>s*n,[s,n]),{createCanvas:_,specifyPage:b,addFabric:x,addTextFabric:C,renderImage:A,clearActive:P,deleteCanvas:D,scaleFabric:k,setCloseSvgOptions:M}=bb(p);cA(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 b({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,W=H.getData("text/plain"),it=H.getData("text/uri-list"),kt={left:at-71,top:j-55};it?I(it,kt):W&&Y(W,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(v)},[v]),Q.useEffect(()=>{M(d)},[d]),Q.useEffect(()=>()=>D(),[]),vm.jsx("div",{style:{transform:`scale(${v})`},onDragOver:N=>N.preventDefault(),onDragEnter:N=>N.preventDefault(),onDrop:F,children:vm.jsx("canvas",{id:p,ref:g,className:r})})}ut.default=uA,ut.useFabric=bb,Object.defineProperties(ut,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
534
|
+
`)}`),w(this,ae,mf).call(this);const f=new Range;let g=u.reduce((b,x)=>b+x.length,0);for(const{firstChild:b}of this.editorDiv.childNodes)if(b.nodeType===Node.TEXT_NODE){const x=b.nodeValue.length;if(g<=x){f.setStart(b,g),f.setEnd(b,g);break}g-=x}r.removeAllRanges(),r.addRange(f)}get contentDiv(){return this.editorDiv}static async deserialize(e,s,i){var a;let n=null;if(e instanceof ub){const{data:{defaultAppearanceData:{fontSize:h,fontColor:c},rect:u,rotation:d,id:f,popupRef:g},textContent:p,textPosition:v,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:v,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,Cs,e.fontSize),m(r,di,q.makeHexColor(...e.color)),m(r,Ss,w(a=Dt,kn,tm).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=Dt._internalPadding*this.parentScale,i=this.getRect(s,s),n=Vt._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:l(this,di)),r={annotationType:nt.FREETEXT,color:n,fontSize:l(this,Cs),value:w(this,ae,Ly).call(this),pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?r:this.annotationElementId&&!w(this,ae,Fy).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,Cs)}px * var(--scale-factor))`,i.color=l(this,di),s.replaceChildren();for(const r of l(this,Ss).split(`
|
|
536
|
+
`)){const a=document.createElement("div");a.append(r?document.createTextNode(r):document.createElement("br")),s.append(a)}const n=Dt._internalPadding*this.parentScale;return e.updateEdited({rect:this.getRect(n,n),popupContent:l(this,Ss)}),s}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}};di=new WeakMap,Ss=new WeakMap,xc=new WeakMap,ja=new WeakMap,Cs=new WeakMap,ae=new WeakSet,Oy=function(e){const s=n=>{this.editorDiv.style.fontSize=`calc(${n}px * var(--scale-factor))`,this.translate(0,-(n-l(this,Cs))*this.parentScale),m(this,Cs,n),w(this,ae,gf).call(this)},i=l(this,Cs);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:pt.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})},Dy=function(e){const s=n=>{m(this,di,this.editorDiv.style.color=n)},i=l(this,di);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:pt.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})},Ry=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=Dt,kn,pf).call(i,n)),s=n);return e.join(`
|
|
537
|
+
`)},gf=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,pf=function(e){return(e.nodeType===Node.TEXT_NODE?e.nodeValue:e.innerText).replaceAll(xd,"")},mf=function(){if(this.editorDiv.replaceChildren(),!!l(this,Ss))for(const e of l(this,Ss).split(`
|
|
538
|
+
`)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},Ly=function(){return l(this,Ss).replaceAll(" "," ")},tm=function(e){return e.replaceAll(" "," ")},Fy=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},y(Dt,kn),J(Dt,"_freeTextDefaultContent",""),J(Dt,"_internalPadding",0),J(Dt,"_defaultColor",null),J(Dt,"_defaultFontSize",10),J(Dt,"_type","freetext"),J(Dt,"_editorType",nt.FREETEXT);let sp=Dt;class U{toSVGPath(){Pt("Abstract method `toSVGPath` must be implemented.")}get box(){Pt("Abstract getter `box` must be implemented.")}serialize(t,e){Pt("Abstract method `serialize` must be implemented.")}static _rescale(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let 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(U,"PRECISION",1e-4);const Pn=class Pn{constructor({x:t,y:e},s,i,n,r,a=0){y(this,de);y(this,As);y(this,fi,[]);y(this,oh);y(this,hh);y(this,Ni,[]);y(this,ct,new Float32Array(18));y(this,Na);y(this,Ba);y(this,Sc);y(this,Cc);y(this,lh);y(this,ch);y(this,br,[]);m(this,As,s),m(this,ch,n*i),m(this,hh,r),l(this,ct).set([NaN,NaN,NaN,NaN,t,e],6),m(this,oh,a),m(this,Cc,l(Pn,Ac)*i),m(this,Sc,l(Pn,Gd)*i),m(this,lh,i),l(this,br).push(t,e)}isEmpty(){return isNaN(l(this,ct)[8])}add({x:t,y:e}){var R;m(this,Na,t),m(this,Ba,e);const[s,i,n,r]=l(this,As);let[a,h,c,u]=l(this,ct).subarray(8,12);const d=t-c,f=e-u,g=Math.hypot(d,f);if(g<l(this,Sc))return!1;const p=g-l(this,Cc),v=p/g,_=v*d,b=v*f;let x=a,S=h;a=c,h=u,c+=_,u+=b,(R=l(this,br))==null||R.push(t,e);const A=-b/p,k=_/p,M=A*l(this,ch),D=k*l(this,ch);return l(this,ct).set(l(this,ct).subarray(2,8),0),l(this,ct).set([c+M,u+D],4),l(this,ct).set(l(this,ct).subarray(14,18),12),l(this,ct).set([c-M,u-D],16),isNaN(l(this,ct)[6])?(l(this,Ni).length===0&&(l(this,ct).set([a+M,h+D],2),l(this,Ni).push(NaN,NaN,NaN,NaN,(a+M-s)/n,(h+D-i)/r),l(this,ct).set([a-M,h-D],14),l(this,fi).push(NaN,NaN,NaN,NaN,(a-M-s)/n,(h-D-i)/r)),l(this,ct).set([x,S,a,h,c,u],6),!this.isEmpty()):(l(this,ct).set([x,S,a,h,c,u],6),Math.abs(Math.atan2(S-h,x-a)-Math.atan2(b,_))<Math.PI/2?([a,h,c,u]=l(this,ct).subarray(2,6),l(this,Ni).push(NaN,NaN,NaN,NaN,((a+c)/2-s)/n,((h+u)/2-i)/r),[a,h,x,S]=l(this,ct).subarray(14,18),l(this,fi).push(NaN,NaN,NaN,NaN,((x+a)/2-s)/n,((S+h)/2-i)/r),!0):([x,S,a,h,c,u]=l(this,ct).subarray(0,6),l(this,Ni).push(((x+5*a)/6-s)/n,((S+5*h)/6-i)/r,((5*a+c)/6-s)/n,((5*h+u)/6-i)/r,((a+c)/2-s)/n,((h+u)/2-i)/r),[c,u,a,h,x,S]=l(this,ct).subarray(12,18),l(this,fi).push(((x+5*a)/6-s)/n,((S+5*h)/6-i)/r,((5*a+c)/6-s)/n,((5*h+u)/6-i)/r,((a+c)/2-s)/n,((h+u)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=l(this,Ni),e=l(this,fi);if(isNaN(l(this,ct)[6])&&!this.isEmpty())return w(this,de,Iy).call(this);const s=[];s.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)isNaN(t[i])?s.push(`L${t[i+4]} ${t[i+5]}`):s.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);w(this,de,Ny).call(this,s);for(let i=e.length-6;i>=6;i-=6)isNaN(e[i])?s.push(`L${e[i+4]} ${e[i+5]}`):s.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return w(this,de,jy).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new pb(t,e,s,i,n,r)}getOutlines(){var d;const t=l(this,Ni),e=l(this,fi),s=l(this,ct),[i,n,r,a]=l(this,As),h=new Float32Array((((d=l(this,br))==null?void 0:d.length)??0)+2);for(let f=0,g=h.length-2;f<g;f+=2)h[f]=(l(this,br)[f]-i)/r,h[f+1]=(l(this,br)[f+1]-n)/a;if(h[h.length-2]=(l(this,Na)-i)/r,h[h.length-1]=(l(this,Ba)-n)/a,isNaN(s[6])&&!this.isEmpty())return w(this,de,By).call(this,h);const c=new Float32Array(l(this,Ni).length+24+l(this,fi).length);let u=t.length;for(let f=0;f<u;f+=2){if(isNaN(t[f])){c[f]=c[f+1]=NaN;continue}c[f]=t[f],c[f+1]=t[f+1]}u=w(this,de,zy).call(this,c,u);for(let f=e.length-6;f>=6;f-=6)for(let g=0;g<6;g+=2){if(isNaN(e[f+g])){c[u]=c[u+1]=NaN,u+=2;continue}c[u]=e[f+g],c[u+1]=e[f+g+1],u+=2}return w(this,de,Hy).call(this,c,u),this.newFreeDrawOutline(c,h,l(this,As),l(this,lh),l(this,oh),l(this,hh))}};As=new WeakMap,fi=new WeakMap,oh=new WeakMap,hh=new WeakMap,Ni=new WeakMap,ct=new WeakMap,Na=new WeakMap,Ba=new WeakMap,Sc=new WeakMap,Cc=new WeakMap,lh=new WeakMap,ch=new WeakMap,br=new WeakMap,Ac=new WeakMap,zd=new WeakMap,Gd=new WeakMap,de=new WeakSet,Zc=function(){const t=l(this,ct).subarray(4,6),e=l(this,ct).subarray(16,18),[s,i,n,r]=l(this,As);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]},Iy=function(){const[t,e,s,i]=l(this,As),[n,r,a,h]=w(this,de,Zc).call(this);return`M${(l(this,ct)[2]-t)/s} ${(l(this,ct)[3]-e)/i} L${(l(this,ct)[4]-t)/s} ${(l(this,ct)[5]-e)/i} L${n} ${r} L${a} ${h} L${(l(this,ct)[16]-t)/s} ${(l(this,ct)[17]-e)/i} L${(l(this,ct)[14]-t)/s} ${(l(this,ct)[15]-e)/i} Z`},jy=function(t){const e=l(this,fi);t.push(`L${e[4]} ${e[5]} Z`)},Ny=function(t){const[e,s,i,n]=l(this,As),r=l(this,ct).subarray(4,6),a=l(this,ct).subarray(16,18),[h,c,u,d]=w(this,de,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}`)},By=function(t){const e=l(this,ct),[s,i,n,r]=l(this,As),[a,h,c,u]=w(this,de,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,As),l(this,lh),l(this,oh),l(this,hh))},Hy=function(t,e){const s=l(this,fi);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},zy=function(t,e){const s=l(this,ct).subarray(4,6),i=l(this,ct).subarray(16,18),[n,r,a,h]=l(this,As),[c,u,d,f]=w(this,de,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},y(Pn,Ac,8),y(Pn,zd,2),y(Pn,Gd,l(Pn,Ac)+l(Pn,zd));let Sd=Pn;class pb extends U{constructor(e,s,i,n,r,a){super();y(this,Vd);y(this,uh);y(this,Ha,new Float32Array(4));y(this,Mn);y(this,Tc);y(this,Ts);y(this,Ec);y(this,te);m(this,te,e),m(this,Ts,s),m(this,uh,i),m(this,Ec,n),m(this,Mn,r),m(this,Tc,a),this.lastPoint=[NaN,NaN],w(this,Vd,Gy).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,te)[4]} ${l(this,te)[5]}`];for(let s=6,i=l(this,te).length;s<i;s+=6){if(isNaN(l(this,te)[s])){e.push(`L${l(this,te)[s+4]} ${l(this,te)[s+5]}`);continue}e.push(`C${l(this,te)[s]} ${l(this,te)[s+1]} ${l(this,te)[s+2]} ${l(this,te)[s+3]} ${l(this,te)[s+4]} ${l(this,te)[s+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,s,i,n],r){const a=i-e,h=n-s;let c,u;switch(r){case 0:c=U._rescale(l(this,te),e,n,a,-h),u=U._rescale(l(this,Ts),e,n,a,-h);break;case 90:c=U._rescaleAndSwap(l(this,te),e,s,a,h),u=U._rescaleAndSwap(l(this,Ts),e,s,a,h);break;case 180:c=U._rescale(l(this,te),i,s,-a,h),u=U._rescale(l(this,Ts),i,s,-a,h);break;case 270:c=U._rescaleAndSwap(l(this,te),i,n,-a,-h),u=U._rescaleAndSwap(l(this,Ts),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,v=n*d+c,_=this.newOutliner({x:l(this,Ts)[0]*f+p,y:l(this,Ts)[1]*g+v},l(this,uh),l(this,Ec),e,l(this,Tc),s??l(this,Mn));for(let b=2;b<l(this,Ts).length;b+=2)_.add({x:l(this,Ts)[b]*f+p,y:l(this,Ts)[b+1]*g+v});return _.getOutlines()}}uh=new WeakMap,Ha=new WeakMap,Mn=new WeakMap,Tc=new WeakMap,Ts=new WeakMap,Ec=new WeakMap,te=new WeakMap,Vd=new WeakSet,Gy=function(e){const s=l(this,te);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,v=s.length;p<v;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 ip{constructor(t,e=0,s=0,i=!0){y(this,qe);y(this,kc);y(this,Pc);y(this,yr,[]);y(this,gi,[]);let n=1/0,r=-1/0,a=1/0,h=-1/0;const c=10**-4;for(const{x:_,y:b,width:x,height:S}of t){const A=Math.floor((_-e)/c)*c,k=Math.ceil((_+x+e)/c)*c,M=Math.floor((b-e)/c)*c,D=Math.ceil((b+S+e)/c)*c,P=[A,M,D,!0],R=[k,M,D,!1];l(this,yr).push(P,R),n=Math.min(n,A),r=Math.max(r,k),a=Math.min(a,M),h=Math.max(h,D)}const u=r-n+2*s,d=h-a+2*s,f=n-s,g=a-s,p=l(this,yr).at(i?-1:-2),v=[p[0],p[2]];for(const _ of l(this,yr)){const[b,x,S]=_;_[0]=(b-f)/u,_[1]=(x-g)/d,_[2]=(S-g)/d}m(this,kc,new Float32Array([f,g,u,d])),m(this,Pc,v)}getOutlines(){l(this,yr).sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of l(this,yr))e[3]?(t.push(...w(this,qe,em).call(this,e)),w(this,qe,Wy).call(this,e)):(w(this,qe,Xy).call(this,e),t.push(...w(this,qe,em).call(this,e)));return w(this,qe,Vy).call(this,t)}}kc=new WeakMap,Pc=new WeakMap,yr=new WeakMap,gi=new WeakMap,qe=new WeakSet,Vy=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 IC(i,l(this,kc),l(this,Pc))},vf=function(t){const e=l(this,gi);let s=0,i=e.length-1;for(;s<=i;){const n=s+i>>1,r=e[n][0];if(r===t)return n;r<t?s=n+1:i=n-1}return i+1},Wy=function([,t,e]){const s=w(this,qe,vf).call(this,t);l(this,gi).splice(s,0,[t,e])},Xy=function([,t,e]){const s=w(this,qe,vf).call(this,t);for(let i=s;i<l(this,gi).length;i++){const[n,r]=l(this,gi)[i];if(n!==t)break;if(n===t&&r===e){l(this,gi).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=l(this,gi)[i];if(n!==t)break;if(n===t&&r===e){l(this,gi).splice(i,1);return}}},em=function(t){const[e,s,i]=t,n=[[e,s,i]],r=w(this,qe,vf).call(this,i);for(let a=0;a<r;a++){const[h,c]=l(this,gi)[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 IC extends U{constructor(e,s,i){super();y(this,Mc);y(this,dh);m(this,dh,e),m(this,Mc,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,Mc)}get classNamesForOutlining(){return["highlightOutline"]}}Mc=new WeakMap,dh=new WeakMap;class np extends Sd{newFreeDrawOutline(t,e,s,i,n,r){return new jC(t,e,s,i,n,r)}}class jC extends pb{newOutliner(t,e,s,i,n,r=0){return new np(t,e,s,i,n,r)}}const ls=class ls{constructor({editor:t=null,uiManager:e=null}){y(this,Et);y(this,pi,null);y(this,za,null);y(this,fh);y(this,fe,null);y(this,Oc,!1);y(this,gh,!1);y(this,Dc,null);y(this,Rc);y(this,_r,null);y(this,mi,null);y(this,ph);var s;t?(m(this,gh,!1),m(this,ph,pt.HIGHLIGHT_COLOR),m(this,Dc,t)):(m(this,gh,!0),m(this,ph,pt.HIGHLIGHT_DEFAULT_COLOR)),m(this,mi,(t==null?void 0:t._uiManager)||e),m(this,Rc,l(this,mi)._eventBus),m(this,fh,(t==null?void 0:t.color)||((s=l(this,mi))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),l(ls,Lc)||m(ls,Lc,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 lt(this,"_keyboardManager",new ll([[["Escape","mac+Escape"],ls.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],ls.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],ls.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],ls.prototype._moveToPrevious],[["Home","mac+Home"],ls.prototype._moveToBeginning],[["End","mac+End"],ls.prototype._moveToEnd]]))}renderButton(){const t=m(this,pi,document.createElement("button"));t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.setAttribute("aria-haspopup",!0);const e=l(this,mi)._signal;t.addEventListener("click",w(this,Et,io).bind(this),{signal:e}),t.addEventListener("keydown",w(this,Et,nm).bind(this),{signal:e});const s=m(this,za,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,fe,w(this,Et,sm).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===l(this,pi)){w(this,Et,io).call(this,t);return}const e=t.target.getAttribute("data-color");e&&w(this,Et,im).call(this,e,t)}_moveToNext(t){var e,s;if(!l(this,Et,Pr)){w(this,Et,io).call(this,t);return}if(t.target===l(this,pi)){(e=l(this,fe).firstChild)==null||e.focus();return}(s=t.target.nextSibling)==null||s.focus()}_moveToPrevious(t){var e,s;if(t.target===((e=l(this,fe))==null?void 0:e.firstChild)||t.target===l(this,pi)){l(this,Et,Pr)&&this._hideDropdownFromKeyboard();return}l(this,Et,Pr)||w(this,Et,io).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!l(this,Et,Pr)){w(this,Et,io).call(this,t);return}(e=l(this,fe).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!l(this,Et,Pr)){w(this,Et,io).call(this,t);return}(e=l(this,fe).lastChild)==null||e.focus()}hideDropdown(){var t,e;(t=l(this,fe))==null||t.classList.add("hidden"),(e=l(this,_r))==null||e.abort(),m(this,_r,null)}_hideDropdownFromKeyboard(){var t;if(!l(this,gh)){if(!l(this,Et,Pr)){(t=l(this,Dc))==null||t.unselect();return}this.hideDropdown(),l(this,pi).focus({preventScroll:!0,focusVisible:l(this,Oc)})}}updateColor(t){if(l(this,za)&&(l(this,za).style.backgroundColor=t),!l(this,fe))return;const e=l(this,mi).highlightColors.values();for(const s of l(this,fe).children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){var t,e;(t=l(this,pi))==null||t.remove(),m(this,pi,null),m(this,za,null),(e=l(this,fe))==null||e.remove(),m(this,fe,null)}};pi=new WeakMap,za=new WeakMap,fh=new WeakMap,fe=new WeakMap,Oc=new WeakMap,gh=new WeakMap,Dc=new WeakMap,Rc=new WeakMap,_r=new WeakMap,mi=new WeakMap,ph=new WeakMap,Lc=new WeakMap,Et=new WeakSet,sm=function(){const t=document.createElement("div"),e=l(this,mi)._signal;t.addEventListener("contextmenu",ni,{signal:e}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[s,i]of l(this,mi).highlightColors){const n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",l(ls,Lc)[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,Et,im).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",w(this,Et,nm).bind(this),{signal:e}),t},im=function(t,e){e.stopPropagation(),l(this,Rc).dispatch("switchannotationeditorparams",{source:this,type:l(this,ph),value:t})},nm=function(t){ls._keyboardManager.exec(this,t)},io=function(t){if(l(this,Et,Pr)){this.hideDropdown();return}if(m(this,Oc,t.detail===0),l(this,_r)||(m(this,_r,new AbortController),window.addEventListener("pointerdown",w(this,Et,Uy).bind(this),{signal:l(this,mi).combinedSignal(l(this,_r))})),l(this,fe)){l(this,fe).classList.remove("hidden");return}const e=m(this,fe,w(this,Et,sm).call(this));l(this,pi).append(e)},Uy=function(t){var e;(e=l(this,fe))!=null&&e.contains(t.target)||this.hideDropdown()},Pr=function(){return l(this,fe)&&!l(this,fe).classList.contains("hidden")},y(ls,Lc,null);let Cd=ls;const _t=class _t extends Vt{constructor(e){super({...e,name:"highlightEditor"});y(this,st);y(this,mh,null);y(this,Fc,0);y(this,On);y(this,Ga,null);y(this,vh,null);y(this,cs,null);y(this,Ic,null);y(this,jc,0);y(this,Va,null);y(this,Gs,null);y(this,Es,null);y(this,xe,!1);y(this,bh,null);y(this,Dn);y(this,Fe,null);y(this,yh,"");y(this,Vs);y(this,Nc,"");this.color=e.color||_t._defaultColor,m(this,Vs,e.thickness||_t._defaultThickness),m(this,Dn,e.opacity||_t._defaultOpacity),m(this,On,e.boxes||null),m(this,Nc,e.methodOfCreation||""),m(this,yh,e.text||""),this._isDraggable=!1,e.highlightId>-1?(m(this,xe,!0),w(this,st,bf).call(this,e),w(this,st,no).call(this)):l(this,On)&&(m(this,mh,e.anchorNode),m(this,Fc,e.anchorOffset),m(this,Ic,e.focusNode),m(this,jc,e.focusOffset),w(this,st,rm).call(this),w(this,st,no).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=_t.prototype;return lt(this,"_keyboardManager",new ll([[["ArrowLeft","mac+ArrowLeft"],e._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],e._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],e._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],e._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:l(this,xe)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:l(this,Vs),methodOfCreation:l(this,Nc)}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get("color").size}}static initialize(e,s){var i;Vt.initialize(e,s),_t._defaultColor||(_t._defaultColor=((i=s.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,s){switch(e){case pt.HIGHLIGHT_DEFAULT_COLOR:_t._defaultColor=s;break;case pt.HIGHLIGHT_THICKNESS:_t._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return l(this,bh)}updateParams(e,s){switch(e){case pt.HIGHLIGHT_COLOR:w(this,st,Yy).call(this,s);break;case pt.HIGHLIGHT_THICKNESS:w(this,st,$y).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[pt.HIGHLIGHT_DEFAULT_COLOR,_t._defaultColor],[pt.HIGHLIGHT_THICKNESS,_t._defaultThickness]]}get propertiesToUpdate(){return[[pt.HIGHLIGHT_COLOR,this.color||_t._defaultColor],[pt.HIGHLIGHT_THICKNESS,l(this,Vs)||_t._defaultThickness],[pt.HIGHLIGHT_FREE,l(this,xe)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(m(this,vh,new Cd({editor:this})),e.addColorPicker(l(this,vh))),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,am).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,am).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,xe)?(e=(e-this.rotation+360)%360,i=w(n=_t,Ws,Nh).call(n,l(this,Gs).box,e)):i=w(r=_t,Ws,Nh).call(r,[this.x,this.y,this.width,this.height],e),s.updateProperties(l(this,Es),{bbox:i,root:{"data-main-rotation":e}}),s.updateProperties(l(this,Fe),{bbox:w(a=_t,Ws,Nh).call(a,l(this,cs).box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();l(this,yh)&&(e.setAttribute("aria-label",l(this,yh)),e.setAttribute("role","mark")),l(this,xe)?e.classList.add("free"):this.div.addEventListener("keydown",w(this,st,Ky).bind(this),{signal:this._uiManager._signal});const s=m(this,Va,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=l(this,Ga);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),gd(this,l(this,Va),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Fe),{rootClass:{hovered:!0}})}pointerleave(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Fe),{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,Fe)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Fe),{rootClass:{hovered:!1,selected:!0}}))}unselect(){var e;super.unselect(),l(this,Fe)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Fe),{rootClass:{selected:!1}}),l(this,xe)||w(this,st,yf).call(this,!1))}get _mustFixPosition(){return!l(this,xe)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(l(this,Es),{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(l(this,Fe),{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,t_).call(this,e,p)};window.addEventListener("blur",g,{signal:f}),window.addEventListener("pointerup",g,{signal:f}),window.addEventListener("pointerdown",ms,{capture:!0,passive:!1,signal:f}),window.addEventListener("contextmenu",ni,{signal:f}),i.addEventListener("pointermove",w(this,Ws,Zy).bind(this,e),{signal:f}),this._freeHighlight=new np({x:n,y:r},[a,h,c,u],e.scale,this._defaultThickness/2,s,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static async deserialize(e,s,i){var v,_,b,x;let n=null;if(e instanceof fb){const{data:{quadPoints:S,rect:A,rotation:k,id:M,color:D,opacity:P,popupRef:R},parent:{page:{pageNumber:F}}}=e;n=e={annotationType:nt.HIGHLIGHT,color:Array.from(D),opacity:P,quadPoints:S,boxes:null,pageIndex:F-1,rect:A.slice(0),rotation:k,id:M,deleted:!1,popupRef:R}}else if(e instanceof ep){const{data:{inkLists:S,rect:A,rotation:k,id:M,color:D,borderStyle:{rawWidth:P},popupRef:R},parent:{page:{pageNumber:F}}}=e;n=e={annotationType:nt.HIGHLIGHT,color:Array.from(D),thickness:P,inkLists:S,boxes:null,pageIndex:F-1,rect:A.slice(0),rotation:k,id:M,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 S=m(u,On,[]);for(let A=0;A<a.length;A+=8)S.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(v=u,st,rm).call(v),w(_=u,st,no).call(_),u.rotate(u.rotation)}else if(h){m(u,xe,!0);const S=h[0],A={x:S[0]-g,y:f-(S[1]-p)},k=new np(A,[0,0,d,f],1,l(u,Vs)/2,!0,.001);for(let P=0,R=S.length;P<R;P+=2)A.x=S[P]-g,A.y=f-(S[P+1]-p),k.add(A);const{id:M,clipPathId:D}=s.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:u.color,"fill-opacity":u._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:k.toSVGPath()}},!0,!0);w(b=u,st,bf).call(b,{highlightOutlines:k.getOutlines(),highlightId:M,clipPathId:D}),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=Vt._colorManager.convert(this.color),n={annotationType:nt.HIGHLIGHT,color:i,opacity:l(this,Dn),thickness:l(this,Vs),quadPoints:w(this,st,Jy).call(this),outlines:w(this,st,Qy).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:w(this,st,tu).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!w(this,st,e_).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,Fc=new WeakMap,On=new WeakMap,Ga=new WeakMap,vh=new WeakMap,cs=new WeakMap,Ic=new WeakMap,jc=new WeakMap,Va=new WeakMap,Gs=new WeakMap,Es=new WeakMap,xe=new WeakMap,bh=new WeakMap,Dn=new WeakMap,Fe=new WeakMap,yh=new WeakMap,Vs=new WeakMap,Nc=new WeakMap,st=new WeakSet,rm=function(){const e=new ip(l(this,On),.001);m(this,Gs,e.getOutlines()),[this.x,this.y,this.width,this.height]=l(this,Gs).box;const s=new ip(l(this,On),.0025,.001,this._uiManager.direction==="ltr");m(this,cs,s.getOutlines());const{lastPoint:i}=l(this,cs);m(this,bh,[(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,Gs,e),m(this,cs,e.getNewOutline(l(this,Vs)/2+1.5,.0025)),s>=0)m(this,Es,s),m(this,Ga,i),this.parent.drawLayer.finalizeDraw(s,{bbox:e.box,path:{d:e.toSVGPath()}}),m(this,Fe,this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:l(this,cs).box,path:{d:l(this,cs).toSVGPath()}},!0));else if(this.parent){const g=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(l(this,Es),{bbox:w(d=_t,Ws,Nh).call(d,l(this,Gs).box,(g-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(l(this,Fe),{bbox:w(f=_t,Ws,Nh).call(f,l(this,cs).box,g),path:{d:l(this,cs).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,cs);m(this,bh,[(u[0]-r)/h,(u[1]-a)/c])},Yy=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,Es),{root:{fill:r,"fill-opacity":a}}),(c=l(this,vh))==null||c.updateColor(r)},i=this.color,n=l(this,Dn);this.addCommands({cmd:s.bind(this,e,_t._defaultOpacity),undo:s.bind(this,i,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:pt.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},$y=function(e){const s=l(this,Vs),i=n=>{m(this,Vs,n),w(this,st,qy).call(this,n)};this.addCommands({cmd:i.bind(this,e),undo:i.bind(this,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:pt.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},qy=function(e){if(!l(this,xe))return;w(this,st,bf).call(this,{highlightOutlines:l(this,Gs).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},am=function(){l(this,Es)===null||!this.parent||(this.parent.drawLayer.remove(l(this,Es)),m(this,Es,null),this.parent.drawLayer.remove(l(this,Fe)),m(this,Fe,null))},no=function(e=this.parent){l(this,Es)===null&&({id:ts(this,Es)._,clipPathId:ts(this,Ga)._}=e.drawLayer.draw({bbox:l(this,Gs).box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":l(this,Dn)},rootClass:{highlight:!0,free:l(this,xe)},path:{d:l(this,Gs).toSVGPath()}},!1,!0),m(this,Fe,e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:l(this,xe)},bbox:l(this,cs).box,path:{d:l(this,cs).toSVGPath()}},l(this,xe))),l(this,Va)&&(l(this,Va).style.clipPath=l(this,Ga)))},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]},Ky=function(e){_t._keyboardManager.exec(this,e)},yf=function(e){if(!l(this,mh))return;const s=window.getSelection();e?s.setPosition(l(this,mh),l(this,Fc)):s.setPosition(l(this,Ic),l(this,jc))},tu=function(){return l(this,xe)?this.rotation:0},Jy=function(){if(l(this,xe))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},Qy=function(e){return l(this,Gs).serialize(e,w(this,st,tu).call(this))},Zy=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},t_=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=""},e_=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},y(_t,Ws),J(_t,"_defaultColor",null),J(_t,"_defaultOpacity",1),J(_t,"_defaultThickness",12),J(_t,"_type","highlight"),J(_t,"_editorType",nt.HIGHLIGHT),J(_t,"_freeHighlightId",-1),J(_t,"_freeHighlight",null),J(_t,"_freeHighlightClipId","");let Ad=_t;class NC{constructor(){y(this,Wa,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,Wa)[t]=e}toSVGProperties(){const t=l(this,Wa);return m(this,Wa,Object.create(null)),{root:t}}reset(){m(this,Wa,Object.create(null))}updateAll(t=this){this.updateProperties(t)}clone(){Pt("Not implemented")}}Wa=new WeakMap;const Y=class Y extends Vt{constructor(e){super(e);y(this,bt);y(this,ks,null);y(this,_h);J(this,"_drawId",null);m(this,_h,e.mustBeCommitted||!1),e.drawOutlines&&(w(this,bt,om).call(this,e),w(this,bt,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){Pt("Not implemented")}static get typesMap(){Pt("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,s){const i=this.typesMap.get(e);i&&this._defaultDrawingOptions.updateProperty(i,s),this._currentParent&&(l(Y,ve).updateProperty(i,s),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,s){const i=this.constructor.typesMap.get(e);i&&this._updateProperty(e,i,s)}static get defaultPropertiesToUpdate(){const e=[],s=this._defaultDrawingOptions;for(const[i,n]of this.typesMap)e.push([i,s[n]]);return e}get propertiesToUpdate(){const e=[],{_drawingOptions:s}=this;for(const[i,n]of this.constructor.typesMap)e.push([i,s[n]]);return e}_updateProperty(e,s,i){const n=this._drawingOptions,r=n[s],a=h=>{var u;n.updateProperty(s,h);const c=l(this,ks).updateProperty(s,h);c&&w(this,bt,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,Y._mergeSVGProperties(l(this,ks).getPathResizingSVGProperties(w(this,bt,_f).call(this)),{bbox:w(this,bt,Bh).call(this)}))}_onResized(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,Y._mergeSVGProperties(l(this,ks).getPathResizedSVGProperties(w(this,bt,_f).call(this)),{bbox:w(this,bt,Bh).call(this)}))}_onTranslating(e,s){var i;(i=this.parent)==null||i.drawLayer.updateProperties(this._drawId,{bbox:w(this,bt,Bh).call(this,e,s)})}_onTranslated(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,Y._mergeSVGProperties(l(this,ks).getPathTranslatedSVGProperties(w(this,bt,_f).call(this),this.parentDimensions),{bbox:w(this,bt,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,bt,lm).call(this),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,bt,eu).call(this),w(this,bt,su).call(this,l(this,ks).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),w(this,bt,lm).call(this)):e&&(this._uiManager.addShouldRescale(this),w(this,bt,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,Y._mergeSVGProperties({bbox:w(this,bt,Bh).call(this)},l(this,ks).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&w(this,bt,su).call(this,l(this,ks).updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;const e=super.render();e.classList.add("draw");const s=document.createElement("div");e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal";const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),this._uiManager.addShouldRescale(this),this.disableEditing(),e}static createDrawerInstance(e,s,i,n,r){Pt("Not implemented")}static startDrawing(e,s,i,n){var _;const{target:r,offsetX:a,offsetY:h,pointerId:c,pointerType:u}=n;if(l(Y,xr)&&l(Y,xr)!==u)return;const{viewport:{rotation:d}}=e,{width:f,height:g}=r.getBoundingClientRect(),p=m(Y,Xa,new AbortController),v=e.combinedSignal(p);if(l(Y,wr)||m(Y,wr,c),l(Y,xr)??m(Y,xr,u),window.addEventListener("pointerup",b=>{var x;l(Y,wr)===b.pointerId?this._endDraw(b):(x=l(Y,Sr))==null||x.delete(b.pointerId)},{signal:v}),window.addEventListener("pointercancel",b=>{var x;l(Y,wr)===b.pointerId?this._currentParent.endDrawingSession():(x=l(Y,Sr))==null||x.delete(b.pointerId)},{signal:v}),window.addEventListener("pointerdown",b=>{l(Y,xr)===b.pointerType&&((l(Y,Sr)||m(Y,Sr,new Set)).add(b.pointerId),l(Y,ve).isCancellable()&&(l(Y,ve).removeLastElement(),l(Y,ve).isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:v}),window.addEventListener("contextmenu",ni,{signal:v}),r.addEventListener("pointermove",this._drawMove.bind(this),{signal:v}),r.addEventListener("touchmove",b=>{b.timeStamp===l(Y,Ya)&&ms(b)},{signal:v}),e.toggleDrawing(),(_=s._editorUndoBar)==null||_.hide(),l(Y,ve)){e.drawLayer.updateProperties(this._currentDrawId,l(Y,ve).startNew(a,h,f,g,d));return}s.updateUIForDefaultProperties(this),m(Y,ve,this.createDrawerInstance(a,h,f,g,d)),m(Y,Ua,this.getDefaultDrawingOptions()),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(l(Y,Ua).toSVGProperties(),l(Y,ve).defaultSVGProperties),!0,!1)}static _drawMove(e){var r;if(m(Y,Ya,-1),!l(Y,ve))return;const{offsetX:s,offsetY:i,pointerId:n}=e;if(l(Y,wr)===n){if(((r=l(Y,Sr))==null?void 0:r.size)>=1){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,l(Y,ve).add(s,i)),m(Y,Ya,e.timeStamp),ms(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,m(Y,ve,null),m(Y,Ua,null),m(Y,xr,null),m(Y,Ya,NaN)),l(Y,Xa)&&(l(Y,Xa).abort(),m(Y,Xa,null),m(Y,wr,NaN),m(Y,Sr,null))}static _endDraw(e){const s=this._currentParent;if(s){if(s.toggleDrawing(!0),this._cleanup(!1),e&&s.drawLayer.updateProperties(this._currentDrawId,l(Y,ve).end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const i=l(Y,ve),n=this._currentDrawId,r=i.getLastElement();s.addCommands({cmd:()=>{s.drawLayer.updateProperties(n,i.setLastElement(r))},undo:()=>{s.drawLayer.updateProperties(n,i.removeLastElement())},mustExec:!1,type:pt.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const s=this._currentParent;if(!s)return null;if(s.toggleDrawing(!0),s.cleanUndoStack(pt.DRAW_STEP),!l(Y,ve).isEmpty()){const{pageDimensions:[i,n],scale:r}=s,a=s.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:l(Y,ve).getOutlines(i*r,n*r,r,this._INNER_MARGIN),drawingOptions:l(Y,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){Pt("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,bt,om).call(d,{drawOutlines:c}),w(f=u,bt,eu).call(f),u.onScaleChanging(),u.rotate(),u}serializeDraw(e){const[s,i]=this.pageTranslation,[n,r]=this.pageDimensions;return l(this,ks).serialize([s,i,n,r],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};ks=new WeakMap,_h=new WeakMap,ve=new WeakMap,Xa=new WeakMap,Ua=new WeakMap,wr=new WeakMap,xr=new WeakMap,Sr=new WeakMap,Ya=new WeakMap,bt=new WeakSet,om=function({drawOutlines:e,drawId:s,drawingOptions:i}){m(this,ks,e),this._drawingOptions||(this._drawingOptions=i),s>=0?(this._drawId=s,this.parent.drawLayer.finalizeDraw(s,e.defaultProperties)):this._drawId=w(this,bt,hm).call(this,e,this.parent),w(this,bt,su).call(this,e.box)},hm=function(e,s){const{id:i}=s.drawLayer.draw(Y._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return i},lm=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,bt,hm).call(this,l(this,ks),e)}},s_=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]}},_f=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,bt,s_).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(Y,"_currentDrawId",-1),J(Y,"_currentParent",null),y(Y,ve,null),y(Y,Xa,null),y(Y,Ua,null),y(Y,wr,NaN),y(Y,xr,null),y(Y,Sr,null),y(Y,Ya,NaN),J(Y,"_INNER_MARGIN",3);let rp=Y;class BC{constructor(t,e,s,i,n,r){y(this,xh);y(this,Bi,new Float64Array(6));y(this,be);y(this,ye);y(this,$a);y(this,wh);y(this,Ke);y(this,Se,"");y(this,Xs,0);y(this,qa,new Td);y(this,Ka);y(this,Ja);m(this,Ka,s),m(this,Ja,i),m(this,$a,n),m(this,wh,r),[t,e]=w(this,xh,wf).call(this,t,e);const a=m(this,be,[NaN,NaN,NaN,NaN,t,e]);m(this,Ke,[t,e]),m(this,ye,[{line:a,points:l(this,Ke)}]),l(this,Bi).set(a,0)}updateProperty(t,e){t==="stroke-width"&&m(this,wh,e)}isEmpty(){return!l(this,ye)||l(this,ye).length===0}isCancellable(){return l(this,Ke).length<=10}add(t,e){[t,e]=w(this,xh,wf).call(this,t,e);const[s,i,n,r]=l(this,Bi).subarray(2,6),a=t-n,h=e-r;return Math.hypot(l(this,Ka)*a,l(this,Ja)*h)<=2?null:(l(this,Ke).push(t,e),isNaN(s)?(l(this,Bi).set([n,r,t,e],2),l(this,be).push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(l(this,Bi)[0])&&l(this,be).splice(6,6),l(this,Bi).set([s,i,n,r,t,e],0),l(this,be).push(...U.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const s=this.add(t,e);return s||(l(this,Ke).length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){m(this,Ka,s),m(this,Ja,i),m(this,$a,n),[t,e]=w(this,xh,wf).call(this,t,e);const r=m(this,be,[NaN,NaN,NaN,NaN,t,e]);m(this,Ke,[t,e]);const a=l(this,ye).at(-1);return a&&(a.line=new Float32Array(a.line),a.points=new Float32Array(a.points)),l(this,ye).push({line:r,points:l(this,Ke)}),l(this,Bi).set(r,0),m(this,Xs,0),this.toSVGPath(),null}getLastElement(){return l(this,ye).at(-1)}setLastElement(t){return l(this,ye)?(l(this,ye).push(t),m(this,be,t.line),m(this,Ke,t.points),m(this,Xs,0),{path:{d:this.toSVGPath()}}):l(this,qa).setLastElement(t)}removeLastElement(){if(!l(this,ye))return l(this,qa).removeLastElement();l(this,ye).pop(),m(this,Se,"");for(let t=0,e=l(this,ye).length;t<e;t++){const{line:s,points:i}=l(this,ye)[t];m(this,be,s),m(this,Ke,i),m(this,Xs,0),this.toSVGPath()}return{path:{d:l(this,Se)}}}toSVGPath(){const t=U.svgRound(l(this,be)[4]),e=U.svgRound(l(this,be)[5]);if(l(this,Ke).length===2)return m(this,Se,`${l(this,Se)} M ${t} ${e} Z`),l(this,Se);if(l(this,Ke).length<=6){const i=l(this,Se).lastIndexOf("M");m(this,Se,`${l(this,Se).slice(0,i)} M ${t} ${e}`),m(this,Xs,6)}if(l(this,Ke).length===4){const i=U.svgRound(l(this,be)[10]),n=U.svgRound(l(this,be)[11]);return m(this,Se,`${l(this,Se)} L ${i} ${n}`),m(this,Xs,12),l(this,Se)}const s=[];l(this,Xs)===0&&(s.push(`M ${t} ${e}`),m(this,Xs,6));for(let i=l(this,Xs),n=l(this,be).length;i<n;i+=6){const[r,a,h,c,u,d]=l(this,be).slice(i,i+6).map(U.svgRound);s.push(`C${r} ${a} ${h} ${c} ${u} ${d}`)}return m(this,Se,l(this,Se)+s.join(" ")),m(this,Xs,l(this,be).length),l(this,Se)}getOutlines(t,e,s,i){const n=l(this,ye).at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),l(this,qa).build(l(this,ye),t,e,s,l(this,$a),l(this,wh),i),m(this,Bi,null),m(this,be,null),m(this,ye,null),m(this,Se,null),l(this,qa)}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}Bi=new WeakMap,be=new WeakMap,ye=new WeakMap,$a=new WeakMap,wh=new WeakMap,Ke=new WeakMap,Se=new WeakMap,Xs=new WeakMap,qa=new WeakMap,Ka=new WeakMap,Ja=new WeakMap,xh=new WeakSet,wf=function(t,e){return U._normalizePoint(t,e,l(this,Ka),l(this,Ja),l(this,$a))};const pp=class pp extends U{constructor(){super(...arguments);y(this,Ce);y(this,Je);y(this,Bc,0);y(this,Hc);y(this,Ps);y(this,Hi);y(this,zi);y(this,Sh);y(this,Ch);y(this,Ah)}build(e,s,i,n,r,a,h){m(this,Hi,s),m(this,zi,i),m(this,Sh,n),m(this,Ch,r),m(this,Ah,a),m(this,Hc,h??0),m(this,Ps,e),w(this,Ce,n_).call(this)}setLastElement(e){return l(this,Ps).push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return l(this,Ps).pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:s}of l(this,Ps)){if(e.push(`M${U.svgRound(s[4])} ${U.svgRound(s[5])}`),s.length===6){e.push("Z");continue}if(s.length===12){e.push(`L${U.svgRound(s[10])} ${U.svgRound(s[11])}`);continue}for(let i=6,n=s.length;i<n;i+=6){const[r,a,h,c,u,d]=s.subarray(i,i+6).map(U.svgRound);e.push(`C${r} ${a} ${h} ${c} ${u} ${d}`)}}return e.join("")}serialize([e,s,i,n],r){const a=[],h=[],[c,u,d,f]=w(this,Ce,i_).call(this);let g,p,v,_,b,x,S,A,k;switch(l(this,Ch)){case 0:k=U._rescale,g=e,p=s+n,v=i,_=-n,b=e+c*i,x=s+(1-u-f)*n,S=e+(c+d)*i,A=s+(1-u)*n;break;case 90:k=U._rescaleAndSwap,g=e,p=s,v=i,_=n,b=e+u*i,x=s+c*n,S=e+(u+f)*i,A=s+(c+d)*n;break;case 180:k=U._rescale,g=e+i,p=s,v=-i,_=n,b=e+(1-c-d)*i,x=s+u*n,S=e+(1-c)*i,A=s+(u+f)*n;break;case 270:k=U._rescaleAndSwap,g=e+i,p=s+n,v=-i,_=-n,b=e+(1-u-f)*i,x=s+(1-c-d)*n,S=e+(1-u)*i,A=s+(1-c)*n;break}for(const{line:M,points:D}of l(this,Ps))a.push(k(M,g,p,v,_,r?new Array(M.length):null)),h.push(k(D,g,p,v,_,r?new Array(D.length):null));return{lines:a,points:h,rect:[b,x,S,A]}}static deserialize(e,s,i,n,r,{paths:{lines:a,points:h},rotation:c,thickness:u}){const d=[];let f,g,p,v,_;switch(c){case 0:_=U._rescale,f=-e/i,g=s/n+1,p=1/i,v=-1/n;break;case 90:_=U._rescaleAndSwap,f=-s/n,g=-e/i,p=1/n,v=1/i;break;case 180:_=U._rescale,f=e/i+1,g=-s/n,p=-1/i,v=1/n;break;case 270:_=U._rescaleAndSwap,f=s/n+1,g=e/i+1,p=-1/n,v=-1/i;break}if(!a){a=[];for(const x of h){const S=x.length;if(S===2){a.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1]]));continue}if(S===4){a.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1],NaN,NaN,NaN,NaN,x[2],x[3]]));continue}const A=new Float32Array(3*(S-2));a.push(A);let[k,M,D,P]=x.subarray(0,4);A.set([NaN,NaN,NaN,NaN,k,M],0);for(let R=4;R<S;R+=2){const F=x[R],I=x[R+1];A.set(U.createBezierPoints(k,M,D,P,F,I),(R-2)*3),[k,M,D,P]=[D,P,F,I]}}}for(let x=0,S=a.length;x<S;x++)d.push({line:_(a[x].map(A=>A??NaN),f,g,p,v),points:_(h[x].map(A=>A??NaN),f,g,p,v)});const b=new pp;return b.build(d,i,n,1,c,u,r),b}get box(){return l(this,Je)}updateProperty(e,s){return e==="stroke-width"?w(this,Ce,r_).call(this,s):null}updateParentDimensions([e,s],i){const[n,r]=w(this,Ce,Nn).call(this);m(this,Hi,e),m(this,zi,s),m(this,Sh,i);const[a,h]=w(this,Ce,Nn).call(this),c=a-n,u=h-r,d=l(this,Je);return d[0]-=c,d[1]-=u,d[2]+=2*c,d[3]+=2*u,d}updateRotation(e){return m(this,Bc,e),{path:{transform:this.rotationTransform}}}get viewBox(){return l(this,Je).map(U.svgRound).join(" ")}get defaultProperties(){const[e,s]=l(this,Je);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${U.svgRound(e)} ${U.svgRound(s)}`}}}get rotationTransform(){const[,,e,s]=l(this,Je);let i=0,n=0,r=0,a=0,h=0,c=0;switch(l(this,Bc)){case 90:n=s/e,r=-e/s,h=e;break;case 180:i=-1,a=-1,h=e,c=s;break;case 270:n=-s/e,r=e/s,c=s;break;default:return""}return`matrix(${i} ${n} ${r} ${a} ${U.svgRound(h)} ${U.svgRound(c)})`}getPathResizingSVGProperties([e,s,i,n]){const[r,a]=w(this,Ce,Nn).call(this),[h,c,u,d]=l(this,Je);if(Math.abs(u-r)<=U.PRECISION||Math.abs(d-a)<=U.PRECISION){const _=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(${_} ${b})`}}}const f=(i-2*r)/(u-2*r),g=(n-2*a)/(d-2*a),p=u/i,v=d/n;return{path:{"transform-origin":`${U.svgRound(h)} ${U.svgRound(c)}`,transform:`${this.rotationTransform} scale(${p} ${v}) translate(${U.svgRound(r)} ${U.svgRound(a)}) scale(${f} ${g}) translate(${U.svgRound(-r)} ${U.svgRound(-a)})`}}}getPathResizedSVGProperties([e,s,i,n]){const[r,a]=w(this,Ce,Nn).call(this),h=l(this,Je),[c,u,d,f]=h;if(h[0]=e,h[1]=s,h[2]=i,h[3]=n,Math.abs(d-r)<=U.PRECISION||Math.abs(f-a)<=U.PRECISION){const b=e+i/2-(c+d/2),x=s+n/2-(u+f/2);for(const{line:S,points:A}of l(this,Ps))U._translate(S,b,x,S),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 g=(i-2*r)/(d-2*r),p=(n-2*a)/(f-2*a),v=-g*(c+r)+e+r,_=-p*(u+a)+s+a;if(g!==1||p!==1||v!==0||_!==0)for(const{line:b,points:x}of l(this,Ps))U._rescale(b,v,_,g,p,b),U._rescale(x,v,_,g,p,x);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${U.svgRound(e)} ${U.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,s],i){const[n,r]=i,a=l(this,Je),h=e-a[0],c=s-a[1];if(l(this,Hi)===n&&l(this,zi)===r)for(const{line:u,points:d}of l(this,Ps))U._translate(u,h,c,u),U._translate(d,h,c,d);else{const u=l(this,Hi)/n,d=l(this,zi)/r;m(this,Hi,n),m(this,zi,r);for(const{line:f,points:g}of l(this,Ps))U._rescale(f,h,c,u,d,f),U._rescale(g,h,c,u,d,g);a[2]*=u,a[3]*=d}return a[0]=e,a[1]=s,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${U.svgRound(e)} ${U.svgRound(s)}`}}}get defaultSVGProperties(){const e=l(this,Je);return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${U.svgRound(e[0])} ${U.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}};Je=new WeakMap,Bc=new WeakMap,Hc=new WeakMap,Ps=new WeakMap,Hi=new WeakMap,zi=new WeakMap,Sh=new WeakMap,Ch=new WeakMap,Ah=new WeakMap,Ce=new WeakSet,Nn=function(e=l(this,Ah)){const s=l(this,Hc)+e/2*l(this,Sh);return l(this,Ch)%180===0?[s/l(this,Hi),s/l(this,zi)]:[s/l(this,zi),s/l(this,Hi)]},i_=function(){const[e,s,i,n]=l(this,Je),[r,a]=w(this,Ce,Nn).call(this,0);return[e+r,s+a,i-2*r,n-2*a]},n_=function(){const e=m(this,Je,new Float32Array([1/0,1/0,-1/0,-1/0]));for(const{line:n}of l(this,Ps)){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,v]=n.subarray(h,h+6);q.bezierBoundingBox(r,a,u,d,f,g,p,v,e),r=p,a=v}}const[s,i]=w(this,Ce,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]},r_=function(e){const[s,i]=w(this,Ce,Nn).call(this);m(this,Ah,e);const[n,r]=w(this,Ce,Nn).call(this),[a,h]=[n-s,r-i],c=l(this,Je);return c[0]-=a,c[1]-=h,c[2]+=2*a,c[3]+=2*h,c};let Td=pp;const mp=class mp extends NC{constructor(e){super();y(this,Th);m(this,Th,e),super.updateProperties({fill:"none",stroke:Vt._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(e,s){e==="stroke-width"&&(s??(s=this["stroke-width"]),s*=l(this,Th).realScale),super.updateSVGProperty(e,s)}clone(){const e=new mp(l(this,Th));return e.updateAll(this),e}};Th=new WeakMap;let ap=mp;const Eh=class Eh extends rp{constructor(e){super({...e,name:"inkEditor"});y(this,Wd);this._willKeepAspectRatio=!0}static initialize(e,s){Vt.initialize(e,s),this._defaultDrawingOptions=new ap(s.viewParameters)}static getDefaultDrawingOptions(e){const s=this._defaultDrawingOptions.clone();return s.updateProperties(e),s}static get supportMultipleDrawings(){return!0}static get typesMap(){return lt(this,"typesMap",new Map([[pt.INK_THICKNESS,"stroke-width"],[pt.INK_COLOR,"stroke"],[pt.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(e,s,i,n,r){return new BC(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 ep){const{data:{inkLists:a,rect:h,rotation:c,id:u,color:d,opacity:f,borderStyle:{rawWidth:g},popupRef:p},parent:{page:{pageNumber:v}}}=e;n=e={annotationType:nt.INK,color:Array.from(d),thickness:g,opacity:f,paths:{points:a},boxes:null,pageIndex:v-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:Vt._colorManager.convert(r),opacity:a,thickness:h,paths:{lines:s,points:i},pageIndex:this.pageIndex,rect:n,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?c:this.annotationElementId&&!w(this,Wd,a_).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}};Wd=new WeakSet,a_=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 op=Eh;const zc=class zc extends Vt{constructor(e){super({...e,name:"stampEditor"});y(this,yt);y(this,Xt,null);y(this,Ae,null);y(this,Cr,null);y(this,Rn,null);y(this,Ar,null);y(this,kh,"");y(this,Gi,null);y(this,Vi,null);y(this,Ms,!1);y(this,Ph,!1);m(this,Rn,e.bitmapUrl),m(this,Ar,e.bitmapFile)}static initialize(e,s){Vt.initialize(e,s)}static get supportedTypes(){return lt(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return lt(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,Ae)&&(m(this,Xt,null),this._uiManager.imageManager.deleteId(l(this,Ae)),(e=l(this,Gi))==null||e.remove(),m(this,Gi,null),l(this,Vi)&&(clearTimeout(l(this,Vi)),m(this,Vi,null))),super.remove()}rebuild(){if(!this.parent){l(this,Ae)&&w(this,yt,xf).call(this);return}super.rebuild(),this.div!==null&&(l(this,Ae)&&l(this,Gi)===null&&w(this,yt,xf).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(e){this._isDraggable=!0,e&&this.div.focus()}isEmpty(){return!(l(this,Cr)||l(this,Xt)||l(this,Rn)||l(this,Ar)||l(this,Ae))}get isResizable(){return!0}render(){if(this.div)return this.div;let e,s;if(this.width&&(e=this.x,s=this.y),super.render(),this.div.hidden=!0,this.div.setAttribute("role","figure"),this.addAltTextButton(),l(this,Xt)?w(this,yt,cm).call(this):w(this,yt,xf).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,Vi)!==null&&clearTimeout(l(this,Vi)),m(this,Vi,setTimeout(()=>{m(this,Vi,null),w(this,yt,um).call(this)},200))}copyCanvas(e,s,i=!1){var g;e||(e=224);const{width:n,height:r}=l(this,Xt),a=new Bg;let h=l(this,Xt),c=n,u=r,d=null;if(s){if(n>s||r>s){const P=Math.min(s/n,s/r);c=Math.floor(n*P),u=Math.floor(r*P)}d=document.createElement("canvas");const p=d.width=Math.ceil(c*a.sx),v=d.height=Math.ceil(u*a.sy);l(this,Ms)||(h=w(this,yt,Sf).call(this,p,v));const _=d.getContext("2d");_.filter=this._uiManager.hcmFilter;let b="white",x="#cfcfd8";this._uiManager.hcmFilter!=="none"?x="black":(g=window.matchMedia)!=null&&g.call(window,"(prefers-color-scheme: dark)").matches&&(b="#8f8f9d",x="#42414d");const S=15,A=S*a.sx,k=S*a.sy,M=new OffscreenCanvas(A*2,k*2),D=M.getContext("2d");D.fillStyle=b,D.fillRect(0,0,A*2,k*2),D.fillStyle=x,D.fillRect(0,0,A,k),D.fillRect(A,k,A,k),_.fillStyle=_.createPattern(M,"repeat"),_.fillRect(0,0,p,v),_.drawImage(h,0,0,h.width,h.height,0,0,p,v)}let f=null;if(i){let p,v;if(a.symmetric&&h.width<e&&h.height<e)p=h.width,v=h.height;else if(h=l(this,Xt),n>e||r>e){const x=Math.min(e/n,e/r);p=Math.floor(n*x),v=Math.floor(r*x),l(this,Ms)||(h=w(this,yt,Sf).call(this,p,v))}const b=new OffscreenCanvas(p,v).getContext("2d",{willReadFrequently:!0});b.drawImage(h,0,0,h.width,h.height,0,0,p,v),f={width:p,height:v,data:b.getImageData(0,0,p,v).data}}return{canvas:d,width:c,height:u,imageData:f}}getImageForAltText(){return l(this,Gi)}static async deserialize(e,s,i){var v;let n=null;if(e instanceof gb){const{data:{rect:_,rotation:b,id:x,structParent:S,popupRef:A},container:k,parent:{page:{pageNumber:M}}}=e,D=k.querySelector("canvas"),P=i.imageManager.getFromCanvas(k.id,D);D.remove();const R=((v=await s._structTree.getAriaAttributes(`${Lg}${x}`))==null?void 0:v.get("aria-label"))||"";n=e={annotationType:nt.STAMP,bitmapId:P.id,bitmap:P.bitmap,pageIndex:M-1,rect:_.slice(0),rotation:b,id:x,deleted:!1,accessibilityData:{decorative:!1,altText:R},isSvg:!1,structParent:S,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,Ae,u),h&&m(r,Xt,h)):m(r,Rn,c),m(r,Ms,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,Ae),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:l(this,Ms),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=w(this,yt,Cf).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,yt,o_).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,Ms)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!s.stamps.has(l(this,Ae)))s.stamps.set(l(this,Ae),{area:a,serialized:i}),i.bitmap=w(this,yt,Cf).call(this,!1);else if(l(this,Ms)){const h=s.stamps.get(l(this,Ae));a>h.area&&(h.area=a,h.serialized.bitmap.close(),h.serialized.bitmap=w(this,yt,Cf).call(this,!1))}return i}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}};Xt=new WeakMap,Ae=new WeakMap,Cr=new WeakMap,Rn=new WeakMap,Ar=new WeakMap,kh=new WeakMap,Gi=new WeakMap,Vi=new WeakMap,Ms=new WeakMap,Ph=new WeakMap,yt=new WeakSet,iu=function(e,s=!1){if(!e){this.remove();return}m(this,Xt,e.bitmap),s||(m(this,Ae,e.id),m(this,Ms,e.isSvg)),e.file&&m(this,kh,e.file.name),w(this,yt,cm).call(this)},nu=function(){if(m(this,Cr,null),this._uiManager.enableWaiting(!1),!!l(this,Gi)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Xt)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Xt)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},xf=function(){if(l(this,Ae)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(l(this,Ae)).then(i=>w(this,yt,iu).call(this,i,!0)).finally(()=>w(this,yt,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,yt,iu).call(this,n)).finally(()=>w(this,yt,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,yt,iu).call(this,n)).finally(()=>w(this,yt,nu).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=zc.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,yt,iu).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>w(this,yt,nu).call(this))),e.click()},cm=function(){var d;const{div:e}=this;let{width:s,height:i}=l(this,Xt);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,Gi,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,yt,um).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))},Sf=function(e,s){const{width:i,height:n}=l(this,Xt);let r=i,a=n,h=l(this,Xt);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},um=function(){const[e,s]=this.parentDimensions,{width:i,height:n}=this,r=new Bg,a=Math.ceil(i*e*r.sx),h=Math.ceil(n*s*r.sy),c=l(this,Gi);if(!c||c.width===a&&c.height===h)return;c.width=a,c.height=h;const u=l(this,Ms)?l(this,Xt):w(this,yt,Sf).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)},Cf=function(e){if(e){if(l(this,Ms)){const n=this._uiManager.imageManager.getSvgUrl(l(this,Ae));if(n)return n}const s=document.createElement("canvas");return{width:s.width,height:s.height}=l(this,Xt),s.getContext("2d").drawImage(l(this,Xt),0,0),s.toDataURL()}if(l(this,Ms)){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,Xt),0,0,l(this,Xt).width,l(this,Xt).height,0,0,n,r),a.transferToImageBitmap()}return structuredClone(l(this,Xt))},o_=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(zc,"_type","stamp"),J(zc,"_editorType",nt.STAMP);let hp=zc;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}){y(this,Ht);y(this,Qa);y(this,Mh,!1);y(this,Wi,null);y(this,Tr,null);y(this,Ln,null);y(this,Us,new Map);y(this,Er,!1);y(this,Oh,!1);y(this,Za,!1);y(this,vi,null);y(this,Fn,null);y(this,Ie,null);y(this,In,null);y(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,Wi,r),this.viewport=c,m(this,Ie,h),this.drawLayer=a,this._structTree=i,l(this,$).addLayer(this)}get isEmpty(){return l(this,Us).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,Ht,Af).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,Ie))==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,Wi))==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,Us).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(l(this,$).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!l(this,Wi)){m(this,Za,!1);return}const e=l(this,Wi).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,Us).values())if(n.disableEditing(),!!n.annotationElementId){if(n.serialize()!==null){t.set(n.annotationElementId,n);continue}else e.set(n.annotationElementId,n);(i=this.getEditableAnnotation(n.annotationElementId))==null||i.show(),n.remove()}if(l(this,Wi)){const n=l(this,Wi).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,Ht,Af).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,Wi))==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,Ie))!=null&&t.div&&!l(this,In)){m(this,In,new AbortController);const e=l(this,$).combinedSignal(l(this,In));l(this,Ie).div.addEventListener("pointerdown",w(this,Ht,h_).bind(this),{signal:e}),l(this,Ie).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=l(this,Ie))!=null&&t.div&&l(this,In)&&(l(this,In).abort(),m(this,In,null),l(this,Ie).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,Us).set(t.id,t);const{annotationElementId:e}=t;e&&l(this,$).isDeletedAnnotationElement(e)&&l(this,$).removeDeletedAnnotationElement(t)}detach(t){var e;l(this,Us).delete(t.id),(e=l(this,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),Vt.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),(e=t.parent)==null||e.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(!(t.parent===this&&t.isAttachedToDOM)){if(this.changeParent(t),l(this,$).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!l(this,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,Ht,Ui))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){l(this,$).updateToolbar(t),l(this,$).updateMode(t);const{offsetX:s,offsetY:i}=w(this,Ht,fm).call(this),n=this.getNextId(),r=w(this,Ht,dm).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,Ht,dm).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,Ht,fm).call(this),!0)}setSelected(t){l(this,$).setSelected(t)}toggleSelected(t){l(this,$).toggleSelected(t)}unselect(t){l(this,$).unselect(t)}pointerup(t){var s;const{isMac:e}=Ue.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&l(this,Er)&&(m(this,Er,!1),!((s=l(this,Ht,Ui))!=null&&s.isDrawer&&l(this,Ht,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}=Ue.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(m(this,Er,!0),(i=l(this,Ht,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,vi)){l(this,Ht,Ui).startDrawing(this,l(this,$),!1,t);return}l(this,$).setCurrentDrawingSession(this),m(this,vi,new AbortController);const e=l(this,$).combinedSignal(l(this,vi));this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(m(this,Fn,null),this.commitOrRemove())},{signal:e}),l(this,Ht,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,vi)?(l(this,$).setCurrentDrawingSession(null),l(this,vi).abort(),m(this,vi,null),m(this,Fn,null),l(this,Ht,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,vi)?(this.endDrawingSession(),!0):!1}onScaleChanging(){l(this,vi)&&l(this,Ht,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,Us).values())(e=l(this,Qa))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,l(this,Us).clear(),l(this,$).removeLayer(this)}render({viewport:t}){this.viewport=t,Wr(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,Ht,Af).call(this);const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,Wr(this.div,{rotation:s}),e!==s)for(const i of l(this,Us).values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return l(this,$).viewParameters.realScale}};Qa=new WeakMap,Mh=new WeakMap,Wi=new WeakMap,Tr=new WeakMap,Ln=new WeakMap,Us=new WeakMap,Er=new WeakMap,Oh=new WeakMap,Za=new WeakMap,vi=new WeakMap,Fn=new WeakMap,Ie=new WeakMap,In=new WeakMap,$=new WeakMap,kr=new WeakMap,Ht=new WeakSet,h_=function(t){l(this,$).unselectAll();const{target:e}=t;if(e===l(this,Ie).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&l(this,Ie).div.contains(e)){const{isMac:s}=Ue.platform;if(t.button!==0||t.ctrlKey&&s)return;l(this,$).showAllEditors("highlight",!0,!0),l(this,Ie).div.classList.add("free"),this.toggleDrawing(),Ad.startHighlighting(this,l(this,$).direction==="ltr",{target:l(this,Ie).div,x:t.x,y:t.y}),l(this,Ie).div.addEventListener("pointerup",()=>{l(this,Ie).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())},dm=function(t){const e=l(this,Ht,Ui);return e?new e.prototype.constructor(t):null},fm=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}},Af=function(){for(const t of l(this,Us).values())t.isEmpty()&&t.remove()},J(bi,"_initialized",!1),y(bi,kr,new Map([sp,op,hp,Ad].map(t=>[t._editorType,t])));let lp=bi;const je=class je{constructor({pageIndex:t}){y(this,Xi);y(this,yi,null);y(this,Gc,0);y(this,Qe,new Map);y(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,Qe).size>0)for(const e of l(this,Qe).values())e.remove(),t.append(e);m(this,yi,t)}}static get _svgFactory(){return lt(this,"_svgFactory",new Zg)}draw(t,e=!1,s=!1){const i=ts(this,Gc)._++,n=w(this,Xi,gm).call(this),r=je._svgFactory.createElement("defs");n.append(r);const a=je._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,Xi,c_).call(this,r,h):null,u=je._svgFactory.createElement("use");return n.append(u),u.setAttribute("href",`#${h}`),this.updateProperties(n,t),l(this,Qe).set(i,n),{id:i,clipPathId:`url(#${c})`}}drawOutline(t,e){const s=ts(this,Gc)._++,i=w(this,Xi,gm).call(this),n=je._svgFactory.createElement("defs");i.append(n);const r=je._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=je._svgFactory.createElement("mask");n.append(d),h=`mask_p${this.pageIndex}_${s}`,d.setAttribute("id",h),d.setAttribute("maskUnits","objectBoundingBox");const f=je._svgFactory.createElement("rect");d.append(f),f.setAttribute("width","1"),f.setAttribute("height","1"),f.setAttribute("fill","white");const g=je._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=je._svgFactory.createElement("use");i.append(c),c.setAttribute("href",`#${a}`),h&&c.setAttribute("mask",`url(#${h})`);const u=c.cloneNode();return i.append(u),c.classList.add("mainOutline"),u.classList.add("secondaryOutline"),this.updateProperties(i,t),l(this,Qe).set(s,i),s}finalizeDraw(t,e){l(this,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,Qe).get(t):t;if(a){if(s&&w(this,Xi,pm).call(this,a,s),i&&w(h=je,Xd,l_).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,Xi,pm).call(this,u,r)}}}updateParent(t,e){if(e===this)return;const s=l(this,Qe).get(t);s&&(l(e,yi).append(s),l(this,Qe).delete(t),l(e,Qe).set(t,s))}remove(t){l(this,to).delete(t),l(this,yi)!==null&&(l(this,Qe).get(t).remove(),l(this,Qe).delete(t))}destroy(){m(this,yi,null);for(const t of l(this,Qe).values())t.remove();l(this,Qe).clear(),l(this,to).clear()}};yi=new WeakMap,Gc=new WeakMap,Qe=new WeakMap,to=new WeakMap,Xd=new WeakSet,l_=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}%`},Xi=new WeakSet,gm=function(){const t=je._svgFactory.create(1,1,!0);return l(this,yi).append(t),t.setAttribute("aria-hidden",!0),t},c_=function(t,e){const s=je._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=je._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i},pm=function(t,e){for(const[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)},y(je,Xd);let cp=je;globalThis.pdfjsTestingUtils={HighlightOutliner:ip},Z.AbortException,Z.AnnotationEditorLayer,Z.AnnotationEditorParamsType,Z.AnnotationEditorType,Z.AnnotationEditorUIManager,Z.AnnotationLayer,Z.AnnotationMode,Z.ColorPicker,Z.DOMSVGFactory,Z.DrawLayer,Z.FeatureTest;var HC=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 zC=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 GC={"pdfjs-dist":"4.10.38"};function VC(o){return new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>t(s.result)),s.addEventListener("error",e),s.readAsDataURL(o)})}const WC=GC["pdfjs-dist"].replace("^","");HC.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${WC}/pdf.worker.min.mjs`;async function XC(o){const t="data:application/pdf;base64,",e=await VC(o);if(typeof e=="string")return window.atob(e.slice(t.length))}function UC(o,t){return zC({data:o,password:t}).promise}function YC(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 $C(i))}),i.addEventListener("error",n=>{window.URL.revokeObjectURL(s),e(n)})})}function $C(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 mb=null;function qC(){const o=document.createElement("div");o.style.width="1in",document.body.append(o);const t=o.offsetWidth;return o.remove(),t}function KC(){const o=mb??qC();return mb=o,o/72}function JC(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 Is=new Map;function QC(o){const t=new gg(o);return Is.set(o,t),t}function ZC(o,t){const e=Date.now();return{PDFId:`${o.name}-${e}`,name:o.name.replace(/.pdf/,""),updateDate:e,PDFBase64:t}}function tA(o,t){const e=o.getViewport({scale:t}),s=document.createElement("canvas"),i=s.getContext("2d"),n=KC()/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 eA({src:o},t,e){if(!o||!e)return null;const{objects:s,options:i}=await Mx(o),n=s.filter(a=>a!==null),r=Ww.groupSVGElements(n,i);return n.forEach(a=>{a.stroke=e}),r.hoverCursor="pointer",r.stroke=`${e}-${t}`,r}function sA(o,t){if(!Is.get(o))return;const s=1/3,i=lA(t,s);bb(o,i,s)}async function iA(o,t){const e=await YC(t),s=Date.now(),n={PDFId:`${t.name}${s}`,name:t.name.replace(/.png|.jpg|.jpeg/,""),updateDate:s,PDFBase64:e};return vb(o,{url:e}),{...n,pages:1}}async function vb(o,{url:t,scale:e=.5}){if(!Is.get(o))return;const i=await Pe.fromURL(t);i.scale(e),bb(o,i,e)}function bb(o,t,e){const s=Is.get(o);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function nA(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 rA(o,t,e){!e||!o||(e.scale(1/t),nA(o,e))}function aA(o,t){if(!o)return;const e=o._cornerSize||6;o.borderScaleFactor=1/t,o.cornerSize=e*(1/t),o.touchCornerSize=e*4*(1/t),o.setCoords()}function oA(o){const t=Is.get(o);t&&(t.discardActiveObject(),t.renderAll())}function hA(o){const t=Is.get(o);t&&(t.clear(),Is.delete(o))}function lA(o,t){return new Pe(o,{scaleX:t,scaleY:t})}function yb(o,t){if(!t)return;const{left:e,top:s,scaleX:i,scaleY:n,width:r,height:a}=o,h=t.x*r*i,c=t.y*a*n;o.set({left:e-h,top:s-c})}function _b(o,t,e){var n;const s=o.type,i={"application/pdf":cA,"image/png":xb,"image/jpeg":xb};return((n=i[s])==null?void 0:n.call(i,o,t,e))??Promise.reject(new Error(`Unsupported ${s} file type.`))}async function cA(o,t,e){const s=await XC(o);if(!s)return;const i=ZC(o,s);try{const n=await wb({page:1,PDFBase64:s,scale:.8,password:t},e);return{...i,pages:n}}catch(n){return Promise.reject(n)}}async function wb({page:o,PDFBase64:t,scale:e,password:s},i){try{const n=await UC(t,s),r=await n.getPage(o),{renderTask:a,canvas:h}=tA(r,e);return a.promise.then(()=>(i&&sA(i,h),n.numPages))}catch(n){return Promise.reject(n)}}async function xb(o,t,e){if(e)return await iA(e,o)}const uA="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",dA={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:6,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},fA={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:6,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},gA={borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},pA={stroke:"#000",hoverStroke:"#B7EC5D",src:uA};function Sb(o){const{id:t="",selectionOptions:e,pointerDown:s,pointerMove:i,pointerUp:n}=o||{},r=Q.useRef(null),a=Q.useRef(null),h=Q.useRef(1),c=Q.useRef({...pA});function u(){if(!t||Is.has(t))return;const P=QC(t);return P.on("selection:created",R=>{if(R.selected.length<=1)return;const F=P.getActiveObject();F&&(a.current=F,e!=null&&e.value&&a.current.set(e.value),a.current._cornerSize=a.current.cornerSize,S(h.current))}),P.on("selection:cleared",()=>k(P)),s&&P.on("mouse:down",s),i&&P.on("mouse:move",i),n&&P.on("mouse:up",n),P}function d(P,R){return _b(P,R,t)}function f(P){return wb(P,t)}function g({url:P,scale:R=.5}){return vb(t,{url:P,scale:R})}async function p(P,R,F){const I=Is.get(t);if(!I)return;const H=await Pe.fromURL(P,{},{...dA,...R});yb(H,F),I.add(H),_(I,H),I.setActiveObject(H)}function v(P,R,F){const I=Is.get(t);if(!I)return;const H=new ke(P,{...fA,...R});yb(H,F),I.add(H),_(I,H),I.setActiveObject(H)}function _(P,R){R.on("selected",F=>b({canvas:P,target:F.target})),R.on("modified",F=>b({canvas:P,target:F.target})),R.on("scaling",()=>k(P)),R.on("moving",()=>k(P)),R.on("rotating",()=>k(P)),R._cornerSize=R.cornerSize}async function b({canvas:P,target:R,stroke:F=c.current.stroke,uuid:I=Date.now()}){var B;if(P.getActiveObjects().length>1||((B=r.current)==null?void 0:B.stroke)===`${F}-${I}`)return;const W=await eA(c.current,I,F);k(P),r.current=W,a.current=R,x(P,R,I),S(h.current,!0),W&&P.add(W)}function x(P,R,F){r.current&&(r.current.on("selected",()=>{P.remove(R),k(P)}),r.current.on("mouseover",()=>{b({canvas:P,target:R,stroke:c.current.hoverStroke,uuid:F})}),r.current.on("mouseout",()=>{b({canvas:P,target:R,stroke:c.current.stroke,uuid:F})}))}function S(P,R=!1){const F=Is.get(t);h.current=P,F&&(aA(a.current,P),rA(a.current,P,r.current),!R&&F.renderAll())}function A(P){if(!P)return;c.current={...c.current,...P};const R=Is.get(t);!r||!a.current||!R||b({target:a.current,canvas:R})}function k(P){a.current=null,r.current&&(P.remove(r.current),r.current=null)}function M(){oA(t)}function D(){hA(t)}return{createCanvas:u,loadFile:d,specifyPage:f,renderImage:g,addFabric:p,addTextFabric:v,clearActive:M,deleteCanvas:D,scaleFabric:S,setCloseSvgOptions:A}}function mA(o){let t=0;const e=JC(()=>{t!==window.innerWidth&&(t=window.innerWidth,o())});Q.useEffect(()=>(window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)),[])}const vA=Q.forwardRef(bA);function bA({file:o,page:t=1,canvasId:e="PDF-canvas",fileZoom:s=1,fileScale:i=1,canvasScale:n=1,canvasClass:r="",isDrop:a=!1,password:h,dropTextOptions:c,dropImageOptions:u,closeSvgOptions:d,selectionOptions:f,manualReload:g,onLoaded:p,onReload:v,onPointerDown:_,onPointerMove:b,onPointerUp:x},S){const A=Q.useRef(null),k=`${e}-${t-1}`,M=Q.useMemo(()=>s*n,[s,n]),D=Q.useMemo(()=>({...gA,...f}),[f]),{createCanvas:P,specifyPage:R,addFabric:F,addTextFabric:I,renderImage:H,clearActive:W,deleteCanvas:B,scaleFabric:ht,setCloseSvgOptions:j}=Sb({id:k,selectionOptions:D,pointerDown:_,pointerMove:b,pointerUp:x});mA(z);async function z(){window.requestAnimationFrame(async()=>{if(P(),o.PDFBase64.startsWith("data:image")||o.canvas){const{canvas:it}=o,ut=it?7:3,Ft=it!=null&&it.length?it[t-1]:o.PDFBase64;H({url:Ft,scale:i/ut});return}await R({page:t,PDFBase64:o.PDFBase64,scale:i,password:h}),p==null||p()})}function at(it){if(it.preventDefault(),it.stopPropagation(),!a||!it.dataTransfer)return;const{dataTransfer:ut,nativeEvent:Ft}=it,{offsetX:us,offsetY:kt}=Ft,dt=ut.getData("text/plain"),Ne=ut.getData("text/uri-list"),Os=ut.getData("custom/offset"),qt=Os?JSON.parse(Os):null,Ud={top:kt,left:us},Vc={x:(qt==null?void 0:qt.offsetX)??0,y:(qt==null?void 0:qt.offsetY)??0};Ne?Mt(Ne,Ud,Vc):dt&&Lt(dt,Ud,Vc)}function Mt(it,ut,Ft){F(it,{...u,...ut},Ft)}function Lt(it,ut,Ft){I(it,{...c,...ut},Ft)}function $t(){g||z(),v==null||v()}return Q.useImperativeHandle(S,()=>({reload:z,addImage:Mt,addText:Lt,clearActive:W,deleteCanvas:B,canvasRef:A})),Q.useEffect(()=>{$t()},[i,t,o,h]),Q.useEffect(()=>{ht(M)},[M]),Q.useEffect(()=>{j(d)},[d]),Q.useEffect(()=>()=>B(),[]),bm.jsx("div",{style:{transform:`scale(${M})`},onDragOver:it=>it.preventDefault(),onDragEnter:it=>it.preventDefault(),onDrop:at,children:bm.jsx("canvas",{id:k,ref:A,className:r})})}ft.default=vA,ft.loadFile=_b,ft.useFabric=Sb,Object.defineProperties(ft,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|