@component-hook/pdf-canvas 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/react/pdf-canvas.es.js +7615 -7040
- package/dist/react/pdf-canvas.umd.js +76 -76
- package/dist/vue/pdf-canvas.es.d.ts +5 -43
- package/dist/vue/pdf-canvas.es.js +6245 -5670
- package/dist/vue/pdf-canvas.umd.js +66 -66
- package/package.json +3 -3
- package/dist/react/chunks/__vite-browser-external-DYxpcVy9.js +0 -4
- package/dist/vue/chunks/__vite-browser-external-DYxpcVy9.js +0 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(ct,
|
|
1
|
+
(function(ct,Q){typeof exports=="object"&&typeof module<"u"?Q(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],Q):(ct=typeof globalThis<"u"?globalThis:ct||self,Q(ct["pdf-canvas"]={},ct.React))})(this,function(ct,Q){"use strict";var nA=Object.defineProperty;var ob=ct=>{throw TypeError(ct)};var rA=(ct,Q,jt)=>Q in ct?nA(ct,Q,{enumerable:!0,configurable:!0,writable:!0,value:jt}):ct[Q]=jt;var q=(ct,Q,jt)=>rA(ct,typeof Q!="symbol"?Q+"":Q,jt),$f=(ct,Q,jt)=>Q.has(ct)||ob("Cannot "+jt);var l=(ct,Q,jt)=>($f(ct,Q,"read from private field"),jt?jt.call(ct):Q.get(ct)),w=(ct,Q,jt)=>Q.has(ct)?ob("Cannot add the same private member more than once"):Q instanceof WeakSet?Q.add(ct):Q.set(ct,jt),v=(ct,Q,jt,Fn)=>($f(ct,Q,"write to private field"),Fn?Fn.call(ct,jt):Q.set(ct,jt),jt),_=(ct,Q,jt)=>($f(ct,Q,"access private method"),jt);var Ke=(ct,Q,jt,Fn)=>({set _(Sr){v(ct,Q,Sr,jt)},get _(){return l(ct,Q,Fn)}});var on,Ad,qf,el,Un,Wr,ei,zr,sl,il,nd,ab,We,hb,lb,Td,cb,Kf,nl,Xr,Ur,Yn,ub,db,gb,rd,ca,rl,Me,ua,Ed,qt,$n,ol,Ht,od,fb,da,ds,ae,me,ga,hn,fa,Ps,qn,pa,Yr,Ci,si,$r,al,hl,ma,ll,Ai,Kn,va,Qn,Ti,hd,Jn,cl,Zn,qr,ul,dl,ue,wt,ln,Kr,gl,fl,tr,Ei,cn,pl,Os,B,kd,Qf,pb,mb,Md,vb,bb,yb,Jf,_b,Zf,tp,wb,Qe,Rn,xb,Sb,ep,Cb,xc,sp,de,ki,ii,ya,Mi,gs,_a,Pi,ss,un,Qr,Oi,er,ni,Sc,Pd,Jr,ri,Vt,wa,sr,ml,Zr,ve,to,ir,nr,vl,eo,rr,bl,so,dn,Di,xa,Sa,Ds,yl,ld,et,ip,_l,np,rp,Ab,Tb,op,ap,hp,lp,Eb,cp,kb,Mb,Pb,up,Cc,io,no,ge,cd,Ob,wl,Ca,xl,ro,Aa,gn,fn,Pe,oo,ao,z,Le,Ac,bh,Od,yh,Db,dp,_h,Tc,Ec,gp,kc,or,fp,pp,Sl,Cl,Ta,Rs,Rb,Lb,Fb,Dd,ho,Al,Tl,El,kl,Ea,ar,xt,ka,Ma,Ml,mp,Xv,hr,is,Pl,Ol,lo,pn,Dl,Rl,co,Pa,Oa,lr,Da,Ll,Ra,uo,Fl,Il,go,fo,jl,cr,La,mn,Ib,jb,vp,fs,Rd,bp,Nb,Bb,dd,ur,vn,Ls,wh,Ld,bn,fd,pd,po,mo,Fa,Fd,Ia,Id,yn,Ri,ja,Na,Li,vo,Mc,oi,Nl,yp,dr,gr,bo,_o,Ba,Ha,Bl,_p,ps,Go,Hb,Vb,Va,md,vd,Ga,wo,Xt,_n,Wa,Hl,Vl,za,wn,ai,xn,Gl,Sn,Wl,xo,So,Ct,jd,wp,Gb,Wb,zb,Xb,Nd,Bd,xp,zl,Xl,Ul,Yl,$l,ql,Kl,Sp,Ql,Co,Ao,Jl,To,Ub,Cp,hi,ms,Zl,Eo,vs,se,Yb,$b,qb,Hd,Cn,Vd,Gd,Kb,Ap,Qb,bs,li,Xa,Ua,Fi,ot,ko,Mo,tc,ec,Ya,$a,fr,sc,bd,yd,le,Pc,Jb,Zb,ty,ey,sy,iy,qa,Po,Tn,ic,ys,nc,Kt,_d,ny,rc,oc,pr,ci,Xe,ry,Wd,oy,ay,Tp,ac,Ka,ui,Oo,Qa,ce,hc,Ja,lc,cc,mr,di,Za,uc,At,Ep,kp,Mp,Wo,hy,xr,th,dc,En,Do,eh,rs,gc,fc,Ro,Fs,_s,be,sh,kn,Oe,ih,Is,pc,st,Pp,zd,ly,cy,uy,Op,zo,js,xh,dy,Xd,Oc,gy,fy,py,my,vy,Lo,ws,nh,pt,Dp,Rp,Lp,Dc,by,Ud,Rc,Sh,Ii,fe,pe,Fo,rh,os,ye,Bs,Io,jo,No,oh,Yd,Ue,mc,vc,xs,ji,Ni,ah,hh,lh,_e,Ln,yy,_y,wy,ch,Gt,we,vr,Mn,br,dh,Bi,Pn,Hi,Ss,gh,ht,Lc,Fc,$d,Fp,xy,qd,Ip,Kd,Sy,Cy,Bo,fh,Vi,yr,On,Hs,_r,ph,gi,De,Dn,Y,wr,Ft,Ay,zi,jp,Np,Qd,pi,yc,Ye,Ho,wd,Ty,Gi,Bp,Ey,Hp;var jt=typeof document<"u"?document.currentScript:null,Fn={exports:{}},Sr={};/**
|
|
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 Vp;function ky(){if(Vp)return Sr;Vp=1;var a=Q,t=Symbol.for("react.element"),e=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,i=a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,n={key:!0,ref:!0,__self:!0,__source:!0};function r(o,h,c){var u,d={},g=null,f=null;c!==void 0&&(g=""+c),h.key!==void 0&&(g=""+h.key),h.ref!==void 0&&(f=h.ref);for(u in h)s.call(h,u)&&!n.hasOwnProperty(u)&&(d[u]=h[u]);if(o&&o.defaultProps)for(u in h=o.defaultProps,h)d[u]===void 0&&(d[u]=h[u]);return{$$typeof:t,type:o,key:g,ref:f,props:d,_owner:i.current}}return Sr.Fragment=e,Sr.jsx=r,Sr.jsxs=r,Sr}var Ch={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,46 +14,46 @@
|
|
|
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
|
-
`+gt+
|
|
19
|
-
`),
|
|
20
|
-
`),
|
|
21
|
-
`+lt[
|
|
17
|
+
*/var Gp;function My(){return Gp||(Gp=1,process.env.NODE_ENV!=="production"&&function(){var a=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"),o=Symbol.for("react.context"),h=Symbol.for("react.forward_ref"),c=Symbol.for("react.suspense"),u=Symbol.for("react.suspense_list"),d=Symbol.for("react.memo"),g=Symbol.for("react.lazy"),f=Symbol.for("react.offscreen"),p=Symbol.iterator,m="@@iterator";function y(S){if(S===null||typeof S!="object")return null;var L=p&&S[p]||S[m];return typeof L=="function"?L:null}var b=a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function x(S){{for(var L=arguments.length,G=new Array(L>1?L-1:0),J=1;J<L;J++)G[J-1]=arguments[J];C("error",S,G)}}function C(S,L,G){{var J=b.ReactDebugCurrentFrame,yt=J.getStackAddendum();yt!==""&&(L+="%s",G=G.concat([yt]));var kt=G.map(function(ft){return String(ft)});kt.unshift("Warning: "+L),Function.prototype.apply.call(console[S],console,kt)}}var A=!1,M=!1,D=!1,k=!1,P=!1,R;R=Symbol.for("react.module.reference");function F(S){return!!(typeof S=="string"||typeof S=="function"||S===s||S===n||P||S===i||S===c||S===u||k||S===f||A||M||D||typeof S=="object"&&S!==null&&(S.$$typeof===g||S.$$typeof===d||S.$$typeof===r||S.$$typeof===o||S.$$typeof===h||S.$$typeof===R||S.getModuleId!==void 0))}function I(S,L,G){var J=S.displayName;if(J)return J;var yt=L.displayName||L.name||"";return yt!==""?G+"("+yt+")":G}function X(S){return S.displayName||"Context"}function j(S){if(S==null)return null;if(typeof S.tag=="number"&&x("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof S=="function")return S.displayName||S.name||null;if(typeof S=="string")return S;switch(S){case s:return"Fragment";case e:return"Portal";case n:return"Profiler";case i:return"StrictMode";case c:return"Suspense";case u:return"SuspenseList"}if(typeof S=="object")switch(S.$$typeof){case o:var L=S;return X(L)+".Consumer";case r:var G=S;return X(G._context)+".Provider";case h:return I(S,S.render,"ForwardRef");case d:var J=S.displayName||null;return J!==null?J:j(S.type)||"Memo";case g:{var yt=S,kt=yt._payload,ft=yt._init;try{return j(ft(kt))}catch{return null}}}return null}var N=Object.assign,it=0,K,V,H,Et,It,ie,Wt;function Tt(){}Tt.__reactDisabledLog=!0;function xe(){{if(it===0){K=console.log,V=console.info,H=console.warn,Et=console.error,It=console.group,ie=console.groupCollapsed,Wt=console.groupEnd;var S={configurable:!0,enumerable:!0,value:Tt,writable:!0};Object.defineProperties(console,{info:S,log:S,warn:S,error:S,group:S,groupCollapsed:S,groupEnd:S})}it++}}function Vs(){{if(it--,it===0){var S={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:N({},S,{value:K}),info:N({},S,{value:V}),warn:N({},S,{value:H}),error:N({},S,{value:Et}),group:N({},S,{value:It}),groupCollapsed:N({},S,{value:ie}),groupEnd:N({},S,{value:Wt})})}it<0&&x("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Pt=b.ReactCurrentDispatcher,gt;function Cs(S,L,G){{if(gt===void 0)try{throw Error()}catch(yt){var J=yt.stack.trim().match(/\n( *(at )?)/);gt=J&&J[1]||""}return`
|
|
18
|
+
`+gt+S}}var Wi=!1,$e;{var RC=typeof WeakMap=="function"?WeakMap:Map;$e=new RC}function Uv(S,L){if(!S||Wi)return"";{var G=$e.get(S);if(G!==void 0)return G}var J;Wi=!0;var yt=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var kt;kt=Pt.current,Pt.current=null,xe();try{if(L){var ft=function(){throw Error()};if(Object.defineProperty(ft.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(ft,[])}catch(as){J=as}Reflect.construct(S,[],ft)}else{try{ft.call()}catch(as){J=as}S.call(ft.prototype)}}else{try{throw Error()}catch(as){J=as}S()}}catch(as){if(as&&J&&typeof as.stack=="string"){for(var lt=as.stack.split(`
|
|
19
|
+
`),qe=J.stack.split(`
|
|
20
|
+
`),Qt=lt.length-1,ne=qe.length-1;Qt>=1&&ne>=0&<[Qt]!==qe[ne];)ne--;for(;Qt>=1&&ne>=0;Qt--,ne--)if(lt[Qt]!==qe[ne]){if(Qt!==1||ne!==1)do if(Qt--,ne--,ne<0||lt[Qt]!==qe[ne]){var Gs=`
|
|
21
|
+
`+lt[Qt].replace(" at new "," at ");return S.displayName&&Gs.includes("<anonymous>")&&(Gs=Gs.replace("<anonymous>",S.displayName)),typeof S=="function"&&$e.set(S,Gs),Gs}while(Qt>=1&&ne>=0);break}}}finally{Wi=!1,Pt.current=kt,Vs(),Error.prepareStackTrace=yt}var vh=S?S.displayName||S.name:"",Vo=vh?Cs(vh):"";return typeof S=="function"&&$e.set(S,Vo),Vo}function LC(S,L,G){return Uv(S,!1)}function FC(S){var L=S.prototype;return!!(L&&L.isReactComponent)}function xd(S,L,G){if(S==null)return"";if(typeof S=="function")return Uv(S,FC(S));if(typeof S=="string")return Cs(S);switch(S){case c:return Cs("Suspense");case u:return Cs("SuspenseList")}if(typeof S=="object")switch(S.$$typeof){case h:return LC(S.render);case d:return xd(S.type,L,G);case g:{var J=S,yt=J._payload,kt=J._init;try{return xd(kt(yt),L,G)}catch{}}}return""}var _c=Object.prototype.hasOwnProperty,Yv={},$v=b.ReactDebugCurrentFrame;function Sd(S){if(S){var L=S._owner,G=xd(S.type,S._source,L?L.type:null);$v.setExtraStackFrame(G)}else $v.setExtraStackFrame(null)}function IC(S,L,G,J,yt){{var kt=Function.call.bind(_c);for(var ft in S)if(kt(S,ft)){var lt=void 0;try{if(typeof S[ft]!="function"){var qe=Error((J||"React class")+": "+G+" type `"+ft+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof S[ft]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw qe.name="Invariant Violation",qe}lt=S[ft](L,ft,J,G,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(Qt){lt=Qt}lt&&!(lt instanceof Error)&&(Sd(yt),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).",J||"React class",G,ft,typeof lt),Sd(null)),lt instanceof Error&&!(lt.message in Yv)&&(Yv[lt.message]=!0,Sd(yt),x("Failed %s type: %s",G,lt.message),Sd(null))}}}var jC=Array.isArray;function Gf(S){return jC(S)}function NC(S){{var L=typeof Symbol=="function"&&Symbol.toStringTag,G=L&&S[Symbol.toStringTag]||S.constructor.name||"Object";return G}}function BC(S){try{return qv(S),!1}catch{return!0}}function qv(S){return""+S}function Kv(S){if(BC(S))return x("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",NC(S)),qv(S)}var wc=b.ReactCurrentOwner,HC={key:!0,ref:!0,__self:!0,__source:!0},Qv,Jv,Wf;Wf={};function VC(S){if(_c.call(S,"ref")){var L=Object.getOwnPropertyDescriptor(S,"ref").get;if(L&&L.isReactWarning)return!1}return S.ref!==void 0}function GC(S){if(_c.call(S,"key")){var L=Object.getOwnPropertyDescriptor(S,"key").get;if(L&&L.isReactWarning)return!1}return S.key!==void 0}function WC(S,L){if(typeof S.ref=="string"&&wc.current&&L&&wc.current.stateNode!==L){var G=j(wc.current.type);Wf[G]||(x('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',j(wc.current.type),S.ref),Wf[G]=!0)}}function zC(S,L){{var G=function(){Qv||(Qv=!0,x("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",L))};G.isReactWarning=!0,Object.defineProperty(S,"key",{get:G,configurable:!0})}}function XC(S,L){{var G=function(){Jv||(Jv=!0,x("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",L))};G.isReactWarning=!0,Object.defineProperty(S,"ref",{get:G,configurable:!0})}}var UC=function(S,L,G,J,yt,kt,ft){var lt={$$typeof:t,type:S,key:L,ref:G,props:ft,_owner:kt};return lt._store={},Object.defineProperty(lt._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(lt,"_self",{configurable:!1,enumerable:!1,writable:!1,value:J}),Object.defineProperty(lt,"_source",{configurable:!1,enumerable:!1,writable:!1,value:yt}),Object.freeze&&(Object.freeze(lt.props),Object.freeze(lt)),lt};function YC(S,L,G,J,yt){{var kt,ft={},lt=null,qe=null;G!==void 0&&(Kv(G),lt=""+G),GC(L)&&(Kv(L.key),lt=""+L.key),VC(L)&&(qe=L.ref,WC(L,yt));for(kt in L)_c.call(L,kt)&&!HC.hasOwnProperty(kt)&&(ft[kt]=L[kt]);if(S&&S.defaultProps){var Qt=S.defaultProps;for(kt in Qt)ft[kt]===void 0&&(ft[kt]=Qt[kt])}if(lt||qe){var ne=typeof S=="function"?S.displayName||S.name||"Unknown":S;lt&&zC(ft,ne),qe&&XC(ft,ne)}return UC(S,lt,qe,yt,J,wc.current,ft)}}var zf=b.ReactCurrentOwner,Zv=b.ReactDebugCurrentFrame;function mh(S){if(S){var L=S._owner,G=xd(S.type,S._source,L?L.type:null);Zv.setExtraStackFrame(G)}else Zv.setExtraStackFrame(null)}var Xf;Xf=!1;function Uf(S){return typeof S=="object"&&S!==null&&S.$$typeof===t}function tb(){{if(zf.current){var S=j(zf.current.type);if(S)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+
|
|
23
|
+
Check the render method of \``+S+"`."}return""}}function $C(S){return""}var eb={};function qC(S){{var L=tb();if(!L){var G=typeof S=="string"?S:S.displayName||S.name;G&&(L=`
|
|
24
24
|
|
|
25
|
-
Check the top-level render call using <`+
|
|
25
|
+
Check the top-level render call using <`+G+">.")}return L}}function sb(S,L){{if(!S._store||S._store.validated||S.key!=null)return;S._store.validated=!0;var G=qC(L);if(eb[G])return;eb[G]=!0;var J="";S&&S._owner&&S._owner!==zf.current&&(J=" It was passed a child from "+j(S._owner.type)+"."),mh(S),x('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',G,J),mh(null)}}function ib(S,L){{if(typeof S!="object")return;if(Gf(S))for(var G=0;G<S.length;G++){var J=S[G];Uf(J)&&sb(J,L)}else if(Uf(S))S._store&&(S._store.validated=!0);else if(S){var yt=y(S);if(typeof yt=="function"&&yt!==S.entries)for(var kt=yt.call(S),ft;!(ft=kt.next()).done;)Uf(ft.value)&&sb(ft.value,L)}}}function KC(S){{var L=S.type;if(L==null||typeof L=="string")return;var G;if(typeof L=="function")G=L.propTypes;else if(typeof L=="object"&&(L.$$typeof===h||L.$$typeof===d))G=L.propTypes;else return;if(G){var J=j(L);IC(G,S.props,"prop",J,S)}else if(L.PropTypes!==void 0&&!Xf){Xf=!0;var yt=j(L);x("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",yt||"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 QC(S){{for(var L=Object.keys(S.props),G=0;G<L.length;G++){var J=L[G];if(J!=="children"&&J!=="key"){mh(S),x("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",J),mh(null);break}}S.ref!==null&&(mh(S),x("Invalid attribute `ref` supplied to `React.Fragment`."),mh(null))}}var nb={};function rb(S,L,G,J,yt,kt){{var ft=F(S);if(!ft){var lt="";(S===void 0||typeof S=="object"&&S!==null&&Object.keys(S).length===0)&&(lt+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var qe=$C();qe?lt+=qe:lt+=tb();var Qt;S===null?Qt="null":Gf(S)?Qt="array":S!==void 0&&S.$$typeof===t?(Qt="<"+(j(S.type)||"Unknown")+" />",lt=" Did you accidentally export a JSX literal instead of a component?"):Qt=typeof S,x("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",Qt,lt)}var ne=YC(S,L,G,yt,kt);if(ne==null)return ne;if(ft){var Gs=L.children;if(Gs!==void 0)if(J)if(Gf(Gs)){for(var vh=0;vh<Gs.length;vh++)ib(Gs[vh],S);Object.freeze&&Object.freeze(Gs)}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(Gs,S)}if(_c.call(L,"key")){var Vo=j(S),as=Object.keys(L).filter(function(iA){return iA!=="key"}),Yf=as.length>0?"{key: someKey, "+as.join(": ..., ")+": ...}":"{key: someKey}";if(!nb[Vo+Yf]){var sA=as.length>0?"{"+as.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(),Pi("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const Oy={};let Fp;const oi=()=>Fp||(Fp={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new My,dispose(){},copyPasteData:Oy}),ja=()=>oi().document,_c=()=>oi().window,Lp=()=>{var o;return Math.max((o=dt.devicePixelRatio)!==null&&o!==void 0?o:_c().devicePixelRatio,1)},dh=new class{constructor(){T(this,"charWidthsCache",{}),T(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}=dt,e=Math.sqrt(t*o);return[Math.floor(e),Math.floor(t/e)]}},jd="6.5.0";function gr(){}const An=Math.PI/2,Di=2*Math.PI,Nd=Math.PI/180,De=Object.freeze([1,0,0,1,0,0]),Bd=16,Tn=.4477152502,st="center",mt="left",Ue="top",Hd="bottom",Vt="right",Re="none",Wd=/\r?\n/,Ip="moving",wc="scaling",jp="rotating",Xd="rotate",Np="skewing",gh="resizing",Py="modifyPoly",Dy="modifyPath",xc="changed",Sc="scale",Fe="scaleX",is="scaleY",Na="skewX",Ba="skewY",$t="fill",Le="stroke",Cc="modified",Ha="json",zd="svg",V=new class{constructor(){this[Ha]=new Map,this[zd]=new Map}has(o){return this[Ha].has(o)}getClass(o){const t=this[Ha].get(o);if(!t)throw new ai("No class registered for ".concat(o));return t}setClass(o,t){t?this[Ha].set(t,o):(this[Ha].set(o.type,o),this[Ha].set(o.type.toLowerCase(),o))}getSVGClass(o){return this[zd].get(o)}setSVGClass(o,t){this[zd].set(t??o.type.toLowerCase(),o)}},Ac=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 Ry{constructor(){T(this,"__eventListeners",{})}on(t,e){if(this.__eventListeners||(this.__eventListeners={}),typeof t=="object")return Object.entries(t).forEach(s=>{let[i,n]=s;this.on(i,n)}),()=>this.off(t);if(e){const s=t;return this.__eventListeners[s]||(this.__eventListeners[s]=[]),this.__eventListeners[s].push(e),()=>this.off(s,e)}return()=>!1}once(t,e){if(typeof t=="object"){const s=[];return Object.entries(t).forEach(i=>{let[n,r]=i;s.push(this.once(n,r))}),()=>s.forEach(i=>i())}if(e){const s=this.on(t,function(){for(var i=arguments.length,n=new Array(i),r=0;r<i;r++)n[r]=arguments[r];e.call(this,...n),s()});return s}return()=>!1}_removeEventListener(t,e){if(this.__eventListeners[t])if(e){const s=this.__eventListeners[t],i=s.indexOf(e);i>-1&&s.splice(i,1)}else this.__eventListeners[t]=[]}off(t,e){if(this.__eventListeners)if(t===void 0)for(const s in this.__eventListeners)this._removeEventListener(s);else typeof t=="object"?Object.entries(t).forEach(s=>{let[i,n]=s;this._removeEventListener(i,n)}):this._removeEventListener(t,e)}fire(t,e){var s;if(!this.__eventListeners)return;const i=(s=this.__eventListeners[t])===null||s===void 0?void 0:s.concat();if(i)for(let n=0;n<i.length;n++)i[n].call(this,e||{})}}const fr=(o,t)=>{const e=o.indexOf(t);return e!==-1&&o.splice(e,1),o},Fs=o=>{if(o===0)return 1;switch(Math.abs(o)/An){case 1:case 3:return 0;case 2:return-1}return Math.cos(o)},Ls=o=>{if(o===0)return 0;const t=o/An,e=Math.sign(o);switch(t){case 1:return e;case 2:return 0;case 3:return-e}return Math.sin(o)};class D{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;typeof t=="object"?(this.x=t.x,this.y=t.y):(this.x=t,this.y=e)}add(t){return new D(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new D(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new D(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new D(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new D(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new D(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new D(this.x/t.x,this.y/t.y)}scalarDivide(t){return new D(this.x/t,this.y/t)}scalarDivideEquals(t){return this.x/=t,this.y/=t,this}eq(t){return this.x===t.x&&this.y===t.y}lt(t){return this.x<t.x&&this.y<t.y}lte(t){return this.x<=t.x&&this.y<=t.y}gt(t){return this.x>t.x&&this.y>t.y}gte(t){return this.x>=t.x&&this.y>=t.y}lerp(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:.5;return e=Math.max(Math.min(1,e),0),new D(this.x+(t.x-this.x)*e,this.y+(t.y-this.y)*e)}distanceFrom(t){const e=this.x-t.x,s=this.y-t.y;return Math.sqrt(e*e+s*s)}midPointFrom(t){return this.lerp(t)}min(t){return new D(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new D(Math.max(this.x,t.x),Math.max(this.y,t.y))}toString(){return"".concat(this.x,",").concat(this.y)}setXY(t,e){return this.x=t,this.y=e,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setFromPoint(t){return this.x=t.x,this.y=t.y,this}swap(t){const e=this.x,s=this.y;this.x=t.x,this.y=t.y,t.x=e,t.y=s}clone(){return new D(this.x,this.y)}rotate(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Vd;const s=Ls(t),i=Fs(t),n=this.subtract(e);return new D(n.x*i-n.y*s,n.x*s+n.y*i).add(e)}transform(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return new D(t[0]*this.x+t[2]*this.y+(e?0:t[4]),t[1]*this.x+t[3]*this.y+(e?0:t[5]))}}const Vd=new D(0,0),Tc=o=>!!o&&Array.isArray(o._objects);function Bp(o){class t extends o{constructor(){super(...arguments),T(this,"_objects",[])}_onObjectAdded(s){}_onObjectRemoved(s){}_onStackOrderChanged(s){}add(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];const r=this._objects.push(...i);return i.forEach(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 l=s.indexOf(h);l!==-1&&(s.splice(l,1),i.push(h),this._onObjectRemoved(h))}),i}forEachObject(s){this.getObjects().forEach((i,n,r)=>s(i,n,r))}getObjects(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];return i.length===0?[...this._objects]:this._objects.filter(r=>r.isType(...i))}item(s){return this._objects[s]}isEmpty(){return this._objects.length===0}size(){return this._objects.length}contains(s,i){return!!this._objects.includes(s)||!!i&&this._objects.some(n=>n instanceof t&&n.contains(s,!0))}complexity(){return this._objects.reduce((s,i)=>s+=i.complexity?i.complexity():0,0)}sendObjectToBack(s){return!(!s||s===this._objects[0])&&(fr(this._objects,s),this._objects.unshift(s),this._onStackOrderChanged(s),!0)}bringObjectToFront(s){return!(!s||s===this._objects[this._objects.length-1])&&(fr(this._objects,s),this._objects.push(s),this._onStackOrderChanged(s),!0)}sendObjectBackwards(s,i){if(!s)return!1;const n=this._objects.indexOf(s);if(n!==0){const r=this.findNewLowerIndex(s,n,i);return fr(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}bringObjectForward(s,i){if(!s)return!1;const n=this._objects.indexOf(s);if(n!==this._objects.length-1){const r=this.findNewUpperIndex(s,n,i);return fr(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}moveObjectTo(s,i){return s!==this._objects[i]&&(fr(this._objects,s),this._objects.splice(i,0,s),this._onStackOrderChanged(s),!0)}findNewLowerIndex(s,i,n){let r;if(n){r=i;for(let a=i-1;a>=0;--a)if(s.isOverlapping(this._objects[a])){r=a;break}}else r=i-1;return r}findNewUpperIndex(s,i,n){let r;if(n){r=i;for(let a=i+1;a<this._objects.length;++a)if(s.isOverlapping(this._objects[a])){r=a;break}}else r=i+1;return r}collectObjects(s){let{left:i,top:n,width:r,height:a}=s,{includeIntersecting:h=!0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const l=[],u=new D(i,n),d=u.add(new D(r,a));for(let g=this._objects.length-1;g>=0;g--){const f=this._objects[g];f.selectable&&f.visible&&(h&&f.intersectsWithRect(u,d)||f.isContainedWithinRect(u,d)||h&&f.containsPoint(u)||h&&f.containsPoint(d))&&l.push(f)}return l}}return t}class Hp extends Ry{_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 fh(o){return _c().requestAnimationFrame(o)}function Wp(o){return _c().cancelAnimationFrame(o)}let Fy=0;const En=()=>Fy++,vs=()=>{const o=ja().createElement("canvas");if(!o||o.getContext===void 0)throw new ai("Failed to create `canvas` element");return o},Xp=()=>ja().createElement("img"),Is=o=>{const t=vs();return t.width=o.width,t.height=o.height,t},Gd=(o,t,e)=>o.toDataURL("image/".concat(t),e),Wt=o=>o*Nd,kn=o=>o/Nd,zp=o=>o.every((t,e)=>t===De[e]),we=(o,t,e)=>new D(o).transform(t,e),qe=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 D(o[4],o[5]).transform(e,!0);return e[4]=-s,e[5]=-i,e},Gt=(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]],Ec=(o,t)=>o.reduceRight((e,s)=>s&&e?Gt(s,e,t):s||e,void 0)||De.concat(),Vp=o=>{let[t,e]=o;return Math.atan2(e,t)},pr=o=>{const t=Vp(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:kn(t),scaleX:s,scaleY:i,skewX:kn(n),skewY:0,translateX:o[4]||0,translateY:o[5]||0}},Wa=function(o){return[1,0,0,1,o,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function Xa(){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=Wt(o),i=Fs(s),n=Ls(s);return[i,n,-n,i,t?t-(i*t-n*e):0,e?e-(n*t+i*e):0]}const kc=function(o){return[o,0,0,arguments.length>1&&arguments[1]!==void 0?arguments[1]:o,0,0]},Gp=o=>Math.tan(Wt(o)),Yd=o=>[1,0,Gp(o),1,0,0],Ud=o=>[1,Gp(o),0,1,0,0],ph=o=>{let{scaleX:t=1,scaleY:e=1,flipX:s=!1,flipY:i=!1,skewX:n=0,skewY:r=0}=o,a=kc(s?-t:t,i?-e:e);return n&&(a=Gt(a,Yd(n),!0)),r&&(a=Gt(a,Ud(r),!0)),a},Yp=o=>{const{translateX:t=0,translateY:e=0,angle:s=0}=o;let i=Wa(t,e);s&&(i=Gt(i,Xa({angle:s})));const n=ph(o);return zp(n)||(i=Gt(i,n)),i},mh=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 Id("loadImage"));const n=Xp();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 ai("Error loading ".concat(n.src)))},e&&(n.crossOrigin=e),n.src=o):a()})},za=function(o){let{signal:t,reviver:e=gr}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise((s,i)=>{const n=[];t&&t.addEventListener("abort",i,{once:!0}),Promise.all(o.map(r=>V.getClass(r.type).fromObject(r,{signal:t}).then(a=>(e(r,a),n.push(a),a)))).then(s).catch(r=>{n.forEach(a=>{a.dispose&&a.dispose()}),i(r)}).finally(()=>{t&&t.removeEventListener("abort",i)})})},vh=function(o){let{signal:t}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise((e,s)=>{const i=[];t&&t.addEventListener("abort",s,{once:!0});const n=Object.values(o).map(a=>a&&a.type&&V.has(a.type)?za([a],{signal:t}).then(h=>{let[l]=h;return i.push(l),l}):a),r=Object.keys(o);Promise.all(n).then(a=>a.reduce((h,l,u)=>(h[r[u]]=l,h),{})).then(e).catch(a=>{i.forEach(h=>{h.dispose&&h.dispose()}),s(a)}).finally(()=>{t&&t.removeEventListener("abort",s)})})},mr=function(o){return(arguments.length>1&&arguments[1]!==void 0?arguments[1]:[]).reduce((t,e)=>(e in o&&(t[e]=o[e]),t),{})},qd=(o,t)=>Object.keys(o).reduce((e,s)=>(t(o[s],s,o)&&(e[s]=o[s]),e),{}),Up={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"},$d=(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),qp=(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 l=i-n;switch(a=h>.5?l/(2-i-n):l/(i+n),i){case o:r=(t-e)/l+(t<e?6:0);break;case t:r=(e-o)/l+2;break;case e:r=(o-t)/l+4}r/=6}return[Math.round(360*r),Math.round(100*a),Math.round(100*h),s]},$p=function(){let o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"1";return parseFloat(o)/(o.endsWith("%")?100:1)},Mc=o=>Math.min(Math.round(o),255).toString(16).toUpperCase().padStart(2,"0"),Kp=o=>{let[t,e,s,i=1]=o;const n=Math.round(.3*t+.59*e+.11*s);return[n,n,n,i]};class yt{constructor(t){if(T(this,"isUnrecognised",!1),t)if(t instanceof yt)this.setSource([...t._source]);else if(Array.isArray(t)){const[e,s,i,n=1]=t;this.setSource([e,s,i,n])}else this.setSource(this._tryParsingColor(t));else this.setSource([0,0,0,1])}_tryParsingColor(t){return t in Up&&(t=Up[t]),t==="transparent"?[255,255,255,0]:yt.sourceFromHex(t)||yt.sourceFromRgb(t)||yt.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]=qp(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(s,"%)")}toHsla(){const[t,e,s,i]=qp(...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(Mc(t)).concat(Mc(e)).concat(Mc(s)).concat(Mc(Math.round(255*i)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(Kp(this.getSource())),this}toBlackWhite(t){const[e,,,s]=Kp(this.getSource()),i=e<(t||127)?0:255;return this.setSource([i,i,i,s]),this}overlayWith(t){t instanceof yt||(t=new yt(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 yt.fromRgba(t)}static fromRgba(t){return new yt(yt.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,$p(e[4])]}}static fromHsl(t){return yt.fromHsla(t)}static fromHsla(t){return new yt(yt.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=(yt.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 l=n<=.5?n*(i+1):n+i-n*i,u=2*n-l;r=$d(u,l,s+1/3),a=$d(u,l,s),h=$d(u,l,s-1/3)}return[Math.round(255*r),Math.round(255*a),Math.round(255*h),$p(e[4])]}static fromHex(t){return new yt(yt.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")?kn(s):e.includes("turn")?360*s:s}}const Dt=(o,t)=>parseFloat(Number(o).toFixed(t)),Ie=function(o){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Bd;const e=/\D{0,2}$/.exec(o),s=parseFloat(o),i=dt.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}},Kd=o=>{const[t,e]=o.trim().split(" "),[s,i]=(n=t)&&n!==Re?[n.slice(1,4),n.slice(5,8)]:n===Re?[n,n]:["Mid","Mid"];var n;return{meetOrSlice:e||"meet",alignX:s,alignY:i}},bh=o=>"matrix("+o.map(t=>Dt(t,dt.NUM_FRACTION_DIGITS)).join(" ")+")",yh=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 yt(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,'" '):"")},bs=o=>!!o&&o.toLive!==void 0,Jp=o=>!!o&&typeof o.toObject=="function",Qp=o=>!!o&&o.offsetX!==void 0&&"source"in o,Zp=o=>!!o&&typeof o._renderText=="function",vr=o=>!!o&&"multiSelectionStacking"in o;function tm(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,em=o=>{var t;return((t=o.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null},sm=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))},Jd=(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 im(o){return o.onselectstart!==void 0&&(o.onselectstart=()=>!1),o.style.userSelect=Re,o}class nm{constructor(t){T(this,"_originalCanvasStyle",void 0),T(this,"lower",void 0);const e=this.createLowerCanvas(t);this.lower={el:e,ctx:e.getContext("2d")}}createLowerCanvas(t){const e=(s=t)&&s.getContext!==void 0?t:t&&ja().getElementById(t)||vs();var s;if(e.hasAttribute("data-fabric"))throw new ai("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;sm(s,i,t,e)}setCSSDimensions(t){Jd(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=em(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=tm(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(){oi().dispose(this.lower.el),delete this.lower}}const Ly={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...De]};class _h extends Bp(Hp){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 _h.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 nm(t)}add(){const t=super.add(...arguments);return arguments.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}insertAt(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),i=1;i<e;i++)s[i-1]=arguments[i];const n=super.insertAt(t,...s);return s.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),n}remove(){const t=super.remove(...arguments);return t.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}_onObjectAdded(t){t.canvas&&t.canvas!==this&&(Pi("warn",`Canvas is trying to add an object that belongs to a different canvas.
|
|
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} />`,Yf,Vo,sA,Vo),nb[Vo+Yf]=!0}}return S===s?QC(ne):KC(ne),ne}}function JC(S,L,G){return rb(S,L,G,!0)}function ZC(S,L,G){return rb(S,L,G,!1)}var tA=ZC,eA=JC;Ch.Fragment=s,Ch.jsx=tA,Ch.jsxs=eA}()),Ch}process.env.NODE_ENV==="production"?Fn.exports=ky():Fn.exports=My();var Wp=Fn.exports;function T(a,t,e){return(t=function(s){var i=function(n,r){if(typeof n!="object"||!n)return n;var o=n[Symbol.toPrimitive];if(o!==void 0){var h=o.call(n,r||"default");if(typeof h!="object")return h;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(n)}(s,"string");return typeof i=="symbol"?i:i+""}(t))in a?Object.defineProperty(a,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):a[t]=e,a}function zp(a,t){var e=Object.keys(a);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(a);t&&(s=s.filter(function(i){return Object.getOwnPropertyDescriptor(a,i).enumerable})),e.push.apply(e,s)}return e}function E(a){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?zp(Object(e),!0).forEach(function(s){T(a,s,e[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(e)):zp(Object(e)).forEach(function(s){Object.defineProperty(a,s,Object.getOwnPropertyDescriptor(e,s))})}return a}function Ot(a,t){if(a==null)return{};var e,s,i=function(r,o){if(r==null)return{};var h={};for(var c in r)if({}.hasOwnProperty.call(r,c)){if(o.indexOf(c)>=0)continue;h[c]=r[c]}return h}(a,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(a);for(s=0;s<n.length;s++)e=n[s],t.indexOf(e)>=0||{}.propertyIsEnumerable.call(a,e)&&(i[e]=a[e])}return i}function In(a,t){return t||(t=a.slice(0)),Object.freeze(Object.defineProperties(a,{raw:{value:Object.freeze(t)}}))}class Xp{constructor(){T(this,"browserShadowBlurConstant",1),T(this,"DPI",96),T(this,"devicePixelRatio",typeof window<"u"?window.devicePixelRatio:1),T(this,"perfLimitSizeTotal",2097152),T(this,"maxCacheSideLimit",4096),T(this,"minCacheSideLimit",256),T(this,"disableStyleCopyPaste",!1),T(this,"enableGLFiltering",!0),T(this,"textureSize",4096),T(this,"forceGLPutImageData",!1),T(this,"cachesBoundsOfCurve",!1),T(this,"fontPaths",{}),T(this,"NUM_FRACTION_DIGITS",4)}}const dt=new class extends Xp{constructor(a){super(),this.configure(a)}configure(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Object.assign(this,a)}addFonts(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.fontPaths=E(E({},this.fontPaths),a)}removeFonts(){(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).forEach(a=>{delete this.fontPaths[a]})}clearFonts(){this.fontPaths={}}restoreDefaults(a){const t=new Xp,e=(a==null?void 0:a.reduce((s,i)=>(s[i]=t[i],s),{}))||t;this.configure(e)}},Xi=function(a){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return console[a]("fabric",...e)};class mi extends Error{constructor(t,e){super("fabric: ".concat(t),e)}}class Jd extends mi{constructor(t){super("".concat(t," 'options.signal' is in 'aborted' state"))}}class Py{}class Oy extends Py{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(),Xi("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const Dy={};let Up;const vi=()=>Up||(Up={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new Oy,dispose(){},copyPasteData:Dy}),Xo=()=>vi().document,Ic=()=>vi().window,Yp=()=>{var a;return Math.max((a=dt.devicePixelRatio)!==null&&a!==void 0?a:Ic().devicePixelRatio,1)},Ah=new class{constructor(){T(this,"charWidthsCache",{}),T(this,"boundsOfCurveCache",{})}getFontCache(a){let{fontFamily:t,fontStyle:e,fontWeight:s}=a;t=t.toLowerCase(),this.charWidthsCache[t]||(this.charWidthsCache[t]={});const i=this.charWidthsCache[t],n="".concat(e.toLowerCase(),"_").concat((s+"").toLowerCase());return i[n]||(i[n]={}),i[n]}clearFontCache(a){(a=(a||"").toLowerCase())?this.charWidthsCache[a]&&delete this.charWidthsCache[a]:this.charWidthsCache={}}limitDimsByArea(a){const{perfLimitSizeTotal:t}=dt,e=Math.sqrt(t*a);return[Math.floor(e),Math.floor(t/e)]}},Zd="6.5.1";function Cr(){}const jn=Math.PI/2,Ui=2*Math.PI,tg=Math.PI/180,Fe=Object.freeze([1,0,0,1,0,0]),eg=16,Nn=.4477152502,tt="center",vt="left",Je="top",sg="bottom",Ut="right",Ie="none",ig=/\r?\n/,$p="moving",jc="scaling",qp="rotating",ng="rotate",Kp="skewing",Th="resizing",Ry="modifyPoly",Ly="modifyPath",Nc="changed",Bc="scale",je="scaleX",hs="scaleY",Uo="skewX",Yo="skewY",Jt="fill",Ne="stroke",Hc="modified",$o="json",rg="svg",W=new class{constructor(){this[$o]=new Map,this[rg]=new Map}has(a){return this[$o].has(a)}getClass(a){const t=this[$o].get(a);if(!t)throw new mi("No class registered for ".concat(a));return t}setClass(a,t){t?this[$o].set(t,a):(this[$o].set(a.type,a),this[$o].set(a.type.toLowerCase(),a))}getSVGClass(a){return this[rg].get(a)}setSVGClass(a,t){this[rg].set(t??a.type.toLowerCase(),a)}},Vc=new class extends Array{remove(a){const t=this.indexOf(a);t>-1&&this.splice(t,1)}cancelAll(){const a=this.splice(0);return a.forEach(t=>t.abort()),a}cancelByCanvas(a){if(!a)return[];const t=this.filter(e=>{var s;return e.target===a||typeof e.target=="object"&&((s=e.target)===null||s===void 0?void 0:s.canvas)===a});return t.forEach(e=>e.abort()),t}cancelByTarget(a){if(!a)return[];const t=this.filter(e=>e.target===a);return t.forEach(e=>e.abort()),t}};class Fy{constructor(){T(this,"__eventListeners",{})}on(t,e){if(this.__eventListeners||(this.__eventListeners={}),typeof t=="object")return Object.entries(t).forEach(s=>{let[i,n]=s;this.on(i,n)}),()=>this.off(t);if(e){const s=t;return this.__eventListeners[s]||(this.__eventListeners[s]=[]),this.__eventListeners[s].push(e),()=>this.off(s,e)}return()=>!1}once(t,e){if(typeof t=="object"){const s=[];return Object.entries(t).forEach(i=>{let[n,r]=i;s.push(this.once(n,r))}),()=>s.forEach(i=>i())}if(e){const s=this.on(t,function(){for(var i=arguments.length,n=new Array(i),r=0;r<i;r++)n[r]=arguments[r];e.call(this,...n),s()});return s}return()=>!1}_removeEventListener(t,e){if(this.__eventListeners[t])if(e){const s=this.__eventListeners[t],i=s.indexOf(e);i>-1&&s.splice(i,1)}else this.__eventListeners[t]=[]}off(t,e){if(this.__eventListeners)if(t===void 0)for(const s in this.__eventListeners)this._removeEventListener(s);else typeof t=="object"?Object.entries(t).forEach(s=>{let[i,n]=s;this._removeEventListener(i,n)}):this._removeEventListener(t,e)}fire(t,e){var s;if(!this.__eventListeners)return;const i=(s=this.__eventListeners[t])===null||s===void 0?void 0:s.concat();if(i)for(let n=0;n<i.length;n++)i[n].call(this,e||{})}}const Ar=(a,t)=>{const e=a.indexOf(t);return e!==-1&&a.splice(e,1),a},Ws=a=>{if(a===0)return 1;switch(Math.abs(a)/jn){case 1:case 3:return 0;case 2:return-1}return Math.cos(a)},zs=a=>{if(a===0)return 0;const t=a/jn,e=Math.sign(a);switch(t){case 1:return e;case 2:return 0;case 3:return-e}return Math.sin(a)};class O{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;typeof t=="object"?(this.x=t.x,this.y=t.y):(this.x=t,this.y=e)}add(t){return new O(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new O(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new O(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new O(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new O(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new O(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new O(this.x/t.x,this.y/t.y)}scalarDivide(t){return new O(this.x/t,this.y/t)}scalarDivideEquals(t){return this.x/=t,this.y/=t,this}eq(t){return this.x===t.x&&this.y===t.y}lt(t){return this.x<t.x&&this.y<t.y}lte(t){return this.x<=t.x&&this.y<=t.y}gt(t){return this.x>t.x&&this.y>t.y}gte(t){return this.x>=t.x&&this.y>=t.y}lerp(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:.5;return e=Math.max(Math.min(1,e),0),new O(this.x+(t.x-this.x)*e,this.y+(t.y-this.y)*e)}distanceFrom(t){const e=this.x-t.x,s=this.y-t.y;return Math.sqrt(e*e+s*s)}midPointFrom(t){return this.lerp(t)}min(t){return new O(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new O(Math.max(this.x,t.x),Math.max(this.y,t.y))}toString(){return"".concat(this.x,",").concat(this.y)}setXY(t,e){return this.x=t,this.y=e,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setFromPoint(t){return this.x=t.x,this.y=t.y,this}swap(t){const e=this.x,s=this.y;this.x=t.x,this.y=t.y,t.x=e,t.y=s}clone(){return new O(this.x,this.y)}rotate(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:og;const s=zs(t),i=Ws(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 og=new O(0,0),Gc=a=>!!a&&Array.isArray(a._objects);function Qp(a){class t extends a{constructor(){super(...arguments),T(this,"_objects",[])}_onObjectAdded(s){}_onObjectRemoved(s){}_onStackOrderChanged(s){}add(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];const r=this._objects.push(...i);return i.forEach(o=>this._onObjectAdded(o)),r}insertAt(s){for(var i=arguments.length,n=new Array(i>1?i-1:0),r=1;r<i;r++)n[r-1]=arguments[r];return this._objects.splice(s,0,...n),n.forEach(o=>this._onObjectAdded(o)),this._objects.length}remove(){const s=this._objects,i=[];for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return r.forEach(h=>{const c=s.indexOf(h);c!==-1&&(s.splice(c,1),i.push(h),this._onObjectRemoved(h))}),i}forEachObject(s){this.getObjects().forEach((i,n,r)=>s(i,n,r))}getObjects(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];return i.length===0?[...this._objects]:this._objects.filter(r=>r.isType(...i))}item(s){return this._objects[s]}isEmpty(){return this._objects.length===0}size(){return this._objects.length}contains(s,i){return!!this._objects.includes(s)||!!i&&this._objects.some(n=>n instanceof t&&n.contains(s,!0))}complexity(){return this._objects.reduce((s,i)=>s+=i.complexity?i.complexity():0,0)}sendObjectToBack(s){return!(!s||s===this._objects[0])&&(Ar(this._objects,s),this._objects.unshift(s),this._onStackOrderChanged(s),!0)}bringObjectToFront(s){return!(!s||s===this._objects[this._objects.length-1])&&(Ar(this._objects,s),this._objects.push(s),this._onStackOrderChanged(s),!0)}sendObjectBackwards(s,i){if(!s)return!1;const n=this._objects.indexOf(s);if(n!==0){const r=this.findNewLowerIndex(s,n,i);return Ar(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}bringObjectForward(s,i){if(!s)return!1;const n=this._objects.indexOf(s);if(n!==this._objects.length-1){const r=this.findNewUpperIndex(s,n,i);return Ar(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}moveObjectTo(s,i){return s!==this._objects[i]&&(Ar(this._objects,s),this._objects.splice(i,0,s),this._onStackOrderChanged(s),!0)}findNewLowerIndex(s,i,n){let r;if(n){r=i;for(let o=i-1;o>=0;--o)if(s.isOverlapping(this._objects[o])){r=o;break}}else r=i-1;return r}findNewUpperIndex(s,i,n){let r;if(n){r=i;for(let o=i+1;o<this._objects.length;++o)if(s.isOverlapping(this._objects[o])){r=o;break}}else r=i+1;return r}collectObjects(s){let{left:i,top:n,width:r,height:o}=s,{includeIntersecting:h=!0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const c=[],u=new O(i,n),d=u.add(new O(r,o));for(let g=this._objects.length-1;g>=0;g--){const f=this._objects[g];f.selectable&&f.visible&&(h&&f.intersectsWithRect(u,d)||f.isContainedWithinRect(u,d)||h&&f.containsPoint(u)||h&&f.containsPoint(d))&&c.push(f)}return c}}return t}class Jp extends Fy{_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 Eh(a){return Ic().requestAnimationFrame(a)}function Zp(a){return Ic().cancelAnimationFrame(a)}let Iy=0;const Bn=()=>Iy++,As=()=>{const a=Xo().createElement("canvas");if(!a||a.getContext===void 0)throw new mi("Failed to create `canvas` element");return a},tm=()=>Xo().createElement("img"),Xs=a=>{const t=As();return t.width=a.width,t.height=a.height,t},ag=(a,t,e)=>a.toDataURL("image/".concat(t),e),zt=a=>a*tg,Hn=a=>a/tg,em=a=>a.every((t,e)=>t===Fe[e]),Se=(a,t,e)=>new O(a).transform(t,e),Ze=a=>{const t=1/(a[0]*a[3]-a[1]*a[2]),e=[t*a[3],-t*a[1],-t*a[2],t*a[0],0,0],{x:s,y:i}=new O(a[4],a[5]).transform(e,!0);return e[4]=-s,e[5]=-i,e},Yt=(a,t,e)=>[a[0]*t[0]+a[2]*t[1],a[1]*t[0]+a[3]*t[1],a[0]*t[2]+a[2]*t[3],a[1]*t[2]+a[3]*t[3],e?0:a[0]*t[4]+a[2]*t[5]+a[4],e?0:a[1]*t[4]+a[3]*t[5]+a[5]],Wc=(a,t)=>a.reduceRight((e,s)=>s&&e?Yt(s,e,t):s||e,void 0)||Fe.concat(),sm=a=>{let[t,e]=a;return Math.atan2(e,t)},Tr=a=>{const t=sm(a),e=Math.pow(a[0],2)+Math.pow(a[1],2),s=Math.sqrt(e),i=(a[0]*a[3]-a[2]*a[1])/s,n=Math.atan2(a[0]*a[2]+a[1]*a[3],e);return{angle:Hn(t),scaleX:s,scaleY:i,skewX:Hn(n),skewY:0,translateX:a[4]||0,translateY:a[5]||0}},qo=function(a){return[1,0,0,1,a,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function Ko(){let{angle:a=0}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},{x:t=0,y:e=0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const s=zt(a),i=Ws(s),n=zs(s);return[i,n,-n,i,t?t-(i*t-n*e):0,e?e-(n*t+i*e):0]}const zc=function(a){return[a,0,0,arguments.length>1&&arguments[1]!==void 0?arguments[1]:a,0,0]},im=a=>Math.tan(zt(a)),hg=a=>[1,0,im(a),1,0,0],lg=a=>[1,im(a),0,1,0,0],kh=a=>{let{scaleX:t=1,scaleY:e=1,flipX:s=!1,flipY:i=!1,skewX:n=0,skewY:r=0}=a,o=zc(s?-t:t,i?-e:e);return n&&(o=Yt(o,hg(n),!0)),r&&(o=Yt(o,lg(r),!0)),o},nm=a=>{const{translateX:t=0,translateY:e=0,angle:s=0}=a;let i=qo(t,e);s&&(i=Yt(i,Ko({angle:s})));const n=kh(a);return em(n)||(i=Yt(i,n)),i},Mh=function(a){let{signal:t,crossOrigin:e=null}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise(function(s,i){if(t&&t.aborted)return i(new Jd("loadImage"));const n=tm();let r;t&&(r=function(h){n.src="",i(h)},t.addEventListener("abort",r,{once:!0}));const o=function(){n.onload=n.onerror=null,r&&(t==null||t.removeEventListener("abort",r)),s(n)};a?(n.onload=o,n.onerror=function(){r&&(t==null||t.removeEventListener("abort",r)),i(new mi("Error loading ".concat(n.src)))},e&&(n.crossOrigin=e),n.src=a):o()})},Qo=function(a){let{signal:t,reviver:e=Cr}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise((s,i)=>{const n=[];t&&t.addEventListener("abort",i,{once:!0}),Promise.all(a.map(r=>W.getClass(r.type).fromObject(r,{signal:t}).then(o=>(e(r,o),n.push(o),o)))).then(s).catch(r=>{n.forEach(o=>{o.dispose&&o.dispose()}),i(r)}).finally(()=>{t&&t.removeEventListener("abort",i)})})},Ph=function(a){let{signal:t}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise((e,s)=>{const i=[];t&&t.addEventListener("abort",s,{once:!0});const n=Object.values(a).map(o=>o&&o.type&&W.has(o.type)?Qo([o],{signal:t}).then(h=>{let[c]=h;return i.push(c),c}):o),r=Object.keys(a);Promise.all(n).then(o=>o.reduce((h,c,u)=>(h[r[u]]=c,h),{})).then(e).catch(o=>{i.forEach(h=>{h.dispose&&h.dispose()}),s(o)}).finally(()=>{t&&t.removeEventListener("abort",s)})})},Er=function(a){return(arguments.length>1&&arguments[1]!==void 0?arguments[1]:[]).reduce((t,e)=>(e in a&&(t[e]=a[e]),t),{})},cg=(a,t)=>Object.keys(a).reduce((e,s)=>(t(a[s],s,a)&&(e[s]=a[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"},ug=(a,t,e)=>(e<0&&(e+=1),e>1&&(e-=1),e<1/6?a+6*(t-a)*e:e<.5?t:e<2/3?a+(t-a)*(2/3-e)*6:a),om=(a,t,e,s)=>{a/=255,t/=255,e/=255;const i=Math.max(a,t,e),n=Math.min(a,t,e);let r,o;const h=(i+n)/2;if(i===n)r=o=0;else{const c=i-n;switch(o=h>.5?c/(2-i-n):c/(i+n),i){case a:r=(t-e)/c+(t<e?6:0);break;case t:r=(e-a)/c+2;break;case e:r=(a-t)/c+4}r/=6}return[Math.round(360*r),Math.round(100*o),Math.round(100*h),s]},am=function(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"1";return parseFloat(a)/(a.endsWith("%")?100:1)},Xc=a=>Math.min(Math.round(a),255).toString(16).toUpperCase().padStart(2,"0"),hm=a=>{let[t,e,s,i=1]=a;const n=Math.round(.3*t+.59*e+.11*s);return[n,n,n,i]};class _t{constructor(t){if(T(this,"isUnrecognised",!1),t)if(t instanceof _t)this.setSource([...t._source]);else if(Array.isArray(t)){const[e,s,i,n=1]=t;this.setSource([e,s,i,n])}else this.setSource(this._tryParsingColor(t));else this.setSource([0,0,0,1])}_tryParsingColor(t){return t in rm&&(t=rm[t]),t==="transparent"?[255,255,255,0]:_t.sourceFromHex(t)||_t.sourceFromRgb(t)||_t.sourceFromHsl(t)||(this.isUnrecognised=!0)&&[0,0,0,1]}getSource(){return this._source}setSource(t){this._source=t}toRgb(){const[t,e,s]=this.getSource();return"rgb(".concat(t,",").concat(e,",").concat(s,")")}toRgba(){return"rgba(".concat(this.getSource().join(","),")")}toHsl(){const[t,e,s]=om(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(s,"%)")}toHsla(){const[t,e,s,i]=om(...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(Xc(t)).concat(Xc(e)).concat(Xc(s)).concat(Xc(Math.round(255*i)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(hm(this.getSource())),this}toBlackWhite(t){const[e,,,s]=hm(this.getSource()),i=e<(t||127)?0:255;return this.setSource([i,i,i,s]),this}overlayWith(t){t instanceof _t||(t=new _t(t));const e=this.getSource(),s=t.getSource(),[i,n,r]=e.map((o,h)=>Math.round(.5*o+.5*s[h]));return this.setSource([i,n,r,e[3]]),this}static fromRgb(t){return _t.fromRgba(t)}static fromRgba(t){return new _t(_t.sourceFromRgb(t))}static sourceFromRgb(t){const e=t.match(/^rgba?\(\s*(\d{0,3}(?:\.\d+)?%?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*(?:\s*[,/]\s*(\d{0,3}(?:\.\d+)?%?)\s*)?\)$/i);if(e){const[s,i,n]=e.slice(1,4).map(r=>{const o=parseFloat(r);return r.endsWith("%")?Math.round(2.55*o):o});return[s,i,n,am(e[4])]}}static fromHsl(t){return _t.fromHsla(t)}static fromHsla(t){return new _t(_t.sourceFromHsl(t))}static sourceFromHsl(t){const e=t.match(/^hsla?\(\s*([+-]?\d{0,3}(?:\.\d+)?(?:deg|turn|rad)?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*(?:\s*[,/]\s*(\d*(?:\.\d+)?%?)\s*)?\)$/i);if(!e)return;const s=(_t.parseAngletoDegrees(e[1])%360+360)%360/360,i=parseFloat(e[2])/100,n=parseFloat(e[3])/100;let r,o,h;if(i===0)r=o=h=n;else{const c=n<=.5?n*(i+1):n+i-n*i,u=2*n-c;r=ug(u,c,s+1/3),o=ug(u,c,s),h=ug(u,c,s-1/3)}return[Math.round(255*r),Math.round(255*o),Math.round(255*h),am(e[4])]}static fromHex(t){return new _t(_t.sourceFromHex(t))}static sourceFromHex(t){if(t.match(/^#?(([0-9a-f]){3,4}|([0-9a-f]{2}){3,4})$/i)){const e=t.slice(t.indexOf("#")+1);let s;s=e.length<=4?e.split("").map(h=>h+h):e.match(/.{2}/g);const[i,n,r,o=255]=s.map(h=>parseInt(h,16));return[i,n,r,o/255]}}static parseAngletoDegrees(t){const e=t.toLowerCase(),s=parseFloat(e);return e.includes("rad")?Hn(s):e.includes("turn")?360*s:s}}const Dt=(a,t)=>parseFloat(Number(a).toFixed(t)),Be=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:eg;const e=/\D{0,2}$/.exec(a),s=parseFloat(a),i=dt.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}},dg=a=>{const[t,e]=a.trim().split(" "),[s,i]=(n=t)&&n!==Ie?[n.slice(1,4),n.slice(5,8)]:n===Ie?[n,n]:["Mid","Mid"];var n;return{meetOrSlice:e||"meet",alignX:s,alignY:i}},Oh=a=>"matrix("+a.map(t=>Dt(t,dt.NUM_FRACTION_DIGITS)).join(" ")+")",Dh=function(a,t){let e,s,i=!(arguments.length>2&&arguments[2]!==void 0)||arguments[2];if(t)if(t.toLive)e="url(#SVGID_".concat(t.id,")");else{const n=new _t(t),r=n.getAlpha();e=n.toRgb(),r!==1&&(s=r.toString())}else e="none";return i?"".concat(a,": ").concat(e,"; ").concat(s?"".concat(a,"-opacity: ").concat(s,"; "):""):"".concat(a,'="').concat(e,'" ').concat(s?"".concat(a,'-opacity="').concat(s,'" '):"")},Ts=a=>!!a&&a.toLive!==void 0,lm=a=>!!a&&typeof a.toObject=="function",cm=a=>!!a&&a.offsetX!==void 0&&"source"in a,um=a=>!!a&&typeof a._renderText=="function",kr=a=>!!a&&"multiSelectionStacking"in a;function dm(a){const t=a&&Us(a);let e=0,s=0;if(!a||!t)return{left:e,top:s};let i=a;const n=t.documentElement,r=t.body||{scrollLeft:0,scrollTop:0};for(;i&&(i.parentNode||i.host)&&(i=i.parentNode||i.host,i===t?(e=r.scrollLeft||n.scrollLeft||0,s=r.scrollTop||n.scrollTop||0):(e+=i.scrollLeft||0,s+=i.scrollTop||0),i.nodeType!==1||i.style.position!=="fixed"););return{left:e,top:s}}const Us=a=>a.ownerDocument||null,gm=a=>{var t;return((t=a.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null},fm=function(a,t,e){let{width:s,height:i}=e,n=arguments.length>3&&arguments[3]!==void 0?arguments[3]:1;a.width=s,a.height=i,n>1&&(a.setAttribute("width",(s*n).toString()),a.setAttribute("height",(i*n).toString()),t.scale(n,n))},gg=(a,t)=>{let{width:e,height:s}=t;e&&(a.style.width=typeof e=="number"?"".concat(e,"px"):e),s&&(a.style.height=typeof s=="number"?"".concat(s,"px"):s)};function pm(a){return a.onselectstart!==void 0&&(a.onselectstart=()=>!1),a.style.userSelect=Ie,a}class mm{constructor(t){T(this,"_originalCanvasStyle",void 0),T(this,"lower",void 0);const e=this.createLowerCanvas(t);this.lower={el:e,ctx:e.getContext("2d")}}createLowerCanvas(t){const e=(s=t)&&s.getContext!==void 0?t:t&&Xo().getElementById(t)||As();var s;if(e.hasAttribute("data-fabric"))throw new mi("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;fm(s,i,t,e)}setCSSDimensions(t){gg(this.lower.el,t)}calcOffset(){return function(t){var e;const s=t&&Us(t),i={left:0,top:0};if(!s)return i;const n=((e=gm(t))===null||e===void 0?void 0:e.getComputedStyle(t,null))||{};i.left+=parseInt(n.borderLeftWidth,10)||0,i.top+=parseInt(n.borderTopWidth,10)||0,i.left+=parseInt(n.paddingLeft,10)||0,i.top+=parseInt(n.paddingTop,10)||0;let r={left:0,top:0};const o=s.documentElement;t.getBoundingClientRect!==void 0&&(r=t.getBoundingClientRect());const h=dm(t);return{left:r.left+h.left-(o.clientLeft||0)+i.left,top:r.top+h.top-(o.clientTop||0)+i.top}}(this.lower.el)}dispose(){vi().dispose(this.lower.el),delete this.lower}}const jy={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...Fe]};class Rh extends Qp(Jp){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 Rh.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 mm(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&&(Xi("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?Yp():1}calcOffset(){return this._offset=this.elements.calcOffset()}getWidth(){return this.width}getHeight(){return this.height}setWidth(t,e){return this.setDimensions({width:t},e)}setHeight(t,e){return this.setDimensions({height:t},e)}_setDimensionsImpl(t){let{cssOnly:e=!1,backstoreOnly:s=!1}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!e){const i=E({width:this.width,height:this.height},t);this.elements.setDimensions(i,this.getRetinaScaling()),this.hasLostContext=!0,this.width=i.width,this.height=i.height}s||this.elements.setCSSDimensions(t),this.calcOffset()}setDimensions(t,e){this._setDimensionsImpl(t,e),e&&e.cssOnly||this.requestRenderAll()}getZoom(){return this.viewportTransform[0]}setViewportTransform(t){this.viewportTransform=t,this.calcViewportBoundaries(),this.renderOnAddRemove&&this.requestRenderAll()}zoomToPoint(t,e){const s=t,i=[...this.viewportTransform],n=Se(t,Ze(i));i[0]=e,i[3]=e;const r=Se(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=Eh(()=>this.renderAndReset()))}calcViewportBoundaries(){const t=this.width,e=this.height,s=Ze(this.viewportTransform),i=Se({x:0,y:0},s),n=Se({x:t,y:e},s),r=i.min(n),o=i.max(n);return this.vptCoords={tl:r,tr:new O(o.x,r.y),bl:new O(r.x,o.y),br:o}}cancelRequestedRender(){this.nextRenderHandle&&(Zp(this.nextRenderHandle),this.nextRenderHandle=0)}drawControls(t){}renderCanvas(t,e){if(this.destroyed)return;const s=this.viewportTransform,i=this.clipPath;this.calcViewportBoundaries(),this.clearContext(t),t.imageSmoothingEnabled=this.imageSmoothingEnabled,t.patternQuality="best",this.fire("before:render",{ctx:t}),this._renderBackground(t),t.save(),t.transform(s[0],s[1],s[2],s[3],s[4],s[5]),this._renderObjects(t,e),t.restore(),this.controlsAboveOverlay||this.skipControlsDrawing||this.drawControls(t),i&&(i._set("canvas",this),i.shouldCache(),i._transformDone=!0,i.renderCache({forClipping:!0}),this.drawClipPathOnCanvas(t,i)),this._renderOverlay(t),this.controlsAboveOverlay&&!this.skipControlsDrawing&&this.drawControls(t),this.fire("after:render",{ctx:t}),this.__cleanupTask&&(this.__cleanupTask(),this.__cleanupTask=void 0)}drawClipPathOnCanvas(t,e){const s=this.viewportTransform;t.save(),t.transform(...s),t.globalCompositeOperation="destination-in",e.transform(t),t.scale(1/e.zoomX,1/e.zoomY),t.drawImage(e._cacheCanvas,-e.cacheTranslationX,-e.cacheTranslationY),t.restore()}_renderObjects(t,e){for(let s=0,i=e.length;s<i;++s)e[s]&&e[s].render(t)}_renderBackgroundOrOverlay(t,e){const s=this["".concat(e,"Color")],i=this["".concat(e,"Image")],n=this.viewportTransform,r=this["".concat(e,"Vpt")];if(!s&&!i)return;const o=Ts(s);if(s){if(t.save(),t.beginPath(),t.moveTo(0,0),t.lineTo(this.width,0),t.lineTo(this.width,this.height),t.lineTo(0,this.height),t.closePath(),t.fillStyle=o?s.toLive(t):s,r&&t.transform(...n),o){t.transform(1,0,0,1,s.offsetX||0,s.offsetY||0);const h=s.gradientTransform||s.patternTransform;h&&t.transform(...h)}t.fill(),t.restore()}if(i){t.save();const{skipOffscreen:h}=this;this.skipOffscreen=r,r&&t.transform(...n),i.render(t),this.skipOffscreen=h,t.restore()}}_renderBackground(t){this._renderBackgroundOrOverlay(t,"background")}_renderOverlay(t){this._renderBackgroundOrOverlay(t,"overlay")}getCenter(){return{top:this.height/2,left:this.width/2}}getCenterPoint(){return new O(this.width/2,this.height/2)}centerObjectH(t){return this._centerObject(t,new O(this.getCenterPoint().x,t.getCenterPoint().y))}centerObjectV(t){return this._centerObject(t,new O(t.getCenterPoint().x,this.getCenterPoint().y))}centerObject(t){return this._centerObject(t,this.getCenterPoint())}viewportCenterObject(t){return this._centerObject(t,this.getVpCenter())}viewportCenterObjectH(t){return this._centerObject(t,new O(this.getVpCenter().x,t.getCenterPoint().y))}viewportCenterObjectV(t){return this._centerObject(t,new O(t.getCenterPoint().x,this.getVpCenter().y))}getVpCenter(){return Se(this.getCenterPoint(),Ze(this.viewportTransform))}_centerObject(t,e){t.setXY(e,tt,tt),t.setCoords(),this.renderOnAddRemove&&this.requestRenderAll()}toDatalessJSON(t){return this.toDatalessObject(t)}toObject(t){return this._toObjectMethod("toObject",t)}toJSON(){return this.toObject()}toDatalessObject(t){return this._toObjectMethod("toDatalessObject",t)}_toObjectMethod(t,e){const s=this.clipPath,i=s&&!s.excludeFromExport?this._toObject(s,t,e):null;return E(E(E({version:Zd},Er(this,e)),{},{objects:this._objects.filter(n=>!n.excludeFromExport).map(n=>this._toObject(n,t,e))},this.__serializeBgOverlay(t,e)),i?{clipPath:i}:null)}_toObject(t,e,s){let i;this.includeDefaultValues||(i=t.includeDefaultValues,t.includeDefaultValues=!1);const n=t[e](s);return this.includeDefaultValues||(t.includeDefaultValues=!!i),n}__serializeBgOverlay(t,e){const s={},i=this.backgroundImage,n=this.overlayImage,r=this.backgroundColor,o=this.overlayColor;return Ts(r)?r.excludeFromExport||(s.background=r.toObject(e)):r&&(s.background=r),Ts(o)?o.excludeFromExport||(s.overlay=o.toObject(e)):o&&(s.overlay=o),i&&!i.excludeFromExport&&(s.backgroundImage=this._toObject(i,t,e)),n&&!n.excludeFromExport&&(s.overlayImage=this._toObject(n,t,e)),s}toSVG(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;t.reviver=e;const s=[];return this._setSVGPreamble(s,t),this._setSVGHeader(s,t),this.clipPath&&s.push('<g clip-path="url(#'.concat(this.clipPath.clipPathId,`)" >
|
|
33
33
|
`)),this._setSVGBgOverlayColor(s,"background"),this._setSVGBgOverlayImage(s,"backgroundImage",e),this._setSVGObjects(s,e),this.clipPath&&s.push(`</g>
|
|
34
34
|
`),this._setSVGBgOverlayColor(s,"overlay"),this._setSVGBgOverlayImage(s,"overlayImage",e),s.push("</svg>"),s.join("")}_setSVGPreamble(t,e){e.suppressPreamble||t.push('<?xml version="1.0" encoding="',e.encoding||"UTF-8",`" standalone="no" ?>
|
|
35
35
|
`,'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" ',`"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
|
36
|
-
`)}_setSVGHeader(t,e){const s=e.width||"".concat(this.width),i=e.height||"".concat(this.height),n=dt.NUM_FRACTION_DIGITS,r=e.viewBox;let
|
|
37
|
-
`,"<desc>Created with Fabric.js ",
|
|
36
|
+
`)}_setSVGHeader(t,e){const s=e.width||"".concat(this.width),i=e.height||"".concat(this.height),n=dt.NUM_FRACTION_DIGITS,r=e.viewBox;let o;if(r)o='viewBox="'.concat(r.x," ").concat(r.y," ").concat(r.width," ").concat(r.height,'" ');else if(this.svgViewportTransformation){const h=this.viewportTransform;o='viewBox="'.concat(Dt(-h[4]/h[0],n)," ").concat(Dt(-h[5]/h[3],n)," ").concat(Dt(this.width/h[0],n)," ").concat(Dt(this.height/h[3],n),'" ')}else o='viewBox="0 0 '.concat(this.width," ").concat(this.height,'" ');t.push("<svg ",'xmlns="http://www.w3.org/2000/svg" ','xmlns:xlink="http://www.w3.org/1999/xlink" ','version="1.1" ','width="',s,'" ','height="',i,'" ',o,`xml:space="preserve">
|
|
37
|
+
`,"<desc>Created with Fabric.js ",Zd,`</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(Bn()),'<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(Ts(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?Oh(i):""})}}).join("")}createSVGFontFacesMarkup(){const t=[],e={},s=dt.fontPaths;this._objects.forEach(function n(r){t.push(r),Gc(r)&&r._objects.forEach(n)}),t.forEach(n=>{if(!um(n))return;const{styles:r,fontFamily:o}=n;!e[o]&&s[o]&&(e[o]=!0,r&&Object.values(r).forEach(h=>{Object.values(h).forEach(c=>{let{fontFamily:u=""}=c;!e[u]&&s[u]&&(e[u]=!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(Ts(s)){const i=s.repeat||"",n=this.width,r=this.height,o=this["".concat(e,"Vpt")]?Oh(Ze(this.viewportTransform)):"";t.push('<rect transform="'.concat(o," translate(").concat(n/2,",").concat(r/2,')" x="').concat(s.offsetX-n/2,'" y="').concat(s.offsetY-r/2,'" width="').concat(i!=="repeat-y"&&i!=="no-repeat"||!cm(s)?n:s.source.width,'" height="').concat(i!=="repeat-x"&&i!=="no-repeat"||!cm(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 mi("`json` is undefined"));const i=typeof t=="string"?JSON.parse(t):t,{objects:n=[],backgroundImage:r,background:o,overlayImage:h,overlay:c,clipPath:u}=i,d=this.renderOnAddRemove;return this.renderOnAddRemove=!1,Promise.all([Qo(n,{reviver:e,signal:s}),Ph({backgroundImage:r,backgroundColor:o,overlayImage:h,overlayColor:c,clipPath:u},{signal:s})]).then(g=>{let[f,p]=g;return this.clear(),this.add(...f),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=Xs(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 ag(this.toCanvasElement(r,t),e,s)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:1,{width:e,height:s,left:i,top:n,filter:r}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const o=(e||this.width)*t,h=(s||this.height)*t,c=this.getZoom(),u=this.width,d=this.height,g=this.skipControlsDrawing,f=c*t,p=this.viewportTransform,m=[f,0,0,f,(p[4]-(i||0))*t,(p[5]-(n||0))*t],y=this.enableRetinaScaling,b=Xs({width:o,height:h}),x=r?this._objects.filter(C=>r(C)):this._objects;return this.enableRetinaScaling=!1,this.viewportTransform=m,this.width=o,this.height=h,this.skipControlsDrawing=!0,this.calcViewportBoundaries(),this.renderCanvas(b.getContext("2d"),x),this.viewportTransform=p,this.width=u,this.height=d,this.calcViewportBoundaries(),this.enableRetinaScaling=y,this.skipControlsDrawing=g,b}dispose(){return!this.disposed&&this.elements.cleanupDOM({width:this.width,height:this.height}),Vc.cancelByCanvas(this),this.disposed=!0,new Promise((t,e)=>{const s=()=>{this.destroy(),t(!0)};s.kill=e,this.__cleanupTask&&this.__cleanupTask.kill("aborted"),this.destroyed?t(!1):this.nextRenderHandle?this.__cleanupTask=s:s()})}destroy(){this.destroyed=!0,this.cancelRequestedRender(),this.forEachObject(t=>t.dispose()),this._objects=[],this.backgroundImage&&this.backgroundImage.dispose(),this.backgroundImage=void 0,this.overlayImage&&this.overlayImage.dispose(),this.overlayImage=void 0,this.elements.dispose()}toString(){return"#<Canvas (".concat(this.complexity(),"): { objects: ").concat(this._objects.length," }>")}}T(Rh,"ownDefaults",jy);const Ny=["touchstart","touchmove","touchend"],vm=a=>{const t=dm(a.target),e=function(s){const i=s.changedTouches;return i&&i[0]?i[0]:s}(a);return new O(e.clientX+t.left,e.clientY+t.top)},Uc=a=>Ny.includes(a.type)||a.pointerType==="touch",fg=a=>{a.preventDefault(),a.stopPropagation()},bi=a=>{let t=0,e=0,s=0,i=0;for(let n=0,r=a.length;n<r;n++){const{x:o,y:h}=a[n];(o>s||!n)&&(s=o),(o<t||!n)&&(t=o),(h>i||!n)&&(i=h),(h<e||!n)&&(e=h)}return{left:t,top:e,width:s-t,height:i-e}},By=["translateX","translateY","scaleX","scaleY"],bm=(a,t)=>Jo(a,Yt(t,a.calcOwnMatrix())),Jo=(a,t)=>{const e=Tr(t),{translateX:s,translateY:i,scaleX:n,scaleY:r}=e,o=Ot(e,By),h=new O(s,i);a.flipX=!1,a.flipY=!1,Object.assign(a,o),a.set({scaleX:n,scaleY:r}),a.setPositionByOrigin(h,tt,tt)},ym=a=>{a.scaleX=1,a.scaleY=1,a.skewX=0,a.skewY=0,a.flipX=!1,a.flipY=!1,a.rotate(0)},pg=a=>({scaleX:a.scaleX,scaleY:a.scaleY,skewX:a.skewX,skewY:a.skewY,angle:a.angle,left:a.left,flipX:a.flipX,flipY:a.flipY,top:a.top}),Yc=(a,t,e)=>{const s=a/2,i=t/2,n=[new O(-s,-i),new O(s,-i),new O(-s,i),new O(s,i)].map(o=>o.transform(e)),r=bi(n);return new O(r.width,r.height)},Lh=function(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Fe;return Yt(Ze(arguments.length>1&&arguments[1]!==void 0?arguments[1]:Fe),a)},Mr=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Fe,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Fe;return a.transform(Lh(t,e))},_m=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Fe,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Fe;return a.transform(Lh(t,e),!0)},mg=(a,t,e)=>{const s=Lh(t,e);return Jo(a,Yt(s,a.calcOwnMatrix())),s},wm=(a,t)=>{var e;const{transform:{target:s}}=t;(e=s.canvas)===null||e===void 0||e.fire("object:".concat(a),E(E({},t),{},{target:s})),s.fire(a,t)},Hy={left:-.5,top:-.5,center:0,bottom:.5,right:.5},Zt=a=>typeof a=="string"?Hy[a]:a-.5,$c="not-allowed";function xm(a){return Zt(a.originX)===Zt(tt)&&Zt(a.originY)===Zt(tt)}function Sm(a){return .5-Zt(a)}const Ys=(a,t)=>a[t],Cm=(a,t,e,s)=>({e:a,transform:t,pointer:new O(e,s)});function Am(a,t){const e=a.getTotalAngle()+Hn(Math.atan2(t.y,t.x))+360;return Math.round(e%360/45)}function vg(a,t,e,s,i){var n;let{target:r,corner:o}=a;const h=r.controls[o],c=((n=r.canvas)===null||n===void 0?void 0:n.getZoom())||1,u=r.padding/c,d=function(g,f,p,m){const y=g.getRelativeCenterPoint(),b=p!==void 0&&m!==void 0?g.translateToGivenOrigin(y,tt,tt,p,m):new O(g.left,g.top);return(g.angle?f.rotate(-zt(g.angle),y):f).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 Vy=(a,t,e,s)=>{const{target:i,offsetX:n,offsetY:r}=t,o=e-n,h=s-r,c=!Ys(i,"lockMovementX")&&i.left!==o,u=!Ys(i,"lockMovementY")&&i.top!==h;return c&&i.set(vt,o),u&&i.set(Je,h),(c||u)&&wm($p,Cm(a,t,e,s)),c||u};class Tm{getSvgStyles(t){const e=this.fillRule?this.fillRule:"nonzero",s=this.strokeWidth?this.strokeWidth:"0",i=this.strokeDashArray?this.strokeDashArray.join(" "):Ie,n=this.strokeDashOffset?this.strokeDashOffset:"0",r=this.strokeLineCap?this.strokeLineCap:"butt",o=this.strokeLineJoin?this.strokeLineJoin:"miter",h=this.strokeMiterLimit?this.strokeMiterLimit:"4",c=this.opacity!==void 0?this.opacity:"1",u=this.visible?"":" visibility: hidden;",d=t?"":this.getSvgFilter(),g=Dh(Jt,this.fill);return[Dh(Ne,this.stroke),"stroke-width: ",s,"; ","stroke-dasharray: ",i,"; ","stroke-linecap: ",r,"; ","stroke-dashoffset: ",n,"; ","stroke-linejoin: ",o,"; ","stroke-miterlimit: ",h,"; ",g,"fill-rule: ",e,"; ","opacity: ",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(Oh(s));return"".concat(i).concat(e,'" ')}_toSVG(t){return[""]}toSVG(t){return this._createBaseSVGMarkup(this._toSVG(t),{reviver:t})}toClipPathSVG(t){return" "+this._createBaseClipPathSVGMarkup(this._toSVG(t),{reviver:t})}_createBaseClipPathSVGMarkup(t){let{reviver:e,additionalTransform:s=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const i=[this.getSvgTransform(!0,s),this.getSvgCommons()].join(""),n=t.indexOf("COMMON_PARTS");return t[n]=i,e?e(t.join("")):t.join("")}_createBaseSVGMarkup(t){let{noStyle:e,reviver:s,withShadow:i,additionalTransform:n}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const r=e?"":'style="'.concat(this.getSvgStyles(),'" '),o=i?'style="'.concat(this.getSvgFilter(),'" '):"",h=this.clipPath,c=this.strokeUniform?'vector-effect="non-scaling-stroke" ':"",u=h&&h.absolutePositioned,d=this.stroke,g=this.fill,f=this.shadow,p=[],m=t.indexOf("COMMON_PARTS");let y;h&&(h.clipPathId="CLIPPATH_".concat(Bn()),y='<clipPath id="'.concat(h.clipPathId,`" >
|
|
51
51
|
`).concat(h.toClipPathSVG(s),`</clipPath>
|
|
52
|
-
`)),u&&p.push("<g ",
|
|
53
|
-
`),p.push("<g ",this.getSvgTransform(!1),u?"":
|
|
54
|
-
`);const b=[r,
|
|
52
|
+
`)),u&&p.push("<g ",o,this.getSvgCommons(),` >
|
|
53
|
+
`),p.push("<g ",this.getSvgTransform(!1),u?"":o+this.getSvgCommons(),` >
|
|
54
|
+
`);const b=[r,c,e?"":this.addPaintOrder()," ",n?'transform="'.concat(n,'" '):""].join("");return t[m]=b,Ts(g)&&p.push(g.toSVG(this)),Ts(d)&&p.push(d.toSVG(this)),f&&p.push(f.toSVG(this)),h&&p.push(y),p.push(t.join("")),p.push(`</g>
|
|
55
55
|
`),u&&p.push(`</g>
|
|
56
|
-
`),s?s(p.join("")):p.join("")}addPaintOrder(){return this.paintFirst
|
|
56
|
+
`),s?s(p.join("")):p.join("")}addPaintOrder(){return this.paintFirst!==Jt?' paint-order="'.concat(this.paintFirst,'" '):""}}function qc(a){return new RegExp("^("+a.join("|")+")\\b","i")}var Em;const $s=String.raw(Em||(Em=In(["(?:[-+]?(?:d*.d+|d+.?)(?:[eE][-+]?d+)?)"],["(?:[-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?)"]))),bg="http://www.w3.org/2000/svg",Gy=new RegExp("(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*("+$s+"(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|"+$s+"))?\\s+(.*)"),Wy={cx:vt,x:vt,r:"radius",cy:Je,y:Je,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"},yg="font-size",_g="clip-path",zy=qc(["path","circle","polygon","polyline","ellipse","rect","line","image","text"]),Xy=qc(["symbol","image","marker","pattern","view","svg"]),km=qc(["symbol","g","a","svg","clipPath","defs"]),Mm=new RegExp("^\\s*("+$s+"+)\\s*,?\\s*("+$s+"+)\\s*,?\\s*("+$s+"+)\\s*,?\\s*("+$s+"+)\\s*$"),Uy=new O(1,0),Pm=new O,wg=(a,t)=>a.rotate(t),Kc=(a,t)=>new O(t).subtract(a),Qc=a=>a.distanceFrom(Pm),Jc=(a,t)=>Math.atan2(Zo(a,t),Dm(a,t)),Om=a=>Jc(Uy,a),Zc=a=>a.eq(Pm)?a:a.scalarDivide(Qc(a)),xg=function(a){let t=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];return Zc(new O(-a.y,a.x).scalarMultiply(t?1:-1))},Zo=(a,t)=>a.x*t.y-a.y*t.x,Dm=(a,t)=>a.x*t.x+a.y*t.y,Sg=(a,t,e)=>{if(a.eq(t)||a.eq(e))return!0;const s=Zo(t,e),i=Zo(t,a),n=Zo(e,a);return s>=0?i>=0&&n<=0:!(i<=0&&n>=0)},Rm="(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?",Lm=new RegExp("(?:\\s|^)"+Rm+Rm+"("+$s+"?(?:px)?)?(?:\\s?|$)(?:$|\\s)");class Yi{constructor(t){const e=typeof t=="string"?Yi.parseShadow(t):t;Object.assign(this,Yi.ownDefaults,e),this.id=Bn()}static parseShadow(t){const e=t.trim(),[,s=0,i=0,n=0]=(Lm.exec(e)||[]).map(r=>parseFloat(r)||0);return{color:(e.replace(Lm,"")||"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=wg(new O(this.offsetX,this.offsetY),zt(-t.angle)),s=new _t(this.color);let i=40,n=40;return t.width&&t.height&&(i=100*Dt((Math.abs(e.x)+this.blur)/t.width,dt.NUM_FRACTION_DIGITS)+20,n=100*Dt((Math.abs(e.y)+this.blur)/t.height,dt.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
57
|
<feGaussianBlur in="SourceAlpha" stdDeviation="`).concat(Dt(this.blur?this.blur/2:0,dt.NUM_FRACTION_DIGITS),`"></feGaussianBlur>
|
|
58
58
|
<feOffset dx="`).concat(Dt(e.x,dt.NUM_FRACTION_DIGITS),'" dy="').concat(Dt(e.y,dt.NUM_FRACTION_DIGITS),`" result="oBlur" ></feOffset>
|
|
59
59
|
<feFlood flood-color="`).concat(s.toRgb(),'" flood-opacity="').concat(s.getAlpha(),`"/>
|
|
@@ -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=Ri.ownDefaults;return this.includeDefaultValues?t:qd(t,(s,i)=>s!==e[i])}static async fromObject(t){return new this(t)}}T(Ri,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),T(Ri,"type","shadow"),V.setClass(Ri,"shadow");const yr=(o,t,e)=>Math.max(o,Math.min(t,e)),Gy=[Ue,mt,Fe,is,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",Na,Ba],Fi=[$t,Le,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],Yy={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:mt,originY:Ue,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:$t,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},hg=(o,t,e,s)=>(o<Math.abs(t)?(o=t,s=e/4):s=t===0&&o===0?e/Di*Math.asin(1):e/Di*Math.asin(t/o),{a:o,c:t,p:e,s}),Sm=(o,t,e,s,i)=>o*Math.pow(2,10*(s-=1))*Math.sin((s*i-t)*Di/e),Cm=(o,t,e,s)=>-e*Math.cos(o/s*An)+e+t,lg=(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,Am=(o,t,e,s)=>e-lg(s-o,0,e,s)+t;var Uy=Object.freeze({__proto__:null,defaultEasing:Cm,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:Am,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}=hg(i,e,n,1.70158);return-Sm(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*Am(2*o,0,e,s)+t:.5*lg(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:l}=hg(i,e,n,1.70158);return o<1?-.5*Sm(r,a,h,o,s)+t:r*Math.pow(2,-10*(o-=1))*Math.sin((o*s-a)*Di/h)*.5+l+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*An)+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:lg,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:l}=hg(i,e,n,1.70158);return r*2**(-10*o)*Math.sin((o*s-a)*Di/h)+l+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*An)+t});const qy=()=>!1;class cg{constructor(t){let{startValue:e,byValue:s,duration:i=500,delay:n=0,easing:r=Cm,onStart:a=gr,onChange:h=gr,onComplete:l=gr,abort:u=qy,target:d}=t;T(this,"_state","pending"),T(this,"durationProgress",0),T(this,"valueProgress",0),this.tick=this.tick.bind(this),this.duration=i,this.delay=n,this.easing=r,this._onStart=a,this._onChange=h,this._onComplete=l,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(()=>fh(t),this.delay):fh(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),fh(this.tick)))}register(){Ac.push(this)}unregister(){Ac.remove(this)}abort(){this._state="aborted",this.unregister()}}const $y=["startValue","endValue"];class Ky extends cg{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(E(E({},Pt(t,$y)),{},{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 Jy=["startValue","endValue"];class Qy extends cg{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(E(E({},Pt(t,Jy)),{},{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 Zy=["startValue","endValue","easing","onChange","onComplete","abort"],t_=(o,t,e,s)=>t+e*(1-Math.cos(o/s*An)),ug=o=>o&&((t,e,s)=>o(new yt(t).toRgba(),e,s));class e_ extends cg{constructor(t){let{startValue:e,endValue:s,easing:i=t_,onChange:n,onComplete:r,abort:a}=t,h=Pt(t,Zy);const l=new yt(e).getSource(),u=new yt(s).getSource();super(E(E({},h),{},{startValue:l,byValue:u.map((d,g)=>d-l[g]),easing:i,onChange:ug(n),onComplete:ug(r),abort:ug(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),yr(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 dg(o){const t=(e=>Array.isArray(e.startValue)||Array.isArray(e.endValue))(o)?new Qy(o):new Ky(o);return t.start(),t}function Tm(o){const t=new e_(o);return t.start(),t}class Lt{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=Fc(e,s),r=Fc(e,t).divide(n);return i?Math.abs(r.x)===Math.abs(r.y):r.x===r.y&&r.x>=0&&r.x<=1}}static isPointInPolygon(t,e){const s=new D(t).setX(Math.min(t.x-1,...e.map(n=>n.x)));let i=0;for(let n=0;n<e.length;n++){const r=this.intersectSegmentSegment(e[n],e[(n+1)%e.length],t,s);if(r.includes(t))return!0;i+=+(r.status==="Intersection")}return i%2==1}static intersectLineLine(t,e,s,i){let n=!(arguments.length>4&&arguments[4]!==void 0)||arguments[4],r=!(arguments.length>5&&arguments[5]!==void 0)||arguments[5];const a=e.x-t.x,h=e.y-t.y,l=i.x-s.x,u=i.y-s.y,d=t.x-s.x,g=t.y-s.y,f=l*g-u*d,p=a*g-h*d,m=u*a-l*h;if(m!==0){const _=f/m,b=p/m;return(n||0<=_&&_<=1)&&(r||0<=b&&b<=1)?new Lt("Intersection").append(new D(t.x+_*a,t.y+_*h)):new Lt}if(f===0||p===0){const _=n||r||Lt.isPointContained(t,s,i)||Lt.isPointContained(e,s,i)||Lt.isPointContained(s,t,e)||Lt.isPointContained(i,t,e);return new Lt(_?"Coincident":void 0)}return new Lt("Parallel")}static intersectSegmentLine(t,e,s,i){return Lt.intersectLineLine(t,e,s,i,!1,!0)}static intersectSegmentSegment(t,e,s,i){return Lt.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 Lt,r=s.length;for(let a,h,l,u=0;u<r;u++){if(a=s[u],h=s[(u+1)%r],l=Lt.intersectLineLine(t,e,a,h,i,!1),l.status==="Coincident")return l;n.append(...l.points)}return n.points.length>0&&(n.status="Intersection"),n}static intersectSegmentPolygon(t,e,s){return Lt.intersectLinePolygon(t,e,s,!1)}static intersectPolygonPolygon(t,e){const s=new Lt,i=t.length,n=[];for(let r=0;r<i;r++){const a=t[r],h=t[(r+1)%i],l=Lt.intersectSegmentPolygon(a,h,e);l.status==="Coincident"?(n.push(l),s.append(a,h)):s.append(...l.points)}return n.length>0&&n.length===t.length?new Lt("Coincident"):(s.points.length>0&&(s.status="Intersection"),s)}static intersectPolygonRectangle(t,e,s){const i=e.min(s),n=e.max(s),r=new D(n.x,i.y),a=new D(i.x,n.y);return Lt.intersectPolygonPolygon(t,[i,r,n,a])}}class s_ extends Hp{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?we(t,this.group.calcTransformMatrix()):t}setXY(t,e,s){this.group&&(t=we(t,qe(this.group.calcTransformMatrix()))),this.setRelativeXY(t,e,s)}getRelativeXY(){return new D(this.left,this.top)}setRelativeXY(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.originX,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.originY;this.setPositionByOrigin(t,e,s)}isStrokeAccountedForInDimensions(){return!1}getCoords(){const{tl:t,tr:e,br:s,bl:i}=this.aCoords||(this.aCoords=this.calcACoords()),n=[t,e,s,i];if(this.group){const r=this.group.calcTransformMatrix();return n.map(a=>we(a,r))}return n}intersectsWithRect(t,e){return Lt.intersectPolygonRectangle(this.getCoords(),t,e).status==="Intersection"}intersectsWithObject(t){const e=Lt.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 Lt.isPointInPolygon(t,this.getCoords())}isOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return!!this.getCoords().some(s=>s.x<=e.x&&s.x>=t.x&&s.y<=e.y&&s.y>=t.y)||!!this.intersectsWithRect(t,e)||this.containsPoint(t.midPointFrom(e))}isPartiallyOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return this.intersectsWithRect(t,e)?!0:this.getCoords().every(s=>(s.x>=e.x||s.x<=t.x)&&(s.y>=e.y||s.y<=t.y))&&this.containsPoint(t.midPointFrom(e))}getBoundingRect(){return hi(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(Fe,t),this._set(is,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?kn(Vp(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.viewportTransform)||De.concat()}calcACoords(){const t=Xa({angle:this.angle}),{x:e,y:s}=this.getRelativeCenterPoint(),i=Wa(e,s),n=Gt(i,t),r=this._getTransformedDimensions(),a=r.x/2,h=r.y/2;return{tl:we({x:-a,y:-h},n),tr:we({x:a,y:-h},n),bl:we({x:-a,y:h},n),br:we({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,Kt(this.originX),Kt(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=Gt(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=Yp(i);return this.ownMatrixCache={key:t,value:n},n}_getNonTransformedDimensions(){return new D(this.width,this.height).scalarAdd(this.strokeWidth)}_calculateCurrentDimensions(t){return this._getTransformedDimensions(t).transform(this.getViewportTransform(),!0).scalarAdd(2*this.padding)}_getTransformedDimensions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=E({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,width:this.width,height:this.height,strokeWidth:this.strokeWidth},t),s=e.strokeWidth;let i=s,n=0;this.strokeUniform&&(i=0,n=s);const r=e.width+i,a=e.height+i;let h;return h=e.skewX===0&&e.skewY===0?new D(r*e.scaleX,a*e.scaleY):Pc(r,a,ph(e)),h.scalarAdd(n)}translateToGivenOrigin(t,e,s,i,n){let r=t.x,a=t.y;const h=Kt(i)-Kt(e),l=Kt(n)-Kt(s);if(h||l){const u=this._getTransformedDimensions();r+=h*u.x,a+=l*u.y}return new D(r,a)}translateToCenterPoint(t,e,s){if(e===st&&s===st)return t;const i=this.translateToGivenOrigin(t,e,s,st,st);return this.angle?i.rotate(Wt(this.angle),t):i}translateToOriginPoint(t,e,s){const i=this.translateToGivenOrigin(t,st,st,e,s);return this.angle?i.rotate(Wt(this.angle),t):i}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?we(t,this.group.calcTransformMatrix()):t}getRelativeCenterPoint(){return this.translateToCenterPoint(new D(this.left,this.top),this.originX,this.originY)}getPointByOrigin(t,e){return this.translateToOriginPoint(this.getRelativeCenterPoint(),t,e)}setPositionByOrigin(t,e,s){const i=this.translateToCenterPoint(t,e,s),n=this.translateToOriginPoint(i,this.originX,this.originY);this.set({left:n.x,top:n.y})}_getLeftTopCoords(){return this.translateToOriginPoint(this.getRelativeCenterPoint(),mt,Ue)}}const i_=["type"],n_=["extraParam"];let Li=class ad extends s_{static getDefaults(){return ad.ownDefaults}get type(){const t=this.constructor.type;return t==="FabricObject"?"object":t.toLowerCase()}set type(t){Pi("warn","Setting type has no effect",t)}constructor(t){super(),T(this,"_cacheContext",null),Object.assign(this,ad.ownDefaults),this.setOptions(t)}_createCacheCanvas(){this._cacheCanvas=vs(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,s=t.height,i=dt.maxCacheSideLimit,n=dt.minCacheSideLimit;if(e<=i&&s<=i&&e*s<=dt.perfLimitSizeTotal)return e<n&&(t.width=n),s<n&&(t.height=n),t;const r=e/s,[a,h]=dh.limitDimsByArea(r),l=yr(n,a,i),u=yr(n,h,i);return e>l&&(t.zoomX/=e/l,t.width=l,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:s+2,height:i+2,zoomX:t.x,zoomY:t.y,x:s,y:i}}_updateCacheCanvas(){const t=this._cacheCanvas,e=this._cacheContext,s=this._limitCacheSize(this._getCacheCanvasDimensions()),i=dt.minCacheSideLimit,n=s.width,r=s.height,a=s.zoomX,h=s.zoomY,l=n!==t.width||r!==t.height,u=this.zoomX!==a||this.zoomY!==h;if(!t||!e)return!1;let d,g,f=l||u,p=0,m=0,_=!1;if(l){const b=this._cacheCanvas.width,x=this._cacheCanvas.height,S=n>b||r>x;_=S||(n<.9*b||r<.9*x)&&b>i&&x>i,S&&!s.capped&&(n>i||r>i)&&(p=.1*n,m=.1*r)}return Zp(this)&&this.path&&(f=!0,_=!0,p+=this.getHeightOfLine(0)*this.zoomX,m+=this.getHeightOfLine(0)*this.zoomY),!!f&&(_?(t.width=Math.ceil(n+p),t.height=Math.ceil(r+m)):(e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,t.width,t.height)),d=s.x/2,g=s.y/2,this.cacheTranslationX=Math.round(t.width/2-d)+d,this.cacheTranslationY=Math.round(t.height/2-g)+g,e.translate(this.cacheTranslationX,this.cacheTranslationY),e.scale(a,h),this.zoomX=a,this.zoomY=h,!0)}setOptions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this._setOptions(t)}transform(t){const e=this.group&&!this.group._transformDone||this.group&&this.canvas&&t===this.canvas.contextTop,s=this.calcTransformMatrix(!e);t.transform(s[0],s[1],s[2],s[3],s[4],s[5])}getObjectScaling(){if(!this.group)return new D(Math.abs(this.scaleX),Math.abs(this.scaleY));const t=pr(this.calcTransformMatrix());return new D(Math.abs(t.scaleX),Math.abs(t.scaleY))}getTotalObjectScaling(){const t=this.getObjectScaling();if(this.canvas){const e=this.canvas.getZoom(),s=this.getCanvasRetinaScaling();return t.scalarMultiply(e*s)}return t}getObjectOpacity(){let t=this.opacity;return this.group&&(t*=this.group.getObjectOpacity()),t}_constrainScale(t){return Math.abs(t)<this.minScaleLimit?t<0?-this.minScaleLimit:this.minScaleLimit:t===0?1e-4:t}_set(t,e){t!==Fe&&t!==is||(e=this._constrainScale(e)),t===Fe&&e<0?(this.flipX=!this.flipX,e*=-1):t==="scaleY"&&e<0?(this.flipY=!this.flipY,e*=-1):t!=="shadow"||!e||e instanceof Ri||(e=new Ri(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===Le&&this.hasFill()&&this.hasStroke()&&this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.needsItsOwnCache()||this.objectCaching&&(!this.parent||!this.parent.isOnACache()),this.ownCaching}willDrawShadow(){return!!this.shadow&&(this.shadow.offsetX!==0||this.shadow.offsetY!==0)}drawClipPathOnCache(t,e,s){t.save(),e.inverted?t.globalCompositeOperation="destination-out":t.globalCompositeOperation="destination-in",t.setTransform(1,0,0,1,0,0),t.drawImage(s,0,0),t.restore()}drawObject(t,e,s){const i=this.fill,n=this.stroke;e?(this.fill="black",this.stroke="",this._setClippingProperties(t)):this._renderBackground(t),this._render(t),this._drawClipPath(t,this.clipPath,s),this.fill=i,this.stroke=n}createClipPathLayer(t,e){const s=Is(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=qe(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,bs(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&&(bs(s)?(t.fillStyle=s.toLive(t),this._applyPatternGradientTransform(t,s)):t.fillStyle=s)}_setClippingProperties(t){t.globalAlpha=1,t.strokeStyle="transparent",t.fillStyle="#000000"}_setLineDash(t,e){e&&e.length!==0&&(1&e.length&&e.push(...e),t.setLineDash(e))}_setShadow(t){if(!this.shadow)return;const e=this.shadow,s=this.canvas,i=this.getCanvasRetinaScaling(),[n,,,r]=(s==null?void 0:s.viewportTransform)||De,a=n*i,h=r*i,l=e.nonScaling?new D(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*dt.browserShadowBlurConstant*(a+h)*(l.x+l.y)/4,t.shadowOffsetX=e.offsetX*a*l.x,t.shadowOffsetY=e.offsetY*h*l.y}_removeShadow(t){this.shadow&&(t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0)}_applyPatternGradientTransform(t,e){if(!bs(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===Le?(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=Is({width:Math.ceil(r),height:Math.ceil(a)}),l=h.getContext("2d");l&&(l.beginPath(),l.moveTo(0,0),l.lineTo(r,0),l.lineTo(r,a),l.lineTo(0,a),l.closePath(),l.translate(r/2,a/2),l.scale(i.zoomX/this.scaleX/n,i.zoomY/this.scaleY/n),this._applyPatternGradientTransform(l,e),l.fillStyle=e.toLive(t),l.fill(),t.translate(-this.width/2-this.strokeWidth/2,-this.height/2-this.strokeWidth/2),t.scale(n*this.scaleX/i.zoomX,n*this.scaleY/i.zoomY),t.strokeStyle=(s=l.createPattern(h,"no-repeat"))!==null&&s!==void 0?s:"")}_findCenterFromElement(){return new D(this.left+this.width/2,this.top+this.height/2)}clone(t){const e=this.toObject(t);return this.constructor.fromObject(e)}cloneAsImage(t){const e=this.toCanvasElement(t);return new(V.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=Zd(this),s=this.group,i=this.shadow,n=Math.abs,r=t.enableRetinaScaling?Lp():1,a=(t.multiplier||1)*r,h=t.canvasProvider||(x=>new _h(x,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&om(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&tg(this,this.getViewportTransform()),this.setCoords();const l=vs(),u=this.getBoundingRect(),d=this.shadow,g=new D;if(d){const x=d.blur,S=d.nonScaling?new D(1,1):this.getObjectScaling();g.x=2*Math.round(n(d.offsetX)+x)*n(S.x),g.y=2*Math.round(n(d.offsetY)+x)*n(S.y)}const f=u.width+g.x,p=u.height+g.y;l.width=Math.ceil(f),l.height=Math.ceil(p);const m=h(l);t.format==="jpeg"&&(m.backgroundColor="#fff"),this.setPositionByOrigin(new D(m.width/2,m.height/2),st,st);const _=this.canvas;m._objects=[this],this.set("canvas",m),this.setCoords();const b=m.toCanvasElement(a||1,t);return this.set("canvas",_),this.shadow=i,s&&(this.group=s),this.set(e),this.setCoords(),m._objects=[],m.destroy(),b}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return Gd(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=st,this.originY=st,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(){Ac.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&oi().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:l}=s,u=E(E({},s),{},{target:this,startValue:a??i.reduce((d,g)=>d[g],this),endValue:e,abort:r==null?void 0:r.bind(this),onChange:(d,g,f)=>{i.reduce((p,m,_)=>(_===i.length-1&&(p[m]=d),p[m]),this),h&&h(d,g,f)},onComplete:(d,g,f)=>{this.setCoords(),l&&l(d,g,f)}});return n?Tm(u):dg(u)}isDescendantOf(t){const{parent:e,group:s}=this;return e===t||s===t||!!e&&e.isDescendantOf(t)||!!s&&s!==e&&s.isDescendantOf(t)}getAncestors(){const t=[];let e=this;do e=e.parent,e&&t.push(e);while(e);return t}findCommonAncestors(t){if(this===t)return{fork:[],otherFork:[],common:[this,...this.getAncestors()]};const e=this.getAncestors(),s=t.getAncestors();if(e.length===0&&s.length>0&&this===s[s.length-1])return{fork:[],otherFork:[t,...s.slice(0,s.length-1)],common:[this]};for(let i,n=0;n<e.length;n++){if(i=e[n],i===t)return{fork:[this,...e.slice(0,n)],otherFork:[],common:e.slice(n)};for(let r=0;r<s.length;r++){if(this===s[r])return{fork:[],otherFork:[t,...s.slice(0,r)],common:[this,...e]};if(i===s[r])return{fork:[this,...e.slice(0,n)],otherFork:[t,...s.slice(0,r)],common:e.slice(n)}}}return{fork:[this,...e],otherFork:[t,...s],common:[]}}hasCommonAncestors(t){const e=this.findCommonAncestors(t);return e&&!!e.common.length}isInFrontOf(t){if(this===t)return;const e=this.findCommonAncestors(t);if(e.fork.includes(t))return!0;if(e.otherFork.includes(this))return!1;const s=e.common[0]||this.canvas;if(!s)return;const i=e.fork.pop(),n=e.otherFork.pop(),r=s._objects.indexOf(i),a=s._objects.indexOf(n);return r>-1&&r>a}toObject(){const t=(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).concat(ad.customProperties,this.constructor.customProperties||[]);let e;const s=dt.NUM_FRACTION_DIGITS,{clipPath:i,fill:n,stroke:r,shadow:a,strokeDashArray:h,left:l,top:u,originX:d,originY:g,width:f,height:p,strokeWidth:m,strokeLineCap:_,strokeDashOffset:b,strokeLineJoin:x,strokeUniform:S,strokeMiterLimit:A,scaleX:k,scaleY:P,angle:M,flipX:O,flipY:R,opacity:I,visible:j,backgroundColor:G,fillRule:L,paintFirst:H,globalCompositeOperation:$,skewX:J,skewY:Y}=this;i&&!i.excludeFromExport&&(e=i.toObject(t.concat("inverted","absolutePositioned")));const X=zt=>Dt(zt,s),Ot=E(E({},mr(this,t)),{},{type:this.constructor.type,version:jd,originX:d,originY:g,left:X(l),top:X(u),width:X(f),height:X(p),fill:Jp(n)?n.toObject():n,stroke:Jp(r)?r.toObject():r,strokeWidth:X(m),strokeDashArray:h&&h.concat(),strokeLineCap:_,strokeDashOffset:b,strokeLineJoin:x,strokeUniform:S,strokeMiterLimit:X(A),scaleX:X(k),scaleY:X(P),angle:X(M),flipX:O,flipY:R,opacity:X(I),shadow:a&&a.toObject(),visible:j,backgroundColor:G,fillRule:L,paintFirst:H,globalCompositeOperation:$,skewX:X(J),skewY:X(Y)},e?{clipPath:e}:null);return this.includeDefaultValues?Ot:this._removeDefaultValues(Ot)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),s=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return qd(t,(i,n)=>{if(n===mt||n===Ue||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=Pt(t,i_),s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{extraParam:i}=s,n=Pt(s,n_);return vh(e,n).then(r=>i?(delete r[i],new this(e[i],r)):new this(r))}static fromObject(t,e){return this._fromObject(t,e)}};T(Li,"stateProperties",Gy),T(Li,"cacheProperties",Fi),T(Li,"ownDefaults",Yy),T(Li,"type","FabricObject"),T(Li,"colorProperties",[$t,Le,"backgroundColor"]),T(Li,"customProperties",[]),V.setClass(Li),V.setClass(Li,"object");const Ya=(o,t,e)=>(s,i,n,r)=>{const a=t(s,i,n,r);return a&&lm(o,E(E({},dm(s,i,n,r)),e)),a};function Ua(o){return(t,e,s,i)=>{const{target:n,originX:r,originY:a}=e,h=n.getRelativeCenterPoint(),l=n.translateToOriginPoint(h,r,a),u=o(t,e,s,i);return n.setPositionByOrigin(l,e.originX,e.originY),u}}const Em=Ya(gh,Ua((o,t,e,s)=>{const i=eg(t,t.originX,t.originY,e,s);if(Kt(t.originX)===Kt(st)||Kt(t.originX)===Kt(Vt)&&i.x<0||Kt(t.originX)===Kt(mt)&&i.x>0){const{target:n}=t,r=n.strokeWidth/(n.strokeUniform?n.scaleX:1),a=cm(t)?2:1,h=n.width,l=Math.abs(i.x*a/n.scaleX)-r;return n.set("width",Math.max(l,1)),h!==n.width}return!1}));function r_(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?Le:$t,l=!a&&(s.cornerStrokeColor||i.cornerStrokeColor);let u,d=t,g=e;o.save(),o.fillStyle=s.cornerColor||i.cornerColor||"",o.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",n>r?(u=n,o.scale(1,r/n),g=e*n/r):r>n?(u=r,o.scale(n/r,1),d=t*r/n):u=n,o.lineWidth=1,o.beginPath(),o.arc(d,g,u/2,0,Di,!1),o[h](),l&&o.stroke(),o.restore()}function a_(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?Le:$t,l=!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.lineWidth=1,o.translate(t,e);const g=i.getTotalAngle();o.rotate(Wt(g)),o["".concat(h,"Rect")](-u,-d,n,r),l&&o.strokeRect(-u,-d,n,r),o.restore()}class Hs{constructor(t){T(this,"visible",!0),T(this,"actionName",Sc),T(this,"angle",0),T(this,"x",0),T(this,"y",0),T(this,"offsetX",0),T(this,"offsetY",0),T(this,"sizeX",0),T(this,"sizeY",0),T(this,"touchSizeX",0),T(this,"touchSizeY",0),T(this,"cursorStyle","crosshair"),T(this,"withConnection",!1),Object.assign(this,t)}shouldActivate(t,e,s,i){var n;let{tl:r,tr:a,br:h,bl:l}=i;return((n=e.canvas)===null||n===void 0?void 0:n.getActiveObject())===e&&e.isControlVisible(t)&&Lt.isPointInPolygon(s,[r,a,h,l])}getActionHandler(t,e,s){return this.actionHandler}getMouseDownHandler(t,e,s){return this.mouseDownHandler}getMouseUpHandler(t,e,s){return this.mouseUpHandler}cursorStyleHandler(t,e,s){return e.cursorStyle}getActionName(t,e,s){return e.actionName}getVisibility(t,e){var s,i;return(s=(i=t._controlsVisibility)===null||i===void 0?void 0:i[e])!==null&&s!==void 0?s:this.visible}setVisibility(t,e,s){this.visible=t}positionHandler(t,e,s,i){return new D(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(e)}calcCornerCoords(t,e,s,i,n,r){const a=Ec([Wa(s,i),Xa({angle:t}),kc((n?this.touchSizeX:this.sizeX)||e,(n?this.touchSizeY:this.sizeY)||e)]);return{tl:new D(-.5,-.5).transform(a),tr:new D(.5,-.5).transform(a),br:new D(.5,.5).transform(a),bl:new D(-.5,.5).transform(a)}}render(t,e,s,i,n){((i=i||{}).cornerStyle||n.cornerStyle)==="circle"?r_.call(this,t,e,s,i,n):a_.call(this,t,e,s,i,n)}}const o_=(o,t,e)=>e.lockRotation?Dc:t.cursorStyle,h_=Ya(jp,Ua((o,t,e,s)=>{let{target:i,ex:n,ey:r,theta:a,originX:h,originY:l}=t;const u=i.translateToOriginPoint(i.getRelativeCenterPoint(),h,l);if(Ns(i,"lockRotation"))return!1;const d=Math.atan2(r-u.y,n-u.x),g=Math.atan2(s-u.y,e-u.x);let f=kn(g-d+a);if(i.snapAngle&&i.snapAngle>0){const m=i.snapAngle,_=i.snapThreshold||m,b=Math.ceil(f/m)*m,x=Math.floor(f/m)*m;Math.abs(f-x)<_?f=x:Math.abs(f-b)<_&&(f=b)}f<0&&(f=360+f),f%=360;const p=i.angle!==f;return i.angle=f,p}));function km(o,t){const e=t.canvas,s=o[e.uniScaleKey];return e.uniformScaling&&!s||!e.uniformScaling&&s}function Mm(o,t,e){const s=Ns(o,"lockScalingX"),i=Ns(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 l_=["e","se","s","sw","w","nw","n","ne","e"],xh=(o,t,e)=>{const s=km(o,e);if(Mm(e,t.x!==0&&t.y===0?"x":t.x===0&&t.y!==0?"y":"",s))return Dc;const i=gm(e,t);return"".concat(l_[i],"-resize")};function gg(o,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{};const n=t.target,r=i.by,a=km(o,n);let h,l,u,d,g,f;if(Mm(n,r,a))return!1;if(t.gestureScale)l=t.scaleX*t.gestureScale,u=t.scaleY*t.gestureScale;else{if(h=eg(t,t.originX,t.originY,e,s),g=r!=="y"?Math.sign(h.x||t.signX||1):1,f=r!=="x"?Math.sign(h.y||t.signY||1):1,t.signX||(t.signX=g),t.signY||(t.signY=f),Ns(n,"lockScalingFlip")&&(t.signX!==g||t.signY!==f))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));l=b.scaleX*x,u=b.scaleY*x}else l=Math.abs(h.x*n.scaleX/d.x),u=Math.abs(h.y*n.scaleY/d.y);cm(t)&&(l*=2,u*=2),t.signX!==g&&r!=="y"&&(t.originX=um(t.originX),l*=-1,t.signX=g),t.signY!==f&&r!=="x"&&(t.originY=um(t.originY),u*=-1,t.signY=f)}const p=n.scaleX,m=n.scaleY;return r?(r==="x"&&n.set(Fe,l),r==="y"&&n.set(is,u)):(!Ns(n,"lockScalingX")&&n.set(Fe,l),!Ns(n,"lockScalingY")&&n.set(is,u)),p!==n.scaleX||m!==n.scaleY}const Nc=Ya(wc,Ua((o,t,e,s)=>gg(o,t,e,s))),c_=Ya(wc,Ua((o,t,e,s)=>gg(o,t,e,s,{by:"x"}))),u_=Ya(wc,Ua((o,t,e,s)=>gg(o,t,e,s,{by:"y"}))),d_=["target","ex","ey","skewingSide"],fg={x:{counterAxis:"y",scale:Fe,skew:Na,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:is,skew:Ba,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},g_=["ns","nesw","ew","nwse"],f_=(o,t,e)=>{if(t.x!==0&&Ns(e,"lockSkewingY")||t.y!==0&&Ns(e,"lockSkewingX"))return Dc;const s=gm(e,t)%4;return"".concat(g_[s],"-resize")};function Om(o,t,e,s,i){const{target:n}=e,{counterAxis:r,origin:a,lockSkewing:h,skew:l,flip:u}=fg[o];if(Ns(n,h))return!1;const{origin:d,flip:g}=fg[r],f=Kt(e[d])*(n[g]?-1:1),p=-Math.sign(f)*(n[u]?-1:1),m=.5*-((n[l]===0&&eg(e,st,st,s,i)[o]>0||n[l]>0?1:-1)*p)+.5;return Ya(Np,Ua((b,x,S,A)=>function(k,P,M){let{target:O,ex:R,ey:I,skewingSide:j}=P,G=Pt(P,d_);const{skew:L}=fg[k],H=M.subtract(new D(R,I)).divide(new D(O.scaleX,O.scaleY))[k],$=O[L],J=G[L],Y=Math.tan(Wt(J)),X=k==="y"?O._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:O._getTransformedDimensions({scaleX:1,scaleY:1}).y,Ot=2*H*j/Math.max(X,1)+Y,zt=kn(Math.atan(Ot));O.set(L,zt);const te=$!==O[L];if(te&&k==="y"){const{skewX:Ht,scaleX:At}=O,_e=O._getTransformedDimensions({skewY:$}),Ps=O._getTransformedDimensions(),kt=Ht!==0?_e.x/Ps.x:1;kt!==1&&O.set(Fe,kt*At)}return te}(o,x,new D(S,A))))(t,E(E({},e),{},{[a]:m,skewingSide:p}),s,i)}const p_=(o,t,e,s)=>Om("x",o,t,e,s),m_=(o,t,e,s)=>Om("y",o,t,e,s);function Bc(o,t){return o[t.canvas.altActionKey]}const Hc=(o,t,e)=>{const s=Bc(o,e);return t.x===0?s?Na:is:t.y===0?s?Ba:Fe:""},qa=(o,t,e)=>Bc(o,e)?f_(0,t,e):xh(o,t,e),Pm=(o,t,e,s)=>Bc(o,t.target)?m_(o,t,e,s):c_(o,t,e,s),Dm=(o,t,e,s)=>Bc(o,t.target)?p_(o,t,e,s):u_(o,t,e,s),Rm=()=>({ml:new Hs({x:-.5,y:0,cursorStyleHandler:qa,actionHandler:Pm,getActionName:Hc}),mr:new Hs({x:.5,y:0,cursorStyleHandler:qa,actionHandler:Pm,getActionName:Hc}),mb:new Hs({x:0,y:.5,cursorStyleHandler:qa,actionHandler:Dm,getActionName:Hc}),mt:new Hs({x:0,y:-.5,cursorStyleHandler:qa,actionHandler:Dm,getActionName:Hc}),tl:new Hs({x:-.5,y:-.5,cursorStyleHandler:xh,actionHandler:Nc}),tr:new Hs({x:.5,y:-.5,cursorStyleHandler:xh,actionHandler:Nc}),bl:new Hs({x:-.5,y:.5,cursorStyleHandler:xh,actionHandler:Nc}),br:new Hs({x:.5,y:.5,cursorStyleHandler:xh,actionHandler:Nc}),mtr:new Hs({x:0,y:-.5,actionHandler:h_,cursorStyleHandler:o_,offsetY:-40,withConnection:!0,actionName:Xd})}),v_=()=>({mr:new Hs({x:.5,y:0,actionHandler:Em,cursorStyleHandler:qa,actionName:gh}),ml:new Hs({x:-.5,y:0,actionHandler:Em,cursorStyleHandler:qa,actionName:gh})}),b_=()=>E(E({},Rm()),v_());class Sh extends Li{static getDefaults(){return E(E({},super.getDefaults()),Sh.ownDefaults)}constructor(t){super(),Object.assign(this,this.constructor.createControls(),Sh.ownDefaults),this.setOptions(t)}static createControls(){return{controls:Rm()}}_updateCacheCanvas(){const t=this.canvas;if(this.noScaleCache&&t&&t._currentTransform){const e=t._currentTransform,s=e.target,i=e.action;if(this===s&&i&&i.startsWith(Sc))return!1}return super._updateCacheCanvas()}getActiveControl(){const t=this.__corner;return t?{key:t,control:this.controls[t],coord:this.oCoords[t]}:void 0}findControl(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];if(!this.hasControls||!this.canvas)return;this.__corner=void 0;const s=Object.entries(this.oCoords);for(let i=s.length-1;i>=0;i--){const[n,r]=s[i],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=Wa(e.x,e.y),i=Xa({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),n=Gt(s,i),r=Gt(t,n),a=Gt(r,[1/t[0],0,0,1/t[3],0,0]),h=this.group?pr(this.calcTransformMatrix()):void 0;h&&(h.scaleX=Math.abs(h.scaleX),h.scaleY=Math.abs(h.scaleY));const l=this._calculateCurrentDimensions(h),u={};return this.forEachControl((d,g)=>{const f=d.positionHandler(l,a,this,d);u[g]=Object.assign(f,this._calcCornerCoords(d,f))}),u}_calcCornerCoords(t,e){const s=this.getTotalAngle();return{corner:t.calcCornerCoords(s,this.cornerSize,e.x,e.y,!1,this),touchCorner:t.calcCornerCoords(s,this.touchCornerSize,e.x,e.y,!0,this)}}setCoords(){super.setCoords(),this.canvas&&(this.oCoords=this.calcOCoords())}forEachControl(t){for(const e in this.controls)t(this.controls[e],e,this)}drawSelectionBackground(t){if(!this.selectionBackgroundColor||this.canvas&&this.canvas._activeObject!==this)return;t.save();const e=this.getRelativeCenterPoint(),s=this._calculateCurrentDimensions(),i=this.getViewportTransform();t.translate(e.x,e.y),t.scale(1/i[0],1/i[3]),t.rotate(Wt(this.angle)),t.fillStyle=this.selectionBackgroundColor,t.fillRect(-s.x/2,-s.y/2,s.x,s.y),t.restore()}strokeBorders(t,e){t.strokeRect(-e.x/2,-e.y/2,e.x,e.y)}_drawBorders(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const i=E({hasControls:this.hasControls,borderColor:this.borderColor,borderDashArray:this.borderDashArray},s);t.save(),t.strokeStyle=i.borderColor,this._setLineDash(t,i.borderDashArray),this.strokeBorders(t,e),i.hasControls&&this.drawControlsConnectingLines(t,e),t.restore()}_renderControls(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const{hasBorders:s,hasControls:i}=this,n=E({hasBorders:s,hasControls:i},e),r=this.getViewportTransform(),a=n.hasBorders,h=n.hasControls,l=Gt(r,this.calcTransformMatrix()),u=pr(l);t.save(),t.translate(u.translateX,u.translateY),t.lineWidth=1*this.borderScaleFactor,this.group===this.parent&&(t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1),this.flipX&&(u.angle-=180),t.rotate(Wt(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=Pc(this.width,this.height,ph(e)),r=this.isStrokeAccountedForInDimensions()?Vd:(this.strokeUniform?new D().scalarAdd(this.canvas?this.canvas.getZoom():1):new D(e.scaleX,e.scaleY)).scalarMultiply(this.strokeWidth);i=n.add(r).scalarAdd(this.borderScaleFactor).scalarAdd(2*this.padding)}else i=this._calculateCurrentDimensions().scalarAdd(this.borderScaleFactor);this._drawBorders(t,i,s)}drawControlsConnectingLines(t,e){let s=!1;t.beginPath(),this.forEachControl((i,n)=>{i.withConnection&&i.getVisibility(this,n)&&(s=!0,t.moveTo(i.x*e.x,i.y*e.y),t.lineTo(i.x*e.x+i.offsetX,i.y*e.y+i.offsetY))}),s&&t.stroke()}drawControls(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};t.save();const s=this.getCanvasRetinaScaling(),{cornerStrokeColor:i,cornerDashArray:n,cornerColor:r}=this,a=E({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,l)=>{if(h.getVisibility(this,l)){const u=this.oCoords[l];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 Fm(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}T(Sh,"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 xe extends Sh{}Fm(xe,[fm]),V.setClass(xe),V.setClass(xe,"object");const Lm=(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 Im{constructor(t){this.options=t,this.strokeProjectionMagnitude=this.options.strokeWidth/2,this.scale=new D(this.options.scaleX,this.options.scaleY),this.strokeUniformScalar=this.options.strokeUniform?new D(1/this.options.scaleX,1/this.options.scaleY):new D(1,1)}createSideVector(t,e){const s=Fc(t,e);return this.options.strokeUniform?s.multiply(this.scale):s}projectOrthogonally(t,e,s){return this.applySkew(t.add(this.calcOrthogonalProjection(t,e,s)))}isSkewed(){return this.options.skewX!==0||this.options.skewY!==0}applySkew(t){const e=new D(t);return e.y+=e.x*Math.tan(Wt(this.options.skewY)),e.x+=e.y*Math.tan(Wt(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}const y_=new D;class $a extends Im{static getOrthogonalRotationFactor(t,e){const s=e?Ic(t,e):ym(t);return Math.abs(s)<An?-1:1}constructor(t,e,s,i){super(i),T(this,"AB",void 0),T(this,"AC",void 0),T(this,"alpha",void 0),T(this,"bisector",void 0),this.A=new D(t),this.B=new D(e),this.C=new D(s),this.AB=this.createSideVector(this.A,this.B),this.AC=this.createSideVector(this.A,this.C),this.alpha=Ic(this.AB,this.AC),this.bisector=jc(rg(this.AB.eq(y_)?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=ag(i),r=$a.getOrthogonalRotationFactor(n,this.bisector);return this.scaleUnitVector(n,s*r)}projectBevel(){const t=[];return(this.alpha%Di==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?Lc(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return Lc(i)/this.strokeProjectionMagnitude<=n&&t.push(this.applySkew(this.A.add(i))),t.push(...this.projectBevel()),t}projectRoundNoSkew(t,e){const s=[],i=new D($a.getOrthogonalRotationFactor(this.bisector),$a.getOrthogonalRotationFactor(new D(this.bisector.y,this.bisector.x)));return[new D(1,0).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i),new D(0,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i)].forEach(n=>{og(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,l=new D(Math.tan(Wt(i)),Math.tan(Wt(n))),u=this.strokeProjectionMagnitude,d=h?u/a/Math.sqrt(1/a**2+1/r**2*l.y**2):u/Math.sqrt(1+l.y**2),g=new D(Math.sqrt(Math.max(u**2-d**2,0)),d),f=h?u/Math.sqrt(1+l.x**2*(1/a)**2/(1/r+1/r*l.x*l.y)**2):u/Math.sqrt(1+l.x**2/(1+l.x*l.y)**2),p=new D(f,Math.sqrt(Math.max(u**2-f**2,0)));return[p,p.scalarMultiply(-1),g,g.scalarMultiply(-1)].map(m=>this.applySkew(h?m.multiply(this.strokeUniformScalar):m)).forEach(m=>{og(m,t,e)&&s.push(this.applySkew(this.A).add(m))}),s}projectRound(){const t=[];t.push(...this.projectBevel());const e=this.alpha%Di==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=Ga(i,r)>0,h=a?i:n,l=a?n:i;return this.isSkewed()?t.push(...this.projectRoundWithSkew(h,l)):t.push(...this.projectRoundNoSkew(h,l)),t}projectPoints(){switch(this.options.strokeLineJoin){case"miter":return this.projectMiter();case"round":return this.projectRound();default:return this.projectBevel()}}project(){return this.projectPoints().map(t=>({originPoint:this.A,projectedPoint:t,angle:this.alpha,bisector:this.bisector}))}}class jm extends Im{constructor(t,e,s){super(s),this.A=new D(t),this.T=new D(e)}calcOrthogonalProjection(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.strokeProjectionMagnitude;const i=this.createSideVector(t,e);return this.scaleUnitVector(ag(i),s)}projectButt(){return[this.projectOrthogonally(this.A,this.T,this.strokeProjectionMagnitude),this.projectOrthogonally(this.A,this.T,-this.strokeProjectionMagnitude)]}projectRound(){const t=[];if(!this.isSkewed()&&this.A.eq(this.T)){const e=new D(1,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar);t.push(this.applySkew(this.A.add(e)),this.applySkew(this.A.subtract(e)))}else t.push(...new $a(this.A,this.T,this.T,this.options).projectRound());return t}projectSquare(){const t=[];if(this.A.eq(this.T)){const e=new D(1,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar);t.push(this.A.add(e),this.A.subtract(e))}else{const e=this.calcOrthogonalProjection(this.A,this.T,this.strokeProjectionMagnitude),s=this.scaleUnitVector(jc(this.createSideVector(this.A,this.T)),-this.strokeProjectionMagnitude),i=this.A.add(s);t.push(i.add(e),i.subtract(e))}return t.map(e=>this.applySkew(e))}projectPoints(){switch(this.options.strokeLineCap){case"round":return this.projectRound();case"square":return this.projectSquare();default:return this.projectButt()}}project(){return this.projectPoints().map(t=>({originPoint:this.A,projectedPoint:t}))}}const Nm=function(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 D(r)),n),[new D(o[0])]);if(i.length===1)e=!0;else if(!e){const n=i[0],r=((a,h)=>{for(let l=a.length-1;l>=0;l--)if(h(a[l],l,a))return l;return-1})(i,a=>!a.eq(n));i.splice(r+1)}return i.forEach((n,r,a)=>{let h,l;r===0?(l=a[1],h=e?n:a[a.length-1]):r===a.length-1?(h=a[r-1],l=e?n:a[0]):(h=a[r-1],l=a[r+1]),e&&a.length===1?s.push(...new jm(n,n,t).project()):!e||r!==0&&r!==a.length-1?s.push(...new $a(n,h,l,t).project()):s.push(...new jm(n,r===0?l:h,t).project())}),s},pg=o=>{const t={};return Object.keys(o).forEach(e=>{t[e]={},Object.keys(o[e]).forEach(s=>{t[e][s]=E({},o[e][s])})}),t},Bm=o=>o.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">"),Wc=o=>{const t=[];for(let e,s=0;s<o.length;s++)(e=__(o,s))!==!1&&t.push(e);return t},__=(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 w_=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:Bm,graphemeSplit:Wc});const Xc=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)},Hm=(o,t)=>{const e=t.split(`
|
|
67
|
-
`),s=[];let i=-1,n={};
|
|
68
|
-
`)]}static async fromElement(t,e,s){const i=Ii(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,width:a=0,height:h=0,visible:l=!0}=i,u=Pt(i,W_);return new this(E(E(E({},e),u),{},{left:n,top:r,width:a,height:h,visible:!!(l&&a&&h)}))}}T(li,"type","Rect"),T(li,"cacheProperties",[...Fi,...Km]),T(li,"ownDefaults",{rx:0,ry:0}),T(li,"ATTRIBUTE_NAMES",[...Mn,"x","y","rx","ry","width","height"]),V.setClass(li),V.setSVGClass(li);const ji="initialization",Vc="added",bg="removed",Gc="imperative",Jm=(o,t)=>{const{strokeUniform:e,strokeWidth:s,width:i,height:n,group:r}=t,a=r&&r!==o?wh(r.calcTransformMatrix(),o.calcTransformMatrix()):null,h=a?t.getRelativeCenterPoint().transform(a):t.getRelativeCenterPoint(),l=!t.isStrokeAccountedForInDimensions(),u=e&&l?hm(new D(s,s),void 0,o.calcTransformMatrix()):Vd,d=!e&&l?s:0,g=Pc(i+d,n+d,Ec([a,t.calcOwnMatrix()],!0)).add(u).scalarDivide(2);return[h.subtract(g),h.add(g)]};class Yc{calcLayoutResult(t,e){if(this.shouldPerformLayout(t))return this.calcBoundingBox(e,t)}shouldPerformLayout(t){let{type:e,prevStrategy:s,strategy:i}=t;return e===ji||e===Gc||!!s&&i!==s}shouldLayoutClipPath(t){let{type:e,target:{clipPath:s}}=t;return e!==ji&&s&&!s.absolutePositioned}getInitialSize(t,e){return e.size}calcBoundingBox(t,e){const{type:s,target:i}=e;if(s===Gc&&e.overrides)return e.overrides;if(t.length===0)return;const{left:n,top:r,width:a,height:h}=hi(t.map(d=>Jm(i,d)).reduce((d,g)=>d.concat(g),[])),l=new D(a,h),u=new D(n,r).add(l.scalarDivide(2));if(s===ji){const d=this.getInitialSize(e,{size:l,center:u});return{center:u,relativeCorrection:new D(0,0),size:d}}return{center:u.transform(i.calcOwnMatrix()),size:l}}}T(Yc,"type","strategy");class yg extends Yc{shouldPerformLayout(t){return!0}}T(yg,"type","fit-content"),V.setClass(yg);const X_=["strategy"],z_=["target","strategy","bubbles","prevStrategy"],Qm="layoutManager";class Ch{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:new yg;T(this,"strategy",void 0),this.strategy=t,this._subscriptions=new Map}performLayout(t){const e=E(E({bubbles:!0,strategy:this.strategy},t),{},{prevStrategy:this._prevLayoutStrategy,stopPropagation(){this.bubbles=!1}});this.onBeforeLayout(e);const s=this.getLayoutResult(e);s&&this.commitLayout(e,s),this.onAfterLayout(e,s),this._prevLayoutStrategy=e.strategy}attachHandlers(t,e){const{target:s}=e;return[Cc,Ip,gh,jp,wc,Np,xc,Py,Dy].map(i=>t.on(i,n=>this.performLayout(i===Cc?{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===ji||s===Vc?this.subscribeTargets(t):s===bg&&this.unsubscribeTargets(t),e.fire("layout:before",{context:t}),i&&i.fire("object:layout:before",{target:e,context:t}),s===Gc&&t.deep){const n=Pt(t,X_);e.forEachObject(r=>r.layoutManager&&r.layoutManager.performLayout(E(E({},n),{},{bubbles:!1,target:r})))}}getLayoutResult(t){const{target:e,strategy:s,type:i}=t,n=s.calcLayoutResult(t,e.getObjects());if(!n)return;const r=i===ji?new D:e.getRelativeCenterPoint(),{center:a,correction:h=new D,relativeCorrection:l=new D}=n,u=r.subtract(a).add(h).transform(i===ji?De:qe(e.calcOwnMatrix()),!0).add(l);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===ji?s.set({left:(r=t.x)!==null&&r!==void 0?r:n.x+i.x*Kt(s.originX),top:(a=t.y)!==null&&a!==void 0?a:n.y+i.y*Kt(s.originY)}):(s.setPositionByOrigin(n,st,st),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=Pt(t,z_),{canvas:h}=s;s.fire("layout:after",{context:t,result:e}),h&&h.fire("object:layout:after",{context:t,result:e,target:s});const l=s.parent;n&&l!=null&&l.layoutManager&&((a.path||(a.path=[])).push(s),l.layoutManager.performLayout(E(E({},a),{},{target:l}))),s.set("dirty",!0)}dispose(){const{_subscriptions:t}=this;t.forEach(e=>e.forEach(s=>s())),t.clear()}toObject(){return{type:Qm,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}V.setClass(Ch,Qm);const V_=["type","objects","layoutManager"];class G_ extends Ch{performLayout(){}}class ci extends Bp(xe){static getDefaults(){return E(E({},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(),T(this,"_activeObjects",[]),T(this,"__objectSelectionTracker",void 0),T(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 Ch,this.layoutManager.performLayout({type:ji,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(Pi("error","Group: circular object trees are not supported, this call has no effect"),!1):this._objects.indexOf(t)===-1||(Pi("error","Group: duplicate objects are not supported inside group, this call has no effect"),!1)}_filterObjectsBeforeEnteringGroup(t){return t.filter((e,s,i)=>this.canEnterGroup(e)&&i.indexOf(e)===s)}add(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];const i=this._filterObjectsBeforeEnteringGroup(e),n=super.add(...i);return this._onAfterObjectsChange(Vc,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(Vc,n),r}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange(bg,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&&Va(t,Gt(qe(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||(Va(t,Gt(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=xe.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(...qe(this.calcTransformMatrix())),r.render(t),t.restore()):r.group===this&&r.render(t)}this._drawClipPath(t,this.clipPath,s)}setCoords(){super.setCoords(),this._shouldSetNestedCoords()&&this.forEachObject(t=>t.setCoords())}triggerLayout(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.layoutManager.performLayout(E({target:this,type:Gc},t))}render(t){this._transformDone=!0,super.render(t),this._transformDone=!1}__serializeObjects(t,e){const s=this.includeDefaultValues;return this._objects.filter(function(i){return!i.excludeFromExport}).map(function(i){const n=i.includeDefaultValues;i.includeDefaultValues=s;const r=i[t||"toObject"](e);return i.includeDefaultValues=n,r})}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=this.layoutManager.toObject();return E(E(E({},super.toObject(["subTargetCheck","interactive",...t])),e.strategy!=="fit-content"||this.includeDefaultValues?{layoutManager:e}:{}),{},{objects:this.__serializeObjects("toObject",t)})}toString(){return"#<Group: (".concat(this.complexity(),")>")}dispose(){this.layoutManager.unsubscribeTargets({targets:this.getObjects(),target:this}),this._activeObjects=[],this.forEachObject(t=>{this._watchObject(!1,t),t.dispose()}),super.dispose()}_createSVGBgRect(t){if(!this.backgroundColor)return"";const e=li.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=Yi.ownDefaults;return this.includeDefaultValues?t:cg(t,(s,i)=>s!==e[i])}static async fromObject(t){return new this(t)}}T(Yi,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),T(Yi,"type","shadow"),W.setClass(Yi,"shadow");const Pr=(a,t,e)=>Math.max(a,Math.min(t,e)),Yy=[Je,vt,je,hs,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",Uo,Yo],$i=[Jt,Ne,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],$y={top:0,left:0,width:0,height:0,angle:0,flipX:!1,flipY:!1,scaleX:1,scaleY:1,minScaleLimit:0,skewX:0,skewY:0,originX:vt,originY:Je,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:Jt,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},Cg=(a,t,e,s)=>(a<Math.abs(t)?(a=t,s=e/4):s=t===0&&a===0?e/Ui*Math.asin(1):e/Ui*Math.asin(t/a),{a,c:t,p:e,s}),Fm=(a,t,e,s,i)=>a*Math.pow(2,10*(s-=1))*Math.sin((s*i-t)*Ui/e),Im=(a,t,e,s)=>-e*Math.cos(a/s*jn)+e+t,Ag=(a,t,e,s)=>(a/=s)<1/2.75?e*(7.5625*a*a)+t:a<2/2.75?e*(7.5625*(a-=1.5/2.75)*a+.75)+t:a<2.5/2.75?e*(7.5625*(a-=2.25/2.75)*a+.9375)+t:e*(7.5625*(a-=2.625/2.75)*a+.984375)+t,jm=(a,t,e,s)=>e-Ag(s-a,0,e,s)+t;var qy=Object.freeze({__proto__:null,defaultEasing:Im,easeInBack:function(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return e*(a/=s)*a*((i+1)*a-i)+t},easeInBounce:jm,easeInCirc:(a,t,e,s)=>-e*(Math.sqrt(1-(a/=s)*a)-1)+t,easeInCubic:(a,t,e,s)=>e*(a/s)**3+t,easeInElastic:(a,t,e,s)=>{const i=e;let n=0;if(a===0)return t;if((a/=s)===1)return t+e;n||(n=.3*s);const{a:r,s:o,p:h}=Cg(i,e,n,1.70158);return-Fm(r,o,h,a,s)+t},easeInExpo:(a,t,e,s)=>a===0?t:e*2**(10*(a/s-1))+t,easeInOutBack:function(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return(a/=s/2)<1?e/2*(a*a*((1+(i*=1.525))*a-i))+t:e/2*((a-=2)*a*((1+(i*=1.525))*a+i)+2)+t},easeInOutBounce:(a,t,e,s)=>a<s/2?.5*jm(2*a,0,e,s)+t:.5*Ag(2*a-s,0,e,s)+.5*e+t,easeInOutCirc:(a,t,e,s)=>(a/=s/2)<1?-e/2*(Math.sqrt(1-a**2)-1)+t:e/2*(Math.sqrt(1-(a-=2)*a)+1)+t,easeInOutCubic:(a,t,e,s)=>(a/=s/2)<1?e/2*a**3+t:e/2*((a-2)**3+2)+t,easeInOutElastic:(a,t,e,s)=>{const i=e;let n=0;if(a===0)return t;if((a/=s/2)===2)return t+e;n||(n=s*(.3*1.5));const{a:r,s:o,p:h,c}=Cg(i,e,n,1.70158);return a<1?-.5*Fm(r,o,h,a,s)+t:r*Math.pow(2,-10*(a-=1))*Math.sin((a*s-o)*Ui/h)*.5+c+t},easeInOutExpo:(a,t,e,s)=>a===0?t:a===s?t+e:(a/=s/2)<1?e/2*2**(10*(a-1))+t:e/2*-(2**(-10*--a)+2)+t,easeInOutQuad:(a,t,e,s)=>(a/=s/2)<1?e/2*a**2+t:-e/2*(--a*(a-2)-1)+t,easeInOutQuart:(a,t,e,s)=>(a/=s/2)<1?e/2*a**4+t:-e/2*((a-=2)*a**3-2)+t,easeInOutQuint:(a,t,e,s)=>(a/=s/2)<1?e/2*a**5+t:e/2*((a-2)**5+2)+t,easeInOutSine:(a,t,e,s)=>-e/2*(Math.cos(Math.PI*a/s)-1)+t,easeInQuad:(a,t,e,s)=>e*(a/=s)*a+t,easeInQuart:(a,t,e,s)=>e*(a/=s)*a**3+t,easeInQuint:(a,t,e,s)=>e*(a/s)**5+t,easeInSine:(a,t,e,s)=>-e*Math.cos(a/s*jn)+e+t,easeOutBack:function(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return e*((a=a/s-1)*a*((i+1)*a+i)+1)+t},easeOutBounce:Ag,easeOutCirc:(a,t,e,s)=>e*Math.sqrt(1-(a=a/s-1)*a)+t,easeOutCubic:(a,t,e,s)=>e*((a/s-1)**3+1)+t,easeOutElastic:(a,t,e,s)=>{const i=e;let n=0;if(a===0)return t;if((a/=s)===1)return t+e;n||(n=.3*s);const{a:r,s:o,p:h,c}=Cg(i,e,n,1.70158);return r*2**(-10*a)*Math.sin((a*s-o)*Ui/h)+c+t},easeOutExpo:(a,t,e,s)=>a===s?t+e:e*-(2**(-10*a/s)+1)+t,easeOutQuad:(a,t,e,s)=>-e*(a/=s)*(a-2)+t,easeOutQuart:(a,t,e,s)=>-e*((a=a/s-1)*a**3-1)+t,easeOutQuint:(a,t,e,s)=>e*((a/s-1)**5+1)+t,easeOutSine:(a,t,e,s)=>e*Math.sin(a/s*jn)+t});const Ky=()=>!1;class Tg{constructor(t){let{startValue:e,byValue:s,duration:i=500,delay:n=0,easing:r=Im,onStart:o=Cr,onChange:h=Cr,onComplete:c=Cr,abort:u=Ky,target:d}=t;T(this,"_state","pending"),T(this,"durationProgress",0),T(this,"valueProgress",0),this.tick=this.tick.bind(this),this.duration=i,this.delay=n,this.easing=r,this._onStart=o,this._onChange=h,this._onComplete=c,this._abort=u,this.target=d,this.startValue=e,this.byValue=s,this.value=this.startValue,this.endValue=Object.freeze(this.calculate(this.duration).value)}get state(){return this._state}isDone(){return this._state==="aborted"||this._state==="completed"}start(){const t=e=>{this._state==="pending"&&(this.startTime=e||+new Date,this._state="running",this._onStart(),this.tick(this.startTime))};this.register(),this.delay>0?setTimeout(()=>Eh(t),this.delay):Eh(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),Eh(this.tick)))}register(){Vc.push(this)}unregister(){Vc.remove(this)}abort(){this._state="aborted",this.unregister()}}const Qy=["startValue","endValue"];class Jy extends Tg{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(E(E({},Ot(t,Qy)),{},{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 Zy=["startValue","endValue"];class t_ extends Tg{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(E(E({},Ot(t,Zy)),{},{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 e_=["startValue","endValue","easing","onChange","onComplete","abort"],s_=(a,t,e,s)=>t+e*(1-Math.cos(a/s*jn)),Eg=a=>a&&((t,e,s)=>a(new _t(t).toRgba(),e,s));class i_ extends Tg{constructor(t){let{startValue:e,endValue:s,easing:i=s_,onChange:n,onComplete:r,abort:o}=t,h=Ot(t,e_);const c=new _t(e).getSource(),u=new _t(s).getSource();super(E(E({},h),{},{startValue:c,byValue:u.map((d,g)=>d-c[g]),easing:i,onChange:Eg(n),onComplete:Eg(r),abort:Eg(o)}))}calculate(t){const[e,s,i,n]=this.startValue.map((o,h)=>this.easing(t,o,this.byValue[h],this.duration,h)),r=[...[e,s,i].map(Math.round),Pr(0,n,1)];return{value:r,valueProgress:r.map((o,h)=>this.byValue[h]!==0?Math.abs((o-this.startValue[h])/this.byValue[h]):0).find(o=>o!==0)||0}}}function kg(a){const t=(e=>Array.isArray(e.startValue)||Array.isArray(e.endValue))(a)?new t_(a):new Jy(a);return t.start(),t}function Nm(a){const t=new i_(a);return t.start(),t}class Nt{constructor(t){this.status=t,this.points=[]}includes(t){return this.points.some(e=>e.eq(t))}append(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];return this.points=this.points.concat(e.filter(i=>!this.includes(i))),this}static isPointContained(t,e,s){let i=arguments.length>3&&arguments[3]!==void 0&&arguments[3];if(e.eq(s))return t.eq(e);if(e.x===s.x)return t.x===e.x&&(i||t.y>=Math.min(e.y,s.y)&&t.y<=Math.max(e.y,s.y));if(e.y===s.y)return t.y===e.y&&(i||t.x>=Math.min(e.x,s.x)&&t.x<=Math.max(e.x,s.x));{const n=Kc(e,s),r=Kc(e,t).divide(n);return i?Math.abs(r.x)===Math.abs(r.y):r.x===r.y&&r.x>=0&&r.x<=1}}static isPointInPolygon(t,e){const s=new O(t).setX(Math.min(t.x-1,...e.map(n=>n.x)));let i=0;for(let n=0;n<e.length;n++){const r=this.intersectSegmentSegment(e[n],e[(n+1)%e.length],t,s);if(r.includes(t))return!0;i+=+(r.status==="Intersection")}return i%2==1}static intersectLineLine(t,e,s,i){let n=!(arguments.length>4&&arguments[4]!==void 0)||arguments[4],r=!(arguments.length>5&&arguments[5]!==void 0)||arguments[5];const o=e.x-t.x,h=e.y-t.y,c=i.x-s.x,u=i.y-s.y,d=t.x-s.x,g=t.y-s.y,f=c*g-u*d,p=o*g-h*d,m=u*o-c*h;if(m!==0){const y=f/m,b=p/m;return(n||0<=y&&y<=1)&&(r||0<=b&&b<=1)?new Nt("Intersection").append(new O(t.x+y*o,t.y+y*h)):new Nt}if(f===0||p===0){const y=n||r||Nt.isPointContained(t,s,i)||Nt.isPointContained(e,s,i)||Nt.isPointContained(s,t,e)||Nt.isPointContained(i,t,e);return new Nt(y?"Coincident":void 0)}return new Nt("Parallel")}static intersectSegmentLine(t,e,s,i){return Nt.intersectLineLine(t,e,s,i,!1,!0)}static intersectSegmentSegment(t,e,s,i){return Nt.intersectLineLine(t,e,s,i,!1,!1)}static intersectLinePolygon(t,e,s){let i=!(arguments.length>3&&arguments[3]!==void 0)||arguments[3];const n=new Nt,r=s.length;for(let o,h,c,u=0;u<r;u++){if(o=s[u],h=s[(u+1)%r],c=Nt.intersectLineLine(t,e,o,h,i,!1),c.status==="Coincident")return c;n.append(...c.points)}return n.points.length>0&&(n.status="Intersection"),n}static intersectSegmentPolygon(t,e,s){return Nt.intersectLinePolygon(t,e,s,!1)}static intersectPolygonPolygon(t,e){const s=new Nt,i=t.length,n=[];for(let r=0;r<i;r++){const o=t[r],h=t[(r+1)%i],c=Nt.intersectSegmentPolygon(o,h,e);c.status==="Coincident"?(n.push(c),s.append(o,h)):s.append(...c.points)}return n.length>0&&n.length===t.length?new Nt("Coincident"):(s.points.length>0&&(s.status="Intersection"),s)}static intersectPolygonRectangle(t,e,s){const i=e.min(s),n=e.max(s),r=new O(n.x,i.y),o=new O(i.x,n.y);return Nt.intersectPolygonPolygon(t,[i,r,n,o])}}class n_ extends Jp{getX(){return this.getXY().x}setX(t){this.setXY(this.getXY().setX(t))}getY(){return this.getXY().y}setY(t){this.setXY(this.getXY().setY(t))}getRelativeX(){return this.left}setRelativeX(t){this.left=t}getRelativeY(){return this.top}setRelativeY(t){this.top=t}getXY(){const t=this.getRelativeXY();return this.group?Se(t,this.group.calcTransformMatrix()):t}setXY(t,e,s){this.group&&(t=Se(t,Ze(this.group.calcTransformMatrix()))),this.setRelativeXY(t,e,s)}getRelativeXY(){return new O(this.left,this.top)}setRelativeXY(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.originX,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.originY;this.setPositionByOrigin(t,e,s)}isStrokeAccountedForInDimensions(){return!1}getCoords(){const{tl:t,tr:e,br:s,bl:i}=this.aCoords||(this.aCoords=this.calcACoords()),n=[t,e,s,i];if(this.group){const r=this.group.calcTransformMatrix();return n.map(o=>Se(o,r))}return n}intersectsWithRect(t,e){return Nt.intersectPolygonRectangle(this.getCoords(),t,e).status==="Intersection"}intersectsWithObject(t){const e=Nt.intersectPolygonPolygon(this.getCoords(),t.getCoords());return e.status==="Intersection"||e.status==="Coincident"||t.isContainedWithinObject(this)||this.isContainedWithinObject(t)}isContainedWithinObject(t){return this.getCoords().every(e=>t.containsPoint(e))}isContainedWithinRect(t,e){const{left:s,top:i,width:n,height:r}=this.getBoundingRect();return s>=t.x&&s+n<=e.x&&i>=t.y&&i+r<=e.y}isOverlapping(t){return this.intersectsWithObject(t)||this.isContainedWithinObject(t)||t.isContainedWithinObject(this)}containsPoint(t){return Nt.isPointInPolygon(t,this.getCoords())}isOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return!!this.getCoords().some(s=>s.x<=e.x&&s.x>=t.x&&s.y<=e.y&&s.y>=t.y)||!!this.intersectsWithRect(t,e)||this.containsPoint(t.midPointFrom(e))}isPartiallyOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return this.intersectsWithRect(t,e)?!0:this.getCoords().every(s=>(s.x>=e.x||s.x<=t.x)&&(s.y>=e.y||s.y<=t.y))&&this.containsPoint(t.midPointFrom(e))}getBoundingRect(){return bi(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(je,t),this._set(hs,t),this.setCoords()}scaleToWidth(t){const e=this.getBoundingRect().width/this.getScaledWidth();return this.scale(t/this.width/e)}scaleToHeight(t){const e=this.getBoundingRect().height/this.getScaledHeight();return this.scale(t/this.height/e)}getCanvasRetinaScaling(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.getRetinaScaling())||1}getTotalAngle(){return this.group?Hn(sm(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.viewportTransform)||Fe.concat()}calcACoords(){const t=Ko({angle:this.angle}),{x:e,y:s}=this.getRelativeCenterPoint(),i=qo(e,s),n=Yt(i,t),r=this._getTransformedDimensions(),o=r.x/2,h=r.y/2;return{tl:Se({x:-o,y:-h},n),tr:Se({x:o,y:-h},n),bl:Se({x:-o,y:h},n),br:Se({x:o,y:h},n)}}setCoords(){this.aCoords=this.calcACoords()}transformMatrixKey(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0],e=[];return!t&&this.group&&(e=this.group.transformMatrixKey(t)),e.push(this.top,this.left,this.width,this.height,this.scaleX,this.scaleY,this.angle,this.strokeWidth,this.skewX,this.skewY,+this.flipX,+this.flipY,Zt(this.originX),Zt(this.originY)),e}calcTransformMatrix(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0],e=this.calcOwnMatrix();if(t||!this.group)return e;const s=this.transformMatrixKey(t),i=this.matrixCache;return i&&i.key.every((n,r)=>n===s[r])?i.value:(this.group&&(e=Yt(this.group.calcTransformMatrix(!1),e)),this.matrixCache={key:s,value:e},e)}calcOwnMatrix(){const t=this.transformMatrixKey(!0),e=this.ownMatrixCache;if(e&&e.key===t)return e.value;const s=this.getRelativeCenterPoint(),i={angle:this.angle,translateX:s.x,translateY:s.y,scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,flipX:this.flipX,flipY:this.flipY},n=nm(i);return this.ownMatrixCache={key:t,value:n},n}_getNonTransformedDimensions(){return new O(this.width,this.height).scalarAdd(this.strokeWidth)}_calculateCurrentDimensions(t){return this._getTransformedDimensions(t).transform(this.getViewportTransform(),!0).scalarAdd(2*this.padding)}_getTransformedDimensions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=E({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,width:this.width,height:this.height,strokeWidth:this.strokeWidth},t),s=e.strokeWidth;let i=s,n=0;this.strokeUniform&&(i=0,n=s);const r=e.width+i,o=e.height+i;let h;return h=e.skewX===0&&e.skewY===0?new O(r*e.scaleX,o*e.scaleY):Yc(r,o,kh(e)),h.scalarAdd(n)}translateToGivenOrigin(t,e,s,i,n){let r=t.x,o=t.y;const h=Zt(i)-Zt(e),c=Zt(n)-Zt(s);if(h||c){const u=this._getTransformedDimensions();r+=h*u.x,o+=c*u.y}return new O(r,o)}translateToCenterPoint(t,e,s){if(e===tt&&s===tt)return t;const i=this.translateToGivenOrigin(t,e,s,tt,tt);return this.angle?i.rotate(zt(this.angle),t):i}translateToOriginPoint(t,e,s){const i=this.translateToGivenOrigin(t,tt,tt,e,s);return this.angle?i.rotate(zt(this.angle),t):i}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?Se(t,this.group.calcTransformMatrix()):t}getRelativeCenterPoint(){return this.translateToCenterPoint(new O(this.left,this.top),this.originX,this.originY)}getPointByOrigin(t,e){return this.translateToOriginPoint(this.getRelativeCenterPoint(),t,e)}setPositionByOrigin(t,e,s){const i=this.translateToCenterPoint(t,e,s),n=this.translateToOriginPoint(i,this.originX,this.originY);this.set({left:n.x,top:n.y})}_getLeftTopCoords(){return this.translateToOriginPoint(this.getRelativeCenterPoint(),vt,Je)}}const r_=["type"],o_=["extraParam"];let qi=class Cd extends n_{static getDefaults(){return Cd.ownDefaults}get type(){const t=this.constructor.type;return t==="FabricObject"?"object":t.toLowerCase()}set type(t){Xi("warn","Setting type has no effect",t)}constructor(t){super(),T(this,"_cacheContext",null),Object.assign(this,Cd.ownDefaults),this.setOptions(t)}_createCacheCanvas(){this._cacheCanvas=As(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,s=t.height,i=dt.maxCacheSideLimit,n=dt.minCacheSideLimit;if(e<=i&&s<=i&&e*s<=dt.perfLimitSizeTotal)return e<n&&(t.width=n),s<n&&(t.height=n),t;const r=e/s,[o,h]=Ah.limitDimsByArea(r),c=Pr(n,o,i),u=Pr(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:s+2,height:i+2,zoomX:t.x,zoomY:t.y,x:s,y:i}}_updateCacheCanvas(){const t=this._cacheCanvas,e=this._cacheContext,s=this._limitCacheSize(this._getCacheCanvasDimensions()),i=dt.minCacheSideLimit,n=s.width,r=s.height,o=s.zoomX,h=s.zoomY,c=n!==t.width||r!==t.height,u=this.zoomX!==o||this.zoomY!==h;if(!t||!e)return!1;let d,g,f=c||u,p=0,m=0,y=!1;if(c){const b=this._cacheCanvas.width,x=this._cacheCanvas.height,C=n>b||r>x;y=C||(n<.9*b||r<.9*x)&&b>i&&x>i,C&&!s.capped&&(n>i||r>i)&&(p=.1*n,m=.1*r)}return um(this)&&this.path&&(f=!0,y=!0,p+=this.getHeightOfLine(0)*this.zoomX,m+=this.getHeightOfLine(0)*this.zoomY),!!f&&(y?(t.width=Math.ceil(n+p),t.height=Math.ceil(r+m)):(e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,t.width,t.height)),d=s.x/2,g=s.y/2,this.cacheTranslationX=Math.round(t.width/2-d)+d,this.cacheTranslationY=Math.round(t.height/2-g)+g,e.translate(this.cacheTranslationX,this.cacheTranslationY),e.scale(o,h),this.zoomX=o,this.zoomY=h,!0)}setOptions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this._setOptions(t)}transform(t){const e=this.group&&!this.group._transformDone||this.group&&this.canvas&&t===this.canvas.contextTop,s=this.calcTransformMatrix(!e);t.transform(s[0],s[1],s[2],s[3],s[4],s[5])}getObjectScaling(){if(!this.group)return new O(Math.abs(this.scaleX),Math.abs(this.scaleY));const t=Tr(this.calcTransformMatrix());return new O(Math.abs(t.scaleX),Math.abs(t.scaleY))}getTotalObjectScaling(){const t=this.getObjectScaling();if(this.canvas){const e=this.canvas.getZoom(),s=this.getCanvasRetinaScaling();return t.scalarMultiply(e*s)}return t}getObjectOpacity(){let t=this.opacity;return this.group&&(t*=this.group.getObjectOpacity()),t}_constrainScale(t){return Math.abs(t)<this.minScaleLimit?t<0?-this.minScaleLimit:this.minScaleLimit:t===0?1e-4:t}_set(t,e){t!==je&&t!==hs||(e=this._constrainScale(e)),t===je&&e<0?(this.flipX=!this.flipX,e*=-1):t==="scaleY"&&e<0?(this.flipY=!this.flipY,e*=-1):t!=="shadow"||!e||e instanceof Yi||(e=new Yi(e));const s=this[t]!==e;return this[t]=e,s&&this.constructor.cacheProperties.includes(t)&&(this.dirty=!0),this.parent&&(this.dirty||s&&this.constructor.stateProperties.includes(t))&&this.parent._set("dirty",!0),this}isNotVisible(){return this.opacity===0||!this.width&&!this.height&&this.strokeWidth===0||!this.visible}render(t){this.isNotVisible()||this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(t.save(),this._setupCompositeOperation(t),this.drawSelectionBackground(t),this.transform(t),this._setOpacity(t),this._setShadow(t),this.shouldCache()?(this.renderCache(),this.drawCacheOnCanvas(t)):(this._removeCacheCanvas(),this.drawObject(t,!1,{}),this.dirty=!1),t.restore())}drawSelectionBackground(t){}renderCache(t){if(t=t||{},this._cacheCanvas&&this._cacheContext||this._createCacheCanvas(),this.isCacheDirty()&&this._cacheContext){const{zoomX:e,zoomY:s,cacheTranslationX:i,cacheTranslationY:n}=this,{width:r,height:o}=this._cacheCanvas;this.drawObject(this._cacheContext,t.forClipping,{zoomX:e,zoomY:s,cacheTranslationX:i,cacheTranslationY:n,width:r,height:o,parentClipPaths:[]}),this.dirty=!1}}_removeCacheCanvas(){this._cacheCanvas=void 0,this._cacheContext=null}hasStroke(){return this.stroke&&this.stroke!=="transparent"&&this.strokeWidth!==0}hasFill(){return this.fill&&this.fill!=="transparent"}needsItsOwnCache(){return!!(this.paintFirst===Ne&&this.hasFill()&&this.hasStroke()&&this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.needsItsOwnCache()||this.objectCaching&&(!this.parent||!this.parent.isOnACache()),this.ownCaching}willDrawShadow(){return!!this.shadow&&(this.shadow.offsetX!==0||this.shadow.offsetY!==0)}drawClipPathOnCache(t,e,s){t.save(),e.inverted?t.globalCompositeOperation="destination-out":t.globalCompositeOperation="destination-in",t.setTransform(1,0,0,1,0,0),t.drawImage(s,0,0),t.restore()}drawObject(t,e,s){const i=this.fill,n=this.stroke;e?(this.fill="black",this.stroke="",this._setClippingProperties(t)):this._renderBackground(t),this._render(t),this._drawClipPath(t,this.clipPath,s),this.fill=i,this.stroke=n}createClipPathLayer(t,e){const s=Xs(e),i=s.getContext("2d");if(i.translate(e.cacheTranslationX,e.cacheTranslationY),i.scale(e.zoomX,e.zoomY),t._cacheCanvas=s,e.parentClipPaths.forEach(n=>{n.transform(i)}),e.parentClipPaths.push(t),t.absolutePositioned){const n=Ze(this.calcTransformMatrix());i.transform(n[0],n[1],n[2],n[3],n[4],n[5])}return t.transform(i),t.drawObject(i,!0,e),s}_drawClipPath(t,e,s){if(!e)return;e._transformDone=!0;const i=this.createClipPathLayer(e,s);this.drawClipPathOnCache(t,e,i)}drawCacheOnCanvas(t){t.scale(1/this.zoomX,1/this.zoomY),t.drawImage(this._cacheCanvas,-this.cacheTranslationX,-this.cacheTranslationY)}isCacheDirty(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0];if(this.isNotVisible())return!1;const e=this._cacheCanvas,s=this._cacheContext;return!(!e||!s||t||!this._updateCacheCanvas())||!!(this.dirty||this.clipPath&&this.clipPath.absolutePositioned)&&(e&&s&&!t&&(s.save(),s.setTransform(1,0,0,1,0,0),s.clearRect(0,0,e.width,e.height),s.restore()),!0)}_renderBackground(t){if(!this.backgroundColor)return;const e=this._getNonTransformedDimensions();t.fillStyle=this.backgroundColor,t.fillRect(-e.x/2,-e.y/2,e.x,e.y),this._removeShadow(t)}_setOpacity(t){this.group&&!this.group._transformDone?t.globalAlpha=this.getObjectOpacity():t.globalAlpha*=this.opacity}_setStrokeStyles(t,e){const s=e.stroke;s&&(t.lineWidth=e.strokeWidth,t.lineCap=e.strokeLineCap,t.lineDashOffset=e.strokeDashOffset,t.lineJoin=e.strokeLineJoin,t.miterLimit=e.strokeMiterLimit,Ts(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&&(Ts(s)?(t.fillStyle=s.toLive(t),this._applyPatternGradientTransform(t,s)):t.fillStyle=s)}_setClippingProperties(t){t.globalAlpha=1,t.strokeStyle="transparent",t.fillStyle="#000000"}_setLineDash(t,e){e&&e.length!==0&&(1&e.length&&e.push(...e),t.setLineDash(e))}_setShadow(t){if(!this.shadow)return;const e=this.shadow,s=this.canvas,i=this.getCanvasRetinaScaling(),[n,,,r]=(s==null?void 0:s.viewportTransform)||Fe,o=n*i,h=r*i,c=e.nonScaling?new O(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*dt.browserShadowBlurConstant*(o+h)*(c.x+c.y)/4,t.shadowOffsetX=e.offsetX*o*c.x,t.shadowOffsetY=e.offsetY*h*c.y}_removeShadow(t){this.shadow&&(t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0)}_applyPatternGradientTransform(t,e){if(!Ts(e))return{offsetX:0,offsetY:0};const s=e.gradientTransform||e.patternTransform,i=-this.width/2+e.offsetX||0,n=-this.height/2+e.offsetY||0;return e.gradientUnits==="percentage"?t.transform(this.width,0,0,this.height,i,n):t.transform(1,0,0,1,i,n),s&&t.transform(s[0],s[1],s[2],s[3],s[4],s[5]),{offsetX:i,offsetY:n}}_renderPaintInOrder(t){this.paintFirst===Ne?(this._renderStroke(t),this._renderFill(t)):(this._renderFill(t),this._renderStroke(t))}_render(t){}_renderFill(t){this.fill&&(t.save(),this._setFillStyles(t,this),this.fillRule==="evenodd"?t.fill("evenodd"):t.fill(),t.restore())}_renderStroke(t){if(this.stroke&&this.strokeWidth!==0){if(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this.strokeUniform){const e=this.getObjectScaling();t.scale(1/e.x,1/e.y)}this._setLineDash(t,this.strokeDashArray),this._setStrokeStyles(t,this),t.stroke(),t.restore()}}_applyPatternForTransformedGradient(t,e){var s;const i=this._limitCacheSize(this._getCacheCanvasDimensions()),n=this.getCanvasRetinaScaling(),r=i.x/this.scaleX/n,o=i.y/this.scaleY/n,h=Xs({width:Math.ceil(r),height:Math.ceil(o)}),c=h.getContext("2d");c&&(c.beginPath(),c.moveTo(0,0),c.lineTo(r,0),c.lineTo(r,o),c.lineTo(0,o),c.closePath(),c.translate(r/2,o/2),c.scale(i.zoomX/this.scaleX/n,i.zoomY/this.scaleY/n),this._applyPatternGradientTransform(c,e),c.fillStyle=e.toLive(t),c.fill(),t.translate(-this.width/2-this.strokeWidth/2,-this.height/2-this.strokeWidth/2),t.scale(n*this.scaleX/i.zoomX,n*this.scaleY/i.zoomY),t.strokeStyle=(s=c.createPattern(h,"no-repeat"))!==null&&s!==void 0?s:"")}_findCenterFromElement(){return new O(this.left+this.width/2,this.top+this.height/2)}clone(t){const e=this.toObject(t);return this.constructor.fromObject(e)}cloneAsImage(t){const e=this.toCanvasElement(t);return new(W.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=pg(this),s=this.group,i=this.shadow,n=Math.abs,r=t.enableRetinaScaling?Yp():1,o=(t.multiplier||1)*r,h=t.canvasProvider||(x=>new Rh(x,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&ym(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&mg(this,this.getViewportTransform()),this.setCoords();const c=As(),u=this.getBoundingRect(),d=this.shadow,g=new O;if(d){const x=d.blur,C=d.nonScaling?new O(1,1):this.getObjectScaling();g.x=2*Math.round(n(d.offsetX)+x)*n(C.x),g.y=2*Math.round(n(d.offsetY)+x)*n(C.y)}const f=u.width+g.x,p=u.height+g.y;c.width=Math.ceil(f),c.height=Math.ceil(p);const m=h(c);t.format==="jpeg"&&(m.backgroundColor="#fff"),this.setPositionByOrigin(new O(m.width/2,m.height/2),tt,tt);const y=this.canvas;m._objects=[this],this.set("canvas",m),this.setCoords();const b=m.toCanvasElement(o||1,t);return this.set("canvas",y),this.shadow=i,s&&(this.group=s),this.set(e),this.setCoords(),m._objects=[],m.destroy(),b}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return ag(this.toCanvasElement(t),t.format||"png",t.quality||1)}isType(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];return e.includes(this.constructor.type)||e.includes(this.type)}complexity(){return 1}toJSON(){return this.toObject()}rotate(t){const{centeredRotation:e,originX:s,originY:i}=this;if(e){const{x:n,y:r}=this.getRelativeCenterPoint();this.originX=tt,this.originY=tt,this.left=n,this.top=r}if(this.set("angle",t),e){const{x:n,y:r}=this.translateToOriginPoint(this.getRelativeCenterPoint(),s,i);this.left=n,this.top=r,this.originX=s,this.originY=i}}setOnGroup(){}_setupCompositeOperation(t){this.globalCompositeOperation&&(t.globalCompositeOperation=this.globalCompositeOperation)}dispose(){Vc.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&vi().dispose(this._cacheCanvas),this._cacheCanvas=void 0,this._cacheContext=null}animate(t,e){return Object.entries(t).reduce((s,i)=>{let[n,r]=i;return s[n]=this._animate(n,r,e),s},{})}_animate(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const i=t.split("."),n=this.constructor.colorProperties.includes(i[i.length-1]),{abort:r,startValue:o,onChange:h,onComplete:c}=s,u=E(E({},s),{},{target:this,startValue:o??i.reduce((d,g)=>d[g],this),endValue:e,abort:r==null?void 0:r.bind(this),onChange:(d,g,f)=>{i.reduce((p,m,y)=>(y===i.length-1&&(p[m]=d),p[m]),this),h&&h(d,g,f)},onComplete:(d,g,f)=>{this.setCoords(),c&&c(d,g,f)}});return n?Nm(u):kg(u)}isDescendantOf(t){const{parent:e,group:s}=this;return e===t||s===t||!!e&&e.isDescendantOf(t)||!!s&&s!==e&&s.isDescendantOf(t)}getAncestors(){const t=[];let e=this;do e=e.parent,e&&t.push(e);while(e);return t}findCommonAncestors(t){if(this===t)return{fork:[],otherFork:[],common:[this,...this.getAncestors()]};const e=this.getAncestors(),s=t.getAncestors();if(e.length===0&&s.length>0&&this===s[s.length-1])return{fork:[],otherFork:[t,...s.slice(0,s.length-1)],common:[this]};for(let i,n=0;n<e.length;n++){if(i=e[n],i===t)return{fork:[this,...e.slice(0,n)],otherFork:[],common:e.slice(n)};for(let r=0;r<s.length;r++){if(this===s[r])return{fork:[],otherFork:[t,...s.slice(0,r)],common:[this,...e]};if(i===s[r])return{fork:[this,...e.slice(0,n)],otherFork:[t,...s.slice(0,r)],common:e.slice(n)}}}return{fork:[this,...e],otherFork:[t,...s],common:[]}}hasCommonAncestors(t){const e=this.findCommonAncestors(t);return e&&!!e.common.length}isInFrontOf(t){if(this===t)return;const e=this.findCommonAncestors(t);if(e.fork.includes(t))return!0;if(e.otherFork.includes(this))return!1;const s=e.common[0]||this.canvas;if(!s)return;const i=e.fork.pop(),n=e.otherFork.pop(),r=s._objects.indexOf(i),o=s._objects.indexOf(n);return r>-1&&r>o}toObject(){const t=(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).concat(Cd.customProperties,this.constructor.customProperties||[]);let e;const s=dt.NUM_FRACTION_DIGITS,{clipPath:i,fill:n,stroke:r,shadow:o,strokeDashArray:h,left:c,top:u,originX:d,originY:g,width:f,height:p,strokeWidth:m,strokeLineCap:y,strokeDashOffset:b,strokeLineJoin:x,strokeUniform:C,strokeMiterLimit:A,scaleX:M,scaleY:D,angle:k,flipX:P,flipY:R,opacity:F,visible:I,backgroundColor:X,fillRule:j,paintFirst:N,globalCompositeOperation:it,skewX:K,skewY:V}=this;i&&!i.excludeFromExport&&(e=i.toObject(t.concat("inverted","absolutePositioned")));const H=It=>Dt(It,s),Et=E(E({},Er(this,t)),{},{type:this.constructor.type,version:Zd,originX:d,originY:g,left:H(c),top:H(u),width:H(f),height:H(p),fill:lm(n)?n.toObject():n,stroke:lm(r)?r.toObject():r,strokeWidth:H(m),strokeDashArray:h&&h.concat(),strokeLineCap:y,strokeDashOffset:b,strokeLineJoin:x,strokeUniform:C,strokeMiterLimit:H(A),scaleX:H(M),scaleY:H(D),angle:H(k),flipX:P,flipY:R,opacity:H(F),shadow:o&&o.toObject(),visible:I,backgroundColor:X,fillRule:j,paintFirst:N,globalCompositeOperation:it,skewX:H(K),skewY:H(V)},e?{clipPath:e}:null);return this.includeDefaultValues?Et:this._removeDefaultValues(Et)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),s=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return cg(t,(i,n)=>{if(n===vt||n===Je||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=Ot(t,r_),s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{extraParam:i}=s,n=Ot(s,o_);return Ph(e,n).then(r=>i?(delete r[i],new this(e[i],r)):new this(r))}static fromObject(t,e){return this._fromObject(t,e)}};T(qi,"stateProperties",Yy),T(qi,"cacheProperties",$i),T(qi,"ownDefaults",$y),T(qi,"type","FabricObject"),T(qi,"colorProperties",[Jt,Ne,"backgroundColor"]),T(qi,"customProperties",[]),W.setClass(qi),W.setClass(qi,"object");const ta=(a,t,e)=>(s,i,n,r)=>{const o=t(s,i,n,r);return o&&wm(a,E(E({},Cm(s,i,n,r)),e)),o};function ea(a){return(t,e,s,i)=>{const{target:n,originX:r,originY:o}=e,h=n.getRelativeCenterPoint(),c=n.translateToOriginPoint(h,r,o),u=a(t,e,s,i);return n.setPositionByOrigin(c,e.originX,e.originY),u}}const Bm=ta(Th,ea((a,t,e,s)=>{const i=vg(t,t.originX,t.originY,e,s);if(Zt(t.originX)===Zt(tt)||Zt(t.originX)===Zt(Ut)&&i.x<0||Zt(t.originX)===Zt(vt)&&i.x>0){const{target:n}=t,r=n.strokeWidth/(n.strokeUniform?n.scaleX:1),o=xm(t)?2:1,h=n.width,c=Math.abs(i.x*o/n.scaleX)-r;return n.set("width",Math.max(c,1)),h!==n.width}return!1}));function a_(a,t,e,s,i){s=s||{};const n=this.sizeX||s.cornerSize||i.cornerSize,r=this.sizeY||s.cornerSize||i.cornerSize,o=s.transparentCorners!==void 0?s.transparentCorners:i.transparentCorners,h=o?Ne:Jt,c=!o&&(s.cornerStrokeColor||i.cornerStrokeColor);let u,d=t,g=e;a.save(),a.fillStyle=s.cornerColor||i.cornerColor||"",a.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",n>r?(u=n,a.scale(1,r/n),g=e*n/r):r>n?(u=r,a.scale(n/r,1),d=t*r/n):u=n,a.beginPath(),a.arc(d,g,u/2,0,Ui,!1),a[h](),c&&a.stroke(),a.restore()}function h_(a,t,e,s,i){s=s||{};const n=this.sizeX||s.cornerSize||i.cornerSize,r=this.sizeY||s.cornerSize||i.cornerSize,o=s.transparentCorners!==void 0?s.transparentCorners:i.transparentCorners,h=o?Ne:Jt,c=!o&&(s.cornerStrokeColor||i.cornerStrokeColor),u=n/2,d=r/2;a.save(),a.fillStyle=s.cornerColor||i.cornerColor||"",a.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",a.translate(t,e);const g=i.getTotalAngle();a.rotate(zt(g)),a["".concat(h,"Rect")](-u,-d,n,r),c&&a.strokeRect(-u,-d,n,r),a.restore()}class qs{constructor(t){T(this,"visible",!0),T(this,"actionName",Bc),T(this,"angle",0),T(this,"x",0),T(this,"y",0),T(this,"offsetX",0),T(this,"offsetY",0),T(this,"sizeX",0),T(this,"sizeY",0),T(this,"touchSizeX",0),T(this,"touchSizeY",0),T(this,"cursorStyle","crosshair"),T(this,"withConnection",!1),Object.assign(this,t)}shouldActivate(t,e,s,i){var n;let{tl:r,tr:o,br:h,bl:c}=i;return((n=e.canvas)===null||n===void 0?void 0:n.getActiveObject())===e&&e.isControlVisible(t)&&Nt.isPointInPolygon(s,[r,o,h,c])}getActionHandler(t,e,s){return this.actionHandler}getMouseDownHandler(t,e,s){return this.mouseDownHandler}getMouseUpHandler(t,e,s){return this.mouseUpHandler}cursorStyleHandler(t,e,s){return e.cursorStyle}getActionName(t,e,s){return e.actionName}getVisibility(t,e){var s,i;return(s=(i=t._controlsVisibility)===null||i===void 0?void 0:i[e])!==null&&s!==void 0?s:this.visible}setVisibility(t,e,s){this.visible=t}positionHandler(t,e,s,i){return new O(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(e)}calcCornerCoords(t,e,s,i,n,r){const o=Wc([qo(s,i),Ko({angle:t}),zc((n?this.touchSizeX:this.sizeX)||e,(n?this.touchSizeY:this.sizeY)||e)]);return{tl:new O(-.5,-.5).transform(o),tr:new O(.5,-.5).transform(o),br:new O(.5,.5).transform(o),bl:new O(-.5,.5).transform(o)}}render(t,e,s,i,n){((i=i||{}).cornerStyle||n.cornerStyle)==="circle"?a_.call(this,t,e,s,i,n):h_.call(this,t,e,s,i,n)}}const l_=(a,t,e)=>e.lockRotation?$c:t.cursorStyle,c_=ta(qp,ea((a,t,e,s)=>{let{target:i,ex:n,ey:r,theta:o,originX:h,originY:c}=t;const u=i.translateToOriginPoint(i.getRelativeCenterPoint(),h,c);if(Ys(i,"lockRotation"))return!1;const d=Math.atan2(r-u.y,n-u.x),g=Math.atan2(s-u.y,e-u.x);let f=Hn(g-d+o);if(i.snapAngle&&i.snapAngle>0){const m=i.snapAngle,y=i.snapThreshold||m,b=Math.ceil(f/m)*m,x=Math.floor(f/m)*m;Math.abs(f-x)<y?f=x:Math.abs(f-b)<y&&(f=b)}f<0&&(f=360+f),f%=360;const p=i.angle!==f;return i.angle=f,p}));function Hm(a,t){const e=t.canvas,s=a[e.uniScaleKey];return e.uniformScaling&&!s||!e.uniformScaling&&s}function Vm(a,t,e){const s=Ys(a,"lockScalingX"),i=Ys(a,"lockScalingY");if(s&&i||!t&&(s||i)&&e||s&&t==="x"||i&&t==="y")return!0;const{width:n,height:r,strokeWidth:o}=a;return n===0&&o===0&&t!=="y"||r===0&&o===0&&t!=="x"}const u_=["e","se","s","sw","w","nw","n","ne","e"],Fh=(a,t,e)=>{const s=Hm(a,e);if(Vm(e,t.x!==0&&t.y===0?"x":t.x===0&&t.y!==0?"y":"",s))return $c;const i=Am(e,t);return"".concat(u_[i],"-resize")};function Mg(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{};const n=t.target,r=i.by,o=Hm(a,n);let h,c,u,d,g,f;if(Vm(n,r,o))return!1;if(t.gestureScale)c=t.scaleX*t.gestureScale,u=t.scaleY*t.gestureScale;else{if(h=vg(t,t.originX,t.originY,e,s),g=r!=="y"?Math.sign(h.x||t.signX||1):1,f=r!=="x"?Math.sign(h.y||t.signY||1):1,t.signX||(t.signX=g),t.signY||(t.signY=f),Ys(n,"lockScalingFlip")&&(t.signX!==g||t.signY!==f))return!1;if(d=n._getTransformedDimensions(),o&&!r){const y=Math.abs(h.x)+Math.abs(h.y),{original:b}=t,x=y/(Math.abs(d.x*b.scaleX/n.scaleX)+Math.abs(d.y*b.scaleY/n.scaleY));c=b.scaleX*x,u=b.scaleY*x}else c=Math.abs(h.x*n.scaleX/d.x),u=Math.abs(h.y*n.scaleY/d.y);xm(t)&&(c*=2,u*=2),t.signX!==g&&r!=="y"&&(t.originX=Sm(t.originX),c*=-1,t.signX=g),t.signY!==f&&r!=="x"&&(t.originY=Sm(t.originY),u*=-1,t.signY=f)}const p=n.scaleX,m=n.scaleY;return r?(r==="x"&&n.set(je,c),r==="y"&&n.set(hs,u)):(!Ys(n,"lockScalingX")&&n.set(je,c),!Ys(n,"lockScalingY")&&n.set(hs,u)),p!==n.scaleX||m!==n.scaleY}const tu=ta(jc,ea((a,t,e,s)=>Mg(a,t,e,s))),d_=ta(jc,ea((a,t,e,s)=>Mg(a,t,e,s,{by:"x"}))),g_=ta(jc,ea((a,t,e,s)=>Mg(a,t,e,s,{by:"y"}))),f_=["target","ex","ey","skewingSide"],Pg={x:{counterAxis:"y",scale:je,skew:Uo,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:hs,skew:Yo,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},p_=["ns","nesw","ew","nwse"],m_=(a,t,e)=>{if(t.x!==0&&Ys(e,"lockSkewingY")||t.y!==0&&Ys(e,"lockSkewingX"))return $c;const s=Am(e,t)%4;return"".concat(p_[s],"-resize")};function Gm(a,t,e,s,i){const{target:n}=e,{counterAxis:r,origin:o,lockSkewing:h,skew:c,flip:u}=Pg[a];if(Ys(n,h))return!1;const{origin:d,flip:g}=Pg[r],f=Zt(e[d])*(n[g]?-1:1),p=-Math.sign(f)*(n[u]?-1:1),m=.5*-((n[c]===0&&vg(e,tt,tt,s,i)[a]>0||n[c]>0?1:-1)*p)+.5;return ta(Kp,ea((b,x,C,A)=>function(M,D,k){let{target:P,ex:R,ey:F,skewingSide:I}=D,X=Ot(D,f_);const{skew:j}=Pg[M],N=k.subtract(new O(R,F)).divide(new O(P.scaleX,P.scaleY))[M],it=P[j],K=X[j],V=Math.tan(zt(K)),H=M==="y"?P._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:P._getTransformedDimensions({scaleX:1,scaleY:1}).y,Et=2*N*I/Math.max(H,1)+V,It=Hn(Math.atan(Et));P.set(j,It);const ie=it!==P[j];if(ie&&M==="y"){const{skewX:Wt,scaleX:Tt}=P,xe=P._getTransformedDimensions({skewY:it}),Vs=P._getTransformedDimensions(),Pt=Wt!==0?xe.x/Vs.x:1;Pt!==1&&P.set(je,Pt*Tt)}return ie}(a,x,new O(C,A))))(t,E(E({},e),{},{[o]:m,skewingSide:p}),s,i)}const v_=(a,t,e,s)=>Gm("x",a,t,e,s),b_=(a,t,e,s)=>Gm("y",a,t,e,s);function eu(a,t){return a[t.canvas.altActionKey]}const su=(a,t,e)=>{const s=eu(a,e);return t.x===0?s?Uo:hs:t.y===0?s?Yo:je:""},sa=(a,t,e)=>eu(a,e)?m_(0,t,e):Fh(a,t,e),Wm=(a,t,e,s)=>eu(a,t.target)?b_(a,t,e,s):d_(a,t,e,s),zm=(a,t,e,s)=>eu(a,t.target)?v_(a,t,e,s):g_(a,t,e,s),Xm=()=>({ml:new qs({x:-.5,y:0,cursorStyleHandler:sa,actionHandler:Wm,getActionName:su}),mr:new qs({x:.5,y:0,cursorStyleHandler:sa,actionHandler:Wm,getActionName:su}),mb:new qs({x:0,y:.5,cursorStyleHandler:sa,actionHandler:zm,getActionName:su}),mt:new qs({x:0,y:-.5,cursorStyleHandler:sa,actionHandler:zm,getActionName:su}),tl:new qs({x:-.5,y:-.5,cursorStyleHandler:Fh,actionHandler:tu}),tr:new qs({x:.5,y:-.5,cursorStyleHandler:Fh,actionHandler:tu}),bl:new qs({x:-.5,y:.5,cursorStyleHandler:Fh,actionHandler:tu}),br:new qs({x:.5,y:.5,cursorStyleHandler:Fh,actionHandler:tu}),mtr:new qs({x:0,y:-.5,actionHandler:c_,cursorStyleHandler:l_,offsetY:-40,withConnection:!0,actionName:ng})}),y_=()=>({mr:new qs({x:.5,y:0,actionHandler:Bm,cursorStyleHandler:sa,actionName:Th}),ml:new qs({x:-.5,y:0,actionHandler:Bm,cursorStyleHandler:sa,actionName:Th})}),__=()=>E(E({},Xm()),y_());class Ih extends qi{static getDefaults(){return E(E({},super.getDefaults()),Ih.ownDefaults)}constructor(t){super(),Object.assign(this,this.constructor.createControls(),Ih.ownDefaults),this.setOptions(t)}static createControls(){return{controls:Xm()}}_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(Bc))return!1}return super._updateCacheCanvas()}getActiveControl(){const t=this.__corner;return t?{key:t,control:this.controls[t],coord:this.oCoords[t]}:void 0}findControl(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];if(!this.hasControls||!this.canvas)return;this.__corner=void 0;const s=Object.entries(this.oCoords);for(let i=s.length-1;i>=0;i--){const[n,r]=s[i],o=this.controls[n];if(o.shouldActivate(n,this,t,e?r.touchCorner:r.corner))return this.__corner=n,{key:n,control:o,coord:this.oCoords[n]}}}calcOCoords(){const t=this.getViewportTransform(),e=this.getCenterPoint(),s=qo(e.x,e.y),i=Ko({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),n=Yt(s,i),r=Yt(t,n),o=Yt(r,[1/t[0],0,0,1/t[3],0,0]),h=this.group?Tr(this.calcTransformMatrix()):void 0;h&&(h.scaleX=Math.abs(h.scaleX),h.scaleY=Math.abs(h.scaleY));const c=this._calculateCurrentDimensions(h),u={};return this.forEachControl((d,g)=>{const f=d.positionHandler(c,o,this,d);u[g]=Object.assign(f,this._calcCornerCoords(d,f))}),u}_calcCornerCoords(t,e){const s=this.getTotalAngle();return{corner:t.calcCornerCoords(s,this.cornerSize,e.x,e.y,!1,this),touchCorner:t.calcCornerCoords(s,this.touchCornerSize,e.x,e.y,!0,this)}}setCoords(){super.setCoords(),this.canvas&&(this.oCoords=this.calcOCoords())}forEachControl(t){for(const e in this.controls)t(this.controls[e],e,this)}drawSelectionBackground(t){if(!this.selectionBackgroundColor||this.canvas&&this.canvas._activeObject!==this)return;t.save();const e=this.getRelativeCenterPoint(),s=this._calculateCurrentDimensions(),i=this.getViewportTransform();t.translate(e.x,e.y),t.scale(1/i[0],1/i[3]),t.rotate(zt(this.angle)),t.fillStyle=this.selectionBackgroundColor,t.fillRect(-s.x/2,-s.y/2,s.x,s.y),t.restore()}strokeBorders(t,e){t.strokeRect(-e.x/2,-e.y/2,e.x,e.y)}_drawBorders(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const i=E({hasControls:this.hasControls,borderColor:this.borderColor,borderDashArray:this.borderDashArray},s);t.save(),t.strokeStyle=i.borderColor,this._setLineDash(t,i.borderDashArray),this.strokeBorders(t,e),i.hasControls&&this.drawControlsConnectingLines(t,e),t.restore()}_renderControls(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const{hasBorders:s,hasControls:i}=this,n=E({hasBorders:s,hasControls:i},e),r=this.getViewportTransform(),o=n.hasBorders,h=n.hasControls,c=Yt(r,this.calcTransformMatrix()),u=Tr(c);t.save(),t.translate(u.translateX,u.translateY),t.lineWidth=this.borderScaleFactor,this.group===this.parent&&(t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1),this.flipX&&(u.angle-=180),t.rotate(zt(this.group?u.angle:this.angle)),o&&this.drawBorders(t,u,e),h&&this.drawControls(t,e),t.restore()}drawBorders(t,e,s){let i;if(s&&s.forActiveSelection||this.group){const n=Yc(this.width,this.height,kh(e)),r=this.isStrokeAccountedForInDimensions()?og:(this.strokeUniform?new O().scalarAdd(this.canvas?this.canvas.getZoom():1):new O(e.scaleX,e.scaleY)).scalarMultiply(this.strokeWidth);i=n.add(r).scalarAdd(this.borderScaleFactor).scalarAdd(2*this.padding)}else i=this._calculateCurrentDimensions().scalarAdd(this.borderScaleFactor);this._drawBorders(t,i,s)}drawControlsConnectingLines(t,e){let s=!1;t.beginPath(),this.forEachControl((i,n)=>{i.withConnection&&i.getVisibility(this,n)&&(s=!0,t.moveTo(i.x*e.x,i.y*e.y),t.lineTo(i.x*e.x+i.offsetX,i.y*e.y+i.offsetY))}),s&&t.stroke()}drawControls(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};t.save();const s=this.getCanvasRetinaScaling(),{cornerStrokeColor:i,cornerDashArray:n,cornerColor:r}=this,o=E({cornerStrokeColor:i,cornerDashArray:n,cornerColor:r},e);t.setTransform(s,0,0,s,0,0),t.strokeStyle=t.fillStyle=o.cornerColor,this.transparentCorners||(t.strokeStyle=o.cornerStrokeColor),this._setLineDash(t,o.cornerDashArray),this.forEachControl((h,c)=>{if(h.getVisibility(this,c)){const u=this.oCoords[c];h.render(t,u.x,u.y,o,this)}}),t.restore()}isControlVisible(t){return this.controls[t]&&this.controls[t].getVisibility(this,t)}setControlVisible(t,e){this._controlsVisibility||(this._controlsVisibility={}),this._controlsVisibility[t]=e}setControlsVisibility(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Object.entries(t).forEach(e=>{let[s,i]=e;return this.setControlVisible(s,i)})}clearContextTop(t){if(!this.canvas)return;const e=this.canvas.contextTop;if(!e)return;const s=this.canvas.viewportTransform;e.save(),e.transform(s[0],s[1],s[2],s[3],s[4],s[5]),this.transform(e);const i=this.width+4,n=this.height+4;return e.clearRect(-i/2,-n/2,i,n),t||e.restore(),e}onDeselect(t){return!1}onSelect(t){return!1}shouldStartDragging(t){return!1}onDragStart(t){return!1}canDrop(t){return!1}renderDragSourceEffect(t){}renderDropTargetEffect(t){}}function Um(a,t){return t.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(s=>{s!=="constructor"&&Object.defineProperty(a.prototype,s,Object.getOwnPropertyDescriptor(e.prototype,s)||Object.create(null))})}),a}T(Ih,"ownDefaults",{noScaleCache:!0,lockMovementX:!1,lockMovementY:!1,lockRotation:!1,lockScalingX:!1,lockScalingY:!1,lockSkewingX:!1,lockSkewingY:!1,lockScalingFlip:!1,cornerSize:13,touchCornerSize:24,transparentCorners:!0,cornerColor:"rgb(178,204,255)",cornerStrokeColor:"",cornerStyle:"rect",cornerDashArray:null,hasControls:!0,borderColor:"rgb(178,204,255)",borderDashArray:null,borderOpacityWhenMoving:.4,borderScaleFactor:1,hasBorders:!0,selectionBackgroundColor:"",selectable:!0,evented:!0,perPixelTargetFind:!1,activeOn:"down",hoverCursor:null,moveCursor:null});class Ce extends Ih{}Um(Ce,[Tm]),W.setClass(Ce),W.setClass(Ce,"object");const Ym=(a,t,e,s)=>{const i=2*(s=Math.round(s))+1,{data:n}=a.getImageData(t-s,e-s,i,i);for(let r=3;r<n.length;r+=4)if(n[r]>0)return!1;return!0};class $m{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=Kc(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 w_=new O;class ia extends $m{static getOrthogonalRotationFactor(t,e){const s=e?Jc(t,e):Om(t);return Math.abs(s)<jn?-1:1}constructor(t,e,s,i){super(i),T(this,"AB",void 0),T(this,"AC",void 0),T(this,"alpha",void 0),T(this,"bisector",void 0),this.A=new 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=Jc(this.AB,this.AC),this.bisector=Zc(wg(this.AB.eq(w_)?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=xg(i),r=ia.getOrthogonalRotationFactor(n,this.bisector);return this.scaleUnitVector(n,s*r)}projectBevel(){const t=[];return(this.alpha%Ui==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?Qc(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return Qc(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(ia.getOrthogonalRotationFactor(this.bisector),ia.getOrthogonalRotationFactor(new O(this.bisector.y,this.bisector.x)));return[new O(1,0).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i),new O(0,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i)].forEach(n=>{Sg(n,t,e)&&s.push(this.A.add(n))}),s}projectRoundWithSkew(t,e){const s=[],{skewX:i,skewY:n,scaleX:r,scaleY:o,strokeUniform:h}=this.options,c=new O(Math.tan(zt(i)),Math.tan(zt(n))),u=this.strokeProjectionMagnitude,d=h?u/o/Math.sqrt(1/o**2+1/r**2*c.y**2):u/Math.sqrt(1+c.y**2),g=new O(Math.sqrt(Math.max(u**2-d**2,0)),d),f=h?u/Math.sqrt(1+c.x**2*(1/o)**2/(1/r+1/r*c.x*c.y)**2):u/Math.sqrt(1+c.x**2/(1+c.x*c.y)**2),p=new O(f,Math.sqrt(Math.max(u**2-f**2,0)));return[p,p.scalarMultiply(-1),g,g.scalarMultiply(-1)].map(m=>this.applySkew(h?m.multiply(this.strokeUniformScalar):m)).forEach(m=>{Sg(m,t,e)&&s.push(this.applySkew(this.A).add(m))}),s}projectRound(){const t=[];t.push(...this.projectBevel());const e=this.alpha%Ui==0,s=this.applySkew(this.A),i=t[e?0:2].subtract(s),n=t[e?1:0].subtract(s),r=e?this.applySkew(this.AB.scalarMultiply(-1)):this.applySkew(this.bisector.multiply(this.strokeUniformScalar).scalarMultiply(-1)),o=Zo(i,r)>0,h=o?i:n,c=o?n:i;return this.isSkewed()?t.push(...this.projectRoundWithSkew(h,c)):t.push(...this.projectRoundNoSkew(h,c)),t}projectPoints(){switch(this.options.strokeLineJoin){case"miter":return this.projectMiter();case"round":return this.projectRound();default:return this.projectBevel()}}project(){return this.projectPoints().map(t=>({originPoint:this.A,projectedPoint:t,angle:this.alpha,bisector:this.bisector}))}}class qm extends $m{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(xg(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 ia(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(Zc(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 Km=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];const s=[];if(a.length===0)return s;const i=a.reduce((n,r)=>(n[n.length-1].eq(r)||n.push(new O(r)),n),[new O(a[0])]);if(i.length===1)e=!0;else if(!e){const n=i[0],r=((o,h)=>{for(let c=o.length-1;c>=0;c--)if(h(o[c],c,o))return c;return-1})(i,o=>!o.eq(n));i.splice(r+1)}return i.forEach((n,r,o)=>{let h,c;r===0?(c=o[1],h=e?n:o[o.length-1]):r===o.length-1?(h=o[r-1],c=e?n:o[0]):(h=o[r-1],c=o[r+1]),e&&o.length===1?s.push(...new qm(n,n,t).project()):!e||r!==0&&r!==o.length-1?s.push(...new ia(n,h,c,t).project()):s.push(...new qm(n,r===0?c:h,t).project())}),s},Og=a=>{const t={};return Object.keys(a).forEach(e=>{t[e]={},Object.keys(a[e]).forEach(s=>{t[e][s]=E({},a[e][s])})}),t},Qm=a=>a.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">"),iu=a=>{const t=[];for(let e,s=0;s<a.length;s++)(e=x_(a,s))!==!1&&t.push(e);return t},x_=(a,t)=>{const e=a.charCodeAt(t);if(isNaN(e))return"";if(e<55296||e>57343)return a.charAt(t);if(55296<=e&&e<=56319){if(a.length<=t+1)throw"High surrogate without following low surrogate";const i=a.charCodeAt(t+1);if(56320>i||i>57343)throw"High surrogate without following low surrogate";return a.charAt(t)+a.charAt(t+1)}if(t===0)throw"Low surrogate without preceding high surrogate";const s=a.charCodeAt(t-1);if(55296>s||s>56319)throw"Low surrogate without preceding high surrogate";return!1};var S_=Object.freeze({__proto__:null,capitalize:function(a){let t=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return"".concat(a.charAt(0).toUpperCase()).concat(t?a.slice(1):a.slice(1).toLowerCase())},escapeXml:Qm,graphemeSplit:iu});const nu=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];return a.fill!==t.fill||a.stroke!==t.stroke||a.strokeWidth!==t.strokeWidth||a.fontSize!==t.fontSize||a.fontFamily!==t.fontFamily||a.fontWeight!==t.fontWeight||a.fontStyle!==t.fontStyle||a.textBackgroundColor!==t.textBackgroundColor||a.deltaY!==t.deltaY||e&&(a.overline!==t.overline||a.underline!==t.underline||a.linethrough!==t.linethrough)},Jm=(a,t)=>{const e=t.split(`
|
|
67
|
+
`),s=[];let i=-1,n={};a=Og(a);for(let r=0;r<e.length;r++){const o=iu(e[r]);if(a[r])for(let h=0;h<o.length;h++){i++;const c=a[r][h];c&&Object.keys(c).length>0&&(nu(n,c,!0)?s.push({start:i,end:i+1,style:c}):s[s.length-1].end++),n=c||{}}else i+=o.length,n={}}return s},Zm=(a,t)=>{if(!Array.isArray(a))return Og(a);const e=t.split(ig),s={};let i=-1,n=0;for(let r=0;r<e.length;r++){const o=iu(e[r]);for(let h=0;h<o.length;h++)i++,a[n]&&a[n].start<=i&&i<a[n].end&&(s[r]=s[r]||{},s[r][h]=E({},a[n].style),i===a[n].end-1&&n++)}return s},Vn=["display","transform",Jt,"fill-opacity","fill-rule","opacity",Ne,"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 t0(a,t){const e=a.nodeName,s=a.getAttribute("class"),i=a.getAttribute("id"),n="(?![a-zA-Z\\-]+)";let r;if(r=new RegExp("^"+e,"i"),t=t.replace(r,""),i&&t.length&&(r=new RegExp("#"+i+n,"i"),t=t.replace(r,"")),s&&t.length){const o=s.split(" ");for(let h=o.length;h--;)r=new RegExp("\\."+o[h]+n,"i"),t=t.replace(r,"")}return t.length===0}function C_(a,t){let e=!0;const s=t0(a,t.pop());return s&&t.length&&(e=function(i,n){let r,o=!0;for(;i.parentElement&&i.parentElement.nodeType===1&&n.length;)o&&(r=n.pop()),o=t0(i=i.parentElement,r);return n.length===0}(a,t)),s&&e&&t.length===0}const A_=a=>{var t;return(t=Wy[a])!==null&&t!==void 0?t:a},T_=new RegExp("(".concat($s,")"),"gi"),E_=a=>a.replace(T_," $1 ").replace(/,/gi," ").replace(/\s+/gi," ");var e0,s0,i0,n0,r0,o0,a0;const He="(".concat($s,")"),k_=String.raw(e0||(e0=In(["(skewX)(",")"],["(skewX)\\(","\\)"])),He),M_=String.raw(s0||(s0=In(["(skewY)(",")"],["(skewY)\\(","\\)"])),He),P_=String.raw(i0||(i0=In(["(rotate)(","(?: "," ",")?)"],["(rotate)\\(","(?: "," ",")?\\)"])),He,He,He),O_=String.raw(n0||(n0=In(["(scale)(","(?: ",")?)"],["(scale)\\(","(?: ",")?\\)"])),He,He),D_=String.raw(r0||(r0=In(["(translate)(","(?: ",")?)"],["(translate)\\(","(?: ",")?\\)"])),He,He),R_=String.raw(o0||(o0=In(["(matrix)("," "," "," "," "," ",")"],["(matrix)\\("," "," "," "," "," ","\\)"])),He,He,He,He,He,He),Dg="(?:".concat(R_,"|").concat(D_,"|").concat(P_,"|").concat(O_,"|").concat(k_,"|").concat(M_,")"),L_="(?:".concat(Dg,"*)"),F_=String.raw(a0||(a0=In(["^s*(?:","?)s*$"],["^\\s*(?:","?)\\s*$"])),L_),I_=new RegExp(F_),j_=new RegExp(Dg),N_=new RegExp(Dg,"g");function ru(a){const t=[];if(!(a=E_(a).replace(/\s*([()])\s*/gi,"$1"))||a&&!I_.test(a))return[...Fe];for(const e of a.matchAll(N_)){const s=j_.exec(e[0]);if(!s)continue;let i=Fe;const n=s.filter(p=>!!p),[,r,...o]=n,[h,c,u,d,g,f]=o.map(p=>parseFloat(p));switch(r){case"translate":i=qo(h,c);break;case ng:i=Ko({angle:h},{x:c,y:u});break;case Bc:i=zc(h,c);break;case Uo:i=hg(h);break;case Yo:i=lg(h);break;case"matrix":i=[h,c,u,d,g,f]}t.push(i)}return Wc(t)}function B_(a,t,e,s){const i=Array.isArray(t);let n,r=t;if(a!==Jt&&a!==Ne||t!==Ie){if(a==="strokeUniform")return t==="non-scaling-stroke";if(a==="strokeDashArray")r=t===Ie?null:t.replace(/,/g," ").split(/\s+/).map(parseFloat);else if(a==="transformMatrix")r=e&&e.transformMatrix?Yt(e.transformMatrix,ru(t)):ru(t);else if(a==="visible")r=t!==Ie&&t!=="hidden",e&&e.visible===!1&&(r=!1);else if(a==="opacity")r=parseFloat(t),e&&e.opacity!==void 0&&(r*=e.opacity);else if(a==="textAnchor")r=t==="start"?vt:t==="end"?Ut:tt;else if(a==="charSpacing")n=Be(t,s)/s*1e3;else if(a==="paintFirst"){const o=t.indexOf(Jt),h=t.indexOf(Ne);r=Jt,(o>-1&&h>-1&&h<o||o===-1&&h>-1)&&(r=Ne)}else{if(a==="href"||a==="xlink:href"||a==="font"||a==="id")return t;if(a==="imageSmoothing")return t==="optimizeQuality";n=i?t.map(Be):Be(t,s)}}else r="";return!i&&isNaN(n)?r:n}function H_(a,t){const e=a.match(Gy);if(!e)return;const s=e[1],i=e[3],n=e[4],r=e[5],o=e[6];s&&(t.fontStyle=s),i&&(t.fontWeight=isNaN(parseFloat(i))?i:parseFloat(i)),n&&(t.fontSize=Be(n)),o&&(t.fontFamily=o),r&&(t.lineHeight=r==="normal"?1:r)}function Rg(a,t){a.replace(/;\s*$/,"").split(";").forEach(e=>{if(!e)return;const[s,i]=e.split(":");t[s.trim().toLowerCase()]=i.trim()})}function V_(a){const t={},e=a.getAttribute("style");return e&&(typeof e=="string"?Rg(e,t):function(s,i){Object.entries(s).forEach(n=>{let[r,o]=n;o!==void 0&&(i[r.toLowerCase()]=o)})}(e,t)),t}const G_={stroke:"strokeOpacity",fill:"fillOpacity"};function Ki(a,t,e){if(!a)return{};let s,i={},n=eg;a.parentNode&&km.test(a.parentNode.nodeName)&&(i=Ki(a.parentElement,t,e),i.fontSize&&(s=n=Be(i.fontSize)));const r=E(E(E({},t.reduce((c,u)=>{const d=a.getAttribute(u);return d&&(c[u]=d),c},{})),function(c){let u=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},d={};for(const g in u)C_(c,g.split(" "))&&(d=E(E({},d),u[g]));return d}(a,e)),V_(a));r[_g]&&a.setAttribute(_g,r[_g]),r[yg]&&(s=Be(r[yg],n),r[yg]="".concat(s));const o={};for(const c in r){const u=A_(c),d=B_(u,r[c],i,s);o[u]=d}o&&o.font&&H_(o.font,o);const h=E(E({},i),o);return km.test(a.nodeName)?h:function(c){const u=Ce.getDefaults();return Object.entries(G_).forEach(d=>{let[g,f]=d;if(c[f]===void 0||c[g]==="")return;if(c[g]===void 0){if(!u[g])return;c[g]=u[g]}if(c[g].indexOf("url(")===0)return;const p=new _t(c[g]);c[g]=p.setAlpha(Dt(p.getAlpha()*c[f],2)).toRgba()}),c}(h)}const W_=["left","top","width","height","visible"],h0=["rx","ry"];class yi extends Ce{static getDefaults(){return E(E({},super.getDefaults()),yi.ownDefaults)}constructor(t){super(),Object.assign(this,yi.ownDefaults),this.setOptions(t),this._initRxRy()}_initRxRy(){const{rx:t,ry:e}=this;t&&!e?this.ry=t:e&&!t&&(this.rx=e)}_render(t){const{width:e,height:s}=this,i=-e/2,n=-s/2,r=this.rx?Math.min(this.rx,e/2):0,o=this.ry?Math.min(this.ry,s/2):0,h=r!==0||o!==0;t.beginPath(),t.moveTo(i+r,n),t.lineTo(i+e-r,n),h&&t.bezierCurveTo(i+e-Nn*r,n,i+e,n+Nn*o,i+e,n+o),t.lineTo(i+e,n+s-o),h&&t.bezierCurveTo(i+e,n+s-Nn*o,i+e-Nn*r,n+s,i+e-r,n+s),t.lineTo(i+r,n+s),h&&t.bezierCurveTo(i+Nn*r,n+s,i,n+s-Nn*o,i,n+s-o),t.lineTo(i,n+o),h&&t.bezierCurveTo(i,n+Nn*o,i+Nn*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([...h0,...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=Ki(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,width:o=0,height:h=0,visible:c=!0}=i,u=Ot(i,W_);return new this(E(E(E({},e),u),{},{left:n,top:r,width:o,height:h,visible:!!(c&&o&&h)}))}}T(yi,"type","Rect"),T(yi,"cacheProperties",[...$i,...h0]),T(yi,"ownDefaults",{rx:0,ry:0}),T(yi,"ATTRIBUTE_NAMES",[...Vn,"x","y","rx","ry","width","height"]),W.setClass(yi),W.setSVGClass(yi);const Qi="initialization",ou="added",Lg="removed",au="imperative",l0=(a,t)=>{const{strokeUniform:e,strokeWidth:s,width:i,height:n,group:r}=t,o=r&&r!==a?Lh(r.calcTransformMatrix(),a.calcTransformMatrix()):null,h=o?t.getRelativeCenterPoint().transform(o):t.getRelativeCenterPoint(),c=!t.isStrokeAccountedForInDimensions(),u=e&&c?_m(new O(s,s),void 0,a.calcTransformMatrix()):og,d=!e&&c?s:0,g=Yc(i+d,n+d,Wc([o,t.calcOwnMatrix()],!0)).add(u).scalarDivide(2);return[h.subtract(g),h.add(g)]};class hu{calcLayoutResult(t,e){if(this.shouldPerformLayout(t))return this.calcBoundingBox(e,t)}shouldPerformLayout(t){let{type:e,prevStrategy:s,strategy:i}=t;return e===Qi||e===au||!!s&&i!==s}shouldLayoutClipPath(t){let{type:e,target:{clipPath:s}}=t;return e!==Qi&&s&&!s.absolutePositioned}getInitialSize(t,e){return e.size}calcBoundingBox(t,e){const{type:s,target:i}=e;if(s===au&&e.overrides)return e.overrides;if(t.length===0)return;const{left:n,top:r,width:o,height:h}=bi(t.map(d=>l0(i,d)).reduce((d,g)=>d.concat(g),[])),c=new O(o,h),u=new O(n,r).add(c.scalarDivide(2));if(s===Qi){const d=this.getInitialSize(e,{size:c,center:u});return{center:u,relativeCorrection:new O(0,0),size:d}}return{center:u.transform(i.calcOwnMatrix()),size:c}}}T(hu,"type","strategy");class Fg extends hu{shouldPerformLayout(t){return!0}}T(Fg,"type","fit-content"),W.setClass(Fg);const z_=["strategy"],X_=["target","strategy","bubbles","prevStrategy"],c0="layoutManager";class jh{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:new Fg;T(this,"strategy",void 0),this.strategy=t,this._subscriptions=new Map}performLayout(t){const e=E(E({bubbles:!0,strategy:this.strategy},t),{},{prevStrategy:this._prevLayoutStrategy,stopPropagation(){this.bubbles=!1}});this.onBeforeLayout(e);const s=this.getLayoutResult(e);s&&this.commitLayout(e,s),this.onAfterLayout(e,s),this._prevLayoutStrategy=e.strategy}attachHandlers(t,e){const{target:s}=e;return[Hc,$p,Th,qp,jc,Kp,Nc,Ry,Ly].map(i=>t.on(i,n=>this.performLayout(i===Hc?{type:"object_modified",trigger:i,e:n,target:s}:{type:"object_modifying",trigger:i,e:n,target:s})))}subscribe(t,e){this.unsubscribe(t,e);const s=this.attachHandlers(t,e);this._subscriptions.set(t,s)}unsubscribe(t,e){(this._subscriptions.get(t)||[]).forEach(s=>s()),this._subscriptions.delete(t)}unsubscribeTargets(t){t.targets.forEach(e=>this.unsubscribe(e,t))}subscribeTargets(t){t.targets.forEach(e=>this.subscribe(e,t))}onBeforeLayout(t){const{target:e,type:s}=t,{canvas:i}=e;if(s===Qi||s===ou?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===au&&t.deep){const n=Ot(t,z_);e.forEachObject(r=>r.layoutManager&&r.layoutManager.performLayout(E(E({},n),{},{bubbles:!1,target:r})))}}getLayoutResult(t){const{target:e,strategy:s,type:i}=t,n=s.calcLayoutResult(t,e.getObjects());if(!n)return;const r=i===Qi?new O:e.getRelativeCenterPoint(),{center:o,correction:h=new O,relativeCorrection:c=new O}=n,u=r.subtract(o).add(h).transform(i===Qi?Fe:Ze(e.calcOwnMatrix()),!0).add(c);return{result:n,prevCenter:r,nextCenter:o,offset:u}}commitLayout(t,e){const{target:s}=t,{result:{size:i},nextCenter:n}=e;var r,o;s.set({width:i.x,height:i.y}),this.layoutObjects(t,e),t.type===Qi?s.set({left:(r=t.x)!==null&&r!==void 0?r:n.x+i.x*Zt(s.originX),top:(o=t.y)!==null&&o!==void 0?o:n.y+i.y*Zt(s.originY)}):(s.setPositionByOrigin(n,tt,tt),s.setCoords(),s.set("dirty",!0))}layoutObjects(t,e){const{target:s}=t;s.forEachObject(i=>{i.group===s&&this.layoutObject(t,e,i)}),t.strategy.shouldLayoutClipPath(t)&&this.layoutObject(t,e,s.clipPath)}layoutObject(t,e,s){let{offset:i}=e;s.set({left:s.left+i.x,top:s.top+i.y})}onAfterLayout(t,e){const{target:s,strategy:i,bubbles:n,prevStrategy:r}=t,o=Ot(t,X_),{canvas:h}=s;s.fire("layout:after",{context:t,result:e}),h&&h.fire("object:layout:after",{context:t,result:e,target:s});const c=s.parent;n&&c!=null&&c.layoutManager&&((o.path||(o.path=[])).push(s),c.layoutManager.performLayout(E(E({},o),{},{target:c}))),s.set("dirty",!0)}dispose(){const{_subscriptions:t}=this;t.forEach(e=>e.forEach(s=>s())),t.clear()}toObject(){return{type:c0,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}W.setClass(jh,c0);const U_=["type","objects","layoutManager"];class Y_ extends jh{performLayout(){}}class _i extends Qp(Ce){static getDefaults(){return E(E({},super.getDefaults()),_i.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),T(this,"_activeObjects",[]),T(this,"__objectSelectionTracker",void 0),T(this,"__objectSelectionDisposer",void 0),Object.assign(this,_i.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 jh,this.layoutManager.performLayout({type:Qi,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(Xi("error","Group: circular object trees are not supported, this call has no effect"),!1):this._objects.indexOf(t)===-1||(Xi("error","Group: duplicate objects are not supported inside group, this call has no effect"),!1)}_filterObjectsBeforeEnteringGroup(t){return t.filter((e,s,i)=>this.canEnterGroup(e)&&i.indexOf(e)===s)}add(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];const i=this._filterObjectsBeforeEnteringGroup(e),n=super.add(...i);return this._onAfterObjectsChange(ou,i),n}insertAt(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),i=1;i<e;i++)s[i-1]=arguments[i];const n=this._filterObjectsBeforeEnteringGroup(s),r=super.insertAt(t,...n);return this._onAfterObjectsChange(ou,n),r}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange(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&&Jo(t,Yt(Ze(this.calcTransformMatrix()),t.calcTransformMatrix())),this._shouldSetNestedCoords()&&t.setCoords(),t._set("group",this),t._set("canvas",this.canvas),this._watchObject(!0,t);const s=this.canvas&&this.canvas.getActiveObject&&this.canvas.getActiveObject();s&&(s===t||t.isDescendantOf(s))&&this._activeObjects.push(t)}exitGroup(t,e){this._exitGroup(t,e),t._set("parent",void 0),t._set("canvas",void 0)}_exitGroup(t,e){t._set("group",void 0),e||(Jo(t,Yt(this.calcTransformMatrix(),t.calcTransformMatrix())),t.setCoords()),this._watchObject(!1,t);const s=this._activeObjects.length>0?this._activeObjects.indexOf(t):-1;s>-1&&this._activeObjects.splice(s,1)}shouldCache(){const t=Ce.prototype.shouldCache.call(this);if(t){for(let e=0;e<this._objects.length;e++)if(this._objects[e].willDrawShadow())return this.ownCaching=!1,!1}return t}willDrawShadow(){if(super.willDrawShadow())return!0;for(let t=0;t<this._objects.length;t++)if(this._objects[t].willDrawShadow())return!0;return!1}isOnACache(){return this.ownCaching||!!this.parent&&this.parent.isOnACache()}drawObject(t,e,s){this._renderBackground(t);for(let n=0;n<this._objects.length;n++){var i;const r=this._objects[n];(i=this.canvas)!==null&&i!==void 0&&i.preserveObjectStacking&&r.group!==this?(t.save(),t.transform(...Ze(this.calcTransformMatrix())),r.render(t),t.restore()):r.group===this&&r.render(t)}this._drawClipPath(t,this.clipPath,s)}setCoords(){super.setCoords(),this._shouldSetNestedCoords()&&this.forEachObject(t=>t.setCoords())}triggerLayout(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.layoutManager.performLayout(E({target:this,type:au},t))}render(t){this._transformDone=!0,super.render(t),this._transformDone=!1}__serializeObjects(t,e){const s=this.includeDefaultValues;return this._objects.filter(function(i){return!i.excludeFromExport}).map(function(i){const n=i.includeDefaultValues;i.includeDefaultValues=s;const r=i[t||"toObject"](e);return i.includeDefaultValues=n,r})}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=this.layoutManager.toObject();return E(E(E({},super.toObject(["subTargetCheck","interactive",...t])),e.strategy!=="fit-content"||this.includeDefaultValues?{layoutManager:e}:{}),{},{objects:this.__serializeObjects("toObject",t)})}toString(){return"#<Group: (".concat(this.complexity(),")>")}dispose(){this.layoutManager.unsubscribeTargets({targets:this.getObjects(),target:this}),this._activeObjects=[],this.forEachObject(t=>{this._watchObject(!1,t),t.dispose()}),super.dispose()}_createSVGBgRect(t){if(!this.backgroundColor)return"";const e=yi.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=Pt(t,V_);return Promise.all([za(i,e),vh(r,e)]).then(a=>{let[h,l]=a;const u=new this(h,E(E(E({},r),l),{},{layoutManager:new G_}));if(n){const d=V.getClass(n.type),g=V.getClass(n.strategy);u.layoutManager=new d(new g)}else u.layoutManager=new Ch;return u.layoutManager.subscribeTargets({type:ji,target:u,targets:u.getObjects()}),u.setCoords(),u})}}T(ci,"type","Group"),T(ci,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),V.setClass(ci);const Zm=(o,t)=>Math.min(t.width/o.width,t.height/o.height),t0=(o,t)=>Math.max(t.width/o.width,t.height/o.height),_g="\\s*,?\\s*",Ah="".concat(_g,"(").concat(Bs,")"),Y_="".concat(Ah).concat(Ah).concat(Ah).concat(_g,"([01])").concat(_g,"([01])").concat(Ah).concat(Ah),U_={m:"l",M:"L"},q_=(o,t,e,s,i,n,r,a,h,l,u)=>{const d=Fs(o),g=Ls(o),f=Fs(t),p=Ls(t),m=e*i*f-s*n*p+r,_=s*i*f+e*n*p+a;return["C",l+h*(-e*i*g-s*n*d),u+h*(-s*i*g+e*n*d),m+h*(e*i*p+s*n*f),_+h*(s*i*p-e*n*f),m,_]},e0=(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 wg(o,t,e,s,i,n,r,a){let h;if(dt.cachesBoundsOfCurve&&(h=[...arguments].join(),dh.boundsOfCurveCache[h]))return dh.boundsOfCurveCache[h];const l=Math.sqrt,u=Math.abs,d=[],g=[[0,0],[0,0]];let f=6*o-12*e+6*i,p=-3*o+9*e-9*i+3*r,m=3*e-3*o;for(let A=0;A<2;++A){if(A>0&&(f=6*t-12*s+6*n,p=-3*t+9*s-9*n+3*a,m=3*s-3*t),u(p)<1e-12){if(u(f)<1e-12)continue;const R=-m/f;0<R&&R<1&&d.push(R);continue}const k=f*f-4*m*p;if(k<0)continue;const P=l(k),M=(-f+P)/(2*p);0<M&&M<1&&d.push(M);const O=(-f-P)/(2*p);0<O&&O<1&&d.push(O)}let _=d.length;const b=_,x=i0(o,t,e,s,i,n,r,a);for(;_--;){const{x:A,y:k}=x(d[_]);g[0][_]=A,g[1][_]=k}g[0][b]=o,g[1][b]=t,g[0][b+1]=r,g[1][b+1]=a;const S=[new D(Math.min(...g[0]),Math.min(...g[1])),new D(Math.max(...g[0]),Math.max(...g[1]))];return dt.cachesBoundsOfCurve&&(dh.boundsOfCurveCache[h]=S),S}const $_=(o,t,e)=>{let[s,i,n,r,a,h,l,u]=e;const d=((g,f,p,m,_,b,x)=>{if(p===0||m===0)return[];let S=0,A=0,k=0;const P=Math.PI,M=x*Nd,O=Ls(M),R=Fs(M),I=.5*(-R*g-O*f),j=.5*(-R*f+O*g),G=p**2,L=m**2,H=j**2,$=I**2,J=G*L-G*H-L*$;let Y=Math.abs(p),X=Math.abs(m);if(J<0){const ze=Math.sqrt(1-J/(G*L));Y*=ze,X*=ze}else k=(_===b?-1:1)*Math.sqrt(J/(G*H+L*$));const Ot=k*Y*j/X,zt=-k*X*I/Y,te=R*Ot-O*zt+.5*g,Ht=O*Ot+R*zt+.5*f;let At=e0(1,0,(I-Ot)/Y,(j-zt)/X),_e=e0((I-Ot)/Y,(j-zt)/X,(-I-Ot)/Y,(-j-zt)/X);b===0&&_e>0?_e-=2*P:b===1&&_e<0&&(_e+=2*P);const Ps=Math.ceil(Math.abs(_e/P*2)),kt=[],gt=_e/Ps,Ds=8/3*Math.sin(gt/4)*Math.sin(gt/4)/Math.sin(gt/2);let ri=At+gt;for(let ze=0;ze<Ps;ze++)kt[ze]=q_(At,ri,R,O,Y,X,te,Ht,Ds,S,A),S=kt[ze][5],A=kt[ze][6],At=ri,ri+=gt;return kt})(l-o,u-t,i,n,a,h,r);for(let g=0,f=d.length;g<f;g++)d[g][1]+=o,d[g][2]+=t,d[g][3]+=o,d[g][4]+=t,d[g][5]+=o,d[g][6]+=t;return d},s0=o=>{let t=0,e=0,s=0,i=0;const n=[];let r,a=0,h=0;for(const l of o){const u=[...l];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":$_(t,e,u).forEach(g=>n.push(g)),t=u[6],e=u[7];break;case"z":case"Z":t=s,e=i,d=["Z"]}d?(n.push(d),r=d[0]):r=""}return n},Uc=(o,t,e,s)=>Math.sqrt((e-o)**2+(s-t)**2),i0=(o,t,e,s,i,n,r,a)=>h=>{const l=h**3,u=(f=>3*f**2*(1-f))(h),d=(f=>3*f*(1-f)**2)(h),g=(f=>(1-f)**3)(h);return new D(r*l+i*u+e*d+o*g,a*l+n*u+s*d+t*g)},n0=o=>o**2,r0=o=>2*o*(1-o),a0=o=>(1-o)**2,K_=(o,t,e,s,i,n,r,a)=>h=>{const l=n0(h),u=r0(h),d=a0(h),g=3*(d*(e-o)+u*(i-e)+l*(r-i)),f=3*(d*(s-t)+u*(n-s)+l*(a-n));return Math.atan2(f,g)},J_=(o,t,e,s,i,n)=>r=>{const a=n0(r),h=r0(r),l=a0(r);return new D(i*a+e*h+o*l,n*a+s*h+t*l)},Q_=(o,t,e,s,i,n)=>r=>{const a=1-r,h=2*(a*(e-o)+r*(i-e)),l=2*(a*(s-t)+r*(n-s));return Math.atan2(l,h)},o0=(o,t,e)=>{let s=new D(t,e),i=0;for(let n=1;n<=100;n+=1){const r=o(n/100);i+=Uc(s.x,s.y,r.x,r.y),s=r}return i},Z_=(o,t)=>{let e,s=0,i=0,n={x:o.x,y:o.y},r=E({},n),a=.01,h=0;const l=o.iterator,u=o.angleFinder;for(;i<t&&a>1e-4;)r=l(s),h=s,e=Uc(n.x,n.y,r.x,r.y),e+i>t?(s-=a,a/=2):(n=r,s+=a,i+=e);return E(E({},r),{},{angle:u(h)})},xg=o=>{let t,e,s=0,i=0,n=0,r=0,a=0;const h=[];for(const l of o){const u={x:i,y:n,command:l[0],length:0};switch(l[0]){case"M":e=u,e.x=r=i=l[1],e.y=a=n=l[2];break;case"L":e=u,e.length=Uc(i,n,l[1],l[2]),i=l[1],n=l[2];break;case"C":t=i0(i,n,l[1],l[2],l[3],l[4],l[5],l[6]),e=u,e.iterator=t,e.angleFinder=K_(i,n,l[1],l[2],l[3],l[4],l[5],l[6]),e.length=o0(t,i,n),i=l[5],n=l[6];break;case"Q":t=J_(i,n,l[1],l[2],l[3],l[4]),e=u,e.iterator=t,e.angleFinder=Q_(i,n,l[1],l[2],l[3],l[4]),e.length=o0(t,i,n),i=l[3],n=l[4];break;case"Z":e=u,e.destX=r,e.destY=a,e.length=Uc(i,n,r,a),i=r,n=a}s+=e.length,h.push(e)}return h.push({length:s,x:i,y:n}),h},h0=function(o,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:xg(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 E(E({},new D(i.x,i.y).lerp(new D(i.destX,i.destY),n)),{},{angle:Math.atan2(i.destY-i.y,i.destX-i.x)});case"L":return E(E({},new D(i.x,i.y).lerp(new D(r[1],r[2]),n)),{},{angle:Math.atan2(r[2]-i.y,r[1]-i.x)});case"C":case"Q":return Z_(i,t)}},tw=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),l0=new RegExp(Y_,"g"),ew=new RegExp(Bs,"gi"),sw={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},c0=o=>{var t;const e=[],s=(t=o.match(tw))!==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=sw[n.toLowerCase()];let a=[];if(n==="a"||n==="A"){l0.lastIndex=0;for(let h=null;h=l0.exec(i);)a.push(...h.slice(1))}else a=i.match(ew)||[];for(let h=0;h<a.length;h+=r){const l=new Array(r),u=U_[n];l[0]=h>0&&u?u:n;for(let d=0;d<r;d++)l[d+1]=parseFloat(a[h+d]);e.push(l)}}return e},iw=function(o){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=new D(o[0]),s=new D(o[1]),i=1,n=0;const r=[],a=o.length,h=a>2;let l;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]),l=1;l<a;l++){if(!e.eq(s)){const u=e.midPointFrom(s);r.push(["Q",e.x,e.y,u.x,u.y])}e=o[l],l+1<o.length&&(s=o[l+1])}return h&&(i=e.x>o[l-2].x?1:e.x===o[l-2].x?0:-1,n=e.y>o[l-2].y?1:e.y===o[l-2].y?0:-1),r.push(["L",e.x+i*t,e.y+n*t]),r},u0=(o,t)=>o.map(e=>e.map((s,i)=>i===0||t===void 0?s:Dt(s,t)).join(" ")).join(" ");function qc(o,t){const e=o.style;e&&t&&(typeof t=="string"?e.cssText+=";"+t:Object.entries(t).forEach(s=>{let[i,n]=s;return e.setProperty(i,n)}))}const nw=(o,t)=>Math.floor(Math.random()*(t-o+1))+o;function d0(o){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const e=t.onComplete||gr,s=new(_c()).XMLHttpRequest,i=t.signal,n=function(){s.abort()},r=function(){i&&i.removeEventListener("abort",n),s.onerror=s.ontimeout=gr};if(i&&i.aborted)throw new Id("request");return i&&i.addEventListener("abort",n,{once:!0}),s.onreadystatechange=function(){s.readyState===4&&(r(),e(s),s.onreadystatechange=gr)},s.onerror=s.ontimeout=r,s.open("get",o,!0),s.send(),s}const $c=(o,t)=>{let e=o._findCenterFromElement();o.transformMatrix&&((s=>{if(s.transformMatrix){const{scaleX:i,scaleY:n,angle:r,skewX:a}=pr(s.transformMatrix);s.flipX=!1,s.flipY=!1,s.set(Fe,i),s.set(is,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,st,st)};var rw=Object.freeze({__proto__:null,addTransformToObject:am,animate:dg,animateColor:Tm,applyTransformToObject:Va,calcAngleBetweenVectors:Ic,calcDimensionsMatrix:ph,calcPlaneChangeMatrix:wh,calcVectorRotation:ym,cancelAnimFrame:Wp,capValue:yr,composeMatrix:Yp,copyCanvasElement:o=>{var t;const e=Is(o);return(t=e.getContext("2d"))===null||t===void 0||t.drawImage(o,0,0),e},cos:Fs,createCanvasElement:vs,createImage:Xp,createRotateMatrix:Xa,createScaleMatrix:kc,createSkewXMatrix:Yd,createSkewYMatrix:Ud,createTranslateMatrix:Wa,createVector:Fc,crossProduct:Ga,degreesToRadians:Wt,dotProduct:_m,ease:Uy,enlivenObjectEnlivables:vh,enlivenObjects:za,findScaleToCover:t0,findScaleToFit:Zm,getBoundsOfCurve:wg,getOrthonormalVector:ag,getPathSegmentsInfo:xg,getPointOnPath:h0,getPointer:rm,getRandomInt:nw,getRegularPolygonPath:(o,t)=>{const e=2*Math.PI/o;let s=-An;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 D(Fs(r),Ls(r)).scalarMultiply(t);i[n]=[n===0?"M":"L",a,h]}return i[o]=["Z"],i},getSmoothPathFromPoints:iw,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:jc,groupSVGElements:(o,t)=>o&&o.length===1?o[0]:new ci(o,t),hasStyleChanged:Xc,invertTransform:qe,isBetweenVectors:og,isIdentityMatrix:zp,isTouchEvent:Oc,isTransparent:Lm,joinPath:u0,loadImage:mh,magnitude:Lc,makeBoundingBoxFromPoints:hi,makePathSimpler:s0,matrixToSVG:bh,mergeClipPaths:(o,t)=>{var e;let s=o,i=t;s.inverted&&!i.inverted&&(s=t,i=o),tg(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:Gt,multiplyTransformMatrixArray:Ec,parsePath:c0,parsePreserveAspectRatioAttribute:Kd,parseUnit:Ie,pick:mr,projectStrokeOnPoints:Nm,qrDecompose:pr,radiansToDegrees:kn,removeFromArray:fr,removeTransformFromObject:(o,t)=>{const e=qe(t),s=Gt(e,o.calcOwnMatrix());Va(o,s)},removeTransformMatrixForSvgParsing:$c,request:d0,requestAnimFrame:fh,resetObjectTransform:om,rotatePoint:(o,t,e)=>o.rotate(e,t),rotateVector:rg,saveObjectTransform:Zd,sendObjectToPlane:tg,sendPointToPlane:br,sendVectorToPlane:hm,setStyle:qc,sin:Ls,sizeAfterTransform:Pc,string:w_,stylesFromArray:Wm,stylesToArray:Hm,toDataURL:Gd,toFixed:Dt,transformPath:(o,t,e)=>(e&&(t=Gt(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}=we({x:s[n],y:s[n+1]},t);i[n]=r,i[n+1]=a}return i})),transformPoint:we});class aw extends nm{constructor(t){let{allowTouchScrolling:e=!1,containerClass:s=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(t),T(this,"upper",void 0),T(this,"container",void 0);const{el:i}=this.lower,n=this.createUpperCanvas();this.upper={el:n,ctx:n.getContext("2d")},this.applyCanvasStyle(i,{allowTouchScrolling:e}),this.applyCanvasStyle(n,{allowTouchScrolling:e,styles:{position:"absolute",left:"0",top:"0"}});const r=this.createContainerElement();r.classList.add(s),i.parentNode&&i.parentNode.replaceChild(r,i),r.append(i,n),this.container=r}createUpperCanvas(){const{el:t}=this.lower,e=vs();return e.className=t.className,e.classList.remove("lower-canvas"),e.classList.add("upper-canvas"),e.setAttribute("data-fabric","top"),e.style.cssText=t.style.cssText,e.setAttribute("draggable","true"),e}createContainerElement(){const t=ja().createElement("div");return t.setAttribute("data-fabric","wrapper"),qc(t,{position:"relative"}),im(t),t}applyCanvasStyle(t,e){const{styles:s,allowTouchScrolling:i}=e;qc(t,E(E({},s),{},{"touch-action":i?"manipulation":Re})),im(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:s,ctx:i}=this.upper;sm(s,i,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),Jd(this.upper.el,t),Jd(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(),oi().dispose(this.upper.el),delete this.upper,delete this.container}}class Kc extends _h{constructor(){super(...arguments),T(this,"targets",[]),T(this,"_hoveredTargets",[]),T(this,"_objectsToRender",void 0),T(this,"_currentTransform",null),T(this,"_groupSelector",null),T(this,"contextTopDirty",!1)}static getDefaults(){return E(E({},super.getDefaults()),Kc.ownDefaults)}get upperCanvasEl(){var t;return(t=this.elements.upper)===null||t===void 0?void 0:t.el}get contextTop(){var t;return(t=this.elements.upper)===null||t===void 0?void 0:t.ctx}get wrapperEl(){return this.elements.container}initElements(t){this.elements=new aw(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 Lm(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===Sc||e===Fe||e===is||e===gh?i=this.centeredScaling||t.centeredScaling:e===Xd&&(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=Vt:["mr","tr","br"].includes(e)&&(s.x=mt),["tl","mt","tr"].includes(e)?s.y=Hd:["bl","mb","br"].includes(e)&&(s.y=Ue)),s}_setupCurrentTransform(t,e,s){var i;const n=e.group?br(this.getScenePoint(t),void 0,e.group.calcTransformMatrix()):this.getScenePoint(t),{key:r="",control:a}=e.getActiveControl()||{},h=s&&a?(i=a.getActionHandler(t,e,a))===null||i===void 0?void 0:i.bind(a):By,l=((f,p,m,_)=>{if(!p||!f)return"drag";const b=_.controls[p];return b.getActionName(m,b,_)})(s,r,t,e),u=t[this.centeredKey],d=this._shouldCenterTransform(e,l,u)?{x:st,y:st}:this._getOriginFromCorner(e,r),g={target:e,action:l,actionHandler:h,actionPerformed:!1,corner:r,scaleX:e.scaleX,scaleY:e.scaleY,skewX:e.skewX,skewY:e.skewY,offsetX:n.x-e.left,offsetY:n.y-e.top,originX:d.x,originY:d.y,ex:n.x,ey:n.y,lastX:n.x,lastY:n.y,theta:Wt(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:u,original:E(E({},Zd(e)),{},{originX:d.x,originY:d.y})};this._currentTransform=g,this.fire("before:transform",{e:t,transform:g})}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new D(e,s).transform(this.viewportTransform),a=new D(e+i,s+n).transform(this.viewportTransform),h=this.selectionLineWidth/2;let l=Math.min(r.x,a.x),u=Math.min(r.y,a.y),d=Math.max(r.x,a.x),g=Math.max(r.y,a.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(l,u,d-l,g-u)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,l+=h,u+=h,d-=h,g-=h,xe.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(l,u,d-l,g-u))}findTarget(t){if(this.skipTargetFind)return;const e=this.getViewportPoint(t),s=this._activeObject,i=this.getActiveObjects();if(this.targets=[],s&&i.length>=1){if(s.findControl(e,Oc(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,l]=s,u=Math.atan2(a.y-r.y,a.x-r.x),d=Fs(u)*n,g=Ls(u)*n,f=d+g,p=d-g;s=[new D(r.x-p,r.y-f),new D(a.x+f,a.y-p),new D(h.x+p,h.y+f),new D(l.x-f,l.y+p)]}return Lt.isPointInPolygon(e,s)}_checkTarget(t,e){return!!(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,br(e,void 0,this.viewportTransform))&&(!this.perPixelTargetFind&&!t.perPixelTargetFind||t.isEditing||!this.isTargetTransparent(t,e.x,e.y)))}_searchPossibleTargets(t,e){let s=t.length;for(;s--;){const i=t[s];if(this._checkTarget(i,e)){if(Tc(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&&Tc(s)&&s.interactive&&this.targets[0]){const i=this.targets;for(let n=i.length-1;n>0;n--){const r=i[n];if(!Tc(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=rm(t),r=i.width||0,a=i.height||0;r&&a||(Ue in i&&Hd in i&&(a=Math.abs(i.top-i.bottom)),Vt in i&&mt in i&&(r=Math.abs(i.right-i.left))),this.calcOffset(),n.x=n.x-this._offset.left,n.y=n.y-this._offset.top,e||(n=br(n,void 0,this.viewportTransform));const h=this.getRetinaScaling();h!==1&&(n.x/=h,n.y/=h);const l=r===0||a===0?new D(1,1):new D(s.width/r,s.height/a);return n.multiply(l)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=vs(),this.pixelFindContext=this.pixelFindCanvasEl.getContext("2d",{willReadFrequently:!0}),this.setTargetFindTolerance(this.targetFindTolerance)}getTopContext(){return this.elements.upper.ctx}getSelectionContext(){return this.elements.upper.ctx}getSelectionElement(){return this.elements.upper.el}getActiveObject(){return this._activeObject}getActiveObjects(){const t=this._activeObject;return vr(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,vr(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),vr(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(Cc,i))}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeObject;vr(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&&vr(e)&&this._activeObject===e){const s=mr(t,["angle","flipX","flipY",mt,Fe,is,Na,Ba,Ue]);return am(t,e.calcOwnMatrix()),s}return{}}_setSVGObject(t,e,s){const i=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,s),e.set(i)}}T(Kc,"ownDefaults",{uniformScaling:!0,uniScaleKey:"shiftKey",centeredScaling:!1,centeredRotation:!1,centeredKey:"altKey",altActionKey:"shiftKey",selection:!0,selectionKey:"shiftKey",selectionColor:"rgba(100, 100, 255, 0.3)",selectionDashArray:[],selectionBorderColor:"rgba(255, 255, 255, 0.3)",selectionLineWidth:1,selectionFullyContained:!1,hoverCursor:"move",moveCursor:"move",defaultCursor:"default",freeDrawingCursor:"crosshair",notAllowedCursor:"not-allowed",perPixelTargetFind:!1,targetFindTolerance:0,skipTargetFind:!1,stopContextMenu:!1,fireRightClick:!1,fireMiddleClick:!1,enablePointerEvents:!1,containerClass:"canvas-container",preserveObjectStacking:!1});class ow{constructor(t){T(this,"targets",[]),T(this,"__disposer",void 0);const e=()=>{const{hiddenTextarea:i}=t.getActiveObject()||{};i&&i.focus()},s=t.upperCanvasEl;s.addEventListener("click",e),this.__disposer=()=>s.removeEventListener("click",e)}exitTextEditing(){this.target=void 0,this.targets.forEach(t=>{t.isEditing&&t.exitEditing()})}add(t){this.targets.push(t)}remove(t){this.unregister(t),fr(this.targets,t)}register(t){this.target=t}unregister(t){t===this.target&&(this.target=void 0)}onMouseMove(t){var e;!((e=this.target)===null||e===void 0)&&e.isEditing&&this.target.updateSelectionOnMouseMove(t)}clear(){this.targets=[],this.target=void 0}dispose(){this.clear(),this.__disposer(),delete this.__disposer}}const hw=["target","oldTarget","fireCanvas","e"],ns={passive:!1},Ka=(o,t)=>{const e=o.getViewportPoint(t),s=o.getScenePoint(t);return{viewportPoint:e,scenePoint:s,pointer:e,absolutePointer:s}},On=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)},ys=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)},lw={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 Sg extends Kc{constructor(t){super(t,arguments.length>1&&arguments[1]!==void 0?arguments[1]:{}),T(this,"_isClick",void 0),T(this,"textEditingManager",new ow(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(On,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const s=this.upperCanvasEl,i=this._getEventPrefix();t(em(s),"resize",this._onResize),t(s,i+"down",this._onMouseDown),t(s,"".concat(i,"move"),this._onMouseMove,ns),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,ns)}removeListeners(){this.addOrRemove(ys,"remove");const t=this._getEventPrefix(),e=js(this.upperCanvasEl);ys(e,"".concat(t,"up"),this._onMouseUp),ys(e,"touchend",this._onTouchEnd,ns),ys(e,"".concat(t,"move"),this._onMouseMove,ns),ys(e,"touchmove",this._onMouseMove,ns),clearTimeout(this._willAddMouseDown)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s=E({e:t},Ka(this,t));this.fire("mouse:out",E(E({},s),{},{target:e})),this._hoveredTarget=void 0,e&&e.fire("mouseout",E({},s)),this._hoveredTargets.forEach(i=>{this.fire("mouse:out",E(E({},s),{},{target:i})),i&&i.fire("mouseout",E({},s))}),this._hoveredTargets=[]}_onMouseEnter(t){this._currentTransform||this.findTarget(t)||(this.fire("mouse:over",E({e:t},Ka(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 On(this.upperCanvasEl,"drag",this._onDragProgress)}Qd(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!==Re,s=e?this._activeObject:void 0,i={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:s};ys(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 l=i[h];l.canDrop(t)&&(a=l),l.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",E({e:t,target:e,subTargets:s,dragSource:this._dragSource},Ka(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&&Qd(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);On(r,"touchend",this._onTouchEnd,ns),e&&On(r,"touchmove",this._onMouseMove,ns),ys(i,"".concat(n,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();ys(e,"".concat(s,"move"),this._onMouseMove,ns);const i=js(e);On(i,"".concat(s,"up"),this._onMouseUp),On(i,"".concat(s,"move"),this._onMouseMove,ns)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),s=js(this.upperCanvasEl);ys(s,"touchend",this._onTouchEnd,ns),ys(s,"touchmove",this._onMouseMove,ns),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout(()=>{On(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);ys(i,"".concat(s,"up"),this._onMouseUp),ys(i,"".concat(s,"move"),this._onMouseMove,ns),On(e,"".concat(s,"move"),this._onMouseMove,ns)}}_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,l=!1;if(s&&(this._finalizeCurrentTransform(t),l=s.actionPerformed),!i){const u=n===this._activeObject;this.handleSelection(t),l||(l=this._shouldRender(n)||!u&&n===this._activeObject)}if(n){const u=n.findControl(this.getViewportPoint(t),Oc(t)),{key:d,control:g}=u||{};if(h=d,n.selectable&&n!==this._activeObject&&n.activeOn==="up")this.setActiveObject(n,t),l=!0;else if(g){const f=g.getMouseUpHandler(t,n,g);f&&(a=this.getScenePoint(t),f.call(g,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),l?this.requestRenderAll():i||(e=this._activeObject)!==null&&e!==void 0&&e.isEditing||this.renderTop()}_basicEventHandler(t,e){const{target:s,subTargets:i=[]}=e;this.fire(t,e),s&&s.fire(t,e);for(let n=0;n<i.length;n++)i[n]!==s&&i[n].fire(t,e);return e}_handleEvent(t,e){const s=this._target,i=this.targets||[],n=E(E({e:t,target:s,subTargets:i},Ka(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),Oc(t));if(e===this._activeObject&&(a||!n)){this._setupCurrentTransform(t,e,r);const h=a?a.control:void 0,l=this.getScenePoint(t),u=h&&h.getMouseDownHandler(t,e,h);u&&u.call(h,t,this._currentTransform,l.x,l.y)}}i&&(this._objectsToRender=void 0),this._handleEvent(t,"down"),i&&this.requestRenderAll()}_resetTransformEventData(){this._target=void 0,this._pointer=void 0,this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getViewportPoint(t),this._absolutePointer=br(this._pointer,void 0,this.viewportTransform),this._target=this._currentTransform?this._currentTransform.target:this.findTarget(t)}__onMouseMove(t){if(this._isClick=!1,this._cacheTransformEventData(t),this._handleEvent(t,"move:before"),this.isDrawingMode)return void this._onMouseMoveInDrawingMode(t);if(!this._isMainEvent(t))return;const e=this._groupSelector;if(e){const s=this.getScenePoint(t);e.deltaX=s.x-e.x,e.deltaY=s.y-e.y,this.renderTop()}else if(this._currentTransform)this._transformObject(t);else{const s=this.findTarget(t);this._setCursorFromEvent(t,s),this._fireOverOutEvents(t,s)}this.textEditingManager.onMouseMove(t),this._handleEvent(t,"move"),this._resetTransformEventData()}_fireOverOutEvents(t,e){const s=this._hoveredTarget,i=this._hoveredTargets,n=this.targets,r=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("mouse",{e:t,target:e,oldTarget:s,fireCanvas:!0});for(let a=0;a<r;a++)this.fireSyntheticInOutEvents("mouse",{e:t,target:n[a],oldTarget:i[a]});this._hoveredTarget=e,this._hoveredTargets=this.targets.concat()}_fireEnterLeaveEvents(t,e){const s=this._draggedoverTarget,i=this._hoveredTargets,n=this.targets,r=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("drag",E(E({},e),{},{target:t,oldTarget:s,fireCanvas:!0}));for(let a=0;a<r;a++)this.fireSyntheticInOutEvents("drag",E(E({},e),{},{target:n[a],oldTarget:i[a]}));this._draggedoverTarget=t}fireSyntheticInOutEvents(t,e){let{target:s,oldTarget:i,fireCanvas:n,e:r}=e,a=Pt(e,hw);const{targetIn:h,targetOut:l,canvasIn:u,canvasOut:d}=lw[t],g=i!==s;if(i&&g){const f=E(E({},a),{},{e:r,target:i,nextTarget:s},Ka(this,r));n&&this.fire(d,f),i.fire(l,f)}if(s&&g){const f=E(E({},a),{},{e:r,target:s,previousTarget:i},Ka(this,r));n&&this.fire(u,f),s.fire(h,f)}}__onMouseWheel(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()}_transformObject(t){const e=this.getScenePoint(t),s=this._currentTransform,i=s.target,n=i.group?br(e,void 0,i.group.calcTransformMatrix()):e;s.shiftKey=t.shiftKey,s.altKey=!!this.centeredKey&&t[this.centeredKey],this._performTransformAction(t,s,n),s.actionPerformed&&this.requestRenderAll()}_performTransformAction(t,e,s){const{action:i,actionHandler:n,target:r}=e,a=!!n&&n(t,e,s.x,s.y);a&&r.setCoords(),i==="drag"&&a&&(e.target.isMoving=!0,this.setCursor(e.target.moveCursor||this.moveCursor)),e.actionPerformed=e.actionPerformed||a}_setCursorFromEvent(t,e){if(!e)return void this.setCursor(this.defaultCursor);let s=e.hoverCursor||this.hoverCursor;const i=vr(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=vr(s);if(s&&this._isSelectionKeyPressed(t)&&this.selection&&e&&e.selectable&&(s!==e||i)&&(i||!e.isDescendantOf(s)&&!s.isDescendantOf(e))&&!e.onSelect({e:t})&&!s.getActiveControl()){if(i){const n=s.getObjects();if(e===s){const r=this.getViewportPoint(t);if(!(e=this.searchPossibleTargets(n,r)||this.searchPossibleTargets(this._objects,r))||!e.selectable)return!1}e.group===s?(s.remove(e),this._hoveredTarget=e,this._hoveredTargets=[...this.targets],s.size()===1&&this._setActiveObject(s.item(0),t)):(s.multiSelectAdd(e),this._hoveredTarget=s,this._hoveredTargets=[...this.targets]),this._fireSelectionEvents(n,t)}else{s.isEditing&&s.exitEditing();const n=new(V.getClass("ActiveSelection"))([],{canvas:this});n.multiSelectAdd(s,e),this._hoveredTarget=n,this._setActiveObject(n,t),this._fireSelectionEvents([s],t)}return!0}return!1}handleSelection(t){if(!this.selection||!this._groupSelector)return!1;const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new D(e,s),a=r.add(new D(i,n)),h=r.min(a),l=r.max(a).subtract(h),u=this.collectObjects({left:h.x,top:h.y,width:l.x,height:l.y},{includeIntersecting:!this.selectionFullyContained}),d=r.eq(a)?u[0]?[u[0]]:[]:u.length>1?u.filter(g=>!g.onSelect({e:t})).reverse():u;if(d.length===1)this.setActiveObject(d[0],t);else if(d.length>1){const g=V.getClass("ActiveSelection");this.setActiveObject(new g(d,{canvas:this}),t)}return this._groupSelector=null,!0}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const g0={x1:0,y1:0,x2:0,y2:0},cw=E(E({},g0),{},{r1:0,r2:0}),Ja=(o,t)=>isNaN(o)&&typeof t=="number"?t:o,uw=/^(\d+\.\d+)%|(\d+)%$/;function f0(o){return o&&uw.test(o)}function p0(o,t){const e=typeof o=="number"?o:typeof o=="string"?parseFloat(o)/(f0(o)?100:1):NaN;return yr(0,Ja(e,t),1)}const dw=/\s*;\s*/,gw=/\s*:\s*/;function fw(o,t){let e,s;const i=o.getAttribute("style");if(i){const r=i.split(dw);r[r.length-1]===""&&r.pop();for(let a=r.length;a--;){const[h,l]=r[a].split(gw).map(u=>u.trim());h==="stop-color"?e=l:h==="stop-opacity"&&(s=l)}}const n=new yt(e||o.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:p0(o.getAttribute("offset"),0),color:n.toRgb(),opacity:Ja(parseFloat(s||o.getAttribute("stop-opacity")||""),1)*n.getAlpha()*t}}function pw(o,t){const e=[],s=o.getElementsByTagName("stop"),i=p0(t,1);for(let n=s.length;n--;)e.push(fw(s[n],i));return e}function m0(o){return o.nodeName==="linearGradient"||o.nodeName==="LINEARGRADIENT"?"linear":"radial"}function v0(o){return o.getAttribute("gradientUnits")==="userSpaceOnUse"?"pixels":"percentage"}function Ws(o,t){return o.getAttribute(t)}function mw(o,t){return function(e,s){let i,{width:n,height:r,gradientUnits:a}=s;return Object.keys(e).reduce((h,l)=>{const u=e[l];return u==="Infinity"?i=1:u==="-Infinity"?i=0:(i=typeof u=="string"?parseFloat(u):u,typeof u=="string"&&f0(u)&&(i*=.01,a==="pixels"&&(l!=="x1"&&l!=="x2"&&l!=="r2"||(i*=n),l!=="y1"&&l!=="y2"||(i*=r)))),h[l]=i,h},{})}(m0(o)==="linear"?function(e){return{x1:Ws(e,"x1")||0,y1:Ws(e,"y1")||0,x2:Ws(e,"x2")||"100%",y2:Ws(e,"y2")||0}}(o):function(e){return{x1:Ws(e,"fx")||Ws(e,"cx")||"50%",y1:Ws(e,"fy")||Ws(e,"cy")||"50%",r1:0,x2:Ws(e,"cx")||"50%",y2:Ws(e,"cy")||"50%",r2:Ws(e,"r")||"50%"}}(o),E(E({},t),{},{gradientUnits:v0(o)}))}class Th{constructor(t){const{type:e="linear",gradientUnits:s="pixels",coords:i={},colorStops:n=[],offsetX:r=0,offsetY:a=0,gradientTransform:h,id:l}=t||{};Object.assign(this,{type:e,gradientUnits:s,coords:E(E({},e==="radial"?cw:g0),i),colorStops:n,offsetX:r,offsetY:a,gradientTransform:h,id:l?"".concat(l,"_").concat(En()):En()})}addColorStop(t){for(const e in t){const s=new yt(t[e]);this.colorStops.push({offset:parseFloat(e),color:s.toRgb(),opacity:s.getAlpha()})}return this}toObject(t){return E(E({},mr(this,t)),{},{type:this.type,coords:E({},this.coords),colorStops:this.colorStops.map(e=>E({},e)),offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?[...this.gradientTransform]:void 0})}toSVG(t){let{additionalTransform:e}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const s=[],i=this.gradientTransform?this.gradientTransform.concat():De.concat(),n=this.gradientUnits==="pixels"?"userSpaceOnUse":"objectBoundingBox",r=this.colorStops.map(d=>E({},d)).sort((d,g)=>d.offset-g.offset);let a=-this.offsetX,h=-this.offsetY;var l;n==="objectBoundingBox"?(a/=t.width,h/=t.height):(a+=t.width/2,h+=t.height/2),(l=t)&&typeof l._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(bh(i),'"'),""].join(" ");if(this.type==="linear"){const{x1:d,y1:g,x2:f,y2:p}=this.coords;s.push("<linearGradient ",u,' x1="',d,'" y1="',g,'" x2="',f,'" y2="',p,`">
|
|
71
|
-
`)}else if(this.type==="radial"){const{x1:d,y1:g,x2:f,y2:p,r1:m,r2:
|
|
72
|
-
`),b&&(r.reverse(),r.forEach(
|
|
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=Ot(t,U_);return Promise.all([Qo(i,e),Ph(r,e)]).then(o=>{let[h,c]=o;const u=new this(h,E(E(E({},r),c),{},{layoutManager:new Y_}));if(n){const d=W.getClass(n.type),g=W.getClass(n.strategy);u.layoutManager=new d(new g)}else u.layoutManager=new jh;return u.layoutManager.subscribeTargets({type:Qi,target:u,targets:u.getObjects()}),u.setCoords(),u})}}T(_i,"type","Group"),T(_i,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),W.setClass(_i);const u0=(a,t)=>Math.min(t.width/a.width,t.height/a.height),d0=(a,t)=>Math.max(t.width/a.width,t.height/a.height),Ig="\\s*,?\\s*",Nh="".concat(Ig,"(").concat($s,")"),$_="".concat(Nh).concat(Nh).concat(Nh).concat(Ig,"([01])").concat(Ig,"([01])").concat(Nh).concat(Nh),q_={m:"l",M:"L"},K_=(a,t,e,s,i,n,r,o,h,c,u)=>{const d=Ws(a),g=zs(a),f=Ws(t),p=zs(t),m=e*i*f-s*n*p+r,y=s*i*f+e*n*p+o;return["C",c+h*(-e*i*g-s*n*d),u+h*(-s*i*g+e*n*d),m+h*(e*i*p+s*n*f),y+h*(s*i*p-e*n*f),m,y]},g0=(a,t,e,s)=>{const i=Math.atan2(t,a),n=Math.atan2(s,e);return n>=i?n-i:2*Math.PI-(i-n)};function jg(a,t,e,s,i,n,r,o){let h;if(dt.cachesBoundsOfCurve&&(h=[...arguments].join(),Ah.boundsOfCurveCache[h]))return Ah.boundsOfCurveCache[h];const c=Math.sqrt,u=Math.abs,d=[],g=[[0,0],[0,0]];let f=6*a-12*e+6*i,p=-3*a+9*e-9*i+3*r,m=3*e-3*a;for(let A=0;A<2;++A){if(A>0&&(f=6*t-12*s+6*n,p=-3*t+9*s-9*n+3*o,m=3*s-3*t),u(p)<1e-12){if(u(f)<1e-12)continue;const R=-m/f;0<R&&R<1&&d.push(R);continue}const M=f*f-4*m*p;if(M<0)continue;const D=c(M),k=(-f+D)/(2*p);0<k&&k<1&&d.push(k);const P=(-f-D)/(2*p);0<P&&P<1&&d.push(P)}let y=d.length;const b=y,x=p0(a,t,e,s,i,n,r,o);for(;y--;){const{x:A,y:M}=x(d[y]);g[0][y]=A,g[1][y]=M}g[0][b]=a,g[1][b]=t,g[0][b+1]=r,g[1][b+1]=o;const C=[new O(Math.min(...g[0]),Math.min(...g[1])),new O(Math.max(...g[0]),Math.max(...g[1]))];return dt.cachesBoundsOfCurve&&(Ah.boundsOfCurveCache[h]=C),C}const Q_=(a,t,e)=>{let[s,i,n,r,o,h,c,u]=e;const d=((g,f,p,m,y,b,x)=>{if(p===0||m===0)return[];let C=0,A=0,M=0;const D=Math.PI,k=x*tg,P=zs(k),R=Ws(k),F=.5*(-R*g-P*f),I=.5*(-R*f+P*g),X=p**2,j=m**2,N=I**2,it=F**2,K=X*j-X*N-j*it;let V=Math.abs(p),H=Math.abs(m);if(K<0){const $e=Math.sqrt(1-K/(X*j));V*=$e,H*=$e}else M=(y===b?-1:1)*Math.sqrt(K/(X*N+j*it));const Et=M*V*I/H,It=-M*H*F/V,ie=R*Et-P*It+.5*g,Wt=P*Et+R*It+.5*f;let Tt=g0(1,0,(F-Et)/V,(I-It)/H),xe=g0((F-Et)/V,(I-It)/H,(-F-Et)/V,(-I-It)/H);b===0&&xe>0?xe-=2*D:b===1&&xe<0&&(xe+=2*D);const Vs=Math.ceil(Math.abs(xe/D*2)),Pt=[],gt=xe/Vs,Cs=8/3*Math.sin(gt/4)*Math.sin(gt/4)/Math.sin(gt/2);let Wi=Tt+gt;for(let $e=0;$e<Vs;$e++)Pt[$e]=K_(Tt,Wi,R,P,V,H,ie,Wt,Cs,C,A),C=Pt[$e][5],A=Pt[$e][6],Tt=Wi,Wi+=gt;return Pt})(c-a,u-t,i,n,o,h,r);for(let g=0,f=d.length;g<f;g++)d[g][1]+=a,d[g][2]+=t,d[g][3]+=a,d[g][4]+=t,d[g][5]+=a,d[g][6]+=t;return d},f0=a=>{let t=0,e=0,s=0,i=0;const n=[];let r,o=0,h=0;for(const c of a){const u=[...c];let d;switch(u[0]){case"l":u[1]+=t,u[2]+=e;case"L":t=u[1],e=u[2],d=["L",t,e];break;case"h":u[1]+=t;case"H":t=u[1],d=["L",t,e];break;case"v":u[1]+=e;case"V":e=u[1],d=["L",t,e];break;case"m":u[1]+=t,u[2]+=e;case"M":t=u[1],e=u[2],s=u[1],i=u[2],d=["M",t,e];break;case"c":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e,u[5]+=t,u[6]+=e;case"C":o=u[3],h=u[4],t=u[5],e=u[6],d=["C",u[1],u[2],o,h,t,e];break;case"s":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e;case"S":r==="C"?(o=2*t-o,h=2*e-h):(o=t,h=e),t=u[3],e=u[4],d=["C",o,h,u[1],u[2],t,e],o=d[3],h=d[4];break;case"q":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e;case"Q":o=u[1],h=u[2],t=u[3],e=u[4],d=["Q",o,h,t,e];break;case"t":u[1]+=t,u[2]+=e;case"T":r==="Q"?(o=2*t-o,h=2*e-h):(o=t,h=e),t=u[1],e=u[2],d=["Q",o,h,t,e];break;case"a":u[6]+=t,u[7]+=e;case"A":Q_(t,e,u).forEach(g=>n.push(g)),t=u[6],e=u[7];break;case"z":case"Z":t=s,e=i,d=["Z"]}d?(n.push(d),r=d[0]):r=""}return n},lu=(a,t,e,s)=>Math.sqrt((e-a)**2+(s-t)**2),p0=(a,t,e,s,i,n,r,o)=>h=>{const c=h**3,u=(f=>3*f**2*(1-f))(h),d=(f=>3*f*(1-f)**2)(h),g=(f=>(1-f)**3)(h);return new O(r*c+i*u+e*d+a*g,o*c+n*u+s*d+t*g)},m0=a=>a**2,v0=a=>2*a*(1-a),b0=a=>(1-a)**2,J_=(a,t,e,s,i,n,r,o)=>h=>{const c=m0(h),u=v0(h),d=b0(h),g=3*(d*(e-a)+u*(i-e)+c*(r-i)),f=3*(d*(s-t)+u*(n-s)+c*(o-n));return Math.atan2(f,g)},Z_=(a,t,e,s,i,n)=>r=>{const o=m0(r),h=v0(r),c=b0(r);return new O(i*o+e*h+a*c,n*o+s*h+t*c)},tw=(a,t,e,s,i,n)=>r=>{const o=1-r,h=2*(o*(e-a)+r*(i-e)),c=2*(o*(s-t)+r*(n-s));return Math.atan2(c,h)},y0=(a,t,e)=>{let s=new O(t,e),i=0;for(let n=1;n<=100;n+=1){const r=a(n/100);i+=lu(s.x,s.y,r.x,r.y),s=r}return i},ew=(a,t)=>{let e,s=0,i=0,n={x:a.x,y:a.y},r=E({},n),o=.01,h=0;const c=a.iterator,u=a.angleFinder;for(;i<t&&o>1e-4;)r=c(s),h=s,e=lu(n.x,n.y,r.x,r.y),e+i>t?(s-=o,o/=2):(n=r,s+=o,i+=e);return E(E({},r),{},{angle:u(h)})},Ng=a=>{let t,e,s=0,i=0,n=0,r=0,o=0;const h=[];for(const c of a){const u={x:i,y:n,command:c[0],length:0};switch(c[0]){case"M":e=u,e.x=r=i=c[1],e.y=o=n=c[2];break;case"L":e=u,e.length=lu(i,n,c[1],c[2]),i=c[1],n=c[2];break;case"C":t=p0(i,n,c[1],c[2],c[3],c[4],c[5],c[6]),e=u,e.iterator=t,e.angleFinder=J_(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=Z_(i,n,c[1],c[2],c[3],c[4]),e=u,e.iterator=t,e.angleFinder=tw(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=o,e.length=lu(i,n,r,o),i=r,n=o}s+=e.length,h.push(e)}return h.push({length:s,x:i,y:n}),h},_0=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Ng(a),s=0;for(;t-e[s].length>0&&s<e.length-2;)t-=e[s].length,s++;const i=e[s],n=t/i.length,r=a[s];switch(i.command){case"M":return{x:i.x,y:i.y,angle:0};case"Z":return E(E({},new O(i.x,i.y).lerp(new O(i.destX,i.destY),n)),{},{angle:Math.atan2(i.destY-i.y,i.destX-i.x)});case"L":return E(E({},new O(i.x,i.y).lerp(new O(r[1],r[2]),n)),{},{angle:Math.atan2(r[2]-i.y,r[1]-i.x)});case"C":case"Q":return ew(i,t)}},sw=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),w0=new RegExp($_,"g"),iw=new RegExp($s,"gi"),nw={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},x0=a=>{var t;const e=[],s=(t=a.match(sw))!==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=nw[n.toLowerCase()];let o=[];if(n==="a"||n==="A"){w0.lastIndex=0;for(let h=null;h=w0.exec(i);)o.push(...h.slice(1))}else o=i.match(iw)||[];for(let h=0;h<o.length;h+=r){const c=new Array(r),u=q_[n];c[0]=h>0&&u?u:n;for(let d=0;d<r;d++)c[d+1]=parseFloat(o[h+d]);e.push(c)}}return e},rw=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=new O(a[0]),s=new O(a[1]),i=1,n=0;const r=[],o=a.length,h=o>2;let c;for(h&&(i=a[2].x<s.x?-1:a[2].x===s.x?0:1,n=a[2].y<s.y?-1:a[2].y===s.y?0:1),r.push(["M",e.x-i*t,e.y-n*t]),c=1;c<o;c++){if(!e.eq(s)){const u=e.midPointFrom(s);r.push(["Q",e.x,e.y,u.x,u.y])}e=a[c],c+1<a.length&&(s=a[c+1])}return h&&(i=e.x>a[c-2].x?1:e.x===a[c-2].x?0:-1,n=e.y>a[c-2].y?1:e.y===a[c-2].y?0:-1),r.push(["L",e.x+i*t,e.y+n*t]),r},S0=(a,t)=>a.map(e=>e.map((s,i)=>i===0||t===void 0?s:Dt(s,t)).join(" ")).join(" ");function cu(a,t){const e=a.style;e&&t&&(typeof t=="string"?e.cssText+=";"+t:Object.entries(t).forEach(s=>{let[i,n]=s;return e.setProperty(i,n)}))}const ow=(a,t)=>Math.floor(Math.random()*(t-a+1))+a;function C0(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const e=t.onComplete||Cr,s=new(Ic()).XMLHttpRequest,i=t.signal,n=function(){s.abort()},r=function(){i&&i.removeEventListener("abort",n),s.onerror=s.ontimeout=Cr};if(i&&i.aborted)throw new Jd("request");return i&&i.addEventListener("abort",n,{once:!0}),s.onreadystatechange=function(){s.readyState===4&&(r(),e(s),s.onreadystatechange=Cr)},s.onerror=s.ontimeout=r,s.open("get",a,!0),s.send(),s}const uu=(a,t)=>{let e=a._findCenterFromElement();a.transformMatrix&&((s=>{if(s.transformMatrix){const{scaleX:i,scaleY:n,angle:r,skewX:o}=Tr(s.transformMatrix);s.flipX=!1,s.flipY=!1,s.set(je,i),s.set(hs,n),s.angle=r,s.skewX=o,s.skewY=0}})(a),e=e.transform(a.transformMatrix)),delete a.transformMatrix,t&&(a.scaleX*=t.scaleX,a.scaleY*=t.scaleY,a.cropX=t.cropX,a.cropY=t.cropY,e.x+=t.offsetLeft,e.y+=t.offsetTop,a.width=t.width,a.height=t.height),a.setPositionByOrigin(e,tt,tt)};var aw=Object.freeze({__proto__:null,addTransformToObject:bm,animate:kg,animateColor:Nm,applyTransformToObject:Jo,calcAngleBetweenVectors:Jc,calcDimensionsMatrix:kh,calcPlaneChangeMatrix:Lh,calcVectorRotation:Om,cancelAnimFrame:Zp,capValue:Pr,composeMatrix:nm,copyCanvasElement:a=>{var t;const e=Xs(a);return(t=e.getContext("2d"))===null||t===void 0||t.drawImage(a,0,0),e},cos:Ws,createCanvasElement:As,createImage:tm,createRotateMatrix:Ko,createScaleMatrix:zc,createSkewXMatrix:hg,createSkewYMatrix:lg,createTranslateMatrix:qo,createVector:Kc,crossProduct:Zo,degreesToRadians:zt,dotProduct:Dm,ease:qy,enlivenObjectEnlivables:Ph,enlivenObjects:Qo,findScaleToCover:d0,findScaleToFit:u0,getBoundsOfCurve:jg,getOrthonormalVector:xg,getPathSegmentsInfo:Ng,getPointOnPath:_0,getPointer:vm,getRandomInt:ow,getRegularPolygonPath:(a,t)=>{const e=2*Math.PI/a;let s=-jn;a%2==0&&(s+=e/2);const i=new Array(a+1);for(let n=0;n<a;n++){const r=n*e+s,{x:o,y:h}=new O(Ws(r),zs(r)).scalarMultiply(t);i[n]=[n===0?"M":"L",o,h]}return i[a]=["Z"],i},getSmoothPathFromPoints:rw,getSvgAttributes:a=>{const t=["instantiated_by_use","style","id","class"];switch(a){case"linearGradient":return t.concat(["x1","y1","x2","y2","gradientUnits","gradientTransform"]);case"radialGradient":return t.concat(["gradientUnits","gradientTransform","cx","cy","r","fx","fy","fr"]);case"stop":return t.concat(["offset","stop-color","stop-opacity"])}return t},getUnitVector:Zc,groupSVGElements:(a,t)=>a&&a.length===1?a[0]:new _i(a,t),hasStyleChanged:nu,invertTransform:Ze,isBetweenVectors:Sg,isIdentityMatrix:em,isTouchEvent:Uc,isTransparent:Ym,joinPath:S0,loadImage:Mh,magnitude:Qc,makeBoundingBoxFromPoints:bi,makePathSimpler:f0,matrixToSVG:Oh,mergeClipPaths:(a,t)=>{var e;let s=a,i=t;s.inverted&&!i.inverted&&(s=t,i=a),mg(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 _i([s],{clipPath:i,inverted:n})},multiplyTransformMatrices:Yt,multiplyTransformMatrixArray:Wc,parsePath:x0,parsePreserveAspectRatioAttribute:dg,parseUnit:Be,pick:Er,projectStrokeOnPoints:Km,qrDecompose:Tr,radiansToDegrees:Hn,removeFromArray:Ar,removeTransformFromObject:(a,t)=>{const e=Ze(t),s=Yt(e,a.calcOwnMatrix());Jo(a,s)},removeTransformMatrixForSvgParsing:uu,request:C0,requestAnimFrame:Eh,resetObjectTransform:ym,rotatePoint:(a,t,e)=>a.rotate(e,t),rotateVector:wg,saveObjectTransform:pg,sendObjectToPlane:mg,sendPointToPlane:Mr,sendVectorToPlane:_m,setStyle:cu,sin:zs,sizeAfterTransform:Yc,string:S_,stylesFromArray:Zm,stylesToArray:Jm,toDataURL:ag,toFixed:Dt,transformPath:(a,t,e)=>(e&&(t=Yt(t,[1,0,0,1,-e.x,-e.y])),a.map(s=>{const i=[...s];for(let n=1;n<s.length-1;n+=2){const{x:r,y:o}=Se({x:s[n],y:s[n+1]},t);i[n]=r,i[n+1]=o}return i})),transformPoint:Se});class hw extends mm{constructor(t){let{allowTouchScrolling:e=!1,containerClass:s=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(t),T(this,"upper",void 0),T(this,"container",void 0);const{el:i}=this.lower,n=this.createUpperCanvas();this.upper={el:n,ctx:n.getContext("2d")},this.applyCanvasStyle(i,{allowTouchScrolling:e}),this.applyCanvasStyle(n,{allowTouchScrolling:e,styles:{position:"absolute",left:"0",top:"0"}});const r=this.createContainerElement();r.classList.add(s),i.parentNode&&i.parentNode.replaceChild(r,i),r.append(i,n),this.container=r}createUpperCanvas(){const{el:t}=this.lower,e=As();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=Xo().createElement("div");return t.setAttribute("data-fabric","wrapper"),cu(t,{position:"relative"}),pm(t),t}applyCanvasStyle(t,e){const{styles:s,allowTouchScrolling:i}=e;cu(t,E(E({},s),{},{"touch-action":i?"manipulation":Ie})),pm(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:s,ctx:i}=this.upper;fm(s,i,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),gg(this.upper.el,t),gg(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(),vi().dispose(this.upper.el),delete this.upper,delete this.container}}class du extends Rh{constructor(){super(...arguments),T(this,"targets",[]),T(this,"_hoveredTargets",[]),T(this,"_objectsToRender",void 0),T(this,"_currentTransform",null),T(this,"_groupSelector",null),T(this,"contextTopDirty",!1)}static getDefaults(){return E(E({},super.getDefaults()),du.ownDefaults)}get upperCanvasEl(){var t;return(t=this.elements.upper)===null||t===void 0?void 0:t.el}get contextTop(){var t;return(t=this.elements.upper)===null||t===void 0?void 0:t.ctx}get wrapperEl(){return this.elements.container}initElements(t){this.elements=new hw(t,{allowTouchScrolling:this.allowTouchScrolling,containerClass:this.containerClass}),this._createCacheCanvas()}_onObjectAdded(t){this._objectsToRender=void 0,super._onObjectAdded(t)}_onObjectRemoved(t){this._objectsToRender=void 0,t===this._activeObject&&(this.fire("before:selection:cleared",{deselected:[t]}),this._discardActiveObject(),this.fire("selection:cleared",{deselected:[t]}),t.fire("deselected",{target:t})),t===this._hoveredTarget&&(this._hoveredTarget=void 0,this._hoveredTargets=[]),super._onObjectRemoved(t)}_onStackOrderChanged(){this._objectsToRender=void 0,super._onStackOrderChanged()}_chooseObjectsToRender(){const t=this._activeObject;return!this.preserveObjectStacking&&t?this._objects.filter(e=>!e.group&&e!==t).concat(t):this._objects}renderAll(){this.cancelRequestedRender(),this.destroyed||(!this.contextTopDirty||this._groupSelector||this.isDrawingMode||(this.clearContext(this.contextTop),this.contextTopDirty=!1),this.hasLostContext&&(this.renderTopLayer(this.contextTop),this.hasLostContext=!1),!this._objectsToRender&&(this._objectsToRender=this._chooseObjectsToRender()),this.renderCanvas(this.getContext(),this._objectsToRender))}renderTopLayer(t){t.save(),this.isDrawingMode&&this._isCurrentlyDrawing&&(this.freeDrawingBrush&&this.freeDrawingBrush._render(),this.contextTopDirty=!0),this.selection&&this._groupSelector&&(this._drawSelection(t),this.contextTopDirty=!0),t.restore()}renderTop(){const t=this.contextTop;this.clearContext(t),this.renderTopLayer(t),this.fire("after:render",{ctx:t})}setTargetFindTolerance(t){t=Math.round(t),this.targetFindTolerance=t;const e=this.getRetinaScaling(),s=Math.ceil((2*t+1)*e);this.pixelFindCanvasEl.width=this.pixelFindCanvasEl.height=s,this.pixelFindContext.scale(e,e)}isTargetTransparent(t,e,s){const i=this.targetFindTolerance,n=this.pixelFindContext;this.clearContext(n),n.save(),n.translate(-e+i,-s+i),n.transform(...this.viewportTransform);const r=t.selectionBackgroundColor;t.selectionBackgroundColor="",t.render(n),t.selectionBackgroundColor=r,n.restore();const o=Math.round(i*this.getRetinaScaling());return Ym(n,o,o,o)}_isSelectionKeyPressed(t){const e=this.selectionKey;return!!e&&(Array.isArray(e)?!!e.find(s=>!!s&&t[s]===!0):t[e])}_shouldClearSelection(t,e){const s=this.getActiveObjects(),i=this._activeObject;return!!(!e||e&&i&&s.length>1&&s.indexOf(e)===-1&&i!==e&&!this._isSelectionKeyPressed(t)||e&&!e.evented||e&&!e.selectable&&i&&i!==e)}_shouldCenterTransform(t,e,s){if(!t)return;let i;return e===Bc||e===je||e===hs||e===Th?i=this.centeredScaling||t.centeredScaling:e===ng&&(i=this.centeredRotation||t.centeredRotation),i?!s:s}_getOriginFromCorner(t,e){const s={x:t.originX,y:t.originY};return e&&(["ml","tl","bl"].includes(e)?s.x=Ut:["mr","tr","br"].includes(e)&&(s.x=vt),["tl","mt","tr"].includes(e)?s.y=sg:["bl","mb","br"].includes(e)&&(s.y=Je)),s}_setupCurrentTransform(t,e,s){var i;const n=e.group?Mr(this.getScenePoint(t),void 0,e.group.calcTransformMatrix()):this.getScenePoint(t),{key:r="",control:o}=e.getActiveControl()||{},h=s&&o?(i=o.getActionHandler(t,e,o))===null||i===void 0?void 0:i.bind(o):Vy,c=((f,p,m,y)=>{if(!p||!f)return"drag";const b=y.controls[p];return b.getActionName(m,b,y)})(s,r,t,e),u=t[this.centeredKey],d=this._shouldCenterTransform(e,c,u)?{x:tt,y:tt}:this._getOriginFromCorner(e,r),g={target:e,action:c,actionHandler:h,actionPerformed:!1,corner:r,scaleX:e.scaleX,scaleY:e.scaleY,skewX:e.skewX,skewY:e.skewY,offsetX:n.x-e.left,offsetY:n.y-e.top,originX:d.x,originY:d.y,ex:n.x,ey:n.y,lastX:n.x,lastY:n.y,theta:zt(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:u,original:E(E({},pg(e)),{},{originX:d.x,originY:d.y})};this._currentTransform=g,this.fire("before:transform",{e:t,transform:g})}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new O(e,s).transform(this.viewportTransform),o=new O(e+i,s+n).transform(this.viewportTransform),h=this.selectionLineWidth/2;let c=Math.min(r.x,o.x),u=Math.min(r.y,o.y),d=Math.max(r.x,o.x),g=Math.max(r.y,o.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(c,u,d-c,g-u)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,c+=h,u+=h,d-=h,g-=h,Ce.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(c,u,d-c,g-u))}findTarget(t){if(this.skipTargetFind)return;const e=this.getViewportPoint(t),s=this._activeObject,i=this.getActiveObjects();if(this.targets=[],s&&i.length>=1){if(s.findControl(e,Uc(t))||i.length>1&&this.searchPossibleTargets([s],e))return s;if(s===this.searchPossibleTargets([s],e)){if(this.preserveObjectStacking){const n=this.targets;this.targets=[];const r=this.searchPossibleTargets(this._objects,e);return t[this.altSelectionKey]&&r&&r!==s?(this.targets=n,s):r}return s}}return this.searchPossibleTargets(this._objects,e)}_pointIsInObjectSelectionArea(t,e){let s=t.getCoords();const i=this.getZoom(),n=t.padding/i;if(n){const[r,o,h,c]=s,u=Math.atan2(o.y-r.y,o.x-r.x),d=Ws(u)*n,g=zs(u)*n,f=d+g,p=d-g;s=[new O(r.x-p,r.y-f),new O(o.x+f,o.y-p),new O(h.x+p,h.y+f),new O(c.x-f,c.y+p)]}return Nt.isPointInPolygon(e,s)}_checkTarget(t,e){return!!(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,Mr(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(Gc(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&&Gc(s)&&s.interactive&&this.targets[0]){const i=this.targets;for(let n=i.length-1;n>0;n--){const r=i[n];if(!Gc(r)||!r.interactive)return r}return i[0]}return s}getViewportPoint(t){return this._pointer?this._pointer:this.getPointer(t,!0)}getScenePoint(t){return this._absolutePointer?this._absolutePointer:this.getPointer(t)}getPointer(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];const s=this.upperCanvasEl,i=s.getBoundingClientRect();let n=vm(t),r=i.width||0,o=i.height||0;r&&o||(Je in i&&sg in i&&(o=Math.abs(i.top-i.bottom)),Ut in i&&vt in i&&(r=Math.abs(i.right-i.left))),this.calcOffset(),n.x=n.x-this._offset.left,n.y=n.y-this._offset.top,e||(n=Mr(n,void 0,this.viewportTransform));const h=this.getRetinaScaling();h!==1&&(n.x/=h,n.y/=h);const c=r===0||o===0?new O(1,1):new O(s.width/r,s.height/o);return n.multiply(c)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=As(),this.pixelFindContext=this.pixelFindCanvasEl.getContext("2d",{willReadFrequently:!0}),this.setTargetFindTolerance(this.targetFindTolerance)}getTopContext(){return this.elements.upper.ctx}getSelectionContext(){return this.elements.upper.ctx}getSelectionElement(){return this.elements.upper.el}getActiveObject(){return this._activeObject}getActiveObjects(){const t=this._activeObject;return kr(t)?t.getObjects():t?[t]:[]}_fireSelectionEvents(t,e){let s=!1,i=!1;const n=this.getActiveObjects(),r=[],o=[];t.forEach(h=>{n.includes(h)||(s=!0,h.fire("deselected",{e,target:h}),o.push(h))}),n.forEach(h=>{t.includes(h)||(s=!0,h.fire("selected",{e,target:h}),r.push(h))}),t.length>0&&n.length>0?(i=!0,s&&this.fire("selection:updated",{e,selected:r,deselected:o})):n.length>0?(i=!0,this.fire("selection:created",{e,selected:r})):t.length>0&&(i=!0,this.fire("selection:cleared",{e,deselected:o})),i&&(this._objectsToRender=void 0)}setActiveObject(t,e){const s=this.getActiveObjects(),i=this._setActiveObject(t,e);return this._fireSelectionEvents(s,e),i}_setActiveObject(t,e){const s=this._activeObject;return s!==t&&!(!this._discardActiveObject(e,t)&&this._activeObject)&&!t.onSelect({e})&&(this._activeObject=t,kr(t)&&s!==t&&t.set("canvas",this),t.setCoords(),!0)}_discardActiveObject(t,e){const s=this._activeObject;return!!s&&!s.onDeselect({e:t,object:e})&&(this._currentTransform&&this._currentTransform.target===s&&this.endCurrentTransform(t),kr(s)&&s===this._hoveredTarget&&(this._hoveredTarget=void 0),this._activeObject=void 0,!0)}discardActiveObject(t){const e=this.getActiveObjects(),s=this.getActiveObject();e.length&&this.fire("before:selection:cleared",{e:t,deselected:[s]});const i=this._discardActiveObject(t);return this._fireSelectionEvents(e,t),i}endCurrentTransform(t){const e=this._currentTransform;this._finalizeCurrentTransform(t),e&&e.target&&(e.target.isMoving=!1),this._currentTransform=null}_finalizeCurrentTransform(t){const e=this._currentTransform,s=e.target,i={e:t,target:s,transform:e,action:e.action};s._scaling&&(s._scaling=!1),s.setCoords(),e.actionPerformed&&(this.fire("object:modified",i),s.fire(Hc,i))}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeObject;kr(t)&&(t.removeAll(),t.dispose()),delete this._activeObject,super.destroy(),this.pixelFindContext=null,this.pixelFindCanvasEl=void 0}clear(){this.discardActiveObject(),this._activeObject=void 0,this.clearContext(this.contextTop),super.clear()}drawControls(t){const e=this._activeObject;e&&e._renderControls(t)}_toObject(t,e,s){const i=this._realizeGroupTransformOnObject(t),n=super._toObject(t,e,s);return t.set(i),n}_realizeGroupTransformOnObject(t){const{group:e}=t;if(e&&kr(e)&&this._activeObject===e){const s=Er(t,["angle","flipX","flipY",vt,je,hs,Uo,Yo,Je]);return bm(t,e.calcOwnMatrix()),s}return{}}_setSVGObject(t,e,s){const i=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,s),e.set(i)}}T(du,"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 lw{constructor(t){T(this,"targets",[]),T(this,"__disposer",void 0);const e=()=>{const{hiddenTextarea:i}=t.getActiveObject()||{};i&&i.focus()},s=t.upperCanvasEl;s.addEventListener("click",e),this.__disposer=()=>s.removeEventListener("click",e)}exitTextEditing(){this.target=void 0,this.targets.forEach(t=>{t.isEditing&&t.exitEditing()})}add(t){this.targets.push(t)}remove(t){this.unregister(t),Ar(this.targets,t)}register(t){this.target=t}unregister(t){t===this.target&&(this.target=void 0)}onMouseMove(t){var e;!((e=this.target)===null||e===void 0)&&e.isEditing&&this.target.updateSelectionOnMouseMove(t)}clear(){this.targets=[],this.target=void 0}dispose(){this.clear(),this.__disposer(),delete this.__disposer}}const cw=["target","oldTarget","fireCanvas","e"],ls={passive:!1},na=(a,t)=>{const e=a.getViewportPoint(t),s=a.getScenePoint(t);return{viewportPoint:e,scenePoint:s,pointer:e,absolutePointer:s}},Gn=function(a){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return a.addEventListener(...e)},Es=function(a){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return a.removeEventListener(...e)},uw={mouse:{in:"over",out:"out",targetIn:"mouseover",targetOut:"mouseout",canvasIn:"mouse:over",canvasOut:"mouse:out"},drag:{in:"enter",out:"leave",targetIn:"dragenter",targetOut:"dragleave",canvasIn:"drag:enter",canvasOut:"drag:leave"}};class Bg extends du{constructor(t){super(t,arguments.length>1&&arguments[1]!==void 0?arguments[1]:{}),T(this,"_isClick",void 0),T(this,"textEditingManager",new lw(this)),["_onMouseDown","_onTouchStart","_onMouseMove","_onMouseUp","_onTouchEnd","_onResize","_onMouseWheel","_onMouseOut","_onMouseEnter","_onContextMenu","_onDoubleClick","_onDragStart","_onDragEnd","_onDragProgress","_onDragOver","_onDragEnter","_onDragLeave","_onDrop"].forEach(e=>{this[e]=this[e].bind(this)}),this.addOrRemove(Gn,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const s=this.upperCanvasEl,i=this._getEventPrefix();t(gm(s),"resize",this._onResize),t(s,i+"down",this._onMouseDown),t(s,"".concat(i,"move"),this._onMouseMove,ls),t(s,"".concat(i,"out"),this._onMouseOut),t(s,"".concat(i,"enter"),this._onMouseEnter),t(s,"wheel",this._onMouseWheel),t(s,"contextmenu",this._onContextMenu),t(s,"dblclick",this._onDoubleClick),t(s,"dragstart",this._onDragStart),t(s,"dragend",this._onDragEnd),t(s,"dragover",this._onDragOver),t(s,"dragenter",this._onDragEnter),t(s,"dragleave",this._onDragLeave),t(s,"drop",this._onDrop),this.enablePointerEvents||t(s,"touchstart",this._onTouchStart,ls)}removeListeners(){this.addOrRemove(Es,"remove");const t=this._getEventPrefix(),e=Us(this.upperCanvasEl);Es(e,"".concat(t,"up"),this._onMouseUp),Es(e,"touchend",this._onTouchEnd,ls),Es(e,"".concat(t,"move"),this._onMouseMove,ls),Es(e,"touchmove",this._onMouseMove,ls),clearTimeout(this._willAddMouseDown)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s=E({e:t},na(this,t));this.fire("mouse:out",E(E({},s),{},{target:e})),this._hoveredTarget=void 0,e&&e.fire("mouseout",E({},s)),this._hoveredTargets.forEach(i=>{this.fire("mouse:out",E(E({},s),{},{target:i})),i&&i.fire("mouseout",E({},s))}),this._hoveredTargets=[]}_onMouseEnter(t){this._currentTransform||this.findTarget(t)||(this.fire("mouse:over",E({e:t},na(this,t))),this._hoveredTarget=void 0,this._hoveredTargets=[])}_onDragStart(t){this._isClick=!1;const e=this.getActiveObject();if(e&&e.onDragStart(t)){this._dragSource=e;const s={e:t,target:e};return this.fire("dragstart",s),e.fire("dragstart",s),void Gn(this.upperCanvasEl,"drag",this._onDragProgress)}fg(t)}_renderDragEffects(t,e,s){let i=!1;const n=this._dropTarget;n&&n!==e&&n!==s&&(n.clearContextTop(),i=!0),e==null||e.clearContextTop(),s!==e&&(s==null||s.clearContextTop());const r=this.contextTop;r.save(),r.transform(...this.viewportTransform),e&&(r.save(),e.transform(r),e.renderDragSourceEffect(t),r.restore(),i=!0),s&&(r.save(),s.transform(r),s.renderDropTargetEffect(t),r.restore(),i=!0),r.restore(),i&&(this.contextTopDirty=!0)}_onDragEnd(t){const e=!!t.dataTransfer&&t.dataTransfer.dropEffect!==Ie,s=e?this._activeObject:void 0,i={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:s};Es(this.upperCanvasEl,"drag",this._onDragProgress),this.fire("dragend",i),this._dragSource&&this._dragSource.fire("dragend",i),delete this._dragSource,this._onMouseUp(t)}_onDragProgress(t){const e={e:t,target:this._dragSource,dragSource:this._dragSource,dropTarget:this._draggedoverTarget};this.fire("drag",e),this._dragSource&&this._dragSource.fire("drag",e)}findDragTargets(t){return this.targets=[],{target:this._searchPossibleTargets(this._objects,this.getViewportPoint(t)),targets:[...this.targets]}}_onDragOver(t){const e="dragover",{target:s,targets:i}=this.findDragTargets(t),n=this._dragSource,r={e:t,target:s,subTargets:i,dragSource:n,canDrop:!1,dropTarget:void 0};let o;this.fire(e,r),this._fireEnterLeaveEvents(s,r),s&&(s.canDrop(t)&&(o=s),s.fire(e,r));for(let h=0;h<i.length;h++){const c=i[h];c.canDrop(t)&&(o=c),c.fire(e,r)}this._renderDragEffects(t,n,o),this._dropTarget=o}_onDragEnter(t){const{target:e,targets:s}=this.findDragTargets(t),i={e:t,target:e,subTargets:s,dragSource:this._dragSource};this.fire("dragenter",i),this._fireEnterLeaveEvents(e,i)}_onDragLeave(t){const e={e:t,target:this._draggedoverTarget,subTargets:this.targets,dragSource:this._dragSource};this.fire("dragleave",e),this._fireEnterLeaveEvents(void 0,e),this._renderDragEffects(t,this._dragSource),this._dropTarget=void 0,this.targets=[],this._hoveredTargets=[]}_onDrop(t){const{target:e,targets:s}=this.findDragTargets(t),i=this._basicEventHandler("drop:before",E({e:t,target:e,subTargets:s,dragSource:this._dragSource},na(this,t)));i.didDrop=!1,i.dropTarget=void 0,this._basicEventHandler("drop",i),this.fire("drop:after",i)}_onContextMenu(t){const e=this.findTarget(t),s=this.targets||[],i=this._basicEventHandler("contextmenu:before",{e:t,target:e,subTargets:s});return this.stopContextMenu&&fg(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=Us(i);Gn(r,"touchend",this._onTouchEnd,ls),e&&Gn(r,"touchmove",this._onMouseMove,ls),Es(i,"".concat(n,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();Es(e,"".concat(s,"move"),this._onMouseMove,ls);const i=Us(e);Gn(i,"".concat(s,"up"),this._onMouseUp),Gn(i,"".concat(s,"move"),this._onMouseMove,ls)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),s=Us(this.upperCanvasEl);Es(s,"touchend",this._onTouchEnd,ls),Es(s,"touchmove",this._onMouseMove,ls),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout(()=>{Gn(this.upperCanvasEl,"".concat(e,"down"),this._onMouseDown),this._willAddMouseDown=0},400)}_onMouseUp(t){this.__onMouseUp(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();if(this._isMainEvent(t)){const i=Us(this.upperCanvasEl);Es(i,"".concat(s,"up"),this._onMouseUp),Es(i,"".concat(s,"move"),this._onMouseMove,ls),Gn(e,"".concat(s,"move"),this._onMouseMove,ls)}}_onMouseMove(t){const e=this.getActiveObject();!this.allowTouchScrolling&&(!e||!e.shouldStartDragging(t))&&t.preventDefault&&t.preventDefault(),this.__onMouseMove(t)}_onResize(){this.calcOffset(),this._resetTransformEventData()}_shouldRender(t){const e=this.getActiveObject();return!!e!=!!t||e&&t&&e!==t}__onMouseUp(t){var e;this._cacheTransformEventData(t),this._handleEvent(t,"up:before");const s=this._currentTransform,i=this._isClick,n=this._target,{button:r}=t;if(r)return(this.fireMiddleClick&&r===1||this.fireRightClick&&r===2)&&this._handleEvent(t,"up"),void this._resetTransformEventData();if(this.isDrawingMode&&this._isCurrentlyDrawing)return void this._onMouseUpInDrawingMode(t);if(!this._isMainEvent(t))return;let o,h,c=!1;if(s&&(this._finalizeCurrentTransform(t),c=s.actionPerformed),!i){const u=n===this._activeObject;this.handleSelection(t),c||(c=this._shouldRender(n)||!u&&n===this._activeObject)}if(n){const u=n.findControl(this.getViewportPoint(t),Uc(t)),{key:d,control:g}=u||{};if(h=d,n.selectable&&n!==this._activeObject&&n.activeOn==="up")this.setActiveObject(n,t),c=!0;else if(g){const f=g.getMouseUpHandler(t,n,g);f&&(o=this.getScenePoint(t),f.call(g,t,s,o.x,o.y))}n.isMoving=!1}if(s&&(s.target!==n||s.corner!==h)){const u=s.target&&s.target.controls[s.corner],d=u&&u.getMouseUpHandler(t,s.target,u);o=o||this.getScenePoint(t),d&&d.call(u,t,s,o.x,o.y)}this._setCursorFromEvent(t,n),this._handleEvent(t,"up"),this._groupSelector=null,this._currentTransform=null,n&&(n.__corner=void 0),c?this.requestRenderAll():i||(e=this._activeObject)!==null&&e!==void 0&&e.isEditing||this.renderTop()}_basicEventHandler(t,e){const{target:s,subTargets:i=[]}=e;this.fire(t,e),s&&s.fire(t,e);for(let n=0;n<i.length;n++)i[n]!==s&&i[n].fire(t,e);return e}_handleEvent(t,e){const s=this._target,i=this.targets||[],n=E(E({e:t,target:s,subTargets:i},na(this,t)),{},{transform:this._currentTransform},e==="up:before"||e==="up"?{isClick:this._isClick,currentTarget:this.findTarget(t),currentSubTargets:this.targets}:{});this.fire("mouse:".concat(e),n),s&&s.fire("mouse".concat(e),n);for(let r=0;r<i.length;r++)i[r]!==s&&i[r].fire("mouse".concat(e),n)}_onMouseDownInDrawingMode(t){this._isCurrentlyDrawing=!0,this.getActiveObject()&&(this.discardActiveObject(t),this.requestRenderAll());const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseDown(e,{e:t,pointer:e}),this._handleEvent(t,"down")}_onMouseMoveInDrawingMode(t){if(this._isCurrentlyDrawing){const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseMove(e,{e:t,pointer:e})}this.setCursor(this.freeDrawingCursor),this._handleEvent(t,"move")}_onMouseUpInDrawingMode(t){const e=this.getScenePoint(t);this.freeDrawingBrush?this._isCurrentlyDrawing=!!this.freeDrawingBrush.onMouseUp({e:t,pointer:e}):this._isCurrentlyDrawing=!1,this._handleEvent(t,"up")}__onMouseDown(t){this._isClick=!0,this._cacheTransformEventData(t),this._handleEvent(t,"down:before");let e=this._target;const{button:s}=t;if(s)return(this.fireMiddleClick&&s===1||this.fireRightClick&&s===2)&&this._handleEvent(t,"down"),void this._resetTransformEventData();if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t)||this._currentTransform)return;let i=this._shouldRender(e),n=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,n=!0,i=!0):this._shouldClearSelection(t,e)&&this.discardActiveObject(t),this.selection&&(!e||!e.selectable&&!e.isEditing&&e!==this._activeObject)){const r=this.getScenePoint(t);this._groupSelector={x:r.x,y:r.y,deltaY:0,deltaX:0}}if(e){const r=e===this._activeObject;e.selectable&&e.activeOn==="down"&&this.setActiveObject(e,t);const o=e.findControl(this.getViewportPoint(t),Uc(t));if(e===this._activeObject&&(o||!n)){this._setupCurrentTransform(t,e,r);const h=o?o.control:void 0,c=this.getScenePoint(t),u=h&&h.getMouseDownHandler(t,e,h);u&&u.call(h,t,this._currentTransform,c.x,c.y)}}i&&(this._objectsToRender=void 0),this._handleEvent(t,"down"),i&&this.requestRenderAll()}_resetTransformEventData(){this._target=void 0,this._pointer=void 0,this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getViewportPoint(t),this._absolutePointer=Mr(this._pointer,void 0,this.viewportTransform),this._target=this._currentTransform?this._currentTransform.target:this.findTarget(t)}__onMouseMove(t){if(this._isClick=!1,this._cacheTransformEventData(t),this._handleEvent(t,"move:before"),this.isDrawingMode)return void this._onMouseMoveInDrawingMode(t);if(!this._isMainEvent(t))return;const e=this._groupSelector;if(e){const s=this.getScenePoint(t);e.deltaX=s.x-e.x,e.deltaY=s.y-e.y,this.renderTop()}else if(this._currentTransform)this._transformObject(t);else{const s=this.findTarget(t);this._setCursorFromEvent(t,s),this._fireOverOutEvents(t,s)}this.textEditingManager.onMouseMove(t),this._handleEvent(t,"move"),this._resetTransformEventData()}_fireOverOutEvents(t,e){const s=this._hoveredTarget,i=this._hoveredTargets,n=this.targets,r=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("mouse",{e:t,target:e,oldTarget:s,fireCanvas:!0});for(let o=0;o<r;o++)this.fireSyntheticInOutEvents("mouse",{e:t,target:n[o],oldTarget:i[o]});this._hoveredTarget=e,this._hoveredTargets=this.targets.concat()}_fireEnterLeaveEvents(t,e){const s=this._draggedoverTarget,i=this._hoveredTargets,n=this.targets,r=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("drag",E(E({},e),{},{target:t,oldTarget:s,fireCanvas:!0}));for(let o=0;o<r;o++)this.fireSyntheticInOutEvents("drag",E(E({},e),{},{target:n[o],oldTarget:i[o]}));this._draggedoverTarget=t}fireSyntheticInOutEvents(t,e){let{target:s,oldTarget:i,fireCanvas:n,e:r}=e,o=Ot(e,cw);const{targetIn:h,targetOut:c,canvasIn:u,canvasOut:d}=uw[t],g=i!==s;if(i&&g){const f=E(E({},o),{},{e:r,target:i,nextTarget:s},na(this,r));n&&this.fire(d,f),i.fire(c,f)}if(s&&g){const f=E(E({},o),{},{e:r,target:s,previousTarget:i},na(this,r));n&&this.fire(u,f),s.fire(h,f)}}__onMouseWheel(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()}_transformObject(t){const e=this.getScenePoint(t),s=this._currentTransform,i=s.target,n=i.group?Mr(e,void 0,i.group.calcTransformMatrix()):e;s.shiftKey=t.shiftKey,s.altKey=!!this.centeredKey&&t[this.centeredKey],this._performTransformAction(t,s,n),s.actionPerformed&&this.requestRenderAll()}_performTransformAction(t,e,s){const{action:i,actionHandler:n,target:r}=e,o=!!n&&n(t,e,s.x,s.y);o&&r.setCoords(),i==="drag"&&o&&(e.target.isMoving=!0,this.setCursor(e.target.moveCursor||this.moveCursor)),e.actionPerformed=e.actionPerformed||o}_setCursorFromEvent(t,e){if(!e)return void this.setCursor(this.defaultCursor);let s=e.hoverCursor||this.hoverCursor;const i=kr(this._activeObject)?this._activeObject:null,n=(!i||e.group!==i)&&e.findControl(this.getViewportPoint(t));if(n){const r=n.control;this.setCursor(r.cursorStyleHandler(t,r,e))}else e.subTargetCheck&&this.targets.concat().reverse().map(r=>{s=r.hoverCursor||s}),this.setCursor(s)}handleMultiSelection(t,e){const s=this._activeObject,i=kr(s);if(s&&this._isSelectionKeyPressed(t)&&this.selection&&e&&e.selectable&&(s!==e||i)&&(i||!e.isDescendantOf(s)&&!s.isDescendantOf(e))&&!e.onSelect({e:t})&&!s.getActiveControl()){if(i){const n=s.getObjects();if(e===s){const r=this.getViewportPoint(t);if(!(e=this.searchPossibleTargets(n,r)||this.searchPossibleTargets(this._objects,r))||!e.selectable)return!1}e.group===s?(s.remove(e),this._hoveredTarget=e,this._hoveredTargets=[...this.targets],s.size()===1&&this._setActiveObject(s.item(0),t)):(s.multiSelectAdd(e),this._hoveredTarget=s,this._hoveredTargets=[...this.targets]),this._fireSelectionEvents(n,t)}else{s.isEditing&&s.exitEditing();const n=new(W.getClass("ActiveSelection"))([],{canvas:this});n.multiSelectAdd(s,e),this._hoveredTarget=n,this._setActiveObject(n,t),this._fireSelectionEvents([s],t)}return!0}return!1}handleSelection(t){if(!this.selection||!this._groupSelector)return!1;const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new O(e,s),o=r.add(new O(i,n)),h=r.min(o),c=r.max(o).subtract(h),u=this.collectObjects({left:h.x,top:h.y,width:c.x,height:c.y},{includeIntersecting:!this.selectionFullyContained}),d=r.eq(o)?u[0]?[u[0]]:[]:u.length>1?u.filter(g=>!g.onSelect({e:t})).reverse():u;if(d.length===1)this.setActiveObject(d[0],t);else if(d.length>1){const g=W.getClass("ActiveSelection");this.setActiveObject(new g(d,{canvas:this}),t)}return this._groupSelector=null,!0}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const A0={x1:0,y1:0,x2:0,y2:0},dw=E(E({},A0),{},{r1:0,r2:0}),ra=(a,t)=>isNaN(a)&&typeof t=="number"?t:a,gw=/^(\d+\.\d+)%|(\d+)%$/;function T0(a){return a&&gw.test(a)}function E0(a,t){const e=typeof a=="number"?a:typeof a=="string"?parseFloat(a)/(T0(a)?100:1):NaN;return Pr(0,ra(e,t),1)}const fw=/\s*;\s*/,pw=/\s*:\s*/;function mw(a,t){let e,s;const i=a.getAttribute("style");if(i){const r=i.split(fw);r[r.length-1]===""&&r.pop();for(let o=r.length;o--;){const[h,c]=r[o].split(pw).map(u=>u.trim());h==="stop-color"?e=c:h==="stop-opacity"&&(s=c)}}const n=new _t(e||a.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:E0(a.getAttribute("offset"),0),color:n.toRgb(),opacity:ra(parseFloat(s||a.getAttribute("stop-opacity")||""),1)*n.getAlpha()*t}}function vw(a,t){const e=[],s=a.getElementsByTagName("stop"),i=E0(t,1);for(let n=s.length;n--;)e.push(mw(s[n],i));return e}function k0(a){return a.nodeName==="linearGradient"||a.nodeName==="LINEARGRADIENT"?"linear":"radial"}function M0(a){return a.getAttribute("gradientUnits")==="userSpaceOnUse"?"pixels":"percentage"}function Ks(a,t){return a.getAttribute(t)}function bw(a,t){return function(e,s){let i,{width:n,height:r,gradientUnits:o}=s;return Object.keys(e).reduce((h,c)=>{const u=e[c];return u==="Infinity"?i=1:u==="-Infinity"?i=0:(i=typeof u=="string"?parseFloat(u):u,typeof u=="string"&&T0(u)&&(i*=.01,o==="pixels"&&(c!=="x1"&&c!=="x2"&&c!=="r2"||(i*=n),c!=="y1"&&c!=="y2"||(i*=r)))),h[c]=i,h},{})}(k0(a)==="linear"?function(e){return{x1:Ks(e,"x1")||0,y1:Ks(e,"y1")||0,x2:Ks(e,"x2")||"100%",y2:Ks(e,"y2")||0}}(a):function(e){return{x1:Ks(e,"fx")||Ks(e,"cx")||"50%",y1:Ks(e,"fy")||Ks(e,"cy")||"50%",r1:0,x2:Ks(e,"cx")||"50%",y2:Ks(e,"cy")||"50%",r2:Ks(e,"r")||"50%"}}(a),E(E({},t),{},{gradientUnits:M0(a)}))}class Bh{constructor(t){const{type:e="linear",gradientUnits:s="pixels",coords:i={},colorStops:n=[],offsetX:r=0,offsetY:o=0,gradientTransform:h,id:c}=t||{};Object.assign(this,{type:e,gradientUnits:s,coords:E(E({},e==="radial"?dw:A0),i),colorStops:n,offsetX:r,offsetY:o,gradientTransform:h,id:c?"".concat(c,"_").concat(Bn()):Bn()})}addColorStop(t){for(const e in t){const s=new _t(t[e]);this.colorStops.push({offset:parseFloat(e),color:s.toRgb(),opacity:s.getAlpha()})}return this}toObject(t){return E(E({},Er(this,t)),{},{type:this.type,coords:E({},this.coords),colorStops:this.colorStops.map(e=>E({},e)),offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?[...this.gradientTransform]:void 0})}toSVG(t){let{additionalTransform:e}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const s=[],i=this.gradientTransform?this.gradientTransform.concat():Fe.concat(),n=this.gradientUnits==="pixels"?"userSpaceOnUse":"objectBoundingBox",r=this.colorStops.map(d=>E({},d)).sort((d,g)=>d.offset-g.offset);let o=-this.offsetX,h=-this.offsetY;var c;n==="objectBoundingBox"?(o/=t.width,h/=t.height):(o+=t.width/2,h+=t.height/2),(c=t)&&typeof c._renderPathCommands=="function"&&this.gradientUnits!=="percentage"&&(o-=t.pathOffset.x,h-=t.pathOffset.y),i[4]-=o,i[5]-=h;const u=['id="SVGID_'.concat(this.id,'"'),'gradientUnits="'.concat(n,'"'),'gradientTransform="'.concat(e?e+" ":"").concat(Oh(i),'"'),""].join(" ");if(this.type==="linear"){const{x1:d,y1:g,x2:f,y2:p}=this.coords;s.push("<linearGradient ",u,' x1="',d,'" y1="',g,'" x2="',f,'" y2="',p,`">
|
|
71
|
+
`)}else if(this.type==="radial"){const{x1:d,y1:g,x2:f,y2:p,r1:m,r2:y}=this.coords,b=m>y;s.push("<radialGradient ",u,' cx="',b?d:f,'" cy="',b?g:p,'" r="',b?m:y,'" fx="',b?f:d,'" fy="',b?p:g,`">
|
|
72
|
+
`),b&&(r.reverse(),r.forEach(C=>{C.offset=1-C.offset}));const x=Math.min(m,y);if(x>0){const C=x/Math.max(m,y);r.forEach(A=>{A.offset+=C*(1-A.offset)})}}return r.forEach(d=>{let{color:g,offset:f,opacity:p}=d;s.push("<stop ",'offset="',100*f+"%",'" style="stop-color:',g,p!==void 0?";stop-opacity: "+p:";",`"/>
|
|
73
73
|
`)}),s.push(this.type==="linear"?"</linearGradient>":"</radialGradient>",`
|
|
74
|
-
`),s.join("")}toLive(t){const{x1:e,y1:s,x2:i,y2:n,r1:r,r2:
|
|
75
|
-
`)}static async fromObject(t,e){let{type:s,source:i,patternTransform:n}=t,r=
|
|
76
|
-
`)]}_getOffsetTransform(){const t=dt.NUM_FRACTION_DIGITS;return" translate(".concat(Dt(-this.pathOffset.x,t),", ").concat(Dt(-this.pathOffset.y,t),")")}toClipPathSVG(t){const e=this._getOffsetTransform();return" "+this._createBaseClipPathSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}toSVG(t){const e=this._getOffsetTransform();return this._createBaseSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}complexity(){return this.path.length}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{width:e,height:s,pathOffset:i}=this._calcDimensions();this.set({width:e,height:s,pathOffset:i}),t&&this.setPositionByOrigin(i,
|
|
77
|
-
`];{const{radius:e}=this,s=
|
|
78
|
-
`]}}static async fromElement(t,e,s){const i=
|
|
79
|
-
`)]}static async fromElement(t,e,s){const i=
|
|
80
|
-
`)]}_render(t){t.beginPath(),t.save(),t.transform(1,0,0,this.ry/this.rx,0,0),t.arc(0,0,this.rx,0,
|
|
81
|
-
`)]}_render(t){const e=this.points.length,s=this.pathOffset.x,i=this.pathOffset.y;if(e&&!isNaN(this.points[e-1].y)){t.beginPath(),t.moveTo(this.points[0].x-s,this.points[0].y-i);for(let n=0;n<e;n++){const r=this.points[n];t.lineTo(r.x-s,r.y-i)}!this.isOpen()&&t.closePath(),this._renderPaintInOrder(t)}}complexity(){return this.points.length}static async fromElement(t,e,s){return new this(
|
|
82
|
-
`)}const Mw=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let Eg;class Se extends A0{static getDefaults(){return E(E({},super.getDefaults()),Se.ownDefaults)}constructor(t,e){super(),T(this,"__charBounds",[]),Object.assign(this,Se.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=xg(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(ui)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,s,i,n,r,a;for(let h=0,l=this._textLines.length;h<l;h++)if((this.textAlign===ui||h!==l-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===Le?(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 st:t.textBaseline="middle";break;case"ascender":t.textBaseline=Ue;break;case"descender":t.textBaseline=Hd}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,l=this._getLineLeftOffset(n);let u,d,g=0,f=0,p=this.getValueOfPropertyAt(n,0,"textBackgroundColor");for(let m=0;m<h;m++){const _=this.__charBounds[n][m];d=this.getValueOfPropertyAt(n,m,"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+l+f,this.direction==="rtl"&&(u=this.width-u-g),t.fillStyle=p,p&&t.fillRect(u,i,g,a/this.lineHeight),f=_.left,g=_.width,p=d):g+=_.kernedWidth}d&&!this.path&&(u=s+l+f,this.direction==="rtl"&&(u=this.width-u-g),t.fillStyle=d,t.fillRect(u,i,g,a/this.lineHeight)),i+=a}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,s,i){const n=dh.getFontCache(e),r=this._getFontDeclaration(e),a=s+t,h=s&&r===this._getFontDeclaration(i),l=e.fontSize/this.CACHE_FONT_SIZE;let u,d,g,f;if(s&&n[s]!==void 0&&(g=n[s]),n[t]!==void 0&&(f=u=n[t]),h&&n[a]!==void 0&&(d=n[a],f=d-g),u===void 0||g===void 0||d===void 0){const p=function(){return Eg||(Eg=Is({width:0,height:0}).getContext("2d")),Eg}();this._setTextStyles(p,e,!0),u===void 0&&(f=u=p.measureText(t).width,n[t]=u),g===void 0&&h&&s&&(g=p.measureText(s).width,n[s]=g),h&&d===void 0&&(d=p.measureText(a).width,n[a]=d,f=d-g)}return{width:u*l,kernedWidth:f*l}}getHeightOfChar(t,e){return this.getValueOfPropertyAt(t,e,"fontSize")}measureLine(t){const e=this._measureLine(t);return this.charSpacing!==0&&(e.width-=this._getWidthOfCharSpacing()),e.width<0&&(e.width=0),e}_measureLine(t){let e,s,i=0;const n=this.pathSide===Vt,r=this.path,a=this._textLines[t],h=a.length,l=new Array(h);this.__charBounds[t]=l;for(let u=0;u<h;u++){const d=a[u];s=this._getGraphemeBox(d,t,u,e),l[u]=s,i+=s.kernedWidth,e=d}if(l[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 mt:u=n?d-i:0;break;case st:u=(d-i)/2;break;case Vt:u=n?0:d-i}u+=this.pathStartOffset*(n?-1:1);for(let g=n?h-1:0;n?g>=0:g<h;n?g--:g++)s=l[g],u>d?u%=d:u<0&&(u+=d),this._setGraphemeOnPath(u,s),u+=s.kernedWidth}return{width:i,numOfSpaces:0}}_setGraphemeOnPath(t,e){const s=t+e.kernedWidth/2,i=this.path,n=h0(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===Vt?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 l,u=h.kernedWidth,d=h.width;this.charSpacing!==0&&(l=this._getWidthOfCharSpacing(),d+=l,u+=l);const g={width:d,left:0,height:r.fontSize,kernedWidth:u,deltaY:r.deltaY};if(s>0&&!n){const f=this.__charBounds[e][s-1];g.left=f.left+f.width+h.kernedWidth-h.width}return g}getHeightOfLine(t){if(this.__lineHeights[t])return this.__lineHeights[t];let e=this.getHeightOfChar(t,0);for(let s=1,i=this._textLines[t].length;s<i;s++)e=Math.max(this.getHeightOfChar(t,s),e);return this.__lineHeights[t]=e*this.lineHeight*this._fontSizeMult}calcTextHeight(){let t,e=0;for(let s=0,i=this._textLines.length;s<i;s++)t=this.getHeightOfLine(s),e+=s===i-1?t/this.lineHeight:t;return e}_getLeftOffset(){return this.direction==="ltr"?-this.width/2:this.width/2}_getTopOffset(){return-this.height/2}_renderTextCommon(t,e){t.save();let s=0;const i=this._getLeftOffset(),n=this._getTopOffset();for(let r=0,a=this._textLines.length;r<a;r++){const h=this.getHeightOfLine(r),l=h/this.lineHeight,u=this._getLineLeftOffset(r);this._renderTextLine(e,t,this._textLines[r],i+u,n+s+l,r),s+=h}t.restore()}_renderTextFill(t){(this.fill||this.styleHas($t))&&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(ui),l=this.path,u=!h&&this.charSpacing===0&&this.isEmptyStyles(r)&&!l,d=this.direction==="ltr",g=this.direction==="ltr"?1:-1,f=e.direction;let p,m,_,b,x,S="",A=0;if(e.save(),f!==this.direction&&(e.canvas.setAttribute("dir",d?"ltr":"rtl"),e.direction=d?"ltr":"rtl",e.textAlign=d?mt:Vt),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,P=s.length-1;k<=P;k++)b=k===P||this.charSpacing||l,S+=s[k],_=this.__charBounds[r][k],A===0?(i+=g*(_.kernedWidth-_.width),A+=_.width):A+=_.kernedWidth,h&&!b&&this._reSpaceAndTab.test(s[k])&&(b=!0),b||(p=p||this.getCompleteStyleDeclaration(r,k),m=this.getCompleteStyleDeclaration(r,k+1),b=Xc(p,m,!1)),b&&(l?(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=m,i+=g*A,A=0);e.restore()}_applyPatternGradientTransformText(t){const e=this.width+this.strokeWidth,s=this.height+this.strokeWidth,i=Is({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 bs(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),l=this.getCompleteStyleDeclaration(s,i),u=t==="fillText"&&l.fill,d=t==="strokeText"&&l.stroke&&l.strokeWidth;if(d||u){if(e.save(),e.font=this._getFontDeclaration(l),h.textBackgroundColor&&this._removeShadow(e),h.deltaY&&(a+=h.deltaY),u){const g=this._setFillStyles(e,l);e.fillText(n,r-g.offsetX,a-g.offsetY)}if(d){const g=this._setStrokeStyles(e,l);e.strokeText(n,r-g.offsetX,a-g.offsetY)}e.restore()}}setSuperscript(t,e){this._setScript(t,e,this.superscript)}setSubscript(t,e){this._setScript(t,e,this.subscript)}_setScript(t,e,s){const i=this.get2DCursorLocation(t,!0),n=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"fontSize"),r=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"deltaY"),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===ui||i===kh&&!r||i===Eh&&!r||i===Qc&&!r?0:(i===st&&(a=s/2),i===Vt&&(a=s),i===kh&&(a=s/2),i===Eh&&(a=s),n==="rtl"&&(i===Vt||i===ui||i===Eh?a=0:i===mt||i===Qc?a=-s:i!==st&&i!==kh||(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,l=this._textLines.length;h<l;h++){const u=this.getHeightOfLine(h);if(!this[e]&&!this.styleHas(e,h)){s+=u;continue}const d=this._textLines[h],g=u/this.lineHeight,f=this._getLineLeftOffset(h);let p,m,_=0,b=0,x=this.getValueOfPropertyAt(h,0,e),S=this.getValueOfPropertyAt(h,0,$t);const A=s+g*(1-this._fontSizeFraction);let k=this.getHeightOfChar(h,0),P=this.getValueOfPropertyAt(h,0,"deltaY");for(let O=0,R=d.length;O<R;O++){const I=this.__charBounds[h][O];p=this.getValueOfPropertyAt(h,O,e),m=this.getValueOfPropertyAt(h,O,$t);const j=this.getHeightOfChar(h,O),G=this.getValueOfPropertyAt(h,O,"deltaY");if(n&&p&&m)t.save(),t.fillStyle=S,t.translate(I.renderLeft,I.renderTop),t.rotate(I.angle),t.fillRect(-I.kernedWidth/2,a*j+G,I.kernedWidth,this.fontSize/15),t.restore();else if((p!==x||m!==S||j!==k||G!==P)&&b>0){let L=i+f+_;this.direction==="rtl"&&(L=this.width-L-b),x&&S&&(t.fillStyle=S,t.fillRect(L,A+a*k+P,b,this.fontSize/15)),_=I.left,b=I.width,x=p,S=m,k=j,P=G}else b+=I.kernedWidth}let M=i+f+_;this.direction==="rtl"&&(M=this.width-M-b),t.fillStyle=m,p&&m&&t.fillRect(M,A+a*k+P,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(",")||Se.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 Wc(t)}_splitTextIntoLines(t){const e=t.split(this._reNewline),s=new Array(e.length),i=[`
|
|
83
|
-
`];let n=[];for(let r=0;r<e.length;r++)s[r]=this.graphemeSplit(e[r]),n=n.concat(s[r],i);return n.pop(),{_unwrappedLines:s,lines:e,graphemeText:n,graphemeLines:s}}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return E(E({},super.toObject([...
|
|
84
|
-
`]}_getSVGTextAndBg(o,t){const e=[],s=[];let i,n=o;this.backgroundColor&&s.push(...Tg(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(Ew)),n=i?'style="'.concat(i,'"'):"",r=t.deltaY,a=r?' dy="'.concat(Dt(r,dt.NUM_FRACTION_DIGITS),'" '):"";return'<tspan x="'.concat(Dt(e,dt.NUM_FRACTION_DIGITS),'" y="').concat(Dt(s,dt.NUM_FRACTION_DIGITS),'" ').concat(a).concat(n,">").concat(Bm(o),"</tspan>")}_setSVGTextLineText(o,t,e,s){const i=this.getHeightOfLine(t),n=this.textAlign.includes(ui),r=this._textLines[t];let a,h,l,u,d,g="",f=0;s+=i*(1-this._fontSizeFraction)/this.lineHeight;for(let p=0,m=r.length-1;p<=m;p++)d=p===m||this.charSpacing,g+=r[p],l=this.__charBounds[t][p],f===0?(e+=l.kernedWidth-l.width,f+=l.width):f+=l.kernedWidth,n&&!d&&this._reSpaceAndTab.test(r[p])&&(d=!0),d||(a=a||this.getCompleteStyleDeclaration(t,p),h=this.getCompleteStyleDeclaration(t,p+1),d=Xc(a,h,!0)),d&&(u=this._getStyleDeclaration(t,p),o.push(this._createTextCharSpan(g,u,e,s)),g="",a=h,this.direction==="rtl"?e-=f:e+=f,f=0)}_setSVGTextLineBg(o,t,e,s){const i=this._textLines[t],n=this.getHeightOfLine(t)/this.lineHeight;let r,a=0,h=0,l=this.getValueOfPropertyAt(t,0,"textBackgroundColor");for(let u=0;u<i.length;u++){const{left:d,width:g,kernedWidth:f}=this.__charBounds[t][u];r=this.getValueOfPropertyAt(t,u,"textBackgroundColor"),r!==l?(l&&o.push(...Tg(l,e+h,s,a,n)),h=d,a=g,l=r):a+=f}r&&o.push(...Tg(l,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:l}=o,u=this.getSvgTextDecoration(o);return[i?yh(Le,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?yh($t,n):"",l?"baseline-shift: ".concat(-l,"; "):"",t?"white-space: pre; ":""].join("")}getSvgTextDecoration(o){return["overline","underline","line-through"].filter(t=>o[t.replace("-","")]).join(" ")}}]),V.setClass(Se),V.setSVGClass(Se);class Ow{constructor(t){T(this,"target",void 0),T(this,"__mouseDownInPlace",!1),T(this,"__dragStartFired",!1),T(this,"__isDraggingOver",!1),T(this,"__dragStartSelection",void 0),T(this,"__dragImageDisposer",void 0),T(this,"_dispose",void 0),this.target=t;const e=[this.target.on("dragenter",this.dragEnterHandler.bind(this)),this.target.on("dragover",this.dragOverHandler.bind(this)),this.target.on("dragleave",this.dragLeaveHandler.bind(this)),this.target.on("dragend",this.dragEndHandler.bind(this)),this.target.on("drop",this.dropHandler.bind(this))];this._dispose=()=>{e.forEach(s=>s()),this._dispose=void 0}}isPointerOverSelection(t){const e=this.target,s=e.getSelectionStartFromPointer(t);return e.isEditing&&s>=e.selectionStart&&s<=e.selectionEnd&&e.selectionStart<e.selectionEnd}start(t){return this.__mouseDownInPlace=this.isPointerOverSelection(t)}isActive(){return this.__mouseDownInPlace}end(t){const e=this.isActive();return e&&!this.__dragStartFired&&(this.target.setCursorByClick(t),this.target.initDelayedCursor(!0)),this.__mouseDownInPlace=!1,this.__dragStartFired=!1,this.__isDraggingOver=!1,e}getDragStartSelection(){return this.__dragStartSelection}setDragImage(t,e){var s;let{selectionStart:i,selectionEnd:n}=e;const r=this.target,a=r.canvas,h=new D(r.flipX?-1:1,r.flipY?-1:1),l=r._getCursorBoundaries(i),u=new D(l.left+l.leftOffset,l.top+l.topOffset).multiply(h).transform(r.calcTransformMatrix()),d=a.getScenePoint(t).subtract(u),g=r.getCanvasRetinaScaling(),f=r.getBoundingRect(),p=u.subtract(new D(f.left,f.top)),m=a.viewportTransform,_=p.add(d).transform(m,!0),b=r.backgroundColor,x=pg(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,qc(A,{position:"fixed",left:"".concat(-A.width,"px"),border:Re,width:"".concat(A.width/g,"px"),height:"".concat(A.height/g,"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=E({text:e.text,value:n},i);t.dataTransfer.setData("text/plain",n),t.dataTransfer.setData("application/fabric",JSON.stringify({value:n,styles:e.getSelectionStyles(i.selectionStart,i.selectionEnd,!0)})),t.dataTransfer.effectAllowed="copyMove",this.setDragImage(t,r)}return e.abortCursorAnimation(),s}canDrop(t){if(this.target.editable&&!this.target.getActiveControl()&&!t.defaultPrevented){if(this.isActive()&&this.__dragStartSelection){const e=this.target.getSelectionStartFromPointer(t),s=this.__dragStartSelection;return e<s.selectionStart||e>s.selectionEnd}return!0}return!1}targetCanDrop(t){return this.target.canDrop(t)}dragEnterHandler(t){let{e}=t;const s=this.targetCanDrop(e);!this.__isDraggingOver&&s&&(this.__isDraggingOver=!0)}dragOverHandler(t){const{e}=t,s=this.targetCanDrop(e);!this.__isDraggingOver&&s?this.__isDraggingOver=!0:this.__isDraggingOver&&!s&&(this.__isDraggingOver=!1),this.__isDraggingOver&&(e.preventDefault(),t.canDrop=!0,t.dropTarget=this.target)}dragLeaveHandler(){(this.__isDraggingOver||this.isActive())&&(this.__isDraggingOver=!1)}dropHandler(t){var e;const{e:s}=t,i=s.defaultPrevented;this.__isDraggingOver=!1,s.preventDefault();let n=(e=s.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain");if(n&&!i){const r=this.target,a=r.canvas;let h=r.getSelectionStartFromPointer(s);const{styles:l}=s.dataTransfer.types.includes("application/fabric")?JSON.parse(s.dataTransfer.getData("application/fabric")):{},u=n[Math.max(0,n.length-1)],d=0;if(this.__dragStartSelection){const g=this.__dragStartSelection.selectionStart,f=this.__dragStartSelection.selectionEnd;h>g&&h<=f?h=g:h>f&&(h-=f-g),r.removeChars(g,f),delete this.__dragStartSelection}r._reNewline.test(u)&&(r._reNewline.test(r._text[h])||h===r._text.length)&&(n=n.trimEnd()),t.didDrop=!0,t.dropTarget=r,r.insertChars(n,l,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(xc,{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)||Re;h===Re?(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(xc,{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 T0=/[ \n\.,;!\?\-]/;class Pw extends Se{constructor(){super(...arguments),T(this,"_currentCursorOpacity",1)}initBehavior(){this._tick=this._tick.bind(this),this._onTickComplete=this._onTickComplete.bind(this),this.updateSelectionOnMouseMove=this.updateSelectionOnMouseMove.bind(this)}onDeselect(t){return this.isEditing&&this.exitEditing(),this.selected=!1,super.onDeselect(t)}_animateCursor(t){let{toValue:e,duration:s,delay:i,onComplete:n}=t;return dg({startValue:this._currentCursorOpacity,endValue:e,duration:s,delay:i,onComplete:n,abort:()=>!this.canvas||this.selectionStart!==this.selectionEnd,onChange:r=>{this._currentCursorOpacity=r,this.renderCursorOrSelection()}})}_tick(t){this._currentTickState=this._animateCursor({toValue:0,duration:this.cursorDuration/2,delay:Math.max(t||0,100),onComplete:this._onTickComplete})}_onTickComplete(){var t;(t=this._currentTickCompleteState)===null||t===void 0||t.abort(),this._currentTickCompleteState=this._animateCursor({toValue:1,duration:this.cursorDuration,onComplete:this._tick})}initDelayedCursor(t){this.abortCursorAnimation(),this._tick(t?0:this.cursorDelay)}abortCursorAnimation(){let t=!1;[this._currentTickState,this._currentTickCompleteState].forEach(e=>{e&&!e.isDone()&&(t=!0,e.abort())}),this._currentCursorOpacity=1,t&&this.clearContextTop()}restartCursorIfNeeded(){[this._currentTickState,this._currentTickCompleteState].some(t=>!t||t.isDone())&&this.initDelayedCursor()}selectAll(){return this.selectionStart=0,this.selectionEnd=this._text.length,this._fireSelectionChanged(),this._updateTextarea(),this}getSelectedText(){return this._text.slice(this.selectionStart,this.selectionEnd).join("")}findWordBoundaryLeft(t){let e=0,s=t-1;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s--;for(;/\S/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findWordBoundaryRight(t){let e=0,s=t;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s++;for(;/\S/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}findLineBoundaryLeft(t){let e=0,s=t-1;for(;!/\n/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findLineBoundaryRight(t){let e=0,s=t;for(;!/\n/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}searchWordBoundary(t,e){const s=this._text;let i=t>0&&this._reSpace.test(s[t])&&(e===-1||!Wd.test(s[t-1]))?t-1:t,n=s[i];for(;i>0&&i<s.length&&!T0.test(n);)i+=e,n=s[i];return e===-1&&T0.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(),l=this.canvas.upperCanvasEl,u=l.width/h,d=l.height/h,g=u-r,f=d-r,p=new D(e.left+a,e.top+e.topOffset+r).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new D(l.clientWidth/u,l.clientHeight/d));return p.x<0&&(p.x=0),p.x>g&&(p.x=g),p.y<0&&(p.y=0),p.y>f&&(p.y=f),p.x+=this.canvas._offset.left,p.y+=this.canvas._offset.top,{left:"".concat(p.x,"px"),top:"".concat(p.y,"px"),fontSize:"".concat(r,"px"),charHeight:r}}_saveEditingProps(){this._savedProps={hasControls:this.hasControls,borderColor:this.borderColor,lockMovementX:this.lockMovementX,lockMovementY:this.lockMovementY,hoverCursor:this.hoverCursor,selectable:this.selectable,defaultCursor:this.canvas&&this.canvas.defaultCursor,moveCursor:this.canvas&&this.canvas.moveCursor}}_restoreEditingProps(){this._savedProps&&(this.hoverCursor=this._savedProps.hoverCursor,this.hasControls=this._savedProps.hasControls,this.borderColor=this._savedProps.borderColor,this.selectable=this._savedProps.selectable,this.lockMovementX=this._savedProps.lockMovementX,this.lockMovementY=this._savedProps.lockMovementY,this.canvas&&(this.canvas.defaultCursor=this._savedProps.defaultCursor||this.canvas.defaultCursor,this.canvas.moveCursor=this._savedProps.moveCursor||this.canvas.moveCursor),delete this._savedProps)}_exitEditing(){const t=this.hiddenTextarea;this.selected=!1,this.isEditing=!1,t&&(t.blur&&t.blur(),t.parentNode&&t.parentNode.removeChild(t)),this.hiddenTextarea=null,this.abortCursorAnimation(),this.selectionStart!==this.selectionEnd&&this.clearContextTop()}exitEditingImpl(){this._exitEditing(),this.selectionEnd=this.selectionStart,this._restoreEditingProps(),this._forceClearCache&&(this.initDimensions(),this.setCoords())}exitEditing(){const t=this._textBeforeEdit!==this.text;return this.exitEditingImpl(),this.fire("editing:exited"),t&&this.fire(Cc),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 l=i;l<r;l++)delete a[l];for(const l in this.styles[s]){const u=parseInt(l,10);u>=r&&(a[u-h]=a[l],delete a[l])}}}shiftLineStyles(t,e){const s=Object.assign({},this.styles);for(const i in this.styles){const n=parseInt(i,10);n>t&&(this.styles[n+e]=s[n],s[n-e]||delete this.styles[n])}}insertNewlineStyleObject(t,e,s,i){const n={},r=this._unwrappedTextLines[t].length,a=r===e;let h=!1;s||(s=1),this.shiftLineStyles(t,s);const l=this.styles[t]?this.styles[t][e===0?e:e-1]:void 0;for(const d in this.styles[t]){const g=parseInt(d,10);g>=e&&(h=!0,n[g-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:E({},i[s-1])}:l?this.styles[t+s]={0:E({},l)}:delete this.styles[t+s],s--;this._forceClearCache=!0}insertCharStyleObject(t,e,s,i){this.styles||(this.styles={});const n=this.styles[t],r=n?E({},n):{};s||(s=1);for(const h in r){const l=parseInt(h,10);l>=e&&(n[l+s]=r[l],r[l-s]||delete n[l])}if(this._forceClearCache=!0,i){for(;s--;)Object.keys(i[s]).length&&(this.styles[t]||(this.styles[t]={}),this.styles[t][e+s]=E({},i[s]));return}if(!n)return;const a=n[e?e-1:1];for(;a&&s--;)this.styles[t][e+s]=E({},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=mt:this._selectionDirection===Vt&&(this._selectionDirection=mt,this.selectionEnd=t),this.selectionStart=s):s>t&&s<e?this._selectionDirection===Vt?this.selectionEnd=s:this.selectionStart=s:(e===t?this._selectionDirection=Vt:this._selectionDirection===mt&&(this._selectionDirection=Vt,this.selectionStart=e),this.selectionEnd=s)}}class Dw extends Pw{initHiddenTextarea(){const t=this.canvas&&js(this.canvas.getElement())||ja(),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(xc),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,l=a!==h;let u,d,g,f,p=r-n;const m=this.fromStringToGraphemeSelection(this.hiddenTextarea.selectionStart,this.hiddenTextarea.selectionEnd,this.hiddenTextarea.value),_=a>m.selectionStart;l?(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(m.selectionEnd-p,m.selectionEnd);if(d&&d.length&&(b.length&&(u=this.getSelectionStyles(a,a+1,!1),u=b.map(()=>u[0])),l?(g=a,f=h):_?(g=h-d.length,f=h):(g=h,f=h+d.length),this.removeStyleFromTo(g,f)),b.length){const{copyPasteData:x}=oi();e&&b.join("")===x.copiedText&&!dt.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}=oi();t.copiedText=this.getSelectedText(),dt.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),l=this._textLines[n].slice(0,r),u=this.missingNewlineOffset(n-1);return-this._textLines[n-1].length+h-l.length+(1-u)}_getIndexOnLine(t,e){const s=this._textLines[t];let i,n,r=this._getLineLeftOffset(t),a=0;for(let h=0,l=s.length;h<l;h++)if(i=this.__charBounds[t][h].width,r+=i,r>e){n=!0;const u=r-i,d=r,g=Math.abs(u-e);a=Math.abs(d-e)<g?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===Vt);if(e.shiftKey?this.moveCursorWithShift(s):this.moveCursorWithoutShift(s),s!==0){const i=this.text.length;this.selectionStart=yr(0,this.selectionStart,i),this.selectionEnd=yr(0,this.selectionEnd,i),this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea()}}moveCursorWithShift(t){const e=this._selectionDirection===mt?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=mt,this.selectionEnd===this.selectionStart&&this.selectionStart!==0&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return this._selectionDirection===Vt&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):this.selectionStart!==0?(this._selectionDirection=mt,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===mt&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection=Vt,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=Vt,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}const kg=o=>!!o.button;class Rw extends Dw{constructor(){super(...arguments),T(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 Ow(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),Qd(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&&!kg(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&&!kg(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||kg(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(qe(this.calcTransformMatrix())).add(new D(-this._getLeftOffset(),-this._getTopOffset()));let s=0,i=0,n=0;for(let l=0;l<this._textLines.length&&s<=e.y;l++)s+=this.getHeightOfLine(l),n=l,l>0&&(i+=this._textLines[l-1].length+this.missingNewlineOffset(l-1));let r=Math.abs(this._getLineLeftOffset(n));const a=this._textLines[n].length,h=this.__charBounds[n];for(let l=0;l<a;l++){const u=r+h[l].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 Zc="moveCursorUp",tu="moveCursorDown",eu="moveCursorLeft",su="moveCursorRight",iu="exitEditing",Fw=E({selectionStart:0,selectionEnd:0,selectionColor:"rgba(17,119,255,0.3)",isEditing:!1,editable:!0,editingBorderColor:"rgba(102,153,255,0.25)",cursorWidth:2,cursorColor:"",cursorDelay:1e3,cursorDuration:600,caching:!0,hiddenTextareaContainer:null,keysMap:{9:iu,27:iu,33:Zc,34:tu,35:su,36:eu,37:eu,38:Zc,39:su,40:tu},keysMapRtl:{9:iu,27:iu,33:Zc,34:tu,35:eu,36:su,37:su,38:Zc,39:eu,40:tu},ctrlKeysMapDown:{65:"selectAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}},{_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1});class Hi extends Rw{static getDefaults(){return E(E({},super.getDefaults()),Hi.ownDefaults)}get type(){const t=super.type;return t==="itext"?"i-text":t}constructor(t,e){super(t,E(E({},Hi.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 Sg&&this.canvas.textEditingManager.remove(this),e instanceof Sg&&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 l=0;l<n;l++)e+=this.getHeightOfLine(l);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===Vt||this.textAlign===ui||this.textAlign===Eh?h.left*=-1:this.textAlign===mt||this.textAlign===Qc?h.left=r-(s>0?s:0):this.textAlign!==st&&this.textAlign!==kh||(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,l=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+l,width:h,height:r}}_renderCursor(t,e,s){const{color:i,opacity:n,left:r,top:a,width:h,height:l}=this.getCursorRenderingData(s,e);t.fillStyle=i,t.globalAlpha=n,t.fillRect(r,a,h,l)}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(ui),a=this.get2DCursorLocation(i),h=this.get2DCursorLocation(n),l=a.lineIndex,u=h.lineIndex,d=a.charIndex<0?0:a.charIndex,g=h.charIndex<0?0:h.charIndex;for(let f=l;f<=u;f++){const p=this._getLineLeftOffset(f)||0;let m=this.getHeightOfLine(f),_=0,b=0,x=0;if(f===l&&(b=this.__charBounds[l][d].left),f>=l&&f<u)x=r&&!this.isEndOfWrapping(f)?this.width:this.getLineWidth(f)||5;else if(f===u)if(g===0)x=this.__charBounds[u][g].left;else{const M=this._getWidthOfCharSpacing();x=this.__charBounds[u][g-1].left+this.__charBounds[u][g-1].width-M}_=m,(this.lineHeight<1||f===u&&this.lineHeight>1)&&(m/=this.lineHeight);let S=s.left+p+b,A=m,k=0;const P=x-b;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",A=1,k=m):t.fillStyle=this.selectionColor,this.direction==="rtl"&&(this.textAlign===Vt||this.textAlign===ui||this.textAlign===Eh?S=this.width-S-P:this.textAlign===mt||this.textAlign===Qc?S=s.left+p-x:this.textAlign!==st&&this.textAlign!==kh||(S=s.left+p-x)),t.fillRect(S,s.top+s.topOffset+k,P,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,$t)}_getCurrentCharIndex(){const t=this.get2DCursorLocation(this.selectionStart,!0),e=t.charIndex>0?t.charIndex-1:0;return{l:t.lineIndex,c:e}}dispose(){this.exitEditingImpl(),this.draggableTextDelegate.dispose(),super.dispose()}}T(Hi,"ownDefaults",Fw),T(Hi,"type","IText"),V.setClass(Hi),V.setClass(Hi,"i-text");class Sr extends Hi{static getDefaults(){return E(E({},super.getDefaults()),Sr.ownDefaults)}constructor(t,e){super(t,E(E({},Sr.ownDefaults),e))}static createControls(){return{controls:b_()}}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(ui)&&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 l in h)for(const u in h[l]){const d=parseInt(u,10);if(d>=s&&(!n||d<e))for(const g in h[l][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(l=>{const u=e?[l]:this.graphemeSplit(l),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,l=[],u=h?"":" ";let d=0,g=[],f=0,p=0,m=!0;e-=r;const _=Math.max(e,i,this.dynamicMinWidth),b=n[t];let x;for(f=0,x=0;x<b.length;x++){const{word:S,width:A}=b[x];f+=S.length,d+=p+A-a,d>_&&!m?(l.push(g),g=[],d=A,m=!0):d+=a,m||h||g.push(u),g=g.concat(S),p=h?0:this._measureWord([u],t,f),f++,m=!1}return x&&l.push(g),i+r>this.dynamicMinWidth&&(this.dynamicMinWidth=i-a+r),l}isEndOfWrapping(t){return!this._styleMap[t+1]||this._styleMap[t+1].line!==this._styleMap[t].line}missingNewlineOffset(t,e){return this.splitByGrapheme&&!e?this.isEndOfWrapping(t)?1:0:1}_splitTextIntoLines(t){const e=super._splitTextIntoLines(t),s=this._wrapText(e.lines,this.width),i=new Array(s.length);for(let n=0;n<s.length;n++)i[n]=s[n].join("");return e.lines=i,e.graphemeLines=s,e}getMinWidth(){return Math.max(this.minWidth,this.dynamicMinWidth)}_removeExtraneousStyles(){const t=new Map;for(const e in this._styleMap){const s=parseInt(e,10);if(this._textLines[s]){const i=this._styleMap[e].line;t.set("".concat(i),!0)}}for(const e in this.styles)t.has(e)||delete this.styles[e]}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject(["minWidth","splitByGrapheme",...t])}}T(Sr,"type","Textbox"),T(Sr,"textLayoutProperties",[...Hi.textLayoutProperties,"width"]),T(Sr,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),V.setClass(Sr);class E0 extends Yc{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}=hi(Jm(s,i)),h=new D(r,a);if(i.absolutePositioned)return{center:br(i.getRelativeCenterPoint(),void 0,n?n.calcTransformMatrix():void 0),size:h};{const l=i.getRelativeCenterPoint().transform(s.calcOwnMatrix(),!0);if(this.shouldPerformLayout(t)){const{center:u=new D,correction:d=new D}=this.calcBoundingBox(e,t)||{};return{center:u.add(l),correction:d.subtract(l),size:h}}return{center:s.getRelativeCenterPoint().add(l),size:h}}}}T(E0,"type","clip-path"),V.setClass(E0);class k0 extends Yc{getInitialSize(t,e){let{target:s}=t,{size:i}=e;return new D(s.width||i.x,s.height||i.y)}}T(k0,"type","fixed"),V.setClass(k0);class Lw extends Ch{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 Cr extends ci{static getDefaults(){return E(E({},super.getDefaults()),Cr.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,Cr.ownDefaults),this.setOptions(e);const{left:s,top:i,layoutManager:n}=e;this.groupInit(t,{left:s,top:i,layoutManager:n??new Lw})}_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))?(Pi("error","ActiveSelection: circular object trees are not supported, this call has no effect"),!1):super.canEnterGroup(t)}enterGroup(t,e){t.parent&&t.parent===t.group?t.parent._exitGroup(t):t.group&&t.parent!==t.group&&t.group.remove(t),this._enterGroup(t,e)}exitGroup(t,e){this._exitGroup(t,e),t.parent&&t.parent._enterGroup(t,!0)}_onAfterObjectsChange(t,e){super._onAfterObjectsChange(t,e);const s=new Set;e.forEach(i=>{const{parent:n}=i;n&&s.add(n)}),t===bg?s.forEach(i=>{i._onAfterObjectsChange(Vc,e)}):s.forEach(i=>{i._set("dirty",!0)})}onDeselect(){return this.removeAll(),!1}toString(){return"#<ActiveSelection: (".concat(this.complexity(),")>")}shouldCache(){return!1}isOnACache(){return!1}_renderControls(t,e,s){t.save(),t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1;const i=E(E({hasControls:!1},s),{},{forActiveSelection:!0});for(let n=0;n<this._objects.length;n++)this._objects[n]._renderControls(t,i);super._renderControls(t,e),t.restore()}}T(Cr,"type","ActiveSelection"),T(Cr,"ownDefaults",{multiSelectionStacking:"canvas-stacking"}),V.setClass(Cr),V.setClass(Cr,"activeSelection");class Iw{constructor(){T(this,"resources",{})}applyFilters(t,e,s,i,n){const r=n.getContext("2d");if(!r)return;r.drawImage(e,0,0,s,i);const 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(l=>{l.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 M0{constructor(){let{tileSize:t=dt.textureSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};T(this,"aPosition",new Float32Array([0,0,0,1,1,0,1,1])),T(this,"resources",{}),this.tileSize=t,this.setupGLContext(t,t),this.captureGPUInfo()}setupGLContext(t,e){this.dispose(),this.createWebGLCanvas(t,e)}createWebGLCanvas(t,e){const s=Is({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 l;r&&(l=this.getCachedTexture(r,e));const u={originalWidth:e.width||e.originalWidth||0,originalHeight:e.height||e.originalHeight||0,sourceWidth:s,sourceHeight:i,destinationWidth:s,destinationHeight:i,context:a,sourceTexture:this.createTexture(a,s,i,l?void 0:e),targetTexture:this.createTexture(a,s,i),originalTexture:l||this.createTexture(a,s,i,l?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(g=>{g&&g.applyTo(u)}),function(g){const f=g.targetCanvas,p=f.width,m=f.height,_=g.destinationWidth,b=g.destinationHeight;p===_&&m===b||(f.width=_,f.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:l,CLAMP_TO_EDGE:u,TEXTURE_MAG_FILTER:d,TEXTURE_MIN_FILTER:g,TEXTURE_WRAP_S:f,TEXTURE_WRAP_T:p}=t,m=t.createTexture();return t.bindTexture(a,m),t.texParameteri(a,d,n||r),t.texParameteri(a,g,n||r),t.texParameteri(a,f,u),t.texParameteri(a,p,u),i?t.texImage2D(a,0,h,h,l,i):t.texImage2D(a,0,h,e,s,0,h,l,null),m}getCachedTexture(t,e,s){const{textureCache:i}=this;if(i[t])return i[t];{const n=this.createTexture(this.gl,e.width,e.height,e,s);return n&&(i[t]=n),n}}evictCachesForKey(t){this.textureCache[t]&&(this.gl.deleteTexture(this.textureCache[t]),delete this.textureCache[t])}copyGLTo2D(t,e){const s=t.canvas,i=e.targetCanvas,n=i.getContext("2d");if(!n)return;n.translate(0,i.height),n.scale(1,-1);const r=s.height-i.height;n.drawImage(s,0,r,i.width,i.height,0,0,i.width,i.height)}copyGLTo2DPutImageData(t,e){const s=e.targetCanvas.getContext("2d"),i=e.destinationWidth,n=e.destinationHeight,r=i*n*4;if(!s)return;const 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 l=new ImageData(h,i,n);s.putImageData(l,0,0)}captureGPUInfo(){if(this.gpuInfo)return this.gpuInfo;const t=this.gl,e={renderer:"",vendor:""};if(!t)return e;const s=t.getExtension("WEBGL_debug_renderer_info");if(s){const i=t.getParameter(s.UNMASKED_RENDERER_WEBGL),n=t.getParameter(s.UNMASKED_VENDOR_WEBGL);i&&(e.renderer=i.toLowerCase()),n&&(e.vendor=n.toLowerCase())}return this.gpuInfo=e,e}}let Mg;function jw(){const{WebGLProbe:o}=oi();return o.queryWebGL(vs()),dt.enableGLFiltering&&o.isSupported(dt.textureSize)?new M0({tileSize:dt.textureSize}):new Iw}function Og(){return!Mg&&(!(arguments.length>0&&arguments[0]!==void 0)||arguments[0])&&(Mg=jw()),Mg}const Nw=["filters","resizeFilter","src","crossOrigin","type"],O0=["cropX","cropY"];class Ce extends xe{static getDefaults(){return E(E({},super.getDefaults()),Ce.ownDefaults)}constructor(t,e){super(),T(this,"_lastScaleX",1),T(this,"_lastScaleY",1),T(this,"_filterScalingX",1),T(this,"_filterScalingY",1),this.filters=[],Object.assign(this,Ce.ownDefaults),this.setOptions(e),this.cacheKey="texture".concat(En()),this.setElement(typeof t=="string"?(this.canvas&&js(this.canvas.getElement())||ja()).getElementById(t):t,e)}getElement(){return this._element}setElement(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._element=t,this._originalElement=t,this._setWidthHeight(e),t.classList.add(Ce.CSS_CANVAS),this.filters.length!==0&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){const e=Og(!1);e instanceof M0&&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&&oi().dispose(e),this[t]=void 0})}getCrossOrigin(){return this._originalElement&&(this._originalElement.crossOrigin||null)}getOriginalSize(){const t=this.getElement();return t?{width:t.naturalWidth||t.width,height:t.naturalHeight||t.height}:{width:0,height:0}}_stroke(t){if(!this.stroke||this.strokeWidth===0)return;const e=this.width/2,s=this.height/2;t.beginPath(),t.moveTo(-e,-s),t.lineTo(e,-s),t.lineTo(e,s),t.lineTo(-e,s),t.lineTo(-e,-s),t.closePath()}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=[];return this.filters.forEach(s=>{s&&e.push(s.toObject())}),E(E({},super.toObject([...O0,...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 l=En();n.push('<clipPath id="imageCrop_'+l+`">
|
|
74
|
+
`),s.join("")}toLive(t){const{x1:e,y1:s,x2:i,y2:n,r1:r,r2:o}=this.coords,h=this.type==="linear"?t.createLinearGradient(e,s,i,n):t.createRadialGradient(e,s,r,i,n,o);return this.colorStops.forEach(c=>{let{color:u,opacity:d,offset:g}=c;h.addColorStop(g,d!==void 0?new _t(u).setAlpha(d).toRgba():u)}),h}static async fromObject(t){const{colorStops:e,gradientTransform:s}=t;return new this(E(E({},t),{},{colorStops:e?e.map(i=>E({},i)):void 0,gradientTransform:s?[...s]:void 0}))}static fromElement(t,e,s){const i=M0(t),n=e._findCenterFromElement();return new this(E({id:t.getAttribute("id")||void 0,type:k0(t),coords:bw(t,{width:s.viewBoxWidth||s.width,height:s.viewBoxHeight||s.height}),colorStops:vw(t,s.opacity),gradientUnits:i,gradientTransform:ru(t.getAttribute("gradientTransform")||"")},i==="pixels"?{offsetX:e.width/2-n.x,offsetY:e.height/2-n.y}:{offsetX:0,offsetY:0}))}}T(Bh,"type","Gradient"),W.setClass(Bh,"gradient"),W.setClass(Bh,"linear"),W.setClass(Bh,"radial");const yw=["type","source","patternTransform"];class Hg{get type(){return"pattern"}set type(t){Xi("warn","Setting type has no effect",t)}constructor(t){T(this,"repeat","repeat"),T(this,"offsetX",0),T(this,"offsetY",0),T(this,"crossOrigin",""),this.id=Bn(),Object.assign(this,t)}isImageSource(){return!!this.source&&typeof this.source.src=="string"}isCanvasSource(){return!!this.source&&!!this.source.toDataURL}sourceToString(){return this.isImageSource()?this.source.src:this.isCanvasSource()?this.source.toDataURL():""}toLive(t){return this.source&&(!this.isImageSource()||this.source.complete&&this.source.naturalWidth!==0&&this.source.naturalHeight!==0)?t.createPattern(this.source,this.repeat):null}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const{repeat:e,crossOrigin:s}=this;return E(E({},Er(this,t)),{},{type:"pattern",source:this.sourceToString(),repeat:e,crossOrigin:s,offsetX:Dt(this.offsetX,dt.NUM_FRACTION_DIGITS),offsetY:Dt(this.offsetY,dt.NUM_FRACTION_DIGITS),patternTransform:this.patternTransform?[...this.patternTransform]:null})}toSVG(t){let{width:e,height:s}=t;const{source:i,repeat:n,id:r}=this,o=ra(this.offsetX/e,0),h=ra(this.offsetY/s,0),c=n==="repeat-y"||n==="no-repeat"?1+Math.abs(o||0):ra(i.width/e,0),u=n==="repeat-x"||n==="no-repeat"?1+Math.abs(h||0):ra(i.height/s,0);return['<pattern id="SVGID_'.concat(r,'" x="').concat(o,'" y="').concat(h,'" width="').concat(c,'" height="').concat(u,'">'),'<image x="0" y="0" width="'.concat(i.width,'" height="').concat(i.height,'" xlink:href="').concat(this.sourceToString(),'"></image>'),"</pattern>",""].join(`
|
|
75
|
+
`)}static async fromObject(t,e){let{type:s,source:i,patternTransform:n}=t,r=Ot(t,yw);const o=await Mh(i,E(E({},e),{},{crossOrigin:r.crossOrigin}));return new this(E(E({},r),{},{patternTransform:n&&n.slice(0),source:o}))}}T(Hg,"type","Pattern"),W.setClass(Hg),W.setClass(Hg,"pattern");const _w=["path","left","top"],ww=["d"];class Or extends Ce{constructor(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{path:s,left:i,top:n}=e,r=Ot(e,_w);super(),Object.assign(this,Or.ownDefaults),this.setOptions(r),this._setPath(t||[],!0),typeof i=="number"&&this.set(vt,i),typeof n=="number"&&this.set(Je,n)}_setPath(t,e){this.path=f0(Array.isArray(t)?t:x0(t)),this.setBoundingBox(e)}_findCenterFromElement(){const t=this._calcBoundsFromPath();return new O(t.left+t.width/2,t.top+t.height/2)}_renderPathCommands(t){const e=-this.pathOffset.x,s=-this.pathOffset.y;t.beginPath();for(const i of this.path)switch(i[0]){case"L":t.lineTo(i[1]+e,i[2]+s);break;case"M":t.moveTo(i[1]+e,i[2]+s);break;case"C":t.bezierCurveTo(i[1]+e,i[2]+s,i[3]+e,i[4]+s,i[5]+e,i[6]+s);break;case"Q":t.quadraticCurveTo(i[1]+e,i[2]+s,i[3]+e,i[4]+s);break;case"Z":t.closePath()}}_render(t){this._renderPathCommands(t),this._renderPaintInOrder(t)}toString(){return"#<Path (".concat(this.complexity(),'): { "top": ').concat(this.top,', "left": ').concat(this.left," }>")}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return E(E({},super.toObject(t)),{},{path:this.path.map(e=>e.slice())})}toDatalessObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=this.toObject(t);return this.sourcePath&&(delete e.path,e.sourcePath=this.sourcePath),e}_toSVG(){const t=S0(this.path,dt.NUM_FRACTION_DIGITS);return["<path ","COMMON_PARTS",'d="'.concat(t,`" stroke-linecap="round" />
|
|
76
|
+
`)]}_getOffsetTransform(){const t=dt.NUM_FRACTION_DIGITS;return" translate(".concat(Dt(-this.pathOffset.x,t),", ").concat(Dt(-this.pathOffset.y,t),")")}toClipPathSVG(t){const e=this._getOffsetTransform();return" "+this._createBaseClipPathSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}toSVG(t){const e=this._getOffsetTransform();return this._createBaseSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}complexity(){return this.path.length}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{width:e,height:s,pathOffset:i}=this._calcDimensions();this.set({width:e,height:s,pathOffset:i}),t&&this.setPositionByOrigin(i,tt,tt)}_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(...jg(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(...jg(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 bi(t)}_calcDimensions(){const t=this._calcBoundsFromPath();return E(E({},t),{},{pathOffset:new O(t.left+t.width/2,t.top+t.height/2)})}static fromObject(t){return this._fromObject(t,{extraParam:"path"})}static async fromElement(t,e,s){const i=Ki(t,this.ATTRIBUTE_NAMES,s),{d:n}=i;return new this(n,E(E(E({},Ot(i,ww)),e),{},{left:void 0,top:void 0}))}}T(Or,"type","Path"),T(Or,"cacheProperties",[...$i,"path","fillRule"]),T(Or,"ATTRIBUTE_NAMES",[...Vn,"d"]),W.setClass(Or),W.setSVGClass(Or);const xw=["left","top","radius"],P0=["radius","startAngle","endAngle","counterClockwise"];class Ji extends Ce{static getDefaults(){return E(E({},super.getDefaults()),Ji.ownDefaults)}constructor(t){super(),Object.assign(this,Ji.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,zt(this.startAngle),zt(this.endAngle),this.counterClockwise),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get(je)}getRadiusY(){return this.get("radius")*this.get(hs)}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([...P0,...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=zt(this.startAngle),i=zt(this.endAngle),n=Ws(s)*e,r=zs(s)*e,o=Ws(i)*e,h=zs(i)*e,c=t>180?1:0,u=this.counterClockwise?0:1;return['<path d="M '.concat(n," ").concat(r," A ").concat(e," ").concat(e," 0 ").concat(c," ").concat(u," ").concat(o," ").concat(h,'" '),"COMMON_PARTS",` />
|
|
78
|
+
`]}}static async fromElement(t,e,s){const i=Ki(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,radius:o=0}=i;return new this(E(E({},Ot(i,xw)),{},{radius:o,left:n-o,top:r-o}))}static fromObject(t){return super._fromObject(t)}}T(Ji,"type","Circle"),T(Ji,"cacheProperties",[...$i,...P0]),T(Ji,"ownDefaults",{radius:0,startAngle:0,endAngle:360,counterClockwise:!1}),T(Ji,"ATTRIBUTE_NAMES",["cx","cy","r",...Vn]),W.setClass(Ji),W.setSVGClass(Ji);const Sw=["x1","y1","x2","y2"],Cw=["x1","y1","x2","y2"],Vg=["x1","x2","y1","y2"];class Dr extends Ce{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,Dr.ownDefaults),this.setOptions(n),this.x1=t,this.x2=s,this.y1=e,this.y2=i,this._setWidthHeight();const{left:r,top:o}=n;typeof r=="number"&&this.set(vt,r),typeof o=="number"&&this.set(Je,o)}_setWidthHeight(){const{x1:t,y1:e,x2:s,y2:i}=this;this.width=Math.abs(s-t),this.height=Math.abs(i-e);const{left:n,top:r,width:o,height:h}=bi([{x:t,y:e},{x:s,y:i}]),c=new O(n+o/2,r+h/2);this.setPositionByOrigin(c,tt,tt)}_set(t,e){return super._set(t,e),Vg.includes(t)&&this._setWidthHeight(),this}_render(t){t.beginPath();const e=this.calcLinePoints();t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2),t.lineWidth=this.strokeWidth;const s=t.strokeStyle;var i;Ts(this.stroke)?t.strokeStyle=this.stroke.toLive(t):t.strokeStyle=(i=this.stroke)!==null&&i!==void 0?i:t.fillStyle,this.stroke&&this._renderStroke(t),t.strokeStyle=s}_findCenterFromElement(){return new O((this.x1+this.x2)/2,(this.y1+this.y2)/2)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return E(E({},super.toObject(t)),this.calcLinePoints())}_getNonTransformedDimensions(){const t=super._getNonTransformedDimensions();return this.strokeLineCap==="butt"&&(this.width===0&&(t.y-=this.strokeWidth),this.height===0&&(t.x-=this.strokeWidth)),t}calcLinePoints(){const{x1:t,x2:e,y1:s,y2:i,width:n,height:r}=this,o=t<=e?-1:1,h=s<=i?-1:1;return{x1:o*n/2,x2:o*-n/2,y1:h*r/2,y2:h*-r/2}}_toSVG(){const{x1:t,x2:e,y1:s,y2:i}=this.calcLinePoints();return["<line ","COMMON_PARTS",'x1="'.concat(t,'" y1="').concat(s,'" x2="').concat(e,'" y2="').concat(i,`" />
|
|
79
|
+
`)]}static async fromElement(t,e,s){const i=Ki(t,this.ATTRIBUTE_NAMES,s),{x1:n=0,y1:r=0,x2:o=0,y2:h=0}=i;return new this([n,r,o,h],Ot(i,Sw))}static fromObject(t){let{x1:e,y1:s,x2:i,y2:n}=t,r=Ot(t,Cw);return this._fromObject(E(E({},r),{},{points:[e,s,i,n]}),{extraParam:"points"})}}T(Dr,"type","Line"),T(Dr,"cacheProperties",[...$i,...Vg]),T(Dr,"ATTRIBUTE_NAMES",Vn.concat(Vg)),W.setClass(Dr),W.setSVGClass(Dr);class Rr extends Ce{static getDefaults(){return E(E({},super.getDefaults()),Rr.ownDefaults)}constructor(t){super(),Object.assign(this,Rr.ownDefaults),this.setOptions(t)}_render(t){const e=this.width/2,s=this.height/2;t.beginPath(),t.moveTo(-e,s),t.lineTo(0,-s),t.lineTo(e,s),t.closePath(),this._renderPaintInOrder(t)}_toSVG(){const t=this.width/2,e=this.height/2;return["<polygon ","COMMON_PARTS",'points="',"".concat(-t," ").concat(e,",0 ").concat(-e,",").concat(t," ").concat(e),'" />']}}T(Rr,"type","Triangle"),T(Rr,"ownDefaults",{width:100,height:100}),W.setClass(Rr),W.setSVGClass(Rr);const O0=["rx","ry"];class Zi extends Ce{static getDefaults(){return E(E({},super.getDefaults()),Zi.ownDefaults)}constructor(t){super(),Object.assign(this,Zi.ownDefaults),this.setOptions(t)}_set(t,e){switch(super._set(t,e),t){case"rx":this.rx=e,this.set("width",2*e);break;case"ry":this.ry=e,this.set("height",2*e)}return this}getRx(){return this.get("rx")*this.get(je)}getRy(){return this.get("ry")*this.get(hs)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...O0,...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,Ui,!1),t.restore(),this._renderPaintInOrder(t)}static async fromElement(t,e,s){const i=Ki(t,this.ATTRIBUTE_NAMES,s);return i.left=(i.left||0)-i.rx,i.top=(i.top||0)-i.ry,new this(i)}}function Aw(a){if(!a)return[];const t=a.replace(/,/g," ").trim().split(/\s+/),e=[];for(let s=0;s<t.length;s+=2)e.push({x:parseFloat(t[s]),y:parseFloat(t[s+1])});return e}T(Zi,"type","Ellipse"),T(Zi,"cacheProperties",[...$i,...O0]),T(Zi,"ownDefaults",{rx:0,ry:0}),T(Zi,"ATTRIBUTE_NAMES",[...Vn,"cx","cy","rx","ry"]),W.setClass(Zi),W.setSVGClass(Zi);const Tw=["left","top"],D0={exactBoundingBox:!1};class Qs extends Ce{static getDefaults(){return E(E({},super.getDefaults()),Qs.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),T(this,"strokeDiff",void 0),Object.assign(this,Qs.ownDefaults),this.setOptions(e),this.points=t;const{left:s,top:i}=e;this.initialized=!0,this.setBoundingBox(!0),typeof s=="number"&&this.set(vt,s),typeof i=="number"&&this.set(Je,i)}isOpen(){return!0}_projectStrokeOnPoints(t){return Km(this.points,t,this.isOpen())}_calcDimensions(t){t=E({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,strokeLineCap:this.strokeLineCap,strokeLineJoin:this.strokeLineJoin,strokeMiterLimit:this.strokeMiterLimit,strokeUniform:this.strokeUniform,strokeWidth:this.strokeWidth},t||{});const e=this.exactBoundingBox?this._projectStrokeOnPoints(t).map(c=>c.projectedPoint):this.points;if(e.length===0)return{left:0,top:0,width:0,height:0,pathOffset:new O,strokeOffset:new O,strokeDiff:new O};const s=bi(e),i=kh(E(E({},t),{},{scaleX:1,scaleY:1})),n=bi(this.points.map(c=>Se(c,i,!0))),r=new O(this.scaleX,this.scaleY);let o=s.left+s.width/2,h=s.top+s.height/2;return this.exactBoundingBox&&(o-=h*Math.tan(zt(this.skewX)),h-=o*Math.tan(zt(this.skewY))),E(E({},s),{},{pathOffset:new O(o,h),strokeOffset:new O(n.left,n.top).subtract(new O(s.left,s.top)).multiply(r),strokeDiff:new O(s.width,s.height).subtract(new O(n.width,n.height)).multiply(r)})}_findCenterFromElement(){const t=bi(this.points);return new O(t.left+t.width/2,t.top+t.height/2)}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{left:e,top:s,width:i,height:n,pathOffset:r,strokeOffset:o,strokeDiff:h}=this._calcDimensions();this.set({width:i,height:n,pathOffset:r,strokeOffset:o,strokeDiff:h}),t&&this.setPositionByOrigin(new O(e+i/2,s+n/2),tt,tt)}isStrokeAccountedForInDimensions(){return this.exactBoundingBox}_getNonTransformedDimensions(){return this.exactBoundingBox?new O(this.width,this.height):super._getNonTransformedDimensions()}_getTransformedDimensions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(this.exactBoundingBox){let r;if(Object.keys(t).some(o=>this.strokeUniform||this.constructor.layoutProperties.includes(o))){var e,s;const{width:o,height:h}=this._calcDimensions(t);r=new O((e=t.width)!==null&&e!==void 0?e:o,(s=t.height)!==null&&s!==void 0?s:h)}else{var i,n;r=new O((i=t.width)!==null&&i!==void 0?i:this.width,(n=t.height)!==null&&n!==void 0?n:this.height)}return r.multiply(new O(t.scaleX||this.scaleX,t.scaleY||this.scaleY))}return super._getTransformedDimensions(t)}_set(t,e){const s=this.initialized&&this[t]!==e,i=super._set(t,e);return this.exactBoundingBox&&s&&((t===je||t===hs)&&this.strokeUniform&&this.constructor.layoutProperties.includes("strokeUniform")||this.constructor.layoutProperties.includes(t))&&this.setDimensions(),i}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return E(E({},super.toObject(t)),{},{points:this.points.map(e=>{let{x:s,y:i}=e;return{x:s,y:i}})})}_toSVG(){const t=[],e=this.pathOffset.x,s=this.pathOffset.y,i=dt.NUM_FRACTION_DIGITS;for(let n=0,r=this.points.length;n<r;n++)t.push(Dt(this.points[n].x-e,i),",",Dt(this.points[n].y-s,i)," ");return["<".concat(this.constructor.type.toLowerCase()," "),"COMMON_PARTS",'points="'.concat(t.join(""),`" />
|
|
81
|
+
`)]}_render(t){const e=this.points.length,s=this.pathOffset.x,i=this.pathOffset.y;if(e&&!isNaN(this.points[e-1].y)){t.beginPath(),t.moveTo(this.points[0].x-s,this.points[0].y-i);for(let n=0;n<e;n++){const r=this.points[n];t.lineTo(r.x-s,r.y-i)}!this.isOpen()&&t.closePath(),this._renderPaintInOrder(t)}}complexity(){return this.points.length}static async fromElement(t,e,s){return new this(Aw(t.getAttribute("points")),E(E({},Ot(Ki(t,this.ATTRIBUTE_NAMES,s),Tw)),e))}static fromObject(t){return this._fromObject(t,{extraParam:"points"})}}T(Qs,"ownDefaults",D0),T(Qs,"type","Polyline"),T(Qs,"layoutProperties",[Uo,Yo,"strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeWidth","strokeUniform","points"]),T(Qs,"cacheProperties",[...$i,"points"]),T(Qs,"ATTRIBUTE_NAMES",[...Vn]),W.setClass(Qs),W.setSVGClass(Qs);class gu extends Qs{isOpen(){return!1}}T(gu,"ownDefaults",D0),T(gu,"type","Polygon"),W.setClass(gu),W.setSVGClass(gu);const R0=["fontSize","fontWeight","fontFamily","fontStyle"],L0=["underline","overline","linethrough"],F0=[...R0,"lineHeight","text","charSpacing","textAlign","styles","path","pathStartOffset","pathSide","pathAlign"],I0=[...F0,...L0,"textBackgroundColor","direction"],Ew=[...R0,...L0,Ne,"strokeWidth",Jt,"deltaY","textBackgroundColor"],kw={_reNewline:ig,_reSpacesAndTabs:/[ \t\r]/g,_reSpaceAndTab:/[ \t\r]/,_reWords:/\S+/g,fontSize:40,fontWeight:"normal",fontFamily:"Times New Roman",underline:!1,overline:!1,linethrough:!1,textAlign:vt,fontStyle:"normal",lineHeight:1.16,superscript:{size:.6,baseline:-.35},subscript:{size:.6,baseline:.11},textBackgroundColor:"",stroke:null,shadow:null,path:void 0,pathStartOffset:0,pathSide:vt,pathAlign:"baseline",_fontSizeFraction:.222,offsets:{underline:.1,linethrough:-.315,overline:-.88},_fontSizeMult:1.13,charSpacing:0,deltaY:0,direction:"ltr",CACHE_FONT_SIZE:400,MIN_TEXT_WIDTH:2},wi="justify",fu="justify-left",Hh="justify-right",Vh="justify-center";class j0 extends Ce{isEmptyStyles(t){if(!this.styles||t!==void 0&&!this.styles[t])return!0;const e=t===void 0?this.styles:{line:this.styles[t]};for(const s in e)for(const i in e[s])for(const n in e[s][i])return!1;return!0}styleHas(t,e){if(!this.styles||e!==void 0&&!this.styles[e])return!1;const s=e===void 0?this.styles:{0:this.styles[e]};for(const i in s)for(const n in s[i])if(s[i][n][t]!==void 0)return!0;return!1}cleanStyle(t){if(!this.styles)return!1;const e=this.styles;let s,i,n=0,r=!0,o=0;for(const h in e){s=0;for(const c in e[h]){const u=e[h][c]||{};n++,u[t]!==void 0?(i?u[t]!==i&&(r=!1):i=u[t],u[t]===this[t]&&delete u[t]):r=!1,Object.keys(u).length!==0?s++:delete e[h][c]}s===0&&delete e[h]}for(let h=0;h<this._textLines.length;h++)o+=this._textLines[h].length;r&&n===o&&(this[t]=i,this.removeStyle(t))}removeStyle(t){if(!this.styles)return;const e=this.styles;let s,i,n;for(i in e){for(n in s=e[i],s)delete s[n][t],Object.keys(s[n]).length===0&&delete s[n];Object.keys(s).length===0&&delete e[i]}}_extendStyles(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t);this._getLineStyle(s)||this._setLineStyle(s);const n=cg(E(E({},this._getStyleDeclaration(s,i)),e),r=>r!==void 0);this._setStyleDeclaration(s,i,n)}getSelectionStyles(t,e,s){const i=[];for(let n=t;n<(e||t);n++)i.push(this.getStyleAtPosition(n,s));return i}getStyleAtPosition(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t);return e?this.getCompleteStyleDeclaration(s,i):this._getStyleDeclaration(s,i)}setSelectionStyles(t,e,s){for(let i=e;i<(s||e);i++)this._extendStyles(i,t);this._forceClearCache=!0}_getStyleDeclaration(t,e){var s;const i=this.styles&&this.styles[t];return i&&(s=i[e])!==null&&s!==void 0?s:{}}getCompleteStyleDeclaration(t,e){return E(E({},Er(this,this.constructor._styleProperties)),this._getStyleDeclaration(t,e))}_setStyleDeclaration(t,e,s){this.styles[t][e]=s}_deleteStyleDeclaration(t,e){delete this.styles[t][e]}_getLineStyle(t){return!!this.styles[t]}_setLineStyle(t){this.styles[t]={}}_deleteLineStyle(t){delete this.styles[t]}}T(j0,"_styleProperties",Ew);const Mw=/ +/g,Pw=/"/g;function Gg(a,t,e,s,i){return" ".concat(function(n,r){let{left:o,top:h,width:c,height:u}=r,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:dt.NUM_FRACTION_DIGITS;const g=Dh(Jt,n,!1),[f,p,m,y]=[o,h,c,u].map(b=>Dt(b,d));return"<rect ".concat(g,' x="').concat(f,'" y="').concat(p,'" width="').concat(m,'" height="').concat(y,'"></rect>')}(a,{left:t,top:e,width:s,height:i}),`
|
|
82
|
+
`)}const Ow=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let Wg;class Ae extends j0{static getDefaults(){return E(E({},super.getDefaults()),Ae.ownDefaults)}constructor(t,e){super(),T(this,"__charBounds",[]),Object.assign(this,Ae.ownDefaults),this.setOptions(e),this.styles||(this.styles={}),this.text=t,this.initialized=!0,this.path&&this.setPathInfo(),this.initDimensions(),this.setCoords()}setPathInfo(){const t=this.path;t&&(t.segmentsInfo=Ng(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(wi)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,s,i,n,r,o;for(let h=0,c=this._textLines.length;h<c;h++)if((this.textAlign===wi||h!==c-1&&!this.isEndOfWrapping(h))&&(i=0,n=this._textLines[h],e=this.getLineWidth(h),e<this.width&&(o=this.textLines[h].match(this._reSpacesAndTabs)))){s=o.length,t=(this.width-e)/s;for(let u=0;u<=n.length;u++)r=this.__charBounds[h][u],this._reSpaceAndTab.test(n[u])?(r.width+=t,r.kernedWidth+=t,r.left+=i,i+=t):r.left+=i}}isEndOfWrapping(t){return t===this._textLines.length-1}missingNewlineOffset(t){return 1}get2DCursorLocation(t,e){const s=e?this._unwrappedTextLines:this._textLines;let i;for(i=0;i<s.length;i++){if(t<=s[i].length)return{lineIndex:i,charIndex:t};t-=s[i].length+this.missingNewlineOffset(i,e)}return{lineIndex:i-1,charIndex:s[i-1].length<t?s[i-1].length:t}}toString(){return"#<Text (".concat(this.complexity(),'): { "text": "').concat(this.text,'", "fontFamily": "').concat(this.fontFamily,'" }>')}_getCacheCanvasDimensions(){const t=super._getCacheCanvasDimensions(),e=this.fontSize;return t.width+=e*t.zoomX,t.height+=e*t.zoomY,t}_render(t){const e=this.path;e&&!e.isNotVisible()&&e._render(t),this._setTextStyles(t),this._renderTextLinesBackground(t),this._renderTextDecoration(t,"underline"),this._renderText(t),this._renderTextDecoration(t,"overline"),this._renderTextDecoration(t,"linethrough")}_renderText(t){this.paintFirst===Ne?(this._renderTextStroke(t),this._renderTextFill(t)):(this._renderTextFill(t),this._renderTextStroke(t))}_setTextStyles(t,e,s){if(t.textBaseline="alphabetic",this.path)switch(this.pathAlign){case tt:t.textBaseline="middle";break;case"ascender":t.textBaseline=Je;break;case"descender":t.textBaseline=sg}t.font=this._getFontDeclaration(e,s)}calcTextWidth(){let t=this.getLineWidth(0);for(let e=1,s=this._textLines.length;e<s;e++){const i=this.getLineWidth(e);i>t&&(t=i)}return t}_renderTextLine(t,e,s,i,n,r){this._renderChars(t,e,s,i,n,r)}_renderTextLinesBackground(t){if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor"))return;const e=t.fillStyle,s=this._getLeftOffset();let i=this._getTopOffset();for(let n=0,r=this._textLines.length;n<r;n++){const o=this.getHeightOfLine(n);if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor",n)){i+=o;continue}const h=this._textLines[n].length,c=this._getLineLeftOffset(n);let u,d,g=0,f=0,p=this.getValueOfPropertyAt(n,0,"textBackgroundColor");for(let m=0;m<h;m++){const y=this.__charBounds[n][m];d=this.getValueOfPropertyAt(n,m,"textBackgroundColor"),this.path?(t.save(),t.translate(y.renderLeft,y.renderTop),t.rotate(y.angle),t.fillStyle=d,d&&t.fillRect(-y.width/2,-o/this.lineHeight*(1-this._fontSizeFraction),y.width,o/this.lineHeight),t.restore()):d!==p?(u=s+c+f,this.direction==="rtl"&&(u=this.width-u-g),t.fillStyle=p,p&&t.fillRect(u,i,g,o/this.lineHeight),f=y.left,g=y.width,p=d):g+=y.kernedWidth}d&&!this.path&&(u=s+c+f,this.direction==="rtl"&&(u=this.width-u-g),t.fillStyle=d,t.fillRect(u,i,g,o/this.lineHeight)),i+=o}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,s,i){const n=Ah.getFontCache(e),r=this._getFontDeclaration(e),o=s+t,h=s&&r===this._getFontDeclaration(i),c=e.fontSize/this.CACHE_FONT_SIZE;let u,d,g,f;if(s&&n[s]!==void 0&&(g=n[s]),n[t]!==void 0&&(f=u=n[t]),h&&n[o]!==void 0&&(d=n[o],f=d-g),u===void 0||g===void 0||d===void 0){const p=function(){return Wg||(Wg=Xs({width:0,height:0}).getContext("2d")),Wg}();this._setTextStyles(p,e,!0),u===void 0&&(f=u=p.measureText(t).width,n[t]=u),g===void 0&&h&&s&&(g=p.measureText(s).width,n[s]=g),h&&d===void 0&&(d=p.measureText(o).width,n[o]=d,f=d-g)}return{width:u*c,kernedWidth:f*c}}getHeightOfChar(t,e){return this.getValueOfPropertyAt(t,e,"fontSize")}measureLine(t){const e=this._measureLine(t);return this.charSpacing!==0&&(e.width-=this._getWidthOfCharSpacing()),e.width<0&&(e.width=0),e}_measureLine(t){let e,s,i=0;const n=this.pathSide===Ut,r=this.path,o=this._textLines[t],h=o.length,c=new Array(h);this.__charBounds[t]=c;for(let u=0;u<h;u++){const d=o[u];s=this._getGraphemeBox(d,t,u,e),c[u]=s,i+=s.kernedWidth,e=d}if(c[h]={left:s?s.left+s.width:0,width:0,kernedWidth:0,height:this.fontSize,deltaY:0},r&&r.segmentsInfo){let u=0;const d=r.segmentsInfo[r.segmentsInfo.length-1].length;switch(this.textAlign){case vt:u=n?d-i:0;break;case tt:u=(d-i)/2;break;case Ut:u=n?0:d-i}u+=this.pathStartOffset*(n?-1:1);for(let g=n?h-1:0;n?g>=0:g<h;n?g--:g++)s=c[g],u>d?u%=d:u<0&&(u+=d),this._setGraphemeOnPath(u,s),u+=s.kernedWidth}return{width:i,numOfSpaces:0}}_setGraphemeOnPath(t,e){const s=t+e.kernedWidth/2,i=this.path,n=_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===Ut?Math.PI:0)}_getGraphemeBox(t,e,s,i,n){const r=this.getCompleteStyleDeclaration(e,s),o=i?this.getCompleteStyleDeclaration(e,s-1):{},h=this._measureChar(t,r,i,o);let c,u=h.kernedWidth,d=h.width;this.charSpacing!==0&&(c=this._getWidthOfCharSpacing(),d+=c,u+=c);const g={width:d,left:0,height:r.fontSize,kernedWidth:u,deltaY:r.deltaY};if(s>0&&!n){const f=this.__charBounds[e][s-1];g.left=f.left+f.width+h.kernedWidth-h.width}return g}getHeightOfLine(t){if(this.__lineHeights[t])return this.__lineHeights[t];let e=this.getHeightOfChar(t,0);for(let s=1,i=this._textLines[t].length;s<i;s++)e=Math.max(this.getHeightOfChar(t,s),e);return this.__lineHeights[t]=e*this.lineHeight*this._fontSizeMult}calcTextHeight(){let t,e=0;for(let s=0,i=this._textLines.length;s<i;s++)t=this.getHeightOfLine(s),e+=s===i-1?t/this.lineHeight:t;return e}_getLeftOffset(){return this.direction==="ltr"?-this.width/2:this.width/2}_getTopOffset(){return-this.height/2}_renderTextCommon(t,e){t.save();let s=0;const i=this._getLeftOffset(),n=this._getTopOffset();for(let r=0,o=this._textLines.length;r<o;r++){const h=this.getHeightOfLine(r),c=h/this.lineHeight,u=this._getLineLeftOffset(r);this._renderTextLine(e,t,this._textLines[r],i+u,n+s+c,r),s+=h}t.restore()}_renderTextFill(t){(this.fill||this.styleHas(Jt))&&this._renderTextCommon(t,"fillText")}_renderTextStroke(t){(this.stroke&&this.strokeWidth!==0||!this.isEmptyStyles())&&(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this._setLineDash(t,this.strokeDashArray),t.beginPath(),this._renderTextCommon(t,"strokeText"),t.closePath(),t.restore())}_renderChars(t,e,s,i,n,r){const o=this.getHeightOfLine(r),h=this.textAlign.includes(wi),c=this.path,u=!h&&this.charSpacing===0&&this.isEmptyStyles(r)&&!c,d=this.direction==="ltr",g=this.direction==="ltr"?1:-1,f=e.direction;let p,m,y,b,x,C="",A=0;if(e.save(),f!==this.direction&&(e.canvas.setAttribute("dir",d?"ltr":"rtl"),e.direction=d?"ltr":"rtl",e.textAlign=d?vt:Ut),n-=o*this._fontSizeFraction/this.lineHeight,u)return this._renderChar(t,e,r,0,s.join(""),i,n),void e.restore();for(let M=0,D=s.length-1;M<=D;M++)b=M===D||this.charSpacing||c,C+=s[M],y=this.__charBounds[r][M],A===0?(i+=g*(y.kernedWidth-y.width),A+=y.width):A+=y.kernedWidth,h&&!b&&this._reSpaceAndTab.test(s[M])&&(b=!0),b||(p=p||this.getCompleteStyleDeclaration(r,M),m=this.getCompleteStyleDeclaration(r,M+1),b=nu(p,m,!1)),b&&(c?(e.save(),e.translate(y.renderLeft,y.renderTop),e.rotate(y.angle),this._renderChar(t,e,r,M,C,-A/2,0),e.restore()):(x=i,this._renderChar(t,e,r,M,C,x,n)),C="",p=m,i+=g*A,A=0);e.restore()}_applyPatternGradientTransformText(t){const e=this.width+this.strokeWidth,s=this.height+this.strokeWidth,i=Xs({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 Ts(s)?s.gradientUnits==="percentage"||s.gradientTransform||s.patternTransform?(i=-this.width/2,n=-this.height/2,t.translate(i,n),t[e]=this._applyPatternGradientTransformText(s),{offsetX:i,offsetY:n}):(t[e]=s.toLive(t),this._applyPatternGradientTransform(t,s)):(t[e]=s,{offsetX:0,offsetY:0})}_setStrokeStyles(t,e){let{stroke:s,strokeWidth:i}=e;return t.lineWidth=i,t.lineCap=this.strokeLineCap,t.lineDashOffset=this.strokeDashOffset,t.lineJoin=this.strokeLineJoin,t.miterLimit=this.strokeMiterLimit,this.handleFiller(t,"strokeStyle",s)}_setFillStyles(t,e){let{fill:s}=e;return this.handleFiller(t,"fillStyle",s)}_renderChar(t,e,s,i,n,r,o){const h=this._getStyleDeclaration(s,i),c=this.getCompleteStyleDeclaration(s,i),u=t==="fillText"&&c.fill,d=t==="strokeText"&&c.stroke&&c.strokeWidth;if(d||u){if(e.save(),e.font=this._getFontDeclaration(c),h.textBackgroundColor&&this._removeShadow(e),h.deltaY&&(o+=h.deltaY),u){const g=this._setFillStyles(e,c);e.fillText(n,r-g.offsetX,o-g.offsetY)}if(d){const g=this._setStrokeStyles(e,c);e.strokeText(n,r-g.offsetX,o-g.offsetY)}e.restore()}}setSuperscript(t,e){this._setScript(t,e,this.superscript)}setSubscript(t,e){this._setScript(t,e,this.subscript)}_setScript(t,e,s){const i=this.get2DCursorLocation(t,!0),n=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"fontSize"),r=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"deltaY"),o={fontSize:n*s.size,deltaY:r+n*s.baseline};this.setSelectionStyles(o,t,e)}_getLineLeftOffset(t){const e=this.getLineWidth(t),s=this.width-e,i=this.textAlign,n=this.direction,r=this.isEndOfWrapping(t);let o=0;return i===wi||i===Vh&&!r||i===Hh&&!r||i===fu&&!r?0:(i===tt&&(o=s/2),i===Ut&&(o=s),i===Vh&&(o=s/2),i===Hh&&(o=s),n==="rtl"&&(i===Ut||i===wi||i===Hh?o=0:i===vt||i===fu?o=-s:i!==tt&&i!==Vh||(o=-s/2)),o)}_clearCache(){this._forceClearCache=!1,this.__lineWidths=[],this.__lineHeights=[],this.__charBounds=[]}getLineWidth(t){if(this.__lineWidths[t]!==void 0)return this.__lineWidths[t];const{width:e}=this.measureLine(t);return this.__lineWidths[t]=e,e}_getWidthOfCharSpacing(){return this.charSpacing!==0?this.fontSize*this.charSpacing/1e3:0}getValueOfPropertyAt(t,e,s){var i;return(i=this._getStyleDeclaration(t,e)[s])!==null&&i!==void 0?i:this[s]}_renderTextDecoration(t,e){if(!this[e]&&!this.styleHas(e))return;let s=this._getTopOffset();const i=this._getLeftOffset(),n=this.path,r=this._getWidthOfCharSpacing(),o=this.offsets[e];for(let h=0,c=this._textLines.length;h<c;h++){const u=this.getHeightOfLine(h);if(!this[e]&&!this.styleHas(e,h)){s+=u;continue}const d=this._textLines[h],g=u/this.lineHeight,f=this._getLineLeftOffset(h);let p,m,y=0,b=0,x=this.getValueOfPropertyAt(h,0,e),C=this.getValueOfPropertyAt(h,0,Jt);const A=s+g*(1-this._fontSizeFraction);let M=this.getHeightOfChar(h,0),D=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),m=this.getValueOfPropertyAt(h,P,Jt);const I=this.getHeightOfChar(h,P),X=this.getValueOfPropertyAt(h,P,"deltaY");if(n&&p&&m)t.save(),t.fillStyle=C,t.translate(F.renderLeft,F.renderTop),t.rotate(F.angle),t.fillRect(-F.kernedWidth/2,o*I+X,F.kernedWidth,this.fontSize/15),t.restore();else if((p!==x||m!==C||I!==M||X!==D)&&b>0){let j=i+f+y;this.direction==="rtl"&&(j=this.width-j-b),x&&C&&(t.fillStyle=C,t.fillRect(j,A+o*M+D,b,this.fontSize/15)),y=F.left,b=F.width,x=p,C=m,M=I,D=X}else b+=F.kernedWidth}let k=i+f+y;this.direction==="rtl"&&(k=this.width-k-b),t.fillStyle=m,p&&m&&t.fillRect(k,A+o*M+D,b-r,this.fontSize/15),s+=u}this._removeShadow(t)}_getFontDeclaration(){let{fontFamily:t=this.fontFamily,fontStyle:e=this.fontStyle,fontWeight:s=this.fontWeight,fontSize:i=this.fontSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;const r=t.includes("'")||t.includes('"')||t.includes(",")||Ae.genericFonts.includes(t.toLowerCase())?t:'"'.concat(t,'"');return[e,s,"".concat(n?this.CACHE_FONT_SIZE:i,"px"),r].join(" ")}render(t){this.visible&&(this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(this._forceClearCache&&this.initDimensions(),super.render(t)))}graphemeSplit(t){return iu(t)}_splitTextIntoLines(t){const e=t.split(this._reNewline),s=new Array(e.length),i=[`
|
|
83
|
+
`];let n=[];for(let r=0;r<e.length;r++)s[r]=this.graphemeSplit(e[r]),n=n.concat(s[r],i);return n.pop(),{_unwrappedLines:s,lines:e,graphemeText:n,graphemeLines:s}}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return E(E({},super.toObject([...I0,...t])),{},{styles:Jm(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=Ki(t,Ae.ATTRIBUTE_NAMES,s),n=E(E({},e),i),{textAnchor:r=vt,textDecoration:o="",dx:h=0,dy:c=0,top:u=0,left:d=0,fontSize:g=eg,strokeWidth:f=1}=n,p=Ot(n,Ow),m=new this((t.textContent||"").replace(/^\s+|\s+$|\n+/g,"").replace(/\s+/g," "),E({left:d+h,top:u+c,underline:o.includes("underline"),overline:o.includes("overline"),linethrough:o.includes("line-through"),strokeWidth:0,fontSize:g},p)),y=m.getScaledHeight()/m.height,b=((m.height+m.strokeWidth)*m.lineHeight-m.height)*y,x=m.getScaledHeight()+b;let C=0;return r===tt&&(C=m.getScaledWidth()/2),r===Ut&&(C=m.getScaledWidth()),m.set({left:m.left-C,top:m.top-(x-m.fontSize*(.07+m._fontSizeFraction))/m.lineHeight,strokeWidth:f}),m}static fromObject(t){return this._fromObject(E(E({},t),{},{styles:Zm(t.styles||{},t.text)}),{extraParam:"text"})}}T(Ae,"textLayoutProperties",F0),T(Ae,"cacheProperties",[...$i,...I0]),T(Ae,"ownDefaults",kw),T(Ae,"type","Text"),T(Ae,"genericFonts",["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong"]),T(Ae,"ATTRIBUTE_NAMES",Vn.concat("x","y","dx","dy","font-family","font-style","font-weight","font-size","letter-spacing","text-decoration","text-anchor")),Um(Ae,[class extends Tm{_toSVG(){const a=this._getSVGLeftTopOffsets(),t=this._getSVGTextAndBg(a.textTop,a.textLeft);return this._wrapSVGTextAndBg(t)}toSVG(a){return this._createBaseSVGMarkup(this._toSVG(),{reviver:a,noStyle:!0,withShadow:!0})}_getSVGLeftTopOffsets(){return{textLeft:-this.width/2,textTop:-this.height/2,lineTop:this.getHeightOfLine(0)}}_wrapSVGTextAndBg(a){let{textBgRects:t,textSpans:e}=a;const s=this.getSvgTextDecoration(this);return[t.join(""),' <text xml:space="preserve" ',this.fontFamily?'font-family="'.concat(this.fontFamily.replace(Pw,"'"),'" '):"",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(a,t){const e=[],s=[];let i,n=a;this.backgroundColor&&s.push(...Gg(this.backgroundColor,-this.width/2,-this.height/2,this.width,this.height));for(let r=0,o=this._textLines.length;r<o;r++)i=this._getLineLeftOffset(r),this.direction==="rtl"&&(i+=this.width),(this.textBackgroundColor||this.styleHas("textBackgroundColor",r))&&this._setSVGTextLineBg(s,r,t+i,n),this._setSVGTextLineText(e,r,t+i,n),n+=this.getHeightOfLine(r);return{textSpans:e,textBgRects:s}}_createTextCharSpan(a,t,e,s){const i=this.getSvgSpanStyles(t,a!==a.trim()||!!a.match(Mw)),n=i?'style="'.concat(i,'"'):"",r=t.deltaY,o=r?' dy="'.concat(Dt(r,dt.NUM_FRACTION_DIGITS),'" '):"";return'<tspan x="'.concat(Dt(e,dt.NUM_FRACTION_DIGITS),'" y="').concat(Dt(s,dt.NUM_FRACTION_DIGITS),'" ').concat(o).concat(n,">").concat(Qm(a),"</tspan>")}_setSVGTextLineText(a,t,e,s){const i=this.getHeightOfLine(t),n=this.textAlign.includes(wi),r=this._textLines[t];let o,h,c,u,d,g="",f=0;s+=i*(1-this._fontSizeFraction)/this.lineHeight;for(let p=0,m=r.length-1;p<=m;p++)d=p===m||this.charSpacing,g+=r[p],c=this.__charBounds[t][p],f===0?(e+=c.kernedWidth-c.width,f+=c.width):f+=c.kernedWidth,n&&!d&&this._reSpaceAndTab.test(r[p])&&(d=!0),d||(o=o||this.getCompleteStyleDeclaration(t,p),h=this.getCompleteStyleDeclaration(t,p+1),d=nu(o,h,!0)),d&&(u=this._getStyleDeclaration(t,p),a.push(this._createTextCharSpan(g,u,e,s)),g="",o=h,this.direction==="rtl"?e-=f:e+=f,f=0)}_setSVGTextLineBg(a,t,e,s){const i=this._textLines[t],n=this.getHeightOfLine(t)/this.lineHeight;let r,o=0,h=0,c=this.getValueOfPropertyAt(t,0,"textBackgroundColor");for(let u=0;u<i.length;u++){const{left:d,width:g,kernedWidth:f}=this.__charBounds[t][u];r=this.getValueOfPropertyAt(t,u,"textBackgroundColor"),r!==c?(c&&a.push(...Gg(c,e+h,s,o,n)),h=d,o=g,c=r):o+=f}r&&a.push(...Gg(c,e+h,s,o,n))}_getSVGLineTopOffset(a){let t,e=0;for(t=0;t<a;t++)e+=this.getHeightOfLine(t);const s=this.getHeightOfLine(t);return{lineTop:e,offset:(this._fontSizeMult-this._fontSizeFraction)*s/(this.lineHeight*this._fontSizeMult)}}getSvgStyles(a){return"".concat(super.getSvgStyles(a)," white-space: pre;")}getSvgSpanStyles(a,t){const{fontFamily:e,strokeWidth:s,stroke:i,fill:n,fontSize:r,fontStyle:o,fontWeight:h,deltaY:c}=a,u=this.getSvgTextDecoration(a);return[i?Dh(Ne,i):"",s?"stroke-width: ".concat(s,"; "):"",e?"font-family: ".concat(e.includes("'")||e.includes('"')?e:"'".concat(e,"'"),"; "):"",r?"font-size: ".concat(r,"px; "):"",o?"font-style: ".concat(o,"; "):"",h?"font-weight: ".concat(h,"; "):"",u&&"text-decoration: ".concat(u,"; "),n?Dh(Jt,n):"",c?"baseline-shift: ".concat(-c,"; "):"",t?"white-space: pre; ":""].join("")}getSvgTextDecoration(a){return["overline","underline","line-through"].filter(t=>a[t.replace("-","")]).join(" ")}}]),W.setClass(Ae),W.setSVGClass(Ae);class Dw{constructor(t){T(this,"target",void 0),T(this,"__mouseDownInPlace",!1),T(this,"__dragStartFired",!1),T(this,"__isDraggingOver",!1),T(this,"__dragStartSelection",void 0),T(this,"__dragImageDisposer",void 0),T(this,"_dispose",void 0),this.target=t;const e=[this.target.on("dragenter",this.dragEnterHandler.bind(this)),this.target.on("dragover",this.dragOverHandler.bind(this)),this.target.on("dragleave",this.dragLeaveHandler.bind(this)),this.target.on("dragend",this.dragEndHandler.bind(this)),this.target.on("drop",this.dropHandler.bind(this))];this._dispose=()=>{e.forEach(s=>s()),this._dispose=void 0}}isPointerOverSelection(t){const e=this.target,s=e.getSelectionStartFromPointer(t);return e.isEditing&&s>=e.selectionStart&&s<=e.selectionEnd&&e.selectionStart<e.selectionEnd}start(t){return this.__mouseDownInPlace=this.isPointerOverSelection(t)}isActive(){return this.__mouseDownInPlace}end(t){const e=this.isActive();return e&&!this.__dragStartFired&&(this.target.setCursorByClick(t),this.target.initDelayedCursor(!0)),this.__mouseDownInPlace=!1,this.__dragStartFired=!1,this.__isDraggingOver=!1,e}getDragStartSelection(){return this.__dragStartSelection}setDragImage(t,e){var s;let{selectionStart:i,selectionEnd:n}=e;const r=this.target,o=r.canvas,h=new O(r.flipX?-1:1,r.flipY?-1:1),c=r._getCursorBoundaries(i),u=new O(c.left+c.leftOffset,c.top+c.topOffset).multiply(h).transform(r.calcTransformMatrix()),d=o.getScenePoint(t).subtract(u),g=r.getCanvasRetinaScaling(),f=r.getBoundingRect(),p=u.subtract(new O(f.left,f.top)),m=o.viewportTransform,y=p.add(d).transform(m,!0),b=r.backgroundColor,x=Og(r.styles);r.backgroundColor="";const C={stroke:"transparent",fill:"transparent",textBackgroundColor:"transparent"};r.setSelectionStyles(C,0,i),r.setSelectionStyles(C,n,r.text.length),r.dirty=!0;const A=r.toCanvasElement({enableRetinaScaling:o.enableRetinaScaling,viewportTransform:!0});r.backgroundColor=b,r.styles=x,r.dirty=!0,cu(A,{position:"fixed",left:"".concat(-A.width,"px"),border:Ie,width:"".concat(A.width/g,"px"),height:"".concat(A.height/g,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{A.remove()},Us(t.target||this.target.hiddenTextarea).body.appendChild(A),(s=t.dataTransfer)===null||s===void 0||s.setDragImage(A,y.x,y.y)}onDragStart(t){this.__dragStartFired=!0;const e=this.target,s=this.isActive();if(s&&t.dataTransfer){const i=this.__dragStartSelection={selectionStart:e.selectionStart,selectionEnd:e.selectionEnd},n=e._text.slice(i.selectionStart,i.selectionEnd).join(""),r=E({text:e.text,value:n},i);t.dataTransfer.setData("text/plain",n),t.dataTransfer.setData("application/fabric",JSON.stringify({value:n,styles:e.getSelectionStyles(i.selectionStart,i.selectionEnd,!0)})),t.dataTransfer.effectAllowed="copyMove",this.setDragImage(t,r)}return e.abortCursorAnimation(),s}canDrop(t){if(this.target.editable&&!this.target.getActiveControl()&&!t.defaultPrevented){if(this.isActive()&&this.__dragStartSelection){const e=this.target.getSelectionStartFromPointer(t),s=this.__dragStartSelection;return e<s.selectionStart||e>s.selectionEnd}return!0}return!1}targetCanDrop(t){return this.target.canDrop(t)}dragEnterHandler(t){let{e}=t;const s=this.targetCanDrop(e);!this.__isDraggingOver&&s&&(this.__isDraggingOver=!0)}dragOverHandler(t){const{e}=t,s=this.targetCanDrop(e);!this.__isDraggingOver&&s?this.__isDraggingOver=!0:this.__isDraggingOver&&!s&&(this.__isDraggingOver=!1),this.__isDraggingOver&&(e.preventDefault(),t.canDrop=!0,t.dropTarget=this.target)}dragLeaveHandler(){(this.__isDraggingOver||this.isActive())&&(this.__isDraggingOver=!1)}dropHandler(t){var e;const{e:s}=t,i=s.defaultPrevented;this.__isDraggingOver=!1,s.preventDefault();let n=(e=s.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain");if(n&&!i){const r=this.target,o=r.canvas;let h=r.getSelectionStartFromPointer(s);const{styles:c}=s.dataTransfer.types.includes("application/fabric")?JSON.parse(s.dataTransfer.getData("application/fabric")):{},u=n[Math.max(0,n.length-1)],d=0;if(this.__dragStartSelection){const g=this.__dragStartSelection.selectionStart,f=this.__dragStartSelection.selectionEnd;h>g&&h<=f?h=g:h>f&&(h-=f-g),r.removeChars(g,f),delete this.__dragStartSelection}r._reNewline.test(u)&&(r._reNewline.test(r._text[h])||h===r._text.length)&&(n=n.trimEnd()),t.didDrop=!0,t.dropTarget=r,r.insertChars(n,c,h),o.setActiveObject(r),r.enterEditing(s),r.selectionStart=Math.min(h+d,r._text.length),r.selectionEnd=Math.min(r.selectionStart+n.length,r._text.length),r.hiddenTextarea.value=r.text,r._updateTextarea(),r.hiddenTextarea.focus(),r.fire(Nc,{index:h+d,action:"drop"}),o.fire("text:changed",{target:r}),o.contextTopDirty=!0,o.requestRenderAll()}}dragEndHandler(t){let{e}=t;if(this.isActive()&&this.__dragStartFired&&this.__dragStartSelection){var s;const i=this.target,n=this.target.canvas,{selectionStart:r,selectionEnd:o}=this.__dragStartSelection,h=((s=e.dataTransfer)===null||s===void 0?void 0:s.dropEffect)||Ie;h===Ie?(i.selectionStart=r,i.selectionEnd=o,i._updateTextarea(),i.hiddenTextarea.focus()):(i.clearContextTop(),h==="move"&&(i.removeChars(r,o),i.selectionStart=i.selectionEnd=r,i.hiddenTextarea&&(i.hiddenTextarea.value=i.text),i._updateTextarea(),i.fire(Nc,{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 N0=/[ \n\.,;!\?\-]/;class Rw extends Ae{constructor(){super(...arguments),T(this,"_currentCursorOpacity",1)}initBehavior(){this._tick=this._tick.bind(this),this._onTickComplete=this._onTickComplete.bind(this),this.updateSelectionOnMouseMove=this.updateSelectionOnMouseMove.bind(this)}onDeselect(t){return this.isEditing&&this.exitEditing(),this.selected=!1,super.onDeselect(t)}_animateCursor(t){let{toValue:e,duration:s,delay:i,onComplete:n}=t;return kg({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||!ig.test(s[t-1]))?t-1:t,n=s[i];for(;i>0&&i<s.length&&!N0.test(n);)i+=e,n=s[i];return e===-1&&N0.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;Us(e).activeElement!==e&&e.focus();const s=this.getSelectionStartFromPointer(t),i=this.selectionStart,n=this.selectionEnd;(s===this.__selectionStartOnMouseDown&&i!==n||i!==s&&n!==s)&&(s>this.__selectionStartOnMouseDown?(this.selectionStart=this.__selectionStartOnMouseDown,this.selectionEnd=s):(this.selectionStart=s,this.selectionEnd=this.__selectionStartOnMouseDown),this.selectionStart===i&&this.selectionEnd===n||(this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()))}_setEditingProps(){this.hoverCursor="text",this.canvas&&(this.canvas.defaultCursor=this.canvas.moveCursor="text"),this.borderColor=this.editingBorderColor,this.hasControls=this.selectable=!1,this.lockMovementX=this.lockMovementY=!0}fromStringToGraphemeSelection(t,e,s){const i=s.slice(0,t),n=this.graphemeSplit(i).length;if(t===e)return{selectionStart:n,selectionEnd:n};const r=s.slice(t,e);return{selectionStart:n,selectionEnd:n+this.graphemeSplit(r).length}}fromGraphemeToStringSelection(t,e,s){const i=s.slice(0,t).join("").length;return t===e?{selectionStart:i,selectionEnd:i}:{selectionStart:i,selectionEnd:i+s.slice(t,e).join("").length}}_updateTextarea(){if(this.cursorOffsetCache={},this.hiddenTextarea){if(!this.inCompositionMode){const t=this.fromGraphemeToStringSelection(this.selectionStart,this.selectionEnd,this._text);this.hiddenTextarea.selectionStart=t.selectionStart,this.hiddenTextarea.selectionEnd=t.selectionEnd}this.updateTextareaPosition()}}updateFromTextArea(){if(!this.hiddenTextarea)return;this.cursorOffsetCache={};const t=this.hiddenTextarea;this.text=t.value,this.set("dirty",!0),this.initDimensions(),this.setCoords();const e=this.fromStringToGraphemeSelection(t.selectionStart,t.selectionEnd,t.value);this.selectionEnd=this.selectionStart=e.selectionEnd,this.inCompositionMode||(this.selectionStart=e.selectionStart),this.updateTextareaPosition()}updateTextareaPosition(){if(this.selectionStart===this.selectionEnd){const t=this._calcTextareaPosition();this.hiddenTextarea.style.left=t.left,this.hiddenTextarea.style.top=t.top}}_calcTextareaPosition(){if(!this.canvas)return{left:"1px",top:"1px"};const t=this.inCompositionMode?this.compositionStart:this.selectionStart,e=this._getCursorBoundaries(t),s=this.get2DCursorLocation(t),i=s.lineIndex,n=s.charIndex,r=this.getValueOfPropertyAt(i,n,"fontSize")*this.lineHeight,o=e.leftOffset,h=this.getCanvasRetinaScaling(),c=this.canvas.upperCanvasEl,u=c.width/h,d=c.height/h,g=u-r,f=d-r,p=new O(e.left+o,e.top+e.topOffset+r).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new O(c.clientWidth/u,c.clientHeight/d));return p.x<0&&(p.x=0),p.x>g&&(p.x=g),p.y<0&&(p.y=0),p.y>f&&(p.y=f),p.x+=this.canvas._offset.left,p.y+=this.canvas._offset.top,{left:"".concat(p.x,"px"),top:"".concat(p.y,"px"),fontSize:"".concat(r,"px"),charHeight:r}}_saveEditingProps(){this._savedProps={hasControls:this.hasControls,borderColor:this.borderColor,lockMovementX:this.lockMovementX,lockMovementY:this.lockMovementY,hoverCursor:this.hoverCursor,selectable:this.selectable,defaultCursor:this.canvas&&this.canvas.defaultCursor,moveCursor:this.canvas&&this.canvas.moveCursor}}_restoreEditingProps(){this._savedProps&&(this.hoverCursor=this._savedProps.hoverCursor,this.hasControls=this._savedProps.hasControls,this.borderColor=this._savedProps.borderColor,this.selectable=this._savedProps.selectable,this.lockMovementX=this._savedProps.lockMovementX,this.lockMovementY=this._savedProps.lockMovementY,this.canvas&&(this.canvas.defaultCursor=this._savedProps.defaultCursor||this.canvas.defaultCursor,this.canvas.moveCursor=this._savedProps.moveCursor||this.canvas.moveCursor),delete this._savedProps)}_exitEditing(){const t=this.hiddenTextarea;this.selected=!1,this.isEditing=!1,t&&(t.blur&&t.blur(),t.parentNode&&t.parentNode.removeChild(t)),this.hiddenTextarea=null,this.abortCursorAnimation(),this.selectionStart!==this.selectionEnd&&this.clearContextTop()}exitEditingImpl(){this._exitEditing(),this.selectionEnd=this.selectionStart,this._restoreEditingProps(),this._forceClearCache&&(this.initDimensions(),this.setCoords())}exitEditing(){const t=this._textBeforeEdit!==this.text;return this.exitEditingImpl(),this.fire("editing:exited"),t&&this.fire(Hc),this.canvas&&(this.canvas.fire("text:editing:exited",{target:this}),t&&this.canvas.fire("object:modified",{target:this})),this}_removeExtraneousStyles(){for(const t in this.styles)this._textLines[t]||delete this.styles[t]}removeStyleFromTo(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t,!0),{lineIndex:n,charIndex:r}=this.get2DCursorLocation(e,!0);if(s!==n){if(this.styles[s])for(let o=i;o<this._unwrappedTextLines[s].length;o++)delete this.styles[s][o];if(this.styles[n])for(let o=r;o<this._unwrappedTextLines[n].length;o++){const h=this.styles[n][o];h&&(this.styles[s]||(this.styles[s]={}),this.styles[s][i+o-r]=h)}for(let o=s+1;o<=n;o++)delete this.styles[o];this.shiftLineStyles(n,s-n)}else if(this.styles[s]){const o=this.styles[s],h=r-i;for(let c=i;c<r;c++)delete o[c];for(const c in this.styles[s]){const u=parseInt(c,10);u>=r&&(o[u-h]=o[c],delete o[c])}}}shiftLineStyles(t,e){const s=Object.assign({},this.styles);for(const i in this.styles){const n=parseInt(i,10);n>t&&(this.styles[n+e]=s[n],s[n-e]||delete this.styles[n])}}insertNewlineStyleObject(t,e,s,i){const n={},r=this._unwrappedTextLines[t].length,o=r===e;let h=!1;s||(s=1),this.shiftLineStyles(t,s);const c=this.styles[t]?this.styles[t][e===0?e:e-1]:void 0;for(const d in this.styles[t]){const g=parseInt(d,10);g>=e&&(h=!0,n[g-e]=this.styles[t][d],o&&e===0||delete this.styles[t][d])}let u=!1;for(h&&!o&&(this.styles[t+s]=n,u=!0),(u||r>e)&&s--;s>0;)i&&i[s-1]?this.styles[t+s]={0:E({},i[s-1])}:c?this.styles[t+s]={0:E({},c)}:delete this.styles[t+s],s--;this._forceClearCache=!0}insertCharStyleObject(t,e,s,i){this.styles||(this.styles={});const n=this.styles[t],r=n?E({},n):{};s||(s=1);for(const h in r){const c=parseInt(h,10);c>=e&&(n[c+s]=r[c],r[c-s]||delete n[c])}if(this._forceClearCache=!0,i){for(;s--;)Object.keys(i[s]).length&&(this.styles[t]||(this.styles[t]={}),this.styles[t][e+s]=E({},i[s]));return}if(!n)return;const o=n[e?e-1:1];for(;o&&s--;)this.styles[t][e+s]=E({},o)}insertNewStyleBlock(t,e,s){const i=this.get2DCursorLocation(e,!0),n=[0];let r,o=0;for(let h=0;h<t.length;h++)t[h]===`
|
|
85
|
+
`?(o++,n[o]=0):n[o]++;for(n[0]>0&&(this.insertCharStyleObject(i.lineIndex,i.charIndex,n[0],s),s=s&&s.slice(n[0]+1)),o&&this.insertNewlineStyleObject(i.lineIndex,i.charIndex+n[0],o),r=1;r<o;r++)n[r]>0?this.insertCharStyleObject(i.lineIndex+r,0,n[r],s):s&&this.styles[i.lineIndex+r]&&s[0]&&(this.styles[i.lineIndex+r][0]=s[0]),s=s&&s.slice(n[r]+1);n[r]>0&&this.insertCharStyleObject(i.lineIndex+r,0,n[r],s)}removeChars(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:t+1;this.removeStyleFromTo(t,e),this._text.splice(t,e-t),this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}insertChars(t,e,s){let i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:s;i>s&&this.removeStyleFromTo(s,i);const n=this.graphemeSplit(t);this.insertNewStyleBlock(n,s,e),this._text=[...this._text.slice(0,s),...n,...this._text.slice(i)],this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}setSelectionStartEndWithShift(t,e,s){s<=t?(e===t?this._selectionDirection=vt:this._selectionDirection===Ut&&(this._selectionDirection=vt,this.selectionEnd=t),this.selectionStart=s):s>t&&s<e?this._selectionDirection===Ut?this.selectionEnd=s:this.selectionStart=s:(e===t?this._selectionDirection=Ut:this._selectionDirection===vt&&(this._selectionDirection=Ut,this.selectionStart=e),this.selectionEnd=s)}}class Lw extends Rw{initHiddenTextarea(){const t=this.canvas&&Us(this.canvas.getElement())||Xo(),e=t.createElement("textarea");Object.entries({autocapitalize:"off",autocorrect:"off",autocomplete:"off",spellcheck:"false","data-fabric":"textarea",wrap:"off"}).map(r=>{let[o,h]=r;return e.setAttribute(o,h)});const{top:s,left:i,fontSize:n}=this._calcTextareaPosition();e.style.cssText="position: absolute; top: ".concat(s,"; left: ").concat(i,"; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; padding-top: ").concat(n,";"),(this.hiddenTextareaContainer||t.body).appendChild(e),Object.entries({blur:"blur",keydown:"onKeyDown",keyup:"onKeyUp",input:"onInput",copy:"copy",cut:"copy",paste:"paste",compositionstart:"onCompositionStart",compositionupdate:"onCompositionUpdate",compositionend:"onCompositionEnd"}).map(r=>{let[o,h]=r;return e.addEventListener(o,this[h].bind(this))}),this.hiddenTextarea=e}blur(){this.abortCursorAnimation()}onKeyDown(t){if(!this.isEditing)return;const e=this.direction==="rtl"?this.keysMapRtl:this.keysMap;if(t.keyCode in e)this[e[t.keyCode]](t);else{if(!(t.keyCode in this.ctrlKeysMapDown)||!t.ctrlKey&&!t.metaKey)return;this[this.ctrlKeysMapDown[t.keyCode]](t)}t.stopImmediatePropagation(),t.preventDefault(),t.keyCode>=33&&t.keyCode<=40?(this.inCompositionMode=!1,this.clearContextTop(),this.renderCursorOrSelection()):this.canvas&&this.canvas.requestRenderAll()}onKeyUp(t){!this.isEditing||this._copyDone||this.inCompositionMode?this._copyDone=!1:t.keyCode in this.ctrlKeysMapUp&&(t.ctrlKey||t.metaKey)&&(this[this.ctrlKeysMapUp[t.keyCode]](t),t.stopImmediatePropagation(),t.preventDefault(),this.canvas&&this.canvas.requestRenderAll())}onInput(t){const e=this.fromPaste;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;const s=()=>{this.updateFromTextArea(),this.fire(Nc),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(this.hiddenTextarea.value==="")return this.styles={},void s();const i=this._splitTextIntoLines(this.hiddenTextarea.value).graphemeText,n=this._text.length,r=i.length,o=this.selectionStart,h=this.selectionEnd,c=o!==h;let u,d,g,f,p=r-n;const m=this.fromStringToGraphemeSelection(this.hiddenTextarea.selectionStart,this.hiddenTextarea.selectionEnd,this.hiddenTextarea.value),y=o>m.selectionStart;c?(d=this._text.slice(o,h),p+=h-o):r<n&&(d=y?this._text.slice(h+p,h):this._text.slice(o,o-p));const b=i.slice(m.selectionEnd-p,m.selectionEnd);if(d&&d.length&&(b.length&&(u=this.getSelectionStyles(o,o+1,!1),u=b.map(()=>u[0])),c?(g=o,f=h):y?(g=h-d.length,f=h):(g=h,f=h+d.length),this.removeStyleFromTo(g,f)),b.length){const{copyPasteData:x}=vi();e&&b.join("")===x.copiedText&&!dt.disableStyleCopyPaste&&(u=x.copiedTextStyle),this.insertNewStyleBlock(b,o,u)}s()}onCompositionStart(){this.inCompositionMode=!0}onCompositionEnd(){this.inCompositionMode=!1}onCompositionUpdate(t){let{target:e}=t;const{selectionStart:s,selectionEnd:i}=e;this.compositionStart=s,this.compositionEnd=i,this.updateTextareaPosition()}copy(){if(this.selectionStart===this.selectionEnd)return;const{copyPasteData:t}=vi();t.copiedText=this.getSelectedText(),dt.disableStyleCopyPaste?t.copiedTextStyle=void 0:t.copiedTextStyle=this.getSelectionStyles(this.selectionStart,this.selectionEnd,!0),this._copyDone=!0}paste(){this.fromPaste=!0}_getWidthBeforeCursor(t,e){let s,i=this._getLineLeftOffset(t);return e>0&&(s=this.__charBounds[t][e-1],i+=s.left+s.width),i}getDownCursorOffset(t,e){const s=this._getSelectionForOffset(t,e),i=this.get2DCursorLocation(s),n=i.lineIndex;if(n===this._textLines.length-1||t.metaKey||t.keyCode===34)return this._text.length-s;const r=i.charIndex,o=this._getWidthBeforeCursor(n,r),h=this._getIndexOnLine(n+1,o);return this._textLines[n].slice(r).length+h+1+this.missingNewlineOffset(n)}_getSelectionForOffset(t,e){return t.shiftKey&&this.selectionStart!==this.selectionEnd&&e?this.selectionEnd:this.selectionStart}getUpCursorOffset(t,e){const s=this._getSelectionForOffset(t,e),i=this.get2DCursorLocation(s),n=i.lineIndex;if(n===0||t.metaKey||t.keyCode===33)return-s;const r=i.charIndex,o=this._getWidthBeforeCursor(n,r),h=this._getIndexOnLine(n-1,o),c=this._textLines[n].slice(0,r),u=this.missingNewlineOffset(n-1);return-this._textLines[n-1].length+h-c.length+(1-u)}_getIndexOnLine(t,e){const s=this._textLines[t];let i,n,r=this._getLineLeftOffset(t),o=0;for(let h=0,c=s.length;h<c;h++)if(i=this.__charBounds[t][h].width,r+=i,r>e){n=!0;const u=r-i,d=r,g=Math.abs(u-e);o=Math.abs(d-e)<g?h:h-1;break}return n||(o=s.length-1),o}moveCursorDown(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorUpOrDown("Down",t)}moveCursorUp(t){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorUpOrDown("Up",t)}_moveCursorUpOrDown(t,e){const s=this["get".concat(t,"CursorOffset")](e,this._selectionDirection===Ut);if(e.shiftKey?this.moveCursorWithShift(s):this.moveCursorWithoutShift(s),s!==0){const i=this.text.length;this.selectionStart=Pr(0,this.selectionStart,i),this.selectionEnd=Pr(0,this.selectionEnd,i),this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea()}}moveCursorWithShift(t){const e=this._selectionDirection===vt?this.selectionStart+t:this.selectionEnd+t;return this.setSelectionStartEndWithShift(this.selectionStart,this.selectionEnd,e),t!==0}moveCursorWithoutShift(t){return t<0?(this.selectionStart+=t,this.selectionEnd=this.selectionStart):(this.selectionEnd+=t,this.selectionStart=this.selectionEnd),t!==0}moveCursorLeft(t){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorLeftOrRight("Left",t)}_move(t,e,s){let i;if(t.altKey)i=this["findWordBoundary".concat(s)](this[e]);else{if(!t.metaKey&&t.keyCode!==35&&t.keyCode!==36)return this[e]+=s==="Left"?-1:1,!0;i=this["findLineBoundary".concat(s)](this[e])}return i!==void 0&&this[e]!==i&&(this[e]=i,!0)}_moveLeft(t,e){return this._move(t,e,"Left")}_moveRight(t,e){return this._move(t,e,"Right")}moveCursorLeftWithoutShift(t){let e=!0;return this._selectionDirection=vt,this.selectionEnd===this.selectionStart&&this.selectionStart!==0&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return this._selectionDirection===Ut&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):this.selectionStart!==0?(this._selectionDirection=vt,this._moveLeft(t,"selectionStart")):void 0}moveCursorRight(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorLeftOrRight("Right",t)}_moveCursorLeftOrRight(t,e){const s="moveCursor".concat(t).concat(e.shiftKey?"WithShift":"WithoutShift");this._currentCursorOpacity=1,this[s](e)&&(this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())}moveCursorRightWithShift(t){return this._selectionDirection===vt&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection=Ut,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=Ut,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}const zg=a=>!!a.button;class Fw extends Lw{constructor(){super(...arguments),T(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 Dw(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),fg(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&&!zg(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&&!zg(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||zg(e)||i||(this.__lastSelected&&!this.getActiveControl()?(this.selected=!1,this.__lastSelected=!1,this.enterEditing(e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection()):this.selected=!0)}setCursorByClick(t){const e=this.getSelectionStartFromPointer(t),s=this.selectionStart,i=this.selectionEnd;t.shiftKey?this.setSelectionStartEndWithShift(s,i,e):(this.selectionStart=e,this.selectionEnd=e),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())}getSelectionStartFromPointer(t){const e=this.canvas.getScenePoint(t).transform(Ze(this.calcTransformMatrix())).add(new O(-this._getLeftOffset(),-this._getTopOffset()));let s=0,i=0,n=0;for(let c=0;c<this._textLines.length&&s<=e.y;c++)s+=this.getHeightOfLine(c),n=c,c>0&&(i+=this._textLines[c-1].length+this.missingNewlineOffset(c-1));let r=Math.abs(this._getLineLeftOffset(n));const o=this._textLines[n].length,h=this.__charBounds[n];for(let c=0;c<o;c++){const u=r+h[c].kernedWidth;if(e.x<=u){Math.abs(e.x-u)<=Math.abs(e.x-r)&&i++;break}r=u,i++}return Math.min(this.flipX?o-i:i,this._text.length)}}const pu="moveCursorUp",mu="moveCursorDown",vu="moveCursorLeft",bu="moveCursorRight",yu="exitEditing",Iw=E({selectionStart:0,selectionEnd:0,selectionColor:"rgba(17,119,255,0.3)",isEditing:!1,editable:!0,editingBorderColor:"rgba(102,153,255,0.25)",cursorWidth:2,cursorColor:"",cursorDelay:1e3,cursorDuration:600,caching:!0,hiddenTextareaContainer:null,keysMap:{9:yu,27:yu,33:pu,34:mu,35:bu,36:vu,37:vu,38:pu,39:bu,40:mu},keysMapRtl:{9:yu,27:yu,33:pu,34:mu,35:vu,36:bu,37:bu,38:pu,39:vu,40:mu},ctrlKeysMapDown:{65:"selectAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}},{_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1});class tn extends Fw{static getDefaults(){return E(E({},super.getDefaults()),tn.ownDefaults)}get type(){const t=super.type;return t==="itext"?"i-text":t}constructor(t,e){super(t,E(E({},tn.ownDefaults),e)),this.initBehavior()}_set(t,e){return this.isEditing&&this._savedProps&&t in this._savedProps?(this._savedProps[t]=e,this):(t==="canvas"&&(this.canvas instanceof Bg&&this.canvas.textEditingManager.remove(this),e instanceof Bg&&e.textEditingManager.add(this)),super._set(t,e))}setSelectionStart(t){t=Math.max(t,0),this._updateAndFire("selectionStart",t)}setSelectionEnd(t){t=Math.min(t,this.text.length),this._updateAndFire("selectionEnd",t)}_updateAndFire(t,e){this[t]!==e&&(this._fireSelectionChanged(),this[t]=e),this._updateTextarea()}_fireSelectionChanged(){this.fire("selection:changed"),this.canvas&&this.canvas.fire("text:selection:changed",{target:this})}initDimensions(){this.isEditing&&this.initDelayedCursor(),super.initDimensions()}getSelectionStyles(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart||0,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionEnd,s=arguments.length>2?arguments[2]:void 0;return super.getSelectionStyles(t,e,s)}setSelectionStyles(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionStart||0,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.selectionEnd;return super.setSelectionStyles(t,e,s)}get2DCursorLocation(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;return super.get2DCursorLocation(t,e)}render(t){super.render(t),this.cursorOffsetCache={},this.renderCursorOrSelection()}toCanvasElement(t){const e=this.isEditing;this.isEditing=!1;const s=super.toCanvasElement(t);return this.isEditing=e,s}renderCursorOrSelection(){if(!this.isEditing)return;const t=this.clearContextTop(!0);if(!t)return;const e=this._getCursorBoundaries();this.selectionStart!==this.selectionEnd||this.inCompositionMode?this.renderSelection(t,e):this.renderCursor(t,e),this.canvas.contextTopDirty=!0,t.restore()}_getCursorBoundaries(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;const s=this._getLeftOffset(),i=this._getTopOffset(),n=this._getCursorBoundariesOffsets(t,e);return{left:s,top:i,leftOffset:n.left,topOffset:n.top}}_getCursorBoundariesOffsets(t,e){return e?this.__getCursorBoundariesOffsets(t):this.cursorOffsetCache&&"top"in this.cursorOffsetCache?this.cursorOffsetCache:this.cursorOffsetCache=this.__getCursorBoundariesOffsets(t)}__getCursorBoundariesOffsets(t){let e=0,s=0;const{charIndex:i,lineIndex:n}=this.get2DCursorLocation(t);for(let c=0;c<n;c++)e+=this.getHeightOfLine(c);const r=this._getLineLeftOffset(n),o=this.__charBounds[n][i];o&&(s=o.left),this.charSpacing!==0&&i===this._textLines[n].length&&(s-=this._getWidthOfCharSpacing());const h={top:e,left:r+(s>0?s:0)};return this.direction==="rtl"&&(this.textAlign===Ut||this.textAlign===wi||this.textAlign===Hh?h.left*=-1:this.textAlign===vt||this.textAlign===fu?h.left=r-(s>0?s:0):this.textAlign!==tt&&this.textAlign!==Vh||(h.left=r-(s>0?s:0))),h}renderCursorAt(t){this._renderCursor(this.canvas.contextTop,this._getCursorBoundaries(t,!0),t)}renderCursor(t,e){this._renderCursor(t,e,this.selectionStart)}getCursorRenderingData(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this._getCursorBoundaries(t);const s=this.get2DCursorLocation(t),i=s.lineIndex,n=s.charIndex>0?s.charIndex-1:0,r=this.getValueOfPropertyAt(i,n,"fontSize"),o=this.getObjectScaling().x*this.canvas.getZoom(),h=this.cursorWidth/o,c=this.getValueOfPropertyAt(i,n,"deltaY"),u=e.topOffset+(1-this._fontSizeFraction)*this.getHeightOfLine(i)/this.lineHeight-r*(1-this._fontSizeFraction);return{color:this.cursorColor||this.getValueOfPropertyAt(i,n,"fill"),opacity:this._currentCursorOpacity,left:e.left+e.leftOffset-h/2,top:u+e.top+c,width:h,height:r}}_renderCursor(t,e,s){const{color:i,opacity:n,left:r,top:o,width:h,height:c}=this.getCursorRenderingData(s,e);t.fillStyle=i,t.globalAlpha=n,t.fillRect(r,o,h,c)}renderSelection(t,e){const s={selectionStart:this.inCompositionMode?this.hiddenTextarea.selectionStart:this.selectionStart,selectionEnd:this.inCompositionMode?this.hiddenTextarea.selectionEnd:this.selectionEnd};this._renderSelection(t,s,e)}renderDragSourceEffect(){const t=this.draggableTextDelegate.getDragStartSelection();this._renderSelection(this.canvas.contextTop,t,this._getCursorBoundaries(t.selectionStart,!0))}renderDropTargetEffect(t){const e=this.getSelectionStartFromPointer(t);this.renderCursorAt(e)}_renderSelection(t,e,s){const i=e.selectionStart,n=e.selectionEnd,r=this.textAlign.includes(wi),o=this.get2DCursorLocation(i),h=this.get2DCursorLocation(n),c=o.lineIndex,u=h.lineIndex,d=o.charIndex<0?0:o.charIndex,g=h.charIndex<0?0:h.charIndex;for(let f=c;f<=u;f++){const p=this._getLineLeftOffset(f)||0;let m=this.getHeightOfLine(f),y=0,b=0,x=0;if(f===c&&(b=this.__charBounds[c][d].left),f>=c&&f<u)x=r&&!this.isEndOfWrapping(f)?this.width:this.getLineWidth(f)||5;else if(f===u)if(g===0)x=this.__charBounds[u][g].left;else{const k=this._getWidthOfCharSpacing();x=this.__charBounds[u][g-1].left+this.__charBounds[u][g-1].width-k}y=m,(this.lineHeight<1||f===u&&this.lineHeight>1)&&(m/=this.lineHeight);let C=s.left+p+b,A=m,M=0;const D=x-b;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",A=1,M=m):t.fillStyle=this.selectionColor,this.direction==="rtl"&&(this.textAlign===Ut||this.textAlign===wi||this.textAlign===Hh?C=this.width-C-D:this.textAlign===vt||this.textAlign===fu?C=s.left+p-x:this.textAlign!==tt&&this.textAlign!==Vh||(C=s.left+p-x)),t.fillRect(C,s.top+s.topOffset+M,D,A),s.topOffset+=y}}getCurrentCharFontSize(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,"fontSize")}getCurrentCharColor(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,Jt)}_getCurrentCharIndex(){const t=this.get2DCursorLocation(this.selectionStart,!0),e=t.charIndex>0?t.charIndex-1:0;return{l:t.lineIndex,c:e}}dispose(){this.exitEditingImpl(),this.draggableTextDelegate.dispose(),super.dispose()}}T(tn,"ownDefaults",Iw),T(tn,"type","IText"),W.setClass(tn),W.setClass(tn,"i-text");class Lr extends tn{static getDefaults(){return E(E({},super.getDefaults()),Lr.ownDefaults)}constructor(t,e){super(t,E(E({},Lr.ownDefaults),e))}static createControls(){return{controls:__()}}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(wi)&&this.enlargeSpaces(),this.height=this.calcTextHeight())}_generateStyleMap(t){let e=0,s=0,i=0;const n={};for(let r=0;r<t.graphemeLines.length;r++)t.graphemeText[i]===`
|
|
86
|
+
`&&r>0?(s=0,i++,e++):!this.splitByGrapheme&&this._reSpaceAndTab.test(t.graphemeText[i])&&r>0&&(s++,i++),n[r]={line:e,offset:s},i+=t.graphemeLines[r].length,s+=t.graphemeLines[r].length;return n}styleHas(t,e){if(this._styleMap&&!this.isWrapping){const s=this._styleMap[e];s&&(e=s.line)}return super.styleHas(t,e)}isEmptyStyles(t){if(!this.styles)return!0;let e,s=0,i=t+1,n=!1;const r=this._styleMap[t],o=this._styleMap[t+1];r&&(t=r.line,s=r.offset),o&&(i=o.line,n=i===t,e=o.offset);const h=t===void 0?this.styles:{line:this.styles[t]};for(const c in h)for(const u in h[c]){const d=parseInt(u,10);if(d>=s&&(!n||d<e))for(const g in h[c][u])return!1}return!0}_getStyleDeclaration(t,e){if(this._styleMap&&!this.isWrapping){const s=this._styleMap[t];if(!s)return{};t=s.line,e=s.offset+e}return super._getStyleDeclaration(t,e)}_setStyleDeclaration(t,e,s){const i=this._styleMap[t];super._setStyleDeclaration(i.line,i.offset+e,s)}_deleteStyleDeclaration(t,e){const s=this._styleMap[t];super._deleteStyleDeclaration(s.line,s.offset+e)}_getLineStyle(t){const e=this._styleMap[t];return!!this.styles[e.line]}_setLineStyle(t){const e=this._styleMap[t];super._setLineStyle(e.line)}_wrapText(t,e){this.isWrapping=!0;const s=this.getGraphemeDataForRender(t),i=[];for(let n=0;n<s.wordsData.length;n++)i.push(...this._wrapLine(n,e,s));return this.isWrapping=!1,i}getGraphemeDataForRender(t){const e=this.splitByGrapheme,s=e?"":" ";let i=0;return{wordsData:t.map((n,r)=>{let o=0;const h=e?this.graphemeSplit(n):this.wordSplit(n);return h.length===0?[{word:[],width:0}]:h.map(c=>{const u=e?[c]:this.graphemeSplit(c),d=this._measureWord(u,r,o);return i=Math.max(d,i),o+=u.length+s.length,{word:u,width:d}})}),largestWordWidth:i}}_measureWord(t,e){let s,i=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,n=0;for(let r=0,o=t.length;r<o;r++)n+=this._getGraphemeBox(t[r],e,r+i,s,!0).kernedWidth,s=t[r];return n}wordSplit(t){return t.split(this._wordJoiners)}_wrapLine(t,e,s){let{largestWordWidth:i,wordsData:n}=s,r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:0;const o=this._getWidthOfCharSpacing(),h=this.splitByGrapheme,c=[],u=h?"":" ";let d=0,g=[],f=0,p=0,m=!0;e-=r;const y=Math.max(e,i,this.dynamicMinWidth),b=n[t];let x;for(f=0,x=0;x<b.length;x++){const{word:C,width:A}=b[x];f+=C.length,d+=p+A-o,d>y&&!m?(c.push(g),g=[],d=A,m=!0):d+=o,m||h||g.push(u),g=g.concat(C),p=h?0:this._measureWord([u],t,f),f++,m=!1}return x&&c.push(g),i+r>this.dynamicMinWidth&&(this.dynamicMinWidth=i-o+r),c}isEndOfWrapping(t){return!this._styleMap[t+1]||this._styleMap[t+1].line!==this._styleMap[t].line}missingNewlineOffset(t,e){return this.splitByGrapheme&&!e?this.isEndOfWrapping(t)?1:0:1}_splitTextIntoLines(t){const e=super._splitTextIntoLines(t),s=this._wrapText(e.lines,this.width),i=new Array(s.length);for(let n=0;n<s.length;n++)i[n]=s[n].join("");return e.lines=i,e.graphemeLines=s,e}getMinWidth(){return Math.max(this.minWidth,this.dynamicMinWidth)}_removeExtraneousStyles(){const t=new Map;for(const e in this._styleMap){const s=parseInt(e,10);if(this._textLines[s]){const i=this._styleMap[e].line;t.set("".concat(i),!0)}}for(const e in this.styles)t.has(e)||delete this.styles[e]}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject(["minWidth","splitByGrapheme",...t])}}T(Lr,"type","Textbox"),T(Lr,"textLayoutProperties",[...tn.textLayoutProperties,"width"]),T(Lr,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),W.setClass(Lr);class B0 extends hu{shouldPerformLayout(t){return!!t.target.clipPath&&super.shouldPerformLayout(t)}shouldLayoutClipPath(){return!1}calcLayoutResult(t,e){const{target:s}=t,{clipPath:i,group:n}=s;if(!i||!this.shouldPerformLayout(t))return;const{width:r,height:o}=bi(l0(s,i)),h=new O(r,o);if(i.absolutePositioned)return{center:Mr(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}}}}T(B0,"type","clip-path"),W.setClass(B0);class H0 extends hu{getInitialSize(t,e){let{target:s}=t,{size:i}=e;return new O(s.width||i.x,s.height||i.y)}}T(H0,"type","fixed"),W.setClass(H0);class jw extends jh{subscribeTargets(t){const e=t.target;t.targets.reduce((s,i)=>(i.parent&&s.add(i.parent),s),new Set).forEach(s=>{s.layoutManager.subscribeTargets({target:s,targets:[e]})})}unsubscribeTargets(t){const e=t.target,s=e.getObjects();t.targets.reduce((i,n)=>(n.parent&&i.add(n.parent),i),new Set).forEach(i=>{!s.some(n=>n.parent===i)&&i.layoutManager.unsubscribeTargets({target:i,targets:[e]})})}}class Fr extends _i{static getDefaults(){return E(E({},super.getDefaults()),Fr.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),Object.assign(this,Fr.ownDefaults),this.setOptions(e);const{left:s,top:i,layoutManager:n}=e;this.groupInit(t,{left:s,top:i,layoutManager:n??new jw})}_shouldSetNestedCoords(){return!0}__objectSelectionMonitor(){}multiSelectAdd(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];this.multiSelectionStacking==="selection-order"?this.add(...e):e.forEach(i=>{const n=this._objects.findIndex(o=>o.isInFrontOf(i)),r=n===-1?this.size():n;this.insertAt(r,i)})}canEnterGroup(t){return this.getObjects().some(e=>e.isDescendantOf(t)||t.isDescendantOf(e))?(Xi("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(ou,e)}):s.forEach(i=>{i._set("dirty",!0)})}onDeselect(){return this.removeAll(),!1}toString(){return"#<ActiveSelection: (".concat(this.complexity(),")>")}shouldCache(){return!1}isOnACache(){return!1}_renderControls(t,e,s){t.save(),t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1;const i=E(E({hasControls:!1},s),{},{forActiveSelection:!0});for(let n=0;n<this._objects.length;n++)this._objects[n]._renderControls(t,i);super._renderControls(t,e),t.restore()}}T(Fr,"type","ActiveSelection"),T(Fr,"ownDefaults",{multiSelectionStacking:"canvas-stacking"}),W.setClass(Fr),W.setClass(Fr,"activeSelection");class Nw{constructor(){T(this,"resources",{})}applyFilters(t,e,s,i,n){const r=n.getContext("2d");if(!r)return;r.drawImage(e,0,0,s,i);const o={sourceWidth:s,sourceHeight:i,imageData:r.getImageData(0,0,s,i),originalEl:e,originalImageData:r.getImageData(0,0,s,i),canvasEl:n,ctx:r,filterBackend:this};t.forEach(c=>{c.applyTo(o)});const{imageData:h}=o;return h.width===s&&h.height===i||(n.width=h.width,n.height=h.height),r.putImageData(h,0,0),o}}class V0{constructor(){let{tileSize:t=dt.textureSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};T(this,"aPosition",new Float32Array([0,0,0,1,1,0,1,1])),T(this,"resources",{}),this.tileSize=t,this.setupGLContext(t,t),this.captureGPUInfo()}setupGLContext(t,e){this.dispose(),this.createWebGLCanvas(t,e)}createWebGLCanvas(t,e){const s=Xs({width:t,height:e}),i=s.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,depth:!1,stencil:!1,antialias:!1});i&&(i.clearColor(0,0,0,0),this.canvas=s,this.gl=i)}applyFilters(t,e,s,i,n,r){const o=this.gl,h=n.getContext("2d");if(!o||!h)return;let c;r&&(c=this.getCachedTexture(r,e));const u={originalWidth:e.width||e.originalWidth||0,originalHeight:e.height||e.originalHeight||0,sourceWidth:s,sourceHeight:i,destinationWidth:s,destinationHeight:i,context:o,sourceTexture:this.createTexture(o,s,i,c?void 0:e),targetTexture:this.createTexture(o,s,i),originalTexture:c||this.createTexture(o,s,i,c?void 0:e),passes:t.length,webgl:!0,aPosition:this.aPosition,programCache:this.programCache,pass:0,filterBackend:this,targetCanvas:n},d=o.createFramebuffer();return o.bindFramebuffer(o.FRAMEBUFFER,d),t.forEach(g=>{g&&g.applyTo(u)}),function(g){const f=g.targetCanvas,p=f.width,m=f.height,y=g.destinationWidth,b=g.destinationHeight;p===y&&m===b||(f.width=y,f.height=b)}(u),this.copyGLTo2D(o,u),o.bindTexture(o.TEXTURE_2D,null),o.deleteTexture(u.sourceTexture),o.deleteTexture(u.targetTexture),o.deleteFramebuffer(d),h.setTransform(1,0,0,1,0,0),u}dispose(){this.canvas&&(this.canvas=null,this.gl=null),this.clearWebGLCaches()}clearWebGLCaches(){this.programCache={},this.textureCache={}}createTexture(t,e,s,i,n){const{NEAREST:r,TEXTURE_2D:o,RGBA:h,UNSIGNED_BYTE:c,CLAMP_TO_EDGE:u,TEXTURE_MAG_FILTER:d,TEXTURE_MIN_FILTER:g,TEXTURE_WRAP_S:f,TEXTURE_WRAP_T:p}=t,m=t.createTexture();return t.bindTexture(o,m),t.texParameteri(o,d,n||r),t.texParameteri(o,g,n||r),t.texParameteri(o,f,u),t.texParameteri(o,p,u),i?t.texImage2D(o,0,h,h,c,i):t.texImage2D(o,0,h,e,s,0,h,c,null),m}getCachedTexture(t,e,s){const{textureCache:i}=this;if(i[t])return i[t];{const n=this.createTexture(this.gl,e.width,e.height,e,s);return n&&(i[t]=n),n}}evictCachesForKey(t){this.textureCache[t]&&(this.gl.deleteTexture(this.textureCache[t]),delete this.textureCache[t])}copyGLTo2D(t,e){const s=t.canvas,i=e.targetCanvas,n=i.getContext("2d");if(!n)return;n.translate(0,i.height),n.scale(1,-1);const r=s.height-i.height;n.drawImage(s,0,r,i.width,i.height,0,0,i.width,i.height)}copyGLTo2DPutImageData(t,e){const s=e.targetCanvas.getContext("2d"),i=e.destinationWidth,n=e.destinationHeight,r=i*n*4;if(!s)return;const o=new Uint8Array(this.imageBuffer,0,r),h=new Uint8ClampedArray(this.imageBuffer,0,r);t.readPixels(0,0,i,n,t.RGBA,t.UNSIGNED_BYTE,o);const c=new ImageData(h,i,n);s.putImageData(c,0,0)}captureGPUInfo(){if(this.gpuInfo)return this.gpuInfo;const t=this.gl,e={renderer:"",vendor:""};if(!t)return e;const s=t.getExtension("WEBGL_debug_renderer_info");if(s){const i=t.getParameter(s.UNMASKED_RENDERER_WEBGL),n=t.getParameter(s.UNMASKED_VENDOR_WEBGL);i&&(e.renderer=i.toLowerCase()),n&&(e.vendor=n.toLowerCase())}return this.gpuInfo=e,e}}let Xg;function Bw(){const{WebGLProbe:a}=vi();return a.queryWebGL(As()),dt.enableGLFiltering&&a.isSupported(dt.textureSize)?new V0({tileSize:dt.textureSize}):new Nw}function Ug(){return!Xg&&(!(arguments.length>0&&arguments[0]!==void 0)||arguments[0])&&(Xg=Bw()),Xg}const Hw=["filters","resizeFilter","src","crossOrigin","type"],G0=["cropX","cropY"];class Te extends Ce{static getDefaults(){return E(E({},super.getDefaults()),Te.ownDefaults)}constructor(t,e){super(),T(this,"_lastScaleX",1),T(this,"_lastScaleY",1),T(this,"_filterScalingX",1),T(this,"_filterScalingY",1),this.filters=[],Object.assign(this,Te.ownDefaults),this.setOptions(e),this.cacheKey="texture".concat(Bn()),this.setElement(typeof t=="string"?(this.canvas&&Us(this.canvas.getElement())||Xo()).getElementById(t):t,e)}getElement(){return this._element}setElement(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._element=t,this._originalElement=t,this._setWidthHeight(e),t.classList.add(Te.CSS_CANVAS),this.filters.length!==0&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){const e=Ug(!1);e instanceof V0&&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&&vi().dispose(e),this[t]=void 0})}getCrossOrigin(){return this._originalElement&&(this._originalElement.crossOrigin||null)}getOriginalSize(){const t=this.getElement();return t?{width:t.naturalWidth||t.width,height:t.naturalHeight||t.height}:{width:0,height:0}}_stroke(t){if(!this.stroke||this.strokeWidth===0)return;const e=this.width/2,s=this.height/2;t.beginPath(),t.moveTo(-e,-s),t.lineTo(e,-s),t.lineTo(e,s),t.lineTo(-e,s),t.lineTo(-e,-s),t.closePath()}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=[];return this.filters.forEach(s=>{s&&e.push(s.toObject())}),E(E({},super.toObject([...G0,...t])),{},{src:this.getSrc(),crossOrigin:this.getCrossOrigin(),filters:e},this.resizeFilter?{resizeFilter:this.resizeFilter.toObject()}:{})}hasCrop(){return!!this.cropX||!!this.cropY||this.width<this._element.width||this.height<this._element.height}_toSVG(){const t=[],e=this._element,s=-this.width/2,i=-this.height/2;let n=[],r=[],o="",h="";if(!e)return[];if(this.hasCrop()){const c=Bn();n.push('<clipPath id="imageCrop_'+c+`">
|
|
87
87
|
`,' <rect x="'+s+'" y="'+i+'" width="'+this.width+'" height="'+this.height+`" />
|
|
88
88
|
`,`</clipPath>
|
|
89
|
-
`),
|
|
90
|
-
`)),this.stroke||this.strokeDashArray){const
|
|
91
|
-
`)],this.fill=l}return n=this.paintFirst!==$t?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 mh(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=Is(r),{width:h,height:l}=r;this._element=a,this._lastScaleX=t.scaleX=i,this._lastScaleY=t.scaleY=n,Og().applyFilters([t],r,h,l,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=Is({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);Og().applyFilters(t,this._originalElement,s,i,this._element),this._originalElement.width===this._element.width&&this._originalElement.height===this._element.height||(this._filterScalingX=this._element.width/this._originalElement.width,this._filterScalingY=this._element.height/this._originalElement.height)}_render(t){t.imageSmoothingEnabled=this.imageSmoothing,this.isMoving!==!0&&this.resizeFilter&&this._needsResize()&&this.applyResizeFilters(),this._stroke(t),this._renderPaintInOrder(t)}drawCacheOnCanvas(t){t.imageSmoothingEnabled=this.imageSmoothing,super.drawCacheOnCanvas(t)}shouldCache(){return this.needsItsOwnCache()}_renderFill(t){const e=this._element;if(!e)return;const s=this._filterScalingX,i=this._filterScalingY,n=this.width,r=this.height,a=Math.max(this.cropX,0),h=Math.max(this.cropY,0),l=e.naturalWidth||e.width,u=e.naturalHeight||e.height,d=a*s,g=h*i,f=Math.min(n*s,l-d),p=Math.min(r*i,u-g),m=-n/2,_=-r/2,b=Math.min(n,l/s-a),x=Math.min(r,u/i-h);e&&t.drawImage(e,d,g,f,p,m,_,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=Kd(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,l=1,u=0,d=0,g=0,f=0;return!t||t.alignX===Re&&t.alignY===Re?(h=e/r,l=s/a):(t.meetOrSlice==="meet"&&(h=l=Zm(this._element,i),n=(e-r*h)/2,t.alignX==="Min"&&(u=-n),t.alignX==="Max"&&(u=n),n=(s-a*l)/2,t.alignY==="Min"&&(d=-n),t.alignY==="Max"&&(d=n)),t.meetOrSlice==="slice"&&(h=l=t0(this._element,i),n=r-e/h,t.alignX==="Mid"&&(g=n/2),t.alignX==="Max"&&(g=n),n=a-s/l,t.alignY==="Mid"&&(f=n/2),t.alignY==="Max"&&(f=n),r=e/h,a=s/l)),{width:r,height:a,scaleX:h,scaleY:l,offsetLeft:u,offsetTop:d,cropX:g,cropY:f}}static fromObject(t,e){let{filters:s,resizeFilter:i,src:n,crossOrigin:r,type:a}=t,h=Pt(t,Nw);return Promise.all([mh(n,E(E({},e),{},{crossOrigin:r})),s&&za(s,e),i&&za([i],e),vh(h,e)]).then(l=>{let[u,d=[],[g]=[],f={}]=l;return new this(u,E(E({},h),{},{src:n,filters:d,resizeFilter:g},f))})}static fromURL(t){let{crossOrigin:e=null,signal:s}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;return mh(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=Ii(t,this.ATTRIBUTE_NAMES,s);return this.fromURL(i["xlink:href"],e,i).catch(n=>(Pi("log","Unable to parse Image",n),null))}}function Pg(o){if(!zy.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"),l=o.getAttribute("height"),u=o.getAttribute("x")||0,d=o.getAttribute("y")||0,g=!(t&&vm.test(t)),f=!h||!l||h==="100%"||l==="100%";let p="",m=0,_=0;if(g&&(u||d)&&o.parentNode&&o.parentNode.nodeName!=="#document"&&(p=" translate("+Ie(u||"0")+" "+Ie(d||"0")+") ",e=(o.getAttribute("transform")||"")+p,o.setAttribute("transform",e),o.removeAttribute("x"),o.removeAttribute("y")),g&&f)return{width:0,height:0};const b={width:0,height:0};if(g)return b.width=Ie(h),b.height=Ie(l),b;const x=t.match(vm);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,f?(b.width=S,b.height=A):(b.width=Ie(h),b.height=Ie(l),i=b.width/S,n=b.height/A);const k=Kd(o.getAttribute("preserveAspectRatio")||"");if(k.alignX!==Re&&(k.meetOrSlice==="meet"&&(n=i=i>n?n:i),k.meetOrSlice==="slice"&&(n=i=i>n?i:n),m=b.width-S*i,_=b.height-A*i,k.alignX==="Mid"&&(m/=2),k.alignY==="Mid"&&(_/=2),k.alignX==="Min"&&(m=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("+Ie(u||"0")+" "+Ie(d||"0")+") "),e=p+" matrix("+i+" 0 0 "+n+" "+(r*i+m)+" "+(a*n+_)+") ",o.nodeName==="svg"){for(s=o.ownerDocument.createElementNS(sg,"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}T(Ce,"type","Image"),T(Ce,"cacheProperties",[...Fi,...O0]),T(Ce,"ownDefaults",{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),T(Ce,"CSS_CANVAS","canvas-img"),T(Ce,"ATTRIBUTE_NAMES",[...Mn,"x","y","width","height","preserveAspectRatio","xlink:href","crossOrigin","image-rendering"]),V.setClass(Ce),V.setSVGClass(Ce);const nu=o=>o.tagName.replace("svg:",""),Bw=Rc(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);function P0(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 Hw=["gradientTransform","x1","x2","y1","y2","gradientUnits","cx","cy","r","fx","fy"],Dg="xlink:href";function D0(o,t){var e;const s=((e=t.getAttribute(Dg))===null||e===void 0?void 0:e.slice(1))||"",i=o.getElementById(s);if(i&&i.getAttribute(Dg)&&D0(o,i),i&&(Hw.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(Dg)}const Ww=["linearGradient","radialGradient","svg:linearGradient","svg:radialGradient"];function Xw(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={},l=a[1].trim().split(";").filter(function(u){return u.trim()});for(e=0,s=l.length;e<s;e++){const u=l[e].split(":"),d=u[0].trim(),g=u[1].trim();h[d]=g}(r=a[0].trim()).split(",").forEach(u=>{(u=u.replace(/^svg/i,"").trim())!==""&&(i[u]=E(E({},i[u]||{}),h))})})}return i}const R0=o=>V.getSVGClass(nu(o).toLowerCase());class zw{constructor(t,e,s,i,n){this.elements=t,this.options=e,this.reviver=s,this.regexUrl=/^url\(['"]?#([^'"]+)['"]?\)/g,this.doc=i,this.clipPaths=n,this.gradientDefs=function(r){const a=P0(r,Ww),h={};let l=a.length;for(;l--;){const u=a[l];u.getAttribute("xlink:href")&&D0(r,u);const d=u.getAttribute("id");d&&(h[d]=u)}return h}(i),this.cssRules=Xw(i)}parse(){return Promise.all(this.elements.map(t=>this.createObject(t)))}async createObject(t){const e=R0(t);if(e){const s=await e.fromElement(t,this.options,this.cssRules);return this.resolveGradient(s,t,$t),this.resolveGradient(s,t,Le),s instanceof Ce&&s._originalElement?$c(s,s.parsePreserveAspectRatioAttribute()):$c(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=Th.fromElement(i,t,E(E({},this.options),{},{opacity:n}));t.set(s,r)}}async resolveClipPath(t,e,s){const i=this.extractPropertyDefinition(t,"clipPath",this.clipPaths);if(i){const n=qe(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=zc("".concat(a.getAttribute("transform")||""," ").concat(r.getAttribute("originalTransform")||""));r.setAttribute("transform","matrix(".concat(h.join(","),")"));const l=await Promise.all(i.map(x=>R0(x).fromElement(x,this.options,this.cssRules).then(S=>($c(S),S.fillRule=S.clipRule,delete S.clipRule,S)))),u=l.length===1?l[0]:new ci(l),d=Gt(n,u.calcTransformMatrix());u.clipPath&&await this.resolveClipPath(u,a,r.getAttribute("clip-path")?a:void 0);const{scaleX:g,scaleY:f,angle:p,skewX:m,translateX:_,translateY:b}=pr(d);u.set({flipX:!1,flipY:!1}),u.set({scaleX:g,scaleY:f,angle:p,skewX:m,skewY:0}),u.setPositionByOrigin(new D(_,b),st,st),t.clipPath=u}else delete t.clipPath}}const F0=o=>Xy.test(nu(o)),Rg=()=>({objects:[],elements:[],options:{},allElements:[]});async function Vw(o,t){let{crossOrigin:e,signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(s&&s.aborted)return Pi("log",new Id("parseSVGDocument")),Rg();const i=o.documentElement;(function(u){const d=P0(u,["use","svg:use"]),g=["x","y","xlink:href","href","transform"];for(const f of d){const p=f.attributes,m={};for(const R of p)R.value&&(m[R.name]=R.value);const _=(m["xlink:href"]||m.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:P=0,transform:M=""}=m,O="".concat(M," ").concat(A.transform||""," translate(").concat(k,", ").concat(P,")");if(Pg(x),/^svg$/i.test(x.nodeName)){const R=x.ownerDocument.createElementNS(sg,"g");Object.entries(A).forEach(I=>{let[j,G]=I;return R.setAttributeNS(sg,j,G)}),R.append(...x.childNodes),x=R}for(const R of p){if(!R)continue;const{name:I,value:j}=R;if(!g.includes(I))if(I==="style"){const G={};vg(j,G),Object.entries(A).forEach(H=>{let[$,J]=H;G[$]=J}),vg(A.style||"",G);const L=Object.entries(G).map(H=>H.join(":")).join(";");x.setAttribute(I,L)}else!A[I]&&x.setAttribute(I,j)}x.setAttribute("transform",O),x.setAttribute("instantiated_by_use","1"),x.removeAttribute("id"),f.parentNode.replaceChild(x,f)}})(o);const n=Array.from(i.getElementsByTagName("*")),r=E(E({},Pg(i)),{},{crossOrigin:e,signal:s}),a=n.filter(u=>(Pg(u),F0(u)&&!function(d){let g=d;for(;g&&(g=g.parentElement);)if(g&&g.nodeName&&Bw.test(nu(g))&&!g.getAttribute("instantiated_by_use"))return!0;return!1}(u)));if(!a||a&&!a.length)return E(E({},Rg()),{},{options:r,allElements:n});const h={};return n.filter(u=>nu(u)==="clipPath").forEach(u=>{u.setAttribute("originalTransform",u.getAttribute("transform")||"");const d=u.getAttribute("id");h[d]=Array.from(u.getElementsByTagName("*")).filter(g=>F0(g))}),{objects:await new zw(a,r,t,o,h).parse(),elements:a,options:r,allElements:n}}function Gw(o,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return new Promise((s,i)=>{d0(o.replace(/^\n\s*/,"").trim(),{onComplete:n=>{const r=n.responseXML;r&&s(r),i()},signal:e.signal})}).then(s=>Vw(s,t,e)).catch(()=>Rg())}const ru=o=>o.webgl!==void 0,Fg="precision highp float",Yw=`
|
|
92
|
-
`.concat(
|
|
89
|
+
`),o=' clip-path="url(#imageCrop_'+c+')" '}if(this.imageSmoothing||(h=' image-rendering="optimizeSpeed"'),t.push(" <image ","COMMON_PARTS",'xlink:href="'.concat(this.getSvgSrc(!0),'" x="').concat(s-this.cropX,'" y="').concat(i-this.cropY,'" width="').concat(e.width||e.naturalWidth,'" height="').concat(e.height||e.naturalHeight,'"').concat(h).concat(o,`></image>
|
|
90
|
+
`)),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!==Jt?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 Mh(t,{crossOrigin:e,signal:s}).then(i=>{e!==void 0&&this.set({crossOrigin:e}),this.setElement(i)})}toString(){return'#<Image: { src: "'.concat(this.getSrc(),'" }>')}applyResizeFilters(){const t=this.resizeFilter,e=this.minimumScaleTrigger,s=this.getTotalObjectScaling(),i=s.x,n=s.y,r=this._filteredEl||this._originalElement;if(this.group&&this.set("dirty",!0),!t||i>e&&n>e)return this._element=r,this._filterScalingX=1,this._filterScalingY=1,this._lastScaleX=i,void(this._lastScaleY=n);const o=Xs(r),{width:h,height:c}=r;this._element=o,this._lastScaleX=t.scaleX=i,this._lastScaleY=t.scaleY=n,Ug().applyFilters([t],r,h,c,this._element),this._filterScalingX=o.width/this._originalElement.width,this._filterScalingY=o.height/this._originalElement.height}applyFilters(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.filters||[];if(t=t.filter(n=>n&&!n.isNeutralState()),this.set("dirty",!0),this.removeTexture("".concat(this.cacheKey,"_filtered")),t.length===0)return this._element=this._originalElement,this._filteredEl=void 0,this._filterScalingX=1,void(this._filterScalingY=1);const e=this._originalElement,s=e.naturalWidth||e.width,i=e.naturalHeight||e.height;if(this._element===this._originalElement){const n=Xs({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);Ug().applyFilters(t,this._originalElement,s,i,this._element),this._originalElement.width===this._element.width&&this._originalElement.height===this._element.height||(this._filterScalingX=this._element.width/this._originalElement.width,this._filterScalingY=this._element.height/this._originalElement.height)}_render(t){t.imageSmoothingEnabled=this.imageSmoothing,this.isMoving!==!0&&this.resizeFilter&&this._needsResize()&&this.applyResizeFilters(),this._stroke(t),this._renderPaintInOrder(t)}drawCacheOnCanvas(t){t.imageSmoothingEnabled=this.imageSmoothing,super.drawCacheOnCanvas(t)}shouldCache(){return this.needsItsOwnCache()}_renderFill(t){const e=this._element;if(!e)return;const s=this._filterScalingX,i=this._filterScalingY,n=this.width,r=this.height,o=Math.max(this.cropX,0),h=Math.max(this.cropY,0),c=e.naturalWidth||e.width,u=e.naturalHeight||e.height,d=o*s,g=h*i,f=Math.min(n*s,c-d),p=Math.min(r*i,u-g),m=-n/2,y=-r/2,b=Math.min(n,c/s-o),x=Math.min(r,u/i-h);e&&t.drawImage(e,d,g,f,p,m,y,b,x)}_needsResize(){const t=this.getTotalObjectScaling();return t.x!==this._lastScaleX||t.y!==this._lastScaleY}_resetWidthHeight(){this.set(this.getOriginalSize())}_setWidthHeight(){let{width:t,height:e}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const s=this.getOriginalSize();this.width=t||s.width,this.height=e||s.height}parsePreserveAspectRatioAttribute(){const t=dg(this.preserveAspectRatio||""),e=this.width,s=this.height,i={width:e,height:s};let n,r=this._element.width,o=this._element.height,h=1,c=1,u=0,d=0,g=0,f=0;return!t||t.alignX===Ie&&t.alignY===Ie?(h=e/r,c=s/o):(t.meetOrSlice==="meet"&&(h=c=u0(this._element,i),n=(e-r*h)/2,t.alignX==="Min"&&(u=-n),t.alignX==="Max"&&(u=n),n=(s-o*c)/2,t.alignY==="Min"&&(d=-n),t.alignY==="Max"&&(d=n)),t.meetOrSlice==="slice"&&(h=c=d0(this._element,i),n=r-e/h,t.alignX==="Mid"&&(g=n/2),t.alignX==="Max"&&(g=n),n=o-s/c,t.alignY==="Mid"&&(f=n/2),t.alignY==="Max"&&(f=n),r=e/h,o=s/c)),{width:r,height:o,scaleX:h,scaleY:c,offsetLeft:u,offsetTop:d,cropX:g,cropY:f}}static fromObject(t,e){let{filters:s,resizeFilter:i,src:n,crossOrigin:r,type:o}=t,h=Ot(t,Hw);return Promise.all([Mh(n,E(E({},e),{},{crossOrigin:r})),s&&Qo(s,e),i&&Qo([i],e),Ph(h,e)]).then(c=>{let[u,d=[],[g]=[],f={}]=c;return new this(u,E(E({},h),{},{src:n,filters:d,resizeFilter:g},f))})}static fromURL(t){let{crossOrigin:e=null,signal:s}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;return Mh(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=Ki(t,this.ATTRIBUTE_NAMES,s);return this.fromURL(i["xlink:href"],e,i).catch(n=>(Xi("log","Unable to parse Image",n),null))}}function Yg(a){if(!Xy.test(a.nodeName))return{};const t=a.getAttribute("viewBox");let e,s,i=1,n=1,r=0,o=0;const h=a.getAttribute("width"),c=a.getAttribute("height"),u=a.getAttribute("x")||0,d=a.getAttribute("y")||0,g=!(t&&Mm.test(t)),f=!h||!c||h==="100%"||c==="100%";let p="",m=0,y=0;if(g&&(u||d)&&a.parentNode&&a.parentNode.nodeName!=="#document"&&(p=" translate("+Be(u||"0")+" "+Be(d||"0")+") ",e=(a.getAttribute("transform")||"")+p,a.setAttribute("transform",e),a.removeAttribute("x"),a.removeAttribute("y")),g&&f)return{width:0,height:0};const b={width:0,height:0};if(g)return b.width=Be(h),b.height=Be(c),b;const x=t.match(Mm);r=-parseFloat(x[1]),o=-parseFloat(x[2]);const C=parseFloat(x[3]),A=parseFloat(x[4]);b.minX=r,b.minY=o,b.viewBoxWidth=C,b.viewBoxHeight=A,f?(b.width=C,b.height=A):(b.width=Be(h),b.height=Be(c),i=b.width/C,n=b.height/A);const M=dg(a.getAttribute("preserveAspectRatio")||"");if(M.alignX!==Ie&&(M.meetOrSlice==="meet"&&(n=i=i>n?n:i),M.meetOrSlice==="slice"&&(n=i=i>n?i:n),m=b.width-C*i,y=b.height-A*i,M.alignX==="Mid"&&(m/=2),M.alignY==="Mid"&&(y/=2),M.alignX==="Min"&&(m=0),M.alignY==="Min"&&(y=0)),i===1&&n===1&&r===0&&o===0&&u===0&&d===0)return b;if((u||d)&&a.parentNode.nodeName!=="#document"&&(p=" translate("+Be(u||"0")+" "+Be(d||"0")+") "),e=p+" matrix("+i+" 0 0 "+n+" "+(r*i+m)+" "+(o*n+y)+") ",a.nodeName==="svg"){for(s=a.ownerDocument.createElementNS(bg,"g");a.firstChild;)s.appendChild(a.firstChild);a.appendChild(s)}else s=a,s.removeAttribute("x"),s.removeAttribute("y"),e=s.getAttribute("transform")+e;return s.setAttribute("transform",e),b}T(Te,"type","Image"),T(Te,"cacheProperties",[...$i,...G0]),T(Te,"ownDefaults",{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),T(Te,"CSS_CANVAS","canvas-img"),T(Te,"ATTRIBUTE_NAMES",[...Vn,"x","y","width","height","preserveAspectRatio","xlink:href","crossOrigin","image-rendering"]),W.setClass(Te),W.setSVGClass(Te);const _u=a=>a.tagName.replace("svg:",""),Vw=qc(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);function W0(a,t){let e,s,i,n,r=[];for(i=0,n=t.length;i<n;i++)e=t[i],s=a.getElementsByTagNameNS("http://www.w3.org/2000/svg",e),r=r.concat(Array.from(s));return r}const Gw=["gradientTransform","x1","x2","y1","y2","gradientUnits","cx","cy","r","fx","fy"],$g="xlink:href";function z0(a,t){var e;const s=((e=t.getAttribute($g))===null||e===void 0?void 0:e.slice(1))||"",i=a.getElementById(s);if(i&&i.getAttribute($g)&&z0(a,i),i&&(Gw.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($g)}const Ww=["linearGradient","radialGradient","svg:linearGradient","svg:radialGradient"];function zw(a){const t=a.getElementsByTagName("style");let e,s;const i={};for(e=0,s=t.length;e<s;e++){const n=(t[e].textContent||"").replace(/\/\*[\s\S]*?\*\//g,"");n.trim()!==""&&n.split("}").filter((r,o,h)=>h.length>1&&r.trim()).forEach(r=>{if((r.match(/{/g)||[]).length>1&&r.trim().startsWith("@"))return;const o=r.split("{"),h={},c=o[1].trim().split(";").filter(function(u){return u.trim()});for(e=0,s=c.length;e<s;e++){const u=c[e].split(":"),d=u[0].trim(),g=u[1].trim();h[d]=g}(r=o[0].trim()).split(",").forEach(u=>{(u=u.replace(/^svg/i,"").trim())!==""&&(i[u]=E(E({},i[u]||{}),h))})})}return i}const X0=a=>W.getSVGClass(_u(a).toLowerCase());class Xw{constructor(t,e,s,i,n){this.elements=t,this.options=e,this.reviver=s,this.regexUrl=/^url\(['"]?#([^'"]+)['"]?\)/g,this.doc=i,this.clipPaths=n,this.gradientDefs=function(r){const o=W0(r,Ww),h={};let c=o.length;for(;c--;){const u=o[c];u.getAttribute("xlink:href")&&z0(r,u);const d=u.getAttribute("id");d&&(h[d]=u)}return h}(i),this.cssRules=zw(i)}parse(){return Promise.all(this.elements.map(t=>this.createObject(t)))}async createObject(t){const e=X0(t);if(e){const s=await e.fromElement(t,this.options,this.cssRules);return this.resolveGradient(s,t,Jt),this.resolveGradient(s,t,Ne),s instanceof Te&&s._originalElement?uu(s,s.parsePreserveAspectRatioAttribute()):uu(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=Bh.fromElement(i,t,E(E({},this.options),{},{opacity:n}));t.set(s,r)}}async resolveClipPath(t,e,s){const i=this.extractPropertyDefinition(t,"clipPath",this.clipPaths);if(i){const n=Ze(t.calcTransformMatrix()),r=i[0].parentElement;let o=e;for(;!s&&o.parentElement&&o.getAttribute("clip-path")!==t.clipPath;)o=o.parentElement;o.parentElement.appendChild(r);const h=ru("".concat(o.getAttribute("transform")||""," ").concat(r.getAttribute("originalTransform")||""));r.setAttribute("transform","matrix(".concat(h.join(","),")"));const c=await Promise.all(i.map(x=>X0(x).fromElement(x,this.options,this.cssRules).then(C=>(uu(C),C.fillRule=C.clipRule,delete C.clipRule,C)))),u=c.length===1?c[0]:new _i(c),d=Yt(n,u.calcTransformMatrix());u.clipPath&&await this.resolveClipPath(u,o,r.getAttribute("clip-path")?o:void 0);const{scaleX:g,scaleY:f,angle:p,skewX:m,translateX:y,translateY:b}=Tr(d);u.set({flipX:!1,flipY:!1}),u.set({scaleX:g,scaleY:f,angle:p,skewX:m,skewY:0}),u.setPositionByOrigin(new O(y,b),tt,tt),t.clipPath=u}else delete t.clipPath}}const U0=a=>zy.test(_u(a)),qg=()=>({objects:[],elements:[],options:{},allElements:[]});async function Uw(a,t){let{crossOrigin:e,signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(s&&s.aborted)return Xi("log",new Jd("parseSVGDocument")),qg();const i=a.documentElement;(function(u){const d=W0(u,["use","svg:use"]),g=["x","y","xlink:href","href","transform"];for(const f of d){const p=f.attributes,m={};for(const R of p)R.value&&(m[R.name]=R.value);const y=(m["xlink:href"]||m.href||"").slice(1);if(y==="")return;const b=u.getElementById(y);if(b===null)return;let x=b.cloneNode(!0);const C=x.attributes,A={};for(const R of C)R.value&&(A[R.name]=R.value);const{x:M=0,y:D=0,transform:k=""}=m,P="".concat(k," ").concat(A.transform||""," translate(").concat(M,", ").concat(D,")");if(Yg(x),/^svg$/i.test(x.nodeName)){const R=x.ownerDocument.createElementNS(bg,"g");Object.entries(A).forEach(F=>{let[I,X]=F;return R.setAttributeNS(bg,I,X)}),R.append(...x.childNodes),x=R}for(const R of p){if(!R)continue;const{name:F,value:I}=R;if(!g.includes(F))if(F==="style"){const X={};Rg(I,X),Object.entries(A).forEach(N=>{let[it,K]=N;X[it]=K}),Rg(A.style||"",X);const j=Object.entries(X).map(N=>N.join(":")).join(";");x.setAttribute(F,j)}else!A[F]&&x.setAttribute(F,I)}x.setAttribute("transform",P),x.setAttribute("instantiated_by_use","1"),x.removeAttribute("id"),f.parentNode.replaceChild(x,f)}})(a);const n=Array.from(i.getElementsByTagName("*")),r=E(E({},Yg(i)),{},{crossOrigin:e,signal:s}),o=n.filter(u=>(Yg(u),U0(u)&&!function(d){let g=d;for(;g&&(g=g.parentElement);)if(g&&g.nodeName&&Vw.test(_u(g))&&!g.getAttribute("instantiated_by_use"))return!0;return!1}(u)));if(!o||o&&!o.length)return E(E({},qg()),{},{options:r,allElements:n});const h={};return n.filter(u=>_u(u)==="clipPath").forEach(u=>{u.setAttribute("originalTransform",u.getAttribute("transform")||"");const d=u.getAttribute("id");h[d]=Array.from(u.getElementsByTagName("*")).filter(g=>U0(g))}),{objects:await new Xw(o,r,t,a,h).parse(),elements:o,options:r,allElements:n}}function Yw(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return new Promise((s,i)=>{C0(a.replace(/^\n\s*/,"").trim(),{onComplete:n=>{const r=n.responseXML;r&&s(r),i()},signal:e.signal})}).then(s=>Uw(s,t,e)).catch(()=>qg())}const wu=a=>a.webgl!==void 0,Kg="precision highp float",$w=`
|
|
92
|
+
`.concat(Kg,`;
|
|
93
93
|
varying vec2 vTexCoord;
|
|
94
94
|
uniform sampler2D uTexture;
|
|
95
95
|
void main() {
|
|
96
96
|
gl_FragColor = texture2D(uTexture, vTexCoord);
|
|
97
|
-
}`),
|
|
97
|
+
}`),qw=["type"],Kw=["type"],Qw=new RegExp(Kg,"g");class re{get type(){return this.constructor.type}constructor(){let t=Ot(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},qw);Object.assign(this,this.constructor.defaults,t)}getFragmentSource(){return $w}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"}}=vi();i!=="highp"&&(e=e.replace(Qw,Kg.replace("highp",i)));const n=t.createShader(t.VERTEX_SHADER),r=t.createShader(t.FRAGMENT_SHADER),o=t.createProgram();if(!n||!r||!o)throw new mi("Vertex, fragment shader or program creation error");if(t.shaderSource(n,s),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new mi("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 mi("Fragment shader compile error for ".concat(this.type,": ").concat(t.getShaderInfoLog(r)));if(t.attachShader(o,n),t.attachShader(o,r),t.linkProgram(o),!t.getProgramParameter(o,t.LINK_STATUS))throw new mi('Shader link error for "'.concat(this.type,'" ').concat(t.getProgramInfoLog(o)));const h=this.getUniformLocations(t,o)||{};return h.uStepW=t.getUniformLocation(o,"uStepW"),h.uStepH=t.getUniformLocation(o,"uStepH"),{program:o,attributeLocations:this.getAttributeLocations(t,o),uniformLocations:h}}getAttributeLocations(t,e){return{aPosition:t.getAttribLocation(e,"aPosition")}}getUniformLocations(t,e){const s=this.constructor.uniformLocations,i={};for(let n=0;n<s.length;n++)i[s[n]]=t.getUniformLocation(e,s[n]);return i}sendAttributeData(t,e,s){const i=e.aPosition,n=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,n),t.enableVertexAttribArray(i),t.vertexAttribPointer(i,2,t.FLOAT,!1,0,0),t.bufferData(t.ARRAY_BUFFER,s,t.STATIC_DRAW)}_setupFrameBuffer(t){const e=t.context;if(t.passes>1){const s=t.destinationWidth,i=t.destinationHeight;t.sourceWidth===s&&t.sourceHeight===i||(e.deleteTexture(t.targetTexture),t.targetTexture=t.filterBackend.createTexture(e,s,i)),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,t.targetTexture,0)}else e.bindFramebuffer(e.FRAMEBUFFER,null),e.finish()}_swapTextures(t){t.passes--,t.pass++;const e=t.targetTexture;t.targetTexture=t.sourceTexture,t.sourceTexture=e}isNeutralState(t){return!1}applyTo(t){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=Xs({width:e,height:s});t.helpLayer=i}}toObject(){const t=Object.keys(this.constructor.defaults||{});return E({type:this.type},t.reduce((e,s)=>(e[s]=this[s],e),{}))}toJSON(){return this.toObject()}static async fromObject(t,e){return new this(Ot(t,Kw))}}T(re,"type","BaseFilter"),T(re,"uniformLocations",[]);const Jw={multiply:`gl_FragColor.rgb *= uColor.rgb;
|
|
104
104
|
`,screen:`gl_FragColor.rgb = 1.0 - (1.0 - gl_FragColor.rgb) * (1.0 - uColor.rgb);
|
|
105
105
|
`,add:`gl_FragColor.rgb += uColor.rgb;
|
|
106
106
|
`,difference:`gl_FragColor.rgb = abs(gl_FragColor.rgb - uColor.rgb);
|
|
@@ -127,7 +127,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
127
127
|
`,tint:`
|
|
128
128
|
gl_FragColor.rgb *= (1.0 - uColor.a);
|
|
129
129
|
gl_FragColor.rgb += uColor.rgb;
|
|
130
|
-
`};class
|
|
130
|
+
`};class xu extends re{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(Jw[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 _t(this.color).getSource(),i=s[0]*this.alpha,n=s[1]*this.alpha,r=s[2]*this.alpha,o=1-this.alpha;for(let h=0;h<e.length;h+=4){const c=e[h],u=e[h+1],d=e[h+2];switch(this.mode){case"multiply":e[h]=c*i/255,e[h+1]=u*n/255,e[h+2]=d*r/255;break;case"screen":e[h]=255-(255-c)*(255-i)/255,e[h+1]=255-(255-u)*(255-n)/255,e[h+2]=255-(255-d)*(255-r)/255;break;case"add":e[h]=c+i,e[h+1]=u+n,e[h+2]=d+r;break;case"difference":e[h]=Math.abs(c-i),e[h+1]=Math.abs(u-n),e[h+2]=Math.abs(d-r);break;case"subtract":e[h]=c-i,e[h+1]=u-n,e[h+2]=d-r;break;case"darken":e[h]=Math.min(c,i),e[h+1]=Math.min(u,n),e[h+2]=Math.min(d,r);break;case"lighten":e[h]=Math.max(c,i),e[h+1]=Math.max(u,n),e[h+2]=Math.max(d,r);break;case"overlay":e[h]=i<128?2*c*i/255:255-2*(255-c)*(255-i)/255,e[h+1]=n<128?2*u*n/255:255-2*(255-u)*(255-n)/255,e[h+2]=r<128?2*d*r/255:255-2*(255-d)*(255-r)/255;break;case"exclusion":e[h]=i+c-2*i*c/255,e[h+1]=n+u-2*n*u/255,e[h+2]=r+d-2*r*d/255;break;case"tint":e[h]=i+c*o,e[h+1]=n+u*o,e[h+2]=r+d*o}}}sendUniformData(t,e){const s=new _t(this.color).getSource();s[0]=this.alpha*s[0]/255,s[1]=this.alpha*s[1]/255,s[2]=this.alpha*s[2]/255,s[3]=this.alpha,t.uniform4fv(e.uColor,s)}}T(xu,"defaults",{color:"#F95C63",mode:"multiply",alpha:1}),T(xu,"type","BlendColor"),T(xu,"uniformLocations",["uColor"]),W.setClass(xu);const Zw={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
|
+
`},tx=["type","image"];class Su extends re{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return Zw[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=As());const o=n.blendImage,h=o.getContext("2d");o.width!==s||o.height!==i?(o.width=s,o.height=i):h.clearRect(0,0,s,i),h.setTransform(r.scaleX,0,0,r.scaleY,r.left,r.top),h.drawImage(r.getElement(),0,0,s,i);const c=h.getImageData(0,0,s,i).data;for(let u=0;u<e.length;u+=4){const d=e[u],g=e[u+1],f=e[u+2],p=e[u+3],m=c[u],y=c[u+1],b=c[u+2],x=c[u+3];switch(this.mode){case"multiply":e[u]=d*m/255,e[u+1]=g*y/255,e[u+2]=f*b/255,e[u+3]=p*x/255;break;case"mask":e[u+3]=x}}}sendUniformData(t,e){const s=this.calculateMatrix();t.uniform1i(e.uImage,1),t.uniformMatrix3fv(e.uTransformMatrix,!1,s)}toObject(){return E(E({},super.toObject()),{},{image:this.image&&this.image.toObject()})}static async fromObject(t,e){let{type:s,image:i}=t,n=Ot(t,tx);return Te.fromObject(i,e).then(r=>new this(E(E({},n),{},{image:r})))}}T(Su,"type","BlendImage"),T(Su,"defaults",{mode:"multiply",alpha:1}),T(Su,"uniformLocations",["uTransformMatrix","uImage"]),W.setClass(Su);class Cu extends re{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=As(),i.blurLayer2=As());const o=i.blurLayer1,h=i.blurLayer2;o.width===n&&o.height===r||(h.width=o.width=n,h.height=o.height=r);const c=o.getContext("2d"),u=h.getContext("2d"),d=15,g=.06*this.blur*.5;let f,p,m,y;for(c.putImageData(s,0,0),u.clearRect(0,0,n,r),y=-15;y<=d;y++)f=(Math.random()-.5)/4,p=y/d,m=g*p*n+f,u.globalAlpha=1-Math.abs(p),u.drawImage(o,m,f),c.drawImage(h,0,0),u.globalAlpha=1,u.clearRect(0,0,h.width,h.height);for(y=-15;y<=d;y++)f=(Math.random()-.5)/4,p=y/d,m=g*p*r+f,u.globalAlpha=1-Math.abs(p),u.drawImage(o,f,m),c.drawImage(h,0,0),u.globalAlpha=1,u.clearRect(0,0,h.width,h.height);e.drawImage(o,0,0);const b=e.getImageData(0,0,o.width,o.height);return c.globalAlpha=1,c.clearRect(0,0,o.width,o.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}}T(Cu,"type","Blur"),T(Cu,"defaults",{blur:0}),T(Cu,"uniformLocations",["uDelta"]),W.setClass(Cu);class Au extends re{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]=e[i]+s,e[i+1]=e[i+1]+s,e[i+2]=e[i+2]+s}isNeutralState(){return this.brightness===0}sendUniformData(t,e){t.uniform1f(e.uBrightness,this.brightness)}}T(
|
|
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]=e[i]+s,e[i+1]=e[i+1]+s,e[i+2]=e[i+2]+s}isNeutralState(){return this.brightness===0}sendUniformData(t,e){t.uniform1f(e.uBrightness,this.brightness)}}T(Au,"type","Brightness"),T(Au,"defaults",{brightness:0}),T(Au,"uniformLocations",["uBrightness"]),W.setClass(Au);class oa extends re{getFragmentSource(){return`
|
|
212
212
|
precision highp float;
|
|
213
213
|
uniform sampler2D uTexture;
|
|
214
214
|
varying vec2 vTexCoord;
|
|
@@ -219,7 +219,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
219
219
|
color *= uColorMatrix;
|
|
220
220
|
color += uConstants;
|
|
221
221
|
gl_FragColor = color;
|
|
222
|
-
}`}applyTo2d(t){const e=t.imageData.data,s=this.matrix,i=this.colorsOnly;for(let n=0;n<e.length;n+=4){const r=e[n],
|
|
222
|
+
}`}applyTo2d(t){const e=t.imageData.data,s=this.matrix,i=this.colorsOnly;for(let n=0;n<e.length;n+=4){const r=e[n],o=e[n+1],h=e[n+2];if(i)e[n]=r*s[0]+o*s[1]+h*s[2]+255*s[4],e[n+1]=r*s[5]+o*s[6]+h*s[7]+255*s[9],e[n+2]=r*s[10]+o*s[11]+h*s[12]+255*s[14];else{const c=e[n+3];e[n]=r*s[0]+o*s[1]+h*s[2]+c*s[3]+255*s[4],e[n+1]=r*s[5]+o*s[6]+h*s[7]+c*s[8]+255*s[9],e[n+2]=r*s[10]+o*s[11]+h*s[12]+c*s[13]+255*s[14],e[n+3]=r*s[15]+o*s[16]+h*s[17]+c*s[18]+255*s[19]}}}sendUniformData(t,e){const s=this.matrix,i=[s[0],s[1],s[2],s[3],s[5],s[6],s[7],s[8],s[10],s[11],s[12],s[13],s[15],s[16],s[17],s[18]],n=[s[4],s[9],s[14],s[19]];t.uniformMatrix4fv(e.uColorMatrix,!1,i),t.uniform4fv(e.uConstants,n)}toObject(){return E(E({},super.toObject()),{},{matrix:[...this.matrix]})}}function Ir(a,t){var e;const s=(T(e=class extends oa{toObject(){return{type:this.type,colorsOnly:this.colorsOnly}}},"type",a),T(e,"defaults",{colorsOnly:!1,matrix:t}),e);return W.setClass(s,a),s}T(oa,"type","ColorMatrix"),T(oa,"defaults",{matrix:[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],colorsOnly:!0}),T(oa,"uniformLocations",["uColorMatrix","uConstants"]),W.setClass(oa),Ir("Brownie",[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0]),Ir("Vintage",[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0]),Ir("Kodachrome",[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0]),Ir("Technicolor",[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0]),Ir("Polaroid",[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0]),Ir("Sepia",[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0]),Ir("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 Y0 extends re{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=>W.getClass(s.type).fromObject(s,e))).then(s=>new this({subFilters:s}))}}T(Y0,"type","Composed"),W.setClass(Y0);class Tu extends re{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)}}T(
|
|
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)}}T(Tu,"type","Contrast"),T(Tu,"defaults",{contrast:0}),T(Tu,"uniformLocations",["uContrast"]),W.setClass(Tu);const ex={Convolute_3_1:`
|
|
233
233
|
precision highp float;
|
|
234
234
|
uniform sampler2D uTexture;
|
|
235
235
|
uniform float uMatrix[9];
|
|
@@ -373,7 +373,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
373
373
|
gl_FragColor = color;
|
|
374
374
|
gl_FragColor.a = alpha;
|
|
375
375
|
}
|
|
376
|
-
`};class
|
|
376
|
+
`};class Eu extends re{getCacheKey(){return"".concat(this.type,"_").concat(Math.sqrt(this.matrix.length),"_").concat(this.opaque?1:0)}getFragmentSource(){return ex[this.getCacheKey()]}applyTo2d(t){const e=t.imageData,s=e.data,i=this.matrix,n=Math.round(Math.sqrt(i.length)),r=Math.floor(n/2),o=e.width,h=e.height,c=t.ctx.createImageData(o,h),u=c.data,d=this.opaque?1:0;let g,f,p,m,y,b,x,C,A,M,D,k,P;for(D=0;D<h;D++)for(M=0;M<o;M++){for(y=4*(D*o+M),g=0,f=0,p=0,m=0,P=0;P<n;P++)for(k=0;k<n;k++)x=D+P-r,b=M+k-r,x<0||x>=h||b<0||b>=o||(C=4*(x*o+b),A=i[P*n+k],g+=s[C]*A,f+=s[C+1]*A,p+=s[C+2]*A,d||(m+=s[C+3]*A));u[y]=g,u[y+1]=f,u[y+2]=p,u[y+3]=d?s[y+3]:m}t.imageData=c}sendUniformData(t,e){t.uniform1fv(e.uMatrix,this.matrix)}toObject(){return E(E({},super.toObject()),{},{opaque:this.opaque,matrix:[...this.matrix]})}}T(Eu,"type","Convolute"),T(Eu,"defaults",{opaque:!1,matrix:[0,0,0,0,1,0,0,0,0]}),T(Eu,"uniformLocations",["uMatrix","uOpaque","uHalfSize","uSize"]),W.setClass(Eu);const $0="Gamma";class ku extends re{getFragmentSource(){return`
|
|
377
377
|
precision highp float;
|
|
378
378
|
uniform sampler2D uTexture;
|
|
379
379
|
uniform vec3 uGamma;
|
|
@@ -387,7 +387,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
387
387
|
gl_FragColor = color;
|
|
388
388
|
gl_FragColor.rgb *= color.a;
|
|
389
389
|
}
|
|
390
|
-
`}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.gamma=t.gamma||this.constructor.defaults.gamma.concat()}applyTo2d(t){let{imageData:{data:e}}=t;const s=this.gamma,i=1/s[0],n=1/s[1],r=1/s[2];this.rgbValues||(this.rgbValues={r:new Uint8Array(256),g:new Uint8Array(256),b:new Uint8Array(256)});const
|
|
390
|
+
`}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.gamma=t.gamma||this.constructor.defaults.gamma.concat()}applyTo2d(t){let{imageData:{data:e}}=t;const s=this.gamma,i=1/s[0],n=1/s[1],r=1/s[2];this.rgbValues||(this.rgbValues={r:new Uint8Array(256),g:new Uint8Array(256),b:new Uint8Array(256)});const o=this.rgbValues;for(let h=0;h<256;h++)o.r[h]=255*Math.pow(h/255,i),o.g[h]=255*Math.pow(h/255,n),o.b[h]=255*Math.pow(h/255,r);for(let h=0;h<e.length;h+=4)e[h]=o.r[e[h]],e[h+1]=o.g[e[h+1]],e[h+2]=o.b[e[h+2]]}sendUniformData(t,e){t.uniform3fv(e.uGamma,this.gamma)}isNeutralState(){const{gamma:t}=this;return t[0]===1&&t[1]===1&&t[2]===1}toObject(){return{type:$0,gamma:this.gamma.concat()}}}T(ku,"type",$0),T(ku,"defaults",{gamma:[1,1,1]}),T(ku,"uniformLocations",["uGamma"]),W.setClass(ku);const sx={average:`
|
|
391
391
|
precision highp float;
|
|
392
392
|
uniform sampler2D uTexture;
|
|
393
393
|
varying vec2 vTexCoord;
|
|
@@ -416,7 +416,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
416
416
|
float average = 0.21 * col.r + 0.72 * col.g + 0.07 * col.b;
|
|
417
417
|
gl_FragColor = vec4(average, average, average, col.a);
|
|
418
418
|
}
|
|
419
|
-
`};class
|
|
419
|
+
`};class Mu extends re{applyTo2d(t){let{imageData:{data:e}}=t;for(let s,i=0;i<e.length;i+=4){switch(this.mode){case"average":s=(e[i]+e[i+1]+e[i+2])/3;break;case"lightness":s=(Math.min(e[i],e[i+1],e[i+2])+Math.max(e[i],e[i+1],e[i+2]))/2;break;case"luminosity":s=.21*e[i]+.72*e[i+1]+.07*e[i+2]}e[i]=s,e[i+1]=s,e[i+2]=s}}getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return sx[this.mode]}sendUniformData(t,e){t.uniform1i(e.uMode,1)}isNeutralState(){return!1}}T(Mu,"type","Grayscale"),T(Mu,"defaults",{mode:"average"}),T(Mu,"uniformLocations",["uMode"]),W.setClass(Mu);class Qg extends oa{calculateMatrix(){const t=this.rotation*Math.PI,e=Ws(t),s=zs(t),i=1/3,n=Math.sqrt(i)*s,r=1-e;this.matrix=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],this.matrix[0]=e+r/3,this.matrix[1]=i*r-n,this.matrix[2]=i*r+n,this.matrix[5]=i*r+n,this.matrix[6]=e+i*r,this.matrix[7]=i*r-n,this.matrix[10]=i*r-n,this.matrix[11]=i*r+n,this.matrix[12]=e+i*r}isNeutralState(){return this.rotation===0}applyTo(t){this.calculateMatrix(),super.applyTo(t)}toObject(){return{type:this.type,rotation:this.rotation}}}T(Qg,"type","HueRotation"),T(Qg,"defaults",{rotation:0}),W.setClass(Qg);class Pu extends re{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))}}T(
|
|
437
|
+
`}isNeutralState(){return!this.invert}sendUniformData(t,e){t.uniform1i(e.uInvert,Number(this.invert)),t.uniform1i(e.uAlpha,Number(this.alpha))}}T(Pu,"type","Invert"),T(Pu,"defaults",{alpha:!1,invert:!0}),T(Pu,"uniformLocations",["uInvert","uAlpha"]),W.setClass(Pu);class Ou extends re{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}}T(
|
|
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}}T(Ou,"type","Noise"),T(Ou,"defaults",{noise:0}),T(Ou,"uniformLocations",["uNoise","uSeed"]),W.setClass(Ou);class Du extends re{applyTo2d(t){let{imageData:{data:e,width:s,height:i}}=t;for(let n=0;n<i;n+=this.blocksize)for(let r=0;r<s;r+=this.blocksize){const o=4*n*s+4*r,h=e[o],c=e[o+1],u=e[o+2],d=e[o+3];for(let g=n;g<Math.min(n+this.blocksize,i);g++)for(let f=r;f<Math.min(r+this.blocksize,s);f++){const p=4*g*s+4*f;e[p]=h,e[p+1]=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)}}T(
|
|
470
|
+
`}sendUniformData(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}}T(Du,"type","Pixelate"),T(Du,"defaults",{blocksize:4}),T(Du,"uniformLocations",["uBlocksize"]),W.setClass(Du);class Ru extends re{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 _t(this.color).getSource(),n=[i[0]-s,i[1]-s,i[2]-s],r=[i[0]+s,i[1]+s,i[2]+s];for(let o=0;o<e.length;o+=4){const h=e[o],c=e[o+1],u=e[o+2];h>n[0]&&c>n[1]&&u>n[2]&&h<r[0]&&c<r[1]&&u<r[2]&&(e[o+3]=0)}}sendUniformData(t,e){const s=new _t(this.color).getSource(),i=this.distance,n=[0+s[0]/255-i,0+s[1]/255-i,0+s[2]/255-i,1],r=[s[0]/255+i,s[1]/255+i,s[2]/255+i,1];t.uniform4fv(e.uLow,n),t.uniform4fv(e.uHigh,r)}}T(Ru,"type","RemoveColor"),T(Ru,"defaults",{color:"#FFFFFF",distance:.02,useAlpha:!1}),T(Ru,"uniformLocations",["uLow","uHigh"]),W.setClass(Ru);class Lu extends re{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,o=Math.round(n*s),h=Math.round(r*i);let c;c=this.resizeType==="sliceHack"?this.sliceByTwo(t,n,r,o,h):this.resizeType==="hermite"?this.hermiteFastResize(t,n,r,o,h):this.resizeType==="bilinear"?this.bilinearFiltering(t,n,r,o,h):this.resizeType==="lanczos"?this.lanczosResize(t,n,r,o,h):new ImageData(o,h),t.imageData=c}sliceByTwo(t,e,s,i,n){const r=t.imageData,o=.5;let h=!1,c=!1,u=e*o,d=s*o;const g=t.filterBackend.resources;let f=0,p=0;const m=e;let y=0;g.sliceByTwo||(g.sliceByTwo=As());const b=g.sliceByTwo;(b.width<1.5*e||b.height<s)&&(b.width=1.5*e,b.height=s);const x=b.getContext("2d");for(x.clearRect(0,0,1.5*e,s),x.putImageData(r,0,0),i=Math.floor(i),n=Math.floor(n);!h||!c;)e=u,s=d,i<Math.floor(u*o)?u=Math.floor(u*o):(u=i,h=!0),n<Math.floor(d*o)?d=Math.floor(d*o):(d=n,c=!0),x.drawImage(b,f,p,e,s,m,y,u,d),f=m,p=y,y+=d;return x.getImageData(f,p,i,n)}lanczosResize(t,e,s,i,n){const r=t.imageData.data,o=t.ctx.createImageData(i,n),h=o.data,c=this.lanczosCreate(this.lanczosLobes),u=this.rcpScaleX,d=this.rcpScaleY,g=2/this.rcpScaleX,f=2/this.rcpScaleY,p=Math.ceil(u*this.lanczosLobes/2),m=Math.ceil(d*this.lanczosLobes/2),y={},b={x:0,y:0},x={x:0,y:0};return function C(A){let M,D,k,P,R,F,I,X,j,N,it;for(b.x=(A+.5)*u,x.x=Math.floor(b.x),M=0;M<n;M++){for(b.y=(M+.5)*d,x.y=Math.floor(b.y),R=0,F=0,I=0,X=0,j=0,D=x.x-p;D<=x.x+p;D++)if(!(D<0||D>=e)){N=Math.floor(1e3*Math.abs(D-b.x)),y[N]||(y[N]={});for(let K=x.y-m;K<=x.y+m;K++)K<0||K>=s||(it=Math.floor(1e3*Math.abs(K-b.y)),y[N][it]||(y[N][it]=c(Math.sqrt(Math.pow(N*g,2)+Math.pow(it*f,2))/1e3)),k=y[N][it],k>0&&(P=4*(K*e+D),R+=k,F+=k*r[P],I+=k*r[P+1],X+=k*r[P+2],j+=k*r[P+3]))}P=4*(M*i+A),h[P]=F/R,h[P+1]=I/R,h[P+2]=X/R,h[P+3]=j/R}return++A<i?C(A):o}(0)}bilinearFiltering(t,e,s,i,n){let r,o,h,c,u,d,g,f,p,m,y,b,x,C=0;const A=this.rcpScaleX,M=this.rcpScaleY,D=4*(e-1),k=t.imageData.data,P=t.ctx.createImageData(i,n),R=P.data;for(g=0;g<n;g++)for(f=0;f<i;f++)for(u=Math.floor(A*f),d=Math.floor(M*g),p=A*f-u,m=M*g-d,x=4*(d*e+u),y=0;y<4;y++)r=k[x+y],o=k[x+4+y],h=k[x+D+y],c=k[x+D+4+y],b=r*(1-p)*(1-m)+o*p*(1-m)+h*m*(1-p)+c*p*m,R[C++]=b;return P}hermiteFastResize(t,e,s,i,n){const r=this.rcpScaleX,o=this.rcpScaleY,h=Math.ceil(r/2),c=Math.ceil(o/2),u=t.imageData.data,d=t.ctx.createImageData(i,n),g=d.data;for(let f=0;f<n;f++)for(let p=0;p<i;p++){const m=4*(p+f*i);let y=0,b=0,x=0,C=0,A=0,M=0,D=0;const k=(f+.5)*o;for(let P=Math.floor(f*o);P<(f+1)*o;P++){const R=Math.abs(k-(P+.5))/c,F=(p+.5)*r,I=R*R;for(let X=Math.floor(p*r);X<(p+1)*r;X++){let j=Math.abs(F-(X+.5))/h;const N=Math.sqrt(I+j*j);N>1&&N<-1||(y=2*N*N*N-3*N*N+1,y>0&&(j=4*(X+P*e),D+=y*u[j+3],x+=y,u[j+3]<255&&(y=y*u[j+3]/250),C+=y*u[j],A+=y*u[j+1],M+=y*u[j+2],b+=y))}}g[m]=C/b,g[m+1]=A/b,g[m+2]=M/b,g[m+3]=D/x}return d}}T(Lu,"type","Resize"),T(Lu,"defaults",{resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3}),T(Lu,"uniformLocations",["uDelta","uTaps"]),W.setClass(Lu);class Fu extends re{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=Math.max(e[i],e[i+1],e[i+2]);e[i]+=n!==e[i]?(n-e[i])*s:0,e[i+1]+=n!==e[i+1]?(n-e[i+1])*s:0,e[i+2]+=n!==e[i+2]?(n-e[i+2])*s:0}}sendUniformData(t,e){t.uniform1f(e.uSaturation,-this.saturation)}isNeutralState(){return this.saturation===0}}T(
|
|
512
|
+
`}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.saturation;for(let i=0;i<e.length;i+=4){const n=Math.max(e[i],e[i+1],e[i+2]);e[i]+=n!==e[i]?(n-e[i])*s:0,e[i+1]+=n!==e[i+1]?(n-e[i+1])*s:0,e[i+2]+=n!==e[i+2]?(n-e[i+2])*s:0}}sendUniformData(t,e){t.uniform1f(e.uSaturation,-this.saturation)}isNeutralState(){return this.saturation===0}}T(Fu,"type","Saturation"),T(Fu,"defaults",{saturation:0}),T(Fu,"uniformLocations",["uSaturation"]),W.setClass(Fu);class Iu extends re{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=Math.max(e[i],e[i+1],e[i+2]),r=(e[i]+e[i+1]+e[i+2])/3,a=2*Math.abs(n-r)/255*s;e[i]+=n!==e[i]?(n-e[i])*a:0,e[i+1]+=n!==e[i+1]?(n-e[i+1])*a:0,e[i+2]+=n!==e[i+2]?(n-e[i+2])*a:0}}sendUniformData(t,e){t.uniform1f(e.uVibrance,-this.vibrance)}isNeutralState(){return this.vibrance===0}}T(_u,"type","Vibrance"),T(_u,"defaults",{vibrance:0}),T(_u,"uniformLocations",["uVibrance"]),V.setClass(_u);const ex="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 sx(o){return new URL(Object.assign({"../assets/close.svg":ex})[`../assets/${o}`],typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ft&&Ft.tagName.toUpperCase()==="SCRIPT"&&Ft.src||new URL("pdf-canvas.umd.js",document.baseURI).href).href}function ix(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 nx(i))}),i.addEventListener("error",n=>{window.URL.revokeObjectURL(s),e(n)})})}function nx(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 j0=null;function rx(){const o=document.createElement("div");o.style.width="1in",document.body.append(o);const t=o.offsetWidth;return o.remove(),t}function ax(){const o=j0??rx();return j0=o,o/72}function ox(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 _s=new Map;function hx(o){const t=new Sg(o);return _s.set(o,t),t}function lx(o,t){const e=Date.now();return{PDFId:`${o.name}-${e}`,name:o.name.replace(/.pdf/,""),updateDate:e,PDFBase64:t}}function cx(o,t){const e=o.getViewport({scale:t}),s=document.createElement("canvas"),i=s.getContext("2d"),n=ax()/window.devicePixelRatio;s.width=Math.floor(e.width*n),s.height=Math.floor(e.height*n);const r={canvasContext:i,viewport:e,transform:[n,0,0,n,0,0]},a=o.render(r);return{canvas:s,renderTask:a}}async function ux(o,t,e){const s=o||sx("close.svg"),{objects:i,options:n}=await Gw(s),r=i.filter(h=>h!==null),a=rw.groupSVGElements(r,n);return r.forEach(h=>{h.stroke=t}),a.hoverCursor="pointer",a.stroke=`${t}-${e}`,a}function dx(o,t){if(!_s.get(o))return;const s=1/3,i=bx(t,s);B0(o,i,s)}async function gx(o,t){const e=await ix(t),s=Date.now(),n={PDFId:`${t.name}${s}`,name:t.name.replace(/.png|.jpg|.jpeg/,""),updateDate:s,PDFBase64:e};return N0(o,{url:e}),{...n,pages:1}}async function N0(o,{url:t,scale:e=.5}){if(!_s.get(o))return;const i=await Ce.fromURL(t);i.scale(e),B0(o,i,e)}function B0(o,t,e){const s=_s.get(o);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function Mh(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 fx(o,t,e){!e||!o||(e.scale(1/t),Mh(o,e))}function px(o,t,e){o&&(o.borderScaleFactor=1/t,o.cornerSize=6*(1/t),o.touchCornerSize=24*(1/t),o.cornerStrokeColor=e.stroke,o.setCoords())}function mx(o){const t=_s.get(o);t&&(t.discardActiveObject(),t.renderAll())}function vx(o){const t=_s.get(o);t&&(t.clear(),_s.delete(o))}function bx(o,t){return new Ce(o,{scaleX:t,scaleY:t})}var Oh={};Oh.d=(o,t)=>{for(var e in t)Oh.o(t,e)&&!Oh.o(o,e)&&Object.defineProperty(o,e,{enumerable:!0,get:t[e]})},Oh.o=(o,t)=>Object.prototype.hasOwnProperty.call(o,t);var et=globalThis.pdfjsLib={};Oh.d(et,{AbortException:()=>Er,AnnotationEditorLayer:()=>_f,AnnotationEditorParamsType:()=>Z,AnnotationEditorType:()=>nt,AnnotationEditorUIManager:()=>Mr,AnnotationLayer:()=>mC,AnnotationMode:()=>Pn,ColorPicker:()=>Nu,DOMSVGFactory:()=>gf,DrawLayer:()=>wf,FeatureTest:()=>Ne,GlobalWorkerOptions:()=>Vi,ImageKind:()=>wu,InvalidPDFException:()=>W0,MissingPDFException:()=>Tr,OPS:()=>zs,OutputScale:()=>qg,PDFDataRangeTransport:()=>_v,PDFDateString:()=>Yg,PDFWorker:()=>eo,PasswordResponses:()=>xx,PermissionFlag:()=>wx,PixelsPerInch:()=>Rn,RenderingCancelledException:()=>Vg,TextLayer:()=>Nh,UnexpectedResponseException:()=>Au,Util:()=>U,VerbosityLevel:()=>xu,XfaLayer:()=>Cv,build:()=>KS,createValidAbsoluteUrl:()=>Tx,fetchData:()=>Eu,getDocument:()=>WS,getFilenameFromUrl:()=>Lx,getPdfFilenameFromUrl:()=>Ix,getXfaPageViewport:()=>jx,isDataScheme:()=>ku,isPdfFile:()=>Gg,noContextMenu:()=>ws,normalizeUnicode:()=>Dx,setLayerDimensions:()=>kr,shadow:()=>ut,version:()=>$S});const Ae=typeof process=="object"&&process+""=="[object process]"&&!process.versions.nw&&!(process.versions.electron&&process.type&&process.type!=="browser"),H0=[1,0,0,1,0,0],Ig=[.001,0,0,.001,0,0],yx=1e7,jg=1.35,rs={ANY:1,DISPLAY:2,PRINT:4,SAVE:8,ANNOTATIONS_FORMS:16,ANNOTATIONS_STORAGE:32,ANNOTATIONS_DISABLE:64,IS_EDITING:128,OPLIST:256},Pn={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},_x="pdfjs_internal_editor_",nt={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15},Z={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},wx={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},Te={FILL:0,STROKE:1,FILL_STROKE:2,INVISIBLE:3,FILL_ADD_TO_PATH:4,STROKE_ADD_TO_PATH:5,FILL_STROKE_ADD_TO_PATH:6,ADD_TO_PATH:7,FILL_STROKE_MASK:3,ADD_TO_PATH_FLAG:4},wu={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},ie={TEXT:1,LINK:2,FREETEXT:3,LINE:4,SQUARE:5,CIRCLE:6,POLYGON:7,POLYLINE:8,HIGHLIGHT:9,UNDERLINE:10,SQUIGGLY:11,STRIKEOUT:12,STAMP:13,CARET:14,INK:15,POPUP:16,FILEATTACHMENT:17,SOUND:18,MOVIE:19,WIDGET:20,SCREEN:21,PRINTERMARK:22,TRAPNET:23,WATERMARK:24,THREED:25,REDACT:26},Ph={SOLID:1,DASHED:2,BEVELED:3,INSET:4,UNDERLINE:5},xu={ERRORS:0,WARNINGS:1,INFOS:5},zs={dependency:1,setLineWidth:2,setLineCap:3,setLineJoin:4,setMiterLimit:5,setDash:6,setRenderingIntent:7,setFlatness:8,setGState:9,save:10,restore:11,transform:12,moveTo:13,lineTo:14,curveTo:15,curveTo2:16,curveTo3:17,closePath:18,rectangle:19,stroke:20,closeStroke:21,fill:22,eoFill:23,fillStroke:24,eoFillStroke:25,closeFillStroke:26,closeEOFillStroke:27,endPath:28,clip:29,eoClip:30,beginText:31,endText:32,setCharSpacing:33,setWordSpacing:34,setHScale:35,setLeading:36,setFont:37,setTextRenderingMode:38,setTextRise:39,moveText:40,setLeadingMoveText:41,setTextMatrix:42,nextLine:43,showText:44,showSpacedText:45,nextLineShowText:46,nextLineSetSpacingShowText:47,setCharWidth:48,setCharWidthAndBounds:49,setStrokeColorSpace:50,setFillColorSpace:51,setStrokeColor:52,setStrokeColorN:53,setFillColor:54,setFillColorN:55,setStrokeGray:56,setFillGray:57,setStrokeRGBColor:58,setFillRGBColor:59,setStrokeCMYKColor:60,setFillCMYKColor:61,shadingFill:62,beginInlineImage:63,beginImageData:64,endInlineImage:65,paintXObject:66,markPoint:67,markPointProps:68,beginMarkedContent:69,beginMarkedContentProps:70,endMarkedContent:71,beginCompat:72,endCompat:73,paintFormXObjectBegin:74,paintFormXObjectEnd:75,beginGroup:76,endGroup:77,beginAnnotation:80,endAnnotation:81,paintImageMaskXObject:83,paintImageMaskXObjectGroup:84,paintImageXObject:85,paintInlineImageXObject:86,paintInlineImageXObjectGroup:87,paintImageXObjectRepeat:88,paintImageMaskXObjectRepeat:89,paintSolidColorImageMask:90,constructPath:91,setStrokeTransparent:92,setFillTransparent:93},xx={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};let Su=xu.WARNINGS;function Sx(o){Number.isInteger(o)&&(Su=o)}function Cx(){return Su}function Cu(o){Su>=xu.INFOS&&console.log(`Info: ${o}`)}function at(o){Su>=xu.WARNINGS&&console.log(`Warning: ${o}`)}function Mt(o){throw new Error(o)}function ne(o,t){o||Mt(t)}function Ax(o){switch(o==null?void 0:o.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}function Tx(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=Px(o)}catch{}}const s=t?new URL(o,t):new URL(o);if(Ax(s))return s}catch{}return null}function ut(o,t,e,s=!1){return Object.defineProperty(o,t,{value:e,enumerable:!s,configurable:!0,writable:!1}),e}const Dn=function(){function t(e,s){this.message=e,this.name=s}return t.prototype=new Error,t.constructor=t,t}();class Ng extends Dn{constructor(t,e){super(t,"PasswordException"),this.code=e}}class Bg extends Dn{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}}class W0 extends Dn{constructor(t){super(t,"InvalidPDFException")}}class Tr extends Dn{constructor(t){super(t,"MissingPDFException")}}class Au extends Dn{constructor(t,e){super(t,"UnexpectedResponseException"),this.status=e}}class Ex extends Dn{constructor(t){super(t,"FormatError")}}class Er extends Dn{constructor(t){super(t,"AbortException")}}function X0(o){(typeof o!="object"||(o==null?void 0:o.length)===void 0)&&Mt("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 Tu(o){typeof o!="string"&&Mt("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 Hg(o){const t=Object.create(null);for(const[e,s]of o)t[e]=s;return t}function Mx(){const o=new Uint8Array(4);return o[0]=1,new Uint32Array(o.buffer,0,1)[0]===1}function Ox(){try{return new Function(""),!0}catch{return!1}}class Ne{static get isLittleEndian(){return ut(this,"isLittleEndian",Mx())}static get isEvalSupported(){return ut(this,"isEvalSupported",Ox())}static get isOffscreenCanvasSupported(){return ut(this,"isOffscreenCanvasSupported",typeof OffscreenCanvas<"u")}static get platform(){return typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.platform)=="string"?ut(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")}):ut(this,"platform",{isMac:!1,isWindows:!1,isFirefox:!1})}static get isCSSRoundSupported(){var t,e;return ut(this,"isCSSRoundSupported",(e=(t=globalThis.CSS)==null?void 0:t.supports)==null?void 0:e.call(t,"width: round(1.5px, 1px)"))}}const Wg=Array.from(Array(256).keys(),o=>o.toString(16).padStart(2,"0"));class U{static makeHexColor(t,e,s){return`#${Wg[t]}${Wg[e]}${Wg[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,l=a+h||1,u=a-h||1;return[Math.sqrt(l),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,l){return l?(l[0]=Math.min(l[0],t,a),l[1]=Math.min(l[1],e,h),l[2]=Math.max(l[2],t,a),l[3]=Math.max(l[3],e,h)):l=[Math.min(t,a),Math.min(e,h),Math.max(t,a),Math.max(e,h)],y(this,Yi,Df).call(this,t,s,n,a,e,i,r,h,3*(-t+3*(s-n)+a),6*(t-2*s+n),3*(s-t),l),y(this,Yi,Df).call(this,t,s,n,a,e,i,r,h,3*(-e+3*(i-r)+h),6*(e-2*i+r),3*(i-e),l),l}}Yi=new WeakSet,od=function(t,e,s,i,n,r,a,h,l,u){if(l<=0||l>=1)return;const d=1-l,g=l*l,f=g*l,p=d*(d*(d*t+3*l*e)+3*g*s)+f*i,m=d*(d*(d*n+3*l*r)+3*g*a)+f*h;u[0]=Math.min(u[0],p),u[1]=Math.min(u[1],m),u[2]=Math.max(u[2],p),u[3]=Math.max(u[3],m)},Df=function(t,e,s,i,n,r,a,h,l,u,d,g){if(Math.abs(l)<1e-12){Math.abs(u)>=1e-12&&y(this,Yi,od).call(this,t,e,s,i,n,r,a,h,-d/u,g);return}const f=u**2-4*d*l;if(f<0)return;const p=Math.sqrt(f),m=2*l;y(this,Yi,od).call(this,t,e,s,i,n,r,a,h,(-u+p)/m,g),y(this,Yi,od).call(this,t,e,s,i,n,r,a,h,(-u-p)/m,g)},w(U,Yi);function Px(o){return decodeURIComponent(escape(o))}let Xg=null,z0=null;function Dx(o){return Xg||(Xg=/([\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,z0=new Map([["ſt","ſt"]])),o.replaceAll(Xg,(t,e,s)=>e?e.normalize("NFKC"):z0.get(s))}function Rx(){if(typeof crypto<"u"&&typeof(crypto==null?void 0:crypto.randomUUID)=="function")return crypto.randomUUID();const o=new Uint8Array(32);if(typeof crypto<"u"&&typeof(crypto==null?void 0:crypto.getRandomValues)=="function")crypto.getRandomValues(o);else for(let t=0;t<32;t++)o[t]=Math.floor(Math.random()*255);return X0(o)}const zg="pdfjs_internal_id_",Wi={BEZIER_CURVE_TO:0,MOVE_TO:1,LINE_TO:2,QUADRATIC_CURVE_TO:3,RESTORE:4,SAVE:5,SCALE:6,TRANSFORM:7,TRANSLATE:8};function Fx(o){return Uint8Array.prototype.toBase64?o.toBase64():btoa(X0(o))}const Xi="http://www.w3.org/2000/svg",Dr=class Dr{};tt(Dr,"CSS",96),tt(Dr,"PDF",72),tt(Dr,"PDF_TO_CSS_UNITS",Dr.CSS/Dr.PDF);let Rn=Dr;async function Eu(o,t="text"){if(Rh(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 Dh{constructor({viewBox:t,scale:e,rotation:s,offsetX:i=0,offsetY:n=0,dontFlip:r=!1}){this.viewBox=t,this.scale=e,this.rotation=s,this.offsetX=i,this.offsetY=n;const a=(t[2]+t[0])/2,h=(t[3]+t[1])/2;let l,u,d,g;switch(s%=360,s<0&&(s+=360),s){case 180:l=-1,u=0,d=0,g=1;break;case 90:l=0,u=1,d=1,g=0;break;case 270:l=0,u=-1,d=-1,g=0;break;case 0:l=1,u=0,d=0,g=-1;break;default:throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.")}r&&(d=-d,g=-g);let f,p,m,_;l===0?(f=Math.abs(h-t[1])*e+i,p=Math.abs(a-t[0])*e+n,m=(t[3]-t[1])*e,_=(t[2]-t[0])*e):(f=Math.abs(a-t[0])*e+i,p=Math.abs(h-t[1])*e+n,m=(t[2]-t[0])*e,_=(t[3]-t[1])*e),this.transform=[l*e,u*e,d*e,g*e,f-l*e*a-d*e*h,p-u*e*a-g*e*h],this.width=m,this.height=_}get rawDims(){const{viewBox:t}=this;return ut(this,"rawDims",{pageWidth:t[2]-t[0],pageHeight:t[3]-t[1],pageX:t[0],pageY:t[1]})}clone({scale:t=this.scale,rotation:e=this.rotation,offsetX:s=this.offsetX,offsetY:i=this.offsetY,dontFlip:n=!1}={}){return new Dh({viewBox:this.viewBox.slice(),scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}convertToViewportPoint(t,e){return U.applyTransform([t,e],this.transform)}convertToViewportRectangle(t){const e=U.applyTransform([t[0],t[1]],this.transform),s=U.applyTransform([t[2],t[3]],this.transform);return[e[0],e[1],s[0],s[1]]}convertToPdfPoint(t,e){return U.applyInverseTransform([t,e],this.transform)}}class Vg extends Dn{constructor(t,e=0){super(t,"RenderingCancelledException"),this.extraDelay=e}}function ku(o){const t=o.length;let e=0;for(;e<t&&o[e].trim()==="";)e++;return o.substring(e,e+5).toLowerCase()==="data:"}function Gg(o){return typeof o=="string"&&/\.pdf$/i.test(o)}function Lx(o){return[o]=o.split(/[#?]/,1),o.substring(o.lastIndexOf("/")+1)}function Ix(o,t="document.pdf"){if(typeof o!="string")return t;if(ku(o))return at('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 V0{constructor(){tt(this,"started",Object.create(null));tt(this,"times",[])}time(t){t in this.started&&at(`Timer is already running for ${t}`),this.started[t]=Date.now()}timeEnd(t){t in this.started||at(`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 Rh(o,t){try{const{protocol:e}=t?new URL(o,t):new URL(o);return e==="http:"||e==="https:"}catch{return!1}}function ws(o){o.preventDefault()}function G0(o){console.log("Deprecated API usage: "+o)}class Yg{static toDateObject(t){if(!t||typeof t!="string")return null;c(this,Xh)||v(this,Xh,new RegExp("^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+|-])?(\\d{2})?'?(\\d{2})?'?"));const e=c(this,Xh).exec(t);if(!e)return null;const s=parseInt(e[1],10);let i=parseInt(e[2],10);i=i>=1&&i<=12?i-1:0;let n=parseInt(e[3],10);n=n>=1&&n<=31?n:1;let r=parseInt(e[4],10);r=r>=0&&r<=23?r:0;let 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 l=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,l==="-"?(r+=u,a+=d):l==="+"&&(r-=u,a-=d),new Date(Date.UTC(s,i,n,r,a,h))}}Xh=new WeakMap,w(Yg,Xh);function jx(o,{scale:t=1,rotation:e=0}){const{width:s,height:i}=o.attributes.style,n=[0,0,parseInt(s),parseInt(i)];return new Dh({viewBox:n,scale:t,rotation:e})}function Ug(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):(at(`Not a valid color format: "${o}"`),[0,0,0])}function Nx(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,Ug(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 zi(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 kr(o,t,e=!1,s=!0){if(t instanceof Dh){const{pageWidth:i,pageHeight:n}=t.rawDims,{style:r}=o,a=Ne.isCSSRoundSupported,h=`var(--scale-factor) * ${i}px`,l=`var(--scale-factor) * ${n}px`,u=a?`round(down, ${h}, var(--scale-round-x, 1px))`:`calc(${h})`,d=a?`round(down, ${l}, var(--scale-round-y, 1px))`:`calc(${l})`;!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 qg{constructor(){const t=window.devicePixelRatio||1;this.sx=t,this.sy=t}get scaled(){return this.sx!==1||this.sy!==1}get symmetric(){return this.sx===this.sy}}const Ui=class Ui{constructor(t){w(this,He);w(this,Ln,null);w(this,Rr,null);w(this,Vs);w(this,Fr,null);w(this,zh,null);v(this,Vs,t),c(Ui,Vh)||v(Ui,Vh,Object.freeze({freetext:"pdfjs-editor-remove-freetext-button",highlight:"pdfjs-editor-remove-highlight-button",ink:"pdfjs-editor-remove-ink-button",stamp:"pdfjs-editor-remove-stamp-button"}))}render(){const t=v(this,Ln,document.createElement("div"));t.classList.add("editToolbar","hidden"),t.setAttribute("role","toolbar");const e=c(this,Vs)._uiManager._signal;t.addEventListener("contextmenu",ws,{signal:e}),t.addEventListener("pointerdown",y(Ui,Wu,Jv),{signal:e});const s=v(this,Fr,document.createElement("div"));s.className="buttons",t.append(s);const i=c(this,Vs).toolbarPosition;if(i){const{style:n}=t,r=c(this,Vs)._uiManager.direction==="ltr"?1-i[0]:i[0];n.insetInlineEnd=`${100*r}%`,n.top=`calc(${100*i[1]}% + var(--editor-toolbar-vert-offset))`}return y(this,He,tb).call(this),t}get div(){return c(this,Ln)}hide(){var t;c(this,Ln).classList.add("hidden"),(t=c(this,Rr))==null||t.hideDropdown()}show(){var t;c(this,Ln).classList.remove("hidden"),(t=c(this,zh))==null||t.shown()}async addAltText(t){const e=await t.render();y(this,He,hd).call(this,e),c(this,Fr).prepend(e,c(this,He,Rf)),v(this,zh,t)}addColorPicker(t){v(this,Rr,t);const e=t.renderButton();y(this,He,hd).call(this,e),c(this,Fr).prepend(e,c(this,He,Rf))}remove(){var t;c(this,Ln).remove(),(t=c(this,Rr))==null||t.destroy(),v(this,Rr,null)}};Ln=new WeakMap,Rr=new WeakMap,Vs=new WeakMap,Fr=new WeakMap,zh=new WeakMap,Vh=new WeakMap,Wu=new WeakSet,Jv=function(t){t.stopPropagation()},He=new WeakSet,Qv=function(t){c(this,Vs)._focusEventsAllowed=!1,t.preventDefault(),t.stopPropagation()},Zv=function(t){c(this,Vs)._focusEventsAllowed=!0,t.preventDefault(),t.stopPropagation()},hd=function(t){const e=c(this,Vs)._uiManager._signal;t.addEventListener("focusin",y(this,He,Qv).bind(this),{capture:!0,signal:e}),t.addEventListener("focusout",y(this,He,Zv).bind(this),{capture:!0,signal:e}),t.addEventListener("contextmenu",ws,{signal:e})},tb=function(){const{editorType:t,_uiManager:e}=c(this,Vs),s=document.createElement("button");s.className="delete",s.tabIndex=0,s.setAttribute("data-l10n-id",c(Ui,Vh)[t]),y(this,He,hd).call(this,s),s.addEventListener("click",i=>{e.delete()},{signal:e._signal}),c(this,Fr).append(s)},Rf=function(){const t=document.createElement("div");return t.className="divider",t},w(Ui,Wu),w(Ui,Vh,null);let $g=Ui;class Bx{constructor(t){w(this,In);w(this,Gh,null);w(this,Lr,null);w(this,Ir);v(this,Ir,t)}show(t,e,s){const[i,n]=y(this,In,sb).call(this,e,s),{style:r}=c(this,Lr)||v(this,Lr,y(this,In,eb).call(this));t.append(c(this,Lr)),r.insetInlineEnd=`${100*i}%`,r.top=`calc(${100*n}% + var(--editor-toolbar-vert-offset))`}hide(){c(this,Lr).remove()}}Gh=new WeakMap,Lr=new WeakMap,Ir=new WeakMap,In=new WeakSet,eb=function(){const t=v(this,Lr,document.createElement("div"));t.className="editToolbar",t.setAttribute("role","toolbar"),t.addEventListener("contextmenu",ws,{signal:c(this,Ir)._signal});const e=v(this,Gh,document.createElement("div"));return e.className="buttons",t.append(e),y(this,In,ib).call(this),t},sb=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]},ib=function(){const t=document.createElement("button");t.className="highlightButton",t.tabIndex=0,t.setAttribute("data-l10n-id","pdfjs-highlight-floating-button1");const e=document.createElement("span");t.append(e),e.className="visuallyHidden",e.setAttribute("data-l10n-id","pdfjs-highlight-floating-button-label");const s=c(this,Ir)._signal;t.addEventListener("contextmenu",ws,{signal:s}),t.addEventListener("click",()=>{c(this,Ir).highlightSelection("floating_button")},{signal:s}),c(this,Gh).append(t)};function Mu(o,t,e){for(const s of e)t.addEventListener(s,o[s].bind(o))}function Hx(o){return Math.round(Math.min(255,Math.max(1,255*o))).toString(16).padStart(2,"0")}class Wx{constructor(){w(this,Xu,0)}get id(){return`${_x}${Ge(this,Xu)._++}`}}Xu=new WeakMap;const xf=class xf{constructor(){w(this,io);w(this,so,Rx());w(this,Yh,0);w(this,Ee,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 ut(this,"_isSVGFittingCanvas",n)}async getFromFile(t){const{lastModified:e,name:s,size:i,type:n}=t;return y(this,io,ld).call(this,`${e}_${s}_${i}_${n}`,t)}async getFromUrl(t){return y(this,io,ld).call(this,t,t)}async getFromBlob(t,e){const s=await e;return y(this,io,ld).call(this,t,s)}async getFromId(t){c(this,Ee)||v(this,Ee,new Map);const e=c(this,Ee).get(t);if(!e)return null;if(e.bitmap)return e.refCounter+=1,e;if(e.file)return this.getFromFile(e.file);if(e.blobPromise){const{blobPromise:s}=e;return delete e.blobPromise,this.getFromBlob(e.id,s)}return this.getFromUrl(e.url)}getFromCanvas(t,e){c(this,Ee)||v(this,Ee,new Map);let s=c(this,Ee).get(t);if(s!=null&&s.bitmap)return s.refCounter+=1,s;const i=new OffscreenCanvas(e.width,e.height);return i.getContext("2d").drawImage(e,0,0),s={bitmap:i.transferToImageBitmap(),id:`image_${c(this,so)}_${Ge(this,Yh)._++}`,refCounter:1,isSvg:!1},c(this,Ee).set(t,s),c(this,Ee).set(s.id,s),s}getSvgUrl(t){const e=c(this,Ee).get(t);return e!=null&&e.isSvg?e.svgUrl:null}deleteId(t){var i;c(this,Ee)||v(this,Ee,new Map);const e=c(this,Ee).get(t);if(!e||(e.refCounter-=1,e.refCounter!==0))return;const{bitmap:s}=e;if(!e.url&&!e.file){const n=new OffscreenCanvas(s.width,s.height);n.getContext("bitmaprenderer").transferFromImageBitmap(s),e.blobPromise=n.convertToBlob()}(i=s.close)==null||i.call(s),e.bitmap=null}isValidId(t){return t.startsWith(`image_${c(this,so)}_`)}};so=new WeakMap,Yh=new WeakMap,Ee=new WeakMap,io=new WeakSet,ld=async function(t,e){c(this,Ee)||v(this,Ee,new Map);let s=c(this,Ee).get(t);if(s===null)return null;if(s!=null&&s.bitmap)return s.refCounter+=1,s;try{s||(s={bitmap:null,id:`image_${c(this,so)}_${Ge(this,Yh)._++}`,refCounter:0,isSvg:!1});let i;if(typeof e=="string"?(s.url=e,i=await Eu(e,"blob")):e instanceof File?i=s.file=e:e instanceof Blob&&(i=e),i.type==="image/svg+xml"){const n=xf._isSVGFittingCanvas,r=new FileReader,a=new Image,h=new Promise((l,u)=>{a.onload=()=>{s.bitmap=a,s.isSvg=!0,l()},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){console.error(i),s=null}return c(this,Ee).set(t,s),s&&c(this,Ee).set(s.id,s),s};let Kg=xf;class Xx{constructor(t=128){w(this,ce,[]);w(this,jn,!1);w(this,Uh);w(this,ue,-1);v(this,Uh,t)}add({cmd:t,undo:e,post:s,mustExec:i,type:n=NaN,overwriteIfSameType:r=!1,keepUndo:a=!1}){if(i&&t(),c(this,jn))return;const h={cmd:t,undo:e,post:s,type:n};if(c(this,ue)===-1){c(this,ce).length>0&&(c(this,ce).length=0),v(this,ue,0),c(this,ce).push(h);return}if(r&&c(this,ce)[c(this,ue)].type===n){a&&(h.undo=c(this,ce)[c(this,ue)].undo),c(this,ce)[c(this,ue)]=h;return}const l=c(this,ue)+1;l===c(this,Uh)?c(this,ce).splice(0,1):(v(this,ue,l),l<c(this,ce).length&&c(this,ce).splice(l)),c(this,ce).push(h)}undo(){if(c(this,ue)===-1)return;v(this,jn,!0);const{undo:t,post:e}=c(this,ce)[c(this,ue)];t(),e==null||e(),v(this,jn,!1),v(this,ue,c(this,ue)-1)}redo(){if(c(this,ue)<c(this,ce).length-1){v(this,ue,c(this,ue)+1),v(this,jn,!0);const{cmd:t,post:e}=c(this,ce)[c(this,ue)];t(),e==null||e(),v(this,jn,!1)}}hasSomethingToUndo(){return c(this,ue)!==-1}hasSomethingToRedo(){return c(this,ue)<c(this,ce).length-1}destroy(){v(this,ce,null)}}ce=new WeakMap,jn=new WeakMap,Uh=new WeakMap,ue=new WeakMap;class Fh{constructor(t){w(this,zu);this.buffer=[],this.callbacks=new Map,this.allKeys=new Set;const{isMac:e}=Ne.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(y(this,zu,nb).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||(e.stopPropagation(),e.preventDefault()))}}zu=new WeakSet,nb=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 Vu=class Vu{get _colors(){const t=new Map([["CanvasText",null],["Canvas",null]]);return Nx(t),ut(this,"_colors",t)}convert(t){const e=Ug(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 Vu._colorsMapping.get(s);return e}getHexCode(t){const e=this._colors.get(t);return e?U.makeHexColor(...e):t}};tt(Vu,"_colorsMapping",new Map([["CanvasText",[0,0,0]],["Canvas",[255,255,255]]]));let Jg=Vu;const co=class co{constructor(t,e,s,i,n,r,a,h,l,u,d){w(this,B);w(this,no,new AbortController);w(this,os,null);w(this,re,new Map);w(this,pe,new Map);w(this,ro,null);w(this,qi,null);w(this,ao,null);w(this,Gs,new Xx);w(this,Nn,null);w(this,oo,0);w(this,jr,new Set);w(this,gi,null);w(this,Ys,null);w(this,Nr,new Set);w(this,qh,!1);w(this,$h,!1);w(this,ho,!1);w(this,Kh,null);w(this,fi,null);w(this,Bn,null);w(this,lo,null);w(this,Hn,!1);w(this,pi,null);w(this,Gu,new Wx);w(this,Wn,!1);w(this,Jh,!1);w(this,Xn,null);w(this,Br,null);w(this,Qh,null);w(this,Zh,null);w(this,de,nt.NONE);w(this,wt,new Set);w(this,$i,null);w(this,Hr,null);w(this,tl,null);w(this,el,{isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1});w(this,zn,[0,0]);w(this,mi,null);w(this,Ki,null);w(this,sl,null);w(this,Ss,null);const g=this._signal=c(this,no).signal;v(this,Ki,t),v(this,sl,e),v(this,ro,s),this._eventBus=i,i._on("editingaction",this.onEditingAction.bind(this),{signal:g}),i._on("pagechanging",this.onPageChanging.bind(this),{signal:g}),i._on("scalechanging",this.onScaleChanging.bind(this),{signal:g}),i._on("rotationchanging",this.onRotationChanging.bind(this),{signal:g}),i._on("setpreference",this.onSetPreference.bind(this),{signal:g}),i._on("switchannotationeditorparams",f=>this.updateParams(f.type,f.value),{signal:g}),y(this,B,ob).call(this),y(this,B,ub).call(this),y(this,B,Lf).call(this),v(this,qi,n.annotationStorage),v(this,Kh,n.filterFactory),v(this,Hr,r),v(this,lo,a||null),v(this,qh,h),v(this,$h,l),v(this,ho,u),v(this,Zh,d||null),this.viewParameters={realScale:Rn.PDF_TO_CSS_UNITS,rotation:0},this.isShiftKeyDown=!1}static get _keyboardManager(){const t=co.prototype,e=r=>c(r,Ki).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 ut(this,"_keyboardManager",new Fh([[["ctrl+a","mac+meta+a"],t.selectAll,{checker:s}],[["ctrl+z","mac+meta+z"],t.undo,{checker:s}],[["ctrl+y","ctrl+shift+z","mac+meta+shift+z","ctrl+shift+Z","mac+meta+shift+Z"],t.redo,{checker:s}],[["Backspace","alt+Backspace","ctrl+Backspace","shift+Backspace","mac+Backspace","mac+alt+Backspace","mac+ctrl+Backspace","Delete","ctrl+Delete","shift+Delete","mac+Delete"],t.delete,{checker:s}],[["Enter","mac+Enter"],t.addNewEditorFromKeyboard,{checker:(r,{target:a})=>!(a instanceof HTMLButtonElement)&&c(r,Ki).contains(a)&&!r.isEnterHandled}],[[" ","mac+ "],t.addNewEditorFromKeyboard,{checker:(r,{target:a})=>!(a instanceof HTMLButtonElement)&&c(r,Ki).contains(document.activeElement)}],[["Escape","mac+Escape"],t.unselectAll],[["ArrowLeft","mac+ArrowLeft"],t.translateSelectedEditors,{args:[-i,0],checker:e}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t.translateSelectedEditors,{args:[-n,0],checker:e}],[["ArrowRight","mac+ArrowRight"],t.translateSelectedEditors,{args:[i,0],checker:e}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t.translateSelectedEditors,{args:[n,0],checker:e}],[["ArrowUp","mac+ArrowUp"],t.translateSelectedEditors,{args:[0,-i],checker:e}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t.translateSelectedEditors,{args:[0,-n],checker:e}],[["ArrowDown","mac+ArrowDown"],t.translateSelectedEditors,{args:[0,i],checker:e}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t.translateSelectedEditors,{args:[0,n],checker:e}]]))}destroy(){var t,e,s,i;(t=c(this,Ss))==null||t.resolve(),v(this,Ss,null),(e=c(this,no))==null||e.abort(),v(this,no,null),this._signal=null;for(const n of c(this,pe).values())n.destroy();c(this,pe).clear(),c(this,re).clear(),c(this,Nr).clear(),v(this,os,null),c(this,wt).clear(),c(this,Gs).destroy(),(s=c(this,ro))==null||s.destroy(),(i=c(this,pi))==null||i.hide(),v(this,pi,null),c(this,fi)&&(clearTimeout(c(this,fi)),v(this,fi,null)),c(this,mi)&&(clearTimeout(c(this,mi)),v(this,mi,null))}combinedSignal(t){return AbortSignal.any([this._signal,t.signal])}get mlManager(){return c(this,Zh)}get useNewAltTextFlow(){return c(this,$h)}get useNewAltTextWhenAddingImage(){return c(this,ho)}get hcmFilter(){return ut(this,"hcmFilter",c(this,Hr)?c(this,Kh).addHCMFilter(c(this,Hr).foreground,c(this,Hr).background):"none")}get direction(){return ut(this,"direction",getComputedStyle(c(this,Ki)).direction)}get highlightColors(){return ut(this,"highlightColors",c(this,lo)?new Map(c(this,lo).split(",").map(t=>t.split("=").map(e=>e.trim()))):null)}get highlightColorNames(){return ut(this,"highlightColorNames",this.highlightColors?new Map(Array.from(this.highlightColors,t=>t.reverse())):null)}setMainHighlightColorPicker(t){v(this,Qh,t)}editAltText(t,e=!1){var s;(s=c(this,ro))==null||s.editAltText(this,t,e)}switchToMode(t,e){this._eventBus.on("annotationeditormodechanged",e,{once:!0,signal:this._signal}),this._eventBus.dispatch("showannotationeditorui",{source:this,mode:t})}setPreference(t,e){this._eventBus.dispatch("setpreference",{source:this,name:t,value:e})}onSetPreference({name:t,value:e}){switch(t){case"enableNewAltTextWhenAddingImage":v(this,ho,e);break}}onPageChanging({pageNumber:t}){v(this,oo,t-1)}focusMainContainer(){c(this,Ki).focus()}findParent(t,e){for(const s of c(this,pe).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){c(this,sl).classList.toggle("noUserSelect",t)}addShouldRescale(t){c(this,Nr).add(t)}removeShouldRescale(t){c(this,Nr).delete(t)}onScaleChanging({scale:t}){this.commitOrRemove(),this.viewParameters.realScale=t*Rn.PDF_TO_CSS_UNITS;for(const e of c(this,Nr))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(),l=y(this,B,cd).call(this,e).closest(".textLayer"),u=this.getSelectionBoxes(l);if(!u)return;e.empty();const d=y(this,B,Ff).call(this,l),g=c(this,de)===nt.NONE,f=()=>{d==null||d.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:t,boxes:u,anchorNode:s,anchorOffset:i,focusNode:n,focusOffset:r,text:a}),g&&this.showAllEditors("highlight",!0,!0)};if(g){this.switchToMode(nt.HIGHLIGHT,f);return}f()}addToAnnotationStorage(t){!t.isEmpty()&&c(this,qi)&&!c(this,qi).has(t.id)&&c(this,qi).setValue(t.id,t)}blur(){if(this.isShiftKeyDown=!1,c(this,Hn)&&(v(this,Hn,!1),y(this,B,ud).call(this,"main_toolbar")),!this.hasSelection)return;const{activeElement:t}=document;for(const e of c(this,wt))if(e.div.contains(t)){v(this,Br,[e,t]),e._focusEventsAllowed=!1;break}}focus(){if(!c(this,Br))return;const[t,e]=c(this,Br);v(this,Br,null),e.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this._signal}),e.focus()}addEditListeners(){y(this,B,Lf).call(this),y(this,B,If).call(this)}removeEditListeners(){y(this,B,cb).call(this),y(this,B,jf).call(this)}dragOver(t){for(const{type:e}of t.dataTransfer.items)for(const s of c(this,Ys))if(s.isHandlingMimeForPasting(e)){t.dataTransfer.dropEffect="copy",t.preventDefault();return}}drop(t){for(const e of t.dataTransfer.items)for(const s of c(this,Ys))if(s.isHandlingMimeForPasting(e.type)){s.paste(e,this.currentLayer),t.preventDefault();return}}copy(t){var s;if(t.preventDefault(),(s=c(this,os))==null||s.commitOrRemove(),!this.hasSelection)return;const e=[];for(const i of c(this,wt)){const n=i.serialize(!0);n&&e.push(n)}e.length!==0&&t.clipboardData.setData("application/pdfjs",JSON.stringify(e))}cut(t){this.copy(t),this.delete()}async paste(t){t.preventDefault();const{clipboardData:e}=t;for(const n of e.items)for(const r of c(this,Ys))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){at(`paste: "${n.message}".`);return}if(!Array.isArray(s))return;this.unselectAll();const i=this.currentLayer;try{const n=[];for(const h of s){const l=await i.deserialize(h);if(!l)return;n.push(l)}const r=()=>{for(const h of n)y(this,B,Nf).call(this,h);y(this,B,Bf).call(this,n)},a=()=>{for(const h of n)h.remove()};this.addCommands({cmd:r,undo:a,mustExec:!0})}catch(n){at(`paste: "${n.message}".`)}}keydown(t){!this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!0),c(this,de)!==nt.NONE&&!this.isEditorHandlingKeyboard&&co._keyboardManager.exec(this,t)}keyup(t){this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!1,c(this,Hn)&&(v(this,Hn,!1),y(this,B,ud).call(this,"main_toolbar")))}onEditingAction({name:t}){switch(t){case"undo":case"redo":case"delete":case"selectAll":this[t]();break;case"highlightSelection":this.highlightSelection("context_menu");break}}setEditingState(t){t?(y(this,B,hb).call(this),y(this,B,If).call(this),y(this,B,Ye).call(this,{isEditing:c(this,de)!==nt.NONE,isEmpty:y(this,B,ac).call(this),hasSomethingToUndo:c(this,Gs).hasSomethingToUndo(),hasSomethingToRedo:c(this,Gs).hasSomethingToRedo(),hasSelectedEditor:!1})):(y(this,B,lb).call(this),y(this,B,jf).call(this),y(this,B,Ye).call(this,{isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(t){if(!c(this,Ys)){v(this,Ys,t);for(const e of c(this,Ys))y(this,B,cr).call(this,e.defaultPropertiesToUpdate)}}getId(){return c(this,Gu).id}get currentLayer(){return c(this,pe).get(c(this,oo))}getLayer(t){return c(this,pe).get(t)}get currentPageIndex(){return c(this,oo)}addLayer(t){c(this,pe).set(t.pageIndex,t),c(this,Wn)?t.enable():t.disable()}removeLayer(t){c(this,pe).delete(t.pageIndex)}async updateMode(t,e=null,s=!1){if(c(this,de)!==t&&!(c(this,Ss)&&(await c(this,Ss).promise,!c(this,Ss)))){if(v(this,Ss,Promise.withResolvers()),v(this,de,t),t===nt.NONE){this.setEditingState(!1),y(this,B,gb).call(this),c(this,Ss).resolve();return}this.setEditingState(!0),await y(this,B,db).call(this),this.unselectAll();for(const i of c(this,pe).values())i.updateMode(t);if(!e){s&&this.addNewEditorFromKeyboard(),c(this,Ss).resolve();return}for(const i of c(this,re).values())i.annotationElementId===e?(this.setSelected(i),i.enterInEditMode()):i.unselect();c(this,Ss).resolve()}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(t){t!==c(this,de)&&this._eventBus.dispatch("switchannotationeditormode",{source:this,mode:t})}updateParams(t,e){var s;if(c(this,Ys)){switch(t){case Z.CREATE:this.currentLayer.addNewEditor();return;case Z.HIGHLIGHT_DEFAULT_COLOR:(s=c(this,Qh))==null||s.updateColor(e);break;case Z.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:{type:"highlight",action:"toggle_visibility"}}}),(c(this,tl)||v(this,tl,new Map)).set(t,e),this.showAllEditors("highlight",e);break}for(const i of c(this,wt))i.updateParams(t,e);for(const i of c(this,Ys))i.updateDefaultParams(t,e)}}showAllEditors(t,e,s=!1){var n;for(const r of c(this,re).values())r.editorType===t&&r.show(e);(((n=c(this,tl))==null?void 0:n.get(Z.HIGHLIGHT_SHOW_ALL))??!0)!==e&&y(this,B,cr).call(this,[[Z.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(c(this,Jh)!==t){v(this,Jh,t);for(const e of c(this,pe).values())t?e.disableClick():e.enableClick(),e.div.classList.toggle("waiting",t)}}getEditors(t){const e=[];for(const s of c(this,re).values())s.pageIndex===t&&e.push(s);return e}getEditor(t){return c(this,re).get(t)}addEditor(t){c(this,re).set(t.id,t)}removeEditor(t){var e;t.div.contains(document.activeElement)&&(c(this,fi)&&clearTimeout(c(this,fi)),v(this,fi,setTimeout(()=>{this.focusMainContainer(),v(this,fi,null)},0))),c(this,re).delete(t.id),this.unselect(t),(!t.annotationElementId||!c(this,jr).has(t.annotationElementId))&&((e=c(this,qi))==null||e.remove(t.id))}addDeletedAnnotationElement(t){c(this,jr).add(t.annotationElementId),this.addChangedExistingAnnotation(t),t.deleted=!0}isDeletedAnnotationElement(t){return c(this,jr).has(t)}removeDeletedAnnotationElement(t){c(this,jr).delete(t.annotationElementId),this.removeChangedExistingAnnotation(t),t.deleted=!1}setActiveEditor(t){c(this,os)!==t&&(v(this,os,t),t&&y(this,B,cr).call(this,t.propertiesToUpdate))}updateUI(t){c(this,B,fb)===t&&y(this,B,cr).call(this,t.propertiesToUpdate)}toggleSelected(t){if(c(this,wt).has(t)){c(this,wt).delete(t),t.unselect(),y(this,B,Ye).call(this,{hasSelectedEditor:this.hasSelection});return}c(this,wt).add(t),t.select(),y(this,B,cr).call(this,t.propertiesToUpdate),y(this,B,Ye).call(this,{hasSelectedEditor:!0})}setSelected(t){for(const e of c(this,wt))e!==t&&e.unselect();c(this,wt).clear(),c(this,wt).add(t),t.select(),y(this,B,cr).call(this,t.propertiesToUpdate),y(this,B,Ye).call(this,{hasSelectedEditor:!0})}isSelected(t){return c(this,wt).has(t)}get firstSelectedEditor(){return c(this,wt).values().next().value}unselect(t){t.unselect(),c(this,wt).delete(t),y(this,B,Ye).call(this,{hasSelectedEditor:this.hasSelection})}get hasSelection(){return c(this,wt).size!==0}get isEnterHandled(){return c(this,wt).size===1&&this.firstSelectedEditor.isEnterHandled}undo(){c(this,Gs).undo(),y(this,B,Ye).call(this,{hasSomethingToUndo:c(this,Gs).hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:y(this,B,ac).call(this)})}redo(){c(this,Gs).redo(),y(this,B,Ye).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:c(this,Gs).hasSomethingToRedo(),isEmpty:y(this,B,ac).call(this)})}addCommands(t){c(this,Gs).add(t),y(this,B,Ye).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:y(this,B,ac).call(this)})}delete(){if(this.commitOrRemove(),!this.hasSelection)return;const t=[...c(this,wt)],e=()=>{for(const i of t)i.remove()},s=()=>{for(const i of t)y(this,B,Nf).call(this,i)};this.addCommands({cmd:e,undo:s,mustExec:!0})}commitOrRemove(){var t;(t=c(this,os))==null||t.commitOrRemove()}hasSomethingToControl(){return c(this,os)||this.hasSelection}selectAll(){for(const t of c(this,wt))t.commit();y(this,B,Bf).call(this,c(this,re).values())}unselectAll(){if(!(c(this,os)&&(c(this,os).commitOrRemove(),c(this,de)!==nt.NONE))&&this.hasSelection){for(const t of c(this,wt))t.unselect();c(this,wt).clear(),y(this,B,Ye).call(this,{hasSelectedEditor:!1})}}translateSelectedEditors(t,e,s=!1){if(s||this.commitOrRemove(),!this.hasSelection)return;c(this,zn)[0]+=t,c(this,zn)[1]+=e;const[i,n]=c(this,zn),r=[...c(this,wt)],a=1e3;c(this,mi)&&clearTimeout(c(this,mi)),v(this,mi,setTimeout(()=>{v(this,mi,null),c(this,zn)[0]=c(this,zn)[1]=0,this.addCommands({cmd:()=>{for(const h of r)c(this,re).has(h.id)&&h.translateInPage(i,n)},undo:()=>{for(const h of r)c(this,re).has(h.id)&&h.translateInPage(-i,-n)},mustExec:!1})},a));for(const h of r)h.translateInPage(t,e)}setUpDragSession(){if(this.hasSelection){this.disableUserSelect(!0),v(this,gi,new Map);for(const t of c(this,wt))c(this,gi).set(t,{savedX:t.x,savedY:t.y,savedPageIndex:t.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!c(this,gi))return!1;this.disableUserSelect(!1);const t=c(this,gi);v(this,gi,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(c(this,re).has(i.id)){const h=c(this,pe).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(c(this,gi))for(const s of c(this,gi).keys())s.drag(t,e)}rebuild(t){if(t.parent===null){const e=this.getLayer(t.pageIndex);e?(e.changeParent(t),e.addOrRebuild(t)):(this.addEditor(t),this.addToAnnotationStorage(t),t.rebuild())}else t.parent.addOrRebuild(t)}get isEditorHandlingKeyboard(){var t;return((t=this.getActive())==null?void 0:t.shouldGetKeyboardEvents())||c(this,wt).size===1&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(t){return c(this,os)===t}getActive(){return c(this,os)}getMode(){return c(this,de)}get imageManager(){return ut(this,"imageManager",new Kg)}getSelectionBoxes(t){if(!t)return null;const e=document.getSelection();for(let l=0,u=e.rangeCount;l<u;l++)if(!t.contains(e.getRangeAt(l).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=(l,u,d,g)=>({x:(u-i)/r,y:1-(l+d-s)/n,width:g/r,height:d/n});break;case"180":a=(l,u,d,g)=>({x:1-(l+d-s)/n,y:1-(u+g-i)/r,width:d/n,height:g/r});break;case"270":a=(l,u,d,g)=>({x:1-(u+g-i)/r,y:(l-s)/n,width:g/r,height:d/n});break;default:a=(l,u,d,g)=>({x:(l-s)/n,y:(u-i)/r,width:d/n,height:g/r});break}const h=[];for(let l=0,u=e.rangeCount;l<u;l++){const d=e.getRangeAt(l);if(!d.collapsed)for(const{x:g,y:f,width:p,height:m}of d.getClientRects())p===0||m===0||h.push(a(g,f,p,m))}return h.length===0?null:h}addChangedExistingAnnotation({annotationElementId:t,id:e}){(c(this,ao)||v(this,ao,new Map)).set(t,e)}removeChangedExistingAnnotation({annotationElementId:t}){var e;(e=c(this,ao))==null||e.delete(t)}renderAnnotationElement(t){var i;const e=(i=c(this,ao))==null?void 0:i.get(t.data.id);if(!e)return;const s=c(this,qi).getRawValue(e);s&&(c(this,de)===nt.NONE&&!s.hasBeenModified||s.renderAnnotationElement(t))}};no=new WeakMap,os=new WeakMap,re=new WeakMap,pe=new WeakMap,ro=new WeakMap,qi=new WeakMap,ao=new WeakMap,Gs=new WeakMap,Nn=new WeakMap,oo=new WeakMap,jr=new WeakMap,gi=new WeakMap,Ys=new WeakMap,Nr=new WeakMap,qh=new WeakMap,$h=new WeakMap,ho=new WeakMap,Kh=new WeakMap,fi=new WeakMap,Bn=new WeakMap,lo=new WeakMap,Hn=new WeakMap,pi=new WeakMap,Gu=new WeakMap,Wn=new WeakMap,Jh=new WeakMap,Xn=new WeakMap,Br=new WeakMap,Qh=new WeakMap,Zh=new WeakMap,de=new WeakMap,wt=new WeakMap,$i=new WeakMap,Hr=new WeakMap,tl=new WeakMap,el=new WeakMap,zn=new WeakMap,mi=new WeakMap,Ki=new WeakMap,sl=new WeakMap,Ss=new WeakMap,B=new WeakSet,cd=function({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t},Ff=function(t){const{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(const s of c(this,pe).values())if(s.hasTextLayer(t))return s;return null},rb=function(){const t=document.getSelection();if(!t||t.isCollapsed)return;const s=y(this,B,cd).call(this,t).closest(".textLayer"),i=this.getSelectionBoxes(s);i&&(c(this,pi)||v(this,pi,new Bx(this)),c(this,pi).show(s,i,this.direction==="ltr"))},ab=function(){var n,r,a;const t=document.getSelection();if(!t||t.isCollapsed){c(this,$i)&&((n=c(this,pi))==null||n.hide(),v(this,$i,null),y(this,B,Ye).call(this,{hasSelectedText:!1}));return}const{anchorNode:e}=t;if(e===c(this,$i))return;const i=y(this,B,cd).call(this,t).closest(".textLayer");if(!i){c(this,$i)&&((r=c(this,pi))==null||r.hide(),v(this,$i,null),y(this,B,Ye).call(this,{hasSelectedText:!1}));return}if((a=c(this,pi))==null||a.hide(),v(this,$i,e),y(this,B,Ye).call(this,{hasSelectedText:!0}),!(c(this,de)!==nt.HIGHLIGHT&&c(this,de)!==nt.NONE)&&(c(this,de)===nt.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0),v(this,Hn,this.isShiftKeyDown),!this.isShiftKeyDown)){const h=c(this,de)===nt.HIGHLIGHT?y(this,B,Ff).call(this,i):null;h==null||h.toggleDrawing();const l=new AbortController,u=this.combinedSignal(l),d=g=>{g.type==="pointerup"&&g.button!==0||(l.abort(),h==null||h.toggleDrawing(!0),g.type==="pointerup"&&y(this,B,ud).call(this,"main_toolbar"))};window.addEventListener("pointerup",d,{signal:u}),window.addEventListener("blur",d,{signal:u})}},ud=function(t=""){c(this,de)===nt.HIGHLIGHT?this.highlightSelection(t):c(this,qh)&&y(this,B,rb).call(this)},ob=function(){document.addEventListener("selectionchange",y(this,B,ab).bind(this),{signal:this._signal})},hb=function(){if(c(this,Bn))return;v(this,Bn,new AbortController);const t=this.combinedSignal(c(this,Bn));window.addEventListener("focus",this.focus.bind(this),{signal:t}),window.addEventListener("blur",this.blur.bind(this),{signal:t})},lb=function(){var t;(t=c(this,Bn))==null||t.abort(),v(this,Bn,null)},Lf=function(){if(c(this,Xn))return;v(this,Xn,new AbortController);const t=this.combinedSignal(c(this,Xn));window.addEventListener("keydown",this.keydown.bind(this),{signal:t}),window.addEventListener("keyup",this.keyup.bind(this),{signal:t})},cb=function(){var t;(t=c(this,Xn))==null||t.abort(),v(this,Xn,null)},If=function(){if(c(this,Nn))return;v(this,Nn,new AbortController);const t=this.combinedSignal(c(this,Nn));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})},jf=function(){var t;(t=c(this,Nn))==null||t.abort(),v(this,Nn,null)},ub=function(){const t=this._signal;document.addEventListener("dragover",this.dragOver.bind(this),{signal:t}),document.addEventListener("drop",this.drop.bind(this),{signal:t})},Ye=function(t){Object.entries(t).some(([s,i])=>c(this,el)[s]!==i)&&(this._eventBus.dispatch("annotationeditorstateschanged",{source:this,details:Object.assign(c(this,el),t)}),c(this,de)===nt.HIGHLIGHT&&t.hasSelectedEditor===!1&&y(this,B,cr).call(this,[[Z.HIGHLIGHT_FREE,!0]]))},cr=function(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})},db=async function(){if(!c(this,Wn)){v(this,Wn,!0);const t=[];for(const e of c(this,pe).values())t.push(e.enable());await Promise.all(t);for(const e of c(this,re).values())e.enable()}},gb=function(){if(this.unselectAll(),c(this,Wn)){v(this,Wn,!1);for(const t of c(this,pe).values())t.disable();for(const t of c(this,re).values())t.disable()}},Nf=function(t){const e=c(this,pe).get(t.pageIndex);e?e.addOrRebuild(t):(this.addEditor(t),this.addToAnnotationStorage(t))},fb=function(){let t=null;for(t of c(this,wt));return t},ac=function(){if(c(this,re).size===0)return!0;if(c(this,re).size===1)for(const t of c(this,re).values())return t.isEmpty();return!1},Bf=function(t){for(const e of c(this,wt))e.unselect();c(this,wt).clear();for(const e of t)e.isEmpty()||(c(this,wt).add(e),e.select());y(this,B,Ye).call(this,{hasSelectedEditor:this.hasSelection})},tt(co,"TRANSLATE_SMALL",1),tt(co,"TRANSLATE_BIG",10);let Mr=co;const We=class We{constructor(t){w(this,qs);w(this,ge,null);w(this,vi,!1);w(this,Us,null);w(this,uo,null);w(this,bi,null);w(this,hs,null);w(this,go,!1);w(this,yi,null);w(this,Je,null);w(this,Ji,null);w(this,Wr,null);w(this,_i,!1);v(this,Je,t),v(this,_i,t._uiManager.useNewAltTextFlow),c(We,Vn)||v(We,Vn,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){We._l10n??(We._l10n=t)}async render(){const t=v(this,Us,document.createElement("button"));t.className="altText",t.tabIndex="0";const e=v(this,uo,document.createElement("span"));t.append(e),c(this,_i)?(t.classList.add("new"),t.setAttribute("data-l10n-id",c(We,Vn).missing),e.setAttribute("data-l10n-id",c(We,Vn)["missing-label"])):(t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button"),e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button-label"));const s=c(this,Je)._uiManager._signal;t.addEventListener("contextmenu",ws,{signal:s}),t.addEventListener("pointerdown",n=>n.stopPropagation(),{signal:s});const i=n=>{n.preventDefault(),c(this,Je)._uiManager.editAltText(c(this,Je)),c(this,_i)&&c(this,Je)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_clicked",data:{label:c(this,qs,oc)}})};return t.addEventListener("click",i,{capture:!0,signal:s}),t.addEventListener("keydown",n=>{n.target===t&&n.key==="Enter"&&(v(this,go,!0),i(n))},{signal:s}),await y(this,qs,dd).call(this),t}finish(){c(this,Us)&&(c(this,Us).focus({focusVisible:c(this,go)}),v(this,go,!1))}isEmpty(){return c(this,_i)?c(this,ge)===null:!c(this,ge)&&!c(this,vi)}hasData(){return c(this,_i)?c(this,ge)!==null||!!c(this,Ji):this.isEmpty()}get guessedText(){return c(this,Ji)}async setGuessedText(t){c(this,ge)===null&&(v(this,Ji,t),v(this,Wr,await We._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",{generatedAltText:t})),y(this,qs,dd).call(this))}toggleAltTextBadge(t=!1){var e;if(!c(this,_i)||c(this,ge)){(e=c(this,yi))==null||e.remove(),v(this,yi,null);return}if(!c(this,yi)){const s=v(this,yi,document.createElement("div"));s.className="noAltTextBadge",c(this,Je).div.append(s)}c(this,yi).classList.toggle("hidden",!t)}serialize(t){let e=c(this,ge);return!t&&c(this,Ji)===e&&(e=c(this,Wr)),{altText:e,decorative:c(this,vi),guessedText:c(this,Ji),textWithDisclaimer:c(this,Wr)}}get data(){return{altText:c(this,ge),decorative:c(this,vi)}}set data({altText:t,decorative:e,guessedText:s,textWithDisclaimer:i,cancel:n=!1}){s&&(v(this,Ji,s),v(this,Wr,i)),!(c(this,ge)===t&&c(this,vi)===e)&&(n||(v(this,ge,t),v(this,vi,e)),y(this,qs,dd).call(this))}toggle(t=!1){c(this,Us)&&(!t&&c(this,hs)&&(clearTimeout(c(this,hs)),v(this,hs,null)),c(this,Us).disabled=!t)}shown(){c(this,Je)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_displayed",data:{label:c(this,qs,oc)}})}destroy(){var t,e;(t=c(this,Us))==null||t.remove(),v(this,Us,null),v(this,uo,null),v(this,bi,null),(e=c(this,yi))==null||e.remove(),v(this,yi,null)}};ge=new WeakMap,vi=new WeakMap,Us=new WeakMap,uo=new WeakMap,bi=new WeakMap,hs=new WeakMap,go=new WeakMap,yi=new WeakMap,Je=new WeakMap,Ji=new WeakMap,Wr=new WeakMap,_i=new WeakMap,Vn=new WeakMap,qs=new WeakSet,oc=function(){return c(this,ge)&&"added"||c(this,ge)===null&&this.guessedText&&"review"||"missing"},dd=async function(){var i,n,r;const t=c(this,Us);if(!t)return;if(c(this,_i)){if(t.classList.toggle("done",!!c(this,ge)),t.setAttribute("data-l10n-id",c(We,Vn)[c(this,qs,oc)]),(i=c(this,uo))==null||i.setAttribute("data-l10n-id",c(We,Vn)[`${c(this,qs,oc)}-label`]),!c(this,ge)){(n=c(this,bi))==null||n.remove();return}}else{if(!c(this,ge)&&!c(this,vi)){t.classList.remove("done"),(r=c(this,bi))==null||r.remove();return}t.classList.add("done"),t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-edit-button")}let e=c(this,bi);if(!e){v(this,bi,e=document.createElement("span")),e.className="tooltip",e.setAttribute("role","tooltip"),e.id=`alt-text-tooltip-${c(this,Je).id}`;const a=100,h=c(this,Je)._uiManager._signal;h.addEventListener("abort",()=>{clearTimeout(c(this,hs)),v(this,hs,null)},{once:!0}),t.addEventListener("mouseenter",()=>{v(this,hs,setTimeout(()=>{v(this,hs,null),c(this,bi).classList.add("show"),c(this,Je)._reportTelemetry({action:"alt_text_tooltip"})},a))},{signal:h}),t.addEventListener("mouseleave",()=>{var l;c(this,hs)&&(clearTimeout(c(this,hs)),v(this,hs,null)),(l=c(this,bi))==null||l.classList.remove("show")},{signal:h})}c(this,vi)?e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-decorative-tooltip"):(e.removeAttribute("data-l10n-id"),e.textContent=c(this,ge)),e.parentNode||t.append(e);const s=c(this,Je).getImageForAltText();s==null||s.setAttribute("aria-describedby",e.id)},w(We,Vn,null),tt(We,"_l10n",null);let Ou=We;const vt=class vt{constructor(t){w(this,rt);w(this,Xr,null);w(this,$s,null);w(this,jt,null);w(this,fo,!1);w(this,zr,!1);w(this,me,null);w(this,Vr,null);w(this,Gn,null);w(this,il,"");w(this,Gr,!1);w(this,Yn,null);w(this,nl,!1);w(this,Yr,!1);w(this,Qi,!1);w(this,wi,null);w(this,po,0);w(this,mo,0);w(this,Cs,null);tt(this,"_editToolbar",null);tt(this,"_initialOptions",Object.create(null));tt(this,"_initialData",null);tt(this,"_isVisible",!0);tt(this,"_uiManager",null);tt(this,"_focusEventsAllowed",!0);w(this,rl,!1);w(this,Yu,vt._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=vt.prototype._resizeWithKeyboard,e=Mr.TRANSLATE_SMALL,s=Mr.TRANSLATE_BIG;return ut(this,"_resizerKeyboardManager",new Fh([[["ArrowLeft","mac+ArrowLeft"],t,{args:[-e,0]}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t,{args:[-s,0]}],[["ArrowRight","mac+ArrowRight"],t,{args:[e,0]}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t,{args:[s,0]}],[["ArrowUp","mac+ArrowUp"],t,{args:[0,-e]}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t,{args:[0,-s]}],[["ArrowDown","mac+ArrowDown"],t,{args:[0,e]}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t,{args:[0,s]}],[["Escape","mac+Escape"],vt.prototype._stopResizingWithKeyboard]]))}get editorType(){return Object.getPrototypeOf(this).constructor._type}static get _defaultLineColor(){return ut(this,"_defaultLineColor",this._colorManager.getHexCode("CanvasText"))}static deleteAnnotationElement(t){const e=new zx({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(vt._l10n??(vt._l10n=t),vt._l10nResizer||(vt._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"})),vt._borderLineWidth!==-1)return;const s=getComputedStyle(document.documentElement);vt._borderLineWidth=parseFloat(s.getPropertyValue("--outline-width"))||0}static updateDefaultParams(t,e){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(t){return!1}static paste(t,e){Mt("Not implemented")}get propertiesToUpdate(){return[]}get _isDraggable(){return c(this,rl)}set _isDraggable(t){var e;v(this,rl,t),(e=this.div)==null||e.classList.toggle("draggable",t)}get isEnterHandled(){return!0}center(){const[t,e]=this.pageDimensions;switch(this.parentRotation){case 90:this.x-=this.height*e/(t*2),this.y+=this.width*t/(e*2);break;case 180:this.x+=this.width/2,this.y+=this.height/2;break;case 270:this.x+=this.height*e/(t*2),this.y-=this.width*t/(e*2);break;default:this.x-=this.width/2,this.y-=this.height/2;break}this.fixAndSetPosition()}addCommands(t){this._uiManager.addCommands(t)}get currentLayer(){return this._uiManager.currentLayer}setInBackground(){this.div.style.zIndex=0}setInForeground(){this.div.style.zIndex=c(this,Yu)}setParent(t){t!==null?(this.pageIndex=t.pageIndex,this.pageDimensions=t.pageDimensions):y(this,rt,hc).call(this),this.parent=t}focusin(t){this._focusEventsAllowed&&(c(this,Gr)?v(this,Gr,!1):this.parent.setSelected(this))}focusout(t){var s;if(!this._focusEventsAllowed||!this.isAttachedToDOM)return;const e=t.relatedTarget;e!=null&&e.closest(`#${this.id}`)||(t.preventDefault(),(s=this.parent)!=null&&s.isMultipleSelection||this.commitOrRemove())}commitOrRemove(){this.isEmpty()?this.remove():this.commit()}commit(){this.addToAnnotationStorage()}addToAnnotationStorage(){this._uiManager.addToAnnotationStorage(this)}setAt(t,e,s,i){const[n,r]=this.parentDimensions;[s,i]=this.screenToPageTranslation(s,i),this.x=(t+s)/n,this.y=(e+i)/r,this.fixAndSetPosition()}translate(t,e){y(this,rt,Hf).call(this,this.parentDimensions,t,e)}translateInPage(t,e){c(this,Yn)||v(this,Yn,[this.x,this.y]),y(this,rt,Hf).call(this,this.pageDimensions,t,e),this.div.scrollIntoView({block:"nearest"})}drag(t,e){c(this,Yn)||v(this,Yn,[this.x,this.y]);const[s,i]=this.parentDimensions;if(this.x+=t/s,this.y+=e/i,this.parent&&(this.x<0||this.x>1||this.y<0||this.y>1)){const{x:l,y:u}=this.div.getBoundingClientRect();this.parent.findNewParent(this,l,u)&&(this.x-=Math.floor(this.x),this.y-=Math.floor(this.y))}let{x:n,y:r}=this;const[a,h]=this.getBaseTranslation();n+=a,r+=h,this.div.style.left=`${(100*n).toFixed(2)}%`,this.div.style.top=`${(100*r).toFixed(2)}%`,this.div.scrollIntoView({block:"nearest"})}get _hasBeenMoved(){return!!c(this,Yn)&&(c(this,Yn)[0]!==this.x||c(this,Yn)[1]!==this.y)}getBaseTranslation(){const[t,e]=this.parentDimensions,{_borderLineWidth:s}=vt,i=s/t,n=s/e;switch(this.rotation){case 90:return[-i,n];case 180:return[i,n];case 270:return[i,-n];default:return[-i,-n]}}get _mustFixPosition(){return!0}fixAndSetPosition(t=this.rotation){const[e,s]=this.pageDimensions;let{x:i,y:n,width:r,height:a}=this;if(r*=e,a*=s,i*=e,n*=s,this._mustFixPosition)switch(t){case 0:i=Math.max(0,Math.min(e-r,i)),n=Math.max(0,Math.min(s-a,n));break;case 90:i=Math.max(0,Math.min(e-a,i)),n=Math.min(s,Math.max(r,n));break;case 180:i=Math.min(e,Math.max(r,i)),n=Math.min(s,Math.max(a,n));break;case 270:i=Math.min(e,Math.max(a,i)),n=Math.max(0,Math.min(s-r,n));break}this.x=i/=e,this.y=n/=s;const[h,l]=this.getBaseTranslation();i+=h,n+=l;const{style:u}=this.div;u.left=`${(100*i).toFixed(2)}%`,u.top=`${(100*n).toFixed(2)}%`,this.moveInDOM()}screenToPageTranslation(t,e){var s;return y(s=vt,al,Wf).call(s,t,e,this.parentRotation)}pageTranslationToScreen(t,e){var s;return y(s=vt,al,Wf).call(s,t,e,360-this.parentRotation)}get parentScale(){return this._uiManager.viewParameters.realScale}get parentRotation(){return(this._uiManager.viewParameters.rotation+this.pageRotation)%360}get parentDimensions(){const{parentScale:t,pageDimensions:[e,s]}=this;return[e*t,s*t]}setDims(t,e){const[s,i]=this.parentDimensions;this.div.style.width=`${(100*t/s).toFixed(2)}%`,c(this,zr)||(this.div.style.height=`${(100*e/i).toFixed(2)}%`)}fixDims(){const{style:t}=this.div,{height:e,width:s}=t,i=s.endsWith("%"),n=!c(this,zr)&&e.endsWith("%");if(i&&n)return;const[r,a]=this.parentDimensions;i||(t.width=`${(100*parseFloat(s)/r).toFixed(2)}%`),!c(this,zr)&&!n&&(t.height=`${(100*parseFloat(e)/a).toFixed(2)}%`)}getInitialTranslation(){return[0,0]}altTextFinish(){var t;(t=c(this,jt))==null||t.finish()}async addEditToolbar(){return this._editToolbar||c(this,Yr)?this._editToolbar:(this._editToolbar=new $g(this),this.div.append(this._editToolbar.render()),c(this,jt)&&await this._editToolbar.addAltText(c(this,jt)),this._editToolbar)}removeEditToolbar(){var t;this._editToolbar&&(this._editToolbar.remove(),this._editToolbar=null,(t=c(this,jt))==null||t.destroy())}addContainer(t){var s;const e=(s=this._editToolbar)==null?void 0:s.div;e?e.before(t):this.div.append(t)}getClientDimensions(){return this.div.getBoundingClientRect()}async addAltTextButton(){c(this,jt)||(Ou.initialize(vt._l10n),v(this,jt,new Ou(this)),c(this,Xr)&&(c(this,jt).data=c(this,Xr),v(this,Xr,null)),await this.addEditToolbar())}get altTextData(){var t;return(t=c(this,jt))==null?void 0:t.data}set altTextData(t){c(this,jt)&&(c(this,jt).data=t)}get guessedAltText(){var t;return(t=c(this,jt))==null?void 0:t.guessedText}async setGuessedAltText(t){var e;await((e=c(this,jt))==null?void 0:e.setGuessedText(t))}serializeAltText(t){var e;return(e=c(this,jt))==null?void 0:e.serialize(t)}hasAltText(){return!!c(this,jt)&&!c(this,jt).isEmpty()}hasAltTextData(){var t;return((t=c(this,jt))==null?void 0:t.hasData())??!1}render(){this.div=document.createElement("div"),this.div.setAttribute("data-editor-rotation",(360-this.rotation)%360),this.div.className=this.name,this.div.setAttribute("id",this.id),this.div.tabIndex=c(this,fo)?-1:0,this._isVisible||this.div.classList.add("hidden"),this.setInForeground(),y(this,rt,Yf).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),Mu(this,this.div,["pointerdown"]),this.div}pointerdown(t){const{isMac:e}=Ne.platform;if(t.button!==0||t.ctrlKey&&e){t.preventDefault();return}if(v(this,Gr,!0),this._isDraggable){y(this,rt,vb).call(this,t);return}y(this,rt,Gf).call(this,t)}get isSelected(){return this._uiManager.isSelected(this)}moveInDOM(){c(this,wi)&&clearTimeout(c(this,wi)),v(this,wi,setTimeout(()=>{var t;v(this,wi,null),(t=this.parent)==null||t.moveEditorInDOM(this)},0))}_setParentAndPosition(t,e,s){t.changeParent(this),this.x=e,this.y=s,this.fixAndSetPosition()}getRect(t,e,s=this.rotation){const i=this.parentScale,[n,r]=this.pageDimensions,[a,h]=this.pageTranslation,l=t/i,u=e/i,d=this.x*n,g=this.y*r,f=this.width*n,p=this.height*r;switch(s){case 0:return[d+l+a,r-g-u-p+h,d+l+f+a,r-g-u+h];case 90:return[d+u+a,r-g+l+h,d+u+p+a,r-g+l+f+h];case 180:return[d-l-f+a,r-g+u+h,d-l+a,r-g+u+p+h];case 270:return[d-u-p+a,r-g-l-f+h,d-u+a,r-g-l+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(){}isEmpty(){return!1}enableEditMode(){v(this,Yr,!0)}disableEditMode(){v(this,Yr,!1)}isInEditMode(){return c(this,Yr)}shouldGetKeyboardEvents(){return c(this,Qi)}needsToBeRebuilt(){return this.div&&!this.isAttachedToDOM}rebuild(){y(this,rt,Yf).call(this)}rotate(t){}serializeDeleted(){var t;return{id:this.annotationElementId,deleted:!0,pageIndex:this.pageIndex,popupRef:((t=this._initialData)==null?void 0:t.popupRef)||""}}serialize(t=!1,e=null){Mt("An editor must be serializable")}static async deserialize(t,e,s){const i=new this.prototype.constructor({parent:e,id:e.getNextId(),uiManager:s});i.rotation=t.rotation,v(i,Xr,t.accessibilityData);const[n,r]=i.pageDimensions,[a,h,l,u]=i.getRectInCurrentCoords(t.rect,r);return i.x=a/n,i.y=h/r,i.width=l/n,i.height=u/r,i}get hasBeenModified(){return!!this.annotationElementId&&(this.deleted||this.serialize()!==null)}remove(){var t;if((t=c(this,Gn))==null||t.abort(),v(this,Gn,null),this.isEmpty()||this.commit(),this.parent?this.parent.remove(this):this._uiManager.removeEditor(this),c(this,wi)&&(clearTimeout(c(this,wi)),v(this,wi,null)),y(this,rt,hc).call(this),this.removeEditToolbar(),c(this,Cs)){for(const e of c(this,Cs).values())clearTimeout(e);v(this,Cs,null)}this.parent=null}get isResizable(){return!1}makeResizable(){this.isResizable&&(y(this,rt,pb).call(this),c(this,me).classList.remove("hidden"),Mu(this,this.div,["keydown"]))}get toolbarPosition(){return null}keydown(t){if(!this.isResizable||t.target!==this.div||t.key!=="Enter")return;this._uiManager.setSelected(this),v(this,Vr,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height});const e=c(this,me).children;if(!c(this,$s)){v(this,$s,Array.from(e));const r=y(this,rt,bb).bind(this),a=y(this,rt,yb).bind(this),h=this._uiManager._signal;for(const l of c(this,$s)){const u=l.getAttribute("data-resizer-name");l.setAttribute("role","spinbutton"),l.addEventListener("keydown",r,{signal:h}),l.addEventListener("blur",a,{signal:h}),l.addEventListener("focus",y(this,rt,_b).bind(this,u),{signal:h}),l.setAttribute("data-l10n-id",vt._l10nResizer[u])}}const s=c(this,$s)[0];let i=0;for(const r of e){if(r===s)break;i++}const n=(360-this.rotation+this.parentRotation)%360/90*(c(this,$s).length/4);if(n!==i){if(n<i)for(let a=0;a<i-n;a++)c(this,me).append(c(this,me).firstChild);else if(n>i)for(let a=0;a<n-i;a++)c(this,me).firstChild.before(c(this,me).lastChild);let r=0;for(const a of e){const l=c(this,$s)[r++].getAttribute("data-resizer-name");a.setAttribute("data-l10n-id",vt._l10nResizer[l])}}y(this,rt,Uf).call(this,0),v(this,Qi,!0),c(this,me).firstChild.focus({focusVisible:!0}),t.preventDefault(),t.stopImmediatePropagation()}_resizeWithKeyboard(t,e){c(this,Qi)&&y(this,rt,Vf).call(this,c(this,il),{movementX:t,movementY:e})}_stopResizingWithKeyboard(){y(this,rt,hc).call(this),this.div.focus()}select(){var t,e,s;if(this.makeResizable(),(t=this.div)==null||t.classList.add("selectedEditor"),!this._editToolbar){this.addEditToolbar().then(()=>{var i,n;(i=this.div)!=null&&i.classList.contains("selectedEditor")&&((n=this._editToolbar)==null||n.show())});return}(e=this._editToolbar)==null||e.show(),(s=c(this,jt))==null||s.toggleAltTextBadge(!1)}unselect(){var t,e,s,i,n;(t=c(this,me))==null||t.classList.add("hidden"),(e=this.div)==null||e.classList.remove("selectedEditor"),(s=this.div)!=null&&s.contains(document.activeElement)&&this._uiManager.currentLayer.div.focus({preventScroll:!0}),(i=this._editToolbar)==null||i.hide(),(n=c(this,jt))==null||n.toggleAltTextBadge(!0)}updateParams(t,e){}disableEditing(){}enableEditing(){}enterInEditMode(){}getImageForAltText(){return null}get contentDiv(){return this.div}get isEditing(){return c(this,nl)}set isEditing(t){v(this,nl,t),this.parent&&(t?(this.parent.setSelected(this),this.parent.setActiveEditor(this)):this.parent.setActiveEditor(null))}setAspectRatio(t,e){v(this,zr,!0);const s=t/e,{style:i}=this.div;i.aspectRatio=s,i.height="auto"}static get MIN_SIZE(){return 16}static canCreateNewEmptyEditor(){return!0}get telemetryInitialData(){return{action:"added"}}get telemetryFinalData(){return null}_reportTelemetry(t,e=!1){if(e){c(this,Cs)||v(this,Cs,new Map);const{action:s}=t;let i=c(this,Cs).get(s);i&&clearTimeout(i),i=setTimeout(()=>{this._reportTelemetry(t),c(this,Cs).delete(s),c(this,Cs).size===0&&v(this,Cs,null)},vt._telemetryTimeout),c(this,Cs).set(s,i);return}t.type||(t.type=this.editorType),this._uiManager._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:t}})}show(t=this._isVisible){this.div.classList.toggle("hidden",!t),this._isVisible=t}enable(){this.div&&(this.div.tabIndex=0),v(this,fo,!1)}disable(){this.div&&(this.div.tabIndex=-1),v(this,fo,!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()}};Xr=new WeakMap,$s=new WeakMap,jt=new WeakMap,fo=new WeakMap,zr=new WeakMap,me=new WeakMap,Vr=new WeakMap,Gn=new WeakMap,il=new WeakMap,Gr=new WeakMap,Yn=new WeakMap,nl=new WeakMap,Yr=new WeakMap,Qi=new WeakMap,wi=new WeakMap,po=new WeakMap,mo=new WeakMap,Cs=new WeakMap,rl=new WeakMap,Yu=new WeakMap,rt=new WeakSet,Hf=function([t,e],s,i){[s,i]=this.screenToPageTranslation(s,i),this.x+=s/t,this.y+=i/e,this.fixAndSetPosition()},al=new WeakSet,Wf=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]}},Xf=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]}},pb=function(){if(c(this,me))return;v(this,me,document.createElement("div")),c(this,me).classList.add("resizers");const t=this._willKeepAspectRatio?["topLeft","topRight","bottomRight","bottomLeft"]:["topLeft","topMiddle","topRight","middleRight","bottomRight","bottomMiddle","bottomLeft","middleLeft"],e=this._uiManager._signal;for(const s of t){const i=document.createElement("div");c(this,me).append(i),i.classList.add("resizer",s),i.setAttribute("data-resizer-name",s),i.addEventListener("pointerdown",y(this,rt,mb).bind(this,s),{signal:e}),i.addEventListener("contextmenu",ws,{signal:e}),i.tabIndex=-1}this.div.prepend(c(this,me))},mb=function(t,e){var p;e.preventDefault();const{isMac:s}=Ne.platform;if(e.button!==0||e.ctrlKey&&s)return;(p=c(this,jt))==null||p.toggle(!1);const i=this._isDraggable;this._isDraggable=!1;const n=new AbortController,r=this._uiManager.combinedSignal(n);this.parent.togglePointerEvents(!1),window.addEventListener("pointermove",y(this,rt,Vf).bind(this,t),{passive:!0,capture:!0,signal:r}),window.addEventListener("contextmenu",ws,{signal:r});const a=this.x,h=this.y,l=this.width,u=this.height,d=this.parent.div.style.cursor,g=this.div.style.cursor;this.div.style.cursor=this.parent.div.style.cursor=window.getComputedStyle(e.target).cursor;const f=()=>{var m;n.abort(),this.parent.togglePointerEvents(!0),(m=c(this,jt))==null||m.toggle(!0),this._isDraggable=i,this.parent.div.style.cursor=d,this.div.style.cursor=g,y(this,rt,zf).call(this,a,h,l,u)};window.addEventListener("pointerup",f,{signal:r}),window.addEventListener("blur",f,{signal:r})},zf=function(t,e,s,i){const n=this.x,r=this.y,a=this.width,h=this.height;n===t&&r===e&&a===s&&h===i||this.addCommands({cmd:()=>{this.width=a,this.height=h,this.x=n,this.y=r;const[l,u]=this.parentDimensions;this.setDims(l*a,u*h),this.fixAndSetPosition()},undo:()=>{this.width=s,this.height=i,this.x=t,this.y=e;const[l,u]=this.parentDimensions;this.setDims(l*s,u*i),this.fixAndSetPosition()},mustExec:!0})},Vf=function(t,e){const[s,i]=this.parentDimensions,n=this.x,r=this.y,a=this.width,h=this.height,l=vt.MIN_SIZE/s,u=vt.MIN_SIZE/i,d=Y=>Math.round(Y*1e4)/1e4,g=y(this,rt,Xf).call(this,this.rotation),f=(Y,X)=>[g[0]*Y+g[2]*X,g[1]*Y+g[3]*X],p=y(this,rt,Xf).call(this,360-this.rotation),m=(Y,X)=>[p[0]*Y+p[2]*X,p[1]*Y+p[3]*X];let _,b,x=!1,S=!1;switch(t){case"topLeft":x=!0,_=(Y,X)=>[0,0],b=(Y,X)=>[Y,X];break;case"topMiddle":_=(Y,X)=>[Y/2,0],b=(Y,X)=>[Y/2,X];break;case"topRight":x=!0,_=(Y,X)=>[Y,0],b=(Y,X)=>[0,X];break;case"middleRight":S=!0,_=(Y,X)=>[Y,X/2],b=(Y,X)=>[0,X/2];break;case"bottomRight":x=!0,_=(Y,X)=>[Y,X],b=(Y,X)=>[0,0];break;case"bottomMiddle":_=(Y,X)=>[Y/2,X],b=(Y,X)=>[Y/2,0];break;case"bottomLeft":x=!0,_=(Y,X)=>[0,X],b=(Y,X)=>[Y,0];break;case"middleLeft":S=!0,_=(Y,X)=>[0,X/2],b=(Y,X)=>[Y,X/2];break}const A=_(a,h),k=b(a,h);let P=f(...k);const M=d(n+P[0]),O=d(r+P[1]);let R=1,I=1,[j,G]=this.screenToPageTranslation(e.movementX,e.movementY);if([j,G]=m(j/s,G/i),x){const Y=Math.hypot(a,h);R=I=Math.max(Math.min(Math.hypot(k[0]-A[0]-j,k[1]-A[1]-G)/Y,1/a,1/h),l/a,u/h)}else S?R=Math.max(l,Math.min(1,Math.abs(k[0]-A[0]-j)))/a:I=Math.max(u,Math.min(1,Math.abs(k[1]-A[1]-G)))/h;const L=d(a*R),H=d(h*I);P=f(...b(L,H));const $=M-P[0],J=O-P[1];this.width=L,this.height=H,this.x=$,this.y=J,this.setDims(s*L,i*H),this.fixAndSetPosition()},Gf=function(t){const{isMac:e}=Ne.platform;t.ctrlKey&&!e||t.shiftKey||t.metaKey&&e?this.parent.toggleSelected(this):this.parent.setSelected(this)},vb=function(t){const{isSelected:e}=this;this._uiManager.setUpDragSession();const s=new AbortController,i=this._uiManager.combinedSignal(s);if(e){this.div.classList.add("moving"),v(this,po,t.clientX),v(this,mo,t.clientY);const r=a=>{const{clientX:h,clientY:l}=a,[u,d]=this.screenToPageTranslation(h-c(this,po),l-c(this,mo));v(this,po,h),v(this,mo,l),this._uiManager.dragSelectedEditors(u,d)};window.addEventListener("pointermove",r,{passive:!0,capture:!0,signal:i})}const n=()=>{s.abort(),e&&this.div.classList.remove("moving"),v(this,Gr,!1),this._uiManager.endDragSession()||y(this,rt,Gf).call(this,t)};window.addEventListener("pointerup",n,{signal:i}),window.addEventListener("blur",n,{signal:i})},Yf=function(){if(c(this,Gn)||!this.div)return;v(this,Gn,new AbortController);const t=this._uiManager.combinedSignal(c(this,Gn));this.div.addEventListener("focusin",this.focusin.bind(this),{signal:t}),this.div.addEventListener("focusout",this.focusout.bind(this),{signal:t})},bb=function(t){vt._resizerKeyboardManager.exec(this,t)},yb=function(t){var e;c(this,Qi)&&((e=t.relatedTarget)==null?void 0:e.parentNode)!==c(this,me)&&y(this,rt,hc).call(this)},_b=function(t){v(this,il,c(this,Qi)?t:"")},Uf=function(t){if(c(this,$s))for(const e of c(this,$s))e.tabIndex=t},hc=function(){if(v(this,Qi,!1),y(this,rt,Uf).call(this,-1),c(this,Vr)){const{savedX:t,savedY:e,savedWidth:s,savedHeight:i}=c(this,Vr);y(this,rt,zf).call(this,t,e,s,i),v(this,Vr,null)}},w(vt,al),tt(vt,"_l10n",null),tt(vt,"_l10nResizer",null),tt(vt,"_borderLineWidth",-1),tt(vt,"_colorManager",new Jg),tt(vt,"_zIndex",1),tt(vt,"_telemetryTimeout",1e3);let _t=vt;class zx extends _t{constructor(t){super(t),this.annotationElementId=t.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}}const Y0=3285377520,xs=4294901760,di=65535;class U0{constructor(t){this.h1=t?t&4294967295:Y0,this.h2=t?t&4294967295:Y0}update(t){let e,s;if(typeof t=="string"){e=new Uint8Array(t.length*2),s=0;for(let m=0,_=t.length;m<_;m++){const b=t.charCodeAt(m);b<=255?e[s++]=b:(e[s++]=b>>>8,e[s++]=b&255)}}else if(ArrayBuffer.isView(t))e=t.slice(),s=e.byteLength;else throw new Error("Invalid data format, must be a string or TypedArray.");const i=s>>2,n=s-i*4,r=new Uint32Array(e.buffer,0,i);let a=0,h=0,l=this.h1,u=this.h2;const d=3432918353,g=461845907,f=d&di,p=g&di;for(let m=0;m<i;m++)m&1?(a=r[m],a=a*d&xs|a*f&di,a=a<<15|a>>>17,a=a*g&xs|a*p&di,l^=a,l=l<<13|l>>>19,l=l*5+3864292196):(h=r[m],h=h*d&xs|h*f&di,h=h<<15|h>>>17,h=h*g&xs|h*p&di,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&xs|a*f&di,a=a<<15|a>>>17,a=a*g&xs|a*p&di,i&1?l^=a:u^=a}this.h1=l,this.h2=u}hexdigest(){let t=this.h1,e=this.h2;return t^=e>>>1,t=t*3981806797&xs|t*36045&di,e=e*4283543511&xs|((e<<16|t>>>16)*2950163797&xs)>>>16,t^=e>>>1,t=t*444984403&xs|t*60499&di,e=e*3301882366&xs|((e<<16|t>>>16)*3120437893&xs)>>>16,t^=e>>>1,(t>>>0).toString(16).padStart(8,"0")+(e>>>0).toString(16).padStart(8,"0")}}const Qg=Object.freeze({map:null,hash:"",transfer:void 0});class Zg{constructor(){w(this,Uu);w(this,Ur,!1);w(this,qr,null);w(this,fe,new Map);this.onSetModified=null,this.onResetModified=null,this.onAnnotationEditor=null}getValue(t,e){const s=c(this,fe).get(t);return s===void 0?e:Object.assign(e,s)}getRawValue(t){return c(this,fe).get(t)}remove(t){if(c(this,fe).delete(t),c(this,fe).size===0&&this.resetModified(),typeof this.onAnnotationEditor=="function"){for(const e of c(this,fe).values())if(e instanceof _t)return;this.onAnnotationEditor(null)}}setValue(t,e){const s=c(this,fe).get(t);let i=!1;if(s!==void 0)for(const[n,r]of Object.entries(e))s[n]!==r&&(i=!0,s[n]=r);else i=!0,c(this,fe).set(t,e);i&&y(this,Uu,wb).call(this),e instanceof _t&&typeof this.onAnnotationEditor=="function"&&this.onAnnotationEditor(e.constructor._type)}has(t){return c(this,fe).has(t)}getAll(){return c(this,fe).size>0?Hg(c(this,fe)):null}setAll(t){for(const[e,s]of Object.entries(t))this.setValue(e,s)}get size(){return c(this,fe).size}resetModified(){c(this,Ur)&&(v(this,Ur,!1),typeof this.onResetModified=="function"&&this.onResetModified())}get print(){return new q0(this)}get serializable(){if(c(this,fe).size===0)return Qg;const t=new Map,e=new U0,s=[],i=Object.create(null);let n=!1;for(const[r,a]of c(this,fe)){const h=a instanceof _t?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}:Qg}get editorStats(){let t=null;const e=new Map;for(const s of c(this,fe).values()){if(!(s instanceof _t))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 l=r.get(a);l||(l=new Map,r.set(a,l));const u=l.get(h)??0;l.set(h,u+1)}}for(const[s,i]of e)t[s]=i.computeTelemetryFinalData(t[s]);return t}resetModifiedIds(){v(this,qr,null)}get modifiedIds(){if(c(this,qr))return c(this,qr);const t=[];for(const e of c(this,fe).values())!(e instanceof _t)||!e.annotationElementId||!e.serialize()||t.push(e.annotationElementId);return v(this,qr,{ids:new Set(t),hash:t.join(",")})}}Ur=new WeakMap,qr=new WeakMap,fe=new WeakMap,Uu=new WeakSet,wb=function(){c(this,Ur)||(v(this,Ur,!0),typeof this.onSetModified=="function"&&this.onSetModified())};class q0 extends Zg{constructor(e){super();w(this,ol);const{map:s,hash:i,transfer:n}=e.serializable,r=structuredClone(s,n?{transfer:n}:null);v(this,ol,{map:r,hash:i,transfer:n})}get print(){Mt("Should not call PrintAnnotationStorage.print")}get serializable(){return c(this,ol)}get modifiedIds(){return ut(this,"modifiedIds",{ids:new Set,hash:""})}}ol=new WeakMap;class Vx{constructor({ownerDocument:t=globalThis.document,styleElement:e=null}){w(this,vo,new Set);this._document=t,this.nativeFontFaces=new Set,this.styleElement=null,this.loadingRequests=[],this.loadTestFontId=0}addNativeFontFace(t){this.nativeFontFaces.add(t),this._document.fonts.add(t)}removeNativeFontFace(t){this.nativeFontFaces.delete(t),this._document.fonts.delete(t)}insertRule(t){this.styleElement||(this.styleElement=this._document.createElement("style"),this._document.documentElement.getElementsByTagName("head")[0].append(this.styleElement));const e=this.styleElement.sheet;e.insertRule(t,e.cssRules.length)}clear(){for(const t of this.nativeFontFaces)this._document.fonts.delete(t);this.nativeFontFaces.clear(),c(this,vo).clear(),this.styleElement&&(this.styleElement.remove(),this.styleElement=null)}async loadSystemFont({systemFontInfo:t,_inspectFont:e}){if(!(!t||c(this,vo).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(),c(this,vo).add(s),e==null||e(t)}catch{at(`Cannot load system font: ${t.baseFontName}, installing it could help to improve PDF rendering.`),this.removeNativeFontFace(r)}return}Mt("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 at(`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 ut(this,"isFontLoadingAPISupported",t)}get isSyncFontLoadingSupported(){let t=!1;return(Ae||typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.userAgent)=="string"&&/Mozilla\/5.0.*?rv:\d+.*? Gecko/.test(navigator.userAgent))&&(t=!0),ut(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 ut(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,P,M){const O=A.substring(0,k),R=A.substring(k+P);return O+M+R}let n,r;const a=this._document.createElement("canvas");a.width=1,a.height=1;const h=a.getContext("2d");let l=0;function u(A,k){if(++l>30){at("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 g=this._loadTestFont;g=i(g,976,d.length,d);const p=16,m=1482184792;let _=s(g,p);for(n=0,r=d.length-3;n<r;n+=4)_=_-m+s(d,n)|0;n<d.length&&(_=_-m+s(d+"XXX",n)|0),g=i(g,p,4,kx(_));const b=`url(data:font/opentype;base64,${btoa(g)});`,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()})}}vo=new WeakMap;class Gx{constructor(t,{disableFontFace:e=!1,inspectFont:s=null}){this.compiledGlyphs=Object.create(null);for(const i in t)this[i]=t[i];this.disableFontFace=e===!0,this._inspectFont=s}createNativeFontFace(){var e;if(!this.data||this.disableFontFace)return null;let t;if(!this.cssFontInfo)t=new FontFace(this.loadedName,this.data,{});else{const s={weight:this.cssFontInfo.fontWeight};this.cssFontInfo.italicAngle&&(s.style=`oblique ${this.cssFontInfo.italicAngle}deg`),t=new FontFace(this.cssFontInfo.fontFamily,this.data,s)}return(e=this._inspectFont)==null||e.call(this,this),t}createFontFaceRule(){var s;if(!this.data||this.disableFontFace)return null;const t=`url(data:${this.mimetype};base64,${Fx(this.data)});`;let e;if(!this.cssFontInfo)e=`@font-face {font-family:"${this.loadedName}";src:${t}}`;else{let i=`font-weight: ${this.cssFontInfo.fontWeight};`;this.cssFontInfo.italicAngle&&(i+=`font-style: oblique ${this.cssFontInfo.italicAngle}deg;`),e=`@font-face {font-family:"${this.cssFontInfo.fontFamily}";${i}src:${t}}`}return(s=this._inspectFont)==null||s.call(this,this,t),e}getPathGenerator(t,e){if(this.compiledGlyphs[e]!==void 0)return this.compiledGlyphs[e];let s;try{s=t.get(this.loadedName+"_path_"+e)}catch(n){at(`getPathGenerator - ignoring character: "${n}".`)}if(!Array.isArray(s)||s.length===0)return this.compiledGlyphs[e]=function(n,r){};const i=[];for(let n=0,r=s.length;n<r;)switch(s[n++]){case Wi.BEZIER_CURVE_TO:{const[a,h,l,u,d,g]=s.slice(n,n+6);i.push(f=>f.bezierCurveTo(a,h,l,u,d,g)),n+=6}break;case Wi.MOVE_TO:{const[a,h]=s.slice(n,n+2);i.push(l=>l.moveTo(a,h)),n+=2}break;case Wi.LINE_TO:{const[a,h]=s.slice(n,n+2);i.push(l=>l.lineTo(a,h)),n+=2}break;case Wi.QUADRATIC_CURVE_TO:{const[a,h,l,u]=s.slice(n,n+4);i.push(d=>d.quadraticCurveTo(a,h,l,u)),n+=4}break;case Wi.RESTORE:i.push(a=>a.restore());break;case Wi.SAVE:i.push(a=>a.save());break;case Wi.SCALE:ne(i.length===2,"Scale command is only valid at the third position.");break;case Wi.TRANSFORM:{const[a,h,l,u,d,g]=s.slice(n,n+6);i.push(f=>f.transform(a,h,l,u,d,g)),n+=6}break;case Wi.TRANSLATE:{const[a,h]=s.slice(n,n+2);i.push(l=>l.translate(a,h)),n+=2}break}return this.compiledGlyphs[e]=function(r,a){i[0](r),i[1](r),r.scale(a,-a);for(let h=2,l=i.length;h<l;h++)i[h](r)}}}class $0{constructor({enableHWA:t=!1}){w(this,hl,!1);v(this,hl,t)}create(t,e){if(t<=0||e<=0)throw new Error("Invalid canvas size");const s=this._createCanvas(t,e);return{canvas:s,context:s.getContext("2d",{willReadFrequently:!c(this,hl)})}}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){Mt("Abstract method `_createCanvas` called.")}}hl=new WeakMap;class Yx extends $0{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 K0{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){Mt("Abstract method `_fetch` called.")}}class J0 extends K0{async _fetch(t){const e=await Eu(t,this.isCompressed?"arraybuffer":"text");return e instanceof ArrayBuffer?new Uint8Array(e):Tu(e)}}class Q0{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 Ux extends Q0{constructor({docId:e,ownerDocument:s=globalThis.document}){super();w(this,z);w(this,$r);w(this,Kr);w(this,xi);w(this,Zi);w(this,ke);w(this,qu);w(this,Jr,0);v(this,Zi,e),v(this,ke,s)}addFilter(e){if(!e)return"none";let s=c(this,z,Pe).get(e);if(s)return s;const[i,n,r]=y(this,z,gd).call(this,e),a=e.length===1?i:`${i}${n}${r}`;if(s=c(this,z,Pe).get(a),s)return c(this,z,Pe).set(e,s),s;const h=`g_${c(this,Zi)}_transfer_map_${Ge(this,Jr)._++}`,l=y(this,z,ah).call(this,h);c(this,z,Pe).set(e,l),c(this,z,Pe).set(a,l);const u=y(this,z,oh).call(this,h);return y(this,z,cc).call(this,i,n,r,u),l}addHCMFilter(e,s){var p;const i=`${e}-${s}`,n="base";let r=c(this,z,nh).get(n);if((r==null?void 0:r.key)===i||(r?((p=r.filter)==null||p.remove(),r.key=i,r.url="none",r.filter=null):(r={key:i,url:"none",filter:null},c(this,z,nh).set(n,r)),!e||!s))return r.url;const a=y(this,z,uc).call(this,e);e=U.makeHexColor(...a);const h=y(this,z,uc).call(this,s);if(s=U.makeHexColor(...h),c(this,z,rh).style.color="",e==="#000000"&&s==="#ffffff"||e===s)return r.url;const l=new Array(256);for(let m=0;m<=255;m++){const _=m/255;l[m]=_<=.03928?_/12.92:((_+.055)/1.055)**2.4}const u=l.join(","),d=`g_${c(this,Zi)}_hcm_filter`,g=r.filter=y(this,z,oh).call(this,d);y(this,z,cc).call(this,u,u,u,g),y(this,z,qf).call(this,g);const f=(m,_)=>{const b=a[m]/255,x=h[m]/255,S=new Array(_+1);for(let A=0;A<=_;A++)S[A]=b+A/_*(x-b);return S.join(",")};return y(this,z,cc).call(this,f(0,5),f(1,5),f(2,5),g),r.url=y(this,z,ah).call(this,d),r.url}addAlphaFilter(e){let s=c(this,z,Pe).get(e);if(s)return s;const[i]=y(this,z,gd).call(this,[e]),n=`alpha_${i}`;if(s=c(this,z,Pe).get(n),s)return c(this,z,Pe).set(e,s),s;const r=`g_${c(this,Zi)}_alpha_map_${Ge(this,Jr)._++}`,a=y(this,z,ah).call(this,r);c(this,z,Pe).set(e,a),c(this,z,Pe).set(n,a);const h=y(this,z,oh).call(this,r);return y(this,z,$f).call(this,i,h),a}addLuminosityFilter(e){let s=c(this,z,Pe).get(e||"luminosity");if(s)return s;let i,n;if(e?([i]=y(this,z,gd).call(this,[e]),n=`luminosity_${i}`):n="luminosity",s=c(this,z,Pe).get(n),s)return c(this,z,Pe).set(e,s),s;const r=`g_${c(this,Zi)}_luminosity_map_${Ge(this,Jr)._++}`,a=y(this,z,ah).call(this,r);c(this,z,Pe).set(e,a),c(this,z,Pe).set(n,a);const h=y(this,z,oh).call(this,r);return y(this,z,xb).call(this,h),e&&y(this,z,$f).call(this,i,h),a}addHighlightHCMFilter(e,s,i,n,r){var x;const a=`${s}-${i}-${n}-${r}`;let h=c(this,z,nh).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},c(this,z,nh).set(e,h)),!s||!i))return h.url;const[l,u]=[s,i].map(y(this,z,uc).bind(this));let d=Math.round(.2126*l[0]+.7152*l[1]+.0722*l[2]),g=Math.round(.2126*u[0]+.7152*u[1]+.0722*u[2]),[f,p]=[n,r].map(y(this,z,uc).bind(this));g<d&&([d,g,f,p]=[g,d,p,f]),c(this,z,rh).style.color="";const m=(S,A,k)=>{const P=new Array(256),M=(g-d)/k,O=S/255,R=(A-S)/(255*k);let I=0;for(let j=0;j<=k;j++){const G=Math.round(d+j*M),L=O+j*R;for(let H=I;H<=G;H++)P[H]=L;I=G+1}for(let j=I;j<256;j++)P[j]=P[I-1];return P.join(",")},_=`g_${c(this,Zi)}_hcm_${e}_filter`,b=h.filter=y(this,z,oh).call(this,_);return y(this,z,qf).call(this,b),y(this,z,cc).call(this,m(f[0],p[0],5),m(f[1],p[1],5),m(f[2],p[2],5),b),h.url=y(this,z,ah).call(this,_),h.url}destroy(e=!1){e&&c(this,z,nh).size!==0||(c(this,xi)&&(c(this,xi).parentNode.parentNode.remove(),v(this,xi,null)),c(this,Kr)&&(c(this,Kr).clear(),v(this,Kr,null)),v(this,Jr,0))}}$r=new WeakMap,Kr=new WeakMap,xi=new WeakMap,Zi=new WeakMap,ke=new WeakMap,qu=new WeakMap,Jr=new WeakMap,z=new WeakSet,Pe=function(){return c(this,Kr)||v(this,Kr,new Map)},nh=function(){return c(this,qu)||v(this,qu,new Map)},rh=function(){if(!c(this,xi)){const e=c(this,ke).createElement("div"),{style:s}=e;s.visibility="hidden",s.contain="strict",s.width=s.height=0,s.position="absolute",s.top=s.left=0,s.zIndex=-1;const i=c(this,ke).createElementNS(Xi,"svg");i.setAttribute("width",0),i.setAttribute("height",0),v(this,xi,c(this,ke).createElementNS(Xi,"defs")),e.append(i),i.append(c(this,xi)),c(this,ke).body.append(e)}return c(this,xi)},gd=function(e){if(e.length===1){const l=e[0],u=new Array(256);for(let g=0;g<256;g++)u[g]=l[g]/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 l=0;l<256;l++)r[l]=s[l]/255,a[l]=i[l]/255,h[l]=n[l]/255;return[r.join(","),a.join(","),h.join(",")]},ah=function(e){if(c(this,$r)===void 0){v(this,$r,"");const s=c(this,ke).URL;s!==c(this,ke).baseURI&&(ku(s)?at('#createUrl: ignore "data:"-URL for performance reasons.'):v(this,$r,s.split("#",1)[0]))}return`url(${c(this,$r)}#${e})`},xb=function(e){const s=c(this,ke).createElementNS(Xi,"feColorMatrix");s.setAttribute("type","matrix"),s.setAttribute("values","0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.59 0.11 0 0"),e.append(s)},qf=function(e){const s=c(this,ke).createElementNS(Xi,"feColorMatrix");s.setAttribute("type","matrix"),s.setAttribute("values","0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0 0 0 1 0"),e.append(s)},oh=function(e){const s=c(this,ke).createElementNS(Xi,"filter");return s.setAttribute("color-interpolation-filters","sRGB"),s.setAttribute("id",e),c(this,z,rh).append(s),s},lc=function(e,s,i){const n=c(this,ke).createElementNS(Xi,s);n.setAttribute("type","discrete"),n.setAttribute("tableValues",i),e.append(n)},cc=function(e,s,i,n){const r=c(this,ke).createElementNS(Xi,"feComponentTransfer");n.append(r),y(this,z,lc).call(this,r,"feFuncR",e),y(this,z,lc).call(this,r,"feFuncG",s),y(this,z,lc).call(this,r,"feFuncB",i)},$f=function(e,s){const i=c(this,ke).createElementNS(Xi,"feComponentTransfer");s.append(i),y(this,z,lc).call(this,i,"feFuncA",e)},uc=function(e){return c(this,z,rh).style.color=e,Ug(getComputedStyle(c(this,z,rh)).getPropertyValue("color"))};class Z0{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){Mt("Abstract method `_fetch` called.")}}class tv extends Z0{async _fetch(t){const e=await Eu(t,"arraybuffer");return new Uint8Array(e)}}if(Ae){var tf=Promise.withResolvers(),Lh=null;(async()=>{const t=await Promise.resolve().then(()=>Hu),e=await Promise.resolve().then(()=>Hu),s=await Promise.resolve().then(()=>Hu),i=await Promise.resolve().then(()=>Hu);let n,r;return new Map(Object.entries({fs:t,http:e,https:s,url:i,canvas:n,path2d:r}))})().then(t=>{Lh=t,tf.resolve()},t=>{at(`loadPackages: ${t}`),Lh=new Map,tf.resolve()})}class Fn{static get promise(){return tf.promise}static get(t){return Lh==null?void 0:Lh.get(t)}}async function ev(o){const e=await Fn.get("fs").promises.readFile(o);return new Uint8Array(e)}class qx extends Q0{}class $x extends $0{_createCanvas(t,e){return Fn.get("canvas").createCanvas(t,e)}}class Kx extends K0{async _fetch(t){return ev(t)}}class Jx extends Z0{async _fetch(t){return ev(t)}}const Be={FILL:"Fill",STROKE:"Stroke",SHADING:"Shading"};function ef(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 sf{getPattern(){Mt("Abstract method `getPattern` called.")}}class Qx extends sf{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===Be.STROKE||i===Be.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,l=e.cachedCanvases.getCanvas("pattern",a,h),u=l.context;u.clearRect(0,0,u.canvas.width,u.canvas.height),u.beginPath(),u.rect(0,0,u.canvas.width,u.canvas.height),u.translate(-r[0],-r[1]),s=U.transform(s,[1,0,0,1,r[0],r[1]]),u.transform(...e.baseTransform),this.matrix&&u.transform(...this.matrix),ef(u,this._bbox),u.fillStyle=this._createGradient(u),u.fill(),n=t.createPattern(l.canvas,"no-repeat");const d=new DOMMatrix(s);n.setTransform(d)}else ef(t,this._bbox),n=this._createGradient(t);return n}}function nf(o,t,e,s,i,n,r,a){const h=t.coords,l=t.colors,u=o.data,d=o.width*4;let g;h[e+1]>h[s+1]&&(g=e,e=s,s=g,g=n,n=r,r=g),h[s+1]>h[i+1]&&(g=s,s=i,i=g,g=r,r=a,a=g),h[e+1]>h[s+1]&&(g=e,e=s,s=g,g=n,n=r,r=g);const f=(h[e]+t.offsetX)*t.scaleX,p=(h[e+1]+t.offsetY)*t.scaleY,m=(h[s]+t.offsetX)*t.scaleX,_=(h[s+1]+t.offsetY)*t.scaleY,b=(h[i]+t.offsetX)*t.scaleX,x=(h[i+1]+t.offsetY)*t.scaleY;if(p>=x)return;const S=l[n],A=l[n+1],k=l[n+2],P=l[r],M=l[r+1],O=l[r+2],R=l[a],I=l[a+1],j=l[a+2],G=Math.round(p),L=Math.round(x);let H,$,J,Y,X,Ot,zt,te;for(let Ht=G;Ht<=L;Ht++){if(Ht<_){const gt=Ht<p?0:(p-Ht)/(p-_);H=f-(f-m)*gt,$=S-(S-P)*gt,J=A-(A-M)*gt,Y=k-(k-O)*gt}else{let gt;Ht>x?gt=1:_===x?gt=0:gt=(_-Ht)/(_-x),H=m-(m-b)*gt,$=P-(P-R)*gt,J=M-(M-I)*gt,Y=O-(O-j)*gt}let At;Ht<p?At=0:Ht>x?At=1:At=(p-Ht)/(p-x),X=f-(f-b)*At,Ot=S-(S-R)*At,zt=A-(A-I)*At,te=k-(k-j)*At;const _e=Math.round(Math.min(H,X)),Ps=Math.round(Math.max(H,X));let kt=d*Ht+_e*4;for(let gt=_e;gt<=Ps;gt++)At=(H-gt)/(H-X),At<0?At=0:At>1&&(At=1),u[kt++]=$-($-Ot)*At|0,u[kt++]=J-(J-zt)*At|0,u[kt++]=Y-(Y-te)*At|0,u[kt++]=255}}function Zx(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,l=a-1;for(n=0;n<h;n++){let u=n*a;for(let d=0;d<l;d++,u++)nf(o,e,s[u],s[u+1],s[u+a],i[u],i[u+1],i[u+a]),nf(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)nf(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 tS extends sf{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]),l=Math.ceil(this._bounds[2])-a,u=Math.ceil(this._bounds[3])-h,d=Math.min(Math.ceil(Math.abs(l*t[0]*1.1)),3e3),g=Math.min(Math.ceil(Math.abs(u*t[1]*1.1)),3e3),f=l/d,p=u/g,m={coords:this._coords,colors:this._colors,offsetX:-a,offsetY:-h,scaleX:1/f,scaleY:1/p},_=d+2*2,b=g+2*2,x=s.getCanvas("mesh",_,b),S=x.context,A=S.createImageData(d,g);if(e){const P=A.data;for(let M=0,O=P.length;M<O;M+=4)P[M]=e[0],P[M+1]=e[1],P[M+2]=e[2],P[M+3]=255}for(const P of this._figures)Zx(A,P,m);return S.putImageData(A,2,2),{canvas:x.canvas,offsetX:a-2*f,offsetY:h-2*p,scaleX:f,scaleY:p}}getPattern(t,e,s,i){ef(t,this._bbox);let n;if(i===Be.SHADING)n=U.singularValueDecompose2dScale(It(t));else if(n=U.singularValueDecompose2dScale(e.baseTransform),this.matrix){const a=U.singularValueDecompose2dScale(this.matrix);n=[n[0]*a[0],n[1]*a[1]]}const r=this._createMeshCanvas(n,i===Be.SHADING?null:this._background,e.cachedCanvases);return i!==Be.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 eS extends sf{getPattern(){return"hotpink"}}function sS(o){switch(o[0]){case"RadialAxial":return new Qx(o);case"Mesh":return new tS(o);case"Dummy":return new eS}throw new Error(`Unknown IR type: ${o[0]}`)}const sv={COLORED:1,UNCOLORED:2},$u=class $u{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:l}=this;h=Math.abs(h),l=Math.abs(l),Cu("TilingType: "+n);const u=e[0],d=e[1],g=e[2],f=e[3],p=g-u,m=f-d,_=U.singularValueDecompose2dScale(this.matrix),b=U.singularValueDecompose2dScale(this.baseTransform),x=_[0]*b[0],S=_[1]*b[1];let A=p,k=m,P=!1,M=!1;const O=Math.ceil(h*x),R=Math.ceil(l*S),I=Math.ceil(p*x),j=Math.ceil(m*S);O>=I?A=h:P=!0,R>=j?k=l:M=!0;const G=this.getSizeAndScale(A,this.ctx.canvas.width,x),L=this.getSizeAndScale(k,this.ctx.canvas.height,S),H=t.cachedCanvases.getCanvas("pattern",G.size,L.size),$=H.context,J=a.createCanvasGraphics($);if(J.groupLevel=t.groupLevel,this.setFillAndStrokeStyleToContext(J,i,r),$.translate(-G.scale*u,-L.scale*d),J.transform(G.scale,0,0,L.scale,0,0),$.save(),this.clipBbox(J,u,d,g,f),J.baseTransform=It(J.ctx),J.executeOperatorList(s),J.endDrawing(),$.restore(),P||M){const Y=H.canvas;P&&(A=h),M&&(k=l);const X=this.getSizeAndScale(A,this.ctx.canvas.width,x),Ot=this.getSizeAndScale(k,this.ctx.canvas.height,S),zt=X.size,te=Ot.size,Ht=t.cachedCanvases.getCanvas("pattern-workaround",zt,te),At=Ht.context,_e=P?Math.floor(p/h):0,Ps=M?Math.floor(m/l):0;for(let kt=0;kt<=_e;kt++)for(let gt=0;gt<=Ps;gt++)At.drawImage(Y,zt*kt,te*gt,zt,te,0,0,zt,te);return{canvas:Ht.canvas,scaleX:X.scale,scaleY:Ot.scale,offsetX:u,offsetY:d}}return{canvas:H.canvas,scaleX:G.scale,scaleY:L.scale,offsetX:u,offsetY:d}}getSizeAndScale(t,e,s){const i=Math.max($u.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 sv.COLORED:const r=this.ctx;i.fillStyle=r.fillStyle,i.strokeStyle=r.strokeStyle,n.fillColor=r.fillStyle,n.strokeColor=r.strokeStyle;break;case sv.UNCOLORED:const a=U.makeHexColor(s[0],s[1],s[2]);i.fillStyle=a,i.strokeStyle=a,n.fillColor=a,n.strokeColor=a;break;default:throw new Ex(`Unsupported paint type: ${e}`)}}getPattern(t,e,s,i){let n=s;i!==Be.SHADING&&(n=U.transform(n,e.baseTransform),this.matrix&&(n=U.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}};tt($u,"MAX_PATTERN_SIZE",3e3);let rf=$u;function iS({src:o,srcPos:t=0,dest:e,width:s,height:i,nonBlackColor:n=4294967295,inverseDecode:r=!1}){const a=Ne.isLittleEndian?4278190080:255,[h,l]=r?[n,a]:[a,n],u=s>>3,d=s&7,g=o.length;e=new Uint32Array(e.buffer);let f=0;for(let p=0;p<i;p++){for(const _=t+u;t<_;t++){const b=t<g?o[t]:255;e[f++]=b&128?l:h,e[f++]=b&64?l:h,e[f++]=b&32?l:h,e[f++]=b&16?l:h,e[f++]=b&8?l:h,e[f++]=b&4?l:h,e[f++]=b&2?l:h,e[f++]=b&1?l:h}if(d===0)continue;const m=t<g?o[t++]:255;for(let _=0;_<d;_++)e[f++]=m&1<<7-_?l:h}return{srcPos:t,destPos:f}}const iv=16,nv=100,nS=15,rv=10,av=1e3,$e=16;function rS(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 aS{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 Pu(o,t,e,s,i,n,r,a,h,l){const[u,d,g,f,p,m]=It(o);if(d===0&&g===0){const x=r*u+p,S=Math.round(x),A=a*f+m,k=Math.round(A),P=(r+h)*u+p,M=Math.abs(Math.round(P)-S)||1,O=(a+l)*f+m,R=Math.abs(Math.round(O)-k)||1;return o.setTransform(Math.sign(u),0,0,Math.sign(f),S,k),o.drawImage(t,e,s,i,n,0,0,M,R),o.setTransform(u,d,g,f,p,m),[M,R]}if(u===0&&f===0){const x=a*g+p,S=Math.round(x),A=r*d+m,k=Math.round(A),P=(a+l)*g+p,M=Math.abs(Math.round(P)-S)||1,O=(r+h)*d+m,R=Math.abs(Math.round(O)-k)||1;return o.setTransform(0,Math.sign(d),Math.sign(g),0,S,k),o.drawImage(t,e,s,i,n,0,0,R,M),o.setTransform(u,d,g,f,p,m),[R,M]}o.drawImage(t,e,s,i,n,r,a,h,l);const _=Math.hypot(u,d),b=Math.hypot(g,f);return[_*h,b*l]}function oS(o){const{width:t,height:e}=o;if(t>av||e>av)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,l;const u=t+7&-8;let d=new Uint8Array(u*e),g=0;for(const b of o.data){let x=128;for(;x>0;)d[g++]=b&x?0:255,x>>=1}let f=0;for(g=0,d[g]!==0&&(r[0]=1,++f),h=1;h<t;h++)d[g]!==d[g+1]&&(r[h]=d[g]?2:1,++f),g++;for(d[g]!==0&&(r[h]=2,++f),a=1;a<e;a++){g=a*u,l=a*n,d[g-u]!==d[g]&&(r[l]=d[g]?1:8,++f);let b=(d[g]?4:0)+(d[g-u]?8:0);for(h=1;h<t;h++)b=(b>>2)+(d[g+1]?4:0)+(d[g-u+1]?8:0),i[b]&&(r[l+h]=i[b],++f),g++;if(d[g-u]!==d[g]&&(r[l+h]=d[g]?2:4,++f),f>s)return null}for(g=u*(e-1),l=a*n,d[g]!==0&&(r[l]=8,++f),h=1;h<t;h++)d[g]!==d[g+1]&&(r[l+h]=d[g]?4:8,++f),g++;if(d[g]!==0&&(r[l+h]=4,++f),f>s)return null;const p=new Int32Array([0,n,-1,0,-n,0,0,0,1]),m=new Path2D;for(a=0;f&&a<=e;a++){let b=a*n;const x=b+t;for(;b<x&&!r[b];)b++;if(b===x)continue;m.moveTo(b%n,a);const S=b;let A=r[b];do{const k=p[A];do b+=k;while(!r[b]);const P=r[b];P!==5&&P!==10?(A=P,r[b]=0):(A=P&51*A>>4,r[b]&=A>>2|A<<2),m.lineTo(b%n,b/n|0),r[b]||--f}while(S!==b);--a}return d=null,r=null,function(b){b.save(),b.scale(1/t,-1/e),b.translate(0,-e),b.fill(m),b.beginPath(),b.restore()}}class ov{constructor(t,e){this.alphaIsShape=!1,this.fontSize=0,this.fontSizeScale=1,this.textMatrix=H0,this.textMatrixScale=1,this.fontMatrix=Ig,this.leading=0,this.x=0,this.y=0,this.lineX=0,this.lineY=0,this.charSpacing=0,this.wordSpacing=0,this.textHScale=1,this.textRenderingMode=Te.FILL,this.textRise=0,this.fillColor="#000000",this.strokeColor="#000000",this.patternFill=!1,this.fillAlpha=1,this.strokeAlpha=1,this.lineWidth=1,this.activeSMask=null,this.transferMaps="none",this.startNewPathAndClipBox([0,0,t,e])}clone(){const t=Object.create(this);return t.clipBox=this.clipBox.slice(),t}setCurrentPoint(t,e){this.x=t,this.y=e}updatePathMinMax(t,e,s){[e,s]=U.applyTransform([e,s],t),this.minX=Math.min(this.minX,e),this.minY=Math.min(this.minY,s),this.maxX=Math.max(this.maxX,e),this.maxY=Math.max(this.maxY,s)}updateRectMinMax(t,e){const s=U.applyTransform(e,t),i=U.applyTransform(e.slice(2),t),n=U.applyTransform([e[0],e[3]],t),r=U.applyTransform([e[2],e[1]],t);this.minX=Math.min(this.minX,s[0],i[0],n[0],r[0]),this.minY=Math.min(this.minY,s[1],i[1],n[1],r[1]),this.maxX=Math.max(this.maxX,s[0],i[0],n[0],r[0]),this.maxY=Math.max(this.maxY,s[1],i[1],n[1],r[1])}updateScalingPathMinMax(t,e){U.scaleMinMax(t,e),this.minX=Math.min(this.minX,e[0]),this.minY=Math.min(this.minY,e[1]),this.maxX=Math.max(this.maxX,e[2]),this.maxY=Math.max(this.maxY,e[3])}updateCurvePathMinMax(t,e,s,i,n,r,a,h,l,u){const d=U.bezierBoundingBox(e,s,i,n,r,a,h,l,u);u||this.updateRectMinMax(t,d)}getPathBoundingBox(t=Be.FILL,e=null){const s=[this.minX,this.minY,this.maxX,this.maxY];if(t===Be.STROKE){e||Mt("Stroke bounding box must include transform.");const i=U.singularValueDecompose2dScale(e),n=i[0]*this.lineWidth/2,r=i[1]*this.lineWidth/2;s[0]-=n,s[1]-=r,s[2]+=n,s[3]+=r}return s}updateClipFromPath(){const t=U.intersect(this.clipBox,this.getPathBoundingBox());this.startNewPathAndClipBox(t||[0,0,0,0])}isEmptyClip(){return this.minX===1/0}startNewPathAndClipBox(t){this.clipBox=t,this.minX=1/0,this.minY=1/0,this.maxX=0,this.maxY=0}getClippedPathBoundingBox(t=Be.FILL,e=null){return U.intersect(this.clipBox,this.getPathBoundingBox(t,e))}}function hv(o,t){if(typeof ImageData<"u"&&t instanceof ImageData){o.putImageData(t,0,0);return}const e=t.height,s=t.width,i=e%$e,n=(e-i)/$e,r=i===0?n:n+1,a=o.createImageData(s,$e);let h=0,l;const u=t.data,d=a.data;let g,f,p,m;if(t.kind===wu.GRAYSCALE_1BPP){const _=u.byteLength,b=new Uint32Array(d.buffer,0,d.byteLength>>2),x=b.length,S=s+7>>3,A=4294967295,k=Ne.isLittleEndian?4278190080:255;for(g=0;g<r;g++){for(p=g<n?$e:i,l=0,f=0;f<p;f++){const P=_-h;let M=0;const O=P>S?s:P*8-7,R=O&-8;let I=0,j=0;for(;M<R;M+=8)j=u[h++],b[l++]=j&128?A:k,b[l++]=j&64?A:k,b[l++]=j&32?A:k,b[l++]=j&16?A:k,b[l++]=j&8?A:k,b[l++]=j&4?A:k,b[l++]=j&2?A:k,b[l++]=j&1?A:k;for(;M<O;M++)I===0&&(j=u[h++],I=128),b[l++]=j&I?A:k,I>>=1}for(;l<x;)b[l++]=0;o.putImageData(a,0,g*$e)}}else if(t.kind===wu.RGBA_32BPP){for(f=0,m=s*$e*4,g=0;g<n;g++)d.set(u.subarray(h,h+m)),h+=m,o.putImageData(a,0,f),f+=$e;g<r&&(m=s*i*4,d.set(u.subarray(h,h+m)),o.putImageData(a,0,f))}else if(t.kind===wu.RGB_24BPP)for(p=$e,m=s*p,g=0;g<r;g++){for(g>=n&&(p=i,m=s*p),l=0,f=m;f--;)d[l++]=u[h++],d[l++]=u[h++],d[l++]=u[h++],d[l++]=255;o.putImageData(a,0,g*$e)}else throw new Error(`bad image kind: ${t.kind}`)}function lv(o,t){if(t.bitmap){o.drawImage(t.bitmap,0,0);return}const e=t.height,s=t.width,i=e%$e,n=(e-i)/$e,r=i===0?n:n+1,a=o.createImageData(s,$e);let h=0;const l=t.data,u=a.data;for(let d=0;d<r;d++){const g=d<n?$e:i;({srcPos:h}=iS({src:l,srcPos:h,dest:u,width:s,height:g,nonBlackColor:0})),o.putImageData(a,0,d*$e)}}function Ih(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 Du(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),!Ae){const{filter:t}=o;t!=="none"&&t!==""&&(o.filter="none")}}function cv(o,t){if(t)return!0;const e=U.singularValueDecompose2dScale(o);e[0]=Math.fround(e[0]),e[1]=Math.fround(e[1]);const s=Math.fround((globalThis.devicePixelRatio||1)*Rn.PDF_TO_CSS_UNITS);return e[0]<=s&&e[1]<=s}const hS=["butt","round","square"],lS=["miter","round","bevel"],cS={},uv={},Sf=class Sf{constructor(t,e,s,i,n,{optionalContentConfig:r,markedContentStack:a=null},h,l){w(this,Un);this.ctx=t,this.current=new ov(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 aS(this.canvasFactory),this.cachedPatterns=new Map,this.annotationCanvasMap=h,this.viewportScale=1,this.outputScaleX=1,this.outputScaleY=1,this.pageColors=l,this._cachedScaleForStroking=[-1,0],this._cachedGetSinglePixelWidth=null,this._cachedBitmapsMap=new Map}getObject(t,e=null){return typeof t=="string"?t.startsWith("g_")?this.commonObjs.get(t):this.objs.get(t):e}beginDrawing({transform:t,viewport:e,transparency:s=!1,background:i=null}){const n=this.ctx.canvas.width,r=this.ctx.canvas.height,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(),Du(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 l=h-a>rv&&typeof s=="function",u=l?Date.now()+nS:0;let d=0;const g=this.commonObjs,f=this.objs;let p;for(;;){if(i!==void 0&&a===i.nextBreakPoint)return i.breakIt(a,s),a;if(p=r[a],p!==zs.dependency)this[p].apply(this,n[a]);else for(const m of n[a]){const _=m.startsWith("g_")?g:f;if(!_.has(m))return _.get(m,s),a}if(a++,a===h)return a;if(l&&++d>rv){if(Date.now()>u)return s(),a;d=0}}}endDrawing(){y(this,Un,Kf).call(this),this.cachedCanvases.clear(),this.cachedPatterns.clear();for(const t of this._cachedBitmapsMap.values()){for(const e of t.values())typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement&&(e.width=e.height=0);t.clear()}this._cachedBitmapsMap.clear(),y(this,Un,Jf).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,l="prescale1",u,d;for(;n>2&&a>1||r>2&&h>1;){let g=a,f=h;n>2&&a>1&&(g=a>=16384?Math.floor(a/2)-1||1:Math.ceil(a/2),n/=a/g),r>2&&h>1&&(f=h>=16384?Math.floor(h/2)-1||1:Math.ceil(h)/2,r/=h/f),u=this.cachedCanvases.getCanvas(l,g,f),d=u.context,d.clearRect(0,0,g,f),d.drawImage(t,0,0,a,h,0,0,g,f),t=u.canvas,a=g,h=f,l=l==="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,l,u,d;if((t.bitmap||t.data)&&t.count>1){const O=t.bitmap||t.data.buffer;l=JSON.stringify(r?a:[a.slice(0,4),n]),h=this._cachedBitmapsMap.get(O),h||(h=new Map,this._cachedBitmapsMap.set(O,h));const R=h.get(l);if(R&&!r){const I=Math.round(Math.min(a[0],a[2])+a[4]),j=Math.round(Math.min(a[1],a[3])+a[5]);return{canvas:R,offsetX:I,offsetY:j}}u=R}u||(d=this.cachedCanvases.getCanvas("maskCanvas",s,i),lv(d.context,t));let g=U.transform(a,[1/s,0,0,-1/i,0,0]);g=U.transform(g,[1,0,0,1,0,-i]);const[f,p,m,_]=U.getAxialAlignedBoundingBox([0,0,s,i],g),b=Math.round(m-f)||1,x=Math.round(_-p)||1,S=this.cachedCanvases.getCanvas("fillCanvas",b,x),A=S.context,k=f,P=p;A.translate(-k,-P),A.transform(...g),u||(u=this._scaleImage(d.canvas,zi(A)),u=u.img,h&&r&&h.set(l,u)),A.imageSmoothingEnabled=cv(It(A),t.interpolate),Pu(A,u,0,0,u.width,u.height,0,0,s,i),A.globalCompositeOperation="source-in";const M=U.transform(zi(A),[1,0,0,1,-k,-P]);return A.fillStyle=r?n.getPattern(e,this,M,Be.FILL):n,A.fillRect(0,0,s,i),h&&!r&&(this.cachedCanvases.delete("fillCanvas"),h.set(l,S.canvas)),{canvas:S.canvas,offsetX:Math.round(k),offsetY:Math.round(P)}}setLineWidth(t){t!==this.current.lineWidth&&(this._cachedScaleForStroking[0]=-1),this.current.lineWidth=t,this.ctx.lineWidth=t}setLineCap(t){this.ctx.lineCap=hS[t]}setLineJoin(t){this.ctx.lineJoin=lS[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)),Ih(this.suspendedCtx,n),rS(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(),Ih(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,l,u,d){let g=t.canvas,f=h-u,p=l-d;if(r){const _=U.makeHexColor(...r);if(f<0||p<0||f+s>g.width||p+i>g.height){const b=this.cachedCanvases.getCanvas("maskExtension",s,i),x=b.context;x.drawImage(g,-f,-p),x.globalCompositeOperation="destination-atop",x.fillStyle=_,x.fillRect(0,0,s,i),x.globalCompositeOperation="source-over",g=b.canvas,f=p=0}else{t.save(),t.globalAlpha=1,t.setTransform(1,0,0,1,0,0);const b=new Path2D;b.rect(f,p,s,i),t.clip(b),t.globalCompositeOperation="destination-atop",t.fillStyle=_,t.fillRect(f,p,s,i),t.restore()}}e.save(),e.globalAlpha=1,e.setTransform(1,0,0,1,0,0),n==="Alpha"&&a?e.filter=this.filterFactory.addAlphaFilter(a):n==="Luminosity"&&(e.filter=this.filterFactory.addLuminosityFilter(a));const m=new Path2D;m.rect(h,l,s,i),e.clip(m),e.globalCompositeOperation="destination-in",e.drawImage(g,f,p,s,i,h,l,s,i),e.restore()}save(){this.inSMaskMode?(Ih(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(),Ih(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,l;const u=It(i),d=u[0]===0&&u[3]===0||u[1]===0&&u[2]===0,g=d?s.slice(0):null;for(let f=0,p=0,m=t.length;f<m;f++)switch(t[f]|0){case zs.rectangle:r=e[p++],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 zs.moveTo:r=e[p++],a=e[p++],i.moveTo(r,a),d||n.updatePathMinMax(u,r,a);break;case zs.lineTo:r=e[p++],a=e[p++],i.lineTo(r,a),d||n.updatePathMinMax(u,r,a);break;case zs.curveTo:h=r,l=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,l,e[p],e[p+1],e[p+2],e[p+3],r,a,g),p+=6;break;case zs.curveTo2:h=r,l=a,i.bezierCurveTo(r,a,e[p],e[p+1],e[p+2],e[p+3]),n.updateCurvePathMinMax(u,h,l,r,a,e[p],e[p+1],e[p+2],e[p+3],g),r=e[p+2],a=e[p+3],p+=4;break;case zs.curveTo3:h=r,l=a,r=e[p+2],a=e[p+3],i.bezierCurveTo(e[p],e[p+1],r,a,r,a),n.updateCurvePathMinMax(u,h,l,e[p],e[p+1],r,a,r,a,g),p+=4;break;case zs.closePath:i.closePath();break}d&&n.updateScalingPathMinMax(u,g),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,zi(e),Be.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,zi(e),Be.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=cS}eoClip(){this.pendingClip=uv}beginText(){this.current.textMatrix=H0,this.current.textMatrixScale=1,this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0}endText(){const t=this.pendingTextPaths,e=this.ctx;if(t===void 0){e.beginPath();return}e.save(),e.beginPath();for(const s of t)e.setTransform(...s.transform),e.translate(s.x,s.y),s.addToPath(e,s.fontSize);e.restore(),e.clip(),e.beginPath(),delete this.pendingTextPaths}setCharSpacing(t){this.current.charSpacing=t}setWordSpacing(t){this.current.wordSpacing=t}setHScale(t){this.current.textHScale=t/100}setLeading(t){this.current.leading=-t}setFont(t,e){var u;const s=this.commonObjs.get(t),i=this.current;if(!s)throw new Error(`Can't find font for ${t}`);if(i.fontMatrix=s.fontMatrix||Ig,(i.fontMatrix[0]===0||i.fontMatrix[3]===0)&&at("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 l=e;e<iv?l=iv:e>nv&&(l=nv),this.current.fontSizeScale=e/l,this.ctx.font=`${h} ${a} ${l}px ${r}`}setTextRenderingMode(t){this.current.textRenderingMode=t}setTextRise(t){this.current.textRise=t}moveText(t,e){this.current.x=this.current.lineX+=t,this.current.y=this.current.lineY+=e}setLeadingMoveText(t,e){this.setLeading(-e),this.moveText(t,e)}setTextMatrix(t,e,s,i,n,r){this.current.textMatrix=[t,e,s,i,n,r],this.current.textMatrixScale=Math.hypot(t,e),this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0}nextLine(){this.moveText(0,this.current.leading)}paintChar(t,e,s,i){const n=this.ctx,r=this.current,a=r.font,h=r.textRenderingMode,l=r.fontSize/r.fontSizeScale,u=h&Te.FILL_STROKE_MASK,d=!!(h&Te.ADD_TO_PATH_FLAG),g=r.patternFill&&!a.missingFile;let f;(a.disableFontFace||d||g)&&(f=a.getPathGenerator(this.commonObjs,t)),a.disableFontFace||g?(n.save(),n.translate(e,s),n.beginPath(),f(n,l),i&&n.setTransform(...i),(u===Te.FILL||u===Te.FILL_STROKE)&&n.fill(),(u===Te.STROKE||u===Te.FILL_STROKE)&&n.stroke(),n.restore()):((u===Te.FILL||u===Te.FILL_STROKE)&&n.fillText(t,e,s),(u===Te.STROKE||u===Te.FILL_STROKE)&&n.strokeText(t,e,s)),d&&(this.pendingTextPaths||(this.pendingTextPaths=[])).push({transform:It(n),x:e,y:s,fontSize:l,addToPath:f})}get isFontSubpixelAAEnabled(){const{context:t}=this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled",10,10);t.scale(1.5,1),t.fillText("I",0,10);const e=t.getImageData(0,0,10,10).data;let s=!1;for(let i=3;i<e.length;i+=4)if(e[i]>0&&e[i]<255){s=!0;break}return ut(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,l=e.fontDirection,u=e.textHScale*l,d=t.length,g=s.vertical,f=g?1:-1,p=s.defaultVMetrics,m=i*e.fontMatrix[0],_=e.textRenderingMode===Te.FILL&&!s.disableFontFace&&!e.patternFill;n.save(),n.transform(...e.textMatrix),n.translate(e.x,e.y+e.textRise),l>0?n.scale(u,-1):n.scale(u,1);let b;if(e.patternFill){n.save();const P=e.fillColor.getPattern(n,this,zi(n),Be.FILL);b=It(n),n.restore(),n.fillStyle=P}let x=e.lineWidth;const S=e.textMatrixScale;if(S===0||x===0){const P=e.textRenderingMode&Te.FILL_STROKE_MASK;(P===Te.STROKE||P===Te.FILL_STROKE)&&(x=this.getSinglePixelWidth())}else x/=S;if(r!==1&&(n.scale(r,r),x/=r),n.lineWidth=x,s.isInvalidPDFjsFont){const P=[];let M=0;for(const O of t)P.push(O.unicode),M+=O.width;n.fillText(P.join(""),0,0),e.x+=M*m*u,n.restore(),this.compose();return}let A=0,k;for(k=0;k<d;++k){const P=t[k];if(typeof P=="number"){A+=f*P*i/1e3;continue}let M=!1;const O=(P.isSpace?h:0)+a,R=P.fontChar,I=P.accent;let j,G,L=P.width;if(g){const $=P.vmetric||p,J=-(P.vmetric?$[1]:L*.5)*m,Y=$[2]*m;L=$?-$[0]:L,j=J/r,G=(A+Y)/r}else j=A/r,G=0;if(s.remeasure&&L>0){const $=n.measureText(R).width*1e3/i*r;if(L<$&&this.isFontSubpixelAAEnabled){const J=L/$;M=!0,n.save(),n.scale(J,1),j/=J}else L!==$&&(j+=(L-$)/2e3*i/r)}if(this.contentVisible&&(P.isInFont||s.missingFile)){if(_&&!I)n.fillText(R,j,G);else if(this.paintChar(R,j,G,b),I){const $=j+i*I.offset.x/r,J=G-i*I.offset.y/r;this.paintChar(I.fontChar,$,J,b)}}const H=g?L*m-O*l:L*m+O*l;A+=H,M&&n.restore()}g?e.y-=A:e.x+=A*u,n.restore(),this.compose()}showType3Text(t){const e=this.ctx,s=this.current,i=s.font,n=s.fontSize,r=s.fontDirection,a=i.vertical?1:-1,h=s.charSpacing,l=s.wordSpacing,u=s.textHScale*r,d=s.fontMatrix||Ig,g=t.length,f=s.textRenderingMode===Te.INVISIBLE;let p,m,_,b;if(!(f||n===0)){for(this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null,e.save(),e.transform(...s.textMatrix),e.translate(s.x,s.y),e.scale(u,r),p=0;p<g;++p){if(m=t[p],typeof m=="number"){b=a*m*n/1e3,this.ctx.translate(b,0),s.x+=b*u;continue}const x=(m.isSpace?l:0)+h,S=i.charProcOperatorList[m.operatorListId];if(!S){at(`Type3 character "${m.operatorListId}" is not available.`);continue}this.contentVisible&&(this.processingType3=m,this.save(),e.scale(n,n),e.transform(...d),this.executeOperatorList(S),this.restore()),_=U.applyTransform([m.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 Sf(r,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack})};e=new rf(t,s,this.ctx,n,i)}else e=this._getPattern(t[1],t[2]);return e}setStrokeColorN(){this.current.strokeColor=this.getColorN_Pattern(arguments)}setFillColorN(){this.current.fillColor=this.getColorN_Pattern(arguments),this.current.patternFill=!0}setStrokeRGBColor(t,e,s){this.ctx.strokeStyle=this.current.strokeColor=U.makeHexColor(t,e,s)}setStrokeTransparent(){this.ctx.strokeStyle=this.current.strokeColor="transparent"}setFillRGBColor(t,e,s){this.ctx.fillStyle=this.current.fillColor=U.makeHexColor(t,e,s),this.current.patternFill=!1}setFillTransparent(){this.ctx.fillStyle=this.current.fillColor="transparent",this.current.patternFill=!1}_getPattern(t,e=null){let s;return this.cachedPatterns.has(t)?s=this.cachedPatterns.get(t):(s=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,zi(e),Be.SHADING);const i=zi(e);if(i){const{width:n,height:r}=e.canvas,[a,h,l,u]=U.getAxialAlignedBoundingBox([0,0,n,r],i);this.ctx.fillRect(a,h,l-a,u-h)}else this.ctx.fillRect(-1e10,-1e10,2e10,2e10);this.compose(this.current.getClippedPathBoundingBox()),this.restore()}beginInlineImage(){Mt("Should not call beginInlineImage")}beginImageData(){Mt("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||Cu("TODO: Support non-isolated groups."),t.knockout&&at("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=U.getAxialAlignedBoundingBox(t.bbox,It(e));const n=[0,0,e.canvas.width,e.canvas.height];i=U.intersect(i,n)||[0,0,0,0];const r=Math.floor(i[0]),a=Math.floor(i[1]),h=Math.max(Math.ceil(i[2])-r,1),l=Math.max(Math.ceil(i[3])-a,1);this.current.startNewPathAndClipBox([0,0,h,l]);let u="groupAt"+this.groupLevel;t.smask&&(u+="_smask_"+this.smaskCounter++%2);const d=this.cachedCanvases.getCanvas(u,h,l),g=d.context;g.translate(-r,-a),g.transform(...s),t.smask?this.smaskStack.push({canvas:d.canvas,context:g,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()),Ih(e,g),this.ctx=g,this.setGState([["BM","source-over"],["ca",1],["CA",1]]),this.groupStack.push(e),this.groupLevel++}endGroup(t){if(!this.contentVisible)return;this.groupLevel--;const e=this.ctx,s=this.groupStack.pop();if(this.ctx=s,this.ctx.imageSmoothingEnabled=!1,t.smask)this.tempSMask=this.smaskStack.pop(),this.restore();else{this.ctx.restore();const i=It(this.ctx);this.restore(),this.ctx.save(),this.ctx.setTransform(...i);const n=U.getAxialAlignedBoundingBox([0,0,e.canvas.width,e.canvas.height],i);this.ctx.drawImage(e.canvas,0,0),this.ctx.restore(),this.compose(n)}}beginAnnotation(t,e,s,i,n){if(y(this,Un,Kf).call(this),Du(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,l]=U.singularValueDecompose2dScale(It(this.ctx)),{viewportScale:u}=this,d=Math.ceil(r*this.outputScaleX*u),g=Math.ceil(a*this.outputScaleY*u);this.annotationCanvas=this.canvasFactory.create(d,g);const{canvas:f,context:p}=this.annotationCanvas;this.annotationCanvasMap.set(t,f),this.annotationCanvas.savedCtx=this.ctx,this.ctx=p,this.ctx.save(),this.ctx.setTransform(h,0,0,-l,0,a*l),Du(this.ctx)}else Du(this.ctx),this.endPath(),this.ctx.rect(e[0],e[1],r,a),this.ctx.clip(),this.ctx.beginPath()}this.current=new ov(this.ctx.canvas.width,this.ctx.canvas.height),this.transform(...s),this.transform(...i)}endAnnotation(){this.annotationCanvas&&(this.ctx.restore(),y(this,Un,Jf).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=oS(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 l=this._createMaskCanvas(t);a.setTransform(1,0,0,1,l.offsetX-h[4],l.offsetY-h[5]);for(let u=0,d=r.length;u<d;u+=2){const g=U.transform(h,[e,s,i,n,r[u],r[u+1]]),[f,p]=U.applyTransform([0,0],g);a.drawImage(l.canvas,f,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:l}=n,u=this.cachedCanvases.getCanvas("maskCanvas",a,h),d=u.context;d.save();const g=this.getObject(r,n);lv(d,g),d.globalCompositeOperation="source-in",d.fillStyle=i?s.getPattern(d,this,zi(e),Be.FILL):s,d.fillRect(0,0,a,h),d.restore(),e.save(),e.transform(...l),e.scale(1,-1),Pu(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){at("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){at("Dependent image isn't ready yet");return}const r=n.width,a=n.height,h=[];for(let l=0,u=i.length;l<u;l+=2)h.push({transform:[e,0,0,s,i[l],i[l+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(),!Ae){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;hv(h,t),n=this.applyTransferMapsToCanvas(h)}const r=this._scaleImage(n,zi(i));i.imageSmoothingEnabled=cv(It(i),t.interpolate),Pu(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;hv(h,t),i=this.applyTransferMapsToCanvas(h)}for(const n of e)s.save(),s.transform(...n.transform),s.scale(1,-1),Pu(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===uv?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),l=Math.abs(n);if(h===l)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/l;else{const u=h*t,d=l*t;r=u<1?1/u:1,a=d<1?1/d:1}}else{const h=Math.abs(e*n-s*i),l=Math.hypot(e,s),u=Math.hypot(i,n);if(t===0)r=u/h,a=l/h;else{const d=t*h;r=u>d?u/d:1,a=l>d?l/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}};Un=new WeakSet,Kf=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)},Jf=function(){if(this.pageColors){const t=this.filterFactory.addHCMFilter(this.pageColors.foreground,this.pageColors.background);if(t!=="none"){const e=this.ctx.filter;this.ctx.filter=t,this.ctx.drawImage(this.ctx.canvas,0,0),this.ctx.filter=e}}};let Za=Sf;for(const o in zs)Za.prototype[o]!==void 0&&(Za.prototype[zs[o]]=Za.prototype[o]);class Vi{static get workerPort(){return c(this,ll)}static set workerPort(t){if(!(typeof Worker<"u"&&t instanceof Worker)&&t!==null)throw new Error("Invalid `workerPort` type.");v(this,ll,t)}static get workerSrc(){return c(this,cl)}static set workerSrc(t){if(typeof t!="string")throw new Error("Invalid `workerSrc` type.");v(this,cl,t)}}ll=new WeakMap,cl=new WeakMap,w(Vi,ll,null),w(Vi,cl,"");const Ru={UNKNOWN:0,DATA:1,ERROR:2},Jt={UNKNOWN:0,CANCEL:1,CANCEL_COMPLETE:2,CLOSE:3,ENQUEUE:4,ERROR:5,PULL:6,PULL_COMPLETE:7,START_COMPLETE:8};function as(o){switch(o instanceof Error||typeof o=="object"&&o!==null||Mt('wrapReason: Expected "reason" to be a (possibly cloned) Error.'),o.name){case"AbortException":return new Er(o.message);case"MissingPDFException":return new Tr(o.message);case"PasswordException":return new Ng(o.message,o.code);case"UnexpectedResponseException":return new Au(o.message,o.status);case"UnknownErrorException":return new Bg(o.message,o.details);default:return new Bg(o.message,o.toString())}}class jh{constructor(t,e,s){w(this,As);w(this,bo,new AbortController);this.sourceName=t,this.targetName=e,this.comObj=s,this.callbackId=1,this.streamId=1,this.streamSinks=Object.create(null),this.streamControllers=Object.create(null),this.callbackCapabilities=Object.create(null),this.actionHandler=Object.create(null),s.addEventListener("message",y(this,As,Sb).bind(this),{signal:c(this,bo).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:l=>{const u=Promise.withResolvers();return this.streamControllers[n]={controller:l,startCall:u,pullCall:null,cancelCall:null,isClosed:!1},h.postMessage({sourceName:r,targetName:a,action:t,streamId:n,data:e,desiredSize:l.desiredSize},i),u.promise},pull:l=>{const u=Promise.withResolvers();return this.streamControllers[n].pullCall=u,h.postMessage({sourceName:r,targetName:a,stream:Jt.PULL,streamId:n,desiredSize:l.desiredSize}),u.promise},cancel:l=>{ne(l 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:Jt.CANCEL,streamId:n,reason:as(l)}),u.promise}},s)}destroy(){var t;(t=c(this,bo))==null||t.abort(),v(this,bo,null)}}bo=new WeakMap,As=new WeakSet,Sb=function({data:t}){if(t.targetName!==this.sourceName)return;if(t.stream){y(this,As,Ab).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===Ru.DATA)i.resolve(t.data);else if(t.callback===Ru.ERROR)i.reject(as(t.reason));else throw new Error("Unexpected callback case");return}const e=this.actionHandler[t.action];if(!e)throw new Error(`Unknown action from worker: ${t.action}`);if(t.callbackId){const s=this.sourceName,i=t.sourceName,n=this.comObj;new Promise(function(r){r(e(t.data))}).then(function(r){n.postMessage({sourceName:s,targetName:i,callback:Ru.DATA,callbackId:t.callbackId,data:r})},function(r){n.postMessage({sourceName:s,targetName:i,callback:Ru.ERROR,callbackId:t.callbackId,reason:as(r)})});return}if(t.streamId){y(this,As,Cb).call(this,t);return}e(t.data)},Cb=function(t){const e=t.streamId,s=this.sourceName,i=t.sourceName,n=this.comObj,r=this,a=this.actionHandler[t.action],h={enqueue(l,u=1,d){if(this.isCancelled)return;const g=this.desiredSize;this.desiredSize-=u,g>0&&this.desiredSize<=0&&(this.sinkCapability=Promise.withResolvers(),this.ready=this.sinkCapability.promise),n.postMessage({sourceName:s,targetName:i,stream:Jt.ENQUEUE,streamId:e,chunk:l},d)},close(){this.isCancelled||(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:Jt.CLOSE,streamId:e}),delete r.streamSinks[e])},error(l){ne(l instanceof Error,"error must have a valid reason"),!this.isCancelled&&(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:Jt.ERROR,streamId:e,reason:as(l)}))},sinkCapability:Promise.withResolvers(),onPull:null,onCancel:null,isCancelled:!1,desiredSize:t.desiredSize,ready:null};h.sinkCapability.resolve(),h.ready=h.sinkCapability.promise,this.streamSinks[e]=h,new Promise(function(l){l(a(t.data,h))}).then(function(){n.postMessage({sourceName:s,targetName:i,stream:Jt.START_COMPLETE,streamId:e,success:!0})},function(l){n.postMessage({sourceName:s,targetName:i,stream:Jt.START_COMPLETE,streamId:e,reason:as(l)})})},Ab=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 Jt.START_COMPLETE:t.success?r.startCall.resolve():r.startCall.reject(as(t.reason));break;case Jt.PULL_COMPLETE:t.success?r.pullCall.resolve():r.pullCall.reject(as(t.reason));break;case Jt.PULL:if(!a){n.postMessage({sourceName:s,targetName:i,stream:Jt.PULL_COMPLETE,streamId:e,success:!0});break}a.desiredSize<=0&&t.desiredSize>0&&a.sinkCapability.resolve(),a.desiredSize=t.desiredSize,new Promise(function(h){var l;h((l=a.onPull)==null?void 0:l.call(a))}).then(function(){n.postMessage({sourceName:s,targetName:i,stream:Jt.PULL_COMPLETE,streamId:e,success:!0})},function(h){n.postMessage({sourceName:s,targetName:i,stream:Jt.PULL_COMPLETE,streamId:e,reason:as(h)})});break;case Jt.ENQUEUE:if(ne(r,"enqueue should have stream controller"),r.isClosed)break;r.controller.enqueue(t.chunk);break;case Jt.CLOSE:if(ne(r,"close should have stream controller"),r.isClosed)break;r.isClosed=!0,r.controller.close(),y(this,As,fd).call(this,r,e);break;case Jt.ERROR:ne(r,"error should have stream controller"),r.controller.error(as(t.reason)),y(this,As,fd).call(this,r,e);break;case Jt.CANCEL_COMPLETE:t.success?r.cancelCall.resolve():r.cancelCall.reject(as(t.reason)),y(this,As,fd).call(this,r,e);break;case Jt.CANCEL:if(!a)break;new Promise(function(h){var l;h((l=a.onCancel)==null?void 0:l.call(a,as(t.reason)))}).then(function(){n.postMessage({sourceName:s,targetName:i,stream:Jt.CANCEL_COMPLETE,streamId:e,success:!0})},function(h){n.postMessage({sourceName:s,targetName:i,stream:Jt.CANCEL_COMPLETE,streamId:e,reason:as(h)})}),a.sinkCapability.reject(as(t.reason)),a.isCancelled=!0,delete this.streamSinks[e];break;default:throw new Error("Unexpected stream case")}},fd=async function(t,e){var s,i,n;await Promise.allSettled([(s=t.startCall)==null?void 0:s.promise,(i=t.pullCall)==null?void 0:i.promise,(n=t.cancelCall)==null?void 0:n.promise]),delete this.streamControllers[e]};class uS{constructor({parsedData:t,rawData:e}){w(this,Qr);w(this,ul);v(this,Qr,t),v(this,ul,e)}getRaw(){return c(this,ul)}get(t){return c(this,Qr).get(t)??null}getAll(){return Hg(c(this,Qr))}has(t){return c(this,Qr).has(t)}}Qr=new WeakMap,ul=new WeakMap;const to=Symbol("INTERNAL");class dS{constructor(t,{name:e,intent:s,usage:i,rbGroups:n}){w(this,dl,!1);w(this,gl,!1);w(this,fl,!1);w(this,yo,!0);v(this,dl,!!(t&rs.DISPLAY)),v(this,gl,!!(t&rs.PRINT)),this.name=e,this.intent=s,this.usage=i,this.rbGroups=n}get visible(){if(c(this,fl))return c(this,yo);if(!c(this,yo))return!1;const{print:t,view:e}=this.usage;return c(this,dl)?(e==null?void 0:e.viewState)!=="OFF":c(this,gl)?(t==null?void 0:t.printState)!=="OFF":!0}_setVisible(t,e,s=!1){t!==to&&Mt("Internal method `_setVisible` called."),v(this,fl,s),v(this,yo,e)}}dl=new WeakMap,gl=new WeakMap,fl=new WeakMap,yo=new WeakMap;class gS{constructor(t,e=rs.DISPLAY){w(this,pl);w(this,qn,null);w(this,xt,new Map);w(this,_o,null);w(this,wo,null);if(this.renderingIntent=e,this.name=null,this.creator=null,t!==null){this.name=t.name,this.creator=t.creator,v(this,wo,t.order);for(const s of t.groups)c(this,xt).set(s.id,new dS(e,s));if(t.baseState==="OFF")for(const s of c(this,xt).values())s._setVisible(to,!1);for(const s of t.on)c(this,xt).get(s)._setVisible(to,!0);for(const s of t.off)c(this,xt).get(s)._setVisible(to,!1);v(this,_o,this.getHash())}}isVisible(t){if(c(this,xt).size===0)return!0;if(!t)return Cu("Optional content group not defined."),!0;if(t.type==="OCG")return c(this,xt).has(t.id)?c(this,xt).get(t.id).visible:(at(`Optional content group not found: ${t.id}`),!0);if(t.type==="OCMD"){if(t.expression)return y(this,pl,Qf).call(this,t.expression);if(!t.policy||t.policy==="AnyOn"){for(const e of t.ids){if(!c(this,xt).has(e))return at(`Optional content group not found: ${e}`),!0;if(c(this,xt).get(e).visible)return!0}return!1}else if(t.policy==="AllOn"){for(const e of t.ids){if(!c(this,xt).has(e))return at(`Optional content group not found: ${e}`),!0;if(!c(this,xt).get(e).visible)return!1}return!0}else if(t.policy==="AnyOff"){for(const e of t.ids){if(!c(this,xt).has(e))return at(`Optional content group not found: ${e}`),!0;if(!c(this,xt).get(e).visible)return!0}return!1}else if(t.policy==="AllOff"){for(const e of t.ids){if(!c(this,xt).has(e))return at(`Optional content group not found: ${e}`),!0;if(c(this,xt).get(e).visible)return!1}return!0}return at(`Unknown optional content policy ${t.policy}.`),!0}return at(`Unknown group type ${t.type}.`),!0}setVisibility(t,e=!0,s=!0){var n;const i=c(this,xt).get(t);if(!i){at(`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=c(this,xt).get(a))==null||n._setVisible(to,!1,!0));i._setVisible(to,!!e,!0),v(this,qn,null)}setOCGState({state:t,preserveRB:e}){let s;for(const i of t){switch(i){case"ON":case"OFF":case"Toggle":s=i;continue}const n=c(this,xt).get(i);if(n)switch(s){case"ON":this.setVisibility(i,!0,e);break;case"OFF":this.setVisibility(i,!1,e);break;case"Toggle":this.setVisibility(i,!n.visible,e);break}}v(this,qn,null)}get hasInitialVisibility(){return c(this,_o)===null||this.getHash()===c(this,_o)}getOrder(){return c(this,xt).size?c(this,wo)?c(this,wo).slice():[...c(this,xt).keys()]:null}getGroups(){return c(this,xt).size>0?Hg(c(this,xt)):null}getGroup(t){return c(this,xt).get(t)||null}getHash(){if(c(this,qn)!==null)return c(this,qn);const t=new U0;for(const[e,s]of c(this,xt))t.update(`${e}:${s.visible}`);return v(this,qn,t.hexdigest())}}qn=new WeakMap,xt=new WeakMap,_o=new WeakMap,wo=new WeakMap,pl=new WeakSet,Qf=function(t){const e=t.length;if(e<2)return!0;const s=t[0];for(let i=1;i<e;i++){const n=t[i];let r;if(Array.isArray(n))r=y(this,pl,Qf).call(this,n);else if(c(this,xt).has(n))r=c(this,xt).get(n).visible;else return at(`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,l)=>{this._onReceiveData({begin:h,chunk:l})}),t.addProgressListener((h,l)=>{this._onProgress({loaded:h,total:l})}),t.addProgressiveReadListener(h=>{this._onReceiveData({chunk:h})}),t.addProgressiveDoneListener(()=>{this._onProgressiveDone()}),t.transportReady()}_onReceiveData({begin:t,chunk:e}){const s=e instanceof Uint8Array&&e.byteLength===e.buffer.byteLength?e.buffer:new Uint8Array(e).buffer;if(t===void 0)this._fullRequestReader?this._fullRequestReader._enqueue(s):this._queuedChunks.push(s);else{const i=this._rangeReaders.some(function(n){return n._begin!==t?!1:(n._enqueue(s),!0)});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 pS(this,t,this._progressiveDone,this._contentDispositionFilename)}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new mS(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 pS{constructor(t,e,s=!1,i=null){this._stream=t,this._done=s||!1,this._filename=Gg(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 mS{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 vS(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=l(u),n(u)}if(e=r(o),e){const u=l(e);return n(u)}if(e=s("filename","i").exec(o),e){e=e[1];let u=a(e);return u=l(u),n(u)}function s(u,d){return new RegExp("(?:^|;)\\s*"+u+'\\s*=\\s*([^";\\s][^;\\s]*|"(?:[^"\\\\]|\\\\"?)+"?)',d)}function i(u,d){if(u){if(!/^[\x00-\xFF]+$/.test(d))return d;try{const g=new TextDecoder(u,{fatal:!0}),f=Tu(d);d=g.decode(f),t=!1}catch{}}return d}function n(u){return t&&/[\x80-\xff]/.test(u)&&(u=i("utf-8",u),t&&(u=i("iso-8859-1",u))),u}function r(u){const d=[];let g;const f=s("filename\\*((?!0\\d)\\d+)(\\*?)","ig");for(;(g=f.exec(u))!==null;){let[,m,_,b]=g;if(m=parseInt(m,10),m in d){if(m===0)break;continue}d[m]=[_,b]}const p=[];for(let m=0;m<d.length&&m in d;++m){let[_,b]=d[m];b=a(b),_&&(b=unescape(b),m===0&&(b=h(b))),p.push(b)}return p.join("")}function a(u){if(u.startsWith('"')){const d=u.slice(1).split('\\"');for(let g=0;g<d.length;++g){const f=d[g].indexOf('"');f!==-1&&(d[g]=d[g].slice(0,f),d.length=g+1),d[g]=d[g].replaceAll(/\\(.)/g,"$1")}u=d.join('"')}return u}function h(u){const d=u.indexOf("'");if(d===-1)return u;const g=u.slice(0,d),p=u.slice(d+1).replace(/^[^']*'/,"");return i(g,p)}function l(u){return!u.startsWith("=?")||/[\x00-\x19\x80-\xff]/.test(u)?u:u.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,function(d,g,f,p){if(f==="q"||f==="Q")return p=p.replaceAll("_"," "),p=p.replaceAll(/=([0-9a-fA-F]{2})/g,function(m,_){return String.fromCharCode(parseInt(_,16))}),i(g,p);try{p=atob(p)}catch{}return i(g,p)})}return""}function af(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 of({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 hf(o){const t=o.get("Content-Disposition");if(t){let e=vS(t);if(e.includes("%"))try{e=decodeURIComponent(e)}catch{}if(Gg(e))return e}return null}function Fu(o,t){return o===404||o===0&&t.startsWith("file:")?new Tr('Missing PDF "'+t+'".'):new Au(`Unexpected server response (${o}) while retrieving PDF "${t}".`,o)}function dv(o){return o===200||o===206}function gv(o,t,e){return{method:"GET",headers:o,signal:e.signal,mode:"cors",credentials:t?"include":"same-origin",redirect:"follow"}}function fv(o){return o instanceof Uint8Array?o.buffer:o instanceof ArrayBuffer?o:(at(`getArrayBuffer - unexpected data format: ${o}`),new Uint8Array(o).buffer)}class pv{constructor(t){this.source=t,this.isHttp=/^https?:/i.test(t.url),this.headers=af(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 yS(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,gv(s,this._withCredentials,this._abortController)).then(n=>{if(!dv(n.status))throw Fu(n.status,i);this._reader=n.body.getReader(),this._headersCapability.resolve();const r=n.headers,{allowRangeRequests:a,suggestedLength:h}=of({responseHeaders:r,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=a,this._contentLength=h||this._contentLength,this._filename=hf(r),!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new Er("Streaming is disabled."))}).catch(this._headersCapability.reject),this.onProgress=null}get headersReady(){return this._headersCapability.promise}get filename(){return this._filename}get contentLength(){return this._contentLength}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;await this._headersCapability.promise;const{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:(this._loaded+=t.byteLength,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded,total:this._contentLength}),{value:fv(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}class yS{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,gv(n,this._withCredentials,this._abortController)).then(a=>{if(!dv(a.status))throw Fu(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:fv(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}const lf=200,cf=206;function _S(o){const t=o.response;return typeof t!="string"?t:Tu(t).buffer}class wS{constructor({url:t,httpHeaders:e,withCredentials:s}){this.url=t,this.isHttp=/^https?:/i.test(t),this.headers=af(this.isHttp,e),this.withCredentials=s||!1,this.currXhrId=0,this.pendingRequests=Object.create(null)}requestRange(t,e,s){const i={begin:t,end:e};for(const n in s)i[n]=s[n];return this.request(i)}requestFull(t){return this.request(t)}request(t){const e=new XMLHttpRequest,s=this.currXhrId++,i=this.pendingRequests[s]={xhr:e};e.open("GET",this.url),e.withCredentials=this.withCredentials;for(const[n,r]of this.headers)e.setRequestHeader(n,r);return this.isHttp&&"begin"in t&&"end"in t?(e.setRequestHeader("Range",`bytes=${t.begin}-${t.end-1}`),i.expectedStatus=cf):i.expectedStatus=lf,e.responseType="arraybuffer",t.onError&&(e.onerror=function(n){t.onError(e.status)}),e.onreadystatechange=this.onStateChange.bind(this,s),e.onprogress=this.onProgress.bind(this,s),i.onHeadersReceived=t.onHeadersReceived,i.onDone=t.onDone,i.onError=t.onError,i.onProgress=t.onProgress,e.send(null),s}onProgress(t,e){var i;const s=this.pendingRequests[t];s&&((i=s.onProgress)==null||i.call(s,e))}onStateChange(t,e){var h,l,u;const s=this.pendingRequests[t];if(!s)return;const i=s.xhr;if(i.readyState>=2&&s.onHeadersReceived&&(s.onHeadersReceived(),delete s.onHeadersReceived),i.readyState!==4||!(t in this.pendingRequests))return;if(delete this.pendingRequests[t],i.status===0&&this.isHttp){(h=s.onError)==null||h.call(s,i.status);return}const n=i.status||lf;if(!(n===lf&&s.expectedStatus===cf)&&n!==s.expectedStatus){(l=s.onError)==null||l.call(s,i.status);return}const a=_S(i);if(n===cf){const d=i.getResponseHeader("Content-Range"),g=/bytes (\d+)-(\d+)\/(\d+)/.exec(d);s.onDone({begin:parseInt(g[1],10),chunk:a})}else a?s.onDone({begin:0,chunk:a}):(u=s.onError)==null||u.call(s,i.status)}getRequestXhr(t){return this.pendingRequests[t].xhr}isPendingRequest(t){return t in this.pendingRequests}abortRequest(t){const e=this.pendingRequests[t].xhr;delete this.pendingRequests[t],e.abort()}}class xS{constructor(t){this._source=t,this._manager=new wS(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 SS(this._manager,this._source),this._fullRequestReader}getRangeReader(t,e){const s=new CS(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 SS{constructor(t,e){this._manager=t;const s={onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)};this._url=e.url,this._fullRequestId=t.requestFull(s),this._headersCapability=Promise.withResolvers(),this._disableRange=e.disableRange||!1,this._contentLength=e.length,this._rangeChunkSize=e.rangeChunkSize,!this._rangeChunkSize&&!this._disableRange&&(this._disableRange=!0),this._isStreamingSupported=!1,this._isRangeSupported=!1,this._cachedChunks=[],this._requests=[],this._done=!1,this._storedError=void 0,this._filename=null,this.onProgress=null}_onHeadersReceived(){const t=this._fullRequestId,e=this._manager.getRequestXhr(t),s=new Headers(e.getAllResponseHeaders().trim().split(/[\r\n]+/).map(r=>{const[a,...h]=r.split(": ");return[a,h.join(": ")]})),{allowRangeRequests:i,suggestedLength:n}=of({responseHeaders:s,isHttp:this._manager.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});i&&(this._isRangeSupported=!0),this._contentLength=n||this._contentLength,this._filename=hf(s),this._isRangeSupported&&this._manager.abortRequest(t),this._headersCapability.resolve()}_onDone(t){if(t&&(this._requests.length>0?this._requests.shift().resolve({value:t.chunk,done:!1}):this._cachedChunks.push(t.chunk)),this._done=!0,!(this._cachedChunks.length>0)){for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}}_onError(t){this._storedError=Fu(t,this._url),this._headersCapability.reject(this._storedError);for(const e of this._requests)e.reject(this._storedError);this._requests.length=0,this._cachedChunks.length=0}_onProgress(t){var e;(e=this.onProgress)==null||e.call(this,{loaded:t.loaded,total:t.lengthComputable?t.total:this._contentLength})}get filename(){return this._filename}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}get contentLength(){return this._contentLength}get headersReady(){return this._headersCapability.promise}async read(){if(this._storedError)throw this._storedError;if(this._cachedChunks.length>0)return{value:this._cachedChunks.shift(),done:!1};if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0,this._headersCapability.reject(t);for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._manager.isPendingRequest(this._fullRequestId)&&this._manager.abortRequest(this._fullRequestId),this._fullRequestReader=null}}class CS{constructor(t,e,s){this._manager=t;const i={onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)};this._url=t.url,this._requestId=t.requestRange(e,s,i),this._requests=[],this._queuedChunk=null,this._done=!1,this._storedError=void 0,this.onProgress=null,this.onClosed=null}_close(){var t;(t=this.onClosed)==null||t.call(this,this)}_onDone(t){const e=t.chunk;this._requests.length>0?this._requests.shift().resolve({value:e,done:!1}):this._queuedChunk=e,this._done=!0;for(const s of this._requests)s.resolve({value:void 0,done:!0});this._requests.length=0,this._close()}_onError(t){this._storedError=Fu(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 AS=/^[a-z][a-z0-9\-+.]+:/i;function TS(o){if(AS.test(o))return new URL(o);const t=Fn.get("url");return new URL(t.pathToFileURL(o))}function mv(o,t,e){return o.protocol==="http:"?Fn.get("http").request(o,{headers:t},e):Fn.get("https").request(o,{headers:t},e)}class ES{constructor(t){this.source=t,this.url=TS(t.url),this.isHttp=this.url.protocol==="http:"||this.url.protocol==="https:",this.isFsUrl=this.url.protocol==="file:",this.headers=af(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,"PDFNodeStream.getFullReader can only be called once."),this._fullRequestReader=this.isFsUrl?new OS(this):new kS(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=this.isFsUrl?new PS(this,t,e):new MS(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 vv{constructor(t){this._url=t.url,this._done=!1,this._storedError=null,this.onProgress=null;const e=t.source;this._contentLength=e.length,this._loaded=0,this._filename=null,this._disableRange=e.disableRange||!1,this._rangeChunkSize=e.rangeChunkSize,!this._rangeChunkSize&&!this._disableRange&&(this._disableRange=!0),this._isStreamingSupported=!e.disableStream,this._isRangeSupported=!e.disableRange,this._readableStream=null,this._readCapability=Promise.withResolvers(),this._headersCapability=Promise.withResolvers()}get headersReady(){return this._headersCapability.promise}get filename(){return this._filename}get contentLength(){return this._contentLength}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;if(await this._readCapability.promise,this._done)return{value:void 0,done:!0};if(this._storedError)throw this._storedError;const t=this._readableStream.read();return t===null?(this._readCapability=Promise.withResolvers(),this.read()):(this._loaded+=t.length,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded,total:this._contentLength}),{value:new Uint8Array(t).buffer,done:!1})}cancel(t){if(!this._readableStream){this._error(t);return}this._readableStream.destroy(t)}_error(t){this._storedError=t,this._readCapability.resolve()}_setReadableStream(t){this._readableStream=t,t.on("readable",()=>{this._readCapability.resolve()}),t.on("end",()=>{t.destroy(),this._done=!0,this._readCapability.resolve()}),t.on("error",e=>{this._error(e)}),!this._isStreamingSupported&&this._isRangeSupported&&this._error(new Er("streaming is disabled")),this._storedError&&this._readableStream.destroy(this._storedError)}}class bv{constructor(t){this._url=t.url,this._done=!1,this._storedError=null,this.onProgress=null,this._loaded=0,this._readableStream=null,this._readCapability=Promise.withResolvers();const e=t.source;this._isStreamingSupported=!e.disableStream}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;if(await this._readCapability.promise,this._done)return{value:void 0,done:!0};if(this._storedError)throw this._storedError;const t=this._readableStream.read();return t===null?(this._readCapability=Promise.withResolvers(),this.read()):(this._loaded+=t.length,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded}),{value:new Uint8Array(t).buffer,done:!1})}cancel(t){if(!this._readableStream){this._error(t);return}this._readableStream.destroy(t)}_error(t){this._storedError=t,this._readCapability.resolve()}_setReadableStream(t){this._readableStream=t,t.on("readable",()=>{this._readCapability.resolve()}),t.on("end",()=>{t.destroy(),this._done=!0,this._readCapability.resolve()}),t.on("error",e=>{this._error(e)}),this._storedError&&this._readableStream.destroy(this._storedError)}}class kS extends vv{constructor(t){super(t);const e=Object.fromEntries(t.headers),s=i=>{if(i.statusCode===404){const h=new Tr(`Missing PDF "${this._url}".`);this._storedError=h,this._headersCapability.reject(h);return}this._headersCapability.resolve(),this._setReadableStream(i);const n=new Headers(this._readableStream.headers),{allowRangeRequests:r,suggestedLength:a}=of({responseHeaders:n,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=r,this._contentLength=a||this._contentLength,this._filename=hf(n)};this._request=mv(this._url,e,s),this._request.on("error",i=>{this._storedError=i,this._headersCapability.reject(i)}),this._request.end()}}class MS extends bv{constructor(t,e,s){super(t);const i=Object.fromEntries(t.headers);i.Range=`bytes=${e}-${s-1}`;const n=r=>{if(r.statusCode===404){const a=new Tr(`Missing PDF "${this._url}".`);this._storedError=a;return}this._setReadableStream(r)};this._request=mv(this._url,i,n),this._request.on("error",r=>{this._storedError=r}),this._request.end()}}class OS extends vv{constructor(t){super(t);const e=Fn.get("fs");e.promises.lstat(this._url).then(s=>{this._contentLength=s.size,this._setReadableStream(e.createReadStream(this._url)),this._headersCapability.resolve()},s=>{s.code==="ENOENT"&&(s=new Tr(`Missing PDF "${this._url}".`)),this._storedError=s,this._headersCapability.reject(s)})}}class PS extends bv{constructor(t,e,s){super(t);const i=Fn.get("fs");this._setReadableStream(i.createReadStream(this._url,{start:e,end:s-1}))}}const DS=1e5,Ke=30,RS=.8,ae=class ae{constructor({textContentSource:t,container:e,viewport:s}){w(this,en);w(this,$n,Promise.withResolvers());w(this,Qe,null);w(this,ml,!1);w(this,vl,!!((Lv=globalThis.FontInspector)!=null&&Lv.enabled));w(this,Zr,null);w(this,tn,null);w(this,bl,0);w(this,yl,0);w(this,ta,null);w(this,xo,null);w(this,So,0);w(this,Kn,0);w(this,Co,Object.create(null));w(this,_l,[]);w(this,Ao,null);w(this,ea,[]);w(this,wl,new WeakMap);w(this,xl,null);var h;if(t instanceof ReadableStream)v(this,Ao,t);else if(typeof t=="object")v(this,Ao,new ReadableStream({start(l){l.enqueue(t),l.close()}}));else throw new Error('No "textContentSource" parameter specified.');v(this,Qe,v(this,xo,e)),v(this,Kn,s.scale*(globalThis.devicePixelRatio||1)),v(this,So,s.rotation),v(this,tn,{div:null,properties:null,ctx:null});const{pageWidth:i,pageHeight:n,pageX:r,pageY:a}=s.rawDims;v(this,xl,[1,0,0,-1,-r,a+n]),v(this,yl,i),v(this,bl,n),y(h=ae,ls,kb).call(h),kr(e,s),c(this,$n).promise.finally(()=>{c(ae,To).delete(this),v(this,tn,null),v(this,Co,null)}).catch(()=>{})}static get fontFamilyMap(){const{isWindows:t,isFirefox:e}=Ne.platform;return ut(this,"fontFamilyMap",new Map([["sans-serif",`${t&&e?"Calibri, ":""}sans-serif`],["monospace",`${t&&e?"Lucida Console, ":""}monospace`]]))}render(){const t=()=>{c(this,ta).read().then(({value:e,done:s})=>{if(s){c(this,$n).resolve();return}c(this,Zr)??v(this,Zr,e.lang),Object.assign(c(this,Co),e.styles),y(this,en,Tb).call(this,e.items),t()},c(this,$n).reject)};return v(this,ta,c(this,Ao).getReader()),c(ae,To).add(this),t(),c(this,$n).promise}update({viewport:t,onBefore:e=null}){var n;const s=t.scale*(globalThis.devicePixelRatio||1),i=t.rotation;if(i!==c(this,So)&&(e==null||e(),v(this,So,i),kr(c(this,xo),{rotation:i})),s!==c(this,Kn)){e==null||e(),v(this,Kn,s);const r={div:null,properties:null,ctx:y(n=ae,ls,pd).call(n,c(this,Zr))};for(const a of c(this,ea))r.properties=c(this,wl).get(a),r.div=a,y(this,en,Zf).call(this,r)}}cancel(){var e;const t=new Er("TextLayer task cancelled.");(e=c(this,ta))==null||e.cancel(t).catch(()=>{}),v(this,ta,null),c(this,$n).reject(t)}get textDivs(){return c(this,ea)}get textContentItemsStr(){return c(this,_l)}static cleanup(){if(!(c(this,To).size>0)){c(this,sa).clear();for(const{canvas:t}of c(this,ia).values())t.remove();c(this,ia).clear()}}};$n=new WeakMap,Qe=new WeakMap,ml=new WeakMap,vl=new WeakMap,Zr=new WeakMap,tn=new WeakMap,bl=new WeakMap,yl=new WeakMap,ta=new WeakMap,xo=new WeakMap,So=new WeakMap,Kn=new WeakMap,Co=new WeakMap,_l=new WeakMap,Ao=new WeakMap,ea=new WeakMap,wl=new WeakMap,xl=new WeakMap,sa=new WeakMap,ia=new WeakMap,Sl=new WeakMap,Jn=new WeakMap,To=new WeakMap,en=new WeakSet,Tb=function(t){var i,n;if(c(this,ml))return;(n=c(this,tn)).ctx??(n.ctx=y(i=ae,ls,pd).call(i,c(this,Zr)));const e=c(this,ea),s=c(this,_l);for(const r of t){if(e.length>DS){at("Ignoring additional textDivs for performance reasons."),v(this,ml,!0);return}if(r.str===void 0){if(r.type==="beginMarkedContentProps"||r.type==="beginMarkedContent"){const a=c(this,Qe);v(this,Qe,document.createElement("span")),c(this,Qe).classList.add("markedContent"),r.id!==null&&c(this,Qe).setAttribute("id",`${r.id}`),a.append(c(this,Qe))}else r.type==="endMarkedContent"&&v(this,Qe,c(this,Qe).parentNode);continue}s.push(r.str),y(this,en,Eb).call(this,r)}},Eb=function(t){var m;const e=document.createElement("span"),s={angle:0,canvasWidth:0,hasText:t.str!=="",hasEOL:t.hasEOL,fontSize:0};c(this,ea).push(e);const i=U.transform(c(this,xl),t.transform);let n=Math.atan2(i[1],i[0]);const r=c(this,Co)[t.fontName];r.vertical&&(n+=Math.PI/2);let a=c(this,vl)&&r.fontSubstitution||r.fontFamily;a=ae.fontFamilyMap.get(a)||a;const h=Math.hypot(i[2],i[3]),l=h*y(m=ae,ls,Mb).call(m,a,c(this,Zr));let u,d;n===0?(u=i[4],d=i[5]-l):(u=i[4]+l*Math.sin(n),d=i[5]-l*Math.cos(n));const g="calc(var(--scale-factor)*",f=e.style;c(this,Qe)===c(this,xo)?(f.left=`${(100*u/c(this,yl)).toFixed(2)}%`,f.top=`${(100*d/c(this,bl)).toFixed(2)}%`):(f.left=`${g}${u.toFixed(2)}px)`,f.top=`${g}${d.toFixed(2)}px)`),f.fontSize=`${g}${(c(ae,Jn)*h).toFixed(2)}px)`,f.fontFamily=a,s.fontSize=h,e.setAttribute("role","presentation"),e.textContent=t.str,e.dir=t.dir,c(this,vl)&&(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),c(this,wl).set(e,s),c(this,tn).div=e,c(this,tn).properties=s,y(this,en,Zf).call(this,c(this,tn)),s.hasText&&c(this,Qe).append(e),s.hasEOL){const _=document.createElement("br");_.setAttribute("role","presentation"),c(this,Qe).append(_)}},Zf=function(t){var a;const{div:e,properties:s,ctx:i}=t,{style:n}=e;let r="";if(c(ae,Jn)>1&&(r=`scale(${1/c(ae,Jn)})`),s.canvasWidth!==0&&s.hasText){const{fontFamily:h}=n,{canvasWidth:l,fontSize:u}=s;y(a=ae,ls,tp).call(a,i,u*c(this,Kn),h);const{width:d}=i.measureText(e.textContent);d>0&&(r=`scaleX(${l*c(this,Kn)/d}) ${r}`)}s.angle!==0&&(r=`rotate(${s.angle}deg) ${r}`),r.length>0&&(n.transform=r)},ls=new WeakSet,pd=function(t=null){let e=c(this,ia).get(t||(t=""));if(!e){const s=document.createElement("canvas");s.className="hiddenCanvasElement",s.lang=t,document.body.append(s),e=s.getContext("2d",{alpha:!1,willReadFrequently:!0}),c(this,ia).set(t,e),c(this,Sl).set(e,{size:0,family:""})}return e},tp=function(t,e,s){const i=c(this,Sl).get(t);e===i.size&&s===i.family||(t.font=`${e}px ${s}`,i.size=e,i.family=s)},kb=function(){if(c(this,Jn)!==null)return;const t=document.createElement("div");t.style.opacity=0,t.style.lineHeight=1,t.style.fontSize="1px",t.style.position="absolute",t.textContent="X",document.body.append(t),v(this,Jn,t.getBoundingClientRect().height),t.remove()},Mb=function(t,e){const s=c(this,sa).get(t);if(s)return s;const i=y(this,ls,pd).call(this,e);i.canvas.width=i.canvas.height=Ke,y(this,ls,tp).call(this,i,Ke,t);const n=i.measureText("");let r=n.fontBoundingBoxAscent,a=Math.abs(n.fontBoundingBoxDescent);if(r){const u=r/(r+a);return c(this,sa).set(t,u),i.canvas.width=i.canvas.height=0,u}i.strokeStyle="red",i.clearRect(0,0,Ke,Ke),i.strokeText("g",0,0);let h=i.getImageData(0,0,Ke,Ke).data;a=0;for(let u=h.length-1-3;u>=0;u-=4)if(h[u]>0){a=Math.ceil(u/4/Ke);break}i.clearRect(0,0,Ke,Ke),i.strokeText("A",0,Ke),h=i.getImageData(0,0,Ke,Ke).data,r=0;for(let u=0,d=h.length;u<d;u+=4)if(h[u]>0){r=Ke-Math.floor(u/4/Ke);break}i.canvas.width=i.canvas.height=0;const l=r?r/(r+a):RS;return c(this,sa).set(t,l),l},w(ae,ls),w(ae,sa,new Map),w(ae,ia,new Map),w(ae,Sl,new WeakMap),w(ae,Jn,null),w(ae,To,new Set);let Nh=ae;class Bh{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(Bh.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 l of n.children)i(l)}return i(t),s}static shouldBuildText(t){return!(t==="textarea"||t==="input"||t==="option"||t==="select")}}const FS=65536,LS=100,IS=5e3,jS=Ae?$x:Yx,NS=Ae?Kx:J0,BS=Ae?qx:Ux,HS=Ae?Jx:tv;function WS(o={}){typeof o=="string"||o instanceof URL?o={url:o}:(o instanceof ArrayBuffer||ArrayBuffer.isView(o))&&(o={data:o});const t=new uf,{docId:e}=t,s=o.url?XS(o.url):null,i=o.data?zS(o.data):null,n=o.httpHeaders||null,r=o.withCredentials===!0,a=o.password??null,h=o.range instanceof _v?o.range:null,l=Number.isInteger(o.rangeChunkSize)&&o.rangeChunkSize>0?o.rangeChunkSize:FS;let u=o.worker instanceof eo?o.worker:null;const d=o.verbosity,g=typeof o.docBaseUrl=="string"&&!ku(o.docBaseUrl)?o.docBaseUrl:null,f=typeof o.cMapUrl=="string"?o.cMapUrl:null,p=o.cMapPacked!==!1,m=o.CMapReaderFactory||NS,_=typeof o.standardFontDataUrl=="string"?o.standardFontDataUrl:null,b=o.StandardFontDataFactory||HS,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:!Ae,P=typeof o.isChrome=="boolean"?o.isChrome:!Ne.platform.isFirefox&&typeof window<"u"&&!!(window!=null&&window.chrome),M=Number.isInteger(o.canvasMaxAreaInBytes)?o.canvasMaxAreaInBytes:-1,O=typeof o.disableFontFace=="boolean"?o.disableFontFace:Ae,R=o.fontExtraProperties===!0,I=o.enableXfa===!0,j=o.ownerDocument||globalThis.document,G=o.disableRange===!0,L=o.disableStream===!0,H=o.disableAutoFetch===!0,$=o.pdfBug===!0,J=o.CanvasFactory||jS,Y=o.FilterFactory||BS,X=o.enableHWA===!0,Ot=h?h.length:o.length??NaN,zt=typeof o.useSystemFonts=="boolean"?o.useSystemFonts:!Ae&&!O,te=typeof o.useWorkerFetch=="boolean"?o.useWorkerFetch:m===J0&&b===tv&&f&&_&&Rh(f,document.baseURI)&&Rh(_,document.baseURI);o.canvasFactory&&G0("`canvasFactory`-instance option, please use `CanvasFactory` instead."),o.filterFactory&&G0("`filterFactory`-instance option, please use `FilterFactory` instead.");const Ht=null;Sx(d);const At={canvasFactory:new J({ownerDocument:j,enableHWA:X}),filterFactory:new Y({docId:e,ownerDocument:j}),cMapReaderFactory:te?null:new m({baseUrl:f,isCompressed:p}),standardFontDataFactory:te?null:new b({baseUrl:_})};if(!u){const kt={verbosity:d,port:Vi.workerPort};u=kt.port?eo.fromPort(kt):new eo(kt),t._worker=u}const _e={docId:e,apiVersion:"4.8.69",data:i,password:a,disableAutoFetch:H,rangeChunkSize:l,length:Ot,docBaseUrl:g,enableXfa:I,evaluatorOptions:{maxImageSize:S,disableFontFace:O,ignoreErrors:x,isEvalSupported:A,isOffscreenCanvasSupported:k,isChrome:P,canvasMaxAreaInBytes:M,fontExtraProperties:R,useSystemFonts:zt,cMapUrl:te?f:null,standardFontDataUrl:te?_:null}},Ps={disableFontFace:O,fontExtraProperties:R,ownerDocument:j,pdfBug:$,styleElement:Ht,loadingParams:{disableAutoFetch:H,enableXfa:I}};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",_e,i?[i.buffer]:null);let gt;if(h)gt=new fS(h,{disableRange:G,disableStream:L});else if(!i){if(!s)throw new Error("getDocument - no `url` parameter provided.");let Ds;Ae?Ds=typeof fetch<"u"&&typeof Response<"u"&&"body"in Response.prototype&&Rh(s)?pv:ES:Ds=Rh(s)?pv:xS,gt=new Ds({url:s,length:Ot,httpHeaders:n,withCredentials:r,rangeChunkSize:l,disableRange:G,disableStream:L})}return kt.then(Ds=>{if(t.destroyed)throw new Error("Loading aborted");if(u.destroyed)throw new Error("Worker was destroyed");const ri=new jh(e,Ds,u.port),ze=new US(ri,t,gt,Ps,At);t._transport=ze,ri.send("Ready",null)})}).catch(t._capability.reject),t}function XS(o){if(o instanceof URL)return o.href;try{return new URL(o,window.location).href}catch{if(Ae&&typeof o=="string")return o}throw new Error("Invalid PDF url data: either string or URL-object is expected in the url property.")}function zS(o){if(Ae&&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 Tu(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 yv(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 Ju=class Ju{constructor(){this._capability=Promise.withResolvers(),this._transport=null,this._worker=null,this.docId=`d${Ge(Ju,Ku)._++}`,this.destroyed=!1,this.onPassword=null,this.onProgress=null}get promise(){return this._capability.promise}async destroy(){var t,e,s;this.destroyed=!0;try{(t=this._worker)!=null&&t.port&&(this._worker._pendingDestroy=!0),await((e=this._transport)==null?void 0:e.destroy())}catch(i){throw(s=this._worker)!=null&&s.port&&delete this._worker._pendingDestroy,i}this._transport=null,this._worker&&(this._worker.destroy(),this._worker=null)}};Ku=new WeakMap,w(Ju,Ku,0);let uf=Ju;class _v{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){Mt("Abstract method PDFDataRangeTransport.requestDataRange")}abort(){}}class VS{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 ut(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 GS{constructor(t,e,s,i=!1){w(this,Ts);w(this,Qn,null);w(this,sn,!1);this._pageIndex=t,this._pageInfo=e,this._transport=s,this._stats=i?new V0:null,this._pdfBug=i,this.commonObjs=s.commonObjs,this.objs=new wv,this._maybeCleanupAfterRender=!1,this._intentStates=new Map,this.destroyed=!1}get pageNumber(){return this._pageIndex+1}get rotate(){return this._pageInfo.rotate}get ref(){return this._pageInfo.ref}get userUnit(){return this._pageInfo.userUnit}get view(){return this._pageInfo.view}getViewport({scale:t,rotation:e=this.rotate,offsetX:s=0,offsetY:i=0,dontFlip:n=!1}={}){return new Dh({viewBox:this.view,scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}getAnnotations({intent:t="display"}={}){const{renderingIntent:e}=this._transport.getRenderingIntent(t);return this._transport.getAnnotations(this._pageIndex,e)}getJSActions(){return this._transport.getPageJSActions(this._pageIndex)}get filterFactory(){return this._transport.filterFactory}get isPureXfa(){return ut(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=Pn.ENABLE,transform:n=null,background:r=null,optionalContentConfigPromise:a=null,annotationCanvasMap:h=null,pageColors:l=null,printAnnotationStorage:u=null,isEditing:d=!1}){var A,k;(A=this._stats)==null||A.time("Overall");const g=this._transport.getRenderingIntent(s,i,u,d),{renderingIntent:f,cacheKey:p}=g;v(this,sn,!1),y(this,Ts,md).call(this),a||(a=this._transport.getOptionalContentConfig(f));let m=this._intentStates.get(p);m||(m=Object.create(null),this._intentStates.set(p,m)),m.streamReaderCancelTimeout&&(clearTimeout(m.streamReaderCancelTimeout),m.streamReaderCancelTimeout=null);const _=!!(f&rs.PRINT);m.displayReadyCapability||(m.displayReadyCapability=Promise.withResolvers(),m.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(k=this._stats)==null||k.time("Page Request"),this._pumpOperatorList(g));const b=P=>{var M;m.renderTasks.delete(x),(this._maybeCleanupAfterRender||_)&&v(this,sn,!0),y(this,Ts,hh).call(this,!_),P?(x.capability.reject(P),this._abortOperatorList({intentState:m,reason:P instanceof Error?P:new Error(P)})):x.capability.resolve(),this._stats&&(this._stats.timeEnd("Rendering"),this._stats.timeEnd("Overall"),(M=globalThis.Stats)!=null&&M.enabled&&globalThis.Stats.add(this.pageNumber,this._stats))},x=new df({callback:b,params:{canvasContext:t,viewport:e,transform:n,background:r},objs:this.objs,commonObjs:this.commonObjs,annotationCanvasMap:h,operatorList:m.operatorList,pageIndex:this._pageIndex,canvasFactory:this._transport.canvasFactory,filterFactory:this._transport.filterFactory,useRequestAnimationFrame:!_,pdfBug:this._pdfBug,pageColors:l});(m.renderTasks||(m.renderTasks=new Set)).add(x);const S=x.task;return Promise.all([m.displayReadyCapability.promise,a]).then(([P,M])=>{var O;if(this.destroyed){b();return}if((O=this._stats)==null||O.time("Rendering"),!(M.renderingIntent&f))throw new Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");x.initializeGraphics({transparency:P,optionalContentConfig:M}),x.operatorListChanged()}).catch(b),S}getOperatorList({intent:t="display",annotationMode:e=Pn.ENABLE,printAnnotationStorage:s=null,isEditing:i=!1}={}){var l;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},(l=this._stats)==null||l.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=>Bh.textContent(s));const e=this.streamTextContent(t);return new Promise(function(s,i){function n(){r.read().then(function({value:h,done:l}){if(l){s(a);return}a.lang??(a.lang=h.lang),Object.assign(a.styles,h.styles),a.items.push(...h.items),n()},i)}const r=e.getReader(),a={items:[],styles:Object.create(null),lang:null};n()})}getStructTree(){return this._transport.getStructTree(this._pageIndex)}_destroy(){this.destroyed=!0;const t=[];for(const e of this._intentStates.values())if(this._abortOperatorList({intentState:e,reason:new Error("Page was destroyed."),force:!0}),!e.opListReadCapability)for(const s of e.renderTasks)t.push(s.completed),s.cancel();return this.objs.clear(),v(this,sn,!1),y(this,Ts,md).call(this),Promise.all(t)}cleanup(t=!1){v(this,sn,!0);const e=y(this,Ts,hh).call(this,!1);return t&&e&&this._stats&&(this._stats=new V0),e}_startRenderPage(t,e){var i,n;const s=this._intentStates.get(e);s&&((i=this._stats)==null||i.timeEnd("Page Request"),(n=s.displayReadyCapability)==null||n.resolve(t))}_renderPageChunk(t,e){for(let s=0,i=t.length;s<i;s++)e.operatorList.fnArray.push(t.fnArray[s]),e.operatorList.argsArray.push(t.argsArray[s]);e.operatorList.lastChunk=t.lastChunk,e.operatorList.separateAnnots=t.separateAnnots;for(const s of e.renderTasks)s.operatorListChanged();t.lastChunk&&y(this,Ts,hh).call(this,!0)}_pumpOperatorList({renderingIntent:t,cacheKey:e,annotationStorageSerializable:s,modifiedIds:i}){const{map:n,transfer:r}=s,h=this._transport.messageHandler.sendWithStream("GetOperatorList",{pageIndex:this._pageIndex,intent:t,cacheKey:e,annotationStorage:n,modifiedIds:i},r).getReader(),l=this._intentStates.get(e);l.streamReader=h;const u=()=>{h.read().then(({value:d,done:g})=>{if(g){l.streamReader=null;return}this._transport.destroyed||(this._renderPageChunk(d,l),u())},d=>{if(l.streamReader=null,!this._transport.destroyed){if(l.operatorList){l.operatorList.lastChunk=!0;for(const g of l.renderTasks)g.operatorListChanged();y(this,Ts,hh).call(this,!0)}if(l.displayReadyCapability)l.displayReadyCapability.reject(d);else if(l.opListReadCapability)l.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 Vg){let i=LS;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 Er(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}}Qn=new WeakMap,sn=new WeakMap,Ts=new WeakSet,hh=function(t=!1){if(y(this,Ts,md).call(this),!c(this,sn)||this.destroyed)return!1;if(t)return v(this,Qn,setTimeout(()=>{v(this,Qn,null),y(this,Ts,hh).call(this,!1)},IS)),!1;for(const{renderTasks:e,operatorList:s}of this._intentStates.values())if(e.size>0||!s.lastChunk)return!1;return this._intentStates.clear(),this.objs.clear(),v(this,sn,!1),!0},md=function(){c(this,Qn)&&(clearTimeout(c(this,Qn)),v(this,Qn,null))};class YS{constructor(){w(this,nn,new Map);w(this,Qu,Promise.resolve())}postMessage(t,e){const s={data:structuredClone(t,e?{transfer:e}:null)};c(this,Qu).then(()=>{for(const[i]of c(this,nn))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){at("LoopbackPort - cannot use an `aborted` signal.");return}const r=()=>this.removeEventListener(t,e);i=()=>n.removeEventListener("abort",r),n.addEventListener("abort",r)}c(this,nn).set(e,i)}removeEventListener(t,e){const s=c(this,nn).get(e);s==null||s(),c(this,nn).delete(e)}terminate(){for(const[,t]of c(this,nn))t==null||t();c(this,nn).clear()}}nn=new WeakMap,Qu=new WeakMap;const Rt=class Rt{constructor({name:t=null,port:e=null,verbosity:s=Cx()}={}){w(this,Eo);var i;if(this.name=t,this.destroyed=!1,this.verbosity=s,this._readyCapability=Promise.withResolvers(),this._port=null,this._webWorker=null,this._messageHandler=null,e){if((i=c(Rt,ra))!=null&&i.has(e))throw new Error("Cannot use more than one PDFWorker per port.");(c(Rt,ra)||v(Rt,ra,new WeakMap)).set(e,this),this._initializeFromPort(e);return}this._initialize()}get promise(){return Ae?Promise.all([Fn.promise,this._readyCapability.promise]):this._readyCapability.promise}get port(){return this._port}get messageHandler(){return this._messageHandler}_initializeFromPort(t){this._port=t,this._messageHandler=new jh("main","worker",t),this._messageHandler.on("ready",function(){}),y(this,Eo,vd).call(this)}_initialize(){if(c(Rt,na)||c(Rt,ko,bd)){this._setupFakeWorker();return}let{workerSrc:t}=Rt;try{Rt._isSameOrigin(window.location.href,t)||(t=Rt._createCDNWrapper(new URL(t,window.location).href));const e=new Worker(t,{type:"module"}),s=new jh("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,y(this,Eo,vd).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{Cu("The worker has been disabled.")}this._setupFakeWorker()}_setupFakeWorker(){c(Rt,na)||(at("Setting up fake worker."),v(Rt,na,!0)),Rt._setupFakeWorkerGlobal.then(t=>{if(this.destroyed){this._readyCapability.reject(new Error("Worker was destroyed"));return}const e=new YS;this._port=e;const s=`fake${Ge(Rt,Zu)._++}`,i=new jh(s+"_worker",s,e);t.setup(i,e),this._messageHandler=new jh(s,s+"_worker",e),y(this,Eo,vd).call(this)}).catch(t=>{this._readyCapability.reject(new Error(`Setting up fake worker failed: "${t.message}".`))})}destroy(){var t;this.destroyed=!0,this._webWorker&&(this._webWorker.terminate(),this._webWorker=null),(t=c(Rt,ra))==null||t.delete(this._port),this._port=null,this._messageHandler&&(this._messageHandler.destroy(),this._messageHandler=null)}static fromPort(t){var s;if(!(t!=null&&t.port))throw new Error("PDFWorker.fromPort - invalid method signature.");const e=(s=c(this,ra))==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 Rt(t)}static get workerSrc(){if(Vi.workerSrc)return Vi.workerSrc;throw new Error('No "GlobalWorkerOptions.workerSrc" specified.')}static get _setupFakeWorkerGlobal(){return ut(this,"_setupFakeWorkerGlobal",(async()=>c(this,ko,bd)?c(this,ko,bd):(await import(this.workerSrc)).WorkerMessageHandler)())}};Zu=new WeakMap,na=new WeakMap,ra=new WeakMap,Eo=new WeakSet,vd=function(){this._readyCapability.resolve(),this._messageHandler.send("configure",{verbosity:this.verbosity})},ko=new WeakSet,bd=function(){var t;try{return((t=globalThis.pdfjsWorker)==null?void 0:t.WorkerMessageHandler)||null}catch{return null}},w(Rt,ko),w(Rt,Zu,0),w(Rt,na,!1),w(Rt,ra),Ae&&(v(Rt,na,!0),Vi.workerSrc||(Vi.workerSrc="./pdf.worker.mjs")),Rt._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},Rt._createCDNWrapper=t=>{const e=`await import("${t}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))};let eo=Rt;class US{constructor(t,e,s,i,n){w(this,aa);w(this,rn,new Map);w(this,Si,new Map);w(this,Mo,new Map);w(this,Oo,new Map);w(this,Ci,null);this.messageHandler=t,this.loadingTask=e,this.commonObjs=new wv,this.fontLoader=new Vx({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 ut(this,"annotationStorage",new Zg)}getRenderingIntent(t,e=Pn.ENABLE,s=null,i=!1,n=!1){let r=rs.DISPLAY,a=Qg;switch(t){case"any":r=rs.ANY;break;case"display":break;case"print":r=rs.PRINT;break;default:at(`getRenderingIntent - invalid intent: ${t}`)}const h=r&rs.PRINT&&s instanceof q0?s:this.annotationStorage;switch(e){case Pn.DISABLE:r+=rs.ANNOTATIONS_DISABLE;break;case Pn.ENABLE:break;case Pn.ENABLE_FORMS:r+=rs.ANNOTATIONS_FORMS;break;case Pn.ENABLE_STORAGE:r+=rs.ANNOTATIONS_STORAGE,a=h.serializable;break;default:at(`getRenderingIntent - invalid annotationMode: ${e}`)}i&&(r+=rs.IS_EDITING),n&&(r+=rs.OPLIST);const{ids:l,hash:u}=h.modifiedIds,d=[r,a.hash,u];return{renderingIntent:r,cacheKey:d.join("_"),annotationStorageSerializable:a,modifiedIds:l}}destroy(){var s;if(this.destroyCapability)return this.destroyCapability.promise;this.destroyed=!0,this.destroyCapability=Promise.withResolvers(),(s=c(this,Ci))==null||s.reject(new Error("Worker was destroyed during onPassword callback"));const t=[];for(const i of c(this,Si).values())t.push(i._destroy());c(this,Si).clear(),c(this,Mo).clear(),c(this,Oo).clear(),this.hasOwnProperty("annotationStorage")&&this.annotationStorage.resetModified();const e=this.messageHandler.sendWithPromise("Terminate",null);return t.push(e),Promise.all(t).then(()=>{var i;this.commonObjs.clear(),this.fontLoader.clear(),c(this,rn).clear(),this.filterFactory.destroy(),Nh.cleanup(),(i=this._networkStream)==null||i.cancelAllRequests(new Er("Worker was terminated.")),this.messageHandler&&(this.messageHandler.destroy(),this.messageHandler=null),this.destroyCapability.resolve()},this.destroyCapability.reject),this.destroyCapability.promise}setupMessageHandler(){const{messageHandler:t,loadingTask:e}=this;t.on("GetReader",(s,i)=>{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 l;(l=e.onProgress)==null||l.call(e,{loaded:h.loaded,total:h.total})}),{isStreamingSupported:i,isRangeSupported:n,contentLength:r}}),t.on("GetRangeReader",(s,i)=>{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 VS(s,this))}),t.on("DocException",function(s){let i;switch(s.name){case"PasswordException":i=new Ng(s.message,s.code);break;case"InvalidPDFException":i=new W0(s.message);break;case"MissingPDFException":i=new Tr(s.message);break;case"UnexpectedResponseException":i=new Au(s.message,s.status);break;case"UnknownErrorException":i=new Bg(s.message,s.details);break;default:Mt("DocException - expected a valid Error.")}e._capability.reject(i)}),t.on("PasswordRequest",s=>{if(v(this,Ci,Promise.withResolvers()),e.onPassword){const i=n=>{n instanceof Error?c(this,Ci).reject(n):c(this,Ci).resolve({password:n})};try{e.onPassword(i,s.code)}catch(n){c(this,Ci).reject(n)}}else c(this,Ci).reject(new Ng(s.message,s.code));return c(this,Ci).promise}),t.on("DataLoaded",s=>{var i;(i=e.onProgress)==null||i.call(e,{loaded:s.length,total:s.length}),this.downloadInfoCapability.resolve(s)}),t.on("StartRenderPage",s=>{if(this.destroyed)return;c(this,Si).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:l}=this._params;if("error"in n){const f=n.error;at(`Error during font loading: ${f}`),this.commonObjs.resolve(s,f);break}const u=l&&((r=globalThis.FontInspector)!=null&&r.enabled)?(f,p)=>globalThis.FontInspector.fontAdded(f,p):null,d=new Gx(n,{disableFontFace:a,inspectFont:u});this.fontLoader.bind(d).catch(()=>t.sendWithPromise("FontFallback",{id:s})).finally(()=>{!h&&d.data&&(d.data=null),this.commonObjs.resolve(s,d)});break;case"CopyLocalImage":const{imageRef:g}=n;ne(g,"The imageRef must be defined.");for(const f of c(this,Si).values())for(const[,p]of f.objs)if((p==null?void 0:p.ref)===g)return p.dataLen?(this.commonObjs.resolve(s,structuredClone(p)),p.dataLen):null;break;case"FontPath":case"Image":case"Pattern":this.commonObjs.resolve(s,n);break;default:throw new Error(`Got unknown common object type ${i}`)}return null}),t.on("obj",([s,i,n,r])=>{var h;if(this.destroyed)return;const a=c(this,Si).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)>yx&&(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&&at("saveDocument called while `annotationStorage` is empty, please use the getData-method instead.");const{map:t,transfer:e}=this.annotationStorage.serializable;return this.messageHandler.sendWithPromise("SaveDocument",{isPureXfa:!!this._htmlForXfa,numPages:this._numPages,annotationStorage:t,filename:((s=this._fullReader)==null?void 0:s.filename)??null},e).finally(()=>{this.annotationStorage.resetModified()})}getPage(t){if(!Number.isInteger(t)||t<=0||t>this._numPages)return Promise.reject(new Error("Invalid page request."));const e=t-1,s=c(this,Mo).get(e);if(s)return s;const i=this.messageHandler.sendWithPromise("GetPage",{pageIndex:e}).then(n=>{if(this.destroyed)throw new Error("Transport destroyed");n.refStr&&c(this,Oo).set(n.refStr,t);const r=new GS(e,n,this,this._params.pdfBug);return c(this,Si).set(e,r),r});return c(this,Mo).set(e,i),i}getPageIndex(t){return yv(t)?this.messageHandler.sendWithPromise("GetPageIndex",{num:t.num,gen:t.gen}):Promise.reject(new Error("Invalid pageIndex request."))}getAnnotations(t,e){return this.messageHandler.sendWithPromise("GetAnnotations",{pageIndex:t,intent:e})}getFieldObjects(){return y(this,aa,dc).call(this,"GetFieldObjects")}hasJSActions(){return y(this,aa,dc).call(this,"HasJSActions")}getCalculationOrderIds(){return this.messageHandler.sendWithPromise("GetCalculationOrderIds",null)}getDestinations(){return this.messageHandler.sendWithPromise("GetDestinations",null)}getDestination(t){return typeof t!="string"?Promise.reject(new Error("Invalid destination request.")):this.messageHandler.sendWithPromise("GetDestination",{id:t})}getPageLabels(){return this.messageHandler.sendWithPromise("GetPageLabels",null)}getPageLayout(){return this.messageHandler.sendWithPromise("GetPageLayout",null)}getPageMode(){return this.messageHandler.sendWithPromise("GetPageMode",null)}getViewerPreferences(){return this.messageHandler.sendWithPromise("GetViewerPreferences",null)}getOpenAction(){return this.messageHandler.sendWithPromise("GetOpenAction",null)}getAttachments(){return this.messageHandler.sendWithPromise("GetAttachments",null)}getDocJSActions(){return y(this,aa,dc).call(this,"GetDocJSActions")}getPageJSActions(t){return this.messageHandler.sendWithPromise("GetPageJSActions",{pageIndex:t})}getStructTree(t){return this.messageHandler.sendWithPromise("GetStructTree",{pageIndex:t})}getOutline(){return this.messageHandler.sendWithPromise("GetOutline",null)}getOptionalContentConfig(t){return y(this,aa,dc).call(this,"GetOptionalContentConfig").then(e=>new gS(e,t))}getPermissions(){return this.messageHandler.sendWithPromise("GetPermissions",null)}getMetadata(){const t="GetMetadata",e=c(this,rn).get(t);if(e)return e;const s=this.messageHandler.sendWithPromise(t,null).then(i=>{var n,r;return{info:i[0],metadata:i[1]?new uS(i[1]):null,contentDispositionFilename:((n=this._fullReader)==null?void 0:n.filename)??null,contentLength:((r=this._fullReader)==null?void 0:r.contentLength)??null}});return c(this,rn).set(t,s),s}getMarkInfo(){return this.messageHandler.sendWithPromise("GetMarkInfo",null)}async startCleanup(t=!1){if(!this.destroyed){await this.messageHandler.sendWithPromise("Cleanup",null);for(const e of c(this,Si).values())if(!e.cleanup())throw new Error(`startCleanup: Page ${e.pageNumber} is currently rendering.`);this.commonObjs.clear(),t||this.fontLoader.clear(),c(this,rn).clear(),this.filterFactory.destroy(!0),Nh.cleanup()}}cachedPageNumber(t){if(!yv(t))return null;const e=t.gen===0?`${t.num}R`:`${t.num}R${t.gen}`;return c(this,Oo).get(e)??null}}rn=new WeakMap,Si=new WeakMap,Mo=new WeakMap,Oo=new WeakMap,Ci=new WeakMap,aa=new WeakSet,dc=function(t,e=null){const s=c(this,rn).get(t);if(s)return s;const i=this.messageHandler.sendWithPromise(t,e);return c(this,rn).set(t,i),i};const Lu=Symbol("INITIAL_DATA");class wv{constructor(){w(this,Cl);w(this,Ks,Object.create(null))}get(t,e=null){if(e){const i=y(this,Cl,ep).call(this,t);return i.promise.then(()=>e(i.data)),null}const s=c(this,Ks)[t];if(!s||s.data===Lu)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return s.data}has(t){const e=c(this,Ks)[t];return!!e&&e.data!==Lu}resolve(t,e=null){const s=y(this,Cl,ep).call(this,t);s.data=e,s.resolve()}clear(){var t;for(const e in c(this,Ks)){const{data:s}=c(this,Ks)[e];(t=s==null?void 0:s.bitmap)==null||t.close()}v(this,Ks,Object.create(null))}*[Symbol.iterator](){for(const t in c(this,Ks)){const{data:e}=c(this,Ks)[t];e!==Lu&&(yield[t,e])}}}Ks=new WeakMap,Cl=new WeakSet,ep=function(t){var e;return(e=c(this,Ks))[t]||(e[t]={...Promise.withResolvers(),data:Lu})};class qS{constructor(t){w(this,Zn,null);v(this,Zn,t),this.onContinue=null}get promise(){return c(this,Zn).capability.promise}cancel(t=0){c(this,Zn).cancel(null,t)}get separateAnnots(){const{separateAnnots:t}=c(this,Zn).operatorList;if(!t)return!1;const{annotationCanvasMap:e}=c(this,Zn);return t.form||t.canvas&&(e==null?void 0:e.size)>0}}Zn=new WeakMap;const ha=class ha{constructor({callback:t,params:e,objs:s,commonObjs:i,annotationCanvasMap:n,operatorList:r,pageIndex:a,canvasFactory:h,filterFactory:l,useRequestAnimationFrame:u=!1,pdfBug:d=!1,pageColors:g=null}){w(this,tr,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=l,this._pdfBug=d,this.pageColors=g,this.running=!1,this.graphicsReadyCallback=null,this.graphicsReady=!1,this._useRequestAnimationFrame=u===!0&&typeof window<"u",this.cancelled=!1,this.capability=Promise.withResolvers(),this.task=new qS(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(c(ha,oa).has(this._canvas))throw new Error("Cannot use the same canvas during multiple render() operations. Use different canvas or ensure previous operations were cancelled or completed.");c(ha,oa).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 Za(s,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:e},this.annotationCanvasMap,this.pageColors),this.gfx.beginDrawing({transform:n,viewport:i,transparency:t,background:r}),this.operatorListIdx=0,this.graphicsReady=!0,(h=this.graphicsReadyCallback)==null||h.call(this)}cancel(t=null,e=0){var s;this.running=!1,this.cancelled=!0,(s=this.gfx)==null||s.endDrawing(),c(this,tr)&&(window.cancelAnimationFrame(c(this,tr)),v(this,tr,null)),c(ha,oa).delete(this._canvas),this.callback(t||new Vg(`Rendering cancelled, page ${this._pageIndex+1}`,e))}operatorListChanged(){var t;if(!this.graphicsReady){this.graphicsReadyCallback||(this.graphicsReadyCallback=this._continueBound);return}(t=this.stepper)==null||t.updateOperatorList(this.operatorList),!this.running&&this._continue()}_continue(){this.running=!0,!this.cancelled&&(this.task.onContinue?this.task.onContinue(this._scheduleNextBound):this._scheduleNext())}_scheduleNext(){this._useRequestAnimationFrame?v(this,tr,window.requestAnimationFrame(()=>{v(this,tr,null),this._nextBound().catch(this._cancelBound)})):Promise.resolve().then(this._nextBound).catch(this._cancelBound)}async _next(){this.cancelled||(this.operatorListIdx=this.gfx.executeOperatorList(this.operatorList,this.operatorListIdx,this._continueBound,this.stepper),this.operatorListIdx===this.operatorList.argsArray.length&&(this.running=!1,this.operatorList.lastChunk&&(this.gfx.endDrawing(),c(ha,oa).delete(this._canvas),this.callback())))}};tr=new WeakMap,oa=new WeakMap,w(ha,oa,new WeakSet);let df=ha;const $S="4.8.69",KS="3634dab10";function xv(o){return Math.floor(Math.max(0,Math.min(1,o))*255).toString(16).padStart(2,"0")}function Hh(o){return Math.max(0,Math.min(255,255*o))}class Sv{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=Hh(t),[t,t,t]}static G_HTML([t]){const e=xv(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(Hh)}static RGB_HTML(t){return`#${t.map(xv).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[Hh(1-Math.min(1,t+i)),Hh(1-Math.min(1,s+i)),Hh(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 JS{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){Mt("Abstract method `_createSVG` called.")}}class gf extends JS{_createSVG(t){return document.createElementNS(Xi,t)}}class Cv{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,l=h.selectedIndex===-1?"":h[h.selectedIndex].value;i.setValue(e,{value:l})});break}}static setAttributes({html:t,element:e,storage:s=null,intent:i,linkService:n}){const{attributes:r}=e,a=t instanceof HTMLAnchorElement;r.type==="radio"&&(r.name=`${r.name}-${i}`);for(const[h,l]of Object.entries(r))if(l!=null)switch(h){case"class":l.length&&t.setAttribute(h,l.join(" "));break;case"dataId":break;case"id":t.setAttribute("data-element-id",l);break;case"style":Object.assign(t.style,l);break;case"textContent":t.textContent=l;break;default:(!a||h!=="href"&&h!=="newWindow")&&t.setAttribute(h,l)}a&&n.addLinkAttributes(t,r.href,r.newWindow),s&&r.dataId&&this.setupStorage(t,r.dataId,e,s)}static render(t){var d,g;const e=t.annotationStorage,s=t.linkService,i=t.xfaHtml,n=t.intent||"display",r=document.createElement(i.name);i.attributes&&this.setAttributes({html:r,element:i,intent:n,linkService:s});const a=n!=="richText",h=t.div;if(h.append(r),t.viewport){const f=`matrix(${t.viewport.transform.join(",")})`;h.style.transform=f}a&&h.setAttribute("class","xfaLayer xfaFont");const l=[];if(i.children.length===0){if(i.value){const f=document.createTextNode(i.value);r.append(f),a&&Bh.shouldBuildText(i.name)&&l.push(f)}return{textDivs:l}}const u=[[i,-1,r]];for(;u.length>0;){const[f,p,m]=u.at(-1);if(p+1===f.children.length){u.pop();continue}const _=f.children[++u.at(-1)[1]];if(_===null)continue;const{name:b}=_;if(b==="#text"){const S=document.createTextNode(_.value);l.push(S),m.append(S);continue}const x=(d=_==null?void 0:_.attributes)!=null&&d.xmlns?document.createElementNS(_.attributes.xmlns,b):document.createElement(b);if(m.append(x),_.attributes&&this.setAttributes({html:x,element:_,storage:e,intent:n,linkService:s}),((g=_.children)==null?void 0:g.length)>0)u.push([_,-1,x]);else if(_.value){const S=document.createTextNode(_.value);a&&Bh.shouldBuildText(b)&&l.push(S),x.append(S)}}for(const f of h.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea"))f.setAttribute("readOnly",!0);return{textDivs:l}}static update(t){const e=`matrix(${t.viewport.transform.join(",")})`;t.div.style.transform=e,t.div.hidden=!1}}const Wh=1e3,QS=9,Or=new WeakSet;function Gi(o){return{width:o[2]-o[0],height:o[3]-o[1]}}class ZS{static create(t){switch(t.data.annotationType){case ie.LINK:return new Av(t);case ie.TEXT:return new tC(t);case ie.WIDGET:switch(t.data.fieldType){case"Tx":return new eC(t);case"Btn":return t.data.radioButton?new Tv(t):t.data.checkBox?new iC(t):new nC(t);case"Ch":return new rC(t);case"Sig":return new sC(t)}return new Pr(t);case ie.POPUP:return new ff(t);case ie.FREETEXT:return new Ev(t);case ie.LINE:return new oC(t);case ie.SQUARE:return new hC(t);case ie.CIRCLE:return new lC(t);case ie.POLYLINE:return new kv(t);case ie.CARET:return new uC(t);case ie.INK:return new pf(t);case ie.POLYGON:return new cC(t);case ie.HIGHLIGHT:return new Mv(t);case ie.UNDERLINE:return new dC(t);case ie.SQUIGGLY:return new gC(t);case ie.STRIKEOUT:return new fC(t);case ie.STAMP:return new Ov(t);case ie.FILEATTACHMENT:return new pC(t);default:return new Yt(t)}}}const Cf=class Cf{constructor(t,{isRenderable:e=!1,ignoreBorder:s=!1,createQuadrilaterals:i=!1}={}){w(this,Al);w(this,la,null);w(this,Po,!1);w(this,Do,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 Cf._hasPopupData(this.data)}updateEdited(t){var s;if(!this.container)return;c(this,la)||v(this,la,{rect:this.data.rect.slice(0)});const{rect:e}=t;e&&y(this,Al,sp).call(this,e),(s=c(this,Do))==null||s.popup.updateEdited(t)}resetEdited(){var t;c(this,la)&&(y(this,Al,sp).call(this,c(this,la).rect),(t=c(this,Do))==null||t.popup.resetEdited(),v(this,la,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 Pr||(n.tabIndex=Wh);const{style:r}=n;if(r.zIndex=this.parent.zIndex++,e.alternativeText&&(n.title=e.alternativeText),e.noRotate&&n.classList.add("norotate"),!e.rect||this instanceof ff){const{rotation:m}=e;return!e.hasOwnCanvas&&m!==0&&this.setRotation(m,n),n}const{width:a,height:h}=Gi(e.rect);if(!t&&e.borderStyle.width>0){r.borderWidth=`${e.borderStyle.width}px`;const m=e.borderStyle.horizontalCornerRadius,_=e.borderStyle.verticalCornerRadius;if(m>0||_>0){const x=`calc(${m}px * var(--scale-factor)) / calc(${_}px * var(--scale-factor))`;r.borderRadius=x}else if(this instanceof Tv){const x=`calc(${a}px * var(--scale-factor)) / calc(${h}px * var(--scale-factor))`;r.borderRadius=x}switch(e.borderStyle.style){case Ph.SOLID:r.borderStyle="solid";break;case Ph.DASHED:r.borderStyle="dashed";break;case Ph.BEVELED:at("Unimplemented border style: beveled");break;case Ph.INSET:at("Unimplemented border style: inset");break;case Ph.UNDERLINE:r.borderBottomStyle="solid";break}const b=e.borderColor||null;b?(v(this,Po,!0),r.borderColor=U.makeHexColor(b[0]|0,b[1]|0,b[2]|0)):r.borderWidth=0}const l=U.normalizeRect([e.rect[0],s.view[3]-e.rect[1]+s.view[1],e.rect[2],s.view[3]-e.rect[3]+s.view[1]]),{pageWidth:u,pageHeight:d,pageX:g,pageY:f}=i.rawDims;r.left=`${100*(l[0]-g)/u}%`,r.top=`${100*(l[1]-f)/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}=Gi(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]=Sv[`${r}_HTML`](a),this.annotationStorage.setValue(this.data.id,{[s]:Sv[`${r}_rgb`](a)})};return ut(this,"_commonActions",{display:e=>{const{display:s}=e.detail,i=s%2===1;this.container.style.visibility=i?"hidden":"visible",this.annotationStorage.setValue(this.data.id,{noView:i,noPrint:s===1||s===2})},print:e=>{this.annotationStorage.setValue(this.data.id,{noPrint:!e.detail.print})},hidden:e=>{const{hidden:s}=e.detail;this.container.style.visibility=s?"hidden":"visible",this.annotationStorage.setValue(this.data.id,{noPrint:s,noView:s})},focus:e=>{setTimeout(()=>e.target.focus({preventScroll:!1}),0)},userName:e=>{e.target.title=e.detail.userName},readonly:e=>{e.target.disabled=e.detail.readonly},required:e=>{this._setRequired(e.target,e.detail.required)},bgColor:e=>{t("bgColor","backgroundColor",e)},fillColor:e=>{t("fillColor","backgroundColor",e)},fgColor:e=>{t("fgColor","color",e)},textColor:e=>{t("textColor","color",e)},borderColor:e=>{t("borderColor","borderColor",e)},strokeColor:e=>{t("strokeColor","borderColor",e)},rotation:e=>{const s=e.detail.rotation;this.setRotation(s),this.annotationStorage.setValue(this.data.id,{rotation:s})}})}_dispatchEventFromSandbox(t,e){const s=this._commonActions;for(const i of Object.keys(e.detail)){const n=t[i]||s[i];n==null||n(e)}}_setDefaultPropertiesFromJS(t){if(!this.enableScripting)return;const e=this.annotationStorage.getRawValue(this.data.id);if(!e)return;const s=this._commonActions;for(const[i,n]of Object.entries(e)){const r=s[i];if(r){const a={detail:{[i]:n},target:t};r(a),delete e[i]}}}_createQuadrilaterals(){if(!this.container)return;const{quadPoints:t}=this.data;if(!t)return;const[e,s,i,n]=this.data.rect.map(m=>Math.fround(m));if(t.length===8){const[m,_,b,x]=t.subarray(2,6);if(i===m&&n===_&&e===b&&s===x)return}const{style:r}=this.container;let a;if(c(this,Po)){const{borderColor:m,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="${m}" stroke-width="${_}">`],this.container.classList.add("hasBorder")}const h=i-e,l=n-s,{svgFactory:u}=this,d=u.createElement("svg");d.classList.add("quadrilateralsContainer"),d.setAttribute("width",0),d.setAttribute("height",0);const g=u.createElement("defs");d.append(g);const f=u.createElement("clipPath"),p=`clippath_${this.data.id}`;f.setAttribute("id",p),f.setAttribute("clipPathUnits","objectBoundingBox"),g.append(f);for(let m=2,_=t.length;m<_;m+=8){const b=t[m],x=t[m+1],S=t[m+2],A=t[m+3],k=u.createElement("rect"),P=(S-e)/h,M=(n-x)/l,O=(b-S)/h,R=(x-A)/l;k.setAttribute("x",P),k.setAttribute("y",M),k.setAttribute("width",O),k.setAttribute("height",R),f.append(k),a==null||a.push(`<rect vector-effect="non-scaling-stroke" x="${P}" y="${M}" width="${O}" height="${R}"/>`)}c(this,Po)&&(a.push("</g></svg>')"),r.backgroundImage=a.join("")),this.container.append(d),this.container.style.clipPath=`url(#${p})`}_createPopup(){const{data:t}=this,e=v(this,Do,new ff({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(){Mt("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,l=document.querySelector(`[data-element-id="${r}"]`);if(l&&!Or.has(l)){at(`_getElementsByName - element not allowed: ${r}`);continue}s.push({id:r,exportValue:h,domElement:l})}return s}for(const i of document.getElementsByName(t)){const{exportValue:n}=i,r=i.getAttribute("data-element-id");r!==e&&Or.has(i)&&s.push({id:r,exportValue:n,domElement:i})}return s}show(){var t;this.container&&(this.container.hidden=!1),(t=this.popup)==null||t.maybeShow()}hide(){var t;this.container&&(this.container.hidden=!0),(t=this.popup)==null||t.forceHide()}getElementsToTriggerPopup(){return this.container}addHighlightArea(){const t=this.getElementsToTriggerPopup();if(Array.isArray(t))for(const e of t)e.classList.add("highlightArea");else t.classList.add("highlightArea")}_editOnDoubleClick(){if(!this._isEditable)return;const{annotationEditorType:t,data:{id:e}}=this;this.container.addEventListener("dblclick",()=>{var s;(s=this.linkService.eventBus)==null||s.dispatch("switchannotationeditormode",{source:this,mode:t,editId:e})})}};la=new WeakMap,Po=new WeakMap,Do=new WeakMap,Al=new WeakSet,sp=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:l,height:u}=Gi(t);e.left=`${100*(t[0]-a)/n}%`,e.top=`${100*(r-t[3]+h)/r}%`,i===0?(e.width=`${100*l/n}%`,e.height=`${100*u/r}%`):this.setRotation(i)};let Yt=Cf;class Av extends Yt{constructor(e,s=null){super(e,{isRenderable:!0,ignoreBorder:!!(s!=null&&s.ignoreBorder),createQuadrilaterals:!0});w(this,cs);this.isTooltipOnly=e.data.isTooltipOnly}render(){const{data:e,linkService:s}=this,i=document.createElement("a");i.setAttribute("data-element-id",e.id);let n=!1;return e.url?(s.addLinkAttributes(i,e.url,e.newWindow),n=!0):e.action?(this._bindNamedAction(i,e.action),n=!0):e.attachment?(y(this,cs,Ob).call(this,i,e.attachment,e.attachmentDest),n=!0):e.setOCGState?(y(this,cs,Pb).call(this,i,e.setOCGState),n=!0):e.dest?(this._bindLink(i,e.dest),n=!0):(e.actions&&(e.actions.Action||e.actions["Mouse Up"]||e.actions["Mouse Down"])&&this.enableScripting&&this.hasJSActions&&(this._bindJSAction(i,e),n=!0),e.resetForm?(this._bindResetFormAction(i,e.resetForm),n=!0):this.isTooltipOnly&&!n&&(this._bindLink(i,""),n=!0)),this.container.classList.add("linkAnnotation"),n&&this.container.append(i),this.container}_bindLink(e,s){e.href=this.linkService.getDestinationHash(s),e.onclick=()=>(s&&this.linkService.goToDestination(s),!1),(s||s==="")&&y(this,cs,Ra).call(this)}_bindNamedAction(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeNamedAction(s),!1),y(this,cs,Ra).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),y(this,cs,Ra).call(this)}_bindResetFormAction(e,s){const i=e.onclick;if(i||(e.href=this.linkService.getAnchorUrl("")),y(this,cs,Ra).call(this),!this._fieldObjects){at('_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 g=new Set(r);for(const f of n){const p=this._fieldObjects[f]||[];for(const{id:m}of p)g.add(m)}for(const f of Object.values(this._fieldObjects))for(const p of f)g.has(p.id)===a&&h.push(p)}else for(const g of Object.values(this._fieldObjects))h.push(...g);const l=this.annotationStorage,u=[];for(const g of h){const{id:f}=g;switch(u.push(f),g.type){case"text":{const m=g.defaultValue||"";l.setValue(f,{value:m});break}case"checkbox":case"radiobutton":{const m=g.defaultValue===g.exportValues;l.setValue(f,{value:m});break}case"combobox":case"listbox":{const m=g.defaultValue||"";l.setValue(f,{value:m});break}default:continue}const p=document.querySelector(`[data-element-id="${f}"]`);if(p){if(!Or.has(p)){at(`_bindResetFormAction - element not allowed: ${f}`);continue}}else continue;p.dispatchEvent(new Event("resetform"))}return this.enableScripting&&((d=this.linkService.eventBus)==null||d.dispatch("dispatcheventinsandbox",{source:this,detail:{id:"app",ids:u,name:"ResetForm"}})),!1}}}cs=new WeakSet,Ra=function(){this.container.setAttribute("data-internal-link","")},Ob=function(e,s,i=null){e.href=this.linkService.getAnchorUrl(""),s.description&&(e.title=s.description),e.onclick=()=>{var n;return(n=this.downloadManager)==null||n.openOrDownloadData(s.content,s.filename,i),!1},y(this,cs,Ra).call(this)},Pb=function(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeSetOCGState(s),!1),y(this,cs,Ra).call(this)};class tC extends Yt{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 Pr extends Yt{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 Ne.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,l]of s)(l==="Action"||(n=this.data.actions)!=null&&n[l])&&((l==="Focus"||l==="Blur")&&(e||(e={focused:!1})),this._setEventListener(t,e,h,l,i),l==="Focus"&&!((r=this.data.actions)!=null&&r.Blur)?this._setEventListener(t,e,"blur","Blur",null):l==="Blur"&&!((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":U.makeHexColor(e[0],e[1],e[2])}_setTextStyle(t){const e=["left","center","right"],{fontColor:s}=this.data.defaultAppearanceData,i=this.data.defaultAppearanceData.fontSize||QS,n=t.style;let r;const a=2,h=l=>Math.round(10*l)/10;if(this.data.multiLine){const l=Math.abs(this.data.rect[3]-this.data.rect[1]-a),u=Math.round(l/(jg*i))||1,d=l/u;r=Math.min(i,h(d/jg))}else{const l=Math.abs(this.data.rect[3]-this.data.rect[1]-a);r=Math.min(i,h(l/jg))}n.fontSize=`calc(${r}px * var(--scale-factor))`,n.color=U.makeHexColor(s[0],s[1],s[2]),this.data.textAlignment!==null&&(n.textAlign=e[this.data.textAlignment])}_setRequired(t,e){e?t.setAttribute("required",!0):t.removeAttribute("required"),t.setAttribute("aria-required",e)}}class eC extends Pr{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 l=r.formattedValue||((i=this.data.textContent)==null?void 0:i.join(`
|
|
529
|
-
`))||null;l&&this.data.comb&&(l=l.replaceAll(/\s+/g,""));const u={userValue:a,formattedValue:l,lastCommittedValue:null,commitKey:1,focused:!1};this.data.multiLine?(s=document.createElement("textarea"),s.textContent=l??a,this.data.doNotScroll&&(s.style.overflowY="hidden")):(s=document.createElement("input"),s.type="text",s.setAttribute("value",l??a),this.data.doNotScroll&&(s.style.overflowX="hidden")),this.data.hasOwnCanvas&&(s.hidden=!0),Or.add(s),s.setAttribute("data-element-id",e),s.disabled=this.data.readOnly,s.name=this.data.fieldName,s.tabIndex=Wh,this._setRequired(s,this.data.required),h&&(s.maxLength=h),s.addEventListener("input",g=>{t.setValue(e,{value:g.target.value}),this.setPropertyOnSiblings(s,"value",g.target.value,"value"),u.formattedValue=null}),s.addEventListener("resetform",g=>{const f=this.data.defaultFieldValue??"";s.value=u.userValue=f,u.formattedValue=null});let d=g=>{const{formattedValue:f}=u;f!=null&&(g.target.value=f),g.target.scrollLeft=0};if(this.enableScripting&&this.hasJSActions){s.addEventListener("focus",f=>{var m;if(u.focused)return;const{target:p}=f;u.userValue&&(p.value=u.userValue),u.lastCommittedValue=p.value,u.commitKey=1,(m=this.data.actions)!=null&&m.Focus||(u.focused=!0)}),s.addEventListener("updatefromsandbox",f=>{this.showElementAndHideCanvas(f.target);const p={value(m){u.userValue=m.detail.value??"",t.setValue(e,{value:u.userValue.toString()}),m.target.value=u.userValue},formattedValue(m){const{formattedValue:_}=m.detail;u.formattedValue=_,_!=null&&m.target!==document.activeElement&&(m.target.value=_),t.setValue(e,{formattedValue:_})},selRange(m){m.target.setSelectionRange(...m.detail.selRange)},charLimit:m=>{var S;const{charLimit:_}=m.detail,{target:b}=m;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,f)}),s.addEventListener("keydown",f=>{var _;u.commitKey=1;let p=-1;if(f.key==="Escape"?p=0:f.key==="Enter"&&!this.data.multiLine?p=2:f.key==="Tab"&&(u.commitKey=3),p===-1)return;const{value:m}=f.target;u.lastCommittedValue!==m&&(u.lastCommittedValue=m,u.userValue=m,(_=this.linkService.eventBus)==null||_.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:m,willCommit:!0,commitKey:p,selStart:f.target.selectionStart,selEnd:f.target.selectionEnd}}))});const g=d;d=null,s.addEventListener("blur",f=>{var m,_;if(!u.focused||!f.relatedTarget)return;(m=this.data.actions)!=null&&m.Blur||(u.focused=!1);const{value:p}=f.target;u.userValue=p,u.lastCommittedValue!==p&&((_=this.linkService.eventBus)==null||_.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:p,willCommit:!0,commitKey:u.commitKey,selStart:f.target.selectionStart,selEnd:f.target.selectionEnd}})),g(f)}),(n=this.data.actions)!=null&&n.Keystroke&&s.addEventListener("beforeinput",f=>{var k;u.lastCommittedValue=null;const{data:p,target:m}=f,{value:_,selectionStart:b,selectionEnd:x}=m;let S=b,A=x;switch(f.inputType){case"deleteWordBackward":{const P=_.substring(0,b).match(/\w*[^\w]*$/);P&&(S-=P[0].length);break}case"deleteWordForward":{const P=_.substring(b).match(/^[^\w]*\w*/);P&&(A+=P[0].length);break}case"deleteContentBackward":b===x&&(S-=1);break;case"deleteContentForward":b===x&&(A+=1);break}f.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"]],f=>f.target.value)}if(d&&s.addEventListener("blur",d),this.data.comb){const f=(this.data.rect[2]-this.data.rect[0])/h;s.classList.add("comb"),s.style.letterSpacing=`calc(${f}px * var(--scale-factor) - 1ch)`}}else s=document.createElement("div"),s.textContent=this.data.fieldValue,s.style.verticalAlign="middle",s.style.display="table-cell",this.data.hasOwnCanvas&&(s.hidden=!0);return this._setTextStyle(s),this._setBackgroundColor(s),this._setDefaultPropertiesFromJS(s),this.container.append(s),this.container}}class sC extends Pr{constructor(t){super(t,{isRenderable:!!t.data.hasOwnCanvas})}}class iC extends Pr{constructor(t){super(t,{isRenderable:t.renderForms})}render(){const t=this.annotationStorage,e=this.data,s=e.id;let i=t.getValue(s,{value:e.exportValue===e.fieldValue}).value;typeof i=="string"&&(i=i!=="Off",t.setValue(s,{value:i})),this.container.classList.add("buttonWidgetAnnotation","checkBox");const n=document.createElement("input");return Or.add(n),n.setAttribute("data-element-id",s),n.disabled=e.readOnly,this._setRequired(n,this.data.required),n.type="checkbox",n.name=e.fieldName,i&&n.setAttribute("checked",!0),n.setAttribute("exportValue",e.exportValue),n.tabIndex=Wh,n.addEventListener("change",r=>{const{name:a,checked:h}=r.target;for(const l of this._getElementsByName(a,s)){const u=h&&l.exportValue===e.exportValue;l.domElement&&(l.domElement.checked=u),t.setValue(l.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 Tv extends Pr{constructor(t){super(t,{isRenderable:t.renderForms})}render(){this.container.classList.add("buttonWidgetAnnotation","radioButton");const t=this.annotationStorage,e=this.data,s=e.id;let i=t.getValue(s,{value:e.fieldValue===e.buttonValue}).value;if(typeof i=="string"&&(i=i!==e.buttonValue,t.setValue(s,{value:i})),i)for(const r of this._getElementsByName(e.fieldName,s))t.setValue(r.id,{value:!1});const n=document.createElement("input");if(Or.add(n),n.setAttribute("data-element-id",s),n.disabled=e.readOnly,this._setRequired(n,this.data.required),n.type="radio",n.name=e.fieldName,i&&n.setAttribute("checked",!0),n.tabIndex=Wh,n.addEventListener("change",r=>{const{name:a,checked:h}=r.target;for(const l of this._getElementsByName(a,s))t.setValue(l.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:l=>{const u=r===l.detail.value;for(const d of this._getElementsByName(l.target.name)){const g=u&&d.id===s;d.domElement&&(d.domElement.checked=g),t.setValue(d.id,{value:g})}}};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 nC extends Av{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 rC extends Pr{constructor(t){super(t,{isRenderable:t.renderForms})}render(){this.container.classList.add("choiceWidgetAnnotation");const t=this.annotationStorage,e=this.data.id,s=t.getValue(e,{value:this.data.fieldValue}),i=document.createElement("select");Or.add(i),i.setAttribute("data-element-id",e),i.disabled=this.data.readOnly,this._setRequired(i,this.data.required),i.name=this.data.fieldName,i.tabIndex=Wh;let n=this.data.combo&&this.data.options.length>0;this.data.combo||(i.size=this.data.options.length,this.data.multiSelect&&(i.multiple=!0)),i.addEventListener("resetform",u=>{const d=this.data.defaultFieldValue;for(const g of i.options)g.selected=g.value===d});for(const u of this.data.options){const d=document.createElement("option");d.textContent=u.displayValue,d.value=u.exportValue,s.value.includes(u.exportValue)&&(d.setAttribute("selected",!0),n=!1),i.append(d)}let r=null;if(n){const u=document.createElement("option");u.value=" ",u.setAttribute("hidden",!0),u.setAttribute("selected",!0),i.prepend(u),r=()=>{u.remove(),i.removeEventListener("input",r),r=null},i.addEventListener("input",r)}const a=u=>{const d=u?"value":"textContent",{options:g,multiple:f}=i;return f?Array.prototype.filter.call(g,p=>p.selected).map(p=>p[d]):g.selectedIndex===-1?null:g[g.selectedIndex][d]};let h=a(!1);const l=u=>{const d=u.target.options;return Array.prototype.map.call(d,g=>({displayValue:g.textContent,exportValue:g.value}))};return this.enableScripting&&this.hasJSActions?(i.addEventListener("updatefromsandbox",u=>{const d={value(g){r==null||r();const f=g.detail.value,p=new Set(Array.isArray(f)?f:[f]);for(const m of i.options)m.selected=p.has(m.value);t.setValue(e,{value:a(!0)}),h=a(!1)},multipleSelection(g){i.multiple=!0},remove(g){const f=i.options,p=g.detail.remove;f[p].selected=!1,i.remove(p),f.length>0&&Array.prototype.findIndex.call(f,_=>_.selected)===-1&&(f[0].selected=!0),t.setValue(e,{value:a(!0),items:l(g)}),h=a(!1)},clear(g){for(;i.length!==0;)i.remove(0);t.setValue(e,{value:null,items:[]}),h=a(!1)},insert(g){const{index:f,displayValue:p,exportValue:m}=g.detail.insert,_=i.children[f],b=document.createElement("option");b.textContent=p,b.value=m,_?_.before(b):i.append(b),t.setValue(e,{value:a(!0),items:l(g)}),h=a(!1)},items(g){const{items:f}=g.detail;for(;i.length!==0;)i.remove(0);for(const p of f){const{displayValue:m,exportValue:_}=p,b=document.createElement("option");b.textContent=m,b.value=_,i.append(b)}i.options.length>0&&(i.options[0].selected=!0),t.setValue(e,{value:a(!0),items:l(g)}),h=a(!1)},indices(g){const f=new Set(g.detail.indices);for(const p of g.target.options)p.selected=f.has(p.index);t.setValue(e,{value:a(!0)}),h=a(!1)},editable(g){g.target.disabled=!g.detail.editable}};this._dispatchEventFromSandbox(d,u)}),i.addEventListener("input",u=>{var f;const d=a(!0),g=a(!1);t.setValue(e,{value:d}),u.preventDefault(),(f=this.linkService.eventBus)==null||f.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:h,change:g,changeEx:d,willCommit:!1,commitKey:1,keyDown:!1}})}),this._setEventListeners(i,null,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"],["input","Action"],["input","Validate"]],u=>u.target.value)):i.addEventListener("input",function(u){t.setValue(e,{value:a(!0)})}),this.data.combo&&this._setTextStyle(i),this._setBackgroundColor(i),this._setDefaultPropertiesFromJS(i),this.container.append(i),this.container}}class ff extends Yt{constructor(t){const{data:e,elements:s}=t;super(t,{isRenderable:Yt._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=>`${zg}${s}`).join(",")),this.container}}class aC{constructor({container:t,color:e,elements:s,titleObj:i,modificationDate:n,contentsObj:r,richText:a,parent:h,rect:l,parentRect:u,open:d}){w(this,St);w(this,Ro,y(this,St,Fb).bind(this));w(this,td,y(this,St,np).bind(this));w(this,ed,y(this,St,wd).bind(this));w(this,Fo,y(this,St,_d).bind(this));w(this,ca,null);w(this,Xt,null);w(this,an,null);w(this,Lo,null);w(this,Tl,null);w(this,El,null);w(this,Io,null);w(this,on,!1);w(this,Js,null);w(this,hn,null);w(this,kl,null);w(this,ln,null);w(this,Ml,null);w(this,ua,null);w(this,da,!1);var g;v(this,Xt,t),v(this,Ml,i),v(this,an,r),v(this,ln,a),v(this,El,h),v(this,ca,e),v(this,kl,l),v(this,Io,u),v(this,Tl,s),v(this,Lo,Yg.toDateObject(n)),this.trigger=s.flatMap(f=>f.getElementsToTriggerPopup());for(const f of this.trigger)f.addEventListener("click",c(this,Fo)),f.addEventListener("mouseenter",c(this,ed)),f.addEventListener("mouseleave",c(this,td)),f.classList.add("popupTriggerArea");for(const f of s)(g=f.container)==null||g.addEventListener("keydown",c(this,Ro));c(this,Xt).hidden=!0,d&&y(this,St,_d).call(this)}render(){if(c(this,Js))return;const t=v(this,Js,document.createElement("div"));if(t.className="popup",c(this,ca)){const n=t.style.outlineColor=U.makeHexColor(...c(this,ca));CSS.supports("background-color","color-mix(in srgb, red 30%, white)")?t.style.backgroundColor=`color-mix(in srgb, ${n} 30%, white)`:t.style.backgroundColor=U.makeHexColor(...c(this,ca).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}=c(this,Ml),t.append(e),c(this,Lo)){const n=document.createElement("span");n.classList.add("popupDate"),n.setAttribute("data-l10n-id","pdfjs-annotation-date-time-string"),n.setAttribute("data-l10n-args",JSON.stringify({dateObj:c(this,Lo).valueOf()})),e.append(n)}const i=c(this,St,yd);if(i)Cv.render({xfaHtml:i,intent:"richText",div:t}),t.lastChild.classList.add("richText","popupContent");else{const n=this._formatContents(c(this,an));t.append(n)}c(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;c(this,ua)||v(this,ua,{contentsObj:c(this,an),richText:c(this,ln)}),t&&v(this,hn,null),e&&(v(this,ln,y(this,St,Rb).call(this,e)),v(this,an,null)),(s=c(this,Js))==null||s.remove(),v(this,Js,null)}resetEdited(){var t;c(this,ua)&&({contentsObj:Ge(this,an)._,richText:Ge(this,ln)._}=c(this,ua),v(this,ua,null),(t=c(this,Js))==null||t.remove(),v(this,Js,null),v(this,hn,null))}forceHide(){v(this,da,this.isVisible),c(this,da)&&(c(this,Xt).hidden=!0)}maybeShow(){c(this,da)&&(c(this,Js)||y(this,St,wd).call(this),v(this,da,!1),c(this,Xt).hidden=!1)}get isVisible(){return c(this,Xt).hidden===!1}}Ro=new WeakMap,td=new WeakMap,ed=new WeakMap,Fo=new WeakMap,ca=new WeakMap,Xt=new WeakMap,an=new WeakMap,Lo=new WeakMap,Tl=new WeakMap,El=new WeakMap,Io=new WeakMap,on=new WeakMap,Js=new WeakMap,hn=new WeakMap,kl=new WeakMap,ln=new WeakMap,Ml=new WeakMap,ua=new WeakMap,da=new WeakMap,St=new WeakSet,yd=function(){const t=c(this,ln),e=c(this,an);return t!=null&&t.str&&(!(e!=null&&e.str)||e.str===t.str)&&c(this,ln).html||null},ip=function(){var t,e,s;return((s=(e=(t=c(this,St,yd))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.fontSize)||0},Db=function(){var t,e,s;return((s=(e=(t=c(this,St,yd))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.color)||null},Rb=function(t){const e=[],s={str:t,html:{name:"div",attributes:{dir:"auto"},children:[{name:"p",children:e}]}},i={style:{color:c(this,St,Db),fontSize:c(this,St,ip)?`calc(${c(this,St,ip)}px * var(--scale-factor))`:""}};for(const n of t.split(`
|
|
530
|
-
`))e.push({name:"span",value:n,attributes:i});return s},Fb=function(t){t.altKey||t.shiftKey||t.ctrlKey||t.metaKey||(t.key==="Enter"||t.key==="Escape"&&c(this,on))&&y(this,St,_d).call(this)},Lb=function(){if(c(this,hn)!==null)return;const{page:{view:t},viewport:{rawDims:{pageWidth:e,pageHeight:s,pageX:i,pageY:n}}}=c(this,El);let r=!!c(this,Io),a=r?c(this,Io):c(this,kl);for(const p of c(this,Tl))if(!a||U.intersect(p.data.rect,a)!==null){a=p.data.rect,r=!0;break}const h=U.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,g=h[1];v(this,hn,[100*(d-i)/e,100*(g-n)/s]);const{style:f}=c(this,Xt);f.left=`${c(this,hn)[0]}%`,f.top=`${c(this,hn)[1]}%`},_d=function(){v(this,on,!c(this,on)),c(this,on)?(y(this,St,wd).call(this),c(this,Xt).addEventListener("click",c(this,Fo)),c(this,Xt).addEventListener("keydown",c(this,Ro))):(y(this,St,np).call(this),c(this,Xt).removeEventListener("click",c(this,Fo)),c(this,Xt).removeEventListener("keydown",c(this,Ro)))},wd=function(){c(this,Js)||this.render(),this.isVisible?c(this,on)&&c(this,Xt).classList.add("focused"):(y(this,St,Lb).call(this),c(this,Xt).hidden=!1,c(this,Xt).style.zIndex=parseInt(c(this,Xt).style.zIndex)+1e3)},np=function(){c(this,Xt).classList.remove("focused"),!(c(this,on)||!this.isVisible)&&(c(this,Xt).hidden=!0,c(this,Xt).style.zIndex=parseInt(c(this,Xt).style.zIndex)-1e3)};class Ev extends Yt{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 oC extends Yt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});w(this,Ol,null)}render(){this.container.classList.add("lineAnnotation");const e=this.data,{width:s,height:i}=Gi(e.rect),n=this.svgFactory.create(s,i,!0),r=v(this,Ol,this.svgFactory.createElement("svg:line"));return r.setAttribute("x1",e.rect[2]-e.lineCoordinates[0]),r.setAttribute("y1",e.rect[3]-e.lineCoordinates[1]),r.setAttribute("x2",e.rect[2]-e.lineCoordinates[2]),r.setAttribute("y2",e.rect[3]-e.lineCoordinates[3]),r.setAttribute("stroke-width",e.borderStyle.width||1),r.setAttribute("stroke","transparent"),r.setAttribute("fill","transparent"),n.append(r),this.container.append(n),!e.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return c(this,Ol)}addHighlightArea(){this.container.classList.add("highlightArea")}}Ol=new WeakMap;class hC extends Yt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});w(this,Pl,null)}render(){this.container.classList.add("squareAnnotation");const e=this.data,{width:s,height:i}=Gi(e.rect),n=this.svgFactory.create(s,i,!0),r=e.borderStyle.width,a=v(this,Pl,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 c(this,Pl)}addHighlightArea(){this.container.classList.add("highlightArea")}}Pl=new WeakMap;class lC extends Yt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});w(this,Dl,null)}render(){this.container.classList.add("circleAnnotation");const e=this.data,{width:s,height:i}=Gi(e.rect),n=this.svgFactory.create(s,i,!0),r=e.borderStyle.width,a=v(this,Dl,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 c(this,Dl)}addHighlightArea(){this.container.classList.add("highlightArea")}}Dl=new WeakMap;class kv extends Yt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});w(this,Rl,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}=Gi(e),h=this.svgFactory.create(r,a,!0);let l=[];for(let d=0,g=s.length;d<g;d+=2){const f=s[d]-e[0],p=e[3]-s[d+1];l.push(`${f},${p}`)}l=l.join(" ");const u=v(this,Rl,this.svgFactory.createElement(this.svgElementName));return u.setAttribute("points",l),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 c(this,Rl)}addHighlightArea(){this.container.classList.add("highlightArea")}}Rl=new WeakMap;class cC extends kv{constructor(t){super(t),this.containerClassName="polygonAnnotation",this.svgElementName="svg:polygon"}}class uC extends Yt{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 pf extends Yt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});w(this,Fl,[]);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,inkLists:s,borderStyle:i,popupRef:n}}=this,{width:r,height:a}=Gi(e),h=this.svgFactory.create(r,a,!0);for(const l of s){let u=[];for(let g=0,f=l.length;g<f;g+=2){const p=l[g]-e[0],m=e[3]-l[g+1];u.push(`${p},${m}`)}u=u.join(" ");const d=this.svgFactory.createElement(this.svgElementName);c(this,Fl).push(d),d.setAttribute("points",u),d.setAttribute("stroke-width",i.width||1),d.setAttribute("stroke","transparent"),d.setAttribute("fill","transparent"),h.append(d)}return!n&&this.hasPopupData&&this._createPopup(),this.container.append(h),this._editOnDoubleClick(),this.container}getElementsToTriggerPopup(){return c(this,Fl)}addHighlightArea(){this.container.classList.add("highlightArea")}}Fl=new WeakMap;class Mv extends Yt{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 dC extends Yt{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 gC extends Yt{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 fC extends Yt{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 Ov extends Yt{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 pC extends Yt{constructor(e){var i;super(e,{isRenderable:!0});w(this,Il);w(this,Ll,null);const{file:s}=this.data;this.filename=s.filename,this.content=s.content,(i=this.linkService.eventBus)==null||i.dispatch("fileattachmentannotation",{source:this,...s})}render(){this.container.classList.add("fileAttachmentAnnotation");const{container:e,data:s}=this;let i;s.hasAppearance||s.fillAlpha===0?i=document.createElement("div"):(i=document.createElement("img"),i.src=`${this.imageResourcesPath}annotation-${/paperclip/i.test(s.name)?"paperclip":"pushpin"}.svg`,s.fillAlpha&&s.fillAlpha<1&&(i.style=`filter: opacity(${Math.round(s.fillAlpha*100)}%);`)),i.addEventListener("dblclick",y(this,Il,rp).bind(this)),v(this,Ll,i);const{isMac:n}=Ne.platform;return e.addEventListener("keydown",r=>{r.key==="Enter"&&(n?r.metaKey:r.ctrlKey)&&y(this,Il,rp).call(this)}),!s.popupRef&&this.hasPopupData?this._createPopup():i.classList.add("popupTriggerArea"),e.append(i),e}getElementsToTriggerPopup(){return c(this,Ll)}addHighlightArea(){this.container.classList.add("highlightArea")}}Ll=new WeakMap,Il=new WeakSet,rp=function(){var e;(e=this.downloadManager)==null||e.openOrDownloadData(this.content,this.filename)};class mC{constructor({div:t,accessibilityManager:e,annotationCanvasMap:s,annotationEditorUIManager:i,page:n,viewport:r,structTreeLayer:a}){w(this,pa);w(this,jl,null);w(this,ga,null);w(this,fa,new Map);w(this,Nl,null);this.div=t,v(this,jl,e),v(this,ga,s),v(this,Nl,a||null),this.page=n,this.viewport=r,this.zIndex=0,this._annotationEditorUIManager=i}hasEditableAnnotations(){return c(this,fa).size>0}async render(t){var r;const{annotations:e}=t,s=this.div;kr(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 gf,annotationStorage:t.annotationStorage||new Zg,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===ie.POPUP;if(h){const d=i.get(a.id);if(!d)continue;n.elements=d}else{const{width:d,height:g}=Gi(a.rect);if(d<=0||g<=0)continue}n.data=a;const l=ZS.create(n);if(!l.isRenderable)continue;if(!h&&a.popupRef){const d=i.get(a.popupRef);d?d.push(l):i.set(a.popupRef,[l])}const u=l.render();a.hidden&&(u.style.visibility="hidden"),await y(this,pa,Ib).call(this,u,a.id),l._isEditable&&(c(this,fa).set(l.data.id,l),(r=this._annotationEditorUIManager)==null||r.renderAnnotationElement(l))}y(this,pa,ap).call(this)}update({viewport:t}){const e=this.div;this.viewport=t,kr(e,{rotation:t.rotation}),y(this,pa,ap).call(this),e.hidden=!1}getEditableAnnotations(){return Array.from(c(this,fa).values())}getEditableAnnotation(t){return c(this,fa).get(t)}}jl=new WeakMap,ga=new WeakMap,fa=new WeakMap,Nl=new WeakMap,pa=new WeakSet,Ib=async function(t,e){var r,a;const s=t.firstChild||t,i=s.id=`${zg}${e}`,n=await((r=c(this,Nl))==null?void 0:r.getAriaAttributes(i));if(n)for(const[h,l]of n)s.setAttribute(h,l);this.div.append(t),(a=c(this,jl))==null||a.moveElementInDOM(this.div,t,s,!1)},ap=function(){if(!c(this,ga))return;const t=this.div;for(const[e,s]of c(this,ga)){const i=t.querySelector(`[data-annotation-id="${e}"]`);if(!i)continue;s.className="annotationContent";const{firstChild:n}=i;n?n.nodeName==="CANVAS"?n.replaceWith(s):n.classList.contains("annotationContent")?n.after(s):n.before(s):i.append(s)}c(this,ga).clear()};const Iu=/\r\n?|\n/g,Et=class Et extends _t{constructor(e){super({...e,name:"freeTextEditor"});w(this,Qt);w(this,Qs);w(this,us,"");w(this,Bl,`${this.id}-editor`);w(this,ma,null);w(this,ds);v(this,Qs,e.color||Et._defaultColor||_t._defaultLineColor),v(this,ds,e.fontSize||Et._defaultFontSize)}static get _keyboardManager(){const e=Et.prototype,s=r=>r.isEmpty(),i=Mr.TRANSLATE_SMALL,n=Mr.TRANSLATE_BIG;return ut(this,"_keyboardManager",new Fh([[["ctrl+s","mac+meta+s","ctrl+p","mac+meta+p"],e.commitOrRemove,{bubbles:!0}],[["ctrl+Enter","mac+meta+Enter","Escape","mac+Escape"],e.commitOrRemove],[["ArrowLeft","mac+ArrowLeft"],e._translateEmpty,{args:[-i,0],checker:s}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],e._translateEmpty,{args:[-n,0],checker:s}],[["ArrowRight","mac+ArrowRight"],e._translateEmpty,{args:[i,0],checker:s}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],e._translateEmpty,{args:[n,0],checker:s}],[["ArrowUp","mac+ArrowUp"],e._translateEmpty,{args:[0,-i],checker:s}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],e._translateEmpty,{args:[0,-n],checker:s}],[["ArrowDown","mac+ArrowDown"],e._translateEmpty,{args:[0,i],checker:s}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],e._translateEmpty,{args:[0,n],checker:s}]]))}static initialize(e,s){_t.initialize(e,s);const i=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(i.getPropertyValue("--freetext-padding"))}static updateDefaultParams(e,s){switch(e){case Z.FREETEXT_SIZE:Et._defaultFontSize=s;break;case Z.FREETEXT_COLOR:Et._defaultColor=s;break}}updateParams(e,s){switch(e){case Z.FREETEXT_SIZE:y(this,Qt,jb).call(this,s);break;case Z.FREETEXT_COLOR:y(this,Qt,Nb).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[Z.FREETEXT_SIZE,Et._defaultFontSize],[Z.FREETEXT_COLOR,Et._defaultColor||_t._defaultLineColor]]}get propertiesToUpdate(){return[[Z.FREETEXT_SIZE,c(this,ds)],[Z.FREETEXT_COLOR,c(this,Qs)]]}_translateEmpty(e,s){this._uiManager.translateSelectedEditors(e,s,!0)}getInitialTranslation(){const e=this.parentScale;return[-Et._internalPadding*e,-(Et._internalPadding+c(this,ds))*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"),v(this,ma,new AbortController);const e=this._uiManager.combinedSignal(c(this,ma));this.editorDiv.addEventListener("keydown",this.editorDivKeydown.bind(this),{signal:e}),this.editorDiv.addEventListener("focus",this.editorDivFocus.bind(this),{signal:e}),this.editorDiv.addEventListener("blur",this.editorDivBlur.bind(this),{signal:e}),this.editorDiv.addEventListener("input",this.editorDivInput.bind(this),{signal:e}),this.editorDiv.addEventListener("paste",this.editorDivPaste.bind(this),{signal:e})}disableEditMode(){var e;this.isInEditMode()&&(this.parent.setEditingState(!0),super.disableEditMode(),this.overlayDiv.classList.add("enabled"),this.editorDiv.contentEditable=!1,this.div.setAttribute("aria-activedescendant",c(this,Bl)),this._isDraggable=!0,(e=c(this,ma))==null||e.abort(),v(this,ma,null),this.div.focus({preventScroll:!0}),this.isEditing=!1,this.parent.div.classList.add("freetextEditing"))}focusin(e){this._focusEventsAllowed&&(super.focusin(e),e.target!==this.editorDiv&&this.editorDiv.focus())}onceAdded(){var e;this.width||(this.enableEditMode(),this.editorDiv.focus(),(e=this._initialOptions)!=null&&e.isCentered&&this.center(),this._initialOptions=null)}isEmpty(){return!this.editorDiv||this.editorDiv.innerText.trim()===""}remove(){this.isEditing=!1,this.parent&&(this.parent.setEditingState(!0),this.parent.div.classList.add("freetextEditing")),super.remove()}commit(){if(!this.isInEditMode())return;super.commit(),this.disableEditMode();const e=c(this,us),s=v(this,us,y(this,Qt,Bb).call(this).trimEnd());if(e===s)return;const i=n=>{if(v(this,us,n),!n){this.remove();return}y(this,Qt,Cd).call(this),this._uiManager.rebuild(this),y(this,Qt,xd).call(this)};this.addCommands({cmd:()=>{i(s)},undo:()=>{i(e)},mustExec:!1}),y(this,Qt,xd).call(this)}shouldGetKeyboardEvents(){return this.isInEditMode()}enterInEditMode(){this.enableEditMode(),this.editorDiv.focus()}dblclick(e){this.enterInEditMode()}keydown(e){e.target===this.div&&e.key==="Enter"&&(this.enterInEditMode(),e.preventDefault())}editorDivKeydown(e){Et._keyboardManager.exec(this,e)}editorDivFocus(e){this.isEditing=!0}editorDivBlur(e){this.isEditing=!1}editorDivInput(e){this.parent.div.classList.toggle("freetextEditing",this.isEmpty())}disableEditing(){this.editorDiv.setAttribute("role","comment"),this.editorDiv.removeAttribute("aria-multiline")}enableEditing(){this.editorDiv.setAttribute("role","textbox"),this.editorDiv.setAttribute("aria-multiline",!0)}render(){if(this.div)return this.div;let e,s;this.width&&(e=this.x,s=this.y),super.render(),this.editorDiv=document.createElement("div"),this.editorDiv.className="internal",this.editorDiv.setAttribute("id",c(this,Bl)),this.editorDiv.setAttribute("data-l10n-id","pdfjs-free-text2"),this.editorDiv.setAttribute("data-l10n-attrs","default-content"),this.enableEditing(),this.editorDiv.contentEditable=!0;const{style:i}=this.editorDiv;if(i.fontSize=`calc(${c(this,ds)}px * var(--scale-factor))`,i.color=c(this,Qs),this.div.append(this.editorDiv),this.overlayDiv=document.createElement("div"),this.overlayDiv.classList.add("overlay","enabled"),this.div.append(this.overlayDiv),Mu(this,this.div,["dblclick","keydown"]),this.width){const[n,r]=this.parentDimensions;if(this.annotationElementId){const{position:a}=this._initialData;let[h,l]=this.getInitialTranslation();[h,l]=this.pageTranslationToScreen(h,l);const[u,d]=this.pageDimensions,[g,f]=this.pageTranslation;let p,m;switch(this.rotation){case 0:p=e+(a[0]-g)/u,m=s+this.height-(a[1]-f)/d;break;case 90:p=e+(a[0]-g)/u,m=s-(a[1]-f)/d,[h,l]=[l,-h];break;case 180:p=e-this.width+(a[0]-g)/u,m=s-(a[1]-f)/d,[h,l]=[-h,-l];break;case 270:p=e+(a[0]-g-this.height*d)/u,m=s+(a[1]-f-this.width*u)/d,[h,l]=[-l,h];break}this.setAt(p*n,m*r,h,l)}else this.setAt(e*n,s*r,this.width*n,this.height*r);y(this,Qt,Cd).call(this),this._isDraggable=!0,this.editorDiv.contentEditable=!1}else this._isDraggable=!1,this.editorDiv.contentEditable=!0;return this.div}editorDivPaste(e){var p,m,_;const s=e.clipboardData||window.clipboardData,{types:i}=s;if(i.length===1&&i[0]==="text/plain")return;e.preventDefault();const n=y(p=Et,cn,op).call(p,s.getData("text")||"").replaceAll(Iu,`
|
|
531
|
-
`);if(!n)return;const r=window.getSelection();if(!r.rangeCount)return;this.editorDiv.normalize(),r.deleteFromDocument();const
|
|
532
|
-
`)){
|
|
527
|
+
`}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.vibrance;for(let i=0;i<e.length;i+=4){const n=Math.max(e[i],e[i+1],e[i+2]),r=(e[i]+e[i+1]+e[i+2])/3,o=2*Math.abs(n-r)/255*s;e[i]+=n!==e[i]?(n-e[i])*o:0,e[i+1]+=n!==e[i+1]?(n-e[i+1])*o:0,e[i+2]+=n!==e[i+2]?(n-e[i+2])*o:0}}sendUniformData(t,e){t.uniform1f(e.uVibrance,-this.vibrance)}isNeutralState(){return this.vibrance===0}}T(Iu,"type","Vibrance"),T(Iu,"defaults",{vibrance:0}),T(Iu,"uniformLocations",["uVibrance"]),W.setClass(Iu);const ix="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2040%2040'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3ccircle%20cx='20'%20cy='20'%20r='10.75'%20stroke='currentColor'%20stroke-width='2.5'/%3e%3cpath%20d='M16%2024L23.7782%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3cpath%20d='M24%2024L16.2218%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3c/svg%3e";function nx(a){return new URL(Object.assign({"../assets/close.svg":ix})[`../assets/${a}`],typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:jt&&jt.tagName.toUpperCase()==="SCRIPT"&&jt.src||new URL("pdf-canvas.umd.js",document.baseURI).href).href}function rx(a){return new Promise((t,e)=>{const s=window.URL.createObjectURL(a),i=new Image;i.src=s,i.addEventListener("load",async()=>{window.URL.revokeObjectURL(s),t(await ox(i))}),i.addEventListener("error",n=>{window.URL.revokeObjectURL(s),e(n)})})}function ox(a){return new Promise(t=>{const e=document.createElement("canvas"),s=e.getContext("2d"),{naturalWidth:i,naturalHeight:n}=a;e.width=i,e.height=n,s==null||s.drawImage(a,0,0,i,n),t(e.toDataURL("image/jpeg",.8))})}let q0=null;function ax(){const a=document.createElement("div");a.style.width="1in",document.body.append(a);const t=a.offsetWidth;return a.remove(),t}function hx(){const a=q0??ax();return q0=a,a/72}function lx(a,t=500){if(typeof a!="function")throw new TypeError("The first argument is not a function.");let e=null;return function(...s){e&&clearTimeout(e),e=setTimeout(()=>{e=null,a.apply(this,s)},t)}}const ks=new Map;function cx(a){const t=new Bg(a);return ks.set(a,t),t}function ux(a,t){const e=Date.now();return{PDFId:`${a.name}-${e}`,name:a.name.replace(/.pdf/,""),updateDate:e,PDFBase64:t}}function dx(a,t){const e=a.getViewport({scale:t}),s=document.createElement("canvas"),i=s.getContext("2d"),n=hx()/window.devicePixelRatio;s.width=Math.floor(e.width*n),s.height=Math.floor(e.height*n);const r={canvasContext:i,viewport:e,transform:[n,0,0,n,0,0]},o=a.render(r);return{canvas:s,renderTask:o}}async function gx(a,t,e){const s=a||nx("close.svg"),{objects:i,options:n}=await Yw(s),r=i.filter(h=>h!==null),o=aw.groupSVGElements(r,n);return r.forEach(h=>{h.stroke=t}),o.hoverCursor="pointer",o.stroke=`${t}-${e}`,o}function fx(a,t){if(!ks.get(a))return;const s=1/3,i=_x(t,s);Q0(a,i,s)}async function px(a,t){const e=await rx(t),s=Date.now(),n={PDFId:`${t.name}${s}`,name:t.name.replace(/.png|.jpg|.jpeg/,""),updateDate:s,PDFBase64:e};return K0(a,{url:e}),{...n,pages:1}}async function K0(a,{url:t,scale:e=.5}){if(!ks.get(a))return;const i=await Te.fromURL(t);i.scale(e),Q0(a,i,e)}function Q0(a,t,e){const s=ks.get(a);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function Gh(a,t){if(!t)return;const{oCoords:e}=a;if(!e)return;const{x:s,y:i}=e.tl.touchCorner.tl,{height:n,width:r,scaleY:o,scaleX:h}=t;t.top=i-n*o/2,t.left=s-r*h/2,t.setCoords()}function mx(a,t,e){!e||!a||(e.scale(1/t),Gh(a,e))}function vx(a,t,e){a&&(a.borderScaleFactor=1/t,a.cornerSize=6*(1/t),a.touchCornerSize=24*(1/t),a.cornerStrokeColor=e.stroke,a.setCoords())}function bx(a){const t=ks.get(a);t&&(t.discardActiveObject(),t.renderAll())}function yx(a){const t=ks.get(a);t&&(t.clear(),ks.delete(a))}function _x(a,t){return new Te(a,{scaleX:t,scaleY:t})}var Wh={};Wh.d=(a,t)=>{for(var e in t)Wh.o(t,e)&&!Wh.o(a,e)&&Object.defineProperty(a,e,{enumerable:!0,get:t[e]})},Wh.o=(a,t)=>Object.prototype.hasOwnProperty.call(a,t);var Z=globalThis.pdfjsLib={};Wh.d(Z,{AbortException:()=>jr,AnnotationEditorLayer:()=>Ff,AnnotationEditorParamsType:()=>ut,AnnotationEditorType:()=>nt,AnnotationEditorUIManager:()=>Br,AnnotationLayer:()=>pC,AnnotationMode:()=>Wn,ColorPicker:()=>ed,DOMSVGFactory:()=>Af,DrawLayer:()=>If,FeatureTest:()=>Ge,GlobalWorkerOptions:()=>nn,ImageKind:()=>ju,InvalidPDFException:()=>Z0,MissingPDFException:()=>Xh,OPS:()=>Js,OutputScale:()=>uf,PDFDataRangeTransport:()=>Dv,PDFDateString:()=>lf,PDFWorker:()=>la,PasswordResponses:()=>Cx,PermissionFlag:()=>Sx,PixelsPerInch:()=>Xn,RenderingCancelledException:()=>af,TextLayer:()=>Qh,UnexpectedResponseException:()=>Vu,Util:()=>$,VerbosityLevel:()=>Nu,XfaLayer:()=>Iv,build:()=>qS,createValidAbsoluteUrl:()=>kx,fetchData:()=>Wu,getDocument:()=>HS,getFilenameFromUrl:()=>jx,getPdfFilenameFromUrl:()=>Nx,getXfaPageViewport:()=>Bx,isDataScheme:()=>zu,isPdfFile:()=>hf,noContextMenu:()=>Zs,normalizeUnicode:()=>Lx,setLayerDimensions:()=>Nr,shadow:()=>at,stopEvent:()=>ti,version:()=>$S});const Ve=typeof process=="object"&&process+""=="[object process]"&&!process.versions.nw&&!(process.versions.electron&&process.type&&process.type!=="browser"),J0=[1,0,0,1,0,0],Jg=[.001,0,0,.001,0,0],wx=1e7,Zg=1.35,cs={ANY:1,DISPLAY:2,PRINT:4,SAVE:8,ANNOTATIONS_FORMS:16,ANNOTATIONS_STORAGE:32,ANNOTATIONS_DISABLE:64,IS_EDITING:128,OPLIST:256},Wn={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},xx="pdfjs_internal_editor_",nt={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15},ut={RESIZE:1,CREATE:2,FREETEXT_SIZE:11,FREETEXT_COLOR:12,FREETEXT_OPACITY:13,INK_COLOR:21,INK_THICKNESS:22,INK_OPACITY:23,HIGHLIGHT_COLOR:31,HIGHLIGHT_DEFAULT_COLOR:32,HIGHLIGHT_THICKNESS:33,HIGHLIGHT_FREE:34,HIGHLIGHT_SHOW_ALL:35,DRAW_STEP:41},Sx={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},Ee={FILL:0,STROKE:1,FILL_STROKE:2,INVISIBLE:3,FILL_ADD_TO_PATH:4,STROKE_ADD_TO_PATH:5,FILL_STROKE_ADD_TO_PATH:6,ADD_TO_PATH:7,FILL_STROKE_MASK:3,ADD_TO_PATH_FLAG:4},ju={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},oe={TEXT:1,LINK:2,FREETEXT:3,LINE:4,SQUARE:5,CIRCLE:6,POLYGON:7,POLYLINE:8,HIGHLIGHT:9,UNDERLINE:10,SQUIGGLY:11,STRIKEOUT:12,STAMP:13,CARET:14,INK:15,POPUP:16,FILEATTACHMENT:17,SOUND:18,MOVIE:19,WIDGET:20,SCREEN:21,PRINTERMARK:22,TRAPNET:23,WATERMARK:24,THREED:25,REDACT:26},zh={SOLID:1,DASHED:2,BEVELED:3,INSET:4,UNDERLINE:5},Nu={ERRORS:0,WARNINGS:1,INFOS:5},Js={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},Cx={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};let Bu=Nu.WARNINGS;function Ax(a){Number.isInteger(a)&&(Bu=a)}function Tx(){return Bu}function Hu(a){Bu>=Nu.INFOS&&console.log(`Info: ${a}`)}function rt(a){Bu>=Nu.WARNINGS&&console.log(`Warning: ${a}`)}function St(a){throw new Error(a)}function te(a,t){a||St(t)}function Ex(a){switch(a==null?void 0:a.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}function kx(a,t=null,e=null){if(!a)return null;try{if(e&&typeof a=="string"){if(e.addDefaultProtocol&&a.startsWith("www.")){const i=a.match(/\./g);(i==null?void 0:i.length)>=2&&(a=`http://${a}`)}if(e.tryConvertEncoding)try{a=Rx(a)}catch{}}const s=t?new URL(a,t):new URL(a);if(Ex(s))return s}catch{}return null}function at(a,t,e,s=!1){return Object.defineProperty(a,t,{value:e,enumerable:!s,configurable:!0,writable:!1}),e}const zn=function(){function t(e,s){this.message=e,this.name=s}return t.prototype=new Error,t.constructor=t,t}();class tf extends zn{constructor(t,e){super(t,"PasswordException"),this.code=e}}class ef extends zn{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}}class Z0 extends zn{constructor(t){super(t,"InvalidPDFException")}}class Xh extends zn{constructor(t){super(t,"MissingPDFException")}}class Vu extends zn{constructor(t,e){super(t,"UnexpectedResponseException"),this.status=e}}class Mx extends zn{constructor(t){super(t,"FormatError")}}class jr extends zn{constructor(t){super(t,"AbortException")}}function tv(a){(typeof a!="object"||(a==null?void 0:a.length)===void 0)&&St("Invalid argument for bytesToString");const t=a.length,e=8192;if(t<e)return String.fromCharCode.apply(null,a);const s=[];for(let i=0;i<t;i+=e){const n=Math.min(i+e,t),r=a.subarray(i,n);s.push(String.fromCharCode.apply(null,r))}return s.join("")}function Gu(a){typeof a!="string"&&St("Invalid argument for stringToBytes");const t=a.length,e=new Uint8Array(t);for(let s=0;s<t;++s)e[s]=a.charCodeAt(s)&255;return e}function Px(a){return String.fromCharCode(a>>24&255,a>>16&255,a>>8&255,a&255)}function sf(a){const t=Object.create(null);for(const[e,s]of a)t[e]=s;return t}function Ox(){const a=new Uint8Array(4);return a[0]=1,new Uint32Array(a.buffer,0,1)[0]===1}function Dx(){try{return new Function(""),!0}catch{return!1}}class Ge{static get isLittleEndian(){return at(this,"isLittleEndian",Ox())}static get isEvalSupported(){return at(this,"isEvalSupported",Dx())}static get isOffscreenCanvasSupported(){return at(this,"isOffscreenCanvasSupported",typeof OffscreenCanvas<"u")}static get isImageDecoderSupported(){return at(this,"isImageDecoderSupported",typeof ImageDecoder<"u")}static get platform(){return typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.platform)=="string"?at(this,"platform",{isMac:navigator.platform.includes("Mac"),isWindows:navigator.platform.includes("Win"),isFirefox:typeof(navigator==null?void 0:navigator.userAgent)=="string"&&navigator.userAgent.includes("Firefox")}):at(this,"platform",{isMac:!1,isWindows:!1,isFirefox:!1})}static get isCSSRoundSupported(){var t,e;return at(this,"isCSSRoundSupported",(e=(t=globalThis.CSS)==null?void 0:t.supports)==null?void 0:e.call(t,"width: round(1.5px, 1px)"))}}const nf=Array.from(Array(256).keys(),a=>a.toString(16).padStart(2,"0"));class ${static makeHexColor(t,e,s){return`#${nf[t]}${nf[e]}${nf[s]}`}static scaleMinMax(t,e){let s;t[0]?(t[0]<0&&(s=e[0],e[0]=e[2],e[2]=s),e[0]*=t[0],e[2]*=t[0],t[3]<0&&(s=e[1],e[1]=e[3],e[3]=s),e[1]*=t[3],e[3]*=t[3]):(s=e[0],e[0]=e[1],e[1]=s,s=e[2],e[2]=e[3],e[3]=s,t[1]<0&&(s=e[1],e[1]=e[3],e[3]=s),e[1]*=t[1],e[3]*=t[1],t[2]<0&&(s=e[0],e[0]=e[2],e[2]=s),e[0]*=t[2],e[2]*=t[2]),e[0]+=t[4],e[1]+=t[5],e[2]+=t[4],e[3]+=t[5]}static transform(t,e){return[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],t[0]*e[4]+t[2]*e[5]+t[4],t[1]*e[4]+t[3]*e[5]+t[5]]}static applyTransform(t,e){const s=t[0]*e[0]+t[1]*e[2]+e[4],i=t[0]*e[1]+t[1]*e[3]+e[5];return[s,i]}static applyInverseTransform(t,e){const s=e[0]*e[3]-e[1]*e[2],i=(t[0]*e[3]-t[1]*e[2]+e[2]*e[5]-e[4]*e[3])/s,n=(-t[0]*e[1]+t[1]*e[0]+e[4]*e[1]-e[5]*e[0])/s;return[i,n]}static getAxialAlignedBoundingBox(t,e){const s=this.applyTransform(t,e),i=this.applyTransform(t.slice(2,4),e),n=this.applyTransform([t[0],t[3]],e),r=this.applyTransform([t[2],t[1]],e);return[Math.min(s[0],i[0],n[0],r[0]),Math.min(s[1],i[1],n[1],r[1]),Math.max(s[0],i[0],n[0],r[0]),Math.max(s[1],i[1],n[1],r[1])]}static inverseTransform(t){const e=t[0]*t[3]-t[1]*t[2];return[t[3]/e,-t[1]/e,-t[2]/e,t[0]/e,(t[2]*t[5]-t[4]*t[3])/e,(t[4]*t[1]-t[5]*t[0])/e]}static singularValueDecompose2dScale(t){const e=[t[0],t[2],t[1],t[3]],s=t[0]*e[0]+t[1]*e[2],i=t[0]*e[1]+t[1]*e[3],n=t[2]*e[0]+t[3]*e[2],r=t[2]*e[1]+t[3]*e[3],o=(s+r)/2,h=Math.sqrt((s+r)**2-4*(s*r-n*i))/2,c=o+h||1,u=o-h||1;return[Math.sqrt(c),Math.sqrt(u)]}static normalizeRect(t){const e=t.slice(0);return t[0]>t[2]&&(e[0]=t[2],e[2]=t[0]),t[1]>t[3]&&(e[1]=t[3],e[3]=t[1]),e}static intersect(t,e){const s=Math.max(Math.min(t[0],t[2]),Math.min(e[0],e[2])),i=Math.min(Math.max(t[0],t[2]),Math.max(e[0],e[2]));if(s>i)return null;const n=Math.max(Math.min(t[1],t[3]),Math.min(e[1],e[3])),r=Math.min(Math.max(t[1],t[3]),Math.max(e[1],e[3]));return n>r?null:[s,n,i,r]}static bezierBoundingBox(t,e,s,i,n,r,o,h,c){return c?(c[0]=Math.min(c[0],t,o),c[1]=Math.min(c[1],e,h),c[2]=Math.max(c[2],t,o),c[3]=Math.max(c[3],e,h)):c=[Math.min(t,o),Math.min(e,h),Math.max(t,o),Math.max(e,h)],_(this,on,qf).call(this,t,s,n,o,e,i,r,h,3*(-t+3*(s-n)+o),6*(t-2*s+n),3*(s-t),c),_(this,on,qf).call(this,t,s,n,o,e,i,r,h,3*(-e+3*(i-r)+h),6*(e-2*i+r),3*(i-e),c),c}}on=new WeakSet,Ad=function(t,e,s,i,n,r,o,h,c,u){if(c<=0||c>=1)return;const d=1-c,g=c*c,f=g*c,p=d*(d*(d*t+3*c*e)+3*g*s)+f*i,m=d*(d*(d*n+3*c*r)+3*g*o)+f*h;u[0]=Math.min(u[0],p),u[1]=Math.min(u[1],m),u[2]=Math.max(u[2],p),u[3]=Math.max(u[3],m)},qf=function(t,e,s,i,n,r,o,h,c,u,d,g){if(Math.abs(c)<1e-12){Math.abs(u)>=1e-12&&_(this,on,Ad).call(this,t,e,s,i,n,r,o,h,-d/u,g);return}const f=u**2-4*d*c;if(f<0)return;const p=Math.sqrt(f),m=2*c;_(this,on,Ad).call(this,t,e,s,i,n,r,o,h,(-u+p)/m,g),_(this,on,Ad).call(this,t,e,s,i,n,r,o,h,(-u-p)/m,g)},w($,on);function Rx(a){return decodeURIComponent(escape(a))}let rf=null,ev=null;function Lx(a){return rf||(rf=/([\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"]])),a.replaceAll(rf,(t,e,s)=>e?e.normalize("NFKC"):ev.get(s))}function Fx(){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();const a=new Uint8Array(32);return crypto.getRandomValues(a),tv(a)}const of="pdfjs_internal_id_",en={BEZIER_CURVE_TO:0,MOVE_TO:1,LINE_TO:2,QUADRATIC_CURVE_TO:3,RESTORE:4,SAVE:5,SCALE:6,TRANSFORM:7,TRANSLATE:8};function Ix(a){return Uint8Array.prototype.toBase64?a.toBase64():btoa(tv(a))}const sn="http://www.w3.org/2000/svg",Gr=class Gr{};q(Gr,"CSS",96),q(Gr,"PDF",72),q(Gr,"PDF_TO_CSS_UNITS",Gr.CSS/Gr.PDF);let Xn=Gr;async function Wu(a,t="text"){if(Yh(a,document.baseURI)){const e=await fetch(a);if(!e.ok)throw new Error(e.statusText);switch(t){case"arraybuffer":return e.arrayBuffer();case"blob":return e.blob();case"json":return e.json()}return e.text()}return new Promise((e,s)=>{const i=new XMLHttpRequest;i.open("GET",a,!0),i.responseType=t,i.onreadystatechange=()=>{if(i.readyState===XMLHttpRequest.DONE){if(i.status===200||i.status===0){switch(t){case"arraybuffer":case"blob":case"json":e(i.response);return}e(i.responseText);return}s(new Error(i.statusText))}},i.send(null)})}class Uh{constructor({viewBox:t,scale:e,rotation:s,offsetX:i=0,offsetY:n=0,dontFlip:r=!1}){this.viewBox=t,this.scale=e,this.rotation=s,this.offsetX=i,this.offsetY=n;const o=(t[2]+t[0])/2,h=(t[3]+t[1])/2;let c,u,d,g;switch(s%=360,s<0&&(s+=360),s){case 180:c=-1,u=0,d=0,g=1;break;case 90:c=0,u=1,d=1,g=0;break;case 270:c=0,u=-1,d=-1,g=0;break;case 0:c=1,u=0,d=0,g=-1;break;default:throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.")}r&&(d=-d,g=-g);let f,p,m,y;c===0?(f=Math.abs(h-t[1])*e+i,p=Math.abs(o-t[0])*e+n,m=(t[3]-t[1])*e,y=(t[2]-t[0])*e):(f=Math.abs(o-t[0])*e+i,p=Math.abs(h-t[1])*e+n,m=(t[2]-t[0])*e,y=(t[3]-t[1])*e),this.transform=[c*e,u*e,d*e,g*e,f-c*e*o-d*e*h,p-u*e*o-g*e*h],this.width=m,this.height=y}get rawDims(){const{viewBox:t}=this;return at(this,"rawDims",{pageWidth:t[2]-t[0],pageHeight:t[3]-t[1],pageX:t[0],pageY:t[1]})}clone({scale:t=this.scale,rotation:e=this.rotation,offsetX:s=this.offsetX,offsetY:i=this.offsetY,dontFlip:n=!1}={}){return new Uh({viewBox:this.viewBox.slice(),scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}convertToViewportPoint(t,e){return $.applyTransform([t,e],this.transform)}convertToViewportRectangle(t){const e=$.applyTransform([t[0],t[1]],this.transform),s=$.applyTransform([t[2],t[3]],this.transform);return[e[0],e[1],s[0],s[1]]}convertToPdfPoint(t,e){return $.applyInverseTransform([t,e],this.transform)}}class af extends zn{constructor(t,e=0){super(t,"RenderingCancelledException"),this.extraDelay=e}}function zu(a){const t=a.length;let e=0;for(;e<t&&a[e].trim()==="";)e++;return a.substring(e,e+5).toLowerCase()==="data:"}function hf(a){return typeof a=="string"&&/\.pdf$/i.test(a)}function jx(a){return[a]=a.split(/[#?]/,1),a.substring(a.lastIndexOf("/")+1)}function Nx(a,t="document.pdf"){if(typeof a!="string")return t;if(zu(a))return rt('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.'),t;const e=/^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/,s=/[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i,i=e.exec(a);let n=s.exec(i[1])||s.exec(i[2])||s.exec(i[3]);if(n&&(n=n[0],n.includes("%")))try{n=s.exec(decodeURIComponent(n))[0]}catch{}return n||t}class sv{constructor(){q(this,"started",Object.create(null));q(this,"times",[])}time(t){t in this.started&&rt(`Timer is already running for ${t}`),this.started[t]=Date.now()}timeEnd(t){t in this.started||rt(`Timer has not been started for ${t}`),this.times.push({name:t,start:this.started[t],end:Date.now()}),delete this.started[t]}toString(){const t=[];let e=0;for(const{name:s}of this.times)e=Math.max(s.length,e);for(const{name:s,start:i,end:n}of this.times)t.push(`${s.padEnd(e)} ${n-i}ms
|
|
528
|
+
`);return t.join("")}}function Yh(a,t){try{const{protocol:e}=t?new URL(a,t):new URL(a);return e==="http:"||e==="https:"}catch{return!1}}function Zs(a){a.preventDefault()}function ti(a){a.preventDefault(),a.stopPropagation()}function iv(a){console.log("Deprecated API usage: "+a)}class lf{static toDateObject(t){if(!t||typeof t!="string")return null;l(this,el)||v(this,el,new RegExp("^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+|-])?(\\d{2})?'?(\\d{2})?'?"));const e=l(this,el).exec(t);if(!e)return null;const s=parseInt(e[1],10);let i=parseInt(e[2],10);i=i>=1&&i<=12?i-1:0;let n=parseInt(e[3],10);n=n>=1&&n<=31?n:1;let r=parseInt(e[4],10);r=r>=0&&r<=23?r:0;let o=parseInt(e[5],10);o=o>=0&&o<=59?o:0;let h=parseInt(e[6],10);h=h>=0&&h<=59?h:0;const c=e[7]||"Z";let u=parseInt(e[8],10);u=u>=0&&u<=23?u:0;let d=parseInt(e[9],10)||0;return d=d>=0&&d<=59?d:0,c==="-"?(r+=u,o+=d):c==="+"&&(r-=u,o-=d),new Date(Date.UTC(s,i,n,r,o,h))}}el=new WeakMap,w(lf,el);function Bx(a,{scale:t=1,rotation:e=0}){const{width:s,height:i}=a.attributes.style,n=[0,0,parseInt(s),parseInt(i)];return new Uh({viewBox:n,scale:t,rotation:e})}function cf(a){if(a.startsWith("#")){const t=parseInt(a.slice(1),16);return[(t&16711680)>>16,(t&65280)>>8,t&255]}return a.startsWith("rgb(")?a.slice(4,-1).split(",").map(t=>parseInt(t)):a.startsWith("rgba(")?a.slice(5,-1).split(",").map(t=>parseInt(t)).slice(0,3):(rt(`Not a valid color format: "${a}"`),[0,0,0])}function Hx(a){const t=document.createElement("span");t.style.visibility="hidden",document.body.append(t);for(const e of a.keys()){t.style.color=e;const s=window.getComputedStyle(t).color;a.set(e,cf(s))}t.remove()}function Rt(a){const{a:t,b:e,c:s,d:i,e:n,f:r}=a.getTransform();return[t,e,s,i,n,r]}function xi(a){const{a:t,b:e,c:s,d:i,e:n,f:r}=a.getTransform().invertSelf();return[t,e,s,i,n,r]}function Nr(a,t,e=!1,s=!0){if(t instanceof Uh){const{pageWidth:i,pageHeight:n}=t.rawDims,{style:r}=a,o=Ge.isCSSRoundSupported,h=`var(--scale-factor) * ${i}px`,c=`var(--scale-factor) * ${n}px`,u=o?`round(down, ${h}, var(--scale-round-x, 1px))`:`calc(${h})`,d=o?`round(down, ${c}, var(--scale-round-y, 1px))`:`calc(${c})`;!e||t.rotation%180===0?(r.width=u,r.height=d):(r.width=d,r.height=u)}s&&a.setAttribute("data-main-rotation",t.rotation)}class uf{constructor(){const t=window.devicePixelRatio||1;this.sx=t,this.sy=t}get scaled(){return this.sx!==1||this.sy!==1}get symmetric(){return this.sx===this.sy}}const an=class an{constructor(t){w(this,We);w(this,Un,null);w(this,Wr,null);w(this,ei);w(this,zr,null);w(this,sl,null);v(this,ei,t),l(an,il)||v(an,il,Object.freeze({freetext:"pdfjs-editor-remove-freetext-button",highlight:"pdfjs-editor-remove-highlight-button",ink:"pdfjs-editor-remove-ink-button",stamp:"pdfjs-editor-remove-stamp-button"}))}render(){const t=v(this,Un,document.createElement("div"));t.classList.add("editToolbar","hidden"),t.setAttribute("role","toolbar");const e=l(this,ei)._uiManager._signal;t.addEventListener("contextmenu",Zs,{signal:e}),t.addEventListener("pointerdown",_(an,nd,ab),{signal:e});const s=v(this,zr,document.createElement("div"));s.className="buttons",t.append(s);const i=l(this,ei).toolbarPosition;if(i){const{style:n}=t,r=l(this,ei)._uiManager.direction==="ltr"?1-i[0]:i[0];n.insetInlineEnd=`${100*r}%`,n.top=`calc(${100*i[1]}% + var(--editor-toolbar-vert-offset))`}return _(this,We,cb).call(this),t}get div(){return l(this,Un)}hide(){var t;l(this,Un).classList.add("hidden"),(t=l(this,Wr))==null||t.hideDropdown()}show(){var t;l(this,Un).classList.remove("hidden"),(t=l(this,sl))==null||t.shown()}async addAltText(t){const e=await t.render();_(this,We,Td).call(this,e),l(this,zr).prepend(e,l(this,We,Kf)),v(this,sl,t)}addColorPicker(t){v(this,Wr,t);const e=t.renderButton();_(this,We,Td).call(this,e),l(this,zr).prepend(e,l(this,We,Kf))}remove(){var t;l(this,Un).remove(),(t=l(this,Wr))==null||t.destroy(),v(this,Wr,null)}};Un=new WeakMap,Wr=new WeakMap,ei=new WeakMap,zr=new WeakMap,sl=new WeakMap,il=new WeakMap,nd=new WeakSet,ab=function(t){t.stopPropagation()},We=new WeakSet,hb=function(t){l(this,ei)._focusEventsAllowed=!1,ti(t)},lb=function(t){l(this,ei)._focusEventsAllowed=!0,ti(t)},Td=function(t){const e=l(this,ei)._uiManager._signal;t.addEventListener("focusin",_(this,We,hb).bind(this),{capture:!0,signal:e}),t.addEventListener("focusout",_(this,We,lb).bind(this),{capture:!0,signal:e}),t.addEventListener("contextmenu",Zs,{signal:e})},cb=function(){const{editorType:t,_uiManager:e}=l(this,ei),s=document.createElement("button");s.className="delete",s.tabIndex=0,s.setAttribute("data-l10n-id",l(an,il)[t]),_(this,We,Td).call(this,s),s.addEventListener("click",i=>{e.delete()},{signal:e._signal}),l(this,zr).append(s)},Kf=function(){const t=document.createElement("div");return t.className="divider",t},w(an,nd),w(an,il,null);let df=an;class Vx{constructor(t){w(this,Yn);w(this,nl,null);w(this,Xr,null);w(this,Ur);v(this,Ur,t)}show(t,e,s){const[i,n]=_(this,Yn,db).call(this,e,s),{style:r}=l(this,Xr)||v(this,Xr,_(this,Yn,ub).call(this));t.append(l(this,Xr)),r.insetInlineEnd=`${100*i}%`,r.top=`calc(${100*n}% + var(--editor-toolbar-vert-offset))`}hide(){l(this,Xr).remove()}}nl=new WeakMap,Xr=new WeakMap,Ur=new WeakMap,Yn=new WeakSet,ub=function(){const t=v(this,Xr,document.createElement("div"));t.className="editToolbar",t.setAttribute("role","toolbar"),t.addEventListener("contextmenu",Zs,{signal:l(this,Ur)._signal});const e=v(this,nl,document.createElement("div"));return e.className="buttons",t.append(e),_(this,Yn,gb).call(this),t},db=function(t,e){let s=0,i=0;for(const n of t){const r=n.y+n.height;if(r<s)continue;const o=n.x+(e?n.width:0);if(r>s){i=o,s=r;continue}e?o>i&&(i=o):o<i&&(i=o)}return[e?1-i:i,s]},gb=function(){const t=document.createElement("button");t.className="highlightButton",t.tabIndex=0,t.setAttribute("data-l10n-id","pdfjs-highlight-floating-button1");const e=document.createElement("span");t.append(e),e.className="visuallyHidden",e.setAttribute("data-l10n-id","pdfjs-highlight-floating-button-label");const s=l(this,Ur)._signal;t.addEventListener("contextmenu",Zs,{signal:s}),t.addEventListener("click",()=>{l(this,Ur).highlightSelection("floating_button")},{signal:s}),l(this,nl).append(t)};function Xu(a,t,e){for(const s of e)t.addEventListener(s,a[s].bind(a))}class Gx{constructor(){w(this,rd,0)}get id(){return`${xx}${Ke(this,rd)._++}`}}rd=new WeakMap;const jf=class jf{constructor(){w(this,ua);w(this,ca,Fx());w(this,rl,0);w(this,Me,null)}static get _isSVGFittingCanvas(){const t='data:image/svg+xml;charset=UTF-8,<svg viewBox="0 0 1 1" width="1" height="1" xmlns="http://www.w3.org/2000/svg"><rect width="1" height="1" style="fill:red;"/></svg>',s=new OffscreenCanvas(1,3).getContext("2d",{willReadFrequently:!0}),i=new Image;i.src=t;const n=i.decode().then(()=>(s.drawImage(i,0,0,1,1,0,0,1,3),new Uint32Array(s.getImageData(0,0,1,1).data.buffer)[0]===0));return at(this,"_isSVGFittingCanvas",n)}async getFromFile(t){const{lastModified:e,name:s,size:i,type:n}=t;return _(this,ua,Ed).call(this,`${e}_${s}_${i}_${n}`,t)}async getFromUrl(t){return _(this,ua,Ed).call(this,t,t)}async getFromBlob(t,e){const s=await e;return _(this,ua,Ed).call(this,t,s)}async getFromId(t){l(this,Me)||v(this,Me,new Map);const e=l(this,Me).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,Me)||v(this,Me,new Map);let s=l(this,Me).get(t);if(s!=null&&s.bitmap)return s.refCounter+=1,s;const i=new OffscreenCanvas(e.width,e.height);return i.getContext("2d").drawImage(e,0,0),s={bitmap:i.transferToImageBitmap(),id:`image_${l(this,ca)}_${Ke(this,rl)._++}`,refCounter:1,isSvg:!1},l(this,Me).set(t,s),l(this,Me).set(s.id,s),s}getSvgUrl(t){const e=l(this,Me).get(t);return e!=null&&e.isSvg?e.svgUrl:null}deleteId(t){var i;l(this,Me)||v(this,Me,new Map);const e=l(this,Me).get(t);if(!e||(e.refCounter-=1,e.refCounter!==0))return;const{bitmap:s}=e;if(!e.url&&!e.file){const n=new OffscreenCanvas(s.width,s.height);n.getContext("bitmaprenderer").transferFromImageBitmap(s),e.blobPromise=n.convertToBlob()}(i=s.close)==null||i.call(s),e.bitmap=null}isValidId(t){return t.startsWith(`image_${l(this,ca)}_`)}};ca=new WeakMap,rl=new WeakMap,Me=new WeakMap,ua=new WeakSet,Ed=async function(t,e){l(this,Me)||v(this,Me,new Map);let s=l(this,Me).get(t);if(s===null)return null;if(s!=null&&s.bitmap)return s.refCounter+=1,s;try{s||(s={bitmap:null,id:`image_${l(this,ca)}_${Ke(this,rl)._++}`,refCounter:0,isSvg:!1});let i;if(typeof e=="string"?(s.url=e,i=await Wu(e,"blob")):e instanceof File?i=s.file=e:e instanceof Blob&&(i=e),i.type==="image/svg+xml"){const n=jf._isSVGFittingCanvas,r=new FileReader,o=new Image,h=new Promise((c,u)=>{o.onload=()=>{s.bitmap=o,s.isSvg=!0,c()},r.onload=async()=>{const d=s.svgUrl=r.result;o.src=await n?`${d}#svgView(preserveAspectRatio(none))`:d},o.onerror=r.onerror=u});r.readAsDataURL(i),await h}else s.bitmap=await createImageBitmap(i);s.refCounter=1}catch(i){rt(i),s=null}return l(this,Me).set(t,s),s&&l(this,Me).set(s.id,s),s};let gf=jf;class Wx{constructor(t=128){w(this,qt,[]);w(this,$n,!1);w(this,ol);w(this,Ht,-1);v(this,ol,t)}add({cmd:t,undo:e,post:s,mustExec:i,type:n=NaN,overwriteIfSameType:r=!1,keepUndo:o=!1}){if(i&&t(),l(this,$n))return;const h={cmd:t,undo:e,post:s,type:n};if(l(this,Ht)===-1){l(this,qt).length>0&&(l(this,qt).length=0),v(this,Ht,0),l(this,qt).push(h);return}if(r&&l(this,qt)[l(this,Ht)].type===n){o&&(h.undo=l(this,qt)[l(this,Ht)].undo),l(this,qt)[l(this,Ht)]=h;return}const c=l(this,Ht)+1;c===l(this,ol)?l(this,qt).splice(0,1):(v(this,Ht,c),c<l(this,qt).length&&l(this,qt).splice(c)),l(this,qt).push(h)}undo(){if(l(this,Ht)===-1)return;v(this,$n,!0);const{undo:t,post:e}=l(this,qt)[l(this,Ht)];t(),e==null||e(),v(this,$n,!1),v(this,Ht,l(this,Ht)-1)}redo(){if(l(this,Ht)<l(this,qt).length-1){v(this,Ht,l(this,Ht)+1),v(this,$n,!0);const{cmd:t,post:e}=l(this,qt)[l(this,Ht)];t(),e==null||e(),v(this,$n,!1)}}hasSomethingToUndo(){return l(this,Ht)!==-1}hasSomethingToRedo(){return l(this,Ht)<l(this,qt).length-1}cleanType(t){if(l(this,Ht)!==-1){for(let e=l(this,Ht);e>=0;e--)if(l(this,qt)[e].type!==t){l(this,qt).splice(e+1,l(this,Ht)-e),v(this,Ht,e);return}l(this,qt).length=0,v(this,Ht,-1)}}destroy(){v(this,qt,null)}}qt=new WeakMap,$n=new WeakMap,ol=new WeakMap,Ht=new WeakMap;class $h{constructor(t){w(this,od);this.buffer=[],this.callbacks=new Map,this.allKeys=new Set;const{isMac:e}=Ge.platform;for(const[s,i,n={}]of t)for(const r of s){const o=r.startsWith("mac+");e&&o?(this.callbacks.set(r.slice(4),{callback:i,options:n}),this.allKeys.add(r.split("+").at(-1))):!e&&!o&&(this.callbacks.set(r,{callback:i,options:n}),this.allKeys.add(r.split("+").at(-1)))}}exec(t,e){if(!this.allKeys.has(e.key))return;const s=this.callbacks.get(_(this,od,fb).call(this,e));if(!s)return;const{callback:i,options:{bubbles:n=!1,args:r=[],checker:o=null}}=s;o&&!o(t,e)||(i.bind(t,...r,e)(),n||ti(e))}}od=new WeakSet,fb=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 ad=class ad{get _colors(){const t=new Map([["CanvasText",null],["Canvas",null]]);return Hx(t),at(this,"_colors",t)}convert(t){const e=cf(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 ad._colorsMapping.get(s);return e}getHexCode(t){const e=this._colors.get(t);return e?$.makeHexColor(...e):t}};q(ad,"_colorsMapping",new Map([["CanvasText",[0,0,0]],["Canvas",[255,255,255]]]));let ff=ad;const ba=class ba{constructor(t,e,s,i,n,r,o,h,c,u,d){w(this,B);w(this,da,new AbortController);w(this,ds,null);w(this,ae,new Map);w(this,me,new Map);w(this,ga,null);w(this,hn,null);w(this,fa,null);w(this,Ps,new Wx);w(this,qn,null);w(this,pa,0);w(this,Yr,new Set);w(this,Ci,null);w(this,si,null);w(this,$r,new Set);w(this,al,!1);w(this,hl,!1);w(this,ma,!1);w(this,ll,null);w(this,Ai,null);w(this,Kn,null);w(this,va,null);w(this,Qn,!1);w(this,Ti,null);w(this,hd,new Gx);w(this,Jn,!1);w(this,cl,!1);w(this,Zn,null);w(this,qr,null);w(this,ul,null);w(this,dl,null);w(this,ue,nt.NONE);w(this,wt,new Set);w(this,ln,null);w(this,Kr,null);w(this,gl,null);w(this,fl,{isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1});w(this,tr,[0,0]);w(this,Ei,null);w(this,cn,null);w(this,pl,null);w(this,Os,null);const g=this._signal=l(this,da).signal;v(this,cn,t),v(this,pl,e),v(this,ga,s),this._eventBus=i,i._on("editingaction",this.onEditingAction.bind(this),{signal:g}),i._on("pagechanging",this.onPageChanging.bind(this),{signal:g}),i._on("scalechanging",this.onScaleChanging.bind(this),{signal:g}),i._on("rotationchanging",this.onRotationChanging.bind(this),{signal:g}),i._on("setpreference",this.onSetPreference.bind(this),{signal:g}),i._on("switchannotationeditorparams",f=>this.updateParams(f.type,f.value),{signal:g}),_(this,B,vb).call(this),_(this,B,wb).call(this),_(this,B,Jf).call(this),v(this,hn,n.annotationStorage),v(this,ll,n.filterFactory),v(this,Kr,r),v(this,va,o||null),v(this,al,h),v(this,hl,c),v(this,ma,u),v(this,dl,d||null),this.viewParameters={realScale:Xn.PDF_TO_CSS_UNITS,rotation:0},this.isShiftKeyDown=!1}static get _keyboardManager(){const t=ba.prototype,e=r=>l(r,cn).contains(document.activeElement)&&document.activeElement.tagName!=="BUTTON"&&r.hasSomethingToControl(),s=(r,{target:o})=>{if(o instanceof HTMLInputElement){const{type:h}=o;return h!=="text"&&h!=="number"}return!0},i=this.TRANSLATE_SMALL,n=this.TRANSLATE_BIG;return at(this,"_keyboardManager",new $h([[["ctrl+a","mac+meta+a"],t.selectAll,{checker:s}],[["ctrl+z","mac+meta+z"],t.undo,{checker:s}],[["ctrl+y","ctrl+shift+z","mac+meta+shift+z","ctrl+shift+Z","mac+meta+shift+Z"],t.redo,{checker:s}],[["Backspace","alt+Backspace","ctrl+Backspace","shift+Backspace","mac+Backspace","mac+alt+Backspace","mac+ctrl+Backspace","Delete","ctrl+Delete","shift+Delete","mac+Delete"],t.delete,{checker:s}],[["Enter","mac+Enter"],t.addNewEditorFromKeyboard,{checker:(r,{target:o})=>!(o instanceof HTMLButtonElement)&&l(r,cn).contains(o)&&!r.isEnterHandled}],[[" ","mac+ "],t.addNewEditorFromKeyboard,{checker:(r,{target:o})=>!(o instanceof HTMLButtonElement)&&l(r,cn).contains(document.activeElement)}],[["Escape","mac+Escape"],t.unselectAll],[["ArrowLeft","mac+ArrowLeft"],t.translateSelectedEditors,{args:[-i,0],checker:e}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t.translateSelectedEditors,{args:[-n,0],checker:e}],[["ArrowRight","mac+ArrowRight"],t.translateSelectedEditors,{args:[i,0],checker:e}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t.translateSelectedEditors,{args:[n,0],checker:e}],[["ArrowUp","mac+ArrowUp"],t.translateSelectedEditors,{args:[0,-i],checker:e}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t.translateSelectedEditors,{args:[0,-n],checker:e}],[["ArrowDown","mac+ArrowDown"],t.translateSelectedEditors,{args:[0,i],checker:e}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t.translateSelectedEditors,{args:[0,n],checker:e}]]))}destroy(){var t,e,s,i;(t=l(this,Os))==null||t.resolve(),v(this,Os,null),(e=l(this,da))==null||e.abort(),v(this,da,null),this._signal=null;for(const n of l(this,me).values())n.destroy();l(this,me).clear(),l(this,ae).clear(),l(this,$r).clear(),v(this,ds,null),l(this,wt).clear(),l(this,Ps).destroy(),(s=l(this,ga))==null||s.destroy(),(i=l(this,Ti))==null||i.hide(),v(this,Ti,null),l(this,Ai)&&(clearTimeout(l(this,Ai)),v(this,Ai,null)),l(this,Ei)&&(clearTimeout(l(this,Ei)),v(this,Ei,null))}combinedSignal(t){return AbortSignal.any([this._signal,t.signal])}get mlManager(){return l(this,dl)}get useNewAltTextFlow(){return l(this,hl)}get useNewAltTextWhenAddingImage(){return l(this,ma)}get hcmFilter(){return at(this,"hcmFilter",l(this,Kr)?l(this,ll).addHCMFilter(l(this,Kr).foreground,l(this,Kr).background):"none")}get direction(){return at(this,"direction",getComputedStyle(l(this,cn)).direction)}get highlightColors(){return at(this,"highlightColors",l(this,va)?new Map(l(this,va).split(",").map(t=>t.split("=").map(e=>e.trim()))):null)}get highlightColorNames(){return at(this,"highlightColorNames",this.highlightColors?new Map(Array.from(this.highlightColors,t=>t.reverse())):null)}setMainHighlightColorPicker(t){v(this,ul,t)}editAltText(t,e=!1){var s;(s=l(this,ga))==null||s.editAltText(this,t,e)}switchToMode(t,e){this._eventBus.on("annotationeditormodechanged",e,{once:!0,signal:this._signal}),this._eventBus.dispatch("showannotationeditorui",{source:this,mode:t})}setPreference(t,e){this._eventBus.dispatch("setpreference",{source:this,name:t,value:e})}onSetPreference({name:t,value:e}){switch(t){case"enableNewAltTextWhenAddingImage":v(this,ma,e);break}}onPageChanging({pageNumber:t}){v(this,pa,t-1)}focusMainContainer(){l(this,cn).focus()}findParent(t,e){for(const s of l(this,me).values()){const{x:i,y:n,width:r,height:o}=s.div.getBoundingClientRect();if(t>=i&&t<=i+r&&e>=n&&e<=n+o)return s}return null}disableUserSelect(t=!1){l(this,pl).classList.toggle("noUserSelect",t)}addShouldRescale(t){l(this,$r).add(t)}removeShouldRescale(t){l(this,$r).delete(t)}onScaleChanging({scale:t}){var e;this.commitOrRemove(),this.viewParameters.realScale=t*Xn.PDF_TO_CSS_UNITS;for(const s of l(this,$r))s.onScaleChanging();(e=this.currentLayer)==null||e.onScaleChanging()}onRotationChanging({pagesRotation:t}){this.commitOrRemove(),this.viewParameters.rotation=t}highlightSelection(t=""){const e=document.getSelection();if(!e||e.isCollapsed)return;const{anchorNode:s,anchorOffset:i,focusNode:n,focusOffset:r}=e,o=e.toString(),c=_(this,B,kd).call(this,e).closest(".textLayer"),u=this.getSelectionBoxes(c);if(!u)return;e.empty();const d=_(this,B,Qf).call(this,c),g=l(this,ue)===nt.NONE,f=()=>{d==null||d.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:t,boxes:u,anchorNode:s,anchorOffset:i,focusNode:n,focusOffset:r,text:o}),g&&this.showAllEditors("highlight",!0,!0)};if(g){this.switchToMode(nt.HIGHLIGHT,f);return}f()}addToAnnotationStorage(t){!t.isEmpty()&&l(this,hn)&&!l(this,hn).has(t.id)&&l(this,hn).setValue(t.id,t)}blur(){if(this.isShiftKeyDown=!1,l(this,Qn)&&(v(this,Qn,!1),_(this,B,Md).call(this,"main_toolbar")),!this.hasSelection)return;const{activeElement:t}=document;for(const e of l(this,wt))if(e.div.contains(t)){v(this,qr,[e,t]),e._focusEventsAllowed=!1;break}}focus(){if(!l(this,qr))return;const[t,e]=l(this,qr);v(this,qr,null),e.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this._signal}),e.focus()}addEditListeners(){_(this,B,Jf).call(this),_(this,B,Zf).call(this)}removeEditListeners(){_(this,B,_b).call(this),_(this,B,tp).call(this)}dragOver(t){for(const{type:e}of t.dataTransfer.items)for(const s of l(this,si))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,si))if(s.isHandlingMimeForPasting(e.type)){s.paste(e,this.currentLayer),t.preventDefault();return}}copy(t){var s;if(t.preventDefault(),(s=l(this,ds))==null||s.commitOrRemove(),!this.hasSelection)return;const e=[];for(const i of l(this,wt)){const n=i.serialize(!0);n&&e.push(n)}e.length!==0&&t.clipboardData.setData("application/pdfjs",JSON.stringify(e))}cut(t){this.copy(t),this.delete()}async paste(t){t.preventDefault();const{clipboardData:e}=t;for(const n of e.items)for(const r of l(this,si))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)_(this,B,ep).call(this,h);_(this,B,sp).call(this,n)},o=()=>{for(const h of n)h.remove()};this.addCommands({cmd:r,undo:o,mustExec:!0})}catch(n){rt(`paste: "${n.message}".`)}}keydown(t){!this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!0),l(this,ue)!==nt.NONE&&!this.isEditorHandlingKeyboard&&ba._keyboardManager.exec(this,t)}keyup(t){this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!1,l(this,Qn)&&(v(this,Qn,!1),_(this,B,Md).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?(_(this,B,bb).call(this),_(this,B,Zf).call(this),_(this,B,Qe).call(this,{isEditing:l(this,ue)!==nt.NONE,isEmpty:_(this,B,xc).call(this),hasSomethingToUndo:l(this,Ps).hasSomethingToUndo(),hasSomethingToRedo:l(this,Ps).hasSomethingToRedo(),hasSelectedEditor:!1})):(_(this,B,yb).call(this),_(this,B,tp).call(this),_(this,B,Qe).call(this,{isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(t){if(!l(this,si)){v(this,si,t);for(const e of l(this,si))_(this,B,Rn).call(this,e.defaultPropertiesToUpdate)}}getId(){return l(this,hd).id}get currentLayer(){return l(this,me).get(l(this,pa))}getLayer(t){return l(this,me).get(t)}get currentPageIndex(){return l(this,pa)}addLayer(t){l(this,me).set(t.pageIndex,t),l(this,Jn)?t.enable():t.disable()}removeLayer(t){l(this,me).delete(t.pageIndex)}async updateMode(t,e=null,s=!1){if(l(this,ue)!==t&&!(l(this,Os)&&(await l(this,Os).promise,!l(this,Os)))){if(v(this,Os,Promise.withResolvers()),v(this,ue,t),t===nt.NONE){this.setEditingState(!1),_(this,B,Sb).call(this),l(this,Os).resolve();return}this.setEditingState(!0),await _(this,B,xb).call(this),this.unselectAll();for(const i of l(this,me).values())i.updateMode(t);if(!e){s&&this.addNewEditorFromKeyboard(),l(this,Os).resolve();return}for(const i of l(this,ae).values())i.annotationElementId===e?(this.setSelected(i),i.enterInEditMode()):i.unselect();l(this,Os).resolve()}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(t){t!==l(this,ue)&&this._eventBus.dispatch("switchannotationeditormode",{source:this,mode:t})}updateParams(t,e){var s;if(l(this,si)){switch(t){case ut.CREATE:this.currentLayer.addNewEditor();return;case ut.HIGHLIGHT_DEFAULT_COLOR:(s=l(this,ul))==null||s.updateColor(e);break;case ut.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:{type:"highlight",action:"toggle_visibility"}}}),(l(this,gl)||v(this,gl,new Map)).set(t,e),this.showAllEditors("highlight",e);break}for(const i of l(this,wt))i.updateParams(t,e);for(const i of l(this,si))i.updateDefaultParams(t,e)}}showAllEditors(t,e,s=!1){var n;for(const r of l(this,ae).values())r.editorType===t&&r.show(e);(((n=l(this,gl))==null?void 0:n.get(ut.HIGHLIGHT_SHOW_ALL))??!0)!==e&&_(this,B,Rn).call(this,[[ut.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(l(this,cl)!==t){v(this,cl,t);for(const e of l(this,me).values())t?e.disableClick():e.enableClick(),e.div.classList.toggle("waiting",t)}}getEditors(t){const e=[];for(const s of l(this,ae).values())s.pageIndex===t&&e.push(s);return e}getEditor(t){return l(this,ae).get(t)}addEditor(t){l(this,ae).set(t.id,t)}removeEditor(t){var e;t.div.contains(document.activeElement)&&(l(this,Ai)&&clearTimeout(l(this,Ai)),v(this,Ai,setTimeout(()=>{this.focusMainContainer(),v(this,Ai,null)},0))),l(this,ae).delete(t.id),this.unselect(t),(!t.annotationElementId||!l(this,Yr).has(t.annotationElementId))&&((e=l(this,hn))==null||e.remove(t.id))}addDeletedAnnotationElement(t){l(this,Yr).add(t.annotationElementId),this.addChangedExistingAnnotation(t),t.deleted=!0}isDeletedAnnotationElement(t){return l(this,Yr).has(t)}removeDeletedAnnotationElement(t){l(this,Yr).delete(t.annotationElementId),this.removeChangedExistingAnnotation(t),t.deleted=!1}setActiveEditor(t){l(this,ds)!==t&&(v(this,ds,t),t&&_(this,B,Rn).call(this,t.propertiesToUpdate))}updateUI(t){l(this,B,Cb)===t&&_(this,B,Rn).call(this,t.propertiesToUpdate)}updateUIForDefaultProperties(t){_(this,B,Rn).call(this,t.defaultPropertiesToUpdate)}toggleSelected(t){if(l(this,wt).has(t)){l(this,wt).delete(t),t.unselect(),_(this,B,Qe).call(this,{hasSelectedEditor:this.hasSelection});return}l(this,wt).add(t),t.select(),_(this,B,Rn).call(this,t.propertiesToUpdate),_(this,B,Qe).call(this,{hasSelectedEditor:!0})}setSelected(t){var e;(e=this.currentLayer)==null||e.commitOrRemove();for(const s of l(this,wt))s!==t&&s.unselect();l(this,wt).clear(),l(this,wt).add(t),t.select(),_(this,B,Rn).call(this,t.propertiesToUpdate),_(this,B,Qe).call(this,{hasSelectedEditor:!0})}isSelected(t){return l(this,wt).has(t)}get firstSelectedEditor(){return l(this,wt).values().next().value}unselect(t){t.unselect(),l(this,wt).delete(t),_(this,B,Qe).call(this,{hasSelectedEditor:this.hasSelection})}get hasSelection(){return l(this,wt).size!==0}get isEnterHandled(){return l(this,wt).size===1&&this.firstSelectedEditor.isEnterHandled}undo(){l(this,Ps).undo(),_(this,B,Qe).call(this,{hasSomethingToUndo:l(this,Ps).hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:_(this,B,xc).call(this)})}redo(){l(this,Ps).redo(),_(this,B,Qe).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:l(this,Ps).hasSomethingToRedo(),isEmpty:_(this,B,xc).call(this)})}addCommands(t){l(this,Ps).add(t),_(this,B,Qe).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:_(this,B,xc).call(this)})}cleanUndoStack(t){l(this,Ps).cleanType(t)}delete(){var n;this.commitOrRemove();const t=(n=this.currentLayer)==null?void 0:n.endDrawingSession(!0);if(!this.hasSelection&&!t)return;const e=t?[t]:[...l(this,wt)],s=()=>{for(const r of e)r.remove()},i=()=>{for(const r of e)_(this,B,ep).call(this,r)};this.addCommands({cmd:s,undo:i,mustExec:!0})}commitOrRemove(){var t;(t=l(this,ds))==null||t.commitOrRemove()}hasSomethingToControl(){return l(this,ds)||this.hasSelection}selectAll(){for(const t of l(this,wt))t.commit();_(this,B,sp).call(this,l(this,ae).values())}unselectAll(){var t;if(!(l(this,ds)&&(l(this,ds).commitOrRemove(),l(this,ue)!==nt.NONE))&&!((t=this.currentLayer)!=null&&t.commitOrRemove())&&this.hasSelection){for(const e of l(this,wt))e.unselect();l(this,wt).clear(),_(this,B,Qe).call(this,{hasSelectedEditor:!1})}}translateSelectedEditors(t,e,s=!1){if(s||this.commitOrRemove(),!this.hasSelection)return;l(this,tr)[0]+=t,l(this,tr)[1]+=e;const[i,n]=l(this,tr),r=[...l(this,wt)],o=1e3;l(this,Ei)&&clearTimeout(l(this,Ei)),v(this,Ei,setTimeout(()=>{v(this,Ei,null),l(this,tr)[0]=l(this,tr)[1]=0,this.addCommands({cmd:()=>{for(const h of r)l(this,ae).has(h.id)&&h.translateInPage(i,n)},undo:()=>{for(const h of r)l(this,ae).has(h.id)&&h.translateInPage(-i,-n)},mustExec:!1})},o));for(const h of r)h.translateInPage(t,e)}setUpDragSession(){if(this.hasSelection){this.disableUserSelect(!0),v(this,Ci,new Map);for(const t of l(this,wt))l(this,Ci).set(t,{savedX:t.x,savedY:t.y,savedPageIndex:t.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!l(this,Ci))return!1;this.disableUserSelect(!1);const t=l(this,Ci);v(this,Ci,null);let e=!1;for(const[{x:i,y:n,pageIndex:r},o]of t)o.newX=i,o.newY=n,o.newPageIndex=r,e||(e=i!==o.savedX||n!==o.savedY||r!==o.savedPageIndex);if(!e)return!1;const s=(i,n,r,o)=>{if(l(this,ae).has(i.id)){const h=l(this,me).get(o);h?i._setParentAndPosition(h,n,r):(i.pageIndex=o,i.x=n,i.y=r)}};return this.addCommands({cmd:()=>{for(const[i,{newX:n,newY:r,newPageIndex:o}]of t)s(i,n,r,o)},undo:()=>{for(const[i,{savedX:n,savedY:r,savedPageIndex:o}]of t)s(i,n,r,o)},mustExec:!0}),!0}dragSelectedEditors(t,e){if(l(this,Ci))for(const s of l(this,Ci).keys())s.drag(t,e)}rebuild(t){if(t.parent===null){const e=this.getLayer(t.pageIndex);e?(e.changeParent(t),e.addOrRebuild(t)):(this.addEditor(t),this.addToAnnotationStorage(t),t.rebuild())}else t.parent.addOrRebuild(t)}get isEditorHandlingKeyboard(){var t;return((t=this.getActive())==null?void 0:t.shouldGetKeyboardEvents())||l(this,wt).size===1&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(t){return l(this,ds)===t}getActive(){return l(this,ds)}getMode(){return l(this,ue)}get imageManager(){return at(this,"imageManager",new gf)}getSelectionBoxes(t){if(!t)return null;const e=document.getSelection();for(let c=0,u=e.rangeCount;c<u;c++)if(!t.contains(e.getRangeAt(c).commonAncestorContainer))return null;const{x:s,y:i,width:n,height:r}=t.getBoundingClientRect();let o;switch(t.getAttribute("data-main-rotation")){case"90":o=(c,u,d,g)=>({x:(u-i)/r,y:1-(c+d-s)/n,width:g/r,height:d/n});break;case"180":o=(c,u,d,g)=>({x:1-(c+d-s)/n,y:1-(u+g-i)/r,width:d/n,height:g/r});break;case"270":o=(c,u,d,g)=>({x:1-(u+g-i)/r,y:(c-s)/n,width:g/r,height:d/n});break;default:o=(c,u,d,g)=>({x:(c-s)/n,y:(u-i)/r,width:d/n,height:g/r});break}const h=[];for(let c=0,u=e.rangeCount;c<u;c++){const d=e.getRangeAt(c);if(!d.collapsed)for(const{x:g,y:f,width:p,height:m}of d.getClientRects())p===0||m===0||h.push(o(g,f,p,m))}return h.length===0?null:h}addChangedExistingAnnotation({annotationElementId:t,id:e}){(l(this,fa)||v(this,fa,new Map)).set(t,e)}removeChangedExistingAnnotation({annotationElementId:t}){var e;(e=l(this,fa))==null||e.delete(t)}renderAnnotationElement(t){var i;const e=(i=l(this,fa))==null?void 0:i.get(t.data.id);if(!e)return;const s=l(this,hn).getRawValue(e);s&&(l(this,ue)===nt.NONE&&!s.hasBeenModified||s.renderAnnotationElement(t))}};da=new WeakMap,ds=new WeakMap,ae=new WeakMap,me=new WeakMap,ga=new WeakMap,hn=new WeakMap,fa=new WeakMap,Ps=new WeakMap,qn=new WeakMap,pa=new WeakMap,Yr=new WeakMap,Ci=new WeakMap,si=new WeakMap,$r=new WeakMap,al=new WeakMap,hl=new WeakMap,ma=new WeakMap,ll=new WeakMap,Ai=new WeakMap,Kn=new WeakMap,va=new WeakMap,Qn=new WeakMap,Ti=new WeakMap,hd=new WeakMap,Jn=new WeakMap,cl=new WeakMap,Zn=new WeakMap,qr=new WeakMap,ul=new WeakMap,dl=new WeakMap,ue=new WeakMap,wt=new WeakMap,ln=new WeakMap,Kr=new WeakMap,gl=new WeakMap,fl=new WeakMap,tr=new WeakMap,Ei=new WeakMap,cn=new WeakMap,pl=new WeakMap,Os=new WeakMap,B=new WeakSet,kd=function({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t},Qf=function(t){const{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(const s of l(this,me).values())if(s.hasTextLayer(t))return s;return null},pb=function(){const t=document.getSelection();if(!t||t.isCollapsed)return;const s=_(this,B,kd).call(this,t).closest(".textLayer"),i=this.getSelectionBoxes(s);i&&(l(this,Ti)||v(this,Ti,new Vx(this)),l(this,Ti).show(s,i,this.direction==="ltr"))},mb=function(){var n,r,o;const t=document.getSelection();if(!t||t.isCollapsed){l(this,ln)&&((n=l(this,Ti))==null||n.hide(),v(this,ln,null),_(this,B,Qe).call(this,{hasSelectedText:!1}));return}const{anchorNode:e}=t;if(e===l(this,ln))return;const i=_(this,B,kd).call(this,t).closest(".textLayer");if(!i){l(this,ln)&&((r=l(this,Ti))==null||r.hide(),v(this,ln,null),_(this,B,Qe).call(this,{hasSelectedText:!1}));return}if((o=l(this,Ti))==null||o.hide(),v(this,ln,e),_(this,B,Qe).call(this,{hasSelectedText:!0}),!(l(this,ue)!==nt.HIGHLIGHT&&l(this,ue)!==nt.NONE)&&(l(this,ue)===nt.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0),v(this,Qn,this.isShiftKeyDown),!this.isShiftKeyDown)){const h=l(this,ue)===nt.HIGHLIGHT?_(this,B,Qf).call(this,i):null;h==null||h.toggleDrawing();const c=new AbortController,u=this.combinedSignal(c),d=g=>{g.type==="pointerup"&&g.button!==0||(c.abort(),h==null||h.toggleDrawing(!0),g.type==="pointerup"&&_(this,B,Md).call(this,"main_toolbar"))};window.addEventListener("pointerup",d,{signal:u}),window.addEventListener("blur",d,{signal:u})}},Md=function(t=""){l(this,ue)===nt.HIGHLIGHT?this.highlightSelection(t):l(this,al)&&_(this,B,pb).call(this)},vb=function(){document.addEventListener("selectionchange",_(this,B,mb).bind(this),{signal:this._signal})},bb=function(){if(l(this,Kn))return;v(this,Kn,new AbortController);const t=this.combinedSignal(l(this,Kn));window.addEventListener("focus",this.focus.bind(this),{signal:t}),window.addEventListener("blur",this.blur.bind(this),{signal:t})},yb=function(){var t;(t=l(this,Kn))==null||t.abort(),v(this,Kn,null)},Jf=function(){if(l(this,Zn))return;v(this,Zn,new AbortController);const t=this.combinedSignal(l(this,Zn));window.addEventListener("keydown",this.keydown.bind(this),{signal:t}),window.addEventListener("keyup",this.keyup.bind(this),{signal:t})},_b=function(){var t;(t=l(this,Zn))==null||t.abort(),v(this,Zn,null)},Zf=function(){if(l(this,qn))return;v(this,qn,new AbortController);const t=this.combinedSignal(l(this,qn));document.addEventListener("copy",this.copy.bind(this),{signal:t}),document.addEventListener("cut",this.cut.bind(this),{signal:t}),document.addEventListener("paste",this.paste.bind(this),{signal:t})},tp=function(){var t;(t=l(this,qn))==null||t.abort(),v(this,qn,null)},wb=function(){const t=this._signal;document.addEventListener("dragover",this.dragOver.bind(this),{signal:t}),document.addEventListener("drop",this.drop.bind(this),{signal:t})},Qe=function(t){Object.entries(t).some(([s,i])=>l(this,fl)[s]!==i)&&(this._eventBus.dispatch("annotationeditorstateschanged",{source:this,details:Object.assign(l(this,fl),t)}),l(this,ue)===nt.HIGHLIGHT&&t.hasSelectedEditor===!1&&_(this,B,Rn).call(this,[[ut.HIGHLIGHT_FREE,!0]]))},Rn=function(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})},xb=async function(){if(!l(this,Jn)){v(this,Jn,!0);const t=[];for(const e of l(this,me).values())t.push(e.enable());await Promise.all(t);for(const e of l(this,ae).values())e.enable()}},Sb=function(){if(this.unselectAll(),l(this,Jn)){v(this,Jn,!1);for(const t of l(this,me).values())t.disable();for(const t of l(this,ae).values())t.disable()}},ep=function(t){const e=l(this,me).get(t.pageIndex);e?e.addOrRebuild(t):(this.addEditor(t),this.addToAnnotationStorage(t))},Cb=function(){let t=null;for(t of l(this,wt));return t},xc=function(){if(l(this,ae).size===0)return!0;if(l(this,ae).size===1)for(const t of l(this,ae).values())return t.isEmpty();return!1},sp=function(t){for(const e of l(this,wt))e.unselect();l(this,wt).clear();for(const e of t)e.isEmpty()||(l(this,wt).add(e),e.select());_(this,B,Qe).call(this,{hasSelectedEditor:this.hasSelection})},q(ba,"TRANSLATE_SMALL",1),q(ba,"TRANSLATE_BIG",10);let Br=ba;const ze=class ze{constructor(t){w(this,ni);w(this,de,null);w(this,ki,!1);w(this,ii,null);w(this,ya,null);w(this,Mi,null);w(this,gs,null);w(this,_a,!1);w(this,Pi,null);w(this,ss,null);w(this,un,null);w(this,Qr,null);w(this,Oi,!1);v(this,ss,t),v(this,Oi,t._uiManager.useNewAltTextFlow),l(ze,er)||v(ze,er,Object.freeze({added:"pdfjs-editor-new-alt-text-added-button","added-label":"pdfjs-editor-new-alt-text-added-button-label",missing:"pdfjs-editor-new-alt-text-missing-button","missing-label":"pdfjs-editor-new-alt-text-missing-button-label",review:"pdfjs-editor-new-alt-text-to-review-button","review-label":"pdfjs-editor-new-alt-text-to-review-button-label"}))}static initialize(t){ze._l10n??(ze._l10n=t)}async render(){const t=v(this,ii,document.createElement("button"));t.className="altText",t.tabIndex="0";const e=v(this,ya,document.createElement("span"));t.append(e),l(this,Oi)?(t.classList.add("new"),t.setAttribute("data-l10n-id",l(ze,er).missing),e.setAttribute("data-l10n-id",l(ze,er)["missing-label"])):(t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button"),e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button-label"));const s=l(this,ss)._uiManager._signal;t.addEventListener("contextmenu",Zs,{signal:s}),t.addEventListener("pointerdown",n=>n.stopPropagation(),{signal:s});const i=n=>{n.preventDefault(),l(this,ss)._uiManager.editAltText(l(this,ss)),l(this,Oi)&&l(this,ss)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_clicked",data:{label:l(this,ni,Sc)}})};return t.addEventListener("click",i,{capture:!0,signal:s}),t.addEventListener("keydown",n=>{n.target===t&&n.key==="Enter"&&(v(this,_a,!0),i(n))},{signal:s}),await _(this,ni,Pd).call(this),t}finish(){l(this,ii)&&(l(this,ii).focus({focusVisible:l(this,_a)}),v(this,_a,!1))}isEmpty(){return l(this,Oi)?l(this,de)===null:!l(this,de)&&!l(this,ki)}hasData(){return l(this,Oi)?l(this,de)!==null||!!l(this,un):this.isEmpty()}get guessedText(){return l(this,un)}async setGuessedText(t){l(this,de)===null&&(v(this,un,t),v(this,Qr,await ze._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",{generatedAltText:t})),_(this,ni,Pd).call(this))}toggleAltTextBadge(t=!1){var e;if(!l(this,Oi)||l(this,de)){(e=l(this,Pi))==null||e.remove(),v(this,Pi,null);return}if(!l(this,Pi)){const s=v(this,Pi,document.createElement("div"));s.className="noAltTextBadge",l(this,ss).div.append(s)}l(this,Pi).classList.toggle("hidden",!t)}serialize(t){let e=l(this,de);return!t&&l(this,un)===e&&(e=l(this,Qr)),{altText:e,decorative:l(this,ki),guessedText:l(this,un),textWithDisclaimer:l(this,Qr)}}get data(){return{altText:l(this,de),decorative:l(this,ki)}}set data({altText:t,decorative:e,guessedText:s,textWithDisclaimer:i,cancel:n=!1}){s&&(v(this,un,s),v(this,Qr,i)),!(l(this,de)===t&&l(this,ki)===e)&&(n||(v(this,de,t),v(this,ki,e)),_(this,ni,Pd).call(this))}toggle(t=!1){l(this,ii)&&(!t&&l(this,gs)&&(clearTimeout(l(this,gs)),v(this,gs,null)),l(this,ii).disabled=!t)}shown(){l(this,ss)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_displayed",data:{label:l(this,ni,Sc)}})}destroy(){var t,e;(t=l(this,ii))==null||t.remove(),v(this,ii,null),v(this,ya,null),v(this,Mi,null),(e=l(this,Pi))==null||e.remove(),v(this,Pi,null)}};de=new WeakMap,ki=new WeakMap,ii=new WeakMap,ya=new WeakMap,Mi=new WeakMap,gs=new WeakMap,_a=new WeakMap,Pi=new WeakMap,ss=new WeakMap,un=new WeakMap,Qr=new WeakMap,Oi=new WeakMap,er=new WeakMap,ni=new WeakSet,Sc=function(){return l(this,de)&&"added"||l(this,de)===null&&this.guessedText&&"review"||"missing"},Pd=async function(){var i,n,r;const t=l(this,ii);if(!t)return;if(l(this,Oi)){if(t.classList.toggle("done",!!l(this,de)),t.setAttribute("data-l10n-id",l(ze,er)[l(this,ni,Sc)]),(i=l(this,ya))==null||i.setAttribute("data-l10n-id",l(ze,er)[`${l(this,ni,Sc)}-label`]),!l(this,de)){(n=l(this,Mi))==null||n.remove();return}}else{if(!l(this,de)&&!l(this,ki)){t.classList.remove("done"),(r=l(this,Mi))==null||r.remove();return}t.classList.add("done"),t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-edit-button")}let e=l(this,Mi);if(!e){v(this,Mi,e=document.createElement("span")),e.className="tooltip",e.setAttribute("role","tooltip"),e.id=`alt-text-tooltip-${l(this,ss).id}`;const o=100,h=l(this,ss)._uiManager._signal;h.addEventListener("abort",()=>{clearTimeout(l(this,gs)),v(this,gs,null)},{once:!0}),t.addEventListener("mouseenter",()=>{v(this,gs,setTimeout(()=>{v(this,gs,null),l(this,Mi).classList.add("show"),l(this,ss)._reportTelemetry({action:"alt_text_tooltip"})},o))},{signal:h}),t.addEventListener("mouseleave",()=>{var c;l(this,gs)&&(clearTimeout(l(this,gs)),v(this,gs,null)),(c=l(this,Mi))==null||c.classList.remove("show")},{signal:h})}l(this,ki)?e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-decorative-tooltip"):(e.removeAttribute("data-l10n-id"),e.textContent=l(this,de)),e.parentNode||t.append(e);const s=l(this,ss).getImageForAltText();s==null||s.setAttribute("aria-describedby",e.id)},w(ze,er,null),q(ze,"_l10n",null);let Uu=ze;const bt=class bt{constructor(t){w(this,et);w(this,Jr,null);w(this,ri,null);w(this,Vt,null);w(this,wa,!1);w(this,sr,null);w(this,ml,"");w(this,Zr,!1);w(this,ve,null);w(this,to,null);w(this,ir,null);w(this,nr,null);w(this,vl,"");w(this,eo,!1);w(this,rr,null);w(this,bl,!1);w(this,so,!1);w(this,dn,!1);w(this,Di,null);w(this,xa,0);w(this,Sa,0);w(this,Ds,null);q(this,"_editToolbar",null);q(this,"_initialOptions",Object.create(null));q(this,"_initialData",null);q(this,"_isVisible",!0);q(this,"_uiManager",null);q(this,"_focusEventsAllowed",!0);w(this,yl,!1);w(this,ld,bt._zIndex++);this.parent=t.parent,this.id=t.id,this.width=this.height=null,this.pageIndex=t.parent.pageIndex,this.name=t.name,this.div=null,this._uiManager=t.uiManager,this.annotationElementId=null,this._willKeepAspectRatio=!1,this._initialOptions.isCentered=t.isCentered,this._structTreeParentId=null;const{rotation:e,rawDims:{pageWidth:s,pageHeight:i,pageX:n,pageY:r}}=this.parent.viewport;this.rotation=e,this.pageRotation=(360+e-this._uiManager.viewParameters.rotation)%360,this.pageDimensions=[s,i],this.pageTranslation=[n,r];const[o,h]=this.parentDimensions;this.x=t.x/o,this.y=t.y/h,this.isAttachedToDOM=!1,this.deleted=!1}static get _resizerKeyboardManager(){const t=bt.prototype._resizeWithKeyboard,e=Br.TRANSLATE_SMALL,s=Br.TRANSLATE_BIG;return at(this,"_resizerKeyboardManager",new $h([[["ArrowLeft","mac+ArrowLeft"],t,{args:[-e,0]}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t,{args:[-s,0]}],[["ArrowRight","mac+ArrowRight"],t,{args:[e,0]}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t,{args:[s,0]}],[["ArrowUp","mac+ArrowUp"],t,{args:[0,-e]}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t,{args:[0,-s]}],[["ArrowDown","mac+ArrowDown"],t,{args:[0,e]}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t,{args:[0,s]}],[["Escape","mac+Escape"],bt.prototype._stopResizingWithKeyboard]]))}get editorType(){return Object.getPrototypeOf(this).constructor._type}static get isDrawer(){return!1}static get _defaultLineColor(){return at(this,"_defaultLineColor",this._colorManager.getHexCode("CanvasText"))}static deleteAnnotationElement(t){const e=new zx({id:t.parent.getNextId(),parent:t.parent,uiManager:t._uiManager});e.annotationElementId=t.annotationElementId,e.deleted=!0,e._uiManager.addToAnnotationStorage(e)}static initialize(t,e){if(bt._l10n??(bt._l10n=t),bt._l10nResizer||(bt._l10nResizer=Object.freeze({topLeft:"pdfjs-editor-resizer-top-left",topMiddle:"pdfjs-editor-resizer-top-middle",topRight:"pdfjs-editor-resizer-top-right",middleRight:"pdfjs-editor-resizer-middle-right",bottomRight:"pdfjs-editor-resizer-bottom-right",bottomMiddle:"pdfjs-editor-resizer-bottom-middle",bottomLeft:"pdfjs-editor-resizer-bottom-left",middleLeft:"pdfjs-editor-resizer-middle-left"})),bt._borderLineWidth!==-1)return;const s=getComputedStyle(document.documentElement);bt._borderLineWidth=parseFloat(s.getPropertyValue("--outline-width"))||0}static updateDefaultParams(t,e){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(t){return!1}static paste(t,e){St("Not implemented")}get propertiesToUpdate(){return[]}get _isDraggable(){return l(this,yl)}set _isDraggable(t){var e;v(this,yl,t),(e=this.div)==null||e.classList.toggle("draggable",t)}get isEnterHandled(){return!0}center(){const[t,e]=this.pageDimensions;switch(this.parentRotation){case 90:this.x-=this.height*e/(t*2),this.y+=this.width*t/(e*2);break;case 180:this.x+=this.width/2,this.y+=this.height/2;break;case 270:this.x+=this.height*e/(t*2),this.y-=this.width*t/(e*2);break;default:this.x-=this.width/2,this.y-=this.height/2;break}this.fixAndSetPosition()}addCommands(t){this._uiManager.addCommands(t)}get currentLayer(){return this._uiManager.currentLayer}setInBackground(){this.div.style.zIndex=0}setInForeground(){this.div.style.zIndex=l(this,ld)}setParent(t){t!==null?(this.pageIndex=t.pageIndex,this.pageDimensions=t.pageDimensions):_(this,et,Cc).call(this),this.parent=t}focusin(t){this._focusEventsAllowed&&(l(this,eo)?v(this,eo,!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){_(this,et,ip).call(this,this.parentDimensions,t,e)}translateInPage(t,e){l(this,rr)||v(this,rr,[this.x,this.y]),_(this,et,ip).call(this,this.pageDimensions,t,e),this.div.scrollIntoView({block:"nearest"})}drag(t,e){l(this,rr)||v(this,rr,[this.x,this.y]);const{div:s,parentDimensions:[i,n]}=this;if(this.x+=t/i,this.y+=e/n,this.parent&&(this.x<0||this.x>1||this.y<0||this.y>1)){const{x:d,y:g}=this.div.getBoundingClientRect();this.parent.findNewParent(this,d,g)&&(this.x-=Math.floor(this.x),this.y-=Math.floor(this.y))}let{x:r,y:o}=this;const[h,c]=this.getBaseTranslation();r+=h,o+=c;const{style:u}=s;u.left=`${(100*r).toFixed(2)}%`,u.top=`${(100*o).toFixed(2)}%`,this._onTranslating(r,o),s.scrollIntoView({block:"nearest"})}_onTranslating(t,e){}_onTranslated(t,e){}get _hasBeenMoved(){return!!l(this,rr)&&(l(this,rr)[0]!==this.x||l(this,rr)[1]!==this.y)}getBaseTranslation(){const[t,e]=this.parentDimensions,{_borderLineWidth:s}=bt,i=s/t,n=s/e;switch(this.rotation){case 90:return[-i,n];case 180:return[i,n];case 270:return[i,-n];default:return[-i,-n]}}get _mustFixPosition(){return!0}fixAndSetPosition(t=this.rotation){const{div:{style:e},pageDimensions:[s,i]}=this;let{x:n,y:r,width:o,height:h}=this;if(o*=s,h*=i,n*=s,r*=i,this._mustFixPosition)switch(t){case 0:n=Math.max(0,Math.min(s-o,n)),r=Math.max(0,Math.min(i-h,r));break;case 90:n=Math.max(0,Math.min(s-h,n)),r=Math.min(i,Math.max(o,r));break;case 180:n=Math.min(s,Math.max(o,n)),r=Math.min(i,Math.max(h,r));break;case 270:n=Math.min(s,Math.max(h,n)),r=Math.max(0,Math.min(i-o,r));break}this.x=n/=s,this.y=r/=i;const[c,u]=this.getBaseTranslation();n+=c,r+=u,e.left=`${(100*n).toFixed(2)}%`,e.top=`${(100*r).toFixed(2)}%`,this.moveInDOM()}screenToPageTranslation(t,e){var s;return _(s=bt,_l,np).call(s,t,e,this.parentRotation)}pageTranslationToScreen(t,e){var s;return _(s=bt,_l,np).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,Zr)||(n.height=`${(100*e/i).toFixed(2)}%`)}fixDims(){const{style:t}=this.div,{height:e,width:s}=t,i=s.endsWith("%"),n=!l(this,Zr)&&e.endsWith("%");if(i&&n)return;const[r,o]=this.parentDimensions;i||(t.width=`${(100*parseFloat(s)/r).toFixed(2)}%`),!l(this,Zr)&&!n&&(t.height=`${(100*parseFloat(e)/o).toFixed(2)}%`)}getInitialTranslation(){return[0,0]}_onResized(){}_onResizing(){}altTextFinish(){var t;(t=l(this,Vt))==null||t.finish()}async addEditToolbar(){return this._editToolbar||l(this,so)?this._editToolbar:(this._editToolbar=new df(this),this.div.append(this._editToolbar.render()),l(this,Vt)&&await this._editToolbar.addAltText(l(this,Vt)),this._editToolbar)}removeEditToolbar(){var t;this._editToolbar&&(this._editToolbar.remove(),this._editToolbar=null,(t=l(this,Vt))==null||t.destroy())}addContainer(t){var s;const e=(s=this._editToolbar)==null?void 0:s.div;e?e.before(t):this.div.append(t)}getClientDimensions(){return this.div.getBoundingClientRect()}async addAltTextButton(){l(this,Vt)||(Uu.initialize(bt._l10n),v(this,Vt,new Uu(this)),l(this,Jr)&&(l(this,Vt).data=l(this,Jr),v(this,Jr,null)),await this.addEditToolbar())}get altTextData(){var t;return(t=l(this,Vt))==null?void 0:t.data}set altTextData(t){l(this,Vt)&&(l(this,Vt).data=t)}get guessedAltText(){var t;return(t=l(this,Vt))==null?void 0:t.guessedText}async setGuessedAltText(t){var e;await((e=l(this,Vt))==null?void 0:e.setGuessedText(t))}serializeAltText(t){var e;return(e=l(this,Vt))==null?void 0:e.serialize(t)}hasAltText(){return!!l(this,Vt)&&!l(this,Vt).isEmpty()}hasAltTextData(){var t;return((t=l(this,Vt))==null?void 0:t.hasData())??!1}render(){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,wa)?-1:0,this._isVisible||this.div.classList.add("hidden"),this.setInForeground(),_(this,et,cp).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),Xu(this,this.div,["pointerdown"]),this.div}pointerdown(t){const{isMac:e}=Ge.platform;if(t.button!==0||t.ctrlKey&&e){t.preventDefault();return}if(v(this,eo,!0),this._isDraggable){_(this,et,Eb).call(this,t);return}_(this,et,lp).call(this,t)}get isSelected(){return this._uiManager.isSelected(this)}_onStartDragging(){}_onStopDragging(){}moveInDOM(){l(this,Di)&&clearTimeout(l(this,Di)),v(this,Di,setTimeout(()=>{var t;v(this,Di,null),(t=this.parent)==null||t.moveEditorInDOM(this)},0))}_setParentAndPosition(t,e,s){t.changeParent(this),this.x=e,this.y=s,this.fixAndSetPosition(),this._onTranslated()}getRect(t,e,s=this.rotation){const i=this.parentScale,[n,r]=this.pageDimensions,[o,h]=this.pageTranslation,c=t/i,u=e/i,d=this.x*n,g=this.y*r,f=this.width*n,p=this.height*r;switch(s){case 0:return[d+c+o,r-g-u-p+h,d+c+f+o,r-g-u+h];case 90:return[d+u+o,r-g+c+h,d+u+p+o,r-g+c+f+h];case 180:return[d-c-f+o,r-g+u+h,d-c+o,r-g+u+p+h];case 270:return[d-u-p+o,r-g-c-f+h,d-u+o,r-g-c+h];default:throw new Error("Invalid rotation")}}getRectInCurrentCoords(t,e){const[s,i,n,r]=t,o=n-s,h=r-i;switch(this.rotation){case 0:return[s,e-r,o,h];case 90:return[s,e-i,h,o];case 180:return[n,e-i,o,h];case 270:return[n,e-r,h,o];default:throw new Error("Invalid rotation")}}onceAdded(){}isEmpty(){return!1}enableEditMode(){v(this,so,!0)}disableEditMode(){v(this,so,!1)}isInEditMode(){return l(this,so)}shouldGetKeyboardEvents(){return l(this,dn)}needsToBeRebuilt(){return this.div&&!this.isAttachedToDOM}rebuild(){_(this,et,cp).call(this)}rotate(t){}resize(){}serializeDeleted(){var t;return{id:this.annotationElementId,deleted:!0,pageIndex:this.pageIndex,popupRef:((t=this._initialData)==null?void 0:t.popupRef)||""}}serialize(t=!1,e=null){St("An editor must be serializable")}static async deserialize(t,e,s){const i=new this.prototype.constructor({parent:e,id:e.getNextId(),uiManager:s});i.rotation=t.rotation,v(i,Jr,t.accessibilityData);const[n,r]=i.pageDimensions,[o,h,c,u]=i.getRectInCurrentCoords(t.rect,r);return i.x=o/n,i.y=h/r,i.width=c/n,i.height=u/r,i}get hasBeenModified(){return!!this.annotationElementId&&(this.deleted||this.serialize()!==null)}remove(){var t;if((t=l(this,nr))==null||t.abort(),v(this,nr,null),this.isEmpty()||this.commit(),this.parent?this.parent.remove(this):this._uiManager.removeEditor(this),l(this,Di)&&(clearTimeout(l(this,Di)),v(this,Di,null)),_(this,et,Cc).call(this),this.removeEditToolbar(),l(this,Ds)){for(const e of l(this,Ds).values())clearTimeout(e);v(this,Ds,null)}this.parent=null}get isResizable(){return!1}makeResizable(){this.isResizable&&(_(this,et,Ab).call(this),l(this,ve).classList.remove("hidden"),Xu(this,this.div,["keydown"]))}get toolbarPosition(){return null}keydown(t){if(!this.isResizable||t.target!==this.div||t.key!=="Enter")return;this._uiManager.setSelected(this),v(this,ir,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height});const e=l(this,ve).children;if(!l(this,ri)){v(this,ri,Array.from(e));const r=_(this,et,kb).bind(this),o=_(this,et,Mb).bind(this),h=this._uiManager._signal;for(const c of l(this,ri)){const u=c.getAttribute("data-resizer-name");c.setAttribute("role","spinbutton"),c.addEventListener("keydown",r,{signal:h}),c.addEventListener("blur",o,{signal:h}),c.addEventListener("focus",_(this,et,Pb).bind(this,u),{signal:h}),c.setAttribute("data-l10n-id",bt._l10nResizer[u])}}const s=l(this,ri)[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,ri).length/4);if(n!==i){if(n<i)for(let o=0;o<i-n;o++)l(this,ve).append(l(this,ve).firstChild);else if(n>i)for(let o=0;o<n-i;o++)l(this,ve).firstChild.before(l(this,ve).lastChild);let r=0;for(const o of e){const c=l(this,ri)[r++].getAttribute("data-resizer-name");o.setAttribute("data-l10n-id",bt._l10nResizer[c])}}_(this,et,up).call(this,0),v(this,dn,!0),l(this,ve).firstChild.focus({focusVisible:!0}),t.preventDefault(),t.stopImmediatePropagation()}_resizeWithKeyboard(t,e){l(this,dn)&&_(this,et,hp).call(this,l(this,vl),{deltaX:t,deltaY:e,fromKeyboard:!0})}_stopResizingWithKeyboard(){_(this,et,Cc).call(this),this.div.focus()}select(){var t,e,s;if(this.makeResizable(),(t=this.div)==null||t.classList.add("selectedEditor"),!this._editToolbar){this.addEditToolbar().then(()=>{var i,n;(i=this.div)!=null&&i.classList.contains("selectedEditor")&&((n=this._editToolbar)==null||n.show())});return}(e=this._editToolbar)==null||e.show(),(s=l(this,Vt))==null||s.toggleAltTextBadge(!1)}unselect(){var t,e,s,i,n;(t=l(this,ve))==null||t.classList.add("hidden"),(e=this.div)==null||e.classList.remove("selectedEditor"),(s=this.div)!=null&&s.contains(document.activeElement)&&this._uiManager.currentLayer.div.focus({preventScroll:!0}),(i=this._editToolbar)==null||i.hide(),(n=l(this,Vt))==null||n.toggleAltTextBadge(!0)}updateParams(t,e){}disableEditing(){}enableEditing(){}enterInEditMode(){}getImageForAltText(){return null}get contentDiv(){return this.div}get isEditing(){return l(this,bl)}set isEditing(t){v(this,bl,t),this.parent&&(t?(this.parent.setSelected(this),this.parent.setActiveEditor(this)):this.parent.setActiveEditor(null))}setAspectRatio(t,e){v(this,Zr,!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,Ds)||v(this,Ds,new Map);const{action:s}=t;let i=l(this,Ds).get(s);i&&clearTimeout(i),i=setTimeout(()=>{this._reportTelemetry(t),l(this,Ds).delete(s),l(this,Ds).size===0&&v(this,Ds,null)},bt._telemetryTimeout),l(this,Ds).set(s,i);return}t.type||(t.type=this.editorType),this._uiManager._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:t}})}show(t=this._isVisible){this.div.classList.toggle("hidden",!t),this._isVisible=t}enable(){this.div&&(this.div.tabIndex=0),v(this,wa,!1)}disable(){this.div&&(this.div.tabIndex=-1),v(this,wa,!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()}};Jr=new WeakMap,ri=new WeakMap,Vt=new WeakMap,wa=new WeakMap,sr=new WeakMap,ml=new WeakMap,Zr=new WeakMap,ve=new WeakMap,to=new WeakMap,ir=new WeakMap,nr=new WeakMap,vl=new WeakMap,eo=new WeakMap,rr=new WeakMap,bl=new WeakMap,so=new WeakMap,dn=new WeakMap,Di=new WeakMap,xa=new WeakMap,Sa=new WeakMap,Ds=new WeakMap,yl=new WeakMap,ld=new WeakMap,et=new WeakSet,ip=function([t,e],s,i){[s,i]=this.screenToPageTranslation(s,i),this.x+=s/t,this.y+=i/e,this._onTranslating(this.x,this.y),this.fixAndSetPosition()},_l=new WeakSet,np=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]}},rp=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]}},Ab=function(){if(l(this,ve))return;v(this,ve,document.createElement("div")),l(this,ve).classList.add("resizers");const t=this._willKeepAspectRatio?["topLeft","topRight","bottomRight","bottomLeft"]:["topLeft","topMiddle","topRight","middleRight","bottomRight","bottomMiddle","bottomLeft","middleLeft"],e=this._uiManager._signal;for(const s of t){const i=document.createElement("div");l(this,ve).append(i),i.classList.add("resizer",s),i.setAttribute("data-resizer-name",s),i.addEventListener("pointerdown",_(this,et,Tb).bind(this,s),{signal:e}),i.addEventListener("contextmenu",Zs,{signal:e}),i.tabIndex=-1}this.div.prepend(l(this,ve))},Tb=function(t,e){var u;e.preventDefault();const{isMac:s}=Ge.platform;if(e.button!==0||e.ctrlKey&&s)return;(u=l(this,Vt))==null||u.toggle(!1);const i=this._isDraggable;this._isDraggable=!1,v(this,to,[e.screenX,e.screenY]);const n=new AbortController,r=this._uiManager.combinedSignal(n);this.parent.togglePointerEvents(!1),window.addEventListener("pointermove",_(this,et,hp).bind(this,t),{passive:!0,capture:!0,signal:r}),window.addEventListener("touchmove",ti,{passive:!1,signal:r}),window.addEventListener("contextmenu",Zs,{signal:r}),v(this,ir,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height});const o=this.parent.div.style.cursor,h=this.div.style.cursor;this.div.style.cursor=this.parent.div.style.cursor=window.getComputedStyle(e.target).cursor;const c=()=>{var d;n.abort(),this.parent.togglePointerEvents(!0),(d=l(this,Vt))==null||d.toggle(!0),this._isDraggable=i,this.parent.div.style.cursor=o,this.div.style.cursor=h,_(this,et,ap).call(this)};window.addEventListener("pointerup",c,{signal:r}),window.addEventListener("blur",c,{signal:r})},op=function(t,e,s,i){this.width=s,this.height=i,this.x=t,this.y=e;const[n,r]=this.parentDimensions;this.setDims(n*s,r*i),this.fixAndSetPosition(),this._onResized()},ap=function(){if(!l(this,ir))return;const{savedX:t,savedY:e,savedWidth:s,savedHeight:i}=l(this,ir);v(this,ir,null);const n=this.x,r=this.y,o=this.width,h=this.height;n===t&&r===e&&o===s&&h===i||this.addCommands({cmd:_(this,et,op).bind(this,n,r,o,h),undo:_(this,et,op).bind(this,t,e,s,i),mustExec:!0})},hp=function(t,e){const[s,i]=this.parentDimensions,n=this.x,r=this.y,o=this.width,h=this.height,c=bt.MIN_SIZE/s,u=bt.MIN_SIZE/i,d=V=>Math.round(V*1e4)/1e4,g=_(this,et,rp).call(this,this.rotation),f=(V,H)=>[g[0]*V+g[2]*H,g[1]*V+g[3]*H],p=_(this,et,rp).call(this,360-this.rotation),m=(V,H)=>[p[0]*V+p[2]*H,p[1]*V+p[3]*H];let y,b,x=!1,C=!1;switch(t){case"topLeft":x=!0,y=(V,H)=>[0,0],b=(V,H)=>[V,H];break;case"topMiddle":y=(V,H)=>[V/2,0],b=(V,H)=>[V/2,H];break;case"topRight":x=!0,y=(V,H)=>[V,0],b=(V,H)=>[0,H];break;case"middleRight":C=!0,y=(V,H)=>[V,H/2],b=(V,H)=>[0,H/2];break;case"bottomRight":x=!0,y=(V,H)=>[V,H],b=(V,H)=>[0,0];break;case"bottomMiddle":y=(V,H)=>[V/2,H],b=(V,H)=>[V/2,0];break;case"bottomLeft":x=!0,y=(V,H)=>[0,H],b=(V,H)=>[V,0];break;case"middleLeft":C=!0,y=(V,H)=>[0,H/2],b=(V,H)=>[V,H/2];break}const A=y(o,h),M=b(o,h);let D=f(...M);const k=d(n+D[0]),P=d(r+D[1]);let R=1,F=1,I,X;if(e.fromKeyboard)({deltaX:I,deltaY:X}=e);else{const{screenX:V,screenY:H}=e,[Et,It]=l(this,to);[I,X]=this.screenToPageTranslation(V-Et,H-It),l(this,to)[0]=V,l(this,to)[1]=H}if([I,X]=m(I/s,X/i),x){const V=Math.hypot(o,h);R=F=Math.max(Math.min(Math.hypot(M[0]-A[0]-I,M[1]-A[1]-X)/V,1/o,1/h),c/o,u/h)}else C?R=Math.max(c,Math.min(1,Math.abs(M[0]-A[0]-I)))/o:F=Math.max(u,Math.min(1,Math.abs(M[1]-A[1]-X)))/h;const j=d(o*R),N=d(h*F);D=f(...b(j,N));const it=k-D[0],K=P-D[1];this.width=j,this.height=N,this.x=it,this.y=K,this.setDims(s*j,i*N),this.fixAndSetPosition(),this._onResizing()},lp=function(t){const{isMac:e}=Ge.platform;t.ctrlKey&&!e||t.shiftKey||t.metaKey&&e?this.parent.toggleSelected(this):this.parent.setSelected(this)},Eb=function(t){const{isSelected:e}=this;this._uiManager.setUpDragSession();const s=new AbortController,i=this._uiManager.combinedSignal(s),n={capture:!0,passive:!1,signal:i},r=h=>{s.abort(),v(this,sr,null),v(this,eo,!1),this._uiManager.endDragSession()||_(this,et,lp).call(this,h)};e&&(v(this,xa,t.clientX),v(this,Sa,t.clientY),v(this,sr,t.pointerId),v(this,ml,t.pointerType),window.addEventListener("pointermove",h=>{const{clientX:c,clientY:u,pointerId:d}=h;if(d!==l(this,sr)){ti(h);return}const[g,f]=this.screenToPageTranslation(c-l(this,xa),u-l(this,Sa));v(this,xa,c),v(this,Sa,u),this._uiManager.dragSelectedEditors(g,f)},n),window.addEventListener("touchmove",ti,n),window.addEventListener("pointerdown",h=>{h.isPrimary&&h.pointerType===l(this,ml)&&r(h),ti(h)},n)),this._onStartDragging();const o=h=>{if(!l(this,sr)||l(this,sr)===h.pointerId){r(h),this._onStopDragging();return}ti(h)};window.addEventListener("pointerup",o,{signal:i}),window.addEventListener("blur",o,{signal:i})},cp=function(){if(l(this,nr)||!this.div)return;v(this,nr,new AbortController);const t=this._uiManager.combinedSignal(l(this,nr));this.div.addEventListener("focusin",this.focusin.bind(this),{signal:t}),this.div.addEventListener("focusout",this.focusout.bind(this),{signal:t})},kb=function(t){bt._resizerKeyboardManager.exec(this,t)},Mb=function(t){var e;l(this,dn)&&((e=t.relatedTarget)==null?void 0:e.parentNode)!==l(this,ve)&&_(this,et,Cc).call(this)},Pb=function(t){v(this,vl,l(this,dn)?t:"")},up=function(t){if(l(this,ri))for(const e of l(this,ri))e.tabIndex=t},Cc=function(){v(this,dn,!1),_(this,et,up).call(this,-1),_(this,et,ap).call(this)},w(bt,_l),q(bt,"_l10n",null),q(bt,"_l10nResizer",null),q(bt,"_borderLineWidth",-1),q(bt,"_colorManager",new ff),q(bt,"_zIndex",1),q(bt,"_telemetryTimeout",1e3);let Bt=bt;class zx extends Bt{constructor(t){super(t),this.annotationElementId=t.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}}const nv=3285377520,Ms=4294901760,Si=65535;class rv{constructor(t){this.h1=t?t&4294967295:nv,this.h2=t?t&4294967295:nv}update(t){let e,s;if(typeof t=="string"){e=new Uint8Array(t.length*2),s=0;for(let m=0,y=t.length;m<y;m++){const b=t.charCodeAt(m);b<=255?e[s++]=b:(e[s++]=b>>>8,e[s++]=b&255)}}else if(ArrayBuffer.isView(t))e=t.slice(),s=e.byteLength;else throw new Error("Invalid data format, must be a string or TypedArray.");const i=s>>2,n=s-i*4,r=new Uint32Array(e.buffer,0,i);let o=0,h=0,c=this.h1,u=this.h2;const d=3432918353,g=461845907,f=d&Si,p=g&Si;for(let m=0;m<i;m++)m&1?(o=r[m],o=o*d&Ms|o*f&Si,o=o<<15|o>>>17,o=o*g&Ms|o*p&Si,c^=o,c=c<<13|c>>>19,c=c*5+3864292196):(h=r[m],h=h*d&Ms|h*f&Si,h=h<<15|h>>>17,h=h*g&Ms|h*p&Si,u^=h,u=u<<13|u>>>19,u=u*5+3864292196);switch(o=0,n){case 3:o^=e[i*4+2]<<16;case 2:o^=e[i*4+1]<<8;case 1:o^=e[i*4],o=o*d&Ms|o*f&Si,o=o<<15|o>>>17,o=o*g&Ms|o*p&Si,i&1?c^=o:u^=o}this.h1=c,this.h2=u}hexdigest(){let t=this.h1,e=this.h2;return t^=e>>>1,t=t*3981806797&Ms|t*36045&Si,e=e*4283543511&Ms|((e<<16|t>>>16)*2950163797&Ms)>>>16,t^=e>>>1,t=t*444984403&Ms|t*60499&Si,e=e*3301882366&Ms|((e<<16|t>>>16)*3120437893&Ms)>>>16,t^=e>>>1,(t>>>0).toString(16).padStart(8,"0")+(e>>>0).toString(16).padStart(8,"0")}}const pf=Object.freeze({map:null,hash:"",transfer:void 0});class mf{constructor(){w(this,cd);w(this,io,!1);w(this,no,null);w(this,ge,new Map);this.onSetModified=null,this.onResetModified=null,this.onAnnotationEditor=null}getValue(t,e){const s=l(this,ge).get(t);return s===void 0?e:Object.assign(e,s)}getRawValue(t){return l(this,ge).get(t)}remove(t){if(l(this,ge).delete(t),l(this,ge).size===0&&this.resetModified(),typeof this.onAnnotationEditor=="function"){for(const e of l(this,ge).values())if(e instanceof Bt)return;this.onAnnotationEditor(null)}}setValue(t,e){const s=l(this,ge).get(t);let i=!1;if(s!==void 0)for(const[n,r]of Object.entries(e))s[n]!==r&&(i=!0,s[n]=r);else i=!0,l(this,ge).set(t,e);i&&_(this,cd,Ob).call(this),e instanceof Bt&&typeof this.onAnnotationEditor=="function"&&this.onAnnotationEditor(e.constructor._type)}has(t){return l(this,ge).has(t)}getAll(){return l(this,ge).size>0?sf(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,io)&&(v(this,io,!1),typeof this.onResetModified=="function"&&this.onResetModified())}get print(){return new ov(this)}get serializable(){if(l(this,ge).size===0)return pf;const t=new Map,e=new rv,s=[],i=Object.create(null);let n=!1;for(const[r,o]of l(this,ge)){const h=o instanceof Bt?o.serialize(!1,i):o;h&&(t.set(r,h),e.update(`${r}:${JSON.stringify(h)}`),n||(n=!!h.bitmap))}if(n)for(const r of t.values())r.bitmap&&s.push(r.bitmap);return t.size>0?{map:t,hash:e.hexdigest(),transfer:s}:pf}get editorStats(){let t=null;const e=new Map;for(const s of l(this,ge).values()){if(!(s instanceof Bt))continue;const i=s.telemetryFinalData;if(!i)continue;const{type:n}=i;e.has(n)||e.set(n,Object.getPrototypeOf(s).constructor),t||(t=Object.create(null));const r=t[n]||(t[n]=new Map);for(const[o,h]of Object.entries(i)){if(o==="type")continue;let c=r.get(o);c||(c=new Map,r.set(o,c));const u=c.get(h)??0;c.set(h,u+1)}}for(const[s,i]of e)t[s]=i.computeTelemetryFinalData(t[s]);return t}resetModifiedIds(){v(this,no,null)}get modifiedIds(){if(l(this,no))return l(this,no);const t=[];for(const e of l(this,ge).values())!(e instanceof Bt)||!e.annotationElementId||!e.serialize()||t.push(e.annotationElementId);return v(this,no,{ids:new Set(t),hash:t.join(",")})}}io=new WeakMap,no=new WeakMap,ge=new WeakMap,cd=new WeakSet,Ob=function(){l(this,io)||(v(this,io,!0),typeof this.onSetModified=="function"&&this.onSetModified())};class ov extends mf{constructor(e){super();w(this,wl);const{map:s,hash:i,transfer:n}=e.serializable,r=structuredClone(s,n?{transfer:n}:null);v(this,wl,{map:r,hash:i,transfer:n})}get print(){St("Should not call PrintAnnotationStorage.print")}get serializable(){return l(this,wl)}get modifiedIds(){return at(this,"modifiedIds",{ids:new Set,hash:""})}}wl=new WeakMap;class Xx{constructor({ownerDocument:t=globalThis.document,styleElement:e=null}){w(this,Ca,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,Ca).clear(),this.styleElement&&(this.styleElement.remove(),this.styleElement=null)}async loadSystemFont({systemFontInfo:t,_inspectFont:e}){if(!(!t||l(this,Ca).has(t.loadedName))){if(te(!this.disableFontFace,"loadSystemFont shouldn't be called when `disableFontFace` is set."),this.isFontLoadingAPISupported){const{loadedName:s,src:i,style:n}=t,r=new FontFace(s,i,n);this.addNativeFontFace(r);try{await r.load(),l(this,Ca).add(s),e==null||e(t)}catch{rt(`Cannot load system font: ${t.baseFontName}, installing it could help to improve PDF rendering.`),this.removeNativeFontFace(r)}return}St("Not implemented: loadSystemFont without the Font Loading API.")}}async bind(t){if(t.attached||t.missingFile&&!t.systemFontInfo)return;if(t.attached=!0,t.systemFontInfo){await this.loadSystemFont(t);return}if(this.isFontLoadingAPISupported){const s=t.createNativeFontFace();if(s){this.addNativeFontFace(s);try{await s.loaded}catch(i){throw rt(`Failed to load font '${s.family}': '${i}'.`),t.disableFontFace=!0,i}}return}const e=t.createFontFaceRule();if(e){if(this.insertRule(e),this.isSyncFontLoadingSupported)return;await new Promise(s=>{const i=this._queueLoadingCallback(s);this._prepareFontLoadEvent(t,i)})}}get isFontLoadingAPISupported(){var e;const t=!!((e=this._document)!=null&&e.fonts);return at(this,"isFontLoadingAPISupported",t)}get isSyncFontLoadingSupported(){let t=!1;return(Ve||typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.userAgent)=="string"&&/Mozilla\/5.0.*?rv:\d+.*? Gecko/.test(navigator.userAgent))&&(t=!0),at(this,"isSyncFontLoadingSupported",t)}_queueLoadingCallback(t){function e(){for(te(!i.done,"completeRequest() cannot be called twice."),i.done=!0;s.length>0&&s[0].done;){const n=s.shift();setTimeout(n.callback,0)}}const{loadingRequests:s}=this,i={done:!1,complete:e,callback:t};return s.push(i),i}get _loadTestFont(){const t=atob("T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA==");return at(this,"_loadTestFont",t)}_prepareFontLoadEvent(t,e){function s(A,M){return A.charCodeAt(M)<<24|A.charCodeAt(M+1)<<16|A.charCodeAt(M+2)<<8|A.charCodeAt(M+3)&255}function i(A,M,D,k){const P=A.substring(0,M),R=A.substring(M+D);return P+k+R}let n,r;const o=this._document.createElement("canvas");o.width=1,o.height=1;const h=o.getContext("2d");let c=0;function u(A,M){if(++c>30){rt("Load test font never loaded."),M();return}if(h.font="30px "+A,h.fillText(".",0,20),h.getImageData(0,0,1,1).data[3]>0){M();return}setTimeout(u.bind(null,A,M))}const d=`lt${Date.now()}${this.loadTestFontId++}`;let g=this._loadTestFont;g=i(g,976,d.length,d);const p=16,m=1482184792;let y=s(g,p);for(n=0,r=d.length-3;n<r;n+=4)y=y-m+s(d,n)|0;n<d.length&&(y=y-m+s(d+"XXX",n)|0),g=i(g,p,4,Px(y));const b=`url(data:font/opentype;base64,${btoa(g)});`,x=`@font-face {font-family:"${d}";src:${b}}`;this.insertRule(x);const C=this._document.createElement("div");C.style.visibility="hidden",C.style.width=C.style.height="10px",C.style.position="absolute",C.style.top=C.style.left="0px";for(const A of[t.loadedName,d]){const M=this._document.createElement("span");M.textContent="Hi",M.style.fontFamily=A,C.append(M)}this._document.body.append(C),u(d,()=>{C.remove(),e.complete()})}}Ca=new WeakMap;class Ux{constructor(t,{disableFontFace:e=!1,inspectFont:s=null}){this.compiledGlyphs=Object.create(null);for(const i in t)this[i]=t[i];this.disableFontFace=e===!0,this._inspectFont=s}createNativeFontFace(){var e;if(!this.data||this.disableFontFace)return null;let t;if(!this.cssFontInfo)t=new FontFace(this.loadedName,this.data,{});else{const s={weight:this.cssFontInfo.fontWeight};this.cssFontInfo.italicAngle&&(s.style=`oblique ${this.cssFontInfo.italicAngle}deg`),t=new FontFace(this.cssFontInfo.fontFamily,this.data,s)}return(e=this._inspectFont)==null||e.call(this,this),t}createFontFaceRule(){var s;if(!this.data||this.disableFontFace)return null;const t=`url(data:${this.mimetype};base64,${Ix(this.data)});`;let e;if(!this.cssFontInfo)e=`@font-face {font-family:"${this.loadedName}";src:${t}}`;else{let i=`font-weight: ${this.cssFontInfo.fontWeight};`;this.cssFontInfo.italicAngle&&(i+=`font-style: oblique ${this.cssFontInfo.italicAngle}deg;`),e=`@font-face {font-family:"${this.cssFontInfo.fontFamily}";${i}src:${t}}`}return(s=this._inspectFont)==null||s.call(this,this,t),e}getPathGenerator(t,e){if(this.compiledGlyphs[e]!==void 0)return this.compiledGlyphs[e];let s;try{s=t.get(this.loadedName+"_path_"+e)}catch(n){rt(`getPathGenerator - ignoring character: "${n}".`)}if(!Array.isArray(s)||s.length===0)return this.compiledGlyphs[e]=function(n,r){};const i=[];for(let n=0,r=s.length;n<r;)switch(s[n++]){case en.BEZIER_CURVE_TO:{const[o,h,c,u,d,g]=s.slice(n,n+6);i.push(f=>f.bezierCurveTo(o,h,c,u,d,g)),n+=6}break;case en.MOVE_TO:{const[o,h]=s.slice(n,n+2);i.push(c=>c.moveTo(o,h)),n+=2}break;case en.LINE_TO:{const[o,h]=s.slice(n,n+2);i.push(c=>c.lineTo(o,h)),n+=2}break;case en.QUADRATIC_CURVE_TO:{const[o,h,c,u]=s.slice(n,n+4);i.push(d=>d.quadraticCurveTo(o,h,c,u)),n+=4}break;case en.RESTORE:i.push(o=>o.restore());break;case en.SAVE:i.push(o=>o.save());break;case en.SCALE:te(i.length===2,"Scale command is only valid at the third position.");break;case en.TRANSFORM:{const[o,h,c,u,d,g]=s.slice(n,n+6);i.push(f=>f.transform(o,h,c,u,d,g)),n+=6}break;case en.TRANSLATE:{const[o,h]=s.slice(n,n+2);i.push(c=>c.translate(o,h)),n+=2}break}return i.push(n=>n.closePath()),this.compiledGlyphs[e]=function(r,o){i[0](r),i[1](r),r.scale(o,-o);for(let h=2,c=i.length;h<c;h++)i[h](r)}}}class av{constructor({enableHWA:t=!1}){w(this,xl,!1);v(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){St("Abstract method `_createCanvas` called.")}}xl=new WeakMap;class Yx extends av{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 hv{constructor({baseUrl:t=null,isCompressed:e=!0}){this.baseUrl=t,this.isCompressed=e}async fetch({name:t}){if(!this.baseUrl)throw new Error("Ensure that the `cMapUrl` and `cMapPacked` API parameters are provided.");if(!t)throw new Error("CMap name must be specified.");const e=this.baseUrl+t+(this.isCompressed?".bcmap":"");return this._fetch(e).then(s=>({cMapData:s,isCompressed:this.isCompressed})).catch(s=>{throw new Error(`Unable to load ${this.isCompressed?"binary ":""}CMap at: ${e}`)})}async _fetch(t){St("Abstract method `_fetch` called.")}}class lv extends hv{async _fetch(t){const e=await Wu(t,this.isCompressed?"arraybuffer":"text");return e instanceof ArrayBuffer?new Uint8Array(e):Gu(e)}}class cv{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 $x extends cv{constructor({docId:e,ownerDocument:s=globalThis.document}){super();w(this,z);w(this,ro);w(this,Aa);w(this,gn);w(this,fn);w(this,Pe);w(this,oo);w(this,ao,0);v(this,fn,e),v(this,Pe,s)}addFilter(e){if(!e)return"none";let s=l(this,z,Le).get(e);if(s)return s;const[i,n,r]=_(this,z,Od).call(this,e),o=e.length===1?i:`${i}${n}${r}`;if(s=l(this,z,Le).get(o),s)return l(this,z,Le).set(e,s),s;const h=`g_${l(this,fn)}_transfer_map_${Ke(this,ao)._++}`,c=_(this,z,yh).call(this,h);l(this,z,Le).set(e,c),l(this,z,Le).set(o,c);const u=_(this,z,_h).call(this,h);return _(this,z,Ec).call(this,i,n,r,u),c}addHCMFilter(e,s){var p;const i=`${e}-${s}`,n="base";let r=l(this,z,Ac).get(n);if((r==null?void 0:r.key)===i||(r?((p=r.filter)==null||p.remove(),r.key=i,r.url="none",r.filter=null):(r={key:i,url:"none",filter:null},l(this,z,Ac).set(n,r)),!e||!s))return r.url;const o=_(this,z,kc).call(this,e);e=$.makeHexColor(...o);const h=_(this,z,kc).call(this,s);if(s=$.makeHexColor(...h),l(this,z,bh).style.color="",e==="#000000"&&s==="#ffffff"||e===s)return r.url;const c=new Array(256);for(let m=0;m<=255;m++){const y=m/255;c[m]=y<=.03928?y/12.92:((y+.055)/1.055)**2.4}const u=c.join(","),d=`g_${l(this,fn)}_hcm_filter`,g=r.filter=_(this,z,_h).call(this,d);_(this,z,Ec).call(this,u,u,u,g),_(this,z,dp).call(this,g);const f=(m,y)=>{const b=o[m]/255,x=h[m]/255,C=new Array(y+1);for(let A=0;A<=y;A++)C[A]=b+A/y*(x-b);return C.join(",")};return _(this,z,Ec).call(this,f(0,5),f(1,5),f(2,5),g),r.url=_(this,z,yh).call(this,d),r.url}addAlphaFilter(e){let s=l(this,z,Le).get(e);if(s)return s;const[i]=_(this,z,Od).call(this,[e]),n=`alpha_${i}`;if(s=l(this,z,Le).get(n),s)return l(this,z,Le).set(e,s),s;const r=`g_${l(this,fn)}_alpha_map_${Ke(this,ao)._++}`,o=_(this,z,yh).call(this,r);l(this,z,Le).set(e,o),l(this,z,Le).set(n,o);const h=_(this,z,_h).call(this,r);return _(this,z,gp).call(this,i,h),o}addLuminosityFilter(e){let s=l(this,z,Le).get(e||"luminosity");if(s)return s;let i,n;if(e?([i]=_(this,z,Od).call(this,[e]),n=`luminosity_${i}`):n="luminosity",s=l(this,z,Le).get(n),s)return l(this,z,Le).set(e,s),s;const r=`g_${l(this,fn)}_luminosity_map_${Ke(this,ao)._++}`,o=_(this,z,yh).call(this,r);l(this,z,Le).set(e,o),l(this,z,Le).set(n,o);const h=_(this,z,_h).call(this,r);return _(this,z,Db).call(this,h),e&&_(this,z,gp).call(this,i,h),o}addHighlightHCMFilter(e,s,i,n,r){var x;const o=`${s}-${i}-${n}-${r}`;let h=l(this,z,Ac).get(e);if((h==null?void 0:h.key)===o||(h?((x=h.filter)==null||x.remove(),h.key=o,h.url="none",h.filter=null):(h={key:o,url:"none",filter:null},l(this,z,Ac).set(e,h)),!s||!i))return h.url;const[c,u]=[s,i].map(_(this,z,kc).bind(this));let d=Math.round(.2126*c[0]+.7152*c[1]+.0722*c[2]),g=Math.round(.2126*u[0]+.7152*u[1]+.0722*u[2]),[f,p]=[n,r].map(_(this,z,kc).bind(this));g<d&&([d,g,f,p]=[g,d,p,f]),l(this,z,bh).style.color="";const m=(C,A,M)=>{const D=new Array(256),k=(g-d)/M,P=C/255,R=(A-C)/(255*M);let F=0;for(let I=0;I<=M;I++){const X=Math.round(d+I*k),j=P+I*R;for(let N=F;N<=X;N++)D[N]=j;F=X+1}for(let I=F;I<256;I++)D[I]=D[F-1];return D.join(",")},y=`g_${l(this,fn)}_hcm_${e}_filter`,b=h.filter=_(this,z,_h).call(this,y);return _(this,z,dp).call(this,b),_(this,z,Ec).call(this,m(f[0],p[0],5),m(f[1],p[1],5),m(f[2],p[2],5),b),h.url=_(this,z,yh).call(this,y),h.url}destroy(e=!1){var s,i,n,r;e&&((s=l(this,oo))!=null&&s.size)||((i=l(this,gn))==null||i.parentNode.parentNode.remove(),v(this,gn,null),(n=l(this,Aa))==null||n.clear(),v(this,Aa,null),(r=l(this,oo))==null||r.clear(),v(this,oo,null),v(this,ao,0))}}ro=new WeakMap,Aa=new WeakMap,gn=new WeakMap,fn=new WeakMap,Pe=new WeakMap,oo=new WeakMap,ao=new WeakMap,z=new WeakSet,Le=function(){return l(this,Aa)||v(this,Aa,new Map)},Ac=function(){return l(this,oo)||v(this,oo,new Map)},bh=function(){if(!l(this,gn)){const e=l(this,Pe).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,Pe).createElementNS(sn,"svg");i.setAttribute("width",0),i.setAttribute("height",0),v(this,gn,l(this,Pe).createElementNS(sn,"defs")),e.append(i),i.append(l(this,gn)),l(this,Pe).body.append(e)}return l(this,gn)},Od=function(e){if(e.length===1){const c=e[0],u=new Array(256);for(let g=0;g<256;g++)u[g]=c[g]/255;const d=u.join(",");return[d,d,d]}const[s,i,n]=e,r=new Array(256),o=new Array(256),h=new Array(256);for(let c=0;c<256;c++)r[c]=s[c]/255,o[c]=i[c]/255,h[c]=n[c]/255;return[r.join(","),o.join(","),h.join(",")]},yh=function(e){if(l(this,ro)===void 0){v(this,ro,"");const s=l(this,Pe).URL;s!==l(this,Pe).baseURI&&(zu(s)?rt('#createUrl: ignore "data:"-URL for performance reasons.'):v(this,ro,s.split("#",1)[0]))}return`url(${l(this,ro)}#${e})`},Db=function(e){const s=l(this,Pe).createElementNS(sn,"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)},dp=function(e){const s=l(this,Pe).createElementNS(sn,"feColorMatrix");s.setAttribute("type","matrix"),s.setAttribute("values","0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0 0 0 1 0"),e.append(s)},_h=function(e){const s=l(this,Pe).createElementNS(sn,"filter");return s.setAttribute("color-interpolation-filters","sRGB"),s.setAttribute("id",e),l(this,z,bh).append(s),s},Tc=function(e,s,i){const n=l(this,Pe).createElementNS(sn,s);n.setAttribute("type","discrete"),n.setAttribute("tableValues",i),e.append(n)},Ec=function(e,s,i,n){const r=l(this,Pe).createElementNS(sn,"feComponentTransfer");n.append(r),_(this,z,Tc).call(this,r,"feFuncR",e),_(this,z,Tc).call(this,r,"feFuncG",s),_(this,z,Tc).call(this,r,"feFuncB",i)},gp=function(e,s){const i=l(this,Pe).createElementNS(sn,"feComponentTransfer");s.append(i),_(this,z,Tc).call(this,i,"feFuncA",e)},kc=function(e){return l(this,z,bh).style.color=e,cf(getComputedStyle(l(this,z,bh)).getPropertyValue("color"))};class uv{constructor({baseUrl:t=null}){this.baseUrl=t}async fetch({filename:t}){if(!this.baseUrl)throw new Error("Ensure that the `standardFontDataUrl` API parameter is provided.");if(!t)throw new Error("Font filename must be specified.");const e=`${this.baseUrl}${t}`;return this._fetch(e).catch(s=>{throw new Error(`Unable to load font data at: ${e}`)})}async _fetch(t){St("Abstract method `_fetch` called.")}}class dv extends uv{async _fetch(t){const e=await Wu(t,"arraybuffer");return new Uint8Array(e)}}async function gv(a){const e=await process.getBuiltinModule("fs").promises.readFile(a);return new Uint8Array(e)}class qx extends cv{}class Kx extends av{_createCanvas(t,e){return process.getBuiltinModule("module").createRequire("file:///home/runner/work/pdf.js/pdf.js/src/display/node_utils.js")("@napi-rs/canvas").createCanvas(t,e)}}class Qx extends hv{async _fetch(t){return gv(t)}}class Jx extends uv{async _fetch(t){return gv(t)}}const ke={FILL:"Fill",STROKE:"Stroke",SHADING:"Shading"};function vf(a,t){if(!t)return;const e=t[2]-t[0],s=t[3]-t[1],i=new Path2D;i.rect(t[0],t[1],e,s),a.clip(i)}class bf{getPattern(){St("Abstract method `getPattern` called.")}}class Zx extends bf{constructor(t){super(),this._type=t[1],this._bbox=t[2],this._colorStops=t[3],this._p0=t[4],this._p1=t[5],this._r0=t[6],this._r1=t[7],this.matrix=null}_createGradient(t){let e;this._type==="axial"?e=t.createLinearGradient(this._p0[0],this._p0[1],this._p1[0],this._p1[1]):this._type==="radial"&&(e=t.createRadialGradient(this._p0[0],this._p0[1],this._r0,this._p1[0],this._p1[1],this._r1));for(const s of this._colorStops)e.addColorStop(s[0],s[1]);return e}getPattern(t,e,s,i){let n;if(i===ke.STROKE||i===ke.FILL){const r=e.current.getClippedPathBoundingBox(i,Rt(t))||[0,0,0,0],o=Math.ceil(r[2]-r[0])||1,h=Math.ceil(r[3]-r[1])||1,c=e.cachedCanvases.getCanvas("pattern",o,h),u=c.context;u.clearRect(0,0,u.canvas.width,u.canvas.height),u.beginPath(),u.rect(0,0,u.canvas.width,u.canvas.height),u.translate(-r[0],-r[1]),s=$.transform(s,[1,0,0,1,r[0],r[1]]),u.transform(...e.baseTransform),this.matrix&&u.transform(...this.matrix),vf(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 vf(t,this._bbox),n=this._createGradient(t);return n}}function yf(a,t,e,s,i,n,r,o){const h=t.coords,c=t.colors,u=a.data,d=a.width*4;let g;h[e+1]>h[s+1]&&(g=e,e=s,s=g,g=n,n=r,r=g),h[s+1]>h[i+1]&&(g=s,s=i,i=g,g=r,r=o,o=g),h[e+1]>h[s+1]&&(g=e,e=s,s=g,g=n,n=r,r=g);const f=(h[e]+t.offsetX)*t.scaleX,p=(h[e+1]+t.offsetY)*t.scaleY,m=(h[s]+t.offsetX)*t.scaleX,y=(h[s+1]+t.offsetY)*t.scaleY,b=(h[i]+t.offsetX)*t.scaleX,x=(h[i+1]+t.offsetY)*t.scaleY;if(p>=x)return;const C=c[n],A=c[n+1],M=c[n+2],D=c[r],k=c[r+1],P=c[r+2],R=c[o],F=c[o+1],I=c[o+2],X=Math.round(p),j=Math.round(x);let N,it,K,V,H,Et,It,ie;for(let Wt=X;Wt<=j;Wt++){if(Wt<y){const gt=Wt<p?0:(p-Wt)/(p-y);N=f-(f-m)*gt,it=C-(C-D)*gt,K=A-(A-k)*gt,V=M-(M-P)*gt}else{let gt;Wt>x?gt=1:y===x?gt=0:gt=(y-Wt)/(y-x),N=m-(m-b)*gt,it=D-(D-R)*gt,K=k-(k-F)*gt,V=P-(P-I)*gt}let Tt;Wt<p?Tt=0:Wt>x?Tt=1:Tt=(p-Wt)/(p-x),H=f-(f-b)*Tt,Et=C-(C-R)*Tt,It=A-(A-F)*Tt,ie=M-(M-I)*Tt;const xe=Math.round(Math.min(N,H)),Vs=Math.round(Math.max(N,H));let Pt=d*Wt+xe*4;for(let gt=xe;gt<=Vs;gt++)Tt=(N-gt)/(N-H),Tt<0?Tt=0:Tt>1&&(Tt=1),u[Pt++]=it-(it-Et)*Tt|0,u[Pt++]=K-(K-It)*Tt|0,u[Pt++]=V-(V-ie)*Tt|0,u[Pt++]=255}}function tS(a,t,e){const s=t.coords,i=t.colors;let n,r;switch(t.type){case"lattice":const o=t.verticesPerRow,h=Math.floor(s.length/o)-1,c=o-1;for(n=0;n<h;n++){let u=n*o;for(let d=0;d<c;d++,u++)yf(a,e,s[u],s[u+1],s[u+o],i[u],i[u+1],i[u+o]),yf(a,e,s[u+o+1],s[u+1],s[u+o],i[u+o+1],i[u+1],i[u+o])}break;case"triangles":for(n=0,r=s.length;n<r;n+=3)yf(a,e,s[n],s[n+1],s[n+2],i[n],i[n+1],i[n+2]);break;default:throw new Error("illegal figure")}}class eS extends bf{constructor(t){super(),this._coords=t[2],this._colors=t[3],this._figures=t[4],this._bounds=t[5],this._bbox=t[7],this._background=t[8],this.matrix=null}_createMeshCanvas(t,e,s){const o=Math.floor(this._bounds[0]),h=Math.floor(this._bounds[1]),c=Math.ceil(this._bounds[2])-o,u=Math.ceil(this._bounds[3])-h,d=Math.min(Math.ceil(Math.abs(c*t[0]*1.1)),3e3),g=Math.min(Math.ceil(Math.abs(u*t[1]*1.1)),3e3),f=c/d,p=u/g,m={coords:this._coords,colors:this._colors,offsetX:-o,offsetY:-h,scaleX:1/f,scaleY:1/p},y=d+2*2,b=g+2*2,x=s.getCanvas("mesh",y,b),C=x.context,A=C.createImageData(d,g);if(e){const D=A.data;for(let k=0,P=D.length;k<P;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)tS(A,D,m);return C.putImageData(A,2,2),{canvas:x.canvas,offsetX:o-2*f,offsetY:h-2*p,scaleX:f,scaleY:p}}getPattern(t,e,s,i){vf(t,this._bbox);let n;if(i===ke.SHADING)n=$.singularValueDecompose2dScale(Rt(t));else if(n=$.singularValueDecompose2dScale(e.baseTransform),this.matrix){const o=$.singularValueDecompose2dScale(this.matrix);n=[n[0]*o[0],n[1]*o[1]]}const r=this._createMeshCanvas(n,i===ke.SHADING?null:this._background,e.cachedCanvases);return i!==ke.SHADING&&(t.setTransform(...e.baseTransform),this.matrix&&t.transform(...this.matrix)),t.translate(r.offsetX,r.offsetY),t.scale(r.scaleX,r.scaleY),t.createPattern(r.canvas,"no-repeat")}}class sS extends bf{getPattern(){return"hotpink"}}function iS(a){switch(a[0]){case"RadialAxial":return new Zx(a);case"Mesh":return new eS(a);case"Dummy":return new sS}throw new Error(`Unknown IR type: ${a[0]}`)}const fv={COLORED:1,UNCOLORED:2},ud=class ud{constructor(t,e,s,i,n){this.operatorList=t[2],this.matrix=t[3],this.bbox=t[4],this.xstep=t[5],this.ystep=t[6],this.paintType=t[7],this.tilingType=t[8],this.color=e,this.ctx=s,this.canvasGraphicsFactory=i,this.baseTransform=n}createPatternCanvas(t){const{bbox:e,operatorList:s,paintType:i,tilingType:n,color:r,canvasGraphicsFactory:o}=this;let{xstep:h,ystep:c}=this;h=Math.abs(h),c=Math.abs(c),Hu("TilingType: "+n);const u=e[0],d=e[1],g=e[2],f=e[3],p=g-u,m=f-d,y=$.singularValueDecompose2dScale(this.matrix),b=$.singularValueDecompose2dScale(this.baseTransform),x=y[0]*b[0],C=y[1]*b[1];let A=p,M=m,D=!1,k=!1;const P=Math.ceil(h*x),R=Math.ceil(c*C),F=Math.ceil(p*x),I=Math.ceil(m*C);P>=F?A=h:D=!0,R>=I?M=c:k=!0;const X=this.getSizeAndScale(A,this.ctx.canvas.width,x),j=this.getSizeAndScale(M,this.ctx.canvas.height,C),N=t.cachedCanvases.getCanvas("pattern",X.size,j.size),it=N.context,K=o.createCanvasGraphics(it);if(K.groupLevel=t.groupLevel,this.setFillAndStrokeStyleToContext(K,i,r),it.translate(-X.scale*u,-j.scale*d),K.transform(X.scale,0,0,j.scale,0,0),it.save(),this.clipBbox(K,u,d,g,f),K.baseTransform=Rt(K.ctx),K.executeOperatorList(s),K.endDrawing(),it.restore(),D||k){const V=N.canvas;D&&(A=h),k&&(M=c);const H=this.getSizeAndScale(A,this.ctx.canvas.width,x),Et=this.getSizeAndScale(M,this.ctx.canvas.height,C),It=H.size,ie=Et.size,Wt=t.cachedCanvases.getCanvas("pattern-workaround",It,ie),Tt=Wt.context,xe=D?Math.floor(p/h):0,Vs=k?Math.floor(m/c):0;for(let Pt=0;Pt<=xe;Pt++)for(let gt=0;gt<=Vs;gt++)Tt.drawImage(V,It*Pt,ie*gt,It,ie,0,0,It,ie);return{canvas:Wt.canvas,scaleX:H.scale,scaleY:Et.scale,offsetX:u,offsetY:d}}return{canvas:N.canvas,scaleX:X.scale,scaleY:j.scale,offsetX:u,offsetY:d}}getSizeAndScale(t,e,s){const i=Math.max(ud.MAX_PATTERN_SIZE,e);let n=Math.ceil(t*s);return n>=i?n=i:s=n/t,{scale:s,size:n}}clipBbox(t,e,s,i,n){const r=i-e,o=n-s;t.ctx.rect(e,s,r,o),t.current.updateRectMinMax(Rt(t.ctx),[e,s,i,n]),t.clip(),t.endPath()}setFillAndStrokeStyleToContext(t,e,s){const i=t.ctx,n=t.current;switch(e){case fv.COLORED:const r=this.ctx;i.fillStyle=r.fillStyle,i.strokeStyle=r.strokeStyle,n.fillColor=r.fillStyle,n.strokeColor=r.strokeStyle;break;case fv.UNCOLORED:const o=$.makeHexColor(s[0],s[1],s[2]);i.fillStyle=o,i.strokeStyle=o,n.fillColor=o,n.strokeColor=o;break;default:throw new Mx(`Unsupported paint type: ${e}`)}}getPattern(t,e,s,i){let n=s;i!==ke.SHADING&&(n=$.transform(n,e.baseTransform),this.matrix&&(n=$.transform(n,this.matrix)));const r=this.createPatternCanvas(e);let o=new DOMMatrix(n);o=o.translate(r.offsetX,r.offsetY),o=o.scale(1/r.scaleX,1/r.scaleY);const h=t.createPattern(r.canvas,"repeat");return h.setTransform(o),h}};q(ud,"MAX_PATTERN_SIZE",3e3);let _f=ud;function nS({src:a,srcPos:t=0,dest:e,width:s,height:i,nonBlackColor:n=4294967295,inverseDecode:r=!1}){const o=Ge.isLittleEndian?4278190080:255,[h,c]=r?[n,o]:[o,n],u=s>>3,d=s&7,g=a.length;e=new Uint32Array(e.buffer);let f=0;for(let p=0;p<i;p++){for(const y=t+u;t<y;t++){const b=t<g?a[t]:255;e[f++]=b&128?c:h,e[f++]=b&64?c:h,e[f++]=b&32?c:h,e[f++]=b&16?c:h,e[f++]=b&8?c:h,e[f++]=b&4?c:h,e[f++]=b&2?c:h,e[f++]=b&1?c:h}if(d===0)continue;const m=t<g?a[t++]:255;for(let y=0;y<d;y++)e[f++]=m&1<<7-y?c:h}return{srcPos:t,destPos:f}}const pv=16,mv=100,rS=15,vv=10,bv=1e3,ts=16;function oS(a,t){if(a._removeMirroring)throw new Error("Context is already forwarding operations.");a.__originalSave=a.save,a.__originalRestore=a.restore,a.__originalRotate=a.rotate,a.__originalScale=a.scale,a.__originalTranslate=a.translate,a.__originalTransform=a.transform,a.__originalSetTransform=a.setTransform,a.__originalResetTransform=a.resetTransform,a.__originalClip=a.clip,a.__originalMoveTo=a.moveTo,a.__originalLineTo=a.lineTo,a.__originalBezierCurveTo=a.bezierCurveTo,a.__originalRect=a.rect,a.__originalClosePath=a.closePath,a.__originalBeginPath=a.beginPath,a._removeMirroring=()=>{a.save=a.__originalSave,a.restore=a.__originalRestore,a.rotate=a.__originalRotate,a.scale=a.__originalScale,a.translate=a.__originalTranslate,a.transform=a.__originalTransform,a.setTransform=a.__originalSetTransform,a.resetTransform=a.__originalResetTransform,a.clip=a.__originalClip,a.moveTo=a.__originalMoveTo,a.lineTo=a.__originalLineTo,a.bezierCurveTo=a.__originalBezierCurveTo,a.rect=a.__originalRect,a.closePath=a.__originalClosePath,a.beginPath=a.__originalBeginPath,delete a._removeMirroring},a.save=function(){t.save(),this.__originalSave()},a.restore=function(){t.restore(),this.__originalRestore()},a.translate=function(s,i){t.translate(s,i),this.__originalTranslate(s,i)},a.scale=function(s,i){t.scale(s,i),this.__originalScale(s,i)},a.transform=function(s,i,n,r,o,h){t.transform(s,i,n,r,o,h),this.__originalTransform(s,i,n,r,o,h)},a.setTransform=function(s,i,n,r,o,h){t.setTransform(s,i,n,r,o,h),this.__originalSetTransform(s,i,n,r,o,h)},a.resetTransform=function(){t.resetTransform(),this.__originalResetTransform()},a.rotate=function(s){t.rotate(s),this.__originalRotate(s)},a.clip=function(s){t.clip(s),this.__originalClip(s)},a.moveTo=function(e,s){t.moveTo(e,s),this.__originalMoveTo(e,s)},a.lineTo=function(e,s){t.lineTo(e,s),this.__originalLineTo(e,s)},a.bezierCurveTo=function(e,s,i,n,r,o){t.bezierCurveTo(e,s,i,n,r,o),this.__originalBezierCurveTo(e,s,i,n,r,o)},a.rect=function(e,s,i,n){t.rect(e,s,i,n),this.__originalRect(e,s,i,n)},a.closePath=function(){t.closePath(),this.__originalClosePath()},a.beginPath=function(){t.beginPath(),this.__originalBeginPath()}}class aS{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 Yu(a,t,e,s,i,n,r,o,h,c){const[u,d,g,f,p,m]=Rt(a);if(d===0&&g===0){const x=r*u+p,C=Math.round(x),A=o*f+m,M=Math.round(A),D=(r+h)*u+p,k=Math.abs(Math.round(D)-C)||1,P=(o+c)*f+m,R=Math.abs(Math.round(P)-M)||1;return a.setTransform(Math.sign(u),0,0,Math.sign(f),C,M),a.drawImage(t,e,s,i,n,0,0,k,R),a.setTransform(u,d,g,f,p,m),[k,R]}if(u===0&&f===0){const x=o*g+p,C=Math.round(x),A=r*d+m,M=Math.round(A),D=(o+c)*g+p,k=Math.abs(Math.round(D)-C)||1,P=(r+h)*d+m,R=Math.abs(Math.round(P)-M)||1;return a.setTransform(0,Math.sign(d),Math.sign(g),0,C,M),a.drawImage(t,e,s,i,n,0,0,R,k),a.setTransform(u,d,g,f,p,m),[R,k]}a.drawImage(t,e,s,i,n,r,o,h,c);const y=Math.hypot(u,d),b=Math.hypot(g,f);return[y*h,b*c]}function hS(a){const{width:t,height:e}=a;if(t>bv||e>bv)return null;const s=1e3,i=new Uint8Array([0,2,4,0,1,0,5,4,8,10,0,8,0,2,1,0]),n=t+1;let r=new Uint8Array(n*(e+1)),o,h,c;const u=t+7&-8;let d=new Uint8Array(u*e),g=0;for(const b of a.data){let x=128;for(;x>0;)d[g++]=b&x?0:255,x>>=1}let f=0;for(g=0,d[g]!==0&&(r[0]=1,++f),h=1;h<t;h++)d[g]!==d[g+1]&&(r[h]=d[g]?2:1,++f),g++;for(d[g]!==0&&(r[h]=2,++f),o=1;o<e;o++){g=o*u,c=o*n,d[g-u]!==d[g]&&(r[c]=d[g]?1:8,++f);let b=(d[g]?4:0)+(d[g-u]?8:0);for(h=1;h<t;h++)b=(b>>2)+(d[g+1]?4:0)+(d[g-u+1]?8:0),i[b]&&(r[c+h]=i[b],++f),g++;if(d[g-u]!==d[g]&&(r[c+h]=d[g]?2:4,++f),f>s)return null}for(g=u*(e-1),c=o*n,d[g]!==0&&(r[c]=8,++f),h=1;h<t;h++)d[g]!==d[g+1]&&(r[c+h]=d[g]?4:8,++f),g++;if(d[g]!==0&&(r[c+h]=4,++f),f>s)return null;const p=new Int32Array([0,n,-1,0,-n,0,0,0,1]),m=new Path2D;for(o=0;f&&o<=e;o++){let b=o*n;const x=b+t;for(;b<x&&!r[b];)b++;if(b===x)continue;m.moveTo(b%n,o);const C=b;let A=r[b];do{const M=p[A];do b+=M;while(!r[b]);const D=r[b];D!==5&&D!==10?(A=D,r[b]=0):(A=D&51*A>>4,r[b]&=A>>2|A<<2),m.lineTo(b%n,b/n|0),r[b]||--f}while(C!==b);--o}return d=null,r=null,function(b){b.save(),b.scale(1/t,-1/e),b.translate(0,-e),b.fill(m),b.beginPath(),b.restore()}}class yv{constructor(t,e){this.alphaIsShape=!1,this.fontSize=0,this.fontSizeScale=1,this.textMatrix=J0,this.textMatrixScale=1,this.fontMatrix=Jg,this.leading=0,this.x=0,this.y=0,this.lineX=0,this.lineY=0,this.charSpacing=0,this.wordSpacing=0,this.textHScale=1,this.textRenderingMode=Ee.FILL,this.textRise=0,this.fillColor="#000000",this.strokeColor="#000000",this.patternFill=!1,this.patternStroke=!1,this.fillAlpha=1,this.strokeAlpha=1,this.lineWidth=1,this.activeSMask=null,this.transferMaps="none",this.startNewPathAndClipBox([0,0,t,e])}clone(){const t=Object.create(this);return t.clipBox=this.clipBox.slice(),t}setCurrentPoint(t,e){this.x=t,this.y=e}updatePathMinMax(t,e,s){[e,s]=$.applyTransform([e,s],t),this.minX=Math.min(this.minX,e),this.minY=Math.min(this.minY,s),this.maxX=Math.max(this.maxX,e),this.maxY=Math.max(this.maxY,s)}updateRectMinMax(t,e){const s=$.applyTransform(e,t),i=$.applyTransform(e.slice(2),t),n=$.applyTransform([e[0],e[3]],t),r=$.applyTransform([e[2],e[1]],t);this.minX=Math.min(this.minX,s[0],i[0],n[0],r[0]),this.minY=Math.min(this.minY,s[1],i[1],n[1],r[1]),this.maxX=Math.max(this.maxX,s[0],i[0],n[0],r[0]),this.maxY=Math.max(this.maxY,s[1],i[1],n[1],r[1])}updateScalingPathMinMax(t,e){$.scaleMinMax(t,e),this.minX=Math.min(this.minX,e[0]),this.minY=Math.min(this.minY,e[1]),this.maxX=Math.max(this.maxX,e[2]),this.maxY=Math.max(this.maxY,e[3])}updateCurvePathMinMax(t,e,s,i,n,r,o,h,c,u){const d=$.bezierBoundingBox(e,s,i,n,r,o,h,c,u);u||this.updateRectMinMax(t,d)}getPathBoundingBox(t=ke.FILL,e=null){const s=[this.minX,this.minY,this.maxX,this.maxY];if(t===ke.STROKE){e||St("Stroke bounding box must include transform.");const i=$.singularValueDecompose2dScale(e),n=i[0]*this.lineWidth/2,r=i[1]*this.lineWidth/2;s[0]-=n,s[1]-=r,s[2]+=n,s[3]+=r}return s}updateClipFromPath(){const t=$.intersect(this.clipBox,this.getPathBoundingBox());this.startNewPathAndClipBox(t||[0,0,0,0])}isEmptyClip(){return this.minX===1/0}startNewPathAndClipBox(t){this.clipBox=t,this.minX=1/0,this.minY=1/0,this.maxX=0,this.maxY=0}getClippedPathBoundingBox(t=ke.FILL,e=null){return $.intersect(this.clipBox,this.getPathBoundingBox(t,e))}}function _v(a,t){if(t instanceof ImageData){a.putImageData(t,0,0);return}const e=t.height,s=t.width,i=e%ts,n=(e-i)/ts,r=i===0?n:n+1,o=a.createImageData(s,ts);let h=0,c;const u=t.data,d=o.data;let g,f,p,m;if(t.kind===ju.GRAYSCALE_1BPP){const y=u.byteLength,b=new Uint32Array(d.buffer,0,d.byteLength>>2),x=b.length,C=s+7>>3,A=4294967295,M=Ge.isLittleEndian?4278190080:255;for(g=0;g<r;g++){for(p=g<n?ts:i,c=0,f=0;f<p;f++){const D=y-h;let k=0;const P=D>C?s:D*8-7,R=P&-8;let F=0,I=0;for(;k<R;k+=8)I=u[h++],b[c++]=I&128?A:M,b[c++]=I&64?A:M,b[c++]=I&32?A:M,b[c++]=I&16?A:M,b[c++]=I&8?A:M,b[c++]=I&4?A:M,b[c++]=I&2?A:M,b[c++]=I&1?A:M;for(;k<P;k++)F===0&&(I=u[h++],F=128),b[c++]=I&F?A:M,F>>=1}for(;c<x;)b[c++]=0;a.putImageData(o,0,g*ts)}}else if(t.kind===ju.RGBA_32BPP){for(f=0,m=s*ts*4,g=0;g<n;g++)d.set(u.subarray(h,h+m)),h+=m,a.putImageData(o,0,f),f+=ts;g<r&&(m=s*i*4,d.set(u.subarray(h,h+m)),a.putImageData(o,0,f))}else if(t.kind===ju.RGB_24BPP)for(p=ts,m=s*p,g=0;g<r;g++){for(g>=n&&(p=i,m=s*p),c=0,f=m;f--;)d[c++]=u[h++],d[c++]=u[h++],d[c++]=u[h++],d[c++]=255;a.putImageData(o,0,g*ts)}else throw new Error(`bad image kind: ${t.kind}`)}function wv(a,t){if(t.bitmap){a.drawImage(t.bitmap,0,0);return}const e=t.height,s=t.width,i=e%ts,n=(e-i)/ts,r=i===0?n:n+1,o=a.createImageData(s,ts);let h=0;const c=t.data,u=o.data;for(let d=0;d<r;d++){const g=d<n?ts:i;({srcPos:h}=nS({src:c,srcPos:h,dest:u,width:s,height:g,nonBlackColor:0})),a.putImageData(o,0,d*ts)}}function qh(a,t){const e=["strokeStyle","fillStyle","fillRule","globalAlpha","lineWidth","lineCap","lineJoin","miterLimit","globalCompositeOperation","font","filter"];for(const s of e)a[s]!==void 0&&(t[s]=a[s]);a.setLineDash!==void 0&&(t.setLineDash(a.getLineDash()),t.lineDashOffset=a.lineDashOffset)}function $u(a){if(a.strokeStyle=a.fillStyle="#000000",a.fillRule="nonzero",a.globalAlpha=1,a.lineWidth=1,a.lineCap="butt",a.lineJoin="miter",a.miterLimit=10,a.globalCompositeOperation="source-over",a.font="10px sans-serif",a.setLineDash!==void 0&&(a.setLineDash([]),a.lineDashOffset=0),!Ve){const{filter:t}=a;t!=="none"&&t!==""&&(a.filter="none")}}function xv(a,t){if(t)return!0;const e=$.singularValueDecompose2dScale(a);e[0]=Math.fround(e[0]),e[1]=Math.fround(e[1]);const s=Math.fround((globalThis.devicePixelRatio||1)*Xn.PDF_TO_CSS_UNITS);return e[0]<=s&&e[1]<=s}const lS=["butt","round","square"],cS=["miter","round","bevel"],uS={},Sv={},Nf=class Nf{constructor(t,e,s,i,n,{optionalContentConfig:r,markedContentStack:o=null},h,c){w(this,or);this.ctx=t,this.current=new yv(this.ctx.canvas.width,this.ctx.canvas.height),this.stateStack=[],this.pendingClip=null,this.pendingEOFill=!1,this.res=null,this.xobjs=null,this.commonObjs=e,this.objs=s,this.canvasFactory=i,this.filterFactory=n,this.groupStack=[],this.processingType3=null,this.baseTransform=null,this.baseTransformStack=[],this.groupLevel=0,this.smaskStack=[],this.smaskCounter=0,this.tempSMask=null,this.suspendedCtx=null,this.contentVisible=!0,this.markedContentStack=o||[],this.optionalContentConfig=r,this.cachedCanvases=new aS(this.canvasFactory),this.cachedPatterns=new Map,this.annotationCanvasMap=h,this.viewportScale=1,this.outputScaleX=1,this.outputScaleY=1,this.pageColors=c,this._cachedScaleForStroking=[-1,0],this._cachedGetSinglePixelWidth=null,this._cachedBitmapsMap=new Map}getObject(t,e=null){return typeof t=="string"?t.startsWith("g_")?this.commonObjs.get(t):this.objs.get(t):e}beginDrawing({transform:t,viewport:e,transparency:s=!1,background:i=null}){const n=this.ctx.canvas.width,r=this.ctx.canvas.height,o=this.ctx.fillStyle;if(this.ctx.fillStyle=i||"#ffffff",this.ctx.fillRect(0,0,n,r),this.ctx.fillStyle=o,s){const h=this.cachedCanvases.getCanvas("transparent",n,r);this.compositeCtx=this.ctx,this.transparentCanvas=h.canvas,this.ctx=h.context,this.ctx.save(),this.ctx.transform(...Rt(this.compositeCtx))}this.ctx.save(),$u(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=Rt(this.ctx)}executeOperatorList(t,e,s,i){const n=t.argsArray,r=t.fnArray;let o=e||0;const h=n.length;if(h===o)return o;const c=h-o>vv&&typeof s=="function",u=c?Date.now()+rS:0;let d=0;const g=this.commonObjs,f=this.objs;let p;for(;;){if(i!==void 0&&o===i.nextBreakPoint)return i.breakIt(o,s),o;if(p=r[o],p!==Js.dependency)this[p].apply(this,n[o]);else for(const m of n[o]){const y=m.startsWith("g_")?g:f;if(!y.has(m))return y.get(m,s),o}if(o++,o===h)return o;if(c&&++d>vv){if(Date.now()>u)return s(),o;d=0}}}endDrawing(){_(this,or,fp).call(this),this.cachedCanvases.clear(),this.cachedPatterns.clear();for(const t of this._cachedBitmapsMap.values()){for(const e of t.values())typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement&&(e.width=e.height=0);t.clear()}this._cachedBitmapsMap.clear(),_(this,or,pp).call(this)}_scaleImage(t,e){const s=t.width??t.displayWidth,i=t.height??t.displayHeight;let n=Math.max(Math.hypot(e[0],e[1]),1),r=Math.max(Math.hypot(e[2],e[3]),1),o=s,h=i,c="prescale1",u,d;for(;n>2&&o>1||r>2&&h>1;){let g=o,f=h;n>2&&o>1&&(g=o>=16384?Math.floor(o/2)-1||1:Math.ceil(o/2),n/=o/g),r>2&&h>1&&(f=h>=16384?Math.floor(h/2)-1||1:Math.ceil(h)/2,r/=h/f),u=this.cachedCanvases.getCanvas(c,g,f),d=u.context,d.clearRect(0,0,g,f),d.drawImage(t,0,0,o,h,0,0,g,f),t=u.canvas,o=g,h=f,c=c==="prescale1"?"prescale2":"prescale1"}return{img:t,paintWidth:o,paintHeight:h}}_createMaskCanvas(t){const e=this.ctx,{width:s,height:i}=t,n=this.current.fillColor,r=this.current.patternFill,o=Rt(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?o:[o.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(o[0],o[2])+o[4]),I=Math.round(Math.min(o[1],o[3])+o[5]);return{canvas:R,offsetX:F,offsetY:I}}u=R}u||(d=this.cachedCanvases.getCanvas("maskCanvas",s,i),wv(d.context,t));let g=$.transform(o,[1/s,0,0,-1/i,0,0]);g=$.transform(g,[1,0,0,1,0,-i]);const[f,p,m,y]=$.getAxialAlignedBoundingBox([0,0,s,i],g),b=Math.round(m-f)||1,x=Math.round(y-p)||1,C=this.cachedCanvases.getCanvas("fillCanvas",b,x),A=C.context,M=f,D=p;A.translate(-M,-D),A.transform(...g),u||(u=this._scaleImage(d.canvas,xi(A)),u=u.img,h&&r&&h.set(c,u)),A.imageSmoothingEnabled=xv(Rt(A),t.interpolate),Yu(A,u,0,0,u.width,u.height,0,0,s,i),A.globalCompositeOperation="source-in";const k=$.transform(xi(A),[1,0,0,1,-M,-D]);return A.fillStyle=r?n.getPattern(e,this,k,ke.FILL):n,A.fillRect(0,0,s,i),h&&!r&&(this.cachedCanvases.delete("fillCanvas"),h.set(c,C.canvas)),{canvas:C.canvas,offsetX:Math.round(M),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=lS[t]}setLineJoin(t){this.ctx.lineJoin=cS[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(...Rt(this.suspendedCtx)),qh(this.suspendedCtx,n),oS(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(),qh(this.ctx,this.suspendedCtx),this.ctx=this.suspendedCtx,this.suspendedCtx=null}compose(t){if(!this.current.activeSMask)return;t?(t[0]=Math.floor(t[0]),t[1]=Math.floor(t[1]),t[2]=Math.ceil(t[2]),t[3]=Math.ceil(t[3])):t=[0,0,this.ctx.canvas.width,this.ctx.canvas.height];const e=this.current.activeSMask,s=this.suspendedCtx;this.composeSMask(s,e,this.ctx,t),this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.ctx.restore()}composeSMask(t,e,s,i){const n=i[0],r=i[1],o=i[2]-n,h=i[3]-r;o===0||h===0||(this.genericComposeSMask(e.context,s,o,h,e.subtype,e.backdrop,e.transferMap,n,r,e.offsetX,e.offsetY),t.save(),t.globalAlpha=1,t.globalCompositeOperation="source-over",t.setTransform(1,0,0,1,0,0),t.drawImage(s.canvas,0,0),t.restore())}genericComposeSMask(t,e,s,i,n,r,o,h,c,u,d){let g=t.canvas,f=h-u,p=c-d;if(r){const y=$.makeHexColor(...r);if(f<0||p<0||f+s>g.width||p+i>g.height){const b=this.cachedCanvases.getCanvas("maskExtension",s,i),x=b.context;x.drawImage(g,-f,-p),x.globalCompositeOperation="destination-atop",x.fillStyle=y,x.fillRect(0,0,s,i),x.globalCompositeOperation="source-over",g=b.canvas,f=p=0}else{t.save(),t.globalAlpha=1,t.setTransform(1,0,0,1,0,0);const b=new Path2D;b.rect(f,p,s,i),t.clip(b),t.globalCompositeOperation="destination-atop",t.fillStyle=y,t.fillRect(f,p,s,i),t.restore()}}e.save(),e.globalAlpha=1,e.setTransform(1,0,0,1,0,0),n==="Alpha"&&o?e.filter=this.filterFactory.addAlphaFilter(o):n==="Luminosity"&&(e.filter=this.filterFactory.addLuminosityFilter(o));const m=new Path2D;m.rect(h,c,s,i),e.clip(m),e.globalCompositeOperation="destination-in",e.drawImage(g,f,p,s,i,h,c,s,i),e.restore()}save(){this.inSMaskMode?(qh(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(),qh(this.suspendedCtx,this.ctx)):this.ctx.restore(),this.checkSMaskState(),this.pendingClip=null,this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null)}transform(t,e,s,i,n,r){this.ctx.transform(t,e,s,i,n,r),this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null}constructPath(t,e,s){const i=this.ctx,n=this.current;let r=n.x,o=n.y,h,c;const u=Rt(i),d=u[0]===0&&u[3]===0||u[1]===0&&u[2]===0,g=d?s.slice(0):null;for(let f=0,p=0,m=t.length;f<m;f++)switch(t[f]|0){case Js.rectangle:r=e[p++],o=e[p++];const y=e[p++],b=e[p++],x=r+y,C=o+b;i.moveTo(r,o),y===0||b===0?i.lineTo(x,C):(i.lineTo(x,o),i.lineTo(x,C),i.lineTo(r,C)),d||n.updateRectMinMax(u,[r,o,x,C]),i.closePath();break;case Js.moveTo:r=e[p++],o=e[p++],i.moveTo(r,o),d||n.updatePathMinMax(u,r,o);break;case Js.lineTo:r=e[p++],o=e[p++],i.lineTo(r,o),d||n.updatePathMinMax(u,r,o);break;case Js.curveTo:h=r,c=o,r=e[p+4],o=e[p+5],i.bezierCurveTo(e[p],e[p+1],e[p+2],e[p+3],r,o),n.updateCurvePathMinMax(u,h,c,e[p],e[p+1],e[p+2],e[p+3],r,o,g),p+=6;break;case Js.curveTo2:h=r,c=o,i.bezierCurveTo(r,o,e[p],e[p+1],e[p+2],e[p+3]),n.updateCurvePathMinMax(u,h,c,r,o,e[p],e[p+1],e[p+2],e[p+3],g),r=e[p+2],o=e[p+3],p+=4;break;case Js.curveTo3:h=r,c=o,r=e[p+2],o=e[p+3],i.bezierCurveTo(e[p],e[p+1],r,o,r,o),n.updateCurvePathMinMax(u,h,c,e[p],e[p+1],r,o,r,o,g),p+=4;break;case Js.closePath:i.closePath();break}d&&n.updateScalingPathMinMax(u,g),n.setCurrentPoint(r,o)}closePath(){this.ctx.closePath()}stroke(t=!0){const e=this.ctx,s=this.current.strokeColor;e.globalAlpha=this.current.strokeAlpha,this.contentVisible&&(typeof s=="object"&&(s!=null&&s.getPattern)?(e.save(),e.strokeStyle=s.getPattern(e,this,xi(e),ke.STROKE),this.rescaleAndStroke(!1),e.restore()):this.rescaleAndStroke(!0)),t&&this.consumePath(this.current.getClippedPathBoundingBox()),e.globalAlpha=this.current.fillAlpha}closeStroke(){this.closePath(),this.stroke()}fill(t=!0){const e=this.ctx,s=this.current.fillColor,i=this.current.patternFill;let n=!1;i&&(e.save(),e.fillStyle=s.getPattern(e,this,xi(e),ke.FILL),n=!0);const r=this.current.getClippedPathBoundingBox();this.contentVisible&&r!==null&&(this.pendingEOFill?(e.fill("evenodd"),this.pendingEOFill=!1):e.fill()),n&&e.restore(),t&&this.consumePath(r)}eoFill(){this.pendingEOFill=!0,this.fill()}fillStroke(){this.fill(!1),this.stroke(!1),this.consumePath()}eoFillStroke(){this.pendingEOFill=!0,this.fillStroke()}closeFillStroke(){this.closePath(),this.fillStroke()}closeEOFillStroke(){this.pendingEOFill=!0,this.closePath(),this.fillStroke()}endPath(){this.consumePath()}clip(){this.pendingClip=uS}eoClip(){this.pendingClip=Sv}beginText(){this.current.textMatrix=J0,this.current.textMatrixScale=1,this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0}endText(){const t=this.pendingTextPaths,e=this.ctx;if(t===void 0){e.beginPath();return}e.save(),e.beginPath();for(const s of t)e.setTransform(...s.transform),e.translate(s.x,s.y),s.addToPath(e,s.fontSize);e.restore(),e.clip(),e.beginPath(),delete this.pendingTextPaths}setCharSpacing(t){this.current.charSpacing=t}setWordSpacing(t){this.current.wordSpacing=t}setHScale(t){this.current.textHScale=t/100}setLeading(t){this.current.leading=-t}setFont(t,e){var u;const s=this.commonObjs.get(t),i=this.current;if(!s)throw new Error(`Can't find font for ${t}`);if(i.fontMatrix=s.fontMatrix||Jg,(i.fontMatrix[0]===0||i.fontMatrix[3]===0)&&rt("Invalid font matrix for font "+t),e<0?(e=-e,i.fontDirection=-1):i.fontDirection=1,this.current.font=s,this.current.fontSize=e,s.isType3Font)return;const n=s.loadedName||"sans-serif",r=((u=s.systemFontInfo)==null?void 0:u.css)||`"${n}", ${s.fallbackName}`;let o="normal";s.black?o="900":s.bold&&(o="bold");const h=s.italic?"italic":"normal";let c=e;e<pv?c=pv:e>mv&&(c=mv),this.current.fontSizeScale=e/c,this.ctx.font=`${h} ${o} ${c}px ${r}`}setTextRenderingMode(t){this.current.textRenderingMode=t}setTextRise(t){this.current.textRise=t}moveText(t,e){this.current.x=this.current.lineX+=t,this.current.y=this.current.lineY+=e}setLeadingMoveText(t,e){this.setLeading(-e),this.moveText(t,e)}setTextMatrix(t,e,s,i,n,r){this.current.textMatrix=[t,e,s,i,n,r],this.current.textMatrixScale=Math.hypot(t,e),this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0}nextLine(){this.moveText(0,this.current.leading)}paintChar(t,e,s,i,n){const r=this.ctx,o=this.current,h=o.font,c=o.textRenderingMode,u=o.fontSize/o.fontSizeScale,d=c&Ee.FILL_STROKE_MASK,g=!!(c&Ee.ADD_TO_PATH_FLAG),f=o.patternFill&&!h.missingFile,p=o.patternStroke&&!h.missingFile;let m;(h.disableFontFace||g||f||p)&&(m=h.getPathGenerator(this.commonObjs,t)),h.disableFontFace||f||p?(r.save(),r.translate(e,s),r.beginPath(),m(r,u),(d===Ee.FILL||d===Ee.FILL_STROKE)&&(i&&r.setTransform(...i),r.fill()),(d===Ee.STROKE||d===Ee.FILL_STROKE)&&(n&&r.setTransform(...n),r.stroke()),r.restore()):((d===Ee.FILL||d===Ee.FILL_STROKE)&&r.fillText(t,e,s),(d===Ee.STROKE||d===Ee.FILL_STROKE)&&r.strokeText(t,e,s)),g&&(this.pendingTextPaths||(this.pendingTextPaths=[])).push({transform:Rt(r),x:e,y:s,fontSize:u,addToPath:m})}get isFontSubpixelAAEnabled(){const{context:t}=this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled",10,10);t.scale(1.5,1),t.fillText("I",0,10);const e=t.getImageData(0,0,10,10).data;let s=!1;for(let i=3;i<e.length;i+=4)if(e[i]>0&&e[i]<255){s=!0;break}return at(this,"isFontSubpixelAAEnabled",s)}showText(t){const e=this.current,s=e.font;if(s.isType3Font)return this.showType3Text(t);const i=e.fontSize;if(i===0)return;const n=this.ctx,r=e.fontSizeScale,o=e.charSpacing,h=e.wordSpacing,c=e.fontDirection,u=e.textHScale*c,d=t.length,g=s.vertical,f=g?1:-1,p=s.defaultVMetrics,m=i*e.fontMatrix[0],y=e.textRenderingMode===Ee.FILL&&!s.disableFontFace&&!e.patternFill;n.save(),n.transform(...e.textMatrix),n.translate(e.x,e.y+e.textRise),c>0?n.scale(u,-1):n.scale(u,1);let b,x;if(e.patternFill){n.save();const k=e.fillColor.getPattern(n,this,xi(n),ke.FILL);b=Rt(n),n.restore(),n.fillStyle=k}if(e.patternStroke){n.save();const k=e.strokeColor.getPattern(n,this,xi(n),ke.STROKE);x=Rt(n),n.restore(),n.strokeStyle=k}let C=e.lineWidth;const A=e.textMatrixScale;if(A===0||C===0){const k=e.textRenderingMode&Ee.FILL_STROKE_MASK;(k===Ee.STROKE||k===Ee.FILL_STROKE)&&(C=this.getSinglePixelWidth())}else C/=A;if(r!==1&&(n.scale(r,r),C/=r),n.lineWidth=C,s.isInvalidPDFjsFont){const k=[];let P=0;for(const R of t)k.push(R.unicode),P+=R.width;n.fillText(k.join(""),0,0),e.x+=P*m*u,n.restore(),this.compose();return}let M=0,D;for(D=0;D<d;++D){const k=t[D];if(typeof k=="number"){M+=f*k*i/1e3;continue}let P=!1;const R=(k.isSpace?h:0)+o,F=k.fontChar,I=k.accent;let X,j,N=k.width;if(g){const K=k.vmetric||p,V=-(k.vmetric?K[1]:N*.5)*m,H=K[2]*m;N=K?-K[0]:N,X=V/r,j=(M+H)/r}else X=M/r,j=0;if(s.remeasure&&N>0){const K=n.measureText(F).width*1e3/i*r;if(N<K&&this.isFontSubpixelAAEnabled){const V=N/K;P=!0,n.save(),n.scale(V,1),X/=V}else N!==K&&(X+=(N-K)/2e3*i/r)}if(this.contentVisible&&(k.isInFont||s.missingFile)){if(y&&!I)n.fillText(F,X,j);else if(this.paintChar(F,X,j,b,x),I){const K=X+i*I.offset.x/r,V=j-i*I.offset.y/r;this.paintChar(I.fontChar,K,V,b,x)}}const it=g?N*m-R*c:N*m+R*c;M+=it,P&&n.restore()}g?e.y-=M:e.x+=M*u,n.restore(),this.compose()}showType3Text(t){const e=this.ctx,s=this.current,i=s.font,n=s.fontSize,r=s.fontDirection,o=i.vertical?1:-1,h=s.charSpacing,c=s.wordSpacing,u=s.textHScale*r,d=s.fontMatrix||Jg,g=t.length,f=s.textRenderingMode===Ee.INVISIBLE;let p,m,y,b;if(!(f||n===0)){for(this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null,e.save(),e.transform(...s.textMatrix),e.translate(s.x,s.y),e.scale(u,r),p=0;p<g;++p){if(m=t[p],typeof m=="number"){b=o*m*n/1e3,this.ctx.translate(b,0),s.x+=b*u;continue}const x=(m.isSpace?c:0)+h,C=i.charProcOperatorList[m.operatorListId];if(!C){rt(`Type3 character "${m.operatorListId}" is not available.`);continue}this.contentVisible&&(this.processingType3=m,this.save(),e.scale(n,n),e.transform(...d),this.executeOperatorList(C),this.restore()),y=$.applyTransform([m.width,0],d)[0]*n+x,e.translate(y,0),s.x+=y*u}e.restore(),this.processingType3=null}}setCharWidth(t,e){}setCharWidthAndBounds(t,e,s,i,n,r){this.ctx.rect(s,i,n-s,r-i),this.ctx.clip(),this.endPath()}getColorN_Pattern(t){let e;if(t[0]==="TilingPattern"){const s=t[1],i=this.baseTransform||Rt(this.ctx),n={createCanvasGraphics:r=>new Nf(r,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack})};e=new _f(t,s,this.ctx,n,i)}else e=this._getPattern(t[1],t[2]);return e}setStrokeColorN(){this.current.strokeColor=this.getColorN_Pattern(arguments),this.current.patternStroke=!0}setFillColorN(){this.current.fillColor=this.getColorN_Pattern(arguments),this.current.patternFill=!0}setStrokeRGBColor(t,e,s){this.ctx.strokeStyle=this.current.strokeColor=$.makeHexColor(t,e,s),this.current.patternStroke=!1}setStrokeTransparent(){this.ctx.strokeStyle=this.current.strokeColor="transparent",this.current.patternStroke=!1}setFillRGBColor(t,e,s){this.ctx.fillStyle=this.current.fillColor=$.makeHexColor(t,e,s),this.current.patternFill=!1}setFillTransparent(){this.ctx.fillStyle=this.current.fillColor="transparent",this.current.patternFill=!1}_getPattern(t,e=null){let s;return this.cachedPatterns.has(t)?s=this.cachedPatterns.get(t):(s=iS(this.getObject(t)),this.cachedPatterns.set(t,s)),e&&(s.matrix=e),s}shadingFill(t){if(!this.contentVisible)return;const e=this.ctx;this.save();const s=this._getPattern(t);e.fillStyle=s.getPattern(e,this,xi(e),ke.SHADING);const i=xi(e);if(i){const{width:n,height:r}=e.canvas,[o,h,c,u]=$.getAxialAlignedBoundingBox([0,0,n,r],i);this.ctx.fillRect(o,h,c-o,u-h)}else this.ctx.fillRect(-1e10,-1e10,2e10,2e10);this.compose(this.current.getClippedPathBoundingBox()),this.restore()}beginInlineImage(){St("Should not call beginInlineImage")}beginImageData(){St("Should not call beginImageData")}paintFormXObjectBegin(t,e){if(this.contentVisible&&(this.save(),this.baseTransformStack.push(this.baseTransform),t&&this.transform(...t),this.baseTransform=Rt(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(Rt(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||Hu("TODO: Support non-isolated groups."),t.knockout&&rt("Knockout groups not supported.");const s=Rt(e);if(t.matrix&&e.transform(...t.matrix),!t.bbox)throw new Error("Bounding box is required.");let i=$.getAxialAlignedBoundingBox(t.bbox,Rt(e));const n=[0,0,e.canvas.width,e.canvas.height];i=$.intersect(i,n)||[0,0,0,0];const r=Math.floor(i[0]),o=Math.floor(i[1]),h=Math.max(Math.ceil(i[2])-r,1),c=Math.max(Math.ceil(i[3])-o,1);this.current.startNewPathAndClipBox([0,0,h,c]);let u="groupAt"+this.groupLevel;t.smask&&(u+="_smask_"+this.smaskCounter++%2);const d=this.cachedCanvases.getCanvas(u,h,c),g=d.context;g.translate(-r,-o),g.transform(...s),t.smask?this.smaskStack.push({canvas:d.canvas,context:g,offsetX:r,offsetY:o,subtype:t.smask.subtype,backdrop:t.smask.backdrop,transferMap:t.smask.transferMap||null,startTransformInverse:null}):(e.setTransform(1,0,0,1,0,0),e.translate(r,o),e.save()),qh(e,g),this.ctx=g,this.setGState([["BM","source-over"],["ca",1],["CA",1]]),this.groupStack.push(e),this.groupLevel++}endGroup(t){if(!this.contentVisible)return;this.groupLevel--;const e=this.ctx,s=this.groupStack.pop();if(this.ctx=s,this.ctx.imageSmoothingEnabled=!1,t.smask)this.tempSMask=this.smaskStack.pop(),this.restore();else{this.ctx.restore();const i=Rt(this.ctx);this.restore(),this.ctx.save(),this.ctx.setTransform(...i);const n=$.getAxialAlignedBoundingBox([0,0,e.canvas.width,e.canvas.height],i);this.ctx.drawImage(e.canvas,0,0),this.ctx.restore(),this.compose(n)}}beginAnnotation(t,e,s,i,n){if(_(this,or,fp).call(this),$u(this.ctx),this.ctx.save(),this.save(),this.baseTransform&&this.ctx.setTransform(...this.baseTransform),e){const r=e[2]-e[0],o=e[3]-e[1];if(n&&this.annotationCanvasMap){s=s.slice(),s[4]-=e[0],s[5]-=e[1],e=e.slice(),e[0]=e[1]=0,e[2]=r,e[3]=o;const[h,c]=$.singularValueDecompose2dScale(Rt(this.ctx)),{viewportScale:u}=this,d=Math.ceil(r*this.outputScaleX*u),g=Math.ceil(o*this.outputScaleY*u);this.annotationCanvas=this.canvasFactory.create(d,g);const{canvas:f,context:p}=this.annotationCanvas;this.annotationCanvasMap.set(t,f),this.annotationCanvas.savedCtx=this.ctx,this.ctx=p,this.ctx.save(),this.ctx.setTransform(h,0,0,-c,0,o*c),$u(this.ctx)}else $u(this.ctx),this.endPath(),this.ctx.rect(e[0],e[1],r,o),this.ctx.clip(),this.ctx.beginPath()}this.current=new yv(this.ctx.canvas.width,this.ctx.canvas.height),this.transform(...s),this.transform(...i)}endAnnotation(){this.annotationCanvas&&(this.ctx.restore(),_(this,or,pp).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=hS(t)),i.compiled)){i.compiled(s);return}const n=this._createMaskCanvas(t),r=n.canvas;s.save(),s.setTransform(1,0,0,1,0,0),s.drawImage(r,n.offsetX,n.offsetY),s.restore(),this.compose()}paintImageMaskXObjectRepeat(t,e,s=0,i=0,n,r){if(!this.contentVisible)return;t=this.getObject(t.data,t);const o=this.ctx;o.save();const h=Rt(o);o.transform(e,s,i,n,0,0);const c=this._createMaskCanvas(t);o.setTransform(1,0,0,1,c.offsetX-h[4],c.offsetY-h[5]);for(let u=0,d=r.length;u<d;u+=2){const g=$.transform(h,[e,s,i,n,r[u],r[u+1]]),[f,p]=$.applyTransform([0,0],g);o.drawImage(c.canvas,f,p)}o.restore(),this.compose()}paintImageMaskXObjectGroup(t){if(!this.contentVisible)return;const e=this.ctx,s=this.current.fillColor,i=this.current.patternFill;for(const n of t){const{data:r,width:o,height:h,transform:c}=n,u=this.cachedCanvases.getCanvas("maskCanvas",o,h),d=u.context;d.save();const g=this.getObject(r,n);wv(d,g),d.globalCompositeOperation="source-in",d.fillStyle=i?s.getPattern(d,this,xi(e),ke.FILL):s,d.fillRect(0,0,o,h),d.restore(),e.save(),e.transform(...c),e.scale(1,-1),Yu(e,u.canvas,0,0,o,h,0,-1,1,1),e.restore()}this.compose()}paintImageXObject(t){if(!this.contentVisible)return;const e=this.getObject(t);if(!e){rt("Dependent image isn't ready yet");return}this.paintInlineImageXObject(e)}paintImageXObjectRepeat(t,e,s,i){if(!this.contentVisible)return;const n=this.getObject(t);if(!n){rt("Dependent image isn't ready yet");return}const r=n.width,o=n.height,h=[];for(let c=0,u=i.length;c<u;c+=2)h.push({transform:[e,0,0,s,i[c],i[c+1]],x:0,y:0,w:r,h:o});this.paintInlineImageXObjectGroup(n,h)}applyTransferMapsToCanvas(t){return this.current.transferMaps!=="none"&&(t.filter=this.current.transferMaps,t.drawImage(t.canvas,0,0),t.filter="none"),t.canvas}applyTransferMapsToBitmap(t){if(this.current.transferMaps==="none")return t.bitmap;const{bitmap:e,width:s,height:i}=t,n=this.cachedCanvases.getCanvas("inlineImage",s,i),r=n.context;return r.filter=this.current.transferMaps,r.drawImage(e,0,0),r.filter="none",n.canvas}paintInlineImageXObject(t){if(!this.contentVisible)return;const e=t.width,s=t.height,i=this.ctx;if(this.save(),!Ve){const{filter:o}=i;o!=="none"&&o!==""&&(i.filter="none")}i.scale(1/e,-1/s);let n;if(t.bitmap)n=this.applyTransferMapsToBitmap(t);else if(typeof HTMLElement=="function"&&t instanceof HTMLElement||!t.data)n=t;else{const h=this.cachedCanvases.getCanvas("inlineImage",e,s).context;_v(h,t),n=this.applyTransferMapsToCanvas(h)}const r=this._scaleImage(n,xi(i));i.imageSmoothingEnabled=xv(Rt(i),t.interpolate),Yu(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;_v(h,t),i=this.applyTransferMapsToCanvas(h)}for(const n of e)s.save(),s.transform(...n.transform),s.scale(1,-1),Yu(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===Sv?s.clip("evenodd"):s.clip()),this.pendingClip=null),this.current.startNewPathAndClipBox(this.current.clipBox),s.beginPath()}getSinglePixelWidth(){if(!this._cachedGetSinglePixelWidth){const t=Rt(this.ctx);if(t[1]===0&&t[2]===0)this._cachedGetSinglePixelWidth=1/Math.min(Math.abs(t[0]),Math.abs(t[3]));else{const e=Math.abs(t[0]*t[3]-t[2]*t[1]),s=Math.hypot(t[0],t[2]),i=Math.hypot(t[1],t[3]);this._cachedGetSinglePixelWidth=Math.max(s,i)/e}}return this._cachedGetSinglePixelWidth}getScaleForStroking(){if(this._cachedScaleForStroking[0]===-1){const{lineWidth:t}=this.current,{a:e,b:s,c:i,d:n}=this.ctx.getTransform();let r,o;if(s===0&&i===0){const h=Math.abs(e),c=Math.abs(n);if(h===c)if(t===0)r=o=1/h;else{const u=h*t;r=o=u<1?1/u:1}else if(t===0)r=1/h,o=1/c;else{const u=h*t,d=c*t;r=u<1?1/u:1,o=d<1?1/d:1}}else{const h=Math.abs(e*n-s*i),c=Math.hypot(e,s),u=Math.hypot(i,n);if(t===0)r=u/h,o=c/h;else{const d=t*h;r=u>d?u/d:1,o=c>d?c/d:1}}this._cachedScaleForStroking[0]=r,this._cachedScaleForStroking[1]=o}return this._cachedScaleForStroking}rescaleAndStroke(t){const{ctx:e}=this,{lineWidth:s}=this.current,[i,n]=this.getScaleForStroking();if(e.lineWidth=s||1,i===1&&n===1){e.stroke();return}const r=e.getLineDash();if(t&&e.save(),e.scale(i,n),r.length>0){const o=Math.max(i,n);e.setLineDash(r.map(h=>h/o)),e.lineDashOffset/=o}e.stroke(),t&&e.restore()}isContentVisible(){for(let t=this.markedContentStack.length-1;t>=0;t--)if(!this.markedContentStack[t].visible)return!1;return!0}};or=new WeakSet,fp=function(){for(;this.stateStack.length||this.inSMaskMode;)this.restore();this.current.activeSMask=null,this.ctx.restore(),this.transparentCanvas&&(this.ctx=this.compositeCtx,this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.drawImage(this.transparentCanvas,0,0),this.ctx.restore(),this.transparentCanvas=null)},pp=function(){if(this.pageColors){const t=this.filterFactory.addHCMFilter(this.pageColors.foreground,this.pageColors.background);if(t!=="none"){const e=this.ctx.filter;this.ctx.filter=t,this.ctx.drawImage(this.ctx.canvas,0,0),this.ctx.filter=e}}};let aa=Nf;for(const a in Js)aa.prototype[a]!==void 0&&(aa.prototype[Js[a]]=aa.prototype[a]);class nn{static get workerPort(){return l(this,Sl)}static set workerPort(t){if(!(typeof Worker<"u"&&t instanceof Worker)&&t!==null)throw new Error("Invalid `workerPort` type.");v(this,Sl,t)}static get workerSrc(){return l(this,Cl)}static set workerSrc(t){if(typeof t!="string")throw new Error("Invalid `workerSrc` type.");v(this,Cl,t)}}Sl=new WeakMap,Cl=new WeakMap,w(nn,Sl,null),w(nn,Cl,"");const qu={UNKNOWN:0,DATA:1,ERROR:2},ee={UNKNOWN:0,CANCEL:1,CANCEL_COMPLETE:2,CLOSE:3,ENQUEUE:4,ERROR:5,PULL:6,PULL_COMPLETE:7,START_COMPLETE:8};function us(a){switch(a instanceof Error||typeof a=="object"&&a!==null||St('wrapReason: Expected "reason" to be a (possibly cloned) Error.'),a.name){case"AbortException":return new jr(a.message);case"MissingPDFException":return new Xh(a.message);case"PasswordException":return new tf(a.message,a.code);case"UnexpectedResponseException":return new Vu(a.message,a.status);case"UnknownErrorException":return new ef(a.message,a.details);default:return new ef(a.message,a.toString())}}class Kh{constructor(t,e,s){w(this,Rs);w(this,Ta,new AbortController);this.sourceName=t,this.targetName=e,this.comObj=s,this.callbackId=1,this.streamId=1,this.streamSinks=Object.create(null),this.streamControllers=Object.create(null),this.callbackCapabilities=Object.create(null),this.actionHandler=Object.create(null),s.addEventListener("message",_(this,Rs,Rb).bind(this),{signal:l(this,Ta).signal})}on(t,e){const s=this.actionHandler;if(s[t])throw new Error(`There is already an actionName called "${t}"`);s[t]=e}send(t,e,s){this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:t,data:e},s)}sendWithPromise(t,e,s){const i=this.callbackId++,n=Promise.withResolvers();this.callbackCapabilities[i]=n;try{this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:t,callbackId:i,data:e},s)}catch(r){n.reject(r)}return n.promise}sendWithStream(t,e,s,i){const n=this.streamId++,r=this.sourceName,o=this.targetName,h=this.comObj;return new ReadableStream({start:c=>{const u=Promise.withResolvers();return this.streamControllers[n]={controller:c,startCall:u,pullCall:null,cancelCall:null,isClosed:!1},h.postMessage({sourceName:r,targetName:o,action:t,streamId:n,data:e,desiredSize:c.desiredSize},i),u.promise},pull:c=>{const u=Promise.withResolvers();return this.streamControllers[n].pullCall=u,h.postMessage({sourceName:r,targetName:o,stream:ee.PULL,streamId:n,desiredSize:c.desiredSize}),u.promise},cancel:c=>{te(c instanceof Error,"cancel must have a valid reason");const u=Promise.withResolvers();return this.streamControllers[n].cancelCall=u,this.streamControllers[n].isClosed=!0,h.postMessage({sourceName:r,targetName:o,stream:ee.CANCEL,streamId:n,reason:us(c)}),u.promise}},s)}destroy(){var t;(t=l(this,Ta))==null||t.abort(),v(this,Ta,null)}}Ta=new WeakMap,Rs=new WeakSet,Rb=function({data:t}){if(t.targetName!==this.sourceName)return;if(t.stream){_(this,Rs,Fb).call(this,t);return}if(t.callback){const s=t.callbackId,i=this.callbackCapabilities[s];if(!i)throw new Error(`Cannot resolve callback ${s}`);if(delete this.callbackCapabilities[s],t.callback===qu.DATA)i.resolve(t.data);else if(t.callback===qu.ERROR)i.reject(us(t.reason));else throw new Error("Unexpected callback case");return}const e=this.actionHandler[t.action];if(!e)throw new Error(`Unknown action from worker: ${t.action}`);if(t.callbackId){const s=this.sourceName,i=t.sourceName,n=this.comObj;new Promise(function(r){r(e(t.data))}).then(function(r){n.postMessage({sourceName:s,targetName:i,callback:qu.DATA,callbackId:t.callbackId,data:r})},function(r){n.postMessage({sourceName:s,targetName:i,callback:qu.ERROR,callbackId:t.callbackId,reason:us(r)})});return}if(t.streamId){_(this,Rs,Lb).call(this,t);return}e(t.data)},Lb=function(t){const e=t.streamId,s=this.sourceName,i=t.sourceName,n=this.comObj,r=this,o=this.actionHandler[t.action],h={enqueue(c,u=1,d){if(this.isCancelled)return;const g=this.desiredSize;this.desiredSize-=u,g>0&&this.desiredSize<=0&&(this.sinkCapability=Promise.withResolvers(),this.ready=this.sinkCapability.promise),n.postMessage({sourceName:s,targetName:i,stream:ee.ENQUEUE,streamId:e,chunk:c},d)},close(){this.isCancelled||(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:ee.CLOSE,streamId:e}),delete r.streamSinks[e])},error(c){te(c instanceof Error,"error must have a valid reason"),!this.isCancelled&&(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:ee.ERROR,streamId:e,reason:us(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,new Promise(function(c){c(o(t.data,h))}).then(function(){n.postMessage({sourceName:s,targetName:i,stream:ee.START_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:ee.START_COMPLETE,streamId:e,reason:us(c)})})},Fb=function(t){const e=t.streamId,s=this.sourceName,i=t.sourceName,n=this.comObj,r=this.streamControllers[e],o=this.streamSinks[e];switch(t.stream){case ee.START_COMPLETE:t.success?r.startCall.resolve():r.startCall.reject(us(t.reason));break;case ee.PULL_COMPLETE:t.success?r.pullCall.resolve():r.pullCall.reject(us(t.reason));break;case ee.PULL:if(!o){n.postMessage({sourceName:s,targetName:i,stream:ee.PULL_COMPLETE,streamId:e,success:!0});break}o.desiredSize<=0&&t.desiredSize>0&&o.sinkCapability.resolve(),o.desiredSize=t.desiredSize,new Promise(function(h){var c;h((c=o.onPull)==null?void 0:c.call(o))}).then(function(){n.postMessage({sourceName:s,targetName:i,stream:ee.PULL_COMPLETE,streamId:e,success:!0})},function(h){n.postMessage({sourceName:s,targetName:i,stream:ee.PULL_COMPLETE,streamId:e,reason:us(h)})});break;case ee.ENQUEUE:if(te(r,"enqueue should have stream controller"),r.isClosed)break;r.controller.enqueue(t.chunk);break;case ee.CLOSE:if(te(r,"close should have stream controller"),r.isClosed)break;r.isClosed=!0,r.controller.close(),_(this,Rs,Dd).call(this,r,e);break;case ee.ERROR:te(r,"error should have stream controller"),r.controller.error(us(t.reason)),_(this,Rs,Dd).call(this,r,e);break;case ee.CANCEL_COMPLETE:t.success?r.cancelCall.resolve():r.cancelCall.reject(us(t.reason)),_(this,Rs,Dd).call(this,r,e);break;case ee.CANCEL:if(!o)break;new Promise(function(h){var c;h((c=o.onCancel)==null?void 0:c.call(o,us(t.reason)))}).then(function(){n.postMessage({sourceName:s,targetName:i,stream:ee.CANCEL_COMPLETE,streamId:e,success:!0})},function(h){n.postMessage({sourceName:s,targetName:i,stream:ee.CANCEL_COMPLETE,streamId:e,reason:us(h)})}),o.sinkCapability.reject(us(t.reason)),o.isCancelled=!0,delete this.streamSinks[e];break;default:throw new Error("Unexpected stream case")}},Dd=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 dS{constructor({parsedData:t,rawData:e}){w(this,ho);w(this,Al);v(this,ho,t),v(this,Al,e)}getRaw(){return l(this,Al)}get(t){return l(this,ho).get(t)??null}getAll(){return sf(l(this,ho))}has(t){return l(this,ho).has(t)}}ho=new WeakMap,Al=new WeakMap;const ha=Symbol("INTERNAL");class gS{constructor(t,{name:e,intent:s,usage:i,rbGroups:n}){w(this,Tl,!1);w(this,El,!1);w(this,kl,!1);w(this,Ea,!0);v(this,Tl,!!(t&cs.DISPLAY)),v(this,El,!!(t&cs.PRINT)),this.name=e,this.intent=s,this.usage=i,this.rbGroups=n}get visible(){if(l(this,kl))return l(this,Ea);if(!l(this,Ea))return!1;const{print:t,view:e}=this.usage;return l(this,Tl)?(e==null?void 0:e.viewState)!=="OFF":l(this,El)?(t==null?void 0:t.printState)!=="OFF":!0}_setVisible(t,e,s=!1){t!==ha&&St("Internal method `_setVisible` called."),v(this,kl,s),v(this,Ea,e)}}Tl=new WeakMap,El=new WeakMap,kl=new WeakMap,Ea=new WeakMap;class fS{constructor(t,e=cs.DISPLAY){w(this,Ml);w(this,ar,null);w(this,xt,new Map);w(this,ka,null);w(this,Ma,null);if(this.renderingIntent=e,this.name=null,this.creator=null,t!==null){this.name=t.name,this.creator=t.creator,v(this,Ma,t.order);for(const s of t.groups)l(this,xt).set(s.id,new gS(e,s));if(t.baseState==="OFF")for(const s of l(this,xt).values())s._setVisible(ha,!1);for(const s of t.on)l(this,xt).get(s)._setVisible(ha,!0);for(const s of t.off)l(this,xt).get(s)._setVisible(ha,!1);v(this,ka,this.getHash())}}isVisible(t){if(l(this,xt).size===0)return!0;if(!t)return Hu("Optional content group not defined."),!0;if(t.type==="OCG")return l(this,xt).has(t.id)?l(this,xt).get(t.id).visible:(rt(`Optional content group not found: ${t.id}`),!0);if(t.type==="OCMD"){if(t.expression)return _(this,Ml,mp).call(this,t.expression);if(!t.policy||t.policy==="AnyOn"){for(const e of t.ids){if(!l(this,xt).has(e))return rt(`Optional content group not found: ${e}`),!0;if(l(this,xt).get(e).visible)return!0}return!1}else if(t.policy==="AllOn"){for(const e of t.ids){if(!l(this,xt).has(e))return rt(`Optional content group not found: ${e}`),!0;if(!l(this,xt).get(e).visible)return!1}return!0}else if(t.policy==="AnyOff"){for(const e of t.ids){if(!l(this,xt).has(e))return rt(`Optional content group not found: ${e}`),!0;if(!l(this,xt).get(e).visible)return!0}return!1}else if(t.policy==="AllOff"){for(const e of t.ids){if(!l(this,xt).has(e))return rt(`Optional content group not found: ${e}`),!0;if(l(this,xt).get(e).visible)return!1}return!0}return rt(`Unknown optional content policy ${t.policy}.`),!0}return rt(`Unknown group type ${t.type}.`),!0}setVisibility(t,e=!0,s=!0){var n;const i=l(this,xt).get(t);if(!i){rt(`Optional content group not found: ${t}`);return}if(s&&e&&i.rbGroups.length)for(const r of i.rbGroups)for(const o of r)o!==t&&((n=l(this,xt).get(o))==null||n._setVisible(ha,!1,!0));i._setVisible(ha,!!e,!0),v(this,ar,null)}setOCGState({state:t,preserveRB:e}){let s;for(const i of t){switch(i){case"ON":case"OFF":case"Toggle":s=i;continue}const n=l(this,xt).get(i);if(n)switch(s){case"ON":this.setVisibility(i,!0,e);break;case"OFF":this.setVisibility(i,!1,e);break;case"Toggle":this.setVisibility(i,!n.visible,e);break}}v(this,ar,null)}get hasInitialVisibility(){return l(this,ka)===null||this.getHash()===l(this,ka)}getOrder(){return l(this,xt).size?l(this,Ma)?l(this,Ma).slice():[...l(this,xt).keys()]:null}getGroups(){return l(this,xt).size>0?sf(l(this,xt)):null}getGroup(t){return l(this,xt).get(t)||null}getHash(){if(l(this,ar)!==null)return l(this,ar);const t=new rv;for(const[e,s]of l(this,xt))t.update(`${e}:${s.visible}`);return v(this,ar,t.hexdigest())}}ar=new WeakMap,xt=new WeakMap,ka=new WeakMap,Ma=new WeakMap,Ml=new WeakSet,mp=function(t){const e=t.length;if(e<2)return!0;const s=t[0];for(let i=1;i<e;i++){const n=t[i];let r;if(Array.isArray(n))r=_(this,Ml,mp).call(this,n);else if(l(this,xt).has(n))r=l(this,xt).get(n).visible;else return rt(`Optional content group not found: ${n}`),!0;switch(s){case"And":if(!r)return!1;break;case"Or":if(r)return!0;break;case"Not":return!r;default:return!0}}return s==="And"};class pS{constructor(t,{disableRange:e=!1,disableStream:s=!1}){te(t,'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');const{length:i,initialData:n,progressiveDone:r,contentDispositionFilename:o}=t;if(this._queuedChunks=[],this._progressiveDone=r,this._contentDispositionFilename=o,(n==null?void 0:n.length)>0){const h=n instanceof Uint8Array&&n.byteLength===n.buffer.byteLength?n.buffer:new Uint8Array(n).buffer;this._queuedChunks.push(h)}this._pdfDataRangeTransport=t,this._isStreamingSupported=!s,this._isRangeSupported=!e,this._contentLength=i,this._fullRequestReader=null,this._rangeReaders=[],t.addRangeListener((h,c)=>{this._onReceiveData({begin:h,chunk:c})}),t.addProgressListener((h,c)=>{this._onProgress({loaded:h,total:c})}),t.addProgressiveReadListener(h=>{this._onReceiveData({chunk:h})}),t.addProgressiveDoneListener(()=>{this._onProgressiveDone()}),t.transportReady()}_onReceiveData({begin:t,chunk:e}){const s=e instanceof Uint8Array&&e.byteLength===e.buffer.byteLength?e.buffer:new Uint8Array(e).buffer;if(t===void 0)this._fullRequestReader?this._fullRequestReader._enqueue(s):this._queuedChunks.push(s);else{const i=this._rangeReaders.some(function(n){return n._begin!==t?!1:(n._enqueue(s),!0)});te(i,"_onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.")}}get _progressiveDataLength(){var t;return((t=this._fullRequestReader)==null?void 0:t._loaded)??0}_onProgress(t){var e,s,i,n;t.total===void 0?(s=(e=this._rangeReaders[0])==null?void 0:e.onProgress)==null||s.call(e,{loaded:t.loaded}):(n=(i=this._fullRequestReader)==null?void 0:i.onProgress)==null||n.call(i,{loaded:t.loaded,total:t.total})}_onProgressiveDone(){var t;(t=this._fullRequestReader)==null||t.progressiveDone(),this._progressiveDone=!0}_removeRangeReader(t){const e=this._rangeReaders.indexOf(t);e>=0&&this._rangeReaders.splice(e,1)}getFullReader(){te(!this._fullRequestReader,"PDFDataTransportStream.getFullReader can only be called once.");const t=this._queuedChunks;return this._queuedChunks=null,new mS(this,t,this._progressiveDone,this._contentDispositionFilename)}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new vS(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 mS{constructor(t,e,s=!1,i=null){this._stream=t,this._done=s||!1,this._filename=hf(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 vS{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 bS(a){let t=!0,e=s("filename\\*","i").exec(a);if(e){e=e[1];let u=o(e);return u=unescape(u),u=h(u),u=c(u),n(u)}if(e=r(a),e){const u=c(e);return n(u)}if(e=s("filename","i").exec(a),e){e=e[1];let u=o(e);return u=c(u),n(u)}function s(u,d){return new RegExp("(?:^|;)\\s*"+u+'\\s*=\\s*([^";\\s][^;\\s]*|"(?:[^"\\\\]|\\\\"?)+"?)',d)}function i(u,d){if(u){if(!/^[\x00-\xFF]+$/.test(d))return d;try{const g=new TextDecoder(u,{fatal:!0}),f=Gu(d);d=g.decode(f),t=!1}catch{}}return d}function n(u){return t&&/[\x80-\xff]/.test(u)&&(u=i("utf-8",u),t&&(u=i("iso-8859-1",u))),u}function r(u){const d=[];let g;const f=s("filename\\*((?!0\\d)\\d+)(\\*?)","ig");for(;(g=f.exec(u))!==null;){let[,m,y,b]=g;if(m=parseInt(m,10),m in d){if(m===0)break;continue}d[m]=[y,b]}const p=[];for(let m=0;m<d.length&&m in d;++m){let[y,b]=d[m];b=o(b),y&&(b=unescape(b),m===0&&(b=h(b))),p.push(b)}return p.join("")}function o(u){if(u.startsWith('"')){const d=u.slice(1).split('\\"');for(let g=0;g<d.length;++g){const f=d[g].indexOf('"');f!==-1&&(d[g]=d[g].slice(0,f),d.length=g+1),d[g]=d[g].replaceAll(/\\(.)/g,"$1")}u=d.join('"')}return u}function h(u){const d=u.indexOf("'");if(d===-1)return u;const g=u.slice(0,d),p=u.slice(d+1).replace(/^[^']*'/,"");return i(g,p)}function c(u){return!u.startsWith("=?")||/[\x00-\x19\x80-\xff]/.test(u)?u:u.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,function(d,g,f,p){if(f==="q"||f==="Q")return p=p.replaceAll("_"," "),p=p.replaceAll(/=([0-9a-fA-F]{2})/g,function(m,y){return String.fromCharCode(parseInt(y,16))}),i(g,p);try{p=atob(p)}catch{}return i(g,p)})}return""}function Cv(a,t){const e=new Headers;if(!a||!t||typeof t!="object")return e;for(const s in t){const i=t[s];i!==void 0&&e.append(s,i)}return e}function Ku(a){try{return new URL(a).origin}catch{}return null}function Av({responseHeaders:a,isHttp:t,rangeChunkSize:e,disableRange:s}){const i={allowRangeRequests:!1,suggestedLength:void 0},n=parseInt(a.get("Content-Length"),10);return!Number.isInteger(n)||(i.suggestedLength=n,n<=2*e)||s||!t||a.get("Accept-Ranges")!=="bytes"||(a.get("Content-Encoding")||"identity")!=="identity"||(i.allowRangeRequests=!0),i}function Tv(a){const t=a.get("Content-Disposition");if(t){let e=bS(t);if(e.includes("%"))try{e=decodeURIComponent(e)}catch{}if(hf(e))return e}return null}function Qu(a,t){return a===404||a===0&&t.startsWith("file:")?new Xh('Missing PDF "'+t+'".'):new Vu(`Unexpected server response (${a}) while retrieving PDF "${t}".`,a)}function Ev(a){return a===200||a===206}function kv(a,t,e){return{method:"GET",headers:a,signal:e.signal,mode:"cors",credentials:t?"include":"same-origin",redirect:"follow"}}function Mv(a){return a instanceof Uint8Array?a.buffer:a instanceof ArrayBuffer?a:(rt(`getArrayBuffer - unexpected data format: ${a}`),new Uint8Array(a).buffer)}class Pv{constructor(t){q(this,"_responseOrigin",null);this.source=t,this.isHttp=/^https?:/i.test(t.url),this.headers=Cv(this.isHttp,t.httpHeaders),this._fullRequestReader=null,this._rangeRequestReaders=[]}get _progressiveDataLength(){var t;return((t=this._fullRequestReader)==null?void 0:t._loaded)??0}getFullReader(){return te(!this._fullRequestReader,"PDFFetchStream.getFullReader can only be called once."),this._fullRequestReader=new yS(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new _S(this,t,e);return this._rangeRequestReaders.push(s),s}cancelAllRequests(t){var e;(e=this._fullRequestReader)==null||e.cancel(t);for(const s of this._rangeRequestReaders.slice(0))s.cancel(t)}}class yS{constructor(t){this._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,kv(s,this._withCredentials,this._abortController)).then(n=>{if(t._responseOrigin=Ku(n.url),!Ev(n.status))throw Qu(n.status,i);this._reader=n.body.getReader(),this._headersCapability.resolve();const r=n.headers,{allowRangeRequests:o,suggestedLength:h}=Av({responseHeaders:r,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=o,this._contentLength=h||this._contentLength,this._filename=Tv(r),!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new jr("Streaming is disabled."))}).catch(this._headersCapability.reject),this.onProgress=null}get headersReady(){return this._headersCapability.promise}get filename(){return this._filename}get contentLength(){return this._contentLength}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;await this._headersCapability.promise;const{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:(this._loaded+=t.byteLength,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded,total:this._contentLength}),{value:Mv(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}class _S{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,kv(n,this._withCredentials,this._abortController)).then(o=>{const h=Ku(o.url);if(h!==t._responseOrigin)throw new Error(`Expected range response-origin "${h}" to match "${t._responseOrigin}".`);if(!Ev(o.status))throw Qu(o.status,r);this._readCapability.resolve(),this._reader=o.body.getReader()}).catch(this._readCapability.reject),this.onProgress=null}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;await this._readCapability.promise;const{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:(this._loaded+=t.byteLength,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded}),{value:Mv(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}const wf=200,xf=206;function wS(a){const t=a.response;return typeof t!="string"?t:Gu(t).buffer}class xS{constructor({url:t,httpHeaders:e,withCredentials:s}){q(this,"_responseOrigin",null);this.url=t,this.isHttp=/^https?:/i.test(t),this.headers=Cv(this.isHttp,e),this.withCredentials=s||!1,this.currXhrId=0,this.pendingRequests=Object.create(null)}requestRange(t,e,s){const i={begin:t,end:e};for(const n in s)i[n]=s[n];return this.request(i)}requestFull(t){return this.request(t)}request(t){const e=new XMLHttpRequest,s=this.currXhrId++,i=this.pendingRequests[s]={xhr:e};e.open("GET",this.url),e.withCredentials=this.withCredentials;for(const[n,r]of this.headers)e.setRequestHeader(n,r);return this.isHttp&&"begin"in t&&"end"in t?(e.setRequestHeader("Range",`bytes=${t.begin}-${t.end-1}`),i.expectedStatus=xf):i.expectedStatus=wf,e.responseType="arraybuffer",t.onError&&(e.onerror=function(n){t.onError(e.status)}),e.onreadystatechange=this.onStateChange.bind(this,s),e.onprogress=this.onProgress.bind(this,s),i.onHeadersReceived=t.onHeadersReceived,i.onDone=t.onDone,i.onError=t.onError,i.onProgress=t.onProgress,e.send(null),s}onProgress(t,e){var i;const s=this.pendingRequests[t];s&&((i=s.onProgress)==null||i.call(s,e))}onStateChange(t,e){var h,c,u;const s=this.pendingRequests[t];if(!s)return;const i=s.xhr;if(i.readyState>=2&&s.onHeadersReceived&&(s.onHeadersReceived(),delete s.onHeadersReceived),i.readyState!==4||!(t in this.pendingRequests))return;if(delete this.pendingRequests[t],i.status===0&&this.isHttp){(h=s.onError)==null||h.call(s,i.status);return}const n=i.status||wf;if(!(n===wf&&s.expectedStatus===xf)&&n!==s.expectedStatus){(c=s.onError)==null||c.call(s,i.status);return}const o=wS(i);if(n===xf){const d=i.getResponseHeader("Content-Range"),g=/bytes (\d+)-(\d+)\/(\d+)/.exec(d);s.onDone({begin:parseInt(g[1],10),chunk:o})}else o?s.onDone({begin:0,chunk:o}):(u=s.onError)==null||u.call(s,i.status)}getRequestXhr(t){return this.pendingRequests[t].xhr}isPendingRequest(t){return t in this.pendingRequests}abortRequest(t){const e=this.pendingRequests[t].xhr;delete this.pendingRequests[t],e.abort()}}class SS{constructor(t){this._source=t,this._manager=new xS(t),this._rangeChunkSize=t.rangeChunkSize,this._fullRequestReader=null,this._rangeRequestReaders=[]}_onRangeRequestReaderClosed(t){const e=this._rangeRequestReaders.indexOf(t);e>=0&&this._rangeRequestReaders.splice(e,1)}getFullReader(){return te(!this._fullRequestReader,"PDFNetworkStream.getFullReader can only be called once."),this._fullRequestReader=new CS(this._manager,this._source),this._fullRequestReader}getRangeReader(t,e){const s=new AS(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 CS{constructor(t,e){this._manager=t;const s={onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)};this._url=e.url,this._fullRequestId=t.requestFull(s),this._headersCapability=Promise.withResolvers(),this._disableRange=e.disableRange||!1,this._contentLength=e.length,this._rangeChunkSize=e.rangeChunkSize,!this._rangeChunkSize&&!this._disableRange&&(this._disableRange=!0),this._isStreamingSupported=!1,this._isRangeSupported=!1,this._cachedChunks=[],this._requests=[],this._done=!1,this._storedError=void 0,this._filename=null,this.onProgress=null}_onHeadersReceived(){const t=this._fullRequestId,e=this._manager.getRequestXhr(t);this._manager._responseOrigin=Ku(e.responseURL);const s=e.getAllResponseHeaders(),i=new Headers(s?s.trim().split(/[\r\n]+/).map(o=>{const[h,...c]=o.split(": ");return[h,c.join(": ")]}):[]),{allowRangeRequests:n,suggestedLength:r}=Av({responseHeaders:i,isHttp:this._manager.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});n&&(this._isRangeSupported=!0),this._contentLength=r||this._contentLength,this._filename=Tv(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=Qu(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 AS{constructor(t,e,s){this._manager=t;const i={onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)};this._url=t.url,this._requestId=t.requestRange(e,s,i),this._requests=[],this._queuedChunk=null,this._done=!1,this._storedError=void 0,this.onProgress=null,this.onClosed=null}_onHeadersReceived(){var e;const t=Ku((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=Qu(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 TS=/^[a-z][a-z0-9\-+.]+:/i;function ES(a){if(TS.test(a))return new URL(a);const t=process.getBuiltinModule("url");return new URL(t.pathToFileURL(a))}class kS{constructor(t){this.source=t,this.url=ES(t.url),te(this.url.protocol==="file:","PDFNodeStream only supports file:// URLs."),this._fullRequestReader=null,this._rangeRequestReaders=[]}get _progressiveDataLength(){var t;return((t=this._fullRequestReader)==null?void 0:t._loaded)??0}getFullReader(){return te(!this._fullRequestReader,"PDFNodeStream.getFullReader can only be called once."),this._fullRequestReader=new MS(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new PS(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 MS{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 Xh(`Missing PDF "${this._url}".`)),this._storedError=i,this._headersCapability.reject(i)})}get headersReady(){return this._headersCapability.promise}get filename(){return this._filename}get contentLength(){return this._contentLength}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;if(await this._readCapability.promise,this._done)return{value:void 0,done:!0};if(this._storedError)throw this._storedError;const t=this._readableStream.read();return t===null?(this._readCapability=Promise.withResolvers(),this.read()):(this._loaded+=t.length,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded,total:this._contentLength}),{value:new Uint8Array(t).buffer,done:!1})}cancel(t){if(!this._readableStream){this._error(t);return}this._readableStream.destroy(t)}_error(t){this._storedError=t,this._readCapability.resolve()}_setReadableStream(t){this._readableStream=t,t.on("readable",()=>{this._readCapability.resolve()}),t.on("end",()=>{t.destroy(),this._done=!0,this._readCapability.resolve()}),t.on("error",e=>{this._error(e)}),!this._isStreamingSupported&&this._isRangeSupported&&this._error(new jr("streaming is disabled")),this._storedError&&this._readableStream.destroy(this._storedError)}}class PS{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 OS=1e5,es=30,DS=.8,he=class he{constructor({textContentSource:t,container:e,viewport:s}){w(this,mn);w(this,hr,Promise.withResolvers());w(this,is,null);w(this,Pl,!1);w(this,Ol,!!((Xv=globalThis.FontInspector)!=null&&Xv.enabled));w(this,lo,null);w(this,pn,null);w(this,Dl,0);w(this,Rl,0);w(this,co,null);w(this,Pa,null);w(this,Oa,0);w(this,lr,0);w(this,Da,Object.create(null));w(this,Ll,[]);w(this,Ra,null);w(this,uo,[]);w(this,Fl,new WeakMap);w(this,Il,null);var h;if(t instanceof ReadableStream)v(this,Ra,t);else if(typeof t=="object")v(this,Ra,new ReadableStream({start(c){c.enqueue(t),c.close()}}));else throw new Error('No "textContentSource" parameter specified.');v(this,is,v(this,Pa,e)),v(this,lr,s.scale*(globalThis.devicePixelRatio||1)),v(this,Oa,s.rotation),v(this,pn,{div:null,properties:null,ctx:null});const{pageWidth:i,pageHeight:n,pageX:r,pageY:o}=s.rawDims;v(this,Il,[1,0,0,-1,-r,o+n]),v(this,Rl,i),v(this,Dl,n),_(h=he,fs,Nb).call(h),Nr(e,s),l(this,hr).promise.finally(()=>{l(he,La).delete(this),v(this,pn,null),v(this,Da,null)}).catch(()=>{})}static get fontFamilyMap(){const{isWindows:t,isFirefox:e}=Ge.platform;return at(this,"fontFamilyMap",new Map([["sans-serif",`${t&&e?"Calibri, ":""}sans-serif`],["monospace",`${t&&e?"Lucida Console, ":""}monospace`]]))}render(){const t=()=>{l(this,co).read().then(({value:e,done:s})=>{if(s){l(this,hr).resolve();return}l(this,lo)??v(this,lo,e.lang),Object.assign(l(this,Da),e.styles),_(this,mn,Ib).call(this,e.items),t()},l(this,hr).reject)};return v(this,co,l(this,Ra).getReader()),l(he,La).add(this),t(),l(this,hr).promise}update({viewport:t,onBefore:e=null}){var n;const s=t.scale*(globalThis.devicePixelRatio||1),i=t.rotation;if(i!==l(this,Oa)&&(e==null||e(),v(this,Oa,i),Nr(l(this,Pa),{rotation:i})),s!==l(this,lr)){e==null||e(),v(this,lr,s);const r={div:null,properties:null,ctx:_(n=he,fs,Rd).call(n,l(this,lo))};for(const o of l(this,uo))r.properties=l(this,Fl).get(o),r.div=o,_(this,mn,vp).call(this,r)}}cancel(){var e;const t=new jr("TextLayer task cancelled.");(e=l(this,co))==null||e.cancel(t).catch(()=>{}),v(this,co,null),l(this,hr).reject(t)}get textDivs(){return l(this,uo)}get textContentItemsStr(){return l(this,Ll)}static cleanup(){if(!(l(this,La).size>0)){l(this,go).clear();for(const{canvas:t}of l(this,fo).values())t.remove();l(this,fo).clear()}}};hr=new WeakMap,is=new WeakMap,Pl=new WeakMap,Ol=new WeakMap,lo=new WeakMap,pn=new WeakMap,Dl=new WeakMap,Rl=new WeakMap,co=new WeakMap,Pa=new WeakMap,Oa=new WeakMap,lr=new WeakMap,Da=new WeakMap,Ll=new WeakMap,Ra=new WeakMap,uo=new WeakMap,Fl=new WeakMap,Il=new WeakMap,go=new WeakMap,fo=new WeakMap,jl=new WeakMap,cr=new WeakMap,La=new WeakMap,mn=new WeakSet,Ib=function(t){var i,n;if(l(this,Pl))return;(n=l(this,pn)).ctx??(n.ctx=_(i=he,fs,Rd).call(i,l(this,lo)));const e=l(this,uo),s=l(this,Ll);for(const r of t){if(e.length>OS){rt("Ignoring additional textDivs for performance reasons."),v(this,Pl,!0);return}if(r.str===void 0){if(r.type==="beginMarkedContentProps"||r.type==="beginMarkedContent"){const o=l(this,is);v(this,is,document.createElement("span")),l(this,is).classList.add("markedContent"),r.id!==null&&l(this,is).setAttribute("id",`${r.id}`),o.append(l(this,is))}else r.type==="endMarkedContent"&&v(this,is,l(this,is).parentNode);continue}s.push(r.str),_(this,mn,jb).call(this,r)}},jb=function(t){var m;const e=document.createElement("span"),s={angle:0,canvasWidth:0,hasText:t.str!=="",hasEOL:t.hasEOL,fontSize:0};l(this,uo).push(e);const i=$.transform(l(this,Il),t.transform);let n=Math.atan2(i[1],i[0]);const r=l(this,Da)[t.fontName];r.vertical&&(n+=Math.PI/2);let o=l(this,Ol)&&r.fontSubstitution||r.fontFamily;o=he.fontFamilyMap.get(o)||o;const h=Math.hypot(i[2],i[3]),c=h*_(m=he,fs,Bb).call(m,o,l(this,lo));let u,d;n===0?(u=i[4],d=i[5]-c):(u=i[4]+c*Math.sin(n),d=i[5]-c*Math.cos(n));const g="calc(var(--scale-factor)*",f=e.style;l(this,is)===l(this,Pa)?(f.left=`${(100*u/l(this,Rl)).toFixed(2)}%`,f.top=`${(100*d/l(this,Dl)).toFixed(2)}%`):(f.left=`${g}${u.toFixed(2)}px)`,f.top=`${g}${d.toFixed(2)}px)`),f.fontSize=`${g}${(l(he,cr)*h).toFixed(2)}px)`,f.fontFamily=o,s.fontSize=h,e.setAttribute("role","presentation"),e.textContent=t.str,e.dir=t.dir,l(this,Ol)&&(e.dataset.fontName=r.fontSubstitutionLoadedName||t.fontName),n!==0&&(s.angle=n*(180/Math.PI));let p=!1;if(t.str.length>1)p=!0;else if(t.str!==" "&&t.transform[0]!==t.transform[3]){const y=Math.abs(t.transform[0]),b=Math.abs(t.transform[3]);y!==b&&Math.max(y,b)/Math.min(y,b)>1.5&&(p=!0)}if(p&&(s.canvasWidth=r.vertical?t.height:t.width),l(this,Fl).set(e,s),l(this,pn).div=e,l(this,pn).properties=s,_(this,mn,vp).call(this,l(this,pn)),s.hasText&&l(this,is).append(e),s.hasEOL){const y=document.createElement("br");y.setAttribute("role","presentation"),l(this,is).append(y)}},vp=function(t){var o;const{div:e,properties:s,ctx:i}=t,{style:n}=e;let r="";if(l(he,cr)>1&&(r=`scale(${1/l(he,cr)})`),s.canvasWidth!==0&&s.hasText){const{fontFamily:h}=n,{canvasWidth:c,fontSize:u}=s;_(o=he,fs,bp).call(o,i,u*l(this,lr),h);const{width:d}=i.measureText(e.textContent);d>0&&(r=`scaleX(${c*l(this,lr)/d}) ${r}`)}s.angle!==0&&(r=`rotate(${s.angle}deg) ${r}`),r.length>0&&(n.transform=r)},fs=new WeakSet,Rd=function(t=null){let e=l(this,fo).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,fo).set(t,e),l(this,jl).set(e,{size:0,family:""})}return e},bp=function(t,e,s){const i=l(this,jl).get(t);e===i.size&&s===i.family||(t.font=`${e}px ${s}`,i.size=e,i.family=s)},Nb=function(){if(l(this,cr)!==null)return;const t=document.createElement("div");t.style.opacity=0,t.style.lineHeight=1,t.style.fontSize="1px",t.style.position="absolute",t.textContent="X",document.body.append(t),v(this,cr,t.getBoundingClientRect().height),t.remove()},Bb=function(t,e){const s=l(this,go).get(t);if(s)return s;const i=_(this,fs,Rd).call(this,e);i.canvas.width=i.canvas.height=es,_(this,fs,bp).call(this,i,es,t);const n=i.measureText("");let r=n.fontBoundingBoxAscent,o=Math.abs(n.fontBoundingBoxDescent);if(r){const u=r/(r+o);return l(this,go).set(t,u),i.canvas.width=i.canvas.height=0,u}i.strokeStyle="red",i.clearRect(0,0,es,es),i.strokeText("g",0,0);let h=i.getImageData(0,0,es,es).data;o=0;for(let u=h.length-1-3;u>=0;u-=4)if(h[u]>0){o=Math.ceil(u/4/es);break}i.clearRect(0,0,es,es),i.strokeText("A",0,es),h=i.getImageData(0,0,es,es).data,r=0;for(let u=0,d=h.length;u<d;u+=4)if(h[u]>0){r=es-Math.floor(u/4/es);break}i.canvas.width=i.canvas.height=0;const c=r?r/(r+o):DS;return l(this,go).set(t,c),c},w(he,fs),w(he,go,new Map),w(he,fo,new Map),w(he,jl,new WeakMap),w(he,cr,null),w(he,La,new Set);let Qh=he;class Jh{static textContent(t){const e=[],s={items:e,styles:Object.create(null)};function i(n){var h;if(!n)return;let r=null;const o=n.name;if(o==="#text")r=n.value;else if(Jh.shouldBuildText(o))(h=n==null?void 0:n.attributes)!=null&&h.textContent?r=n.attributes.textContent:n.value&&(r=n.value);else return;if(r!==null&&e.push({str:r}),!!n.children)for(const c of n.children)i(c)}return i(t),s}static shouldBuildText(t){return!(t==="textarea"||t==="input"||t==="option"||t==="select")}}const RS=65536,LS=100,FS=5e3,IS=Ve?Kx:Yx,jS=Ve?Qx:lv,NS=Ve?qx:$x,BS=Ve?Jx:dv;function HS(a={}){typeof a=="string"||a instanceof URL?a={url:a}:(a instanceof ArrayBuffer||ArrayBuffer.isView(a))&&(a={data:a});const t=new Sf,{docId:e}=t,s=a.url?VS(a.url):null,i=a.data?GS(a.data):null,n=a.httpHeaders||null,r=a.withCredentials===!0,o=a.password??null,h=a.range instanceof Dv?a.range:null,c=Number.isInteger(a.rangeChunkSize)&&a.rangeChunkSize>0?a.rangeChunkSize:RS;let u=a.worker instanceof la?a.worker:null;const d=a.verbosity,g=typeof a.docBaseUrl=="string"&&!zu(a.docBaseUrl)?a.docBaseUrl:null,f=typeof a.cMapUrl=="string"?a.cMapUrl:null,p=a.cMapPacked!==!1,m=a.CMapReaderFactory||jS,y=typeof a.standardFontDataUrl=="string"?a.standardFontDataUrl:null,b=a.StandardFontDataFactory||BS,x=a.stopAtErrors!==!0,C=Number.isInteger(a.maxImageSize)&&a.maxImageSize>-1?a.maxImageSize:-1,A=a.isEvalSupported!==!1,M=typeof a.isOffscreenCanvasSupported=="boolean"?a.isOffscreenCanvasSupported:!Ve,D=typeof a.isImageDecoderSupported=="boolean"?a.isImageDecoderSupported:!Ve&&(Ge.platform.isFirefox||!globalThis.chrome),k=Number.isInteger(a.canvasMaxAreaInBytes)?a.canvasMaxAreaInBytes:-1,P=typeof a.disableFontFace=="boolean"?a.disableFontFace:Ve,R=a.fontExtraProperties===!0,F=a.enableXfa===!0,I=a.ownerDocument||globalThis.document,X=a.disableRange===!0,j=a.disableStream===!0,N=a.disableAutoFetch===!0,it=a.pdfBug===!0,K=a.CanvasFactory||IS,V=a.FilterFactory||NS,H=a.enableHWA===!0,Et=h?h.length:a.length??NaN,It=typeof a.useSystemFonts=="boolean"?a.useSystemFonts:!Ve&&!P,ie=typeof a.useWorkerFetch=="boolean"?a.useWorkerFetch:m===lv&&b===dv&&f&&y&&Yh(f,document.baseURI)&&Yh(y,document.baseURI);a.canvasFactory&&iv("`canvasFactory`-instance option, please use `CanvasFactory` instead."),a.filterFactory&&iv("`filterFactory`-instance option, please use `FilterFactory` instead.");const Wt=null;Ax(d);const Tt={canvasFactory:new K({ownerDocument:I,enableHWA:H}),filterFactory:new V({docId:e,ownerDocument:I}),cMapReaderFactory:ie?null:new m({baseUrl:f,isCompressed:p}),standardFontDataFactory:ie?null:new b({baseUrl:y})};if(!u){const Pt={verbosity:d,port:nn.workerPort};u=Pt.port?la.fromPort(Pt):new la(Pt),t._worker=u}const xe={docId:e,apiVersion:"4.9.124",data:i,password:o,disableAutoFetch:N,rangeChunkSize:c,length:Et,docBaseUrl:g,enableXfa:F,evaluatorOptions:{maxImageSize:C,disableFontFace:P,ignoreErrors:x,isEvalSupported:A,isOffscreenCanvasSupported:M,isImageDecoderSupported:D,canvasMaxAreaInBytes:k,fontExtraProperties:R,useSystemFonts:It,cMapUrl:ie?f:null,standardFontDataUrl:ie?y:null}},Vs={disableFontFace:P,fontExtraProperties:R,ownerDocument:I,pdfBug:it,styleElement:Wt,loadingParams:{disableAutoFetch:N,enableXfa:F}};return u.promise.then(function(){if(t.destroyed)throw new Error("Loading aborted");if(u.destroyed)throw new Error("Worker was destroyed");const Pt=u.messageHandler.sendWithPromise("GetDocRequest",xe,i?[i.buffer]:null);let gt;if(h)gt=new pS(h,{disableRange:X,disableStream:j});else if(!i){if(!s)throw new Error("getDocument - no `url` parameter provided.");let Cs;if(Ve)if(Yh(s)){if(typeof fetch>"u"||typeof Response>"u"||!("body"in Response.prototype))throw new Error("getDocument - the Fetch API was disabled in Node.js, see `--no-experimental-fetch`.");Cs=Pv}else Cs=kS;else Cs=Yh(s)?Pv:SS;gt=new Cs({url:s,length:Et,httpHeaders:n,withCredentials:r,rangeChunkSize:c,disableRange:X,disableStream:j})}return Pt.then(Cs=>{if(t.destroyed)throw new Error("Loading aborted");if(u.destroyed)throw new Error("Worker was destroyed");const Wi=new Kh(e,Cs,u.port),$e=new US(Wi,t,gt,Vs,Tt);t._transport=$e,Wi.send("Ready",null)})}).catch(t._capability.reject),t}function VS(a){if(a instanceof URL)return a.href;try{return new URL(a,window.location).href}catch{if(Ve&&typeof a=="string")return a}throw new Error("Invalid PDF url data: either string or URL-object is expected in the url property.")}function GS(a){if(Ve&&typeof Buffer<"u"&&a instanceof Buffer)throw new Error("Please provide binary data as `Uint8Array`, rather than `Buffer`.");if(a instanceof Uint8Array&&a.byteLength===a.buffer.byteLength)return a;if(typeof a=="string")return Gu(a);if(a instanceof ArrayBuffer||ArrayBuffer.isView(a)||typeof a=="object"&&!isNaN(a==null?void 0:a.length))return new Uint8Array(a);throw new Error("Invalid PDF binary data: either TypedArray, string, or array-like object is expected in the data property.")}function Ov(a){return typeof a=="object"&&Number.isInteger(a==null?void 0:a.num)&&a.num>=0&&Number.isInteger(a==null?void 0:a.gen)&&a.gen>=0}const gd=class gd{constructor(){this._capability=Promise.withResolvers(),this._transport=null,this._worker=null,this.docId=`d${Ke(gd,dd)._++}`,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}};dd=new WeakMap,w(gd,dd,0);let Sf=gd;class Dv{constructor(t,e,s=!1,i=null){this.length=t,this.initialData=e,this.progressiveDone=s,this.contentDispositionFilename=i,this._rangeListeners=[],this._progressListeners=[],this._progressiveReadListeners=[],this._progressiveDoneListeners=[],this._readyCapability=Promise.withResolvers()}addRangeListener(t){this._rangeListeners.push(t)}addProgressListener(t){this._progressListeners.push(t)}addProgressiveReadListener(t){this._progressiveReadListeners.push(t)}addProgressiveDoneListener(t){this._progressiveDoneListeners.push(t)}onDataRange(t,e){for(const s of this._rangeListeners)s(t,e)}onDataProgress(t,e){this._readyCapability.promise.then(()=>{for(const s of this._progressListeners)s(t,e)})}onDataProgressiveRead(t){this._readyCapability.promise.then(()=>{for(const e of this._progressiveReadListeners)e(t)})}onDataProgressiveDone(){this._readyCapability.promise.then(()=>{for(const t of this._progressiveDoneListeners)t()})}transportReady(){this._readyCapability.resolve()}requestDataRange(t,e){St("Abstract method PDFDataRangeTransport.requestDataRange")}abort(){}}class WS{constructor(t,e){this._pdfInfo=t,this._transport=e}get annotationStorage(){return this._transport.annotationStorage}get canvasFactory(){return this._transport.canvasFactory}get filterFactory(){return this._transport.filterFactory}get numPages(){return this._pdfInfo.numPages}get fingerprints(){return this._pdfInfo.fingerprints}get isPureXfa(){return at(this,"isPureXfa",!!this._transport._htmlForXfa)}get allXfaHtml(){return this._transport._htmlForXfa}getPage(t){return this._transport.getPage(t)}getPageIndex(t){return this._transport.getPageIndex(t)}getDestinations(){return this._transport.getDestinations()}getDestination(t){return this._transport.getDestination(t)}getPageLabels(){return this._transport.getPageLabels()}getPageLayout(){return this._transport.getPageLayout()}getPageMode(){return this._transport.getPageMode()}getViewerPreferences(){return this._transport.getViewerPreferences()}getOpenAction(){return this._transport.getOpenAction()}getAttachments(){return this._transport.getAttachments()}getJSActions(){return this._transport.getDocJSActions()}getOutline(){return this._transport.getOutline()}getOptionalContentConfig({intent:t="display"}={}){const{renderingIntent:e}=this._transport.getRenderingIntent(t);return this._transport.getOptionalContentConfig(e)}getPermissions(){return this._transport.getPermissions()}getMetadata(){return this._transport.getMetadata()}getMarkInfo(){return this._transport.getMarkInfo()}getData(){return this._transport.getData()}saveDocument(){return this._transport.saveDocument()}getDownloadInfo(){return this._transport.downloadInfoCapability.promise}cleanup(t=!1){return this._transport.startCleanup(t||this.isPureXfa)}destroy(){return this.loadingTask.destroy()}cachedPageNumber(t){return this._transport.cachedPageNumber(t)}get loadingParams(){return this._transport.loadingParams}get loadingTask(){return this._transport.loadingTask}getFieldObjects(){return this._transport.getFieldObjects()}hasJSActions(){return this._transport.hasJSActions()}getCalculationOrderIds(){return this._transport.getCalculationOrderIds()}}class zS{constructor(t,e,s,i=!1){w(this,Ls);w(this,ur,null);w(this,vn,!1);this._pageIndex=t,this._pageInfo=e,this._transport=s,this._stats=i?new sv:null,this._pdfBug=i,this.commonObjs=s.commonObjs,this.objs=new Rv,this._maybeCleanupAfterRender=!1,this._intentStates=new Map,this.destroyed=!1}get pageNumber(){return this._pageIndex+1}get rotate(){return this._pageInfo.rotate}get ref(){return this._pageInfo.ref}get userUnit(){return this._pageInfo.userUnit}get view(){return this._pageInfo.view}getViewport({scale:t,rotation:e=this.rotate,offsetX:s=0,offsetY:i=0,dontFlip:n=!1}={}){return new Uh({viewBox:this.view,scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}getAnnotations({intent:t="display"}={}){const{renderingIntent:e}=this._transport.getRenderingIntent(t);return this._transport.getAnnotations(this._pageIndex,e)}getJSActions(){return this._transport.getPageJSActions(this._pageIndex)}get filterFactory(){return this._transport.filterFactory}get isPureXfa(){return at(this,"isPureXfa",!!this._transport._htmlForXfa)}async getXfa(){var t;return((t=this._transport._htmlForXfa)==null?void 0:t.children[this._pageIndex])||null}render({canvasContext:t,viewport:e,intent:s="display",annotationMode:i=Wn.ENABLE,transform:n=null,background:r=null,optionalContentConfigPromise:o=null,annotationCanvasMap:h=null,pageColors:c=null,printAnnotationStorage:u=null,isEditing:d=!1}){var A,M;(A=this._stats)==null||A.time("Overall");const g=this._transport.getRenderingIntent(s,i,u,d),{renderingIntent:f,cacheKey:p}=g;v(this,vn,!1),_(this,Ls,Ld).call(this),o||(o=this._transport.getOptionalContentConfig(f));let m=this._intentStates.get(p);m||(m=Object.create(null),this._intentStates.set(p,m)),m.streamReaderCancelTimeout&&(clearTimeout(m.streamReaderCancelTimeout),m.streamReaderCancelTimeout=null);const y=!!(f&cs.PRINT);m.displayReadyCapability||(m.displayReadyCapability=Promise.withResolvers(),m.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(M=this._stats)==null||M.time("Page Request"),this._pumpOperatorList(g));const b=D=>{var k;m.renderTasks.delete(x),(this._maybeCleanupAfterRender||y)&&v(this,vn,!0),_(this,Ls,wh).call(this,!y),D?(x.capability.reject(D),this._abortOperatorList({intentState:m,reason:D instanceof Error?D:new Error(D)})):x.capability.resolve(),this._stats&&(this._stats.timeEnd("Rendering"),this._stats.timeEnd("Overall"),(k=globalThis.Stats)!=null&&k.enabled&&globalThis.Stats.add(this.pageNumber,this._stats))},x=new Cf({callback:b,params:{canvasContext:t,viewport:e,transform:n,background:r},objs:this.objs,commonObjs:this.commonObjs,annotationCanvasMap:h,operatorList:m.operatorList,pageIndex:this._pageIndex,canvasFactory:this._transport.canvasFactory,filterFactory:this._transport.filterFactory,useRequestAnimationFrame:!y,pdfBug:this._pdfBug,pageColors:c});(m.renderTasks||(m.renderTasks=new Set)).add(x);const C=x.task;return Promise.all([m.displayReadyCapability.promise,o]).then(([D,k])=>{var P;if(this.destroyed){b();return}if((P=this._stats)==null||P.time("Rendering"),!(k.renderingIntent&f))throw new Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");x.initializeGraphics({transparency:D,optionalContentConfig:k}),x.operatorListChanged()}).catch(b),C}getOperatorList({intent:t="display",annotationMode:e=Wn.ENABLE,printAnnotationStorage:s=null,isEditing:i=!1}={}){var c;function n(){o.operatorList.lastChunk&&(o.opListReadCapability.resolve(o.operatorList),o.renderTasks.delete(h))}const r=this._transport.getRenderingIntent(t,e,s,i,!0);let o=this._intentStates.get(r.cacheKey);o||(o=Object.create(null),this._intentStates.set(r.cacheKey,o));let h;return o.opListReadCapability||(h=Object.create(null),h.operatorListChanged=n,o.opListReadCapability=Promise.withResolvers(),(o.renderTasks||(o.renderTasks=new Set)).add(h),o.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(c=this._stats)==null||c.time("Page Request"),this._pumpOperatorList(r)),o.opListReadCapability.promise}streamTextContent({includeMarkedContent:t=!1,disableNormalization:e=!1}={}){return this._transport.messageHandler.sendWithStream("GetTextContent",{pageIndex:this._pageIndex,includeMarkedContent:t===!0,disableNormalization:e===!0},{highWaterMark:100,size(i){return i.items.length}})}getTextContent(t={}){if(this._transport._htmlForXfa)return this.getXfa().then(s=>Jh.textContent(s));const e=this.streamTextContent(t);return new Promise(function(s,i){function n(){r.read().then(function({value:h,done:c}){if(c){s(o);return}o.lang??(o.lang=h.lang),Object.assign(o.styles,h.styles),o.items.push(...h.items),n()},i)}const r=e.getReader(),o={items:[],styles:Object.create(null),lang:null};n()})}getStructTree(){return this._transport.getStructTree(this._pageIndex)}_destroy(){this.destroyed=!0;const t=[];for(const e of this._intentStates.values())if(this._abortOperatorList({intentState:e,reason:new Error("Page was destroyed."),force:!0}),!e.opListReadCapability)for(const s of e.renderTasks)t.push(s.completed),s.cancel();return this.objs.clear(),v(this,vn,!1),_(this,Ls,Ld).call(this),Promise.all(t)}cleanup(t=!1){v(this,vn,!0);const e=_(this,Ls,wh).call(this,!1);return t&&e&&this._stats&&(this._stats=new sv),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&&_(this,Ls,wh).call(this,!0)}_pumpOperatorList({renderingIntent:t,cacheKey:e,annotationStorageSerializable:s,modifiedIds:i}){const{map:n,transfer:r}=s,h=this._transport.messageHandler.sendWithStream("GetOperatorList",{pageIndex:this._pageIndex,intent:t,cacheKey:e,annotationStorage:n,modifiedIds:i},r).getReader(),c=this._intentStates.get(e);c.streamReader=h;const u=()=>{h.read().then(({value:d,done:g})=>{if(g){c.streamReader=null;return}this._transport.destroyed||(this._renderPageChunk(d,c),u())},d=>{if(c.streamReader=null,!this._transport.destroyed){if(c.operatorList){c.operatorList.lastChunk=!0;for(const g of c.renderTasks)g.operatorListChanged();_(this,Ls,wh).call(this,!0)}if(c.displayReadyCapability)c.displayReadyCapability.reject(d);else if(c.opListReadCapability)c.opListReadCapability.reject(d);else throw d}})};u()}_abortOperatorList({intentState:t,reason:e,force:s=!1}){if(t.streamReader){if(t.streamReaderCancelTimeout&&(clearTimeout(t.streamReaderCancelTimeout),t.streamReaderCancelTimeout=null),!s){if(t.renderTasks.size>0)return;if(e instanceof af){let i=LS;e.extraDelay>0&&e.extraDelay<1e3&&(i+=e.extraDelay),t.streamReaderCancelTimeout=setTimeout(()=>{t.streamReaderCancelTimeout=null,this._abortOperatorList({intentState:t,reason:e,force:!0})},i);return}}if(t.streamReader.cancel(new jr(e.message)).catch(()=>{}),t.streamReader=null,!this._transport.destroyed){for(const[i,n]of this._intentStates)if(n===t){this._intentStates.delete(i);break}this.cleanup()}}}get stats(){return this._stats}}ur=new WeakMap,vn=new WeakMap,Ls=new WeakSet,wh=function(t=!1){if(_(this,Ls,Ld).call(this),!l(this,vn)||this.destroyed)return!1;if(t)return v(this,ur,setTimeout(()=>{v(this,ur,null),_(this,Ls,wh).call(this,!1)},FS)),!1;for(const{renderTasks:e,operatorList:s}of this._intentStates.values())if(e.size>0||!s.lastChunk)return!1;return this._intentStates.clear(),this.objs.clear(),v(this,vn,!1),!0},Ld=function(){l(this,ur)&&(clearTimeout(l(this,ur)),v(this,ur,null))};class XS{constructor(){w(this,bn,new Map);w(this,fd,Promise.resolve())}postMessage(t,e){const s={data:structuredClone(t,e?{transfer:e}:null)};l(this,fd).then(()=>{for(const[i]of l(this,bn))i.call(this,s)})}addEventListener(t,e,s=null){let i=null;if((s==null?void 0:s.signal)instanceof AbortSignal){const{signal:n}=s;if(n.aborted){rt("LoopbackPort - cannot use an `aborted` signal.");return}const r=()=>this.removeEventListener(t,e);i=()=>n.removeEventListener("abort",r),n.addEventListener("abort",r)}l(this,bn).set(e,i)}removeEventListener(t,e){const s=l(this,bn).get(e);s==null||s(),l(this,bn).delete(e)}terminate(){for(const[,t]of l(this,bn))t==null||t();l(this,bn).clear()}}bn=new WeakMap,fd=new WeakMap;const Lt=class Lt{constructor({name:t=null,port:e=null,verbosity:s=Tx()}={}){w(this,Fa);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(Lt,mo))!=null&&i.has(e))throw new Error("Cannot use more than one PDFWorker per port.");(l(Lt,mo)||v(Lt,mo,new WeakMap)).set(e,this),this._initializeFromPort(e);return}this._initialize()}get promise(){return this._readyCapability.promise}get port(){return this._port}get messageHandler(){return this._messageHandler}_initializeFromPort(t){this._port=t,this._messageHandler=new Kh("main","worker",t),this._messageHandler.on("ready",function(){}),_(this,Fa,Fd).call(this)}_initialize(){if(l(Lt,po)||l(Lt,Ia,Id)){this._setupFakeWorker();return}let{workerSrc:t}=Lt;try{Lt._isSameOrigin(window.location.href,t)||(t=Lt._createCDNWrapper(new URL(t,window.location).href));const e=new Worker(t,{type:"module"}),s=new Kh("main","worker",e),i=()=>{n.abort(),s.destroy(),e.terminate(),this.destroyed?this._readyCapability.reject(new Error("Worker was destroyed")):this._setupFakeWorker()},n=new AbortController;e.addEventListener("error",()=>{this._webWorker||i()},{signal:n.signal}),s.on("test",o=>{if(n.abort(),this.destroyed||!o){i();return}this._messageHandler=s,this._port=e,this._webWorker=e,_(this,Fa,Fd).call(this)}),s.on("ready",o=>{if(n.abort(),this.destroyed){i();return}try{r()}catch{this._setupFakeWorker()}});const r=()=>{const o=new Uint8Array;s.send("test",o,[o.buffer])};r();return}catch{Hu("The worker has been disabled.")}this._setupFakeWorker()}_setupFakeWorker(){l(Lt,po)||(rt("Setting up fake worker."),v(Lt,po,!0)),Lt._setupFakeWorkerGlobal.then(t=>{if(this.destroyed){this._readyCapability.reject(new Error("Worker was destroyed"));return}const e=new XS;this._port=e;const s=`fake${Ke(Lt,pd)._++}`,i=new Kh(s+"_worker",s,e);t.setup(i,e),this._messageHandler=new Kh(s,s+"_worker",e),_(this,Fa,Fd).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(Lt,mo))==null||e.delete(this._port),this._port=null,(s=this._messageHandler)==null||s.destroy(),this._messageHandler=null}static fromPort(t){var s;if(!(t!=null&&t.port))throw new Error("PDFWorker.fromPort - invalid method signature.");const e=(s=l(this,mo))==null?void 0:s.get(t.port);if(e){if(e._pendingDestroy)throw new Error("PDFWorker.fromPort - the worker is being destroyed.\nPlease remember to await `PDFDocumentLoadingTask.destroy()`-calls.");return e}return new Lt(t)}static get workerSrc(){if(nn.workerSrc)return nn.workerSrc;throw new Error('No "GlobalWorkerOptions.workerSrc" specified.')}static get _setupFakeWorkerGlobal(){return at(this,"_setupFakeWorkerGlobal",(async()=>l(this,Ia,Id)?l(this,Ia,Id):(await import(this.workerSrc)).WorkerMessageHandler)())}};pd=new WeakMap,po=new WeakMap,mo=new WeakMap,Fa=new WeakSet,Fd=function(){this._readyCapability.resolve(),this._messageHandler.send("configure",{verbosity:this.verbosity})},Ia=new WeakSet,Id=function(){var t;try{return((t=globalThis.pdfjsWorker)==null?void 0:t.WorkerMessageHandler)||null}catch{return null}},w(Lt,Ia),w(Lt,pd,0),w(Lt,po,!1),w(Lt,mo),Ve&&(v(Lt,po,!0),nn.workerSrc||(nn.workerSrc="./pdf.worker.mjs")),Lt._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},Lt._createCDNWrapper=t=>{const e=`await import("${t}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))};let la=Lt;class US{constructor(t,e,s,i,n){w(this,vo);w(this,yn,new Map);w(this,Ri,new Map);w(this,ja,new Map);w(this,Na,new Map);w(this,Li,null);this.messageHandler=t,this.loadingTask=e,this.commonObjs=new Rv,this.fontLoader=new Xx({ownerDocument:i.ownerDocument,styleElement:i.styleElement}),this.loadingParams=i.loadingParams,this._params=i,this.canvasFactory=n.canvasFactory,this.filterFactory=n.filterFactory,this.cMapReaderFactory=n.cMapReaderFactory,this.standardFontDataFactory=n.standardFontDataFactory,this.destroyed=!1,this.destroyCapability=null,this._networkStream=s,this._fullReader=null,this._lastProgress=null,this.downloadInfoCapability=Promise.withResolvers(),this.setupMessageHandler()}get annotationStorage(){return at(this,"annotationStorage",new mf)}getRenderingIntent(t,e=Wn.ENABLE,s=null,i=!1,n=!1){let r=cs.DISPLAY,o=pf;switch(t){case"any":r=cs.ANY;break;case"display":break;case"print":r=cs.PRINT;break;default:rt(`getRenderingIntent - invalid intent: ${t}`)}const h=r&cs.PRINT&&s instanceof ov?s:this.annotationStorage;switch(e){case Wn.DISABLE:r+=cs.ANNOTATIONS_DISABLE;break;case Wn.ENABLE:break;case Wn.ENABLE_FORMS:r+=cs.ANNOTATIONS_FORMS;break;case Wn.ENABLE_STORAGE:r+=cs.ANNOTATIONS_STORAGE,o=h.serializable;break;default:rt(`getRenderingIntent - invalid annotationMode: ${e}`)}i&&(r+=cs.IS_EDITING),n&&(r+=cs.OPLIST);const{ids:c,hash:u}=h.modifiedIds,d=[r,o.hash,u];return{renderingIntent:r,cacheKey:d.join("_"),annotationStorageSerializable:o,modifiedIds:c}}destroy(){var s;if(this.destroyCapability)return this.destroyCapability.promise;this.destroyed=!0,this.destroyCapability=Promise.withResolvers(),(s=l(this,Li))==null||s.reject(new Error("Worker was destroyed during onPassword callback"));const t=[];for(const i of l(this,Ri).values())t.push(i._destroy());l(this,Ri).clear(),l(this,ja).clear(),l(this,Na).clear(),this.hasOwnProperty("annotationStorage")&&this.annotationStorage.resetModified();const e=this.messageHandler.sendWithPromise("Terminate",null);return t.push(e),Promise.all(t).then(()=>{var i,n;this.commonObjs.clear(),this.fontLoader.clear(),l(this,yn).clear(),this.filterFactory.destroy(),Qh.cleanup(),(i=this._networkStream)==null||i.cancelAllRequests(new jr("Worker was terminated.")),(n=this.messageHandler)==null||n.destroy(),this.messageHandler=null,this.destroyCapability.resolve()},this.destroyCapability.reject),this.destroyCapability.promise}setupMessageHandler(){const{messageHandler:t,loadingTask:e}=this;t.on("GetReader",(s,i)=>{te(this._networkStream,"GetReader - no `IPDFStream` instance available."),this._fullReader=this._networkStream.getFullReader(),this._fullReader.onProgress=n=>{this._lastProgress={loaded:n.loaded,total:n.total}},i.onPull=()=>{this._fullReader.read().then(function({value:n,done:r}){if(r){i.close();return}te(n instanceof ArrayBuffer,"GetReader - expected an ArrayBuffer."),i.enqueue(new Uint8Array(n),1,[n])}).catch(n=>{i.error(n)})},i.onCancel=n=>{this._fullReader.cancel(n),i.ready.catch(r=>{if(!this.destroyed)throw r})}}),t.on("ReaderHeadersReady",async s=>{var o;await this._fullReader.headersReady;const{isStreamingSupported:i,isRangeSupported:n,contentLength:r}=this._fullReader;return(!i||!n)&&(this._lastProgress&&((o=e.onProgress)==null||o.call(e,this._lastProgress)),this._fullReader.onProgress=h=>{var c;(c=e.onProgress)==null||c.call(e,{loaded:h.loaded,total:h.total})}),{isStreamingSupported:i,isRangeSupported:n,contentLength:r}}),t.on("GetRangeReader",(s,i)=>{te(this._networkStream,"GetRangeReader - no `IPDFStream` instance available.");const n=this._networkStream.getRangeReader(s.begin,s.end);if(!n){i.close();return}i.onPull=()=>{n.read().then(function({value:r,done:o}){if(o){i.close();return}te(r instanceof ArrayBuffer,"GetRangeReader - expected an ArrayBuffer."),i.enqueue(new Uint8Array(r),1,[r])}).catch(r=>{i.error(r)})},i.onCancel=r=>{n.cancel(r),i.ready.catch(o=>{if(!this.destroyed)throw o})}}),t.on("GetDoc",({pdfInfo:s})=>{this._numPages=s.numPages,this._htmlForXfa=s.htmlForXfa,delete s.htmlForXfa,e._capability.resolve(new WS(s,this))}),t.on("DocException",function(s){let i;switch(s.name){case"PasswordException":i=new tf(s.message,s.code);break;case"InvalidPDFException":i=new Z0(s.message);break;case"MissingPDFException":i=new Xh(s.message);break;case"UnexpectedResponseException":i=new Vu(s.message,s.status);break;case"UnknownErrorException":i=new ef(s.message,s.details);break;default:St("DocException - expected a valid Error.")}e._capability.reject(i)}),t.on("PasswordRequest",s=>{if(v(this,Li,Promise.withResolvers()),e.onPassword){const i=n=>{n instanceof Error?l(this,Li).reject(n):l(this,Li).resolve({password:n})};try{e.onPassword(i,s.code)}catch(n){l(this,Li).reject(n)}}else l(this,Li).reject(new tf(s.message,s.code));return l(this,Li).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,Ri).get(s.pageIndex)._startRenderPage(s.transparency,s.cacheKey)}),t.on("commonobj",([s,i,n])=>{var r;if(this.destroyed||this.commonObjs.has(s))return null;switch(i){case"Font":const{disableFontFace:o,fontExtraProperties:h,pdfBug:c}=this._params;if("error"in n){const f=n.error;rt(`Error during font loading: ${f}`),this.commonObjs.resolve(s,f);break}const u=c&&((r=globalThis.FontInspector)!=null&&r.enabled)?(f,p)=>globalThis.FontInspector.fontAdded(f,p):null,d=new Ux(n,{disableFontFace:o,inspectFont:u});this.fontLoader.bind(d).catch(()=>t.sendWithPromise("FontFallback",{id:s})).finally(()=>{!h&&d.data&&(d.data=null),this.commonObjs.resolve(s,d)});break;case"CopyLocalImage":const{imageRef:g}=n;te(g,"The imageRef must be defined.");for(const f of l(this,Ri).values())for(const[,p]of f.objs)if((p==null?void 0:p.ref)===g)return p.dataLen?(this.commonObjs.resolve(s,structuredClone(p)),p.dataLen):null;break;case"FontPath":case"Image":case"Pattern":this.commonObjs.resolve(s,n);break;default:throw new Error(`Got unknown common object type ${i}`)}return null}),t.on("obj",([s,i,n,r])=>{var h;if(this.destroyed)return;const o=l(this,Ri).get(i);if(!o.objs.has(s)){if(o._intentStates.size===0){(h=r==null?void 0:r.bitmap)==null||h.close();return}switch(n){case"Image":o.objs.resolve(s,r),(r==null?void 0:r.dataLen)>wx&&(o._maybeCleanupAfterRender=!0);break;case"Pattern":o.objs.resolve(s,r);break;default:throw new Error(`Got unknown object type ${n}`)}}}),t.on("DocProgress",s=>{var i;this.destroyed||(i=e.onProgress)==null||i.call(e,{loaded:s.loaded,total:s.total})}),t.on("FetchBuiltInCMap",async s=>{if(this.destroyed)throw new Error("Worker was destroyed.");if(!this.cMapReaderFactory)throw new Error("CMapReaderFactory not initialized, see the `useWorkerFetch` parameter.");return this.cMapReaderFactory.fetch(s)}),t.on("FetchStandardFontData",async s=>{if(this.destroyed)throw new Error("Worker was destroyed.");if(!this.standardFontDataFactory)throw new Error("StandardFontDataFactory not initialized, see the `useWorkerFetch` parameter.");return this.standardFontDataFactory.fetch(s)})}getData(){return this.messageHandler.sendWithPromise("GetData",null)}saveDocument(){var s;this.annotationStorage.size<=0&&rt("saveDocument called while `annotationStorage` is empty, please use the getData-method instead.");const{map:t,transfer:e}=this.annotationStorage.serializable;return this.messageHandler.sendWithPromise("SaveDocument",{isPureXfa:!!this._htmlForXfa,numPages:this._numPages,annotationStorage:t,filename:((s=this._fullReader)==null?void 0:s.filename)??null},e).finally(()=>{this.annotationStorage.resetModified()})}getPage(t){if(!Number.isInteger(t)||t<=0||t>this._numPages)return Promise.reject(new Error("Invalid page request."));const e=t-1,s=l(this,ja).get(e);if(s)return s;const i=this.messageHandler.sendWithPromise("GetPage",{pageIndex:e}).then(n=>{if(this.destroyed)throw new Error("Transport destroyed");n.refStr&&l(this,Na).set(n.refStr,t);const r=new zS(e,n,this,this._params.pdfBug);return l(this,Ri).set(e,r),r});return l(this,ja).set(e,i),i}getPageIndex(t){return Ov(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 _(this,vo,Mc).call(this,"GetFieldObjects")}hasJSActions(){return _(this,vo,Mc).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 _(this,vo,Mc).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 _(this,vo,Mc).call(this,"GetOptionalContentConfig").then(e=>new fS(e,t))}getPermissions(){return this.messageHandler.sendWithPromise("GetPermissions",null)}getMetadata(){const t="GetMetadata",e=l(this,yn).get(t);if(e)return e;const s=this.messageHandler.sendWithPromise(t,null).then(i=>{var n,r;return{info:i[0],metadata:i[1]?new 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,yn).set(t,s),s}getMarkInfo(){return this.messageHandler.sendWithPromise("GetMarkInfo",null)}async startCleanup(t=!1){if(!this.destroyed){await this.messageHandler.sendWithPromise("Cleanup",null);for(const e of l(this,Ri).values())if(!e.cleanup())throw new Error(`startCleanup: Page ${e.pageNumber} is currently rendering.`);this.commonObjs.clear(),t||this.fontLoader.clear(),l(this,yn).clear(),this.filterFactory.destroy(!0),Qh.cleanup()}}cachedPageNumber(t){if(!Ov(t))return null;const e=t.gen===0?`${t.num}R`:`${t.num}R${t.gen}`;return l(this,Na).get(e)??null}}yn=new WeakMap,Ri=new WeakMap,ja=new WeakMap,Na=new WeakMap,Li=new WeakMap,vo=new WeakSet,Mc=function(t,e=null){const s=l(this,yn).get(t);if(s)return s;const i=this.messageHandler.sendWithPromise(t,e);return l(this,yn).set(t,i),i};const Ju=Symbol("INITIAL_DATA");class Rv{constructor(){w(this,Nl);w(this,oi,Object.create(null))}get(t,e=null){if(e){const i=_(this,Nl,yp).call(this,t);return i.promise.then(()=>e(i.data)),null}const s=l(this,oi)[t];if(!s||s.data===Ju)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return s.data}has(t){const e=l(this,oi)[t];return!!e&&e.data!==Ju}resolve(t,e=null){const s=_(this,Nl,yp).call(this,t);s.data=e,s.resolve()}clear(){var t;for(const e in l(this,oi)){const{data:s}=l(this,oi)[e];(t=s==null?void 0:s.bitmap)==null||t.close()}v(this,oi,Object.create(null))}*[Symbol.iterator](){for(const t in l(this,oi)){const{data:e}=l(this,oi)[t];e!==Ju&&(yield[t,e])}}}oi=new WeakMap,Nl=new WeakSet,yp=function(t){var e;return(e=l(this,oi))[t]||(e[t]={...Promise.withResolvers(),data:Ju})};class YS{constructor(t){w(this,dr,null);v(this,dr,t),this.onContinue=null}get promise(){return l(this,dr).capability.promise}cancel(t=0){l(this,dr).cancel(null,t)}get separateAnnots(){const{separateAnnots:t}=l(this,dr).operatorList;if(!t)return!1;const{annotationCanvasMap:e}=l(this,dr);return t.form||t.canvas&&(e==null?void 0:e.size)>0}}dr=new WeakMap;const yo=class yo{constructor({callback:t,params:e,objs:s,commonObjs:i,annotationCanvasMap:n,operatorList:r,pageIndex:o,canvasFactory:h,filterFactory:c,useRequestAnimationFrame:u=!1,pdfBug:d=!1,pageColors:g=null}){w(this,gr,null);this.callback=t,this.params=e,this.objs=s,this.commonObjs=i,this.annotationCanvasMap=n,this.operatorListIdx=null,this.operatorList=r,this._pageIndex=o,this.canvasFactory=h,this.filterFactory=c,this._pdfBug=d,this.pageColors=g,this.running=!1,this.graphicsReadyCallback=null,this.graphicsReady=!1,this._useRequestAnimationFrame=u===!0&&typeof window<"u",this.cancelled=!1,this.capability=Promise.withResolvers(),this.task=new YS(this),this._cancelBound=this.cancel.bind(this),this._continueBound=this._continue.bind(this),this._scheduleNextBound=this._scheduleNext.bind(this),this._nextBound=this._next.bind(this),this._canvas=e.canvasContext.canvas}get completed(){return this.capability.promise.catch(function(){})}initializeGraphics({transparency:t=!1,optionalContentConfig:e}){var o,h;if(this.cancelled)return;if(this._canvas){if(l(yo,bo).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(yo,bo).add(this._canvas)}this._pdfBug&&((o=globalThis.StepperManager)!=null&&o.enabled)&&(this.stepper=globalThis.StepperManager.create(this._pageIndex),this.stepper.init(this.operatorList),this.stepper.nextBreakPoint=this.stepper.getNextBreakPoint());const{canvasContext:s,viewport:i,transform:n,background:r}=this.params;this.gfx=new aa(s,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:e},this.annotationCanvasMap,this.pageColors),this.gfx.beginDrawing({transform:n,viewport:i,transparency:t,background:r}),this.operatorListIdx=0,this.graphicsReady=!0,(h=this.graphicsReadyCallback)==null||h.call(this)}cancel(t=null,e=0){var s;this.running=!1,this.cancelled=!0,(s=this.gfx)==null||s.endDrawing(),l(this,gr)&&(window.cancelAnimationFrame(l(this,gr)),v(this,gr,null)),l(yo,bo).delete(this._canvas),this.callback(t||new af(`Rendering cancelled, page ${this._pageIndex+1}`,e))}operatorListChanged(){var t;if(!this.graphicsReady){this.graphicsReadyCallback||(this.graphicsReadyCallback=this._continueBound);return}(t=this.stepper)==null||t.updateOperatorList(this.operatorList),!this.running&&this._continue()}_continue(){this.running=!0,!this.cancelled&&(this.task.onContinue?this.task.onContinue(this._scheduleNextBound):this._scheduleNext())}_scheduleNext(){this._useRequestAnimationFrame?v(this,gr,window.requestAnimationFrame(()=>{v(this,gr,null),this._nextBound().catch(this._cancelBound)})):Promise.resolve().then(this._nextBound).catch(this._cancelBound)}async _next(){this.cancelled||(this.operatorListIdx=this.gfx.executeOperatorList(this.operatorList,this.operatorListIdx,this._continueBound,this.stepper),this.operatorListIdx===this.operatorList.argsArray.length&&(this.running=!1,this.operatorList.lastChunk&&(this.gfx.endDrawing(),l(yo,bo).delete(this._canvas),this.callback())))}};gr=new WeakMap,bo=new WeakMap,w(yo,bo,new WeakSet);let Cf=yo;const $S="4.9.124",qS="867aaf01f";function Lv(a){return Math.floor(Math.max(0,Math.min(1,a))*255).toString(16).padStart(2,"0")}function Zh(a){return Math.max(0,Math.min(255,255*a))}class Fv{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=Zh(t),[t,t,t]}static G_HTML([t]){const e=Lv(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(Zh)}static RGB_HTML(t){return`#${t.map(Lv).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[Zh(1-Math.min(1,t+i)),Zh(1-Math.min(1,s+i)),Zh(1-Math.min(1,e+i))]}static CMYK_HTML(t){const e=this.CMYK_RGB(t).slice(1);return this.RGB_HTML(e)}static RGB_CMYK([t,e,s]){const i=1-t,n=1-e,r=1-s,o=Math.min(i,n,r);return["CMYK",i,n,r,o]}}class KS{create(t,e,s=!1){if(t<=0||e<=0)throw new Error("Invalid SVG dimensions");const i=this._createSVG("svg:svg");return i.setAttribute("version","1.1"),s||(i.setAttribute("width",`${t}px`),i.setAttribute("height",`${e}px`)),i.setAttribute("preserveAspectRatio","none"),i.setAttribute("viewBox",`0 0 ${t} ${e}`),i}createElement(t){if(typeof t!="string")throw new Error("Invalid SVG element type");return this._createSVG(t)}_createSVG(t){St("Abstract method `_createSVG` called.")}}class Af extends KS{_createSVG(t){return document.createElementNS(sn,t)}}class Iv{static setupStorage(t,e,s,i,n){const r=i.getValue(e,{value:null});switch(s.name){case"textarea":if(r.value!==null&&(t.textContent=r.value),n==="print")break;t.addEventListener("input",o=>{i.setValue(e,{value:o.target.value})});break;case"input":if(s.attributes.type==="radio"||s.attributes.type==="checkbox"){if(r.value===s.attributes.xfaOn?t.setAttribute("checked",!0):r.value===s.attributes.xfaOff&&t.removeAttribute("checked"),n==="print")break;t.addEventListener("change",o=>{i.setValue(e,{value:o.target.checked?o.target.getAttribute("xfaOn"):o.target.getAttribute("xfaOff")})})}else{if(r.value!==null&&t.setAttribute("value",r.value),n==="print")break;t.addEventListener("input",o=>{i.setValue(e,{value:o.target.value})})}break;case"select":if(r.value!==null){t.setAttribute("value",r.value);for(const o of s.children)o.attributes.value===r.value?o.attributes.selected=!0:o.attributes.hasOwnProperty("selected")&&delete o.attributes.selected}t.addEventListener("input",o=>{const h=o.target.options,c=h.selectedIndex===-1?"":h[h.selectedIndex].value;i.setValue(e,{value:c})});break}}static setAttributes({html:t,element:e,storage:s=null,intent:i,linkService:n}){const{attributes:r}=e,o=t instanceof HTMLAnchorElement;r.type==="radio"&&(r.name=`${r.name}-${i}`);for(const[h,c]of Object.entries(r))if(c!=null)switch(h){case"class":c.length&&t.setAttribute(h,c.join(" "));break;case"dataId":break;case"id":t.setAttribute("data-element-id",c);break;case"style":Object.assign(t.style,c);break;case"textContent":t.textContent=c;break;default:(!o||h!=="href"&&h!=="newWindow")&&t.setAttribute(h,c)}o&&n.addLinkAttributes(t,r.href,r.newWindow),s&&r.dataId&&this.setupStorage(t,r.dataId,e,s)}static render(t){var d,g;const e=t.annotationStorage,s=t.linkService,i=t.xfaHtml,n=t.intent||"display",r=document.createElement(i.name);i.attributes&&this.setAttributes({html:r,element:i,intent:n,linkService:s});const o=n!=="richText",h=t.div;if(h.append(r),t.viewport){const f=`matrix(${t.viewport.transform.join(",")})`;h.style.transform=f}o&&h.setAttribute("class","xfaLayer xfaFont");const c=[];if(i.children.length===0){if(i.value){const f=document.createTextNode(i.value);r.append(f),o&&Jh.shouldBuildText(i.name)&&c.push(f)}return{textDivs:c}}const u=[[i,-1,r]];for(;u.length>0;){const[f,p,m]=u.at(-1);if(p+1===f.children.length){u.pop();continue}const y=f.children[++u.at(-1)[1]];if(y===null)continue;const{name:b}=y;if(b==="#text"){const C=document.createTextNode(y.value);c.push(C),m.append(C);continue}const x=(d=y==null?void 0:y.attributes)!=null&&d.xmlns?document.createElementNS(y.attributes.xmlns,b):document.createElement(b);if(m.append(x),y.attributes&&this.setAttributes({html:x,element:y,storage:e,intent:n,linkService:s}),((g=y.children)==null?void 0:g.length)>0)u.push([y,-1,x]);else if(y.value){const C=document.createTextNode(y.value);o&&Jh.shouldBuildText(b)&&c.push(C),x.append(C)}}for(const f of h.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea"))f.setAttribute("readOnly",!0);return{textDivs:c}}static update(t){const e=`matrix(${t.viewport.transform.join(",")})`;t.div.style.transform=e,t.div.hidden=!1}}const tl=1e3,QS=9,Hr=new WeakSet;function rn(a){return{width:a[2]-a[0],height:a[3]-a[1]}}class JS{static create(t){switch(t.data.annotationType){case oe.LINK:return new jv(t);case oe.TEXT:return new ZS(t);case oe.WIDGET:switch(t.data.fieldType){case"Tx":return new tC(t);case"Btn":return t.data.radioButton?new Nv(t):t.data.checkBox?new sC(t):new iC(t);case"Ch":return new nC(t);case"Sig":return new eC(t)}return new Vr(t);case oe.POPUP:return new Tf(t);case oe.FREETEXT:return new Bv(t);case oe.LINE:return new oC(t);case oe.SQUARE:return new aC(t);case oe.CIRCLE:return new hC(t);case oe.POLYLINE:return new Hv(t);case oe.CARET:return new cC(t);case oe.INK:return new Ef(t);case oe.POLYGON:return new lC(t);case oe.HIGHLIGHT:return new Vv(t);case oe.UNDERLINE:return new uC(t);case oe.SQUIGGLY:return new dC(t);case oe.STRIKEOUT:return new gC(t);case oe.STAMP:return new Gv(t);case oe.FILEATTACHMENT:return new fC(t);default:return new $t(t)}}}const Bf=class Bf{constructor(t,{isRenderable:e=!1,ignoreBorder:s=!1,createQuadrilaterals:i=!1}={}){w(this,Bl);w(this,_o,null);w(this,Ba,!1);w(this,Ha,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 Bf._hasPopupData(this.data)}updateEdited(t){var s;if(!this.container)return;l(this,_o)||v(this,_o,{rect:this.data.rect.slice(0)});const{rect:e}=t;e&&_(this,Bl,_p).call(this,e),(s=l(this,Ha))==null||s.popup.updateEdited(t)}resetEdited(){var t;l(this,_o)&&(_(this,Bl,_p).call(this,l(this,_o).rect),(t=l(this,Ha))==null||t.popup.resetEdited(),v(this,_o,null))}_createContainer(t){const{data:e,parent:{page:s,viewport:i}}=this,n=document.createElement("section");n.setAttribute("data-annotation-id",e.id),this instanceof Vr||(n.tabIndex=tl);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 Tf){const{rotation:m}=e;return!e.hasOwnCanvas&&m!==0&&this.setRotation(m,n),n}const{width:o,height:h}=rn(e.rect);if(!t&&e.borderStyle.width>0){r.borderWidth=`${e.borderStyle.width}px`;const m=e.borderStyle.horizontalCornerRadius,y=e.borderStyle.verticalCornerRadius;if(m>0||y>0){const x=`calc(${m}px * var(--scale-factor)) / calc(${y}px * var(--scale-factor))`;r.borderRadius=x}else if(this instanceof Nv){const x=`calc(${o}px * var(--scale-factor)) / calc(${h}px * var(--scale-factor))`;r.borderRadius=x}switch(e.borderStyle.style){case zh.SOLID:r.borderStyle="solid";break;case zh.DASHED:r.borderStyle="dashed";break;case zh.BEVELED:rt("Unimplemented border style: beveled");break;case zh.INSET:rt("Unimplemented border style: inset");break;case zh.UNDERLINE:r.borderBottomStyle="solid";break}const b=e.borderColor||null;b?(v(this,Ba,!0),r.borderColor=$.makeHexColor(b[0]|0,b[1]|0,b[2]|0)):r.borderWidth=0}const c=$.normalizeRect([e.rect[0],s.view[3]-e.rect[1]+s.view[1],e.rect[2],s.view[3]-e.rect[3]+s.view[1]]),{pageWidth:u,pageHeight:d,pageX:g,pageY:f}=i.rawDims;r.left=`${100*(c[0]-g)/u}%`,r.top=`${100*(c[1]-f)/d}%`;const{rotation:p}=e;return e.hasOwnCanvas||p===0?(r.width=`${100*o/u}%`,r.height=`${100*h/d}%`):this.setRotation(p,n),n}setRotation(t,e=this.container){if(!this.data.rect)return;const{pageWidth:s,pageHeight:i}=this.parent.viewport.rawDims,{width:n,height:r}=rn(this.data.rect);let o,h;t%180===0?(o=100*n/s,h=100*r/i):(o=100*r/s,h=100*n/i),e.style.width=`${o}%`,e.style.height=`${h}%`,e.setAttribute("data-main-rotation",(360-t)%360)}get _commonActions(){const t=(e,s,i)=>{const n=i.detail[e],r=n[0],o=n.slice(1);i.target.style[s]=Fv[`${r}_HTML`](o),this.annotationStorage.setValue(this.data.id,{[s]:Fv[`${r}_rgb`](o)})};return at(this,"_commonActions",{display:e=>{const{display:s}=e.detail,i=s%2===1;this.container.style.visibility=i?"hidden":"visible",this.annotationStorage.setValue(this.data.id,{noView:i,noPrint:s===1||s===2})},print:e=>{this.annotationStorage.setValue(this.data.id,{noPrint:!e.detail.print})},hidden:e=>{const{hidden:s}=e.detail;this.container.style.visibility=s?"hidden":"visible",this.annotationStorage.setValue(this.data.id,{noPrint:s,noView:s})},focus:e=>{setTimeout(()=>e.target.focus({preventScroll:!1}),0)},userName:e=>{e.target.title=e.detail.userName},readonly:e=>{e.target.disabled=e.detail.readonly},required:e=>{this._setRequired(e.target,e.detail.required)},bgColor:e=>{t("bgColor","backgroundColor",e)},fillColor:e=>{t("fillColor","backgroundColor",e)},fgColor:e=>{t("fgColor","color",e)},textColor:e=>{t("textColor","color",e)},borderColor:e=>{t("borderColor","borderColor",e)},strokeColor:e=>{t("strokeColor","borderColor",e)},rotation:e=>{const s=e.detail.rotation;this.setRotation(s),this.annotationStorage.setValue(this.data.id,{rotation:s})}})}_dispatchEventFromSandbox(t,e){const s=this._commonActions;for(const i of Object.keys(e.detail)){const n=t[i]||s[i];n==null||n(e)}}_setDefaultPropertiesFromJS(t){if(!this.enableScripting)return;const e=this.annotationStorage.getRawValue(this.data.id);if(!e)return;const s=this._commonActions;for(const[i,n]of Object.entries(e)){const r=s[i];if(r){const o={detail:{[i]:n},target:t};r(o),delete e[i]}}}_createQuadrilaterals(){if(!this.container)return;const{quadPoints:t}=this.data;if(!t)return;const[e,s,i,n]=this.data.rect.map(m=>Math.fround(m));if(t.length===8){const[m,y,b,x]=t.subarray(2,6);if(i===m&&n===y&&e===b&&s===x)return}const{style:r}=this.container;let o;if(l(this,Ba)){const{borderColor:m,borderWidth:y}=r;r.borderWidth=0,o=["url('data:image/svg+xml;utf8,",'<svg xmlns="http://www.w3.org/2000/svg"',' preserveAspectRatio="none" viewBox="0 0 1 1">',`<g fill="transparent" stroke="${m}" stroke-width="${y}">`],this.container.classList.add("hasBorder")}const h=i-e,c=n-s,{svgFactory:u}=this,d=u.createElement("svg");d.classList.add("quadrilateralsContainer"),d.setAttribute("width",0),d.setAttribute("height",0);const g=u.createElement("defs");d.append(g);const f=u.createElement("clipPath"),p=`clippath_${this.data.id}`;f.setAttribute("id",p),f.setAttribute("clipPathUnits","objectBoundingBox"),g.append(f);for(let m=2,y=t.length;m<y;m+=8){const b=t[m],x=t[m+1],C=t[m+2],A=t[m+3],M=u.createElement("rect"),D=(C-e)/h,k=(n-x)/c,P=(b-C)/h,R=(x-A)/c;M.setAttribute("x",D),M.setAttribute("y",k),M.setAttribute("width",P),M.setAttribute("height",R),f.append(M),o==null||o.push(`<rect vector-effect="non-scaling-stroke" x="${D}" y="${k}" width="${P}" height="${R}"/>`)}l(this,Ba)&&(o.push("</g></svg>')"),r.backgroundImage=o.join("")),this.container.append(d),this.container.style.clipPath=`url(#${p})`}_createPopup(){const{data:t}=this,e=v(this,Ha,new Tf({data:{color:t.color,titleObj:t.titleObj,modificationDate:t.modificationDate,contentsObj:t.contentsObj,richText:t.richText,parentRect:t.rect,borderStyle:0,id:`popup_${t.id}`,rotation:t.rotation},parent:this.parent,elements:[this]}));this.parent.div.append(e.render())}render(){St("Abstract method `AnnotationElement.render` called")}_getElementsByName(t,e=null){const s=[];if(this._fieldObjects){const i=this._fieldObjects[t];if(i)for(const{page:n,id:r,exportValues:o}of i){if(n===-1||r===e)continue;const h=typeof o=="string"?o:null,c=document.querySelector(`[data-element-id="${r}"]`);if(c&&!Hr.has(c)){rt(`_getElementsByName - element not allowed: ${r}`);continue}s.push({id:r,exportValue:h,domElement:c})}return s}for(const i of document.getElementsByName(t)){const{exportValue:n}=i,r=i.getAttribute("data-element-id");r!==e&&Hr.has(i)&&s.push({id:r,exportValue:n,domElement:i})}return s}show(){var t;this.container&&(this.container.hidden=!1),(t=this.popup)==null||t.maybeShow()}hide(){var t;this.container&&(this.container.hidden=!0),(t=this.popup)==null||t.forceHide()}getElementsToTriggerPopup(){return this.container}addHighlightArea(){const t=this.getElementsToTriggerPopup();if(Array.isArray(t))for(const e of t)e.classList.add("highlightArea");else t.classList.add("highlightArea")}_editOnDoubleClick(){if(!this._isEditable)return;const{annotationEditorType:t,data:{id:e}}=this;this.container.addEventListener("dblclick",()=>{var s;(s=this.linkService.eventBus)==null||s.dispatch("switchannotationeditormode",{source:this,mode:t,editId:e})})}};_o=new WeakMap,Ba=new WeakMap,Ha=new WeakMap,Bl=new WeakSet,_p=function(t){const{container:{style:e},data:{rect:s,rotation:i},parent:{viewport:{rawDims:{pageWidth:n,pageHeight:r,pageX:o,pageY:h}}}}=this;s==null||s.splice(0,4,...t);const{width:c,height:u}=rn(t);e.left=`${100*(t[0]-o)/n}%`,e.top=`${100*(r-t[3]+h)/r}%`,i===0?(e.width=`${100*c/n}%`,e.height=`${100*u/r}%`):this.setRotation(i)};let $t=Bf;class jv extends $t{constructor(e,s=null){super(e,{isRenderable:!0,ignoreBorder:!!(s!=null&&s.ignoreBorder),createQuadrilaterals:!0});w(this,ps);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?(_(this,ps,Hb).call(this,i,e.attachment,e.attachmentDest),n=!0):e.setOCGState?(_(this,ps,Vb).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==="")&&_(this,ps,Go).call(this)}_bindNamedAction(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeNamedAction(s),!1),_(this,ps,Go).call(this)}_bindJSAction(e,s){e.href=this.linkService.getAnchorUrl("");const i=new Map([["Action","onclick"],["Mouse Up","onmouseup"],["Mouse Down","onmousedown"]]);for(const n of Object.keys(s.actions)){const r=i.get(n);r&&(e[r]=()=>{var o;return(o=this.linkService.eventBus)==null||o.dispatch("dispatcheventinsandbox",{source:this,detail:{id:s.id,name:n}}),!1})}e.onclick||(e.onclick=()=>!1),_(this,ps,Go).call(this)}_bindResetFormAction(e,s){const i=e.onclick;if(i||(e.href=this.linkService.getAnchorUrl("")),_(this,ps,Go).call(this),!this._fieldObjects){rt('_bindResetFormAction - "resetForm" action not supported, ensure that the `fieldObjects` parameter is provided.'),i||(e.onclick=()=>!1);return}e.onclick=()=>{var d;i==null||i();const{fields:n,refs:r,include:o}=s,h=[];if(n.length!==0||r.length!==0){const g=new Set(r);for(const f of n){const p=this._fieldObjects[f]||[];for(const{id:m}of p)g.add(m)}for(const f of Object.values(this._fieldObjects))for(const p of f)g.has(p.id)===o&&h.push(p)}else for(const g of Object.values(this._fieldObjects))h.push(...g);const c=this.annotationStorage,u=[];for(const g of h){const{id:f}=g;switch(u.push(f),g.type){case"text":{const m=g.defaultValue||"";c.setValue(f,{value:m});break}case"checkbox":case"radiobutton":{const m=g.defaultValue===g.exportValues;c.setValue(f,{value:m});break}case"combobox":case"listbox":{const m=g.defaultValue||"";c.setValue(f,{value:m});break}default:continue}const p=document.querySelector(`[data-element-id="${f}"]`);if(p){if(!Hr.has(p)){rt(`_bindResetFormAction - element not allowed: ${f}`);continue}}else continue;p.dispatchEvent(new Event("resetform"))}return this.enableScripting&&((d=this.linkService.eventBus)==null||d.dispatch("dispatcheventinsandbox",{source:this,detail:{id:"app",ids:u,name:"ResetForm"}})),!1}}}ps=new WeakSet,Go=function(){this.container.setAttribute("data-internal-link","")},Hb=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},_(this,ps,Go).call(this)},Vb=function(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeSetOCGState(s),!1),_(this,ps,Go).call(this)};class ZS extends $t{constructor(t){super(t,{isRenderable:!0})}render(){this.container.classList.add("textAnnotation");const t=document.createElement("img");return t.src=this.imageResourcesPath+"annotation-"+this.data.name.toLowerCase()+".svg",t.setAttribute("data-l10n-id","pdfjs-text-annotation-type"),t.setAttribute("data-l10n-args",JSON.stringify({type:this.data.name})),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.append(t),this.container}}class Vr extends $t{render(){return this.container}showElementAndHideCanvas(t){var e;this.data.hasOwnCanvas&&(((e=t.previousSibling)==null?void 0:e.nodeName)==="CANVAS"&&(t.previousSibling.hidden=!0),t.hidden=!1)}_getKeyModifier(t){return Ge.platform.isMac?t.metaKey:t.ctrlKey}_setEventListener(t,e,s,i,n){s.includes("mouse")?t.addEventListener(s,r=>{var o;(o=this.linkService.eventBus)==null||o.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:i,value:n(r),shift:r.shiftKey,modifier:this._getKeyModifier(r)}})}):t.addEventListener(s,r=>{var o;if(s==="blur"){if(!e.focused||!r.relatedTarget)return;e.focused=!1}else if(s==="focus"){if(e.focused)return;e.focused=!0}n&&((o=this.linkService.eventBus)==null||o.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:i,value:n(r)}}))})}_setEventListeners(t,e,s,i){var n,r,o;for(const[h,c]of s)(c==="Action"||(n=this.data.actions)!=null&&n[c])&&((c==="Focus"||c==="Blur")&&(e||(e={focused:!1})),this._setEventListener(t,e,h,c,i),c==="Focus"&&!((r=this.data.actions)!=null&&r.Blur)?this._setEventListener(t,e,"blur","Blur",null):c==="Blur"&&!((o=this.data.actions)!=null&&o.Focus)&&this._setEventListener(t,e,"focus","Focus",null))}_setBackgroundColor(t){const e=this.data.backgroundColor||null;t.style.backgroundColor=e===null?"transparent":$.makeHexColor(e[0],e[1],e[2])}_setTextStyle(t){const e=["left","center","right"],{fontColor:s}=this.data.defaultAppearanceData,i=this.data.defaultAppearanceData.fontSize||QS,n=t.style;let r;const o=2,h=c=>Math.round(10*c)/10;if(this.data.multiLine){const c=Math.abs(this.data.rect[3]-this.data.rect[1]-o),u=Math.round(c/(Zg*i))||1,d=c/u;r=Math.min(i,h(d/Zg))}else{const c=Math.abs(this.data.rect[3]-this.data.rect[1]-o);r=Math.min(i,h(c/Zg))}n.fontSize=`calc(${r}px * var(--scale-factor))`,n.color=$.makeHexColor(s[0],s[1],s[2]),this.data.textAlignment!==null&&(n.textAlign=e[this.data.textAlignment])}_setRequired(t,e){e?t.setAttribute("required",!0):t.removeAttribute("required"),t.setAttribute("aria-required",e)}}class tC extends Vr{constructor(t){const e=t.renderForms||t.data.hasOwnCanvas||!t.data.hasAppearance&&!!t.data.fieldValue;super(t,{isRenderable:e})}setPropertyOnSiblings(t,e,s,i){const n=this.annotationStorage;for(const r of this._getElementsByName(t.name,t.id))r.domElement&&(r.domElement[e]=s),n.setValue(r.id,{[i]:s})}render(){var i,n;const t=this.annotationStorage,e=this.data.id;this.container.classList.add("textWidgetAnnotation");let s=null;if(this.renderForms){const r=t.getValue(e,{value:this.data.fieldValue});let o=r.value||"";const h=t.getValue(e,{charLimit:this.data.maxLen}).charLimit;h&&o.length>h&&(o=o.slice(0,h));let c=r.formattedValue||((i=this.data.textContent)==null?void 0:i.join(`
|
|
529
|
+
`))||null;c&&this.data.comb&&(c=c.replaceAll(/\s+/g,""));const u={userValue:o,formattedValue:c,lastCommittedValue:null,commitKey:1,focused:!1};this.data.multiLine?(s=document.createElement("textarea"),s.textContent=c??o,this.data.doNotScroll&&(s.style.overflowY="hidden")):(s=document.createElement("input"),s.type="text",s.setAttribute("value",c??o),this.data.doNotScroll&&(s.style.overflowX="hidden")),this.data.hasOwnCanvas&&(s.hidden=!0),Hr.add(s),s.setAttribute("data-element-id",e),s.disabled=this.data.readOnly,s.name=this.data.fieldName,s.tabIndex=tl,this._setRequired(s,this.data.required),h&&(s.maxLength=h),s.addEventListener("input",g=>{t.setValue(e,{value:g.target.value}),this.setPropertyOnSiblings(s,"value",g.target.value,"value"),u.formattedValue=null}),s.addEventListener("resetform",g=>{const f=this.data.defaultFieldValue??"";s.value=u.userValue=f,u.formattedValue=null});let d=g=>{const{formattedValue:f}=u;f!=null&&(g.target.value=f),g.target.scrollLeft=0};if(this.enableScripting&&this.hasJSActions){s.addEventListener("focus",f=>{var m;if(u.focused)return;const{target:p}=f;u.userValue&&(p.value=u.userValue),u.lastCommittedValue=p.value,u.commitKey=1,(m=this.data.actions)!=null&&m.Focus||(u.focused=!0)}),s.addEventListener("updatefromsandbox",f=>{this.showElementAndHideCanvas(f.target);const p={value(m){u.userValue=m.detail.value??"",t.setValue(e,{value:u.userValue.toString()}),m.target.value=u.userValue},formattedValue(m){const{formattedValue:y}=m.detail;u.formattedValue=y,y!=null&&m.target!==document.activeElement&&(m.target.value=y),t.setValue(e,{formattedValue:y})},selRange(m){m.target.setSelectionRange(...m.detail.selRange)},charLimit:m=>{var C;const{charLimit:y}=m.detail,{target:b}=m;if(y===0){b.removeAttribute("maxLength");return}b.setAttribute("maxLength",y);let x=u.userValue;!x||x.length<=y||(x=x.slice(0,y),b.value=u.userValue=x,t.setValue(e,{value:x}),(C=this.linkService.eventBus)==null||C.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:x,willCommit:!0,commitKey:1,selStart:b.selectionStart,selEnd:b.selectionEnd}}))}};this._dispatchEventFromSandbox(p,f)}),s.addEventListener("keydown",f=>{var y;u.commitKey=1;let p=-1;if(f.key==="Escape"?p=0:f.key==="Enter"&&!this.data.multiLine?p=2:f.key==="Tab"&&(u.commitKey=3),p===-1)return;const{value:m}=f.target;u.lastCommittedValue!==m&&(u.lastCommittedValue=m,u.userValue=m,(y=this.linkService.eventBus)==null||y.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:m,willCommit:!0,commitKey:p,selStart:f.target.selectionStart,selEnd:f.target.selectionEnd}}))});const g=d;d=null,s.addEventListener("blur",f=>{var m,y;if(!u.focused||!f.relatedTarget)return;(m=this.data.actions)!=null&&m.Blur||(u.focused=!1);const{value:p}=f.target;u.userValue=p,u.lastCommittedValue!==p&&((y=this.linkService.eventBus)==null||y.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:p,willCommit:!0,commitKey:u.commitKey,selStart:f.target.selectionStart,selEnd:f.target.selectionEnd}})),g(f)}),(n=this.data.actions)!=null&&n.Keystroke&&s.addEventListener("beforeinput",f=>{var M;u.lastCommittedValue=null;const{data:p,target:m}=f,{value:y,selectionStart:b,selectionEnd:x}=m;let C=b,A=x;switch(f.inputType){case"deleteWordBackward":{const D=y.substring(0,b).match(/\w*[^\w]*$/);D&&(C-=D[0].length);break}case"deleteWordForward":{const D=y.substring(b).match(/^[^\w]*\w*/);D&&(A+=D[0].length);break}case"deleteContentBackward":b===x&&(C-=1);break;case"deleteContentForward":b===x&&(A+=1);break}f.preventDefault(),(M=this.linkService.eventBus)==null||M.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:y,change:p||"",willCommit:!1,selStart:C,selEnd:A}})}),this._setEventListeners(s,u,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],f=>f.target.value)}if(d&&s.addEventListener("blur",d),this.data.comb){const f=(this.data.rect[2]-this.data.rect[0])/h;s.classList.add("comb"),s.style.letterSpacing=`calc(${f}px * var(--scale-factor) - 1ch)`}}else s=document.createElement("div"),s.textContent=this.data.fieldValue,s.style.verticalAlign="middle",s.style.display="table-cell",this.data.hasOwnCanvas&&(s.hidden=!0);return this._setTextStyle(s),this._setBackgroundColor(s),this._setDefaultPropertiesFromJS(s),this.container.append(s),this.container}}class eC extends Vr{constructor(t){super(t,{isRenderable:!!t.data.hasOwnCanvas})}}class sC extends Vr{constructor(t){super(t,{isRenderable:t.renderForms})}render(){const t=this.annotationStorage,e=this.data,s=e.id;let i=t.getValue(s,{value:e.exportValue===e.fieldValue}).value;typeof i=="string"&&(i=i!=="Off",t.setValue(s,{value:i})),this.container.classList.add("buttonWidgetAnnotation","checkBox");const n=document.createElement("input");return Hr.add(n),n.setAttribute("data-element-id",s),n.disabled=e.readOnly,this._setRequired(n,this.data.required),n.type="checkbox",n.name=e.fieldName,i&&n.setAttribute("checked",!0),n.setAttribute("exportValue",e.exportValue),n.tabIndex=tl,n.addEventListener("change",r=>{const{name:o,checked:h}=r.target;for(const c of this._getElementsByName(o,s)){const u=h&&c.exportValue===e.exportValue;c.domElement&&(c.domElement.checked=u),t.setValue(c.id,{value:u})}t.setValue(s,{value:h})}),n.addEventListener("resetform",r=>{const o=e.defaultFieldValue||"Off";r.target.checked=o===e.exportValue}),this.enableScripting&&this.hasJSActions&&(n.addEventListener("updatefromsandbox",r=>{const o={value(h){h.target.checked=h.detail.value!=="Off",t.setValue(s,{value:h.target.checked})}};this._dispatchEventFromSandbox(o,r)}),this._setEventListeners(n,null,[["change","Validate"],["change","Action"],["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],r=>r.target.checked)),this._setBackgroundColor(n),this._setDefaultPropertiesFromJS(n),this.container.append(n),this.container}}class Nv extends Vr{constructor(t){super(t,{isRenderable:t.renderForms})}render(){this.container.classList.add("buttonWidgetAnnotation","radioButton");const t=this.annotationStorage,e=this.data,s=e.id;let i=t.getValue(s,{value:e.fieldValue===e.buttonValue}).value;if(typeof i=="string"&&(i=i!==e.buttonValue,t.setValue(s,{value:i})),i)for(const r of this._getElementsByName(e.fieldName,s))t.setValue(r.id,{value:!1});const n=document.createElement("input");if(Hr.add(n),n.setAttribute("data-element-id",s),n.disabled=e.readOnly,this._setRequired(n,this.data.required),n.type="radio",n.name=e.fieldName,i&&n.setAttribute("checked",!0),n.tabIndex=tl,n.addEventListener("change",r=>{const{name:o,checked:h}=r.target;for(const c of this._getElementsByName(o,s))t.setValue(c.id,{value:!1});t.setValue(s,{value:h})}),n.addEventListener("resetform",r=>{const o=e.defaultFieldValue;r.target.checked=o!=null&&o===e.buttonValue}),this.enableScripting&&this.hasJSActions){const r=e.buttonValue;n.addEventListener("updatefromsandbox",o=>{const h={value:c=>{const u=r===c.detail.value;for(const d of this._getElementsByName(c.target.name)){const g=u&&d.id===s;d.domElement&&(d.domElement.checked=g),t.setValue(d.id,{value:g})}}};this._dispatchEventFromSandbox(h,o)}),this._setEventListeners(n,null,[["change","Validate"],["change","Action"],["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],o=>o.target.checked)}return this._setBackgroundColor(n),this._setDefaultPropertiesFromJS(n),this.container.append(n),this.container}}class iC extends jv{constructor(t){super(t,{ignoreBorder:t.data.hasAppearance})}render(){const t=super.render();t.classList.add("buttonWidgetAnnotation","pushButton");const e=t.lastChild;return this.enableScripting&&this.hasJSActions&&e&&(this._setDefaultPropertiesFromJS(e),e.addEventListener("updatefromsandbox",s=>{this._dispatchEventFromSandbox({},s)})),t}}class nC extends Vr{constructor(t){super(t,{isRenderable:t.renderForms})}render(){this.container.classList.add("choiceWidgetAnnotation");const t=this.annotationStorage,e=this.data.id,s=t.getValue(e,{value:this.data.fieldValue}),i=document.createElement("select");Hr.add(i),i.setAttribute("data-element-id",e),i.disabled=this.data.readOnly,this._setRequired(i,this.data.required),i.name=this.data.fieldName,i.tabIndex=tl;let n=this.data.combo&&this.data.options.length>0;this.data.combo||(i.size=this.data.options.length,this.data.multiSelect&&(i.multiple=!0)),i.addEventListener("resetform",u=>{const d=this.data.defaultFieldValue;for(const g of i.options)g.selected=g.value===d});for(const u of this.data.options){const d=document.createElement("option");d.textContent=u.displayValue,d.value=u.exportValue,s.value.includes(u.exportValue)&&(d.setAttribute("selected",!0),n=!1),i.append(d)}let r=null;if(n){const u=document.createElement("option");u.value=" ",u.setAttribute("hidden",!0),u.setAttribute("selected",!0),i.prepend(u),r=()=>{u.remove(),i.removeEventListener("input",r),r=null},i.addEventListener("input",r)}const o=u=>{const d=u?"value":"textContent",{options:g,multiple:f}=i;return f?Array.prototype.filter.call(g,p=>p.selected).map(p=>p[d]):g.selectedIndex===-1?null:g[g.selectedIndex][d]};let h=o(!1);const c=u=>{const d=u.target.options;return Array.prototype.map.call(d,g=>({displayValue:g.textContent,exportValue:g.value}))};return this.enableScripting&&this.hasJSActions?(i.addEventListener("updatefromsandbox",u=>{const d={value(g){r==null||r();const f=g.detail.value,p=new Set(Array.isArray(f)?f:[f]);for(const m of i.options)m.selected=p.has(m.value);t.setValue(e,{value:o(!0)}),h=o(!1)},multipleSelection(g){i.multiple=!0},remove(g){const f=i.options,p=g.detail.remove;f[p].selected=!1,i.remove(p),f.length>0&&Array.prototype.findIndex.call(f,y=>y.selected)===-1&&(f[0].selected=!0),t.setValue(e,{value:o(!0),items:c(g)}),h=o(!1)},clear(g){for(;i.length!==0;)i.remove(0);t.setValue(e,{value:null,items:[]}),h=o(!1)},insert(g){const{index:f,displayValue:p,exportValue:m}=g.detail.insert,y=i.children[f],b=document.createElement("option");b.textContent=p,b.value=m,y?y.before(b):i.append(b),t.setValue(e,{value:o(!0),items:c(g)}),h=o(!1)},items(g){const{items:f}=g.detail;for(;i.length!==0;)i.remove(0);for(const p of f){const{displayValue:m,exportValue:y}=p,b=document.createElement("option");b.textContent=m,b.value=y,i.append(b)}i.options.length>0&&(i.options[0].selected=!0),t.setValue(e,{value:o(!0),items:c(g)}),h=o(!1)},indices(g){const f=new Set(g.detail.indices);for(const p of g.target.options)p.selected=f.has(p.index);t.setValue(e,{value:o(!0)}),h=o(!1)},editable(g){g.target.disabled=!g.detail.editable}};this._dispatchEventFromSandbox(d,u)}),i.addEventListener("input",u=>{var f;const d=o(!0),g=o(!1);t.setValue(e,{value:d}),u.preventDefault(),(f=this.linkService.eventBus)==null||f.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:h,change:g,changeEx:d,willCommit:!1,commitKey:1,keyDown:!1}})}),this._setEventListeners(i,null,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"],["input","Action"],["input","Validate"]],u=>u.target.value)):i.addEventListener("input",function(u){t.setValue(e,{value:o(!0)})}),this.data.combo&&this._setTextStyle(i),this._setBackgroundColor(i),this._setDefaultPropertiesFromJS(i),this.container.append(i),this.container}}class Tf extends $t{constructor(t){const{data:e,elements:s}=t;super(t,{isRenderable:$t._hasPopupData(e)}),this.elements=s,this.popup=null}render(){this.container.classList.add("popupAnnotation");const t=this.popup=new rC({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=>`${of}${s}`).join(",")),this.container}}class rC{constructor({container:t,color:e,elements:s,titleObj:i,modificationDate:n,contentsObj:r,richText:o,parent:h,rect:c,parentRect:u,open:d}){w(this,Ct);w(this,Va,_(this,Ct,zb).bind(this));w(this,md,_(this,Ct,xp).bind(this));w(this,vd,_(this,Ct,Bd).bind(this));w(this,Ga,_(this,Ct,Nd).bind(this));w(this,wo,null);w(this,Xt,null);w(this,_n,null);w(this,Wa,null);w(this,Hl,null);w(this,Vl,null);w(this,za,null);w(this,wn,!1);w(this,ai,null);w(this,xn,null);w(this,Gl,null);w(this,Sn,null);w(this,Wl,null);w(this,xo,null);w(this,So,!1);var g;v(this,Xt,t),v(this,Wl,i),v(this,_n,r),v(this,Sn,o),v(this,Vl,h),v(this,wo,e),v(this,Gl,c),v(this,za,u),v(this,Hl,s),v(this,Wa,lf.toDateObject(n)),this.trigger=s.flatMap(f=>f.getElementsToTriggerPopup());for(const f of this.trigger)f.addEventListener("click",l(this,Ga)),f.addEventListener("mouseenter",l(this,vd)),f.addEventListener("mouseleave",l(this,md)),f.classList.add("popupTriggerArea");for(const f of s)(g=f.container)==null||g.addEventListener("keydown",l(this,Va));l(this,Xt).hidden=!0,d&&_(this,Ct,Nd).call(this)}render(){if(l(this,ai))return;const t=v(this,ai,document.createElement("div"));if(t.className="popup",l(this,wo)){const n=t.style.outlineColor=$.makeHexColor(...l(this,wo));CSS.supports("background-color","color-mix(in srgb, red 30%, white)")?t.style.backgroundColor=`color-mix(in srgb, ${n} 30%, white)`:t.style.backgroundColor=$.makeHexColor(...l(this,wo).map(o=>Math.floor(.7*(255-o)+o)))}const e=document.createElement("span");e.className="header";const s=document.createElement("h1");if(e.append(s),{dir:s.dir,str:s.textContent}=l(this,Wl),t.append(e),l(this,Wa)){const n=document.createElement("span");n.classList.add("popupDate"),n.setAttribute("data-l10n-id","pdfjs-annotation-date-time-string"),n.setAttribute("data-l10n-args",JSON.stringify({dateObj:l(this,Wa).valueOf()})),e.append(n)}const i=l(this,Ct,jd);if(i)Iv.render({xfaHtml:i,intent:"richText",div:t}),t.lastChild.classList.add("richText","popupContent");else{const n=this._formatContents(l(this,_n));t.append(n)}l(this,Xt).append(t)}_formatContents({str:t,dir:e}){const s=document.createElement("p");s.classList.add("popupContent"),s.dir=e;const i=t.split(/(?:\r\n?|\n)/);for(let n=0,r=i.length;n<r;++n){const o=i[n];s.append(document.createTextNode(o)),n<r-1&&s.append(document.createElement("br"))}return s}updateEdited({rect:t,popupContent:e}){var s;l(this,xo)||v(this,xo,{contentsObj:l(this,_n),richText:l(this,Sn)}),t&&v(this,xn,null),e&&(v(this,Sn,_(this,Ct,Wb).call(this,e)),v(this,_n,null)),(s=l(this,ai))==null||s.remove(),v(this,ai,null)}resetEdited(){var t;l(this,xo)&&({contentsObj:Ke(this,_n)._,richText:Ke(this,Sn)._}=l(this,xo),v(this,xo,null),(t=l(this,ai))==null||t.remove(),v(this,ai,null),v(this,xn,null))}forceHide(){v(this,So,this.isVisible),l(this,So)&&(l(this,Xt).hidden=!0)}maybeShow(){l(this,So)&&(l(this,ai)||_(this,Ct,Bd).call(this),v(this,So,!1),l(this,Xt).hidden=!1)}get isVisible(){return l(this,Xt).hidden===!1}}Va=new WeakMap,md=new WeakMap,vd=new WeakMap,Ga=new WeakMap,wo=new WeakMap,Xt=new WeakMap,_n=new WeakMap,Wa=new WeakMap,Hl=new WeakMap,Vl=new WeakMap,za=new WeakMap,wn=new WeakMap,ai=new WeakMap,xn=new WeakMap,Gl=new WeakMap,Sn=new WeakMap,Wl=new WeakMap,xo=new WeakMap,So=new WeakMap,Ct=new WeakSet,jd=function(){const t=l(this,Sn),e=l(this,_n);return t!=null&&t.str&&(!(e!=null&&e.str)||e.str===t.str)&&l(this,Sn).html||null},wp=function(){var t,e,s;return((s=(e=(t=l(this,Ct,jd))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.fontSize)||0},Gb=function(){var t,e,s;return((s=(e=(t=l(this,Ct,jd))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.color)||null},Wb=function(t){const e=[],s={str:t,html:{name:"div",attributes:{dir:"auto"},children:[{name:"p",children:e}]}},i={style:{color:l(this,Ct,Gb),fontSize:l(this,Ct,wp)?`calc(${l(this,Ct,wp)}px * var(--scale-factor))`:""}};for(const n of t.split(`
|
|
530
|
+
`))e.push({name:"span",value:n,attributes:i});return s},zb=function(t){t.altKey||t.shiftKey||t.ctrlKey||t.metaKey||(t.key==="Enter"||t.key==="Escape"&&l(this,wn))&&_(this,Ct,Nd).call(this)},Xb=function(){if(l(this,xn)!==null)return;const{page:{view:t},viewport:{rawDims:{pageWidth:e,pageHeight:s,pageX:i,pageY:n}}}=l(this,Vl);let r=!!l(this,za),o=r?l(this,za):l(this,Gl);for(const p of l(this,Hl))if(!o||$.intersect(p.data.rect,o)!==null){o=p.data.rect,r=!0;break}const h=$.normalizeRect([o[0],t[3]-o[1]+t[1],o[2],t[3]-o[3]+t[1]]),u=r?o[2]-o[0]+5:0,d=h[0]+u,g=h[1];v(this,xn,[100*(d-i)/e,100*(g-n)/s]);const{style:f}=l(this,Xt);f.left=`${l(this,xn)[0]}%`,f.top=`${l(this,xn)[1]}%`},Nd=function(){v(this,wn,!l(this,wn)),l(this,wn)?(_(this,Ct,Bd).call(this),l(this,Xt).addEventListener("click",l(this,Ga)),l(this,Xt).addEventListener("keydown",l(this,Va))):(_(this,Ct,xp).call(this),l(this,Xt).removeEventListener("click",l(this,Ga)),l(this,Xt).removeEventListener("keydown",l(this,Va)))},Bd=function(){l(this,ai)||this.render(),this.isVisible?l(this,wn)&&l(this,Xt).classList.add("focused"):(_(this,Ct,Xb).call(this),l(this,Xt).hidden=!1,l(this,Xt).style.zIndex=parseInt(l(this,Xt).style.zIndex)+1e3)},xp=function(){l(this,Xt).classList.remove("focused"),!(l(this,wn)||!this.isVisible)&&(l(this,Xt).hidden=!0,l(this,Xt).style.zIndex=parseInt(l(this,Xt).style.zIndex)-1e3)};class Bv extends $t{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 oC extends $t{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});w(this,zl,null)}render(){this.container.classList.add("lineAnnotation");const e=this.data,{width:s,height:i}=rn(e.rect),n=this.svgFactory.create(s,i,!0),r=v(this,zl,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,zl)}addHighlightArea(){this.container.classList.add("highlightArea")}}zl=new WeakMap;class aC extends $t{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});w(this,Xl,null)}render(){this.container.classList.add("squareAnnotation");const e=this.data,{width:s,height:i}=rn(e.rect),n=this.svgFactory.create(s,i,!0),r=e.borderStyle.width,o=v(this,Xl,this.svgFactory.createElement("svg:rect"));return o.setAttribute("x",r/2),o.setAttribute("y",r/2),o.setAttribute("width",s-r),o.setAttribute("height",i-r),o.setAttribute("stroke-width",r||1),o.setAttribute("stroke","transparent"),o.setAttribute("fill","transparent"),n.append(o),this.container.append(n),!e.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,Xl)}addHighlightArea(){this.container.classList.add("highlightArea")}}Xl=new WeakMap;class hC extends $t{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});w(this,Ul,null)}render(){this.container.classList.add("circleAnnotation");const e=this.data,{width:s,height:i}=rn(e.rect),n=this.svgFactory.create(s,i,!0),r=e.borderStyle.width,o=v(this,Ul,this.svgFactory.createElement("svg:ellipse"));return o.setAttribute("cx",s/2),o.setAttribute("cy",i/2),o.setAttribute("rx",s/2-r/2),o.setAttribute("ry",i/2-r/2),o.setAttribute("stroke-width",r||1),o.setAttribute("stroke","transparent"),o.setAttribute("fill","transparent"),n.append(o),this.container.append(n),!e.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,Ul)}addHighlightArea(){this.container.classList.add("highlightArea")}}Ul=new WeakMap;class Hv extends $t{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});w(this,Yl,null);this.containerClassName="polylineAnnotation",this.svgElementName="svg:polyline"}render(){this.container.classList.add(this.containerClassName);const{data:{rect:e,vertices:s,borderStyle:i,popupRef:n}}=this;if(!s)return this.container;const{width:r,height:o}=rn(e),h=this.svgFactory.create(r,o,!0);let c=[];for(let d=0,g=s.length;d<g;d+=2){const f=s[d]-e[0],p=e[3]-s[d+1];c.push(`${f},${p}`)}c=c.join(" ");const u=v(this,Yl,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,Yl)}addHighlightArea(){this.container.classList.add("highlightArea")}}Yl=new WeakMap;class lC extends Hv{constructor(t){super(t),this.containerClassName="polygonAnnotation",this.svgElementName="svg:polygon"}}class cC extends $t{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){return this.container.classList.add("caretAnnotation"),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container}}class Ef extends $t{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});w(this,$l,[]);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,inkLists:s,borderStyle:i,popupRef:n}}=this,{width:r,height:o}=rn(e),h=this.svgFactory.create(r,o,!0);for(const c of s){let u=[];for(let g=0,f=c.length;g<f;g+=2){const p=c[g]-e[0],m=e[3]-c[g+1];u.push(`${p},${m}`)}u=u.join(" ");const d=this.svgFactory.createElement(this.svgElementName);l(this,$l).push(d),d.setAttribute("points",u),d.setAttribute("stroke-width",i.width||1),d.setAttribute("stroke","transparent"),d.setAttribute("fill","transparent"),h.append(d)}return!n&&this.hasPopupData&&this._createPopup(),this.container.append(h),this._editOnDoubleClick(),this.container}getElementsToTriggerPopup(){return l(this,$l)}addHighlightArea(){this.container.classList.add("highlightArea")}}$l=new WeakMap;class Vv extends $t{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 uC extends $t{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("underlineAnnotation"),this.container}}class dC extends $t{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("squigglyAnnotation"),this.container}}class gC extends $t{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("strikeoutAnnotation"),this.container}}class Gv extends $t{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 fC extends $t{constructor(e){var i;super(e,{isRenderable:!0});w(this,Kl);w(this,ql,null);const{file:s}=this.data;this.filename=s.filename,this.content=s.content,(i=this.linkService.eventBus)==null||i.dispatch("fileattachmentannotation",{source:this,...s})}render(){this.container.classList.add("fileAttachmentAnnotation");const{container:e,data:s}=this;let i;s.hasAppearance||s.fillAlpha===0?i=document.createElement("div"):(i=document.createElement("img"),i.src=`${this.imageResourcesPath}annotation-${/paperclip/i.test(s.name)?"paperclip":"pushpin"}.svg`,s.fillAlpha&&s.fillAlpha<1&&(i.style=`filter: opacity(${Math.round(s.fillAlpha*100)}%);`)),i.addEventListener("dblclick",_(this,Kl,Sp).bind(this)),v(this,ql,i);const{isMac:n}=Ge.platform;return e.addEventListener("keydown",r=>{r.key==="Enter"&&(n?r.metaKey:r.ctrlKey)&&_(this,Kl,Sp).call(this)}),!s.popupRef&&this.hasPopupData?this._createPopup():i.classList.add("popupTriggerArea"),e.append(i),e}getElementsToTriggerPopup(){return l(this,ql)}addHighlightArea(){this.container.classList.add("highlightArea")}}ql=new WeakMap,Kl=new WeakSet,Sp=function(){var e;(e=this.downloadManager)==null||e.openOrDownloadData(this.content,this.filename)};class pC{constructor({div:t,accessibilityManager:e,annotationCanvasMap:s,annotationEditorUIManager:i,page:n,viewport:r,structTreeLayer:o}){w(this,To);w(this,Ql,null);w(this,Co,null);w(this,Ao,new Map);w(this,Jl,null);this.div=t,v(this,Ql,e),v(this,Co,s),v(this,Jl,o||null),this.page=n,this.viewport=r,this.zIndex=0,this._annotationEditorUIManager=i}hasEditableAnnotations(){return l(this,Ao).size>0}async render(t){var r;const{annotations:e}=t,s=this.div;Nr(s,this.viewport);const i=new Map,n={data:null,layer:s,linkService:t.linkService,downloadManager:t.downloadManager,imageResourcesPath:t.imageResourcesPath||"",renderForms:t.renderForms!==!1,svgFactory:new Af,annotationStorage:t.annotationStorage||new mf,enableScripting:t.enableScripting===!0,hasJSActions:t.hasJSActions,fieldObjects:t.fieldObjects,parent:this,elements:null};for(const o of e){if(o.noHTML)continue;const h=o.annotationType===oe.POPUP;if(h){const d=i.get(o.id);if(!d)continue;n.elements=d}else{const{width:d,height:g}=rn(o.rect);if(d<=0||g<=0)continue}n.data=o;const c=JS.create(n);if(!c.isRenderable)continue;if(!h&&o.popupRef){const d=i.get(o.popupRef);d?d.push(c):i.set(o.popupRef,[c])}const u=c.render();o.hidden&&(u.style.visibility="hidden"),await _(this,To,Ub).call(this,u,o.id),c._isEditable&&(l(this,Ao).set(c.data.id,c),(r=this._annotationEditorUIManager)==null||r.renderAnnotationElement(c))}_(this,To,Cp).call(this)}update({viewport:t}){const e=this.div;this.viewport=t,Nr(e,{rotation:t.rotation}),_(this,To,Cp).call(this),e.hidden=!1}getEditableAnnotations(){return Array.from(l(this,Ao).values())}getEditableAnnotation(t){return l(this,Ao).get(t)}}Ql=new WeakMap,Co=new WeakMap,Ao=new WeakMap,Jl=new WeakMap,To=new WeakSet,Ub=async function(t,e){var r,o;const s=t.firstChild||t,i=s.id=`${of}${e}`,n=await((r=l(this,Jl))==null?void 0:r.getAriaAttributes(i));if(n)for(const[h,c]of n)s.setAttribute(h,c);this.div.append(t),(o=l(this,Ql))==null||o.moveElementInDOM(this.div,t,s,!1)},Cp=function(){if(!l(this,Co))return;const t=this.div;for(const[e,s]of l(this,Co)){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,Co).clear()};const Zu=/\r\n?|\n/g,Mt=class Mt extends Bt{constructor(e){super({...e,name:"freeTextEditor"});w(this,se);w(this,hi);w(this,ms,"");w(this,Zl,`${this.id}-editor`);w(this,Eo,null);w(this,vs);v(this,hi,e.color||Mt._defaultColor||Bt._defaultLineColor),v(this,vs,e.fontSize||Mt._defaultFontSize)}static get _keyboardManager(){const e=Mt.prototype,s=r=>r.isEmpty(),i=Br.TRANSLATE_SMALL,n=Br.TRANSLATE_BIG;return at(this,"_keyboardManager",new $h([[["ctrl+s","mac+meta+s","ctrl+p","mac+meta+p"],e.commitOrRemove,{bubbles:!0}],[["ctrl+Enter","mac+meta+Enter","Escape","mac+Escape"],e.commitOrRemove],[["ArrowLeft","mac+ArrowLeft"],e._translateEmpty,{args:[-i,0],checker:s}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],e._translateEmpty,{args:[-n,0],checker:s}],[["ArrowRight","mac+ArrowRight"],e._translateEmpty,{args:[i,0],checker:s}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],e._translateEmpty,{args:[n,0],checker:s}],[["ArrowUp","mac+ArrowUp"],e._translateEmpty,{args:[0,-i],checker:s}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],e._translateEmpty,{args:[0,-n],checker:s}],[["ArrowDown","mac+ArrowDown"],e._translateEmpty,{args:[0,i],checker:s}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],e._translateEmpty,{args:[0,n],checker:s}]]))}static initialize(e,s){Bt.initialize(e,s);const i=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(i.getPropertyValue("--freetext-padding"))}static updateDefaultParams(e,s){switch(e){case ut.FREETEXT_SIZE:Mt._defaultFontSize=s;break;case ut.FREETEXT_COLOR:Mt._defaultColor=s;break}}updateParams(e,s){switch(e){case ut.FREETEXT_SIZE:_(this,se,Yb).call(this,s);break;case ut.FREETEXT_COLOR:_(this,se,$b).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[ut.FREETEXT_SIZE,Mt._defaultFontSize],[ut.FREETEXT_COLOR,Mt._defaultColor||Bt._defaultLineColor]]}get propertiesToUpdate(){return[[ut.FREETEXT_SIZE,l(this,vs)],[ut.FREETEXT_COLOR,l(this,hi)]]}_translateEmpty(e,s){this._uiManager.translateSelectedEditors(e,s,!0)}getInitialTranslation(){const e=this.parentScale;return[-Mt._internalPadding*e,-(Mt._internalPadding+l(this,vs))*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"),v(this,Eo,new AbortController);const e=this._uiManager.combinedSignal(l(this,Eo));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,Zl)),this._isDraggable=!0,(e=l(this,Eo))==null||e.abort(),v(this,Eo,null),this.div.focus({preventScroll:!0}),this.isEditing=!1,this.parent.div.classList.add("freetextEditing"))}focusin(e){this._focusEventsAllowed&&(super.focusin(e),e.target!==this.editorDiv&&this.editorDiv.focus())}onceAdded(){var e;this.width||(this.enableEditMode(),this.editorDiv.focus(),(e=this._initialOptions)!=null&&e.isCentered&&this.center(),this._initialOptions=null)}isEmpty(){return!this.editorDiv||this.editorDiv.innerText.trim()===""}remove(){this.isEditing=!1,this.parent&&(this.parent.setEditingState(!0),this.parent.div.classList.add("freetextEditing")),super.remove()}commit(){if(!this.isInEditMode())return;super.commit(),this.disableEditMode();const e=l(this,ms),s=v(this,ms,_(this,se,qb).call(this).trimEnd());if(e===s)return;const i=n=>{if(v(this,ms,n),!n){this.remove();return}_(this,se,Gd).call(this),this._uiManager.rebuild(this),_(this,se,Hd).call(this)};this.addCommands({cmd:()=>{i(s)},undo:()=>{i(e)},mustExec:!1}),_(this,se,Hd).call(this)}shouldGetKeyboardEvents(){return this.isInEditMode()}enterInEditMode(){this.enableEditMode(),this.editorDiv.focus()}dblclick(e){this.enterInEditMode()}keydown(e){e.target===this.div&&e.key==="Enter"&&(this.enterInEditMode(),e.preventDefault())}editorDivKeydown(e){Mt._keyboardManager.exec(this,e)}editorDivFocus(e){this.isEditing=!0}editorDivBlur(e){this.isEditing=!1}editorDivInput(e){this.parent.div.classList.toggle("freetextEditing",this.isEmpty())}disableEditing(){this.editorDiv.setAttribute("role","comment"),this.editorDiv.removeAttribute("aria-multiline")}enableEditing(){this.editorDiv.setAttribute("role","textbox"),this.editorDiv.setAttribute("aria-multiline",!0)}render(){if(this.div)return this.div;let e,s;this.width&&(e=this.x,s=this.y),super.render(),this.editorDiv=document.createElement("div"),this.editorDiv.className="internal",this.editorDiv.setAttribute("id",l(this,Zl)),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,vs)}px * var(--scale-factor))`,i.color=l(this,hi),this.div.append(this.editorDiv),this.overlayDiv=document.createElement("div"),this.overlayDiv.classList.add("overlay","enabled"),this.div.append(this.overlayDiv),Xu(this,this.div,["dblclick","keydown"]),this.width){const[n,r]=this.parentDimensions;if(this.annotationElementId){const{position:o}=this._initialData;let[h,c]=this.getInitialTranslation();[h,c]=this.pageTranslationToScreen(h,c);const[u,d]=this.pageDimensions,[g,f]=this.pageTranslation;let p,m;switch(this.rotation){case 0:p=e+(o[0]-g)/u,m=s+this.height-(o[1]-f)/d;break;case 90:p=e+(o[0]-g)/u,m=s-(o[1]-f)/d,[h,c]=[c,-h];break;case 180:p=e-this.width+(o[0]-g)/u,m=s-(o[1]-f)/d,[h,c]=[-h,-c];break;case 270:p=e+(o[0]-g-this.height*d)/u,m=s+(o[1]-f-this.width*u)/d,[h,c]=[-c,h];break}this.setAt(p*n,m*r,h,c)}else this.setAt(e*n,s*r,this.width*n,this.height*r);_(this,se,Gd).call(this),this._isDraggable=!0,this.editorDiv.contentEditable=!1}else this._isDraggable=!1,this.editorDiv.contentEditable=!0;return this.div}editorDivPaste(e){var p,m,y;const s=e.clipboardData||window.clipboardData,{types:i}=s;if(i.length===1&&i[0]==="text/plain")return;e.preventDefault();const n=_(p=Mt,Cn,Ap).call(p,s.getData("text")||"").replaceAll(Zu,`
|
|
531
|
+
`);if(!n)return;const r=window.getSelection();if(!r.rangeCount)return;this.editorDiv.normalize(),r.deleteFromDocument();const o=r.getRangeAt(0);if(!n.includes(`
|
|
532
|
+
`)){o.insertNode(document.createTextNode(n)),this.editorDiv.normalize(),r.collapseToStart();return}const{startContainer:h,startOffset:c}=o,u=[],d=[];if(h.nodeType===Node.TEXT_NODE){const b=h.parentElement;if(d.push(h.nodeValue.slice(c).replaceAll(Zu,"")),b!==this.editorDiv){let x=u;for(const C of this.editorDiv.childNodes){if(C===b){x=d;continue}x.push(_(m=Mt,Cn,Vd).call(m,C))}}u.push(h.nodeValue.slice(0,c).replaceAll(Zu,""))}else if(h===this.editorDiv){let b=u,x=0;for(const C of this.editorDiv.childNodes)x++===c&&(b=d),b.push(_(y=Mt,Cn,Vd).call(y,C))}v(this,ms,`${u.join(`
|
|
533
533
|
`)}${n}${d.join(`
|
|
534
|
-
`)}`),
|
|
535
|
-
`),position:m,pageIndex:
|
|
536
|
-
`)){const
|
|
537
|
-
`)},
|
|
538
|
-
`)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},Hb=function(){return c(this,us).replaceAll(" "," ")},op=function(e){return e.replaceAll(" "," ")},Wb=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},w(Et,cn),tt(Et,"_freeTextDefaultContent",""),tt(Et,"_internalPadding",0),tt(Et,"_defaultColor",null),tt(Et,"_defaultFontSize",10),tt(Et,"_type","freetext"),tt(Et,"_editorType",nt.FREETEXT);let mf=Et;class Pv{toSVGPath(){Mt("Abstract method `toSVGPath` must be implemented.")}get box(){Mt("Abstract getter `box` must be implemented.")}serialize(t,e){Mt("Abstract method `serialize` must be implemented.")}get classNamesForDrawing(){Mt("Abstract getter `classNamesForDrawing` must be implemented.")}get classNamesForOutlining(){Mt("Abstract getter `classNamesForOutlining` must be implemented.")}get mustRemoveSelfIntersections(){return!1}}const un=class un{constructor({x:t,y:e},s,i,n,r,a=0){w(this,oe);w(this,gs);w(this,Zs,[]);w(this,jo);w(this,No);w(this,Ai,[]);w(this,ot,new Float64Array(18));w(this,va);w(this,ba);w(this,Hl);w(this,Wl);w(this,Bo);w(this,Ho);w(this,er,[]);v(this,gs,s),v(this,Ho,n*i),v(this,No,r),c(this,ot).set([NaN,NaN,NaN,NaN,t,e],6),v(this,jo,a),v(this,Wl,c(un,Xl)*i),v(this,Hl,c(un,id)*i),v(this,Bo,i),c(this,er).push(t,e)}isEmpty(){return isNaN(c(this,ot)[8])}add({x:t,y:e}){var R;v(this,va,t),v(this,ba,e);const[s,i,n,r]=c(this,gs);let[a,h,l,u]=c(this,ot).subarray(8,12);const d=t-l,g=e-u,f=Math.hypot(d,g);if(f<c(this,Hl))return!1;const p=f-c(this,Wl),m=p/f,_=m*d,b=m*g;let x=a,S=h;a=l,h=u,l+=_,u+=b,(R=c(this,er))==null||R.push(t,e);const A=-b/p,k=_/p,P=A*c(this,Ho),M=k*c(this,Ho);return c(this,ot).set(c(this,ot).subarray(2,8),0),c(this,ot).set([l+P,u+M],4),c(this,ot).set(c(this,ot).subarray(14,18),12),c(this,ot).set([l-P,u-M],16),isNaN(c(this,ot)[6])?(c(this,Ai).length===0&&(c(this,ot).set([a+P,h+M],2),c(this,Ai).push(NaN,NaN,NaN,NaN,(a+P-s)/n,(h+M-i)/r),c(this,ot).set([a-P,h-M],14),c(this,Zs).push(NaN,NaN,NaN,NaN,(a-P-s)/n,(h-M-i)/r)),c(this,ot).set([x,S,a,h,l,u],6),!this.isEmpty()):(c(this,ot).set([x,S,a,h,l,u],6),Math.abs(Math.atan2(S-h,x-a)-Math.atan2(b,_))<Math.PI/2?([a,h,l,u]=c(this,ot).subarray(2,6),c(this,Ai).push(NaN,NaN,NaN,NaN,((a+l)/2-s)/n,((h+u)/2-i)/r),[a,h,x,S]=c(this,ot).subarray(14,18),c(this,Zs).push(NaN,NaN,NaN,NaN,((x+a)/2-s)/n,((S+h)/2-i)/r),!0):([x,S,a,h,l,u]=c(this,ot).subarray(0,6),c(this,Ai).push(((x+5*a)/6-s)/n,((S+5*h)/6-i)/r,((5*a+l)/6-s)/n,((5*h+u)/6-i)/r,((a+l)/2-s)/n,((h+u)/2-i)/r),[l,u,a,h,x,S]=c(this,ot).subarray(12,18),c(this,Zs).push(((x+5*a)/6-s)/n,((S+5*h)/6-i)/r,((5*a+l)/6-s)/n,((5*h+u)/6-i)/r,((a+l)/2-s)/n,((h+u)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=c(this,Ai),e=c(this,Zs);if(isNaN(c(this,ot)[6])&&!this.isEmpty())return y(this,oe,Xb).call(this);const s=[];s.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)isNaN(t[i])?s.push(`L${t[i+4]} ${t[i+5]}`):s.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);y(this,oe,Vb).call(this,s);for(let i=e.length-6;i>=6;i-=6)isNaN(e[i])?s.push(`L${e[i+4]} ${e[i+5]}`):s.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return y(this,oe,zb).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new Dv(t,e,s,i,n,r)}getOutlines(){var d;const t=c(this,Ai),e=c(this,Zs),s=c(this,ot),[i,n,r,a]=c(this,gs),h=new Float64Array((((d=c(this,er))==null?void 0:d.length)??0)+2);for(let g=0,f=h.length-2;g<f;g+=2)h[g]=(c(this,er)[g]-i)/r,h[g+1]=(c(this,er)[g+1]-n)/a;if(h[h.length-2]=(c(this,va)-i)/r,h[h.length-1]=(c(this,ba)-n)/a,isNaN(s[6])&&!this.isEmpty())return y(this,oe,Gb).call(this,h);const l=new Float64Array(c(this,Ai).length+24+c(this,Zs).length);let u=t.length;for(let g=0;g<u;g+=2){if(isNaN(t[g])){l[g]=l[g+1]=NaN;continue}l[g]=t[g],l[g+1]=t[g+1]}u=y(this,oe,Ub).call(this,l,u);for(let g=e.length-6;g>=6;g-=6)for(let f=0;f<6;f+=2){if(isNaN(e[g+f])){l[u]=l[u+1]=NaN,u+=2;continue}l[u]=e[g+f],l[u+1]=e[g+f+1],u+=2}return y(this,oe,Yb).call(this,l,u),this.newFreeDrawOutline(l,h,c(this,gs),c(this,Bo),c(this,jo),c(this,No))}};gs=new WeakMap,Zs=new WeakMap,jo=new WeakMap,No=new WeakMap,Ai=new WeakMap,ot=new WeakMap,va=new WeakMap,ba=new WeakMap,Hl=new WeakMap,Wl=new WeakMap,Bo=new WeakMap,Ho=new WeakMap,er=new WeakMap,Xl=new WeakMap,sd=new WeakMap,id=new WeakMap,oe=new WeakSet,gc=function(){const t=c(this,ot).subarray(4,6),e=c(this,ot).subarray(16,18),[s,i,n,r]=c(this,gs);return[(c(this,va)+(t[0]-e[0])/2-s)/n,(c(this,ba)+(t[1]-e[1])/2-i)/r,(c(this,va)+(e[0]-t[0])/2-s)/n,(c(this,ba)+(e[1]-t[1])/2-i)/r]},Xb=function(){const[t,e,s,i]=c(this,gs),[n,r,a,h]=y(this,oe,gc).call(this);return`M${(c(this,ot)[2]-t)/s} ${(c(this,ot)[3]-e)/i} L${(c(this,ot)[4]-t)/s} ${(c(this,ot)[5]-e)/i} L${n} ${r} L${a} ${h} L${(c(this,ot)[16]-t)/s} ${(c(this,ot)[17]-e)/i} L${(c(this,ot)[14]-t)/s} ${(c(this,ot)[15]-e)/i} Z`},zb=function(t){const e=c(this,Zs);t.push(`L${e[4]} ${e[5]} Z`)},Vb=function(t){const[e,s,i,n]=c(this,gs),r=c(this,ot).subarray(4,6),a=c(this,ot).subarray(16,18),[h,l,u,d]=y(this,oe,gc).call(this);t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${h} ${l} L${u} ${d} L${(a[0]-e)/i} ${(a[1]-s)/n}`)},Gb=function(t){const e=c(this,ot),[s,i,n,r]=c(this,gs),[a,h,l,u]=y(this,oe,gc).call(this),d=new Float64Array(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,l,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,c(this,gs),c(this,Bo),c(this,jo),c(this,No))},Yb=function(t,e){const s=c(this,Zs);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},Ub=function(t,e){const s=c(this,ot).subarray(4,6),i=c(this,ot).subarray(16,18),[n,r,a,h]=c(this,gs),[l,u,d,g]=y(this,oe,gc).call(this);return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/a,(s[1]-r)/h,NaN,NaN,NaN,NaN,l,u,NaN,NaN,NaN,NaN,d,g,NaN,NaN,NaN,NaN,(i[0]-n)/a,(i[1]-r)/h],e),e+=24},w(un,Xl,8),w(un,sd,2),w(un,id,c(un,Xl)+c(un,sd));let ju=un;class Dv extends Pv{constructor(e,s,i,n,r,a){super();w(this,Ze);w(this,Wo);w(this,ya,null);w(this,dn);w(this,zl);w(this,fs);w(this,Vl);w(this,Ut);v(this,Ut,e),v(this,fs,s),v(this,Wo,i),v(this,Vl,n),v(this,dn,r),v(this,zl,a),y(this,Ze,qb).call(this,a);const{x:h,y:l,width:u,height:d}=c(this,ya);for(let g=0,f=e.length;g<f;g+=2)e[g]=(e[g]-h)/u,e[g+1]=(e[g+1]-l)/d;for(let g=0,f=s.length;g<f;g+=2)s[g]=(s[g]-h)/u,s[g+1]=(s[g+1]-l)/d}toSVGPath(){const e=[`M${c(this,Ut)[4]} ${c(this,Ut)[5]}`];for(let s=6,i=c(this,Ut).length;s<i;s+=6){if(isNaN(c(this,Ut)[s])){e.push(`L${c(this,Ut)[s+4]} ${c(this,Ut)[s+5]}`);continue}e.push(`C${c(this,Ut)[s]} ${c(this,Ut)[s+1]} ${c(this,Ut)[s+2]} ${c(this,Ut)[s+3]} ${c(this,Ut)[s+4]} ${c(this,Ut)[s+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,s,i,n],r){const a=i-e,h=n-s;let l,u;switch(r){case 0:l=y(this,Ze,fc).call(this,c(this,Ut),e,n,a,-h),u=y(this,Ze,fc).call(this,c(this,fs),e,n,a,-h);break;case 90:l=y(this,Ze,pc).call(this,c(this,Ut),e,s,a,h),u=y(this,Ze,pc).call(this,c(this,fs),e,s,a,h);break;case 180:l=y(this,Ze,fc).call(this,c(this,Ut),i,s,-a,h),u=y(this,Ze,fc).call(this,c(this,fs),i,s,-a,h);break;case 270:l=y(this,Ze,pc).call(this,c(this,Ut),i,n,-a,-h),u=y(this,Ze,pc).call(this,c(this,fs),i,n,-a,-h);break}return{outline:Array.from(l),points:[Array.from(u)]}}get box(){return c(this,ya)}newOutliner(e,s,i,n,r,a=0){return new ju(e,s,i,n,r,a)}getNewOutline(e,s){const{x:i,y:n,width:r,height:a}=c(this,ya),[h,l,u,d]=c(this,Wo),g=r*u,f=a*d,p=i*u+h,m=n*d+l,_=this.newOutliner({x:c(this,fs)[0]*g+p,y:c(this,fs)[1]*f+m},c(this,Wo),c(this,Vl),e,c(this,zl),s??c(this,dn));for(let b=2;b<c(this,fs).length;b+=2)_.add({x:c(this,fs)[b]*g+p,y:c(this,fs)[b+1]*f+m});return _.getOutlines()}get mustRemoveSelfIntersections(){return!0}}Wo=new WeakMap,ya=new WeakMap,dn=new WeakMap,zl=new WeakMap,fs=new WeakMap,Vl=new WeakMap,Ut=new WeakMap,Ze=new WeakSet,fc=function(e,s,i,n,r){const a=new Float64Array(e.length);for(let h=0,l=e.length;h<l;h+=2)a[h]=s+e[h]*n,a[h+1]=i+e[h+1]*r;return a},pc=function(e,s,i,n,r){const a=new Float64Array(e.length);for(let h=0,l=e.length;h<l;h+=2)a[h]=s+e[h+1]*n,a[h+1]=i+e[h]*r;return a},qb=function(e){const s=c(this,Ut);let i=s[4],n=s[5],r=i,a=n,h=i,l=n,u=i,d=n;const g=e?Math.max:Math.min;for(let b=6,x=s.length;b<x;b+=6){if(isNaN(s[b]))r=Math.min(r,s[b+4]),a=Math.min(a,s[b+5]),h=Math.max(h,s[b+4]),l=Math.max(l,s[b+5]),d<s[b+5]?(u=s[b+4],d=s[b+5]):d===s[b+5]&&(u=g(u,s[b+4]));else{const S=U.bezierBoundingBox(i,n,...s.slice(b,b+6));r=Math.min(r,S[0]),a=Math.min(a,S[1]),h=Math.max(h,S[2]),l=Math.max(l,S[3]),d<S[3]?(u=S[2],d=S[3]):d===S[3]&&(u=g(u,S[2]))}i=s[b+4],n=s[b+5]}const f=r-c(this,dn),p=a-c(this,dn),m=h-r+2*c(this,dn),_=l-a+2*c(this,dn);v(this,ya,{x:f,y:p,width:m,height:_,lastPoint:[u,d]})};class Rv{constructor(t,e=0,s=0,i=!0){w(this,Xe);w(this,Gl);w(this,sr,[]);w(this,ti,[]);let n=1/0,r=-1/0,a=1/0,h=-1/0;const u=10**-4;for(const{x:b,y:x,width:S,height:A}of t){const k=Math.floor((b-e)/u)*u,P=Math.ceil((b+S+e)/u)*u,M=Math.floor((x-e)/u)*u,O=Math.ceil((x+A+e)/u)*u,R=[k,M,O,!0],I=[P,M,O,!1];c(this,sr).push(R,I),n=Math.min(n,k),r=Math.max(r,P),a=Math.min(a,M),h=Math.max(h,O)}const d=r-n+2*s,g=h-a+2*s,f=n-s,p=a-s,m=c(this,sr).at(i?-1:-2),_=[m[0],m[2]];for(const b of c(this,sr)){const[x,S,A]=b;b[0]=(x-f)/d,b[1]=(S-p)/g,b[2]=(A-p)/g}v(this,Gl,{x:f,y:p,width:d,height:g,lastPoint:_})}getOutlines(){c(this,sr).sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of c(this,sr))e[3]?(t.push(...y(this,Xe,hp).call(this,e)),y(this,Xe,Kb).call(this,e)):(y(this,Xe,Jb).call(this,e),t.push(...y(this,Xe,hp).call(this,e)));return y(this,Xe,$b).call(this,t)}}Gl=new WeakMap,sr=new WeakMap,ti=new WeakMap,Xe=new WeakSet,$b=function(t){const e=[],s=new Set;for(const r of t){const[a,h,l]=r;e.push([a,h,r],[a,l,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],l=e[r+1][2];h.push(l),l.push(h),s.add(h),s.add(l)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[a,h,l,u,d]=r;s.delete(r);let g=a,f=h;for(n=[a,l],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,l,u,d]=p,g!==a&&(n.push(g,f,a,f===h?h:l),g=a),f=f===h?l:h}n.push(g,f)}return new vC(i,c(this,Gl))},Ad=function(t){const e=c(this,ti);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},Kb=function([,t,e]){const s=y(this,Xe,Ad).call(this,t);c(this,ti).splice(s,0,[t,e])},Jb=function([,t,e]){const s=y(this,Xe,Ad).call(this,t);for(let i=s;i<c(this,ti).length;i++){const[n,r]=c(this,ti)[i];if(n!==t)break;if(n===t&&r===e){c(this,ti).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=c(this,ti)[i];if(n!==t)break;if(n===t&&r===e){c(this,ti).splice(i,1);return}}},hp=function(t){const[e,s,i]=t,n=[[e,s,i]],r=y(this,Xe,Ad).call(this,i);for(let a=0;a<r;a++){const[h,l]=c(this,ti)[a];for(let u=0,d=n.length;u<d;u++){const[,g,f]=n[u];if(!(l<=g||f<=h)){if(g>=h){if(f>l)n[u][1]=l;else{if(d===1)return[];n.splice(u,1),u--,d--}continue}n[u][2]=h,f>l&&n.push([e,l,f])}}}return n};class vC extends Pv{constructor(e,s){super();w(this,Yl);w(this,Xo);v(this,Xo,e),v(this,Yl,s)}toSVGPath(){const e=[];for(const s of c(this,Xo)){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,l=n-s;for(const u of c(this,Xo)){const d=new Array(u.length);for(let g=0;g<u.length;g+=2)d[g]=e+u[g]*h,d[g+1]=n-u[g+1]*l;a.push(d)}return a}get box(){return c(this,Yl)}get classNamesForDrawing(){return["highlight"]}get classNamesForOutlining(){return["highlightOutline"]}}Yl=new WeakMap,Xo=new WeakMap;class vf extends ju{newFreeDrawOutline(t,e,s,i,n,r){return new bC(t,e,s,i,n,r)}get classNamesForDrawing(){return["highlight","free"]}}class bC extends Dv{get classNamesForDrawing(){return["highlight","free"]}get classNamesForOutlining(){return["highlightOutline","free"]}newOutliner(t,e,s,i,n,r=0){return new vf(t,e,s,i,n,r)}}const ts=class ts{constructor({editor:t=null,uiManager:e=null}){w(this,Ct);w(this,ei,null);w(this,_a,null);w(this,zo);w(this,he,null);w(this,Ul,!1);w(this,Vo,!1);w(this,ql,null);w(this,$l);w(this,ir,null);w(this,si,null);w(this,Go);var s;t?(v(this,Vo,!1),v(this,Go,Z.HIGHLIGHT_COLOR),v(this,ql,t)):(v(this,Vo,!0),v(this,Go,Z.HIGHLIGHT_DEFAULT_COLOR)),v(this,si,(t==null?void 0:t._uiManager)||e),v(this,$l,c(this,si)._eventBus),v(this,zo,(t==null?void 0:t.color)||((s=c(this,si))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),c(ts,Kl)||v(ts,Kl,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 ut(this,"_keyboardManager",new Fh([[["Escape","mac+Escape"],ts.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],ts.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],ts.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],ts.prototype._moveToPrevious],[["Home","mac+Home"],ts.prototype._moveToBeginning],[["End","mac+End"],ts.prototype._moveToEnd]]))}renderButton(){const t=v(this,ei,document.createElement("button"));t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.setAttribute("aria-haspopup",!0);const e=c(this,si)._signal;t.addEventListener("click",y(this,Ct,Fa).bind(this),{signal:e}),t.addEventListener("keydown",y(this,Ct,up).bind(this),{signal:e});const s=v(this,_a,document.createElement("span"));return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=c(this,zo),t.append(s),t}renderMainDropdown(){const t=v(this,he,y(this,Ct,lp).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===c(this,ei)){y(this,Ct,Fa).call(this,t);return}const e=t.target.getAttribute("data-color");e&&y(this,Ct,cp).call(this,e,t)}_moveToNext(t){var e,s;if(!c(this,Ct,ur)){y(this,Ct,Fa).call(this,t);return}if(t.target===c(this,ei)){(e=c(this,he).firstChild)==null||e.focus();return}(s=t.target.nextSibling)==null||s.focus()}_moveToPrevious(t){var e,s;if(t.target===((e=c(this,he))==null?void 0:e.firstChild)||t.target===c(this,ei)){c(this,Ct,ur)&&this._hideDropdownFromKeyboard();return}c(this,Ct,ur)||y(this,Ct,Fa).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!c(this,Ct,ur)){y(this,Ct,Fa).call(this,t);return}(e=c(this,he).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!c(this,Ct,ur)){y(this,Ct,Fa).call(this,t);return}(e=c(this,he).lastChild)==null||e.focus()}hideDropdown(){var t,e;(t=c(this,he))==null||t.classList.add("hidden"),(e=c(this,ir))==null||e.abort(),v(this,ir,null)}_hideDropdownFromKeyboard(){var t;if(!c(this,Vo)){if(!c(this,Ct,ur)){(t=c(this,ql))==null||t.unselect();return}this.hideDropdown(),c(this,ei).focus({preventScroll:!0,focusVisible:c(this,Ul)})}}updateColor(t){if(c(this,_a)&&(c(this,_a).style.backgroundColor=t),!c(this,he))return;const e=c(this,si).highlightColors.values();for(const s of c(this,he).children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){var t,e;(t=c(this,ei))==null||t.remove(),v(this,ei,null),v(this,_a,null),(e=c(this,he))==null||e.remove(),v(this,he,null)}};ei=new WeakMap,_a=new WeakMap,zo=new WeakMap,he=new WeakMap,Ul=new WeakMap,Vo=new WeakMap,ql=new WeakMap,$l=new WeakMap,ir=new WeakMap,si=new WeakMap,Go=new WeakMap,Kl=new WeakMap,Ct=new WeakSet,lp=function(){const t=document.createElement("div"),e=c(this,si)._signal;t.addEventListener("contextmenu",ws,{signal:e}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[s,i]of c(this,si).highlightColors){const n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",c(ts,Kl)[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===c(this,zo)),n.addEventListener("click",y(this,Ct,cp).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",y(this,Ct,up).bind(this),{signal:e}),t},cp=function(t,e){e.stopPropagation(),c(this,$l).dispatch("switchannotationeditorparams",{source:this,type:c(this,Go),value:t})},up=function(t){ts._keyboardManager.exec(this,t)},Fa=function(t){if(c(this,Ct,ur)){this.hideDropdown();return}if(v(this,Ul,t.detail===0),c(this,ir)||(v(this,ir,new AbortController),window.addEventListener("pointerdown",y(this,Ct,Qb).bind(this),{signal:c(this,si).combinedSignal(c(this,ir))})),c(this,he)){c(this,he).classList.remove("hidden");return}const e=v(this,he,y(this,Ct,lp).call(this));c(this,ei).append(e)},Qb=function(t){var e;(e=c(this,he))!=null&&e.contains(t.target)||this.hideDropdown()},ur=function(){return c(this,he)&&!c(this,he).classList.contains("hidden")},w(ts,Kl,null);let Nu=ts;const pt=class pt extends _t{constructor(e){super({...e,name:"highlightEditor"});w(this,it);w(this,Yo,null);w(this,Jl,0);w(this,gn);w(this,wa,null);w(this,Uo,null);w(this,Es,null);w(this,Ql,null);w(this,Zl,0);w(this,xa,null);w(this,ii,null);w(this,Me,null);w(this,es,!1);w(this,qo,null);w(this,fn);w(this,le,null);w(this,$o,"");w(this,ks);w(this,tc,"");this.color=e.color||pt._defaultColor,v(this,ks,e.thickness||pt._defaultThickness),v(this,fn,e.opacity||pt._defaultOpacity),v(this,gn,e.boxes||null),v(this,tc,e.methodOfCreation||""),v(this,$o,e.text||""),this._isDraggable=!1,e.highlightId>-1?(v(this,es,!0),y(this,it,Td).call(this,e),y(this,it,La).call(this)):c(this,gn)&&(v(this,Yo,e.anchorNode),v(this,Jl,e.anchorOffset),v(this,Ql,e.focusNode),v(this,Zl,e.focusOffset),y(this,it,dp).call(this),y(this,it,La).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=pt.prototype;return ut(this,"_keyboardManager",new Fh([[["ArrowLeft","mac+ArrowLeft"],e._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],e._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],e._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],e._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:c(this,es)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:c(this,ks),methodOfCreation:c(this,tc)}}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;_t.initialize(e,s),pt._defaultColor||(pt._defaultColor=((i=s.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,s){switch(e){case Z.HIGHLIGHT_DEFAULT_COLOR:pt._defaultColor=s;break;case Z.HIGHLIGHT_THICKNESS:pt._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return c(this,qo)}updateParams(e,s){switch(e){case Z.HIGHLIGHT_COLOR:y(this,it,Zb).call(this,s);break;case Z.HIGHLIGHT_THICKNESS:y(this,it,ty).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[Z.HIGHLIGHT_DEFAULT_COLOR,pt._defaultColor],[Z.HIGHLIGHT_THICKNESS,pt._defaultThickness]]}get propertiesToUpdate(){return[[Z.HIGHLIGHT_COLOR,this.color||pt._defaultColor],[Z.HIGHLIGHT_THICKNESS,c(this,ks)||pt._defaultThickness],[Z.HIGHLIGHT_FREE,c(this,es)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(v(this,Uo,new Nu({editor:this})),e.addColorPicker(c(this,Uo))),e):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(y(this,it,mc).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,y(this,it,mc).call(this))}onceAdded(){this.annotationElementId||this.parent.addUndoableEditor(this),this.div.focus()}remove(){y(this,it,gp).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(y(this,it,La).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?y(this,it,gp).call(this):e&&(y(this,it,La).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;c(this,es)?(e=(e-this.rotation+360)%360,i=y(n=pt,Ms,lh).call(n,c(this,ii).box,e)):i=y(r=pt,Ms,lh).call(r,this,e),s.rotate(c(this,Me),e),s.rotate(c(this,le),e),s.updateBox(c(this,Me),i),s.updateBox(c(this,le),y(a=pt,Ms,lh).call(a,c(this,Es).box,e))}render(){if(this.div)return this.div;const e=super.render();c(this,$o)&&(e.setAttribute("aria-label",c(this,$o)),e.setAttribute("role","mark")),c(this,es)?e.classList.add("free"):this.div.addEventListener("keydown",y(this,it,sy).bind(this),{signal:this._uiManager._signal});const s=v(this,xa,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=c(this,wa);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),Mu(this,c(this,xa),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){this.isSelected||this.parent.drawLayer.addClass(c(this,le),"hovered")}pointerleave(){this.isSelected||this.parent.drawLayer.removeClass(c(this,le),"hovered")}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:y(this,it,Ed).call(this,!0);break;case 1:case 3:y(this,it,Ed).call(this,!1);break}}select(){var e,s;super.select(),c(this,le)&&((e=this.parent)==null||e.drawLayer.removeClass(c(this,le),"hovered"),(s=this.parent)==null||s.drawLayer.addClass(c(this,le),"selected"))}unselect(){var e;super.unselect(),c(this,le)&&((e=this.parent)==null||e.drawLayer.removeClass(c(this,le),"selected"),c(this,es)||y(this,it,Ed).call(this,!1))}get _mustFixPosition(){return!c(this,es)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.show(c(this,Me),e),this.parent.drawLayer.show(c(this,le),e))}static startHighlighting(e,s,{target:i,x:n,y:r}){const{x:a,y:h,width:l,height:u}=i.getBoundingClientRect(),d=new AbortController,g=e.combinedSignal(d),f=m=>{m.preventDefault(),m.stopPropagation()},p=m=>{d.abort(),y(this,Ms,ay).call(this,e,m)};window.addEventListener("blur",p,{signal:g}),window.addEventListener("pointerup",p,{signal:g}),window.addEventListener("pointerdown",f,{capture:!0,passive:!1,signal:g}),window.addEventListener("contextmenu",ws,{signal:g}),i.addEventListener("pointermove",y(this,Ms,ry).bind(this,e),{signal:g}),this._freeHighlight=new vf({x:n,y:r},[a,h,l,u],e.scale,this._defaultThickness/2,s,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw(this._freeHighlight,this._defaultColor,this._defaultOpacity,!0)}static async deserialize(e,s,i){var m,_,b,x;let n=null;if(e instanceof Mv){const{data:{quadPoints:S,rect:A,rotation:k,id:P,color:M,opacity:O,popupRef:R},parent:{page:{pageNumber:I}}}=e;n=e={annotationType:nt.HIGHLIGHT,color:Array.from(M),opacity:O,quadPoints:S,boxes:null,pageIndex:I-1,rect:A.slice(0),rotation:k,id:P,deleted:!1,popupRef:R}}else if(e instanceof pf){const{data:{inkLists:S,rect:A,rotation:k,id:P,color:M,borderStyle:{rawWidth:O},popupRef:R},parent:{page:{pageNumber:I}}}=e;n=e={annotationType:nt.HIGHLIGHT,color:Array.from(M),thickness:O,inkLists:S,boxes:null,pageIndex:I-1,rect:A.slice(0),rotation:k,id:P,deleted:!1,popupRef:R}}const{color:r,quadPoints:a,inkLists:h,opacity:l}=e,u=await super.deserialize(e,s,i);u.color=U.makeHexColor(...r),v(u,fn,l||1),h&&v(u,ks,e.thickness),u.annotationElementId=e.id||null,u._initialData=n;const[d,g]=u.pageDimensions,[f,p]=u.pageTranslation;if(a){const S=v(u,gn,[]);for(let A=0;A<a.length;A+=8)S.push({x:(a[A]-f)/d,y:1-(a[A+1]-p)/g,width:(a[A+2]-a[A])/d,height:(a[A+1]-a[A+5])/g});y(m=u,it,dp).call(m),y(_=u,it,La).call(_),u.rotate(u.rotation)}else if(h){v(u,es,!0);const S=h[0],A={x:S[0]-f,y:g-(S[1]-p)},k=new vf(A,[0,0,d,g],1,c(u,ks)/2,!0,.001);for(let O=0,R=S.length;O<R;O+=2)A.x=S[O]-f,A.y=g-(S[O+1]-p),k.add(A);const{id:P,clipPathId:M}=s.drawLayer.draw(k,u.color,u._defaultOpacity,!0);y(b=u,it,Td).call(b,{highlightOutlines:k.getOutlines(),highlightId:P,clipPathId:M}),y(x=u,it,La).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=_t._colorManager.convert(this.color),n={annotationType:nt.HIGHLIGHT,color:i,opacity:c(this,fn),thickness:c(this,ks),quadPoints:y(this,it,iy).call(this),outlines:y(this,it,ny).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:y(this,it,mc).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!y(this,it,oy).call(this,n)?null:(n.id=this.annotationElementId,n)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};Yo=new WeakMap,Jl=new WeakMap,gn=new WeakMap,wa=new WeakMap,Uo=new WeakMap,Es=new WeakMap,Ql=new WeakMap,Zl=new WeakMap,xa=new WeakMap,ii=new WeakMap,Me=new WeakMap,es=new WeakMap,qo=new WeakMap,fn=new WeakMap,le=new WeakMap,$o=new WeakMap,ks=new WeakMap,tc=new WeakMap,it=new WeakSet,dp=function(){const e=new Rv(c(this,gn),.001);v(this,ii,e.getOutlines()),{x:this.x,y:this.y,width:this.width,height:this.height}=c(this,ii).box;const s=new Rv(c(this,gn),.0025,.001,this._uiManager.direction==="ltr");v(this,Es,s.getOutlines());const{lastPoint:i}=c(this,Es).box;v(this,qo,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height])},Td=function({highlightOutlines:e,highlightId:s,clipPathId:i}){var d,g;if(v(this,ii,e),v(this,Es,e.getNewOutline(c(this,ks)/2+1.5,.0025)),s>=0)v(this,Me,s),v(this,wa,i),this.parent.drawLayer.finalizeLine(s,e),v(this,le,this.parent.drawLayer.drawOutline(c(this,Es)));else if(this.parent){const f=this.parent.viewport.rotation;this.parent.drawLayer.updateLine(c(this,Me),e),this.parent.drawLayer.updateBox(c(this,Me),y(d=pt,Ms,lh).call(d,c(this,ii).box,(f-this.rotation+360)%360)),this.parent.drawLayer.updateLine(c(this,le),c(this,Es)),this.parent.drawLayer.updateBox(c(this,le),y(g=pt,Ms,lh).call(g,c(this,Es).box,f))}const{x:r,y:a,width:h,height:l}=e.box;switch(this.rotation){case 0:this.x=r,this.y=a,this.width=h,this.height=l;break;case 90:{const[f,p]=this.parentDimensions;this.x=a,this.y=1-r,this.width=h*p/f,this.height=l*f/p;break}case 180:this.x=1-r,this.y=1-a,this.width=h,this.height=l;break;case 270:{const[f,p]=this.parentDimensions;this.x=1-a,this.y=r,this.width=h*p/f,this.height=l*f/p;break}}const{lastPoint:u}=c(this,Es).box;v(this,qo,[(u[0]-r)/h,(u[1]-a)/l])},Zb=function(e){const s=(r,a)=>{var h,l,u;this.color=r,(h=this.parent)==null||h.drawLayer.changeColor(c(this,Me),r),(l=c(this,Uo))==null||l.updateColor(r),v(this,fn,a),(u=this.parent)==null||u.drawLayer.changeOpacity(c(this,Me),a)},i=this.color,n=c(this,fn);this.addCommands({cmd:s.bind(this,e,pt._defaultOpacity),undo:s.bind(this,i,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Z.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},ty=function(e){const s=c(this,ks),i=n=>{v(this,ks,n),y(this,it,ey).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:Z.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},ey=function(e){if(!c(this,es))return;y(this,it,Td).call(this,{highlightOutlines:c(this,ii).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},gp=function(){c(this,Me)===null||!this.parent||(this.parent.drawLayer.remove(c(this,Me)),v(this,Me,null),this.parent.drawLayer.remove(c(this,le)),v(this,le,null))},La=function(e=this.parent){c(this,Me)===null&&({id:Ge(this,Me)._,clipPathId:Ge(this,wa)._}=e.drawLayer.draw(c(this,ii),this.color,c(this,fn)),v(this,le,e.drawLayer.drawOutline(c(this,Es))),c(this,xa)&&(c(this,xa).style.clipPath=c(this,wa)))},Ms=new WeakSet,lh=function({x:e,y:s,width:i,height:n},r){switch(r){case 90:return{x:1-s-n,y:e,width:n,height:i};case 180:return{x:1-e-i,y:1-s-n,width:i,height:n};case 270:return{x:s,y:1-e-i,width:n,height:i}}return{x:e,y:s,width:i,height:n}},sy=function(e){pt._keyboardManager.exec(this,e)},Ed=function(e){if(!c(this,Yo))return;const s=window.getSelection();e?s.setPosition(c(this,Yo),c(this,Jl)):s.setPosition(c(this,Ql),c(this,Zl))},mc=function(){return c(this,es)?this.rotation:0},iy=function(){if(c(this,es))return null;const[e,s]=this.pageDimensions,[i,n]=this.pageTranslation,r=c(this,gn),a=new Float32Array(r.length*8);let h=0;for(const{x:l,y:u,width:d,height:g}of r){const f=l*e+i,p=(1-u-g)*s+n;a[h]=a[h+4]=f,a[h+1]=a[h+3]=p,a[h+2]=a[h+6]=f+d*e,a[h+5]=a[h+7]=p+g*s,h+=8}return a},ny=function(e){return c(this,ii).serialize(e,y(this,it,mc).call(this))},ry=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updatePath(this._freeHighlightId,this._freeHighlight)},ay=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=""},oy=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},w(pt,Ms),tt(pt,"_defaultColor",null),tt(pt,"_defaultOpacity",1),tt(pt,"_defaultThickness",12),tt(pt,"_type","highlight"),tt(pt,"_editorType",nt.HIGHLIGHT),tt(pt,"_freeHighlightId",-1),tt(pt,"_freeHighlight",null),tt(pt,"_freeHighlightClipId","");let Bu=pt;const Nt=class Nt extends _t{constructor(e){super({...e,name:"inkEditor"});w(this,N);w(this,Sa,0);w(this,Ca,0);w(this,Ti,null);w(this,pn,new Path2D);w(this,Os,!1);w(this,Aa,null);w(this,Ta,!1);w(this,Ea,!1);w(this,mn,null);w(this,Ko,null);w(this,ka,0);w(this,Ma,0);w(this,nr,null);this.color=e.color||null,this.thickness=e.thickness||null,this.opacity=e.opacity||null,this.paths=[],this.bezierPath2D=[],this.allRawPaths=[],this.currentPath=[],this.scaleFactor=1,this.translationX=this.translationY=0,this.x=0,this.y=0,this._willKeepAspectRatio=!0}static initialize(e,s){_t.initialize(e,s)}static updateDefaultParams(e,s){switch(e){case Z.INK_THICKNESS:Nt._defaultThickness=s;break;case Z.INK_COLOR:Nt._defaultColor=s;break;case Z.INK_OPACITY:Nt._defaultOpacity=s/100;break}}updateParams(e,s){switch(e){case Z.INK_THICKNESS:y(this,N,hy).call(this,s);break;case Z.INK_COLOR:y(this,N,ly).call(this,s);break;case Z.INK_OPACITY:y(this,N,cy).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[Z.INK_THICKNESS,Nt._defaultThickness],[Z.INK_COLOR,Nt._defaultColor||_t._defaultLineColor],[Z.INK_OPACITY,Math.round(Nt._defaultOpacity*100)]]}get propertiesToUpdate(){return[[Z.INK_THICKNESS,this.thickness||Nt._defaultThickness],[Z.INK_COLOR,this.color||Nt._defaultColor||_t._defaultLineColor],[Z.INK_OPACITY,Math.round(100*(this.opacity??Nt._defaultOpacity))]]}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.canvas||(y(this,N,kd).call(this),y(this,N,Md).call(this)),this.isAttachedToDOM||(this.parent.add(this),y(this,N,ch).call(this)),y(this,N,vc).call(this)))}remove(){var e;this.canvas!==null&&(this.isEmpty()||this.commit(),this.canvas.width=this.canvas.height=0,this.canvas.remove(),this.canvas=null,c(this,Ti)&&(clearTimeout(c(this,Ti)),v(this,Ti,null)),(e=c(this,mn))==null||e.disconnect(),v(this,mn,null),super.remove())}setParent(e){!this.parent&&e?this._uiManager.removeShouldRescale(this):this.parent&&e===null&&this._uiManager.addShouldRescale(this),super.setParent(e)}onScaleChanging(){const[e,s]=this.parentDimensions,i=this.width*e,n=this.height*s;this.setDimensions(i,n)}enableEditMode(){c(this,Os)||this.canvas===null||(super.enableEditMode(),this._isDraggable=!1,y(this,N,mp).call(this))}disableEditMode(){!this.isInEditMode()||this.canvas===null||(super.disableEditMode(),this._isDraggable=!this.isEmpty(),this.div.classList.remove("editing"),y(this,N,vp).call(this))}onceAdded(){this._isDraggable=!this.isEmpty()}isEmpty(){return this.paths.length===0||this.paths.length===1&&this.paths[0].length===0}commit(){c(this,Os)||(super.commit(),this.isEditing=!1,this.disableEditMode(),this.setInForeground(),v(this,Os,!0),this.div.classList.add("disabled"),y(this,N,vc).call(this,!0),this.select(),this.parent.addInkEditorIfNeeded(!0),this.moveInDOM(),this.div.focus({preventScroll:!0}))}focusin(e){this._focusEventsAllowed&&(super.focusin(e),this.enableEditMode())}canvasPointerdown(e){e.button!==0||!this.isInEditMode()||c(this,Os)||(this.setInForeground(),e.preventDefault(),this.div.contains(document.activeElement)||this.div.focus({preventScroll:!0}),y(this,N,dy).call(this,e.offsetX,e.offsetY))}canvasPointermove(e){e.preventDefault(),y(this,N,pp).call(this,e.offsetX,e.offsetY)}canvasPointerup(e){e.preventDefault(),y(this,N,bp).call(this,e)}canvasPointerleave(e){y(this,N,bp).call(this,e)}get isResizable(){return!this.isEmpty()&&c(this,Os)}render(){if(this.div)return this.div;let e,s;this.width&&(e=this.x,s=this.y),super.render(),this.div.setAttribute("data-l10n-id","pdfjs-ink");const[i,n,r,a]=y(this,N,uy).call(this);if(this.setAt(i,n,0,0),this.setDims(r,a),y(this,N,kd).call(this),this.width){const[h,l]=this.parentDimensions;this.setAspectRatio(this.width*h,this.height*l),this.setAt(e*h,s*l,this.width*h,this.height*l),v(this,Ea,!0),y(this,N,ch).call(this),this.setDims(this.width*h,this.height*l),y(this,N,Ia).call(this),this.div.classList.add("disabled")}else this.div.classList.add("editing"),this.enableEditMode();return y(this,N,Md).call(this),this.div}setDimensions(e,s){const i=Math.round(e),n=Math.round(s);if(c(this,ka)===i&&c(this,Ma)===n)return;v(this,ka,i),v(this,Ma,n),this.canvas.style.visibility="hidden";const[r,a]=this.parentDimensions;this.width=e/r,this.height=s/a,this.fixAndSetPosition(),c(this,Os)&&y(this,N,yp).call(this,e,s),y(this,N,ch).call(this),y(this,N,Ia).call(this),this.canvas.style.visibility="visible",this.fixDims()}static async deserialize(e,s,i){var _,b,x;if(e instanceof pf)return null;const n=await super.deserialize(e,s,i);n.thickness=e.thickness,n.color=U.makeHexColor(...e.color),n.opacity=e.opacity;const[r,a]=n.pageDimensions,h=n.width*r,l=n.height*a,u=n.parentScale,d=e.thickness/2;v(n,Os,!0),v(n,ka,Math.round(h)),v(n,Ma,Math.round(l));const{paths:g,rect:f,rotation:p}=e;for(let{bezier:S}of g){S=y(_=Nt,vn,yy).call(_,S,f,p);const A=[];n.paths.push(A);let k=u*(S[0]-d),P=u*(S[1]-d);for(let O=2,R=S.length;O<R;O+=6){const I=u*(S[O]-d),j=u*(S[O+1]-d),G=u*(S[O+2]-d),L=u*(S[O+3]-d),H=u*(S[O+4]-d),$=u*(S[O+5]-d);A.push([[k,P],[I,j],[G,L],[H,$]]),k=H,P=$}const M=y(this,vn,by).call(this,A);n.bezierPath2D.push(M)}const m=y(b=n,N,wp).call(b);return v(n,Ca,Math.max(_t.MIN_SIZE,m[2]-m[0])),v(n,Sa,Math.max(_t.MIN_SIZE,m[3]-m[1])),y(x=n,N,yp).call(x,h,l),n}serialize(){if(this.isEmpty())return null;const e=this.getRect(0,0),s=_t._colorManager.convert(this.ctx.strokeStyle);return{annotationType:nt.INK,color:s,thickness:this.thickness,opacity:this.opacity,paths:y(this,N,_y).call(this,this.scaleFactor/this.parentScale,this.translationX,this.translationY,e),pageIndex:this.pageIndex,rect:e,rotation:this.rotation,structTreeParentId:this._structTreeParentId}}};Sa=new WeakMap,Ca=new WeakMap,Ti=new WeakMap,pn=new WeakMap,Os=new WeakMap,Aa=new WeakMap,Ta=new WeakMap,Ea=new WeakMap,mn=new WeakMap,Ko=new WeakMap,ka=new WeakMap,Ma=new WeakMap,nr=new WeakMap,N=new WeakSet,hy=function(e){const s=n=>{this.thickness=n,y(this,N,vc).call(this)},i=this.thickness;this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Z.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0})},ly=function(e){const s=n=>{this.color=n,y(this,N,Ia).call(this)},i=this.color;this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Z.INK_COLOR,overwriteIfSameType:!0,keepUndo:!0})},cy=function(e){const s=n=>{this.opacity=n,y(this,N,Ia).call(this)};e/=100;const i=this.opacity;this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Z.INK_OPACITY,overwriteIfSameType:!0,keepUndo:!0})},uy=function(){const{parentRotation:e,parentDimensions:[s,i]}=this;switch(e){case 90:return[0,i,i,s];case 180:return[s,i,s,i];case 270:return[s,0,i,s];default:return[0,0,s,i]}},fp=function(){const{ctx:e,color:s,opacity:i,thickness:n,parentScale:r,scaleFactor:a}=this;e.lineWidth=n*r/a,e.lineCap="round",e.lineJoin="round",e.miterLimit=10,e.strokeStyle=`${s}${Hx(i)}`},dy=function(e,s){this.canvas.addEventListener("contextmenu",ws,{signal:this._uiManager._signal}),y(this,N,vp).call(this),v(this,Aa,new AbortController);const i=this._uiManager.combinedSignal(c(this,Aa));this.canvas.addEventListener("pointerleave",this.canvasPointerleave.bind(this),{signal:i}),this.canvas.addEventListener("pointermove",this.canvasPointermove.bind(this),{signal:i}),this.canvas.addEventListener("pointerup",this.canvasPointerup.bind(this),{signal:i}),this.isEditing=!0,c(this,Ea)||(v(this,Ea,!0),y(this,N,ch).call(this),this.thickness||(this.thickness=Nt._defaultThickness),this.color||(this.color=Nt._defaultColor||_t._defaultLineColor),this.opacity??(this.opacity=Nt._defaultOpacity)),this.currentPath.push([e,s]),v(this,Ta,!1),y(this,N,fp).call(this),v(this,nr,()=>{y(this,N,py).call(this),c(this,nr)&&window.requestAnimationFrame(c(this,nr))}),window.requestAnimationFrame(c(this,nr))},pp=function(e,s){const[i,n]=this.currentPath.at(-1);if(this.currentPath.length>1&&e===i&&s===n)return;const r=this.currentPath;let a=c(this,pn);if(r.push([e,s]),v(this,Ta,!0),r.length<=2){a.moveTo(...r[0]),a.lineTo(e,s);return}r.length===3&&(v(this,pn,a=new Path2D),a.moveTo(...r[0])),y(this,N,my).call(this,a,...r.at(-3),...r.at(-2),e,s)},gy=function(){if(this.currentPath.length===0)return;const e=this.currentPath.at(-1);c(this,pn).lineTo(...e)},fy=function(e,s){v(this,nr,null),e=Math.min(Math.max(e,0),this.canvas.width),s=Math.min(Math.max(s,0),this.canvas.height),y(this,N,pp).call(this,e,s),y(this,N,gy).call(this);let i;if(this.currentPath.length!==1)i=y(this,N,vy).call(this);else{const l=[e,s];i=[[l,l.slice(),l.slice(),l]]}const n=c(this,pn),r=this.currentPath;this.currentPath=[],v(this,pn,new Path2D);const a=()=>{this.allRawPaths.push(r),this.paths.push(i),this.bezierPath2D.push(n),this._uiManager.rebuild(this)},h=()=>{this.allRawPaths.pop(),this.paths.pop(),this.bezierPath2D.pop(),this.paths.length===0?this.remove():(this.canvas||(y(this,N,kd).call(this),y(this,N,Md).call(this)),y(this,N,vc).call(this))};this.addCommands({cmd:a,undo:h,mustExec:!0})},py=function(){if(!c(this,Ta))return;v(this,Ta,!1);const e=Math.ceil(this.thickness*this.parentScale),s=this.currentPath.slice(-3),i=s.map(a=>a[0]),n=s.map(a=>a[1]);Math.min(...i)-e,Math.max(...i)+e,Math.min(...n)-e,Math.max(...n)+e;const{ctx:r}=this;r.save(),r.clearRect(0,0,this.canvas.width,this.canvas.height);for(const a of this.bezierPath2D)r.stroke(a);r.stroke(c(this,pn)),r.restore()},my=function(e,s,i,n,r,a,h){const l=(s+n)/2,u=(i+r)/2,d=(n+a)/2,g=(r+h)/2;e.bezierCurveTo(l+2*(n-l)/3,u+2*(r-u)/3,d+2*(n-d)/3,g+2*(r-g)/3,d,g)},vy=function(){const e=this.currentPath;if(e.length<=2)return[[e[0],e[0],e.at(-1),e.at(-1)]];const s=[];let i,[n,r]=e[0];for(i=1;i<e.length-2;i++){const[f,p]=e[i],[m,_]=e[i+1],b=(f+m)/2,x=(p+_)/2,S=[n+2*(f-n)/3,r+2*(p-r)/3],A=[b+2*(f-b)/3,x+2*(p-x)/3];s.push([[n,r],S,A,[b,x]]),[n,r]=[b,x]}const[a,h]=e[i],[l,u]=e[i+1],d=[n+2*(a-n)/3,r+2*(h-r)/3],g=[l+2*(a-l)/3,u+2*(h-u)/3];return s.push([[n,r],d,g,[l,u]]),s},Ia=function(){if(this.isEmpty()){y(this,N,Od).call(this);return}y(this,N,fp).call(this);const{canvas:e,ctx:s}=this;s.setTransform(1,0,0,1,0,0),s.clearRect(0,0,e.width,e.height),y(this,N,Od).call(this);for(const i of this.bezierPath2D)s.stroke(i)},mp=function(){if(c(this,Ko))return;v(this,Ko,new AbortController);const e=this._uiManager.combinedSignal(c(this,Ko));this.canvas.addEventListener("pointerdown",this.canvasPointerdown.bind(this),{signal:e})},vp=function(){var e;(e=this.pointerdownAC)==null||e.abort(),this.pointerdownAC=null},bp=function(e){var s;(s=c(this,Aa))==null||s.abort(),v(this,Aa,null),y(this,N,mp).call(this),c(this,Ti)&&clearTimeout(c(this,Ti)),v(this,Ti,setTimeout(()=>{v(this,Ti,null),this.canvas.removeEventListener("contextmenu",ws)},10)),y(this,N,fy).call(this,e.offsetX,e.offsetY),this.addToAnnotationStorage(),this.setInBackground()},kd=function(){this.canvas=document.createElement("canvas"),this.canvas.width=this.canvas.height=0,this.canvas.className="inkEditorCanvas",this.canvas.setAttribute("data-l10n-id","pdfjs-ink-canvas"),this.div.append(this.canvas),this.ctx=this.canvas.getContext("2d")},Md=function(){v(this,mn,new ResizeObserver(e=>{const s=e[0].contentRect;s.width&&s.height&&this.setDimensions(s.width,s.height)})),c(this,mn).observe(this.div),this._uiManager._signal.addEventListener("abort",()=>{var e;(e=c(this,mn))==null||e.disconnect(),v(this,mn,null)},{once:!0})},ch=function(){if(!c(this,Ea))return;const[e,s]=this.parentDimensions;this.canvas.width=Math.ceil(this.width*e),this.canvas.height=Math.ceil(this.height*s),y(this,N,Od).call(this)},yp=function(e,s){const i=y(this,N,Pd).call(this),n=(e-i)/c(this,Ca),r=(s-i)/c(this,Sa);this.scaleFactor=Math.min(n,r)},Od=function(){const e=y(this,N,Pd).call(this)/2;this.ctx.setTransform(this.scaleFactor,0,0,this.scaleFactor,this.translationX*this.scaleFactor+e,this.translationY*this.scaleFactor+e)},vn=new WeakSet,by=function(e){const s=new Path2D;for(let i=0,n=e.length;i<n;i++){const[r,a,h,l]=e[i];i===0&&s.moveTo(...r),s.bezierCurveTo(a[0],a[1],h[0],h[1],l[0],l[1])}return s},_p=function(e,s,i){const[n,r,a,h]=s;switch(i){case 0:for(let l=0,u=e.length;l<u;l+=2)e[l]+=n,e[l+1]=h-e[l+1];break;case 90:for(let l=0,u=e.length;l<u;l+=2){const d=e[l];e[l]=e[l+1]+n,e[l+1]=d+r}break;case 180:for(let l=0,u=e.length;l<u;l+=2)e[l]=a-e[l],e[l+1]+=r;break;case 270:for(let l=0,u=e.length;l<u;l+=2){const d=e[l];e[l]=a-e[l+1],e[l+1]=h-d}break;default:throw new Error("Invalid rotation")}return e},yy=function(e,s,i){const[n,r,a,h]=s;switch(i){case 0:for(let l=0,u=e.length;l<u;l+=2)e[l]-=n,e[l+1]=h-e[l+1];break;case 90:for(let l=0,u=e.length;l<u;l+=2){const d=e[l];e[l]=e[l+1]-r,e[l+1]=d-n}break;case 180:for(let l=0,u=e.length;l<u;l+=2)e[l]=a-e[l],e[l+1]-=r;break;case 270:for(let l=0,u=e.length;l<u;l+=2){const d=e[l];e[l]=h-e[l+1],e[l+1]=a-d}break;default:throw new Error("Invalid rotation")}return e},_y=function(e,s,i,n){var u,d;const r=[],a=this.thickness/2,h=e*s+a,l=e*i+a;for(const g of this.paths){const f=[],p=[];for(let m=0,_=g.length;m<_;m++){const[b,x,S,A]=g[m];if(b[0]===A[0]&&b[1]===A[1]&&_===1){const L=e*b[0]+h,H=e*b[1]+l;f.push(L,H),p.push(L,H);break}const k=e*b[0]+h,P=e*b[1]+l,M=e*x[0]+h,O=e*x[1]+l,R=e*S[0]+h,I=e*S[1]+l,j=e*A[0]+h,G=e*A[1]+l;m===0&&(f.push(k,P),p.push(k,P)),f.push(M,O,R,I,j,G),p.push(M,O),m===_-1&&p.push(j,G)}r.push({bezier:y(u=Nt,vn,_p).call(u,f,n,this.rotation),points:y(d=Nt,vn,_p).call(d,p,n,this.rotation)})}return r},wp=function(){let e=1/0,s=-1/0,i=1/0,n=-1/0;for(const r of this.paths)for(const[a,h,l,u]of r){const d=U.bezierBoundingBox(...a,...h,...l,...u);e=Math.min(e,d[0]),i=Math.min(i,d[1]),s=Math.max(s,d[2]),n=Math.max(n,d[3])}return[e,i,s,n]},Pd=function(){return c(this,Os)?Math.ceil(this.thickness*this.parentScale):0},vc=function(e=!1){if(this.isEmpty())return;if(!c(this,Os)){y(this,N,Ia).call(this);return}const s=y(this,N,wp).call(this),i=y(this,N,Pd).call(this);v(this,Ca,Math.max(_t.MIN_SIZE,s[2]-s[0])),v(this,Sa,Math.max(_t.MIN_SIZE,s[3]-s[1]));const n=Math.ceil(i+c(this,Ca)*this.scaleFactor),r=Math.ceil(i+c(this,Sa)*this.scaleFactor),[a,h]=this.parentDimensions;this.width=n/a,this.height=r/h,this.setAspectRatio(n,r);const l=this.translationX,u=this.translationY;this.translationX=-s[0],this.translationY=-s[1],y(this,N,ch).call(this),y(this,N,Ia).call(this),v(this,ka,n),v(this,Ma,r),this.setDims(n,r);const d=e?i/this.scaleFactor/2:0;this.translate(l-this.translationX-d,u-this.translationY-d)},w(Nt,vn),tt(Nt,"_defaultColor",null),tt(Nt,"_defaultOpacity",1),tt(Nt,"_defaultThickness",1),tt(Nt,"_type","ink"),tt(Nt,"_editorType",nt.INK);let bf=Nt;const ec=class ec extends _t{constructor(e){super({...e,name:"stampEditor"});w(this,ht);w(this,Bt,null);w(this,ve,null);w(this,rr,null);w(this,bn,null);w(this,ar,null);w(this,Jo,"");w(this,Ei,null);w(this,yn,null);w(this,ki,null);w(this,ps,!1);w(this,Qo,!1);v(this,bn,e.bitmapUrl),v(this,ar,e.bitmapFile)}static initialize(e,s){_t.initialize(e,s)}static get supportedTypes(){return ut(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return ut(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 l=h.output;return await this.setGuessedAltText(l),s&&!this.hasAltTextData()&&(this.altTextData={alt:l,decorative:!1}),l}remove(){var e,s;c(this,ve)&&(v(this,Bt,null),this._uiManager.imageManager.deleteId(c(this,ve)),(e=c(this,Ei))==null||e.remove(),v(this,Ei,null),(s=c(this,yn))==null||s.disconnect(),v(this,yn,null),c(this,ki)&&(clearTimeout(c(this,ki)),v(this,ki,null))),super.remove()}rebuild(){if(!this.parent){c(this,ve)&&y(this,ht,Dd).call(this);return}super.rebuild(),this.div!==null&&(c(this,ve)&&c(this,Ei)===null&&y(this,ht,Dd).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(){this._isDraggable=!0,this.div.focus()}isEmpty(){return!(c(this,rr)||c(this,Bt)||c(this,bn)||c(this,ar)||c(this,ve))}get isResizable(){return!0}render(){if(this.div)return this.div;let e,s;if(this.width&&(e=this.x,s=this.y),super.render(),this.div.hidden=!0,this.div.setAttribute("role","figure"),this.addAltTextButton(),c(this,Bt)?y(this,ht,xp).call(this):y(this,ht,Dd).call(this),this.width&&!this.annotationElementId){const[i,n]=this.parentDimensions;this.setAt(e*i,s*n,this.width*i,this.height*n)}return this.div}copyCanvas(e,s,i=!1){var f;e||(e=224);const{width:n,height:r}=c(this,Bt),a=new qg;let h=c(this,Bt),l=n,u=r,d=null;if(s){if(n>s||r>s){const O=Math.min(s/n,s/r);l=Math.floor(n*O),u=Math.floor(r*O)}d=document.createElement("canvas");const p=d.width=Math.ceil(l*a.sx),m=d.height=Math.ceil(u*a.sy);c(this,ps)||(h=y(this,ht,Rd).call(this,p,m));const _=d.getContext("2d");_.filter=this._uiManager.hcmFilter;let b="white",x="#cfcfd8";this._uiManager.hcmFilter!=="none"?x="black":(f=window.matchMedia)!=null&&f.call(window,"(prefers-color-scheme: dark)").matches&&(b="#8f8f9d",x="#42414d");const S=15,A=S*a.sx,k=S*a.sy,P=new OffscreenCanvas(A*2,k*2),M=P.getContext("2d");M.fillStyle=b,M.fillRect(0,0,A*2,k*2),M.fillStyle=x,M.fillRect(0,0,A,k),M.fillRect(A,k,A,k),_.fillStyle=_.createPattern(P,"repeat"),_.fillRect(0,0,p,m),_.drawImage(h,0,0,h.width,h.height,0,0,p,m)}let g=null;if(i){let p,m;if(a.symmetric&&h.width<e&&h.height<e)p=h.width,m=h.height;else if(h=c(this,Bt),n>e||r>e){const x=Math.min(e/n,e/r);p=Math.floor(n*x),m=Math.floor(r*x),c(this,ps)||(h=y(this,ht,Rd).call(this,p,m))}const b=new OffscreenCanvas(p,m).getContext("2d",{willReadFrequently:!0});b.drawImage(h,0,0,h.width,h.height,0,0,p,m),g={width:p,height:m,data:b.getImageData(0,0,p,m).data}}return{canvas:d,width:l,height:u,imageData:g}}getImageForAltText(){return c(this,Ei)}static async deserialize(e,s,i){var m;let n=null;if(e instanceof Ov){const{data:{rect:_,rotation:b,id:x,structParent:S,popupRef:A},container:k,parent:{page:{pageNumber:P}}}=e,M=k.querySelector("canvas"),O=i.imageManager.getFromCanvas(k.id,M);M.remove();const R=((m=await s._structTree.getAriaAttributes(`${zg}${x}`))==null?void 0:m.get("aria-label"))||"";n=e={annotationType:nt.STAMP,bitmapId:O.id,bitmap:O.bitmap,pageIndex:P-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:l,bitmapId:u,isSvg:d,accessibilityData:g}=e;u&&i.imageManager.isValidId(u)?(v(r,ve,u),h&&v(r,Bt,h)):v(r,bn,l),v(r,ps,d);const[f,p]=r.pageDimensions;return r.width=(a[2]-a[0])/f,r.height=(a[3]-a[1])/p,r.annotationElementId=e.id||null,g&&(r.altTextData=g),r._initialData=n,v(r,Qo,!!n),r}serialize(e=!1,s=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const i={annotationType:nt.STAMP,bitmapId:c(this,ve),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:c(this,ps),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=y(this,ht,Fd).call(this,!0),i.accessibilityData=this.serializeAltText(!0),i;const{decorative:n,altText:r}=this.serializeAltText(!1);if(!n&&r&&(i.accessibilityData={type:"Figure",alt:r}),this.annotationElementId){const h=y(this,ht,Sy).call(this,i);if(h.isSame)return null;h.isSameAltText?delete i.accessibilityData:i.accessibilityData.structParent=this._initialData.structParent??-1}if(i.id=this.annotationElementId,s===null)return i;s.stamps||(s.stamps=new Map);const a=c(this,ps)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!s.stamps.has(c(this,ve)))s.stamps.set(c(this,ve),{area:a,serialized:i}),i.bitmap=y(this,ht,Fd).call(this,!1);else if(c(this,ps)){const h=s.stamps.get(c(this,ve));a>h.area&&(h.area=a,h.serialized.bitmap.close(),h.serialized.bitmap=y(this,ht,Fd).call(this,!1))}return i}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}};Bt=new WeakMap,ve=new WeakMap,rr=new WeakMap,bn=new WeakMap,ar=new WeakMap,Jo=new WeakMap,Ei=new WeakMap,yn=new WeakMap,ki=new WeakMap,ps=new WeakMap,Qo=new WeakMap,ht=new WeakSet,bc=function(e,s=!1){if(!e){this.remove();return}v(this,Bt,e.bitmap),s||(v(this,ve,e.id),v(this,ps,e.isSvg)),e.file&&v(this,Jo,e.file.name),y(this,ht,xp).call(this)},yc=function(){if(v(this,rr,null),this._uiManager.enableWaiting(!1),!!c(this,Ei)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&c(this,Bt)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&c(this,Bt)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},Dd=function(){if(c(this,ve)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(c(this,ve)).then(i=>y(this,ht,bc).call(this,i,!0)).finally(()=>y(this,ht,yc).call(this));return}if(c(this,bn)){const i=c(this,bn);v(this,bn,null),this._uiManager.enableWaiting(!0),v(this,rr,this._uiManager.imageManager.getFromUrl(i).then(n=>y(this,ht,bc).call(this,n)).finally(()=>y(this,ht,yc).call(this)));return}if(c(this,ar)){const i=c(this,ar);v(this,ar,null),this._uiManager.enableWaiting(!0),v(this,rr,this._uiManager.imageManager.getFromFile(i).then(n=>y(this,ht,bc).call(this,n)).finally(()=>y(this,ht,yc).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=ec.supportedTypesStr;const s=this._uiManager._signal;v(this,rr,new Promise(i=>{e.addEventListener("change",async()=>{if(!e.files||e.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const n=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),y(this,ht,bc).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>y(this,ht,yc).call(this))),e.click()},xp=function(){const{div:e}=this;let{width:s,height:i}=c(this,Bt);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 d=Math.min(a*n/s,a*r/i);s*=d,i*=d}const[h,l]=this.parentDimensions;this.setDims(s*h/n,i*l/r),this._uiManager.enableWaiting(!1);const u=v(this,Ei,document.createElement("canvas"));u.setAttribute("role","img"),this.addContainer(u),(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),y(this,ht,Sp).call(this,s,i),y(this,ht,xy).call(this),c(this,Qo)||(this.parent.addUndoableEditor(this),v(this,Qo,!0)),this._reportTelemetry({action:"inserted_image"}),c(this,Jo)&&u.setAttribute("aria-label",c(this,Jo))},wy=function(e,s){var a;const[i,n]=this.parentDimensions;this.width=e/i,this.height=s/n,(a=this._initialOptions)!=null&&a.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,c(this,ki)!==null&&clearTimeout(c(this,ki)),v(this,ki,setTimeout(()=>{v(this,ki,null),y(this,ht,Sp).call(this,e,s)},200))},Rd=function(e,s){const{width:i,height:n}=c(this,Bt);let r=i,a=n,h=c(this,Bt);for(;r>2*e||a>2*s;){const l=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,l,u,0,0,r,a),h=d.transferToImageBitmap()}return h},Sp=function(e,s){const i=new qg,n=Math.ceil(e*i.sx),r=Math.ceil(s*i.sy),a=c(this,Ei);if(!a||a.width===n&&a.height===r)return;a.width=n,a.height=r;const h=c(this,ps)?c(this,Bt):y(this,ht,Rd).call(this,n,r),l=a.getContext("2d");l.filter=this._uiManager.hcmFilter,l.drawImage(h,0,0,h.width,h.height,0,0,n,r)},Fd=function(e){if(e){if(c(this,ps)){const n=this._uiManager.imageManager.getSvgUrl(c(this,ve));if(n)return n}const s=document.createElement("canvas");return{width:s.width,height:s.height}=c(this,Bt),s.getContext("2d").drawImage(c(this,Bt),0,0),s.toDataURL()}if(c(this,ps)){const[s,i]=this.pageDimensions,n=Math.round(this.width*s*Rn.PDF_TO_CSS_UNITS),r=Math.round(this.height*i*Rn.PDF_TO_CSS_UNITS),a=new OffscreenCanvas(n,r);return a.getContext("2d").drawImage(c(this,Bt),0,0,c(this,Bt).width,c(this,Bt).height,0,0,n,r),a.transferToImageBitmap()}return structuredClone(c(this,Bt))},xy=function(){this._uiManager._signal&&(v(this,yn,new ResizeObserver(e=>{const s=e[0].contentRect;s.width&&s.height&&y(this,ht,wy).call(this,s.width,s.height)})),c(this,yn).observe(this.div),this._uiManager._signal.addEventListener("abort",()=>{var e;(e=c(this,yn))==null||e.disconnect(),v(this,yn,null)},{once:!0}))},Sy=function(e){var l;const{rect:s,pageIndex:i,accessibilityData:{altText:n}}=this._initialData,r=e.rect.every((u,d)=>Math.abs(u-s[d])<1),a=e.pageIndex===i,h=(((l=e.accessibilityData)==null?void 0:l.alt)||"")===n;return{isSame:r&&a&&h,isSameAltText:h}},tt(ec,"_type","stamp"),tt(ec,"_editorType",nt.STAMP);let yf=ec;const ni=class ni{constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:a,textLayer:h,viewport:l,l10n:u}){w(this,be);w(this,Oa);w(this,Zo,!1);w(this,Mi,null);w(this,or,null);w(this,_n,null);w(this,ms,new Map);w(this,hr,!1);w(this,th,!1);w(this,eh,!1);w(this,Oe,null);w(this,wn,null);w(this,q);const d=[...c(ni,lr).values()];if(!ni._initialized){ni._initialized=!0;for(const g of d)g.initialize(u,t)}t.registerEditorTypes(d),v(this,q,t),this.pageIndex=e,this.div=s,v(this,Oa,n),v(this,Mi,r),this.viewport=l,v(this,Oe,h),this.drawLayer=a,this._structTree=i,c(this,q).addLayer(this)}get isEmpty(){return c(this,ms).size===0}get isInvisible(){return this.isEmpty&&c(this,q).getMode()===nt.NONE}updateToolbar(t){c(this,q).updateToolbar(t)}updateMode(t=c(this,q).getMode()){switch(y(this,be,Ld).call(this),t){case nt.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case nt.INK:this.addInkEditorIfNeeded(!1),this.disableTextSelection(),this.togglePointerEvents(!0),this.disableClick();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 c(ni,lr).values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=c(this,Oe))==null?void 0:e.div)}addInkEditorIfNeeded(t){if(c(this,q).getMode()!==nt.INK)return;if(!t){for(const s of c(this,ms).values())if(s.isEmpty()){s.setInBackground();return}}this.createAndAddNewEditor({offsetX:0,offsetY:0},!1).setInBackground()}setEditingState(t){c(this,q).setEditingState(t)}addCommands(t){c(this,q).addCommands(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){var e;(e=c(this,Mi))==null||e.div.classList.toggle("disabled",!t)}async enable(){this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of c(this,ms).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(c(this,q).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!c(this,Mi))return;const e=c(this,Mi).getEditableAnnotations();for(const s of e){if(s.hide(),c(this,q).isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}}disable(){var i;v(this,eh,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const n of c(this,ms).values())if(n.disableEditing(),!!n.annotationElementId){if(n.serialize()!==null){t.set(n.annotationElementId,n);continue}else e.set(n.annotationElementId,n);(i=this.getEditableAnnotation(n.annotationElementId))==null||i.show(),n.remove()}if(c(this,Mi)){const n=c(this,Mi).getEditableAnnotations();for(const r of n){const{id:a}=r.data;if(c(this,q).isDeletedAnnotationElement(a))continue;let h=e.get(a);if(h){h.resetAnnotationElement(r),h.show(!1),r.show();continue}h=t.get(a),h&&(c(this,q).addChangedExistingAnnotation(h),h.renderAnnotationElement(r)&&h.show(!1)),r.show()}}y(this,be,Ld).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of c(ni,lr).values())s.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),v(this,eh,!1)}getEditableAnnotation(t){var e;return((e=c(this,Mi))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){c(this,q).getActive()!==t&&c(this,q).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=c(this,Oe))!=null&&t.div&&!c(this,wn)){v(this,wn,new AbortController);const e=c(this,q).combinedSignal(c(this,wn));c(this,Oe).div.addEventListener("pointerdown",y(this,be,Cy).bind(this),{signal:e}),c(this,Oe).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=c(this,Oe))!=null&&t.div&&c(this,wn)&&(c(this,wn).abort(),v(this,wn,null),c(this,Oe).div.classList.remove("highlighting"))}enableClick(){if(c(this,or))return;v(this,or,new AbortController);const t=c(this,q).combinedSignal(c(this,or));this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t}),this.div.addEventListener("pointerup",this.pointerup.bind(this),{signal:t})}disableClick(){var t;(t=c(this,or))==null||t.abort(),v(this,or,null)}attach(t){c(this,ms).set(t.id,t);const{annotationElementId:e}=t;e&&c(this,q).isDeletedAnnotationElement(e)&&c(this,q).removeDeletedAnnotationElement(t)}detach(t){var e;c(this,ms).delete(t.id),(e=c(this,Oa))==null||e.removePointerInTextLayer(t.contentDiv),!c(this,eh)&&t.annotationElementId&&c(this,q).addDeletedAnnotationElement(t)}remove(t){this.detach(t),c(this,q).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1,c(this,th)||this.addInkEditorIfNeeded(!1)}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(c(this,q).addDeletedAnnotationElement(t.annotationElementId),_t.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),(e=t.parent)==null||e.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(!(t.parent===this&&t.isAttachedToDOM)){if(this.changeParent(t),c(this,q).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(),c(this,q).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!c(this,_n)&&(t._focusEventsAllowed=!1,v(this,_n,setTimeout(()=>{v(this,_n,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:c(this,q)._signal}),e.focus())},0))),t._structTreeParentId=(s=c(this,Oa))==null?void 0:s.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||(t.parent=this),t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getNextId(){return c(this,q).getId()}combinedSignal(t){return c(this,q).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=c(this,be,Cp))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){c(this,q).updateToolbar(t),c(this,q).updateMode(t);const{offsetX:s,offsetY:i}=y(this,be,Tp).call(this),n=this.getNextId(),r=y(this,be,Ap).call(this,{parent:this,id:n,x:s,y:i,uiManager:c(this,q),isCentered:!0,...e});r&&this.add(r)}async deserialize(t){var e;return await((e=c(ni,lr).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,c(this,q)))||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=y(this,be,Ap).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:c(this,q),isCentered:e,...s});return n&&this.add(n),n}addNewEditor(){this.createAndAddNewEditor(y(this,be,Tp).call(this),!0)}setSelected(t){c(this,q).setSelected(t)}toggleSelected(t){c(this,q).toggleSelected(t)}unselect(t){c(this,q).unselect(t)}pointerup(t){const{isMac:e}=Ne.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&c(this,hr)){if(v(this,hr,!1),!c(this,Zo)){v(this,Zo,!0);return}if(c(this,q).getMode()===nt.STAMP){c(this,q).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){if(c(this,q).getMode()===nt.HIGHLIGHT&&this.enableTextSelection(),c(this,hr)){v(this,hr,!1);return}const{isMac:e}=Ne.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;v(this,hr,!0);const s=c(this,q).getActive();v(this,Zo,!s||s.isEmpty())}findNewParent(t,e,s){const i=c(this,q).findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}destroy(){var t,e;((t=c(this,q).getActive())==null?void 0:t.parent)===this&&(c(this,q).commitOrRemove(),c(this,q).setActiveEditor(null)),c(this,_n)&&(clearTimeout(c(this,_n)),v(this,_n,null));for(const s of c(this,ms).values())(e=c(this,Oa))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,c(this,ms).clear(),c(this,q).removeLayer(this)}render({viewport:t}){this.viewport=t,kr(this.div,t);for(const e of c(this,q).getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){c(this,q).commitOrRemove(),y(this,be,Ld).call(this);const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,kr(this.div,{rotation:s}),e!==s)for(const i of c(this,ms).values())i.rotate(s);this.addInkEditorIfNeeded(!1)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return c(this,q).viewParameters.realScale}};Oa=new WeakMap,Zo=new WeakMap,Mi=new WeakMap,or=new WeakMap,_n=new WeakMap,ms=new WeakMap,hr=new WeakMap,th=new WeakMap,eh=new WeakMap,Oe=new WeakMap,wn=new WeakMap,q=new WeakMap,lr=new WeakMap,be=new WeakSet,Cy=function(t){c(this,q).unselectAll();const{target:e}=t;if(e===c(this,Oe).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&c(this,Oe).div.contains(e)){const{isMac:s}=Ne.platform;if(t.button!==0||t.ctrlKey&&s)return;c(this,q).showAllEditors("highlight",!0,!0),c(this,Oe).div.classList.add("free"),this.toggleDrawing(),Bu.startHighlighting(this,c(this,q).direction==="ltr",{target:c(this,Oe).div,x:t.x,y:t.y}),c(this,Oe).div.addEventListener("pointerup",()=>{c(this,Oe).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:c(this,q)._signal}),t.preventDefault()}},Cp=function(){return c(ni,lr).get(c(this,q).getMode())},Ap=function(t){const e=c(this,be,Cp);return e?new e.prototype.constructor(t):null},Tp=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),l=(n+a)/2-t,u=(r+h)/2-e,[d,g]=this.viewport.rotation%180===0?[l,u]:[u,l];return{offsetX:d,offsetY:g}},Ld=function(){v(this,th,!0);for(const t of c(this,ms).values())t.isEmpty()&&t.remove();v(this,th,!1)},tt(ni,"_initialized",!1),w(ni,lr,new Map([mf,bf,yf,Bu].map(t=>[t._editorType,t])));let _f=ni;const ye=class ye{constructor({pageIndex:t}){w(this,Pa);w(this,Oi,null);w(this,sc,0);w(this,Zt,new Map);w(this,xn,new Map);this.pageIndex=t}setParent(t){if(!c(this,Oi)){v(this,Oi,t);return}if(c(this,Oi)!==t){if(c(this,Zt).size>0)for(const e of c(this,Zt).values())e.remove(),t.append(e);v(this,Oi,t)}}static get _svgFactory(){return ut(this,"_svgFactory",new gf)}draw(t,e,s,i=!1){const n=Ge(this,sc)._++,r=y(this,Pa,kp).call(this,t.box);r.classList.add(...t.classNamesForDrawing);const a=ye._svgFactory.createElement("defs");r.append(a);const h=ye._svgFactory.createElement("path");a.append(h);const l=`path_p${this.pageIndex}_${n}`;h.setAttribute("id",l),h.setAttribute("d",t.toSVGPath()),i&&c(this,xn).set(n,h);const u=y(this,Pa,Ay).call(this,a,l),d=ye._svgFactory.createElement("use");return r.append(d),r.setAttribute("fill",e),r.setAttribute("fill-opacity",s),d.setAttribute("href",`#${l}`),c(this,Zt).set(n,r),{id:n,clipPathId:`url(#${u})`}}drawOutline(t){const e=Ge(this,sc)._++,s=y(this,Pa,kp).call(this,t.box);s.classList.add(...t.classNamesForOutlining);const i=ye._svgFactory.createElement("defs");s.append(i);const n=ye._svgFactory.createElement("path");i.append(n);const r=`path_p${this.pageIndex}_${e}`;n.setAttribute("id",r),n.setAttribute("d",t.toSVGPath()),n.setAttribute("vector-effect","non-scaling-stroke");let a;if(t.mustRemoveSelfIntersections){const u=ye._svgFactory.createElement("mask");i.append(u),a=`mask_p${this.pageIndex}_${e}`,u.setAttribute("id",a),u.setAttribute("maskUnits","objectBoundingBox");const d=ye._svgFactory.createElement("rect");u.append(d),d.setAttribute("width","1"),d.setAttribute("height","1"),d.setAttribute("fill","white");const g=ye._svgFactory.createElement("use");u.append(g),g.setAttribute("href",`#${r}`),g.setAttribute("stroke","none"),g.setAttribute("fill","black"),g.setAttribute("fill-rule","nonzero"),g.classList.add("mask")}const h=ye._svgFactory.createElement("use");s.append(h),h.setAttribute("href",`#${r}`),a&&h.setAttribute("mask",`url(#${a})`);const l=h.cloneNode();return s.append(l),h.classList.add("mainOutline"),l.classList.add("secondaryOutline"),c(this,Zt).set(e,s),e}finalizeLine(t,e){const s=c(this,xn).get(t);c(this,xn).delete(t),this.updateBox(t,e.box),s.setAttribute("d",e.toSVGPath())}updateLine(t,e){c(this,Zt).get(t).firstChild.firstChild.setAttribute("d",e.toSVGPath())}updatePath(t,e){c(this,xn).get(t).setAttribute("d",e.toSVGPath())}updateBox(t,e){var s;y(s=ye,ic,Ep).call(s,c(this,Zt).get(t),e)}show(t,e){c(this,Zt).get(t).classList.toggle("hidden",!e)}rotate(t,e){c(this,Zt).get(t).setAttribute("data-main-rotation",e)}changeColor(t,e){c(this,Zt).get(t).setAttribute("fill",e)}changeOpacity(t,e){c(this,Zt).get(t).setAttribute("fill-opacity",e)}addClass(t,e){c(this,Zt).get(t).classList.add(e)}removeClass(t,e){c(this,Zt).get(t).classList.remove(e)}getSVGRoot(t){return c(this,Zt).get(t)}remove(t){c(this,xn).delete(t),c(this,Oi)!==null&&(c(this,Zt).get(t).remove(),c(this,Zt).delete(t))}destroy(){v(this,Oi,null);for(const t of c(this,Zt).values())t.remove();c(this,Zt).clear(),c(this,xn).clear()}};Oi=new WeakMap,sc=new WeakMap,Zt=new WeakMap,xn=new WeakMap,ic=new WeakSet,Ep=function(t,{x:e=0,y:s=0,width:i=1,height:n=1}={}){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`},Pa=new WeakSet,kp=function(t){var s;const e=ye._svgFactory.create(1,1,!0);return c(this,Oi).append(e),e.setAttribute("aria-hidden",!0),y(s=ye,ic,Ep).call(s,e,t),e},Ay=function(t,e){const s=ye._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=ye._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i},w(ye,ic);let wf=ye;et.AbortException,et.AnnotationEditorLayer,et.AnnotationEditorParamsType,et.AnnotationEditorType,et.AnnotationEditorUIManager,et.AnnotationLayer,et.AnnotationMode,et.ColorPicker,et.DOMSVGFactory,et.DrawLayer,et.FeatureTest;var yC=et.GlobalWorkerOptions;et.ImageKind,et.InvalidPDFException,et.MissingPDFException,et.OPS,et.OutputScale,et.PDFDataRangeTransport,et.PDFDateString,et.PDFWorker,et.PasswordResponses,et.PermissionFlag,et.PixelsPerInch,et.RenderingCancelledException,et.TextLayer,et.UnexpectedResponseException,et.Util,et.VerbosityLevel,et.XfaLayer,et.build,et.createValidAbsoluteUrl,et.fetchData;var _C=et.getDocument;et.getFilenameFromUrl,et.getPdfFilenameFromUrl,et.getXfaPageViewport,et.isDataScheme,et.isPdfFile,et.noContextMenu,et.normalizeUnicode,et.setLayerDimensions,et.shadow,et.version;const wC={fabric:"^6.5.0","pdfjs-dist":"^4.8.69"};function xC(o){return new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>t(s.result)),s.addEventListener("error",e),s.readAsDataURL(o)})}const SC=wC["pdfjs-dist"].replace("^","");yC.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${SC}/pdf.worker.min.mjs`;async function CC(o){const t="data:application/pdf;base64,",e=await xC(o);if(typeof e=="string")return window.atob(e.slice(t.length))}function AC(o,t){return _C({data:o,password:t}).promise}const TC={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},EC={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},kC={stroke:"#000",hoverStroke:"#B7EC5D",src:""};function Fv(o=""){const t=K.useRef(0),e=K.useRef(null),s=K.useRef(null),i=K.useRef(1),n=K.useRef({...kC});function r(){if(!o||_s.has(o))return;const M=hx(o);return M.on("selection:cleared",()=>A(M)),M}function a(M,O){var j;const R=M.type,I={"application/pdf":h,"image/png":d,"image/jpeg":d};return((j=I[R])==null?void 0:j.call(I,M,O))??Promise.reject(new Error(`Unsupported ${R} file type.`))}async function h(M,O){const R=await CC(M);if(!R)return;const I=lx(M,R);try{return await l({page:1,PDFBase64:R,scale:.8,password:O}),{...I,pages:t.current}}catch(j){return Promise.reject(j)}}async function l({page:M,PDFBase64:O,scale:R,password:I}){try{const j=await AC(O,I),G=await j.getPage(M),{renderTask:L,canvas:H}=cx(G,R);return t.current=j.numPages,L.promise.then(()=>u(H))}catch(j){return Promise.reject(j)}}function u(M){dx(o,M)}async function d(M){return await gx(o,M)}async function g({url:M,scale:O=.5}){await N0(o,{url:M,scale:O})}async function f(M,O){const R=_s.get(o);if(!R)return;const I=await Ce.fromURL(M,{},{...TC,...O});R.add(I),m(R,I)}function p(M,O){const R=_s.get(o);if(!R)return;const I=new Se(M,{...EC,...O});R.add(I),m(R,I)}function m(M,O){O.on("selected",R=>_({canvas:M,target:R.target})),O.on("modified",R=>Mh(R.target,e.current)),O.on("scaling",R=>Mh(R.transform.target,e.current)),O.on("moving",R=>Mh(R.transform.target,e.current)),O.on("rotating",R=>Mh(R.transform.target,e.current))}async function _({canvas:M,target:O,stroke:R=n.current.stroke,uuid:I=Date.now()}){var G;if(((G=e.current)==null?void 0:G.stroke)===`${R}-${I}`)return;const j=await ux(n.current.src,R,I);A(M),e.current=j,s.current=O,b(M,O,I),x(i.current,!0),M.add(j)}function b(M,O,R){e.current&&(e.current.on("selected",()=>{M.remove(O),A(M)}),e.current.on("mouseover",()=>{_({canvas:M,target:O,stroke:n.current.hoverStroke,uuid:R})}),e.current.on("mouseout",()=>{_({canvas:M,target:O,stroke:n.current.stroke,uuid:R})}))}function x(M,O=!1){const R=_s.get(o);i.current=M,R&&(px(s.current,M,n.current),fx(s.current,M,e.current),!O&&R.renderAll())}function S(M){if(!M)return;n.current={...n.current,...M};const O=_s.get(o);!e||!s.current||!O||_({target:s.current,canvas:O})}function A(M){e.current&&(M.remove(e.current),e.current=s.current=null)}function k(){mx(o)}function P(){vx(o)}return{createCanvas:r,loadFile:a,specifyPage:l,renderImage:g,addFabric:f,addTextFabric:p,clearActive:k,deleteCanvas:P,scaleFabric:x,setCloseSvgOptions:S}}function MC(o){let t=0;const e=ox(()=>{t!==window.innerWidth&&(t=window.innerWidth,o())});K.useEffect(()=>(window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)),[])}const OC=K.forwardRef(PC);function PC({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:l,dropImageOptions:u,closeSvgOptions:d},g){const f=K.useRef(null),p=`${e}-${t-1}`,m=K.useMemo(()=>s*n,[s,n]),{createCanvas:_,specifyPage:b,addFabric:x,addTextFabric:S,renderImage:A,clearActive:k,deleteCanvas:P,scaleFabric:M,setCloseSvgOptions:O}=Fv(p);MC(R);async function R(){window.requestAnimationFrame(async()=>{if(_(),o.PDFBase64.startsWith("data:image")||o.canvas){const{canvas:L}=o,H=L?7:3,$=L!=null&&L.length?L[t-1]:o.PDFBase64;A({url:$,scale:i/H});return}await b({page:t,PDFBase64:o.PDFBase64,scale:i,password:h})})}function I(L){if(L.preventDefault(),L.stopPropagation(),!a||!L.dataTransfer)return;const{dataTransfer:H,clientX:$,clientY:J}=L,Y=H.getData("text"),X=H.getData("image"),Ot={left:$-71,top:J-55};X&&j(X,Ot),Y&&G(Y,Ot)}function j(L,H){x(L,{...H,...u})}function G(L,H){S(L,{...H,...l})}return K.useImperativeHandle(g,()=>({addImage:j,addText:G,clearActive:k,deleteCanvas:P,canvasRef:f})),K.useEffect(()=>{R()},[i,t,o,h]),K.useEffect(()=>{M(m)},[m]),K.useEffect(()=>{O(d)},[d]),K.useEffect(()=>()=>P(),[]),Pp.jsx("div",{style:{transform:`scale(${m})`},onDragOver:L=>L.preventDefault(),onDragEnter:L=>L.preventDefault(),onDrop:I,children:Pp.jsx("canvas",{id:p,ref:f,className:r})})}const Hu=Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"}));ct.default=OC,ct.useFabric=Fv,Object.defineProperties(ct,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
534
|
+
`)}`),_(this,se,Gd).call(this);const g=new Range;let f=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(f<=x){g.setStart(b,f),g.setEnd(b,f);break}f-=x}r.removeAllRanges(),r.addRange(g)}get contentDiv(){return this.editorDiv}static async deserialize(e,s,i){var o;let n=null;if(e instanceof Bv){const{data:{defaultAppearanceData:{fontSize:h,fontColor:c},rect:u,rotation:d,id:g,popupRef:f},textContent:p,textPosition:m,parent:{page:{pageNumber:y}}}=e;if(!p||p.length===0)return null;n=e={annotationType:nt.FREETEXT,color:Array.from(c),fontSize:h,value:p.join(`
|
|
535
|
+
`),position:m,pageIndex:y-1,rect:u.slice(0),rotation:d,id:g,deleted:!1,popupRef:f}}const r=await super.deserialize(e,s,i);return v(r,vs,e.fontSize),v(r,hi,$.makeHexColor(...e.color)),v(r,ms,_(o=Mt,Cn,Ap).call(o,e.value)),r.annotationElementId=e.id||null,r._initialData=n,r}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const s=Mt._internalPadding*this.parentScale,i=this.getRect(s,s),n=Bt._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:l(this,hi)),r={annotationType:nt.FREETEXT,color:n,fontSize:l(this,vs),value:_(this,se,Kb).call(this),pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?r:this.annotationElementId&&!_(this,se,Qb).call(this,r)?null:(r.id=this.annotationElementId,r)}renderAnnotationElement(e){const s=super.renderAnnotationElement(e);if(this.deleted)return s;const{style:i}=s;i.fontSize=`calc(${l(this,vs)}px * var(--scale-factor))`,i.color=l(this,hi),s.replaceChildren();for(const r of l(this,ms).split(`
|
|
536
|
+
`)){const o=document.createElement("div");o.append(r?document.createTextNode(r):document.createElement("br")),s.append(o)}const n=Mt._internalPadding*this.parentScale;return e.updateEdited({rect:this.getRect(n,n),popupContent:l(this,ms)}),s}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}};hi=new WeakMap,ms=new WeakMap,Zl=new WeakMap,Eo=new WeakMap,vs=new WeakMap,se=new WeakSet,Yb=function(e){const s=n=>{this.editorDiv.style.fontSize=`calc(${n}px * var(--scale-factor))`,this.translate(0,-(n-l(this,vs))*this.parentScale),v(this,vs,n),_(this,se,Hd).call(this)},i=l(this,vs);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ut.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})},$b=function(e){const s=n=>{v(this,hi,this.editorDiv.style.color=n)},i=l(this,hi);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ut.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})},qb=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(_(i=Mt,Cn,Vd).call(i,n)),s=n);return e.join(`
|
|
537
|
+
`)},Hd=function(){const[e,s]=this.parentDimensions;let i;if(this.isAttachedToDOM)i=this.div.getBoundingClientRect();else{const{currentLayer:n,div:r}=this,o=r.style.display,h=r.classList.contains("hidden");r.classList.remove("hidden"),r.style.display="hidden",n.div.append(this.div),i=r.getBoundingClientRect(),r.remove(),r.style.display=o,r.classList.toggle("hidden",h)}this.rotation%180===this.parentRotation%180?(this.width=i.width/e,this.height=i.height/s):(this.width=i.height/e,this.height=i.width/s),this.fixAndSetPosition()},Cn=new WeakSet,Vd=function(e){return(e.nodeType===Node.TEXT_NODE?e.nodeValue:e.innerText).replaceAll(Zu,"")},Gd=function(){if(this.editorDiv.replaceChildren(),!!l(this,ms))for(const e of l(this,ms).split(`
|
|
538
|
+
`)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},Kb=function(){return l(this,ms).replaceAll(" "," ")},Ap=function(e){return e.replaceAll(" "," ")},Qb=function(e){const{value:s,fontSize:i,color:n,pageIndex:r}=this._initialData;return this._hasBeenMoved||e.value!==s||e.fontSize!==i||e.color.some((o,h)=>o!==n[h])||e.pageIndex!==r},w(Mt,Cn),q(Mt,"_freeTextDefaultContent",""),q(Mt,"_internalPadding",0),q(Mt,"_defaultColor",null),q(Mt,"_defaultFontSize",10),q(Mt,"_type","freetext"),q(Mt,"_editorType",nt.FREETEXT);let kf=Mt;class U{toSVGPath(){St("Abstract method `toSVGPath` must be implemented.")}get box(){St("Abstract getter `box` must be implemented.")}serialize(t,e){St("Abstract method `serialize` must be implemented.")}static _rescale(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o]*i,r[o+1]=s+t[o+1]*n;return r}static _rescaleAndSwap(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o+1]*i,r[o+1]=s+t[o]*n;return r}static _translate(t,e,s,i){i||(i=new Float32Array(t.length));for(let n=0,r=t.length;n<r;n+=2)i[n]=e+t[n],i[n+1]=s+t[n+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,s,i,n){switch(n){case 90:return[1-e/s,t/i];case 180:return[1-t/s,1-e/i];case 270:return[e/s,1-t/i];default:return[t/s,e/i]}}static _normalizePagePoint(t,e,s){switch(s){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}}q(U,"PRECISION",1e-4);const An=class An{constructor({x:t,y:e},s,i,n,r,o=0){w(this,le);w(this,bs);w(this,li,[]);w(this,Xa);w(this,Ua);w(this,Fi,[]);w(this,ot,new Float32Array(18));w(this,ko);w(this,Mo);w(this,tc);w(this,ec);w(this,Ya);w(this,$a);w(this,fr,[]);v(this,bs,s),v(this,$a,n*i),v(this,Ua,r),l(this,ot).set([NaN,NaN,NaN,NaN,t,e],6),v(this,Xa,o),v(this,ec,l(An,sc)*i),v(this,tc,l(An,yd)*i),v(this,Ya,i),l(this,fr).push(t,e)}isEmpty(){return isNaN(l(this,ot)[8])}add({x:t,y:e}){var R;v(this,ko,t),v(this,Mo,e);const[s,i,n,r]=l(this,bs);let[o,h,c,u]=l(this,ot).subarray(8,12);const d=t-c,g=e-u,f=Math.hypot(d,g);if(f<l(this,tc))return!1;const p=f-l(this,ec),m=p/f,y=m*d,b=m*g;let x=o,C=h;o=c,h=u,c+=y,u+=b,(R=l(this,fr))==null||R.push(t,e);const A=-b/p,M=y/p,D=A*l(this,$a),k=M*l(this,$a);return l(this,ot).set(l(this,ot).subarray(2,8),0),l(this,ot).set([c+D,u+k],4),l(this,ot).set(l(this,ot).subarray(14,18),12),l(this,ot).set([c-D,u-k],16),isNaN(l(this,ot)[6])?(l(this,Fi).length===0&&(l(this,ot).set([o+D,h+k],2),l(this,Fi).push(NaN,NaN,NaN,NaN,(o+D-s)/n,(h+k-i)/r),l(this,ot).set([o-D,h-k],14),l(this,li).push(NaN,NaN,NaN,NaN,(o-D-s)/n,(h-k-i)/r)),l(this,ot).set([x,C,o,h,c,u],6),!this.isEmpty()):(l(this,ot).set([x,C,o,h,c,u],6),Math.abs(Math.atan2(C-h,x-o)-Math.atan2(b,y))<Math.PI/2?([o,h,c,u]=l(this,ot).subarray(2,6),l(this,Fi).push(NaN,NaN,NaN,NaN,((o+c)/2-s)/n,((h+u)/2-i)/r),[o,h,x,C]=l(this,ot).subarray(14,18),l(this,li).push(NaN,NaN,NaN,NaN,((x+o)/2-s)/n,((C+h)/2-i)/r),!0):([x,C,o,h,c,u]=l(this,ot).subarray(0,6),l(this,Fi).push(((x+5*o)/6-s)/n,((C+5*h)/6-i)/r,((5*o+c)/6-s)/n,((5*h+u)/6-i)/r,((o+c)/2-s)/n,((h+u)/2-i)/r),[c,u,o,h,x,C]=l(this,ot).subarray(12,18),l(this,li).push(((x+5*o)/6-s)/n,((C+5*h)/6-i)/r,((5*o+c)/6-s)/n,((5*h+u)/6-i)/r,((o+c)/2-s)/n,((h+u)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=l(this,Fi),e=l(this,li);if(isNaN(l(this,ot)[6])&&!this.isEmpty())return _(this,le,Jb).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]}`);_(this,le,ty).call(this,s);for(let i=e.length-6;i>=6;i-=6)isNaN(e[i])?s.push(`L${e[i+4]} ${e[i+5]}`):s.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return _(this,le,Zb).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new Wv(t,e,s,i,n,r)}getOutlines(){var d;const t=l(this,Fi),e=l(this,li),s=l(this,ot),[i,n,r,o]=l(this,bs),h=new Float32Array((((d=l(this,fr))==null?void 0:d.length)??0)+2);for(let g=0,f=h.length-2;g<f;g+=2)h[g]=(l(this,fr)[g]-i)/r,h[g+1]=(l(this,fr)[g+1]-n)/o;if(h[h.length-2]=(l(this,ko)-i)/r,h[h.length-1]=(l(this,Mo)-n)/o,isNaN(s[6])&&!this.isEmpty())return _(this,le,ey).call(this,h);const c=new Float32Array(l(this,Fi).length+24+l(this,li).length);let u=t.length;for(let g=0;g<u;g+=2){if(isNaN(t[g])){c[g]=c[g+1]=NaN;continue}c[g]=t[g],c[g+1]=t[g+1]}u=_(this,le,iy).call(this,c,u);for(let g=e.length-6;g>=6;g-=6)for(let f=0;f<6;f+=2){if(isNaN(e[g+f])){c[u]=c[u+1]=NaN,u+=2;continue}c[u]=e[g+f],c[u+1]=e[g+f+1],u+=2}return _(this,le,sy).call(this,c,u),this.newFreeDrawOutline(c,h,l(this,bs),l(this,Ya),l(this,Xa),l(this,Ua))}};bs=new WeakMap,li=new WeakMap,Xa=new WeakMap,Ua=new WeakMap,Fi=new WeakMap,ot=new WeakMap,ko=new WeakMap,Mo=new WeakMap,tc=new WeakMap,ec=new WeakMap,Ya=new WeakMap,$a=new WeakMap,fr=new WeakMap,sc=new WeakMap,bd=new WeakMap,yd=new WeakMap,le=new WeakSet,Pc=function(){const t=l(this,ot).subarray(4,6),e=l(this,ot).subarray(16,18),[s,i,n,r]=l(this,bs);return[(l(this,ko)+(t[0]-e[0])/2-s)/n,(l(this,Mo)+(t[1]-e[1])/2-i)/r,(l(this,ko)+(e[0]-t[0])/2-s)/n,(l(this,Mo)+(e[1]-t[1])/2-i)/r]},Jb=function(){const[t,e,s,i]=l(this,bs),[n,r,o,h]=_(this,le,Pc).call(this);return`M${(l(this,ot)[2]-t)/s} ${(l(this,ot)[3]-e)/i} L${(l(this,ot)[4]-t)/s} ${(l(this,ot)[5]-e)/i} L${n} ${r} L${o} ${h} L${(l(this,ot)[16]-t)/s} ${(l(this,ot)[17]-e)/i} L${(l(this,ot)[14]-t)/s} ${(l(this,ot)[15]-e)/i} Z`},Zb=function(t){const e=l(this,li);t.push(`L${e[4]} ${e[5]} Z`)},ty=function(t){const[e,s,i,n]=l(this,bs),r=l(this,ot).subarray(4,6),o=l(this,ot).subarray(16,18),[h,c,u,d]=_(this,le,Pc).call(this);t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${h} ${c} L${u} ${d} L${(o[0]-e)/i} ${(o[1]-s)/n}`)},ey=function(t){const e=l(this,ot),[s,i,n,r]=l(this,bs),[o,h,c,u]=_(this,le,Pc).call(this),d=new Float32Array(36);return d.set([NaN,NaN,NaN,NaN,(e[2]-s)/n,(e[3]-i)/r,NaN,NaN,NaN,NaN,(e[4]-s)/n,(e[5]-i)/r,NaN,NaN,NaN,NaN,o,h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,(e[16]-s)/n,(e[17]-i)/r,NaN,NaN,NaN,NaN,(e[14]-s)/n,(e[15]-i)/r],0),this.newFreeDrawOutline(d,t,l(this,bs),l(this,Ya),l(this,Xa),l(this,Ua))},sy=function(t,e){const s=l(this,li);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},iy=function(t,e){const s=l(this,ot).subarray(4,6),i=l(this,ot).subarray(16,18),[n,r,o,h]=l(this,bs),[c,u,d,g]=_(this,le,Pc).call(this);return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/o,(s[1]-r)/h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,d,g,NaN,NaN,NaN,NaN,(i[0]-n)/o,(i[1]-r)/h],e),e+=24},w(An,sc,8),w(An,bd,2),w(An,yd,l(An,sc)+l(An,bd));let td=An;class Wv extends U{constructor(e,s,i,n,r,o){super();w(this,_d);w(this,qa);w(this,Po,new Float32Array(4));w(this,Tn);w(this,ic);w(this,ys);w(this,nc);w(this,Kt);v(this,Kt,e),v(this,ys,s),v(this,qa,i),v(this,nc,n),v(this,Tn,r),v(this,ic,o),this.lastPoint=[NaN,NaN],_(this,_d,ny).call(this,o);const[h,c,u,d]=l(this,Po);for(let g=0,f=e.length;g<f;g+=2)e[g]=(e[g]-h)/u,e[g+1]=(e[g+1]-c)/d;for(let g=0,f=s.length;g<f;g+=2)s[g]=(s[g]-h)/u,s[g+1]=(s[g+1]-c)/d}toSVGPath(){const e=[`M${l(this,Kt)[4]} ${l(this,Kt)[5]}`];for(let s=6,i=l(this,Kt).length;s<i;s+=6){if(isNaN(l(this,Kt)[s])){e.push(`L${l(this,Kt)[s+4]} ${l(this,Kt)[s+5]}`);continue}e.push(`C${l(this,Kt)[s]} ${l(this,Kt)[s+1]} ${l(this,Kt)[s+2]} ${l(this,Kt)[s+3]} ${l(this,Kt)[s+4]} ${l(this,Kt)[s+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,s,i,n],r){const o=i-e,h=n-s;let c,u;switch(r){case 0:c=U._rescale(l(this,Kt),e,n,o,-h),u=U._rescale(l(this,ys),e,n,o,-h);break;case 90:c=U._rescaleAndSwap(l(this,Kt),e,s,o,h),u=U._rescaleAndSwap(l(this,ys),e,s,o,h);break;case 180:c=U._rescale(l(this,Kt),i,s,-o,h),u=U._rescale(l(this,ys),i,s,-o,h);break;case 270:c=U._rescaleAndSwap(l(this,Kt),i,n,-o,-h),u=U._rescaleAndSwap(l(this,ys),i,n,-o,-h);break}return{outline:Array.from(c),points:[Array.from(u)]}}get box(){return l(this,Po)}newOutliner(e,s,i,n,r,o=0){return new td(e,s,i,n,r,o)}getNewOutline(e,s){const[i,n,r,o]=l(this,Po),[h,c,u,d]=l(this,qa),g=r*u,f=o*d,p=i*u+h,m=n*d+c,y=this.newOutliner({x:l(this,ys)[0]*g+p,y:l(this,ys)[1]*f+m},l(this,qa),l(this,nc),e,l(this,ic),s??l(this,Tn));for(let b=2;b<l(this,ys).length;b+=2)y.add({x:l(this,ys)[b]*g+p,y:l(this,ys)[b+1]*f+m});return y.getOutlines()}}qa=new WeakMap,Po=new WeakMap,Tn=new WeakMap,ic=new WeakMap,ys=new WeakMap,nc=new WeakMap,Kt=new WeakMap,_d=new WeakSet,ny=function(e){const s=l(this,Kt);let i=s[4],n=s[5],r=i,o=n,h=i,c=n,u=i,d=n;const g=e?Math.max:Math.min;for(let p=6,m=s.length;p<m;p+=6){if(isNaN(s[p]))r=Math.min(r,s[p+4]),o=Math.min(o,s[p+5]),h=Math.max(h,s[p+4]),c=Math.max(c,s[p+5]),d<s[p+5]?(u=s[p+4],d=s[p+5]):d===s[p+5]&&(u=g(u,s[p+4]));else{const y=$.bezierBoundingBox(i,n,...s.slice(p,p+6));r=Math.min(r,y[0]),o=Math.min(o,y[1]),h=Math.max(h,y[2]),c=Math.max(c,y[3]),d<y[3]?(u=y[2],d=y[3]):d===y[3]&&(u=g(u,y[2]))}i=s[p+4],n=s[p+5]}const f=l(this,Po);f[0]=r-l(this,Tn),f[1]=o-l(this,Tn),f[2]=h-r+2*l(this,Tn),f[3]=c-o+2*l(this,Tn),this.lastPoint=[u,d]};class Mf{constructor(t,e=0,s=0,i=!0){w(this,Xe);w(this,rc);w(this,oc);w(this,pr,[]);w(this,ci,[]);let n=1/0,r=-1/0,o=1/0,h=-1/0;const u=10**-4;for(const{x:b,y:x,width:C,height:A}of t){const M=Math.floor((b-e)/u)*u,D=Math.ceil((b+C+e)/u)*u,k=Math.floor((x-e)/u)*u,P=Math.ceil((x+A+e)/u)*u,R=[M,k,P,!0],F=[D,k,P,!1];l(this,pr).push(R,F),n=Math.min(n,M),r=Math.max(r,D),o=Math.min(o,k),h=Math.max(h,P)}const d=r-n+2*s,g=h-o+2*s,f=n-s,p=o-s,m=l(this,pr).at(i?-1:-2),y=[m[0],m[2]];for(const b of l(this,pr)){const[x,C,A]=b;b[0]=(x-f)/d,b[1]=(C-p)/g,b[2]=(A-p)/g}v(this,rc,new Float32Array([f,p,d,g])),v(this,oc,y)}getOutlines(){l(this,pr).sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of l(this,pr))e[3]?(t.push(..._(this,Xe,Tp).call(this,e)),_(this,Xe,oy).call(this,e)):(_(this,Xe,ay).call(this,e),t.push(..._(this,Xe,Tp).call(this,e)));return _(this,Xe,ry).call(this,t)}}rc=new WeakMap,oc=new WeakMap,pr=new WeakMap,ci=new WeakMap,Xe=new WeakSet,ry=function(t){const e=[],s=new Set;for(const r of t){const[o,h,c]=r;e.push([o,h,r],[o,c,r])}e.sort((r,o)=>r[1]-o[1]||r[0]-o[0]);for(let r=0,o=e.length;r<o;r+=2){const h=e[r][2],c=e[r+1][2];h.push(c),c.push(h),s.add(h),s.add(c)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[o,h,c,u,d]=r;s.delete(r);let g=o,f=h;for(n=[o,c],i.push(n);;){let p;if(s.has(u))p=u;else if(s.has(d))p=d;else break;s.delete(p),[o,h,c,u,d]=p,g!==o&&(n.push(g,f,o,f===h?h:c),g=o),f=f===h?c:h}n.push(g,f)}return new mC(i,l(this,rc),l(this,oc))},Wd=function(t){const e=l(this,ci);let s=0,i=e.length-1;for(;s<=i;){const n=s+i>>1,r=e[n][0];if(r===t)return n;r<t?s=n+1:i=n-1}return i+1},oy=function([,t,e]){const s=_(this,Xe,Wd).call(this,t);l(this,ci).splice(s,0,[t,e])},ay=function([,t,e]){const s=_(this,Xe,Wd).call(this,t);for(let i=s;i<l(this,ci).length;i++){const[n,r]=l(this,ci)[i];if(n!==t)break;if(n===t&&r===e){l(this,ci).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=l(this,ci)[i];if(n!==t)break;if(n===t&&r===e){l(this,ci).splice(i,1);return}}},Tp=function(t){const[e,s,i]=t,n=[[e,s,i]],r=_(this,Xe,Wd).call(this,i);for(let o=0;o<r;o++){const[h,c]=l(this,ci)[o];for(let u=0,d=n.length;u<d;u++){const[,g,f]=n[u];if(!(c<=g||f<=h)){if(g>=h){if(f>c)n[u][1]=c;else{if(d===1)return[];n.splice(u,1),u--,d--}continue}n[u][2]=h,f>c&&n.push([e,c,f])}}}return n};class mC extends U{constructor(e,s,i){super();w(this,ac);w(this,Ka);v(this,Ka,e),v(this,ac,s),this.lastPoint=i}toSVGPath(){const e=[];for(const s of l(this,Ka)){let[i,n]=s;e.push(`M${i} ${n}`);for(let r=2;r<s.length;r+=2){const o=s[r],h=s[r+1];o===i?(e.push(`V${h}`),n=h):h===n&&(e.push(`H${o}`),i=o)}e.push("Z")}return e.join(" ")}serialize([e,s,i,n],r){const o=[],h=i-e,c=n-s;for(const u of l(this,Ka)){const d=new Array(u.length);for(let g=0;g<u.length;g+=2)d[g]=e+u[g]*h,d[g+1]=n-u[g+1]*c;o.push(d)}return o}get box(){return l(this,ac)}get classNamesForOutlining(){return["highlightOutline"]}}ac=new WeakMap,Ka=new WeakMap;class Pf extends td{newFreeDrawOutline(t,e,s,i,n,r){return new vC(t,e,s,i,n,r)}}class vC extends Wv{newOutliner(t,e,s,i,n,r=0){return new Pf(t,e,s,i,n,r)}}const ns=class ns{constructor({editor:t=null,uiManager:e=null}){w(this,At);w(this,ui,null);w(this,Oo,null);w(this,Qa);w(this,ce,null);w(this,hc,!1);w(this,Ja,!1);w(this,lc,null);w(this,cc);w(this,mr,null);w(this,di,null);w(this,Za);var s;t?(v(this,Ja,!1),v(this,Za,ut.HIGHLIGHT_COLOR),v(this,lc,t)):(v(this,Ja,!0),v(this,Za,ut.HIGHLIGHT_DEFAULT_COLOR)),v(this,di,(t==null?void 0:t._uiManager)||e),v(this,cc,l(this,di)._eventBus),v(this,Qa,(t==null?void 0:t.color)||((s=l(this,di))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),l(ns,uc)||v(ns,uc,Object.freeze({blue:"pdfjs-editor-colorpicker-blue",green:"pdfjs-editor-colorpicker-green",pink:"pdfjs-editor-colorpicker-pink",red:"pdfjs-editor-colorpicker-red",yellow:"pdfjs-editor-colorpicker-yellow"}))}static get _keyboardManager(){return at(this,"_keyboardManager",new $h([[["Escape","mac+Escape"],ns.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],ns.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],ns.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],ns.prototype._moveToPrevious],[["Home","mac+Home"],ns.prototype._moveToBeginning],[["End","mac+End"],ns.prototype._moveToEnd]]))}renderButton(){const t=v(this,ui,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,di)._signal;t.addEventListener("click",_(this,At,Wo).bind(this),{signal:e}),t.addEventListener("keydown",_(this,At,Mp).bind(this),{signal:e});const s=v(this,Oo,document.createElement("span"));return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=l(this,Qa),t.append(s),t}renderMainDropdown(){const t=v(this,ce,_(this,At,Ep).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===l(this,ui)){_(this,At,Wo).call(this,t);return}const e=t.target.getAttribute("data-color");e&&_(this,At,kp).call(this,e,t)}_moveToNext(t){var e,s;if(!l(this,At,xr)){_(this,At,Wo).call(this,t);return}if(t.target===l(this,ui)){(e=l(this,ce).firstChild)==null||e.focus();return}(s=t.target.nextSibling)==null||s.focus()}_moveToPrevious(t){var e,s;if(t.target===((e=l(this,ce))==null?void 0:e.firstChild)||t.target===l(this,ui)){l(this,At,xr)&&this._hideDropdownFromKeyboard();return}l(this,At,xr)||_(this,At,Wo).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!l(this,At,xr)){_(this,At,Wo).call(this,t);return}(e=l(this,ce).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!l(this,At,xr)){_(this,At,Wo).call(this,t);return}(e=l(this,ce).lastChild)==null||e.focus()}hideDropdown(){var t,e;(t=l(this,ce))==null||t.classList.add("hidden"),(e=l(this,mr))==null||e.abort(),v(this,mr,null)}_hideDropdownFromKeyboard(){var t;if(!l(this,Ja)){if(!l(this,At,xr)){(t=l(this,lc))==null||t.unselect();return}this.hideDropdown(),l(this,ui).focus({preventScroll:!0,focusVisible:l(this,hc)})}}updateColor(t){if(l(this,Oo)&&(l(this,Oo).style.backgroundColor=t),!l(this,ce))return;const e=l(this,di).highlightColors.values();for(const s of l(this,ce).children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){var t,e;(t=l(this,ui))==null||t.remove(),v(this,ui,null),v(this,Oo,null),(e=l(this,ce))==null||e.remove(),v(this,ce,null)}};ui=new WeakMap,Oo=new WeakMap,Qa=new WeakMap,ce=new WeakMap,hc=new WeakMap,Ja=new WeakMap,lc=new WeakMap,cc=new WeakMap,mr=new WeakMap,di=new WeakMap,Za=new WeakMap,uc=new WeakMap,At=new WeakSet,Ep=function(){const t=document.createElement("div"),e=l(this,di)._signal;t.addEventListener("contextmenu",Zs,{signal:e}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[s,i]of l(this,di).highlightColors){const n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",l(ns,uc)[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===l(this,Qa)),n.addEventListener("click",_(this,At,kp).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",_(this,At,Mp).bind(this),{signal:e}),t},kp=function(t,e){e.stopPropagation(),l(this,cc).dispatch("switchannotationeditorparams",{source:this,type:l(this,Za),value:t})},Mp=function(t){ns._keyboardManager.exec(this,t)},Wo=function(t){if(l(this,At,xr)){this.hideDropdown();return}if(v(this,hc,t.detail===0),l(this,mr)||(v(this,mr,new AbortController),window.addEventListener("pointerdown",_(this,At,hy).bind(this),{signal:l(this,di).combinedSignal(l(this,mr))})),l(this,ce)){l(this,ce).classList.remove("hidden");return}const e=v(this,ce,_(this,At,Ep).call(this));l(this,ui).append(e)},hy=function(t){var e;(e=l(this,ce))!=null&&e.contains(t.target)||this.hideDropdown()},xr=function(){return l(this,ce)&&!l(this,ce).classList.contains("hidden")},w(ns,uc,null);let ed=ns;const mt=class mt extends Bt{constructor(e){super({...e,name:"highlightEditor"});w(this,st);w(this,th,null);w(this,dc,0);w(this,En);w(this,Do,null);w(this,eh,null);w(this,rs,null);w(this,gc,null);w(this,fc,0);w(this,Ro,null);w(this,Fs,null);w(this,_s,null);w(this,be,!1);w(this,sh,null);w(this,kn);w(this,Oe,null);w(this,ih,"");w(this,Is);w(this,pc,"");this.color=e.color||mt._defaultColor,v(this,Is,e.thickness||mt._defaultThickness),v(this,kn,e.opacity||mt._defaultOpacity),v(this,En,e.boxes||null),v(this,pc,e.methodOfCreation||""),v(this,ih,e.text||""),this._isDraggable=!1,e.highlightId>-1?(v(this,be,!0),_(this,st,zd).call(this,e),_(this,st,zo).call(this)):l(this,En)&&(v(this,th,e.anchorNode),v(this,dc,e.anchorOffset),v(this,gc,e.focusNode),v(this,fc,e.focusOffset),_(this,st,Pp).call(this),_(this,st,zo).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=mt.prototype;return at(this,"_keyboardManager",new $h([[["ArrowLeft","mac+ArrowLeft"],e._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],e._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],e._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],e._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:l(this,be)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:l(this,Is),methodOfCreation:l(this,pc)}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get("color").size}}static initialize(e,s){var i;Bt.initialize(e,s),mt._defaultColor||(mt._defaultColor=((i=s.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,s){switch(e){case ut.HIGHLIGHT_DEFAULT_COLOR:mt._defaultColor=s;break;case ut.HIGHLIGHT_THICKNESS:mt._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return l(this,sh)}updateParams(e,s){switch(e){case ut.HIGHLIGHT_COLOR:_(this,st,ly).call(this,s);break;case ut.HIGHLIGHT_THICKNESS:_(this,st,cy).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[ut.HIGHLIGHT_DEFAULT_COLOR,mt._defaultColor],[ut.HIGHLIGHT_THICKNESS,mt._defaultThickness]]}get propertiesToUpdate(){return[[ut.HIGHLIGHT_COLOR,this.color||mt._defaultColor],[ut.HIGHLIGHT_THICKNESS,l(this,Is)||mt._defaultThickness],[ut.HIGHLIGHT_FREE,l(this,be)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(v(this,eh,new ed({editor:this})),e.addColorPicker(l(this,eh))),e):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(_(this,st,Oc).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,_(this,st,Oc).call(this))}onceAdded(){this.annotationElementId||this.parent.addUndoableEditor(this),this.div.focus()}remove(){_(this,st,Op).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(_(this,st,zo).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?_(this,st,Op).call(this):e&&(_(this,st,zo).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),this.show(this._isVisible),s&&this.select()}rotate(e){var n,r,o;const{drawLayer:s}=this.parent;let i;l(this,be)?(e=(e-this.rotation+360)%360,i=_(n=mt,js,xh).call(n,l(this,Fs).box,e)):i=_(r=mt,js,xh).call(r,[this.x,this.y,this.width,this.height],e),s.updateProperties(l(this,_s),{bbox:i,root:{"data-main-rotation":e}}),s.updateProperties(l(this,Oe),{bbox:_(o=mt,js,xh).call(o,l(this,rs).box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();l(this,ih)&&(e.setAttribute("aria-label",l(this,ih)),e.setAttribute("role","mark")),l(this,be)?e.classList.add("free"):this.div.addEventListener("keydown",_(this,st,dy).bind(this),{signal:this._uiManager._signal});const s=v(this,Ro,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=l(this,Do);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),Xu(this,l(this,Ro),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Oe),{rootClass:{hovered:!0}})}pointerleave(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Oe),{rootClass:{hovered:!1}})}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:_(this,st,Xd).call(this,!0);break;case 1:case 3:_(this,st,Xd).call(this,!1);break}}select(){var e;super.select(),l(this,Oe)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Oe),{rootClass:{hovered:!1,selected:!0}}))}unselect(){var e;super.unselect(),l(this,Oe)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Oe),{rootClass:{selected:!1}}),l(this,be)||_(this,st,Xd).call(this,!1))}get _mustFixPosition(){return!l(this,be)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(l(this,_s),{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(l(this,Oe),{rootClass:{hidden:!e}}))}static startHighlighting(e,s,{target:i,x:n,y:r}){const{x:o,y:h,width:c,height:u}=i.getBoundingClientRect(),d=new AbortController,g=e.combinedSignal(d),f=p=>{d.abort(),_(this,js,my).call(this,e,p)};window.addEventListener("blur",f,{signal:g}),window.addEventListener("pointerup",f,{signal:g}),window.addEventListener("pointerdown",ti,{capture:!0,passive:!1,signal:g}),window.addEventListener("contextmenu",Zs,{signal:g}),i.addEventListener("pointermove",_(this,js,py).bind(this,e),{signal:g}),this._freeHighlight=new Pf({x:n,y:r},[o,h,c,u],e.scale,this._defaultThickness/2,s,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static async deserialize(e,s,i){var m,y,b,x;let n=null;if(e instanceof Vv){const{data:{quadPoints:C,rect:A,rotation:M,id:D,color:k,opacity:P,popupRef:R},parent:{page:{pageNumber:F}}}=e;n=e={annotationType:nt.HIGHLIGHT,color:Array.from(k),opacity:P,quadPoints:C,boxes:null,pageIndex:F-1,rect:A.slice(0),rotation:M,id:D,deleted:!1,popupRef:R}}else if(e instanceof Ef){const{data:{inkLists:C,rect:A,rotation:M,id:D,color:k,borderStyle:{rawWidth:P},popupRef:R},parent:{page:{pageNumber:F}}}=e;n=e={annotationType:nt.HIGHLIGHT,color:Array.from(k),thickness:P,inkLists:C,boxes:null,pageIndex:F-1,rect:A.slice(0),rotation:M,id:D,deleted:!1,popupRef:R}}const{color:r,quadPoints:o,inkLists:h,opacity:c}=e,u=await super.deserialize(e,s,i);u.color=$.makeHexColor(...r),v(u,kn,c||1),h&&v(u,Is,e.thickness),u.annotationElementId=e.id||null,u._initialData=n;const[d,g]=u.pageDimensions,[f,p]=u.pageTranslation;if(o){const C=v(u,En,[]);for(let A=0;A<o.length;A+=8)C.push({x:(o[A]-f)/d,y:1-(o[A+1]-p)/g,width:(o[A+2]-o[A])/d,height:(o[A+1]-o[A+5])/g});_(m=u,st,Pp).call(m),_(y=u,st,zo).call(y),u.rotate(u.rotation)}else if(h){v(u,be,!0);const C=h[0],A={x:C[0]-f,y:g-(C[1]-p)},M=new Pf(A,[0,0,d,g],1,l(u,Is)/2,!0,.001);for(let P=0,R=C.length;P<R;P+=2)A.x=C[P]-f,A.y=g-(C[P+1]-p),M.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:M.toSVGPath()}},!0,!0);_(b=u,st,zd).call(b,{highlightOutlines:M.getOutlines(),highlightId:D,clipPathId:k}),_(x=u,st,zo).call(x)}return u}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();const s=this.getRect(0,0),i=Bt._colorManager.convert(this.color),n={annotationType:nt.HIGHLIGHT,color:i,opacity:l(this,kn),thickness:l(this,Is),quadPoints:_(this,st,gy).call(this),outlines:_(this,st,fy).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:_(this,st,Oc).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!_(this,st,vy).call(this,n)?null:(n.id=this.annotationElementId,n)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};th=new WeakMap,dc=new WeakMap,En=new WeakMap,Do=new WeakMap,eh=new WeakMap,rs=new WeakMap,gc=new WeakMap,fc=new WeakMap,Ro=new WeakMap,Fs=new WeakMap,_s=new WeakMap,be=new WeakMap,sh=new WeakMap,kn=new WeakMap,Oe=new WeakMap,ih=new WeakMap,Is=new WeakMap,pc=new WeakMap,st=new WeakSet,Pp=function(){const e=new Mf(l(this,En),.001);v(this,Fs,e.getOutlines()),[this.x,this.y,this.width,this.height]=l(this,Fs).box;const s=new Mf(l(this,En),.0025,.001,this._uiManager.direction==="ltr");v(this,rs,s.getOutlines());const{lastPoint:i}=l(this,rs);v(this,sh,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height])},zd=function({highlightOutlines:e,highlightId:s,clipPathId:i}){var d,g;if(v(this,Fs,e),v(this,rs,e.getNewOutline(l(this,Is)/2+1.5,.0025)),s>=0)v(this,_s,s),v(this,Do,i),this.parent.drawLayer.finalizeDraw(s,{bbox:e.box,path:{d:e.toSVGPath()}}),v(this,Oe,this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:l(this,rs).box,path:{d:l(this,rs).toSVGPath()}},!0));else if(this.parent){const f=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(l(this,_s),{bbox:_(d=mt,js,xh).call(d,l(this,Fs).box,(f-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(l(this,Oe),{bbox:_(g=mt,js,xh).call(g,l(this,rs).box,f),path:{d:l(this,rs).toSVGPath()}})}const[r,o,h,c]=e.box;switch(this.rotation){case 0:this.x=r,this.y=o,this.width=h,this.height=c;break;case 90:{const[f,p]=this.parentDimensions;this.x=o,this.y=1-r,this.width=h*p/f,this.height=c*f/p;break}case 180:this.x=1-r,this.y=1-o,this.width=h,this.height=c;break;case 270:{const[f,p]=this.parentDimensions;this.x=1-o,this.y=r,this.width=h*p/f,this.height=c*f/p;break}}const{lastPoint:u}=l(this,rs);v(this,sh,[(u[0]-r)/h,(u[1]-o)/c])},ly=function(e){const s=(r,o)=>{var h,c;this.color=r,v(this,kn,o),(h=this.parent)==null||h.drawLayer.updateProperties(l(this,_s),{root:{fill:r,"fill-opacity":o}}),(c=l(this,eh))==null||c.updateColor(r)},i=this.color,n=l(this,kn);this.addCommands({cmd:s.bind(this,e,mt._defaultOpacity),undo:s.bind(this,i,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ut.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},cy=function(e){const s=l(this,Is),i=n=>{v(this,Is,n),_(this,st,uy).call(this,n)};this.addCommands({cmd:i.bind(this,e),undo:i.bind(this,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ut.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},uy=function(e){if(!l(this,be))return;_(this,st,zd).call(this,{highlightOutlines:l(this,Fs).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},Op=function(){l(this,_s)===null||!this.parent||(this.parent.drawLayer.remove(l(this,_s)),v(this,_s,null),this.parent.drawLayer.remove(l(this,Oe)),v(this,Oe,null))},zo=function(e=this.parent){l(this,_s)===null&&({id:Ke(this,_s)._,clipPathId:Ke(this,Do)._}=e.drawLayer.draw({bbox:l(this,Fs).box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":l(this,kn)},rootClass:{highlight:!0,free:l(this,be)},path:{d:l(this,Fs).toSVGPath()}},!1,!0),v(this,Oe,e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:l(this,be)},bbox:l(this,rs).box,path:{d:l(this,rs).toSVGPath()}},l(this,be))),l(this,Ro)&&(l(this,Ro).style.clipPath=l(this,Do)))},js=new WeakSet,xh=function([e,s,i,n],r){switch(r){case 90:return[1-s-n,e,n,i];case 180:return[1-e-i,1-s-n,i,n];case 270:return[s,1-e-i,n,i]}return[e,s,i,n]},dy=function(e){mt._keyboardManager.exec(this,e)},Xd=function(e){if(!l(this,th))return;const s=window.getSelection();e?s.setPosition(l(this,th),l(this,dc)):s.setPosition(l(this,gc),l(this,fc))},Oc=function(){return l(this,be)?this.rotation:0},gy=function(){if(l(this,be))return null;const[e,s]=this.pageDimensions,[i,n]=this.pageTranslation,r=l(this,En),o=new Float32Array(r.length*8);let h=0;for(const{x:c,y:u,width:d,height:g}of r){const f=c*e+i,p=(1-u)*s+n;o[h]=o[h+4]=f,o[h+1]=o[h+3]=p,o[h+2]=o[h+6]=f+d*e,o[h+5]=o[h+7]=p-g*s,h+=8}return o},fy=function(e){return l(this,Fs).serialize(e,_(this,st,Oc).call(this))},py=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},my=function(e,s){this._freeHighlight.isEmpty()?e.drawLayer.remove(this._freeHighlightId):e.createAndAddNewEditor(s,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""},vy=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},w(mt,js),q(mt,"_defaultColor",null),q(mt,"_defaultOpacity",1),q(mt,"_defaultThickness",12),q(mt,"_type","highlight"),q(mt,"_editorType",nt.HIGHLIGHT),q(mt,"_freeHighlightId",-1),q(mt,"_freeHighlight",null),q(mt,"_freeHighlightClipId","");let sd=mt;class bC{constructor(){w(this,Lo,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,Lo)[t]=e}toSVGProperties(){const t=l(this,Lo);return v(this,Lo,Object.create(null)),{root:t}}reset(){v(this,Lo,Object.create(null))}updateAll(t=this){this.updateProperties(t)}clone(){St("Not implemented")}}Lo=new WeakMap;const Ns=class Ns extends Bt{constructor(e){super(e);w(this,pt);w(this,ws,null);w(this,nh);q(this,"_drawId",null);v(this,nh,e.mustBeCommitted||!1),e.drawOutlines&&(_(this,pt,Dp).call(this,e),_(this,pt,Dc).call(this))}static _mergeSVGProperties(e,s){const i=new Set(Object.keys(e));for(const[n,r]of Object.entries(s))i.has(n)?Object.assign(e[n],r):e[n]=r;return e}static getDefaultDrawingOptions(e){St("Not implemented")}static get typesMap(){St("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,s){const i=this.typesMap.get(e);i&&this._defaultDrawingOptions.updateProperty(i,s),this._currentParent&&(this._currentDraw.updateProperty(i,s),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,s){const i=this.constructor.typesMap.get(e);i&&this._updateProperty(e,i,s)}static get defaultPropertiesToUpdate(){const e=[],s=this._defaultDrawingOptions;for(const[i,n]of this.typesMap)e.push([i,s[n]]);return e}get propertiesToUpdate(){const e=[],{_drawingOptions:s}=this;for(const[i,n]of this.constructor.typesMap)e.push([i,s[n]]);return e}_updateProperty(e,s,i){const n=this._drawingOptions,r=n[s],o=h=>{var u;n.updateProperty(s,h);const c=l(this,ws).updateProperty(s,h);c&&_(this,pt,Rc).call(this,c),(u=this.parent)==null||u.drawLayer.updateProperties(this._drawId,n.toSVGProperties())};this.addCommands({cmd:o.bind(this,i),undo:o.bind(this,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,Ns._mergeSVGProperties(l(this,ws).getPathResizingSVGProperties(_(this,pt,Ud).call(this)),{bbox:_(this,pt,Sh).call(this)}))}_onResized(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,Ns._mergeSVGProperties(l(this,ws).getPathResizedSVGProperties(_(this,pt,Ud).call(this)),{bbox:_(this,pt,Sh).call(this)}))}_onTranslating(e,s){var i;(i=this.parent)==null||i.drawLayer.updateProperties(this._drawId,{bbox:_(this,pt,Sh).call(this,e,s)})}_onTranslated(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,Ns._mergeSVGProperties(l(this,ws).getPathTranslatedSVGProperties(_(this,pt,Ud).call(this),this.parentDimensions),{bbox:_(this,pt,Sh).call(this)}))}_onStartDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit(),this.disableEditMode(),this.disableEditing()}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,l(this,nh)&&(v(this,nh,!1),this.commit(),this.parent.setSelected(this),this.div.focus())}remove(){_(this,pt,Lp).call(this),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(_(this,pt,Dc).call(this),_(this,pt,Rc).call(this,l(this,ws).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),_(this,pt,Lp).call(this)):e&&(this._uiManager.addShouldRescale(this),_(this,pt,Dc).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,Ns._mergeSVGProperties({bbox:_(this,pt,Sh).call(this)},l(this,ws).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&_(this,pt,Rc).call(this,l(this,ws).updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;const e=super.render();e.classList.add("draw");const s=document.createElement("div");e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal";const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),this._uiManager.addShouldRescale(this),this.disableEditing(),e}static createDrawerInstance(e,s,i,n,r){St("Not implemented")}static startDrawing(e,s,i,{target:n,offsetX:r,offsetY:o}){const{viewport:{rotation:h}}=e,{width:c,height:u}=n.getBoundingClientRect(),d=new AbortController,g=e.combinedSignal(d);if(window.addEventListener("pointerup",f=>{d.abort(),e.toggleDrawing(!0),this._endDraw(f)},{signal:g}),window.addEventListener("pointerdown",ti,{capture:!0,passive:!1,signal:g}),window.addEventListener("contextmenu",Zs,{signal:g}),n.addEventListener("pointermove",this._drawMove.bind(this),{signal:g}),e.toggleDrawing(),this._currentDraw){e.drawLayer.updateProperties(this._currentDrawId,this._currentDraw.startNew(r,o,c,u,h));return}s.updateUIForDefaultProperties(this),this._currentDraw=this.createDrawerInstance(r,o,c,u,h),this._currentDrawingOptions=this.getDefaultDrawingOptions(),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(this._currentDrawingOptions.toSVGProperties(),this._currentDraw.defaultSVGProperties),!0,!1)}static _drawMove({offsetX:e,offsetY:s}){this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._currentDraw.add(e,s))}static _endDraw({offsetX:e,offsetY:s}){const i=this._currentParent;if(i.drawLayer.updateProperties(this._currentDrawId,this._currentDraw.end(e,s)),this.supportMultipleDrawings){const n=this._currentDraw,r=this._currentDrawId,o=n.getLastElement();i.addCommands({cmd:()=>{i.drawLayer.updateProperties(r,n.setLastElement(o))},undo:()=>{i.drawLayer.updateProperties(r,n.removeLastElement())},mustExec:!1,type:ut.DRAW_STEP});return}this.endDrawing(!1)}static endDrawing(e){const s=this._currentParent;if(!s)return null;if(s.toggleDrawing(!0),s.cleanUndoStack(ut.DRAW_STEP),!this._currentDraw.isEmpty()){const{pageDimensions:[i,n],scale:r}=s,o=s.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:this._currentDraw.getOutlines(i*r,n*r,r,this._INNER_MARGIN),drawingOptions:this._currentDrawingOptions,mustBeCommitted:!e});return this._cleanup(),o}return s.drawLayer.remove(this._currentDrawId),this._cleanup(),null}static _cleanup(){this._currentDrawId=-1,this._currentDraw=null,this._currentDrawingOptions=null,this._currentParent=null}createDrawingOptions(e){}static deserializeDraw(e,s,i,n,r,o){St("Not implemented")}static async deserialize(e,s,i){var d,g;const{rawDims:{pageWidth:n,pageHeight:r,pageX:o,pageY:h}}=s.viewport,c=this.deserializeDraw(o,h,n,r,this._INNER_MARGIN,e),u=await super.deserialize(e,s,i);return u.createDrawingOptions(e),_(d=u,pt,Dp).call(d,{drawOutlines:c}),_(g=u,pt,Dc).call(g),u.onScaleChanging(),u.rotate(),u}serializeDraw(e){const[s,i]=this.pageTranslation,[n,r]=this.pageDimensions;return l(this,ws).serialize([s,i,n,r],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};ws=new WeakMap,nh=new WeakMap,pt=new WeakSet,Dp=function({drawOutlines:e,drawId:s,drawingOptions:i}){v(this,ws,e),this._drawingOptions||(this._drawingOptions=i),s>=0?(this._drawId=s,this.parent.drawLayer.finalizeDraw(s,e.defaultProperties)):this._drawId=_(this,pt,Rp).call(this,e,this.parent),_(this,pt,Rc).call(this,e.box)},Rp=function(e,s){const{id:i}=s.drawLayer.draw(Ns._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return i},Lp=function(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())},Dc=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=_(this,pt,Rp).call(this,l(this,ws),e)}},by=function([e,s,i,n]){const{parentDimensions:[r,o],rotation:h}=this;switch(h){case 90:return[s,1-e,i*(o/r),n*(r/o)];case 180:return[1-e,1-s,i,n];case 270:return[1-s,e,i*(o/r),n*(r/o)];default:return[e,s,i,n]}},Ud=function(){const{x:e,y:s,width:i,height:n,parentDimensions:[r,o],rotation:h}=this;switch(h){case 90:return[1-s,e,i*(r/o),n*(o/r)];case 180:return[1-e,1-s,i,n];case 270:return[s,1-e,i*(r/o),n*(o/r)];default:return[e,s,i,n]}},Rc=function(e){if([this.x,this.y,this.width,this.height]=_(this,pt,by).call(this,e),this.div){this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)}this._onResized()},Sh=function(){const{x:e,y:s,width:i,height:n,rotation:r,parentRotation:o,parentDimensions:[h,c]}=this;switch((r*4+o)/90){case 1:return[1-s-n,e,n,i];case 2:return[1-e-i,1-s-n,i,n];case 3:return[s,1-e-i,n,i];case 4:return[e,s-i*(h/c),n*(c/h),i*(h/c)];case 5:return[1-s,e,i*(h/c),n*(c/h)];case 6:return[1-e-n*(c/h),1-s,n*(c/h),i*(h/c)];case 7:return[s-i*(h/c),1-e-n*(c/h),i*(h/c),n*(c/h)];case 8:return[e-i,s-n,i,n];case 9:return[1-s,e-i,n,i];case 10:return[1-e,1-s,i,n];case 11:return[s-n,1-e,n,i];case 12:return[e-n*(c/h),s,n*(c/h),i*(h/c)];case 13:return[1-s-i*(h/c),e-n*(c/h),i*(h/c),n*(c/h)];case 14:return[1-e,1-s-i*(h/c),n*(c/h),i*(h/c)];case 15:return[s,1-e,i*(h/c),n*(c/h)];default:return[e,s,i,n]}},q(Ns,"_currentDrawId",-1),q(Ns,"_currentDraw",null),q(Ns,"_currentDrawingOptions",null),q(Ns,"_currentParent",null),q(Ns,"_INNER_MARGIN",3);let Of=Ns;class yC{constructor(t,e,s,i,n,r){w(this,oh);w(this,Ii,new Float64Array(6));w(this,fe);w(this,pe);w(this,Fo);w(this,rh);w(this,os);w(this,ye,"");w(this,Bs,0);w(this,Io,new id);w(this,jo);w(this,No);v(this,jo,s),v(this,No,i),v(this,Fo,n),v(this,rh,r),[t,e]=_(this,oh,Yd).call(this,t,e);const o=v(this,fe,[NaN,NaN,NaN,NaN,t,e]);v(this,os,[t,e]),v(this,pe,[{line:o,points:l(this,os)}]),l(this,Ii).set(o,0)}updateProperty(t,e){t==="stroke-width"&&v(this,rh,e)}isEmpty(){return!l(this,pe)||l(this,pe).length===0}add(t,e){[t,e]=_(this,oh,Yd).call(this,t,e);const[s,i,n,r]=l(this,Ii).subarray(2,6),o=t-n,h=e-r;return Math.hypot(l(this,jo)*o,l(this,No)*h)<=2?null:(l(this,os).push(t,e),isNaN(s)?(l(this,Ii).set([n,r,t,e],2),l(this,fe).push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(l(this,Ii)[0])&&l(this,fe).splice(6,6),l(this,Ii).set([s,i,n,r,t,e],0),l(this,fe).push((s+5*n)/6,(i+5*r)/6,(5*n+t)/6,(5*r+e)/6,(n+t)/2,(r+e)/2),{path:{d:this.toSVGPath()}}))}end(t,e){const s=this.add(t,e);return s||(l(this,os).length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){v(this,jo,s),v(this,No,i),v(this,Fo,n),[t,e]=_(this,oh,Yd).call(this,t,e);const r=v(this,fe,[NaN,NaN,NaN,NaN,t,e]);v(this,os,[t,e]);const o=l(this,pe).at(-1);return o&&(o.line=new Float32Array(o.line),o.points=new Float32Array(o.points)),l(this,pe).push({line:r,points:l(this,os)}),l(this,Ii).set(r,0),v(this,Bs,0),this.toSVGPath(),null}getLastElement(){return l(this,pe).at(-1)}setLastElement(t){return l(this,pe)?(l(this,pe).push(t),v(this,fe,t.line),v(this,os,t.points),v(this,Bs,0),{path:{d:this.toSVGPath()}}):l(this,Io).setLastElement(t)}removeLastElement(){if(!l(this,pe))return l(this,Io).removeLastElement();l(this,pe).pop(),v(this,ye,"");for(let t=0,e=l(this,pe).length;t<e;t++){const{line:s,points:i}=l(this,pe)[t];v(this,fe,s),v(this,os,i),v(this,Bs,0),this.toSVGPath()}return{path:{d:l(this,ye)}}}toSVGPath(){const t=U.svgRound(l(this,fe)[4]),e=U.svgRound(l(this,fe)[5]);if(l(this,os).length===2)return v(this,ye,`${l(this,ye)} M ${t} ${e} Z`),l(this,ye);if(l(this,os).length<=6){const i=l(this,ye).lastIndexOf("M");v(this,ye,`${l(this,ye).slice(0,i)} M ${t} ${e}`),v(this,Bs,6)}if(l(this,os).length===4){const i=U.svgRound(l(this,fe)[10]),n=U.svgRound(l(this,fe)[11]);return v(this,ye,`${l(this,ye)} L ${i} ${n}`),v(this,Bs,12),l(this,ye)}const s=[];l(this,Bs)===0&&(s.push(`M ${t} ${e}`),v(this,Bs,6));for(let i=l(this,Bs),n=l(this,fe).length;i<n;i+=6){const[r,o,h,c,u,d]=l(this,fe).slice(i,i+6).map(U.svgRound);s.push(`C${r} ${o} ${h} ${c} ${u} ${d}`)}return v(this,ye,l(this,ye)+s.join(" ")),v(this,Bs,l(this,fe).length),l(this,ye)}getOutlines(t,e,s,i){const n=l(this,pe).at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),l(this,Io).build(l(this,pe),t,e,s,l(this,Fo),l(this,rh),i),v(this,Ii,null),v(this,fe,null),v(this,pe,null),v(this,ye,null),l(this,Io)}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}Ii=new WeakMap,fe=new WeakMap,pe=new WeakMap,Fo=new WeakMap,rh=new WeakMap,os=new WeakMap,ye=new WeakMap,Bs=new WeakMap,Io=new WeakMap,jo=new WeakMap,No=new WeakMap,oh=new WeakSet,Yd=function(t,e){return U._normalizePoint(t,e,l(this,jo),l(this,No),l(this,Fo))};const Hf=class Hf extends U{constructor(){super(...arguments);w(this,_e);w(this,Ue);w(this,mc,0);w(this,vc);w(this,xs);w(this,ji);w(this,Ni);w(this,ah);w(this,hh);w(this,lh)}build(e,s,i,n,r,o,h){v(this,ji,s),v(this,Ni,i),v(this,ah,n),v(this,hh,r),v(this,lh,o),v(this,vc,h??0),v(this,xs,e),_(this,_e,_y).call(this)}setLastElement(e){return l(this,xs).push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return l(this,xs).pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:s}of l(this,xs)){if(e.push(`M${U.svgRound(s[4])} ${U.svgRound(s[5])}`),s.length===6){e.push("Z");continue}if(s.length===12){e.push(`L${U.svgRound(s[10])} ${U.svgRound(s[11])}`);continue}for(let i=6,n=s.length;i<n;i+=6){const[r,o,h,c,u,d]=s.subarray(i,i+6).map(U.svgRound);e.push(`C${r} ${o} ${h} ${c} ${u} ${d}`)}}return e.join("")}serialize([e,s,i,n],r){const o=[],h=[],[c,u,d,g]=_(this,_e,yy).call(this);let f,p,m,y,b,x,C,A,M;switch(l(this,hh)){case 0:M=U._rescale,f=e,p=s+n,m=i,y=-n,b=e+c*i,x=s+(1-u-g)*n,C=e+(c+d)*i,A=s+(1-u)*n;break;case 90:M=U._rescaleAndSwap,f=e,p=s,m=i,y=n,b=e+u*i,x=s+c*n,C=e+(u+g)*i,A=s+(c+d)*n;break;case 180:M=U._rescale,f=e+i,p=s,m=-i,y=n,b=e+(1-c-d)*i,x=s+u*n,C=e+(1-c)*i,A=s+(u+g)*n;break;case 270:M=U._rescaleAndSwap,f=e+i,p=s+n,m=-i,y=-n,b=e+(1-u-g)*i,x=s+(1-c-d)*n,C=e+(1-u)*i,A=s+(1-c)*n;break}for(const{line:D,points:k}of l(this,xs))o.push(M(D,f,p,m,y,r?new Array(D.length):null)),h.push(M(k,f,p,m,y,r?new Array(k.length):null));return{lines:o,points:h,rect:[b,x,C,A]}}static deserialize(e,s,i,n,r,{paths:{lines:o,points:h},rotation:c,thickness:u}){const d=[];let g,f,p,m,y;switch(c){case 0:y=U._rescale,g=-e/i,f=s/n+1,p=1/i,m=-1/n;break;case 90:y=U._rescaleAndSwap,g=-s/n,f=-e/i,p=1/n,m=1/i;break;case 180:y=U._rescale,g=e/i+1,f=-s/n,p=-1/i,m=1/n;break;case 270:y=U._rescaleAndSwap,g=s/n+1,f=e/i+1,p=-1/n,m=-1/i;break}for(let x=0,C=o.length;x<C;x++)d.push({line:y(o[x].map(A=>A??NaN),g,f,p,m),points:y(h[x].map(A=>A??NaN),g,f,p,m)});const b=new Hf;return b.build(d,i,n,1,c,u,r),b}get box(){return l(this,Ue)}updateProperty(e,s){return e==="stroke-width"?_(this,_e,wy).call(this,s):null}updateParentDimensions([e,s],i){const[n,r]=_(this,_e,Ln).call(this);v(this,ji,e),v(this,Ni,s),v(this,ah,i);const[o,h]=_(this,_e,Ln).call(this),c=o-n,u=h-r,d=l(this,Ue);return d[0]-=c,d[1]-=u,d[2]+=2*c,d[3]+=2*u,d}updateRotation(e){return v(this,mc,e),{path:{transform:this.rotationTransform}}}get viewBox(){return l(this,Ue).map(U.svgRound).join(" ")}get defaultProperties(){const[e,s]=l(this,Ue);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${U.svgRound(e)} ${U.svgRound(s)}`}}}get rotationTransform(){const[,,e,s]=l(this,Ue);let i=0,n=0,r=0,o=0,h=0,c=0;switch(l(this,mc)){case 90:n=s/e,r=-e/s,h=e;break;case 180:i=-1,o=-1,h=e,c=s;break;case 270:n=-s/e,r=e/s,c=s;break;default:return""}return`matrix(${i} ${n} ${r} ${o} ${U.svgRound(h)} ${U.svgRound(c)})`}getPathResizingSVGProperties([e,s,i,n]){const[r,o]=_(this,_e,Ln).call(this),[h,c,u,d]=l(this,Ue);if(Math.abs(u-r)<=U.PRECISION||Math.abs(d-o)<=U.PRECISION){const y=e+i/2-(h+u/2),b=s+n/2-(c+d/2);return{path:{"transform-origin":`${U.svgRound(e)} ${U.svgRound(s)}`,transform:`${this.rotationTransform} translate(${y} ${b})`}}}const g=(i-2*r)/(u-2*r),f=(n-2*o)/(d-2*o),p=u/i,m=d/n;return{path:{"transform-origin":`${U.svgRound(h)} ${U.svgRound(c)}`,transform:`${this.rotationTransform} scale(${p} ${m}) translate(${U.svgRound(r)} ${U.svgRound(o)}) scale(${g} ${f}) translate(${U.svgRound(-r)} ${U.svgRound(-o)})`}}}getPathResizedSVGProperties([e,s,i,n]){const[r,o]=_(this,_e,Ln).call(this),h=l(this,Ue),[c,u,d,g]=h;if(h[0]=e,h[1]=s,h[2]=i,h[3]=n,Math.abs(d-r)<=U.PRECISION||Math.abs(g-o)<=U.PRECISION){const b=e+i/2-(c+d/2),x=s+n/2-(u+g/2);for(const{line:C,points:A}of l(this,xs))U._translate(C,b,x,C),U._translate(A,b,x,A);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${U.svgRound(e)} ${U.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const f=(i-2*r)/(d-2*r),p=(n-2*o)/(g-2*o),m=-f*(c+r)+e+r,y=-p*(u+o)+s+o;if(f!==1||p!==1||m!==0||y!==0)for(const{line:b,points:x}of l(this,xs))U._rescale(b,m,y,f,p,b),U._rescale(x,m,y,f,p,x);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${U.svgRound(e)} ${U.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,s],i){const[n,r]=i,o=l(this,Ue),h=e-o[0],c=s-o[1];if(l(this,ji)===n&&l(this,Ni)===r)for(const{line:u,points:d}of l(this,xs))U._translate(u,h,c,u),U._translate(d,h,c,d);else{const u=l(this,ji)/n,d=l(this,Ni)/r;v(this,ji,n),v(this,Ni,r);for(const{line:g,points:f}of l(this,xs))U._rescale(g,h,c,u,d,g),U._rescale(f,h,c,u,d,f);o[2]*=u,o[3]*=d}return o[0]=e,o[1]=s,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${U.svgRound(e)} ${U.svgRound(s)}`}}}get defaultSVGProperties(){const e=l(this,Ue);return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${U.svgRound(e[0])} ${U.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}};Ue=new WeakMap,mc=new WeakMap,vc=new WeakMap,xs=new WeakMap,ji=new WeakMap,Ni=new WeakMap,ah=new WeakMap,hh=new WeakMap,lh=new WeakMap,_e=new WeakSet,Ln=function(e=l(this,lh)){const s=l(this,vc)+e/2*l(this,ah);return l(this,hh)%180===0?[s/l(this,ji),s/l(this,Ni)]:[s/l(this,Ni),s/l(this,ji)]},yy=function(){const[e,s,i,n]=l(this,Ue),[r,o]=_(this,_e,Ln).call(this,0);return[e+r,s+o,i-2*r,n-2*o]},_y=function(){const e=v(this,Ue,new Float32Array([1/0,1/0,-1/0,-1/0]));for(const{line:n}of l(this,xs)){if(n.length<=12){for(let h=4,c=n.length;h<c;h+=6){const[u,d]=n.subarray(h,h+2);e[0]=Math.min(e[0],u),e[1]=Math.min(e[1],d),e[2]=Math.max(e[2],u),e[3]=Math.max(e[3],d)}continue}let r=n[4],o=n[5];for(let h=6,c=n.length;h<c;h+=6){const[u,d,g,f,p,m]=n.subarray(h,h+6);$.bezierBoundingBox(r,o,u,d,g,f,p,m,e),r=p,o=m}}const[s,i]=_(this,_e,Ln).call(this);e[0]=Math.min(1,Math.max(0,e[0]-s)),e[1]=Math.min(1,Math.max(0,e[1]-i)),e[2]=Math.min(1,Math.max(0,e[2]+s)),e[3]=Math.min(1,Math.max(0,e[3]+i)),e[2]-=e[0],e[3]-=e[1]},wy=function(e){const[s,i]=_(this,_e,Ln).call(this);v(this,lh,e);const[n,r]=_(this,_e,Ln).call(this),[o,h]=[n-s,r-i],c=l(this,Ue);return c[0]-=o,c[1]-=h,c[2]+=2*o,c[3]+=2*h,c};let id=Hf;const Vf=class Vf extends bC{constructor(e){super();w(this,ch);v(this,ch,e),super.updateProperties({fill:"none",stroke:Bt._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(e,s){e==="stroke-width"&&(s??(s=this["stroke-width"]),s*=l(this,ch).realScale),super.updateSVGProperty(e,s)}clone(){const e=new Vf(l(this,ch));return e.updateAll(this),e}};ch=new WeakMap;let Df=Vf;const uh=class uh extends Of{constructor(t){super({...t,name:"inkEditor"}),this._willKeepAspectRatio=!0}static initialize(t,e){Bt.initialize(t,e),this._defaultDrawingOptions=new Df(e.viewParameters)}static getDefaultDrawingOptions(t){const e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get supportMultipleDrawings(){return!0}static get typesMap(){return at(this,"typesMap",new Map([[ut.INK_THICKNESS,"stroke-width"],[ut.INK_COLOR,"stroke"],[ut.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(t,e,s,i,n){return new yC(t,e,s,i,n,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(t,e,s,i,n,r){return id.deserialize(t,e,s,i,n,r)}static async deserialize(t,e,s){return t instanceof Ef?null:super.deserialize(t,e,s)}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:t,_drawingOptions:e,parent:s}=this;e.updateSVGProperty("stroke-width"),s.drawLayer.updateProperties(t,e.toSVGProperties())}static onScaleChangingWhenDrawing(){const t=this._currentParent;t&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),t.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:t,thickness:e,opacity:s}){this._drawingOptions=uh.getDefaultDrawingOptions({stroke:$.makeHexColor(...t),"stroke-width":e,"stroke-opacity":s})}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:e,points:s,rect:i}=this.serializeDraw(t),{_drawingOptions:{stroke:n,"stroke-opacity":r,"stroke-width":o}}=this,h={annotationType:nt.INK,color:Bt._colorManager.convert(n),opacity:r,thickness:o,paths:{lines:e,points:s},pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return h.id=this.annotationElementId,h}};q(uh,"_type","ink"),q(uh,"_editorType",nt.INK),q(uh,"_defaultDrawingOptions",null);let Rf=uh;const bc=class bc extends Bt{constructor(e){super({...e,name:"stampEditor"});w(this,ht);w(this,Gt,null);w(this,we,null);w(this,vr,null);w(this,Mn,null);w(this,br,null);w(this,dh,"");w(this,Bi,null);w(this,Pn,null);w(this,Hi,null);w(this,Ss,!1);w(this,gh,!1);v(this,Mn,e.bitmapUrl),v(this,br,e.bitmapFile)}static initialize(e,s){Bt.initialize(e,s)}static get supportedTypes(){return at(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return at(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(e){return this.supportedTypes.includes(e)}static paste(e,s){s.pasteEditor(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:o}=e||this.copyCanvas(null,null,!0).imageData,h=await i.guess({name:"altText",request:{data:n,width:r,height:o,channels:n.length/(r*o)}});if(!h)throw new Error("No response from the AI service.");if(h.error)throw new Error("Error from the AI service.");if(h.cancel)return null;if(!h.output)throw new Error("No valid response from the AI service.");const c=h.output;return await this.setGuessedAltText(c),s&&!this.hasAltTextData()&&(this.altTextData={alt:c,decorative:!1}),c}remove(){var e,s;l(this,we)&&(v(this,Gt,null),this._uiManager.imageManager.deleteId(l(this,we)),(e=l(this,Bi))==null||e.remove(),v(this,Bi,null),(s=l(this,Pn))==null||s.disconnect(),v(this,Pn,null),l(this,Hi)&&(clearTimeout(l(this,Hi)),v(this,Hi,null))),super.remove()}rebuild(){if(!this.parent){l(this,we)&&_(this,ht,$d).call(this);return}super.rebuild(),this.div!==null&&(l(this,we)&&l(this,Bi)===null&&_(this,ht,$d).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(){this._isDraggable=!0,this.div.focus()}isEmpty(){return!(l(this,vr)||l(this,Gt)||l(this,Mn)||l(this,br)||l(this,we))}get isResizable(){return!0}render(){if(this.div)return this.div;let e,s;if(this.width&&(e=this.x,s=this.y),super.render(),this.div.hidden=!0,this.div.setAttribute("role","figure"),this.addAltTextButton(),l(this,Gt)?_(this,ht,Fp).call(this):_(this,ht,$d).call(this),this.width&&!this.annotationElementId){const[i,n]=this.parentDimensions;this.setAt(e*i,s*n,this.width*i,this.height*n)}return this.div}copyCanvas(e,s,i=!1){var f;e||(e=224);const{width:n,height:r}=l(this,Gt),o=new uf;let h=l(this,Gt),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*o.sx),m=d.height=Math.ceil(u*o.sy);l(this,Ss)||(h=_(this,ht,qd).call(this,p,m));const y=d.getContext("2d");y.filter=this._uiManager.hcmFilter;let b="white",x="#cfcfd8";this._uiManager.hcmFilter!=="none"?x="black":(f=window.matchMedia)!=null&&f.call(window,"(prefers-color-scheme: dark)").matches&&(b="#8f8f9d",x="#42414d");const C=15,A=C*o.sx,M=C*o.sy,D=new OffscreenCanvas(A*2,M*2),k=D.getContext("2d");k.fillStyle=b,k.fillRect(0,0,A*2,M*2),k.fillStyle=x,k.fillRect(0,0,A,M),k.fillRect(A,M,A,M),y.fillStyle=y.createPattern(D,"repeat"),y.fillRect(0,0,p,m),y.drawImage(h,0,0,h.width,h.height,0,0,p,m)}let g=null;if(i){let p,m;if(o.symmetric&&h.width<e&&h.height<e)p=h.width,m=h.height;else if(h=l(this,Gt),n>e||r>e){const x=Math.min(e/n,e/r);p=Math.floor(n*x),m=Math.floor(r*x),l(this,Ss)||(h=_(this,ht,qd).call(this,p,m))}const b=new OffscreenCanvas(p,m).getContext("2d",{willReadFrequently:!0});b.drawImage(h,0,0,h.width,h.height,0,0,p,m),g={width:p,height:m,data:b.getImageData(0,0,p,m).data}}return{canvas:d,width:c,height:u,imageData:g}}getImageForAltText(){return l(this,Bi)}static async deserialize(e,s,i){var m;let n=null;if(e instanceof Gv){const{data:{rect:y,rotation:b,id:x,structParent:C,popupRef:A},container:M,parent:{page:{pageNumber:D}}}=e,k=M.querySelector("canvas"),P=i.imageManager.getFromCanvas(M.id,k);k.remove();const R=((m=await s._structTree.getAriaAttributes(`${of}${x}`))==null?void 0:m.get("aria-label"))||"";n=e={annotationType:nt.STAMP,bitmapId:P.id,bitmap:P.bitmap,pageIndex:D-1,rect:y.slice(0),rotation:b,id:x,deleted:!1,accessibilityData:{decorative:!1,altText:R},isSvg:!1,structParent:C,popupRef:A}}const r=await super.deserialize(e,s,i),{rect:o,bitmap:h,bitmapUrl:c,bitmapId:u,isSvg:d,accessibilityData:g}=e;u&&i.imageManager.isValidId(u)?(v(r,we,u),h&&v(r,Gt,h)):v(r,Mn,c),v(r,Ss,d);const[f,p]=r.pageDimensions;return r.width=(o[2]-o[0])/f,r.height=(o[3]-o[1])/p,r.annotationElementId=e.id||null,g&&(r.altTextData=g),r._initialData=n,v(r,gh,!!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,we),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:l(this,Ss),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=_(this,ht,Kd).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=_(this,ht,Cy).call(this,i);if(h.isSame)return null;h.isSameAltText?delete i.accessibilityData:i.accessibilityData.structParent=this._initialData.structParent??-1}if(i.id=this.annotationElementId,s===null)return i;s.stamps||(s.stamps=new Map);const o=l(this,Ss)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!s.stamps.has(l(this,we)))s.stamps.set(l(this,we),{area:o,serialized:i}),i.bitmap=_(this,ht,Kd).call(this,!1);else if(l(this,Ss)){const h=s.stamps.get(l(this,we));o>h.area&&(h.area=o,h.serialized.bitmap.close(),h.serialized.bitmap=_(this,ht,Kd).call(this,!1))}return i}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}};Gt=new WeakMap,we=new WeakMap,vr=new WeakMap,Mn=new WeakMap,br=new WeakMap,dh=new WeakMap,Bi=new WeakMap,Pn=new WeakMap,Hi=new WeakMap,Ss=new WeakMap,gh=new WeakMap,ht=new WeakSet,Lc=function(e,s=!1){if(!e){this.remove();return}v(this,Gt,e.bitmap),s||(v(this,we,e.id),v(this,Ss,e.isSvg)),e.file&&v(this,dh,e.file.name),_(this,ht,Fp).call(this)},Fc=function(){if(v(this,vr,null),this._uiManager.enableWaiting(!1),!!l(this,Bi)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Gt)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Gt)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},$d=function(){if(l(this,we)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(l(this,we)).then(i=>_(this,ht,Lc).call(this,i,!0)).finally(()=>_(this,ht,Fc).call(this));return}if(l(this,Mn)){const i=l(this,Mn);v(this,Mn,null),this._uiManager.enableWaiting(!0),v(this,vr,this._uiManager.imageManager.getFromUrl(i).then(n=>_(this,ht,Lc).call(this,n)).finally(()=>_(this,ht,Fc).call(this)));return}if(l(this,br)){const i=l(this,br);v(this,br,null),this._uiManager.enableWaiting(!0),v(this,vr,this._uiManager.imageManager.getFromFile(i).then(n=>_(this,ht,Lc).call(this,n)).finally(()=>_(this,ht,Fc).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=bc.supportedTypesStr;const s=this._uiManager._signal;v(this,vr,new Promise(i=>{e.addEventListener("change",async()=>{if(!e.files||e.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const n=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),_(this,ht,Lc).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>_(this,ht,Fc).call(this))),e.click()},Fp=function(){const{div:e}=this;let{width:s,height:i}=l(this,Gt);const[n,r]=this.pageDimensions,o=.75;if(this.width)s=this.width*n,i=this.height*r;else if(s>o*n||i>o*r){const d=Math.min(o*n/s,o*r/i);s*=d,i*=d}const[h,c]=this.parentDimensions;this.setDims(s*h/n,i*c/r),this._uiManager.enableWaiting(!1);const u=v(this,Bi,document.createElement("canvas"));u.setAttribute("role","img"),this.addContainer(u),(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),_(this,ht,Ip).call(this,s,i),_(this,ht,Sy).call(this),l(this,gh)||(this.parent.addUndoableEditor(this),v(this,gh,!0)),this._reportTelemetry({action:"inserted_image"}),l(this,dh)&&u.setAttribute("aria-label",l(this,dh))},xy=function(e,s){var o;const[i,n]=this.parentDimensions;this.width=e/i,this.height=s/n,(o=this._initialOptions)!=null&&o.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,l(this,Hi)!==null&&clearTimeout(l(this,Hi)),v(this,Hi,setTimeout(()=>{v(this,Hi,null),_(this,ht,Ip).call(this,e,s)},200))},qd=function(e,s){const{width:i,height:n}=l(this,Gt);let r=i,o=n,h=l(this,Gt);for(;r>2*e||o>2*s;){const c=r,u=o;r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2)),o>2*s&&(o=o>=16384?Math.floor(o/2)-1:Math.ceil(o/2));const d=new OffscreenCanvas(r,o);d.getContext("2d").drawImage(h,0,0,c,u,0,0,r,o),h=d.transferToImageBitmap()}return h},Ip=function(e,s){const i=new uf,n=Math.ceil(e*i.sx),r=Math.ceil(s*i.sy),o=l(this,Bi);if(!o||o.width===n&&o.height===r)return;o.width=n,o.height=r;const h=l(this,Ss)?l(this,Gt):_(this,ht,qd).call(this,n,r),c=o.getContext("2d");c.filter=this._uiManager.hcmFilter,c.drawImage(h,0,0,h.width,h.height,0,0,n,r)},Kd=function(e){if(e){if(l(this,Ss)){const n=this._uiManager.imageManager.getSvgUrl(l(this,we));if(n)return n}const s=document.createElement("canvas");return{width:s.width,height:s.height}=l(this,Gt),s.getContext("2d").drawImage(l(this,Gt),0,0),s.toDataURL()}if(l(this,Ss)){const[s,i]=this.pageDimensions,n=Math.round(this.width*s*Xn.PDF_TO_CSS_UNITS),r=Math.round(this.height*i*Xn.PDF_TO_CSS_UNITS),o=new OffscreenCanvas(n,r);return o.getContext("2d").drawImage(l(this,Gt),0,0,l(this,Gt).width,l(this,Gt).height,0,0,n,r),o.transferToImageBitmap()}return structuredClone(l(this,Gt))},Sy=function(){this._uiManager._signal&&(v(this,Pn,new ResizeObserver(e=>{const s=e[0].contentRect;s.width&&s.height&&_(this,ht,xy).call(this,s.width,s.height)})),l(this,Pn).observe(this.div),this._uiManager._signal.addEventListener("abort",()=>{var e;(e=l(this,Pn))==null||e.disconnect(),v(this,Pn,null)},{once:!0}))},Cy=function(e){var c;const{rect:s,pageIndex:i,accessibilityData:{altText:n}}=this._initialData,r=e.rect.every((u,d)=>Math.abs(u-s[d])<1),o=e.pageIndex===i,h=(((c=e.accessibilityData)==null?void 0:c.alt)||"")===n;return{isSame:r&&o&&h,isSameAltText:h}},q(bc,"_type","stamp"),q(bc,"_editorType",nt.STAMP);let Lf=bc;const fi=class fi{constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:o,textLayer:h,viewport:c,l10n:u}){w(this,Ft);w(this,Bo);w(this,fh,!1);w(this,Vi,null);w(this,yr,null);w(this,On,null);w(this,Hs,new Map);w(this,_r,!1);w(this,ph,!1);w(this,gi,null);w(this,De,null);w(this,Dn,null);w(this,Y);const d=[...l(fi,wr).values()];if(!fi._initialized){fi._initialized=!0;for(const g of d)g.initialize(u,t)}t.registerEditorTypes(d),v(this,Y,t),this.pageIndex=e,this.div=s,v(this,Bo,n),v(this,Vi,r),this.viewport=c,v(this,De,h),this.drawLayer=o,this._structTree=i,l(this,Y).addLayer(this)}get isEmpty(){return l(this,Hs).size===0}get isInvisible(){return this.isEmpty&&l(this,Y).getMode()===nt.NONE}updateToolbar(t){l(this,Y).updateToolbar(t)}updateMode(t=l(this,Y).getMode()){switch(_(this,Ft,Qd).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(fi,wr).values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=l(this,De))==null?void 0:e.div)}setEditingState(t){l(this,Y).setEditingState(t)}addCommands(t){l(this,Y).addCommands(t)}cleanUndoStack(t){l(this,Y).cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){var e;(e=l(this,Vi))==null||e.div.classList.toggle("disabled",!t)}async enable(){this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of l(this,Hs).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(l(this,Y).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!l(this,Vi))return;const e=l(this,Vi).getEditableAnnotations();for(const s of e){if(s.hide(),l(this,Y).isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}}disable(){var i;v(this,ph,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const n of l(this,Hs).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,Vi)){const n=l(this,Vi).getEditableAnnotations();for(const r of n){const{id:o}=r.data;if(l(this,Y).isDeletedAnnotationElement(o))continue;let h=e.get(o);if(h){h.resetAnnotationElement(r),h.show(!1),r.show();continue}h=t.get(o),h&&(l(this,Y).addChangedExistingAnnotation(h),h.renderAnnotationElement(r)&&h.show(!1)),r.show()}}_(this,Ft,Qd).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of l(fi,wr).values())s.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),v(this,ph,!1)}getEditableAnnotation(t){var e;return((e=l(this,Vi))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){l(this,Y).getActive()!==t&&l(this,Y).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=l(this,De))!=null&&t.div&&!l(this,Dn)){v(this,Dn,new AbortController);const e=l(this,Y).combinedSignal(l(this,Dn));l(this,De).div.addEventListener("pointerdown",_(this,Ft,Ay).bind(this),{signal:e}),l(this,De).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=l(this,De))!=null&&t.div&&l(this,Dn)&&(l(this,Dn).abort(),v(this,Dn,null),l(this,De).div.classList.remove("highlighting"))}enableClick(){if(l(this,yr))return;v(this,yr,new AbortController);const t=l(this,Y).combinedSignal(l(this,yr));this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t}),this.div.addEventListener("pointerup",this.pointerup.bind(this),{signal:t})}disableClick(){var t;(t=l(this,yr))==null||t.abort(),v(this,yr,null)}attach(t){l(this,Hs).set(t.id,t);const{annotationElementId:e}=t;e&&l(this,Y).isDeletedAnnotationElement(e)&&l(this,Y).removeDeletedAnnotationElement(t)}detach(t){var e;l(this,Hs).delete(t.id),(e=l(this,Bo))==null||e.removePointerInTextLayer(t.contentDiv),!l(this,ph)&&t.annotationElementId&&l(this,Y).addDeletedAnnotationElement(t)}remove(t){this.detach(t),l(this,Y).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(l(this,Y).addDeletedAnnotationElement(t.annotationElementId),Bt.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),(e=t.parent)==null||e.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(!(t.parent===this&&t.isAttachedToDOM)){if(this.changeParent(t),l(this,Y).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(),l(this,Y).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!l(this,On)&&(t._focusEventsAllowed=!1,v(this,On,setTimeout(()=>{v(this,On,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:l(this,Y)._signal}),e.focus())},0))),t._structTreeParentId=(s=l(this,Bo))==null?void 0:s.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||(t.parent=this),t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getNextId(){return l(this,Y).getId()}combinedSignal(t){return l(this,Y).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=l(this,Ft,zi))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){l(this,Y).updateToolbar(t),l(this,Y).updateMode(t);const{offsetX:s,offsetY:i}=_(this,Ft,Np).call(this),n=this.getNextId(),r=_(this,Ft,jp).call(this,{parent:this,id:n,x:s,y:i,uiManager:l(this,Y),isCentered:!0,...e});r&&this.add(r)}async deserialize(t){var e;return await((e=l(fi,wr).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,l(this,Y)))||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=_(this,Ft,jp).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:l(this,Y),isCentered:e,...s});return n&&this.add(n),n}addNewEditor(){this.createAndAddNewEditor(_(this,Ft,Np).call(this),!0)}setSelected(t){l(this,Y).setSelected(t)}toggleSelected(t){l(this,Y).toggleSelected(t)}unselect(t){l(this,Y).unselect(t)}pointerup(t){var s;const{isMac:e}=Ge.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&l(this,_r)&&(v(this,_r,!1),!((s=l(this,Ft,zi))!=null&&s.isDrawer&&l(this,Ft,zi).supportMultipleDrawings))){if(!l(this,fh)){v(this,fh,!0);return}if(l(this,Y).getMode()===nt.STAMP){l(this,Y).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){var i;if(l(this,Y).getMode()===nt.HIGHLIGHT&&this.enableTextSelection(),l(this,_r)){v(this,_r,!1);return}const{isMac:e}=Ge.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(v(this,_r,!0),(i=l(this,Ft,zi))!=null&&i.isDrawer){this.startDrawingSession(t);return}const s=l(this,Y).getActive();v(this,fh,!s||s.isEmpty())}startDrawingSession(t){if(this.div.focus(),l(this,gi)){l(this,Ft,zi).startDrawing(this,l(this,Y),!1,t);return}l(this,Y).unselectAll(),v(this,gi,new AbortController);const e=l(this,Y).combinedSignal(l(this,gi));this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&this.commitOrRemove()},{signal:e}),l(this,Y).disableUserSelect(!0),l(this,Ft,zi).startDrawing(this,l(this,Y),!1,t)}endDrawingSession(t=!1){return l(this,gi)?(l(this,gi).abort(),v(this,gi,null),l(this,Y).disableUserSelect(!1),l(this,Ft,zi).endDrawing(t)):null}findNewParent(t,e,s){const i=l(this,Y).findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return l(this,gi)?(this.endDrawingSession(),!0):!1}onScaleChanging(){l(this,gi)&&l(this,Ft,zi).onScaleChangingWhenDrawing(this)}destroy(){var t,e;this.commitOrRemove(),((t=l(this,Y).getActive())==null?void 0:t.parent)===this&&(l(this,Y).commitOrRemove(),l(this,Y).setActiveEditor(null)),l(this,On)&&(clearTimeout(l(this,On)),v(this,On,null));for(const s of l(this,Hs).values())(e=l(this,Bo))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,l(this,Hs).clear(),l(this,Y).removeLayer(this)}render({viewport:t}){this.viewport=t,Nr(this.div,t);for(const e of l(this,Y).getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){l(this,Y).commitOrRemove(),_(this,Ft,Qd).call(this);const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,Nr(this.div,{rotation:s}),e!==s)for(const i of l(this,Hs).values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return l(this,Y).viewParameters.realScale}};Bo=new WeakMap,fh=new WeakMap,Vi=new WeakMap,yr=new WeakMap,On=new WeakMap,Hs=new WeakMap,_r=new WeakMap,ph=new WeakMap,gi=new WeakMap,De=new WeakMap,Dn=new WeakMap,Y=new WeakMap,wr=new WeakMap,Ft=new WeakSet,Ay=function(t){l(this,Y).unselectAll();const{target:e}=t;if(e===l(this,De).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&l(this,De).div.contains(e)){const{isMac:s}=Ge.platform;if(t.button!==0||t.ctrlKey&&s)return;l(this,Y).showAllEditors("highlight",!0,!0),l(this,De).div.classList.add("free"),this.toggleDrawing(),sd.startHighlighting(this,l(this,Y).direction==="ltr",{target:l(this,De).div,x:t.x,y:t.y}),l(this,De).div.addEventListener("pointerup",()=>{l(this,De).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:l(this,Y)._signal}),t.preventDefault()}},zi=function(){return l(fi,wr).get(l(this,Y).getMode())},jp=function(t){const e=l(this,Ft,zi);return e?new e.prototype.constructor(t):null},Np=function(){const{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),o=Math.min(window.innerWidth,t+s),h=Math.min(window.innerHeight,e+i),c=(n+o)/2-t,u=(r+h)/2-e,[d,g]=this.viewport.rotation%180===0?[c,u]:[u,c];return{offsetX:d,offsetY:g}},Qd=function(){for(const t of l(this,Hs).values())t.isEmpty()&&t.remove()},q(fi,"_initialized",!1),w(fi,wr,new Map([kf,Rf,Lf,sd].map(t=>[t._editorType,t])));let Ff=fi;const Re=class Re{constructor({pageIndex:t}){w(this,Gi);w(this,pi,null);w(this,yc,0);w(this,Ye,new Map);w(this,Ho,new Map);this.pageIndex=t}setParent(t){if(!l(this,pi)){v(this,pi,t);return}if(l(this,pi)!==t){if(l(this,Ye).size>0)for(const e of l(this,Ye).values())e.remove(),t.append(e);v(this,pi,t)}}static get _svgFactory(){return at(this,"_svgFactory",new Af)}draw(t,e=!1,s=!1){const i=Ke(this,yc)._++,n=_(this,Gi,Bp).call(this),r=Re._svgFactory.createElement("defs");n.append(r);const o=Re._svgFactory.createElement("path");r.append(o);const h=`path_p${this.pageIndex}_${i}`;o.setAttribute("id",h),o.setAttribute("vector-effect","non-scaling-stroke"),e&&l(this,Ho).set(i,o);const c=s?_(this,Gi,Ey).call(this,r,h):null,u=Re._svgFactory.createElement("use");return n.append(u),u.setAttribute("href",`#${h}`),this.updateProperties(n,t),l(this,Ye).set(i,n),{id:i,clipPathId:`url(#${c})`}}drawOutline(t,e){const s=Ke(this,yc)._++,i=_(this,Gi,Bp).call(this),n=Re._svgFactory.createElement("defs");i.append(n);const r=Re._svgFactory.createElement("path");n.append(r);const o=`path_p${this.pageIndex}_${s}`;r.setAttribute("id",o),r.setAttribute("vector-effect","non-scaling-stroke");let h;if(e){const d=Re._svgFactory.createElement("mask");n.append(d),h=`mask_p${this.pageIndex}_${s}`,d.setAttribute("id",h),d.setAttribute("maskUnits","objectBoundingBox");const g=Re._svgFactory.createElement("rect");d.append(g),g.setAttribute("width","1"),g.setAttribute("height","1"),g.setAttribute("fill","white");const f=Re._svgFactory.createElement("use");d.append(f),f.setAttribute("href",`#${o}`),f.setAttribute("stroke","none"),f.setAttribute("fill","black"),f.setAttribute("fill-rule","nonzero"),f.classList.add("mask")}const c=Re._svgFactory.createElement("use");i.append(c),c.setAttribute("href",`#${o}`),h&&c.setAttribute("mask",`url(#${h})`);const u=c.cloneNode();return i.append(u),c.classList.add("mainOutline"),u.classList.add("secondaryOutline"),this.updateProperties(i,t),l(this,Ye).set(s,i),s}finalizeDraw(t,e){l(this,Ho).delete(t),this.updateProperties(t,e)}updateProperties(t,e){var h;if(!e)return;const{root:s,bbox:i,rootClass:n,path:r}=e,o=typeof t=="number"?l(this,Ye).get(t):t;if(o){if(s&&_(this,Gi,Hp).call(this,o,s),i&&_(h=Re,wd,Ty).call(h,o,i),n){const{classList:c}=o;for(const[u,d]of Object.entries(n))c.toggle(u,d)}if(r){const u=o.firstChild.firstChild;_(this,Gi,Hp).call(this,u,r)}}}updateParent(t,e){if(e===this)return;const s=l(this,Ye).get(t);s&&(l(e,pi).append(s),l(this,Ye).delete(t),l(e,Ye).set(t,s))}remove(t){l(this,Ho).delete(t),l(this,pi)!==null&&(l(this,Ye).get(t).remove(),l(this,Ye).delete(t))}destroy(){v(this,pi,null);for(const t of l(this,Ye).values())t.remove();l(this,Ye).clear(),l(this,Ho).clear()}};pi=new WeakMap,yc=new WeakMap,Ye=new WeakMap,Ho=new WeakMap,wd=new WeakSet,Ty=function(t,[e,s,i,n]){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`},Gi=new WeakSet,Bp=function(){const t=Re._svgFactory.create(1,1,!0);return l(this,pi).append(t),t.setAttribute("aria-hidden",!0),t},Ey=function(t,e){const s=Re._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=Re._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i},Hp=function(t,e){for(const[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)},w(Re,wd);let If=Re;globalThis.pdfjsTestingUtils={HighlightOutliner:Mf},Z.AbortException,Z.AnnotationEditorLayer,Z.AnnotationEditorParamsType,Z.AnnotationEditorType,Z.AnnotationEditorUIManager,Z.AnnotationLayer,Z.AnnotationMode,Z.ColorPicker,Z.DOMSVGFactory,Z.DrawLayer,Z.FeatureTest;var _C=Z.GlobalWorkerOptions;Z.ImageKind,Z.InvalidPDFException,Z.MissingPDFException,Z.OPS,Z.OutputScale,Z.PDFDataRangeTransport,Z.PDFDateString,Z.PDFWorker,Z.PasswordResponses,Z.PermissionFlag,Z.PixelsPerInch,Z.RenderingCancelledException,Z.TextLayer,Z.UnexpectedResponseException,Z.Util,Z.VerbosityLevel,Z.XfaLayer,Z.build,Z.createValidAbsoluteUrl,Z.fetchData;var wC=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 xC={fabric:"^6.5.1","pdfjs-dist":"^4.9.124"};function SC(a){return new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>t(s.result)),s.addEventListener("error",e),s.readAsDataURL(a)})}const CC=xC["pdfjs-dist"].replace("^","");_C.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${CC}/pdf.worker.min.mjs`;async function AC(a){const t="data:application/pdf;base64,",e=await SC(a);if(typeof e=="string")return window.atob(e.slice(t.length))}function TC(a,t){return wC({data:a,password:t}).promise}const EC={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},kC={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},MC={stroke:"#000",hoverStroke:"#B7EC5D",src:""};function zv(a=""){const t=Q.useRef(0),e=Q.useRef(null),s=Q.useRef(null),i=Q.useRef(1),n=Q.useRef({...MC});function r(){if(!a||ks.has(a))return;const k=cx(a);return k.on("selection:cleared",()=>A(k)),k}function o(k,P){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,P))??Promise.reject(new Error(`Unsupported ${R} file type.`))}async function h(k,P){const R=await AC(k);if(!R)return;const F=ux(k,R);try{return await c({page:1,PDFBase64:R,scale:.8,password:P}),{...F,pages:t.current}}catch(I){return Promise.reject(I)}}async function c({page:k,PDFBase64:P,scale:R,password:F}){try{const I=await TC(P,F),X=await I.getPage(k),{renderTask:j,canvas:N}=dx(X,R);return t.current=I.numPages,j.promise.then(()=>u(N))}catch(I){return Promise.reject(I)}}function u(k){fx(a,k)}async function d(k){return await px(a,k)}async function g({url:k,scale:P=.5}){await K0(a,{url:k,scale:P})}async function f(k,P){const R=ks.get(a);if(!R)return;const F=await Te.fromURL(k,{},{...EC,...P});R.add(F),m(R,F)}function p(k,P){const R=ks.get(a);if(!R)return;const F=new Ae(k,{...kC,...P});R.add(F),m(R,F)}function m(k,P){P.on("selected",R=>y({canvas:k,target:R.target})),P.on("modified",R=>Gh(R.target,e.current)),P.on("scaling",R=>Gh(R.transform.target,e.current)),P.on("moving",R=>Gh(R.transform.target,e.current)),P.on("rotating",R=>Gh(R.transform.target,e.current))}async function y({canvas:k,target:P,stroke:R=n.current.stroke,uuid:F=Date.now()}){var X;if(((X=e.current)==null?void 0:X.stroke)===`${R}-${F}`)return;const I=await gx(n.current.src,R,F);A(k),e.current=I,s.current=P,b(k,P,F),x(i.current,!0),k.add(I)}function b(k,P,R){e.current&&(e.current.on("selected",()=>{k.remove(P),A(k)}),e.current.on("mouseover",()=>{y({canvas:k,target:P,stroke:n.current.hoverStroke,uuid:R})}),e.current.on("mouseout",()=>{y({canvas:k,target:P,stroke:n.current.stroke,uuid:R})}))}function x(k,P=!1){const R=ks.get(a);i.current=k,R&&(vx(s.current,k,n.current),mx(s.current,k,e.current),!P&&R.renderAll())}function C(k){if(!k)return;n.current={...n.current,...k};const P=ks.get(a);!e||!s.current||!P||y({target:s.current,canvas:P})}function A(k){e.current&&(k.remove(e.current),e.current=s.current=null)}function M(){bx(a)}function D(){yx(a)}return{createCanvas:r,loadFile:o,specifyPage:c,renderImage:g,addFabric:f,addTextFabric:p,clearActive:M,deleteCanvas:D,scaleFabric:x,setCloseSvgOptions:C}}function PC(a){let t=0;const e=lx(()=>{t!==window.innerWidth&&(t=window.innerWidth,a())});Q.useEffect(()=>(window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)),[])}const OC=Q.forwardRef(DC);function DC({file:a,page:t=1,canvasId:e="PDF-canvas",fileZoom:s=1,fileScale:i=1,canvasScale:n=1,canvasClass:r="",isDrop:o=!1,password:h,dropTextOptions:c,dropImageOptions:u,closeSvgOptions:d},g){const f=Q.useRef(null),p=`${e}-${t-1}`,m=Q.useMemo(()=>s*n,[s,n]),{createCanvas:y,specifyPage:b,addFabric:x,addTextFabric:C,renderImage:A,clearActive:M,deleteCanvas:D,scaleFabric:k,setCloseSvgOptions:P}=zv(p);PC(R);async function R(){window.requestAnimationFrame(async()=>{if(y(),a.PDFBase64.startsWith("data:image")||a.canvas){const{canvas:j}=a,N=j?7:3,it=j!=null&&j.length?j[t-1]:a.PDFBase64;A({url:it,scale:i/N});return}await b({page:t,PDFBase64:a.PDFBase64,scale:i,password:h})})}function F(j){if(j.preventDefault(),j.stopPropagation(),!o||!j.dataTransfer)return;const{dataTransfer:N,clientX:it,clientY:K}=j,V=N.getData("text"),H=N.getData("image"),Et={left:it-71,top:K-55};H&&I(H,Et),V&&X(V,Et)}function I(j,N){x(j,{...N,...u})}function X(j,N){C(j,{...N,...c})}return Q.useImperativeHandle(g,()=>({addImage:I,addText:X,clearActive:M,deleteCanvas:D,canvasRef:f})),Q.useEffect(()=>{R()},[i,t,a,h]),Q.useEffect(()=>{k(m)},[m]),Q.useEffect(()=>{P(d)},[d]),Q.useEffect(()=>()=>D(),[]),Wp.jsx("div",{style:{transform:`scale(${m})`},onDragOver:j=>j.preventDefault(),onDragEnter:j=>j.preventDefault(),onDrop:F,children:Wp.jsx("canvas",{id:p,ref:f,className:r})})}ct.default=OC,ct.useFabric=zv,Object.defineProperties(ct,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|