ziko 0.38.1 → 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.
Files changed (51) hide show
  1. package/dist/ziko.cjs +962 -1360
  2. package/dist/ziko.js +962 -1360
  3. package/dist/ziko.min.js +2 -2
  4. package/dist/ziko.mjs +902 -1342
  5. package/package.json +1 -1
  6. package/src/data/index.js +2 -2
  7. package/src/data/string/checkers.js +27 -0
  8. package/src/data/string/converters.js +24 -0
  9. package/src/data/string/index.js +2 -1
  10. package/src/data/string-dep/index.js +1 -0
  11. package/src/events/types/clipboard.d.ts +2 -2
  12. package/src/events/types/focus.d.ts +2 -2
  13. package/src/events/types/pointer.d.ts +2 -2
  14. package/src/hooks/use-state.js +11 -8
  15. package/src/index.js +2 -1
  16. package/src/math/index.js +17 -17
  17. package/src/reactivity/hooks/UI/index.js +1 -1
  18. package/src/reactivity/hooks/UI/useRoot.js +3 -3
  19. package/src/time/animation/index.js +88 -70
  20. package/src/time/clocks/clock.js +62 -0
  21. package/src/time/clocks/index.js +3 -0
  22. package/src/time/clocks/scheduler.js +69 -0
  23. package/src/time/clocks/tick.js +34 -0
  24. package/src/time/converters/index.js +1 -0
  25. package/src/time/delay/index.js +2 -0
  26. package/src/time/delay/sleep.js +3 -0
  27. package/src/time/delay/timeout.js +15 -0
  28. package/src/time/ease/index.js +77 -0
  29. package/src/time/index.js +6 -9
  30. package/src/time/loop/index.js +67 -51
  31. package/src/time/utils/index.js +2 -2
  32. package/src/ui/__methods__/attrs.js +49 -0
  33. package/src/ui/__methods__/index.js +2 -1
  34. package/src/ui/__methods__/style.js +34 -0
  35. package/src/ui/__utils__/index.js +2 -2
  36. package/src/ui/constructors/{ZikoUIElement.js → UIElement.js} +23 -64
  37. package/src/ui/constructors/{ZikoUINode.js → UINode.js} +2 -2
  38. package/src/ui/constructors/style/index.js +2 -1
  39. package/src/ui/flex/index.js +8 -8
  40. package/src/ui/graphics/canvas.js +2 -2
  41. package/src/ui/graphics/svg.js +2 -2
  42. package/src/ui/grid/index.js +4 -4
  43. package/src/ui/index.js +2 -2
  44. package/src/ui/suspense/index.js +3 -3
  45. package/src/ui/tags/index.d.ts.txt +125 -125
  46. package/src/ui/tags/index.js +12 -16
  47. package/src/ui/text/index.js +2 -2
  48. package/src/ui/wrapper/index.js +3 -3
  49. package/src/time/utils/ease.js +0 -144
  50. /package/src/data/{string → string-dep}/patterns.js +0 -0
  51. /package/src/data/{string → string-dep}/string.js +0 -0
package/dist/ziko.js CHANGED
@@ -2,7 +2,7 @@
2
2
  /*
3
3
  Project: ziko.js
4
4
  Author: Zakaria Elalaoui
5
- Date : Sun Aug 17 2025 21:52:49 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
@@ -14,22 +14,22 @@
14
14
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Ziko = {}));
15
15
  })(this, (function (exports) { 'use strict';
16
16
 
17
- const { PI: PI$1, E } = Math;
17
+ const { PI: PI$2, E } = Math;
18
18
  const EPSILON=Number.EPSILON;
19
19
 
20
- const {PI, cos: cos$1, sin: sin$1, tan: tan$1, acos: acos$1, asin: asin$1, atan: atan$1, cosh: cosh$1, sinh: sinh$1, tanh: tanh$1, acosh: acosh$1, asinh: asinh$1, atanh: atanh$1, log} = Math;
20
+ const {PI: PI$1, cos: cos$2, sin: sin$2, tan: tan$1, acos: acos$2, asin: asin$1, atan: atan$1, cosh: cosh$1, sinh: sinh$1, tanh: tanh$1, acosh: acosh$1, asinh: asinh$1, atanh: atanh$1, log} = Math;
21
21
  let Fixed={
22
- cos: cos$1,
23
- sin: sin$1,
22
+ cos: cos$2,
23
+ sin: sin$2,
24
24
  tan: tan$1,
25
- sinc: x => sin$1(PI*x)/(PI*x),
26
- sec: x => 1/cos$1(x),
27
- csc: x => 1/sin$1(x),
25
+ sinc: x => sin$2(PI$1*x)/(PI$1*x),
26
+ sec: x => 1/cos$2(x),
27
+ csc: x => 1/sin$2(x),
28
28
  cot: x => 1/tan$1(x),
29
- acos: acos$1,
29
+ acos: acos$2,
30
30
  asin: asin$1,
31
31
  atan: atan$1,
32
- acot: x => PI/2-atan$1(x),
32
+ acot: x => PI$1/2-atan$1(x),
33
33
  cosh: cosh$1,
34
34
  sinh: sinh$1,
35
35
  tanh: tanh$1,
@@ -67,20 +67,20 @@
67
67
  const [a,b,z,phi]=[x.a,x.b,x.z,x.phi];
68
68
  switch(fun){
69
69
  case Math.log: return complex(ln(z),phi); // Done
70
- case Math.exp: return complex(e(a)*cos(b),e(a)*sin(b)); // Done
70
+ case Math.exp: return complex(e(a)*cos$1(b),e(a)*sin$1(b)); // Done
71
71
  case Math.abs: return z; // Done
72
- case Math.sqrt: return complex(sqrt(z)*cos(phi/2),sqrt(z)*sin(phi/2)); // Done
73
- case Fixed.cos: return complex(cos(a)*cosh(b),-(sin(a)*sinh(b)));
74
- case Fixed.sin: return complex(sin(a)*cosh(b),cos(a)*sinh(b));
72
+ case Math.sqrt: return complex(sqrt$1(z)*cos$1(phi/2),sqrt$1(z)*sin$1(phi/2)); // Done
73
+ case Fixed.cos: return complex(cos$1(a)*cosh(b),-(sin$1(a)*sinh(b)));
74
+ case Fixed.sin: return complex(sin$1(a)*cosh(b),cos$1(a)*sinh(b));
75
75
  case Fixed.tan:{
76
- const DEN = cos(2*a)+cosh(2*b);
77
- return complex(sin(2*a)/DEN,sinh(2*b)/DEN);
76
+ const DEN = cos$1(2*a)+cosh(2*b);
77
+ return complex(sin$1(2*a)/DEN,sinh(2*b)/DEN);
78
78
  }
79
- case Fixed.cosh:return complex(cosh(a)*cos(b),sinh(a)*sin(b));
80
- case Fixed.sinh:return complex(sinh(a)*cos(b),cosh(a)*sin(b));
79
+ case Fixed.cosh:return complex(cosh(a)*cos$1(b),sinh(a)*sin$1(b));
80
+ case Fixed.sinh:return complex(sinh(a)*cos$1(b),cosh(a)*sin$1(b));
81
81
  case Fixed.tanh:{
82
- const DEN=cosh(2*a)+cos(2*b);
83
- return complex(sinh(2*a)/DEN,sin(2*b)/DEN)
82
+ const DEN=cosh(2*a)+cos$1(2*b);
83
+ return complex(sinh(2*a)/DEN,sin$1(2*b)/DEN)
84
84
  }
85
85
  default : return fun(x)
86
86
  }
@@ -321,7 +321,7 @@
321
321
  }
322
322
  };
323
323
  const logspace=(a,b,n=b-a+1,base=E,endpoint=true)=>{
324
- return linspace(a,b,n,endpoint).map(n=>pow(base,n))
324
+ return linspace(a,b,n,endpoint).map(n=>pow$1(base,n))
325
325
  };
326
326
  const geomspace=(a,b,n=abs(b-a)+1,endpoint=true)=>{
327
327
  if(Math.floor(n)!==n)return;
@@ -1049,7 +1049,7 @@
1049
1049
  }
1050
1050
  };
1051
1051
 
1052
- class ZikoUINode {
1052
+ class UINode {
1053
1053
  constructor(node){
1054
1054
  this.cache = {
1055
1055
  node
@@ -1063,7 +1063,7 @@
1063
1063
  }
1064
1064
  }
1065
1065
 
1066
- globalThis.node = (node) => new ZikoUINode(node);
1066
+ globalThis.node = (node) => new UINode(node);
1067
1067
 
1068
1068
  function register_to_class(target, ...mixins){
1069
1069
  mixins.forEach(n => _register_to_class_(target, n));
@@ -1106,7 +1106,114 @@
1106
1106
  else register_to_instance(target, ...mixins);
1107
1107
  };
1108
1108
 
1109
- class ZikoUIText extends ZikoUINode {
1109
+ function useState(initialValue) {
1110
+ let value = initialValue;
1111
+ const subscribers = new Set();
1112
+ let paused = false;
1113
+
1114
+ function getValue() {
1115
+ return {
1116
+ value,
1117
+ isStateGetter: () => true,
1118
+ _subscribe: (
1119
+ fn,
1120
+ // UIElement
1121
+ ) => {
1122
+ subscribers.add(fn);
1123
+
1124
+ // const observer = new MutationObserver(() => {
1125
+ // if (!document.body.contains(UIElement.element)) {
1126
+ // subscribers.delete(fn);
1127
+ // observer.disconnect();
1128
+ // }
1129
+ // });
1130
+
1131
+ // observer.observe(document.body, { childList: true, subtree: true });
1132
+ },
1133
+ };
1134
+ }
1135
+
1136
+ function setValue(newValue) {
1137
+ if (paused) return;
1138
+ if (typeof newValue === "function") newValue = newValue(value);
1139
+ if (newValue !== value) {
1140
+ value = newValue;
1141
+ subscribers.forEach(fn => fn(value));
1142
+ }
1143
+ }
1144
+
1145
+ const controller = {
1146
+ pause: () => { paused = true; },
1147
+ resume: () => { paused = false; },
1148
+ clear: () => { subscribers.clear(); },
1149
+ force: (newValue) => { // force update even if paused
1150
+ if (typeof newValue === "function") newValue = newValue(value);
1151
+ value = newValue;
1152
+ subscribers.forEach(fn => fn(value));
1153
+ },
1154
+ getSubscribers: () => new Set(subscribers),
1155
+ };
1156
+
1157
+ return [getValue, setValue, controller];
1158
+ }
1159
+
1160
+ const isStateGetter = (arg) => {
1161
+ return typeof(arg) === 'function' && arg?.()?.isStateGetter?.()
1162
+ };
1163
+
1164
+ const camel2hyphencase = (text = '') => text.replace(/[A-Z]/g, match => '-' + match.toLowerCase());
1165
+
1166
+ const is_camelcase = (text = '') =>{
1167
+ if (text.length === 0) return false;
1168
+ const camelCasePattern = /^[a-z][a-zA-Z0-9]*$/;
1169
+ return camelCasePattern.test(text);
1170
+ };
1171
+
1172
+ // To Do add getter, watchAttr
1173
+ const AttrsMethods = {
1174
+ setAttr(name, value) {
1175
+ if(name instanceof Object){
1176
+ const [names,values]=[Object.keys(name),Object.values(name)];
1177
+ for(let i=0;i<names.length;i++){
1178
+ if(values[i] instanceof Array)value[i] = values[i].join(" ");
1179
+ _set_attrs_.call(this, names[i], values[i]);
1180
+ }
1181
+ }
1182
+ else {
1183
+ if(value instanceof Array) value = value.join(" ");
1184
+ _set_attrs_.call(this, name, value);
1185
+ }
1186
+ return this;
1187
+ },
1188
+ removeAttr(...names) {
1189
+ for(let i=0;i<names.length;i++)this.element?.removeAttribute(names[i]);
1190
+ return this;
1191
+ },
1192
+ getAttr(name){
1193
+ name = is_camelcase(name) ? camel2hyphencase(name) : name;
1194
+ return this.element.attributes[name].value;
1195
+ },
1196
+ setContentEditable(bool = true) {
1197
+ this.setAttr("contenteditable", bool);
1198
+ return this;
1199
+ }
1200
+ };
1201
+
1202
+ function _set_attrs_(name, value){
1203
+ if(this.element?.tagName !== "svg") name = is_camelcase(name) ? camel2hyphencase(name) : name;
1204
+ if(this?.attr[name] && this?.attr[name]===value) return;
1205
+ if(isStateGetter(value)){
1206
+ const getter = value();
1207
+ getter._subscribe(
1208
+ (newValue) => this.element?.setAttribute(name, newValue),
1209
+ this
1210
+ );
1211
+ }
1212
+ else this.element?.setAttribute(name, value);
1213
+ Object.assign(this.cache.attributes, {[name]:value});
1214
+ }
1215
+
1216
+ class ZikoUIText extends UINode {
1110
1217
  constructor(...value) {
1111
1218
  super("span", "text", false, ...value);
1112
1219
  this.element = globalThis?.document?.createTextNode(...value);
@@ -1652,723 +1759,175 @@
1652
1759
  },
1653
1760
  };
1654
1761
 
1655
- class ZikoUseStyle {
1656
- constructor(style = {}, use = style.hasOwnProperty("default")? "default" : Object.keys(style)[0], id = 0) {
1657
- this.id = "Ziko-Style-" + id;
1658
- this.keys = new Set();
1659
- this.styles = {
1660
- default: {
1661
- fontSize: "1em",
1662
- color : "green"
1663
- },
1664
- other: {
1665
- fontSize : "2em",
1666
- color : "cyan"
1667
- }
1668
- };
1669
- style && this.add(style);
1670
- use && this.use(use);
1671
- }
1672
-
1673
- get current() {
1674
- return [...this.keys].reduce((key, value) => {
1675
- key[value] = `var(--${value}-${this.id})`;
1676
- return key;
1677
- }, {});
1678
- }
1679
-
1680
- add(name, style = {}) {
1681
- if (name && typeof name === 'object' && !Array.isArray(name)) {
1682
- Object.assign(this.styles, name);
1683
- } else if (typeof name === 'string') {
1684
- Object.assign(this.styles, { [name]: style });
1685
- }
1686
- return this;
1687
- }
1688
-
1689
- #useStyleIndex(index) {
1690
- const keys = Object.keys(this.styles);
1691
- for (let a in this.styles[keys[index]]) {
1692
- if (Object.prototype.hasOwnProperty.call(this.styles[keys[index]], a)) {
1693
- document.documentElement.style.setProperty(`--${a}-${this.id}`, this.styles[keys[index]][a]);
1694
- this.keys.add(a);
1695
- }
1696
- }
1697
- return this;
1698
- }
1699
-
1700
- #useStyleName(name) {
1701
- if (!this.styles[name]) return this;
1702
- for (let a in this.styles[name]) {
1703
- if (Object.prototype.hasOwnProperty.call(this.styles[name], a)) {
1704
- document.documentElement.style.setProperty(`--${a}-${this.id}`, this.styles[name][a]);
1705
- this.keys.add(a);
1706
- }
1707
- }
1708
- return this;
1709
- }
1710
-
1711
- #useStyleObject(style) {
1712
- for (let a in style) {
1713
- if (Object.prototype.hasOwnProperty.call(style, a)) {
1714
- document.documentElement.style.setProperty(`--${a}-${this.id}`, style[a]);
1715
- this.keys.add(a);
1716
- }
1717
- }
1718
- return this;
1719
- }
1720
-
1721
- use(style) {
1722
- if (typeof style === "number") return this.#useStyleIndex(style);
1723
- if (typeof style === "string") return this.#useStyleName(style);
1724
- if (style && typeof style === "object") return this.#useStyleObject(style);
1725
- return this;
1726
- }
1727
- }
1728
-
1729
- const useStyle = (styles, use, id) => new ZikoUseStyle(styles, use, id);
1730
-
1731
- const addSuffixeToNumber=(value,suffixe="px")=>{
1732
- if(typeof value === "number") value+=suffixe;
1733
- if(value instanceof Array)value=value.map(n=>typeof n==="number"?n+=suffixe:n).join(" ");
1734
- return value;
1735
- };
1736
-
1737
- class ZikoUIElementStyle{
1738
- constructor(defaultStyle={}){
1739
- this.target=null;
1740
- this.styles=new Map(
1741
- [["default",defaultStyle]]
1742
- );
1743
- this.cache={
1744
- isHidden:false,
1745
- isFaddedOut:false,
1746
- transformation:{
1747
- Flip:[0,0,0],
1748
- matrix:new Matrix([
1749
- [1,0,0,0],
1750
- [0,1,0,0],
1751
- [0,0,1,0],
1752
- [0,0,0,1]
1753
- ])
1754
- }
1755
- };
1756
- }
1762
+ const StyleMethods = {
1757
1763
  style(styles){
1758
- for(const [key, value] of Object.entries(styles)){
1759
- if(Str.isCamelCase(key)){
1760
- delete styles[key];
1761
- Object.assign(styles,{[Str.camel2hyphencase(key)]:value});
1764
+ for(let key in styles){
1765
+ const value = styles[key];
1766
+ if(isStateGetter(value)){
1767
+ const getter = value();
1768
+ Object.assign(this.element.style, {[key] : getter.value});
1769
+ getter._subscribe(
1770
+ (newValue) => {
1771
+ console.log({newValue});
1772
+ Object.assign(this.element.style, {[key] : newValue});
1773
+ },
1774
+ // this
1775
+ );
1762
1776
  }
1777
+ else Object.assign(this.element.style, {[key] : value});
1763
1778
  }
1764
- if(this?.target?.element?.style)Object.assign(this?.target?.element?.style, styles);
1765
- return this;
1766
- }
1767
- linkTo(target){
1768
- this.target=target;
1769
- return this;
1770
- }
1771
- use(name="default"){
1772
- this.style(this.styles.get(name));
1773
- return this;
1774
- }
1775
- update(name,styles){
1776
- const old=this.styles.get(name);
1777
- old?this.styles.set(name,Object.assign(old,styles)):this.styles.set(name,styles);
1778
- return this;
1779
- }
1780
- add(name,styles){
1781
- this.styles.set(name,styles);
1782
1779
  return this;
1783
- }
1784
- replace(name,styles){
1785
- this.styles.set(name,styles);
1780
+ },
1781
+ size(width, height){
1782
+ return this.style({width, height})
1783
+ },
1784
+ hide(){
1785
+
1786
+ },
1787
+ show(){
1788
+
1789
+ },
1790
+ animate(keyframe, {duration=1000, iterations=1, easing="ease"}={}){
1791
+ this.element?.animate(keyframe,{duration, iterations, easing});
1786
1792
  return this;
1787
1793
  }
1788
- delete(...names){
1789
- names.forEach(n=>this.styles.delete(n));
1790
- return this;
1794
+ };
1795
+
1796
+ function EVENT_CONTROLLER(e,EVENT,setter,push_object){
1797
+ this.event=e;
1798
+ if(this.cache.preventDefault[EVENT])e.preventDefault();
1799
+ console.log({setter});
1800
+ if(setter)setter();
1801
+ if(this.cache.stream.enabled[EVENT]&&push_object)this.cache.stream.history[EVENT].push(push_object);
1802
+ this.cache.callbacks[EVENT].map(n=>n(this));
1803
+ return this;
1804
+ }
1805
+ class ZikoEvent{
1806
+ constructor(target){
1807
+ this.target=null;
1808
+ this.setTarget(target);
1809
+ this.__dispose=this.dispose.bind(this);
1810
+ // this.EventIndex=Garbage.Pointer.data.length;
1811
+ // Garbage.Pointer.data.push({event:this,index:this.EventIndex});
1791
1812
  }
1792
- updateDefaultStyle(){
1793
- const defaultStyle=Object.fromEntries(
1794
- Object.entries(this.target.element.style).filter(n=>isNaN(+n[0]))
1795
- );
1796
- this.update("default",defaultStyle);
1797
- return this;
1813
+ get targetElement(){
1814
+ return this.target.element
1798
1815
  }
1799
- hover(styles){
1800
- //this.updateDefaultStyle()
1801
- if(styles)this.add("hover",styles);
1802
- this.target?.element?.addEventListener("pointerenter",()=>this.use("hover"));
1803
- this.target?.element?.addEventListener("pointerleave",()=>this.use("default"));
1816
+ setTarget(UI){
1817
+ this.target=UI;
1804
1818
  return this;
1805
1819
  }
1806
- // Checkers
1807
- isInline(){
1808
- return getComputedStyle(this.target.element).display.includes("inline");
1820
+ __handle(event,handler,dispose){
1821
+ const EVENT=(event==="drag")?event:`${this.cache.prefixe}${event}`;
1822
+ this.dispose(dispose);
1823
+ this.targetElement?.addEventListener(EVENT,handler);
1824
+ return this;
1809
1825
  }
1810
- isBlock(){
1811
- return !(this.isInline());
1826
+ __onEvent(event,dispose,...callbacks){
1827
+ if(callbacks.length===0){
1828
+ if(this.cache.callbacks.length>1){
1829
+ this.cache.callbacks.map(n=>e=>n.call(this,e));
1830
+ }
1831
+ else {
1832
+ return this;
1833
+ }
1834
+ }
1835
+ else this.cache.callbacks[event]=callbacks.map(n=>e=>n.call(this,e));
1836
+ this.__handle(event,this.__controller[event],dispose);
1837
+ return this;
1812
1838
  }
1813
- // Size
1814
- size(width,height){
1815
- this.style({
1816
- width,
1817
- height
1818
- });
1839
+ preventDefault(config={}){
1840
+ Object.assign(this.cache.preventDefault,config);
1819
1841
  return this;
1820
1842
  }
1821
- width(w){
1822
- if(w instanceof Object){
1823
- if(w instanceof Array)w={min:w[0],max:w[1]};
1824
- if("min" in w || "max" in w){
1825
- let min= w.min ?? w.max;
1826
- let max= w.max ?? w.min;
1827
- min=addSuffixeToNumber(min,"px");
1828
- max=addSuffixeToNumber(max,"px");
1829
- this.style({ minWidth: min, maxWidth: max }, { target, maskVector });
1830
- }
1831
- }
1832
- else {
1833
- w=addSuffixeToNumber(w,"px");
1834
- this.style({width:w});
1835
- }
1836
- return this
1837
- }
1838
- height(h){
1839
- if(h instanceof Object){
1840
- if(h instanceof Array)h={min:h[0],max:h[1]};
1841
- if("min" in h || "max" in h){
1842
- let min= h.min ?? h.max;
1843
- let max= h.max ?? h.min;
1844
- min=addSuffixeToNumber(min,"px");
1845
- max=addSuffixeToNumber(max,"px");
1846
- this.style({ minHeight: min, maxHeight: max }, { target, maskVector });
1847
- }
1848
- }
1849
- else {
1850
- h=addSuffixeToNumber(h,"px");
1851
- this.style({height:h});
1852
- }
1853
- return this
1854
- }
1855
- enableResize(h=false,v=false){
1856
- let resize="none";
1857
- if(h)v?resize="both":resize="horizontal";
1858
- else v?resize="vertical":resize="none";
1859
- this.style({
1860
- resize,
1861
- overflow:"hidden"
1862
- });
1863
- if(this.isInline()){
1864
- console.group("Ziko Issue : Temporarily Incompatible Method");
1865
- console.warn(".enableResize has no effect on inline elements!");
1866
- console.info("%cConsider using other display types such as block, inline-block, flex, or grid for proper resizing behavior.","color:gold;background-color:#3333cc;padding:5px");
1867
- console.groupEnd();
1843
+ pause(config={}){
1844
+ const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,true]));
1845
+ config={...all,...config};
1846
+ for(let key in config){
1847
+ if(config[key]){
1848
+ this.targetElement?.removeEventListener(`${this.cache.prefixe}${key}`,this.__controller[`${this.cache.prefixe}${key}`]);
1849
+ this.cache.paused[`${this.cache.prefixe}${key}`]=true;
1850
+ }
1868
1851
  }
1869
1852
  return this;
1870
- }
1871
- // Apparence
1872
- hide({after, target, maskVector } = {}){
1873
- if(typeof after==="number"){
1874
- const wrapper=()=>this.hide({target,maskVector});
1875
- setTimeout(wrapper, after);
1876
- clearTimeout(wrapper);
1877
- }
1878
- else {
1879
- this.cache.isHidden=true;
1880
- this.style({display:"none"},{target,maskVector});
1853
+ }
1854
+ resume(config={}){
1855
+ const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,true]));
1856
+ config={...all,...config};
1857
+ for(let key in config){
1858
+ if(config[key]){
1859
+ this.targetElement?.addEventListener(`${this.cache.prefixe}${key}`,this.__controller[`${this.cache.prefixe}${key}`]);
1860
+ this.cache.paused[`${this.cache.prefixe}${key}`]=false;
1861
+ }
1881
1862
  }
1882
1863
  return this;
1883
- }
1884
- show({after, target, maskVector } = {}){
1885
- if(typeof after==="number"){
1886
- const wrapper=()=>this.show({target,maskVector});
1887
- setTimeout(wrapper, after);
1888
- clearTimeout(wrapper);
1889
- }
1890
- else {
1891
- this.cache.isHidden=false;
1892
- this.style({display:""},{target,maskVector});
1893
- }
1864
+ }
1865
+ dispose(config={}){
1866
+ this.pause(config);
1894
1867
  return this;
1895
- }
1896
- color(color){
1897
- this.style({color});
1868
+ }
1869
+ stream(config={}){
1870
+ this.cache.stream.t0=Date.now();
1871
+ const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,true]));
1872
+ config={...all,...config};
1873
+ Object.assign(this.cache.stream.enabled,config);
1898
1874
  return this;
1899
- }
1900
- background(background){
1901
- this.style({background});
1875
+ }
1876
+ clear(config={}){
1877
+ const all=Object.fromEntries(Object.keys(this.cache.stream.clear).map(n=>[n,true]));
1878
+ config={...all,...config};
1879
+ for(let key in config){
1880
+ if(config[key]){
1881
+ this.cache.stream.history[key]=[];
1882
+ }
1883
+ }
1902
1884
  return this;
1903
1885
  }
1904
- backgroundColor(backgroundColor){
1905
- this.style({backgroundColor});
1906
- return this;
1907
- }
1908
- opacity(opacity, { target, maskVector } = {}) {
1909
- this.style({ opacity }, { target, maskVector });
1910
- return this;
1911
- }
1912
- // Placement
1913
- position(position){
1914
- this.style({position});
1915
- return this
1916
- }
1917
- display(disp, { target, maskVector } = {}) {
1918
- this.style({ display: disp }, { target, maskVector });
1919
- return this;
1920
- }
1921
- zIndex(z){
1922
- this.style({zIndex:z});
1923
- return this;
1924
- }
1925
- float(float, { target, maskVector } = {}) {
1926
- this.style({ float: float }, { target, maskVector });
1927
- return this;
1928
- }
1929
- // Box Model
1930
- border(border = "1px solid red", { target, maskVector } = {}){
1931
- this.style({border}, { target, maskVector });
1932
- return this;
1933
- }
1934
- borderTop(borderTop = "1px solid red", { target, maskVector } = {}){
1935
- this.style({borderTop}, { target, maskVector });
1936
- return this;
1937
- }
1938
- borderRight(borderRight = "1px solid red", { target, maskVector } = {}){
1939
- this.style({borderRight}, { target, maskVector });
1940
- return this;
1941
- }
1942
- borderBottom(borderBottom = "1px solid red", { target, maskVector } = {}){
1943
- this.style({borderBottom}, { target, maskVector });
1944
- return this;
1945
- }
1946
- borderLeft(borderLeft = "1px solid red", { target, maskVector } = {}){
1947
- this.style({borderLeft}, { target, maskVector });
1948
- return this;
1949
- }
1950
- borderRadius(radius){
1951
- radius=addSuffixeToNumber(radius,"px");
1952
- this.style({ borderRadius: radius }, { target, maskVector });
1953
- return this;
1954
- }
1955
- margin(margin){
1956
- margin=addSuffixeToNumber(margin,"px");
1957
- this.style({ margin }, { target, maskVector });
1958
- return this;
1959
- }
1960
- marginTop(marginTop){
1961
- marginTop=addSuffixeToNumber(marginTop,"px");
1962
- this.style({marginTop});
1963
- return this;
1964
- }
1965
- marginRight(marginRight){
1966
- marginRight=addSuffixeToNumber(marginRight,"px");
1967
- this.style({marginRight});
1968
- return this;
1969
- }
1970
- marginBootom(marginBootom){
1971
- marginBootom=addSuffixeToNumber(marginBootom,"px");
1972
- this.style({marginBootom});
1973
- return this;
1974
- }
1975
- marginLeft(marginLeft){
1976
- marginLeft=addSuffixeToNumber(marginLeft,"px");
1977
- this.style({marginLeft});
1978
- return this;
1979
- }
1980
- padding(padding){
1981
- padding=addSuffixeToNumber(padding,"px");
1982
- this.style({padding});
1983
- return this;
1984
- }
1985
- paddingTop(paddingTop){
1986
- paddingTop=addSuffixeToNumber(paddingTop,"px");
1987
- this.style({paddingTop});
1988
- return this;
1989
- }
1990
- paddingRight(paddingRight){
1991
- paddingRight=addSuffixeToNumber(paddingRight,"px");
1992
- this.style({paddingRight});
1993
- return this;
1994
- }
1995
- paddingBootom(paddingBootom){
1996
- paddingBootom=addSuffixeToNumber(paddingBootom,"px");
1997
- this.style({paddingBootom});
1998
- return this;
1999
- }
2000
- paddingLeft(paddingLeft){
2001
- paddingLeft=addSuffixeToNumber(paddingLeft,"px");
2002
- this.style({paddingLeft});
2003
- return this;
2004
- }
2005
- // Typographie
2006
- font(font){
2007
- this.style({font});
2008
- return this;
2009
- }
2010
- fontFamily(fontFamily=""){
2011
- this.style({fontFamily});
2012
- return this;
2013
- }
2014
- fontSize(fontSize){
2015
- this.style({fontSize});
2016
- return this;
2017
- }
2018
- // Misc
2019
- cursor(type="pointer"){
2020
- this.style({ cursor: type });
2021
- return this;
2022
- }
2023
- overflow(x,y){
2024
- const values=["hidden","auto"];
2025
- this.style({
2026
- overflowX:typeof x==="number"?values[x]:x,
2027
- overflowY:typeof y==="number"?values[y]:y
2028
- },{target,maskVector});
2029
- return this;
2030
- }
2031
- clip(polygon, { target, maskVector } = {}) {
2032
- if (typeof polygon === "string") polygon = "polygon(" + polygon + ")";
2033
- this.style({ clipPath: polygon }, { target, maskVector });
2034
- return this;
2035
- }
2036
- // Transfromations
2037
- fadeOut(transitionTimming = 1) {
2038
- this.style({
2039
- transition:`opacity ${transitionTimming/1000}s`,
2040
- opacity: 0
2041
- });
2042
- this.cache.isFaddedOut=true;
2043
- return this;
2044
- }
2045
- fadeIn(transitionTimming = 1) {
2046
- this.style({
2047
- transition: `opacity ${transitionTimming/1000}s`,
2048
- opacity: 1
2049
- });
2050
- this.cache.isFaddedOut=false;
2051
- return this;
2052
- }
2053
- toggleFade(t_in = 1000,t_out=t_in){
2054
- this.cache.isFaddedOut?this.fadeIn(t_in):this.fadeOut(t_out);
2055
- return this;
2056
- }
2057
- morphBorderRadius(newValue, transitionTimming){
2058
- this.style({
2059
- borderRadius: newValue,
2060
- transition: `borderRadius ${transitionTimming/1000}s`,
2061
- });
2062
- return this;
2063
- }
2064
- #applyTransformMatrix(transitionTimming){
2065
- const transformMatrix = this.cache.transformation.matrix.arr.join(",");
2066
- this.style({
2067
- transform: `matrix3d(${transformMatrix})`,
2068
- "-webkit-transform": `matrix3d(${transformMatrix})`,
2069
- "-moz-transform": `matrix3d(${transformMatrix})`,
2070
- "-ms-transform": `matrix3d(${transformMatrix})`,
2071
- "-o-transform": `matrix3d(${transformMatrix})`
2072
- });
2073
- if (transitionTimming != 0) this.style({ transition: `transform ${transitionTimming/1000}s ease` });
2074
- }
2075
- translate(dx, dy = dx ,dz = 0, transitionTimming = 0) {
2076
- this.cache.transformation.matrix.set(3,0,dx);
2077
- this.cache.transformation.matrix.set(3,1,dy);
2078
- this.cache.transformation.matrix.set(3,2,dz);
2079
- this.#applyTransformMatrix(transitionTimming);
2080
- return this;
2081
- }
2082
- translateX(dx, transitionTimming = 0) {
2083
- this.cache.transformation.matrix.set(3,0,dx);
2084
- this.#applyTransformMatrix(transitionTimming);
2085
- return this;
2086
- }
2087
- translateY(dy, transitionTimming = 0) {
2088
- this.cache.transformation.matrix.set(3,1,dy);
2089
- this.#applyTransformMatrix(transitionTimming);
2090
- return this;
2091
- }
2092
- translateZ(dz, transitionTimming = 0) {
2093
- const d=-1/this.cache.transformation.matrix[2][2];
2094
- this.cache.transformation.matrix.set(3,2,z);
2095
- this.cache.transformation.matrix.set(3,3,1-(dz/d));
2096
- this.#applyTransformMatrix(transitionTimming);
2097
- return this;
2098
- }
2099
- perspective(distance,transitionTimming=0){
2100
- const z=this.cache.transformation.matrix[3][2];
2101
- this.cache.transformation.matrix.set(2,2,-1/d);
2102
- this.cache.transformation.matrix.set(3,3,1-(z/distance));
2103
- this.#applyTransformMatrix(transitionTimming);
2104
- return this;
2105
- }
2106
- scale(sx, sy = sx, transitionTimming = 0) {
2107
- this.cache.transformation.matrix.set(0,0,sx);
2108
- this.cache.transformation.matrix.set(1,1,sy);
2109
- // const transformMatrix = this.cache.transformation.matrix.arr.join(",");
2110
- this.#applyTransformMatrix(transitionTimming);
2111
- return this;
2112
- }
2113
- scaleX(x = 1 , transitionTimming = 0) {
2114
- this.cache.transformation.matrix.set(0,0,x);
2115
- // const transformMatrix = this.cache.transformation.matrix.arr.join(",");
2116
- this.#applyTransformMatrix(transitionTimming);
2117
- return this;
2118
- }
2119
- scaleY(y = 1, transitionTimming = 0) {
2120
- this.cache.transformation.matrix.set(1,1,y);
2121
- this.cache.transformation.matrix.arr.join(",");
2122
- this.#applyTransformMatrix(transitionTimming);
2123
- return this;
2124
- }
2125
- skew(x, y = x, transitionTimming = 0) {
2126
- this.cache.transformation.matrix.set(0,1,x);
2127
- this.cache.transformation.matrix.set(1,0,y);
2128
- this.cache.transformation.matrix.arr.join(",");
2129
- this.#applyTransformMatrix(transitionTimming);
2130
- return this;
2131
- }
2132
- skewX(x = 1 , transitionTimming = 0) {
2133
- this.cache.transformation.matrix.set(0,1,x);
2134
- this.cache.transformation.matrix.arr.join(",");
2135
- this.#applyTransformMatrix(transitionTimming);
2136
- return this;
2137
- }
2138
- skewY(y = 1, transitionTimming = 0) {
2139
- this.cache.transformation.matrix.set(1,0,y);
2140
- this.cache.transformation.matrix.arr.join(",");
2141
- this.#applyTransformMatrix(transitionTimming);
2142
- return this;
2143
- }
2144
- rotateX(rx, transitionTimming = 0) {
2145
- this.cache.transformation.matrix.set(1,1,cos(rx));
2146
- this.cache.transformation.matrix.set(1,2,-sin(rx));
2147
- this.cache.transformation.matrix.set(2,1,sin(rx));
2148
- this.cache.transformation.matrix.set(1,2,cos(rx));
2149
- this.#applyTransformMatrix(transitionTimming);
2150
- return this;
2151
- }
2152
- rotateY(ry, transitionTimming = 0) {
2153
- this.cache.transformation.matrix.set(0,0,cos(ry));
2154
- this.cache.transformation.matrix.set(0,2,sin(ry));
2155
- this.cache.transformation.matrix.set(2,0,-sin(ry));
2156
- this.cache.transformation.matrix.set(2,2,cos(ry));
2157
- this.#applyTransformMatrix(transitionTimming);
2158
- return this;
2159
- }
2160
- rotateZ(rz, transitionTimming = 0) {
2161
- this.cache.transformation.matrix.set(0,0,cos(rz));
2162
- this.cache.transformation.matrix.set(0,1,-sin(rz));
2163
- this.cache.transformation.matrix.set(1,0,sin(rz));
2164
- this.cache.transformation.matrix.set(1,1,cos(rz));
2165
- this.#applyTransformMatrix(transitionTimming);
2166
- return this;
2167
- }
2168
- flipeX(transitionTimming = 1) {
2169
- this.cache.transformation.Flip[0] += 180;
2170
- this.cache.transformation.Flip[0] %= 360;
2171
- this.rotateX(this.cache.transformation.Flip[0], transitionTimming);
2172
- return this;
2173
- }
2174
- flipeY(transitionTimming = 1) {
2175
- this.cache.transformation.Flip[1] += 180 ;
2176
- this.cache.transformation.Flip[1] %= 360;
2177
- this.rotateY(this.cache.transformation.Flip[1], transitionTimming);
2178
- return this;
2179
- }
2180
- flipeZ(transitionTimming = 1) {
2181
- this.cache.transformation.Flip[2] += 180;
2182
- this.cache.transformation.Flip[2] %= 360;
2183
- this.rotateZ(this.cache.transformation.Flip[2], transitionTimming);
2184
- return this;
2185
- }
2186
- slideHeightIn(transitionTimming = 1, h = this.h) {
2187
- this.style({ transition: transitionTimming + "s", height: h });
2188
- return this;
2189
- }
2190
- slideHeightOut(transitionTimming = 1) {
2191
- this.style({ transition: transitionTimming + "s", height: 0 });
2192
- this.target?.element?.n("transitionend", () =>
2193
- this.style({ opacity: "none" }),
2194
- );
2195
- return this;
2196
- }
2197
- slideWidthIn(transitionTimming = 1, w = this.w) {
2198
- this.style({ transition: transitionTimming + "s", width: w });
2199
- return this;
2200
- }
2201
- slideWidthOut(transitionTimming = 1) {
2202
- this.style({ transition: transitionTimming + "s", width: 0 });
2203
- const wrapper=()=>{
2204
- this.style({ opacity: "none" });
2205
- };
2206
- this.target?.element?.addEventListener("transitionend",wrapper);
2207
- this.target?.element?.removeEventListener("transitionend",wrapper);
2208
- return this;
2209
- }
2210
- slideIn({ transitionTimming = 1, w = "100%", h = "auto" } = {}) {
2211
- this.style({
2212
- transition: transitionTimming + "s",
2213
- width: w,
2214
- height: h,
2215
- visibility: "visible",
2216
- });
2217
- return this;
2218
- }
2219
- slideOut({ transitionTimming = 1, width = 0, heightransitionTimming = 0 } = {}) {
2220
- this.style({
2221
- visibility: "hidden",
2222
- transition: transitionTimming + "s",
2223
- opacity: "none",
2224
- width: width,
2225
- height: height,
2226
- });
2227
- const wrapper=()=>{
2228
- this.style({ opacity: "none" });
2229
- };
2230
- this.target?.element?.addEventListener("transitionend",wrapper);
2231
- this.target?.element?.removeEventListener("transitionend",wrapper);
2232
- return this;
2233
- }
2234
-
2235
- }
2236
-
2237
- function EVENT_CONTROLLER(e,EVENT,setter,push_object){
2238
- this.event=e;
2239
- if(this.cache.preventDefault[EVENT])e.preventDefault();
2240
- console.log({setter});
2241
- if(setter)setter();
2242
- if(this.cache.stream.enabled[EVENT]&&push_object)this.cache.stream.history[EVENT].push(push_object);
2243
- this.cache.callbacks[EVENT].map(n=>n(this));
2244
- return this;
2245
- }
2246
- class ZikoEvent{
2247
- constructor(target){
2248
- this.target=null;
2249
- this.setTarget(target);
2250
- this.__dispose=this.dispose.bind(this);
2251
- // this.EventIndex=Garbage.Pointer.data.length;
2252
- // Garbage.Pointer.data.push({event:this,index:this.EventIndex});
2253
- }
2254
- get targetElement(){
2255
- return this.target.element
2256
- }
2257
- setTarget(UI){
2258
- this.target=UI;
2259
- return this;
2260
- }
2261
- __handle(event,handler,dispose){
2262
- const EVENT=(event==="drag")?event:`${this.cache.prefixe}${event}`;
2263
- this.dispose(dispose);
2264
- this.targetElement?.addEventListener(EVENT,handler);
2265
- return this;
2266
- }
2267
- __onEvent(event,dispose,...callbacks){
2268
- if(callbacks.length===0){
2269
- if(this.cache.callbacks.length>1){
2270
- this.cache.callbacks.map(n=>e=>n.call(this,e));
2271
- }
2272
- else {
2273
- return this;
2274
- }
2275
- }
2276
- else this.cache.callbacks[event]=callbacks.map(n=>e=>n.call(this,e));
2277
- this.__handle(event,this.__controller[event],dispose);
2278
- return this;
2279
- }
2280
- preventDefault(config={}){
2281
- Object.assign(this.cache.preventDefault,config);
2282
- return this;
2283
- }
2284
- pause(config={}){
2285
- const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,true]));
2286
- config={...all,...config};
2287
- for(let key in config){
2288
- if(config[key]){
2289
- this.targetElement?.removeEventListener(`${this.cache.prefixe}${key}`,this.__controller[`${this.cache.prefixe}${key}`]);
2290
- this.cache.paused[`${this.cache.prefixe}${key}`]=true;
2291
- }
2292
- }
2293
- return this;
2294
- }
2295
- resume(config={}){
2296
- const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,true]));
2297
- config={...all,...config};
2298
- for(let key in config){
2299
- if(config[key]){
2300
- this.targetElement?.addEventListener(`${this.cache.prefixe}${key}`,this.__controller[`${this.cache.prefixe}${key}`]);
2301
- this.cache.paused[`${this.cache.prefixe}${key}`]=false;
2302
- }
2303
- }
2304
- return this;
2305
- }
2306
- dispose(config={}){
2307
- this.pause(config);
2308
- return this;
2309
- }
2310
- stream(config={}){
2311
- this.cache.stream.t0=Date.now();
2312
- const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,true]));
2313
- config={...all,...config};
2314
- Object.assign(this.cache.stream.enabled,config);
2315
- return this;
2316
- }
2317
- clear(config={}){
2318
- const all=Object.fromEntries(Object.keys(this.cache.stream.clear).map(n=>[n,true]));
2319
- config={...all,...config};
2320
- for(let key in config){
2321
- if(config[key]){
2322
- this.cache.stream.history[key]=[];
2323
- }
2324
- }
2325
- return this;
2326
- }
2327
- }
2328
-
2329
- function input_controller(e){
2330
- EVENT_CONTROLLER.call(this,e,"input",null,null);
2331
- }
2332
- function change_controller(e){
2333
- EVENT_CONTROLLER.call(this,e,"change",null,null);
2334
- }
2335
- class ZikoEventInput extends ZikoEvent{
2336
- constructor(target){
2337
- super(target);
2338
- this.event=null;
2339
- this.cache={
2340
- prefixe:"",
2341
- preventDefault:{
2342
- input:false,
2343
- change:false,
2344
- },
2345
- paused:{
2346
- input:false,
2347
- change:false,
2348
- },
2349
- stream:{
2350
- enabled:{
2351
- input:false,
2352
- change:false,
2353
- },
2354
- clear:{
2355
- input:false,
2356
- change:false,
2357
- },
2358
- history:{
2359
- input:[],
2360
- change:[],
2361
- }
2362
- },
2363
- callbacks:{
2364
- input:[],
2365
- change:[],
2366
- }
2367
- };
2368
- this.__controller={
2369
- input:input_controller.bind(this),
2370
- change:change_controller.bind(this),
2371
- };
1886
+ }
1887
+
1888
+ function input_controller(e){
1889
+ EVENT_CONTROLLER.call(this,e,"input",null,null);
1890
+ }
1891
+ function change_controller(e){
1892
+ EVENT_CONTROLLER.call(this,e,"change",null,null);
1893
+ }
1894
+ class ZikoEventInput extends ZikoEvent{
1895
+ constructor(target){
1896
+ super(target);
1897
+ this.event=null;
1898
+ this.cache={
1899
+ prefixe:"",
1900
+ preventDefault:{
1901
+ input:false,
1902
+ change:false,
1903
+ },
1904
+ paused:{
1905
+ input:false,
1906
+ change:false,
1907
+ },
1908
+ stream:{
1909
+ enabled:{
1910
+ input:false,
1911
+ change:false,
1912
+ },
1913
+ clear:{
1914
+ input:false,
1915
+ change:false,
1916
+ },
1917
+ history:{
1918
+ input:[],
1919
+ change:[],
1920
+ }
1921
+ },
1922
+ callbacks:{
1923
+ input:[],
1924
+ change:[],
1925
+ }
1926
+ };
1927
+ this.__controller={
1928
+ input:input_controller.bind(this),
1929
+ change:change_controller.bind(this),
1930
+ };
2372
1931
  }
2373
1932
  get value(){
2374
1933
  return this.target.value;
@@ -3273,8 +2832,8 @@
3273
2832
  }
3274
2833
 
3275
2834
  __init__global__();
3276
- class ZikoUIElement extends ZikoUINode{
3277
- constructor(element, name="", {type="html", useDefaultStyle=false}={}){
2835
+ class UIElement extends UINode{
2836
+ constructor({element, name ='', type="html", useDefaultStyle=false}={}){
3278
2837
  super();
3279
2838
  this.target = globalThis.__Ziko__.__Config__.default.target||globalThis?.document?.body;
3280
2839
  if(typeof element === "string") {
@@ -3285,9 +2844,16 @@
3285
2844
  }
3286
2845
  }
3287
2846
  else {
3288
- this.target = element.parentElement;
3289
- }
3290
- register(this, DomMethods, IndexingMethods, EventsMethodes);
2847
+ this.target = element?.parentElement;
2848
+ }
2849
+ register(
2850
+ this,
2851
+ AttrsMethods,
2852
+ DomMethods,
2853
+ StyleMethods,
2854
+ IndexingMethods,
2855
+ EventsMethodes
2856
+ );
3291
2857
  Object.assign(this.cache, {
3292
2858
  name,
3293
2859
  isInteractive : [true, false][Math.floor(2*Math.random())],
@@ -3297,7 +2863,6 @@
3297
2863
  isHidden: false,
3298
2864
  isFrozzen:false,
3299
2865
  legacyParent : null,
3300
- style: new ZikoUIElementStyle({}),
3301
2866
  attributes: {},
3302
2867
  filters: {},
3303
2868
  temp:{}
@@ -3322,7 +2887,6 @@
3322
2887
  if(element)Object.assign(this.cache,{element});
3323
2888
  this.uuid = `${this.cache.name}-${Random.string(16)}`;
3324
2889
  this.ui_index = globalThis.__Ziko__.__CACHE__.get_ui_index();
3325
- this.cache.style.linkTo(this);
3326
2890
  useDefaultStyle && this.style({
3327
2891
  position: "relative",
3328
2892
  boxSizing:"border-box",
@@ -3404,25 +2968,17 @@
3404
2968
  else UI.element=this.element.cloneNode(true);
3405
2969
  return UI.render(render);
3406
2970
  }
3407
- style(styles){
3408
- styles instanceof ZikoUseStyle ? this.st.style(styles.current): this.st.style(styles);
3409
- return this;
3410
- }
3411
- size(width,height){
3412
- this.st.size(width,height);
3413
- return this;
3414
- }
3415
2971
  [Symbol.iterator]() {
3416
2972
  return this.items[Symbol.iterator]();
3417
2973
  }
3418
2974
  maintain() {
3419
- for (let i = 0; i < this.items.length; i++) {
3420
- Object.defineProperty(this, i, {
3421
- value: this.items[i],
3422
- writable: true,
3423
- configurable: true,
3424
- enumerable: false
3425
- });
2975
+ for (let i = 0; i < this.items.length; i++) {
2976
+ Object.defineProperty(this, i, {
2977
+ value: this.items[i],
2978
+ writable: true,
2979
+ configurable: true,
2980
+ enumerable: false
2981
+ });
3426
2982
  }
3427
2983
  }
3428
2984
  freeze(freeze){
@@ -3440,43 +2996,6 @@
3440
2996
  describe(label){
3441
2997
  if(label)this.setAttr("aria-label",label);
3442
2998
  }
3443
- animate(keyframe, {duration=1000, iterations=1, easing="ease"}={}){
3444
- this.element?.animate(keyframe,{duration, iterations, easing});
3445
- return this;
3446
- }
3447
- // Attributes
3448
- #setAttr(name, value){
3449
- if(this.element?.tagName !== "svg") name = Str.isCamelCase(name) ? Str.camel2hyphencase(name) : name;
3450
- if(this?.attr[name] && this?.attr[name]===value) return;
3451
- this.element?.setAttribute(name, value);
3452
- Object.assign(this.cache.attributes, {[name]:value});
3453
- }
3454
- setAttr(name, value) {
3455
- if(name instanceof Object){
3456
- const [names,values]=[Object.keys(name),Object.values(name)];
3457
- for(let i=0;i<names.length;i++){
3458
- if(values[i] instanceof Array)value[i] = values[i].join(" ");
3459
- this.#setAttr(names[i], values[i]);
3460
- }
3461
- }
3462
- else {
3463
- if(value instanceof Array)value = value.join(" ");
3464
- this.#setAttr(name, value);
3465
- }
3466
- return this;
3467
- }
3468
- removeAttr(...names) {
3469
- for(let i=0;i<names.length;i++)this.element?.removeAttribute(names[i]);
3470
- return this;
3471
- }
3472
- getAttr(name){
3473
- name = Str.isCamelCase(name) ? Str.camel2hyphencase(name) : name;
3474
- return this.element.attributes[name].value;
3475
- }
3476
- setContentEditable(bool = true) {
3477
- this.setAttr("contenteditable", bool);
3478
- return this;
3479
- }
3480
2999
  get children() {
3481
3000
  return [...this.element.children];
3482
3001
  }
@@ -3671,10 +3190,6 @@
3671
3190
  "desc", "title", "metadata", "foreignObject"
3672
3191
  ];
3673
3192
 
3674
- const isStateGetter = (arg) => {
3675
- return typeof(arg) === 'function' && arg?.()?.isStateGetter?.()
3676
- };
3677
-
3678
3193
  const tags = new Proxy({}, {
3679
3194
  get(target, prop) {
3680
3195
  if (typeof prop !== 'string') return undefined;
@@ -3682,27 +3197,23 @@
3682
3197
  let type ;
3683
3198
  if(HTMLTags.includes(tag)) type = 'html';
3684
3199
  if(SVGTags.includes(tag)) type = 'svg';
3685
- if(HTMLTags.includes(tag)) return (...args)=>{
3200
+ return (...args)=>{
3686
3201
  console.log(isStateGetter(args[0]));
3687
- // if(typeof args[0] === 'function') {
3688
- // console.log(args[0], args[0]?.() instanceof StateGetter)
3689
- // globalThis.a = args[0]
3690
- // console.log({t : a.constructor})
3691
- // }
3692
3202
  if(
3693
3203
  ['string', 'number'].includes(typeof args[0])
3694
- || args[0] instanceof ZikoUIElement
3204
+ || args[0] instanceof UIElement
3695
3205
  || (typeof args[0] === 'function' && args[0]().isStateGetter())
3696
- ) return new ZikoUIElement(tag, tag, {type}).append(...args);
3697
- return new ZikoUIElement(tag).setAttr(args.shift()).append(...args)
3206
+ ) return new UIElement({element : tag, name : tag, type}).append(...args);
3207
+ // console.log(args[0])
3208
+ return new UIElement({element : tag}).setAttr(args.shift()).append(...args)
3698
3209
  }
3699
- // if(SVGTags.includes(tag)) return (...args) => new ZikoUIElement(tag,"",{el_type : "svg"}).append(...args);
3210
+ // if(SVGTags.includes(tag)) return (...args) => new UIElement(tag,"",{el_type : "svg"}).append(...args);
3700
3211
  // return (...args)=>{
3701
- // if(!(args[0] instanceof ZikoUIElement) && args[0] instanceof Object){
3212
+ // if(!(args[0] instanceof UIElement) && args[0] instanceof Object){
3702
3213
  // let attributes = args.shift()
3703
- // return new ZikoUIElement(tag).setAttr(attributes).append(...args)
3214
+ // return new UIElement(tag).setAttr(attributes).append(...args)
3704
3215
  // }
3705
- // return new ZikoUIElement(tag).append(...args);
3216
+ // return new UIElement(tag).append(...args);
3706
3217
  // }
3707
3218
  // // switch(tag){
3708
3219
  // case "html" : globalThis?.document?.createElement("html")
@@ -3712,14 +3223,14 @@
3712
3223
  // case "meta" :
3713
3224
  // case "srcipt":
3714
3225
  // case "body" : return null; break;
3715
- // default : return new ZikoUIElement(tag);
3226
+ // default : return new UIElement(tag);
3716
3227
  // }
3717
3228
  }
3718
3229
  });
3719
3230
 
3720
- class ZikoUIFlex extends ZikoUIElement {
3231
+ class ZikoUIFlex extends UIElement {
3721
3232
  constructor(tag = "div", w = "100%", h = "100%") {
3722
- super(tag ,"Flex");
3233
+ super({element : tag , name : "Flex"});
3723
3234
  this.direction = "cols";
3724
3235
  if (typeof w == "number") w += "%";
3725
3236
  if (typeof h == "number") h += "%";
@@ -3787,13 +3298,13 @@
3787
3298
  }
3788
3299
  }
3789
3300
 
3790
- const Flex = (...ZikoUIElement) =>{
3301
+ const Flex = (...UIElement) =>{
3791
3302
  let tag="div";
3792
- if(typeof ZikoUIElement[0]==="string"){
3793
- tag=ZikoUIElement[0];
3794
- ZikoUIElement.pop();
3303
+ if(typeof UIElement[0]==="string"){
3304
+ tag=UIElement[0];
3305
+ UIElement.pop();
3795
3306
  }
3796
- return new ZikoUIFlex(tag).append(...ZikoUIElement);
3307
+ return new ZikoUIFlex(tag).append(...UIElement);
3797
3308
  };
3798
3309
  function set_vertical(direction){
3799
3310
  direction == 1
@@ -3816,9 +3327,9 @@
3816
3327
  return map_pos_x(-align);
3817
3328
  }
3818
3329
 
3819
- class ZikoUIGrid extends ZikoUIElement {
3330
+ class ZikoUIGrid extends UIElement {
3820
3331
  constructor(tag ="div", w = "50vw", h = "50vh") {
3821
- super(tag,"Grid");
3332
+ super({element : tag, name : "Grid"});
3822
3333
  this.direction = "cols";
3823
3334
  if (typeof w == "number") w += "%";
3824
3335
  if (typeof h == "number") h += "%";
@@ -3846,11 +3357,11 @@
3846
3357
  return this;
3847
3358
  }
3848
3359
  }
3849
- const Grid$1 = (...ZikoUIElement) => new ZikoUIGrid("div").append(...ZikoUIElement);
3360
+ const Grid$1 = (...UIElement) => new ZikoUIGrid("div").append(...UIElement);
3850
3361
 
3851
- class ZikoUISuspense extends ZikoUIElement{
3362
+ class ZikoUISuspense extends UIElement{
3852
3363
  constructor(fallback_ui, callback){
3853
- super("div", "suspense");
3364
+ super({element : "div", name : "suspense"});
3854
3365
  this.setAttr({
3855
3366
  dataTemp : "suspense"
3856
3367
  });
@@ -3872,9 +3383,9 @@
3872
3383
 
3873
3384
  const Suspense = (fallback_ui, callback) => new ZikoUISuspense(fallback_ui, callback);
3874
3385
 
3875
- class ZikoUIXMLWrapper extends ZikoUIElement{
3386
+ class ZikoUIXMLWrapper extends UIElement{
3876
3387
  constructor(XMLContent, type){
3877
- super("div", "");
3388
+ super({element : "div", name : ""});
3878
3389
  this.element.append(type==="svg"?svg2dom(XMLContent):html2dom(XMLContent));
3879
3390
  }
3880
3391
  }
@@ -3906,7 +3417,7 @@
3906
3417
  const HTMLWrapper = (HTMLContent) => new ZikoUIHTMLWrapper(HTMLContent);
3907
3418
  const SVGWrapper = (SVGContent) => new ZikoUISVGWrapper(SVGContent);
3908
3419
 
3909
- class ZikoUICanvas extends ZikoUIElement{
3420
+ class ZikoUICanvas extends UIElement{
3910
3421
  constructor(w,h){
3911
3422
  super("canvas","canvas");
3912
3423
  this.ctx = this.element?.getContext("2d");
@@ -4076,7 +3587,7 @@
4076
3587
 
4077
3588
  const Canvas=(w,h)=>new ZikoUICanvas(w,h);
4078
3589
 
4079
- class ZikoUISvg extends ZikoUIElement {
3590
+ class ZikoUISvg extends UIElement {
4080
3591
  constructor(w=360,h=300) {
4081
3592
  super("svg","svg");
4082
3593
  //this.cache={};
@@ -4285,175 +3796,6 @@
4285
3796
  }, Array.isArray(obj) ? [] : {});
4286
3797
  }
4287
3798
 
4288
- const Patterns={
4289
- isDigit: /^\d+$/,
4290
- isURL: /^(https?:\/\/)?([\w\-]+\.)+[\w\-]+(\/[\w\-./?%&=]*)?$/,
4291
- isHexColor: /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/,
4292
- 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]?)$/,
4293
- isMACAddress: /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/,
4294
- isDate: /^\d{4}-\d{2}-\d{2}$/,
4295
- };
4296
-
4297
- class Str{
4298
- constructor(string){
4299
- this.string=string;
4300
- }
4301
- isDigit() {
4302
- return Patterns.isDigit.test(this.string);
4303
- }
4304
- static isDigit(string){
4305
- return new Str(string).isDigit();
4306
- }
4307
- isNumber() {
4308
- return !isNaN(this.string);
4309
- }
4310
- static isNumber(string){
4311
- return new Str(string).isNumber();
4312
- }
4313
- isUrl(){
4314
- return Patterns.isURL.test(this.string);
4315
- }
4316
- static isUrl(string){
4317
- return new Str(string).isUrl();
4318
- }
4319
- isHexColor(){
4320
- return Patterns.isHexColor.test(this.string);
4321
- }
4322
- static isHexColor(string){
4323
- return new Str(string).isHexColor();
4324
- }
4325
- isIPv4(){
4326
- return Patterns.isIPv4.test(this.string);
4327
- }
4328
- static isIPv4(string){
4329
- return new Str(string).isIPv4();
4330
- }
4331
- isDate(){
4332
- return Patterns.isDate.test(this.string);
4333
- }
4334
- static isDate(string){
4335
- return new Str(string).isDate();
4336
- }
4337
- isMACAddress(){
4338
- return Patterns.isMACAddress.test(this.string);
4339
- }
4340
- static isMACAddress(string){
4341
- return new Str(string).isMACAddress();
4342
- }
4343
- isPascalCase(){
4344
- if (this.string.length === 0) return false;
4345
- const PascalCasePattern = /^[A-Z][a-zA-Z0-9]*$/;
4346
- return PascalCasePattern.test(this.string);
4347
- }
4348
- static isPascalCase(string){
4349
- return new Str(string).isPascalCase();
4350
- }
4351
- isCamelCase() {
4352
- if (this.string.length === 0) return false;
4353
- const camelCasePattern = /^[a-z][a-zA-Z0-9]*$/;
4354
- return camelCasePattern.test(this.string);
4355
- }
4356
- static isCamelCase(string){
4357
- return new Str(string).isCamelCase();
4358
- }
4359
- isHyphenCase(){
4360
- return this.string.split('-').length > 1;
4361
- }
4362
- static isHyphenCase(string){
4363
- return new Str(string).isHyphenCase();
4364
- }
4365
- isSnakeCase(){
4366
- return this.string.split('_').length > 1;
4367
- }
4368
- static isSnakeCase(string){
4369
- return new Str(string).isSnakeCase();
4370
- }
4371
- isPalindrome(){
4372
- const str=this.string.toLocaleLowerCase();
4373
- let l=str.length,i;
4374
- for(i=0;i<l/2;i++)if(str[i]!=str[l-i-1])return false;
4375
- return true;
4376
- }
4377
- static isPalindrome(string){
4378
- return new Str(string).isPalindrome();
4379
- }
4380
- static isAnagrams(word,words){
4381
- word=word.split("").sort();
4382
- words=words.split("").sort();
4383
- return JSON.stringify(word)===JSON.stringify(words);
4384
- }
4385
- isIsogram(){
4386
- return [...new Set(this.string.toLowerCase())].length===this.string.length;
4387
- }
4388
- static isIsogram(string){
4389
- return new Str(string).isIsogram();
4390
- }
4391
- static camel2hyphencase(text) {
4392
- return text.replace(/[A-Z]/g, match => '-' + match.toLowerCase());
4393
- }
4394
- static camel2snakecase(text) {
4395
- return text.replace(/[A-Z]/g, match => '_' + match.toLowerCase());
4396
- }
4397
- static camel2pascalcase(text) {
4398
- return text.charAt(0).toUpperCase() + text.slice(1);
4399
- }
4400
- static camel2constantcase(text) {
4401
- return text.replace(/[A-Z]/g, match => '_' + match).toUpperCase();
4402
- }
4403
- static pascal2snakecase(text) {
4404
- return text.replace(/([A-Z])/g, (match, offset) => offset ? '_' + match.toLowerCase() : match.toLowerCase());
4405
- }
4406
- static pascal2hyphencase(text) {
4407
- return text.replace(/([A-Z])/g, (match, offset) => offset ? '-' + match.toLowerCase() : match.toLowerCase());
4408
- }
4409
- static pascal2camelcase(text) {
4410
- return text.charAt(0).toLowerCase() + text.slice(1);
4411
- }
4412
- static pascal2constantcase(text) {
4413
- return text.replace(/([A-Z])/g, (match, offset) => offset ? '_' + match : match).toUpperCase();
4414
- }
4415
- static snake2camelcase(text) {
4416
- return text.replace(/(_\w)/g, match => match[1].toUpperCase());
4417
- }
4418
- static snake2hyphencase(text) {
4419
- return text.replace(/_/g, "-");
4420
- }
4421
- static snake2pascalcase(text) {
4422
- return text.split('_').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join('');
4423
- }
4424
- static snake2constantcase(text) {
4425
- return text.toUpperCase();
4426
- }
4427
- static hyphen2camelcase(text) {
4428
- return text.replace(/-([a-z])/g, match => match[1].toUpperCase());
4429
- }
4430
- static hyphen2snakecase(text) {
4431
- return text.replace(/-/g, '_');
4432
- }
4433
- static hyphen2pascalcase(text) {
4434
- return text.split('-').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join('');
4435
- }
4436
- static hyphen2constantcase(text) {
4437
- return text.replace(/-/g, '_').toUpperCase();
4438
- }
4439
- static constant2camelcase(text) {
4440
- return text.toLowerCase().replace(/_([a-z])/g, match => match[1].toUpperCase());
4441
- }
4442
- static constant2snakecase(text) {
4443
- return text.toLowerCase();
4444
- }
4445
- static constant2pascalcase(text) {
4446
- return text.toLowerCase().split('_').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join('');
4447
- }
4448
- static constant2hyphencase(text) {
4449
- return text.toLowerCase().replace(/_/g, '-');
4450
- }
4451
- }
4452
- const removeExtraSpace=str=>str.replace(/\s+/g,' ');
4453
- const count=(str,value)=>str.split("").filter(x => x==value).length;
4454
- const countWords=(str,value)=>str.split(" ").filter(x => x==value).length;
4455
- const str=string=>new Str(string);
4456
-
4457
3799
  class Matrix extends ZikoMath{
4458
3800
  constructor(rows, cols, element = [] ) {
4459
3801
  super();
@@ -4612,7 +3954,7 @@
4612
3954
  .mul(determinat(deleteRowAndColumn(M, i)))
4613
3955
  );*/
4614
3956
  //const to_be_added=Utils.add(Utils.mul(pow(-1, i),Utils.mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
4615
- const to_be_added=Utils.add(Utils.mul(pow(-1, i),Utils.mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
3957
+ const to_be_added=Utils.add(Utils.mul(pow$1(-1, i),Utils.mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
4616
3958
  answer=Utils.add(answer,to_be_added);
4617
3959
  }
4618
3960
  return answer;
@@ -5135,7 +4477,7 @@
5135
4477
  }
5136
4478
  else if(("a" in b && "z" in a)){
5137
4479
  this.a=a.a;
5138
- this.b=sqrt((a.z**2)-(a.a**2));
4480
+ this.b=sqrt$1((a.z**2)-(a.a**2));
5139
4481
  }
5140
4482
  else if(("a" in b && "phi" in a)){
5141
4483
  this.a=a.a;
@@ -5143,15 +4485,15 @@
5143
4485
  }
5144
4486
  else if(("b" in b && "z" in a)){
5145
4487
  this.b=a.b;
5146
- this.a=sqrt((a.z**2)-(a.b**2));
4488
+ this.a=sqrt$1((a.z**2)-(a.b**2));
5147
4489
  }
5148
4490
  else if(("b" in b && "phi" in a)){
5149
4491
  this.b=b;
5150
4492
  this.a=a.b/tan(a.phi);
5151
4493
  }
5152
4494
  else if(("z" in b && "phi" in a)){
5153
- this.a=a.z*cos(a.phi);
5154
- this.a=a.z*sin(a.phi);
4495
+ this.a=a.z*cos$1(a.phi);
4496
+ this.a=a.z*sin$1(a.phi);
5155
4497
  }
5156
4498
  }
5157
4499
  else if(typeof(a)==="number"&&typeof(b)==="number"){
@@ -5191,7 +4533,7 @@
5191
4533
  return new Complex(this.a, -this.b);
5192
4534
  }
5193
4535
  get inv() {
5194
- return new Complex(this.a / (pow(this.a, 2) + pow(this.b, 2)), -this.b / (pow(this.a, 2) + pow(this.b, 2)));
4536
+ return new Complex(this.a / (pow$1(this.a, 2) + pow$1(this.b, 2)), -this.b / (pow$1(this.a, 2) + pow$1(this.b, 2)));
5195
4537
  }
5196
4538
  add(...z) {
5197
4539
  for (let i = 0; i < z.length; i++) {
@@ -5219,8 +4561,8 @@
5219
4561
  }
5220
4562
  let Z=+prod(this.z,...z.map(n=>n.z)).toFixed(15);
5221
4563
  let phi=+sum(this.phi,...z.map(n=>n.phi)).toFixed(15);
5222
- this.a=+(Z*cos(phi).toFixed(15)).toFixed(14);
5223
- this.b=+(Z*sin(phi).toFixed(15)).toFixed(14);
4564
+ this.a=+(Z*cos$1(phi).toFixed(15)).toFixed(14);
4565
+ this.b=+(Z*sin$1(phi).toFixed(15)).toFixed(14);
5224
4566
  return this;
5225
4567
  }
5226
4568
  div(...z) {
@@ -5229,23 +4571,23 @@
5229
4571
  }
5230
4572
  let Z=+(this.z/prod(...z.map(n=>n.z))).toFixed(15);
5231
4573
  let phi=+(this.phi-sum(...z.map(n=>n.phi))).toFixed(15);
5232
- this.a=+(Z*cos(phi).toFixed(15)).toFixed(15);
5233
- this.b=+(Z*sin(phi).toFixed(15)).toFixed(15);
4574
+ this.a=+(Z*cos$1(phi).toFixed(15)).toFixed(15);
4575
+ this.b=+(Z*sin$1(phi).toFixed(15)).toFixed(15);
5234
4576
  return this;
5235
4577
  }
5236
4578
  pow(n) {
5237
4579
  if (floor(n) === n && n > 0) {
5238
4580
  let z=+(this.z**n).toFixed(15);
5239
4581
  let phi=+(this.phi*n).toFixed(15);
5240
- this.a=+(z*cos(phi).toFixed(15)).toFixed(15);
5241
- this.b=+(z*sin(phi).toFixed(15)).toFixed(15);
4582
+ this.a=+(z*cos$1(phi).toFixed(15)).toFixed(15);
4583
+ this.b=+(z*sin$1(phi).toFixed(15)).toFixed(15);
5242
4584
  }
5243
4585
  return this;
5244
4586
  }
5245
4587
  static fromExpo(z, phi) {
5246
4588
  return new Complex(
5247
- +(z * cos(phi)).toFixed(13),
5248
- +(z * sin(phi)).toFixed(13)
4589
+ +(z * cos$1(phi)).toFixed(13),
4590
+ +(z * sin$1(phi)).toFixed(13)
5249
4591
  );
5250
4592
  }
5251
4593
  get expo() {
@@ -5267,10 +4609,10 @@
5267
4609
  return z.clone.pow(n);
5268
4610
  }
5269
4611
  static xpowZ(x){
5270
- return complex((x**this.a)*cos(this.b*ln(x)),(x**this.a)*sin(this.b*ln(x)));
4612
+ return complex((x**this.a)*cos$1(this.b*ln(x)),(x**this.a)*sin$1(this.b*ln(x)));
5271
4613
  }
5272
4614
  sqrtn(n=2){
5273
- return complex(sqrtn(this.z,n)*cos(this.phi/n),sqrtn(this.z,n)*sin(this.phi/n));
4615
+ return complex(sqrtn(this.z,n)*cos$1(this.phi/n),sqrtn(this.z,n)*sin$1(this.phi/n));
5274
4616
  }
5275
4617
  get sqrt(){
5276
4618
  return this.sqrtn(2);
@@ -5279,14 +4621,14 @@
5279
4621
  return complex(this.z,this.phi);
5280
4622
  }
5281
4623
  get cos(){
5282
- return complex(cos(this.a)*cosh(this.b),sin(this.a)*sinh(this.b))
4624
+ return complex(cos$1(this.a)*cosh(this.b),sin$1(this.a)*sinh(this.b))
5283
4625
  }
5284
4626
  get sin(){
5285
- return complex(sin(this.a)*cosh(this.b),cos(this.a)*sinh(this.b))
4627
+ return complex(sin$1(this.a)*cosh(this.b),cos$1(this.a)*sinh(this.b))
5286
4628
  }
5287
4629
  get tan(){
5288
- const de=cos(this.a*2)+cosh(this.b*2);
5289
- return complex(sin(2*this.a)/de,sinh(2*this.b)/de);
4630
+ const de=cos$1(this.a*2)+cosh(this.b*2);
4631
+ return complex(sin$1(2*this.a)/de,sinh(2*this.b)/de);
5290
4632
  }
5291
4633
  printInConsole() {
5292
4634
  let string = this.a + " + " + this.b + " * i";
@@ -5317,12 +4659,12 @@
5317
4659
  // } from "../calculus/index.js";
5318
4660
 
5319
4661
  const abs=(...x)=>mapfun$1(Math.abs,...x);
5320
- const sqrt=(...x)=>mapfun$1(Math.sqrt,...x);
5321
- const pow=(x,n)=>{
4662
+ const sqrt$1=(...x)=>mapfun$1(Math.sqrt,...x);
4663
+ const pow$1=(x,n)=>{
5322
4664
  if(typeof x === "number"){
5323
4665
  if(typeof n === "number")return Math.pow(x,n);
5324
4666
  else if(n instanceof Complex)return Complex.fromExpo(x**n.a,n.b*ln(x))
5325
- else return mapfun$1(a=>pow(x,a),...n);
4667
+ else return mapfun$1(a=>pow$1(x,a),...n);
5326
4668
  }
5327
4669
  else if(x instanceof Complex){
5328
4670
  if(typeof n === "number")return Complex.fromExpo(x.z**n,x.phi*n);
@@ -5330,14 +4672,14 @@
5330
4672
  x.z**n.a*e(-x.phi*n.b),
5331
4673
  ln(x.z)*n.b+n.a*x.phi
5332
4674
  )
5333
- else return mapfun$1(a=>pow(x,a),...n);
4675
+ else return mapfun$1(a=>pow$1(x,a),...n);
5334
4676
  }
5335
4677
  else if(x instanceof Array){
5336
- if(typeof n === "number") return mapfun$1(a=>pow(a,n),...x);
4678
+ if(typeof n === "number") return mapfun$1(a=>pow$1(a,n),...x);
5337
4679
  else if(n instanceof Array){
5338
4680
  const Y=[];
5339
4681
  for(let i=0;i<x.length;i++){
5340
- Y.push(mapfun$1(a=>pow(x[i],a),...n));
4682
+ Y.push(mapfun$1(a=>pow$1(x[i],a),...n));
5341
4683
  }
5342
4684
  return Y;
5343
4685
  }
@@ -5362,293 +4704,533 @@
5362
4704
  return Y;
5363
4705
  }
5364
4706
  }
5365
- };
5366
- const e=(...x) => mapfun$1(Math.exp,...x);
5367
- const ln=(...x) => mapfun$1(Math.log,...x);
5368
- const cos=(...x) => mapfun$1(Fixed.cos,...x);
5369
- const sin=(...x) => mapfun$1(Fixed.sin,...x);
5370
- const tan=(...x) => mapfun$1(Fixed.tan,...x);
5371
- const sec=(...x) => mapfun$1(Fixed.sec,...x);
5372
- const sinc=(...x) => mapfun$1(Fixed.sinc,...x);
5373
- const csc=(...x) => mapfun$1(Fixed.csc,...x);
5374
- const cot=(...x) => mapfun$1(Fixed.cot,...x);
5375
- const acos=(...x) => mapfun$1(Fixed.acos,...x);
5376
- const asin=(...x) => mapfun$1(Fixed.asin,...x);
5377
- const atan=(...x) => mapfun$1(Fixed.atan,...x);
5378
- const acot=(...x) => mapfun$1(Fixed.acot,...x);
5379
- const cosh=(...x) => mapfun$1(Fixed.cosh,...x);
5380
- const sinh=(...x) => mapfun$1(Fixed.sinh,...x);
5381
- const tanh=(...x) => mapfun$1(Fixed.tanh,...x);
5382
- const coth=(...x) => mapfun$1(Fixed.coth,...x);
5383
- const acosh=(...x) => mapfun$1(Fixed.acosh,...x);
5384
- const asinh=(...x) => mapfun$1(Fixed.asinh,...x);
5385
- const atanh=(...x) => mapfun$1(Fixed.atanh,...x);
5386
- const ceil=(...x) => mapfun$1(Math.ceil,...x);
5387
- const floor=(...x) => mapfun$1(Math.floor,...x);
5388
- const round=(...x) => mapfun$1(Math.round,...x);
5389
- const atan2=(x,y,rad=true)=>{
5390
- if(typeof x === "number"){
5391
- if(typeof y === "number")return rad?Math.atan2(x,y):Math.atan2(x,y)*180/Math.PI;
5392
- else return mapfun$1(a=>atan2(x,a,rad),...y);
4707
+ };
4708
+ const e=(...x) => mapfun$1(Math.exp,...x);
4709
+ const ln=(...x) => mapfun$1(Math.log,...x);
4710
+ const cos$1=(...x) => mapfun$1(Fixed.cos,...x);
4711
+ const sin$1=(...x) => mapfun$1(Fixed.sin,...x);
4712
+ const tan=(...x) => mapfun$1(Fixed.tan,...x);
4713
+ const sec=(...x) => mapfun$1(Fixed.sec,...x);
4714
+ const sinc=(...x) => mapfun$1(Fixed.sinc,...x);
4715
+ const csc=(...x) => mapfun$1(Fixed.csc,...x);
4716
+ const cot=(...x) => mapfun$1(Fixed.cot,...x);
4717
+ const acos$1=(...x) => mapfun$1(Fixed.acos,...x);
4718
+ const asin=(...x) => mapfun$1(Fixed.asin,...x);
4719
+ const atan=(...x) => mapfun$1(Fixed.atan,...x);
4720
+ const acot=(...x) => mapfun$1(Fixed.acot,...x);
4721
+ const cosh=(...x) => mapfun$1(Fixed.cosh,...x);
4722
+ const sinh=(...x) => mapfun$1(Fixed.sinh,...x);
4723
+ const tanh=(...x) => mapfun$1(Fixed.tanh,...x);
4724
+ const coth=(...x) => mapfun$1(Fixed.coth,...x);
4725
+ const acosh=(...x) => mapfun$1(Fixed.acosh,...x);
4726
+ const asinh=(...x) => mapfun$1(Fixed.asinh,...x);
4727
+ const atanh=(...x) => mapfun$1(Fixed.atanh,...x);
4728
+ const ceil=(...x) => mapfun$1(Math.ceil,...x);
4729
+ const floor=(...x) => mapfun$1(Math.floor,...x);
4730
+ const round=(...x) => mapfun$1(Math.round,...x);
4731
+ const atan2=(x,y,rad=true)=>{
4732
+ if(typeof x === "number"){
4733
+ if(typeof y === "number")return rad?Math.atan2(x,y):Math.atan2(x,y)*180/Math.PI;
4734
+ else return mapfun$1(a=>atan2(x,a,rad),...y);
4735
+ }
4736
+ // else if(x instanceof Complex){
4737
+ // if(typeof n === "number")return Complex.fromExpo(x.z**n,x.phi*n);
4738
+ // else return mapfun(a=>pow(x,a),...n);
4739
+ // }
4740
+ else if(x instanceof Array){
4741
+ if(typeof y === "number") return mapfun$1(a=>atan2(a,y,rad),...x);
4742
+ else if(y instanceof Array){
4743
+ const Y=[];
4744
+ for(let i=0;i<x.length;i++){
4745
+ Y.push(mapfun$1(a=>pow$1(x[i],a),...y));
4746
+ }
4747
+ return Y;
4748
+ }
4749
+ }
4750
+ };
4751
+ const fact=(...x)=>mapfun$1(n=> {
4752
+ let i,
4753
+ y = 1;
4754
+ if (n == 0) y = 1;
4755
+ else if (n > 0) for (i = 1; i <= n; i++) y *= i;
4756
+ else y = NaN;
4757
+ return y;
4758
+ },...x);
4759
+ const sign=(...x)=>mapfun$1(Math.sign,...x);
4760
+
4761
+ const sig=(...x)=>mapfun$1(n=>1/(1+e(-n)),...x);
4762
+
4763
+ const hypot=(...x)=>{
4764
+ if(x.every(n=>typeof n === "number"))return Math.hypot(...x);
4765
+ if(x.every(n=>n instanceof Array))return mapfun$1(
4766
+ Math.hypot,
4767
+ ...x
4768
+ )
4769
+ };
4770
+
4771
+ const {PI, sqrt, cos, sin, acos, pow} = Math;
4772
+
4773
+ const Linear = t => t;
4774
+ const InSin = t => 1 - cos((t * PI) / 2);
4775
+ const OutSin = t => sin((t * PI) / 2);
4776
+ const InOutSin = t => -(cos(PI * t) - 1) / 2;
4777
+
4778
+ const InQuad = t => t**2;
4779
+ const OutQuad = t => 1 - (1-t)**2;
4780
+ const InOutQuad = t => t < 0.5 ? 2 * (t**2) : 1 - (-2 * t + 2)**2 / 2;
4781
+
4782
+ const InCubic = t => t**3;
4783
+ const OutCubic = t => 1 - (1-t)**3;
4784
+ const InOutCubic = t => t < 0.5 ? 4 * (t**3) : 1 - (-2 * t + 2)**3 / 2;
4785
+
4786
+ const InQuart = t => t**4;
4787
+ const OutQuart = t => 1 - (1-t)**4;
4788
+ const InOutQuart = t => t < 0.5 ? 8 * (t**4) : 1 - (-2 * t + 2)**4 / 2;
4789
+
4790
+ const InQuint = t => t**5;
4791
+ const OutQuint = t => 1 - (1-t)**5;
4792
+ const InOutQuint = t => t < 0.5 ? 16 * (t**5) : 1 - (-2 * t + 2)**5 / 2;
4793
+
4794
+ const InExpo = t => t === 0 ? 0 : 2**(10*t - 10);
4795
+ const OutExpo = t => t === 1 ? 1 : 1 - 2**(-10 * t);
4796
+ const InOutExpo = t => t === 0? 0: t === 1? 1: t < 0.5 ? 2**(20 * t - 10) / 2: (2 - 2**(-20 * t + 10)) / 2;
4797
+
4798
+ const InCirc = t => 1 - sqrt(1 - t**2);
4799
+ const OutCirc = t => sqrt(1 - (t-1)**2);
4800
+ const InOutCirc = t => t < 0.5? (1 - sqrt(1 - (2*t)**2)) / 2: (sqrt(1 - (-2*t+2)**2) + 1) / 2;
4801
+
4802
+ const Arc = t => 1 - sin(acos(t));
4803
+ const Back = (t, x = 1) => (t**2) * ((x+1)*t - x);
4804
+ const Elastic = t => -2*pow(2, 10 * (t - 1)) * cos(20 * PI * t / 3 * t);
4805
+
4806
+ const InBack = (t, c1 = 1.70158, c3 = c1 + 1) => c3 * pow(t,3)- c1 * (t**2);
4807
+ const OutBack = (t, c1 = 1.70158, c3 = c1 + 1) => 1 + c3 * pow(t - 1, 3) + c1 * pow(t - 1, 2);
4808
+ const InOutBack = (t, c1 = 1.70158, c2 = c1 * 1.525) => t < 0.5 ? (pow(2 * t, 2) * ((c2 + 1) * 2 * t - c2)) / 2 : (pow(2 * t - 2, 2) * ((c2 + 1) * (t * 2 - 2) + c2) + 2) / 2;
4809
+
4810
+ const InElastic = (t, c4 = 2*PI/3) => {
4811
+ return t === 0
4812
+ ? 0
4813
+ : t === 1
4814
+ ? 1
4815
+ : -pow(2, 10 * t - 10) * sin((t * 10 - 10.75) * c4);
4816
+ };
4817
+
4818
+ const OutElastic = (t, c4 = 2*PI/3) => {
4819
+ return t === 0
4820
+ ? 0
4821
+ : t === 1
4822
+ ? 1
4823
+ : pow(2, -10 * t) * sin((t * 10 - 0.75) * c4) + 1;
4824
+ };
4825
+ const InOutElastic = (t, c5 = 2 * PI / 4.5) => {
4826
+ return t === 0
4827
+ ? 0
4828
+ : t === 1
4829
+ ? 1
4830
+ : t < 0.5
4831
+ ? -(pow(2, 20 * t - 10) * sin((20 * t - 11.125) * c5)) / 2
4832
+ : (pow(2, -20 * t + 10) * sin((20 * t - 11.125) * c5)) / 2 + 1;
4833
+ };
4834
+
4835
+ const InBounce = (t, n1 = 7.5625, d1 = 2.75) => 1 - OutBounce(1-t, n1, d1);
4836
+ const OutBounce = (t, n1 = 7.5625, d1 = 2.75) => {
4837
+ if(t<1/d1) return n1 * t * t;
4838
+ if(t < 2 / d1) return n1 * (t -= 1.5 / d1) * t + 0.75;
4839
+ if(t < 2.5 / d1) return n1 * (t -= 2.25 / d1) * t + 0.9375;
4840
+ return n1 * (t -= 2.625 / d1) * t + 0.984375;
4841
+ };
4842
+
4843
+ const InOutBounce = (t, n1 = 7.5625, d1 = 2.75) => t < 0.5 ? OutBounce(1 - 2 * t, n1, d1)/2 : OutBounce(2 * t - 1, n1, d1)/2;
4844
+
4845
+
4846
+ const Step = (t, steps = 5) => Math.floor(t*steps) / steps;
4847
+ const Discret = (t, segments = 5) => Math.ceil(t*segments) / segments;
4848
+
4849
+ class TimeAnimation {
4850
+ constructor(callback, { ease = Linear, step = 50, t0 = 0, start = true, duration = 3000 } = {}) {
4851
+ this.callback = callback;
4852
+ this.state = {
4853
+ isRunning: false,
4854
+ animationId: null,
4855
+ startTime: null,
4856
+ ease,
4857
+ step,
4858
+ // interval: [t0, t1],
4859
+ autoStart: start,
4860
+ duration
4861
+ };
4862
+
4863
+ this.t = 0; // elapsed time
4864
+ this.tx = 0; // normalized [0,1]
4865
+ this.ty = 0; // eased value
4866
+ this.i = 0; // frame index
4867
+
4868
+ if (this.state.autoStart) {
4869
+ this.start();
4870
+ }
4871
+ }
4872
+
4873
+ // ---- private loop handler ----
4874
+ #tick = () => {
4875
+ this.t += this.state.step;
4876
+ this.i++;
4877
+
4878
+ this.tx = map(this.t, 0, this.state.duration, 0, 1);
4879
+ this.ty = this.state.ease(this.tx);
4880
+
4881
+ this.callback(this);
4882
+
4883
+ if (this.t >= this.state.duration) {
4884
+ clearInterval(this.state.animationId);
4885
+ this.state.isRunning = false;
4886
+ }
4887
+ };
4888
+
4889
+ // ---- core runner ----
4890
+ #run(reset = true) {
4891
+ if (!this.state.isRunning) {
4892
+ if (reset) this.reset(false);
4893
+
4894
+ this.state.isRunning = true;
4895
+ this.state.startTime = Date.now();
4896
+ this.state.animationId = setInterval(this.#tick, this.state.step);
4897
+ }
4898
+ return this;
4899
+ }
4900
+
4901
+ // ---- lifecycle methods ----
4902
+ start() {
4903
+ return this.#run(true);
4904
+ }
4905
+
4906
+ pause() {
4907
+ if (this.state.isRunning) {
4908
+ clearInterval(this.state.animationId);
4909
+ this.state.isRunning = false;
4910
+ }
4911
+ return this;
4912
+ }
4913
+
4914
+ resume() {
4915
+ return this.#run(false);
4916
+ }
4917
+
4918
+ stop() {
4919
+ this.pause();
4920
+ this.reset(false);
4921
+ return this;
4922
+ }
4923
+
4924
+ reset(restart = true) {
4925
+ this.t = 0;
4926
+ this.tx = 0;
4927
+ this.ty = 0;
4928
+ this.i = 0;
4929
+
4930
+ if (restart) this.start();
4931
+ return this;
4932
+ }
4933
+ }
4934
+
4935
+ // Hook-style factory
4936
+ const animation = (callback, {ease, t0, t1, start, duration} = {}) =>
4937
+ new TimeAnimation(callback, {ease, t0, t1, start, duration});
4938
+
4939
+ class Tick {
4940
+ constructor(ms, fn) {
4941
+ this.ms = ms;
4942
+ this.fn = fn;
4943
+ this.id = null;
4944
+ this.running = false;
4945
+ }
4946
+
4947
+ start() {
4948
+ if (!this.running) {
4949
+ this.running = true;
4950
+ this.id = setInterval(this.fn, this.ms);
4951
+ }
4952
+ return this;
4953
+ }
4954
+
4955
+ stop() {
4956
+ if (this.running) {
4957
+ this.running = false;
4958
+ clearInterval(this.id);
4959
+ this.id = null;
5393
4960
  }
5394
- // else if(x instanceof Complex){
5395
- // if(typeof n === "number")return Complex.fromExpo(x.z**n,x.phi*n);
5396
- // else return mapfun(a=>pow(x,a),...n);
5397
- // }
5398
- else if(x instanceof Array){
5399
- if(typeof y === "number") return mapfun$1(a=>atan2(a,y,rad),...x);
5400
- else if(y instanceof Array){
5401
- const Y=[];
5402
- for(let i=0;i<x.length;i++){
5403
- Y.push(mapfun$1(a=>pow(x[i],a),...y));
5404
- }
5405
- return Y;
5406
- }
4961
+ return this;
4962
+ }
4963
+
4964
+ isRunning() {
4965
+ return this.running;
4966
+ }
4967
+ }
4968
+ const tick = (ms, fn) => new Tick(ms, fn);
4969
+
4970
+ class Clock extends Tick {
4971
+ constructor(tickMs = 1000 / 60) {
4972
+ super(tickMs, () => this._tick());
4973
+ this.elapsed = 0;
4974
+ this._lastTime = performance.now();
4975
+ this._callbacks = new Set();
4976
+ }
4977
+
4978
+ _tick() {
4979
+ const now = performance.now();
4980
+ const delta = now - this._lastTime;
4981
+ this.elapsed += delta;
4982
+ this._lastTime = now;
4983
+
4984
+ for (const cb of this._callbacks) {
4985
+ cb({ elapsed: this.elapsed, delta });
5407
4986
  }
5408
- };
5409
- const fact=(...x)=>mapfun$1(n=> {
5410
- let i,
5411
- y = 1;
5412
- if (n == 0) y = 1;
5413
- else if (n > 0) for (i = 1; i <= n; i++) y *= i;
5414
- else y = NaN;
5415
- return y;
5416
- },...x);
5417
- const sign=(...x)=>mapfun$1(Math.sign,...x);
4987
+ }
5418
4988
 
5419
- const sig=(...x)=>mapfun$1(n=>1/(1+e(-n)),...x);
4989
+ onTick(cb) {
4990
+ this._callbacks.add(cb);
4991
+ return () => this._callbacks.delete(cb);
4992
+ }
5420
4993
 
5421
- const hypot=(...x)=>{
5422
- if(x.every(n=>typeof n === "number"))return Math.hypot(...x);
5423
- if(x.every(n=>n instanceof Array))return mapfun$1(
5424
- Math.hypot,
5425
- ...x
5426
- )
4994
+ reset() {
4995
+ this.elapsed = 0;
4996
+ this._lastTime = performance.now();
4997
+ }
4998
+
4999
+ pause() {
5000
+ super.stop();
5001
+ }
5002
+
5003
+ resume() {
5004
+ this._lastTime = performance.now();
5005
+ super.start();
5006
+ }
5007
+ }
5008
+
5009
+ const clock = (tickMs) => new Clock(tickMs);
5010
+
5011
+
5012
+ /*
5013
+
5014
+ const clock = new Clock(200);
5015
+
5016
+ clock.onTick(({ elapsed, delta }) => {
5017
+ console.log(`Elapsed: ${elapsed.toFixed(0)}ms, Delta: ${delta.toFixed(0)}ms`);
5018
+ });
5019
+
5020
+ clock.start();
5021
+
5022
+ setTimeout(() => clock.pause(), 1000);
5023
+ setTimeout(() => clock.resume(), 2000);
5024
+
5025
+ */
5026
+
5027
+ class TimeScheduler {
5028
+ constructor(tasks = [], { repeat = 1, loop = false } = {}) {
5029
+ this.tasks = tasks;
5030
+ this.repeat = repeat;
5031
+ this.loop = loop;
5032
+
5033
+ this.stopped = false;
5034
+ this.running = false;
5035
+
5036
+ // lifecycle hooks
5037
+ this.onStart = null;
5038
+ this.onTask = null;
5039
+ this.onEnd = null;
5040
+ }
5041
+
5042
+ async run() {
5043
+ if (this.running) return;
5044
+ this.running = true;
5045
+ this.stopped = false;
5046
+
5047
+ if (this.onStart) this.onStart();
5048
+
5049
+ let repeatCount = this.repeat;
5050
+
5051
+ do {
5052
+ for (const task of this.tasks) {
5053
+ if (this.stopped) return;
5054
+
5055
+ if (Array.isArray(task)) {
5056
+ // Parallel tasks
5057
+ await Promise.all(
5058
+ task.map(({ fn, delay = 0 }) =>
5059
+ new Promise(async (resolve) => {
5060
+ if (delay > 0) await new Promise(r => setTimeout(r, delay));
5061
+ if (this.onTask) this.onTask(fn);
5062
+ await fn();
5063
+ resolve();
5064
+ })
5065
+ )
5066
+ );
5067
+ } else {
5068
+ // Single task
5069
+ const { fn, delay = 0 } = task;
5070
+ if (delay > 0) await new Promise(r => setTimeout(r, delay));
5071
+ if (this.onTask) this.onTask(fn);
5072
+ await fn();
5073
+ }
5074
+ }
5075
+ } while (this.loop && !this.stopped && (repeatCount === Infinity || repeatCount-- > 1));
5076
+
5077
+ if (!this.stopped && this.onEnd) this.onEnd();
5078
+ this.running = false;
5079
+ }
5080
+
5081
+ stop() {
5082
+ this.stopped = true;
5083
+ this.running = false;
5084
+ }
5085
+
5086
+ addTask(task) {
5087
+ this.tasks.push(task);
5088
+ }
5089
+
5090
+ clearTasks() {
5091
+ this.tasks = [];
5092
+ }
5093
+ }
5094
+
5095
+ const Scheduler = (tasks, { repeat = null} = {}) => new TimeScheduler(tasks, { repeat});
5096
+
5097
+ const step_fps = (step_or_fps) => 1000 / step_or_fps;
5098
+
5099
+ const debounce=(fn,delay=1000)=>{
5100
+ return (...args) => setTimeout(()=>fn(...args),delay);
5101
+ };
5102
+ const throttle=(fn,delay)=>{
5103
+ let lastTime=0;
5104
+ return (...args) => {
5105
+ const now = new Date().getTime();
5106
+ if(now-lastTime < delay) return;
5107
+ lastTime = now;
5108
+ fn(...args);
5109
+ }
5427
5110
  };
5428
5111
 
5429
- class ZikoTimeLoop {
5430
- constructor(callback, step = 1000/30, startTime=0, endTime = Infinity, started = true) {
5112
+ function timeout(ms, fn) {
5113
+ let id;
5114
+ const promise = new Promise((resolve) => {
5115
+ id = setTimeout(() => {
5116
+ if (fn) fn();
5117
+ resolve();
5118
+ }, ms);
5119
+ });
5120
+
5121
+ return {
5122
+ id,
5123
+ clear: () => clearTimeout(id),
5124
+ promise
5125
+ };
5126
+ }
5127
+
5128
+ const sleep= ms => new Promise(res => setTimeout(res, ms));
5129
+
5130
+ // use it with await
5131
+
5132
+ class TimeLoop {
5133
+ constructor(callback, { step = 1000, t0 = 0, t1 = Infinity, autoplay = true } = {}) {
5431
5134
  this.callback = callback;
5432
5135
  this.cache = {
5433
5136
  isRunning: false,
5434
- AnimationId : null,
5435
- t0 : null,
5137
+ id: null,
5138
+ last_tick: null,
5436
5139
  step,
5437
- // fps,
5438
- startTime,
5439
- endTime,
5440
- started
5140
+ t0,
5141
+ t1,
5142
+ autoplay,
5143
+ pauseTime: null,
5144
+ frame : 0,
5441
5145
  };
5442
- this.init();
5443
- this.i=0;
5444
- }
5445
- init(){
5446
- // if(this.cache.step && this.cache.fps){
5447
- // console.warn(`Fps will be adjusted from ${this.cache.fps} to ${1000/this.cache.step} to ensure a smoother animation`);
5448
- // this.cache.fps=1000/this.cache.step;
5449
- // }
5450
- if(this.cache.started){
5451
- this.cache.startTime?this.startAfter(this.cache.startTime):this.start();
5452
- if(this.cache.endTime&&this.cache.endTime!==Infinity)this.stopAfter(this.cache.endTime);
5146
+
5147
+ if (autoplay) {
5148
+ t0 ? this.startAfter(t0) : this.start();
5149
+ if (t1 !== Infinity) this.stopAfter(t1);
5453
5150
  }
5454
- return this;
5455
5151
  }
5456
- // get TIME_STEP() {
5457
- // // return this.cache.step?this.cache.step:1000 / this.cache.fps;
5458
- // return this.cache.step;
5459
- // }
5152
+
5153
+ get frame(){
5154
+ return this.cache.frame;
5155
+ }
5156
+ get elapsed(){
5157
+ return this.cache.elapsed;
5158
+ }
5159
+
5460
5160
  start() {
5461
5161
  if (!this.cache.isRunning) {
5462
- this.i=0;
5162
+ this.cache.frame = 0;
5463
5163
  this.cache.isRunning = true;
5464
- this.cache.t0 = Date.now();
5164
+ this.cache.last_tick = Date.now();
5465
5165
  this.animate();
5466
5166
  }
5467
5167
  return this;
5468
5168
  }
5169
+
5469
5170
  pause() {
5470
5171
  if (this.cache.isRunning) {
5471
- clearTimeout(this.cache.AnimationId);
5172
+ clearTimeout(this.cache.id);
5472
5173
  this.cache.isRunning = false;
5174
+ this.cache.pauseTime = Date.now();
5473
5175
  }
5474
5176
  return this;
5475
5177
  }
5476
- stop(){
5477
- this.pause();
5478
- this.i=0;
5178
+
5179
+ resume() {
5180
+ if (!this.cache.isRunning) {
5181
+ this.cache.isRunning = true;
5182
+ if (this.cache.pauseTime) {
5183
+ // adjust start time so delta stays consistent
5184
+ const pausedDuration = Date.now() - this.cache.pauseTime;
5185
+ this.cache.last_tick += pausedDuration;
5186
+ }
5187
+ this.animate();
5188
+ }
5479
5189
  return this;
5480
5190
  }
5481
- resume(){
5482
- this.cache.isRunning=true;
5483
- this.animate();
5191
+
5192
+ stop() {
5193
+ this.pause();
5194
+ this.cache.frame = 0;
5484
5195
  return this;
5485
5196
  }
5486
- startAfter(t=1000){
5487
- setTimeout(this.start.bind(this),t);
5197
+
5198
+ startAfter(t = 1000) {
5199
+ setTimeout(() => this.start(), t);
5488
5200
  return this;
5489
5201
  }
5490
- stopAfter(t=1000){
5491
- setTimeout(this.stop.bind(this),t);
5492
- return this;
5202
+
5203
+ stopAfter(t = 1000) {
5204
+ setTimeout(() => this.stop(), t);
5205
+ return this;
5493
5206
  }
5207
+
5494
5208
  animate = () => {
5495
5209
  if (this.cache.isRunning) {
5496
5210
  const now = Date.now();
5497
- const delta = now - this.cache.t0;
5498
- if (delta > this.cache.step) {
5211
+ const delta = now - this.cache.last_tick;
5212
+
5213
+ if (delta >= this.cache.step) {
5214
+ this.cache.elapsed = now - (this.cache.t0 || 0);
5499
5215
  this.callback(this);
5500
- this.i++;
5501
- this.cache.t0 = now - (delta % this.cache.step);
5216
+ this.cache.frame++;
5217
+ this.cache.last_tick = now - (delta % this.cache.step);
5502
5218
  }
5503
- this.cache.AnimationId = setTimeout(this.animate, 0);
5504
- } }
5505
- }
5506
- const useFps = fps => 1000/fps;
5507
- const useTimeLoop = (callback, step, startTime, endTime, started) => new ZikoTimeLoop(callback, step, startTime, endTime, started);
5508
-
5509
- const Ease={
5510
- Linear:function(t){
5511
- return t;
5512
- },
5513
- InSin(t){
5514
- return 1 - Math.cos((t * Math.PI) / 2);
5515
- },
5516
- OutSin(t){
5517
- return Math.sin((t * Math.PI) / 2);
5518
- },
5519
- InOutSin(t){
5520
- return -(Math.cos(Math.PI * t) - 1) / 2;
5521
- },
5522
- InQuad(t){
5523
- return t**2;
5524
- },
5525
- OutQuad(t){
5526
- return 1 - Math.pow((1 - t),2)
5527
- },
5528
- InOutQuad(t){
5529
- return t < 0.5 ? 2 * Math.pow(t,2) : 1 - Math.pow(-2 * t + 2, 2) / 2;
5530
- },
5531
- InCubic(t){
5532
- return t**3;
5533
- },
5534
- OutCubic(t){
5535
- return 1 - Math.pow((1 - t),3)
5536
- },
5537
- InOutCubic(t){
5538
- return t < 0.5 ? 4 * Math.pow(t,3) : 1 - Math.pow(-2 * t + 2, 3) / 2;
5539
- },
5540
- InQuart(t){
5541
- return t**4;
5542
- },
5543
- OutQuart(t){
5544
- return 1 - Math.pow((1 - t),4);
5545
- },
5546
- InOutQuart(t){
5547
- return t < 0.5 ? 8 * Math.pow(t,4) : 1 - Math.pow(-2 * t + 2, 4) / 2;
5548
- },
5549
- InQuint(t){
5550
- return t**5;
5551
- },
5552
- OutQuint(t){
5553
- return 1 - Math.pow((1 - t),5);
5554
- },
5555
- InOutQuint(t){
5556
- return t < 0.5 ? 16 * Math.pow(t,5) : 1 - Math.pow(-2 * t + 2, 5) / 2;
5557
- },
5558
- InExpo(t){
5559
- return t === 0 ? 0 : Math.pow(2, 10 * t - 10);
5560
- },
5561
- OutExpo(t){
5562
- return t === 1 ? 1 : 1 - Math.pow(2, -10 * t);
5563
- },
5564
- InOutExpo(t){
5565
- 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;
5566
- },
5567
- InCirc(t){
5568
- return 1 - Math.sqrt(1 - Math.pow(t, 2));
5569
- },
5570
- OutCirc(t){
5571
- return Math.sqrt(1 - Math.pow(t - 1, 2));
5572
- },
5573
- InOutCic(t){
5574
- 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;
5575
- },
5576
- Arc(t){
5577
- return 1 - Math.sin(Math.acos(t));
5578
- },
5579
- Back(t){
5580
- // To Be Changed
5581
- let x=1;
5582
- return Math.pow(t, 2) * ((x + 1) * t - x);
5583
- },
5584
- Elastic(t){
5585
- return -2*Math.pow(2, 10 * (t - 1)) * Math.cos(20 * Math.PI * t / 3 * t);
5586
- },
5587
- InBack(t){
5588
- const c1 = 1.70158;
5589
- const c3 = c1 + 1;
5590
- return c3 *Math.pow(t,3)- c1 * (t**2);
5591
- },
5592
- OutBack(t){
5593
- const c1 = 1.70158;
5594
- const c3 = c1 + 1;
5595
- return 1 + c3 * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2);
5596
- },
5597
- InOutBack(t){
5598
- const c1 = 1.70158;
5599
- const c2 = c1 * 1.525;
5600
- return t < 0.5
5601
- ? (Math.pow(2 * t, 2) * ((c2 + 1) * 2 * t - c2)) / 2
5602
- : (Math.pow(2 * t - 2, 2) * ((c2 + 1) * (t * 2 - 2) + c2) + 2) / 2;
5603
- },
5604
- InElastic(t){
5605
- const c4 = (2 * Math.PI) / 3;return t === 0
5606
- ? 0
5607
- : t === 1
5608
- ? 1
5609
- : -Math.pow(2, 10 * t - 10) * Math.sin((t * 10 - 10.75) * c4);
5610
- },
5611
- OutElastic(t){
5612
- const c4 = (2 * Math.PI) / 3;
5613
- return t === 0
5614
- ? 0
5615
- : t === 1
5616
- ? 1
5617
- : Math.pow(2, -10 * t) * Math.sin((t * 10 - 0.75) * c4) + 1;
5618
- },
5619
- InOutElastic(t){
5620
- const c5 = (2 * Math.PI) / 4.5;
5621
- return t === 0
5622
- ? 0
5623
- : t === 1
5624
- ? 1
5625
- : t < 0.5
5626
- ? -(Math.pow(2, 20 * t - 10) * Math.sin((20 * t - 11.125) * c5)) / 2
5627
- : (Math.pow(2, -20 * t + 10) * Math.sin((20 * t - 11.125) * c5)) / 2 + 1;
5628
- },
5629
- InBounce(t){
5630
- return 1 - Ease.OutBounce(1-t);
5631
- },
5632
- OutBounce(t){
5633
- const n1 = 7.5625;
5634
- const d1 = 2.75;
5635
- if (t < 1 / d1) {
5636
- return n1 * t * t;
5637
- } else if (t < 2 / d1) {
5638
- return n1 * (t -= 1.5 / d1) * t + 0.75;
5639
- } else if (t < 2.5 / d1) {
5640
- return n1 * (t -= 2.25 / d1) * t + 0.9375;
5641
- } else {
5642
- return n1 * (t -= 2.625 / d1) * t + 0.984375;
5643
- }
5644
5219
 
5645
- },
5646
- InOutBounce(t){
5647
- return t < 0.5
5648
- ? (1 - Ease.OutBounce(1 - 2 * t)) / 2
5649
- : (1 + Ease.OutBounce(2 * t - 1)) / 2;
5220
+ this.cache.id = setTimeout(this.animate, 0);
5650
5221
  }
5651
- };
5222
+ }
5223
+ }
5224
+
5225
+ const loop = (callback, options = {}) => new TimeLoop(callback, options);
5226
+
5227
+
5228
+ // Helpers
5229
+ // const useFps = (fps) => 1000 / fps;
5230
+
5231
+ // const _loop = loop( e => {
5232
+ // console.log("Frame:", e.frame, " Elapsed: ", e.elapsed);
5233
+ // });
5652
5234
 
5653
5235
  const time_memory_Taken = (callback) => {
5654
5236
  const t0 = Date.now();
@@ -5691,6 +5273,7 @@
5691
5273
  }
5692
5274
  };
5693
5275
 
5276
+ // import Ease from "./ease.js";
5694
5277
  const wait=(delayInMS)=>{
5695
5278
  return new Promise((resolve) => setTimeout(resolve, delayInMS));
5696
5279
  };
@@ -5701,93 +5284,6 @@
5701
5284
  return r;
5702
5285
  };
5703
5286
 
5704
- class ZikoTimeAnimation{
5705
- constructor(callback,ease=Ease.Linear,step=50,{t=[0,null],start=true,duration=3000}={}){
5706
- this.cache={
5707
- isRunning:false,
5708
- AnimationId:null,
5709
- startTime:null,
5710
- ease,
5711
- step,
5712
- intervall:t,
5713
- started:start,
5714
- duration
5715
- };
5716
- this.t=0;
5717
- this.tx=0;
5718
- this.ty=0;
5719
- this.i=0;
5720
- this.callback=callback;
5721
- }
5722
- #animation_handler(){
5723
- this.t+=this.cache.step;
5724
- this.i++;
5725
- this.tx=map(this.t,0,this.cache.duration,0,1);
5726
- this.ty=this.cache.ease(this.tx);
5727
- this.callback(this);
5728
- if(this.t>=this.cache.duration){
5729
- clearInterval(this.cache.AnimationId);
5730
- this.cache.isRunning=false;
5731
- }
5732
- }
5733
- reset(restart=true){
5734
- this.t=0;
5735
- this.tx=0;
5736
- this.ty=0;
5737
- this.i=0;
5738
- if(restart)this.start();
5739
- return this;
5740
- }
5741
- #animate(reset=true){
5742
- if(!this.cache.isRunning){
5743
- if(reset)this.reset(false);
5744
- this.cache.isRunning=true;
5745
- this.cache.startTime = Date.now();
5746
- this.cache.AnimationId=setInterval(this.#animation_handler.bind(this),this.cache.step);
5747
- }
5748
- return this;
5749
- }
5750
- start(){
5751
- this.#animate(true);
5752
- return this;
5753
- }
5754
- pause(){
5755
- if (this.cache.isRunning) {
5756
- clearTimeout(this.cache.AnimationId);
5757
- this.cache.isRunning = false;
5758
- }
5759
- return this;
5760
- }
5761
- resume(){
5762
- this.#animate(false);
5763
- return this;
5764
- }
5765
- stop(){
5766
- this.pause();
5767
- this.reset(false);
5768
- return this;
5769
- }
5770
- // clear(){
5771
- // }
5772
- // stream(){
5773
- // }
5774
- }
5775
-
5776
- const useAnimation=(callback,ease=Ease.Linear,step=50,config)=>new ZikoTimeAnimation(callback,ease=Ease.Linear,step=50,config);
5777
-
5778
- const debounce=(fn,delay=1000)=>{
5779
- return (...args) => setTimeout(()=>fn(...args),delay);
5780
- };
5781
- const throttle=(fn,delay)=>{
5782
- let lastTime=0;
5783
- return (...args) => {
5784
- const now = new Date().getTime();
5785
- if(now-lastTime < delay) return;
5786
- lastTime = now;
5787
- fn(...args);
5788
- }
5789
- };
5790
-
5791
5287
  class ZikoApp {
5792
5288
  constructor({head = null, wrapper = null, target = null}){
5793
5289
  this.head = head;
@@ -6003,6 +5499,70 @@
6003
5499
  return commonPath;
6004
5500
  }
6005
5501
 
5502
+ function useDerived(deriveFn, sources) {
5503
+ let value = deriveFn(...sources.map(s => s().value));
5504
+ const subscribers = new Set();
5505
+ let paused = false;
5506
+
5507
+ function getValue() {
5508
+ return {
5509
+ value,
5510
+ isStateGetter: () => true,
5511
+ _subscribe: (fn, UIElement) => {
5512
+ subscribers.add(fn);
5513
+
5514
+ const observer = new MutationObserver(() => {
5515
+ if (!document.body.contains(UIElement.element)) {
5516
+ subscribers.delete(fn);
5517
+ observer.disconnect();
5518
+ }
5519
+ });
5520
+
5521
+ observer.observe(document.body, { childList: true, subtree: true });
5522
+ },
5523
+ };
5524
+ }
5525
+
5526
+ function setValue(newValue) {
5527
+ if (paused) return;
5528
+ if (typeof newValue === "function") newValue = newValue(value);
5529
+ if (newValue !== value) {
5530
+ value = newValue;
5531
+ subscribers.forEach(fn => fn(value));
5532
+ }
5533
+ }
5534
+
5535
+ const controller = {
5536
+ pause: () => { paused = true; },
5537
+ resume: () => { paused = false; },
5538
+ clear: () => { subscribers.clear(); },
5539
+ force: (newValue) => {
5540
+ if (typeof newValue === "function") newValue = newValue(value);
5541
+ value = newValue;
5542
+ subscribers.forEach(fn => fn(value));
5543
+ },
5544
+ getSubscribers: () => new Set(subscribers),
5545
+ };
5546
+
5547
+ // Subscribe to source states
5548
+ sources.forEach(source => {
5549
+ const srcValue = source(); // getValue()
5550
+ srcValue._subscribe(() => {
5551
+ if (!paused) {
5552
+ const newVal = deriveFn(...sources.map(s => s().value));
5553
+ if (newVal !== value) {
5554
+ value = newVal;
5555
+ subscribers.forEach(fn => fn(value));
5556
+ }
5557
+ }
5558
+ }, { element: document.body }); // dummy UIElement
5559
+ });
5560
+
5561
+ return [getValue, setValue, controller];
5562
+ }
5563
+
5564
+ const useReactive = (nested_value) => mapfun$1(n => useState(n), nested_value);
5565
+
6006
5566
  class ZikoUseChannel{
6007
5567
  constructor(name = ""){
6008
5568
  this.channel = new BroadcastChannel(name);
@@ -6242,27 +5802,69 @@
6242
5802
  }
6243
5803
 
6244
5804
  exports.App = App;
5805
+ exports.Arc = Arc;
5806
+ exports.Back = Back;
6245
5807
  exports.Base = Base;
6246
5808
  exports.Canvas = Canvas;
5809
+ exports.Clock = Clock;
6247
5810
  exports.Combinaison = Combinaison;
6248
5811
  exports.Complex = Complex;
5812
+ exports.Discret = Discret;
6249
5813
  exports.E = E;
6250
5814
  exports.EPSILON = EPSILON;
6251
- exports.Ease = Ease;
5815
+ exports.Elastic = Elastic;
6252
5816
  exports.FileBasedRouting = FileBasedRouting;
6253
5817
  exports.Flex = Flex;
6254
5818
  exports.Grid = Grid$1;
6255
5819
  exports.HTMLWrapper = HTMLWrapper;
5820
+ exports.InBack = InBack;
5821
+ exports.InBounce = InBounce;
5822
+ exports.InCirc = InCirc;
5823
+ exports.InCubic = InCubic;
5824
+ exports.InElastic = InElastic;
5825
+ exports.InExpo = InExpo;
5826
+ exports.InOutBack = InOutBack;
5827
+ exports.InOutBounce = InOutBounce;
5828
+ exports.InOutCirc = InOutCirc;
5829
+ exports.InOutCubic = InOutCubic;
5830
+ exports.InOutElastic = InOutElastic;
5831
+ exports.InOutExpo = InOutExpo;
5832
+ exports.InOutQuad = InOutQuad;
5833
+ exports.InOutQuart = InOutQuart;
5834
+ exports.InOutQuint = InOutQuint;
5835
+ exports.InOutSin = InOutSin;
5836
+ exports.InQuad = InQuad;
5837
+ exports.InQuart = InQuart;
5838
+ exports.InQuint = InQuint;
5839
+ exports.InSin = InSin;
5840
+ exports.Linear = Linear;
6256
5841
  exports.Logic = Logic$1;
6257
5842
  exports.Matrix = Matrix;
6258
- exports.PI = PI$1;
5843
+ exports.OutBack = OutBack;
5844
+ exports.OutBounce = OutBounce;
5845
+ exports.OutCirc = OutCirc;
5846
+ exports.OutCubic = OutCubic;
5847
+ exports.OutElastic = OutElastic;
5848
+ exports.OutExpo = OutExpo;
5849
+ exports.OutQuad = OutQuad;
5850
+ exports.OutQuart = OutQuart;
5851
+ exports.OutQuint = OutQuint;
5852
+ exports.OutSin = OutSin;
5853
+ exports.PI = PI$2;
6259
5854
  exports.Permutation = Permutation;
6260
5855
  exports.Random = Random;
6261
5856
  exports.SPA = SPA;
6262
5857
  exports.SVGWrapper = SVGWrapper;
6263
- exports.Str = Str;
5858
+ exports.Scheduler = Scheduler;
5859
+ exports.Step = Step;
6264
5860
  exports.Suspense = Suspense;
6265
5861
  exports.Svg = Svg;
5862
+ exports.Tick = Tick;
5863
+ exports.TimeAnimation = TimeAnimation;
5864
+ exports.TimeLoop = TimeLoop;
5865
+ exports.TimeScheduler = TimeScheduler;
5866
+ exports.UIElement = UIElement;
5867
+ exports.UINode = UINode;
6266
5868
  exports.Utils = Utils;
6267
5869
  exports.ZikoApp = ZikoApp;
6268
5870
  exports.ZikoCustomEvent = ZikoCustomEvent;
@@ -6282,25 +5884,23 @@
6282
5884
  exports.ZikoMutationObserver = ZikoMutationObserver;
6283
5885
  exports.ZikoSPA = ZikoSPA;
6284
5886
  exports.ZikoUICanvas = ZikoUICanvas;
6285
- exports.ZikoUIElement = ZikoUIElement;
6286
5887
  exports.ZikoUIFlex = ZikoUIFlex;
6287
5888
  exports.ZikoUIGrid = ZikoUIGrid;
6288
5889
  exports.ZikoUIHTMLWrapper = ZikoUIHTMLWrapper;
6289
- exports.ZikoUINode = ZikoUINode;
6290
5890
  exports.ZikoUISVGWrapper = ZikoUISVGWrapper;
6291
5891
  exports.ZikoUISuspense = ZikoUISuspense;
6292
5892
  exports.ZikoUISvg = ZikoUISvg;
6293
5893
  exports.ZikoUIText = ZikoUIText;
6294
5894
  exports.ZikoUIXMLWrapper = ZikoUIXMLWrapper;
6295
5895
  exports.ZikoUseRoot = ZikoUseRoot;
6296
- exports.ZikoUseStyle = ZikoUseStyle;
6297
5896
  exports.__ZikoEvent__ = __ZikoEvent__;
6298
5897
  exports.abs = abs;
6299
5898
  exports.accum = accum;
6300
- exports.acos = acos;
5899
+ exports.acos = acos$1;
6301
5900
  exports.acosh = acosh;
6302
5901
  exports.acot = acot;
6303
5902
  exports.add = add;
5903
+ exports.animation = animation;
6304
5904
  exports.arange = arange;
6305
5905
  exports.arr2str = arr2str;
6306
5906
  exports.asin = asin;
@@ -6322,14 +5922,13 @@
6322
5922
  exports.cartesianProduct = cartesianProduct;
6323
5923
  exports.ceil = ceil;
6324
5924
  exports.clamp = clamp;
5925
+ exports.clock = clock;
6325
5926
  exports.combinaison = combinaison;
6326
5927
  exports.complex = complex;
6327
- exports.cos = cos;
5928
+ exports.cos = cos$1;
6328
5929
  exports.cosh = cosh;
6329
5930
  exports.cot = cot;
6330
5931
  exports.coth = coth;
6331
- exports.count = count;
6332
- exports.countWords = countWords;
6333
5932
  exports.csc = csc;
6334
5933
  exports.csv2arr = csv2arr;
6335
5934
  exports.csv2json = csv2json;
@@ -6348,6 +5947,7 @@
6348
5947
  exports.hypot = hypot;
6349
5948
  exports.inRange = inRange;
6350
5949
  exports.isApproximatlyEqual = isApproximatlyEqual;
5950
+ exports.isStateGetter = isStateGetter;
6351
5951
  exports.json2arr = json2arr;
6352
5952
  exports.json2css = json2css;
6353
5953
  exports.json2csv = json2csv;
@@ -6360,6 +5960,7 @@
6360
5960
  exports.linspace = linspace;
6361
5961
  exports.ln = ln;
6362
5962
  exports.logspace = logspace;
5963
+ exports.loop = loop;
6363
5964
  exports.map = map;
6364
5965
  exports.mapfun = mapfun$1;
6365
5966
  exports.matrix = matrix;
@@ -6375,23 +5976,23 @@
6375
5976
  exports.obj2str = obj2str;
6376
5977
  exports.ones = ones;
6377
5978
  exports.pgcd = pgcd;
6378
- exports.pow = pow;
5979
+ exports.pow = pow$1;
6379
5980
  exports.powerSet = powerSet;
6380
5981
  exports.ppcm = ppcm;
6381
5982
  exports.preload = preload;
6382
5983
  exports.prod = prod;
6383
5984
  exports.rad2deg = rad2deg;
6384
- exports.removeExtraSpace = removeExtraSpace;
6385
5985
  exports.round = round;
6386
5986
  exports.sec = sec;
6387
5987
  exports.sig = sig;
6388
5988
  exports.sign = sign;
6389
- exports.sin = sin;
5989
+ exports.sin = sin$1;
6390
5990
  exports.sinc = sinc;
6391
5991
  exports.sinh = sinh;
6392
- exports.sqrt = sqrt;
5992
+ exports.sleep = sleep;
5993
+ exports.sqrt = sqrt$1;
6393
5994
  exports.sqrtn = sqrtn;
6394
- exports.str = str;
5995
+ exports.step_fps = step_fps;
6395
5996
  exports.sub = sub;
6396
5997
  exports.subSet = subSet;
6397
5998
  exports.sum = sum;
@@ -6404,27 +6005,28 @@
6404
6005
  exports.tanh = tanh;
6405
6006
  exports.text = text;
6406
6007
  exports.throttle = throttle;
6008
+ exports.tick = tick;
6407
6009
  exports.timeTaken = timeTaken;
6408
6010
  exports.time_memory_Taken = time_memory_Taken;
6409
- exports.useAnimation = useAnimation;
6011
+ exports.timeout = timeout;
6410
6012
  exports.useChannel = useChannel;
6411
6013
  exports.useCustomEvent = useCustomEvent;
6014
+ exports.useDerived = useDerived;
6412
6015
  exports.useEventEmitter = useEventEmitter;
6413
6016
  exports.useFavIcon = useFavIcon;
6414
- exports.useFps = useFps;
6415
6017
  exports.useHashEvent = useHashEvent;
6416
6018
  exports.useHead = useHead;
6417
6019
  exports.useInputEvent = useInputEvent;
6418
6020
  exports.useLocaleStorage = useLocaleStorage;
6419
6021
  exports.useMediaQuery = useMediaQuery;
6420
6022
  exports.useMeta = useMeta;
6023
+ exports.useReactive = useReactive;
6421
6024
  exports.useRoot = useRoot;
6422
6025
  exports.useSessionStorage = useSessionStorage;
6423
- exports.useStyle = useStyle;
6026
+ exports.useState = useState;
6424
6027
  exports.useSuccesifKeys = useSuccesifKeys;
6425
6028
  exports.useSwipeEvent = useSwipeEvent;
6426
6029
  exports.useThread = useThread;
6427
- exports.useTimeLoop = useTimeLoop;
6428
6030
  exports.useTitle = useTitle;
6429
6031
  exports.wait = wait;
6430
6032
  exports.waitForUIElm = waitForUIElm;