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.js CHANGED
@@ -2,7 +2,7 @@
2
2
  /*
3
3
  Project: ziko.js
4
4
  Author: Zakaria Elalaoui
5
- Date : Mon Aug 18 2025 11:00:54 GMT+0100 (UTC+01:00)
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
@@ -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$1, E } = Math;
17
+ const { PI: PI$2, E } = Math;
18
18
  const EPSILON=Number.EPSILON;
19
19
 
20
- const {PI, cos: cos$1, sin: sin$1, tan: tan$1, acos: acos$1, 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;
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$1,
23
- sin: sin$1,
22
+ cos: cos$2,
23
+ sin: sin$2,
24
24
  tan: tan$1,
25
- sinc: x => sin$1(PI*x)/(PI*x),
26
- sec: x => 1/cos$1(x),
27
- csc: x => 1/sin$1(x),
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$1,
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 = Str.isCamelCase(name) ? Str.camel2hyphencase(name) : 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 = Str.isCamelCase(name) ? Str.camel2hyphencase(name) : 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();
@@ -1234,7 +1293,7 @@
1234
1293
 
1235
1294
  };
1236
1295
 
1237
- function __addItem__(adder, pusher, ...ele) {
1296
+ async function __addItem__(adder, pusher, ...ele) {
1238
1297
  if (this.cache.isFrozzen) {
1239
1298
  console.warn("You can't append new item to frozzen element");
1240
1299
  return this;
@@ -1260,6 +1319,13 @@
1260
1319
  ele[i].target = this.element;
1261
1320
  this.items[pusher](ele[i]);
1262
1321
  }
1322
+ else if(ele[i] instanceof Promise){
1323
+ const UIEle = await ele[i];
1324
+ UIEle.cache.parent = this;
1325
+ this.element?.[adder](UIEle.element);
1326
+ UIEle.target = this.element;
1327
+ this.items[pusher](UIEle);
1328
+ }
1263
1329
  else if (ele[i] instanceof Object) {
1264
1330
  if (ele[i]?.style) this.style(ele[i]?.style);
1265
1331
  if (ele[i]?.attr) {
@@ -1700,19 +1766,38 @@
1700
1766
  },
1701
1767
  };
1702
1768
 
1703
- // Process width and height
1704
1769
  const StyleMethods = {
1705
1770
  style(styles){
1706
- Object.assign(this.element.style, styles);
1771
+ for(let key in styles){
1772
+ const value = styles[key];
1773
+ if(isStateGetter(value)){
1774
+ const getter = value();
1775
+ Object.assign(this.element.style, {[key] : getter.value});
1776
+ getter._subscribe(
1777
+ (newValue) => {
1778
+ console.log({newValue});
1779
+ Object.assign(this.element.style, {[key] : newValue});
1780
+ },
1781
+ // this
1782
+ );
1783
+ }
1784
+ else Object.assign(this.element.style, {[key] : value});
1785
+ }
1707
1786
  return this;
1708
1787
  },
1709
1788
  size(width, height){
1710
1789
  return this.style({width, height})
1790
+ },
1791
+ hide(){
1792
+
1793
+ },
1794
+ show(){
1795
+
1711
1796
  },
1712
1797
  animate(keyframe, {duration=1000, iterations=1, easing="ease"}={}){
1713
1798
  this.element?.animate(keyframe,{duration, iterations, easing});
1714
1799
  return this;
1715
- }
1800
+ }
1716
1801
  };
1717
1802
 
1718
1803
  function EVENT_CONTROLLER(e,EVENT,setter,push_object){
@@ -3119,18 +3204,14 @@
3119
3204
  let type ;
3120
3205
  if(HTMLTags.includes(tag)) type = 'html';
3121
3206
  if(SVGTags.includes(tag)) type = 'svg';
3122
- if(HTMLTags.includes(tag)) return (...args)=>{
3207
+ return (...args)=>{
3123
3208
  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
3209
  if(
3130
3210
  ['string', 'number'].includes(typeof args[0])
3131
3211
  || args[0] instanceof UIElement
3132
3212
  || (typeof args[0] === 'function' && args[0]().isStateGetter())
3133
- ) return new UIElement({element :tag, name : tag, type}).append(...args);
3213
+ ) return new UIElement({element : tag, name : tag, type}).append(...args);
3214
+ // console.log(args[0])
3134
3215
  return new UIElement({element : tag}).setAttr(args.shift()).append(...args)
3135
3216
  }
3136
3217
  // if(SVGTags.includes(tag)) return (...args) => new UIElement(tag,"",{el_type : "svg"}).append(...args);
@@ -3722,175 +3803,6 @@
3722
3803
  }, Array.isArray(obj) ? [] : {});
3723
3804
  }
3724
3805
 
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
3806
  class Matrix extends ZikoMath{
3895
3807
  constructor(rows, cols, element = [] ) {
3896
3808
  super();
@@ -4049,7 +3961,7 @@
4049
3961
  .mul(determinat(deleteRowAndColumn(M, i)))
4050
3962
  );*/
4051
3963
  //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)))));
3964
+ const to_be_added=Utils.add(Utils.mul(pow$1(-1, i),Utils.mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
4053
3965
  answer=Utils.add(answer,to_be_added);
4054
3966
  }
4055
3967
  return answer;
@@ -4572,7 +4484,7 @@
4572
4484
  }
4573
4485
  else if(("a" in b && "z" in a)){
4574
4486
  this.a=a.a;
4575
- this.b=sqrt((a.z**2)-(a.a**2));
4487
+ this.b=sqrt$1((a.z**2)-(a.a**2));
4576
4488
  }
4577
4489
  else if(("a" in b && "phi" in a)){
4578
4490
  this.a=a.a;
@@ -4580,15 +4492,15 @@
4580
4492
  }
4581
4493
  else if(("b" in b && "z" in a)){
4582
4494
  this.b=a.b;
4583
- this.a=sqrt((a.z**2)-(a.b**2));
4495
+ this.a=sqrt$1((a.z**2)-(a.b**2));
4584
4496
  }
4585
4497
  else if(("b" in b && "phi" in a)){
4586
4498
  this.b=b;
4587
4499
  this.a=a.b/tan(a.phi);
4588
4500
  }
4589
4501
  else if(("z" in b && "phi" in a)){
4590
- this.a=a.z*cos(a.phi);
4591
- this.a=a.z*sin(a.phi);
4502
+ this.a=a.z*cos$1(a.phi);
4503
+ this.a=a.z*sin$1(a.phi);
4592
4504
  }
4593
4505
  }
4594
4506
  else if(typeof(a)==="number"&&typeof(b)==="number"){
@@ -4628,7 +4540,7 @@
4628
4540
  return new Complex(this.a, -this.b);
4629
4541
  }
4630
4542
  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)));
4543
+ 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
4544
  }
4633
4545
  add(...z) {
4634
4546
  for (let i = 0; i < z.length; i++) {
@@ -4656,8 +4568,8 @@
4656
4568
  }
4657
4569
  let Z=+prod(this.z,...z.map(n=>n.z)).toFixed(15);
4658
4570
  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);
4571
+ this.a=+(Z*cos$1(phi).toFixed(15)).toFixed(14);
4572
+ this.b=+(Z*sin$1(phi).toFixed(15)).toFixed(14);
4661
4573
  return this;
4662
4574
  }
4663
4575
  div(...z) {
@@ -4666,23 +4578,23 @@
4666
4578
  }
4667
4579
  let Z=+(this.z/prod(...z.map(n=>n.z))).toFixed(15);
4668
4580
  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);
4581
+ this.a=+(Z*cos$1(phi).toFixed(15)).toFixed(15);
4582
+ this.b=+(Z*sin$1(phi).toFixed(15)).toFixed(15);
4671
4583
  return this;
4672
4584
  }
4673
4585
  pow(n) {
4674
4586
  if (floor(n) === n && n > 0) {
4675
4587
  let z=+(this.z**n).toFixed(15);
4676
4588
  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);
4589
+ this.a=+(z*cos$1(phi).toFixed(15)).toFixed(15);
4590
+ this.b=+(z*sin$1(phi).toFixed(15)).toFixed(15);
4679
4591
  }
4680
4592
  return this;
4681
4593
  }
4682
4594
  static fromExpo(z, phi) {
4683
4595
  return new Complex(
4684
- +(z * cos(phi)).toFixed(13),
4685
- +(z * sin(phi)).toFixed(13)
4596
+ +(z * cos$1(phi)).toFixed(13),
4597
+ +(z * sin$1(phi)).toFixed(13)
4686
4598
  );
4687
4599
  }
4688
4600
  get expo() {
@@ -4704,10 +4616,10 @@
4704
4616
  return z.clone.pow(n);
4705
4617
  }
4706
4618
  static xpowZ(x){
4707
- return complex((x**this.a)*cos(this.b*ln(x)),(x**this.a)*sin(this.b*ln(x)));
4619
+ return complex((x**this.a)*cos$1(this.b*ln(x)),(x**this.a)*sin$1(this.b*ln(x)));
4708
4620
  }
4709
4621
  sqrtn(n=2){
4710
- return complex(sqrtn(this.z,n)*cos(this.phi/n),sqrtn(this.z,n)*sin(this.phi/n));
4622
+ return complex(sqrtn(this.z,n)*cos$1(this.phi/n),sqrtn(this.z,n)*sin$1(this.phi/n));
4711
4623
  }
4712
4624
  get sqrt(){
4713
4625
  return this.sqrtn(2);
@@ -4716,14 +4628,14 @@
4716
4628
  return complex(this.z,this.phi);
4717
4629
  }
4718
4630
  get cos(){
4719
- return complex(cos(this.a)*cosh(this.b),sin(this.a)*sinh(this.b))
4631
+ return complex(cos$1(this.a)*cosh(this.b),sin$1(this.a)*sinh(this.b))
4720
4632
  }
4721
4633
  get sin(){
4722
- return complex(sin(this.a)*cosh(this.b),cos(this.a)*sinh(this.b))
4634
+ return complex(sin$1(this.a)*cosh(this.b),cos$1(this.a)*sinh(this.b))
4723
4635
  }
4724
4636
  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);
4637
+ const de=cos$1(this.a*2)+cosh(this.b*2);
4638
+ return complex(sin$1(2*this.a)/de,sinh(2*this.b)/de);
4727
4639
  }
4728
4640
  printInConsole() {
4729
4641
  let string = this.a + " + " + this.b + " * i";
@@ -4754,12 +4666,12 @@
4754
4666
  // } from "../calculus/index.js";
4755
4667
 
4756
4668
  const abs=(...x)=>mapfun$1(Math.abs,...x);
4757
- const sqrt=(...x)=>mapfun$1(Math.sqrt,...x);
4758
- const pow=(x,n)=>{
4669
+ const sqrt$1=(...x)=>mapfun$1(Math.sqrt,...x);
4670
+ const pow$1=(x,n)=>{
4759
4671
  if(typeof x === "number"){
4760
4672
  if(typeof n === "number")return Math.pow(x,n);
4761
4673
  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);
4674
+ else return mapfun$1(a=>pow$1(x,a),...n);
4763
4675
  }
4764
4676
  else if(x instanceof Complex){
4765
4677
  if(typeof n === "number")return Complex.fromExpo(x.z**n,x.phi*n);
@@ -4767,14 +4679,14 @@
4767
4679
  x.z**n.a*e(-x.phi*n.b),
4768
4680
  ln(x.z)*n.b+n.a*x.phi
4769
4681
  )
4770
- else return mapfun$1(a=>pow(x,a),...n);
4682
+ else return mapfun$1(a=>pow$1(x,a),...n);
4771
4683
  }
4772
4684
  else if(x instanceof Array){
4773
- if(typeof n === "number") return mapfun$1(a=>pow(a,n),...x);
4685
+ if(typeof n === "number") return mapfun$1(a=>pow$1(a,n),...x);
4774
4686
  else if(n instanceof Array){
4775
4687
  const Y=[];
4776
4688
  for(let i=0;i<x.length;i++){
4777
- Y.push(mapfun$1(a=>pow(x[i],a),...n));
4689
+ Y.push(mapfun$1(a=>pow$1(x[i],a),...n));
4778
4690
  }
4779
4691
  return Y;
4780
4692
  }
@@ -4802,14 +4714,14 @@
4802
4714
  };
4803
4715
  const e=(...x) => mapfun$1(Math.exp,...x);
4804
4716
  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);
4717
+ const cos$1=(...x) => mapfun$1(Fixed.cos,...x);
4718
+ const sin$1=(...x) => mapfun$1(Fixed.sin,...x);
4807
4719
  const tan=(...x) => mapfun$1(Fixed.tan,...x);
4808
4720
  const sec=(...x) => mapfun$1(Fixed.sec,...x);
4809
4721
  const sinc=(...x) => mapfun$1(Fixed.sinc,...x);
4810
4722
  const csc=(...x) => mapfun$1(Fixed.csc,...x);
4811
4723
  const cot=(...x) => mapfun$1(Fixed.cot,...x);
4812
- const acos=(...x) => mapfun$1(Fixed.acos,...x);
4724
+ const acos$1=(...x) => mapfun$1(Fixed.acos,...x);
4813
4725
  const asin=(...x) => mapfun$1(Fixed.asin,...x);
4814
4726
  const atan=(...x) => mapfun$1(Fixed.atan,...x);
4815
4727
  const acot=(...x) => mapfun$1(Fixed.acot,...x);
@@ -4837,7 +4749,7 @@
4837
4749
  else if(y instanceof Array){
4838
4750
  const Y=[];
4839
4751
  for(let i=0;i<x.length;i++){
4840
- Y.push(mapfun$1(a=>pow(x[i],a),...y));
4752
+ Y.push(mapfun$1(a=>pow$1(x[i],a),...y));
4841
4753
  }
4842
4754
  return Y;
4843
4755
  }
@@ -4863,229 +4775,469 @@
4863
4775
  )
4864
4776
  };
4865
4777
 
4866
- class ZikoTimeLoop {
4867
- constructor(callback, step = 1000/30, startTime=0, endTime = Infinity, started = true) {
4778
+ const {PI, sqrt, cos, sin, acos, pow} = Math;
4779
+
4780
+ const Linear = t => t;
4781
+ const InSin = t => 1 - cos((t * PI) / 2);
4782
+ const OutSin = t => sin((t * PI) / 2);
4783
+ const InOutSin = t => -(cos(PI * t) - 1) / 2;
4784
+
4785
+ const InQuad = t => t**2;
4786
+ const OutQuad = t => 1 - (1-t)**2;
4787
+ const InOutQuad = t => t < 0.5 ? 2 * (t**2) : 1 - (-2 * t + 2)**2 / 2;
4788
+
4789
+ const InCubic = t => t**3;
4790
+ const OutCubic = t => 1 - (1-t)**3;
4791
+ const InOutCubic = t => t < 0.5 ? 4 * (t**3) : 1 - (-2 * t + 2)**3 / 2;
4792
+
4793
+ const InQuart = t => t**4;
4794
+ const OutQuart = t => 1 - (1-t)**4;
4795
+ const InOutQuart = t => t < 0.5 ? 8 * (t**4) : 1 - (-2 * t + 2)**4 / 2;
4796
+
4797
+ const InQuint = t => t**5;
4798
+ const OutQuint = t => 1 - (1-t)**5;
4799
+ const InOutQuint = t => t < 0.5 ? 16 * (t**5) : 1 - (-2 * t + 2)**5 / 2;
4800
+
4801
+ const InExpo = t => t === 0 ? 0 : 2**(10*t - 10);
4802
+ const OutExpo = t => t === 1 ? 1 : 1 - 2**(-10 * t);
4803
+ const InOutExpo = t => t === 0? 0: t === 1? 1: t < 0.5 ? 2**(20 * t - 10) / 2: (2 - 2**(-20 * t + 10)) / 2;
4804
+
4805
+ const InCirc = t => 1 - sqrt(1 - t**2);
4806
+ const OutCirc = t => sqrt(1 - (t-1)**2);
4807
+ const InOutCirc = t => t < 0.5? (1 - sqrt(1 - (2*t)**2)) / 2: (sqrt(1 - (-2*t+2)**2) + 1) / 2;
4808
+
4809
+ const Arc = t => 1 - sin(acos(t));
4810
+ const Back = (t, x = 1) => (t**2) * ((x+1)*t - x);
4811
+ const Elastic = t => -2*pow(2, 10 * (t - 1)) * cos(20 * PI * t / 3 * t);
4812
+
4813
+ const InBack = (t, c1 = 1.70158, c3 = c1 + 1) => c3 * pow(t,3)- c1 * (t**2);
4814
+ const OutBack = (t, c1 = 1.70158, c3 = c1 + 1) => 1 + c3 * pow(t - 1, 3) + c1 * pow(t - 1, 2);
4815
+ 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;
4816
+
4817
+ const InElastic = (t, c4 = 2*PI/3) => {
4818
+ return t === 0
4819
+ ? 0
4820
+ : t === 1
4821
+ ? 1
4822
+ : -pow(2, 10 * t - 10) * sin((t * 10 - 10.75) * c4);
4823
+ };
4824
+
4825
+ const OutElastic = (t, c4 = 2*PI/3) => {
4826
+ return t === 0
4827
+ ? 0
4828
+ : t === 1
4829
+ ? 1
4830
+ : pow(2, -10 * t) * sin((t * 10 - 0.75) * c4) + 1;
4831
+ };
4832
+ const InOutElastic = (t, c5 = 2 * PI / 4.5) => {
4833
+ return t === 0
4834
+ ? 0
4835
+ : t === 1
4836
+ ? 1
4837
+ : t < 0.5
4838
+ ? -(pow(2, 20 * t - 10) * sin((20 * t - 11.125) * c5)) / 2
4839
+ : (pow(2, -20 * t + 10) * sin((20 * t - 11.125) * c5)) / 2 + 1;
4840
+ };
4841
+
4842
+ const InBounce = (t, n1 = 7.5625, d1 = 2.75) => 1 - OutBounce(1-t, n1, d1);
4843
+ const OutBounce = (t, n1 = 7.5625, d1 = 2.75) => {
4844
+ if(t<1/d1) return n1 * t * t;
4845
+ if(t < 2 / d1) return n1 * (t -= 1.5 / d1) * t + 0.75;
4846
+ if(t < 2.5 / d1) return n1 * (t -= 2.25 / d1) * t + 0.9375;
4847
+ return n1 * (t -= 2.625 / d1) * t + 0.984375;
4848
+ };
4849
+
4850
+ 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;
4851
+
4852
+
4853
+ const Step = (t, steps = 5) => Math.floor(t*steps) / steps;
4854
+ const Discret = (t, segments = 5) => Math.ceil(t*segments) / segments;
4855
+
4856
+ class TimeAnimation {
4857
+ constructor(callback, { ease = Linear, step = 50, t0 = 0, start = true, duration = 3000 } = {}) {
4868
4858
  this.callback = callback;
4869
- this.cache = {
4859
+ this.state = {
4870
4860
  isRunning: false,
4871
- AnimationId : null,
4872
- t0 : null,
4861
+ animationId: null,
4862
+ startTime: null,
4863
+ ease,
4873
4864
  step,
4874
- // fps,
4875
- startTime,
4876
- endTime,
4877
- started
4865
+ // interval: [t0, t1],
4866
+ autoStart: start,
4867
+ duration
4878
4868
  };
4879
- this.init();
4880
- this.i=0;
4869
+
4870
+ this.t = 0; // elapsed time
4871
+ this.tx = 0; // normalized [0,1]
4872
+ this.ty = 0; // eased value
4873
+ this.i = 0; // frame index
4874
+
4875
+ if (this.state.autoStart) {
4876
+ this.start();
4877
+ }
4881
4878
  }
4882
- init(){
4883
- // if(this.cache.step && this.cache.fps){
4884
- // console.warn(`Fps will be adjusted from ${this.cache.fps} to ${1000/this.cache.step} to ensure a smoother animation`);
4885
- // this.cache.fps=1000/this.cache.step;
4886
- // }
4887
- if(this.cache.started){
4888
- this.cache.startTime?this.startAfter(this.cache.startTime):this.start();
4889
- if(this.cache.endTime&&this.cache.endTime!==Infinity)this.stopAfter(this.cache.endTime);
4879
+
4880
+ // ---- private loop handler ----
4881
+ #tick = () => {
4882
+ this.t += this.state.step;
4883
+ this.i++;
4884
+
4885
+ this.tx = map(this.t, 0, this.state.duration, 0, 1);
4886
+ this.ty = this.state.ease(this.tx);
4887
+
4888
+ this.callback(this);
4889
+
4890
+ if (this.t >= this.state.duration) {
4891
+ clearInterval(this.state.animationId);
4892
+ this.state.isRunning = false;
4893
+ }
4894
+ };
4895
+
4896
+ // ---- core runner ----
4897
+ #run(reset = true) {
4898
+ if (!this.state.isRunning) {
4899
+ if (reset) this.reset(false);
4900
+
4901
+ this.state.isRunning = true;
4902
+ this.state.startTime = Date.now();
4903
+ this.state.animationId = setInterval(this.#tick, this.state.step);
4890
4904
  }
4891
4905
  return this;
4892
4906
  }
4893
- // get TIME_STEP() {
4894
- // // return this.cache.step?this.cache.step:1000 / this.cache.fps;
4895
- // return this.cache.step;
4896
- // }
4907
+
4908
+ // ---- lifecycle methods ----
4909
+ start() {
4910
+ return this.#run(true);
4911
+ }
4912
+
4913
+ pause() {
4914
+ if (this.state.isRunning) {
4915
+ clearInterval(this.state.animationId);
4916
+ this.state.isRunning = false;
4917
+ }
4918
+ return this;
4919
+ }
4920
+
4921
+ resume() {
4922
+ return this.#run(false);
4923
+ }
4924
+
4925
+ stop() {
4926
+ this.pause();
4927
+ this.reset(false);
4928
+ return this;
4929
+ }
4930
+
4931
+ reset(restart = true) {
4932
+ this.t = 0;
4933
+ this.tx = 0;
4934
+ this.ty = 0;
4935
+ this.i = 0;
4936
+
4937
+ if (restart) this.start();
4938
+ return this;
4939
+ }
4940
+ }
4941
+
4942
+ // Hook-style factory
4943
+ const animation = (callback, {ease, t0, t1, start, duration} = {}) =>
4944
+ new TimeAnimation(callback, {ease, t0, t1, start, duration});
4945
+
4946
+ class Tick {
4947
+ constructor(ms, fn) {
4948
+ this.ms = ms;
4949
+ this.fn = fn;
4950
+ this.id = null;
4951
+ this.running = false;
4952
+ }
4953
+
4954
+ start() {
4955
+ if (!this.running) {
4956
+ this.running = true;
4957
+ this.id = setInterval(this.fn, this.ms);
4958
+ }
4959
+ return this;
4960
+ }
4961
+
4962
+ stop() {
4963
+ if (this.running) {
4964
+ this.running = false;
4965
+ clearInterval(this.id);
4966
+ this.id = null;
4967
+ }
4968
+ return this;
4969
+ }
4970
+
4971
+ isRunning() {
4972
+ return this.running;
4973
+ }
4974
+ }
4975
+ const tick = (ms, fn) => new Tick(ms, fn);
4976
+
4977
+ class Clock extends Tick {
4978
+ constructor(tickMs = 1000 / 60) {
4979
+ super(tickMs, () => this._tick());
4980
+ this.elapsed = 0;
4981
+ this._lastTime = performance.now();
4982
+ this._callbacks = new Set();
4983
+ }
4984
+
4985
+ _tick() {
4986
+ const now = performance.now();
4987
+ const delta = now - this._lastTime;
4988
+ this.elapsed += delta;
4989
+ this._lastTime = now;
4990
+
4991
+ for (const cb of this._callbacks) {
4992
+ cb({ elapsed: this.elapsed, delta });
4993
+ }
4994
+ }
4995
+
4996
+ onTick(cb) {
4997
+ this._callbacks.add(cb);
4998
+ return () => this._callbacks.delete(cb);
4999
+ }
5000
+
5001
+ reset() {
5002
+ this.elapsed = 0;
5003
+ this._lastTime = performance.now();
5004
+ }
5005
+
5006
+ pause() {
5007
+ super.stop();
5008
+ }
5009
+
5010
+ resume() {
5011
+ this._lastTime = performance.now();
5012
+ super.start();
5013
+ }
5014
+ }
5015
+
5016
+ const clock = (tickMs) => new Clock(tickMs);
5017
+
5018
+
5019
+ /*
5020
+
5021
+ const clock = new Clock(200);
5022
+
5023
+ clock.onTick(({ elapsed, delta }) => {
5024
+ console.log(`Elapsed: ${elapsed.toFixed(0)}ms, Delta: ${delta.toFixed(0)}ms`);
5025
+ });
5026
+
5027
+ clock.start();
5028
+
5029
+ setTimeout(() => clock.pause(), 1000);
5030
+ setTimeout(() => clock.resume(), 2000);
5031
+
5032
+ */
5033
+
5034
+ class TimeScheduler {
5035
+ constructor(tasks = [], { repeat = 1, loop = false } = {}) {
5036
+ this.tasks = tasks;
5037
+ this.repeat = repeat;
5038
+ this.loop = loop;
5039
+
5040
+ this.stopped = false;
5041
+ this.running = false;
5042
+
5043
+ // lifecycle hooks
5044
+ this.onStart = null;
5045
+ this.onTask = null;
5046
+ this.onEnd = null;
5047
+ }
5048
+
5049
+ async run() {
5050
+ if (this.running) return;
5051
+ this.running = true;
5052
+ this.stopped = false;
5053
+
5054
+ if (this.onStart) this.onStart();
5055
+
5056
+ let repeatCount = this.repeat;
5057
+
5058
+ do {
5059
+ for (const task of this.tasks) {
5060
+ if (this.stopped) return;
5061
+
5062
+ if (Array.isArray(task)) {
5063
+ // Parallel tasks
5064
+ await Promise.all(
5065
+ task.map(({ fn, delay = 0 }) =>
5066
+ new Promise(async (resolve) => {
5067
+ if (delay > 0) await new Promise(r => setTimeout(r, delay));
5068
+ if (this.onTask) this.onTask(fn);
5069
+ await fn();
5070
+ resolve();
5071
+ })
5072
+ )
5073
+ );
5074
+ } else {
5075
+ // Single task
5076
+ const { fn, delay = 0 } = task;
5077
+ if (delay > 0) await new Promise(r => setTimeout(r, delay));
5078
+ if (this.onTask) this.onTask(fn);
5079
+ await fn();
5080
+ }
5081
+ }
5082
+ } while (this.loop && !this.stopped && (repeatCount === Infinity || repeatCount-- > 1));
5083
+
5084
+ if (!this.stopped && this.onEnd) this.onEnd();
5085
+ this.running = false;
5086
+ }
5087
+
5088
+ stop() {
5089
+ this.stopped = true;
5090
+ this.running = false;
5091
+ }
5092
+
5093
+ addTask(task) {
5094
+ this.tasks.push(task);
5095
+ }
5096
+
5097
+ clearTasks() {
5098
+ this.tasks = [];
5099
+ }
5100
+ }
5101
+
5102
+ const Scheduler = (tasks, { repeat = null} = {}) => new TimeScheduler(tasks, { repeat});
5103
+
5104
+ const step_fps = (step_or_fps) => 1000 / step_or_fps;
5105
+
5106
+ const debounce=(fn,delay=1000)=>{
5107
+ return (...args) => setTimeout(()=>fn(...args),delay);
5108
+ };
5109
+ const throttle=(fn,delay)=>{
5110
+ let lastTime=0;
5111
+ return (...args) => {
5112
+ const now = new Date().getTime();
5113
+ if(now-lastTime < delay) return;
5114
+ lastTime = now;
5115
+ fn(...args);
5116
+ }
5117
+ };
5118
+
5119
+ function timeout(ms, fn) {
5120
+ let id;
5121
+ const promise = new Promise((resolve) => {
5122
+ id = setTimeout(() => {
5123
+ if (fn) fn();
5124
+ resolve();
5125
+ }, ms);
5126
+ });
5127
+
5128
+ return {
5129
+ id,
5130
+ clear: () => clearTimeout(id),
5131
+ promise
5132
+ };
5133
+ }
5134
+
5135
+ const sleep= ms => new Promise(res => setTimeout(res, ms));
5136
+
5137
+ // use it with await
5138
+
5139
+ class TimeLoop {
5140
+ constructor(callback, { step = 1000, t0 = 0, t1 = Infinity, autoplay = true } = {}) {
5141
+ this.callback = callback;
5142
+ this.cache = {
5143
+ isRunning: false,
5144
+ id: null,
5145
+ last_tick: null,
5146
+ step,
5147
+ t0,
5148
+ t1,
5149
+ autoplay,
5150
+ pauseTime: null,
5151
+ frame : 0,
5152
+ };
5153
+
5154
+ if (autoplay) {
5155
+ t0 ? this.startAfter(t0) : this.start();
5156
+ if (t1 !== Infinity) this.stopAfter(t1);
5157
+ }
5158
+ }
5159
+
5160
+ get frame(){
5161
+ return this.cache.frame;
5162
+ }
5163
+ get elapsed(){
5164
+ return this.cache.elapsed;
5165
+ }
5166
+
4897
5167
  start() {
4898
5168
  if (!this.cache.isRunning) {
4899
- this.i=0;
5169
+ this.cache.frame = 0;
4900
5170
  this.cache.isRunning = true;
4901
- this.cache.t0 = Date.now();
5171
+ this.cache.last_tick = Date.now();
4902
5172
  this.animate();
4903
5173
  }
4904
5174
  return this;
4905
5175
  }
5176
+
4906
5177
  pause() {
4907
5178
  if (this.cache.isRunning) {
4908
- clearTimeout(this.cache.AnimationId);
5179
+ clearTimeout(this.cache.id);
4909
5180
  this.cache.isRunning = false;
5181
+ this.cache.pauseTime = Date.now();
4910
5182
  }
4911
5183
  return this;
4912
5184
  }
4913
- stop(){
4914
- this.pause();
4915
- this.i=0;
5185
+
5186
+ resume() {
5187
+ if (!this.cache.isRunning) {
5188
+ this.cache.isRunning = true;
5189
+ if (this.cache.pauseTime) {
5190
+ // adjust start time so delta stays consistent
5191
+ const pausedDuration = Date.now() - this.cache.pauseTime;
5192
+ this.cache.last_tick += pausedDuration;
5193
+ }
5194
+ this.animate();
5195
+ }
4916
5196
  return this;
4917
5197
  }
4918
- resume(){
4919
- this.cache.isRunning=true;
4920
- this.animate();
5198
+
5199
+ stop() {
5200
+ this.pause();
5201
+ this.cache.frame = 0;
4921
5202
  return this;
4922
5203
  }
4923
- startAfter(t=1000){
4924
- setTimeout(this.start.bind(this),t);
5204
+
5205
+ startAfter(t = 1000) {
5206
+ setTimeout(() => this.start(), t);
4925
5207
  return this;
4926
5208
  }
4927
- stopAfter(t=1000){
4928
- setTimeout(this.stop.bind(this),t);
4929
- return this;
5209
+
5210
+ stopAfter(t = 1000) {
5211
+ setTimeout(() => this.stop(), t);
5212
+ return this;
4930
5213
  }
5214
+
4931
5215
  animate = () => {
4932
5216
  if (this.cache.isRunning) {
4933
5217
  const now = Date.now();
4934
- const delta = now - this.cache.t0;
4935
- if (delta > this.cache.step) {
5218
+ const delta = now - this.cache.last_tick;
5219
+
5220
+ if (delta >= this.cache.step) {
5221
+ this.cache.elapsed = now - (this.cache.t0 || 0);
4936
5222
  this.callback(this);
4937
- this.i++;
4938
- this.cache.t0 = now - (delta % this.cache.step);
5223
+ this.cache.frame++;
5224
+ this.cache.last_tick = now - (delta % this.cache.step);
4939
5225
  }
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
5226
 
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;
5227
+ this.cache.id = setTimeout(this.animate, 0);
5087
5228
  }
5088
- };
5229
+ }
5230
+ }
5231
+
5232
+ const loop = (callback, options = {}) => new TimeLoop(callback, options);
5233
+
5234
+
5235
+ // Helpers
5236
+ // const useFps = (fps) => 1000 / fps;
5237
+
5238
+ // const _loop = loop( e => {
5239
+ // console.log("Frame:", e.frame, " Elapsed: ", e.elapsed);
5240
+ // });
5089
5241
 
5090
5242
  const time_memory_Taken = (callback) => {
5091
5243
  const t0 = Date.now();
@@ -5128,6 +5280,7 @@
5128
5280
  }
5129
5281
  };
5130
5282
 
5283
+ // import Ease from "./ease.js";
5131
5284
  const wait=(delayInMS)=>{
5132
5285
  return new Promise((resolve) => setTimeout(resolve, delayInMS));
5133
5286
  };
@@ -5138,93 +5291,6 @@
5138
5291
  return r;
5139
5292
  };
5140
5293
 
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
5294
  class ZikoApp {
5229
5295
  constructor({head = null, wrapper = null, target = null}){
5230
5296
  this.head = head;
@@ -5440,6 +5506,70 @@
5440
5506
  return commonPath;
5441
5507
  }
5442
5508
 
5509
+ function useDerived(deriveFn, sources) {
5510
+ let value = deriveFn(...sources.map(s => s().value));
5511
+ const subscribers = new Set();
5512
+ let paused = false;
5513
+
5514
+ function getValue() {
5515
+ return {
5516
+ value,
5517
+ isStateGetter: () => true,
5518
+ _subscribe: (fn, UIElement) => {
5519
+ subscribers.add(fn);
5520
+
5521
+ const observer = new MutationObserver(() => {
5522
+ if (!document.body.contains(UIElement.element)) {
5523
+ subscribers.delete(fn);
5524
+ observer.disconnect();
5525
+ }
5526
+ });
5527
+
5528
+ observer.observe(document.body, { childList: true, subtree: true });
5529
+ },
5530
+ };
5531
+ }
5532
+
5533
+ function setValue(newValue) {
5534
+ if (paused) return;
5535
+ if (typeof newValue === "function") newValue = newValue(value);
5536
+ if (newValue !== value) {
5537
+ value = newValue;
5538
+ subscribers.forEach(fn => fn(value));
5539
+ }
5540
+ }
5541
+
5542
+ const controller = {
5543
+ pause: () => { paused = true; },
5544
+ resume: () => { paused = false; },
5545
+ clear: () => { subscribers.clear(); },
5546
+ force: (newValue) => {
5547
+ if (typeof newValue === "function") newValue = newValue(value);
5548
+ value = newValue;
5549
+ subscribers.forEach(fn => fn(value));
5550
+ },
5551
+ getSubscribers: () => new Set(subscribers),
5552
+ };
5553
+
5554
+ // Subscribe to source states
5555
+ sources.forEach(source => {
5556
+ const srcValue = source(); // getValue()
5557
+ srcValue._subscribe(() => {
5558
+ if (!paused) {
5559
+ const newVal = deriveFn(...sources.map(s => s().value));
5560
+ if (newVal !== value) {
5561
+ value = newVal;
5562
+ subscribers.forEach(fn => fn(value));
5563
+ }
5564
+ }
5565
+ }, { element: document.body }); // dummy UIElement
5566
+ });
5567
+
5568
+ return [getValue, setValue, controller];
5569
+ }
5570
+
5571
+ const useReactive = (nested_value) => mapfun$1(n => useState(n), nested_value);
5572
+
5443
5573
  class ZikoUseChannel{
5444
5574
  constructor(name = ""){
5445
5575
  this.channel = new BroadcastChannel(name);
@@ -5679,27 +5809,67 @@
5679
5809
  }
5680
5810
 
5681
5811
  exports.App = App;
5812
+ exports.Arc = Arc;
5813
+ exports.Back = Back;
5682
5814
  exports.Base = Base;
5683
5815
  exports.Canvas = Canvas;
5816
+ exports.Clock = Clock;
5684
5817
  exports.Combinaison = Combinaison;
5685
5818
  exports.Complex = Complex;
5819
+ exports.Discret = Discret;
5686
5820
  exports.E = E;
5687
5821
  exports.EPSILON = EPSILON;
5688
- exports.Ease = Ease;
5822
+ exports.Elastic = Elastic;
5689
5823
  exports.FileBasedRouting = FileBasedRouting;
5690
5824
  exports.Flex = Flex;
5691
5825
  exports.Grid = Grid$1;
5692
5826
  exports.HTMLWrapper = HTMLWrapper;
5827
+ exports.InBack = InBack;
5828
+ exports.InBounce = InBounce;
5829
+ exports.InCirc = InCirc;
5830
+ exports.InCubic = InCubic;
5831
+ exports.InElastic = InElastic;
5832
+ exports.InExpo = InExpo;
5833
+ exports.InOutBack = InOutBack;
5834
+ exports.InOutBounce = InOutBounce;
5835
+ exports.InOutCirc = InOutCirc;
5836
+ exports.InOutCubic = InOutCubic;
5837
+ exports.InOutElastic = InOutElastic;
5838
+ exports.InOutExpo = InOutExpo;
5839
+ exports.InOutQuad = InOutQuad;
5840
+ exports.InOutQuart = InOutQuart;
5841
+ exports.InOutQuint = InOutQuint;
5842
+ exports.InOutSin = InOutSin;
5843
+ exports.InQuad = InQuad;
5844
+ exports.InQuart = InQuart;
5845
+ exports.InQuint = InQuint;
5846
+ exports.InSin = InSin;
5847
+ exports.Linear = Linear;
5693
5848
  exports.Logic = Logic$1;
5694
5849
  exports.Matrix = Matrix;
5695
- exports.PI = PI$1;
5850
+ exports.OutBack = OutBack;
5851
+ exports.OutBounce = OutBounce;
5852
+ exports.OutCirc = OutCirc;
5853
+ exports.OutCubic = OutCubic;
5854
+ exports.OutElastic = OutElastic;
5855
+ exports.OutExpo = OutExpo;
5856
+ exports.OutQuad = OutQuad;
5857
+ exports.OutQuart = OutQuart;
5858
+ exports.OutQuint = OutQuint;
5859
+ exports.OutSin = OutSin;
5860
+ exports.PI = PI$2;
5696
5861
  exports.Permutation = Permutation;
5697
5862
  exports.Random = Random;
5698
5863
  exports.SPA = SPA;
5699
5864
  exports.SVGWrapper = SVGWrapper;
5700
- exports.Str = Str;
5865
+ exports.Scheduler = Scheduler;
5866
+ exports.Step = Step;
5701
5867
  exports.Suspense = Suspense;
5702
5868
  exports.Svg = Svg;
5869
+ exports.Tick = Tick;
5870
+ exports.TimeAnimation = TimeAnimation;
5871
+ exports.TimeLoop = TimeLoop;
5872
+ exports.TimeScheduler = TimeScheduler;
5703
5873
  exports.UIElement = UIElement;
5704
5874
  exports.UINode = UINode;
5705
5875
  exports.Utils = Utils;
@@ -5733,10 +5903,11 @@
5733
5903
  exports.__ZikoEvent__ = __ZikoEvent__;
5734
5904
  exports.abs = abs;
5735
5905
  exports.accum = accum;
5736
- exports.acos = acos;
5906
+ exports.acos = acos$1;
5737
5907
  exports.acosh = acosh;
5738
5908
  exports.acot = acot;
5739
5909
  exports.add = add;
5910
+ exports.animation = animation;
5740
5911
  exports.arange = arange;
5741
5912
  exports.arr2str = arr2str;
5742
5913
  exports.asin = asin;
@@ -5758,14 +5929,13 @@
5758
5929
  exports.cartesianProduct = cartesianProduct;
5759
5930
  exports.ceil = ceil;
5760
5931
  exports.clamp = clamp;
5932
+ exports.clock = clock;
5761
5933
  exports.combinaison = combinaison;
5762
5934
  exports.complex = complex;
5763
- exports.cos = cos;
5935
+ exports.cos = cos$1;
5764
5936
  exports.cosh = cosh;
5765
5937
  exports.cot = cot;
5766
5938
  exports.coth = coth;
5767
- exports.count = count;
5768
- exports.countWords = countWords;
5769
5939
  exports.csc = csc;
5770
5940
  exports.csv2arr = csv2arr;
5771
5941
  exports.csv2json = csv2json;
@@ -5784,6 +5954,7 @@
5784
5954
  exports.hypot = hypot;
5785
5955
  exports.inRange = inRange;
5786
5956
  exports.isApproximatlyEqual = isApproximatlyEqual;
5957
+ exports.isStateGetter = isStateGetter;
5787
5958
  exports.json2arr = json2arr;
5788
5959
  exports.json2css = json2css;
5789
5960
  exports.json2csv = json2csv;
@@ -5796,6 +5967,7 @@
5796
5967
  exports.linspace = linspace;
5797
5968
  exports.ln = ln;
5798
5969
  exports.logspace = logspace;
5970
+ exports.loop = loop;
5799
5971
  exports.map = map;
5800
5972
  exports.mapfun = mapfun$1;
5801
5973
  exports.matrix = matrix;
@@ -5811,23 +5983,23 @@
5811
5983
  exports.obj2str = obj2str;
5812
5984
  exports.ones = ones;
5813
5985
  exports.pgcd = pgcd;
5814
- exports.pow = pow;
5986
+ exports.pow = pow$1;
5815
5987
  exports.powerSet = powerSet;
5816
5988
  exports.ppcm = ppcm;
5817
5989
  exports.preload = preload;
5818
5990
  exports.prod = prod;
5819
5991
  exports.rad2deg = rad2deg;
5820
- exports.removeExtraSpace = removeExtraSpace;
5821
5992
  exports.round = round;
5822
5993
  exports.sec = sec;
5823
5994
  exports.sig = sig;
5824
5995
  exports.sign = sign;
5825
- exports.sin = sin;
5996
+ exports.sin = sin$1;
5826
5997
  exports.sinc = sinc;
5827
5998
  exports.sinh = sinh;
5828
- exports.sqrt = sqrt;
5999
+ exports.sleep = sleep;
6000
+ exports.sqrt = sqrt$1;
5829
6001
  exports.sqrtn = sqrtn;
5830
- exports.str = str;
6002
+ exports.step_fps = step_fps;
5831
6003
  exports.sub = sub;
5832
6004
  exports.subSet = subSet;
5833
6005
  exports.sum = sum;
@@ -5840,26 +6012,28 @@
5840
6012
  exports.tanh = tanh;
5841
6013
  exports.text = text;
5842
6014
  exports.throttle = throttle;
6015
+ exports.tick = tick;
5843
6016
  exports.timeTaken = timeTaken;
5844
6017
  exports.time_memory_Taken = time_memory_Taken;
5845
- exports.useAnimation = useAnimation;
6018
+ exports.timeout = timeout;
5846
6019
  exports.useChannel = useChannel;
5847
6020
  exports.useCustomEvent = useCustomEvent;
6021
+ exports.useDerived = useDerived;
5848
6022
  exports.useEventEmitter = useEventEmitter;
5849
6023
  exports.useFavIcon = useFavIcon;
5850
- exports.useFps = useFps;
5851
6024
  exports.useHashEvent = useHashEvent;
5852
6025
  exports.useHead = useHead;
5853
6026
  exports.useInputEvent = useInputEvent;
5854
6027
  exports.useLocaleStorage = useLocaleStorage;
5855
6028
  exports.useMediaQuery = useMediaQuery;
5856
6029
  exports.useMeta = useMeta;
6030
+ exports.useReactive = useReactive;
5857
6031
  exports.useRoot = useRoot;
5858
6032
  exports.useSessionStorage = useSessionStorage;
6033
+ exports.useState = useState;
5859
6034
  exports.useSuccesifKeys = useSuccesifKeys;
5860
6035
  exports.useSwipeEvent = useSwipeEvent;
5861
6036
  exports.useThread = useThread;
5862
- exports.useTimeLoop = useTimeLoop;
5863
6037
  exports.useTitle = useTitle;
5864
6038
  exports.wait = wait;
5865
6039
  exports.waitForUIElm = waitForUIElm;