ziko 1.1.0 → 1.1.1
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 +89 -345
- package/dist/ziko.js +89 -345
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +89 -330
- package/package.json +1 -1
- 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/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 :
|
|
5
|
+
Date : Tue Jul 28 2026 17:04: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
|
|
@@ -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 = {
|
|
@@ -4318,110 +4138,6 @@ const svg2ascii=svg=>btoa(svg2str(svg));
|
|
|
4318
4138
|
const svg2imgUrl=svg=>'data:image/svg+xml;base64,'+svg2ascii(svg);
|
|
4319
4139
|
const svg2img=(svg,render=true)=>tags.img(svg2imgUrl(svg)).mount(render);
|
|
4320
4140
|
|
|
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
4141
|
const json2css=(json, indentLevel = 0)=>{
|
|
4426
4142
|
json = trimKeys(json);
|
|
4427
4143
|
let cssText = '';
|
|
@@ -4694,6 +4410,49 @@ function useDerived(deriveFn, sources) {
|
|
|
4694
4410
|
})
|
|
4695
4411
|
}
|
|
4696
4412
|
|
|
4413
|
+
const mapfun=(fun,...X)=>{
|
|
4414
|
+
const Y=X.map(x=>{
|
|
4415
|
+
if(
|
|
4416
|
+
x===null||
|
|
4417
|
+
["number","string","boolean","bigint","undefined"].includes(typeof x)||
|
|
4418
|
+
x?.__mapfun__
|
|
4419
|
+
) return fun(x)
|
|
4420
|
+
if(x instanceof Array) return x.map(n=>mapfun(fun,n));
|
|
4421
|
+
if(ArrayBuffer.isView(x)) return x.map(n=>fun(n));
|
|
4422
|
+
if(x instanceof Set) return new Set(mapfun(fun,...[...x]));
|
|
4423
|
+
if(x instanceof Map) return new Map([...x].map(n=>[n[0],mapfun(fun,n[1])]));
|
|
4424
|
+
if(x.isMatrix?.()) return new x.constructor(x.rows, x.cols, mapfun(x.arr.flat(1)))
|
|
4425
|
+
// if(x.isComplex?.()){
|
|
4426
|
+
// const [a,b,z,phi]=[x.a,x.b,x.z,x.phi];
|
|
4427
|
+
// switch(fun){
|
|
4428
|
+
// // Moved to Fixed to avoid Circular Dep
|
|
4429
|
+
// // case Math.log: return new x.constructor(ln(z),phi); // Done
|
|
4430
|
+
// // case Math.exp: return new x.constructor(e(a)*cos(b),e(a)*sin(b)); // Done
|
|
4431
|
+
// // case Math.abs: return z; // Done
|
|
4432
|
+
// // case Math.sqrt: return new x.constructor(sqrt(z)*cos(phi/2),sqrt(z)*sin(phi/2)); // Done
|
|
4433
|
+
// // case Fixed.cos: return new x.constructor(cos(a)*cosh(b),-(sin(a)*sinh(b)));
|
|
4434
|
+
// // case Fixed.sin: return new x.constructor(sin(a)*cosh(b),cos(a)*sinh(b));
|
|
4435
|
+
// // case Fixed.tan:{
|
|
4436
|
+
// // const DEN = cos(2*a)+cosh(2*b);
|
|
4437
|
+
// // return new x.constructor(sin(2*a)/DEN,sinh(2*b)/DEN);
|
|
4438
|
+
// // }
|
|
4439
|
+
// // case Fixed.cosh:return new x.constructor(cosh(a)*cos(b),sinh(a)*sin(b));
|
|
4440
|
+
// // case Fixed.sinh:return new x.constructor(sinh(a)*cos(b),cosh(a)*sin(b));
|
|
4441
|
+
// // case Fixed.tanh:{
|
|
4442
|
+
// // const DEN=cosh(2*a)+cos(2*b);
|
|
4443
|
+
// // return new x.constructor(sinh(2*a)/DEN,sin(2*b)/DEN)
|
|
4444
|
+
// // }
|
|
4445
|
+
// default : return fun(x)
|
|
4446
|
+
// }
|
|
4447
|
+
// }
|
|
4448
|
+
else if(x instanceof Object){
|
|
4449
|
+
return Object.fromEntries(Object.entries(x).map(n=>n=[n[0],mapfun(fun,n[1])]))
|
|
4450
|
+
// return fun(Object) || Object.fromEntries(Object.entries(x).map(n=>n=[n[0],mapfun(fun,n[1])]))
|
|
4451
|
+
}
|
|
4452
|
+
});
|
|
4453
|
+
return Y.length==1? Y[0]: Y;
|
|
4454
|
+
};
|
|
4455
|
+
|
|
4697
4456
|
const useReactive = (nested_value) => mapfun(
|
|
4698
4457
|
n => {
|
|
4699
4458
|
const state = useState(n);
|
|
@@ -5163,7 +4922,6 @@ exports.UISwitch = UISwitch;
|
|
|
5163
4922
|
exports.UIView = UIView;
|
|
5164
4923
|
exports.UseRoot = UseRoot;
|
|
5165
4924
|
exports.UseThread = UseThread;
|
|
5166
|
-
exports.Utils = Utils;
|
|
5167
4925
|
exports.View = View;
|
|
5168
4926
|
exports.ViewEvent = ViewEvent;
|
|
5169
4927
|
exports.ViewListeners = ViewListeners;
|
|
@@ -5183,9 +4941,7 @@ exports.add_vendor_prefix = add_vendor_prefix;
|
|
|
5183
4941
|
exports.and = and;
|
|
5184
4942
|
exports.animation = animation;
|
|
5185
4943
|
exports.apply_fun = apply_fun;
|
|
5186
|
-
exports.arange = arange;
|
|
5187
4944
|
exports.arc = arc;
|
|
5188
|
-
exports.arr2str = arr2str;
|
|
5189
4945
|
exports.asin = asin;
|
|
5190
4946
|
exports.asinh = asinh;
|
|
5191
4947
|
exports.atan = atan;
|
|
@@ -5194,7 +4950,6 @@ exports.atanh = atanh;
|
|
|
5194
4950
|
exports.back = back;
|
|
5195
4951
|
exports.binomial = binomial;
|
|
5196
4952
|
exports.call_with_optional_props = call_with_optional_props;
|
|
5197
|
-
exports.cartesianProduct = cartesianProduct;
|
|
5198
4953
|
exports.cbrt = cbrt;
|
|
5199
4954
|
exports.ceil = ceil;
|
|
5200
4955
|
exports.clamp = clamp;
|
|
@@ -5220,9 +4975,7 @@ exports.elastic = elastic;
|
|
|
5220
4975
|
exports.exp = exp$1;
|
|
5221
4976
|
exports.floor = floor;
|
|
5222
4977
|
exports.fract = fract;
|
|
5223
|
-
exports.geomspace = geomspace;
|
|
5224
4978
|
exports.hypot = hypot;
|
|
5225
|
-
exports.inRange = inRange;
|
|
5226
4979
|
exports.in_back = in_back;
|
|
5227
4980
|
exports.in_bounce = in_bounce;
|
|
5228
4981
|
exports.in_circ = in_circ;
|
|
@@ -5243,7 +4996,6 @@ exports.in_quad = in_quad;
|
|
|
5243
4996
|
exports.in_quart = in_quart;
|
|
5244
4997
|
exports.in_quint = in_quint;
|
|
5245
4998
|
exports.in_sin = in_sin;
|
|
5246
|
-
exports.isApproximatlyEqual = isApproximatlyEqual;
|
|
5247
4999
|
exports.isPrimitive = isPrimitive;
|
|
5248
5000
|
exports.isStateGetter = isStateGetter;
|
|
5249
5001
|
exports.json2arr = json2arr;
|
|
@@ -5257,12 +5009,10 @@ exports.json2ymlFile = json2ymlFile;
|
|
|
5257
5009
|
exports.lerp = lerp;
|
|
5258
5010
|
exports.linear = linear;
|
|
5259
5011
|
exports.linkStyle = linkStyle;
|
|
5260
|
-
exports.linspace = linspace;
|
|
5261
5012
|
exports.ln = ln;
|
|
5262
|
-
exports.logspace = logspace;
|
|
5263
5013
|
exports.loop = loop;
|
|
5264
5014
|
exports.map = map$1;
|
|
5265
|
-
exports.mapfun = mapfun;
|
|
5015
|
+
exports.mapfun = mapfun$1;
|
|
5266
5016
|
exports.matrix = matrix;
|
|
5267
5017
|
exports.matrix2 = matrix2;
|
|
5268
5018
|
exports.matrix3 = matrix3;
|
|
@@ -5278,9 +5028,6 @@ exports.nor = nor;
|
|
|
5278
5028
|
exports.norm = norm;
|
|
5279
5029
|
exports.normalize_css_value = normalize_css_value;
|
|
5280
5030
|
exports.nthr = nthr;
|
|
5281
|
-
exports.nums = nums;
|
|
5282
|
-
exports.obj2str = obj2str;
|
|
5283
|
-
exports.ones = ones;
|
|
5284
5031
|
exports.or = or;
|
|
5285
5032
|
exports.out_back = out_back;
|
|
5286
5033
|
exports.out_bounce = out_bounce;
|
|
@@ -5293,9 +5040,7 @@ exports.out_quart = out_quart;
|
|
|
5293
5040
|
exports.out_quint = out_quint;
|
|
5294
5041
|
exports.out_sin = out_sin;
|
|
5295
5042
|
exports.percentile = percentile;
|
|
5296
|
-
exports.pgcd = pgcd;
|
|
5297
5043
|
exports.pow = pow$1;
|
|
5298
|
-
exports.ppcm = ppcm;
|
|
5299
5044
|
exports.rad2deg = rad2deg;
|
|
5300
5045
|
exports.register_click_away_event = register_click_away_event;
|
|
5301
5046
|
exports.register_swipe_event = register_swipe_event;
|
|
@@ -5349,4 +5094,3 @@ exports.waitForUIElmSync = waitForUIElmSync;
|
|
|
5349
5094
|
exports.watchQueryParams = watchQueryParams;
|
|
5350
5095
|
exports.xnor = xnor;
|
|
5351
5096
|
exports.xor = xor;
|
|
5352
|
-
exports.zeros = zeros;
|