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.mjs 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
@@ -943,16 +943,28 @@ const preload=(url)=>{
943
943
  }
944
944
  };
945
945
 
946
- async function fetchdom(url='https://github.com/zakarialaoui10'){
947
- const data=await fetch(url);
948
- const html=await data.text();
949
- const dom= new DOMParser().parseFromString(html,'text/xml');
950
- return dom.documentElement
946
+ async function fetchdom(url='https://github.com/zakarialaoui10') {
947
+ try {
948
+ const response = await fetch(url);
949
+ if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
950
+ const html = await response.text();
951
+ const dom = new DOMParser().parseFromString(html, 'text/html');
952
+ return dom.documentElement;
953
+ } catch (err) {
954
+ console.error('Failed to fetch DOM:', err);
955
+ throw err;
956
+ }
951
957
  }
952
- function fetchdomSync(url='https://github.com/zakarialaoui10'){
953
- const data=preload(url);
954
- const dom= new DOMParser().parseFromString(data,'text/xml');
955
- return dom.documentElement;
958
+
959
+ function fetchdomSync(url='https://github.com/zakarialaoui10') {
960
+ try {
961
+ const data = preload(url);
962
+ const dom = new DOMParser().parseFromString(data, 'text/html');
963
+ return dom.documentElement;
964
+ } catch (err) {
965
+ console.error('Failed to fetch DOM synchronously:', err);
966
+ throw err;
967
+ }
956
968
  }
957
969
 
958
970
  globalThis.fetchdom=fetchdom;
@@ -1211,6 +1223,67 @@ function _register_to_class_(target, mixin) {
1211
1223
  }
1212
1224
  }
1213
1225
 
1226
+ // export function mount(target = this.target) {
1227
+ // if(this.isBody) return ;
1228
+ // if(target?.isUIElement)target=target.element;
1229
+ // this.target=target;
1230
+ // this.target?.appendChild(this.element);
1231
+ // return this;
1232
+ // }
1233
+ // export function unmount(){
1234
+ // if(this.cache.parent)this.cache.parent.remove(this);
1235
+ // else if(this.target?.children?.length && [...this.target?.children].includes(this.element)) this.target.removeChild(this.element);
1236
+ // return this;
1237
+ // }
1238
+
1239
+ // export function mountAfter(target = this.target, t = 1) {
1240
+ // setTimeout(() => this.mount(), t);
1241
+ // return this;
1242
+ // }
1243
+ // export function unmountAfter(t = 1) {
1244
+ // setTimeout(() => this.unmount(), t);
1245
+ // return this;
1246
+ // }
1247
+
1248
+ function mount(target = this.target, delay = 0) {
1249
+ if (delay > 0) {
1250
+ setTimeout(() => this.mount(target, 0), delay);
1251
+ return this;
1252
+ }
1253
+
1254
+ if (this.isBody) return this;
1255
+
1256
+ if (target?.isUIElement) target = target.element;
1257
+ this.target = target;
1258
+
1259
+ this.target?.appendChild(this.element);
1260
+ return this;
1261
+ }
1262
+
1263
+ function unmount(delay = 0) {
1264
+ if (delay > 0) {
1265
+ setTimeout(() => this.unmount(0), delay);
1266
+ return this;
1267
+ }
1268
+
1269
+ if (this.cache.parent) {
1270
+ this.cache.parent.remove(this);
1271
+ } else if (
1272
+ this.target?.children?.length &&
1273
+ [...this.target.children].includes(this.element)
1274
+ ) {
1275
+ this.target.removeChild(this.element);
1276
+ }
1277
+
1278
+ return this;
1279
+ }
1280
+
1281
+ var LifecycleMethods = /*#__PURE__*/Object.freeze({
1282
+ __proto__: null,
1283
+ mount: mount,
1284
+ unmount: unmount
1285
+ });
1286
+
1214
1287
  function parseQueryParams$1(queryString) {
1215
1288
  const params = {};
1216
1289
  queryString.replace(/[A-Z0-9]+?=([\w|:|\/\.]*)/gi, (match) => {
@@ -1699,18 +1772,6 @@ function clear(){
1699
1772
  this.element.innerHTML = "";
1700
1773
  return this;
1701
1774
  }
1702
- function mount(target = this.target) {
1703
- if(this.isBody)return ;
1704
- if(target?.isUIElement)target=target.element;
1705
- this.target=target;
1706
- this.target?.appendChild(this.element);
1707
- return this;
1708
- }
1709
- function unmount(){
1710
- if(this.cache.parent)this.cache.parent.remove(this);
1711
- else if(this.target?.children?.length && [...this.target?.children].includes(this.element)) this.target.removeChild(this.element);
1712
- return this;
1713
- }
1714
1775
  function replaceElementWith(new_element){
1715
1776
  this.cache.element.replaceWith(new_element);
1716
1777
  this.cache.element = new_element;
@@ -1718,14 +1779,6 @@ function replaceElementWith(new_element){
1718
1779
  // To do : Dispose Events and States
1719
1780
  return this
1720
1781
  }
1721
- function renderAfter(t = 1) {
1722
- setTimeout(() => this.mount(), t);
1723
- return this;
1724
- }
1725
- function unrenderAfter(t = 1) {
1726
- setTimeout(() => this.unmount(), t);
1727
- return this;
1728
- }
1729
1782
  function after(ui){
1730
1783
  if(ui?.isUIElement) ui=ui.element;
1731
1784
  this.element?.after(ui);
@@ -1744,20 +1797,12 @@ var DomMethods = /*#__PURE__*/Object.freeze({
1744
1797
  before: before,
1745
1798
  clear: clear,
1746
1799
  insertAt: insertAt,
1747
- mount: mount,
1748
1800
  prepend: prepend,
1749
1801
  remove: remove,
1750
- renderAfter: renderAfter,
1751
- replaceElementWith: replaceElementWith,
1752
- unmount: unmount,
1753
- unrenderAfter: unrenderAfter
1802
+ replaceElementWith: replaceElementWith
1754
1803
  });
1755
1804
 
1756
1805
  const EventsMap = {
1757
- 'Custom' : [
1758
- 'emit',
1759
- 'on'
1760
- ],
1761
1806
  'Click' : [
1762
1807
  'Click',
1763
1808
  'DblClick',
@@ -1803,64 +1848,109 @@ const EventsMap = {
1803
1848
  ],
1804
1849
  'Wheel': [
1805
1850
  'Wheel'
1806
- ]
1851
+ ],
1807
1852
  // 'Media':[
1808
1853
 
1809
1854
  // ],
1810
1855
  // 'Hash':[
1811
1856
  // "HashChange"
1812
1857
  // ]
1858
+
1859
+ 'View':[
1860
+ 'EnterView',
1861
+ 'ExitView',
1862
+ 'ResizeView'
1863
+ ],
1864
+ 'Swipe':[
1865
+ 'SwipeLeft',
1866
+ 'SwipeUp',
1867
+ 'SwipeRight',
1868
+ 'SwipeDown'
1869
+ ]
1813
1870
  };
1814
1871
 
1872
+ function event_controller(e, event_name, details_setter, customizer) {
1873
+ this.cache.currentEvent = event_name;
1874
+ this.cache.event = e;
1875
+
1876
+ details_setter?.call(this);
1877
+ if (customizer?.hasOwnProperty('prototype')) customizer?.call(this);
1878
+ else customizer?.call(null, this);
1879
+
1880
+ if (this.cache.preventDefault[event_name]) e.preventDefault();
1881
+ if (this.cache.stopPropagation[event_name]) e.stopPropagation();
1882
+ if (this.cache.stopImmediatePropagation[event_name]) e.stopImmediatePropagation();
1883
+
1884
+ // Call the single callback if it exists
1885
+ this.cache.callbacks[event_name]?.(this);
1886
+ }
1887
+
1888
+ function toggle_event_listener(method, ...events) {
1889
+ const keys = events.length === 0
1890
+ ? Object.keys(this.cache.paused)
1891
+ : events;
1892
+ keys.forEach(key => {
1893
+ if (!this.cache.paused.hasOwnProperty(key)) return;
1894
+ this.targetElement?.[method](
1895
+ key,
1896
+ this.cache.__controllers__[key],
1897
+ this.cache.options[key]
1898
+ );
1899
+ this.cache.paused[key] = method === 'removeEventListener';
1900
+ });
1901
+ return this;
1902
+ }
1815
1903
  const getEvent=(event = "")=>{
1816
1904
  if(event.startsWith("Ptr"))return `pointer${event.split("Ptr")[1].toLowerCase()}`;
1817
1905
  return event.toLowerCase()
1818
1906
  };
1819
1907
 
1820
1908
  class ZikoEvent {
1821
- constructor(target = null, Events = [], details_setter, customizer){
1909
+ constructor(signature, target = null, Events = [], details_setter, customizer){
1822
1910
  this.target = target;
1823
1911
  this.cache = {
1912
+ signature,
1824
1913
  currentEvent : null,
1825
1914
  event: null,
1826
1915
  options : {},
1827
1916
  preventDefault : {},
1828
1917
  stopPropagation : {},
1829
1918
  stopImmediatePropagation : {},
1830
- event_flow : {},
1831
1919
  paused : {},
1832
- stream : {
1833
- enabled : {},
1834
- clear : {},
1835
- history : {}
1836
- },
1837
1920
  callbacks : {},
1838
1921
  __controllers__:{}
1839
1922
  };
1840
- if(Events)this._register_events(Events, details_setter, customizer);
1841
- }
1842
- _register_events(Events, details_setter, customizer, REGISTER_METHODES = true){
1843
- const events = Events?.map(n=>getEvent(n));
1844
- events?.forEach((event,i)=>{
1845
- Object.assign(this.cache.preventDefault, {[event] : false});
1846
- Object.assign(this.cache.options, {[event] : {}});
1847
- Object.assign(this.cache.paused, {[event] : false});
1848
- Object.assign(this.cache.stream.enabled, {[event] : false});
1849
- Object.assign(this.cache.stream.clear, {[event] : false});
1850
- Object.assign(this.cache.stream.history, {[event] : []});
1851
- Object.assign(this.cache.__controllers__, {[event] : e=>event_controller.call(this, e, event, details_setter, customizer)});
1852
- if(REGISTER_METHODES)Object.assign(this, { [`on${Events[i]}`] : (...callbacks)=> this.__onEvent(event, this.cache.options[event], {}, ...callbacks)});
1923
+ if (Events) this._register_events(Events, details_setter, customizer);
1924
+ }
1925
+ _register_events(Events, details_setter, customizer, REGISTER_METHODES = true) {
1926
+ const events = Events?.map(n => getEvent(n));
1927
+ events?.forEach((event, i) => {
1928
+ this.cache.preventDefault[event] = false;
1929
+ this.cache.options[event] = {};
1930
+ this.cache.paused[event] = false;
1931
+ this.cache.__controllers__[event] = (e) =>
1932
+ event_controller.call(this, e, event, details_setter, customizer);
1933
+ if (REGISTER_METHODES) {
1934
+ this[`on${Events[i]}`] = (callback) =>
1935
+ this.__onEvent(event, this.cache.options[event], {}, callback);
1936
+ }
1853
1937
  });
1854
1938
  return this;
1855
1939
  }
1940
+ __onEvent(event, options, dispose, callback) {
1941
+ if (!callback) return this;
1942
+ this.cache.callbacks[event] = callback;
1943
+ this.__handle(event, this.cache.__controllers__[event], options, dispose);
1944
+ return this;
1945
+ }
1856
1946
  get targetElement(){
1857
1947
  return this.target?.element;
1858
1948
  }
1859
1949
  get isParent(){
1860
- return this.target?.element === this.event.srcElement;
1950
+ return this.target?.element === this.event?.srcElement;
1861
1951
  }
1862
1952
  get item(){
1863
- return this.target.find(n=>n.element == this.event?.srcElement)?.[0];
1953
+ return this.target.find(n => n.element == this.event?.srcElement)?.[0];
1864
1954
  }
1865
1955
  get currentEvent(){
1866
1956
  return this.cache.currentEvent;
@@ -1868,114 +1958,51 @@ class ZikoEvent {
1868
1958
  get event(){
1869
1959
  return this.cache.event;
1870
1960
  }
1961
+ get detail(){
1962
+ return this.cache.event.detail
1963
+ }
1871
1964
  setTarget(UI){
1872
- this.target=UI;
1965
+ this.target = UI;
1873
1966
  return this;
1874
1967
  }
1875
- __handle(event, handler, options, dispose){
1968
+ __handle(event, handler, options){
1876
1969
  this.targetElement?.addEventListener(event, handler, options);
1877
1970
  return this;
1878
1971
  }
1879
- __onEvent(event, options, dispose, ...callbacks){
1880
- if(callbacks.length===0){
1881
- console.log("00");
1882
- if(this.cache.callbacks[event]){
1883
- console.log("Call");
1884
- // this.cache.callbacks.map(n=>e=>n.call(this,e));
1885
- this.cache.callbacks[event].map(n=>e=>n.call(this,e));
1886
- }
1887
- else {
1888
- return this;
1889
- }
1890
- }
1891
- else this.cache.callbacks[event] = callbacks.map(n=>e=>n.call(this,e));
1892
- this.__handle(event, this.cache.__controllers__[event],options, dispose);
1893
- return this;
1894
- }
1895
- #override(methode, overrides, defaultValue){
1896
- if(defaultValue === "default") Object.assign(this.cache[methode], {...this.cache[methode], ...overrides});
1897
- const all = defaultValue === "default"
1898
- ? this.cache[methode]
1899
- : Object.fromEntries(Object.keys(this.cache.preventDefault).map(n=>[n,defaultValue]));
1900
- Object.assign(this.cache[methode], {...all,...overrides});
1901
- return this
1902
- }
1903
- preventDefault(overrides = {}, defaultValue = "default"){
1904
- this.#override("preventDefault", overrides, defaultValue);
1905
- // const all=Object.fromEntries(Object.keys(this.cache.preventDefault).map(n=>[n,defaultValue]))
1906
- // Object.assign(this.cache.preventDefault, {...all,...overrides});
1972
+ #override(method, ...events) {
1973
+ const keys = events.length === 0 ? Object.keys(this.cache[method]) : events;
1974
+ keys.forEach(e => {
1975
+ if (this.cache[method].hasOwnProperty(e)) this.cache[method][e] = true;
1976
+ });
1907
1977
  return this;
1908
1978
  }
1909
- stopPropagation(overrides = {}, defaultValue = "default"){
1910
- this.#override("stopPropagation", overrides, defaultValue);
1911
- return this;
1979
+ preventDefault(...events) {
1980
+ return this.#override('preventDefault', ...events);
1912
1981
  }
1913
- stopImmediatePropagation(overrides = {}, defaultValue = "default"){
1914
- this.#override("stopImmediatePropagation", overrides, defaultValue);
1915
- return this;
1982
+ stopPropagation(...events) {
1983
+ return this.#override('stopPropagation', ...events);
1984
+ }
1985
+ stopImmediatePropagation(...events) {
1986
+ return this.#override('stopImmediatePropagation', ...events);
1916
1987
  }
1917
1988
  setEventOptions(event, options){
1918
- this.pause({[event] : true, }, "default");
1919
- Object.assign(this.cache.options[getEvent(event)], options);
1920
- this.resume({[event] : true, }, "default");
1989
+ const evt = getEvent(event);
1990
+ this.pause();
1991
+ Object.assign(this.cache.options[evt], options);
1992
+ this.resume();
1921
1993
  return this;
1922
1994
  }
1923
- pause(overrides = {}, defaultValue = "default"){
1924
- const all = defaultValue === "default"
1925
- ? this.cache.stream.enabled
1926
- : Object.entries(Object.keys(this.cache.stream.enabled).map(n=>[n,defaultValue]));
1927
- overrides={...all,...overrides};
1928
- for(let key in overrides){
1929
- if(overrides[key]){
1930
- this.targetElement?.removeEventListener(key, this.cache.__controllers__[key], this.cache.options[key]);
1931
- this.cache.paused[key]=true;
1932
- }
1933
- }
1934
- return this;
1995
+ pause(...events) {
1996
+ return toggle_event_listener.call(this, 'removeEventListener', ...events)
1935
1997
  }
1936
- resume(overrides = {}, defaultValue = "default"){
1937
- const all = defaultValue === "default"
1938
- ? this.cache.stream.enabled
1939
- : Object.entries(Object.keys(this.cache.stream.enabled).map(n=>[n,defaultValue]));
1940
- overrides={...all,...overrides};
1941
- for(let key in overrides){
1942
- if(overrides[key]){
1943
- this.targetElement?.addEventListener(key,this.cache.__controllers__[key], this.cache.options[key]);
1944
- this.cache.paused[key]=false;
1945
- }
1946
- }
1947
- return this;
1948
- }
1949
- stream(overrides = {}, defaultValue = "default"){
1950
- this.cache.stream.t0=Date.now();
1951
- const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,defaultValue]));
1952
- overrides={...all,...overrides};
1953
- Object.assign(this.cache.stream.enabled,overrides);
1954
- return this;
1955
- }
1956
- clear(){
1957
- return this;
1998
+ resume(...events) {
1999
+ return toggle_event_listener.call(this, 'addEventListener', ...events);
1958
2000
  }
1959
- dispose(overrides = {}, defaultValue = "default"){
1960
- this.pause(overrides, defaultValue);
1961
-
2001
+ dispose(){
2002
+ this.pause();
2003
+ this.target.events[this.cache.signature] = null;
1962
2004
  return this;
1963
2005
  }
1964
- }
1965
-
1966
- function event_controller(e, event_name, details_setter, customizer, push_object){
1967
- this.cache.currentEvent = event_name;
1968
- this.cache.event = e;
1969
- details_setter?.call(this);
1970
- customizer?.hasOwnProperty("prototype") ? customizer?.call(this) : customizer?.call(null, this);
1971
- // if(customizer?.hasOwnProperty("prototype")) customizer?.call(this)
1972
- // else customizer?.call(null, this)
1973
- if(this.cache.preventDefault[event_name]) e.preventDefault();
1974
- if(this.cache.stopPropagation[event_name]) e.stopPropagation();
1975
- if(this.cache.stopImmediatePropagation[event_name]) e.stopImmediatePropagation();
1976
-
1977
- if(this.cache.stream.enabled[event_name]&&push_object)this.cache.stream.history[event_name].push(push_object);
1978
- this.cache.callbacks[event_name]?.map(n=>n(this));
1979
2006
  }
1980
2007
 
1981
2008
  function key_details_setter(){
@@ -1993,38 +2020,137 @@ function key_details_setter(){
1993
2020
  }
1994
2021
  }
1995
2022
 
1996
- function ptr_details_setter(){
1997
- switch(this.currentEvent){
1998
- case "pointerdown" : {
1999
- this.dx = parseInt(this.event.offsetX);
2000
- this.dy = parseInt(this.event.offsetY);
2023
+ function ptr_details_setter() {
2024
+ const rect = this.targetElement.getBoundingClientRect();
2025
+ const e = this.event;
2026
+ let x = (e.clientX - rect.left) | 0;
2027
+ let y = (e.clientY - rect.top) | 0;
2028
+
2029
+ if(this.cache.useNormalisedCoordinates){
2030
+ const w = this.targetElement.clientWidth;
2031
+ const h = this.targetElement.clientHeight;
2032
+ x = +((x / w) * 2 - 1).toFixed(8);
2033
+ y = +((y / h) * -2 + 1).toFixed(8);
2034
+ }
2035
+ switch (this.currentEvent) {
2036
+
2037
+ case "pointerdown":
2038
+ this.dx = x;
2039
+ this.dy = y;
2001
2040
  this.isDown = true;
2002
- } break;
2003
- case "pointermove" : {
2004
- this.mx = parseInt(this.event.offsetX);
2005
- this.my = parseInt(this.event.offsetY);
2041
+ break;
2042
+
2043
+ case "pointermove":
2044
+ this.mx = x;
2045
+ this.my = y;
2006
2046
  this.isMoving = true;
2007
- } break;
2008
- case "pointerup" : {
2009
- this.ux = parseInt(this.event.offsetX);
2010
- this.uy = parseInt(this.event.offsetY);
2047
+ break;
2048
+
2049
+ case "pointerup":
2050
+ this.ux = x;
2051
+ this.uy = y;
2011
2052
  this.isDown = false;
2012
- console.log(this.target.width);
2013
- const delta_x=(this.ux-this.dx)/this.target.width;
2014
- const delta_y=(this.dy-this.uy)/this.target.height;
2015
- const HORIZONTAL_SWIPPE=(delta_x<0)?"left":(delta_x>0)?"right":"none";
2016
- const VERTICAL_SWIPPE=(delta_y<0)?"bottom":(delta_y>0)?"top":"none";
2017
- this.swippe={
2018
- h:HORIZONTAL_SWIPPE,
2019
- v:VERTICAL_SWIPPE,
2020
- delta_x,
2021
- delta_y
2022
- };
2023
- } break;
2053
+ this.isMoving = false;
2054
+ break;
2055
+ }
2056
+ }
2057
+
2058
+ function mouse_details_setter() {
2059
+ const rect = this.targetElement.getBoundingClientRect();
2060
+ const e = this.event;
2061
+ let x = (e.clientX - rect.left) | 0;
2062
+ let y = (e.clientY - rect.top) | 0;
2063
+
2064
+ if(this.cache.useNormalisedCoordinates){
2065
+ const w = this.targetElement.clientWidth;
2066
+ const h = this.targetElement.clientHeight;
2067
+ x = +((x / w) * 2 - 1).toFixed(8);
2068
+ y = +((y / h) * -2 + 1).toFixed(8);
2069
+ }
2070
+
2071
+ switch (this.currentEvent) {
2072
+
2073
+ case "mousedown":
2074
+ this.dx = x;
2075
+ this.dy = y;
2076
+ this.isDown = true;
2077
+ break;
2078
+
2079
+ case "mousemove":
2080
+ this.mx = x;
2081
+ this.my = y;
2082
+ this.isMoving = true;
2083
+ break;
2084
+
2085
+ case "mouserup":
2086
+ this.ux = x;
2087
+ this.uy = y;
2088
+ this.isDown = false;
2089
+ this.isMoving = false;
2090
+ break;
2091
+ }
2092
+ }
2093
+
2094
+ function touch_details_setter() {
2095
+ const e = this.event;
2096
+ const touch = e.touches?.[0] || e.changedTouches?.[0];
2097
+
2098
+ if (!touch) return; // should never happen but safe
2099
+
2100
+ const rect = this.targetElement.getBoundingClientRect();
2101
+ let x = touch.clientX - rect.left;
2102
+ let y = touch.clientY - rect.top;
2103
+
2104
+ if(this.cache.useNormalisedCoordinates){
2105
+ const w = this.targetElement.clientWidth;
2106
+ const h = this.targetElement.clientHeight;
2107
+ x = +((x / w) * 2 - 1).toFixed(8);
2108
+ y = +((y / h) * -2 + 1).toFixed(8);
2109
+ }
2110
+
2111
+ switch (this.currentEvent) {
2112
+ case "touchstart":
2113
+ this.dx = x;
2114
+ this.dy = y;
2115
+ this.isDown = true;
2116
+ break;
2117
+
2118
+ case "touchmove":
2119
+ this.mx = x;
2120
+ this.my = y;
2121
+ this.isMoving = true;
2122
+ break;
2123
+
2124
+ case "touchend":
2125
+ this.ux = x;
2126
+ this.uy = y;
2127
+ this.isDown = false;
2128
+ break;
2129
+ }
2130
+ }
2131
+
2132
+ class CoordinatesBasedEvent extends ZikoEvent{
2133
+ constructor(signature, target = null, Events = [], details_setter, customizer){
2134
+ super(signature, target, Events, details_setter, customizer);
2135
+ Object.assign(this.cache,{
2136
+ useNormalisedCoordinates : false
2137
+ });
2138
+ this.isDown = false;
2139
+ this.isMoving = false;
2140
+ this.dx = 0;
2141
+ this.dy = 0;
2142
+ this.mx = 0;
2143
+ this.my = 0;
2144
+ this.ux = 0;
2145
+ this.uy = 0;
2146
+ }
2147
+ get isDragging(){
2148
+ return this.isDown && this.isMoving
2149
+ }
2150
+ useNormalisedCoordinates(enable = true){
2151
+ this.cache.useNormalisedCoordinates = enable;
2152
+ return this;
2024
2153
  }
2025
- // if(this.currentEvent==="click") this.dx = 0
2026
- // else this.dx = 1
2027
- // console.log(this.currentEvent)
2028
2154
  }
2029
2155
 
2030
2156
  class ClickAwayEvent extends Event {
@@ -2062,9 +2188,165 @@ function register_click_away_event(element) {
2062
2188
  // // later, you can stop listening:
2063
2189
  // // stop();
2064
2190
 
2191
+ const debounce=(fn,delay=1000)=>{
2192
+ let id;
2193
+ return (...args) => id ? clearTimeout(id) : setTimeout(()=>fn(...args),delay);
2194
+ };
2195
+ const throttle=(fn,delay)=>{
2196
+ let lastTime=0;
2197
+ return (...args) => {
2198
+ const now = new Date().getTime();
2199
+ if(now-lastTime < delay) return;
2200
+ lastTime = now;
2201
+ fn(...args);
2202
+ }
2203
+ };
2204
+
2205
+ class ViewEvent extends CustomEvent {
2206
+ constructor(type, detail, { bubbles = true, cancelable = true } = {}) {
2207
+ super(type, { detail, bubbles, cancelable });
2208
+ }
2209
+ }
2210
+
2211
+ function register_view_event(
2212
+ element,
2213
+ {
2214
+ intersection = true,
2215
+ resize = true,
2216
+ threshold = 0,
2217
+ throttleResize = 100,
2218
+ throttleEnterExit = 0
2219
+ } = {}
2220
+ ) {
2221
+ let intersectionObserver, resizeObserver;
2222
+ const resizeCallback = entries => {
2223
+ for (let entry of entries) {
2224
+ const { width, height } = entry.contentRect;
2225
+
2226
+ element.dispatchEvent(
2227
+ new ViewEvent("resizeview", {
2228
+ width,
2229
+ height,
2230
+ entry
2231
+ })
2232
+ );
2233
+ }
2234
+ };
2235
+
2236
+ const throttledResize = throttleResize > 0
2237
+ ? throttle(resizeCallback, throttleResize)
2238
+ : resizeCallback;
2239
+
2240
+ const intersectionCallback = entries => {
2241
+ for (let entry of entries) {
2242
+ const type = entry.isIntersecting ? "enterview" : "exitview";
2243
+ element.dispatchEvent(new ViewEvent(type, entry));
2244
+ }
2245
+ };
2246
+
2247
+ const throttledIntersections = throttleEnterExit > 0
2248
+ ? throttle(intersectionCallback, throttleEnterExit)
2249
+ : intersectionCallback;
2250
+
2251
+ if (intersection) {
2252
+ intersectionObserver = new IntersectionObserver(throttledIntersections, { threshold });
2253
+ intersectionObserver.observe(element);
2254
+ }
2255
+
2256
+ if (resize) {
2257
+ resizeObserver = new ResizeObserver(throttledResize);
2258
+ resizeObserver.observe(element);
2259
+ }
2260
+
2261
+ // ---- UNREGISTER ----
2262
+ return () => {
2263
+ if (intersectionObserver) {
2264
+ intersectionObserver.unobserve(element);
2265
+ intersectionObserver.disconnect();
2266
+ }
2267
+ if (resizeObserver) {
2268
+ resizeObserver.unobserve(element);
2269
+ resizeObserver.disconnect();
2270
+ }
2271
+ };
2272
+ }
2273
+
2274
+ class SwipeEvent extends CustomEvent {
2275
+ constructor(type, detail) {
2276
+ super(type, {
2277
+ detail,
2278
+ bubbles: true,
2279
+ cancelable: true
2280
+ });
2281
+ }
2282
+ }
2283
+
2284
+ function register_swipe_event(
2285
+ element,
2286
+ threshold = 50,
2287
+ restraint = 100,
2288
+ allowedTime = 500
2289
+ ) {
2290
+ let startX = 0,
2291
+ startY = 0,
2292
+ startTime = 0,
2293
+ isPointerDown = false;
2294
+
2295
+ function onPointerDown(e) {
2296
+ startX = e.clientX;
2297
+ startY = e.clientY;
2298
+ startTime = performance.now();
2299
+ isPointerDown = true;
2300
+ }
2301
+
2302
+ function onPointerUp(e) {
2303
+ if (!isPointerDown) return;
2304
+ isPointerDown = false;
2305
+
2306
+ const distX = e.clientX - startX;
2307
+ const distY = e.clientY - startY;
2308
+ const elapsed = performance.now() - startTime;
2309
+
2310
+ let direction = null;
2311
+ let eventName = null;
2312
+
2313
+ if (elapsed <= allowedTime) {
2314
+ if (Math.abs(distX) >= threshold && Math.abs(distY) <= restraint) {
2315
+ direction = distX < 0 ? "left" : "right";
2316
+ eventName = "swipe" + direction;
2317
+ }
2318
+ else if (Math.abs(distY) >= threshold && Math.abs(distX) <= restraint) {
2319
+ direction = distY < 0 ? "up" : "down";
2320
+ eventName = "swipe" + direction;
2321
+ }
2322
+ }
2323
+
2324
+ // Emit event
2325
+ if (eventName) {
2326
+ element.dispatchEvent(
2327
+ new SwipeEvent(eventName, {
2328
+ direction,
2329
+ distX,
2330
+ distY,
2331
+ originalEvent: e
2332
+ })
2333
+ );
2334
+ }
2335
+ }
2336
+
2337
+ element.addEventListener("pointerdown", onPointerDown, { passive: true });
2338
+ element.addEventListener("pointerup", onPointerUp, { passive: true });
2339
+
2340
+ return () => {
2341
+ element.removeEventListener("pointerdown", onPointerDown);
2342
+ element.removeEventListener("pointerup", onPointerUp);
2343
+ };
2344
+ }
2345
+
2065
2346
  const bind_click_event = (target, customizer) => {
2066
2347
  register_click_away_event(target.element);
2067
2348
  return new ZikoEvent(
2349
+ 'click',
2068
2350
  target,
2069
2351
  EventsMap.Click,
2070
2352
  null,
@@ -2072,64 +2354,87 @@ const bind_click_event = (target, customizer) => {
2072
2354
  );
2073
2355
  };
2074
2356
  const bind_clipboard_event = (target, customizer) => new ZikoEvent(
2357
+ 'clipboard',
2075
2358
  target,
2076
2359
  EventsMap.Clipboard,
2077
2360
  null,
2078
2361
  customizer
2079
2362
  );
2080
2363
  const bind_drag_event = (target, customizer) => new ZikoEvent(
2364
+ 'drag',
2081
2365
  target,
2082
2366
  EventsMap.Drag,
2083
2367
  null,
2084
2368
  customizer
2085
2369
  );
2086
2370
  const bind_focus_event = (target, customizer) => new ZikoEvent(
2371
+ 'focus',
2087
2372
  target,
2088
2373
  EventsMap.Focus,
2089
2374
  null,
2090
2375
  customizer
2091
2376
  );
2092
2377
  const bind_key_event = (target, customizer) => new ZikoEvent(
2378
+ 'key',
2093
2379
  target,
2094
2380
  EventsMap.Key,
2095
2381
  key_details_setter,
2096
2382
  customizer
2097
2383
  );
2098
- const bind_mouse_event = (target, customizer) => new ZikoEvent(
2384
+ const bind_mouse_event = (target, customizer) => new CoordinatesBasedEvent(
2385
+ 'mouse',
2099
2386
  target,
2100
2387
  EventsMap.Mouse,
2101
- null,
2388
+ mouse_details_setter,
2102
2389
  customizer
2103
2390
  );
2104
- const bind_pointer_event = (target, customizer) => new ZikoEvent(
2391
+ const bind_pointer_event = (target, customizer) => new CoordinatesBasedEvent(
2392
+ 'ptr',
2105
2393
  target,
2106
2394
  EventsMap.Ptr,
2107
2395
  ptr_details_setter,
2108
2396
  customizer
2109
2397
  );
2110
- const bind_touch_event = (target, customizer) => new ZikoEvent(
2398
+ const bind_touch_event = (target, customizer) => new CoordinatesBasedEvent(
2399
+ 'touch',
2111
2400
  target,
2112
2401
  EventsMap.Touch,
2113
- null,
2402
+ touch_details_setter,
2114
2403
  customizer
2115
2404
  );
2116
2405
  const bind_wheel_event = (target, customizer) => new ZikoEvent(
2406
+ 'wheel',
2117
2407
  target,
2118
2408
  EventsMap.Wheel,
2119
2409
  null,
2120
2410
  customizer
2121
2411
  );
2122
2412
 
2413
+ const bind_view_event = (target, customizer) => {
2414
+ register_view_event(target.element);
2415
+ return new ZikoEvent(
2416
+ 'view',
2417
+ target,
2418
+ EventsMap.View,
2419
+ null,
2420
+ customizer
2421
+ )
2422
+ };
2123
2423
 
2124
- // function details_setter(){
2125
- // if(this.currentEvent==="click") this.dx = 0
2126
- // else this.dx = 1
2127
- // // console.log(this.currentEvent)
2128
- // }
2424
+ const bind_swipe_event = (target, customizer) => {
2425
+ register_swipe_event(target.element);
2426
+ return new ZikoEvent(
2427
+ 'swipe',
2428
+ target,
2429
+ EventsMap.Swipe,
2430
+ null,
2431
+ customizer
2432
+ )
2433
+ };
2129
2434
 
2130
2435
  class ZikoCustomEvent extends ZikoEvent{
2131
2436
  constructor(target, events, customizer){
2132
- super(target, events, details_setter, customizer);
2437
+ super('custom', target, events, details_setter, customizer);
2133
2438
  }
2134
2439
  _register_events(events){
2135
2440
  super._register_events(events, null, null, false);
@@ -2163,7 +2468,9 @@ const binderMap = {
2163
2468
  drag : bind_drag_event,
2164
2469
  clipboard : bind_clipboard_event,
2165
2470
  focus : bind_focus_event,
2166
- wheel : bind_wheel_event
2471
+ wheel : bind_wheel_event,
2472
+ view : bind_view_event,
2473
+ swipe : bind_swipe_event
2167
2474
  };
2168
2475
 
2169
2476
  const EventsMethodes = {
@@ -2183,9 +2490,9 @@ Object.entries(EventsMap).forEach(([name, eventList]) => {
2183
2490
  const lname = name.toLowerCase();
2184
2491
  eventList.forEach(event => {
2185
2492
  const methodName = `on${event}`;
2186
- EventsMethodes[methodName] = function (...callbacks) {
2493
+ EventsMethodes[methodName] = function (callbacks) {
2187
2494
  if (!this.events[lname]) this.events[lname] = binderMap[lname](this);
2188
- this.events[lname][methodName](...callbacks);
2495
+ this.events[lname][methodName](callbacks);
2189
2496
  return this;
2190
2497
  };
2191
2498
  });
@@ -2262,6 +2569,7 @@ let UIElement$1 = class UIElement extends UIElementCore{
2262
2569
  // console.log(this)
2263
2570
  register_to_class(
2264
2571
  this,
2572
+ LifecycleMethods,
2265
2573
  AttrsMethods,
2266
2574
  DomMethods,
2267
2575
  StyleMethods,
@@ -2391,32 +2699,12 @@ let UIElement$1 = class UIElement extends UIElementCore{
2391
2699
  // get id() {
2392
2700
  // return this.element.getAttribute("id");
2393
2701
  // }
2394
- // onSwipe(width_threshold, height_threshold,...callbacks){
2395
- // if(!this.events.swipe)this.events.swipe = useSwipeEvent(this, width_threshold, height_threshold);
2396
- // this.events.swipe.onSwipe(...callbacks);
2397
- // return this;
2398
- // }
2399
2702
  // To Fix
2400
2703
  // onKeysDown({keys=[],callback}={}){
2401
2704
  // if(!this.events.key)this.events.key = useKeyEvent(this);
2402
2705
  // this.events.key.handleSuccessifKeys({keys,callback});
2403
2706
  // return this;
2404
2707
  // }
2405
- // onSelect(...callbacks){
2406
- // if(!this.events.clipboard)this.events.clipboard = useClipboardEvent(this);
2407
- // this.events.clipboard.onSelect(...callbacks);
2408
- // return this;
2409
- // }
2410
- // on(event_name,...callbacks){
2411
- // if(!this.events.custom)this.events.custom = useCustomEvent(this);
2412
- // this.events.custom.on(event_name,...callbacks);
2413
- // return this;
2414
- // }
2415
- // emit(event_name,detail={}){
2416
- // if(!this.events.custom)this.events.custom = useCustomEvent(this);
2417
- // this.events.custom.emit(event_name,detail);
2418
- // return this;
2419
- // }
2420
2708
  // watchAttr(callback){
2421
2709
  // if(!this.observer.attr)this.observer.attr = watchAttr(this,callback);
2422
2710
  // return this;
@@ -2425,16 +2713,8 @@ let UIElement$1 = class UIElement extends UIElementCore{
2425
2713
  // if(!this.observer.children)this.observer.children = watchChildren(this,callback);
2426
2714
  // return this;
2427
2715
  // }
2428
- // watchSize(callback){
2429
- // if(!this.observer.resize)this.observer.resize = watchSize(this,callback);
2430
- // this.observer.resize.start();
2431
- // return this;
2432
- // }
2433
- // watchIntersection(callback,config){
2434
- // if(!this.observer.intersection)this.observer.intersection = watchIntersection(this,callback,config);
2435
- // this.observer.intersection.start();
2436
- // return this;
2437
- // }
2716
+ // watchSize(callback)Remplaced By on onViewResize
2717
+ // watchIntersection(callback,config) Remplaced By onViewEnter and onViewExit
2438
2718
 
2439
2719
  };
2440
2720
 
@@ -2733,7 +3013,6 @@ class ZikoUISuspense extends UIElement{
2733
3013
  const ui = await callback();
2734
3014
  fallback_ui.unmount();
2735
3015
  this.append(ui);
2736
- // console.log(content)
2737
3016
  }
2738
3017
  catch(error){
2739
3018
  console.log({error});
@@ -4364,20 +4643,6 @@ const Scheduler = (tasks, { repeat = null} = {}) => new TimeScheduler(tasks, { r
4364
4643
 
4365
4644
  const step_fps = (step_or_fps) => 1000 / step_or_fps;
4366
4645
 
4367
- const debounce=(fn,delay=1000)=>{
4368
- let id;
4369
- return (...args) => id ? clearTimeout(id) : setTimeout(()=>fn(...args),delay);
4370
- };
4371
- const throttle=(fn,delay)=>{
4372
- let lastTime=0;
4373
- return (...args) => {
4374
- const now = new Date().getTime();
4375
- if(now-lastTime < delay) return;
4376
- lastTime = now;
4377
- fn(...args);
4378
- }
4379
- };
4380
-
4381
4646
  const sleep= ms => new Promise(res => setTimeout(res, ms));
4382
4647
  function timeout(ms, fn) {
4383
4648
  let id;
@@ -5152,4 +5417,4 @@ if(globalThis?.document){
5152
5417
  document?.addEventListener("DOMContentLoaded", __Ziko__.__Config__.init());
5153
5418
  }
5154
5419
 
5155
- export { App, Base, Clock, Combinaison, Complex, E, EPSILON, FileBasedRouting, Flex, HTMLWrapper, Logic$1 as Logic, Matrix, PI$2 as PI, Permutation, Random, SPA, SVGWrapper, Scheduler, Suspense, Switch, Tick, TimeAnimation, TimeLoop, TimeScheduler, UIElement$1 as UIElement, UIHTMLWrapper, UINode, UISVGWrapper, UISwitch, UIView, UseRoot, UseThread, Utils, View, ZikoApp, ZikoEvent, ZikoSPA, ZikoUIFlex, ZikoUISuspense, ZikoUIText, abs, accum, acos$1 as acos, acosh, acot, add, animation, arange, arc, arr2str, asin, asinh, atan, atan2, atanh, back, bind_click_event, bind_clipboard_event, bind_drag_event, bind_focus_event, bind_key_event, bind_mouse_event, bind_pointer_event, bind_touch_event, bind_wheel_event, cartesianProduct, ceil, clamp, clock, combinaison, complex, cos$2 as cos, cosh$1 as cosh, cot, coth, csc, csv2arr, csv2json, csv2matrix, csv2object, csv2sql, debounce, defineParamsGetter, define_wc, deg2rad, discret, div, e, elastic, fact, floor, geomspace, getEvent, hypot, inRange, in_back, in_bounce, in_circ, in_cubic, in_elastic, in_expo, in_out_back, in_out_bounce, in_out_circ, in_out_cubic, in_out_elastic, in_out_expo, in_out_quad, in_out_quart, in_out_quint, in_out_sin, in_quad, in_quart, in_quint, in_sin, isApproximatlyEqual, isStateGetter, json2arr, json2css, json2csv, json2csvFile, json2xml, json2xmlFile, json2yml, json2ymlFile, lerp, linear, linspace, ln, logspace, loop, map$1 as map, mapfun$1 as mapfun, matrix, matrix2, matrix3, matrix4, max, min, modulo, mul, norm, nums, obj2str, ones, out_back, out_bounce, out_circ, out_cubic, out_elastic, out_expo, out_quad, out_quart, out_quint, out_sin, pgcd, pow$1 as pow, powerSet, ppcm, preload, prod, rad2deg, round, sec, sig, sign, sin$2 as sin, sinc, sinh$1 as sinh, sleep, sqrt$2 as sqrt, sqrtn, step, step_fps, sub, subSet, sum, svg2ascii, svg2img, svg2imgUrl, svg2str, tags, tan, tanh, text, throttle, tick, timeTaken, time_memory_Taken, timeout, useDerived, useEventEmitter, useIPC, useLocaleStorage, useMediaQuery, useReactive, useRoot, useSessionStorage, useState, useThread, useTitle, wait, waitForUIElm, waitForUIElmSync, zeros };
5420
+ export { App, Base, Clock, Combinaison, Complex, E, EPSILON, FileBasedRouting, Flex, HTMLWrapper, Logic$1 as Logic, Matrix, PI$2 as PI, Permutation, Random, SPA, SVGWrapper, Scheduler, Suspense, Switch, Tick, TimeAnimation, TimeLoop, TimeScheduler, UIElement$1 as UIElement, UIHTMLWrapper, UINode, UISVGWrapper, UISwitch, UIView, UseRoot, UseThread, Utils, View, ZikoApp, ZikoEvent, ZikoSPA, ZikoUIFlex, ZikoUISuspense, ZikoUIText, abs, accum, acos$1 as acos, acosh, acot, add, animation, arange, arc, arr2str, asin, asinh, atan, atan2, atanh, back, bind_click_event, bind_clipboard_event, bind_drag_event, bind_focus_event, bind_key_event, bind_mouse_event, bind_pointer_event, bind_swipe_event, bind_touch_event, bind_view_event, bind_wheel_event, cartesianProduct, ceil, clamp, clock, combinaison, complex, cos$2 as cos, cosh$1 as cosh, cot, coth, csc, csv2arr, csv2json, csv2matrix, csv2object, csv2sql, debounce, defineParamsGetter, define_wc, deg2rad, discret, div, e, elastic, event_controller, fact, floor, geomspace, getEvent, hypot, inRange, in_back, in_bounce, in_circ, in_cubic, in_elastic, in_expo, in_out_back, in_out_bounce, in_out_circ, in_out_cubic, in_out_elastic, in_out_expo, in_out_quad, in_out_quart, in_out_quint, in_out_sin, in_quad, in_quart, in_quint, in_sin, isApproximatlyEqual, isStateGetter, json2arr, json2css, json2csv, json2csvFile, json2xml, json2xmlFile, json2yml, json2ymlFile, lerp, linear, linspace, ln, logspace, loop, map$1 as map, mapfun$1 as mapfun, matrix, matrix2, matrix3, matrix4, max, min, modulo, mul, norm, nums, obj2str, ones, out_back, out_bounce, out_circ, out_cubic, out_elastic, out_expo, out_quad, out_quart, out_quint, out_sin, pgcd, pow$1 as pow, powerSet, ppcm, preload, prod, rad2deg, round, sec, sig, sign, sin$2 as sin, sinc, sinh$1 as sinh, sleep, sqrt$2 as sqrt, sqrtn, step, step_fps, sub, subSet, sum, svg2ascii, svg2img, svg2imgUrl, svg2str, tags, tan, tanh, text, throttle, tick, timeTaken, time_memory_Taken, timeout, toggle_event_listener, useDerived, useEventEmitter, useIPC, useLocaleStorage, useMediaQuery, useReactive, useRoot, useSessionStorage, useState, useThread, useTitle, wait, waitForUIElm, waitForUIElmSync, zeros };