ziko 0.0.26 → 0.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ziko.js CHANGED
@@ -2,7 +2,7 @@
2
2
  /*
3
3
  Project: ziko.js
4
4
  Author: Zakaria Elalaoui
5
- Date : Sat Mar 08 2025 13:43:10 GMT+0000 (UTC)
5
+ Date : Wed Jul 23 2025 15:08:02 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
@@ -1013,6 +1013,11 @@
1013
1013
  }
1014
1014
  }
1015
1015
 
1016
+ var __Random__ = /*#__PURE__*/Object.freeze({
1017
+ __proto__: null,
1018
+ Random: Random
1019
+ });
1020
+
1016
1021
  const luDecomposition=matrix=>{
1017
1022
  if(matrix instanceof Matrix)matrix=matrix.arr;
1018
1023
  const n = matrix.length;
@@ -1808,6 +1813,7 @@
1808
1813
  function EVENT_CONTROLLER(e,EVENT,setter,push_object){
1809
1814
  this.event=e;
1810
1815
  if(this.cache.preventDefault[EVENT])e.preventDefault();
1816
+ console.log({setter});
1811
1817
  if(setter)setter();
1812
1818
  if(this.cache.stream.enabled[EVENT]&&push_object)this.cache.stream.history[EVENT].push(push_object);
1813
1819
  this.cache.callbacks[EVENT].map(n=>n(this));
@@ -4608,10 +4614,181 @@
4608
4614
  useType: useType
4609
4615
  });
4610
4616
 
4617
+ const getEvent=(event = "")=>{
4618
+ if(event.startsWith("Ptr"))return `pointer${event.split("Ptr")[1].toLowerCase()}`;
4619
+ return event.toLowerCase()
4620
+ };
4621
+
4622
+ function event_controller(e, event_name, details_setter, customizer, push_object){
4623
+ this.cache.currentEvent = event_name;
4624
+ this.cache.event = e;
4625
+ details_setter?.call(this);
4626
+ if(customizer?.hasOwnProperty("prototype"))customizer?.call(this);
4627
+ else customizer?.call(null, this);
4628
+ if(this.cache.preventDefault[event_name]) e.preventDefault();
4629
+ if(this.cache.stopPropagation[event_name]) e.stopPropagation();
4630
+ if(this.cache.stopImmediatePropagation[event_name]) e.stopImmediatePropagation();
4631
+
4632
+ if(this.cache.stream.enabled[event_name]&&push_object)this.cache.stream.history[event_name].push(push_object);
4633
+ this.cache.callbacks[event_name]?.map(n=>n(this));
4634
+ }
4635
+ class __ZikoEvent__ {
4636
+ constructor(target = null, Events = [], details_setter, customizer){
4637
+ this.target = target;
4638
+ this.cache = {
4639
+ currentEvent : null,
4640
+ event: null,
4641
+ options : {},
4642
+ preventDefault : {},
4643
+ stopPropagation : {},
4644
+ stopImmediatePropagation : {},
4645
+ event_flow : {},
4646
+ paused : {},
4647
+ stream : {
4648
+ enabled : {},
4649
+ clear : {},
4650
+ history : {}
4651
+ },
4652
+ callbacks : {},
4653
+ __controllers__:{}
4654
+ };
4655
+ const events = Events.map(n=>getEvent(n));
4656
+ events.forEach((event,i)=>{
4657
+ Object.assign(this.cache.preventDefault, {[event] : false});
4658
+ Object.assign(this.cache.options, {[event] : {}});
4659
+ Object.assign(this.cache.paused, {[event] : false});
4660
+ Object.assign(this.cache.stream.enabled, {[event] : false});
4661
+ Object.assign(this.cache.stream.clear, {[event] : false});
4662
+ Object.assign(this.cache.stream.history, {[event] : []});
4663
+ Object.assign(this.cache.__controllers__, {[event] : e=>event_controller.call(this, e, event, details_setter, customizer)});
4664
+ Object.assign(this, { [`on${Events[i]}`] : (...callbacks)=> this.__onEvent(event, this.cache.options[event], {}, ...callbacks)});
4665
+ });
4666
+ }
4667
+ get targetElement(){
4668
+ return this.target?.element;
4669
+ }
4670
+ get isParent(){
4671
+ return this.target?.element === this.event.srcElement;
4672
+ }
4673
+ get item(){
4674
+ return this.target.find(n=>n.element == this.event?.srcElement)?.[0];
4675
+ }
4676
+ get currentEvent(){
4677
+ return this.cache.currentEvent;
4678
+ }
4679
+ get event(){
4680
+ return this.cache.event;
4681
+ }
4682
+ setTarget(UI){
4683
+ this.target=UI;
4684
+ return this;
4685
+ }
4686
+ __handle(event, handler, options, dispose){
4687
+ this.targetElement?.addEventListener(event, handler, options);
4688
+ return this;
4689
+ }
4690
+ __onEvent(event, options, dispose, ...callbacks){
4691
+ if(callbacks.length===0){
4692
+ console.log("00");
4693
+ if(this.cache.callbacks[event]){
4694
+ console.log("Call");
4695
+ // this.cache.callbacks.map(n=>e=>n.call(this,e));
4696
+ this.cache.callbacks[event].map(n=>e=>n.call(this,e));
4697
+ }
4698
+ else {
4699
+ return this;
4700
+ }
4701
+ }
4702
+ else this.cache.callbacks[event] = callbacks.map(n=>e=>n.call(this,e));
4703
+ this.__handle(event, this.cache.__controllers__[event],options, dispose);
4704
+ return this;
4705
+ }
4706
+ #override(methode, overrides, defaultValue){
4707
+ if(defaultValue === "default") Object.assign(this.cache[methode], {...this.cache[methode], ...overrides});
4708
+ const all = defaultValue === "default"
4709
+ ? this.cache[methode]
4710
+ : Object.fromEntries(Object.keys(this.cache.preventDefault).map(n=>[n,defaultValue]));
4711
+ Object.assign(this.cache[methode], {...all,...overrides});
4712
+ return this
4713
+ }
4714
+ preventDefault(overrides = {}, defaultValue = "default"){
4715
+ this.#override("preventDefault", overrides, defaultValue);
4716
+ // const all=Object.fromEntries(Object.keys(this.cache.preventDefault).map(n=>[n,defaultValue]))
4717
+ // Object.assign(this.cache.preventDefault, {...all,...overrides});
4718
+ return this;
4719
+ }
4720
+ stopPropagation(overrides = {}, defaultValue = "default"){
4721
+ this.#override("stopPropagation", overrides, defaultValue);
4722
+ return this;
4723
+ }
4724
+ stopImmediatePropagation(overrides = {}, defaultValue = "default"){
4725
+ this.#override("stopImmediatePropagation", overrides, defaultValue);
4726
+ return this;
4727
+ }
4728
+ setEventOptions(event, options){
4729
+ this.pause({[event] : true, }, "default");
4730
+ Object.assign(this.cache.options[getEvent(event)], options);
4731
+ this.resume({[event] : true, }, "default");
4732
+ return this;
4733
+ }
4734
+ pause(overrides = {}, defaultValue = "default"){
4735
+ const all = defaultValue === "default"
4736
+ ? this.cache.stream.enabled
4737
+ : Object.entries(Object.keys(this.cache.stream.enabled).map(n=>[n,defaultValue]));
4738
+ overrides={...all,...overrides};
4739
+ for(let key in overrides){
4740
+ if(overrides[key]){
4741
+ this.targetElement?.removeEventListener(key, this.cache.__controllers__[key], this.cache.options[key]);
4742
+ this.cache.paused[key]=true;
4743
+ }
4744
+ }
4745
+ return this;
4746
+ }
4747
+ resume(overrides = {}, defaultValue = "default"){
4748
+ const all = defaultValue === "default"
4749
+ ? this.cache.stream.enabled
4750
+ : Object.entries(Object.keys(this.cache.stream.enabled).map(n=>[n,defaultValue]));
4751
+ overrides={...all,...overrides};
4752
+ for(let key in overrides){
4753
+ if(overrides[key]){
4754
+ this.targetElement?.addEventListener(key,this.cache.__controllers__[key], this.cache.options[key]);
4755
+ this.cache.paused[key]=false;
4756
+ }
4757
+ }
4758
+ return this;
4759
+ }
4760
+ stream(overrides = {}, defaultValue = "default"){
4761
+ this.cache.stream.t0=Date.now();
4762
+ const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,defaultValue]));
4763
+ overrides={...all,...overrides};
4764
+ Object.assign(this.cache.stream.enabled,overrides);
4765
+ return this;
4766
+ }
4767
+ clear(){
4768
+
4769
+ }
4770
+ dispose(overrides = {}, defaultValue = "default"){
4771
+ this.pause(overrides, defaultValue);
4772
+
4773
+ return this;
4774
+ }
4775
+ }
4776
+
4777
+ // export * from "./click.js";
4778
+ // export * from "./key.js";
4779
+ // export * from "./pointer.js"
4780
+
4781
+ var EventsExp = /*#__PURE__*/Object.freeze({
4782
+ __proto__: null,
4783
+ __ZikoEvent__: __ZikoEvent__,
4784
+ getEvent: getEvent
4785
+ });
4786
+
4611
4787
  const Reactivity={
4612
4788
  ...Events,
4613
4789
  ...Observer,
4614
4790
  ...Hooks,
4791
+ ...EventsExp,
4615
4792
  };
4616
4793
 
4617
4794
  class ZikoUIElement {
@@ -4659,6 +4836,7 @@
4659
4836
  intersection:null
4660
4837
  };
4661
4838
  this.uuid = `${this.cache.name}-${Random.string(16)}`;
4839
+ this.ui_index = globalThis.__Ziko__.__CACHE__.get_ui_index();
4662
4840
  this.cache.style.linkTo(this);
4663
4841
  useDefaultStyle && this.style({
4664
4842
  position: "relative",
@@ -4671,7 +4849,7 @@
4671
4849
  this.items = [];
4672
4850
  globalThis.__Ziko__.__UI__[this.cache.name]?globalThis.__Ziko__.__UI__[this.cache.name]?.push(this):globalThis.__Ziko__.__UI__[this.cache.name]=[this];
4673
4851
  element && globalThis.__Ziko__.__Config__.default.render && this.render();
4674
- this.setAttr("data-ref", this.uuid);
4852
+ this.setAttr("data-ui-index", this.ui_index);
4675
4853
  if(globalThis.__Ziko__.__Config__.renderingMode !== "spa" && !globalThis.__Ziko__.__Config__.isSSC) {
4676
4854
  globalThis.__Ziko__.__HYDRATION_MAP__.set(this.uuid, ()=>this);
4677
4855
  }
@@ -4755,12 +4933,14 @@
4755
4933
  }
4756
4934
  for (let i = 0; i < ele.length; i++) {
4757
4935
  if (["number", "string"].includes(typeof ele[i])) ele[i] = text(ele[i]);
4936
+ if(ele[i] instanceof Node) ele[i] = new ZikoUIElement(ele[i]);
4758
4937
  if (ele[i]?.isZikoUIElement) {
4759
4938
  ele[i].cache.parent = this;
4760
4939
  this.element[adder](ele[i].element);
4761
4940
  ele[i].target = this.element;
4762
4941
  this.items[pusher](ele[i]);
4763
- } else if (ele[i] instanceof Object) {
4942
+ }
4943
+ else if (ele[i] instanceof Object) {
4764
4944
  if (ele[i]?.style) this.style(ele[i]?.style);
4765
4945
  if (ele[i]?.attr) {
4766
4946
  Object.entries(ele[i].attr).forEach((n) =>
@@ -5846,15 +6026,19 @@
5846
6026
  }
5847
6027
  }
5848
6028
  function html2dom(htmlString) {
5849
- const parser = new DOMParser();
5850
- const doc = parser.parseFromString(`<div>${htmlString}</div>`, 'text/html');
5851
- doc.body.firstChild.style.display = "contents";
5852
- return doc.body.firstChild;
6029
+ if(globalThis?.DOMParser){
6030
+ const parser = new DOMParser();
6031
+ const doc = parser.parseFromString(`<div>${htmlString}</div>`, 'text/html');
6032
+ doc.body.firstChild.style.display = "contents";
6033
+ return doc.body.firstChild;
6034
+ }
5853
6035
  }
5854
6036
  function svg2dom(svgString) {
5855
- const parser = new DOMParser();
5856
- const doc = parser.parseFromString(svgString.replace(/\s+/g, ' ').trim(), 'image/svg+xml');
5857
- return doc.documentElement; // SVG elements are usually at the root
6037
+ if(globalThis?.DOMParser){
6038
+ const parser = new DOMParser();
6039
+ const doc = parser.parseFromString(svgString.replace(/\s+/g, ' ').trim(), 'image/svg+xml');
6040
+ return doc.documentElement; // SVG elements are usually at the root
6041
+ }
5858
6042
  }
5859
6043
  class ZikoUIHTMLWrapper extends ZikoUIXMLWrapper{
5860
6044
  constructor(HTMLContent){
@@ -6057,7 +6241,6 @@
6057
6241
  class ZikoUIBtn extends ZikoUIElement {
6058
6242
  constructor(value = "button") {
6059
6243
  super("button","btn");
6060
- this.element = document?.createElement("button");
6061
6244
  this.setValue(value);
6062
6245
  this.st.cursor("pointer");
6063
6246
  globalThis.__Ziko__.__Config__.default.render && this.render();
@@ -8466,6 +8649,7 @@
8466
8649
  ...__Functions__,
8467
8650
  ...__Complex__,
8468
8651
  ...__Matrix__,
8652
+ ...__Random__,
8469
8653
  ...__Utils__,
8470
8654
  ...__Discrect__,
8471
8655
  // ...__Signal__,
@@ -9101,7 +9285,28 @@
9101
9285
  });
9102
9286
  }
9103
9287
 
9104
- const __UI__={};
9288
+ const __UI__={
9289
+ __all__(){
9290
+ return Object.values(this)
9291
+ .filter(Array.isArray)
9292
+ .flat();
9293
+ },
9294
+ querySelectorAll(){
9295
+ return this.__all__().filter(n=>n)
9296
+ },
9297
+ getElementByIndex(index){
9298
+ return this.__all__().find(n=>n.ui_index===index);
9299
+ },
9300
+ getElementById(id){
9301
+ return null;
9302
+ },
9303
+ getElementsByClass(){
9304
+
9305
+ },
9306
+ getElementsByTagName(){
9307
+
9308
+ }
9309
+ };
9105
9310
  const __HYDRATION_MAP__ = new Map();
9106
9311
  const __Config__={
9107
9312
  default:{
@@ -9119,10 +9324,17 @@
9119
9324
  init:()=>document.documentElement.setAttribute("data-engine","zikojs"),
9120
9325
  renderingMode :"spa",
9121
9326
  isSSC : false,
9327
+ };
9328
+ const __CACHE__ = {
9329
+ ui_index : 0,
9330
+ get_ui_index:function(){
9331
+ return this.ui_index ++
9332
+ }
9122
9333
  };
9123
9334
 
9124
9335
  var Global = /*#__PURE__*/Object.freeze({
9125
9336
  __proto__: null,
9337
+ __CACHE__: __CACHE__,
9126
9338
  __Config__: __Config__,
9127
9339
  __HYDRATION_MAP__: __HYDRATION_MAP__,
9128
9340
  __UI__: __UI__
@@ -9226,6 +9438,7 @@
9226
9438
  __UI__,
9227
9439
  __HYDRATION_MAP__,
9228
9440
  __Config__,
9441
+ __CACHE__,
9229
9442
  ExtractAll,
9230
9443
  RemoveAll
9231
9444
  };
@@ -9363,9 +9576,11 @@
9363
9576
  exports.ZikoUIXMLWrapper = ZikoUIXMLWrapper;
9364
9577
  exports.ZikoUseRoot = ZikoUseRoot;
9365
9578
  exports.ZikoUseStyle = ZikoUseStyle;
9579
+ exports.__CACHE__ = __CACHE__;
9366
9580
  exports.__Config__ = __Config__;
9367
9581
  exports.__HYDRATION_MAP__ = __HYDRATION_MAP__;
9368
9582
  exports.__UI__ = __UI__;
9583
+ exports.__ZikoEvent__ = __ZikoEvent__;
9369
9584
  exports.abbrText = abbrText;
9370
9585
  exports.abs = abs;
9371
9586
  exports.accum = accum;
@@ -9419,6 +9634,7 @@
9419
9634
  exports.floor = floor;
9420
9635
  exports.gamma = gamma;
9421
9636
  exports.geomspace = geomspace;
9637
+ exports.getEvent = getEvent;
9422
9638
  exports.h = h;
9423
9639
  exports.h1 = h1;
9424
9640
  exports.h2 = h2;