ziko 0.51.1 → 0.53.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 +1638 -1456
- package/dist/ziko.js +853 -810
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +853 -810
- package/package.json +1 -1
- package/src/{__helpers__ → helpers}/register/index.js +1 -1
- package/src/hooks/use-ipc.js +1 -3
- package/src/math/adapted/index.js +7 -0
- package/src/math/complex/index.js +11 -8
- package/src/math/functions/helper.js +68 -17
- package/src/math/functions/index.js +3 -2
- package/src/math/functions/primitives/index.js +355 -0
- package/src/math/mapfun/index.js +19 -0
- package/src/math/utils/index.js +1 -1
- package/src/math/utils/mapfun.js +30 -30
- package/src/ui/constructors/UIElement.js +9 -9
- package/src/ui/constructors/UIElementCore.js +2 -2
- package/types/math/adapted/index.d.ts +4 -0
- package/types/math/complex/index.d.ts +1 -1
- package/types/math/mapfun/index.d.ts +87 -0
- /package/src/{__helpers__ → helpers}/checkers/index.js +0 -0
- /package/src/{__helpers__ → helpers}/index.js +0 -0
- /package/src/{__helpers__ → helpers}/register/register-to-class.js +0 -0
- /package/src/{__helpers__ → helpers}/register/register-to-instance.js +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ziko",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.53.0",
|
|
4
4
|
"description": "A versatile JavaScript library offering a rich set of Hyperscript Based UI components, advanced mathematical utilities, interactivity ,animations, client side routing and more ...",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"front-end",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { register_to_class } from "./register-to-class.js";
|
|
2
|
-
import { register_to_instance } from "./register-to-instance"; // Not Overridable
|
|
2
|
+
import { register_to_instance } from "./register-to-instance.js"; // Not Overridable
|
|
3
3
|
export const register = (target, ...mixins) => {
|
|
4
4
|
console.log(target)
|
|
5
5
|
// return register_to_class(target, ...mixins)
|
package/src/hooks/use-ipc.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Random } from "../math/random/index.js";
|
|
2
|
-
|
|
3
1
|
class UseIPC {
|
|
4
2
|
#channel;
|
|
5
3
|
#eventData;
|
|
@@ -11,7 +9,7 @@ class UseIPC {
|
|
|
11
9
|
this.#channel = new BroadcastChannel(name);
|
|
12
10
|
this.#eventData = new Map();
|
|
13
11
|
this.#handlers = new Map(); // Map<event, Array<{fn, rooms}>>
|
|
14
|
-
this.#uuid = "ziko-channel:" +
|
|
12
|
+
this.#uuid = "ziko-channel:" + (Math.random()*10e16); // To Be Replaced by UUID
|
|
15
13
|
this.#subscribers = new Set([this.#uuid]);
|
|
16
14
|
this.#currentRooms = new Set();
|
|
17
15
|
this.#channel.addEventListener("message", (e) => {
|
|
@@ -41,8 +41,8 @@ class Complex{
|
|
|
41
41
|
this.a=a.b/tan(a.phi);
|
|
42
42
|
}
|
|
43
43
|
else if(("z" in a && "phi" in a)){
|
|
44
|
-
this.a=a.z*cos(a.phi);
|
|
45
|
-
this.
|
|
44
|
+
this.a = +a.z*cos(a.phi).toFixed(15);
|
|
45
|
+
this.b = +a.z*sin(a.phi).toFixed(15);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
else if(typeof(a)==="number"&&typeof(b)==="number"){
|
|
@@ -50,6 +50,9 @@ class Complex{
|
|
|
50
50
|
this.b = +b.toFixed(32);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
+
get __mapfun__(){
|
|
54
|
+
return true
|
|
55
|
+
}
|
|
53
56
|
isComplex(){
|
|
54
57
|
return true
|
|
55
58
|
}
|
|
@@ -66,7 +69,7 @@ class Complex{
|
|
|
66
69
|
return str;
|
|
67
70
|
}
|
|
68
71
|
|
|
69
|
-
|
|
72
|
+
clone() {
|
|
70
73
|
return new Complex(this.a, this.b);
|
|
71
74
|
}
|
|
72
75
|
get z(){
|
|
@@ -143,19 +146,19 @@ class Complex{
|
|
|
143
146
|
return [this.z, this.phi];
|
|
144
147
|
}
|
|
145
148
|
static add(c,...z) {
|
|
146
|
-
return c.clone.add(...z);
|
|
149
|
+
return c.clone().add(...z);
|
|
147
150
|
}
|
|
148
151
|
static sub(c,...z) {
|
|
149
|
-
return c.clone.sub(...z);
|
|
152
|
+
return c.clone().sub(...z);
|
|
150
153
|
}
|
|
151
154
|
static mul(c,...z) {
|
|
152
|
-
return c.clone.mul(...z);
|
|
155
|
+
return c.clone().mul(...z);
|
|
153
156
|
}
|
|
154
157
|
static div(c,...z) {
|
|
155
|
-
return c.clone.div(...z);
|
|
158
|
+
return c.clone().div(...z);
|
|
156
159
|
}
|
|
157
160
|
static pow(z,n){
|
|
158
|
-
return z.clone.pow(n);
|
|
161
|
+
return z.clone().pow(n);
|
|
159
162
|
}
|
|
160
163
|
static xpowZ(x){
|
|
161
164
|
return complex((x**this.a)*cos(this.b*ln(x)),(x**this.a)*sin(this.b*ln(x)));
|
|
@@ -1,30 +1,81 @@
|
|
|
1
1
|
const {PI, cos, sin, tan, acos, asin, atan, cosh, sinh, tanh, acosh, asinh, atanh, log} = Math
|
|
2
2
|
export let Fixed={
|
|
3
|
-
cos
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
cos : x=> {
|
|
4
|
+
if(x.isComplex?.()) return new x.constructor(
|
|
5
|
+
cos(x.a)*cosh(x.b),
|
|
6
|
+
-(sin(x.a)*sinh(x.b))
|
|
7
|
+
);
|
|
8
|
+
return cos(x)
|
|
9
|
+
},
|
|
10
|
+
sin : x=>{
|
|
11
|
+
if(x?.isComplex) return new x.constructor(
|
|
12
|
+
sin(x.a)*cosh(x.b),
|
|
13
|
+
cos(x.a)*sinh(x.b)
|
|
14
|
+
);
|
|
15
|
+
return sin(x)
|
|
16
|
+
},
|
|
17
|
+
tan : x=>{
|
|
18
|
+
if(x?.isComplex){
|
|
19
|
+
const DEN = cos(2*x.a)+cosh(2*x.b);
|
|
20
|
+
return new x.constructor(
|
|
21
|
+
sin(2*x.a)/DEN,
|
|
22
|
+
sinh(2*x.b)/DEN
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
return tan(x)
|
|
26
|
+
},
|
|
6
27
|
sinc: x => sin(PI*x)/(PI*x),
|
|
7
28
|
sec: x => 1/cos(x),
|
|
8
29
|
csc: x => 1/sin(x),
|
|
9
30
|
cot: x => 1/tan(x),
|
|
10
|
-
acos
|
|
11
|
-
|
|
12
|
-
|
|
31
|
+
acos: x=>{
|
|
32
|
+
if(x?.isComplex) return
|
|
33
|
+
return sin(x)
|
|
34
|
+
},
|
|
35
|
+
asin: x=>{
|
|
36
|
+
if(x?.isComplex) return
|
|
37
|
+
return sin(x)
|
|
38
|
+
},
|
|
39
|
+
atan: x=>{
|
|
40
|
+
if(x?.isComplex) return
|
|
41
|
+
return sin(x)
|
|
42
|
+
},
|
|
13
43
|
acot: x => PI/2-atan(x),
|
|
14
|
-
cosh
|
|
15
|
-
|
|
16
|
-
|
|
44
|
+
cosh: x=>{
|
|
45
|
+
if(x?.isComplex) return new x.constructor(
|
|
46
|
+
cosh(x.a)*cos(x.b),
|
|
47
|
+
sinh(x.a)*sin(x.b)
|
|
48
|
+
);
|
|
49
|
+
return cosh(x)
|
|
50
|
+
},
|
|
51
|
+
sinh: x=>{
|
|
52
|
+
if(x?.isComplex) return new x.constructor(
|
|
53
|
+
sinh(x.a)*cos(x.b),
|
|
54
|
+
cosh(x.a)*sin(x.b)
|
|
55
|
+
);
|
|
56
|
+
return sinh(x)
|
|
57
|
+
},
|
|
58
|
+
tanh: x=>{
|
|
59
|
+
if(x?.isComplex){
|
|
60
|
+
const DEN=cosh(2*a)+cos(2*b);
|
|
61
|
+
return new x.constructor(
|
|
62
|
+
sinh(2*a)/DEN,
|
|
63
|
+
sin(2*b)/DEN
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
return tanh(x)
|
|
67
|
+
},
|
|
17
68
|
coth: n => (1/2*log((1+n)/(1-n))),
|
|
18
69
|
acosh,
|
|
19
70
|
asinh,
|
|
20
71
|
atanh,
|
|
21
72
|
}
|
|
22
73
|
|
|
23
|
-
Fixed = new Proxy(Fixed, {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
})
|
|
74
|
+
// Fixed = new Proxy(Fixed, {
|
|
75
|
+
// get(target, prop) {
|
|
76
|
+
// if(prop in target){
|
|
77
|
+
// return x => + target[prop](x).toFixed(15);
|
|
78
|
+
// }
|
|
79
|
+
// return undefined;
|
|
80
|
+
// }
|
|
81
|
+
// })
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Fixed } from "./helper.js";
|
|
2
|
-
import { mapfun } from "../
|
|
2
|
+
import { mapfun } from "../mapfun/index.js";
|
|
3
3
|
import {
|
|
4
4
|
min,
|
|
5
5
|
max
|
|
6
|
-
}
|
|
6
|
+
}
|
|
7
|
+
from "../statistics/index.js";
|
|
7
8
|
|
|
8
9
|
const abs=(...x)=>mapfun(Math.abs,...x);
|
|
9
10
|
const sqrt=(...x)=>mapfun(Math.sqrt,...x);
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { mapfun } from '../../mapfun/index.js';
|
|
2
|
+
|
|
3
|
+
export const abs = (...x) => mapfun(
|
|
4
|
+
x =>{
|
|
5
|
+
if(x.isComplex?.()) return x.z;
|
|
6
|
+
return Math.abs(x)
|
|
7
|
+
},
|
|
8
|
+
...x
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
export const pow = (...x) => {
|
|
12
|
+
const n = x.pop();
|
|
13
|
+
return mapfun(
|
|
14
|
+
x => {
|
|
15
|
+
if(x.isComplex?.()) {
|
|
16
|
+
if(n.isComplex?.()) return new x.constructor({
|
|
17
|
+
z: Math.exp(n.a * Math.log(x.z) - n.b * x.phi),
|
|
18
|
+
phi: n.b * Math.log(x.z) + n.a * x.phi
|
|
19
|
+
})
|
|
20
|
+
return new x.constructor({z: x.z ** n, phi: x.phi * n});
|
|
21
|
+
}
|
|
22
|
+
if(n.isComplex?.()) return new x.constructor({
|
|
23
|
+
z: Math.exp(n.a * Math.log(x)),
|
|
24
|
+
phi: n.b * Math.log(x)
|
|
25
|
+
})
|
|
26
|
+
return Math.pow(x, n)
|
|
27
|
+
},
|
|
28
|
+
...x
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const sqrt = (...x) => mapfun(
|
|
33
|
+
x=>{
|
|
34
|
+
if(x.isComplex?.())
|
|
35
|
+
return new x.constructor({z: x.z**(1/2), phi: x.phi/2})
|
|
36
|
+
return Math.sqrt(x);
|
|
37
|
+
},
|
|
38
|
+
...x
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
export const cbrt = (...x) => mapfun(
|
|
42
|
+
x=>{
|
|
43
|
+
if(x.isComplex?.())
|
|
44
|
+
return new x.constructor({z: x.z**(1/3), phi: x.phi/3})
|
|
45
|
+
return Math.sqrt(x);
|
|
46
|
+
},
|
|
47
|
+
...x
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
export const nthr = (...x) => {
|
|
51
|
+
const n = x.pop();
|
|
52
|
+
return mapfun(
|
|
53
|
+
x => {
|
|
54
|
+
if(x.isComplex?.()) return new x.constructor({z: x.z ** 1/n, phi: x.phi / n});
|
|
55
|
+
return x**(1/n)
|
|
56
|
+
},
|
|
57
|
+
...x
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const croot = (...x) =>{
|
|
62
|
+
const z = x.pop()
|
|
63
|
+
return mapfun(
|
|
64
|
+
x => {
|
|
65
|
+
if(x.isComplex?.()) return null
|
|
66
|
+
return null
|
|
67
|
+
},
|
|
68
|
+
...x
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const exp = (...x) => mapfun(
|
|
73
|
+
x => {
|
|
74
|
+
if(x.isComplex?.()) return new x.constructor(
|
|
75
|
+
Math.exp(x.a) * Math.cos(x.b),
|
|
76
|
+
Math.exp(x.a) * Math.sin(x.b)
|
|
77
|
+
);
|
|
78
|
+
return Math.ln(x)
|
|
79
|
+
}
|
|
80
|
+
,...x
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
export const ln = (...x) => mapfun(
|
|
84
|
+
x => {
|
|
85
|
+
if(x.isComplex?.()) return new x.constructor(
|
|
86
|
+
Math.log(x.z),
|
|
87
|
+
x.phi
|
|
88
|
+
);
|
|
89
|
+
return Math.ln(x)
|
|
90
|
+
}
|
|
91
|
+
,...x
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
export const sign = (...x) => mapfun(
|
|
95
|
+
x => {
|
|
96
|
+
if(x.isComplex?.()){
|
|
97
|
+
const {z, phi} = x;
|
|
98
|
+
if(z===0) return new x.constructor(0, 0);
|
|
99
|
+
return new x.constructor({z:1, phi})
|
|
100
|
+
}
|
|
101
|
+
return Math.sign(x)
|
|
102
|
+
}
|
|
103
|
+
,...x
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
export const floor = (...x) => mapfun(
|
|
107
|
+
x => {
|
|
108
|
+
if(x.isComplex?.()) return new x.constructor(
|
|
109
|
+
Math.floor(x.a),
|
|
110
|
+
Math.floor(x.b)
|
|
111
|
+
)
|
|
112
|
+
return Math.floor(x)
|
|
113
|
+
},
|
|
114
|
+
...x
|
|
115
|
+
)
|
|
116
|
+
export const ceil = (...x) => mapfun(
|
|
117
|
+
x => {
|
|
118
|
+
if(x.isComplex?.()) return new x.constructor(
|
|
119
|
+
Math.ceil(x.a),
|
|
120
|
+
Math.ceil(x.b)
|
|
121
|
+
)
|
|
122
|
+
return Math.ceil(x)
|
|
123
|
+
},
|
|
124
|
+
...x
|
|
125
|
+
)
|
|
126
|
+
export const round = (...x) => mapfun(
|
|
127
|
+
x => {
|
|
128
|
+
if(x.isComplex?.()) return new x.constructor(
|
|
129
|
+
Math.round(x.a),
|
|
130
|
+
Math.round(x.b)
|
|
131
|
+
)
|
|
132
|
+
return Math.round(x)
|
|
133
|
+
},
|
|
134
|
+
...x
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
export const trunc = (...x) => mapfun(
|
|
138
|
+
x => {
|
|
139
|
+
if(x.isComplex?.()) return new x.constructor(
|
|
140
|
+
Math.trunc(x.a),
|
|
141
|
+
Math.trunc(x.b)
|
|
142
|
+
)
|
|
143
|
+
return Math.trunc(x)
|
|
144
|
+
},
|
|
145
|
+
...x
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
export const fract = (...x) => mapfun(
|
|
149
|
+
x => {
|
|
150
|
+
if(x.isComplex?.()) return new x.constructor(
|
|
151
|
+
x.a - Math.trunc(x.a),
|
|
152
|
+
x.b - Math.trunc(x.b)
|
|
153
|
+
)
|
|
154
|
+
return x - Math.trunc(x)
|
|
155
|
+
},
|
|
156
|
+
...x
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
export const cos = (...x) => mapfun(
|
|
160
|
+
x => {
|
|
161
|
+
if(x.isComplex?.()) return new x.constructor(
|
|
162
|
+
Math.cos(x.a) * Math.cosh(x.b),
|
|
163
|
+
-Math.sin(x.a) * Math.sinh(x.b)
|
|
164
|
+
);
|
|
165
|
+
return Math.cos(x)
|
|
166
|
+
}
|
|
167
|
+
,...x
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
export const sin = (...x) => mapfun(
|
|
171
|
+
x =>{
|
|
172
|
+
if(x?.isComplex) return new x.constructor(
|
|
173
|
+
Math.sin(x.a) * Math.cosh(x.b),
|
|
174
|
+
Math.cos(x.a) * Math.sinh(x.b)
|
|
175
|
+
);
|
|
176
|
+
return Math.sin(x)
|
|
177
|
+
}
|
|
178
|
+
, ...x
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
export const tan = (...x) => mapfun(
|
|
182
|
+
x =>{
|
|
183
|
+
if(x?.isComplex){
|
|
184
|
+
const D = Math.cos(2*x.a) + Math.cosh(2*x.b);
|
|
185
|
+
return new x.constructor(
|
|
186
|
+
Math.sin(2*x.a) / D,
|
|
187
|
+
Math.sinh(2*x.b) / D
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
return Math.tan(x)
|
|
191
|
+
},
|
|
192
|
+
...x
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
export const sec = (...x) => mapfun(
|
|
196
|
+
x => {
|
|
197
|
+
if(x.isComplex?.()) {
|
|
198
|
+
|
|
199
|
+
}
|
|
200
|
+
return 1 / Math.cos(x)
|
|
201
|
+
}
|
|
202
|
+
,...x
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
export const acos = (...x) => mapfun(
|
|
206
|
+
x =>{
|
|
207
|
+
if(x?.isComplex){
|
|
208
|
+
const { a, b } = x;
|
|
209
|
+
const Rp = Math.hypot(a + 1, b);
|
|
210
|
+
const Rm = Math.hypot(a - 1, b);
|
|
211
|
+
globalThis.Rp = Rp
|
|
212
|
+
globalThis.Rm = Rm
|
|
213
|
+
return new x.constructor(
|
|
214
|
+
Math.acos((Rp - Rm) / 2),
|
|
215
|
+
-Math.acosh((Rp + Rm) / 2),
|
|
216
|
+
)
|
|
217
|
+
}
|
|
218
|
+
return Math.acos(x)
|
|
219
|
+
},
|
|
220
|
+
...x
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
export const asin = (...x) => mapfun(
|
|
224
|
+
x => {
|
|
225
|
+
if(x?.isComplex){
|
|
226
|
+
const { a, b } = x;
|
|
227
|
+
const Rp = Math.hypot(a + 1, b);
|
|
228
|
+
const Rm = Math.hypot(a - 1, b);
|
|
229
|
+
return new x.constructor(
|
|
230
|
+
Math.asin((Rp - Rm) / 2),
|
|
231
|
+
Math.acosh((Rp + Rm) / 2)
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
return Math.asin(x);
|
|
235
|
+
},
|
|
236
|
+
...x
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
export const atan = (...x) => mapfun(
|
|
240
|
+
x => {
|
|
241
|
+
if(x?.isComplex){
|
|
242
|
+
const { a, b } = x;
|
|
243
|
+
return new x.constructor(
|
|
244
|
+
Math.atan((a*2/(1-a**2-b**2)))/2,
|
|
245
|
+
Math.log((a**2 + (1+b)**2)/(a**2 + (1-b)**2))/4
|
|
246
|
+
)
|
|
247
|
+
}
|
|
248
|
+
return Math.atan(x);
|
|
249
|
+
},
|
|
250
|
+
...x
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
export const acot = (...x) => mapfun(
|
|
254
|
+
x => {
|
|
255
|
+
if(x?.isComplex){
|
|
256
|
+
const { a, b } = x;
|
|
257
|
+
return new x.constructor(
|
|
258
|
+
Math.atan(2*a/(a**2+(b-1)*(b+1)))/2,
|
|
259
|
+
Math.log((a**2 + (b-1)**2)/(a**2 + (b+1)**2))/4
|
|
260
|
+
)
|
|
261
|
+
}
|
|
262
|
+
return Math.PI/2 - Math.atan(x);
|
|
263
|
+
},
|
|
264
|
+
...x
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
export const cosh = (...x) => mapfun(
|
|
269
|
+
x =>{
|
|
270
|
+
if(x?.isComplex) return new x.constructor(
|
|
271
|
+
cosh(x.a)*cos(x.b),
|
|
272
|
+
sinh(x.a)*sin(x.b)
|
|
273
|
+
);
|
|
274
|
+
return cosh(x)
|
|
275
|
+
},
|
|
276
|
+
...x
|
|
277
|
+
)
|
|
278
|
+
export const sinh = (...x) => mapfun(
|
|
279
|
+
x =>{
|
|
280
|
+
if(x?.isComplex) return new x.constructor(
|
|
281
|
+
sinh(x.a)*cos(x.b),
|
|
282
|
+
cosh(x.a)*sin(x.b)
|
|
283
|
+
);
|
|
284
|
+
return sinh(x)
|
|
285
|
+
},
|
|
286
|
+
...x
|
|
287
|
+
)
|
|
288
|
+
export const tanh = (...x) => mapfun(
|
|
289
|
+
x =>{
|
|
290
|
+
if(x?.isComplex){
|
|
291
|
+
const D=cosh(2*a)+cos(2*b);
|
|
292
|
+
return new x.constructor(
|
|
293
|
+
sinh(2*a)/D,
|
|
294
|
+
sin(2*b)/D
|
|
295
|
+
)
|
|
296
|
+
}
|
|
297
|
+
return tanh(x)
|
|
298
|
+
},
|
|
299
|
+
...x
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
export const coth = (...x) => mapfun(
|
|
303
|
+
x =>{
|
|
304
|
+
if(x?.isComplex){
|
|
305
|
+
const {a, b} = x
|
|
306
|
+
const D = (Math.sinh(a)**2)*(Math.cos(b)**2) + (Math.cosh(a)**2)*(Math.sin(b)**2)
|
|
307
|
+
return new x.constructor(
|
|
308
|
+
Math.cosh(a) * Math.sinh(a) / D,
|
|
309
|
+
- Math.sin(b) * Math.cos(b) / D
|
|
310
|
+
)
|
|
311
|
+
}
|
|
312
|
+
return 1/Math.tanh(x)
|
|
313
|
+
},
|
|
314
|
+
...x
|
|
315
|
+
)
|
|
316
|
+
|
|
317
|
+
export const acosh = (...x) => mapfun(
|
|
318
|
+
x =>{
|
|
319
|
+
if(x?.isComplex){
|
|
320
|
+
return ln(x.clone().add(sqrt(x.clone().mul(x.clone()).sub(1))))
|
|
321
|
+
}
|
|
322
|
+
return Math.acosh(x)
|
|
323
|
+
},
|
|
324
|
+
...x
|
|
325
|
+
)
|
|
326
|
+
|
|
327
|
+
export const asinh = (...x) => mapfun(
|
|
328
|
+
x =>{
|
|
329
|
+
if(x?.isComplex){
|
|
330
|
+
return ln(x.clone().add(sqrt(x.clone().mul(x.clone()).add(1))))
|
|
331
|
+
}
|
|
332
|
+
return Math.asinh(x)
|
|
333
|
+
},
|
|
334
|
+
...x
|
|
335
|
+
)
|
|
336
|
+
|
|
337
|
+
export const atanh = (...x) => mapfun(
|
|
338
|
+
x =>{
|
|
339
|
+
if(x?.isComplex){
|
|
340
|
+
|
|
341
|
+
}
|
|
342
|
+
return Math.atanh(x)
|
|
343
|
+
},
|
|
344
|
+
...x
|
|
345
|
+
)
|
|
346
|
+
|
|
347
|
+
export const sig = (...x) => mapfun(
|
|
348
|
+
x =>{
|
|
349
|
+
if(x?.isComplex){
|
|
350
|
+
|
|
351
|
+
}
|
|
352
|
+
return 1/(1+Math.e(-x))
|
|
353
|
+
},
|
|
354
|
+
...x
|
|
355
|
+
)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { is_primitive } from "../../helpers/checkers/index.js";
|
|
2
|
+
export const mapfun=(fun,...X)=>{
|
|
3
|
+
const Y=X.map(x=>{
|
|
4
|
+
if(is_primitive(x) || x?.__mapfun__) return fun(x)
|
|
5
|
+
if(x instanceof Array) return x.map(n=>mapfun(fun,n));
|
|
6
|
+
if(ArrayBuffer.isView(x)) return x.map(n=>fun(n));
|
|
7
|
+
if(x instanceof Set) return new Set(mapfun(fun,...[...x]));
|
|
8
|
+
if(x instanceof Map) return new Map([...x].map(n=>[n[0],mapfun(fun,n[1])]));
|
|
9
|
+
if(x.isMatrix?.()) return new x.constructor(x.rows, x.cols, mapfun(x.arr.flat(1)))
|
|
10
|
+
else if(x instanceof Object){
|
|
11
|
+
return Object.fromEntries(
|
|
12
|
+
Object.entries(x).map(
|
|
13
|
+
n=>n=[n[0],mapfun(fun,n[1])]
|
|
14
|
+
)
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return Y.length==1? Y[0]: Y;
|
|
19
|
+
}
|
package/src/math/utils/index.js
CHANGED
package/src/math/utils/mapfun.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import {ln,e,cos,sin,sqrt,cosh,sinh} from "../functions/index.js";
|
|
2
|
-
import { Fixed } from "../functions/helper.js";
|
|
3
|
-
// To generalise
|
|
4
1
|
const mapfun=(fun,...X)=>{
|
|
5
2
|
const Y=X.map(x=>{
|
|
6
|
-
if(
|
|
7
|
-
|
|
3
|
+
if(
|
|
4
|
+
x===null||
|
|
5
|
+
["number","string","boolean","bigint","undefined"].includes(typeof x)||
|
|
6
|
+
x?.__mapfun__
|
|
7
|
+
) return fun(x)
|
|
8
8
|
if(x instanceof Array) return x.map(n=>mapfun(fun,n));
|
|
9
9
|
if(ArrayBuffer.isView(x)) return x.map(n=>fun(n));
|
|
10
10
|
if(x instanceof Set) return new Set(mapfun(fun,...[...x]));
|
|
11
11
|
if(x instanceof Map) return new Map([...x].map(n=>[n[0],mapfun(fun,n[1])]));
|
|
12
12
|
if(x.isMatrix?.()) return new x.constructor(x.rows, x.cols, mapfun(x.arr.flat(1)))
|
|
13
|
-
if(x.isComplex?.()){
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
13
|
+
// if(x.isComplex?.()){
|
|
14
|
+
// const [a,b,z,phi]=[x.a,x.b,x.z,x.phi];
|
|
15
|
+
// switch(fun){
|
|
16
|
+
// // Moved to Fixed to avoid Circular Dep
|
|
17
|
+
// // case Math.log: return new x.constructor(ln(z),phi); // Done
|
|
18
|
+
// // case Math.exp: return new x.constructor(e(a)*cos(b),e(a)*sin(b)); // Done
|
|
19
|
+
// // case Math.abs: return z; // Done
|
|
20
|
+
// // case Math.sqrt: return new x.constructor(sqrt(z)*cos(phi/2),sqrt(z)*sin(phi/2)); // Done
|
|
21
|
+
// // case Fixed.cos: return new x.constructor(cos(a)*cosh(b),-(sin(a)*sinh(b)));
|
|
22
|
+
// // case Fixed.sin: return new x.constructor(sin(a)*cosh(b),cos(a)*sinh(b));
|
|
23
|
+
// // case Fixed.tan:{
|
|
24
|
+
// // const DEN = cos(2*a)+cosh(2*b);
|
|
25
|
+
// // return new x.constructor(sin(2*a)/DEN,sinh(2*b)/DEN);
|
|
26
|
+
// // }
|
|
27
|
+
// // case Fixed.cosh:return new x.constructor(cosh(a)*cos(b),sinh(a)*sin(b));
|
|
28
|
+
// // case Fixed.sinh:return new x.constructor(sinh(a)*cos(b),cosh(a)*sin(b));
|
|
29
|
+
// // case Fixed.tanh:{
|
|
30
|
+
// // const DEN=cosh(2*a)+cos(2*b);
|
|
31
|
+
// // return new x.constructor(sinh(2*a)/DEN,sin(2*b)/DEN)
|
|
32
|
+
// // }
|
|
33
|
+
// default : return fun(x)
|
|
34
|
+
// }
|
|
35
|
+
// }
|
|
36
36
|
else if(x instanceof Object){
|
|
37
37
|
return Object.fromEntries(Object.entries(x).map(n=>n=[n[0],mapfun(fun,n[1])]))
|
|
38
|
-
return fun(Object) || Object.fromEntries(Object.entries(x).map(n=>n=[n[0],mapfun(fun,n[1])]))
|
|
38
|
+
// return fun(Object) || Object.fromEntries(Object.entries(x).map(n=>n=[n[0],mapfun(fun,n[1])]))
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
|
-
return Y.length==1?Y[0]:Y;
|
|
41
|
+
return Y.length==1? Y[0]: Y;
|
|
42
42
|
}
|
|
43
43
|
export {mapfun}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UIElementCore } from "./UIElementCore.js";
|
|
2
|
-
import { register_to_class } from "../../
|
|
2
|
+
import { register_to_class } from "../../helpers/register/register-to-class.js";
|
|
3
3
|
import {
|
|
4
4
|
LifecycleMethods,
|
|
5
5
|
AttrsMethods,
|
|
@@ -8,14 +8,14 @@ import {
|
|
|
8
8
|
EventsMethodes,
|
|
9
9
|
StyleMethods
|
|
10
10
|
} from "../__methods__/index.js";
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} from "../../--reactivity-deprecated/events/custom-event.js"
|
|
11
|
+
// import {
|
|
12
|
+
// // useCustomEvent,
|
|
13
|
+
// // useSwipeEvent,
|
|
14
|
+
// // watchIntersection,
|
|
15
|
+
// // watchSize,
|
|
16
|
+
// // watchAttr,
|
|
17
|
+
// // watchChildren
|
|
18
|
+
// } from "../../--reactivity-deprecated/events/custom-event.js"
|
|
19
19
|
class UIElement extends UIElementCore{
|
|
20
20
|
constructor({element, name ='', type='html', render = __Ziko__.__Config__.default.render}={}){
|
|
21
21
|
super()
|