@component-hook/pdf-canvas 0.2.0 → 0.2.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -16
- package/dist/react/pdf-canvas.es.js +3957 -3936
- package/dist/react/pdf-canvas.umd.js +75 -75
- package/dist/vue/pdf-canvas.es.js +3811 -3787
- package/dist/vue/pdf-canvas.umd.js +60 -60
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(ct,K){typeof exports=="object"&&typeof module<"u"?K(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],K):(ct=typeof globalThis<"u"?globalThis:ct||self,K(ct["pdf-canvas"]={},ct.React))})(this,function(ct,K){"use strict";var
|
|
1
|
+
(function(ct,K){typeof exports=="object"&&typeof module<"u"?K(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],K):(ct=typeof globalThis<"u"?globalThis:ct||self,K(ct["pdf-canvas"]={},ct.React))})(this,function(ct,K){"use strict";var iA=Object.defineProperty;var Kv=ct=>{throw TypeError(ct)};var nA=(ct,K,Ft)=>K in ct?iA(ct,K,{enumerable:!0,configurable:!0,writable:!0,value:Ft}):ct[K]=Ft;var tt=(ct,K,Ft)=>nA(ct,typeof K!="symbol"?K+"":K,Ft),Pf=(ct,K,Ft)=>K.has(ct)||Kv("Cannot "+Ft);var c=(ct,K,Ft)=>(Pf(ct,K,"read from private field"),Ft?Ft.call(ct):K.get(ct)),w=(ct,K,Ft)=>K.has(ct)?Kv("Cannot add the same private member more than once"):K instanceof WeakSet?K.add(ct):K.set(ct,Ft),v=(ct,K,Ft,Sn)=>(Pf(ct,K,"write to private field"),Sn?Sn.call(ct,Ft):K.set(ct,Ft),Ft),y=(ct,K,Ft)=>(Pf(ct,K,"access private method"),Ft);var Ge=(ct,K,Ft,Sn)=>({set _(dr){v(ct,K,dr,Ft)},get _(){return c(ct,K,Sn)}});var Yi,od,Df,Xh,Ln,Rr,Vs,Fr,zh,Vh,Wu,Jv,He,Qv,Zv,hd,tb,Rf,Gh,Lr,Ir,In,eb,sb,ib,Xu,so,Yh,Ee,io,ld,ce,jn,Uh,ue,zu,nb,no,os,re,pe,ro,qi,ao,Gs,Nn,oo,jr,gi,Ys,Nr,qh,$h,ho,Kh,fi,Bn,lo,Hn,pi,Gu,Wn,Jh,Xn,Br,Qh,Zh,de,wt,$i,Hr,tl,el,zn,mi,Ki,sl,Ss,B,cd,Ff,rb,ab,ud,ob,hb,lb,Lf,cb,If,jf,ub,Ye,cr,db,gb,Nf,fb,ac,Bf,ge,vi,Us,uo,bi,hs,go,yi,Je,Ji,Wr,_i,Vn,qs,oc,dd,Xr,$s,jt,fo,zr,me,Vr,Gn,il,Gr,Yn,nl,Yr,Qi,wi,po,mo,Cs,rl,Yu,rt,Hf,al,Wf,Xf,pb,mb,zf,Vf,Gf,vb,Yf,bb,yb,_b,Uf,hc,Ur,qr,fe,Uu,wb,ol,vo,hl,$r,Kr,xi,Zi,ke,qu,Jr,z,Pe,nh,rh,gd,ah,xb,qf,oh,lc,cc,$f,uc,Un,Kf,Jf,ll,cl,bo,As,Sb,Cb,Ab,fd,Qr,ul,dl,gl,fl,yo,qn,xt,_o,wo,pl,Qf,Lv,$n,Qe,ml,vl,Zr,tn,bl,yl,ta,xo,So,Kn,Co,_l,Ao,ea,wl,xl,sa,ia,Sl,Jn,To,en,Tb,Eb,Zf,ls,pd,tp,kb,Mb,Ku,Qn,sn,Ts,hh,md,nn,Qu,Zu,na,ra,Eo,vd,ko,bd,rn,Si,Mo,Oo,Ci,aa,dc,Ks,Cl,ep,Zn,tr,oa,la,Po,Do,Al,sp,cs,Ra,Ob,Pb,Ro,td,ed,Fo,ca,Xt,an,Lo,Tl,El,Io,on,Js,hn,kl,ln,Ml,ua,da,St,yd,ip,Db,Rb,Fb,Lb,_d,wd,np,Ol,Pl,Dl,Rl,Fl,Ll,Il,rp,jl,ga,fa,Nl,pa,Ib,ap,Qs,us,Bl,ma,ds,Qt,jb,Nb,Bb,xd,cn,Sd,Cd,Hb,op,Wb,gs,Zs,jo,No,Ai,ot,va,ba,Hl,Wl,Bo,Ho,er,Xl,sd,id,oe,gc,Xb,zb,Vb,Gb,Yb,Ub,Wo,ya,dn,zl,fs,Vl,Ut,Ze,fc,pc,qb,Gl,sr,ti,Xe,$b,Ad,Kb,Jb,hp,Yl,Xo,ei,_a,zo,he,Ul,Vo,ql,$l,ir,si,Go,Kl,Ct,lp,cp,up,Fa,Qb,ur,Yo,Jl,gn,wa,Uo,Es,Ql,Zl,xa,ii,Me,es,qo,fn,le,$o,ks,tc,it,dp,Td,Zb,ty,ey,gp,La,Ms,lh,sy,Ed,mc,iy,ny,ry,ay,oy,Sa,Ca,Ti,pn,Os,Aa,Ta,Ea,mn,Ko,ka,Ma,nr,N,hy,ly,cy,uy,fp,dy,pp,gy,fy,py,my,vy,Ia,mp,vp,bp,kd,Md,ch,yp,Od,vn,by,_p,yy,_y,wp,Pd,vc,Bt,ve,rr,bn,ar,Jo,Ei,yn,ki,ps,Qo,ht,bc,yc,Dd,xp,wy,Rd,Sp,Fd,xy,Sy,Oa,Zo,Mi,or,_n,ms,hr,th,eh,Oe,wn,q,lr,be,Cy,Cp,Ap,Tp,Ld,Oi,sc,Zt,xn,ic,Ep,Pa,kp,Ay;var Ft=typeof document<"u"?document.currentScript:null,Sn={exports:{}},dr={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var Mp;function Ty(){if(Mp)return dr;Mp=1;var o=K,t=Symbol.for("react.element"),e=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,i=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,n={key:!0,ref:!0,__self:!0,__source:!0};function r(a,h,l){var u,d={},g=null,f=null;l!==void 0&&(g=""+l),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(a&&a.defaultProps)for(u in h=a.defaultProps,h)d[u]===void 0&&(d[u]=h[u]);return{$$typeof:t,type:a,key:g,ref:f,props:d,_owner:i.current}}return dr.Fragment=e,dr.jsx=r,dr.jsxs=r,dr}var uh={};/**
|
|
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
|
-
`+
|
|
19
|
-
`),
|
|
20
|
-
`),
|
|
21
|
-
`+lt[
|
|
17
|
+
*/var Op;function Ey(){return Op||(Op=1,process.env.NODE_ENV!=="production"&&function(){var o=K,t=Symbol.for("react.element"),e=Symbol.for("react.portal"),s=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),n=Symbol.for("react.profiler"),r=Symbol.for("react.provider"),a=Symbol.for("react.context"),h=Symbol.for("react.forward_ref"),l=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 _(C){if(C===null||typeof C!="object")return null;var F=p&&C[p]||C[m];return typeof F=="function"?F:null}var b=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function x(C){{for(var F=arguments.length,W=new Array(F>1?F-1:0),Q=1;Q<F;Q++)W[Q-1]=arguments[Q];S("error",C,W)}}function S(C,F,W){{var Q=b.ReactDebugCurrentFrame,bt=Q.getStackAddendum();bt!==""&&(F+="%s",W=W.concat([bt]));var Tt=W.map(function(ft){return String(ft)});Tt.unshift("Warning: "+F),Function.prototype.apply.call(console[C],console,Tt)}}var A=!1,k=!1,P=!1,M=!1,O=!1,R;R=Symbol.for("react.module.reference");function I(C){return!!(typeof C=="string"||typeof C=="function"||C===s||C===n||O||C===i||C===l||C===u||M||C===f||A||k||P||typeof C=="object"&&C!==null&&(C.$$typeof===g||C.$$typeof===d||C.$$typeof===r||C.$$typeof===a||C.$$typeof===h||C.$$typeof===R||C.getModuleId!==void 0))}function j(C,F,W){var Q=C.displayName;if(Q)return Q;var bt=F.displayName||F.name||"";return bt!==""?W+"("+bt+")":W}function G(C){return C.displayName||"Context"}function L(C){if(C==null)return null;if(typeof C.tag=="number"&&x("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof C=="function")return C.displayName||C.name||null;if(typeof C=="string")return C;switch(C){case s:return"Fragment";case e:return"Portal";case n:return"Profiler";case i:return"StrictMode";case l:return"Suspense";case u:return"SuspenseList"}if(typeof C=="object")switch(C.$$typeof){case a:var F=C;return G(F)+".Consumer";case r:var W=C;return G(W._context)+".Provider";case h:return j(C,C.render,"ForwardRef");case d:var Q=C.displayName||null;return Q!==null?Q:L(C.type)||"Memo";case g:{var bt=C,Tt=bt._payload,ft=bt._init;try{return L(ft(Tt))}catch{return null}}}return null}var H=Object.assign,$=0,J,Y,X,Ot,zt,te,Ht;function At(){}At.__reactDisabledLog=!0;function _e(){{if($===0){J=console.log,Y=console.info,X=console.warn,Ot=console.error,zt=console.group,te=console.groupCollapsed,Ht=console.groupEnd;var C={configurable:!0,enumerable:!0,value:At,writable:!0};Object.defineProperties(console,{info:C,log:C,warn:C,error:C,group:C,groupCollapsed:C,groupEnd:C})}$++}}function Ps(){{if($--,$===0){var C={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:H({},C,{value:J}),info:H({},C,{value:Y}),warn:H({},C,{value:X}),error:H({},C,{value:Ot}),group:H({},C,{value:zt}),groupCollapsed:H({},C,{value:te}),groupEnd:H({},C,{value:Ht})})}$<0&&x("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var kt=b.ReactCurrentDispatcher,gt;function Ds(C,F,W){{if(gt===void 0)try{throw Error()}catch(bt){var Q=bt.stack.trim().match(/\n( *(at )?)/);gt=Q&&Q[1]||""}return`
|
|
18
|
+
`+gt+C}}var ri=!1,ze;{var DC=typeof WeakMap=="function"?WeakMap:Map;ze=new DC}function Iv(C,F){if(!C||ri)return"";{var W=ze.get(C);if(W!==void 0)return W}var Q;ri=!0;var bt=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var Tt;Tt=kt.current,kt.current=null,_e();try{if(F){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(ss){Q=ss}Reflect.construct(C,[],ft)}else{try{ft.call()}catch(ss){Q=ss}C.call(ft.prototype)}}else{try{throw Error()}catch(ss){Q=ss}C()}}catch(ss){if(ss&&Q&&typeof ss.stack=="string"){for(var lt=ss.stack.split(`
|
|
19
|
+
`),Ve=Q.stack.split(`
|
|
20
|
+
`),qt=lt.length-1,ee=Ve.length-1;qt>=1&&ee>=0&<[qt]!==Ve[ee];)ee--;for(;qt>=1&&ee>=0;qt--,ee--)if(lt[qt]!==Ve[ee]){if(qt!==1||ee!==1)do if(qt--,ee--,ee<0||lt[qt]!==Ve[ee]){var Rs=`
|
|
21
|
+
`+lt[qt].replace(" at new "," at ");return C.displayName&&Rs.includes("<anonymous>")&&(Rs=Rs.replace("<anonymous>",C.displayName)),typeof C=="function"&&ze.set(C,Rs),Rs}while(qt>=1&&ee>=0);break}}}finally{ri=!1,kt.current=Tt,Ps(),Error.prepareStackTrace=bt}var ih=C?C.displayName||C.name:"",Da=ih?Ds(ih):"";return typeof C=="function"&&ze.set(C,Da),Da}function RC(C,F,W){return Iv(C,!1)}function FC(C){var F=C.prototype;return!!(F&&F.isReactComponent)}function nd(C,F,W){if(C==null)return"";if(typeof C=="function")return Iv(C,FC(C));if(typeof C=="string")return Ds(C);switch(C){case l:return Ds("Suspense");case u:return Ds("SuspenseList")}if(typeof C=="object")switch(C.$$typeof){case h:return RC(C.render);case d:return nd(C.type,F,W);case g:{var Q=C,bt=Q._payload,Tt=Q._init;try{return nd(Tt(bt),F,W)}catch{}}}return""}var nc=Object.prototype.hasOwnProperty,jv={},Nv=b.ReactDebugCurrentFrame;function rd(C){if(C){var F=C._owner,W=nd(C.type,C._source,F?F.type:null);Nv.setExtraStackFrame(W)}else Nv.setExtraStackFrame(null)}function LC(C,F,W,Q,bt){{var Tt=Function.call.bind(nc);for(var ft in C)if(Tt(C,ft)){var lt=void 0;try{if(typeof C[ft]!="function"){var Ve=Error((Q||"React class")+": "+W+" type `"+ft+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof C[ft]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Ve.name="Invariant Violation",Ve}lt=C[ft](F,ft,Q,W,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(qt){lt=qt}lt&&!(lt instanceof Error)&&(rd(bt),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).",Q||"React class",W,ft,typeof lt),rd(null)),lt instanceof Error&&!(lt.message in jv)&&(jv[lt.message]=!0,rd(bt),x("Failed %s type: %s",W,lt.message),rd(null))}}}var IC=Array.isArray;function Af(C){return IC(C)}function jC(C){{var F=typeof Symbol=="function"&&Symbol.toStringTag,W=F&&C[Symbol.toStringTag]||C.constructor.name||"Object";return W}}function NC(C){try{return Bv(C),!1}catch{return!0}}function Bv(C){return""+C}function Hv(C){if(NC(C))return x("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",jC(C)),Bv(C)}var rc=b.ReactCurrentOwner,BC={key:!0,ref:!0,__self:!0,__source:!0},Wv,Xv,Tf;Tf={};function HC(C){if(nc.call(C,"ref")){var F=Object.getOwnPropertyDescriptor(C,"ref").get;if(F&&F.isReactWarning)return!1}return C.ref!==void 0}function WC(C){if(nc.call(C,"key")){var F=Object.getOwnPropertyDescriptor(C,"key").get;if(F&&F.isReactWarning)return!1}return C.key!==void 0}function XC(C,F){if(typeof C.ref=="string"&&rc.current&&F&&rc.current.stateNode!==F){var W=L(rc.current.type);Tf[W]||(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',L(rc.current.type),C.ref),Tf[W]=!0)}}function zC(C,F){{var W=function(){Wv||(Wv=!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)",F))};W.isReactWarning=!0,Object.defineProperty(C,"key",{get:W,configurable:!0})}}function VC(C,F){{var W=function(){Xv||(Xv=!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)",F))};W.isReactWarning=!0,Object.defineProperty(C,"ref",{get:W,configurable:!0})}}var GC=function(C,F,W,Q,bt,Tt,ft){var lt={$$typeof:t,type:C,key:F,ref:W,props:ft,_owner:Tt};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:Q}),Object.defineProperty(lt,"_source",{configurable:!1,enumerable:!1,writable:!1,value:bt}),Object.freeze&&(Object.freeze(lt.props),Object.freeze(lt)),lt};function YC(C,F,W,Q,bt){{var Tt,ft={},lt=null,Ve=null;W!==void 0&&(Hv(W),lt=""+W),WC(F)&&(Hv(F.key),lt=""+F.key),HC(F)&&(Ve=F.ref,XC(F,bt));for(Tt in F)nc.call(F,Tt)&&!BC.hasOwnProperty(Tt)&&(ft[Tt]=F[Tt]);if(C&&C.defaultProps){var qt=C.defaultProps;for(Tt in qt)ft[Tt]===void 0&&(ft[Tt]=qt[Tt])}if(lt||Ve){var ee=typeof C=="function"?C.displayName||C.name||"Unknown":C;lt&&zC(ft,ee),Ve&&VC(ft,ee)}return GC(C,lt,Ve,bt,Q,rc.current,ft)}}var Ef=b.ReactCurrentOwner,zv=b.ReactDebugCurrentFrame;function sh(C){if(C){var F=C._owner,W=nd(C.type,C._source,F?F.type:null);zv.setExtraStackFrame(W)}else zv.setExtraStackFrame(null)}var kf;kf=!1;function Mf(C){return typeof C=="object"&&C!==null&&C.$$typeof===t}function Vv(){{if(Ef.current){var C=L(Ef.current.type);if(C)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+
|
|
23
|
+
Check the render method of \``+C+"`."}return""}}function UC(C){return""}var Gv={};function qC(C){{var F=Vv();if(!F){var W=typeof C=="string"?C:C.displayName||C.name;W&&(F=`
|
|
24
24
|
|
|
25
|
-
Check the top-level render call using <`+W+">.")}return F}}function
|
|
25
|
+
Check the top-level render call using <`+W+">.")}return F}}function Yv(C,F){{if(!C._store||C._store.validated||C.key!=null)return;C._store.validated=!0;var W=qC(F);if(Gv[W])return;Gv[W]=!0;var Q="";C&&C._owner&&C._owner!==Ef.current&&(Q=" It was passed a child from "+L(C._owner.type)+"."),sh(C),x('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',W,Q),sh(null)}}function Uv(C,F){{if(typeof C!="object")return;if(Af(C))for(var W=0;W<C.length;W++){var Q=C[W];Mf(Q)&&Yv(Q,F)}else if(Mf(C))C._store&&(C._store.validated=!0);else if(C){var bt=_(C);if(typeof bt=="function"&&bt!==C.entries)for(var Tt=bt.call(C),ft;!(ft=Tt.next()).done;)Mf(ft.value)&&Yv(ft.value,F)}}}function $C(C){{var F=C.type;if(F==null||typeof F=="string")return;var W;if(typeof F=="function")W=F.propTypes;else if(typeof F=="object"&&(F.$$typeof===h||F.$$typeof===d))W=F.propTypes;else return;if(W){var Q=L(F);LC(W,C.props,"prop",Q,C)}else if(F.PropTypes!==void 0&&!kf){kf=!0;var bt=L(F);x("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",bt||"Unknown")}typeof F.getDefaultProps=="function"&&!F.getDefaultProps.isReactClassApproved&&x("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function KC(C){{for(var F=Object.keys(C.props),W=0;W<F.length;W++){var Q=F[W];if(Q!=="children"&&Q!=="key"){sh(C),x("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",Q),sh(null);break}}C.ref!==null&&(sh(C),x("Invalid attribute `ref` supplied to `React.Fragment`."),sh(null))}}var qv={};function $v(C,F,W,Q,bt,Tt){{var ft=I(C);if(!ft){var lt="";(C===void 0||typeof C=="object"&&C!==null&&Object.keys(C).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 Ve=UC();Ve?lt+=Ve:lt+=Vv();var qt;C===null?qt="null":Af(C)?qt="array":C!==void 0&&C.$$typeof===t?(qt="<"+(L(C.type)||"Unknown")+" />",lt=" Did you accidentally export a JSX literal instead of a component?"):qt=typeof C,x("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",qt,lt)}var ee=YC(C,F,W,bt,Tt);if(ee==null)return ee;if(ft){var Rs=F.children;if(Rs!==void 0)if(Q)if(Af(Rs)){for(var ih=0;ih<Rs.length;ih++)Uv(Rs[ih],C);Object.freeze&&Object.freeze(Rs)}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 Uv(Rs,C)}if(nc.call(F,"key")){var Da=L(C),ss=Object.keys(F).filter(function(sA){return sA!=="key"}),Of=ss.length>0?"{key: someKey, "+ss.join(": ..., ")+": ...}":"{key: someKey}";if(!qv[Da+Of]){var eA=ss.length>0?"{"+ss.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(),Oi("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const My={};let Rp;const oi=()=>Rp||(Rp={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new ky,dispose(){},copyPasteData:My}),jo=()=>oi().document,yc=()=>oi().window,Fp=()=>{var a;return Math.max((a=dt.devicePixelRatio)!==null&&a!==void 0?a:yc().devicePixelRatio,1)},uh=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)]}},Id="6.4.3";function dr(){}const Cn=Math.PI/2,Pi=2*Math.PI,jd=Math.PI/180,Re=Object.freeze([1,0,0,1,0,0]),Nd=16,An=.4477152502,st="center",mt="left",qe="top",Bd="bottom",Vt="right",Fe="none",Hd=/\r?\n/,Lp="moving",_c="scaling",Ip="rotating",Wd="rotate",jp="skewing",dh="resizing",Oy="modifyPoly",Py="modifyPath",wc="changed",xc="scale",Le="scaleX",ns="scaleY",No="skewX",Bo="skewY",Gt="fill",Ie="stroke",Sc="modified",Ho="json",Xd="svg",V=new class{constructor(){this[Ho]=new Map,this[Xd]=new Map}has(a){return this[Ho].has(a)}getClass(a){const t=this[Ho].get(a);if(!t)throw new ri("No class registered for ".concat(a));return t}setClass(a,t){t?this[Ho].set(t,a):(this[Ho].set(a.type,a),this[Ho].set(a.type.toLowerCase(),a))}getSVGClass(a){return this[Xd].get(a)}setSVGClass(a,t){this[Xd].set(t??a.type.toLowerCase(),a)}},Cc=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 Dy{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=(a,t)=>{const e=a.indexOf(t);return e!==-1&&a.splice(e,1),a},Fs=a=>{if(a===0)return 1;switch(Math.abs(a)/Cn){case 1:case 3:return 0;case 2:return-1}return Math.cos(a)},Ls=a=>{if(a===0)return 0;const t=a/Cn,e=Math.sign(a);switch(t){case 1:return e;case 2:return 0;case 3:return-e}return Math.sin(a)};class D{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;typeof t=="object"?(this.x=t.x,this.y=t.y):(this.x=t,this.y=e)}add(t){return new D(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new D(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new D(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new D(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new D(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new D(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new D(this.x/t.x,this.y/t.y)}scalarDivide(t){return new D(this.x/t,this.y/t)}scalarDivideEquals(t){return this.x/=t,this.y/=t,this}eq(t){return this.x===t.x&&this.y===t.y}lt(t){return this.x<t.x&&this.y<t.y}lte(t){return this.x<=t.x&&this.y<=t.y}gt(t){return this.x>t.x&&this.y>t.y}gte(t){return this.x>=t.x&&this.y>=t.y}lerp(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:.5;return e=Math.max(Math.min(1,e),0),new D(this.x+(t.x-this.x)*e,this.y+(t.y-this.y)*e)}distanceFrom(t){const e=this.x-t.x,s=this.y-t.y;return Math.sqrt(e*e+s*s)}midPointFrom(t){return this.lerp(t)}min(t){return new D(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new D(Math.max(this.x,t.x),Math.max(this.y,t.y))}toString(){return"".concat(this.x,",").concat(this.y)}setXY(t,e){return this.x=t,this.y=e,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setFromPoint(t){return this.x=t.x,this.y=t.y,this}swap(t){const e=this.x,s=this.y;this.x=t.x,this.y=t.y,t.x=e,t.y=s}clone(){return new D(this.x,this.y)}rotate(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:zd;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 zd=new D(0,0),Ac=a=>!!a&&Array.isArray(a._objects);function Np(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 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 o=i-1;o>=0;--o)if(s.isOverlapping(this._objects[o])){r=o;break}}else r=i-1;return r}findNewUpperIndex(s,i,n){let r;if(n){r=i;for(let o=i+1;o<this._objects.length;++o)if(s.isOverlapping(this._objects[o])){r=o;break}}else r=i+1;return r}collectObjects(s){let{left:i,top:n,width:r,height:o}=s,{includeIntersecting:h=!0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const l=[],u=new D(i,n),d=u.add(new D(r,o));for(let f=this._objects.length-1;f>=0;f--){const g=this._objects[f];g.selectable&&g.visible&&(h&&g.intersectsWithRect(u,d)||g.isContainedWithinRect(u,d)||h&&g.containsPoint(u)||h&&g.containsPoint(d))&&l.push(g)}return l}}return t}class Bp extends Dy{_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(a){return yc().requestAnimationFrame(a)}function Hp(a){return yc().cancelAnimationFrame(a)}let Ry=0;const Tn=()=>Ry++,Ut=()=>{const a=jo().createElement("canvas");if(!a||a.getContext===void 0)throw new ri("Failed to create `canvas` element");return a},Wp=()=>jo().createElement("img"),Vd=(a,t,e)=>a.toDataURL("image/".concat(t),e),Wt=a=>a*jd,En=a=>a/jd,Xp=a=>a.every((t,e)=>t===Re[e]),xe=(a,t,e)=>new D(a).transform(t,e),$e=a=>{const t=1/(a[0]*a[3]-a[1]*a[2]),e=[t*a[3],-t*a[1],-t*a[2],t*a[0],0,0],{x:s,y:i}=new D(a[4],a[5]).transform(e,!0);return e[4]=-s,e[5]=-i,e},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]],Tc=(a,t)=>a.reduceRight((e,s)=>s&&e?Yt(s,e,t):s||e,void 0)||Re.concat(),zp=a=>{let[t,e]=a;return Math.atan2(e,t)},gr=a=>{const t=zp(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:En(t),scaleX:s,scaleY:i,skewX:En(n),skewY:0,translateX:a[4]||0,translateY:a[5]||0}},Wo=function(a){return[1,0,0,1,a,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function Xo(){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=Wt(a),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 Ec=function(a){return[a,0,0,arguments.length>1&&arguments[1]!==void 0?arguments[1]:a,0,0]},Vp=a=>Math.tan(Wt(a)),Gd=a=>[1,0,Vp(a),1,0,0],Ud=a=>[1,Vp(a),0,1,0,0],gh=a=>{let{scaleX:t=1,scaleY:e=1,flipX:s=!1,flipY:i=!1,skewX:n=0,skewY:r=0}=a,o=Ec(s?-t:t,i?-e:e);return n&&(o=Yt(o,Gd(n),!0)),r&&(o=Yt(o,Ud(r),!0)),o},Gp=a=>{const{translateX:t=0,translateY:e=0,angle:s=0}=a;let i=Wo(t,e);s&&(i=Yt(i,Xo({angle:s})));const n=gh(a);return Xp(n)||(i=Yt(i,n)),i},ph=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 Ld("loadImage"));const n=Wp();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 ri("Error loading ".concat(n.src)))},e&&(n.crossOrigin=e),n.src=a):o()})},zo=function(a){let{signal:t,reviver:e=dr}=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=>V.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)})})},mh=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&&V.has(o.type)?zo([o],{signal:t}).then(h=>{let[l]=h;return i.push(l),l}):o),r=Object.keys(a);Promise.all(n).then(o=>o.reduce((h,l,u)=>(h[r[u]]=l,h),{})).then(e).catch(o=>{i.forEach(h=>{h.dispose&&h.dispose()}),s(o)}).finally(()=>{t&&t.removeEventListener("abort",s)})})},pr=function(a){return(arguments.length>1&&arguments[1]!==void 0?arguments[1]:[]).reduce((t,e)=>(e in a&&(t[e]=a[e]),t),{})},Yd=(a,t)=>Object.keys(a).reduce((e,s)=>(t(a[s],s,a)&&(e[s]=a[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"},qd=(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),Yp=(a,t,e,s)=>{a/=255,t/=255,e/=255;const i=Math.max(a,t,e),n=Math.min(a,t,e);let r,o;const h=(i+n)/2;if(i===n)r=o=0;else{const l=i-n;switch(o=h>.5?l/(2-i-n):l/(i+n),i){case a:r=(t-e)/l+(t<e?6:0);break;case t:r=(e-a)/l+2;break;case e:r=(a-t)/l+4}r/=6}return[Math.round(360*r),Math.round(100*o),Math.round(100*h),s]},qp=function(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"1";return parseFloat(a)/(a.endsWith("%")?100:1)},kc=a=>Math.min(Math.round(a),255).toString(16).toUpperCase().padStart(2,"0"),$p=a=>{let[t,e,s,i=1]=a;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]=Yp(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(s,"%)")}toHsla(){const[t,e,s,i]=Yp(...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(kc(t)).concat(kc(e)).concat(kc(s)).concat(kc(Math.round(255*i)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource($p(this.getSource())),this}toBlackWhite(t){const[e,,,s]=$p(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((o,h)=>Math.round(.5*o+.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 o=parseFloat(r);return r.endsWith("%")?Math.round(2.55*o):o});return[s,i,n,qp(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,o,h;if(i===0)r=o=h=n;else{const l=n<=.5?n*(i+1):n+i-n*i,u=2*n-l;r=qd(u,l,s+1/3),o=qd(u,l,s),h=qd(u,l,s-1/3)}return[Math.round(255*r),Math.round(255*o),Math.round(255*h),qp(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,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")?En(s):e.includes("turn")?360*s:s}}const Dt=(a,t)=>parseFloat(Number(a).toFixed(t)),je=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Nd;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}},$d=a=>{const[t,e]=a.trim().split(" "),[s,i]=(n=t)&&n!==Fe?[n.slice(1,4),n.slice(5,8)]:n===Fe?[n,n]:["Mid","Mid"];var n;return{meetOrSlice:e||"meet",alignX:s,alignY:i}},vh=a=>"matrix("+a.map(t=>Dt(t,dt.NUM_FRACTION_DIGITS)).join(" ")+")",bh=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 yt(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,'" '):"")},bs=a=>!!a&&a.toLive!==void 0,Kp=a=>!!a&&typeof a.toObject=="function",Jp=a=>!!a&&a.offsetX!==void 0&&"source"in a,Qp=a=>!!a&&typeof a._renderText=="function",mr=a=>!!a&&"multiSelectionStacking"in a;function Zp(a){const t=a&&Is(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 Is=a=>a.ownerDocument||null,tm=a=>{var t;return((t=a.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null},em=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))},Kd=(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 sm(a){return a.onselectstart!==void 0&&(a.onselectstart=()=>!1),a.style.userSelect=Fe,a}class im{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&&jo().getElementById(t)||Ut();var s;if(e.hasAttribute("data-fabric"))throw new ri("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;em(s,i,t,e)}setCSSDimensions(t){Kd(this.lower.el,t)}calcOffset(){return function(t){var e;const s=t&&Is(t),i={left:0,top:0};if(!s)return i;const n=((e=tm(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=Zp(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(){oi().dispose(this.lower.el),delete this.lower}}const Fy={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...Re]};class yh extends Np(Bp){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 yh.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 im(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&&(Oi("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} />`,Of,Da,eA,Da),qv[Da+Of]=!0}}return C===s?KC(ee):$C(ee),ee}}function JC(C,F,W){return $v(C,F,W,!0)}function QC(C,F,W){return $v(C,F,W,!1)}var ZC=QC,tA=JC;uh.Fragment=s,uh.jsx=ZC,uh.jsxs=tA}()),uh}process.env.NODE_ENV==="production"?Sn.exports=Ty():Sn.exports=Ey();var Pp=Sn.exports;function T(o,t,e){return(t=function(s){var i=function(n,r){if(typeof n!="object"||!n)return n;var a=n[Symbol.toPrimitive];if(a!==void 0){var h=a.call(n,r||"default");if(typeof h!="object")return h;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(n)}(s,"string");return typeof i=="symbol"?i:i+""}(t))in o?Object.defineProperty(o,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):o[t]=e,o}function Dp(o,t){var e=Object.keys(o);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(o);t&&(s=s.filter(function(i){return Object.getOwnPropertyDescriptor(o,i).enumerable})),e.push.apply(e,s)}return e}function E(o){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?Dp(Object(e),!0).forEach(function(s){T(o,s,e[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(o,Object.getOwnPropertyDescriptors(e)):Dp(Object(e)).forEach(function(s){Object.defineProperty(o,s,Object.getOwnPropertyDescriptor(e,s))})}return o}function Pt(o,t){if(o==null)return{};var e,s,i=function(r,a){if(r==null)return{};var h={};for(var l in r)if({}.hasOwnProperty.call(r,l)){if(a.indexOf(l)>=0)continue;h[l]=r[l]}return h}(o,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(o);for(s=0;s<n.length;s++)e=n[s],t.indexOf(e)>=0||{}.propertyIsEnumerable.call(o,e)&&(i[e]=o[e])}return i}function Cn(o,t){return t||(t=o.slice(0)),Object.freeze(Object.defineProperties(o,{raw:{value:Object.freeze(t)}}))}class Rp{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 Rp{constructor(o){super(),this.configure(o)}configure(){let o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Object.assign(this,o)}addFonts(){let o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.fontPaths=E(E({},this.fontPaths),o)}removeFonts(){(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).forEach(o=>{delete this.fontPaths[o]})}clearFonts(){this.fontPaths={}}restoreDefaults(o){const t=new Rp,e=(o==null?void 0:o.reduce((s,i)=>(s[i]=t[i],s),{}))||t;this.configure(e)}},Pi=function(o){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return console[o]("fabric",...e)};class ai extends Error{constructor(t,e){super("fabric: ".concat(t),e)}}class Id extends ai{constructor(t){super("".concat(t," 'options.signal' is in 'aborted' state"))}}class ky{}class My extends ky{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(),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?Lp():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=we(t,qe(i));i[0]=e,i[3]=e;const r=we(n,i);i[4]+=s.x-r.x,i[5]+=s.y-r.y,this.setViewportTransform(i)}setZoom(t){this.zoomToPoint(new D(0,0),t)}absolutePan(t){const e=[...this.viewportTransform];return e[4]=-t.x,e[5]=-t.y,this.setViewportTransform(e)}relativePan(t){return this.absolutePan(new D(-t.x-this.viewportTransform[4],-t.y-this.viewportTransform[5]))}getElement(){return this.elements.lower.el}clearContext(t){t.clearRect(0,0,this.width,this.height)}getContext(){return this.elements.lower.ctx}clear(){this.remove(...this.getObjects()),this.backgroundImage=void 0,this.overlayImage=void 0,this.backgroundColor="",this.overlayColor="",this.clearContext(this.getContext()),this.fire("canvas:cleared"),this.renderOnAddRemove&&this.requestRenderAll()}renderAll(){this.cancelRequestedRender(),this.destroyed||this.renderCanvas(this.getContext(),this._objects)}renderAndReset(){this.nextRenderHandle=0,this.renderAll()}requestRenderAll(){this.nextRenderHandle||this.disposed||this.destroyed||(this.nextRenderHandle=fh(()=>this.renderAndReset()))}calcViewportBoundaries(){const t=this.width,e=this.height,s=qe(this.viewportTransform),i=we({x:0,y:0},s),n=we({x:t,y:e},s),r=i.min(n),a=i.max(n);return this.vptCoords={tl:r,tr:new D(a.x,r.y),bl:new D(r.x,a.y),br:a}}cancelRequestedRender(){this.nextRenderHandle&&(Wp(this.nextRenderHandle),this.nextRenderHandle=0)}drawControls(t){}renderCanvas(t,e){if(this.destroyed)return;const s=this.viewportTransform,i=this.clipPath;this.calcViewportBoundaries(),this.clearContext(t),t.imageSmoothingEnabled=this.imageSmoothingEnabled,t.patternQuality="best",this.fire("before:render",{ctx:t}),this._renderBackground(t),t.save(),t.transform(s[0],s[1],s[2],s[3],s[4],s[5]),this._renderObjects(t,e),t.restore(),this.controlsAboveOverlay||this.skipControlsDrawing||this.drawControls(t),i&&(i._set("canvas",this),i.shouldCache(),i._transformDone=!0,i.renderCache({forClipping:!0}),this.drawClipPathOnCanvas(t,i)),this._renderOverlay(t),this.controlsAboveOverlay&&!this.skipControlsDrawing&&this.drawControls(t),this.fire("after:render",{ctx:t}),this.__cleanupTask&&(this.__cleanupTask(),this.__cleanupTask=void 0)}drawClipPathOnCanvas(t,e){const s=this.viewportTransform;t.save(),t.transform(...s),t.globalCompositeOperation="destination-in",e.transform(t),t.scale(1/e.zoomX,1/e.zoomY),t.drawImage(e._cacheCanvas,-e.cacheTranslationX,-e.cacheTranslationY),t.restore()}_renderObjects(t,e){for(let s=0,i=e.length;s<i;++s)e[s]&&e[s].render(t)}_renderBackgroundOrOverlay(t,e){const s=this["".concat(e,"Color")],i=this["".concat(e,"Image")],n=this.viewportTransform,r=this["".concat(e,"Vpt")];if(!s&&!i)return;const a=bs(s);if(s){if(t.save(),t.beginPath(),t.moveTo(0,0),t.lineTo(this.width,0),t.lineTo(this.width,this.height),t.lineTo(0,this.height),t.closePath(),t.fillStyle=a?s.toLive(t):s,r&&t.transform(...n),a){t.transform(1,0,0,1,s.offsetX||0,s.offsetY||0);const h=s.gradientTransform||s.patternTransform;h&&t.transform(...h)}t.fill(),t.restore()}if(i){t.save();const{skipOffscreen:h}=this;this.skipOffscreen=r,r&&t.transform(...n),i.render(t),this.skipOffscreen=h,t.restore()}}_renderBackground(t){this._renderBackgroundOrOverlay(t,"background")}_renderOverlay(t){this._renderBackgroundOrOverlay(t,"overlay")}getCenter(){return{top:this.height/2,left:this.width/2}}getCenterPoint(){return new D(this.width/2,this.height/2)}centerObjectH(t){return this._centerObject(t,new D(this.getCenterPoint().x,t.getCenterPoint().y))}centerObjectV(t){return this._centerObject(t,new D(t.getCenterPoint().x,this.getCenterPoint().y))}centerObject(t){return this._centerObject(t,this.getCenterPoint())}viewportCenterObject(t){return this._centerObject(t,this.getVpCenter())}viewportCenterObjectH(t){return this._centerObject(t,new D(this.getVpCenter().x,t.getCenterPoint().y))}viewportCenterObjectV(t){return this._centerObject(t,new D(t.getCenterPoint().x,this.getVpCenter().y))}getVpCenter(){return we(this.getCenterPoint(),qe(this.viewportTransform))}_centerObject(t,e){t.setXY(e,st,st),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:jd},mr(this,e)),{},{objects:this._objects.filter(n=>!n.excludeFromExport).map(n=>this._toObject(n,t,e))},this.__serializeBgOverlay(t,e)),i?{clipPath:i}:null)}_toObject(t,e,s){let i;this.includeDefaultValues||(i=t.includeDefaultValues,t.includeDefaultValues=!1);const n=t[e](s);return this.includeDefaultValues||(t.includeDefaultValues=!!i),n}__serializeBgOverlay(t,e){const s={},i=this.backgroundImage,n=this.overlayImage,r=this.backgroundColor,a=this.overlayColor;return bs(r)?r.excludeFromExport||(s.background=r.toObject(e)):r&&(s.background=r),bs(a)?a.excludeFromExport||(s.overlay=a.toObject(e)):a&&(s.overlay=a),i&&!i.excludeFromExport&&(s.backgroundImage=this._toObject(i,t,e)),n&&!n.excludeFromExport&&(s.overlayImage=this._toObject(n,t,e)),s}toSVG(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;t.reviver=e;const s=[];return this._setSVGPreamble(s,t),this._setSVGHeader(s,t),this.clipPath&&s.push('<g clip-path="url(#'.concat(this.clipPath.clipPathId,`)" >
|
|
33
33
|
`)),this._setSVGBgOverlayColor(s,"background"),this._setSVGBgOverlayImage(s,"backgroundImage",e),this._setSVGObjects(s,e),this.clipPath&&s.push(`</g>
|
|
34
34
|
`),this._setSVGBgOverlayColor(s,"overlay"),this._setSVGBgOverlayImage(s,"overlayImage",e),s.push("</svg>"),s.join("")}_setSVGPreamble(t,e){e.suppressPreamble||t.push('<?xml version="1.0" encoding="',e.encoding||"UTF-8",`" standalone="no" ?>
|
|
35
35
|
`,'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" ',`"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
|
36
|
-
`)}_setSVGHeader(t,e){const s=e.width||"".concat(this.width),i=e.height||"".concat(this.height),n=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 a;if(r)a='viewBox="'.concat(r.x," ").concat(r.y," ").concat(r.width," ").concat(r.height,'" ');else if(this.svgViewportTransformation){const h=this.viewportTransform;a='viewBox="'.concat(Dt(-h[4]/h[0],n)," ").concat(Dt(-h[5]/h[3],n)," ").concat(Dt(this.width/h[0],n)," ").concat(Dt(this.height/h[3],n),'" ')}else a='viewBox="0 0 '.concat(this.width," ").concat(this.height,'" ');t.push("<svg ",'xmlns="http://www.w3.org/2000/svg" ','xmlns:xlink="http://www.w3.org/1999/xlink" ','version="1.1" ','width="',s,'" ','height="',i,'" ',a,`xml:space="preserve">
|
|
37
|
+
`,"<desc>Created with Fabric.js ",jd,`</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(En()),'<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(bs(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?
|
|
42
|
+
`)):""}createSVGRefElementsMarkup(){return["background","overlay"].map(t=>{const e=this["".concat(t,"Color")];if(bs(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?bh(i):""})}}).join("")}createSVGFontFacesMarkup(){const t=[],e={},s=dt.fontPaths;this._objects.forEach(function n(r){t.push(r),Tc(r)&&r._objects.forEach(n)}),t.forEach(n=>{if(!Zp(n))return;const{styles:r,fontFamily:a}=n;!e[a]&&s[a]&&(e[a]=!0,r&&Object.values(r).forEach(h=>{Object.values(h).forEach(l=>{let{fontFamily:u=""}=l;!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(bs(s)){const i=s.repeat||"",n=this.width,r=this.height,
|
|
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(bs(s)){const i=s.repeat||"",n=this.width,r=this.height,a=this["".concat(e,"Vpt")]?bh(qe(this.viewportTransform)):"";t.push('<rect transform="'.concat(a," translate(").concat(n/2,",").concat(r/2,')" x="').concat(s.offsetX-n/2,'" y="').concat(s.offsetY-r/2,'" width="').concat(i!=="repeat-y"&&i!=="no-repeat"||!Qp(s)?n:s.source.width,'" height="').concat(i!=="repeat-x"&&i!=="no-repeat"||!Qp(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 ai("`json` is undefined"));const i=typeof t=="string"?JSON.parse(t):t,{objects:n=[],backgroundImage:r,background:a,overlayImage:h,overlay:l,clipPath:u}=i,d=this.renderOnAddRemove;return this.renderOnAddRemove=!1,Promise.all([za(n,{reviver:e,signal:s}),vh({backgroundImage:r,backgroundColor:a,overlayImage:h,overlayColor:l,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=Is(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 Gd(this.toCanvasElement(r,t),e,s)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:1,{width:e,height:s,left:i,top:n,filter:r}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const a=(e||this.width)*t,h=(s||this.height)*t,l=this.getZoom(),u=this.width,d=this.height,g=this.skipControlsDrawing,f=l*t,p=this.viewportTransform,m=[f,0,0,f,(p[4]-(i||0))*t,(p[5]-(n||0))*t],_=this.enableRetinaScaling,b=Is({width:a,height:h}),x=r?this._objects.filter(S=>r(S)):this._objects;return this.enableRetinaScaling=!1,this.viewportTransform=m,this.width=a,this.height=h,this.skipControlsDrawing=!0,this.calcViewportBoundaries(),this.renderCanvas(b.getContext("2d"),x),this.viewportTransform=p,this.width=u,this.height=d,this.calcViewportBoundaries(),this.enableRetinaScaling=_,this.skipControlsDrawing=g,b}dispose(){return!this.disposed&&this.elements.cleanupDOM({width:this.width,height:this.height}),Ac.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(_h,"ownDefaults",Ly);const Iy=["touchstart","touchmove","touchend"],rm=o=>{const t=tm(o.target),e=function(s){const i=s.changedTouches;return i&&i[0]?i[0]:s}(o);return new D(e.clientX+t.left,e.clientY+t.top)},Oc=o=>Iy.includes(o.type)||o.pointerType==="touch",Qd=o=>{o.preventDefault(),o.stopPropagation()},hi=o=>{let t=0,e=0,s=0,i=0;for(let n=0,r=o.length;n<r;n++){const{x:a,y:h}=o[n];(a>s||!n)&&(s=a),(a<t||!n)&&(t=a),(h>i||!n)&&(i=h),(h<e||!n)&&(e=h)}return{left:t,top:e,width:s-t,height:i-e}},jy=["translateX","translateY","scaleX","scaleY"],am=(o,t)=>Va(o,Gt(t,o.calcOwnMatrix())),Va=(o,t)=>{const e=pr(t),{translateX:s,translateY:i,scaleX:n,scaleY:r}=e,a=Pt(e,jy),h=new D(s,i);o.flipX=!1,o.flipY=!1,Object.assign(o,a),o.set({scaleX:n,scaleY:r}),o.setPositionByOrigin(h,st,st)},om=o=>{o.scaleX=1,o.scaleY=1,o.skewX=0,o.skewY=0,o.flipX=!1,o.flipY=!1,o.rotate(0)},Zd=o=>({scaleX:o.scaleX,scaleY:o.scaleY,skewX:o.skewX,skewY:o.skewY,angle:o.angle,left:o.left,flipX:o.flipX,flipY:o.flipY,top:o.top}),Pc=(o,t,e)=>{const s=o/2,i=t/2,n=[new D(-s,-i),new D(s,-i),new D(-s,i),new D(s,i)].map(a=>a.transform(e)),r=hi(n);return new D(r.width,r.height)},wh=function(){let o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:De;return Gt(qe(arguments.length>1&&arguments[1]!==void 0?arguments[1]:De),o)},br=function(o){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:De,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:De;return o.transform(wh(t,e))},hm=function(o){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:De,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:De;return o.transform(wh(t,e),!0)},tg=(o,t,e)=>{const s=wh(t,e);return Va(o,Gt(s,o.calcOwnMatrix())),s},lm=(o,t)=>{var e;const{transform:{target:s}}=t;(e=s.canvas)===null||e===void 0||e.fire("object:".concat(o),E(E({},t),{},{target:s})),s.fire(o,t)},Ny={left:-.5,top:-.5,center:0,bottom:.5,right:.5},Kt=o=>typeof o=="string"?Ny[o]:o-.5,Dc="not-allowed";function cm(o){return Kt(o.originX)===Kt(st)&&Kt(o.originY)===Kt(st)}function um(o){return .5-Kt(o)}const Ns=(o,t)=>o[t],dm=(o,t,e,s)=>({e:o,transform:t,pointer:new D(e,s)});function gm(o,t){const e=o.getTotalAngle()+kn(Math.atan2(t.y,t.x))+360;return Math.round(e%360/45)}function eg(o,t,e,s,i){var n;let{target:r,corner:a}=o;const h=r.controls[a],l=((n=r.canvas)===null||n===void 0?void 0:n.getZoom())||1,u=r.padding/l,d=function(g,f,p,m){const _=g.getRelativeCenterPoint(),b=p!==void 0&&m!==void 0?g.translateToGivenOrigin(_,st,st,p,m):new D(g.left,g.top);return(g.angle?f.rotate(-Wt(g.angle),_):f).subtract(b)}(r,new D(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 By=(o,t,e,s)=>{const{target:i,offsetX:n,offsetY:r}=t,a=e-n,h=s-r,l=!Ns(i,"lockMovementX")&&i.left!==a,u=!Ns(i,"lockMovementY")&&i.top!==h;return l&&i.set(mt,a),u&&i.set(Ue,h),(l||u)&&lm(Ip,dm(o,t,e,s)),l||u};class fm{getSvgStyles(t){const e=this.fillRule?this.fillRule:"nonzero",s=this.strokeWidth?this.strokeWidth:"0",i=this.strokeDashArray?this.strokeDashArray.join(" "):Re,n=this.strokeDashOffset?this.strokeDashOffset:"0",r=this.strokeLineCap?this.strokeLineCap:"butt",a=this.strokeLineJoin?this.strokeLineJoin:"miter",h=this.strokeMiterLimit?this.strokeMiterLimit:"4",l=this.opacity!==void 0?this.opacity:"1",u=this.visible?"":" visibility: hidden;",d=t?"":this.getSvgFilter(),g=yh($t,this.fill);return[yh(Le,this.stroke),"stroke-width: ",s,"; ","stroke-dasharray: ",i,"; ","stroke-linecap: ",r,"; ","stroke-dashoffset: ",n,"; ","stroke-linejoin: ",a,"; ","stroke-miterlimit: ",h,"; ",g,"fill-rule: ",e,"; ","opacity: ",l,";",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(bh(s));return"".concat(i).concat(e,'" ')}_toSVG(t){return[""]}toSVG(t){return this._createBaseSVGMarkup(this._toSVG(t),{reviver:t})}toClipPathSVG(t){return" "+this._createBaseClipPathSVGMarkup(this._toSVG(t),{reviver:t})}_createBaseClipPathSVGMarkup(t){let{reviver:e,additionalTransform:s=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const i=[this.getSvgTransform(!0,s),this.getSvgCommons()].join(""),n=t.indexOf("COMMON_PARTS");return t[n]=i,e?e(t.join("")):t.join("")}_createBaseSVGMarkup(t){let{noStyle:e,reviver:s,withShadow:i,additionalTransform:n}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const r=e?"":'style="'.concat(this.getSvgStyles(),'" '),a=i?'style="'.concat(this.getSvgFilter(),'" '):"",h=this.clipPath,l=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 _;h&&(h.clipPathId="CLIPPATH_".concat(En()),_='<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,l,e?"":this.addPaintOrder()," ",n?'transform="'.concat(n,'" '):""].join("");return t[m]=b,bs(
|
|
52
|
+
`)),u&&p.push("<g ",a,this.getSvgCommons(),` >
|
|
53
|
+
`),p.push("<g ",this.getSvgTransform(!1),u?"":a+this.getSvgCommons(),` >
|
|
54
|
+
`);const b=[r,l,e?"":this.addPaintOrder()," ",n?'transform="'.concat(n,'" '):""].join("");return t[m]=b,bs(g)&&p.push(g.toSVG(this)),bs(d)&&p.push(d.toSVG(this)),f&&p.push(f.toSVG(this)),h&&p.push(_),p.push(t.join("")),p.push(`</g>
|
|
55
55
|
`),u&&p.push(`</g>
|
|
56
|
-
`),s?s(p.join("")):p.join("")}addPaintOrder(){return this.paintFirst
|
|
56
|
+
`),s?s(p.join("")):p.join("")}addPaintOrder(){return this.paintFirst!==$t?' paint-order="'.concat(this.paintFirst,'" '):""}}function Rc(o){return new RegExp("^("+o.join("|")+")\\b","i")}var pm;const Bs=String.raw(pm||(pm=Cn(["(?:[-+]?(?:d*.d+|d+.?)(?:[eE][-+]?d+)?)"],["(?:[-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?)"]))),sg="http://www.w3.org/2000/svg",Hy=new RegExp("(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*("+Bs+"(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|"+Bs+"))?\\s+(.*)"),Wy={cx:mt,x:mt,r:"radius",cy:Ue,y:Ue,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"},ig="font-size",ng="clip-path",Xy=Rc(["path","circle","polygon","polyline","ellipse","rect","line","image","text"]),zy=Rc(["symbol","image","marker","pattern","view","svg"]),mm=Rc(["symbol","g","a","svg","clipPath","defs"]),vm=new RegExp("^\\s*("+Bs+"+)\\s*,?\\s*("+Bs+"+)\\s*,?\\s*("+Bs+"+)\\s*,?\\s*("+Bs+"+)\\s*$"),Vy=new D(1,0),bm=new D,rg=(o,t)=>o.rotate(t),Fc=(o,t)=>new D(t).subtract(o),Lc=o=>o.distanceFrom(bm),Ic=(o,t)=>Math.atan2(Ga(o,t),_m(o,t)),ym=o=>Ic(Vy,o),jc=o=>o.eq(bm)?o:o.scalarDivide(Lc(o)),ag=function(o){let t=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];return jc(new D(-o.y,o.x).scalarMultiply(t?1:-1))},Ga=(o,t)=>o.x*t.y-o.y*t.x,_m=(o,t)=>o.x*t.x+o.y*t.y,og=(o,t,e)=>{if(o.eq(t)||o.eq(e))return!0;const s=Ga(t,e),i=Ga(t,o),n=Ga(e,o);return s>=0?i>=0&&n<=0:!(i<=0&&n>=0)},wm="(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?",xm=new RegExp("(?:\\s|^)"+wm+wm+"("+Bs+"?(?:px)?)?(?:\\s?|$)(?:$|\\s)");class Ri{constructor(t){const e=typeof t=="string"?Ri.parseShadow(t):t;Object.assign(this,Ri.ownDefaults,e),this.id=En()}static parseShadow(t){const e=t.trim(),[,s=0,i=0,n=0]=(xm.exec(e)||[]).map(r=>parseFloat(r)||0);return{color:(e.replace(xm,"")||"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=rg(new D(this.offsetX,this.offsetY),Wt(-t.angle)),s=new yt(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=Di.ownDefaults;return this.includeDefaultValues?t:Yd(t,(s,i)=>s!==e[i])}static async fromObject(t){return new this(t)}}T(Di,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),T(Di,"type","shadow"),V.setClass(Di,"shadow");const br=(a,t,e)=>Math.max(a,Math.min(t,e)),Vy=[qe,mt,Le,ns,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",No,Bo],Ri=[Gt,Ie,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],Gy={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:qe,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:Gt,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},hf=(a,t,e,s)=>(a<Math.abs(t)?(a=t,s=e/4):s=t===0&&a===0?e/Pi*Math.asin(1):e/Pi*Math.asin(t/a),{a,c:t,p:e,s}),xm=(a,t,e,s,i)=>a*Math.pow(2,10*(s-=1))*Math.sin((s*i-t)*Pi/e),Sm=(a,t,e,s)=>-e*Math.cos(a/s*Cn)+e+t,lf=(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,Cm=(a,t,e,s)=>e-lf(s-a,0,e,s)+t;var Uy=Object.freeze({__proto__:null,defaultEasing:Sm,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:Cm,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}=hf(i,e,n,1.70158);return-xm(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*Cm(2*a,0,e,s)+t:.5*lf(2*a-s,0,e,s)+.5*e+t,easeInOutCirc:(a,t,e,s)=>(a/=s/2)<1?-e/2*(Math.sqrt(1-a**2)-1)+t:e/2*(Math.sqrt(1-(a-=2)*a)+1)+t,easeInOutCubic:(a,t,e,s)=>(a/=s/2)<1?e/2*a**3+t:e/2*((a-2)**3+2)+t,easeInOutElastic:(a,t,e,s)=>{const i=e;let n=0;if(a===0)return t;if((a/=s/2)===2)return t+e;n||(n=s*(.3*1.5));const{a:r,s:o,p:h,c:l}=hf(i,e,n,1.70158);return a<1?-.5*xm(r,o,h,a,s)+t:r*Math.pow(2,-10*(a-=1))*Math.sin((a*s-o)*Pi/h)*.5+l+t},easeInOutExpo:(a,t,e,s)=>a===0?t:a===s?t+e:(a/=s/2)<1?e/2*2**(10*(a-1))+t:e/2*-(2**(-10*--a)+2)+t,easeInOutQuad:(a,t,e,s)=>(a/=s/2)<1?e/2*a**2+t:-e/2*(--a*(a-2)-1)+t,easeInOutQuart:(a,t,e,s)=>(a/=s/2)<1?e/2*a**4+t:-e/2*((a-=2)*a**3-2)+t,easeInOutQuint:(a,t,e,s)=>(a/=s/2)<1?e/2*a**5+t:e/2*((a-2)**5+2)+t,easeInOutSine:(a,t,e,s)=>-e/2*(Math.cos(Math.PI*a/s)-1)+t,easeInQuad:(a,t,e,s)=>e*(a/=s)*a+t,easeInQuart:(a,t,e,s)=>e*(a/=s)*a**3+t,easeInQuint:(a,t,e,s)=>e*(a/s)**5+t,easeInSine:(a,t,e,s)=>-e*Math.cos(a/s*Cn)+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:lf,easeOutCirc:(a,t,e,s)=>e*Math.sqrt(1-(a=a/s-1)*a)+t,easeOutCubic:(a,t,e,s)=>e*((a/s-1)**3+1)+t,easeOutElastic:(a,t,e,s)=>{const i=e;let n=0;if(a===0)return t;if((a/=s)===1)return t+e;n||(n=.3*s);const{a:r,s:o,p:h,c:l}=hf(i,e,n,1.70158);return r*2**(-10*a)*Math.sin((a*s-o)*Pi/h)+l+t},easeOutExpo:(a,t,e,s)=>a===s?t+e:e*-(2**(-10*a/s)+1)+t,easeOutQuad:(a,t,e,s)=>-e*(a/=s)*(a-2)+t,easeOutQuart:(a,t,e,s)=>-e*((a=a/s-1)*a**3-1)+t,easeOutQuint:(a,t,e,s)=>e*((a/s-1)**5+1)+t,easeOutSine:(a,t,e,s)=>e*Math.sin(a/s*Cn)+t});const Yy=()=>!1;class cf{constructor(t){let{startValue:e,byValue:s,duration:i=500,delay:n=0,easing:r=Sm,onStart:o=dr,onChange:h=dr,onComplete:l=dr,abort:u=Yy,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=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(){Cc.push(this)}unregister(){Cc.remove(this)}abort(){this._state="aborted",this.unregister()}}const qy=["startValue","endValue"];class $y extends cf{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(E(E({},Pt(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 Ky=["startValue","endValue"];class Jy extends cf{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(E(E({},Pt(t,Ky)),{},{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 Qy=["startValue","endValue","easing","onChange","onComplete","abort"],Zy=(a,t,e,s)=>t+e*(1-Math.cos(a/s*Cn)),uf=a=>a&&((t,e,s)=>a(new yt(t).toRgba(),e,s));class t_ extends cf{constructor(t){let{startValue:e,endValue:s,easing:i=Zy,onChange:n,onComplete:r,abort:o}=t,h=Pt(t,Qy);const l=new yt(e).getSource(),u=new yt(s).getSource();super(E(E({},h),{},{startValue:l,byValue:u.map((d,f)=>d-l[f]),easing:i,onChange:uf(n),onComplete:uf(r),abort:uf(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),br(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 df(a){const t=(e=>Array.isArray(e.startValue)||Array.isArray(e.endValue))(a)?new Jy(a):new $y(a);return t.start(),t}function Am(a){const t=new t_(a);return t.start(),t}class Ft{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=Rc(e,s),r=Rc(e,t).divide(n);return i?Math.abs(r.x)===Math.abs(r.y):r.x===r.y&&r.x>=0&&r.x<=1}}static isPointInPolygon(t,e){const s=new D(t).setX(Math.min(t.x-1,...e.map(n=>n.x)));let i=0;for(let n=0;n<e.length;n++){const r=this.intersectSegmentSegment(e[n],e[(n+1)%e.length],t,s);if(r.includes(t))return!0;i+=+(r.status==="Intersection")}return i%2==1}static intersectLineLine(t,e,s,i){let n=!(arguments.length>4&&arguments[4]!==void 0)||arguments[4],r=!(arguments.length>5&&arguments[5]!==void 0)||arguments[5];const o=e.x-t.x,h=e.y-t.y,l=i.x-s.x,u=i.y-s.y,d=t.x-s.x,f=t.y-s.y,g=l*f-u*d,p=o*f-h*d,m=u*o-l*h;if(m!==0){const _=g/m,b=p/m;return(n||0<=_&&_<=1)&&(r||0<=b&&b<=1)?new Ft("Intersection").append(new D(t.x+_*o,t.y+_*h)):new Ft}if(g===0||p===0){const _=n||r||Ft.isPointContained(t,s,i)||Ft.isPointContained(e,s,i)||Ft.isPointContained(s,t,e)||Ft.isPointContained(i,t,e);return new Ft(_?"Coincident":void 0)}return new Ft("Parallel")}static intersectSegmentLine(t,e,s,i){return Ft.intersectLineLine(t,e,s,i,!1,!0)}static intersectSegmentSegment(t,e,s,i){return Ft.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 Ft,r=s.length;for(let o,h,l,u=0;u<r;u++){if(o=s[u],h=s[(u+1)%r],l=Ft.intersectLineLine(t,e,o,h,i,!1),l.status==="Coincident")return l;n.append(...l.points)}return n.points.length>0&&(n.status="Intersection"),n}static intersectSegmentPolygon(t,e,s){return Ft.intersectLinePolygon(t,e,s,!1)}static intersectPolygonPolygon(t,e){const s=new Ft,i=t.length,n=[];for(let r=0;r<i;r++){const o=t[r],h=t[(r+1)%i],l=Ft.intersectSegmentPolygon(o,h,e);l.status==="Coincident"?(n.push(l),s.append(o,h)):s.append(...l.points)}return n.length>0&&n.length===t.length?new Ft("Coincident"):(s.points.length>0&&(s.status="Intersection"),s)}static intersectPolygonRectangle(t,e,s){const i=e.min(s),n=e.max(s),r=new D(n.x,i.y),o=new D(i.x,n.y);return Ft.intersectPolygonPolygon(t,[i,r,n,o])}}class e_ extends Bp{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?xe(t,this.group.calcTransformMatrix()):t}setXY(t,e,s){this.group&&(t=xe(t,$e(this.group.calcTransformMatrix()))),this.setRelativeXY(t,e,s)}getRelativeXY(){return new D(this.left,this.top)}setRelativeXY(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.originX,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.originY;this.setPositionByOrigin(t,e,s)}isStrokeAccountedForInDimensions(){return!1}getCoords(){const{tl:t,tr:e,br:s,bl:i}=this.aCoords||(this.aCoords=this.calcACoords()),n=[t,e,s,i];if(this.group){const r=this.group.calcTransformMatrix();return n.map(o=>xe(o,r))}return n}intersectsWithRect(t,e){return Ft.intersectPolygonRectangle(this.getCoords(),t,e).status==="Intersection"}intersectsWithObject(t){const e=Ft.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 Ft.isPointInPolygon(t,this.getCoords())}isOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return!!this.getCoords().some(s=>s.x<=e.x&&s.x>=t.x&&s.y<=e.y&&s.y>=t.y)||!!this.intersectsWithRect(t,e)||this.containsPoint(t.midPointFrom(e))}isPartiallyOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return this.intersectsWithRect(t,e)?!0:this.getCoords().every(s=>(s.x>=e.x||s.x<=t.x)&&(s.y>=e.y||s.y<=t.y))&&this.containsPoint(t.midPointFrom(e))}getBoundingRect(){return ai(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(Le,t),this._set(ns,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?En(zp(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.viewportTransform)||Re.concat()}calcACoords(){const t=Xo({angle:this.angle}),{x:e,y:s}=this.getRelativeCenterPoint(),i=Wo(e,s),n=Yt(i,t),r=this._getTransformedDimensions(),o=r.x/2,h=r.y/2;return{tl:xe({x:-o,y:-h},n),tr:xe({x:o,y:-h},n),bl:xe({x:-o,y:h},n),br:xe({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,Jt(this.originX),Jt(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=Gp(i);return this.ownMatrixCache={key:t,value:n},n}_getNonTransformedDimensions(){return new D(this.width,this.height).scalarAdd(this.strokeWidth)}_calculateCurrentDimensions(t){return this._getTransformedDimensions(t).transform(this.getViewportTransform(),!0).scalarAdd(2*this.padding)}_getTransformedDimensions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=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 D(r*e.scaleX,o*e.scaleY):Oc(r,o,gh(e)),h.scalarAdd(n)}translateToGivenOrigin(t,e,s,i,n){let r=t.x,o=t.y;const h=Jt(i)-Jt(e),l=Jt(n)-Jt(s);if(h||l){const u=this._getTransformedDimensions();r+=h*u.x,o+=l*u.y}return new D(r,o)}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?xe(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,qe)}}const s_=["type"],i_=["extraParam"];let Fi=class rd extends e_{static getDefaults(){return rd.ownDefaults}get type(){const t=this.constructor.type;return t==="FabricObject"?"object":t.toLowerCase()}set type(t){Oi("warn","Setting type has no effect",t)}constructor(t){super(),T(this,"_cacheContext",null),Object.assign(this,rd.ownDefaults),this.setOptions(t)}_createCacheCanvas(){this._cacheCanvas=Ut(),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]=uh.limitDimsByArea(r),l=br(n,o,i),u=br(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,o=s.zoomX,h=s.zoomY,l=n!==t.width||r!==t.height,u=this.zoomX!==o||this.zoomY!==h;if(!t||!e)return!1;let d,f,g=l||u,p=0,m=0,_=!1;if(l){const b=this._cacheCanvas.width,x=this._cacheCanvas.height,C=n>b||r>x;_=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 Qp(this)&&this.path&&(g=!0,_=!0,p+=this.getHeightOfLine(0)*this.zoomX,m+=this.getHeightOfLine(0)*this.zoomY),!!g&&(_?(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,f=s.y/2,this.cacheTranslationX=Math.round(t.width/2-d)+d,this.cacheTranslationY=Math.round(t.height/2-f)+f,e.translate(this.cacheTranslationX,this.cacheTranslationY),e.scale(o,h),this.zoomX=o,this.zoomY=h,!0)}setOptions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this._setOptions(t)}transform(t){const e=this.group&&!this.group._transformDone||this.group&&this.canvas&&t===this.canvas.contextTop,s=this.calcTransformMatrix(!e);t.transform(s[0],s[1],s[2],s[3],s[4],s[5])}getObjectScaling(){if(!this.group)return new D(Math.abs(this.scaleX),Math.abs(this.scaleY));const t=gr(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!==Le&&t!==ns||(e=this._constrainScale(e)),t===Le&&e<0?(this.flipX=!this.flipX,e*=-1):t==="scaleY"&&e<0?(this.flipY=!this.flipY,e*=-1):t!=="shadow"||!e||e instanceof Di||(e=new Di(e));const s=this[t]!==e;return this[t]=e,s&&this.constructor.cacheProperties.includes(t)&&(this.dirty=!0),this.parent&&(this.dirty||s&&this.constructor.stateProperties.includes(t))&&this.parent._set("dirty",!0),this}isNotVisible(){return this.opacity===0||!this.width&&!this.height&&this.strokeWidth===0||!this.visible}render(t){this.isNotVisible()||this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(t.save(),this._setupCompositeOperation(t),this.drawSelectionBackground(t),this.transform(t),this._setOpacity(t),this._setShadow(t),this.shouldCache()?(this.renderCache(),this.drawCacheOnCanvas(t)):(this._removeCacheCanvas(),this.drawObject(t),this.dirty=!1),t.restore())}drawSelectionBackground(t){}renderCache(t){t=t||{},this._cacheCanvas&&this._cacheContext||this._createCacheCanvas(),this.isCacheDirty()&&this._cacheContext&&(this.drawObject(this._cacheContext,t.forClipping),this.dirty=!1)}_removeCacheCanvas(){this._cacheCanvas=void 0,this._cacheContext=null}hasStroke(){return this.stroke&&this.stroke!=="transparent"&&this.strokeWidth!==0}hasFill(){return this.fill&&this.fill!=="transparent"}needsItsOwnCache(){return!!(this.paintFirst===Ie&&this.hasFill()&&this.hasStroke()&&this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.needsItsOwnCache()||this.objectCaching&&(!this.parent||!this.parent.isOnACache()),this.ownCaching}willDrawShadow(){return!!this.shadow&&(this.shadow.offsetX!==0||this.shadow.offsetY!==0)}drawClipPathOnCache(t,e){if(t.save(),e.inverted?t.globalCompositeOperation="destination-out":t.globalCompositeOperation="destination-in",e.absolutePositioned){const s=$e(this.calcTransformMatrix());t.transform(s[0],s[1],s[2],s[3],s[4],s[5])}e.transform(t),t.scale(1/e.zoomX,1/e.zoomY),t.drawImage(e._cacheCanvas,-e.cacheTranslationX,-e.cacheTranslationY),t.restore()}drawObject(t,e){const s=this.fill,i=this.stroke;e?(this.fill="black",this.stroke="",this._setClippingProperties(t)):this._renderBackground(t),this._render(t),this._drawClipPath(t,this.clipPath),this.fill=s,this.stroke=i}_drawClipPath(t,e){e&&(e._set("canvas",this.canvas),e.shouldCache(),e._transformDone=!0,e.renderCache({forClipping:!0}),this.drawClipPathOnCache(t,e))}drawCacheOnCanvas(t){t.scale(1/this.zoomX,1/this.zoomY),t.drawImage(this._cacheCanvas,-this.cacheTranslationX,-this.cacheTranslationY)}isCacheDirty(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0];if(this.isNotVisible())return!1;const e=this._cacheCanvas,s=this._cacheContext;return!(!e||!s||t||!this._updateCacheCanvas())||!!(this.dirty||this.clipPath&&this.clipPath.absolutePositioned)&&(e&&s&&!t&&(s.save(),s.setTransform(1,0,0,1,0,0),s.clearRect(0,0,e.width,e.height),s.restore()),!0)}_renderBackground(t){if(!this.backgroundColor)return;const e=this._getNonTransformedDimensions();t.fillStyle=this.backgroundColor,t.fillRect(-e.x/2,-e.y/2,e.x,e.y),this._removeShadow(t)}_setOpacity(t){this.group&&!this.group._transformDone?t.globalAlpha=this.getObjectOpacity():t.globalAlpha*=this.opacity}_setStrokeStyles(t,e){const s=e.stroke;s&&(t.lineWidth=e.strokeWidth,t.lineCap=e.strokeLineCap,t.lineDashOffset=e.strokeDashOffset,t.lineJoin=e.strokeLineJoin,t.miterLimit=e.strokeMiterLimit,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)||Re,o=n*i,h=r*i,l=e.nonScaling?new D(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*dt.browserShadowBlurConstant*(o+h)*(l.x+l.y)/4,t.shadowOffsetX=e.offsetX*o*l.x,t.shadowOffsetY=e.offsetY*h*l.y}_removeShadow(t){this.shadow&&(t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0)}_applyPatternGradientTransform(t,e){if(!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===Ie?(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=Ut(),r=this.getCanvasRetinaScaling(),o=i.x/this.scaleX/r,h=i.y/this.scaleY/r;n.width=Math.ceil(o),n.height=Math.ceil(h);const l=n.getContext("2d");l&&(l.beginPath(),l.moveTo(0,0),l.lineTo(o,0),l.lineTo(o,h),l.lineTo(0,h),l.closePath(),l.translate(o/2,h/2),l.scale(i.zoomX/this.scaleX/r,i.zoomY/this.scaleY/r),this._applyPatternGradientTransform(l,e),l.fillStyle=e.toLive(t),l.fill(),t.translate(-this.width/2-this.strokeWidth/2,-this.height/2-this.strokeWidth/2),t.scale(r*this.scaleX/i.zoomX,r*this.scaleY/i.zoomY),t.strokeStyle=(s=l.createPattern(n,"no-repeat"))!==null&&s!==void 0?s:"")}_findCenterFromElement(){return new D(this.left+this.width/2,this.top+this.height/2)}clone(t){const e=this.toObject(t);return this.constructor.fromObject(e)}cloneAsImage(t){const e=this.toCanvasElement(t);return new(V.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=Qd(this),s=this.group,i=this.shadow,n=Math.abs,r=t.enableRetinaScaling?Fp():1,o=(t.multiplier||1)*r,h=t.canvasProvider||(x=>new yh(x,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&om(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&Zd(this,this.getViewportTransform()),this.setCoords();const l=Ut(),u=this.getBoundingRect(),d=this.shadow,f=new D;if(d){const x=d.blur,C=d.nonScaling?new D(1,1):this.getObjectScaling();f.x=2*Math.round(n(d.offsetX)+x)*n(C.x),f.y=2*Math.round(n(d.offsetY)+x)*n(C.y)}const g=u.width+f.x,p=u.height+f.y;l.width=Math.ceil(g),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(o||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 Vd(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(){Cc.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:o,onChange:h,onComplete:l}=s,u=E(E({},s),{},{target:this,startValue:o??i.reduce((d,f)=>d[f],this),endValue:e,abort:r==null?void 0:r.bind(this),onChange:(d,f,g)=>{i.reduce((p,m,_)=>(_===i.length-1&&(p[m]=d),p[m]),this),h&&h(d,f,g)},onComplete:(d,f,g)=>{this.setCoords(),l&&l(d,f,g)}});return n?Am(u):df(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(rd.customProperties,this.constructor.customProperties||[]);let e;const s=dt.NUM_FRACTION_DIGITS,{clipPath:i,fill:n,stroke:r,shadow:o,strokeDashArray:h,left:l,top:u,originX:d,originY:f,width:g,height:p,strokeWidth:m,strokeLineCap:_,strokeDashOffset:b,strokeLineJoin:x,strokeUniform:C,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:U}=this;i&&!i.excludeFromExport&&(e=i.toObject(t.concat("inverted","absolutePositioned")));const X=zt=>Dt(zt,s),Ot=E(E({},pr(this,t)),{},{type:this.constructor.type,version:Id,originX:d,originY:f,left:X(l),top:X(u),width:X(g),height:X(p),fill:Kp(n)?n.toObject():n,stroke:Kp(r)?r.toObject():r,strokeWidth:X(m),strokeDashArray:h&&h.concat(),strokeLineCap:_,strokeDashOffset:b,strokeLineJoin:x,strokeUniform:C,strokeMiterLimit:X(A),scaleX:X(k),scaleY:X(P),angle:X(M),flipX:O,flipY:R,opacity:X(I),shadow:o&&o.toObject(),visible:j,backgroundColor:G,fillRule:L,paintFirst:H,globalCompositeOperation:$,skewX:X(J),skewY:X(U)},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 Yd(t,(i,n)=>{if(n===mt||n===qe||n==="type")return!0;const r=s[n];return i!==r&&!(Array.isArray(i)&&Array.isArray(r)&&i.length===0&&r.length===0)})}toString(){return"#<".concat(this.constructor.type,">")}static _fromObject(t){let e=Pt(t,s_),s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{extraParam:i}=s,n=Pt(s,i_);return mh(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(Fi,"stateProperties",Vy),T(Fi,"cacheProperties",Ri),T(Fi,"ownDefaults",Gy),T(Fi,"type","FabricObject"),T(Fi,"colorProperties",[Gt,Ie,"backgroundColor"]),T(Fi,"customProperties",[]),V.setClass(Fi),V.setClass(Fi,"object");const Uo=(a,t,e)=>(s,i,n,r)=>{const o=t(s,i,n,r);return o&&hm(a,E(E({},um(s,i,n,r)),e)),o};function Yo(a){return(t,e,s,i)=>{const{target:n,originX:r,originY:o}=e,h=n.getRelativeCenterPoint(),l=n.translateToOriginPoint(h,r,o),u=a(t,e,s,i);return n.setPositionByOrigin(l,e.originX,e.originY),u}}const Tm=Uo(dh,Yo((a,t,e,s)=>{const i=tf(t,t.originX,t.originY,e,s);if(Jt(t.originX)===Jt(st)||Jt(t.originX)===Jt(Vt)&&i.x<0||Jt(t.originX)===Jt(mt)&&i.x>0){const{target:n}=t,r=n.strokeWidth/(n.strokeUniform?n.scaleX:1),o=lm(t)?2:1,h=n.width,l=Math.abs(i.x*o/n.scaleX)-r;return n.set("width",Math.max(l,1)),h!==n.width}return!1}));function n_(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?Ie:Gt,l=!o&&(s.cornerStrokeColor||i.cornerStrokeColor);let u,d=t,f=e;a.save(),a.fillStyle=s.cornerColor||i.cornerColor||"",a.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",n>r?(u=n,a.scale(1,r/n),f=e*n/r):r>n?(u=r,a.scale(n/r,1),d=t*r/n):u=n,a.lineWidth=1,a.beginPath(),a.arc(d,f,u/2,0,Pi,!1),a[h](),l&&a.stroke(),a.restore()}function r_(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?Ie:Gt,l=!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.lineWidth=1,a.translate(t,e);const f=i.getTotalAngle();a.rotate(Wt(f)),a["".concat(h,"Rect")](-u,-d,n,r),l&&a.strokeRect(-u,-d,n,r),a.restore()}class Bs{constructor(t){T(this,"visible",!0),T(this,"actionName",xc),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:l}=i;return((n=e.canvas)===null||n===void 0?void 0:n.getActiveObject())===e&&e.isControlVisible(t)&&Ft.isPointInPolygon(s,[r,o,h,l])}getActionHandler(t,e,s){return this.actionHandler}getMouseDownHandler(t,e,s){return this.mouseDownHandler}getMouseUpHandler(t,e,s){return this.mouseUpHandler}cursorStyleHandler(t,e,s){return e.cursorStyle}getActionName(t,e,s){return e.actionName}getVisibility(t,e){var s,i;return(s=(i=t._controlsVisibility)===null||i===void 0?void 0:i[e])!==null&&s!==void 0?s:this.visible}setVisibility(t,e,s){this.visible=t}positionHandler(t,e,s,i){return new D(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(e)}calcCornerCoords(t,e,s,i,n,r){const o=Tc([Wo(s,i),Xo({angle:t}),Ec((n?this.touchSizeX:this.sizeX)||e,(n?this.touchSizeY:this.sizeY)||e)]);return{tl:new D(-.5,-.5).transform(o),tr:new D(.5,-.5).transform(o),br:new D(.5,.5).transform(o),bl:new D(-.5,.5).transform(o)}}render(t,e,s,i,n){((i=i||{}).cornerStyle||n.cornerStyle)==="circle"?n_.call(this,t,e,s,i,n):r_.call(this,t,e,s,i,n)}}const o_=(a,t,e)=>e.lockRotation?Pc:t.cursorStyle,a_=Uo(Ip,Yo((a,t,e,s)=>{let{target:i,ex:n,ey:r,theta:o,originX:h,originY:l}=t;const u=i.translateToOriginPoint(i.getRelativeCenterPoint(),h,l);if(js(i,"lockRotation"))return!1;const d=Math.atan2(r-u.y,n-u.x),f=Math.atan2(s-u.y,e-u.x);let g=En(f-d+o);if(i.snapAngle&&i.snapAngle>0){const m=i.snapAngle,_=i.snapThreshold||m,b=Math.ceil(g/m)*m,x=Math.floor(g/m)*m;Math.abs(g-x)<_?g=x:Math.abs(g-b)<_&&(g=b)}g<0&&(g=360+g),g%=360;const p=i.angle!==g;return i.angle=g,p}));function Em(a,t){const e=t.canvas,s=a[e.uniScaleKey];return e.uniformScaling&&!s||!e.uniformScaling&&s}function km(a,t,e){const s=js(a,"lockScalingX"),i=js(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 h_=["e","se","s","sw","w","nw","n","ne","e"],wh=(a,t,e)=>{const s=Em(a,e);if(km(e,t.x!==0&&t.y===0?"x":t.x===0&&t.y!==0?"y":"",s))return Pc;const i=dm(e,t);return"".concat(h_[i],"-resize")};function ff(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{};const n=t.target,r=i.by,o=Em(a,n);let h,l,u,d,f,g;if(km(n,r,o))return!1;if(t.gestureScale)l=t.scaleX*t.gestureScale,u=t.scaleY*t.gestureScale;else{if(h=tf(t,t.originX,t.originY,e,s),f=r!=="y"?Math.sign(h.x||t.signX||1):1,g=r!=="x"?Math.sign(h.y||t.signY||1):1,t.signX||(t.signX=f),t.signY||(t.signY=g),js(n,"lockScalingFlip")&&(t.signX!==f||t.signY!==g))return!1;if(d=n._getTransformedDimensions(),o&&!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);lm(t)&&(l*=2,u*=2),t.signX!==f&&r!=="y"&&(t.originX=cm(t.originX),l*=-1,t.signX=f),t.signY!==g&&r!=="x"&&(t.originY=cm(t.originY),u*=-1,t.signY=g)}const p=n.scaleX,m=n.scaleY;return r?(r==="x"&&n.set(Le,l),r==="y"&&n.set(ns,u)):(!js(n,"lockScalingX")&&n.set(Le,l),!js(n,"lockScalingY")&&n.set(ns,u)),p!==n.scaleX||m!==n.scaleY}const jc=Uo(_c,Yo((a,t,e,s)=>ff(a,t,e,s))),l_=Uo(_c,Yo((a,t,e,s)=>ff(a,t,e,s,{by:"x"}))),c_=Uo(_c,Yo((a,t,e,s)=>ff(a,t,e,s,{by:"y"}))),u_=["target","ex","ey","skewingSide"],gf={x:{counterAxis:"y",scale:Le,skew:No,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:ns,skew:Bo,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},d_=["ns","nesw","ew","nwse"],f_=(a,t,e)=>{if(t.x!==0&&js(e,"lockSkewingY")||t.y!==0&&js(e,"lockSkewingX"))return Pc;const s=dm(e,t)%4;return"".concat(d_[s],"-resize")};function Mm(a,t,e,s,i){const{target:n}=e,{counterAxis:r,origin:o,lockSkewing:h,skew:l,flip:u}=gf[a];if(js(n,h))return!1;const{origin:d,flip:f}=gf[r],g=Jt(e[d])*(n[f]?-1:1),p=-Math.sign(g)*(n[u]?-1:1),m=.5*-((n[l]===0&&tf(e,st,st,s,i)[a]>0||n[l]>0?1:-1)*p)+.5;return Uo(jp,Yo((b,x,C,A)=>function(k,P,M){let{target:O,ex:R,ey:I,skewingSide:j}=P,G=Pt(P,u_);const{skew:L}=gf[k],H=M.subtract(new D(R,I)).divide(new D(O.scaleX,O.scaleY))[k],$=O[L],J=G[L],U=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)+U,zt=En(Math.atan(Ot));O.set(L,zt);const ee=$!==O[L];if(ee&&k==="y"){const{skewX:Bt,scaleX:At}=O,we=O._getTransformedDimensions({skewY:$}),Ps=O._getTransformedDimensions(),kt=Bt!==0?we.x/Ps.x:1;kt!==1&&O.set(Le,kt*At)}return ee}(a,x,new D(C,A))))(t,E(E({},e),{},{[o]:m,skewingSide:p}),s,i)}const g_=(a,t,e,s)=>Mm("x",a,t,e,s),p_=(a,t,e,s)=>Mm("y",a,t,e,s);function Nc(a,t){return a[t.canvas.altActionKey]}const Bc=(a,t,e)=>{const s=Nc(a,e);return t.x===0?s?No:ns:t.y===0?s?Bo:Le:""},qo=(a,t,e)=>Nc(a,e)?f_(0,t,e):wh(a,t,e),Om=(a,t,e,s)=>Nc(a,t.target)?p_(a,t,e,s):l_(a,t,e,s),Pm=(a,t,e,s)=>Nc(a,t.target)?g_(a,t,e,s):c_(a,t,e,s),Dm=()=>({ml:new Bs({x:-.5,y:0,cursorStyleHandler:qo,actionHandler:Om,getActionName:Bc}),mr:new Bs({x:.5,y:0,cursorStyleHandler:qo,actionHandler:Om,getActionName:Bc}),mb:new Bs({x:0,y:.5,cursorStyleHandler:qo,actionHandler:Pm,getActionName:Bc}),mt:new Bs({x:0,y:-.5,cursorStyleHandler:qo,actionHandler:Pm,getActionName:Bc}),tl:new Bs({x:-.5,y:-.5,cursorStyleHandler:wh,actionHandler:jc}),tr:new Bs({x:.5,y:-.5,cursorStyleHandler:wh,actionHandler:jc}),bl:new Bs({x:-.5,y:.5,cursorStyleHandler:wh,actionHandler:jc}),br:new Bs({x:.5,y:.5,cursorStyleHandler:wh,actionHandler:jc}),mtr:new Bs({x:0,y:-.5,actionHandler:a_,cursorStyleHandler:o_,offsetY:-40,withConnection:!0,actionName:Wd})}),m_=()=>({mr:new Bs({x:.5,y:0,actionHandler:Tm,cursorStyleHandler:qo,actionName:dh}),ml:new Bs({x:-.5,y:0,actionHandler:Tm,cursorStyleHandler:qo,actionName:dh})}),v_=()=>E(E({},Dm()),m_());class xh extends Fi{static getDefaults(){return E(E({},super.getDefaults()),xh.ownDefaults)}constructor(t){super(),Object.assign(this,this.constructor.createControls(),xh.ownDefaults),this.setOptions(t)}static createControls(){return{controls:Dm()}}_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(xc))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=Wo(e.x,e.y),i=Xo({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?gr(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,f)=>{const g=d.positionHandler(l,o,this,d);u[f]=Object.assign(g,this._calcCornerCoords(d,g))}),u}_calcCornerCoords(t,e){const s=this.getTotalAngle();return{corner:t.calcCornerCoords(s,this.cornerSize,e.x,e.y,!1,this),touchCorner:t.calcCornerCoords(s,this.touchCornerSize,e.x,e.y,!0,this)}}setCoords(){super.setCoords(),this.canvas&&(this.oCoords=this.calcOCoords())}forEachControl(t){for(const e in this.controls)t(this.controls[e],e,this)}drawSelectionBackground(t){if(!this.selectionBackgroundColor||this.canvas&&this.canvas._activeObject!==this)return;t.save();const e=this.getRelativeCenterPoint(),s=this._calculateCurrentDimensions(),i=this.getViewportTransform();t.translate(e.x,e.y),t.scale(1/i[0],1/i[3]),t.rotate(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(),o=n.hasBorders,h=n.hasControls,l=Yt(r,this.calcTransformMatrix()),u=gr(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)),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=Oc(this.width,this.height,gh(e)),r=this.isStrokeAccountedForInDimensions()?zd:(this.strokeUniform?new D().scalarAdd(this.canvas?this.canvas.getZoom():1):new D(e.scaleX,e.scaleY)).scalarMultiply(this.strokeWidth);i=n.add(r).scalarAdd(this.borderScaleFactor).scalarAdd(2*this.padding)}else i=this._calculateCurrentDimensions().scalarAdd(this.borderScaleFactor);this._drawBorders(t,i,s)}drawControlsConnectingLines(t,e){let s=!1;t.beginPath(),this.forEachControl((i,n)=>{i.withConnection&&i.getVisibility(this,n)&&(s=!0,t.moveTo(i.x*e.x,i.y*e.y),t.lineTo(i.x*e.x+i.offsetX,i.y*e.y+i.offsetY))}),s&&t.stroke()}drawControls(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};t.save();const s=this.getCanvasRetinaScaling(),{cornerStrokeColor:i,cornerDashArray:n,cornerColor:r}=this,o=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,l)=>{if(h.getVisibility(this,l)){const u=this.oCoords[l];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 Rm(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(xh,"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 Se extends xh{}Rm(Se,[fm]),V.setClass(Se),V.setClass(Se,"object");const Fm=(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 Lm{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=Rc(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 b_=new D;class $o extends Lm{static getOrthogonalRotationFactor(t,e){const s=e?Lc(t,e):bm(t);return Math.abs(s)<Cn?-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=Lc(this.AB,this.AC),this.bisector=Ic(rf(this.AB.eq(b_)?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=of(i),r=$o.getOrthogonalRotationFactor(n,this.bisector);return this.scaleUnitVector(n,s*r)}projectBevel(){const t=[];return(this.alpha%Pi==0?[this.B]:[this.B,this.C]).forEach(e=>{t.push(this.projectOrthogonally(this.A,e)),t.push(this.projectOrthogonally(this.A,e,-this.strokeProjectionMagnitude))}),t}projectMiter(){const t=[],e=Math.abs(this.alpha),s=1/Math.sin(e/2),i=this.scaleUnitVector(this.bisector,-this.strokeProjectionMagnitude*s),n=this.options.strokeUniform?Fc(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return Fc(i)/this.strokeProjectionMagnitude<=n&&t.push(this.applySkew(this.A.add(i))),t.push(...this.projectBevel()),t}projectRoundNoSkew(t,e){const s=[],i=new D($o.getOrthogonalRotationFactor(this.bisector),$o.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=>{af(n,t,e)&&s.push(this.A.add(n))}),s}projectRoundWithSkew(t,e){const s=[],{skewX:i,skewY:n,scaleX:r,scaleY:o,strokeUniform:h}=this.options,l=new D(Math.tan(Wt(i)),Math.tan(Wt(n))),u=this.strokeProjectionMagnitude,d=h?u/o/Math.sqrt(1/o**2+1/r**2*l.y**2):u/Math.sqrt(1+l.y**2),f=new D(Math.sqrt(Math.max(u**2-d**2,0)),d),g=h?u/Math.sqrt(1+l.x**2*(1/o)**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(g,Math.sqrt(Math.max(u**2-g**2,0)));return[p,p.scalarMultiply(-1),f,f.scalarMultiply(-1)].map(m=>this.applySkew(h?m.multiply(this.strokeUniformScalar):m)).forEach(m=>{af(m,t,e)&&s.push(this.applySkew(this.A).add(m))}),s}projectRound(){const t=[];t.push(...this.projectBevel());const e=this.alpha%Pi==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=Go(i,r)>0,h=o?i:n,l=o?n:i;return this.isSkewed()?t.push(...this.projectRoundWithSkew(h,l)):t.push(...this.projectRoundNoSkew(h,l)),t}projectPoints(){switch(this.options.strokeLineJoin){case"miter":return this.projectMiter();case"round":return this.projectRound();default:return this.projectBevel()}}project(){return this.projectPoints().map(t=>({originPoint:this.A,projectedPoint:t,angle:this.alpha,bisector:this.bisector}))}}class Im extends Lm{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(of(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 $o(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(Ic(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 jm=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];const s=[];if(a.length===0)return s;const i=a.reduce((n,r)=>(n[n.length-1].eq(r)||n.push(new D(r)),n),[new D(a[0])]);if(i.length===1)e=!0;else if(!e){const n=i[0],r=((o,h)=>{for(let l=o.length-1;l>=0;l--)if(h(o[l],l,o))return l;return-1})(i,o=>!o.eq(n));i.splice(r+1)}return i.forEach((n,r,o)=>{let h,l;r===0?(l=o[1],h=e?n:o[o.length-1]):r===o.length-1?(h=o[r-1],l=e?n:o[0]):(h=o[r-1],l=o[r+1]),e&&o.length===1?s.push(...new Im(n,n,t).project()):!e||r!==0&&r!==o.length-1?s.push(...new $o(n,h,l,t).project()):s.push(...new Im(n,r===0?l:h,t).project())}),s},pf=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},Nm=a=>a.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">"),Hc=a=>{const t=[];for(let e,s=0;s<a.length;s++)(e=y_(a,s))!==!1&&t.push(e);return t},y_=(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 __=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:Nm,graphemeSplit:Hc});const Wc=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];return a.fill!==t.fill||a.stroke!==t.stroke||a.strokeWidth!==t.strokeWidth||a.fontSize!==t.fontSize||a.fontFamily!==t.fontFamily||a.fontWeight!==t.fontWeight||a.fontStyle!==t.fontStyle||a.textBackgroundColor!==t.textBackgroundColor||a.deltaY!==t.deltaY||e&&(a.overline!==t.overline||a.underline!==t.underline||a.linethrough!==t.linethrough)},Bm=(a,t)=>{const e=t.split(`
|
|
67
|
-
`),s=[];let i=-1,n={};
|
|
68
|
-
`)]}static async fromElement(t,e,s){const i=Li(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,width:o=0,height:h=0,visible:l=!0}=i,u=Pt(i,H_);return new this(E(E(E({},e),u),{},{left:n,top:r,width:o,height:h,visible:!!(l&&o&&h)}))}}T(hi,"type","Rect"),T(hi,"cacheProperties",[...Ri,...$m]),T(hi,"ownDefaults",{rx:0,ry:0}),T(hi,"ATTRIBUTE_NAMES",[...kn,"x","y","rx","ry","width","height"]),V.setClass(hi),V.setSVGClass(hi);const Ii="initialization",zc="added",bf="removed",Vc="imperative",Km=(a,t)=>{const{strokeUniform:e,strokeWidth:s,width:i,height:n,group:r}=t,o=r&&r!==a?_h(r.calcTransformMatrix(),a.calcTransformMatrix()):null,h=o?t.getRelativeCenterPoint().transform(o):t.getRelativeCenterPoint(),l=!t.isStrokeAccountedForInDimensions(),u=e&&l?am(new D(s,s),void 0,a.calcTransformMatrix()):zd,d=!e&&l?s:0,f=Oc(i+d,n+d,Tc([o,t.calcOwnMatrix()],!0)).add(u).scalarDivide(2);return[h.subtract(f),h.add(f)]};class Gc{calcLayoutResult(t,e){if(this.shouldPerformLayout(t))return this.calcBoundingBox(e,t)}shouldPerformLayout(t){let{type:e,prevStrategy:s,strategy:i}=t;return e===Ii||e===Vc||!!s&&i!==s}shouldLayoutClipPath(t){let{type:e,target:{clipPath:s}}=t;return e!==Ii&&s&&!s.absolutePositioned}getInitialSize(t,e){return e.size}calcBoundingBox(t,e){const{type:s,target:i}=e;if(s===Vc&&e.overrides)return e.overrides;if(t.length===0)return;const{left:n,top:r,width:o,height:h}=ai(t.map(d=>Km(i,d)).reduce((d,f)=>d.concat(f),[])),l=new D(o,h),u=new D(n,r).add(l.scalarDivide(2));if(s===Ii){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(Gc,"type","strategy");class yf extends Gc{shouldPerformLayout(t){return!0}}T(yf,"type","fit-content"),V.setClass(yf);const W_=["strategy"],X_=["target","strategy","bubbles","prevStrategy"],Jm="layoutManager";class Sh{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:new yf;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[Sc,Lp,dh,Ip,_c,jp,wc,Oy,Py].map(i=>t.on(i,n=>this.performLayout(i===Sc?{type:"object_modified",trigger:i,e:n,target:s}:{type:"object_modifying",trigger:i,e:n,target:s})))}subscribe(t,e){this.unsubscribe(t,e);const s=this.attachHandlers(t,e);this._subscriptions.set(t,s)}unsubscribe(t,e){(this._subscriptions.get(t)||[]).forEach(s=>s()),this._subscriptions.delete(t)}unsubscribeTargets(t){t.targets.forEach(e=>this.unsubscribe(e,t))}subscribeTargets(t){t.targets.forEach(e=>this.subscribe(e,t))}onBeforeLayout(t){const{target:e,type:s}=t,{canvas:i}=e;if(s===Ii||s===zc?this.subscribeTargets(t):s===bf&&this.unsubscribeTargets(t),e.fire("layout:before",{context:t}),i&&i.fire("object:layout:before",{target:e,context:t}),s===Vc&&t.deep){const n=Pt(t,W_);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===Ii?new D:e.getRelativeCenterPoint(),{center:o,correction:h=new D,relativeCorrection:l=new D}=n,u=r.subtract(o).add(h).transform(i===Ii?Re:$e(e.calcOwnMatrix()),!0).add(l);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===Ii?s.set({left:(r=t.x)!==null&&r!==void 0?r:n.x+i.x*Jt(s.originX),top:(o=t.y)!==null&&o!==void 0?o:n.y+i.y*Jt(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,o=Pt(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 l=s.parent;n&&l!=null&&l.layoutManager&&((o.path||(o.path=[])).push(s),l.layoutManager.performLayout(E(E({},o),{},{target:l}))),s.set("dirty",!0)}dispose(){const{_subscriptions:t}=this;t.forEach(e=>e.forEach(s=>s())),t.clear()}toObject(){return{type:Jm,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}V.setClass(Sh,Jm);const z_=["type","objects","layoutManager"];class V_ extends Sh{performLayout(){}}class li extends Np(Se){static getDefaults(){return E(E({},super.getDefaults()),li.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,li.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 Sh,this.layoutManager.performLayout({type:Ii,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(Oi("error","Group: circular object trees are not supported, this call has no effect"),!1):this._objects.indexOf(t)===-1||(Oi("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(zc,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(zc,n),r}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange(bf,t),t}_onObjectAdded(t){this.enterGroup(t,!0),this.fire("object:added",{target:t}),t.fire("added",{target:this})}_onObjectRemoved(t,e){this.exitGroup(t,e),this.fire("object:removed",{target:t}),t.fire("removed",{target:this})}_onAfterObjectsChange(t,e){this.layoutManager.performLayout({type:t,targets:e,target:this})}_onStackOrderChanged(){this._set("dirty",!0)}_set(t,e){const s=this[t];return super._set(t,e),t==="canvas"&&s!==e&&(this._objects||[]).forEach(i=>{i._set(t,e)}),this}_shouldSetNestedCoords(){return this.subTargetCheck}removeAll(){return this._activeObjects=[],this.remove(...this._objects)}__objectSelectionMonitor(t,e){let{target:s}=e;const i=this._activeObjects;if(t)i.push(s),this._set("dirty",!0);else if(i.length>0){const n=i.indexOf(s);n>-1&&(i.splice(n,1),this._set("dirty",!0))}}_watchObject(t,e){t&&this._watchObject(!1,e),t?(e.on("selected",this.__objectSelectionTracker),e.on("deselected",this.__objectSelectionDisposer)):(e.off("selected",this.__objectSelectionTracker),e.off("deselected",this.__objectSelectionDisposer))}enterGroup(t,e){t.group&&t.group.remove(t),t._set("parent",this),this._enterGroup(t,e)}_enterGroup(t,e){e&&Vo(t,Yt($e(this.calcTransformMatrix()),t.calcTransformMatrix())),this._shouldSetNestedCoords()&&t.setCoords(),t._set("group",this),t._set("canvas",this.canvas),this._watchObject(!0,t);const s=this.canvas&&this.canvas.getActiveObject&&this.canvas.getActiveObject();s&&(s===t||t.isDescendantOf(s))&&this._activeObjects.push(t)}exitGroup(t,e){this._exitGroup(t,e),t._set("parent",void 0),t._set("canvas",void 0)}_exitGroup(t,e){t._set("group",void 0),e||(Vo(t,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=Se.prototype.shouldCache.call(this);if(t){for(let e=0;e<this._objects.length;e++)if(this._objects[e].willDrawShadow())return this.ownCaching=!1,!1}return t}willDrawShadow(){if(super.willDrawShadow())return!0;for(let t=0;t<this._objects.length;t++)if(this._objects[t].willDrawShadow())return!0;return!1}isOnACache(){return this.ownCaching||!!this.parent&&this.parent.isOnACache()}drawObject(t){this._renderBackground(t);for(let s=0;s<this._objects.length;s++){var e;(e=this.canvas)!==null&&e!==void 0&&e.preserveObjectStacking&&this._objects[s].group!==this?(t.save(),t.transform(...$e(this.calcTransformMatrix())),this._objects[s].render(t),t.restore()):this._objects[s].group===this&&this._objects[s].render(t)}this._drawClipPath(t,this.clipPath)}setCoords(){super.setCoords(),this._shouldSetNestedCoords()&&this.forEachObject(t=>t.setCoords())}triggerLayout(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.layoutManager.performLayout(E({target:this,type:Vc},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=hi.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=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={};o=pg(o);for(let r=0;r<e.length;r++){const a=Wc(e[r]);if(o[r])for(let h=0;h<a.length;h++){i++;const l=o[r][h];l&&Object.keys(l).length>0&&(Xc(n,l,!0)?s.push({start:i,end:i+1,style:l}):s[s.length-1].end++),n=l||{}}else i+=a.length,n={}}return s},Wm=(o,t)=>{if(!Array.isArray(o))return pg(o);const e=t.split(Wd),s={};let i=-1,n=0;for(let r=0;r<e.length;r++){const a=Wc(e[r]);for(let h=0;h<a.length;h++)i++,o[n]&&o[n].start<=i&&i<o[n].end&&(s[r]=s[r]||{},s[r][h]=E({},o[n].style),i===o[n].end-1&&n++)}return s},Mn=["display","transform",$t,"fill-opacity","fill-rule","opacity",Le,"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 Xm(o,t){const e=o.nodeName,s=o.getAttribute("class"),i=o.getAttribute("id"),n="(?![a-zA-Z\\-]+)";let r;if(r=new RegExp("^"+e,"i"),t=t.replace(r,""),i&&t.length&&(r=new RegExp("#"+i+n,"i"),t=t.replace(r,"")),s&&t.length){const a=s.split(" ");for(let h=a.length;h--;)r=new RegExp("\\."+a[h]+n,"i"),t=t.replace(r,"")}return t.length===0}function x_(o,t){let e=!0;const s=Xm(o,t.pop());return s&&t.length&&(e=function(i,n){let r,a=!0;for(;i.parentElement&&i.parentElement.nodeType===1&&n.length;)a&&(r=n.pop()),a=Xm(i=i.parentElement,r);return n.length===0}(o,t)),s&&e&&t.length===0}const S_=o=>{var t;return(t=Wy[o])!==null&&t!==void 0?t:o},C_=new RegExp("(".concat(Bs,")"),"gi"),A_=o=>o.replace(C_," $1 ").replace(/,/gi," ").replace(/\s+/gi," ");var zm,Vm,Gm,Ym,Um,qm,$m;const je="(".concat(Bs,")"),T_=String.raw(zm||(zm=Cn(["(skewX)(",")"],["(skewX)\\(","\\)"])),je),E_=String.raw(Vm||(Vm=Cn(["(skewY)(",")"],["(skewY)\\(","\\)"])),je),k_=String.raw(Gm||(Gm=Cn(["(rotate)(","(?: "," ",")?)"],["(rotate)\\(","(?: "," ",")?\\)"])),je,je,je),M_=String.raw(Ym||(Ym=Cn(["(scale)(","(?: ",")?)"],["(scale)\\(","(?: ",")?\\)"])),je,je),O_=String.raw(Um||(Um=Cn(["(translate)(","(?: ",")?)"],["(translate)\\(","(?: ",")?\\)"])),je,je),P_=String.raw(qm||(qm=Cn(["(matrix)("," "," "," "," "," ",")"],["(matrix)\\("," "," "," "," "," ","\\)"])),je,je,je,je,je,je),mg="(?:".concat(P_,"|").concat(O_,"|").concat(k_,"|").concat(M_,"|").concat(T_,"|").concat(E_,")"),D_="(?:".concat(mg,"*)"),R_=String.raw($m||($m=Cn(["^s*(?:","?)s*$"],["^\\s*(?:","?)\\s*$"])),D_),F_=new RegExp(R_),L_=new RegExp(mg),I_=new RegExp(mg,"g");function zc(o){const t=[];if(!(o=A_(o).replace(/\s*([()])\s*/gi,"$1"))||o&&!F_.test(o))return[...De];for(const e of o.matchAll(I_)){const s=L_.exec(e[0]);if(!s)continue;let i=De;const n=s.filter(p=>!!p),[,r,...a]=n,[h,l,u,d,g,f]=a.map(p=>parseFloat(p));switch(r){case"translate":i=Wa(h,l);break;case Xd:i=Xa({angle:h},{x:l,y:u});break;case Sc:i=kc(h,l);break;case Na:i=Yd(h);break;case Ba:i=Ud(h);break;case"matrix":i=[h,l,u,d,g,f]}t.push(i)}return Ec(t)}function j_(o,t,e,s){const i=Array.isArray(t);let n,r=t;if(o!==$t&&o!==Le||t!==Re){if(o==="strokeUniform")return t==="non-scaling-stroke";if(o==="strokeDashArray")r=t===Re?null:t.replace(/,/g," ").split(/\s+/).map(parseFloat);else if(o==="transformMatrix")r=e&&e.transformMatrix?Gt(e.transformMatrix,zc(t)):zc(t);else if(o==="visible")r=t!==Re&&t!=="hidden",e&&e.visible===!1&&(r=!1);else if(o==="opacity")r=parseFloat(t),e&&e.opacity!==void 0&&(r*=e.opacity);else if(o==="textAnchor")r=t==="start"?mt:t==="end"?Vt:st;else if(o==="charSpacing")n=Ie(t,s)/s*1e3;else if(o==="paintFirst"){const a=t.indexOf($t),h=t.indexOf(Le);r=$t,(a>-1&&h>-1&&h<a||a===-1&&h>-1)&&(r=Le)}else{if(o==="href"||o==="xlink:href"||o==="font"||o==="id")return t;if(o==="imageSmoothing")return t==="optimizeQuality";n=i?t.map(Ie):Ie(t,s)}}else r="";return!i&&isNaN(n)?r:n}function N_(o,t){const e=o.match(Hy);if(!e)return;const s=e[1],i=e[3],n=e[4],r=e[5],a=e[6];s&&(t.fontStyle=s),i&&(t.fontWeight=isNaN(parseFloat(i))?i:parseFloat(i)),n&&(t.fontSize=Ie(n)),a&&(t.fontFamily=a),r&&(t.lineHeight=r==="normal"?1:r)}function vg(o,t){o.replace(/;\s*$/,"").split(";").forEach(e=>{if(!e)return;const[s,i]=e.split(":");t[s.trim().toLowerCase()]=i.trim()})}function B_(o){const t={},e=o.getAttribute("style");return e&&(typeof e=="string"?vg(e,t):function(s,i){Object.entries(s).forEach(n=>{let[r,a]=n;a!==void 0&&(i[r.toLowerCase()]=a)})}(e,t)),t}const H_={stroke:"strokeOpacity",fill:"fillOpacity"};function Ii(o,t,e){if(!o)return{};let s,i={},n=Bd;o.parentNode&&mm.test(o.parentNode.nodeName)&&(i=Ii(o.parentElement,t,e),i.fontSize&&(s=n=Ie(i.fontSize)));const r=E(E(E({},t.reduce((l,u)=>{const d=o.getAttribute(u);return d&&(l[u]=d),l},{})),function(l){let u=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},d={};for(const g in u)x_(l,g.split(" "))&&(d=E(E({},d),u[g]));return d}(o,e)),B_(o));r[ng]&&o.setAttribute(ng,r[ng]),r[ig]&&(s=Ie(r[ig],n),r[ig]="".concat(s));const a={};for(const l in r){const u=S_(l),d=j_(u,r[l],i,s);a[u]=d}a&&a.font&&N_(a.font,a);const h=E(E({},i),a);return mm.test(o.nodeName)?h:function(l){const u=xe.getDefaults();return Object.entries(H_).forEach(d=>{let[g,f]=d;if(l[f]===void 0||l[g]==="")return;if(l[g]===void 0){if(!u[g])return;l[g]=u[g]}if(l[g].indexOf("url(")===0)return;const p=new yt(l[g]);l[g]=p.setAlpha(Dt(p.getAlpha()*l[f],2)).toRgba()}),l}(h)}const W_=["left","top","width","height","visible"],Km=["rx","ry"];class li extends xe{static getDefaults(){return E(E({},super.getDefaults()),li.ownDefaults)}constructor(t){super(),Object.assign(this,li.ownDefaults),this.setOptions(t),this._initRxRy()}_initRxRy(){const{rx:t,ry:e}=this;t&&!e?this.ry=t:e&&!t&&(this.rx=e)}_render(t){const{width:e,height:s}=this,i=-e/2,n=-s/2,r=this.rx?Math.min(this.rx,e/2):0,a=this.ry?Math.min(this.ry,s/2):0,h=r!==0||a!==0;t.beginPath(),t.moveTo(i+r,n),t.lineTo(i+e-r,n),h&&t.bezierCurveTo(i+e-Tn*r,n,i+e,n+Tn*a,i+e,n+a),t.lineTo(i+e,n+s-a),h&&t.bezierCurveTo(i+e,n+s-Tn*a,i+e-Tn*r,n+s,i+e-r,n+s),t.lineTo(i+r,n+s),h&&t.bezierCurveTo(i+Tn*r,n+s,i,n+s-Tn*a,i,n+s-a),t.lineTo(i,n+a),h&&t.bezierCurveTo(i,n+Tn*a,i+Tn*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([...Km,...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=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",` >
|
|
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,z_);return Promise.all([zo(i,e),mh(r,e)]).then(o=>{let[h,l]=o;const u=new this(h,E(E(E({},r),l),{},{layoutManager:new V_}));if(n){const d=V.getClass(n.type),f=V.getClass(n.strategy);u.layoutManager=new d(new f)}else u.layoutManager=new Sh;return u.layoutManager.subscribeTargets({type:Ii,target:u,targets:u.getObjects()}),u.setCoords(),u})}}T(li,"type","Group"),T(li,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),V.setClass(li);const Qm=(a,t)=>Math.min(t.width/a.width,t.height/a.height),Zm=(a,t)=>Math.max(t.width/a.width,t.height/a.height),_f="\\s*,?\\s*",Ch="".concat(_f,"(").concat(Ns,")"),G_="".concat(Ch).concat(Ch).concat(Ch).concat(_f,"([01])").concat(_f,"([01])").concat(Ch).concat(Ch),U_={m:"l",M:"L"},Y_=(a,t,e,s,i,n,r,o,h,l,u)=>{const d=Fs(a),f=Ls(a),g=Fs(t),p=Ls(t),m=e*i*g-s*n*p+r,_=s*i*g+e*n*p+o;return["C",l+h*(-e*i*f-s*n*d),u+h*(-s*i*f+e*n*d),m+h*(e*i*p+s*n*g),_+h*(s*i*p-e*n*g),m,_]},t0=(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 wf(a,t,e,s,i,n,r,o){let h;if(dt.cachesBoundsOfCurve&&(h=[...arguments].join(),uh.boundsOfCurveCache[h]))return uh.boundsOfCurveCache[h];const l=Math.sqrt,u=Math.abs,d=[],f=[[0,0],[0,0]];let g=6*a-12*e+6*i,p=-3*a+9*e-9*i+3*r,m=3*e-3*a;for(let A=0;A<2;++A){if(A>0&&(g=6*t-12*s+6*n,p=-3*t+9*s-9*n+3*o,m=3*s-3*t),u(p)<1e-12){if(u(g)<1e-12)continue;const R=-m/g;0<R&&R<1&&d.push(R);continue}const k=g*g-4*m*p;if(k<0)continue;const P=l(k),M=(-g+P)/(2*p);0<M&&M<1&&d.push(M);const O=(-g-P)/(2*p);0<O&&O<1&&d.push(O)}let _=d.length;const b=_,x=s0(a,t,e,s,i,n,r,o);for(;_--;){const{x:A,y:k}=x(d[_]);f[0][_]=A,f[1][_]=k}f[0][b]=a,f[1][b]=t,f[0][b+1]=r,f[1][b+1]=o;const C=[new D(Math.min(...f[0]),Math.min(...f[1])),new D(Math.max(...f[0]),Math.max(...f[1]))];return dt.cachesBoundsOfCurve&&(uh.boundsOfCurveCache[h]=C),C}const q_=(a,t,e)=>{let[s,i,n,r,o,h,l,u]=e;const d=((f,g,p,m,_,b,x)=>{if(p===0||m===0)return[];let C=0,A=0,k=0;const P=Math.PI,M=x*jd,O=Ls(M),R=Fs(M),I=.5*(-R*f-O*g),j=.5*(-R*g+O*f),G=p**2,L=m**2,H=j**2,$=I**2,J=G*L-G*H-L*$;let U=Math.abs(p),X=Math.abs(m);if(J<0){const Ve=Math.sqrt(1-J/(G*L));U*=Ve,X*=Ve}else k=(_===b?-1:1)*Math.sqrt(J/(G*H+L*$));const Ot=k*U*j/X,zt=-k*X*I/U,ee=R*Ot-O*zt+.5*f,Bt=O*Ot+R*zt+.5*g;let At=t0(1,0,(I-Ot)/U,(j-zt)/X),we=t0((I-Ot)/U,(j-zt)/X,(-I-Ot)/U,(-j-zt)/X);b===0&&we>0?we-=2*P:b===1&&we<0&&(we+=2*P);const Ps=Math.ceil(Math.abs(we/P*2)),kt=[],ft=we/Ps,Ds=8/3*Math.sin(ft/4)*Math.sin(ft/4)/Math.sin(ft/2);let ni=At+ft;for(let Ve=0;Ve<Ps;Ve++)kt[Ve]=Y_(At,ni,R,O,U,X,ee,Bt,Ds,C,A),C=kt[Ve][5],A=kt[Ve][6],At=ni,ni+=ft;return kt})(l-a,u-t,i,n,o,h,r);for(let f=0,g=d.length;f<g;f++)d[f][1]+=a,d[f][2]+=t,d[f][3]+=a,d[f][4]+=t,d[f][5]+=a,d[f][6]+=t;return d},e0=a=>{let t=0,e=0,s=0,i=0;const n=[];let r,o=0,h=0;for(const l of a){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":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(f=>n.push(f)),t=u[6],e=u[7];break;case"z":case"Z":t=s,e=i,d=["Z"]}d?(n.push(d),r=d[0]):r=""}return n},Uc=(a,t,e,s)=>Math.sqrt((e-a)**2+(s-t)**2),s0=(a,t,e,s,i,n,r,o)=>h=>{const l=h**3,u=(g=>3*g**2*(1-g))(h),d=(g=>3*g*(1-g)**2)(h),f=(g=>(1-g)**3)(h);return new D(r*l+i*u+e*d+a*f,o*l+n*u+s*d+t*f)},i0=a=>a**2,n0=a=>2*a*(1-a),r0=a=>(1-a)**2,$_=(a,t,e,s,i,n,r,o)=>h=>{const l=i0(h),u=n0(h),d=r0(h),f=3*(d*(e-a)+u*(i-e)+l*(r-i)),g=3*(d*(s-t)+u*(n-s)+l*(o-n));return Math.atan2(g,f)},K_=(a,t,e,s,i,n)=>r=>{const o=i0(r),h=n0(r),l=r0(r);return new D(i*o+e*h+a*l,n*o+s*h+t*l)},J_=(a,t,e,s,i,n)=>r=>{const o=1-r,h=2*(o*(e-a)+r*(i-e)),l=2*(o*(s-t)+r*(n-s));return Math.atan2(l,h)},o0=(a,t,e)=>{let s=new D(t,e),i=0;for(let n=1;n<=100;n+=1){const r=a(n/100);i+=Uc(s.x,s.y,r.x,r.y),s=r}return i},Q_=(a,t)=>{let e,s=0,i=0,n={x:a.x,y:a.y},r=E({},n),o=.01,h=0;const l=a.iterator,u=a.angleFinder;for(;i<t&&o>1e-4;)r=l(s),h=s,e=Uc(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)})},xf=a=>{let t,e,s=0,i=0,n=0,r=0,o=0;const h=[];for(const l of a){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=o=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=s0(i,n,l[1],l[2],l[3],l[4],l[5],l[6]),e=u,e.iterator=t,e.angleFinder=$_(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=K_(i,n,l[1],l[2],l[3],l[4]),e=u,e.iterator=t,e.angleFinder=J_(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=o,e.length=Uc(i,n,r,o),i=r,n=o}s+=e.length,h.push(e)}return h.push({length:s,x:i,y:n}),h},a0=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:xf(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 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 Q_(i,t)}},Z_=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),h0=new RegExp(G_,"g"),tw=new RegExp(Ns,"gi"),ew={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},l0=a=>{var t;const e=[],s=(t=a.match(Z_))!==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=ew[n.toLowerCase()];let o=[];if(n==="a"||n==="A"){h0.lastIndex=0;for(let h=null;h=h0.exec(i);)o.push(...h.slice(1))}else o=i.match(tw)||[];for(let h=0;h<o.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(o[h+d]);e.push(l)}}return e},sw=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=new D(a[0]),s=new D(a[1]),i=1,n=0;const r=[],o=a.length,h=o>2;let l;for(h&&(i=a[2].x<s.x?-1:a[2].x===s.x?0:1,n=a[2].y<s.y?-1:a[2].y===s.y?0:1),r.push(["M",e.x-i*t,e.y-n*t]),l=1;l<o;l++){if(!e.eq(s)){const u=e.midPointFrom(s);r.push(["Q",e.x,e.y,u.x,u.y])}e=a[l],l+1<a.length&&(s=a[l+1])}return h&&(i=e.x>a[l-2].x?1:e.x===a[l-2].x?0:-1,n=e.y>a[l-2].y?1:e.y===a[l-2].y?0:-1),r.push(["L",e.x+i*t,e.y+n*t]),r},c0=(a,t)=>a.map(e=>e.map((s,i)=>i===0||t===void 0?s:Dt(s,t)).join(" ")).join(" ");function Yc(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 iw=(a,t)=>Math.floor(Math.random()*(t-a+1))+a;function u0(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const e=t.onComplete||dr,s=new(yc()).XMLHttpRequest,i=t.signal,n=function(){s.abort()},r=function(){i&&i.removeEventListener("abort",n),s.onerror=s.ontimeout=dr};if(i&&i.aborted)throw new Ld("request");return i&&i.addEventListener("abort",n,{once:!0}),s.onreadystatechange=function(){s.readyState===4&&(r(),e(s),s.onreadystatechange=dr)},s.onerror=s.ontimeout=r,s.open("get",a,!0),s.send(),s}const qc=(a,t)=>{let e=a._findCenterFromElement();a.transformMatrix&&((s=>{if(s.transformMatrix){const{scaleX:i,scaleY:n,angle:r,skewX:o}=gr(s.transformMatrix);s.flipX=!1,s.flipY=!1,s.set(Le,i),s.set(ns,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,st,st)};var nw=Object.freeze({__proto__:null,addTransformToObject:rm,animate:df,animateColor:Am,applyTransformToObject:Vo,calcAngleBetweenVectors:Lc,calcDimensionsMatrix:gh,calcPlaneChangeMatrix:_h,calcVectorRotation:bm,cancelAnimFrame:Hp,capValue:br,composeMatrix:Gp,copyCanvasElement:a=>{var t;const e=Ut();return e.width=a.width,e.height=a.height,(t=e.getContext("2d"))===null||t===void 0||t.drawImage(a,0,0),e},cos:Fs,createCanvasElement:Ut,createImage:Wp,createRotateMatrix:Xo,createScaleMatrix:Ec,createSkewXMatrix:Gd,createSkewYMatrix:Ud,createTranslateMatrix:Wo,createVector:Rc,crossProduct:Go,degreesToRadians:Wt,dotProduct:ym,ease:Uy,enlivenObjectEnlivables:mh,enlivenObjects:zo,findScaleToCover:Zm,findScaleToFit:Qm,getBoundsOfCurve:wf,getOrthonormalVector:of,getPathSegmentsInfo:xf,getPointOnPath:a0,getPointer:nm,getRandomInt:iw,getRegularPolygonPath:(a,t)=>{const e=2*Math.PI/a;let s=-Cn;a%2==0&&(s+=e/2);const i=new Array(a+1);for(let n=0;n<a;n++){const r=n*e+s,{x:o,y:h}=new D(Fs(r),Ls(r)).scalarMultiply(t);i[n]=[n===0?"M":"L",o,h]}return i[a]=["Z"],i},getSmoothPathFromPoints:sw,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:Ic,groupSVGElements:(a,t)=>a&&a.length===1?a[0]:new li(a,t),hasStyleChanged:Wc,invertTransform:$e,isBetweenVectors:af,isIdentityMatrix:Xp,isTouchEvent:Mc,isTransparent:Fm,joinPath:c0,loadImage:ph,magnitude:Fc,makeBoundingBoxFromPoints:ai,makePathSimpler:e0,matrixToSVG:vh,mergeClipPaths:(a,t)=>{var e;let s=a,i=t;s.inverted&&!i.inverted&&(s=t,i=a),Zd(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 li([s],{clipPath:i,inverted:n})},multiplyTransformMatrices:Yt,multiplyTransformMatrixArray:Tc,parsePath:l0,parsePreserveAspectRatioAttribute:$d,parseUnit:je,pick:pr,projectStrokeOnPoints:jm,qrDecompose:gr,radiansToDegrees:En,removeFromArray:fr,removeTransformFromObject:(a,t)=>{const e=$e(t),s=Yt(e,a.calcOwnMatrix());Vo(a,s)},removeTransformMatrixForSvgParsing:qc,request:u0,requestAnimFrame:fh,resetObjectTransform:om,rotatePoint:(a,t,e)=>a.rotate(e,t),rotateVector:rf,saveObjectTransform:Qd,sendObjectToPlane:Zd,sendPointToPlane:vr,sendVectorToPlane:am,setStyle:Yc,sin:Ls,sizeAfterTransform:Oc,string:__,stylesFromArray:Hm,stylesToArray:Bm,toDataURL:Vd,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}=xe({x:s[n],y:s[n+1]},t);i[n]=r,i[n+1]=o}return i})),transformPoint:xe});class rw extends im{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=Ut();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=jo().createElement("div");return t.setAttribute("data-fabric","wrapper"),Yc(t,{position:"relative"}),sm(t),t}applyCanvasStyle(t,e){const{styles:s,allowTouchScrolling:i}=e;Yc(t,E(E({},s),{},{"touch-action":i?"manipulation":Fe})),sm(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:s,ctx:i}=this.upper;em(s,i,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),Kd(this.upper.el,t),Kd(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 $c extends yh{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()),$c.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 rw(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 Fm(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===xc||e===Le||e===ns||e===dh?i=this.centeredScaling||t.centeredScaling:e===Wd&&(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=Bd:["bl","mb","br"].includes(e)&&(s.y=qe)),s}_setupCurrentTransform(t,e,s){var i;const n=e.group?vr(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):Ny,l=((g,p,m,_)=>{if(!p||!g)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),f={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({},Qd(e)),{},{originX:d.x,originY:d.y})};this._currentTransform=f,this.fire("before:transform",{e:t,transform:f})}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new D(e,s).transform(this.viewportTransform),o=new D(e+i,s+n).transform(this.viewportTransform),h=this.selectionLineWidth/2;let l=Math.min(r.x,o.x),u=Math.min(r.y,o.y),d=Math.max(r.x,o.x),f=Math.max(r.y,o.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(l,u,d-l,f-u)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,l+=h,u+=h,d-=h,f-=h,Se.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(l,u,d-l,f-u))}findTarget(t){if(this.skipTargetFind)return;const e=this.getViewportPoint(t),s=this._activeObject,i=this.getActiveObjects();if(this.targets=[],s&&i.length>=1){if(s.findControl(e,Mc(t))||i.length>1&&this.searchPossibleTargets([s],e))return s;if(s===this.searchPossibleTargets([s],e)){if(this.preserveObjectStacking){const n=this.targets;this.targets=[];const r=this.searchPossibleTargets(this._objects,e);return t[this.altSelectionKey]&&r&&r!==s?(this.targets=n,s):r}return s}}return this.searchPossibleTargets(this._objects,e)}_pointIsInObjectSelectionArea(t,e){let s=t.getCoords();const i=this.getZoom(),n=t.padding/i;if(n){const[r,o,h,l]=s,u=Math.atan2(o.y-r.y,o.x-r.x),d=Fs(u)*n,f=Ls(u)*n,g=d+f,p=d-f;s=[new D(r.x-p,r.y-g),new D(o.x+g,o.y-p),new D(h.x+p,h.y+g),new D(l.x-g,l.y+p)]}return Ft.isPointInPolygon(e,s)}_checkTarget(t,e){return!!(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,vr(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(Ac(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&&Ac(s)&&s.interactive&&this.targets[0]){const i=this.targets;for(let n=i.length-1;n>0;n--){const r=i[n];if(!Ac(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=nm(t),r=i.width||0,o=i.height||0;r&&o||(qe in i&&Bd in i&&(o=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=vr(n,void 0,this.viewportTransform));const h=this.getRetinaScaling();h!==1&&(n.x/=h,n.y/=h);const l=r===0||o===0?new D(1,1):new D(s.width/r,s.height/o);return n.multiply(l)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=Ut(),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 mr(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,mr(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),mr(s)&&s===this._hoveredTarget&&(this._hoveredTarget=void 0),this._activeObject=void 0,!0)}discardActiveObject(t){const e=this.getActiveObjects(),s=this.getActiveObject();e.length&&this.fire("before:selection:cleared",{e:t,deselected:[s]});const i=this._discardActiveObject(t);return this._fireSelectionEvents(e,t),i}endCurrentTransform(t){const e=this._currentTransform;this._finalizeCurrentTransform(t),e&&e.target&&(e.target.isMoving=!1),this._currentTransform=null}_finalizeCurrentTransform(t){const e=this._currentTransform,s=e.target,i={e:t,target:s,transform:e,action:e.action};s._scaling&&(s._scaling=!1),s.setCoords(),e.actionPerformed&&(this.fire("object:modified",i),s.fire(Sc,i))}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeObject;mr(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&&mr(e)&&this._activeObject===e){const s=pr(t,["angle","flipX","flipY",mt,Le,ns,No,Bo,qe]);return rm(t,e.calcOwnMatrix()),s}return{}}_setSVGObject(t,e,s){const i=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,s),e.set(i)}}T($c,"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 aw=["target","oldTarget","fireCanvas","e"],rs={passive:!1},Ko=(a,t)=>{const e=a.getViewportPoint(t),s=a.getScenePoint(t);return{viewportPoint:e,scenePoint:s,pointer:e,absolutePointer:s}},Mn=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)},ys=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)},hw={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 Sf extends $c{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(Mn,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const s=this.upperCanvasEl,i=this._getEventPrefix();t(tm(s),"resize",this._onResize),t(s,i+"down",this._onMouseDown),t(s,"".concat(i,"move"),this._onMouseMove,rs),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,rs)}removeListeners(){this.addOrRemove(ys,"remove");const t=this._getEventPrefix(),e=Is(this.upperCanvasEl);ys(e,"".concat(t,"up"),this._onMouseUp),ys(e,"touchend",this._onTouchEnd,rs),ys(e,"".concat(t,"move"),this._onMouseMove,rs),ys(e,"touchmove",this._onMouseMove,rs)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s=E({e:t},Ko(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},Ko(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 Mn(this.upperCanvasEl,"drag",this._onDragProgress)}Jd(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!==Fe,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 o;this.fire(e,r),this._fireEnterLeaveEvents(s,r),s&&(s.canDrop(t)&&(o=s),s.fire(e,r));for(let h=0;h<i.length;h++){const l=i[h];l.canDrop(t)&&(o=l),l.fire(e,r)}this._renderDragEffects(t,n,o),this._dropTarget=o}_onDragEnter(t){const{target:e,targets:s}=this.findDragTargets(t),i={e:t,target:e,subTargets:s,dragSource:this._dragSource};this.fire("dragenter",i),this._fireEnterLeaveEvents(e,i)}_onDragLeave(t){const e={e:t,target:this._draggedoverTarget,subTargets:this.targets,dragSource:this._dragSource};this.fire("dragleave",e),this._fireEnterLeaveEvents(void 0,e),this._renderDragEffects(t,this._dragSource),this._dropTarget=void 0,this.targets=[],this._hoveredTargets=[]}_onDrop(t){const{target:e,targets:s}=this.findDragTargets(t),i=this._basicEventHandler("drop:before",E({e:t,target:e,subTargets:s,dragSource:this._dragSource},Ko(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&&Jd(t),this._basicEventHandler("contextmenu",i),!1}_onDoubleClick(t){this._cacheTransformEventData(t),this._handleEvent(t,"dblclick"),this._resetTransformEventData()}getPointerId(t){const e=t.changedTouches;return e?e[0]&&e[0].identifier:this.enablePointerEvents?t.pointerId:-1}_isMainEvent(t){return t.isPrimary===!0||t.isPrimary!==!1&&(t.type==="touchend"&&t.touches.length===0||!t.changedTouches||t.changedTouches[0].identifier===this.mainTouchId)}_onTouchStart(t){t.preventDefault(),this.mainTouchId===void 0&&(this.mainTouchId=this.getPointerId(t)),this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix(),i=Is(e);Mn(i,"touchend",this._onTouchEnd,rs),Mn(i,"touchmove",this._onMouseMove,rs),ys(e,"".concat(s,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();ys(e,"".concat(s,"move"),this._onMouseMove,rs);const i=Is(e);Mn(i,"".concat(s,"up"),this._onMouseUp),Mn(i,"".concat(s,"move"),this._onMouseMove,rs)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),s=Is(this.upperCanvasEl);ys(s,"touchend",this._onTouchEnd,rs),ys(s,"touchmove",this._onMouseMove,rs),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout(()=>{Mn(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=Is(this.upperCanvasEl);ys(i,"".concat(s,"up"),this._onMouseUp),ys(i,"".concat(s,"move"),this._onMouseMove,rs),Mn(e,"".concat(s,"move"),this._onMouseMove,rs)}}_onMouseMove(t){const e=this.getActiveObject();!this.allowTouchScrolling&&(!e||!e.shouldStartDragging(t))&&t.preventDefault&&t.preventDefault(),this.__onMouseMove(t)}_onResize(){this.calcOffset(),this._resetTransformEventData()}_shouldRender(t){const e=this.getActiveObject();return!!e!=!!t||e&&t&&e!==t}__onMouseUp(t){var e;this._cacheTransformEventData(t),this._handleEvent(t,"up:before");const s=this._currentTransform,i=this._isClick,n=this._target,{button:r}=t;if(r)return(this.fireMiddleClick&&r===1||this.fireRightClick&&r===2)&&this._handleEvent(t,"up"),void this._resetTransformEventData();if(this.isDrawingMode&&this._isCurrentlyDrawing)return void this._onMouseUpInDrawingMode(t);if(!this._isMainEvent(t))return;let o,h,l=!1;if(s&&(this._finalizeCurrentTransform(t),l=s.actionPerformed),!i){const 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),Mc(t)),{key:d,control:f}=u||{};if(h=d,n.selectable&&n!==this._activeObject&&n.activeOn==="up")this.setActiveObject(n,t),l=!0;else if(f){const g=f.getMouseUpHandler(t,n,f);g&&(o=this.getScenePoint(t),g.call(f,t,s,o.x,o.y))}n.isMoving=!1}if(s&&(s.target!==n||s.corner!==h)){const u=s.target&&s.target.controls[s.corner],d=u&&u.getMouseUpHandler(t,s.target,u);o=o||this.getScenePoint(t),d&&d.call(u,t,s,o.x,o.y)}this._setCursorFromEvent(t,n),this._handleEvent(t,"up"),this._groupSelector=null,this._currentTransform=null,n&&(n.__corner=void 0),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},Ko(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),Mc(t));if(e===this._activeObject&&(o||!n)){this._setupCurrentTransform(t,e,r);const h=o?o.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=vr(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=Pt(e,aw);const{targetIn:h,targetOut:l,canvasIn:u,canvasOut:d}=hw[t],f=i!==s;if(i&&f){const g=E(E({},o),{},{e:r,target:i,nextTarget:s},Ko(this,r));n&&this.fire(d,g),i.fire(l,g)}if(s&&f){const g=E(E({},o),{},{e:r,target:s,previousTarget:i},Ko(this,r));n&&this.fire(u,g),s.fire(h,g)}}__onMouseWheel(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()}_transformObject(t){const e=this.getScenePoint(t),s=this._currentTransform,i=s.target,n=i.group?vr(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=mr(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=mr(s);if(s&&this._isSelectionKeyPressed(t)&&this.selection&&e&&e.selectable&&(s!==e||i)&&(i||!e.isDescendantOf(s)&&!s.isDescendantOf(e))&&!e.onSelect({e:t})&&!s.getActiveControl()){if(i){const n=s.getObjects();if(e===s){const r=this.getViewportPoint(t);if(!(e=this.searchPossibleTargets(n,r)||this.searchPossibleTargets(this._objects,r))||!e.selectable)return!1}e.group===s?(s.remove(e),this._hoveredTarget=e,this._hoveredTargets=[...this.targets],s.size()===1&&this._setActiveObject(s.item(0),t)):(s.multiSelectAdd(e),this._hoveredTarget=s,this._hoveredTargets=[...this.targets]),this._fireSelectionEvents(n,t)}else{s.exitEditing&&s.exitEditing();const n=new(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),o=r.add(new D(i,n)),h=r.min(o),l=r.max(o).subtract(h),u=this.collectObjects({left:h.x,top:h.y,width:l.x,height:l.y},{includeIntersecting:!this.selectionFullyContained}),d=r.eq(o)?u[0]?[u[0]]:[]:u.length>1?u.filter(f=>!f.onSelect({e:t})).reverse():u;if(d.length===1)this.setActiveObject(d[0],t);else if(d.length>1){const f=V.getClass("ActiveSelection");this.setActiveObject(new f(d,{canvas:this}),t)}return this._groupSelector=null,!0}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const d0={x1:0,y1:0,x2:0,y2:0},lw=E(E({},d0),{},{r1:0,r2:0}),Jo=(a,t)=>isNaN(a)&&typeof t=="number"?t:a,cw=/^(\d+\.\d+)%|(\d+)%$/;function f0(a){return a&&cw.test(a)}function g0(a,t){const e=typeof a=="number"?a:typeof a=="string"?parseFloat(a)/(f0(a)?100:1):NaN;return br(0,Jo(e,t),1)}const uw=/\s*;\s*/,dw=/\s*:\s*/;function fw(a,t){let e,s;const i=a.getAttribute("style");if(i){const r=i.split(uw);r[r.length-1]===""&&r.pop();for(let o=r.length;o--;){const[h,l]=r[o].split(dw).map(u=>u.trim());h==="stop-color"?e=l:h==="stop-opacity"&&(s=l)}}const n=new yt(e||a.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:g0(a.getAttribute("offset"),0),color:n.toRgb(),opacity:Jo(parseFloat(s||a.getAttribute("stop-opacity")||""),1)*n.getAlpha()*t}}function gw(a,t){const e=[],s=a.getElementsByTagName("stop"),i=g0(t,1);for(let n=s.length;n--;)e.push(fw(s[n],i));return e}function p0(a){return a.nodeName==="linearGradient"||a.nodeName==="LINEARGRADIENT"?"linear":"radial"}function m0(a){return a.getAttribute("gradientUnits")==="userSpaceOnUse"?"pixels":"percentage"}function Hs(a,t){return a.getAttribute(t)}function pw(a,t){return function(e,s){let i,{width:n,height:r,gradientUnits:o}=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,o==="pixels"&&(l!=="x1"&&l!=="x2"&&l!=="r2"||(i*=n),l!=="y1"&&l!=="y2"||(i*=r)))),h[l]=i,h},{})}(p0(a)==="linear"?function(e){return{x1:Hs(e,"x1")||0,y1:Hs(e,"y1")||0,x2:Hs(e,"x2")||"100%",y2:Hs(e,"y2")||0}}(a):function(e){return{x1:Hs(e,"fx")||Hs(e,"cx")||"50%",y1:Hs(e,"fy")||Hs(e,"cy")||"50%",r1:0,x2:Hs(e,"cx")||"50%",y2:Hs(e,"cy")||"50%",r2:Hs(e,"r")||"50%"}}(a),E(E({},t),{},{gradientUnits:m0(a)}))}class Ah{constructor(t){const{type:e="linear",gradientUnits:s="pixels",coords:i={},colorStops:n=[],offsetX:r=0,offsetY:o=0,gradientTransform:h,id:l}=t||{};Object.assign(this,{type:e,gradientUnits:s,coords:E(E({},e==="radial"?lw:d0),i),colorStops:n,offsetX:r,offsetY:o,gradientTransform:h,id:l?"".concat(l,"_").concat(Tn()):Tn()})}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({},pr(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():Re.concat(),n=this.gradientUnits==="pixels"?"userSpaceOnUse":"objectBoundingBox",r=this.colorStops.map(d=>E({},d)).sort((d,f)=>d.offset-f.offset);let o=-this.offsetX,h=-this.offsetY;var l;n==="objectBoundingBox"?(o/=t.width,h/=t.height):(o+=t.width/2,h+=t.height/2),(l=t)&&typeof l._renderPathCommands=="function"&&this.gradientUnits!=="percentage"&&(o-=t.pathOffset.x,h-=t.pathOffset.y),i[4]-=o,i[5]-=h;const u=['id="SVGID_'.concat(this.id,'"'),'gradientUnits="'.concat(n,'"'),'gradientTransform="'.concat(e?e+" ":"").concat(vh(i),'"'),""].join(" ");if(this.type==="linear"){const{x1:d,y1:f,x2:g,y2:p}=this.coords;s.push("<linearGradient ",u,' x1="',d,'" y1="',f,'" x2="',g,'" y2="',p,`">
|
|
71
|
-
`)}else if(this.type==="radial"){const{x1:d,y1:
|
|
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=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:_}=this.coords,b=m>_;s.push("<radialGradient ",u,' cx="',b?d:f,'" cy="',b?g:p,'" r="',b?m:_,'" fx="',b?f:d,'" fy="',b?p:g,`">
|
|
72
|
+
`),b&&(r.reverse(),r.forEach(S=>{S.offset=1-S.offset}));const x=Math.min(m,_);if(x>0){const S=x/Math.max(m,_);r.forEach(A=>{A.offset+=S*(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=Pt(t,
|
|
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,st,st)}_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(...
|
|
77
|
-
`];{const{radius:e}=this,s=Wt(this.startAngle),i=Wt(this.endAngle),n=Fs(s)*e,r=Ls(s)*e,
|
|
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 kw=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let Ef;class Ce extends C0{static getDefaults(){return E(E({},super.getDefaults()),Ce.ownDefaults)}constructor(t,e){super(),T(this,"__charBounds",[]),Object.assign(this,Ce.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=xf(t.path))}_splitText(){const t=this._splitTextIntoLines(this.text);return this.textLines=t.lines,this._textLines=t.graphemeLines,this._unwrappedTextLines=t._unwrappedLines,this._text=t.graphemeText,t}initDimensions(){this._splitText(),this._clearCache(),this.dirty=!0,this.path?(this.width=this.path.width,this.height=this.path.height):(this.width=this.calcTextWidth()||this.cursorWidth||this.MIN_TEXT_WIDTH,this.height=this.calcTextHeight()),this.textAlign.includes(ci)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,s,i,n,r,o;for(let h=0,l=this._textLines.length;h<l;h++)if((this.textAlign===ci||h!==l-1&&!this.isEndOfWrapping(h))&&(i=0,n=this._textLines[h],e=this.getLineWidth(h),e<this.width&&(o=this.textLines[h].match(this._reSpacesAndTabs)))){s=o.length,t=(this.width-e)/s;for(let 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===Ie?(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=qe;break;case"descender":t.textBaseline=Bd}t.font=this._getFontDeclaration(e,s)}calcTextWidth(){let t=this.getLineWidth(0);for(let e=1,s=this._textLines.length;e<s;e++){const i=this.getLineWidth(e);i>t&&(t=i)}return t}_renderTextLine(t,e,s,i,n,r){this._renderChars(t,e,s,i,n,r)}_renderTextLinesBackground(t){if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor"))return;const e=t.fillStyle,s=this._getLeftOffset();let i=this._getTopOffset();for(let n=0,r=this._textLines.length;n<r;n++){const o=this.getHeightOfLine(n);if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor",n)){i+=o;continue}const h=this._textLines[n].length,l=this._getLineLeftOffset(n);let u,d,f=0,g=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,-o/this.lineHeight*(1-this._fontSizeFraction),_.width,o/this.lineHeight),t.restore()):d!==p?(u=s+l+g,this.direction==="rtl"&&(u=this.width-u-f),t.fillStyle=p,p&&t.fillRect(u,i,f,o/this.lineHeight),g=_.left,f=_.width,p=d):f+=_.kernedWidth}d&&!this.path&&(u=s+l+g,this.direction==="rtl"&&(u=this.width-u-f),t.fillStyle=d,t.fillRect(u,i,f,o/this.lineHeight)),i+=o}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,s,i){const n=uh.getFontCache(e),r=this._getFontDeclaration(e),o=s+t,h=s&&r===this._getFontDeclaration(i),l=e.fontSize/this.CACHE_FONT_SIZE;let u,d,f,g;if(s&&n[s]!==void 0&&(f=n[s]),n[t]!==void 0&&(g=u=n[t]),h&&n[o]!==void 0&&(d=n[o],g=d-f),u===void 0||f===void 0||d===void 0){const p=function(){if(!Ef){const m=Ut();m.width=m.height=0,Ef=m.getContext("2d")}return Ef}();this._setTextStyles(p,e,!0),u===void 0&&(g=u=p.measureText(t).width,n[t]=u),f===void 0&&h&&s&&(f=p.measureText(s).width,n[s]=f),h&&d===void 0&&(d=p.measureText(o).width,n[o]=d,g=d-f)}return{width:u*l,kernedWidth:g*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,o=this._textLines[t],h=o.length,l=new Array(h);this.__charBounds[t]=l;for(let u=0;u<h;u++){const d=o[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 f=n?h-1:0;n?f>=0:f<h;n?f--:f++)s=l[f],u>d?u%=d:u<0&&(u+=d),this._setGraphemeOnPath(u,s),u+=s.kernedWidth}return{width:i,numOfSpaces:0}}_setGraphemeOnPath(t,e){const s=t+e.kernedWidth/2,i=this.path,n=a0(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),o=i?this.getCompleteStyleDeclaration(e,s-1):{},h=this._measureChar(t,r,i,o);let l,u=h.kernedWidth,d=h.width;this.charSpacing!==0&&(l=this._getWidthOfCharSpacing(),d+=l,u+=l);const f={width:d,left:0,height:r.fontSize,kernedWidth:u,deltaY:r.deltaY};if(s>0&&!n){const g=this.__charBounds[e][s-1];f.left=g.left+g.width+h.kernedWidth-h.width}return f}getHeightOfLine(t){if(this.__lineHeights[t])return this.__lineHeights[t];let e=this.getHeightOfChar(t,0);for(let s=1,i=this._textLines[t].length;s<i;s++)e=Math.max(this.getHeightOfChar(t,s),e);return this.__lineHeights[t]=e*this.lineHeight*this._fontSizeMult}calcTextHeight(){let t,e=0;for(let s=0,i=this._textLines.length;s<i;s++)t=this.getHeightOfLine(s),e+=s===i-1?t/this.lineHeight:t;return e}_getLeftOffset(){return this.direction==="ltr"?-this.width/2:this.width/2}_getTopOffset(){return-this.height/2}_renderTextCommon(t,e){t.save();let s=0;const i=this._getLeftOffset(),n=this._getTopOffset();for(let r=0,o=this._textLines.length;r<o;r++){const h=this.getHeightOfLine(r),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(Gt))&&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(ci),l=this.path,u=!h&&this.charSpacing===0&&this.isEmptyStyles(r)&&!l,d=this.direction==="ltr",f=this.direction==="ltr"?1:-1,g=e.direction;let p,m,_,b,x,C="",A=0;if(e.save(),g!==this.direction&&(e.canvas.setAttribute("dir",d?"ltr":"rtl"),e.direction=d?"ltr":"rtl",e.textAlign=d?mt:Vt),n-=o*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,C+=s[k],_=this.__charBounds[r][k],A===0?(i+=f*(_.kernedWidth-_.width),A+=_.width):A+=_.kernedWidth,h&&!b&&this._reSpaceAndTab.test(s[k])&&(b=!0),b||(p=p||this.getCompleteStyleDeclaration(r,k),m=this.getCompleteStyleDeclaration(r,k+1),b=Wc(p,m,!1)),b&&(l?(e.save(),e.translate(_.renderLeft,_.renderTop),e.rotate(_.angle),this._renderChar(t,e,r,k,C,-A/2,0),e.restore()):(x=i,this._renderChar(t,e,r,k,C,x,n)),C="",p=m,i+=f*A,A=0);e.restore()}_applyPatternGradientTransformText(t){const e=Ut(),s=this.width+this.strokeWidth,i=this.height+this.strokeWidth,n=e.getContext("2d");return e.width=s,e.height=i,n.beginPath(),n.moveTo(0,0),n.lineTo(s,0),n.lineTo(s,i),n.lineTo(0,i),n.closePath(),n.translate(s/2,i/2),n.fillStyle=t.toLive(n),this._applyPatternGradientTransform(n,t),n.fill(),n.createPattern(e,"no-repeat")}handleFiller(t,e,s){let i,n;return 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,o){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&&(o+=h.deltaY),u){const f=this._setFillStyles(e,l);e.fillText(n,r-f.offsetX,o-f.offsetY)}if(d){const f=this._setStrokeStyles(e,l);e.strokeText(n,r-f.offsetX,o-f.offsetY)}e.restore()}}setSuperscript(t,e){this._setScript(t,e,this.superscript)}setSubscript(t,e){this._setScript(t,e,this.subscript)}_setScript(t,e,s){const i=this.get2DCursorLocation(t,!0),n=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"fontSize"),r=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"deltaY"),o={fontSize:n*s.size,deltaY:r+n*s.baseline};this.setSelectionStyles(o,t,e)}_getLineLeftOffset(t){const e=this.getLineWidth(t),s=this.width-e,i=this.textAlign,n=this.direction,r=this.isEndOfWrapping(t);let o=0;return i===ci||i===Eh&&!r||i===Th&&!r||i===Jc&&!r?0:(i===st&&(o=s/2),i===Vt&&(o=s),i===Eh&&(o=s/2),i===Th&&(o=s),n==="rtl"&&(i===Vt||i===ci||i===Th?o=0:i===mt||i===Jc?o=-s:i!==st&&i!==Eh||(o=-s/2)),o)}_clearCache(){this._forceClearCache=!1,this.__lineWidths=[],this.__lineHeights=[],this.__charBounds=[]}getLineWidth(t){if(this.__lineWidths[t]!==void 0)return this.__lineWidths[t];const{width:e}=this.measureLine(t);return this.__lineWidths[t]=e,e}_getWidthOfCharSpacing(){return this.charSpacing!==0?this.fontSize*this.charSpacing/1e3:0}getValueOfPropertyAt(t,e,s){var i;return(i=this._getStyleDeclaration(t,e)[s])!==null&&i!==void 0?i:this[s]}_renderTextDecoration(t,e){if(!this[e]&&!this.styleHas(e))return;let s=this._getTopOffset();const i=this._getLeftOffset(),n=this.path,r=this._getWidthOfCharSpacing(),o=this.offsets[e];for(let h=0,l=this._textLines.length;h<l;h++){const u=this.getHeightOfLine(h);if(!this[e]&&!this.styleHas(e,h)){s+=u;continue}const d=this._textLines[h],f=u/this.lineHeight,g=this._getLineLeftOffset(h);let p,m,_=0,b=0,x=this.getValueOfPropertyAt(h,0,e),C=this.getValueOfPropertyAt(h,0,Gt);const A=s+f*(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,Gt);const j=this.getHeightOfChar(h,O),G=this.getValueOfPropertyAt(h,O,"deltaY");if(n&&p&&m)t.save(),t.fillStyle=C,t.translate(I.renderLeft,I.renderTop),t.rotate(I.angle),t.fillRect(-I.kernedWidth/2,o*j+G,I.kernedWidth,this.fontSize/15),t.restore();else if((p!==x||m!==C||j!==k||G!==P)&&b>0){let L=i+g+_;this.direction==="rtl"&&(L=this.width-L-b),x&&C&&(t.fillStyle=C,t.fillRect(L,A+o*k+P,b,this.fontSize/15)),_=I.left,b=I.width,x=p,C=m,k=j,P=G}else b+=I.kernedWidth}let M=i+g+_;this.direction==="rtl"&&(M=this.width-M-b),t.fillStyle=m,p&&m&&t.fillRect(M,A+o*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(",")||Ce.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 Hc(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(a,t){const e=[],s=[];let i,n=a;this.backgroundColor&&s.push(...Tf(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(Tw)),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(Nm(a),"</tspan>")}_setSVGTextLineText(a,t,e,s){const i=this.getHeightOfLine(t),n=this.textAlign.includes(ci),r=this._textLines[t];let o,h,l,u,d,f="",g=0;s+=i*(1-this._fontSizeFraction)/this.lineHeight;for(let p=0,m=r.length-1;p<=m;p++)d=p===m||this.charSpacing,f+=r[p],l=this.__charBounds[t][p],g===0?(e+=l.kernedWidth-l.width,g+=l.width):g+=l.kernedWidth,n&&!d&&this._reSpaceAndTab.test(r[p])&&(d=!0),d||(o=o||this.getCompleteStyleDeclaration(t,p),h=this.getCompleteStyleDeclaration(t,p+1),d=Wc(o,h,!0)),d&&(u=this._getStyleDeclaration(t,p),a.push(this._createTextCharSpan(f,u,e,s)),f="",o=h,this.direction==="rtl"?e-=g:e+=g,g=0)}_setSVGTextLineBg(a,t,e,s){const i=this._textLines[t],n=this.getHeightOfLine(t)/this.lineHeight;let r,o=0,h=0,l=this.getValueOfPropertyAt(t,0,"textBackgroundColor");for(let u=0;u<i.length;u++){const{left:d,width:f,kernedWidth:g}=this.__charBounds[t][u];r=this.getValueOfPropertyAt(t,u,"textBackgroundColor"),r!==l?(l&&a.push(...Tf(l,e+h,s,o,n)),h=d,o=f,l=r):o+=g}r&&a.push(...Tf(l,e+h,s,o,n))}_getSVGLineTopOffset(a){let t,e=0;for(t=0;t<a;t++)e+=this.getHeightOfLine(t);const s=this.getHeightOfLine(t);return{lineTop:e,offset:(this._fontSizeMult-this._fontSizeFraction)*s/(this.lineHeight*this._fontSizeMult)}}getSvgStyles(a){return"".concat(super.getSvgStyles(a)," white-space: pre;")}getSvgSpanStyles(a,t){const{fontFamily:e,strokeWidth:s,stroke:i,fill:n,fontSize:r,fontStyle:o,fontWeight:h,deltaY:l}=a,u=this.getSvgTextDecoration(a);return[i?bh(Ie,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?bh(Gt,n):"",l?"baseline-shift: ".concat(-l,"; "):"",t?"white-space: pre; ":""].join("")}getSvgTextDecoration(a){return["overline","underline","line-through"].filter(t=>a[t.replace("-","")]).join(" ")}}]),V.setClass(Ce),V.setSVGClass(Ce);class Mw{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 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=o.getScenePoint(t).subtract(u),f=r.getCanvasRetinaScaling(),g=r.getBoundingRect(),p=u.subtract(new D(g.left,g.top)),m=o.viewportTransform,_=p.add(d).transform(m,!0),b=r.backgroundColor,x=pf(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,Yc(A,{position:"fixed",left:"".concat(-A.width,"px"),border:Fe,width:"".concat(A.width/f,"px"),height:"".concat(A.height/f,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{A.remove()},Is(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,o=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 f=this.__dragStartSelection.selectionStart,g=this.__dragStartSelection.selectionEnd;h>f&&h<=g?h=f:h>g&&(h-=g-f),r.removeChars(f,g),delete this.__dragStartSelection}r._reNewline.test(u)&&(r._reNewline.test(r._text[h])||h===r._text.length)&&(n=n.trimEnd()),t.didDrop=!0,t.dropTarget=r,r.insertChars(n,l,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(wc,{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)||Fe;h===Fe?(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(wc,{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 A0=/[ \n\.,;!\?\-]/;class Ow extends Ce{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 df({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||!Hd.test(s[t-1]))?t-1:t,n=s[i];for(;i>0&&i<s.length&&!A0.test(n);)i+=e,n=s[i];return e===-1&&A0.test(n)&&i++,i}selectWord(t){t=t||this.selectionStart;const e=this.searchWordBoundary(t,-1),s=Math.max(e,this.searchWordBoundary(t,1));this.selectionStart=e,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(t){t=t||this.selectionStart;const e=this.findLineBoundaryLeft(t),s=this.findLineBoundaryRight(t);return this.selectionStart=e,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea(),this}enterEditing(t){!this.isEditing&&this.editable&&(this.canvas&&(this.canvas.calcOffset(),this.canvas.textEditingManager.exitTextEditing()),this.isEditing=!0,this.initHiddenTextarea(),this.hiddenTextarea.focus(),this.hiddenTextarea.value=this.text,this._updateTextarea(),this._saveEditingProps(),this._setEditingProps(),this._textBeforeEdit=this.text,this._tick(),this.fire("editing:entered",t?{e:t}:void 0),this._fireSelectionChanged(),this.canvas&&(this.canvas.fire("text:editing:entered",{target:this,e:t}),this.canvas.requestRenderAll()))}updateSelectionOnMouseMove(t){if(this.getActiveControl())return;const e=this.hiddenTextarea;Is(e).activeElement!==e&&e.focus();const s=this.getSelectionStartFromPointer(t),i=this.selectionStart,n=this.selectionEnd;(s===this.__selectionStartOnMouseDown&&i!==n||i!==s&&n!==s)&&(s>this.__selectionStartOnMouseDown?(this.selectionStart=this.__selectionStartOnMouseDown,this.selectionEnd=s):(this.selectionStart=s,this.selectionEnd=this.__selectionStartOnMouseDown),this.selectionStart===i&&this.selectionEnd===n||(this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()))}_setEditingProps(){this.hoverCursor="text",this.canvas&&(this.canvas.defaultCursor=this.canvas.moveCursor="text"),this.borderColor=this.editingBorderColor,this.hasControls=this.selectable=!1,this.lockMovementX=this.lockMovementY=!0}fromStringToGraphemeSelection(t,e,s){const i=s.slice(0,t),n=this.graphemeSplit(i).length;if(t===e)return{selectionStart:n,selectionEnd:n};const r=s.slice(t,e);return{selectionStart:n,selectionEnd:n+this.graphemeSplit(r).length}}fromGraphemeToStringSelection(t,e,s){const i=s.slice(0,t).join("").length;return t===e?{selectionStart:i,selectionEnd:i}:{selectionStart:i,selectionEnd:i+s.slice(t,e).join("").length}}_updateTextarea(){if(this.cursorOffsetCache={},this.hiddenTextarea){if(!this.inCompositionMode){const t=this.fromGraphemeToStringSelection(this.selectionStart,this.selectionEnd,this._text);this.hiddenTextarea.selectionStart=t.selectionStart,this.hiddenTextarea.selectionEnd=t.selectionEnd}this.updateTextareaPosition()}}updateFromTextArea(){if(!this.hiddenTextarea)return;this.cursorOffsetCache={};const t=this.hiddenTextarea;this.text=t.value,this.set("dirty",!0),this.initDimensions(),this.setCoords();const e=this.fromStringToGraphemeSelection(t.selectionStart,t.selectionEnd,t.value);this.selectionEnd=this.selectionStart=e.selectionEnd,this.inCompositionMode||(this.selectionStart=e.selectionStart),this.updateTextareaPosition()}updateTextareaPosition(){if(this.selectionStart===this.selectionEnd){const t=this._calcTextareaPosition();this.hiddenTextarea.style.left=t.left,this.hiddenTextarea.style.top=t.top}}_calcTextareaPosition(){if(!this.canvas)return{left:"1px",top:"1px"};const t=this.inCompositionMode?this.compositionStart:this.selectionStart,e=this._getCursorBoundaries(t),s=this.get2DCursorLocation(t),i=s.lineIndex,n=s.charIndex,r=this.getValueOfPropertyAt(i,n,"fontSize")*this.lineHeight,o=e.leftOffset,h=this.getCanvasRetinaScaling(),l=this.canvas.upperCanvasEl,u=l.width/h,d=l.height/h,f=u-r,g=d-r,p=new D(e.left+o,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>f&&(p.x=f),p.y<0&&(p.y=0),p.y>g&&(p.y=g),p.x+=this.canvas._offset.left,p.y+=this.canvas._offset.top,{left:"".concat(p.x,"px"),top:"".concat(p.y,"px"),fontSize:"".concat(r,"px"),charHeight:r}}_saveEditingProps(){this._savedProps={hasControls:this.hasControls,borderColor:this.borderColor,lockMovementX:this.lockMovementX,lockMovementY:this.lockMovementY,hoverCursor:this.hoverCursor,selectable:this.selectable,defaultCursor:this.canvas&&this.canvas.defaultCursor,moveCursor:this.canvas&&this.canvas.moveCursor}}_restoreEditingProps(){this._savedProps&&(this.hoverCursor=this._savedProps.hoverCursor,this.hasControls=this._savedProps.hasControls,this.borderColor=this._savedProps.borderColor,this.selectable=this._savedProps.selectable,this.lockMovementX=this._savedProps.lockMovementX,this.lockMovementY=this._savedProps.lockMovementY,this.canvas&&(this.canvas.defaultCursor=this._savedProps.defaultCursor||this.canvas.defaultCursor,this.canvas.moveCursor=this._savedProps.moveCursor||this.canvas.moveCursor),delete this._savedProps)}_exitEditing(){const t=this.hiddenTextarea;this.selected=!1,this.isEditing=!1,t&&(t.blur&&t.blur(),t.parentNode&&t.parentNode.removeChild(t)),this.hiddenTextarea=null,this.abortCursorAnimation(),this.selectionStart!==this.selectionEnd&&this.clearContextTop()}exitEditing(){const t=this._textBeforeEdit!==this.text;return this._exitEditing(),this.selectionEnd=this.selectionStart,this._restoreEditingProps(),this._forceClearCache&&(this.initDimensions(),this.setCoords()),this.fire("editing:exited"),t&&this.fire(Sc),this.canvas&&(this.canvas.fire("text:editing:exited",{target:this}),t&&this.canvas.fire("object:modified",{target:this})),this}_removeExtraneousStyles(){for(const t in this.styles)this._textLines[t]||delete this.styles[t]}removeStyleFromTo(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t,!0),{lineIndex:n,charIndex:r}=this.get2DCursorLocation(e,!0);if(s!==n){if(this.styles[s])for(let o=i;o<this._unwrappedTextLines[s].length;o++)delete this.styles[s][o];if(this.styles[n])for(let o=r;o<this._unwrappedTextLines[n].length;o++){const h=this.styles[n][o];h&&(this.styles[s]||(this.styles[s]={}),this.styles[s][i+o-r]=h)}for(let o=s+1;o<=n;o++)delete this.styles[o];this.shiftLineStyles(n,s-n)}else if(this.styles[s]){const o=this.styles[s],h=r-i;for(let l=i;l<r;l++)delete o[l];for(const l in this.styles[s]){const u=parseInt(l,10);u>=r&&(o[u-h]=o[l],delete o[l])}}}shiftLineStyles(t,e){const s=Object.assign({},this.styles);for(const i in this.styles){const n=parseInt(i,10);n>t&&(this.styles[n+e]=s[n],s[n-e]||delete this.styles[n])}}insertNewlineStyleObject(t,e,s,i){const n={},r=this._unwrappedTextLines[t].length,o=r===e;let h=!1;s||(s=1),this.shiftLineStyles(t,s);const l=this.styles[t]?this.styles[t][e===0?e:e-1]:void 0;for(const d in this.styles[t]){const f=parseInt(d,10);f>=e&&(h=!0,n[f-e]=this.styles[t][d],o&&e===0||delete this.styles[t][d])}let u=!1;for(h&&!o&&(this.styles[t+s]=n,u=!0),(u||r>e)&&s--;s>0;)i&&i[s-1]?this.styles[t+s]={0:E({},i[s-1])}: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 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=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 Pw extends Ow{initHiddenTextarea(){const t=this.canvas&&Is(this.canvas.getElement())||jo(),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(wc),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(this.hiddenTextarea.value==="")return this.styles={},void s();const i=this._splitTextIntoLines(this.hiddenTextarea.value).graphemeText,n=this._text.length,r=i.length,o=this.selectionStart,h=this.selectionEnd,l=o!==h;let u,d,f,g,p=r-n;const m=this.fromStringToGraphemeSelection(this.hiddenTextarea.selectionStart,this.hiddenTextarea.selectionEnd,this.hiddenTextarea.value),_=o>m.selectionStart;l?(d=this._text.slice(o,h),p+=h-o):r<n&&(d=_?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])),l?(f=o,g=h):_?(f=h-d.length,g=h):(f=h,g=h+d.length),this.removeStyleFromTo(f,g)),b.length){const{copyPasteData:x}=oi();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}=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,o=this._getWidthBeforeCursor(n,r),h=this._getIndexOnLine(n+1,o);return this._textLines[n].slice(r).length+h+1+this.missingNewlineOffset(n)}_getSelectionForOffset(t,e){return t.shiftKey&&this.selectionStart!==this.selectionEnd&&e?this.selectionEnd:this.selectionStart}getUpCursorOffset(t,e){const s=this._getSelectionForOffset(t,e),i=this.get2DCursorLocation(s),n=i.lineIndex;if(n===0||t.metaKey||t.keyCode===33)return-s;const r=i.charIndex,o=this._getWidthBeforeCursor(n,r),h=this._getIndexOnLine(n-1,o),l=this._textLines[n].slice(0,r),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),o=0;for(let h=0,l=s.length;h<l;h++)if(i=this.__charBounds[t][h].width,r+=i,r>e){n=!0;const u=r-i,d=r,f=Math.abs(u-e);o=Math.abs(d-e)<f?h:h-1;break}return n||(o=s.length-1),o}moveCursorDown(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorUpOrDown("Down",t)}moveCursorUp(t){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorUpOrDown("Up",t)}_moveCursorUpOrDown(t,e){const s=this["get".concat(t,"CursorOffset")](e,this._selectionDirection===Vt);if(e.shiftKey?this.moveCursorWithShift(s):this.moveCursorWithoutShift(s),s!==0){const i=this.text.length;this.selectionStart=br(0,this.selectionStart,i),this.selectionEnd=br(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 kf=a=>!!a.button;class Dw extends Pw{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 Mw(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),Jd(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&&!kf(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&&!kf(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||kf(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($e(this.calcTransformMatrix())).add(new D(-this._getLeftOffset(),-this._getTopOffset()));let s=0,i=0,n=0;for(let l=0;l<this._textLines.length&&s<=e.y;l++)s+=this.getHeightOfLine(l),n=l,l>0&&(i+=this._textLines[l-1].length+this.missingNewlineOffset(l-1));let r=Math.abs(this._getLineLeftOffset(n));const o=this._textLines[n].length,h=this.__charBounds[n];for(let l=0;l<o;l++){const 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?o-i:i,this._text.length)}}const Qc="moveCursorUp",Zc="moveCursorDown",tu="moveCursorLeft",eu="moveCursorRight",su="exitEditing",Rw=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:su,27:su,33:Qc,34:Zc,35:eu,36:tu,37:tu,38:Qc,39:eu,40:Zc},keysMapRtl:{9:su,27:su,33:Qc,34:Zc,35:tu,36:eu,37:eu,38:Qc,39:tu,40:Zc},ctrlKeysMapDown:{65:"selectAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}},{_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1});class Bi extends Dw{static getDefaults(){return E(E({},super.getDefaults()),Bi.ownDefaults)}get type(){const t=super.type;return t==="itext"?"i-text":t}constructor(t,e){super(t,E(E({},Bi.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 Sf&&this.canvas.textEditingManager.remove(this),e instanceof Sf&&e.textEditingManager.add(this)),super._set(t,e))}setSelectionStart(t){t=Math.max(t,0),this._updateAndFire("selectionStart",t)}setSelectionEnd(t){t=Math.min(t,this.text.length),this._updateAndFire("selectionEnd",t)}_updateAndFire(t,e){this[t]!==e&&(this._fireSelectionChanged(),this[t]=e),this._updateTextarea()}_fireSelectionChanged(){this.fire("selection:changed"),this.canvas&&this.canvas.fire("text:selection:changed",{target:this})}initDimensions(){this.isEditing&&this.initDelayedCursor(),super.initDimensions()}getSelectionStyles(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart||0,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionEnd,s=arguments.length>2?arguments[2]:void 0;return super.getSelectionStyles(t,e,s)}setSelectionStyles(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionStart||0,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.selectionEnd;return super.setSelectionStyles(t,e,s)}get2DCursorLocation(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;return super.get2DCursorLocation(t,e)}render(t){super.render(t),this.cursorOffsetCache={},this.renderCursorOrSelection()}toCanvasElement(t){const e=this.isEditing;this.isEditing=!1;const s=super.toCanvasElement(t);return this.isEditing=e,s}renderCursorOrSelection(){if(!this.isEditing)return;const t=this.clearContextTop(!0);if(!t)return;const e=this._getCursorBoundaries();this.selectionStart===this.selectionEnd?this.renderCursor(t,e):this.renderSelection(t,e),this.canvas.contextTopDirty=!0,t.restore()}_getCursorBoundaries(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;const s=this._getLeftOffset(),i=this._getTopOffset(),n=this._getCursorBoundariesOffsets(t,e);return{left:s,top:i,leftOffset:n.left,topOffset:n.top}}_getCursorBoundariesOffsets(t,e){return e?this.__getCursorBoundariesOffsets(t):this.cursorOffsetCache&&"top"in this.cursorOffsetCache?this.cursorOffsetCache:this.cursorOffsetCache=this.__getCursorBoundariesOffsets(t)}__getCursorBoundariesOffsets(t){let e=0,s=0;const{charIndex:i,lineIndex:n}=this.get2DCursorLocation(t);for(let l=0;l<n;l++)e+=this.getHeightOfLine(l);const r=this._getLineLeftOffset(n),o=this.__charBounds[n][i];o&&(s=o.left),this.charSpacing!==0&&i===this._textLines[n].length&&(s-=this._getWidthOfCharSpacing());const h={top:e,left:r+(s>0?s:0)};return this.direction==="rtl"&&(this.textAlign===Vt||this.textAlign===ci||this.textAlign===Th?h.left*=-1:this.textAlign===mt||this.textAlign===Jc?h.left=r-(s>0?s:0):this.textAlign!==st&&this.textAlign!==Eh||(h.left=r-(s>0?s:0))),h}renderCursorAt(t){const e=this._getCursorBoundaries(t,!0);this._renderCursor(this.canvas.contextTop,e,t)}renderCursor(t,e){this._renderCursor(t,e,this.selectionStart)}_renderCursor(t,e,s){const i=this.get2DCursorLocation(s),n=i.lineIndex,r=i.charIndex>0?i.charIndex-1:0,o=this.getValueOfPropertyAt(n,r,"fontSize"),h=this.getObjectScaling().x*this.canvas.getZoom(),l=this.cursorWidth/h,u=this.getValueOfPropertyAt(n,r,"deltaY"),d=e.topOffset+(1-this._fontSizeFraction)*this.getHeightOfLine(n)/this.lineHeight-o*(1-this._fontSizeFraction);this.inCompositionMode&&this.renderSelection(t,e),t.fillStyle=this.cursorColor||this.getValueOfPropertyAt(n,r,Gt),t.globalAlpha=this._currentCursorOpacity,t.fillRect(e.left+e.leftOffset-l/2,d+e.top+u,l,o)}renderSelection(t,e){const s={selectionStart:this.inCompositionMode?this.hiddenTextarea.selectionStart:this.selectionStart,selectionEnd:this.inCompositionMode?this.hiddenTextarea.selectionEnd:this.selectionEnd};this._renderSelection(t,s,e)}renderDragSourceEffect(){const t=this.draggableTextDelegate.getDragStartSelection();this._renderSelection(this.canvas.contextTop,t,this._getCursorBoundaries(t.selectionStart,!0))}renderDropTargetEffect(t){const e=this.getSelectionStartFromPointer(t);this.renderCursorAt(e)}_renderSelection(t,e,s){const i=e.selectionStart,n=e.selectionEnd,r=this.textAlign.includes(ci),o=this.get2DCursorLocation(i),h=this.get2DCursorLocation(n),l=o.lineIndex,u=h.lineIndex,d=o.charIndex<0?0:o.charIndex,f=h.charIndex<0?0:h.charIndex;for(let g=l;g<=u;g++){const p=this._getLineLeftOffset(g)||0;let m=this.getHeightOfLine(g),_=0,b=0,x=0;if(g===l&&(b=this.__charBounds[l][d].left),g>=l&&g<u)x=r&&!this.isEndOfWrapping(g)?this.width:this.getLineWidth(g)||5;else if(g===u)if(f===0)x=this.__charBounds[u][f].left;else{const M=this._getWidthOfCharSpacing();x=this.__charBounds[u][f-1].left+this.__charBounds[u][f-1].width-M}_=m,(this.lineHeight<1||g===u&&this.lineHeight>1)&&(m/=this.lineHeight);let C=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===ci||this.textAlign===Th?C=this.width-C-P:this.textAlign===mt||this.textAlign===Jc?C=s.left+p-x:this.textAlign!==st&&this.textAlign!==Eh||(C=s.left+p-x)),t.fillRect(C,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,Gt)}_getCurrentCharIndex(){const t=this.get2DCursorLocation(this.selectionStart,!0),e=t.charIndex>0?t.charIndex-1:0;return{l:t.lineIndex,c:e}}dispose(){this._exitEditing(),this.draggableTextDelegate.dispose(),super.dispose()}}T(Bi,"ownDefaults",Rw),T(Bi,"type","IText"),V.setClass(Bi),V.setClass(Bi,"i-text");class xr extends Bi{static getDefaults(){return E(E({},super.getDefaults()),xr.ownDefaults)}constructor(t,e){super(t,E(E({},xr.ownDefaults),e))}static createControls(){return{controls:v_()}}initDimensions(){this.initialized&&(this.isEditing&&this.initDelayedCursor(),this._clearCache(),this.dynamicMinWidth=0,this._styleMap=this._generateStyleMap(this._splitText()),this.dynamicMinWidth>this.width&&this._set("width",this.dynamicMinWidth),this.textAlign.includes(ci)&&this.enlargeSpaces(),this.height=this.calcTextHeight())}_generateStyleMap(t){let e=0,s=0,i=0;const n={};for(let r=0;r<t.graphemeLines.length;r++)t.graphemeText[i]===`
|
|
86
|
-
`&&r>0?(s=0,i++,e++):!this.splitByGrapheme&&this._reSpaceAndTab.test(t.graphemeText[i])&&r>0&&(s++,i++),n[r]={line:e,offset:s},i+=t.graphemeLines[r].length,s+=t.graphemeLines[r].length;return n}styleHas(t,e){if(this._styleMap&&!this.isWrapping){const s=this._styleMap[e];s&&(e=s.line)}return super.styleHas(t,e)}isEmptyStyles(t){if(!this.styles)return!0;let e,s=0,i=t+1,n=!1;const r=this._styleMap[t],o=this._styleMap[t+1];r&&(t=r.line,s=r.offset),o&&(i=o.line,n=i===t,e=o.offset);const h=t===void 0?this.styles:{line:this.styles[t]};for(const l in h)for(const u in h[l]){const d=parseInt(u,10);if(d>=s&&(!n||d<e))for(const f 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 o=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,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,l=[],u=h?"":" ";let d=0,f=[],g=0,p=0,m=!0;e-=r;const _=Math.max(e,i,this.dynamicMinWidth),b=n[t];let x;for(g=0,x=0;x<b.length;x++){const{word:C,width:A}=b[x];g+=C.length,d+=p+A-o,d>_&&!m?(l.push(f),f=[],d=A,m=!0):d+=o,m||h||f.push(u),f=f.concat(C),p=h?0:this._measureWord([u],t,g),g++,m=!1}return x&&l.push(f),i+r>this.dynamicMinWidth&&(this.dynamicMinWidth=i-o+r),l}isEndOfWrapping(t){return!this._styleMap[t+1]||this._styleMap[t+1].line!==this._styleMap[t].line}missingNewlineOffset(t,e){return this.splitByGrapheme&&!e?this.isEndOfWrapping(t)?1:0:1}_splitTextIntoLines(t){const e=super._splitTextIntoLines(t),s=this._wrapText(e.lines,this.width),i=new Array(s.length);for(let n=0;n<s.length;n++)i[n]=s[n].join("");return e.lines=i,e.graphemeLines=s,e}getMinWidth(){return Math.max(this.minWidth,this.dynamicMinWidth)}_removeExtraneousStyles(){const t=new Map;for(const e in this._styleMap){const s=parseInt(e,10);if(this._textLines[s]){const i=this._styleMap[e].line;t.set("".concat(i),!0)}}for(const e in this.styles)t.has(e)||delete this.styles[e]}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject(["minWidth","splitByGrapheme",...t])}}T(xr,"type","Textbox"),T(xr,"textLayoutProperties",[...Bi.textLayoutProperties,"width"]),T(xr,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),V.setClass(xr);class T0 extends Gc{shouldPerformLayout(t){return!!t.target.clipPath&&super.shouldPerformLayout(t)}shouldLayoutClipPath(){return!1}calcLayoutResult(t,e){const{target:s}=t,{clipPath:i,group:n}=s;if(!i||!this.shouldPerformLayout(t))return;const{width:r,height:o}=ai(Km(s,i)),h=new D(r,o);if(i.absolutePositioned)return{center:vr(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(T0,"type","clip-path"),V.setClass(T0);class E0 extends Gc{getInitialSize(t,e){let{target:s}=t,{size:i}=e;return new D(s.width||i.x,s.height||i.y)}}T(E0,"type","fixed"),V.setClass(E0);class Fw extends Sh{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 Sr extends li{static getDefaults(){return E(E({},super.getDefaults()),Sr.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,Sr.ownDefaults),this.setOptions(e);const{left:s,top:i,layoutManager:n}=e;this.groupInit(t,{left:s,top:i,layoutManager:n??new Fw})}_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))?(Oi("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===bf?s.forEach(i=>{i._onAfterObjectsChange(zc,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(Sr,"type","ActiveSelection"),T(Sr,"ownDefaults",{multiSelectionStacking:"canvas-stacking"}),V.setClass(Sr),V.setClass(Sr,"activeSelection");class Lw{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(l=>{l.applyTo(o)});const{imageData:h}=o;return h.width===s&&h.height===i||(n.width=h.width,n.height=h.height),r.putImageData(h,0,0),o}}class k0{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=Ut();s.width=t,s.height=e;const i=s.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,depth:!1,stencil:!1,antialias:!1});i&&(i.clearColor(0,0,0,0),this.canvas=s,this.gl=i)}applyFilters(t,e,s,i,n,r){const o=this.gl,h=n.getContext("2d");if(!o||!h)return;let l;r&&(l=this.getCachedTexture(r,e));const 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,l?void 0:e),targetTexture:this.createTexture(o,s,i),originalTexture:l||this.createTexture(o,s,i,l?void 0:e),passes:t.length,webgl:!0,aPosition:this.aPosition,programCache:this.programCache,pass:0,filterBackend:this,targetCanvas:n},d=o.createFramebuffer();return o.bindFramebuffer(o.FRAMEBUFFER,d),t.forEach(f=>{f&&f.applyTo(u)}),function(f){const g=f.targetCanvas,p=g.width,m=g.height,_=f.destinationWidth,b=f.destinationHeight;p===_&&m===b||(g.width=_,g.height=b)}(u),this.copyGLTo2D(o,u),o.bindTexture(o.TEXTURE_2D,null),o.deleteTexture(u.sourceTexture),o.deleteTexture(u.targetTexture),o.deleteFramebuffer(d),h.setTransform(1,0,0,1,0,0),u}dispose(){this.canvas&&(this.canvas=null,this.gl=null),this.clearWebGLCaches()}clearWebGLCaches(){this.programCache={},this.textureCache={}}createTexture(t,e,s,i,n){const{NEAREST:r,TEXTURE_2D:o,RGBA:h,UNSIGNED_BYTE:l,CLAMP_TO_EDGE:u,TEXTURE_MAG_FILTER:d,TEXTURE_MIN_FILTER:f,TEXTURE_WRAP_S:g,TEXTURE_WRAP_T:p}=t,m=t.createTexture();return t.bindTexture(o,m),t.texParameteri(o,d,n||r),t.texParameteri(o,f,n||r),t.texParameteri(o,g,u),t.texParameteri(o,p,u),i?t.texImage2D(o,0,h,h,l,i):t.texImage2D(o,0,h,e,s,0,h,l,null),m}getCachedTexture(t,e,s){const{textureCache:i}=this;if(i[t])return i[t];{const n=this.createTexture(this.gl,e.width,e.height,e,s);return n&&(i[t]=n),n}}evictCachesForKey(t){this.textureCache[t]&&(this.gl.deleteTexture(this.textureCache[t]),delete this.textureCache[t])}copyGLTo2D(t,e){const s=t.canvas,i=e.targetCanvas,n=i.getContext("2d");if(!n)return;n.translate(0,i.height),n.scale(1,-1);const r=s.height-i.height;n.drawImage(s,0,r,i.width,i.height,0,0,i.width,i.height)}copyGLTo2DPutImageData(t,e){const s=e.targetCanvas.getContext("2d"),i=e.destinationWidth,n=e.destinationHeight,r=i*n*4;if(!s)return;const o=new Uint8Array(this.imageBuffer,0,r),h=new Uint8ClampedArray(this.imageBuffer,0,r);t.readPixels(0,0,i,n,t.RGBA,t.UNSIGNED_BYTE,o);const l=new ImageData(h,i,n);s.putImageData(l,0,0)}captureGPUInfo(){if(this.gpuInfo)return this.gpuInfo;const t=this.gl,e={renderer:"",vendor:""};if(!t)return e;const s=t.getExtension("WEBGL_debug_renderer_info");if(s){const i=t.getParameter(s.UNMASKED_RENDERER_WEBGL),n=t.getParameter(s.UNMASKED_VENDOR_WEBGL);i&&(e.renderer=i.toLowerCase()),n&&(e.vendor=n.toLowerCase())}return this.gpuInfo=e,e}}let Mf;function Iw(){const{WebGLProbe:a}=oi();return a.queryWebGL(Ut()),dt.enableGLFiltering&&a.isSupported(dt.textureSize)?new k0({tileSize:dt.textureSize}):new Lw}function Of(){return!Mf&&(!(arguments.length>0&&arguments[0]!==void 0)||arguments[0])&&(Mf=Iw()),Mf}const jw=["filters","resizeFilter","src","crossOrigin","type"],M0=["cropX","cropY"];class Ae extends Se{static getDefaults(){return E(E({},super.getDefaults()),Ae.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,Ae.ownDefaults),this.setOptions(e),this.cacheKey="texture".concat(Tn()),this.setElement(typeof t=="string"?(this.canvas&&Is(this.canvas.getElement())||jo()).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(Ae.CSS_CANVAS),this.filters.length!==0&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){const e=Of(!1);e instanceof k0&&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([...M0,...t])),{},{src:this.getSrc(),crossOrigin:this.getCrossOrigin(),filters:e},this.resizeFilter?{resizeFilter:this.resizeFilter.toObject()}:{})}hasCrop(){return!!this.cropX||!!this.cropY||this.width<this._element.width||this.height<this._element.height}_toSVG(){const t=[],e=this._element,s=-this.width/2,i=-this.height/2;let n=[],r=[],o="",h="";if(!e)return[];if(this.hasCrop()){const l=Tn();n.push('<clipPath id="imageCrop_'+l+`">
|
|
74
|
+
`),s.join("")}toLive(t){const{x1:e,y1:s,x2:i,y2:n,r1:r,r2:a}=this.coords,h=this.type==="linear"?t.createLinearGradient(e,s,i,n):t.createRadialGradient(e,s,r,i,n,a);return this.colorStops.forEach(l=>{let{color:u,opacity:d,offset:g}=l;h.addColorStop(g,d!==void 0?new yt(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=v0(t),n=e._findCenterFromElement();return new this(E({id:t.getAttribute("id")||void 0,type:m0(t),coords:mw(t,{width:s.viewBoxWidth||s.width,height:s.viewBoxHeight||s.height}),colorStops:pw(t,s.opacity),gradientUnits:i,gradientTransform:zc(t.getAttribute("gradientTransform")||"")},i==="pixels"?{offsetX:e.width/2-n.x,offsetY:e.height/2-n.y}:{offsetX:0,offsetY:0}))}}T(Th,"type","Gradient"),V.setClass(Th,"gradient"),V.setClass(Th,"linear"),V.setClass(Th,"radial");const vw=["type","source","patternTransform"];class Cg{get type(){return"pattern"}set type(t){Pi("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=En(),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({},mr(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,a=Ja(this.offsetX/e,0),h=Ja(this.offsetY/s,0),l=n==="repeat-y"||n==="no-repeat"?1+Math.abs(a||0):Ja(i.width/e,0),u=n==="repeat-x"||n==="no-repeat"?1+Math.abs(h||0):Ja(i.height/s,0);return['<pattern id="SVGID_'.concat(r,'" x="').concat(a,'" y="').concat(h,'" width="').concat(l,'" 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=Pt(t,vw);const a=await mh(i,E(E({},e),{},{crossOrigin:r.crossOrigin}));return new this(E(E({},r),{},{patternTransform:n&&n.slice(0),source:a}))}}T(Cg,"type","Pattern"),V.setClass(Cg),V.setClass(Cg,"pattern");const bw=["path","left","top"],yw=["d"];class _r extends xe{constructor(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{path:s,left:i,top:n}=e,r=Pt(e,bw);super(),Object.assign(this,_r.ownDefaults),this.setOptions(r),this._setPath(t||[],!0),typeof i=="number"&&this.set(mt,i),typeof n=="number"&&this.set(Ue,n)}_setPath(t,e){this.path=s0(Array.isArray(t)?t:c0(t)),this.setBoundingBox(e)}_findCenterFromElement(){const t=this._calcBoundsFromPath();return new D(t.left+t.width/2,t.top+t.height/2)}_renderPathCommands(t){const e=-this.pathOffset.x,s=-this.pathOffset.y;t.beginPath();for(const i of this.path)switch(i[0]){case"L":t.lineTo(i[1]+e,i[2]+s);break;case"M":t.moveTo(i[1]+e,i[2]+s);break;case"C":t.bezierCurveTo(i[1]+e,i[2]+s,i[3]+e,i[4]+s,i[5]+e,i[6]+s);break;case"Q":t.quadraticCurveTo(i[1]+e,i[2]+s,i[3]+e,i[4]+s);break;case"Z":t.closePath()}}_render(t){this._renderPathCommands(t),this._renderPaintInOrder(t)}toString(){return"#<Path (".concat(this.complexity(),'): { "top": ').concat(this.top,', "left": ').concat(this.left," }>")}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return 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=u0(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,st,st)}_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(...wg(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(...wg(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 hi(t)}_calcDimensions(){const t=this._calcBoundsFromPath();return E(E({},t),{},{pathOffset:new D(t.left+t.width/2,t.top+t.height/2)})}static fromObject(t){return this._fromObject(t,{extraParam:"path"})}static async fromElement(t,e,s){const i=Ii(t,this.ATTRIBUTE_NAMES,s),{d:n}=i;return new this(n,E(E(E({},Pt(i,yw)),e),{},{left:void 0,top:void 0}))}}T(_r,"type","Path"),T(_r,"cacheProperties",[...Fi,"path","fillRule"]),T(_r,"ATTRIBUTE_NAMES",[...Mn,"d"]),V.setClass(_r),V.setSVGClass(_r);const _w=["left","top","radius"],b0=["radius","startAngle","endAngle","counterClockwise"];class Ni extends xe{static getDefaults(){return E(E({},super.getDefaults()),Ni.ownDefaults)}constructor(t){super(),Object.assign(this,Ni.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,Wt(this.startAngle),Wt(this.endAngle),this.counterClockwise),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get(Fe)}getRadiusY(){return this.get("radius")*this.get(is)}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([...b0,...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=Wt(this.startAngle),i=Wt(this.endAngle),n=Fs(s)*e,r=Ls(s)*e,a=Fs(i)*e,h=Ls(i)*e,l=t>180?1:0,u=this.counterClockwise?0:1;return['<path d="M '.concat(n," ").concat(r," A ").concat(e," ").concat(e," 0 ").concat(l," ").concat(u," ").concat(a," ").concat(h,'" '),"COMMON_PARTS",` />
|
|
78
|
+
`]}}static async fromElement(t,e,s){const i=Ii(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,radius:a=0}=i;return new this(E(E({},Pt(i,_w)),{},{radius:a,left:n-a,top:r-a}))}static fromObject(t){return super._fromObject(t)}}T(Ni,"type","Circle"),T(Ni,"cacheProperties",[...Fi,...b0]),T(Ni,"ownDefaults",{radius:0,startAngle:0,endAngle:360,counterClockwise:!1}),T(Ni,"ATTRIBUTE_NAMES",["cx","cy","r",...Mn]),V.setClass(Ni),V.setSVGClass(Ni);const ww=["x1","y1","x2","y2"],xw=["x1","y1","x2","y2"],Ag=["x1","x2","y1","y2"];class wr extends xe{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,wr.ownDefaults),this.setOptions(n),this.x1=t,this.x2=s,this.y1=e,this.y2=i,this._setWidthHeight();const{left:r,top:a}=n;typeof r=="number"&&this.set(mt,r),typeof a=="number"&&this.set(Ue,a)}_setWidthHeight(){const{x1:t,y1:e,x2:s,y2:i}=this;this.width=Math.abs(s-t),this.height=Math.abs(i-e);const{left:n,top:r,width:a,height:h}=hi([{x:t,y:e},{x:s,y:i}]),l=new D(n+a/2,r+h/2);this.setPositionByOrigin(l,st,st)}_set(t,e){return super._set(t,e),Ag.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;bs(this.stroke)?t.strokeStyle=this.stroke.toLive(t):t.strokeStyle=(i=this.stroke)!==null&&i!==void 0?i:t.fillStyle,this.stroke&&this._renderStroke(t),t.strokeStyle=s}_findCenterFromElement(){return new D((this.x1+this.x2)/2,(this.y1+this.y2)/2)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return 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,a=t<=e?-1:1,h=s<=i?-1:1;return{x1:a*n/2,x2:a*-n/2,y1:h*r/2,y2:h*-r/2}}_toSVG(){const{x1:t,x2:e,y1:s,y2:i}=this.calcLinePoints();return["<line ","COMMON_PARTS",'x1="'.concat(t,'" y1="').concat(s,'" x2="').concat(e,'" y2="').concat(i,`" />
|
|
79
|
+
`)]}static async fromElement(t,e,s){const i=Ii(t,this.ATTRIBUTE_NAMES,s),{x1:n=0,y1:r=0,x2:a=0,y2:h=0}=i;return new this([n,r,a,h],Pt(i,ww))}static fromObject(t){let{x1:e,y1:s,x2:i,y2:n}=t,r=Pt(t,xw);return this._fromObject(E(E({},r),{},{points:[e,s,i,n]}),{extraParam:"points"})}}T(wr,"type","Line"),T(wr,"cacheProperties",[...Fi,...Ag]),T(wr,"ATTRIBUTE_NAMES",Mn.concat(Ag)),V.setClass(wr),V.setSVGClass(wr);class xr extends xe{static getDefaults(){return E(E({},super.getDefaults()),xr.ownDefaults)}constructor(t){super(),Object.assign(this,xr.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(xr,"type","Triangle"),T(xr,"ownDefaults",{width:100,height:100}),V.setClass(xr),V.setSVGClass(xr);const y0=["rx","ry"];class Bi extends xe{static getDefaults(){return E(E({},super.getDefaults()),Bi.ownDefaults)}constructor(t){super(),Object.assign(this,Bi.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(Fe)}getRy(){return this.get("ry")*this.get(is)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...y0,...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,Di,!1),t.restore(),this._renderPaintInOrder(t)}static async fromElement(t,e,s){const i=Ii(t,this.ATTRIBUTE_NAMES,s);return i.left=(i.left||0)-i.rx,i.top=(i.top||0)-i.ry,new this(i)}}function Sw(o){if(!o)return[];const t=o.replace(/,/g," ").trim().split(/\s+/),e=[];for(let s=0;s<t.length;s+=2)e.push({x:parseFloat(t[s]),y:parseFloat(t[s+1])});return e}T(Bi,"type","Ellipse"),T(Bi,"cacheProperties",[...Fi,...y0]),T(Bi,"ownDefaults",{rx:0,ry:0}),T(Bi,"ATTRIBUTE_NAMES",[...Mn,"cx","cy","rx","ry"]),V.setClass(Bi),V.setSVGClass(Bi);const Cw=["left","top"],_0={exactBoundingBox:!1};class Xs extends xe{static getDefaults(){return E(E({},super.getDefaults()),Xs.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,Xs.ownDefaults),this.setOptions(e),this.points=t;const{left:s,top:i}=e;this.initialized=!0,this.setBoundingBox(!0),typeof s=="number"&&this.set(mt,s),typeof i=="number"&&this.set(Ue,i)}isOpen(){return!0}_projectStrokeOnPoints(t){return Nm(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(l=>l.projectedPoint):this.points;if(e.length===0)return{left:0,top:0,width:0,height:0,pathOffset:new D,strokeOffset:new D,strokeDiff:new D};const s=hi(e),i=ph(E(E({},t),{},{scaleX:1,scaleY:1})),n=hi(this.points.map(l=>we(l,i,!0))),r=new D(this.scaleX,this.scaleY);let a=s.left+s.width/2,h=s.top+s.height/2;return this.exactBoundingBox&&(a-=h*Math.tan(Wt(this.skewX)),h-=a*Math.tan(Wt(this.skewY))),E(E({},s),{},{pathOffset:new D(a,h),strokeOffset:new D(n.left,n.top).subtract(new D(s.left,s.top)).multiply(r),strokeDiff:new D(s.width,s.height).subtract(new D(n.width,n.height)).multiply(r)})}_findCenterFromElement(){const t=hi(this.points);return new D(t.left+t.width/2,t.top+t.height/2)}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{left:e,top:s,width:i,height:n,pathOffset:r,strokeOffset:a,strokeDiff:h}=this._calcDimensions();this.set({width:i,height:n,pathOffset:r,strokeOffset:a,strokeDiff:h}),t&&this.setPositionByOrigin(new D(e+i/2,s+n/2),st,st)}isStrokeAccountedForInDimensions(){return this.exactBoundingBox}_getNonTransformedDimensions(){return this.exactBoundingBox?new D(this.width,this.height):super._getNonTransformedDimensions()}_getTransformedDimensions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(this.exactBoundingBox){let r;if(Object.keys(t).some(a=>this.strokeUniform||this.constructor.layoutProperties.includes(a))){var e,s;const{width:a,height:h}=this._calcDimensions(t);r=new D((e=t.width)!==null&&e!==void 0?e:a,(s=t.height)!==null&&s!==void 0?s:h)}else{var i,n;r=new D((i=t.width)!==null&&i!==void 0?i:this.width,(n=t.height)!==null&&n!==void 0?n:this.height)}return r.multiply(new D(t.scaleX||this.scaleX,t.scaleY||this.scaleY))}return super._getTransformedDimensions(t)}_set(t,e){const s=this.initialized&&this[t]!==e,i=super._set(t,e);return this.exactBoundingBox&&s&&((t===Fe||t===is)&&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(Sw(t.getAttribute("points")),E(E({},Pt(Ii(t,this.ATTRIBUTE_NAMES,s),Cw)),e))}static fromObject(t){return this._fromObject(t,{extraParam:"points"})}}T(Xs,"ownDefaults",_0),T(Xs,"type","Polyline"),T(Xs,"layoutProperties",[Na,Ba,"strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeWidth","strokeUniform","points"]),T(Xs,"cacheProperties",[...Fi,"points"]),T(Xs,"ATTRIBUTE_NAMES",[...Mn]),V.setClass(Xs),V.setSVGClass(Xs);class Jc extends Xs{isOpen(){return!1}}T(Jc,"ownDefaults",_0),T(Jc,"type","Polygon"),V.setClass(Jc),V.setSVGClass(Jc);const w0=["fontSize","fontWeight","fontFamily","fontStyle"],x0=["underline","overline","linethrough"],S0=[...w0,"lineHeight","text","charSpacing","textAlign","styles","path","pathStartOffset","pathSide","pathAlign"],C0=[...S0,...x0,"textBackgroundColor","direction"],Aw=[...w0,...x0,Le,"strokeWidth",$t,"deltaY","textBackgroundColor"],Tw={_reNewline:Wd,_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:mt,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:mt,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},ui="justify",Qc="justify-left",Eh="justify-right",kh="justify-center";class A0 extends xe{isEmptyStyles(t){if(!this.styles||t!==void 0&&!this.styles[t])return!0;const e=t===void 0?this.styles:{line:this.styles[t]};for(const s in e)for(const i in e[s])for(const n in e[s][i])return!1;return!0}styleHas(t,e){if(!this.styles||e!==void 0&&!this.styles[e])return!1;const s=e===void 0?this.styles:{0:this.styles[e]};for(const i in s)for(const n in s[i])if(s[i][n][t]!==void 0)return!0;return!1}cleanStyle(t){if(!this.styles)return!1;const e=this.styles;let s,i,n=0,r=!0,a=0;for(const h in e){s=0;for(const l in e[h]){const u=e[h][l]||{};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][l]}s===0&&delete e[h]}for(let h=0;h<this._textLines.length;h++)a+=this._textLines[h].length;r&&n===a&&(this[t]=i,this.removeStyle(t))}removeStyle(t){if(!this.styles)return;const e=this.styles;let s,i,n;for(i in e){for(n in s=e[i],s)delete s[n][t],Object.keys(s[n]).length===0&&delete s[n];Object.keys(s).length===0&&delete e[i]}}_extendStyles(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t);this._getLineStyle(s)||this._setLineStyle(s);const n=qd(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({},mr(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(A0,"_styleProperties",Aw);const Ew=/ +/g,kw=/"/g;function Tg(o,t,e,s,i){return" ".concat(function(n,r){let{left:a,top:h,width:l,height:u}=r,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:dt.NUM_FRACTION_DIGITS;const g=yh($t,n,!1),[f,p,m,_]=[a,h,l,u].map(b=>Dt(b,d));return"<rect ".concat(g,' x="').concat(f,'" y="').concat(p,'" width="').concat(m,'" height="').concat(_,'"></rect>')}(o,{left:t,top:e,width:s,height:i}),`
|
|
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([...C0,...t])),{},{styles:Hm(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=Ii(t,Se.ATTRIBUTE_NAMES,s),n=E(E({},e),i),{textAnchor:r=mt,textDecoration:a="",dx:h=0,dy:l=0,top:u=0,left:d=0,fontSize:g=Bd,strokeWidth:f=1}=n,p=Pt(n,Mw),m=new this((t.textContent||"").replace(/^\s+|\s+$|\n+/g,"").replace(/\s+/g," "),E({left:d+h,top:u+l,underline:a.includes("underline"),overline:a.includes("overline"),linethrough:a.includes("line-through"),strokeWidth:0,fontSize:g},p)),_=m.getScaledHeight()/m.height,b=((m.height+m.strokeWidth)*m.lineHeight-m.height)*_,x=m.getScaledHeight()+b;let S=0;return r===st&&(S=m.getScaledWidth()/2),r===Vt&&(S=m.getScaledWidth()),m.set({left:m.left-S,top:m.top-(x-m.fontSize*(.07+m._fontSizeFraction))/m.lineHeight,strokeWidth:f}),m}static fromObject(t){return this._fromObject(E(E({},t),{},{styles:Wm(t.styles||{},t.text)}),{extraParam:"text"})}}T(Se,"textLayoutProperties",S0),T(Se,"cacheProperties",[...Fi,...C0]),T(Se,"ownDefaults",Tw),T(Se,"type","Text"),T(Se,"genericFonts",["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong"]),T(Se,"ATTRIBUTE_NAMES",Mn.concat("x","y","dx","dy","font-family","font-style","font-weight","font-size","letter-spacing","text-decoration","text-anchor")),Fm(Se,[class extends fm{_toSVG(){const o=this._getSVGLeftTopOffsets(),t=this._getSVGTextAndBg(o.textTop,o.textLeft);return this._wrapSVGTextAndBg(t)}toSVG(o){return this._createBaseSVGMarkup(this._toSVG(),{reviver:o,noStyle:!0,withShadow:!0})}_getSVGLeftTopOffsets(){return{textLeft:-this.width/2,textTop:-this.height/2,lineTop:this.getHeightOfLine(0)}}_wrapSVGTextAndBg(o){let{textBgRects:t,textSpans:e}=o;const s=this.getSvgTextDecoration(this);return[t.join(""),' <text xml:space="preserve" ',this.fontFamily?'font-family="'.concat(this.fontFamily.replace(kw,"'"),'" '):"",this.fontSize?'font-size="'.concat(this.fontSize,'" '):"",this.fontStyle?'font-style="'.concat(this.fontStyle,'" '):"",this.fontWeight?'font-weight="'.concat(this.fontWeight,'" '):"",s?'text-decoration="'.concat(s,'" '):"",this.direction==="rtl"?'direction="'.concat(this.direction,'" '):"",'style="',this.getSvgStyles(!0),'"',this.addPaintOrder()," >",e.join(""),`</text>
|
|
84
|
+
`]}_getSVGTextAndBg(o,t){const e=[],s=[];let i,n=o;this.backgroundColor&&s.push(...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+`">
|
|
87
87
|
`,' <rect x="'+s+'" y="'+i+'" width="'+this.width+'" height="'+this.height+`" />
|
|
88
88
|
`,`</clipPath>
|
|
89
|
-
`),
|
|
89
|
+
`),a=' clip-path="url(#imageCrop_'+l+')" '}if(this.imageSmoothing||(h=' image-rendering="optimizeSpeed"'),t.push(" <image ","COMMON_PARTS",'xlink:href="'.concat(this.getSvgSrc(!0),'" x="').concat(s-this.cropX,'" y="').concat(i-this.cropY,'" width="').concat(e.width||e.naturalWidth,'" height="').concat(e.height||e.naturalHeight,'"').concat(h).concat(a,`></image>
|
|
90
90
|
`)),this.stroke||this.strokeDashArray){const l=this.fill;this.fill=null,r=[' <rect x="'.concat(s,'" y="').concat(i,'" width="').concat(this.width,'" height="').concat(this.height,'" style="').concat(this.getSvgStyles(),`" />
|
|
91
|
-
`)],this.fill=l}return n=this.paintFirst!==Gt?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 ph(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=Ut(),h=r.width,l=r.height;o.width=h,o.height=l,this._element=o,this._lastScaleX=t.scaleX=i,this._lastScaleY=t.scaleY=n,Of().applyFilters([t],r,h,l,this._element),this._filterScalingX=o.width/this._originalElement.width,this._filterScalingY=o.height/this._originalElement.height}applyFilters(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.filters||[];if(t=t.filter(n=>n&&!n.isNeutralState()),this.set("dirty",!0),this.removeTexture("".concat(this.cacheKey,"_filtered")),t.length===0)return this._element=this._originalElement,this._filteredEl=void 0,this._filterScalingX=1,void(this._filterScalingY=1);const e=this._originalElement,s=e.naturalWidth||e.width,i=e.naturalHeight||e.height;if(this._element===this._originalElement){const n=Ut();n.width=s,n.height=i,this._element=n,this._filteredEl=n}else this._filteredEl&&(this._element=this._filteredEl,this._filteredEl.getContext("2d").clearRect(0,0,s,i),this._lastScaleX=1,this._lastScaleY=1);Of().applyFilters(t,this._originalElement,s,i,this._element),this._originalElement.width===this._element.width&&this._originalElement.height===this._element.height||(this._filterScalingX=this._element.width/this._originalElement.width,this._filterScalingY=this._element.height/this._originalElement.height)}_render(t){t.imageSmoothingEnabled=this.imageSmoothing,this.isMoving!==!0&&this.resizeFilter&&this._needsResize()&&this.applyResizeFilters(),this._stroke(t),this._renderPaintInOrder(t)}drawCacheOnCanvas(t){t.imageSmoothingEnabled=this.imageSmoothing,super.drawCacheOnCanvas(t)}shouldCache(){return this.needsItsOwnCache()}_renderFill(t){const e=this._element;if(!e)return;const s=this._filterScalingX,i=this._filterScalingY,n=this.width,r=this.height,o=Math.max(this.cropX,0),h=Math.max(this.cropY,0),l=e.naturalWidth||e.width,u=e.naturalHeight||e.height,d=o*s,f=h*i,g=Math.min(n*s,l-d),p=Math.min(r*i,u-f),m=-n/2,_=-r/2,b=Math.min(n,l/s-o),x=Math.min(r,u/i-h);e&&t.drawImage(e,d,f,g,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=$d(this.preserveAspectRatio||""),e=this.width,s=this.height,i={width:e,height:s};let n,r=this._element.width,o=this._element.height,h=1,l=1,u=0,d=0,f=0,g=0;return!t||t.alignX===Fe&&t.alignY===Fe?(h=e/r,l=s/o):(t.meetOrSlice==="meet"&&(h=l=Qm(this._element,i),n=(e-r*h)/2,t.alignX==="Min"&&(u=-n),t.alignX==="Max"&&(u=n),n=(s-o*l)/2,t.alignY==="Min"&&(d=-n),t.alignY==="Max"&&(d=n)),t.meetOrSlice==="slice"&&(h=l=Zm(this._element,i),n=r-e/h,t.alignX==="Mid"&&(f=n/2),t.alignX==="Max"&&(f=n),n=o-s/l,t.alignY==="Mid"&&(g=n/2),t.alignY==="Max"&&(g=n),r=e/h,o=s/l)),{width:r,height:o,scaleX:h,scaleY:l,offsetLeft:u,offsetTop:d,cropX:f,cropY:g}}static fromObject(t,e){let{filters:s,resizeFilter:i,src:n,crossOrigin:r,type:o}=t,h=Pt(t,jw);return Promise.all([ph(n,E(E({},e),{},{crossOrigin:r})),s&&zo(s,e),i&&zo([i],e),mh(h,e)]).then(l=>{let[u,d=[],[f]=[],g={}]=l;return new this(u,E(E({},h),{},{src:n,filters:d,resizeFilter:f},g))})}static fromURL(t){let{crossOrigin:e=null,signal:s}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;return ph(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=Li(t,this.ATTRIBUTE_NAMES,s);return this.fromURL(i["xlink:href"],e,i).catch(n=>(Oi("log","Unable to parse Image",n),null))}}function Pf(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"),l=a.getAttribute("height"),u=a.getAttribute("x")||0,d=a.getAttribute("y")||0,f=!(t&&mm.test(t)),g=!h||!l||h==="100%"||l==="100%";let p="",m=0,_=0;if(f&&(u||d)&&a.parentNode&&a.parentNode.nodeName!=="#document"&&(p=" translate("+je(u||"0")+" "+je(d||"0")+") ",e=(a.getAttribute("transform")||"")+p,a.setAttribute("transform",e),a.removeAttribute("x"),a.removeAttribute("y")),f&&g)return{width:0,height:0};const b={width:0,height:0};if(f)return b.width=je(h),b.height=je(l),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,g?(b.width=C,b.height=A):(b.width=je(h),b.height=je(l),i=b.width/C,n=b.height/A);const k=$d(a.getAttribute("preserveAspectRatio")||"");if(k.alignX!==Fe&&(k.meetOrSlice==="meet"&&(n=i=i>n?n:i),k.meetOrSlice==="slice"&&(n=i=i>n?i:n),m=b.width-C*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&&o===0&&u===0&&d===0)return b;if((u||d)&&a.parentNode.nodeName!=="#document"&&(p=" translate("+je(u||"0")+" "+je(d||"0")+") "),e=p+" matrix("+i+" 0 0 "+n+" "+(r*i+m)+" "+(o*n+_)+") ",a.nodeName==="svg"){for(s=a.ownerDocument.createElementNS(ef,"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(Ae,"type","Image"),T(Ae,"cacheProperties",[...Ri,...M0]),T(Ae,"ownDefaults",{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),T(Ae,"CSS_CANVAS","canvas-img"),T(Ae,"ATTRIBUTE_NAMES",[...kn,"x","y","width","height","preserveAspectRatio","xlink:href","crossOrigin","image-rendering"]),V.setClass(Ae),V.setSVGClass(Ae);const iu=a=>a.tagName.replace("svg:",""),Nw=Dc(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);function O0(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 Bw=["gradientTransform","x1","x2","y1","y2","gradientUnits","cx","cy","r","fx","fy"],Df="xlink:href";function P0(a,t){var e;const s=((e=t.getAttribute(Df))===null||e===void 0?void 0:e.slice(1))||"",i=a.getElementById(s);if(i&&i.getAttribute(Df)&&P0(a,i),i&&(Bw.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(Df)}const Hw=["linearGradient","radialGradient","svg:linearGradient","svg:radialGradient"];function Ww(a){const t=a.getElementsByTagName("style");let e,s;const i={};for(e=0,s=t.length;e<s;e++){const n=(t[e].textContent||"").replace(/\/\*[\s\S]*?\*\//g,"");n.trim()!==""&&n.split("}").filter((r,o,h)=>h.length>1&&r.trim()).forEach(r=>{if((r.match(/{/g)||[]).length>1&&r.trim().startsWith("@"))return;const o=r.split("{"),h={},l=o[1].trim().split(";").filter(function(u){return u.trim()});for(e=0,s=l.length;e<s;e++){const u=l[e].split(":"),d=u[0].trim(),f=u[1].trim();h[d]=f}(r=o[0].trim()).split(",").forEach(u=>{(u=u.replace(/^svg/i,"").trim())!==""&&(i[u]=E(E({},i[u]||{}),h))})})}return i}const D0=a=>V.getSVGClass(iu(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=O0(r,Hw),h={};let l=o.length;for(;l--;){const u=o[l];u.getAttribute("xlink:href")&&P0(r,u);const d=u.getAttribute("id");d&&(h[d]=u)}return h}(i),this.cssRules=Ww(i)}parse(){return Promise.all(this.elements.map(t=>this.createObject(t)))}async createObject(t){const e=D0(t);if(e){const s=await e.fromElement(t,this.options,this.cssRules);return this.resolveGradient(s,t,Gt),this.resolveGradient(s,t,Ie),s instanceof Ae&&s._originalElement?qc(s,s.parsePreserveAspectRatioAttribute()):qc(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=Ah.fromElement(i,t,E(E({},this.options),{},{opacity:n}));t.set(s,r)}}async resolveClipPath(t,e){const s=this.extractPropertyDefinition(t,"clipPath",this.clipPaths);if(s){const i=$e(t.calcTransformMatrix()),n=s[0].parentElement;let r=e;for(;r.parentElement&&r.getAttribute("clip-path")!==t.clipPath;)r=r.parentElement;r.parentElement.appendChild(n);const o=Xc("".concat(r.getAttribute("transform")||""," ").concat(n.getAttribute("originalTransform")||""));n.setAttribute("transform","matrix(".concat(o.join(","),")"));const h=await Promise.all(s.map(b=>D0(b).fromElement(b,this.options,this.cssRules).then(x=>(qc(x),x.fillRule=x.clipRule,delete x.clipRule,x)))),l=h.length===1?h[0]:new li(h),u=Yt(i,l.calcTransformMatrix());l.clipPath&&await this.resolveClipPath(l,r);const{scaleX:d,scaleY:f,angle:g,skewX:p,translateX:m,translateY:_}=gr(u);l.set({flipX:!1,flipY:!1}),l.set({scaleX:d,scaleY:f,angle:g,skewX:p,skewY:0}),l.setPositionByOrigin(new D(m,_),st,st),t.clipPath=l}else delete t.clipPath}}const R0=a=>Wy.test(iu(a)),Rf=()=>({objects:[],elements:[],options:{},allElements:[]});async function zw(a,t){let{crossOrigin:e,signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(s&&s.aborted)return Oi("log",new Ld("parseSVGDocument")),Rf();const i=a.documentElement;(function(u){const d=O0(u,["use","svg:use"]),f=["x","y","xlink:href","href","transform"];for(const g of d){const p=g.attributes,m={};for(const R of p)R.value&&(m[R.name]=R.value);const _=(m["xlink:href"]||m.href||"").slice(1);if(_==="")return;const b=u.getElementById(_);if(b===null)return;let x=b.cloneNode(!0);const C=x.attributes,A={};for(const R of C)R.value&&(A[R.name]=R.value);const{x:k=0,y:P=0,transform:M=""}=m,O="".concat(M," ").concat(A.transform||""," translate(").concat(k,", ").concat(P,")");if(Pf(x),/^svg$/i.test(x.nodeName)){const R=x.ownerDocument.createElementNS(ef,"g");Object.entries(A).forEach(I=>{let[j,G]=I;return R.setAttributeNS(ef,j,G)}),R.append(...x.childNodes),x=R}for(const R of p){if(!R)continue;const{name:I,value:j}=R;if(!f.includes(I))if(I==="style"){const G={};vf(j,G),Object.entries(A).forEach(H=>{let[$,J]=H;G[$]=J}),vf(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"),g.parentNode.replaceChild(x,g)}})(a);const n=Array.from(i.getElementsByTagName("*")),r=E(E({},Pf(i)),{},{crossOrigin:e,signal:s}),o=n.filter(u=>(Pf(u),R0(u)&&!function(d){let f=d;for(;f&&(f=f.parentElement);)if(f&&f.nodeName&&Nw.test(iu(f))&&!f.getAttribute("instantiated_by_use"))return!0;return!1}(u)));if(!o||o&&!o.length)return E(E({},Rf()),{},{options:r,allElements:n});const h={};return n.filter(u=>iu(u)==="clipPath").forEach(u=>{u.setAttribute("originalTransform",u.getAttribute("transform")||"");const d=u.getAttribute("id");h[d]=Array.from(u.getElementsByTagName("*")).filter(f=>R0(f))}),{objects:await new Xw(o,r,t,a,h).parse(),elements:o,options:r,allElements:n}}function Vw(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return new Promise((s,i)=>{u0(a.replace(/^\n\s*/,"").trim(),{onComplete:n=>{const r=n.responseXML;r&&s(r),i()},signal:e.signal})}).then(s=>zw(s,t,e)).catch(()=>Rf())}const nu=a=>a.webgl!==void 0,Ff="precision highp float",Gw=`
|
|
92
|
-
`.concat(
|
|
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(Fg,`;
|
|
93
93
|
varying vec2 vTexCoord;
|
|
94
94
|
uniform sampler2D uTexture;
|
|
95
95
|
void main() {
|
|
96
96
|
gl_FragColor = texture2D(uTexture, vTexCoord);
|
|
97
|
-
}`),Uw=["type"],
|
|
97
|
+
}`),Uw=["type"],qw=["type"],$w=new RegExp(Fg,"g");class se{get type(){return this.constructor.type}constructor(){let t=Pt(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},Uw);Object.assign(this,this.constructor.defaults,t)}getFragmentSource(){return Yw}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"}}=oi();i!=="highp"&&(e=e.replace(
|
|
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"}}=oi();i!=="highp"&&(e=e.replace($w,Fg.replace("highp",i)));const n=t.createShader(t.VERTEX_SHADER),r=t.createShader(t.FRAGMENT_SHADER),a=t.createProgram();if(!n||!r||!a)throw new ai("Vertex, fragment shader or program creation error");if(t.shaderSource(n,s),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new ai("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 ai("Fragment shader compile error for ".concat(this.type,": ").concat(t.getShaderInfoLog(r)));if(t.attachShader(a,n),t.attachShader(a,r),t.linkProgram(a),!t.getProgramParameter(a,t.LINK_STATUS))throw new ai('Shader link error for "'.concat(this.type,'" ').concat(t.getProgramInfoLog(a)));const h=this.getUniformLocations(t,a)||{};return h.uStepW=t.getUniformLocation(a,"uStepW"),h.uStepH=t.getUniformLocation(a,"uStepH"),{program:a,attributeLocations:this.getAttributeLocations(t,a),uniformLocations:h}}getAttributeLocations(t,e){return{aPosition:t.getAttribLocation(e,"aPosition")}}getUniformLocations(t,e){const s=this.constructor.uniformLocations,i={};for(let n=0;n<s.length;n++)i[s[n]]=t.getUniformLocation(e,s[n]);return i}sendAttributeData(t,e,s){const i=e.aPosition,n=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,n),t.enableVertexAttribArray(i),t.vertexAttribPointer(i,2,t.FLOAT,!1,0,0),t.bufferData(t.ARRAY_BUFFER,s,t.STATIC_DRAW)}_setupFrameBuffer(t){const e=t.context;if(t.passes>1){const s=t.destinationWidth,i=t.destinationHeight;t.sourceWidth===s&&t.sourceHeight===i||(e.deleteTexture(t.targetTexture),t.targetTexture=t.filterBackend.createTexture(e,s,i)),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,t.targetTexture,0)}else e.bindFramebuffer(e.FRAMEBUFFER,null),e.finish()}_swapTextures(t){t.passes--,t.pass++;const e=t.targetTexture;t.targetTexture=t.sourceTexture,t.sourceTexture=e}isNeutralState(t){return!1}applyTo(t){ru(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=Is({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(Pt(t,qw))}}T(se,"type","BaseFilter"),T(se,"uniformLocations",[]);const Kw={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 au extends se{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(Kw[this.mode],`
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
`)}applyTo2d(t){let{imageData:{data:e}}=t;const s=new yt(this.color).getSource(),i=s[0]*this.alpha,n=s[1]*this.alpha,r=s[2]*this.alpha,
|
|
142
|
+
`)}applyTo2d(t){let{imageData:{data:e}}=t;const s=new yt(this.color).getSource(),i=s[0]*this.alpha,n=s[1]*this.alpha,r=s[2]*this.alpha,a=1-this.alpha;for(let h=0;h<e.length;h+=4){const l=e[h],u=e[h+1],d=e[h+2];switch(this.mode){case"multiply":e[h]=l*i/255,e[h+1]=u*n/255,e[h+2]=d*r/255;break;case"screen":e[h]=255-(255-l)*(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]=l+i,e[h+1]=u+n,e[h+2]=d+r;break;case"difference":e[h]=Math.abs(l-i),e[h+1]=Math.abs(u-n),e[h+2]=Math.abs(d-r);break;case"subtract":e[h]=l-i,e[h+1]=u-n,e[h+2]=d-r;break;case"darken":e[h]=Math.min(l,i),e[h+1]=Math.min(u,n),e[h+2]=Math.min(d,r);break;case"lighten":e[h]=Math.max(l,i),e[h+1]=Math.max(u,n),e[h+2]=Math.max(d,r);break;case"overlay":e[h]=i<128?2*l*i/255:255-2*(255-l)*(255-i)/255,e[h+1]=n<128?2*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+l-2*i*l/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+l*a,e[h+1]=n+u*a,e[h+2]=r+d*a}}}sendUniformData(t,e){const s=new yt(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(au,"defaults",{color:"#F95C63",mode:"multiply",alpha:1}),T(au,"type","BlendColor"),T(au,"uniformLocations",["uColor"]),V.setClass(au);const Jw={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
|
+
`},Qw=["type","image"];class ou extends se{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return Jw[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=vs());const a=n.blendImage,h=a.getContext("2d");a.width!==s||a.height!==i?(a.width=s,a.height=i):h.clearRect(0,0,s,i),h.setTransform(r.scaleX,0,0,r.scaleY,r.left,r.top),h.drawImage(r.getElement(),0,0,s,i);const l=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=l[u],_=l[u+1],b=l[u+2],x=l[u+3];switch(this.mode){case"multiply":e[u]=d*m/255,e[u+1]=g*_/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=Pt(t,Qw);return Ce.fromObject(i,e).then(r=>new this(E(E({},n),{},{image:r})))}}T(ou,"type","BlendImage"),T(ou,"defaults",{mode:"multiply",alpha:1}),T(ou,"uniformLocations",["uTransformMatrix","uImage"]),V.setClass(ou);class hu extends se{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){ru(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=vs(),i.blurLayer2=vs());const a=i.blurLayer1,h=i.blurLayer2;a.width===n&&a.height===r||(h.width=a.width=n,h.height=a.height=r);const l=a.getContext("2d"),u=h.getContext("2d"),d=15,g=.06*this.blur*.5;let f,p,m,_;for(l.putImageData(s,0,0),u.clearRect(0,0,n,r),_=-15;_<=d;_++)f=(Math.random()-.5)/4,p=_/d,m=g*p*n+f,u.globalAlpha=1-Math.abs(p),u.drawImage(a,m,f),l.drawImage(h,0,0),u.globalAlpha=1,u.clearRect(0,0,h.width,h.height);for(_=-15;_<=d;_++)f=(Math.random()-.5)/4,p=_/d,m=g*p*r+f,u.globalAlpha=1-Math.abs(p),u.drawImage(a,f,m),l.drawImage(h,0,0),u.globalAlpha=1,u.clearRect(0,0,h.width,h.height);e.drawImage(a,0,0);const b=e.getImageData(0,0,a.width,a.height);return l.globalAlpha=1,l.clearRect(0,0,a.width,a.height),b}sendUniformData(t,e){const s=this.chooseRightDelta();t.uniform2fv(e.uDelta,s)}isNeutralState(){return this.blur===0}chooseRightDelta(){let t=1;const e=[0,0];this.horizontal?this.aspectRatio>1&&(t=1/this.aspectRatio):this.aspectRatio<1&&(t=this.aspectRatio);const s=t*this.blur*.12;return this.horizontal?e[0]=s:e[1]=s,e}}T(hu,"type","Blur"),T(hu,"defaults",{blur:0}),T(hu,"uniformLocations",["uDelta"]),V.setClass(hu);class lu extends se{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(lu,"type","Brightness"),T(lu,"defaults",{brightness:0}),T(lu,"uniformLocations",["uBrightness"]),V.setClass(lu);class Qa extends se{getFragmentSource(){return`
|
|
212
212
|
precision highp float;
|
|
213
213
|
uniform sampler2D uTexture;
|
|
214
214
|
varying vec2 vTexCoord;
|
|
@@ -219,7 +219,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
219
219
|
color *= uColorMatrix;
|
|
220
220
|
color += uConstants;
|
|
221
221
|
gl_FragColor = color;
|
|
222
|
-
}`}applyTo2d(t){const e=t.imageData.data,s=this.matrix,i=this.colorsOnly;for(let n=0;n<e.length;n+=4){const r=e[n],
|
|
222
|
+
}`}applyTo2d(t){const e=t.imageData.data,s=this.matrix,i=this.colorsOnly;for(let n=0;n<e.length;n+=4){const r=e[n],a=e[n+1],h=e[n+2];if(i)e[n]=r*s[0]+a*s[1]+h*s[2]+255*s[4],e[n+1]=r*s[5]+a*s[6]+h*s[7]+255*s[9],e[n+2]=r*s[10]+a*s[11]+h*s[12]+255*s[14];else{const l=e[n+3];e[n]=r*s[0]+a*s[1]+h*s[2]+l*s[3]+255*s[4],e[n+1]=r*s[5]+a*s[6]+h*s[7]+l*s[8]+255*s[9],e[n+2]=r*s[10]+a*s[11]+h*s[12]+l*s[13]+255*s[14],e[n+3]=r*s[15]+a*s[16]+h*s[17]+l*s[18]+255*s[19]}}}sendUniformData(t,e){const s=this.matrix,i=[s[0],s[1],s[2],s[3],s[5],s[6],s[7],s[8],s[10],s[11],s[12],s[13],s[15],s[16],s[17],s[18]],n=[s[4],s[9],s[14],s[19]];t.uniformMatrix4fv(e.uColorMatrix,!1,i),t.uniform4fv(e.uConstants,n)}toObject(){return E(E({},super.toObject()),{},{matrix:[...this.matrix]})}}function Ar(o,t){var e;const s=(T(e=class extends Qa{toObject(){return{type:this.type,colorsOnly:this.colorsOnly}}},"type",o),T(e,"defaults",{colorsOnly:!1,matrix:t}),e);return V.setClass(s,o),s}T(Qa,"type","ColorMatrix"),T(Qa,"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(Qa,"uniformLocations",["uColorMatrix","uConstants"]),V.setClass(Qa),Ar("Brownie",[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0]),Ar("Vintage",[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0]),Ar("Kodachrome",[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0]),Ar("Technicolor",[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0]),Ar("Polaroid",[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0]),Ar("Sepia",[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0]),Ar("BlackWhite",[1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,0,0,0,1,0]);class L0 extends se{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.subFilters=t.subFilters||[]}applyTo(t){ru(t)&&(t.passes+=this.subFilters.length-1),this.subFilters.forEach(e=>{e.applyTo(t)})}toObject(){return{type:this.type,subFilters:this.subFilters.map(t=>t.toObject())}}isNeutralState(){return!this.subFilters.some(t=>!t.isNeutralState())}static fromObject(t,e){return Promise.all((t.subFilters||[]).map(s=>V.getClass(s.type).fromObject(s,e))).then(s=>new this({subFilters:s}))}}T(L0,"type","Composed"),V.setClass(L0);class cu extends se{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(cu,"type","Contrast"),T(cu,"defaults",{contrast:0}),T(cu,"uniformLocations",["uContrast"]),V.setClass(cu);const Zw={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 uu extends se{getCacheKey(){return"".concat(this.type,"_").concat(Math.sqrt(this.matrix.length),"_").concat(this.opaque?1:0)}getFragmentSource(){return Zw[this.getCacheKey()]}applyTo2d(t){const e=t.imageData,s=e.data,i=this.matrix,n=Math.round(Math.sqrt(i.length)),r=Math.floor(n/2),a=e.width,h=e.height,l=t.ctx.createImageData(a,h),u=l.data,d=this.opaque?1:0;let g,f,p,m,_,b,x,S,A,k,P,M,O;for(P=0;P<h;P++)for(k=0;k<a;k++){for(_=4*(P*a+k),g=0,f=0,p=0,m=0,O=0;O<n;O++)for(M=0;M<n;M++)x=P+O-r,b=k+M-r,x<0||x>=h||b<0||b>=a||(S=4*(x*a+b),A=i[O*n+M],g+=s[S]*A,f+=s[S+1]*A,p+=s[S+2]*A,d||(m+=s[S+3]*A));u[_]=g,u[_+1]=f,u[_+2]=p,u[_+3]=d?s[_+3]:m}t.imageData=l}sendUniformData(t,e){t.uniform1fv(e.uMatrix,this.matrix)}toObject(){return E(E({},super.toObject()),{},{opaque:this.opaque,matrix:[...this.matrix]})}}T(uu,"type","Convolute"),T(uu,"defaults",{opaque:!1,matrix:[0,0,0,0,1,0,0,0,0]}),T(uu,"uniformLocations",["uMatrix","uOpaque","uHalfSize","uSize"]),V.setClass(uu);const I0="Gamma";class du extends se{getFragmentSource(){return`
|
|
377
377
|
precision highp float;
|
|
378
378
|
uniform sampler2D uTexture;
|
|
379
379
|
uniform vec3 uGamma;
|
|
@@ -387,7 +387,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
387
387
|
gl_FragColor = color;
|
|
388
388
|
gl_FragColor.rgb *= color.a;
|
|
389
389
|
}
|
|
390
|
-
`}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.gamma=t.gamma||this.constructor.defaults.gamma.concat()}applyTo2d(t){let{imageData:{data:e}}=t;const s=this.gamma,i=1/s[0],n=1/s[1],r=1/s[2];this.rgbValues||(this.rgbValues={r:new Uint8Array(256),g:new Uint8Array(256),b:new Uint8Array(256)});const
|
|
390
|
+
`}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.gamma=t.gamma||this.constructor.defaults.gamma.concat()}applyTo2d(t){let{imageData:{data:e}}=t;const s=this.gamma,i=1/s[0],n=1/s[1],r=1/s[2];this.rgbValues||(this.rgbValues={r:new Uint8Array(256),g:new Uint8Array(256),b:new Uint8Array(256)});const a=this.rgbValues;for(let h=0;h<256;h++)a.r[h]=255*Math.pow(h/255,i),a.g[h]=255*Math.pow(h/255,n),a.b[h]=255*Math.pow(h/255,r);for(let h=0;h<e.length;h+=4)e[h]=a.r[e[h]],e[h+1]=a.g[e[h+1]],e[h+2]=a.b[e[h+2]]}sendUniformData(t,e){t.uniform3fv(e.uGamma,this.gamma)}isNeutralState(){const{gamma:t}=this;return t[0]===1&&t[1]===1&&t[2]===1}toObject(){return{type:I0,gamma:this.gamma.concat()}}}T(du,"type",I0),T(du,"defaults",{gamma:[1,1,1]}),T(du,"uniformLocations",["uGamma"]),V.setClass(du);const tx={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 gu extends se{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 tx[this.mode]}sendUniformData(t,e){t.uniform1i(e.uMode,1)}isNeutralState(){return!1}}T(gu,"type","Grayscale"),T(gu,"defaults",{mode:"average"}),T(gu,"uniformLocations",["uMode"]),V.setClass(gu);class Lg extends Qa{calculateMatrix(){const t=this.rotation*Math.PI,e=Fs(t),s=Ls(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(Lg,"type","HueRotation"),T(Lg,"defaults",{rotation:0}),V.setClass(Lg);class fu extends se{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(fu,"type","Invert"),T(fu,"defaults",{alpha:!1,invert:!0}),T(fu,"uniformLocations",["uInvert","uAlpha"]),V.setClass(fu);class
|
|
437
|
+
`}isNeutralState(){return!this.invert}sendUniformData(t,e){t.uniform1i(e.uInvert,Number(this.invert)),t.uniform1i(e.uAlpha,Number(this.alpha))}}T(fu,"type","Invert"),T(fu,"defaults",{alpha:!1,invert:!0}),T(fu,"uniformLocations",["uInvert","uAlpha"]),V.setClass(fu);class pu extends se{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(pu,"type","Noise"),T(pu,"defaults",{noise:0}),T(pu,"uniformLocations",["uNoise","uSeed"]),V.setClass(pu);class mu extends se{applyTo2d(t){let{imageData:{data:e,width:s,height:i}}=t;for(let n=0;n<i;n+=this.blocksize)for(let r=0;r<s;r+=this.blocksize){const a=4*n*s+4*r,h=e[a],l=e[a+1],u=e[a+2],d=e[a+3];for(let g=n;g<Math.min(n+this.blocksize,i);g++)for(let f=r;f<Math.min(r+this.blocksize,s);f++){const p=4*g*s+4*f;e[p]=h,e[p+1]=l,e[p+2]=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(mu,"type","Pixelate"),T(mu,"defaults",{blocksize:4}),T(mu,"uniformLocations",["uBlocksize"]),V.setClass(mu);class vu extends se{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 yt(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
|
|
482
|
+
`}applyTo2d(t){let{imageData:{data:e}}=t;const s=255*this.distance,i=new yt(this.color).getSource(),n=[i[0]-s,i[1]-s,i[2]-s],r=[i[0]+s,i[1]+s,i[2]+s];for(let a=0;a<e.length;a+=4){const h=e[a],l=e[a+1],u=e[a+2];h>n[0]&&l>n[1]&&u>n[2]&&h<r[0]&&l<r[1]&&u<r[2]&&(e[a+3]=0)}}sendUniformData(t,e){const s=new yt(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(vu,"type","RemoveColor"),T(vu,"defaults",{color:"#FFFFFF",distance:.02,useAlpha:!1}),T(vu,"uniformLocations",["uLow","uHigh"]),V.setClass(vu);class bu extends se{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){ru(t)?this.applyToForWebgl(t):this.applyTo2d(t)}isNeutralState(){return this.scaleX===1&&this.scaleY===1}lanczosCreate(t){return e=>{if(e>=t||e<=-t)return 0;if(e<11920929e-14&&e>-11920929e-14)return 1;const s=(e*=Math.PI)/t;return Math.sin(e)/e*Math.sin(s)/s}}applyTo2d(t){const e=t.imageData,s=this.scaleX,i=this.scaleY;this.rcpScaleX=1/s,this.rcpScaleY=1/i;const n=e.width,r=e.height,a=Math.round(n*s),h=Math.round(r*i);let l;l=this.resizeType==="sliceHack"?this.sliceByTwo(t,n,r,a,h):this.resizeType==="hermite"?this.hermiteFastResize(t,n,r,a,h):this.resizeType==="bilinear"?this.bilinearFiltering(t,n,r,a,h):this.resizeType==="lanczos"?this.lanczosResize(t,n,r,a,h):new ImageData(a,h),t.imageData=l}sliceByTwo(t,e,s,i,n){const r=t.imageData,a=.5;let h=!1,l=!1,u=e*a,d=s*a;const g=t.filterBackend.resources;let f=0,p=0;const m=e;let _=0;g.sliceByTwo||(g.sliceByTwo=vs());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||!l;)e=u,s=d,i<Math.floor(u*a)?u=Math.floor(u*a):(u=i,h=!0),n<Math.floor(d*a)?d=Math.floor(d*a):(d=n,l=!0),x.drawImage(b,f,p,e,s,m,_,u,d),f=m,p=_,_+=d;return x.getImageData(f,p,i,n)}lanczosResize(t,e,s,i,n){const r=t.imageData.data,a=t.ctx.createImageData(i,n),h=a.data,l=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),_={},b={x:0,y:0},x={x:0,y:0};return function S(A){let k,P,M,O,R,I,j,G,L,H,$;for(b.x=(A+.5)*u,x.x=Math.floor(b.x),k=0;k<n;k++){for(b.y=(k+.5)*d,x.y=Math.floor(b.y),R=0,I=0,j=0,G=0,L=0,P=x.x-p;P<=x.x+p;P++)if(!(P<0||P>=e)){H=Math.floor(1e3*Math.abs(P-b.x)),_[H]||(_[H]={});for(let J=x.y-m;J<=x.y+m;J++)J<0||J>=s||($=Math.floor(1e3*Math.abs(J-b.y)),_[H][$]||(_[H][$]=l(Math.sqrt(Math.pow(H*g,2)+Math.pow($*f,2))/1e3)),M=_[H][$],M>0&&(O=4*(J*e+P),R+=M,I+=M*r[O],j+=M*r[O+1],G+=M*r[O+2],L+=M*r[O+3]))}O=4*(k*i+A),h[O]=I/R,h[O+1]=j/R,h[O+2]=G/R,h[O+3]=L/R}return++A<i?S(A):a}(0)}bilinearFiltering(t,e,s,i,n){let r,a,h,l,u,d,g,f,p,m,_,b,x,S=0;const A=this.rcpScaleX,k=this.rcpScaleY,P=4*(e-1),M=t.imageData.data,O=t.ctx.createImageData(i,n),R=O.data;for(g=0;g<n;g++)for(f=0;f<i;f++)for(u=Math.floor(A*f),d=Math.floor(k*g),p=A*f-u,m=k*g-d,x=4*(d*e+u),_=0;_<4;_++)r=M[x+_],a=M[x+4+_],h=M[x+P+_],l=M[x+P+4+_],b=r*(1-p)*(1-m)+a*p*(1-m)+h*m*(1-p)+l*p*m,R[S++]=b;return O}hermiteFastResize(t,e,s,i,n){const r=this.rcpScaleX,a=this.rcpScaleY,h=Math.ceil(r/2),l=Math.ceil(a/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 _=0,b=0,x=0,S=0,A=0,k=0,P=0;const M=(f+.5)*a;for(let O=Math.floor(f*a);O<(f+1)*a;O++){const R=Math.abs(M-(O+.5))/l,I=(p+.5)*r,j=R*R;for(let G=Math.floor(p*r);G<(p+1)*r;G++){let L=Math.abs(I-(G+.5))/h;const H=Math.sqrt(j+L*L);H>1&&H<-1||(_=2*H*H*H-3*H*H+1,_>0&&(L=4*(G+O*e),P+=_*u[L+3],x+=_,u[L+3]<255&&(_=_*u[L+3]/250),S+=_*u[L],A+=_*u[L+1],k+=_*u[L+2],b+=_))}}g[m]=S/b,g[m+1]=A/b,g[m+2]=k/b,g[m+3]=P/x}return d}}T(bu,"type","Resize"),T(bu,"defaults",{resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3}),T(bu,"uniformLocations",["uDelta","uTaps"]),V.setClass(bu);class yu extends se{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(yu,"type","Saturation"),T(yu,"defaults",{saturation:0}),T(yu,"uniformLocations",["uSaturation"]),V.setClass(yu);class _u extends se{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,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(yu,"type","Vibrance"),T(yu,"defaults",{vibrance:0}),T(yu,"uniformLocations",["uVibrance"]),V.setClass(yu);const tx="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 ex(a){return new URL(Object.assign({"../assets/close.svg":tx})[`../assets/${a}`],typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ht&&Ht.src||new URL("pdf-canvas.umd.js",document.baseURI).href).href}function sx(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 ix(i))}),i.addEventListener("error",n=>{window.URL.revokeObjectURL(s),e(n)})})}function ix(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 I0=null;function nx(){const a=document.createElement("div");a.style.width="1in",document.body.append(a);const t=a.offsetWidth;return a.remove(),t}function rx(){const a=I0??nx();return I0=a,a/72}function ox(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 _s=new Map;function ax(a){const t=new Sf(a);return _s.set(a,t),t}function hx(a,t){const e=Date.now();return{PDFId:`${a.name}-${e}`,name:a.name.replace(/.pdf/,""),updateDate:e,PDFBase64:t}}function lx(a,t){const e=a.getViewport({scale:t}),s=document.createElement("canvas"),i=s.getContext("2d"),n=rx()/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 cx(a,t,e){const s=a||ex("close.svg"),{objects:i,options:n}=await Vw(s),r=i.filter(h=>h!==null),o=nw.groupSVGElements(r,n);return r.forEach(h=>{h.stroke=t}),o.hoverCursor="pointer",o.stroke=`${t}-${e}`,o}function ux(a,t){if(!_s.get(a))return;const s=1/3,i=vx(t,s);N0(a,i,s)}async function dx(a,t){const e=await sx(t),s=Date.now(),n={PDFId:`${t.name}${s}`,name:t.name.replace(/.png|.jpg|.jpeg/,""),updateDate:s,PDFBase64:e};return j0(a,{url:e}),{...n,pages:1}}async function j0(a,{url:t,scale:e=.5}){if(!_s.get(a))return;const i=await Ae.fromURL(t);i.scale(e),N0(a,i,e)}function N0(a,t,e){const s=_s.get(a);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function kh(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 fx(a,t,e){!e||!a||(e.scale(1/t),kh(a,e))}function gx(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 px(a){const t=_s.get(a);t&&(t.discardActiveObject(),t.renderAll())}function mx(a){const t=_s.get(a);t&&(t.clear(),_s.delete(a))}function vx(a,t){return new Ae(a,{scaleX:t,scaleY:t})}var Mh={};Mh.d=(a,t)=>{for(var e in t)Mh.o(t,e)&&!Mh.o(a,e)&&Object.defineProperty(a,e,{enumerable:!0,get:t[e]})},Mh.o=(a,t)=>Object.prototype.hasOwnProperty.call(a,t);var et=globalThis.pdfjsLib={};Mh.d(et,{AbortException:()=>Tr,AnnotationEditorLayer:()=>yg,AnnotationEditorParamsType:()=>Z,AnnotationEditorType:()=>nt,AnnotationEditorUIManager:()=>kr,AnnotationLayer:()=>pC,AnnotationMode:()=>On,ColorPicker:()=>ju,DOMSVGFactory:()=>dg,DrawLayer:()=>_g,FeatureTest:()=>Be,GlobalWorkerOptions:()=>zi,ImageKind:()=>_u,InvalidPDFException:()=>H0,MissingPDFException:()=>Ar,OPS:()=>Xs,OutputScale:()=>qf,PDFDataRangeTransport:()=>yv,PDFDateString:()=>Uf,PDFWorker:()=>ea,PasswordResponses:()=>wx,PermissionFlag:()=>_x,PixelsPerInch:()=>Dn,RenderingCancelledException:()=>Vf,TextLayer:()=>jh,UnexpectedResponseException:()=>Cu,Util:()=>Y,VerbosityLevel:()=>wu,XfaLayer:()=>Sv,build:()=>$S,createValidAbsoluteUrl:()=>Ax,fetchData:()=>Tu,getDocument:()=>HS,getFilenameFromUrl:()=>Fx,getPdfFilenameFromUrl:()=>Lx,getXfaPageViewport:()=>Ix,isDataScheme:()=>Eu,isPdfFile:()=>Gf,noContextMenu:()=>ws,normalizeUnicode:()=>Px,setLayerDimensions:()=>Er,shadow:()=>ut,version:()=>qS});const Te=typeof process=="object"&&process+""=="[object process]"&&!process.versions.nw&&!(process.versions.electron&&process.type&&process.type!=="browser"),B0=[1,0,0,1,0,0],If=[.001,0,0,.001,0,0],bx=1e7,jf=1.35,os={ANY:1,DISPLAY:2,PRINT:4,SAVE:8,ANNOTATIONS_FORMS:16,ANNOTATIONS_STORAGE:32,ANNOTATIONS_DISABLE:64,IS_EDITING:128,OPLIST:256},On={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},yx="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},_x={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},_u={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},ne={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},Oh={SOLID:1,DASHED:2,BEVELED:3,INSET:4,UNDERLINE:5},wu={ERRORS:0,WARNINGS:1,INFOS:5},Xs={dependency:1,setLineWidth:2,setLineCap:3,setLineJoin:4,setMiterLimit:5,setDash:6,setRenderingIntent:7,setFlatness:8,setGState:9,save:10,restore:11,transform:12,moveTo:13,lineTo:14,curveTo:15,curveTo2:16,curveTo3:17,closePath:18,rectangle:19,stroke:20,closeStroke:21,fill:22,eoFill:23,fillStroke:24,eoFillStroke:25,closeFillStroke:26,closeEOFillStroke:27,endPath:28,clip:29,eoClip:30,beginText:31,endText:32,setCharSpacing:33,setWordSpacing:34,setHScale:35,setLeading:36,setFont:37,setTextRenderingMode:38,setTextRise:39,moveText:40,setLeadingMoveText:41,setTextMatrix:42,nextLine:43,showText:44,showSpacedText:45,nextLineShowText:46,nextLineSetSpacingShowText:47,setCharWidth:48,setCharWidthAndBounds:49,setStrokeColorSpace:50,setFillColorSpace:51,setStrokeColor:52,setStrokeColorN:53,setFillColor:54,setFillColorN:55,setStrokeGray:56,setFillGray:57,setStrokeRGBColor:58,setFillRGBColor:59,setStrokeCMYKColor:60,setFillCMYKColor:61,shadingFill:62,beginInlineImage:63,beginImageData:64,endInlineImage:65,paintXObject:66,markPoint:67,markPointProps:68,beginMarkedContent:69,beginMarkedContentProps:70,endMarkedContent:71,beginCompat:72,endCompat:73,paintFormXObjectBegin:74,paintFormXObjectEnd:75,beginGroup:76,endGroup:77,beginAnnotation:80,endAnnotation:81,paintImageMaskXObject:83,paintImageMaskXObjectGroup:84,paintImageXObject:85,paintInlineImageXObject:86,paintInlineImageXObjectGroup:87,paintImageXObjectRepeat:88,paintImageMaskXObjectRepeat:89,paintSolidColorImageMask:90,constructPath:91,setStrokeTransparent:92,setFillTransparent:93},wx={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};let xu=wu.WARNINGS;function xx(a){Number.isInteger(a)&&(xu=a)}function Sx(){return xu}function Su(a){xu>=wu.INFOS&&console.log(`Info: ${a}`)}function ot(a){xu>=wu.WARNINGS&&console.log(`Warning: ${a}`)}function Mt(a){throw new Error(a)}function re(a,t){a||Mt(t)}function Cx(a){switch(a==null?void 0:a.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}function Ax(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=Ox(a)}catch{}}const s=t?new URL(a,t):new URL(a);if(Cx(s))return s}catch{}return null}function ut(a,t,e,s=!1){return Object.defineProperty(a,t,{value:e,enumerable:!s,configurable:!0,writable:!1}),e}const Pn=function(){function t(e,s){this.message=e,this.name=s}return t.prototype=new Error,t.constructor=t,t}();class Nf extends Pn{constructor(t,e){super(t,"PasswordException"),this.code=e}}class Bf extends Pn{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}}class H0 extends Pn{constructor(t){super(t,"InvalidPDFException")}}class Ar extends Pn{constructor(t){super(t,"MissingPDFException")}}class Cu extends Pn{constructor(t,e){super(t,"UnexpectedResponseException"),this.status=e}}class Tx extends Pn{constructor(t){super(t,"FormatError")}}class Tr extends Pn{constructor(t){super(t,"AbortException")}}function W0(a){(typeof a!="object"||(a==null?void 0:a.length)===void 0)&&Mt("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 Au(a){typeof a!="string"&&Mt("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 Ex(a){return String.fromCharCode(a>>24&255,a>>16&255,a>>8&255,a&255)}function Hf(a){const t=Object.create(null);for(const[e,s]of a)t[e]=s;return t}function kx(){const a=new Uint8Array(4);return a[0]=1,new Uint32Array(a.buffer,0,1)[0]===1}function Mx(){try{return new Function(""),!0}catch{return!1}}class Be{static get isLittleEndian(){return ut(this,"isLittleEndian",kx())}static get isEvalSupported(){return ut(this,"isEvalSupported",Mx())}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 Wf=Array.from(Array(256).keys(),a=>a.toString(16).padStart(2,"0"));class Y{static makeHexColor(t,e,s){return`#${Wf[t]}${Wf[e]}${Wf[s]}`}static scaleMinMax(t,e){let s;t[0]?(t[0]<0&&(s=e[0],e[0]=e[2],e[2]=s),e[0]*=t[0],e[2]*=t[0],t[3]<0&&(s=e[1],e[1]=e[3],e[3]=s),e[1]*=t[3],e[3]*=t[3]):(s=e[0],e[0]=e[1],e[1]=s,s=e[2],e[2]=e[3],e[3]=s,t[1]<0&&(s=e[1],e[1]=e[3],e[3]=s),e[1]*=t[1],e[3]*=t[1],t[2]<0&&(s=e[0],e[0]=e[2],e[2]=s),e[0]*=t[2],e[2]*=t[2]),e[0]+=t[4],e[1]+=t[5],e[2]+=t[4],e[3]+=t[5]}static transform(t,e){return[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],t[0]*e[4]+t[2]*e[5]+t[4],t[1]*e[4]+t[3]*e[5]+t[5]]}static applyTransform(t,e){const s=t[0]*e[0]+t[1]*e[2]+e[4],i=t[0]*e[1]+t[1]*e[3]+e[5];return[s,i]}static applyInverseTransform(t,e){const s=e[0]*e[3]-e[1]*e[2],i=(t[0]*e[3]-t[1]*e[2]+e[2]*e[5]-e[4]*e[3])/s,n=(-t[0]*e[1]+t[1]*e[0]+e[4]*e[1]-e[5]*e[0])/s;return[i,n]}static getAxialAlignedBoundingBox(t,e){const s=this.applyTransform(t,e),i=this.applyTransform(t.slice(2,4),e),n=this.applyTransform([t[0],t[3]],e),r=this.applyTransform([t[2],t[1]],e);return[Math.min(s[0],i[0],n[0],r[0]),Math.min(s[1],i[1],n[1],r[1]),Math.max(s[0],i[0],n[0],r[0]),Math.max(s[1],i[1],n[1],r[1])]}static inverseTransform(t){const e=t[0]*t[3]-t[1]*t[2];return[t[3]/e,-t[1]/e,-t[2]/e,t[0]/e,(t[2]*t[5]-t[4]*t[3])/e,(t[4]*t[1]-t[5]*t[0])/e]}static singularValueDecompose2dScale(t){const e=[t[0],t[2],t[1],t[3]],s=t[0]*e[0]+t[1]*e[2],i=t[0]*e[1]+t[1]*e[3],n=t[2]*e[0]+t[3]*e[2],r=t[2]*e[1]+t[3]*e[3],o=(s+r)/2,h=Math.sqrt((s+r)**2-4*(s*r-n*i))/2,l=o+h||1,u=o-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,o,h,l){return l?(l[0]=Math.min(l[0],t,o),l[1]=Math.min(l[1],e,h),l[2]=Math.max(l[2],t,o),l[3]=Math.max(l[3],e,h)):l=[Math.min(t,o),Math.min(e,h),Math.max(t,o),Math.max(e,h)],y(this,Gi,Pg).call(this,t,s,n,o,e,i,r,h,3*(-t+3*(s-n)+o),6*(t-2*s+n),3*(s-t),l),y(this,Gi,Pg).call(this,t,s,n,o,e,i,r,h,3*(-e+3*(i-r)+h),6*(e-2*i+r),3*(i-e),l),l}}Gi=new WeakSet,od=function(t,e,s,i,n,r,o,h,l,u){if(l<=0||l>=1)return;const d=1-l,f=l*l,g=f*l,p=d*(d*(d*t+3*l*e)+3*f*s)+g*i,m=d*(d*(d*n+3*l*r)+3*f*o)+g*h;u[0]=Math.min(u[0],p),u[1]=Math.min(u[1],m),u[2]=Math.max(u[2],p),u[3]=Math.max(u[3],m)},Pg=function(t,e,s,i,n,r,o,h,l,u,d,f){if(Math.abs(l)<1e-12){Math.abs(u)>=1e-12&&y(this,Gi,od).call(this,t,e,s,i,n,r,o,h,-d/u,f);return}const g=u**2-4*d*l;if(g<0)return;const p=Math.sqrt(g),m=2*l;y(this,Gi,od).call(this,t,e,s,i,n,r,o,h,(-u+p)/m,f),y(this,Gi,od).call(this,t,e,s,i,n,r,o,h,(-u-p)/m,f)},w(Y,Gi);function Ox(a){return decodeURIComponent(escape(a))}let Xf=null,X0=null;function Px(a){return Xf||(Xf=/([\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,X0=new Map([["ſt","ſt"]])),a.replaceAll(Xf,(t,e,s)=>e?e.normalize("NFKC"):X0.get(s))}function Dx(){if(typeof crypto<"u"&&typeof(crypto==null?void 0:crypto.randomUUID)=="function")return crypto.randomUUID();const a=new Uint8Array(32);if(typeof crypto<"u"&&typeof(crypto==null?void 0:crypto.getRandomValues)=="function")crypto.getRandomValues(a);else for(let t=0;t<32;t++)a[t]=Math.floor(Math.random()*255);return W0(a)}const zf="pdfjs_internal_id_",Hi={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 Rx(a){return Uint8Array.prototype.toBase64?a.toBase64():btoa(W0(a))}const Wi="http://www.w3.org/2000/svg",Pr=class Pr{};tt(Pr,"CSS",96),tt(Pr,"PDF",72),tt(Pr,"PDF_TO_CSS_UNITS",Pr.CSS/Pr.PDF);let Dn=Pr;async function Tu(a,t="text"){if(Dh(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 Ph{constructor({viewBox:t,scale:e,rotation:s,offsetX:i=0,offsetY:n=0,dontFlip:r=!1}){this.viewBox=t,this.scale=e,this.rotation=s,this.offsetX=i,this.offsetY=n;const o=(t[2]+t[0])/2,h=(t[3]+t[1])/2;let l,u,d,f;switch(s%=360,s<0&&(s+=360),s){case 180:l=-1,u=0,d=0,f=1;break;case 90:l=0,u=1,d=1,f=0;break;case 270:l=0,u=-1,d=-1,f=0;break;case 0:l=1,u=0,d=0,f=-1;break;default:throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.")}r&&(d=-d,f=-f);let g,p,m,_;l===0?(g=Math.abs(h-t[1])*e+i,p=Math.abs(o-t[0])*e+n,m=(t[3]-t[1])*e,_=(t[2]-t[0])*e):(g=Math.abs(o-t[0])*e+i,p=Math.abs(h-t[1])*e+n,m=(t[2]-t[0])*e,_=(t[3]-t[1])*e),this.transform=[l*e,u*e,d*e,f*e,g-l*e*o-d*e*h,p-u*e*o-f*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 Ph({viewBox:this.viewBox.slice(),scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}convertToViewportPoint(t,e){return Y.applyTransform([t,e],this.transform)}convertToViewportRectangle(t){const e=Y.applyTransform([t[0],t[1]],this.transform),s=Y.applyTransform([t[2],t[3]],this.transform);return[e[0],e[1],s[0],s[1]]}convertToPdfPoint(t,e){return Y.applyInverseTransform([t,e],this.transform)}}class Vf extends Pn{constructor(t,e=0){super(t,"RenderingCancelledException"),this.extraDelay=e}}function Eu(a){const t=a.length;let e=0;for(;e<t&&a[e].trim()==="";)e++;return a.substring(e,e+5).toLowerCase()==="data:"}function Gf(a){return typeof a=="string"&&/\.pdf$/i.test(a)}function Fx(a){return[a]=a.split(/[#?]/,1),a.substring(a.lastIndexOf("/")+1)}function Lx(a,t="document.pdf"){if(typeof a!="string")return t;if(Eu(a))return ot('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 z0{constructor(){tt(this,"started",Object.create(null));tt(this,"times",[])}time(t){t in this.started&&ot(`Timer is already running for ${t}`),this.started[t]=Date.now()}timeEnd(t){t in this.started||ot(`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 Dh(a,t){try{const{protocol:e}=t?new URL(a,t):new URL(a);return e==="http:"||e==="https:"}catch{return!1}}function ws(a){a.preventDefault()}function V0(a){console.log("Deprecated API usage: "+a)}class Uf{static toDateObject(t){if(!t||typeof t!="string")return null;c(this,Wh)||v(this,Wh,new RegExp("^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+|-])?(\\d{2})?'?(\\d{2})?'?"));const e=c(this,Wh).exec(t);if(!e)return null;const s=parseInt(e[1],10);let i=parseInt(e[2],10);i=i>=1&&i<=12?i-1:0;let n=parseInt(e[3],10);n=n>=1&&n<=31?n:1;let r=parseInt(e[4],10);r=r>=0&&r<=23?r:0;let o=parseInt(e[5],10);o=o>=0&&o<=59?o:0;let h=parseInt(e[6],10);h=h>=0&&h<=59?h:0;const l=e[7]||"Z";let 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,o+=d):l==="+"&&(r-=u,o-=d),new Date(Date.UTC(s,i,n,r,o,h))}}Wh=new WeakMap,w(Uf,Wh);function Ix(a,{scale:t=1,rotation:e=0}){const{width:s,height:i}=a.attributes.style,n=[0,0,parseInt(s),parseInt(i)];return new Ph({viewBox:n,scale:t,rotation:e})}function Yf(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):(ot(`Not a valid color format: "${a}"`),[0,0,0])}function jx(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,Yf(s))}t.remove()}function Lt(a){const{a:t,b:e,c:s,d:i,e:n,f:r}=a.getTransform();return[t,e,s,i,n,r]}function 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 Er(a,t,e=!1,s=!0){if(t instanceof Ph){const{pageWidth:i,pageHeight:n}=t.rawDims,{style:r}=a,o=Be.isCSSRoundSupported,h=`var(--scale-factor) * ${i}px`,l=`var(--scale-factor) * ${n}px`,u=o?`round(down, ${h}, var(--scale-round-x, 1px))`:`calc(${h})`,d=o?`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&&a.setAttribute("data-main-rotation",t.rotation)}class qf{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,We);w(this,Fn,null);w(this,Dr,null);w(this,zs);w(this,Rr,null);w(this,Xh,null);v(this,zs,t),c(Ui,zh)||v(Ui,zh,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,Fn,document.createElement("div"));t.classList.add("editToolbar","hidden"),t.setAttribute("role","toolbar");const e=c(this,zs)._uiManager._signal;t.addEventListener("contextmenu",ws,{signal:e}),t.addEventListener("pointerdown",y(Ui,Hu,Kv),{signal:e});const s=v(this,Rr,document.createElement("div"));s.className="buttons",t.append(s);const i=c(this,zs).toolbarPosition;if(i){const{style:n}=t,r=c(this,zs)._uiManager.direction==="ltr"?1-i[0]:i[0];n.insetInlineEnd=`${100*r}%`,n.top=`calc(${100*i[1]}% + var(--editor-toolbar-vert-offset))`}return y(this,We,Zv).call(this),t}get div(){return c(this,Fn)}hide(){var t;c(this,Fn).classList.add("hidden"),(t=c(this,Dr))==null||t.hideDropdown()}show(){var t;c(this,Fn).classList.remove("hidden"),(t=c(this,Xh))==null||t.shown()}async addAltText(t){const e=await t.render();y(this,We,ad).call(this,e),c(this,Rr).prepend(e,c(this,We,Dg)),v(this,Xh,t)}addColorPicker(t){v(this,Dr,t);const e=t.renderButton();y(this,We,ad).call(this,e),c(this,Rr).prepend(e,c(this,We,Dg))}remove(){var t;c(this,Fn).remove(),(t=c(this,Dr))==null||t.destroy(),v(this,Dr,null)}};Fn=new WeakMap,Dr=new WeakMap,zs=new WeakMap,Rr=new WeakMap,Xh=new WeakMap,zh=new WeakMap,Hu=new WeakSet,Kv=function(t){t.stopPropagation()},We=new WeakSet,Jv=function(t){c(this,zs)._focusEventsAllowed=!1,t.preventDefault(),t.stopPropagation()},Qv=function(t){c(this,zs)._focusEventsAllowed=!0,t.preventDefault(),t.stopPropagation()},ad=function(t){const e=c(this,zs)._uiManager._signal;t.addEventListener("focusin",y(this,We,Jv).bind(this),{capture:!0,signal:e}),t.addEventListener("focusout",y(this,We,Qv).bind(this),{capture:!0,signal:e}),t.addEventListener("contextmenu",ws,{signal:e})},Zv=function(){const{editorType:t,_uiManager:e}=c(this,zs),s=document.createElement("button");s.className="delete",s.tabIndex=0,s.setAttribute("data-l10n-id",c(Ui,zh)[t]),y(this,We,ad).call(this,s),s.addEventListener("click",i=>{e.delete()},{signal:e._signal}),c(this,Rr).append(s)},Dg=function(){const t=document.createElement("div");return t.className="divider",t},w(Ui,Hu),w(Ui,zh,null);let $f=Ui;class Nx{constructor(t){w(this,Ln);w(this,Vh,null);w(this,Fr,null);w(this,Lr);v(this,Lr,t)}show(t,e,s){const[i,n]=y(this,Ln,eb).call(this,e,s),{style:r}=c(this,Fr)||v(this,Fr,y(this,Ln,tb).call(this));t.append(c(this,Fr)),r.insetInlineEnd=`${100*i}%`,r.top=`calc(${100*n}% + var(--editor-toolbar-vert-offset))`}hide(){c(this,Fr).remove()}}Vh=new WeakMap,Fr=new WeakMap,Lr=new WeakMap,Ln=new WeakSet,tb=function(){const t=v(this,Fr,document.createElement("div"));t.className="editToolbar",t.setAttribute("role","toolbar"),t.addEventListener("contextmenu",ws,{signal:c(this,Lr)._signal});const e=v(this,Vh,document.createElement("div"));return e.className="buttons",t.append(e),y(this,Ln,sb).call(this),t},eb=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]},sb=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,Lr)._signal;t.addEventListener("contextmenu",ws,{signal:s}),t.addEventListener("click",()=>{c(this,Lr).highlightSelection("floating_button")},{signal:s}),c(this,Vh).append(t)};function ku(a,t,e){for(const s of e)t.addEventListener(s,a[s].bind(a))}function Bx(a){return Math.round(Math.min(255,Math.max(1,255*a))).toString(16).padStart(2,"0")}class Hx{constructor(){w(this,Wu,0)}get id(){return`${yx}${Ue(this,Wu)._++}`}}Wu=new WeakMap;const wg=class wg{constructor(){w(this,ia);w(this,sa,Dx());w(this,Gh,0);w(this,ke,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,ia,hd).call(this,`${e}_${s}_${i}_${n}`,t)}async getFromUrl(t){return y(this,ia,hd).call(this,t,t)}async getFromBlob(t,e){const s=await e;return y(this,ia,hd).call(this,t,s)}async getFromId(t){c(this,ke)||v(this,ke,new Map);const e=c(this,ke).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,ke)||v(this,ke,new Map);let s=c(this,ke).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,sa)}_${Ue(this,Gh)._++}`,refCounter:1,isSvg:!1},c(this,ke).set(t,s),c(this,ke).set(s.id,s),s}getSvgUrl(t){const e=c(this,ke).get(t);return e!=null&&e.isSvg?e.svgUrl:null}deleteId(t){var i;c(this,ke)||v(this,ke,new Map);const e=c(this,ke).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,sa)}_`)}};sa=new WeakMap,Gh=new WeakMap,ke=new WeakMap,ia=new WeakSet,hd=async function(t,e){c(this,ke)||v(this,ke,new Map);let s=c(this,ke).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,sa)}_${Ue(this,Gh)._++}`,refCounter:0,isSvg:!1});let i;if(typeof e=="string"?(s.url=e,i=await Tu(e,"blob")):e instanceof File?i=s.file=e:e instanceof Blob&&(i=e),i.type==="image/svg+xml"){const n=wg._isSVGFittingCanvas,r=new FileReader,o=new Image,h=new Promise((l,u)=>{o.onload=()=>{s.bitmap=o,s.isSvg=!0,l()},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){console.error(i),s=null}return c(this,ke).set(t,s),s&&c(this,ke).set(s.id,s),s};let Kf=wg;class Wx{constructor(t=128){w(this,ue,[]);w(this,In,!1);w(this,Uh);w(this,de,-1);v(this,Uh,t)}add({cmd:t,undo:e,post:s,mustExec:i,type:n=NaN,overwriteIfSameType:r=!1,keepUndo:o=!1}){if(i&&t(),c(this,In))return;const h={cmd:t,undo:e,post:s,type:n};if(c(this,de)===-1){c(this,ue).length>0&&(c(this,ue).length=0),v(this,de,0),c(this,ue).push(h);return}if(r&&c(this,ue)[c(this,de)].type===n){o&&(h.undo=c(this,ue)[c(this,de)].undo),c(this,ue)[c(this,de)]=h;return}const l=c(this,de)+1;l===c(this,Uh)?c(this,ue).splice(0,1):(v(this,de,l),l<c(this,ue).length&&c(this,ue).splice(l)),c(this,ue).push(h)}undo(){if(c(this,de)===-1)return;v(this,In,!0);const{undo:t,post:e}=c(this,ue)[c(this,de)];t(),e==null||e(),v(this,In,!1),v(this,de,c(this,de)-1)}redo(){if(c(this,de)<c(this,ue).length-1){v(this,de,c(this,de)+1),v(this,In,!0);const{cmd:t,post:e}=c(this,ue)[c(this,de)];t(),e==null||e(),v(this,In,!1)}}hasSomethingToUndo(){return c(this,de)!==-1}hasSomethingToRedo(){return c(this,de)<c(this,ue).length-1}destroy(){v(this,ue,null)}}ue=new WeakMap,In=new WeakMap,Uh=new WeakMap,de=new WeakMap;class Rh{constructor(t){w(this,Xu);this.buffer=[],this.callbacks=new Map,this.allKeys=new Set;const{isMac:e}=Be.platform;for(const[s,i,n={}]of t)for(const r of s){const o=r.startsWith("mac+");e&&o?(this.callbacks.set(r.slice(4),{callback:i,options:n}),this.allKeys.add(r.split("+").at(-1))):!e&&!o&&(this.callbacks.set(r,{callback:i,options:n}),this.allKeys.add(r.split("+").at(-1)))}}exec(t,e){if(!this.allKeys.has(e.key))return;const s=this.callbacks.get(y(this,Xu,ib).call(this,e));if(!s)return;const{callback:i,options:{bubbles:n=!1,args:r=[],checker:o=null}}=s;o&&!o(t,e)||(i.bind(t,...r,e)(),n||(e.stopPropagation(),e.preventDefault()))}}Xu=new WeakSet,ib=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 zu=class zu{get _colors(){const t=new Map([["CanvasText",null],["Canvas",null]]);return jx(t),ut(this,"_colors",t)}convert(t){const e=Yf(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 zu._colorsMapping.get(s);return e}getHexCode(t){const e=this._colors.get(t);return e?Y.makeHexColor(...e):t}};tt(zu,"_colorsMapping",new Map([["CanvasText",[0,0,0]],["Canvas",[255,255,255]]]));let Jf=zu;const ca=class ca{constructor(t,e,s,i,n,r,o,h,l,u,d){w(this,B);w(this,na,new AbortController);w(this,hs,null);w(this,oe,new Map);w(this,me,new Map);w(this,ra,null);w(this,Yi,null);w(this,oa,null);w(this,Vs,new Wx);w(this,jn,null);w(this,aa,0);w(this,Ir,new Set);w(this,di,null);w(this,Gs,null);w(this,jr,new Set);w(this,Yh,!1);w(this,qh,!1);w(this,ha,!1);w(this,$h,null);w(this,fi,null);w(this,Nn,null);w(this,la,null);w(this,Bn,!1);w(this,gi,null);w(this,Vu,new Hx);w(this,Hn,!1);w(this,Kh,!1);w(this,Wn,null);w(this,Nr,null);w(this,Jh,null);w(this,Qh,null);w(this,fe,nt.NONE);w(this,wt,new Set);w(this,qi,null);w(this,Br,null);w(this,Zh,null);w(this,tl,{isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1});w(this,Xn,[0,0]);w(this,pi,null);w(this,$i,null);w(this,el,null);w(this,Ss,null);const f=this._signal=c(this,na).signal;v(this,$i,t),v(this,el,e),v(this,ra,s),this._eventBus=i,i._on("editingaction",this.onEditingAction.bind(this),{signal:f}),i._on("pagechanging",this.onPageChanging.bind(this),{signal:f}),i._on("scalechanging",this.onScaleChanging.bind(this),{signal:f}),i._on("rotationchanging",this.onRotationChanging.bind(this),{signal:f}),i._on("setpreference",this.onSetPreference.bind(this),{signal:f}),i._on("switchannotationeditorparams",g=>this.updateParams(g.type,g.value),{signal:f}),y(this,B,ob).call(this),y(this,B,cb).call(this),y(this,B,Fg).call(this),v(this,Yi,n.annotationStorage),v(this,$h,n.filterFactory),v(this,Br,r),v(this,la,o||null),v(this,Yh,h),v(this,qh,l),v(this,ha,u),v(this,Qh,d||null),this.viewParameters={realScale:Dn.PDF_TO_CSS_UNITS,rotation:0},this.isShiftKeyDown=!1}static get _keyboardManager(){const t=ca.prototype,e=r=>c(r,$i).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 ut(this,"_keyboardManager",new Rh([[["ctrl+a","mac+meta+a"],t.selectAll,{checker:s}],[["ctrl+z","mac+meta+z"],t.undo,{checker:s}],[["ctrl+y","ctrl+shift+z","mac+meta+shift+z","ctrl+shift+Z","mac+meta+shift+Z"],t.redo,{checker:s}],[["Backspace","alt+Backspace","ctrl+Backspace","shift+Backspace","mac+Backspace","mac+alt+Backspace","mac+ctrl+Backspace","Delete","ctrl+Delete","shift+Delete","mac+Delete"],t.delete,{checker:s}],[["Enter","mac+Enter"],t.addNewEditorFromKeyboard,{checker:(r,{target:o})=>!(o instanceof HTMLButtonElement)&&c(r,$i).contains(o)&&!r.isEnterHandled}],[[" ","mac+ "],t.addNewEditorFromKeyboard,{checker:(r,{target:o})=>!(o instanceof HTMLButtonElement)&&c(r,$i).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,na))==null||e.abort(),v(this,na,null),this._signal=null;for(const n of c(this,me).values())n.destroy();c(this,me).clear(),c(this,oe).clear(),c(this,jr).clear(),v(this,hs,null),c(this,wt).clear(),c(this,Vs).destroy(),(s=c(this,ra))==null||s.destroy(),(i=c(this,gi))==null||i.hide(),v(this,gi,null),c(this,fi)&&(clearTimeout(c(this,fi)),v(this,fi,null)),c(this,pi)&&(clearTimeout(c(this,pi)),v(this,pi,null))}combinedSignal(t){return AbortSignal.any([this._signal,t.signal])}get mlManager(){return c(this,Qh)}get useNewAltTextFlow(){return c(this,qh)}get useNewAltTextWhenAddingImage(){return c(this,ha)}get hcmFilter(){return ut(this,"hcmFilter",c(this,Br)?c(this,$h).addHCMFilter(c(this,Br).foreground,c(this,Br).background):"none")}get direction(){return ut(this,"direction",getComputedStyle(c(this,$i)).direction)}get highlightColors(){return ut(this,"highlightColors",c(this,la)?new Map(c(this,la).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,Jh,t)}editAltText(t,e=!1){var s;(s=c(this,ra))==null||s.editAltText(this,t,e)}switchToMode(t,e){this._eventBus.on("annotationeditormodechanged",e,{once:!0,signal:this._signal}),this._eventBus.dispatch("showannotationeditorui",{source:this,mode:t})}setPreference(t,e){this._eventBus.dispatch("setpreference",{source:this,name:t,value:e})}onSetPreference({name:t,value:e}){switch(t){case"enableNewAltTextWhenAddingImage":v(this,ha,e);break}}onPageChanging({pageNumber:t}){v(this,aa,t-1)}focusMainContainer(){c(this,$i).focus()}findParent(t,e){for(const s of c(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){c(this,el).classList.toggle("noUserSelect",t)}addShouldRescale(t){c(this,jr).add(t)}removeShouldRescale(t){c(this,jr).delete(t)}onScaleChanging({scale:t}){this.commitOrRemove(),this.viewParameters.realScale=t*Dn.PDF_TO_CSS_UNITS;for(const e of c(this,jr))e.onScaleChanging()}onRotationChanging({pagesRotation:t}){this.commitOrRemove(),this.viewParameters.rotation=t}highlightSelection(t=""){const e=document.getSelection();if(!e||e.isCollapsed)return;const{anchorNode:s,anchorOffset:i,focusNode:n,focusOffset:r}=e,o=e.toString(),l=y(this,B,ld).call(this,e).closest(".textLayer"),u=this.getSelectionBoxes(l);if(!u)return;e.empty();const d=y(this,B,Rg).call(this,l),f=c(this,fe)===nt.NONE,g=()=>{d==null||d.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:t,boxes:u,anchorNode:s,anchorOffset:i,focusNode:n,focusOffset:r,text:o}),f&&this.showAllEditors("highlight",!0,!0)};if(f){this.switchToMode(nt.HIGHLIGHT,g);return}g()}addToAnnotationStorage(t){!t.isEmpty()&&c(this,Yi)&&!c(this,Yi).has(t.id)&&c(this,Yi).setValue(t.id,t)}blur(){if(this.isShiftKeyDown=!1,c(this,Bn)&&(v(this,Bn,!1),y(this,B,cd).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,Nr,[e,t]),e._focusEventsAllowed=!1;break}}focus(){if(!c(this,Nr))return;const[t,e]=c(this,Nr);v(this,Nr,null),e.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this._signal}),e.focus()}addEditListeners(){y(this,B,Fg).call(this),y(this,B,Lg).call(this)}removeEditListeners(){y(this,B,lb).call(this),y(this,B,Ig).call(this)}dragOver(t){for(const{type:e}of t.dataTransfer.items)for(const s of c(this,Gs))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,Gs))if(s.isHandlingMimeForPasting(e.type)){s.paste(e,this.currentLayer),t.preventDefault();return}}copy(t){var s;if(t.preventDefault(),(s=c(this,hs))==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,Gs))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){ot(`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,jg).call(this,h);y(this,B,Ng).call(this,n)},o=()=>{for(const h of n)h.remove()};this.addCommands({cmd:r,undo:o,mustExec:!0})}catch(n){ot(`paste: "${n.message}".`)}}keydown(t){!this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!0),c(this,fe)!==nt.NONE&&!this.isEditorHandlingKeyboard&&ca._keyboardManager.exec(this,t)}keyup(t){this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!1,c(this,Bn)&&(v(this,Bn,!1),y(this,B,cd).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,ab).call(this),y(this,B,Lg).call(this),y(this,B,Ye).call(this,{isEditing:c(this,fe)!==nt.NONE,isEmpty:y(this,B,rc).call(this),hasSomethingToUndo:c(this,Vs).hasSomethingToUndo(),hasSomethingToRedo:c(this,Vs).hasSomethingToRedo(),hasSelectedEditor:!1})):(y(this,B,hb).call(this),y(this,B,Ig).call(this),y(this,B,Ye).call(this,{isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(t){if(!c(this,Gs)){v(this,Gs,t);for(const e of c(this,Gs))y(this,B,lr).call(this,e.defaultPropertiesToUpdate)}}getId(){return c(this,Vu).id}get currentLayer(){return c(this,me).get(c(this,aa))}getLayer(t){return c(this,me).get(t)}get currentPageIndex(){return c(this,aa)}addLayer(t){c(this,me).set(t.pageIndex,t),c(this,Hn)?t.enable():t.disable()}removeLayer(t){c(this,me).delete(t.pageIndex)}async updateMode(t,e=null,s=!1){if(c(this,fe)!==t&&!(c(this,Ss)&&(await c(this,Ss).promise,!c(this,Ss)))){if(v(this,Ss,Promise.withResolvers()),v(this,fe,t),t===nt.NONE){this.setEditingState(!1),y(this,B,db).call(this),c(this,Ss).resolve();return}this.setEditingState(!0),await y(this,B,ub).call(this),this.unselectAll();for(const i of c(this,me).values())i.updateMode(t);if(!e){s&&this.addNewEditorFromKeyboard(),c(this,Ss).resolve();return}for(const i of c(this,oe).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,fe)&&this._eventBus.dispatch("switchannotationeditormode",{source:this,mode:t})}updateParams(t,e){var s;if(c(this,Gs)){switch(t){case Z.CREATE:this.currentLayer.addNewEditor();return;case Z.HIGHLIGHT_DEFAULT_COLOR:(s=c(this,Jh))==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,Zh)||v(this,Zh,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,Gs))i.updateDefaultParams(t,e)}}showAllEditors(t,e,s=!1){var n;for(const r of c(this,oe).values())r.editorType===t&&r.show(e);(((n=c(this,Zh))==null?void 0:n.get(Z.HIGHLIGHT_SHOW_ALL))??!0)!==e&&y(this,B,lr).call(this,[[Z.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(c(this,Kh)!==t){v(this,Kh,t);for(const e of c(this,me).values())t?e.disableClick():e.enableClick(),e.div.classList.toggle("waiting",t)}}getEditors(t){const e=[];for(const s of c(this,oe).values())s.pageIndex===t&&e.push(s);return e}getEditor(t){return c(this,oe).get(t)}addEditor(t){c(this,oe).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,oe).delete(t.id),this.unselect(t),(!t.annotationElementId||!c(this,Ir).has(t.annotationElementId))&&((e=c(this,Yi))==null||e.remove(t.id))}addDeletedAnnotationElement(t){c(this,Ir).add(t.annotationElementId),this.addChangedExistingAnnotation(t),t.deleted=!0}isDeletedAnnotationElement(t){return c(this,Ir).has(t)}removeDeletedAnnotationElement(t){c(this,Ir).delete(t.annotationElementId),this.removeChangedExistingAnnotation(t),t.deleted=!1}setActiveEditor(t){c(this,hs)!==t&&(v(this,hs,t),t&&y(this,B,lr).call(this,t.propertiesToUpdate))}updateUI(t){c(this,B,fb)===t&&y(this,B,lr).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,lr).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,lr).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,Vs).undo(),y(this,B,Ye).call(this,{hasSomethingToUndo:c(this,Vs).hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:y(this,B,rc).call(this)})}redo(){c(this,Vs).redo(),y(this,B,Ye).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:c(this,Vs).hasSomethingToRedo(),isEmpty:y(this,B,rc).call(this)})}addCommands(t){c(this,Vs).add(t),y(this,B,Ye).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:y(this,B,rc).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,jg).call(this,i)};this.addCommands({cmd:e,undo:s,mustExec:!0})}commitOrRemove(){var t;(t=c(this,hs))==null||t.commitOrRemove()}hasSomethingToControl(){return c(this,hs)||this.hasSelection}selectAll(){for(const t of c(this,wt))t.commit();y(this,B,Ng).call(this,c(this,oe).values())}unselectAll(){if(!(c(this,hs)&&(c(this,hs).commitOrRemove(),c(this,fe)!==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,Xn)[0]+=t,c(this,Xn)[1]+=e;const[i,n]=c(this,Xn),r=[...c(this,wt)],o=1e3;c(this,pi)&&clearTimeout(c(this,pi)),v(this,pi,setTimeout(()=>{v(this,pi,null),c(this,Xn)[0]=c(this,Xn)[1]=0,this.addCommands({cmd:()=>{for(const h of r)c(this,oe).has(h.id)&&h.translateInPage(i,n)},undo:()=>{for(const h of r)c(this,oe).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,di,new Map);for(const t of c(this,wt))c(this,di).set(t,{savedX:t.x,savedY:t.y,savedPageIndex:t.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!c(this,di))return!1;this.disableUserSelect(!1);const t=c(this,di);v(this,di,null);let e=!1;for(const[{x:i,y:n,pageIndex:r},o]of t)o.newX=i,o.newY=n,o.newPageIndex=r,e||(e=i!==o.savedX||n!==o.savedY||r!==o.savedPageIndex);if(!e)return!1;const s=(i,n,r,o)=>{if(c(this,oe).has(i.id)){const h=c(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(c(this,di))for(const s of c(this,di).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,hs)===t}getActive(){return c(this,hs)}getMode(){return c(this,fe)}get imageManager(){return ut(this,"imageManager",new Kf)}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 o;switch(t.getAttribute("data-main-rotation")){case"90":o=(l,u,d,f)=>({x:(u-i)/r,y:1-(l+d-s)/n,width:f/r,height:d/n});break;case"180":o=(l,u,d,f)=>({x:1-(l+d-s)/n,y:1-(u+f-i)/r,width:d/n,height:f/r});break;case"270":o=(l,u,d,f)=>({x:1-(u+f-i)/r,y:(l-s)/n,width:f/r,height:d/n});break;default:o=(l,u,d,f)=>({x:(l-s)/n,y:(u-i)/r,width:d/n,height:f/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:f,y:g,width:p,height:m}of d.getClientRects())p===0||m===0||h.push(o(f,g,p,m))}return h.length===0?null:h}addChangedExistingAnnotation({annotationElementId:t,id:e}){(c(this,oa)||v(this,oa,new Map)).set(t,e)}removeChangedExistingAnnotation({annotationElementId:t}){var e;(e=c(this,oa))==null||e.delete(t)}renderAnnotationElement(t){var i;const e=(i=c(this,oa))==null?void 0:i.get(t.data.id);if(!e)return;const s=c(this,Yi).getRawValue(e);s&&(c(this,fe)===nt.NONE&&!s.hasBeenModified||s.renderAnnotationElement(t))}};na=new WeakMap,hs=new WeakMap,oe=new WeakMap,me=new WeakMap,ra=new WeakMap,Yi=new WeakMap,oa=new WeakMap,Vs=new WeakMap,jn=new WeakMap,aa=new WeakMap,Ir=new WeakMap,di=new WeakMap,Gs=new WeakMap,jr=new WeakMap,Yh=new WeakMap,qh=new WeakMap,ha=new WeakMap,$h=new WeakMap,fi=new WeakMap,Nn=new WeakMap,la=new WeakMap,Bn=new WeakMap,gi=new WeakMap,Vu=new WeakMap,Hn=new WeakMap,Kh=new WeakMap,Wn=new WeakMap,Nr=new WeakMap,Jh=new WeakMap,Qh=new WeakMap,fe=new WeakMap,wt=new WeakMap,qi=new WeakMap,Br=new WeakMap,Zh=new WeakMap,tl=new WeakMap,Xn=new WeakMap,pi=new WeakMap,$i=new WeakMap,el=new WeakMap,Ss=new WeakMap,B=new WeakSet,ld=function({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t},Rg=function(t){const{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(const s of c(this,me).values())if(s.hasTextLayer(t))return s;return null},nb=function(){const t=document.getSelection();if(!t||t.isCollapsed)return;const s=y(this,B,ld).call(this,t).closest(".textLayer"),i=this.getSelectionBoxes(s);i&&(c(this,gi)||v(this,gi,new Nx(this)),c(this,gi).show(s,i,this.direction==="ltr"))},rb=function(){var n,r,o;const t=document.getSelection();if(!t||t.isCollapsed){c(this,qi)&&((n=c(this,gi))==null||n.hide(),v(this,qi,null),y(this,B,Ye).call(this,{hasSelectedText:!1}));return}const{anchorNode:e}=t;if(e===c(this,qi))return;const i=y(this,B,ld).call(this,t).closest(".textLayer");if(!i){c(this,qi)&&((r=c(this,gi))==null||r.hide(),v(this,qi,null),y(this,B,Ye).call(this,{hasSelectedText:!1}));return}if((o=c(this,gi))==null||o.hide(),v(this,qi,e),y(this,B,Ye).call(this,{hasSelectedText:!0}),!(c(this,fe)!==nt.HIGHLIGHT&&c(this,fe)!==nt.NONE)&&(c(this,fe)===nt.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0),v(this,Bn,this.isShiftKeyDown),!this.isShiftKeyDown)){const h=c(this,fe)===nt.HIGHLIGHT?y(this,B,Rg).call(this,i):null;h==null||h.toggleDrawing();const l=new AbortController,u=this.combinedSignal(l),d=f=>{f.type==="pointerup"&&f.button!==0||(l.abort(),h==null||h.toggleDrawing(!0),f.type==="pointerup"&&y(this,B,cd).call(this,"main_toolbar"))};window.addEventListener("pointerup",d,{signal:u}),window.addEventListener("blur",d,{signal:u})}},cd=function(t=""){c(this,fe)===nt.HIGHLIGHT?this.highlightSelection(t):c(this,Yh)&&y(this,B,nb).call(this)},ob=function(){document.addEventListener("selectionchange",y(this,B,rb).bind(this),{signal:this._signal})},ab=function(){if(c(this,Nn))return;v(this,Nn,new AbortController);const t=this.combinedSignal(c(this,Nn));window.addEventListener("focus",this.focus.bind(this),{signal:t}),window.addEventListener("blur",this.blur.bind(this),{signal:t})},hb=function(){var t;(t=c(this,Nn))==null||t.abort(),v(this,Nn,null)},Fg=function(){if(c(this,Wn))return;v(this,Wn,new AbortController);const t=this.combinedSignal(c(this,Wn));window.addEventListener("keydown",this.keydown.bind(this),{signal:t}),window.addEventListener("keyup",this.keyup.bind(this),{signal:t})},lb=function(){var t;(t=c(this,Wn))==null||t.abort(),v(this,Wn,null)},Lg=function(){if(c(this,jn))return;v(this,jn,new AbortController);const t=this.combinedSignal(c(this,jn));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})},Ig=function(){var t;(t=c(this,jn))==null||t.abort(),v(this,jn,null)},cb=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,tl)[s]!==i)&&(this._eventBus.dispatch("annotationeditorstateschanged",{source:this,details:Object.assign(c(this,tl),t)}),c(this,fe)===nt.HIGHLIGHT&&t.hasSelectedEditor===!1&&y(this,B,lr).call(this,[[Z.HIGHLIGHT_FREE,!0]]))},lr=function(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})},ub=async function(){if(!c(this,Hn)){v(this,Hn,!0);const t=[];for(const e of c(this,me).values())t.push(e.enable());await Promise.all(t);for(const e of c(this,oe).values())e.enable()}},db=function(){if(this.unselectAll(),c(this,Hn)){v(this,Hn,!1);for(const t of c(this,me).values())t.disable();for(const t of c(this,oe).values())t.disable()}},jg=function(t){const e=c(this,me).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},rc=function(){if(c(this,oe).size===0)return!0;if(c(this,oe).size===1)for(const t of c(this,oe).values())return t.isEmpty();return!1},Ng=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(ca,"TRANSLATE_SMALL",1),tt(ca,"TRANSLATE_BIG",10);let kr=ca;const Xe=class Xe{constructor(t){w(this,Ys);w(this,ge,null);w(this,mi,!1);w(this,Us,null);w(this,ua,null);w(this,vi,null);w(this,ls,null);w(this,da,!1);w(this,bi,null);w(this,Qe,null);w(this,Ki,null);w(this,Hr,null);w(this,yi,!1);v(this,Qe,t),v(this,yi,t._uiManager.useNewAltTextFlow),c(Xe,zn)||v(Xe,zn,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){Xe._l10n??(Xe._l10n=t)}async render(){const t=v(this,Us,document.createElement("button"));t.className="altText",t.tabIndex="0";const e=v(this,ua,document.createElement("span"));t.append(e),c(this,yi)?(t.classList.add("new"),t.setAttribute("data-l10n-id",c(Xe,zn).missing),e.setAttribute("data-l10n-id",c(Xe,zn)["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,Qe)._uiManager._signal;t.addEventListener("contextmenu",ws,{signal:s}),t.addEventListener("pointerdown",n=>n.stopPropagation(),{signal:s});const i=n=>{n.preventDefault(),c(this,Qe)._uiManager.editAltText(c(this,Qe)),c(this,yi)&&c(this,Qe)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_clicked",data:{label:c(this,Ys,oc)}})};return t.addEventListener("click",i,{capture:!0,signal:s}),t.addEventListener("keydown",n=>{n.target===t&&n.key==="Enter"&&(v(this,da,!0),i(n))},{signal:s}),await y(this,Ys,ud).call(this),t}finish(){c(this,Us)&&(c(this,Us).focus({focusVisible:c(this,da)}),v(this,da,!1))}isEmpty(){return c(this,yi)?c(this,ge)===null:!c(this,ge)&&!c(this,mi)}hasData(){return c(this,yi)?c(this,ge)!==null||!!c(this,Ki):this.isEmpty()}get guessedText(){return c(this,Ki)}async setGuessedText(t){c(this,ge)===null&&(v(this,Ki,t),v(this,Hr,await Xe._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",{generatedAltText:t})),y(this,Ys,ud).call(this))}toggleAltTextBadge(t=!1){var e;if(!c(this,yi)||c(this,ge)){(e=c(this,bi))==null||e.remove(),v(this,bi,null);return}if(!c(this,bi)){const s=v(this,bi,document.createElement("div"));s.className="noAltTextBadge",c(this,Qe).div.append(s)}c(this,bi).classList.toggle("hidden",!t)}serialize(t){let e=c(this,ge);return!t&&c(this,Ki)===e&&(e=c(this,Hr)),{altText:e,decorative:c(this,mi),guessedText:c(this,Ki),textWithDisclaimer:c(this,Hr)}}get data(){return{altText:c(this,ge),decorative:c(this,mi)}}set data({altText:t,decorative:e,guessedText:s,textWithDisclaimer:i,cancel:n=!1}){s&&(v(this,Ki,s),v(this,Hr,i)),!(c(this,ge)===t&&c(this,mi)===e)&&(n||(v(this,ge,t),v(this,mi,e)),y(this,Ys,ud).call(this))}toggle(t=!1){c(this,Us)&&(!t&&c(this,ls)&&(clearTimeout(c(this,ls)),v(this,ls,null)),c(this,Us).disabled=!t)}shown(){c(this,Qe)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_displayed",data:{label:c(this,Ys,oc)}})}destroy(){var t,e;(t=c(this,Us))==null||t.remove(),v(this,Us,null),v(this,ua,null),v(this,vi,null),(e=c(this,bi))==null||e.remove(),v(this,bi,null)}};ge=new WeakMap,mi=new WeakMap,Us=new WeakMap,ua=new WeakMap,vi=new WeakMap,ls=new WeakMap,da=new WeakMap,bi=new WeakMap,Qe=new WeakMap,Ki=new WeakMap,Hr=new WeakMap,yi=new WeakMap,zn=new WeakMap,Ys=new WeakSet,oc=function(){return c(this,ge)&&"added"||c(this,ge)===null&&this.guessedText&&"review"||"missing"},ud=async function(){var i,n,r;const t=c(this,Us);if(!t)return;if(c(this,yi)){if(t.classList.toggle("done",!!c(this,ge)),t.setAttribute("data-l10n-id",c(Xe,zn)[c(this,Ys,oc)]),(i=c(this,ua))==null||i.setAttribute("data-l10n-id",c(Xe,zn)[`${c(this,Ys,oc)}-label`]),!c(this,ge)){(n=c(this,vi))==null||n.remove();return}}else{if(!c(this,ge)&&!c(this,mi)){t.classList.remove("done"),(r=c(this,vi))==null||r.remove();return}t.classList.add("done"),t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-edit-button")}let e=c(this,vi);if(!e){v(this,vi,e=document.createElement("span")),e.className="tooltip",e.setAttribute("role","tooltip"),e.id=`alt-text-tooltip-${c(this,Qe).id}`;const o=100,h=c(this,Qe)._uiManager._signal;h.addEventListener("abort",()=>{clearTimeout(c(this,ls)),v(this,ls,null)},{once:!0}),t.addEventListener("mouseenter",()=>{v(this,ls,setTimeout(()=>{v(this,ls,null),c(this,vi).classList.add("show"),c(this,Qe)._reportTelemetry({action:"alt_text_tooltip"})},o))},{signal:h}),t.addEventListener("mouseleave",()=>{var l;c(this,ls)&&(clearTimeout(c(this,ls)),v(this,ls,null)),(l=c(this,vi))==null||l.classList.remove("show")},{signal:h})}c(this,mi)?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,Qe).getImageForAltText();s==null||s.setAttribute("aria-describedby",e.id)},w(Xe,zn,null),tt(Xe,"_l10n",null);let Mu=Xe;const vt=class vt{constructor(t){w(this,rt);w(this,Wr,null);w(this,qs,null);w(this,It,null);w(this,fa,!1);w(this,Xr,!1);w(this,ve,null);w(this,zr,null);w(this,Vn,null);w(this,sl,"");w(this,Vr,!1);w(this,Gn,null);w(this,il,!1);w(this,Gr,!1);w(this,Ji,!1);w(this,_i,null);w(this,ga,0);w(this,pa,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,nl,!1);w(this,Gu,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[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=vt.prototype._resizeWithKeyboard,e=kr.TRANSLATE_SMALL,s=kr.TRANSLATE_BIG;return ut(this,"_resizerKeyboardManager",new Rh([[["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 Xx({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,nl)}set _isDraggable(t){var e;v(this,nl,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,Gu)}setParent(t){t!==null?(this.pageIndex=t.pageIndex,this.pageDimensions=t.pageDimensions):y(this,rt,ac).call(this),this.parent=t}focusin(t){this._focusEventsAllowed&&(c(this,Vr)?v(this,Vr,!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,Bg).call(this,this.parentDimensions,t,e)}translateInPage(t,e){c(this,Gn)||v(this,Gn,[this.x,this.y]),y(this,rt,Bg).call(this,this.pageDimensions,t,e),this.div.scrollIntoView({block:"nearest"})}drag(t,e){c(this,Gn)||v(this,Gn,[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[o,h]=this.getBaseTranslation();n+=o,r+=h,this.div.style.left=`${(100*n).toFixed(2)}%`,this.div.style.top=`${(100*r).toFixed(2)}%`,this.div.scrollIntoView({block:"nearest"})}get _hasBeenMoved(){return!!c(this,Gn)&&(c(this,Gn)[0]!==this.x||c(this,Gn)[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:o}=this;if(r*=e,o*=s,i*=e,n*=s,this._mustFixPosition)switch(t){case 0:i=Math.max(0,Math.min(e-r,i)),n=Math.max(0,Math.min(s-o,n));break;case 90:i=Math.max(0,Math.min(e-o,i)),n=Math.min(s,Math.max(r,n));break;case 180:i=Math.min(e,Math.max(r,i)),n=Math.min(s,Math.max(o,n));break;case 270:i=Math.min(e,Math.max(o,i)),n=Math.max(0,Math.min(s-r,n));break}this.x=i/=e,this.y=n/=s;const[h,l]=this.getBaseTranslation();i+=h,n+=l;const{style: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,rl,Hg).call(s,t,e,this.parentRotation)}pageTranslationToScreen(t,e){var s;return y(s=vt,rl,Hg).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,Xr)||(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,Xr)&&e.endsWith("%");if(i&&n)return;const[r,o]=this.parentDimensions;i||(t.width=`${(100*parseFloat(s)/r).toFixed(2)}%`),!c(this,Xr)&&!n&&(t.height=`${(100*parseFloat(e)/o).toFixed(2)}%`)}getInitialTranslation(){return[0,0]}altTextFinish(){var t;(t=c(this,It))==null||t.finish()}async addEditToolbar(){return this._editToolbar||c(this,Gr)?this._editToolbar:(this._editToolbar=new $f(this),this.div.append(this._editToolbar.render()),c(this,It)&&await this._editToolbar.addAltText(c(this,It)),this._editToolbar)}removeEditToolbar(){var t;this._editToolbar&&(this._editToolbar.remove(),this._editToolbar=null,(t=c(this,It))==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,It)||(Mu.initialize(vt._l10n),v(this,It,new Mu(this)),c(this,Wr)&&(c(this,It).data=c(this,Wr),v(this,Wr,null)),await this.addEditToolbar())}get altTextData(){var t;return(t=c(this,It))==null?void 0:t.data}set altTextData(t){c(this,It)&&(c(this,It).data=t)}get guessedAltText(){var t;return(t=c(this,It))==null?void 0:t.guessedText}async setGuessedAltText(t){var e;await((e=c(this,It))==null?void 0:e.setGuessedText(t))}serializeAltText(t){var e;return(e=c(this,It))==null?void 0:e.serialize(t)}hasAltText(){return!!c(this,It)&&!c(this,It).isEmpty()}hasAltTextData(){var t;return((t=c(this,It))==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,fa)?-1:0,this._isVisible||this.div.classList.add("hidden"),this.setInForeground(),y(this,rt,Gg).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),ku(this,this.div,["pointerdown"]),this.div}pointerdown(t){const{isMac:e}=Be.platform;if(t.button!==0||t.ctrlKey&&e){t.preventDefault();return}if(v(this,Vr,!0),this._isDraggable){y(this,rt,mb).call(this,t);return}y(this,rt,Vg).call(this,t)}get isSelected(){return this._uiManager.isSelected(this)}moveInDOM(){c(this,_i)&&clearTimeout(c(this,_i)),v(this,_i,setTimeout(()=>{var t;v(this,_i,null),(t=this.parent)==null||t.moveEditorInDOM(this)},0))}_setParentAndPosition(t,e,s){t.changeParent(this),this.x=e,this.y=s,this.fixAndSetPosition()}getRect(t,e,s=this.rotation){const i=this.parentScale,[n,r]=this.pageDimensions,[o,h]=this.pageTranslation,l=t/i,u=e/i,d=this.x*n,f=this.y*r,g=this.width*n,p=this.height*r;switch(s){case 0:return[d+l+o,r-f-u-p+h,d+l+g+o,r-f-u+h];case 90:return[d+u+o,r-f+l+h,d+u+p+o,r-f+l+g+h];case 180:return[d-l-g+o,r-f+u+h,d-l+o,r-f+u+p+h];case 270:return[d-u-p+o,r-f-l-g+h,d-u+o,r-f-l+h];default:throw new Error("Invalid rotation")}}getRectInCurrentCoords(t,e){const[s,i,n,r]=t,o=n-s,h=r-i;switch(this.rotation){case 0:return[s,e-r,o,h];case 90:return[s,e-i,h,o];case 180:return[n,e-i,o,h];case 270:return[n,e-r,h,o];default:throw new Error("Invalid rotation")}}onceAdded(){}isEmpty(){return!1}enableEditMode(){v(this,Gr,!0)}disableEditMode(){v(this,Gr,!1)}isInEditMode(){return c(this,Gr)}shouldGetKeyboardEvents(){return c(this,Ji)}needsToBeRebuilt(){return this.div&&!this.isAttachedToDOM}rebuild(){y(this,rt,Gg).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,Wr,t.accessibilityData);const[n,r]=i.pageDimensions,[o,h,l,u]=i.getRectInCurrentCoords(t.rect,r);return i.x=o/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,Vn))==null||t.abort(),v(this,Vn,null),this.isEmpty()||this.commit(),this.parent?this.parent.remove(this):this._uiManager.removeEditor(this),c(this,_i)&&(clearTimeout(c(this,_i)),v(this,_i,null)),y(this,rt,ac).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,gb).call(this),c(this,ve).classList.remove("hidden"),ku(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,zr,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height});const e=c(this,ve).children;if(!c(this,qs)){v(this,qs,Array.from(e));const r=y(this,rt,vb).bind(this),o=y(this,rt,bb).bind(this),h=this._uiManager._signal;for(const l of c(this,qs)){const u=l.getAttribute("data-resizer-name");l.setAttribute("role","spinbutton"),l.addEventListener("keydown",r,{signal:h}),l.addEventListener("blur",o,{signal:h}),l.addEventListener("focus",y(this,rt,yb).bind(this,u),{signal:h}),l.setAttribute("data-l10n-id",vt._l10nResizer[u])}}const s=c(this,qs)[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,qs).length/4);if(n!==i){if(n<i)for(let o=0;o<i-n;o++)c(this,ve).append(c(this,ve).firstChild);else if(n>i)for(let o=0;o<n-i;o++)c(this,ve).firstChild.before(c(this,ve).lastChild);let r=0;for(const o of e){const l=c(this,qs)[r++].getAttribute("data-resizer-name");o.setAttribute("data-l10n-id",vt._l10nResizer[l])}}y(this,rt,Ug).call(this,0),v(this,Ji,!0),c(this,ve).firstChild.focus({focusVisible:!0}),t.preventDefault(),t.stopImmediatePropagation()}_resizeWithKeyboard(t,e){c(this,Ji)&&y(this,rt,zg).call(this,c(this,sl),{movementX:t,movementY:e})}_stopResizingWithKeyboard(){y(this,rt,ac).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,It))==null||s.toggleAltTextBadge(!1)}unselect(){var t,e,s,i,n;(t=c(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=c(this,It))==null||n.toggleAltTextBadge(!0)}updateParams(t,e){}disableEditing(){}enableEditing(){}enterInEditMode(){}getImageForAltText(){return null}get contentDiv(){return this.div}get isEditing(){return c(this,il)}set isEditing(t){v(this,il,t),this.parent&&(t?(this.parent.setSelected(this),this.parent.setActiveEditor(this)):this.parent.setActiveEditor(null))}setAspectRatio(t,e){v(this,Xr,!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,fa,!1)}disable(){this.div&&(this.div.tabIndex=-1),v(this,fa,!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()}};Wr=new WeakMap,qs=new WeakMap,It=new WeakMap,fa=new WeakMap,Xr=new WeakMap,ve=new WeakMap,zr=new WeakMap,Vn=new WeakMap,sl=new WeakMap,Vr=new WeakMap,Gn=new WeakMap,il=new WeakMap,Gr=new WeakMap,Ji=new WeakMap,_i=new WeakMap,ga=new WeakMap,pa=new WeakMap,Cs=new WeakMap,nl=new WeakMap,Gu=new WeakMap,rt=new WeakSet,Bg=function([t,e],s,i){[s,i]=this.screenToPageTranslation(s,i),this.x+=s/t,this.y+=i/e,this.fixAndSetPosition()},rl=new WeakSet,Hg=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]}},Wg=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]}},gb=function(){if(c(this,ve))return;v(this,ve,document.createElement("div")),c(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");c(this,ve).append(i),i.classList.add("resizer",s),i.setAttribute("data-resizer-name",s),i.addEventListener("pointerdown",y(this,rt,pb).bind(this,s),{signal:e}),i.addEventListener("contextmenu",ws,{signal:e}),i.tabIndex=-1}this.div.prepend(c(this,ve))},pb=function(t,e){var p;e.preventDefault();const{isMac:s}=Be.platform;if(e.button!==0||e.ctrlKey&&s)return;(p=c(this,It))==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,zg).bind(this,t),{passive:!0,capture:!0,signal:r}),window.addEventListener("contextmenu",ws,{signal:r});const o=this.x,h=this.y,l=this.width,u=this.height,d=this.parent.div.style.cursor,f=this.div.style.cursor;this.div.style.cursor=this.parent.div.style.cursor=window.getComputedStyle(e.target).cursor;const g=()=>{var m;n.abort(),this.parent.togglePointerEvents(!0),(m=c(this,It))==null||m.toggle(!0),this._isDraggable=i,this.parent.div.style.cursor=d,this.div.style.cursor=f,y(this,rt,Xg).call(this,o,h,l,u)};window.addEventListener("pointerup",g,{signal:r}),window.addEventListener("blur",g,{signal:r})},Xg=function(t,e,s,i){const n=this.x,r=this.y,o=this.width,h=this.height;n===t&&r===e&&o===s&&h===i||this.addCommands({cmd:()=>{this.width=o,this.height=h,this.x=n,this.y=r;const[l,u]=this.parentDimensions;this.setDims(l*o,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})},zg=function(t,e){const[s,i]=this.parentDimensions,n=this.x,r=this.y,o=this.width,h=this.height,l=vt.MIN_SIZE/s,u=vt.MIN_SIZE/i,d=U=>Math.round(U*1e4)/1e4,f=y(this,rt,Wg).call(this,this.rotation),g=(U,X)=>[f[0]*U+f[2]*X,f[1]*U+f[3]*X],p=y(this,rt,Wg).call(this,360-this.rotation),m=(U,X)=>[p[0]*U+p[2]*X,p[1]*U+p[3]*X];let _,b,x=!1,C=!1;switch(t){case"topLeft":x=!0,_=(U,X)=>[0,0],b=(U,X)=>[U,X];break;case"topMiddle":_=(U,X)=>[U/2,0],b=(U,X)=>[U/2,X];break;case"topRight":x=!0,_=(U,X)=>[U,0],b=(U,X)=>[0,X];break;case"middleRight":C=!0,_=(U,X)=>[U,X/2],b=(U,X)=>[0,X/2];break;case"bottomRight":x=!0,_=(U,X)=>[U,X],b=(U,X)=>[0,0];break;case"bottomMiddle":_=(U,X)=>[U/2,X],b=(U,X)=>[U/2,0];break;case"bottomLeft":x=!0,_=(U,X)=>[0,X],b=(U,X)=>[U,0];break;case"middleLeft":C=!0,_=(U,X)=>[0,X/2],b=(U,X)=>[U,X/2];break}const A=_(o,h),k=b(o,h);let P=g(...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 U=Math.hypot(o,h);R=I=Math.max(Math.min(Math.hypot(k[0]-A[0]-j,k[1]-A[1]-G)/U,1/o,1/h),l/o,u/h)}else C?R=Math.max(l,Math.min(1,Math.abs(k[0]-A[0]-j)))/o:I=Math.max(u,Math.min(1,Math.abs(k[1]-A[1]-G)))/h;const L=d(o*R),H=d(h*I);P=g(...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()},Vg=function(t){const{isMac:e}=Be.platform;t.ctrlKey&&!e||t.shiftKey||t.metaKey&&e?this.parent.toggleSelected(this):this.parent.setSelected(this)},mb=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,ga,t.clientX),v(this,pa,t.clientY);const r=o=>{const{clientX:h,clientY:l}=o,[u,d]=this.screenToPageTranslation(h-c(this,ga),l-c(this,pa));v(this,ga,h),v(this,pa,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,Vr,!1),this._uiManager.endDragSession()||y(this,rt,Vg).call(this,t)};window.addEventListener("pointerup",n,{signal:i}),window.addEventListener("blur",n,{signal:i})},Gg=function(){if(c(this,Vn)||!this.div)return;v(this,Vn,new AbortController);const t=this._uiManager.combinedSignal(c(this,Vn));this.div.addEventListener("focusin",this.focusin.bind(this),{signal:t}),this.div.addEventListener("focusout",this.focusout.bind(this),{signal:t})},vb=function(t){vt._resizerKeyboardManager.exec(this,t)},bb=function(t){var e;c(this,Ji)&&((e=t.relatedTarget)==null?void 0:e.parentNode)!==c(this,ve)&&y(this,rt,ac).call(this)},yb=function(t){v(this,sl,c(this,Ji)?t:"")},Ug=function(t){if(c(this,qs))for(const e of c(this,qs))e.tabIndex=t},ac=function(){if(v(this,Ji,!1),y(this,rt,Ug).call(this,-1),c(this,zr)){const{savedX:t,savedY:e,savedWidth:s,savedHeight:i}=c(this,zr);y(this,rt,Xg).call(this,t,e,s,i),v(this,zr,null)}},w(vt,rl),tt(vt,"_l10n",null),tt(vt,"_l10nResizer",null),tt(vt,"_borderLineWidth",-1),tt(vt,"_colorManager",new Jf),tt(vt,"_zIndex",1),tt(vt,"_telemetryTimeout",1e3);let _t=vt;class Xx extends _t{constructor(t){super(t),this.annotationElementId=t.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}}const G0=3285377520,xs=4294901760,ui=65535;class U0{constructor(t){this.h1=t?t&4294967295:G0,this.h2=t?t&4294967295:G0}update(t){let e,s;if(typeof t=="string"){e=new Uint8Array(t.length*2),s=0;for(let m=0,_=t.length;m<_;m++){const 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,l=this.h1,u=this.h2;const d=3432918353,f=461845907,g=d&ui,p=f&ui;for(let m=0;m<i;m++)m&1?(o=r[m],o=o*d&xs|o*g&ui,o=o<<15|o>>>17,o=o*f&xs|o*p&ui,l^=o,l=l<<13|l>>>19,l=l*5+3864292196):(h=r[m],h=h*d&xs|h*g&ui,h=h<<15|h>>>17,h=h*f&xs|h*p&ui,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&xs|o*g&ui,o=o<<15|o>>>17,o=o*f&xs|o*p&ui,i&1?l^=o:u^=o}this.h1=l,this.h2=u}hexdigest(){let t=this.h1,e=this.h2;return t^=e>>>1,t=t*3981806797&xs|t*36045&ui,e=e*4283543511&xs|((e<<16|t>>>16)*2950163797&xs)>>>16,t^=e>>>1,t=t*444984403&xs|t*60499&ui,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 Qf=Object.freeze({map:null,hash:"",transfer:void 0});class Zf{constructor(){w(this,Uu);w(this,Ur,!1);w(this,Yr,null);w(this,pe,new Map);this.onSetModified=null,this.onResetModified=null,this.onAnnotationEditor=null}getValue(t,e){const s=c(this,pe).get(t);return s===void 0?e:Object.assign(e,s)}getRawValue(t){return c(this,pe).get(t)}remove(t){if(c(this,pe).delete(t),c(this,pe).size===0&&this.resetModified(),typeof this.onAnnotationEditor=="function"){for(const e of c(this,pe).values())if(e instanceof _t)return;this.onAnnotationEditor(null)}}setValue(t,e){const s=c(this,pe).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,pe).set(t,e);i&&y(this,Uu,_b).call(this),e instanceof _t&&typeof this.onAnnotationEditor=="function"&&this.onAnnotationEditor(e.constructor._type)}has(t){return c(this,pe).has(t)}getAll(){return c(this,pe).size>0?Hf(c(this,pe)):null}setAll(t){for(const[e,s]of Object.entries(t))this.setValue(e,s)}get size(){return c(this,pe).size}resetModified(){c(this,Ur)&&(v(this,Ur,!1),typeof this.onResetModified=="function"&&this.onResetModified())}get print(){return new Y0(this)}get serializable(){if(c(this,pe).size===0)return Qf;const t=new Map,e=new U0,s=[],i=Object.create(null);let n=!1;for(const[r,o]of c(this,pe)){const h=o instanceof _t?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}:Qf}get editorStats(){let t=null;const e=new Map;for(const s of c(this,pe).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[o,h]of Object.entries(i)){if(o==="type")continue;let l=r.get(o);l||(l=new Map,r.set(o,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,Yr,null)}get modifiedIds(){if(c(this,Yr))return c(this,Yr);const t=[];for(const e of c(this,pe).values())!(e instanceof _t)||!e.annotationElementId||!e.serialize()||t.push(e.annotationElementId);return v(this,Yr,{ids:new Set(t),hash:t.join(",")})}}Ur=new WeakMap,Yr=new WeakMap,pe=new WeakMap,Uu=new WeakSet,_b=function(){c(this,Ur)||(v(this,Ur,!0),typeof this.onSetModified=="function"&&this.onSetModified())};class Y0 extends Zf{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 zx{constructor({ownerDocument:t=globalThis.document,styleElement:e=null}){w(this,ma,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,ma).clear(),this.styleElement&&(this.styleElement.remove(),this.styleElement=null)}async loadSystemFont({systemFontInfo:t,_inspectFont:e}){if(!(!t||c(this,ma).has(t.loadedName))){if(re(!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,ma).add(s),e==null||e(t)}catch{ot(`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 ot(`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(Te||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(re(!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 o=this._document.createElement("canvas");o.width=1,o.height=1;const h=o.getContext("2d");let l=0;function u(A,k){if(++l>30){ot("Load test font never loaded."),k();return}if(h.font="30px "+A,h.fillText(".",0,20),h.getImageData(0,0,1,1).data[3]>0){k();return}setTimeout(u.bind(null,A,k))}const d=`lt${Date.now()}${this.loadTestFontId++}`;let f=this._loadTestFont;f=i(f,976,d.length,d);const p=16,m=1482184792;let _=s(f,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),f=i(f,p,4,Ex(_));const b=`url(data:font/opentype;base64,${btoa(f)});`,x=`@font-face {font-family:"${d}";src:${b}}`;this.insertRule(x);const C=this._document.createElement("div");C.style.visibility="hidden",C.style.width=C.style.height="10px",C.style.position="absolute",C.style.top=C.style.left="0px";for(const A of[t.loadedName,d]){const k=this._document.createElement("span");k.textContent="Hi",k.style.fontFamily=A,C.append(k)}this._document.body.append(C),u(d,()=>{C.remove(),e.complete()})}}ma=new WeakMap;class Vx{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,${Rx(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){ot(`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 Hi.BEZIER_CURVE_TO:{const[o,h,l,u,d,f]=s.slice(n,n+6);i.push(g=>g.bezierCurveTo(o,h,l,u,d,f)),n+=6}break;case Hi.MOVE_TO:{const[o,h]=s.slice(n,n+2);i.push(l=>l.moveTo(o,h)),n+=2}break;case Hi.LINE_TO:{const[o,h]=s.slice(n,n+2);i.push(l=>l.lineTo(o,h)),n+=2}break;case Hi.QUADRATIC_CURVE_TO:{const[o,h,l,u]=s.slice(n,n+4);i.push(d=>d.quadraticCurveTo(o,h,l,u)),n+=4}break;case Hi.RESTORE:i.push(o=>o.restore());break;case Hi.SAVE:i.push(o=>o.save());break;case Hi.SCALE:re(i.length===2,"Scale command is only valid at the third position.");break;case Hi.TRANSFORM:{const[o,h,l,u,d,f]=s.slice(n,n+6);i.push(g=>g.transform(o,h,l,u,d,f)),n+=6}break;case Hi.TRANSLATE:{const[o,h]=s.slice(n,n+2);i.push(l=>l.translate(o,h)),n+=2}break}return this.compiledGlyphs[e]=function(r,o){i[0](r),i[1](r),r.scale(o,-o);for(let h=2,l=i.length;h<l;h++)i[h](r)}}}class q0{constructor({enableHWA:t=!1}){w(this,al,!1);v(this,al,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,al)})}}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.")}}al=new WeakMap;class Gx extends q0{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 $0{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 K0 extends $0{async _fetch(t){const e=await Tu(t,this.isCompressed?"arraybuffer":"text");return e instanceof ArrayBuffer?new Uint8Array(e):Au(e)}}class J0{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 J0{constructor({docId:e,ownerDocument:s=globalThis.document}){super();w(this,z);w(this,qr);w(this,$r);w(this,wi);w(this,Qi);w(this,Me);w(this,Yu);w(this,Kr,0);v(this,Qi,e),v(this,Me,s)}addFilter(e){if(!e)return"none";let s=c(this,z,De).get(e);if(s)return s;const[i,n,r]=y(this,z,dd).call(this,e),o=e.length===1?i:`${i}${n}${r}`;if(s=c(this,z,De).get(o),s)return c(this,z,De).set(e,s),s;const h=`g_${c(this,Qi)}_transfer_map_${Ue(this,Kr)._++}`,l=y(this,z,rh).call(this,h);c(this,z,De).set(e,l),c(this,z,De).set(o,l);const u=y(this,z,oh).call(this,h);return y(this,z,lc).call(this,i,n,r,u),l}addHCMFilter(e,s){var p;const i=`${e}-${s}`,n="base";let r=c(this,z,ih).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,ih).set(n,r)),!e||!s))return r.url;const o=y(this,z,cc).call(this,e);e=Y.makeHexColor(...o);const h=y(this,z,cc).call(this,s);if(s=Y.makeHexColor(...h),c(this,z,nh).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,Qi)}_hcm_filter`,f=r.filter=y(this,z,oh).call(this,d);y(this,z,lc).call(this,u,u,u,f),y(this,z,Yg).call(this,f);const g=(m,_)=>{const b=o[m]/255,x=h[m]/255,C=new Array(_+1);for(let A=0;A<=_;A++)C[A]=b+A/_*(x-b);return C.join(",")};return y(this,z,lc).call(this,g(0,5),g(1,5),g(2,5),f),r.url=y(this,z,rh).call(this,d),r.url}addAlphaFilter(e){let s=c(this,z,De).get(e);if(s)return s;const[i]=y(this,z,dd).call(this,[e]),n=`alpha_${i}`;if(s=c(this,z,De).get(n),s)return c(this,z,De).set(e,s),s;const r=`g_${c(this,Qi)}_alpha_map_${Ue(this,Kr)._++}`,o=y(this,z,rh).call(this,r);c(this,z,De).set(e,o),c(this,z,De).set(n,o);const h=y(this,z,oh).call(this,r);return y(this,z,qg).call(this,i,h),o}addLuminosityFilter(e){let s=c(this,z,De).get(e||"luminosity");if(s)return s;let i,n;if(e?([i]=y(this,z,dd).call(this,[e]),n=`luminosity_${i}`):n="luminosity",s=c(this,z,De).get(n),s)return c(this,z,De).set(e,s),s;const r=`g_${c(this,Qi)}_luminosity_map_${Ue(this,Kr)._++}`,o=y(this,z,rh).call(this,r);c(this,z,De).set(e,o),c(this,z,De).set(n,o);const h=y(this,z,oh).call(this,r);return y(this,z,wb).call(this,h),e&&y(this,z,qg).call(this,i,h),o}addHighlightHCMFilter(e,s,i,n,r){var x;const o=`${s}-${i}-${n}-${r}`;let h=c(this,z,ih).get(e);if((h==null?void 0:h.key)===o||(h?((x=h.filter)==null||x.remove(),h.key=o,h.url="none",h.filter=null):(h={key:o,url:"none",filter:null},c(this,z,ih).set(e,h)),!s||!i))return h.url;const[l,u]=[s,i].map(y(this,z,cc).bind(this));let d=Math.round(.2126*l[0]+.7152*l[1]+.0722*l[2]),f=Math.round(.2126*u[0]+.7152*u[1]+.0722*u[2]),[g,p]=[n,r].map(y(this,z,cc).bind(this));f<d&&([d,f,g,p]=[f,d,p,g]),c(this,z,nh).style.color="";const m=(C,A,k)=>{const P=new Array(256),M=(f-d)/k,O=C/255,R=(A-C)/(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,Qi)}_hcm_${e}_filter`,b=h.filter=y(this,z,oh).call(this,_);return y(this,z,Yg).call(this,b),y(this,z,lc).call(this,m(g[0],p[0],5),m(g[1],p[1],5),m(g[2],p[2],5),b),h.url=y(this,z,rh).call(this,_),h.url}destroy(e=!1){e&&c(this,z,ih).size!==0||(c(this,wi)&&(c(this,wi).parentNode.parentNode.remove(),v(this,wi,null)),c(this,$r)&&(c(this,$r).clear(),v(this,$r,null)),v(this,Kr,0))}}qr=new WeakMap,$r=new WeakMap,wi=new WeakMap,Qi=new WeakMap,Me=new WeakMap,Yu=new WeakMap,Kr=new WeakMap,z=new WeakSet,De=function(){return c(this,$r)||v(this,$r,new Map)},ih=function(){return c(this,Yu)||v(this,Yu,new Map)},nh=function(){if(!c(this,wi)){const e=c(this,Me).createElement("div"),{style:s}=e;s.visibility="hidden",s.contain="strict",s.width=s.height=0,s.position="absolute",s.top=s.left=0,s.zIndex=-1;const i=c(this,Me).createElementNS(Wi,"svg");i.setAttribute("width",0),i.setAttribute("height",0),v(this,wi,c(this,Me).createElementNS(Wi,"defs")),e.append(i),i.append(c(this,wi)),c(this,Me).body.append(e)}return c(this,wi)},dd=function(e){if(e.length===1){const l=e[0],u=new Array(256);for(let f=0;f<256;f++)u[f]=l[f]/255;const d=u.join(",");return[d,d,d]}const[s,i,n]=e,r=new Array(256),o=new Array(256),h=new Array(256);for(let l=0;l<256;l++)r[l]=s[l]/255,o[l]=i[l]/255,h[l]=n[l]/255;return[r.join(","),o.join(","),h.join(",")]},rh=function(e){if(c(this,qr)===void 0){v(this,qr,"");const s=c(this,Me).URL;s!==c(this,Me).baseURI&&(Eu(s)?ot('#createUrl: ignore "data:"-URL for performance reasons.'):v(this,qr,s.split("#",1)[0]))}return`url(${c(this,qr)}#${e})`},wb=function(e){const s=c(this,Me).createElementNS(Wi,"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)},Yg=function(e){const s=c(this,Me).createElementNS(Wi,"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,Me).createElementNS(Wi,"filter");return s.setAttribute("color-interpolation-filters","sRGB"),s.setAttribute("id",e),c(this,z,nh).append(s),s},hc=function(e,s,i){const n=c(this,Me).createElementNS(Wi,s);n.setAttribute("type","discrete"),n.setAttribute("tableValues",i),e.append(n)},lc=function(e,s,i,n){const r=c(this,Me).createElementNS(Wi,"feComponentTransfer");n.append(r),y(this,z,hc).call(this,r,"feFuncR",e),y(this,z,hc).call(this,r,"feFuncG",s),y(this,z,hc).call(this,r,"feFuncB",i)},qg=function(e,s){const i=c(this,Me).createElementNS(Wi,"feComponentTransfer");s.append(i),y(this,z,hc).call(this,i,"feFuncA",e)},cc=function(e){return c(this,z,nh).style.color=e,Yf(getComputedStyle(c(this,z,nh)).getPropertyValue("color"))};class Q0{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 Z0 extends Q0{async _fetch(t){const e=await Tu(t,"arraybuffer");return new Uint8Array(e)}}if(Te){var tg=Promise.withResolvers(),Fh=null;(async()=>{const t=await Promise.resolve().then(()=>Bu),e=await Promise.resolve().then(()=>Bu),s=await Promise.resolve().then(()=>Bu),i=await Promise.resolve().then(()=>Bu);let n,r;return new Map(Object.entries({fs:t,http:e,https:s,url:i,canvas:n,path2d:r}))})().then(t=>{Fh=t,tg.resolve()},t=>{ot(`loadPackages: ${t}`),Fh=new Map,tg.resolve()})}class Rn{static get promise(){return tg.promise}static get(t){return Fh==null?void 0:Fh.get(t)}}async function tv(a){const e=await Rn.get("fs").promises.readFile(a);return new Uint8Array(e)}class Yx extends J0{}class qx extends q0{_createCanvas(t,e){return Rn.get("canvas").createCanvas(t,e)}}class $x extends $0{async _fetch(t){return tv(t)}}class Kx extends Q0{async _fetch(t){return tv(t)}}const He={FILL:"Fill",STROKE:"Stroke",SHADING:"Shading"};function eg(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 sg{getPattern(){Mt("Abstract method `getPattern` called.")}}class Jx extends sg{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===He.STROKE||i===He.FILL){const r=e.current.getClippedPathBoundingBox(i,Lt(t))||[0,0,0,0],o=Math.ceil(r[2]-r[0])||1,h=Math.ceil(r[3]-r[1])||1,l=e.cachedCanvases.getCanvas("pattern",o,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=Y.transform(s,[1,0,0,1,r[0],r[1]]),u.transform(...e.baseTransform),this.matrix&&u.transform(...this.matrix),eg(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 eg(t,this._bbox),n=this._createGradient(t);return n}}function ig(a,t,e,s,i,n,r,o){const h=t.coords,l=t.colors,u=a.data,d=a.width*4;let f;h[e+1]>h[s+1]&&(f=e,e=s,s=f,f=n,n=r,r=f),h[s+1]>h[i+1]&&(f=s,s=i,i=f,f=r,r=o,o=f),h[e+1]>h[s+1]&&(f=e,e=s,s=f,f=n,n=r,r=f);const g=(h[e]+t.offsetX)*t.scaleX,p=(h[e+1]+t.offsetY)*t.scaleY,m=(h[s]+t.offsetX)*t.scaleX,_=(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=l[n],A=l[n+1],k=l[n+2],P=l[r],M=l[r+1],O=l[r+2],R=l[o],I=l[o+1],j=l[o+2],G=Math.round(p),L=Math.round(x);let H,$,J,U,X,Ot,zt,ee;for(let Bt=G;Bt<=L;Bt++){if(Bt<_){const ft=Bt<p?0:(p-Bt)/(p-_);H=g-(g-m)*ft,$=C-(C-P)*ft,J=A-(A-M)*ft,U=k-(k-O)*ft}else{let ft;Bt>x?ft=1:_===x?ft=0:ft=(_-Bt)/(_-x),H=m-(m-b)*ft,$=P-(P-R)*ft,J=M-(M-I)*ft,U=O-(O-j)*ft}let At;Bt<p?At=0:Bt>x?At=1:At=(p-Bt)/(p-x),X=g-(g-b)*At,Ot=C-(C-R)*At,zt=A-(A-I)*At,ee=k-(k-j)*At;const we=Math.round(Math.min(H,X)),Ps=Math.round(Math.max(H,X));let kt=d*Bt+we*4;for(let ft=we;ft<=Ps;ft++)At=(H-ft)/(H-X),At<0?At=0:At>1&&(At=1),u[kt++]=$-($-Ot)*At|0,u[kt++]=J-(J-zt)*At|0,u[kt++]=U-(U-ee)*At|0,u[kt++]=255}}function Qx(a,t,e){const s=t.coords,i=t.colors;let n,r;switch(t.type){case"lattice":const o=t.verticesPerRow,h=Math.floor(s.length/o)-1,l=o-1;for(n=0;n<h;n++){let u=n*o;for(let d=0;d<l;d++,u++)ig(a,e,s[u],s[u+1],s[u+o],i[u],i[u+1],i[u+o]),ig(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)ig(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 Zx extends sg{constructor(t){super(),this._coords=t[2],this._colors=t[3],this._figures=t[4],this._bounds=t[5],this._bbox=t[7],this._background=t[8],this.matrix=null}_createMeshCanvas(t,e,s){const o=Math.floor(this._bounds[0]),h=Math.floor(this._bounds[1]),l=Math.ceil(this._bounds[2])-o,u=Math.ceil(this._bounds[3])-h,d=Math.min(Math.ceil(Math.abs(l*t[0]*1.1)),3e3),f=Math.min(Math.ceil(Math.abs(u*t[1]*1.1)),3e3),g=l/d,p=u/f,m={coords:this._coords,colors:this._colors,offsetX:-o,offsetY:-h,scaleX:1/g,scaleY:1/p},_=d+2*2,b=f+2*2,x=s.getCanvas("mesh",_,b),C=x.context,A=C.createImageData(d,f);if(e){const 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)Qx(A,P,m);return C.putImageData(A,2,2),{canvas:x.canvas,offsetX:o-2*g,offsetY:h-2*p,scaleX:g,scaleY:p}}getPattern(t,e,s,i){eg(t,this._bbox);let n;if(i===He.SHADING)n=Y.singularValueDecompose2dScale(Lt(t));else if(n=Y.singularValueDecompose2dScale(e.baseTransform),this.matrix){const o=Y.singularValueDecompose2dScale(this.matrix);n=[n[0]*o[0],n[1]*o[1]]}const r=this._createMeshCanvas(n,i===He.SHADING?null:this._background,e.cachedCanvases);return i!==He.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 tS extends sg{getPattern(){return"hotpink"}}function eS(a){switch(a[0]){case"RadialAxial":return new Jx(a);case"Mesh":return new Zx(a);case"Dummy":return new tS}throw new Error(`Unknown IR type: ${a[0]}`)}const ev={COLORED:1,UNCOLORED:2},qu=class qu{constructor(t,e,s,i,n){this.operatorList=t[2],this.matrix=t[3],this.bbox=t[4],this.xstep=t[5],this.ystep=t[6],this.paintType=t[7],this.tilingType=t[8],this.color=e,this.ctx=s,this.canvasGraphicsFactory=i,this.baseTransform=n}createPatternCanvas(t){const{bbox:e,operatorList:s,paintType:i,tilingType:n,color:r,canvasGraphicsFactory:o}=this;let{xstep:h,ystep:l}=this;h=Math.abs(h),l=Math.abs(l),Su("TilingType: "+n);const u=e[0],d=e[1],f=e[2],g=e[3],p=f-u,m=g-d,_=Y.singularValueDecompose2dScale(this.matrix),b=Y.singularValueDecompose2dScale(this.baseTransform),x=_[0]*b[0],C=_[1]*b[1];let A=p,k=m,P=!1,M=!1;const O=Math.ceil(h*x),R=Math.ceil(l*C),I=Math.ceil(p*x),j=Math.ceil(m*C);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,C),H=t.cachedCanvases.getCanvas("pattern",G.size,L.size),$=H.context,J=o.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,f,g),J.baseTransform=Lt(J.ctx),J.executeOperatorList(s),J.endDrawing(),$.restore(),P||M){const U=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,C),zt=X.size,ee=Ot.size,Bt=t.cachedCanvases.getCanvas("pattern-workaround",zt,ee),At=Bt.context,we=P?Math.floor(p/h):0,Ps=M?Math.floor(m/l):0;for(let kt=0;kt<=we;kt++)for(let ft=0;ft<=Ps;ft++)At.drawImage(U,zt*kt,ee*ft,zt,ee,0,0,zt,ee);return{canvas:Bt.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(qu.MAX_PATTERN_SIZE,e);let n=Math.ceil(t*s);return n>=i?n=i:s=n/t,{scale:s,size:n}}clipBbox(t,e,s,i,n){const r=i-e,o=n-s;t.ctx.rect(e,s,r,o),t.current.updateRectMinMax(Lt(t.ctx),[e,s,i,n]),t.clip(),t.endPath()}setFillAndStrokeStyleToContext(t,e,s){const i=t.ctx,n=t.current;switch(e){case ev.COLORED:const r=this.ctx;i.fillStyle=r.fillStyle,i.strokeStyle=r.strokeStyle,n.fillColor=r.fillStyle,n.strokeColor=r.strokeStyle;break;case ev.UNCOLORED:const o=Y.makeHexColor(s[0],s[1],s[2]);i.fillStyle=o,i.strokeStyle=o,n.fillColor=o,n.strokeColor=o;break;default:throw new Tx(`Unsupported paint type: ${e}`)}}getPattern(t,e,s,i){let n=s;i!==He.SHADING&&(n=Y.transform(n,e.baseTransform),this.matrix&&(n=Y.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}};tt(qu,"MAX_PATTERN_SIZE",3e3);let ng=qu;function sS({src:a,srcPos:t=0,dest:e,width:s,height:i,nonBlackColor:n=4294967295,inverseDecode:r=!1}){const o=Be.isLittleEndian?4278190080:255,[h,l]=r?[n,o]:[o,n],u=s>>3,d=s&7,f=a.length;e=new Uint32Array(e.buffer);let g=0;for(let p=0;p<i;p++){for(const _=t+u;t<_;t++){const b=t<f?a[t]:255;e[g++]=b&128?l:h,e[g++]=b&64?l:h,e[g++]=b&32?l:h,e[g++]=b&16?l:h,e[g++]=b&8?l:h,e[g++]=b&4?l:h,e[g++]=b&2?l:h,e[g++]=b&1?l:h}if(d===0)continue;const m=t<f?a[t++]:255;for(let _=0;_<d;_++)e[g++]=m&1<<7-_?l:h}return{srcPos:t,destPos:g}}const sv=16,iv=100,iS=15,nv=10,rv=1e3,Ke=16;function nS(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 rS{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 Ou(a,t,e,s,i,n,r,o,h,l){const[u,d,f,g,p,m]=Lt(a);if(d===0&&f===0){const x=r*u+p,C=Math.round(x),A=o*g+m,k=Math.round(A),P=(r+h)*u+p,M=Math.abs(Math.round(P)-C)||1,O=(o+l)*g+m,R=Math.abs(Math.round(O)-k)||1;return a.setTransform(Math.sign(u),0,0,Math.sign(g),C,k),a.drawImage(t,e,s,i,n,0,0,M,R),a.setTransform(u,d,f,g,p,m),[M,R]}if(u===0&&g===0){const x=o*f+p,C=Math.round(x),A=r*d+m,k=Math.round(A),P=(o+l)*f+p,M=Math.abs(Math.round(P)-C)||1,O=(r+h)*d+m,R=Math.abs(Math.round(O)-k)||1;return a.setTransform(0,Math.sign(d),Math.sign(f),0,C,k),a.drawImage(t,e,s,i,n,0,0,R,M),a.setTransform(u,d,f,g,p,m),[R,M]}a.drawImage(t,e,s,i,n,r,o,h,l);const _=Math.hypot(u,d),b=Math.hypot(f,g);return[_*h,b*l]}function oS(a){const{width:t,height:e}=a;if(t>rv||e>rv)return null;const s=1e3,i=new Uint8Array([0,2,4,0,1,0,5,4,8,10,0,8,0,2,1,0]),n=t+1;let r=new Uint8Array(n*(e+1)),o,h,l;const u=t+7&-8;let d=new Uint8Array(u*e),f=0;for(const b of a.data){let x=128;for(;x>0;)d[f++]=b&x?0:255,x>>=1}let g=0;for(f=0,d[f]!==0&&(r[0]=1,++g),h=1;h<t;h++)d[f]!==d[f+1]&&(r[h]=d[f]?2:1,++g),f++;for(d[f]!==0&&(r[h]=2,++g),o=1;o<e;o++){f=o*u,l=o*n,d[f-u]!==d[f]&&(r[l]=d[f]?1:8,++g);let b=(d[f]?4:0)+(d[f-u]?8:0);for(h=1;h<t;h++)b=(b>>2)+(d[f+1]?4:0)+(d[f-u+1]?8:0),i[b]&&(r[l+h]=i[b],++g),f++;if(d[f-u]!==d[f]&&(r[l+h]=d[f]?2:4,++g),g>s)return null}for(f=u*(e-1),l=o*n,d[f]!==0&&(r[l]=8,++g),h=1;h<t;h++)d[f]!==d[f+1]&&(r[l+h]=d[f]?4:8,++g),f++;if(d[f]!==0&&(r[l+h]=4,++g),g>s)return null;const p=new Int32Array([0,n,-1,0,-n,0,0,0,1]),m=new Path2D;for(o=0;g&&o<=e;o++){let b=o*n;const x=b+t;for(;b<x&&!r[b];)b++;if(b===x)continue;m.moveTo(b%n,o);const C=b;let 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]||--g}while(C!==b);--o}return d=null,r=null,function(b){b.save(),b.scale(1/t,-1/e),b.translate(0,-e),b.fill(m),b.beginPath(),b.restore()}}class ov{constructor(t,e){this.alphaIsShape=!1,this.fontSize=0,this.fontSizeScale=1,this.textMatrix=B0,this.textMatrixScale=1,this.fontMatrix=If,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.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]=Y.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=Y.applyTransform(e,t),i=Y.applyTransform(e.slice(2),t),n=Y.applyTransform([e[0],e[3]],t),r=Y.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){Y.scaleMinMax(t,e),this.minX=Math.min(this.minX,e[0]),this.minY=Math.min(this.minY,e[1]),this.maxX=Math.max(this.maxX,e[2]),this.maxY=Math.max(this.maxY,e[3])}updateCurvePathMinMax(t,e,s,i,n,r,o,h,l,u){const d=Y.bezierBoundingBox(e,s,i,n,r,o,h,l,u);u||this.updateRectMinMax(t,d)}getPathBoundingBox(t=He.FILL,e=null){const s=[this.minX,this.minY,this.maxX,this.maxY];if(t===He.STROKE){e||Mt("Stroke bounding box must include transform.");const i=Y.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=Y.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=He.FILL,e=null){return Y.intersect(this.clipBox,this.getPathBoundingBox(t,e))}}function av(a,t){if(typeof ImageData<"u"&&t instanceof ImageData){a.putImageData(t,0,0);return}const e=t.height,s=t.width,i=e%Ke,n=(e-i)/Ke,r=i===0?n:n+1,o=a.createImageData(s,Ke);let h=0,l;const u=t.data,d=o.data;let f,g,p,m;if(t.kind===_u.GRAYSCALE_1BPP){const _=u.byteLength,b=new Uint32Array(d.buffer,0,d.byteLength>>2),x=b.length,C=s+7>>3,A=4294967295,k=Be.isLittleEndian?4278190080:255;for(f=0;f<r;f++){for(p=f<n?Ke:i,l=0,g=0;g<p;g++){const P=_-h;let M=0;const O=P>C?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;a.putImageData(o,0,f*Ke)}}else if(t.kind===_u.RGBA_32BPP){for(g=0,m=s*Ke*4,f=0;f<n;f++)d.set(u.subarray(h,h+m)),h+=m,a.putImageData(o,0,g),g+=Ke;f<r&&(m=s*i*4,d.set(u.subarray(h,h+m)),a.putImageData(o,0,g))}else if(t.kind===_u.RGB_24BPP)for(p=Ke,m=s*p,f=0;f<r;f++){for(f>=n&&(p=i,m=s*p),l=0,g=m;g--;)d[l++]=u[h++],d[l++]=u[h++],d[l++]=u[h++],d[l++]=255;a.putImageData(o,0,f*Ke)}else throw new Error(`bad image kind: ${t.kind}`)}function hv(a,t){if(t.bitmap){a.drawImage(t.bitmap,0,0);return}const e=t.height,s=t.width,i=e%Ke,n=(e-i)/Ke,r=i===0?n:n+1,o=a.createImageData(s,Ke);let h=0;const l=t.data,u=o.data;for(let d=0;d<r;d++){const f=d<n?Ke:i;({srcPos:h}=sS({src:l,srcPos:h,dest:u,width:s,height:f,nonBlackColor:0})),a.putImageData(o,0,d*Ke)}}function Lh(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 Pu(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),!Te){const{filter:t}=a;t!=="none"&&t!==""&&(a.filter="none")}}function lv(a,t){if(t)return!0;const e=Y.singularValueDecompose2dScale(a);e[0]=Math.fround(e[0]),e[1]=Math.fround(e[1]);const s=Math.fround((globalThis.devicePixelRatio||1)*Dn.PDF_TO_CSS_UNITS);return e[0]<=s&&e[1]<=s}const aS=["butt","round","square"],hS=["miter","round","bevel"],lS={},cv={},xg=class xg{constructor(t,e,s,i,n,{optionalContentConfig:r,markedContentStack:o=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=o||[],this.optionalContentConfig=r,this.cachedCanvases=new rS(this.canvasFactory),this.cachedPatterns=new Map,this.annotationCanvasMap=h,this.viewportScale=1,this.outputScaleX=1,this.outputScaleY=1,this.pageColors=l,this._cachedScaleForStroking=[-1,0],this._cachedGetSinglePixelWidth=null,this._cachedBitmapsMap=new Map}getObject(t,e=null){return typeof t=="string"?t.startsWith("g_")?this.commonObjs.get(t):this.objs.get(t):e}beginDrawing({transform:t,viewport:e,transparency:s=!1,background:i=null}){const n=this.ctx.canvas.width,r=this.ctx.canvas.height,o=this.ctx.fillStyle;if(this.ctx.fillStyle=i||"#ffffff",this.ctx.fillRect(0,0,n,r),this.ctx.fillStyle=o,s){const h=this.cachedCanvases.getCanvas("transparent",n,r);this.compositeCtx=this.ctx,this.transparentCanvas=h.canvas,this.ctx=h.context,this.ctx.save(),this.ctx.transform(...Lt(this.compositeCtx))}this.ctx.save(),Pu(this.ctx),t&&(this.ctx.transform(...t),this.outputScaleX=t[0],this.outputScaleY=t[0]),this.ctx.transform(...e.transform),this.viewportScale=e.scale,this.baseTransform=Lt(this.ctx)}executeOperatorList(t,e,s,i){const n=t.argsArray,r=t.fnArray;let o=e||0;const h=n.length;if(h===o)return o;const l=h-o>nv&&typeof s=="function",u=l?Date.now()+iS:0;let d=0;const f=this.commonObjs,g=this.objs;let p;for(;;){if(i!==void 0&&o===i.nextBreakPoint)return i.breakIt(o,s),o;if(p=r[o],p!==Xs.dependency)this[p].apply(this,n[o]);else for(const m of n[o]){const _=m.startsWith("g_")?f:g;if(!_.has(m))return _.get(m,s),o}if(o++,o===h)return o;if(l&&++d>nv){if(Date.now()>u)return s(),o;d=0}}}endDrawing(){y(this,Un,$g).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,Kg).call(this)}_scaleImage(t,e){const s=t.width??t.displayWidth,i=t.height??t.displayHeight;let n=Math.max(Math.hypot(e[0],e[1]),1),r=Math.max(Math.hypot(e[2],e[3]),1),o=s,h=i,l="prescale1",u,d;for(;n>2&&o>1||r>2&&h>1;){let f=o,g=h;n>2&&o>1&&(f=o>=16384?Math.floor(o/2)-1||1:Math.ceil(o/2),n/=o/f),r>2&&h>1&&(g=h>=16384?Math.floor(h/2)-1||1:Math.ceil(h)/2,r/=h/g),u=this.cachedCanvases.getCanvas(l,f,g),d=u.context,d.clearRect(0,0,f,g),d.drawImage(t,0,0,o,h,0,0,f,g),t=u.canvas,o=f,h=g,l=l==="prescale1"?"prescale2":"prescale1"}return{img:t,paintWidth:o,paintHeight:h}}_createMaskCanvas(t){const e=this.ctx,{width:s,height:i}=t,n=this.current.fillColor,r=this.current.patternFill,o=Lt(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?o:[o.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(o[0],o[2])+o[4]),j=Math.round(Math.min(o[1],o[3])+o[5]);return{canvas:R,offsetX:I,offsetY:j}}u=R}u||(d=this.cachedCanvases.getCanvas("maskCanvas",s,i),hv(d.context,t));let f=Y.transform(o,[1/s,0,0,-1/i,0,0]);f=Y.transform(f,[1,0,0,1,0,-i]);const[g,p,m,_]=Y.getAxialAlignedBoundingBox([0,0,s,i],f),b=Math.round(m-g)||1,x=Math.round(_-p)||1,C=this.cachedCanvases.getCanvas("fillCanvas",b,x),A=C.context,k=g,P=p;A.translate(-k,-P),A.transform(...f),u||(u=this._scaleImage(d.canvas,Xi(A)),u=u.img,h&&r&&h.set(l,u)),A.imageSmoothingEnabled=lv(Lt(A),t.interpolate),Ou(A,u,0,0,u.width,u.height,0,0,s,i),A.globalCompositeOperation="source-in";const M=Y.transform(Xi(A),[1,0,0,1,-k,-P]);return A.fillStyle=r?n.getPattern(e,this,M,He.FILL):n,A.fillRect(0,0,s,i),h&&!r&&(this.cachedCanvases.delete("fillCanvas"),h.set(l,C.canvas)),{canvas:C.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=aS[t]}setLineJoin(t){this.ctx.lineJoin=hS[t]}setMiterLimit(t){this.ctx.miterLimit=t}setDash(t,e){const s=this.ctx;s.setLineDash!==void 0&&(s.setLineDash(t),s.lineDashOffset=e)}setRenderingIntent(t){}setFlatness(t){}setGState(t){for(const[e,s]of t)switch(e){case"LW":this.setLineWidth(s);break;case"LC":this.setLineCap(s);break;case"LJ":this.setLineJoin(s);break;case"ML":this.setMiterLimit(s);break;case"D":this.setDash(s[0],s[1]);break;case"RI":this.setRenderingIntent(s);break;case"FL":this.setFlatness(s);break;case"Font":this.setFont(s[0],s[1]);break;case"CA":this.current.strokeAlpha=s;break;case"ca":this.current.fillAlpha=s,this.ctx.globalAlpha=s;break;case"BM":this.ctx.globalCompositeOperation=s;break;case"SMask":this.current.activeSMask=s?this.tempSMask:null,this.tempSMask=null,this.checkSMaskState();break;case"TR":this.ctx.filter=this.current.transferMaps=this.filterFactory.addFilter(s);break}}get inSMaskMode(){return!!this.suspendedCtx}checkSMaskState(){const t=this.inSMaskMode;this.current.activeSMask&&!t?this.beginSMaskMode():!this.current.activeSMask&&t&&this.endSMaskMode()}beginSMaskMode(){if(this.inSMaskMode)throw new Error("beginSMaskMode called while already in smask mode");const t=this.ctx.canvas.width,e=this.ctx.canvas.height,s="smaskGroupAt"+this.groupLevel,i=this.cachedCanvases.getCanvas(s,t,e);this.suspendedCtx=this.ctx,this.ctx=i.context;const n=this.ctx;n.setTransform(...Lt(this.suspendedCtx)),Lh(this.suspendedCtx,n),nS(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(),Lh(this.ctx,this.suspendedCtx),this.ctx=this.suspendedCtx,this.suspendedCtx=null}compose(t){if(!this.current.activeSMask)return;t?(t[0]=Math.floor(t[0]),t[1]=Math.floor(t[1]),t[2]=Math.ceil(t[2]),t[3]=Math.ceil(t[3])):t=[0,0,this.ctx.canvas.width,this.ctx.canvas.height];const e=this.current.activeSMask,s=this.suspendedCtx;this.composeSMask(s,e,this.ctx,t),this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.ctx.restore()}composeSMask(t,e,s,i){const n=i[0],r=i[1],o=i[2]-n,h=i[3]-r;o===0||h===0||(this.genericComposeSMask(e.context,s,o,h,e.subtype,e.backdrop,e.transferMap,n,r,e.offsetX,e.offsetY),t.save(),t.globalAlpha=1,t.globalCompositeOperation="source-over",t.setTransform(1,0,0,1,0,0),t.drawImage(s.canvas,0,0),t.restore())}genericComposeSMask(t,e,s,i,n,r,o,h,l,u,d){let f=t.canvas,g=h-u,p=l-d;if(r){const _=Y.makeHexColor(...r);if(g<0||p<0||g+s>f.width||p+i>f.height){const b=this.cachedCanvases.getCanvas("maskExtension",s,i),x=b.context;x.drawImage(f,-g,-p),x.globalCompositeOperation="destination-atop",x.fillStyle=_,x.fillRect(0,0,s,i),x.globalCompositeOperation="source-over",f=b.canvas,g=p=0}else{t.save(),t.globalAlpha=1,t.setTransform(1,0,0,1,0,0);const b=new Path2D;b.rect(g,p,s,i),t.clip(b),t.globalCompositeOperation="destination-atop",t.fillStyle=_,t.fillRect(g,p,s,i),t.restore()}}e.save(),e.globalAlpha=1,e.setTransform(1,0,0,1,0,0),n==="Alpha"&&o?e.filter=this.filterFactory.addAlphaFilter(o):n==="Luminosity"&&(e.filter=this.filterFactory.addLuminosityFilter(o));const m=new Path2D;m.rect(h,l,s,i),e.clip(m),e.globalCompositeOperation="destination-in",e.drawImage(f,g,p,s,i,h,l,s,i),e.restore()}save(){this.inSMaskMode?(Lh(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(),Lh(this.suspendedCtx,this.ctx)):this.ctx.restore(),this.checkSMaskState(),this.pendingClip=null,this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null)}transform(t,e,s,i,n,r){this.ctx.transform(t,e,s,i,n,r),this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null}constructPath(t,e,s){const i=this.ctx,n=this.current;let r=n.x,o=n.y,h,l;const u=Lt(i),d=u[0]===0&&u[3]===0||u[1]===0&&u[2]===0,f=d?s.slice(0):null;for(let g=0,p=0,m=t.length;g<m;g++)switch(t[g]|0){case Xs.rectangle:r=e[p++],o=e[p++];const _=e[p++],b=e[p++],x=r+_,C=o+b;i.moveTo(r,o),_===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 Xs.moveTo:r=e[p++],o=e[p++],i.moveTo(r,o),d||n.updatePathMinMax(u,r,o);break;case Xs.lineTo:r=e[p++],o=e[p++],i.lineTo(r,o),d||n.updatePathMinMax(u,r,o);break;case Xs.curveTo:h=r,l=o,r=e[p+4],o=e[p+5],i.bezierCurveTo(e[p],e[p+1],e[p+2],e[p+3],r,o),n.updateCurvePathMinMax(u,h,l,e[p],e[p+1],e[p+2],e[p+3],r,o,f),p+=6;break;case Xs.curveTo2:h=r,l=o,i.bezierCurveTo(r,o,e[p],e[p+1],e[p+2],e[p+3]),n.updateCurvePathMinMax(u,h,l,r,o,e[p],e[p+1],e[p+2],e[p+3],f),r=e[p+2],o=e[p+3],p+=4;break;case Xs.curveTo3:h=r,l=o,r=e[p+2],o=e[p+3],i.bezierCurveTo(e[p],e[p+1],r,o,r,o),n.updateCurvePathMinMax(u,h,l,e[p],e[p+1],r,o,r,o,f),p+=4;break;case Xs.closePath:i.closePath();break}d&&n.updateScalingPathMinMax(u,f),n.setCurrentPoint(r,o)}closePath(){this.ctx.closePath()}stroke(t=!0){const e=this.ctx,s=this.current.strokeColor;e.globalAlpha=this.current.strokeAlpha,this.contentVisible&&(typeof s=="object"&&(s!=null&&s.getPattern)?(e.save(),e.strokeStyle=s.getPattern(e,this,Xi(e),He.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),He.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=lS}eoClip(){this.pendingClip=cv}beginText(){this.current.textMatrix=B0,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||If,(i.fontMatrix[0]===0||i.fontMatrix[3]===0)&&ot("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 l=e;e<sv?l=sv:e>iv&&(l=iv),this.current.fontSizeScale=e/l,this.ctx.font=`${h} ${o} ${l}px ${r}`}setTextRenderingMode(t){this.current.textRenderingMode=t}setTextRise(t){this.current.textRise=t}moveText(t,e){this.current.x=this.current.lineX+=t,this.current.y=this.current.lineY+=e}setLeadingMoveText(t,e){this.setLeading(-e),this.moveText(t,e)}setTextMatrix(t,e,s,i,n,r){this.current.textMatrix=[t,e,s,i,n,r],this.current.textMatrixScale=Math.hypot(t,e),this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0}nextLine(){this.moveText(0,this.current.leading)}paintChar(t,e,s,i){const n=this.ctx,r=this.current,o=r.font,h=r.textRenderingMode,l=r.fontSize/r.fontSizeScale,u=h&Ee.FILL_STROKE_MASK,d=!!(h&Ee.ADD_TO_PATH_FLAG),f=r.patternFill&&!o.missingFile;let g;(o.disableFontFace||d||f)&&(g=o.getPathGenerator(this.commonObjs,t)),o.disableFontFace||f?(n.save(),n.translate(e,s),n.beginPath(),g(n,l),i&&n.setTransform(...i),(u===Ee.FILL||u===Ee.FILL_STROKE)&&n.fill(),(u===Ee.STROKE||u===Ee.FILL_STROKE)&&n.stroke(),n.restore()):((u===Ee.FILL||u===Ee.FILL_STROKE)&&n.fillText(t,e,s),(u===Ee.STROKE||u===Ee.FILL_STROKE)&&n.strokeText(t,e,s)),d&&(this.pendingTextPaths||(this.pendingTextPaths=[])).push({transform:Lt(n),x:e,y:s,fontSize:l,addToPath:g})}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,o=e.charSpacing,h=e.wordSpacing,l=e.fontDirection,u=e.textHScale*l,d=t.length,f=s.vertical,g=f?1:-1,p=s.defaultVMetrics,m=i*e.fontMatrix[0],_=e.textRenderingMode===Ee.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,Xi(n),He.FILL);b=Lt(n),n.restore(),n.fillStyle=P}let x=e.lineWidth;const C=e.textMatrixScale;if(C===0||x===0){const P=e.textRenderingMode&Ee.FILL_STROKE_MASK;(P===Ee.STROKE||P===Ee.FILL_STROKE)&&(x=this.getSinglePixelWidth())}else x/=C;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+=g*P*i/1e3;continue}let M=!1;const O=(P.isSpace?h:0)+o,R=P.fontChar,I=P.accent;let j,G,L=P.width;if(f){const $=P.vmetric||p,J=-(P.vmetric?$[1]:L*.5)*m,U=$[2]*m;L=$?-$[0]:L,j=J/r,G=(A+U)/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=f?L*m-O*l:L*m+O*l;A+=H,M&&n.restore()}f?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,o=i.vertical?1:-1,h=s.charSpacing,l=s.wordSpacing,u=s.textHScale*r,d=s.fontMatrix||If,f=t.length,g=s.textRenderingMode===Ee.INVISIBLE;let p,m,_,b;if(!(g||n===0)){for(this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null,e.save(),e.transform(...s.textMatrix),e.translate(s.x,s.y),e.scale(u,r),p=0;p<f;++p){if(m=t[p],typeof m=="number"){b=o*m*n/1e3,this.ctx.translate(b,0),s.x+=b*u;continue}const x=(m.isSpace?l:0)+h,C=i.charProcOperatorList[m.operatorListId];if(!C){ot(`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(_,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||Lt(this.ctx),n={createCanvasGraphics:r=>new xg(r,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack})};e=new ng(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=Y.makeHexColor(t,e,s)}setStrokeTransparent(){this.ctx.strokeStyle=this.current.strokeColor="transparent"}setFillRGBColor(t,e,s){this.ctx.fillStyle=this.current.fillColor=Y.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=eS(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),He.SHADING);const i=Xi(e);if(i){const{width:n,height:r}=e.canvas,[o,h,l,u]=Y.getAxialAlignedBoundingBox([0,0,n,r],i);this.ctx.fillRect(o,h,l-o,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=Lt(this.ctx),e)){const s=e[2]-e[0],i=e[3]-e[1];this.ctx.rect(e[0],e[1],s,i),this.current.updateRectMinMax(Lt(this.ctx),e),this.clip(),this.endPath()}}paintFormXObjectEnd(){this.contentVisible&&(this.restore(),this.baseTransform=this.baseTransformStack.pop())}beginGroup(t){if(!this.contentVisible)return;this.save(),this.inSMaskMode&&(this.endSMaskMode(),this.current.activeSMask=null);const e=this.ctx;t.isolated||Su("TODO: Support non-isolated groups."),t.knockout&&ot("Knockout groups not supported.");const s=Lt(e);if(t.matrix&&e.transform(...t.matrix),!t.bbox)throw new Error("Bounding box is required.");let i=Y.getAxialAlignedBoundingBox(t.bbox,Lt(e));const n=[0,0,e.canvas.width,e.canvas.height];i=Y.intersect(i,n)||[0,0,0,0];const r=Math.floor(i[0]),o=Math.floor(i[1]),h=Math.max(Math.ceil(i[2])-r,1),l=Math.max(Math.ceil(i[3])-o,1);this.current.startNewPathAndClipBox([0,0,h,l]);let u="groupAt"+this.groupLevel;t.smask&&(u+="_smask_"+this.smaskCounter++%2);const d=this.cachedCanvases.getCanvas(u,h,l),f=d.context;f.translate(-r,-o),f.transform(...s),t.smask?this.smaskStack.push({canvas:d.canvas,context:f,offsetX:r,offsetY:o,subtype:t.smask.subtype,backdrop:t.smask.backdrop,transferMap:t.smask.transferMap||null,startTransformInverse:null}):(e.setTransform(1,0,0,1,0,0),e.translate(r,o),e.save()),Lh(e,f),this.ctx=f,this.setGState([["BM","source-over"],["ca",1],["CA",1]]),this.groupStack.push(e),this.groupLevel++}endGroup(t){if(!this.contentVisible)return;this.groupLevel--;const e=this.ctx,s=this.groupStack.pop();if(this.ctx=s,this.ctx.imageSmoothingEnabled=!1,t.smask)this.tempSMask=this.smaskStack.pop(),this.restore();else{this.ctx.restore();const i=Lt(this.ctx);this.restore(),this.ctx.save(),this.ctx.setTransform(...i);const n=Y.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,$g).call(this),Pu(this.ctx),this.ctx.save(),this.save(),this.baseTransform&&this.ctx.setTransform(...this.baseTransform),e){const r=e[2]-e[0],o=e[3]-e[1];if(n&&this.annotationCanvasMap){s=s.slice(),s[4]-=e[0],s[5]-=e[1],e=e.slice(),e[0]=e[1]=0,e[2]=r,e[3]=o;const[h,l]=Y.singularValueDecompose2dScale(Lt(this.ctx)),{viewportScale:u}=this,d=Math.ceil(r*this.outputScaleX*u),f=Math.ceil(o*this.outputScaleY*u);this.annotationCanvas=this.canvasFactory.create(d,f);const{canvas:g,context:p}=this.annotationCanvas;this.annotationCanvasMap.set(t,g),this.annotationCanvas.savedCtx=this.ctx,this.ctx=p,this.ctx.save(),this.ctx.setTransform(h,0,0,-l,0,o*l),Pu(this.ctx)}else Pu(this.ctx),this.endPath(),this.ctx.rect(e[0],e[1],r,o),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,Kg).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 o=this.ctx;o.save();const h=Lt(o);o.transform(e,s,i,n,0,0);const l=this._createMaskCanvas(t);o.setTransform(1,0,0,1,l.offsetX-h[4],l.offsetY-h[5]);for(let u=0,d=r.length;u<d;u+=2){const f=Y.transform(h,[e,s,i,n,r[u],r[u+1]]),[g,p]=Y.applyTransform([0,0],f);o.drawImage(l.canvas,g,p)}o.restore(),this.compose()}paintImageMaskXObjectGroup(t){if(!this.contentVisible)return;const e=this.ctx,s=this.current.fillColor,i=this.current.patternFill;for(const n of t){const{data:r,width:o,height:h,transform:l}=n,u=this.cachedCanvases.getCanvas("maskCanvas",o,h),d=u.context;d.save();const f=this.getObject(r,n);hv(d,f),d.globalCompositeOperation="source-in",d.fillStyle=i?s.getPattern(d,this,Xi(e),He.FILL):s,d.fillRect(0,0,o,h),d.restore(),e.save(),e.transform(...l),e.scale(1,-1),Ou(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){ot("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){ot("Dependent image isn't ready yet");return}const r=n.width,o=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: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(),!Te){const{filter:o}=i;o!=="none"&&o!==""&&(i.filter="none")}i.scale(1/e,-1/s);let n;if(t.bitmap)n=this.applyTransferMapsToBitmap(t);else if(typeof HTMLElement=="function"&&t instanceof HTMLElement||!t.data)n=t;else{const h=this.cachedCanvases.getCanvas("inlineImage",e,s).context;av(h,t),n=this.applyTransferMapsToCanvas(h)}const r=this._scaleImage(n,Xi(i));i.imageSmoothingEnabled=lv(Lt(i),t.interpolate),Ou(i,r.img,0,0,r.paintWidth,r.paintHeight,0,-s,e,s),this.compose(),this.restore()}paintInlineImageXObjectGroup(t,e){if(!this.contentVisible)return;const s=this.ctx;let i;if(t.bitmap)i=t.bitmap;else{const n=t.width,r=t.height,h=this.cachedCanvases.getCanvas("inlineImage",n,r).context;av(h,t),i=this.applyTransferMapsToCanvas(h)}for(const n of e)s.save(),s.transform(...n.transform),s.scale(1,-1),Ou(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===cv?s.clip("evenodd"):s.clip()),this.pendingClip=null),this.current.startNewPathAndClipBox(this.current.clipBox),s.beginPath()}getSinglePixelWidth(){if(!this._cachedGetSinglePixelWidth){const t=Lt(this.ctx);if(t[1]===0&&t[2]===0)this._cachedGetSinglePixelWidth=1/Math.min(Math.abs(t[0]),Math.abs(t[3]));else{const e=Math.abs(t[0]*t[3]-t[2]*t[1]),s=Math.hypot(t[0],t[2]),i=Math.hypot(t[1],t[3]);this._cachedGetSinglePixelWidth=Math.max(s,i)/e}}return this._cachedGetSinglePixelWidth}getScaleForStroking(){if(this._cachedScaleForStroking[0]===-1){const{lineWidth:t}=this.current,{a:e,b:s,c:i,d:n}=this.ctx.getTransform();let r,o;if(s===0&&i===0){const h=Math.abs(e),l=Math.abs(n);if(h===l)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/l;else{const u=h*t,d=l*t;r=u<1?1/u:1,o=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,o=l/h;else{const d=t*h;r=u>d?u/d:1,o=l>d?l/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}};Un=new WeakSet,$g=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)},Kg=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 Zo=xg;for(const a in Xs)Zo.prototype[a]!==void 0&&(Zo.prototype[Xs[a]]=Zo.prototype[a]);class zi{static get workerPort(){return c(this,hl)}static set workerPort(t){if(!(typeof Worker<"u"&&t instanceof Worker)&&t!==null)throw new Error("Invalid `workerPort` type.");v(this,hl,t)}static get workerSrc(){return c(this,ll)}static set workerSrc(t){if(typeof t!="string")throw new Error("Invalid `workerSrc` type.");v(this,ll,t)}}hl=new WeakMap,ll=new WeakMap,w(zi,hl,null),w(zi,ll,"");const Du={UNKNOWN:0,DATA:1,ERROR:2},Qt={UNKNOWN:0,CANCEL:1,CANCEL_COMPLETE:2,CLOSE:3,ENQUEUE:4,ERROR:5,PULL:6,PULL_COMPLETE:7,START_COMPLETE:8};function as(a){switch(a instanceof Error||typeof a=="object"&&a!==null||Mt('wrapReason: Expected "reason" to be a (possibly cloned) Error.'),a.name){case"AbortException":return new Tr(a.message);case"MissingPDFException":return new Ar(a.message);case"PasswordException":return new Nf(a.message,a.code);case"UnexpectedResponseException":return new Cu(a.message,a.status);case"UnknownErrorException":return new Bf(a.message,a.details);default:return new Bf(a.message,a.toString())}}class Ih{constructor(t,e,s){w(this,As);w(this,va,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,xb).bind(this),{signal:c(this,va).signal})}on(t,e){const s=this.actionHandler;if(s[t])throw new Error(`There is already an actionName called "${t}"`);s[t]=e}send(t,e,s){this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:t,data:e},s)}sendWithPromise(t,e,s){const i=this.callbackId++,n=Promise.withResolvers();this.callbackCapabilities[i]=n;try{this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:t,callbackId:i,data:e},s)}catch(r){n.reject(r)}return n.promise}sendWithStream(t,e,s,i){const n=this.streamId++,r=this.sourceName,o=this.targetName,h=this.comObj;return new ReadableStream({start:l=>{const u=Promise.withResolvers();return this.streamControllers[n]={controller:l,startCall:u,pullCall:null,cancelCall:null,isClosed:!1},h.postMessage({sourceName:r,targetName:o,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:o,stream:Qt.PULL,streamId:n,desiredSize:l.desiredSize}),u.promise},cancel:l=>{re(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:o,stream:Qt.CANCEL,streamId:n,reason:as(l)}),u.promise}},s)}destroy(){var t;(t=c(this,va))==null||t.abort(),v(this,va,null)}}va=new WeakMap,As=new WeakSet,xb=function({data:t}){if(t.targetName!==this.sourceName)return;if(t.stream){y(this,As,Cb).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===Du.DATA)i.resolve(t.data);else if(t.callback===Du.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:Du.DATA,callbackId:t.callbackId,data:r})},function(r){n.postMessage({sourceName:s,targetName:i,callback:Du.ERROR,callbackId:t.callbackId,reason:as(r)})});return}if(t.streamId){y(this,As,Sb).call(this,t);return}e(t.data)},Sb=function(t){const e=t.streamId,s=this.sourceName,i=t.sourceName,n=this.comObj,r=this,o=this.actionHandler[t.action],h={enqueue(l,u=1,d){if(this.isCancelled)return;const f=this.desiredSize;this.desiredSize-=u,f>0&&this.desiredSize<=0&&(this.sinkCapability=Promise.withResolvers(),this.ready=this.sinkCapability.promise),n.postMessage({sourceName:s,targetName:i,stream:Qt.ENQUEUE,streamId:e,chunk:l},d)},close(){this.isCancelled||(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:Qt.CLOSE,streamId:e}),delete r.streamSinks[e])},error(l){re(l instanceof Error,"error must have a valid reason"),!this.isCancelled&&(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:Qt.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(o(t.data,h))}).then(function(){n.postMessage({sourceName:s,targetName:i,stream:Qt.START_COMPLETE,streamId:e,success:!0})},function(l){n.postMessage({sourceName:s,targetName:i,stream:Qt.START_COMPLETE,streamId:e,reason:as(l)})})},Cb=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 Qt.START_COMPLETE:t.success?r.startCall.resolve():r.startCall.reject(as(t.reason));break;case Qt.PULL_COMPLETE:t.success?r.pullCall.resolve():r.pullCall.reject(as(t.reason));break;case Qt.PULL:if(!o){n.postMessage({sourceName:s,targetName:i,stream:Qt.PULL_COMPLETE,streamId:e,success:!0});break}o.desiredSize<=0&&t.desiredSize>0&&o.sinkCapability.resolve(),o.desiredSize=t.desiredSize,new Promise(function(h){var l;h((l=o.onPull)==null?void 0:l.call(o))}).then(function(){n.postMessage({sourceName:s,targetName:i,stream:Qt.PULL_COMPLETE,streamId:e,success:!0})},function(h){n.postMessage({sourceName:s,targetName:i,stream:Qt.PULL_COMPLETE,streamId:e,reason:as(h)})});break;case Qt.ENQUEUE:if(re(r,"enqueue should have stream controller"),r.isClosed)break;r.controller.enqueue(t.chunk);break;case Qt.CLOSE:if(re(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 Qt.ERROR:re(r,"error should have stream controller"),r.controller.error(as(t.reason)),y(this,As,fd).call(this,r,e);break;case Qt.CANCEL_COMPLETE:t.success?r.cancelCall.resolve():r.cancelCall.reject(as(t.reason)),y(this,As,fd).call(this,r,e);break;case Qt.CANCEL:if(!o)break;new Promise(function(h){var l;h((l=o.onCancel)==null?void 0:l.call(o,as(t.reason)))}).then(function(){n.postMessage({sourceName:s,targetName:i,stream:Qt.CANCEL_COMPLETE,streamId:e,success:!0})},function(h){n.postMessage({sourceName:s,targetName:i,stream:Qt.CANCEL_COMPLETE,streamId:e,reason:as(h)})}),o.sinkCapability.reject(as(t.reason)),o.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 cS{constructor({parsedData:t,rawData:e}){w(this,Jr);w(this,cl);v(this,Jr,t),v(this,cl,e)}getRaw(){return c(this,cl)}get(t){return c(this,Jr).get(t)??null}getAll(){return Hf(c(this,Jr))}has(t){return c(this,Jr).has(t)}}Jr=new WeakMap,cl=new WeakMap;const ta=Symbol("INTERNAL");class uS{constructor(t,{name:e,intent:s,usage:i,rbGroups:n}){w(this,ul,!1);w(this,dl,!1);w(this,fl,!1);w(this,ba,!0);v(this,ul,!!(t&os.DISPLAY)),v(this,dl,!!(t&os.PRINT)),this.name=e,this.intent=s,this.usage=i,this.rbGroups=n}get visible(){if(c(this,fl))return c(this,ba);if(!c(this,ba))return!1;const{print:t,view:e}=this.usage;return c(this,ul)?(e==null?void 0:e.viewState)!=="OFF":c(this,dl)?(t==null?void 0:t.printState)!=="OFF":!0}_setVisible(t,e,s=!1){t!==ta&&Mt("Internal method `_setVisible` called."),v(this,fl,s),v(this,ba,e)}}ul=new WeakMap,dl=new WeakMap,fl=new WeakMap,ba=new WeakMap;class dS{constructor(t,e=os.DISPLAY){w(this,gl);w(this,Yn,null);w(this,xt,new Map);w(this,ya,null);w(this,_a,null);if(this.renderingIntent=e,this.name=null,this.creator=null,t!==null){this.name=t.name,this.creator=t.creator,v(this,_a,t.order);for(const s of t.groups)c(this,xt).set(s.id,new uS(e,s));if(t.baseState==="OFF")for(const s of c(this,xt).values())s._setVisible(ta,!1);for(const s of t.on)c(this,xt).get(s)._setVisible(ta,!0);for(const s of t.off)c(this,xt).get(s)._setVisible(ta,!1);v(this,ya,this.getHash())}}isVisible(t){if(c(this,xt).size===0)return!0;if(!t)return Su("Optional content group not defined."),!0;if(t.type==="OCG")return c(this,xt).has(t.id)?c(this,xt).get(t.id).visible:(ot(`Optional content group not found: ${t.id}`),!0);if(t.type==="OCMD"){if(t.expression)return y(this,gl,Jg).call(this,t.expression);if(!t.policy||t.policy==="AnyOn"){for(const e of t.ids){if(!c(this,xt).has(e))return ot(`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 ot(`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 ot(`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 ot(`Optional content group not found: ${e}`),!0;if(c(this,xt).get(e).visible)return!1}return!0}return ot(`Unknown optional content policy ${t.policy}.`),!0}return ot(`Unknown group type ${t.type}.`),!0}setVisibility(t,e=!0,s=!0){var n;const i=c(this,xt).get(t);if(!i){ot(`Optional content group not found: ${t}`);return}if(s&&e&&i.rbGroups.length)for(const r of i.rbGroups)for(const o of r)o!==t&&((n=c(this,xt).get(o))==null||n._setVisible(ta,!1,!0));i._setVisible(ta,!!e,!0),v(this,Yn,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,Yn,null)}get hasInitialVisibility(){return c(this,ya)===null||this.getHash()===c(this,ya)}getOrder(){return c(this,xt).size?c(this,_a)?c(this,_a).slice():[...c(this,xt).keys()]:null}getGroups(){return c(this,xt).size>0?Hf(c(this,xt)):null}getGroup(t){return c(this,xt).get(t)||null}getHash(){if(c(this,Yn)!==null)return c(this,Yn);const t=new U0;for(const[e,s]of c(this,xt))t.update(`${e}:${s.visible}`);return v(this,Yn,t.hexdigest())}}Yn=new WeakMap,xt=new WeakMap,ya=new WeakMap,_a=new WeakMap,gl=new WeakSet,Jg=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,gl,Jg).call(this,n);else if(c(this,xt).has(n))r=c(this,xt).get(n).visible;else return ot(`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}){re(t,'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');const{length:i,initialData:n,progressiveDone:r,contentDispositionFilename:o}=t;if(this._queuedChunks=[],this._progressiveDone=r,this._contentDispositionFilename=o,(n==null?void 0:n.length)>0){const h=n instanceof Uint8Array&&n.byteLength===n.buffer.byteLength?n.buffer:new Uint8Array(n).buffer;this._queuedChunks.push(h)}this._pdfDataRangeTransport=t,this._isStreamingSupported=!s,this._isRangeSupported=!e,this._contentLength=i,this._fullRequestReader=null,this._rangeReaders=[],t.addRangeListener((h,l)=>{this._onReceiveData({begin:h,chunk:l})}),t.addProgressListener((h,l)=>{this._onProgress({loaded:h,total:l})}),t.addProgressiveReadListener(h=>{this._onReceiveData({chunk:h})}),t.addProgressiveDoneListener(()=>{this._onProgressiveDone()}),t.transportReady()}_onReceiveData({begin:t,chunk:e}){const s=e instanceof Uint8Array&&e.byteLength===e.buffer.byteLength?e.buffer:new Uint8Array(e).buffer;if(t===void 0)this._fullRequestReader?this._fullRequestReader._enqueue(s):this._queuedChunks.push(s);else{const i=this._rangeReaders.some(function(n){return n._begin!==t?!1:(n._enqueue(s),!0)});re(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(){re(!this._fullRequestReader,"PDFDataTransportStream.getFullReader can only be called once.");const t=this._queuedChunks;return this._queuedChunks=null,new gS(this,t,this._progressiveDone,this._contentDispositionFilename)}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new pS(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 gS{constructor(t,e,s=!1,i=null){this._stream=t,this._done=s||!1,this._filename=Gf(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 pS{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 mS(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=l(u),n(u)}if(e=r(a),e){const u=l(e);return n(u)}if(e=s("filename","i").exec(a),e){e=e[1];let u=o(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 f=new TextDecoder(u,{fatal:!0}),g=Au(d);d=f.decode(g),t=!1}catch{}}return d}function n(u){return t&&/[\x80-\xff]/.test(u)&&(u=i("utf-8",u),t&&(u=i("iso-8859-1",u))),u}function r(u){const d=[];let f;const g=s("filename\\*((?!0\\d)\\d+)(\\*?)","ig");for(;(f=g.exec(u))!==null;){let[,m,_,b]=f;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=o(b),_&&(b=unescape(b),m===0&&(b=h(b))),p.push(b)}return p.join("")}function o(u){if(u.startsWith('"')){const d=u.slice(1).split('\\"');for(let f=0;f<d.length;++f){const g=d[f].indexOf('"');g!==-1&&(d[f]=d[f].slice(0,g),d.length=f+1),d[f]=d[f].replaceAll(/\\(.)/g,"$1")}u=d.join('"')}return u}function h(u){const d=u.indexOf("'");if(d===-1)return u;const f=u.slice(0,d),p=u.slice(d+1).replace(/^[^']*'/,"");return i(f,p)}function l(u){return!u.startsWith("=?")||/[\x00-\x19\x80-\xff]/.test(u)?u:u.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,function(d,f,g,p){if(g==="q"||g==="Q")return p=p.replaceAll("_"," "),p=p.replaceAll(/=([0-9a-fA-F]{2})/g,function(m,_){return String.fromCharCode(parseInt(_,16))}),i(f,p);try{p=atob(p)}catch{}return i(f,p)})}return""}function rg(a,t){const e=new Headers;if(!a||!t||typeof t!="object")return e;for(const s in t){const i=t[s];i!==void 0&&e.append(s,i)}return e}function og({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 ag(a){const t=a.get("Content-Disposition");if(t){let e=mS(t);if(e.includes("%"))try{e=decodeURIComponent(e)}catch{}if(Gf(e))return e}return null}function Ru(a,t){return a===404||a===0&&t.startsWith("file:")?new Ar('Missing PDF "'+t+'".'):new Cu(`Unexpected server response (${a}) while retrieving PDF "${t}".`,a)}function uv(a){return a===200||a===206}function dv(a,t,e){return{method:"GET",headers:a,signal:e.signal,mode:"cors",credentials:t?"include":"same-origin",redirect:"follow"}}function fv(a){return a instanceof Uint8Array?a.buffer:a instanceof ArrayBuffer?a:(ot(`getArrayBuffer - unexpected data format: ${a}`),new Uint8Array(a).buffer)}class gv{constructor(t){this.source=t,this.isHttp=/^https?:/i.test(t.url),this.headers=rg(this.isHttp,t.httpHeaders),this._fullRequestReader=null,this._rangeRequestReaders=[]}get _progressiveDataLength(){var t;return((t=this._fullRequestReader)==null?void 0:t._loaded)??0}getFullReader(){return re(!this._fullRequestReader,"PDFFetchStream.getFullReader can only be called once."),this._fullRequestReader=new vS(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new bS(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 vS{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,dv(s,this._withCredentials,this._abortController)).then(n=>{if(!uv(n.status))throw Ru(n.status,i);this._reader=n.body.getReader(),this._headersCapability.resolve();const r=n.headers,{allowRangeRequests:o,suggestedLength:h}=og({responseHeaders:r,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=o,this._contentLength=h||this._contentLength,this._filename=ag(r),!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new Tr("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 bS{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,dv(n,this._withCredentials,this._abortController)).then(o=>{if(!uv(o.status))throw Ru(o.status,r);this._readCapability.resolve(),this._reader=o.body.getReader()}).catch(this._readCapability.reject),this.onProgress=null}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;await this._readCapability.promise;const{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:(this._loaded+=t.byteLength,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded}),{value:fv(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}const hg=200,lg=206;function yS(a){const t=a.response;return typeof t!="string"?t:Au(t).buffer}class _S{constructor({url:t,httpHeaders:e,withCredentials:s}){this.url=t,this.isHttp=/^https?:/i.test(t),this.headers=rg(this.isHttp,e),this.withCredentials=s||!1,this.currXhrId=0,this.pendingRequests=Object.create(null)}requestRange(t,e,s){const i={begin:t,end:e};for(const n in s)i[n]=s[n];return this.request(i)}requestFull(t){return this.request(t)}request(t){const e=new XMLHttpRequest,s=this.currXhrId++,i=this.pendingRequests[s]={xhr:e};e.open("GET",this.url),e.withCredentials=this.withCredentials;for(const[n,r]of this.headers)e.setRequestHeader(n,r);return this.isHttp&&"begin"in t&&"end"in t?(e.setRequestHeader("Range",`bytes=${t.begin}-${t.end-1}`),i.expectedStatus=lg):i.expectedStatus=hg,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||hg;if(!(n===hg&&s.expectedStatus===lg)&&n!==s.expectedStatus){(l=s.onError)==null||l.call(s,i.status);return}const o=yS(i);if(n===lg){const d=i.getResponseHeader("Content-Range"),f=/bytes (\d+)-(\d+)\/(\d+)/.exec(d);s.onDone({begin:parseInt(f[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 wS{constructor(t){this._source=t,this._manager=new _S(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 re(!this._fullRequestReader,"PDFNetworkStream.getFullReader can only be called once."),this._fullRequestReader=new xS(this._manager,this._source),this._fullRequestReader}getRangeReader(t,e){const s=new SS(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 xS{constructor(t,e){this._manager=t;const s={onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)};this._url=e.url,this._fullRequestId=t.requestFull(s),this._headersCapability=Promise.withResolvers(),this._disableRange=e.disableRange||!1,this._contentLength=e.length,this._rangeChunkSize=e.rangeChunkSize,!this._rangeChunkSize&&!this._disableRange&&(this._disableRange=!0),this._isStreamingSupported=!1,this._isRangeSupported=!1,this._cachedChunks=[],this._requests=[],this._done=!1,this._storedError=void 0,this._filename=null,this.onProgress=null}_onHeadersReceived(){const t=this._fullRequestId,e=this._manager.getRequestXhr(t),s=new Headers(e.getAllResponseHeaders().trim().split(/[\r\n]+/).map(r=>{const[o,...h]=r.split(": ");return[o,h.join(": ")]})),{allowRangeRequests:i,suggestedLength:n}=og({responseHeaders:s,isHttp:this._manager.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});i&&(this._isRangeSupported=!0),this._contentLength=n||this._contentLength,this._filename=ag(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=Ru(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 SS{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=Ru(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 CS=/^[a-z][a-z0-9\-+.]+:/i;function AS(a){if(CS.test(a))return new URL(a);const t=Rn.get("url");return new URL(t.pathToFileURL(a))}function pv(a,t,e){return a.protocol==="http:"?Rn.get("http").request(a,{headers:t},e):Rn.get("https").request(a,{headers:t},e)}class TS{constructor(t){this.source=t,this.url=AS(t.url),this.isHttp=this.url.protocol==="http:"||this.url.protocol==="https:",this.isFsUrl=this.url.protocol==="file:",this.headers=rg(this.isHttp,t.httpHeaders),this._fullRequestReader=null,this._rangeRequestReaders=[]}get _progressiveDataLength(){var t;return((t=this._fullRequestReader)==null?void 0:t._loaded)??0}getFullReader(){return re(!this._fullRequestReader,"PDFNodeStream.getFullReader can only be called once."),this._fullRequestReader=this.isFsUrl?new MS(this):new ES(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=this.isFsUrl?new OS(this,t,e):new kS(this,t,e);return this._rangeRequestReaders.push(s),s}cancelAllRequests(t){var e;(e=this._fullRequestReader)==null||e.cancel(t);for(const s of this._rangeRequestReaders.slice(0))s.cancel(t)}}class mv{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 Tr("streaming is disabled")),this._storedError&&this._readableStream.destroy(this._storedError)}}class vv{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 ES extends mv{constructor(t){super(t);const e=Object.fromEntries(t.headers),s=i=>{if(i.statusCode===404){const h=new Ar(`Missing PDF "${this._url}".`);this._storedError=h,this._headersCapability.reject(h);return}this._headersCapability.resolve(),this._setReadableStream(i);const n=new Headers(this._readableStream.headers),{allowRangeRequests:r,suggestedLength:o}=og({responseHeaders:n,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=r,this._contentLength=o||this._contentLength,this._filename=ag(n)};this._request=pv(this._url,e,s),this._request.on("error",i=>{this._storedError=i,this._headersCapability.reject(i)}),this._request.end()}}class kS extends vv{constructor(t,e,s){super(t);const i=Object.fromEntries(t.headers);i.Range=`bytes=${e}-${s-1}`;const n=r=>{if(r.statusCode===404){const o=new Ar(`Missing PDF "${this._url}".`);this._storedError=o;return}this._setReadableStream(r)};this._request=pv(this._url,i,n),this._request.on("error",r=>{this._storedError=r}),this._request.end()}}class MS extends mv{constructor(t){super(t);const e=Rn.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 Ar(`Missing PDF "${this._url}".`)),this._storedError=s,this._headersCapability.reject(s)})}}class OS extends vv{constructor(t,e,s){super(t);const i=Rn.get("fs");this._setReadableStream(i.createReadStream(this._url,{start:e,end:s-1}))}}const PS=1e5,Je=30,DS=.8,ae=class ae{constructor({textContentSource:t,container:e,viewport:s}){w(this,tn);w(this,qn,Promise.withResolvers());w(this,Ze,null);w(this,pl,!1);w(this,ml,!!((Fv=globalThis.FontInspector)!=null&&Fv.enabled));w(this,Qr,null);w(this,Zi,null);w(this,vl,0);w(this,bl,0);w(this,Zr,null);w(this,wa,null);w(this,xa,0);w(this,$n,0);w(this,Sa,Object.create(null));w(this,yl,[]);w(this,Ca,null);w(this,to,[]);w(this,_l,new WeakMap);w(this,wl,null);var h;if(t instanceof ReadableStream)v(this,Ca,t);else if(typeof t=="object")v(this,Ca,new ReadableStream({start(l){l.enqueue(t),l.close()}}));else throw new Error('No "textContentSource" parameter specified.');v(this,Ze,v(this,wa,e)),v(this,$n,s.scale*(globalThis.devicePixelRatio||1)),v(this,xa,s.rotation),v(this,Zi,{div:null,properties:null,ctx:null});const{pageWidth:i,pageHeight:n,pageX:r,pageY:o}=s.rawDims;v(this,wl,[1,0,0,-1,-r,o+n]),v(this,bl,i),v(this,vl,n),y(h=ae,cs,Eb).call(h),Er(e,s),c(this,qn).promise.finally(()=>{c(ae,Aa).delete(this),v(this,Zi,null),v(this,Sa,null)}).catch(()=>{})}static get fontFamilyMap(){const{isWindows:t,isFirefox:e}=Be.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,Zr).read().then(({value:e,done:s})=>{if(s){c(this,qn).resolve();return}c(this,Qr)??v(this,Qr,e.lang),Object.assign(c(this,Sa),e.styles),y(this,tn,Ab).call(this,e.items),t()},c(this,qn).reject)};return v(this,Zr,c(this,Ca).getReader()),c(ae,Aa).add(this),t(),c(this,qn).promise}update({viewport:t,onBefore:e=null}){var n;const s=t.scale*(globalThis.devicePixelRatio||1),i=t.rotation;if(i!==c(this,xa)&&(e==null||e(),v(this,xa,i),Er(c(this,wa),{rotation:i})),s!==c(this,$n)){e==null||e(),v(this,$n,s);const r={div:null,properties:null,ctx:y(n=ae,cs,gd).call(n,c(this,Qr))};for(const o of c(this,to))r.properties=c(this,_l).get(o),r.div=o,y(this,tn,Qg).call(this,r)}}cancel(){var e;const t=new Tr("TextLayer task cancelled.");(e=c(this,Zr))==null||e.cancel(t).catch(()=>{}),v(this,Zr,null),c(this,qn).reject(t)}get textDivs(){return c(this,to)}get textContentItemsStr(){return c(this,yl)}static cleanup(){if(!(c(this,Aa).size>0)){c(this,eo).clear();for(const{canvas:t}of c(this,so).values())t.remove();c(this,so).clear()}}};qn=new WeakMap,Ze=new WeakMap,pl=new WeakMap,ml=new WeakMap,Qr=new WeakMap,Zi=new WeakMap,vl=new WeakMap,bl=new WeakMap,Zr=new WeakMap,wa=new WeakMap,xa=new WeakMap,$n=new WeakMap,Sa=new WeakMap,yl=new WeakMap,Ca=new WeakMap,to=new WeakMap,_l=new WeakMap,wl=new WeakMap,eo=new WeakMap,so=new WeakMap,xl=new WeakMap,Kn=new WeakMap,Aa=new WeakMap,tn=new WeakSet,Ab=function(t){var i,n;if(c(this,pl))return;(n=c(this,Zi)).ctx??(n.ctx=y(i=ae,cs,gd).call(i,c(this,Qr)));const e=c(this,to),s=c(this,yl);for(const r of t){if(e.length>PS){ot("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=c(this,Ze);v(this,Ze,document.createElement("span")),c(this,Ze).classList.add("markedContent"),r.id!==null&&c(this,Ze).setAttribute("id",`${r.id}`),o.append(c(this,Ze))}else r.type==="endMarkedContent"&&v(this,Ze,c(this,Ze).parentNode);continue}s.push(r.str),y(this,tn,Tb).call(this,r)}},Tb=function(t){var m;const e=document.createElement("span"),s={angle:0,canvasWidth:0,hasText:t.str!=="",hasEOL:t.hasEOL,fontSize:0};c(this,to).push(e);const i=Y.transform(c(this,wl),t.transform);let n=Math.atan2(i[1],i[0]);const r=c(this,Sa)[t.fontName];r.vertical&&(n+=Math.PI/2);let o=c(this,ml)&&r.fontSubstitution||r.fontFamily;o=ae.fontFamilyMap.get(o)||o;const h=Math.hypot(i[2],i[3]),l=h*y(m=ae,cs,kb).call(m,o,c(this,Qr));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 f="calc(var(--scale-factor)*",g=e.style;c(this,Ze)===c(this,wa)?(g.left=`${(100*u/c(this,bl)).toFixed(2)}%`,g.top=`${(100*d/c(this,vl)).toFixed(2)}%`):(g.left=`${f}${u.toFixed(2)}px)`,g.top=`${f}${d.toFixed(2)}px)`),g.fontSize=`${f}${(c(ae,Kn)*h).toFixed(2)}px)`,g.fontFamily=o,s.fontSize=h,e.setAttribute("role","presentation"),e.textContent=t.str,e.dir=t.dir,c(this,ml)&&(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,_l).set(e,s),c(this,Zi).div=e,c(this,Zi).properties=s,y(this,tn,Qg).call(this,c(this,Zi)),s.hasText&&c(this,Ze).append(e),s.hasEOL){const _=document.createElement("br");_.setAttribute("role","presentation"),c(this,Ze).append(_)}},Qg=function(t){var o;const{div:e,properties:s,ctx:i}=t,{style:n}=e;let r="";if(c(ae,Kn)>1&&(r=`scale(${1/c(ae,Kn)})`),s.canvasWidth!==0&&s.hasText){const{fontFamily:h}=n,{canvasWidth:l,fontSize:u}=s;y(o=ae,cs,Zg).call(o,i,u*c(this,$n),h);const{width:d}=i.measureText(e.textContent);d>0&&(r=`scaleX(${l*c(this,$n)/d}) ${r}`)}s.angle!==0&&(r=`rotate(${s.angle}deg) ${r}`),r.length>0&&(n.transform=r)},cs=new WeakSet,gd=function(t=null){let e=c(this,so).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,so).set(t,e),c(this,xl).set(e,{size:0,family:""})}return e},Zg=function(t,e,s){const i=c(this,xl).get(t);e===i.size&&s===i.family||(t.font=`${e}px ${s}`,i.size=e,i.family=s)},Eb=function(){if(c(this,Kn)!==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,Kn,t.getBoundingClientRect().height),t.remove()},kb=function(t,e){const s=c(this,eo).get(t);if(s)return s;const i=y(this,cs,gd).call(this,e);i.canvas.width=i.canvas.height=Je,y(this,cs,Zg).call(this,i,Je,t);const n=i.measureText("");let r=n.fontBoundingBoxAscent,o=Math.abs(n.fontBoundingBoxDescent);if(r){const u=r/(r+o);return c(this,eo).set(t,u),i.canvas.width=i.canvas.height=0,u}i.strokeStyle="red",i.clearRect(0,0,Je,Je),i.strokeText("g",0,0);let h=i.getImageData(0,0,Je,Je).data;o=0;for(let u=h.length-1-3;u>=0;u-=4)if(h[u]>0){o=Math.ceil(u/4/Je);break}i.clearRect(0,0,Je,Je),i.strokeText("A",0,Je),h=i.getImageData(0,0,Je,Je).data,r=0;for(let u=0,d=h.length;u<d;u+=4)if(h[u]>0){r=Je-Math.floor(u/4/Je);break}i.canvas.width=i.canvas.height=0;const l=r?r/(r+o):DS;return c(this,eo).set(t,l),l},w(ae,cs),w(ae,eo,new Map),w(ae,so,new Map),w(ae,xl,new WeakMap),w(ae,Kn,null),w(ae,Aa,new Set);let jh=ae;class Nh{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(Nh.shouldBuildText(o))(h=n==null?void 0:n.attributes)!=null&&h.textContent?r=n.attributes.textContent:n.value&&(r=n.value);else return;if(r!==null&&e.push({str:r}),!!n.children)for(const l of n.children)i(l)}return i(t),s}static shouldBuildText(t){return!(t==="textarea"||t==="input"||t==="option"||t==="select")}}const RS=65536,FS=100,LS=5e3,IS=Te?qx:Gx,jS=Te?$x:K0,NS=Te?Yx:Ux,BS=Te?Kx:Z0;function HS(a={}){typeof a=="string"||a instanceof URL?a={url:a}:(a instanceof ArrayBuffer||ArrayBuffer.isView(a))&&(a={data:a});const t=new cg,{docId:e}=t,s=a.url?WS(a.url):null,i=a.data?XS(a.data):null,n=a.httpHeaders||null,r=a.withCredentials===!0,o=a.password??null,h=a.range instanceof yv?a.range:null,l=Number.isInteger(a.rangeChunkSize)&&a.rangeChunkSize>0?a.rangeChunkSize:RS;let u=a.worker instanceof ea?a.worker:null;const d=a.verbosity,f=typeof a.docBaseUrl=="string"&&!Eu(a.docBaseUrl)?a.docBaseUrl:null,g=typeof a.cMapUrl=="string"?a.cMapUrl:null,p=a.cMapPacked!==!1,m=a.CMapReaderFactory||jS,_=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,k=typeof a.isOffscreenCanvasSupported=="boolean"?a.isOffscreenCanvasSupported:!Te,P=typeof a.isChrome=="boolean"?a.isChrome:!Be.platform.isFirefox&&typeof window<"u"&&!!(window!=null&&window.chrome),M=Number.isInteger(a.canvasMaxAreaInBytes)?a.canvasMaxAreaInBytes:-1,O=typeof a.disableFontFace=="boolean"?a.disableFontFace:Te,R=a.fontExtraProperties===!0,I=a.enableXfa===!0,j=a.ownerDocument||globalThis.document,G=a.disableRange===!0,L=a.disableStream===!0,H=a.disableAutoFetch===!0,$=a.pdfBug===!0,J=a.CanvasFactory||IS,U=a.FilterFactory||NS,X=a.enableHWA===!0,Ot=h?h.length:a.length??NaN,zt=typeof a.useSystemFonts=="boolean"?a.useSystemFonts:!Te&&!O,ee=typeof a.useWorkerFetch=="boolean"?a.useWorkerFetch:m===K0&&b===Z0&&g&&_&&Dh(g,document.baseURI)&&Dh(_,document.baseURI);a.canvasFactory&&V0("`canvasFactory`-instance option, please use `CanvasFactory` instead."),a.filterFactory&&V0("`filterFactory`-instance option, please use `FilterFactory` instead.");const Bt=null;xx(d);const At={canvasFactory:new J({ownerDocument:j,enableHWA:X}),filterFactory:new U({docId:e,ownerDocument:j}),cMapReaderFactory:ee?null:new m({baseUrl:g,isCompressed:p}),standardFontDataFactory:ee?null:new b({baseUrl:_})};if(!u){const kt={verbosity:d,port:zi.workerPort};u=kt.port?ea.fromPort(kt):new ea(kt),t._worker=u}const we={docId:e,apiVersion:"4.8.69",data:i,password:o,disableAutoFetch:H,rangeChunkSize:l,length:Ot,docBaseUrl:f,enableXfa:I,evaluatorOptions:{maxImageSize:C,disableFontFace:O,ignoreErrors:x,isEvalSupported:A,isOffscreenCanvasSupported:k,isChrome:P,canvasMaxAreaInBytes:M,fontExtraProperties:R,useSystemFonts:zt,cMapUrl:ee?g:null,standardFontDataUrl:ee?_:null}},Ps={disableFontFace:O,fontExtraProperties:R,ownerDocument:j,pdfBug:$,styleElement:Bt,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",we,i?[i.buffer]:null);let ft;if(h)ft=new fS(h,{disableRange:G,disableStream:L});else if(!i){if(!s)throw new Error("getDocument - no `url` parameter provided.");let Ds;Te?Ds=typeof fetch<"u"&&typeof Response<"u"&&"body"in Response.prototype&&Dh(s)?gv:TS:Ds=Dh(s)?gv:wS,ft=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 ni=new Ih(e,Ds,u.port),Ve=new US(ni,t,ft,Ps,At);t._transport=Ve,ni.send("Ready",null)})}).catch(t._capability.reject),t}function WS(a){if(a instanceof URL)return a.href;try{return new URL(a,window.location).href}catch{if(Te&&typeof a=="string")return a}throw new Error("Invalid PDF url data: either string or URL-object is expected in the url property.")}function XS(a){if(Te&&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 Au(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 bv(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 Ku=class Ku{constructor(){this._capability=Promise.withResolvers(),this._transport=null,this._worker=null,this.docId=`d${Ue(Ku,$u)._++}`,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)}};$u=new WeakMap,w(Ku,$u,0);let cg=Ku;class yv{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 zS{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 VS{constructor(t,e,s,i=!1){w(this,Ts);w(this,Jn,null);w(this,en,!1);this._pageIndex=t,this._pageInfo=e,this._transport=s,this._stats=i?new z0:null,this._pdfBug=i,this.commonObjs=s.commonObjs,this.objs=new _v,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 Ph({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=On.ENABLE,transform:n=null,background:r=null,optionalContentConfigPromise:o=null,annotationCanvasMap:h=null,pageColors:l=null,printAnnotationStorage:u=null,isEditing:d=!1}){var A,k;(A=this._stats)==null||A.time("Overall");const f=this._transport.getRenderingIntent(s,i,u,d),{renderingIntent:g,cacheKey:p}=f;v(this,en,!1),y(this,Ts,pd).call(this),o||(o=this._transport.getOptionalContentConfig(g));let m=this._intentStates.get(p);m||(m=Object.create(null),this._intentStates.set(p,m)),m.streamReaderCancelTimeout&&(clearTimeout(m.streamReaderCancelTimeout),m.streamReaderCancelTimeout=null);const _=!!(g&os.PRINT);m.displayReadyCapability||(m.displayReadyCapability=Promise.withResolvers(),m.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(k=this._stats)==null||k.time("Page Request"),this._pumpOperatorList(f));const b=P=>{var M;m.renderTasks.delete(x),(this._maybeCleanupAfterRender||_)&&v(this,en,!0),y(this,Ts,ah).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 ug({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 C=x.task;return Promise.all([m.displayReadyCapability.promise,o]).then(([P,M])=>{var O;if(this.destroyed){b();return}if((O=this._stats)==null||O.time("Rendering"),!(M.renderingIntent&g))throw new Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");x.initializeGraphics({transparency:P,optionalContentConfig:M}),x.operatorListChanged()}).catch(b),C}getOperatorList({intent:t="display",annotationMode:e=On.ENABLE,printAnnotationStorage:s=null,isEditing:i=!1}={}){var l;function n(){o.operatorList.lastChunk&&(o.opListReadCapability.resolve(o.operatorList),o.renderTasks.delete(h))}const r=this._transport.getRenderingIntent(t,e,s,i,!0);let o=this._intentStates.get(r.cacheKey);o||(o=Object.create(null),this._intentStates.set(r.cacheKey,o));let h;return o.opListReadCapability||(h=Object.create(null),h.operatorListChanged=n,o.opListReadCapability=Promise.withResolvers(),(o.renderTasks||(o.renderTasks=new Set)).add(h),o.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(l=this._stats)==null||l.time("Page Request"),this._pumpOperatorList(r)),o.opListReadCapability.promise}streamTextContent({includeMarkedContent:t=!1,disableNormalization:e=!1}={}){return this._transport.messageHandler.sendWithStream("GetTextContent",{pageIndex:this._pageIndex,includeMarkedContent:t===!0,disableNormalization:e===!0},{highWaterMark:100,size(i){return i.items.length}})}getTextContent(t={}){if(this._transport._htmlForXfa)return this.getXfa().then(s=>Nh.textContent(s));const e=this.streamTextContent(t);return new Promise(function(s,i){function n(){r.read().then(function({value:h,done:l}){if(l){s(o);return}o.lang??(o.lang=h.lang),Object.assign(o.styles,h.styles),o.items.push(...h.items),n()},i)}const r=e.getReader(),o={items:[],styles:Object.create(null),lang:null};n()})}getStructTree(){return this._transport.getStructTree(this._pageIndex)}_destroy(){this.destroyed=!0;const t=[];for(const e of this._intentStates.values())if(this._abortOperatorList({intentState:e,reason:new Error("Page was destroyed."),force:!0}),!e.opListReadCapability)for(const s of e.renderTasks)t.push(s.completed),s.cancel();return this.objs.clear(),v(this,en,!1),y(this,Ts,pd).call(this),Promise.all(t)}cleanup(t=!1){v(this,en,!0);const e=y(this,Ts,ah).call(this,!1);return t&&e&&this._stats&&(this._stats=new z0),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,ah).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:f})=>{if(f){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 f of l.renderTasks)f.operatorListChanged();y(this,Ts,ah).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 Vf){let i=FS;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 Tr(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}}Jn=new WeakMap,en=new WeakMap,Ts=new WeakSet,ah=function(t=!1){if(y(this,Ts,pd).call(this),!c(this,en)||this.destroyed)return!1;if(t)return v(this,Jn,setTimeout(()=>{v(this,Jn,null),y(this,Ts,ah).call(this,!1)},LS)),!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,en,!1),!0},pd=function(){c(this,Jn)&&(clearTimeout(c(this,Jn)),v(this,Jn,null))};class GS{constructor(){w(this,sn,new Map);w(this,Ju,Promise.resolve())}postMessage(t,e){const s={data:structuredClone(t,e?{transfer:e}:null)};c(this,Ju).then(()=>{for(const[i]of c(this,sn))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){ot("LoopbackPort - cannot use an `aborted` signal.");return}const r=()=>this.removeEventListener(t,e);i=()=>n.removeEventListener("abort",r),n.addEventListener("abort",r)}c(this,sn).set(e,i)}removeEventListener(t,e){const s=c(this,sn).get(e);s==null||s(),c(this,sn).delete(e)}terminate(){for(const[,t]of c(this,sn))t==null||t();c(this,sn).clear()}}sn=new WeakMap,Ju=new WeakMap;const Rt=class Rt{constructor({name:t=null,port:e=null,verbosity:s=Sx()}={}){w(this,Ta);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,no))!=null&&i.has(e))throw new Error("Cannot use more than one PDFWorker per port.");(c(Rt,no)||v(Rt,no,new WeakMap)).set(e,this),this._initializeFromPort(e);return}this._initialize()}get promise(){return Te?Promise.all([Rn.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 Ih("main","worker",t),this._messageHandler.on("ready",function(){}),y(this,Ta,md).call(this)}_initialize(){if(c(Rt,io)||c(Rt,Ea,vd)){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 Ih("main","worker",e),i=()=>{n.abort(),s.destroy(),e.terminate(),this.destroyed?this._readyCapability.reject(new Error("Worker was destroyed")):this._setupFakeWorker()},n=new AbortController;e.addEventListener("error",()=>{this._webWorker||i()},{signal:n.signal}),s.on("test",o=>{if(n.abort(),this.destroyed||!o){i();return}this._messageHandler=s,this._port=e,this._webWorker=e,y(this,Ta,md).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{Su("The worker has been disabled.")}this._setupFakeWorker()}_setupFakeWorker(){c(Rt,io)||(ot("Setting up fake worker."),v(Rt,io,!0)),Rt._setupFakeWorkerGlobal.then(t=>{if(this.destroyed){this._readyCapability.reject(new Error("Worker was destroyed"));return}const e=new GS;this._port=e;const s=`fake${Ue(Rt,Qu)._++}`,i=new Ih(s+"_worker",s,e);t.setup(i,e),this._messageHandler=new Ih(s,s+"_worker",e),y(this,Ta,md).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,no))==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,no))==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(zi.workerSrc)return zi.workerSrc;throw new Error('No "GlobalWorkerOptions.workerSrc" specified.')}static get _setupFakeWorkerGlobal(){return ut(this,"_setupFakeWorkerGlobal",(async()=>c(this,Ea,vd)?c(this,Ea,vd):(await import(this.workerSrc)).WorkerMessageHandler)())}};Qu=new WeakMap,io=new WeakMap,no=new WeakMap,Ta=new WeakSet,md=function(){this._readyCapability.resolve(),this._messageHandler.send("configure",{verbosity:this.verbosity})},Ea=new WeakSet,vd=function(){var t;try{return((t=globalThis.pdfjsWorker)==null?void 0:t.WorkerMessageHandler)||null}catch{return null}},w(Rt,Ea),w(Rt,Qu,0),w(Rt,io,!1),w(Rt,no),Te&&(v(Rt,io,!0),zi.workerSrc||(zi.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 ea=Rt;class US{constructor(t,e,s,i,n){w(this,ro);w(this,nn,new Map);w(this,xi,new Map);w(this,ka,new Map);w(this,Ma,new Map);w(this,Si,null);this.messageHandler=t,this.loadingTask=e,this.commonObjs=new _v,this.fontLoader=new zx({ownerDocument:i.ownerDocument,styleElement:i.styleElement}),this.loadingParams=i.loadingParams,this._params=i,this.canvasFactory=n.canvasFactory,this.filterFactory=n.filterFactory,this.cMapReaderFactory=n.cMapReaderFactory,this.standardFontDataFactory=n.standardFontDataFactory,this.destroyed=!1,this.destroyCapability=null,this._networkStream=s,this._fullReader=null,this._lastProgress=null,this.downloadInfoCapability=Promise.withResolvers(),this.setupMessageHandler()}get annotationStorage(){return ut(this,"annotationStorage",new Zf)}getRenderingIntent(t,e=On.ENABLE,s=null,i=!1,n=!1){let r=os.DISPLAY,o=Qf;switch(t){case"any":r=os.ANY;break;case"display":break;case"print":r=os.PRINT;break;default:ot(`getRenderingIntent - invalid intent: ${t}`)}const h=r&os.PRINT&&s instanceof Y0?s:this.annotationStorage;switch(e){case On.DISABLE:r+=os.ANNOTATIONS_DISABLE;break;case On.ENABLE:break;case On.ENABLE_FORMS:r+=os.ANNOTATIONS_FORMS;break;case On.ENABLE_STORAGE:r+=os.ANNOTATIONS_STORAGE,o=h.serializable;break;default:ot(`getRenderingIntent - invalid annotationMode: ${e}`)}i&&(r+=os.IS_EDITING),n&&(r+=os.OPLIST);const{ids:l,hash:u}=h.modifiedIds,d=[r,o.hash,u];return{renderingIntent:r,cacheKey:d.join("_"),annotationStorageSerializable:o,modifiedIds:l}}destroy(){var s;if(this.destroyCapability)return this.destroyCapability.promise;this.destroyed=!0,this.destroyCapability=Promise.withResolvers(),(s=c(this,Si))==null||s.reject(new Error("Worker was destroyed during onPassword callback"));const t=[];for(const i of c(this,xi).values())t.push(i._destroy());c(this,xi).clear(),c(this,ka).clear(),c(this,Ma).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,nn).clear(),this.filterFactory.destroy(),jh.cleanup(),(i=this._networkStream)==null||i.cancelAllRequests(new Tr("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)=>{re(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}re(n instanceof ArrayBuffer,"GetReader - expected an ArrayBuffer."),i.enqueue(new Uint8Array(n),1,[n])}).catch(n=>{i.error(n)})},i.onCancel=n=>{this._fullReader.cancel(n),i.ready.catch(r=>{if(!this.destroyed)throw r})}}),t.on("ReaderHeadersReady",async s=>{var o;await this._fullReader.headersReady;const{isStreamingSupported:i,isRangeSupported:n,contentLength:r}=this._fullReader;return(!i||!n)&&(this._lastProgress&&((o=e.onProgress)==null||o.call(e,this._lastProgress)),this._fullReader.onProgress=h=>{var l;(l=e.onProgress)==null||l.call(e,{loaded:h.loaded,total:h.total})}),{isStreamingSupported:i,isRangeSupported:n,contentLength:r}}),t.on("GetRangeReader",(s,i)=>{re(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}re(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 zS(s,this))}),t.on("DocException",function(s){let i;switch(s.name){case"PasswordException":i=new Nf(s.message,s.code);break;case"InvalidPDFException":i=new H0(s.message);break;case"MissingPDFException":i=new Ar(s.message);break;case"UnexpectedResponseException":i=new Cu(s.message,s.status);break;case"UnknownErrorException":i=new Bf(s.message,s.details);break;default:Mt("DocException - expected a valid Error.")}e._capability.reject(i)}),t.on("PasswordRequest",s=>{if(v(this,Si,Promise.withResolvers()),e.onPassword){const i=n=>{n instanceof Error?c(this,Si).reject(n):c(this,Si).resolve({password:n})};try{e.onPassword(i,s.code)}catch(n){c(this,Si).reject(n)}}else c(this,Si).reject(new Nf(s.message,s.code));return c(this,Si).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,xi).get(s.pageIndex)._startRenderPage(s.transparency,s.cacheKey)}),t.on("commonobj",([s,i,n])=>{var r;if(this.destroyed||this.commonObjs.has(s))return null;switch(i){case"Font":const{disableFontFace:o,fontExtraProperties:h,pdfBug:l}=this._params;if("error"in n){const g=n.error;ot(`Error during font loading: ${g}`),this.commonObjs.resolve(s,g);break}const u=l&&((r=globalThis.FontInspector)!=null&&r.enabled)?(g,p)=>globalThis.FontInspector.fontAdded(g,p):null,d=new Vx(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:f}=n;re(f,"The imageRef must be defined.");for(const g of c(this,xi).values())for(const[,p]of g.objs)if((p==null?void 0:p.ref)===f)return p.dataLen?(this.commonObjs.resolve(s,structuredClone(p)),p.dataLen):null;break;case"FontPath":case"Image":case"Pattern":this.commonObjs.resolve(s,n);break;default:throw new Error(`Got unknown common object type ${i}`)}return null}),t.on("obj",([s,i,n,r])=>{var h;if(this.destroyed)return;const o=c(this,xi).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)>bx&&(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&&ot("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,ka).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,Ma).set(n.refStr,t);const r=new VS(e,n,this,this._params.pdfBug);return c(this,xi).set(e,r),r});return c(this,ka).set(e,i),i}getPageIndex(t){return bv(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,ro,uc).call(this,"GetFieldObjects")}hasJSActions(){return y(this,ro,uc).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,ro,uc).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,ro,uc).call(this,"GetOptionalContentConfig").then(e=>new dS(e,t))}getPermissions(){return this.messageHandler.sendWithPromise("GetPermissions",null)}getMetadata(){const t="GetMetadata",e=c(this,nn).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 cS(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,nn).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,xi).values())if(!e.cleanup())throw new Error(`startCleanup: Page ${e.pageNumber} is currently rendering.`);this.commonObjs.clear(),t||this.fontLoader.clear(),c(this,nn).clear(),this.filterFactory.destroy(!0),jh.cleanup()}}cachedPageNumber(t){if(!bv(t))return null;const e=t.gen===0?`${t.num}R`:`${t.num}R${t.gen}`;return c(this,Ma).get(e)??null}}nn=new WeakMap,xi=new WeakMap,ka=new WeakMap,Ma=new WeakMap,Si=new WeakMap,ro=new WeakSet,uc=function(t,e=null){const s=c(this,nn).get(t);if(s)return s;const i=this.messageHandler.sendWithPromise(t,e);return c(this,nn).set(t,i),i};const Fu=Symbol("INITIAL_DATA");class _v{constructor(){w(this,Sl);w(this,$s,Object.create(null))}get(t,e=null){if(e){const i=y(this,Sl,tp).call(this,t);return i.promise.then(()=>e(i.data)),null}const s=c(this,$s)[t];if(!s||s.data===Fu)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return s.data}has(t){const e=c(this,$s)[t];return!!e&&e.data!==Fu}resolve(t,e=null){const s=y(this,Sl,tp).call(this,t);s.data=e,s.resolve()}clear(){var t;for(const e in c(this,$s)){const{data:s}=c(this,$s)[e];(t=s==null?void 0:s.bitmap)==null||t.close()}v(this,$s,Object.create(null))}*[Symbol.iterator](){for(const t in c(this,$s)){const{data:e}=c(this,$s)[t];e!==Fu&&(yield[t,e])}}}$s=new WeakMap,Sl=new WeakSet,tp=function(t){var e;return(e=c(this,$s))[t]||(e[t]={...Promise.withResolvers(),data:Fu})};class YS{constructor(t){w(this,Qn,null);v(this,Qn,t),this.onContinue=null}get promise(){return c(this,Qn).capability.promise}cancel(t=0){c(this,Qn).cancel(null,t)}get separateAnnots(){const{separateAnnots:t}=c(this,Qn).operatorList;if(!t)return!1;const{annotationCanvasMap:e}=c(this,Qn);return t.form||t.canvas&&(e==null?void 0:e.size)>0}}Qn=new WeakMap;const ao=class ao{constructor({callback:t,params:e,objs:s,commonObjs:i,annotationCanvasMap:n,operatorList:r,pageIndex:o,canvasFactory:h,filterFactory:l,useRequestAnimationFrame:u=!1,pdfBug:d=!1,pageColors:f=null}){w(this,Zn,null);this.callback=t,this.params=e,this.objs=s,this.commonObjs=i,this.annotationCanvasMap=n,this.operatorListIdx=null,this.operatorList=r,this._pageIndex=o,this.canvasFactory=h,this.filterFactory=l,this._pdfBug=d,this.pageColors=f,this.running=!1,this.graphicsReadyCallback=null,this.graphicsReady=!1,this._useRequestAnimationFrame=u===!0&&typeof window<"u",this.cancelled=!1,this.capability=Promise.withResolvers(),this.task=new 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(c(ao,oo).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(ao,oo).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 Zo(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,Zn)&&(window.cancelAnimationFrame(c(this,Zn)),v(this,Zn,null)),c(ao,oo).delete(this._canvas),this.callback(t||new Vf(`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,Zn,window.requestAnimationFrame(()=>{v(this,Zn,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(ao,oo).delete(this._canvas),this.callback())))}};Zn=new WeakMap,oo=new WeakMap,w(ao,oo,new WeakSet);let ug=ao;const qS="4.8.69",$S="3634dab10";function wv(a){return Math.floor(Math.max(0,Math.min(1,a))*255).toString(16).padStart(2,"0")}function Bh(a){return Math.max(0,Math.min(255,255*a))}class xv{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=Bh(t),[t,t,t]}static G_HTML([t]){const e=wv(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(Bh)}static RGB_HTML(t){return`#${t.map(wv).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[Bh(1-Math.min(1,t+i)),Bh(1-Math.min(1,s+i)),Bh(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){Mt("Abstract method `_createSVG` called.")}}class dg extends KS{_createSVG(t){return document.createElementNS(Wi,t)}}class Sv{static setupStorage(t,e,s,i,n){const r=i.getValue(e,{value:null});switch(s.name){case"textarea":if(r.value!==null&&(t.textContent=r.value),n==="print")break;t.addEventListener("input",o=>{i.setValue(e,{value:o.target.value})});break;case"input":if(s.attributes.type==="radio"||s.attributes.type==="checkbox"){if(r.value===s.attributes.xfaOn?t.setAttribute("checked",!0):r.value===s.attributes.xfaOff&&t.removeAttribute("checked"),n==="print")break;t.addEventListener("change",o=>{i.setValue(e,{value:o.target.checked?o.target.getAttribute("xfaOn"):o.target.getAttribute("xfaOff")})})}else{if(r.value!==null&&t.setAttribute("value",r.value),n==="print")break;t.addEventListener("input",o=>{i.setValue(e,{value:o.target.value})})}break;case"select":if(r.value!==null){t.setAttribute("value",r.value);for(const o of s.children)o.attributes.value===r.value?o.attributes.selected=!0:o.attributes.hasOwnProperty("selected")&&delete o.attributes.selected}t.addEventListener("input",o=>{const h=o.target.options,l=h.selectedIndex===-1?"":h[h.selectedIndex].value;i.setValue(e,{value:l})});break}}static setAttributes({html:t,element:e,storage:s=null,intent:i,linkService:n}){const{attributes:r}=e,o=t instanceof HTMLAnchorElement;r.type==="radio"&&(r.name=`${r.name}-${i}`);for(const[h,l]of Object.entries(r))if(l!=null)switch(h){case"class":l.length&&t.setAttribute(h,l.join(" "));break;case"dataId":break;case"id":t.setAttribute("data-element-id",l);break;case"style":Object.assign(t.style,l);break;case"textContent":t.textContent=l;break;default:(!o||h!=="href"&&h!=="newWindow")&&t.setAttribute(h,l)}o&&n.addLinkAttributes(t,r.href,r.newWindow),s&&r.dataId&&this.setupStorage(t,r.dataId,e,s)}static render(t){var d,f;const e=t.annotationStorage,s=t.linkService,i=t.xfaHtml,n=t.intent||"display",r=document.createElement(i.name);i.attributes&&this.setAttributes({html:r,element:i,intent:n,linkService:s});const o=n!=="richText",h=t.div;if(h.append(r),t.viewport){const g=`matrix(${t.viewport.transform.join(",")})`;h.style.transform=g}o&&h.setAttribute("class","xfaLayer xfaFont");const l=[];if(i.children.length===0){if(i.value){const g=document.createTextNode(i.value);r.append(g),o&&Nh.shouldBuildText(i.name)&&l.push(g)}return{textDivs:l}}const u=[[i,-1,r]];for(;u.length>0;){const[g,p,m]=u.at(-1);if(p+1===g.children.length){u.pop();continue}const _=g.children[++u.at(-1)[1]];if(_===null)continue;const{name:b}=_;if(b==="#text"){const C=document.createTextNode(_.value);l.push(C),m.append(C);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}),((f=_.children)==null?void 0:f.length)>0)u.push([_,-1,x]);else if(_.value){const C=document.createTextNode(_.value);o&&Nh.shouldBuildText(b)&&l.push(C),x.append(C)}}for(const g of h.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea"))g.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 Hh=1e3,JS=9,Mr=new WeakSet;function Vi(a){return{width:a[2]-a[0],height:a[3]-a[1]}}class QS{static create(t){switch(t.data.annotationType){case ne.LINK:return new Cv(t);case ne.TEXT:return new ZS(t);case ne.WIDGET:switch(t.data.fieldType){case"Tx":return new tC(t);case"Btn":return t.data.radioButton?new Av(t):t.data.checkBox?new sC(t):new iC(t);case"Ch":return new nC(t);case"Sig":return new eC(t)}return new Or(t);case ne.POPUP:return new fg(t);case ne.FREETEXT:return new Tv(t);case ne.LINE:return new oC(t);case ne.SQUARE:return new aC(t);case ne.CIRCLE:return new hC(t);case ne.POLYLINE:return new Ev(t);case ne.CARET:return new cC(t);case ne.INK:return new gg(t);case ne.POLYGON:return new lC(t);case ne.HIGHLIGHT:return new kv(t);case ne.UNDERLINE:return new uC(t);case ne.SQUIGGLY:return new dC(t);case ne.STRIKEOUT:return new fC(t);case ne.STAMP:return new Mv(t);case ne.FILEATTACHMENT:return new gC(t);default:return new qt(t)}}}const Sg=class Sg{constructor(t,{isRenderable:e=!1,ignoreBorder:s=!1,createQuadrilaterals:i=!1}={}){w(this,Cl);w(this,ho,null);w(this,Oa,!1);w(this,Pa,null);this.isRenderable=e,this.data=t.data,this.layer=t.layer,this.linkService=t.linkService,this.downloadManager=t.downloadManager,this.imageResourcesPath=t.imageResourcesPath,this.renderForms=t.renderForms,this.svgFactory=t.svgFactory,this.annotationStorage=t.annotationStorage,this.enableScripting=t.enableScripting,this.hasJSActions=t.hasJSActions,this._fieldObjects=t.fieldObjects,this.parent=t.parent,e&&(this.container=this._createContainer(s)),i&&this._createQuadrilaterals()}static _hasPopupData({titleObj:t,contentsObj:e,richText:s}){return!!(t!=null&&t.str||e!=null&&e.str||s!=null&&s.str)}get _isEditable(){return this.data.isEditable}get hasPopupData(){return Sg._hasPopupData(this.data)}updateEdited(t){var s;if(!this.container)return;c(this,ho)||v(this,ho,{rect:this.data.rect.slice(0)});const{rect:e}=t;e&&y(this,Cl,ep).call(this,e),(s=c(this,Pa))==null||s.popup.updateEdited(t)}resetEdited(){var t;c(this,ho)&&(y(this,Cl,ep).call(this,c(this,ho).rect),(t=c(this,Pa))==null||t.popup.resetEdited(),v(this,ho,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 Or||(n.tabIndex=Hh);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 fg){const{rotation:m}=e;return!e.hasOwnCanvas&&m!==0&&this.setRotation(m,n),n}const{width:o,height:h}=Vi(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 Av){const x=`calc(${o}px * var(--scale-factor)) / calc(${h}px * var(--scale-factor))`;r.borderRadius=x}switch(e.borderStyle.style){case Oh.SOLID:r.borderStyle="solid";break;case Oh.DASHED:r.borderStyle="dashed";break;case Oh.BEVELED:ot("Unimplemented border style: beveled");break;case Oh.INSET:ot("Unimplemented border style: inset");break;case Oh.UNDERLINE:r.borderBottomStyle="solid";break}const b=e.borderColor||null;b?(v(this,Oa,!0),r.borderColor=Y.makeHexColor(b[0]|0,b[1]|0,b[2]|0)):r.borderWidth=0}const l=Y.normalizeRect([e.rect[0],s.view[3]-e.rect[1]+s.view[1],e.rect[2],s.view[3]-e.rect[3]+s.view[1]]),{pageWidth:u,pageHeight:d,pageX:f,pageY:g}=i.rawDims;r.left=`${100*(l[0]-f)/u}%`,r.top=`${100*(l[1]-g)/d}%`;const{rotation:p}=e;return e.hasOwnCanvas||p===0?(r.width=`${100*o/u}%`,r.height=`${100*h/d}%`):this.setRotation(p,n),n}setRotation(t,e=this.container){if(!this.data.rect)return;const{pageWidth:s,pageHeight:i}=this.parent.viewport.rawDims,{width:n,height:r}=Vi(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]=xv[`${r}_HTML`](o),this.annotationStorage.setValue(this.data.id,{[s]:xv[`${r}_rgb`](o)})};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 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,_,b,x]=t.subarray(2,6);if(i===m&&n===_&&e===b&&s===x)return}const{style:r}=this.container;let o;if(c(this,Oa)){const{borderColor:m,borderWidth:_}=r;r.borderWidth=0,o=["url('data:image/svg+xml;utf8,",'<svg xmlns="http://www.w3.org/2000/svg"',' preserveAspectRatio="none" viewBox="0 0 1 1">',`<g fill="transparent" stroke="${m}" stroke-width="${_}">`],this.container.classList.add("hasBorder")}const h=i-e,l=n-s,{svgFactory:u}=this,d=u.createElement("svg");d.classList.add("quadrilateralsContainer"),d.setAttribute("width",0),d.setAttribute("height",0);const f=u.createElement("defs");d.append(f);const g=u.createElement("clipPath"),p=`clippath_${this.data.id}`;g.setAttribute("id",p),g.setAttribute("clipPathUnits","objectBoundingBox"),f.append(g);for(let m=2,_=t.length;m<_;m+=8){const b=t[m],x=t[m+1],C=t[m+2],A=t[m+3],k=u.createElement("rect"),P=(C-e)/h,M=(n-x)/l,O=(b-C)/h,R=(x-A)/l;k.setAttribute("x",P),k.setAttribute("y",M),k.setAttribute("width",O),k.setAttribute("height",R),g.append(k),o==null||o.push(`<rect vector-effect="non-scaling-stroke" x="${P}" y="${M}" width="${O}" height="${R}"/>`)}c(this,Oa)&&(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,Pa,new fg({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:o}of i){if(n===-1||r===e)continue;const h=typeof o=="string"?o:null,l=document.querySelector(`[data-element-id="${r}"]`);if(l&&!Mr.has(l)){ot(`_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&&Mr.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})})}};ho=new WeakMap,Oa=new WeakMap,Pa=new WeakMap,Cl=new WeakSet,ep=function(t){const{container:{style:e},data:{rect:s,rotation:i},parent:{viewport:{rawDims:{pageWidth:n,pageHeight:r,pageX:o,pageY:h}}}}=this;s==null||s.splice(0,4,...t);const{width:l,height:u}=Vi(t);e.left=`${100*(t[0]-o)/n}%`,e.top=`${100*(r-t[3]+h)/r}%`,i===0?(e.width=`${100*l/n}%`,e.height=`${100*u/r}%`):this.setRotation(i)};let qt=Sg;class Cv extends qt{constructor(e,s=null){super(e,{isRenderable:!0,ignoreBorder:!!(s!=null&&s.ignoreBorder),createQuadrilaterals:!0});w(this,us);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,us,Mb).call(this,i,e.attachment,e.attachmentDest),n=!0):e.setOCGState?(y(this,us,Ob).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,us,Ro).call(this)}_bindNamedAction(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeNamedAction(s),!1),y(this,us,Ro).call(this)}_bindJSAction(e,s){e.href=this.linkService.getAnchorUrl("");const i=new Map([["Action","onclick"],["Mouse Up","onmouseup"],["Mouse Down","onmousedown"]]);for(const n of Object.keys(s.actions)){const r=i.get(n);r&&(e[r]=()=>{var o;return(o=this.linkService.eventBus)==null||o.dispatch("dispatcheventinsandbox",{source:this,detail:{id:s.id,name:n}}),!1})}e.onclick||(e.onclick=()=>!1),y(this,us,Ro).call(this)}_bindResetFormAction(e,s){const i=e.onclick;if(i||(e.href=this.linkService.getAnchorUrl("")),y(this,us,Ro).call(this),!this._fieldObjects){ot('_bindResetFormAction - "resetForm" action not supported, ensure that the `fieldObjects` parameter is provided.'),i||(e.onclick=()=>!1);return}e.onclick=()=>{var d;i==null||i();const{fields:n,refs:r,include:o}=s,h=[];if(n.length!==0||r.length!==0){const f=new Set(r);for(const g of n){const p=this._fieldObjects[g]||[];for(const{id:m}of p)f.add(m)}for(const g of Object.values(this._fieldObjects))for(const p of g)f.has(p.id)===o&&h.push(p)}else for(const f of Object.values(this._fieldObjects))h.push(...f);const l=this.annotationStorage,u=[];for(const f of h){const{id:g}=f;switch(u.push(g),f.type){case"text":{const m=f.defaultValue||"";l.setValue(g,{value:m});break}case"checkbox":case"radiobutton":{const m=f.defaultValue===f.exportValues;l.setValue(g,{value:m});break}case"combobox":case"listbox":{const m=f.defaultValue||"";l.setValue(g,{value:m});break}default:continue}const p=document.querySelector(`[data-element-id="${g}"]`);if(p){if(!Mr.has(p)){ot(`_bindResetFormAction - element not allowed: ${g}`);continue}}else continue;p.dispatchEvent(new Event("resetform"))}return this.enableScripting&&((d=this.linkService.eventBus)==null||d.dispatch("dispatcheventinsandbox",{source:this,detail:{id:"app",ids:u,name:"ResetForm"}})),!1}}}us=new WeakSet,Ro=function(){this.container.setAttribute("data-internal-link","")},Mb=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,us,Ro).call(this)},Ob=function(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeSetOCGState(s),!1),y(this,us,Ro).call(this)};class ZS extends qt{constructor(t){super(t,{isRenderable:!0})}render(){this.container.classList.add("textAnnotation");const t=document.createElement("img");return t.src=this.imageResourcesPath+"annotation-"+this.data.name.toLowerCase()+".svg",t.setAttribute("data-l10n-id","pdfjs-text-annotation-type"),t.setAttribute("data-l10n-args",JSON.stringify({type:this.data.name})),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.append(t),this.container}}class Or extends qt{render(){return this.container}showElementAndHideCanvas(t){var e;this.data.hasOwnCanvas&&(((e=t.previousSibling)==null?void 0:e.nodeName)==="CANVAS"&&(t.previousSibling.hidden=!0),t.hidden=!1)}_getKeyModifier(t){return Be.platform.isMac?t.metaKey:t.ctrlKey}_setEventListener(t,e,s,i,n){s.includes("mouse")?t.addEventListener(s,r=>{var o;(o=this.linkService.eventBus)==null||o.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:i,value:n(r),shift:r.shiftKey,modifier:this._getKeyModifier(r)}})}):t.addEventListener(s,r=>{var o;if(s==="blur"){if(!e.focused||!r.relatedTarget)return;e.focused=!1}else if(s==="focus"){if(e.focused)return;e.focused=!0}n&&((o=this.linkService.eventBus)==null||o.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:i,value:n(r)}}))})}_setEventListeners(t,e,s,i){var n,r,o;for(const[h,l]of s)(l==="Action"||(n=this.data.actions)!=null&&n[l])&&((l==="Focus"||l==="Blur")&&(e||(e={focused:!1})),this._setEventListener(t,e,h,l,i),l==="Focus"&&!((r=this.data.actions)!=null&&r.Blur)?this._setEventListener(t,e,"blur","Blur",null):l==="Blur"&&!((o=this.data.actions)!=null&&o.Focus)&&this._setEventListener(t,e,"focus","Focus",null))}_setBackgroundColor(t){const e=this.data.backgroundColor||null;t.style.backgroundColor=e===null?"transparent":Y.makeHexColor(e[0],e[1],e[2])}_setTextStyle(t){const e=["left","center","right"],{fontColor:s}=this.data.defaultAppearanceData,i=this.data.defaultAppearanceData.fontSize||JS,n=t.style;let r;const o=2,h=l=>Math.round(10*l)/10;if(this.data.multiLine){const l=Math.abs(this.data.rect[3]-this.data.rect[1]-o),u=Math.round(l/(jf*i))||1,d=l/u;r=Math.min(i,h(d/jf))}else{const l=Math.abs(this.data.rect[3]-this.data.rect[1]-o);r=Math.min(i,h(l/jf))}n.fontSize=`calc(${r}px * var(--scale-factor))`,n.color=Y.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 Or{constructor(t){const e=t.renderForms||t.data.hasOwnCanvas||!t.data.hasAppearance&&!!t.data.fieldValue;super(t,{isRenderable:e})}setPropertyOnSiblings(t,e,s,i){const n=this.annotationStorage;for(const r of this._getElementsByName(t.name,t.id))r.domElement&&(r.domElement[e]=s),n.setValue(r.id,{[i]:s})}render(){var i,n;const t=this.annotationStorage,e=this.data.id;this.container.classList.add("textWidgetAnnotation");let s=null;if(this.renderForms){const r=t.getValue(e,{value:this.data.fieldValue});let o=r.value||"";const h=t.getValue(e,{charLimit:this.data.maxLen}).charLimit;h&&o.length>h&&(o=o.slice(0,h));let l=r.formattedValue||((i=this.data.textContent)==null?void 0:i.join(`
|
|
529
|
-
`))||null;l&&this.data.comb&&(l=l.replaceAll(/\s+/g,""));const u={userValue:o,formattedValue:l,lastCommittedValue:null,commitKey:1,focused:!1};this.data.multiLine?(s=document.createElement("textarea"),s.textContent=l??o,this.data.doNotScroll&&(s.style.overflowY="hidden")):(s=document.createElement("input"),s.type="text",s.setAttribute("value",l??o),this.data.doNotScroll&&(s.style.overflowX="hidden")),this.data.hasOwnCanvas&&(s.hidden=!0),Mr.add(s),s.setAttribute("data-element-id",e),s.disabled=this.data.readOnly,s.name=this.data.fieldName,s.tabIndex=Hh,this._setRequired(s,this.data.required),h&&(s.maxLength=h),s.addEventListener("input",f=>{t.setValue(e,{value:f.target.value}),this.setPropertyOnSiblings(s,"value",f.target.value,"value"),u.formattedValue=null}),s.addEventListener("resetform",f=>{const g=this.data.defaultFieldValue??"";s.value=u.userValue=g,u.formattedValue=null});let d=f=>{const{formattedValue:g}=u;g!=null&&(f.target.value=g),f.target.scrollLeft=0};if(this.enableScripting&&this.hasJSActions){s.addEventListener("focus",g=>{var m;if(u.focused)return;const{target:p}=g;u.userValue&&(p.value=u.userValue),u.lastCommittedValue=p.value,u.commitKey=1,(m=this.data.actions)!=null&&m.Focus||(u.focused=!0)}),s.addEventListener("updatefromsandbox",g=>{this.showElementAndHideCanvas(g.target);const p={value(m){u.userValue=m.detail.value??"",t.setValue(e,{value:u.userValue.toString()}),m.target.value=u.userValue},formattedValue(m){const{formattedValue:_}=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 C;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}),(C=this.linkService.eventBus)==null||C.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:x,willCommit:!0,commitKey:1,selStart:b.selectionStart,selEnd:b.selectionEnd}}))}};this._dispatchEventFromSandbox(p,g)}),s.addEventListener("keydown",g=>{var _;u.commitKey=1;let p=-1;if(g.key==="Escape"?p=0:g.key==="Enter"&&!this.data.multiLine?p=2:g.key==="Tab"&&(u.commitKey=3),p===-1)return;const{value:m}=g.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:g.target.selectionStart,selEnd:g.target.selectionEnd}}))});const f=d;d=null,s.addEventListener("blur",g=>{var m,_;if(!u.focused||!g.relatedTarget)return;(m=this.data.actions)!=null&&m.Blur||(u.focused=!1);const{value:p}=g.target;u.userValue=p,u.lastCommittedValue!==p&&((_=this.linkService.eventBus)==null||_.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:p,willCommit:!0,commitKey:u.commitKey,selStart:g.target.selectionStart,selEnd:g.target.selectionEnd}})),f(g)}),(n=this.data.actions)!=null&&n.Keystroke&&s.addEventListener("beforeinput",g=>{var k;u.lastCommittedValue=null;const{data:p,target:m}=g,{value:_,selectionStart:b,selectionEnd:x}=m;let C=b,A=x;switch(g.inputType){case"deleteWordBackward":{const P=_.substring(0,b).match(/\w*[^\w]*$/);P&&(C-=P[0].length);break}case"deleteWordForward":{const P=_.substring(b).match(/^[^\w]*\w*/);P&&(A+=P[0].length);break}case"deleteContentBackward":b===x&&(C-=1);break;case"deleteContentForward":b===x&&(A+=1);break}g.preventDefault(),(k=this.linkService.eventBus)==null||k.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:_,change:p||"",willCommit:!1,selStart:C,selEnd:A}})}),this._setEventListeners(s,u,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],g=>g.target.value)}if(d&&s.addEventListener("blur",d),this.data.comb){const g=(this.data.rect[2]-this.data.rect[0])/h;s.classList.add("comb"),s.style.letterSpacing=`calc(${g}px * var(--scale-factor) - 1ch)`}}else s=document.createElement("div"),s.textContent=this.data.fieldValue,s.style.verticalAlign="middle",s.style.display="table-cell",this.data.hasOwnCanvas&&(s.hidden=!0);return this._setTextStyle(s),this._setBackgroundColor(s),this._setDefaultPropertiesFromJS(s),this.container.append(s),this.container}}class eC extends Or{constructor(t){super(t,{isRenderable:!!t.data.hasOwnCanvas})}}class sC extends Or{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 Mr.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=Hh,n.addEventListener("change",r=>{const{name:o,checked:h}=r.target;for(const l of this._getElementsByName(o,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 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 Av extends Or{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(Mr.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=Hh,n.addEventListener("change",r=>{const{name:o,checked:h}=r.target;for(const l of this._getElementsByName(o,s))t.setValue(l.id,{value:!1});t.setValue(s,{value:h})}),n.addEventListener("resetform",r=>{const o=e.defaultFieldValue;r.target.checked=o!=null&&o===e.buttonValue}),this.enableScripting&&this.hasJSActions){const r=e.buttonValue;n.addEventListener("updatefromsandbox",o=>{const h={value:l=>{const u=r===l.detail.value;for(const d of this._getElementsByName(l.target.name)){const f=u&&d.id===s;d.domElement&&(d.domElement.checked=f),t.setValue(d.id,{value:f})}}};this._dispatchEventFromSandbox(h,o)}),this._setEventListeners(n,null,[["change","Validate"],["change","Action"],["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],o=>o.target.checked)}return this._setBackgroundColor(n),this._setDefaultPropertiesFromJS(n),this.container.append(n),this.container}}class iC extends Cv{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 Or{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");Mr.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=Hh;let n=this.data.combo&&this.data.options.length>0;this.data.combo||(i.size=this.data.options.length,this.data.multiSelect&&(i.multiple=!0)),i.addEventListener("resetform",u=>{const d=this.data.defaultFieldValue;for(const f of i.options)f.selected=f.value===d});for(const u of this.data.options){const d=document.createElement("option");d.textContent=u.displayValue,d.value=u.exportValue,s.value.includes(u.exportValue)&&(d.setAttribute("selected",!0),n=!1),i.append(d)}let r=null;if(n){const u=document.createElement("option");u.value=" ",u.setAttribute("hidden",!0),u.setAttribute("selected",!0),i.prepend(u),r=()=>{u.remove(),i.removeEventListener("input",r),r=null},i.addEventListener("input",r)}const o=u=>{const d=u?"value":"textContent",{options:f,multiple:g}=i;return g?Array.prototype.filter.call(f,p=>p.selected).map(p=>p[d]):f.selectedIndex===-1?null:f[f.selectedIndex][d]};let h=o(!1);const l=u=>{const d=u.target.options;return Array.prototype.map.call(d,f=>({displayValue:f.textContent,exportValue:f.value}))};return this.enableScripting&&this.hasJSActions?(i.addEventListener("updatefromsandbox",u=>{const d={value(f){r==null||r();const g=f.detail.value,p=new Set(Array.isArray(g)?g:[g]);for(const m of i.options)m.selected=p.has(m.value);t.setValue(e,{value:o(!0)}),h=o(!1)},multipleSelection(f){i.multiple=!0},remove(f){const g=i.options,p=f.detail.remove;g[p].selected=!1,i.remove(p),g.length>0&&Array.prototype.findIndex.call(g,_=>_.selected)===-1&&(g[0].selected=!0),t.setValue(e,{value:o(!0),items:l(f)}),h=o(!1)},clear(f){for(;i.length!==0;)i.remove(0);t.setValue(e,{value:null,items:[]}),h=o(!1)},insert(f){const{index:g,displayValue:p,exportValue:m}=f.detail.insert,_=i.children[g],b=document.createElement("option");b.textContent=p,b.value=m,_?_.before(b):i.append(b),t.setValue(e,{value:o(!0),items:l(f)}),h=o(!1)},items(f){const{items:g}=f.detail;for(;i.length!==0;)i.remove(0);for(const p of g){const{displayValue:m,exportValue:_}=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:o(!0),items:l(f)}),h=o(!1)},indices(f){const g=new Set(f.detail.indices);for(const p of f.target.options)p.selected=g.has(p.index);t.setValue(e,{value:o(!0)}),h=o(!1)},editable(f){f.target.disabled=!f.detail.editable}};this._dispatchEventFromSandbox(d,u)}),i.addEventListener("input",u=>{var g;const d=o(!0),f=o(!1);t.setValue(e,{value:d}),u.preventDefault(),(g=this.linkService.eventBus)==null||g.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:h,change:f,changeEx:d,willCommit:!1,commitKey:1,keyDown:!1}})}),this._setEventListeners(i,null,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"],["input","Action"],["input","Validate"]],u=>u.target.value)):i.addEventListener("input",function(u){t.setValue(e,{value:o(!0)})}),this.data.combo&&this._setTextStyle(i),this._setBackgroundColor(i),this._setDefaultPropertiesFromJS(i),this.container.append(i),this.container}}class fg extends qt{constructor(t){const{data:e,elements:s}=t;super(t,{isRenderable:qt._hasPopupData(e)}),this.elements=s,this.popup=null}render(){this.container.classList.add("popupAnnotation");const t=this.popup=new 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=>`${zf}${s}`).join(",")),this.container}}class rC{constructor({container:t,color:e,elements:s,titleObj:i,modificationDate:n,contentsObj:r,richText:o,parent:h,rect:l,parentRect:u,open:d}){w(this,St);w(this,Da,y(this,St,Rb).bind(this));w(this,Zu,y(this,St,ip).bind(this));w(this,td,y(this,St,_d).bind(this));w(this,Ra,y(this,St,yd).bind(this));w(this,lo,null);w(this,Xt,null);w(this,rn,null);w(this,Fa,null);w(this,Al,null);w(this,Tl,null);w(this,La,null);w(this,on,!1);w(this,Ks,null);w(this,an,null);w(this,El,null);w(this,hn,null);w(this,kl,null);w(this,co,null);w(this,uo,!1);var f;v(this,Xt,t),v(this,kl,i),v(this,rn,r),v(this,hn,o),v(this,Tl,h),v(this,lo,e),v(this,El,l),v(this,La,u),v(this,Al,s),v(this,Fa,Uf.toDateObject(n)),this.trigger=s.flatMap(g=>g.getElementsToTriggerPopup());for(const g of this.trigger)g.addEventListener("click",c(this,Ra)),g.addEventListener("mouseenter",c(this,td)),g.addEventListener("mouseleave",c(this,Zu)),g.classList.add("popupTriggerArea");for(const g of s)(f=g.container)==null||f.addEventListener("keydown",c(this,Da));c(this,Xt).hidden=!0,d&&y(this,St,yd).call(this)}render(){if(c(this,Ks))return;const t=v(this,Ks,document.createElement("div"));if(t.className="popup",c(this,lo)){const n=t.style.outlineColor=Y.makeHexColor(...c(this,lo));CSS.supports("background-color","color-mix(in srgb, red 30%, white)")?t.style.backgroundColor=`color-mix(in srgb, ${n} 30%, white)`:t.style.backgroundColor=Y.makeHexColor(...c(this,lo).map(o=>Math.floor(.7*(255-o)+o)))}const e=document.createElement("span");e.className="header";const s=document.createElement("h1");if(e.append(s),{dir:s.dir,str:s.textContent}=c(this,kl),t.append(e),c(this,Fa)){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,Fa).valueOf()})),e.append(n)}const i=c(this,St,bd);if(i)Sv.render({xfaHtml:i,intent:"richText",div:t}),t.lastChild.classList.add("richText","popupContent");else{const n=this._formatContents(c(this,rn));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 o=i[n];s.append(document.createTextNode(o)),n<r-1&&s.append(document.createElement("br"))}return s}updateEdited({rect:t,popupContent:e}){var s;c(this,co)||v(this,co,{contentsObj:c(this,rn),richText:c(this,hn)}),t&&v(this,an,null),e&&(v(this,hn,y(this,St,Db).call(this,e)),v(this,rn,null)),(s=c(this,Ks))==null||s.remove(),v(this,Ks,null)}resetEdited(){var t;c(this,co)&&({contentsObj:Ue(this,rn)._,richText:Ue(this,hn)._}=c(this,co),v(this,co,null),(t=c(this,Ks))==null||t.remove(),v(this,Ks,null),v(this,an,null))}forceHide(){v(this,uo,this.isVisible),c(this,uo)&&(c(this,Xt).hidden=!0)}maybeShow(){c(this,uo)&&(c(this,Ks)||y(this,St,_d).call(this),v(this,uo,!1),c(this,Xt).hidden=!1)}get isVisible(){return c(this,Xt).hidden===!1}}Da=new WeakMap,Zu=new WeakMap,td=new WeakMap,Ra=new WeakMap,lo=new WeakMap,Xt=new WeakMap,rn=new WeakMap,Fa=new WeakMap,Al=new WeakMap,Tl=new WeakMap,La=new WeakMap,on=new WeakMap,Ks=new WeakMap,an=new WeakMap,El=new WeakMap,hn=new WeakMap,kl=new WeakMap,co=new WeakMap,uo=new WeakMap,St=new WeakSet,bd=function(){const t=c(this,hn),e=c(this,rn);return t!=null&&t.str&&(!(e!=null&&e.str)||e.str===t.str)&&c(this,hn).html||null},sp=function(){var t,e,s;return((s=(e=(t=c(this,St,bd))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.fontSize)||0},Pb=function(){var t,e,s;return((s=(e=(t=c(this,St,bd))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.color)||null},Db=function(t){const e=[],s={str:t,html:{name:"div",attributes:{dir:"auto"},children:[{name:"p",children:e}]}},i={style:{color:c(this,St,Pb),fontSize:c(this,St,sp)?`calc(${c(this,St,sp)}px * var(--scale-factor))`:""}};for(const n of t.split(`
|
|
530
|
-
`))e.push({name:"span",value:n,attributes:i});return s},Rb=function(t){t.altKey||t.shiftKey||t.ctrlKey||t.metaKey||(t.key==="Enter"||t.key==="Escape"&&c(this,on))&&y(this,St,yd).call(this)},Fb=function(){if(c(this,an)!==null)return;const{page:{view:t},viewport:{rawDims:{pageWidth:e,pageHeight:s,pageX:i,pageY:n}}}=c(this,Tl);let r=!!c(this,La),o=r?c(this,La):c(this,El);for(const p of c(this,Al))if(!o||Y.intersect(p.data.rect,o)!==null){o=p.data.rect,r=!0;break}const h=Y.normalizeRect([o[0],t[3]-o[1]+t[1],o[2],t[3]-o[3]+t[1]]),u=r?o[2]-o[0]+5:0,d=h[0]+u,f=h[1];v(this,an,[100*(d-i)/e,100*(f-n)/s]);const{style:g}=c(this,Xt);g.left=`${c(this,an)[0]}%`,g.top=`${c(this,an)[1]}%`},yd=function(){v(this,on,!c(this,on)),c(this,on)?(y(this,St,_d).call(this),c(this,Xt).addEventListener("click",c(this,Ra)),c(this,Xt).addEventListener("keydown",c(this,Da))):(y(this,St,ip).call(this),c(this,Xt).removeEventListener("click",c(this,Ra)),c(this,Xt).removeEventListener("keydown",c(this,Da)))},_d=function(){c(this,Ks)||this.render(),this.isVisible?c(this,on)&&c(this,Xt).classList.add("focused"):(y(this,St,Fb).call(this),c(this,Xt).hidden=!1,c(this,Xt).style.zIndex=parseInt(c(this,Xt).style.zIndex)+1e3)},ip=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 Tv extends qt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.textContent=t.data.textContent,this.textPosition=t.data.textPosition,this.annotationEditorType=nt.FREETEXT}render(){if(this.container.classList.add("freeTextAnnotation"),this.textContent){const t=document.createElement("div");t.classList.add("annotationTextContent"),t.setAttribute("role","comment");for(const e of this.textContent){const s=document.createElement("span");s.textContent=e,t.append(s)}this.container.append(t)}return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this._editOnDoubleClick(),this.container}}class oC extends qt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});w(this,Ml,null)}render(){this.container.classList.add("lineAnnotation");const e=this.data,{width:s,height:i}=Vi(e.rect),n=this.svgFactory.create(s,i,!0),r=v(this,Ml,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,Ml)}addHighlightArea(){this.container.classList.add("highlightArea")}}Ml=new WeakMap;class aC extends qt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});w(this,Ol,null)}render(){this.container.classList.add("squareAnnotation");const e=this.data,{width:s,height:i}=Vi(e.rect),n=this.svgFactory.create(s,i,!0),r=e.borderStyle.width,o=v(this,Ol,this.svgFactory.createElement("svg:rect"));return o.setAttribute("x",r/2),o.setAttribute("y",r/2),o.setAttribute("width",s-r),o.setAttribute("height",i-r),o.setAttribute("stroke-width",r||1),o.setAttribute("stroke","transparent"),o.setAttribute("fill","transparent"),n.append(o),this.container.append(n),!e.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return c(this,Ol)}addHighlightArea(){this.container.classList.add("highlightArea")}}Ol=new WeakMap;class hC extends qt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});w(this,Pl,null)}render(){this.container.classList.add("circleAnnotation");const e=this.data,{width:s,height:i}=Vi(e.rect),n=this.svgFactory.create(s,i,!0),r=e.borderStyle.width,o=v(this,Pl,this.svgFactory.createElement("svg:ellipse"));return o.setAttribute("cx",s/2),o.setAttribute("cy",i/2),o.setAttribute("rx",s/2-r/2),o.setAttribute("ry",i/2-r/2),o.setAttribute("stroke-width",r||1),o.setAttribute("stroke","transparent"),o.setAttribute("fill","transparent"),n.append(o),this.container.append(n),!e.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return c(this,Pl)}addHighlightArea(){this.container.classList.add("highlightArea")}}Pl=new WeakMap;class Ev extends qt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});w(this,Dl,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}=Vi(e),h=this.svgFactory.create(r,o,!0);let l=[];for(let d=0,f=s.length;d<f;d+=2){const g=s[d]-e[0],p=e[3]-s[d+1];l.push(`${g},${p}`)}l=l.join(" ");const u=v(this,Dl,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,Dl)}addHighlightArea(){this.container.classList.add("highlightArea")}}Dl=new WeakMap;class lC extends Ev{constructor(t){super(t),this.containerClassName="polygonAnnotation",this.svgElementName="svg:polygon"}}class cC extends qt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){return this.container.classList.add("caretAnnotation"),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container}}class gg extends qt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});w(this,Rl,[]);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}=Vi(e),h=this.svgFactory.create(r,o,!0);for(const l of s){let u=[];for(let f=0,g=l.length;f<g;f+=2){const p=l[f]-e[0],m=e[3]-l[f+1];u.push(`${p},${m}`)}u=u.join(" ");const d=this.svgFactory.createElement(this.svgElementName);c(this,Rl).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,Rl)}addHighlightArea(){this.container.classList.add("highlightArea")}}Rl=new WeakMap;class kv extends qt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0}),this.annotationEditorType=nt.HIGHLIGHT}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("highlightAnnotation"),this._editOnDoubleClick(),this.container}}class uC extends qt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("underlineAnnotation"),this.container}}class dC extends qt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("squigglyAnnotation"),this.container}}class fC extends qt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("strikeoutAnnotation"),this.container}}class Mv extends qt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.annotationEditorType=nt.STAMP}render(){return this.container.classList.add("stampAnnotation"),this.container.setAttribute("role","img"),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this._editOnDoubleClick(),this.container}}class gC extends qt{constructor(e){var i;super(e,{isRenderable:!0});w(this,Ll);w(this,Fl,null);const{file:s}=this.data;this.filename=s.filename,this.content=s.content,(i=this.linkService.eventBus)==null||i.dispatch("fileattachmentannotation",{source:this,...s})}render(){this.container.classList.add("fileAttachmentAnnotation");const{container:e,data:s}=this;let i;s.hasAppearance||s.fillAlpha===0?i=document.createElement("div"):(i=document.createElement("img"),i.src=`${this.imageResourcesPath}annotation-${/paperclip/i.test(s.name)?"paperclip":"pushpin"}.svg`,s.fillAlpha&&s.fillAlpha<1&&(i.style=`filter: opacity(${Math.round(s.fillAlpha*100)}%);`)),i.addEventListener("dblclick",y(this,Ll,np).bind(this)),v(this,Fl,i);const{isMac:n}=Be.platform;return e.addEventListener("keydown",r=>{r.key==="Enter"&&(n?r.metaKey:r.ctrlKey)&&y(this,Ll,np).call(this)}),!s.popupRef&&this.hasPopupData?this._createPopup():i.classList.add("popupTriggerArea"),e.append(i),e}getElementsToTriggerPopup(){return c(this,Fl)}addHighlightArea(){this.container.classList.add("highlightArea")}}Fl=new WeakMap,Ll=new WeakSet,np=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,po);w(this,Il,null);w(this,fo,null);w(this,go,new Map);w(this,jl,null);this.div=t,v(this,Il,e),v(this,fo,s),v(this,jl,o||null),this.page=n,this.viewport=r,this.zIndex=0,this._annotationEditorUIManager=i}hasEditableAnnotations(){return c(this,go).size>0}async render(t){var r;const{annotations:e}=t,s=this.div;Er(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 dg,annotationStorage:t.annotationStorage||new Zf,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===ne.POPUP;if(h){const d=i.get(o.id);if(!d)continue;n.elements=d}else{const{width:d,height:f}=Vi(o.rect);if(d<=0||f<=0)continue}n.data=o;const l=QS.create(n);if(!l.isRenderable)continue;if(!h&&o.popupRef){const d=i.get(o.popupRef);d?d.push(l):i.set(o.popupRef,[l])}const u=l.render();o.hidden&&(u.style.visibility="hidden"),await y(this,po,Lb).call(this,u,o.id),l._isEditable&&(c(this,go).set(l.data.id,l),(r=this._annotationEditorUIManager)==null||r.renderAnnotationElement(l))}y(this,po,rp).call(this)}update({viewport:t}){const e=this.div;this.viewport=t,Er(e,{rotation:t.rotation}),y(this,po,rp).call(this),e.hidden=!1}getEditableAnnotations(){return Array.from(c(this,go).values())}getEditableAnnotation(t){return c(this,go).get(t)}}Il=new WeakMap,fo=new WeakMap,go=new WeakMap,jl=new WeakMap,po=new WeakSet,Lb=async function(t,e){var r,o;const s=t.firstChild||t,i=s.id=`${zf}${e}`,n=await((r=c(this,jl))==null?void 0:r.getAriaAttributes(i));if(n)for(const[h,l]of n)s.setAttribute(h,l);this.div.append(t),(o=c(this,Il))==null||o.moveElementInDOM(this.div,t,s,!1)},rp=function(){if(!c(this,fo))return;const t=this.div;for(const[e,s]of c(this,fo)){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,fo).clear()};const Lu=/\r\n?|\n/g,Et=class Et extends _t{constructor(e){super({...e,name:"freeTextEditor"});w(this,Zt);w(this,Js);w(this,ds,"");w(this,Nl,`${this.id}-editor`);w(this,mo,null);w(this,fs);v(this,Js,e.color||Et._defaultColor||_t._defaultLineColor),v(this,fs,e.fontSize||Et._defaultFontSize)}static get _keyboardManager(){const e=Et.prototype,s=r=>r.isEmpty(),i=kr.TRANSLATE_SMALL,n=kr.TRANSLATE_BIG;return ut(this,"_keyboardManager",new Rh([[["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,Zt,Ib).call(this,s);break;case Z.FREETEXT_COLOR:y(this,Zt,jb).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,fs)],[Z.FREETEXT_COLOR,c(this,Js)]]}_translateEmpty(e,s){this._uiManager.translateSelectedEditors(e,s,!0)}getInitialTranslation(){const e=this.parentScale;return[-Et._internalPadding*e,-(Et._internalPadding+c(this,fs))*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,mo,new AbortController);const e=this._uiManager.combinedSignal(c(this,mo));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,Nl)),this._isDraggable=!0,(e=c(this,mo))==null||e.abort(),v(this,mo,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,ds),s=v(this,ds,y(this,Zt,Nb).call(this).trimEnd());if(e===s)return;const i=n=>{if(v(this,ds,n),!n){this.remove();return}y(this,Zt,Sd).call(this),this._uiManager.rebuild(this),y(this,Zt,wd).call(this)};this.addCommands({cmd:()=>{i(s)},undo:()=>{i(e)},mustExec:!1}),y(this,Zt,wd).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,Nl)),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,fs)}px * var(--scale-factor))`,i.color=c(this,Js),this.div.append(this.editorDiv),this.overlayDiv=document.createElement("div"),this.overlayDiv.classList.add("overlay","enabled"),this.div.append(this.overlayDiv),ku(this,this.div,["dblclick","keydown"]),this.width){const[n,r]=this.parentDimensions;if(this.annotationElementId){const{position:o}=this._initialData;let[h,l]=this.getInitialTranslation();[h,l]=this.pageTranslationToScreen(h,l);const[u,d]=this.pageDimensions,[f,g]=this.pageTranslation;let p,m;switch(this.rotation){case 0:p=e+(o[0]-f)/u,m=s+this.height-(o[1]-g)/d;break;case 90:p=e+(o[0]-f)/u,m=s-(o[1]-g)/d,[h,l]=[l,-h];break;case 180:p=e-this.width+(o[0]-f)/u,m=s-(o[1]-g)/d,[h,l]=[-h,-l];break;case 270:p=e+(o[0]-f-this.height*d)/u,m=s+(o[1]-g-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,Zt,Sd).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,ln,op).call(p,s.getData("text")||"").replaceAll(Lu,`
|
|
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,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 a=r.getRangeAt(0);if(!n.includes(`
|
|
532
|
+
`)){a.insertNode(document.createTextNode(n)),this.editorDiv.normalize(),r.collapseToStart();return}const{startContainer:h,startOffset:l}=a,u=[],d=[];if(h.nodeType===Node.TEXT_NODE){const b=h.parentElement;if(d.push(h.nodeValue.slice(l).replaceAll(Iu,"")),b!==this.editorDiv){let x=u;for(const S of this.editorDiv.childNodes){if(S===b){x=d;continue}x.push(y(m=Et,cn,Sd).call(m,S))}}u.push(h.nodeValue.slice(0,l).replaceAll(Iu,""))}else if(h===this.editorDiv){let b=u,x=0;for(const S of this.editorDiv.childNodes)x++===l&&(b=d),b.push(y(_=Et,cn,Sd).call(_,S))}v(this,us,`${u.join(`
|
|
533
533
|
`)}${n}${d.join(`
|
|
534
|
-
`)}`),y(this,
|
|
535
|
-
`),position:m,pageIndex:_-1,rect:u.slice(0),rotation:d,id:
|
|
536
|
-
`)){const
|
|
537
|
-
`)},
|
|
538
|
-
`)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},Bb=function(){return c(this,ds).replaceAll(" "," ")},op=function(e){return e.replaceAll(" "," ")},Hb=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(Et,ln),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 pg=Et;class Ov{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 cn=class cn{constructor({x:t,y:e},s,i,n,r,o=0){w(this,he);w(this,gs);w(this,Qs,[]);w(this,Ia);w(this,ja);w(this,Ci,[]);w(this,at,new Float64Array(18));w(this,vo);w(this,bo);w(this,Bl);w(this,Hl);w(this,Na);w(this,Ba);w(this,tr,[]);v(this,gs,s),v(this,Ba,n*i),v(this,ja,r),c(this,at).set([NaN,NaN,NaN,NaN,t,e],6),v(this,Ia,o),v(this,Hl,c(cn,Wl)*i),v(this,Bl,c(cn,sd)*i),v(this,Na,i),c(this,tr).push(t,e)}isEmpty(){return isNaN(c(this,at)[8])}add({x:t,y:e}){var R;v(this,vo,t),v(this,bo,e);const[s,i,n,r]=c(this,gs);let[o,h,l,u]=c(this,at).subarray(8,12);const d=t-l,f=e-u,g=Math.hypot(d,f);if(g<c(this,Bl))return!1;const p=g-c(this,Hl),m=p/g,_=m*d,b=m*f;let x=o,C=h;o=l,h=u,l+=_,u+=b,(R=c(this,tr))==null||R.push(t,e);const A=-b/p,k=_/p,P=A*c(this,Ba),M=k*c(this,Ba);return c(this,at).set(c(this,at).subarray(2,8),0),c(this,at).set([l+P,u+M],4),c(this,at).set(c(this,at).subarray(14,18),12),c(this,at).set([l-P,u-M],16),isNaN(c(this,at)[6])?(c(this,Ci).length===0&&(c(this,at).set([o+P,h+M],2),c(this,Ci).push(NaN,NaN,NaN,NaN,(o+P-s)/n,(h+M-i)/r),c(this,at).set([o-P,h-M],14),c(this,Qs).push(NaN,NaN,NaN,NaN,(o-P-s)/n,(h-M-i)/r)),c(this,at).set([x,C,o,h,l,u],6),!this.isEmpty()):(c(this,at).set([x,C,o,h,l,u],6),Math.abs(Math.atan2(C-h,x-o)-Math.atan2(b,_))<Math.PI/2?([o,h,l,u]=c(this,at).subarray(2,6),c(this,Ci).push(NaN,NaN,NaN,NaN,((o+l)/2-s)/n,((h+u)/2-i)/r),[o,h,x,C]=c(this,at).subarray(14,18),c(this,Qs).push(NaN,NaN,NaN,NaN,((x+o)/2-s)/n,((C+h)/2-i)/r),!0):([x,C,o,h,l,u]=c(this,at).subarray(0,6),c(this,Ci).push(((x+5*o)/6-s)/n,((C+5*h)/6-i)/r,((5*o+l)/6-s)/n,((5*h+u)/6-i)/r,((o+l)/2-s)/n,((h+u)/2-i)/r),[l,u,o,h,x,C]=c(this,at).subarray(12,18),c(this,Qs).push(((x+5*o)/6-s)/n,((C+5*h)/6-i)/r,((5*o+l)/6-s)/n,((5*h+u)/6-i)/r,((o+l)/2-s)/n,((h+u)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=c(this,Ci),e=c(this,Qs);if(isNaN(c(this,at)[6])&&!this.isEmpty())return y(this,he,Wb).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,he,zb).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,he,Xb).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new Pv(t,e,s,i,n,r)}getOutlines(){var d;const t=c(this,Ci),e=c(this,Qs),s=c(this,at),[i,n,r,o]=c(this,gs),h=new Float64Array((((d=c(this,tr))==null?void 0:d.length)??0)+2);for(let f=0,g=h.length-2;f<g;f+=2)h[f]=(c(this,tr)[f]-i)/r,h[f+1]=(c(this,tr)[f+1]-n)/o;if(h[h.length-2]=(c(this,vo)-i)/r,h[h.length-1]=(c(this,bo)-n)/o,isNaN(s[6])&&!this.isEmpty())return y(this,he,Vb).call(this,h);const l=new Float64Array(c(this,Ci).length+24+c(this,Qs).length);let u=t.length;for(let f=0;f<u;f+=2){if(isNaN(t[f])){l[f]=l[f+1]=NaN;continue}l[f]=t[f],l[f+1]=t[f+1]}u=y(this,he,Ub).call(this,l,u);for(let f=e.length-6;f>=6;f-=6)for(let g=0;g<6;g+=2){if(isNaN(e[f+g])){l[u]=l[u+1]=NaN,u+=2;continue}l[u]=e[f+g],l[u+1]=e[f+g+1],u+=2}return y(this,he,Gb).call(this,l,u),this.newFreeDrawOutline(l,h,c(this,gs),c(this,Na),c(this,Ia),c(this,ja))}};gs=new WeakMap,Qs=new WeakMap,Ia=new WeakMap,ja=new WeakMap,Ci=new WeakMap,at=new WeakMap,vo=new WeakMap,bo=new WeakMap,Bl=new WeakMap,Hl=new WeakMap,Na=new WeakMap,Ba=new WeakMap,tr=new WeakMap,Wl=new WeakMap,ed=new WeakMap,sd=new WeakMap,he=new WeakSet,dc=function(){const t=c(this,at).subarray(4,6),e=c(this,at).subarray(16,18),[s,i,n,r]=c(this,gs);return[(c(this,vo)+(t[0]-e[0])/2-s)/n,(c(this,bo)+(t[1]-e[1])/2-i)/r,(c(this,vo)+(e[0]-t[0])/2-s)/n,(c(this,bo)+(e[1]-t[1])/2-i)/r]},Wb=function(){const[t,e,s,i]=c(this,gs),[n,r,o,h]=y(this,he,dc).call(this);return`M${(c(this,at)[2]-t)/s} ${(c(this,at)[3]-e)/i} L${(c(this,at)[4]-t)/s} ${(c(this,at)[5]-e)/i} L${n} ${r} L${o} ${h} L${(c(this,at)[16]-t)/s} ${(c(this,at)[17]-e)/i} L${(c(this,at)[14]-t)/s} ${(c(this,at)[15]-e)/i} Z`},Xb=function(t){const e=c(this,Qs);t.push(`L${e[4]} ${e[5]} Z`)},zb=function(t){const[e,s,i,n]=c(this,gs),r=c(this,at).subarray(4,6),o=c(this,at).subarray(16,18),[h,l,u,d]=y(this,he,dc).call(this);t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${h} ${l} L${u} ${d} L${(o[0]-e)/i} ${(o[1]-s)/n}`)},Vb=function(t){const e=c(this,at),[s,i,n,r]=c(this,gs),[o,h,l,u]=y(this,he,dc).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,o,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,Na),c(this,Ia),c(this,ja))},Gb=function(t,e){const s=c(this,Qs);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},Ub=function(t,e){const s=c(this,at).subarray(4,6),i=c(this,at).subarray(16,18),[n,r,o,h]=c(this,gs),[l,u,d,f]=y(this,he,dc).call(this);return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/o,(s[1]-r)/h,NaN,NaN,NaN,NaN,l,u,NaN,NaN,NaN,NaN,d,f,NaN,NaN,NaN,NaN,(i[0]-n)/o,(i[1]-r)/h],e),e+=24},w(cn,Wl,8),w(cn,ed,2),w(cn,sd,c(cn,Wl)+c(cn,ed));let Iu=cn;class Pv extends Ov{constructor(e,s,i,n,r,o){super();w(this,ts);w(this,Ha);w(this,yo,null);w(this,un);w(this,Xl);w(this,ps);w(this,zl);w(this,$t);v(this,$t,e),v(this,ps,s),v(this,Ha,i),v(this,zl,n),v(this,un,r),v(this,Xl,o),y(this,ts,Yb).call(this,o);const{x:h,y:l,width:u,height:d}=c(this,yo);for(let f=0,g=e.length;f<g;f+=2)e[f]=(e[f]-h)/u,e[f+1]=(e[f+1]-l)/d;for(let f=0,g=s.length;f<g;f+=2)s[f]=(s[f]-h)/u,s[f+1]=(s[f+1]-l)/d}toSVGPath(){const e=[`M${c(this,$t)[4]} ${c(this,$t)[5]}`];for(let s=6,i=c(this,$t).length;s<i;s+=6){if(isNaN(c(this,$t)[s])){e.push(`L${c(this,$t)[s+4]} ${c(this,$t)[s+5]}`);continue}e.push(`C${c(this,$t)[s]} ${c(this,$t)[s+1]} ${c(this,$t)[s+2]} ${c(this,$t)[s+3]} ${c(this,$t)[s+4]} ${c(this,$t)[s+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,s,i,n],r){const o=i-e,h=n-s;let l,u;switch(r){case 0:l=y(this,ts,fc).call(this,c(this,$t),e,n,o,-h),u=y(this,ts,fc).call(this,c(this,ps),e,n,o,-h);break;case 90:l=y(this,ts,gc).call(this,c(this,$t),e,s,o,h),u=y(this,ts,gc).call(this,c(this,ps),e,s,o,h);break;case 180:l=y(this,ts,fc).call(this,c(this,$t),i,s,-o,h),u=y(this,ts,fc).call(this,c(this,ps),i,s,-o,h);break;case 270:l=y(this,ts,gc).call(this,c(this,$t),i,n,-o,-h),u=y(this,ts,gc).call(this,c(this,ps),i,n,-o,-h);break}return{outline:Array.from(l),points:[Array.from(u)]}}get box(){return c(this,yo)}newOutliner(e,s,i,n,r,o=0){return new Iu(e,s,i,n,r,o)}getNewOutline(e,s){const{x:i,y:n,width:r,height:o}=c(this,yo),[h,l,u,d]=c(this,Ha),f=r*u,g=o*d,p=i*u+h,m=n*d+l,_=this.newOutliner({x:c(this,ps)[0]*f+p,y:c(this,ps)[1]*g+m},c(this,Ha),c(this,zl),e,c(this,Xl),s??c(this,un));for(let b=2;b<c(this,ps).length;b+=2)_.add({x:c(this,ps)[b]*f+p,y:c(this,ps)[b+1]*g+m});return _.getOutlines()}get mustRemoveSelfIntersections(){return!0}}Ha=new WeakMap,yo=new WeakMap,un=new WeakMap,Xl=new WeakMap,ps=new WeakMap,zl=new WeakMap,$t=new WeakMap,ts=new WeakSet,fc=function(e,s,i,n,r){const o=new Float64Array(e.length);for(let h=0,l=e.length;h<l;h+=2)o[h]=s+e[h]*n,o[h+1]=i+e[h+1]*r;return o},gc=function(e,s,i,n,r){const o=new Float64Array(e.length);for(let h=0,l=e.length;h<l;h+=2)o[h]=s+e[h+1]*n,o[h+1]=i+e[h]*r;return o},Yb=function(e){const s=c(this,$t);let i=s[4],n=s[5],r=i,o=n,h=i,l=n,u=i,d=n;const f=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]),o=Math.min(o,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=f(u,s[b+4]));else{const C=Y.bezierBoundingBox(i,n,...s.slice(b,b+6));r=Math.min(r,C[0]),o=Math.min(o,C[1]),h=Math.max(h,C[2]),l=Math.max(l,C[3]),d<C[3]?(u=C[2],d=C[3]):d===C[3]&&(u=f(u,C[2]))}i=s[b+4],n=s[b+5]}const g=r-c(this,un),p=o-c(this,un),m=h-r+2*c(this,un),_=l-o+2*c(this,un);v(this,yo,{x:g,y:p,width:m,height:_,lastPoint:[u,d]})};class Dv{constructor(t,e=0,s=0,i=!0){w(this,ze);w(this,Vl);w(this,er,[]);w(this,Zs,[]);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 k=Math.floor((b-e)/u)*u,P=Math.ceil((b+C+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,er).push(R,I),n=Math.min(n,k),r=Math.max(r,P),o=Math.min(o,M),h=Math.max(h,O)}const d=r-n+2*s,f=h-o+2*s,g=n-s,p=o-s,m=c(this,er).at(i?-1:-2),_=[m[0],m[2]];for(const b of c(this,er)){const[x,C,A]=b;b[0]=(x-g)/d,b[1]=(C-p)/f,b[2]=(A-p)/f}v(this,Vl,{x:g,y:p,width:d,height:f,lastPoint:_})}getOutlines(){c(this,er).sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of c(this,er))e[3]?(t.push(...y(this,ze,ap).call(this,e)),y(this,ze,$b).call(this,e)):(y(this,ze,Kb).call(this,e),t.push(...y(this,ze,ap).call(this,e)));return y(this,ze,qb).call(this,t)}}Vl=new WeakMap,er=new WeakMap,Zs=new WeakMap,ze=new WeakSet,qb=function(t){const e=[],s=new Set;for(const r of t){const[o,h,l]=r;e.push([o,h,r],[o,l,r])}e.sort((r,o)=>r[1]-o[1]||r[0]-o[0]);for(let r=0,o=e.length;r<o;r+=2){const h=e[r][2],l=e[r+1][2];h.push(l),l.push(h),s.add(h),s.add(l)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[o,h,l,u,d]=r;s.delete(r);let f=o,g=h;for(n=[o,l],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,l,u,d]=p,f!==o&&(n.push(f,g,o,g===h?h:l),f=o),g=g===h?l:h}n.push(f,g)}return new mC(i,c(this,Vl))},Cd=function(t){const e=c(this,Zs);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},$b=function([,t,e]){const s=y(this,ze,Cd).call(this,t);c(this,Zs).splice(s,0,[t,e])},Kb=function([,t,e]){const s=y(this,ze,Cd).call(this,t);for(let i=s;i<c(this,Zs).length;i++){const[n,r]=c(this,Zs)[i];if(n!==t)break;if(n===t&&r===e){c(this,Zs).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=c(this,Zs)[i];if(n!==t)break;if(n===t&&r===e){c(this,Zs).splice(i,1);return}}},ap=function(t){const[e,s,i]=t,n=[[e,s,i]],r=y(this,ze,Cd).call(this,i);for(let o=0;o<r;o++){const[h,l]=c(this,Zs)[o];for(let u=0,d=n.length;u<d;u++){const[,f,g]=n[u];if(!(l<=f||g<=h)){if(f>=h){if(g>l)n[u][1]=l;else{if(d===1)return[];n.splice(u,1),u--,d--}continue}n[u][2]=h,g>l&&n.push([e,l,g])}}}return n};class mC extends Ov{constructor(e,s){super();w(this,Gl);w(this,Wa);v(this,Wa,e),v(this,Gl,s)}toSVGPath(){const e=[];for(const s of c(this,Wa)){let[i,n]=s;e.push(`M${i} ${n}`);for(let r=2;r<s.length;r+=2){const o=s[r],h=s[r+1];o===i?(e.push(`V${h}`),n=h):h===n&&(e.push(`H${o}`),i=o)}e.push("Z")}return e.join(" ")}serialize([e,s,i,n],r){const o=[],h=i-e,l=n-s;for(const u of c(this,Wa)){const d=new Array(u.length);for(let f=0;f<u.length;f+=2)d[f]=e+u[f]*h,d[f+1]=n-u[f+1]*l;o.push(d)}return o}get box(){return c(this,Gl)}get classNamesForDrawing(){return["highlight"]}get classNamesForOutlining(){return["highlightOutline"]}}Gl=new WeakMap,Wa=new WeakMap;class mg extends Iu{newFreeDrawOutline(t,e,s,i,n,r){return new vC(t,e,s,i,n,r)}get classNamesForDrawing(){return["highlight","free"]}}class vC extends Pv{get classNamesForDrawing(){return["highlight","free"]}get classNamesForOutlining(){return["highlightOutline","free"]}newOutliner(t,e,s,i,n,r=0){return new mg(t,e,s,i,n,r)}}const es=class es{constructor({editor:t=null,uiManager:e=null}){w(this,Ct);w(this,ti,null);w(this,_o,null);w(this,Xa);w(this,le,null);w(this,Ul,!1);w(this,za,!1);w(this,Yl,null);w(this,ql);w(this,sr,null);w(this,ei,null);w(this,Va);var s;t?(v(this,za,!1),v(this,Va,Z.HIGHLIGHT_COLOR),v(this,Yl,t)):(v(this,za,!0),v(this,Va,Z.HIGHLIGHT_DEFAULT_COLOR)),v(this,ei,(t==null?void 0:t._uiManager)||e),v(this,ql,c(this,ei)._eventBus),v(this,Xa,(t==null?void 0:t.color)||((s=c(this,ei))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),c(es,$l)||v(es,$l,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 Rh([[["Escape","mac+Escape"],es.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],es.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],es.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],es.prototype._moveToPrevious],[["Home","mac+Home"],es.prototype._moveToBeginning],[["End","mac+End"],es.prototype._moveToEnd]]))}renderButton(){const t=v(this,ti,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,ei)._signal;t.addEventListener("click",y(this,Ct,Fo).bind(this),{signal:e}),t.addEventListener("keydown",y(this,Ct,cp).bind(this),{signal:e});const s=v(this,_o,document.createElement("span"));return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=c(this,Xa),t.append(s),t}renderMainDropdown(){const t=v(this,le,y(this,Ct,hp).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===c(this,ti)){y(this,Ct,Fo).call(this,t);return}const e=t.target.getAttribute("data-color");e&&y(this,Ct,lp).call(this,e,t)}_moveToNext(t){var e,s;if(!c(this,Ct,cr)){y(this,Ct,Fo).call(this,t);return}if(t.target===c(this,ti)){(e=c(this,le).firstChild)==null||e.focus();return}(s=t.target.nextSibling)==null||s.focus()}_moveToPrevious(t){var e,s;if(t.target===((e=c(this,le))==null?void 0:e.firstChild)||t.target===c(this,ti)){c(this,Ct,cr)&&this._hideDropdownFromKeyboard();return}c(this,Ct,cr)||y(this,Ct,Fo).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!c(this,Ct,cr)){y(this,Ct,Fo).call(this,t);return}(e=c(this,le).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!c(this,Ct,cr)){y(this,Ct,Fo).call(this,t);return}(e=c(this,le).lastChild)==null||e.focus()}hideDropdown(){var t,e;(t=c(this,le))==null||t.classList.add("hidden"),(e=c(this,sr))==null||e.abort(),v(this,sr,null)}_hideDropdownFromKeyboard(){var t;if(!c(this,za)){if(!c(this,Ct,cr)){(t=c(this,Yl))==null||t.unselect();return}this.hideDropdown(),c(this,ti).focus({preventScroll:!0,focusVisible:c(this,Ul)})}}updateColor(t){if(c(this,_o)&&(c(this,_o).style.backgroundColor=t),!c(this,le))return;const e=c(this,ei).highlightColors.values();for(const s of c(this,le).children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){var t,e;(t=c(this,ti))==null||t.remove(),v(this,ti,null),v(this,_o,null),(e=c(this,le))==null||e.remove(),v(this,le,null)}};ti=new WeakMap,_o=new WeakMap,Xa=new WeakMap,le=new WeakMap,Ul=new WeakMap,za=new WeakMap,Yl=new WeakMap,ql=new WeakMap,sr=new WeakMap,ei=new WeakMap,Va=new WeakMap,$l=new WeakMap,Ct=new WeakSet,hp=function(){const t=document.createElement("div"),e=c(this,ei)._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,ei).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(es,$l)[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===c(this,Xa)),n.addEventListener("click",y(this,Ct,lp).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",y(this,Ct,cp).bind(this),{signal:e}),t},lp=function(t,e){e.stopPropagation(),c(this,ql).dispatch("switchannotationeditorparams",{source:this,type:c(this,Va),value:t})},cp=function(t){es._keyboardManager.exec(this,t)},Fo=function(t){if(c(this,Ct,cr)){this.hideDropdown();return}if(v(this,Ul,t.detail===0),c(this,sr)||(v(this,sr,new AbortController),window.addEventListener("pointerdown",y(this,Ct,Jb).bind(this),{signal:c(this,ei).combinedSignal(c(this,sr))})),c(this,le)){c(this,le).classList.remove("hidden");return}const e=v(this,le,y(this,Ct,hp).call(this));c(this,ti).append(e)},Jb=function(t){var e;(e=c(this,le))!=null&&e.contains(t.target)||this.hideDropdown()},cr=function(){return c(this,le)&&!c(this,le).classList.contains("hidden")},w(es,$l,null);let ju=es;const pt=class pt extends _t{constructor(e){super({...e,name:"highlightEditor"});w(this,it);w(this,Ga,null);w(this,Kl,0);w(this,dn);w(this,wo,null);w(this,Ua,null);w(this,Es,null);w(this,Jl,null);w(this,Ql,0);w(this,xo,null);w(this,si,null);w(this,Oe,null);w(this,ss,!1);w(this,Ya,null);w(this,fn);w(this,ce,null);w(this,qa,"");w(this,ks);w(this,Zl,"");this.color=e.color||pt._defaultColor,v(this,ks,e.thickness||pt._defaultThickness),v(this,fn,e.opacity||pt._defaultOpacity),v(this,dn,e.boxes||null),v(this,Zl,e.methodOfCreation||""),v(this,qa,e.text||""),this._isDraggable=!1,e.highlightId>-1?(v(this,ss,!0),y(this,it,Ad).call(this,e),y(this,it,Lo).call(this)):c(this,dn)&&(v(this,Ga,e.anchorNode),v(this,Kl,e.anchorOffset),v(this,Jl,e.focusNode),v(this,Ql,e.focusOffset),y(this,it,up).call(this),y(this,it,Lo).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=pt.prototype;return ut(this,"_keyboardManager",new Rh([[["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,ss)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:c(this,ks),methodOfCreation:c(this,Zl)}}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,Ya)}updateParams(e,s){switch(e){case Z.HIGHLIGHT_COLOR:y(this,it,Qb).call(this,s);break;case Z.HIGHLIGHT_THICKNESS:y(this,it,Zb).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,ss)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(v(this,Ua,new ju({editor:this})),e.addColorPicker(c(this,Ua))),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,pc).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,y(this,it,pc).call(this))}onceAdded(){this.annotationElementId||this.parent.addUndoableEditor(this),this.div.focus()}remove(){y(this,it,dp).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(y(this,it,Lo).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?y(this,it,dp).call(this):e&&(y(this,it,Lo).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),this.show(this._isVisible),s&&this.select()}rotate(e){var n,r,o;const{drawLayer:s}=this.parent;let i;c(this,ss)?(e=(e-this.rotation+360)%360,i=y(n=pt,Ms,hh).call(n,c(this,si).box,e)):i=y(r=pt,Ms,hh).call(r,this,e),s.rotate(c(this,Oe),e),s.rotate(c(this,ce),e),s.updateBox(c(this,Oe),i),s.updateBox(c(this,ce),y(o=pt,Ms,hh).call(o,c(this,Es).box,e))}render(){if(this.div)return this.div;const e=super.render();c(this,qa)&&(e.setAttribute("aria-label",c(this,qa)),e.setAttribute("role","mark")),c(this,ss)?e.classList.add("free"):this.div.addEventListener("keydown",y(this,it,ey).bind(this),{signal:this._uiManager._signal});const s=v(this,xo,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=c(this,wo);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),ku(this,c(this,xo),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){this.isSelected||this.parent.drawLayer.addClass(c(this,ce),"hovered")}pointerleave(){this.isSelected||this.parent.drawLayer.removeClass(c(this,ce),"hovered")}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:y(this,it,Td).call(this,!0);break;case 1:case 3:y(this,it,Td).call(this,!1);break}}select(){var e,s;super.select(),c(this,ce)&&((e=this.parent)==null||e.drawLayer.removeClass(c(this,ce),"hovered"),(s=this.parent)==null||s.drawLayer.addClass(c(this,ce),"selected"))}unselect(){var e;super.unselect(),c(this,ce)&&((e=this.parent)==null||e.drawLayer.removeClass(c(this,ce),"selected"),c(this,ss)||y(this,it,Td).call(this,!1))}get _mustFixPosition(){return!c(this,ss)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.show(c(this,Oe),e),this.parent.drawLayer.show(c(this,ce),e))}static startHighlighting(e,s,{target:i,x:n,y:r}){const{x:o,y:h,width:l,height:u}=i.getBoundingClientRect(),d=new AbortController,f=e.combinedSignal(d),g=m=>{m.preventDefault(),m.stopPropagation()},p=m=>{d.abort(),y(this,Ms,ry).call(this,e,m)};window.addEventListener("blur",p,{signal:f}),window.addEventListener("pointerup",p,{signal:f}),window.addEventListener("pointerdown",g,{capture:!0,passive:!1,signal:f}),window.addEventListener("contextmenu",ws,{signal:f}),i.addEventListener("pointermove",y(this,Ms,ny).bind(this,e),{signal:f}),this._freeHighlight=new mg({x:n,y:r},[o,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 kv){const{data:{quadPoints:C,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:C,boxes:null,pageIndex:I-1,rect:A.slice(0),rotation:k,id:P,deleted:!1,popupRef:R}}else if(e instanceof gg){const{data:{inkLists:C,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:C,boxes:null,pageIndex:I-1,rect:A.slice(0),rotation:k,id:P,deleted:!1,popupRef:R}}const{color:r,quadPoints:o,inkLists:h,opacity:l}=e,u=await super.deserialize(e,s,i);u.color=Y.makeHexColor(...r),v(u,fn,l||1),h&&v(u,ks,e.thickness),u.annotationElementId=e.id||null,u._initialData=n;const[d,f]=u.pageDimensions,[g,p]=u.pageTranslation;if(o){const C=v(u,dn,[]);for(let A=0;A<o.length;A+=8)C.push({x:(o[A]-g)/d,y:1-(o[A+1]-p)/f,width:(o[A+2]-o[A])/d,height:(o[A+1]-o[A+5])/f});y(m=u,it,up).call(m),y(_=u,it,Lo).call(_),u.rotate(u.rotation)}else if(h){v(u,ss,!0);const C=h[0],A={x:C[0]-g,y:f-(C[1]-p)},k=new mg(A,[0,0,d,f],1,c(u,ks)/2,!0,.001);for(let O=0,R=C.length;O<R;O+=2)A.x=C[O]-g,A.y=f-(C[O+1]-p),k.add(A);const{id:P,clipPathId:M}=s.drawLayer.draw(k,u.color,u._defaultOpacity,!0);y(b=u,it,Ad).call(b,{highlightOutlines:k.getOutlines(),highlightId:P,clipPathId:M}),y(x=u,it,Lo).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,sy).call(this),outlines:y(this,it,iy).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:y(this,it,pc).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}};Ga=new WeakMap,Kl=new WeakMap,dn=new WeakMap,wo=new WeakMap,Ua=new WeakMap,Es=new WeakMap,Jl=new WeakMap,Ql=new WeakMap,xo=new WeakMap,si=new WeakMap,Oe=new WeakMap,ss=new WeakMap,Ya=new WeakMap,fn=new WeakMap,ce=new WeakMap,qa=new WeakMap,ks=new WeakMap,Zl=new WeakMap,it=new WeakSet,up=function(){const e=new Dv(c(this,dn),.001);v(this,si,e.getOutlines()),{x:this.x,y:this.y,width:this.width,height:this.height}=c(this,si).box;const s=new Dv(c(this,dn),.0025,.001,this._uiManager.direction==="ltr");v(this,Es,s.getOutlines());const{lastPoint:i}=c(this,Es).box;v(this,Ya,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height])},Ad=function({highlightOutlines:e,highlightId:s,clipPathId:i}){var d,f;if(v(this,si,e),v(this,Es,e.getNewOutline(c(this,ks)/2+1.5,.0025)),s>=0)v(this,Oe,s),v(this,wo,i),this.parent.drawLayer.finalizeLine(s,e),v(this,ce,this.parent.drawLayer.drawOutline(c(this,Es)));else if(this.parent){const g=this.parent.viewport.rotation;this.parent.drawLayer.updateLine(c(this,Oe),e),this.parent.drawLayer.updateBox(c(this,Oe),y(d=pt,Ms,hh).call(d,c(this,si).box,(g-this.rotation+360)%360)),this.parent.drawLayer.updateLine(c(this,ce),c(this,Es)),this.parent.drawLayer.updateBox(c(this,ce),y(f=pt,Ms,hh).call(f,c(this,Es).box,g))}const{x:r,y:o,width:h,height:l}=e.box;switch(this.rotation){case 0:this.x=r,this.y=o,this.width=h,this.height=l;break;case 90:{const[g,p]=this.parentDimensions;this.x=o,this.y=1-r,this.width=h*p/g,this.height=l*g/p;break}case 180:this.x=1-r,this.y=1-o,this.width=h,this.height=l;break;case 270:{const[g,p]=this.parentDimensions;this.x=1-o,this.y=r,this.width=h*p/g,this.height=l*g/p;break}}const{lastPoint:u}=c(this,Es).box;v(this,Ya,[(u[0]-r)/h,(u[1]-o)/l])},Qb=function(e){const s=(r,o)=>{var h,l,u;this.color=r,(h=this.parent)==null||h.drawLayer.changeColor(c(this,Oe),r),(l=c(this,Ua))==null||l.updateColor(r),v(this,fn,o),(u=this.parent)==null||u.drawLayer.changeOpacity(c(this,Oe),o)},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)},Zb=function(e){const s=c(this,ks),i=n=>{v(this,ks,n),y(this,it,ty).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)},ty=function(e){if(!c(this,ss))return;y(this,it,Ad).call(this,{highlightOutlines:c(this,si).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},dp=function(){c(this,Oe)===null||!this.parent||(this.parent.drawLayer.remove(c(this,Oe)),v(this,Oe,null),this.parent.drawLayer.remove(c(this,ce)),v(this,ce,null))},Lo=function(e=this.parent){c(this,Oe)===null&&({id:Ue(this,Oe)._,clipPathId:Ue(this,wo)._}=e.drawLayer.draw(c(this,si),this.color,c(this,fn)),v(this,ce,e.drawLayer.drawOutline(c(this,Es))),c(this,xo)&&(c(this,xo).style.clipPath=c(this,wo)))},Ms=new WeakSet,hh=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}},ey=function(e){pt._keyboardManager.exec(this,e)},Td=function(e){if(!c(this,Ga))return;const s=window.getSelection();e?s.setPosition(c(this,Ga),c(this,Kl)):s.setPosition(c(this,Jl),c(this,Ql))},pc=function(){return c(this,ss)?this.rotation:0},sy=function(){if(c(this,ss))return null;const[e,s]=this.pageDimensions,[i,n]=this.pageTranslation,r=c(this,dn),o=new Float32Array(r.length*8);let h=0;for(const{x:l,y:u,width:d,height:f}of r){const g=l*e+i,p=(1-u-f)*s+n;o[h]=o[h+4]=g,o[h+1]=o[h+3]=p,o[h+2]=o[h+6]=g+d*e,o[h+5]=o[h+7]=p+f*s,h+=8}return o},iy=function(e){return c(this,si).serialize(e,y(this,it,pc).call(this))},ny=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updatePath(this._freeHighlightId,this._freeHighlight)},ry=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 Nu=pt;const jt=class jt extends _t{constructor(e){super({...e,name:"inkEditor"});w(this,N);w(this,So,0);w(this,Co,0);w(this,Ai,null);w(this,gn,new Path2D);w(this,Os,!1);w(this,Ao,null);w(this,To,!1);w(this,Eo,!1);w(this,pn,null);w(this,$a,null);w(this,ko,0);w(this,Mo,0);w(this,ir,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:jt._defaultThickness=s;break;case Z.INK_COLOR:jt._defaultColor=s;break;case Z.INK_OPACITY:jt._defaultOpacity=s/100;break}}updateParams(e,s){switch(e){case Z.INK_THICKNESS:y(this,N,ay).call(this,s);break;case Z.INK_COLOR:y(this,N,hy).call(this,s);break;case Z.INK_OPACITY:y(this,N,ly).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[Z.INK_THICKNESS,jt._defaultThickness],[Z.INK_COLOR,jt._defaultColor||_t._defaultLineColor],[Z.INK_OPACITY,Math.round(jt._defaultOpacity*100)]]}get propertiesToUpdate(){return[[Z.INK_THICKNESS,this.thickness||jt._defaultThickness],[Z.INK_COLOR,this.color||jt._defaultColor||_t._defaultLineColor],[Z.INK_OPACITY,Math.round(100*(this.opacity??jt._defaultOpacity))]]}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.canvas||(y(this,N,Ed).call(this),y(this,N,kd).call(this)),this.isAttachedToDOM||(this.parent.add(this),y(this,N,lh).call(this)),y(this,N,mc).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,Ai)&&(clearTimeout(c(this,Ai)),v(this,Ai,null)),(e=c(this,pn))==null||e.disconnect(),v(this,pn,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,pp).call(this))}disableEditMode(){!this.isInEditMode()||this.canvas===null||(super.disableEditMode(),this._isDraggable=!this.isEmpty(),this.div.classList.remove("editing"),y(this,N,mp).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,mc).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,uy).call(this,e.offsetX,e.offsetY))}canvasPointermove(e){e.preventDefault(),y(this,N,gp).call(this,e.offsetX,e.offsetY)}canvasPointerup(e){e.preventDefault(),y(this,N,vp).call(this,e)}canvasPointerleave(e){y(this,N,vp).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,o]=y(this,N,cy).call(this);if(this.setAt(i,n,0,0),this.setDims(r,o),y(this,N,Ed).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,Eo,!0),y(this,N,lh).call(this),this.setDims(this.width*h,this.height*l),y(this,N,Io).call(this),this.div.classList.add("disabled")}else this.div.classList.add("editing"),this.enableEditMode();return y(this,N,kd).call(this),this.div}setDimensions(e,s){const i=Math.round(e),n=Math.round(s);if(c(this,ko)===i&&c(this,Mo)===n)return;v(this,ko,i),v(this,Mo,n),this.canvas.style.visibility="hidden";const[r,o]=this.parentDimensions;this.width=e/r,this.height=s/o,this.fixAndSetPosition(),c(this,Os)&&y(this,N,bp).call(this,e,s),y(this,N,lh).call(this),y(this,N,Io).call(this),this.canvas.style.visibility="visible",this.fixDims()}static async deserialize(e,s,i){var _,b,x;if(e instanceof gg)return null;const n=await super.deserialize(e,s,i);n.thickness=e.thickness,n.color=Y.makeHexColor(...e.color),n.opacity=e.opacity;const[r,o]=n.pageDimensions,h=n.width*r,l=n.height*o,u=n.parentScale,d=e.thickness/2;v(n,Os,!0),v(n,ko,Math.round(h)),v(n,Mo,Math.round(l));const{paths:f,rect:g,rotation:p}=e;for(let{bezier:C}of f){C=y(_=jt,mn,by).call(_,C,g,p);const A=[];n.paths.push(A);let k=u*(C[0]-d),P=u*(C[1]-d);for(let O=2,R=C.length;O<R;O+=6){const I=u*(C[O]-d),j=u*(C[O+1]-d),G=u*(C[O+2]-d),L=u*(C[O+3]-d),H=u*(C[O+4]-d),$=u*(C[O+5]-d);A.push([[k,P],[I,j],[G,L],[H,$]]),k=H,P=$}const M=y(this,mn,vy).call(this,A);n.bezierPath2D.push(M)}const m=y(b=n,N,_p).call(b);return v(n,Co,Math.max(_t.MIN_SIZE,m[2]-m[0])),v(n,So,Math.max(_t.MIN_SIZE,m[3]-m[1])),y(x=n,N,bp).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,yy).call(this,this.scaleFactor/this.parentScale,this.translationX,this.translationY,e),pageIndex:this.pageIndex,rect:e,rotation:this.rotation,structTreeParentId:this._structTreeParentId}}};So=new WeakMap,Co=new WeakMap,Ai=new WeakMap,gn=new WeakMap,Os=new WeakMap,Ao=new WeakMap,To=new WeakMap,Eo=new WeakMap,pn=new WeakMap,$a=new WeakMap,ko=new WeakMap,Mo=new WeakMap,ir=new WeakMap,N=new WeakSet,ay=function(e){const s=n=>{this.thickness=n,y(this,N,mc).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})},hy=function(e){const s=n=>{this.color=n,y(this,N,Io).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})},ly=function(e){const s=n=>{this.opacity=n,y(this,N,Io).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})},cy=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:o}=this;e.lineWidth=n*r/o,e.lineCap="round",e.lineJoin="round",e.miterLimit=10,e.strokeStyle=`${s}${Bx(i)}`},uy=function(e,s){this.canvas.addEventListener("contextmenu",ws,{signal:this._uiManager._signal}),y(this,N,mp).call(this),v(this,Ao,new AbortController);const i=this._uiManager.combinedSignal(c(this,Ao));this.canvas.addEventListener("pointerleave",this.canvasPointerleave.bind(this),{signal:i}),this.canvas.addEventListener("pointermove",this.canvasPointermove.bind(this),{signal:i}),this.canvas.addEventListener("pointerup",this.canvasPointerup.bind(this),{signal:i}),this.isEditing=!0,c(this,Eo)||(v(this,Eo,!0),y(this,N,lh).call(this),this.thickness||(this.thickness=jt._defaultThickness),this.color||(this.color=jt._defaultColor||_t._defaultLineColor),this.opacity??(this.opacity=jt._defaultOpacity)),this.currentPath.push([e,s]),v(this,To,!1),y(this,N,fp).call(this),v(this,ir,()=>{y(this,N,gy).call(this),c(this,ir)&&window.requestAnimationFrame(c(this,ir))}),window.requestAnimationFrame(c(this,ir))},gp=function(e,s){const[i,n]=this.currentPath.at(-1);if(this.currentPath.length>1&&e===i&&s===n)return;const r=this.currentPath;let o=c(this,gn);if(r.push([e,s]),v(this,To,!0),r.length<=2){o.moveTo(...r[0]),o.lineTo(e,s);return}r.length===3&&(v(this,gn,o=new Path2D),o.moveTo(...r[0])),y(this,N,py).call(this,o,...r.at(-3),...r.at(-2),e,s)},dy=function(){if(this.currentPath.length===0)return;const e=this.currentPath.at(-1);c(this,gn).lineTo(...e)},fy=function(e,s){v(this,ir,null),e=Math.min(Math.max(e,0),this.canvas.width),s=Math.min(Math.max(s,0),this.canvas.height),y(this,N,gp).call(this,e,s),y(this,N,dy).call(this);let i;if(this.currentPath.length!==1)i=y(this,N,my).call(this);else{const l=[e,s];i=[[l,l.slice(),l.slice(),l]]}const n=c(this,gn),r=this.currentPath;this.currentPath=[],v(this,gn,new Path2D);const o=()=>{this.allRawPaths.push(r),this.paths.push(i),this.bezierPath2D.push(n),this._uiManager.rebuild(this)},h=()=>{this.allRawPaths.pop(),this.paths.pop(),this.bezierPath2D.pop(),this.paths.length===0?this.remove():(this.canvas||(y(this,N,Ed).call(this),y(this,N,kd).call(this)),y(this,N,mc).call(this))};this.addCommands({cmd:o,undo:h,mustExec:!0})},gy=function(){if(!c(this,To))return;v(this,To,!1);const e=Math.ceil(this.thickness*this.parentScale),s=this.currentPath.slice(-3),i=s.map(o=>o[0]),n=s.map(o=>o[1]);Math.min(...i)-e,Math.max(...i)+e,Math.min(...n)-e,Math.max(...n)+e;const{ctx:r}=this;r.save(),r.clearRect(0,0,this.canvas.width,this.canvas.height);for(const o of this.bezierPath2D)r.stroke(o);r.stroke(c(this,gn)),r.restore()},py=function(e,s,i,n,r,o,h){const l=(s+n)/2,u=(i+r)/2,d=(n+o)/2,f=(r+h)/2;e.bezierCurveTo(l+2*(n-l)/3,u+2*(r-u)/3,d+2*(n-d)/3,f+2*(r-f)/3,d,f)},my=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[g,p]=e[i],[m,_]=e[i+1],b=(g+m)/2,x=(p+_)/2,C=[n+2*(g-n)/3,r+2*(p-r)/3],A=[b+2*(g-b)/3,x+2*(p-x)/3];s.push([[n,r],C,A,[b,x]]),[n,r]=[b,x]}const[o,h]=e[i],[l,u]=e[i+1],d=[n+2*(o-n)/3,r+2*(h-r)/3],f=[l+2*(o-l)/3,u+2*(h-u)/3];return s.push([[n,r],d,f,[l,u]]),s},Io=function(){if(this.isEmpty()){y(this,N,Md).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,Md).call(this);for(const i of this.bezierPath2D)s.stroke(i)},pp=function(){if(c(this,$a))return;v(this,$a,new AbortController);const e=this._uiManager.combinedSignal(c(this,$a));this.canvas.addEventListener("pointerdown",this.canvasPointerdown.bind(this),{signal:e})},mp=function(){var e;(e=this.pointerdownAC)==null||e.abort(),this.pointerdownAC=null},vp=function(e){var s;(s=c(this,Ao))==null||s.abort(),v(this,Ao,null),y(this,N,pp).call(this),c(this,Ai)&&clearTimeout(c(this,Ai)),v(this,Ai,setTimeout(()=>{v(this,Ai,null),this.canvas.removeEventListener("contextmenu",ws)},10)),y(this,N,fy).call(this,e.offsetX,e.offsetY),this.addToAnnotationStorage(),this.setInBackground()},Ed=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")},kd=function(){v(this,pn,new ResizeObserver(e=>{const s=e[0].contentRect;s.width&&s.height&&this.setDimensions(s.width,s.height)})),c(this,pn).observe(this.div),this._uiManager._signal.addEventListener("abort",()=>{var e;(e=c(this,pn))==null||e.disconnect(),v(this,pn,null)},{once:!0})},lh=function(){if(!c(this,Eo))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,Md).call(this)},bp=function(e,s){const i=y(this,N,Od).call(this),n=(e-i)/c(this,Co),r=(s-i)/c(this,So);this.scaleFactor=Math.min(n,r)},Md=function(){const e=y(this,N,Od).call(this)/2;this.ctx.setTransform(this.scaleFactor,0,0,this.scaleFactor,this.translationX*this.scaleFactor+e,this.translationY*this.scaleFactor+e)},mn=new WeakSet,vy=function(e){const s=new Path2D;for(let i=0,n=e.length;i<n;i++){const[r,o,h,l]=e[i];i===0&&s.moveTo(...r),s.bezierCurveTo(o[0],o[1],h[0],h[1],l[0],l[1])}return s},yp=function(e,s,i){const[n,r,o,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]=o-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]=o-e[l+1],e[l+1]=h-d}break;default:throw new Error("Invalid rotation")}return e},by=function(e,s,i){const[n,r,o,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]=o-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]=o-d}break;default:throw new Error("Invalid rotation")}return e},yy=function(e,s,i,n){var u,d;const r=[],o=this.thickness/2,h=e*s+o,l=e*i+o;for(const f of this.paths){const g=[],p=[];for(let m=0,_=f.length;m<_;m++){const[b,x,C,A]=f[m];if(b[0]===A[0]&&b[1]===A[1]&&_===1){const L=e*b[0]+h,H=e*b[1]+l;g.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*C[0]+h,I=e*C[1]+l,j=e*A[0]+h,G=e*A[1]+l;m===0&&(g.push(k,P),p.push(k,P)),g.push(M,O,R,I,j,G),p.push(M,O),m===_-1&&p.push(j,G)}r.push({bezier:y(u=jt,mn,yp).call(u,g,n,this.rotation),points:y(d=jt,mn,yp).call(d,p,n,this.rotation)})}return r},_p=function(){let e=1/0,s=-1/0,i=1/0,n=-1/0;for(const r of this.paths)for(const[o,h,l,u]of r){const d=Y.bezierBoundingBox(...o,...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]},Od=function(){return c(this,Os)?Math.ceil(this.thickness*this.parentScale):0},mc=function(e=!1){if(this.isEmpty())return;if(!c(this,Os)){y(this,N,Io).call(this);return}const s=y(this,N,_p).call(this),i=y(this,N,Od).call(this);v(this,Co,Math.max(_t.MIN_SIZE,s[2]-s[0])),v(this,So,Math.max(_t.MIN_SIZE,s[3]-s[1]));const n=Math.ceil(i+c(this,Co)*this.scaleFactor),r=Math.ceil(i+c(this,So)*this.scaleFactor),[o,h]=this.parentDimensions;this.width=n/o,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,lh).call(this),y(this,N,Io).call(this),v(this,ko,n),v(this,Mo,r),this.setDims(n,r);const d=e?i/this.scaleFactor/2:0;this.translate(l-this.translationX-d,u-this.translationY-d)},w(jt,mn),tt(jt,"_defaultColor",null),tt(jt,"_defaultOpacity",1),tt(jt,"_defaultThickness",1),tt(jt,"_type","ink"),tt(jt,"_editorType",nt.INK);let vg=jt;const tc=class tc extends _t{constructor(e){super({...e,name:"stampEditor"});w(this,ht);w(this,Nt,null);w(this,be,null);w(this,nr,null);w(this,vn,null);w(this,rr,null);w(this,Ka,"");w(this,Ti,null);w(this,bn,null);w(this,Ei,null);w(this,ms,!1);w(this,Ja,!1);v(this,vn,e.bitmapUrl),v(this,rr,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:o}=e||this.copyCanvas(null,null,!0).imageData,h=await i.guess({name:"altText",request:{data:n,width:r,height:o,channels:n.length/(r*o)}});if(!h)throw new Error("No response from the AI service.");if(h.error)throw new Error("Error from the AI service.");if(h.cancel)return null;if(!h.output)throw new Error("No valid response from the AI service.");const l=h.output;return await this.setGuessedAltText(l),s&&!this.hasAltTextData()&&(this.altTextData={alt:l,decorative:!1}),l}remove(){var e,s;c(this,be)&&(v(this,Nt,null),this._uiManager.imageManager.deleteId(c(this,be)),(e=c(this,Ti))==null||e.remove(),v(this,Ti,null),(s=c(this,bn))==null||s.disconnect(),v(this,bn,null),c(this,Ei)&&(clearTimeout(c(this,Ei)),v(this,Ei,null))),super.remove()}rebuild(){if(!this.parent){c(this,be)&&y(this,ht,Pd).call(this);return}super.rebuild(),this.div!==null&&(c(this,be)&&c(this,Ti)===null&&y(this,ht,Pd).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(){this._isDraggable=!0,this.div.focus()}isEmpty(){return!(c(this,nr)||c(this,Nt)||c(this,vn)||c(this,rr)||c(this,be))}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,Nt)?y(this,ht,wp).call(this):y(this,ht,Pd).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 g;e||(e=224);const{width:n,height:r}=c(this,Nt),o=new qf;let h=c(this,Nt),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*o.sx),m=d.height=Math.ceil(u*o.sy);c(this,ms)||(h=y(this,ht,Dd).call(this,p,m));const _=d.getContext("2d");_.filter=this._uiManager.hcmFilter;let b="white",x="#cfcfd8";this._uiManager.hcmFilter!=="none"?x="black":(g=window.matchMedia)!=null&&g.call(window,"(prefers-color-scheme: dark)").matches&&(b="#8f8f9d",x="#42414d");const C=15,A=C*o.sx,k=C*o.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 f=null;if(i){let p,m;if(o.symmetric&&h.width<e&&h.height<e)p=h.width,m=h.height;else if(h=c(this,Nt),n>e||r>e){const x=Math.min(e/n,e/r);p=Math.floor(n*x),m=Math.floor(r*x),c(this,ms)||(h=y(this,ht,Dd).call(this,p,m))}const b=new OffscreenCanvas(p,m).getContext("2d",{willReadFrequently:!0});b.drawImage(h,0,0,h.width,h.height,0,0,p,m),f={width:p,height:m,data:b.getImageData(0,0,p,m).data}}return{canvas:d,width:l,height:u,imageData:f}}getImageForAltText(){return c(this,Ti)}static async deserialize(e,s,i){var m;let n=null;if(e instanceof Mv){const{data:{rect:_,rotation:b,id:x,structParent:C,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(`${zf}${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:C,popupRef:A}}const r=await super.deserialize(e,s,i),{rect:o,bitmap:h,bitmapUrl:l,bitmapId:u,isSvg:d,accessibilityData:f}=e;u&&i.imageManager.isValidId(u)?(v(r,be,u),h&&v(r,Nt,h)):v(r,vn,l),v(r,ms,d);const[g,p]=r.pageDimensions;return r.width=(o[2]-o[0])/g,r.height=(o[3]-o[1])/p,r.annotationElementId=e.id||null,f&&(r.altTextData=f),r._initialData=n,v(r,Ja,!!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,be),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:c(this,ms),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=y(this,ht,Rd).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,xy).call(this,i);if(h.isSame)return null;h.isSameAltText?delete i.accessibilityData:i.accessibilityData.structParent=this._initialData.structParent??-1}if(i.id=this.annotationElementId,s===null)return i;s.stamps||(s.stamps=new Map);const o=c(this,ms)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!s.stamps.has(c(this,be)))s.stamps.set(c(this,be),{area:o,serialized:i}),i.bitmap=y(this,ht,Rd).call(this,!1);else if(c(this,ms)){const h=s.stamps.get(c(this,be));o>h.area&&(h.area=o,h.serialized.bitmap.close(),h.serialized.bitmap=y(this,ht,Rd).call(this,!1))}return i}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}};Nt=new WeakMap,be=new WeakMap,nr=new WeakMap,vn=new WeakMap,rr=new WeakMap,Ka=new WeakMap,Ti=new WeakMap,bn=new WeakMap,Ei=new WeakMap,ms=new WeakMap,Ja=new WeakMap,ht=new WeakSet,vc=function(e,s=!1){if(!e){this.remove();return}v(this,Nt,e.bitmap),s||(v(this,be,e.id),v(this,ms,e.isSvg)),e.file&&v(this,Ka,e.file.name),y(this,ht,wp).call(this)},bc=function(){if(v(this,nr,null),this._uiManager.enableWaiting(!1),!!c(this,Ti)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&c(this,Nt)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&c(this,Nt)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},Pd=function(){if(c(this,be)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(c(this,be)).then(i=>y(this,ht,vc).call(this,i,!0)).finally(()=>y(this,ht,bc).call(this));return}if(c(this,vn)){const i=c(this,vn);v(this,vn,null),this._uiManager.enableWaiting(!0),v(this,nr,this._uiManager.imageManager.getFromUrl(i).then(n=>y(this,ht,vc).call(this,n)).finally(()=>y(this,ht,bc).call(this)));return}if(c(this,rr)){const i=c(this,rr);v(this,rr,null),this._uiManager.enableWaiting(!0),v(this,nr,this._uiManager.imageManager.getFromFile(i).then(n=>y(this,ht,vc).call(this,n)).finally(()=>y(this,ht,bc).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=tc.supportedTypesStr;const s=this._uiManager._signal;v(this,nr,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,vc).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>y(this,ht,bc).call(this))),e.click()},wp=function(){const{div:e}=this;let{width:s,height:i}=c(this,Nt);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,l]=this.parentDimensions;this.setDims(s*h/n,i*l/r),this._uiManager.enableWaiting(!1);const u=v(this,Ti,document.createElement("canvas"));u.setAttribute("role","img"),this.addContainer(u),(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),y(this,ht,xp).call(this,s,i),y(this,ht,wy).call(this),c(this,Ja)||(this.parent.addUndoableEditor(this),v(this,Ja,!0)),this._reportTelemetry({action:"inserted_image"}),c(this,Ka)&&u.setAttribute("aria-label",c(this,Ka))},_y=function(e,s){var o;const[i,n]=this.parentDimensions;this.width=e/i,this.height=s/n,(o=this._initialOptions)!=null&&o.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,c(this,Ei)!==null&&clearTimeout(c(this,Ei)),v(this,Ei,setTimeout(()=>{v(this,Ei,null),y(this,ht,xp).call(this,e,s)},200))},Dd=function(e,s){const{width:i,height:n}=c(this,Nt);let r=i,o=n,h=c(this,Nt);for(;r>2*e||o>2*s;){const l=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,l,u,0,0,r,o),h=d.transferToImageBitmap()}return h},xp=function(e,s){const i=new qf,n=Math.ceil(e*i.sx),r=Math.ceil(s*i.sy),o=c(this,Ti);if(!o||o.width===n&&o.height===r)return;o.width=n,o.height=r;const h=c(this,ms)?c(this,Nt):y(this,ht,Dd).call(this,n,r),l=o.getContext("2d");l.filter=this._uiManager.hcmFilter,l.drawImage(h,0,0,h.width,h.height,0,0,n,r)},Rd=function(e){if(e){if(c(this,ms)){const n=this._uiManager.imageManager.getSvgUrl(c(this,be));if(n)return n}const s=document.createElement("canvas");return{width:s.width,height:s.height}=c(this,Nt),s.getContext("2d").drawImage(c(this,Nt),0,0),s.toDataURL()}if(c(this,ms)){const[s,i]=this.pageDimensions,n=Math.round(this.width*s*Dn.PDF_TO_CSS_UNITS),r=Math.round(this.height*i*Dn.PDF_TO_CSS_UNITS),o=new OffscreenCanvas(n,r);return o.getContext("2d").drawImage(c(this,Nt),0,0,c(this,Nt).width,c(this,Nt).height,0,0,n,r),o.transferToImageBitmap()}return structuredClone(c(this,Nt))},wy=function(){this._uiManager._signal&&(v(this,bn,new ResizeObserver(e=>{const s=e[0].contentRect;s.width&&s.height&&y(this,ht,_y).call(this,s.width,s.height)})),c(this,bn).observe(this.div),this._uiManager._signal.addEventListener("abort",()=>{var e;(e=c(this,bn))==null||e.disconnect(),v(this,bn,null)},{once:!0}))},xy=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),o=e.pageIndex===i,h=(((l=e.accessibilityData)==null?void 0:l.alt)||"")===n;return{isSame:r&&o&&h,isSameAltText:h}},tt(tc,"_type","stamp"),tt(tc,"_editorType",nt.STAMP);let bg=tc;const ii=class ii{constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:o,textLayer:h,viewport:l,l10n:u}){w(this,ye);w(this,Oo);w(this,Qa,!1);w(this,ki,null);w(this,or,null);w(this,yn,null);w(this,vs,new Map);w(this,ar,!1);w(this,Za,!1);w(this,th,!1);w(this,Pe,null);w(this,_n,null);w(this,q);const d=[...c(ii,hr).values()];if(!ii._initialized){ii._initialized=!0;for(const f of d)f.initialize(u,t)}t.registerEditorTypes(d),v(this,q,t),this.pageIndex=e,this.div=s,v(this,Oo,n),v(this,ki,r),this.viewport=l,v(this,Pe,h),this.drawLayer=o,this._structTree=i,c(this,q).addLayer(this)}get isEmpty(){return c(this,vs).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,ye,Fd).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(ii,hr).values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=c(this,Pe))==null?void 0:e.div)}addInkEditorIfNeeded(t){if(c(this,q).getMode()!==nt.INK)return;if(!t){for(const s of c(this,vs).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,ki))==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,vs).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(c(this,q).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!c(this,ki))return;const e=c(this,ki).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,th,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const n of c(this,vs).values())if(n.disableEditing(),!!n.annotationElementId){if(n.serialize()!==null){t.set(n.annotationElementId,n);continue}else e.set(n.annotationElementId,n);(i=this.getEditableAnnotation(n.annotationElementId))==null||i.show(),n.remove()}if(c(this,ki)){const n=c(this,ki).getEditableAnnotations();for(const r of n){const{id:o}=r.data;if(c(this,q).isDeletedAnnotationElement(o))continue;let h=e.get(o);if(h){h.resetAnnotationElement(r),h.show(!1),r.show();continue}h=t.get(o),h&&(c(this,q).addChangedExistingAnnotation(h),h.renderAnnotationElement(r)&&h.show(!1)),r.show()}}y(this,ye,Fd).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of c(ii,hr).values())s.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),v(this,th,!1)}getEditableAnnotation(t){var e;return((e=c(this,ki))==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,Pe))!=null&&t.div&&!c(this,_n)){v(this,_n,new AbortController);const e=c(this,q).combinedSignal(c(this,_n));c(this,Pe).div.addEventListener("pointerdown",y(this,ye,Sy).bind(this),{signal:e}),c(this,Pe).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=c(this,Pe))!=null&&t.div&&c(this,_n)&&(c(this,_n).abort(),v(this,_n,null),c(this,Pe).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,vs).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,vs).delete(t.id),(e=c(this,Oo))==null||e.removePointerInTextLayer(t.contentDiv),!c(this,th)&&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,Za)||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,yn)&&(t._focusEventsAllowed=!1,v(this,yn,setTimeout(()=>{v(this,yn,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,Oo))==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,ye,Sp))==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,ye,Ap).call(this),n=this.getNextId(),r=y(this,ye,Cp).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(ii,hr).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,ye,Cp).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,ye,Ap).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}=Be.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&c(this,ar)){if(v(this,ar,!1),!c(this,Qa)){v(this,Qa,!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,ar)){v(this,ar,!1);return}const{isMac:e}=Be.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;v(this,ar,!0);const s=c(this,q).getActive();v(this,Qa,!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,yn)&&(clearTimeout(c(this,yn)),v(this,yn,null));for(const s of c(this,vs).values())(e=c(this,Oo))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,c(this,vs).clear(),c(this,q).removeLayer(this)}render({viewport:t}){this.viewport=t,Er(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,ye,Fd).call(this);const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,Er(this.div,{rotation:s}),e!==s)for(const i of c(this,vs).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}};Oo=new WeakMap,Qa=new WeakMap,ki=new WeakMap,or=new WeakMap,yn=new WeakMap,vs=new WeakMap,ar=new WeakMap,Za=new WeakMap,th=new WeakMap,Pe=new WeakMap,_n=new WeakMap,q=new WeakMap,hr=new WeakMap,ye=new WeakSet,Sy=function(t){c(this,q).unselectAll();const{target:e}=t;if(e===c(this,Pe).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&c(this,Pe).div.contains(e)){const{isMac:s}=Be.platform;if(t.button!==0||t.ctrlKey&&s)return;c(this,q).showAllEditors("highlight",!0,!0),c(this,Pe).div.classList.add("free"),this.toggleDrawing(),Nu.startHighlighting(this,c(this,q).direction==="ltr",{target:c(this,Pe).div,x:t.x,y:t.y}),c(this,Pe).div.addEventListener("pointerup",()=>{c(this,Pe).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:c(this,q)._signal}),t.preventDefault()}},Sp=function(){return c(ii,hr).get(c(this,q).getMode())},Cp=function(t){const e=c(this,ye,Sp);return e?new e.prototype.constructor(t):null},Ap=function(){const{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),o=Math.min(window.innerWidth,t+s),h=Math.min(window.innerHeight,e+i),l=(n+o)/2-t,u=(r+h)/2-e,[d,f]=this.viewport.rotation%180===0?[l,u]:[u,l];return{offsetX:d,offsetY:f}},Fd=function(){v(this,Za,!0);for(const t of c(this,vs).values())t.isEmpty()&&t.remove();v(this,Za,!1)},tt(ii,"_initialized",!1),w(ii,hr,new Map([pg,vg,bg,Nu].map(t=>[t._editorType,t])));let yg=ii;const _e=class _e{constructor({pageIndex:t}){w(this,Po);w(this,Mi,null);w(this,ec,0);w(this,te,new Map);w(this,wn,new Map);this.pageIndex=t}setParent(t){if(!c(this,Mi)){v(this,Mi,t);return}if(c(this,Mi)!==t){if(c(this,te).size>0)for(const e of c(this,te).values())e.remove(),t.append(e);v(this,Mi,t)}}static get _svgFactory(){return ut(this,"_svgFactory",new dg)}draw(t,e,s,i=!1){const n=Ue(this,ec)._++,r=y(this,Po,Ep).call(this,t.box);r.classList.add(...t.classNamesForDrawing);const o=_e._svgFactory.createElement("defs");r.append(o);const h=_e._svgFactory.createElement("path");o.append(h);const l=`path_p${this.pageIndex}_${n}`;h.setAttribute("id",l),h.setAttribute("d",t.toSVGPath()),i&&c(this,wn).set(n,h);const u=y(this,Po,Cy).call(this,o,l),d=_e._svgFactory.createElement("use");return r.append(d),r.setAttribute("fill",e),r.setAttribute("fill-opacity",s),d.setAttribute("href",`#${l}`),c(this,te).set(n,r),{id:n,clipPathId:`url(#${u})`}}drawOutline(t){const e=Ue(this,ec)._++,s=y(this,Po,Ep).call(this,t.box);s.classList.add(...t.classNamesForOutlining);const i=_e._svgFactory.createElement("defs");s.append(i);const n=_e._svgFactory.createElement("path");i.append(n);const r=`path_p${this.pageIndex}_${e}`;n.setAttribute("id",r),n.setAttribute("d",t.toSVGPath()),n.setAttribute("vector-effect","non-scaling-stroke");let o;if(t.mustRemoveSelfIntersections){const u=_e._svgFactory.createElement("mask");i.append(u),o=`mask_p${this.pageIndex}_${e}`,u.setAttribute("id",o),u.setAttribute("maskUnits","objectBoundingBox");const d=_e._svgFactory.createElement("rect");u.append(d),d.setAttribute("width","1"),d.setAttribute("height","1"),d.setAttribute("fill","white");const f=_e._svgFactory.createElement("use");u.append(f),f.setAttribute("href",`#${r}`),f.setAttribute("stroke","none"),f.setAttribute("fill","black"),f.setAttribute("fill-rule","nonzero"),f.classList.add("mask")}const h=_e._svgFactory.createElement("use");s.append(h),h.setAttribute("href",`#${r}`),o&&h.setAttribute("mask",`url(#${o})`);const l=h.cloneNode();return s.append(l),h.classList.add("mainOutline"),l.classList.add("secondaryOutline"),c(this,te).set(e,s),e}finalizeLine(t,e){const s=c(this,wn).get(t);c(this,wn).delete(t),this.updateBox(t,e.box),s.setAttribute("d",e.toSVGPath())}updateLine(t,e){c(this,te).get(t).firstChild.firstChild.setAttribute("d",e.toSVGPath())}updatePath(t,e){c(this,wn).get(t).setAttribute("d",e.toSVGPath())}updateBox(t,e){var s;y(s=_e,sc,Tp).call(s,c(this,te).get(t),e)}show(t,e){c(this,te).get(t).classList.toggle("hidden",!e)}rotate(t,e){c(this,te).get(t).setAttribute("data-main-rotation",e)}changeColor(t,e){c(this,te).get(t).setAttribute("fill",e)}changeOpacity(t,e){c(this,te).get(t).setAttribute("fill-opacity",e)}addClass(t,e){c(this,te).get(t).classList.add(e)}removeClass(t,e){c(this,te).get(t).classList.remove(e)}getSVGRoot(t){return c(this,te).get(t)}remove(t){c(this,wn).delete(t),c(this,Mi)!==null&&(c(this,te).get(t).remove(),c(this,te).delete(t))}destroy(){v(this,Mi,null);for(const t of c(this,te).values())t.remove();c(this,te).clear(),c(this,wn).clear()}};Mi=new WeakMap,ec=new WeakMap,te=new WeakMap,wn=new WeakMap,sc=new WeakSet,Tp=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}%`},Po=new WeakSet,Ep=function(t){var s;const e=_e._svgFactory.create(1,1,!0);return c(this,Mi).append(e),e.setAttribute("aria-hidden",!0),y(s=_e,sc,Tp).call(s,e,t),e},Cy=function(t,e){const s=_e._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=_e._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i},w(_e,sc);let _g=_e;et.AbortException,et.AnnotationEditorLayer,et.AnnotationEditorParamsType,et.AnnotationEditorType,et.AnnotationEditorUIManager,et.AnnotationLayer,et.AnnotationMode,et.ColorPicker,et.DOMSVGFactory,et.DrawLayer,et.FeatureTest;var bC=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 yC=et.getDocument;et.getFilenameFromUrl,et.getPdfFilenameFromUrl,et.getXfaPageViewport,et.isDataScheme,et.isPdfFile,et.noContextMenu,et.normalizeUnicode,et.setLayerDimensions,et.shadow,et.version;const _C={fabric:"^6.4.3","pdfjs-dist":"^4.8.69"};function wC(a){return new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>t(s.result)),s.addEventListener("error",e),s.readAsDataURL(a)})}const xC=_C["pdfjs-dist"].replace("^","");bC.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${xC}/pdf.worker.min.mjs`;async function SC(a){const t="data:application/pdf;base64,",e=await wC(a);if(typeof e=="string")return window.atob(e.slice(t.length))}function CC(a,t){return yC({data:a,password:t}).promise}const AC={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},TC={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},EC={stroke:"#000",hoverStroke:"#B7EC5D",src:""};function Rv(a=""){const t=K.useRef(0),e=K.useRef(null),s=K.useRef(null),i=K.useRef(1),n=K.useRef({...EC});function r(){if(!a||_s.has(a))return;const M=ax(a);return M.on("selection:cleared",()=>A(M)),M}function o(M,O){const R=M.type;return{"application/pdf":h,"image/png":d,"image/jpeg":d}[R](M,O)??Promise.reject(new Error(`Unsupported ${R} file type.`))}async function h(M,O){const R=await SC(M);if(!R)return;const I=hx(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 CC(O,I),G=await j.getPage(M),{renderTask:L,canvas:H}=lx(G,R);return t.current=j.numPages,L.promise.then(()=>u(H))}catch(j){return Promise.reject(j)}}function u(M){ux(a,M)}async function d(M){return await dx(a,M)}async function f({url:M,scale:O=.5}){await j0(a,{url:M,scale:O})}async function g(M,O){const R=_s.get(a);if(!R)return;const I=await Ae.fromURL(M,{},{...AC,...O});R.add(I),m(R,I)}function p(M,O){const R=_s.get(a);if(!R)return;const I=new Ce(M,{...TC,...O});R.add(I),m(R,I)}function m(M,O){O.on("selected",R=>_({canvas:M,target:R.target})),O.on("modified",R=>kh(R.target,e.current)),O.on("scaling",R=>kh(R.transform.target,e.current)),O.on("moving",R=>kh(R.transform.target,e.current)),O.on("rotating",R=>kh(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 cx(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(a);i.current=M,R&&(gx(s.current,M,n.current),fx(s.current,M,e.current),!O&&R.renderAll())}function C(M){if(!M)return;n.current={...n.current,...M};const O=_s.get(a);!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(){px(a)}function P(){mx(a)}return{createCanvas:r,loadFile:o,specifyPage:l,renderImage:f,addFabric:g,addTextFabric:p,clearActive:k,deleteCanvas:P,scaleFabric:x,setCloseSvgOptions:C}}function kC(a){let t=0;const e=ox(()=>{t!==window.innerWidth&&(t=window.innerWidth,a())});K.useEffect(()=>(window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)),[])}const MC=K.forwardRef(OC);function OC({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:l,dropImageOptions:u,closeSvgOptions:d},f){const g=K.useRef(null),p=`${e}-${t-1}`,m=K.useMemo(()=>s*n,[s,n]),{createCanvas:_,specifyPage:b,addFabric:x,addTextFabric:C,renderImage:A,clearActive:k,deleteCanvas:P,scaleFabric:M,setCloseSvgOptions:O}=Rv(p);kC(R);async function R(){window.requestAnimationFrame(async()=>{if(_(),a.PDFBase64.startsWith("data:image")||a.canvas){const{canvas:L}=a,H=L?7:3,$=L!=null&&L.length?L[t-1]:a.PDFBase64;A({url:$,scale:i/H});return}await b({page:t,PDFBase64:a.PDFBase64,scale:i,password:h})})}function I(L){if(L.preventDefault(),L.stopPropagation(),!o||!L.dataTransfer)return;const{dataTransfer:H,clientX:$,clientY:J}=L,U=H.getData("text"),X=H.getData("image"),Ot={left:$-71,top:J-55};X&&j(X,Ot),U&&G(U,Ot)}function j(L,H){x(L,{...H,...u})}function G(L,H){C(L,{...H,...l})}return K.useImperativeHandle(f,()=>({addImage:j,addText:G,clearActive:k,deleteCanvas:P,canvasRef:g})),K.useEffect(()=>{R()},[i,t,a,h]),K.useEffect(()=>{M(m)},[m]),K.useEffect(()=>{O(d)},[d]),K.useEffect(()=>()=>P(),[]),Op.jsx("div",{style:{transform:`scale(${m})`},onDragOver:L=>L.preventDefault(),onDragEnter:L=>L.preventDefault(),onDrop:I,children:Op.jsx("canvas",{id:p,ref:g,className:r})})}const Bu=Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"}));ct.default=MC,ct.useFabric=Rv,Object.defineProperties(ct,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
534
|
+
`)}`),y(this,Qt,Cd).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 a;let n=null;if(e instanceof Ev){const{data:{defaultAppearanceData:{fontSize:h,fontColor:l},rect:u,rotation:d,id:g,popupRef:f},textContent:p,textPosition:m,parent:{page:{pageNumber:_}}}=e;if(!p||p.length===0)return null;n=e={annotationType:nt.FREETEXT,color:Array.from(l),fontSize:h,value:p.join(`
|
|
535
|
+
`),position:m,pageIndex:_-1,rect:u.slice(0),rotation:d,id:g,deleted:!1,popupRef:f}}const r=await super.deserialize(e,s,i);return v(r,ds,e.fontSize),v(r,Qs,U.makeHexColor(...e.color)),v(r,us,y(a=Et,cn,op).call(a,e.value)),r.annotationElementId=e.id||null,r._initialData=n,r}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const s=Et._internalPadding*this.parentScale,i=this.getRect(s,s),n=_t._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:c(this,Qs)),r={annotationType:nt.FREETEXT,color:n,fontSize:c(this,ds),value:y(this,Qt,Hb).call(this),pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?r:this.annotationElementId&&!y(this,Qt,Wb).call(this,r)?null:(r.id=this.annotationElementId,r)}renderAnnotationElement(e){const s=super.renderAnnotationElement(e);if(this.deleted)return s;const{style:i}=s;i.fontSize=`calc(${c(this,ds)}px * var(--scale-factor))`,i.color=c(this,Qs),s.replaceChildren();for(const r of c(this,us).split(`
|
|
536
|
+
`)){const a=document.createElement("div");a.append(r?document.createTextNode(r):document.createElement("br")),s.append(a)}const n=Et._internalPadding*this.parentScale;return e.updateEdited({rect:this.getRect(n,n),popupContent:c(this,us)}),s}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}};Qs=new WeakMap,us=new WeakMap,Bl=new WeakMap,ma=new WeakMap,ds=new WeakMap,Qt=new WeakSet,jb=function(e){const s=n=>{this.editorDiv.style.fontSize=`calc(${n}px * var(--scale-factor))`,this.translate(0,-(n-c(this,ds))*this.parentScale),v(this,ds,n),y(this,Qt,xd).call(this)},i=c(this,ds);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Z.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})},Nb=function(e){const s=n=>{v(this,Qs,this.editorDiv.style.color=n)},i=c(this,Qs);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Z.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})},Bb=function(){var i;const e=[];this.editorDiv.normalize();let s=null;for(const n of this.editorDiv.childNodes)(s==null?void 0:s.nodeType)===Node.TEXT_NODE&&n.nodeName==="BR"||(e.push(y(i=Et,cn,Sd).call(i,n)),s=n);return e.join(`
|
|
537
|
+
`)},xd=function(){const[e,s]=this.parentDimensions;let i;if(this.isAttachedToDOM)i=this.div.getBoundingClientRect();else{const{currentLayer:n,div:r}=this,a=r.style.display,h=r.classList.contains("hidden");r.classList.remove("hidden"),r.style.display="hidden",n.div.append(this.div),i=r.getBoundingClientRect(),r.remove(),r.style.display=a,r.classList.toggle("hidden",h)}this.rotation%180===this.parentRotation%180?(this.width=i.width/e,this.height=i.height/s):(this.width=i.height/e,this.height=i.width/s),this.fixAndSetPosition()},cn=new WeakSet,Sd=function(e){return(e.nodeType===Node.TEXT_NODE?e.nodeValue:e.innerText).replaceAll(Iu,"")},Cd=function(){if(this.editorDiv.replaceChildren(),!!c(this,us))for(const e of c(this,us).split(`
|
|
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"}})});
|