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