ziko 0.50.1 → 0.51.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 (50) hide show
  1. package/dist/ziko.cjs +772 -898
  2. package/dist/ziko.js +509 -240
  3. package/dist/ziko.min.js +2 -2
  4. package/dist/ziko.mjs +506 -241
  5. package/package.json +1 -1
  6. package/src/__helpers__/checkers/index.js +1 -0
  7. package/src/data/api/fetchdom.js +27 -11
  8. package/src/events/binders/coordinates-based-event.js +25 -0
  9. package/src/events/binders/custom-event.js +1 -1
  10. package/src/events/binders/index.js +45 -12
  11. package/src/events/custom-events-registry/index.js +3 -1
  12. package/src/events/custom-events-registry/swipe.js +41 -23
  13. package/src/events/custom-events-registry/view.js +50 -19
  14. package/src/events/customizers/normalise-coordinates.js +0 -0
  15. package/src/events/details-setter/index.js +3 -1
  16. package/src/events/details-setter/mouse.js +35 -0
  17. package/src/events/details-setter/pointer.js +33 -31
  18. package/src/events/details-setter/touch.js +37 -0
  19. package/src/events/events-map/index.js +13 -5
  20. package/src/events/utils.js +31 -0
  21. package/src/events/ziko-event.js +59 -117
  22. package/src/router/file-based-router/index.js +46 -0
  23. package/src/router/index.js +2 -0
  24. package/src/router/utils/dynamic-routes-parser.js +76 -0
  25. package/src/router/utils/get-root.js +16 -0
  26. package/src/router/utils/index.js +5 -0
  27. package/src/router/utils/normalize-path.js +17 -0
  28. package/src/router/utils/routes-grouper.js +22 -0
  29. package/src/router/utils/routes-matcher.js +60 -0
  30. package/src/ui/__methods__/dom.js +0 -20
  31. package/src/ui/__methods__/events.js +8 -4
  32. package/src/ui/__methods__/index.js +3 -0
  33. package/src/ui/__methods__/lifecycle.js +54 -0
  34. package/src/ui/constructors/UIElement.js +4 -30
  35. package/src/ui/{constructors/UIElement-lite.js → mini/UIElement.js} +1 -1
  36. package/src/ui/suspense/index.js +1 -2
  37. package/types/data/api/index.d.ts +15 -0
  38. package/types/data/index.d.ts +1 -0
  39. package/types/data/string/checkers.d.ts +51 -0
  40. package/types/data/string/converters.d.ts +101 -0
  41. package/types/data/string/index.d.ts +2 -0
  42. package/types/index.d.ts +3 -1
  43. package/types/router/file-based-router/index.d.ts +20 -0
  44. package/types/router/index.d.ts +2 -0
  45. package/types/router/utils/dynamic-routes-parser.d.ts +14 -0
  46. package/types/router/utils/get-root.d.ts +11 -0
  47. package/types/router/utils/index.d.ts +5 -0
  48. package/types/router/utils/normalize-path.d.ts +15 -0
  49. package/types/router/utils/routes-grouper.d.ts +29 -0
  50. package/types/router/utils/routes-matcher.d.ts +1 -0
package/dist/ziko.js CHANGED
@@ -2,7 +2,7 @@
2
2
  /*
3
3
  Project: ziko.js
4
4
  Author: Zakaria Elalaoui
5
- Date : Tue Dec 02 2025 16:28:22 GMT+0100 (UTC+01:00)
5
+ Date : Wed Dec 03 2025 10:58:16 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
@@ -949,16 +949,28 @@
949
949
  }
950
950
  };
951
951
 
952
- async function fetchdom(url='https://github.com/zakarialaoui10'){
953
- const data=await fetch(url);
954
- const html=await data.text();
955
- const dom= new DOMParser().parseFromString(html,'text/xml');
956
- return dom.documentElement
952
+ async function fetchdom(url='https://github.com/zakarialaoui10') {
953
+ try {
954
+ const response = await fetch(url);
955
+ if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
956
+ const html = await response.text();
957
+ const dom = new DOMParser().parseFromString(html, 'text/html');
958
+ return dom.documentElement;
959
+ } catch (err) {
960
+ console.error('Failed to fetch DOM:', err);
961
+ throw err;
962
+ }
957
963
  }
958
- function fetchdomSync(url='https://github.com/zakarialaoui10'){
959
- const data=preload(url);
960
- const dom= new DOMParser().parseFromString(data,'text/xml');
961
- return dom.documentElement;
964
+
965
+ function fetchdomSync(url='https://github.com/zakarialaoui10') {
966
+ try {
967
+ const data = preload(url);
968
+ const dom = new DOMParser().parseFromString(data, 'text/html');
969
+ return dom.documentElement;
970
+ } catch (err) {
971
+ console.error('Failed to fetch DOM synchronously:', err);
972
+ throw err;
973
+ }
962
974
  }
963
975
 
964
976
  globalThis.fetchdom=fetchdom;
@@ -1217,6 +1229,67 @@
1217
1229
  }
1218
1230
  }
1219
1231
 
1232
+ // export function mount(target = this.target) {
1233
+ // if(this.isBody) return ;
1234
+ // if(target?.isUIElement)target=target.element;
1235
+ // this.target=target;
1236
+ // this.target?.appendChild(this.element);
1237
+ // return this;
1238
+ // }
1239
+ // export function unmount(){
1240
+ // if(this.cache.parent)this.cache.parent.remove(this);
1241
+ // else if(this.target?.children?.length && [...this.target?.children].includes(this.element)) this.target.removeChild(this.element);
1242
+ // return this;
1243
+ // }
1244
+
1245
+ // export function mountAfter(target = this.target, t = 1) {
1246
+ // setTimeout(() => this.mount(), t);
1247
+ // return this;
1248
+ // }
1249
+ // export function unmountAfter(t = 1) {
1250
+ // setTimeout(() => this.unmount(), t);
1251
+ // return this;
1252
+ // }
1253
+
1254
+ function mount(target = this.target, delay = 0) {
1255
+ if (delay > 0) {
1256
+ setTimeout(() => this.mount(target, 0), delay);
1257
+ return this;
1258
+ }
1259
+
1260
+ if (this.isBody) return this;
1261
+
1262
+ if (target?.isUIElement) target = target.element;
1263
+ this.target = target;
1264
+
1265
+ this.target?.appendChild(this.element);
1266
+ return this;
1267
+ }
1268
+
1269
+ function unmount(delay = 0) {
1270
+ if (delay > 0) {
1271
+ setTimeout(() => this.unmount(0), delay);
1272
+ return this;
1273
+ }
1274
+
1275
+ if (this.cache.parent) {
1276
+ this.cache.parent.remove(this);
1277
+ } else if (
1278
+ this.target?.children?.length &&
1279
+ [...this.target.children].includes(this.element)
1280
+ ) {
1281
+ this.target.removeChild(this.element);
1282
+ }
1283
+
1284
+ return this;
1285
+ }
1286
+
1287
+ var LifecycleMethods = /*#__PURE__*/Object.freeze({
1288
+ __proto__: null,
1289
+ mount: mount,
1290
+ unmount: unmount
1291
+ });
1292
+
1220
1293
  function parseQueryParams$1(queryString) {
1221
1294
  const params = {};
1222
1295
  queryString.replace(/[A-Z0-9]+?=([\w|:|\/\.]*)/gi, (match) => {
@@ -1705,18 +1778,6 @@
1705
1778
  this.element.innerHTML = "";
1706
1779
  return this;
1707
1780
  }
1708
- function mount(target = this.target) {
1709
- if(this.isBody)return ;
1710
- if(target?.isUIElement)target=target.element;
1711
- this.target=target;
1712
- this.target?.appendChild(this.element);
1713
- return this;
1714
- }
1715
- function unmount(){
1716
- if(this.cache.parent)this.cache.parent.remove(this);
1717
- else if(this.target?.children?.length && [...this.target?.children].includes(this.element)) this.target.removeChild(this.element);
1718
- return this;
1719
- }
1720
1781
  function replaceElementWith(new_element){
1721
1782
  this.cache.element.replaceWith(new_element);
1722
1783
  this.cache.element = new_element;
@@ -1724,14 +1785,6 @@
1724
1785
  // To do : Dispose Events and States
1725
1786
  return this
1726
1787
  }
1727
- function renderAfter(t = 1) {
1728
- setTimeout(() => this.mount(), t);
1729
- return this;
1730
- }
1731
- function unrenderAfter(t = 1) {
1732
- setTimeout(() => this.unmount(), t);
1733
- return this;
1734
- }
1735
1788
  function after(ui){
1736
1789
  if(ui?.isUIElement) ui=ui.element;
1737
1790
  this.element?.after(ui);
@@ -1750,20 +1803,12 @@
1750
1803
  before: before,
1751
1804
  clear: clear,
1752
1805
  insertAt: insertAt,
1753
- mount: mount,
1754
1806
  prepend: prepend,
1755
1807
  remove: remove,
1756
- renderAfter: renderAfter,
1757
- replaceElementWith: replaceElementWith,
1758
- unmount: unmount,
1759
- unrenderAfter: unrenderAfter
1808
+ replaceElementWith: replaceElementWith
1760
1809
  });
1761
1810
 
1762
1811
  const EventsMap = {
1763
- 'Custom' : [
1764
- 'emit',
1765
- 'on'
1766
- ],
1767
1812
  'Click' : [
1768
1813
  'Click',
1769
1814
  'DblClick',
@@ -1809,64 +1854,109 @@
1809
1854
  ],
1810
1855
  'Wheel': [
1811
1856
  'Wheel'
1812
- ]
1857
+ ],
1813
1858
  // 'Media':[
1814
1859
 
1815
1860
  // ],
1816
1861
  // 'Hash':[
1817
1862
  // "HashChange"
1818
1863
  // ]
1864
+
1865
+ 'View':[
1866
+ 'EnterView',
1867
+ 'ExitView',
1868
+ 'ResizeView'
1869
+ ],
1870
+ 'Swipe':[
1871
+ 'SwipeLeft',
1872
+ 'SwipeUp',
1873
+ 'SwipeRight',
1874
+ 'SwipeDown'
1875
+ ]
1819
1876
  };
1820
1877
 
1878
+ function event_controller(e, event_name, details_setter, customizer) {
1879
+ this.cache.currentEvent = event_name;
1880
+ this.cache.event = e;
1881
+
1882
+ details_setter?.call(this);
1883
+ if (customizer?.hasOwnProperty('prototype')) customizer?.call(this);
1884
+ else customizer?.call(null, this);
1885
+
1886
+ if (this.cache.preventDefault[event_name]) e.preventDefault();
1887
+ if (this.cache.stopPropagation[event_name]) e.stopPropagation();
1888
+ if (this.cache.stopImmediatePropagation[event_name]) e.stopImmediatePropagation();
1889
+
1890
+ // Call the single callback if it exists
1891
+ this.cache.callbacks[event_name]?.(this);
1892
+ }
1893
+
1894
+ function toggle_event_listener(method, ...events) {
1895
+ const keys = events.length === 0
1896
+ ? Object.keys(this.cache.paused)
1897
+ : events;
1898
+ keys.forEach(key => {
1899
+ if (!this.cache.paused.hasOwnProperty(key)) return;
1900
+ this.targetElement?.[method](
1901
+ key,
1902
+ this.cache.__controllers__[key],
1903
+ this.cache.options[key]
1904
+ );
1905
+ this.cache.paused[key] = method === 'removeEventListener';
1906
+ });
1907
+ return this;
1908
+ }
1821
1909
  const getEvent=(event = "")=>{
1822
1910
  if(event.startsWith("Ptr"))return `pointer${event.split("Ptr")[1].toLowerCase()}`;
1823
1911
  return event.toLowerCase()
1824
1912
  };
1825
1913
 
1826
1914
  class ZikoEvent {
1827
- constructor(target = null, Events = [], details_setter, customizer){
1915
+ constructor(signature, target = null, Events = [], details_setter, customizer){
1828
1916
  this.target = target;
1829
1917
  this.cache = {
1918
+ signature,
1830
1919
  currentEvent : null,
1831
1920
  event: null,
1832
1921
  options : {},
1833
1922
  preventDefault : {},
1834
1923
  stopPropagation : {},
1835
1924
  stopImmediatePropagation : {},
1836
- event_flow : {},
1837
1925
  paused : {},
1838
- stream : {
1839
- enabled : {},
1840
- clear : {},
1841
- history : {}
1842
- },
1843
1926
  callbacks : {},
1844
1927
  __controllers__:{}
1845
1928
  };
1846
- if(Events)this._register_events(Events, details_setter, customizer);
1847
- }
1848
- _register_events(Events, details_setter, customizer, REGISTER_METHODES = true){
1849
- const events = Events?.map(n=>getEvent(n));
1850
- events?.forEach((event,i)=>{
1851
- Object.assign(this.cache.preventDefault, {[event] : false});
1852
- Object.assign(this.cache.options, {[event] : {}});
1853
- Object.assign(this.cache.paused, {[event] : false});
1854
- Object.assign(this.cache.stream.enabled, {[event] : false});
1855
- Object.assign(this.cache.stream.clear, {[event] : false});
1856
- Object.assign(this.cache.stream.history, {[event] : []});
1857
- Object.assign(this.cache.__controllers__, {[event] : e=>event_controller.call(this, e, event, details_setter, customizer)});
1858
- if(REGISTER_METHODES)Object.assign(this, { [`on${Events[i]}`] : (...callbacks)=> this.__onEvent(event, this.cache.options[event], {}, ...callbacks)});
1929
+ if (Events) this._register_events(Events, details_setter, customizer);
1930
+ }
1931
+ _register_events(Events, details_setter, customizer, REGISTER_METHODES = true) {
1932
+ const events = Events?.map(n => getEvent(n));
1933
+ events?.forEach((event, i) => {
1934
+ this.cache.preventDefault[event] = false;
1935
+ this.cache.options[event] = {};
1936
+ this.cache.paused[event] = false;
1937
+ this.cache.__controllers__[event] = (e) =>
1938
+ event_controller.call(this, e, event, details_setter, customizer);
1939
+ if (REGISTER_METHODES) {
1940
+ this[`on${Events[i]}`] = (callback) =>
1941
+ this.__onEvent(event, this.cache.options[event], {}, callback);
1942
+ }
1859
1943
  });
1860
1944
  return this;
1861
1945
  }
1946
+ __onEvent(event, options, dispose, callback) {
1947
+ if (!callback) return this;
1948
+ this.cache.callbacks[event] = callback;
1949
+ this.__handle(event, this.cache.__controllers__[event], options, dispose);
1950
+ return this;
1951
+ }
1862
1952
  get targetElement(){
1863
1953
  return this.target?.element;
1864
1954
  }
1865
1955
  get isParent(){
1866
- return this.target?.element === this.event.srcElement;
1956
+ return this.target?.element === this.event?.srcElement;
1867
1957
  }
1868
1958
  get item(){
1869
- return this.target.find(n=>n.element == this.event?.srcElement)?.[0];
1959
+ return this.target.find(n => n.element == this.event?.srcElement)?.[0];
1870
1960
  }
1871
1961
  get currentEvent(){
1872
1962
  return this.cache.currentEvent;
@@ -1874,114 +1964,51 @@
1874
1964
  get event(){
1875
1965
  return this.cache.event;
1876
1966
  }
1967
+ get detail(){
1968
+ return this.cache.event.detail
1969
+ }
1877
1970
  setTarget(UI){
1878
- this.target=UI;
1971
+ this.target = UI;
1879
1972
  return this;
1880
1973
  }
1881
- __handle(event, handler, options, dispose){
1974
+ __handle(event, handler, options){
1882
1975
  this.targetElement?.addEventListener(event, handler, options);
1883
1976
  return this;
1884
1977
  }
1885
- __onEvent(event, options, dispose, ...callbacks){
1886
- if(callbacks.length===0){
1887
- console.log("00");
1888
- if(this.cache.callbacks[event]){
1889
- console.log("Call");
1890
- // this.cache.callbacks.map(n=>e=>n.call(this,e));
1891
- this.cache.callbacks[event].map(n=>e=>n.call(this,e));
1892
- }
1893
- else {
1894
- return this;
1895
- }
1896
- }
1897
- else this.cache.callbacks[event] = callbacks.map(n=>e=>n.call(this,e));
1898
- this.__handle(event, this.cache.__controllers__[event],options, dispose);
1899
- return this;
1900
- }
1901
- #override(methode, overrides, defaultValue){
1902
- if(defaultValue === "default") Object.assign(this.cache[methode], {...this.cache[methode], ...overrides});
1903
- const all = defaultValue === "default"
1904
- ? this.cache[methode]
1905
- : Object.fromEntries(Object.keys(this.cache.preventDefault).map(n=>[n,defaultValue]));
1906
- Object.assign(this.cache[methode], {...all,...overrides});
1907
- return this
1908
- }
1909
- preventDefault(overrides = {}, defaultValue = "default"){
1910
- this.#override("preventDefault", overrides, defaultValue);
1911
- // const all=Object.fromEntries(Object.keys(this.cache.preventDefault).map(n=>[n,defaultValue]))
1912
- // Object.assign(this.cache.preventDefault, {...all,...overrides});
1978
+ #override(method, ...events) {
1979
+ const keys = events.length === 0 ? Object.keys(this.cache[method]) : events;
1980
+ keys.forEach(e => {
1981
+ if (this.cache[method].hasOwnProperty(e)) this.cache[method][e] = true;
1982
+ });
1913
1983
  return this;
1914
1984
  }
1915
- stopPropagation(overrides = {}, defaultValue = "default"){
1916
- this.#override("stopPropagation", overrides, defaultValue);
1917
- return this;
1985
+ preventDefault(...events) {
1986
+ return this.#override('preventDefault', ...events);
1918
1987
  }
1919
- stopImmediatePropagation(overrides = {}, defaultValue = "default"){
1920
- this.#override("stopImmediatePropagation", overrides, defaultValue);
1921
- return this;
1988
+ stopPropagation(...events) {
1989
+ return this.#override('stopPropagation', ...events);
1990
+ }
1991
+ stopImmediatePropagation(...events) {
1992
+ return this.#override('stopImmediatePropagation', ...events);
1922
1993
  }
1923
1994
  setEventOptions(event, options){
1924
- this.pause({[event] : true, }, "default");
1925
- Object.assign(this.cache.options[getEvent(event)], options);
1926
- this.resume({[event] : true, }, "default");
1995
+ const evt = getEvent(event);
1996
+ this.pause();
1997
+ Object.assign(this.cache.options[evt], options);
1998
+ this.resume();
1927
1999
  return this;
1928
2000
  }
1929
- pause(overrides = {}, defaultValue = "default"){
1930
- const all = defaultValue === "default"
1931
- ? this.cache.stream.enabled
1932
- : Object.entries(Object.keys(this.cache.stream.enabled).map(n=>[n,defaultValue]));
1933
- overrides={...all,...overrides};
1934
- for(let key in overrides){
1935
- if(overrides[key]){
1936
- this.targetElement?.removeEventListener(key, this.cache.__controllers__[key], this.cache.options[key]);
1937
- this.cache.paused[key]=true;
1938
- }
1939
- }
1940
- return this;
2001
+ pause(...events) {
2002
+ return toggle_event_listener.call(this, 'removeEventListener', ...events)
1941
2003
  }
1942
- resume(overrides = {}, defaultValue = "default"){
1943
- const all = defaultValue === "default"
1944
- ? this.cache.stream.enabled
1945
- : Object.entries(Object.keys(this.cache.stream.enabled).map(n=>[n,defaultValue]));
1946
- overrides={...all,...overrides};
1947
- for(let key in overrides){
1948
- if(overrides[key]){
1949
- this.targetElement?.addEventListener(key,this.cache.__controllers__[key], this.cache.options[key]);
1950
- this.cache.paused[key]=false;
1951
- }
1952
- }
1953
- return this;
1954
- }
1955
- stream(overrides = {}, defaultValue = "default"){
1956
- this.cache.stream.t0=Date.now();
1957
- const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,defaultValue]));
1958
- overrides={...all,...overrides};
1959
- Object.assign(this.cache.stream.enabled,overrides);
1960
- return this;
1961
- }
1962
- clear(){
1963
- return this;
2004
+ resume(...events) {
2005
+ return toggle_event_listener.call(this, 'addEventListener', ...events);
1964
2006
  }
1965
- dispose(overrides = {}, defaultValue = "default"){
1966
- this.pause(overrides, defaultValue);
1967
-
2007
+ dispose(){
2008
+ this.pause();
2009
+ this.target.events[this.cache.signature] = null;
1968
2010
  return this;
1969
2011
  }
1970
- }
1971
-
1972
- function event_controller(e, event_name, details_setter, customizer, push_object){
1973
- this.cache.currentEvent = event_name;
1974
- this.cache.event = e;
1975
- details_setter?.call(this);
1976
- customizer?.hasOwnProperty("prototype") ? customizer?.call(this) : customizer?.call(null, this);
1977
- // if(customizer?.hasOwnProperty("prototype")) customizer?.call(this)
1978
- // else customizer?.call(null, this)
1979
- if(this.cache.preventDefault[event_name]) e.preventDefault();
1980
- if(this.cache.stopPropagation[event_name]) e.stopPropagation();
1981
- if(this.cache.stopImmediatePropagation[event_name]) e.stopImmediatePropagation();
1982
-
1983
- if(this.cache.stream.enabled[event_name]&&push_object)this.cache.stream.history[event_name].push(push_object);
1984
- this.cache.callbacks[event_name]?.map(n=>n(this));
1985
2012
  }
1986
2013
 
1987
2014
  function key_details_setter(){
@@ -1999,38 +2026,137 @@
1999
2026
  }
2000
2027
  }
2001
2028
 
2002
- function ptr_details_setter(){
2003
- switch(this.currentEvent){
2004
- case "pointerdown" : {
2005
- this.dx = parseInt(this.event.offsetX);
2006
- this.dy = parseInt(this.event.offsetY);
2029
+ function ptr_details_setter() {
2030
+ const rect = this.targetElement.getBoundingClientRect();
2031
+ const e = this.event;
2032
+ let x = (e.clientX - rect.left) | 0;
2033
+ let y = (e.clientY - rect.top) | 0;
2034
+
2035
+ if(this.cache.useNormalisedCoordinates){
2036
+ const w = this.targetElement.clientWidth;
2037
+ const h = this.targetElement.clientHeight;
2038
+ x = +((x / w) * 2 - 1).toFixed(8);
2039
+ y = +((y / h) * -2 + 1).toFixed(8);
2040
+ }
2041
+ switch (this.currentEvent) {
2042
+
2043
+ case "pointerdown":
2044
+ this.dx = x;
2045
+ this.dy = y;
2007
2046
  this.isDown = true;
2008
- } break;
2009
- case "pointermove" : {
2010
- this.mx = parseInt(this.event.offsetX);
2011
- this.my = parseInt(this.event.offsetY);
2047
+ break;
2048
+
2049
+ case "pointermove":
2050
+ this.mx = x;
2051
+ this.my = y;
2012
2052
  this.isMoving = true;
2013
- } break;
2014
- case "pointerup" : {
2015
- this.ux = parseInt(this.event.offsetX);
2016
- this.uy = parseInt(this.event.offsetY);
2053
+ break;
2054
+
2055
+ case "pointerup":
2056
+ this.ux = x;
2057
+ this.uy = y;
2017
2058
  this.isDown = false;
2018
- console.log(this.target.width);
2019
- const delta_x=(this.ux-this.dx)/this.target.width;
2020
- const delta_y=(this.dy-this.uy)/this.target.height;
2021
- const HORIZONTAL_SWIPPE=(delta_x<0)?"left":(delta_x>0)?"right":"none";
2022
- const VERTICAL_SWIPPE=(delta_y<0)?"bottom":(delta_y>0)?"top":"none";
2023
- this.swippe={
2024
- h:HORIZONTAL_SWIPPE,
2025
- v:VERTICAL_SWIPPE,
2026
- delta_x,
2027
- delta_y
2028
- };
2029
- } break;
2059
+ this.isMoving = false;
2060
+ break;
2061
+ }
2062
+ }
2063
+
2064
+ function mouse_details_setter() {
2065
+ const rect = this.targetElement.getBoundingClientRect();
2066
+ const e = this.event;
2067
+ let x = (e.clientX - rect.left) | 0;
2068
+ let y = (e.clientY - rect.top) | 0;
2069
+
2070
+ if(this.cache.useNormalisedCoordinates){
2071
+ const w = this.targetElement.clientWidth;
2072
+ const h = this.targetElement.clientHeight;
2073
+ x = +((x / w) * 2 - 1).toFixed(8);
2074
+ y = +((y / h) * -2 + 1).toFixed(8);
2075
+ }
2076
+
2077
+ switch (this.currentEvent) {
2078
+
2079
+ case "mousedown":
2080
+ this.dx = x;
2081
+ this.dy = y;
2082
+ this.isDown = true;
2083
+ break;
2084
+
2085
+ case "mousemove":
2086
+ this.mx = x;
2087
+ this.my = y;
2088
+ this.isMoving = true;
2089
+ break;
2090
+
2091
+ case "mouserup":
2092
+ this.ux = x;
2093
+ this.uy = y;
2094
+ this.isDown = false;
2095
+ this.isMoving = false;
2096
+ break;
2097
+ }
2098
+ }
2099
+
2100
+ function touch_details_setter() {
2101
+ const e = this.event;
2102
+ const touch = e.touches?.[0] || e.changedTouches?.[0];
2103
+
2104
+ if (!touch) return; // should never happen but safe
2105
+
2106
+ const rect = this.targetElement.getBoundingClientRect();
2107
+ let x = touch.clientX - rect.left;
2108
+ let y = touch.clientY - rect.top;
2109
+
2110
+ if(this.cache.useNormalisedCoordinates){
2111
+ const w = this.targetElement.clientWidth;
2112
+ const h = this.targetElement.clientHeight;
2113
+ x = +((x / w) * 2 - 1).toFixed(8);
2114
+ y = +((y / h) * -2 + 1).toFixed(8);
2115
+ }
2116
+
2117
+ switch (this.currentEvent) {
2118
+ case "touchstart":
2119
+ this.dx = x;
2120
+ this.dy = y;
2121
+ this.isDown = true;
2122
+ break;
2123
+
2124
+ case "touchmove":
2125
+ this.mx = x;
2126
+ this.my = y;
2127
+ this.isMoving = true;
2128
+ break;
2129
+
2130
+ case "touchend":
2131
+ this.ux = x;
2132
+ this.uy = y;
2133
+ this.isDown = false;
2134
+ break;
2135
+ }
2136
+ }
2137
+
2138
+ class CoordinatesBasedEvent extends ZikoEvent{
2139
+ constructor(signature, target = null, Events = [], details_setter, customizer){
2140
+ super(signature, target, Events, details_setter, customizer);
2141
+ Object.assign(this.cache,{
2142
+ useNormalisedCoordinates : false
2143
+ });
2144
+ this.isDown = false;
2145
+ this.isMoving = false;
2146
+ this.dx = 0;
2147
+ this.dy = 0;
2148
+ this.mx = 0;
2149
+ this.my = 0;
2150
+ this.ux = 0;
2151
+ this.uy = 0;
2152
+ }
2153
+ get isDragging(){
2154
+ return this.isDown && this.isMoving
2155
+ }
2156
+ useNormalisedCoordinates(enable = true){
2157
+ this.cache.useNormalisedCoordinates = enable;
2158
+ return this;
2030
2159
  }
2031
- // if(this.currentEvent==="click") this.dx = 0
2032
- // else this.dx = 1
2033
- // console.log(this.currentEvent)
2034
2160
  }
2035
2161
 
2036
2162
  class ClickAwayEvent extends Event {
@@ -2068,9 +2194,165 @@
2068
2194
  // // later, you can stop listening:
2069
2195
  // // stop();
2070
2196
 
2197
+ const debounce=(fn,delay=1000)=>{
2198
+ let id;
2199
+ return (...args) => id ? clearTimeout(id) : setTimeout(()=>fn(...args),delay);
2200
+ };
2201
+ const throttle=(fn,delay)=>{
2202
+ let lastTime=0;
2203
+ return (...args) => {
2204
+ const now = new Date().getTime();
2205
+ if(now-lastTime < delay) return;
2206
+ lastTime = now;
2207
+ fn(...args);
2208
+ }
2209
+ };
2210
+
2211
+ class ViewEvent extends CustomEvent {
2212
+ constructor(type, detail, { bubbles = true, cancelable = true } = {}) {
2213
+ super(type, { detail, bubbles, cancelable });
2214
+ }
2215
+ }
2216
+
2217
+ function register_view_event(
2218
+ element,
2219
+ {
2220
+ intersection = true,
2221
+ resize = true,
2222
+ threshold = 0,
2223
+ throttleResize = 100,
2224
+ throttleEnterExit = 0
2225
+ } = {}
2226
+ ) {
2227
+ let intersectionObserver, resizeObserver;
2228
+ const resizeCallback = entries => {
2229
+ for (let entry of entries) {
2230
+ const { width, height } = entry.contentRect;
2231
+
2232
+ element.dispatchEvent(
2233
+ new ViewEvent("resizeview", {
2234
+ width,
2235
+ height,
2236
+ entry
2237
+ })
2238
+ );
2239
+ }
2240
+ };
2241
+
2242
+ const throttledResize = throttleResize > 0
2243
+ ? throttle(resizeCallback, throttleResize)
2244
+ : resizeCallback;
2245
+
2246
+ const intersectionCallback = entries => {
2247
+ for (let entry of entries) {
2248
+ const type = entry.isIntersecting ? "enterview" : "exitview";
2249
+ element.dispatchEvent(new ViewEvent(type, entry));
2250
+ }
2251
+ };
2252
+
2253
+ const throttledIntersections = throttleEnterExit > 0
2254
+ ? throttle(intersectionCallback, throttleEnterExit)
2255
+ : intersectionCallback;
2256
+
2257
+ if (intersection) {
2258
+ intersectionObserver = new IntersectionObserver(throttledIntersections, { threshold });
2259
+ intersectionObserver.observe(element);
2260
+ }
2261
+
2262
+ if (resize) {
2263
+ resizeObserver = new ResizeObserver(throttledResize);
2264
+ resizeObserver.observe(element);
2265
+ }
2266
+
2267
+ // ---- UNREGISTER ----
2268
+ return () => {
2269
+ if (intersectionObserver) {
2270
+ intersectionObserver.unobserve(element);
2271
+ intersectionObserver.disconnect();
2272
+ }
2273
+ if (resizeObserver) {
2274
+ resizeObserver.unobserve(element);
2275
+ resizeObserver.disconnect();
2276
+ }
2277
+ };
2278
+ }
2279
+
2280
+ class SwipeEvent extends CustomEvent {
2281
+ constructor(type, detail) {
2282
+ super(type, {
2283
+ detail,
2284
+ bubbles: true,
2285
+ cancelable: true
2286
+ });
2287
+ }
2288
+ }
2289
+
2290
+ function register_swipe_event(
2291
+ element,
2292
+ threshold = 50,
2293
+ restraint = 100,
2294
+ allowedTime = 500
2295
+ ) {
2296
+ let startX = 0,
2297
+ startY = 0,
2298
+ startTime = 0,
2299
+ isPointerDown = false;
2300
+
2301
+ function onPointerDown(e) {
2302
+ startX = e.clientX;
2303
+ startY = e.clientY;
2304
+ startTime = performance.now();
2305
+ isPointerDown = true;
2306
+ }
2307
+
2308
+ function onPointerUp(e) {
2309
+ if (!isPointerDown) return;
2310
+ isPointerDown = false;
2311
+
2312
+ const distX = e.clientX - startX;
2313
+ const distY = e.clientY - startY;
2314
+ const elapsed = performance.now() - startTime;
2315
+
2316
+ let direction = null;
2317
+ let eventName = null;
2318
+
2319
+ if (elapsed <= allowedTime) {
2320
+ if (Math.abs(distX) >= threshold && Math.abs(distY) <= restraint) {
2321
+ direction = distX < 0 ? "left" : "right";
2322
+ eventName = "swipe" + direction;
2323
+ }
2324
+ else if (Math.abs(distY) >= threshold && Math.abs(distX) <= restraint) {
2325
+ direction = distY < 0 ? "up" : "down";
2326
+ eventName = "swipe" + direction;
2327
+ }
2328
+ }
2329
+
2330
+ // Emit event
2331
+ if (eventName) {
2332
+ element.dispatchEvent(
2333
+ new SwipeEvent(eventName, {
2334
+ direction,
2335
+ distX,
2336
+ distY,
2337
+ originalEvent: e
2338
+ })
2339
+ );
2340
+ }
2341
+ }
2342
+
2343
+ element.addEventListener("pointerdown", onPointerDown, { passive: true });
2344
+ element.addEventListener("pointerup", onPointerUp, { passive: true });
2345
+
2346
+ return () => {
2347
+ element.removeEventListener("pointerdown", onPointerDown);
2348
+ element.removeEventListener("pointerup", onPointerUp);
2349
+ };
2350
+ }
2351
+
2071
2352
  const bind_click_event = (target, customizer) => {
2072
2353
  register_click_away_event(target.element);
2073
2354
  return new ZikoEvent(
2355
+ 'click',
2074
2356
  target,
2075
2357
  EventsMap.Click,
2076
2358
  null,
@@ -2078,64 +2360,87 @@
2078
2360
  );
2079
2361
  };
2080
2362
  const bind_clipboard_event = (target, customizer) => new ZikoEvent(
2363
+ 'clipboard',
2081
2364
  target,
2082
2365
  EventsMap.Clipboard,
2083
2366
  null,
2084
2367
  customizer
2085
2368
  );
2086
2369
  const bind_drag_event = (target, customizer) => new ZikoEvent(
2370
+ 'drag',
2087
2371
  target,
2088
2372
  EventsMap.Drag,
2089
2373
  null,
2090
2374
  customizer
2091
2375
  );
2092
2376
  const bind_focus_event = (target, customizer) => new ZikoEvent(
2377
+ 'focus',
2093
2378
  target,
2094
2379
  EventsMap.Focus,
2095
2380
  null,
2096
2381
  customizer
2097
2382
  );
2098
2383
  const bind_key_event = (target, customizer) => new ZikoEvent(
2384
+ 'key',
2099
2385
  target,
2100
2386
  EventsMap.Key,
2101
2387
  key_details_setter,
2102
2388
  customizer
2103
2389
  );
2104
- const bind_mouse_event = (target, customizer) => new ZikoEvent(
2390
+ const bind_mouse_event = (target, customizer) => new CoordinatesBasedEvent(
2391
+ 'mouse',
2105
2392
  target,
2106
2393
  EventsMap.Mouse,
2107
- null,
2394
+ mouse_details_setter,
2108
2395
  customizer
2109
2396
  );
2110
- const bind_pointer_event = (target, customizer) => new ZikoEvent(
2397
+ const bind_pointer_event = (target, customizer) => new CoordinatesBasedEvent(
2398
+ 'ptr',
2111
2399
  target,
2112
2400
  EventsMap.Ptr,
2113
2401
  ptr_details_setter,
2114
2402
  customizer
2115
2403
  );
2116
- const bind_touch_event = (target, customizer) => new ZikoEvent(
2404
+ const bind_touch_event = (target, customizer) => new CoordinatesBasedEvent(
2405
+ 'touch',
2117
2406
  target,
2118
2407
  EventsMap.Touch,
2119
- null,
2408
+ touch_details_setter,
2120
2409
  customizer
2121
2410
  );
2122
2411
  const bind_wheel_event = (target, customizer) => new ZikoEvent(
2412
+ 'wheel',
2123
2413
  target,
2124
2414
  EventsMap.Wheel,
2125
2415
  null,
2126
2416
  customizer
2127
2417
  );
2128
2418
 
2419
+ const bind_view_event = (target, customizer) => {
2420
+ register_view_event(target.element);
2421
+ return new ZikoEvent(
2422
+ 'view',
2423
+ target,
2424
+ EventsMap.View,
2425
+ null,
2426
+ customizer
2427
+ )
2428
+ };
2129
2429
 
2130
- // function details_setter(){
2131
- // if(this.currentEvent==="click") this.dx = 0
2132
- // else this.dx = 1
2133
- // // console.log(this.currentEvent)
2134
- // }
2430
+ const bind_swipe_event = (target, customizer) => {
2431
+ register_swipe_event(target.element);
2432
+ return new ZikoEvent(
2433
+ 'swipe',
2434
+ target,
2435
+ EventsMap.Swipe,
2436
+ null,
2437
+ customizer
2438
+ )
2439
+ };
2135
2440
 
2136
2441
  class ZikoCustomEvent extends ZikoEvent{
2137
2442
  constructor(target, events, customizer){
2138
- super(target, events, details_setter, customizer);
2443
+ super('custom', target, events, details_setter, customizer);
2139
2444
  }
2140
2445
  _register_events(events){
2141
2446
  super._register_events(events, null, null, false);
@@ -2169,7 +2474,9 @@
2169
2474
  drag : bind_drag_event,
2170
2475
  clipboard : bind_clipboard_event,
2171
2476
  focus : bind_focus_event,
2172
- wheel : bind_wheel_event
2477
+ wheel : bind_wheel_event,
2478
+ view : bind_view_event,
2479
+ swipe : bind_swipe_event
2173
2480
  };
2174
2481
 
2175
2482
  const EventsMethodes = {
@@ -2189,9 +2496,9 @@
2189
2496
  const lname = name.toLowerCase();
2190
2497
  eventList.forEach(event => {
2191
2498
  const methodName = `on${event}`;
2192
- EventsMethodes[methodName] = function (...callbacks) {
2499
+ EventsMethodes[methodName] = function (callbacks) {
2193
2500
  if (!this.events[lname]) this.events[lname] = binderMap[lname](this);
2194
- this.events[lname][methodName](...callbacks);
2501
+ this.events[lname][methodName](callbacks);
2195
2502
  return this;
2196
2503
  };
2197
2504
  });
@@ -2268,6 +2575,7 @@
2268
2575
  // console.log(this)
2269
2576
  register_to_class(
2270
2577
  this,
2578
+ LifecycleMethods,
2271
2579
  AttrsMethods,
2272
2580
  DomMethods,
2273
2581
  StyleMethods,
@@ -2397,32 +2705,12 @@
2397
2705
  // get id() {
2398
2706
  // return this.element.getAttribute("id");
2399
2707
  // }
2400
- // onSwipe(width_threshold, height_threshold,...callbacks){
2401
- // if(!this.events.swipe)this.events.swipe = useSwipeEvent(this, width_threshold, height_threshold);
2402
- // this.events.swipe.onSwipe(...callbacks);
2403
- // return this;
2404
- // }
2405
2708
  // To Fix
2406
2709
  // onKeysDown({keys=[],callback}={}){
2407
2710
  // if(!this.events.key)this.events.key = useKeyEvent(this);
2408
2711
  // this.events.key.handleSuccessifKeys({keys,callback});
2409
2712
  // return this;
2410
2713
  // }
2411
- // onSelect(...callbacks){
2412
- // if(!this.events.clipboard)this.events.clipboard = useClipboardEvent(this);
2413
- // this.events.clipboard.onSelect(...callbacks);
2414
- // return this;
2415
- // }
2416
- // on(event_name,...callbacks){
2417
- // if(!this.events.custom)this.events.custom = useCustomEvent(this);
2418
- // this.events.custom.on(event_name,...callbacks);
2419
- // return this;
2420
- // }
2421
- // emit(event_name,detail={}){
2422
- // if(!this.events.custom)this.events.custom = useCustomEvent(this);
2423
- // this.events.custom.emit(event_name,detail);
2424
- // return this;
2425
- // }
2426
2714
  // watchAttr(callback){
2427
2715
  // if(!this.observer.attr)this.observer.attr = watchAttr(this,callback);
2428
2716
  // return this;
@@ -2431,16 +2719,8 @@
2431
2719
  // if(!this.observer.children)this.observer.children = watchChildren(this,callback);
2432
2720
  // return this;
2433
2721
  // }
2434
- // watchSize(callback){
2435
- // if(!this.observer.resize)this.observer.resize = watchSize(this,callback);
2436
- // this.observer.resize.start();
2437
- // return this;
2438
- // }
2439
- // watchIntersection(callback,config){
2440
- // if(!this.observer.intersection)this.observer.intersection = watchIntersection(this,callback,config);
2441
- // this.observer.intersection.start();
2442
- // return this;
2443
- // }
2722
+ // watchSize(callback)Remplaced By on onViewResize
2723
+ // watchIntersection(callback,config) Remplaced By onViewEnter and onViewExit
2444
2724
 
2445
2725
  };
2446
2726
 
@@ -2739,7 +3019,6 @@
2739
3019
  const ui = await callback();
2740
3020
  fallback_ui.unmount();
2741
3021
  this.append(ui);
2742
- // console.log(content)
2743
3022
  }
2744
3023
  catch(error){
2745
3024
  console.log({error});
@@ -4370,20 +4649,6 @@
4370
4649
 
4371
4650
  const step_fps = (step_or_fps) => 1000 / step_or_fps;
4372
4651
 
4373
- const debounce=(fn,delay=1000)=>{
4374
- let id;
4375
- return (...args) => id ? clearTimeout(id) : setTimeout(()=>fn(...args),delay);
4376
- };
4377
- const throttle=(fn,delay)=>{
4378
- let lastTime=0;
4379
- return (...args) => {
4380
- const now = new Date().getTime();
4381
- if(now-lastTime < delay) return;
4382
- lastTime = now;
4383
- fn(...args);
4384
- }
4385
- };
4386
-
4387
4652
  const sleep= ms => new Promise(res => setTimeout(res, ms));
4388
4653
  function timeout(ms, fn) {
4389
4654
  let id;
@@ -5221,7 +5486,9 @@
5221
5486
  exports.bind_key_event = bind_key_event;
5222
5487
  exports.bind_mouse_event = bind_mouse_event;
5223
5488
  exports.bind_pointer_event = bind_pointer_event;
5489
+ exports.bind_swipe_event = bind_swipe_event;
5224
5490
  exports.bind_touch_event = bind_touch_event;
5491
+ exports.bind_view_event = bind_view_event;
5225
5492
  exports.bind_wheel_event = bind_wheel_event;
5226
5493
  exports.cartesianProduct = cartesianProduct;
5227
5494
  exports.ceil = ceil;
@@ -5247,6 +5514,7 @@
5247
5514
  exports.div = div;
5248
5515
  exports.e = e;
5249
5516
  exports.elastic = elastic;
5517
+ exports.event_controller = event_controller;
5250
5518
  exports.fact = fact;
5251
5519
  exports.floor = floor;
5252
5520
  exports.geomspace = geomspace;
@@ -5348,6 +5616,7 @@
5348
5616
  exports.timeTaken = timeTaken;
5349
5617
  exports.time_memory_Taken = time_memory_Taken;
5350
5618
  exports.timeout = timeout;
5619
+ exports.toggle_event_listener = toggle_event_listener;
5351
5620
  exports.useDerived = useDerived;
5352
5621
  exports.useEventEmitter = useEventEmitter;
5353
5622
  exports.useIPC = useIPC;