nhanh-pure-function 3.0.6 → 3.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
* https://github.com/MikeMcl/decimal.js
|
|
7
7
|
* Copyright (c) 2025 Michael Mclaughlin <M8ch88l@gmail.com>
|
|
8
8
|
* MIT Licence
|
|
9
|
-
*/var he=9e15,ut=1e9,ue="0123456789abcdef",Zt="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Qt="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",de={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-9e15,maxE:he,crypto:!1},Le,nt,S=!0,ie="[DecimalError] ",ht=ie+"Invalid argument: ",Te=ie+"Precision limit exceeded",Fe=ie+"crypto unavailable",Be="[object Decimal]",T=Math.floor,I=Math.pow,Mi=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Oi=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Ni=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Ue=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,$=1e7,b=7,Ai=9007199254740991,Ii=Zt.length-1,fe=Qt.length-1,y={toStringTag:Be};y.absoluteValue=y.abs=function(){var r=new this.constructor(this);return r.s<0&&(r.s=1),x(r)};y.ceil=function(){return x(new this.constructor(this),this.e+1,2)};y.clampedTo=y.clamp=function(r,n){var t,e=this,i=e.constructor;if(r=new i(r),n=new i(n),!r.s||!n.s)return new i(NaN);if(r.gt(n))throw Error(ht+n);return t=e.cmp(r),t<0?r:e.cmp(n)>0?n:new i(e)};y.comparedTo=y.cmp=function(r){var n,t,e,i,s=this,o=s.d,a=(r=new s.constructor(r)).d,l=s.s,c=r.s;if(!o||!a)return!l||!c?NaN:l!==c?l:o===a?0:!o^l<0?1:-1;if(!o[0]||!a[0])return o[0]?l:a[0]?-c:0;if(l!==c)return l;if(s.e!==r.e)return s.e>r.e^l<0?1:-1;for(e=o.length,i=a.length,n=0,t=e<i?e:i;n<t;++n)if(o[n]!==a[n])return o[n]>a[n]^l<0?1:-1;return e===i?0:e>i^l<0?1:-1};y.cosine=y.cos=function(){var r,n,t=this,e=t.constructor;return t.d?t.d[0]?(r=e.precision,n=e.rounding,e.precision=r+Math.max(t.e,t.sd())+b,e.rounding=1,t=Hi(e,We(e,t)),e.precision=r,e.rounding=n,x(nt==2||nt==3?t.neg():t,r,n,!0)):new e(1):new e(NaN)};y.cubeRoot=y.cbrt=function(){var r,n,t,e,i,s,o,a,l,c,h=this,u=h.constructor;if(!h.isFinite()||h.isZero())return new u(h);for(S=!1,s=h.s*I(h.s*h,1/3),!s||Math.abs(s)==1/0?(t=H(h.d),r=h.e,(s=(r-t.length+1)%3)&&(t+=s==1||s==-2?"0":"00"),s=I(t,1/3),r=T((r+1)/3)-(r%3==(r<0?-1:2)),s==1/0?t="5e"+r:(t=s.toExponential(),t=t.slice(0,t.indexOf("e")+1)+r),e=new u(t),e.s=h.s):e=new u(s.toString()),o=(r=u.precision)+3;;)if(a=e,l=a.times(a).times(a),c=l.plus(h),e=k(c.plus(h).times(a),c.plus(l),o+2,1),H(a.d).slice(0,o)===(t=H(e.d)).slice(0,o))if(t=t.slice(o-3,o+1),t=="9999"||!i&&t=="4999"){if(!i&&(x(a,r+1,0),a.times(a).times(a).eq(h))){e=a;break}o+=4,i=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(x(e,r+1,1),n=!e.times(e).times(e).eq(h));break}return S=!0,x(e,r,u.rounding,n)};y.decimalPlaces=y.dp=function(){var r,n=this.d,t=NaN;if(n){if(r=n.length-1,t=(r-T(this.e/b))*b,r=n[r],r)for(;r%10==0;r/=10)t--;t<0&&(t=0)}return t};y.dividedBy=y.div=function(r){return k(this,new this.constructor(r))};y.dividedToIntegerBy=y.divToInt=function(r){var n=this,t=n.constructor;return x(k(n,new t(r),0,1,1),t.precision,t.rounding)};y.equals=y.eq=function(r){return this.cmp(r)===0};y.floor=function(){return x(new this.constructor(this),this.e+1,3)};y.greaterThan=y.gt=function(r){return this.cmp(r)>0};y.greaterThanOrEqualTo=y.gte=function(r){var n=this.cmp(r);return n==1||n===0};y.hyperbolicCosine=y.cosh=function(){var r,n,t,e,i,s=this,o=s.constructor,a=new o(1);if(!s.isFinite())return new o(s.s?1/0:NaN);if(s.isZero())return a;t=o.precision,e=o.rounding,o.precision=t+Math.max(s.e,s.sd())+4,o.rounding=1,i=s.d.length,i<32?(r=Math.ceil(i/3),n=(1/ne(4,r)).toString()):(r=16,n="2.3283064365386962890625e-10"),s=Dt(o,1,s.times(n),new o(1),!0);for(var l,c=r,h=new o(8);c--;)l=s.times(s),s=a.minus(l.times(h.minus(l.times(h))));return x(s,o.precision=t,o.rounding=e,!0)};y.hyperbolicSine=y.sinh=function(){var r,n,t,e,i=this,s=i.constructor;if(!i.isFinite()||i.isZero())return new s(i);if(n=s.precision,t=s.rounding,s.precision=n+Math.max(i.e,i.sd())+4,s.rounding=1,e=i.d.length,e<3)i=Dt(s,2,i,i,!0);else{r=1.4*Math.sqrt(e),r=r>16?16:r|0,i=i.times(1/ne(5,r)),i=Dt(s,2,i,i,!0);for(var o,a=new s(5),l=new s(16),c=new s(20);r--;)o=i.times(i),i=i.times(a.plus(o.times(l.times(o).plus(c))))}return s.precision=n,s.rounding=t,x(i,n,t,!0)};y.hyperbolicTangent=y.tanh=function(){var r,n,t=this,e=t.constructor;return t.isFinite()?t.isZero()?new e(t):(r=e.precision,n=e.rounding,e.precision=r+7,e.rounding=1,k(t.sinh(),t.cosh(),e.precision=r,e.rounding=n)):new e(t.s)};y.inverseCosine=y.acos=function(){var r=this,n=r.constructor,t=r.abs().cmp(1),e=n.precision,i=n.rounding;return t!==-1?t===0?r.isNeg()?J(n,e,i):new n(0):new n(NaN):r.isZero()?J(n,e+4,i).times(.5):(n.precision=e+6,n.rounding=1,r=new n(1).minus(r).div(r.plus(1)).sqrt().atan(),n.precision=e,n.rounding=i,r.times(2))};y.inverseHyperbolicCosine=y.acosh=function(){var r,n,t=this,e=t.constructor;return t.lte(1)?new e(t.eq(1)?0:NaN):t.isFinite()?(r=e.precision,n=e.rounding,e.precision=r+Math.max(Math.abs(t.e),t.sd())+4,e.rounding=1,S=!1,t=t.times(t).minus(1).sqrt().plus(t),S=!0,e.precision=r,e.rounding=n,t.ln()):new e(t)};y.inverseHyperbolicSine=y.asinh=function(){var r,n,t=this,e=t.constructor;return!t.isFinite()||t.isZero()?new e(t):(r=e.precision,n=e.rounding,e.precision=r+2*Math.max(Math.abs(t.e),t.sd())+6,e.rounding=1,S=!1,t=t.times(t).plus(1).sqrt().plus(t),S=!0,e.precision=r,e.rounding=n,t.ln())};y.inverseHyperbolicTangent=y.atanh=function(){var r,n,t,e,i=this,s=i.constructor;return i.isFinite()?i.e>=0?new s(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(r=s.precision,n=s.rounding,e=i.sd(),Math.max(e,r)<2*-i.e-1?x(new s(i),r,n,!0):(s.precision=t=e-i.e,i=k(i.plus(1),new s(1).minus(i),t+r,1),s.precision=r+4,s.rounding=1,i=i.ln(),s.precision=r,s.rounding=n,i.times(.5))):new s(NaN)};y.inverseSine=y.asin=function(){var r,n,t,e,i=this,s=i.constructor;return i.isZero()?new s(i):(n=i.abs().cmp(1),t=s.precision,e=s.rounding,n!==-1?n===0?(r=J(s,t+4,e).times(.5),r.s=i.s,r):new s(NaN):(s.precision=t+6,s.rounding=1,i=i.div(new s(1).minus(i.times(i)).sqrt().plus(1)).atan(),s.precision=t,s.rounding=e,i.times(2)))};y.inverseTangent=y.atan=function(){var r,n,t,e,i,s,o,a,l,c=this,h=c.constructor,u=h.precision,d=h.rounding;if(c.isFinite()){if(c.isZero())return new h(c);if(c.abs().eq(1)&&u+4<=fe)return o=J(h,u+4,d).times(.25),o.s=c.s,o}else{if(!c.s)return new h(NaN);if(u+4<=fe)return o=J(h,u+4,d).times(.5),o.s=c.s,o}for(h.precision=a=u+10,h.rounding=1,t=Math.min(28,a/b+2|0),r=t;r;--r)c=c.div(c.times(c).plus(1).sqrt().plus(1));for(S=!1,n=Math.ceil(a/b),e=1,l=c.times(c),o=new h(c),i=c;r!==-1;)if(i=i.times(l),s=o.minus(i.div(e+=2)),i=i.times(l),o=s.plus(i.div(e+=2)),o.d[n]!==void 0)for(r=n;o.d[r]===s.d[r]&&r--;);return t&&(o=o.times(2<<t-1)),S=!0,x(o,h.precision=u,h.rounding=d,!0)};y.isFinite=function(){return!!this.d};y.isInteger=y.isInt=function(){return!!this.d&&T(this.e/b)>this.d.length-2};y.isNaN=function(){return!this.s};y.isNegative=y.isNeg=function(){return this.s<0};y.isPositive=y.isPos=function(){return this.s>0};y.isZero=function(){return!!this.d&&this.d[0]===0};y.lessThan=y.lt=function(r){return this.cmp(r)<0};y.lessThanOrEqualTo=y.lte=function(r){return this.cmp(r)<1};y.logarithm=y.log=function(r){var n,t,e,i,s,o,a,l,c=this,h=c.constructor,u=h.precision,d=h.rounding,m=5;if(r==null)r=new h(10),n=!0;else{if(r=new h(r),t=r.d,r.s<0||!t||!t[0]||r.eq(1))return new h(NaN);n=r.eq(10)}if(t=c.d,c.s<0||!t||!t[0]||c.eq(1))return new h(t&&!t[0]?-1/0:c.s!=1?NaN:t?0:1/0);if(n)if(t.length>1)s=!0;else{for(i=t[0];i%10===0;)i/=10;s=i!==1}if(S=!1,a=u+m,o=at(c,a),e=n?Jt(h,a+10):at(r,a),l=k(o,e,a,1),Ot(l.d,i=u,d))do if(a+=10,o=at(c,a),e=n?Jt(h,a+10):at(r,a),l=k(o,e,a,1),!s){+H(l.d).slice(i+1,i+15)+1==1e14&&(l=x(l,u+1,0));break}while(Ot(l.d,i+=10,d));return S=!0,x(l,u,d)};y.minus=y.sub=function(r){var n,t,e,i,s,o,a,l,c,h,u,d,m=this,g=m.constructor;if(r=new g(r),!m.d||!r.d)return!m.s||!r.s?r=new g(NaN):m.d?r.s=-r.s:r=new g(r.d||m.s!==r.s?m:NaN),r;if(m.s!=r.s)return r.s=-r.s,m.plus(r);if(c=m.d,d=r.d,a=g.precision,l=g.rounding,!c[0]||!d[0]){if(d[0])r.s=-r.s;else if(c[0])r=new g(m);else return new g(l===3?-0:0);return S?x(r,a,l):r}if(t=T(r.e/b),h=T(m.e/b),c=c.slice(),s=h-t,s){for(u=s<0,u?(n=c,s=-s,o=d.length):(n=d,t=h,o=c.length),e=Math.max(Math.ceil(a/b),o)+2,s>e&&(s=e,n.length=1),n.reverse(),e=s;e--;)n.push(0);n.reverse()}else{for(e=c.length,o=d.length,u=e<o,u&&(o=e),e=0;e<o;e++)if(c[e]!=d[e]){u=c[e]<d[e];break}s=0}for(u&&(n=c,c=d,d=n,r.s=-r.s),o=c.length,e=d.length-o;e>0;--e)c[o++]=0;for(e=d.length;e>s;){if(c[--e]<d[e]){for(i=e;i&&c[--i]===0;)c[i]=$-1;--c[i],c[e]+=$}c[e]-=d[e]}for(;c[--o]===0;)c.pop();for(;c[0]===0;c.shift())--t;return c[0]?(r.d=c,r.e=se(c,t),S?x(r,a,l):r):new g(l===3?-0:0)};y.modulo=y.mod=function(r){var n,t=this,e=t.constructor;return r=new e(r),!t.d||!r.s||r.d&&!r.d[0]?new e(NaN):!r.d||t.d&&!t.d[0]?x(new e(t),e.precision,e.rounding):(S=!1,e.modulo==9?(n=k(t,r.abs(),0,3,1),n.s*=r.s):n=k(t,r,0,e.modulo,1),n=n.times(r),S=!0,t.minus(n))};y.naturalExponential=y.exp=function(){return me(this)};y.naturalLogarithm=y.ln=function(){return at(this)};y.negated=y.neg=function(){var r=new this.constructor(this);return r.s=-r.s,x(r)};y.plus=y.add=function(r){var n,t,e,i,s,o,a,l,c,h,u=this,d=u.constructor;if(r=new d(r),!u.d||!r.d)return!u.s||!r.s?r=new d(NaN):u.d||(r=new d(r.d||u.s===r.s?u:NaN)),r;if(u.s!=r.s)return r.s=-r.s,u.minus(r);if(c=u.d,h=r.d,a=d.precision,l=d.rounding,!c[0]||!h[0])return h[0]||(r=new d(u)),S?x(r,a,l):r;if(s=T(u.e/b),e=T(r.e/b),c=c.slice(),i=s-e,i){for(i<0?(t=c,i=-i,o=h.length):(t=h,e=s,o=c.length),s=Math.ceil(a/b),o=s>o?s+1:o+1,i>o&&(i=o,t.length=1),t.reverse();i--;)t.push(0);t.reverse()}for(o=c.length,i=h.length,o-i<0&&(i=o,t=h,h=c,c=t),n=0;i;)n=(c[--i]=c[i]+h[i]+n)/$|0,c[i]%=$;for(n&&(c.unshift(n),++e),o=c.length;c[--o]==0;)c.pop();return r.d=c,r.e=se(c,e),S?x(r,a,l):r};y.precision=y.sd=function(r){var n,t=this;if(r!==void 0&&r!==!!r&&r!==1&&r!==0)throw Error(ht+r);return t.d?(n=Ge(t.d),r&&t.e+1>n&&(n=t.e+1)):n=NaN,n};y.round=function(){var r=this,n=r.constructor;return x(new n(r),r.e+1,n.rounding)};y.sine=y.sin=function(){var r,n,t=this,e=t.constructor;return t.isFinite()?t.isZero()?new e(t):(r=e.precision,n=e.rounding,e.precision=r+Math.max(t.e,t.sd())+b,e.rounding=1,t=Ti(e,We(e,t)),e.precision=r,e.rounding=n,x(nt>2?t.neg():t,r,n,!0)):new e(NaN)};y.squareRoot=y.sqrt=function(){var r,n,t,e,i,s,o=this,a=o.d,l=o.e,c=o.s,h=o.constructor;if(c!==1||!a||!a[0])return new h(!c||c<0&&(!a||a[0])?NaN:a?o:1/0);for(S=!1,c=Math.sqrt(+o),c==0||c==1/0?(n=H(a),(n.length+l)%2==0&&(n+="0"),c=Math.sqrt(n),l=T((l+1)/2)-(l<0||l%2),c==1/0?n="5e"+l:(n=c.toExponential(),n=n.slice(0,n.indexOf("e")+1)+l),e=new h(n)):e=new h(c.toString()),t=(l=h.precision)+3;;)if(s=e,e=s.plus(k(o,s,t+2,1)).times(.5),H(s.d).slice(0,t)===(n=H(e.d)).slice(0,t))if(n=n.slice(t-3,t+1),n=="9999"||!i&&n=="4999"){if(!i&&(x(s,l+1,0),s.times(s).eq(o))){e=s;break}t+=4,i=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(x(e,l+1,1),r=!e.times(e).eq(o));break}return S=!0,x(e,l,h.rounding,r)};y.tangent=y.tan=function(){var r,n,t=this,e=t.constructor;return t.isFinite()?t.isZero()?new e(t):(r=e.precision,n=e.rounding,e.precision=r+10,e.rounding=1,t=t.sin(),t.s=1,t=k(t,new e(1).minus(t.times(t)).sqrt(),r+10,0),e.precision=r,e.rounding=n,x(nt==2||nt==4?t.neg():t,r,n,!0)):new e(NaN)};y.times=y.mul=function(r){var n,t,e,i,s,o,a,l,c,h=this,u=h.constructor,d=h.d,m=(r=new u(r)).d;if(r.s*=h.s,!d||!d[0]||!m||!m[0])return new u(!r.s||d&&!d[0]&&!m||m&&!m[0]&&!d?NaN:!d||!m?r.s/0:r.s*0);for(t=T(h.e/b)+T(r.e/b),l=d.length,c=m.length,l<c&&(s=d,d=m,m=s,o=l,l=c,c=o),s=[],o=l+c,e=o;e--;)s.push(0);for(e=c;--e>=0;){for(n=0,i=l+e;i>e;)a=s[i]+m[e]*d[i-e-1]+n,s[i--]=a%$|0,n=a/$|0;s[i]=(s[i]+n)%$|0}for(;!s[--o];)s.pop();return n?++t:s.shift(),r.d=s,r.e=se(s,t),S?x(r,u.precision,u.rounding):r};y.toBinary=function(r,n){return Pe(this,2,r,n)};y.toDecimalPlaces=y.toDP=function(r,n){var t=this,e=t.constructor;return t=new e(t),r===void 0?t:(U(r,0,ut),n===void 0?n=e.rounding:U(n,0,8),x(t,r+t.e+1,n))};y.toExponential=function(r,n){var t,e=this,i=e.constructor;return r===void 0?t=K(e,!0):(U(r,0,ut),n===void 0?n=i.rounding:U(n,0,8),e=x(new i(e),r+1,n),t=K(e,!0,r+1)),e.isNeg()&&!e.isZero()?"-"+t:t};y.toFixed=function(r,n){var t,e,i=this,s=i.constructor;return r===void 0?t=K(i):(U(r,0,ut),n===void 0?n=s.rounding:U(n,0,8),e=x(new s(i),r+i.e+1,n),t=K(e,!1,r+e.e+1)),i.isNeg()&&!i.isZero()?"-"+t:t};y.toFraction=function(r){var n,t,e,i,s,o,a,l,c,h,u,d,m=this,g=m.d,p=m.constructor;if(!g)return new p(m);if(c=t=new p(1),e=l=new p(0),n=new p(e),s=n.e=Ge(g)-m.e-1,o=s%b,n.d[0]=I(10,o<0?b+o:o),r==null)r=s>0?n:c;else{if(a=new p(r),!a.isInt()||a.lt(c))throw Error(ht+a);r=a.gt(n)?s>0?n:c:a}for(S=!1,a=new p(H(g)),h=p.precision,p.precision=s=g.length*b*2;u=k(a,n,0,1,1),i=t.plus(u.times(e)),i.cmp(r)!=1;)t=e,e=i,i=c,c=l.plus(u.times(i)),l=i,i=n,n=a.minus(u.times(i)),a=i;return i=k(r.minus(t),e,0,1,1),l=l.plus(i.times(c)),t=t.plus(i.times(e)),l.s=c.s=m.s,d=k(c,e,s,1).minus(m).abs().cmp(k(l,t,s,1).minus(m).abs())<1?[c,e]:[l,t],p.precision=h,S=!0,d};y.toHexadecimal=y.toHex=function(r,n){return Pe(this,16,r,n)};y.toNearest=function(r,n){var t=this,e=t.constructor;if(t=new e(t),r==null){if(!t.d)return t;r=new e(1),n=e.rounding}else{if(r=new e(r),n===void 0?n=e.rounding:U(n,0,8),!t.d)return r.s?t:r;if(!r.d)return r.s&&(r.s=t.s),r}return r.d[0]?(S=!1,t=k(t,r,0,n,1).times(r),S=!0,x(t)):(r.s=t.s,t=r),t};y.toNumber=function(){return+this};y.toOctal=function(r,n){return Pe(this,8,r,n)};y.toPower=y.pow=function(r){var n,t,e,i,s,o,a=this,l=a.constructor,c=+(r=new l(r));if(!a.d||!r.d||!a.d[0]||!r.d[0])return new l(I(+a,c));if(a=new l(a),a.eq(1))return a;if(e=l.precision,s=l.rounding,r.eq(1))return x(a,e,s);if(n=T(r.e/b),n>=r.d.length-1&&(t=c<0?-c:c)<=Ai)return i=Xe(l,a,t,e),r.s<0?new l(1).div(i):x(i,e,s);if(o=a.s,o<0){if(n<r.d.length-1)return new l(NaN);if(r.d[n]&1||(o=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=o,a}return t=I(+a,c),n=t==0||!isFinite(t)?T(c*(Math.log("0."+H(a.d))/Math.LN10+a.e+1)):new l(t+"").e,n>l.maxE+1||n<l.minE-1?new l(n>0?o/0:0):(S=!1,l.rounding=a.s=1,t=Math.min(12,(n+"").length),i=me(r.times(at(a,e+t)),e),i.d&&(i=x(i,e+5,1),Ot(i.d,e,s)&&(n=e+10,i=x(me(r.times(at(a,n+t)),n),n+5,1),+H(i.d).slice(e+1,e+15)+1==1e14&&(i=x(i,e+1,0)))),i.s=o,S=!0,l.rounding=s,x(i,e,s))};y.toPrecision=function(r,n){var t,e=this,i=e.constructor;return r===void 0?t=K(e,e.e<=i.toExpNeg||e.e>=i.toExpPos):(U(r,1,ut),n===void 0?n=i.rounding:U(n,0,8),e=x(new i(e),r,n),t=K(e,r<=e.e||e.e<=i.toExpNeg,r)),e.isNeg()&&!e.isZero()?"-"+t:t};y.toSignificantDigits=y.toSD=function(r,n){var t=this,e=t.constructor;return r===void 0?(r=e.precision,n=e.rounding):(U(r,1,ut),n===void 0?n=e.rounding:U(n,0,8)),x(new e(t),r,n)};y.toString=function(){var r=this,n=r.constructor,t=K(r,r.e<=n.toExpNeg||r.e>=n.toExpPos);return r.isNeg()&&!r.isZero()?"-"+t:t};y.truncated=y.trunc=function(){return x(new this.constructor(this),this.e+1,1)};y.valueOf=y.toJSON=function(){var r=this,n=r.constructor,t=K(r,r.e<=n.toExpNeg||r.e>=n.toExpPos);return r.isNeg()?"-"+t:t};function H(r){var n,t,e,i=r.length-1,s="",o=r[0];if(i>0){for(s+=o,n=1;n<i;n++)e=r[n]+"",t=b-e.length,t&&(s+=ot(t)),s+=e;o=r[n],e=o+"",t=b-e.length,t&&(s+=ot(t))}else if(o===0)return"0";for(;o%10===0;)o/=10;return s+o}function U(r,n,t){if(r!==~~r||r<n||r>t)throw Error(ht+r)}function Ot(r,n,t,e){var i,s,o,a;for(s=r[0];s>=10;s/=10)--n;return--n<0?(n+=b,i=0):(i=Math.ceil((n+1)/b),n%=b),s=I(10,b-n),a=r[i]%s|0,e==null?n<3?(n==0?a=a/100|0:n==1&&(a=a/10|0),o=t<4&&a==99999||t>3&&a==49999||a==5e4||a==0):o=(t<4&&a+1==s||t>3&&a+1==s/2)&&(r[i+1]/s/100|0)==I(10,n-2)-1||(a==s/2||a==0)&&(r[i+1]/s/100|0)==0:n<4?(n==0?a=a/1e3|0:n==1?a=a/100|0:n==2&&(a=a/10|0),o=(e||t<4)&&a==9999||!e&&t>3&&a==4999):o=((e||t<4)&&a+1==s||!e&&t>3&&a+1==s/2)&&(r[i+1]/s/1e3|0)==I(10,n-3)-1,o}function Bt(r,n,t){for(var e,i=[0],s,o=0,a=r.length;o<a;){for(s=i.length;s--;)i[s]*=n;for(i[0]+=ue.indexOf(r.charAt(o++)),e=0;e<i.length;e++)i[e]>t-1&&(i[e+1]===void 0&&(i[e+1]=0),i[e+1]+=i[e]/t|0,i[e]%=t)}return i.reverse()}function Hi(r,n){var t,e,i;if(n.isZero())return n;e=n.d.length,e<32?(t=Math.ceil(e/3),i=(1/ne(4,t)).toString()):(t=16,i="2.3283064365386962890625e-10"),r.precision+=t,n=Dt(r,1,n.times(i),new r(1));for(var s=t;s--;){var o=n.times(n);n=o.times(o).minus(o).times(8).plus(1)}return r.precision-=t,n}var k=function(){function r(e,i,s){var o,a=0,l=e.length;for(e=e.slice();l--;)o=e[l]*i+a,e[l]=o%s|0,a=o/s|0;return a&&e.unshift(a),e}function n(e,i,s,o){var a,l;if(s!=o)l=s>o?1:-1;else for(a=l=0;a<s;a++)if(e[a]!=i[a]){l=e[a]>i[a]?1:-1;break}return l}function t(e,i,s,o){for(var a=0;s--;)e[s]-=a,a=e[s]<i[s]?1:0,e[s]=a*o+e[s]-i[s];for(;!e[0]&&e.length>1;)e.shift()}return function(e,i,s,o,a,l){var c,h,u,d,m,g,p,v,w,_,C,E,N,G,At,dt,rt,vt,X,It,Ht=e.constructor,oe=e.s==i.s?1:-1,L=e.d,M=i.d;if(!L||!L[0]||!M||!M[0])return new Ht(!e.s||!i.s||(L?M&&L[0]==M[0]:!M)?NaN:L&&L[0]==0||!M?oe*0:oe/0);for(l?(m=1,h=e.e-i.e):(l=$,m=b,h=T(e.e/m)-T(i.e/m)),X=M.length,rt=L.length,w=new Ht(oe),_=w.d=[],u=0;M[u]==(L[u]||0);u++);if(M[u]>(L[u]||0)&&h--,s==null?(G=s=Ht.precision,o=Ht.rounding):a?G=s+(e.e-i.e)+1:G=s,G<0)_.push(1),g=!0;else{if(G=G/m+2|0,u=0,X==1){for(d=0,M=M[0],G++;(u<rt||d)&&G--;u++)At=d*l+(L[u]||0),_[u]=At/M|0,d=At%M|0;g=d||u<rt}else{for(d=l/(M[0]+1)|0,d>1&&(M=r(M,d,l),L=r(L,d,l),X=M.length,rt=L.length),dt=X,C=L.slice(0,X),E=C.length;E<X;)C[E++]=0;It=M.slice(),It.unshift(0),vt=M[0],M[1]>=l/2&&++vt;do d=0,c=n(M,C,X,E),c<0?(N=C[0],X!=E&&(N=N*l+(C[1]||0)),d=N/vt|0,d>1?(d>=l&&(d=l-1),p=r(M,d,l),v=p.length,E=C.length,c=n(p,C,v,E),c==1&&(d--,t(p,X<v?It:M,v,l))):(d==0&&(c=d=1),p=M.slice()),v=p.length,v<E&&p.unshift(0),t(C,p,E,l),c==-1&&(E=C.length,c=n(M,C,X,E),c<1&&(d++,t(C,X<E?It:M,E,l))),E=C.length):c===0&&(d++,C=[0]),_[u++]=d,c&&C[0]?C[E++]=L[dt]||0:(C=[L[dt]],E=1);while((dt++<rt||C[0]!==void 0)&&G--);g=C[0]!==void 0}_[0]||_.shift()}if(m==1)w.e=h,Le=g;else{for(u=1,d=_[0];d>=10;d/=10)u++;w.e=u+h*m-1,x(w,a?s+w.e+1:s,o,g)}return w}}();function x(r,n,t,e){var i,s,o,a,l,c,h,u,d,m=r.constructor;t:if(n!=null){if(u=r.d,!u)return r;for(i=1,a=u[0];a>=10;a/=10)i++;if(s=n-i,s<0)s+=b,o=n,h=u[d=0],l=h/I(10,i-o-1)%10|0;else if(d=Math.ceil((s+1)/b),a=u.length,d>=a)if(e){for(;a++<=d;)u.push(0);h=l=0,i=1,s%=b,o=s-b+1}else break t;else{for(h=a=u[d],i=1;a>=10;a/=10)i++;s%=b,o=s-b+i,l=o<0?0:h/I(10,i-o-1)%10|0}if(e=e||n<0||u[d+1]!==void 0||(o<0?h:h%I(10,i-o-1)),c=t<4?(l||e)&&(t==0||t==(r.s<0?3:2)):l>5||l==5&&(t==4||e||t==6&&(s>0?o>0?h/I(10,i-o):0:u[d-1])%10&1||t==(r.s<0?8:7)),n<1||!u[0])return u.length=0,c?(n-=r.e+1,u[0]=I(10,(b-n%b)%b),r.e=-n||0):u[0]=r.e=0,r;if(s==0?(u.length=d,a=1,d--):(u.length=d+1,a=I(10,b-s),u[d]=o>0?(h/I(10,i-o)%I(10,o)|0)*a:0),c)for(;;)if(d==0){for(s=1,o=u[0];o>=10;o/=10)s++;for(o=u[0]+=a,a=1;o>=10;o/=10)a++;s!=a&&(r.e++,u[0]==$&&(u[0]=1));break}else{if(u[d]+=a,u[d]!=$)break;u[d--]=0,a=1}for(s=u.length;u[--s]===0;)u.pop()}return S&&(r.e>m.maxE?(r.d=null,r.e=NaN):r.e<m.minE&&(r.e=0,r.d=[0])),r}function K(r,n,t){if(!r.isFinite())return ze(r);var e,i=r.e,s=H(r.d),o=s.length;return n?(t&&(e=t-o)>0?s=s.charAt(0)+"."+s.slice(1)+ot(e):o>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(r.e<0?"e":"e+")+r.e):i<0?(s="0."+ot(-i-1)+s,t&&(e=t-o)>0&&(s+=ot(e))):i>=o?(s+=ot(i+1-o),t&&(e=t-i-1)>0&&(s=s+"."+ot(e))):((e=i+1)<o&&(s=s.slice(0,e)+"."+s.slice(e)),t&&(e=t-o)>0&&(i+1===o&&(s+="."),s+=ot(e))),s}function se(r,n){var t=r[0];for(n*=b;t>=10;t/=10)n++;return n}function Jt(r,n,t){if(n>Ii)throw S=!0,t&&(r.precision=t),Error(Te);return x(new r(Zt),n,1,!0)}function J(r,n,t){if(n>fe)throw Error(Te);return x(new r(Qt),n,t,!0)}function Ge(r){var n=r.length-1,t=n*b+1;if(n=r[n],n){for(;n%10==0;n/=10)t--;for(n=r[0];n>=10;n/=10)t++}return t}function ot(r){for(var n="";r--;)n+="0";return n}function Xe(r,n,t,e){var i,s=new r(1),o=Math.ceil(e/b+4);for(S=!1;;){if(t%2&&(s=s.times(n),Ee(s.d,o)&&(i=!0)),t=T(t/2),t===0){t=s.d.length-1,i&&s.d[t]===0&&++s.d[t];break}n=n.times(n),Ee(n.d,o)}return S=!0,s}function Se(r){return r.d[r.d.length-1]&1}function Ye(r,n,t){for(var e,i,s=new r(n[0]),o=0;++o<n.length;){if(i=new r(n[o]),!i.s){s=i;break}e=s.cmp(i),(e===t||e===0&&s.s===t)&&(s=i)}return s}function me(r,n){var t,e,i,s,o,a,l,c=0,h=0,u=0,d=r.constructor,m=d.rounding,g=d.precision;if(!r.d||!r.d[0]||r.e>17)return new d(r.d?r.d[0]?r.s<0?0:1/0:1:r.s?r.s<0?0:r:NaN);for(n==null?(S=!1,l=g):l=n,a=new d(.03125);r.e>-2;)r=r.times(a),u+=5;for(e=Math.log(I(2,u))/Math.LN10*2+5|0,l+=e,t=s=o=new d(1),d.precision=l;;){if(s=x(s.times(r),l,1),t=t.times(++h),a=o.plus(k(s,t,l,1)),H(a.d).slice(0,l)===H(o.d).slice(0,l)){for(i=u;i--;)o=x(o.times(o),l,1);if(n==null)if(c<3&&Ot(o.d,l-e,m,c))d.precision=l+=10,t=s=a=new d(1),h=0,c++;else return x(o,d.precision=g,m,S=!0);else return d.precision=g,o}o=a}}function at(r,n){var t,e,i,s,o,a,l,c,h,u,d,m=1,g=10,p=r,v=p.d,w=p.constructor,_=w.rounding,C=w.precision;if(p.s<0||!v||!v[0]||!p.e&&v[0]==1&&v.length==1)return new w(v&&!v[0]?-1/0:p.s!=1?NaN:v?0:p);if(n==null?(S=!1,h=C):h=n,w.precision=h+=g,t=H(v),e=t.charAt(0),Math.abs(s=p.e)<15e14){for(;e<7&&e!=1||e==1&&t.charAt(1)>3;)p=p.times(r),t=H(p.d),e=t.charAt(0),m++;s=p.e,e>1?(p=new w("0."+t),s++):p=new w(e+"."+t.slice(1))}else return c=Jt(w,h+2,C).times(s+""),p=at(new w(e+"."+t.slice(1)),h-g).plus(c),w.precision=C,n==null?x(p,C,_,S=!0):p;for(u=p,l=o=p=k(p.minus(1),p.plus(1),h,1),d=x(p.times(p),h,1),i=3;;){if(o=x(o.times(d),h,1),c=l.plus(k(o,new w(i),h,1)),H(c.d).slice(0,h)===H(l.d).slice(0,h))if(l=l.times(2),s!==0&&(l=l.plus(Jt(w,h+2,C).times(s+""))),l=k(l,new w(m),h,1),n==null)if(Ot(l.d,h-g,_,a))w.precision=h+=g,c=o=p=k(u.minus(1),u.plus(1),h,1),d=x(p.times(p),h,1),i=a=1;else return x(l,w.precision=C,_,S=!0);else return w.precision=C,l;l=c,i+=2}}function ze(r){return String(r.s*r.s/0)}function Ut(r,n){var t,e,i;for((t=n.indexOf("."))>-1&&(n=n.replace(".","")),(e=n.search(/e/i))>0?(t<0&&(t=e),t+=+n.slice(e+1),n=n.substring(0,e)):t<0&&(t=n.length),e=0;n.charCodeAt(e)===48;e++);for(i=n.length;n.charCodeAt(i-1)===48;--i);if(n=n.slice(e,i),n){if(i-=e,r.e=t=t-e-1,r.d=[],e=(t+1)%b,t<0&&(e+=b),e<i){for(e&&r.d.push(+n.slice(0,e)),i-=b;e<i;)r.d.push(+n.slice(e,e+=b));n=n.slice(e),e=b-n.length}else e-=i;for(;e--;)n+="0";r.d.push(+n),S&&(r.e>r.constructor.maxE?(r.d=null,r.e=NaN):r.e<r.constructor.minE&&(r.e=0,r.d=[0]))}else r.e=0,r.d=[0];return r}function Li(r,n){var t,e,i,s,o,a,l,c,h;if(n.indexOf("_")>-1){if(n=n.replace(/(\d)_(?=\d)/g,"$1"),Ue.test(n))return Ut(r,n)}else if(n==="Infinity"||n==="NaN")return+n||(r.s=NaN),r.e=NaN,r.d=null,r;if(Oi.test(n))t=16,n=n.toLowerCase();else if(Mi.test(n))t=2;else if(Ni.test(n))t=8;else throw Error(ht+n);for(s=n.search(/p/i),s>0?(l=+n.slice(s+1),n=n.substring(2,s)):n=n.slice(2),s=n.indexOf("."),o=s>=0,e=r.constructor,o&&(n=n.replace(".",""),a=n.length,s=a-s,i=Xe(e,new e(t),s,s*2)),c=Bt(n,t,$),h=c.length-1,s=h;c[s]===0;--s)c.pop();return s<0?new e(r.s*0):(r.e=se(c,h),r.d=c,S=!1,o&&(r=k(r,i,a*4)),l&&(r=r.times(Math.abs(l)<54?I(2,l):V.pow(2,l))),S=!0,r)}function Ti(r,n){var t,e=n.d.length;if(e<3)return n.isZero()?n:Dt(r,2,n,n);t=1.4*Math.sqrt(e),t=t>16?16:t|0,n=n.times(1/ne(5,t)),n=Dt(r,2,n,n);for(var i,s=new r(5),o=new r(16),a=new r(20);t--;)i=n.times(n),n=n.times(s.plus(i.times(o.times(i).minus(a))));return n}function Dt(r,n,t,e,i){var s,o,a,l,c=r.precision,h=Math.ceil(c/b);for(S=!1,l=t.times(t),a=new r(e);;){if(o=k(a.times(l),new r(n++*n++),c,1),a=i?e.plus(o):e.minus(o),e=k(o.times(l),new r(n++*n++),c,1),o=a.plus(e),o.d[h]!==void 0){for(s=h;o.d[s]===a.d[s]&&s--;);if(s==-1)break}s=a,a=e,e=o,o=s}return S=!0,o.d.length=h+1,o}function ne(r,n){for(var t=r;--n;)t*=r;return t}function We(r,n){var t,e=n.s<0,i=J(r,r.precision,1),s=i.times(.5);if(n=n.abs(),n.lte(s))return nt=e?4:1,n;if(t=n.divToInt(i),t.isZero())nt=e?3:2;else{if(n=n.minus(t.times(i)),n.lte(s))return nt=Se(t)?e?2:3:e?4:1,n;nt=Se(t)?e?1:4:e?3:2}return n.minus(i).abs()}function Pe(r,n,t,e){var i,s,o,a,l,c,h,u,d,m=r.constructor,g=t!==void 0;if(g?(U(t,1,ut),e===void 0?e=m.rounding:U(e,0,8)):(t=m.precision,e=m.rounding),!r.isFinite())h=ze(r);else{for(h=K(r),o=h.indexOf("."),g?(i=2,n==16?t=t*4-3:n==8&&(t=t*3-2)):i=n,o>=0&&(h=h.replace(".",""),d=new m(1),d.e=h.length-o,d.d=Bt(K(d),10,i),d.e=d.d.length),u=Bt(h,10,i),s=l=u.length;u[--l]==0;)u.pop();if(!u[0])h=g?"0p+0":"0";else{if(o<0?s--:(r=new m(r),r.d=u,r.e=s,r=k(r,d,t,e,0,i),u=r.d,s=r.e,c=Le),o=u[t],a=i/2,c=c||u[t+1]!==void 0,c=e<4?(o!==void 0||c)&&(e===0||e===(r.s<0?3:2)):o>a||o===a&&(e===4||c||e===6&&u[t-1]&1||e===(r.s<0?8:7)),u.length=t,c)for(;++u[--t]>i-1;)u[t]=0,t||(++s,u.unshift(1));for(l=u.length;!u[l-1];--l);for(o=0,h="";o<l;o++)h+=ue.charAt(u[o]);if(g){if(l>1)if(n==16||n==8){for(o=n==16?4:3,--l;l%o;l++)h+="0";for(u=Bt(h,i,n),l=u.length;!u[l-1];--l);for(o=1,h="1.";o<l;o++)h+=ue.charAt(u[o])}else h=h.charAt(0)+"."+h.slice(1);h=h+(s<0?"p":"p+")+s}else if(s<0){for(;++s;)h="0"+h;h="0."+h}else if(++s>l)for(s-=l;s--;)h+="0";else s<l&&(h=h.slice(0,s)+"."+h.slice(s))}h=(n==16?"0x":n==2?"0b":n==8?"0o":"")+h}return r.s<0?"-"+h:h}function Ee(r,n){if(r.length>n)return r.length=n,!0}function Fi(r){return new this(r).abs()}function Bi(r){return new this(r).acos()}function Ui(r){return new this(r).acosh()}function Gi(r,n){return new this(r).plus(n)}function Xi(r){return new this(r).asin()}function Yi(r){return new this(r).asinh()}function zi(r){return new this(r).atan()}function Wi(r){return new this(r).atanh()}function ji(r,n){r=new this(r),n=new this(n);var t,e=this.precision,i=this.rounding,s=e+4;return!r.s||!n.s?t=new this(NaN):!r.d&&!n.d?(t=J(this,s,1).times(n.s>0?.25:.75),t.s=r.s):!n.d||r.isZero()?(t=n.s<0?J(this,e,i):new this(0),t.s=r.s):!r.d||n.isZero()?(t=J(this,s,1).times(.5),t.s=r.s):n.s<0?(this.precision=s,this.rounding=1,t=this.atan(k(r,n,s,1)),n=J(this,s,1),this.precision=e,this.rounding=i,t=r.s<0?t.minus(n):t.plus(n)):t=this.atan(k(r,n,s,1)),t}function qi(r){return new this(r).cbrt()}function $i(r){return x(r=new this(r),r.e+1,2)}function Zi(r,n,t){return new this(r).clamp(n,t)}function Qi(r){if(!r||typeof r!="object")throw Error(ie+"Object expected");var n,t,e,i=r.defaults===!0,s=["precision",1,ut,"rounding",0,8,"toExpNeg",-9e15,0,"toExpPos",0,he,"maxE",0,he,"minE",-9e15,0,"modulo",0,9];for(n=0;n<s.length;n+=3)if(t=s[n],i&&(this[t]=de[t]),(e=r[t])!==void 0)if(T(e)===e&&e>=s[n+1]&&e<=s[n+2])this[t]=e;else throw Error(ht+t+": "+e);if(t="crypto",i&&(this[t]=de[t]),(e=r[t])!==void 0)if(e===!0||e===!1||e===0||e===1)if(e)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[t]=!0;else throw Error(Fe);else this[t]=!1;else throw Error(ht+t+": "+e);return this}function Ji(r){return new this(r).cos()}function Ki(r){return new this(r).cosh()}function je(r){var n,t,e;function i(s){var o,a,l,c=this;if(!(c instanceof i))return new i(s);if(c.constructor=i,De(s)){c.s=s.s,S?!s.d||s.e>i.maxE?(c.e=NaN,c.d=null):s.e<i.minE?(c.e=0,c.d=[0]):(c.e=s.e,c.d=s.d.slice()):(c.e=s.e,c.d=s.d?s.d.slice():s.d);return}if(l=typeof s,l==="number"){if(s===0){c.s=1/s<0?-1:1,c.e=0,c.d=[0];return}if(s<0?(s=-s,c.s=-1):c.s=1,s===~~s&&s<1e7){for(o=0,a=s;a>=10;a/=10)o++;S?o>i.maxE?(c.e=NaN,c.d=null):o<i.minE?(c.e=0,c.d=[0]):(c.e=o,c.d=[s]):(c.e=o,c.d=[s]);return}if(s*0!==0){s||(c.s=NaN),c.e=NaN,c.d=null;return}return Ut(c,s.toString())}if(l==="string")return(a=s.charCodeAt(0))===45?(s=s.slice(1),c.s=-1):(a===43&&(s=s.slice(1)),c.s=1),Ue.test(s)?Ut(c,s):Li(c,s);if(l==="bigint")return s<0?(s=-s,c.s=-1):c.s=1,Ut(c,s.toString());throw Error(ht+s)}if(i.prototype=y,i.ROUND_UP=0,i.ROUND_DOWN=1,i.ROUND_CEIL=2,i.ROUND_FLOOR=3,i.ROUND_HALF_UP=4,i.ROUND_HALF_DOWN=5,i.ROUND_HALF_EVEN=6,i.ROUND_HALF_CEIL=7,i.ROUND_HALF_FLOOR=8,i.EUCLID=9,i.config=i.set=Qi,i.clone=je,i.isDecimal=De,i.abs=Fi,i.acos=Bi,i.acosh=Ui,i.add=Gi,i.asin=Xi,i.asinh=Yi,i.atan=zi,i.atanh=Wi,i.atan2=ji,i.cbrt=qi,i.ceil=$i,i.clamp=Zi,i.cos=Ji,i.cosh=Ki,i.div=ts,i.exp=es,i.floor=is,i.hypot=ss,i.ln=ns,i.log=rs,i.log10=as,i.log2=os,i.max=ls,i.min=cs,i.mod=hs,i.mul=us,i.pow=ds,i.random=fs,i.round=ms,i.sign=ps,i.sin=gs,i.sinh=ys,i.sqrt=vs,i.sub=ws,i.sum=Ps,i.tan=xs,i.tanh=bs,i.trunc=_s,r===void 0&&(r={}),r&&r.defaults!==!0)for(e=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],n=0;n<e.length;)r.hasOwnProperty(t=e[n++])||(r[t]=this[t]);return i.config(r),i}function ts(r,n){return new this(r).div(n)}function es(r){return new this(r).exp()}function is(r){return x(r=new this(r),r.e+1,3)}function ss(){var r,n,t=new this(0);for(S=!1,r=0;r<arguments.length;)if(n=new this(arguments[r++]),n.d)t.d&&(t=t.plus(n.times(n)));else{if(n.s)return S=!0,new this(1/0);t=n}return S=!0,t.sqrt()}function De(r){return r instanceof V||r&&r.toStringTag===Be||!1}function ns(r){return new this(r).ln()}function rs(r,n){return new this(r).log(n)}function os(r){return new this(r).log(2)}function as(r){return new this(r).log(10)}function ls(){return Ye(this,arguments,-1)}function cs(){return Ye(this,arguments,1)}function hs(r,n){return new this(r).mod(n)}function us(r,n){return new this(r).mul(n)}function ds(r,n){return new this(r).pow(n)}function fs(r){var n,t,e,i,s=0,o=new this(1),a=[];if(r===void 0?r=this.precision:U(r,1,ut),e=Math.ceil(r/b),this.crypto)if(crypto.getRandomValues)for(n=crypto.getRandomValues(new Uint32Array(e));s<e;)i=n[s],i>=429e7?n[s]=crypto.getRandomValues(new Uint32Array(1))[0]:a[s++]=i%1e7;else if(crypto.randomBytes){for(n=crypto.randomBytes(e*=4);s<e;)i=n[s]+(n[s+1]<<8)+(n[s+2]<<16)+((n[s+3]&127)<<24),i>=214e7?crypto.randomBytes(4).copy(n,s):(a.push(i%1e7),s+=4);s=e/4}else throw Error(Fe);else for(;s<e;)a[s++]=Math.random()*1e7|0;for(e=a[--s],r%=b,e&&r&&(i=I(10,b-r),a[s]=(e/i|0)*i);a[s]===0;s--)a.pop();if(s<0)t=0,a=[0];else{for(t=-1;a[0]===0;t-=b)a.shift();for(e=1,i=a[0];i>=10;i/=10)e++;e<b&&(t-=b-e)}return o.e=t,o.d=a,o}function ms(r){return x(r=new this(r),r.e+1,this.rounding)}function ps(r){return r=new this(r),r.d?r.d[0]?r.s:0*r.s:r.s||NaN}function gs(r){return new this(r).sin()}function ys(r){return new this(r).sinh()}function vs(r){return new this(r).sqrt()}function ws(r,n){return new this(r).sub(n)}function Ps(){var r=0,n=arguments,t=new this(n[r]);for(S=!1;t.s&&++r<n.length;)t=t.plus(n[r]);return S=!0,x(t,this.precision,this.rounding)}function xs(r){return new this(r).tan()}function bs(r){return new this(r).tanh()}function _s(r){return x(r=new this(r),r.e+1,1)}y[Symbol.for("nodejs.util.inspect.custom")]=y.toString;y[Symbol.toStringTag]="Decimal";var V=y.constructor=je(de);Zt=new V(Zt);Qt=new V(Qt);class Cs{constructor(){f(this,"parent");f(this,"name","");f(this,"extData");f(this,"mainCanvas");f(this,"_isRecalculate",!1);f(this,"notifyReload")}get isRecalculate(){return(this.parent?this.parent.isRecalculate:!1)||this._isRecalculate}set isRecalculate(n){this._isRecalculate=n}equalsMainCanvas(n){return this.mainCanvas===n}setMainCanvas(n){this.mainCanvas=n}}class Ss extends Cs{constructor(){super(...arguments);f(this,"_isVisible",!0);f(this,"inheritOpacity",!0);f(this,"_opacity");f(this,"_scaleRange")}get isVisible(){return this._isVisible}set isVisible(t){var e;t!=this.isVisible&&(this._isVisible=t,(e=this.notifyReload)==null||e.call(this,!0))}get opacity(){var t;return this.inheritOpacity?this._opacity??((t=this.parent)==null?void 0:t.opacity):this._opacity}set opacity(t){var e;this._opacity!=t&&(t===void 0||t>=0&&t<=1?(this._opacity=t,(e=this.notifyReload)==null||e.call(this,!1)):console.warn("Opacity value should be between 0 and 1."))}get scaleRange(){return this._scaleRange}set scaleRange(t){var e;t!=this.scaleRange&&(this._scaleRange=t,this.isVisible&&((e=this.notifyReload)==null||e.call(this)))}shouldRender(){var e;if(!this.isVisible||this.opacity===0)return!1;const t=(e=this.mainCanvas)==null?void 0:e.scale;if(this.scaleRange&&t){const i=Math.min(...this.scaleRange),s=Math.max(...this.scaleRange);return t>=i&&t<=s}return!0}}let Es=class extends Ss{constructor(n){super(),n.name=n.name||$t("default-name-"),Object.assign(this,{...n})}};class Ds extends Es{constructor(t){super(t);f(this,"_isInteractive",!0);f(this,"_isHoverable",!0);f(this,"_isDownable",!0);f(this,"_isContextmenuable",!0);f(this,"_isClickable",!0);f(this,"_isDoubleClickable",!0);f(this,"_isDraggable",!0);f(this,"_isWheelable",!0);Object.assign(this,{...t})}get isInteractive(){return this.getPropValue("isInteractive",this._isInteractive,!1)}set isInteractive(t){this._isInteractive=t}get isHoverable(){return this.getPropValue("isHoverable",this._isHoverable)}set isHoverable(t){this._isHoverable=t}get isDownable(){return this.getPropValue("isDownable",this._isDownable)}set isDownable(t){this._isDownable=t}get isContextmenuable(){return this.getPropValue("isContextmenuable",this._isContextmenuable)}set isContextmenuable(t){this._isContextmenuable=t}get isClickable(){return this.getPropValue("isClickable",this._isClickable)}set isClickable(t){this._isClickable=t}get isDoubleClickable(){return this.getPropValue("isDoubleClickable",this._isDoubleClickable)}set isDoubleClickable(t){this._isDoubleClickable=t}get isDraggable(){return this.getPropValue("isDraggable",this._isDraggable)}set isDraggable(t){this._isDraggable=t}get isWheelable(){return this.getPropValue("isWheelable",this._isWheelable)}set isWheelable(t){this._isWheelable=t}getPropValue(t,e,i=!0){return(this.parent?this.parent[t]:!0)&&e&&(i?this.isInteractive:!0)}}class Vs{constructor(n){f(this,"propagationStopped",!1);this.data=n}stopPropagation(){this.propagationStopped=!0}get canPropagate(){return!this.propagationStopped}}class Nt extends Ds{constructor(){super(...arguments);f(this,"listeners",{wheel:new Set,hover:new Set,down:new Set,contextmenu:new Set,click:new Set,doubleClick:new Set,dragg:new Set});f(this,"sharedControllers",{});f(this,"_eventDate",{});f(this,"_clearEventDate",!1);f(this,"_isHover",!1);f(this,"notifyHover",(t,e)=>this.checkEventDate("hover",t)&&this.trigger("hover",{state:t,oldState:this.isHover},e,"isHoverable"));f(this,"_isDown",!1);f(this,"notifyDown",(t,e)=>this.checkEventDate("down",t)&&this.trigger("down",{state:t,oldState:this.isDown},e,"isDownable"));f(this,"_isContextmenu",!1);f(this,"notifyContextmenu",(t,e)=>this.checkEventDate("contextmenu",t)&&this.trigger("contextmenu",{state:t,oldState:this.isContextmenu},e,"isContextmenuable"));f(this,"_isClick",!1);f(this,"clickTimestamp",0);f(this,"doubleClickInterval",300);f(this,"notifyClick",(t,e)=>{if(!this.checkEventDate("click",t))return;let i=!1;t?(i=Date.now()-this.clickTimestamp<this.doubleClickInterval,this.clickTimestamp=i?0:Date.now()):(this._isDblClick=!1,this.clickTimestamp=0),i?this.notifyDoubleClick(i,e):this.trigger("click",{state:t,oldState:this.isClick},e,"isClickable")});f(this,"_isDblClick",!1);f(this,"notifyDoubleClick",(t,e)=>this.checkEventDate("doubleClick",t)&&this.trigger("doubleClick",{state:t,oldState:this.isDblClick},e,"isDoubleClickable"));f(this,"notifyDragg",(t,e)=>this.checkEventDate("dragg",t)&&this.trigger("dragg",t,e,"isDraggable"));f(this,"notifyWheel",(t,e)=>this.checkEventDate("wheel",t)&&this.trigger("wheel",t,e,"isWheelable"))}addEventListener(t,e){this.listeners[t].add(e)}removeEventListener(t,e){this.listeners[t].delete(e)}registerControllers(t,e){this.sharedControllers[t]=e}hasController(t,e){var i;return(i=this.sharedControllers[t])==null?void 0:i.includes(e)}trigger(t,e,i,s){var c,h;if(!this[s])return;this.updateStates(t,e);const o=new Vs(e);this.listeners[t].forEach(u=>u(o,i));const a="notify"+(t.charAt(0).toUpperCase()+t.slice(1)),l=["notifyDragg","notifyWheel"].includes(a)?e:e.state;o.canPropagate&&((c=this.parent)==null||c[a](l,i)),(h=this.sharedControllers[t])==null||h.forEach(u=>u!==this&&u[a](l,i))}updateStates(t,e){const i=e;switch(t){case"hover":this._isHover=i.state;break;case"down":this._isDown=i.state;break;case"contextmenu":this._isContextmenu=i.state;break;case"click":this._isClick=i.state;break;case"doubleClick":this._isDblClick=i.state;break}}checkEventDate(t,e){const i=this._eventDate[t],s=JSON.stringify(e);return i==s?!1:(this._eventDate[t]=s,this._clearEventDate||(this._clearEventDate=!0,Promise.resolve().then(()=>{this._clearEventDate=!1,this._eventDate={}})),!0)}get isHover(){return this.isHoverable&&this._isHover}get isDown(){return this.isDraggable&&this._isDown}get isContextmenu(){return this.isClickable&&this._isContextmenu}get isClick(){return this.isClickable&&this._isClick}get isDblClick(){return this.isDoubleClickable&&this._isDblClick}}class Rs extends Nt{constructor(t){super(t);f(this,"canvas");f(this,"ctx");f(this,"_rectValueIsUpdated",!1);f(this,"_rect");f(this,"offset",{x:0,y:0});f(this,"center",{x:0,y:0});f(this,"defaultCenter",{top:void 0,bottom:void 0,left:void 0,right:void 0});f(this,"accuracy",5);f(this,"scale",1);f(this,"defaultScale",1);f(this,"percentage",1);f(this,"axisConfig",{count:2,min:100,size:100,x:1,y:1});f(this,"cycle",10);f(this,"delta",.02);f(this,"_redrawInNextRenderFrame",!1);f(this,"isAuto",!1);f(this,"isRendering",!1);f(this,"drawAxis");f(this,"layerGroups",new Map);f(this,"isScaleUpdated",!1);f(this,"nowGridCount");const{id:e,axisConfig:i,defaultCenter:s,offset:o,defaultScale:a}=t,l=document.getElementById(e);if(l instanceof HTMLCanvasElement)if(l.getContext){this.canvas=l,this.ctx=l.getContext("2d");const{clientWidth:c,clientHeight:h}=l;[l.width,l.height]=[c,h]}else throw new Error("canvas-unsupported code here");else throw new Error("canvas is not HTMLCanvasElement");i&&this.setAxis(i),o&&(this.offset.x=o.x||0,this.offset.y=o.y||0),s&&this.setDefaultCenter(s),a&&(this.updateCenter(),this.setScale("center",a-1),this.defaultScale=a)}get rect(){return this._rectValueIsUpdated&&this._rect?this._rect:(this._rectValueIsUpdated=!0,Promise.resolve().then(()=>this._rectValueIsUpdated=!1),this._rect=this.canvas.getBoundingClientRect(),this._rect)}get redrawInNextRenderFrame(){return this._redrawInNextRenderFrame}set redrawInNextRenderFrame(t){this._redrawInNextRenderFrame=t}setNotifyReload(t){this.notifyReload=t}getDefaultCenterLocation(){const{canvas:t,rect:e,defaultCenter:i}=this;if(!t)return console.error("canvas is not HTMLCanvasElement");const{width:s,height:o}=e,{top:a,bottom:l,left:c,right:h}=i,u={vertical:(p,v)=>{if([0,"0","0%"].includes(p))return 0;if(!(p==1/0||p==-1/0))return typeof p=="number"?p:["top","left"].includes(p)?0:["bottom","right"].includes(p)?v:["middle","center"].includes(p)?v/2:/^(-?\d+)%$/.test(p)?(p=p.match(/^(-?\d+)%$/)[1],v*Number(p)/100):Number(p)||void 0},reverse:(p,v)=>{if([0,"0","0%"].includes(p))return v;if(p==1/0||p==-1/0)return;if(typeof p=="number")return v-p;const w=u.vertical(p,v);return w?v-w:void 0}},d=(p,v,w)=>{if(p!==void 0){const _=u.vertical(p,w);if(_!==void 0)return _}if(v!==void 0){const _=u.reverse(v,w);if(_!==void 0)return _}return w/2},m=d(a,l,o);return{x:d(c,h,s),y:m}}updateCenter(){const t=this.getDefaultCenterLocation();if(!t)return;const{x:e,y:i}=t;this.center={x:Math.floor(e+this.offset.x),y:Math.floor(i+this.offset.y)}}updateSize(){const{scale:t,axisConfig:e}=this;e.size=this.getGridSize(t),this.percentage=this.getAxisPointByValue(e.count,0).x/e.min}setScale(t,e){const{canvas:i,isWheelable:s,axisConfig:o,rect:a}=this;if(!s||!i)return console.error("canvas is not HTMLCanvasElement");let l,c;t==="center"?(l=a.left+a.width/2,c=a.top+a.height/2):[l,c]=[t.clientX,t.clientY];const h=this.getMousePositionOnAxis({clientX:l,clientY:c}),u=this.getAxisValueByPoint(h.x,h.y);this.scale=new V(this.scale).add(e).toNumber(),this.isScaleUpdated=!0,this.updateSize();const d=this.getAxisPointByValue(u.xV,u.yV);this.offset.x-=(d.x-h.x)*o.x,this.offset.y-=(d.y-h.y)*o.y,this.offset.x=Number(this.offset.x.toFixed(0)),this.offset.y=Number(this.offset.y.toFixed(0))}setAxis(t){const e={...this.axisConfig,...t},i=Object.fromEntries(Object.entries(e).map(([p,v])=>[p,Number(v)])),{x:s,y:o,count:a,min:l,size:c}=i,h=[1,-1].includes(s),u=[1,-1].includes(o),d=a>0,m=l>0,g=c>=l&&c<=l*2;if(!h||!u||!d||!m){console.warn("Invalid axis configuration:",{x:s,y:o,count:a,min:l});return}g||(i.size=l),this.axisConfig=i}setDefaultCenter(t){Object.assign(this.defaultCenter,t),this.updateCenter()}getGridSize(t){const{cycle:e,delta:i,axisConfig:s}=this;let o=new V(t).sub(1).abs().mod(e*i).div(i).toNumber();return o=t<1&&o!=0?e-o:o,Number(((o/e+1)*s.min).toFixed(0))}getGridCount(t){const{axisConfig:e,cycle:i,delta:s}=this,o=e.count,a=i*s;if(t===1)return o;if(t>1){const l=new V(t).sub(1).div(a).floor();return new V(o).div(new V(2).pow(l)).toNumber()}else{const l=new V(1).sub(t).div(a).ceil();return new V(o).mul(new V(2).pow(l)).toNumber()}}get getNowGridCount(){const{scale:t,nowGridCount:e,isRendering:i}=this;return e&&i?e:(this.nowGridCount=this.getGridCount(t),i&&Promise.resolve().then(()=>this.nowGridCount=void 0),this.nowGridCount)}getMousePositionOnAxis(t){const{canvas:e,center:i,rect:s,axisConfig:o}=this;if(!e)return console.error("canvas is not HTMLCanvasElement");const{clientX:a,clientY:l}=t,{left:c,top:h}=s,u=(a-c-i.x)*o.x,d=(l-h-i.y)*o.y;return{x:u,y:d}}getAxisValueByPoint(t,e,i){const{axisConfig:s}=this;if(i)return{xV:t/s.min*s.count,yV:e/s.min*s.count};const o=this.getNowGridCount,a=new V(t).div(s.size).mul(o).toFixed(8),l=new V(e).div(s.size).mul(o).toFixed(8);return{xV:Number(a),yV:Number(l)}}getAxisPointByValue(t,e,i){const{axisConfig:s}=this;if(i)return{x:t/s.count*s.min,y:e/s.count*s.min};const o=this.getNowGridCount,a=new V(t).div(o).mul(s.size).toFixed(3),l=new V(e).div(o).mul(s.size).toFixed(3);return{x:Number(a),y:Number(l)}}getMaxMinValue(t){t=t||this.rect;const{left:e,top:i,right:s,bottom:o}=t,{axisConfig:a}=this,{x:l,y:c}=this.getMousePositionOnAxis({clientX:a.x==1?e:s,clientY:a.y==1?i:o}),{xV:h,yV:u}=this.getAxisValueByPoint(l,c),{x:d,y:m}=this.getMousePositionOnAxis({clientX:a.x==1?s:e,clientY:a.y==1?o:i}),{xV:g,yV:p}=this.getAxisValueByPoint(d,m);return{minXV:h,maxXV:g,minYV:u,maxYV:p}}transformPosition(t){const{center:e,percentage:i,axisConfig:s}=this,o=i*s.x,a=i*s.y,l=c=>[e.x+c[0]*o,e.y+c[1]*a];return Array.isArray(t[0])?t.map(c=>l(c)):l(t)}}class ks extends Rs{constructor(t){super(t);f(this,"theme","light");f(this,"isThemeUpdated",!1);f(this,"style",{light:{background:"#fff",text:{color:"#222",secondary:"#909399",stroke:"#fff",size:12,family:"monospace",bold:!0},grid:{axis:"#222",grid:"#666",innerGrid:"#e5e5e5"},point:{radius:5,fill:"#d03050",width:14,stroke:"#d0305080"},line:{stroke:{color:"#f0a020",color_hover:"#f2c97d",width:4,dash:!1,dashGap:[5,10],dashOffset:0,cap:"round",join:"round"},point:{radius:5,stroke:"#f0a02080",width:14,fill:"#f0a020"}},arc:{fill:"#f0a02030",fill_hover:"#f2c97d60",stroke:{color:"#f0a020",color_hover:"#f2c97d",width:4,dash:!1,dashGap:[5,10],dashOffset:0,cap:"round",join:"round"},point:{radius:5,stroke:"#f0a02080",width:14,fill:"#f0a020"}},arcTo:{stroke:{color:"#f0a020",color_hover:"#f2c97d",width:4,dash:!1,dashGap:[5,10],dashOffset:0,cap:"round",join:"round"},point:{radius:5,stroke:"#f0a02080",width:14,fill:"#f0a020"}},polygon:{fill:"#18a05830",fill_hover:"#03693360",stroke:{color:"#18a058",color_hover:"#036933",width:1,dash:!1,dashGap:[5,10],dashOffset:0,cap:"round",join:"round"},point:{radius:5,stroke:"#03693380",width:14,fill:"#036933"}}},dark:{background:"#000",text:{color:"#aeaeae",secondary:"#8c8c8c",stroke:"#000",size:12,family:"monospace",bold:!0},grid:{axis:"#aeaeae",grid:"#666",innerGrid:"#454545"},point:{radius:5,fill:"#e88080",width:14,stroke:"#e8808070"},line:{stroke:{color:"#f2c97d",color_hover:"#f0a020",width:4,dash:!1,dashGap:[5,10],dashOffset:0,cap:"round",join:"round"},point:{radius:5,stroke:"#f2c97d80",width:14,fill:"#f2c97d"}},arc:{fill:"#f2c97d30",fill_hover:"#f0a02060",stroke:{color:"#f2c97d",color_hover:"#f0a020",width:4,dash:!1,dashGap:[5,10],dashOffset:0,cap:"round",join:"round"},point:{radius:5,stroke:"#f2c97d80",width:14,fill:"#f2c97d"}},arcTo:{stroke:{color:"#f2c97d",color_hover:"#f0a020",width:4,dash:!1,dashGap:[5,10],dashOffset:0,cap:"round",join:"round"},point:{radius:5,stroke:"#f2c97d80",width:14,fill:"#f2c97d"}},polygon:{fill:"#63e2b730",fill_hover:"#7efbd160",stroke:{color:"#63e2b7",color_hover:"#63e2b7",width:1,dash:!1,dashGap:[5,10],dashOffset:0,cap:"round",join:"round"},point:{radius:5,stroke:"#7efbd180",width:14,fill:"#7efbd1"}}}});const{theme:e}=t;e&&this.setTheme(e),this.initStyle(),this.clearScreen()}initStyle(){const{canvas:t,ctx:e,theme:i}=this;t.classList.add("_nhanh_canvas");const s=this.style[i];e.font=`${s.text.bold?"bold":""} ${s.text.size}px ${s.text.family}`}clearScreen(t=!0){const{ctx:e,theme:i,rect:s}=this,{width:o,height:a}=s;e.clearRect(0,0,o,a),t&&this.style[i].background&&(e.fillStyle=this.style[i].background,e.fillRect(0,0,o,a))}setStyle(t){for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e)){const i=Ie(this.style[e]||this.style[this.theme]);ct(i,t[e]),this.style[e]=i}this.initStyle()}setTheme(t){t in this.style&&(this.theme=t,this.isThemeUpdated=!0)}}class R extends Nt{constructor(t){t={...t},t.isDraggable=t.isDraggable??!1;const{mainCanvas:e,notifyReload:i}=t;delete t.mainCanvas,delete t.notifyReload;super(t);f(this,"_style");f(this,"_position");f(this,"_value");f(this,"_zIndex",0);f(this,"_dynamicPosition");f(this,"_offset",{x:0,y:0});f(this,"path");f(this,"publicToPrivateKeyMap",{offset:"_offset",position:"_position",value:"_value",dynamicPosition:"_dynamicPosition",zIndex:"_zIndex",style:"_style"});f(this,"redrawOnIsHoverChange",!0);f(this,"defaultHover",(t,e)=>{var i;this.redrawOnIsHoverChange&&((i=this.notifyReload)==null||i.call(this))});f(this,"_valueScope");f(this,"styleRadius",{value:0,radius:0});f(this,"offsetValue",{xV:0,yV:0});f(this,"fixedExtraScope",{topV:0,bottomV:0,leftV:0,rightV:0});f(this,"extraScope",{top:0,bottom:0,left:0,right:0,topV:0,bottomV:0,leftV:0,rightV:0});this.setNotifyReload(i),this.mainCanvas=e,["redrawOnIsHoverChange"].forEach(o=>{o in t&&(this[o]=t[o])});const s={};["offset","style","zIndex","position","dynamicPosition","value"].forEach(o=>{o in t&&(s[o]=t[o])}),this.internalUpdate(s),this.addEventListener("hover",this.defaultHover)}get style(){return this._style}set style(t){var e;this._style=t,this.mainCanvas&&(this.updateValueScope(),(e=this.notifyReload)==null||e.call(this))}get position(){return this._position}set position(t){var e;this._position=t,this._value=void 0,this.updateBaseData(),(e=this.notifyReload)==null||e.call(this)}get value(){return this._value}set value(t){var e;this._value=t,this._position=void 0,this.updateBaseData(),(e=this.notifyReload)==null||e.call(this)}get zIndex(){return this._zIndex}set zIndex(t){var e;this._zIndex!=t&&(this._zIndex=t,(e=this.notifyReload)==null||e.call(this))}get dynamicPosition(){return this._dynamicPosition}set dynamicPosition(t){this._dynamicPosition=t}get offset(){return this._offset}set offset(t){var e;this._offset=t,this.calculateOffsetValue(),(e=this.notifyReload)==null||e.call(this)}get finalDynamicPosition(){var i;const{x:t,y:e}=this.offset;return(i=this.dynamicPosition)==null?void 0:i.map((s,o)=>typeof s=="number"?o==0?s+t:s+e:[s[0]+t,s[1]+e])}internalUpdate(t,e){Object.keys(t).forEach(i=>{const s=this.publicToPrivateKeyMap[i];s&&(this[s]=t[i])}),e&&this.updateValueScope()}setMainCanvas(t){super.setMainCanvas(t),t&&this.updateBaseData()}setNotifyReload(t){this.notifyReload=t?e=>{var i;e&&(this.isRecalculate=!0),(e||this.isNeedRender||(i=this.mainCanvas)!=null&&i.currentDrawOverlays.includes(this))&&t()}:void 0}get valueScope(){return this._valueScope}set valueScope(t){this._valueScope=t}initValueScope(){const t=this.value;if(Array.isArray(t[0])){let e=1/0,i=-1/0,s=1/0,o=-1/0;t.forEach(([a,l])=>{e=Math.min(e,a),i=Math.max(i,a),s=Math.min(s,l),o=Math.max(o,l)}),this.valueScope={minX:e,maxX:i,minY:s,maxY:o}}else{const[e,i]=t;this.valueScope={minX:e,maxX:e,minY:i,maxY:i}}this.calculateStyleRadiusValue(!1),this.calculateOffsetValue(!1),this.setFixedExtraScope(!0),this.setExtraScope(!0)}calculateStyleRadiusValue(t=!0){if(!(!this.mainCanvas||!this.valueScope))if(t){const{radius:e,value:i}=this.styleRadius;if(e==0)return;const s=this.mainCanvas.getAxisValueByPoint(e,0).xV,o=s-i;this.valueScope.minX-=o,this.valueScope.maxX+=o,this.valueScope.minY-=o,this.valueScope.maxY+=o,this.styleRadius={radius:e,value:s}}else{const{stroke:e,point:i}=this.computedValueScopeStyles,s=i?i.radius+Math.max(0,i.width/2):0,o=e?Math.max(0,e.width/2):0,a=Math.max(s,o);if(a==0)return this.styleRadius={radius:0,value:0};const l=this.mainCanvas.getAxisValueByPoint(a,0).xV;this.valueScope.minX-=l,this.valueScope.maxX+=l,this.valueScope.minY-=l,this.valueScope.maxY+=l,this.styleRadius={radius:a,value:l}}}calculateOffsetValue(t=!0){const{mainCanvas:e,valueScope:i,offset:s,offsetValue:o}=this;if(!(!e||!i))if(t){const{x:a,y:l}=e.axisConfig;let{xV:c,yV:h}=e.getAxisValueByPoint(s.x,s.y);c*=a,h*=l;const u=c-o.xV,d=h-o.yV;i.minX+=u,i.maxX+=u,i.minY+=d,i.maxY+=d,this.offsetValue={xV:c,yV:h}}else{if(this.offsetValue={xV:0,yV:0},s.x==0&&s.y==0)return;this.calculateOffsetValue()}}setFixedExtraScope(t){if(t===!0)this.fixedExtraScope={topV:0,bottomV:0,leftV:0,rightV:0};else{const e=t||{topV:0,bottomV:0,leftV:0,rightV:0};if(this.valueScope){const{leftV:i,rightV:s,topV:o,bottomV:a}=e;this.valueScope.minX-=i-this.fixedExtraScope.leftV,this.valueScope.maxX+=s-this.fixedExtraScope.rightV,this.valueScope.minY-=o-this.fixedExtraScope.topV,this.valueScope.maxY+=a-this.fixedExtraScope.bottomV,this.fixedExtraScope=e}}}setExtraScope(t){const{valueScope:e,mainCanvas:i,extraScope:s}=this;if(!(!e||!i))if(t===!0)this.extraScope={top:0,bottom:0,left:0,right:0,topV:0,bottomV:0,leftV:0,rightV:0};else if(t){const{left:o,right:a,top:l,bottom:c}=t,{xV:h,yV:u}=i.getAxisValueByPoint(l,c),{xV:d,yV:m}=i.getAxisValueByPoint(o,a);e.minX-=d-s.leftV,e.maxX+=m-s.rightV,e.minY-=h-s.topV,e.maxY+=u-s.bottomV,this.extraScope={...t,topV:h,bottomV:u,leftV:d,rightV:m}}else this.setExtraScope(this.extraScope)}get isWithinRange(){const{mainCanvas:t,valueScope:e}=this;if(!t)return!1;const{isScaleUpdated:i,maxMinValue:s}=t;return i&&(this.calculateStyleRadiusValue(),this.calculateOffsetValue(),this.setExtraScope()),e?!(s.maxXV<e.minX||s.minXV>e.maxX||s.maxYV<e.minY||s.minYV>e.maxY):!0}get isNeedRender(){return!!(this.mainCanvas&&this.shouldRender()&&this.dynamicPosition&&this.isWithinRange)}calculateOffset(t,e){const{percentage:i,axisConfig:s}=this.mainCanvas,o=s.count/s.min/i,a={value:t*o*s.x,position:t/i*s.x,dynamicPosition:t},l={value:e*o*s.y,position:e/i*s.y,dynamicPosition:e};return{x:a,y:l}}handleValuePosition(t,e){let{value:i,position:s,mainCanvas:o}=this;if(!o)return!1;const a=t==="array1D"?ee:Mt,[l,c]=[a(i)&&(!e||i.length>=e),a(s)&&(!e||s.length>=e)],h={value:i,position:s,dynamicPosition:[]};if(!l&&!c)return this.internalUpdate({dynamicPosition:void 0}),!1;if(l){const u=i;if(t==="array1D"){const d=o.getAxisPointByValue(u[0],u[1],!0);h.position=[d.x,d.y]}else{h.position=[];for(let d=0;d<u.length;d++){const m=u[d],g=o.getAxisPointByValue(m[0],m[1],!0);h.position.push([g.x,g.y])}}}else{const u=s;if(t==="array1D"){const d=o.getAxisValueByPoint(u[0],u[1],!0);h.value=[d.xV,d.yV]}else{h.value=[];for(let d=0;d<u.length;d++){const m=u[d],g=o.getAxisValueByPoint(m[0],m[1],!0);h.value.push([g.xV,g.yV])}}}return h.dynamicPosition=o.transformPosition(h.position),this.internalUpdate(h,!0),!0}isPointInAnywhere(t,e){return this.isPointInPath(t,e)||this.isPointInStroke(t,e)}setGlobalAlpha(t){var i;const e=this.opacity??((i=this.parent)==null?void 0:i.opacity);e!==void 0&&(t.globalAlpha=e)}setBaseLineStyle(t,e){const{width:i,dash:s,dashGap:o,dashOffset:a,color:l,color_hover:c,cap:h,join:u}=e;return t.setLineDash(s?o:[]),t.lineDashOffset=a,t.lineCap=h,t.lineJoin=u,t.lineWidth=i,t.strokeStyle=this.isHover?c:l,e}get cursorStyle(){return this.isInteractive?this.isDraggable?"_nhanh_canvas_hover_overlay_draggable":"_nhanh_canvas_hover_overlay":void 0}}f(R,"ctx",document.createElement("canvas").getContext("2d"));class Gt extends R{constructor(t){super(t);f(this,"_draw");this.redrawOnIsHoverChange=!1;const{draw:e}=t;Object.assign(this,{draw:e})}updateValueScope(){this.initValueScope()}isPointInPath(t,e){return!1}isPointInStroke(t,e){return!1}updateBaseData(){if(!this.mainCanvas)return;this.internalUpdate({dynamicPosition:void 0});let t=this.value,e=this.position;t?e=this.convertValuesToPositions(t):t=this.convertPositionsToValues(e),this.updateDataProperties(t,e)}convertValuesToPositions(t){const e=[];let i;return t.forEach(s=>{if(i===void 0){const o=this.mainCanvas.getAxisPointByValue(s[0],s[1],!0);e.push([o.x,o.y]),s[0]!=0?i=new V(o.x).div(s[0]).toNumber():s[1]!=0&&(i=new V(o.y).div(s[1]).toNumber())}else e.push([new V(i).mul(s[0]).toNumber(),new V(i).mul(s[1]).toNumber()])}),e}convertPositionsToValues(t){const e=[];let i;return t.forEach((s,o)=>{if(i===void 0){const a=this.mainCanvas.getAxisValueByPoint(s[0],s[1],!0);e.push([a.xV,a.yV]),s[0]!=0?i=new V(a.xV).div(s[0]).toNumber():s[1]!=0&&(i=new V(a.yV).div(s[1]).toNumber())}else e.push([new V(i).mul(s[0]).toNumber(),new V(i).mul(s[1]).toNumber()])}),e}updateDataProperties(t,e){this.internalUpdate({value:t,position:e,dynamicPosition:this.mainCanvas.transformPosition(e)})}setOverlayStyles(t){}get computedValueScopeStyles(){return{}}get draw(){return t=>{var e;this.setGlobalAlpha(t),(e=this._draw)==null||e.call(this,t)}}set draw(t){this._draw=t}getDraw(){if(this.isNeedRender){const{mainCanvas:t,position:e}=this;return this.isRecalculate&&this.internalUpdate({dynamicPosition:t.transformPosition(e)}),[this.draw,this]}}}class O{static add(n,t){return new V(n).add(t).toNumber()}static sub(n,t){return new V(n).sub(t).toNumber()}static mul(n,t){return new V(n).mul(t).toNumber()}static div(n,t){return new V(n).div(t).toNumber()}}class Xt extends R{constructor(t){super(t);f(this,"textOffset",{x:0,y:0});f(this,"_text");f(this,"defaultDragg",(t,e)=>{var l;const{offsetX:i,offsetY:s}=t.data,{x:o,y:a}=this.calculateOffset(i,s);this.internalUpdate({value:[O.add(this.value[0],o.value),O.add(this.value[1],a.value)],position:[O.add(this.position[0],o.position),O.add(this.position[1],a.position)],dynamicPosition:[O.add(this.dynamicPosition[0],o.dynamicPosition),O.add(this.dynamicPosition[1],a.dynamicPosition)]},!0),(l=this.notifyReload)==null||l.call(this)});const{text:e}=t;Object.assign(this,{text:e}),this.addEventListener("dragg",this.defaultDragg)}get text(){return this._text}set text(t){var e;this._text!=t&&(this._text=t,this.updateBaseData(),(e=this.notifyReload)==null||e.call(this))}updateValueScope(){this.initValueScope();const t=this.textOffset;this.setExtraScope({top:t.y,bottom:t.y,left:t.x,right:t.x})}isPointInPath(t,e){return this.path?R.ctx.isPointInPath(this.path,t,e):!1}isPointInStroke(t,e){return!1}updateBaseData(){if(!this.mainCanvas)return;if(!this.text||this.text.length==0)return this.internalUpdate({dynamicPosition:void 0});const t=R.ctx;this.setOverlayStyles(t);const e=t.measureText(this.text);this.textOffset={x:e.width/2,y:e.actualBoundingBoxAscent/2},this.handleValuePosition("array1D")}setOverlayStyles(t){var o;const e=this.mainCanvas,i=e.style[e.theme].text;let s={};return typeof this.style=="string"?s=((o=e.style[this.style])==null?void 0:o.text)||i:typeof this.style=="object"?s=Object.assign({},i,this.style):s=i,t.font=`${s.bold?"bold":""} ${s.size}px ${s.family}`,t.lineWidth=2,t.strokeStyle=s.stroke,t.fillStyle=s[this.isHover?"secondary":"color"],s}get computedValueScopeStyles(){return{}}draw(t){const{text:e,textOffset:i,finalDynamicPosition:s}=this;if(!this.mainCanvas||!e)return;this.setGlobalAlpha(t),this.setOverlayStyles(t);const o=s[0]-i.x,a=s[1]+i.y;t.strokeText(e,o,a),t.fillText(e,o,a),this.path=new Path2D,this.path.rect(o,s[1]-i.y,i.x*2,i.y*2)}getDraw(){if(this.isNeedRender){if(this.isRecalculate){const{position:t,mainCanvas:e}=this;this.internalUpdate({dynamicPosition:e.transformPosition(t)})}return[this.draw,this]}}}class lt extends R{constructor(t){super(t);f(this,"angle",2*Math.PI);f(this,"defaultDragg",(t,e)=>{var l;const{offsetX:i,offsetY:s}=t.data,{x:o,y:a}=this.calculateOffset(i,s);this.internalUpdate({value:[O.add(this.value[0],o.value),O.add(this.value[1],a.value)],position:[O.add(this.position[0],o.position),O.add(this.position[1],a.position)],dynamicPosition:[O.add(this.dynamicPosition[0],o.dynamicPosition),O.add(this.dynamicPosition[1],a.dynamicPosition)]},!0),(l=this.notifyReload)==null||l.call(this)});f(this,"fillProgress");f(this,"defaultHover",(t,e)=>{const i=t.data.state,s=300,o=this.setOverlayStyles().width;this.fillProgress?this.cancelAndRestartAnimation(i,o,s-100):i&&this.startNewHoverAnimation(o,s)});this.addEventListener("hover",this.defaultHover),this.addEventListener("dragg",this.defaultDragg)}updateValueScope(){this.initValueScope()}cancelAndRestartAnimation(t,e,i){this.fillProgress.scheduleCallback();let s=0;this.fillProgress.scheduleCallback=kt(o=>{!this.fillProgress||!o||(this.fillProgress.progress+=(o-s)*(t?1:-1),s=o,this.fillProgress.progress=Math.min(1,Math.max(0,this.fillProgress.progress)),this.updateLineWidthOffset(e),(this.fillProgress.progress===1||this.fillProgress.progress===0)&&(this.fillProgress.scheduleCallback(),this.fillProgress.progress===0&&(this.fillProgress=void 0)))},i)}startNewHoverAnimation(t,e){this.fillProgress={lineWidthOffset:0,progress:0,scheduleCallback:kt(i=>{this.fillProgress&&(this.fillProgress.progress=i,this.updateLineWidthOffset(t))},e)}}updateLineWidthOffset(t){var i;if(!this.fillProgress)return;const e=Math.ceil(t*this.fillProgress.progress);e!==this.fillProgress.lineWidthOffset&&(this.fillProgress.lineWidthOffset=e,(i=this.notifyReload)==null||i.call(this))}isPointInPath(t,e){return this.path?R.ctx.isPointInPath(this.path,t,e):!1}isPointInStroke(t,e){var i;if(this.path&&this.mainCanvas){const{width:s}=this.setOverlayStyles(R.ctx);return((i=this.fillProgress)==null?void 0:i.lineWidthOffset)==s?!1:R.ctx.isPointInStroke(this.path,t,e)}return!1}updateBaseData(){this.handleValuePosition("array1D")}setOverlayStyles(t){var c,h;const e=this.mainCanvas,i=e.style[e.theme].point;let s={};typeof this.style=="string"?s=((c=e.style[this.style])==null?void 0:c.point)||i:typeof this.style=="object"?s=Object.assign({},i,this.style):s=i;const{width:o,stroke:a,fill:l}=s;if(t){t.setLineDash([]);const u=((h=this.fillProgress)==null?void 0:h.lineWidthOffset)||0;t.lineWidth=o-u,t.strokeStyle=a,t.fillStyle=l}return{...s}}get computedValueScopeStyles(){return{point:this.setOverlayStyles()}}draw(t){var h;const{finalDynamicPosition:e,mainCanvas:i}=this;if(!i)return;this.setGlobalAlpha(t);const{radius:s,width:o}=this.setOverlayStyles(t),a=((h=this.fillProgress)==null?void 0:h.lineWidthOffset)||0,[l,c]=e;t.beginPath(),this.path=new Path2D,this.path.arc(l,c,s+a/2,0,this.angle),o!=a&&t.stroke(this.path),t.fill(this.path)}getDraw(){if(this.isNeedRender){const{mainCanvas:t,position:e}=this;return this.isRecalculate&&this.internalUpdate({dynamicPosition:t.transformPosition(e)}),[this.draw,this]}}}class qe extends R{constructor(t){super(t);f(this,"handlePoints",[]);f(this,"isShowHandlePoint",!1);f(this,"_isHandlePointsVisible",!0);f(this,"canCreateOrDeleteHandlePoint",!0);f(this,"lockedCanCreateOrDeleteHandlePoint",!1);f(this,"defaultClick",(t,e)=>{var o;if(!this.isHandlePointsVisible)return;const{state:i,oldState:s}=t.data;i!=s&&!this.isInfinite&&((o=this.notifyReload)==null||o.call(this))});f(this,"defaultDoubleClick",(t,e)=>{if(e){if(!this.isHandlePointsVisible)return;const{offsetX:i,offsetY:s}=e,{state:o}=t.data;if(this.lockedCanCreateOrDeleteHandlePoint)this.resetHandlePointLock();else if(o&&this.isHandlePointsVisible&&this.canCreateOrDeleteHandlePoint&&this.isDraggable){const l=this.handlePoints.findIndex(c=>c.isHover);l===-1?this.tryCreateNewHandlePoint(i,s):this.tryDeleteHandlePoint(l)}}});f(this,"defaultDragg",(t,e)=>{var s;if(!this.mainCanvas)return;const i=()=>{const{offsetX:o,offsetY:a}=t.data,{x:l,y:c}=this.calculateOffset(o,a);this.value.forEach((h,u)=>{this.value[u]=[O.add(this.value[u][0],l.value),O.add(this.value[u][1],c.value)],this.position[u]=[O.add(this.position[u][0],l.position),O.add(this.position[u][1],c.position)],this.dynamicPosition[u]=[O.add(this.dynamicPosition[u][0],l.dynamicPosition),O.add(this.dynamicPosition[u][1],c.dynamicPosition)]}),this.handlePoints.forEach((h,u)=>{h.internalUpdate({value:this.value[u],position:this.position[u],dynamicPosition:this.dynamicPosition[u]})}),this.lockedCanCreateOrDeleteHandlePoint=!0};if(this.isHandlePointsVisible){const o=this.handlePoints.findIndex(a=>a.isHover);if(o!=-1){const a=this.handlePoints[o];a.notifyDragg(t.data,e),this.value[o]=a.value,this.position[o]=a.position,this.dynamicPosition[o]=a.dynamicPosition}else i()}else i();(s=this.notifyReload)==null||s.call(this),this.updateValueScope()});["isHandlePointsVisible","canCreateOrDeleteHandlePoint"].forEach(e=>{e in t&&(this[e]=t[e])}),this.addEventListener("click",this.defaultClick),this.addEventListener("doubleClick",this.defaultDoubleClick),this.addEventListener("dragg",this.defaultDragg)}get isHandlePointsVisible(){return this._isHandlePointsVisible}set isHandlePointsVisible(t){var e;this._isHandlePointsVisible!==t&&(this._isHandlePointsVisible=t,this.isShowHandlePoint!=t&&((e=this.notifyReload)==null||e.call(this)),this.updateHandlePoints())}get offset(){return super.offset}set offset(t){super.offset=t;let{isHandlePointsVisible:e,handlePoints:i}=this;e&&i.forEach(s=>s.internalUpdate({offset:t}))}tryCreateNewHandlePoint(t,e){var c;if(!this.isPointInStroke(t,e))return;const i=this.getExtendedDynamicPositions(),s=Ms([t,e],i);if(s===-1)return;const[o,a]=this.getAdjacentIndices(s),l=this.createNewHandlePoint(o,a);this.insertHandlePoint(s,l),this.lockHandlePointCreationTemporarily(),(c=this.notifyReload)==null||c.call(this)}tryDeleteHandlePoint(t){var e;!this.isDblClick||!this.canDeleteHandlePoint||(this.deleteHandlePoint(t),(e=this.notifyReload)==null||e.call(this))}getExtendedDynamicPositions(){return this.isClosed?[...this.dynamicPosition,this.dynamicPosition[0]]:this.dynamicPosition}getAdjacentIndices(t){const e=t-1,i=this.isClosed&&t===this.dynamicPosition.length?0:t;return[e,i]}createNewHandlePoint(t,e){const i=ae(this.value[t],this.value[e]),s=ae(this.position[t],this.position[e]),o=ae(this.dynamicPosition[t],this.dynamicPosition[e]);return new lt({value:i,position:s,dynamicPosition:o,isDraggable:!0,mainCanvas:this.mainCanvas,notifyReload:()=>{var a;return(a=this.notifyReload)==null?void 0:a.call(this)}})}insertHandlePoint(t,e){this.handlePoints.splice(t,0,e),this.value.splice(t,0,e.value),this.position.splice(t,0,e.position),this.dynamicPosition.splice(t,0,e.dynamicPosition)}deleteHandlePoint(t){this.handlePoints.splice(t,1),this.value.splice(t,1),this.position.splice(t,1),this.dynamicPosition.splice(t,1)}lockHandlePointCreationTemporarily(){this.lockedCanCreateOrDeleteHandlePoint=!0,setTimeout(()=>{this.lockedCanCreateOrDeleteHandlePoint=!1},300)}resetHandlePointLock(){this.lockedCanCreateOrDeleteHandlePoint=!1}get canDeleteHandlePoint(){return this.handlePoints.length>this.minNeededHandlePoints}updateHandlePoints(){let{value:t,position:e,dynamicPosition:i,offset:s,isHandlePointsVisible:o}=this;!i||!o||(t==null||t.forEach((a,l)=>{if(!this.handlePoints[l]){const c=new lt({value:[0,0],mainCanvas:this.mainCanvas,isDraggable:!0,offset:s,notifyReload:()=>{var h;return(h=this.notifyReload)==null?void 0:h.call(this)}});this.handlePoints.push(c)}this.handlePoints[l].internalUpdate({value:t[l],position:e[l],dynamicPosition:i[l]},!0)}),this.handlePoints.length=t.length)}updateHandlePointsPosition(){this.isHandlePointsVisible&&this.handlePoints.forEach((t,e)=>{t.internalUpdate({dynamicPosition:this.dynamicPosition[e]})})}}function Ms(r,n,t=10){if(n.length===0)return 0;if(n.length===1)return 1;let e=1/0,i=-1;for(let s=0;s<n.length-1;s++){const o=Je(r,n[s],n[s+1]);if(o<t)return s+1;o<e&&(e=o,i=s+1)}return i}function ae(r,n){const{x:t,y:e}=be(...r,...n);return[t,e]}class Yt extends qe{constructor(t){super(t);f(this,"_isInfinite");f(this,"isClosed",!1);f(this,"minNeededHandlePoints",2);const{isInfinite:e}=t;Object.assign(this,{isInfinite:e}),e&&(this.canCreateOrDeleteHandlePoint=!1)}get isInfinite(){return this._isInfinite}set isInfinite(t){var e;this._isInfinite!=t&&(this._isInfinite=t,this.canCreateOrDeleteHandlePoint=!t,(e=this.notifyReload)==null||e.call(this))}updateValueScope(){this.initValueScope()}isPointInPath(t,e){return!1}isPointInStroke(t,e){return this.path&&this.mainCanvas?(this.setOverlayStyles(R.ctx),this.isDraggable&&(R.ctx.lineWidth=Math.max(R.ctx.lineWidth,20)),R.ctx.isPointInStroke(this.path,t,e)):!1}isPointInAnywhere(t,e){return(s=>{if(!s)return!1;let o=!1;return[...this.handlePoints].sort((l,c)=>(l.isHover?0:1)-(c.isHover?0:1)).forEach(l=>{o?l.isHover&&l.notifyHover(!1):(o=l.isPointInAnywhere(t,e),o!=l.isHover&&l.notifyHover(o))}),o})((this.isClick||!!this.isInfinite)&&this.isShowHandlePoint)||super.isPointInAnywhere(t,e)}get isWithinRange(){if(this.isInfinite){this.isRecalculate&&this.updateDynamicPosition();const{width:t,height:e}=this.mainCanvas.rect;return Os([0,0],[t,e],this.finalDynamicPosition[0],this.finalDynamicPosition[1])}return super.isWithinRange}updateBaseData(){this.handleValuePosition("array2D",2)&&this.updateHandlePoints()}updateDynamicPosition(){const{mainCanvas:t,position:e}=this,i=t.transformPosition(e);this.internalUpdate({dynamicPosition:i}),this.updateHandlePointsPosition()}setOverlayStyles(t){var o;const e=this.mainCanvas,i=e.style[e.theme].line;let s={};return typeof this.style=="string"?s=((o=e.style[this.style])==null?void 0:o.line)||i:typeof this.style=="object"?s=ct(JSON.parse(JSON.stringify(i)),this.style):s=i,t&&this.setBaseLineStyle(t,s.stroke),s}get computedValueScopeStyles(){return this.setOverlayStyles()}drawLine(t,e){const{mainCanvas:i,isInfinite:s,isClick:o}=this;if(e=e||this.finalDynamicPosition,!i)return;this.setGlobalAlpha(t);const a=this.setOverlayStyles(t);t.beginPath(),this.path=new Path2D,e.forEach((l,c)=>{this.path[c==0?"moveTo":"lineTo"](l[0],l[1])}),t.stroke(this.path),this.isShowHandlePoint=(s||o)&&this.isHandlePointsVisible,this.isShowHandlePoint&&this.handlePoints.forEach(l=>{var c;l.style=a.point,(c=l.getDraw())==null||c[0].call(l,t)})}drawisInfiniteStraightLine(t){const{mainCanvas:e,finalDynamicPosition:i}=this;if(!e)return;this.setGlobalAlpha(t);const{rect:s}=e,[o,a]=i,l=[a[0]-o[0],a[1]-o[1]];if(l[0]===0&&l[1]===0)return console.error("重合点无法确定方向");const c=Ve(o,[-l[0],-l[1]],s.width,s.height),h=Ve(a,l,s.width,s.height);this.drawLine(t,[c,h])}getDraw(){if(this.isNeedRender){const{isRecalculate:t,isInfinite:e}=this;return t&&this.updateDynamicPosition(),e?[this.drawisInfiniteStraightLine,this]:[this.drawLine,this]}}}function Ve(r,n,t,e){const[i,s]=r,[o,a]=n;let l=1/0;if(o!==0){const c=o>0?(t-i)/o:-i/o;c>0&&(l=Math.min(l,c))}if(a!==0){const c=a>0?(e-s)/a:-s/a;c>0&&(l=Math.min(l,c))}return l===1/0?r:[i+o*l,s+a*l]}function Os(r,n,t,e){const i=Math.min(r[0],n[0]),s=Math.max(r[0],n[0]),o=Math.min(r[1],n[1]),a=Math.max(r[1],n[1]),l=[[i,o],[s,o],[s,a],[i,a]],c=e[1]-t[1],h=t[0]-e[0],u=e[0]*t[1]-t[0]*e[1];if(c===0&&h===0){const[p,v]=t;return p>=i&&p<=s&&v>=o&&v<=a}const d=1e-10;let m=!1,g=!1;for(const[p,v]of l){const w=c*p+h*v+u;if(Math.abs(w)<d||(w>d?m=!0:g=!0,m&&g))return!0}return m&&g}class zt extends qe{constructor(t){super(t);f(this,"_isRect",!1);f(this,"dynamicBorderRadius");f(this,"_borderRadius");f(this,"_borderRadiusType","position");f(this,"isClosed",!0);f(this,"minNeededHandlePoints",3);["isRect","borderRadius","borderRadiusType"].forEach(e=>{e in t&&(this[e]=t[e])}),t.isRect&&(this.canCreateOrDeleteHandlePoint=!1)}get isRect(){return this._isRect}set isRect(t){var e;this._isRect!=t&&(this._isRect=t,this.canCreateOrDeleteHandlePoint=!t,this.updateBaseData(),(e=this.notifyReload)==null||e.call(this))}get borderRadius(){return this._borderRadius}set borderRadius(t){var e;this._borderRadius!=t&&(this._borderRadius=t,this.updateDynamicRadius(),(e=this.notifyReload)==null||e.call(this))}get borderRadiusType(){return this._borderRadiusType}set borderRadiusType(t){var e;this._borderRadiusType!=t&&(this._borderRadiusType=t,this.updateDynamicRadius(),(e=this.notifyReload)==null||e.call(this))}updateValueScope(){this.initValueScope()}isPointInPath(t,e){return this.path?R.ctx.isPointInPath(this.path,t,e):!1}isPointInStroke(t,e){return this.path&&this.mainCanvas?(this.setOverlayStyles(R.ctx),this.isDraggable&&(R.ctx.lineWidth=Math.max(R.ctx.lineWidth,20)),R.ctx.isPointInStroke(this.path,t,e)):!1}isPointInAnywhere(t,e){return(s=>{if(!s)return!1;let o=!1;return[...this.handlePoints].sort((l,c)=>(l.isHover?0:1)-(c.isHover?0:1)).forEach(l=>{o?l.isHover&&l.notifyHover(!1):(o=l.isPointInAnywhere(t,e),o!=l.isHover&&l.notifyHover(o))}),o})(this.isClick&&this.isShowHandlePoint)||super.isPointInAnywhere(t,e)}updateDynamicRadius(){const{mainCanvas:t,borderRadius:e}=this;if(!t||!e){this.dynamicBorderRadius=void 0;return}if(typeof e=="number"){this.dynamicBorderRadius=this.handleSingleRadius(e);return}this.dynamicBorderRadius=e.map(i=>this.handleSingleRadius(i,!0))}handleSingleRadius(t,e){const{mainCanvas:i,borderRadiusType:s}=this;if(t<=0)return e?0:void 0;switch(s){case"position":return t*i.percentage;default:return i.getAxisPointByValue(t,0).x}}updateBaseData(){if(!this.mainCanvas)return;let{value:t,position:e,isRect:i}=this;const s=i?2:3;i&&(Array.isArray(t)&&(t.length=2),Array.isArray(e)&&(e.length=2)),this.handleValuePosition("array2D",s)&&(this.updateHandlePoints(),this.updateDynamicRadius())}setOverlayStyles(t){var c;const e=this.isHover,i=this.mainCanvas,s=i.style[i.theme].polygon;let o={};typeof this.style=="string"?o=((c=i.style[this.style])==null?void 0:c.polygon)||s:typeof this.style=="object"?o=ct(JSON.parse(JSON.stringify(s)),this.style):o=s;const{fill:a,fill_hover:l}=o;return t&&(this.setBaseLineStyle(t,o.stroke),t.fillStyle=e?l:a),o}get computedValueScopeStyles(){return this.setOverlayStyles()}drawRect(t){this.setGlobalAlpha(t);const[[e,i],[s,o]]=this.finalDynamicPosition,a=Math.abs(s-e),l=Math.abs(o-i),c=Math.min(e,s),h=Math.min(i,o),u=this.setOverlayStyles(t);t.beginPath(),this.path=new Path2D,this.dynamicBorderRadius?this.path.roundRect(c,h,a,l,this.dynamicBorderRadius):this.path.rect(c,h,a,l),t.stroke(this.path),t.fill(this.path),this.isShowHandlePoint=this.isClick&&this.isHandlePointsVisible,this.isShowHandlePoint&&this.handlePoints.forEach(d=>{var m;d.internalUpdate({style:u.point}),(m=d.getDraw())==null||m[0].call(d,t)})}drawPolygon(t){this.setGlobalAlpha(t);const e=this.finalDynamicPosition,i=this.setOverlayStyles(t);t.beginPath(),this.path=new Path2D,e.forEach((s,o)=>{this.path[o==0?"moveTo":"lineTo"](s[0],s[1])}),this.path.closePath(),t.stroke(this.path),t.fill(this.path),this.isShowHandlePoint=this.isClick&&this.isHandlePointsVisible,this.isShowHandlePoint&&this.handlePoints.forEach(s=>{var o;s.internalUpdate({style:i.point}),(o=s.getDraw())==null||o[0].call(s,t)})}getDraw(){if(this.isNeedRender){const{mainCanvas:t,position:e}=this;if(this.isRecalculate){this.updateDynamicRadius();const i=t.transformPosition(e);this.internalUpdate({dynamicPosition:i}),this.updateHandlePointsPosition()}return this.isRect?[this.drawRect,this]:[this.drawPolygon,this]}}}class pe extends R{constructor(t){super(t);f(this,"_isFill",!1);f(this,"_isClosed",!1);f(this,"_isClosedThroughCenter",!1);f(this,"_radiusValue",0);f(this,"_radiusPosition",0);f(this,"_startAngle",0);f(this,"_endAngle",0);f(this,"_counterclockwise",!1);f(this,"isShowHandlePoint",!1);f(this,"_isHandlePointsVisible",!0);f(this,"defaultClick",(t,e)=>{var o;if(!this.isHandlePointsVisible)return;const{state:i,oldState:s}=t.data;i!=s&&((o=this.notifyReload)==null||o.call(this))});f(this,"defaultDragg",(t,e)=>{if(!this.mainCanvas)return;const i=()=>{var h;const{offsetX:s,offsetY:o}=t.data,{x:a,y:l}=this.calculateOffset(s,o);this.handlePointsArr.concat(this).forEach(u=>{u.internalUpdate({value:[O.add(u.value[0],a.value),O.add(u.value[1],l.value)],position:[O.add(u.position[0],a.position),O.add(u.position[1],l.position)],dynamicPosition:[O.add(u.dynamicPosition[0],a.dynamicPosition),O.add(u.dynamicPosition[1],l.dynamicPosition)]},!0)}),(h=this.notifyReload)==null||h.call(this)};if(this.isHandlePointsVisible){const{start:s,end:o,radius:a}=this.handlePoints,l=this.handlePointsArr.find(c=>c.isHover);if(l){const c=t.data.offsetX;if(l==s)this.startAngle=(this.startAngle+-c/180*Math.PI)%(Math.PI*2);else if(l==o)this.endAngle=(this.endAngle+-c/180*Math.PI)%(Math.PI*2);else if(l==a){const h=c/2/this.mainCanvas.percentage;this.radiusPosition+h>0&&(this.radiusPosition+=h)}}else i()}else i()});f(this,"handlePoints",{start:void 0,end:void 0,radius:void 0});["isFill","isClosed","isClosedThroughCenter","radiusValue","radiusPosition","startAngle","endAngle","counterclockwise","isHandlePointsVisible"].forEach(e=>{e in t&&(this["_"+e]=t[e])}),this.addEventListener("click",this.defaultClick),this.addEventListener("dragg",this.defaultDragg)}get isFill(){return this._isFill}set isFill(t){var e;this._isFill!=t&&(this._isFill=t,(e=this.notifyReload)==null||e.call(this))}get isClosed(){return this._isClosed}set isClosed(t){var e;this._isClosed!=t&&(this._isClosed=t,(e=this.notifyReload)==null||e.call(this))}get isClosedThroughCenter(){return this._isClosedThroughCenter}set isClosedThroughCenter(t){var e;this._isClosedThroughCenter!=t&&(this._isClosedThroughCenter=t,(e=this.notifyReload)==null||e.call(this))}get radiusValue(){return this._radiusValue}set radiusValue(t){this._radiusValue!=t&&(this._radiusValue=t,this._radiusPosition=0,this.updateBaseData())}get radiusPosition(){return this._radiusPosition}set radiusPosition(t){this._radiusPosition!=t&&(this._radiusPosition=t,this._radiusValue=0,this.updateBaseData())}get startAngle(){return this._startAngle}set startAngle(t){var e;this._startAngle!=t&&(this._startAngle=t,this.updateHandlePoints(),(e=this.notifyReload)==null||e.call(this))}get endAngle(){return this._endAngle}set endAngle(t){var e;this._endAngle!=t&&(this._endAngle=t,this.updateHandlePoints(),(e=this.notifyReload)==null||e.call(this))}get counterclockwise(){return this._counterclockwise}set counterclockwise(t){var e;this._counterclockwise!=t&&(this._counterclockwise=t,(e=this.notifyReload)==null||e.call(this))}get isHandlePointsVisible(){return this._isHandlePointsVisible}set isHandlePointsVisible(t){var e;this._isHandlePointsVisible!==t&&(this._isHandlePointsVisible=t,this.isShowHandlePoint!=t&&((e=this.notifyReload)==null||e.call(this)),this.updateHandlePoints())}get offset(){return super.offset}set offset(t){super.offset=t;let{isHandlePointsVisible:e,handlePointsArr:i}=this;e&&i.forEach(s=>s.internalUpdate({offset:t}))}updateValueScope(){const{mainCanvas:t,radiusValue:e}=this;t&&(this.initValueScope(),this.setFixedExtraScope({topV:e,bottomV:e,leftV:e,rightV:e*2}))}isPointInPath(t,e){return this.isFill&&this.path?R.ctx.isPointInPath(this.path,t,e):!1}isPointInStroke(t,e){return this.path&&this.mainCanvas?(this.setOverlayStyles(R.ctx),this.isDraggable&&(R.ctx.lineWidth=Math.max(R.ctx.lineWidth,20)),R.ctx.isPointInStroke(this.path,t,e)):!1}isPointInAnywhere(t,e){return(s=>{if(!s)return!1;let o=!1;return this.handlePointsArr.forEach(a=>{o?a.isHover&&a.notifyHover(!1):(o=a.isPointInAnywhere(t,e),o!=a.isHover&&a.notifyHover(o))}),o})(this.isClick&&this.isShowHandlePoint)||super.isPointInAnywhere(t,e)}get cursorStyle(){const t=this.handlePointsArr.some(e=>e==null?void 0:e.isHover);return this.isInteractive?this.isDraggable?"_nhanh_canvas_hover_overlay_draggable"+(t?"_ew":""):"_nhanh_canvas_hover_overlay":void 0}setOverlayStyles(t){var c;const e=this.isHover,i=this.mainCanvas,s=i.style[i.theme].arc;let o={};typeof this.style=="string"?o=((c=i.style[this.style])==null?void 0:c.arc)||s:typeof this.style=="object"?o=ct(JSON.parse(JSON.stringify(s)),this.style):o=s;const{fill:a,fill_hover:l}=o;return t&&(this.setBaseLineStyle(t,o.stroke),t.fillStyle=e?l:a),o}get computedValueScopeStyles(){return this.setOverlayStyles()}get handlePointsArr(){const t=this.handlePoints.radius;return Object.values(this.handlePoints).filter(Boolean).sort((e,i)=>(e.isHover||e==t?0:1)-(i.isHover||i==t?0:1))}updateHandlePoints(){let{mainCanvas:t,value:e,radiusValue:i,startAngle:s,endAngle:o,dynamicPosition:a,isHandlePointsVisible:l,offset:c}=this;if(!t||!a||!l)return;const[h,u]=Ns(...e,i,s,o,t.axisConfig.x,t.axisConfig.y),d=w=>new lt({name:w,offset:c,value:[0,0],isDraggable:!0,mainCanvas:this.mainCanvas,notifyReload:()=>{var _;return(_=this.notifyReload)==null?void 0:_.call(this)}}),m=this.handlePoints.start||d("start"),g=this.handlePoints.end||d("end"),p=this.handlePoints.radius||d("radius");m.value=h,g.value=u;const v=e[0]+i*2*t.axisConfig.x;p.value=[v,e[1]],this.handlePoints={start:m,end:g,radius:p}}updateBaseData(){this.mainCanvas&&(this.radiusValue?this._radiusPosition=this.mainCanvas.getAxisPointByValue(this.radiusValue,0,!0).x:this._radiusValue=this.mainCanvas.getAxisValueByPoint(this.radiusPosition,0,!0).xV,this.handleValuePosition("array1D")&&this.updateHandlePoints())}drawGuideLine(t,e,i,s){this.setBaseLineStyle(t,{...s.stroke,dash:!s.stroke.dash});const{radiusPosition:o,startAngle:a,endAngle:l,counterclockwise:c,mainCanvas:h}=this;t.beginPath(),t.arc(e,i,o*h.percentage,l,a,c),t.stroke(),t.beginPath(),t.moveTo(e,i);const u=this.handlePoints.radius.finalDynamicPosition;t.lineTo(u[0],u[1]),t.stroke(),!(this.isClosed&&this.isClosedThroughCenter)&&(t.fillStyle=t.strokeStyle,t.beginPath(),t.arc(e,i,s.point.radius,0,Math.PI*2),t.fill())}draw(t){const{finalDynamicPosition:e,mainCanvas:i,startAngle:s,endAngle:o,counterclockwise:a,isFill:l,isClosed:c,isClosedThroughCenter:h,radiusPosition:u}=this;if(!i||u<=0)return;this.setGlobalAlpha(t);const d=this.setOverlayStyles(t),[m,g]=e;t.beginPath(),this.path=new Path2D,this.path.arc(m,g,u*i.percentage,s,o,a),c&&(this.path.lineTo(m,g),h&&this.path.closePath()),t.stroke(this.path),l&&t.fill(this.path),this.isShowHandlePoint=this.isClick&&this.isHandlePointsVisible,this.isShowHandlePoint&&(this.drawGuideLine(t,m,g,d),this.handlePointsArr.forEach(p=>{var v;p.internalUpdate({style:d.point}),(v=p.getDraw())==null||v[0].call(p,t)}))}getDraw(){if(this.isNeedRender){if(this.isRecalculate){const{position:t,mainCanvas:e}=this,i=this.dynamicPosition,s=e.transformPosition(t);if(this.internalUpdate({dynamicPosition:s}),this.isHandlePointsVisible)if(e!=null&&e.isScaleUpdated)this.updateHandlePoints();else{const o=s[0]-i[0],a=s[1]-i[1];this.handlePointsArr.forEach(l=>{const c=l.dynamicPosition[0]+o,h=l.dynamicPosition[1]+a;l.internalUpdate({dynamicPosition:[c,h]})})}}return[this.draw,this]}}}function Ns(r,n,t,e,i,s=1,o=1){const a=r+t*Math.cos(e)*s,l=n+t*Math.sin(e)*o,c=r+t*Math.cos(i)*s,h=n+t*Math.sin(i)*o;return[[a,l],[c,h]]}class ge extends R{constructor(t){super(t);f(this,"handlePoints");f(this,"isShowHandlePoint",!1);f(this,"_isHandlePointsVisible",!0);f(this,"_radiusValue",0);f(this,"_radiusPosition",0);f(this,"defaultClick",(t,e)=>{var o;if(!this.isHandlePointsVisible)return;const{state:i,oldState:s}=t.data;i!=s&&((o=this.notifyReload)==null||o.call(this))});f(this,"defaultDragg",(t,e)=>{this.mainCanvas});["isHandlePointsVisible"].forEach(e=>{e in t&&(this["_"+e]=t[e])}),this.addEventListener("click",this.defaultClick),this.addEventListener("dragg",this.defaultDragg)}get handlePointsArr(){if(this.handlePoints){const{radius:t,other:e}=this.handlePoints;return[t,...e].filter(Boolean).sort((i,s)=>(i.isHover||i==t?0:1)-(s.isHover||s==t?0:1))}return[]}get isHandlePointsVisible(){return this._isHandlePointsVisible}set isHandlePointsVisible(t){var e;this._isHandlePointsVisible!==t&&(this._isHandlePointsVisible=t,this.isShowHandlePoint!=t&&((e=this.notifyReload)==null||e.call(this)))}get radiusValue(){return this._radiusValue}set radiusValue(t){this._radiusValue!=t&&(this._radiusValue=t,this.updateBaseData())}get radiusPosition(){return this._radiusPosition}set radiusPosition(t){this._radiusPosition!=t&&(this._radiusPosition=t,this.updateBaseData())}updateValueScope(){this.initValueScope()}isPointInPath(t,e){return!1}isPointInStroke(t,e){return this.path&&this.mainCanvas?(this.setOverlayStyles(R.ctx),this.isDraggable&&(R.ctx.lineWidth=Math.max(R.ctx.lineWidth,20)),R.ctx.isPointInStroke(this.path,t,e)):!1}isPointInAnywhere(t,e){return(s=>{if(!s)return!1;let o=!1;return this.handlePointsArr.forEach(a=>{o?a.isHover&&a.notifyHover(!1):(o=a.isPointInAnywhere(t,e),o!=a.isHover&&a.notifyHover(o))}),o})(this.isClick&&this.isShowHandlePoint)||super.isPointInAnywhere(t,e)}get cursorStyle(){var e;const t=(e=this.handlePoints)==null?void 0:e.radius.isHover;return this.isDraggable?"_nhanh_canvas_hover_overlay_draggable"+(t?"_ns":""):"_nhanh_canvas_hover_overlay"}setOverlayStyles(t){var o;const e=this.mainCanvas,i=e.style[e.theme].arcTo;let s={};return typeof this.style=="string"?s=((o=e.style[this.style])==null?void 0:o.arcTo)||i:typeof this.style=="object"?s=ct(JSON.parse(JSON.stringify(i)),this.style):s=i,t&&this.setBaseLineStyle(t,s.stroke),s}get computedValueScopeStyles(){return this.setOverlayStyles()}updateHandlePoints(){var c,h;let{value:t,position:e,dynamicPosition:i,isHandlePointsVisible:s}=this;if(!i||!s)return;const o=()=>new lt({value:[0,0],mainCanvas:this.mainCanvas,isDraggable:!0,notifyReload:()=>{var u;return(u=this.notifyReload)==null?void 0:u.call(this)}}),a=((c=this.handlePoints)==null?void 0:c.other)||[];t==null||t.forEach((u,d)=>{a[d]||a.push(o()),a[d].internalUpdate({value:t[d],position:e[d],dynamicPosition:i[d]},!0)}),a.length=t.length;const l=((h=this.handlePoints)==null?void 0:h.radius)||o();this.handlePoints={radius:l,other:a}}updateBaseData(){if(!this.mainCanvas)return;let{value:t,position:e}=this;const[i,s]=[Mt(t)&&t.length>1,Mt(e)&&e.length>1];if(!i&&!s)return this.handlePoints=void 0,this.internalUpdate({dynamicPosition:void 0});if(i){e=[];for(let a=0;a<t.length;a++){const l=t[a],c=this.mainCanvas.getAxisPointByValue(l[0],l[1],!0);e.push([c.x,c.y])}}else{t=[];for(let a=0;a<e.length;a++){const l=e[a],c=this.mainCanvas.getAxisValueByPoint(l[0],l[1],!0);t.push([c.xV,c.yV])}}const o=this.mainCanvas.transformPosition(e);this.internalUpdate({value:t,position:e,dynamicPosition:o}),this.updateHandlePoints()}draw(t){const{dynamicPosition:e,mainCanvas:i,radiusValue:s}=this}getDraw(){if(this.isNeedRender){if(this.isRecalculate){const{position:t,mainCanvas:e}=this,i=this.dynamicPosition,s=e.transformPosition(t);if(this.internalUpdate({dynamicPosition:s}),this.isHandlePointsVisible)if(e!=null&&e.isScaleUpdated)this.updateHandlePoints();else{const o=s[0][0]-i[0][0],a=s[0][1]-i[0][1];this.handlePointsArr.forEach(l=>{const c=l.dynamicPosition[0]+o,h=l.dynamicPosition[1]+a;l.internalUpdate({dynamicPosition:[c,h]})})}}return[this.draw,this]}}}class As extends ks{constructor(t){super(t);f(this,"resizeObserver");f(this,"currentDrawOverlays",[]);f(this,"rely","");f(this,"maxMinValue",{minXV:0,maxXV:0,minYV:0,maxYV:0});f(this,"measureRedrawPerformance",He(()=>{this.isRendering=!0,this.redraw(),this.redrawInNextRenderFrame=!1,this.isRendering=!1},{level:[[1,"#F56C6C"],[.5,"#E6A23C"],[0,"#67C23A"]]}));this.canvas&&(this.resizeObserver=new ResizeObserver(we(()=>{[this.canvas.width,this.canvas.height]=[this.rect.width,this.rect.height],this.redrawOnce()},200)),this.resizeObserver.observe(this.canvas)),this.updateRely(),this.isRecalculate=!1}updateRely(){const{center:t,scale:e,rect:i,axisConfig:s}=this,o=[t.x,t.y,e,JSON.stringify(s),i.width,i.height].join();this.isRecalculate=this.rely!==o,this.rely=o}redraw(){var s,o;if(!this.canvas)return console.warn("canvas is not HTMLCanvasElement");if(this.canvas.clientWidth==0||this.canvas.clientHeight==0)return console.warn("The image argument is a canvas element with a width or height of 0.");if(!this.shouldRender())return this.clearScreen(!1);this.ctx.globalAlpha=this.opacity??1,this.updateCenter(),this.updateRely(),this.maxMinValue=this.getMaxMinValue(),this.clearScreen();const t=[];let e=[];const i=(s=this.drawAxis)==null?void 0:s.drawAxisAndGrid();i&&e.push([0,i,[]]),this.layerGroups.forEach(a=>e.push(...a.fetchCanvas())),e.sort((a,l)=>a[0]-l[0]),e.forEach(([,a,l],c)=>{this.ctx.drawImage(a,0,0),l.forEach(([[h,u],d])=>{t.push([[h+c,u],d])})}),t.sort(([[a,l],c],[[h,u],d])=>{if(a!==h)return h-a;if(l!==u)return u-l;const m=g=>g instanceof Gt?5:g instanceof Xt?4:g instanceof lt?3:g instanceof Yt||g instanceof pe||g instanceof ge?2:g instanceof zt?1:0;return m(d)-m(c)}),this.currentDrawOverlays=t.map(([,a])=>a),this.isRecalculate=!1,this.isThemeUpdated=!1,this.isScaleUpdated=!1,(o=this.notifyReload)==null||o.call(this)}redrawOnce(){this.redrawInNextRenderFrame||(this.redrawInNextRenderFrame=!0,Promise.resolve().then(()=>{this.isRendering=!0,this.redraw(),this.redrawInNextRenderFrame=!1,this.isRendering=!1}))}findOverlayByPoint(t){const{offsetX:e,offsetY:i,clientX:s,clientY:o}=t,{x:a,y:l}=this.axisConfig,c=this.getMousePositionOnAxis({clientX:s-10*a,clientY:o-10*l}),h=this.getMousePositionOnAxis({clientX:s+10*a,clientY:o+10*l}),u=this.getAxisValueByPoint(c.x,c.y),d=this.getAxisValueByPoint(h.x,h.y);return[...this.currentDrawOverlays].sort((m,g)=>(m.isDraggable&&m.isClick?0:1)-(g.isDraggable&&g.isClick?0:1)).find(m=>{const g=m.valueScope;return g&&(g.maxX<u.xV||g.minX>d.xV||g.maxY<u.yV||g.minY>d.yV)?!1:m.isPointInAnywhere(e,i)})}destroy(){var t;(t=this.resizeObserver)==null||t.disconnect()}}class Is extends As{constructor(t){super(t);f(this,"mouseInCanvas",!1);f(this,"mouseIsDown",!1);f(this,"mouseLastPosition",{x:0,y:0});f(this,"unBind");f(this,"lastClickedOverlay");f(this,"lockNotifyClick",!1);f(this,"lastContextmenuOverlay");f(this,"defaultContextmenu",(t,e)=>{const i=this.lastClickedOverlay;i!=null&&i.isDraggable&&i.notifyClick(!1,e)});f(this,"lastPressedKey",{key:"",keyupTime:0,doubleClick:!1});f(this,"defaultWheel",(t,e)=>{this.setScale(e,t.data),this.redrawOnce()});f(this,"lastDownOverlay");f(this,"defaultDown",(t,e)=>{(e==null?void 0:e.button)==0&&(this.mouseIsDown=!0)});f(this,"lastHoverOverlay");f(this,"lastCursorStyle");f(this,"oldClientX",[]);f(this,"oldClientY",[]);this.initEvent(),this.addEventListener("contextmenu",this.defaultContextmenu),this.addEventListener("down",this.defaultDown),this.addEventListener("wheel",this.defaultWheel)}initEvent(){const{canvas:t}=this;if(!t)return console.error("canvas is not HTMLCanvasElement");const e=[{type:"click",handler:this.click.bind(this)},{type:"contextmenu",handler:this.contextmenu.bind(this)},{type:"mouseenter",handler:this.mouseenter.bind(this)},{type:"mouseleave",handler:this.mouseleave.bind(this)},{type:"keydown",handler:this.keydown.bind(this),target:window},{type:"keyup",handler:this.keyup.bind(this),target:window},{type:"wheel",handler:this.wheel.bind(this)},{type:"mousedown",handler:this.mousedown.bind(this)},{type:"mouseup",handler:this.mouseup.bind(this),target:window},{type:"mousemove",handler:this.mousemove.bind(this),target:window},{type:"touchend",handler:this.touchend.bind(this)},{type:"touchmove",handler:this.touchmove.bind(this)}];e.forEach(({type:i,handler:s,target:o=t})=>{o.addEventListener(i,s)}),this.unBind=()=>{e.forEach(({type:i,handler:s,target:o=t})=>{o.removeEventListener(i,s)})}}click(t){var i;if(!this.isClickable)return;if(this.lockNotifyClick)return this.lockNotifyClick=!1;const e=this.findOverlayByPoint(t);this.lastClickedOverlay!=e&&((i=this.lastClickedOverlay)==null||i.notifyClick(!1,t)),e==null||e.notifyClick(!0,t),this.lastClickedOverlay=e,this.notifyClick(!0,t)}contextmenu(t){var i;if(!this.isContextmenuable)return;t.preventDefault();const e=this.findOverlayByPoint(t);this.lastContextmenuOverlay!=e&&((i=this.lastContextmenuOverlay)==null||i.notifyContextmenu(!1,t)),e==null||e.notifyContextmenu(!0,t),this.lastContextmenuOverlay=e,this.notifyContextmenu(!0,t)}mouseenter(t){this.mouseInCanvas=!0}mouseleave(t){this.mouseInCanvas=!1}getStep(t){const{lastPressedKey:e}=this;return e.doubleClick?4:e.key===t&&Date.now()-e.keyupTime<300?(e.doubleClick=!0,4):1}keydown(t){const{mouseInCanvas:e,offset:i,delta:s,axisConfig:o}=this,a=t.key;if(!e||!this.isDraggable||this.isAuto)return;const l=this.getStep(a),c=this.lastClickedOverlay,u=(c==null?void 0:c.isDraggable)&&this.currentDrawOverlays.includes(c)&&(Mt(c.value)?"Matrix":ee(c.value)?"Single":!1),d=(v,w)=>{if(!u)return i.x+=v*l,i.y+=w*l,!0;const _=this.getAxisValueByPoint(l,0).xV,[C,E]=[_*o.x,_*o.y];if(u==="Single"){const N=c.value;N[0]+=v*C,N[1]+=w*E}else c.value.forEach(N=>{N[0]+=v*C,N[1]+=w*E});return c.value=[...c.value],!0},m=v=>(this.setScale("center",v*s),!0),p={ArrowUp:()=>d(0,-1),ArrowDown:()=>d(0,1),ArrowLeft:()=>d(-1,0),ArrowRight:()=>d(1,0),"+":()=>m(1),"-":()=>m(-1)}[a];p!=null&&p()&&(this.redrawOnce(),t.preventDefault())}keyup(t){const{mouseInCanvas:e,lastPressedKey:i}=this;if(e){const s=t.key;i.key=s,i.keyupTime=Date.now(),i.doubleClick=!1}}wheel(t){if(!this.isWheelable)return;t.preventDefault();const{delta:e,isAuto:i}=this;if(i)return;const s=t.deltaY<0?e:-e,o=this.findOverlayByPoint(t);o==null||o.notifyWheel(s,t),this.notifyWheel(s,t)}mousedown(t){var o;if(!this.isDownable)return;const{clientX:e,clientY:i}=t;this.mouseLastPosition={x:e,y:i};const s=this.findOverlayByPoint(t);this.lastDownOverlay!=s&&((o=this.lastDownOverlay)==null||o.notifyDown(!1,t),s==null||s.notifyDown(!0,t)),this.lastDownOverlay=s,this.notifyDown(!0,t)}mouseup(t){this.mouseIsDown=!1,this.lastDownOverlay=void 0}mousemove(t){this.isAuto||(this.canvas.classList.toggle("_nhanh_canvas_draggable",this.isDraggable),this.mouseIsDown?this.handleDragMove(t):this.handleHover(t))}handleDragMove(t){if(!this.isDraggable)return;const{clientX:e,clientY:i}=t,s={x:e,y:i};if(JSON.stringify(s)==JSON.stringify(this.mouseLastPosition))return;const{lastDownOverlay:o}=this;o!=null&&o.isDraggable?this.notifyDraggOverlays(t):this.handleCanvasPan(t),this.mouseLastPosition=s,this.lockNotifyClick=!0}notifyDraggOverlays(t){const e=this.lastDownOverlay,{mouseLastPosition:i}=this,{clientX:s,clientY:o}=t;e.notifyDragg({offsetX:s-i.x,offsetY:o-i.y},t)}handleCanvasPan(t){const{clientX:e,clientY:i}=t,{offset:s,mouseLastPosition:o}=this,a=e-o.x,l=i-o.y;s.x+=a,s.y+=l,this.redrawOnce(),this.notifyDragg({offsetX:a,offsetY:l},t)}handleHover(t){if(!this.isHoverable||t.target!=this.canvas)return;const e=this.findOverlayByPoint(t);this.updateHoverState(e,t),this.notifyHover(!0,t)}updateHoverState(t,e){if(this.lastHoverOverlay===t){const s=t==null?void 0:t.cursorStyle;s!==this.lastCursorStyle&&(this.lastCursorStyle&&this.canvas.classList.remove(this.lastCursorStyle),s&&this.canvas.classList.add(s),this.lastCursorStyle=s);return}this.lastHoverOverlay&&t&&t.hasController("hover",this.lastHoverOverlay)||(this.clearHoverState(e),this.applyHoverState(t,e)),this.lastHoverOverlay=t}clearHoverState(t){this.lastHoverOverlay&&(this.lastHoverOverlay.notifyHover(!1,t),this.lastHoverOverlay.cursorStyle&&this.canvas.classList.remove(this.lastHoverOverlay.cursorStyle))}applyHoverState(t,e){t&&(t.notifyHover(!0,e),this.lastCursorStyle=t.cursorStyle,this.lastCursorStyle&&this.canvas.classList.add(this.lastCursorStyle))}touchend(t){this.oldClientX=this.oldClientY=[]}touchmove(t){if(!this.isDraggable)return;const e=t.touches;t.preventDefault();const{oldClientX:i,oldClientY:s,offset:o,delta:a,isAuto:l,isDraggable:c}=this;if(c&&!l){if(e.length===1){const{clientX:h,clientY:u}=e[0];i.length&&(o.x+=h-i[0],o.y+=u-s[0],this.redrawOnce()),this.oldClientX=[h],this.oldClientY=[u]}else if(e.length===2){const{clientX:h,clientY:u}=e[0],{clientX:d,clientY:m}=e[1];if(i.length==2){const g=ye(i[0],s[0],i[1],s[1]),p=ye(h,u,d,m),{x:v,y:w}=be(h,u,d,m);this.setScale({clientX:v,clientY:w},p>g?a:-a),this.redrawOnce()}this.oldClientX=[h,d],this.oldClientY=[u,m]}}}destroy(){var t;super.destroy(),(t=this.unBind)==null||t.call(this)}}class et extends Nt{constructor(t){super(t);f(this,"overlays",new Set);this.setNotifyReload(t.notifyReload)}setMainCanvas(t){var e;super.setMainCanvas(t),this.overlays.forEach(i=>{i.setMainCanvas(t),i.parent=this}),t&&this.overlays.size&&((e=this.notifyReload)==null||e.call(this))}setNotifyReload(t){this.notifyReload=t?e=>{e&&(this.isRecalculate=!0),(e||this.shouldRender()&&this.overlays.size)&&t()}:void 0,this.overlays.forEach(e=>e.setNotifyReload(this.notifyReload))}addOverlays(t){var e;[t].flat().forEach(i=>{i.setNotifyReload(this.notifyReload),i.setMainCanvas(this.mainCanvas),i.parent=this,this.overlays.add(i)}),(e=this.notifyReload)==null||e.call(this)}hasOverlay(t){return this.overlays.has(t)}removeOverlays(t){var e;[t].flat().forEach(i=>{this.overlays.delete(i),i.setNotifyReload(),i.setMainCanvas(),i.parent=void 0}),(e=this.notifyReload)==null||e.call(this)}clearOverlays(){var t;(t=this.notifyReload)==null||t.call(this),this.overlays.forEach(e=>{e.setNotifyReload(),e.setMainCanvas(),e.parent=void 0}),this.overlays.clear()}getOverlaysDrawingMethod(){const t=[];return this.shouldRender()&&this.overlays.size&&Array.from(this.overlays.values()).sort((e,i)=>e.zIndex-i.zIndex).forEach(e=>{if(e.equalsMainCanvas(this.mainCanvas)){const i=e.getDraw();i&&t.push([Number(e.zIndex)||0,i])}else this.overlays.delete(e)}),t}}class it extends Nt{constructor(t){super(t);f(this,"zIndex",4);f(this,"canvas",document.createElement("canvas"));f(this,"ctx",this.canvas.getContext("2d"));f(this,"isReload",!1);f(this,"groups",new Map);f(this,"currentDrawOverlays",[]);this.setNotifyReload(t.notifyReload)}setMainCanvas(t){super.setMainCanvas(t),this.canvas.width=(t==null?void 0:t.rect.width)||0,this.canvas.height=(t==null?void 0:t.rect.height)||0,this.groups.forEach(e=>{e.setMainCanvas(t),e.parent=this})}setNotifyReload(t){this.notifyReload=t?e=>{e&&(this.isRecalculate=!0),(e||this.shouldRender()&&this.groups.size)&&t()}:void 0,this.groups.forEach(e=>this.setGroupNotifyReload(e))}setGroupNotifyReload(t){t.setNotifyReload(this.notifyReload?()=>{var e;(e=this.notifyReload)==null||e.call(this),this.isReload=!0}:void 0)}getGroup(t){return this.groups.get(t)}addGroup(t){[t].flat().forEach(e=>{e instanceof et&&(this.setGroupNotifyReload(e),e.setMainCanvas(this.mainCanvas),e.parent=this,this.groups.set(e.name,e))})}removeGroup(t){var i;let e=!1;[t].flat().forEach(s=>{s instanceof et&&(this.groups.delete(s.name),s.setNotifyReload(),s.setMainCanvas(),s.parent=void 0,e=!0)}),e&&((i=this.notifyReload)==null||i.call(this))}clearGroup(){var t;this.groups.size&&(this.groups.forEach(e=>{e.setNotifyReload(),e.setMainCanvas(),e.parent=void 0}),this.groups.clear(),(t=this.notifyReload)==null||t.call(this))}setzIndex(t){var e;t!=this.zIndex&&(this.zIndex=t,(e=this.notifyReload)==null||e.call(this,!1))}getCanvas(){if(!this.mainCanvas)return;const{rect:t,isThemeUpdated:e}=this.mainCanvas,i=this.shouldRender(),s=this.groups.size;if(i&&s){if(this.isReload||this.isRecalculate||e){this.currentDrawOverlays=[],this.isReload=!1,this.canvas.width=t.width||0,this.canvas.height=t.height||0;const o=[];this.groups.forEach(a=>{a.equalsMainCanvas(this.mainCanvas)?o.push(...a.getOverlaysDrawingMethod()):this.groups.delete(a.name)}),o.sort((a,l)=>a[0]-l[0]),o.forEach(([a,[l,c]])=>{l.call(c,this.ctx),this.currentDrawOverlays.push([[Number(this.zIndex)||0,a],c])})}return[Number(this.zIndex)||0,this.canvas,this.currentDrawOverlays]}}}class Rt extends Nt{constructor(t){super(t);f(this,"layers",new Map);f(this,"defaultContextmenu",(t,e)=>t.stopPropagation());f(this,"defaultClick",(t,e)=>t.stopPropagation());f(this,"defaultDoubleClick",(t,e)=>t.stopPropagation());f(this,"defaultHover",(t,e)=>t.stopPropagation());f(this,"defaultDragg",(t,e)=>t.stopPropagation());f(this,"defaultDown",(t,e)=>t.stopPropagation());this.inheritOpacity=!1,this.setNotifyReload(t.notifyReload),this.addEventListener("contextmenu",this.defaultContextmenu),this.addEventListener("click",this.defaultClick),this.addEventListener("doubleClick",this.defaultDoubleClick),this.addEventListener("hover",this.defaultHover),this.addEventListener("dragg",this.defaultDragg),this.addEventListener("down",this.defaultDown)}setMainCanvas(t){super.setMainCanvas(t),this.layers.forEach(e=>{e.setMainCanvas(t),e.parent=this})}setNotifyReload(t){this.notifyReload=t?e=>{e&&(this.isRecalculate=!0),(e||this.shouldRender()&&this.layers.size)&&t()}:void 0,this.layers.forEach(e=>e.setNotifyReload(this.notifyReload))}getLayer(t){return this.layers.get(t)}addLayer(t){[t].flat().forEach(e=>{e instanceof it&&(e.setNotifyReload(this.notifyReload),e.setMainCanvas(this.mainCanvas),e.parent=this,this.layers.set(e.name,e))})}removeLayer(t){var i;let e=!1;[t].flat().forEach(s=>{s instanceof it&&(this.layers.delete(s.name),s.setNotifyReload(),s.setMainCanvas(),s.parent=void 0,e=!0)}),e&&((i=this.notifyReload)==null||i.call(this))}clearLayers(){var t;this.layers.size&&(this.layers.forEach(e=>{e.setNotifyReload(),e.setMainCanvas(),e.parent=void 0}),this.layers.clear(),(t=this.notifyReload)==null||t.call(this))}fetchCanvas(){if(this.shouldRender()&&this.layers.size){const t=[];return this.layers.forEach(e=>{if(e.equalsMainCanvas(this.mainCanvas)){const i=e.getCanvas();i&&t.push(i)}else this.layers.delete(e.name)}),t}return[]}}class Hs extends Is{getDefaultOverlayGroup(){var a,l,c,h,u;const n=this.layerGroups.get("默认图层群组");if(!n)return;const t=(a=n.getLayer("点位图层"))==null?void 0:a.getGroup("点位覆盖物群组"),e=(l=n.getLayer("线段图层"))==null?void 0:l.getGroup("线段覆盖物群组"),i=(c=n.getLayer("多边形图层"))==null?void 0:c.getGroup("多边形覆盖物群组"),s=(h=n.getLayer("文字图层"))==null?void 0:h.getGroup("文字覆盖物群组"),o=(u=n.getLayer("自定义绘制图层"))==null?void 0:u.getGroup("自定义绘制覆盖物群组");return{overlays_text:s,overlays_point:t,overlays_line:e,overlays_polygon:i,overlays_custom:o}}getAllOverlays(n){const t=[],e=n!==void 0?Array.isArray(n)?[...n]:[n]:Array.from(this.layerGroups.values());for(;e.length>0;){const i=e.pop();if(i instanceof Rt){if(!i.isVisible)continue;e.push(...i.layers.values())}else if(i instanceof it){if(!i.isVisible)continue;e.push(...i.groups.values())}else if(i instanceof et){if(!i.isVisible)continue;e.push(...i.overlays.values())}else i.isVisible&&t.push(i)}return t}}class Ls extends Hs{zoom(n){const{canvas:t,rect:e}=this;if(!t||!e)return console.error("canvas is not HTMLCanvasElement");this.setScale("center",n),this.redrawOnce()}zoomIn(){this.zoom(this.delta)}zoomOut(){this.zoom(-this.delta)}setStyle(n){super.setStyle(n),this.redrawOnce()}setTheme(n){super.setTheme(n),this.redrawOnce()}setAxis(n){super.setAxis(n),this.redrawOnce()}setDefaultCenter(n){super.setDefaultCenter(n),this.redrawOnce()}}class Ts extends Ls{setFitView(n=void 0,t=!1,e=[60,60,60,60],i){const s=this.getAllOverlays(n);if(s.length===0)return;const{minX:o,maxX:a,minY:l,maxY:c}=this.calculateBoundingBox(s),h=a-o,u=c-l,d=this.calculateOptimalScale(h,u,e,i),m=this.calculateOffsetDifference(o,a,l,c,e);d==this.scale&&m.x==0&&m.y==0||(t?this.applyTransformImmediately(d,m):this.animateTransform(d,m))}calculateBoundingBox(n){let t=1/0,e=-1/0,i=1/0,s=-1/0;for(const o of n){const a=o.valueScope;t=Math.min(t,a.minX),e=Math.max(e,a.maxX),i=Math.min(i,a.minY),s=Math.max(s,a.maxY)}return{minX:t,maxX:e,minY:i,maxY:s}}calculateOptimalScale(n,t,e,i){const{cycle:s,delta:o,axisConfig:a,rect:l}=this,{width:c,height:h}=l,u=Math.max(0,c-e[1]-e[3])||c,d=Math.max(0,h-e[0]-e[2])||h;if(u<=0||d<=0)return console.warn("无效的可视区域尺寸,边距设置可能不合理"),this.scale;const m=n/u,g=t/d,p=Math.max(m,g),v=a.count,w=v/a.min,_=s*o;let C;if(p>w){const E=Math.ceil(p/w);C=1-((v*E/p-a.min)/a.min+(E-2))*_}else{const E=(dt,rt,vt)=>dt<rt?vt-1:E(dt/2,rt,vt+1),N=E(w,p,0),G=Math.pow(2,N);C=1+((v/G/p-a.min)/a.min+N)*_}return i!==void 0&&(C=Math.min(i,C)),C=new V(C).div(o).round().mul(o).toNumber(),C}calculateOffsetDifference(n,t,e,i,s){const{width:o,height:a}=this.rect,{axisConfig:l,center:c}=this,h=(t+n)/2,u=(i+e)/2,d=this.getAxisPointByValue(h,u),m=this.getAxisValueByPoint((o/2-c.x)*l.x,(a/2-c.y)*l.y),g=this.getAxisPointByValue(m.xV,m.yV);return{x:Math.round(-(d.x+(s[3]-s[1])-g.x)*l.x),y:Math.round(-(d.y+(s[0]-s[2])-g.y)*l.y)}}applyTransformImmediately(n,t){this.offset={x:this.offset.x+t.x,y:this.offset.y+t.y},this.scale=n,this.updateSize(),this.redrawOnce()}animateTransform(n,t){const e=this.scale,i={...this.offset},s=300;this.isAuto=!0;const o=()=>this.isAuto=!1;(c=>this.animateOffset(i,t,s,c||o))(c=>this.animateScale(e,n,s,c||o))}animateScale(n,t,e,i){const s=t-n;let o=0;kt(a=>{!this.isAuto||!this.canvas||!this.isInteractive||(this.setScale("center",(a-o)*s),o=a,this.redrawOnce(),a===1&&i())},e)}animateOffset(n,t,e,i){kt(s=>{!this.isAuto||!this.canvas||!this.isInteractive||(this.offset={x:Number((n.x+t.x*s).toFixed(0)),y:Number((n.y+t.y*s).toFixed(0))},this.redrawOnce(),s===1&&i())},e)}returnToOrigin(){if(!this.isInteractive||this.scale==this.defaultScale&&this.offset.x==0&&this.offset.y==0)return;const{rect:n,axisConfig:t}=this,e=this.getDefaultCenterLocation(),i=(n.width/2-e.x)*t.x,s=(n.height/2-e.y)*t.y,o=this.getAxisValueByPoint(i,s,!0),a=this.getMousePositionOnAxis({clientX:n.x+n.width/2,clientY:n.y+n.height/2}),l=this.getAxisValueByPoint(a.x,a.y),c=t.size/this.getNowGridCount,h=Math.round((l.xV-o.xV)*t.x*c),u=Math.round((l.yV-o.yV)*t.y*c);h==0&&u==0||this.animateTransform(this.defaultScale,{x:h,y:u})}}class Fs extends Ts{toggleAxis(n){this.drawAxis.toggleAxis(n),this.redrawOnce()}togglePoint(n){const{overlays_point:t}=this.getDefaultOverlayGroup()||{};return t?(t.isVisible=n??!t.isVisible,this.redrawOnce(),t.isVisible):!1}toggleLine(n){const{overlays_line:t}=this.getDefaultOverlayGroup()||{};return t?(t.isVisible=n??!t.isVisible,this.redrawOnce(),t.isVisible):!1}togglePolygon(n){const{overlays_polygon:t}=this.getDefaultOverlayGroup()||{};return t?(t.isVisible=n??!t.isVisible,this.redrawOnce(),t.isVisible):!1}toggleLock(n){return this.isInteractive=n??!this.isInteractive,this.isInteractive}}class Bs extends Fs{static clearPathRegion(n,t){const{width:e,height:i}=n.canvas;n.save(),n.beginPath(),n.clip(t),n.clearRect(0,0,e,i),n.restore()}}class Us extends Bs{}class Gs{constructor(n){f(this,"canvas");f(this,"axis_canvas",document.createElement("canvas"));f(this,"ctx",this.axis_canvas.getContext("2d"));f(this,"isReload",!0);f(this,"show",{all:!0,grid:{main:!0,secondary:!0},axis:!0,axisText:!0});this.canvas=n,this.initAxisCanvas()}initAxisCanvas(){const{canvas:n,axis_canvas:t}=this;n&&(t.width=n.rect.width||0,t.height=n.rect.height||0)}toggleAxis(n){const t=(()=>{if(typeof n=="object"){const{all:e=!0,axis:i=!0,axisText:s=!0}=n,o=Object.assign({main:!0,secondary:!0},n.grid);return{all:e,grid:o,axis:i,axisText:s}}return typeof n=="boolean"?{all:!0,grid:{main:n,secondary:n},axis:n,axisText:n}:!this.show.all})();typeof t=="boolean"?this.show.all=t:this.show=t,this.isReload=!0}drawAxisAndGrid(){if(!(!this.canvas||!this.show.all))return(this.canvas.isRecalculate||this.isReload||this.canvas.isThemeUpdated)&&(this.isReload=!1,this.initAxisCanvas(),(this.show.grid.main||this.show.grid.secondary)&&this.drawGrid(),this.show.axis&&this.drawAxis(),this.show.axisText&&this.drawAxisText()),this.axis_canvas}color(){const{theme:n,style:t}=this.canvas;return(t[n]||t.light).grid}drawGrid(){const{canvas:n,ctx:t}=this,{rect:e,center:i,axisConfig:s}=n,{width:o,height:a}=e,l=this.color(),c=s.size,h=c/5;t.lineWidth=1;const u=(m,g)=>{const p=i.x%m>0?i.x%m:m+i.x%m;t.strokeStyle=g,t.beginPath();for(let v=0;v*m+p<=o;v++)t.moveTo(v*m+p,0),t.lineTo(v*m+p,a);t.stroke()},d=(m,g)=>{const p=i.y%m>0?i.y%m:m+i.y%m;t.strokeStyle=g,t.beginPath();for(let v=0;v*m+p<=a;v++)t.moveTo(0,v*m+p),t.lineTo(o,v*m+p);t.stroke()};this.show.grid.secondary&&(u(h,l.innerGrid),d(h,l.innerGrid)),this.show.grid.main&&(u(c,l.grid),d(c,l.grid))}drawAxis(){const{canvas:n,ctx:t}=this,{rect:e,center:i}=n,{width:s,height:o}=e,a=this.color();t.lineWidth=2,t.strokeStyle=a.axis;const l=()=>{i.y>=0&&i.y<=o&&(t.beginPath(),t.moveTo(0,i.y),t.lineTo(s,i.y),t.stroke())},c=()=>{i.x>=0&&i.x<=s&&(t.beginPath(),t.moveTo(i.x,0),t.lineTo(i.x,o),t.stroke())};l(),c()}drawText(n,t,e,i){const{canvas:s,ctx:o}=this,{theme:a}=s,l=this.canvas.style[a].text;o.font=`${l.bold?"bold":""} ${l.size}px ${l.family}`,o.strokeStyle=l.stroke,![n,t,e].includes(void 0)&&o.strokeText(n,t,e),o.fillStyle=l[i?"secondary":"color"],![n,t,e].includes(void 0)&&o.fillText(n,t,e)}drawAxisText(){const{canvas:n,ctx:t}=this,{rect:e,center:i,axisConfig:s,style:o,theme:a}=n,{width:l,height:c}=e;this.drawText();const h=p=>Math.ceil(t.measureText(p).width),u=4,d=o[a].text.size;{const p=h("0"),v=i.x<u||i.x>l+p+u,w=i.y<-(u+d)||i.y>c+d+u;!v&&!w&&this.drawText("0",i.x-p-u,i.y+d+u)}const m=n.getNowGridCount,g=s.size;{let p=i.y+d+u;p=Math.max(Math.min(p,c-u),u+d);const v=i.y>c||i.y<0;let w=i.x>0?i.x%g:i.x<0?g+i.x%g:0,_=n.getAxisValueByPoint((w-i.x)*s.x,0).xV;for(;w<=l;){const C=Wt(_),E=h(C);_!==0&&this.drawText(C,w-E/2,p,v),w+=g,_=new V(m).mul(s.x).add(_).toNumber()}}{const p=i.x>l||i.x<0;let v=i.y>0?i.y%g:i.y<0?g+i.y%g:0,w=n.getAxisValueByPoint(0,(v-i.y)*s.y).yV;for(;v<=c;){const _=Wt(w),C=h(_);let E=i.x-C-u;E=Math.max(Math.min(E,l-C-u),u),w!=0&&this.drawText(_,E,v+d/2,p),v+=g,w=new V(m).mul(s.y).add(w).toNumber()}}}}function Tt(r){return[r].flat(1/0)}class Y extends Us{constructor(n){super(n),this.drawAxis=new Gs(this),"axisShow"in n&&this.toggleAxis(n.axisShow),this.initLayerGroups(),this.updateCenter()}initLayerGroups(){const n=new it({name:"多边形图层"});n.addGroup(new et({name:"多边形覆盖物群组"})),n.setzIndex(1);const t=new it({name:"线段图层"});t.addGroup(new et({name:"线段覆盖物群组"})),t.setzIndex(2);const e=new it({name:"点位图层"});e.addGroup(new et({name:"点位覆盖物群组"})),e.setzIndex(3);const i=new it({name:"文字图层"});i.addGroup(new et({name:"文字覆盖物群组"})),i.setzIndex(4);const s=new it({name:"自定义绘制图层"});s.addGroup(new et({name:"自定义绘制覆盖物群组"})),s.setzIndex(5);const o=new Rt({name:"默认图层群组"});o.addLayer([i,e,t,n,s]),this.setLayerGroup(o)}gteLayerGroups(n="默认图层群组"){return this.layerGroups.get(n)}setLayerGroup(n){n instanceof Rt&&(this.layerGroups.set(n.name,n),n.setNotifyReload(()=>this.redrawOnce()),n.setMainCanvas(this),n.parent=this)}removeLayerGroup(n){n instanceof Rt&&(this.layerGroups.delete(n.name),n.setNotifyReload(),n.setMainCanvas(),n.parent=void 0,this.redrawOnce())}addLayer(n){const t=this.layerGroups.get("默认图层群组");t&&t.addLayer(Tt(n))}removeLayer(n){const t=this.layerGroups.get("默认图层群组");t&&t.removeLayer(Tt(n))}addOverlay(n){const{overlays_text:t,overlays_point:e,overlays_line:i,overlays_polygon:s,overlays_custom:o}=this.getDefaultOverlayGroup()||{};Tt(n).forEach(a=>{a instanceof Xt?t==null||t.addOverlays(a):a instanceof lt?e==null||e.addOverlays(a):a instanceof Yt||a instanceof pe||a instanceof ge?i==null||i.addOverlays(a):a instanceof zt?s==null||s.addOverlays(a):a instanceof Gt&&(o==null||o.addOverlays(a))})}removeOverlay(n){const{overlays_text:t,overlays_point:e,overlays_line:i,overlays_polygon:s,overlays_custom:o}=this.getDefaultOverlayGroup()||{};Tt(n).forEach(a=>{a instanceof Xt?t==null||t.removeOverlays(a):a instanceof lt?e==null||e.removeOverlays(a):a instanceof Yt?i==null||i.removeOverlays(a):a instanceof zt?s==null||s.removeOverlays(a):a instanceof Gt&&(o==null||o.addOverlays(a))})}destroy(){super.destroy()}}f(Y,"LayerGroup",Rt),f(Y,"Layer",it),f(Y,"OverlayGroup",et),f(Y,"Text",Xt),f(Y,"Point",lt),f(Y,"Line",Yt),f(Y,"Polygon",zt),f(Y,"Custom",Gt),f(Y,"Arc",pe),f(Y,"ArcTo",ge);function Xs(r){const n=we(r,100);let t=0,e=0;return function(i){const s=i.target;if(!s||!(s instanceof Element))return;const{scrollTop:o,scrollHeight:a,clientHeight:l,scrollLeft:c,scrollWidth:h,clientWidth:u}=s;function d(){if(t==o)return;const g=t>o;if(t=o,g)return;a-o-l<=1&&n("vertical")}function m(){if(e==c)return;const g=e>c;if(e=c,g)return;h-c-u<=1&&n("horizontal")}d(),m()}}function Ys(r,n,t){const{isClickAllowed:e,uiLibrary:i=["naiveUI","ElementPlus","Element"]}=t||{},s=function(l){const c=[];for(const h in l)Object.hasOwnProperty.call(l,h)&&i.includes(h)&&c.push(...l[h]);return c}({naiveUI:[".v-binder-follower-container",".n-image-preview-container",".n-modal-container"],ElementPlus:[".el-popper"],Element:[".el-popper"]});function o(){n(),document.removeEventListener("mousedown",a)}function a(l){if(e){const u=e(l);if(u)return;if(u===!1)return o()}const c=l.target;if(!(c instanceof Element)||!c.isConnected)return;r.concat(s).some(u=>!!(c!=null&&c.closest(u)))||o()}requestAnimationFrame(()=>document.addEventListener("mousedown",a))}var z,ft,mt,Pt,xt,Z,Q,st,bt;class zs{constructor(){A(this,z);A(this,ft,!1);A(this,mt,{});A(this,Pt,0);A(this,xt,0);A(this,Z,0);A(this,Q,0);A(this,st);A(this,bt)}init(n,t){D(this,z,n),D(this,st,t==null?void 0:t.limit),D(this,bt,t==null?void 0:t.dragDom),D(this,mt,{mousedown:this.mousedown.bind(this),mousemove:this.mousemove.bind(this),mouseup:this.mouseup.bind(this)}),this.bindOrUnbindEvent("bind")}finish(){this.bindOrUnbindEvent("unbind")}bindOrUnbindEvent(n){const t=n==="bind"?"addEventListener":"removeEventListener";if(!P(this,z))return console.error("No DOM");P(this,z)[t]("mousedown",P(this,mt).mousedown),document[t]("mousemove",P(this,mt).mousemove),document[t]("mouseup",P(this,mt).mouseup)}alterLocation(){if(!P(this,z))return console.error("No DOM");P(this,st)&&(D(this,Z,Math.min(P(this,Z),P(this,st).max.top)),D(this,Z,Math.max(P(this,Z),P(this,st).min.top)),D(this,Q,Math.min(P(this,Q),P(this,st).max.left)),D(this,Q,Math.max(P(this,Q),P(this,st).min.left))),P(this,z).style.setProperty("--top",P(this,Z)+"px"),P(this,z).style.setProperty("--left",P(this,Q)+"px")}mousedown(n){if(!P(this,z))return console.error("No DOM");if(P(this,bt)&&n.target!=P(this,bt))return;document.body.classList.add("no-select"),D(this,ft,!0);const t=P(this,z).getBoundingClientRect(),{pageX:e,pageY:i}=n;D(this,Pt,e),D(this,xt,i),D(this,Z,t.y),D(this,Q,t.x)}mousemove(n){const{pageX:t,pageY:e}=n;P(this,ft)&&(D(this,Z,P(this,Z)+(e-P(this,xt))),D(this,Q,P(this,Q)+(t-P(this,Pt))),D(this,Pt,t),D(this,xt,e),this.alterLocation())}mouseup(){P(this,ft)&&(D(this,ft,!1),document.body.classList.remove("no-select"))}}z=new WeakMap,ft=new WeakMap,mt=new WeakMap,Pt=new WeakMap,xt=new WeakMap,Z=new WeakMap,Q=new WeakMap,st=new WeakMap,bt=new WeakMap;var W,pt,gt,_t,Ct,j,q,B,St,Et;class Ws{constructor(){A(this,W);A(this,pt,!1);A(this,gt,{});A(this,_t,0);A(this,Ct,0);A(this,j,0);A(this,q,0);A(this,B);A(this,St);A(this,Et)}init(n,t={}){D(this,W,n),D(this,B,t.limit),D(this,St,t.update_move),D(this,Et,t.update_up),D(this,gt,{mousedown:this.mousedown.bind(this),mousemove:this.mousemove.bind(this),mouseup:this.mouseup.bind(this)}),this.bindOrUnbindEvent("bind")}finish(){this.bindOrUnbindEvent("unbind")}bindOrUnbindEvent(n){const t=n==="bind"?"addEventListener":"removeEventListener";if(!P(this,W))return console.error("No DOM");P(this,W)[t]("mousedown",P(this,gt).mousedown),document[t]("mousemove",P(this,gt).mousemove),document[t]("mouseup",P(this,gt).mouseup)}updateValue(){const n={top:P(this,j),left:P(this,q),percentage:{top:0,left:0}};if(P(this,B)){const t=e=>P(this,B)?(n[e]-P(this,B).min[e])/(P(this,B).max[e]-P(this,B).min[e]):0;n.percentage={top:t("top")||0,left:t("left")||0}}return n}alterLocation(){if(!P(this,W))return console.error("No DOM");P(this,B)&&(D(this,j,Math.min(P(this,j),P(this,B).max.top)),D(this,j,Math.max(P(this,j),P(this,B).min.top)),D(this,q,Math.min(P(this,q),P(this,B).max.left)),D(this,q,Math.max(P(this,q),P(this,B).min.left))),P(this,St)&&P(this,St).call(this,this.updateValue()),P(this,W).style.setProperty("--top",P(this,j)+"px"),P(this,W).style.setProperty("--left",P(this,q)+"px")}mousedown(n){if(!P(this,W))return console.error("No DOM");document.body.classList.add("no-select"),D(this,pt,!0);const t=P(this,W).getBoundingClientRect();D(this,Ct,t.y),D(this,_t,t.x);const{pageX:e,pageY:i}=n;D(this,j,i-P(this,Ct)),D(this,q,e-P(this,_t)),this.alterLocation()}mousemove(n){const{pageX:t,pageY:e}=n;P(this,pt)&&(D(this,j,e-P(this,Ct)),D(this,q,t-P(this,_t)),this.alterLocation())}mouseup(){P(this,pt)&&(D(this,pt,!1),document.body.classList.remove("no-select"),P(this,Et)&&P(this,Et).call(this,this.updateValue()))}}W=new WeakMap,pt=new WeakMap,gt=new WeakMap,_t=new WeakMap,Ct=new WeakMap,j=new WeakMap,q=new WeakMap,B=new WeakMap,St=new WeakMap,Et=new WeakMap;function re(r){if(typeof r=="string"){const n=document.querySelector(r);if(n)return n;console.error(`Element "${r}" not found`)}else return r||document.documentElement}function $e(r){const n=re(r);return n?n.requestFullscreen?n.requestFullscreen():n.mozRequestFullScreen?n.mozRequestFullScreen():n.webkitRequestFullscreen?n.webkitRequestFullscreen():n.msRequestFullscreen?n.msRequestFullscreen():Promise.reject("No Fullscreen API"):Promise.reject("No Element")}function Ze(){const r=document;return document.exitFullscreen?document.exitFullscreen():r.mozCancelFullScreen?r.mozCancelFullScreen():r.webkitExitFullscreen?r.webkitExitFullscreen():r.msExitFullscreen?r.msExitFullscreen():Promise.reject("No ExitFullscreen API")}function xe(r){const n=re(r),t=document,e=document.fullscreenElement||t.webkitFullscreenElement||t.mozFullScreenElement||t.msFullscreenElement;return n==e||!r&&window.innerWidth==screen.width&&window.innerHeight==screen.height}function js(r){if(r=re(r),!!r)return function(){xe(r)?Ze():$e(r)}}function qs(r,n){const t=re(n);if(!t)return;const e=()=>{r(xe(t))};return document.addEventListener("fullscreenchange",e),document.addEventListener("webkitfullscreenchange",e),document.addEventListener("mozfullscreenchange",e),document.addEventListener("MSFullscreenChange",e),e(),()=>{document.removeEventListener("fullscreenchange",e),document.removeEventListener("webkitfullscreenchange",e),document.removeEventListener("mozfullscreenchange",e),document.removeEventListener("MSFullscreenChange",e)}}function $s(r,n){if(typeof r=="number")return r;if(/px/.test(r))return Number(r.replace(/px/,""))||0;const t=document.createElement("div");t.style.width=r,n=n||document.body,n.appendChild(t);const e=t.getBoundingClientRect().width;return n.removeChild(t),e}function Zs(r,n){if(!r)return;let t,e;if(typeof n=="string"){const s=document.querySelector(n);if(!s)return;const o=s.getBoundingClientRect();t=o.width,e=o.height}else if(Array.isArray(n))t=n[0],e=n[1];else{const s=n.getBoundingClientRect();t=s.width,e=s.height}const i=t/e;return i>r?[r*e,e]:i<r?[t,t/r]:[t,e]}function Qs(r,n=5e3){return new Promise((t,e)=>{const i=new Image;i.src=r;const s=setTimeout(()=>{e(new Error("图片加载超时")),i.onload=null,i.onerror=null},n);i.onload=()=>{clearTimeout(s);const o=i.naturalWidth,a=i.naturalHeight,l=o/a;t([i,l])},i.onerror=()=>{clearTimeout(s),e(new Error("图片加载失败"))},i.crossOrigin="Anonymous"})}function Js(r){const t=document.getElementById(r).querySelectorAll("img"),e=t.length,i=[];let s=0;return e===0?Promise.resolve({allLoaded:!0,loaded:0,failed:0,total:0,errors:[]}):new Promise(o=>{const a=()=>{s===e&&o({allLoaded:i.length===0,loaded:e-i.length,failed:i.length,total:e,errors:i})};t.forEach(l=>{if(l.complete){l.naturalWidth===0&&i.push(l),s++,a();return}l.addEventListener("load",()=>{s++,a()},{once:!0}),l.addEventListener("error",()=>{i.push(l),s++,a()},{once:!0})})})}function Ks(r){return new Promise((n,t)=>{fetch(r).then(e=>n(e.text())).catch(e=>{console.error("Error fetching :",e),t(e)})})}function Qe(r){const{href:n,fileName:t,onProgress:e,timeout:i=3e4,autoDownload:s=!0}=r;let o,a=!1,l=null,c;const h=t||jt(n,"downloaded_file");c=decodeURIComponent(h);const u=()=>{if(!l)return;const p=URL.createObjectURL(l),v=document.createElement("a");v.href=p,v.download=c,v.click(),URL.revokeObjectURL(p)};return{promise:new Promise((p,v)=>{try{o=new XMLHttpRequest,o.open("GET",n),o.responseType="blob",o.timeout=i,o.ontimeout=()=>{a||v(new Error(`请求超时(已超过${i/1e3}秒)`))},o.addEventListener("progress",w=>{if(w.lengthComputable&&!a){const _=w.loaded/w.total*100;e==null||e(Number(_.toFixed(2)))}}),o.addEventListener("load",()=>{a||(o.status>=200&&o.status<300?(l=o.response,s&&u(),p(o.response)):v(new Error(`下载失败,状态码: ${o.status}`)))}),o.addEventListener("error",()=>{a||v(new Error("网络错误,下载失败"))}),o.addEventListener("abort",()=>{a||(a=!0,v(new Error("下载已被中止")))}),o.send()}catch(w){a||v(w)}}),abort:()=>!a&&o.abort(),download:()=>{!a&&l&&u()}}}function tn(r,n,t){if(!t){let s=n.replace(/^[^.]+./,"");s=s==n?"text/plain":"application/"+s,t={type:s}}const e=new Blob(r,t),i=URL.createObjectURL(e);Qe({href:i,fileName:n})}const en=Math.PI/2,Kt=Math.PI/180,te=6378137,sn=85.05112878;function nn(r,n){const t=Math.max(Math.min(r,180),-180),e=Math.max(Math.min(n,sn),-85.05112878),i=t*Kt*te,s=e*Kt,o=Math.log(Math.tan(Math.PI/4+s/2))*te;return[i,o]}function rn(r,n){const t=r/te/Kt,e=(2*Math.atan(Math.exp(n/te))-en)/Kt;return[t,e]}function Je(r,n,t){const[e,i]=r,[s,o]=n,[a,l]=t,c=(a-s)**2+(l-o)**2;if(c===0)return Math.sqrt((e-s)**2+(i-o)**2);let h=((e-s)*(a-s)+(i-o)*(l-o))/c;return h=Math.max(0,Math.min(1,h)),Math.sqrt((e-(s+h*(a-s)))**2+(i-(o+h*(l-o)))**2)}function on(r,n,t,e,i,s=1,o=1){const a=r+t*Math.cos(e)*s,l=n+t*Math.sin(e)*o,c=r+t*Math.cos(i)*s,h=n+t*Math.sin(i)*o;return[[a,l],[c,h]]}function ye(r,n,t,e){return Math.hypot(Math.abs(t-r),Math.abs(e-n))}function be(r,n,t,e){const i=(r+t)/2,s=(n+e)/2;return{x:i,y:s}}function an(r,n,t,e){const[i,s]=r,[o,a]=n;let l=1/0;if(o!==0){const c=o>0?(t-i)/o:-i/o;c>0&&(l=Math.min(l,c))}if(a!==0){const c=a>0?(e-s)/a:-s/a;c>0&&(l=Math.min(l,c))}return l===1/0?r:[i+o*l,s+a*l]}const ln=new Set(["sin","cos","tan","asin","acos","atan","atan2"]),cn=new Proxy(Math,{get(r,n){return ln.has(n)?function(...t){const e=t.map(i=>i/180*Math.PI);return r[n](...e)}:r[n]},set(){throw new Error("DegreeMath 是只读的,不能修改属性")},deleteProperty(){throw new Error("DegreeMath 是只读的,不能删除属性")}});class wt{constructor(n,t){f(this,"resolve");f(this,"reject");this.resolve=n,this.reject=t}run(n){var t,e;return n instanceof Promise?n.then(i=>{var s;return(s=this.resolve)==null||s.call(this),i}).catch(i=>{var s;return(s=this.reject)==null||s.call(this),Promise.reject(i)}):n?(t=this.resolve)==null||t.call(this):(e=this.reject)==null||e.call(this),n}}class hn extends wt{constructor(n){super(),this.resolve=n}warning(...n){const t=()=>{var e,i;return(i=(e=yt.tips).warning)==null?void 0:i.call(e,...n)};return new wt(this.resolve,t)}error(...n){const t=()=>{var e,i;return(i=(e=yt.tips).error)==null?void 0:i.call(e,...n)};return new wt(this.resolve,t)}}class un extends wt{constructor(n){super(),this.reject=n}info(...n){const t=()=>{var e,i;return(i=(e=yt.tips).info)==null?void 0:i.call(e,...n)};return new wt(t,this.reject)}success(...n){const t=()=>{var e,i;return(i=(e=yt.tips).success)==null?void 0:i.call(e,...n)};return new wt(t,this.reject)}}const F=class F{constructor(){if(new.target===F)throw new Error("请直接使用静态方法,而不是实例化此类")}static register(n,t){if(typeof t!="function")return console.error("TipHandler must be a function");F.tips[n]=t}static resolveTip(n){return function(...t){const e=()=>{var i,s;return(s=(i=F.tips)[n])==null?void 0:s.call(i,...t)};return new hn(e)}}static rejectTip(n){return function(...t){const e=()=>{var i,s;return(s=(i=F.tips)[n])==null?void 0:s.call(i,...t)};return new un(e)}}};f(F,"tips",{info:void 0,success:void 0,warning:void 0,error:void 0}),f(F,"info",F.resolveTip("info")),f(F,"success",F.resolveTip("success")),f(F,"warning",F.rejectTip("warning")),f(F,"error",F.rejectTip("error"));let yt=F;exports.EXTENSION_TO_MIME=Re;exports.FILE_EXTENSIONS=Ft;exports.PAPER_SIZE_DEFINITIONS=ve;exports.PAPER_SIZE_OPTIONS=ii;exports.UNIT_LABELS=le;exports.WINDOW_TARGET=ei;exports._Animate_CreateOscillator=si;exports._Animate_NumericTransition=ni;exports._Animate_Schedule=kt;exports._Blob_ConvertDataToImageUrl=ri;exports._Browser_CalculatePrintableArea=ki;exports._Browser_CopyToClipboard=Ri;exports._Browser_GetFrameRate=Vi;exports._Browser_SameOriginTabManager=Vt;exports._Canvas=Y;exports._Element_CalculateCanvasSize=Zs;exports._Element_CheckImagesLoaded=Js;exports._Element_CloseOnOutsideClick=Ys;exports._Element_Drag=zs;exports._Element_EnterFullscreen=$e;exports._Element_ExitFullscreen=Ze;exports._Element_Fullscreen=js;exports._Element_FullscreenObserver=qs;exports._Element_GetOtherSizeInPixels=$s;exports._Element_IsFullscreen=xe;exports._Element_LoadImage=Qs;exports._Element_LocalDrag=Ws;exports._Element_ScrollEndListener=Xs;exports._File_CreateAndDownload=tn;exports._File_Download=Qe;exports._File_Read=Ks;exports._Format_CamelCase=ui;exports._Format_CapitalizeFirstLetter=oi;exports._Format_ChunkArray=pi;exports._Format_ExcludeSubstring=di;exports._Format_FileSize=ci;exports._Format_HrefName=jt;exports._Format_MillisecondToReadable=mi;exports._Format_NumberWithCommas=Wt;exports._Format_NumberWithUnit=li;exports._Format_Percentage=ai;exports._Format_Timestamp=hi;exports._Format_ToggleInvisibleChars=fi;exports._Math_CalculateDistance2D=ye;exports._Math_Degree=cn;exports._Math_GetArcPoints=on;exports._Math_GetBoundaryIntersection=an;exports._Math_GetMidpoint=be;exports._Math_LngLatToPlane=nn;exports._Math_PlaneToLngLat=rn;exports._Math_PointToLineDistance=Je;exports._Tip=yt;exports._Utility_Clone=Ie;exports._Utility_Debounce=we;exports._Utility_ExecuteWhenIdle=bi;exports._Utility_GenerateUUID=$t;exports._Utility_GetTargetByPath=Ci;exports._Utility_MergeObjects=ct;exports._Utility_RotateList=Ei;exports._Utility_SetTargetByPath=Si;exports._Utility_Sleep=Di;exports._Utility_Throttle=_i;exports._Utility_TimeConsumption=He;exports._Utility_WaitForCondition=Ae;exports._Valid_CheckConnectionWithXHR=Pi;exports._Valid_DataType=qt;exports._Valid_DoesInfiniteLineIntersectRectangle=vi;exports._Valid_FileTypeChecker=ce;exports._Valid_Is2DNumberArray=Mt;exports._Valid_IsInMargin=gi;exports._Valid_IsNumberArray=ee;exports._Valid_IsPointInPolygon=yi;exports._Valid_IsSecureContext=wi;
|
|
9
|
+
*/var he=9e15,ut=1e9,ue="0123456789abcdef",Zt="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Qt="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",de={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-9e15,maxE:he,crypto:!1},Le,nt,S=!0,ie="[DecimalError] ",ht=ie+"Invalid argument: ",Te=ie+"Precision limit exceeded",Fe=ie+"crypto unavailable",Be="[object Decimal]",T=Math.floor,I=Math.pow,Mi=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Oi=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Ni=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Ue=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,$=1e7,b=7,Ai=9007199254740991,Ii=Zt.length-1,fe=Qt.length-1,y={toStringTag:Be};y.absoluteValue=y.abs=function(){var r=new this.constructor(this);return r.s<0&&(r.s=1),x(r)};y.ceil=function(){return x(new this.constructor(this),this.e+1,2)};y.clampedTo=y.clamp=function(r,n){var t,e=this,i=e.constructor;if(r=new i(r),n=new i(n),!r.s||!n.s)return new i(NaN);if(r.gt(n))throw Error(ht+n);return t=e.cmp(r),t<0?r:e.cmp(n)>0?n:new i(e)};y.comparedTo=y.cmp=function(r){var n,t,e,i,s=this,o=s.d,a=(r=new s.constructor(r)).d,l=s.s,c=r.s;if(!o||!a)return!l||!c?NaN:l!==c?l:o===a?0:!o^l<0?1:-1;if(!o[0]||!a[0])return o[0]?l:a[0]?-c:0;if(l!==c)return l;if(s.e!==r.e)return s.e>r.e^l<0?1:-1;for(e=o.length,i=a.length,n=0,t=e<i?e:i;n<t;++n)if(o[n]!==a[n])return o[n]>a[n]^l<0?1:-1;return e===i?0:e>i^l<0?1:-1};y.cosine=y.cos=function(){var r,n,t=this,e=t.constructor;return t.d?t.d[0]?(r=e.precision,n=e.rounding,e.precision=r+Math.max(t.e,t.sd())+b,e.rounding=1,t=Hi(e,We(e,t)),e.precision=r,e.rounding=n,x(nt==2||nt==3?t.neg():t,r,n,!0)):new e(1):new e(NaN)};y.cubeRoot=y.cbrt=function(){var r,n,t,e,i,s,o,a,l,c,h=this,u=h.constructor;if(!h.isFinite()||h.isZero())return new u(h);for(S=!1,s=h.s*I(h.s*h,1/3),!s||Math.abs(s)==1/0?(t=H(h.d),r=h.e,(s=(r-t.length+1)%3)&&(t+=s==1||s==-2?"0":"00"),s=I(t,1/3),r=T((r+1)/3)-(r%3==(r<0?-1:2)),s==1/0?t="5e"+r:(t=s.toExponential(),t=t.slice(0,t.indexOf("e")+1)+r),e=new u(t),e.s=h.s):e=new u(s.toString()),o=(r=u.precision)+3;;)if(a=e,l=a.times(a).times(a),c=l.plus(h),e=k(c.plus(h).times(a),c.plus(l),o+2,1),H(a.d).slice(0,o)===(t=H(e.d)).slice(0,o))if(t=t.slice(o-3,o+1),t=="9999"||!i&&t=="4999"){if(!i&&(x(a,r+1,0),a.times(a).times(a).eq(h))){e=a;break}o+=4,i=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(x(e,r+1,1),n=!e.times(e).times(e).eq(h));break}return S=!0,x(e,r,u.rounding,n)};y.decimalPlaces=y.dp=function(){var r,n=this.d,t=NaN;if(n){if(r=n.length-1,t=(r-T(this.e/b))*b,r=n[r],r)for(;r%10==0;r/=10)t--;t<0&&(t=0)}return t};y.dividedBy=y.div=function(r){return k(this,new this.constructor(r))};y.dividedToIntegerBy=y.divToInt=function(r){var n=this,t=n.constructor;return x(k(n,new t(r),0,1,1),t.precision,t.rounding)};y.equals=y.eq=function(r){return this.cmp(r)===0};y.floor=function(){return x(new this.constructor(this),this.e+1,3)};y.greaterThan=y.gt=function(r){return this.cmp(r)>0};y.greaterThanOrEqualTo=y.gte=function(r){var n=this.cmp(r);return n==1||n===0};y.hyperbolicCosine=y.cosh=function(){var r,n,t,e,i,s=this,o=s.constructor,a=new o(1);if(!s.isFinite())return new o(s.s?1/0:NaN);if(s.isZero())return a;t=o.precision,e=o.rounding,o.precision=t+Math.max(s.e,s.sd())+4,o.rounding=1,i=s.d.length,i<32?(r=Math.ceil(i/3),n=(1/ne(4,r)).toString()):(r=16,n="2.3283064365386962890625e-10"),s=Dt(o,1,s.times(n),new o(1),!0);for(var l,c=r,h=new o(8);c--;)l=s.times(s),s=a.minus(l.times(h.minus(l.times(h))));return x(s,o.precision=t,o.rounding=e,!0)};y.hyperbolicSine=y.sinh=function(){var r,n,t,e,i=this,s=i.constructor;if(!i.isFinite()||i.isZero())return new s(i);if(n=s.precision,t=s.rounding,s.precision=n+Math.max(i.e,i.sd())+4,s.rounding=1,e=i.d.length,e<3)i=Dt(s,2,i,i,!0);else{r=1.4*Math.sqrt(e),r=r>16?16:r|0,i=i.times(1/ne(5,r)),i=Dt(s,2,i,i,!0);for(var o,a=new s(5),l=new s(16),c=new s(20);r--;)o=i.times(i),i=i.times(a.plus(o.times(l.times(o).plus(c))))}return s.precision=n,s.rounding=t,x(i,n,t,!0)};y.hyperbolicTangent=y.tanh=function(){var r,n,t=this,e=t.constructor;return t.isFinite()?t.isZero()?new e(t):(r=e.precision,n=e.rounding,e.precision=r+7,e.rounding=1,k(t.sinh(),t.cosh(),e.precision=r,e.rounding=n)):new e(t.s)};y.inverseCosine=y.acos=function(){var r=this,n=r.constructor,t=r.abs().cmp(1),e=n.precision,i=n.rounding;return t!==-1?t===0?r.isNeg()?J(n,e,i):new n(0):new n(NaN):r.isZero()?J(n,e+4,i).times(.5):(n.precision=e+6,n.rounding=1,r=new n(1).minus(r).div(r.plus(1)).sqrt().atan(),n.precision=e,n.rounding=i,r.times(2))};y.inverseHyperbolicCosine=y.acosh=function(){var r,n,t=this,e=t.constructor;return t.lte(1)?new e(t.eq(1)?0:NaN):t.isFinite()?(r=e.precision,n=e.rounding,e.precision=r+Math.max(Math.abs(t.e),t.sd())+4,e.rounding=1,S=!1,t=t.times(t).minus(1).sqrt().plus(t),S=!0,e.precision=r,e.rounding=n,t.ln()):new e(t)};y.inverseHyperbolicSine=y.asinh=function(){var r,n,t=this,e=t.constructor;return!t.isFinite()||t.isZero()?new e(t):(r=e.precision,n=e.rounding,e.precision=r+2*Math.max(Math.abs(t.e),t.sd())+6,e.rounding=1,S=!1,t=t.times(t).plus(1).sqrt().plus(t),S=!0,e.precision=r,e.rounding=n,t.ln())};y.inverseHyperbolicTangent=y.atanh=function(){var r,n,t,e,i=this,s=i.constructor;return i.isFinite()?i.e>=0?new s(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(r=s.precision,n=s.rounding,e=i.sd(),Math.max(e,r)<2*-i.e-1?x(new s(i),r,n,!0):(s.precision=t=e-i.e,i=k(i.plus(1),new s(1).minus(i),t+r,1),s.precision=r+4,s.rounding=1,i=i.ln(),s.precision=r,s.rounding=n,i.times(.5))):new s(NaN)};y.inverseSine=y.asin=function(){var r,n,t,e,i=this,s=i.constructor;return i.isZero()?new s(i):(n=i.abs().cmp(1),t=s.precision,e=s.rounding,n!==-1?n===0?(r=J(s,t+4,e).times(.5),r.s=i.s,r):new s(NaN):(s.precision=t+6,s.rounding=1,i=i.div(new s(1).minus(i.times(i)).sqrt().plus(1)).atan(),s.precision=t,s.rounding=e,i.times(2)))};y.inverseTangent=y.atan=function(){var r,n,t,e,i,s,o,a,l,c=this,h=c.constructor,u=h.precision,d=h.rounding;if(c.isFinite()){if(c.isZero())return new h(c);if(c.abs().eq(1)&&u+4<=fe)return o=J(h,u+4,d).times(.25),o.s=c.s,o}else{if(!c.s)return new h(NaN);if(u+4<=fe)return o=J(h,u+4,d).times(.5),o.s=c.s,o}for(h.precision=a=u+10,h.rounding=1,t=Math.min(28,a/b+2|0),r=t;r;--r)c=c.div(c.times(c).plus(1).sqrt().plus(1));for(S=!1,n=Math.ceil(a/b),e=1,l=c.times(c),o=new h(c),i=c;r!==-1;)if(i=i.times(l),s=o.minus(i.div(e+=2)),i=i.times(l),o=s.plus(i.div(e+=2)),o.d[n]!==void 0)for(r=n;o.d[r]===s.d[r]&&r--;);return t&&(o=o.times(2<<t-1)),S=!0,x(o,h.precision=u,h.rounding=d,!0)};y.isFinite=function(){return!!this.d};y.isInteger=y.isInt=function(){return!!this.d&&T(this.e/b)>this.d.length-2};y.isNaN=function(){return!this.s};y.isNegative=y.isNeg=function(){return this.s<0};y.isPositive=y.isPos=function(){return this.s>0};y.isZero=function(){return!!this.d&&this.d[0]===0};y.lessThan=y.lt=function(r){return this.cmp(r)<0};y.lessThanOrEqualTo=y.lte=function(r){return this.cmp(r)<1};y.logarithm=y.log=function(r){var n,t,e,i,s,o,a,l,c=this,h=c.constructor,u=h.precision,d=h.rounding,m=5;if(r==null)r=new h(10),n=!0;else{if(r=new h(r),t=r.d,r.s<0||!t||!t[0]||r.eq(1))return new h(NaN);n=r.eq(10)}if(t=c.d,c.s<0||!t||!t[0]||c.eq(1))return new h(t&&!t[0]?-1/0:c.s!=1?NaN:t?0:1/0);if(n)if(t.length>1)s=!0;else{for(i=t[0];i%10===0;)i/=10;s=i!==1}if(S=!1,a=u+m,o=at(c,a),e=n?Jt(h,a+10):at(r,a),l=k(o,e,a,1),Ot(l.d,i=u,d))do if(a+=10,o=at(c,a),e=n?Jt(h,a+10):at(r,a),l=k(o,e,a,1),!s){+H(l.d).slice(i+1,i+15)+1==1e14&&(l=x(l,u+1,0));break}while(Ot(l.d,i+=10,d));return S=!0,x(l,u,d)};y.minus=y.sub=function(r){var n,t,e,i,s,o,a,l,c,h,u,d,m=this,g=m.constructor;if(r=new g(r),!m.d||!r.d)return!m.s||!r.s?r=new g(NaN):m.d?r.s=-r.s:r=new g(r.d||m.s!==r.s?m:NaN),r;if(m.s!=r.s)return r.s=-r.s,m.plus(r);if(c=m.d,d=r.d,a=g.precision,l=g.rounding,!c[0]||!d[0]){if(d[0])r.s=-r.s;else if(c[0])r=new g(m);else return new g(l===3?-0:0);return S?x(r,a,l):r}if(t=T(r.e/b),h=T(m.e/b),c=c.slice(),s=h-t,s){for(u=s<0,u?(n=c,s=-s,o=d.length):(n=d,t=h,o=c.length),e=Math.max(Math.ceil(a/b),o)+2,s>e&&(s=e,n.length=1),n.reverse(),e=s;e--;)n.push(0);n.reverse()}else{for(e=c.length,o=d.length,u=e<o,u&&(o=e),e=0;e<o;e++)if(c[e]!=d[e]){u=c[e]<d[e];break}s=0}for(u&&(n=c,c=d,d=n,r.s=-r.s),o=c.length,e=d.length-o;e>0;--e)c[o++]=0;for(e=d.length;e>s;){if(c[--e]<d[e]){for(i=e;i&&c[--i]===0;)c[i]=$-1;--c[i],c[e]+=$}c[e]-=d[e]}for(;c[--o]===0;)c.pop();for(;c[0]===0;c.shift())--t;return c[0]?(r.d=c,r.e=se(c,t),S?x(r,a,l):r):new g(l===3?-0:0)};y.modulo=y.mod=function(r){var n,t=this,e=t.constructor;return r=new e(r),!t.d||!r.s||r.d&&!r.d[0]?new e(NaN):!r.d||t.d&&!t.d[0]?x(new e(t),e.precision,e.rounding):(S=!1,e.modulo==9?(n=k(t,r.abs(),0,3,1),n.s*=r.s):n=k(t,r,0,e.modulo,1),n=n.times(r),S=!0,t.minus(n))};y.naturalExponential=y.exp=function(){return me(this)};y.naturalLogarithm=y.ln=function(){return at(this)};y.negated=y.neg=function(){var r=new this.constructor(this);return r.s=-r.s,x(r)};y.plus=y.add=function(r){var n,t,e,i,s,o,a,l,c,h,u=this,d=u.constructor;if(r=new d(r),!u.d||!r.d)return!u.s||!r.s?r=new d(NaN):u.d||(r=new d(r.d||u.s===r.s?u:NaN)),r;if(u.s!=r.s)return r.s=-r.s,u.minus(r);if(c=u.d,h=r.d,a=d.precision,l=d.rounding,!c[0]||!h[0])return h[0]||(r=new d(u)),S?x(r,a,l):r;if(s=T(u.e/b),e=T(r.e/b),c=c.slice(),i=s-e,i){for(i<0?(t=c,i=-i,o=h.length):(t=h,e=s,o=c.length),s=Math.ceil(a/b),o=s>o?s+1:o+1,i>o&&(i=o,t.length=1),t.reverse();i--;)t.push(0);t.reverse()}for(o=c.length,i=h.length,o-i<0&&(i=o,t=h,h=c,c=t),n=0;i;)n=(c[--i]=c[i]+h[i]+n)/$|0,c[i]%=$;for(n&&(c.unshift(n),++e),o=c.length;c[--o]==0;)c.pop();return r.d=c,r.e=se(c,e),S?x(r,a,l):r};y.precision=y.sd=function(r){var n,t=this;if(r!==void 0&&r!==!!r&&r!==1&&r!==0)throw Error(ht+r);return t.d?(n=Ge(t.d),r&&t.e+1>n&&(n=t.e+1)):n=NaN,n};y.round=function(){var r=this,n=r.constructor;return x(new n(r),r.e+1,n.rounding)};y.sine=y.sin=function(){var r,n,t=this,e=t.constructor;return t.isFinite()?t.isZero()?new e(t):(r=e.precision,n=e.rounding,e.precision=r+Math.max(t.e,t.sd())+b,e.rounding=1,t=Ti(e,We(e,t)),e.precision=r,e.rounding=n,x(nt>2?t.neg():t,r,n,!0)):new e(NaN)};y.squareRoot=y.sqrt=function(){var r,n,t,e,i,s,o=this,a=o.d,l=o.e,c=o.s,h=o.constructor;if(c!==1||!a||!a[0])return new h(!c||c<0&&(!a||a[0])?NaN:a?o:1/0);for(S=!1,c=Math.sqrt(+o),c==0||c==1/0?(n=H(a),(n.length+l)%2==0&&(n+="0"),c=Math.sqrt(n),l=T((l+1)/2)-(l<0||l%2),c==1/0?n="5e"+l:(n=c.toExponential(),n=n.slice(0,n.indexOf("e")+1)+l),e=new h(n)):e=new h(c.toString()),t=(l=h.precision)+3;;)if(s=e,e=s.plus(k(o,s,t+2,1)).times(.5),H(s.d).slice(0,t)===(n=H(e.d)).slice(0,t))if(n=n.slice(t-3,t+1),n=="9999"||!i&&n=="4999"){if(!i&&(x(s,l+1,0),s.times(s).eq(o))){e=s;break}t+=4,i=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(x(e,l+1,1),r=!e.times(e).eq(o));break}return S=!0,x(e,l,h.rounding,r)};y.tangent=y.tan=function(){var r,n,t=this,e=t.constructor;return t.isFinite()?t.isZero()?new e(t):(r=e.precision,n=e.rounding,e.precision=r+10,e.rounding=1,t=t.sin(),t.s=1,t=k(t,new e(1).minus(t.times(t)).sqrt(),r+10,0),e.precision=r,e.rounding=n,x(nt==2||nt==4?t.neg():t,r,n,!0)):new e(NaN)};y.times=y.mul=function(r){var n,t,e,i,s,o,a,l,c,h=this,u=h.constructor,d=h.d,m=(r=new u(r)).d;if(r.s*=h.s,!d||!d[0]||!m||!m[0])return new u(!r.s||d&&!d[0]&&!m||m&&!m[0]&&!d?NaN:!d||!m?r.s/0:r.s*0);for(t=T(h.e/b)+T(r.e/b),l=d.length,c=m.length,l<c&&(s=d,d=m,m=s,o=l,l=c,c=o),s=[],o=l+c,e=o;e--;)s.push(0);for(e=c;--e>=0;){for(n=0,i=l+e;i>e;)a=s[i]+m[e]*d[i-e-1]+n,s[i--]=a%$|0,n=a/$|0;s[i]=(s[i]+n)%$|0}for(;!s[--o];)s.pop();return n?++t:s.shift(),r.d=s,r.e=se(s,t),S?x(r,u.precision,u.rounding):r};y.toBinary=function(r,n){return Pe(this,2,r,n)};y.toDecimalPlaces=y.toDP=function(r,n){var t=this,e=t.constructor;return t=new e(t),r===void 0?t:(U(r,0,ut),n===void 0?n=e.rounding:U(n,0,8),x(t,r+t.e+1,n))};y.toExponential=function(r,n){var t,e=this,i=e.constructor;return r===void 0?t=K(e,!0):(U(r,0,ut),n===void 0?n=i.rounding:U(n,0,8),e=x(new i(e),r+1,n),t=K(e,!0,r+1)),e.isNeg()&&!e.isZero()?"-"+t:t};y.toFixed=function(r,n){var t,e,i=this,s=i.constructor;return r===void 0?t=K(i):(U(r,0,ut),n===void 0?n=s.rounding:U(n,0,8),e=x(new s(i),r+i.e+1,n),t=K(e,!1,r+e.e+1)),i.isNeg()&&!i.isZero()?"-"+t:t};y.toFraction=function(r){var n,t,e,i,s,o,a,l,c,h,u,d,m=this,g=m.d,p=m.constructor;if(!g)return new p(m);if(c=t=new p(1),e=l=new p(0),n=new p(e),s=n.e=Ge(g)-m.e-1,o=s%b,n.d[0]=I(10,o<0?b+o:o),r==null)r=s>0?n:c;else{if(a=new p(r),!a.isInt()||a.lt(c))throw Error(ht+a);r=a.gt(n)?s>0?n:c:a}for(S=!1,a=new p(H(g)),h=p.precision,p.precision=s=g.length*b*2;u=k(a,n,0,1,1),i=t.plus(u.times(e)),i.cmp(r)!=1;)t=e,e=i,i=c,c=l.plus(u.times(i)),l=i,i=n,n=a.minus(u.times(i)),a=i;return i=k(r.minus(t),e,0,1,1),l=l.plus(i.times(c)),t=t.plus(i.times(e)),l.s=c.s=m.s,d=k(c,e,s,1).minus(m).abs().cmp(k(l,t,s,1).minus(m).abs())<1?[c,e]:[l,t],p.precision=h,S=!0,d};y.toHexadecimal=y.toHex=function(r,n){return Pe(this,16,r,n)};y.toNearest=function(r,n){var t=this,e=t.constructor;if(t=new e(t),r==null){if(!t.d)return t;r=new e(1),n=e.rounding}else{if(r=new e(r),n===void 0?n=e.rounding:U(n,0,8),!t.d)return r.s?t:r;if(!r.d)return r.s&&(r.s=t.s),r}return r.d[0]?(S=!1,t=k(t,r,0,n,1).times(r),S=!0,x(t)):(r.s=t.s,t=r),t};y.toNumber=function(){return+this};y.toOctal=function(r,n){return Pe(this,8,r,n)};y.toPower=y.pow=function(r){var n,t,e,i,s,o,a=this,l=a.constructor,c=+(r=new l(r));if(!a.d||!r.d||!a.d[0]||!r.d[0])return new l(I(+a,c));if(a=new l(a),a.eq(1))return a;if(e=l.precision,s=l.rounding,r.eq(1))return x(a,e,s);if(n=T(r.e/b),n>=r.d.length-1&&(t=c<0?-c:c)<=Ai)return i=Xe(l,a,t,e),r.s<0?new l(1).div(i):x(i,e,s);if(o=a.s,o<0){if(n<r.d.length-1)return new l(NaN);if(r.d[n]&1||(o=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=o,a}return t=I(+a,c),n=t==0||!isFinite(t)?T(c*(Math.log("0."+H(a.d))/Math.LN10+a.e+1)):new l(t+"").e,n>l.maxE+1||n<l.minE-1?new l(n>0?o/0:0):(S=!1,l.rounding=a.s=1,t=Math.min(12,(n+"").length),i=me(r.times(at(a,e+t)),e),i.d&&(i=x(i,e+5,1),Ot(i.d,e,s)&&(n=e+10,i=x(me(r.times(at(a,n+t)),n),n+5,1),+H(i.d).slice(e+1,e+15)+1==1e14&&(i=x(i,e+1,0)))),i.s=o,S=!0,l.rounding=s,x(i,e,s))};y.toPrecision=function(r,n){var t,e=this,i=e.constructor;return r===void 0?t=K(e,e.e<=i.toExpNeg||e.e>=i.toExpPos):(U(r,1,ut),n===void 0?n=i.rounding:U(n,0,8),e=x(new i(e),r,n),t=K(e,r<=e.e||e.e<=i.toExpNeg,r)),e.isNeg()&&!e.isZero()?"-"+t:t};y.toSignificantDigits=y.toSD=function(r,n){var t=this,e=t.constructor;return r===void 0?(r=e.precision,n=e.rounding):(U(r,1,ut),n===void 0?n=e.rounding:U(n,0,8)),x(new e(t),r,n)};y.toString=function(){var r=this,n=r.constructor,t=K(r,r.e<=n.toExpNeg||r.e>=n.toExpPos);return r.isNeg()&&!r.isZero()?"-"+t:t};y.truncated=y.trunc=function(){return x(new this.constructor(this),this.e+1,1)};y.valueOf=y.toJSON=function(){var r=this,n=r.constructor,t=K(r,r.e<=n.toExpNeg||r.e>=n.toExpPos);return r.isNeg()?"-"+t:t};function H(r){var n,t,e,i=r.length-1,s="",o=r[0];if(i>0){for(s+=o,n=1;n<i;n++)e=r[n]+"",t=b-e.length,t&&(s+=ot(t)),s+=e;o=r[n],e=o+"",t=b-e.length,t&&(s+=ot(t))}else if(o===0)return"0";for(;o%10===0;)o/=10;return s+o}function U(r,n,t){if(r!==~~r||r<n||r>t)throw Error(ht+r)}function Ot(r,n,t,e){var i,s,o,a;for(s=r[0];s>=10;s/=10)--n;return--n<0?(n+=b,i=0):(i=Math.ceil((n+1)/b),n%=b),s=I(10,b-n),a=r[i]%s|0,e==null?n<3?(n==0?a=a/100|0:n==1&&(a=a/10|0),o=t<4&&a==99999||t>3&&a==49999||a==5e4||a==0):o=(t<4&&a+1==s||t>3&&a+1==s/2)&&(r[i+1]/s/100|0)==I(10,n-2)-1||(a==s/2||a==0)&&(r[i+1]/s/100|0)==0:n<4?(n==0?a=a/1e3|0:n==1?a=a/100|0:n==2&&(a=a/10|0),o=(e||t<4)&&a==9999||!e&&t>3&&a==4999):o=((e||t<4)&&a+1==s||!e&&t>3&&a+1==s/2)&&(r[i+1]/s/1e3|0)==I(10,n-3)-1,o}function Bt(r,n,t){for(var e,i=[0],s,o=0,a=r.length;o<a;){for(s=i.length;s--;)i[s]*=n;for(i[0]+=ue.indexOf(r.charAt(o++)),e=0;e<i.length;e++)i[e]>t-1&&(i[e+1]===void 0&&(i[e+1]=0),i[e+1]+=i[e]/t|0,i[e]%=t)}return i.reverse()}function Hi(r,n){var t,e,i;if(n.isZero())return n;e=n.d.length,e<32?(t=Math.ceil(e/3),i=(1/ne(4,t)).toString()):(t=16,i="2.3283064365386962890625e-10"),r.precision+=t,n=Dt(r,1,n.times(i),new r(1));for(var s=t;s--;){var o=n.times(n);n=o.times(o).minus(o).times(8).plus(1)}return r.precision-=t,n}var k=function(){function r(e,i,s){var o,a=0,l=e.length;for(e=e.slice();l--;)o=e[l]*i+a,e[l]=o%s|0,a=o/s|0;return a&&e.unshift(a),e}function n(e,i,s,o){var a,l;if(s!=o)l=s>o?1:-1;else for(a=l=0;a<s;a++)if(e[a]!=i[a]){l=e[a]>i[a]?1:-1;break}return l}function t(e,i,s,o){for(var a=0;s--;)e[s]-=a,a=e[s]<i[s]?1:0,e[s]=a*o+e[s]-i[s];for(;!e[0]&&e.length>1;)e.shift()}return function(e,i,s,o,a,l){var c,h,u,d,m,g,p,v,w,_,C,E,N,G,At,dt,rt,vt,X,It,Ht=e.constructor,oe=e.s==i.s?1:-1,L=e.d,M=i.d;if(!L||!L[0]||!M||!M[0])return new Ht(!e.s||!i.s||(L?M&&L[0]==M[0]:!M)?NaN:L&&L[0]==0||!M?oe*0:oe/0);for(l?(m=1,h=e.e-i.e):(l=$,m=b,h=T(e.e/m)-T(i.e/m)),X=M.length,rt=L.length,w=new Ht(oe),_=w.d=[],u=0;M[u]==(L[u]||0);u++);if(M[u]>(L[u]||0)&&h--,s==null?(G=s=Ht.precision,o=Ht.rounding):a?G=s+(e.e-i.e)+1:G=s,G<0)_.push(1),g=!0;else{if(G=G/m+2|0,u=0,X==1){for(d=0,M=M[0],G++;(u<rt||d)&&G--;u++)At=d*l+(L[u]||0),_[u]=At/M|0,d=At%M|0;g=d||u<rt}else{for(d=l/(M[0]+1)|0,d>1&&(M=r(M,d,l),L=r(L,d,l),X=M.length,rt=L.length),dt=X,C=L.slice(0,X),E=C.length;E<X;)C[E++]=0;It=M.slice(),It.unshift(0),vt=M[0],M[1]>=l/2&&++vt;do d=0,c=n(M,C,X,E),c<0?(N=C[0],X!=E&&(N=N*l+(C[1]||0)),d=N/vt|0,d>1?(d>=l&&(d=l-1),p=r(M,d,l),v=p.length,E=C.length,c=n(p,C,v,E),c==1&&(d--,t(p,X<v?It:M,v,l))):(d==0&&(c=d=1),p=M.slice()),v=p.length,v<E&&p.unshift(0),t(C,p,E,l),c==-1&&(E=C.length,c=n(M,C,X,E),c<1&&(d++,t(C,X<E?It:M,E,l))),E=C.length):c===0&&(d++,C=[0]),_[u++]=d,c&&C[0]?C[E++]=L[dt]||0:(C=[L[dt]],E=1);while((dt++<rt||C[0]!==void 0)&&G--);g=C[0]!==void 0}_[0]||_.shift()}if(m==1)w.e=h,Le=g;else{for(u=1,d=_[0];d>=10;d/=10)u++;w.e=u+h*m-1,x(w,a?s+w.e+1:s,o,g)}return w}}();function x(r,n,t,e){var i,s,o,a,l,c,h,u,d,m=r.constructor;t:if(n!=null){if(u=r.d,!u)return r;for(i=1,a=u[0];a>=10;a/=10)i++;if(s=n-i,s<0)s+=b,o=n,h=u[d=0],l=h/I(10,i-o-1)%10|0;else if(d=Math.ceil((s+1)/b),a=u.length,d>=a)if(e){for(;a++<=d;)u.push(0);h=l=0,i=1,s%=b,o=s-b+1}else break t;else{for(h=a=u[d],i=1;a>=10;a/=10)i++;s%=b,o=s-b+i,l=o<0?0:h/I(10,i-o-1)%10|0}if(e=e||n<0||u[d+1]!==void 0||(o<0?h:h%I(10,i-o-1)),c=t<4?(l||e)&&(t==0||t==(r.s<0?3:2)):l>5||l==5&&(t==4||e||t==6&&(s>0?o>0?h/I(10,i-o):0:u[d-1])%10&1||t==(r.s<0?8:7)),n<1||!u[0])return u.length=0,c?(n-=r.e+1,u[0]=I(10,(b-n%b)%b),r.e=-n||0):u[0]=r.e=0,r;if(s==0?(u.length=d,a=1,d--):(u.length=d+1,a=I(10,b-s),u[d]=o>0?(h/I(10,i-o)%I(10,o)|0)*a:0),c)for(;;)if(d==0){for(s=1,o=u[0];o>=10;o/=10)s++;for(o=u[0]+=a,a=1;o>=10;o/=10)a++;s!=a&&(r.e++,u[0]==$&&(u[0]=1));break}else{if(u[d]+=a,u[d]!=$)break;u[d--]=0,a=1}for(s=u.length;u[--s]===0;)u.pop()}return S&&(r.e>m.maxE?(r.d=null,r.e=NaN):r.e<m.minE&&(r.e=0,r.d=[0])),r}function K(r,n,t){if(!r.isFinite())return ze(r);var e,i=r.e,s=H(r.d),o=s.length;return n?(t&&(e=t-o)>0?s=s.charAt(0)+"."+s.slice(1)+ot(e):o>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(r.e<0?"e":"e+")+r.e):i<0?(s="0."+ot(-i-1)+s,t&&(e=t-o)>0&&(s+=ot(e))):i>=o?(s+=ot(i+1-o),t&&(e=t-i-1)>0&&(s=s+"."+ot(e))):((e=i+1)<o&&(s=s.slice(0,e)+"."+s.slice(e)),t&&(e=t-o)>0&&(i+1===o&&(s+="."),s+=ot(e))),s}function se(r,n){var t=r[0];for(n*=b;t>=10;t/=10)n++;return n}function Jt(r,n,t){if(n>Ii)throw S=!0,t&&(r.precision=t),Error(Te);return x(new r(Zt),n,1,!0)}function J(r,n,t){if(n>fe)throw Error(Te);return x(new r(Qt),n,t,!0)}function Ge(r){var n=r.length-1,t=n*b+1;if(n=r[n],n){for(;n%10==0;n/=10)t--;for(n=r[0];n>=10;n/=10)t++}return t}function ot(r){for(var n="";r--;)n+="0";return n}function Xe(r,n,t,e){var i,s=new r(1),o=Math.ceil(e/b+4);for(S=!1;;){if(t%2&&(s=s.times(n),Ee(s.d,o)&&(i=!0)),t=T(t/2),t===0){t=s.d.length-1,i&&s.d[t]===0&&++s.d[t];break}n=n.times(n),Ee(n.d,o)}return S=!0,s}function Se(r){return r.d[r.d.length-1]&1}function Ye(r,n,t){for(var e,i,s=new r(n[0]),o=0;++o<n.length;){if(i=new r(n[o]),!i.s){s=i;break}e=s.cmp(i),(e===t||e===0&&s.s===t)&&(s=i)}return s}function me(r,n){var t,e,i,s,o,a,l,c=0,h=0,u=0,d=r.constructor,m=d.rounding,g=d.precision;if(!r.d||!r.d[0]||r.e>17)return new d(r.d?r.d[0]?r.s<0?0:1/0:1:r.s?r.s<0?0:r:NaN);for(n==null?(S=!1,l=g):l=n,a=new d(.03125);r.e>-2;)r=r.times(a),u+=5;for(e=Math.log(I(2,u))/Math.LN10*2+5|0,l+=e,t=s=o=new d(1),d.precision=l;;){if(s=x(s.times(r),l,1),t=t.times(++h),a=o.plus(k(s,t,l,1)),H(a.d).slice(0,l)===H(o.d).slice(0,l)){for(i=u;i--;)o=x(o.times(o),l,1);if(n==null)if(c<3&&Ot(o.d,l-e,m,c))d.precision=l+=10,t=s=a=new d(1),h=0,c++;else return x(o,d.precision=g,m,S=!0);else return d.precision=g,o}o=a}}function at(r,n){var t,e,i,s,o,a,l,c,h,u,d,m=1,g=10,p=r,v=p.d,w=p.constructor,_=w.rounding,C=w.precision;if(p.s<0||!v||!v[0]||!p.e&&v[0]==1&&v.length==1)return new w(v&&!v[0]?-1/0:p.s!=1?NaN:v?0:p);if(n==null?(S=!1,h=C):h=n,w.precision=h+=g,t=H(v),e=t.charAt(0),Math.abs(s=p.e)<15e14){for(;e<7&&e!=1||e==1&&t.charAt(1)>3;)p=p.times(r),t=H(p.d),e=t.charAt(0),m++;s=p.e,e>1?(p=new w("0."+t),s++):p=new w(e+"."+t.slice(1))}else return c=Jt(w,h+2,C).times(s+""),p=at(new w(e+"."+t.slice(1)),h-g).plus(c),w.precision=C,n==null?x(p,C,_,S=!0):p;for(u=p,l=o=p=k(p.minus(1),p.plus(1),h,1),d=x(p.times(p),h,1),i=3;;){if(o=x(o.times(d),h,1),c=l.plus(k(o,new w(i),h,1)),H(c.d).slice(0,h)===H(l.d).slice(0,h))if(l=l.times(2),s!==0&&(l=l.plus(Jt(w,h+2,C).times(s+""))),l=k(l,new w(m),h,1),n==null)if(Ot(l.d,h-g,_,a))w.precision=h+=g,c=o=p=k(u.minus(1),u.plus(1),h,1),d=x(p.times(p),h,1),i=a=1;else return x(l,w.precision=C,_,S=!0);else return w.precision=C,l;l=c,i+=2}}function ze(r){return String(r.s*r.s/0)}function Ut(r,n){var t,e,i;for((t=n.indexOf("."))>-1&&(n=n.replace(".","")),(e=n.search(/e/i))>0?(t<0&&(t=e),t+=+n.slice(e+1),n=n.substring(0,e)):t<0&&(t=n.length),e=0;n.charCodeAt(e)===48;e++);for(i=n.length;n.charCodeAt(i-1)===48;--i);if(n=n.slice(e,i),n){if(i-=e,r.e=t=t-e-1,r.d=[],e=(t+1)%b,t<0&&(e+=b),e<i){for(e&&r.d.push(+n.slice(0,e)),i-=b;e<i;)r.d.push(+n.slice(e,e+=b));n=n.slice(e),e=b-n.length}else e-=i;for(;e--;)n+="0";r.d.push(+n),S&&(r.e>r.constructor.maxE?(r.d=null,r.e=NaN):r.e<r.constructor.minE&&(r.e=0,r.d=[0]))}else r.e=0,r.d=[0];return r}function Li(r,n){var t,e,i,s,o,a,l,c,h;if(n.indexOf("_")>-1){if(n=n.replace(/(\d)_(?=\d)/g,"$1"),Ue.test(n))return Ut(r,n)}else if(n==="Infinity"||n==="NaN")return+n||(r.s=NaN),r.e=NaN,r.d=null,r;if(Oi.test(n))t=16,n=n.toLowerCase();else if(Mi.test(n))t=2;else if(Ni.test(n))t=8;else throw Error(ht+n);for(s=n.search(/p/i),s>0?(l=+n.slice(s+1),n=n.substring(2,s)):n=n.slice(2),s=n.indexOf("."),o=s>=0,e=r.constructor,o&&(n=n.replace(".",""),a=n.length,s=a-s,i=Xe(e,new e(t),s,s*2)),c=Bt(n,t,$),h=c.length-1,s=h;c[s]===0;--s)c.pop();return s<0?new e(r.s*0):(r.e=se(c,h),r.d=c,S=!1,o&&(r=k(r,i,a*4)),l&&(r=r.times(Math.abs(l)<54?I(2,l):V.pow(2,l))),S=!0,r)}function Ti(r,n){var t,e=n.d.length;if(e<3)return n.isZero()?n:Dt(r,2,n,n);t=1.4*Math.sqrt(e),t=t>16?16:t|0,n=n.times(1/ne(5,t)),n=Dt(r,2,n,n);for(var i,s=new r(5),o=new r(16),a=new r(20);t--;)i=n.times(n),n=n.times(s.plus(i.times(o.times(i).minus(a))));return n}function Dt(r,n,t,e,i){var s,o,a,l,c=r.precision,h=Math.ceil(c/b);for(S=!1,l=t.times(t),a=new r(e);;){if(o=k(a.times(l),new r(n++*n++),c,1),a=i?e.plus(o):e.minus(o),e=k(o.times(l),new r(n++*n++),c,1),o=a.plus(e),o.d[h]!==void 0){for(s=h;o.d[s]===a.d[s]&&s--;);if(s==-1)break}s=a,a=e,e=o,o=s}return S=!0,o.d.length=h+1,o}function ne(r,n){for(var t=r;--n;)t*=r;return t}function We(r,n){var t,e=n.s<0,i=J(r,r.precision,1),s=i.times(.5);if(n=n.abs(),n.lte(s))return nt=e?4:1,n;if(t=n.divToInt(i),t.isZero())nt=e?3:2;else{if(n=n.minus(t.times(i)),n.lte(s))return nt=Se(t)?e?2:3:e?4:1,n;nt=Se(t)?e?1:4:e?3:2}return n.minus(i).abs()}function Pe(r,n,t,e){var i,s,o,a,l,c,h,u,d,m=r.constructor,g=t!==void 0;if(g?(U(t,1,ut),e===void 0?e=m.rounding:U(e,0,8)):(t=m.precision,e=m.rounding),!r.isFinite())h=ze(r);else{for(h=K(r),o=h.indexOf("."),g?(i=2,n==16?t=t*4-3:n==8&&(t=t*3-2)):i=n,o>=0&&(h=h.replace(".",""),d=new m(1),d.e=h.length-o,d.d=Bt(K(d),10,i),d.e=d.d.length),u=Bt(h,10,i),s=l=u.length;u[--l]==0;)u.pop();if(!u[0])h=g?"0p+0":"0";else{if(o<0?s--:(r=new m(r),r.d=u,r.e=s,r=k(r,d,t,e,0,i),u=r.d,s=r.e,c=Le),o=u[t],a=i/2,c=c||u[t+1]!==void 0,c=e<4?(o!==void 0||c)&&(e===0||e===(r.s<0?3:2)):o>a||o===a&&(e===4||c||e===6&&u[t-1]&1||e===(r.s<0?8:7)),u.length=t,c)for(;++u[--t]>i-1;)u[t]=0,t||(++s,u.unshift(1));for(l=u.length;!u[l-1];--l);for(o=0,h="";o<l;o++)h+=ue.charAt(u[o]);if(g){if(l>1)if(n==16||n==8){for(o=n==16?4:3,--l;l%o;l++)h+="0";for(u=Bt(h,i,n),l=u.length;!u[l-1];--l);for(o=1,h="1.";o<l;o++)h+=ue.charAt(u[o])}else h=h.charAt(0)+"."+h.slice(1);h=h+(s<0?"p":"p+")+s}else if(s<0){for(;++s;)h="0"+h;h="0."+h}else if(++s>l)for(s-=l;s--;)h+="0";else s<l&&(h=h.slice(0,s)+"."+h.slice(s))}h=(n==16?"0x":n==2?"0b":n==8?"0o":"")+h}return r.s<0?"-"+h:h}function Ee(r,n){if(r.length>n)return r.length=n,!0}function Fi(r){return new this(r).abs()}function Bi(r){return new this(r).acos()}function Ui(r){return new this(r).acosh()}function Gi(r,n){return new this(r).plus(n)}function Xi(r){return new this(r).asin()}function Yi(r){return new this(r).asinh()}function zi(r){return new this(r).atan()}function Wi(r){return new this(r).atanh()}function ji(r,n){r=new this(r),n=new this(n);var t,e=this.precision,i=this.rounding,s=e+4;return!r.s||!n.s?t=new this(NaN):!r.d&&!n.d?(t=J(this,s,1).times(n.s>0?.25:.75),t.s=r.s):!n.d||r.isZero()?(t=n.s<0?J(this,e,i):new this(0),t.s=r.s):!r.d||n.isZero()?(t=J(this,s,1).times(.5),t.s=r.s):n.s<0?(this.precision=s,this.rounding=1,t=this.atan(k(r,n,s,1)),n=J(this,s,1),this.precision=e,this.rounding=i,t=r.s<0?t.minus(n):t.plus(n)):t=this.atan(k(r,n,s,1)),t}function qi(r){return new this(r).cbrt()}function $i(r){return x(r=new this(r),r.e+1,2)}function Zi(r,n,t){return new this(r).clamp(n,t)}function Qi(r){if(!r||typeof r!="object")throw Error(ie+"Object expected");var n,t,e,i=r.defaults===!0,s=["precision",1,ut,"rounding",0,8,"toExpNeg",-9e15,0,"toExpPos",0,he,"maxE",0,he,"minE",-9e15,0,"modulo",0,9];for(n=0;n<s.length;n+=3)if(t=s[n],i&&(this[t]=de[t]),(e=r[t])!==void 0)if(T(e)===e&&e>=s[n+1]&&e<=s[n+2])this[t]=e;else throw Error(ht+t+": "+e);if(t="crypto",i&&(this[t]=de[t]),(e=r[t])!==void 0)if(e===!0||e===!1||e===0||e===1)if(e)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[t]=!0;else throw Error(Fe);else this[t]=!1;else throw Error(ht+t+": "+e);return this}function Ji(r){return new this(r).cos()}function Ki(r){return new this(r).cosh()}function je(r){var n,t,e;function i(s){var o,a,l,c=this;if(!(c instanceof i))return new i(s);if(c.constructor=i,De(s)){c.s=s.s,S?!s.d||s.e>i.maxE?(c.e=NaN,c.d=null):s.e<i.minE?(c.e=0,c.d=[0]):(c.e=s.e,c.d=s.d.slice()):(c.e=s.e,c.d=s.d?s.d.slice():s.d);return}if(l=typeof s,l==="number"){if(s===0){c.s=1/s<0?-1:1,c.e=0,c.d=[0];return}if(s<0?(s=-s,c.s=-1):c.s=1,s===~~s&&s<1e7){for(o=0,a=s;a>=10;a/=10)o++;S?o>i.maxE?(c.e=NaN,c.d=null):o<i.minE?(c.e=0,c.d=[0]):(c.e=o,c.d=[s]):(c.e=o,c.d=[s]);return}if(s*0!==0){s||(c.s=NaN),c.e=NaN,c.d=null;return}return Ut(c,s.toString())}if(l==="string")return(a=s.charCodeAt(0))===45?(s=s.slice(1),c.s=-1):(a===43&&(s=s.slice(1)),c.s=1),Ue.test(s)?Ut(c,s):Li(c,s);if(l==="bigint")return s<0?(s=-s,c.s=-1):c.s=1,Ut(c,s.toString());throw Error(ht+s)}if(i.prototype=y,i.ROUND_UP=0,i.ROUND_DOWN=1,i.ROUND_CEIL=2,i.ROUND_FLOOR=3,i.ROUND_HALF_UP=4,i.ROUND_HALF_DOWN=5,i.ROUND_HALF_EVEN=6,i.ROUND_HALF_CEIL=7,i.ROUND_HALF_FLOOR=8,i.EUCLID=9,i.config=i.set=Qi,i.clone=je,i.isDecimal=De,i.abs=Fi,i.acos=Bi,i.acosh=Ui,i.add=Gi,i.asin=Xi,i.asinh=Yi,i.atan=zi,i.atanh=Wi,i.atan2=ji,i.cbrt=qi,i.ceil=$i,i.clamp=Zi,i.cos=Ji,i.cosh=Ki,i.div=ts,i.exp=es,i.floor=is,i.hypot=ss,i.ln=ns,i.log=rs,i.log10=as,i.log2=os,i.max=ls,i.min=cs,i.mod=hs,i.mul=us,i.pow=ds,i.random=fs,i.round=ms,i.sign=ps,i.sin=gs,i.sinh=ys,i.sqrt=vs,i.sub=ws,i.sum=Ps,i.tan=xs,i.tanh=bs,i.trunc=_s,r===void 0&&(r={}),r&&r.defaults!==!0)for(e=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],n=0;n<e.length;)r.hasOwnProperty(t=e[n++])||(r[t]=this[t]);return i.config(r),i}function ts(r,n){return new this(r).div(n)}function es(r){return new this(r).exp()}function is(r){return x(r=new this(r),r.e+1,3)}function ss(){var r,n,t=new this(0);for(S=!1,r=0;r<arguments.length;)if(n=new this(arguments[r++]),n.d)t.d&&(t=t.plus(n.times(n)));else{if(n.s)return S=!0,new this(1/0);t=n}return S=!0,t.sqrt()}function De(r){return r instanceof V||r&&r.toStringTag===Be||!1}function ns(r){return new this(r).ln()}function rs(r,n){return new this(r).log(n)}function os(r){return new this(r).log(2)}function as(r){return new this(r).log(10)}function ls(){return Ye(this,arguments,-1)}function cs(){return Ye(this,arguments,1)}function hs(r,n){return new this(r).mod(n)}function us(r,n){return new this(r).mul(n)}function ds(r,n){return new this(r).pow(n)}function fs(r){var n,t,e,i,s=0,o=new this(1),a=[];if(r===void 0?r=this.precision:U(r,1,ut),e=Math.ceil(r/b),this.crypto)if(crypto.getRandomValues)for(n=crypto.getRandomValues(new Uint32Array(e));s<e;)i=n[s],i>=429e7?n[s]=crypto.getRandomValues(new Uint32Array(1))[0]:a[s++]=i%1e7;else if(crypto.randomBytes){for(n=crypto.randomBytes(e*=4);s<e;)i=n[s]+(n[s+1]<<8)+(n[s+2]<<16)+((n[s+3]&127)<<24),i>=214e7?crypto.randomBytes(4).copy(n,s):(a.push(i%1e7),s+=4);s=e/4}else throw Error(Fe);else for(;s<e;)a[s++]=Math.random()*1e7|0;for(e=a[--s],r%=b,e&&r&&(i=I(10,b-r),a[s]=(e/i|0)*i);a[s]===0;s--)a.pop();if(s<0)t=0,a=[0];else{for(t=-1;a[0]===0;t-=b)a.shift();for(e=1,i=a[0];i>=10;i/=10)e++;e<b&&(t-=b-e)}return o.e=t,o.d=a,o}function ms(r){return x(r=new this(r),r.e+1,this.rounding)}function ps(r){return r=new this(r),r.d?r.d[0]?r.s:0*r.s:r.s||NaN}function gs(r){return new this(r).sin()}function ys(r){return new this(r).sinh()}function vs(r){return new this(r).sqrt()}function ws(r,n){return new this(r).sub(n)}function Ps(){var r=0,n=arguments,t=new this(n[r]);for(S=!1;t.s&&++r<n.length;)t=t.plus(n[r]);return S=!0,x(t,this.precision,this.rounding)}function xs(r){return new this(r).tan()}function bs(r){return new this(r).tanh()}function _s(r){return x(r=new this(r),r.e+1,1)}y[Symbol.for("nodejs.util.inspect.custom")]=y.toString;y[Symbol.toStringTag]="Decimal";var V=y.constructor=je(de);Zt=new V(Zt);Qt=new V(Qt);class Cs{constructor(){f(this,"parent");f(this,"name","");f(this,"extData");f(this,"mainCanvas");f(this,"_isRecalculate",!1);f(this,"notifyReload")}get isRecalculate(){return(this.parent?this.parent.isRecalculate:!1)||this._isRecalculate}set isRecalculate(n){this._isRecalculate=n}equalsMainCanvas(n){return this.mainCanvas===n}setMainCanvas(n){this.mainCanvas=n}}class Ss extends Cs{constructor(){super(...arguments);f(this,"_isVisible",!0);f(this,"inheritOpacity",!0);f(this,"_opacity");f(this,"_scaleRange")}get isVisible(){return this._isVisible}set isVisible(t){var e;t!=this.isVisible&&(this._isVisible=t,(e=this.notifyReload)==null||e.call(this,!0))}get opacity(){var t;return this.inheritOpacity?this._opacity??((t=this.parent)==null?void 0:t.opacity):this._opacity}set opacity(t){var e;this._opacity!=t&&(t===void 0||t>=0&&t<=1?(this._opacity=t,(e=this.notifyReload)==null||e.call(this,!1)):console.warn("Opacity value should be between 0 and 1."))}get scaleRange(){return this._scaleRange}set scaleRange(t){var e;t!=this.scaleRange&&(this._scaleRange=t,this.isVisible&&((e=this.notifyReload)==null||e.call(this)))}shouldRender(){var e;if(!this.isVisible||this.opacity===0)return!1;const t=(e=this.mainCanvas)==null?void 0:e.scale;if(this.scaleRange&&t){const i=Math.min(...this.scaleRange),s=Math.max(...this.scaleRange);return t>=i&&t<=s}return!0}}let Es=class extends Ss{constructor(n){super(),n.name=n.name||$t("default-name-"),Object.assign(this,{...n})}};class Ds extends Es{constructor(t){super(t);f(this,"_isInteractive",!0);f(this,"_isHoverable",!0);f(this,"_isDownable",!0);f(this,"_isContextmenuable",!0);f(this,"_isClickable",!0);f(this,"_isDoubleClickable",!0);f(this,"_isDraggable",!0);f(this,"_isWheelable",!0);Object.assign(this,{...t})}get isInteractive(){return this.getPropValue("isInteractive",this._isInteractive,!1)}set isInteractive(t){this._isInteractive=t}get isHoverable(){return this.getPropValue("isHoverable",this._isHoverable)}set isHoverable(t){this._isHoverable=t}get isDownable(){return this.getPropValue("isDownable",this._isDownable)}set isDownable(t){this._isDownable=t}get isContextmenuable(){return this.getPropValue("isContextmenuable",this._isContextmenuable)}set isContextmenuable(t){this._isContextmenuable=t}get isClickable(){return this.getPropValue("isClickable",this._isClickable)}set isClickable(t){this._isClickable=t}get isDoubleClickable(){return this.getPropValue("isDoubleClickable",this._isDoubleClickable)}set isDoubleClickable(t){this._isDoubleClickable=t}get isDraggable(){return this.getPropValue("isDraggable",this._isDraggable)}set isDraggable(t){this._isDraggable=t}get isWheelable(){return this.getPropValue("isWheelable",this._isWheelable)}set isWheelable(t){this._isWheelable=t}getPropValue(t,e,i=!0){return(this.parent?this.parent[t]:!0)&&e&&(i?this.isInteractive:!0)}}class Vs{constructor(n){f(this,"propagationStopped",!1);this.data=n}stopPropagation(){this.propagationStopped=!0}get canPropagate(){return!this.propagationStopped}}class Nt extends Ds{constructor(){super(...arguments);f(this,"listeners",{wheel:new Set,hover:new Set,down:new Set,contextmenu:new Set,click:new Set,doubleClick:new Set,dragg:new Set});f(this,"sharedControllers",{});f(this,"_eventDate",{});f(this,"_clearEventDate",!1);f(this,"_isHover",!1);f(this,"notifyHover",(t,e)=>this.checkEventDate("hover",t)&&this.trigger("hover",{state:t,oldState:this.isHover},e,"isHoverable"));f(this,"_isDown",!1);f(this,"notifyDown",(t,e)=>this.checkEventDate("down",t)&&this.trigger("down",{state:t,oldState:this.isDown},e,"isDownable"));f(this,"_isContextmenu",!1);f(this,"notifyContextmenu",(t,e)=>this.checkEventDate("contextmenu",t)&&this.trigger("contextmenu",{state:t,oldState:this.isContextmenu},e,"isContextmenuable"));f(this,"_isClick",!1);f(this,"clickTimestamp",0);f(this,"doubleClickInterval",300);f(this,"notifyClick",(t,e)=>{if(!this.checkEventDate("click",t))return;let i=!1;t?(i=Date.now()-this.clickTimestamp<this.doubleClickInterval,this.clickTimestamp=i?0:Date.now()):(this._isDblClick=!1,this.clickTimestamp=0),i?this.notifyDoubleClick(i,e):this.trigger("click",{state:t,oldState:this.isClick},e,"isClickable")});f(this,"_isDblClick",!1);f(this,"notifyDoubleClick",(t,e)=>this.checkEventDate("doubleClick",t)&&this.trigger("doubleClick",{state:t,oldState:this.isDblClick},e,"isDoubleClickable"));f(this,"notifyDragg",(t,e)=>this.checkEventDate("dragg",t)&&this.trigger("dragg",t,e,"isDraggable"));f(this,"notifyWheel",(t,e)=>this.checkEventDate("wheel",t)&&this.trigger("wheel",t,e,"isWheelable"))}addEventListener(t,e){this.listeners[t].add(e)}removeEventListener(t,e){this.listeners[t].delete(e)}registerControllers(t,e){this.sharedControllers[t]=e}hasController(t,e){var i;return(i=this.sharedControllers[t])==null?void 0:i.includes(e)}trigger(t,e,i,s){var c,h;if(!this[s])return;this.updateStates(t,e);const o=new Vs(e);this.listeners[t].forEach(u=>u(o,i));const a="notify"+(t.charAt(0).toUpperCase()+t.slice(1)),l=["notifyDragg","notifyWheel"].includes(a)?e:e.state;o.canPropagate&&((c=this.parent)==null||c[a](l,i)),(h=this.sharedControllers[t])==null||h.forEach(u=>u!==this&&u[a](l,i))}updateStates(t,e){const i=e;switch(t){case"hover":this._isHover=i.state;break;case"down":this._isDown=i.state;break;case"contextmenu":this._isContextmenu=i.state;break;case"click":this._isClick=i.state;break;case"doubleClick":this._isDblClick=i.state;break}}checkEventDate(t,e){const i=this._eventDate[t],s=JSON.stringify(e);return i==s?!1:(this._eventDate[t]=s,this._clearEventDate||(this._clearEventDate=!0,Promise.resolve().then(()=>{this._clearEventDate=!1,this._eventDate={}})),!0)}get isHover(){return this.isHoverable&&this._isHover}get isDown(){return this.isDraggable&&this._isDown}get isContextmenu(){return this.isClickable&&this._isContextmenu}get isClick(){return this.isClickable&&this._isClick}get isDblClick(){return this.isDoubleClickable&&this._isDblClick}}class Rs extends Nt{constructor(t){super(t);f(this,"canvas");f(this,"ctx");f(this,"_rectValueIsUpdated",!1);f(this,"_rect");f(this,"offset",{x:0,y:0});f(this,"center",{x:0,y:0});f(this,"defaultCenter",{top:void 0,bottom:void 0,left:void 0,right:void 0});f(this,"accuracy",5);f(this,"scale",1);f(this,"defaultScale",1);f(this,"percentage",1);f(this,"axisConfig",{count:2,min:100,size:100,x:1,y:1});f(this,"cycle",10);f(this,"delta",.02);f(this,"_redrawInNextRenderFrame",!1);f(this,"isAuto",!1);f(this,"isRendering",!1);f(this,"drawAxis");f(this,"layerGroups",new Map);f(this,"isScaleUpdated",!1);f(this,"nowGridCount");const{id:e,axisConfig:i,defaultCenter:s,offset:o,defaultScale:a}=t,l=document.getElementById(e);if(l instanceof HTMLCanvasElement)if(l.getContext){this.canvas=l,this.ctx=l.getContext("2d");const{clientWidth:c,clientHeight:h}=l;[l.width,l.height]=[c,h]}else throw new Error("canvas-unsupported code here");else throw new Error("canvas is not HTMLCanvasElement");i&&this.setAxis(i),o&&(this.offset.x=o.x||0,this.offset.y=o.y||0),s&&this.setDefaultCenter(s),a&&(this.updateCenter(),this.setScale("center",a-1),this.defaultScale=a)}get rect(){return this._rectValueIsUpdated&&this._rect?this._rect:(this._rectValueIsUpdated=!0,Promise.resolve().then(()=>this._rectValueIsUpdated=!1),this._rect=this.canvas.getBoundingClientRect(),this._rect)}get redrawInNextRenderFrame(){return this._redrawInNextRenderFrame}set redrawInNextRenderFrame(t){this._redrawInNextRenderFrame=t}setNotifyReload(t){this.notifyReload=t}getDefaultCenterLocation(){const{canvas:t,rect:e,defaultCenter:i}=this;if(!t)return console.error("canvas is not HTMLCanvasElement");const{width:s,height:o}=e,{top:a,bottom:l,left:c,right:h}=i,u={vertical:(p,v)=>{if([0,"0","0%"].includes(p))return 0;if(!(p==1/0||p==-1/0))return typeof p=="number"?p:["top","left"].includes(p)?0:["bottom","right"].includes(p)?v:["middle","center"].includes(p)?v/2:/^(-?\d+)%$/.test(p)?(p=p.match(/^(-?\d+)%$/)[1],v*Number(p)/100):Number(p)||void 0},reverse:(p,v)=>{if([0,"0","0%"].includes(p))return v;if(p==1/0||p==-1/0)return;if(typeof p=="number")return v-p;const w=u.vertical(p,v);return w?v-w:void 0}},d=(p,v,w)=>{if(p!==void 0){const _=u.vertical(p,w);if(_!==void 0)return _}if(v!==void 0){const _=u.reverse(v,w);if(_!==void 0)return _}return w/2},m=d(a,l,o);return{x:d(c,h,s),y:m}}updateCenter(){const t=this.getDefaultCenterLocation();if(!t)return;const{x:e,y:i}=t;this.center={x:Math.floor(e+this.offset.x),y:Math.floor(i+this.offset.y)}}updateSize(){const{scale:t,axisConfig:e}=this;e.size=this.getGridSize(t),this.percentage=this.getAxisPointByValue(e.count,0).x/e.min}setScale(t,e){const{canvas:i,isWheelable:s,axisConfig:o,rect:a}=this;if(!s||!i)return console.error("canvas is not HTMLCanvasElement");let l,c;t==="center"?(l=a.left+a.width/2,c=a.top+a.height/2):[l,c]=[t.clientX,t.clientY];const h=this.getMousePositionOnAxis({clientX:l,clientY:c}),u=this.getAxisValueByPoint(h.x,h.y);this.scale=new V(this.scale).add(e).toNumber(),this.isScaleUpdated=!0,this.updateSize();const d=this.getAxisPointByValue(u.xV,u.yV);this.offset.x-=(d.x-h.x)*o.x,this.offset.y-=(d.y-h.y)*o.y,this.offset.x=Number(this.offset.x.toFixed(0)),this.offset.y=Number(this.offset.y.toFixed(0))}setAxis(t){const e={...this.axisConfig,...t},i=Object.fromEntries(Object.entries(e).map(([p,v])=>[p,Number(v)])),{x:s,y:o,count:a,min:l,size:c}=i,h=[1,-1].includes(s),u=[1,-1].includes(o),d=a>0,m=l>0,g=c>=l&&c<=l*2;if(!h||!u||!d||!m){console.warn("Invalid axis configuration:",{x:s,y:o,count:a,min:l});return}g||(i.size=l),this.axisConfig=i}setDefaultCenter(t){Object.assign(this.defaultCenter,t),this.updateCenter()}getGridSize(t){const{cycle:e,delta:i,axisConfig:s}=this;let o=new V(t).sub(1).abs().mod(e*i).div(i).toNumber();return o=t<1&&o!=0?e-o:o,Number(((o/e+1)*s.min).toFixed(0))}getGridCount(t){const{axisConfig:e,cycle:i,delta:s}=this,o=e.count,a=i*s;if(t===1)return o;if(t>1){const l=new V(t).sub(1).div(a).floor();return new V(o).div(new V(2).pow(l)).toNumber()}else{const l=new V(1).sub(t).div(a).ceil();return new V(o).mul(new V(2).pow(l)).toNumber()}}get getNowGridCount(){const{scale:t,nowGridCount:e,isRendering:i}=this;return e&&i?e:(this.nowGridCount=this.getGridCount(t),i&&Promise.resolve().then(()=>this.nowGridCount=void 0),this.nowGridCount)}getMousePositionOnAxis(t){const{canvas:e,center:i,rect:s,axisConfig:o}=this;if(!e)return console.error("canvas is not HTMLCanvasElement");const{clientX:a,clientY:l}=t,{left:c,top:h}=s,u=(a-c-i.x)*o.x,d=(l-h-i.y)*o.y;return{x:u,y:d}}getAxisValueByPoint(t,e,i){const{axisConfig:s}=this;if(i)return{xV:t/s.min*s.count,yV:e/s.min*s.count};const o=this.getNowGridCount,a=new V(t).div(s.size).mul(o).toFixed(8),l=new V(e).div(s.size).mul(o).toFixed(8);return{xV:Number(a),yV:Number(l)}}getAxisPointByValue(t,e,i){const{axisConfig:s}=this;if(i)return{x:t/s.count*s.min,y:e/s.count*s.min};const o=this.getNowGridCount,a=new V(t).div(o).mul(s.size).toFixed(3),l=new V(e).div(o).mul(s.size).toFixed(3);return{x:Number(a),y:Number(l)}}getMaxMinValue(t){t=t||this.rect;const{left:e,top:i,right:s,bottom:o}=t,{axisConfig:a}=this,{x:l,y:c}=this.getMousePositionOnAxis({clientX:a.x==1?e:s,clientY:a.y==1?i:o}),{xV:h,yV:u}=this.getAxisValueByPoint(l,c),{x:d,y:m}=this.getMousePositionOnAxis({clientX:a.x==1?s:e,clientY:a.y==1?o:i}),{xV:g,yV:p}=this.getAxisValueByPoint(d,m);return{minXV:h,maxXV:g,minYV:u,maxYV:p}}transformPosition(t){const{center:e,percentage:i,axisConfig:s}=this,o=i*s.x,a=i*s.y,l=c=>[e.x+c[0]*o,e.y+c[1]*a];return Array.isArray(t[0])?t.map(c=>l(c)):l(t)}}class ks extends Rs{constructor(t){super(t);f(this,"theme","light");f(this,"isThemeUpdated",!1);f(this,"style",{light:{background:"#fff",text:{color:"#222",secondary:"#909399",stroke:"#fff",size:12,family:"monospace",bold:!0},grid:{axis:"#222",grid:"#666",innerGrid:"#e5e5e5"},point:{radius:5,fill:"#d03050",width:14,stroke:"#d0305080"},line:{stroke:{color:"#f0a020",color_hover:"#f2c97d",width:4,dash:!1,dashGap:[5,10],dashOffset:0,cap:"round",join:"round"},point:{radius:5,stroke:"#f0a02080",width:14,fill:"#f0a020"}},arc:{fill:"#f0a02030",fill_hover:"#f2c97d60",stroke:{color:"#f0a020",color_hover:"#f2c97d",width:4,dash:!1,dashGap:[5,10],dashOffset:0,cap:"round",join:"round"},point:{radius:5,stroke:"#f0a02080",width:14,fill:"#f0a020"}},arcTo:{stroke:{color:"#f0a020",color_hover:"#f2c97d",width:4,dash:!1,dashGap:[5,10],dashOffset:0,cap:"round",join:"round"},point:{radius:5,stroke:"#f0a02080",width:14,fill:"#f0a020"}},polygon:{fill:"#18a05830",fill_hover:"#03693360",stroke:{color:"#18a058",color_hover:"#036933",width:1,dash:!1,dashGap:[5,10],dashOffset:0,cap:"round",join:"round"},point:{radius:5,stroke:"#03693380",width:14,fill:"#036933"}}},dark:{background:"#000",text:{color:"#aeaeae",secondary:"#8c8c8c",stroke:"#000",size:12,family:"monospace",bold:!0},grid:{axis:"#aeaeae",grid:"#666",innerGrid:"#454545"},point:{radius:5,fill:"#e88080",width:14,stroke:"#e8808070"},line:{stroke:{color:"#f2c97d",color_hover:"#f0a020",width:4,dash:!1,dashGap:[5,10],dashOffset:0,cap:"round",join:"round"},point:{radius:5,stroke:"#f2c97d80",width:14,fill:"#f2c97d"}},arc:{fill:"#f2c97d30",fill_hover:"#f0a02060",stroke:{color:"#f2c97d",color_hover:"#f0a020",width:4,dash:!1,dashGap:[5,10],dashOffset:0,cap:"round",join:"round"},point:{radius:5,stroke:"#f2c97d80",width:14,fill:"#f2c97d"}},arcTo:{stroke:{color:"#f2c97d",color_hover:"#f0a020",width:4,dash:!1,dashGap:[5,10],dashOffset:0,cap:"round",join:"round"},point:{radius:5,stroke:"#f2c97d80",width:14,fill:"#f2c97d"}},polygon:{fill:"#63e2b730",fill_hover:"#7efbd160",stroke:{color:"#63e2b7",color_hover:"#63e2b7",width:1,dash:!1,dashGap:[5,10],dashOffset:0,cap:"round",join:"round"},point:{radius:5,stroke:"#7efbd180",width:14,fill:"#7efbd1"}}}});const{theme:e}=t;e&&this.setTheme(e),this.initStyle(),this.clearScreen()}initStyle(){const{canvas:t,ctx:e,theme:i}=this;t.classList.add("_nhanh_canvas");const s=this.style[i];e.font=`${s.text.bold?"bold":""} ${s.text.size}px ${s.text.family}`}clearScreen(t=!0){const{ctx:e,theme:i,rect:s}=this,{width:o,height:a}=s;e.clearRect(0,0,o,a),t&&this.style[i].background&&(e.fillStyle=this.style[i].background,e.fillRect(0,0,o,a))}setStyle(t){for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e)){const i=Ie(this.style[e]||this.style[this.theme]);ct(i,t[e]),this.style[e]=i}this.initStyle()}setTheme(t){t in this.style&&(this.theme=t,this.isThemeUpdated=!0)}}class R extends Nt{constructor(t){t={...t},t.isDraggable=t.isDraggable??!1;const{mainCanvas:e,notifyReload:i}=t;delete t.mainCanvas,delete t.notifyReload;super(t);f(this,"_style");f(this,"_position");f(this,"_value");f(this,"_zIndex",0);f(this,"_dynamicPosition");f(this,"_offset",{x:0,y:0});f(this,"path");f(this,"publicToPrivateKeyMap",{offset:"_offset",position:"_position",value:"_value",dynamicPosition:"_dynamicPosition",zIndex:"_zIndex",style:"_style"});f(this,"redrawOnIsHoverChange",!0);f(this,"defaultHover",(t,e)=>{var i;this.redrawOnIsHoverChange&&((i=this.notifyReload)==null||i.call(this))});f(this,"_valueScope");f(this,"styleRadius",{value:0,radius:0});f(this,"offsetValue",{xV:0,yV:0});f(this,"fixedExtraScope",{topV:0,bottomV:0,leftV:0,rightV:0});f(this,"extraScope",{top:0,bottom:0,left:0,right:0,topV:0,bottomV:0,leftV:0,rightV:0});this.setNotifyReload(i),this.mainCanvas=e,["redrawOnIsHoverChange"].forEach(o=>{o in t&&(this[o]=t[o])});const s={};["offset","style","zIndex","position","dynamicPosition","value"].forEach(o=>{o in t&&(s[o]=t[o])}),this.internalUpdate(s),this.addEventListener("hover",this.defaultHover)}get style(){return this._style}set style(t){var e;this._style=t,this.mainCanvas&&(this.updateValueScope(),(e=this.notifyReload)==null||e.call(this))}get position(){return this._position}set position(t){var e;this._position=t,this._value=void 0,this.updateBaseData(),(e=this.notifyReload)==null||e.call(this)}get value(){return this._value}set value(t){var e;this._value=t,this._position=void 0,this.updateBaseData(),(e=this.notifyReload)==null||e.call(this)}get zIndex(){return this._zIndex}set zIndex(t){var e;this._zIndex!=t&&(this._zIndex=t,(e=this.notifyReload)==null||e.call(this))}get dynamicPosition(){return this._dynamicPosition}set dynamicPosition(t){this._dynamicPosition=t}get offset(){return this._offset}set offset(t){var e;this._offset=t,this.calculateOffsetValue(),(e=this.notifyReload)==null||e.call(this)}get finalDynamicPosition(){var i;const{x:t,y:e}=this.offset;return(i=this.dynamicPosition)==null?void 0:i.map((s,o)=>typeof s=="number"?o==0?s+t:s+e:[s[0]+t,s[1]+e])}internalUpdate(t,e){Object.keys(t).forEach(i=>{const s=this.publicToPrivateKeyMap[i];s&&(this[s]=t[i])}),e&&this.updateValueScope()}setMainCanvas(t){super.setMainCanvas(t),t&&this.updateBaseData()}setNotifyReload(t){this.notifyReload=t?e=>{var i;e&&(this.isRecalculate=!0),(e||this.isNeedRender||(i=this.mainCanvas)!=null&&i.currentDrawOverlays.includes(this))&&t()}:void 0}get valueScope(){return this._valueScope}set valueScope(t){this._valueScope=t}initValueScope(){const t=this.value;if(Array.isArray(t[0])){let e=1/0,i=-1/0,s=1/0,o=-1/0;t.forEach(([a,l])=>{e=Math.min(e,a),i=Math.max(i,a),s=Math.min(s,l),o=Math.max(o,l)}),this.valueScope={minX:e,maxX:i,minY:s,maxY:o}}else{const[e,i]=t;this.valueScope={minX:e,maxX:e,minY:i,maxY:i}}this.calculateStyleRadiusValue(!1),this.calculateOffsetValue(!1),this.setFixedExtraScope(!0),this.setExtraScope(!0)}calculateStyleRadiusValue(t=!0){if(!(!this.mainCanvas||!this.valueScope))if(t){const{radius:e,value:i}=this.styleRadius;if(e==0)return;const s=this.mainCanvas.getAxisValueByPoint(e,0).xV,o=s-i;this.valueScope.minX-=o,this.valueScope.maxX+=o,this.valueScope.minY-=o,this.valueScope.maxY+=o,this.styleRadius={radius:e,value:s}}else{const{stroke:e,point:i}=this.computedValueScopeStyles,s=i?i.radius+Math.max(0,i.width/2):0,o=e?Math.max(0,e.width/2):0,a=Math.max(s,o);if(a==0)return this.styleRadius={radius:0,value:0};const l=this.mainCanvas.getAxisValueByPoint(a,0).xV;this.valueScope.minX-=l,this.valueScope.maxX+=l,this.valueScope.minY-=l,this.valueScope.maxY+=l,this.styleRadius={radius:a,value:l}}}calculateOffsetValue(t=!0){const{mainCanvas:e,valueScope:i,offset:s,offsetValue:o}=this;if(!(!e||!i))if(t){const{x:a,y:l}=e.axisConfig;let{xV:c,yV:h}=e.getAxisValueByPoint(s.x,s.y);c*=a,h*=l;const u=c-o.xV,d=h-o.yV;i.minX+=u,i.maxX+=u,i.minY+=d,i.maxY+=d,this.offsetValue={xV:c,yV:h}}else{if(this.offsetValue={xV:0,yV:0},s.x==0&&s.y==0)return;this.calculateOffsetValue()}}setFixedExtraScope(t){if(t===!0)this.fixedExtraScope={topV:0,bottomV:0,leftV:0,rightV:0};else{const e=t||{topV:0,bottomV:0,leftV:0,rightV:0};if(this.valueScope){const{leftV:i,rightV:s,topV:o,bottomV:a}=e;this.valueScope.minX-=i-this.fixedExtraScope.leftV,this.valueScope.maxX+=s-this.fixedExtraScope.rightV,this.valueScope.minY-=o-this.fixedExtraScope.topV,this.valueScope.maxY+=a-this.fixedExtraScope.bottomV,this.fixedExtraScope=e}}}setExtraScope(t){const{valueScope:e,mainCanvas:i,extraScope:s}=this;if(!(!e||!i))if(t===!0)this.extraScope={top:0,bottom:0,left:0,right:0,topV:0,bottomV:0,leftV:0,rightV:0};else if(t){const{left:o,right:a,top:l,bottom:c}=t,{xV:h,yV:u}=i.getAxisValueByPoint(l,c),{xV:d,yV:m}=i.getAxisValueByPoint(o,a);e.minX-=d-s.leftV,e.maxX+=m-s.rightV,e.minY-=h-s.topV,e.maxY+=u-s.bottomV,this.extraScope={...t,topV:h,bottomV:u,leftV:d,rightV:m}}else this.setExtraScope(this.extraScope)}get isWithinRange(){const{mainCanvas:t,valueScope:e}=this;if(!t)return!1;const{isScaleUpdated:i,maxMinValue:s}=t;return i&&(this.calculateStyleRadiusValue(),this.calculateOffsetValue(),this.setExtraScope()),e?!(s.maxXV<e.minX||s.minXV>e.maxX||s.maxYV<e.minY||s.minYV>e.maxY):!0}get isNeedRender(){return!!(this.mainCanvas&&this.shouldRender()&&this.dynamicPosition&&this.isWithinRange)}calculateOffset(t,e){const{percentage:i,axisConfig:s}=this.mainCanvas,o=s.count/s.min/i,a={value:t*o*s.x,position:t/i*s.x,dynamicPosition:t},l={value:e*o*s.y,position:e/i*s.y,dynamicPosition:e};return{x:a,y:l}}handleValuePosition(t,e){let{value:i,position:s,mainCanvas:o}=this;if(!o)return!1;const a=t==="array1D"?ee:Mt,[l,c]=[a(i)&&(!e||i.length>=e),a(s)&&(!e||s.length>=e)],h={value:i,position:s,dynamicPosition:[]};if(!l&&!c)return this.internalUpdate({dynamicPosition:void 0}),!1;if(l){const u=i;if(t==="array1D"){const d=o.getAxisPointByValue(u[0],u[1],!0);h.position=[d.x,d.y]}else{h.position=[];for(let d=0;d<u.length;d++){const m=u[d],g=o.getAxisPointByValue(m[0],m[1],!0);h.position.push([g.x,g.y])}}}else{const u=s;if(t==="array1D"){const d=o.getAxisValueByPoint(u[0],u[1],!0);h.value=[d.xV,d.yV]}else{h.value=[];for(let d=0;d<u.length;d++){const m=u[d],g=o.getAxisValueByPoint(m[0],m[1],!0);h.value.push([g.xV,g.yV])}}}return h.dynamicPosition=o.transformPosition(h.position),this.internalUpdate(h,!0),!0}isPointInAnywhere(t,e){return this.isPointInPath(t,e)||this.isPointInStroke(t,e)}setGlobalAlpha(t){var i;const e=this.opacity??((i=this.parent)==null?void 0:i.opacity);e!==void 0&&(t.globalAlpha=e)}setBaseLineStyle(t,e){const{width:i,dash:s,dashGap:o,dashOffset:a,color:l,color_hover:c,cap:h,join:u}=e;return t.setLineDash(s?o:[]),t.lineDashOffset=a,t.lineCap=h,t.lineJoin=u,t.lineWidth=i,t.strokeStyle=this.isHover?c:l,e}get cursorStyle(){return this.isInteractive?this.isDraggable?"_nhanh_canvas_hover_overlay_draggable":"_nhanh_canvas_hover_overlay":void 0}}f(R,"ctx",document.createElement("canvas").getContext("2d"));class Gt extends R{constructor(t){super(t);f(this,"_draw");this.redrawOnIsHoverChange=!1;const{draw:e}=t;Object.assign(this,{draw:e})}updateValueScope(){this.initValueScope()}isPointInPath(t,e){return!1}isPointInStroke(t,e){return!1}updateBaseData(){if(!this.mainCanvas)return;this.internalUpdate({dynamicPosition:[]});let t=this.value,e=this.position;t?e=this.convertValuesToPositions(t):e&&(t=this.convertPositionsToValues(e)),t&&e&&this.updateDataProperties(t,e)}convertValuesToPositions(t){const e=[];let i;return t.forEach(s=>{if(i===void 0){const o=this.mainCanvas.getAxisPointByValue(s[0],s[1],!0);e.push([o.x,o.y]),s[0]!=0?i=new V(o.x).div(s[0]).toNumber():s[1]!=0&&(i=new V(o.y).div(s[1]).toNumber())}else e.push([new V(i).mul(s[0]).toNumber(),new V(i).mul(s[1]).toNumber()])}),e}convertPositionsToValues(t){const e=[];let i;return t.forEach((s,o)=>{if(i===void 0){const a=this.mainCanvas.getAxisValueByPoint(s[0],s[1],!0);e.push([a.xV,a.yV]),s[0]!=0?i=new V(a.xV).div(s[0]).toNumber():s[1]!=0&&(i=new V(a.yV).div(s[1]).toNumber())}else e.push([new V(i).mul(s[0]).toNumber(),new V(i).mul(s[1]).toNumber()])}),e}updateDataProperties(t,e){this.internalUpdate({value:t,position:e,dynamicPosition:this.mainCanvas.transformPosition(e)})}setOverlayStyles(t){}get computedValueScopeStyles(){return{}}get draw(){return t=>{var e;this.setGlobalAlpha(t),(e=this._draw)==null||e.call(this,t)}}set draw(t){this._draw=t}getDraw(){if(this.isNeedRender){const{mainCanvas:t,position:e}=this;return this.isRecalculate&&e&&this.internalUpdate({dynamicPosition:t.transformPosition(e)}),[this.draw,this]}}}class O{static add(n,t){return new V(n).add(t).toNumber()}static sub(n,t){return new V(n).sub(t).toNumber()}static mul(n,t){return new V(n).mul(t).toNumber()}static div(n,t){return new V(n).div(t).toNumber()}}class Xt extends R{constructor(t){super(t);f(this,"textOffset",{x:0,y:0});f(this,"_text");f(this,"defaultDragg",(t,e)=>{var l;const{offsetX:i,offsetY:s}=t.data,{x:o,y:a}=this.calculateOffset(i,s);this.internalUpdate({value:[O.add(this.value[0],o.value),O.add(this.value[1],a.value)],position:[O.add(this.position[0],o.position),O.add(this.position[1],a.position)],dynamicPosition:[O.add(this.dynamicPosition[0],o.dynamicPosition),O.add(this.dynamicPosition[1],a.dynamicPosition)]},!0),(l=this.notifyReload)==null||l.call(this)});const{text:e}=t;Object.assign(this,{text:e}),this.addEventListener("dragg",this.defaultDragg)}get text(){return this._text}set text(t){var e;this._text!=t&&(this._text=t,this.updateBaseData(),(e=this.notifyReload)==null||e.call(this))}updateValueScope(){this.initValueScope();const t=this.textOffset;this.setExtraScope({top:t.y,bottom:t.y,left:t.x,right:t.x})}isPointInPath(t,e){return this.path?R.ctx.isPointInPath(this.path,t,e):!1}isPointInStroke(t,e){return!1}updateBaseData(){if(!this.mainCanvas)return;if(!this.text||this.text.length==0)return this.internalUpdate({dynamicPosition:void 0});const t=R.ctx;this.setOverlayStyles(t);const e=t.measureText(this.text);this.textOffset={x:e.width/2,y:e.actualBoundingBoxAscent/2},this.handleValuePosition("array1D")}setOverlayStyles(t){var o;const e=this.mainCanvas,i=e.style[e.theme].text;let s={};return typeof this.style=="string"?s=((o=e.style[this.style])==null?void 0:o.text)||i:typeof this.style=="object"?s=Object.assign({},i,this.style):s=i,t.font=`${s.bold?"bold":""} ${s.size}px ${s.family}`,t.lineWidth=2,t.strokeStyle=s.stroke,t.fillStyle=s[this.isHover?"secondary":"color"],s}get computedValueScopeStyles(){return{}}draw(t){const{text:e,textOffset:i,finalDynamicPosition:s}=this;if(!this.mainCanvas||!e)return;this.setGlobalAlpha(t),this.setOverlayStyles(t);const o=s[0]-i.x,a=s[1]+i.y;t.strokeText(e,o,a),t.fillText(e,o,a),this.path=new Path2D,this.path.rect(o,s[1]-i.y,i.x*2,i.y*2)}getDraw(){if(this.isNeedRender){if(this.isRecalculate){const{position:t,mainCanvas:e}=this;this.internalUpdate({dynamicPosition:e.transformPosition(t)})}return[this.draw,this]}}}class lt extends R{constructor(t){super(t);f(this,"angle",2*Math.PI);f(this,"defaultDragg",(t,e)=>{var l;const{offsetX:i,offsetY:s}=t.data,{x:o,y:a}=this.calculateOffset(i,s);this.internalUpdate({value:[O.add(this.value[0],o.value),O.add(this.value[1],a.value)],position:[O.add(this.position[0],o.position),O.add(this.position[1],a.position)],dynamicPosition:[O.add(this.dynamicPosition[0],o.dynamicPosition),O.add(this.dynamicPosition[1],a.dynamicPosition)]},!0),(l=this.notifyReload)==null||l.call(this)});f(this,"fillProgress");f(this,"defaultHover",(t,e)=>{const i=t.data.state,s=300,o=this.setOverlayStyles().width;this.fillProgress?this.cancelAndRestartAnimation(i,o,s-100):i&&this.startNewHoverAnimation(o,s)});this.addEventListener("hover",this.defaultHover),this.addEventListener("dragg",this.defaultDragg)}updateValueScope(){this.initValueScope()}cancelAndRestartAnimation(t,e,i){this.fillProgress.scheduleCallback();let s=0;this.fillProgress.scheduleCallback=kt(o=>{!this.fillProgress||!o||(this.fillProgress.progress+=(o-s)*(t?1:-1),s=o,this.fillProgress.progress=Math.min(1,Math.max(0,this.fillProgress.progress)),this.updateLineWidthOffset(e),(this.fillProgress.progress===1||this.fillProgress.progress===0)&&(this.fillProgress.scheduleCallback(),this.fillProgress.progress===0&&(this.fillProgress=void 0)))},i)}startNewHoverAnimation(t,e){this.fillProgress={lineWidthOffset:0,progress:0,scheduleCallback:kt(i=>{this.fillProgress&&(this.fillProgress.progress=i,this.updateLineWidthOffset(t))},e)}}updateLineWidthOffset(t){var i;if(!this.fillProgress)return;const e=Math.ceil(t*this.fillProgress.progress);e!==this.fillProgress.lineWidthOffset&&(this.fillProgress.lineWidthOffset=e,(i=this.notifyReload)==null||i.call(this))}isPointInPath(t,e){return this.path?R.ctx.isPointInPath(this.path,t,e):!1}isPointInStroke(t,e){var i;if(this.path&&this.mainCanvas){const{width:s}=this.setOverlayStyles(R.ctx);return((i=this.fillProgress)==null?void 0:i.lineWidthOffset)==s?!1:R.ctx.isPointInStroke(this.path,t,e)}return!1}updateBaseData(){this.handleValuePosition("array1D")}setOverlayStyles(t){var c,h;const e=this.mainCanvas,i=e.style[e.theme].point;let s={};typeof this.style=="string"?s=((c=e.style[this.style])==null?void 0:c.point)||i:typeof this.style=="object"?s=Object.assign({},i,this.style):s=i;const{width:o,stroke:a,fill:l}=s;if(t){t.setLineDash([]);const u=((h=this.fillProgress)==null?void 0:h.lineWidthOffset)||0;t.lineWidth=o-u,t.strokeStyle=a,t.fillStyle=l}return{...s}}get computedValueScopeStyles(){return{point:this.setOverlayStyles()}}draw(t){var h;const{finalDynamicPosition:e,mainCanvas:i}=this;if(!i)return;this.setGlobalAlpha(t);const{radius:s,width:o}=this.setOverlayStyles(t),a=((h=this.fillProgress)==null?void 0:h.lineWidthOffset)||0,[l,c]=e;t.beginPath(),this.path=new Path2D,this.path.arc(l,c,s+a/2,0,this.angle),o!=a&&t.stroke(this.path),t.fill(this.path)}getDraw(){if(this.isNeedRender){const{mainCanvas:t,position:e}=this;return this.isRecalculate&&this.internalUpdate({dynamicPosition:t.transformPosition(e)}),[this.draw,this]}}}class qe extends R{constructor(t){super(t);f(this,"handlePoints",[]);f(this,"isShowHandlePoint",!1);f(this,"_isHandlePointsVisible",!0);f(this,"canCreateOrDeleteHandlePoint",!0);f(this,"lockedCanCreateOrDeleteHandlePoint",!1);f(this,"defaultClick",(t,e)=>{var o;if(!this.isHandlePointsVisible)return;const{state:i,oldState:s}=t.data;i!=s&&!this.isInfinite&&((o=this.notifyReload)==null||o.call(this))});f(this,"defaultDoubleClick",(t,e)=>{if(e){if(!this.isHandlePointsVisible)return;const{offsetX:i,offsetY:s}=e,{state:o}=t.data;if(this.lockedCanCreateOrDeleteHandlePoint)this.resetHandlePointLock();else if(o&&this.isHandlePointsVisible&&this.canCreateOrDeleteHandlePoint&&this.isDraggable){const l=this.handlePoints.findIndex(c=>c.isHover);l===-1?this.tryCreateNewHandlePoint(i,s):this.tryDeleteHandlePoint(l)}}});f(this,"defaultDragg",(t,e)=>{var s;if(!this.mainCanvas)return;const i=()=>{const{offsetX:o,offsetY:a}=t.data,{x:l,y:c}=this.calculateOffset(o,a);this.value.forEach((h,u)=>{this.value[u]=[O.add(this.value[u][0],l.value),O.add(this.value[u][1],c.value)],this.position[u]=[O.add(this.position[u][0],l.position),O.add(this.position[u][1],c.position)],this.dynamicPosition[u]=[O.add(this.dynamicPosition[u][0],l.dynamicPosition),O.add(this.dynamicPosition[u][1],c.dynamicPosition)]}),this.handlePoints.forEach((h,u)=>{h.internalUpdate({value:this.value[u],position:this.position[u],dynamicPosition:this.dynamicPosition[u]})}),this.lockedCanCreateOrDeleteHandlePoint=!0};if(this.isHandlePointsVisible){const o=this.handlePoints.findIndex(a=>a.isHover);if(o!=-1){const a=this.handlePoints[o];a.notifyDragg(t.data,e),this.value[o]=a.value,this.position[o]=a.position,this.dynamicPosition[o]=a.dynamicPosition}else i()}else i();(s=this.notifyReload)==null||s.call(this),this.updateValueScope()});["isHandlePointsVisible","canCreateOrDeleteHandlePoint"].forEach(e=>{e in t&&(this[e]=t[e])}),this.addEventListener("click",this.defaultClick),this.addEventListener("doubleClick",this.defaultDoubleClick),this.addEventListener("dragg",this.defaultDragg)}get isHandlePointsVisible(){return this._isHandlePointsVisible}set isHandlePointsVisible(t){var e;this._isHandlePointsVisible!==t&&(this._isHandlePointsVisible=t,this.isShowHandlePoint!=t&&((e=this.notifyReload)==null||e.call(this)),this.updateHandlePoints())}get offset(){return super.offset}set offset(t){super.offset=t;let{isHandlePointsVisible:e,handlePoints:i}=this;e&&i.forEach(s=>s.internalUpdate({offset:t}))}tryCreateNewHandlePoint(t,e){var c;if(!this.isPointInStroke(t,e))return;const i=this.getExtendedDynamicPositions(),s=Ms([t,e],i);if(s===-1)return;const[o,a]=this.getAdjacentIndices(s),l=this.createNewHandlePoint(o,a);this.insertHandlePoint(s,l),this.lockHandlePointCreationTemporarily(),(c=this.notifyReload)==null||c.call(this)}tryDeleteHandlePoint(t){var e;!this.isDblClick||!this.canDeleteHandlePoint||(this.deleteHandlePoint(t),(e=this.notifyReload)==null||e.call(this))}getExtendedDynamicPositions(){return this.isClosed?[...this.dynamicPosition,this.dynamicPosition[0]]:this.dynamicPosition}getAdjacentIndices(t){const e=t-1,i=this.isClosed&&t===this.dynamicPosition.length?0:t;return[e,i]}createNewHandlePoint(t,e){const i=ae(this.value[t],this.value[e]),s=ae(this.position[t],this.position[e]),o=ae(this.dynamicPosition[t],this.dynamicPosition[e]);return new lt({value:i,position:s,dynamicPosition:o,isDraggable:!0,mainCanvas:this.mainCanvas,notifyReload:()=>{var a;return(a=this.notifyReload)==null?void 0:a.call(this)}})}insertHandlePoint(t,e){this.handlePoints.splice(t,0,e),this.value.splice(t,0,e.value),this.position.splice(t,0,e.position),this.dynamicPosition.splice(t,0,e.dynamicPosition)}deleteHandlePoint(t){this.handlePoints.splice(t,1),this.value.splice(t,1),this.position.splice(t,1),this.dynamicPosition.splice(t,1)}lockHandlePointCreationTemporarily(){this.lockedCanCreateOrDeleteHandlePoint=!0,setTimeout(()=>{this.lockedCanCreateOrDeleteHandlePoint=!1},300)}resetHandlePointLock(){this.lockedCanCreateOrDeleteHandlePoint=!1}get canDeleteHandlePoint(){return this.handlePoints.length>this.minNeededHandlePoints}updateHandlePoints(){let{value:t,position:e,dynamicPosition:i,offset:s,isHandlePointsVisible:o}=this;!i||!o||(t==null||t.forEach((a,l)=>{if(!this.handlePoints[l]){const c=new lt({value:[0,0],mainCanvas:this.mainCanvas,isDraggable:!0,offset:s,notifyReload:()=>{var h;return(h=this.notifyReload)==null?void 0:h.call(this)}});this.handlePoints.push(c)}this.handlePoints[l].internalUpdate({value:t[l],position:e[l],dynamicPosition:i[l]},!0)}),this.handlePoints.length=t.length)}updateHandlePointsPosition(){this.isHandlePointsVisible&&this.handlePoints.forEach((t,e)=>{t.internalUpdate({dynamicPosition:this.dynamicPosition[e]})})}}function Ms(r,n,t=10){if(n.length===0)return 0;if(n.length===1)return 1;let e=1/0,i=-1;for(let s=0;s<n.length-1;s++){const o=Je(r,n[s],n[s+1]);if(o<t)return s+1;o<e&&(e=o,i=s+1)}return i}function ae(r,n){const{x:t,y:e}=be(...r,...n);return[t,e]}class Yt extends qe{constructor(t){super(t);f(this,"_isInfinite");f(this,"isClosed",!1);f(this,"minNeededHandlePoints",2);const{isInfinite:e}=t;Object.assign(this,{isInfinite:e}),e&&(this.canCreateOrDeleteHandlePoint=!1)}get isInfinite(){return this._isInfinite}set isInfinite(t){var e;this._isInfinite!=t&&(this._isInfinite=t,this.canCreateOrDeleteHandlePoint=!t,(e=this.notifyReload)==null||e.call(this))}updateValueScope(){this.initValueScope()}isPointInPath(t,e){return!1}isPointInStroke(t,e){return this.path&&this.mainCanvas?(this.setOverlayStyles(R.ctx),this.isDraggable&&(R.ctx.lineWidth=Math.max(R.ctx.lineWidth,20)),R.ctx.isPointInStroke(this.path,t,e)):!1}isPointInAnywhere(t,e){return(s=>{if(!s)return!1;let o=!1;return[...this.handlePoints].sort((l,c)=>(l.isHover?0:1)-(c.isHover?0:1)).forEach(l=>{o?l.isHover&&l.notifyHover(!1):(o=l.isPointInAnywhere(t,e),o!=l.isHover&&l.notifyHover(o))}),o})((this.isClick||!!this.isInfinite)&&this.isShowHandlePoint)||super.isPointInAnywhere(t,e)}get isWithinRange(){if(this.isInfinite){this.isRecalculate&&this.updateDynamicPosition();const{width:t,height:e}=this.mainCanvas.rect;return Os([0,0],[t,e],this.finalDynamicPosition[0],this.finalDynamicPosition[1])}return super.isWithinRange}updateBaseData(){this.handleValuePosition("array2D",2)&&this.updateHandlePoints()}updateDynamicPosition(){const{mainCanvas:t,position:e}=this,i=t.transformPosition(e);this.internalUpdate({dynamicPosition:i}),this.updateHandlePointsPosition()}setOverlayStyles(t){var o;const e=this.mainCanvas,i=e.style[e.theme].line;let s={};return typeof this.style=="string"?s=((o=e.style[this.style])==null?void 0:o.line)||i:typeof this.style=="object"?s=ct(JSON.parse(JSON.stringify(i)),this.style):s=i,t&&this.setBaseLineStyle(t,s.stroke),s}get computedValueScopeStyles(){return this.setOverlayStyles()}drawLine(t,e){const{mainCanvas:i,isInfinite:s,isClick:o}=this;if(e=e||this.finalDynamicPosition,!i)return;this.setGlobalAlpha(t);const a=this.setOverlayStyles(t);t.beginPath(),this.path=new Path2D,e.forEach((l,c)=>{this.path[c==0?"moveTo":"lineTo"](l[0],l[1])}),t.stroke(this.path),this.isShowHandlePoint=(s||o)&&this.isHandlePointsVisible,this.isShowHandlePoint&&this.handlePoints.forEach(l=>{var c;l.style=a.point,(c=l.getDraw())==null||c[0].call(l,t)})}drawisInfiniteStraightLine(t){const{mainCanvas:e,finalDynamicPosition:i}=this;if(!e)return;this.setGlobalAlpha(t);const{rect:s}=e,[o,a]=i,l=[a[0]-o[0],a[1]-o[1]];if(l[0]===0&&l[1]===0)return console.error("重合点无法确定方向");const c=Ve(o,[-l[0],-l[1]],s.width,s.height),h=Ve(a,l,s.width,s.height);this.drawLine(t,[c,h])}getDraw(){if(this.isNeedRender){const{isRecalculate:t,isInfinite:e}=this;return t&&this.updateDynamicPosition(),e?[this.drawisInfiniteStraightLine,this]:[this.drawLine,this]}}}function Ve(r,n,t,e){const[i,s]=r,[o,a]=n;let l=1/0;if(o!==0){const c=o>0?(t-i)/o:-i/o;c>0&&(l=Math.min(l,c))}if(a!==0){const c=a>0?(e-s)/a:-s/a;c>0&&(l=Math.min(l,c))}return l===1/0?r:[i+o*l,s+a*l]}function Os(r,n,t,e){const i=Math.min(r[0],n[0]),s=Math.max(r[0],n[0]),o=Math.min(r[1],n[1]),a=Math.max(r[1],n[1]),l=[[i,o],[s,o],[s,a],[i,a]],c=e[1]-t[1],h=t[0]-e[0],u=e[0]*t[1]-t[0]*e[1];if(c===0&&h===0){const[p,v]=t;return p>=i&&p<=s&&v>=o&&v<=a}const d=1e-10;let m=!1,g=!1;for(const[p,v]of l){const w=c*p+h*v+u;if(Math.abs(w)<d||(w>d?m=!0:g=!0,m&&g))return!0}return m&&g}class zt extends qe{constructor(t){super(t);f(this,"_isRect",!1);f(this,"dynamicBorderRadius");f(this,"_borderRadius");f(this,"_borderRadiusType","position");f(this,"isClosed",!0);f(this,"minNeededHandlePoints",3);["isRect","borderRadius","borderRadiusType"].forEach(e=>{e in t&&(this[e]=t[e])}),t.isRect&&(this.canCreateOrDeleteHandlePoint=!1)}get isRect(){return this._isRect}set isRect(t){var e;this._isRect!=t&&(this._isRect=t,this.canCreateOrDeleteHandlePoint=!t,this.updateBaseData(),(e=this.notifyReload)==null||e.call(this))}get borderRadius(){return this._borderRadius}set borderRadius(t){var e;this._borderRadius!=t&&(this._borderRadius=t,this.updateDynamicRadius(),(e=this.notifyReload)==null||e.call(this))}get borderRadiusType(){return this._borderRadiusType}set borderRadiusType(t){var e;this._borderRadiusType!=t&&(this._borderRadiusType=t,this.updateDynamicRadius(),(e=this.notifyReload)==null||e.call(this))}updateValueScope(){this.initValueScope()}isPointInPath(t,e){return this.path?R.ctx.isPointInPath(this.path,t,e):!1}isPointInStroke(t,e){return this.path&&this.mainCanvas?(this.setOverlayStyles(R.ctx),this.isDraggable&&(R.ctx.lineWidth=Math.max(R.ctx.lineWidth,20)),R.ctx.isPointInStroke(this.path,t,e)):!1}isPointInAnywhere(t,e){return(s=>{if(!s)return!1;let o=!1;return[...this.handlePoints].sort((l,c)=>(l.isHover?0:1)-(c.isHover?0:1)).forEach(l=>{o?l.isHover&&l.notifyHover(!1):(o=l.isPointInAnywhere(t,e),o!=l.isHover&&l.notifyHover(o))}),o})(this.isClick&&this.isShowHandlePoint)||super.isPointInAnywhere(t,e)}updateDynamicRadius(){const{mainCanvas:t,borderRadius:e}=this;if(!t||!e){this.dynamicBorderRadius=void 0;return}if(typeof e=="number"){this.dynamicBorderRadius=this.handleSingleRadius(e);return}this.dynamicBorderRadius=e.map(i=>this.handleSingleRadius(i,!0))}handleSingleRadius(t,e){const{mainCanvas:i,borderRadiusType:s}=this;if(t<=0)return e?0:void 0;switch(s){case"position":return t*i.percentage;default:return i.getAxisPointByValue(t,0).x}}updateBaseData(){if(!this.mainCanvas)return;let{value:t,position:e,isRect:i}=this;const s=i?2:3;i&&(Array.isArray(t)&&(t.length=2),Array.isArray(e)&&(e.length=2)),this.handleValuePosition("array2D",s)&&(this.updateHandlePoints(),this.updateDynamicRadius())}setOverlayStyles(t){var c;const e=this.isHover,i=this.mainCanvas,s=i.style[i.theme].polygon;let o={};typeof this.style=="string"?o=((c=i.style[this.style])==null?void 0:c.polygon)||s:typeof this.style=="object"?o=ct(JSON.parse(JSON.stringify(s)),this.style):o=s;const{fill:a,fill_hover:l}=o;return t&&(this.setBaseLineStyle(t,o.stroke),t.fillStyle=e?l:a),o}get computedValueScopeStyles(){return this.setOverlayStyles()}drawRect(t){this.setGlobalAlpha(t);const[[e,i],[s,o]]=this.finalDynamicPosition,a=Math.abs(s-e),l=Math.abs(o-i),c=Math.min(e,s),h=Math.min(i,o),u=this.setOverlayStyles(t);t.beginPath(),this.path=new Path2D,this.dynamicBorderRadius?this.path.roundRect(c,h,a,l,this.dynamicBorderRadius):this.path.rect(c,h,a,l),t.stroke(this.path),t.fill(this.path),this.isShowHandlePoint=this.isClick&&this.isHandlePointsVisible,this.isShowHandlePoint&&this.handlePoints.forEach(d=>{var m;d.internalUpdate({style:u.point}),(m=d.getDraw())==null||m[0].call(d,t)})}drawPolygon(t){this.setGlobalAlpha(t);const e=this.finalDynamicPosition,i=this.setOverlayStyles(t);t.beginPath(),this.path=new Path2D,e.forEach((s,o)=>{this.path[o==0?"moveTo":"lineTo"](s[0],s[1])}),this.path.closePath(),t.stroke(this.path),t.fill(this.path),this.isShowHandlePoint=this.isClick&&this.isHandlePointsVisible,this.isShowHandlePoint&&this.handlePoints.forEach(s=>{var o;s.internalUpdate({style:i.point}),(o=s.getDraw())==null||o[0].call(s,t)})}getDraw(){if(this.isNeedRender){const{mainCanvas:t,position:e}=this;if(this.isRecalculate){this.updateDynamicRadius();const i=t.transformPosition(e);this.internalUpdate({dynamicPosition:i}),this.updateHandlePointsPosition()}return this.isRect?[this.drawRect,this]:[this.drawPolygon,this]}}}class pe extends R{constructor(t){super(t);f(this,"_isFill",!1);f(this,"_isClosed",!1);f(this,"_isClosedThroughCenter",!1);f(this,"_radiusValue",0);f(this,"_radiusPosition",0);f(this,"_startAngle",0);f(this,"_endAngle",0);f(this,"_counterclockwise",!1);f(this,"isShowHandlePoint",!1);f(this,"_isHandlePointsVisible",!0);f(this,"defaultClick",(t,e)=>{var o;if(!this.isHandlePointsVisible)return;const{state:i,oldState:s}=t.data;i!=s&&((o=this.notifyReload)==null||o.call(this))});f(this,"defaultDragg",(t,e)=>{if(!this.mainCanvas)return;const i=()=>{var h;const{offsetX:s,offsetY:o}=t.data,{x:a,y:l}=this.calculateOffset(s,o);this.handlePointsArr.concat(this).forEach(u=>{u.internalUpdate({value:[O.add(u.value[0],a.value),O.add(u.value[1],l.value)],position:[O.add(u.position[0],a.position),O.add(u.position[1],l.position)],dynamicPosition:[O.add(u.dynamicPosition[0],a.dynamicPosition),O.add(u.dynamicPosition[1],l.dynamicPosition)]},!0)}),(h=this.notifyReload)==null||h.call(this)};if(this.isHandlePointsVisible){const{start:s,end:o,radius:a}=this.handlePoints,l=this.handlePointsArr.find(c=>c.isHover);if(l){const c=t.data.offsetX;if(l==s)this.startAngle=(this.startAngle+-c/180*Math.PI)%(Math.PI*2);else if(l==o)this.endAngle=(this.endAngle+-c/180*Math.PI)%(Math.PI*2);else if(l==a){const h=c/2/this.mainCanvas.percentage;this.radiusPosition+h>0&&(this.radiusPosition+=h)}}else i()}else i()});f(this,"handlePoints",{start:void 0,end:void 0,radius:void 0});["isFill","isClosed","isClosedThroughCenter","radiusValue","radiusPosition","startAngle","endAngle","counterclockwise","isHandlePointsVisible"].forEach(e=>{e in t&&(this["_"+e]=t[e])}),this.addEventListener("click",this.defaultClick),this.addEventListener("dragg",this.defaultDragg)}get isFill(){return this._isFill}set isFill(t){var e;this._isFill!=t&&(this._isFill=t,(e=this.notifyReload)==null||e.call(this))}get isClosed(){return this._isClosed}set isClosed(t){var e;this._isClosed!=t&&(this._isClosed=t,(e=this.notifyReload)==null||e.call(this))}get isClosedThroughCenter(){return this._isClosedThroughCenter}set isClosedThroughCenter(t){var e;this._isClosedThroughCenter!=t&&(this._isClosedThroughCenter=t,(e=this.notifyReload)==null||e.call(this))}get radiusValue(){return this._radiusValue}set radiusValue(t){this._radiusValue!=t&&(this._radiusValue=t,this._radiusPosition=0,this.updateBaseData())}get radiusPosition(){return this._radiusPosition}set radiusPosition(t){this._radiusPosition!=t&&(this._radiusPosition=t,this._radiusValue=0,this.updateBaseData())}get startAngle(){return this._startAngle}set startAngle(t){var e;this._startAngle!=t&&(this._startAngle=t,this.updateHandlePoints(),(e=this.notifyReload)==null||e.call(this))}get endAngle(){return this._endAngle}set endAngle(t){var e;this._endAngle!=t&&(this._endAngle=t,this.updateHandlePoints(),(e=this.notifyReload)==null||e.call(this))}get counterclockwise(){return this._counterclockwise}set counterclockwise(t){var e;this._counterclockwise!=t&&(this._counterclockwise=t,(e=this.notifyReload)==null||e.call(this))}get isHandlePointsVisible(){return this._isHandlePointsVisible}set isHandlePointsVisible(t){var e;this._isHandlePointsVisible!==t&&(this._isHandlePointsVisible=t,this.isShowHandlePoint!=t&&((e=this.notifyReload)==null||e.call(this)),this.updateHandlePoints())}get offset(){return super.offset}set offset(t){super.offset=t;let{isHandlePointsVisible:e,handlePointsArr:i}=this;e&&i.forEach(s=>s.internalUpdate({offset:t}))}updateValueScope(){const{mainCanvas:t,radiusValue:e}=this;t&&(this.initValueScope(),this.setFixedExtraScope({topV:e,bottomV:e,leftV:e,rightV:e*2}))}isPointInPath(t,e){return this.isFill&&this.path?R.ctx.isPointInPath(this.path,t,e):!1}isPointInStroke(t,e){return this.path&&this.mainCanvas?(this.setOverlayStyles(R.ctx),this.isDraggable&&(R.ctx.lineWidth=Math.max(R.ctx.lineWidth,20)),R.ctx.isPointInStroke(this.path,t,e)):!1}isPointInAnywhere(t,e){return(s=>{if(!s)return!1;let o=!1;return this.handlePointsArr.forEach(a=>{o?a.isHover&&a.notifyHover(!1):(o=a.isPointInAnywhere(t,e),o!=a.isHover&&a.notifyHover(o))}),o})(this.isClick&&this.isShowHandlePoint)||super.isPointInAnywhere(t,e)}get cursorStyle(){const t=this.handlePointsArr.some(e=>e==null?void 0:e.isHover);return this.isInteractive?this.isDraggable?"_nhanh_canvas_hover_overlay_draggable"+(t?"_ew":""):"_nhanh_canvas_hover_overlay":void 0}setOverlayStyles(t){var c;const e=this.isHover,i=this.mainCanvas,s=i.style[i.theme].arc;let o={};typeof this.style=="string"?o=((c=i.style[this.style])==null?void 0:c.arc)||s:typeof this.style=="object"?o=ct(JSON.parse(JSON.stringify(s)),this.style):o=s;const{fill:a,fill_hover:l}=o;return t&&(this.setBaseLineStyle(t,o.stroke),t.fillStyle=e?l:a),o}get computedValueScopeStyles(){return this.setOverlayStyles()}get handlePointsArr(){const t=this.handlePoints.radius;return Object.values(this.handlePoints).filter(Boolean).sort((e,i)=>(e.isHover||e==t?0:1)-(i.isHover||i==t?0:1))}updateHandlePoints(){let{mainCanvas:t,value:e,radiusValue:i,startAngle:s,endAngle:o,dynamicPosition:a,isHandlePointsVisible:l,offset:c}=this;if(!t||!a||!l)return;const[h,u]=Ns(...e,i,s,o,t.axisConfig.x,t.axisConfig.y),d=w=>new lt({name:w,offset:c,value:[0,0],isDraggable:!0,mainCanvas:this.mainCanvas,notifyReload:()=>{var _;return(_=this.notifyReload)==null?void 0:_.call(this)}}),m=this.handlePoints.start||d("start"),g=this.handlePoints.end||d("end"),p=this.handlePoints.radius||d("radius");m.value=h,g.value=u;const v=e[0]+i*2*t.axisConfig.x;p.value=[v,e[1]],this.handlePoints={start:m,end:g,radius:p}}updateBaseData(){this.mainCanvas&&(this.radiusValue?this._radiusPosition=this.mainCanvas.getAxisPointByValue(this.radiusValue,0,!0).x:this._radiusValue=this.mainCanvas.getAxisValueByPoint(this.radiusPosition,0,!0).xV,this.handleValuePosition("array1D")&&this.updateHandlePoints())}drawGuideLine(t,e,i,s){this.setBaseLineStyle(t,{...s.stroke,dash:!s.stroke.dash});const{radiusPosition:o,startAngle:a,endAngle:l,counterclockwise:c,mainCanvas:h}=this;t.beginPath(),t.arc(e,i,o*h.percentage,l,a,c),t.stroke(),t.beginPath(),t.moveTo(e,i);const u=this.handlePoints.radius.finalDynamicPosition;t.lineTo(u[0],u[1]),t.stroke(),!(this.isClosed&&this.isClosedThroughCenter)&&(t.fillStyle=t.strokeStyle,t.beginPath(),t.arc(e,i,s.point.radius,0,Math.PI*2),t.fill())}draw(t){const{finalDynamicPosition:e,mainCanvas:i,startAngle:s,endAngle:o,counterclockwise:a,isFill:l,isClosed:c,isClosedThroughCenter:h,radiusPosition:u}=this;if(!i||u<=0)return;this.setGlobalAlpha(t);const d=this.setOverlayStyles(t),[m,g]=e;t.beginPath(),this.path=new Path2D,this.path.arc(m,g,u*i.percentage,s,o,a),c&&(this.path.lineTo(m,g),h&&this.path.closePath()),t.stroke(this.path),l&&t.fill(this.path),this.isShowHandlePoint=this.isClick&&this.isHandlePointsVisible,this.isShowHandlePoint&&(this.drawGuideLine(t,m,g,d),this.handlePointsArr.forEach(p=>{var v;p.internalUpdate({style:d.point}),(v=p.getDraw())==null||v[0].call(p,t)}))}getDraw(){if(this.isNeedRender){if(this.isRecalculate){const{position:t,mainCanvas:e}=this,i=this.dynamicPosition,s=e.transformPosition(t);if(this.internalUpdate({dynamicPosition:s}),this.isHandlePointsVisible)if(e!=null&&e.isScaleUpdated)this.updateHandlePoints();else{const o=s[0]-i[0],a=s[1]-i[1];this.handlePointsArr.forEach(l=>{const c=l.dynamicPosition[0]+o,h=l.dynamicPosition[1]+a;l.internalUpdate({dynamicPosition:[c,h]})})}}return[this.draw,this]}}}function Ns(r,n,t,e,i,s=1,o=1){const a=r+t*Math.cos(e)*s,l=n+t*Math.sin(e)*o,c=r+t*Math.cos(i)*s,h=n+t*Math.sin(i)*o;return[[a,l],[c,h]]}class ge extends R{constructor(t){super(t);f(this,"handlePoints");f(this,"isShowHandlePoint",!1);f(this,"_isHandlePointsVisible",!0);f(this,"_radiusValue",0);f(this,"_radiusPosition",0);f(this,"defaultClick",(t,e)=>{var o;if(!this.isHandlePointsVisible)return;const{state:i,oldState:s}=t.data;i!=s&&((o=this.notifyReload)==null||o.call(this))});f(this,"defaultDragg",(t,e)=>{this.mainCanvas});["isHandlePointsVisible"].forEach(e=>{e in t&&(this["_"+e]=t[e])}),this.addEventListener("click",this.defaultClick),this.addEventListener("dragg",this.defaultDragg)}get handlePointsArr(){if(this.handlePoints){const{radius:t,other:e}=this.handlePoints;return[t,...e].filter(Boolean).sort((i,s)=>(i.isHover||i==t?0:1)-(s.isHover||s==t?0:1))}return[]}get isHandlePointsVisible(){return this._isHandlePointsVisible}set isHandlePointsVisible(t){var e;this._isHandlePointsVisible!==t&&(this._isHandlePointsVisible=t,this.isShowHandlePoint!=t&&((e=this.notifyReload)==null||e.call(this)))}get radiusValue(){return this._radiusValue}set radiusValue(t){this._radiusValue!=t&&(this._radiusValue=t,this.updateBaseData())}get radiusPosition(){return this._radiusPosition}set radiusPosition(t){this._radiusPosition!=t&&(this._radiusPosition=t,this.updateBaseData())}updateValueScope(){this.initValueScope()}isPointInPath(t,e){return!1}isPointInStroke(t,e){return this.path&&this.mainCanvas?(this.setOverlayStyles(R.ctx),this.isDraggable&&(R.ctx.lineWidth=Math.max(R.ctx.lineWidth,20)),R.ctx.isPointInStroke(this.path,t,e)):!1}isPointInAnywhere(t,e){return(s=>{if(!s)return!1;let o=!1;return this.handlePointsArr.forEach(a=>{o?a.isHover&&a.notifyHover(!1):(o=a.isPointInAnywhere(t,e),o!=a.isHover&&a.notifyHover(o))}),o})(this.isClick&&this.isShowHandlePoint)||super.isPointInAnywhere(t,e)}get cursorStyle(){var e;const t=(e=this.handlePoints)==null?void 0:e.radius.isHover;return this.isDraggable?"_nhanh_canvas_hover_overlay_draggable"+(t?"_ns":""):"_nhanh_canvas_hover_overlay"}setOverlayStyles(t){var o;const e=this.mainCanvas,i=e.style[e.theme].arcTo;let s={};return typeof this.style=="string"?s=((o=e.style[this.style])==null?void 0:o.arcTo)||i:typeof this.style=="object"?s=ct(JSON.parse(JSON.stringify(i)),this.style):s=i,t&&this.setBaseLineStyle(t,s.stroke),s}get computedValueScopeStyles(){return this.setOverlayStyles()}updateHandlePoints(){var c,h;let{value:t,position:e,dynamicPosition:i,isHandlePointsVisible:s}=this;if(!i||!s)return;const o=()=>new lt({value:[0,0],mainCanvas:this.mainCanvas,isDraggable:!0,notifyReload:()=>{var u;return(u=this.notifyReload)==null?void 0:u.call(this)}}),a=((c=this.handlePoints)==null?void 0:c.other)||[];t==null||t.forEach((u,d)=>{a[d]||a.push(o()),a[d].internalUpdate({value:t[d],position:e[d],dynamicPosition:i[d]},!0)}),a.length=t.length;const l=((h=this.handlePoints)==null?void 0:h.radius)||o();this.handlePoints={radius:l,other:a}}updateBaseData(){if(!this.mainCanvas)return;let{value:t,position:e}=this;const[i,s]=[Mt(t)&&t.length>1,Mt(e)&&e.length>1];if(!i&&!s)return this.handlePoints=void 0,this.internalUpdate({dynamicPosition:void 0});if(i){e=[];for(let a=0;a<t.length;a++){const l=t[a],c=this.mainCanvas.getAxisPointByValue(l[0],l[1],!0);e.push([c.x,c.y])}}else{t=[];for(let a=0;a<e.length;a++){const l=e[a],c=this.mainCanvas.getAxisValueByPoint(l[0],l[1],!0);t.push([c.xV,c.yV])}}const o=this.mainCanvas.transformPosition(e);this.internalUpdate({value:t,position:e,dynamicPosition:o}),this.updateHandlePoints()}draw(t){const{dynamicPosition:e,mainCanvas:i,radiusValue:s}=this}getDraw(){if(this.isNeedRender){if(this.isRecalculate){const{position:t,mainCanvas:e}=this,i=this.dynamicPosition,s=e.transformPosition(t);if(this.internalUpdate({dynamicPosition:s}),this.isHandlePointsVisible)if(e!=null&&e.isScaleUpdated)this.updateHandlePoints();else{const o=s[0][0]-i[0][0],a=s[0][1]-i[0][1];this.handlePointsArr.forEach(l=>{const c=l.dynamicPosition[0]+o,h=l.dynamicPosition[1]+a;l.internalUpdate({dynamicPosition:[c,h]})})}}return[this.draw,this]}}}class As extends ks{constructor(t){super(t);f(this,"resizeObserver");f(this,"currentDrawOverlays",[]);f(this,"rely","");f(this,"maxMinValue",{minXV:0,maxXV:0,minYV:0,maxYV:0});f(this,"measureRedrawPerformance",He(()=>{this.isRendering=!0,this.redraw(),this.redrawInNextRenderFrame=!1,this.isRendering=!1},{level:[[1,"#F56C6C"],[.5,"#E6A23C"],[0,"#67C23A"]]}));this.canvas&&(this.resizeObserver=new ResizeObserver(we(()=>{[this.canvas.width,this.canvas.height]=[this.rect.width,this.rect.height],this.redrawOnce()},200)),this.resizeObserver.observe(this.canvas)),this.updateRely(),this.isRecalculate=!1}updateRely(){const{center:t,scale:e,rect:i,axisConfig:s}=this,o=[t.x,t.y,e,JSON.stringify(s),i.width,i.height].join();this.isRecalculate=this.rely!==o,this.rely=o}redraw(){var s,o;if(!this.canvas)return console.warn("canvas is not HTMLCanvasElement");if(this.canvas.clientWidth==0||this.canvas.clientHeight==0)return console.warn("The image argument is a canvas element with a width or height of 0.");if(!this.shouldRender())return this.clearScreen(!1);this.ctx.globalAlpha=this.opacity??1,this.updateCenter(),this.updateRely(),this.maxMinValue=this.getMaxMinValue(),this.clearScreen();const t=[];let e=[];const i=(s=this.drawAxis)==null?void 0:s.drawAxisAndGrid();i&&e.push([0,i,[]]),this.layerGroups.forEach(a=>e.push(...a.fetchCanvas())),e.sort((a,l)=>a[0]-l[0]),e.forEach(([,a,l],c)=>{this.ctx.drawImage(a,0,0),l.forEach(([[h,u],d])=>{t.push([[h+c,u],d])})}),t.sort(([[a,l],c],[[h,u],d])=>{if(a!==h)return h-a;if(l!==u)return u-l;const m=g=>g instanceof Gt?5:g instanceof Xt?4:g instanceof lt?3:g instanceof Yt||g instanceof pe||g instanceof ge?2:g instanceof zt?1:0;return m(d)-m(c)}),this.currentDrawOverlays=t.map(([,a])=>a),this.isRecalculate=!1,this.isThemeUpdated=!1,this.isScaleUpdated=!1,(o=this.notifyReload)==null||o.call(this)}redrawOnce(){this.redrawInNextRenderFrame||(this.redrawInNextRenderFrame=!0,Promise.resolve().then(()=>{this.isRendering=!0,this.redraw(),this.redrawInNextRenderFrame=!1,this.isRendering=!1}))}findOverlayByPoint(t){const{offsetX:e,offsetY:i,clientX:s,clientY:o}=t,{x:a,y:l}=this.axisConfig,c=this.getMousePositionOnAxis({clientX:s-10*a,clientY:o-10*l}),h=this.getMousePositionOnAxis({clientX:s+10*a,clientY:o+10*l}),u=this.getAxisValueByPoint(c.x,c.y),d=this.getAxisValueByPoint(h.x,h.y);return[...this.currentDrawOverlays].sort((m,g)=>(m.isDraggable&&m.isClick?0:1)-(g.isDraggable&&g.isClick?0:1)).find(m=>{const g=m.valueScope;return g&&(g.maxX<u.xV||g.minX>d.xV||g.maxY<u.yV||g.minY>d.yV)?!1:m.isPointInAnywhere(e,i)})}destroy(){var t;(t=this.resizeObserver)==null||t.disconnect()}}class Is extends As{constructor(t){super(t);f(this,"mouseInCanvas",!1);f(this,"mouseIsDown",!1);f(this,"mouseLastPosition",{x:0,y:0});f(this,"unBind");f(this,"lastClickedOverlay");f(this,"lockNotifyClick",!1);f(this,"lastContextmenuOverlay");f(this,"defaultContextmenu",(t,e)=>{const i=this.lastClickedOverlay;i!=null&&i.isDraggable&&i.notifyClick(!1,e)});f(this,"lastPressedKey",{key:"",keyupTime:0,doubleClick:!1});f(this,"defaultWheel",(t,e)=>{this.setScale(e,t.data),this.redrawOnce()});f(this,"lastDownOverlay");f(this,"defaultDown",(t,e)=>{(e==null?void 0:e.button)==0&&(this.mouseIsDown=!0)});f(this,"lastHoverOverlay");f(this,"lastCursorStyle");f(this,"oldClientX",[]);f(this,"oldClientY",[]);this.initEvent(),this.addEventListener("contextmenu",this.defaultContextmenu),this.addEventListener("down",this.defaultDown),this.addEventListener("wheel",this.defaultWheel)}initEvent(){const{canvas:t}=this;if(!t)return console.error("canvas is not HTMLCanvasElement");const e=[{type:"click",handler:this.click.bind(this)},{type:"contextmenu",handler:this.contextmenu.bind(this)},{type:"mouseenter",handler:this.mouseenter.bind(this)},{type:"mouseleave",handler:this.mouseleave.bind(this)},{type:"keydown",handler:this.keydown.bind(this),target:window},{type:"keyup",handler:this.keyup.bind(this),target:window},{type:"wheel",handler:this.wheel.bind(this)},{type:"mousedown",handler:this.mousedown.bind(this)},{type:"mouseup",handler:this.mouseup.bind(this),target:window},{type:"mousemove",handler:this.mousemove.bind(this),target:window},{type:"touchend",handler:this.touchend.bind(this)},{type:"touchmove",handler:this.touchmove.bind(this)}];e.forEach(({type:i,handler:s,target:o=t})=>{o.addEventListener(i,s)}),this.unBind=()=>{e.forEach(({type:i,handler:s,target:o=t})=>{o.removeEventListener(i,s)})}}click(t){var i;if(!this.isClickable)return;if(this.lockNotifyClick)return this.lockNotifyClick=!1;const e=this.findOverlayByPoint(t);this.lastClickedOverlay!=e&&((i=this.lastClickedOverlay)==null||i.notifyClick(!1,t)),e==null||e.notifyClick(!0,t),this.lastClickedOverlay=e,this.notifyClick(!0,t)}contextmenu(t){var i;if(!this.isContextmenuable)return;t.preventDefault();const e=this.findOverlayByPoint(t);this.lastContextmenuOverlay!=e&&((i=this.lastContextmenuOverlay)==null||i.notifyContextmenu(!1,t)),e==null||e.notifyContextmenu(!0,t),this.lastContextmenuOverlay=e,this.notifyContextmenu(!0,t)}mouseenter(t){this.mouseInCanvas=!0}mouseleave(t){this.mouseInCanvas=!1}getStep(t){const{lastPressedKey:e}=this;return e.doubleClick?4:e.key===t&&Date.now()-e.keyupTime<300?(e.doubleClick=!0,4):1}keydown(t){const{mouseInCanvas:e,offset:i,delta:s,axisConfig:o}=this,a=t.key;if(!e||!this.isDraggable||this.isAuto)return;const l=this.getStep(a),c=this.lastClickedOverlay,u=(c==null?void 0:c.isDraggable)&&this.currentDrawOverlays.includes(c)&&(Mt(c.value)?"Matrix":ee(c.value)?"Single":!1),d=(v,w)=>{if(!u)return i.x+=v*l,i.y+=w*l,!0;const _=this.getAxisValueByPoint(l,0).xV,[C,E]=[_*o.x,_*o.y];if(u==="Single"){const N=c.value;N[0]+=v*C,N[1]+=w*E}else c.value.forEach(N=>{N[0]+=v*C,N[1]+=w*E});return c.value=[...c.value],!0},m=v=>(this.setScale("center",v*s),!0),p={ArrowUp:()=>d(0,-1),ArrowDown:()=>d(0,1),ArrowLeft:()=>d(-1,0),ArrowRight:()=>d(1,0),"+":()=>m(1),"-":()=>m(-1)}[a];p!=null&&p()&&(this.redrawOnce(),t.preventDefault())}keyup(t){const{mouseInCanvas:e,lastPressedKey:i}=this;if(e){const s=t.key;i.key=s,i.keyupTime=Date.now(),i.doubleClick=!1}}wheel(t){if(!this.isWheelable)return;t.preventDefault();const{delta:e,isAuto:i}=this;if(i)return;const s=t.deltaY<0?e:-e,o=this.findOverlayByPoint(t);o==null||o.notifyWheel(s,t),this.notifyWheel(s,t)}mousedown(t){var o;if(!this.isDownable)return;const{clientX:e,clientY:i}=t;this.mouseLastPosition={x:e,y:i};const s=this.findOverlayByPoint(t);this.lastDownOverlay!=s&&((o=this.lastDownOverlay)==null||o.notifyDown(!1,t),s==null||s.notifyDown(!0,t)),this.lastDownOverlay=s,this.notifyDown(!0,t)}mouseup(t){this.mouseIsDown=!1,this.lastDownOverlay=void 0}mousemove(t){this.isAuto||(this.canvas.classList.toggle("_nhanh_canvas_draggable",this.isDraggable),this.mouseIsDown?this.handleDragMove(t):this.handleHover(t))}handleDragMove(t){if(!this.isDraggable)return;const{clientX:e,clientY:i}=t,s={x:e,y:i};if(JSON.stringify(s)==JSON.stringify(this.mouseLastPosition))return;const{lastDownOverlay:o}=this;o!=null&&o.isDraggable?this.notifyDraggOverlays(t):this.handleCanvasPan(t),this.mouseLastPosition=s,this.lockNotifyClick=!0}notifyDraggOverlays(t){const e=this.lastDownOverlay,{mouseLastPosition:i}=this,{clientX:s,clientY:o}=t;e.notifyDragg({offsetX:s-i.x,offsetY:o-i.y},t)}handleCanvasPan(t){const{clientX:e,clientY:i}=t,{offset:s,mouseLastPosition:o}=this,a=e-o.x,l=i-o.y;s.x+=a,s.y+=l,this.redrawOnce(),this.notifyDragg({offsetX:a,offsetY:l},t)}handleHover(t){if(!this.isHoverable||t.target!=this.canvas)return;const e=this.findOverlayByPoint(t);this.updateHoverState(e,t),this.notifyHover(!0,t)}updateHoverState(t,e){if(this.lastHoverOverlay===t){const s=t==null?void 0:t.cursorStyle;s!==this.lastCursorStyle&&(this.lastCursorStyle&&this.canvas.classList.remove(this.lastCursorStyle),s&&this.canvas.classList.add(s),this.lastCursorStyle=s);return}this.lastHoverOverlay&&t&&t.hasController("hover",this.lastHoverOverlay)||(this.clearHoverState(e),this.applyHoverState(t,e)),this.lastHoverOverlay=t}clearHoverState(t){this.lastHoverOverlay&&(this.lastHoverOverlay.notifyHover(!1,t),this.lastHoverOverlay.cursorStyle&&this.canvas.classList.remove(this.lastHoverOverlay.cursorStyle))}applyHoverState(t,e){t&&(t.notifyHover(!0,e),this.lastCursorStyle=t.cursorStyle,this.lastCursorStyle&&this.canvas.classList.add(this.lastCursorStyle))}touchend(t){this.oldClientX=this.oldClientY=[]}touchmove(t){if(!this.isDraggable)return;const e=t.touches;t.preventDefault();const{oldClientX:i,oldClientY:s,offset:o,delta:a,isAuto:l,isDraggable:c}=this;if(c&&!l){if(e.length===1){const{clientX:h,clientY:u}=e[0];i.length&&(o.x+=h-i[0],o.y+=u-s[0],this.redrawOnce()),this.oldClientX=[h],this.oldClientY=[u]}else if(e.length===2){const{clientX:h,clientY:u}=e[0],{clientX:d,clientY:m}=e[1];if(i.length==2){const g=ye(i[0],s[0],i[1],s[1]),p=ye(h,u,d,m),{x:v,y:w}=be(h,u,d,m);this.setScale({clientX:v,clientY:w},p>g?a:-a),this.redrawOnce()}this.oldClientX=[h,d],this.oldClientY=[u,m]}}}destroy(){var t;super.destroy(),(t=this.unBind)==null||t.call(this)}}class et extends Nt{constructor(t){super(t);f(this,"overlays",new Set);this.setNotifyReload(t.notifyReload)}setMainCanvas(t){var e;super.setMainCanvas(t),this.overlays.forEach(i=>{i.setMainCanvas(t),i.parent=this}),t&&this.overlays.size&&((e=this.notifyReload)==null||e.call(this))}setNotifyReload(t){this.notifyReload=t?e=>{e&&(this.isRecalculate=!0),(e||this.shouldRender()&&this.overlays.size)&&t()}:void 0,this.overlays.forEach(e=>e.setNotifyReload(this.notifyReload))}addOverlays(t){var e;[t].flat().forEach(i=>{i.setNotifyReload(this.notifyReload),i.setMainCanvas(this.mainCanvas),i.parent=this,this.overlays.add(i)}),(e=this.notifyReload)==null||e.call(this)}hasOverlay(t){return this.overlays.has(t)}removeOverlays(t){var e;[t].flat().forEach(i=>{this.overlays.delete(i),i.setNotifyReload(),i.setMainCanvas(),i.parent=void 0}),(e=this.notifyReload)==null||e.call(this)}clearOverlays(){var t;(t=this.notifyReload)==null||t.call(this),this.overlays.forEach(e=>{e.setNotifyReload(),e.setMainCanvas(),e.parent=void 0}),this.overlays.clear()}getOverlaysDrawingMethod(){const t=[];return this.shouldRender()&&this.overlays.size&&Array.from(this.overlays.values()).sort((e,i)=>e.zIndex-i.zIndex).forEach(e=>{if(e.equalsMainCanvas(this.mainCanvas)){const i=e.getDraw();i&&t.push([Number(e.zIndex)||0,i])}else this.overlays.delete(e)}),t}}class it extends Nt{constructor(t){super(t);f(this,"zIndex",4);f(this,"canvas",document.createElement("canvas"));f(this,"ctx",this.canvas.getContext("2d"));f(this,"isReload",!1);f(this,"groups",new Map);f(this,"currentDrawOverlays",[]);this.setNotifyReload(t.notifyReload)}setMainCanvas(t){super.setMainCanvas(t),this.canvas.width=(t==null?void 0:t.rect.width)||0,this.canvas.height=(t==null?void 0:t.rect.height)||0,this.groups.forEach(e=>{e.setMainCanvas(t),e.parent=this})}setNotifyReload(t){this.notifyReload=t?e=>{e&&(this.isRecalculate=!0),(e||this.shouldRender()&&this.groups.size)&&t()}:void 0,this.groups.forEach(e=>this.setGroupNotifyReload(e))}setGroupNotifyReload(t){t.setNotifyReload(this.notifyReload?()=>{var e;(e=this.notifyReload)==null||e.call(this),this.isReload=!0}:void 0)}getGroup(t){return this.groups.get(t)}addGroup(t){[t].flat().forEach(e=>{e instanceof et&&(this.setGroupNotifyReload(e),e.setMainCanvas(this.mainCanvas),e.parent=this,this.groups.set(e.name,e))})}removeGroup(t){var i;let e=!1;[t].flat().forEach(s=>{s instanceof et&&(this.groups.delete(s.name),s.setNotifyReload(),s.setMainCanvas(),s.parent=void 0,e=!0)}),e&&((i=this.notifyReload)==null||i.call(this))}clearGroup(){var t;this.groups.size&&(this.groups.forEach(e=>{e.setNotifyReload(),e.setMainCanvas(),e.parent=void 0}),this.groups.clear(),(t=this.notifyReload)==null||t.call(this))}setzIndex(t){var e;t!=this.zIndex&&(this.zIndex=t,(e=this.notifyReload)==null||e.call(this,!1))}getCanvas(){if(!this.mainCanvas)return;const{rect:t,isThemeUpdated:e}=this.mainCanvas,i=this.shouldRender(),s=this.groups.size;if(i&&s){if(this.isReload||this.isRecalculate||e){this.currentDrawOverlays=[],this.isReload=!1,this.canvas.width=t.width||0,this.canvas.height=t.height||0;const o=[];this.groups.forEach(a=>{a.equalsMainCanvas(this.mainCanvas)?o.push(...a.getOverlaysDrawingMethod()):this.groups.delete(a.name)}),o.sort((a,l)=>a[0]-l[0]),o.forEach(([a,[l,c]])=>{l.call(c,this.ctx),this.currentDrawOverlays.push([[Number(this.zIndex)||0,a],c])})}return[Number(this.zIndex)||0,this.canvas,this.currentDrawOverlays]}}}class Rt extends Nt{constructor(t){super(t);f(this,"layers",new Map);f(this,"defaultContextmenu",(t,e)=>t.stopPropagation());f(this,"defaultClick",(t,e)=>t.stopPropagation());f(this,"defaultDoubleClick",(t,e)=>t.stopPropagation());f(this,"defaultHover",(t,e)=>t.stopPropagation());f(this,"defaultDragg",(t,e)=>t.stopPropagation());f(this,"defaultDown",(t,e)=>t.stopPropagation());this.inheritOpacity=!1,this.setNotifyReload(t.notifyReload),this.addEventListener("contextmenu",this.defaultContextmenu),this.addEventListener("click",this.defaultClick),this.addEventListener("doubleClick",this.defaultDoubleClick),this.addEventListener("hover",this.defaultHover),this.addEventListener("dragg",this.defaultDragg),this.addEventListener("down",this.defaultDown)}setMainCanvas(t){super.setMainCanvas(t),this.layers.forEach(e=>{e.setMainCanvas(t),e.parent=this})}setNotifyReload(t){this.notifyReload=t?e=>{e&&(this.isRecalculate=!0),(e||this.shouldRender()&&this.layers.size)&&t()}:void 0,this.layers.forEach(e=>e.setNotifyReload(this.notifyReload))}getLayer(t){return this.layers.get(t)}addLayer(t){[t].flat().forEach(e=>{e instanceof it&&(e.setNotifyReload(this.notifyReload),e.setMainCanvas(this.mainCanvas),e.parent=this,this.layers.set(e.name,e))})}removeLayer(t){var i;let e=!1;[t].flat().forEach(s=>{s instanceof it&&(this.layers.delete(s.name),s.setNotifyReload(),s.setMainCanvas(),s.parent=void 0,e=!0)}),e&&((i=this.notifyReload)==null||i.call(this))}clearLayers(){var t;this.layers.size&&(this.layers.forEach(e=>{e.setNotifyReload(),e.setMainCanvas(),e.parent=void 0}),this.layers.clear(),(t=this.notifyReload)==null||t.call(this))}fetchCanvas(){if(this.shouldRender()&&this.layers.size){const t=[];return this.layers.forEach(e=>{if(e.equalsMainCanvas(this.mainCanvas)){const i=e.getCanvas();i&&t.push(i)}else this.layers.delete(e.name)}),t}return[]}}class Hs extends Is{getDefaultOverlayGroup(){var a,l,c,h,u;const n=this.layerGroups.get("默认图层群组");if(!n)return;const t=(a=n.getLayer("点位图层"))==null?void 0:a.getGroup("点位覆盖物群组"),e=(l=n.getLayer("线段图层"))==null?void 0:l.getGroup("线段覆盖物群组"),i=(c=n.getLayer("多边形图层"))==null?void 0:c.getGroup("多边形覆盖物群组"),s=(h=n.getLayer("文字图层"))==null?void 0:h.getGroup("文字覆盖物群组"),o=(u=n.getLayer("自定义绘制图层"))==null?void 0:u.getGroup("自定义绘制覆盖物群组");return{overlays_text:s,overlays_point:t,overlays_line:e,overlays_polygon:i,overlays_custom:o}}getAllOverlays(n){const t=[],e=n!==void 0?Array.isArray(n)?[...n]:[n]:Array.from(this.layerGroups.values());for(;e.length>0;){const i=e.pop();if(i instanceof Rt){if(!i.isVisible)continue;e.push(...i.layers.values())}else if(i instanceof it){if(!i.isVisible)continue;e.push(...i.groups.values())}else if(i instanceof et){if(!i.isVisible)continue;e.push(...i.overlays.values())}else i.isVisible&&t.push(i)}return t}}class Ls extends Hs{zoom(n){const{canvas:t,rect:e}=this;if(!t||!e)return console.error("canvas is not HTMLCanvasElement");this.setScale("center",n),this.redrawOnce()}zoomIn(){this.zoom(this.delta)}zoomOut(){this.zoom(-this.delta)}setStyle(n){super.setStyle(n),this.redrawOnce()}setTheme(n){super.setTheme(n),this.redrawOnce()}setAxis(n){super.setAxis(n),this.redrawOnce()}setDefaultCenter(n){super.setDefaultCenter(n),this.redrawOnce()}}class Ts extends Ls{setFitView(n=void 0,t=!1,e=[60,60,60,60],i){const s=this.getAllOverlays(n);if(s.length===0)return;const{minX:o,maxX:a,minY:l,maxY:c}=this.calculateBoundingBox(s),h=a-o,u=c-l,d=this.calculateOptimalScale(h,u,e,i),m=this.calculateOffsetDifference(o,a,l,c,e);d==this.scale&&m.x==0&&m.y==0||(t?this.applyTransformImmediately(d,m):this.animateTransform(d,m))}calculateBoundingBox(n){let t=1/0,e=-1/0,i=1/0,s=-1/0;for(const o of n){const a=o.valueScope;t=Math.min(t,a.minX),e=Math.max(e,a.maxX),i=Math.min(i,a.minY),s=Math.max(s,a.maxY)}return{minX:t,maxX:e,minY:i,maxY:s}}calculateOptimalScale(n,t,e,i){const{cycle:s,delta:o,axisConfig:a,rect:l}=this,{width:c,height:h}=l,u=Math.max(0,c-e[1]-e[3])||c,d=Math.max(0,h-e[0]-e[2])||h;if(u<=0||d<=0)return console.warn("无效的可视区域尺寸,边距设置可能不合理"),this.scale;const m=n/u,g=t/d,p=Math.max(m,g),v=a.count,w=v/a.min,_=s*o;let C;if(p>w){const E=Math.ceil(p/w);C=1-((v*E/p-a.min)/a.min+(E-2))*_}else{const E=(dt,rt,vt)=>dt<rt?vt-1:E(dt/2,rt,vt+1),N=E(w,p,0),G=Math.pow(2,N);C=1+((v/G/p-a.min)/a.min+N)*_}return i!==void 0&&(C=Math.min(i,C)),C=new V(C).div(o).round().mul(o).toNumber(),C}calculateOffsetDifference(n,t,e,i,s){const{width:o,height:a}=this.rect,{axisConfig:l,center:c}=this,h=(t+n)/2,u=(i+e)/2,d=this.getAxisPointByValue(h,u),m=this.getAxisValueByPoint((o/2-c.x)*l.x,(a/2-c.y)*l.y),g=this.getAxisPointByValue(m.xV,m.yV);return{x:Math.round(-(d.x+(s[3]-s[1])-g.x)*l.x),y:Math.round(-(d.y+(s[0]-s[2])-g.y)*l.y)}}applyTransformImmediately(n,t){this.offset={x:this.offset.x+t.x,y:this.offset.y+t.y},this.scale=n,this.updateSize(),this.redrawOnce()}animateTransform(n,t){const e=this.scale,i={...this.offset},s=300;this.isAuto=!0;const o=()=>this.isAuto=!1;(c=>this.animateOffset(i,t,s,c||o))(c=>this.animateScale(e,n,s,c||o))}animateScale(n,t,e,i){const s=t-n;let o=0;kt(a=>{!this.isAuto||!this.canvas||!this.isInteractive||(this.setScale("center",(a-o)*s),o=a,this.redrawOnce(),a===1&&i())},e)}animateOffset(n,t,e,i){kt(s=>{!this.isAuto||!this.canvas||!this.isInteractive||(this.offset={x:Number((n.x+t.x*s).toFixed(0)),y:Number((n.y+t.y*s).toFixed(0))},this.redrawOnce(),s===1&&i())},e)}returnToOrigin(){if(!this.isInteractive||this.scale==this.defaultScale&&this.offset.x==0&&this.offset.y==0)return;const{rect:n,axisConfig:t}=this,e=this.getDefaultCenterLocation(),i=(n.width/2-e.x)*t.x,s=(n.height/2-e.y)*t.y,o=this.getAxisValueByPoint(i,s,!0),a=this.getMousePositionOnAxis({clientX:n.x+n.width/2,clientY:n.y+n.height/2}),l=this.getAxisValueByPoint(a.x,a.y),c=t.size/this.getNowGridCount,h=Math.round((l.xV-o.xV)*t.x*c),u=Math.round((l.yV-o.yV)*t.y*c);h==0&&u==0||this.animateTransform(this.defaultScale,{x:h,y:u})}}class Fs extends Ts{toggleAxis(n){this.drawAxis.toggleAxis(n),this.redrawOnce()}togglePoint(n){const{overlays_point:t}=this.getDefaultOverlayGroup()||{};return t?(t.isVisible=n??!t.isVisible,this.redrawOnce(),t.isVisible):!1}toggleLine(n){const{overlays_line:t}=this.getDefaultOverlayGroup()||{};return t?(t.isVisible=n??!t.isVisible,this.redrawOnce(),t.isVisible):!1}togglePolygon(n){const{overlays_polygon:t}=this.getDefaultOverlayGroup()||{};return t?(t.isVisible=n??!t.isVisible,this.redrawOnce(),t.isVisible):!1}toggleLock(n){return this.isInteractive=n??!this.isInteractive,this.isInteractive}}class Bs extends Fs{static clearPathRegion(n,t){const{width:e,height:i}=n.canvas;n.save(),n.beginPath(),n.clip(t),n.clearRect(0,0,e,i),n.restore()}}class Us extends Bs{}class Gs{constructor(n){f(this,"canvas");f(this,"axis_canvas",document.createElement("canvas"));f(this,"ctx",this.axis_canvas.getContext("2d"));f(this,"isReload",!0);f(this,"show",{all:!0,grid:{main:!0,secondary:!0},axis:!0,axisText:!0});this.canvas=n,this.initAxisCanvas()}initAxisCanvas(){const{canvas:n,axis_canvas:t}=this;n&&(t.width=n.rect.width||0,t.height=n.rect.height||0)}toggleAxis(n){const t=(()=>{if(typeof n=="object"){const{all:e=!0,axis:i=!0,axisText:s=!0}=n,o=Object.assign({main:!0,secondary:!0},n.grid);return{all:e,grid:o,axis:i,axisText:s}}return typeof n=="boolean"?{all:!0,grid:{main:n,secondary:n},axis:n,axisText:n}:!this.show.all})();typeof t=="boolean"?this.show.all=t:this.show=t,this.isReload=!0}drawAxisAndGrid(){if(!(!this.canvas||!this.show.all))return(this.canvas.isRecalculate||this.isReload||this.canvas.isThemeUpdated)&&(this.isReload=!1,this.initAxisCanvas(),(this.show.grid.main||this.show.grid.secondary)&&this.drawGrid(),this.show.axis&&this.drawAxis(),this.show.axisText&&this.drawAxisText()),this.axis_canvas}color(){const{theme:n,style:t}=this.canvas;return(t[n]||t.light).grid}drawGrid(){const{canvas:n,ctx:t}=this,{rect:e,center:i,axisConfig:s}=n,{width:o,height:a}=e,l=this.color(),c=s.size,h=c/5;t.lineWidth=1;const u=(m,g)=>{const p=i.x%m>0?i.x%m:m+i.x%m;t.strokeStyle=g,t.beginPath();for(let v=0;v*m+p<=o;v++)t.moveTo(v*m+p,0),t.lineTo(v*m+p,a);t.stroke()},d=(m,g)=>{const p=i.y%m>0?i.y%m:m+i.y%m;t.strokeStyle=g,t.beginPath();for(let v=0;v*m+p<=a;v++)t.moveTo(0,v*m+p),t.lineTo(o,v*m+p);t.stroke()};this.show.grid.secondary&&(u(h,l.innerGrid),d(h,l.innerGrid)),this.show.grid.main&&(u(c,l.grid),d(c,l.grid))}drawAxis(){const{canvas:n,ctx:t}=this,{rect:e,center:i}=n,{width:s,height:o}=e,a=this.color();t.lineWidth=2,t.strokeStyle=a.axis;const l=()=>{i.y>=0&&i.y<=o&&(t.beginPath(),t.moveTo(0,i.y),t.lineTo(s,i.y),t.stroke())},c=()=>{i.x>=0&&i.x<=s&&(t.beginPath(),t.moveTo(i.x,0),t.lineTo(i.x,o),t.stroke())};l(),c()}drawText(n,t,e,i){const{canvas:s,ctx:o}=this,{theme:a}=s,l=this.canvas.style[a].text;o.font=`${l.bold?"bold":""} ${l.size}px ${l.family}`,o.strokeStyle=l.stroke,![n,t,e].includes(void 0)&&o.strokeText(n,t,e),o.fillStyle=l[i?"secondary":"color"],![n,t,e].includes(void 0)&&o.fillText(n,t,e)}drawAxisText(){const{canvas:n,ctx:t}=this,{rect:e,center:i,axisConfig:s,style:o,theme:a}=n,{width:l,height:c}=e;this.drawText();const h=p=>Math.ceil(t.measureText(p).width),u=4,d=o[a].text.size;{const p=h("0"),v=i.x<u||i.x>l+p+u,w=i.y<-(u+d)||i.y>c+d+u;!v&&!w&&this.drawText("0",i.x-p-u,i.y+d+u)}const m=n.getNowGridCount,g=s.size;{let p=i.y+d+u;p=Math.max(Math.min(p,c-u),u+d);const v=i.y>c||i.y<0;let w=i.x>0?i.x%g:i.x<0?g+i.x%g:0,_=n.getAxisValueByPoint((w-i.x)*s.x,0).xV;for(;w<=l;){const C=Wt(_),E=h(C);_!==0&&this.drawText(C,w-E/2,p,v),w+=g,_=new V(m).mul(s.x).add(_).toNumber()}}{const p=i.x>l||i.x<0;let v=i.y>0?i.y%g:i.y<0?g+i.y%g:0,w=n.getAxisValueByPoint(0,(v-i.y)*s.y).yV;for(;v<=c;){const _=Wt(w),C=h(_);let E=i.x-C-u;E=Math.max(Math.min(E,l-C-u),u),w!=0&&this.drawText(_,E,v+d/2,p),v+=g,w=new V(m).mul(s.y).add(w).toNumber()}}}}function Tt(r){return[r].flat(1/0)}class Y extends Us{constructor(n){super(n),this.drawAxis=new Gs(this),"axisShow"in n&&this.toggleAxis(n.axisShow),this.initLayerGroups(),this.updateCenter()}initLayerGroups(){const n=new it({name:"多边形图层"});n.addGroup(new et({name:"多边形覆盖物群组"})),n.setzIndex(1);const t=new it({name:"线段图层"});t.addGroup(new et({name:"线段覆盖物群组"})),t.setzIndex(2);const e=new it({name:"点位图层"});e.addGroup(new et({name:"点位覆盖物群组"})),e.setzIndex(3);const i=new it({name:"文字图层"});i.addGroup(new et({name:"文字覆盖物群组"})),i.setzIndex(4);const s=new it({name:"自定义绘制图层"});s.addGroup(new et({name:"自定义绘制覆盖物群组"})),s.setzIndex(5);const o=new Rt({name:"默认图层群组"});o.addLayer([i,e,t,n,s]),this.setLayerGroup(o)}gteLayerGroups(n="默认图层群组"){return this.layerGroups.get(n)}setLayerGroup(n){n instanceof Rt&&(this.layerGroups.set(n.name,n),n.setNotifyReload(()=>this.redrawOnce()),n.setMainCanvas(this),n.parent=this)}removeLayerGroup(n){n instanceof Rt&&(this.layerGroups.delete(n.name),n.setNotifyReload(),n.setMainCanvas(),n.parent=void 0,this.redrawOnce())}addLayer(n){const t=this.layerGroups.get("默认图层群组");t&&t.addLayer(Tt(n))}removeLayer(n){const t=this.layerGroups.get("默认图层群组");t&&t.removeLayer(Tt(n))}addOverlay(n){const{overlays_text:t,overlays_point:e,overlays_line:i,overlays_polygon:s,overlays_custom:o}=this.getDefaultOverlayGroup()||{};Tt(n).forEach(a=>{a instanceof Xt?t==null||t.addOverlays(a):a instanceof lt?e==null||e.addOverlays(a):a instanceof Yt||a instanceof pe||a instanceof ge?i==null||i.addOverlays(a):a instanceof zt?s==null||s.addOverlays(a):a instanceof Gt&&(o==null||o.addOverlays(a))})}removeOverlay(n){const{overlays_text:t,overlays_point:e,overlays_line:i,overlays_polygon:s,overlays_custom:o}=this.getDefaultOverlayGroup()||{};Tt(n).forEach(a=>{a instanceof Xt?t==null||t.removeOverlays(a):a instanceof lt?e==null||e.removeOverlays(a):a instanceof Yt?i==null||i.removeOverlays(a):a instanceof zt?s==null||s.removeOverlays(a):a instanceof Gt&&(o==null||o.addOverlays(a))})}destroy(){super.destroy()}}f(Y,"LayerGroup",Rt),f(Y,"Layer",it),f(Y,"OverlayGroup",et),f(Y,"Text",Xt),f(Y,"Point",lt),f(Y,"Line",Yt),f(Y,"Polygon",zt),f(Y,"Custom",Gt),f(Y,"Arc",pe),f(Y,"ArcTo",ge);function Xs(r){const n=we(r,100);let t=0,e=0;return function(i){const s=i.target;if(!s||!(s instanceof Element))return;const{scrollTop:o,scrollHeight:a,clientHeight:l,scrollLeft:c,scrollWidth:h,clientWidth:u}=s;function d(){if(t==o)return;const g=t>o;if(t=o,g)return;a-o-l<=1&&n("vertical")}function m(){if(e==c)return;const g=e>c;if(e=c,g)return;h-c-u<=1&&n("horizontal")}d(),m()}}function Ys(r,n,t){const{isClickAllowed:e,uiLibrary:i=["naiveUI","ElementPlus","Element"]}=t||{},s=function(l){const c=[];for(const h in l)Object.hasOwnProperty.call(l,h)&&i.includes(h)&&c.push(...l[h]);return c}({naiveUI:[".v-binder-follower-container",".n-image-preview-container",".n-modal-container"],ElementPlus:[".el-popper"],Element:[".el-popper"]});function o(){n(),document.removeEventListener("mousedown",a)}function a(l){if(e){const u=e(l);if(u)return;if(u===!1)return o()}const c=l.target;if(!(c instanceof Element)||!c.isConnected)return;r.concat(s).some(u=>!!(c!=null&&c.closest(u)))||o()}requestAnimationFrame(()=>document.addEventListener("mousedown",a))}var z,ft,mt,Pt,xt,Z,Q,st,bt;class zs{constructor(){A(this,z);A(this,ft,!1);A(this,mt,{});A(this,Pt,0);A(this,xt,0);A(this,Z,0);A(this,Q,0);A(this,st);A(this,bt)}init(n,t){D(this,z,n),D(this,st,t==null?void 0:t.limit),D(this,bt,t==null?void 0:t.dragDom),D(this,mt,{mousedown:this.mousedown.bind(this),mousemove:this.mousemove.bind(this),mouseup:this.mouseup.bind(this)}),this.bindOrUnbindEvent("bind")}finish(){this.bindOrUnbindEvent("unbind")}bindOrUnbindEvent(n){const t=n==="bind"?"addEventListener":"removeEventListener";if(!P(this,z))return console.error("No DOM");P(this,z)[t]("mousedown",P(this,mt).mousedown),document[t]("mousemove",P(this,mt).mousemove),document[t]("mouseup",P(this,mt).mouseup)}alterLocation(){if(!P(this,z))return console.error("No DOM");P(this,st)&&(D(this,Z,Math.min(P(this,Z),P(this,st).max.top)),D(this,Z,Math.max(P(this,Z),P(this,st).min.top)),D(this,Q,Math.min(P(this,Q),P(this,st).max.left)),D(this,Q,Math.max(P(this,Q),P(this,st).min.left))),P(this,z).style.setProperty("--top",P(this,Z)+"px"),P(this,z).style.setProperty("--left",P(this,Q)+"px")}mousedown(n){if(!P(this,z))return console.error("No DOM");if(P(this,bt)&&n.target!=P(this,bt))return;document.body.classList.add("no-select"),D(this,ft,!0);const t=P(this,z).getBoundingClientRect(),{pageX:e,pageY:i}=n;D(this,Pt,e),D(this,xt,i),D(this,Z,t.y),D(this,Q,t.x)}mousemove(n){const{pageX:t,pageY:e}=n;P(this,ft)&&(D(this,Z,P(this,Z)+(e-P(this,xt))),D(this,Q,P(this,Q)+(t-P(this,Pt))),D(this,Pt,t),D(this,xt,e),this.alterLocation())}mouseup(){P(this,ft)&&(D(this,ft,!1),document.body.classList.remove("no-select"))}}z=new WeakMap,ft=new WeakMap,mt=new WeakMap,Pt=new WeakMap,xt=new WeakMap,Z=new WeakMap,Q=new WeakMap,st=new WeakMap,bt=new WeakMap;var W,pt,gt,_t,Ct,j,q,B,St,Et;class Ws{constructor(){A(this,W);A(this,pt,!1);A(this,gt,{});A(this,_t,0);A(this,Ct,0);A(this,j,0);A(this,q,0);A(this,B);A(this,St);A(this,Et)}init(n,t={}){D(this,W,n),D(this,B,t.limit),D(this,St,t.update_move),D(this,Et,t.update_up),D(this,gt,{mousedown:this.mousedown.bind(this),mousemove:this.mousemove.bind(this),mouseup:this.mouseup.bind(this)}),this.bindOrUnbindEvent("bind")}finish(){this.bindOrUnbindEvent("unbind")}bindOrUnbindEvent(n){const t=n==="bind"?"addEventListener":"removeEventListener";if(!P(this,W))return console.error("No DOM");P(this,W)[t]("mousedown",P(this,gt).mousedown),document[t]("mousemove",P(this,gt).mousemove),document[t]("mouseup",P(this,gt).mouseup)}updateValue(){const n={top:P(this,j),left:P(this,q),percentage:{top:0,left:0}};if(P(this,B)){const t=e=>P(this,B)?(n[e]-P(this,B).min[e])/(P(this,B).max[e]-P(this,B).min[e]):0;n.percentage={top:t("top")||0,left:t("left")||0}}return n}alterLocation(){if(!P(this,W))return console.error("No DOM");P(this,B)&&(D(this,j,Math.min(P(this,j),P(this,B).max.top)),D(this,j,Math.max(P(this,j),P(this,B).min.top)),D(this,q,Math.min(P(this,q),P(this,B).max.left)),D(this,q,Math.max(P(this,q),P(this,B).min.left))),P(this,St)&&P(this,St).call(this,this.updateValue()),P(this,W).style.setProperty("--top",P(this,j)+"px"),P(this,W).style.setProperty("--left",P(this,q)+"px")}mousedown(n){if(!P(this,W))return console.error("No DOM");document.body.classList.add("no-select"),D(this,pt,!0);const t=P(this,W).getBoundingClientRect();D(this,Ct,t.y),D(this,_t,t.x);const{pageX:e,pageY:i}=n;D(this,j,i-P(this,Ct)),D(this,q,e-P(this,_t)),this.alterLocation()}mousemove(n){const{pageX:t,pageY:e}=n;P(this,pt)&&(D(this,j,e-P(this,Ct)),D(this,q,t-P(this,_t)),this.alterLocation())}mouseup(){P(this,pt)&&(D(this,pt,!1),document.body.classList.remove("no-select"),P(this,Et)&&P(this,Et).call(this,this.updateValue()))}}W=new WeakMap,pt=new WeakMap,gt=new WeakMap,_t=new WeakMap,Ct=new WeakMap,j=new WeakMap,q=new WeakMap,B=new WeakMap,St=new WeakMap,Et=new WeakMap;function re(r){if(typeof r=="string"){const n=document.querySelector(r);if(n)return n;console.error(`Element "${r}" not found`)}else return r||document.documentElement}function $e(r){const n=re(r);return n?n.requestFullscreen?n.requestFullscreen():n.mozRequestFullScreen?n.mozRequestFullScreen():n.webkitRequestFullscreen?n.webkitRequestFullscreen():n.msRequestFullscreen?n.msRequestFullscreen():Promise.reject("No Fullscreen API"):Promise.reject("No Element")}function Ze(){const r=document;return document.exitFullscreen?document.exitFullscreen():r.mozCancelFullScreen?r.mozCancelFullScreen():r.webkitExitFullscreen?r.webkitExitFullscreen():r.msExitFullscreen?r.msExitFullscreen():Promise.reject("No ExitFullscreen API")}function xe(r){const n=re(r),t=document,e=document.fullscreenElement||t.webkitFullscreenElement||t.mozFullScreenElement||t.msFullscreenElement;return n==e||!r&&window.innerWidth==screen.width&&window.innerHeight==screen.height}function js(r){if(r=re(r),!!r)return function(){xe(r)?Ze():$e(r)}}function qs(r,n){const t=re(n);if(!t)return;const e=()=>{r(xe(t))};return document.addEventListener("fullscreenchange",e),document.addEventListener("webkitfullscreenchange",e),document.addEventListener("mozfullscreenchange",e),document.addEventListener("MSFullscreenChange",e),e(),()=>{document.removeEventListener("fullscreenchange",e),document.removeEventListener("webkitfullscreenchange",e),document.removeEventListener("mozfullscreenchange",e),document.removeEventListener("MSFullscreenChange",e)}}function $s(r,n){if(typeof r=="number")return r;if(/px/.test(r))return Number(r.replace(/px/,""))||0;const t=document.createElement("div");t.style.width=r,n=n||document.body,n.appendChild(t);const e=t.getBoundingClientRect().width;return n.removeChild(t),e}function Zs(r,n){if(!r)return;let t,e;if(typeof n=="string"){const s=document.querySelector(n);if(!s)return;const o=s.getBoundingClientRect();t=o.width,e=o.height}else if(Array.isArray(n))t=n[0],e=n[1];else{const s=n.getBoundingClientRect();t=s.width,e=s.height}const i=t/e;return i>r?[r*e,e]:i<r?[t,t/r]:[t,e]}function Qs(r,n=5e3){return new Promise((t,e)=>{const i=new Image;i.src=r;const s=setTimeout(()=>{e(new Error("图片加载超时")),i.onload=null,i.onerror=null},n);i.onload=()=>{clearTimeout(s);const o=i.naturalWidth,a=i.naturalHeight,l=o/a;t([i,l])},i.onerror=()=>{clearTimeout(s),e(new Error("图片加载失败"))},i.crossOrigin="Anonymous"})}function Js(r){const t=document.getElementById(r).querySelectorAll("img"),e=t.length,i=[];let s=0;return e===0?Promise.resolve({allLoaded:!0,loaded:0,failed:0,total:0,errors:[]}):new Promise(o=>{const a=()=>{s===e&&o({allLoaded:i.length===0,loaded:e-i.length,failed:i.length,total:e,errors:i})};t.forEach(l=>{if(l.complete){l.naturalWidth===0&&i.push(l),s++,a();return}l.addEventListener("load",()=>{s++,a()},{once:!0}),l.addEventListener("error",()=>{i.push(l),s++,a()},{once:!0})})})}function Ks(r){return new Promise((n,t)=>{fetch(r).then(e=>n(e.text())).catch(e=>{console.error("Error fetching :",e),t(e)})})}function Qe(r){const{href:n,fileName:t,onProgress:e,timeout:i=3e4,autoDownload:s=!0}=r;let o,a=!1,l=null,c;const h=t||jt(n,"downloaded_file");c=decodeURIComponent(h);const u=()=>{if(!l)return;const p=URL.createObjectURL(l),v=document.createElement("a");v.href=p,v.download=c,v.click(),URL.revokeObjectURL(p)};return{promise:new Promise((p,v)=>{try{o=new XMLHttpRequest,o.open("GET",n),o.responseType="blob",o.timeout=i,o.ontimeout=()=>{a||v(new Error(`请求超时(已超过${i/1e3}秒)`))},o.addEventListener("progress",w=>{if(w.lengthComputable&&!a){const _=w.loaded/w.total*100;e==null||e(Number(_.toFixed(2)))}}),o.addEventListener("load",()=>{a||(o.status>=200&&o.status<300?(l=o.response,s&&u(),p(o.response)):v(new Error(`下载失败,状态码: ${o.status}`)))}),o.addEventListener("error",()=>{a||v(new Error("网络错误,下载失败"))}),o.addEventListener("abort",()=>{a||(a=!0,v(new Error("下载已被中止")))}),o.send()}catch(w){a||v(w)}}),abort:()=>!a&&o.abort(),download:()=>{!a&&l&&u()}}}function tn(r,n,t){if(!t){let s=n.replace(/^[^.]+./,"");s=s==n?"text/plain":"application/"+s,t={type:s}}const e=new Blob(r,t),i=URL.createObjectURL(e);Qe({href:i,fileName:n})}const en=Math.PI/2,Kt=Math.PI/180,te=6378137,sn=85.05112878;function nn(r,n){const t=Math.max(Math.min(r,180),-180),e=Math.max(Math.min(n,sn),-85.05112878),i=t*Kt*te,s=e*Kt,o=Math.log(Math.tan(Math.PI/4+s/2))*te;return[i,o]}function rn(r,n){const t=r/te/Kt,e=(2*Math.atan(Math.exp(n/te))-en)/Kt;return[t,e]}function Je(r,n,t){const[e,i]=r,[s,o]=n,[a,l]=t,c=(a-s)**2+(l-o)**2;if(c===0)return Math.sqrt((e-s)**2+(i-o)**2);let h=((e-s)*(a-s)+(i-o)*(l-o))/c;return h=Math.max(0,Math.min(1,h)),Math.sqrt((e-(s+h*(a-s)))**2+(i-(o+h*(l-o)))**2)}function on(r,n,t,e,i,s=1,o=1){const a=r+t*Math.cos(e)*s,l=n+t*Math.sin(e)*o,c=r+t*Math.cos(i)*s,h=n+t*Math.sin(i)*o;return[[a,l],[c,h]]}function ye(r,n,t,e){return Math.hypot(Math.abs(t-r),Math.abs(e-n))}function be(r,n,t,e){const i=(r+t)/2,s=(n+e)/2;return{x:i,y:s}}function an(r,n,t,e){const[i,s]=r,[o,a]=n;let l=1/0;if(o!==0){const c=o>0?(t-i)/o:-i/o;c>0&&(l=Math.min(l,c))}if(a!==0){const c=a>0?(e-s)/a:-s/a;c>0&&(l=Math.min(l,c))}return l===1/0?r:[i+o*l,s+a*l]}const ln=new Set(["sin","cos","tan","asin","acos","atan","atan2"]),cn=new Proxy(Math,{get(r,n){return ln.has(n)?function(...t){const e=t.map(i=>i/180*Math.PI);return r[n](...e)}:r[n]},set(){throw new Error("DegreeMath 是只读的,不能修改属性")},deleteProperty(){throw new Error("DegreeMath 是只读的,不能删除属性")}});class wt{constructor(n,t){f(this,"resolve");f(this,"reject");this.resolve=n,this.reject=t}run(n){var t,e;return n instanceof Promise?n.then(i=>{var s;return(s=this.resolve)==null||s.call(this),i}).catch(i=>{var s;return(s=this.reject)==null||s.call(this),Promise.reject(i)}):n?(t=this.resolve)==null||t.call(this):(e=this.reject)==null||e.call(this),n}}class hn extends wt{constructor(n){super(),this.resolve=n}warning(...n){const t=()=>{var e,i;return(i=(e=yt.tips).warning)==null?void 0:i.call(e,...n)};return new wt(this.resolve,t)}error(...n){const t=()=>{var e,i;return(i=(e=yt.tips).error)==null?void 0:i.call(e,...n)};return new wt(this.resolve,t)}}class un extends wt{constructor(n){super(),this.reject=n}info(...n){const t=()=>{var e,i;return(i=(e=yt.tips).info)==null?void 0:i.call(e,...n)};return new wt(t,this.reject)}success(...n){const t=()=>{var e,i;return(i=(e=yt.tips).success)==null?void 0:i.call(e,...n)};return new wt(t,this.reject)}}const F=class F{constructor(){if(new.target===F)throw new Error("请直接使用静态方法,而不是实例化此类")}static register(n,t){if(typeof t!="function")return console.error("TipHandler must be a function");F.tips[n]=t}static resolveTip(n){return function(...t){const e=()=>{var i,s;return(s=(i=F.tips)[n])==null?void 0:s.call(i,...t)};return new hn(e)}}static rejectTip(n){return function(...t){const e=()=>{var i,s;return(s=(i=F.tips)[n])==null?void 0:s.call(i,...t)};return new un(e)}}};f(F,"tips",{info:void 0,success:void 0,warning:void 0,error:void 0}),f(F,"info",F.resolveTip("info")),f(F,"success",F.resolveTip("success")),f(F,"warning",F.rejectTip("warning")),f(F,"error",F.rejectTip("error"));let yt=F;exports.EXTENSION_TO_MIME=Re;exports.FILE_EXTENSIONS=Ft;exports.PAPER_SIZE_DEFINITIONS=ve;exports.PAPER_SIZE_OPTIONS=ii;exports.UNIT_LABELS=le;exports.WINDOW_TARGET=ei;exports._Animate_CreateOscillator=si;exports._Animate_NumericTransition=ni;exports._Animate_Schedule=kt;exports._Blob_ConvertDataToImageUrl=ri;exports._Browser_CalculatePrintableArea=ki;exports._Browser_CopyToClipboard=Ri;exports._Browser_GetFrameRate=Vi;exports._Browser_SameOriginTabManager=Vt;exports._Canvas=Y;exports._Element_CalculateCanvasSize=Zs;exports._Element_CheckImagesLoaded=Js;exports._Element_CloseOnOutsideClick=Ys;exports._Element_Drag=zs;exports._Element_EnterFullscreen=$e;exports._Element_ExitFullscreen=Ze;exports._Element_Fullscreen=js;exports._Element_FullscreenObserver=qs;exports._Element_GetOtherSizeInPixels=$s;exports._Element_IsFullscreen=xe;exports._Element_LoadImage=Qs;exports._Element_LocalDrag=Ws;exports._Element_ScrollEndListener=Xs;exports._File_CreateAndDownload=tn;exports._File_Download=Qe;exports._File_Read=Ks;exports._Format_CamelCase=ui;exports._Format_CapitalizeFirstLetter=oi;exports._Format_ChunkArray=pi;exports._Format_ExcludeSubstring=di;exports._Format_FileSize=ci;exports._Format_HrefName=jt;exports._Format_MillisecondToReadable=mi;exports._Format_NumberWithCommas=Wt;exports._Format_NumberWithUnit=li;exports._Format_Percentage=ai;exports._Format_Timestamp=hi;exports._Format_ToggleInvisibleChars=fi;exports._Math_CalculateDistance2D=ye;exports._Math_Degree=cn;exports._Math_GetArcPoints=on;exports._Math_GetBoundaryIntersection=an;exports._Math_GetMidpoint=be;exports._Math_LngLatToPlane=nn;exports._Math_PlaneToLngLat=rn;exports._Math_PointToLineDistance=Je;exports._Tip=yt;exports._Utility_Clone=Ie;exports._Utility_Debounce=we;exports._Utility_ExecuteWhenIdle=bi;exports._Utility_GenerateUUID=$t;exports._Utility_GetTargetByPath=Ci;exports._Utility_MergeObjects=ct;exports._Utility_RotateList=Ei;exports._Utility_SetTargetByPath=Si;exports._Utility_Sleep=Di;exports._Utility_Throttle=_i;exports._Utility_TimeConsumption=He;exports._Utility_WaitForCondition=Ae;exports._Valid_CheckConnectionWithXHR=Pi;exports._Valid_DataType=qt;exports._Valid_DoesInfiniteLineIntersectRectangle=vi;exports._Valid_FileTypeChecker=ce;exports._Valid_Is2DNumberArray=Mt;exports._Valid_IsInMargin=gi;exports._Valid_IsNumberArray=ee;exports._Valid_IsPointInPolygon=yi;exports._Valid_IsSecureContext=wi;
|
package/dist/index.es.js
CHANGED
|
@@ -3344,9 +3344,9 @@ class Ft extends R {
|
|
|
3344
3344
|
}
|
|
3345
3345
|
updateBaseData() {
|
|
3346
3346
|
if (!this.mainCanvas) return;
|
|
3347
|
-
this.internalUpdate({ dynamicPosition:
|
|
3347
|
+
this.internalUpdate({ dynamicPosition: [] });
|
|
3348
3348
|
let t = this.value, e = this.position;
|
|
3349
|
-
t ? e = this.convertValuesToPositions(t) : t = this.convertPositionsToValues(e), this.updateDataProperties(t, e);
|
|
3349
|
+
t ? e = this.convertValuesToPositions(t) : e && (t = this.convertPositionsToValues(e)), t && e && this.updateDataProperties(t, e);
|
|
3350
3350
|
}
|
|
3351
3351
|
convertValuesToPositions(t) {
|
|
3352
3352
|
const e = [];
|
|
@@ -3413,7 +3413,7 @@ class Ft extends R {
|
|
|
3413
3413
|
getDraw() {
|
|
3414
3414
|
if (this.isNeedRender) {
|
|
3415
3415
|
const { mainCanvas: t, position: e } = this;
|
|
3416
|
-
return this.isRecalculate && this.internalUpdate({
|
|
3416
|
+
return this.isRecalculate && e && this.internalUpdate({
|
|
3417
3417
|
dynamicPosition: t.transformPosition(e)
|
|
3418
3418
|
}), [this.draw, this];
|
|
3419
3419
|
}
|