ziko 0.39.0 → 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ziko.cjs +689 -522
- package/dist/ziko.js +689 -522
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +631 -508
- 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/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__/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.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/*
|
|
3
3
|
Project: ziko.js
|
|
4
4
|
Author: Zakaria Elalaoui
|
|
5
|
-
Date :
|
|
5
|
+
Date : Tue Aug 19 2025 09:41:09 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
|
|
@@ -14,22 +14,22 @@
|
|
|
14
14
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Ziko = {}));
|
|
15
15
|
})(this, (function (exports) { 'use strict';
|
|
16
16
|
|
|
17
|
-
const { PI: PI$
|
|
17
|
+
const { PI: PI$2, E } = Math;
|
|
18
18
|
const EPSILON=Number.EPSILON;
|
|
19
19
|
|
|
20
|
-
const {PI, cos: cos$
|
|
20
|
+
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;
|
|
21
21
|
let Fixed={
|
|
22
|
-
cos: cos$
|
|
23
|
-
sin: sin$
|
|
22
|
+
cos: cos$2,
|
|
23
|
+
sin: sin$2,
|
|
24
24
|
tan: tan$1,
|
|
25
|
-
sinc: x => sin$
|
|
26
|
-
sec: x => 1/cos$
|
|
27
|
-
csc: x => 1/sin$
|
|
25
|
+
sinc: x => sin$2(PI$1*x)/(PI$1*x),
|
|
26
|
+
sec: x => 1/cos$2(x),
|
|
27
|
+
csc: x => 1/sin$2(x),
|
|
28
28
|
cot: x => 1/tan$1(x),
|
|
29
|
-
acos: acos$
|
|
29
|
+
acos: acos$2,
|
|
30
30
|
asin: asin$1,
|
|
31
31
|
atan: atan$1,
|
|
32
|
-
acot: x => PI/2-atan$1(x),
|
|
32
|
+
acot: x => PI$1/2-atan$1(x),
|
|
33
33
|
cosh: cosh$1,
|
|
34
34
|
sinh: sinh$1,
|
|
35
35
|
tanh: tanh$1,
|
|
@@ -67,20 +67,20 @@
|
|
|
67
67
|
const [a,b,z,phi]=[x.a,x.b,x.z,x.phi];
|
|
68
68
|
switch(fun){
|
|
69
69
|
case Math.log: return complex(ln(z),phi); // Done
|
|
70
|
-
case Math.exp: return complex(e(a)*cos(b),e(a)*sin(b)); // Done
|
|
70
|
+
case Math.exp: return complex(e(a)*cos$1(b),e(a)*sin$1(b)); // Done
|
|
71
71
|
case Math.abs: return z; // Done
|
|
72
|
-
case Math.sqrt: return complex(sqrt(z)*cos(phi/2),sqrt(z)*sin(phi/2)); // Done
|
|
73
|
-
case Fixed.cos: return complex(cos(a)*cosh(b),-(sin(a)*sinh(b)));
|
|
74
|
-
case Fixed.sin: return complex(sin(a)*cosh(b),cos(a)*sinh(b));
|
|
72
|
+
case Math.sqrt: return complex(sqrt$1(z)*cos$1(phi/2),sqrt$1(z)*sin$1(phi/2)); // Done
|
|
73
|
+
case Fixed.cos: return complex(cos$1(a)*cosh(b),-(sin$1(a)*sinh(b)));
|
|
74
|
+
case Fixed.sin: return complex(sin$1(a)*cosh(b),cos$1(a)*sinh(b));
|
|
75
75
|
case Fixed.tan:{
|
|
76
|
-
const DEN = cos(2*a)+cosh(2*b);
|
|
77
|
-
return complex(sin(2*a)/DEN,sinh(2*b)/DEN);
|
|
76
|
+
const DEN = cos$1(2*a)+cosh(2*b);
|
|
77
|
+
return complex(sin$1(2*a)/DEN,sinh(2*b)/DEN);
|
|
78
78
|
}
|
|
79
|
-
case Fixed.cosh:return complex(cosh(a)*cos(b),sinh(a)*sin(b));
|
|
80
|
-
case Fixed.sinh:return complex(sinh(a)*cos(b),cosh(a)*sin(b));
|
|
79
|
+
case Fixed.cosh:return complex(cosh(a)*cos$1(b),sinh(a)*sin$1(b));
|
|
80
|
+
case Fixed.sinh:return complex(sinh(a)*cos$1(b),cosh(a)*sin$1(b));
|
|
81
81
|
case Fixed.tanh:{
|
|
82
|
-
const DEN=cosh(2*a)+cos(2*b);
|
|
83
|
-
return complex(sinh(2*a)/DEN,sin(2*b)/DEN)
|
|
82
|
+
const DEN=cosh(2*a)+cos$1(2*b);
|
|
83
|
+
return complex(sinh(2*a)/DEN,sin$1(2*b)/DEN)
|
|
84
84
|
}
|
|
85
85
|
default : return fun(x)
|
|
86
86
|
}
|
|
@@ -321,7 +321,7 @@
|
|
|
321
321
|
}
|
|
322
322
|
};
|
|
323
323
|
const logspace=(a,b,n=b-a+1,base=E,endpoint=true)=>{
|
|
324
|
-
return linspace(a,b,n,endpoint).map(n=>pow(base,n))
|
|
324
|
+
return linspace(a,b,n,endpoint).map(n=>pow$1(base,n))
|
|
325
325
|
};
|
|
326
326
|
const geomspace=(a,b,n=abs(b-a)+1,endpoint=true)=>{
|
|
327
327
|
if(Math.floor(n)!==n)return;
|
|
@@ -1106,10 +1106,69 @@
|
|
|
1106
1106
|
else register_to_instance(target, ...mixins);
|
|
1107
1107
|
};
|
|
1108
1108
|
|
|
1109
|
+
function useState(initialValue) {
|
|
1110
|
+
let value = initialValue;
|
|
1111
|
+
const subscribers = new Set();
|
|
1112
|
+
let paused = false;
|
|
1113
|
+
|
|
1114
|
+
function getValue() {
|
|
1115
|
+
return {
|
|
1116
|
+
value,
|
|
1117
|
+
isStateGetter: () => true,
|
|
1118
|
+
_subscribe: (
|
|
1119
|
+
fn,
|
|
1120
|
+
// UIElement
|
|
1121
|
+
) => {
|
|
1122
|
+
subscribers.add(fn);
|
|
1123
|
+
|
|
1124
|
+
// const observer = new MutationObserver(() => {
|
|
1125
|
+
// if (!document.body.contains(UIElement.element)) {
|
|
1126
|
+
// subscribers.delete(fn);
|
|
1127
|
+
// observer.disconnect();
|
|
1128
|
+
// }
|
|
1129
|
+
// });
|
|
1130
|
+
|
|
1131
|
+
// observer.observe(document.body, { childList: true, subtree: true });
|
|
1132
|
+
},
|
|
1133
|
+
};
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
function setValue(newValue) {
|
|
1137
|
+
if (paused) return;
|
|
1138
|
+
if (typeof newValue === "function") newValue = newValue(value);
|
|
1139
|
+
if (newValue !== value) {
|
|
1140
|
+
value = newValue;
|
|
1141
|
+
subscribers.forEach(fn => fn(value));
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
const controller = {
|
|
1146
|
+
pause: () => { paused = true; },
|
|
1147
|
+
resume: () => { paused = false; },
|
|
1148
|
+
clear: () => { subscribers.clear(); },
|
|
1149
|
+
force: (newValue) => { // force update even if paused
|
|
1150
|
+
if (typeof newValue === "function") newValue = newValue(value);
|
|
1151
|
+
value = newValue;
|
|
1152
|
+
subscribers.forEach(fn => fn(value));
|
|
1153
|
+
},
|
|
1154
|
+
getSubscribers: () => new Set(subscribers),
|
|
1155
|
+
};
|
|
1156
|
+
|
|
1157
|
+
return [getValue, setValue, controller];
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1109
1160
|
const isStateGetter = (arg) => {
|
|
1110
1161
|
return typeof(arg) === 'function' && arg?.()?.isStateGetter?.()
|
|
1111
1162
|
};
|
|
1112
1163
|
|
|
1164
|
+
const camel2hyphencase = (text = '') => text.replace(/[A-Z]/g, match => '-' + match.toLowerCase());
|
|
1165
|
+
|
|
1166
|
+
const is_camelcase = (text = '') =>{
|
|
1167
|
+
if (text.length === 0) return false;
|
|
1168
|
+
const camelCasePattern = /^[a-z][a-zA-Z0-9]*$/;
|
|
1169
|
+
return camelCasePattern.test(text);
|
|
1170
|
+
};
|
|
1171
|
+
|
|
1113
1172
|
// To Do add getter, watchAttr
|
|
1114
1173
|
const AttrsMethods = {
|
|
1115
1174
|
setAttr(name, value) {
|
|
@@ -1131,7 +1190,7 @@
|
|
|
1131
1190
|
return this;
|
|
1132
1191
|
},
|
|
1133
1192
|
getAttr(name){
|
|
1134
|
-
name =
|
|
1193
|
+
name = is_camelcase(name) ? camel2hyphencase(name) : name;
|
|
1135
1194
|
return this.element.attributes[name].value;
|
|
1136
1195
|
},
|
|
1137
1196
|
setContentEditable(bool = true) {
|
|
@@ -1141,7 +1200,7 @@
|
|
|
1141
1200
|
};
|
|
1142
1201
|
|
|
1143
1202
|
function _set_attrs_(name, value){
|
|
1144
|
-
if(this.element?.tagName !== "svg") name =
|
|
1203
|
+
if(this.element?.tagName !== "svg") name = is_camelcase(name) ? camel2hyphencase(name) : name;
|
|
1145
1204
|
if(this?.attr[name] && this?.attr[name]===value) return;
|
|
1146
1205
|
if(isStateGetter(value)){
|
|
1147
1206
|
const getter = value();
|
|
@@ -1700,19 +1759,38 @@
|
|
|
1700
1759
|
},
|
|
1701
1760
|
};
|
|
1702
1761
|
|
|
1703
|
-
// Process width and height
|
|
1704
1762
|
const StyleMethods = {
|
|
1705
1763
|
style(styles){
|
|
1706
|
-
|
|
1764
|
+
for(let key in styles){
|
|
1765
|
+
const value = styles[key];
|
|
1766
|
+
if(isStateGetter(value)){
|
|
1767
|
+
const getter = value();
|
|
1768
|
+
Object.assign(this.element.style, {[key] : getter.value});
|
|
1769
|
+
getter._subscribe(
|
|
1770
|
+
(newValue) => {
|
|
1771
|
+
console.log({newValue});
|
|
1772
|
+
Object.assign(this.element.style, {[key] : newValue});
|
|
1773
|
+
},
|
|
1774
|
+
// this
|
|
1775
|
+
);
|
|
1776
|
+
}
|
|
1777
|
+
else Object.assign(this.element.style, {[key] : value});
|
|
1778
|
+
}
|
|
1707
1779
|
return this;
|
|
1708
1780
|
},
|
|
1709
1781
|
size(width, height){
|
|
1710
1782
|
return this.style({width, height})
|
|
1783
|
+
},
|
|
1784
|
+
hide(){
|
|
1785
|
+
|
|
1786
|
+
},
|
|
1787
|
+
show(){
|
|
1788
|
+
|
|
1711
1789
|
},
|
|
1712
1790
|
animate(keyframe, {duration=1000, iterations=1, easing="ease"}={}){
|
|
1713
1791
|
this.element?.animate(keyframe,{duration, iterations, easing});
|
|
1714
1792
|
return this;
|
|
1715
|
-
|
|
1793
|
+
}
|
|
1716
1794
|
};
|
|
1717
1795
|
|
|
1718
1796
|
function EVENT_CONTROLLER(e,EVENT,setter,push_object){
|
|
@@ -3119,18 +3197,14 @@
|
|
|
3119
3197
|
let type ;
|
|
3120
3198
|
if(HTMLTags.includes(tag)) type = 'html';
|
|
3121
3199
|
if(SVGTags.includes(tag)) type = 'svg';
|
|
3122
|
-
|
|
3200
|
+
return (...args)=>{
|
|
3123
3201
|
console.log(isStateGetter(args[0]));
|
|
3124
|
-
// if(typeof args[0] === 'function') {
|
|
3125
|
-
// console.log(args[0], args[0]?.() instanceof StateGetter)
|
|
3126
|
-
// globalThis.a = args[0]
|
|
3127
|
-
// console.log({t : a.constructor})
|
|
3128
|
-
// }
|
|
3129
3202
|
if(
|
|
3130
3203
|
['string', 'number'].includes(typeof args[0])
|
|
3131
3204
|
|| args[0] instanceof UIElement
|
|
3132
3205
|
|| (typeof args[0] === 'function' && args[0]().isStateGetter())
|
|
3133
|
-
) return new UIElement({element :tag, name : tag, type}).append(...args);
|
|
3206
|
+
) return new UIElement({element : tag, name : tag, type}).append(...args);
|
|
3207
|
+
// console.log(args[0])
|
|
3134
3208
|
return new UIElement({element : tag}).setAttr(args.shift()).append(...args)
|
|
3135
3209
|
}
|
|
3136
3210
|
// if(SVGTags.includes(tag)) return (...args) => new UIElement(tag,"",{el_type : "svg"}).append(...args);
|
|
@@ -3722,175 +3796,6 @@
|
|
|
3722
3796
|
}, Array.isArray(obj) ? [] : {});
|
|
3723
3797
|
}
|
|
3724
3798
|
|
|
3725
|
-
const Patterns={
|
|
3726
|
-
isDigit: /^\d+$/,
|
|
3727
|
-
isURL: /^(https?:\/\/)?([\w\-]+\.)+[\w\-]+(\/[\w\-./?%&=]*)?$/,
|
|
3728
|
-
isHexColor: /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/,
|
|
3729
|
-
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]?)$/,
|
|
3730
|
-
isMACAddress: /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/,
|
|
3731
|
-
isDate: /^\d{4}-\d{2}-\d{2}$/,
|
|
3732
|
-
};
|
|
3733
|
-
|
|
3734
|
-
class Str{
|
|
3735
|
-
constructor(string){
|
|
3736
|
-
this.string=string;
|
|
3737
|
-
}
|
|
3738
|
-
isDigit() {
|
|
3739
|
-
return Patterns.isDigit.test(this.string);
|
|
3740
|
-
}
|
|
3741
|
-
static isDigit(string){
|
|
3742
|
-
return new Str(string).isDigit();
|
|
3743
|
-
}
|
|
3744
|
-
isNumber() {
|
|
3745
|
-
return !isNaN(this.string);
|
|
3746
|
-
}
|
|
3747
|
-
static isNumber(string){
|
|
3748
|
-
return new Str(string).isNumber();
|
|
3749
|
-
}
|
|
3750
|
-
isUrl(){
|
|
3751
|
-
return Patterns.isURL.test(this.string);
|
|
3752
|
-
}
|
|
3753
|
-
static isUrl(string){
|
|
3754
|
-
return new Str(string).isUrl();
|
|
3755
|
-
}
|
|
3756
|
-
isHexColor(){
|
|
3757
|
-
return Patterns.isHexColor.test(this.string);
|
|
3758
|
-
}
|
|
3759
|
-
static isHexColor(string){
|
|
3760
|
-
return new Str(string).isHexColor();
|
|
3761
|
-
}
|
|
3762
|
-
isIPv4(){
|
|
3763
|
-
return Patterns.isIPv4.test(this.string);
|
|
3764
|
-
}
|
|
3765
|
-
static isIPv4(string){
|
|
3766
|
-
return new Str(string).isIPv4();
|
|
3767
|
-
}
|
|
3768
|
-
isDate(){
|
|
3769
|
-
return Patterns.isDate.test(this.string);
|
|
3770
|
-
}
|
|
3771
|
-
static isDate(string){
|
|
3772
|
-
return new Str(string).isDate();
|
|
3773
|
-
}
|
|
3774
|
-
isMACAddress(){
|
|
3775
|
-
return Patterns.isMACAddress.test(this.string);
|
|
3776
|
-
}
|
|
3777
|
-
static isMACAddress(string){
|
|
3778
|
-
return new Str(string).isMACAddress();
|
|
3779
|
-
}
|
|
3780
|
-
isPascalCase(){
|
|
3781
|
-
if (this.string.length === 0) return false;
|
|
3782
|
-
const PascalCasePattern = /^[A-Z][a-zA-Z0-9]*$/;
|
|
3783
|
-
return PascalCasePattern.test(this.string);
|
|
3784
|
-
}
|
|
3785
|
-
static isPascalCase(string){
|
|
3786
|
-
return new Str(string).isPascalCase();
|
|
3787
|
-
}
|
|
3788
|
-
isCamelCase() {
|
|
3789
|
-
if (this.string.length === 0) return false;
|
|
3790
|
-
const camelCasePattern = /^[a-z][a-zA-Z0-9]*$/;
|
|
3791
|
-
return camelCasePattern.test(this.string);
|
|
3792
|
-
}
|
|
3793
|
-
static isCamelCase(string){
|
|
3794
|
-
return new Str(string).isCamelCase();
|
|
3795
|
-
}
|
|
3796
|
-
isHyphenCase(){
|
|
3797
|
-
return this.string.split('-').length > 1;
|
|
3798
|
-
}
|
|
3799
|
-
static isHyphenCase(string){
|
|
3800
|
-
return new Str(string).isHyphenCase();
|
|
3801
|
-
}
|
|
3802
|
-
isSnakeCase(){
|
|
3803
|
-
return this.string.split('_').length > 1;
|
|
3804
|
-
}
|
|
3805
|
-
static isSnakeCase(string){
|
|
3806
|
-
return new Str(string).isSnakeCase();
|
|
3807
|
-
}
|
|
3808
|
-
isPalindrome(){
|
|
3809
|
-
const str=this.string.toLocaleLowerCase();
|
|
3810
|
-
let l=str.length,i;
|
|
3811
|
-
for(i=0;i<l/2;i++)if(str[i]!=str[l-i-1])return false;
|
|
3812
|
-
return true;
|
|
3813
|
-
}
|
|
3814
|
-
static isPalindrome(string){
|
|
3815
|
-
return new Str(string).isPalindrome();
|
|
3816
|
-
}
|
|
3817
|
-
static isAnagrams(word,words){
|
|
3818
|
-
word=word.split("").sort();
|
|
3819
|
-
words=words.split("").sort();
|
|
3820
|
-
return JSON.stringify(word)===JSON.stringify(words);
|
|
3821
|
-
}
|
|
3822
|
-
isIsogram(){
|
|
3823
|
-
return [...new Set(this.string.toLowerCase())].length===this.string.length;
|
|
3824
|
-
}
|
|
3825
|
-
static isIsogram(string){
|
|
3826
|
-
return new Str(string).isIsogram();
|
|
3827
|
-
}
|
|
3828
|
-
static camel2hyphencase(text) {
|
|
3829
|
-
return text.replace(/[A-Z]/g, match => '-' + match.toLowerCase());
|
|
3830
|
-
}
|
|
3831
|
-
static camel2snakecase(text) {
|
|
3832
|
-
return text.replace(/[A-Z]/g, match => '_' + match.toLowerCase());
|
|
3833
|
-
}
|
|
3834
|
-
static camel2pascalcase(text) {
|
|
3835
|
-
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
3836
|
-
}
|
|
3837
|
-
static camel2constantcase(text) {
|
|
3838
|
-
return text.replace(/[A-Z]/g, match => '_' + match).toUpperCase();
|
|
3839
|
-
}
|
|
3840
|
-
static pascal2snakecase(text) {
|
|
3841
|
-
return text.replace(/([A-Z])/g, (match, offset) => offset ? '_' + match.toLowerCase() : match.toLowerCase());
|
|
3842
|
-
}
|
|
3843
|
-
static pascal2hyphencase(text) {
|
|
3844
|
-
return text.replace(/([A-Z])/g, (match, offset) => offset ? '-' + match.toLowerCase() : match.toLowerCase());
|
|
3845
|
-
}
|
|
3846
|
-
static pascal2camelcase(text) {
|
|
3847
|
-
return text.charAt(0).toLowerCase() + text.slice(1);
|
|
3848
|
-
}
|
|
3849
|
-
static pascal2constantcase(text) {
|
|
3850
|
-
return text.replace(/([A-Z])/g, (match, offset) => offset ? '_' + match : match).toUpperCase();
|
|
3851
|
-
}
|
|
3852
|
-
static snake2camelcase(text) {
|
|
3853
|
-
return text.replace(/(_\w)/g, match => match[1].toUpperCase());
|
|
3854
|
-
}
|
|
3855
|
-
static snake2hyphencase(text) {
|
|
3856
|
-
return text.replace(/_/g, "-");
|
|
3857
|
-
}
|
|
3858
|
-
static snake2pascalcase(text) {
|
|
3859
|
-
return text.split('_').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join('');
|
|
3860
|
-
}
|
|
3861
|
-
static snake2constantcase(text) {
|
|
3862
|
-
return text.toUpperCase();
|
|
3863
|
-
}
|
|
3864
|
-
static hyphen2camelcase(text) {
|
|
3865
|
-
return text.replace(/-([a-z])/g, match => match[1].toUpperCase());
|
|
3866
|
-
}
|
|
3867
|
-
static hyphen2snakecase(text) {
|
|
3868
|
-
return text.replace(/-/g, '_');
|
|
3869
|
-
}
|
|
3870
|
-
static hyphen2pascalcase(text) {
|
|
3871
|
-
return text.split('-').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join('');
|
|
3872
|
-
}
|
|
3873
|
-
static hyphen2constantcase(text) {
|
|
3874
|
-
return text.replace(/-/g, '_').toUpperCase();
|
|
3875
|
-
}
|
|
3876
|
-
static constant2camelcase(text) {
|
|
3877
|
-
return text.toLowerCase().replace(/_([a-z])/g, match => match[1].toUpperCase());
|
|
3878
|
-
}
|
|
3879
|
-
static constant2snakecase(text) {
|
|
3880
|
-
return text.toLowerCase();
|
|
3881
|
-
}
|
|
3882
|
-
static constant2pascalcase(text) {
|
|
3883
|
-
return text.toLowerCase().split('_').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join('');
|
|
3884
|
-
}
|
|
3885
|
-
static constant2hyphencase(text) {
|
|
3886
|
-
return text.toLowerCase().replace(/_/g, '-');
|
|
3887
|
-
}
|
|
3888
|
-
}
|
|
3889
|
-
const removeExtraSpace=str=>str.replace(/\s+/g,' ');
|
|
3890
|
-
const count=(str,value)=>str.split("").filter(x => x==value).length;
|
|
3891
|
-
const countWords=(str,value)=>str.split(" ").filter(x => x==value).length;
|
|
3892
|
-
const str=string=>new Str(string);
|
|
3893
|
-
|
|
3894
3799
|
class Matrix extends ZikoMath{
|
|
3895
3800
|
constructor(rows, cols, element = [] ) {
|
|
3896
3801
|
super();
|
|
@@ -4049,7 +3954,7 @@
|
|
|
4049
3954
|
.mul(determinat(deleteRowAndColumn(M, i)))
|
|
4050
3955
|
);*/
|
|
4051
3956
|
//const to_be_added=Utils.add(Utils.mul(pow(-1, i),Utils.mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
|
|
4052
|
-
const to_be_added=Utils.add(Utils.mul(pow(-1, i),Utils.mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
|
|
3957
|
+
const to_be_added=Utils.add(Utils.mul(pow$1(-1, i),Utils.mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
|
|
4053
3958
|
answer=Utils.add(answer,to_be_added);
|
|
4054
3959
|
}
|
|
4055
3960
|
return answer;
|
|
@@ -4572,7 +4477,7 @@
|
|
|
4572
4477
|
}
|
|
4573
4478
|
else if(("a" in b && "z" in a)){
|
|
4574
4479
|
this.a=a.a;
|
|
4575
|
-
this.b=sqrt((a.z**2)-(a.a**2));
|
|
4480
|
+
this.b=sqrt$1((a.z**2)-(a.a**2));
|
|
4576
4481
|
}
|
|
4577
4482
|
else if(("a" in b && "phi" in a)){
|
|
4578
4483
|
this.a=a.a;
|
|
@@ -4580,15 +4485,15 @@
|
|
|
4580
4485
|
}
|
|
4581
4486
|
else if(("b" in b && "z" in a)){
|
|
4582
4487
|
this.b=a.b;
|
|
4583
|
-
this.a=sqrt((a.z**2)-(a.b**2));
|
|
4488
|
+
this.a=sqrt$1((a.z**2)-(a.b**2));
|
|
4584
4489
|
}
|
|
4585
4490
|
else if(("b" in b && "phi" in a)){
|
|
4586
4491
|
this.b=b;
|
|
4587
4492
|
this.a=a.b/tan(a.phi);
|
|
4588
4493
|
}
|
|
4589
4494
|
else if(("z" in b && "phi" in a)){
|
|
4590
|
-
this.a=a.z*cos(a.phi);
|
|
4591
|
-
this.a=a.z*sin(a.phi);
|
|
4495
|
+
this.a=a.z*cos$1(a.phi);
|
|
4496
|
+
this.a=a.z*sin$1(a.phi);
|
|
4592
4497
|
}
|
|
4593
4498
|
}
|
|
4594
4499
|
else if(typeof(a)==="number"&&typeof(b)==="number"){
|
|
@@ -4628,7 +4533,7 @@
|
|
|
4628
4533
|
return new Complex(this.a, -this.b);
|
|
4629
4534
|
}
|
|
4630
4535
|
get inv() {
|
|
4631
|
-
return new Complex(this.a / (pow(this.a, 2) + pow(this.b, 2)), -this.b / (pow(this.a, 2) + pow(this.b, 2)));
|
|
4536
|
+
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)));
|
|
4632
4537
|
}
|
|
4633
4538
|
add(...z) {
|
|
4634
4539
|
for (let i = 0; i < z.length; i++) {
|
|
@@ -4656,8 +4561,8 @@
|
|
|
4656
4561
|
}
|
|
4657
4562
|
let Z=+prod(this.z,...z.map(n=>n.z)).toFixed(15);
|
|
4658
4563
|
let phi=+sum(this.phi,...z.map(n=>n.phi)).toFixed(15);
|
|
4659
|
-
this.a=+(Z*cos(phi).toFixed(15)).toFixed(14);
|
|
4660
|
-
this.b=+(Z*sin(phi).toFixed(15)).toFixed(14);
|
|
4564
|
+
this.a=+(Z*cos$1(phi).toFixed(15)).toFixed(14);
|
|
4565
|
+
this.b=+(Z*sin$1(phi).toFixed(15)).toFixed(14);
|
|
4661
4566
|
return this;
|
|
4662
4567
|
}
|
|
4663
4568
|
div(...z) {
|
|
@@ -4666,23 +4571,23 @@
|
|
|
4666
4571
|
}
|
|
4667
4572
|
let Z=+(this.z/prod(...z.map(n=>n.z))).toFixed(15);
|
|
4668
4573
|
let phi=+(this.phi-sum(...z.map(n=>n.phi))).toFixed(15);
|
|
4669
|
-
this.a=+(Z*cos(phi).toFixed(15)).toFixed(15);
|
|
4670
|
-
this.b=+(Z*sin(phi).toFixed(15)).toFixed(15);
|
|
4574
|
+
this.a=+(Z*cos$1(phi).toFixed(15)).toFixed(15);
|
|
4575
|
+
this.b=+(Z*sin$1(phi).toFixed(15)).toFixed(15);
|
|
4671
4576
|
return this;
|
|
4672
4577
|
}
|
|
4673
4578
|
pow(n) {
|
|
4674
4579
|
if (floor(n) === n && n > 0) {
|
|
4675
4580
|
let z=+(this.z**n).toFixed(15);
|
|
4676
4581
|
let phi=+(this.phi*n).toFixed(15);
|
|
4677
|
-
this.a=+(z*cos(phi).toFixed(15)).toFixed(15);
|
|
4678
|
-
this.b=+(z*sin(phi).toFixed(15)).toFixed(15);
|
|
4582
|
+
this.a=+(z*cos$1(phi).toFixed(15)).toFixed(15);
|
|
4583
|
+
this.b=+(z*sin$1(phi).toFixed(15)).toFixed(15);
|
|
4679
4584
|
}
|
|
4680
4585
|
return this;
|
|
4681
4586
|
}
|
|
4682
4587
|
static fromExpo(z, phi) {
|
|
4683
4588
|
return new Complex(
|
|
4684
|
-
+(z * cos(phi)).toFixed(13),
|
|
4685
|
-
+(z * sin(phi)).toFixed(13)
|
|
4589
|
+
+(z * cos$1(phi)).toFixed(13),
|
|
4590
|
+
+(z * sin$1(phi)).toFixed(13)
|
|
4686
4591
|
);
|
|
4687
4592
|
}
|
|
4688
4593
|
get expo() {
|
|
@@ -4704,10 +4609,10 @@
|
|
|
4704
4609
|
return z.clone.pow(n);
|
|
4705
4610
|
}
|
|
4706
4611
|
static xpowZ(x){
|
|
4707
|
-
return complex((x**this.a)*cos(this.b*ln(x)),(x**this.a)*sin(this.b*ln(x)));
|
|
4612
|
+
return complex((x**this.a)*cos$1(this.b*ln(x)),(x**this.a)*sin$1(this.b*ln(x)));
|
|
4708
4613
|
}
|
|
4709
4614
|
sqrtn(n=2){
|
|
4710
|
-
return complex(sqrtn(this.z,n)*cos(this.phi/n),sqrtn(this.z,n)*sin(this.phi/n));
|
|
4615
|
+
return complex(sqrtn(this.z,n)*cos$1(this.phi/n),sqrtn(this.z,n)*sin$1(this.phi/n));
|
|
4711
4616
|
}
|
|
4712
4617
|
get sqrt(){
|
|
4713
4618
|
return this.sqrtn(2);
|
|
@@ -4716,14 +4621,14 @@
|
|
|
4716
4621
|
return complex(this.z,this.phi);
|
|
4717
4622
|
}
|
|
4718
4623
|
get cos(){
|
|
4719
|
-
return complex(cos(this.a)*cosh(this.b),sin(this.a)*sinh(this.b))
|
|
4624
|
+
return complex(cos$1(this.a)*cosh(this.b),sin$1(this.a)*sinh(this.b))
|
|
4720
4625
|
}
|
|
4721
4626
|
get sin(){
|
|
4722
|
-
return complex(sin(this.a)*cosh(this.b),cos(this.a)*sinh(this.b))
|
|
4627
|
+
return complex(sin$1(this.a)*cosh(this.b),cos$1(this.a)*sinh(this.b))
|
|
4723
4628
|
}
|
|
4724
4629
|
get tan(){
|
|
4725
|
-
const de=cos(this.a*2)+cosh(this.b*2);
|
|
4726
|
-
return complex(sin(2*this.a)/de,sinh(2*this.b)/de);
|
|
4630
|
+
const de=cos$1(this.a*2)+cosh(this.b*2);
|
|
4631
|
+
return complex(sin$1(2*this.a)/de,sinh(2*this.b)/de);
|
|
4727
4632
|
}
|
|
4728
4633
|
printInConsole() {
|
|
4729
4634
|
let string = this.a + " + " + this.b + " * i";
|
|
@@ -4754,12 +4659,12 @@
|
|
|
4754
4659
|
// } from "../calculus/index.js";
|
|
4755
4660
|
|
|
4756
4661
|
const abs=(...x)=>mapfun$1(Math.abs,...x);
|
|
4757
|
-
const sqrt=(...x)=>mapfun$1(Math.sqrt,...x);
|
|
4758
|
-
const pow=(x,n)=>{
|
|
4662
|
+
const sqrt$1=(...x)=>mapfun$1(Math.sqrt,...x);
|
|
4663
|
+
const pow$1=(x,n)=>{
|
|
4759
4664
|
if(typeof x === "number"){
|
|
4760
4665
|
if(typeof n === "number")return Math.pow(x,n);
|
|
4761
4666
|
else if(n instanceof Complex)return Complex.fromExpo(x**n.a,n.b*ln(x))
|
|
4762
|
-
else return mapfun$1(a=>pow(x,a),...n);
|
|
4667
|
+
else return mapfun$1(a=>pow$1(x,a),...n);
|
|
4763
4668
|
}
|
|
4764
4669
|
else if(x instanceof Complex){
|
|
4765
4670
|
if(typeof n === "number")return Complex.fromExpo(x.z**n,x.phi*n);
|
|
@@ -4767,14 +4672,14 @@
|
|
|
4767
4672
|
x.z**n.a*e(-x.phi*n.b),
|
|
4768
4673
|
ln(x.z)*n.b+n.a*x.phi
|
|
4769
4674
|
)
|
|
4770
|
-
else return mapfun$1(a=>pow(x,a),...n);
|
|
4675
|
+
else return mapfun$1(a=>pow$1(x,a),...n);
|
|
4771
4676
|
}
|
|
4772
4677
|
else if(x instanceof Array){
|
|
4773
|
-
if(typeof n === "number") return mapfun$1(a=>pow(a,n),...x);
|
|
4678
|
+
if(typeof n === "number") return mapfun$1(a=>pow$1(a,n),...x);
|
|
4774
4679
|
else if(n instanceof Array){
|
|
4775
4680
|
const Y=[];
|
|
4776
4681
|
for(let i=0;i<x.length;i++){
|
|
4777
|
-
Y.push(mapfun$1(a=>pow(x[i],a),...n));
|
|
4682
|
+
Y.push(mapfun$1(a=>pow$1(x[i],a),...n));
|
|
4778
4683
|
}
|
|
4779
4684
|
return Y;
|
|
4780
4685
|
}
|
|
@@ -4802,14 +4707,14 @@
|
|
|
4802
4707
|
};
|
|
4803
4708
|
const e=(...x) => mapfun$1(Math.exp,...x);
|
|
4804
4709
|
const ln=(...x) => mapfun$1(Math.log,...x);
|
|
4805
|
-
const cos=(...x) => mapfun$1(Fixed.cos,...x);
|
|
4806
|
-
const sin=(...x) => mapfun$1(Fixed.sin,...x);
|
|
4710
|
+
const cos$1=(...x) => mapfun$1(Fixed.cos,...x);
|
|
4711
|
+
const sin$1=(...x) => mapfun$1(Fixed.sin,...x);
|
|
4807
4712
|
const tan=(...x) => mapfun$1(Fixed.tan,...x);
|
|
4808
4713
|
const sec=(...x) => mapfun$1(Fixed.sec,...x);
|
|
4809
4714
|
const sinc=(...x) => mapfun$1(Fixed.sinc,...x);
|
|
4810
4715
|
const csc=(...x) => mapfun$1(Fixed.csc,...x);
|
|
4811
4716
|
const cot=(...x) => mapfun$1(Fixed.cot,...x);
|
|
4812
|
-
const acos=(...x) => mapfun$1(Fixed.acos,...x);
|
|
4717
|
+
const acos$1=(...x) => mapfun$1(Fixed.acos,...x);
|
|
4813
4718
|
const asin=(...x) => mapfun$1(Fixed.asin,...x);
|
|
4814
4719
|
const atan=(...x) => mapfun$1(Fixed.atan,...x);
|
|
4815
4720
|
const acot=(...x) => mapfun$1(Fixed.acot,...x);
|
|
@@ -4837,7 +4742,7 @@
|
|
|
4837
4742
|
else if(y instanceof Array){
|
|
4838
4743
|
const Y=[];
|
|
4839
4744
|
for(let i=0;i<x.length;i++){
|
|
4840
|
-
Y.push(mapfun$1(a=>pow(x[i],a),...y));
|
|
4745
|
+
Y.push(mapfun$1(a=>pow$1(x[i],a),...y));
|
|
4841
4746
|
}
|
|
4842
4747
|
return Y;
|
|
4843
4748
|
}
|
|
@@ -4863,229 +4768,469 @@
|
|
|
4863
4768
|
)
|
|
4864
4769
|
};
|
|
4865
4770
|
|
|
4866
|
-
|
|
4867
|
-
|
|
4771
|
+
const {PI, sqrt, cos, sin, acos, pow} = Math;
|
|
4772
|
+
|
|
4773
|
+
const Linear = t => t;
|
|
4774
|
+
const InSin = t => 1 - cos((t * PI) / 2);
|
|
4775
|
+
const OutSin = t => sin((t * PI) / 2);
|
|
4776
|
+
const InOutSin = t => -(cos(PI * t) - 1) / 2;
|
|
4777
|
+
|
|
4778
|
+
const InQuad = t => t**2;
|
|
4779
|
+
const OutQuad = t => 1 - (1-t)**2;
|
|
4780
|
+
const InOutQuad = t => t < 0.5 ? 2 * (t**2) : 1 - (-2 * t + 2)**2 / 2;
|
|
4781
|
+
|
|
4782
|
+
const InCubic = t => t**3;
|
|
4783
|
+
const OutCubic = t => 1 - (1-t)**3;
|
|
4784
|
+
const InOutCubic = t => t < 0.5 ? 4 * (t**3) : 1 - (-2 * t + 2)**3 / 2;
|
|
4785
|
+
|
|
4786
|
+
const InQuart = t => t**4;
|
|
4787
|
+
const OutQuart = t => 1 - (1-t)**4;
|
|
4788
|
+
const InOutQuart = t => t < 0.5 ? 8 * (t**4) : 1 - (-2 * t + 2)**4 / 2;
|
|
4789
|
+
|
|
4790
|
+
const InQuint = t => t**5;
|
|
4791
|
+
const OutQuint = t => 1 - (1-t)**5;
|
|
4792
|
+
const InOutQuint = t => t < 0.5 ? 16 * (t**5) : 1 - (-2 * t + 2)**5 / 2;
|
|
4793
|
+
|
|
4794
|
+
const InExpo = t => t === 0 ? 0 : 2**(10*t - 10);
|
|
4795
|
+
const OutExpo = t => t === 1 ? 1 : 1 - 2**(-10 * t);
|
|
4796
|
+
const InOutExpo = t => t === 0? 0: t === 1? 1: t < 0.5 ? 2**(20 * t - 10) / 2: (2 - 2**(-20 * t + 10)) / 2;
|
|
4797
|
+
|
|
4798
|
+
const InCirc = t => 1 - sqrt(1 - t**2);
|
|
4799
|
+
const OutCirc = t => sqrt(1 - (t-1)**2);
|
|
4800
|
+
const InOutCirc = t => t < 0.5? (1 - sqrt(1 - (2*t)**2)) / 2: (sqrt(1 - (-2*t+2)**2) + 1) / 2;
|
|
4801
|
+
|
|
4802
|
+
const Arc = t => 1 - sin(acos(t));
|
|
4803
|
+
const Back = (t, x = 1) => (t**2) * ((x+1)*t - x);
|
|
4804
|
+
const Elastic = t => -2*pow(2, 10 * (t - 1)) * cos(20 * PI * t / 3 * t);
|
|
4805
|
+
|
|
4806
|
+
const InBack = (t, c1 = 1.70158, c3 = c1 + 1) => c3 * pow(t,3)- c1 * (t**2);
|
|
4807
|
+
const OutBack = (t, c1 = 1.70158, c3 = c1 + 1) => 1 + c3 * pow(t - 1, 3) + c1 * pow(t - 1, 2);
|
|
4808
|
+
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;
|
|
4809
|
+
|
|
4810
|
+
const InElastic = (t, c4 = 2*PI/3) => {
|
|
4811
|
+
return t === 0
|
|
4812
|
+
? 0
|
|
4813
|
+
: t === 1
|
|
4814
|
+
? 1
|
|
4815
|
+
: -pow(2, 10 * t - 10) * sin((t * 10 - 10.75) * c4);
|
|
4816
|
+
};
|
|
4817
|
+
|
|
4818
|
+
const OutElastic = (t, c4 = 2*PI/3) => {
|
|
4819
|
+
return t === 0
|
|
4820
|
+
? 0
|
|
4821
|
+
: t === 1
|
|
4822
|
+
? 1
|
|
4823
|
+
: pow(2, -10 * t) * sin((t * 10 - 0.75) * c4) + 1;
|
|
4824
|
+
};
|
|
4825
|
+
const InOutElastic = (t, c5 = 2 * PI / 4.5) => {
|
|
4826
|
+
return t === 0
|
|
4827
|
+
? 0
|
|
4828
|
+
: t === 1
|
|
4829
|
+
? 1
|
|
4830
|
+
: t < 0.5
|
|
4831
|
+
? -(pow(2, 20 * t - 10) * sin((20 * t - 11.125) * c5)) / 2
|
|
4832
|
+
: (pow(2, -20 * t + 10) * sin((20 * t - 11.125) * c5)) / 2 + 1;
|
|
4833
|
+
};
|
|
4834
|
+
|
|
4835
|
+
const InBounce = (t, n1 = 7.5625, d1 = 2.75) => 1 - OutBounce(1-t, n1, d1);
|
|
4836
|
+
const OutBounce = (t, n1 = 7.5625, d1 = 2.75) => {
|
|
4837
|
+
if(t<1/d1) return n1 * t * t;
|
|
4838
|
+
if(t < 2 / d1) return n1 * (t -= 1.5 / d1) * t + 0.75;
|
|
4839
|
+
if(t < 2.5 / d1) return n1 * (t -= 2.25 / d1) * t + 0.9375;
|
|
4840
|
+
return n1 * (t -= 2.625 / d1) * t + 0.984375;
|
|
4841
|
+
};
|
|
4842
|
+
|
|
4843
|
+
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;
|
|
4844
|
+
|
|
4845
|
+
|
|
4846
|
+
const Step = (t, steps = 5) => Math.floor(t*steps) / steps;
|
|
4847
|
+
const Discret = (t, segments = 5) => Math.ceil(t*segments) / segments;
|
|
4848
|
+
|
|
4849
|
+
class TimeAnimation {
|
|
4850
|
+
constructor(callback, { ease = Linear, step = 50, t0 = 0, start = true, duration = 3000 } = {}) {
|
|
4868
4851
|
this.callback = callback;
|
|
4869
|
-
this.
|
|
4852
|
+
this.state = {
|
|
4870
4853
|
isRunning: false,
|
|
4871
|
-
|
|
4872
|
-
|
|
4854
|
+
animationId: null,
|
|
4855
|
+
startTime: null,
|
|
4856
|
+
ease,
|
|
4873
4857
|
step,
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
started
|
|
4858
|
+
// interval: [t0, t1],
|
|
4859
|
+
autoStart: start,
|
|
4860
|
+
duration
|
|
4878
4861
|
};
|
|
4879
|
-
|
|
4880
|
-
this.
|
|
4862
|
+
|
|
4863
|
+
this.t = 0; // elapsed time
|
|
4864
|
+
this.tx = 0; // normalized [0,1]
|
|
4865
|
+
this.ty = 0; // eased value
|
|
4866
|
+
this.i = 0; // frame index
|
|
4867
|
+
|
|
4868
|
+
if (this.state.autoStart) {
|
|
4869
|
+
this.start();
|
|
4870
|
+
}
|
|
4881
4871
|
}
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4872
|
+
|
|
4873
|
+
// ---- private loop handler ----
|
|
4874
|
+
#tick = () => {
|
|
4875
|
+
this.t += this.state.step;
|
|
4876
|
+
this.i++;
|
|
4877
|
+
|
|
4878
|
+
this.tx = map(this.t, 0, this.state.duration, 0, 1);
|
|
4879
|
+
this.ty = this.state.ease(this.tx);
|
|
4880
|
+
|
|
4881
|
+
this.callback(this);
|
|
4882
|
+
|
|
4883
|
+
if (this.t >= this.state.duration) {
|
|
4884
|
+
clearInterval(this.state.animationId);
|
|
4885
|
+
this.state.isRunning = false;
|
|
4886
|
+
}
|
|
4887
|
+
};
|
|
4888
|
+
|
|
4889
|
+
// ---- core runner ----
|
|
4890
|
+
#run(reset = true) {
|
|
4891
|
+
if (!this.state.isRunning) {
|
|
4892
|
+
if (reset) this.reset(false);
|
|
4893
|
+
|
|
4894
|
+
this.state.isRunning = true;
|
|
4895
|
+
this.state.startTime = Date.now();
|
|
4896
|
+
this.state.animationId = setInterval(this.#tick, this.state.step);
|
|
4890
4897
|
}
|
|
4891
4898
|
return this;
|
|
4892
4899
|
}
|
|
4893
|
-
|
|
4894
|
-
//
|
|
4895
|
-
|
|
4896
|
-
|
|
4900
|
+
|
|
4901
|
+
// ---- lifecycle methods ----
|
|
4902
|
+
start() {
|
|
4903
|
+
return this.#run(true);
|
|
4904
|
+
}
|
|
4905
|
+
|
|
4906
|
+
pause() {
|
|
4907
|
+
if (this.state.isRunning) {
|
|
4908
|
+
clearInterval(this.state.animationId);
|
|
4909
|
+
this.state.isRunning = false;
|
|
4910
|
+
}
|
|
4911
|
+
return this;
|
|
4912
|
+
}
|
|
4913
|
+
|
|
4914
|
+
resume() {
|
|
4915
|
+
return this.#run(false);
|
|
4916
|
+
}
|
|
4917
|
+
|
|
4918
|
+
stop() {
|
|
4919
|
+
this.pause();
|
|
4920
|
+
this.reset(false);
|
|
4921
|
+
return this;
|
|
4922
|
+
}
|
|
4923
|
+
|
|
4924
|
+
reset(restart = true) {
|
|
4925
|
+
this.t = 0;
|
|
4926
|
+
this.tx = 0;
|
|
4927
|
+
this.ty = 0;
|
|
4928
|
+
this.i = 0;
|
|
4929
|
+
|
|
4930
|
+
if (restart) this.start();
|
|
4931
|
+
return this;
|
|
4932
|
+
}
|
|
4933
|
+
}
|
|
4934
|
+
|
|
4935
|
+
// Hook-style factory
|
|
4936
|
+
const animation = (callback, {ease, t0, t1, start, duration} = {}) =>
|
|
4937
|
+
new TimeAnimation(callback, {ease, t0, t1, start, duration});
|
|
4938
|
+
|
|
4939
|
+
class Tick {
|
|
4940
|
+
constructor(ms, fn) {
|
|
4941
|
+
this.ms = ms;
|
|
4942
|
+
this.fn = fn;
|
|
4943
|
+
this.id = null;
|
|
4944
|
+
this.running = false;
|
|
4945
|
+
}
|
|
4946
|
+
|
|
4947
|
+
start() {
|
|
4948
|
+
if (!this.running) {
|
|
4949
|
+
this.running = true;
|
|
4950
|
+
this.id = setInterval(this.fn, this.ms);
|
|
4951
|
+
}
|
|
4952
|
+
return this;
|
|
4953
|
+
}
|
|
4954
|
+
|
|
4955
|
+
stop() {
|
|
4956
|
+
if (this.running) {
|
|
4957
|
+
this.running = false;
|
|
4958
|
+
clearInterval(this.id);
|
|
4959
|
+
this.id = null;
|
|
4960
|
+
}
|
|
4961
|
+
return this;
|
|
4962
|
+
}
|
|
4963
|
+
|
|
4964
|
+
isRunning() {
|
|
4965
|
+
return this.running;
|
|
4966
|
+
}
|
|
4967
|
+
}
|
|
4968
|
+
const tick = (ms, fn) => new Tick(ms, fn);
|
|
4969
|
+
|
|
4970
|
+
class Clock extends Tick {
|
|
4971
|
+
constructor(tickMs = 1000 / 60) {
|
|
4972
|
+
super(tickMs, () => this._tick());
|
|
4973
|
+
this.elapsed = 0;
|
|
4974
|
+
this._lastTime = performance.now();
|
|
4975
|
+
this._callbacks = new Set();
|
|
4976
|
+
}
|
|
4977
|
+
|
|
4978
|
+
_tick() {
|
|
4979
|
+
const now = performance.now();
|
|
4980
|
+
const delta = now - this._lastTime;
|
|
4981
|
+
this.elapsed += delta;
|
|
4982
|
+
this._lastTime = now;
|
|
4983
|
+
|
|
4984
|
+
for (const cb of this._callbacks) {
|
|
4985
|
+
cb({ elapsed: this.elapsed, delta });
|
|
4986
|
+
}
|
|
4987
|
+
}
|
|
4988
|
+
|
|
4989
|
+
onTick(cb) {
|
|
4990
|
+
this._callbacks.add(cb);
|
|
4991
|
+
return () => this._callbacks.delete(cb);
|
|
4992
|
+
}
|
|
4993
|
+
|
|
4994
|
+
reset() {
|
|
4995
|
+
this.elapsed = 0;
|
|
4996
|
+
this._lastTime = performance.now();
|
|
4997
|
+
}
|
|
4998
|
+
|
|
4999
|
+
pause() {
|
|
5000
|
+
super.stop();
|
|
5001
|
+
}
|
|
5002
|
+
|
|
5003
|
+
resume() {
|
|
5004
|
+
this._lastTime = performance.now();
|
|
5005
|
+
super.start();
|
|
5006
|
+
}
|
|
5007
|
+
}
|
|
5008
|
+
|
|
5009
|
+
const clock = (tickMs) => new Clock(tickMs);
|
|
5010
|
+
|
|
5011
|
+
|
|
5012
|
+
/*
|
|
5013
|
+
|
|
5014
|
+
const clock = new Clock(200);
|
|
5015
|
+
|
|
5016
|
+
clock.onTick(({ elapsed, delta }) => {
|
|
5017
|
+
console.log(`Elapsed: ${elapsed.toFixed(0)}ms, Delta: ${delta.toFixed(0)}ms`);
|
|
5018
|
+
});
|
|
5019
|
+
|
|
5020
|
+
clock.start();
|
|
5021
|
+
|
|
5022
|
+
setTimeout(() => clock.pause(), 1000);
|
|
5023
|
+
setTimeout(() => clock.resume(), 2000);
|
|
5024
|
+
|
|
5025
|
+
*/
|
|
5026
|
+
|
|
5027
|
+
class TimeScheduler {
|
|
5028
|
+
constructor(tasks = [], { repeat = 1, loop = false } = {}) {
|
|
5029
|
+
this.tasks = tasks;
|
|
5030
|
+
this.repeat = repeat;
|
|
5031
|
+
this.loop = loop;
|
|
5032
|
+
|
|
5033
|
+
this.stopped = false;
|
|
5034
|
+
this.running = false;
|
|
5035
|
+
|
|
5036
|
+
// lifecycle hooks
|
|
5037
|
+
this.onStart = null;
|
|
5038
|
+
this.onTask = null;
|
|
5039
|
+
this.onEnd = null;
|
|
5040
|
+
}
|
|
5041
|
+
|
|
5042
|
+
async run() {
|
|
5043
|
+
if (this.running) return;
|
|
5044
|
+
this.running = true;
|
|
5045
|
+
this.stopped = false;
|
|
5046
|
+
|
|
5047
|
+
if (this.onStart) this.onStart();
|
|
5048
|
+
|
|
5049
|
+
let repeatCount = this.repeat;
|
|
5050
|
+
|
|
5051
|
+
do {
|
|
5052
|
+
for (const task of this.tasks) {
|
|
5053
|
+
if (this.stopped) return;
|
|
5054
|
+
|
|
5055
|
+
if (Array.isArray(task)) {
|
|
5056
|
+
// Parallel tasks
|
|
5057
|
+
await Promise.all(
|
|
5058
|
+
task.map(({ fn, delay = 0 }) =>
|
|
5059
|
+
new Promise(async (resolve) => {
|
|
5060
|
+
if (delay > 0) await new Promise(r => setTimeout(r, delay));
|
|
5061
|
+
if (this.onTask) this.onTask(fn);
|
|
5062
|
+
await fn();
|
|
5063
|
+
resolve();
|
|
5064
|
+
})
|
|
5065
|
+
)
|
|
5066
|
+
);
|
|
5067
|
+
} else {
|
|
5068
|
+
// Single task
|
|
5069
|
+
const { fn, delay = 0 } = task;
|
|
5070
|
+
if (delay > 0) await new Promise(r => setTimeout(r, delay));
|
|
5071
|
+
if (this.onTask) this.onTask(fn);
|
|
5072
|
+
await fn();
|
|
5073
|
+
}
|
|
5074
|
+
}
|
|
5075
|
+
} while (this.loop && !this.stopped && (repeatCount === Infinity || repeatCount-- > 1));
|
|
5076
|
+
|
|
5077
|
+
if (!this.stopped && this.onEnd) this.onEnd();
|
|
5078
|
+
this.running = false;
|
|
5079
|
+
}
|
|
5080
|
+
|
|
5081
|
+
stop() {
|
|
5082
|
+
this.stopped = true;
|
|
5083
|
+
this.running = false;
|
|
5084
|
+
}
|
|
5085
|
+
|
|
5086
|
+
addTask(task) {
|
|
5087
|
+
this.tasks.push(task);
|
|
5088
|
+
}
|
|
5089
|
+
|
|
5090
|
+
clearTasks() {
|
|
5091
|
+
this.tasks = [];
|
|
5092
|
+
}
|
|
5093
|
+
}
|
|
5094
|
+
|
|
5095
|
+
const Scheduler = (tasks, { repeat = null} = {}) => new TimeScheduler(tasks, { repeat});
|
|
5096
|
+
|
|
5097
|
+
const step_fps = (step_or_fps) => 1000 / step_or_fps;
|
|
5098
|
+
|
|
5099
|
+
const debounce=(fn,delay=1000)=>{
|
|
5100
|
+
return (...args) => setTimeout(()=>fn(...args),delay);
|
|
5101
|
+
};
|
|
5102
|
+
const throttle=(fn,delay)=>{
|
|
5103
|
+
let lastTime=0;
|
|
5104
|
+
return (...args) => {
|
|
5105
|
+
const now = new Date().getTime();
|
|
5106
|
+
if(now-lastTime < delay) return;
|
|
5107
|
+
lastTime = now;
|
|
5108
|
+
fn(...args);
|
|
5109
|
+
}
|
|
5110
|
+
};
|
|
5111
|
+
|
|
5112
|
+
function timeout(ms, fn) {
|
|
5113
|
+
let id;
|
|
5114
|
+
const promise = new Promise((resolve) => {
|
|
5115
|
+
id = setTimeout(() => {
|
|
5116
|
+
if (fn) fn();
|
|
5117
|
+
resolve();
|
|
5118
|
+
}, ms);
|
|
5119
|
+
});
|
|
5120
|
+
|
|
5121
|
+
return {
|
|
5122
|
+
id,
|
|
5123
|
+
clear: () => clearTimeout(id),
|
|
5124
|
+
promise
|
|
5125
|
+
};
|
|
5126
|
+
}
|
|
5127
|
+
|
|
5128
|
+
const sleep= ms => new Promise(res => setTimeout(res, ms));
|
|
5129
|
+
|
|
5130
|
+
// use it with await
|
|
5131
|
+
|
|
5132
|
+
class TimeLoop {
|
|
5133
|
+
constructor(callback, { step = 1000, t0 = 0, t1 = Infinity, autoplay = true } = {}) {
|
|
5134
|
+
this.callback = callback;
|
|
5135
|
+
this.cache = {
|
|
5136
|
+
isRunning: false,
|
|
5137
|
+
id: null,
|
|
5138
|
+
last_tick: null,
|
|
5139
|
+
step,
|
|
5140
|
+
t0,
|
|
5141
|
+
t1,
|
|
5142
|
+
autoplay,
|
|
5143
|
+
pauseTime: null,
|
|
5144
|
+
frame : 0,
|
|
5145
|
+
};
|
|
5146
|
+
|
|
5147
|
+
if (autoplay) {
|
|
5148
|
+
t0 ? this.startAfter(t0) : this.start();
|
|
5149
|
+
if (t1 !== Infinity) this.stopAfter(t1);
|
|
5150
|
+
}
|
|
5151
|
+
}
|
|
5152
|
+
|
|
5153
|
+
get frame(){
|
|
5154
|
+
return this.cache.frame;
|
|
5155
|
+
}
|
|
5156
|
+
get elapsed(){
|
|
5157
|
+
return this.cache.elapsed;
|
|
5158
|
+
}
|
|
5159
|
+
|
|
4897
5160
|
start() {
|
|
4898
5161
|
if (!this.cache.isRunning) {
|
|
4899
|
-
this.
|
|
5162
|
+
this.cache.frame = 0;
|
|
4900
5163
|
this.cache.isRunning = true;
|
|
4901
|
-
this.cache.
|
|
5164
|
+
this.cache.last_tick = Date.now();
|
|
4902
5165
|
this.animate();
|
|
4903
5166
|
}
|
|
4904
5167
|
return this;
|
|
4905
5168
|
}
|
|
5169
|
+
|
|
4906
5170
|
pause() {
|
|
4907
5171
|
if (this.cache.isRunning) {
|
|
4908
|
-
clearTimeout(this.cache.
|
|
5172
|
+
clearTimeout(this.cache.id);
|
|
4909
5173
|
this.cache.isRunning = false;
|
|
5174
|
+
this.cache.pauseTime = Date.now();
|
|
4910
5175
|
}
|
|
4911
5176
|
return this;
|
|
4912
5177
|
}
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
this.
|
|
5178
|
+
|
|
5179
|
+
resume() {
|
|
5180
|
+
if (!this.cache.isRunning) {
|
|
5181
|
+
this.cache.isRunning = true;
|
|
5182
|
+
if (this.cache.pauseTime) {
|
|
5183
|
+
// adjust start time so delta stays consistent
|
|
5184
|
+
const pausedDuration = Date.now() - this.cache.pauseTime;
|
|
5185
|
+
this.cache.last_tick += pausedDuration;
|
|
5186
|
+
}
|
|
5187
|
+
this.animate();
|
|
5188
|
+
}
|
|
4916
5189
|
return this;
|
|
4917
5190
|
}
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
this.
|
|
5191
|
+
|
|
5192
|
+
stop() {
|
|
5193
|
+
this.pause();
|
|
5194
|
+
this.cache.frame = 0;
|
|
4921
5195
|
return this;
|
|
4922
5196
|
}
|
|
4923
|
-
|
|
4924
|
-
|
|
5197
|
+
|
|
5198
|
+
startAfter(t = 1000) {
|
|
5199
|
+
setTimeout(() => this.start(), t);
|
|
4925
5200
|
return this;
|
|
4926
5201
|
}
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
5202
|
+
|
|
5203
|
+
stopAfter(t = 1000) {
|
|
5204
|
+
setTimeout(() => this.stop(), t);
|
|
5205
|
+
return this;
|
|
4930
5206
|
}
|
|
5207
|
+
|
|
4931
5208
|
animate = () => {
|
|
4932
5209
|
if (this.cache.isRunning) {
|
|
4933
5210
|
const now = Date.now();
|
|
4934
|
-
const delta = now - this.cache.
|
|
4935
|
-
|
|
5211
|
+
const delta = now - this.cache.last_tick;
|
|
5212
|
+
|
|
5213
|
+
if (delta >= this.cache.step) {
|
|
5214
|
+
this.cache.elapsed = now - (this.cache.t0 || 0);
|
|
4936
5215
|
this.callback(this);
|
|
4937
|
-
this.
|
|
4938
|
-
this.cache.
|
|
5216
|
+
this.cache.frame++;
|
|
5217
|
+
this.cache.last_tick = now - (delta % this.cache.step);
|
|
4939
5218
|
}
|
|
4940
|
-
this.cache.AnimationId = setTimeout(this.animate, 0);
|
|
4941
|
-
} }
|
|
4942
|
-
}
|
|
4943
|
-
const useFps = fps => 1000/fps;
|
|
4944
|
-
const useTimeLoop = (callback, step, startTime, endTime, started) => new ZikoTimeLoop(callback, step, startTime, endTime, started);
|
|
4945
|
-
|
|
4946
|
-
const Ease={
|
|
4947
|
-
Linear:function(t){
|
|
4948
|
-
return t;
|
|
4949
|
-
},
|
|
4950
|
-
InSin(t){
|
|
4951
|
-
return 1 - Math.cos((t * Math.PI) / 2);
|
|
4952
|
-
},
|
|
4953
|
-
OutSin(t){
|
|
4954
|
-
return Math.sin((t * Math.PI) / 2);
|
|
4955
|
-
},
|
|
4956
|
-
InOutSin(t){
|
|
4957
|
-
return -(Math.cos(Math.PI * t) - 1) / 2;
|
|
4958
|
-
},
|
|
4959
|
-
InQuad(t){
|
|
4960
|
-
return t**2;
|
|
4961
|
-
},
|
|
4962
|
-
OutQuad(t){
|
|
4963
|
-
return 1 - Math.pow((1 - t),2)
|
|
4964
|
-
},
|
|
4965
|
-
InOutQuad(t){
|
|
4966
|
-
return t < 0.5 ? 2 * Math.pow(t,2) : 1 - Math.pow(-2 * t + 2, 2) / 2;
|
|
4967
|
-
},
|
|
4968
|
-
InCubic(t){
|
|
4969
|
-
return t**3;
|
|
4970
|
-
},
|
|
4971
|
-
OutCubic(t){
|
|
4972
|
-
return 1 - Math.pow((1 - t),3)
|
|
4973
|
-
},
|
|
4974
|
-
InOutCubic(t){
|
|
4975
|
-
return t < 0.5 ? 4 * Math.pow(t,3) : 1 - Math.pow(-2 * t + 2, 3) / 2;
|
|
4976
|
-
},
|
|
4977
|
-
InQuart(t){
|
|
4978
|
-
return t**4;
|
|
4979
|
-
},
|
|
4980
|
-
OutQuart(t){
|
|
4981
|
-
return 1 - Math.pow((1 - t),4);
|
|
4982
|
-
},
|
|
4983
|
-
InOutQuart(t){
|
|
4984
|
-
return t < 0.5 ? 8 * Math.pow(t,4) : 1 - Math.pow(-2 * t + 2, 4) / 2;
|
|
4985
|
-
},
|
|
4986
|
-
InQuint(t){
|
|
4987
|
-
return t**5;
|
|
4988
|
-
},
|
|
4989
|
-
OutQuint(t){
|
|
4990
|
-
return 1 - Math.pow((1 - t),5);
|
|
4991
|
-
},
|
|
4992
|
-
InOutQuint(t){
|
|
4993
|
-
return t < 0.5 ? 16 * Math.pow(t,5) : 1 - Math.pow(-2 * t + 2, 5) / 2;
|
|
4994
|
-
},
|
|
4995
|
-
InExpo(t){
|
|
4996
|
-
return t === 0 ? 0 : Math.pow(2, 10 * t - 10);
|
|
4997
|
-
},
|
|
4998
|
-
OutExpo(t){
|
|
4999
|
-
return t === 1 ? 1 : 1 - Math.pow(2, -10 * t);
|
|
5000
|
-
},
|
|
5001
|
-
InOutExpo(t){
|
|
5002
|
-
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;
|
|
5003
|
-
},
|
|
5004
|
-
InCirc(t){
|
|
5005
|
-
return 1 - Math.sqrt(1 - Math.pow(t, 2));
|
|
5006
|
-
},
|
|
5007
|
-
OutCirc(t){
|
|
5008
|
-
return Math.sqrt(1 - Math.pow(t - 1, 2));
|
|
5009
|
-
},
|
|
5010
|
-
InOutCic(t){
|
|
5011
|
-
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;
|
|
5012
|
-
},
|
|
5013
|
-
Arc(t){
|
|
5014
|
-
return 1 - Math.sin(Math.acos(t));
|
|
5015
|
-
},
|
|
5016
|
-
Back(t){
|
|
5017
|
-
// To Be Changed
|
|
5018
|
-
let x=1;
|
|
5019
|
-
return Math.pow(t, 2) * ((x + 1) * t - x);
|
|
5020
|
-
},
|
|
5021
|
-
Elastic(t){
|
|
5022
|
-
return -2*Math.pow(2, 10 * (t - 1)) * Math.cos(20 * Math.PI * t / 3 * t);
|
|
5023
|
-
},
|
|
5024
|
-
InBack(t){
|
|
5025
|
-
const c1 = 1.70158;
|
|
5026
|
-
const c3 = c1 + 1;
|
|
5027
|
-
return c3 *Math.pow(t,3)- c1 * (t**2);
|
|
5028
|
-
},
|
|
5029
|
-
OutBack(t){
|
|
5030
|
-
const c1 = 1.70158;
|
|
5031
|
-
const c3 = c1 + 1;
|
|
5032
|
-
return 1 + c3 * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2);
|
|
5033
|
-
},
|
|
5034
|
-
InOutBack(t){
|
|
5035
|
-
const c1 = 1.70158;
|
|
5036
|
-
const c2 = c1 * 1.525;
|
|
5037
|
-
return t < 0.5
|
|
5038
|
-
? (Math.pow(2 * t, 2) * ((c2 + 1) * 2 * t - c2)) / 2
|
|
5039
|
-
: (Math.pow(2 * t - 2, 2) * ((c2 + 1) * (t * 2 - 2) + c2) + 2) / 2;
|
|
5040
|
-
},
|
|
5041
|
-
InElastic(t){
|
|
5042
|
-
const c4 = (2 * Math.PI) / 3;return t === 0
|
|
5043
|
-
? 0
|
|
5044
|
-
: t === 1
|
|
5045
|
-
? 1
|
|
5046
|
-
: -Math.pow(2, 10 * t - 10) * Math.sin((t * 10 - 10.75) * c4);
|
|
5047
|
-
},
|
|
5048
|
-
OutElastic(t){
|
|
5049
|
-
const c4 = (2 * Math.PI) / 3;
|
|
5050
|
-
return t === 0
|
|
5051
|
-
? 0
|
|
5052
|
-
: t === 1
|
|
5053
|
-
? 1
|
|
5054
|
-
: Math.pow(2, -10 * t) * Math.sin((t * 10 - 0.75) * c4) + 1;
|
|
5055
|
-
},
|
|
5056
|
-
InOutElastic(t){
|
|
5057
|
-
const c5 = (2 * Math.PI) / 4.5;
|
|
5058
|
-
return t === 0
|
|
5059
|
-
? 0
|
|
5060
|
-
: t === 1
|
|
5061
|
-
? 1
|
|
5062
|
-
: t < 0.5
|
|
5063
|
-
? -(Math.pow(2, 20 * t - 10) * Math.sin((20 * t - 11.125) * c5)) / 2
|
|
5064
|
-
: (Math.pow(2, -20 * t + 10) * Math.sin((20 * t - 11.125) * c5)) / 2 + 1;
|
|
5065
|
-
},
|
|
5066
|
-
InBounce(t){
|
|
5067
|
-
return 1 - Ease.OutBounce(1-t);
|
|
5068
|
-
},
|
|
5069
|
-
OutBounce(t){
|
|
5070
|
-
const n1 = 7.5625;
|
|
5071
|
-
const d1 = 2.75;
|
|
5072
|
-
if (t < 1 / d1) {
|
|
5073
|
-
return n1 * t * t;
|
|
5074
|
-
} else if (t < 2 / d1) {
|
|
5075
|
-
return n1 * (t -= 1.5 / d1) * t + 0.75;
|
|
5076
|
-
} else if (t < 2.5 / d1) {
|
|
5077
|
-
return n1 * (t -= 2.25 / d1) * t + 0.9375;
|
|
5078
|
-
} else {
|
|
5079
|
-
return n1 * (t -= 2.625 / d1) * t + 0.984375;
|
|
5080
|
-
}
|
|
5081
5219
|
|
|
5082
|
-
|
|
5083
|
-
InOutBounce(t){
|
|
5084
|
-
return t < 0.5
|
|
5085
|
-
? (1 - Ease.OutBounce(1 - 2 * t)) / 2
|
|
5086
|
-
: (1 + Ease.OutBounce(2 * t - 1)) / 2;
|
|
5220
|
+
this.cache.id = setTimeout(this.animate, 0);
|
|
5087
5221
|
}
|
|
5088
|
-
|
|
5222
|
+
}
|
|
5223
|
+
}
|
|
5224
|
+
|
|
5225
|
+
const loop = (callback, options = {}) => new TimeLoop(callback, options);
|
|
5226
|
+
|
|
5227
|
+
|
|
5228
|
+
// Helpers
|
|
5229
|
+
// const useFps = (fps) => 1000 / fps;
|
|
5230
|
+
|
|
5231
|
+
// const _loop = loop( e => {
|
|
5232
|
+
// console.log("Frame:", e.frame, " Elapsed: ", e.elapsed);
|
|
5233
|
+
// });
|
|
5089
5234
|
|
|
5090
5235
|
const time_memory_Taken = (callback) => {
|
|
5091
5236
|
const t0 = Date.now();
|
|
@@ -5128,6 +5273,7 @@
|
|
|
5128
5273
|
}
|
|
5129
5274
|
};
|
|
5130
5275
|
|
|
5276
|
+
// import Ease from "./ease.js";
|
|
5131
5277
|
const wait=(delayInMS)=>{
|
|
5132
5278
|
return new Promise((resolve) => setTimeout(resolve, delayInMS));
|
|
5133
5279
|
};
|
|
@@ -5138,93 +5284,6 @@
|
|
|
5138
5284
|
return r;
|
|
5139
5285
|
};
|
|
5140
5286
|
|
|
5141
|
-
class ZikoTimeAnimation{
|
|
5142
|
-
constructor(callback,ease=Ease.Linear,step=50,{t=[0,null],start=true,duration=3000}={}){
|
|
5143
|
-
this.cache={
|
|
5144
|
-
isRunning:false,
|
|
5145
|
-
AnimationId:null,
|
|
5146
|
-
startTime:null,
|
|
5147
|
-
ease,
|
|
5148
|
-
step,
|
|
5149
|
-
intervall:t,
|
|
5150
|
-
started:start,
|
|
5151
|
-
duration
|
|
5152
|
-
};
|
|
5153
|
-
this.t=0;
|
|
5154
|
-
this.tx=0;
|
|
5155
|
-
this.ty=0;
|
|
5156
|
-
this.i=0;
|
|
5157
|
-
this.callback=callback;
|
|
5158
|
-
}
|
|
5159
|
-
#animation_handler(){
|
|
5160
|
-
this.t+=this.cache.step;
|
|
5161
|
-
this.i++;
|
|
5162
|
-
this.tx=map(this.t,0,this.cache.duration,0,1);
|
|
5163
|
-
this.ty=this.cache.ease(this.tx);
|
|
5164
|
-
this.callback(this);
|
|
5165
|
-
if(this.t>=this.cache.duration){
|
|
5166
|
-
clearInterval(this.cache.AnimationId);
|
|
5167
|
-
this.cache.isRunning=false;
|
|
5168
|
-
}
|
|
5169
|
-
}
|
|
5170
|
-
reset(restart=true){
|
|
5171
|
-
this.t=0;
|
|
5172
|
-
this.tx=0;
|
|
5173
|
-
this.ty=0;
|
|
5174
|
-
this.i=0;
|
|
5175
|
-
if(restart)this.start();
|
|
5176
|
-
return this;
|
|
5177
|
-
}
|
|
5178
|
-
#animate(reset=true){
|
|
5179
|
-
if(!this.cache.isRunning){
|
|
5180
|
-
if(reset)this.reset(false);
|
|
5181
|
-
this.cache.isRunning=true;
|
|
5182
|
-
this.cache.startTime = Date.now();
|
|
5183
|
-
this.cache.AnimationId=setInterval(this.#animation_handler.bind(this),this.cache.step);
|
|
5184
|
-
}
|
|
5185
|
-
return this;
|
|
5186
|
-
}
|
|
5187
|
-
start(){
|
|
5188
|
-
this.#animate(true);
|
|
5189
|
-
return this;
|
|
5190
|
-
}
|
|
5191
|
-
pause(){
|
|
5192
|
-
if (this.cache.isRunning) {
|
|
5193
|
-
clearTimeout(this.cache.AnimationId);
|
|
5194
|
-
this.cache.isRunning = false;
|
|
5195
|
-
}
|
|
5196
|
-
return this;
|
|
5197
|
-
}
|
|
5198
|
-
resume(){
|
|
5199
|
-
this.#animate(false);
|
|
5200
|
-
return this;
|
|
5201
|
-
}
|
|
5202
|
-
stop(){
|
|
5203
|
-
this.pause();
|
|
5204
|
-
this.reset(false);
|
|
5205
|
-
return this;
|
|
5206
|
-
}
|
|
5207
|
-
// clear(){
|
|
5208
|
-
// }
|
|
5209
|
-
// stream(){
|
|
5210
|
-
// }
|
|
5211
|
-
}
|
|
5212
|
-
|
|
5213
|
-
const useAnimation=(callback,ease=Ease.Linear,step=50,config)=>new ZikoTimeAnimation(callback,ease=Ease.Linear,step=50,config);
|
|
5214
|
-
|
|
5215
|
-
const debounce=(fn,delay=1000)=>{
|
|
5216
|
-
return (...args) => setTimeout(()=>fn(...args),delay);
|
|
5217
|
-
};
|
|
5218
|
-
const throttle=(fn,delay)=>{
|
|
5219
|
-
let lastTime=0;
|
|
5220
|
-
return (...args) => {
|
|
5221
|
-
const now = new Date().getTime();
|
|
5222
|
-
if(now-lastTime < delay) return;
|
|
5223
|
-
lastTime = now;
|
|
5224
|
-
fn(...args);
|
|
5225
|
-
}
|
|
5226
|
-
};
|
|
5227
|
-
|
|
5228
5287
|
class ZikoApp {
|
|
5229
5288
|
constructor({head = null, wrapper = null, target = null}){
|
|
5230
5289
|
this.head = head;
|
|
@@ -5440,6 +5499,70 @@
|
|
|
5440
5499
|
return commonPath;
|
|
5441
5500
|
}
|
|
5442
5501
|
|
|
5502
|
+
function useDerived(deriveFn, sources) {
|
|
5503
|
+
let value = deriveFn(...sources.map(s => s().value));
|
|
5504
|
+
const subscribers = new Set();
|
|
5505
|
+
let paused = false;
|
|
5506
|
+
|
|
5507
|
+
function getValue() {
|
|
5508
|
+
return {
|
|
5509
|
+
value,
|
|
5510
|
+
isStateGetter: () => true,
|
|
5511
|
+
_subscribe: (fn, UIElement) => {
|
|
5512
|
+
subscribers.add(fn);
|
|
5513
|
+
|
|
5514
|
+
const observer = new MutationObserver(() => {
|
|
5515
|
+
if (!document.body.contains(UIElement.element)) {
|
|
5516
|
+
subscribers.delete(fn);
|
|
5517
|
+
observer.disconnect();
|
|
5518
|
+
}
|
|
5519
|
+
});
|
|
5520
|
+
|
|
5521
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
5522
|
+
},
|
|
5523
|
+
};
|
|
5524
|
+
}
|
|
5525
|
+
|
|
5526
|
+
function setValue(newValue) {
|
|
5527
|
+
if (paused) return;
|
|
5528
|
+
if (typeof newValue === "function") newValue = newValue(value);
|
|
5529
|
+
if (newValue !== value) {
|
|
5530
|
+
value = newValue;
|
|
5531
|
+
subscribers.forEach(fn => fn(value));
|
|
5532
|
+
}
|
|
5533
|
+
}
|
|
5534
|
+
|
|
5535
|
+
const controller = {
|
|
5536
|
+
pause: () => { paused = true; },
|
|
5537
|
+
resume: () => { paused = false; },
|
|
5538
|
+
clear: () => { subscribers.clear(); },
|
|
5539
|
+
force: (newValue) => {
|
|
5540
|
+
if (typeof newValue === "function") newValue = newValue(value);
|
|
5541
|
+
value = newValue;
|
|
5542
|
+
subscribers.forEach(fn => fn(value));
|
|
5543
|
+
},
|
|
5544
|
+
getSubscribers: () => new Set(subscribers),
|
|
5545
|
+
};
|
|
5546
|
+
|
|
5547
|
+
// Subscribe to source states
|
|
5548
|
+
sources.forEach(source => {
|
|
5549
|
+
const srcValue = source(); // getValue()
|
|
5550
|
+
srcValue._subscribe(() => {
|
|
5551
|
+
if (!paused) {
|
|
5552
|
+
const newVal = deriveFn(...sources.map(s => s().value));
|
|
5553
|
+
if (newVal !== value) {
|
|
5554
|
+
value = newVal;
|
|
5555
|
+
subscribers.forEach(fn => fn(value));
|
|
5556
|
+
}
|
|
5557
|
+
}
|
|
5558
|
+
}, { element: document.body }); // dummy UIElement
|
|
5559
|
+
});
|
|
5560
|
+
|
|
5561
|
+
return [getValue, setValue, controller];
|
|
5562
|
+
}
|
|
5563
|
+
|
|
5564
|
+
const useReactive = (nested_value) => mapfun$1(n => useState(n), nested_value);
|
|
5565
|
+
|
|
5443
5566
|
class ZikoUseChannel{
|
|
5444
5567
|
constructor(name = ""){
|
|
5445
5568
|
this.channel = new BroadcastChannel(name);
|
|
@@ -5679,27 +5802,67 @@
|
|
|
5679
5802
|
}
|
|
5680
5803
|
|
|
5681
5804
|
exports.App = App;
|
|
5805
|
+
exports.Arc = Arc;
|
|
5806
|
+
exports.Back = Back;
|
|
5682
5807
|
exports.Base = Base;
|
|
5683
5808
|
exports.Canvas = Canvas;
|
|
5809
|
+
exports.Clock = Clock;
|
|
5684
5810
|
exports.Combinaison = Combinaison;
|
|
5685
5811
|
exports.Complex = Complex;
|
|
5812
|
+
exports.Discret = Discret;
|
|
5686
5813
|
exports.E = E;
|
|
5687
5814
|
exports.EPSILON = EPSILON;
|
|
5688
|
-
exports.
|
|
5815
|
+
exports.Elastic = Elastic;
|
|
5689
5816
|
exports.FileBasedRouting = FileBasedRouting;
|
|
5690
5817
|
exports.Flex = Flex;
|
|
5691
5818
|
exports.Grid = Grid$1;
|
|
5692
5819
|
exports.HTMLWrapper = HTMLWrapper;
|
|
5820
|
+
exports.InBack = InBack;
|
|
5821
|
+
exports.InBounce = InBounce;
|
|
5822
|
+
exports.InCirc = InCirc;
|
|
5823
|
+
exports.InCubic = InCubic;
|
|
5824
|
+
exports.InElastic = InElastic;
|
|
5825
|
+
exports.InExpo = InExpo;
|
|
5826
|
+
exports.InOutBack = InOutBack;
|
|
5827
|
+
exports.InOutBounce = InOutBounce;
|
|
5828
|
+
exports.InOutCirc = InOutCirc;
|
|
5829
|
+
exports.InOutCubic = InOutCubic;
|
|
5830
|
+
exports.InOutElastic = InOutElastic;
|
|
5831
|
+
exports.InOutExpo = InOutExpo;
|
|
5832
|
+
exports.InOutQuad = InOutQuad;
|
|
5833
|
+
exports.InOutQuart = InOutQuart;
|
|
5834
|
+
exports.InOutQuint = InOutQuint;
|
|
5835
|
+
exports.InOutSin = InOutSin;
|
|
5836
|
+
exports.InQuad = InQuad;
|
|
5837
|
+
exports.InQuart = InQuart;
|
|
5838
|
+
exports.InQuint = InQuint;
|
|
5839
|
+
exports.InSin = InSin;
|
|
5840
|
+
exports.Linear = Linear;
|
|
5693
5841
|
exports.Logic = Logic$1;
|
|
5694
5842
|
exports.Matrix = Matrix;
|
|
5695
|
-
exports.
|
|
5843
|
+
exports.OutBack = OutBack;
|
|
5844
|
+
exports.OutBounce = OutBounce;
|
|
5845
|
+
exports.OutCirc = OutCirc;
|
|
5846
|
+
exports.OutCubic = OutCubic;
|
|
5847
|
+
exports.OutElastic = OutElastic;
|
|
5848
|
+
exports.OutExpo = OutExpo;
|
|
5849
|
+
exports.OutQuad = OutQuad;
|
|
5850
|
+
exports.OutQuart = OutQuart;
|
|
5851
|
+
exports.OutQuint = OutQuint;
|
|
5852
|
+
exports.OutSin = OutSin;
|
|
5853
|
+
exports.PI = PI$2;
|
|
5696
5854
|
exports.Permutation = Permutation;
|
|
5697
5855
|
exports.Random = Random;
|
|
5698
5856
|
exports.SPA = SPA;
|
|
5699
5857
|
exports.SVGWrapper = SVGWrapper;
|
|
5700
|
-
exports.
|
|
5858
|
+
exports.Scheduler = Scheduler;
|
|
5859
|
+
exports.Step = Step;
|
|
5701
5860
|
exports.Suspense = Suspense;
|
|
5702
5861
|
exports.Svg = Svg;
|
|
5862
|
+
exports.Tick = Tick;
|
|
5863
|
+
exports.TimeAnimation = TimeAnimation;
|
|
5864
|
+
exports.TimeLoop = TimeLoop;
|
|
5865
|
+
exports.TimeScheduler = TimeScheduler;
|
|
5703
5866
|
exports.UIElement = UIElement;
|
|
5704
5867
|
exports.UINode = UINode;
|
|
5705
5868
|
exports.Utils = Utils;
|
|
@@ -5733,10 +5896,11 @@
|
|
|
5733
5896
|
exports.__ZikoEvent__ = __ZikoEvent__;
|
|
5734
5897
|
exports.abs = abs;
|
|
5735
5898
|
exports.accum = accum;
|
|
5736
|
-
exports.acos = acos;
|
|
5899
|
+
exports.acos = acos$1;
|
|
5737
5900
|
exports.acosh = acosh;
|
|
5738
5901
|
exports.acot = acot;
|
|
5739
5902
|
exports.add = add;
|
|
5903
|
+
exports.animation = animation;
|
|
5740
5904
|
exports.arange = arange;
|
|
5741
5905
|
exports.arr2str = arr2str;
|
|
5742
5906
|
exports.asin = asin;
|
|
@@ -5758,14 +5922,13 @@
|
|
|
5758
5922
|
exports.cartesianProduct = cartesianProduct;
|
|
5759
5923
|
exports.ceil = ceil;
|
|
5760
5924
|
exports.clamp = clamp;
|
|
5925
|
+
exports.clock = clock;
|
|
5761
5926
|
exports.combinaison = combinaison;
|
|
5762
5927
|
exports.complex = complex;
|
|
5763
|
-
exports.cos = cos;
|
|
5928
|
+
exports.cos = cos$1;
|
|
5764
5929
|
exports.cosh = cosh;
|
|
5765
5930
|
exports.cot = cot;
|
|
5766
5931
|
exports.coth = coth;
|
|
5767
|
-
exports.count = count;
|
|
5768
|
-
exports.countWords = countWords;
|
|
5769
5932
|
exports.csc = csc;
|
|
5770
5933
|
exports.csv2arr = csv2arr;
|
|
5771
5934
|
exports.csv2json = csv2json;
|
|
@@ -5784,6 +5947,7 @@
|
|
|
5784
5947
|
exports.hypot = hypot;
|
|
5785
5948
|
exports.inRange = inRange;
|
|
5786
5949
|
exports.isApproximatlyEqual = isApproximatlyEqual;
|
|
5950
|
+
exports.isStateGetter = isStateGetter;
|
|
5787
5951
|
exports.json2arr = json2arr;
|
|
5788
5952
|
exports.json2css = json2css;
|
|
5789
5953
|
exports.json2csv = json2csv;
|
|
@@ -5796,6 +5960,7 @@
|
|
|
5796
5960
|
exports.linspace = linspace;
|
|
5797
5961
|
exports.ln = ln;
|
|
5798
5962
|
exports.logspace = logspace;
|
|
5963
|
+
exports.loop = loop;
|
|
5799
5964
|
exports.map = map;
|
|
5800
5965
|
exports.mapfun = mapfun$1;
|
|
5801
5966
|
exports.matrix = matrix;
|
|
@@ -5811,23 +5976,23 @@
|
|
|
5811
5976
|
exports.obj2str = obj2str;
|
|
5812
5977
|
exports.ones = ones;
|
|
5813
5978
|
exports.pgcd = pgcd;
|
|
5814
|
-
exports.pow = pow;
|
|
5979
|
+
exports.pow = pow$1;
|
|
5815
5980
|
exports.powerSet = powerSet;
|
|
5816
5981
|
exports.ppcm = ppcm;
|
|
5817
5982
|
exports.preload = preload;
|
|
5818
5983
|
exports.prod = prod;
|
|
5819
5984
|
exports.rad2deg = rad2deg;
|
|
5820
|
-
exports.removeExtraSpace = removeExtraSpace;
|
|
5821
5985
|
exports.round = round;
|
|
5822
5986
|
exports.sec = sec;
|
|
5823
5987
|
exports.sig = sig;
|
|
5824
5988
|
exports.sign = sign;
|
|
5825
|
-
exports.sin = sin;
|
|
5989
|
+
exports.sin = sin$1;
|
|
5826
5990
|
exports.sinc = sinc;
|
|
5827
5991
|
exports.sinh = sinh;
|
|
5828
|
-
exports.
|
|
5992
|
+
exports.sleep = sleep;
|
|
5993
|
+
exports.sqrt = sqrt$1;
|
|
5829
5994
|
exports.sqrtn = sqrtn;
|
|
5830
|
-
exports.
|
|
5995
|
+
exports.step_fps = step_fps;
|
|
5831
5996
|
exports.sub = sub;
|
|
5832
5997
|
exports.subSet = subSet;
|
|
5833
5998
|
exports.sum = sum;
|
|
@@ -5840,26 +6005,28 @@
|
|
|
5840
6005
|
exports.tanh = tanh;
|
|
5841
6006
|
exports.text = text;
|
|
5842
6007
|
exports.throttle = throttle;
|
|
6008
|
+
exports.tick = tick;
|
|
5843
6009
|
exports.timeTaken = timeTaken;
|
|
5844
6010
|
exports.time_memory_Taken = time_memory_Taken;
|
|
5845
|
-
exports.
|
|
6011
|
+
exports.timeout = timeout;
|
|
5846
6012
|
exports.useChannel = useChannel;
|
|
5847
6013
|
exports.useCustomEvent = useCustomEvent;
|
|
6014
|
+
exports.useDerived = useDerived;
|
|
5848
6015
|
exports.useEventEmitter = useEventEmitter;
|
|
5849
6016
|
exports.useFavIcon = useFavIcon;
|
|
5850
|
-
exports.useFps = useFps;
|
|
5851
6017
|
exports.useHashEvent = useHashEvent;
|
|
5852
6018
|
exports.useHead = useHead;
|
|
5853
6019
|
exports.useInputEvent = useInputEvent;
|
|
5854
6020
|
exports.useLocaleStorage = useLocaleStorage;
|
|
5855
6021
|
exports.useMediaQuery = useMediaQuery;
|
|
5856
6022
|
exports.useMeta = useMeta;
|
|
6023
|
+
exports.useReactive = useReactive;
|
|
5857
6024
|
exports.useRoot = useRoot;
|
|
5858
6025
|
exports.useSessionStorage = useSessionStorage;
|
|
6026
|
+
exports.useState = useState;
|
|
5859
6027
|
exports.useSuccesifKeys = useSuccesifKeys;
|
|
5860
6028
|
exports.useSwipeEvent = useSwipeEvent;
|
|
5861
6029
|
exports.useThread = useThread;
|
|
5862
|
-
exports.useTimeLoop = useTimeLoop;
|
|
5863
6030
|
exports.useTitle = useTitle;
|
|
5864
6031
|
exports.wait = wait;
|
|
5865
6032
|
exports.waitForUIElm = waitForUIElm;
|