ziko 0.45.2 → 0.45.4

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 : Mon Sep 01 2025 13:22:11 GMT+0100 (UTC+01:00)
5
+ Date : Thu Sep 04 2025 20:47:52 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
@@ -1213,11 +1213,11 @@
1213
1213
  switch(type){
1214
1214
  case "html" : {
1215
1215
  element = globalThis?.document?.createElement(element);
1216
- console.log('1');
1216
+ // console.log('1')
1217
1217
  } break;
1218
1218
  case "svg" : {
1219
1219
  element = globalThis?.document?.createElementNS("http://www.w3.org/2000/svg", element);
1220
- console.log('2');
1220
+ // console.log('2')
1221
1221
  } break;
1222
1222
  default : throw Error("Not supported")
1223
1223
  }
@@ -1679,6 +1679,13 @@
1679
1679
  else if(this.target?.children?.length && [...this.target?.children].includes(this.element)) this.target.removeChild(this.element);
1680
1680
  return this;
1681
1681
  }
1682
+ function replaceElementWith(new_element){
1683
+ this.cache.element.replaceWith(new_element);
1684
+ this.cache.element = new_element;
1685
+
1686
+ // To do : Dispose Events and States
1687
+ return this
1688
+ }
1682
1689
  function renderAfter(t = 1) {
1683
1690
  setTimeout(() => this.render(), t);
1684
1691
  return this;
@@ -1709,6 +1716,7 @@
1709
1716
  remove: remove,
1710
1717
  render: render,
1711
1718
  renderAfter: renderAfter,
1719
+ replaceElementWith: replaceElementWith,
1712
1720
  unrender: unrender,
1713
1721
  unrenderAfter: unrenderAfter
1714
1722
  });
@@ -3130,7 +3138,7 @@
3130
3138
  let UIElement$1 = class UIElement extends UIElementCore{
3131
3139
  constructor({element, name ='', type='html', render = __Ziko__.__Config__.default.render}={}){
3132
3140
  super();
3133
- console.log({type});
3141
+ // console.log({type})
3134
3142
  // console.log(this)
3135
3143
  register_to_class(
3136
3144
  this,
@@ -3140,7 +3148,7 @@
3140
3148
  IndexingMethods,
3141
3149
  EventsMethodes
3142
3150
  );
3143
- this.init(element, name, type, render);
3151
+ if(element)this.init(element, name, type, render);
3144
3152
  }
3145
3153
  get element(){
3146
3154
  return this.cache.element;
@@ -3430,13 +3438,13 @@
3430
3438
  let type ;
3431
3439
  if(HTMLTags.includes(tag)) type = 'html';
3432
3440
  if(SVGTags.includes(tag)) type = 'svg';
3433
- console.log(type);
3441
+ // console.log(type)
3434
3442
  return (...args)=>{
3435
3443
  // Fix undefined
3436
3444
  // console.log(isStateGetter(args[0]))
3437
3445
  // console.log(!!args)
3438
3446
  if(args.length === 0) {
3439
- console.log('length 0');
3447
+ // console.log('length 0')
3440
3448
  return new UIElement$1({element : tag, name : tag, type})
3441
3449
  }
3442
3450
  if(
@@ -3704,6 +3712,38 @@
3704
3712
  );
3705
3713
  }
3706
3714
 
3715
+ class UISwitch extends UIElement$1{
3716
+ constructor(key, cases){
3717
+ super();
3718
+ this.key = key;
3719
+ this.cases = cases;
3720
+ this.init();
3721
+ }
3722
+ init(){
3723
+ Object.values(this.cases).filter(n=>n != this.current).forEach(n=>n.unrender());
3724
+ super.init(this.current.element);
3725
+ }
3726
+ get current(){
3727
+ const matched = Object.keys(this.cases).find(n => n == this.key) ?? 'default';
3728
+ return this.cases[matched]
3729
+ }
3730
+ updateKey(key){
3731
+ this.key = key;
3732
+ this.replaceElementWith(this.current.element);
3733
+ // this.cache.element.replaceWith(this.current.element)
3734
+ // this.cache.element = this.current.element;
3735
+ return this;
3736
+ }
3737
+
3738
+ }
3739
+
3740
+ const Switch=({key, cases})=> new UISwitch(key, cases);
3741
+
3742
+ // export const Switch=({key, cases}) => {
3743
+ // const matched = Object.keys(cases).find(n => n == key) ?? 'default';
3744
+ // return this.cases[matched]()
3745
+ // }
3746
+
3707
3747
  const svg2str=svg=>(new XMLSerializer()).serializeToString(svg);
3708
3748
  const svg2ascii=svg=>btoa(svg2str(svg));
3709
3749
  const svg2imgUrl=svg=>'data:image/svg+xml;base64,'+svg2ascii(svg);
@@ -5953,6 +5993,7 @@
5953
5993
  exports.Scheduler = Scheduler;
5954
5994
  exports.Step = Step;
5955
5995
  exports.Suspense = Suspense;
5996
+ exports.Switch = Switch;
5956
5997
  exports.Tick = Tick;
5957
5998
  exports.TimeAnimation = TimeAnimation;
5958
5999
  exports.TimeLoop = TimeLoop;
@@ -5961,6 +6002,7 @@
5961
6002
  exports.UIHTMLWrapper = UIHTMLWrapper;
5962
6003
  exports.UINode = UINode;
5963
6004
  exports.UISVGWrapper = UISVGWrapper;
6005
+ exports.UISwitch = UISwitch;
5964
6006
  exports.Utils = Utils;
5965
6007
  exports.ZikoApp = ZikoApp;
5966
6008
  exports.ZikoCustomEvent = ZikoCustomEvent;