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.js
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
|
|
@@ -19,18 +19,18 @@
|
|
|
19
19
|
|
|
20
20
|
const is_primitive = value => typeof value !== 'object' && typeof value !== 'function' || value === null;
|
|
21
21
|
|
|
22
|
-
const mapfun=(fun,...X)=>{
|
|
22
|
+
const mapfun$1=(fun,...X)=>{
|
|
23
23
|
const Y=X.map(x=>{
|
|
24
24
|
if(is_primitive(x) || x?.__mapfun__) return fun(x)
|
|
25
|
-
if(x instanceof Array) return x.map(n=>mapfun(fun,n));
|
|
25
|
+
if(x instanceof Array) return x.map(n=>mapfun$1(fun,n));
|
|
26
26
|
if(ArrayBuffer.isView(x)) return x.map(n=>fun(n));
|
|
27
|
-
if(x instanceof Set) return new Set(mapfun(fun,...[...x]));
|
|
28
|
-
if(x instanceof Map) return new Map([...x].map(n=>[n[0],mapfun(fun,n[1])]));
|
|
29
|
-
if(x.isMatrix?.()) return new x.constructor(x.rows, x.cols, mapfun(x.arr.flat(1)))
|
|
27
|
+
if(x instanceof Set) return new Set(mapfun$1(fun,...[...x]));
|
|
28
|
+
if(x instanceof Map) return new Map([...x].map(n=>[n[0],mapfun$1(fun,n[1])]));
|
|
29
|
+
if(x.isMatrix?.()) return new x.constructor(x.rows, x.cols, mapfun$1(x.arr.flat(1)))
|
|
30
30
|
else if(x instanceof Object){
|
|
31
31
|
return Object.fromEntries(
|
|
32
32
|
Object.entries(x).map(
|
|
33
|
-
n=>n=[n[0],mapfun(fun,n[1])]
|
|
33
|
+
n=>n=[n[0],mapfun$1(fun,n[1])]
|
|
34
34
|
)
|
|
35
35
|
)
|
|
36
36
|
}
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
x.cols,
|
|
49
49
|
x.arr.flat(1).map(fn)
|
|
50
50
|
)
|
|
51
|
-
if (x instanceof Array) mapfun(fn, ...x);
|
|
51
|
+
if (x instanceof Array) mapfun$1(fn, ...x);
|
|
52
52
|
return fn(x)
|
|
53
53
|
};
|
|
54
54
|
|
|
@@ -531,7 +531,7 @@
|
|
|
531
531
|
|
|
532
532
|
const PRECESION = 8;
|
|
533
533
|
|
|
534
|
-
const abs = (...x) => mapfun(
|
|
534
|
+
const abs = (...x) => mapfun$1(
|
|
535
535
|
x =>{
|
|
536
536
|
if(x.isComplex?.()) return x.z;
|
|
537
537
|
return Math.abs(x)
|
|
@@ -541,7 +541,7 @@
|
|
|
541
541
|
|
|
542
542
|
const pow$1 = (...x) => {
|
|
543
543
|
const n = x.pop();
|
|
544
|
-
return mapfun(
|
|
544
|
+
return mapfun$1(
|
|
545
545
|
x => {
|
|
546
546
|
if(x.isComplex?.()) {
|
|
547
547
|
if(n.isComplex?.()) return new x.constructor({
|
|
@@ -560,7 +560,7 @@
|
|
|
560
560
|
)
|
|
561
561
|
};
|
|
562
562
|
|
|
563
|
-
const sqrt$2 = (...x) => mapfun(
|
|
563
|
+
const sqrt$2 = (...x) => mapfun$1(
|
|
564
564
|
x=>{
|
|
565
565
|
if(x.isComplex?.())
|
|
566
566
|
return new x.constructor({z: x.z**(1/2), phi: x.phi/2});
|
|
@@ -570,7 +570,7 @@
|
|
|
570
570
|
...x
|
|
571
571
|
);
|
|
572
572
|
|
|
573
|
-
const cbrt = (...x) => mapfun(
|
|
573
|
+
const cbrt = (...x) => mapfun$1(
|
|
574
574
|
x=>{
|
|
575
575
|
if(x.isComplex?.())
|
|
576
576
|
return new x.constructor({z: x.z**(1/3), phi: x.phi/3}).toFixed(PRECESION)
|
|
@@ -582,7 +582,7 @@
|
|
|
582
582
|
const nthr = (...x) => {
|
|
583
583
|
const n = x.pop();
|
|
584
584
|
if(typeof n !== 'number') throw Error('nthr expects a real number n');
|
|
585
|
-
return mapfun(
|
|
585
|
+
return mapfun$1(
|
|
586
586
|
x => {
|
|
587
587
|
if(x.isComplex?.()) return new x.constructor({z: x.z ** (1/n), phi: x.phi / n});
|
|
588
588
|
if(x<0) return n %2 ===2
|
|
@@ -597,7 +597,7 @@
|
|
|
597
597
|
const croot = (...x) =>{
|
|
598
598
|
const c = x.pop();
|
|
599
599
|
if(!c.isComplex?.()) throw Error('croot expect Complex number as root')
|
|
600
|
-
return mapfun(
|
|
600
|
+
return mapfun$1(
|
|
601
601
|
x => {
|
|
602
602
|
if(typeof x === 'number') x = new c.constructor(x, 0);
|
|
603
603
|
const {a : c_a, b : c_b} = c;
|
|
@@ -614,7 +614,7 @@
|
|
|
614
614
|
)
|
|
615
615
|
};
|
|
616
616
|
|
|
617
|
-
const exp$1 = (...x) => mapfun(
|
|
617
|
+
const exp$1 = (...x) => mapfun$1(
|
|
618
618
|
x => {
|
|
619
619
|
if(x.isComplex?.()) return new x.constructor(
|
|
620
620
|
Math.exp(x.a) * Math.cos(x.b),
|
|
@@ -625,7 +625,7 @@
|
|
|
625
625
|
,...x
|
|
626
626
|
);
|
|
627
627
|
|
|
628
|
-
const ln = (...x) => mapfun(
|
|
628
|
+
const ln = (...x) => mapfun$1(
|
|
629
629
|
x => {
|
|
630
630
|
if(x.isComplex?.()) return new x.constructor(
|
|
631
631
|
Math.log(x.z),
|
|
@@ -636,7 +636,7 @@
|
|
|
636
636
|
,...x
|
|
637
637
|
);
|
|
638
638
|
|
|
639
|
-
const sign = (...x) => mapfun(
|
|
639
|
+
const sign = (...x) => mapfun$1(
|
|
640
640
|
x => {
|
|
641
641
|
if(x.isComplex?.()){
|
|
642
642
|
const {z, phi} = x;
|
|
@@ -648,7 +648,7 @@
|
|
|
648
648
|
,...x
|
|
649
649
|
);
|
|
650
650
|
|
|
651
|
-
const floor = (...x) => mapfun(
|
|
651
|
+
const floor = (...x) => mapfun$1(
|
|
652
652
|
x => {
|
|
653
653
|
if(x.isComplex?.()) return new x.constructor(
|
|
654
654
|
Math.floor(x.a),
|
|
@@ -658,7 +658,7 @@
|
|
|
658
658
|
},
|
|
659
659
|
...x
|
|
660
660
|
);
|
|
661
|
-
const ceil = (...x) => mapfun(
|
|
661
|
+
const ceil = (...x) => mapfun$1(
|
|
662
662
|
x => {
|
|
663
663
|
if(x.isComplex?.()) return new x.constructor(
|
|
664
664
|
Math.ceil(x.a),
|
|
@@ -668,7 +668,7 @@
|
|
|
668
668
|
},
|
|
669
669
|
...x
|
|
670
670
|
);
|
|
671
|
-
const round = (...x) => mapfun(
|
|
671
|
+
const round = (...x) => mapfun$1(
|
|
672
672
|
x => {
|
|
673
673
|
if(x.isComplex?.()) return new x.constructor(
|
|
674
674
|
Math.round(x.a),
|
|
@@ -679,7 +679,7 @@
|
|
|
679
679
|
...x
|
|
680
680
|
);
|
|
681
681
|
|
|
682
|
-
const trunc = (...x) => mapfun(
|
|
682
|
+
const trunc = (...x) => mapfun$1(
|
|
683
683
|
x => {
|
|
684
684
|
if(x.isComplex?.()) return new x.constructor(
|
|
685
685
|
Math.trunc(x.a),
|
|
@@ -690,7 +690,7 @@
|
|
|
690
690
|
...x
|
|
691
691
|
);
|
|
692
692
|
|
|
693
|
-
const fract = (...x) => mapfun(
|
|
693
|
+
const fract = (...x) => mapfun$1(
|
|
694
694
|
x => {
|
|
695
695
|
if(x.isComplex?.()) return new x.constructor(
|
|
696
696
|
x.a - Math.trunc(x.a),
|
|
@@ -701,7 +701,7 @@
|
|
|
701
701
|
...x
|
|
702
702
|
);
|
|
703
703
|
|
|
704
|
-
const cos$3 = (...x) => mapfun(
|
|
704
|
+
const cos$3 = (...x) => mapfun$1(
|
|
705
705
|
x => {
|
|
706
706
|
if(x.isComplex?.()) return new x.constructor(
|
|
707
707
|
Math.cos(x.a) * Math.cosh(x.b),
|
|
@@ -712,7 +712,7 @@
|
|
|
712
712
|
,...x
|
|
713
713
|
);
|
|
714
714
|
|
|
715
|
-
const sin$3 = (...x) => mapfun(
|
|
715
|
+
const sin$3 = (...x) => mapfun$1(
|
|
716
716
|
x =>{
|
|
717
717
|
if(x?.isComplex) return new x.constructor(
|
|
718
718
|
Math.sin(x.a) * Math.cosh(x.b),
|
|
@@ -723,7 +723,7 @@
|
|
|
723
723
|
, ...x
|
|
724
724
|
);
|
|
725
725
|
|
|
726
|
-
const tan = (...x) => mapfun(
|
|
726
|
+
const tan = (...x) => mapfun$1(
|
|
727
727
|
x =>{
|
|
728
728
|
if(x?.isComplex){
|
|
729
729
|
const D = Math.cos(2*x.a) + Math.cosh(2*x.b);
|
|
@@ -737,7 +737,7 @@
|
|
|
737
737
|
...x
|
|
738
738
|
);
|
|
739
739
|
|
|
740
|
-
const sec = (...x) => mapfun(
|
|
740
|
+
const sec = (...x) => mapfun$1(
|
|
741
741
|
x => {
|
|
742
742
|
if(x.isComplex?.()) ;
|
|
743
743
|
return + (1 / Math.cos(x)).toFixed(PRECESION)
|
|
@@ -745,7 +745,7 @@
|
|
|
745
745
|
,...x
|
|
746
746
|
);
|
|
747
747
|
|
|
748
|
-
const acos$1 = (...x) => mapfun(
|
|
748
|
+
const acos$1 = (...x) => mapfun$1(
|
|
749
749
|
x =>{
|
|
750
750
|
if(x?.isComplex){
|
|
751
751
|
const { a, b } = x;
|
|
@@ -763,7 +763,7 @@
|
|
|
763
763
|
...x
|
|
764
764
|
);
|
|
765
765
|
|
|
766
|
-
const asin = (...x) => mapfun(
|
|
766
|
+
const asin = (...x) => mapfun$1(
|
|
767
767
|
x => {
|
|
768
768
|
if(x?.isComplex){
|
|
769
769
|
const { a, b } = x;
|
|
@@ -779,7 +779,7 @@
|
|
|
779
779
|
...x
|
|
780
780
|
);
|
|
781
781
|
|
|
782
|
-
const atan = (...x) => mapfun(
|
|
782
|
+
const atan = (...x) => mapfun$1(
|
|
783
783
|
x => {
|
|
784
784
|
if(x?.isComplex){
|
|
785
785
|
const { a, b } = x;
|
|
@@ -793,7 +793,7 @@
|
|
|
793
793
|
...x
|
|
794
794
|
);
|
|
795
795
|
|
|
796
|
-
const acot = (...x) => mapfun(
|
|
796
|
+
const acot = (...x) => mapfun$1(
|
|
797
797
|
x => {
|
|
798
798
|
if(x?.isComplex){
|
|
799
799
|
const { a, b } = x;
|
|
@@ -808,7 +808,7 @@
|
|
|
808
808
|
);
|
|
809
809
|
|
|
810
810
|
|
|
811
|
-
const cosh$2 = (...x) => mapfun(
|
|
811
|
+
const cosh$2 = (...x) => mapfun$1(
|
|
812
812
|
x =>{
|
|
813
813
|
if(x?.isComplex) return new x.constructor(
|
|
814
814
|
Math.cosh(x.a) * Math.cos(x.b),
|
|
@@ -818,7 +818,7 @@
|
|
|
818
818
|
},
|
|
819
819
|
...x
|
|
820
820
|
);
|
|
821
|
-
const sinh$1 = (...x) => mapfun(
|
|
821
|
+
const sinh$1 = (...x) => mapfun$1(
|
|
822
822
|
x =>{
|
|
823
823
|
if(x?.isComplex) return new x.constructor(
|
|
824
824
|
Math.sinh(x.a) * Math.cos(x.b),
|
|
@@ -828,7 +828,7 @@
|
|
|
828
828
|
},
|
|
829
829
|
...x
|
|
830
830
|
);
|
|
831
|
-
const tanh = (...x) => mapfun(
|
|
831
|
+
const tanh = (...x) => mapfun$1(
|
|
832
832
|
x =>{
|
|
833
833
|
if(x?.isComplex){
|
|
834
834
|
const D = Math.cosh(2*a) + Math.cos(2*b);
|
|
@@ -842,7 +842,7 @@
|
|
|
842
842
|
...x
|
|
843
843
|
);
|
|
844
844
|
|
|
845
|
-
const coth = (...x) => mapfun(
|
|
845
|
+
const coth = (...x) => mapfun$1(
|
|
846
846
|
x =>{
|
|
847
847
|
if(x?.isComplex){
|
|
848
848
|
const {a, b} = x;
|
|
@@ -857,7 +857,7 @@
|
|
|
857
857
|
...x
|
|
858
858
|
);
|
|
859
859
|
|
|
860
|
-
const acosh = (...x) => mapfun(
|
|
860
|
+
const acosh = (...x) => mapfun$1(
|
|
861
861
|
x =>{
|
|
862
862
|
if(x?.isComplex){
|
|
863
863
|
return ln(x.clone().add(sqrt$2(x.clone().mul(x.clone()).sub(1))))
|
|
@@ -867,7 +867,7 @@
|
|
|
867
867
|
...x
|
|
868
868
|
);
|
|
869
869
|
|
|
870
|
-
const asinh = (...x) => mapfun(
|
|
870
|
+
const asinh = (...x) => mapfun$1(
|
|
871
871
|
x =>{
|
|
872
872
|
if(x?.isComplex){
|
|
873
873
|
return ln(x.clone().add(sqrt$2(x.clone().mul(x.clone()).add(1))))
|
|
@@ -877,7 +877,7 @@
|
|
|
877
877
|
...x
|
|
878
878
|
);
|
|
879
879
|
|
|
880
|
-
const atanh = (...x) => mapfun(
|
|
880
|
+
const atanh = (...x) => mapfun$1(
|
|
881
881
|
x =>{
|
|
882
882
|
if(x?.isComplex);
|
|
883
883
|
return + Math.atanh(x).toFixed(PRECESION)
|
|
@@ -885,7 +885,7 @@
|
|
|
885
885
|
...x
|
|
886
886
|
);
|
|
887
887
|
|
|
888
|
-
const sig = (...x) => mapfun(
|
|
888
|
+
const sig = (...x) => mapfun$1(
|
|
889
889
|
x =>{
|
|
890
890
|
if(x?.isComplex);
|
|
891
891
|
return 1/(1 + Math.exp(-x)).toFixed(PRECESION)
|
|
@@ -893,8 +893,8 @@
|
|
|
893
893
|
...x
|
|
894
894
|
);
|
|
895
895
|
|
|
896
|
-
const deg2rad = (...deg) => mapfun(x => x * Math.PI / 180, ...deg);
|
|
897
|
-
const rad2deg = (...rad) => mapfun(x => x / Math.PI * 180, ...rad);
|
|
896
|
+
const deg2rad = (...deg) => mapfun$1(x => x * Math.PI / 180, ...deg);
|
|
897
|
+
const rad2deg = (...rad) => mapfun$1(x => x / Math.PI * 180, ...rad);
|
|
898
898
|
|
|
899
899
|
const norm = (x, min, max) => apply_fun(
|
|
900
900
|
x,
|
|
@@ -925,10 +925,10 @@
|
|
|
925
925
|
|
|
926
926
|
const atan2 = (y, x, rad = true) => {
|
|
927
927
|
if (y instanceof Array && !(x instanceof Array))
|
|
928
|
-
return mapfun(n => atan2(n, x, rad), ...y);
|
|
928
|
+
return mapfun$1(n => atan2(n, x, rad), ...y);
|
|
929
929
|
|
|
930
930
|
if (x instanceof Array && !(y instanceof Array))
|
|
931
|
-
return mapfun(n => atan2(y, n, rad), ...x);
|
|
931
|
+
return mapfun$1(n => atan2(y, n, rad), ...x);
|
|
932
932
|
|
|
933
933
|
if (y instanceof Array && x instanceof Array)
|
|
934
934
|
return y.map((v, i) => atan2(v, x[i], rad));
|
|
@@ -1165,7 +1165,7 @@
|
|
|
1165
1165
|
return new Matrix(this.rows, this.cols, this.arr.flat(1));
|
|
1166
1166
|
}
|
|
1167
1167
|
toComplex(){
|
|
1168
|
-
this.arr = mapfun(
|
|
1168
|
+
this.arr = mapfun$1(
|
|
1169
1169
|
x => x?.isComplex?.() ? x : new Complex(x, 0),
|
|
1170
1170
|
...this.arr
|
|
1171
1171
|
);
|
|
@@ -1629,7 +1629,7 @@
|
|
|
1629
1629
|
return new Matrix(v.length, 1, v);
|
|
1630
1630
|
}
|
|
1631
1631
|
serialize() {
|
|
1632
|
-
const arr = mapfun(x => x.serialize?.() || x, ...this.arr);
|
|
1632
|
+
const arr = mapfun$1(x => x.serialize?.() || x, ...this.arr);
|
|
1633
1633
|
return JSON.stringify({
|
|
1634
1634
|
type : 'matrix',
|
|
1635
1635
|
data : {
|
|
@@ -1644,7 +1644,7 @@
|
|
|
1644
1644
|
const {type, data} = json;
|
|
1645
1645
|
if(type !== 'matrix') return TypeError('Not a valid Matrix')
|
|
1646
1646
|
let {arr} = data;
|
|
1647
|
-
arr = mapfun(x => {
|
|
1647
|
+
arr = mapfun$1(x => {
|
|
1648
1648
|
if(typeof x === 'string') {
|
|
1649
1649
|
const x_obj = JSON.parse(x);
|
|
1650
1650
|
const {type} = x_obj;
|
|
@@ -1675,186 +1675,6 @@
|
|
|
1675
1675
|
const matrix3=(...element)=>new Matrix(3, 3, element);
|
|
1676
1676
|
const matrix4=(...element)=>new Matrix(4, 4, element);
|
|
1677
1677
|
|
|
1678
|
-
const zeros=(n)=>new Array(n).fill(0);
|
|
1679
|
-
const ones=(n)=>new Array(n).fill(1);
|
|
1680
|
-
const nums=(num,n)=>new Array(n).fill(num);
|
|
1681
|
-
|
|
1682
|
-
const arange=(a, b, step , include = false)=>{
|
|
1683
|
-
let tab = [];
|
|
1684
|
-
if(a<b){
|
|
1685
|
-
for (let i = a; include?i<=b:i<b; i += step) tab.push((i * 10) / 10);
|
|
1686
|
-
}
|
|
1687
|
-
else {
|
|
1688
|
-
for(let i = a; include?i>=b:i>b; i -= step) tab.push((i * 10) / 10);
|
|
1689
|
-
}
|
|
1690
|
-
return tab;
|
|
1691
|
-
};
|
|
1692
|
-
const linspace=(a,b,n=abs(b-a)+1,endpoint=true)=>{
|
|
1693
|
-
if(Math.floor(n)!==n)return;
|
|
1694
|
-
if([a,b].every(n=>typeof n==="number")){
|
|
1695
|
-
const [max,min]=[a,b].sort((a,b)=>b-a);
|
|
1696
|
-
var Y = [];
|
|
1697
|
-
let step ;
|
|
1698
|
-
endpoint ? step = (max - min) / (n - 1) : step = (max - min) / n;
|
|
1699
|
-
for (var i = 0; i < n; i++) {
|
|
1700
|
-
a<b?Y.push(min+step*i):Y.push(max-step*i);
|
|
1701
|
-
}
|
|
1702
|
-
return Y
|
|
1703
|
-
}
|
|
1704
|
-
|
|
1705
|
-
if([a,b].some(n=>n.isComplex?.())){
|
|
1706
|
-
const z1 = new n.constructor(a);
|
|
1707
|
-
const z2 = new n.constructor(b);
|
|
1708
|
-
n=n||Math.abs(z1.a-z2.a)+1;
|
|
1709
|
-
const X=linspace(z1.a,z2.a,n,endpoint);
|
|
1710
|
-
const Y=linspace(z1.b,z2.b,n,endpoint);
|
|
1711
|
-
let Z=new Array(n).fill(null);
|
|
1712
|
-
Z=Z.map((n,i)=> new n.constructor(X[i],Y[i]));
|
|
1713
|
-
return Z;
|
|
1714
|
-
}
|
|
1715
|
-
};
|
|
1716
|
-
const logspace=(a,b,n=b-a+1,base=E,endpoint=true)=>{
|
|
1717
|
-
return linspace(a,b,n,endpoint).map(n=>pow$1(base,n))
|
|
1718
|
-
};
|
|
1719
|
-
const geomspace=(a,b,n=abs(b-a)+1,endpoint=true)=>{
|
|
1720
|
-
if(Math.floor(n)!==n)return;
|
|
1721
|
-
if([a,b].every(n=>typeof n==="number")){
|
|
1722
|
-
const [max,min]=[a,b].sort((a,b)=>b-a);
|
|
1723
|
-
let base;
|
|
1724
|
-
endpoint ? base = nthr(max/min,n-1) : base = nthr(max/min,n) ;
|
|
1725
|
-
const Y = [min];
|
|
1726
|
-
for (let i = 1; i < n; i++) {
|
|
1727
|
-
Y.push(Y[i-1]*base);
|
|
1728
|
-
}
|
|
1729
|
-
return a<b?Y:Y.reverse()
|
|
1730
|
-
}
|
|
1731
|
-
|
|
1732
|
-
if([a,b].some(n=>n.isComplex?.())){
|
|
1733
|
-
const z1 = new n.constructor(a);
|
|
1734
|
-
const z2 = new n.constructor(b);
|
|
1735
|
-
n=n||Math.abs(z1.a-z2.a)+1;
|
|
1736
|
-
let base;
|
|
1737
|
-
endpoint ? base = nthr(z2.div(z1),n-1) : base = nthr(z2.div(z1),n) ;
|
|
1738
|
-
const Y = [z1];
|
|
1739
|
-
for (let i = 1; i < n; i++) {
|
|
1740
|
-
Y.push(mul(Y[i-1],base));
|
|
1741
|
-
}
|
|
1742
|
-
return Y;
|
|
1743
|
-
}
|
|
1744
|
-
};
|
|
1745
|
-
|
|
1746
|
-
/** @module Math */
|
|
1747
|
-
/**
|
|
1748
|
-
* Checks if a value is within the specified range.
|
|
1749
|
-
* @function
|
|
1750
|
-
* @param {number} x - The value to check.
|
|
1751
|
-
* @param {number} a - The start of the range.
|
|
1752
|
-
* @param {number} b - The end of the range.
|
|
1753
|
-
* @returns {boolean} Returns true if the value is within the range [a, b], otherwise false.
|
|
1754
|
-
*/
|
|
1755
|
-
const inRange = (x, a, b) => {
|
|
1756
|
-
const [min, max] = [Math.min(a, b), Math.max(a, b)];
|
|
1757
|
-
return x >= min && x <= max;
|
|
1758
|
-
};
|
|
1759
|
-
|
|
1760
|
-
/**
|
|
1761
|
-
* Checks if two numbers are approximately equal within a given error margin.
|
|
1762
|
-
* @param {number} a - The first number.
|
|
1763
|
-
* @param {number} b - The second number.
|
|
1764
|
-
* @param {number} [Err=0.0001] - The maximum acceptable difference between the two numbers.
|
|
1765
|
-
* @returns {boolean} Returns true if the two numbers are approximately equal within the specified error margin, otherwise false.
|
|
1766
|
-
*/
|
|
1767
|
-
const isApproximatlyEqual = (a, b, Err = 0.0001) => {
|
|
1768
|
-
return Math.abs(a - b) <= Err;
|
|
1769
|
-
};
|
|
1770
|
-
|
|
1771
|
-
/** @module Math */
|
|
1772
|
-
|
|
1773
|
-
/**
|
|
1774
|
-
* Computes the cartesian product of two arrays.
|
|
1775
|
-
* @param {Array} a - The first array.
|
|
1776
|
-
* @param {Array} b - The second array.
|
|
1777
|
-
* @returns {Array} Returns an array representing the cartesian product of the input arrays.
|
|
1778
|
-
*/
|
|
1779
|
-
const cartesianProduct = (a, b) => a.reduce((p, x) => [...p, ...b.map((y) => [x, y])], []);
|
|
1780
|
-
|
|
1781
|
-
/**
|
|
1782
|
-
* Computes the greatest common divisor (GCD) of two numbers.
|
|
1783
|
-
* @param {number} n1 - The first number.
|
|
1784
|
-
* @param {number} n2 - The second number.
|
|
1785
|
-
* @returns {number} Returns the greatest common divisor of the two input numbers.
|
|
1786
|
-
*/
|
|
1787
|
-
const pgcd = (n1, n2) => {
|
|
1788
|
-
let i,
|
|
1789
|
-
pgcd = 1;
|
|
1790
|
-
if (n1 == floor(n1) && n2 == floor(n2)) {
|
|
1791
|
-
for (i = 2; i <= n1 && i <= n2; ++i) {
|
|
1792
|
-
if (n1 % i == 0 && n2 % i == 0) pgcd = i;
|
|
1793
|
-
}
|
|
1794
|
-
return pgcd;
|
|
1795
|
-
} else console.log("error");
|
|
1796
|
-
};
|
|
1797
|
-
|
|
1798
|
-
/**
|
|
1799
|
-
* Computes the least common multiple (LCM) of two numbers.
|
|
1800
|
-
* @param {number} n1 - The first number.
|
|
1801
|
-
* @param {number} n2 - The second number.
|
|
1802
|
-
* @returns {number} Returns the least common multiple of the two input numbers.
|
|
1803
|
-
*/
|
|
1804
|
-
const ppcm = (n1, n2) => {
|
|
1805
|
-
let ppcm;
|
|
1806
|
-
if (n1 == floor(n1) && n2 == floor(n2)) {
|
|
1807
|
-
ppcm = n1 > n2 ? n1 : n2;
|
|
1808
|
-
while (true) {
|
|
1809
|
-
if (ppcm % n1 == 0 && ppcm % n2 == 0) break;
|
|
1810
|
-
++ppcm;
|
|
1811
|
-
}
|
|
1812
|
-
return ppcm;
|
|
1813
|
-
} else console.log("error");
|
|
1814
|
-
};
|
|
1815
|
-
|
|
1816
|
-
// import { mapfun } from "../mapfun/index.js";
|
|
1817
|
-
// import {
|
|
1818
|
-
// add,
|
|
1819
|
-
// sub,
|
|
1820
|
-
// mul,
|
|
1821
|
-
// div,
|
|
1822
|
-
// modulo
|
|
1823
|
-
// } from "./arithmetic.js";
|
|
1824
|
-
const Utils={
|
|
1825
|
-
// add,
|
|
1826
|
-
// sub,
|
|
1827
|
-
// mul,
|
|
1828
|
-
// div,
|
|
1829
|
-
// modulo,
|
|
1830
|
-
|
|
1831
|
-
zeros,
|
|
1832
|
-
ones,
|
|
1833
|
-
nums,
|
|
1834
|
-
// norm,
|
|
1835
|
-
// lerp,
|
|
1836
|
-
// map,
|
|
1837
|
-
// clamp,
|
|
1838
|
-
arange,
|
|
1839
|
-
linspace,
|
|
1840
|
-
logspace,
|
|
1841
|
-
geomspace,
|
|
1842
|
-
|
|
1843
|
-
// sum,
|
|
1844
|
-
// prod,
|
|
1845
|
-
// accum,
|
|
1846
|
-
|
|
1847
|
-
cartesianProduct,
|
|
1848
|
-
ppcm,
|
|
1849
|
-
pgcd,
|
|
1850
|
-
|
|
1851
|
-
// deg2rad,
|
|
1852
|
-
// rad2deg,
|
|
1853
|
-
|
|
1854
|
-
inRange,
|
|
1855
|
-
isApproximatlyEqual
|
|
1856
|
-
};
|
|
1857
|
-
|
|
1858
1678
|
class UINode {
|
|
1859
1679
|
constructor(node){
|
|
1860
1680
|
this.cache = {
|
|
@@ -4322,110 +4142,6 @@
|
|
|
4322
4142
|
const svg2imgUrl=svg=>'data:image/svg+xml;base64,'+svg2ascii(svg);
|
|
4323
4143
|
const svg2img=(svg,render=true)=>tags.img(svg2imgUrl(svg)).mount(render);
|
|
4324
4144
|
|
|
4325
|
-
// const obj2str=(object)=>{
|
|
4326
|
-
// const recursiveToString = (obj) => {
|
|
4327
|
-
// if (Array.isArray(obj)) return arr2str(obj);
|
|
4328
|
-
// if (typeof obj === 'object' && obj !== null) {
|
|
4329
|
-
// return `{ ${Object.entries(obj)
|
|
4330
|
-
// .map(([key, value]) => `${key}:${recursiveToString(value)}`)
|
|
4331
|
-
// .join(" , ")} }`;
|
|
4332
|
-
// }
|
|
4333
|
-
// return String(obj);
|
|
4334
|
-
// };
|
|
4335
|
-
// return recursiveToString(object);
|
|
4336
|
-
// };
|
|
4337
|
-
// const obj2str = (object) => {
|
|
4338
|
-
// const recursiveToString = (obj, indentLevel = 0) => {
|
|
4339
|
-
// const indent = ' '.repeat(indentLevel);
|
|
4340
|
-
// const nextIndent = ' '.repeat(indentLevel + 1);
|
|
4341
|
-
// if(Array.isArray(obj)) return arr2str(obj, indentLevel);
|
|
4342
|
-
// if(obj instanceof Complex || obj instanceof Matrix) return obj.toString();
|
|
4343
|
-
// if (typeof obj === 'object' && obj !== null) {
|
|
4344
|
-
// const entries = Object.entries(obj)
|
|
4345
|
-
// .map(([key, value]) => `${nextIndent}${key}: ${recursiveToString(value, indentLevel + 1)}`)
|
|
4346
|
-
// .join(",\n");
|
|
4347
|
-
|
|
4348
|
-
// return `{\n${entries}\n${indent}}`;
|
|
4349
|
-
// }
|
|
4350
|
-
|
|
4351
|
-
// return String(obj);
|
|
4352
|
-
// };
|
|
4353
|
-
|
|
4354
|
-
// return recursiveToString(object);
|
|
4355
|
-
// };
|
|
4356
|
-
// const obj2str = (object, useIndentation = true, indentLevel = 0) => {
|
|
4357
|
-
// const recursiveToString = (obj, level = 0) => {
|
|
4358
|
-
// const indent = useIndentation ? ' '.repeat(level) : '';
|
|
4359
|
-
// const nextIndent = useIndentation ? ' '.repeat(level + 1) : '';
|
|
4360
|
-
// if (Array.isArray(obj)) return arr2str(obj, false, level);
|
|
4361
|
-
// if(obj instanceof Complex || obj instanceof Matrix) return obj.toString();
|
|
4362
|
-
// if (typeof obj === 'object' && obj !== null) {
|
|
4363
|
-
// const entries = Object.entries(obj)
|
|
4364
|
-
// .map(([key, value]) => useIndentation
|
|
4365
|
-
// ? `${nextIndent}${key}: ${recursiveToString(value, level + 1)}`
|
|
4366
|
-
// : `${key}: ${recursiveToString(value, level + 1)}`
|
|
4367
|
-
// ).join(useIndentation ? ",\n" : ", ");
|
|
4368
|
-
|
|
4369
|
-
// return useIndentation
|
|
4370
|
-
// ? `{\n${entries}\n${indent}}`
|
|
4371
|
-
// : `{${entries}}`;
|
|
4372
|
-
// }
|
|
4373
|
-
|
|
4374
|
-
// return String(obj);
|
|
4375
|
-
// };
|
|
4376
|
-
|
|
4377
|
-
// return recursiveToString(object, indentLevel);
|
|
4378
|
-
// };
|
|
4379
|
-
|
|
4380
|
-
const obj2str=(obj)=>JSON.stringify(
|
|
4381
|
-
mapfun(n=>{
|
|
4382
|
-
if(["number","string","boolean","bigint"].includes(typeof n)) return String(n);
|
|
4383
|
-
if(n instanceof Complex || n instanceof Matrix) return n.toString();
|
|
4384
|
-
if(n instanceof Array) return arr2str(n)
|
|
4385
|
-
},
|
|
4386
|
-
obj), null, " ")
|
|
4387
|
-
.replace(/"([^"]+)":/g, '$1:') // Remove Quotes from Keys
|
|
4388
|
-
.replace(/: "([^"]+)"/g, ': $1'); // Remove Quotes from str values
|
|
4389
|
-
|
|
4390
|
-
const getMaxDepth = arr=> {
|
|
4391
|
-
if (!Array.isArray(arr)) return 0;
|
|
4392
|
-
let maxDepth = 1;
|
|
4393
|
-
for (const element of arr) {
|
|
4394
|
-
if (Array.isArray(element)) {
|
|
4395
|
-
const depth = getMaxDepth(element);
|
|
4396
|
-
if (depth + 1 > maxDepth) {
|
|
4397
|
-
maxDepth = depth + 1;
|
|
4398
|
-
}
|
|
4399
|
-
}
|
|
4400
|
-
}
|
|
4401
|
-
return maxDepth;
|
|
4402
|
-
};
|
|
4403
|
-
const arr2str = (arr) => {
|
|
4404
|
-
let level = 0;
|
|
4405
|
-
function arrStringify(arr) {
|
|
4406
|
-
let max = getMaxDepth(arr);
|
|
4407
|
-
let useIdentation = 0;
|
|
4408
|
-
if (arr.some((n) => Array.isArray(n))) {
|
|
4409
|
-
level++;
|
|
4410
|
-
useIdentation = 1;
|
|
4411
|
-
}
|
|
4412
|
-
return (
|
|
4413
|
-
"[" +
|
|
4414
|
-
arr.map((n, i) => {
|
|
4415
|
-
if (["number", "string", "boolean", "bigint"].includes(typeof n))
|
|
4416
|
-
return String(n);
|
|
4417
|
-
if (n instanceof Complex) return n.toString();
|
|
4418
|
-
if (n instanceof Array) {
|
|
4419
|
-
return `\n${" ".repeat(level)}${arrStringify(n)}${i === arr.length - 1 ? "\n" : ""}`;
|
|
4420
|
-
}
|
|
4421
|
-
if( n instanceof Object) return obj2str(n);
|
|
4422
|
-
})
|
|
4423
|
-
+ `${" ".repeat((max+level+1) * useIdentation)}]`
|
|
4424
|
-
);
|
|
4425
|
-
}
|
|
4426
|
-
return arrStringify(arr);
|
|
4427
|
-
};
|
|
4428
|
-
|
|
4429
4145
|
const json2css=(json, indentLevel = 0)=>{
|
|
4430
4146
|
json = trimKeys(json);
|
|
4431
4147
|
let cssText = '';
|
|
@@ -4698,6 +4414,49 @@
|
|
|
4698
4414
|
})
|
|
4699
4415
|
}
|
|
4700
4416
|
|
|
4417
|
+
const mapfun=(fun,...X)=>{
|
|
4418
|
+
const Y=X.map(x=>{
|
|
4419
|
+
if(
|
|
4420
|
+
x===null||
|
|
4421
|
+
["number","string","boolean","bigint","undefined"].includes(typeof x)||
|
|
4422
|
+
x?.__mapfun__
|
|
4423
|
+
) return fun(x)
|
|
4424
|
+
if(x instanceof Array) return x.map(n=>mapfun(fun,n));
|
|
4425
|
+
if(ArrayBuffer.isView(x)) return x.map(n=>fun(n));
|
|
4426
|
+
if(x instanceof Set) return new Set(mapfun(fun,...[...x]));
|
|
4427
|
+
if(x instanceof Map) return new Map([...x].map(n=>[n[0],mapfun(fun,n[1])]));
|
|
4428
|
+
if(x.isMatrix?.()) return new x.constructor(x.rows, x.cols, mapfun(x.arr.flat(1)))
|
|
4429
|
+
// if(x.isComplex?.()){
|
|
4430
|
+
// const [a,b,z,phi]=[x.a,x.b,x.z,x.phi];
|
|
4431
|
+
// switch(fun){
|
|
4432
|
+
// // Moved to Fixed to avoid Circular Dep
|
|
4433
|
+
// // case Math.log: return new x.constructor(ln(z),phi); // Done
|
|
4434
|
+
// // case Math.exp: return new x.constructor(e(a)*cos(b),e(a)*sin(b)); // Done
|
|
4435
|
+
// // case Math.abs: return z; // Done
|
|
4436
|
+
// // case Math.sqrt: return new x.constructor(sqrt(z)*cos(phi/2),sqrt(z)*sin(phi/2)); // Done
|
|
4437
|
+
// // case Fixed.cos: return new x.constructor(cos(a)*cosh(b),-(sin(a)*sinh(b)));
|
|
4438
|
+
// // case Fixed.sin: return new x.constructor(sin(a)*cosh(b),cos(a)*sinh(b));
|
|
4439
|
+
// // case Fixed.tan:{
|
|
4440
|
+
// // const DEN = cos(2*a)+cosh(2*b);
|
|
4441
|
+
// // return new x.constructor(sin(2*a)/DEN,sinh(2*b)/DEN);
|
|
4442
|
+
// // }
|
|
4443
|
+
// // case Fixed.cosh:return new x.constructor(cosh(a)*cos(b),sinh(a)*sin(b));
|
|
4444
|
+
// // case Fixed.sinh:return new x.constructor(sinh(a)*cos(b),cosh(a)*sin(b));
|
|
4445
|
+
// // case Fixed.tanh:{
|
|
4446
|
+
// // const DEN=cosh(2*a)+cos(2*b);
|
|
4447
|
+
// // return new x.constructor(sinh(2*a)/DEN,sin(2*b)/DEN)
|
|
4448
|
+
// // }
|
|
4449
|
+
// default : return fun(x)
|
|
4450
|
+
// }
|
|
4451
|
+
// }
|
|
4452
|
+
else if(x instanceof Object){
|
|
4453
|
+
return Object.fromEntries(Object.entries(x).map(n=>n=[n[0],mapfun(fun,n[1])]))
|
|
4454
|
+
// return fun(Object) || Object.fromEntries(Object.entries(x).map(n=>n=[n[0],mapfun(fun,n[1])]))
|
|
4455
|
+
}
|
|
4456
|
+
});
|
|
4457
|
+
return Y.length==1? Y[0]: Y;
|
|
4458
|
+
};
|
|
4459
|
+
|
|
4701
4460
|
const useReactive = (nested_value) => mapfun(
|
|
4702
4461
|
n => {
|
|
4703
4462
|
const state = useState(n);
|
|
@@ -5167,7 +4926,6 @@
|
|
|
5167
4926
|
exports.UIView = UIView;
|
|
5168
4927
|
exports.UseRoot = UseRoot;
|
|
5169
4928
|
exports.UseThread = UseThread;
|
|
5170
|
-
exports.Utils = Utils;
|
|
5171
4929
|
exports.View = View;
|
|
5172
4930
|
exports.ViewEvent = ViewEvent;
|
|
5173
4931
|
exports.ViewListeners = ViewListeners;
|
|
@@ -5187,9 +4945,7 @@
|
|
|
5187
4945
|
exports.and = and;
|
|
5188
4946
|
exports.animation = animation;
|
|
5189
4947
|
exports.apply_fun = apply_fun;
|
|
5190
|
-
exports.arange = arange;
|
|
5191
4948
|
exports.arc = arc;
|
|
5192
|
-
exports.arr2str = arr2str;
|
|
5193
4949
|
exports.asin = asin;
|
|
5194
4950
|
exports.asinh = asinh;
|
|
5195
4951
|
exports.atan = atan;
|
|
@@ -5198,7 +4954,6 @@
|
|
|
5198
4954
|
exports.back = back;
|
|
5199
4955
|
exports.binomial = binomial;
|
|
5200
4956
|
exports.call_with_optional_props = call_with_optional_props;
|
|
5201
|
-
exports.cartesianProduct = cartesianProduct;
|
|
5202
4957
|
exports.cbrt = cbrt;
|
|
5203
4958
|
exports.ceil = ceil;
|
|
5204
4959
|
exports.clamp = clamp;
|
|
@@ -5224,9 +4979,7 @@
|
|
|
5224
4979
|
exports.exp = exp$1;
|
|
5225
4980
|
exports.floor = floor;
|
|
5226
4981
|
exports.fract = fract;
|
|
5227
|
-
exports.geomspace = geomspace;
|
|
5228
4982
|
exports.hypot = hypot;
|
|
5229
|
-
exports.inRange = inRange;
|
|
5230
4983
|
exports.in_back = in_back;
|
|
5231
4984
|
exports.in_bounce = in_bounce;
|
|
5232
4985
|
exports.in_circ = in_circ;
|
|
@@ -5247,7 +5000,6 @@
|
|
|
5247
5000
|
exports.in_quart = in_quart;
|
|
5248
5001
|
exports.in_quint = in_quint;
|
|
5249
5002
|
exports.in_sin = in_sin;
|
|
5250
|
-
exports.isApproximatlyEqual = isApproximatlyEqual;
|
|
5251
5003
|
exports.isPrimitive = isPrimitive;
|
|
5252
5004
|
exports.isStateGetter = isStateGetter;
|
|
5253
5005
|
exports.json2arr = json2arr;
|
|
@@ -5261,12 +5013,10 @@
|
|
|
5261
5013
|
exports.lerp = lerp;
|
|
5262
5014
|
exports.linear = linear;
|
|
5263
5015
|
exports.linkStyle = linkStyle;
|
|
5264
|
-
exports.linspace = linspace;
|
|
5265
5016
|
exports.ln = ln;
|
|
5266
|
-
exports.logspace = logspace;
|
|
5267
5017
|
exports.loop = loop;
|
|
5268
5018
|
exports.map = map$1;
|
|
5269
|
-
exports.mapfun = mapfun;
|
|
5019
|
+
exports.mapfun = mapfun$1;
|
|
5270
5020
|
exports.matrix = matrix;
|
|
5271
5021
|
exports.matrix2 = matrix2;
|
|
5272
5022
|
exports.matrix3 = matrix3;
|
|
@@ -5282,9 +5032,6 @@
|
|
|
5282
5032
|
exports.norm = norm;
|
|
5283
5033
|
exports.normalize_css_value = normalize_css_value;
|
|
5284
5034
|
exports.nthr = nthr;
|
|
5285
|
-
exports.nums = nums;
|
|
5286
|
-
exports.obj2str = obj2str;
|
|
5287
|
-
exports.ones = ones;
|
|
5288
5035
|
exports.or = or;
|
|
5289
5036
|
exports.out_back = out_back;
|
|
5290
5037
|
exports.out_bounce = out_bounce;
|
|
@@ -5297,9 +5044,7 @@
|
|
|
5297
5044
|
exports.out_quint = out_quint;
|
|
5298
5045
|
exports.out_sin = out_sin;
|
|
5299
5046
|
exports.percentile = percentile;
|
|
5300
|
-
exports.pgcd = pgcd;
|
|
5301
5047
|
exports.pow = pow$1;
|
|
5302
|
-
exports.ppcm = ppcm;
|
|
5303
5048
|
exports.rad2deg = rad2deg;
|
|
5304
5049
|
exports.register_click_away_event = register_click_away_event;
|
|
5305
5050
|
exports.register_swipe_event = register_swipe_event;
|
|
@@ -5353,6 +5098,5 @@
|
|
|
5353
5098
|
exports.watchQueryParams = watchQueryParams;
|
|
5354
5099
|
exports.xnor = xnor;
|
|
5355
5100
|
exports.xor = xor;
|
|
5356
|
-
exports.zeros = zeros;
|
|
5357
5101
|
|
|
5358
5102
|
}));
|