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