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.mjs CHANGED
@@ -2,28 +2,28 @@
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
9
9
  */
10
10
 
11
- const { PI: PI$1, E } = Math;
11
+ const { PI: PI$2, E } = Math;
12
12
  const EPSILON=Number.EPSILON;
13
13
 
14
- const {PI, cos: cos$1, sin: sin$1, tan: tan$1, acos: acos$1, asin: asin$1, atan: atan$1, cosh: cosh$1, sinh: sinh$1, tanh: tanh$1, acosh: acosh$1, asinh: asinh$1, atanh: atanh$1, log} = Math;
14
+ const {PI: PI$1, cos: cos$2, sin: sin$2, tan: tan$1, acos: acos$2, asin: asin$1, atan: atan$1, cosh: cosh$1, sinh: sinh$1, tanh: tanh$1, acosh: acosh$1, asinh: asinh$1, atanh: atanh$1, log} = Math;
15
15
  let Fixed={
16
- cos: cos$1,
17
- sin: sin$1,
16
+ cos: cos$2,
17
+ sin: sin$2,
18
18
  tan: tan$1,
19
- sinc: x => sin$1(PI*x)/(PI*x),
20
- sec: x => 1/cos$1(x),
21
- csc: x => 1/sin$1(x),
19
+ sinc: x => sin$2(PI$1*x)/(PI$1*x),
20
+ sec: x => 1/cos$2(x),
21
+ csc: x => 1/sin$2(x),
22
22
  cot: x => 1/tan$1(x),
23
- acos: acos$1,
23
+ acos: acos$2,
24
24
  asin: asin$1,
25
25
  atan: atan$1,
26
- acot: x => PI/2-atan$1(x),
26
+ acot: x => PI$1/2-atan$1(x),
27
27
  cosh: cosh$1,
28
28
  sinh: sinh$1,
29
29
  tanh: tanh$1,
@@ -61,20 +61,20 @@ const mapfun$1=(fun,...X)=>{
61
61
  const [a,b,z,phi]=[x.a,x.b,x.z,x.phi];
62
62
  switch(fun){
63
63
  case Math.log: return complex(ln(z),phi); // Done
64
- case Math.exp: return complex(e(a)*cos(b),e(a)*sin(b)); // Done
64
+ case Math.exp: return complex(e(a)*cos$1(b),e(a)*sin$1(b)); // Done
65
65
  case Math.abs: return z; // Done
66
- case Math.sqrt: return complex(sqrt(z)*cos(phi/2),sqrt(z)*sin(phi/2)); // Done
67
- case Fixed.cos: return complex(cos(a)*cosh(b),-(sin(a)*sinh(b)));
68
- case Fixed.sin: return complex(sin(a)*cosh(b),cos(a)*sinh(b));
66
+ case Math.sqrt: return complex(sqrt$1(z)*cos$1(phi/2),sqrt$1(z)*sin$1(phi/2)); // Done
67
+ case Fixed.cos: return complex(cos$1(a)*cosh(b),-(sin$1(a)*sinh(b)));
68
+ case Fixed.sin: return complex(sin$1(a)*cosh(b),cos$1(a)*sinh(b));
69
69
  case Fixed.tan:{
70
- const DEN = cos(2*a)+cosh(2*b);
71
- return complex(sin(2*a)/DEN,sinh(2*b)/DEN);
70
+ const DEN = cos$1(2*a)+cosh(2*b);
71
+ return complex(sin$1(2*a)/DEN,sinh(2*b)/DEN);
72
72
  }
73
- case Fixed.cosh:return complex(cosh(a)*cos(b),sinh(a)*sin(b));
74
- case Fixed.sinh:return complex(sinh(a)*cos(b),cosh(a)*sin(b));
73
+ case Fixed.cosh:return complex(cosh(a)*cos$1(b),sinh(a)*sin$1(b));
74
+ case Fixed.sinh:return complex(sinh(a)*cos$1(b),cosh(a)*sin$1(b));
75
75
  case Fixed.tanh:{
76
- const DEN=cosh(2*a)+cos(2*b);
77
- return complex(sinh(2*a)/DEN,sin(2*b)/DEN)
76
+ const DEN=cosh(2*a)+cos$1(2*b);
77
+ return complex(sinh(2*a)/DEN,sin$1(2*b)/DEN)
78
78
  }
79
79
  default : return fun(x)
80
80
  }
@@ -315,7 +315,7 @@ const linspace=(a,b,n=abs(b-a)+1,endpoint=true)=>{
315
315
  }
316
316
  };
317
317
  const logspace=(a,b,n=b-a+1,base=E,endpoint=true)=>{
318
- return linspace(a,b,n,endpoint).map(n=>pow(base,n))
318
+ return linspace(a,b,n,endpoint).map(n=>pow$1(base,n))
319
319
  };
320
320
  const geomspace=(a,b,n=abs(b-a)+1,endpoint=true)=>{
321
321
  if(Math.floor(n)!==n)return;
@@ -1043,7 +1043,7 @@ const json2xmlFile=(json,indent)=>{
1043
1043
  }
1044
1044
  };
1045
1045
 
1046
- class ZikoUINode {
1046
+ class UINode {
1047
1047
  constructor(node){
1048
1048
  this.cache = {
1049
1049
  node
@@ -1057,7 +1057,7 @@ class ZikoUINode {
1057
1057
  }
1058
1058
  }
1059
1059
 
1060
- globalThis.node = (node) => new ZikoUINode(node);
1060
+ globalThis.node = (node) => new UINode(node);
1061
1061
 
1062
1062
  function register_to_class(target, ...mixins){
1063
1063
  mixins.forEach(n => _register_to_class_(target, n));
@@ -1100,7 +1100,114 @@ const register = (target, ...mixins) => {
1100
1100
  else register_to_instance(target, ...mixins);
1101
1101
  };
1102
1102
 
1103
- class ZikoUIText extends ZikoUINode {
1103
+ function useState(initialValue) {
1104
+ let value = initialValue;
1105
+ const subscribers = new Set();
1106
+ let paused = false;
1107
+
1108
+ function getValue() {
1109
+ return {
1110
+ value,
1111
+ isStateGetter: () => true,
1112
+ _subscribe: (
1113
+ fn,
1114
+ // UIElement
1115
+ ) => {
1116
+ subscribers.add(fn);
1117
+
1118
+ // const observer = new MutationObserver(() => {
1119
+ // if (!document.body.contains(UIElement.element)) {
1120
+ // subscribers.delete(fn);
1121
+ // observer.disconnect();
1122
+ // }
1123
+ // });
1124
+
1125
+ // observer.observe(document.body, { childList: true, subtree: true });
1126
+ },
1127
+ };
1128
+ }
1129
+
1130
+ function setValue(newValue) {
1131
+ if (paused) return;
1132
+ if (typeof newValue === "function") newValue = newValue(value);
1133
+ if (newValue !== value) {
1134
+ value = newValue;
1135
+ subscribers.forEach(fn => fn(value));
1136
+ }
1137
+ }
1138
+
1139
+ const controller = {
1140
+ pause: () => { paused = true; },
1141
+ resume: () => { paused = false; },
1142
+ clear: () => { subscribers.clear(); },
1143
+ force: (newValue) => { // force update even if paused
1144
+ if (typeof newValue === "function") newValue = newValue(value);
1145
+ value = newValue;
1146
+ subscribers.forEach(fn => fn(value));
1147
+ },
1148
+ getSubscribers: () => new Set(subscribers),
1149
+ };
1150
+
1151
+ return [getValue, setValue, controller];
1152
+ }
1153
+
1154
+ const isStateGetter = (arg) => {
1155
+ return typeof(arg) === 'function' && arg?.()?.isStateGetter?.()
1156
+ };
1157
+
1158
+ const camel2hyphencase = (text = '') => text.replace(/[A-Z]/g, match => '-' + match.toLowerCase());
1159
+
1160
+ const is_camelcase = (text = '') =>{
1161
+ if (text.length === 0) return false;
1162
+ const camelCasePattern = /^[a-z][a-zA-Z0-9]*$/;
1163
+ return camelCasePattern.test(text);
1164
+ };
1165
+
1166
+ // To Do add getter, watchAttr
1167
+ const AttrsMethods = {
1168
+ setAttr(name, value) {
1169
+ if(name instanceof Object){
1170
+ const [names,values]=[Object.keys(name),Object.values(name)];
1171
+ for(let i=0;i<names.length;i++){
1172
+ if(values[i] instanceof Array)value[i] = values[i].join(" ");
1173
+ _set_attrs_.call(this, names[i], values[i]);
1174
+ }
1175
+ }
1176
+ else {
1177
+ if(value instanceof Array) value = value.join(" ");
1178
+ _set_attrs_.call(this, name, value);
1179
+ }
1180
+ return this;
1181
+ },
1182
+ removeAttr(...names) {
1183
+ for(let i=0;i<names.length;i++)this.element?.removeAttribute(names[i]);
1184
+ return this;
1185
+ },
1186
+ getAttr(name){
1187
+ name = is_camelcase(name) ? camel2hyphencase(name) : name;
1188
+ return this.element.attributes[name].value;
1189
+ },
1190
+ setContentEditable(bool = true) {
1191
+ this.setAttr("contenteditable", bool);
1192
+ return this;
1193
+ }
1194
+ };
1195
+
1196
+ function _set_attrs_(name, value){
1197
+ if(this.element?.tagName !== "svg") name = is_camelcase(name) ? camel2hyphencase(name) : name;
1198
+ if(this?.attr[name] && this?.attr[name]===value) return;
1199
+ if(isStateGetter(value)){
1200
+ const getter = value();
1201
+ getter._subscribe(
1202
+ (newValue) => this.element?.setAttribute(name, newValue),
1203
+ this
1204
+ );
1205
+ }
1206
+ else this.element?.setAttribute(name, value);
1207
+ Object.assign(this.cache.attributes, {[name]:value});
1208
+ }
1209
+
1210
+ class ZikoUIText extends UINode {
1104
1211
  constructor(...value) {
1105
1212
  super("span", "text", false, ...value);
1106
1213
  this.element = globalThis?.document?.createTextNode(...value);
@@ -1646,723 +1753,175 @@ const IndexingMethods = {
1646
1753
  },
1647
1754
  };
1648
1755
 
1649
- class ZikoUseStyle {
1650
- constructor(style = {}, use = style.hasOwnProperty("default")? "default" : Object.keys(style)[0], id = 0) {
1651
- this.id = "Ziko-Style-" + id;
1652
- this.keys = new Set();
1653
- this.styles = {
1654
- default: {
1655
- fontSize: "1em",
1656
- color : "green"
1657
- },
1658
- other: {
1659
- fontSize : "2em",
1660
- color : "cyan"
1661
- }
1662
- };
1663
- style && this.add(style);
1664
- use && this.use(use);
1665
- }
1666
-
1667
- get current() {
1668
- return [...this.keys].reduce((key, value) => {
1669
- key[value] = `var(--${value}-${this.id})`;
1670
- return key;
1671
- }, {});
1672
- }
1673
-
1674
- add(name, style = {}) {
1675
- if (name && typeof name === 'object' && !Array.isArray(name)) {
1676
- Object.assign(this.styles, name);
1677
- } else if (typeof name === 'string') {
1678
- Object.assign(this.styles, { [name]: style });
1679
- }
1680
- return this;
1681
- }
1682
-
1683
- #useStyleIndex(index) {
1684
- const keys = Object.keys(this.styles);
1685
- for (let a in this.styles[keys[index]]) {
1686
- if (Object.prototype.hasOwnProperty.call(this.styles[keys[index]], a)) {
1687
- document.documentElement.style.setProperty(`--${a}-${this.id}`, this.styles[keys[index]][a]);
1688
- this.keys.add(a);
1689
- }
1690
- }
1691
- return this;
1692
- }
1693
-
1694
- #useStyleName(name) {
1695
- if (!this.styles[name]) return this;
1696
- for (let a in this.styles[name]) {
1697
- if (Object.prototype.hasOwnProperty.call(this.styles[name], a)) {
1698
- document.documentElement.style.setProperty(`--${a}-${this.id}`, this.styles[name][a]);
1699
- this.keys.add(a);
1700
- }
1701
- }
1702
- return this;
1703
- }
1704
-
1705
- #useStyleObject(style) {
1706
- for (let a in style) {
1707
- if (Object.prototype.hasOwnProperty.call(style, a)) {
1708
- document.documentElement.style.setProperty(`--${a}-${this.id}`, style[a]);
1709
- this.keys.add(a);
1710
- }
1711
- }
1712
- return this;
1713
- }
1714
-
1715
- use(style) {
1716
- if (typeof style === "number") return this.#useStyleIndex(style);
1717
- if (typeof style === "string") return this.#useStyleName(style);
1718
- if (style && typeof style === "object") return this.#useStyleObject(style);
1719
- return this;
1720
- }
1721
- }
1722
-
1723
- const useStyle = (styles, use, id) => new ZikoUseStyle(styles, use, id);
1724
-
1725
- const addSuffixeToNumber=(value,suffixe="px")=>{
1726
- if(typeof value === "number") value+=suffixe;
1727
- if(value instanceof Array)value=value.map(n=>typeof n==="number"?n+=suffixe:n).join(" ");
1728
- return value;
1729
- };
1730
-
1731
- class ZikoUIElementStyle{
1732
- constructor(defaultStyle={}){
1733
- this.target=null;
1734
- this.styles=new Map(
1735
- [["default",defaultStyle]]
1736
- );
1737
- this.cache={
1738
- isHidden:false,
1739
- isFaddedOut:false,
1740
- transformation:{
1741
- Flip:[0,0,0],
1742
- matrix:new Matrix([
1743
- [1,0,0,0],
1744
- [0,1,0,0],
1745
- [0,0,1,0],
1746
- [0,0,0,1]
1747
- ])
1748
- }
1749
- };
1750
- }
1756
+ const StyleMethods = {
1751
1757
  style(styles){
1752
- for(const [key, value] of Object.entries(styles)){
1753
- if(Str.isCamelCase(key)){
1754
- delete styles[key];
1755
- Object.assign(styles,{[Str.camel2hyphencase(key)]:value});
1758
+ for(let key in styles){
1759
+ const value = styles[key];
1760
+ if(isStateGetter(value)){
1761
+ const getter = value();
1762
+ Object.assign(this.element.style, {[key] : getter.value});
1763
+ getter._subscribe(
1764
+ (newValue) => {
1765
+ console.log({newValue});
1766
+ Object.assign(this.element.style, {[key] : newValue});
1767
+ },
1768
+ // this
1769
+ );
1756
1770
  }
1771
+ else Object.assign(this.element.style, {[key] : value});
1757
1772
  }
1758
- if(this?.target?.element?.style)Object.assign(this?.target?.element?.style, styles);
1759
- return this;
1760
- }
1761
- linkTo(target){
1762
- this.target=target;
1763
- return this;
1764
- }
1765
- use(name="default"){
1766
- this.style(this.styles.get(name));
1767
- return this;
1768
- }
1769
- update(name,styles){
1770
- const old=this.styles.get(name);
1771
- old?this.styles.set(name,Object.assign(old,styles)):this.styles.set(name,styles);
1772
- return this;
1773
- }
1774
- add(name,styles){
1775
- this.styles.set(name,styles);
1776
1773
  return this;
1777
- }
1778
- replace(name,styles){
1779
- this.styles.set(name,styles);
1774
+ },
1775
+ size(width, height){
1776
+ return this.style({width, height})
1777
+ },
1778
+ hide(){
1779
+
1780
+ },
1781
+ show(){
1782
+
1783
+ },
1784
+ animate(keyframe, {duration=1000, iterations=1, easing="ease"}={}){
1785
+ this.element?.animate(keyframe,{duration, iterations, easing});
1780
1786
  return this;
1781
1787
  }
1782
- delete(...names){
1783
- names.forEach(n=>this.styles.delete(n));
1784
- return this;
1788
+ };
1789
+
1790
+ function EVENT_CONTROLLER(e,EVENT,setter,push_object){
1791
+ this.event=e;
1792
+ if(this.cache.preventDefault[EVENT])e.preventDefault();
1793
+ console.log({setter});
1794
+ if(setter)setter();
1795
+ if(this.cache.stream.enabled[EVENT]&&push_object)this.cache.stream.history[EVENT].push(push_object);
1796
+ this.cache.callbacks[EVENT].map(n=>n(this));
1797
+ return this;
1798
+ }
1799
+ class ZikoEvent{
1800
+ constructor(target){
1801
+ this.target=null;
1802
+ this.setTarget(target);
1803
+ this.__dispose=this.dispose.bind(this);
1804
+ // this.EventIndex=Garbage.Pointer.data.length;
1805
+ // Garbage.Pointer.data.push({event:this,index:this.EventIndex});
1785
1806
  }
1786
- updateDefaultStyle(){
1787
- const defaultStyle=Object.fromEntries(
1788
- Object.entries(this.target.element.style).filter(n=>isNaN(+n[0]))
1789
- );
1790
- this.update("default",defaultStyle);
1791
- return this;
1807
+ get targetElement(){
1808
+ return this.target.element
1792
1809
  }
1793
- hover(styles){
1794
- //this.updateDefaultStyle()
1795
- if(styles)this.add("hover",styles);
1796
- this.target?.element?.addEventListener("pointerenter",()=>this.use("hover"));
1797
- this.target?.element?.addEventListener("pointerleave",()=>this.use("default"));
1810
+ setTarget(UI){
1811
+ this.target=UI;
1798
1812
  return this;
1799
1813
  }
1800
- // Checkers
1801
- isInline(){
1802
- return getComputedStyle(this.target.element).display.includes("inline");
1814
+ __handle(event,handler,dispose){
1815
+ const EVENT=(event==="drag")?event:`${this.cache.prefixe}${event}`;
1816
+ this.dispose(dispose);
1817
+ this.targetElement?.addEventListener(EVENT,handler);
1818
+ return this;
1803
1819
  }
1804
- isBlock(){
1805
- return !(this.isInline());
1820
+ __onEvent(event,dispose,...callbacks){
1821
+ if(callbacks.length===0){
1822
+ if(this.cache.callbacks.length>1){
1823
+ this.cache.callbacks.map(n=>e=>n.call(this,e));
1824
+ }
1825
+ else {
1826
+ return this;
1827
+ }
1828
+ }
1829
+ else this.cache.callbacks[event]=callbacks.map(n=>e=>n.call(this,e));
1830
+ this.__handle(event,this.__controller[event],dispose);
1831
+ return this;
1806
1832
  }
1807
- // Size
1808
- size(width,height){
1809
- this.style({
1810
- width,
1811
- height
1812
- });
1833
+ preventDefault(config={}){
1834
+ Object.assign(this.cache.preventDefault,config);
1813
1835
  return this;
1814
1836
  }
1815
- width(w){
1816
- if(w instanceof Object){
1817
- if(w instanceof Array)w={min:w[0],max:w[1]};
1818
- if("min" in w || "max" in w){
1819
- let min= w.min ?? w.max;
1820
- let max= w.max ?? w.min;
1821
- min=addSuffixeToNumber(min,"px");
1822
- max=addSuffixeToNumber(max,"px");
1823
- this.style({ minWidth: min, maxWidth: max }, { target, maskVector });
1824
- }
1825
- }
1826
- else {
1827
- w=addSuffixeToNumber(w,"px");
1828
- this.style({width:w});
1829
- }
1830
- return this
1831
- }
1832
- height(h){
1833
- if(h instanceof Object){
1834
- if(h instanceof Array)h={min:h[0],max:h[1]};
1835
- if("min" in h || "max" in h){
1836
- let min= h.min ?? h.max;
1837
- let max= h.max ?? h.min;
1838
- min=addSuffixeToNumber(min,"px");
1839
- max=addSuffixeToNumber(max,"px");
1840
- this.style({ minHeight: min, maxHeight: max }, { target, maskVector });
1841
- }
1842
- }
1843
- else {
1844
- h=addSuffixeToNumber(h,"px");
1845
- this.style({height:h});
1846
- }
1847
- return this
1848
- }
1849
- enableResize(h=false,v=false){
1850
- let resize="none";
1851
- if(h)v?resize="both":resize="horizontal";
1852
- else v?resize="vertical":resize="none";
1853
- this.style({
1854
- resize,
1855
- overflow:"hidden"
1856
- });
1857
- if(this.isInline()){
1858
- console.group("Ziko Issue : Temporarily Incompatible Method");
1859
- console.warn(".enableResize has no effect on inline elements!");
1860
- 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");
1861
- console.groupEnd();
1837
+ pause(config={}){
1838
+ const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,true]));
1839
+ config={...all,...config};
1840
+ for(let key in config){
1841
+ if(config[key]){
1842
+ this.targetElement?.removeEventListener(`${this.cache.prefixe}${key}`,this.__controller[`${this.cache.prefixe}${key}`]);
1843
+ this.cache.paused[`${this.cache.prefixe}${key}`]=true;
1844
+ }
1862
1845
  }
1863
1846
  return this;
1864
- }
1865
- // Apparence
1866
- hide({after, target, maskVector } = {}){
1867
- if(typeof after==="number"){
1868
- const wrapper=()=>this.hide({target,maskVector});
1869
- setTimeout(wrapper, after);
1870
- clearTimeout(wrapper);
1871
- }
1872
- else {
1873
- this.cache.isHidden=true;
1874
- this.style({display:"none"},{target,maskVector});
1847
+ }
1848
+ resume(config={}){
1849
+ const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,true]));
1850
+ config={...all,...config};
1851
+ for(let key in config){
1852
+ if(config[key]){
1853
+ this.targetElement?.addEventListener(`${this.cache.prefixe}${key}`,this.__controller[`${this.cache.prefixe}${key}`]);
1854
+ this.cache.paused[`${this.cache.prefixe}${key}`]=false;
1855
+ }
1875
1856
  }
1876
1857
  return this;
1877
- }
1878
- show({after, target, maskVector } = {}){
1879
- if(typeof after==="number"){
1880
- const wrapper=()=>this.show({target,maskVector});
1881
- setTimeout(wrapper, after);
1882
- clearTimeout(wrapper);
1883
- }
1884
- else {
1885
- this.cache.isHidden=false;
1886
- this.style({display:""},{target,maskVector});
1887
- }
1858
+ }
1859
+ dispose(config={}){
1860
+ this.pause(config);
1888
1861
  return this;
1889
- }
1890
- color(color){
1891
- this.style({color});
1862
+ }
1863
+ stream(config={}){
1864
+ this.cache.stream.t0=Date.now();
1865
+ const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,true]));
1866
+ config={...all,...config};
1867
+ Object.assign(this.cache.stream.enabled,config);
1892
1868
  return this;
1893
- }
1894
- background(background){
1895
- this.style({background});
1869
+ }
1870
+ clear(config={}){
1871
+ const all=Object.fromEntries(Object.keys(this.cache.stream.clear).map(n=>[n,true]));
1872
+ config={...all,...config};
1873
+ for(let key in config){
1874
+ if(config[key]){
1875
+ this.cache.stream.history[key]=[];
1876
+ }
1877
+ }
1896
1878
  return this;
1897
1879
  }
1898
- backgroundColor(backgroundColor){
1899
- this.style({backgroundColor});
1900
- return this;
1901
- }
1902
- opacity(opacity, { target, maskVector } = {}) {
1903
- this.style({ opacity }, { target, maskVector });
1904
- return this;
1905
- }
1906
- // Placement
1907
- position(position){
1908
- this.style({position});
1909
- return this
1910
- }
1911
- display(disp, { target, maskVector } = {}) {
1912
- this.style({ display: disp }, { target, maskVector });
1913
- return this;
1914
- }
1915
- zIndex(z){
1916
- this.style({zIndex:z});
1917
- return this;
1918
- }
1919
- float(float, { target, maskVector } = {}) {
1920
- this.style({ float: float }, { target, maskVector });
1921
- return this;
1922
- }
1923
- // Box Model
1924
- border(border = "1px solid red", { target, maskVector } = {}){
1925
- this.style({border}, { target, maskVector });
1926
- return this;
1927
- }
1928
- borderTop(borderTop = "1px solid red", { target, maskVector } = {}){
1929
- this.style({borderTop}, { target, maskVector });
1930
- return this;
1931
- }
1932
- borderRight(borderRight = "1px solid red", { target, maskVector } = {}){
1933
- this.style({borderRight}, { target, maskVector });
1934
- return this;
1935
- }
1936
- borderBottom(borderBottom = "1px solid red", { target, maskVector } = {}){
1937
- this.style({borderBottom}, { target, maskVector });
1938
- return this;
1939
- }
1940
- borderLeft(borderLeft = "1px solid red", { target, maskVector } = {}){
1941
- this.style({borderLeft}, { target, maskVector });
1942
- return this;
1943
- }
1944
- borderRadius(radius){
1945
- radius=addSuffixeToNumber(radius,"px");
1946
- this.style({ borderRadius: radius }, { target, maskVector });
1947
- return this;
1948
- }
1949
- margin(margin){
1950
- margin=addSuffixeToNumber(margin,"px");
1951
- this.style({ margin }, { target, maskVector });
1952
- return this;
1953
- }
1954
- marginTop(marginTop){
1955
- marginTop=addSuffixeToNumber(marginTop,"px");
1956
- this.style({marginTop});
1957
- return this;
1958
- }
1959
- marginRight(marginRight){
1960
- marginRight=addSuffixeToNumber(marginRight,"px");
1961
- this.style({marginRight});
1962
- return this;
1963
- }
1964
- marginBootom(marginBootom){
1965
- marginBootom=addSuffixeToNumber(marginBootom,"px");
1966
- this.style({marginBootom});
1967
- return this;
1968
- }
1969
- marginLeft(marginLeft){
1970
- marginLeft=addSuffixeToNumber(marginLeft,"px");
1971
- this.style({marginLeft});
1972
- return this;
1973
- }
1974
- padding(padding){
1975
- padding=addSuffixeToNumber(padding,"px");
1976
- this.style({padding});
1977
- return this;
1978
- }
1979
- paddingTop(paddingTop){
1980
- paddingTop=addSuffixeToNumber(paddingTop,"px");
1981
- this.style({paddingTop});
1982
- return this;
1983
- }
1984
- paddingRight(paddingRight){
1985
- paddingRight=addSuffixeToNumber(paddingRight,"px");
1986
- this.style({paddingRight});
1987
- return this;
1988
- }
1989
- paddingBootom(paddingBootom){
1990
- paddingBootom=addSuffixeToNumber(paddingBootom,"px");
1991
- this.style({paddingBootom});
1992
- return this;
1993
- }
1994
- paddingLeft(paddingLeft){
1995
- paddingLeft=addSuffixeToNumber(paddingLeft,"px");
1996
- this.style({paddingLeft});
1997
- return this;
1998
- }
1999
- // Typographie
2000
- font(font){
2001
- this.style({font});
2002
- return this;
2003
- }
2004
- fontFamily(fontFamily=""){
2005
- this.style({fontFamily});
2006
- return this;
2007
- }
2008
- fontSize(fontSize){
2009
- this.style({fontSize});
2010
- return this;
2011
- }
2012
- // Misc
2013
- cursor(type="pointer"){
2014
- this.style({ cursor: type });
2015
- return this;
2016
- }
2017
- overflow(x,y){
2018
- const values=["hidden","auto"];
2019
- this.style({
2020
- overflowX:typeof x==="number"?values[x]:x,
2021
- overflowY:typeof y==="number"?values[y]:y
2022
- },{target,maskVector});
2023
- return this;
2024
- }
2025
- clip(polygon, { target, maskVector } = {}) {
2026
- if (typeof polygon === "string") polygon = "polygon(" + polygon + ")";
2027
- this.style({ clipPath: polygon }, { target, maskVector });
2028
- return this;
2029
- }
2030
- // Transfromations
2031
- fadeOut(transitionTimming = 1) {
2032
- this.style({
2033
- transition:`opacity ${transitionTimming/1000}s`,
2034
- opacity: 0
2035
- });
2036
- this.cache.isFaddedOut=true;
2037
- return this;
2038
- }
2039
- fadeIn(transitionTimming = 1) {
2040
- this.style({
2041
- transition: `opacity ${transitionTimming/1000}s`,
2042
- opacity: 1
2043
- });
2044
- this.cache.isFaddedOut=false;
2045
- return this;
2046
- }
2047
- toggleFade(t_in = 1000,t_out=t_in){
2048
- this.cache.isFaddedOut?this.fadeIn(t_in):this.fadeOut(t_out);
2049
- return this;
2050
- }
2051
- morphBorderRadius(newValue, transitionTimming){
2052
- this.style({
2053
- borderRadius: newValue,
2054
- transition: `borderRadius ${transitionTimming/1000}s`,
2055
- });
2056
- return this;
2057
- }
2058
- #applyTransformMatrix(transitionTimming){
2059
- const transformMatrix = this.cache.transformation.matrix.arr.join(",");
2060
- this.style({
2061
- transform: `matrix3d(${transformMatrix})`,
2062
- "-webkit-transform": `matrix3d(${transformMatrix})`,
2063
- "-moz-transform": `matrix3d(${transformMatrix})`,
2064
- "-ms-transform": `matrix3d(${transformMatrix})`,
2065
- "-o-transform": `matrix3d(${transformMatrix})`
2066
- });
2067
- if (transitionTimming != 0) this.style({ transition: `transform ${transitionTimming/1000}s ease` });
2068
- }
2069
- translate(dx, dy = dx ,dz = 0, transitionTimming = 0) {
2070
- this.cache.transformation.matrix.set(3,0,dx);
2071
- this.cache.transformation.matrix.set(3,1,dy);
2072
- this.cache.transformation.matrix.set(3,2,dz);
2073
- this.#applyTransformMatrix(transitionTimming);
2074
- return this;
2075
- }
2076
- translateX(dx, transitionTimming = 0) {
2077
- this.cache.transformation.matrix.set(3,0,dx);
2078
- this.#applyTransformMatrix(transitionTimming);
2079
- return this;
2080
- }
2081
- translateY(dy, transitionTimming = 0) {
2082
- this.cache.transformation.matrix.set(3,1,dy);
2083
- this.#applyTransformMatrix(transitionTimming);
2084
- return this;
2085
- }
2086
- translateZ(dz, transitionTimming = 0) {
2087
- const d=-1/this.cache.transformation.matrix[2][2];
2088
- this.cache.transformation.matrix.set(3,2,z);
2089
- this.cache.transformation.matrix.set(3,3,1-(dz/d));
2090
- this.#applyTransformMatrix(transitionTimming);
2091
- return this;
2092
- }
2093
- perspective(distance,transitionTimming=0){
2094
- const z=this.cache.transformation.matrix[3][2];
2095
- this.cache.transformation.matrix.set(2,2,-1/d);
2096
- this.cache.transformation.matrix.set(3,3,1-(z/distance));
2097
- this.#applyTransformMatrix(transitionTimming);
2098
- return this;
2099
- }
2100
- scale(sx, sy = sx, transitionTimming = 0) {
2101
- this.cache.transformation.matrix.set(0,0,sx);
2102
- this.cache.transformation.matrix.set(1,1,sy);
2103
- // const transformMatrix = this.cache.transformation.matrix.arr.join(",");
2104
- this.#applyTransformMatrix(transitionTimming);
2105
- return this;
2106
- }
2107
- scaleX(x = 1 , transitionTimming = 0) {
2108
- this.cache.transformation.matrix.set(0,0,x);
2109
- // const transformMatrix = this.cache.transformation.matrix.arr.join(",");
2110
- this.#applyTransformMatrix(transitionTimming);
2111
- return this;
2112
- }
2113
- scaleY(y = 1, transitionTimming = 0) {
2114
- this.cache.transformation.matrix.set(1,1,y);
2115
- this.cache.transformation.matrix.arr.join(",");
2116
- this.#applyTransformMatrix(transitionTimming);
2117
- return this;
2118
- }
2119
- skew(x, y = x, transitionTimming = 0) {
2120
- this.cache.transformation.matrix.set(0,1,x);
2121
- this.cache.transformation.matrix.set(1,0,y);
2122
- this.cache.transformation.matrix.arr.join(",");
2123
- this.#applyTransformMatrix(transitionTimming);
2124
- return this;
2125
- }
2126
- skewX(x = 1 , transitionTimming = 0) {
2127
- this.cache.transformation.matrix.set(0,1,x);
2128
- this.cache.transformation.matrix.arr.join(",");
2129
- this.#applyTransformMatrix(transitionTimming);
2130
- return this;
2131
- }
2132
- skewY(y = 1, transitionTimming = 0) {
2133
- this.cache.transformation.matrix.set(1,0,y);
2134
- this.cache.transformation.matrix.arr.join(",");
2135
- this.#applyTransformMatrix(transitionTimming);
2136
- return this;
2137
- }
2138
- rotateX(rx, transitionTimming = 0) {
2139
- this.cache.transformation.matrix.set(1,1,cos(rx));
2140
- this.cache.transformation.matrix.set(1,2,-sin(rx));
2141
- this.cache.transformation.matrix.set(2,1,sin(rx));
2142
- this.cache.transformation.matrix.set(1,2,cos(rx));
2143
- this.#applyTransformMatrix(transitionTimming);
2144
- return this;
2145
- }
2146
- rotateY(ry, transitionTimming = 0) {
2147
- this.cache.transformation.matrix.set(0,0,cos(ry));
2148
- this.cache.transformation.matrix.set(0,2,sin(ry));
2149
- this.cache.transformation.matrix.set(2,0,-sin(ry));
2150
- this.cache.transformation.matrix.set(2,2,cos(ry));
2151
- this.#applyTransformMatrix(transitionTimming);
2152
- return this;
2153
- }
2154
- rotateZ(rz, transitionTimming = 0) {
2155
- this.cache.transformation.matrix.set(0,0,cos(rz));
2156
- this.cache.transformation.matrix.set(0,1,-sin(rz));
2157
- this.cache.transformation.matrix.set(1,0,sin(rz));
2158
- this.cache.transformation.matrix.set(1,1,cos(rz));
2159
- this.#applyTransformMatrix(transitionTimming);
2160
- return this;
2161
- }
2162
- flipeX(transitionTimming = 1) {
2163
- this.cache.transformation.Flip[0] += 180;
2164
- this.cache.transformation.Flip[0] %= 360;
2165
- this.rotateX(this.cache.transformation.Flip[0], transitionTimming);
2166
- return this;
2167
- }
2168
- flipeY(transitionTimming = 1) {
2169
- this.cache.transformation.Flip[1] += 180 ;
2170
- this.cache.transformation.Flip[1] %= 360;
2171
- this.rotateY(this.cache.transformation.Flip[1], transitionTimming);
2172
- return this;
2173
- }
2174
- flipeZ(transitionTimming = 1) {
2175
- this.cache.transformation.Flip[2] += 180;
2176
- this.cache.transformation.Flip[2] %= 360;
2177
- this.rotateZ(this.cache.transformation.Flip[2], transitionTimming);
2178
- return this;
2179
- }
2180
- slideHeightIn(transitionTimming = 1, h = this.h) {
2181
- this.style({ transition: transitionTimming + "s", height: h });
2182
- return this;
2183
- }
2184
- slideHeightOut(transitionTimming = 1) {
2185
- this.style({ transition: transitionTimming + "s", height: 0 });
2186
- this.target?.element?.n("transitionend", () =>
2187
- this.style({ opacity: "none" }),
2188
- );
2189
- return this;
2190
- }
2191
- slideWidthIn(transitionTimming = 1, w = this.w) {
2192
- this.style({ transition: transitionTimming + "s", width: w });
2193
- return this;
2194
- }
2195
- slideWidthOut(transitionTimming = 1) {
2196
- this.style({ transition: transitionTimming + "s", width: 0 });
2197
- const wrapper=()=>{
2198
- this.style({ opacity: "none" });
2199
- };
2200
- this.target?.element?.addEventListener("transitionend",wrapper);
2201
- this.target?.element?.removeEventListener("transitionend",wrapper);
2202
- return this;
2203
- }
2204
- slideIn({ transitionTimming = 1, w = "100%", h = "auto" } = {}) {
2205
- this.style({
2206
- transition: transitionTimming + "s",
2207
- width: w,
2208
- height: h,
2209
- visibility: "visible",
2210
- });
2211
- return this;
2212
- }
2213
- slideOut({ transitionTimming = 1, width = 0, heightransitionTimming = 0 } = {}) {
2214
- this.style({
2215
- visibility: "hidden",
2216
- transition: transitionTimming + "s",
2217
- opacity: "none",
2218
- width: width,
2219
- height: height,
2220
- });
2221
- const wrapper=()=>{
2222
- this.style({ opacity: "none" });
2223
- };
2224
- this.target?.element?.addEventListener("transitionend",wrapper);
2225
- this.target?.element?.removeEventListener("transitionend",wrapper);
2226
- return this;
2227
- }
2228
-
2229
- }
2230
-
2231
- function EVENT_CONTROLLER(e,EVENT,setter,push_object){
2232
- this.event=e;
2233
- if(this.cache.preventDefault[EVENT])e.preventDefault();
2234
- console.log({setter});
2235
- if(setter)setter();
2236
- if(this.cache.stream.enabled[EVENT]&&push_object)this.cache.stream.history[EVENT].push(push_object);
2237
- this.cache.callbacks[EVENT].map(n=>n(this));
2238
- return this;
2239
- }
2240
- class ZikoEvent{
2241
- constructor(target){
2242
- this.target=null;
2243
- this.setTarget(target);
2244
- this.__dispose=this.dispose.bind(this);
2245
- // this.EventIndex=Garbage.Pointer.data.length;
2246
- // Garbage.Pointer.data.push({event:this,index:this.EventIndex});
2247
- }
2248
- get targetElement(){
2249
- return this.target.element
2250
- }
2251
- setTarget(UI){
2252
- this.target=UI;
2253
- return this;
2254
- }
2255
- __handle(event,handler,dispose){
2256
- const EVENT=(event==="drag")?event:`${this.cache.prefixe}${event}`;
2257
- this.dispose(dispose);
2258
- this.targetElement?.addEventListener(EVENT,handler);
2259
- return this;
2260
- }
2261
- __onEvent(event,dispose,...callbacks){
2262
- if(callbacks.length===0){
2263
- if(this.cache.callbacks.length>1){
2264
- this.cache.callbacks.map(n=>e=>n.call(this,e));
2265
- }
2266
- else {
2267
- return this;
2268
- }
2269
- }
2270
- else this.cache.callbacks[event]=callbacks.map(n=>e=>n.call(this,e));
2271
- this.__handle(event,this.__controller[event],dispose);
2272
- return this;
2273
- }
2274
- preventDefault(config={}){
2275
- Object.assign(this.cache.preventDefault,config);
2276
- return this;
2277
- }
2278
- pause(config={}){
2279
- const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,true]));
2280
- config={...all,...config};
2281
- for(let key in config){
2282
- if(config[key]){
2283
- this.targetElement?.removeEventListener(`${this.cache.prefixe}${key}`,this.__controller[`${this.cache.prefixe}${key}`]);
2284
- this.cache.paused[`${this.cache.prefixe}${key}`]=true;
2285
- }
2286
- }
2287
- return this;
2288
- }
2289
- resume(config={}){
2290
- const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,true]));
2291
- config={...all,...config};
2292
- for(let key in config){
2293
- if(config[key]){
2294
- this.targetElement?.addEventListener(`${this.cache.prefixe}${key}`,this.__controller[`${this.cache.prefixe}${key}`]);
2295
- this.cache.paused[`${this.cache.prefixe}${key}`]=false;
2296
- }
2297
- }
2298
- return this;
2299
- }
2300
- dispose(config={}){
2301
- this.pause(config);
2302
- return this;
2303
- }
2304
- stream(config={}){
2305
- this.cache.stream.t0=Date.now();
2306
- const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,true]));
2307
- config={...all,...config};
2308
- Object.assign(this.cache.stream.enabled,config);
2309
- return this;
2310
- }
2311
- clear(config={}){
2312
- const all=Object.fromEntries(Object.keys(this.cache.stream.clear).map(n=>[n,true]));
2313
- config={...all,...config};
2314
- for(let key in config){
2315
- if(config[key]){
2316
- this.cache.stream.history[key]=[];
2317
- }
2318
- }
2319
- return this;
2320
- }
2321
- }
2322
-
2323
- function input_controller(e){
2324
- EVENT_CONTROLLER.call(this,e,"input",null,null);
2325
- }
2326
- function change_controller(e){
2327
- EVENT_CONTROLLER.call(this,e,"change",null,null);
2328
- }
2329
- class ZikoEventInput extends ZikoEvent{
2330
- constructor(target){
2331
- super(target);
2332
- this.event=null;
2333
- this.cache={
2334
- prefixe:"",
2335
- preventDefault:{
2336
- input:false,
2337
- change:false,
2338
- },
2339
- paused:{
2340
- input:false,
2341
- change:false,
2342
- },
2343
- stream:{
2344
- enabled:{
2345
- input:false,
2346
- change:false,
2347
- },
2348
- clear:{
2349
- input:false,
2350
- change:false,
2351
- },
2352
- history:{
2353
- input:[],
2354
- change:[],
2355
- }
2356
- },
2357
- callbacks:{
2358
- input:[],
2359
- change:[],
2360
- }
2361
- };
2362
- this.__controller={
2363
- input:input_controller.bind(this),
2364
- change:change_controller.bind(this),
2365
- };
1880
+ }
1881
+
1882
+ function input_controller(e){
1883
+ EVENT_CONTROLLER.call(this,e,"input",null,null);
1884
+ }
1885
+ function change_controller(e){
1886
+ EVENT_CONTROLLER.call(this,e,"change",null,null);
1887
+ }
1888
+ class ZikoEventInput extends ZikoEvent{
1889
+ constructor(target){
1890
+ super(target);
1891
+ this.event=null;
1892
+ this.cache={
1893
+ prefixe:"",
1894
+ preventDefault:{
1895
+ input:false,
1896
+ change:false,
1897
+ },
1898
+ paused:{
1899
+ input:false,
1900
+ change:false,
1901
+ },
1902
+ stream:{
1903
+ enabled:{
1904
+ input:false,
1905
+ change:false,
1906
+ },
1907
+ clear:{
1908
+ input:false,
1909
+ change:false,
1910
+ },
1911
+ history:{
1912
+ input:[],
1913
+ change:[],
1914
+ }
1915
+ },
1916
+ callbacks:{
1917
+ input:[],
1918
+ change:[],
1919
+ }
1920
+ };
1921
+ this.__controller={
1922
+ input:input_controller.bind(this),
1923
+ change:change_controller.bind(this),
1924
+ };
2366
1925
  }
2367
1926
  get value(){
2368
1927
  return this.target.value;
@@ -3267,8 +2826,8 @@ function __init__global__(){
3267
2826
  }
3268
2827
 
3269
2828
  __init__global__();
3270
- class ZikoUIElement extends ZikoUINode{
3271
- constructor(element, name="", {type="html", useDefaultStyle=false}={}){
2829
+ class UIElement extends UINode{
2830
+ constructor({element, name ='', type="html", useDefaultStyle=false}={}){
3272
2831
  super();
3273
2832
  this.target = globalThis.__Ziko__.__Config__.default.target||globalThis?.document?.body;
3274
2833
  if(typeof element === "string") {
@@ -3279,9 +2838,16 @@ class ZikoUIElement extends ZikoUINode{
3279
2838
  }
3280
2839
  }
3281
2840
  else {
3282
- this.target = element.parentElement;
3283
- }
3284
- register(this, DomMethods, IndexingMethods, EventsMethodes);
2841
+ this.target = element?.parentElement;
2842
+ }
2843
+ register(
2844
+ this,
2845
+ AttrsMethods,
2846
+ DomMethods,
2847
+ StyleMethods,
2848
+ IndexingMethods,
2849
+ EventsMethodes
2850
+ );
3285
2851
  Object.assign(this.cache, {
3286
2852
  name,
3287
2853
  isInteractive : [true, false][Math.floor(2*Math.random())],
@@ -3291,7 +2857,6 @@ class ZikoUIElement extends ZikoUINode{
3291
2857
  isHidden: false,
3292
2858
  isFrozzen:false,
3293
2859
  legacyParent : null,
3294
- style: new ZikoUIElementStyle({}),
3295
2860
  attributes: {},
3296
2861
  filters: {},
3297
2862
  temp:{}
@@ -3316,7 +2881,6 @@ class ZikoUIElement extends ZikoUINode{
3316
2881
  if(element)Object.assign(this.cache,{element});
3317
2882
  this.uuid = `${this.cache.name}-${Random.string(16)}`;
3318
2883
  this.ui_index = globalThis.__Ziko__.__CACHE__.get_ui_index();
3319
- this.cache.style.linkTo(this);
3320
2884
  useDefaultStyle && this.style({
3321
2885
  position: "relative",
3322
2886
  boxSizing:"border-box",
@@ -3398,25 +2962,17 @@ class ZikoUIElement extends ZikoUINode{
3398
2962
  else UI.element=this.element.cloneNode(true);
3399
2963
  return UI.render(render);
3400
2964
  }
3401
- style(styles){
3402
- styles instanceof ZikoUseStyle ? this.st.style(styles.current): this.st.style(styles);
3403
- return this;
3404
- }
3405
- size(width,height){
3406
- this.st.size(width,height);
3407
- return this;
3408
- }
3409
2965
  [Symbol.iterator]() {
3410
2966
  return this.items[Symbol.iterator]();
3411
2967
  }
3412
2968
  maintain() {
3413
- for (let i = 0; i < this.items.length; i++) {
3414
- Object.defineProperty(this, i, {
3415
- value: this.items[i],
3416
- writable: true,
3417
- configurable: true,
3418
- enumerable: false
3419
- });
2969
+ for (let i = 0; i < this.items.length; i++) {
2970
+ Object.defineProperty(this, i, {
2971
+ value: this.items[i],
2972
+ writable: true,
2973
+ configurable: true,
2974
+ enumerable: false
2975
+ });
3420
2976
  }
3421
2977
  }
3422
2978
  freeze(freeze){
@@ -3434,43 +2990,6 @@ class ZikoUIElement extends ZikoUINode{
3434
2990
  describe(label){
3435
2991
  if(label)this.setAttr("aria-label",label);
3436
2992
  }
3437
- animate(keyframe, {duration=1000, iterations=1, easing="ease"}={}){
3438
- this.element?.animate(keyframe,{duration, iterations, easing});
3439
- return this;
3440
- }
3441
- // Attributes
3442
- #setAttr(name, value){
3443
- if(this.element?.tagName !== "svg") name = Str.isCamelCase(name) ? Str.camel2hyphencase(name) : name;
3444
- if(this?.attr[name] && this?.attr[name]===value) return;
3445
- this.element?.setAttribute(name, value);
3446
- Object.assign(this.cache.attributes, {[name]:value});
3447
- }
3448
- setAttr(name, value) {
3449
- if(name instanceof Object){
3450
- const [names,values]=[Object.keys(name),Object.values(name)];
3451
- for(let i=0;i<names.length;i++){
3452
- if(values[i] instanceof Array)value[i] = values[i].join(" ");
3453
- this.#setAttr(names[i], values[i]);
3454
- }
3455
- }
3456
- else {
3457
- if(value instanceof Array)value = value.join(" ");
3458
- this.#setAttr(name, value);
3459
- }
3460
- return this;
3461
- }
3462
- removeAttr(...names) {
3463
- for(let i=0;i<names.length;i++)this.element?.removeAttribute(names[i]);
3464
- return this;
3465
- }
3466
- getAttr(name){
3467
- name = Str.isCamelCase(name) ? Str.camel2hyphencase(name) : name;
3468
- return this.element.attributes[name].value;
3469
- }
3470
- setContentEditable(bool = true) {
3471
- this.setAttr("contenteditable", bool);
3472
- return this;
3473
- }
3474
2993
  get children() {
3475
2994
  return [...this.element.children];
3476
2995
  }
@@ -3665,10 +3184,6 @@ const SVGTags = [
3665
3184
  "desc", "title", "metadata", "foreignObject"
3666
3185
  ];
3667
3186
 
3668
- const isStateGetter = (arg) => {
3669
- return typeof(arg) === 'function' && arg?.()?.isStateGetter?.()
3670
- };
3671
-
3672
3187
  const tags = new Proxy({}, {
3673
3188
  get(target, prop) {
3674
3189
  if (typeof prop !== 'string') return undefined;
@@ -3676,27 +3191,23 @@ const tags = new Proxy({}, {
3676
3191
  let type ;
3677
3192
  if(HTMLTags.includes(tag)) type = 'html';
3678
3193
  if(SVGTags.includes(tag)) type = 'svg';
3679
- if(HTMLTags.includes(tag)) return (...args)=>{
3194
+ return (...args)=>{
3680
3195
  console.log(isStateGetter(args[0]));
3681
- // if(typeof args[0] === 'function') {
3682
- // console.log(args[0], args[0]?.() instanceof StateGetter)
3683
- // globalThis.a = args[0]
3684
- // console.log({t : a.constructor})
3685
- // }
3686
3196
  if(
3687
3197
  ['string', 'number'].includes(typeof args[0])
3688
- || args[0] instanceof ZikoUIElement
3198
+ || args[0] instanceof UIElement
3689
3199
  || (typeof args[0] === 'function' && args[0]().isStateGetter())
3690
- ) return new ZikoUIElement(tag, tag, {type}).append(...args);
3691
- return new ZikoUIElement(tag).setAttr(args.shift()).append(...args)
3200
+ ) return new UIElement({element : tag, name : tag, type}).append(...args);
3201
+ // console.log(args[0])
3202
+ return new UIElement({element : tag}).setAttr(args.shift()).append(...args)
3692
3203
  }
3693
- // if(SVGTags.includes(tag)) return (...args) => new ZikoUIElement(tag,"",{el_type : "svg"}).append(...args);
3204
+ // if(SVGTags.includes(tag)) return (...args) => new UIElement(tag,"",{el_type : "svg"}).append(...args);
3694
3205
  // return (...args)=>{
3695
- // if(!(args[0] instanceof ZikoUIElement) && args[0] instanceof Object){
3206
+ // if(!(args[0] instanceof UIElement) && args[0] instanceof Object){
3696
3207
  // let attributes = args.shift()
3697
- // return new ZikoUIElement(tag).setAttr(attributes).append(...args)
3208
+ // return new UIElement(tag).setAttr(attributes).append(...args)
3698
3209
  // }
3699
- // return new ZikoUIElement(tag).append(...args);
3210
+ // return new UIElement(tag).append(...args);
3700
3211
  // }
3701
3212
  // // switch(tag){
3702
3213
  // case "html" : globalThis?.document?.createElement("html")
@@ -3706,14 +3217,14 @@ const tags = new Proxy({}, {
3706
3217
  // case "meta" :
3707
3218
  // case "srcipt":
3708
3219
  // case "body" : return null; break;
3709
- // default : return new ZikoUIElement(tag);
3220
+ // default : return new UIElement(tag);
3710
3221
  // }
3711
3222
  }
3712
3223
  });
3713
3224
 
3714
- class ZikoUIFlex extends ZikoUIElement {
3225
+ class ZikoUIFlex extends UIElement {
3715
3226
  constructor(tag = "div", w = "100%", h = "100%") {
3716
- super(tag ,"Flex");
3227
+ super({element : tag , name : "Flex"});
3717
3228
  this.direction = "cols";
3718
3229
  if (typeof w == "number") w += "%";
3719
3230
  if (typeof h == "number") h += "%";
@@ -3781,13 +3292,13 @@ class ZikoUIFlex extends ZikoUIElement {
3781
3292
  }
3782
3293
  }
3783
3294
 
3784
- const Flex = (...ZikoUIElement) =>{
3295
+ const Flex = (...UIElement) =>{
3785
3296
  let tag="div";
3786
- if(typeof ZikoUIElement[0]==="string"){
3787
- tag=ZikoUIElement[0];
3788
- ZikoUIElement.pop();
3297
+ if(typeof UIElement[0]==="string"){
3298
+ tag=UIElement[0];
3299
+ UIElement.pop();
3789
3300
  }
3790
- return new ZikoUIFlex(tag).append(...ZikoUIElement);
3301
+ return new ZikoUIFlex(tag).append(...UIElement);
3791
3302
  };
3792
3303
  function set_vertical(direction){
3793
3304
  direction == 1
@@ -3810,9 +3321,9 @@ function map_pos_y(align){
3810
3321
  return map_pos_x(-align);
3811
3322
  }
3812
3323
 
3813
- class ZikoUIGrid extends ZikoUIElement {
3324
+ class ZikoUIGrid extends UIElement {
3814
3325
  constructor(tag ="div", w = "50vw", h = "50vh") {
3815
- super(tag,"Grid");
3326
+ super({element : tag, name : "Grid"});
3816
3327
  this.direction = "cols";
3817
3328
  if (typeof w == "number") w += "%";
3818
3329
  if (typeof h == "number") h += "%";
@@ -3840,11 +3351,11 @@ class ZikoUIGrid extends ZikoUIElement {
3840
3351
  return this;
3841
3352
  }
3842
3353
  }
3843
- const Grid$1 = (...ZikoUIElement) => new ZikoUIGrid("div").append(...ZikoUIElement);
3354
+ const Grid$1 = (...UIElement) => new ZikoUIGrid("div").append(...UIElement);
3844
3355
 
3845
- class ZikoUISuspense extends ZikoUIElement{
3356
+ class ZikoUISuspense extends UIElement{
3846
3357
  constructor(fallback_ui, callback){
3847
- super("div", "suspense");
3358
+ super({element : "div", name : "suspense"});
3848
3359
  this.setAttr({
3849
3360
  dataTemp : "suspense"
3850
3361
  });
@@ -3866,9 +3377,9 @@ class ZikoUISuspense extends ZikoUIElement{
3866
3377
 
3867
3378
  const Suspense = (fallback_ui, callback) => new ZikoUISuspense(fallback_ui, callback);
3868
3379
 
3869
- class ZikoUIXMLWrapper extends ZikoUIElement{
3380
+ class ZikoUIXMLWrapper extends UIElement{
3870
3381
  constructor(XMLContent, type){
3871
- super("div", "");
3382
+ super({element : "div", name : ""});
3872
3383
  this.element.append(type==="svg"?svg2dom(XMLContent):html2dom(XMLContent));
3873
3384
  }
3874
3385
  }
@@ -3900,7 +3411,7 @@ class ZikoUISVGWrapper extends ZikoUIXMLWrapper{
3900
3411
  const HTMLWrapper = (HTMLContent) => new ZikoUIHTMLWrapper(HTMLContent);
3901
3412
  const SVGWrapper = (SVGContent) => new ZikoUISVGWrapper(SVGContent);
3902
3413
 
3903
- class ZikoUICanvas extends ZikoUIElement{
3414
+ class ZikoUICanvas extends UIElement{
3904
3415
  constructor(w,h){
3905
3416
  super("canvas","canvas");
3906
3417
  this.ctx = this.element?.getContext("2d");
@@ -4070,7 +3581,7 @@ class ZikoUICanvas extends ZikoUIElement{
4070
3581
 
4071
3582
  const Canvas=(w,h)=>new ZikoUICanvas(w,h);
4072
3583
 
4073
- class ZikoUISvg extends ZikoUIElement {
3584
+ class ZikoUISvg extends UIElement {
4074
3585
  constructor(w=360,h=300) {
4075
3586
  super("svg","svg");
4076
3587
  //this.cache={};
@@ -4279,175 +3790,6 @@ function trimKeys(obj) {
4279
3790
  }, Array.isArray(obj) ? [] : {});
4280
3791
  }
4281
3792
 
4282
- const Patterns={
4283
- isDigit: /^\d+$/,
4284
- isURL: /^(https?:\/\/)?([\w\-]+\.)+[\w\-]+(\/[\w\-./?%&=]*)?$/,
4285
- isHexColor: /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/,
4286
- 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]?)$/,
4287
- isMACAddress: /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/,
4288
- isDate: /^\d{4}-\d{2}-\d{2}$/,
4289
- };
4290
-
4291
- class Str{
4292
- constructor(string){
4293
- this.string=string;
4294
- }
4295
- isDigit() {
4296
- return Patterns.isDigit.test(this.string);
4297
- }
4298
- static isDigit(string){
4299
- return new Str(string).isDigit();
4300
- }
4301
- isNumber() {
4302
- return !isNaN(this.string);
4303
- }
4304
- static isNumber(string){
4305
- return new Str(string).isNumber();
4306
- }
4307
- isUrl(){
4308
- return Patterns.isURL.test(this.string);
4309
- }
4310
- static isUrl(string){
4311
- return new Str(string).isUrl();
4312
- }
4313
- isHexColor(){
4314
- return Patterns.isHexColor.test(this.string);
4315
- }
4316
- static isHexColor(string){
4317
- return new Str(string).isHexColor();
4318
- }
4319
- isIPv4(){
4320
- return Patterns.isIPv4.test(this.string);
4321
- }
4322
- static isIPv4(string){
4323
- return new Str(string).isIPv4();
4324
- }
4325
- isDate(){
4326
- return Patterns.isDate.test(this.string);
4327
- }
4328
- static isDate(string){
4329
- return new Str(string).isDate();
4330
- }
4331
- isMACAddress(){
4332
- return Patterns.isMACAddress.test(this.string);
4333
- }
4334
- static isMACAddress(string){
4335
- return new Str(string).isMACAddress();
4336
- }
4337
- isPascalCase(){
4338
- if (this.string.length === 0) return false;
4339
- const PascalCasePattern = /^[A-Z][a-zA-Z0-9]*$/;
4340
- return PascalCasePattern.test(this.string);
4341
- }
4342
- static isPascalCase(string){
4343
- return new Str(string).isPascalCase();
4344
- }
4345
- isCamelCase() {
4346
- if (this.string.length === 0) return false;
4347
- const camelCasePattern = /^[a-z][a-zA-Z0-9]*$/;
4348
- return camelCasePattern.test(this.string);
4349
- }
4350
- static isCamelCase(string){
4351
- return new Str(string).isCamelCase();
4352
- }
4353
- isHyphenCase(){
4354
- return this.string.split('-').length > 1;
4355
- }
4356
- static isHyphenCase(string){
4357
- return new Str(string).isHyphenCase();
4358
- }
4359
- isSnakeCase(){
4360
- return this.string.split('_').length > 1;
4361
- }
4362
- static isSnakeCase(string){
4363
- return new Str(string).isSnakeCase();
4364
- }
4365
- isPalindrome(){
4366
- const str=this.string.toLocaleLowerCase();
4367
- let l=str.length,i;
4368
- for(i=0;i<l/2;i++)if(str[i]!=str[l-i-1])return false;
4369
- return true;
4370
- }
4371
- static isPalindrome(string){
4372
- return new Str(string).isPalindrome();
4373
- }
4374
- static isAnagrams(word,words){
4375
- word=word.split("").sort();
4376
- words=words.split("").sort();
4377
- return JSON.stringify(word)===JSON.stringify(words);
4378
- }
4379
- isIsogram(){
4380
- return [...new Set(this.string.toLowerCase())].length===this.string.length;
4381
- }
4382
- static isIsogram(string){
4383
- return new Str(string).isIsogram();
4384
- }
4385
- static camel2hyphencase(text) {
4386
- return text.replace(/[A-Z]/g, match => '-' + match.toLowerCase());
4387
- }
4388
- static camel2snakecase(text) {
4389
- return text.replace(/[A-Z]/g, match => '_' + match.toLowerCase());
4390
- }
4391
- static camel2pascalcase(text) {
4392
- return text.charAt(0).toUpperCase() + text.slice(1);
4393
- }
4394
- static camel2constantcase(text) {
4395
- return text.replace(/[A-Z]/g, match => '_' + match).toUpperCase();
4396
- }
4397
- static pascal2snakecase(text) {
4398
- return text.replace(/([A-Z])/g, (match, offset) => offset ? '_' + match.toLowerCase() : match.toLowerCase());
4399
- }
4400
- static pascal2hyphencase(text) {
4401
- return text.replace(/([A-Z])/g, (match, offset) => offset ? '-' + match.toLowerCase() : match.toLowerCase());
4402
- }
4403
- static pascal2camelcase(text) {
4404
- return text.charAt(0).toLowerCase() + text.slice(1);
4405
- }
4406
- static pascal2constantcase(text) {
4407
- return text.replace(/([A-Z])/g, (match, offset) => offset ? '_' + match : match).toUpperCase();
4408
- }
4409
- static snake2camelcase(text) {
4410
- return text.replace(/(_\w)/g, match => match[1].toUpperCase());
4411
- }
4412
- static snake2hyphencase(text) {
4413
- return text.replace(/_/g, "-");
4414
- }
4415
- static snake2pascalcase(text) {
4416
- return text.split('_').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join('');
4417
- }
4418
- static snake2constantcase(text) {
4419
- return text.toUpperCase();
4420
- }
4421
- static hyphen2camelcase(text) {
4422
- return text.replace(/-([a-z])/g, match => match[1].toUpperCase());
4423
- }
4424
- static hyphen2snakecase(text) {
4425
- return text.replace(/-/g, '_');
4426
- }
4427
- static hyphen2pascalcase(text) {
4428
- return text.split('-').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join('');
4429
- }
4430
- static hyphen2constantcase(text) {
4431
- return text.replace(/-/g, '_').toUpperCase();
4432
- }
4433
- static constant2camelcase(text) {
4434
- return text.toLowerCase().replace(/_([a-z])/g, match => match[1].toUpperCase());
4435
- }
4436
- static constant2snakecase(text) {
4437
- return text.toLowerCase();
4438
- }
4439
- static constant2pascalcase(text) {
4440
- return text.toLowerCase().split('_').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join('');
4441
- }
4442
- static constant2hyphencase(text) {
4443
- return text.toLowerCase().replace(/_/g, '-');
4444
- }
4445
- }
4446
- const removeExtraSpace=str=>str.replace(/\s+/g,' ');
4447
- const count=(str,value)=>str.split("").filter(x => x==value).length;
4448
- const countWords=(str,value)=>str.split(" ").filter(x => x==value).length;
4449
- const str=string=>new Str(string);
4450
-
4451
3793
  class Matrix extends ZikoMath{
4452
3794
  constructor(rows, cols, element = [] ) {
4453
3795
  super();
@@ -4606,7 +3948,7 @@ class Matrix extends ZikoMath{
4606
3948
  .mul(determinat(deleteRowAndColumn(M, i)))
4607
3949
  );*/
4608
3950
  //const to_be_added=Utils.add(Utils.mul(pow(-1, i),Utils.mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
4609
- const to_be_added=Utils.add(Utils.mul(pow(-1, i),Utils.mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
3951
+ const to_be_added=Utils.add(Utils.mul(pow$1(-1, i),Utils.mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
4610
3952
  answer=Utils.add(answer,to_be_added);
4611
3953
  }
4612
3954
  return answer;
@@ -5129,7 +4471,7 @@ class Complex extends ZikoMath{
5129
4471
  }
5130
4472
  else if(("a" in b && "z" in a)){
5131
4473
  this.a=a.a;
5132
- this.b=sqrt((a.z**2)-(a.a**2));
4474
+ this.b=sqrt$1((a.z**2)-(a.a**2));
5133
4475
  }
5134
4476
  else if(("a" in b && "phi" in a)){
5135
4477
  this.a=a.a;
@@ -5137,15 +4479,15 @@ class Complex extends ZikoMath{
5137
4479
  }
5138
4480
  else if(("b" in b && "z" in a)){
5139
4481
  this.b=a.b;
5140
- this.a=sqrt((a.z**2)-(a.b**2));
4482
+ this.a=sqrt$1((a.z**2)-(a.b**2));
5141
4483
  }
5142
4484
  else if(("b" in b && "phi" in a)){
5143
4485
  this.b=b;
5144
4486
  this.a=a.b/tan(a.phi);
5145
4487
  }
5146
4488
  else if(("z" in b && "phi" in a)){
5147
- this.a=a.z*cos(a.phi);
5148
- this.a=a.z*sin(a.phi);
4489
+ this.a=a.z*cos$1(a.phi);
4490
+ this.a=a.z*sin$1(a.phi);
5149
4491
  }
5150
4492
  }
5151
4493
  else if(typeof(a)==="number"&&typeof(b)==="number"){
@@ -5185,7 +4527,7 @@ class Complex extends ZikoMath{
5185
4527
  return new Complex(this.a, -this.b);
5186
4528
  }
5187
4529
  get inv() {
5188
- return new Complex(this.a / (pow(this.a, 2) + pow(this.b, 2)), -this.b / (pow(this.a, 2) + pow(this.b, 2)));
4530
+ return new Complex(this.a / (pow$1(this.a, 2) + pow$1(this.b, 2)), -this.b / (pow$1(this.a, 2) + pow$1(this.b, 2)));
5189
4531
  }
5190
4532
  add(...z) {
5191
4533
  for (let i = 0; i < z.length; i++) {
@@ -5213,8 +4555,8 @@ class Complex extends ZikoMath{
5213
4555
  }
5214
4556
  let Z=+prod(this.z,...z.map(n=>n.z)).toFixed(15);
5215
4557
  let phi=+sum(this.phi,...z.map(n=>n.phi)).toFixed(15);
5216
- this.a=+(Z*cos(phi).toFixed(15)).toFixed(14);
5217
- this.b=+(Z*sin(phi).toFixed(15)).toFixed(14);
4558
+ this.a=+(Z*cos$1(phi).toFixed(15)).toFixed(14);
4559
+ this.b=+(Z*sin$1(phi).toFixed(15)).toFixed(14);
5218
4560
  return this;
5219
4561
  }
5220
4562
  div(...z) {
@@ -5223,23 +4565,23 @@ class Complex extends ZikoMath{
5223
4565
  }
5224
4566
  let Z=+(this.z/prod(...z.map(n=>n.z))).toFixed(15);
5225
4567
  let phi=+(this.phi-sum(...z.map(n=>n.phi))).toFixed(15);
5226
- this.a=+(Z*cos(phi).toFixed(15)).toFixed(15);
5227
- this.b=+(Z*sin(phi).toFixed(15)).toFixed(15);
4568
+ this.a=+(Z*cos$1(phi).toFixed(15)).toFixed(15);
4569
+ this.b=+(Z*sin$1(phi).toFixed(15)).toFixed(15);
5228
4570
  return this;
5229
4571
  }
5230
4572
  pow(n) {
5231
4573
  if (floor(n) === n && n > 0) {
5232
4574
  let z=+(this.z**n).toFixed(15);
5233
4575
  let phi=+(this.phi*n).toFixed(15);
5234
- this.a=+(z*cos(phi).toFixed(15)).toFixed(15);
5235
- this.b=+(z*sin(phi).toFixed(15)).toFixed(15);
4576
+ this.a=+(z*cos$1(phi).toFixed(15)).toFixed(15);
4577
+ this.b=+(z*sin$1(phi).toFixed(15)).toFixed(15);
5236
4578
  }
5237
4579
  return this;
5238
4580
  }
5239
4581
  static fromExpo(z, phi) {
5240
4582
  return new Complex(
5241
- +(z * cos(phi)).toFixed(13),
5242
- +(z * sin(phi)).toFixed(13)
4583
+ +(z * cos$1(phi)).toFixed(13),
4584
+ +(z * sin$1(phi)).toFixed(13)
5243
4585
  );
5244
4586
  }
5245
4587
  get expo() {
@@ -5261,10 +4603,10 @@ class Complex extends ZikoMath{
5261
4603
  return z.clone.pow(n);
5262
4604
  }
5263
4605
  static xpowZ(x){
5264
- return complex((x**this.a)*cos(this.b*ln(x)),(x**this.a)*sin(this.b*ln(x)));
4606
+ return complex((x**this.a)*cos$1(this.b*ln(x)),(x**this.a)*sin$1(this.b*ln(x)));
5265
4607
  }
5266
4608
  sqrtn(n=2){
5267
- return complex(sqrtn(this.z,n)*cos(this.phi/n),sqrtn(this.z,n)*sin(this.phi/n));
4609
+ return complex(sqrtn(this.z,n)*cos$1(this.phi/n),sqrtn(this.z,n)*sin$1(this.phi/n));
5268
4610
  }
5269
4611
  get sqrt(){
5270
4612
  return this.sqrtn(2);
@@ -5273,14 +4615,14 @@ class Complex extends ZikoMath{
5273
4615
  return complex(this.z,this.phi);
5274
4616
  }
5275
4617
  get cos(){
5276
- return complex(cos(this.a)*cosh(this.b),sin(this.a)*sinh(this.b))
4618
+ return complex(cos$1(this.a)*cosh(this.b),sin$1(this.a)*sinh(this.b))
5277
4619
  }
5278
4620
  get sin(){
5279
- return complex(sin(this.a)*cosh(this.b),cos(this.a)*sinh(this.b))
4621
+ return complex(sin$1(this.a)*cosh(this.b),cos$1(this.a)*sinh(this.b))
5280
4622
  }
5281
4623
  get tan(){
5282
- const de=cos(this.a*2)+cosh(this.b*2);
5283
- return complex(sin(2*this.a)/de,sinh(2*this.b)/de);
4624
+ const de=cos$1(this.a*2)+cosh(this.b*2);
4625
+ return complex(sin$1(2*this.a)/de,sinh(2*this.b)/de);
5284
4626
  }
5285
4627
  printInConsole() {
5286
4628
  let string = this.a + " + " + this.b + " * i";
@@ -5311,12 +4653,12 @@ const complex=(a,b)=>{
5311
4653
  // } from "../calculus/index.js";
5312
4654
 
5313
4655
  const abs=(...x)=>mapfun$1(Math.abs,...x);
5314
- const sqrt=(...x)=>mapfun$1(Math.sqrt,...x);
5315
- const pow=(x,n)=>{
4656
+ const sqrt$1=(...x)=>mapfun$1(Math.sqrt,...x);
4657
+ const pow$1=(x,n)=>{
5316
4658
  if(typeof x === "number"){
5317
4659
  if(typeof n === "number")return Math.pow(x,n);
5318
4660
  else if(n instanceof Complex)return Complex.fromExpo(x**n.a,n.b*ln(x))
5319
- else return mapfun$1(a=>pow(x,a),...n);
4661
+ else return mapfun$1(a=>pow$1(x,a),...n);
5320
4662
  }
5321
4663
  else if(x instanceof Complex){
5322
4664
  if(typeof n === "number")return Complex.fromExpo(x.z**n,x.phi*n);
@@ -5324,14 +4666,14 @@ const pow=(x,n)=>{
5324
4666
  x.z**n.a*e(-x.phi*n.b),
5325
4667
  ln(x.z)*n.b+n.a*x.phi
5326
4668
  )
5327
- else return mapfun$1(a=>pow(x,a),...n);
4669
+ else return mapfun$1(a=>pow$1(x,a),...n);
5328
4670
  }
5329
4671
  else if(x instanceof Array){
5330
- if(typeof n === "number") return mapfun$1(a=>pow(a,n),...x);
4672
+ if(typeof n === "number") return mapfun$1(a=>pow$1(a,n),...x);
5331
4673
  else if(n instanceof Array){
5332
4674
  const Y=[];
5333
4675
  for(let i=0;i<x.length;i++){
5334
- Y.push(mapfun$1(a=>pow(x[i],a),...n));
4676
+ Y.push(mapfun$1(a=>pow$1(x[i],a),...n));
5335
4677
  }
5336
4678
  return Y;
5337
4679
  }
@@ -5356,293 +4698,533 @@ const sqrtn=(x,n)=>{
5356
4698
  return Y;
5357
4699
  }
5358
4700
  }
5359
- };
5360
- const e=(...x) => mapfun$1(Math.exp,...x);
5361
- const ln=(...x) => mapfun$1(Math.log,...x);
5362
- const cos=(...x) => mapfun$1(Fixed.cos,...x);
5363
- const sin=(...x) => mapfun$1(Fixed.sin,...x);
5364
- const tan=(...x) => mapfun$1(Fixed.tan,...x);
5365
- const sec=(...x) => mapfun$1(Fixed.sec,...x);
5366
- const sinc=(...x) => mapfun$1(Fixed.sinc,...x);
5367
- const csc=(...x) => mapfun$1(Fixed.csc,...x);
5368
- const cot=(...x) => mapfun$1(Fixed.cot,...x);
5369
- const acos=(...x) => mapfun$1(Fixed.acos,...x);
5370
- const asin=(...x) => mapfun$1(Fixed.asin,...x);
5371
- const atan=(...x) => mapfun$1(Fixed.atan,...x);
5372
- const acot=(...x) => mapfun$1(Fixed.acot,...x);
5373
- const cosh=(...x) => mapfun$1(Fixed.cosh,...x);
5374
- const sinh=(...x) => mapfun$1(Fixed.sinh,...x);
5375
- const tanh=(...x) => mapfun$1(Fixed.tanh,...x);
5376
- const coth=(...x) => mapfun$1(Fixed.coth,...x);
5377
- const acosh=(...x) => mapfun$1(Fixed.acosh,...x);
5378
- const asinh=(...x) => mapfun$1(Fixed.asinh,...x);
5379
- const atanh=(...x) => mapfun$1(Fixed.atanh,...x);
5380
- const ceil=(...x) => mapfun$1(Math.ceil,...x);
5381
- const floor=(...x) => mapfun$1(Math.floor,...x);
5382
- const round=(...x) => mapfun$1(Math.round,...x);
5383
- const atan2=(x,y,rad=true)=>{
5384
- if(typeof x === "number"){
5385
- if(typeof y === "number")return rad?Math.atan2(x,y):Math.atan2(x,y)*180/Math.PI;
5386
- else return mapfun$1(a=>atan2(x,a,rad),...y);
4701
+ };
4702
+ const e=(...x) => mapfun$1(Math.exp,...x);
4703
+ const ln=(...x) => mapfun$1(Math.log,...x);
4704
+ const cos$1=(...x) => mapfun$1(Fixed.cos,...x);
4705
+ const sin$1=(...x) => mapfun$1(Fixed.sin,...x);
4706
+ const tan=(...x) => mapfun$1(Fixed.tan,...x);
4707
+ const sec=(...x) => mapfun$1(Fixed.sec,...x);
4708
+ const sinc=(...x) => mapfun$1(Fixed.sinc,...x);
4709
+ const csc=(...x) => mapfun$1(Fixed.csc,...x);
4710
+ const cot=(...x) => mapfun$1(Fixed.cot,...x);
4711
+ const acos$1=(...x) => mapfun$1(Fixed.acos,...x);
4712
+ const asin=(...x) => mapfun$1(Fixed.asin,...x);
4713
+ const atan=(...x) => mapfun$1(Fixed.atan,...x);
4714
+ const acot=(...x) => mapfun$1(Fixed.acot,...x);
4715
+ const cosh=(...x) => mapfun$1(Fixed.cosh,...x);
4716
+ const sinh=(...x) => mapfun$1(Fixed.sinh,...x);
4717
+ const tanh=(...x) => mapfun$1(Fixed.tanh,...x);
4718
+ const coth=(...x) => mapfun$1(Fixed.coth,...x);
4719
+ const acosh=(...x) => mapfun$1(Fixed.acosh,...x);
4720
+ const asinh=(...x) => mapfun$1(Fixed.asinh,...x);
4721
+ const atanh=(...x) => mapfun$1(Fixed.atanh,...x);
4722
+ const ceil=(...x) => mapfun$1(Math.ceil,...x);
4723
+ const floor=(...x) => mapfun$1(Math.floor,...x);
4724
+ const round=(...x) => mapfun$1(Math.round,...x);
4725
+ const atan2=(x,y,rad=true)=>{
4726
+ if(typeof x === "number"){
4727
+ if(typeof y === "number")return rad?Math.atan2(x,y):Math.atan2(x,y)*180/Math.PI;
4728
+ else return mapfun$1(a=>atan2(x,a,rad),...y);
4729
+ }
4730
+ // else if(x instanceof Complex){
4731
+ // if(typeof n === "number")return Complex.fromExpo(x.z**n,x.phi*n);
4732
+ // else return mapfun(a=>pow(x,a),...n);
4733
+ // }
4734
+ else if(x instanceof Array){
4735
+ if(typeof y === "number") return mapfun$1(a=>atan2(a,y,rad),...x);
4736
+ else if(y instanceof Array){
4737
+ const Y=[];
4738
+ for(let i=0;i<x.length;i++){
4739
+ Y.push(mapfun$1(a=>pow$1(x[i],a),...y));
4740
+ }
4741
+ return Y;
4742
+ }
4743
+ }
4744
+ };
4745
+ const fact=(...x)=>mapfun$1(n=> {
4746
+ let i,
4747
+ y = 1;
4748
+ if (n == 0) y = 1;
4749
+ else if (n > 0) for (i = 1; i <= n; i++) y *= i;
4750
+ else y = NaN;
4751
+ return y;
4752
+ },...x);
4753
+ const sign=(...x)=>mapfun$1(Math.sign,...x);
4754
+
4755
+ const sig=(...x)=>mapfun$1(n=>1/(1+e(-n)),...x);
4756
+
4757
+ const hypot=(...x)=>{
4758
+ if(x.every(n=>typeof n === "number"))return Math.hypot(...x);
4759
+ if(x.every(n=>n instanceof Array))return mapfun$1(
4760
+ Math.hypot,
4761
+ ...x
4762
+ )
4763
+ };
4764
+
4765
+ const {PI, sqrt, cos, sin, acos, pow} = Math;
4766
+
4767
+ const Linear = t => t;
4768
+ const InSin = t => 1 - cos((t * PI) / 2);
4769
+ const OutSin = t => sin((t * PI) / 2);
4770
+ const InOutSin = t => -(cos(PI * t) - 1) / 2;
4771
+
4772
+ const InQuad = t => t**2;
4773
+ const OutQuad = t => 1 - (1-t)**2;
4774
+ const InOutQuad = t => t < 0.5 ? 2 * (t**2) : 1 - (-2 * t + 2)**2 / 2;
4775
+
4776
+ const InCubic = t => t**3;
4777
+ const OutCubic = t => 1 - (1-t)**3;
4778
+ const InOutCubic = t => t < 0.5 ? 4 * (t**3) : 1 - (-2 * t + 2)**3 / 2;
4779
+
4780
+ const InQuart = t => t**4;
4781
+ const OutQuart = t => 1 - (1-t)**4;
4782
+ const InOutQuart = t => t < 0.5 ? 8 * (t**4) : 1 - (-2 * t + 2)**4 / 2;
4783
+
4784
+ const InQuint = t => t**5;
4785
+ const OutQuint = t => 1 - (1-t)**5;
4786
+ const InOutQuint = t => t < 0.5 ? 16 * (t**5) : 1 - (-2 * t + 2)**5 / 2;
4787
+
4788
+ const InExpo = t => t === 0 ? 0 : 2**(10*t - 10);
4789
+ const OutExpo = t => t === 1 ? 1 : 1 - 2**(-10 * t);
4790
+ const InOutExpo = t => t === 0? 0: t === 1? 1: t < 0.5 ? 2**(20 * t - 10) / 2: (2 - 2**(-20 * t + 10)) / 2;
4791
+
4792
+ const InCirc = t => 1 - sqrt(1 - t**2);
4793
+ const OutCirc = t => sqrt(1 - (t-1)**2);
4794
+ const InOutCirc = t => t < 0.5? (1 - sqrt(1 - (2*t)**2)) / 2: (sqrt(1 - (-2*t+2)**2) + 1) / 2;
4795
+
4796
+ const Arc = t => 1 - sin(acos(t));
4797
+ const Back = (t, x = 1) => (t**2) * ((x+1)*t - x);
4798
+ const Elastic = t => -2*pow(2, 10 * (t - 1)) * cos(20 * PI * t / 3 * t);
4799
+
4800
+ const InBack = (t, c1 = 1.70158, c3 = c1 + 1) => c3 * pow(t,3)- c1 * (t**2);
4801
+ const OutBack = (t, c1 = 1.70158, c3 = c1 + 1) => 1 + c3 * pow(t - 1, 3) + c1 * pow(t - 1, 2);
4802
+ const InOutBack = (t, c1 = 1.70158, c2 = c1 * 1.525) => t < 0.5 ? (pow(2 * t, 2) * ((c2 + 1) * 2 * t - c2)) / 2 : (pow(2 * t - 2, 2) * ((c2 + 1) * (t * 2 - 2) + c2) + 2) / 2;
4803
+
4804
+ const InElastic = (t, c4 = 2*PI/3) => {
4805
+ return t === 0
4806
+ ? 0
4807
+ : t === 1
4808
+ ? 1
4809
+ : -pow(2, 10 * t - 10) * sin((t * 10 - 10.75) * c4);
4810
+ };
4811
+
4812
+ const OutElastic = (t, c4 = 2*PI/3) => {
4813
+ return t === 0
4814
+ ? 0
4815
+ : t === 1
4816
+ ? 1
4817
+ : pow(2, -10 * t) * sin((t * 10 - 0.75) * c4) + 1;
4818
+ };
4819
+ const InOutElastic = (t, c5 = 2 * PI / 4.5) => {
4820
+ return t === 0
4821
+ ? 0
4822
+ : t === 1
4823
+ ? 1
4824
+ : t < 0.5
4825
+ ? -(pow(2, 20 * t - 10) * sin((20 * t - 11.125) * c5)) / 2
4826
+ : (pow(2, -20 * t + 10) * sin((20 * t - 11.125) * c5)) / 2 + 1;
4827
+ };
4828
+
4829
+ const InBounce = (t, n1 = 7.5625, d1 = 2.75) => 1 - OutBounce(1-t, n1, d1);
4830
+ const OutBounce = (t, n1 = 7.5625, d1 = 2.75) => {
4831
+ if(t<1/d1) return n1 * t * t;
4832
+ if(t < 2 / d1) return n1 * (t -= 1.5 / d1) * t + 0.75;
4833
+ if(t < 2.5 / d1) return n1 * (t -= 2.25 / d1) * t + 0.9375;
4834
+ return n1 * (t -= 2.625 / d1) * t + 0.984375;
4835
+ };
4836
+
4837
+ const InOutBounce = (t, n1 = 7.5625, d1 = 2.75) => t < 0.5 ? OutBounce(1 - 2 * t, n1, d1)/2 : OutBounce(2 * t - 1, n1, d1)/2;
4838
+
4839
+
4840
+ const Step = (t, steps = 5) => Math.floor(t*steps) / steps;
4841
+ const Discret = (t, segments = 5) => Math.ceil(t*segments) / segments;
4842
+
4843
+ class TimeAnimation {
4844
+ constructor(callback, { ease = Linear, step = 50, t0 = 0, start = true, duration = 3000 } = {}) {
4845
+ this.callback = callback;
4846
+ this.state = {
4847
+ isRunning: false,
4848
+ animationId: null,
4849
+ startTime: null,
4850
+ ease,
4851
+ step,
4852
+ // interval: [t0, t1],
4853
+ autoStart: start,
4854
+ duration
4855
+ };
4856
+
4857
+ this.t = 0; // elapsed time
4858
+ this.tx = 0; // normalized [0,1]
4859
+ this.ty = 0; // eased value
4860
+ this.i = 0; // frame index
4861
+
4862
+ if (this.state.autoStart) {
4863
+ this.start();
4864
+ }
4865
+ }
4866
+
4867
+ // ---- private loop handler ----
4868
+ #tick = () => {
4869
+ this.t += this.state.step;
4870
+ this.i++;
4871
+
4872
+ this.tx = map(this.t, 0, this.state.duration, 0, 1);
4873
+ this.ty = this.state.ease(this.tx);
4874
+
4875
+ this.callback(this);
4876
+
4877
+ if (this.t >= this.state.duration) {
4878
+ clearInterval(this.state.animationId);
4879
+ this.state.isRunning = false;
4880
+ }
4881
+ };
4882
+
4883
+ // ---- core runner ----
4884
+ #run(reset = true) {
4885
+ if (!this.state.isRunning) {
4886
+ if (reset) this.reset(false);
4887
+
4888
+ this.state.isRunning = true;
4889
+ this.state.startTime = Date.now();
4890
+ this.state.animationId = setInterval(this.#tick, this.state.step);
4891
+ }
4892
+ return this;
4893
+ }
4894
+
4895
+ // ---- lifecycle methods ----
4896
+ start() {
4897
+ return this.#run(true);
4898
+ }
4899
+
4900
+ pause() {
4901
+ if (this.state.isRunning) {
4902
+ clearInterval(this.state.animationId);
4903
+ this.state.isRunning = false;
4904
+ }
4905
+ return this;
4906
+ }
4907
+
4908
+ resume() {
4909
+ return this.#run(false);
4910
+ }
4911
+
4912
+ stop() {
4913
+ this.pause();
4914
+ this.reset(false);
4915
+ return this;
4916
+ }
4917
+
4918
+ reset(restart = true) {
4919
+ this.t = 0;
4920
+ this.tx = 0;
4921
+ this.ty = 0;
4922
+ this.i = 0;
4923
+
4924
+ if (restart) this.start();
4925
+ return this;
4926
+ }
4927
+ }
4928
+
4929
+ // Hook-style factory
4930
+ const animation = (callback, {ease, t0, t1, start, duration} = {}) =>
4931
+ new TimeAnimation(callback, {ease, t0, t1, start, duration});
4932
+
4933
+ class Tick {
4934
+ constructor(ms, fn) {
4935
+ this.ms = ms;
4936
+ this.fn = fn;
4937
+ this.id = null;
4938
+ this.running = false;
4939
+ }
4940
+
4941
+ start() {
4942
+ if (!this.running) {
4943
+ this.running = true;
4944
+ this.id = setInterval(this.fn, this.ms);
4945
+ }
4946
+ return this;
4947
+ }
4948
+
4949
+ stop() {
4950
+ if (this.running) {
4951
+ this.running = false;
4952
+ clearInterval(this.id);
4953
+ this.id = null;
5387
4954
  }
5388
- // else if(x instanceof Complex){
5389
- // if(typeof n === "number")return Complex.fromExpo(x.z**n,x.phi*n);
5390
- // else return mapfun(a=>pow(x,a),...n);
5391
- // }
5392
- else if(x instanceof Array){
5393
- if(typeof y === "number") return mapfun$1(a=>atan2(a,y,rad),...x);
5394
- else if(y instanceof Array){
5395
- const Y=[];
5396
- for(let i=0;i<x.length;i++){
5397
- Y.push(mapfun$1(a=>pow(x[i],a),...y));
5398
- }
5399
- return Y;
5400
- }
4955
+ return this;
4956
+ }
4957
+
4958
+ isRunning() {
4959
+ return this.running;
4960
+ }
4961
+ }
4962
+ const tick = (ms, fn) => new Tick(ms, fn);
4963
+
4964
+ class Clock extends Tick {
4965
+ constructor(tickMs = 1000 / 60) {
4966
+ super(tickMs, () => this._tick());
4967
+ this.elapsed = 0;
4968
+ this._lastTime = performance.now();
4969
+ this._callbacks = new Set();
4970
+ }
4971
+
4972
+ _tick() {
4973
+ const now = performance.now();
4974
+ const delta = now - this._lastTime;
4975
+ this.elapsed += delta;
4976
+ this._lastTime = now;
4977
+
4978
+ for (const cb of this._callbacks) {
4979
+ cb({ elapsed: this.elapsed, delta });
5401
4980
  }
5402
- };
5403
- const fact=(...x)=>mapfun$1(n=> {
5404
- let i,
5405
- y = 1;
5406
- if (n == 0) y = 1;
5407
- else if (n > 0) for (i = 1; i <= n; i++) y *= i;
5408
- else y = NaN;
5409
- return y;
5410
- },...x);
5411
- const sign=(...x)=>mapfun$1(Math.sign,...x);
4981
+ }
5412
4982
 
5413
- const sig=(...x)=>mapfun$1(n=>1/(1+e(-n)),...x);
4983
+ onTick(cb) {
4984
+ this._callbacks.add(cb);
4985
+ return () => this._callbacks.delete(cb);
4986
+ }
5414
4987
 
5415
- const hypot=(...x)=>{
5416
- if(x.every(n=>typeof n === "number"))return Math.hypot(...x);
5417
- if(x.every(n=>n instanceof Array))return mapfun$1(
5418
- Math.hypot,
5419
- ...x
5420
- )
4988
+ reset() {
4989
+ this.elapsed = 0;
4990
+ this._lastTime = performance.now();
4991
+ }
4992
+
4993
+ pause() {
4994
+ super.stop();
4995
+ }
4996
+
4997
+ resume() {
4998
+ this._lastTime = performance.now();
4999
+ super.start();
5000
+ }
5001
+ }
5002
+
5003
+ const clock = (tickMs) => new Clock(tickMs);
5004
+
5005
+
5006
+ /*
5007
+
5008
+ const clock = new Clock(200);
5009
+
5010
+ clock.onTick(({ elapsed, delta }) => {
5011
+ console.log(`Elapsed: ${elapsed.toFixed(0)}ms, Delta: ${delta.toFixed(0)}ms`);
5012
+ });
5013
+
5014
+ clock.start();
5015
+
5016
+ setTimeout(() => clock.pause(), 1000);
5017
+ setTimeout(() => clock.resume(), 2000);
5018
+
5019
+ */
5020
+
5021
+ class TimeScheduler {
5022
+ constructor(tasks = [], { repeat = 1, loop = false } = {}) {
5023
+ this.tasks = tasks;
5024
+ this.repeat = repeat;
5025
+ this.loop = loop;
5026
+
5027
+ this.stopped = false;
5028
+ this.running = false;
5029
+
5030
+ // lifecycle hooks
5031
+ this.onStart = null;
5032
+ this.onTask = null;
5033
+ this.onEnd = null;
5034
+ }
5035
+
5036
+ async run() {
5037
+ if (this.running) return;
5038
+ this.running = true;
5039
+ this.stopped = false;
5040
+
5041
+ if (this.onStart) this.onStart();
5042
+
5043
+ let repeatCount = this.repeat;
5044
+
5045
+ do {
5046
+ for (const task of this.tasks) {
5047
+ if (this.stopped) return;
5048
+
5049
+ if (Array.isArray(task)) {
5050
+ // Parallel tasks
5051
+ await Promise.all(
5052
+ task.map(({ fn, delay = 0 }) =>
5053
+ new Promise(async (resolve) => {
5054
+ if (delay > 0) await new Promise(r => setTimeout(r, delay));
5055
+ if (this.onTask) this.onTask(fn);
5056
+ await fn();
5057
+ resolve();
5058
+ })
5059
+ )
5060
+ );
5061
+ } else {
5062
+ // Single task
5063
+ const { fn, delay = 0 } = task;
5064
+ if (delay > 0) await new Promise(r => setTimeout(r, delay));
5065
+ if (this.onTask) this.onTask(fn);
5066
+ await fn();
5067
+ }
5068
+ }
5069
+ } while (this.loop && !this.stopped && (repeatCount === Infinity || repeatCount-- > 1));
5070
+
5071
+ if (!this.stopped && this.onEnd) this.onEnd();
5072
+ this.running = false;
5073
+ }
5074
+
5075
+ stop() {
5076
+ this.stopped = true;
5077
+ this.running = false;
5078
+ }
5079
+
5080
+ addTask(task) {
5081
+ this.tasks.push(task);
5082
+ }
5083
+
5084
+ clearTasks() {
5085
+ this.tasks = [];
5086
+ }
5087
+ }
5088
+
5089
+ const Scheduler = (tasks, { repeat = null} = {}) => new TimeScheduler(tasks, { repeat});
5090
+
5091
+ const step_fps = (step_or_fps) => 1000 / step_or_fps;
5092
+
5093
+ const debounce=(fn,delay=1000)=>{
5094
+ return (...args) => setTimeout(()=>fn(...args),delay);
5095
+ };
5096
+ const throttle=(fn,delay)=>{
5097
+ let lastTime=0;
5098
+ return (...args) => {
5099
+ const now = new Date().getTime();
5100
+ if(now-lastTime < delay) return;
5101
+ lastTime = now;
5102
+ fn(...args);
5103
+ }
5421
5104
  };
5422
5105
 
5423
- class ZikoTimeLoop {
5424
- constructor(callback, step = 1000/30, startTime=0, endTime = Infinity, started = true) {
5106
+ function timeout(ms, fn) {
5107
+ let id;
5108
+ const promise = new Promise((resolve) => {
5109
+ id = setTimeout(() => {
5110
+ if (fn) fn();
5111
+ resolve();
5112
+ }, ms);
5113
+ });
5114
+
5115
+ return {
5116
+ id,
5117
+ clear: () => clearTimeout(id),
5118
+ promise
5119
+ };
5120
+ }
5121
+
5122
+ const sleep= ms => new Promise(res => setTimeout(res, ms));
5123
+
5124
+ // use it with await
5125
+
5126
+ class TimeLoop {
5127
+ constructor(callback, { step = 1000, t0 = 0, t1 = Infinity, autoplay = true } = {}) {
5425
5128
  this.callback = callback;
5426
5129
  this.cache = {
5427
5130
  isRunning: false,
5428
- AnimationId : null,
5429
- t0 : null,
5131
+ id: null,
5132
+ last_tick: null,
5430
5133
  step,
5431
- // fps,
5432
- startTime,
5433
- endTime,
5434
- started
5134
+ t0,
5135
+ t1,
5136
+ autoplay,
5137
+ pauseTime: null,
5138
+ frame : 0,
5435
5139
  };
5436
- this.init();
5437
- this.i=0;
5438
- }
5439
- init(){
5440
- // if(this.cache.step && this.cache.fps){
5441
- // console.warn(`Fps will be adjusted from ${this.cache.fps} to ${1000/this.cache.step} to ensure a smoother animation`);
5442
- // this.cache.fps=1000/this.cache.step;
5443
- // }
5444
- if(this.cache.started){
5445
- this.cache.startTime?this.startAfter(this.cache.startTime):this.start();
5446
- if(this.cache.endTime&&this.cache.endTime!==Infinity)this.stopAfter(this.cache.endTime);
5140
+
5141
+ if (autoplay) {
5142
+ t0 ? this.startAfter(t0) : this.start();
5143
+ if (t1 !== Infinity) this.stopAfter(t1);
5447
5144
  }
5448
- return this;
5449
5145
  }
5450
- // get TIME_STEP() {
5451
- // // return this.cache.step?this.cache.step:1000 / this.cache.fps;
5452
- // return this.cache.step;
5453
- // }
5146
+
5147
+ get frame(){
5148
+ return this.cache.frame;
5149
+ }
5150
+ get elapsed(){
5151
+ return this.cache.elapsed;
5152
+ }
5153
+
5454
5154
  start() {
5455
5155
  if (!this.cache.isRunning) {
5456
- this.i=0;
5156
+ this.cache.frame = 0;
5457
5157
  this.cache.isRunning = true;
5458
- this.cache.t0 = Date.now();
5158
+ this.cache.last_tick = Date.now();
5459
5159
  this.animate();
5460
5160
  }
5461
5161
  return this;
5462
5162
  }
5163
+
5463
5164
  pause() {
5464
5165
  if (this.cache.isRunning) {
5465
- clearTimeout(this.cache.AnimationId);
5166
+ clearTimeout(this.cache.id);
5466
5167
  this.cache.isRunning = false;
5168
+ this.cache.pauseTime = Date.now();
5467
5169
  }
5468
5170
  return this;
5469
5171
  }
5470
- stop(){
5471
- this.pause();
5472
- this.i=0;
5172
+
5173
+ resume() {
5174
+ if (!this.cache.isRunning) {
5175
+ this.cache.isRunning = true;
5176
+ if (this.cache.pauseTime) {
5177
+ // adjust start time so delta stays consistent
5178
+ const pausedDuration = Date.now() - this.cache.pauseTime;
5179
+ this.cache.last_tick += pausedDuration;
5180
+ }
5181
+ this.animate();
5182
+ }
5473
5183
  return this;
5474
5184
  }
5475
- resume(){
5476
- this.cache.isRunning=true;
5477
- this.animate();
5185
+
5186
+ stop() {
5187
+ this.pause();
5188
+ this.cache.frame = 0;
5478
5189
  return this;
5479
5190
  }
5480
- startAfter(t=1000){
5481
- setTimeout(this.start.bind(this),t);
5191
+
5192
+ startAfter(t = 1000) {
5193
+ setTimeout(() => this.start(), t);
5482
5194
  return this;
5483
5195
  }
5484
- stopAfter(t=1000){
5485
- setTimeout(this.stop.bind(this),t);
5486
- return this;
5196
+
5197
+ stopAfter(t = 1000) {
5198
+ setTimeout(() => this.stop(), t);
5199
+ return this;
5487
5200
  }
5201
+
5488
5202
  animate = () => {
5489
5203
  if (this.cache.isRunning) {
5490
5204
  const now = Date.now();
5491
- const delta = now - this.cache.t0;
5492
- if (delta > this.cache.step) {
5205
+ const delta = now - this.cache.last_tick;
5206
+
5207
+ if (delta >= this.cache.step) {
5208
+ this.cache.elapsed = now - (this.cache.t0 || 0);
5493
5209
  this.callback(this);
5494
- this.i++;
5495
- this.cache.t0 = now - (delta % this.cache.step);
5210
+ this.cache.frame++;
5211
+ this.cache.last_tick = now - (delta % this.cache.step);
5496
5212
  }
5497
- this.cache.AnimationId = setTimeout(this.animate, 0);
5498
- } }
5499
- }
5500
- const useFps = fps => 1000/fps;
5501
- const useTimeLoop = (callback, step, startTime, endTime, started) => new ZikoTimeLoop(callback, step, startTime, endTime, started);
5502
-
5503
- const Ease={
5504
- Linear:function(t){
5505
- return t;
5506
- },
5507
- InSin(t){
5508
- return 1 - Math.cos((t * Math.PI) / 2);
5509
- },
5510
- OutSin(t){
5511
- return Math.sin((t * Math.PI) / 2);
5512
- },
5513
- InOutSin(t){
5514
- return -(Math.cos(Math.PI * t) - 1) / 2;
5515
- },
5516
- InQuad(t){
5517
- return t**2;
5518
- },
5519
- OutQuad(t){
5520
- return 1 - Math.pow((1 - t),2)
5521
- },
5522
- InOutQuad(t){
5523
- return t < 0.5 ? 2 * Math.pow(t,2) : 1 - Math.pow(-2 * t + 2, 2) / 2;
5524
- },
5525
- InCubic(t){
5526
- return t**3;
5527
- },
5528
- OutCubic(t){
5529
- return 1 - Math.pow((1 - t),3)
5530
- },
5531
- InOutCubic(t){
5532
- return t < 0.5 ? 4 * Math.pow(t,3) : 1 - Math.pow(-2 * t + 2, 3) / 2;
5533
- },
5534
- InQuart(t){
5535
- return t**4;
5536
- },
5537
- OutQuart(t){
5538
- return 1 - Math.pow((1 - t),4);
5539
- },
5540
- InOutQuart(t){
5541
- return t < 0.5 ? 8 * Math.pow(t,4) : 1 - Math.pow(-2 * t + 2, 4) / 2;
5542
- },
5543
- InQuint(t){
5544
- return t**5;
5545
- },
5546
- OutQuint(t){
5547
- return 1 - Math.pow((1 - t),5);
5548
- },
5549
- InOutQuint(t){
5550
- return t < 0.5 ? 16 * Math.pow(t,5) : 1 - Math.pow(-2 * t + 2, 5) / 2;
5551
- },
5552
- InExpo(t){
5553
- return t === 0 ? 0 : Math.pow(2, 10 * t - 10);
5554
- },
5555
- OutExpo(t){
5556
- return t === 1 ? 1 : 1 - Math.pow(2, -10 * t);
5557
- },
5558
- InOutExpo(t){
5559
- 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;
5560
- },
5561
- InCirc(t){
5562
- return 1 - Math.sqrt(1 - Math.pow(t, 2));
5563
- },
5564
- OutCirc(t){
5565
- return Math.sqrt(1 - Math.pow(t - 1, 2));
5566
- },
5567
- InOutCic(t){
5568
- 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;
5569
- },
5570
- Arc(t){
5571
- return 1 - Math.sin(Math.acos(t));
5572
- },
5573
- Back(t){
5574
- // To Be Changed
5575
- let x=1;
5576
- return Math.pow(t, 2) * ((x + 1) * t - x);
5577
- },
5578
- Elastic(t){
5579
- return -2*Math.pow(2, 10 * (t - 1)) * Math.cos(20 * Math.PI * t / 3 * t);
5580
- },
5581
- InBack(t){
5582
- const c1 = 1.70158;
5583
- const c3 = c1 + 1;
5584
- return c3 *Math.pow(t,3)- c1 * (t**2);
5585
- },
5586
- OutBack(t){
5587
- const c1 = 1.70158;
5588
- const c3 = c1 + 1;
5589
- return 1 + c3 * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2);
5590
- },
5591
- InOutBack(t){
5592
- const c1 = 1.70158;
5593
- const c2 = c1 * 1.525;
5594
- return t < 0.5
5595
- ? (Math.pow(2 * t, 2) * ((c2 + 1) * 2 * t - c2)) / 2
5596
- : (Math.pow(2 * t - 2, 2) * ((c2 + 1) * (t * 2 - 2) + c2) + 2) / 2;
5597
- },
5598
- InElastic(t){
5599
- const c4 = (2 * Math.PI) / 3;return t === 0
5600
- ? 0
5601
- : t === 1
5602
- ? 1
5603
- : -Math.pow(2, 10 * t - 10) * Math.sin((t * 10 - 10.75) * c4);
5604
- },
5605
- OutElastic(t){
5606
- const c4 = (2 * Math.PI) / 3;
5607
- return t === 0
5608
- ? 0
5609
- : t === 1
5610
- ? 1
5611
- : Math.pow(2, -10 * t) * Math.sin((t * 10 - 0.75) * c4) + 1;
5612
- },
5613
- InOutElastic(t){
5614
- const c5 = (2 * Math.PI) / 4.5;
5615
- return t === 0
5616
- ? 0
5617
- : t === 1
5618
- ? 1
5619
- : t < 0.5
5620
- ? -(Math.pow(2, 20 * t - 10) * Math.sin((20 * t - 11.125) * c5)) / 2
5621
- : (Math.pow(2, -20 * t + 10) * Math.sin((20 * t - 11.125) * c5)) / 2 + 1;
5622
- },
5623
- InBounce(t){
5624
- return 1 - Ease.OutBounce(1-t);
5625
- },
5626
- OutBounce(t){
5627
- const n1 = 7.5625;
5628
- const d1 = 2.75;
5629
- if (t < 1 / d1) {
5630
- return n1 * t * t;
5631
- } else if (t < 2 / d1) {
5632
- return n1 * (t -= 1.5 / d1) * t + 0.75;
5633
- } else if (t < 2.5 / d1) {
5634
- return n1 * (t -= 2.25 / d1) * t + 0.9375;
5635
- } else {
5636
- return n1 * (t -= 2.625 / d1) * t + 0.984375;
5637
- }
5638
5213
 
5639
- },
5640
- InOutBounce(t){
5641
- return t < 0.5
5642
- ? (1 - Ease.OutBounce(1 - 2 * t)) / 2
5643
- : (1 + Ease.OutBounce(2 * t - 1)) / 2;
5214
+ this.cache.id = setTimeout(this.animate, 0);
5644
5215
  }
5645
- };
5216
+ }
5217
+ }
5218
+
5219
+ const loop = (callback, options = {}) => new TimeLoop(callback, options);
5220
+
5221
+
5222
+ // Helpers
5223
+ // const useFps = (fps) => 1000 / fps;
5224
+
5225
+ // const _loop = loop( e => {
5226
+ // console.log("Frame:", e.frame, " Elapsed: ", e.elapsed);
5227
+ // });
5646
5228
 
5647
5229
  const time_memory_Taken = (callback) => {
5648
5230
  const t0 = Date.now();
@@ -5685,6 +5267,7 @@ const waitForUIElm=(UIElement)=>{
5685
5267
  }
5686
5268
  };
5687
5269
 
5270
+ // import Ease from "./ease.js";
5688
5271
  const wait=(delayInMS)=>{
5689
5272
  return new Promise((resolve) => setTimeout(resolve, delayInMS));
5690
5273
  };
@@ -5695,93 +5278,6 @@ const timeTaken = callback => {
5695
5278
  return r;
5696
5279
  };
5697
5280
 
5698
- class ZikoTimeAnimation{
5699
- constructor(callback,ease=Ease.Linear,step=50,{t=[0,null],start=true,duration=3000}={}){
5700
- this.cache={
5701
- isRunning:false,
5702
- AnimationId:null,
5703
- startTime:null,
5704
- ease,
5705
- step,
5706
- intervall:t,
5707
- started:start,
5708
- duration
5709
- };
5710
- this.t=0;
5711
- this.tx=0;
5712
- this.ty=0;
5713
- this.i=0;
5714
- this.callback=callback;
5715
- }
5716
- #animation_handler(){
5717
- this.t+=this.cache.step;
5718
- this.i++;
5719
- this.tx=map(this.t,0,this.cache.duration,0,1);
5720
- this.ty=this.cache.ease(this.tx);
5721
- this.callback(this);
5722
- if(this.t>=this.cache.duration){
5723
- clearInterval(this.cache.AnimationId);
5724
- this.cache.isRunning=false;
5725
- }
5726
- }
5727
- reset(restart=true){
5728
- this.t=0;
5729
- this.tx=0;
5730
- this.ty=0;
5731
- this.i=0;
5732
- if(restart)this.start();
5733
- return this;
5734
- }
5735
- #animate(reset=true){
5736
- if(!this.cache.isRunning){
5737
- if(reset)this.reset(false);
5738
- this.cache.isRunning=true;
5739
- this.cache.startTime = Date.now();
5740
- this.cache.AnimationId=setInterval(this.#animation_handler.bind(this),this.cache.step);
5741
- }
5742
- return this;
5743
- }
5744
- start(){
5745
- this.#animate(true);
5746
- return this;
5747
- }
5748
- pause(){
5749
- if (this.cache.isRunning) {
5750
- clearTimeout(this.cache.AnimationId);
5751
- this.cache.isRunning = false;
5752
- }
5753
- return this;
5754
- }
5755
- resume(){
5756
- this.#animate(false);
5757
- return this;
5758
- }
5759
- stop(){
5760
- this.pause();
5761
- this.reset(false);
5762
- return this;
5763
- }
5764
- // clear(){
5765
- // }
5766
- // stream(){
5767
- // }
5768
- }
5769
-
5770
- const useAnimation=(callback,ease=Ease.Linear,step=50,config)=>new ZikoTimeAnimation(callback,ease=Ease.Linear,step=50,config);
5771
-
5772
- const debounce=(fn,delay=1000)=>{
5773
- return (...args) => setTimeout(()=>fn(...args),delay);
5774
- };
5775
- const throttle=(fn,delay)=>{
5776
- let lastTime=0;
5777
- return (...args) => {
5778
- const now = new Date().getTime();
5779
- if(now-lastTime < delay) return;
5780
- lastTime = now;
5781
- fn(...args);
5782
- }
5783
- };
5784
-
5785
5281
  class ZikoApp {
5786
5282
  constructor({head = null, wrapper = null, target = null}){
5787
5283
  this.head = head;
@@ -5997,6 +5493,70 @@ function findCommonPath(paths) {
5997
5493
  return commonPath;
5998
5494
  }
5999
5495
 
5496
+ function useDerived(deriveFn, sources) {
5497
+ let value = deriveFn(...sources.map(s => s().value));
5498
+ const subscribers = new Set();
5499
+ let paused = false;
5500
+
5501
+ function getValue() {
5502
+ return {
5503
+ value,
5504
+ isStateGetter: () => true,
5505
+ _subscribe: (fn, UIElement) => {
5506
+ subscribers.add(fn);
5507
+
5508
+ const observer = new MutationObserver(() => {
5509
+ if (!document.body.contains(UIElement.element)) {
5510
+ subscribers.delete(fn);
5511
+ observer.disconnect();
5512
+ }
5513
+ });
5514
+
5515
+ observer.observe(document.body, { childList: true, subtree: true });
5516
+ },
5517
+ };
5518
+ }
5519
+
5520
+ function setValue(newValue) {
5521
+ if (paused) return;
5522
+ if (typeof newValue === "function") newValue = newValue(value);
5523
+ if (newValue !== value) {
5524
+ value = newValue;
5525
+ subscribers.forEach(fn => fn(value));
5526
+ }
5527
+ }
5528
+
5529
+ const controller = {
5530
+ pause: () => { paused = true; },
5531
+ resume: () => { paused = false; },
5532
+ clear: () => { subscribers.clear(); },
5533
+ force: (newValue) => {
5534
+ if (typeof newValue === "function") newValue = newValue(value);
5535
+ value = newValue;
5536
+ subscribers.forEach(fn => fn(value));
5537
+ },
5538
+ getSubscribers: () => new Set(subscribers),
5539
+ };
5540
+
5541
+ // Subscribe to source states
5542
+ sources.forEach(source => {
5543
+ const srcValue = source(); // getValue()
5544
+ srcValue._subscribe(() => {
5545
+ if (!paused) {
5546
+ const newVal = deriveFn(...sources.map(s => s().value));
5547
+ if (newVal !== value) {
5548
+ value = newVal;
5549
+ subscribers.forEach(fn => fn(value));
5550
+ }
5551
+ }
5552
+ }, { element: document.body }); // dummy UIElement
5553
+ });
5554
+
5555
+ return [getValue, setValue, controller];
5556
+ }
5557
+
5558
+ const useReactive = (nested_value) => mapfun$1(n => useState(n), nested_value);
5559
+
6000
5560
  class ZikoUseChannel{
6001
5561
  constructor(name = ""){
6002
5562
  this.channel = new BroadcastChannel(name);
@@ -6235,4 +5795,4 @@ if(globalThis?.document){
6235
5795
  document?.addEventListener("DOMContentLoaded", __Ziko__.__Config__.init());
6236
5796
  }
6237
5797
 
6238
- export { App, Base, Canvas, Combinaison, Complex, E, EPSILON, Ease, FileBasedRouting, Flex, Grid$1 as Grid, HTMLWrapper, Logic$1 as Logic, Matrix, PI$1 as PI, Permutation, Random, SPA, SVGWrapper, Str, Suspense, Svg, Utils, ZikoApp, ZikoCustomEvent, ZikoEventClick, ZikoEventClipboard, ZikoEventCustom, ZikoEventDrag, ZikoEventFocus, ZikoEventInput, ZikoEventKey, ZikoEventMouse, ZikoEventPointer, ZikoEventSwipe, ZikoEventTouch, ZikoEventWheel, ZikoHead, ZikoMutationObserver, ZikoSPA, ZikoUICanvas, ZikoUIElement, ZikoUIFlex, ZikoUIGrid, ZikoUIHTMLWrapper, ZikoUINode, ZikoUISVGWrapper, ZikoUISuspense, ZikoUISvg, ZikoUIText, ZikoUIXMLWrapper, ZikoUseRoot, ZikoUseStyle, __ZikoEvent__, abs, accum, acos, acosh, acot, add, arange, arr2str, asin, asinh, atan, atan2, atanh, bindClickEvent, bindClipboardEvent, bindCustomEvent, bindDragEvent, bindFocusEvent, bindHashEvent, bindKeyEvent, bindMouseEvent, bindPointerEvent, bindTouchEvent, bindWheelEvent, cartesianProduct, ceil, clamp, combinaison, complex, cos, cosh, cot, coth, count, countWords, csc, csv2arr, csv2json, csv2matrix, csv2object, csv2sql, debounce, defineParamsGetter, deg2rad, div, e, fact, floor, geomspace, getEvent, hypot, inRange, isApproximatlyEqual, json2arr, json2css, json2csv, json2csvFile, json2xml, json2xmlFile, json2yml, json2ymlFile, lerp, linspace, ln, logspace, map, mapfun$1 as mapfun, matrix, matrix2, matrix3, matrix4, max, min, modulo, mul, norm, nums, obj2str, ones, pgcd, pow, powerSet, ppcm, preload, prod, rad2deg, removeExtraSpace, round, sec, sig, sign, sin, sinc, sinh, sqrt, sqrtn, str, sub, subSet, sum, svg2ascii, svg2img, svg2imgUrl, svg2str, tags, tan, tanh, text, throttle, timeTaken, time_memory_Taken, useAnimation, useChannel, useCustomEvent, useEventEmitter, useFavIcon, useFps, useHashEvent, useHead, useInputEvent, useLocaleStorage, useMediaQuery, useMeta, useRoot, useSessionStorage, useStyle, useSuccesifKeys, useSwipeEvent, useThread, useTimeLoop, useTitle, wait, waitForUIElm, waitForUIElmSync, watch, watchAttr, watchChildren, watchIntersection, watchScreen, watchSize, zeros };
5798
+ export { App, Arc, Back, Base, Canvas, Clock, Combinaison, Complex, Discret, E, EPSILON, Elastic, FileBasedRouting, Flex, Grid$1 as Grid, HTMLWrapper, InBack, InBounce, InCirc, InCubic, InElastic, InExpo, InOutBack, InOutBounce, InOutCirc, InOutCubic, InOutElastic, InOutExpo, InOutQuad, InOutQuart, InOutQuint, InOutSin, InQuad, InQuart, InQuint, InSin, Linear, Logic$1 as Logic, Matrix, OutBack, OutBounce, OutCirc, OutCubic, OutElastic, OutExpo, OutQuad, OutQuart, OutQuint, OutSin, PI$2 as PI, Permutation, Random, SPA, SVGWrapper, Scheduler, Step, Suspense, Svg, Tick, TimeAnimation, TimeLoop, TimeScheduler, UIElement, UINode, Utils, ZikoApp, ZikoCustomEvent, ZikoEventClick, ZikoEventClipboard, ZikoEventCustom, ZikoEventDrag, ZikoEventFocus, ZikoEventInput, ZikoEventKey, ZikoEventMouse, ZikoEventPointer, ZikoEventSwipe, ZikoEventTouch, ZikoEventWheel, ZikoHead, ZikoMutationObserver, ZikoSPA, ZikoUICanvas, ZikoUIFlex, ZikoUIGrid, ZikoUIHTMLWrapper, ZikoUISVGWrapper, ZikoUISuspense, ZikoUISvg, ZikoUIText, ZikoUIXMLWrapper, ZikoUseRoot, __ZikoEvent__, abs, accum, acos$1 as acos, acosh, acot, add, animation, arange, arr2str, asin, asinh, atan, atan2, atanh, bindClickEvent, bindClipboardEvent, bindCustomEvent, bindDragEvent, bindFocusEvent, bindHashEvent, bindKeyEvent, bindMouseEvent, bindPointerEvent, bindTouchEvent, bindWheelEvent, cartesianProduct, ceil, clamp, clock, combinaison, complex, cos$1 as cos, cosh, cot, coth, csc, csv2arr, csv2json, csv2matrix, csv2object, csv2sql, debounce, defineParamsGetter, deg2rad, div, e, fact, floor, geomspace, getEvent, hypot, inRange, isApproximatlyEqual, isStateGetter, json2arr, json2css, json2csv, json2csvFile, json2xml, json2xmlFile, json2yml, json2ymlFile, lerp, linspace, ln, logspace, loop, map, mapfun$1 as mapfun, matrix, matrix2, matrix3, matrix4, max, min, modulo, mul, norm, nums, obj2str, ones, pgcd, pow$1 as pow, powerSet, ppcm, preload, prod, rad2deg, round, sec, sig, sign, sin$1 as sin, sinc, sinh, sleep, sqrt$1 as sqrt, sqrtn, step_fps, sub, subSet, sum, svg2ascii, svg2img, svg2imgUrl, svg2str, tags, tan, tanh, text, throttle, tick, timeTaken, time_memory_Taken, timeout, useChannel, useCustomEvent, useDerived, useEventEmitter, useFavIcon, useHashEvent, useHead, useInputEvent, useLocaleStorage, useMediaQuery, useMeta, useReactive, useRoot, useSessionStorage, useState, useSuccesifKeys, useSwipeEvent, useThread, useTitle, wait, waitForUIElm, waitForUIElmSync, watch, watchAttr, watchChildren, watchIntersection, watchScreen, watchSize, zeros };