ziko 1.1.0 → 1.2.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 +225 -458
- package/dist/ziko.js +225 -458
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +224 -442
- package/package.json +1 -1
- package/src/__ziko__/__state__.js +10 -10
- package/src/data/converter/index.js +6 -6
- package/src/data/converter/object.js +6 -2
- package/src/hooks/use-reactive.js +1 -1
- package/src/hooks/use-state.js +30 -28
- package/src/hooks/use-storage.js +99 -80
- package/src/math/functions/mapfun/index.d.ts +1 -1
- package/src/math/index.d.ts.txt +5 -0
- package/src/math/index.js +4 -4
- package/src/math/utils/index.js +100 -94
- package/src/math/utils/mapfun.js +1 -2
- package/src/math/index.d.ts +0 -5
- /package/src/math/functions/utils/{mapfun.d.ts → mapfun.d.ts.txt} +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 : Thu
|
|
5
|
+
Date : Thu Jul 30 2026 14:31:45 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
|
|
@@ -15,18 +15,18 @@ const EPSILON=Number.EPSILON;
|
|
|
15
15
|
|
|
16
16
|
const is_primitive = value => typeof value !== 'object' && typeof value !== 'function' || value === null;
|
|
17
17
|
|
|
18
|
-
const mapfun=(fun,...X)=>{
|
|
18
|
+
const mapfun$1=(fun,...X)=>{
|
|
19
19
|
const Y=X.map(x=>{
|
|
20
20
|
if(is_primitive(x) || x?.__mapfun__) return fun(x)
|
|
21
|
-
if(x instanceof Array) return x.map(n=>mapfun(fun,n));
|
|
21
|
+
if(x instanceof Array) return x.map(n=>mapfun$1(fun,n));
|
|
22
22
|
if(ArrayBuffer.isView(x)) return x.map(n=>fun(n));
|
|
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)))
|
|
23
|
+
if(x instanceof Set) return new Set(mapfun$1(fun,...[...x]));
|
|
24
|
+
if(x instanceof Map) return new Map([...x].map(n=>[n[0],mapfun$1(fun,n[1])]));
|
|
25
|
+
if(x.isMatrix?.()) return new x.constructor(x.rows, x.cols, mapfun$1(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(fun,n[1])]
|
|
29
|
+
n=>n=[n[0],mapfun$1(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(fn, ...x);
|
|
47
|
+
if (x instanceof Array) mapfun$1(fn, ...x);
|
|
48
48
|
return fn(x)
|
|
49
49
|
};
|
|
50
50
|
|
|
@@ -527,7 +527,7 @@ const complex=(a,b)=>{
|
|
|
527
527
|
|
|
528
528
|
const PRECESION = 8;
|
|
529
529
|
|
|
530
|
-
const abs = (...x) => mapfun(
|
|
530
|
+
const abs = (...x) => mapfun$1(
|
|
531
531
|
x =>{
|
|
532
532
|
if(x.isComplex?.()) return x.z;
|
|
533
533
|
return Math.abs(x)
|
|
@@ -537,7 +537,7 @@ const abs = (...x) => mapfun(
|
|
|
537
537
|
|
|
538
538
|
const pow$1 = (...x) => {
|
|
539
539
|
const n = x.pop();
|
|
540
|
-
return mapfun(
|
|
540
|
+
return mapfun$1(
|
|
541
541
|
x => {
|
|
542
542
|
if(x.isComplex?.()) {
|
|
543
543
|
if(n.isComplex?.()) return new x.constructor({
|
|
@@ -556,7 +556,7 @@ const pow$1 = (...x) => {
|
|
|
556
556
|
)
|
|
557
557
|
};
|
|
558
558
|
|
|
559
|
-
const sqrt$2 = (...x) => mapfun(
|
|
559
|
+
const sqrt$2 = (...x) => mapfun$1(
|
|
560
560
|
x=>{
|
|
561
561
|
if(x.isComplex?.())
|
|
562
562
|
return new x.constructor({z: x.z**(1/2), phi: x.phi/2});
|
|
@@ -566,7 +566,7 @@ const sqrt$2 = (...x) => mapfun(
|
|
|
566
566
|
...x
|
|
567
567
|
);
|
|
568
568
|
|
|
569
|
-
const cbrt = (...x) => mapfun(
|
|
569
|
+
const cbrt = (...x) => mapfun$1(
|
|
570
570
|
x=>{
|
|
571
571
|
if(x.isComplex?.())
|
|
572
572
|
return new x.constructor({z: x.z**(1/3), phi: x.phi/3}).toFixed(PRECESION)
|
|
@@ -578,7 +578,7 @@ const cbrt = (...x) => mapfun(
|
|
|
578
578
|
const nthr = (...x) => {
|
|
579
579
|
const n = x.pop();
|
|
580
580
|
if(typeof n !== 'number') throw Error('nthr expects a real number n');
|
|
581
|
-
return mapfun(
|
|
581
|
+
return mapfun$1(
|
|
582
582
|
x => {
|
|
583
583
|
if(x.isComplex?.()) return new x.constructor({z: x.z ** (1/n), phi: x.phi / n});
|
|
584
584
|
if(x<0) return n %2 ===2
|
|
@@ -593,7 +593,7 @@ const nthr = (...x) => {
|
|
|
593
593
|
const croot = (...x) =>{
|
|
594
594
|
const c = x.pop();
|
|
595
595
|
if(!c.isComplex?.()) throw Error('croot expect Complex number as root')
|
|
596
|
-
return mapfun(
|
|
596
|
+
return mapfun$1(
|
|
597
597
|
x => {
|
|
598
598
|
if(typeof x === 'number') x = new c.constructor(x, 0);
|
|
599
599
|
const {a : c_a, b : c_b} = c;
|
|
@@ -610,7 +610,7 @@ const croot = (...x) =>{
|
|
|
610
610
|
)
|
|
611
611
|
};
|
|
612
612
|
|
|
613
|
-
const exp$1 = (...x) => mapfun(
|
|
613
|
+
const exp$1 = (...x) => mapfun$1(
|
|
614
614
|
x => {
|
|
615
615
|
if(x.isComplex?.()) return new x.constructor(
|
|
616
616
|
Math.exp(x.a) * Math.cos(x.b),
|
|
@@ -621,7 +621,7 @@ const exp$1 = (...x) => mapfun(
|
|
|
621
621
|
,...x
|
|
622
622
|
);
|
|
623
623
|
|
|
624
|
-
const ln = (...x) => mapfun(
|
|
624
|
+
const ln = (...x) => mapfun$1(
|
|
625
625
|
x => {
|
|
626
626
|
if(x.isComplex?.()) return new x.constructor(
|
|
627
627
|
Math.log(x.z),
|
|
@@ -632,7 +632,7 @@ const ln = (...x) => mapfun(
|
|
|
632
632
|
,...x
|
|
633
633
|
);
|
|
634
634
|
|
|
635
|
-
const sign = (...x) => mapfun(
|
|
635
|
+
const sign = (...x) => mapfun$1(
|
|
636
636
|
x => {
|
|
637
637
|
if(x.isComplex?.()){
|
|
638
638
|
const {z, phi} = x;
|
|
@@ -644,7 +644,7 @@ const sign = (...x) => mapfun(
|
|
|
644
644
|
,...x
|
|
645
645
|
);
|
|
646
646
|
|
|
647
|
-
const floor = (...x) => mapfun(
|
|
647
|
+
const floor = (...x) => mapfun$1(
|
|
648
648
|
x => {
|
|
649
649
|
if(x.isComplex?.()) return new x.constructor(
|
|
650
650
|
Math.floor(x.a),
|
|
@@ -654,7 +654,7 @@ const floor = (...x) => mapfun(
|
|
|
654
654
|
},
|
|
655
655
|
...x
|
|
656
656
|
);
|
|
657
|
-
const ceil = (...x) => mapfun(
|
|
657
|
+
const ceil = (...x) => mapfun$1(
|
|
658
658
|
x => {
|
|
659
659
|
if(x.isComplex?.()) return new x.constructor(
|
|
660
660
|
Math.ceil(x.a),
|
|
@@ -664,7 +664,7 @@ const ceil = (...x) => mapfun(
|
|
|
664
664
|
},
|
|
665
665
|
...x
|
|
666
666
|
);
|
|
667
|
-
const round = (...x) => mapfun(
|
|
667
|
+
const round = (...x) => mapfun$1(
|
|
668
668
|
x => {
|
|
669
669
|
if(x.isComplex?.()) return new x.constructor(
|
|
670
670
|
Math.round(x.a),
|
|
@@ -675,7 +675,7 @@ const round = (...x) => mapfun(
|
|
|
675
675
|
...x
|
|
676
676
|
);
|
|
677
677
|
|
|
678
|
-
const trunc = (...x) => mapfun(
|
|
678
|
+
const trunc = (...x) => mapfun$1(
|
|
679
679
|
x => {
|
|
680
680
|
if(x.isComplex?.()) return new x.constructor(
|
|
681
681
|
Math.trunc(x.a),
|
|
@@ -686,7 +686,7 @@ const trunc = (...x) => mapfun(
|
|
|
686
686
|
...x
|
|
687
687
|
);
|
|
688
688
|
|
|
689
|
-
const fract = (...x) => mapfun(
|
|
689
|
+
const fract = (...x) => mapfun$1(
|
|
690
690
|
x => {
|
|
691
691
|
if(x.isComplex?.()) return new x.constructor(
|
|
692
692
|
x.a - Math.trunc(x.a),
|
|
@@ -697,7 +697,7 @@ const fract = (...x) => mapfun(
|
|
|
697
697
|
...x
|
|
698
698
|
);
|
|
699
699
|
|
|
700
|
-
const cos$3 = (...x) => mapfun(
|
|
700
|
+
const cos$3 = (...x) => mapfun$1(
|
|
701
701
|
x => {
|
|
702
702
|
if(x.isComplex?.()) return new x.constructor(
|
|
703
703
|
Math.cos(x.a) * Math.cosh(x.b),
|
|
@@ -708,7 +708,7 @@ const cos$3 = (...x) => mapfun(
|
|
|
708
708
|
,...x
|
|
709
709
|
);
|
|
710
710
|
|
|
711
|
-
const sin$3 = (...x) => mapfun(
|
|
711
|
+
const sin$3 = (...x) => mapfun$1(
|
|
712
712
|
x =>{
|
|
713
713
|
if(x?.isComplex) return new x.constructor(
|
|
714
714
|
Math.sin(x.a) * Math.cosh(x.b),
|
|
@@ -719,7 +719,7 @@ const sin$3 = (...x) => mapfun(
|
|
|
719
719
|
, ...x
|
|
720
720
|
);
|
|
721
721
|
|
|
722
|
-
const tan = (...x) => mapfun(
|
|
722
|
+
const tan = (...x) => mapfun$1(
|
|
723
723
|
x =>{
|
|
724
724
|
if(x?.isComplex){
|
|
725
725
|
const D = Math.cos(2*x.a) + Math.cosh(2*x.b);
|
|
@@ -733,7 +733,7 @@ const tan = (...x) => mapfun(
|
|
|
733
733
|
...x
|
|
734
734
|
);
|
|
735
735
|
|
|
736
|
-
const sec = (...x) => mapfun(
|
|
736
|
+
const sec = (...x) => mapfun$1(
|
|
737
737
|
x => {
|
|
738
738
|
if(x.isComplex?.()) ;
|
|
739
739
|
return + (1 / Math.cos(x)).toFixed(PRECESION)
|
|
@@ -741,7 +741,7 @@ const sec = (...x) => mapfun(
|
|
|
741
741
|
,...x
|
|
742
742
|
);
|
|
743
743
|
|
|
744
|
-
const acos$1 = (...x) => mapfun(
|
|
744
|
+
const acos$1 = (...x) => mapfun$1(
|
|
745
745
|
x =>{
|
|
746
746
|
if(x?.isComplex){
|
|
747
747
|
const { a, b } = x;
|
|
@@ -759,7 +759,7 @@ const acos$1 = (...x) => mapfun(
|
|
|
759
759
|
...x
|
|
760
760
|
);
|
|
761
761
|
|
|
762
|
-
const asin = (...x) => mapfun(
|
|
762
|
+
const asin = (...x) => mapfun$1(
|
|
763
763
|
x => {
|
|
764
764
|
if(x?.isComplex){
|
|
765
765
|
const { a, b } = x;
|
|
@@ -775,7 +775,7 @@ const asin = (...x) => mapfun(
|
|
|
775
775
|
...x
|
|
776
776
|
);
|
|
777
777
|
|
|
778
|
-
const atan = (...x) => mapfun(
|
|
778
|
+
const atan = (...x) => mapfun$1(
|
|
779
779
|
x => {
|
|
780
780
|
if(x?.isComplex){
|
|
781
781
|
const { a, b } = x;
|
|
@@ -789,7 +789,7 @@ const atan = (...x) => mapfun(
|
|
|
789
789
|
...x
|
|
790
790
|
);
|
|
791
791
|
|
|
792
|
-
const acot = (...x) => mapfun(
|
|
792
|
+
const acot = (...x) => mapfun$1(
|
|
793
793
|
x => {
|
|
794
794
|
if(x?.isComplex){
|
|
795
795
|
const { a, b } = x;
|
|
@@ -804,7 +804,7 @@ const acot = (...x) => mapfun(
|
|
|
804
804
|
);
|
|
805
805
|
|
|
806
806
|
|
|
807
|
-
const cosh$2 = (...x) => mapfun(
|
|
807
|
+
const cosh$2 = (...x) => mapfun$1(
|
|
808
808
|
x =>{
|
|
809
809
|
if(x?.isComplex) return new x.constructor(
|
|
810
810
|
Math.cosh(x.a) * Math.cos(x.b),
|
|
@@ -814,7 +814,7 @@ const cosh$2 = (...x) => mapfun(
|
|
|
814
814
|
},
|
|
815
815
|
...x
|
|
816
816
|
);
|
|
817
|
-
const sinh$1 = (...x) => mapfun(
|
|
817
|
+
const sinh$1 = (...x) => mapfun$1(
|
|
818
818
|
x =>{
|
|
819
819
|
if(x?.isComplex) return new x.constructor(
|
|
820
820
|
Math.sinh(x.a) * Math.cos(x.b),
|
|
@@ -824,7 +824,7 @@ const sinh$1 = (...x) => mapfun(
|
|
|
824
824
|
},
|
|
825
825
|
...x
|
|
826
826
|
);
|
|
827
|
-
const tanh = (...x) => mapfun(
|
|
827
|
+
const tanh = (...x) => mapfun$1(
|
|
828
828
|
x =>{
|
|
829
829
|
if(x?.isComplex){
|
|
830
830
|
const D = Math.cosh(2*a) + Math.cos(2*b);
|
|
@@ -838,7 +838,7 @@ const tanh = (...x) => mapfun(
|
|
|
838
838
|
...x
|
|
839
839
|
);
|
|
840
840
|
|
|
841
|
-
const coth = (...x) => mapfun(
|
|
841
|
+
const coth = (...x) => mapfun$1(
|
|
842
842
|
x =>{
|
|
843
843
|
if(x?.isComplex){
|
|
844
844
|
const {a, b} = x;
|
|
@@ -853,7 +853,7 @@ const coth = (...x) => mapfun(
|
|
|
853
853
|
...x
|
|
854
854
|
);
|
|
855
855
|
|
|
856
|
-
const acosh = (...x) => mapfun(
|
|
856
|
+
const acosh = (...x) => mapfun$1(
|
|
857
857
|
x =>{
|
|
858
858
|
if(x?.isComplex){
|
|
859
859
|
return ln(x.clone().add(sqrt$2(x.clone().mul(x.clone()).sub(1))))
|
|
@@ -863,7 +863,7 @@ const acosh = (...x) => mapfun(
|
|
|
863
863
|
...x
|
|
864
864
|
);
|
|
865
865
|
|
|
866
|
-
const asinh = (...x) => mapfun(
|
|
866
|
+
const asinh = (...x) => mapfun$1(
|
|
867
867
|
x =>{
|
|
868
868
|
if(x?.isComplex){
|
|
869
869
|
return ln(x.clone().add(sqrt$2(x.clone().mul(x.clone()).add(1))))
|
|
@@ -873,7 +873,7 @@ const asinh = (...x) => mapfun(
|
|
|
873
873
|
...x
|
|
874
874
|
);
|
|
875
875
|
|
|
876
|
-
const atanh = (...x) => mapfun(
|
|
876
|
+
const atanh = (...x) => mapfun$1(
|
|
877
877
|
x =>{
|
|
878
878
|
if(x?.isComplex);
|
|
879
879
|
return + Math.atanh(x).toFixed(PRECESION)
|
|
@@ -881,7 +881,7 @@ const atanh = (...x) => mapfun(
|
|
|
881
881
|
...x
|
|
882
882
|
);
|
|
883
883
|
|
|
884
|
-
const sig = (...x) => mapfun(
|
|
884
|
+
const sig = (...x) => mapfun$1(
|
|
885
885
|
x =>{
|
|
886
886
|
if(x?.isComplex);
|
|
887
887
|
return 1/(1 + Math.exp(-x)).toFixed(PRECESION)
|
|
@@ -889,8 +889,8 @@ const sig = (...x) => mapfun(
|
|
|
889
889
|
...x
|
|
890
890
|
);
|
|
891
891
|
|
|
892
|
-
const deg2rad = (...deg) => mapfun(x => x * Math.PI / 180, ...deg);
|
|
893
|
-
const rad2deg = (...rad) => mapfun(x => x / Math.PI * 180, ...rad);
|
|
892
|
+
const deg2rad = (...deg) => mapfun$1(x => x * Math.PI / 180, ...deg);
|
|
893
|
+
const rad2deg = (...rad) => mapfun$1(x => x / Math.PI * 180, ...rad);
|
|
894
894
|
|
|
895
895
|
const norm = (x, min, max) => apply_fun(
|
|
896
896
|
x,
|
|
@@ -921,10 +921,10 @@ const hypot = (...x) => {
|
|
|
921
921
|
|
|
922
922
|
const atan2 = (y, x, rad = true) => {
|
|
923
923
|
if (y instanceof Array && !(x instanceof Array))
|
|
924
|
-
return mapfun(n => atan2(n, x, rad), ...y);
|
|
924
|
+
return mapfun$1(n => atan2(n, x, rad), ...y);
|
|
925
925
|
|
|
926
926
|
if (x instanceof Array && !(y instanceof Array))
|
|
927
|
-
return mapfun(n => atan2(y, n, rad), ...x);
|
|
927
|
+
return mapfun$1(n => atan2(y, n, rad), ...x);
|
|
928
928
|
|
|
929
929
|
if (y instanceof Array && x instanceof Array)
|
|
930
930
|
return y.map((v, i) => atan2(v, x[i], rad));
|
|
@@ -1161,7 +1161,7 @@ class Matrix{
|
|
|
1161
1161
|
return new Matrix(this.rows, this.cols, this.arr.flat(1));
|
|
1162
1162
|
}
|
|
1163
1163
|
toComplex(){
|
|
1164
|
-
this.arr = mapfun(
|
|
1164
|
+
this.arr = mapfun$1(
|
|
1165
1165
|
x => x?.isComplex?.() ? x : new Complex(x, 0),
|
|
1166
1166
|
...this.arr
|
|
1167
1167
|
);
|
|
@@ -1625,7 +1625,7 @@ class Matrix{
|
|
|
1625
1625
|
return new Matrix(v.length, 1, v);
|
|
1626
1626
|
}
|
|
1627
1627
|
serialize() {
|
|
1628
|
-
const arr = mapfun(x => x.serialize?.() || x, ...this.arr);
|
|
1628
|
+
const arr = mapfun$1(x => x.serialize?.() || x, ...this.arr);
|
|
1629
1629
|
return JSON.stringify({
|
|
1630
1630
|
type : 'matrix',
|
|
1631
1631
|
data : {
|
|
@@ -1640,7 +1640,7 @@ class Matrix{
|
|
|
1640
1640
|
const {type, data} = json;
|
|
1641
1641
|
if(type !== 'matrix') return TypeError('Not a valid Matrix')
|
|
1642
1642
|
let {arr} = data;
|
|
1643
|
-
arr = mapfun(x => {
|
|
1643
|
+
arr = mapfun$1(x => {
|
|
1644
1644
|
if(typeof x === 'string') {
|
|
1645
1645
|
const x_obj = JSON.parse(x);
|
|
1646
1646
|
const {type} = x_obj;
|
|
@@ -1671,186 +1671,6 @@ const matrix2=(...element)=>new Matrix(2, 2, element);
|
|
|
1671
1671
|
const matrix3=(...element)=>new Matrix(3, 3, element);
|
|
1672
1672
|
const matrix4=(...element)=>new Matrix(4, 4, element);
|
|
1673
1673
|
|
|
1674
|
-
const zeros=(n)=>new Array(n).fill(0);
|
|
1675
|
-
const ones=(n)=>new Array(n).fill(1);
|
|
1676
|
-
const nums=(num,n)=>new Array(n).fill(num);
|
|
1677
|
-
|
|
1678
|
-
const arange=(a, b, step , include = false)=>{
|
|
1679
|
-
let tab = [];
|
|
1680
|
-
if(a<b){
|
|
1681
|
-
for (let i = a; include?i<=b:i<b; i += step) tab.push((i * 10) / 10);
|
|
1682
|
-
}
|
|
1683
|
-
else {
|
|
1684
|
-
for(let i = a; include?i>=b:i>b; i -= step) tab.push((i * 10) / 10);
|
|
1685
|
-
}
|
|
1686
|
-
return tab;
|
|
1687
|
-
};
|
|
1688
|
-
const linspace=(a,b,n=abs(b-a)+1,endpoint=true)=>{
|
|
1689
|
-
if(Math.floor(n)!==n)return;
|
|
1690
|
-
if([a,b].every(n=>typeof n==="number")){
|
|
1691
|
-
const [max,min]=[a,b].sort((a,b)=>b-a);
|
|
1692
|
-
var Y = [];
|
|
1693
|
-
let step ;
|
|
1694
|
-
endpoint ? step = (max - min) / (n - 1) : step = (max - min) / n;
|
|
1695
|
-
for (var i = 0; i < n; i++) {
|
|
1696
|
-
a<b?Y.push(min+step*i):Y.push(max-step*i);
|
|
1697
|
-
}
|
|
1698
|
-
return Y
|
|
1699
|
-
}
|
|
1700
|
-
|
|
1701
|
-
if([a,b].some(n=>n.isComplex?.())){
|
|
1702
|
-
const z1 = new n.constructor(a);
|
|
1703
|
-
const z2 = new n.constructor(b);
|
|
1704
|
-
n=n||Math.abs(z1.a-z2.a)+1;
|
|
1705
|
-
const X=linspace(z1.a,z2.a,n,endpoint);
|
|
1706
|
-
const Y=linspace(z1.b,z2.b,n,endpoint);
|
|
1707
|
-
let Z=new Array(n).fill(null);
|
|
1708
|
-
Z=Z.map((n,i)=> new n.constructor(X[i],Y[i]));
|
|
1709
|
-
return Z;
|
|
1710
|
-
}
|
|
1711
|
-
};
|
|
1712
|
-
const logspace=(a,b,n=b-a+1,base=E,endpoint=true)=>{
|
|
1713
|
-
return linspace(a,b,n,endpoint).map(n=>pow$1(base,n))
|
|
1714
|
-
};
|
|
1715
|
-
const geomspace=(a,b,n=abs(b-a)+1,endpoint=true)=>{
|
|
1716
|
-
if(Math.floor(n)!==n)return;
|
|
1717
|
-
if([a,b].every(n=>typeof n==="number")){
|
|
1718
|
-
const [max,min]=[a,b].sort((a,b)=>b-a);
|
|
1719
|
-
let base;
|
|
1720
|
-
endpoint ? base = nthr(max/min,n-1) : base = nthr(max/min,n) ;
|
|
1721
|
-
const Y = [min];
|
|
1722
|
-
for (let i = 1; i < n; i++) {
|
|
1723
|
-
Y.push(Y[i-1]*base);
|
|
1724
|
-
}
|
|
1725
|
-
return a<b?Y:Y.reverse()
|
|
1726
|
-
}
|
|
1727
|
-
|
|
1728
|
-
if([a,b].some(n=>n.isComplex?.())){
|
|
1729
|
-
const z1 = new n.constructor(a);
|
|
1730
|
-
const z2 = new n.constructor(b);
|
|
1731
|
-
n=n||Math.abs(z1.a-z2.a)+1;
|
|
1732
|
-
let base;
|
|
1733
|
-
endpoint ? base = nthr(z2.div(z1),n-1) : base = nthr(z2.div(z1),n) ;
|
|
1734
|
-
const Y = [z1];
|
|
1735
|
-
for (let i = 1; i < n; i++) {
|
|
1736
|
-
Y.push(mul(Y[i-1],base));
|
|
1737
|
-
}
|
|
1738
|
-
return Y;
|
|
1739
|
-
}
|
|
1740
|
-
};
|
|
1741
|
-
|
|
1742
|
-
/** @module Math */
|
|
1743
|
-
/**
|
|
1744
|
-
* Checks if a value is within the specified range.
|
|
1745
|
-
* @function
|
|
1746
|
-
* @param {number} x - The value to check.
|
|
1747
|
-
* @param {number} a - The start of the range.
|
|
1748
|
-
* @param {number} b - The end of the range.
|
|
1749
|
-
* @returns {boolean} Returns true if the value is within the range [a, b], otherwise false.
|
|
1750
|
-
*/
|
|
1751
|
-
const inRange = (x, a, b) => {
|
|
1752
|
-
const [min, max] = [Math.min(a, b), Math.max(a, b)];
|
|
1753
|
-
return x >= min && x <= max;
|
|
1754
|
-
};
|
|
1755
|
-
|
|
1756
|
-
/**
|
|
1757
|
-
* Checks if two numbers are approximately equal within a given error margin.
|
|
1758
|
-
* @param {number} a - The first number.
|
|
1759
|
-
* @param {number} b - The second number.
|
|
1760
|
-
* @param {number} [Err=0.0001] - The maximum acceptable difference between the two numbers.
|
|
1761
|
-
* @returns {boolean} Returns true if the two numbers are approximately equal within the specified error margin, otherwise false.
|
|
1762
|
-
*/
|
|
1763
|
-
const isApproximatlyEqual = (a, b, Err = 0.0001) => {
|
|
1764
|
-
return Math.abs(a - b) <= Err;
|
|
1765
|
-
};
|
|
1766
|
-
|
|
1767
|
-
/** @module Math */
|
|
1768
|
-
|
|
1769
|
-
/**
|
|
1770
|
-
* Computes the cartesian product of two arrays.
|
|
1771
|
-
* @param {Array} a - The first array.
|
|
1772
|
-
* @param {Array} b - The second array.
|
|
1773
|
-
* @returns {Array} Returns an array representing the cartesian product of the input arrays.
|
|
1774
|
-
*/
|
|
1775
|
-
const cartesianProduct = (a, b) => a.reduce((p, x) => [...p, ...b.map((y) => [x, y])], []);
|
|
1776
|
-
|
|
1777
|
-
/**
|
|
1778
|
-
* Computes the greatest common divisor (GCD) of two numbers.
|
|
1779
|
-
* @param {number} n1 - The first number.
|
|
1780
|
-
* @param {number} n2 - The second number.
|
|
1781
|
-
* @returns {number} Returns the greatest common divisor of the two input numbers.
|
|
1782
|
-
*/
|
|
1783
|
-
const pgcd = (n1, n2) => {
|
|
1784
|
-
let i,
|
|
1785
|
-
pgcd = 1;
|
|
1786
|
-
if (n1 == floor(n1) && n2 == floor(n2)) {
|
|
1787
|
-
for (i = 2; i <= n1 && i <= n2; ++i) {
|
|
1788
|
-
if (n1 % i == 0 && n2 % i == 0) pgcd = i;
|
|
1789
|
-
}
|
|
1790
|
-
return pgcd;
|
|
1791
|
-
} else console.log("error");
|
|
1792
|
-
};
|
|
1793
|
-
|
|
1794
|
-
/**
|
|
1795
|
-
* Computes the least common multiple (LCM) of two numbers.
|
|
1796
|
-
* @param {number} n1 - The first number.
|
|
1797
|
-
* @param {number} n2 - The second number.
|
|
1798
|
-
* @returns {number} Returns the least common multiple of the two input numbers.
|
|
1799
|
-
*/
|
|
1800
|
-
const ppcm = (n1, n2) => {
|
|
1801
|
-
let ppcm;
|
|
1802
|
-
if (n1 == floor(n1) && n2 == floor(n2)) {
|
|
1803
|
-
ppcm = n1 > n2 ? n1 : n2;
|
|
1804
|
-
while (true) {
|
|
1805
|
-
if (ppcm % n1 == 0 && ppcm % n2 == 0) break;
|
|
1806
|
-
++ppcm;
|
|
1807
|
-
}
|
|
1808
|
-
return ppcm;
|
|
1809
|
-
} else console.log("error");
|
|
1810
|
-
};
|
|
1811
|
-
|
|
1812
|
-
// import { mapfun } from "../mapfun/index.js";
|
|
1813
|
-
// import {
|
|
1814
|
-
// add,
|
|
1815
|
-
// sub,
|
|
1816
|
-
// mul,
|
|
1817
|
-
// div,
|
|
1818
|
-
// modulo
|
|
1819
|
-
// } from "./arithmetic.js";
|
|
1820
|
-
const Utils={
|
|
1821
|
-
// add,
|
|
1822
|
-
// sub,
|
|
1823
|
-
// mul,
|
|
1824
|
-
// div,
|
|
1825
|
-
// modulo,
|
|
1826
|
-
|
|
1827
|
-
zeros,
|
|
1828
|
-
ones,
|
|
1829
|
-
nums,
|
|
1830
|
-
// norm,
|
|
1831
|
-
// lerp,
|
|
1832
|
-
// map,
|
|
1833
|
-
// clamp,
|
|
1834
|
-
arange,
|
|
1835
|
-
linspace,
|
|
1836
|
-
logspace,
|
|
1837
|
-
geomspace,
|
|
1838
|
-
|
|
1839
|
-
// sum,
|
|
1840
|
-
// prod,
|
|
1841
|
-
// accum,
|
|
1842
|
-
|
|
1843
|
-
cartesianProduct,
|
|
1844
|
-
ppcm,
|
|
1845
|
-
pgcd,
|
|
1846
|
-
|
|
1847
|
-
// deg2rad,
|
|
1848
|
-
// rad2deg,
|
|
1849
|
-
|
|
1850
|
-
inRange,
|
|
1851
|
-
isApproximatlyEqual
|
|
1852
|
-
};
|
|
1853
|
-
|
|
1854
1674
|
class UINode {
|
|
1855
1675
|
constructor(node){
|
|
1856
1676
|
this.cache = {
|
|
@@ -2056,115 +1876,134 @@ class UseIPC {
|
|
|
2056
1876
|
const useIPC = (name) => new UseIPC(name);
|
|
2057
1877
|
|
|
2058
1878
|
class UseStorage {
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
globalKey,
|
|
2063
|
-
channel: use_channel ? useIPC(`Ziko:useStorage-${globalKey}`) : null,
|
|
2064
|
-
oldItemKeys: new Set()
|
|
2065
|
-
};
|
|
1879
|
+
static RESERVED_KEYS = new Set([
|
|
1880
|
+
"cache", "items", "set", "add", "remove", "get", "clear", "onStorageUpdated"
|
|
1881
|
+
]);
|
|
2066
1882
|
|
|
2067
|
-
|
|
2068
|
-
|
|
1883
|
+
constructor(storage, globalKey, initialValue, use_channel = true) {
|
|
1884
|
+
this.cache = {
|
|
1885
|
+
storage,
|
|
1886
|
+
globalKey,
|
|
1887
|
+
channel: use_channel ? useIPC(`Ziko:useStorage-${globalKey}`) : null,
|
|
1888
|
+
oldItemKeys: new Set()
|
|
1889
|
+
};
|
|
2069
1890
|
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
if (!raw) return {};
|
|
2073
|
-
try {
|
|
2074
|
-
return JSON.parse(raw);
|
|
2075
|
-
} catch {
|
|
2076
|
-
return {};
|
|
2077
|
-
}
|
|
2078
|
-
}
|
|
1891
|
+
this.#init(initialValue, use_channel);
|
|
1892
|
+
}
|
|
2079
1893
|
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
}
|
|
2088
|
-
#init(initialValue, use_channel) {
|
|
2089
|
-
if (use_channel && this.cache.channel) this.cache.channel.on("Ziko-Storage-Updated", () => this.#maintain());
|
|
2090
|
-
if (!initialValue) {
|
|
2091
|
-
this.#maintain();
|
|
2092
|
-
return;
|
|
2093
|
-
}
|
|
2094
|
-
if (this.cache.storage.getItem(this.cache.globalKey)) {
|
|
2095
|
-
const existing = this.items;
|
|
2096
|
-
Object.keys(existing).forEach(k => this.cache.oldItemKeys.add(k));
|
|
2097
|
-
this.#maintain();
|
|
2098
|
-
}
|
|
2099
|
-
else this.set(initialValue);
|
|
1894
|
+
get items() {
|
|
1895
|
+
const raw = this.cache.storage.getItem(this.cache.globalKey);
|
|
1896
|
+
if (!raw) return {};
|
|
1897
|
+
try {
|
|
1898
|
+
return JSON.parse(raw);
|
|
1899
|
+
} catch {
|
|
1900
|
+
return {};
|
|
2100
1901
|
}
|
|
1902
|
+
}
|
|
2101
1903
|
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
this.#maintain();
|
|
2106
|
-
return this;
|
|
2107
|
-
}
|
|
1904
|
+
#maintain() {
|
|
1905
|
+
const currentItems = this.items;
|
|
1906
|
+
const currentKeys = new Set(Object.keys(currentItems));
|
|
2108
1907
|
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
1908
|
+
// Cleanup keys that were removed
|
|
1909
|
+
this.cache.oldItemKeys.forEach(key => {
|
|
1910
|
+
if (!currentKeys.has(key)) {
|
|
1911
|
+
delete this[key];
|
|
1912
|
+
this.cache.oldItemKeys.delete(key);
|
|
1913
|
+
}
|
|
1914
|
+
});
|
|
1915
|
+
|
|
1916
|
+
// Populate keys from storage onto `this`
|
|
1917
|
+
for (const key in currentItems) {
|
|
1918
|
+
if (!UseStorage.RESERVED_KEYS.has(key)) {
|
|
1919
|
+
this[key] = currentItems[key];
|
|
1920
|
+
this.cache.oldItemKeys.add(key);
|
|
1921
|
+
}
|
|
2115
1922
|
}
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
this.cache.oldItemKeys.delete(key);
|
|
2122
|
-
});
|
|
2123
|
-
this.set(items);
|
|
2124
|
-
return this;
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1925
|
+
#init(initialValue, use_channel) {
|
|
1926
|
+
if (use_channel && this.cache.channel) {
|
|
1927
|
+
this.cache.channel.on("Ziko-Storage-Updated", () => this.#maintain());
|
|
2125
1928
|
}
|
|
2126
|
-
|
|
2127
|
-
|
|
1929
|
+
|
|
1930
|
+
const hasStoredData = this.cache.storage.getItem(this.cache.globalKey) !== null;
|
|
1931
|
+
|
|
1932
|
+
if (hasStoredData) {
|
|
1933
|
+
// Key already exists in storage -> Restore data to instance
|
|
1934
|
+
this.#maintain();
|
|
1935
|
+
} else if (initialValue !== undefined) {
|
|
1936
|
+
// Key doesn't exist -> Seed with initialValue
|
|
1937
|
+
this.set(initialValue);
|
|
1938
|
+
} else {
|
|
1939
|
+
// Key doesn't exist and no initialValue provided -> Default to empty
|
|
1940
|
+
this.#maintain();
|
|
2128
1941
|
}
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
1942
|
+
}
|
|
1943
|
+
|
|
1944
|
+
set(data) {
|
|
1945
|
+
this.cache.storage.setItem(this.cache.globalKey, JSON.stringify(data));
|
|
1946
|
+
if (this.cache.channel) {
|
|
1947
|
+
this.cache.channel.emit("Ziko-Storage-Updated", data);
|
|
2135
1948
|
}
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
1949
|
+
this.#maintain();
|
|
1950
|
+
return this;
|
|
1951
|
+
}
|
|
1952
|
+
|
|
1953
|
+
add(data) {
|
|
1954
|
+
return this.set({
|
|
1955
|
+
...this.items,
|
|
1956
|
+
...data
|
|
1957
|
+
});
|
|
1958
|
+
}
|
|
1959
|
+
|
|
1960
|
+
remove(...keys) {
|
|
1961
|
+
const items = { ...this.items };
|
|
1962
|
+
keys.forEach(key => delete items[key]);
|
|
1963
|
+
return this.set(items);
|
|
1964
|
+
}
|
|
1965
|
+
|
|
1966
|
+
get(key) {
|
|
1967
|
+
return this.items[key];
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
clear() {
|
|
1971
|
+
this.cache.storage.removeItem(this.cache.globalKey);
|
|
1972
|
+
this.#maintain();
|
|
1973
|
+
return this;
|
|
1974
|
+
}
|
|
1975
|
+
|
|
1976
|
+
onStorageUpdated(callback) {
|
|
1977
|
+
if (this.cache.channel) {
|
|
1978
|
+
this.cache.channel.on("Ziko-Storage-Updated", callback);
|
|
2141
1979
|
}
|
|
1980
|
+
return this;
|
|
1981
|
+
}
|
|
2142
1982
|
}
|
|
2143
1983
|
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
new UseStorage(localStorage, key, initialValue, use_channel);
|
|
1984
|
+
const useLocalStorage = (key, initialValue, use_channel = true) =>
|
|
1985
|
+
new UseStorage(localStorage, key, initialValue, use_channel);
|
|
2147
1986
|
|
|
2148
1987
|
const useSessionStorage = (key, initialValue, use_channel = true) =>
|
|
2149
|
-
|
|
1988
|
+
new UseStorage(sessionStorage, key, initialValue, use_channel);
|
|
2150
1989
|
|
|
2151
1990
|
var __State__ = {
|
|
2152
1991
|
store : new Map(),
|
|
2153
1992
|
index : 0,
|
|
2154
1993
|
session_storage : null,
|
|
2155
1994
|
register: function(state){
|
|
2156
|
-
if(!
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
}
|
|
2162
|
-
this.store.set(this.index++, state)
|
|
1995
|
+
// if(!import.meta?.env?.SSR && import.meta?.env?.DEV){
|
|
1996
|
+
// if(!this.session) this.session_storage = useSessionStorage('ziko-state', {})
|
|
1997
|
+
// const savedValue = this.session_storage.get(this.index)
|
|
1998
|
+
// if(!savedValue) this.session_storage.add({[this.index] : state.value});
|
|
1999
|
+
// else state.value = savedValue
|
|
2000
|
+
// }
|
|
2001
|
+
// this.store.set(this.index++, state)
|
|
2163
2002
|
},
|
|
2164
2003
|
update: function(index, value){
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2004
|
+
// if(!import.meta?.env?.SSR && import.meta?.env?.DEV){
|
|
2005
|
+
// this.session_storage.add({[index] : value})
|
|
2006
|
+
// }
|
|
2168
2007
|
},
|
|
2169
2008
|
|
|
2170
2009
|
};
|
|
@@ -2341,57 +2180,61 @@ var LifecycleMethods = /*#__PURE__*/Object.freeze({
|
|
|
2341
2180
|
unmount: unmount
|
|
2342
2181
|
});
|
|
2343
2182
|
|
|
2344
|
-
|
|
2183
|
+
// import { __init__global__ } from "../__ziko__/index.js";
|
|
2184
|
+
|
|
2185
|
+
// if (!globalThis.__Ziko__) __init__global__();
|
|
2345
2186
|
|
|
2346
2187
|
function useState(initialValue) {
|
|
2347
2188
|
|
|
2348
|
-
const
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
});
|
|
2354
|
-
|
|
2355
|
-
let current = store.get(index);
|
|
2189
|
+
const state = {
|
|
2190
|
+
value: initialValue,
|
|
2191
|
+
subscribers: new Set(),
|
|
2192
|
+
paused: false,
|
|
2193
|
+
};
|
|
2356
2194
|
|
|
2357
2195
|
function getValue() {
|
|
2358
2196
|
return {
|
|
2359
|
-
value:
|
|
2197
|
+
value: state.value,
|
|
2360
2198
|
isStateGetter: () => true,
|
|
2361
|
-
_subscribe: (fn) =>
|
|
2199
|
+
_subscribe: (fn) => {
|
|
2200
|
+
state.subscribers.add(fn);
|
|
2201
|
+
return () => state.subscribers.delete(fn);
|
|
2202
|
+
},
|
|
2362
2203
|
};
|
|
2363
2204
|
}
|
|
2364
2205
|
|
|
2365
2206
|
function setValue(newValue) {
|
|
2366
|
-
if (
|
|
2207
|
+
if (state.paused) return;
|
|
2208
|
+
|
|
2367
2209
|
if (typeof newValue === "function") {
|
|
2368
|
-
newValue = newValue(
|
|
2210
|
+
newValue = newValue(state.value);
|
|
2369
2211
|
}
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2212
|
+
|
|
2213
|
+
if (!Object.is(newValue, state.value)) {
|
|
2214
|
+
state.value = newValue;
|
|
2215
|
+
state.subscribers.forEach((fn) => fn(state.value));
|
|
2374
2216
|
}
|
|
2375
2217
|
}
|
|
2376
2218
|
|
|
2377
2219
|
const controller = {
|
|
2378
|
-
pause: () => {
|
|
2379
|
-
resume: () => {
|
|
2380
|
-
clear: () => {
|
|
2220
|
+
pause: () => { state.paused = true; },
|
|
2221
|
+
resume: () => { state.paused = false; },
|
|
2222
|
+
clear: () => { state.subscribers.clear(); },
|
|
2381
2223
|
force: (newValue) => {
|
|
2382
|
-
if (typeof newValue === "function")
|
|
2383
|
-
|
|
2384
|
-
|
|
2224
|
+
if (typeof newValue === "function") {
|
|
2225
|
+
newValue = newValue(state.value);
|
|
2226
|
+
}
|
|
2227
|
+
state.value = newValue;
|
|
2228
|
+
state.subscribers.forEach((fn) => fn(state.value));
|
|
2385
2229
|
},
|
|
2386
|
-
getSubscribers: () => new Set(
|
|
2230
|
+
getSubscribers: () => new Set(state.subscribers),
|
|
2387
2231
|
};
|
|
2388
2232
|
|
|
2389
2233
|
return [getValue, setValue, controller];
|
|
2390
2234
|
}
|
|
2391
2235
|
|
|
2392
|
-
|
|
2393
2236
|
const isStateGetter = (arg) => {
|
|
2394
|
-
return typeof arg ===
|
|
2237
|
+
return typeof arg === "function" && arg?.()?.isStateGetter?.() === true;
|
|
2395
2238
|
};
|
|
2396
2239
|
|
|
2397
2240
|
const camel2hyphencase = (text = '') => text.replace(/[A-Z]/g, match => '-' + match.toLowerCase());
|
|
@@ -4318,110 +4161,6 @@ const svg2ascii=svg=>btoa(svg2str(svg));
|
|
|
4318
4161
|
const svg2imgUrl=svg=>'data:image/svg+xml;base64,'+svg2ascii(svg);
|
|
4319
4162
|
const svg2img=(svg,render=true)=>tags.img(svg2imgUrl(svg)).mount(render);
|
|
4320
4163
|
|
|
4321
|
-
// const obj2str=(object)=>{
|
|
4322
|
-
// const recursiveToString = (obj) => {
|
|
4323
|
-
// if (Array.isArray(obj)) return arr2str(obj);
|
|
4324
|
-
// if (typeof obj === 'object' && obj !== null) {
|
|
4325
|
-
// return `{ ${Object.entries(obj)
|
|
4326
|
-
// .map(([key, value]) => `${key}:${recursiveToString(value)}`)
|
|
4327
|
-
// .join(" , ")} }`;
|
|
4328
|
-
// }
|
|
4329
|
-
// return String(obj);
|
|
4330
|
-
// };
|
|
4331
|
-
// return recursiveToString(object);
|
|
4332
|
-
// };
|
|
4333
|
-
// const obj2str = (object) => {
|
|
4334
|
-
// const recursiveToString = (obj, indentLevel = 0) => {
|
|
4335
|
-
// const indent = ' '.repeat(indentLevel);
|
|
4336
|
-
// const nextIndent = ' '.repeat(indentLevel + 1);
|
|
4337
|
-
// if(Array.isArray(obj)) return arr2str(obj, indentLevel);
|
|
4338
|
-
// if(obj instanceof Complex || obj instanceof Matrix) return obj.toString();
|
|
4339
|
-
// if (typeof obj === 'object' && obj !== null) {
|
|
4340
|
-
// const entries = Object.entries(obj)
|
|
4341
|
-
// .map(([key, value]) => `${nextIndent}${key}: ${recursiveToString(value, indentLevel + 1)}`)
|
|
4342
|
-
// .join(",\n");
|
|
4343
|
-
|
|
4344
|
-
// return `{\n${entries}\n${indent}}`;
|
|
4345
|
-
// }
|
|
4346
|
-
|
|
4347
|
-
// return String(obj);
|
|
4348
|
-
// };
|
|
4349
|
-
|
|
4350
|
-
// return recursiveToString(object);
|
|
4351
|
-
// };
|
|
4352
|
-
// const obj2str = (object, useIndentation = true, indentLevel = 0) => {
|
|
4353
|
-
// const recursiveToString = (obj, level = 0) => {
|
|
4354
|
-
// const indent = useIndentation ? ' '.repeat(level) : '';
|
|
4355
|
-
// const nextIndent = useIndentation ? ' '.repeat(level + 1) : '';
|
|
4356
|
-
// if (Array.isArray(obj)) return arr2str(obj, false, level);
|
|
4357
|
-
// if(obj instanceof Complex || obj instanceof Matrix) return obj.toString();
|
|
4358
|
-
// if (typeof obj === 'object' && obj !== null) {
|
|
4359
|
-
// const entries = Object.entries(obj)
|
|
4360
|
-
// .map(([key, value]) => useIndentation
|
|
4361
|
-
// ? `${nextIndent}${key}: ${recursiveToString(value, level + 1)}`
|
|
4362
|
-
// : `${key}: ${recursiveToString(value, level + 1)}`
|
|
4363
|
-
// ).join(useIndentation ? ",\n" : ", ");
|
|
4364
|
-
|
|
4365
|
-
// return useIndentation
|
|
4366
|
-
// ? `{\n${entries}\n${indent}}`
|
|
4367
|
-
// : `{${entries}}`;
|
|
4368
|
-
// }
|
|
4369
|
-
|
|
4370
|
-
// return String(obj);
|
|
4371
|
-
// };
|
|
4372
|
-
|
|
4373
|
-
// return recursiveToString(object, indentLevel);
|
|
4374
|
-
// };
|
|
4375
|
-
|
|
4376
|
-
const obj2str=(obj)=>JSON.stringify(
|
|
4377
|
-
mapfun(n=>{
|
|
4378
|
-
if(["number","string","boolean","bigint"].includes(typeof n)) return String(n);
|
|
4379
|
-
if(n instanceof Complex || n instanceof Matrix) return n.toString();
|
|
4380
|
-
if(n instanceof Array) return arr2str(n)
|
|
4381
|
-
},
|
|
4382
|
-
obj), null, " ")
|
|
4383
|
-
.replace(/"([^"]+)":/g, '$1:') // Remove Quotes from Keys
|
|
4384
|
-
.replace(/: "([^"]+)"/g, ': $1'); // Remove Quotes from str values
|
|
4385
|
-
|
|
4386
|
-
const getMaxDepth = arr=> {
|
|
4387
|
-
if (!Array.isArray(arr)) return 0;
|
|
4388
|
-
let maxDepth = 1;
|
|
4389
|
-
for (const element of arr) {
|
|
4390
|
-
if (Array.isArray(element)) {
|
|
4391
|
-
const depth = getMaxDepth(element);
|
|
4392
|
-
if (depth + 1 > maxDepth) {
|
|
4393
|
-
maxDepth = depth + 1;
|
|
4394
|
-
}
|
|
4395
|
-
}
|
|
4396
|
-
}
|
|
4397
|
-
return maxDepth;
|
|
4398
|
-
};
|
|
4399
|
-
const arr2str = (arr) => {
|
|
4400
|
-
let level = 0;
|
|
4401
|
-
function arrStringify(arr) {
|
|
4402
|
-
let max = getMaxDepth(arr);
|
|
4403
|
-
let useIdentation = 0;
|
|
4404
|
-
if (arr.some((n) => Array.isArray(n))) {
|
|
4405
|
-
level++;
|
|
4406
|
-
useIdentation = 1;
|
|
4407
|
-
}
|
|
4408
|
-
return (
|
|
4409
|
-
"[" +
|
|
4410
|
-
arr.map((n, i) => {
|
|
4411
|
-
if (["number", "string", "boolean", "bigint"].includes(typeof n))
|
|
4412
|
-
return String(n);
|
|
4413
|
-
if (n instanceof Complex) return n.toString();
|
|
4414
|
-
if (n instanceof Array) {
|
|
4415
|
-
return `\n${" ".repeat(level)}${arrStringify(n)}${i === arr.length - 1 ? "\n" : ""}`;
|
|
4416
|
-
}
|
|
4417
|
-
if( n instanceof Object) return obj2str(n);
|
|
4418
|
-
})
|
|
4419
|
-
+ `${" ".repeat((max+level+1) * useIdentation)}]`
|
|
4420
|
-
);
|
|
4421
|
-
}
|
|
4422
|
-
return arrStringify(arr);
|
|
4423
|
-
};
|
|
4424
|
-
|
|
4425
4164
|
const json2css=(json, indentLevel = 0)=>{
|
|
4426
4165
|
json = trimKeys(json);
|
|
4427
4166
|
let cssText = '';
|
|
@@ -4694,6 +4433,49 @@ function useDerived(deriveFn, sources) {
|
|
|
4694
4433
|
})
|
|
4695
4434
|
}
|
|
4696
4435
|
|
|
4436
|
+
const mapfun=(fun,...X)=>{
|
|
4437
|
+
const Y=X.map(x=>{
|
|
4438
|
+
if(
|
|
4439
|
+
x===null||
|
|
4440
|
+
["number","string","boolean","bigint","undefined"].includes(typeof x)||
|
|
4441
|
+
x?.__mapfun__
|
|
4442
|
+
) return fun(x)
|
|
4443
|
+
if(x instanceof Array) return x.map(n=>mapfun(fun,n));
|
|
4444
|
+
if(ArrayBuffer.isView(x)) return x.map(n=>fun(n));
|
|
4445
|
+
if(x instanceof Set) return new Set(mapfun(fun,...[...x]));
|
|
4446
|
+
if(x instanceof Map) return new Map([...x].map(n=>[n[0],mapfun(fun,n[1])]));
|
|
4447
|
+
if(x.isMatrix?.()) return new x.constructor(x.rows, x.cols, mapfun(x.arr.flat(1)))
|
|
4448
|
+
// if(x.isComplex?.()){
|
|
4449
|
+
// const [a,b,z,phi]=[x.a,x.b,x.z,x.phi];
|
|
4450
|
+
// switch(fun){
|
|
4451
|
+
// // Moved to Fixed to avoid Circular Dep
|
|
4452
|
+
// // case Math.log: return new x.constructor(ln(z),phi); // Done
|
|
4453
|
+
// // case Math.exp: return new x.constructor(e(a)*cos(b),e(a)*sin(b)); // Done
|
|
4454
|
+
// // case Math.abs: return z; // Done
|
|
4455
|
+
// // case Math.sqrt: return new x.constructor(sqrt(z)*cos(phi/2),sqrt(z)*sin(phi/2)); // Done
|
|
4456
|
+
// // case Fixed.cos: return new x.constructor(cos(a)*cosh(b),-(sin(a)*sinh(b)));
|
|
4457
|
+
// // case Fixed.sin: return new x.constructor(sin(a)*cosh(b),cos(a)*sinh(b));
|
|
4458
|
+
// // case Fixed.tan:{
|
|
4459
|
+
// // const DEN = cos(2*a)+cosh(2*b);
|
|
4460
|
+
// // return new x.constructor(sin(2*a)/DEN,sinh(2*b)/DEN);
|
|
4461
|
+
// // }
|
|
4462
|
+
// // case Fixed.cosh:return new x.constructor(cosh(a)*cos(b),sinh(a)*sin(b));
|
|
4463
|
+
// // case Fixed.sinh:return new x.constructor(sinh(a)*cos(b),cosh(a)*sin(b));
|
|
4464
|
+
// // case Fixed.tanh:{
|
|
4465
|
+
// // const DEN=cosh(2*a)+cos(2*b);
|
|
4466
|
+
// // return new x.constructor(sinh(2*a)/DEN,sin(2*b)/DEN)
|
|
4467
|
+
// // }
|
|
4468
|
+
// default : return fun(x)
|
|
4469
|
+
// }
|
|
4470
|
+
// }
|
|
4471
|
+
else if(x instanceof Object){
|
|
4472
|
+
return Object.fromEntries(Object.entries(x).map(n=>n=[n[0],mapfun(fun,n[1])]))
|
|
4473
|
+
// return fun(Object) || Object.fromEntries(Object.entries(x).map(n=>n=[n[0],mapfun(fun,n[1])]))
|
|
4474
|
+
}
|
|
4475
|
+
});
|
|
4476
|
+
return Y.length==1? Y[0]: Y;
|
|
4477
|
+
};
|
|
4478
|
+
|
|
4697
4479
|
const useReactive = (nested_value) => mapfun(
|
|
4698
4480
|
n => {
|
|
4699
4481
|
const state = useState(n);
|
|
@@ -5163,7 +4945,6 @@ exports.UISwitch = UISwitch;
|
|
|
5163
4945
|
exports.UIView = UIView;
|
|
5164
4946
|
exports.UseRoot = UseRoot;
|
|
5165
4947
|
exports.UseThread = UseThread;
|
|
5166
|
-
exports.Utils = Utils;
|
|
5167
4948
|
exports.View = View;
|
|
5168
4949
|
exports.ViewEvent = ViewEvent;
|
|
5169
4950
|
exports.ViewListeners = ViewListeners;
|
|
@@ -5183,9 +4964,7 @@ exports.add_vendor_prefix = add_vendor_prefix;
|
|
|
5183
4964
|
exports.and = and;
|
|
5184
4965
|
exports.animation = animation;
|
|
5185
4966
|
exports.apply_fun = apply_fun;
|
|
5186
|
-
exports.arange = arange;
|
|
5187
4967
|
exports.arc = arc;
|
|
5188
|
-
exports.arr2str = arr2str;
|
|
5189
4968
|
exports.asin = asin;
|
|
5190
4969
|
exports.asinh = asinh;
|
|
5191
4970
|
exports.atan = atan;
|
|
@@ -5194,7 +4973,6 @@ exports.atanh = atanh;
|
|
|
5194
4973
|
exports.back = back;
|
|
5195
4974
|
exports.binomial = binomial;
|
|
5196
4975
|
exports.call_with_optional_props = call_with_optional_props;
|
|
5197
|
-
exports.cartesianProduct = cartesianProduct;
|
|
5198
4976
|
exports.cbrt = cbrt;
|
|
5199
4977
|
exports.ceil = ceil;
|
|
5200
4978
|
exports.clamp = clamp;
|
|
@@ -5220,9 +4998,7 @@ exports.elastic = elastic;
|
|
|
5220
4998
|
exports.exp = exp$1;
|
|
5221
4999
|
exports.floor = floor;
|
|
5222
5000
|
exports.fract = fract;
|
|
5223
|
-
exports.geomspace = geomspace;
|
|
5224
5001
|
exports.hypot = hypot;
|
|
5225
|
-
exports.inRange = inRange;
|
|
5226
5002
|
exports.in_back = in_back;
|
|
5227
5003
|
exports.in_bounce = in_bounce;
|
|
5228
5004
|
exports.in_circ = in_circ;
|
|
@@ -5243,7 +5019,6 @@ exports.in_quad = in_quad;
|
|
|
5243
5019
|
exports.in_quart = in_quart;
|
|
5244
5020
|
exports.in_quint = in_quint;
|
|
5245
5021
|
exports.in_sin = in_sin;
|
|
5246
|
-
exports.isApproximatlyEqual = isApproximatlyEqual;
|
|
5247
5022
|
exports.isPrimitive = isPrimitive;
|
|
5248
5023
|
exports.isStateGetter = isStateGetter;
|
|
5249
5024
|
exports.json2arr = json2arr;
|
|
@@ -5257,12 +5032,10 @@ exports.json2ymlFile = json2ymlFile;
|
|
|
5257
5032
|
exports.lerp = lerp;
|
|
5258
5033
|
exports.linear = linear;
|
|
5259
5034
|
exports.linkStyle = linkStyle;
|
|
5260
|
-
exports.linspace = linspace;
|
|
5261
5035
|
exports.ln = ln;
|
|
5262
|
-
exports.logspace = logspace;
|
|
5263
5036
|
exports.loop = loop;
|
|
5264
5037
|
exports.map = map$1;
|
|
5265
|
-
exports.mapfun = mapfun;
|
|
5038
|
+
exports.mapfun = mapfun$1;
|
|
5266
5039
|
exports.matrix = matrix;
|
|
5267
5040
|
exports.matrix2 = matrix2;
|
|
5268
5041
|
exports.matrix3 = matrix3;
|
|
@@ -5278,9 +5051,6 @@ exports.nor = nor;
|
|
|
5278
5051
|
exports.norm = norm;
|
|
5279
5052
|
exports.normalize_css_value = normalize_css_value;
|
|
5280
5053
|
exports.nthr = nthr;
|
|
5281
|
-
exports.nums = nums;
|
|
5282
|
-
exports.obj2str = obj2str;
|
|
5283
|
-
exports.ones = ones;
|
|
5284
5054
|
exports.or = or;
|
|
5285
5055
|
exports.out_back = out_back;
|
|
5286
5056
|
exports.out_bounce = out_bounce;
|
|
@@ -5293,9 +5063,7 @@ exports.out_quart = out_quart;
|
|
|
5293
5063
|
exports.out_quint = out_quint;
|
|
5294
5064
|
exports.out_sin = out_sin;
|
|
5295
5065
|
exports.percentile = percentile;
|
|
5296
|
-
exports.pgcd = pgcd;
|
|
5297
5066
|
exports.pow = pow$1;
|
|
5298
|
-
exports.ppcm = ppcm;
|
|
5299
5067
|
exports.rad2deg = rad2deg;
|
|
5300
5068
|
exports.register_click_away_event = register_click_away_event;
|
|
5301
5069
|
exports.register_swipe_event = register_swipe_event;
|
|
@@ -5332,7 +5100,7 @@ exports.trunc = trunc;
|
|
|
5332
5100
|
exports.useDerived = useDerived;
|
|
5333
5101
|
exports.useEventEmitter = useEventEmitter;
|
|
5334
5102
|
exports.useIPC = useIPC;
|
|
5335
|
-
exports.
|
|
5103
|
+
exports.useLocalStorage = useLocalStorage;
|
|
5336
5104
|
exports.useMediaQuery = useMediaQuery;
|
|
5337
5105
|
exports.useQueryParams = useQueryParams;
|
|
5338
5106
|
exports.useReactive = useReactive;
|
|
@@ -5349,4 +5117,3 @@ exports.waitForUIElmSync = waitForUIElmSync;
|
|
|
5349
5117
|
exports.watchQueryParams = watchQueryParams;
|
|
5350
5118
|
exports.xnor = xnor;
|
|
5351
5119
|
exports.xor = xor;
|
|
5352
|
-
exports.zeros = zeros;
|