ziko 2.0.0-alpha.0 → 2.0.0-beta.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 +329 -1758
- package/dist/ziko.js +1 -1
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +1 -1
- package/package.json +5 -13
- package/src/app/Layout/index.d.ts +38 -0
- package/src/app/Layout/index.js +98 -0
- package/src/app/index.d.ts +1 -0
- package/src/app/index.js +1 -0
- package/src/dom/internal-utils/checkers.js +1 -1
- package/src/index.d.ts +0 -1
- package/src/index.js +5 -5
- package/src/internal-utils/symbols/index.d.ts +4 -1
- package/src/internal-utils/symbols/index.js +2 -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 : Sat Sep 05 2026 12:37:55 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
|
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
const { PI, E } = Math;
|
|
14
14
|
const EPSILON=Number.EPSILON;
|
|
15
15
|
|
|
16
|
-
const is_primitive
|
|
16
|
+
const is_primitive = value => typeof value !== 'object' && typeof value !== 'function' || value === null;
|
|
17
17
|
|
|
18
18
|
const mapfun=(fun,...X)=>{
|
|
19
19
|
const Y=X.map(x=>{
|
|
20
|
-
if(is_primitive
|
|
20
|
+
if(is_primitive(x) || x?.__mapfun__) return fun(x)
|
|
21
21
|
if(x instanceof Array) return x.map(n=>mapfun(fun,n));
|
|
22
22
|
if(ArrayBuffer.isView(x)) return x.map(n=>fun(n));
|
|
23
23
|
if(x instanceof Set) return new Set(mapfun(fun,...[...x]));
|
|
@@ -48,1117 +48,141 @@ const apply_fun = (x, fn) => {
|
|
|
48
48
|
return fn(x)
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
const dec = parseInt(value, fromBase);
|
|
54
|
-
if (Number.isNaN(dec)) throw new TypeError('Invalid value for the given base');
|
|
55
|
-
|
|
56
|
-
return dec.toString(toBase);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const percentile = (X, p) => {
|
|
60
|
-
if (X.length === 0)
|
|
61
|
-
return NaN;
|
|
62
|
-
let a = X.sort((x, y) => x - y);
|
|
63
|
-
let index = (p / 100) * (a.length - 1);
|
|
64
|
-
let i = Math.floor(index);
|
|
65
|
-
let f = index - i;
|
|
66
|
-
if (i === a.length - 1)
|
|
67
|
-
return a[i];
|
|
68
|
-
return a[i] * (1 - f) + a[i + 1] * f;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const q1 = X => percentile(X, 25);
|
|
72
|
-
const median = X => percentile(X, 50);
|
|
73
|
-
const q3 = X => percentile(X, 75);
|
|
74
|
-
|
|
75
|
-
// Interquartile Range
|
|
76
|
-
const iqr = X => q3(X) - q1(X);
|
|
77
|
-
|
|
78
|
-
// Mean
|
|
79
|
-
const mean = (...x) => x.reduce((a, b) => a + b) / x.length;
|
|
80
|
-
const geo_mean = (...x) => (x.reduce((a, b) => a * b)) ** (1/x.length);
|
|
81
|
-
// Quadratic Mean
|
|
82
|
-
const rms = (...x) => {
|
|
83
|
-
const n = x.length;
|
|
84
|
-
return (Math.hypot(...x)/n)**(1/n)
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const weighted_mean=(values, weights)=>{
|
|
88
|
-
let sum = 0, sw = 0;
|
|
89
|
-
for (let i = 0; i < values.length; i++) {
|
|
90
|
-
sum += values[i] * weights[i];
|
|
91
|
-
sw += weights[i];
|
|
92
|
-
}
|
|
93
|
-
return sum / sw;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const harmonic_mean = (...x) => {
|
|
97
|
-
let s = 0, i = 0;
|
|
98
|
-
for(i=0; i<x.length; i++)
|
|
99
|
-
s += 1/x[i];
|
|
100
|
-
return x.length / s;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const power_mean = (X, p) =>{
|
|
104
|
-
let s = 0, i = 0, l = X.length;
|
|
105
|
-
for(i=0; i < l; i++)
|
|
106
|
-
s+= X[i]**p;
|
|
107
|
-
return (s / l) ** (1 / p);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const trimmed_mean = (X, k) =>{
|
|
111
|
-
let a = [...X].sort((a,b)=>a-b).slice(k, X.length - k);
|
|
112
|
-
return mean(...a);
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const winsorized_mean = (X, k) =>{
|
|
116
|
-
let a = [...X].sort((a,b)=>a-b);
|
|
117
|
-
let low = a[k], high = a[a.length - k - 1];
|
|
118
|
-
a = a.map(x => Math.max(low, Math.min(high, x)));
|
|
119
|
-
return mean(a);
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const midrange = (x) =>{
|
|
123
|
-
let min = Math.min(...x);
|
|
124
|
-
let max = Math.max(...x);
|
|
125
|
-
return (min + max) / 2;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
const midhinge = (...x) =>{
|
|
129
|
-
let a = x.sort((a,b)=>a-b);
|
|
130
|
-
let q1 = a[Math.floor((a.length - 1) * 0.25)];
|
|
131
|
-
let q3 = a[Math.floor((a.length - 1) * 0.75)];
|
|
132
|
-
return (q1 + q3) / 2;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const interquartile_mean = (...x) =>{
|
|
137
|
-
let a = x.sort((a,b)=>a-b);
|
|
138
|
-
let q1 = a[Math.floor((a.length - 1) * 0.25)];
|
|
139
|
-
let q3 = a[Math.floor((a.length - 1) * 0.75)];
|
|
140
|
-
let m = a.filter(x => x >= q1 && x <= q3);
|
|
141
|
-
return mean(m);
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const contraharmonic_mean = (...x) =>{
|
|
146
|
-
let num = 0, den = 0, i, l = x.length;
|
|
147
|
-
for(i = 0; i < l; i++){
|
|
148
|
-
num += x[i]**2;
|
|
149
|
-
den += x[i];
|
|
150
|
-
}
|
|
151
|
-
return num / den;
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
// Population Variance
|
|
155
|
-
const variance = (...x) => {
|
|
156
|
-
const n = x.length;
|
|
157
|
-
if (n === 0) return NaN;
|
|
158
|
-
const x_mean = mean(...x);
|
|
159
|
-
return x.reduce((sum, xi) => sum + (xi - x_mean) ** 2, 0) / n;
|
|
160
|
-
};
|
|
161
|
-
const std = (...x) => Math.sqrt(variance(...x));
|
|
51
|
+
const deg2rad = (...deg) => mapfun(x => x * Math.PI / 180, ...deg);
|
|
52
|
+
const rad2deg = (...rad) => mapfun(x => x / Math.PI * 180, ...rad);
|
|
162
53
|
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
54
|
+
const norm = (x, min, max) => apply_fun(
|
|
55
|
+
x,
|
|
56
|
+
v => min !== max ? (v - min) / (max - min) : 0
|
|
57
|
+
);
|
|
58
|
+
const lerp = (x, min, max) => apply_fun(
|
|
59
|
+
x,
|
|
60
|
+
v => (max - min) * v + min
|
|
61
|
+
);
|
|
62
|
+
const clamp = (x, min, max) => apply_fun(
|
|
63
|
+
x,
|
|
64
|
+
v => Math.min(Math.max(v, min), max)
|
|
65
|
+
);
|
|
66
|
+
const map$1 = (x, a, b, c, d) => apply_fun(
|
|
67
|
+
x,
|
|
68
|
+
v => lerp(norm(v, a, b), c, d)
|
|
69
|
+
);
|
|
179
70
|
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
result.push(sample_variance(w)); // usually sample variance for rolling
|
|
71
|
+
const hypot = (...x) => {
|
|
72
|
+
const c0 = x.find(a => a.isComplex?.());
|
|
73
|
+
if (c0) {
|
|
74
|
+
const W = x.map(n => n.isComplex?.() ? n : new c0.constructor(n, 0));
|
|
75
|
+
return Math.hypot(...W.map(c => c.z));
|
|
186
76
|
}
|
|
187
|
-
return
|
|
188
|
-
};
|
|
189
|
-
const rolling_std = (X, windowSize) => Math.sqrt(rolling_variance(X, windowSize));
|
|
190
|
-
|
|
191
|
-
// Simple Moving Average
|
|
192
|
-
const sma = (X, w) =>{
|
|
193
|
-
let r = [];
|
|
194
|
-
for (let i = 0; i <= X.length - w; i++) {
|
|
195
|
-
let s = 0;
|
|
196
|
-
for (let j = 0; j < w; j++) s += X[i + j];
|
|
197
|
-
r.push(s / w);
|
|
198
|
-
}
|
|
199
|
-
return r;
|
|
77
|
+
return Math.hypot(...x);
|
|
200
78
|
};
|
|
201
79
|
|
|
202
|
-
// exponential Moving Average
|
|
203
|
-
const ema = (X, alpha) =>{
|
|
204
|
-
let r = [], prev = X[0];
|
|
205
|
-
r.push(prev);
|
|
206
|
-
for (let i = 1; i < X.length; i++) {
|
|
207
|
-
prev = alpha * X[i] + (1 - alpha) * prev;
|
|
208
|
-
r.push(prev);
|
|
209
|
-
}
|
|
210
|
-
return r;
|
|
211
|
-
};
|
|
212
80
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
let sw = weights.reduce((a,b)=>a+b, 0);
|
|
217
|
-
let r = [];
|
|
218
|
-
for (let i = 0; i <= X.length - k; i++) {
|
|
219
|
-
let s = 0;
|
|
220
|
-
for (let j = 0; j < k; j++) s += X[i+j] * weights[j];
|
|
221
|
-
r.push(s / sw);
|
|
222
|
-
}
|
|
223
|
-
return r;
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
const accum_sum = (arr) => {
|
|
227
|
-
let result = [];
|
|
228
|
-
let total = 0;
|
|
229
|
-
for (let x of arr) {
|
|
230
|
-
total += x;
|
|
231
|
-
result.push(total);
|
|
232
|
-
}
|
|
233
|
-
return result;
|
|
234
|
-
};
|
|
81
|
+
const atan2 = (y, x, rad = true) => {
|
|
82
|
+
if (y instanceof Array && !(x instanceof Array))
|
|
83
|
+
return mapfun(n => atan2(n, x, rad), ...y);
|
|
235
84
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
let prod = 1;
|
|
239
|
-
for (let x of arr) {
|
|
240
|
-
prod *= x;
|
|
241
|
-
result.push(prod);
|
|
242
|
-
}
|
|
243
|
-
return result;
|
|
244
|
-
};
|
|
85
|
+
if (x instanceof Array && !(y instanceof Array))
|
|
86
|
+
return mapfun(n => atan2(y, n, rad), ...x);
|
|
245
87
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
let m = -Infinity;
|
|
249
|
-
for (let x of arr) {
|
|
250
|
-
m = Math.max(m, x);
|
|
251
|
-
result.push(m);
|
|
252
|
-
}
|
|
253
|
-
return result;
|
|
254
|
-
};
|
|
88
|
+
if (y instanceof Array && x instanceof Array)
|
|
89
|
+
return y.map((v, i) => atan2(v, x[i], rad));
|
|
255
90
|
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
let m = Infinity;
|
|
259
|
-
for (let x of arr) {
|
|
260
|
-
m = Math.min(m, x);
|
|
261
|
-
result.push(m);
|
|
262
|
-
}
|
|
263
|
-
return result;
|
|
91
|
+
const phi = Math.atan2(y, x);
|
|
92
|
+
return rad ? phi : phi * 180 / Math.PI;
|
|
264
93
|
};
|
|
265
94
|
|
|
266
|
-
class
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
static float(a, b){
|
|
271
|
-
return b !== undefined
|
|
272
|
-
? Math.random() * (b - a) + a
|
|
273
|
-
: Math.random() * a;
|
|
274
|
-
}
|
|
275
|
-
static bin(){
|
|
276
|
-
return this.int(2);
|
|
277
|
-
}
|
|
278
|
-
static oct(){
|
|
279
|
-
return this.int(8);
|
|
280
|
-
}
|
|
281
|
-
static dec(){
|
|
282
|
-
return this.int(10);
|
|
283
|
-
}
|
|
284
|
-
static hex(){
|
|
285
|
-
return base2base(this.int(16), 10, 16);
|
|
286
|
-
}
|
|
287
|
-
static char(upperCase = false){
|
|
288
|
-
const i = upperCase
|
|
289
|
-
? this.int(65, 91)
|
|
290
|
-
: this.int(97, 123);
|
|
291
|
-
return String.fromCharCode(i);
|
|
292
|
-
}
|
|
293
|
-
static bool(){
|
|
294
|
-
return Boolean(this.int(2));
|
|
295
|
-
}
|
|
296
|
-
static get color(){
|
|
297
|
-
return {
|
|
298
|
-
hex : () =>
|
|
299
|
-
`#${this.int(0xffffff).toString(16).padStart(6, '0')}`,
|
|
300
|
-
|
|
301
|
-
hexa : () => {
|
|
302
|
-
const [r,g,b,a] = Array.from(
|
|
303
|
-
{length:4},
|
|
304
|
-
() => this.int(0xff).toString(16).padStart(2,'0')
|
|
305
|
-
);
|
|
306
|
-
return `#${r}${g}${b}${a}`;
|
|
307
|
-
},
|
|
308
|
-
rgb : () => {
|
|
309
|
-
const [r,g,b] = Array.from({length:3}, () => this.int(0xff));
|
|
310
|
-
return `rgb(${r}, ${g}, ${b})`;
|
|
311
|
-
},
|
|
312
|
-
rgba : () => {
|
|
313
|
-
const [r,g,b] = Array.from({length:3}, () => this.int(0xff));
|
|
314
|
-
const a = Math.random().toFixed(2);
|
|
315
|
-
return `rgba(${r}, ${g}, ${b}, ${a})`;
|
|
316
|
-
},
|
|
317
|
-
hsl : () => {
|
|
318
|
-
const h = this.int(360);
|
|
319
|
-
const s = this.int(100);
|
|
320
|
-
const l = this.int(100);
|
|
321
|
-
return `hsl(${h}, ${s}%, ${l}%)`;
|
|
322
|
-
},
|
|
323
|
-
hsla : () => {
|
|
324
|
-
const h = this.int(360);
|
|
325
|
-
const s = this.int(100);
|
|
326
|
-
const l = this.int(100);
|
|
327
|
-
const a = Math.random().toFixed(2);
|
|
328
|
-
return `hsla(${h}, ${s}%, ${l}%, ${a})`;
|
|
329
|
-
},
|
|
330
|
-
gray : () => {
|
|
331
|
-
const g = this.int(0xff);
|
|
332
|
-
return `rgb(${g}, ${g}, ${g})`;
|
|
333
|
-
}
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
static get sample(){
|
|
337
|
-
const R = this;
|
|
338
|
-
return {
|
|
339
|
-
int : (n, a, b) => Array.from({length:n}, () => R.int(a, b)),
|
|
340
|
-
float : (n, a, b) => Array.from({length:n}, () => R.float(a, b)),
|
|
341
|
-
char : (n, upper=false) => Array.from({length:n}, () => R.char(upper)),
|
|
342
|
-
bool : n => Array.from({length:n}, () => R.bool()),
|
|
343
|
-
bin : n => Array.from({length:n}, () => R.bin()),
|
|
344
|
-
oct : n => Array.from({length:n}, () => R.oct()),
|
|
345
|
-
dec : n => Array.from({length:n}, () => R.dec()),
|
|
346
|
-
hex : n => Array.from({length:n}, () => R.hex()),
|
|
347
|
-
get color(){
|
|
348
|
-
return {
|
|
349
|
-
hex : n => Array.from({length:n}, () => R.color.hex()),
|
|
350
|
-
hexa : n => Array.from({length:n}, () => R.color.hexa()),
|
|
351
|
-
rgb : n => Array.from({length:n}, () => R.color.rgb()),
|
|
352
|
-
rgba : n => Array.from({length:n}, () => R.color.rgba()),
|
|
353
|
-
hsl : n => Array.from({length:n}, () => R.color.hsl()),
|
|
354
|
-
hsla : n => Array.from({length:n}, () => R.color.hsla()),
|
|
355
|
-
gray : n => Array.from({length:n}, () => R.color.gray())
|
|
356
|
-
};
|
|
357
|
-
},
|
|
358
|
-
choice : (n, choices, p) =>
|
|
359
|
-
Array.from({length:n}, () => R.choice(choices, p))
|
|
95
|
+
class UINode {
|
|
96
|
+
constructor(node){
|
|
97
|
+
this.cache = {
|
|
98
|
+
node
|
|
360
99
|
};
|
|
361
100
|
}
|
|
362
|
-
|
|
363
|
-
return [...arr].sort(() => 0.5 - Math.random());
|
|
364
|
-
}
|
|
365
|
-
static choice(choices = [1,2,3], p = new Array(choices.length).fill(1 / choices.length)){
|
|
366
|
-
const acc = accum_sum(...p).map(v => v * 100);
|
|
367
|
-
const pool = new Array(100);
|
|
368
|
-
pool.fill(choices[0], 0, acc[0]);
|
|
369
|
-
for(let i=1;i<choices.length;i++)
|
|
370
|
-
pool.fill(choices[i], acc[i-1], acc[i]);
|
|
371
|
-
return pool[this.int(pool.length)];
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
const complex_constructor = (Complex, a, b) => {
|
|
376
|
-
let _a, _b;
|
|
377
|
-
if (a instanceof Complex) {
|
|
378
|
-
_a = a.a;
|
|
379
|
-
_b = a.b;
|
|
380
|
-
}
|
|
381
|
-
else if (typeof a === "object") {
|
|
382
|
-
if ("a" in a && "b" in a) {
|
|
383
|
-
_a = a.a;
|
|
384
|
-
_b = a.b;
|
|
385
|
-
}
|
|
386
|
-
else if ("a" in a && "z" in a) {
|
|
387
|
-
_a = a.a;
|
|
388
|
-
_b = Math.sqrt(a.z ** 2 - a.a ** 2);
|
|
389
|
-
}
|
|
390
|
-
else if ("a" in a && "phi" in a) {
|
|
391
|
-
_a = a.a;
|
|
392
|
-
_b = a.a * Math.tan(a.phi);
|
|
393
|
-
}
|
|
394
|
-
else if ("b" in a && "z" in a) {
|
|
395
|
-
_b = a.b;
|
|
396
|
-
_a = Math.sqrt(a.z ** 2 - a.b ** 2);
|
|
397
|
-
}
|
|
398
|
-
else if ("b" in a && "phi" in a) {
|
|
399
|
-
_b = b;
|
|
400
|
-
_a = a.b / Math.tan(a.phi);
|
|
401
|
-
}
|
|
402
|
-
else if ("z" in a && "phi" in a) {
|
|
403
|
-
_a = +a.z * Math.cos(a.phi).toFixed(15);
|
|
404
|
-
_b = +a.z * Math.sin(a.phi).toFixed(15);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
else if (typeof a === "number" && typeof b === "number") {
|
|
408
|
-
_a = +a.toFixed(32);
|
|
409
|
-
_b = +b.toFixed(32);
|
|
410
|
-
}
|
|
411
|
-
return [_a, _b]
|
|
412
|
-
};
|
|
413
|
-
|
|
414
|
-
class Complex{
|
|
415
|
-
constructor(a = 0, b = 0) {
|
|
416
|
-
[
|
|
417
|
-
this.a,
|
|
418
|
-
this.b
|
|
419
|
-
] = complex_constructor(Complex, a, b);
|
|
420
|
-
}
|
|
421
|
-
get __mapfun__(){
|
|
422
|
-
return true
|
|
423
|
-
}
|
|
424
|
-
isComplex(){
|
|
101
|
+
isUINode(){
|
|
425
102
|
return true
|
|
426
103
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
if (this.a !== 0)
|
|
430
|
-
this.b >= 0
|
|
431
|
-
? (str = `${this.a}+${this.b}*i`)
|
|
432
|
-
: (str = `${this.a}-${Math.abs(this.b)}*i`);
|
|
433
|
-
else
|
|
434
|
-
this.b >= 0
|
|
435
|
-
? (str = `${this.b}*i`)
|
|
436
|
-
: (str = `-${Math.abs(this.b)}*i`);
|
|
437
|
-
return str;
|
|
438
|
-
}
|
|
439
|
-
serialize() {
|
|
440
|
-
return JSON.stringify({
|
|
441
|
-
type : 'complex',
|
|
442
|
-
data : this
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
static deserialize(json){
|
|
446
|
-
if(typeof json === 'string') json = JSON.parse(json);
|
|
447
|
-
let {data, type} = json;
|
|
448
|
-
return (type === 'complex' && ('a' in data) && ('b' in data))
|
|
449
|
-
? new Complex(data.a, data.b)
|
|
450
|
-
: TypeError('Not a valid complex')
|
|
104
|
+
get node(){
|
|
105
|
+
return this.cache.node;
|
|
451
106
|
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
static get random(){
|
|
482
|
-
return {
|
|
483
|
-
int : (a, b)=> new Complex(...Random.sample.int(2, a, b) ),
|
|
484
|
-
float : (a, b)=> new Complex(...Random.sample.float(2, a, b) ),
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
static twiddle(K, N){
|
|
488
|
-
const phi = -2 * Math.PI * K / N;
|
|
489
|
-
return new Complex(
|
|
490
|
-
Math.cos(phi),
|
|
491
|
-
Math.sin(phi)
|
|
492
|
-
);
|
|
493
|
-
}
|
|
494
|
-
get conj() {
|
|
495
|
-
return new Complex(this.a, -this.b);
|
|
496
|
-
}
|
|
497
|
-
get inv() {
|
|
498
|
-
return new Complex(
|
|
499
|
-
this.a / Math.hypot(this.a, this.b),
|
|
500
|
-
-this.b / Math.hypot(this.a, this.b)
|
|
501
|
-
);
|
|
502
|
-
}
|
|
503
|
-
add(...c) {
|
|
504
|
-
for (let i = 0; i < c.length; i++) {
|
|
505
|
-
if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
|
|
506
|
-
this.a += c[i].a;
|
|
507
|
-
this.b += c[i].b;
|
|
508
|
-
}
|
|
509
|
-
return this;
|
|
510
|
-
}
|
|
511
|
-
sub(...c) {
|
|
512
|
-
for (let i = 0; i < c.length; i++) {
|
|
513
|
-
if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
|
|
514
|
-
this.a -= c[i].a;
|
|
515
|
-
this.b -= c[i].b;
|
|
516
|
-
}
|
|
517
|
-
return this;
|
|
518
|
-
}
|
|
519
|
-
mul(...c){
|
|
520
|
-
let {z, phi} = this;
|
|
521
|
-
for (let i = 0; i < c.length; i++) {
|
|
522
|
-
if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
|
|
523
|
-
z *= c[i].z;
|
|
524
|
-
phi += c[i].phi;
|
|
525
|
-
}
|
|
526
|
-
this.a = z * Math.cos(phi);
|
|
527
|
-
this.b = z * Math.sin(phi);
|
|
528
|
-
return this.toFixed(8);
|
|
529
|
-
}
|
|
530
|
-
div(...c){
|
|
531
|
-
let {z, phi} = this;
|
|
532
|
-
for (let i = 0; i < c.length; i++) {
|
|
533
|
-
if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
|
|
534
|
-
z /= c[i].z;
|
|
535
|
-
phi -= c[i].phi;
|
|
536
|
-
}
|
|
537
|
-
this.a = z * Math.cos(phi);
|
|
538
|
-
this.b = z * Math.sin(phi);
|
|
539
|
-
return this.toFixed(8); }
|
|
540
|
-
modulo(...c) {
|
|
541
|
-
for (let i = 0; i < c.length; i++) {
|
|
542
|
-
if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
|
|
543
|
-
this.a %= c[i].a;
|
|
544
|
-
this.b %= c[i].b;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function parseQueryParams(queryString) {
|
|
110
|
+
const params = {};
|
|
111
|
+
queryString.replace(/[A-Z0-9]+?=([\w|:|\/\.]*)/gi, (match) => {
|
|
112
|
+
const [key, value] = match.split('=');
|
|
113
|
+
params[key] = value;
|
|
114
|
+
});
|
|
115
|
+
return params;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function defineParamsGetter(target ){
|
|
119
|
+
Object.defineProperties(target, {
|
|
120
|
+
'QueryParams': {
|
|
121
|
+
get: function() {
|
|
122
|
+
return parseQueryParams(globalThis.location.search.substring(1));
|
|
123
|
+
},
|
|
124
|
+
configurable: false,
|
|
125
|
+
enumerable: true
|
|
126
|
+
},
|
|
127
|
+
'HashParams': {
|
|
128
|
+
get: function() {
|
|
129
|
+
const hash = globalThis.location.hash.substring(1);
|
|
130
|
+
return hash.split("#");
|
|
131
|
+
},
|
|
132
|
+
configurable: false,
|
|
133
|
+
enumerable: true
|
|
545
134
|
}
|
|
546
|
-
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
class UIStore extends Array {
|
|
139
|
+
constructor(...args) {
|
|
140
|
+
super(...args);
|
|
547
141
|
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
for (let i = 0; i < c.length; i++) {
|
|
551
|
-
if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
|
|
552
|
-
z *= Math.exp(c[i].a * Math.log(z) - c[i].b * phi);
|
|
553
|
-
phi += c[i].b * Math.log(z) + c[i].a * phi;
|
|
554
|
-
}
|
|
555
|
-
this.a = z * Math.cos(phi);
|
|
556
|
-
this.b = z * Math.sin(phi);
|
|
142
|
+
clear(){
|
|
143
|
+
this.length = 0;
|
|
557
144
|
return this;
|
|
558
145
|
}
|
|
559
|
-
|
|
560
|
-
return
|
|
561
|
-
}
|
|
562
|
-
nthr(n=2){
|
|
563
|
-
return complex({z: this.z ** (1/n), phi: this.phi / n});
|
|
564
|
-
}
|
|
565
|
-
get sqrt(){
|
|
566
|
-
return this.nthr(2);
|
|
567
|
-
}
|
|
568
|
-
get cbrt(){
|
|
569
|
-
return this.nthr(3);
|
|
146
|
+
getItemById(id) {
|
|
147
|
+
return this.find(n => n.element.id === id);
|
|
570
148
|
}
|
|
571
|
-
|
|
572
|
-
return
|
|
149
|
+
getItemsByTagName(tag) {
|
|
150
|
+
return this.filter(n => n.element.tagName.toLowerCase() === tag.toLowerCase());
|
|
573
151
|
}
|
|
574
|
-
|
|
575
|
-
return
|
|
576
|
-
Math.cos(this.a) * Math.cosh(this.b),
|
|
577
|
-
Math.sin(this.a) * Math.sinh(this.b)
|
|
578
|
-
)
|
|
152
|
+
getElementsByClassName(className) {
|
|
153
|
+
return this.filter(n => n.element.classList?.contains(className));
|
|
579
154
|
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
)
|
|
155
|
+
querySelector(selector) {
|
|
156
|
+
const el = globalThis?.document?.querySelector(selector);
|
|
157
|
+
if (!el) return null;
|
|
158
|
+
return this.find(ui => ui.element === el) || null;
|
|
585
159
|
}
|
|
586
|
-
|
|
587
|
-
const
|
|
588
|
-
return
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
);
|
|
160
|
+
querySelectorAll(selector) {
|
|
161
|
+
const els = globalThis?.document?.querySelectorAll(selector);
|
|
162
|
+
return Array.from(els)
|
|
163
|
+
.map(el => this.find(ui => ui.element === el))
|
|
164
|
+
.filter(Boolean);
|
|
592
165
|
}
|
|
593
166
|
}
|
|
594
|
-
const complex=(a,b)=>{
|
|
595
|
-
if((a instanceof Array||ArrayBuffer.isView(a)) && (b instanceof Array||ArrayBuffer.isView(a)))return a.map((n,i)=>complex(a[i],b[i]));
|
|
596
|
-
if(a.isMatrix?.() && b.isMatrix?.()){
|
|
597
|
-
if((a.shape[0]!==b.shape[0])||(a.shape[1]!==b.shape[1]))return Error(0)
|
|
598
|
-
const arr=a.arr.map((n,i)=>complex(a.arr[i],b.arr[i]));
|
|
599
|
-
return new a.constructor(a.rows,a.cols,...arr)
|
|
600
|
-
}
|
|
601
|
-
return new Complex(a,b)
|
|
602
|
-
};
|
|
603
|
-
|
|
604
|
-
const PRECESION = 8;
|
|
605
167
|
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
168
|
+
// create the singleton
|
|
169
|
+
const __UI__ = new UIStore();
|
|
170
|
+
|
|
171
|
+
const __Config__ = {
|
|
172
|
+
default:{
|
|
173
|
+
target:null,
|
|
174
|
+
render:true,
|
|
175
|
+
// math:{
|
|
176
|
+
// mode:"deg"
|
|
177
|
+
// }
|
|
610
178
|
},
|
|
611
|
-
|
|
612
|
-
);
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
const n = x.pop();
|
|
616
|
-
return mapfun(
|
|
617
|
-
x => {
|
|
618
|
-
if(x.isComplex?.()) {
|
|
619
|
-
if(n.isComplex?.()) return new x.constructor({
|
|
620
|
-
z: Math.exp(n.a * Math.log(x.z) - n.b * x.phi),
|
|
621
|
-
phi: n.b * Math.log(x.z) + n.a * x.phi
|
|
622
|
-
})
|
|
623
|
-
return new x.constructor({z: x.z ** n, phi: x.phi * n});
|
|
624
|
-
}
|
|
625
|
-
if(n.isComplex?.()) return new x.constructor({
|
|
626
|
-
z: Math.exp(n.a * Math.log(x)),
|
|
627
|
-
phi: n.b * Math.log(x)
|
|
628
|
-
})
|
|
629
|
-
return Math.pow(x, n)
|
|
630
|
-
},
|
|
631
|
-
...x
|
|
632
|
-
)
|
|
633
|
-
};
|
|
634
|
-
|
|
635
|
-
const sqrt = (...x) => mapfun(
|
|
636
|
-
x=>{
|
|
637
|
-
if(x.isComplex?.())
|
|
638
|
-
return new x.constructor({z: x.z**(1/2), phi: x.phi/2});
|
|
639
|
-
if(x < 0) return complex(0, Math.sqrt(-x)).toFixed(PRECESION)
|
|
640
|
-
return + Math.sqrt(x).toFixed(PRECESION);
|
|
179
|
+
setDefault:function(pairs){
|
|
180
|
+
const keys=Object.keys(pairs);
|
|
181
|
+
const values=Object.values(pairs);
|
|
182
|
+
for(let i=0; i<keys.length; i++) this.default[keys[i]]=values[i];
|
|
641
183
|
},
|
|
642
|
-
|
|
643
|
-
)
|
|
644
|
-
|
|
645
|
-
const cbrt = (...x) => mapfun(
|
|
646
|
-
x=>{
|
|
647
|
-
if(x.isComplex?.())
|
|
648
|
-
return new x.constructor({z: x.z**(1/3), phi: x.phi/3}).toFixed(PRECESION)
|
|
649
|
-
return + Math.cbrt(x).toFixed(PRECESION);
|
|
650
|
-
},
|
|
651
|
-
...x
|
|
652
|
-
);
|
|
653
|
-
|
|
654
|
-
const nthr = (...x) => {
|
|
655
|
-
const n = x.pop();
|
|
656
|
-
if(typeof n !== 'number') throw Error('nthr expects a real number n');
|
|
657
|
-
return mapfun(
|
|
658
|
-
x => {
|
|
659
|
-
if(x.isComplex?.()) return new x.constructor({z: x.z ** (1/n), phi: x.phi / n});
|
|
660
|
-
if(x<0) return n %2 ===2
|
|
661
|
-
? complex(0, (-x)**(1/n)).toFixed(PRECESION)
|
|
662
|
-
: + (-1 * (-x)**(1/n)).toFixed(PRECESION)
|
|
663
|
-
return + (x**(1/n)).toFixed(PRECESION)
|
|
664
|
-
},
|
|
665
|
-
...x
|
|
666
|
-
)
|
|
667
|
-
};
|
|
668
|
-
|
|
669
|
-
const croot = (...x) =>{
|
|
670
|
-
const c = x.pop();
|
|
671
|
-
if(!c.isComplex?.()) throw Error('croot expect Complex number as root')
|
|
672
|
-
return mapfun(
|
|
673
|
-
x => {
|
|
674
|
-
if(typeof x === 'number') x = new c.constructor(x, 0);
|
|
675
|
-
const {a : c_a, b : c_b} = c;
|
|
676
|
-
const {z, phi} = x;
|
|
677
|
-
const D = Math.hypot(c_a, c_b);
|
|
678
|
-
const A = Math.exp((Math.log(z)*c_a + phi*c_b)/D);
|
|
679
|
-
const B = (phi*c_a - Math.log(z)*c_b)/D;
|
|
680
|
-
return new c.constructor(
|
|
681
|
-
A * Math.cos(B),
|
|
682
|
-
A * Math.sin(B)
|
|
683
|
-
).toFixed(PRECESION)
|
|
684
|
-
},
|
|
685
|
-
...x
|
|
686
|
-
)
|
|
687
|
-
};
|
|
688
|
-
|
|
689
|
-
const exp = (...x) => mapfun(
|
|
690
|
-
x => {
|
|
691
|
-
if(x.isComplex?.()) return new x.constructor(
|
|
692
|
-
Math.exp(x.a) * Math.cos(x.b),
|
|
693
|
-
Math.exp(x.a) * Math.sin(x.b)
|
|
694
|
-
).toFixed(PRECESION);
|
|
695
|
-
return + Math.exp(x).toFixed(PRECESION)
|
|
696
|
-
}
|
|
697
|
-
,...x
|
|
698
|
-
);
|
|
699
|
-
|
|
700
|
-
const ln = (...x) => mapfun(
|
|
701
|
-
x => {
|
|
702
|
-
if(x.isComplex?.()) return new x.constructor(
|
|
703
|
-
Math.log(x.z),
|
|
704
|
-
x.phi
|
|
705
|
-
).toFixed(PRECESION);
|
|
706
|
-
return + Math.log(x).toFixed(PRECESION)
|
|
707
|
-
}
|
|
708
|
-
,...x
|
|
709
|
-
);
|
|
710
|
-
|
|
711
|
-
const sign = (...x) => mapfun(
|
|
712
|
-
x => {
|
|
713
|
-
if(x.isComplex?.()){
|
|
714
|
-
const {z, phi} = x;
|
|
715
|
-
if(z===0) return new x.constructor(0, 0);
|
|
716
|
-
return new x.constructor({z:1, phi})
|
|
717
|
-
}
|
|
718
|
-
return Math.sign(x)
|
|
719
|
-
}
|
|
720
|
-
,...x
|
|
721
|
-
);
|
|
722
|
-
|
|
723
|
-
const floor = (...x) => mapfun(
|
|
724
|
-
x => {
|
|
725
|
-
if(x.isComplex?.()) return new x.constructor(
|
|
726
|
-
Math.floor(x.a),
|
|
727
|
-
Math.floor(x.b)
|
|
728
|
-
)
|
|
729
|
-
return Math.floor(x)
|
|
730
|
-
},
|
|
731
|
-
...x
|
|
732
|
-
);
|
|
733
|
-
const ceil = (...x) => mapfun(
|
|
734
|
-
x => {
|
|
735
|
-
if(x.isComplex?.()) return new x.constructor(
|
|
736
|
-
Math.ceil(x.a),
|
|
737
|
-
Math.ceil(x.b)
|
|
738
|
-
)
|
|
739
|
-
return Math.ceil(x)
|
|
740
|
-
},
|
|
741
|
-
...x
|
|
742
|
-
);
|
|
743
|
-
const round = (...x) => mapfun(
|
|
744
|
-
x => {
|
|
745
|
-
if(x.isComplex?.()) return new x.constructor(
|
|
746
|
-
Math.round(x.a),
|
|
747
|
-
Math.round(x.b)
|
|
748
|
-
)
|
|
749
|
-
return Math.round(x)
|
|
750
|
-
},
|
|
751
|
-
...x
|
|
752
|
-
);
|
|
753
|
-
|
|
754
|
-
const trunc = (...x) => mapfun(
|
|
755
|
-
x => {
|
|
756
|
-
if(x.isComplex?.()) return new x.constructor(
|
|
757
|
-
Math.trunc(x.a),
|
|
758
|
-
Math.trunc(x.b)
|
|
759
|
-
)
|
|
760
|
-
return Math.trunc(x)
|
|
761
|
-
},
|
|
762
|
-
...x
|
|
763
|
-
);
|
|
764
|
-
|
|
765
|
-
const fract = (...x) => mapfun(
|
|
766
|
-
x => {
|
|
767
|
-
if(x.isComplex?.()) return new x.constructor(
|
|
768
|
-
x.a - Math.trunc(x.a),
|
|
769
|
-
x.b - Math.trunc(x.b)
|
|
770
|
-
)
|
|
771
|
-
return x - Math.trunc(x)
|
|
772
|
-
},
|
|
773
|
-
...x
|
|
774
|
-
);
|
|
775
|
-
|
|
776
|
-
const cos$1 = (...x) => mapfun(
|
|
777
|
-
x => {
|
|
778
|
-
if(x.isComplex?.()) return new x.constructor(
|
|
779
|
-
Math.cos(x.a) * Math.cosh(x.b),
|
|
780
|
-
-Math.sin(x.a) * Math.sinh(x.b)
|
|
781
|
-
).toFixed(PRECESION);
|
|
782
|
-
return + Math.cos(x).toFixed(PRECESION)
|
|
783
|
-
}
|
|
784
|
-
,...x
|
|
785
|
-
);
|
|
786
|
-
|
|
787
|
-
const sin$1 = (...x) => mapfun(
|
|
788
|
-
x =>{
|
|
789
|
-
if(x?.isComplex) return new x.constructor(
|
|
790
|
-
Math.sin(x.a) * Math.cosh(x.b),
|
|
791
|
-
Math.cos(x.a) * Math.sinh(x.b)
|
|
792
|
-
).toFixed(PRECESION);
|
|
793
|
-
return + Math.sin(x).toFixed(PRECESION)
|
|
794
|
-
}
|
|
795
|
-
, ...x
|
|
796
|
-
);
|
|
797
|
-
|
|
798
|
-
const tan = (...x) => mapfun(
|
|
799
|
-
x =>{
|
|
800
|
-
if(x?.isComplex){
|
|
801
|
-
const D = Math.cos(2*x.a) + Math.cosh(2*x.b);
|
|
802
|
-
return new x.constructor(
|
|
803
|
-
Math.sin(2*x.a) / D,
|
|
804
|
-
Math.sinh(2*x.b) / D
|
|
805
|
-
).toFixed(PRECESION);
|
|
806
|
-
}
|
|
807
|
-
return + Math.tan(x).toFixed(PRECESION)
|
|
808
|
-
},
|
|
809
|
-
...x
|
|
810
|
-
);
|
|
811
|
-
|
|
812
|
-
const sec = (...x) => mapfun(
|
|
813
|
-
x => {
|
|
814
|
-
if(x.isComplex?.()) ;
|
|
815
|
-
return + (1 / Math.cos(x)).toFixed(PRECESION)
|
|
816
|
-
}
|
|
817
|
-
,...x
|
|
818
|
-
);
|
|
819
|
-
|
|
820
|
-
const acos = (...x) => mapfun(
|
|
821
|
-
x =>{
|
|
822
|
-
if(x?.isComplex){
|
|
823
|
-
const { a, b } = x;
|
|
824
|
-
const Rp = Math.hypot(a + 1, b);
|
|
825
|
-
const Rm = Math.hypot(a - 1, b);
|
|
826
|
-
globalThis.Rp = Rp;
|
|
827
|
-
globalThis.Rm = Rm;
|
|
828
|
-
return new x.constructor(
|
|
829
|
-
Math.acos((Rp - Rm) / 2),
|
|
830
|
-
-Math.acosh((Rp + Rm) / 2),
|
|
831
|
-
).toFixed(PRECESION)
|
|
832
|
-
}
|
|
833
|
-
return + Math.acos(x).toFixed(PRECESION)
|
|
834
|
-
},
|
|
835
|
-
...x
|
|
836
|
-
);
|
|
837
|
-
|
|
838
|
-
const asin = (...x) => mapfun(
|
|
839
|
-
x => {
|
|
840
|
-
if(x?.isComplex){
|
|
841
|
-
const { a, b } = x;
|
|
842
|
-
const Rp = Math.hypot(a + 1, b);
|
|
843
|
-
const Rm = Math.hypot(a - 1, b);
|
|
844
|
-
return new x.constructor(
|
|
845
|
-
Math.asin((Rp - Rm) / 2),
|
|
846
|
-
Math.acosh((Rp + Rm) / 2)
|
|
847
|
-
).toFixed(PRECESION);
|
|
848
|
-
}
|
|
849
|
-
return + Math.asin(x).toFixed(PRECESION);
|
|
850
|
-
},
|
|
851
|
-
...x
|
|
852
|
-
);
|
|
853
|
-
|
|
854
|
-
const atan = (...x) => mapfun(
|
|
855
|
-
x => {
|
|
856
|
-
if(x?.isComplex){
|
|
857
|
-
const { a, b } = x;
|
|
858
|
-
return new x.constructor(
|
|
859
|
-
Math.atan((a*2/(1-a**2-b**2)))/2,
|
|
860
|
-
Math.log((a**2 + (1+b)**2)/(a**2 + (1-b)**2))/4
|
|
861
|
-
).toFixed(PRECESION)
|
|
862
|
-
}
|
|
863
|
-
return + Math.atan(x).toFixed(PRECESION);
|
|
864
|
-
},
|
|
865
|
-
...x
|
|
866
|
-
);
|
|
867
|
-
|
|
868
|
-
const acot = (...x) => mapfun(
|
|
869
|
-
x => {
|
|
870
|
-
if(x?.isComplex){
|
|
871
|
-
const { a, b } = x;
|
|
872
|
-
return new x.constructor(
|
|
873
|
-
Math.atan(2*a/(a**2+(b-1)*(b+1)))/2,
|
|
874
|
-
Math.log((a**2 + (b-1)**2)/(a**2 + (b+1)**2))/4
|
|
875
|
-
).toFixed(PRECESION)
|
|
876
|
-
}
|
|
877
|
-
return + (Math.PI/2 - Math.atan(x)).toFixed(PRECESION);
|
|
878
|
-
},
|
|
879
|
-
...x
|
|
880
|
-
);
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
const cosh$1 = (...x) => mapfun(
|
|
884
|
-
x =>{
|
|
885
|
-
if(x?.isComplex) return new x.constructor(
|
|
886
|
-
Math.cosh(x.a) * Math.cos(x.b),
|
|
887
|
-
Math.sinh(x.a) * Math.sin(x.b)
|
|
888
|
-
).toFixed(PRECESION);
|
|
889
|
-
return + Math.cosh(x).toFixed(PRECESION)
|
|
890
|
-
},
|
|
891
|
-
...x
|
|
892
|
-
);
|
|
893
|
-
const sinh = (...x) => mapfun(
|
|
894
|
-
x =>{
|
|
895
|
-
if(x?.isComplex) return new x.constructor(
|
|
896
|
-
Math.sinh(x.a) * Math.cos(x.b),
|
|
897
|
-
Math.cosh(x.a) * Math.sin(x.b)
|
|
898
|
-
).toFixed(PRECESION);
|
|
899
|
-
return + Math.sinh(x).toFixed(PRECESION)
|
|
900
|
-
},
|
|
901
|
-
...x
|
|
902
|
-
);
|
|
903
|
-
const tanh = (...x) => mapfun(
|
|
904
|
-
x =>{
|
|
905
|
-
if(x?.isComplex){
|
|
906
|
-
const D = Math.cosh(2*a) + Math.cos(2*b);
|
|
907
|
-
return new x.constructor(
|
|
908
|
-
Math.sinh(2*a) / D,
|
|
909
|
-
Math.sin(2*b) / D
|
|
910
|
-
).toFixed(PRECESION)
|
|
911
|
-
}
|
|
912
|
-
return + Math.tanh(x).toFixed(PRECESION)
|
|
913
|
-
},
|
|
914
|
-
...x
|
|
915
|
-
);
|
|
916
|
-
|
|
917
|
-
const coth = (...x) => mapfun(
|
|
918
|
-
x =>{
|
|
919
|
-
if(x?.isComplex){
|
|
920
|
-
const {a, b} = x;
|
|
921
|
-
const D = (Math.sinh(a)**2)*(Math.cos(b)**2) + (Math.cosh(a)**2)*(Math.sin(b)**2);
|
|
922
|
-
return new x.constructor(
|
|
923
|
-
Math.cosh(a) * Math.sinh(a) / D,
|
|
924
|
-
- Math.sin(b) * Math.cos(b) / D
|
|
925
|
-
).toFixed(PRECESION)
|
|
926
|
-
}
|
|
927
|
-
return + (1 / Math.tanh(x)).toFixed(PRECESION)
|
|
928
|
-
},
|
|
929
|
-
...x
|
|
930
|
-
);
|
|
931
|
-
|
|
932
|
-
const acosh = (...x) => mapfun(
|
|
933
|
-
x =>{
|
|
934
|
-
if(x?.isComplex){
|
|
935
|
-
return ln(x.clone().add(sqrt(x.clone().mul(x.clone()).sub(1))))
|
|
936
|
-
}
|
|
937
|
-
return + Math.acosh(x).toFixed(PRECESION)
|
|
938
|
-
},
|
|
939
|
-
...x
|
|
940
|
-
);
|
|
941
|
-
|
|
942
|
-
const asinh = (...x) => mapfun(
|
|
943
|
-
x =>{
|
|
944
|
-
if(x?.isComplex){
|
|
945
|
-
return ln(x.clone().add(sqrt(x.clone().mul(x.clone()).add(1))))
|
|
946
|
-
}
|
|
947
|
-
return + Math.asinh(x).toFixed(PRECESION)
|
|
948
|
-
},
|
|
949
|
-
...x
|
|
950
|
-
);
|
|
951
|
-
|
|
952
|
-
const atanh = (...x) => mapfun(
|
|
953
|
-
x =>{
|
|
954
|
-
if(x?.isComplex);
|
|
955
|
-
return + Math.atanh(x).toFixed(PRECESION)
|
|
956
|
-
},
|
|
957
|
-
...x
|
|
958
|
-
);
|
|
959
|
-
|
|
960
|
-
const sig = (...x) => mapfun(
|
|
961
|
-
x =>{
|
|
962
|
-
if(x?.isComplex);
|
|
963
|
-
return 1/(1 + Math.exp(-x)).toFixed(PRECESION)
|
|
964
|
-
},
|
|
965
|
-
...x
|
|
966
|
-
);
|
|
967
|
-
|
|
968
|
-
const arithmetic_helper=(op, x, y)=>{
|
|
969
|
-
if(typeof x === 'number'){
|
|
970
|
-
if(typeof y === 'number'){
|
|
971
|
-
switch(op){
|
|
972
|
-
case 'add' : return x + y;
|
|
973
|
-
case 'sub' : return x - y;
|
|
974
|
-
case 'mul' : return x * y;
|
|
975
|
-
case 'div' : return x / y;
|
|
976
|
-
case 'modulo' : return x % y;
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
if(y?.isComplex?.()) x = new y.constructor(x, 0);
|
|
980
|
-
if(y?.isMatrix?.()) x = y.constructor.nums(y.rows, y.cols, x);
|
|
981
|
-
return x[op](y)
|
|
982
|
-
}
|
|
983
|
-
if(x?.isComplex?.()){
|
|
984
|
-
if(typeof y === 'number' || y?.isComplex?.()) return x.clone()[op](y);
|
|
985
|
-
if(y?.isMatrix?.()){
|
|
986
|
-
x = y.constructor.nums(y.rows, y.cols, x);
|
|
987
|
-
return x.clone()[op](y)
|
|
988
|
-
}
|
|
989
|
-
}
|
|
990
|
-
if(x?.isMatrix?.()){
|
|
991
|
-
return x.clone()[op](y)
|
|
992
|
-
}
|
|
993
|
-
};
|
|
994
|
-
const add=(a,...b)=>{
|
|
995
|
-
let res = a;
|
|
996
|
-
for(let i=0; i<b.length; i++)
|
|
997
|
-
res = arithmetic_helper('add', res, b[i]);
|
|
998
|
-
return res;
|
|
999
|
-
};
|
|
1000
|
-
const sub=(a,...b)=>{
|
|
1001
|
-
let res = a;
|
|
1002
|
-
for(let i=0; i<b.length; i++)
|
|
1003
|
-
res = arithmetic_helper('sub', res, b[i]);
|
|
1004
|
-
return res;
|
|
1005
|
-
};
|
|
1006
|
-
const mul=(a,...b)=>{
|
|
1007
|
-
let res = a;
|
|
1008
|
-
for(let i=0; i<b.length; i++)
|
|
1009
|
-
res = arithmetic_helper('mul', res, b[i]);
|
|
1010
|
-
return res;
|
|
1011
|
-
};
|
|
1012
|
-
const div=(a,...b)=>{
|
|
1013
|
-
let res = a;
|
|
1014
|
-
for(let i=0; i<b.length; i++)
|
|
1015
|
-
res = arithmetic_helper('div', res, b[i]);
|
|
1016
|
-
return res;
|
|
1017
|
-
};
|
|
1018
|
-
const modulo=(a,...b)=>{
|
|
1019
|
-
let res = a;
|
|
1020
|
-
for(let i=0; i<b.length; i++)
|
|
1021
|
-
res = arithmetic_helper('modulo', res, b[i]);
|
|
1022
|
-
return res;
|
|
1023
|
-
};
|
|
1024
|
-
|
|
1025
|
-
const deg2rad = (...deg) => mapfun(x => x * Math.PI / 180, ...deg);
|
|
1026
|
-
const rad2deg = (...rad) => mapfun(x => x / Math.PI * 180, ...rad);
|
|
1027
|
-
|
|
1028
|
-
const norm = (x, min, max) => apply_fun(
|
|
1029
|
-
x,
|
|
1030
|
-
v => min !== max ? (v - min) / (max - min) : 0
|
|
1031
|
-
);
|
|
1032
|
-
const lerp = (x, min, max) => apply_fun(
|
|
1033
|
-
x,
|
|
1034
|
-
v => (max - min) * v + min
|
|
1035
|
-
);
|
|
1036
|
-
const clamp = (x, min, max) => apply_fun(
|
|
1037
|
-
x,
|
|
1038
|
-
v => Math.min(Math.max(v, min), max)
|
|
1039
|
-
);
|
|
1040
|
-
const map$1 = (x, a, b, c, d) => apply_fun(
|
|
1041
|
-
x,
|
|
1042
|
-
v => lerp(norm(v, a, b), c, d)
|
|
1043
|
-
);
|
|
1044
|
-
|
|
1045
|
-
const hypot = (...x) => {
|
|
1046
|
-
const c0 = x.find(a => a.isComplex?.());
|
|
1047
|
-
if (c0) {
|
|
1048
|
-
const W = x.map(n => n.isComplex?.() ? n : new c0.constructor(n, 0));
|
|
1049
|
-
return Math.hypot(...W.map(c => c.z));
|
|
1050
|
-
}
|
|
1051
|
-
return Math.hypot(...x);
|
|
1052
|
-
};
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
const atan2 = (y, x, rad = true) => {
|
|
1056
|
-
if (y instanceof Array && !(x instanceof Array))
|
|
1057
|
-
return mapfun(n => atan2(n, x, rad), ...y);
|
|
1058
|
-
|
|
1059
|
-
if (x instanceof Array && !(y instanceof Array))
|
|
1060
|
-
return mapfun(n => atan2(y, n, rad), ...x);
|
|
1061
|
-
|
|
1062
|
-
if (y instanceof Array && x instanceof Array)
|
|
1063
|
-
return y.map((v, i) => atan2(v, x[i], rad));
|
|
1064
|
-
|
|
1065
|
-
const phi = Math.atan2(y, x);
|
|
1066
|
-
return rad ? phi : phi * 180 / Math.PI;
|
|
1067
|
-
};
|
|
1068
|
-
|
|
1069
|
-
class UINode {
|
|
1070
|
-
constructor(node){
|
|
1071
|
-
this.cache = {
|
|
1072
|
-
node
|
|
1073
|
-
};
|
|
1074
|
-
}
|
|
1075
|
-
isUINode(){
|
|
1076
|
-
return true
|
|
1077
|
-
}
|
|
1078
|
-
get node(){
|
|
1079
|
-
return this.cache.node;
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
|
|
1083
|
-
// globalThis.node = (node) => new UINode(node);
|
|
1084
|
-
|
|
1085
|
-
function parseQueryParams(queryString) {
|
|
1086
|
-
const params = {};
|
|
1087
|
-
queryString.replace(/[A-Z0-9]+?=([\w|:|\/\.]*)/gi, (match) => {
|
|
1088
|
-
const [key, value] = match.split('=');
|
|
1089
|
-
params[key] = value;
|
|
1090
|
-
});
|
|
1091
|
-
return params;
|
|
1092
|
-
}
|
|
1093
|
-
|
|
1094
|
-
function defineParamsGetter(target ){
|
|
1095
|
-
Object.defineProperties(target, {
|
|
1096
|
-
'QueryParams': {
|
|
1097
|
-
get: function() {
|
|
1098
|
-
return parseQueryParams(globalThis.location.search.substring(1));
|
|
1099
|
-
},
|
|
1100
|
-
configurable: false,
|
|
1101
|
-
enumerable: true
|
|
1102
|
-
},
|
|
1103
|
-
'HashParams': {
|
|
1104
|
-
get: function() {
|
|
1105
|
-
const hash = globalThis.location.hash.substring(1);
|
|
1106
|
-
return hash.split("#");
|
|
1107
|
-
},
|
|
1108
|
-
configurable: false,
|
|
1109
|
-
enumerable: true
|
|
1110
|
-
}
|
|
1111
|
-
});
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
class UIStore extends Array {
|
|
1115
|
-
constructor(...args) {
|
|
1116
|
-
super(...args);
|
|
1117
|
-
}
|
|
1118
|
-
clear(){
|
|
1119
|
-
this.length = 0;
|
|
1120
|
-
return this;
|
|
1121
|
-
}
|
|
1122
|
-
getItemById(id) {
|
|
1123
|
-
return this.find(n => n.element.id === id);
|
|
1124
|
-
}
|
|
1125
|
-
getItemsByTagName(tag) {
|
|
1126
|
-
return this.filter(n => n.element.tagName.toLowerCase() === tag.toLowerCase());
|
|
1127
|
-
}
|
|
1128
|
-
getElementsByClassName(className) {
|
|
1129
|
-
return this.filter(n => n.element.classList?.contains(className));
|
|
1130
|
-
}
|
|
1131
|
-
querySelector(selector) {
|
|
1132
|
-
const el = globalThis?.document?.querySelector(selector);
|
|
1133
|
-
if (!el) return null;
|
|
1134
|
-
return this.find(ui => ui.element === el) || null;
|
|
1135
|
-
}
|
|
1136
|
-
querySelectorAll(selector) {
|
|
1137
|
-
const els = globalThis?.document?.querySelectorAll(selector);
|
|
1138
|
-
return Array.from(els)
|
|
1139
|
-
.map(el => this.find(ui => ui.element === el))
|
|
1140
|
-
.filter(Boolean);
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
// create the singleton
|
|
1145
|
-
const __UI__ = new UIStore();
|
|
1146
|
-
|
|
1147
|
-
const __Config__ = {
|
|
1148
|
-
default:{
|
|
1149
|
-
target:null,
|
|
1150
|
-
render:true,
|
|
1151
|
-
// math:{
|
|
1152
|
-
// mode:"deg"
|
|
1153
|
-
// }
|
|
1154
|
-
},
|
|
1155
|
-
setDefault:function(pairs){
|
|
1156
|
-
const keys=Object.keys(pairs);
|
|
1157
|
-
const values=Object.values(pairs);
|
|
1158
|
-
for(let i=0; i<keys.length; i++) this.default[keys[i]]=values[i];
|
|
1159
|
-
},
|
|
1160
|
-
init:()=>{
|
|
1161
|
-
// document.documentElement.setAttribute("data-engine","zikojs")
|
|
184
|
+
init:()=>{
|
|
185
|
+
// document.documentElement.setAttribute("data-engine","zikojs")
|
|
1162
186
|
},
|
|
1163
187
|
renderingMode :"spa",
|
|
1164
188
|
isSSC : false,
|
|
@@ -1250,7 +274,7 @@ const parse_props = (props = {}) => {
|
|
|
1250
274
|
};
|
|
1251
275
|
|
|
1252
276
|
__init__global__();
|
|
1253
|
-
class
|
|
277
|
+
let UIElement$1 = class UIElement extends UINode{
|
|
1254
278
|
constructor(){
|
|
1255
279
|
super();
|
|
1256
280
|
}
|
|
@@ -1336,7 +360,7 @@ class UIElementCore extends UINode{
|
|
|
1336
360
|
isUIElement(){
|
|
1337
361
|
return true;
|
|
1338
362
|
}
|
|
1339
|
-
}
|
|
363
|
+
};
|
|
1340
364
|
|
|
1341
365
|
function register_to_class(target, ...mixins){
|
|
1342
366
|
mixins.forEach(n => _register_to_class_(target, n));
|
|
@@ -1355,28 +379,6 @@ function _register_to_class_(target, mixin) {
|
|
|
1355
379
|
}
|
|
1356
380
|
}
|
|
1357
381
|
|
|
1358
|
-
// export function mount(target = this.target) {
|
|
1359
|
-
// if(this.isBody) return ;
|
|
1360
|
-
// if(target?.isUIElement)target=target.element;
|
|
1361
|
-
// this.target=target;
|
|
1362
|
-
// this.target?.appendChild(this.element);
|
|
1363
|
-
// return this;
|
|
1364
|
-
// }
|
|
1365
|
-
// export function unmount(){
|
|
1366
|
-
// if(this.cache.parent)this.cache.parent.remove(this);
|
|
1367
|
-
// else if(this.target?.children?.length && [...this.target?.children].includes(this.element)) this.target.removeChild(this.element);
|
|
1368
|
-
// return this;
|
|
1369
|
-
// }
|
|
1370
|
-
|
|
1371
|
-
// export function mountAfter(target = this.target, t = 1) {
|
|
1372
|
-
// setTimeout(() => this.mount(), t);
|
|
1373
|
-
// return this;
|
|
1374
|
-
// }
|
|
1375
|
-
// export function unmountAfter(t = 1) {
|
|
1376
|
-
// setTimeout(() => this.unmount(), t);
|
|
1377
|
-
// return this;
|
|
1378
|
-
// }
|
|
1379
|
-
|
|
1380
382
|
function mount(target = this.target, delay = 0) {
|
|
1381
383
|
if (delay > 0) {
|
|
1382
384
|
setTimeout(() => this.mount(target, 0), delay);
|
|
@@ -1418,9 +420,6 @@ var LifecycleMethods = /*#__PURE__*/Object.freeze({
|
|
|
1418
420
|
|
|
1419
421
|
const STATE_GETTER = Symbol.for("ziko/hooks/STATE_GETTER");
|
|
1420
422
|
|
|
1421
|
-
// import { __init__global__ } from "../__ziko__/index.js";
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
423
|
function useState(initialValue) {
|
|
1425
424
|
const state = {
|
|
1426
425
|
value: initialValue,
|
|
@@ -1529,7 +528,7 @@ var AttrsMethods = /*#__PURE__*/Object.freeze({
|
|
|
1529
528
|
setContentEditable: setContentEditable
|
|
1530
529
|
});
|
|
1531
530
|
|
|
1532
|
-
class
|
|
531
|
+
class UIText extends UINode {
|
|
1533
532
|
constructor(...value) {
|
|
1534
533
|
super("span", "text", false, ...value);
|
|
1535
534
|
this.element = globalThis?.document?.createTextNode(...value);
|
|
@@ -1538,7 +537,7 @@ class ZikoUIText extends UINode {
|
|
|
1538
537
|
return true
|
|
1539
538
|
}
|
|
1540
539
|
}
|
|
1541
|
-
const text = (...str) => new
|
|
540
|
+
const text = (...str) => new UIText(...str);
|
|
1542
541
|
|
|
1543
542
|
function append(...ele) {
|
|
1544
543
|
__addItem__.call(this, "append", "push", ...ele);
|
|
@@ -1679,7 +678,7 @@ var IndexingMethods = /*#__PURE__*/Object.freeze({
|
|
|
1679
678
|
map: map
|
|
1680
679
|
});
|
|
1681
680
|
|
|
1682
|
-
function style
|
|
681
|
+
function style(styles){
|
|
1683
682
|
if(!this.element?.style) return this;
|
|
1684
683
|
for(let key in styles){
|
|
1685
684
|
const value = styles[key];
|
|
@@ -1718,7 +717,7 @@ var StyleMethods = /*#__PURE__*/Object.freeze({
|
|
|
1718
717
|
hide: hide,
|
|
1719
718
|
show: show,
|
|
1720
719
|
size: size,
|
|
1721
|
-
style: style
|
|
720
|
+
style: style
|
|
1722
721
|
});
|
|
1723
722
|
|
|
1724
723
|
class EventController {
|
|
@@ -1920,28 +919,218 @@ const KeyListeners = {
|
|
|
1920
919
|
|
|
1921
920
|
};
|
|
1922
921
|
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
fn(...args);
|
|
1934
|
-
}
|
|
1935
|
-
};
|
|
1936
|
-
|
|
1937
|
-
class ViewEvent extends CustomEvent {
|
|
1938
|
-
constructor(type, detail, { bubbles = true, cancelable = true } = {}) {
|
|
1939
|
-
super(type, { detail, bubbles, cancelable });
|
|
1940
|
-
}
|
|
1941
|
-
}
|
|
922
|
+
class Tick {
|
|
923
|
+
constructor(fn, ms, count = Infinity, start) {
|
|
924
|
+
this.ms = ms;
|
|
925
|
+
this.fn = fn;
|
|
926
|
+
this.count = count;
|
|
927
|
+
this.frame = 1;
|
|
928
|
+
this.id = null;
|
|
929
|
+
this.running = false;
|
|
930
|
+
if(start) this.start();
|
|
931
|
+
}
|
|
1942
932
|
|
|
1943
|
-
|
|
1944
|
-
|
|
933
|
+
start() {
|
|
934
|
+
if (!this.running) {
|
|
935
|
+
this.running = true;
|
|
936
|
+
this.frame = 1;
|
|
937
|
+
this.id = setInterval(() => {
|
|
938
|
+
if (this.frame > this.count) {
|
|
939
|
+
this.stop();
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
this.fn.call(null, this);
|
|
943
|
+
this.frame++;
|
|
944
|
+
}, this.ms);
|
|
945
|
+
}
|
|
946
|
+
return this;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
stop() {
|
|
950
|
+
if (this.running) {
|
|
951
|
+
this.running = false;
|
|
952
|
+
clearInterval(this.id);
|
|
953
|
+
this.id = null;
|
|
954
|
+
}
|
|
955
|
+
return this;
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
isRunning() {
|
|
959
|
+
return this.running;
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
// Helper factory
|
|
964
|
+
const tick = (fn, ms, count = Infinity, start = true) => new Tick(fn, ms, count, start);
|
|
965
|
+
|
|
966
|
+
class Clock extends Tick {
|
|
967
|
+
constructor(tickMs = 1000 / 60) {
|
|
968
|
+
super(tickMs, () => this._tick());
|
|
969
|
+
this.elapsed = 0;
|
|
970
|
+
this._lastTime = performance.now();
|
|
971
|
+
this._callbacks = new Set();
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
_tick() {
|
|
975
|
+
const now = performance.now();
|
|
976
|
+
const delta = now - this._lastTime;
|
|
977
|
+
this.elapsed += delta;
|
|
978
|
+
this._lastTime = now;
|
|
979
|
+
|
|
980
|
+
for (const cb of this._callbacks) {
|
|
981
|
+
cb({ elapsed: this.elapsed, delta });
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
onTick(cb) {
|
|
986
|
+
this._callbacks.add(cb);
|
|
987
|
+
return () => this._callbacks.delete(cb);
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
reset() {
|
|
991
|
+
this.elapsed = 0;
|
|
992
|
+
this._lastTime = performance.now();
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
pause() {
|
|
996
|
+
super.stop();
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
resume() {
|
|
1000
|
+
this._lastTime = performance.now();
|
|
1001
|
+
super.start();
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
const clock = (tickMs) => new Clock(tickMs);
|
|
1006
|
+
|
|
1007
|
+
|
|
1008
|
+
/*
|
|
1009
|
+
|
|
1010
|
+
const clock = new Clock(200);
|
|
1011
|
+
|
|
1012
|
+
clock.onTick(({ elapsed, delta }) => {
|
|
1013
|
+
console.log(`Elapsed: ${elapsed.toFixed(0)}ms, Delta: ${delta.toFixed(0)}ms`);
|
|
1014
|
+
});
|
|
1015
|
+
|
|
1016
|
+
clock.start();
|
|
1017
|
+
|
|
1018
|
+
setTimeout(() => clock.pause(), 1000);
|
|
1019
|
+
setTimeout(() => clock.resume(), 2000);
|
|
1020
|
+
|
|
1021
|
+
*/
|
|
1022
|
+
|
|
1023
|
+
const debounce=(fn,delay=1000)=>{
|
|
1024
|
+
let id;
|
|
1025
|
+
return (...args) => id ? clearTimeout(id) : setTimeout(()=>fn(...args),delay);
|
|
1026
|
+
};
|
|
1027
|
+
|
|
1028
|
+
class TimeScheduler {
|
|
1029
|
+
constructor(tasks = [], { repeat = 1, loop = false } = {}) {
|
|
1030
|
+
this.tasks = tasks;
|
|
1031
|
+
this.repeat = repeat;
|
|
1032
|
+
this.loop = loop;
|
|
1033
|
+
|
|
1034
|
+
this.stopped = false;
|
|
1035
|
+
this.running = false;
|
|
1036
|
+
|
|
1037
|
+
// lifecycle hooks
|
|
1038
|
+
this.onStart = null;
|
|
1039
|
+
this.onTask = null;
|
|
1040
|
+
this.onEnd = null;
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
async run() {
|
|
1044
|
+
if (this.running) return;
|
|
1045
|
+
this.running = true;
|
|
1046
|
+
this.stopped = false;
|
|
1047
|
+
|
|
1048
|
+
if (this.onStart) this.onStart();
|
|
1049
|
+
|
|
1050
|
+
let repeatCount = this.repeat;
|
|
1051
|
+
|
|
1052
|
+
do {
|
|
1053
|
+
for (const task of this.tasks) {
|
|
1054
|
+
if (this.stopped) return;
|
|
1055
|
+
|
|
1056
|
+
if (Array.isArray(task)) {
|
|
1057
|
+
// Parallel tasks
|
|
1058
|
+
await Promise.all(
|
|
1059
|
+
task.map(({ fn, delay = 0 }) =>
|
|
1060
|
+
new Promise(async (resolve) => {
|
|
1061
|
+
if (delay > 0) await new Promise(r => setTimeout(r, delay));
|
|
1062
|
+
if (this.onTask) this.onTask(fn);
|
|
1063
|
+
await fn();
|
|
1064
|
+
resolve();
|
|
1065
|
+
})
|
|
1066
|
+
)
|
|
1067
|
+
);
|
|
1068
|
+
} else {
|
|
1069
|
+
// Single task
|
|
1070
|
+
const { fn, delay = 0 } = task;
|
|
1071
|
+
if (delay > 0) await new Promise(r => setTimeout(r, delay));
|
|
1072
|
+
if (this.onTask) this.onTask(fn);
|
|
1073
|
+
await fn();
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
} while (this.loop && !this.stopped && (repeatCount === Infinity || repeatCount-- > 1));
|
|
1077
|
+
|
|
1078
|
+
if (!this.stopped && this.onEnd) this.onEnd();
|
|
1079
|
+
this.running = false;
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
stop() {
|
|
1083
|
+
this.stopped = true;
|
|
1084
|
+
this.running = false;
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
addTask(task) {
|
|
1088
|
+
this.tasks.push(task);
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
clearTasks() {
|
|
1092
|
+
this.tasks = [];
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
const Scheduler = (tasks, { repeat = null} = {}) => new TimeScheduler(tasks, { repeat});
|
|
1097
|
+
|
|
1098
|
+
const sleep= ms => new Promise(res => setTimeout(res, ms));
|
|
1099
|
+
|
|
1100
|
+
const throttle=(fn,delay)=>{
|
|
1101
|
+
let lastTime=0;
|
|
1102
|
+
return (...args) => {
|
|
1103
|
+
const now = new Date().getTime();
|
|
1104
|
+
if(now-lastTime < delay) return;
|
|
1105
|
+
lastTime = now;
|
|
1106
|
+
fn(...args);
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
|
|
1110
|
+
function timeout(ms, fn) {
|
|
1111
|
+
let id;
|
|
1112
|
+
const promise = new Promise((resolve) => {
|
|
1113
|
+
id = setTimeout(() => {
|
|
1114
|
+
if (fn) fn();
|
|
1115
|
+
resolve();
|
|
1116
|
+
}, ms);
|
|
1117
|
+
});
|
|
1118
|
+
|
|
1119
|
+
return {
|
|
1120
|
+
id,
|
|
1121
|
+
clear: () => clearTimeout(id),
|
|
1122
|
+
promise
|
|
1123
|
+
};
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
class ViewEvent extends CustomEvent {
|
|
1127
|
+
constructor(type, detail, { bubbles = true, cancelable = true } = {}) {
|
|
1128
|
+
super(type, { detail, bubbles, cancelable });
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
function register_view_event(
|
|
1133
|
+
element,
|
|
1945
1134
|
{
|
|
1946
1135
|
intersection = true,
|
|
1947
1136
|
resize = true,
|
|
@@ -2097,7 +1286,7 @@ function register_swipe_event(
|
|
|
2097
1286
|
};
|
|
2098
1287
|
}
|
|
2099
1288
|
|
|
2100
|
-
class UIElement extends
|
|
1289
|
+
class UIElement extends UIElement$1{
|
|
2101
1290
|
constructor({element, name ='', type = 'html', render = __Ziko__.__Config__.default.render, props}={}){
|
|
2102
1291
|
super();
|
|
2103
1292
|
this.exp = {
|
|
@@ -2211,95 +1400,6 @@ class UIElement extends UIElementCore{
|
|
|
2211
1400
|
|
|
2212
1401
|
}
|
|
2213
1402
|
|
|
2214
|
-
const is_primitive = (value) => typeof value !== 'object' && typeof value !== 'function' || value === null;
|
|
2215
|
-
|
|
2216
|
-
const call_with_optional_props = (Component) => {
|
|
2217
|
-
return (...args) => {
|
|
2218
|
-
const first = args[0];
|
|
2219
|
-
|
|
2220
|
-
const isChild = first?.isUIElement?.() || is_primitive(first);
|
|
2221
|
-
|
|
2222
|
-
if (isChild) {
|
|
2223
|
-
return new Component({}, ...args);
|
|
2224
|
-
}
|
|
2225
|
-
|
|
2226
|
-
return new Component(first, ...args.slice(1));
|
|
2227
|
-
};
|
|
2228
|
-
};
|
|
2229
|
-
|
|
2230
|
-
function add_vendor_prefix(property) {
|
|
2231
|
-
const propertyUC = property.slice(0, 1).toUpperCase() + property.slice(1);
|
|
2232
|
-
const vendors = ['Webkit', 'Moz', 'O', 'ms'];
|
|
2233
|
-
for(let i = 0, len = vendors.length; i < len; i++) {
|
|
2234
|
-
const vendor = vendors[i];
|
|
2235
|
-
if(typeof (globalThis?.document?.body).style[vendor + propertyUC] !== 'undefined') return vendor + propertyUC;
|
|
2236
|
-
}
|
|
2237
|
-
return property;
|
|
2238
|
-
}
|
|
2239
|
-
const normalize_css_value = value => typeof value === 'number' ? value+'px' : value;
|
|
2240
|
-
const add_class = (UIElement, name) => UIElement.element.className = UIElement.element.className.replace(/\s+$/gi, '') + ' ' + name;
|
|
2241
|
-
const remove_class =(UIElement, name) => UIElement.element.className = UIElement.element.className.replace(name, '');
|
|
2242
|
-
|
|
2243
|
-
// const addSuffixeToNumber=(value,suffixe="px")=>{
|
|
2244
|
-
// if(typeof value === "number") value+=suffixe;
|
|
2245
|
-
// if(value instanceof Array)value=value.map(n=>typeof n==="number"?n+=suffixe:n).join(" ");
|
|
2246
|
-
// return value;
|
|
2247
|
-
// }
|
|
2248
|
-
|
|
2249
|
-
// const Id = (a) => document.getElementById(a);
|
|
2250
|
-
// const Class = (a) => [...document.getElementsByClassName(a)];
|
|
2251
|
-
// const $=(...selector)=>{
|
|
2252
|
-
// var ele=[]
|
|
2253
|
-
// for(let i=0;i<selector.length;i++){
|
|
2254
|
-
// if(typeof selector[i]=="string")ele.push(...document.querySelectorAll(selector[i]));
|
|
2255
|
-
// if(selector[i] instanceof UIElement)ele.push(selector[i].element)
|
|
2256
|
-
// }
|
|
2257
|
-
// return ele.length===1?ele[0]:ele;
|
|
2258
|
-
// }
|
|
2259
|
-
|
|
2260
|
-
const style = (el, styles) => {if(el)Object.assign(el.style, styles);};
|
|
2261
|
-
|
|
2262
|
-
function script(src) {
|
|
2263
|
-
const Script = document?.createElement("script");
|
|
2264
|
-
Script.setAttribute("src", src);
|
|
2265
|
-
document.head.appendChild(Script);
|
|
2266
|
-
}
|
|
2267
|
-
function linkStyle(href) {
|
|
2268
|
-
const link = document?.createElement("link");
|
|
2269
|
-
link.setAttribute("rel", "stylesheet");
|
|
2270
|
-
link.setAttribute("href", href);
|
|
2271
|
-
document.head.appendChild(link);
|
|
2272
|
-
}
|
|
2273
|
-
const CloneElement = (UIElement) => {
|
|
2274
|
-
var clone = new UIElement.__proto__.constructor();
|
|
2275
|
-
//waitForUIElm(UIElement).then(e=>console.log(e)).then(()=>clone = new UIElement.__proto__.constructor())
|
|
2276
|
-
//let a = new UIElement.__proto__.constructor()
|
|
2277
|
-
return clone;
|
|
2278
|
-
};
|
|
2279
|
-
const cloneUI=UIElement=>{
|
|
2280
|
-
return Object.assign(Object.create(Object.getPrototypeOf(UIElement)),UIElement)
|
|
2281
|
-
};
|
|
2282
|
-
// function isPrimitive(value) {
|
|
2283
|
-
// return typeof value !== 'object' && typeof value !== 'function' || value === null;
|
|
2284
|
-
// }
|
|
2285
|
-
const waitElm=(UIElement)=>{
|
|
2286
|
-
return new Promise(resolve => {
|
|
2287
|
-
if (UIElement) {
|
|
2288
|
-
return resolve(UIElement);
|
|
2289
|
-
}
|
|
2290
|
-
const observer = new MutationObserver(() => {
|
|
2291
|
-
if (UIElement) {
|
|
2292
|
-
resolve(UIElement);
|
|
2293
|
-
observer.disconnect();
|
|
2294
|
-
}
|
|
2295
|
-
});
|
|
2296
|
-
observer.observe(document?.body, {
|
|
2297
|
-
childList: true,
|
|
2298
|
-
subtree: true
|
|
2299
|
-
});
|
|
2300
|
-
});
|
|
2301
|
-
};
|
|
2302
|
-
|
|
2303
1403
|
const HTMLTags = [
|
|
2304
1404
|
'a',
|
|
2305
1405
|
'abb',
|
|
@@ -2459,443 +1559,6 @@ const tags = new Proxy({}, {
|
|
|
2459
1559
|
}
|
|
2460
1560
|
});
|
|
2461
1561
|
|
|
2462
|
-
const linear = t => t;
|
|
2463
|
-
|
|
2464
|
-
class TimeAnimation {
|
|
2465
|
-
constructor(callback, { ease = linear, step = 50, t0 = 0, start = true, duration = 3000 } = {}) {
|
|
2466
|
-
this.callback = callback;
|
|
2467
|
-
this.state = {
|
|
2468
|
-
isRunning: false,
|
|
2469
|
-
animationId: null,
|
|
2470
|
-
startTime: null,
|
|
2471
|
-
ease,
|
|
2472
|
-
step,
|
|
2473
|
-
// interval: [t0, t1],
|
|
2474
|
-
autoStart: start,
|
|
2475
|
-
duration
|
|
2476
|
-
};
|
|
2477
|
-
|
|
2478
|
-
this.t = 0; // elapsed time
|
|
2479
|
-
this.tx = 0; // normalized [0,1]
|
|
2480
|
-
this.ty = 0; // eased value
|
|
2481
|
-
this.i = 0; // frame index
|
|
2482
|
-
|
|
2483
|
-
if (this.state.autoStart) {
|
|
2484
|
-
this.start();
|
|
2485
|
-
}
|
|
2486
|
-
}
|
|
2487
|
-
|
|
2488
|
-
// ---- private loop handler ----
|
|
2489
|
-
#tick = () => {
|
|
2490
|
-
this.t += this.state.step;
|
|
2491
|
-
this.i++;
|
|
2492
|
-
|
|
2493
|
-
this.tx = map$1(this.t, 0, this.state.duration, 0, 1);
|
|
2494
|
-
this.ty = this.state.ease(this.tx);
|
|
2495
|
-
|
|
2496
|
-
this.callback(this);
|
|
2497
|
-
|
|
2498
|
-
if (this.t >= this.state.duration) {
|
|
2499
|
-
clearInterval(this.state.animationId);
|
|
2500
|
-
this.state.isRunning = false;
|
|
2501
|
-
}
|
|
2502
|
-
};
|
|
2503
|
-
|
|
2504
|
-
// ---- core runner ----
|
|
2505
|
-
#run(reset = true) {
|
|
2506
|
-
if (!this.state.isRunning) {
|
|
2507
|
-
if (reset) this.reset(false);
|
|
2508
|
-
|
|
2509
|
-
this.state.isRunning = true;
|
|
2510
|
-
this.state.startTime = Date.now();
|
|
2511
|
-
this.state.animationId = setInterval(this.#tick, this.state.step);
|
|
2512
|
-
}
|
|
2513
|
-
return this;
|
|
2514
|
-
}
|
|
2515
|
-
|
|
2516
|
-
// ---- lifecycle methods ----
|
|
2517
|
-
start() {
|
|
2518
|
-
return this.#run(true);
|
|
2519
|
-
}
|
|
2520
|
-
|
|
2521
|
-
pause() {
|
|
2522
|
-
if (this.state.isRunning) {
|
|
2523
|
-
clearInterval(this.state.animationId);
|
|
2524
|
-
this.state.isRunning = false;
|
|
2525
|
-
}
|
|
2526
|
-
return this;
|
|
2527
|
-
}
|
|
2528
|
-
|
|
2529
|
-
resume() {
|
|
2530
|
-
return this.#run(false);
|
|
2531
|
-
}
|
|
2532
|
-
|
|
2533
|
-
stop() {
|
|
2534
|
-
this.pause();
|
|
2535
|
-
this.reset(false);
|
|
2536
|
-
return this;
|
|
2537
|
-
}
|
|
2538
|
-
|
|
2539
|
-
reset(restart = true) {
|
|
2540
|
-
this.t = 0;
|
|
2541
|
-
this.tx = 0;
|
|
2542
|
-
this.ty = 0;
|
|
2543
|
-
this.i = 0;
|
|
2544
|
-
|
|
2545
|
-
if (restart) this.start();
|
|
2546
|
-
return this;
|
|
2547
|
-
}
|
|
2548
|
-
}
|
|
2549
|
-
|
|
2550
|
-
// Hook-style factory
|
|
2551
|
-
const animation = (callback, {ease, t0, t1, start, duration} = {}) =>
|
|
2552
|
-
new TimeAnimation(callback, {ease, t0, t1, start, duration});
|
|
2553
|
-
|
|
2554
|
-
class Tick {
|
|
2555
|
-
constructor(fn, ms, count = Infinity, start) {
|
|
2556
|
-
this.ms = ms;
|
|
2557
|
-
this.fn = fn;
|
|
2558
|
-
this.count = count;
|
|
2559
|
-
this.frame = 1;
|
|
2560
|
-
this.id = null;
|
|
2561
|
-
this.running = false;
|
|
2562
|
-
if(start) this.start();
|
|
2563
|
-
}
|
|
2564
|
-
|
|
2565
|
-
start() {
|
|
2566
|
-
if (!this.running) {
|
|
2567
|
-
this.running = true;
|
|
2568
|
-
this.frame = 1;
|
|
2569
|
-
this.id = setInterval(() => {
|
|
2570
|
-
if (this.frame > this.count) {
|
|
2571
|
-
this.stop();
|
|
2572
|
-
return;
|
|
2573
|
-
}
|
|
2574
|
-
this.fn.call(null, this);
|
|
2575
|
-
this.frame++;
|
|
2576
|
-
}, this.ms);
|
|
2577
|
-
}
|
|
2578
|
-
return this;
|
|
2579
|
-
}
|
|
2580
|
-
|
|
2581
|
-
stop() {
|
|
2582
|
-
if (this.running) {
|
|
2583
|
-
this.running = false;
|
|
2584
|
-
clearInterval(this.id);
|
|
2585
|
-
this.id = null;
|
|
2586
|
-
}
|
|
2587
|
-
return this;
|
|
2588
|
-
}
|
|
2589
|
-
|
|
2590
|
-
isRunning() {
|
|
2591
|
-
return this.running;
|
|
2592
|
-
}
|
|
2593
|
-
}
|
|
2594
|
-
|
|
2595
|
-
// Helper factory
|
|
2596
|
-
const tick = (fn, ms, count = Infinity, start = true) => new Tick(fn, ms, count, start);
|
|
2597
|
-
|
|
2598
|
-
class Clock extends Tick {
|
|
2599
|
-
constructor(tickMs = 1000 / 60) {
|
|
2600
|
-
super(tickMs, () => this._tick());
|
|
2601
|
-
this.elapsed = 0;
|
|
2602
|
-
this._lastTime = performance.now();
|
|
2603
|
-
this._callbacks = new Set();
|
|
2604
|
-
}
|
|
2605
|
-
|
|
2606
|
-
_tick() {
|
|
2607
|
-
const now = performance.now();
|
|
2608
|
-
const delta = now - this._lastTime;
|
|
2609
|
-
this.elapsed += delta;
|
|
2610
|
-
this._lastTime = now;
|
|
2611
|
-
|
|
2612
|
-
for (const cb of this._callbacks) {
|
|
2613
|
-
cb({ elapsed: this.elapsed, delta });
|
|
2614
|
-
}
|
|
2615
|
-
}
|
|
2616
|
-
|
|
2617
|
-
onTick(cb) {
|
|
2618
|
-
this._callbacks.add(cb);
|
|
2619
|
-
return () => this._callbacks.delete(cb);
|
|
2620
|
-
}
|
|
2621
|
-
|
|
2622
|
-
reset() {
|
|
2623
|
-
this.elapsed = 0;
|
|
2624
|
-
this._lastTime = performance.now();
|
|
2625
|
-
}
|
|
2626
|
-
|
|
2627
|
-
pause() {
|
|
2628
|
-
super.stop();
|
|
2629
|
-
}
|
|
2630
|
-
|
|
2631
|
-
resume() {
|
|
2632
|
-
this._lastTime = performance.now();
|
|
2633
|
-
super.start();
|
|
2634
|
-
}
|
|
2635
|
-
}
|
|
2636
|
-
|
|
2637
|
-
const clock = (tickMs) => new Clock(tickMs);
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
/*
|
|
2641
|
-
|
|
2642
|
-
const clock = new Clock(200);
|
|
2643
|
-
|
|
2644
|
-
clock.onTick(({ elapsed, delta }) => {
|
|
2645
|
-
console.log(`Elapsed: ${elapsed.toFixed(0)}ms, Delta: ${delta.toFixed(0)}ms`);
|
|
2646
|
-
});
|
|
2647
|
-
|
|
2648
|
-
clock.start();
|
|
2649
|
-
|
|
2650
|
-
setTimeout(() => clock.pause(), 1000);
|
|
2651
|
-
setTimeout(() => clock.resume(), 2000);
|
|
2652
|
-
|
|
2653
|
-
*/
|
|
2654
|
-
|
|
2655
|
-
class TimeScheduler {
|
|
2656
|
-
constructor(tasks = [], { repeat = 1, loop = false } = {}) {
|
|
2657
|
-
this.tasks = tasks;
|
|
2658
|
-
this.repeat = repeat;
|
|
2659
|
-
this.loop = loop;
|
|
2660
|
-
|
|
2661
|
-
this.stopped = false;
|
|
2662
|
-
this.running = false;
|
|
2663
|
-
|
|
2664
|
-
// lifecycle hooks
|
|
2665
|
-
this.onStart = null;
|
|
2666
|
-
this.onTask = null;
|
|
2667
|
-
this.onEnd = null;
|
|
2668
|
-
}
|
|
2669
|
-
|
|
2670
|
-
async run() {
|
|
2671
|
-
if (this.running) return;
|
|
2672
|
-
this.running = true;
|
|
2673
|
-
this.stopped = false;
|
|
2674
|
-
|
|
2675
|
-
if (this.onStart) this.onStart();
|
|
2676
|
-
|
|
2677
|
-
let repeatCount = this.repeat;
|
|
2678
|
-
|
|
2679
|
-
do {
|
|
2680
|
-
for (const task of this.tasks) {
|
|
2681
|
-
if (this.stopped) return;
|
|
2682
|
-
|
|
2683
|
-
if (Array.isArray(task)) {
|
|
2684
|
-
// Parallel tasks
|
|
2685
|
-
await Promise.all(
|
|
2686
|
-
task.map(({ fn, delay = 0 }) =>
|
|
2687
|
-
new Promise(async (resolve) => {
|
|
2688
|
-
if (delay > 0) await new Promise(r => setTimeout(r, delay));
|
|
2689
|
-
if (this.onTask) this.onTask(fn);
|
|
2690
|
-
await fn();
|
|
2691
|
-
resolve();
|
|
2692
|
-
})
|
|
2693
|
-
)
|
|
2694
|
-
);
|
|
2695
|
-
} else {
|
|
2696
|
-
// Single task
|
|
2697
|
-
const { fn, delay = 0 } = task;
|
|
2698
|
-
if (delay > 0) await new Promise(r => setTimeout(r, delay));
|
|
2699
|
-
if (this.onTask) this.onTask(fn);
|
|
2700
|
-
await fn();
|
|
2701
|
-
}
|
|
2702
|
-
}
|
|
2703
|
-
} while (this.loop && !this.stopped && (repeatCount === Infinity || repeatCount-- > 1));
|
|
2704
|
-
|
|
2705
|
-
if (!this.stopped && this.onEnd) this.onEnd();
|
|
2706
|
-
this.running = false;
|
|
2707
|
-
}
|
|
2708
|
-
|
|
2709
|
-
stop() {
|
|
2710
|
-
this.stopped = true;
|
|
2711
|
-
this.running = false;
|
|
2712
|
-
}
|
|
2713
|
-
|
|
2714
|
-
addTask(task) {
|
|
2715
|
-
this.tasks.push(task);
|
|
2716
|
-
}
|
|
2717
|
-
|
|
2718
|
-
clearTasks() {
|
|
2719
|
-
this.tasks = [];
|
|
2720
|
-
}
|
|
2721
|
-
}
|
|
2722
|
-
|
|
2723
|
-
const Scheduler = (tasks, { repeat = null} = {}) => new TimeScheduler(tasks, { repeat});
|
|
2724
|
-
|
|
2725
|
-
const step_fps = (step_or_fps) => 1000 / step_or_fps;
|
|
2726
|
-
|
|
2727
|
-
const sleep= ms => new Promise(res => setTimeout(res, ms));
|
|
2728
|
-
function timeout(ms, fn) {
|
|
2729
|
-
let id;
|
|
2730
|
-
const promise = new Promise((resolve) => {
|
|
2731
|
-
id = setTimeout(() => {
|
|
2732
|
-
if (fn) fn();
|
|
2733
|
-
resolve();
|
|
2734
|
-
}, ms);
|
|
2735
|
-
});
|
|
2736
|
-
|
|
2737
|
-
return {
|
|
2738
|
-
id,
|
|
2739
|
-
clear: () => clearTimeout(id),
|
|
2740
|
-
promise
|
|
2741
|
-
};
|
|
2742
|
-
}
|
|
2743
|
-
|
|
2744
|
-
class TimeLoop {
|
|
2745
|
-
constructor(callback, { step = 1000, t0 = 0, t1 = Infinity, autoplay = true } = {}) {
|
|
2746
|
-
this.callback = callback;
|
|
2747
|
-
this.cache = {
|
|
2748
|
-
isRunning: false,
|
|
2749
|
-
id: null,
|
|
2750
|
-
last_tick: null,
|
|
2751
|
-
step,
|
|
2752
|
-
t0,
|
|
2753
|
-
t1,
|
|
2754
|
-
autoplay,
|
|
2755
|
-
pauseTime: null,
|
|
2756
|
-
frame : 0,
|
|
2757
|
-
};
|
|
2758
|
-
|
|
2759
|
-
if (autoplay) {
|
|
2760
|
-
t0 ? this.startAfter(t0) : this.start();
|
|
2761
|
-
if (t1 !== Infinity) this.stopAfter(t1);
|
|
2762
|
-
}
|
|
2763
|
-
}
|
|
2764
|
-
|
|
2765
|
-
get frame(){
|
|
2766
|
-
return this.cache.frame;
|
|
2767
|
-
}
|
|
2768
|
-
get elapsed(){
|
|
2769
|
-
return this.cache.elapsed;
|
|
2770
|
-
}
|
|
2771
|
-
|
|
2772
|
-
start() {
|
|
2773
|
-
if (!this.cache.isRunning) {
|
|
2774
|
-
this.cache.frame = 0;
|
|
2775
|
-
this.cache.isRunning = true;
|
|
2776
|
-
this.cache.last_tick = Date.now();
|
|
2777
|
-
this.animate();
|
|
2778
|
-
}
|
|
2779
|
-
return this;
|
|
2780
|
-
}
|
|
2781
|
-
|
|
2782
|
-
pause() {
|
|
2783
|
-
if (this.cache.isRunning) {
|
|
2784
|
-
clearTimeout(this.cache.id);
|
|
2785
|
-
this.cache.isRunning = false;
|
|
2786
|
-
this.cache.pauseTime = Date.now();
|
|
2787
|
-
}
|
|
2788
|
-
return this;
|
|
2789
|
-
}
|
|
2790
|
-
|
|
2791
|
-
resume() {
|
|
2792
|
-
if (!this.cache.isRunning) {
|
|
2793
|
-
this.cache.isRunning = true;
|
|
2794
|
-
if (this.cache.pauseTime) {
|
|
2795
|
-
// adjust start time so delta stays consistent
|
|
2796
|
-
const pausedDuration = Date.now() - this.cache.pauseTime;
|
|
2797
|
-
this.cache.last_tick += pausedDuration;
|
|
2798
|
-
}
|
|
2799
|
-
this.animate();
|
|
2800
|
-
}
|
|
2801
|
-
return this;
|
|
2802
|
-
}
|
|
2803
|
-
|
|
2804
|
-
stop() {
|
|
2805
|
-
this.pause();
|
|
2806
|
-
this.cache.frame = 0;
|
|
2807
|
-
return this;
|
|
2808
|
-
}
|
|
2809
|
-
|
|
2810
|
-
startAfter(t = 1000) {
|
|
2811
|
-
setTimeout(() => this.start(), t);
|
|
2812
|
-
return this;
|
|
2813
|
-
}
|
|
2814
|
-
|
|
2815
|
-
stopAfter(t = 1000) {
|
|
2816
|
-
setTimeout(() => this.stop(), t);
|
|
2817
|
-
return this;
|
|
2818
|
-
}
|
|
2819
|
-
|
|
2820
|
-
animate = () => {
|
|
2821
|
-
if (this.cache.isRunning) {
|
|
2822
|
-
const now = Date.now();
|
|
2823
|
-
const delta = now - this.cache.last_tick;
|
|
2824
|
-
|
|
2825
|
-
if (delta >= this.cache.step) {
|
|
2826
|
-
this.cache.elapsed = now - (this.cache.t0 || 0);
|
|
2827
|
-
this.callback(this);
|
|
2828
|
-
this.cache.frame++;
|
|
2829
|
-
this.cache.last_tick = now - (delta % this.cache.step);
|
|
2830
|
-
}
|
|
2831
|
-
|
|
2832
|
-
this.cache.id = setTimeout(this.animate, 0);
|
|
2833
|
-
}
|
|
2834
|
-
}
|
|
2835
|
-
}
|
|
2836
|
-
|
|
2837
|
-
const loop = (callback, options = {}) => new TimeLoop(callback, options);
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
// Helpers
|
|
2841
|
-
// const useFps = (fps) => 1000 / fps;
|
|
2842
|
-
|
|
2843
|
-
// const _loop = loop( e => {
|
|
2844
|
-
// console.log("Frame:", e.frame, " Elapsed: ", e.elapsed);
|
|
2845
|
-
// });
|
|
2846
|
-
|
|
2847
|
-
const time_memory_Taken = (callback) => {
|
|
2848
|
-
const t0 = Date.now();
|
|
2849
|
-
const m0 = performance.memory.usedJSHeapSize;
|
|
2850
|
-
const result = callback();
|
|
2851
|
-
const t1 = Date.now();
|
|
2852
|
-
const m1 = performance.memory.usedJSHeapSize;
|
|
2853
|
-
const elapsedTime = t1 - t0;
|
|
2854
|
-
const usedMemory = m1 - m0;
|
|
2855
|
-
return {
|
|
2856
|
-
elapsedTime,
|
|
2857
|
-
usedMemory,
|
|
2858
|
-
result
|
|
2859
|
-
};
|
|
2860
|
-
};
|
|
2861
|
-
|
|
2862
|
-
const waitForUIElm=(UIElement)=>{
|
|
2863
|
-
return new Promise(resolve => {
|
|
2864
|
-
if (UIElement.element) {
|
|
2865
|
-
return resolve(UIElement.element);
|
|
2866
|
-
}
|
|
2867
|
-
|
|
2868
|
-
const observer = new MutationObserver(() => {
|
|
2869
|
-
if (UIElement.element) {
|
|
2870
|
-
resolve(UIElement.element);
|
|
2871
|
-
observer.disconnect();
|
|
2872
|
-
}
|
|
2873
|
-
});
|
|
2874
|
-
|
|
2875
|
-
observer.observe(document?.body, {
|
|
2876
|
-
childList: true,
|
|
2877
|
-
subtree: true
|
|
2878
|
-
});
|
|
2879
|
-
});
|
|
2880
|
-
};
|
|
2881
|
-
const waitForUIElmSync=(UIElement,timeout=2000)=>{
|
|
2882
|
-
const t0=Date.now();
|
|
2883
|
-
while(Date.now()-t0<timeout){
|
|
2884
|
-
if(UIElement.element)return UIElement.element
|
|
2885
|
-
}
|
|
2886
|
-
};
|
|
2887
|
-
|
|
2888
|
-
// import Ease from "./ease.js";
|
|
2889
|
-
const wait=(delayInMS)=>{
|
|
2890
|
-
return new Promise((resolve) => setTimeout(resolve, delayInMS));
|
|
2891
|
-
};
|
|
2892
|
-
const timeTaken = callback => {
|
|
2893
|
-
console.time('timeTaken');
|
|
2894
|
-
const r = callback();
|
|
2895
|
-
console.timeEnd('timeTaken');
|
|
2896
|
-
return r;
|
|
2897
|
-
};
|
|
2898
|
-
|
|
2899
1562
|
function useDerived(deriveFn, sources) {
|
|
2900
1563
|
const getValue = () => deriveFn(...sources.map(source => source().value));
|
|
2901
1564
|
|
|
@@ -3100,77 +1763,38 @@ if(globalThis?.document){
|
|
|
3100
1763
|
exports.ClickAwayEvent = ClickAwayEvent;
|
|
3101
1764
|
exports.ClickListeners = ClickListeners;
|
|
3102
1765
|
exports.Clock = Clock;
|
|
3103
|
-
exports.CloneElement = CloneElement;
|
|
3104
1766
|
exports.E = E;
|
|
3105
1767
|
exports.EPSILON = EPSILON;
|
|
3106
1768
|
exports.EventController = EventController;
|
|
3107
1769
|
exports.KeyListeners = KeyListeners;
|
|
3108
1770
|
exports.PI = PI;
|
|
3109
1771
|
exports.PtrListeners = PtrListeners;
|
|
3110
|
-
exports.Random = Random;
|
|
3111
1772
|
exports.Scheduler = Scheduler;
|
|
3112
1773
|
exports.SwipeEvent = SwipeEvent;
|
|
3113
1774
|
exports.Tick = Tick;
|
|
3114
|
-
exports.TimeAnimation = TimeAnimation;
|
|
3115
|
-
exports.TimeLoop = TimeLoop;
|
|
3116
1775
|
exports.TimeScheduler = TimeScheduler;
|
|
3117
1776
|
exports.UIElement = UIElement;
|
|
3118
|
-
exports.UINode = UINode;
|
|
3119
1777
|
exports.ViewEvent = ViewEvent;
|
|
3120
1778
|
exports.ViewListeners = ViewListeners;
|
|
3121
|
-
exports.
|
|
3122
|
-
exports.abs = abs;
|
|
3123
|
-
exports.accum_max = accum_max;
|
|
3124
|
-
exports.accum_min = accum_min;
|
|
3125
|
-
exports.accum_product = accum_product;
|
|
3126
|
-
exports.accum_sum = accum_sum;
|
|
3127
|
-
exports.acos = acos;
|
|
3128
|
-
exports.acosh = acosh;
|
|
3129
|
-
exports.acot = acot;
|
|
3130
|
-
exports.add = add;
|
|
3131
|
-
exports.add_class = add_class;
|
|
3132
|
-
exports.add_vendor_prefix = add_vendor_prefix;
|
|
3133
|
-
exports.animation = animation;
|
|
3134
|
-
exports.asin = asin;
|
|
3135
|
-
exports.asinh = asinh;
|
|
3136
|
-
exports.atan = atan;
|
|
1779
|
+
exports.apply_fun = apply_fun;
|
|
3137
1780
|
exports.atan2 = atan2;
|
|
3138
|
-
exports.atanh = atanh;
|
|
3139
|
-
exports.call_with_optional_props = call_with_optional_props;
|
|
3140
1781
|
exports.camel2constantcase = camel2constantcase;
|
|
3141
1782
|
exports.camel2hyphencase = camel2hyphencase$1;
|
|
3142
1783
|
exports.camel2pascalcase = camel2pascalcase;
|
|
3143
1784
|
exports.camel2snakecase = camel2snakecase;
|
|
3144
|
-
exports.cbrt = cbrt;
|
|
3145
|
-
exports.ceil = ceil;
|
|
3146
1785
|
exports.clamp = clamp;
|
|
3147
1786
|
exports.clock = clock;
|
|
3148
|
-
exports.cloneUI = cloneUI;
|
|
3149
1787
|
exports.constant2camelcase = constant2camelcase;
|
|
3150
1788
|
exports.constant2hyphencase = constant2hyphencase;
|
|
3151
1789
|
exports.constant2pascalcase = constant2pascalcase;
|
|
3152
1790
|
exports.constant2snakecase = constant2snakecase;
|
|
3153
|
-
exports.contraharmonic_mean = contraharmonic_mean;
|
|
3154
|
-
exports.cos = cos$1;
|
|
3155
|
-
exports.cosh = cosh$1;
|
|
3156
|
-
exports.coth = coth;
|
|
3157
|
-
exports.croot = croot;
|
|
3158
1791
|
exports.debounce = debounce;
|
|
3159
1792
|
exports.deg2rad = deg2rad;
|
|
3160
|
-
exports.div = div;
|
|
3161
|
-
exports.ema = ema;
|
|
3162
|
-
exports.exp = exp;
|
|
3163
|
-
exports.floor = floor;
|
|
3164
|
-
exports.fract = fract;
|
|
3165
|
-
exports.geo_mean = geo_mean;
|
|
3166
|
-
exports.harmonic_mean = harmonic_mean;
|
|
3167
1793
|
exports.hyphen2camelcase = hyphen2camelcase;
|
|
3168
1794
|
exports.hyphen2constantcase = hyphen2constantcase;
|
|
3169
1795
|
exports.hyphen2pascalcase = hyphen2pascalcase;
|
|
3170
1796
|
exports.hyphen2snakecase = hyphen2snakecase;
|
|
3171
1797
|
exports.hypot = hypot;
|
|
3172
|
-
exports.interquartile_mean = interquartile_mean;
|
|
3173
|
-
exports.iqr = iqr;
|
|
3174
1798
|
exports.isStateGetter = isStateGetter;
|
|
3175
1799
|
exports.is_anagram = is_anagram;
|
|
3176
1800
|
exports.is_camelcase = is_camelcase$1;
|
|
@@ -3178,83 +1802,30 @@ exports.is_hyphencase = is_hyphencase;
|
|
|
3178
1802
|
exports.is_isogram = is_isogram;
|
|
3179
1803
|
exports.is_palindrome = is_palindrome;
|
|
3180
1804
|
exports.is_pascalcalse = is_pascalcalse;
|
|
3181
|
-
exports.is_primitive = is_primitive;
|
|
3182
1805
|
exports.is_snakeCase = is_snakeCase;
|
|
3183
1806
|
exports.lerp = lerp;
|
|
3184
|
-
exports.linkStyle = linkStyle;
|
|
3185
|
-
exports.ln = ln;
|
|
3186
|
-
exports.loop = loop;
|
|
3187
1807
|
exports.map = map$1;
|
|
3188
|
-
exports.
|
|
3189
|
-
exports.median = median;
|
|
3190
|
-
exports.midhinge = midhinge;
|
|
3191
|
-
exports.midrange = midrange;
|
|
3192
|
-
exports.modulo = modulo;
|
|
3193
|
-
exports.mul = mul;
|
|
1808
|
+
exports.mapfun = mapfun;
|
|
3194
1809
|
exports.norm = norm;
|
|
3195
|
-
exports.normalize_css_value = normalize_css_value;
|
|
3196
|
-
exports.nthr = nthr;
|
|
3197
|
-
exports.parse_props = parse_props;
|
|
3198
1810
|
exports.pascal2camelcase = pascal2camelcase;
|
|
3199
1811
|
exports.pascal2constantcase = pascal2constantcase;
|
|
3200
1812
|
exports.pascal2hyphencase = pascal2hyphencase;
|
|
3201
1813
|
exports.pascal2snakecase = pascal2snakecase;
|
|
3202
|
-
exports.percentile = percentile;
|
|
3203
|
-
exports.pow = pow;
|
|
3204
|
-
exports.power_mean = power_mean;
|
|
3205
|
-
exports.q1 = q1;
|
|
3206
|
-
exports.q3 = q3;
|
|
3207
1814
|
exports.rad2deg = rad2deg;
|
|
3208
1815
|
exports.register_click_away_event = register_click_away_event;
|
|
3209
1816
|
exports.register_swipe_event = register_swipe_event;
|
|
3210
1817
|
exports.register_view_event = register_view_event;
|
|
3211
|
-
exports.remove_class = remove_class;
|
|
3212
|
-
exports.rms = rms;
|
|
3213
|
-
exports.rolling_std = rolling_std;
|
|
3214
|
-
exports.rolling_variance = rolling_variance;
|
|
3215
|
-
exports.round = round;
|
|
3216
|
-
exports.sample_std = sample_std;
|
|
3217
|
-
exports.sample_variance = sample_variance;
|
|
3218
|
-
exports.script = script;
|
|
3219
|
-
exports.sec = sec;
|
|
3220
|
-
exports.sig = sig;
|
|
3221
|
-
exports.sign = sign;
|
|
3222
|
-
exports.sin = sin$1;
|
|
3223
|
-
exports.sinh = sinh;
|
|
3224
1818
|
exports.sleep = sleep;
|
|
3225
|
-
exports.sma = sma;
|
|
3226
1819
|
exports.snake2camelcase = snake2camelcase;
|
|
3227
1820
|
exports.snake2constantcase = snake2constantcase;
|
|
3228
1821
|
exports.snake2hyphencase = snake2hyphencase;
|
|
3229
1822
|
exports.snake2pascalcase = snake2pascalcase;
|
|
3230
|
-
exports.sqrt = sqrt;
|
|
3231
|
-
exports.std = std;
|
|
3232
|
-
exports.step_fps = step_fps;
|
|
3233
|
-
exports.style = style;
|
|
3234
|
-
exports.sub = sub;
|
|
3235
1823
|
exports.tags = tags;
|
|
3236
|
-
exports.tan = tan;
|
|
3237
|
-
exports.tanh = tanh;
|
|
3238
|
-
exports.text = text;
|
|
3239
1824
|
exports.throttle = throttle;
|
|
3240
1825
|
exports.tick = tick;
|
|
3241
|
-
exports.timeTaken = timeTaken;
|
|
3242
|
-
exports.time_memory_Taken = time_memory_Taken;
|
|
3243
1826
|
exports.timeout = timeout;
|
|
3244
|
-
exports.trimmed_mean = trimmed_mean;
|
|
3245
|
-
exports.trunc = trunc;
|
|
3246
1827
|
exports.useDerived = useDerived;
|
|
3247
1828
|
exports.useEffect = useEffect;
|
|
3248
1829
|
exports.useEventEmitter = useEventEmitter;
|
|
3249
1830
|
exports.useReactive = useReactive;
|
|
3250
1831
|
exports.useState = useState;
|
|
3251
|
-
exports.variance = variance;
|
|
3252
|
-
exports.wait = wait;
|
|
3253
|
-
exports.waitElm = waitElm;
|
|
3254
|
-
exports.waitForUIElm = waitForUIElm;
|
|
3255
|
-
exports.waitForUIElmSync = waitForUIElmSync;
|
|
3256
|
-
exports.weighted_mean = weighted_mean;
|
|
3257
|
-
exports.weighted_std = weighted_std;
|
|
3258
|
-
exports.weighted_variance = weighted_variance;
|
|
3259
|
-
exports.winsorized_mean = winsorized_mean;
|
|
3260
|
-
exports.wma = wma;
|