ziko 0.39.0 → 0.40.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 +689 -522
- package/dist/ziko.js +697 -523
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +639 -509
- package/package.json +1 -1
- package/src/data/index.js +2 -2
- package/src/data/string/checkers.js +27 -0
- package/src/data/string/converters.js +24 -0
- package/src/data/string/index.js +2 -1
- package/src/data/string-dep/index.js +1 -0
- package/src/hooks/use-state.js +11 -8
- package/src/index.js +2 -1
- package/src/math/index.js +17 -17
- package/src/reactivity/hooks/UI/useRoot.js +3 -3
- package/src/reactivity/index.js +0 -9
- package/src/time/animation/index.js +88 -70
- package/src/time/clocks/clock.js +62 -0
- package/src/time/clocks/index.js +3 -0
- package/src/time/clocks/scheduler.js +69 -0
- package/src/time/clocks/tick.js +34 -0
- package/src/time/converters/index.js +1 -0
- package/src/time/delay/index.js +2 -0
- package/src/time/delay/sleep.js +3 -0
- package/src/time/delay/timeout.js +15 -0
- package/src/time/ease/index.js +77 -0
- package/src/time/index.js +6 -9
- package/src/time/loop/index.js +67 -51
- package/src/time/utils/index.js +2 -2
- package/src/ui/__methods__/attrs.js +6 -3
- package/src/ui/__methods__/dom.js +8 -1
- package/src/ui/__methods__/style.js +23 -3
- package/src/ui/constructors/style/index.js +2 -1
- package/src/ui/tags/index.js +3 -7
- package/src/time/utils/ease.js +0 -144
- /package/src/data/{string → string-dep}/patterns.js +0 -0
- /package/src/data/{string → string-dep}/string.js +0 -0
package/dist/ziko.mjs
CHANGED
|
@@ -2,28 +2,28 @@
|
|
|
2
2
|
/*
|
|
3
3
|
Project: ziko.js
|
|
4
4
|
Author: Zakaria Elalaoui
|
|
5
|
-
Date :
|
|
5
|
+
Date : Tue Aug 19 2025 12:50:26 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
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
const { PI: PI$
|
|
11
|
+
const { PI: PI$2, E } = Math;
|
|
12
12
|
const EPSILON=Number.EPSILON;
|
|
13
13
|
|
|
14
|
-
const {PI, cos: cos$
|
|
14
|
+
const {PI: PI$1, cos: cos$2, sin: sin$2, tan: tan$1, acos: acos$2, asin: asin$1, atan: atan$1, cosh: cosh$1, sinh: sinh$1, tanh: tanh$1, acosh: acosh$1, asinh: asinh$1, atanh: atanh$1, log} = Math;
|
|
15
15
|
let Fixed={
|
|
16
|
-
cos: cos$
|
|
17
|
-
sin: sin$
|
|
16
|
+
cos: cos$2,
|
|
17
|
+
sin: sin$2,
|
|
18
18
|
tan: tan$1,
|
|
19
|
-
sinc: x => sin$
|
|
20
|
-
sec: x => 1/cos$
|
|
21
|
-
csc: x => 1/sin$
|
|
19
|
+
sinc: x => sin$2(PI$1*x)/(PI$1*x),
|
|
20
|
+
sec: x => 1/cos$2(x),
|
|
21
|
+
csc: x => 1/sin$2(x),
|
|
22
22
|
cot: x => 1/tan$1(x),
|
|
23
|
-
acos: acos$
|
|
23
|
+
acos: acos$2,
|
|
24
24
|
asin: asin$1,
|
|
25
25
|
atan: atan$1,
|
|
26
|
-
acot: x => PI/2-atan$1(x),
|
|
26
|
+
acot: x => PI$1/2-atan$1(x),
|
|
27
27
|
cosh: cosh$1,
|
|
28
28
|
sinh: sinh$1,
|
|
29
29
|
tanh: tanh$1,
|
|
@@ -61,20 +61,20 @@ const mapfun$1=(fun,...X)=>{
|
|
|
61
61
|
const [a,b,z,phi]=[x.a,x.b,x.z,x.phi];
|
|
62
62
|
switch(fun){
|
|
63
63
|
case Math.log: return complex(ln(z),phi); // Done
|
|
64
|
-
case Math.exp: return complex(e(a)*cos(b),e(a)*sin(b)); // Done
|
|
64
|
+
case Math.exp: return complex(e(a)*cos$1(b),e(a)*sin$1(b)); // Done
|
|
65
65
|
case Math.abs: return z; // Done
|
|
66
|
-
case Math.sqrt: return complex(sqrt(z)*cos(phi/2),sqrt(z)*sin(phi/2)); // Done
|
|
67
|
-
case Fixed.cos: return complex(cos(a)*cosh(b),-(sin(a)*sinh(b)));
|
|
68
|
-
case Fixed.sin: return complex(sin(a)*cosh(b),cos(a)*sinh(b));
|
|
66
|
+
case Math.sqrt: return complex(sqrt$1(z)*cos$1(phi/2),sqrt$1(z)*sin$1(phi/2)); // Done
|
|
67
|
+
case Fixed.cos: return complex(cos$1(a)*cosh(b),-(sin$1(a)*sinh(b)));
|
|
68
|
+
case Fixed.sin: return complex(sin$1(a)*cosh(b),cos$1(a)*sinh(b));
|
|
69
69
|
case Fixed.tan:{
|
|
70
|
-
const DEN = cos(2*a)+cosh(2*b);
|
|
71
|
-
return complex(sin(2*a)/DEN,sinh(2*b)/DEN);
|
|
70
|
+
const DEN = cos$1(2*a)+cosh(2*b);
|
|
71
|
+
return complex(sin$1(2*a)/DEN,sinh(2*b)/DEN);
|
|
72
72
|
}
|
|
73
|
-
case Fixed.cosh:return complex(cosh(a)*cos(b),sinh(a)*sin(b));
|
|
74
|
-
case Fixed.sinh:return complex(sinh(a)*cos(b),cosh(a)*sin(b));
|
|
73
|
+
case Fixed.cosh:return complex(cosh(a)*cos$1(b),sinh(a)*sin$1(b));
|
|
74
|
+
case Fixed.sinh:return complex(sinh(a)*cos$1(b),cosh(a)*sin$1(b));
|
|
75
75
|
case Fixed.tanh:{
|
|
76
|
-
const DEN=cosh(2*a)+cos(2*b);
|
|
77
|
-
return complex(sinh(2*a)/DEN,sin(2*b)/DEN)
|
|
76
|
+
const DEN=cosh(2*a)+cos$1(2*b);
|
|
77
|
+
return complex(sinh(2*a)/DEN,sin$1(2*b)/DEN)
|
|
78
78
|
}
|
|
79
79
|
default : return fun(x)
|
|
80
80
|
}
|
|
@@ -315,7 +315,7 @@ const linspace=(a,b,n=abs(b-a)+1,endpoint=true)=>{
|
|
|
315
315
|
}
|
|
316
316
|
};
|
|
317
317
|
const logspace=(a,b,n=b-a+1,base=E,endpoint=true)=>{
|
|
318
|
-
return linspace(a,b,n,endpoint).map(n=>pow(base,n))
|
|
318
|
+
return linspace(a,b,n,endpoint).map(n=>pow$1(base,n))
|
|
319
319
|
};
|
|
320
320
|
const geomspace=(a,b,n=abs(b-a)+1,endpoint=true)=>{
|
|
321
321
|
if(Math.floor(n)!==n)return;
|
|
@@ -1100,10 +1100,69 @@ const register = (target, ...mixins) => {
|
|
|
1100
1100
|
else register_to_instance(target, ...mixins);
|
|
1101
1101
|
};
|
|
1102
1102
|
|
|
1103
|
+
function useState(initialValue) {
|
|
1104
|
+
let value = initialValue;
|
|
1105
|
+
const subscribers = new Set();
|
|
1106
|
+
let paused = false;
|
|
1107
|
+
|
|
1108
|
+
function getValue() {
|
|
1109
|
+
return {
|
|
1110
|
+
value,
|
|
1111
|
+
isStateGetter: () => true,
|
|
1112
|
+
_subscribe: (
|
|
1113
|
+
fn,
|
|
1114
|
+
// UIElement
|
|
1115
|
+
) => {
|
|
1116
|
+
subscribers.add(fn);
|
|
1117
|
+
|
|
1118
|
+
// const observer = new MutationObserver(() => {
|
|
1119
|
+
// if (!document.body.contains(UIElement.element)) {
|
|
1120
|
+
// subscribers.delete(fn);
|
|
1121
|
+
// observer.disconnect();
|
|
1122
|
+
// }
|
|
1123
|
+
// });
|
|
1124
|
+
|
|
1125
|
+
// observer.observe(document.body, { childList: true, subtree: true });
|
|
1126
|
+
},
|
|
1127
|
+
};
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
function setValue(newValue) {
|
|
1131
|
+
if (paused) return;
|
|
1132
|
+
if (typeof newValue === "function") newValue = newValue(value);
|
|
1133
|
+
if (newValue !== value) {
|
|
1134
|
+
value = newValue;
|
|
1135
|
+
subscribers.forEach(fn => fn(value));
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
const controller = {
|
|
1140
|
+
pause: () => { paused = true; },
|
|
1141
|
+
resume: () => { paused = false; },
|
|
1142
|
+
clear: () => { subscribers.clear(); },
|
|
1143
|
+
force: (newValue) => { // force update even if paused
|
|
1144
|
+
if (typeof newValue === "function") newValue = newValue(value);
|
|
1145
|
+
value = newValue;
|
|
1146
|
+
subscribers.forEach(fn => fn(value));
|
|
1147
|
+
},
|
|
1148
|
+
getSubscribers: () => new Set(subscribers),
|
|
1149
|
+
};
|
|
1150
|
+
|
|
1151
|
+
return [getValue, setValue, controller];
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1103
1154
|
const isStateGetter = (arg) => {
|
|
1104
1155
|
return typeof(arg) === 'function' && arg?.()?.isStateGetter?.()
|
|
1105
1156
|
};
|
|
1106
1157
|
|
|
1158
|
+
const camel2hyphencase = (text = '') => text.replace(/[A-Z]/g, match => '-' + match.toLowerCase());
|
|
1159
|
+
|
|
1160
|
+
const is_camelcase = (text = '') =>{
|
|
1161
|
+
if (text.length === 0) return false;
|
|
1162
|
+
const camelCasePattern = /^[a-z][a-zA-Z0-9]*$/;
|
|
1163
|
+
return camelCasePattern.test(text);
|
|
1164
|
+
};
|
|
1165
|
+
|
|
1107
1166
|
// To Do add getter, watchAttr
|
|
1108
1167
|
const AttrsMethods = {
|
|
1109
1168
|
setAttr(name, value) {
|
|
@@ -1125,7 +1184,7 @@ const AttrsMethods = {
|
|
|
1125
1184
|
return this;
|
|
1126
1185
|
},
|
|
1127
1186
|
getAttr(name){
|
|
1128
|
-
name =
|
|
1187
|
+
name = is_camelcase(name) ? camel2hyphencase(name) : name;
|
|
1129
1188
|
return this.element.attributes[name].value;
|
|
1130
1189
|
},
|
|
1131
1190
|
setContentEditable(bool = true) {
|
|
@@ -1135,7 +1194,7 @@ const AttrsMethods = {
|
|
|
1135
1194
|
};
|
|
1136
1195
|
|
|
1137
1196
|
function _set_attrs_(name, value){
|
|
1138
|
-
if(this.element?.tagName !== "svg") name =
|
|
1197
|
+
if(this.element?.tagName !== "svg") name = is_camelcase(name) ? camel2hyphencase(name) : name;
|
|
1139
1198
|
if(this?.attr[name] && this?.attr[name]===value) return;
|
|
1140
1199
|
if(isStateGetter(value)){
|
|
1141
1200
|
const getter = value();
|
|
@@ -1228,7 +1287,7 @@ const DomMethods = {
|
|
|
1228
1287
|
|
|
1229
1288
|
};
|
|
1230
1289
|
|
|
1231
|
-
function __addItem__(adder, pusher, ...ele) {
|
|
1290
|
+
async function __addItem__(adder, pusher, ...ele) {
|
|
1232
1291
|
if (this.cache.isFrozzen) {
|
|
1233
1292
|
console.warn("You can't append new item to frozzen element");
|
|
1234
1293
|
return this;
|
|
@@ -1254,6 +1313,13 @@ function __addItem__(adder, pusher, ...ele) {
|
|
|
1254
1313
|
ele[i].target = this.element;
|
|
1255
1314
|
this.items[pusher](ele[i]);
|
|
1256
1315
|
}
|
|
1316
|
+
else if(ele[i] instanceof Promise){
|
|
1317
|
+
const UIEle = await ele[i];
|
|
1318
|
+
UIEle.cache.parent = this;
|
|
1319
|
+
this.element?.[adder](UIEle.element);
|
|
1320
|
+
UIEle.target = this.element;
|
|
1321
|
+
this.items[pusher](UIEle);
|
|
1322
|
+
}
|
|
1257
1323
|
else if (ele[i] instanceof Object) {
|
|
1258
1324
|
if (ele[i]?.style) this.style(ele[i]?.style);
|
|
1259
1325
|
if (ele[i]?.attr) {
|
|
@@ -1694,19 +1760,38 @@ const IndexingMethods = {
|
|
|
1694
1760
|
},
|
|
1695
1761
|
};
|
|
1696
1762
|
|
|
1697
|
-
// Process width and height
|
|
1698
1763
|
const StyleMethods = {
|
|
1699
1764
|
style(styles){
|
|
1700
|
-
|
|
1765
|
+
for(let key in styles){
|
|
1766
|
+
const value = styles[key];
|
|
1767
|
+
if(isStateGetter(value)){
|
|
1768
|
+
const getter = value();
|
|
1769
|
+
Object.assign(this.element.style, {[key] : getter.value});
|
|
1770
|
+
getter._subscribe(
|
|
1771
|
+
(newValue) => {
|
|
1772
|
+
console.log({newValue});
|
|
1773
|
+
Object.assign(this.element.style, {[key] : newValue});
|
|
1774
|
+
},
|
|
1775
|
+
// this
|
|
1776
|
+
);
|
|
1777
|
+
}
|
|
1778
|
+
else Object.assign(this.element.style, {[key] : value});
|
|
1779
|
+
}
|
|
1701
1780
|
return this;
|
|
1702
1781
|
},
|
|
1703
1782
|
size(width, height){
|
|
1704
1783
|
return this.style({width, height})
|
|
1784
|
+
},
|
|
1785
|
+
hide(){
|
|
1786
|
+
|
|
1787
|
+
},
|
|
1788
|
+
show(){
|
|
1789
|
+
|
|
1705
1790
|
},
|
|
1706
1791
|
animate(keyframe, {duration=1000, iterations=1, easing="ease"}={}){
|
|
1707
1792
|
this.element?.animate(keyframe,{duration, iterations, easing});
|
|
1708
1793
|
return this;
|
|
1709
|
-
|
|
1794
|
+
}
|
|
1710
1795
|
};
|
|
1711
1796
|
|
|
1712
1797
|
function EVENT_CONTROLLER(e,EVENT,setter,push_object){
|
|
@@ -3113,18 +3198,14 @@ const tags = new Proxy({}, {
|
|
|
3113
3198
|
let type ;
|
|
3114
3199
|
if(HTMLTags.includes(tag)) type = 'html';
|
|
3115
3200
|
if(SVGTags.includes(tag)) type = 'svg';
|
|
3116
|
-
|
|
3201
|
+
return (...args)=>{
|
|
3117
3202
|
console.log(isStateGetter(args[0]));
|
|
3118
|
-
// if(typeof args[0] === 'function') {
|
|
3119
|
-
// console.log(args[0], args[0]?.() instanceof StateGetter)
|
|
3120
|
-
// globalThis.a = args[0]
|
|
3121
|
-
// console.log({t : a.constructor})
|
|
3122
|
-
// }
|
|
3123
3203
|
if(
|
|
3124
3204
|
['string', 'number'].includes(typeof args[0])
|
|
3125
3205
|
|| args[0] instanceof UIElement
|
|
3126
3206
|
|| (typeof args[0] === 'function' && args[0]().isStateGetter())
|
|
3127
|
-
) return new UIElement({element :tag, name : tag, type}).append(...args);
|
|
3207
|
+
) return new UIElement({element : tag, name : tag, type}).append(...args);
|
|
3208
|
+
// console.log(args[0])
|
|
3128
3209
|
return new UIElement({element : tag}).setAttr(args.shift()).append(...args)
|
|
3129
3210
|
}
|
|
3130
3211
|
// if(SVGTags.includes(tag)) return (...args) => new UIElement(tag,"",{el_type : "svg"}).append(...args);
|
|
@@ -3716,175 +3797,6 @@ function trimKeys(obj) {
|
|
|
3716
3797
|
}, Array.isArray(obj) ? [] : {});
|
|
3717
3798
|
}
|
|
3718
3799
|
|
|
3719
|
-
const Patterns={
|
|
3720
|
-
isDigit: /^\d+$/,
|
|
3721
|
-
isURL: /^(https?:\/\/)?([\w\-]+\.)+[\w\-]+(\/[\w\-./?%&=]*)?$/,
|
|
3722
|
-
isHexColor: /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/,
|
|
3723
|
-
isIPv4: /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,
|
|
3724
|
-
isMACAddress: /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/,
|
|
3725
|
-
isDate: /^\d{4}-\d{2}-\d{2}$/,
|
|
3726
|
-
};
|
|
3727
|
-
|
|
3728
|
-
class Str{
|
|
3729
|
-
constructor(string){
|
|
3730
|
-
this.string=string;
|
|
3731
|
-
}
|
|
3732
|
-
isDigit() {
|
|
3733
|
-
return Patterns.isDigit.test(this.string);
|
|
3734
|
-
}
|
|
3735
|
-
static isDigit(string){
|
|
3736
|
-
return new Str(string).isDigit();
|
|
3737
|
-
}
|
|
3738
|
-
isNumber() {
|
|
3739
|
-
return !isNaN(this.string);
|
|
3740
|
-
}
|
|
3741
|
-
static isNumber(string){
|
|
3742
|
-
return new Str(string).isNumber();
|
|
3743
|
-
}
|
|
3744
|
-
isUrl(){
|
|
3745
|
-
return Patterns.isURL.test(this.string);
|
|
3746
|
-
}
|
|
3747
|
-
static isUrl(string){
|
|
3748
|
-
return new Str(string).isUrl();
|
|
3749
|
-
}
|
|
3750
|
-
isHexColor(){
|
|
3751
|
-
return Patterns.isHexColor.test(this.string);
|
|
3752
|
-
}
|
|
3753
|
-
static isHexColor(string){
|
|
3754
|
-
return new Str(string).isHexColor();
|
|
3755
|
-
}
|
|
3756
|
-
isIPv4(){
|
|
3757
|
-
return Patterns.isIPv4.test(this.string);
|
|
3758
|
-
}
|
|
3759
|
-
static isIPv4(string){
|
|
3760
|
-
return new Str(string).isIPv4();
|
|
3761
|
-
}
|
|
3762
|
-
isDate(){
|
|
3763
|
-
return Patterns.isDate.test(this.string);
|
|
3764
|
-
}
|
|
3765
|
-
static isDate(string){
|
|
3766
|
-
return new Str(string).isDate();
|
|
3767
|
-
}
|
|
3768
|
-
isMACAddress(){
|
|
3769
|
-
return Patterns.isMACAddress.test(this.string);
|
|
3770
|
-
}
|
|
3771
|
-
static isMACAddress(string){
|
|
3772
|
-
return new Str(string).isMACAddress();
|
|
3773
|
-
}
|
|
3774
|
-
isPascalCase(){
|
|
3775
|
-
if (this.string.length === 0) return false;
|
|
3776
|
-
const PascalCasePattern = /^[A-Z][a-zA-Z0-9]*$/;
|
|
3777
|
-
return PascalCasePattern.test(this.string);
|
|
3778
|
-
}
|
|
3779
|
-
static isPascalCase(string){
|
|
3780
|
-
return new Str(string).isPascalCase();
|
|
3781
|
-
}
|
|
3782
|
-
isCamelCase() {
|
|
3783
|
-
if (this.string.length === 0) return false;
|
|
3784
|
-
const camelCasePattern = /^[a-z][a-zA-Z0-9]*$/;
|
|
3785
|
-
return camelCasePattern.test(this.string);
|
|
3786
|
-
}
|
|
3787
|
-
static isCamelCase(string){
|
|
3788
|
-
return new Str(string).isCamelCase();
|
|
3789
|
-
}
|
|
3790
|
-
isHyphenCase(){
|
|
3791
|
-
return this.string.split('-').length > 1;
|
|
3792
|
-
}
|
|
3793
|
-
static isHyphenCase(string){
|
|
3794
|
-
return new Str(string).isHyphenCase();
|
|
3795
|
-
}
|
|
3796
|
-
isSnakeCase(){
|
|
3797
|
-
return this.string.split('_').length > 1;
|
|
3798
|
-
}
|
|
3799
|
-
static isSnakeCase(string){
|
|
3800
|
-
return new Str(string).isSnakeCase();
|
|
3801
|
-
}
|
|
3802
|
-
isPalindrome(){
|
|
3803
|
-
const str=this.string.toLocaleLowerCase();
|
|
3804
|
-
let l=str.length,i;
|
|
3805
|
-
for(i=0;i<l/2;i++)if(str[i]!=str[l-i-1])return false;
|
|
3806
|
-
return true;
|
|
3807
|
-
}
|
|
3808
|
-
static isPalindrome(string){
|
|
3809
|
-
return new Str(string).isPalindrome();
|
|
3810
|
-
}
|
|
3811
|
-
static isAnagrams(word,words){
|
|
3812
|
-
word=word.split("").sort();
|
|
3813
|
-
words=words.split("").sort();
|
|
3814
|
-
return JSON.stringify(word)===JSON.stringify(words);
|
|
3815
|
-
}
|
|
3816
|
-
isIsogram(){
|
|
3817
|
-
return [...new Set(this.string.toLowerCase())].length===this.string.length;
|
|
3818
|
-
}
|
|
3819
|
-
static isIsogram(string){
|
|
3820
|
-
return new Str(string).isIsogram();
|
|
3821
|
-
}
|
|
3822
|
-
static camel2hyphencase(text) {
|
|
3823
|
-
return text.replace(/[A-Z]/g, match => '-' + match.toLowerCase());
|
|
3824
|
-
}
|
|
3825
|
-
static camel2snakecase(text) {
|
|
3826
|
-
return text.replace(/[A-Z]/g, match => '_' + match.toLowerCase());
|
|
3827
|
-
}
|
|
3828
|
-
static camel2pascalcase(text) {
|
|
3829
|
-
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
3830
|
-
}
|
|
3831
|
-
static camel2constantcase(text) {
|
|
3832
|
-
return text.replace(/[A-Z]/g, match => '_' + match).toUpperCase();
|
|
3833
|
-
}
|
|
3834
|
-
static pascal2snakecase(text) {
|
|
3835
|
-
return text.replace(/([A-Z])/g, (match, offset) => offset ? '_' + match.toLowerCase() : match.toLowerCase());
|
|
3836
|
-
}
|
|
3837
|
-
static pascal2hyphencase(text) {
|
|
3838
|
-
return text.replace(/([A-Z])/g, (match, offset) => offset ? '-' + match.toLowerCase() : match.toLowerCase());
|
|
3839
|
-
}
|
|
3840
|
-
static pascal2camelcase(text) {
|
|
3841
|
-
return text.charAt(0).toLowerCase() + text.slice(1);
|
|
3842
|
-
}
|
|
3843
|
-
static pascal2constantcase(text) {
|
|
3844
|
-
return text.replace(/([A-Z])/g, (match, offset) => offset ? '_' + match : match).toUpperCase();
|
|
3845
|
-
}
|
|
3846
|
-
static snake2camelcase(text) {
|
|
3847
|
-
return text.replace(/(_\w)/g, match => match[1].toUpperCase());
|
|
3848
|
-
}
|
|
3849
|
-
static snake2hyphencase(text) {
|
|
3850
|
-
return text.replace(/_/g, "-");
|
|
3851
|
-
}
|
|
3852
|
-
static snake2pascalcase(text) {
|
|
3853
|
-
return text.split('_').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join('');
|
|
3854
|
-
}
|
|
3855
|
-
static snake2constantcase(text) {
|
|
3856
|
-
return text.toUpperCase();
|
|
3857
|
-
}
|
|
3858
|
-
static hyphen2camelcase(text) {
|
|
3859
|
-
return text.replace(/-([a-z])/g, match => match[1].toUpperCase());
|
|
3860
|
-
}
|
|
3861
|
-
static hyphen2snakecase(text) {
|
|
3862
|
-
return text.replace(/-/g, '_');
|
|
3863
|
-
}
|
|
3864
|
-
static hyphen2pascalcase(text) {
|
|
3865
|
-
return text.split('-').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join('');
|
|
3866
|
-
}
|
|
3867
|
-
static hyphen2constantcase(text) {
|
|
3868
|
-
return text.replace(/-/g, '_').toUpperCase();
|
|
3869
|
-
}
|
|
3870
|
-
static constant2camelcase(text) {
|
|
3871
|
-
return text.toLowerCase().replace(/_([a-z])/g, match => match[1].toUpperCase());
|
|
3872
|
-
}
|
|
3873
|
-
static constant2snakecase(text) {
|
|
3874
|
-
return text.toLowerCase();
|
|
3875
|
-
}
|
|
3876
|
-
static constant2pascalcase(text) {
|
|
3877
|
-
return text.toLowerCase().split('_').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join('');
|
|
3878
|
-
}
|
|
3879
|
-
static constant2hyphencase(text) {
|
|
3880
|
-
return text.toLowerCase().replace(/_/g, '-');
|
|
3881
|
-
}
|
|
3882
|
-
}
|
|
3883
|
-
const removeExtraSpace=str=>str.replace(/\s+/g,' ');
|
|
3884
|
-
const count=(str,value)=>str.split("").filter(x => x==value).length;
|
|
3885
|
-
const countWords=(str,value)=>str.split(" ").filter(x => x==value).length;
|
|
3886
|
-
const str=string=>new Str(string);
|
|
3887
|
-
|
|
3888
3800
|
class Matrix extends ZikoMath{
|
|
3889
3801
|
constructor(rows, cols, element = [] ) {
|
|
3890
3802
|
super();
|
|
@@ -4043,7 +3955,7 @@ class Matrix extends ZikoMath{
|
|
|
4043
3955
|
.mul(determinat(deleteRowAndColumn(M, i)))
|
|
4044
3956
|
);*/
|
|
4045
3957
|
//const to_be_added=Utils.add(Utils.mul(pow(-1, i),Utils.mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
|
|
4046
|
-
const to_be_added=Utils.add(Utils.mul(pow(-1, i),Utils.mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
|
|
3958
|
+
const to_be_added=Utils.add(Utils.mul(pow$1(-1, i),Utils.mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
|
|
4047
3959
|
answer=Utils.add(answer,to_be_added);
|
|
4048
3960
|
}
|
|
4049
3961
|
return answer;
|
|
@@ -4566,7 +4478,7 @@ class Complex extends ZikoMath{
|
|
|
4566
4478
|
}
|
|
4567
4479
|
else if(("a" in b && "z" in a)){
|
|
4568
4480
|
this.a=a.a;
|
|
4569
|
-
this.b=sqrt((a.z**2)-(a.a**2));
|
|
4481
|
+
this.b=sqrt$1((a.z**2)-(a.a**2));
|
|
4570
4482
|
}
|
|
4571
4483
|
else if(("a" in b && "phi" in a)){
|
|
4572
4484
|
this.a=a.a;
|
|
@@ -4574,15 +4486,15 @@ class Complex extends ZikoMath{
|
|
|
4574
4486
|
}
|
|
4575
4487
|
else if(("b" in b && "z" in a)){
|
|
4576
4488
|
this.b=a.b;
|
|
4577
|
-
this.a=sqrt((a.z**2)-(a.b**2));
|
|
4489
|
+
this.a=sqrt$1((a.z**2)-(a.b**2));
|
|
4578
4490
|
}
|
|
4579
4491
|
else if(("b" in b && "phi" in a)){
|
|
4580
4492
|
this.b=b;
|
|
4581
4493
|
this.a=a.b/tan(a.phi);
|
|
4582
4494
|
}
|
|
4583
4495
|
else if(("z" in b && "phi" in a)){
|
|
4584
|
-
this.a=a.z*cos(a.phi);
|
|
4585
|
-
this.a=a.z*sin(a.phi);
|
|
4496
|
+
this.a=a.z*cos$1(a.phi);
|
|
4497
|
+
this.a=a.z*sin$1(a.phi);
|
|
4586
4498
|
}
|
|
4587
4499
|
}
|
|
4588
4500
|
else if(typeof(a)==="number"&&typeof(b)==="number"){
|
|
@@ -4622,7 +4534,7 @@ class Complex extends ZikoMath{
|
|
|
4622
4534
|
return new Complex(this.a, -this.b);
|
|
4623
4535
|
}
|
|
4624
4536
|
get inv() {
|
|
4625
|
-
return new Complex(this.a / (pow(this.a, 2) + pow(this.b, 2)), -this.b / (pow(this.a, 2) + pow(this.b, 2)));
|
|
4537
|
+
return new Complex(this.a / (pow$1(this.a, 2) + pow$1(this.b, 2)), -this.b / (pow$1(this.a, 2) + pow$1(this.b, 2)));
|
|
4626
4538
|
}
|
|
4627
4539
|
add(...z) {
|
|
4628
4540
|
for (let i = 0; i < z.length; i++) {
|
|
@@ -4650,8 +4562,8 @@ class Complex extends ZikoMath{
|
|
|
4650
4562
|
}
|
|
4651
4563
|
let Z=+prod(this.z,...z.map(n=>n.z)).toFixed(15);
|
|
4652
4564
|
let phi=+sum(this.phi,...z.map(n=>n.phi)).toFixed(15);
|
|
4653
|
-
this.a=+(Z*cos(phi).toFixed(15)).toFixed(14);
|
|
4654
|
-
this.b=+(Z*sin(phi).toFixed(15)).toFixed(14);
|
|
4565
|
+
this.a=+(Z*cos$1(phi).toFixed(15)).toFixed(14);
|
|
4566
|
+
this.b=+(Z*sin$1(phi).toFixed(15)).toFixed(14);
|
|
4655
4567
|
return this;
|
|
4656
4568
|
}
|
|
4657
4569
|
div(...z) {
|
|
@@ -4660,23 +4572,23 @@ class Complex extends ZikoMath{
|
|
|
4660
4572
|
}
|
|
4661
4573
|
let Z=+(this.z/prod(...z.map(n=>n.z))).toFixed(15);
|
|
4662
4574
|
let phi=+(this.phi-sum(...z.map(n=>n.phi))).toFixed(15);
|
|
4663
|
-
this.a=+(Z*cos(phi).toFixed(15)).toFixed(15);
|
|
4664
|
-
this.b=+(Z*sin(phi).toFixed(15)).toFixed(15);
|
|
4575
|
+
this.a=+(Z*cos$1(phi).toFixed(15)).toFixed(15);
|
|
4576
|
+
this.b=+(Z*sin$1(phi).toFixed(15)).toFixed(15);
|
|
4665
4577
|
return this;
|
|
4666
4578
|
}
|
|
4667
4579
|
pow(n) {
|
|
4668
4580
|
if (floor(n) === n && n > 0) {
|
|
4669
4581
|
let z=+(this.z**n).toFixed(15);
|
|
4670
4582
|
let phi=+(this.phi*n).toFixed(15);
|
|
4671
|
-
this.a=+(z*cos(phi).toFixed(15)).toFixed(15);
|
|
4672
|
-
this.b=+(z*sin(phi).toFixed(15)).toFixed(15);
|
|
4583
|
+
this.a=+(z*cos$1(phi).toFixed(15)).toFixed(15);
|
|
4584
|
+
this.b=+(z*sin$1(phi).toFixed(15)).toFixed(15);
|
|
4673
4585
|
}
|
|
4674
4586
|
return this;
|
|
4675
4587
|
}
|
|
4676
4588
|
static fromExpo(z, phi) {
|
|
4677
4589
|
return new Complex(
|
|
4678
|
-
+(z * cos(phi)).toFixed(13),
|
|
4679
|
-
+(z * sin(phi)).toFixed(13)
|
|
4590
|
+
+(z * cos$1(phi)).toFixed(13),
|
|
4591
|
+
+(z * sin$1(phi)).toFixed(13)
|
|
4680
4592
|
);
|
|
4681
4593
|
}
|
|
4682
4594
|
get expo() {
|
|
@@ -4698,10 +4610,10 @@ class Complex extends ZikoMath{
|
|
|
4698
4610
|
return z.clone.pow(n);
|
|
4699
4611
|
}
|
|
4700
4612
|
static xpowZ(x){
|
|
4701
|
-
return complex((x**this.a)*cos(this.b*ln(x)),(x**this.a)*sin(this.b*ln(x)));
|
|
4613
|
+
return complex((x**this.a)*cos$1(this.b*ln(x)),(x**this.a)*sin$1(this.b*ln(x)));
|
|
4702
4614
|
}
|
|
4703
4615
|
sqrtn(n=2){
|
|
4704
|
-
return complex(sqrtn(this.z,n)*cos(this.phi/n),sqrtn(this.z,n)*sin(this.phi/n));
|
|
4616
|
+
return complex(sqrtn(this.z,n)*cos$1(this.phi/n),sqrtn(this.z,n)*sin$1(this.phi/n));
|
|
4705
4617
|
}
|
|
4706
4618
|
get sqrt(){
|
|
4707
4619
|
return this.sqrtn(2);
|
|
@@ -4710,14 +4622,14 @@ class Complex extends ZikoMath{
|
|
|
4710
4622
|
return complex(this.z,this.phi);
|
|
4711
4623
|
}
|
|
4712
4624
|
get cos(){
|
|
4713
|
-
return complex(cos(this.a)*cosh(this.b),sin(this.a)*sinh(this.b))
|
|
4625
|
+
return complex(cos$1(this.a)*cosh(this.b),sin$1(this.a)*sinh(this.b))
|
|
4714
4626
|
}
|
|
4715
4627
|
get sin(){
|
|
4716
|
-
return complex(sin(this.a)*cosh(this.b),cos(this.a)*sinh(this.b))
|
|
4628
|
+
return complex(sin$1(this.a)*cosh(this.b),cos$1(this.a)*sinh(this.b))
|
|
4717
4629
|
}
|
|
4718
4630
|
get tan(){
|
|
4719
|
-
const de=cos(this.a*2)+cosh(this.b*2);
|
|
4720
|
-
return complex(sin(2*this.a)/de,sinh(2*this.b)/de);
|
|
4631
|
+
const de=cos$1(this.a*2)+cosh(this.b*2);
|
|
4632
|
+
return complex(sin$1(2*this.a)/de,sinh(2*this.b)/de);
|
|
4721
4633
|
}
|
|
4722
4634
|
printInConsole() {
|
|
4723
4635
|
let string = this.a + " + " + this.b + " * i";
|
|
@@ -4748,12 +4660,12 @@ const complex=(a,b)=>{
|
|
|
4748
4660
|
// } from "../calculus/index.js";
|
|
4749
4661
|
|
|
4750
4662
|
const abs=(...x)=>mapfun$1(Math.abs,...x);
|
|
4751
|
-
const sqrt=(...x)=>mapfun$1(Math.sqrt,...x);
|
|
4752
|
-
const pow=(x,n)=>{
|
|
4663
|
+
const sqrt$1=(...x)=>mapfun$1(Math.sqrt,...x);
|
|
4664
|
+
const pow$1=(x,n)=>{
|
|
4753
4665
|
if(typeof x === "number"){
|
|
4754
4666
|
if(typeof n === "number")return Math.pow(x,n);
|
|
4755
4667
|
else if(n instanceof Complex)return Complex.fromExpo(x**n.a,n.b*ln(x))
|
|
4756
|
-
else return mapfun$1(a=>pow(x,a),...n);
|
|
4668
|
+
else return mapfun$1(a=>pow$1(x,a),...n);
|
|
4757
4669
|
}
|
|
4758
4670
|
else if(x instanceof Complex){
|
|
4759
4671
|
if(typeof n === "number")return Complex.fromExpo(x.z**n,x.phi*n);
|
|
@@ -4761,14 +4673,14 @@ const pow=(x,n)=>{
|
|
|
4761
4673
|
x.z**n.a*e(-x.phi*n.b),
|
|
4762
4674
|
ln(x.z)*n.b+n.a*x.phi
|
|
4763
4675
|
)
|
|
4764
|
-
else return mapfun$1(a=>pow(x,a),...n);
|
|
4676
|
+
else return mapfun$1(a=>pow$1(x,a),...n);
|
|
4765
4677
|
}
|
|
4766
4678
|
else if(x instanceof Array){
|
|
4767
|
-
if(typeof n === "number") return mapfun$1(a=>pow(a,n),...x);
|
|
4679
|
+
if(typeof n === "number") return mapfun$1(a=>pow$1(a,n),...x);
|
|
4768
4680
|
else if(n instanceof Array){
|
|
4769
4681
|
const Y=[];
|
|
4770
4682
|
for(let i=0;i<x.length;i++){
|
|
4771
|
-
Y.push(mapfun$1(a=>pow(x[i],a),...n));
|
|
4683
|
+
Y.push(mapfun$1(a=>pow$1(x[i],a),...n));
|
|
4772
4684
|
}
|
|
4773
4685
|
return Y;
|
|
4774
4686
|
}
|
|
@@ -4796,14 +4708,14 @@ const sqrtn=(x,n)=>{
|
|
|
4796
4708
|
};
|
|
4797
4709
|
const e=(...x) => mapfun$1(Math.exp,...x);
|
|
4798
4710
|
const ln=(...x) => mapfun$1(Math.log,...x);
|
|
4799
|
-
const cos=(...x) => mapfun$1(Fixed.cos,...x);
|
|
4800
|
-
const sin=(...x) => mapfun$1(Fixed.sin,...x);
|
|
4711
|
+
const cos$1=(...x) => mapfun$1(Fixed.cos,...x);
|
|
4712
|
+
const sin$1=(...x) => mapfun$1(Fixed.sin,...x);
|
|
4801
4713
|
const tan=(...x) => mapfun$1(Fixed.tan,...x);
|
|
4802
4714
|
const sec=(...x) => mapfun$1(Fixed.sec,...x);
|
|
4803
4715
|
const sinc=(...x) => mapfun$1(Fixed.sinc,...x);
|
|
4804
4716
|
const csc=(...x) => mapfun$1(Fixed.csc,...x);
|
|
4805
4717
|
const cot=(...x) => mapfun$1(Fixed.cot,...x);
|
|
4806
|
-
const acos=(...x) => mapfun$1(Fixed.acos,...x);
|
|
4718
|
+
const acos$1=(...x) => mapfun$1(Fixed.acos,...x);
|
|
4807
4719
|
const asin=(...x) => mapfun$1(Fixed.asin,...x);
|
|
4808
4720
|
const atan=(...x) => mapfun$1(Fixed.atan,...x);
|
|
4809
4721
|
const acot=(...x) => mapfun$1(Fixed.acot,...x);
|
|
@@ -4831,7 +4743,7 @@ const atan2=(x,y,rad=true)=>{
|
|
|
4831
4743
|
else if(y instanceof Array){
|
|
4832
4744
|
const Y=[];
|
|
4833
4745
|
for(let i=0;i<x.length;i++){
|
|
4834
|
-
Y.push(mapfun$1(a=>pow(x[i],a),...y));
|
|
4746
|
+
Y.push(mapfun$1(a=>pow$1(x[i],a),...y));
|
|
4835
4747
|
}
|
|
4836
4748
|
return Y;
|
|
4837
4749
|
}
|
|
@@ -4857,229 +4769,469 @@ const hypot=(...x)=>{
|
|
|
4857
4769
|
)
|
|
4858
4770
|
};
|
|
4859
4771
|
|
|
4860
|
-
|
|
4861
|
-
|
|
4772
|
+
const {PI, sqrt, cos, sin, acos, pow} = Math;
|
|
4773
|
+
|
|
4774
|
+
const Linear = t => t;
|
|
4775
|
+
const InSin = t => 1 - cos((t * PI) / 2);
|
|
4776
|
+
const OutSin = t => sin((t * PI) / 2);
|
|
4777
|
+
const InOutSin = t => -(cos(PI * t) - 1) / 2;
|
|
4778
|
+
|
|
4779
|
+
const InQuad = t => t**2;
|
|
4780
|
+
const OutQuad = t => 1 - (1-t)**2;
|
|
4781
|
+
const InOutQuad = t => t < 0.5 ? 2 * (t**2) : 1 - (-2 * t + 2)**2 / 2;
|
|
4782
|
+
|
|
4783
|
+
const InCubic = t => t**3;
|
|
4784
|
+
const OutCubic = t => 1 - (1-t)**3;
|
|
4785
|
+
const InOutCubic = t => t < 0.5 ? 4 * (t**3) : 1 - (-2 * t + 2)**3 / 2;
|
|
4786
|
+
|
|
4787
|
+
const InQuart = t => t**4;
|
|
4788
|
+
const OutQuart = t => 1 - (1-t)**4;
|
|
4789
|
+
const InOutQuart = t => t < 0.5 ? 8 * (t**4) : 1 - (-2 * t + 2)**4 / 2;
|
|
4790
|
+
|
|
4791
|
+
const InQuint = t => t**5;
|
|
4792
|
+
const OutQuint = t => 1 - (1-t)**5;
|
|
4793
|
+
const InOutQuint = t => t < 0.5 ? 16 * (t**5) : 1 - (-2 * t + 2)**5 / 2;
|
|
4794
|
+
|
|
4795
|
+
const InExpo = t => t === 0 ? 0 : 2**(10*t - 10);
|
|
4796
|
+
const OutExpo = t => t === 1 ? 1 : 1 - 2**(-10 * t);
|
|
4797
|
+
const InOutExpo = t => t === 0? 0: t === 1? 1: t < 0.5 ? 2**(20 * t - 10) / 2: (2 - 2**(-20 * t + 10)) / 2;
|
|
4798
|
+
|
|
4799
|
+
const InCirc = t => 1 - sqrt(1 - t**2);
|
|
4800
|
+
const OutCirc = t => sqrt(1 - (t-1)**2);
|
|
4801
|
+
const InOutCirc = t => t < 0.5? (1 - sqrt(1 - (2*t)**2)) / 2: (sqrt(1 - (-2*t+2)**2) + 1) / 2;
|
|
4802
|
+
|
|
4803
|
+
const Arc = t => 1 - sin(acos(t));
|
|
4804
|
+
const Back = (t, x = 1) => (t**2) * ((x+1)*t - x);
|
|
4805
|
+
const Elastic = t => -2*pow(2, 10 * (t - 1)) * cos(20 * PI * t / 3 * t);
|
|
4806
|
+
|
|
4807
|
+
const InBack = (t, c1 = 1.70158, c3 = c1 + 1) => c3 * pow(t,3)- c1 * (t**2);
|
|
4808
|
+
const OutBack = (t, c1 = 1.70158, c3 = c1 + 1) => 1 + c3 * pow(t - 1, 3) + c1 * pow(t - 1, 2);
|
|
4809
|
+
const InOutBack = (t, c1 = 1.70158, c2 = c1 * 1.525) => t < 0.5 ? (pow(2 * t, 2) * ((c2 + 1) * 2 * t - c2)) / 2 : (pow(2 * t - 2, 2) * ((c2 + 1) * (t * 2 - 2) + c2) + 2) / 2;
|
|
4810
|
+
|
|
4811
|
+
const InElastic = (t, c4 = 2*PI/3) => {
|
|
4812
|
+
return t === 0
|
|
4813
|
+
? 0
|
|
4814
|
+
: t === 1
|
|
4815
|
+
? 1
|
|
4816
|
+
: -pow(2, 10 * t - 10) * sin((t * 10 - 10.75) * c4);
|
|
4817
|
+
};
|
|
4818
|
+
|
|
4819
|
+
const OutElastic = (t, c4 = 2*PI/3) => {
|
|
4820
|
+
return t === 0
|
|
4821
|
+
? 0
|
|
4822
|
+
: t === 1
|
|
4823
|
+
? 1
|
|
4824
|
+
: pow(2, -10 * t) * sin((t * 10 - 0.75) * c4) + 1;
|
|
4825
|
+
};
|
|
4826
|
+
const InOutElastic = (t, c5 = 2 * PI / 4.5) => {
|
|
4827
|
+
return t === 0
|
|
4828
|
+
? 0
|
|
4829
|
+
: t === 1
|
|
4830
|
+
? 1
|
|
4831
|
+
: t < 0.5
|
|
4832
|
+
? -(pow(2, 20 * t - 10) * sin((20 * t - 11.125) * c5)) / 2
|
|
4833
|
+
: (pow(2, -20 * t + 10) * sin((20 * t - 11.125) * c5)) / 2 + 1;
|
|
4834
|
+
};
|
|
4835
|
+
|
|
4836
|
+
const InBounce = (t, n1 = 7.5625, d1 = 2.75) => 1 - OutBounce(1-t, n1, d1);
|
|
4837
|
+
const OutBounce = (t, n1 = 7.5625, d1 = 2.75) => {
|
|
4838
|
+
if(t<1/d1) return n1 * t * t;
|
|
4839
|
+
if(t < 2 / d1) return n1 * (t -= 1.5 / d1) * t + 0.75;
|
|
4840
|
+
if(t < 2.5 / d1) return n1 * (t -= 2.25 / d1) * t + 0.9375;
|
|
4841
|
+
return n1 * (t -= 2.625 / d1) * t + 0.984375;
|
|
4842
|
+
};
|
|
4843
|
+
|
|
4844
|
+
const InOutBounce = (t, n1 = 7.5625, d1 = 2.75) => t < 0.5 ? OutBounce(1 - 2 * t, n1, d1)/2 : OutBounce(2 * t - 1, n1, d1)/2;
|
|
4845
|
+
|
|
4846
|
+
|
|
4847
|
+
const Step = (t, steps = 5) => Math.floor(t*steps) / steps;
|
|
4848
|
+
const Discret = (t, segments = 5) => Math.ceil(t*segments) / segments;
|
|
4849
|
+
|
|
4850
|
+
class TimeAnimation {
|
|
4851
|
+
constructor(callback, { ease = Linear, step = 50, t0 = 0, start = true, duration = 3000 } = {}) {
|
|
4862
4852
|
this.callback = callback;
|
|
4863
|
-
this.
|
|
4853
|
+
this.state = {
|
|
4864
4854
|
isRunning: false,
|
|
4865
|
-
|
|
4866
|
-
|
|
4855
|
+
animationId: null,
|
|
4856
|
+
startTime: null,
|
|
4857
|
+
ease,
|
|
4867
4858
|
step,
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
started
|
|
4859
|
+
// interval: [t0, t1],
|
|
4860
|
+
autoStart: start,
|
|
4861
|
+
duration
|
|
4872
4862
|
};
|
|
4873
|
-
|
|
4874
|
-
this.
|
|
4863
|
+
|
|
4864
|
+
this.t = 0; // elapsed time
|
|
4865
|
+
this.tx = 0; // normalized [0,1]
|
|
4866
|
+
this.ty = 0; // eased value
|
|
4867
|
+
this.i = 0; // frame index
|
|
4868
|
+
|
|
4869
|
+
if (this.state.autoStart) {
|
|
4870
|
+
this.start();
|
|
4871
|
+
}
|
|
4875
4872
|
}
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4873
|
+
|
|
4874
|
+
// ---- private loop handler ----
|
|
4875
|
+
#tick = () => {
|
|
4876
|
+
this.t += this.state.step;
|
|
4877
|
+
this.i++;
|
|
4878
|
+
|
|
4879
|
+
this.tx = map(this.t, 0, this.state.duration, 0, 1);
|
|
4880
|
+
this.ty = this.state.ease(this.tx);
|
|
4881
|
+
|
|
4882
|
+
this.callback(this);
|
|
4883
|
+
|
|
4884
|
+
if (this.t >= this.state.duration) {
|
|
4885
|
+
clearInterval(this.state.animationId);
|
|
4886
|
+
this.state.isRunning = false;
|
|
4887
|
+
}
|
|
4888
|
+
};
|
|
4889
|
+
|
|
4890
|
+
// ---- core runner ----
|
|
4891
|
+
#run(reset = true) {
|
|
4892
|
+
if (!this.state.isRunning) {
|
|
4893
|
+
if (reset) this.reset(false);
|
|
4894
|
+
|
|
4895
|
+
this.state.isRunning = true;
|
|
4896
|
+
this.state.startTime = Date.now();
|
|
4897
|
+
this.state.animationId = setInterval(this.#tick, this.state.step);
|
|
4884
4898
|
}
|
|
4885
4899
|
return this;
|
|
4886
4900
|
}
|
|
4887
|
-
|
|
4888
|
-
//
|
|
4889
|
-
|
|
4890
|
-
|
|
4901
|
+
|
|
4902
|
+
// ---- lifecycle methods ----
|
|
4903
|
+
start() {
|
|
4904
|
+
return this.#run(true);
|
|
4905
|
+
}
|
|
4906
|
+
|
|
4907
|
+
pause() {
|
|
4908
|
+
if (this.state.isRunning) {
|
|
4909
|
+
clearInterval(this.state.animationId);
|
|
4910
|
+
this.state.isRunning = false;
|
|
4911
|
+
}
|
|
4912
|
+
return this;
|
|
4913
|
+
}
|
|
4914
|
+
|
|
4915
|
+
resume() {
|
|
4916
|
+
return this.#run(false);
|
|
4917
|
+
}
|
|
4918
|
+
|
|
4919
|
+
stop() {
|
|
4920
|
+
this.pause();
|
|
4921
|
+
this.reset(false);
|
|
4922
|
+
return this;
|
|
4923
|
+
}
|
|
4924
|
+
|
|
4925
|
+
reset(restart = true) {
|
|
4926
|
+
this.t = 0;
|
|
4927
|
+
this.tx = 0;
|
|
4928
|
+
this.ty = 0;
|
|
4929
|
+
this.i = 0;
|
|
4930
|
+
|
|
4931
|
+
if (restart) this.start();
|
|
4932
|
+
return this;
|
|
4933
|
+
}
|
|
4934
|
+
}
|
|
4935
|
+
|
|
4936
|
+
// Hook-style factory
|
|
4937
|
+
const animation = (callback, {ease, t0, t1, start, duration} = {}) =>
|
|
4938
|
+
new TimeAnimation(callback, {ease, t0, t1, start, duration});
|
|
4939
|
+
|
|
4940
|
+
class Tick {
|
|
4941
|
+
constructor(ms, fn) {
|
|
4942
|
+
this.ms = ms;
|
|
4943
|
+
this.fn = fn;
|
|
4944
|
+
this.id = null;
|
|
4945
|
+
this.running = false;
|
|
4946
|
+
}
|
|
4947
|
+
|
|
4948
|
+
start() {
|
|
4949
|
+
if (!this.running) {
|
|
4950
|
+
this.running = true;
|
|
4951
|
+
this.id = setInterval(this.fn, this.ms);
|
|
4952
|
+
}
|
|
4953
|
+
return this;
|
|
4954
|
+
}
|
|
4955
|
+
|
|
4956
|
+
stop() {
|
|
4957
|
+
if (this.running) {
|
|
4958
|
+
this.running = false;
|
|
4959
|
+
clearInterval(this.id);
|
|
4960
|
+
this.id = null;
|
|
4961
|
+
}
|
|
4962
|
+
return this;
|
|
4963
|
+
}
|
|
4964
|
+
|
|
4965
|
+
isRunning() {
|
|
4966
|
+
return this.running;
|
|
4967
|
+
}
|
|
4968
|
+
}
|
|
4969
|
+
const tick = (ms, fn) => new Tick(ms, fn);
|
|
4970
|
+
|
|
4971
|
+
class Clock extends Tick {
|
|
4972
|
+
constructor(tickMs = 1000 / 60) {
|
|
4973
|
+
super(tickMs, () => this._tick());
|
|
4974
|
+
this.elapsed = 0;
|
|
4975
|
+
this._lastTime = performance.now();
|
|
4976
|
+
this._callbacks = new Set();
|
|
4977
|
+
}
|
|
4978
|
+
|
|
4979
|
+
_tick() {
|
|
4980
|
+
const now = performance.now();
|
|
4981
|
+
const delta = now - this._lastTime;
|
|
4982
|
+
this.elapsed += delta;
|
|
4983
|
+
this._lastTime = now;
|
|
4984
|
+
|
|
4985
|
+
for (const cb of this._callbacks) {
|
|
4986
|
+
cb({ elapsed: this.elapsed, delta });
|
|
4987
|
+
}
|
|
4988
|
+
}
|
|
4989
|
+
|
|
4990
|
+
onTick(cb) {
|
|
4991
|
+
this._callbacks.add(cb);
|
|
4992
|
+
return () => this._callbacks.delete(cb);
|
|
4993
|
+
}
|
|
4994
|
+
|
|
4995
|
+
reset() {
|
|
4996
|
+
this.elapsed = 0;
|
|
4997
|
+
this._lastTime = performance.now();
|
|
4998
|
+
}
|
|
4999
|
+
|
|
5000
|
+
pause() {
|
|
5001
|
+
super.stop();
|
|
5002
|
+
}
|
|
5003
|
+
|
|
5004
|
+
resume() {
|
|
5005
|
+
this._lastTime = performance.now();
|
|
5006
|
+
super.start();
|
|
5007
|
+
}
|
|
5008
|
+
}
|
|
5009
|
+
|
|
5010
|
+
const clock = (tickMs) => new Clock(tickMs);
|
|
5011
|
+
|
|
5012
|
+
|
|
5013
|
+
/*
|
|
5014
|
+
|
|
5015
|
+
const clock = new Clock(200);
|
|
5016
|
+
|
|
5017
|
+
clock.onTick(({ elapsed, delta }) => {
|
|
5018
|
+
console.log(`Elapsed: ${elapsed.toFixed(0)}ms, Delta: ${delta.toFixed(0)}ms`);
|
|
5019
|
+
});
|
|
5020
|
+
|
|
5021
|
+
clock.start();
|
|
5022
|
+
|
|
5023
|
+
setTimeout(() => clock.pause(), 1000);
|
|
5024
|
+
setTimeout(() => clock.resume(), 2000);
|
|
5025
|
+
|
|
5026
|
+
*/
|
|
5027
|
+
|
|
5028
|
+
class TimeScheduler {
|
|
5029
|
+
constructor(tasks = [], { repeat = 1, loop = false } = {}) {
|
|
5030
|
+
this.tasks = tasks;
|
|
5031
|
+
this.repeat = repeat;
|
|
5032
|
+
this.loop = loop;
|
|
5033
|
+
|
|
5034
|
+
this.stopped = false;
|
|
5035
|
+
this.running = false;
|
|
5036
|
+
|
|
5037
|
+
// lifecycle hooks
|
|
5038
|
+
this.onStart = null;
|
|
5039
|
+
this.onTask = null;
|
|
5040
|
+
this.onEnd = null;
|
|
5041
|
+
}
|
|
5042
|
+
|
|
5043
|
+
async run() {
|
|
5044
|
+
if (this.running) return;
|
|
5045
|
+
this.running = true;
|
|
5046
|
+
this.stopped = false;
|
|
5047
|
+
|
|
5048
|
+
if (this.onStart) this.onStart();
|
|
5049
|
+
|
|
5050
|
+
let repeatCount = this.repeat;
|
|
5051
|
+
|
|
5052
|
+
do {
|
|
5053
|
+
for (const task of this.tasks) {
|
|
5054
|
+
if (this.stopped) return;
|
|
5055
|
+
|
|
5056
|
+
if (Array.isArray(task)) {
|
|
5057
|
+
// Parallel tasks
|
|
5058
|
+
await Promise.all(
|
|
5059
|
+
task.map(({ fn, delay = 0 }) =>
|
|
5060
|
+
new Promise(async (resolve) => {
|
|
5061
|
+
if (delay > 0) await new Promise(r => setTimeout(r, delay));
|
|
5062
|
+
if (this.onTask) this.onTask(fn);
|
|
5063
|
+
await fn();
|
|
5064
|
+
resolve();
|
|
5065
|
+
})
|
|
5066
|
+
)
|
|
5067
|
+
);
|
|
5068
|
+
} else {
|
|
5069
|
+
// Single task
|
|
5070
|
+
const { fn, delay = 0 } = task;
|
|
5071
|
+
if (delay > 0) await new Promise(r => setTimeout(r, delay));
|
|
5072
|
+
if (this.onTask) this.onTask(fn);
|
|
5073
|
+
await fn();
|
|
5074
|
+
}
|
|
5075
|
+
}
|
|
5076
|
+
} while (this.loop && !this.stopped && (repeatCount === Infinity || repeatCount-- > 1));
|
|
5077
|
+
|
|
5078
|
+
if (!this.stopped && this.onEnd) this.onEnd();
|
|
5079
|
+
this.running = false;
|
|
5080
|
+
}
|
|
5081
|
+
|
|
5082
|
+
stop() {
|
|
5083
|
+
this.stopped = true;
|
|
5084
|
+
this.running = false;
|
|
5085
|
+
}
|
|
5086
|
+
|
|
5087
|
+
addTask(task) {
|
|
5088
|
+
this.tasks.push(task);
|
|
5089
|
+
}
|
|
5090
|
+
|
|
5091
|
+
clearTasks() {
|
|
5092
|
+
this.tasks = [];
|
|
5093
|
+
}
|
|
5094
|
+
}
|
|
5095
|
+
|
|
5096
|
+
const Scheduler = (tasks, { repeat = null} = {}) => new TimeScheduler(tasks, { repeat});
|
|
5097
|
+
|
|
5098
|
+
const step_fps = (step_or_fps) => 1000 / step_or_fps;
|
|
5099
|
+
|
|
5100
|
+
const debounce=(fn,delay=1000)=>{
|
|
5101
|
+
return (...args) => setTimeout(()=>fn(...args),delay);
|
|
5102
|
+
};
|
|
5103
|
+
const throttle=(fn,delay)=>{
|
|
5104
|
+
let lastTime=0;
|
|
5105
|
+
return (...args) => {
|
|
5106
|
+
const now = new Date().getTime();
|
|
5107
|
+
if(now-lastTime < delay) return;
|
|
5108
|
+
lastTime = now;
|
|
5109
|
+
fn(...args);
|
|
5110
|
+
}
|
|
5111
|
+
};
|
|
5112
|
+
|
|
5113
|
+
function timeout(ms, fn) {
|
|
5114
|
+
let id;
|
|
5115
|
+
const promise = new Promise((resolve) => {
|
|
5116
|
+
id = setTimeout(() => {
|
|
5117
|
+
if (fn) fn();
|
|
5118
|
+
resolve();
|
|
5119
|
+
}, ms);
|
|
5120
|
+
});
|
|
5121
|
+
|
|
5122
|
+
return {
|
|
5123
|
+
id,
|
|
5124
|
+
clear: () => clearTimeout(id),
|
|
5125
|
+
promise
|
|
5126
|
+
};
|
|
5127
|
+
}
|
|
5128
|
+
|
|
5129
|
+
const sleep= ms => new Promise(res => setTimeout(res, ms));
|
|
5130
|
+
|
|
5131
|
+
// use it with await
|
|
5132
|
+
|
|
5133
|
+
class TimeLoop {
|
|
5134
|
+
constructor(callback, { step = 1000, t0 = 0, t1 = Infinity, autoplay = true } = {}) {
|
|
5135
|
+
this.callback = callback;
|
|
5136
|
+
this.cache = {
|
|
5137
|
+
isRunning: false,
|
|
5138
|
+
id: null,
|
|
5139
|
+
last_tick: null,
|
|
5140
|
+
step,
|
|
5141
|
+
t0,
|
|
5142
|
+
t1,
|
|
5143
|
+
autoplay,
|
|
5144
|
+
pauseTime: null,
|
|
5145
|
+
frame : 0,
|
|
5146
|
+
};
|
|
5147
|
+
|
|
5148
|
+
if (autoplay) {
|
|
5149
|
+
t0 ? this.startAfter(t0) : this.start();
|
|
5150
|
+
if (t1 !== Infinity) this.stopAfter(t1);
|
|
5151
|
+
}
|
|
5152
|
+
}
|
|
5153
|
+
|
|
5154
|
+
get frame(){
|
|
5155
|
+
return this.cache.frame;
|
|
5156
|
+
}
|
|
5157
|
+
get elapsed(){
|
|
5158
|
+
return this.cache.elapsed;
|
|
5159
|
+
}
|
|
5160
|
+
|
|
4891
5161
|
start() {
|
|
4892
5162
|
if (!this.cache.isRunning) {
|
|
4893
|
-
this.
|
|
5163
|
+
this.cache.frame = 0;
|
|
4894
5164
|
this.cache.isRunning = true;
|
|
4895
|
-
this.cache.
|
|
5165
|
+
this.cache.last_tick = Date.now();
|
|
4896
5166
|
this.animate();
|
|
4897
5167
|
}
|
|
4898
5168
|
return this;
|
|
4899
5169
|
}
|
|
5170
|
+
|
|
4900
5171
|
pause() {
|
|
4901
5172
|
if (this.cache.isRunning) {
|
|
4902
|
-
clearTimeout(this.cache.
|
|
5173
|
+
clearTimeout(this.cache.id);
|
|
4903
5174
|
this.cache.isRunning = false;
|
|
5175
|
+
this.cache.pauseTime = Date.now();
|
|
4904
5176
|
}
|
|
4905
5177
|
return this;
|
|
4906
5178
|
}
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
this.
|
|
5179
|
+
|
|
5180
|
+
resume() {
|
|
5181
|
+
if (!this.cache.isRunning) {
|
|
5182
|
+
this.cache.isRunning = true;
|
|
5183
|
+
if (this.cache.pauseTime) {
|
|
5184
|
+
// adjust start time so delta stays consistent
|
|
5185
|
+
const pausedDuration = Date.now() - this.cache.pauseTime;
|
|
5186
|
+
this.cache.last_tick += pausedDuration;
|
|
5187
|
+
}
|
|
5188
|
+
this.animate();
|
|
5189
|
+
}
|
|
4910
5190
|
return this;
|
|
4911
5191
|
}
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
this.
|
|
5192
|
+
|
|
5193
|
+
stop() {
|
|
5194
|
+
this.pause();
|
|
5195
|
+
this.cache.frame = 0;
|
|
4915
5196
|
return this;
|
|
4916
5197
|
}
|
|
4917
|
-
|
|
4918
|
-
|
|
5198
|
+
|
|
5199
|
+
startAfter(t = 1000) {
|
|
5200
|
+
setTimeout(() => this.start(), t);
|
|
4919
5201
|
return this;
|
|
4920
5202
|
}
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
5203
|
+
|
|
5204
|
+
stopAfter(t = 1000) {
|
|
5205
|
+
setTimeout(() => this.stop(), t);
|
|
5206
|
+
return this;
|
|
4924
5207
|
}
|
|
5208
|
+
|
|
4925
5209
|
animate = () => {
|
|
4926
5210
|
if (this.cache.isRunning) {
|
|
4927
5211
|
const now = Date.now();
|
|
4928
|
-
const delta = now - this.cache.
|
|
4929
|
-
|
|
5212
|
+
const delta = now - this.cache.last_tick;
|
|
5213
|
+
|
|
5214
|
+
if (delta >= this.cache.step) {
|
|
5215
|
+
this.cache.elapsed = now - (this.cache.t0 || 0);
|
|
4930
5216
|
this.callback(this);
|
|
4931
|
-
this.
|
|
4932
|
-
this.cache.
|
|
5217
|
+
this.cache.frame++;
|
|
5218
|
+
this.cache.last_tick = now - (delta % this.cache.step);
|
|
4933
5219
|
}
|
|
4934
|
-
this.cache.AnimationId = setTimeout(this.animate, 0);
|
|
4935
|
-
} }
|
|
4936
|
-
}
|
|
4937
|
-
const useFps = fps => 1000/fps;
|
|
4938
|
-
const useTimeLoop = (callback, step, startTime, endTime, started) => new ZikoTimeLoop(callback, step, startTime, endTime, started);
|
|
4939
|
-
|
|
4940
|
-
const Ease={
|
|
4941
|
-
Linear:function(t){
|
|
4942
|
-
return t;
|
|
4943
|
-
},
|
|
4944
|
-
InSin(t){
|
|
4945
|
-
return 1 - Math.cos((t * Math.PI) / 2);
|
|
4946
|
-
},
|
|
4947
|
-
OutSin(t){
|
|
4948
|
-
return Math.sin((t * Math.PI) / 2);
|
|
4949
|
-
},
|
|
4950
|
-
InOutSin(t){
|
|
4951
|
-
return -(Math.cos(Math.PI * t) - 1) / 2;
|
|
4952
|
-
},
|
|
4953
|
-
InQuad(t){
|
|
4954
|
-
return t**2;
|
|
4955
|
-
},
|
|
4956
|
-
OutQuad(t){
|
|
4957
|
-
return 1 - Math.pow((1 - t),2)
|
|
4958
|
-
},
|
|
4959
|
-
InOutQuad(t){
|
|
4960
|
-
return t < 0.5 ? 2 * Math.pow(t,2) : 1 - Math.pow(-2 * t + 2, 2) / 2;
|
|
4961
|
-
},
|
|
4962
|
-
InCubic(t){
|
|
4963
|
-
return t**3;
|
|
4964
|
-
},
|
|
4965
|
-
OutCubic(t){
|
|
4966
|
-
return 1 - Math.pow((1 - t),3)
|
|
4967
|
-
},
|
|
4968
|
-
InOutCubic(t){
|
|
4969
|
-
return t < 0.5 ? 4 * Math.pow(t,3) : 1 - Math.pow(-2 * t + 2, 3) / 2;
|
|
4970
|
-
},
|
|
4971
|
-
InQuart(t){
|
|
4972
|
-
return t**4;
|
|
4973
|
-
},
|
|
4974
|
-
OutQuart(t){
|
|
4975
|
-
return 1 - Math.pow((1 - t),4);
|
|
4976
|
-
},
|
|
4977
|
-
InOutQuart(t){
|
|
4978
|
-
return t < 0.5 ? 8 * Math.pow(t,4) : 1 - Math.pow(-2 * t + 2, 4) / 2;
|
|
4979
|
-
},
|
|
4980
|
-
InQuint(t){
|
|
4981
|
-
return t**5;
|
|
4982
|
-
},
|
|
4983
|
-
OutQuint(t){
|
|
4984
|
-
return 1 - Math.pow((1 - t),5);
|
|
4985
|
-
},
|
|
4986
|
-
InOutQuint(t){
|
|
4987
|
-
return t < 0.5 ? 16 * Math.pow(t,5) : 1 - Math.pow(-2 * t + 2, 5) / 2;
|
|
4988
|
-
},
|
|
4989
|
-
InExpo(t){
|
|
4990
|
-
return t === 0 ? 0 : Math.pow(2, 10 * t - 10);
|
|
4991
|
-
},
|
|
4992
|
-
OutExpo(t){
|
|
4993
|
-
return t === 1 ? 1 : 1 - Math.pow(2, -10 * t);
|
|
4994
|
-
},
|
|
4995
|
-
InOutExpo(t){
|
|
4996
|
-
return t === 0? 0: t === 1? 1: t < 0.5 ? Math.pow(2, 20 * t - 10) / 2: (2 - Math.pow(2, -20 * t + 10)) / 2;
|
|
4997
|
-
},
|
|
4998
|
-
InCirc(t){
|
|
4999
|
-
return 1 - Math.sqrt(1 - Math.pow(t, 2));
|
|
5000
|
-
},
|
|
5001
|
-
OutCirc(t){
|
|
5002
|
-
return Math.sqrt(1 - Math.pow(t - 1, 2));
|
|
5003
|
-
},
|
|
5004
|
-
InOutCic(t){
|
|
5005
|
-
return t < 0.5? (1 - Math.sqrt(1 - Math.pow(2 * t, 2))) / 2: (Math.sqrt(1 - Math.pow(-2 * t + 2, 2)) + 1) / 2;
|
|
5006
|
-
},
|
|
5007
|
-
Arc(t){
|
|
5008
|
-
return 1 - Math.sin(Math.acos(t));
|
|
5009
|
-
},
|
|
5010
|
-
Back(t){
|
|
5011
|
-
// To Be Changed
|
|
5012
|
-
let x=1;
|
|
5013
|
-
return Math.pow(t, 2) * ((x + 1) * t - x);
|
|
5014
|
-
},
|
|
5015
|
-
Elastic(t){
|
|
5016
|
-
return -2*Math.pow(2, 10 * (t - 1)) * Math.cos(20 * Math.PI * t / 3 * t);
|
|
5017
|
-
},
|
|
5018
|
-
InBack(t){
|
|
5019
|
-
const c1 = 1.70158;
|
|
5020
|
-
const c3 = c1 + 1;
|
|
5021
|
-
return c3 *Math.pow(t,3)- c1 * (t**2);
|
|
5022
|
-
},
|
|
5023
|
-
OutBack(t){
|
|
5024
|
-
const c1 = 1.70158;
|
|
5025
|
-
const c3 = c1 + 1;
|
|
5026
|
-
return 1 + c3 * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2);
|
|
5027
|
-
},
|
|
5028
|
-
InOutBack(t){
|
|
5029
|
-
const c1 = 1.70158;
|
|
5030
|
-
const c2 = c1 * 1.525;
|
|
5031
|
-
return t < 0.5
|
|
5032
|
-
? (Math.pow(2 * t, 2) * ((c2 + 1) * 2 * t - c2)) / 2
|
|
5033
|
-
: (Math.pow(2 * t - 2, 2) * ((c2 + 1) * (t * 2 - 2) + c2) + 2) / 2;
|
|
5034
|
-
},
|
|
5035
|
-
InElastic(t){
|
|
5036
|
-
const c4 = (2 * Math.PI) / 3;return t === 0
|
|
5037
|
-
? 0
|
|
5038
|
-
: t === 1
|
|
5039
|
-
? 1
|
|
5040
|
-
: -Math.pow(2, 10 * t - 10) * Math.sin((t * 10 - 10.75) * c4);
|
|
5041
|
-
},
|
|
5042
|
-
OutElastic(t){
|
|
5043
|
-
const c4 = (2 * Math.PI) / 3;
|
|
5044
|
-
return t === 0
|
|
5045
|
-
? 0
|
|
5046
|
-
: t === 1
|
|
5047
|
-
? 1
|
|
5048
|
-
: Math.pow(2, -10 * t) * Math.sin((t * 10 - 0.75) * c4) + 1;
|
|
5049
|
-
},
|
|
5050
|
-
InOutElastic(t){
|
|
5051
|
-
const c5 = (2 * Math.PI) / 4.5;
|
|
5052
|
-
return t === 0
|
|
5053
|
-
? 0
|
|
5054
|
-
: t === 1
|
|
5055
|
-
? 1
|
|
5056
|
-
: t < 0.5
|
|
5057
|
-
? -(Math.pow(2, 20 * t - 10) * Math.sin((20 * t - 11.125) * c5)) / 2
|
|
5058
|
-
: (Math.pow(2, -20 * t + 10) * Math.sin((20 * t - 11.125) * c5)) / 2 + 1;
|
|
5059
|
-
},
|
|
5060
|
-
InBounce(t){
|
|
5061
|
-
return 1 - Ease.OutBounce(1-t);
|
|
5062
|
-
},
|
|
5063
|
-
OutBounce(t){
|
|
5064
|
-
const n1 = 7.5625;
|
|
5065
|
-
const d1 = 2.75;
|
|
5066
|
-
if (t < 1 / d1) {
|
|
5067
|
-
return n1 * t * t;
|
|
5068
|
-
} else if (t < 2 / d1) {
|
|
5069
|
-
return n1 * (t -= 1.5 / d1) * t + 0.75;
|
|
5070
|
-
} else if (t < 2.5 / d1) {
|
|
5071
|
-
return n1 * (t -= 2.25 / d1) * t + 0.9375;
|
|
5072
|
-
} else {
|
|
5073
|
-
return n1 * (t -= 2.625 / d1) * t + 0.984375;
|
|
5074
|
-
}
|
|
5075
5220
|
|
|
5076
|
-
|
|
5077
|
-
InOutBounce(t){
|
|
5078
|
-
return t < 0.5
|
|
5079
|
-
? (1 - Ease.OutBounce(1 - 2 * t)) / 2
|
|
5080
|
-
: (1 + Ease.OutBounce(2 * t - 1)) / 2;
|
|
5221
|
+
this.cache.id = setTimeout(this.animate, 0);
|
|
5081
5222
|
}
|
|
5082
|
-
}
|
|
5223
|
+
}
|
|
5224
|
+
}
|
|
5225
|
+
|
|
5226
|
+
const loop = (callback, options = {}) => new TimeLoop(callback, options);
|
|
5227
|
+
|
|
5228
|
+
|
|
5229
|
+
// Helpers
|
|
5230
|
+
// const useFps = (fps) => 1000 / fps;
|
|
5231
|
+
|
|
5232
|
+
// const _loop = loop( e => {
|
|
5233
|
+
// console.log("Frame:", e.frame, " Elapsed: ", e.elapsed);
|
|
5234
|
+
// });
|
|
5083
5235
|
|
|
5084
5236
|
const time_memory_Taken = (callback) => {
|
|
5085
5237
|
const t0 = Date.now();
|
|
@@ -5122,6 +5274,7 @@ const waitForUIElm=(UIElement)=>{
|
|
|
5122
5274
|
}
|
|
5123
5275
|
};
|
|
5124
5276
|
|
|
5277
|
+
// import Ease from "./ease.js";
|
|
5125
5278
|
const wait=(delayInMS)=>{
|
|
5126
5279
|
return new Promise((resolve) => setTimeout(resolve, delayInMS));
|
|
5127
5280
|
};
|
|
@@ -5132,93 +5285,6 @@ const timeTaken = callback => {
|
|
|
5132
5285
|
return r;
|
|
5133
5286
|
};
|
|
5134
5287
|
|
|
5135
|
-
class ZikoTimeAnimation{
|
|
5136
|
-
constructor(callback,ease=Ease.Linear,step=50,{t=[0,null],start=true,duration=3000}={}){
|
|
5137
|
-
this.cache={
|
|
5138
|
-
isRunning:false,
|
|
5139
|
-
AnimationId:null,
|
|
5140
|
-
startTime:null,
|
|
5141
|
-
ease,
|
|
5142
|
-
step,
|
|
5143
|
-
intervall:t,
|
|
5144
|
-
started:start,
|
|
5145
|
-
duration
|
|
5146
|
-
};
|
|
5147
|
-
this.t=0;
|
|
5148
|
-
this.tx=0;
|
|
5149
|
-
this.ty=0;
|
|
5150
|
-
this.i=0;
|
|
5151
|
-
this.callback=callback;
|
|
5152
|
-
}
|
|
5153
|
-
#animation_handler(){
|
|
5154
|
-
this.t+=this.cache.step;
|
|
5155
|
-
this.i++;
|
|
5156
|
-
this.tx=map(this.t,0,this.cache.duration,0,1);
|
|
5157
|
-
this.ty=this.cache.ease(this.tx);
|
|
5158
|
-
this.callback(this);
|
|
5159
|
-
if(this.t>=this.cache.duration){
|
|
5160
|
-
clearInterval(this.cache.AnimationId);
|
|
5161
|
-
this.cache.isRunning=false;
|
|
5162
|
-
}
|
|
5163
|
-
}
|
|
5164
|
-
reset(restart=true){
|
|
5165
|
-
this.t=0;
|
|
5166
|
-
this.tx=0;
|
|
5167
|
-
this.ty=0;
|
|
5168
|
-
this.i=0;
|
|
5169
|
-
if(restart)this.start();
|
|
5170
|
-
return this;
|
|
5171
|
-
}
|
|
5172
|
-
#animate(reset=true){
|
|
5173
|
-
if(!this.cache.isRunning){
|
|
5174
|
-
if(reset)this.reset(false);
|
|
5175
|
-
this.cache.isRunning=true;
|
|
5176
|
-
this.cache.startTime = Date.now();
|
|
5177
|
-
this.cache.AnimationId=setInterval(this.#animation_handler.bind(this),this.cache.step);
|
|
5178
|
-
}
|
|
5179
|
-
return this;
|
|
5180
|
-
}
|
|
5181
|
-
start(){
|
|
5182
|
-
this.#animate(true);
|
|
5183
|
-
return this;
|
|
5184
|
-
}
|
|
5185
|
-
pause(){
|
|
5186
|
-
if (this.cache.isRunning) {
|
|
5187
|
-
clearTimeout(this.cache.AnimationId);
|
|
5188
|
-
this.cache.isRunning = false;
|
|
5189
|
-
}
|
|
5190
|
-
return this;
|
|
5191
|
-
}
|
|
5192
|
-
resume(){
|
|
5193
|
-
this.#animate(false);
|
|
5194
|
-
return this;
|
|
5195
|
-
}
|
|
5196
|
-
stop(){
|
|
5197
|
-
this.pause();
|
|
5198
|
-
this.reset(false);
|
|
5199
|
-
return this;
|
|
5200
|
-
}
|
|
5201
|
-
// clear(){
|
|
5202
|
-
// }
|
|
5203
|
-
// stream(){
|
|
5204
|
-
// }
|
|
5205
|
-
}
|
|
5206
|
-
|
|
5207
|
-
const useAnimation=(callback,ease=Ease.Linear,step=50,config)=>new ZikoTimeAnimation(callback,ease=Ease.Linear,step=50,config);
|
|
5208
|
-
|
|
5209
|
-
const debounce=(fn,delay=1000)=>{
|
|
5210
|
-
return (...args) => setTimeout(()=>fn(...args),delay);
|
|
5211
|
-
};
|
|
5212
|
-
const throttle=(fn,delay)=>{
|
|
5213
|
-
let lastTime=0;
|
|
5214
|
-
return (...args) => {
|
|
5215
|
-
const now = new Date().getTime();
|
|
5216
|
-
if(now-lastTime < delay) return;
|
|
5217
|
-
lastTime = now;
|
|
5218
|
-
fn(...args);
|
|
5219
|
-
}
|
|
5220
|
-
};
|
|
5221
|
-
|
|
5222
5288
|
class ZikoApp {
|
|
5223
5289
|
constructor({head = null, wrapper = null, target = null}){
|
|
5224
5290
|
this.head = head;
|
|
@@ -5434,6 +5500,70 @@ function findCommonPath(paths) {
|
|
|
5434
5500
|
return commonPath;
|
|
5435
5501
|
}
|
|
5436
5502
|
|
|
5503
|
+
function useDerived(deriveFn, sources) {
|
|
5504
|
+
let value = deriveFn(...sources.map(s => s().value));
|
|
5505
|
+
const subscribers = new Set();
|
|
5506
|
+
let paused = false;
|
|
5507
|
+
|
|
5508
|
+
function getValue() {
|
|
5509
|
+
return {
|
|
5510
|
+
value,
|
|
5511
|
+
isStateGetter: () => true,
|
|
5512
|
+
_subscribe: (fn, UIElement) => {
|
|
5513
|
+
subscribers.add(fn);
|
|
5514
|
+
|
|
5515
|
+
const observer = new MutationObserver(() => {
|
|
5516
|
+
if (!document.body.contains(UIElement.element)) {
|
|
5517
|
+
subscribers.delete(fn);
|
|
5518
|
+
observer.disconnect();
|
|
5519
|
+
}
|
|
5520
|
+
});
|
|
5521
|
+
|
|
5522
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
5523
|
+
},
|
|
5524
|
+
};
|
|
5525
|
+
}
|
|
5526
|
+
|
|
5527
|
+
function setValue(newValue) {
|
|
5528
|
+
if (paused) return;
|
|
5529
|
+
if (typeof newValue === "function") newValue = newValue(value);
|
|
5530
|
+
if (newValue !== value) {
|
|
5531
|
+
value = newValue;
|
|
5532
|
+
subscribers.forEach(fn => fn(value));
|
|
5533
|
+
}
|
|
5534
|
+
}
|
|
5535
|
+
|
|
5536
|
+
const controller = {
|
|
5537
|
+
pause: () => { paused = true; },
|
|
5538
|
+
resume: () => { paused = false; },
|
|
5539
|
+
clear: () => { subscribers.clear(); },
|
|
5540
|
+
force: (newValue) => {
|
|
5541
|
+
if (typeof newValue === "function") newValue = newValue(value);
|
|
5542
|
+
value = newValue;
|
|
5543
|
+
subscribers.forEach(fn => fn(value));
|
|
5544
|
+
},
|
|
5545
|
+
getSubscribers: () => new Set(subscribers),
|
|
5546
|
+
};
|
|
5547
|
+
|
|
5548
|
+
// Subscribe to source states
|
|
5549
|
+
sources.forEach(source => {
|
|
5550
|
+
const srcValue = source(); // getValue()
|
|
5551
|
+
srcValue._subscribe(() => {
|
|
5552
|
+
if (!paused) {
|
|
5553
|
+
const newVal = deriveFn(...sources.map(s => s().value));
|
|
5554
|
+
if (newVal !== value) {
|
|
5555
|
+
value = newVal;
|
|
5556
|
+
subscribers.forEach(fn => fn(value));
|
|
5557
|
+
}
|
|
5558
|
+
}
|
|
5559
|
+
}, { element: document.body }); // dummy UIElement
|
|
5560
|
+
});
|
|
5561
|
+
|
|
5562
|
+
return [getValue, setValue, controller];
|
|
5563
|
+
}
|
|
5564
|
+
|
|
5565
|
+
const useReactive = (nested_value) => mapfun$1(n => useState(n), nested_value);
|
|
5566
|
+
|
|
5437
5567
|
class ZikoUseChannel{
|
|
5438
5568
|
constructor(name = ""){
|
|
5439
5569
|
this.channel = new BroadcastChannel(name);
|
|
@@ -5672,4 +5802,4 @@ if(globalThis?.document){
|
|
|
5672
5802
|
document?.addEventListener("DOMContentLoaded", __Ziko__.__Config__.init());
|
|
5673
5803
|
}
|
|
5674
5804
|
|
|
5675
|
-
export { App, Base, Canvas, Combinaison, Complex, E, EPSILON,
|
|
5805
|
+
export { App, Arc, Back, Base, Canvas, Clock, Combinaison, Complex, Discret, E, EPSILON, Elastic, FileBasedRouting, Flex, Grid$1 as Grid, HTMLWrapper, InBack, InBounce, InCirc, InCubic, InElastic, InExpo, InOutBack, InOutBounce, InOutCirc, InOutCubic, InOutElastic, InOutExpo, InOutQuad, InOutQuart, InOutQuint, InOutSin, InQuad, InQuart, InQuint, InSin, Linear, Logic$1 as Logic, Matrix, OutBack, OutBounce, OutCirc, OutCubic, OutElastic, OutExpo, OutQuad, OutQuart, OutQuint, OutSin, PI$2 as PI, Permutation, Random, SPA, SVGWrapper, Scheduler, Step, Suspense, Svg, Tick, TimeAnimation, TimeLoop, TimeScheduler, UIElement, UINode, Utils, ZikoApp, ZikoCustomEvent, ZikoEventClick, ZikoEventClipboard, ZikoEventCustom, ZikoEventDrag, ZikoEventFocus, ZikoEventInput, ZikoEventKey, ZikoEventMouse, ZikoEventPointer, ZikoEventSwipe, ZikoEventTouch, ZikoEventWheel, ZikoHead, ZikoMutationObserver, ZikoSPA, ZikoUICanvas, ZikoUIFlex, ZikoUIGrid, ZikoUIHTMLWrapper, ZikoUISVGWrapper, ZikoUISuspense, ZikoUISvg, ZikoUIText, ZikoUIXMLWrapper, ZikoUseRoot, __ZikoEvent__, abs, accum, acos$1 as acos, acosh, acot, add, animation, arange, arr2str, asin, asinh, atan, atan2, atanh, bindClickEvent, bindClipboardEvent, bindCustomEvent, bindDragEvent, bindFocusEvent, bindHashEvent, bindKeyEvent, bindMouseEvent, bindPointerEvent, bindTouchEvent, bindWheelEvent, cartesianProduct, ceil, clamp, clock, combinaison, complex, cos$1 as cos, cosh, cot, coth, csc, csv2arr, csv2json, csv2matrix, csv2object, csv2sql, debounce, defineParamsGetter, deg2rad, div, e, fact, floor, geomspace, getEvent, hypot, inRange, isApproximatlyEqual, isStateGetter, json2arr, json2css, json2csv, json2csvFile, json2xml, json2xmlFile, json2yml, json2ymlFile, lerp, linspace, ln, logspace, loop, map, mapfun$1 as mapfun, matrix, matrix2, matrix3, matrix4, max, min, modulo, mul, norm, nums, obj2str, ones, pgcd, pow$1 as pow, powerSet, ppcm, preload, prod, rad2deg, round, sec, sig, sign, sin$1 as sin, sinc, sinh, sleep, sqrt$1 as sqrt, sqrtn, step_fps, sub, subSet, sum, svg2ascii, svg2img, svg2imgUrl, svg2str, tags, tan, tanh, text, throttle, tick, timeTaken, time_memory_Taken, timeout, useChannel, useCustomEvent, useDerived, useEventEmitter, useFavIcon, useHashEvent, useHead, useInputEvent, useLocaleStorage, useMediaQuery, useMeta, useReactive, useRoot, useSessionStorage, useState, useSuccesifKeys, useSwipeEvent, useThread, useTitle, wait, waitForUIElm, waitForUIElmSync, watch, watchAttr, watchChildren, watchIntersection, watchScreen, watchSize, zeros };
|