ziko 1.9.0 → 2.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ziko.cjs +304 -2868
- package/dist/ziko.js +1322 -5315
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +1242 -5057
- package/package.json +70 -97
- package/src/__ziko__/__config__.js +3 -3
- package/src/__ziko__/__state__.js +0 -1
- package/src/{dom/components → components}/Fragment/index.js +1 -1
- package/src/{dom/components/wrappers → components}/HTMLWrapper/index.js +3 -7
- package/src/{dom/components/wrappers → components}/SVGWrapper/index.js +3 -15
- package/src/{dom/components → components}/Suspense/index.js +1 -1
- package/src/{dom/components → components}/Swap/index.js +2 -2
- package/src/{dom/components → components}/Switch/index.js +1 -2
- package/src/components/View/index.js +11 -0
- package/src/{dom/components → components}/index.js +2 -3
- package/src/dom/{constructors/UIElement.js → UIElement/index.js} +6 -6
- package/src/dom/index.js +2 -6
- package/src/dom/{utils → internal-utils}/call_with_optional_props.js +1 -1
- package/src/dom/{utils/is_ui_item.js → internal-utils/checkers.js} +1 -0
- package/src/dom/internal-utils/is_ui_item.js +10 -0
- package/src/dom/tags/index.js +3 -3
- package/src/events/custom-events-registry/view.js +1 -1
- package/src/hooks/index.d.ts +0 -8
- package/src/hooks/index.js +1 -12
- package/src/hooks/use-derived.js +18 -14
- package/src/hooks/use-effect.js +7 -15
- package/src/hooks/use-reactive.d.ts +1 -1
- package/src/hooks/use-reactive.js +1 -1
- package/src/hooks/use-state.js +1 -7
- package/src/index.js +2 -6
- package/src/{helpers → internal-utils}/checkers/index.js +1 -1
- package/src/math/index.d.ts +4 -4
- package/src/math/index.js +7 -10
- package/src/math/{functions/mapfun → mapfun}/index.js +1 -1
- package/src/math/{functions/utils → utils}/index.d.ts +1 -1
- package/src/math/utils/index.js +42 -103
- package/src/{dom/constructors/UIElementCore.d.ts → mini-dom/UIElement/index.d.ts} +1 -1
- package/src/{dom/constructors/UIElementCore.js → mini-dom/UIElement/index.js} +5 -14
- package/src/{dom/constructors/UINode.js → mini-dom/UINode/index.js} +1 -3
- package/src/{dom/constructors → mini-dom}/mixins/attrs.js +6 -6
- package/src/{dom/constructors → mini-dom}/mixins/dom.js +2 -16
- package/src/mini-dom/mixins/lifecycle.js +32 -0
- package/src/{dom/constructors → mini-dom}/mixins/style.js +1 -1
- package/src/mini-dom/parse_props.js +26 -0
- package/src/{dom → mini-dom}/text/index.js +4 -4
- package/src/router/file-based-router/index.js +63 -14
- package/src/router/index.d.ts +1 -1
- package/src/router/index.js +1 -1
- package/src/router/{utils → internal-utils}/dynamic-routes-parser.js +45 -11
- package/src/router/internal-utils/get-root.js +24 -0
- package/src/router/internal-utils/index.d.ts +5 -0
- package/src/router/internal-utils/normalize-path.js +32 -0
- package/src/router/internal-utils/routes-grouper.js +49 -0
- package/src/router/{utils → internal-utils}/routes-matcher.js +32 -9
- package/src/{hooks/use-query-params.js → router/useQueryParams/index.js} +0 -1
- package/src/time/{clocks/clock.js → clock/index.js} +1 -1
- package/src/time/{clocks/clock.d.ts → clock/index.ts} +1 -1
- package/src/time/debounce/index.d.ts +4 -0
- package/src/time/debounce/index.js +4 -0
- package/src/time/index.d.ts +7 -5
- package/src/time/index.js +7 -8
- package/src/time/sleep/index.d.ts +1 -0
- package/src/time/sleep/index.js +1 -0
- package/src/time/throttle/index.d.ts +4 -0
- package/src/time/throttle/index.js +9 -0
- package/src/time/{clocks/tick.js → tick/index.js} +2 -7
- package/src/time/{delay → timeout}/index.d.ts +0 -2
- package/src/time/{delay → timeout}/index.js +0 -1
- package/src/app/globals.js +0 -76
- package/src/app/index.js +0 -18
- package/src/app/params.js +0 -37
- package/src/app/routes.js +0 -57
- package/src/app/spa-file-based-routing.js +0 -74
- package/src/app/spa.js +0 -55
- package/src/app/ziko-app.js +0 -39
- package/src/data/api/fetchdom.js +0 -30
- package/src/data/api/index.js +0 -4
- package/src/data/api/preload.js +0 -11
- package/src/data/converter/__(To Be Moved)adoc.js +0 -130
- package/src/data/converter/__(To Be Moved)markdown.js +0 -95
- package/src/data/converter/array.js +0 -43
- package/src/data/converter/canvas.js +0 -25
- package/src/data/converter/css.js +0 -37
- package/src/data/converter/csv.js +0 -35
- package/src/data/converter/idea.txt +0 -10
- package/src/data/converter/index.js +0 -33
- package/src/data/converter/json.js +0 -80
- package/src/data/converter/object.js +0 -74
- package/src/data/converter/svg.js +0 -11
- package/src/data/datatypes/color.js +0 -11
- package/src/data/decorators.js +0 -0
- package/src/data/index.js +0 -17
- package/src/data/parser/index.d.ts +0 -41
- package/src/data/parser/index.js +0 -28
- package/src/data/string-dep/index.js +0 -1
- package/src/data/string-dep/patterns.js +0 -12
- package/src/data/string-dep/string.js +0 -170
- package/src/dom/components/Flex/index.js +0 -89
- package/src/dom/components/Flex/utils/index.js +0 -20
- package/src/dom/components/View/index.js +0 -9
- package/src/dom/components/graphics/Canvas/index.js +0 -175
- package/src/dom/components/graphics/Svg/index.js +0 -69
- package/src/dom/components/graphics/index.js +0 -2
- package/src/dom/components/wrappers/index.js +0 -2
- package/src/dom/constructors/mixins/lifecycle.js +0 -54
- package/src/dom/grid/index.js +0 -33
- package/src/dom/mini/UIElement.js +0 -10
- package/src/dom/utils/checkers.js +0 -1
- package/src/dom/utils/getters.js +0 -0
- package/src/hooks/use-favicon.d.ts +0 -41
- package/src/hooks/use-favicon.js +0 -59
- package/src/hooks/use-ipc.d.ts +0 -12
- package/src/hooks/use-ipc.js +0 -83
- package/src/hooks/use-media-query.d.ts +0 -24
- package/src/hooks/use-media-query.js +0 -59
- package/src/hooks/use-root.d.ts +0 -15
- package/src/hooks/use-root.js +0 -73
- package/src/hooks/use-storage.d.ts +0 -47
- package/src/hooks/use-storage.js +0 -118
- package/src/hooks/use-thread.d.ts +0 -33
- package/src/hooks/use-thread.js +0 -55
- package/src/hooks/use-title.d.ts +0 -37
- package/src/hooks/use-title.js +0 -43
- package/src/lite.js +0 -2
- package/src/math/--discret/Set/index.js +0 -2
- package/src/math/--discret/Set/power-set.js +0 -15
- package/src/math/--discret/Set/sub-set.js +0 -10
- package/src/math/--discret/index.js +0 -12
- package/src/math/complex/helpers/constructor.js +0 -38
- package/src/math/complex/helpers/index.js +0 -1
- package/src/math/complex/index.d.ts +0 -231
- package/src/math/complex/index.js +0 -193
- package/src/math/functions/conversions/index.d.ts +0 -101
- package/src/math/functions/conversions/index.js +0 -61
- package/src/math/functions/helper.js +0 -81
- package/src/math/functions/index.d.ts +0 -147
- package/src/math/functions/index.js +0 -43
- package/src/math/functions/logic/index.d.ts +0 -53
- package/src/math/functions/logic/index.js +0 -54
- package/src/math/functions/proxy.js +0 -58
- package/src/math/functions/signal/index.d.ts +0 -146
- package/src/math/functions/signal/index.js +0 -104
- package/src/math/functions/stats/index.js +0 -61
- package/src/math/functions/ufunc/index.d.ts +0 -96
- package/src/math/functions/ufunc/index.js +0 -372
- package/src/math/functions/utils/index.js +0 -47
- package/src/math/matrix/AbstractMatrix.js +0 -0
- package/src/math/matrix/helpers/constructor.js +0 -31
- package/src/math/matrix/helpers/det.js +0 -36
- package/src/math/matrix/helpers/index.js +0 -5
- package/src/math/matrix/helpers/inverse.js +0 -52
- package/src/math/matrix/helpers/maintain.js +0 -13
- package/src/math/matrix/helpers/stack.js +0 -24
- package/src/math/matrix/index.js +0 -557
- package/src/math/random/index.d.ts +0 -162
- package/src/math/random/index.js +0 -125
- package/src/math/signal/functions.js +0 -84
- package/src/math/signal/index.js +0 -1
- package/src/math/stats/accum/index.d.ts +0 -43
- package/src/math/stats/accum/index.js +0 -39
- package/src/math/stats/average/index.d.ts +0 -123
- package/src/math/stats/average/index.js +0 -75
- package/src/math/stats/index.d.ts +0 -5
- package/src/math/stats/index.js +0 -14
- package/src/math/stats/percentile/index.d.ts +0 -66
- package/src/math/stats/percentile/index.js +0 -18
- package/src/math/stats/rolling/index.d.ts +0 -47
- package/src/math/stats/rolling/index.js +0 -34
- package/src/math/stats/variability/index.d.ts +0 -93
- package/src/math/stats/variability/index.js +0 -37
- package/src/math/utils/arithmetic.js +0 -137
- package/src/math/utils/checkers.js +0 -29
- package/src/math/utils/comparaison.js +0 -1
- package/src/math/utils/conversions.js +0 -19
- package/src/math/utils/discret.js +0 -51
- package/src/math/utils/mapfun.js +0 -42
- package/src/no-module.js +0 -32
- package/src/provider/index.js +0 -7
- package/src/router/utils/get-root.js +0 -16
- package/src/router/utils/index.d.ts +0 -5
- package/src/router/utils/normalize-path.js +0 -21
- package/src/router/utils/routes-grouper.js +0 -22
- package/src/time/animation/index.d.ts +0 -189
- package/src/time/animation/index.js +0 -94
- package/src/time/clocks/index.d.ts +0 -3
- package/src/time/clocks/index.js +0 -3
- package/src/time/converters/index.js +0 -1
- package/src/time/decorators/index.d.ts +0 -9
- package/src/time/decorators/index.js +0 -17
- package/src/time/ease/index.d.ts +0 -103
- package/src/time/ease/index.js +0 -118
- package/src/time/loop/index.d.ts +0 -50
- package/src/time/loop/index.js +0 -103
- package/src/time/utils/index.js +0 -17
- package/src/time/utils/performance.js +0 -16
- package/src/time/utils/ui.js +0 -26
- /package/src/{dom/components → components}/For/index.js +0 -0
- /package/src/{dom/components → components}/Fragment/index.d.ts +0 -0
- /package/src/{dom/components → components}/Swap/index.d.ts +0 -0
- /package/src/{dom/components → components}/index.d.ts +0 -0
- /package/src/dom/{utils → internal-utils}/index.js +0 -0
- /package/src/dom/{utils → internal-utils}/parse_props.js +0 -0
- /package/src/{helpers → internal-utils}/index.js +0 -0
- /package/src/{helpers → internal-utils}/register/index.js +0 -0
- /package/src/{helpers → internal-utils}/register/register-to-class.js +0 -0
- /package/src/{helpers → internal-utils}/register/register-to-instance.js +0 -0
- /package/src/{symbols → internal-utils/symbols}/index.d.ts +0 -0
- /package/src/{symbols → internal-utils/symbols}/index.js +0 -0
- /package/src/math/{functions/arithmetic → arithmetic}/index.d.ts +0 -0
- /package/src/math/{functions/arithmetic → arithmetic}/index.js +0 -0
- /package/src/math/{const.js → const/index.js} +0 -0
- /package/src/math/{functions/mapfun → mapfun}/index.d.ts +0 -0
- /package/src/math/{functions/mapfun → mapfun}/index.d.ts.txt +0 -0
- /package/src/math/{functions/utils → utils}/mapfun.d.ts.txt +0 -0
- /package/src/{dom/constructors/UINode.d.ts → mini-dom/UINode/index.d.ts} +0 -0
- /package/src/{dom/constructors → mini-dom}/mixins/index.js +0 -0
- /package/src/{dom/constructors → mini-dom}/mixins/indexing.js +0 -0
- /package/src/router/{utils → internal-utils}/dynamic-routes-parser.d.ts +0 -0
- /package/src/router/{utils → internal-utils}/get-root.d.ts +0 -0
- /package/src/router/{utils → internal-utils}/index.js +0 -0
- /package/src/router/{utils → internal-utils}/normalize-path.d.ts +0 -0
- /package/src/router/{utils → internal-utils}/renderer.js +0 -0
- /package/src/router/{utils → internal-utils}/routes-grouper.d.ts +0 -0
- /package/src/router/{utils → internal-utils}/routes-matcher.d.ts +0 -0
- /package/src/{hooks/use-query-params.d.ts → router/useQueryParams/index.d.ts} +0 -0
- /package/src/{data/string → string}/checkers/index.d.ts +0 -0
- /package/src/{data/string → string}/checkers/index.js +0 -0
- /package/src/{data/string → string}/converters/index.d.ts +0 -0
- /package/src/{data/string → string}/converters/index.js +0 -0
- /package/src/{data/string → string}/index.d.ts +0 -0
- /package/src/{data/string → string}/index.js +0 -0
- /package/src/time/{clocks/scheduler.js → schedular/index.js} +0 -0
- /package/src/time/{clocks/scheduler.d.ts → schedular/index.ts} +0 -0
- /package/src/time/{clocks/tick.d.ts → tick/index.ts} +0 -0
package/dist/ziko.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/*
|
|
3
3
|
Project: ziko.js
|
|
4
4
|
Author: Zakaria Elalaoui
|
|
5
|
-
Date : Wed
|
|
5
|
+
Date : Wed Sep 02 2026 10:53:51 GMT+0100 (UTC+01:00)
|
|
6
6
|
Git-Repo : https://github.com/zakarialaoui10/ziko.js
|
|
7
7
|
Git-Wiki : https://github.com/zakarialaoui10/ziko.js/wiki
|
|
8
8
|
Released under MIT License
|
|
@@ -10,23 +10,23 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
const { PI
|
|
13
|
+
const { PI, E } = Math;
|
|
14
14
|
const EPSILON=Number.EPSILON;
|
|
15
15
|
|
|
16
16
|
const is_primitive$1 = value => typeof value !== 'object' && typeof value !== 'function' || value === null;
|
|
17
17
|
|
|
18
|
-
const mapfun
|
|
18
|
+
const mapfun=(fun,...X)=>{
|
|
19
19
|
const Y=X.map(x=>{
|
|
20
20
|
if(is_primitive$1(x) || x?.__mapfun__) return fun(x)
|
|
21
|
-
if(x instanceof Array) return x.map(n=>mapfun
|
|
21
|
+
if(x instanceof Array) return x.map(n=>mapfun(fun,n));
|
|
22
22
|
if(ArrayBuffer.isView(x)) return x.map(n=>fun(n));
|
|
23
|
-
if(x instanceof Set) return new Set(mapfun
|
|
24
|
-
if(x instanceof Map) return new Map([...x].map(n=>[n[0],mapfun
|
|
25
|
-
if(x.isMatrix?.()) return new x.constructor(x.rows, x.cols, mapfun
|
|
23
|
+
if(x instanceof Set) return new Set(mapfun(fun,...[...x]));
|
|
24
|
+
if(x instanceof Map) return new Map([...x].map(n=>[n[0],mapfun(fun,n[1])]));
|
|
25
|
+
if(x.isMatrix?.()) return new x.constructor(x.rows, x.cols, mapfun(x.arr.flat(1)))
|
|
26
26
|
else if(x instanceof Object){
|
|
27
27
|
return Object.fromEntries(
|
|
28
28
|
Object.entries(x).map(
|
|
29
|
-
n=>n=[n[0],mapfun
|
|
29
|
+
n=>n=[n[0],mapfun(fun,n[1])]
|
|
30
30
|
)
|
|
31
31
|
)
|
|
32
32
|
}
|
|
@@ -44,7 +44,7 @@ const apply_fun = (x, fn) => {
|
|
|
44
44
|
x.cols,
|
|
45
45
|
x.arr.flat(1).map(fn)
|
|
46
46
|
)
|
|
47
|
-
if (x instanceof Array) mapfun
|
|
47
|
+
if (x instanceof Array) mapfun(fn, ...x);
|
|
48
48
|
return fn(x)
|
|
49
49
|
};
|
|
50
50
|
|
|
@@ -370,21 +370,7 @@ class Random {
|
|
|
370
370
|
pool.fill(choices[i], acc[i-1], acc[i]);
|
|
371
371
|
return pool[this.int(pool.length)];
|
|
372
372
|
}
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
globalThis.Random = Random;
|
|
377
|
-
|
|
378
|
-
// // (upperCase) => upperCase ? : String.fromCharCode(rand_int(97,120))
|
|
379
|
-
// class Random {
|
|
380
|
-
// static string(length,upperCase){
|
|
381
|
-
// return length instanceof Array?
|
|
382
|
-
// new Array(this.int(...length)).fill(0).map(() => this.char(upperCase)).join(""):
|
|
383
|
-
// new Array(length).fill(0).map(() => this.char(upperCase)).join("");
|
|
384
|
-
// }
|
|
385
|
-
|
|
386
|
-
// }
|
|
387
|
-
// export{Random}
|
|
373
|
+
}
|
|
388
374
|
|
|
389
375
|
const complex_constructor = (Complex, a, b) => {
|
|
390
376
|
let _a, _b;
|
|
@@ -617,7 +603,7 @@ const complex=(a,b)=>{
|
|
|
617
603
|
|
|
618
604
|
const PRECESION = 8;
|
|
619
605
|
|
|
620
|
-
const abs = (...x) => mapfun
|
|
606
|
+
const abs = (...x) => mapfun(
|
|
621
607
|
x =>{
|
|
622
608
|
if(x.isComplex?.()) return x.z;
|
|
623
609
|
return Math.abs(x)
|
|
@@ -625,9 +611,9 @@ const abs = (...x) => mapfun$1(
|
|
|
625
611
|
...x
|
|
626
612
|
);
|
|
627
613
|
|
|
628
|
-
const pow
|
|
614
|
+
const pow = (...x) => {
|
|
629
615
|
const n = x.pop();
|
|
630
|
-
return mapfun
|
|
616
|
+
return mapfun(
|
|
631
617
|
x => {
|
|
632
618
|
if(x.isComplex?.()) {
|
|
633
619
|
if(n.isComplex?.()) return new x.constructor({
|
|
@@ -646,7 +632,7 @@ const pow$1 = (...x) => {
|
|
|
646
632
|
)
|
|
647
633
|
};
|
|
648
634
|
|
|
649
|
-
const sqrt
|
|
635
|
+
const sqrt = (...x) => mapfun(
|
|
650
636
|
x=>{
|
|
651
637
|
if(x.isComplex?.())
|
|
652
638
|
return new x.constructor({z: x.z**(1/2), phi: x.phi/2});
|
|
@@ -656,7 +642,7 @@ const sqrt$2 = (...x) => mapfun$1(
|
|
|
656
642
|
...x
|
|
657
643
|
);
|
|
658
644
|
|
|
659
|
-
const cbrt = (...x) => mapfun
|
|
645
|
+
const cbrt = (...x) => mapfun(
|
|
660
646
|
x=>{
|
|
661
647
|
if(x.isComplex?.())
|
|
662
648
|
return new x.constructor({z: x.z**(1/3), phi: x.phi/3}).toFixed(PRECESION)
|
|
@@ -668,7 +654,7 @@ const cbrt = (...x) => mapfun$1(
|
|
|
668
654
|
const nthr = (...x) => {
|
|
669
655
|
const n = x.pop();
|
|
670
656
|
if(typeof n !== 'number') throw Error('nthr expects a real number n');
|
|
671
|
-
return mapfun
|
|
657
|
+
return mapfun(
|
|
672
658
|
x => {
|
|
673
659
|
if(x.isComplex?.()) return new x.constructor({z: x.z ** (1/n), phi: x.phi / n});
|
|
674
660
|
if(x<0) return n %2 ===2
|
|
@@ -683,7 +669,7 @@ const nthr = (...x) => {
|
|
|
683
669
|
const croot = (...x) =>{
|
|
684
670
|
const c = x.pop();
|
|
685
671
|
if(!c.isComplex?.()) throw Error('croot expect Complex number as root')
|
|
686
|
-
return mapfun
|
|
672
|
+
return mapfun(
|
|
687
673
|
x => {
|
|
688
674
|
if(typeof x === 'number') x = new c.constructor(x, 0);
|
|
689
675
|
const {a : c_a, b : c_b} = c;
|
|
@@ -700,7 +686,7 @@ const croot = (...x) =>{
|
|
|
700
686
|
)
|
|
701
687
|
};
|
|
702
688
|
|
|
703
|
-
const exp
|
|
689
|
+
const exp = (...x) => mapfun(
|
|
704
690
|
x => {
|
|
705
691
|
if(x.isComplex?.()) return new x.constructor(
|
|
706
692
|
Math.exp(x.a) * Math.cos(x.b),
|
|
@@ -711,7 +697,7 @@ const exp$1 = (...x) => mapfun$1(
|
|
|
711
697
|
,...x
|
|
712
698
|
);
|
|
713
699
|
|
|
714
|
-
const ln = (...x) => mapfun
|
|
700
|
+
const ln = (...x) => mapfun(
|
|
715
701
|
x => {
|
|
716
702
|
if(x.isComplex?.()) return new x.constructor(
|
|
717
703
|
Math.log(x.z),
|
|
@@ -722,7 +708,7 @@ const ln = (...x) => mapfun$1(
|
|
|
722
708
|
,...x
|
|
723
709
|
);
|
|
724
710
|
|
|
725
|
-
const sign = (...x) => mapfun
|
|
711
|
+
const sign = (...x) => mapfun(
|
|
726
712
|
x => {
|
|
727
713
|
if(x.isComplex?.()){
|
|
728
714
|
const {z, phi} = x;
|
|
@@ -734,7 +720,7 @@ const sign = (...x) => mapfun$1(
|
|
|
734
720
|
,...x
|
|
735
721
|
);
|
|
736
722
|
|
|
737
|
-
const floor = (...x) => mapfun
|
|
723
|
+
const floor = (...x) => mapfun(
|
|
738
724
|
x => {
|
|
739
725
|
if(x.isComplex?.()) return new x.constructor(
|
|
740
726
|
Math.floor(x.a),
|
|
@@ -744,7 +730,7 @@ const floor = (...x) => mapfun$1(
|
|
|
744
730
|
},
|
|
745
731
|
...x
|
|
746
732
|
);
|
|
747
|
-
const ceil = (...x) => mapfun
|
|
733
|
+
const ceil = (...x) => mapfun(
|
|
748
734
|
x => {
|
|
749
735
|
if(x.isComplex?.()) return new x.constructor(
|
|
750
736
|
Math.ceil(x.a),
|
|
@@ -754,7 +740,7 @@ const ceil = (...x) => mapfun$1(
|
|
|
754
740
|
},
|
|
755
741
|
...x
|
|
756
742
|
);
|
|
757
|
-
const round = (...x) => mapfun
|
|
743
|
+
const round = (...x) => mapfun(
|
|
758
744
|
x => {
|
|
759
745
|
if(x.isComplex?.()) return new x.constructor(
|
|
760
746
|
Math.round(x.a),
|
|
@@ -765,7 +751,7 @@ const round = (...x) => mapfun$1(
|
|
|
765
751
|
...x
|
|
766
752
|
);
|
|
767
753
|
|
|
768
|
-
const trunc = (...x) => mapfun
|
|
754
|
+
const trunc = (...x) => mapfun(
|
|
769
755
|
x => {
|
|
770
756
|
if(x.isComplex?.()) return new x.constructor(
|
|
771
757
|
Math.trunc(x.a),
|
|
@@ -776,7 +762,7 @@ const trunc = (...x) => mapfun$1(
|
|
|
776
762
|
...x
|
|
777
763
|
);
|
|
778
764
|
|
|
779
|
-
const fract = (...x) => mapfun
|
|
765
|
+
const fract = (...x) => mapfun(
|
|
780
766
|
x => {
|
|
781
767
|
if(x.isComplex?.()) return new x.constructor(
|
|
782
768
|
x.a - Math.trunc(x.a),
|
|
@@ -787,7 +773,7 @@ const fract = (...x) => mapfun$1(
|
|
|
787
773
|
...x
|
|
788
774
|
);
|
|
789
775
|
|
|
790
|
-
const cos$
|
|
776
|
+
const cos$1 = (...x) => mapfun(
|
|
791
777
|
x => {
|
|
792
778
|
if(x.isComplex?.()) return new x.constructor(
|
|
793
779
|
Math.cos(x.a) * Math.cosh(x.b),
|
|
@@ -798,7 +784,7 @@ const cos$3 = (...x) => mapfun$1(
|
|
|
798
784
|
,...x
|
|
799
785
|
);
|
|
800
786
|
|
|
801
|
-
const sin$
|
|
787
|
+
const sin$1 = (...x) => mapfun(
|
|
802
788
|
x =>{
|
|
803
789
|
if(x?.isComplex) return new x.constructor(
|
|
804
790
|
Math.sin(x.a) * Math.cosh(x.b),
|
|
@@ -809,7 +795,7 @@ const sin$3 = (...x) => mapfun$1(
|
|
|
809
795
|
, ...x
|
|
810
796
|
);
|
|
811
797
|
|
|
812
|
-
const tan = (...x) => mapfun
|
|
798
|
+
const tan = (...x) => mapfun(
|
|
813
799
|
x =>{
|
|
814
800
|
if(x?.isComplex){
|
|
815
801
|
const D = Math.cos(2*x.a) + Math.cosh(2*x.b);
|
|
@@ -823,7 +809,7 @@ const tan = (...x) => mapfun$1(
|
|
|
823
809
|
...x
|
|
824
810
|
);
|
|
825
811
|
|
|
826
|
-
const sec = (...x) => mapfun
|
|
812
|
+
const sec = (...x) => mapfun(
|
|
827
813
|
x => {
|
|
828
814
|
if(x.isComplex?.()) ;
|
|
829
815
|
return + (1 / Math.cos(x)).toFixed(PRECESION)
|
|
@@ -831,7 +817,7 @@ const sec = (...x) => mapfun$1(
|
|
|
831
817
|
,...x
|
|
832
818
|
);
|
|
833
819
|
|
|
834
|
-
const acos
|
|
820
|
+
const acos = (...x) => mapfun(
|
|
835
821
|
x =>{
|
|
836
822
|
if(x?.isComplex){
|
|
837
823
|
const { a, b } = x;
|
|
@@ -849,7 +835,7 @@ const acos$1 = (...x) => mapfun$1(
|
|
|
849
835
|
...x
|
|
850
836
|
);
|
|
851
837
|
|
|
852
|
-
const asin = (...x) => mapfun
|
|
838
|
+
const asin = (...x) => mapfun(
|
|
853
839
|
x => {
|
|
854
840
|
if(x?.isComplex){
|
|
855
841
|
const { a, b } = x;
|
|
@@ -865,7 +851,7 @@ const asin = (...x) => mapfun$1(
|
|
|
865
851
|
...x
|
|
866
852
|
);
|
|
867
853
|
|
|
868
|
-
const atan = (...x) => mapfun
|
|
854
|
+
const atan = (...x) => mapfun(
|
|
869
855
|
x => {
|
|
870
856
|
if(x?.isComplex){
|
|
871
857
|
const { a, b } = x;
|
|
@@ -879,7 +865,7 @@ const atan = (...x) => mapfun$1(
|
|
|
879
865
|
...x
|
|
880
866
|
);
|
|
881
867
|
|
|
882
|
-
const acot = (...x) => mapfun
|
|
868
|
+
const acot = (...x) => mapfun(
|
|
883
869
|
x => {
|
|
884
870
|
if(x?.isComplex){
|
|
885
871
|
const { a, b } = x;
|
|
@@ -894,7 +880,7 @@ const acot = (...x) => mapfun$1(
|
|
|
894
880
|
);
|
|
895
881
|
|
|
896
882
|
|
|
897
|
-
const cosh$
|
|
883
|
+
const cosh$1 = (...x) => mapfun(
|
|
898
884
|
x =>{
|
|
899
885
|
if(x?.isComplex) return new x.constructor(
|
|
900
886
|
Math.cosh(x.a) * Math.cos(x.b),
|
|
@@ -904,7 +890,7 @@ const cosh$2 = (...x) => mapfun$1(
|
|
|
904
890
|
},
|
|
905
891
|
...x
|
|
906
892
|
);
|
|
907
|
-
const sinh
|
|
893
|
+
const sinh = (...x) => mapfun(
|
|
908
894
|
x =>{
|
|
909
895
|
if(x?.isComplex) return new x.constructor(
|
|
910
896
|
Math.sinh(x.a) * Math.cos(x.b),
|
|
@@ -914,7 +900,7 @@ const sinh$1 = (...x) => mapfun$1(
|
|
|
914
900
|
},
|
|
915
901
|
...x
|
|
916
902
|
);
|
|
917
|
-
const tanh = (...x) => mapfun
|
|
903
|
+
const tanh = (...x) => mapfun(
|
|
918
904
|
x =>{
|
|
919
905
|
if(x?.isComplex){
|
|
920
906
|
const D = Math.cosh(2*a) + Math.cos(2*b);
|
|
@@ -928,7 +914,7 @@ const tanh = (...x) => mapfun$1(
|
|
|
928
914
|
...x
|
|
929
915
|
);
|
|
930
916
|
|
|
931
|
-
const coth = (...x) => mapfun
|
|
917
|
+
const coth = (...x) => mapfun(
|
|
932
918
|
x =>{
|
|
933
919
|
if(x?.isComplex){
|
|
934
920
|
const {a, b} = x;
|
|
@@ -943,27 +929,27 @@ const coth = (...x) => mapfun$1(
|
|
|
943
929
|
...x
|
|
944
930
|
);
|
|
945
931
|
|
|
946
|
-
const acosh = (...x) => mapfun
|
|
932
|
+
const acosh = (...x) => mapfun(
|
|
947
933
|
x =>{
|
|
948
934
|
if(x?.isComplex){
|
|
949
|
-
return ln(x.clone().add(sqrt
|
|
935
|
+
return ln(x.clone().add(sqrt(x.clone().mul(x.clone()).sub(1))))
|
|
950
936
|
}
|
|
951
937
|
return + Math.acosh(x).toFixed(PRECESION)
|
|
952
938
|
},
|
|
953
939
|
...x
|
|
954
940
|
);
|
|
955
941
|
|
|
956
|
-
const asinh = (...x) => mapfun
|
|
942
|
+
const asinh = (...x) => mapfun(
|
|
957
943
|
x =>{
|
|
958
944
|
if(x?.isComplex){
|
|
959
|
-
return ln(x.clone().add(sqrt
|
|
945
|
+
return ln(x.clone().add(sqrt(x.clone().mul(x.clone()).add(1))))
|
|
960
946
|
}
|
|
961
947
|
return + Math.asinh(x).toFixed(PRECESION)
|
|
962
948
|
},
|
|
963
949
|
...x
|
|
964
950
|
);
|
|
965
951
|
|
|
966
|
-
const atanh = (...x) => mapfun
|
|
952
|
+
const atanh = (...x) => mapfun(
|
|
967
953
|
x =>{
|
|
968
954
|
if(x?.isComplex);
|
|
969
955
|
return + Math.atanh(x).toFixed(PRECESION)
|
|
@@ -971,7 +957,7 @@ const atanh = (...x) => mapfun$1(
|
|
|
971
957
|
...x
|
|
972
958
|
);
|
|
973
959
|
|
|
974
|
-
const sig = (...x) => mapfun
|
|
960
|
+
const sig = (...x) => mapfun(
|
|
975
961
|
x =>{
|
|
976
962
|
if(x?.isComplex);
|
|
977
963
|
return 1/(1 + Math.exp(-x)).toFixed(PRECESION)
|
|
@@ -1036,8 +1022,8 @@ const modulo=(a,...b)=>{
|
|
|
1036
1022
|
return res;
|
|
1037
1023
|
};
|
|
1038
1024
|
|
|
1039
|
-
const deg2rad = (...deg) => mapfun
|
|
1040
|
-
const rad2deg = (...rad) => mapfun
|
|
1025
|
+
const deg2rad = (...deg) => mapfun(x => x * Math.PI / 180, ...deg);
|
|
1026
|
+
const rad2deg = (...rad) => mapfun(x => x / Math.PI * 180, ...rad);
|
|
1041
1027
|
|
|
1042
1028
|
const norm = (x, min, max) => apply_fun(
|
|
1043
1029
|
x,
|
|
@@ -1068,10 +1054,10 @@ const hypot = (...x) => {
|
|
|
1068
1054
|
|
|
1069
1055
|
const atan2 = (y, x, rad = true) => {
|
|
1070
1056
|
if (y instanceof Array && !(x instanceof Array))
|
|
1071
|
-
return mapfun
|
|
1057
|
+
return mapfun(n => atan2(n, x, rad), ...y);
|
|
1072
1058
|
|
|
1073
1059
|
if (x instanceof Array && !(y instanceof Array))
|
|
1074
|
-
return mapfun
|
|
1060
|
+
return mapfun(n => atan2(y, n, rad), ...x);
|
|
1075
1061
|
|
|
1076
1062
|
if (y instanceof Array && x instanceof Array)
|
|
1077
1063
|
return y.map((v, i) => atan2(v, x[i], rad));
|
|
@@ -1080,804 +1066,6 @@ const atan2 = (y, x, rad = true) => {
|
|
|
1080
1066
|
return rad ? phi : phi * 180 / Math.PI;
|
|
1081
1067
|
};
|
|
1082
1068
|
|
|
1083
|
-
const min = (...x) => Math.min(...x);
|
|
1084
|
-
const max = (...x) => Math.max(...x);
|
|
1085
|
-
|
|
1086
|
-
const binomial = (n, k) =>{
|
|
1087
|
-
if(n !== Math.floor(n)) return TypeError('n must be an integer');
|
|
1088
|
-
if(k !== Math.floor(k)) return TypeError('k must be an integer');
|
|
1089
|
-
if (n < 0) return TypeError('n must be non-negative');
|
|
1090
|
-
if (k < 0 || n < 0 || k > n) return 0;
|
|
1091
|
-
if (k > n - k) k = n - k;
|
|
1092
|
-
let c = 1, i;
|
|
1093
|
-
for (i = 0; i < k; i++)
|
|
1094
|
-
c = c * (n - i) / (i + 1);
|
|
1095
|
-
return c;
|
|
1096
|
-
};
|
|
1097
|
-
|
|
1098
|
-
// export const mean = (...x) => x.reduce((a, b) => a + b) / x.length;
|
|
1099
|
-
|
|
1100
|
-
// export const variance = (...x) => {
|
|
1101
|
-
// const n = x.length;
|
|
1102
|
-
// if (n === 0) return NaN;
|
|
1103
|
-
// const x_mean = mean(...x);
|
|
1104
|
-
// return x.reduce((sum, xi) => sum + (xi - x_mean) ** 2, 0) / n;
|
|
1105
|
-
// };
|
|
1106
|
-
|
|
1107
|
-
// export const std = (...x) => Math.sqrt(variance(...x));
|
|
1108
|
-
|
|
1109
|
-
// export const accum_sum = (...x) => {
|
|
1110
|
-
// let result = [];
|
|
1111
|
-
// let total = 0, i, n = x.length;
|
|
1112
|
-
// for(i = 0; i < n ; i++){
|
|
1113
|
-
// total = add(total, x[i])
|
|
1114
|
-
// result.push(total);
|
|
1115
|
-
// }
|
|
1116
|
-
// return result;
|
|
1117
|
-
// };
|
|
1118
|
-
|
|
1119
|
-
const accum_prod = (...x) => {
|
|
1120
|
-
let result = [];
|
|
1121
|
-
let prod = 1, i, n = x.length;
|
|
1122
|
-
for(i = 0; i < n ; i++){
|
|
1123
|
-
prod = mul(prod, x[i]);
|
|
1124
|
-
result.push(prod);
|
|
1125
|
-
}
|
|
1126
|
-
return result;
|
|
1127
|
-
};
|
|
1128
|
-
|
|
1129
|
-
// export const percentile = (X, p) => {
|
|
1130
|
-
// if (X.length === 0)
|
|
1131
|
-
// return NaN;
|
|
1132
|
-
// let a = [...X].sort((x, y) => x - y);
|
|
1133
|
-
// let index = (p / 100) * (a.length - 1);
|
|
1134
|
-
// let i = Math.floor(index);
|
|
1135
|
-
// let f = index - i;
|
|
1136
|
-
// if (i === a.length - 1)
|
|
1137
|
-
// return a[i];
|
|
1138
|
-
// return a[i] * (1 - f) + a[i + 1] * f;
|
|
1139
|
-
// }
|
|
1140
|
-
|
|
1141
|
-
// export const median = X => percentile(X, 50);
|
|
1142
|
-
|
|
1143
|
-
const not = x => {
|
|
1144
|
-
if(x.isComplex?.()) return new x.constructor(not(x.a), not(x.b))
|
|
1145
|
-
if(x.isMatrix?.()) return new x.constructor(x.rows, x.cols, x.arr.flat(1).map(not))
|
|
1146
|
-
return + !x;
|
|
1147
|
-
};
|
|
1148
|
-
const handle_complex_and_matrix = (x, operation) => {
|
|
1149
|
-
if (x.every(n => n.isComplex?.())) {
|
|
1150
|
-
const Re = x.map(n => n.a);
|
|
1151
|
-
const Im = x.map(n => n.b);
|
|
1152
|
-
return new x[0].constructor(
|
|
1153
|
-
operation(...Re),
|
|
1154
|
-
operation(...Im)
|
|
1155
|
-
);
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
|
-
if (x.every(n => n.isMatrix?.())) {
|
|
1159
|
-
if (!x.every(mat => mat.rows === x[0].rows && mat.cols === x[0].cols)) {
|
|
1160
|
-
return TypeError('All matrices must have the same shape');
|
|
1161
|
-
}
|
|
1162
|
-
|
|
1163
|
-
const { rows, cols } = x[0];
|
|
1164
|
-
const Y = Array.from({ length: rows }, (_, i) =>
|
|
1165
|
-
Array.from({ length: cols }, (_, j) =>
|
|
1166
|
-
operation(...x.map(mat => mat.arr[i][j]))
|
|
1167
|
-
)
|
|
1168
|
-
);
|
|
1169
|
-
return new x[0].constructor(Y);
|
|
1170
|
-
}
|
|
1171
|
-
|
|
1172
|
-
return null; // Return null if no Complex or Matrix found
|
|
1173
|
-
};
|
|
1174
|
-
|
|
1175
|
-
const and = (...x) => {
|
|
1176
|
-
const result = handle_complex_and_matrix(x, and);
|
|
1177
|
-
if (result !== null) return result;
|
|
1178
|
-
return x.reduce((n, m) => (n &= m), 1);
|
|
1179
|
-
};
|
|
1180
|
-
|
|
1181
|
-
const or = (...x) => {
|
|
1182
|
-
const result = handle_complex_and_matrix(x, or);
|
|
1183
|
-
if (result !== null) return result;
|
|
1184
|
-
return x.reduce((n, m) => (n |= m), 0);
|
|
1185
|
-
};
|
|
1186
|
-
|
|
1187
|
-
const xor = (...x) => {
|
|
1188
|
-
const result = handle_complex_and_matrix(x, xor);
|
|
1189
|
-
if (result !== null) return result;
|
|
1190
|
-
return x.reduce((n, m) => (n ^= m), 0);
|
|
1191
|
-
};
|
|
1192
|
-
|
|
1193
|
-
const nand = (...x) => not(and(...x));
|
|
1194
|
-
const nor = (...x) => not(or(...x));
|
|
1195
|
-
const xnor = (...x) => not(xor(...x));
|
|
1196
|
-
|
|
1197
|
-
const matrix_constructor = (Matrix, rows, cols, element) => {
|
|
1198
|
-
if (rows instanceof Matrix) {
|
|
1199
|
-
arr = rows.arr;
|
|
1200
|
-
rows = rows.rows;
|
|
1201
|
-
cols = rows.cols;
|
|
1202
|
-
}
|
|
1203
|
-
else {
|
|
1204
|
-
let arr = [], i, j;
|
|
1205
|
-
if (rows instanceof Array) {
|
|
1206
|
-
arr = rows;
|
|
1207
|
-
rows = arr.length;
|
|
1208
|
-
cols = arr[0].length;
|
|
1209
|
-
}
|
|
1210
|
-
else {
|
|
1211
|
-
for (i = 0; i < rows; i++) {
|
|
1212
|
-
arr.push([]);
|
|
1213
|
-
arr[i].push(new Array(cols));
|
|
1214
|
-
for (j = 0; j < cols; j++) {
|
|
1215
|
-
arr[i][j] = element[i * cols + j];
|
|
1216
|
-
if (element[i * cols + j] == undefined) arr[i][j] = 0;
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
}
|
|
1220
|
-
return [
|
|
1221
|
-
rows,
|
|
1222
|
-
cols,
|
|
1223
|
-
arr
|
|
1224
|
-
]
|
|
1225
|
-
}
|
|
1226
|
-
};
|
|
1227
|
-
|
|
1228
|
-
const maintain_indexes = (Matrix, oldRows) =>{
|
|
1229
|
-
for (let i = 0; i < Matrix.arr.length; i++) {
|
|
1230
|
-
Object.defineProperty(Matrix, i, {
|
|
1231
|
-
value: Matrix.arr[i],
|
|
1232
|
-
writable: true,
|
|
1233
|
-
configurable: true,
|
|
1234
|
-
enumerable: false
|
|
1235
|
-
});
|
|
1236
|
-
}
|
|
1237
|
-
for (let i = Matrix.arr.length; i < oldRows; i++) {
|
|
1238
|
-
delete Matrix[i];
|
|
1239
|
-
}
|
|
1240
|
-
};
|
|
1241
|
-
|
|
1242
|
-
function matrix_inverse(M) {
|
|
1243
|
-
if(M.row !== M.cols) throw Error('is not a square matrix"')
|
|
1244
|
-
if (M.det === 0) throw Error("determinant should not equal 0");
|
|
1245
|
-
const { arr } = M;
|
|
1246
|
-
if (arr.length !== arr[0].length) return;
|
|
1247
|
-
var i = 0, ii = 0, j = 0, dim = arr.length, e = 0;
|
|
1248
|
-
var I = [], C = [];
|
|
1249
|
-
for (i = 0; i < dim; i += 1) {
|
|
1250
|
-
I[I.length] = [];
|
|
1251
|
-
C[C.length] = [];
|
|
1252
|
-
for (j = 0; j < dim; j += 1) {
|
|
1253
|
-
if (i == j) I[i][j] = 1;
|
|
1254
|
-
else I[i][j] = 0;
|
|
1255
|
-
C[i][j] = arr[i][j];
|
|
1256
|
-
}
|
|
1257
|
-
}
|
|
1258
|
-
for (i = 0; i < dim; i += 1) {
|
|
1259
|
-
e = C[i][i];
|
|
1260
|
-
if (e == 0) {
|
|
1261
|
-
for (ii = i + 1; ii < dim; ii += 1) {
|
|
1262
|
-
if (C[ii][i] != 0) {
|
|
1263
|
-
for (j = 0; j < dim; j++) {
|
|
1264
|
-
e = C[i][j];
|
|
1265
|
-
C[i][j] = C[ii][j];
|
|
1266
|
-
C[ii][j] = e;
|
|
1267
|
-
e = I[i][j];
|
|
1268
|
-
I[i][j] = I[ii][j];
|
|
1269
|
-
I[ii][j] = e;
|
|
1270
|
-
}
|
|
1271
|
-
break;
|
|
1272
|
-
}
|
|
1273
|
-
}
|
|
1274
|
-
e = C[i][i];
|
|
1275
|
-
if (e == 0) return;
|
|
1276
|
-
}
|
|
1277
|
-
for (j = 0; j < dim; j++) {
|
|
1278
|
-
C[i][j] = C[i][j] / e;
|
|
1279
|
-
I[i][j] = I[i][j] / e;
|
|
1280
|
-
}
|
|
1281
|
-
for (ii = 0; ii < dim; ii++) {
|
|
1282
|
-
if (ii == i) {
|
|
1283
|
-
continue;
|
|
1284
|
-
}
|
|
1285
|
-
e = C[ii][i];
|
|
1286
|
-
for (j = 0; j < dim; j++) {
|
|
1287
|
-
C[ii][j] -= e * C[i][j];
|
|
1288
|
-
I[ii][j] -= e * I[i][j];
|
|
1289
|
-
}
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
return new M.constructor(I);
|
|
1293
|
-
}
|
|
1294
|
-
|
|
1295
|
-
function matrix_det(M) {
|
|
1296
|
-
if (!M.isSquare) return new Error("is not square matrix");
|
|
1297
|
-
if (M.rows == 1) return M.arr[0][0];
|
|
1298
|
-
function determinat(M) {
|
|
1299
|
-
if (M.length == 2) {
|
|
1300
|
-
if (M.flat(1).some((n) => n?.isMatrix?.())) {
|
|
1301
|
-
console.warn("Tensors are not completely supported yet ...");
|
|
1302
|
-
return;
|
|
1303
|
-
}
|
|
1304
|
-
return sub(mul(M[0][0],M[1][1]),mul(M[0][1],M[1][0]))
|
|
1305
|
-
}
|
|
1306
|
-
var answer = 0;
|
|
1307
|
-
for (var i = 0; i < M.length; i++) {
|
|
1308
|
-
//console.log(M[0][i]);
|
|
1309
|
-
/*answer = answer.add(
|
|
1310
|
-
pow(-1, i)
|
|
1311
|
-
.mul(M[0][i])
|
|
1312
|
-
.mul(determinat(deleteRowAndColumn(M, i)))
|
|
1313
|
-
);*/
|
|
1314
|
-
//const to_be_added=add(mul(pow(-1, i),mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
|
|
1315
|
-
const to_be_added=add(mul(pow$1(-1, i),mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
|
|
1316
|
-
answer=add(answer,to_be_added);
|
|
1317
|
-
}
|
|
1318
|
-
return answer;
|
|
1319
|
-
}
|
|
1320
|
-
return determinat(M.arr);
|
|
1321
|
-
}
|
|
1322
|
-
function deleteRowAndColumn(M, index) {
|
|
1323
|
-
var temp = [];
|
|
1324
|
-
for (let i = 0; i < M.length; i++) temp.push(M[i].slice(0));
|
|
1325
|
-
temp.splice(0, 1);
|
|
1326
|
-
for (let i = 0; i < temp.length; i++) temp[i].splice(index, 1);
|
|
1327
|
-
return temp;
|
|
1328
|
-
}
|
|
1329
|
-
|
|
1330
|
-
function hstack(M1, M2){
|
|
1331
|
-
M1 = M1.clone();
|
|
1332
|
-
M2 = M2.clone();
|
|
1333
|
-
if (M1.rows !== M2.rows) return;
|
|
1334
|
-
let newArr = M1.arr;
|
|
1335
|
-
for (let i = 0; i < M1.rows; i++)
|
|
1336
|
-
for (let j = M1.cols; j < M1.cols + M2.cols; j++)
|
|
1337
|
-
newArr[i][j] = M2.arr[i][j - M1.cols];
|
|
1338
|
-
M1.cols += M2.cols;
|
|
1339
|
-
return new M1.constructor(M1.rows, M1.cols, newArr.flat(1));
|
|
1340
|
-
}
|
|
1341
|
-
|
|
1342
|
-
function vstack(M1, M2){
|
|
1343
|
-
M1 = M1.clone();
|
|
1344
|
-
M2 = M2.clone();
|
|
1345
|
-
if (M1.cols !== M2.cols) return;
|
|
1346
|
-
let newArr = M1.arr;
|
|
1347
|
-
for (let i = M1.rows; i < M1.rows + M2.rows; i++) {
|
|
1348
|
-
newArr[i] = [];
|
|
1349
|
-
for (let j = 0; j < M1.cols; j++) newArr[i][j] = M2.arr[i - M1.rows][j];
|
|
1350
|
-
}
|
|
1351
|
-
M1.rows += M2.rows;
|
|
1352
|
-
return new M1.constructor(M1.rows, M1.cols, newArr.flat(1));
|
|
1353
|
-
}
|
|
1354
|
-
|
|
1355
|
-
class Matrix{
|
|
1356
|
-
constructor(rows, cols, element = [] ) {
|
|
1357
|
-
[
|
|
1358
|
-
this.rows,
|
|
1359
|
-
this.cols,
|
|
1360
|
-
this.arr
|
|
1361
|
-
] = matrix_constructor(Matrix, rows, cols, element);
|
|
1362
|
-
maintain_indexes(this);
|
|
1363
|
-
}
|
|
1364
|
-
isMatrix(){
|
|
1365
|
-
return true
|
|
1366
|
-
}
|
|
1367
|
-
clone() {
|
|
1368
|
-
return new Matrix(this.rows, this.cols, this.arr.flat(1));
|
|
1369
|
-
}
|
|
1370
|
-
toComplex(){
|
|
1371
|
-
this.arr = mapfun$1(
|
|
1372
|
-
x => x?.isComplex?.() ? x : new Complex(x, 0),
|
|
1373
|
-
...this.arr
|
|
1374
|
-
);
|
|
1375
|
-
maintain_indexes(this);
|
|
1376
|
-
return this;
|
|
1377
|
-
}
|
|
1378
|
-
[Symbol.iterator]() {
|
|
1379
|
-
return this.arr[Symbol.iterator]();
|
|
1380
|
-
}
|
|
1381
|
-
get size() {
|
|
1382
|
-
return this.rows * this.cols;
|
|
1383
|
-
}
|
|
1384
|
-
get shape() {
|
|
1385
|
-
return [this.rows, this.cols];
|
|
1386
|
-
}
|
|
1387
|
-
// toString(){
|
|
1388
|
-
// return arr2str(this.arr,false);
|
|
1389
|
-
// }
|
|
1390
|
-
at(i = 0, j = undefined) {
|
|
1391
|
-
if(i < 0) i += this.rows;
|
|
1392
|
-
if(i < 0 || i >= this.rows) throw new Error('Row index out of bounds');
|
|
1393
|
-
if(j === undefined) return this.arr[i];
|
|
1394
|
-
if(j < 0) j += this.cols;
|
|
1395
|
-
if(j < 0 || j >= this.cols) throw new Error('Column index out of bounds');
|
|
1396
|
-
return this.arr[i][j];
|
|
1397
|
-
}
|
|
1398
|
-
slice(r0=0, c0=0, r1 = this.rows-1, c1 = this.cols-1) {
|
|
1399
|
-
if(r1 < 0) r1 = this.rows + r1;
|
|
1400
|
-
if(c1 < 0 ) c1 = this.cols + c1;
|
|
1401
|
-
let newRow = r1 - r0,
|
|
1402
|
-
newCol = c1 - c0;
|
|
1403
|
-
let newArr = new Array(newCol);
|
|
1404
|
-
for (let i = 0; i < newRow; i++) {
|
|
1405
|
-
newArr[i] = [];
|
|
1406
|
-
for (let j = 0; j < newCol; j++)
|
|
1407
|
-
newArr[i][j] = this.arr[i + r0][j + c0];
|
|
1408
|
-
}
|
|
1409
|
-
this.arr = newArr;
|
|
1410
|
-
maintain_indexes(this.rows);
|
|
1411
|
-
this.rows = newRow;
|
|
1412
|
-
this.cols = newCol;
|
|
1413
|
-
return this;
|
|
1414
|
-
}
|
|
1415
|
-
reshape(newRows, newCols) {
|
|
1416
|
-
if(!(newRows * newCols === this.rows * this.cols)) throw Error('size not matched');
|
|
1417
|
-
const oldRows = this.rows;
|
|
1418
|
-
Object.assign(this, new Matrix(newRows, newCols, this.arr.flat(1)));
|
|
1419
|
-
maintain_indexes(oldRows);
|
|
1420
|
-
return this;
|
|
1421
|
-
}
|
|
1422
|
-
get T() {
|
|
1423
|
-
let transpose = [];
|
|
1424
|
-
for (let i = 0; i < this.arr[0].length; i++) {
|
|
1425
|
-
transpose[i] = [];
|
|
1426
|
-
for (let j = 0; j < this.arr.length; j++)
|
|
1427
|
-
transpose[i][j] = this.arr[j][i];
|
|
1428
|
-
}
|
|
1429
|
-
return new Matrix(this.cols, this.rows, transpose.flat(1));
|
|
1430
|
-
}
|
|
1431
|
-
get det() {
|
|
1432
|
-
return matrix_det(this)
|
|
1433
|
-
}
|
|
1434
|
-
get inv() {
|
|
1435
|
-
return matrix_inverse(this)
|
|
1436
|
-
}
|
|
1437
|
-
// normalize names
|
|
1438
|
-
static eye(size) {
|
|
1439
|
-
let result = new Matrix(size, size);
|
|
1440
|
-
for (let i = 0; i < size; i++)
|
|
1441
|
-
for (let j = 0; j < size; j++) i === j ? (result.arr[i][j] = 1) : (result.arr[i][j] = 0);
|
|
1442
|
-
return result;
|
|
1443
|
-
}
|
|
1444
|
-
static zeros(rows, cols) {
|
|
1445
|
-
let result = new Matrix(rows, cols);
|
|
1446
|
-
for (let i = 0; i < rows; i++)
|
|
1447
|
-
for (var j = 0; j < cols; j++) result.arr[i][j] = 0;
|
|
1448
|
-
return result;
|
|
1449
|
-
}
|
|
1450
|
-
static ones(rows, cols) {
|
|
1451
|
-
let result = new Matrix(rows, cols);
|
|
1452
|
-
for (let i = 0; i < rows; i++)
|
|
1453
|
-
for (let j = 0; j < cols; j++) result.arr[i][j] = 1;
|
|
1454
|
-
return result;
|
|
1455
|
-
}
|
|
1456
|
-
static nums(rows, cols, number) {
|
|
1457
|
-
let result = new Matrix(rows, cols);
|
|
1458
|
-
for (let i = 0; i < rows; i++)
|
|
1459
|
-
for (let j = 0; j < cols; j++) result.arr[i][j] = number;
|
|
1460
|
-
return result;
|
|
1461
|
-
}
|
|
1462
|
-
static get random(){
|
|
1463
|
-
return {
|
|
1464
|
-
int : (r, c, a, b)=> new Matrix(
|
|
1465
|
-
r,
|
|
1466
|
-
c,
|
|
1467
|
-
Random.sample.int(r*c, a, b)
|
|
1468
|
-
),
|
|
1469
|
-
float : (r, c, a,)=> new Matrix(
|
|
1470
|
-
r,
|
|
1471
|
-
c,
|
|
1472
|
-
Random.sample.float(r*c, a, b)
|
|
1473
|
-
),
|
|
1474
|
-
}
|
|
1475
|
-
}
|
|
1476
|
-
get range(){
|
|
1477
|
-
return {
|
|
1478
|
-
map : (xmin, xmax, ymin, ymax) => {
|
|
1479
|
-
this.arr = map$1(this.arr, xmin, xmax, ymin, ymax);
|
|
1480
|
-
return this;
|
|
1481
|
-
},
|
|
1482
|
-
norm : (min, max) => {
|
|
1483
|
-
this.arr = norm(this.arr, min, max);
|
|
1484
|
-
return this;
|
|
1485
|
-
},
|
|
1486
|
-
lerp : (min, max) => {
|
|
1487
|
-
this.arr = lerp(this.arr, min, max);
|
|
1488
|
-
return this;
|
|
1489
|
-
},
|
|
1490
|
-
clamp : (min, max) => {
|
|
1491
|
-
this.arr = clamp(this.arr, min, max);
|
|
1492
|
-
return this;
|
|
1493
|
-
},
|
|
1494
|
-
|
|
1495
|
-
}
|
|
1496
|
-
}
|
|
1497
|
-
hstack(...matrices) {
|
|
1498
|
-
const M=[this, ...matrices].reduce((a,b)=>hstack(a, b));
|
|
1499
|
-
Object.assign(this, M);
|
|
1500
|
-
maintain_indexes(this);
|
|
1501
|
-
return this;
|
|
1502
|
-
}
|
|
1503
|
-
vstack(...matrices){
|
|
1504
|
-
const M=[this, ...matrices].reduce((a,b)=>vstack(a, b));
|
|
1505
|
-
Object.assign(this, M);
|
|
1506
|
-
maintain_indexes(this);
|
|
1507
|
-
return this;
|
|
1508
|
-
}
|
|
1509
|
-
hqueue(...matrices){
|
|
1510
|
-
const M=[this, ...matrices].reverse().reduce((a,b)=>hstack(a, b));
|
|
1511
|
-
Object.assign(this, M);
|
|
1512
|
-
maintain_indexes(this);
|
|
1513
|
-
return this;
|
|
1514
|
-
}
|
|
1515
|
-
vqueue(...matrices){
|
|
1516
|
-
const M=[this,...matrices].reverse().reduce((a, b)=>vstack(a, b));
|
|
1517
|
-
Object.assign(this, M);
|
|
1518
|
-
maintain_indexes(this);
|
|
1519
|
-
return this;
|
|
1520
|
-
}
|
|
1521
|
-
forEach(fn){
|
|
1522
|
-
this.arr.flat(1).forEach(fn);
|
|
1523
|
-
return this;
|
|
1524
|
-
}
|
|
1525
|
-
forEachRow(fn){
|
|
1526
|
-
this.arr.forEach(fn);
|
|
1527
|
-
return this;
|
|
1528
|
-
}
|
|
1529
|
-
forEachCol(fn){
|
|
1530
|
-
this.clone().T.forEachRow(fn);
|
|
1531
|
-
return this
|
|
1532
|
-
}
|
|
1533
|
-
map(fn){
|
|
1534
|
-
const arr = this.arr.flat(1).map(fn);
|
|
1535
|
-
return new Matrix(
|
|
1536
|
-
this.rows,
|
|
1537
|
-
this.cols,
|
|
1538
|
-
arr
|
|
1539
|
-
)
|
|
1540
|
-
}
|
|
1541
|
-
mapRows(fn = ()=>{}){
|
|
1542
|
-
this.arr = this.arr.map(fn);
|
|
1543
|
-
return this;
|
|
1544
|
-
}
|
|
1545
|
-
mapCols(fn){
|
|
1546
|
-
return this.clone().T.mapRows(fn).T;
|
|
1547
|
-
}
|
|
1548
|
-
sort(fn = ()=>{}){
|
|
1549
|
-
const arr = this.arr.flat(1).sort(fn);
|
|
1550
|
-
return new Matrix(
|
|
1551
|
-
this.rows,
|
|
1552
|
-
this.cols,
|
|
1553
|
-
arr
|
|
1554
|
-
)
|
|
1555
|
-
}
|
|
1556
|
-
shuffle(){
|
|
1557
|
-
return this.sort(() => 0.5-Math.random())
|
|
1558
|
-
}
|
|
1559
|
-
sortRows(fn = ()=>{}){
|
|
1560
|
-
this.arr = this.arr.map(row => row.sort(fn));
|
|
1561
|
-
return this;
|
|
1562
|
-
}
|
|
1563
|
-
shuffleRows(){
|
|
1564
|
-
return this.sortRows(() => 0.5-Math.random())
|
|
1565
|
-
}
|
|
1566
|
-
sortCols(fn){
|
|
1567
|
-
return this.clone().T.sortRows(fn).T;
|
|
1568
|
-
}
|
|
1569
|
-
shuffleCols(){
|
|
1570
|
-
return this.sortCols(() => 0.5-Math.random())
|
|
1571
|
-
}
|
|
1572
|
-
reduce(fn, initialValue){
|
|
1573
|
-
const value = initialValue
|
|
1574
|
-
? this.arr.flat(1).reduce(fn, initialValue)
|
|
1575
|
-
: this.arr.flat(1).reduce(fn);
|
|
1576
|
-
return new Matrix([[value]])
|
|
1577
|
-
}
|
|
1578
|
-
reduceRows(fn, initialValue){
|
|
1579
|
-
const values = initialValue
|
|
1580
|
-
? this.arr.map(row => row.reduce(fn, initialValue))
|
|
1581
|
-
: this.arr.map(row => row.reduce(fn));
|
|
1582
|
-
return new Matrix(1, this.cols, values)
|
|
1583
|
-
}
|
|
1584
|
-
reduceCols(fn, initialValue){
|
|
1585
|
-
return this.T.reduceRows(fn, initialValue).T
|
|
1586
|
-
}
|
|
1587
|
-
filterRows(fn){
|
|
1588
|
-
const mask = this.arr.map(n => n.some(m => fn(m)));
|
|
1589
|
-
const arr = [];
|
|
1590
|
-
let i;
|
|
1591
|
-
for(i = 0; i < mask.length; i++)
|
|
1592
|
-
if(mask[i]) arr.push(this.arr[i]);
|
|
1593
|
-
return new Matrix(arr)
|
|
1594
|
-
}
|
|
1595
|
-
filterCols(fn){
|
|
1596
|
-
const arr = this.T.filterRows(fn);
|
|
1597
|
-
return new Matrix(arr).T
|
|
1598
|
-
}
|
|
1599
|
-
every(fn){
|
|
1600
|
-
return this.arr.flat(1).every(fn)
|
|
1601
|
-
}
|
|
1602
|
-
everyRow(fn){
|
|
1603
|
-
return this.arr.map(n => n.every(fn))
|
|
1604
|
-
}
|
|
1605
|
-
everyCol(fn){
|
|
1606
|
-
return this.T.arr.map(n => n.every(fn))
|
|
1607
|
-
}
|
|
1608
|
-
some(fn){
|
|
1609
|
-
return this.arr.flat(1).some(fn)
|
|
1610
|
-
}
|
|
1611
|
-
someRow(fn){
|
|
1612
|
-
return this.arr.map(n => n.some(fn))
|
|
1613
|
-
}
|
|
1614
|
-
someCol(fn){
|
|
1615
|
-
return this.T.arr.map(n => n.some(fn))
|
|
1616
|
-
}
|
|
1617
|
-
// Checkers
|
|
1618
|
-
get isSquare() {
|
|
1619
|
-
return this.rows === this.cols;
|
|
1620
|
-
}
|
|
1621
|
-
get isSym() {
|
|
1622
|
-
if (!this.isSquare) return false;
|
|
1623
|
-
for (let i = 0; i < this.rows; i++) {
|
|
1624
|
-
for (let j = i + 1; j < this.cols; j++) {
|
|
1625
|
-
if (this.arr[i][j] !== this.arr[j][i]) return false;
|
|
1626
|
-
}
|
|
1627
|
-
}
|
|
1628
|
-
return true;
|
|
1629
|
-
}
|
|
1630
|
-
get isAntiSym() {
|
|
1631
|
-
if (!this.isSquare) return false;
|
|
1632
|
-
const n = this.rows;
|
|
1633
|
-
for (let i = 0; i < n; i++) {
|
|
1634
|
-
if (this.arr[i][i] !== 0) return false;
|
|
1635
|
-
for (let j = i + 1; j < n; j++) {
|
|
1636
|
-
if (this.arr[i][j] !== -this.arr[j][i]) return false;
|
|
1637
|
-
}
|
|
1638
|
-
}
|
|
1639
|
-
return true;
|
|
1640
|
-
}
|
|
1641
|
-
get isDiag() {
|
|
1642
|
-
if (!this.isSquare) return false;
|
|
1643
|
-
const n = this.rows;
|
|
1644
|
-
for (let i = 0; i < n; i++) {
|
|
1645
|
-
for (let j = i + 1; j < n; j++) {
|
|
1646
|
-
if (this.arr[i][j] !== 0 || this.arr[j][i] !== 0) return false;
|
|
1647
|
-
}
|
|
1648
|
-
}
|
|
1649
|
-
return true;
|
|
1650
|
-
}
|
|
1651
|
-
get isOrtho() {
|
|
1652
|
-
if (!this.isSquare) return false;
|
|
1653
|
-
return this.isDiag && (this.det == 1 || this.det == -1);
|
|
1654
|
-
}
|
|
1655
|
-
get isIdemp() {
|
|
1656
|
-
if (!this.isSquare) return false;
|
|
1657
|
-
const n = this.rows;
|
|
1658
|
-
const A = this.arr;
|
|
1659
|
-
// Compute A * A
|
|
1660
|
-
const MM = [];
|
|
1661
|
-
for (let i = 0; i < n; i++) {
|
|
1662
|
-
MM[i] = [];
|
|
1663
|
-
for (let j = 0; j < n; j++) {
|
|
1664
|
-
let sum = 0;
|
|
1665
|
-
for (let k = 0; k < n; k++) {
|
|
1666
|
-
sum += A[i][k] * A[k][j];
|
|
1667
|
-
}
|
|
1668
|
-
MM[i][j] = sum;
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
// Check if A * A == A
|
|
1672
|
-
for (let i = 0; i < n; i++) {
|
|
1673
|
-
for (let j = 0; j < n; j++) {
|
|
1674
|
-
if (MM[i][j] !== A[i][j]) return false;
|
|
1675
|
-
}
|
|
1676
|
-
}
|
|
1677
|
-
return true;
|
|
1678
|
-
}
|
|
1679
|
-
|
|
1680
|
-
get isUpperTri() {
|
|
1681
|
-
if (!this.isSquare) return false;
|
|
1682
|
-
const n = this.rows;
|
|
1683
|
-
for (let i = 1; i < n; i++) {
|
|
1684
|
-
for (let j = 0; j < i; j++) {
|
|
1685
|
-
if (this.arr[i][j] !== 0) return false;
|
|
1686
|
-
}
|
|
1687
|
-
}
|
|
1688
|
-
return true;
|
|
1689
|
-
}
|
|
1690
|
-
get isLowerTri() {
|
|
1691
|
-
if (!this.isSquare) return false;
|
|
1692
|
-
const n = this.rows;
|
|
1693
|
-
for (let i = 0; i < n - 1; i++) {
|
|
1694
|
-
for (let j = i + 1; j < n; j++) {
|
|
1695
|
-
if (this.arr[i][j] !== 0) return false;
|
|
1696
|
-
}
|
|
1697
|
-
}
|
|
1698
|
-
return true;
|
|
1699
|
-
}
|
|
1700
|
-
toPrecision(p) {
|
|
1701
|
-
for (let i = 0; i < this.cols; i++)
|
|
1702
|
-
for (let j = 0; j < this.rows; j++)
|
|
1703
|
-
this.arr[i][j] = +this.arr[i][j].toPrecision(p);
|
|
1704
|
-
return this;
|
|
1705
|
-
}
|
|
1706
|
-
toFixed(p) {
|
|
1707
|
-
for (let i = 0; i < this.cols; i++)
|
|
1708
|
-
for (let j = 0; j < this.rows; j++)
|
|
1709
|
-
this.arr[i][j] = +this.arr[i][j].toFixed(p);
|
|
1710
|
-
return this;
|
|
1711
|
-
}
|
|
1712
|
-
// max2min() {
|
|
1713
|
-
// let newArr = this.arr.flat(1).max2min;
|
|
1714
|
-
// return new Matrix(this.rows, this.cols, newArr);
|
|
1715
|
-
// }
|
|
1716
|
-
// min2max() {
|
|
1717
|
-
// let newArr = this.arr.flat(1).min2max;
|
|
1718
|
-
// return new Matrix(this.rows, this.cols, newArr);
|
|
1719
|
-
// }
|
|
1720
|
-
// count(n) {
|
|
1721
|
-
// return this.arr.flat(1).count(n);
|
|
1722
|
-
// }
|
|
1723
|
-
splice(r0,c0,deleteCount,...items){
|
|
1724
|
-
|
|
1725
|
-
}
|
|
1726
|
-
getRows(ri, rf = ri + 1) {
|
|
1727
|
-
return this.slice(ri, 0, rf, this.cols);
|
|
1728
|
-
}
|
|
1729
|
-
getCols(ci, cf = ci + 1) {
|
|
1730
|
-
return this.slice(0, ci, this.rows, cf);
|
|
1731
|
-
}
|
|
1732
|
-
#arithmetic(fn, ...matr){
|
|
1733
|
-
for (let k = 0; k < matr.length; k++) {
|
|
1734
|
-
if (typeof matr[k] == "number" || matr[k]?.isComplex?.()) matr[k] = Matrix.nums(this.rows, this.cols, matr[k]);
|
|
1735
|
-
for (let i = 0; i < this.rows; i++)
|
|
1736
|
-
for (var j = 0; j < this.cols; j++)
|
|
1737
|
-
this.arr[i][j] = fn(this.arr[i][j], matr[k].arr[i][j]);
|
|
1738
|
-
}
|
|
1739
|
-
return new Matrix(this.rows, this.cols, this.arr.flat(1));
|
|
1740
|
-
}
|
|
1741
|
-
add(...matr) {
|
|
1742
|
-
return this.#arithmetic(add, ...matr)
|
|
1743
|
-
}
|
|
1744
|
-
sub(...matr) {
|
|
1745
|
-
return this.#arithmetic(sub, ...matr)
|
|
1746
|
-
}
|
|
1747
|
-
mul(...matr) {
|
|
1748
|
-
return this.#arithmetic(mul, ...matr)
|
|
1749
|
-
}
|
|
1750
|
-
div(...matr) {
|
|
1751
|
-
return this.#arithmetic(div, ...matr)
|
|
1752
|
-
}
|
|
1753
|
-
modulo(...matr) {
|
|
1754
|
-
return this.#arithmetic(modulo, ...matr)
|
|
1755
|
-
}
|
|
1756
|
-
dot(matrix) {
|
|
1757
|
-
var res = [];
|
|
1758
|
-
for (var i = 0; i < this.arr.length; i++) {
|
|
1759
|
-
res[i] = [];
|
|
1760
|
-
for (var j = 0; j < matrix.arr[0].length; j++) {
|
|
1761
|
-
res[i][j] = 0;
|
|
1762
|
-
for (var k = 0; k < this.arr[0].length; k++) {
|
|
1763
|
-
res[i][j] = add(
|
|
1764
|
-
res[i][j],
|
|
1765
|
-
mul(this.arr[i][k],matrix.arr[k][j])
|
|
1766
|
-
);
|
|
1767
|
-
}
|
|
1768
|
-
}
|
|
1769
|
-
}
|
|
1770
|
-
return new Matrix(this.arr.length, matrix.arr[0].length, res.flat(1));
|
|
1771
|
-
}
|
|
1772
|
-
pow(n) {
|
|
1773
|
-
let a = this.clone(),
|
|
1774
|
-
p = this.clone();
|
|
1775
|
-
for (let i = 0; i < n - 1; i++) p = p.dot(a);
|
|
1776
|
-
return p;
|
|
1777
|
-
}
|
|
1778
|
-
sum(){
|
|
1779
|
-
let S = 0;
|
|
1780
|
-
for (let i = 0; i < this.rows; i++)
|
|
1781
|
-
for (let j = 0; j < this.cols; j++)
|
|
1782
|
-
S = add(S, this.arr[i][j]);
|
|
1783
|
-
return S;
|
|
1784
|
-
}
|
|
1785
|
-
prod(){
|
|
1786
|
-
let S = 1;
|
|
1787
|
-
for (let i = 0; i < this.rows; i++)
|
|
1788
|
-
for (let j = 0; j < this.cols; j++)
|
|
1789
|
-
S = mul(S, this.arr[i][j]);
|
|
1790
|
-
return S;
|
|
1791
|
-
}
|
|
1792
|
-
hasComplex(){
|
|
1793
|
-
return this.arr.flat(Infinity).some((n) => n instanceof Complex);
|
|
1794
|
-
}
|
|
1795
|
-
get min() {
|
|
1796
|
-
if (this.hasComplex()) console.error("Complex numbers are not comparable");
|
|
1797
|
-
let minRow = [];
|
|
1798
|
-
for (let i = 0; i < this.rows; i++)
|
|
1799
|
-
minRow.push(Math.min(...this.arr[i]));
|
|
1800
|
-
return Math.min(...minRow);
|
|
1801
|
-
}
|
|
1802
|
-
get max() {
|
|
1803
|
-
if (this.hasComplex()) console.error("Complex numbers are not comparable");
|
|
1804
|
-
let maxRow = [];
|
|
1805
|
-
for (let i = 0; i < this.rows; i++)
|
|
1806
|
-
maxRow.push(Math.max(...this.arr[i]));
|
|
1807
|
-
return Math.max(...maxRow);
|
|
1808
|
-
}
|
|
1809
|
-
get minRows() {
|
|
1810
|
-
if (this.hasComplex()) console.error("Complex numbers are not comparable");
|
|
1811
|
-
let minRow = [];
|
|
1812
|
-
for (let i = 0; i < this.rows; i++)
|
|
1813
|
-
minRow.push(Math.min(...this.arr[i]));
|
|
1814
|
-
return minRow;
|
|
1815
|
-
}
|
|
1816
|
-
get maxRows() {
|
|
1817
|
-
if (this.hasComplex()) console.error("Complex numbers are not comparable");
|
|
1818
|
-
let maxRow = [];
|
|
1819
|
-
for (let i = 0; i < this.rows; i++)
|
|
1820
|
-
maxRow.push(Math.max(...this.arr[i]));
|
|
1821
|
-
return maxRow;
|
|
1822
|
-
}
|
|
1823
|
-
get minCols() {
|
|
1824
|
-
if (this.hasComplex()) console.error("Complex numbers are not comparable");
|
|
1825
|
-
return this.T.minRows;
|
|
1826
|
-
}
|
|
1827
|
-
get maxCols() {
|
|
1828
|
-
if (this.hasComplex()) console.error("Complex numbers are not comparable");
|
|
1829
|
-
return this.T.maxRows;
|
|
1830
|
-
}
|
|
1831
|
-
static fromVector(v) {
|
|
1832
|
-
return new Matrix(v.length, 1, v);
|
|
1833
|
-
}
|
|
1834
|
-
serialize() {
|
|
1835
|
-
const arr = mapfun$1(x => x.serialize?.() || x, ...this.arr);
|
|
1836
|
-
return JSON.stringify({
|
|
1837
|
-
type : 'matrix',
|
|
1838
|
-
data : {
|
|
1839
|
-
rows : this.rows,
|
|
1840
|
-
cols : this.cols,
|
|
1841
|
-
arr,
|
|
1842
|
-
}
|
|
1843
|
-
});
|
|
1844
|
-
}
|
|
1845
|
-
static deserialize(json) {
|
|
1846
|
-
if (typeof json == "string") json = JSON.parse(json);
|
|
1847
|
-
const {type, data} = json;
|
|
1848
|
-
if(type !== 'matrix') return TypeError('Not a valid Matrix')
|
|
1849
|
-
let {arr} = data;
|
|
1850
|
-
arr = mapfun$1(x => {
|
|
1851
|
-
if(typeof x === 'string') {
|
|
1852
|
-
const x_obj = JSON.parse(x);
|
|
1853
|
-
const {type} = x_obj;
|
|
1854
|
-
if(type === 'complex') return Complex.deserialize(x_obj)
|
|
1855
|
-
}
|
|
1856
|
-
return x
|
|
1857
|
-
}, ...arr);
|
|
1858
|
-
return new Matrix(arr)
|
|
1859
|
-
}
|
|
1860
|
-
flip(){
|
|
1861
|
-
return this.flipeH().flipeV()
|
|
1862
|
-
}
|
|
1863
|
-
flipeH(){
|
|
1864
|
-
this.arr = this.arr.map(row => [...row].reverse());
|
|
1865
|
-
maintain_indexes(this);
|
|
1866
|
-
return this;
|
|
1867
|
-
}
|
|
1868
|
-
flipeV(){
|
|
1869
|
-
this.arr = this.arr.reverse();
|
|
1870
|
-
maintain_indexes(this);
|
|
1871
|
-
return this;
|
|
1872
|
-
}
|
|
1873
|
-
}
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
const matrix=(r, c, element)=>new Matrix(r, c, element);
|
|
1877
|
-
const matrix2=(...element)=>new Matrix(2, 2, element);
|
|
1878
|
-
const matrix3=(...element)=>new Matrix(3, 3, element);
|
|
1879
|
-
const matrix4=(...element)=>new Matrix(4, 4, element);
|
|
1880
|
-
|
|
1881
1069
|
class UINode {
|
|
1882
1070
|
constructor(node){
|
|
1883
1071
|
this.cache = {
|
|
@@ -1894,7 +1082,7 @@ class UINode {
|
|
|
1894
1082
|
|
|
1895
1083
|
// globalThis.node = (node) => new UINode(node);
|
|
1896
1084
|
|
|
1897
|
-
function parseQueryParams
|
|
1085
|
+
function parseQueryParams(queryString) {
|
|
1898
1086
|
const params = {};
|
|
1899
1087
|
queryString.replace(/[A-Z0-9]+?=([\w|:|\/\.]*)/gi, (match) => {
|
|
1900
1088
|
const [key, value] = match.split('=');
|
|
@@ -1903,11 +1091,11 @@ function parseQueryParams$2(queryString) {
|
|
|
1903
1091
|
return params;
|
|
1904
1092
|
}
|
|
1905
1093
|
|
|
1906
|
-
function defineParamsGetter
|
|
1094
|
+
function defineParamsGetter(target ){
|
|
1907
1095
|
Object.defineProperties(target, {
|
|
1908
1096
|
'QueryParams': {
|
|
1909
1097
|
get: function() {
|
|
1910
|
-
return parseQueryParams
|
|
1098
|
+
return parseQueryParams(globalThis.location.search.substring(1));
|
|
1911
1099
|
},
|
|
1912
1100
|
configurable: false,
|
|
1913
1101
|
enumerable: true
|
|
@@ -1960,9 +1148,9 @@ const __Config__ = {
|
|
|
1960
1148
|
default:{
|
|
1961
1149
|
target:null,
|
|
1962
1150
|
render:true,
|
|
1963
|
-
math:{
|
|
1964
|
-
|
|
1965
|
-
}
|
|
1151
|
+
// math:{
|
|
1152
|
+
// mode:"deg"
|
|
1153
|
+
// }
|
|
1966
1154
|
},
|
|
1967
1155
|
setDefault:function(pairs){
|
|
1968
1156
|
const keys=Object.keys(pairs);
|
|
@@ -1999,219 +1187,24 @@ const __CACHE__ = {
|
|
|
1999
1187
|
}
|
|
2000
1188
|
};
|
|
2001
1189
|
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
this
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
this
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
if (rooms && rooms.length && !rooms.some(r => this.#currentRooms.has(r))) return;
|
|
2021
|
-
this.#subscribers.add(userId);
|
|
2022
|
-
this.#eventData = new Map(eventData);
|
|
2023
|
-
const handlersList = this.#handlers.get(last_sent_event);
|
|
2024
|
-
if (!handlersList) return;
|
|
2025
|
-
handlersList.forEach(({ fn, rooms: handlerRooms }) => {
|
|
2026
|
-
// trigger if listener has no room filter, or intersects subscriber rooms
|
|
2027
|
-
if (!handlerRooms || handlerRooms.length === 0 ||
|
|
2028
|
-
!rooms || rooms.some(r => handlerRooms.includes(r))) {
|
|
2029
|
-
fn(this.#eventData.get(last_sent_event));
|
|
2030
|
-
}
|
|
2031
|
-
});
|
|
2032
|
-
});
|
|
2033
|
-
}
|
|
2034
|
-
|
|
2035
|
-
emit(event, data, rooms) {
|
|
2036
|
-
this.#eventData.set(event, data);
|
|
2037
|
-
if(typeof rooms === 'string') rooms = [rooms];
|
|
2038
|
-
this.#channel.postMessage({
|
|
2039
|
-
eventData: Array.from(this.#eventData.entries()),
|
|
2040
|
-
last_sent_event: event,
|
|
2041
|
-
userId: this.#uuid,
|
|
2042
|
-
rooms: rooms && rooms.length ? rooms : undefined
|
|
2043
|
-
});
|
|
2044
|
-
return this;
|
|
2045
|
-
}
|
|
2046
|
-
on(event, handler = console.log, rooms) {
|
|
2047
|
-
if (!this.#handlers.has(event)) this.#handlers.set(event, []);
|
|
2048
|
-
if(typeof rooms === 'string') rooms = [rooms];
|
|
2049
|
-
this.#handlers.get(event).push({ fn: handler, rooms });
|
|
2050
|
-
return this;
|
|
2051
|
-
}
|
|
2052
|
-
off(event, handler) {
|
|
2053
|
-
if (!this.#handlers.has(event)) return this;
|
|
2054
|
-
this.#handlers.set(
|
|
2055
|
-
event,
|
|
2056
|
-
this.#handlers.get(event).filter(h => h.fn !== handler)
|
|
2057
|
-
);
|
|
2058
|
-
return this;
|
|
2059
|
-
}
|
|
2060
|
-
once(event, handler, rooms) {
|
|
2061
|
-
const wrapper = (data) => {
|
|
2062
|
-
handler(data);
|
|
2063
|
-
this.off(event, wrapper);
|
|
2064
|
-
};
|
|
2065
|
-
this.on(event, wrapper, rooms);
|
|
2066
|
-
return this;
|
|
2067
|
-
}
|
|
2068
|
-
join(...rooms) {
|
|
2069
|
-
rooms.forEach(r => this.#currentRooms.add(r));
|
|
2070
|
-
return this;
|
|
2071
|
-
}
|
|
2072
|
-
leave(...rooms) {
|
|
2073
|
-
if (!rooms.length) this.#currentRooms.clear();
|
|
2074
|
-
else rooms.forEach(r => this.#currentRooms.delete(r));
|
|
2075
|
-
return this;
|
|
2076
|
-
}
|
|
2077
|
-
close() {
|
|
2078
|
-
this.#channel.close();
|
|
2079
|
-
return this;
|
|
2080
|
-
}
|
|
2081
|
-
}
|
|
2082
|
-
|
|
2083
|
-
const useIPC = (name) => new UseIPC(name);
|
|
2084
|
-
|
|
2085
|
-
class UseStorage {
|
|
2086
|
-
static RESERVED_KEYS = new Set([
|
|
2087
|
-
"cache", "items", "set", "add", "remove", "get", "clear", "onStorageUpdated"
|
|
2088
|
-
]);
|
|
2089
|
-
|
|
2090
|
-
constructor(storage, globalKey, initialValue, use_channel = true) {
|
|
2091
|
-
this.cache = {
|
|
2092
|
-
storage,
|
|
2093
|
-
globalKey,
|
|
2094
|
-
channel: use_channel ? useIPC(`Ziko:useStorage-${globalKey}`) : null,
|
|
2095
|
-
oldItemKeys: new Set()
|
|
2096
|
-
};
|
|
2097
|
-
|
|
2098
|
-
this.#init(initialValue, use_channel);
|
|
2099
|
-
}
|
|
2100
|
-
|
|
2101
|
-
get items() {
|
|
2102
|
-
const raw = this.cache.storage.getItem(this.cache.globalKey);
|
|
2103
|
-
if (!raw) return {};
|
|
2104
|
-
try {
|
|
2105
|
-
return JSON.parse(raw);
|
|
2106
|
-
} catch {
|
|
2107
|
-
return {};
|
|
2108
|
-
}
|
|
2109
|
-
}
|
|
2110
|
-
|
|
2111
|
-
#maintain() {
|
|
2112
|
-
const currentItems = this.items;
|
|
2113
|
-
const currentKeys = new Set(Object.keys(currentItems));
|
|
2114
|
-
|
|
2115
|
-
// Cleanup keys that were removed
|
|
2116
|
-
this.cache.oldItemKeys.forEach(key => {
|
|
2117
|
-
if (!currentKeys.has(key)) {
|
|
2118
|
-
delete this[key];
|
|
2119
|
-
this.cache.oldItemKeys.delete(key);
|
|
2120
|
-
}
|
|
2121
|
-
});
|
|
2122
|
-
|
|
2123
|
-
// Populate keys from storage onto `this`
|
|
2124
|
-
for (const key in currentItems) {
|
|
2125
|
-
if (!UseStorage.RESERVED_KEYS.has(key)) {
|
|
2126
|
-
this[key] = currentItems[key];
|
|
2127
|
-
this.cache.oldItemKeys.add(key);
|
|
2128
|
-
}
|
|
2129
|
-
}
|
|
2130
|
-
}
|
|
2131
|
-
|
|
2132
|
-
#init(initialValue, use_channel) {
|
|
2133
|
-
if (use_channel && this.cache.channel) {
|
|
2134
|
-
this.cache.channel.on("Ziko-Storage-Updated", () => this.#maintain());
|
|
2135
|
-
}
|
|
2136
|
-
|
|
2137
|
-
const hasStoredData = this.cache.storage.getItem(this.cache.globalKey) !== null;
|
|
2138
|
-
|
|
2139
|
-
if (hasStoredData) {
|
|
2140
|
-
// Key already exists in storage -> Restore data to instance
|
|
2141
|
-
this.#maintain();
|
|
2142
|
-
} else if (initialValue !== undefined) {
|
|
2143
|
-
// Key doesn't exist -> Seed with initialValue
|
|
2144
|
-
this.set(initialValue);
|
|
2145
|
-
} else {
|
|
2146
|
-
// Key doesn't exist and no initialValue provided -> Default to empty
|
|
2147
|
-
this.#maintain();
|
|
2148
|
-
}
|
|
2149
|
-
}
|
|
2150
|
-
|
|
2151
|
-
set(data) {
|
|
2152
|
-
this.cache.storage.setItem(this.cache.globalKey, JSON.stringify(data));
|
|
2153
|
-
if (this.cache.channel) {
|
|
2154
|
-
this.cache.channel.emit("Ziko-Storage-Updated", data);
|
|
2155
|
-
}
|
|
2156
|
-
this.#maintain();
|
|
2157
|
-
return this;
|
|
2158
|
-
}
|
|
2159
|
-
|
|
2160
|
-
add(data) {
|
|
2161
|
-
return this.set({
|
|
2162
|
-
...this.items,
|
|
2163
|
-
...data
|
|
2164
|
-
});
|
|
2165
|
-
}
|
|
2166
|
-
|
|
2167
|
-
remove(...keys) {
|
|
2168
|
-
const items = { ...this.items };
|
|
2169
|
-
keys.forEach(key => delete items[key]);
|
|
2170
|
-
return this.set(items);
|
|
2171
|
-
}
|
|
2172
|
-
|
|
2173
|
-
get(key) {
|
|
2174
|
-
return this.items[key];
|
|
2175
|
-
}
|
|
2176
|
-
|
|
2177
|
-
clear() {
|
|
2178
|
-
this.cache.storage.removeItem(this.cache.globalKey);
|
|
2179
|
-
this.#maintain();
|
|
2180
|
-
return this;
|
|
2181
|
-
}
|
|
2182
|
-
|
|
2183
|
-
onStorageUpdated(callback) {
|
|
2184
|
-
if (this.cache.channel) {
|
|
2185
|
-
this.cache.channel.on("Ziko-Storage-Updated", callback);
|
|
2186
|
-
}
|
|
2187
|
-
return this;
|
|
2188
|
-
}
|
|
2189
|
-
}
|
|
2190
|
-
|
|
2191
|
-
const useLocalStorage = (key, initialValue, use_channel = true) =>
|
|
2192
|
-
new UseStorage(localStorage, key, initialValue, use_channel);
|
|
2193
|
-
|
|
2194
|
-
const useSessionStorage = (key, initialValue, use_channel = true) =>
|
|
2195
|
-
new UseStorage(sessionStorage, key, initialValue, use_channel);
|
|
2196
|
-
|
|
2197
|
-
var __State__ = {
|
|
2198
|
-
store : new Map(),
|
|
2199
|
-
index : 0,
|
|
2200
|
-
session_storage : null,
|
|
2201
|
-
register: function(state){
|
|
2202
|
-
// if(!import.meta?.env?.SSR && import.meta?.env?.DEV){
|
|
2203
|
-
// if(!this.session) this.session_storage = useSessionStorage('ziko-state', {})
|
|
2204
|
-
// const savedValue = this.session_storage.get(this.index)
|
|
2205
|
-
// if(!savedValue) this.session_storage.add({[this.index] : state.value});
|
|
2206
|
-
// else state.value = savedValue
|
|
2207
|
-
// }
|
|
2208
|
-
// this.store.set(this.index++, state)
|
|
2209
|
-
},
|
|
2210
|
-
update: function(index, value){
|
|
2211
|
-
// if(!import.meta?.env?.SSR && import.meta?.env?.DEV){
|
|
2212
|
-
// this.session_storage.add({[index] : value})
|
|
2213
|
-
// }
|
|
2214
|
-
},
|
|
1190
|
+
var __State__ = {
|
|
1191
|
+
store : new Map(),
|
|
1192
|
+
index : 0,
|
|
1193
|
+
session_storage : null,
|
|
1194
|
+
register: function(state){
|
|
1195
|
+
// if(!import.meta?.env?.SSR && import.meta?.env?.DEV){
|
|
1196
|
+
// if(!this.session) this.session_storage = useSessionStorage('ziko-state', {})
|
|
1197
|
+
// const savedValue = this.session_storage.get(this.index)
|
|
1198
|
+
// if(!savedValue) this.session_storage.add({[this.index] : state.value});
|
|
1199
|
+
// else state.value = savedValue
|
|
1200
|
+
// }
|
|
1201
|
+
// this.store.set(this.index++, state)
|
|
1202
|
+
},
|
|
1203
|
+
update: function(index, value){
|
|
1204
|
+
// if(!import.meta?.env?.SSR && import.meta?.env?.DEV){
|
|
1205
|
+
// this.session_storage.add({[index] : value})
|
|
1206
|
+
// }
|
|
1207
|
+
},
|
|
2215
1208
|
|
|
2216
1209
|
};
|
|
2217
1210
|
|
|
@@ -2225,7 +1218,7 @@ function __init__global__(){
|
|
|
2225
1218
|
__CACHE__,
|
|
2226
1219
|
__PROVIDERS__: {}
|
|
2227
1220
|
};
|
|
2228
|
-
defineParamsGetter
|
|
1221
|
+
defineParamsGetter(__Ziko__);
|
|
2229
1222
|
}
|
|
2230
1223
|
}
|
|
2231
1224
|
|
|
@@ -2267,11 +1260,9 @@ class UIElementCore extends UINode{
|
|
|
2267
1260
|
switch(type){
|
|
2268
1261
|
case "html" : {
|
|
2269
1262
|
element = globalThis?.document?.createElement(element);
|
|
2270
|
-
// console.log('1')
|
|
2271
1263
|
} break;
|
|
2272
1264
|
case "svg" : {
|
|
2273
1265
|
element = globalThis?.document?.createElementNS("http://www.w3.org/2000/svg", element);
|
|
2274
|
-
// console.log('2')
|
|
2275
1266
|
} break;
|
|
2276
1267
|
default : throw Error("Not supported")
|
|
2277
1268
|
}
|
|
@@ -2314,20 +1305,13 @@ class UIElementCore extends UINode{
|
|
|
2314
1305
|
: globalThis.__Ziko__.__UI__[this.cache.name]=[this];
|
|
2315
1306
|
element && render && this?.render?.();
|
|
2316
1307
|
globalThis.__Ziko__.__UI__.push(this);
|
|
2317
|
-
|
|
2318
|
-
// console.log({props})
|
|
1308
|
+
|
|
2319
1309
|
const parsed_props = parse_props(props);
|
|
2320
|
-
|
|
2321
1310
|
this.parsed_props = parsed_props;
|
|
2322
|
-
|
|
2323
1311
|
this.style(parsed_props.style);
|
|
2324
1312
|
this.setAttr(parsed_props.attrs);
|
|
2325
|
-
|
|
2326
1313
|
const Events = Object.entries(parsed_props.events);
|
|
2327
|
-
|
|
2328
1314
|
Events.forEach(([ev, callback]) => this[ev](callback.bind(this)));
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
1315
|
if(items.length > 0) this.append(...items);
|
|
2332
1316
|
}
|
|
2333
1317
|
get element(){
|
|
@@ -2489,14 +1473,11 @@ function useState(initialValue) {
|
|
|
2489
1473
|
|
|
2490
1474
|
const isStateGetter = (arg) => typeof arg === "function" && arg[STATE_GETTER] === true;
|
|
2491
1475
|
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
return camelCasePattern.test(text);
|
|
2498
|
-
};
|
|
2499
|
-
|
|
1476
|
+
// import {
|
|
1477
|
+
// is_camelcase,
|
|
1478
|
+
// camel2hyphencase
|
|
1479
|
+
// } from '../../../data/string/index.js'
|
|
1480
|
+
|
|
2500
1481
|
function setAttr(name, value) {
|
|
2501
1482
|
if(name instanceof Object){
|
|
2502
1483
|
const [names,values]=[Object.keys(name),Object.values(name)];
|
|
@@ -2516,7 +1497,7 @@ function removeAttr(...names) {
|
|
|
2516
1497
|
return this;
|
|
2517
1498
|
}
|
|
2518
1499
|
function getAttr(name){
|
|
2519
|
-
name = is_camelcase(name) ? camel2hyphencase(name) : name;
|
|
1500
|
+
// name = is_camelcase(name) ? camel2hyphencase(name) : name;
|
|
2520
1501
|
return this.element.attributes[name].value;
|
|
2521
1502
|
}
|
|
2522
1503
|
function setContentEditable(bool = true) {
|
|
@@ -2569,23 +1550,17 @@ function prepend(...ele) {
|
|
|
2569
1550
|
}
|
|
2570
1551
|
function insertAt(index, ...ele) {
|
|
2571
1552
|
const target = this.itemsTarget;
|
|
2572
|
-
|
|
2573
1553
|
if (index >= target.items.length) return this.append(...ele);
|
|
2574
|
-
|
|
2575
1554
|
for (let i = 0; i < ele.length; i++) {
|
|
2576
1555
|
if (["number", "string"].includes(typeof ele[i]))
|
|
2577
1556
|
ele[i] = text(ele[i]);
|
|
2578
|
-
|
|
2579
1557
|
target.element?.insertBefore(
|
|
2580
1558
|
ele[i].element,
|
|
2581
1559
|
target.items[index].element
|
|
2582
1560
|
);
|
|
2583
|
-
|
|
2584
1561
|
target.items.splice(index, 0, ele[i]);
|
|
2585
1562
|
}
|
|
2586
|
-
|
|
2587
1563
|
target.maintain();
|
|
2588
|
-
|
|
2589
1564
|
return this;
|
|
2590
1565
|
}
|
|
2591
1566
|
function remove(...ele) {
|
|
@@ -2608,7 +1583,6 @@ function clear(){
|
|
|
2608
1583
|
function replaceElementWith(new_element){
|
|
2609
1584
|
this.cache.element.replaceWith(new_element);
|
|
2610
1585
|
this.cache.element = new_element;
|
|
2611
|
-
|
|
2612
1586
|
// To do : Dispose Events and States
|
|
2613
1587
|
return this
|
|
2614
1588
|
}
|
|
@@ -2622,14 +1596,9 @@ function before(ui){
|
|
|
2622
1596
|
this.itemsTarget.element?.before(ui);
|
|
2623
1597
|
return this;
|
|
2624
1598
|
}
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
1599
|
async function __addItem__(adder, pusher, ...ele) {
|
|
2630
1600
|
const itemsTarget_el = this.itemsTarget.element;
|
|
2631
1601
|
const itemsTarget = this.itemsTarget;
|
|
2632
|
-
|
|
2633
1602
|
if (this.cache.isFrozzen) {
|
|
2634
1603
|
console.warn("You can't append new item to frozzen element");
|
|
2635
1604
|
return this;
|
|
@@ -2639,7 +1608,6 @@ async function __addItem__(adder, pusher, ...ele) {
|
|
|
2639
1608
|
// Fix Items Latter
|
|
2640
1609
|
if (ele[i] instanceof Function) {
|
|
2641
1610
|
if (isStateGetter(ele[i])) {
|
|
2642
|
-
console.log({s : ele[i]()});
|
|
2643
1611
|
const getter = ele[i]();
|
|
2644
1612
|
ele[i] = text(getter.value);
|
|
2645
1613
|
getter._subscribe(
|
|
@@ -3129,7 +2097,7 @@ function register_swipe_event(
|
|
|
3129
2097
|
};
|
|
3130
2098
|
}
|
|
3131
2099
|
|
|
3132
|
-
|
|
2100
|
+
class UIElement extends UIElementCore{
|
|
3133
2101
|
constructor({element, name ='', type = 'html', render = __Ziko__.__Config__.default.render, props}={}){
|
|
3134
2102
|
super();
|
|
3135
2103
|
this.exp = {
|
|
@@ -3216,9 +2184,9 @@ let UIElement$1 = class UIElement extends UIElementCore{
|
|
|
3216
2184
|
get text(){
|
|
3217
2185
|
return this.element.textContent;
|
|
3218
2186
|
}
|
|
3219
|
-
get isBody(){
|
|
3220
|
-
|
|
3221
|
-
}
|
|
2187
|
+
// get isBody(){
|
|
2188
|
+
// return this.element === globalThis?.document.body;
|
|
2189
|
+
// }
|
|
3222
2190
|
get parent(){
|
|
3223
2191
|
return this.cache.parent;
|
|
3224
2192
|
}
|
|
@@ -3241,7 +2209,7 @@ let UIElement$1 = class UIElement extends UIElementCore{
|
|
|
3241
2209
|
return this.element.getBoundingClientRect().left;
|
|
3242
2210
|
}
|
|
3243
2211
|
|
|
3244
|
-
}
|
|
2212
|
+
}
|
|
3245
2213
|
|
|
3246
2214
|
const is_primitive = (value) => typeof value !== 'object' && typeof value !== 'function' || value === null;
|
|
3247
2215
|
|
|
@@ -3478,874 +2446,154 @@ const tags = new Proxy({}, {
|
|
|
3478
2446
|
if(MathMLTags.includes(tag)) type = 'mathml';
|
|
3479
2447
|
return (...args) => {
|
|
3480
2448
|
if(args.length === 0) {
|
|
3481
|
-
return new UIElement
|
|
2449
|
+
return new UIElement({element : tag, name : tag, type})
|
|
3482
2450
|
}
|
|
3483
2451
|
if(
|
|
3484
2452
|
['string', 'number'].includes(typeof args[0])
|
|
3485
|
-
|| args[0] instanceof UIElement
|
|
2453
|
+
|| args[0] instanceof UIElement
|
|
3486
2454
|
|| isStateGetter(args[0])
|
|
3487
2455
|
|| args[0] instanceof HTMLElement
|
|
3488
|
-
) return new UIElement
|
|
3489
|
-
return new UIElement
|
|
2456
|
+
) return new UIElement({element : tag, name : tag, type}).append(...args);
|
|
2457
|
+
return new UIElement({element : tag, type, props : args.shift()}).append(...args)
|
|
3490
2458
|
}
|
|
3491
2459
|
}
|
|
3492
2460
|
});
|
|
3493
2461
|
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
2462
|
+
const linear = t => t;
|
|
2463
|
+
|
|
2464
|
+
class TimeAnimation {
|
|
2465
|
+
constructor(callback, { ease = linear, step = 50, t0 = 0, start = true, duration = 3000 } = {}) {
|
|
2466
|
+
this.callback = callback;
|
|
2467
|
+
this.state = {
|
|
2468
|
+
isRunning: false,
|
|
2469
|
+
animationId: null,
|
|
2470
|
+
startTime: null,
|
|
2471
|
+
ease,
|
|
2472
|
+
step,
|
|
2473
|
+
// interval: [t0, t1],
|
|
2474
|
+
autoStart: start,
|
|
2475
|
+
duration
|
|
2476
|
+
};
|
|
2477
|
+
|
|
2478
|
+
this.t = 0; // elapsed time
|
|
2479
|
+
this.tx = 0; // normalized [0,1]
|
|
2480
|
+
this.ty = 0; // eased value
|
|
2481
|
+
this.i = 0; // frame index
|
|
2482
|
+
|
|
2483
|
+
if (this.state.autoStart) {
|
|
2484
|
+
this.start();
|
|
3502
2485
|
}
|
|
3503
|
-
|
|
3504
|
-
name,
|
|
3505
|
-
class extends HTMLElement {
|
|
3506
|
-
static get observedAttributes() {
|
|
3507
|
-
return ['style', ...Object.keys(props)];
|
|
3508
|
-
}
|
|
2486
|
+
}
|
|
3509
2487
|
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
this.mask = {
|
|
3515
|
-
...props,
|
|
3516
|
-
// style: { type: Object }
|
|
3517
|
-
};
|
|
3518
|
-
}
|
|
2488
|
+
// ---- private loop handler ----
|
|
2489
|
+
#tick = () => {
|
|
2490
|
+
this.t += this.state.step;
|
|
2491
|
+
this.i++;
|
|
3519
2492
|
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
}
|
|
2493
|
+
this.tx = map$1(this.t, 0, this.state.duration, 0, 1);
|
|
2494
|
+
this.ty = this.state.ease(this.tx);
|
|
3523
2495
|
|
|
3524
|
-
|
|
3525
|
-
this.shadowRoot.innerHTML = '';
|
|
3526
|
-
const item = UI_Constructor(this.props);
|
|
3527
|
-
if(item instanceof Array) item.forEach(n => n.mount(this.shadowRoot));
|
|
3528
|
-
else item.mount(this.shadowRoot);
|
|
3529
|
-
}
|
|
2496
|
+
this.callback(this);
|
|
3530
2497
|
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
});
|
|
3535
|
-
this.render();
|
|
3536
|
-
}
|
|
3537
|
-
}
|
|
3538
|
-
);
|
|
3539
|
-
}
|
|
3540
|
-
|
|
3541
|
-
class UIView extends UIElement$1{
|
|
3542
|
-
constructor(...items){
|
|
3543
|
-
super({element : 'div', name : 'view'});
|
|
3544
|
-
this.append(...items);
|
|
2498
|
+
if (this.t >= this.state.duration) {
|
|
2499
|
+
clearInterval(this.state.animationId);
|
|
2500
|
+
this.state.isRunning = false;
|
|
3545
2501
|
}
|
|
3546
|
-
}
|
|
2502
|
+
};
|
|
3547
2503
|
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
direction == 1
|
|
3558
|
-
? this.style({ flexDirection: "row" })
|
|
3559
|
-
: direction == -1 && this.style({ flexDirection: "row-reverse" });
|
|
3560
|
-
return this;
|
|
3561
|
-
}
|
|
3562
|
-
function map_pos_x(align){
|
|
3563
|
-
let pos = ["flex-start", "center", "flex-end"];
|
|
3564
|
-
if (typeof align === "number") align = pos[align + 1];
|
|
3565
|
-
return align;
|
|
3566
|
-
}
|
|
3567
|
-
function map_pos_y(align){
|
|
3568
|
-
return map_pos_x(-align);
|
|
3569
|
-
}
|
|
3570
|
-
|
|
3571
|
-
class UIFlex extends UIElement$1 {
|
|
3572
|
-
constructor({tag = "div", orientation = "h", order, w = "100%", h = "100%"} = {}) {
|
|
3573
|
-
super({element : tag , name : "Flex"});
|
|
3574
|
-
this.direction = "cols";
|
|
3575
|
-
this.style({ display: "flex" });
|
|
3576
|
-
// this.mount();
|
|
3577
|
-
}
|
|
3578
|
-
isFlex(){
|
|
3579
|
-
return true;
|
|
3580
|
-
}
|
|
3581
|
-
responsify(respBreakPoint, wrap = true) {
|
|
3582
|
-
this.wrap(wrap);
|
|
3583
|
-
if (this.element.clientWidth < respBreakPoint) this.vertical();
|
|
3584
|
-
else this.horizontal();
|
|
2504
|
+
// ---- core runner ----
|
|
2505
|
+
#run(reset = true) {
|
|
2506
|
+
if (!this.state.isRunning) {
|
|
2507
|
+
if (reset) this.reset(false);
|
|
2508
|
+
|
|
2509
|
+
this.state.isRunning = true;
|
|
2510
|
+
this.state.startTime = Date.now();
|
|
2511
|
+
this.state.animationId = setInterval(this.#tick, this.state.step);
|
|
2512
|
+
}
|
|
3585
2513
|
return this;
|
|
3586
2514
|
}
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
2515
|
+
|
|
2516
|
+
// ---- lifecycle methods ----
|
|
2517
|
+
start() {
|
|
2518
|
+
return this.#run(true);
|
|
3590
2519
|
}
|
|
3591
|
-
|
|
3592
|
-
|
|
2520
|
+
|
|
2521
|
+
pause() {
|
|
2522
|
+
if (this.state.isRunning) {
|
|
2523
|
+
clearInterval(this.state.animationId);
|
|
2524
|
+
this.state.isRunning = false;
|
|
2525
|
+
}
|
|
3593
2526
|
return this;
|
|
3594
2527
|
}
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
return this;
|
|
2528
|
+
|
|
2529
|
+
resume() {
|
|
2530
|
+
return this.#run(false);
|
|
3598
2531
|
}
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
2532
|
+
|
|
2533
|
+
stop() {
|
|
2534
|
+
this.pause();
|
|
2535
|
+
this.reset(false);
|
|
3602
2536
|
return this;
|
|
3603
2537
|
}
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
this.
|
|
3607
|
-
|
|
3608
|
-
|
|
2538
|
+
|
|
2539
|
+
reset(restart = true) {
|
|
2540
|
+
this.t = 0;
|
|
2541
|
+
this.tx = 0;
|
|
2542
|
+
this.ty = 0;
|
|
2543
|
+
this.i = 0;
|
|
2544
|
+
|
|
2545
|
+
if (restart) this.start();
|
|
3609
2546
|
return this;
|
|
3610
2547
|
}
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
2548
|
+
}
|
|
2549
|
+
|
|
2550
|
+
// Hook-style factory
|
|
2551
|
+
const animation = (callback, {ease, t0, t1, start, duration} = {}) =>
|
|
2552
|
+
new TimeAnimation(callback, {ease, t0, t1, start, duration});
|
|
2553
|
+
|
|
2554
|
+
class Tick {
|
|
2555
|
+
constructor(fn, ms, count = Infinity, start) {
|
|
2556
|
+
this.ms = ms;
|
|
2557
|
+
this.fn = fn;
|
|
2558
|
+
this.count = count;
|
|
2559
|
+
this.frame = 1;
|
|
2560
|
+
this.id = null;
|
|
2561
|
+
this.running = false;
|
|
2562
|
+
if(start) this.start();
|
|
3614
2563
|
}
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
2564
|
+
|
|
2565
|
+
start() {
|
|
2566
|
+
if (!this.running) {
|
|
2567
|
+
this.running = true;
|
|
2568
|
+
this.frame = 1;
|
|
2569
|
+
this.id = setInterval(() => {
|
|
2570
|
+
if (this.frame > this.count) {
|
|
2571
|
+
this.stop();
|
|
2572
|
+
return;
|
|
2573
|
+
}
|
|
2574
|
+
this.fn.call(null, this);
|
|
2575
|
+
this.frame++;
|
|
2576
|
+
}, this.ms);
|
|
2577
|
+
}
|
|
3622
2578
|
return this;
|
|
3623
2579
|
}
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
}
|
|
2580
|
+
|
|
2581
|
+
stop() {
|
|
2582
|
+
if (this.running) {
|
|
2583
|
+
this.running = false;
|
|
2584
|
+
clearInterval(this.id);
|
|
2585
|
+
this.id = null;
|
|
2586
|
+
}
|
|
3631
2587
|
return this;
|
|
3632
2588
|
}
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
this.
|
|
3636
|
-
return this;
|
|
2589
|
+
|
|
2590
|
+
isRunning() {
|
|
2591
|
+
return this.running;
|
|
3637
2592
|
}
|
|
3638
2593
|
}
|
|
3639
2594
|
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
if(typeof UIElement[0]==="string"){
|
|
3643
|
-
tag=UIElement[0];
|
|
3644
|
-
UIElement.pop();
|
|
3645
|
-
}
|
|
3646
|
-
return new UIFlex(tag).append(...UIElement);
|
|
3647
|
-
};
|
|
3648
|
-
|
|
3649
|
-
class UIElement extends UIElementCore{
|
|
3650
|
-
constructor({element, name, type, render}){
|
|
3651
|
-
super({element, name, type, render});
|
|
3652
|
-
}
|
|
3653
|
-
}
|
|
3654
|
-
|
|
3655
|
-
class UISuspense extends UIElement{
|
|
3656
|
-
constructor(fallback_ui, callback){
|
|
3657
|
-
super({element : "div", name : "suspense"});
|
|
3658
|
-
this.setAttr({
|
|
3659
|
-
dataTemp : "suspense"
|
|
3660
|
-
});
|
|
3661
|
-
this.fallback_ui = fallback_ui;
|
|
3662
|
-
this.append(fallback_ui);
|
|
3663
|
-
(async ()=>{
|
|
3664
|
-
try{
|
|
3665
|
-
const ui = await callback();
|
|
3666
|
-
fallback_ui.unmount();
|
|
3667
|
-
this.append(ui);
|
|
3668
|
-
}
|
|
3669
|
-
catch(error){
|
|
3670
|
-
console.log({error});
|
|
3671
|
-
}
|
|
3672
|
-
})();
|
|
3673
|
-
}
|
|
3674
|
-
}
|
|
3675
|
-
|
|
3676
|
-
const Suspense = (fallback_ui, callback) => new UISuspense(fallback_ui, callback);
|
|
3677
|
-
|
|
3678
|
-
class UISwap extends UIElement$1 {
|
|
3679
|
-
#DISPLAYS_MAP = new WeakMap()
|
|
3680
|
-
constructor({ activeIndex = 0 } = {}, ...items) {
|
|
3681
|
-
super({ element: 'div' });
|
|
3682
|
-
this.style({ display: 'contents' });
|
|
3683
|
-
|
|
3684
|
-
this.states = {
|
|
3685
|
-
activeIndex
|
|
3686
|
-
};
|
|
3687
|
-
|
|
3688
|
-
this.append(...items);
|
|
3689
|
-
requestAnimationFrame(() => {
|
|
3690
|
-
this.render();
|
|
3691
|
-
});
|
|
3692
|
-
}
|
|
3693
|
-
get activeItem(){
|
|
3694
|
-
return this.items[this.states.activeIndex]
|
|
3695
|
-
}
|
|
3696
|
-
render() {
|
|
3697
|
-
this.items.forEach((n, i) => {
|
|
3698
|
-
|
|
3699
|
-
const initialDisplay = getComputedStyle(n.element).display;
|
|
3700
|
-
this.#DISPLAYS_MAP.set(n, initialDisplay);
|
|
3701
|
-
|
|
3702
|
-
if (i !== this.states.activeIndex) {
|
|
3703
|
-
n.style({ display: 'none' });
|
|
3704
|
-
}
|
|
3705
|
-
});
|
|
3706
|
-
}
|
|
3707
|
-
get DS(){
|
|
3708
|
-
return this.#DISPLAYS_MAP
|
|
3709
|
-
}
|
|
3710
|
-
next(n = 1) {
|
|
3711
|
-
return this.activate(this.states.activeIndex + n);
|
|
3712
|
-
}
|
|
3713
|
-
previous(n = 1) {
|
|
3714
|
-
return this.activate(this.states.activeIndex - n);
|
|
3715
|
-
}
|
|
3716
|
-
activate(index) {
|
|
3717
|
-
if (!this.items.length) return this;
|
|
3718
|
-
|
|
3719
|
-
const currentItem = this.items.at(this.states.activeIndex);
|
|
3720
|
-
|
|
3721
|
-
if (currentItem) {
|
|
3722
|
-
currentItem.style({ display: 'none' });
|
|
3723
|
-
}
|
|
3724
|
-
|
|
3725
|
-
const len = this.items.length;
|
|
3726
|
-
this.states.activeIndex = ((index % len) + len) % len;
|
|
3727
|
-
|
|
3728
|
-
const activeItem = this.items.at(this.states.activeIndex);
|
|
3729
|
-
if (activeItem) {
|
|
3730
|
-
const restoredDisplay = this.#DISPLAYS_MAP.get(activeItem) || 'block';
|
|
3731
|
-
activeItem.style({ display: restoredDisplay === 'none' ? 'block' : restoredDisplay });
|
|
3732
|
-
}
|
|
3733
|
-
|
|
3734
|
-
return this;
|
|
3735
|
-
}
|
|
3736
|
-
}
|
|
3737
|
-
|
|
3738
|
-
const Swap = call_with_optional_props(UISwap);
|
|
3739
|
-
|
|
3740
|
-
class UIFragment extends UIElement$1{
|
|
3741
|
-
constructor(...items){
|
|
3742
|
-
super({ element : document.createDocumentFragment()});
|
|
3743
|
-
this.append(...items);
|
|
3744
|
-
}
|
|
3745
|
-
isFragment(){
|
|
3746
|
-
return true
|
|
3747
|
-
}
|
|
3748
|
-
}
|
|
3749
|
-
|
|
3750
|
-
const Fragment = (...items) => new UIFragment(...items);
|
|
3751
|
-
|
|
3752
|
-
class UIFor extends UIFragment{
|
|
3753
|
-
constructor({each, fallback, mapFn = () => {}} = {}){
|
|
3754
|
-
super();
|
|
3755
|
-
this.config = {
|
|
3756
|
-
each,
|
|
3757
|
-
fallback,
|
|
3758
|
-
mapFn
|
|
3759
|
-
};
|
|
3760
|
-
this.append(
|
|
3761
|
-
...this.config.each.map((n,i) => this.config.mapFn(n, i))
|
|
3762
|
-
);
|
|
3763
|
-
}
|
|
3764
|
-
}
|
|
3765
|
-
|
|
3766
|
-
const For = ({each, fallback, mapFn} = {}) => new UIFor({each, fallback, mapFn});
|
|
3767
|
-
|
|
3768
|
-
class UISwitch extends UIElement$1{
|
|
3769
|
-
constructor(key, cases){
|
|
3770
|
-
super();
|
|
3771
|
-
this.key = key;
|
|
3772
|
-
this.cases = cases;
|
|
3773
|
-
this.init();
|
|
3774
|
-
}
|
|
3775
|
-
init(){
|
|
3776
|
-
Object.values(this.cases).filter(n=>n != this.current).forEach(n=>n.unmount());
|
|
3777
|
-
super.init(this.current.element);
|
|
3778
|
-
}
|
|
3779
|
-
get current(){
|
|
3780
|
-
const matched = Object.keys(this.cases).find(n => n == this.key) ?? 'default';
|
|
3781
|
-
return this.cases[matched]
|
|
3782
|
-
}
|
|
3783
|
-
updateKey(key){
|
|
3784
|
-
this.key = key;
|
|
3785
|
-
this.replaceElementWith(this.current.element);
|
|
3786
|
-
// this.cache.element.replaceWith(this.current.element)
|
|
3787
|
-
// this.cache.element = this.current.element;
|
|
3788
|
-
return this;
|
|
3789
|
-
}
|
|
3790
|
-
|
|
3791
|
-
}
|
|
3792
|
-
|
|
3793
|
-
const Switch=({key, cases})=> new UISwitch(key, cases);
|
|
3794
|
-
|
|
3795
|
-
// export const Switch=({key, cases}) => {
|
|
3796
|
-
// const matched = Object.keys(cases).find(n => n == key) ?? 'default';
|
|
3797
|
-
// return this.cases[matched]()
|
|
3798
|
-
// }
|
|
3799
|
-
|
|
3800
|
-
class UIHTMLWrapper extends UIElement$1 {
|
|
3801
|
-
constructor(content){
|
|
3802
|
-
super({element : 'div', name : 'html_wrappper'});
|
|
3803
|
-
this.element.append(html2dom(content));
|
|
3804
|
-
this.style({
|
|
3805
|
-
display : 'contents'
|
|
3806
|
-
});
|
|
3807
|
-
}
|
|
3808
|
-
}
|
|
3809
|
-
|
|
3810
|
-
function html2dom(htmlString) {
|
|
3811
|
-
if(globalThis?.DOMParser){
|
|
3812
|
-
const parser = new DOMParser();
|
|
3813
|
-
const doc = parser.parseFromString(`<div>${htmlString}</div>`, 'text/html');
|
|
3814
|
-
doc.body.firstChild.style.display = "contents";
|
|
3815
|
-
return doc.body.firstChild;
|
|
3816
|
-
}
|
|
3817
|
-
}
|
|
3818
|
-
|
|
3819
|
-
const HTMLWrapper = (content) => new UIHTMLWrapper(content);
|
|
3820
|
-
|
|
3821
|
-
class UISVGWrapper extends UIElement$1 {
|
|
3822
|
-
constructor(content){
|
|
3823
|
-
super({element : 'div', name : 'html_wrappper'});
|
|
3824
|
-
this.element.append(svg2dom(content));
|
|
3825
|
-
this.style({
|
|
3826
|
-
display : 'contents'
|
|
3827
|
-
});
|
|
3828
|
-
}
|
|
3829
|
-
}
|
|
3830
|
-
|
|
3831
|
-
function svg2dom(svgString) {
|
|
3832
|
-
if (typeof DOMParser !== "undefined") {
|
|
3833
|
-
const parser = new DOMParser();
|
|
3834
|
-
const doc = parser.parseFromString(svgString.trim(), "image/svg+xml");
|
|
3835
|
-
const svg = doc.documentElement;
|
|
3836
|
-
|
|
3837
|
-
if (svg.nodeName === "parsererror") {
|
|
3838
|
-
throw new Error("Invalid SVG string");
|
|
3839
|
-
}
|
|
3840
|
-
if(svg.hasAttribute('xmlns')) return svg
|
|
3841
|
-
// TO Fix ...
|
|
3842
|
-
const {children, attributes} = svg;
|
|
3843
|
-
const element = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
3844
|
-
for(let {name, value} of attributes){
|
|
3845
|
-
element.setAttribute(name, value);
|
|
3846
|
-
}
|
|
3847
|
-
element.append(...children);
|
|
3848
|
-
|
|
3849
|
-
globalThis.svg = svg;
|
|
3850
|
-
globalThis.children = children;
|
|
3851
|
-
globalThis.attributes = attributes;
|
|
3852
|
-
globalThis.element = element;
|
|
3853
|
-
return element;
|
|
3854
|
-
}
|
|
3855
|
-
throw new Error("DOMParser is not available in this environment");
|
|
3856
|
-
}
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
const SVGWrapper = (content) => new UISVGWrapper(content);
|
|
3861
|
-
|
|
3862
|
-
class UICanvas extends UIElement$1{
|
|
3863
|
-
constructor(w,h){
|
|
3864
|
-
super("canvas","canvas");
|
|
3865
|
-
this.ctx = this.element?.getContext("2d");
|
|
3866
|
-
this.style({
|
|
3867
|
-
border:"1px red solid",
|
|
3868
|
-
});
|
|
3869
|
-
this.transformMatrix = new Matrix([
|
|
3870
|
-
[1,0,0],
|
|
3871
|
-
[0,1,0],
|
|
3872
|
-
[0,0,1]
|
|
3873
|
-
]);
|
|
3874
|
-
this.axisMatrix = new Matrix([
|
|
3875
|
-
[-10,-10],
|
|
3876
|
-
[10,10]
|
|
3877
|
-
]);
|
|
3878
|
-
// setTimeout(()=>this.resize(w,h),0);
|
|
3879
|
-
requestAnimationFrame(()=>this.resize(w,h),0);
|
|
3880
|
-
this.on("sizeupdated",()=>this.adjust());
|
|
3881
|
-
}
|
|
3882
|
-
get Xmin(){
|
|
3883
|
-
return this.axisMatrix[0][0];
|
|
3884
|
-
}
|
|
3885
|
-
get Ymin(){
|
|
3886
|
-
return this.axisMatrix[0][1];
|
|
3887
|
-
}
|
|
3888
|
-
get Xmax(){
|
|
3889
|
-
return this.axisMatrix[1][0];
|
|
3890
|
-
}
|
|
3891
|
-
get Ymax(){
|
|
3892
|
-
return this.axisMatrix[1][1];
|
|
3893
|
-
}
|
|
3894
|
-
get ImageData(){
|
|
3895
|
-
return this.ctx.getImageData(0,0,c.Width,c.Height);
|
|
3896
|
-
}
|
|
3897
|
-
draw(all=true){
|
|
3898
|
-
if(all){
|
|
3899
|
-
this.clear();
|
|
3900
|
-
this.items.forEach(element => {
|
|
3901
|
-
element.parent=this;
|
|
3902
|
-
element.draw(this.ctx);
|
|
3903
|
-
});
|
|
3904
|
-
}
|
|
3905
|
-
else {
|
|
3906
|
-
this.items.at(-1).parent=this;
|
|
3907
|
-
this.items.at(-1).draw(this.ctx);
|
|
3908
|
-
}
|
|
3909
|
-
this.maintain();
|
|
3910
|
-
return this;
|
|
3911
|
-
}
|
|
3912
|
-
applyTransformMatrix(){
|
|
3913
|
-
this.ctx.setTransform(
|
|
3914
|
-
this.transformMatrix[0][0],
|
|
3915
|
-
this.transformMatrix[1][0],
|
|
3916
|
-
this.transformMatrix[0][1],
|
|
3917
|
-
this.transformMatrix[1][1],
|
|
3918
|
-
this.transformMatrix[0][2],
|
|
3919
|
-
this.transformMatrix[1][2],
|
|
3920
|
-
);
|
|
3921
|
-
return this;
|
|
3922
|
-
}
|
|
3923
|
-
resize(w,h){
|
|
3924
|
-
this.size(w,h);
|
|
3925
|
-
this.lineWidth();
|
|
3926
|
-
this.view(this.axisMatrix[0][0], this.axisMatrix[0][1], this.axisMatrix[1][0], this.axisMatrix[1][1]);
|
|
3927
|
-
this.emit("sizeupdated");
|
|
3928
|
-
return this;
|
|
3929
|
-
}
|
|
3930
|
-
adjust(){
|
|
3931
|
-
this.element.width =this.element?.getBoundingClientRect().width;
|
|
3932
|
-
this.element.height =this.element?.getBoundingClientRect().height;
|
|
3933
|
-
this.view(this.axisMatrix[0][0], this.axisMatrix[0][1], this.axisMatrix[1][0], this.axisMatrix[1][1]);
|
|
3934
|
-
return this;
|
|
3935
|
-
}
|
|
3936
|
-
view(xMin,yMin,xMax,yMax){
|
|
3937
|
-
this.transformMatrix[0][0]=this.width/(xMax-xMin); // scaleX
|
|
3938
|
-
this.transformMatrix[1][1]=-this.height/(yMax-yMin); // scaleY
|
|
3939
|
-
this.transformMatrix[0][2]=this.width/2;
|
|
3940
|
-
this.transformMatrix[1][2]=this.height/2;
|
|
3941
|
-
this.axisMatrix=new Matrix([
|
|
3942
|
-
[xMin,yMin],
|
|
3943
|
-
[xMax,yMax]
|
|
3944
|
-
]);
|
|
3945
|
-
|
|
3946
|
-
this.applyTransformMatrix();
|
|
3947
|
-
this.clear();
|
|
3948
|
-
this.lineWidth(1);
|
|
3949
|
-
this.draw();
|
|
3950
|
-
return this;
|
|
3951
|
-
}
|
|
3952
|
-
reset(){
|
|
3953
|
-
this.ctx.setTransform(1,0,0,0,0,0);
|
|
3954
|
-
return this;
|
|
3955
|
-
}
|
|
3956
|
-
append(element){
|
|
3957
|
-
this.items.push(element);
|
|
3958
|
-
this.draw(false);
|
|
3959
|
-
return this;
|
|
3960
|
-
}
|
|
3961
|
-
background(color){
|
|
3962
|
-
this.ctx.fillStyle = color;
|
|
3963
|
-
this.ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
3964
|
-
this.ctx.fillRect(0, 0, this.width, this.height);
|
|
3965
|
-
this.applyTransformMatrix();
|
|
3966
|
-
this.draw();
|
|
3967
|
-
}
|
|
3968
|
-
lineWidth(w){
|
|
3969
|
-
this.ctx.lineWidth=w/this.transformMatrix[0][0];
|
|
3970
|
-
return this
|
|
3971
|
-
}
|
|
3972
|
-
getImageData(x=0,y=0,w=this.width,h=this.height){
|
|
3973
|
-
return this.ctx.getImageData(x,y,w,h);
|
|
3974
|
-
}
|
|
3975
|
-
clear(){
|
|
3976
|
-
this.ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
3977
|
-
this.ctx.clearRect(0, 0, this.width, this.height);
|
|
3978
|
-
this.applyTransformMatrix();
|
|
3979
|
-
return this;
|
|
3980
|
-
}
|
|
3981
|
-
clone(){
|
|
3982
|
-
console.log(this.width);
|
|
3983
|
-
const canvas=new UICanvas();
|
|
3984
|
-
canvas.items=this.items;
|
|
3985
|
-
canvas.transformMatrix=this.transformMatrix;
|
|
3986
|
-
canvas.axisMatrix=this.axisMatrix;
|
|
3987
|
-
Object.assign(canvas.cache,{...this.cache});
|
|
3988
|
-
//waitForUIElm(this)
|
|
3989
|
-
//console.log(element)
|
|
3990
|
-
this.size(this.element.style.width,this.element.style.width);
|
|
3991
|
-
this.applyTransformMatrix();
|
|
3992
|
-
this.draw();
|
|
3993
|
-
this.adjust();
|
|
3994
|
-
return canvas;
|
|
3995
|
-
}
|
|
3996
|
-
toImage() {
|
|
3997
|
-
this.img = document?.createElement("img");
|
|
3998
|
-
this.img.src = this.element?.toDataURL("image/png");
|
|
3999
|
-
return this;
|
|
4000
|
-
}
|
|
4001
|
-
toBlob() {
|
|
4002
|
-
var canvas = this.element;
|
|
4003
|
-
canvas.toBlob(function (blob) {
|
|
4004
|
-
var newImg = document?.createElement("img"),
|
|
4005
|
-
url = URL.createObjectURL(blob);
|
|
4006
|
-
newImg.onload = function () {
|
|
4007
|
-
URL.revokeObjectURL(url);
|
|
4008
|
-
};
|
|
4009
|
-
newImg.src = url;
|
|
4010
|
-
console.log(newImg);
|
|
4011
|
-
});
|
|
4012
|
-
}
|
|
4013
|
-
zoomIn(){
|
|
4014
|
-
|
|
4015
|
-
}
|
|
4016
|
-
zoomOut(){
|
|
4017
|
-
|
|
4018
|
-
}
|
|
4019
|
-
undo(n){
|
|
4020
|
-
|
|
4021
|
-
}
|
|
4022
|
-
redo(n){
|
|
4023
|
-
|
|
4024
|
-
}
|
|
4025
|
-
stream(){
|
|
4026
|
-
|
|
4027
|
-
}
|
|
4028
|
-
}
|
|
4029
|
-
|
|
4030
|
-
const Canvas=(w,h)=>new UICanvas(w,h);
|
|
4031
|
-
|
|
4032
|
-
class UISvg extends UIElement$1 {
|
|
4033
|
-
constructor(w=360,h=300) {
|
|
4034
|
-
super("svg","svg");
|
|
4035
|
-
//this.cache={};
|
|
4036
|
-
// this.setAttr("width",w);
|
|
4037
|
-
// this.setAttr("height",h);
|
|
4038
|
-
// this.setAttr({
|
|
4039
|
-
// width : w,
|
|
4040
|
-
// height : h
|
|
4041
|
-
// })
|
|
4042
|
-
this.style({border:"1px black solid"});
|
|
4043
|
-
//this.view(-w/2,-h/2,w/2,h/2);
|
|
4044
|
-
this.size(w, h);
|
|
4045
|
-
this.view(-10,-10,10,10);
|
|
4046
|
-
}
|
|
4047
|
-
size(w, h){
|
|
4048
|
-
this.setAttr({
|
|
4049
|
-
width : w,
|
|
4050
|
-
height : h
|
|
4051
|
-
});
|
|
4052
|
-
return this
|
|
4053
|
-
}
|
|
4054
|
-
view(x1,y1,x2,y2){
|
|
4055
|
-
let width=Math.abs(x2-x1);
|
|
4056
|
-
let height=Math.abs(y2-y1);
|
|
4057
|
-
this.setAttr("viewBox",[x1,y1,width,height].join(" "));
|
|
4058
|
-
this.st.scaleY(-1);
|
|
4059
|
-
return this;
|
|
4060
|
-
}
|
|
4061
|
-
add(...svgElement){
|
|
4062
|
-
for(let i=0;i<svgElement.length;i++){
|
|
4063
|
-
this.element.append(svgElement[i].element);
|
|
4064
|
-
this.items.push(svgElement[i]);
|
|
4065
|
-
}
|
|
4066
|
-
this.maintain();
|
|
4067
|
-
return this;
|
|
4068
|
-
}
|
|
4069
|
-
remove(...svgElement){
|
|
4070
|
-
for(let i=0;i<svgElement.length;i++){
|
|
4071
|
-
this.element?.removeChild(svgElement[i].element);
|
|
4072
|
-
this.items=this.items.filter(n=>!svgElement);
|
|
4073
|
-
}
|
|
4074
|
-
this.maintain();
|
|
4075
|
-
return this;
|
|
4076
|
-
}
|
|
4077
|
-
mask(){
|
|
4078
|
-
|
|
4079
|
-
}
|
|
4080
|
-
toString(){
|
|
4081
|
-
return (new XMLSerializer()).serializeToString(this.element);
|
|
4082
|
-
}
|
|
4083
|
-
btoa(){
|
|
4084
|
-
return btoa(this.toString())
|
|
4085
|
-
}
|
|
4086
|
-
toImg(){
|
|
4087
|
-
return 'data:image/svg+xml;base64,'+this.btoa()
|
|
4088
|
-
}
|
|
4089
|
-
toImg2(){
|
|
4090
|
-
return "data:image/svg+xml;charset=utf8,"+this.toString().replaceAll("<","%3C").replaceAll(">","%3E").replaceAll("#","%23").replaceAll('"',"'");
|
|
4091
|
-
}
|
|
4092
|
-
|
|
4093
|
-
}
|
|
4094
|
-
|
|
4095
|
-
const Svg =(w,h)=>new UISvg(w,h);
|
|
4096
|
-
|
|
4097
|
-
const { PI, sqrt: sqrt$1, cos: cos$2, sin: sin$2, acos, pow } = Math;
|
|
4098
|
-
|
|
4099
|
-
const linear = t => t;
|
|
4100
|
-
|
|
4101
|
-
// --- Sin ---
|
|
4102
|
-
const in_sin = t => 1 - cos$2((t * PI) / 2);
|
|
4103
|
-
const out_sin = t => sin$2((t * PI) / 2);
|
|
4104
|
-
const in_out_sin = t => -(cos$2(PI * t) - 1) / 2;
|
|
4105
|
-
|
|
4106
|
-
// --- Quad ---
|
|
4107
|
-
const in_quad = t => t ** 2;
|
|
4108
|
-
const out_quad = t => 1 - (1 - t) ** 2;
|
|
4109
|
-
const in_out_quad = t =>
|
|
4110
|
-
t < 0.5 ? 2 * (t ** 2) : 1 - (-2 * t + 2) ** 2 / 2;
|
|
4111
|
-
|
|
4112
|
-
// --- Cubic ---
|
|
4113
|
-
const in_cubic = t => t ** 3;
|
|
4114
|
-
const out_cubic = t => 1 - (1 - t) ** 3;
|
|
4115
|
-
const in_out_cubic = t =>
|
|
4116
|
-
t < 0.5 ? 4 * (t ** 3) : 1 - (-2 * t + 2) ** 3 / 2;
|
|
4117
|
-
|
|
4118
|
-
// --- Quart ---
|
|
4119
|
-
const in_quart = t => t ** 4;
|
|
4120
|
-
const out_quart = t => 1 - (1 - t) ** 4;
|
|
4121
|
-
const in_out_quart = t =>
|
|
4122
|
-
t < 0.5 ? 8 * (t ** 4) : 1 - (-2 * t + 2) ** 4 / 2;
|
|
4123
|
-
|
|
4124
|
-
// --- Quint ---
|
|
4125
|
-
const in_quint = t => t ** 5;
|
|
4126
|
-
const out_quint = t => 1 - (1 - t) ** 5;
|
|
4127
|
-
const in_out_quint = t =>
|
|
4128
|
-
t < 0.5 ? 16 * (t ** 5) : 1 - (-2 * t + 2) ** 5 / 2;
|
|
4129
|
-
|
|
4130
|
-
// --- Expo ---
|
|
4131
|
-
const in_expo = t => (t === 0 ? 0 : 2 ** (10 * t - 10));
|
|
4132
|
-
const out_expo = t => (t === 1 ? 1 : 1 - 2 ** (-10 * t));
|
|
4133
|
-
const in_out_expo = t =>
|
|
4134
|
-
t === 0
|
|
4135
|
-
? 0
|
|
4136
|
-
: t === 1
|
|
4137
|
-
? 1
|
|
4138
|
-
: t < 0.5
|
|
4139
|
-
? 2 ** (20 * t - 10) / 2
|
|
4140
|
-
: (2 - 2 ** (-20 * t + 10)) / 2;
|
|
4141
|
-
|
|
4142
|
-
// --- Circ ---
|
|
4143
|
-
const in_circ = t => 1 - sqrt$1(1 - t ** 2);
|
|
4144
|
-
const out_circ = t => sqrt$1(1 - (t - 1) ** 2);
|
|
4145
|
-
const in_out_circ = t =>
|
|
4146
|
-
t < 0.5
|
|
4147
|
-
? (1 - sqrt$1(1 - (2 * t) ** 2)) / 2
|
|
4148
|
-
: (sqrt$1(1 - (-2 * t + 2) ** 2) + 1) / 2;
|
|
4149
|
-
|
|
4150
|
-
// --- Arc ---
|
|
4151
|
-
const arc = t => 1 - sin$2(acos(t));
|
|
4152
|
-
|
|
4153
|
-
// --- Back ---
|
|
4154
|
-
const back = (t, x = 1) => (t ** 2) * ((x + 1) * t - x);
|
|
4155
|
-
|
|
4156
|
-
// --- Elastic ---
|
|
4157
|
-
const elastic = t =>
|
|
4158
|
-
-2 * pow(2, 10 * (t - 1)) * cos$2((20 * PI * t) / 3 * t);
|
|
4159
|
-
|
|
4160
|
-
// --- Back variations ---
|
|
4161
|
-
const in_back = (t, c1 = 1.70158, c3 = c1 + 1) =>
|
|
4162
|
-
c3 * pow(t, 3) - c1 * (t ** 2);
|
|
4163
|
-
|
|
4164
|
-
const out_back = (t, c1 = 1.70158, c3 = c1 + 1) =>
|
|
4165
|
-
1 + c3 * pow(t - 1, 3) + c1 * pow(t - 1, 2);
|
|
4166
|
-
|
|
4167
|
-
const in_out_back = (t, c1 = 1.70158, c2 = c1 * 1.525) =>
|
|
4168
|
-
t < 0.5
|
|
4169
|
-
? (pow(2 * t, 2) * ((c2 + 1) * 2 * t - c2)) / 2
|
|
4170
|
-
: (pow(2 * t - 2, 2) * ((c2 + 1) * (t * 2 - 2) + c2) + 2) / 2;
|
|
4171
|
-
|
|
4172
|
-
// --- Elastic variations ---
|
|
4173
|
-
const in_elastic = (t, c4 = (2 * PI) / 3) =>
|
|
4174
|
-
t === 0
|
|
4175
|
-
? 0
|
|
4176
|
-
: t === 1
|
|
4177
|
-
? 1
|
|
4178
|
-
: -pow(2, 10 * t - 10) * sin$2((t * 10 - 10.75) * c4);
|
|
4179
|
-
|
|
4180
|
-
const out_elastic = (t, c4 = (2 * PI) / 3) =>
|
|
4181
|
-
t === 0
|
|
4182
|
-
? 0
|
|
4183
|
-
: t === 1
|
|
4184
|
-
? 1
|
|
4185
|
-
: pow(2, -10 * t) * sin$2((t * 10 - 0.75) * c4) + 1;
|
|
4186
|
-
|
|
4187
|
-
const in_out_elastic = (t, c5 = (2 * PI) / 4.5) =>
|
|
4188
|
-
t === 0
|
|
4189
|
-
? 0
|
|
4190
|
-
: t === 1
|
|
4191
|
-
? 1
|
|
4192
|
-
: t < 0.5
|
|
4193
|
-
? -(pow(2, 20 * t - 10) * sin$2((20 * t - 11.125) * c5)) / 2
|
|
4194
|
-
: (pow(2, -20 * t + 10) * sin$2((20 * t - 11.125) * c5)) / 2 + 1;
|
|
4195
|
-
|
|
4196
|
-
// --- Bounce ---
|
|
4197
|
-
const in_bounce = (t, n1 = 7.5625, d1 = 2.75) =>
|
|
4198
|
-
1 - out_bounce(1 - t, n1, d1);
|
|
4199
|
-
|
|
4200
|
-
const out_bounce = (t, n1 = 7.5625, d1 = 2.75) => {
|
|
4201
|
-
if (t < 1 / d1) return n1 * t * t;
|
|
4202
|
-
if (t < 2 / d1) return n1 * (t -= 1.5 / d1) * t + 0.75;
|
|
4203
|
-
if (t < 2.5 / d1) return n1 * (t -= 2.25 / d1) * t + 0.9375;
|
|
4204
|
-
return n1 * (t -= 2.625 / d1) * t + 0.984375;
|
|
4205
|
-
};
|
|
4206
|
-
|
|
4207
|
-
const in_out_bounce = (t, n1 = 7.5625, d1 = 2.75) =>
|
|
4208
|
-
t < 0.5
|
|
4209
|
-
? out_bounce(1 - 2 * t, n1, d1) / 2
|
|
4210
|
-
: out_bounce(2 * t - 1, n1, d1) / 2;
|
|
4211
|
-
|
|
4212
|
-
// --- Step / Discrete ---
|
|
4213
|
-
const step = (t, steps = 5) => Math.floor(t * steps) / steps;
|
|
4214
|
-
const discret = (t, segments = 5) => Math.ceil(t * segments) / segments;
|
|
4215
|
-
|
|
4216
|
-
class TimeAnimation {
|
|
4217
|
-
constructor(callback, { ease = linear, step = 50, t0 = 0, start = true, duration = 3000 } = {}) {
|
|
4218
|
-
this.callback = callback;
|
|
4219
|
-
this.state = {
|
|
4220
|
-
isRunning: false,
|
|
4221
|
-
animationId: null,
|
|
4222
|
-
startTime: null,
|
|
4223
|
-
ease,
|
|
4224
|
-
step,
|
|
4225
|
-
// interval: [t0, t1],
|
|
4226
|
-
autoStart: start,
|
|
4227
|
-
duration
|
|
4228
|
-
};
|
|
4229
|
-
|
|
4230
|
-
this.t = 0; // elapsed time
|
|
4231
|
-
this.tx = 0; // normalized [0,1]
|
|
4232
|
-
this.ty = 0; // eased value
|
|
4233
|
-
this.i = 0; // frame index
|
|
4234
|
-
|
|
4235
|
-
if (this.state.autoStart) {
|
|
4236
|
-
this.start();
|
|
4237
|
-
}
|
|
4238
|
-
}
|
|
4239
|
-
|
|
4240
|
-
// ---- private loop handler ----
|
|
4241
|
-
#tick = () => {
|
|
4242
|
-
this.t += this.state.step;
|
|
4243
|
-
this.i++;
|
|
4244
|
-
|
|
4245
|
-
this.tx = map$1(this.t, 0, this.state.duration, 0, 1);
|
|
4246
|
-
this.ty = this.state.ease(this.tx);
|
|
4247
|
-
|
|
4248
|
-
this.callback(this);
|
|
4249
|
-
|
|
4250
|
-
if (this.t >= this.state.duration) {
|
|
4251
|
-
clearInterval(this.state.animationId);
|
|
4252
|
-
this.state.isRunning = false;
|
|
4253
|
-
}
|
|
4254
|
-
};
|
|
4255
|
-
|
|
4256
|
-
// ---- core runner ----
|
|
4257
|
-
#run(reset = true) {
|
|
4258
|
-
if (!this.state.isRunning) {
|
|
4259
|
-
if (reset) this.reset(false);
|
|
4260
|
-
|
|
4261
|
-
this.state.isRunning = true;
|
|
4262
|
-
this.state.startTime = Date.now();
|
|
4263
|
-
this.state.animationId = setInterval(this.#tick, this.state.step);
|
|
4264
|
-
}
|
|
4265
|
-
return this;
|
|
4266
|
-
}
|
|
4267
|
-
|
|
4268
|
-
// ---- lifecycle methods ----
|
|
4269
|
-
start() {
|
|
4270
|
-
return this.#run(true);
|
|
4271
|
-
}
|
|
4272
|
-
|
|
4273
|
-
pause() {
|
|
4274
|
-
if (this.state.isRunning) {
|
|
4275
|
-
clearInterval(this.state.animationId);
|
|
4276
|
-
this.state.isRunning = false;
|
|
4277
|
-
}
|
|
4278
|
-
return this;
|
|
4279
|
-
}
|
|
4280
|
-
|
|
4281
|
-
resume() {
|
|
4282
|
-
return this.#run(false);
|
|
4283
|
-
}
|
|
4284
|
-
|
|
4285
|
-
stop() {
|
|
4286
|
-
this.pause();
|
|
4287
|
-
this.reset(false);
|
|
4288
|
-
return this;
|
|
4289
|
-
}
|
|
4290
|
-
|
|
4291
|
-
reset(restart = true) {
|
|
4292
|
-
this.t = 0;
|
|
4293
|
-
this.tx = 0;
|
|
4294
|
-
this.ty = 0;
|
|
4295
|
-
this.i = 0;
|
|
4296
|
-
|
|
4297
|
-
if (restart) this.start();
|
|
4298
|
-
return this;
|
|
4299
|
-
}
|
|
4300
|
-
}
|
|
4301
|
-
|
|
4302
|
-
// Hook-style factory
|
|
4303
|
-
const animation = (callback, {ease, t0, t1, start, duration} = {}) =>
|
|
4304
|
-
new TimeAnimation(callback, {ease, t0, t1, start, duration});
|
|
4305
|
-
|
|
4306
|
-
class Tick {
|
|
4307
|
-
constructor(fn, ms, count = Infinity, start) {
|
|
4308
|
-
this.ms = ms;
|
|
4309
|
-
this.fn = fn;
|
|
4310
|
-
this.count = count;
|
|
4311
|
-
this.frame = 1;
|
|
4312
|
-
this.id = null;
|
|
4313
|
-
this.running = false;
|
|
4314
|
-
if(start) this.start();
|
|
4315
|
-
}
|
|
4316
|
-
|
|
4317
|
-
start() {
|
|
4318
|
-
if (!this.running) {
|
|
4319
|
-
this.running = true;
|
|
4320
|
-
this.frame = 1;
|
|
4321
|
-
this.id = setInterval(() => {
|
|
4322
|
-
if (this.frame > this.count) {
|
|
4323
|
-
this.stop();
|
|
4324
|
-
return;
|
|
4325
|
-
}
|
|
4326
|
-
this.fn.call(null, this);
|
|
4327
|
-
this.frame++;
|
|
4328
|
-
}, this.ms);
|
|
4329
|
-
}
|
|
4330
|
-
return this;
|
|
4331
|
-
}
|
|
4332
|
-
|
|
4333
|
-
stop() {
|
|
4334
|
-
if (this.running) {
|
|
4335
|
-
this.running = false;
|
|
4336
|
-
clearInterval(this.id);
|
|
4337
|
-
this.id = null;
|
|
4338
|
-
}
|
|
4339
|
-
return this;
|
|
4340
|
-
}
|
|
4341
|
-
|
|
4342
|
-
isRunning() {
|
|
4343
|
-
return this.running;
|
|
4344
|
-
}
|
|
4345
|
-
}
|
|
4346
|
-
|
|
4347
|
-
// Helper factory
|
|
4348
|
-
const tick = (fn, ms, count = Infinity, start = true) => new Tick(fn, ms, count, start);
|
|
2595
|
+
// Helper factory
|
|
2596
|
+
const tick = (fn, ms, count = Infinity, start = true) => new Tick(fn, ms, count, start);
|
|
4349
2597
|
|
|
4350
2598
|
class Clock extends Tick {
|
|
4351
2599
|
constructor(tickMs = 1000 / 60) {
|
|
@@ -4648,461 +2896,39 @@ const timeTaken = callback => {
|
|
|
4648
2896
|
return r;
|
|
4649
2897
|
};
|
|
4650
2898
|
|
|
4651
|
-
|
|
4652
|
-
const
|
|
4653
|
-
const csv2object = (csv, delimiter = ",") => {
|
|
4654
|
-
const [header, ...rows] = csv2arr(csv,delimiter);
|
|
4655
|
-
const result = rows.map(row => {
|
|
4656
|
-
const obj = {};
|
|
4657
|
-
header.forEach((key, index) => {
|
|
4658
|
-
obj[key] = row[index];
|
|
4659
|
-
});
|
|
4660
|
-
return obj;
|
|
4661
|
-
});
|
|
4662
|
-
return result;
|
|
4663
|
-
};
|
|
4664
|
-
const csv2json = (csv, delimiter = ",") => JSON.stringify(csv2object(csv,delimiter));
|
|
4665
|
-
const csv2sql=(csv, Table)=>{
|
|
4666
|
-
const sanitizeId = s => s.trim().replace(/[^a-zA-Z0-9_]/g, '');
|
|
4667
|
-
const escapeVal = s => "'" + s.trim().replace(/'/g, "''") + "'";
|
|
4668
|
-
const lines = csv.trim().trimEnd().split('\n').filter(n=>n);
|
|
4669
|
-
const columns = lines[0].split(',').map(sanitizeId);
|
|
4670
|
-
let sqlQuery = "INSERT INTO " + sanitizeId(Table) + " (" + columns.join(', ') + ") Values ";
|
|
4671
|
-
let sqlValues = [];
|
|
4672
|
-
for (let i = 1; i < lines.length; i++) {
|
|
4673
|
-
const values = lines[i].split(',').map(escapeVal);
|
|
4674
|
-
sqlValues.push("(" + values.join(', ') + ")");
|
|
4675
|
-
}
|
|
4676
|
-
return sqlQuery+sqlValues.join(",\n");
|
|
4677
|
-
};
|
|
4678
|
-
|
|
4679
|
-
const _objects2arr=data=>data instanceof Array?[Object.keys(data[0]),...data.map(n=>Object.values(n))]:[Object.keys(data)];
|
|
4680
|
-
const _objects2csv=(data,delimiter)=>_objects2arr(data).map(n=>n.join(delimiter)).join("\n");
|
|
4681
|
-
const json2arr=json=>json instanceof Object?_objects2arr(json):_objects2arr(JSON.parse(json));
|
|
4682
|
-
const json2csv=(json,delimiter=",")=>json instanceof Object?_objects2csv(json,delimiter):_objects2csv(JSON.parse(json),delimiter);
|
|
4683
|
-
const json2csvFile=(json,delimiter)=>{
|
|
4684
|
-
const str=json2csv(json,delimiter);
|
|
4685
|
-
const blob=new Blob([str], { type: 'text/csv;charset=utf-8;' });
|
|
4686
|
-
return {
|
|
4687
|
-
str,
|
|
4688
|
-
blob,
|
|
4689
|
-
url:URL.createObjectURL(blob)
|
|
4690
|
-
}
|
|
4691
|
-
};
|
|
4692
|
-
const _processObject=(obj, indent)=>{
|
|
4693
|
-
const yml = [];
|
|
4694
|
-
if (Array.isArray(obj)) {
|
|
4695
|
-
obj.forEach(item => {
|
|
4696
|
-
if (typeof item === 'object' && item !== null) {
|
|
4697
|
-
yml.push(`${indent}-`);
|
|
4698
|
-
const nestedLines = _processObject(item, `${indent} `);
|
|
4699
|
-
yml.push(...nestedLines);
|
|
4700
|
-
} else yml.push(`${indent}- ${item}`);
|
|
4701
|
-
});
|
|
4702
|
-
} else {
|
|
4703
|
-
for (const key in obj) {
|
|
4704
|
-
if (obj.hasOwnProperty(key)) {
|
|
4705
|
-
const value = obj[key];
|
|
4706
|
-
if (typeof value === 'object' && value !== null) {
|
|
4707
|
-
yml.push(`${indent}${key}:`);
|
|
4708
|
-
const nestedLines = _processObject(value, `${indent} `);
|
|
4709
|
-
yml.push(...nestedLines);
|
|
4710
|
-
} else {
|
|
4711
|
-
yml.push(`${indent}${key}: ${value}`);
|
|
4712
|
-
}
|
|
4713
|
-
}
|
|
4714
|
-
}
|
|
4715
|
-
}
|
|
4716
|
-
return yml;
|
|
4717
|
-
};
|
|
4718
|
-
const _object2yml=(object,indent="")=>_processObject(object,indent).join('\n');
|
|
4719
|
-
const json2yml=(json,indent)=>json instanceof Object?_object2yml(json,indent):_object2yml(JSON.parse(json),indent);
|
|
4720
|
-
const json2ymlFile=(json,indent)=>{
|
|
4721
|
-
const str=json2yml(json,indent);
|
|
4722
|
-
const blob=new Blob([str], { type: 'text/yml;charset=utf-8;' });
|
|
4723
|
-
return {
|
|
4724
|
-
str,
|
|
4725
|
-
blob,
|
|
4726
|
-
url:URL.createObjectURL(blob)
|
|
4727
|
-
}
|
|
4728
|
-
};
|
|
4729
|
-
const json2xml=(json, indent = 1)=>{
|
|
4730
|
-
let xml = '';
|
|
4731
|
-
for (const key in json) {
|
|
4732
|
-
if (json.hasOwnProperty(key)) {
|
|
4733
|
-
const value = json[key];
|
|
4734
|
-
xml += '\n' + ' '.repeat(indent) + `<${key}>`;
|
|
4735
|
-
(typeof value === 'object') ? xml += json2xml(value, indent + 2) : xml += `${value}`;
|
|
4736
|
-
xml += `</${key}>`;
|
|
4737
|
-
}
|
|
4738
|
-
}
|
|
4739
|
-
return xml.trim();
|
|
4740
|
-
};
|
|
4741
|
-
const json2xmlFile=(json,indent)=>{
|
|
4742
|
-
const str=json2xml(json,indent);
|
|
4743
|
-
const blob=new Blob([str], { type: 'text/xml;charset=utf-8;' });
|
|
4744
|
-
return {
|
|
4745
|
-
str,
|
|
4746
|
-
blob,
|
|
4747
|
-
url:URL.createObjectURL(blob)
|
|
4748
|
-
}
|
|
4749
|
-
};
|
|
4750
|
-
|
|
4751
|
-
const svg2str=svg=>(new XMLSerializer()).serializeToString(svg);
|
|
4752
|
-
const svg2ascii=svg=>btoa(svg2str(svg));
|
|
4753
|
-
const svg2imgUrl=svg=>'data:image/svg+xml;base64,'+svg2ascii(svg);
|
|
4754
|
-
const svg2img=(svg,render=true)=>tags.img(svg2imgUrl(svg)).mount(render);
|
|
4755
|
-
|
|
4756
|
-
const json2css=(json, indentLevel = 0)=>{
|
|
4757
|
-
json = trimKeys(json);
|
|
4758
|
-
let cssText = '';
|
|
4759
|
-
const indent = ' '.repeat(indentLevel);
|
|
4760
|
-
|
|
4761
|
-
for (let selector in json) {
|
|
4762
|
-
if (typeof json[selector] === 'object') {
|
|
4763
|
-
cssText += `${indent}${selector} {\n`;
|
|
4764
|
-
const properties = json[selector];
|
|
4765
|
-
for (let property in properties) {
|
|
4766
|
-
if (typeof properties[property] === 'object') {
|
|
4767
|
-
cssText += json2css({ [property]: properties[property] }, indentLevel + 1);
|
|
4768
|
-
} else {
|
|
4769
|
-
cssText += `${indent} ${property.replace(/[A-Z]/g, match => '-' + match.toLowerCase())}: ${properties[property]};\n`;
|
|
4770
|
-
}
|
|
4771
|
-
}
|
|
4772
|
-
|
|
4773
|
-
cssText += `${indent}}\n`;
|
|
4774
|
-
}
|
|
4775
|
-
}
|
|
4776
|
-
|
|
4777
|
-
return cssText;
|
|
4778
|
-
};
|
|
4779
|
-
function trimKeys(obj) {
|
|
4780
|
-
if (typeof obj !== 'object' || obj === null) {
|
|
4781
|
-
return obj;
|
|
4782
|
-
}
|
|
4783
|
-
|
|
4784
|
-
return Object.keys(obj).reduce((acc, key) => {
|
|
4785
|
-
const trimmedKey = key.trim();
|
|
4786
|
-
acc[trimmedKey] = trimKeys(obj[key]);
|
|
4787
|
-
return acc;
|
|
4788
|
-
}, Array.isArray(obj) ? [] : {});
|
|
4789
|
-
}
|
|
4790
|
-
|
|
4791
|
-
function parseXML(xmlString) {
|
|
4792
|
-
const parser = new DOMParser();
|
|
4793
|
-
const xmlDoc = parser.parseFromString(xmlString, 'text/xml');
|
|
4794
|
-
const rootNode = xmlDoc.documentElement;
|
|
4795
|
-
const result = parseNode(rootNode);
|
|
4796
|
-
return result;
|
|
4797
|
-
}
|
|
4798
|
-
|
|
4799
|
-
function parseNode(node) {
|
|
4800
|
-
const obj = {
|
|
4801
|
-
type: node.nodeName,
|
|
4802
|
-
attributes: {},
|
|
4803
|
-
children: []
|
|
4804
|
-
};
|
|
4805
|
-
for (let i = 0; i < node.attributes.length; i++) {
|
|
4806
|
-
const attr = node.attributes[i];
|
|
4807
|
-
obj.attributes[attr.name] = attr.value;
|
|
4808
|
-
}
|
|
4809
|
-
for (let i = 0; i < node.childNodes.length; i++) {
|
|
4810
|
-
const child = node.childNodes[i];
|
|
4811
|
-
if (child.nodeType === Node.ELEMENT_NODE) {
|
|
4812
|
-
obj.children.push(parseNode(child));
|
|
4813
|
-
} else if (child.nodeType === Node.TEXT_NODE) {
|
|
4814
|
-
obj.text = child.textContent.trim();
|
|
4815
|
-
}
|
|
4816
|
-
}
|
|
4817
|
-
return obj;
|
|
4818
|
-
}
|
|
4819
|
-
|
|
4820
|
-
// import { ZikoHead , useHead} from "../reactivity/hooks/head/index.js";
|
|
4821
|
-
class ZikoApp {
|
|
4822
|
-
constructor({head = null, wrapper = null, target = null}){
|
|
4823
|
-
this.head = head;
|
|
4824
|
-
this.wrapper = wrapper;
|
|
4825
|
-
this.target = target;
|
|
4826
|
-
this.init();
|
|
4827
|
-
}
|
|
4828
|
-
get isZikoApp(){
|
|
4829
|
-
return true;
|
|
4830
|
-
}
|
|
4831
|
-
init(){
|
|
4832
|
-
this.head && this.setHead(this.head);
|
|
4833
|
-
this.wrapper && this.setWrapper(this.wrapper);
|
|
4834
|
-
this.target && this.setTarget(this.target);
|
|
4835
|
-
if(this.wrapper && this.target)this.wrapper.mount(this.target);
|
|
4836
|
-
}
|
|
4837
|
-
setTarget(target){
|
|
4838
|
-
if(target instanceof HTMLElement) this.target = target;
|
|
4839
|
-
else if (typeof target === "string") this.target = globalThis?.document?.querySelector(target);
|
|
4840
|
-
return this;
|
|
4841
|
-
}
|
|
4842
|
-
setWrapper(wrapper){
|
|
4843
|
-
if(wrapper?.isUIElement) this.wrapper = wrapper;
|
|
4844
|
-
else if(typeof wrapper === "function") this.wrapper = wrapper();
|
|
4845
|
-
return this;
|
|
4846
|
-
}
|
|
4847
|
-
// setHead(head){
|
|
4848
|
-
// if(head instanceof ZikoHead) this.head = head;
|
|
4849
|
-
// else this.head = useHead(head);
|
|
4850
|
-
// return this;
|
|
4851
|
-
// }
|
|
4852
|
-
|
|
4853
|
-
}
|
|
4854
|
-
const App = ({head, wrapper, target}) => new ZikoApp({head, wrapper, target});
|
|
4855
|
-
|
|
4856
|
-
function routesMatcher(mask, route) {
|
|
4857
|
-
const maskSegments = mask.split('/');
|
|
4858
|
-
const routeSegments = route.split('/');
|
|
4859
|
-
if (maskSegments.length !== routeSegments.length) {
|
|
4860
|
-
return false;
|
|
4861
|
-
}
|
|
4862
|
-
for (let i = 0; i < maskSegments.length; i++) {
|
|
4863
|
-
const maskSegment = maskSegments[i];
|
|
4864
|
-
const routeSegment = routeSegments[i];
|
|
4865
|
-
if (maskSegment.startsWith(':')) {
|
|
4866
|
-
continue;
|
|
4867
|
-
} else if (maskSegment !== routeSegment) {
|
|
4868
|
-
return false;
|
|
4869
|
-
}
|
|
4870
|
-
}
|
|
4871
|
-
return true;
|
|
4872
|
-
}
|
|
4873
|
-
function dynamicRoutesParser(mask, route) {
|
|
4874
|
-
const maskSegments = mask.split('/');
|
|
4875
|
-
const routeSegments = route.split('/');
|
|
4876
|
-
const params = {};
|
|
4877
|
-
if (maskSegments.length !== routeSegments.length) {
|
|
4878
|
-
return params;
|
|
4879
|
-
}
|
|
4880
|
-
for (let i = 0; i < maskSegments.length; i++) {
|
|
4881
|
-
const maskSegment = maskSegments[i];
|
|
4882
|
-
const routeSegment = routeSegments[i];
|
|
4883
|
-
if (maskSegment.startsWith(':')) {
|
|
4884
|
-
const paramName = maskSegment.slice(1);
|
|
4885
|
-
params[paramName] = routeSegment;
|
|
4886
|
-
} else if (maskSegment !== routeSegment) {
|
|
4887
|
-
return {};
|
|
4888
|
-
}
|
|
4889
|
-
}
|
|
4890
|
-
return params;
|
|
4891
|
-
}
|
|
2899
|
+
function useDerived(deriveFn, sources) {
|
|
2900
|
+
const getValue = () => deriveFn(...sources.map(source => source().value));
|
|
4892
2901
|
|
|
4893
|
-
|
|
4894
|
-
const
|
|
4895
|
-
return DynamicPattern.test(path);
|
|
4896
|
-
}
|
|
2902
|
+
let value = getValue();
|
|
2903
|
+
const subscribers = new Set();
|
|
4897
2904
|
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
// const route = "app/lang/en/id/7";
|
|
4901
|
-
// console.log(dynamicRoutesParser(mask, route)); // Should return { lang: "en", id: "7" }
|
|
4902
|
-
|
|
4903
|
-
class ZikoSPA extends ZikoApp{
|
|
4904
|
-
constructor({head, wrapper, target, routes}){
|
|
4905
|
-
super({head, wrapper, target});
|
|
4906
|
-
this.routes=new Map([
|
|
4907
|
-
["404",text("Error 404")],
|
|
4908
|
-
...Object.entries(routes)
|
|
4909
|
-
]);
|
|
4910
|
-
this.clear();
|
|
4911
|
-
globalThis.onpopstate = this.mount(location.pathname);
|
|
4912
|
-
}
|
|
4913
|
-
clear(){
|
|
4914
|
-
[...this.routes].forEach(n=>{
|
|
4915
|
-
!isDynamic(n[0]) && n[1]?.isUIElement && n[1].unmount();
|
|
4916
|
-
});
|
|
4917
|
-
// this.wrapper.clear();
|
|
4918
|
-
return this;
|
|
4919
|
-
}
|
|
4920
|
-
mount(path){
|
|
4921
|
-
const [mask, callback] = [...this.routes].find(route=>routesMatcher(route[0],path));
|
|
4922
|
-
let element ;
|
|
4923
|
-
if(isDynamic(mask)){
|
|
4924
|
-
const params = dynamicRoutesParser(mask, path);
|
|
4925
|
-
element = callback.call(this,params);
|
|
4926
|
-
}
|
|
4927
|
-
else {
|
|
4928
|
-
callback?.isUIElement && callback.mount(this.wrapper);
|
|
4929
|
-
if(typeof callback === "function") element = callback();
|
|
4930
|
-
}
|
|
4931
|
-
if(element?.isUIElement) element.mount(this.wrapper);
|
|
4932
|
-
// if(element?.isZikoApp) element.mount(this.wrapper);
|
|
4933
|
-
if(element instanceof Promise){
|
|
4934
|
-
element.then(e=>e.mount(this.wrapper));
|
|
4935
|
-
}
|
|
4936
|
-
globalThis.history.pushState({}, "", path);
|
|
4937
|
-
return this;
|
|
4938
|
-
}
|
|
4939
|
-
}
|
|
4940
|
-
const SPA=({head, wrapper, target, routes})=>new ZikoSPA({head, wrapper, target, routes});
|
|
2905
|
+
const notify = () => {
|
|
2906
|
+
const newValue = getValue();
|
|
4941
2907
|
|
|
2908
|
+
if (Object.is(newValue, value)) return;
|
|
4942
2909
|
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
// Dynamique
|
|
4947
|
-
s.get("/url/name/:name/id/:id",(path,name,id)=>handler())
|
|
4948
|
-
// regEx
|
|
4949
|
-
*/
|
|
4950
|
-
|
|
4951
|
-
function parseQueryParams$1(queryString) {
|
|
4952
|
-
return Object.fromEntries(
|
|
4953
|
-
new URLSearchParams(location.search)
|
|
4954
|
-
);
|
|
4955
|
-
}
|
|
2910
|
+
value = newValue;
|
|
2911
|
+
subscribers.forEach(fn => fn(value));
|
|
2912
|
+
};
|
|
4956
2913
|
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
|
|
4960
|
-
get: function() {
|
|
4961
|
-
return parseQueryParams$1(globalThis.location.search.substring(1));
|
|
4962
|
-
},
|
|
4963
|
-
configurable: false,
|
|
4964
|
-
enumerable: true
|
|
4965
|
-
},
|
|
4966
|
-
'HashParams': {
|
|
4967
|
-
get: function() {
|
|
4968
|
-
const hash = globalThis.location.hash.substring(1);
|
|
4969
|
-
return hash.split("#");
|
|
4970
|
-
},
|
|
4971
|
-
configurable: false,
|
|
4972
|
-
enumerable: true
|
|
4973
|
-
}
|
|
2914
|
+
sources.map(source => {
|
|
2915
|
+
const state = source();
|
|
2916
|
+
return state._subscribe(notify);
|
|
4974
2917
|
});
|
|
4975
|
-
}
|
|
4976
|
-
|
|
4977
|
-
// import.meta.glob('./src/pages/**/*.js')
|
|
4978
|
-
async function FileBasedRouting(pages /* use import.meta.glob */){
|
|
4979
|
-
const routes = Object.keys(pages);
|
|
4980
|
-
const root = findCommonPath(routes);
|
|
4981
|
-
const pairs = {};
|
|
4982
|
-
for(let i=0; i<routes.length; i++){
|
|
4983
|
-
const module = await pages[routes[i]]();
|
|
4984
|
-
const component = await module.default;
|
|
4985
|
-
Object.assign(pairs,{[customPath(routes[i], root)]:component});
|
|
4986
|
-
}
|
|
4987
|
-
return SPA({
|
|
4988
|
-
target : document.body,
|
|
4989
|
-
routes : {
|
|
4990
|
-
"/" : ()=>{},
|
|
4991
|
-
...pairs
|
|
4992
|
-
},
|
|
4993
|
-
wrapper : tags.section()
|
|
4994
|
-
})
|
|
4995
|
-
}
|
|
4996
|
-
function customPath(inputPath, root = './src/pages', extensions = ['js', 'ts']) {
|
|
4997
|
-
if(root.at(-1)==="/") root = root.slice(0, -1);
|
|
4998
|
-
const normalizedPath = inputPath.replace(/\\/g, '/').replace(/\[(\w+)\]/g, '$1/:$1');
|
|
4999
|
-
const parts = normalizedPath.split('/');
|
|
5000
|
-
const rootParts = root.split('/');
|
|
5001
|
-
const rootIndex = parts.indexOf(rootParts.at(-1));
|
|
5002
|
-
if (rootIndex !== -1) {
|
|
5003
|
-
const subsequentParts = parts.slice(rootIndex + 1);
|
|
5004
|
-
const lastPart = parts.at(-1);
|
|
5005
|
-
const isIndexFile = lastPart === 'index.js' || lastPart === 'index.ts';
|
|
5006
|
-
// console.log({extensions, subsequentParts, lastPart, isIndexFile, rootParts, rootIndex, parts})
|
|
5007
|
-
const hasValidExtension = extensions.some(ext => lastPart === `.${ext}` || lastPart.endsWith(`.${ext}`));
|
|
5008
|
-
if (isIndexFile) {
|
|
5009
|
-
return '/' + (subsequentParts.length > 1 ? subsequentParts.slice(0, -1).join('/') : '');
|
|
5010
|
-
}
|
|
5011
|
-
if (hasValidExtension) {
|
|
5012
|
-
return '/' + subsequentParts.join('/').replace(/\.(js|ts)$/, '');
|
|
5013
|
-
}
|
|
5014
|
-
}
|
|
5015
|
-
return '';
|
|
5016
|
-
}
|
|
5017
|
-
function findCommonPath(paths) {
|
|
5018
|
-
if (paths.length === 0) return '';
|
|
5019
|
-
const splitPaths = paths.map(path => path.split('/'));
|
|
5020
|
-
const minLength = Math.min(...splitPaths.map(parts => parts.length));
|
|
5021
|
-
let commonParts = [];
|
|
5022
|
-
for (let i = 0; i < minLength; i++) {
|
|
5023
|
-
const part = splitPaths[0][i];
|
|
5024
|
-
if (splitPaths.every(parts => parts[i] === part || parts[i].startsWith('['))) {
|
|
5025
|
-
commonParts.push(part);
|
|
5026
|
-
} else {
|
|
5027
|
-
break;
|
|
5028
|
-
}
|
|
5029
|
-
}
|
|
5030
|
-
const commonPath = commonParts.join('/') + (commonParts.length ? '/' : '');
|
|
5031
|
-
return commonPath;
|
|
5032
|
-
}
|
|
5033
|
-
|
|
5034
|
-
function useDerived(deriveFn, sources) {
|
|
5035
|
-
let value = deriveFn(...sources.map(s => s().value));
|
|
5036
|
-
const subscribers = new Set();
|
|
5037
|
-
|
|
5038
|
-
// const unsubscribers = sources.map(source => {
|
|
5039
|
-
// const srcValue = source();
|
|
5040
|
-
|
|
5041
|
-
// return srcValue._subscribe(() => {
|
|
5042
|
-
// const newVal = deriveFn(...sources.map(s => s().value));
|
|
5043
|
-
|
|
5044
|
-
// if (!Object.is(newVal, value)) {
|
|
5045
|
-
// value = newVal;
|
|
5046
|
-
// subscribers.forEach(fn => fn(value));
|
|
5047
|
-
// }
|
|
5048
|
-
// });
|
|
5049
|
-
// });
|
|
5050
2918
|
|
|
5051
2919
|
const getter = () => ({
|
|
5052
2920
|
value,
|
|
5053
|
-
_subscribe
|
|
2921
|
+
_subscribe(fn) {
|
|
5054
2922
|
subscribers.add(fn);
|
|
5055
2923
|
return () => subscribers.delete(fn);
|
|
5056
2924
|
},
|
|
5057
2925
|
});
|
|
5058
2926
|
|
|
5059
2927
|
getter[STATE_GETTER] = true;
|
|
5060
|
-
|
|
2928
|
+
|
|
2929
|
+
return getter;
|
|
5061
2930
|
}
|
|
5062
2931
|
|
|
5063
|
-
const mapfun=(fun,...X)=>{
|
|
5064
|
-
const Y=X.map(x=>{
|
|
5065
|
-
if(
|
|
5066
|
-
x===null||
|
|
5067
|
-
["number","string","boolean","bigint","undefined"].includes(typeof x)||
|
|
5068
|
-
x?.__mapfun__
|
|
5069
|
-
) return fun(x)
|
|
5070
|
-
if(x instanceof Array) return x.map(n=>mapfun(fun,n));
|
|
5071
|
-
if(ArrayBuffer.isView(x)) return x.map(n=>fun(n));
|
|
5072
|
-
if(x instanceof Set) return new Set(mapfun(fun,...[...x]));
|
|
5073
|
-
if(x instanceof Map) return new Map([...x].map(n=>[n[0],mapfun(fun,n[1])]));
|
|
5074
|
-
if(x.isMatrix?.()) return new x.constructor(x.rows, x.cols, mapfun(x.arr.flat(1)))
|
|
5075
|
-
// if(x.isComplex?.()){
|
|
5076
|
-
// const [a,b,z,phi]=[x.a,x.b,x.z,x.phi];
|
|
5077
|
-
// switch(fun){
|
|
5078
|
-
// // Moved to Fixed to avoid Circular Dep
|
|
5079
|
-
// // case Math.log: return new x.constructor(ln(z),phi); // Done
|
|
5080
|
-
// // case Math.exp: return new x.constructor(e(a)*cos(b),e(a)*sin(b)); // Done
|
|
5081
|
-
// // case Math.abs: return z; // Done
|
|
5082
|
-
// // case Math.sqrt: return new x.constructor(sqrt(z)*cos(phi/2),sqrt(z)*sin(phi/2)); // Done
|
|
5083
|
-
// // case Fixed.cos: return new x.constructor(cos(a)*cosh(b),-(sin(a)*sinh(b)));
|
|
5084
|
-
// // case Fixed.sin: return new x.constructor(sin(a)*cosh(b),cos(a)*sinh(b));
|
|
5085
|
-
// // case Fixed.tan:{
|
|
5086
|
-
// // const DEN = cos(2*a)+cosh(2*b);
|
|
5087
|
-
// // return new x.constructor(sin(2*a)/DEN,sinh(2*b)/DEN);
|
|
5088
|
-
// // }
|
|
5089
|
-
// // case Fixed.cosh:return new x.constructor(cosh(a)*cos(b),sinh(a)*sin(b));
|
|
5090
|
-
// // case Fixed.sinh:return new x.constructor(sinh(a)*cos(b),cosh(a)*sin(b));
|
|
5091
|
-
// // case Fixed.tanh:{
|
|
5092
|
-
// // const DEN=cosh(2*a)+cos(2*b);
|
|
5093
|
-
// // return new x.constructor(sinh(2*a)/DEN,sin(2*b)/DEN)
|
|
5094
|
-
// // }
|
|
5095
|
-
// default : return fun(x)
|
|
5096
|
-
// }
|
|
5097
|
-
// }
|
|
5098
|
-
else if(x instanceof Object){
|
|
5099
|
-
return Object.fromEntries(Object.entries(x).map(n=>n=[n[0],mapfun(fun,n[1])]))
|
|
5100
|
-
// return fun(Object) || Object.fromEntries(Object.entries(x).map(n=>n=[n[0],mapfun(fun,n[1])]))
|
|
5101
|
-
}
|
|
5102
|
-
});
|
|
5103
|
-
return Y.length==1? Y[0]: Y;
|
|
5104
|
-
};
|
|
5105
|
-
|
|
5106
2932
|
const useReactive = (nested_value) => mapfun(
|
|
5107
2933
|
n => {
|
|
5108
2934
|
const state = useState(n);
|
|
@@ -5114,37 +2940,29 @@ const useReactive = (nested_value) => mapfun(
|
|
|
5114
2940
|
nested_value
|
|
5115
2941
|
);
|
|
5116
2942
|
|
|
5117
|
-
const useEffect = (callback, deps = []) =>{
|
|
2943
|
+
const useEffect = (callback, deps = []) => {
|
|
5118
2944
|
const states = deps.filter(isStateGetter);
|
|
5119
|
-
|
|
5120
2945
|
let cleanup;
|
|
5121
2946
|
|
|
2947
|
+
const getValues = () =>
|
|
2948
|
+
states.map(state => state().value);
|
|
2949
|
+
|
|
5122
2950
|
const execute = () => {
|
|
5123
|
-
// Cleanup previous effect
|
|
5124
2951
|
if (typeof cleanup === "function") {
|
|
5125
2952
|
cleanup();
|
|
5126
2953
|
}
|
|
5127
2954
|
|
|
5128
|
-
|
|
5129
|
-
const values = states.map(state => state().value);
|
|
5130
|
-
|
|
5131
|
-
// Execute effect
|
|
5132
|
-
cleanup = callback(...values);
|
|
2955
|
+
cleanup = callback(getValues());
|
|
5133
2956
|
};
|
|
5134
2957
|
|
|
5135
|
-
// Subscribe to states
|
|
5136
2958
|
const unsubscribers = states.map(state =>
|
|
5137
2959
|
state()._subscribe(execute)
|
|
5138
2960
|
);
|
|
5139
2961
|
|
|
5140
|
-
// Initial execution
|
|
5141
2962
|
execute();
|
|
5142
2963
|
|
|
5143
|
-
// Return effect cleanup
|
|
5144
2964
|
return () => {
|
|
5145
|
-
unsubscribers.forEach(unsubscribe =>
|
|
5146
|
-
unsubscribe();
|
|
5147
|
-
});
|
|
2965
|
+
unsubscribers.forEach(unsubscribe => unsubscribe());
|
|
5148
2966
|
|
|
5149
2967
|
if (typeof cleanup === "function") {
|
|
5150
2968
|
cleanup();
|
|
@@ -5153,60 +2971,6 @@ const useEffect = (callback, deps = []) =>{
|
|
|
5153
2971
|
};
|
|
5154
2972
|
};
|
|
5155
2973
|
|
|
5156
|
-
class UseThread {
|
|
5157
|
-
#worker;
|
|
5158
|
-
#callbacks = new Map();
|
|
5159
|
-
#idCounter = 0;
|
|
5160
|
-
|
|
5161
|
-
constructor() {
|
|
5162
|
-
const workerCode = `
|
|
5163
|
-
this.onmessage = function(e) {
|
|
5164
|
-
const { id, funStr, args, close } = e.data;
|
|
5165
|
-
try {
|
|
5166
|
-
const func = new Function("return " + funStr)();
|
|
5167
|
-
const result = func(...args);
|
|
5168
|
-
postMessage({ id, result });
|
|
5169
|
-
} catch (error) {
|
|
5170
|
-
postMessage({ id, error: error.message });
|
|
5171
|
-
} finally {
|
|
5172
|
-
if (close) self.close();
|
|
5173
|
-
}
|
|
5174
|
-
}
|
|
5175
|
-
`;
|
|
5176
|
-
const blob = new Blob([workerCode], { type: "text/javascript" });
|
|
5177
|
-
this.#worker = new Worker(URL.createObjectURL(blob));
|
|
5178
|
-
|
|
5179
|
-
this.#worker.addEventListener("message", (e) => {
|
|
5180
|
-
const { id, result, error } = e.data;
|
|
5181
|
-
const callback = this.#callbacks.get(id);
|
|
5182
|
-
if (!callback) return;
|
|
5183
|
-
|
|
5184
|
-
callback(result, error);
|
|
5185
|
-
this.#callbacks.delete(id);
|
|
5186
|
-
});
|
|
5187
|
-
}
|
|
5188
|
-
call(func, callback, args = [], close = true) {
|
|
5189
|
-
if (typeof func !== "function") throw new TypeError("func must be a function");
|
|
5190
|
-
const id = ++this.#idCounter;
|
|
5191
|
-
this.#callbacks.set(id, callback);
|
|
5192
|
-
|
|
5193
|
-
this.#worker.postMessage({
|
|
5194
|
-
id,
|
|
5195
|
-
funStr: func.toString(),
|
|
5196
|
-
args,
|
|
5197
|
-
close
|
|
5198
|
-
});
|
|
5199
|
-
|
|
5200
|
-
return this;
|
|
5201
|
-
}
|
|
5202
|
-
|
|
5203
|
-
terminate() {
|
|
5204
|
-
this.#worker.terminate();
|
|
5205
|
-
}
|
|
5206
|
-
}
|
|
5207
|
-
|
|
5208
|
-
const useThread = (func, callback, args = [], close = true) => new UseThread().call(func, callback, args, close);
|
|
5209
|
-
|
|
5210
2974
|
class UseEventEmitter {
|
|
5211
2975
|
constructor(maxListeners = 10) {
|
|
5212
2976
|
this.events = {};
|
|
@@ -5274,485 +3038,169 @@ class UseEventEmitter {
|
|
|
5274
3038
|
|
|
5275
3039
|
const useEventEmitter = (maxListeners) => new UseEventEmitter(maxListeners);
|
|
5276
3040
|
|
|
5277
|
-
|
|
5278
|
-
[
|
|
5279
|
-
|
|
5280
|
-
|
|
5281
|
-
callback: () => console.log(1)
|
|
5282
|
-
},
|
|
5283
|
-
{
|
|
5284
|
-
query: '(max-width: 300px)',
|
|
5285
|
-
callback: () => console.log(2)
|
|
5286
|
-
}
|
|
5287
|
-
]
|
|
5288
|
-
*/
|
|
5289
|
-
|
|
5290
|
-
class UseMediaQuery {
|
|
5291
|
-
#mediaQueryRules;
|
|
5292
|
-
#fallback;
|
|
5293
|
-
#lastCalledCallback = null;
|
|
5294
|
-
|
|
5295
|
-
constructor(mediaQueryRules = [], fallback = () => {}) {
|
|
5296
|
-
this.#mediaQueryRules = mediaQueryRules;
|
|
5297
|
-
this.#fallback = fallback;
|
|
5298
|
-
|
|
5299
|
-
this.#init();
|
|
5300
|
-
}
|
|
5301
|
-
|
|
5302
|
-
// PRIVATE: check if ANY rule matches
|
|
5303
|
-
#checkAllRules() {
|
|
5304
|
-
return this.#mediaQueryRules.some(
|
|
5305
|
-
({ query }) => globalThis.matchMedia(query).matches
|
|
5306
|
-
);
|
|
5307
|
-
}
|
|
5308
|
-
|
|
5309
|
-
// PRIVATE: installs listeners and initial checks
|
|
5310
|
-
#init() {
|
|
5311
|
-
this.#mediaQueryRules.forEach(({ query, callback }) => {
|
|
5312
|
-
const mediaQueryList = globalThis.matchMedia(query);
|
|
5313
|
-
|
|
5314
|
-
const checkMatches = () => {
|
|
5315
|
-
const anyMatch = this.#checkAllRules();
|
|
5316
|
-
|
|
5317
|
-
if (mediaQueryList.matches) {
|
|
5318
|
-
callback();
|
|
5319
|
-
this.#lastCalledCallback = callback;
|
|
5320
|
-
} else if (!anyMatch && this.#lastCalledCallback !== this.#fallback) {
|
|
5321
|
-
this.#fallback();
|
|
5322
|
-
this.#lastCalledCallback = this.#fallback;
|
|
5323
|
-
}
|
|
5324
|
-
};
|
|
5325
|
-
|
|
5326
|
-
checkMatches();
|
|
5327
|
-
mediaQueryList.addEventListener("change", checkMatches);
|
|
5328
|
-
});
|
|
5329
|
-
}
|
|
5330
|
-
}
|
|
5331
|
-
|
|
5332
|
-
const useMediaQuery = (mediaQueryRules, fallback) =>
|
|
5333
|
-
new UseMediaQuery(mediaQueryRules, fallback);
|
|
5334
|
-
|
|
5335
|
-
class UseTitle {
|
|
5336
|
-
constructor(title = document.title, withEmitter = true) {
|
|
5337
|
-
this.cache = {
|
|
5338
|
-
emitter: null
|
|
5339
|
-
};
|
|
5340
|
-
|
|
5341
|
-
if (withEmitter) this.useEventEmitter();
|
|
5342
|
-
this.set(title);
|
|
5343
|
-
}
|
|
5344
|
-
|
|
5345
|
-
useEventEmitter() {
|
|
5346
|
-
this.cache.emitter = useEventEmitter();
|
|
5347
|
-
return this;
|
|
5348
|
-
}
|
|
5349
|
-
|
|
5350
|
-
setTitle(title) {
|
|
5351
|
-
if (title !== document.title) {
|
|
5352
|
-
document.title = title;
|
|
5353
|
-
|
|
5354
|
-
if (this.cache.emitter) {
|
|
5355
|
-
this.cache.emitter.emit("ziko:title-changed", title);
|
|
5356
|
-
}
|
|
5357
|
-
}
|
|
5358
|
-
return this;
|
|
5359
|
-
}
|
|
5360
|
-
|
|
5361
|
-
get current() {
|
|
5362
|
-
return document.title;
|
|
5363
|
-
}
|
|
5364
|
-
|
|
5365
|
-
onChange(callback) {
|
|
5366
|
-
if (this.cache.emitter) {
|
|
5367
|
-
this.cache.emitter.on("ziko:title-changed", callback);
|
|
5368
|
-
}
|
|
5369
|
-
return this;
|
|
5370
|
-
}
|
|
5371
|
-
}
|
|
5372
|
-
|
|
5373
|
-
const useTitle = (title, withEmitter = true) => new UseTitle(title, withEmitter);
|
|
5374
|
-
|
|
5375
|
-
class UseRoot {
|
|
5376
|
-
constructor(PropsMap, { namespace = 'Ziko', ValidateCssProps = false } = {}) {
|
|
5377
|
-
this.currentPropsMap = PropsMap;
|
|
5378
|
-
this.namespace = namespace;
|
|
5379
|
-
this.ValidateCssProps = ValidateCssProps;
|
|
5380
|
-
this.use(PropsMap);
|
|
5381
|
-
}
|
|
5382
|
-
|
|
5383
|
-
use(PropsMap) {
|
|
5384
|
-
if (this.ValidateCssProps) ValidateCssPropsFn(PropsMap);
|
|
5385
|
-
this.currentPropsMap = PropsMap;
|
|
5386
|
-
this.#maintain();
|
|
5387
|
-
return this;
|
|
5388
|
-
}
|
|
5389
|
-
|
|
5390
|
-
#maintain() {
|
|
5391
|
-
const root = globalThis?.document?.documentElement?.style;
|
|
5392
|
-
for (const prop in this.currentPropsMap) {
|
|
5393
|
-
const cssProp = this.namespace ? `--${this.namespace}-${prop}` : `--${prop}`;
|
|
5394
|
-
root.setProperty(cssProp, this.currentPropsMap[prop]);
|
|
5395
|
-
|
|
5396
|
-
Object.defineProperty(this, prop, {
|
|
5397
|
-
value: `var(${cssProp})`,
|
|
5398
|
-
writable: true,
|
|
5399
|
-
configurable: true,
|
|
5400
|
-
enumerable: false
|
|
5401
|
-
});
|
|
5402
|
-
}
|
|
5403
|
-
}
|
|
5404
|
-
}
|
|
5405
|
-
|
|
5406
|
-
function ValidateCssPropsFn(PropsMap) {
|
|
5407
|
-
const validProps = new Set(Object.keys(document.documentElement.style));
|
|
5408
|
-
for (const key in PropsMap) {
|
|
5409
|
-
if (!validProps.has(key)) {
|
|
5410
|
-
throw new Error(`Invalid CSS property: "${key}"`);
|
|
5411
|
-
}
|
|
5412
|
-
}
|
|
5413
|
-
}
|
|
5414
|
-
|
|
5415
|
-
const useRoot = (PropsMap, options = {}) => new UseRoot(PropsMap, options);
|
|
3041
|
+
const camel2hyphencase$1 = (text = '') => text.replace(/[A-Z]/g, match => '-' + match.toLowerCase());
|
|
3042
|
+
const camel2snakecase = (text = '') => text.replace(/[A-Z]/g, match => '_' + match.toLowerCase());
|
|
3043
|
+
const camel2pascalcase = (text = '') => text.charAt(0).toUpperCase() + text.slice(1);
|
|
3044
|
+
const camel2constantcase = (text = '') => text.replace(/[A-Z]/g, match => '_' + match).toUpperCase();
|
|
5416
3045
|
|
|
3046
|
+
const pascal2snakecase = (text = '') => text.replace(/([A-Z])/g, (match, offset) => offset ? '_' + match.toLowerCase() : match.toLowerCase());
|
|
3047
|
+
const pascal2hyphencase = (text = '') => text.replace(/([A-Z])/g, (match, offset) => offset ? '-' + match.toLowerCase() : match.toLowerCase());
|
|
3048
|
+
const pascal2camelcase = (text = '') => text.charAt(0).toLowerCase() + text.slice(1);
|
|
3049
|
+
const pascal2constantcase = (text = '') => text.replace(/([A-Z])/g, (match, offset) => offset ? '_' + match : match).toUpperCase();
|
|
5417
3050
|
|
|
5418
|
-
|
|
3051
|
+
const snake2camelcase = (text = '') => text.replace(/(_\w)/g, match => match[1].toUpperCase());
|
|
3052
|
+
const snake2hyphencase = (text = '') => text.replace(/_/g, "-");
|
|
3053
|
+
const snake2pascalcase = (text = '') => text.split('_').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join('');
|
|
3054
|
+
const snake2constantcase = (text = '') => text.toUpperCase();
|
|
5419
3055
|
|
|
5420
|
-
|
|
5421
|
-
const
|
|
5422
|
-
|
|
5423
|
-
|
|
5424
|
-
color : 'darkblue'
|
|
5425
|
-
border : '2px darkblue solid"'
|
|
5426
|
-
},
|
|
5427
|
-
S2 : {
|
|
5428
|
-
background : 'darkblue',
|
|
5429
|
-
color : 'white'
|
|
5430
|
-
border : '2px green solid"'
|
|
5431
|
-
}
|
|
5432
|
-
}
|
|
5433
|
-
const {use, border, background, color} = useRoot(Style.S1)
|
|
5434
|
-
|
|
5435
|
-
tags.p("Test useRoot ").style({
|
|
5436
|
-
border,
|
|
5437
|
-
color,
|
|
5438
|
-
background,
|
|
5439
|
-
padding : '10px'
|
|
5440
|
-
})
|
|
3056
|
+
const hyphen2camelcase = (text = '') => text.replace(/-([a-z])/g, match => match[1].toUpperCase());
|
|
3057
|
+
const hyphen2snakecase = (text = '') => text.replace(/-/g, '_');
|
|
3058
|
+
const hyphen2pascalcase = (text = '') => text.split('-').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join('');
|
|
3059
|
+
const hyphen2constantcase = (text = '') => text.replace(/-/g, '_').toUpperCase();
|
|
5441
3060
|
|
|
5442
|
-
|
|
3061
|
+
const constant2camelcase = (text = '') => text.toLowerCase().replace(/_([a-z])/g, match => match[1].toUpperCase());
|
|
3062
|
+
const constant2snakecase = (text = '') => text.toLowerCase();
|
|
3063
|
+
const constant2pascalcase = (text = '') => text.toLowerCase().split('_').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join('');
|
|
3064
|
+
const constant2hyphencase = (text = '') => text.toLowerCase().replace(/_/g, '-');
|
|
5443
3065
|
|
|
5444
|
-
const
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
|
|
5448
|
-
|
|
5449
|
-
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
|
|
5455
|
-
|
|
5456
|
-
: updates;
|
|
5457
|
-
|
|
5458
|
-
const finalParams = merge
|
|
5459
|
-
? { ...current, ...next }
|
|
5460
|
-
: next;
|
|
5461
|
-
|
|
5462
|
-
const search = new URLSearchParams(finalParams).toString();
|
|
5463
|
-
|
|
5464
|
-
window.history.pushState(
|
|
5465
|
-
{},
|
|
5466
|
-
"",
|
|
5467
|
-
`${window.location.pathname}${search ? `?${search}` : ""}`
|
|
5468
|
-
);
|
|
5469
|
-
|
|
5470
|
-
window.dispatchEvent(
|
|
5471
|
-
new CustomEvent("queryparamschange", {
|
|
5472
|
-
detail: finalParams
|
|
5473
|
-
})
|
|
5474
|
-
);
|
|
5475
|
-
};
|
|
5476
|
-
|
|
5477
|
-
return [getParams, setParams];
|
|
5478
|
-
}
|
|
5479
|
-
|
|
5480
|
-
function watchQueryParams(callback) {
|
|
5481
|
-
let previousSearch = location.search;
|
|
5482
|
-
|
|
5483
|
-
const notify = () => {
|
|
5484
|
-
const currentSearch = location.search;
|
|
5485
|
-
|
|
5486
|
-
if (currentSearch === previousSearch) {
|
|
5487
|
-
return;
|
|
5488
|
-
}
|
|
5489
|
-
|
|
5490
|
-
previousSearch = currentSearch;
|
|
5491
|
-
callback(parseQueryParams());
|
|
5492
|
-
};
|
|
5493
|
-
|
|
5494
|
-
window.addEventListener("popstate", notify);
|
|
5495
|
-
|
|
5496
|
-
const pushState = history.pushState;
|
|
5497
|
-
history.pushState = function (...args) {
|
|
5498
|
-
pushState.apply(this, args);
|
|
5499
|
-
notify();
|
|
5500
|
-
};
|
|
5501
|
-
|
|
5502
|
-
const replaceState = history.replaceState;
|
|
5503
|
-
history.replaceState = function (...args) {
|
|
5504
|
-
replaceState.apply(this, args);
|
|
5505
|
-
notify();
|
|
5506
|
-
};
|
|
5507
|
-
|
|
5508
|
-
callback(parseQueryParams());
|
|
3066
|
+
const is_camelcase$1 = (text = '') =>{
|
|
3067
|
+
if (text.length === 0) return false;
|
|
3068
|
+
const camelCasePattern = /^[a-z][a-zA-Z0-9]*$/;
|
|
3069
|
+
return camelCasePattern.test(text);
|
|
3070
|
+
};
|
|
3071
|
+
const is_hyphencase = (text = '') => text.split('-').length > 0;
|
|
3072
|
+
const is_snakeCase = (text = '') => text.split('_').length > 0;
|
|
3073
|
+
const is_pascalcalse = (text = '') => {
|
|
3074
|
+
if (text.length === 0) return false;
|
|
3075
|
+
const PascalCasePattern = /^[A-Z][a-zA-Z0-9]*$/;
|
|
3076
|
+
return PascalCasePattern.test(text);
|
|
3077
|
+
};
|
|
5509
3078
|
|
|
5510
|
-
|
|
5511
|
-
|
|
5512
|
-
|
|
5513
|
-
|
|
5514
|
-
|
|
5515
|
-
|
|
5516
|
-
// Math.abs = new Proxy(Math.abs, {
|
|
5517
|
-
// apply(target, thisArg, args) {
|
|
5518
|
-
// const x = args[0]
|
|
5519
|
-
// if(typeof x === 'number') return target.apply(thisArg, args);
|
|
5520
|
-
// if(x?.isComplex?.()){
|
|
5521
|
-
// const {a, b, z, phi} = x
|
|
5522
|
-
// const complex = (a, b) => new x.constructor(a, b)
|
|
5523
|
-
// switch(target.name){
|
|
5524
|
-
// case 'abs' : return a.z;
|
|
5525
|
-
// case 'sqrt' : return complex(sqrt(z)*cos(phi/2),sqrt(z)*sin(phi/2));
|
|
5526
|
-
// }
|
|
5527
|
-
// }
|
|
5528
|
-
|
|
5529
|
-
// }
|
|
5530
|
-
// });
|
|
3079
|
+
const is_palindrome = text =>{
|
|
3080
|
+
const str = text.toLocaleLowerCase();
|
|
3081
|
+
let l = str.length,i;
|
|
3082
|
+
for(i=0;i<l/2;i++)if(str[i]!=str[l-i-1])return false;
|
|
3083
|
+
return true;
|
|
3084
|
+
};
|
|
5531
3085
|
|
|
3086
|
+
const is_anagram = (word, words) =>{
|
|
3087
|
+
word=word.split("").sort();
|
|
3088
|
+
words=words.split("").sort();
|
|
3089
|
+
return JSON.stringify(word)===JSON.stringify(words);
|
|
3090
|
+
};
|
|
5532
3091
|
|
|
5533
|
-
|
|
5534
|
-
const fn = Math[key];
|
|
5535
|
-
if (typeof fn === "function") {
|
|
5536
|
-
Math[key] = new Proxy(fn, {
|
|
5537
|
-
apply(target, thisArg, args) {
|
|
5538
|
-
// console.log(target)
|
|
5539
|
-
const x = args[0];
|
|
5540
|
-
if(typeof x === 'number' || args.length === 0) return target.apply(thisArg, args);
|
|
5541
|
-
if(x?.isComplex?.()){
|
|
5542
|
-
const {a, b, z, phi} = x;
|
|
5543
|
-
const complex = (a, b) => new x.constructor(a, b);
|
|
5544
|
-
switch(target.name){
|
|
5545
|
-
case 'abs' : return x.z;
|
|
5546
|
-
case 'sqrt' : return complex(sqrt(z)*cos$1(phi/2),sqrt(z)*sin$1(phi/2));
|
|
5547
|
-
case 'log' : return complex(log(z), phi);
|
|
5548
|
-
case 'exp' : return complex(exp(a)*cos$1(b),exp(a)*sin$1(b));
|
|
5549
|
-
case 'cos' : return complex(cos$1(a)*cosh$1(b),-(sin$1(a)*sinh(b)));
|
|
5550
|
-
case 'sin' : return complex(sin$1(a)*cosh$1(b),cos$1(a)*sinh(b));
|
|
5551
|
-
case 'tan' : {
|
|
5552
|
-
const DEN = cos$1(2*a)+cosh$1(2*b);
|
|
5553
|
-
return complex(sin$1(2*a) /DEN, sinh(2*b)/DEN);
|
|
5554
|
-
}
|
|
5555
|
-
case 'cosh' : return complex(cosh$1(a)*cos$1(b),sinh(a)*sin$1(b));
|
|
5556
|
-
case 'sinh' : return complex(sinh(a)*cos$1(b),cosh$1(a)*sin$1(b));
|
|
5557
|
-
case 'tanh' : {
|
|
5558
|
-
const DEN=cosh$1(2*a)+cos$1(2*b);
|
|
5559
|
-
return complex(sinh(2*a)/DEN,sin$1(2*b)/DEN)
|
|
5560
|
-
}
|
|
5561
|
-
default : return target.apply(thisArg, args)
|
|
5562
|
-
}
|
|
5563
|
-
}
|
|
5564
|
-
// if( x.isMatrix?.()){
|
|
5565
|
-
// const {rows, cols, arr} = x
|
|
5566
|
-
// // return new x.constructor(rows, cols, arr.flat(1).map(n=>));
|
|
5567
|
-
// }
|
|
5568
|
-
throw new TypeError(`Math.${key} expects only numbers`);
|
|
5569
|
-
}
|
|
5570
|
-
});
|
|
5571
|
-
}
|
|
5572
|
-
}
|
|
3092
|
+
const is_isogram = (text = '') => [...new Set(text.toLowerCase())].length === text.length;
|
|
5573
3093
|
|
|
5574
3094
|
if(globalThis?.document){
|
|
5575
3095
|
document?.addEventListener("DOMContentLoaded", __Ziko__.__Config__.init());
|
|
5576
|
-
}
|
|
3096
|
+
}
|
|
3097
|
+
|
|
3098
|
+
// import './math/functions/proxy.js'
|
|
5577
3099
|
|
|
5578
|
-
exports.App = App;
|
|
5579
|
-
exports.Canvas = Canvas;
|
|
5580
3100
|
exports.ClickAwayEvent = ClickAwayEvent;
|
|
5581
3101
|
exports.ClickListeners = ClickListeners;
|
|
5582
3102
|
exports.Clock = Clock;
|
|
5583
3103
|
exports.CloneElement = CloneElement;
|
|
5584
|
-
exports.Complex = Complex;
|
|
5585
3104
|
exports.E = E;
|
|
5586
3105
|
exports.EPSILON = EPSILON;
|
|
5587
3106
|
exports.EventController = EventController;
|
|
5588
|
-
exports.FileBasedRouting = FileBasedRouting;
|
|
5589
|
-
exports.Flex = Flex;
|
|
5590
|
-
exports.For = For;
|
|
5591
|
-
exports.Fragment = Fragment;
|
|
5592
|
-
exports.HTMLWrapper = HTMLWrapper;
|
|
5593
3107
|
exports.KeyListeners = KeyListeners;
|
|
5594
|
-
exports.
|
|
5595
|
-
exports.PI = PI$1;
|
|
3108
|
+
exports.PI = PI;
|
|
5596
3109
|
exports.PtrListeners = PtrListeners;
|
|
5597
3110
|
exports.Random = Random;
|
|
5598
|
-
exports.SPA = SPA;
|
|
5599
|
-
exports.SVGWrapper = SVGWrapper;
|
|
5600
3111
|
exports.Scheduler = Scheduler;
|
|
5601
|
-
exports.Suspense = Suspense;
|
|
5602
|
-
exports.Svg = Svg;
|
|
5603
|
-
exports.Swap = Swap;
|
|
5604
3112
|
exports.SwipeEvent = SwipeEvent;
|
|
5605
|
-
exports.Switch = Switch;
|
|
5606
3113
|
exports.Tick = Tick;
|
|
5607
3114
|
exports.TimeAnimation = TimeAnimation;
|
|
5608
3115
|
exports.TimeLoop = TimeLoop;
|
|
5609
3116
|
exports.TimeScheduler = TimeScheduler;
|
|
5610
|
-
exports.
|
|
5611
|
-
exports.UIElement = UIElement$1;
|
|
5612
|
-
exports.UIFlex = UIFlex;
|
|
5613
|
-
exports.UIFragment = UIFragment;
|
|
5614
|
-
exports.UIHTMLWrapper = UIHTMLWrapper;
|
|
3117
|
+
exports.UIElement = UIElement;
|
|
5615
3118
|
exports.UINode = UINode;
|
|
5616
|
-
exports.UISVGWrapper = UISVGWrapper;
|
|
5617
|
-
exports.UISuspense = UISuspense;
|
|
5618
|
-
exports.UISvg = UISvg;
|
|
5619
|
-
exports.UISwap = UISwap;
|
|
5620
|
-
exports.UISwitch = UISwitch;
|
|
5621
|
-
exports.UIView = UIView;
|
|
5622
|
-
exports.UseRoot = UseRoot;
|
|
5623
|
-
exports.UseThread = UseThread;
|
|
5624
|
-
exports.View = View;
|
|
5625
3119
|
exports.ViewEvent = ViewEvent;
|
|
5626
3120
|
exports.ViewListeners = ViewListeners;
|
|
5627
|
-
exports.ZikoApp = ZikoApp;
|
|
5628
|
-
exports.ZikoSPA = ZikoSPA;
|
|
5629
3121
|
exports.ZikoUIText = ZikoUIText;
|
|
5630
3122
|
exports.abs = abs;
|
|
5631
3123
|
exports.accum_max = accum_max;
|
|
5632
3124
|
exports.accum_min = accum_min;
|
|
5633
|
-
exports.accum_prod = accum_prod;
|
|
5634
3125
|
exports.accum_product = accum_product;
|
|
5635
3126
|
exports.accum_sum = accum_sum;
|
|
5636
|
-
exports.acos = acos
|
|
3127
|
+
exports.acos = acos;
|
|
5637
3128
|
exports.acosh = acosh;
|
|
5638
3129
|
exports.acot = acot;
|
|
5639
3130
|
exports.add = add;
|
|
5640
3131
|
exports.add_class = add_class;
|
|
5641
3132
|
exports.add_vendor_prefix = add_vendor_prefix;
|
|
5642
|
-
exports.and = and;
|
|
5643
3133
|
exports.animation = animation;
|
|
5644
|
-
exports.apply_fun = apply_fun;
|
|
5645
|
-
exports.arc = arc;
|
|
5646
3134
|
exports.asin = asin;
|
|
5647
3135
|
exports.asinh = asinh;
|
|
5648
3136
|
exports.atan = atan;
|
|
5649
3137
|
exports.atan2 = atan2;
|
|
5650
3138
|
exports.atanh = atanh;
|
|
5651
|
-
exports.back = back;
|
|
5652
|
-
exports.binomial = binomial;
|
|
5653
3139
|
exports.call_with_optional_props = call_with_optional_props;
|
|
3140
|
+
exports.camel2constantcase = camel2constantcase;
|
|
3141
|
+
exports.camel2hyphencase = camel2hyphencase$1;
|
|
3142
|
+
exports.camel2pascalcase = camel2pascalcase;
|
|
3143
|
+
exports.camel2snakecase = camel2snakecase;
|
|
5654
3144
|
exports.cbrt = cbrt;
|
|
5655
3145
|
exports.ceil = ceil;
|
|
5656
3146
|
exports.clamp = clamp;
|
|
5657
3147
|
exports.clock = clock;
|
|
5658
3148
|
exports.cloneUI = cloneUI;
|
|
5659
|
-
exports.
|
|
3149
|
+
exports.constant2camelcase = constant2camelcase;
|
|
3150
|
+
exports.constant2hyphencase = constant2hyphencase;
|
|
3151
|
+
exports.constant2pascalcase = constant2pascalcase;
|
|
3152
|
+
exports.constant2snakecase = constant2snakecase;
|
|
5660
3153
|
exports.contraharmonic_mean = contraharmonic_mean;
|
|
5661
|
-
exports.cos = cos$
|
|
5662
|
-
exports.cosh = cosh$
|
|
3154
|
+
exports.cos = cos$1;
|
|
3155
|
+
exports.cosh = cosh$1;
|
|
5663
3156
|
exports.coth = coth;
|
|
5664
3157
|
exports.croot = croot;
|
|
5665
|
-
exports.csv2arr = csv2arr;
|
|
5666
|
-
exports.csv2json = csv2json;
|
|
5667
|
-
exports.csv2matrix = csv2matrix;
|
|
5668
|
-
exports.csv2object = csv2object;
|
|
5669
|
-
exports.csv2sql = csv2sql;
|
|
5670
3158
|
exports.debounce = debounce;
|
|
5671
|
-
exports.defineParamsGetter = defineParamsGetter;
|
|
5672
|
-
exports.define_wc = define_wc;
|
|
5673
3159
|
exports.deg2rad = deg2rad;
|
|
5674
|
-
exports.discret = discret;
|
|
5675
3160
|
exports.div = div;
|
|
5676
|
-
exports.elastic = elastic;
|
|
5677
3161
|
exports.ema = ema;
|
|
5678
|
-
exports.exp = exp
|
|
3162
|
+
exports.exp = exp;
|
|
5679
3163
|
exports.floor = floor;
|
|
5680
3164
|
exports.fract = fract;
|
|
5681
3165
|
exports.geo_mean = geo_mean;
|
|
5682
3166
|
exports.harmonic_mean = harmonic_mean;
|
|
3167
|
+
exports.hyphen2camelcase = hyphen2camelcase;
|
|
3168
|
+
exports.hyphen2constantcase = hyphen2constantcase;
|
|
3169
|
+
exports.hyphen2pascalcase = hyphen2pascalcase;
|
|
3170
|
+
exports.hyphen2snakecase = hyphen2snakecase;
|
|
5683
3171
|
exports.hypot = hypot;
|
|
5684
|
-
exports.in_back = in_back;
|
|
5685
|
-
exports.in_bounce = in_bounce;
|
|
5686
|
-
exports.in_circ = in_circ;
|
|
5687
|
-
exports.in_cubic = in_cubic;
|
|
5688
|
-
exports.in_elastic = in_elastic;
|
|
5689
|
-
exports.in_expo = in_expo;
|
|
5690
|
-
exports.in_out_back = in_out_back;
|
|
5691
|
-
exports.in_out_bounce = in_out_bounce;
|
|
5692
|
-
exports.in_out_circ = in_out_circ;
|
|
5693
|
-
exports.in_out_cubic = in_out_cubic;
|
|
5694
|
-
exports.in_out_elastic = in_out_elastic;
|
|
5695
|
-
exports.in_out_expo = in_out_expo;
|
|
5696
|
-
exports.in_out_quad = in_out_quad;
|
|
5697
|
-
exports.in_out_quart = in_out_quart;
|
|
5698
|
-
exports.in_out_quint = in_out_quint;
|
|
5699
|
-
exports.in_out_sin = in_out_sin;
|
|
5700
|
-
exports.in_quad = in_quad;
|
|
5701
|
-
exports.in_quart = in_quart;
|
|
5702
|
-
exports.in_quint = in_quint;
|
|
5703
|
-
exports.in_sin = in_sin;
|
|
5704
3172
|
exports.interquartile_mean = interquartile_mean;
|
|
5705
3173
|
exports.iqr = iqr;
|
|
5706
3174
|
exports.isStateGetter = isStateGetter;
|
|
3175
|
+
exports.is_anagram = is_anagram;
|
|
3176
|
+
exports.is_camelcase = is_camelcase$1;
|
|
3177
|
+
exports.is_hyphencase = is_hyphencase;
|
|
3178
|
+
exports.is_isogram = is_isogram;
|
|
3179
|
+
exports.is_palindrome = is_palindrome;
|
|
3180
|
+
exports.is_pascalcalse = is_pascalcalse;
|
|
5707
3181
|
exports.is_primitive = is_primitive;
|
|
5708
|
-
exports.
|
|
5709
|
-
exports.json2css = json2css;
|
|
5710
|
-
exports.json2csv = json2csv;
|
|
5711
|
-
exports.json2csvFile = json2csvFile;
|
|
5712
|
-
exports.json2xml = json2xml;
|
|
5713
|
-
exports.json2xmlFile = json2xmlFile;
|
|
5714
|
-
exports.json2yml = json2yml;
|
|
5715
|
-
exports.json2ymlFile = json2ymlFile;
|
|
3182
|
+
exports.is_snakeCase = is_snakeCase;
|
|
5716
3183
|
exports.lerp = lerp;
|
|
5717
|
-
exports.linear = linear;
|
|
5718
3184
|
exports.linkStyle = linkStyle;
|
|
5719
3185
|
exports.ln = ln;
|
|
5720
3186
|
exports.loop = loop;
|
|
5721
3187
|
exports.map = map$1;
|
|
5722
|
-
exports.mapfun = mapfun$1;
|
|
5723
|
-
exports.matrix = matrix;
|
|
5724
|
-
exports.matrix2 = matrix2;
|
|
5725
|
-
exports.matrix3 = matrix3;
|
|
5726
|
-
exports.matrix4 = matrix4;
|
|
5727
|
-
exports.max = max;
|
|
5728
3188
|
exports.mean = mean;
|
|
5729
3189
|
exports.median = median;
|
|
5730
3190
|
exports.midhinge = midhinge;
|
|
5731
3191
|
exports.midrange = midrange;
|
|
5732
|
-
exports.min = min;
|
|
5733
3192
|
exports.modulo = modulo;
|
|
5734
3193
|
exports.mul = mul;
|
|
5735
|
-
exports.nand = nand;
|
|
5736
|
-
exports.nor = nor;
|
|
5737
3194
|
exports.norm = norm;
|
|
5738
3195
|
exports.normalize_css_value = normalize_css_value;
|
|
5739
|
-
exports.not = not;
|
|
5740
3196
|
exports.nthr = nthr;
|
|
5741
|
-
exports.or = or;
|
|
5742
|
-
exports.out_back = out_back;
|
|
5743
|
-
exports.out_bounce = out_bounce;
|
|
5744
|
-
exports.out_circ = out_circ;
|
|
5745
|
-
exports.out_cubic = out_cubic;
|
|
5746
|
-
exports.out_elastic = out_elastic;
|
|
5747
|
-
exports.out_expo = out_expo;
|
|
5748
|
-
exports.out_quad = out_quad;
|
|
5749
|
-
exports.out_quart = out_quart;
|
|
5750
|
-
exports.out_quint = out_quint;
|
|
5751
|
-
exports.out_sin = out_sin;
|
|
5752
|
-
exports.parseXML = parseXML;
|
|
5753
3197
|
exports.parse_props = parse_props;
|
|
3198
|
+
exports.pascal2camelcase = pascal2camelcase;
|
|
3199
|
+
exports.pascal2constantcase = pascal2constantcase;
|
|
3200
|
+
exports.pascal2hyphencase = pascal2hyphencase;
|
|
3201
|
+
exports.pascal2snakecase = pascal2snakecase;
|
|
5754
3202
|
exports.percentile = percentile;
|
|
5755
|
-
exports.pow = pow
|
|
3203
|
+
exports.pow = pow;
|
|
5756
3204
|
exports.power_mean = power_mean;
|
|
5757
3205
|
exports.q1 = q1;
|
|
5758
3206
|
exports.q3 = q3;
|
|
@@ -5771,20 +3219,19 @@ exports.script = script;
|
|
|
5771
3219
|
exports.sec = sec;
|
|
5772
3220
|
exports.sig = sig;
|
|
5773
3221
|
exports.sign = sign;
|
|
5774
|
-
exports.sin = sin$
|
|
5775
|
-
exports.sinh = sinh
|
|
3222
|
+
exports.sin = sin$1;
|
|
3223
|
+
exports.sinh = sinh;
|
|
5776
3224
|
exports.sleep = sleep;
|
|
5777
3225
|
exports.sma = sma;
|
|
5778
|
-
exports.
|
|
3226
|
+
exports.snake2camelcase = snake2camelcase;
|
|
3227
|
+
exports.snake2constantcase = snake2constantcase;
|
|
3228
|
+
exports.snake2hyphencase = snake2hyphencase;
|
|
3229
|
+
exports.snake2pascalcase = snake2pascalcase;
|
|
3230
|
+
exports.sqrt = sqrt;
|
|
5779
3231
|
exports.std = std;
|
|
5780
|
-
exports.step = step;
|
|
5781
3232
|
exports.step_fps = step_fps;
|
|
5782
3233
|
exports.style = style;
|
|
5783
3234
|
exports.sub = sub;
|
|
5784
|
-
exports.svg2ascii = svg2ascii;
|
|
5785
|
-
exports.svg2img = svg2img;
|
|
5786
|
-
exports.svg2imgUrl = svg2imgUrl;
|
|
5787
|
-
exports.svg2str = svg2str;
|
|
5788
3235
|
exports.tags = tags;
|
|
5789
3236
|
exports.tan = tan;
|
|
5790
3237
|
exports.tanh = tanh;
|
|
@@ -5799,26 +3246,15 @@ exports.trunc = trunc;
|
|
|
5799
3246
|
exports.useDerived = useDerived;
|
|
5800
3247
|
exports.useEffect = useEffect;
|
|
5801
3248
|
exports.useEventEmitter = useEventEmitter;
|
|
5802
|
-
exports.useIPC = useIPC;
|
|
5803
|
-
exports.useLocalStorage = useLocalStorage;
|
|
5804
|
-
exports.useMediaQuery = useMediaQuery;
|
|
5805
|
-
exports.useQueryParams = useQueryParams;
|
|
5806
3249
|
exports.useReactive = useReactive;
|
|
5807
|
-
exports.useRoot = useRoot;
|
|
5808
|
-
exports.useSessionStorage = useSessionStorage;
|
|
5809
3250
|
exports.useState = useState;
|
|
5810
|
-
exports.useThread = useThread;
|
|
5811
|
-
exports.useTitle = useTitle;
|
|
5812
3251
|
exports.variance = variance;
|
|
5813
3252
|
exports.wait = wait;
|
|
5814
3253
|
exports.waitElm = waitElm;
|
|
5815
3254
|
exports.waitForUIElm = waitForUIElm;
|
|
5816
3255
|
exports.waitForUIElmSync = waitForUIElmSync;
|
|
5817
|
-
exports.watchQueryParams = watchQueryParams;
|
|
5818
3256
|
exports.weighted_mean = weighted_mean;
|
|
5819
3257
|
exports.weighted_std = weighted_std;
|
|
5820
3258
|
exports.weighted_variance = weighted_variance;
|
|
5821
3259
|
exports.winsorized_mean = winsorized_mean;
|
|
5822
3260
|
exports.wma = wma;
|
|
5823
|
-
exports.xnor = xnor;
|
|
5824
|
-
exports.xor = xor;
|