ziko 0.41.2 → 0.42.1

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 Aug 23 2025 14:24:46 GMT+0100 (UTC+01:00)
5
+ Date : Sun Aug 24 2025 12:52:45 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
@@ -17,23 +17,23 @@
17
17
  const { PI: PI$2, E } = Math;
18
18
  const EPSILON=Number.EPSILON;
19
19
 
20
- const {PI: PI$1, cos: cos$2, sin: sin$2, tan: tan$1, acos: acos$2, asin: asin$1, atan: atan$1, cosh: cosh$1, sinh: sinh$1, tanh: tanh$1, acosh: acosh$1, asinh: asinh$1, atanh: atanh$1, log} = Math;
20
+ const {PI: PI$1, cos: cos$3, sin: sin$3, tan: tan$1, acos: acos$2, asin: asin$1, atan: atan$1, cosh: cosh$2, sinh: sinh$2, tanh: tanh$1, acosh: acosh$1, asinh: asinh$1, atanh: atanh$1, log: log$1} = Math;
21
21
  let Fixed={
22
- cos: cos$2,
23
- sin: sin$2,
22
+ cos: cos$3,
23
+ sin: sin$3,
24
24
  tan: tan$1,
25
- sinc: x => sin$2(PI$1*x)/(PI$1*x),
26
- sec: x => 1/cos$2(x),
27
- csc: x => 1/sin$2(x),
25
+ sinc: x => sin$3(PI$1*x)/(PI$1*x),
26
+ sec: x => 1/cos$3(x),
27
+ csc: x => 1/sin$3(x),
28
28
  cot: x => 1/tan$1(x),
29
29
  acos: acos$2,
30
30
  asin: asin$1,
31
31
  atan: atan$1,
32
32
  acot: x => PI$1/2-atan$1(x),
33
- cosh: cosh$1,
34
- sinh: sinh$1,
33
+ cosh: cosh$2,
34
+ sinh: sinh$2,
35
35
  tanh: tanh$1,
36
- coth: n => (1/2*log((1+n)/(1-n))),
36
+ coth: n => (1/2*log$1((1+n)/(1-n))),
37
37
  acosh: acosh$1,
38
38
  asinh: asinh$1,
39
39
  atanh: atanh$1,
@@ -67,20 +67,20 @@
67
67
  const [a,b,z,phi]=[x.a,x.b,x.z,x.phi];
68
68
  switch(fun){
69
69
  case Math.log: return complex(ln(z),phi); // Done
70
- case Math.exp: return complex(e(a)*cos$1(b),e(a)*sin$1(b)); // Done
70
+ case Math.exp: return complex(e(a)*cos$2(b),e(a)*sin$2(b)); // Done
71
71
  case Math.abs: return z; // Done
72
- case Math.sqrt: return complex(sqrt$1(z)*cos$1(phi/2),sqrt$1(z)*sin$1(phi/2)); // Done
73
- case Fixed.cos: return complex(cos$1(a)*cosh(b),-(sin$1(a)*sinh(b)));
74
- case Fixed.sin: return complex(sin$1(a)*cosh(b),cos$1(a)*sinh(b));
72
+ case Math.sqrt: return complex(sqrt$2(z)*cos$2(phi/2),sqrt$2(z)*sin$2(phi/2)); // Done
73
+ case Fixed.cos: return complex(cos$2(a)*cosh$1(b),-(sin$2(a)*sinh$1(b)));
74
+ case Fixed.sin: return complex(sin$2(a)*cosh$1(b),cos$2(a)*sinh$1(b));
75
75
  case Fixed.tan:{
76
- const DEN = cos$1(2*a)+cosh(2*b);
77
- return complex(sin$1(2*a)/DEN,sinh(2*b)/DEN);
76
+ const DEN = cos$2(2*a)+cosh$1(2*b);
77
+ return complex(sin$2(2*a)/DEN,sinh$1(2*b)/DEN);
78
78
  }
79
- case Fixed.cosh:return complex(cosh(a)*cos$1(b),sinh(a)*sin$1(b));
80
- case Fixed.sinh:return complex(sinh(a)*cos$1(b),cosh(a)*sin$1(b));
79
+ case Fixed.cosh:return complex(cosh$1(a)*cos$2(b),sinh$1(a)*sin$2(b));
80
+ case Fixed.sinh:return complex(sinh$1(a)*cos$2(b),cosh$1(a)*sin$2(b));
81
81
  case Fixed.tanh:{
82
- const DEN=cosh(2*a)+cos$1(2*b);
83
- return complex(sinh(2*a)/DEN,sin$1(2*b)/DEN)
82
+ const DEN=cosh$1(2*a)+cos$2(2*b);
83
+ return complex(sinh$1(2*a)/DEN,sin$2(2*b)/DEN)
84
84
  }
85
85
  default : return fun(x)
86
86
  }
@@ -951,6 +951,21 @@
951
951
  }
952
952
  };
953
953
 
954
+ async function fetchdom(url='https://github.com/zakarialaoui10'){
955
+ const data=await fetch(url);
956
+ const html=await data.text();
957
+ const dom= new DOMParser().parseFromString(html,'text/xml');
958
+ return dom.documentElement
959
+ }
960
+ function fetchdomSync(url='https://github.com/zakarialaoui10'){
961
+ const data=preload(url);
962
+ const dom= new DOMParser().parseFromString(data,'text/xml');
963
+ return dom.documentElement;
964
+ }
965
+
966
+ globalThis.fetchdom=fetchdom;
967
+ globalThis.fetchdomSync=fetchdomSync;
968
+
954
969
  const csv2arr = (csv, delimiter = ",")=>csv.trim().trimEnd().split("\n").map(n=>n.split(delimiter));
955
970
  const csv2matrix = (csv, delimiter = ",")=>new Matrix(csv2arr(csv,delimiter));
956
971
  const csv2object = (csv, delimiter = ",") => {
@@ -1106,59 +1121,188 @@
1106
1121
  else register_to_instance(target, ...mixins);
1107
1122
  };
1108
1123
 
1124
+ function parseQueryParams$1(queryString) {
1125
+ const params = {};
1126
+ queryString.replace(/[A-Z0-9]+?=([\w|:|\/\.]*)/gi, (match) => {
1127
+ const [key, value] = match.split('=');
1128
+ params[key] = value;
1129
+ });
1130
+ return params;
1131
+ }
1132
+
1133
+ function defineParamsGetter$1(target ){
1134
+ Object.defineProperties(target, {
1135
+ 'QueryParams': {
1136
+ get: function() {
1137
+ return parseQueryParams$1(globalThis.location.search.substring(1));
1138
+ },
1139
+ configurable: false,
1140
+ enumerable: true
1141
+ },
1142
+ 'HashParams': {
1143
+ get: function() {
1144
+ const hash = globalThis.location.hash.substring(1);
1145
+ return hash.split("#");
1146
+ },
1147
+ configurable: false,
1148
+ enumerable: true
1149
+ }
1150
+ });
1151
+ }
1152
+
1153
+ class UIStore extends Array {
1154
+ constructor(...args) {
1155
+ super(...args);
1156
+ }
1157
+ getItemById(id) {
1158
+ return this.find(n => n.element.id === id);
1159
+ }
1160
+ getItemsByTagName(tag) {
1161
+ return this.filter(n => n.element.tagName.toLowerCase() === tag.toLowerCase());
1162
+ }
1163
+ getElementsByClassName(className) {
1164
+ return this.filter(n => n.element.classList?.contains(className));
1165
+ }
1166
+ querySelector(selector) {
1167
+ const el = globalThis?.document?.querySelector(selector);
1168
+ if (!el) return null;
1169
+ return this.find(ui => ui.element === el) || null;
1170
+ }
1171
+ querySelectorAll(selector) {
1172
+ const els = globalThis?.document?.querySelectorAll(selector);
1173
+ return Array.from(els)
1174
+ .map(el => this.find(ui => ui.element === el))
1175
+ .filter(Boolean);
1176
+ }
1177
+ }
1178
+
1179
+ // create the singleton
1180
+ const __UI__ = new UIStore();
1181
+
1182
+ const __Config__ = {
1183
+ default:{
1184
+ target:null,
1185
+ render:true,
1186
+ math:{
1187
+ mode:"deg"
1188
+ }
1189
+ },
1190
+ setDefault:function(pairs){
1191
+ const keys=Object.keys(pairs);
1192
+ const values=Object.values(pairs);
1193
+ for(let i=0; i<keys.length; i++) this.default[keys[i]]=values[i];
1194
+ },
1195
+ init:()=>{
1196
+ // document.documentElement.setAttribute("data-engine","zikojs")
1197
+ },
1198
+ renderingMode :"spa",
1199
+ isSSC : false,
1200
+ };
1201
+
1202
+ const __HYDRATION__ = {
1203
+ store : new Map(),
1204
+ index : 0,
1205
+ register: function(component){
1206
+ this.store.set(this.index++, component);
1207
+ }
1208
+ };
1209
+
1210
+ const __CACHE__ = {
1211
+ ui_index : 0,
1212
+ get_ui_index:function(){
1213
+ return this.ui_index ++
1214
+ },
1215
+ register_ui: function(UIElement){
1216
+
1217
+ }
1218
+ };
1219
+
1220
+ const __State__ = {
1221
+ store : new Map(),
1222
+ index : undefined?.data?.__Ziko__?.__State__?.index ?? 0,
1223
+ register: function(state){
1224
+ console.log({
1225
+ hmr : undefined?.data.__Ziko__.__State__.index,
1226
+ index : this.index
1227
+ });
1228
+ this.store.set(this.index++, state);
1229
+ }
1230
+
1231
+ };
1232
+
1233
+ function __init__global__(){
1234
+ if ( !globalThis?.__Ziko__ ){
1235
+ globalThis.__Ziko__ = {
1236
+ __UI__,
1237
+ __HYDRATION__,
1238
+ __State__,
1239
+ __Config__,
1240
+ __CACHE__,
1241
+ };
1242
+ defineParamsGetter$1(__Ziko__);
1243
+ }
1244
+ }
1245
+
1246
+ if(!globalThis.__Ziko__) __init__global__();
1247
+
1248
+ // HMR persistence
1249
+ if (undefined) {
1250
+ undefined.data.__Ziko__ = undefined.data.__Ziko__ || globalThis.__Ziko__;
1251
+ globalThis.__Ziko__ = undefined.data.__Ziko__;
1252
+ // import.meta.hot.accept(n=>console.log(n));
1253
+ // console.log(import.meta.hot.data.__Ziko__.__State__.store)
1254
+ }
1255
+
1256
+
1257
+
1109
1258
  function useState(initialValue) {
1110
- let value = initialValue;
1111
- const subscribers = new Set();
1112
- let paused = false;
1259
+
1260
+ // console.log(import.meta.hot.data.__Ziko__.__State__.store.get(0))
1261
+
1262
+ const {store, index} = __Ziko__.__State__;
1263
+ __Ziko__.__State__.register({
1264
+ value : initialValue,
1265
+ subscribers : new Set(),
1266
+ paused : false
1267
+ });
1268
+
1269
+ const current = store.get(index);
1113
1270
 
1114
1271
  function getValue() {
1115
1272
  return {
1116
- value,
1273
+ value: current.value,
1117
1274
  isStateGetter: () => true,
1118
- _subscribe: (
1119
- fn,
1120
- // UIElement
1121
- ) => {
1122
- subscribers.add(fn);
1123
-
1124
- // const observer = new MutationObserver(() => {
1125
- // if (!document.body.contains(UIElement.element)) {
1126
- // subscribers.delete(fn);
1127
- // observer.disconnect();
1128
- // }
1129
- // });
1130
-
1131
- // observer.observe(document.body, { childList: true, subtree: true });
1132
- },
1275
+ _subscribe: (fn) => current.subscribers.add(fn),
1133
1276
  };
1134
1277
  }
1135
1278
 
1136
1279
  function setValue(newValue) {
1137
- if (paused) return;
1138
- if (typeof newValue === "function") newValue = newValue(value);
1139
- if (newValue !== value) {
1140
- value = newValue;
1141
- subscribers.forEach(fn => fn(value));
1280
+ if (current.paused) return;
1281
+ if (typeof newValue === "function") newValue = newValue(current.value);
1282
+ if (newValue !== current.value) {
1283
+ current.value = newValue;
1284
+ current.subscribers.forEach(fn => fn(current.value));
1142
1285
  }
1143
1286
  }
1144
1287
 
1145
1288
  const controller = {
1146
- pause: () => { paused = true; },
1147
- resume: () => { paused = false; },
1148
- clear: () => { subscribers.clear(); },
1149
- force: (newValue) => { // force update even if paused
1150
- if (typeof newValue === "function") newValue = newValue(value);
1151
- value = newValue;
1152
- subscribers.forEach(fn => fn(value));
1289
+ pause: () => { current.paused = true; },
1290
+ resume: () => { current.paused = false; },
1291
+ clear: () => { current.subscribers.clear(); },
1292
+ force: (newValue) => {
1293
+ if (typeof newValue === "function") newValue = newValue(current.value);
1294
+ current.value = newValue;
1295
+ current.subscribers.forEach(fn => fn(current.value));
1153
1296
  },
1154
- getSubscribers: () => new Set(subscribers),
1297
+ getSubscribers: () => new Set(current.subscribers),
1155
1298
  };
1156
1299
 
1157
1300
  return [getValue, setValue, controller];
1158
1301
  }
1159
1302
 
1303
+
1160
1304
  const isStateGetter = (arg) => {
1161
- return typeof(arg) === 'function' && arg?.()?.isStateGetter?.()
1305
+ return typeof arg === 'function' && arg?.()?.isStateGetter?.();
1162
1306
  };
1163
1307
 
1164
1308
  const camel2hyphencase = (text = '') => text.replace(/[A-Z]/g, match => '-' + match.toLowerCase());
@@ -2737,110 +2881,9 @@
2737
2881
 
2738
2882
  const useMediaQuery = (mediaQueryRules,fallback) => new ZikoUseMediaQuery(mediaQueryRules,fallback);
2739
2883
 
2740
- function parseQueryParams$1(queryString) {
2741
- const params = {};
2742
- queryString.replace(/[A-Z0-9]+?=([\w|:|\/\.]*)/gi, (match) => {
2743
- const [key, value] = match.split('=');
2744
- params[key] = value;
2745
- });
2746
- return params;
2747
- }
2748
-
2749
- function defineParamsGetter$1(target ){
2750
- Object.defineProperties(target, {
2751
- 'QueryParams': {
2752
- get: function() {
2753
- return parseQueryParams$1(globalThis.location.search.substring(1));
2754
- },
2755
- configurable: false,
2756
- enumerable: true
2757
- },
2758
- 'HashParams': {
2759
- get: function() {
2760
- const hash = globalThis.location.hash.substring(1);
2761
- return hash.split("#");
2762
- },
2763
- configurable: false,
2764
- enumerable: true
2765
- }
2766
- });
2767
- }
2768
-
2769
- const __UI__={
2770
- __all__(){
2771
- return Object.values(this)
2772
- .filter(Array.isArray)
2773
- .flat();
2774
- },
2775
- querySelectorAll(){
2776
- return this.__all__().filter(n=>n)
2777
- },
2778
- getElementByIndex(index){
2779
- return this.__all__().find(n=>n.ui_index===index);
2780
- },
2781
- getElementById(id){
2782
- return null;
2783
- },
2784
- getElementsByClass(){
2785
-
2786
- },
2787
- getElementsByTagName(){
2788
-
2789
- }
2790
- };
2791
-
2792
- const __Config__ = {
2793
- default:{
2794
- target:null,
2795
- render:true,
2796
- math:{
2797
- mode:"deg"
2798
- }
2799
- },
2800
- setDefault:function(pairs){
2801
- const keys=Object.keys(pairs);
2802
- const values=Object.values(pairs);
2803
- for(let i=0; i<keys.length; i++) this.default[keys[i]]=values[i];
2804
- },
2805
- init:()=>{
2806
- // document.documentElement.setAttribute("data-engine","zikojs")
2807
- },
2808
- renderingMode :"spa",
2809
- isSSC : false,
2810
- };
2811
-
2812
- const __HYDRATION__ = {
2813
- map : new Map(),
2814
- index : 0,
2815
- increment : function(){
2816
- return this.index ++
2817
- }
2818
- };
2819
- const __HYDRATION_MAP__ = new Map();
2820
-
2821
- const __CACHE__ = {
2822
- ui_index : 0,
2823
- get_ui_index:function(){
2824
- return this.ui_index ++
2825
- }
2826
- };
2827
-
2828
- function __init__global__(){
2829
- if ( !globalThis?.__Ziko__ ){
2830
- globalThis.__Ziko__ = {
2831
- __UI__,
2832
- __HYDRATION__,
2833
- __HYDRATION_MAP__,
2834
- __Config__,
2835
- __CACHE__,
2836
- };
2837
- defineParamsGetter$1(__Ziko__);
2838
- }
2839
- }
2840
-
2841
2884
  __init__global__();
2842
2885
  class UIElement extends UINode{
2843
- constructor({element, name ='', type="html", useDefaultStyle=false}={}){
2886
+ constructor({element, name ='', type="html", render = __Ziko__.__Config__.default.render, useDefaultStyle=false}={}){
2844
2887
  super();
2845
2888
  this.target = globalThis.__Ziko__.__Config__.default.target||globalThis?.document?.body;
2846
2889
  if(typeof element === "string") {
@@ -2891,8 +2934,8 @@
2891
2934
  resize:null,
2892
2935
  intersection:null
2893
2936
  };
2894
- if(element)Object.assign(this.cache,{element});
2895
- this.uuid = `${this.cache.name}-${Random.string(16)}`;
2937
+ if(element) Object.assign(this.cache,{element});
2938
+ // this.uuid = `${this.cache.name}-${Random.string(16)}`
2896
2939
  this.ui_index = globalThis.__Ziko__.__CACHE__.get_ui_index();
2897
2940
  useDefaultStyle && this.style({
2898
2941
  position: "relative",
@@ -2902,9 +2945,9 @@
2902
2945
  width : "auto",
2903
2946
  height : "auto"
2904
2947
  });
2905
- this.items = [];
2948
+ this.items = new UIStore();
2906
2949
  globalThis.__Ziko__.__UI__[this.cache.name]?globalThis.__Ziko__.__UI__[this.cache.name]?.push(this):globalThis.__Ziko__.__UI__[this.cache.name]=[this];
2907
- element && globalThis.__Ziko__.__Config__.default.render && this?.render?.();
2950
+ element && render && this?.render?.();
2908
2951
  if(
2909
2952
  // globalThis.__Ziko__.__Config__.renderingMode !== "spa"
2910
2953
  // &&
@@ -2913,9 +2956,9 @@
2913
2956
  this.isInteractive()
2914
2957
  ){
2915
2958
  this.setAttr("ziko-hydration-index", globalThis.__Ziko__.__HYDRATION__.index);
2916
- globalThis.__Ziko__.__HYDRATION__.map.set(globalThis.__Ziko__.__HYDRATION__.index, ()=>this);
2917
- globalThis.__Ziko__.__HYDRATION__.increment();
2959
+ globalThis.__Ziko__.__HYDRATION__.register(() => this);
2918
2960
  }
2961
+ globalThis.__Ziko__.__UI__.push(this);
2919
2962
  }
2920
2963
  get element(){
2921
2964
  return this.cache.element;
@@ -2966,14 +3009,13 @@
2966
3009
  return this.element.getBoundingClientRect().left;
2967
3010
  }
2968
3011
  clone(render=false) {
2969
- const UI = new this.constructor();
2970
- UI.__proto__=this.__proto__;
2971
- if(this.items.length){
2972
- const items = [...this.items].map(n=>n.clone());
2973
- UI.append(...items);
2974
- }
2975
- else UI.element=this.element.cloneNode(true);
2976
- return UI.render(render);
3012
+ // UI.__proto__=this.__proto__;
3013
+ // if(this.items.length){
3014
+ // const items = [...this.items].map(n=>n.clone());
3015
+ // UI.append(...items);
3016
+ // }
3017
+ // else UI.element=this.element.cloneNode(true);
3018
+ // return UI.render(render);
2977
3019
  }
2978
3020
  [Symbol.iterator]() {
2979
3021
  return this.items[Symbol.iterator]();
@@ -2992,14 +3034,14 @@
2992
3034
  this.cache.isFrozzen=freeze;
2993
3035
  return this;
2994
3036
  }
2995
- setTarget(tg) {
2996
- if(this.isBody) return ;
2997
- if (tg?.isZikoUIElement) tg = tg.element;
2998
- this.unrender();
2999
- this.target = tg;
3000
- this.render();
3001
- return this;
3002
- }
3037
+ // setTarget(tg) {
3038
+ // if(this.isBody) return ;
3039
+ // if (tg?.isZikoUIElement) tg = tg.element;
3040
+ // this.unrender();
3041
+ // this.target = tg;
3042
+ // this.render();
3043
+ // return this;
3044
+ // }
3003
3045
  describe(label){
3004
3046
  if(label)this.setAttr("aria-label",label);
3005
3047
  }
@@ -3660,7 +3702,15 @@
3660
3702
 
3661
3703
  const Svg =(w,h)=>new ZikoUISvg(w,h);
3662
3704
 
3663
- function defineWC(name, UIElement, props = {}, { mode = 'open'} = {}) {
3705
+ function define_wc(name, UIElement, props = {}, { mode = 'open'} = {}) {
3706
+ if (globalThis.customElements?.get(name)) {
3707
+ console.warn(`Custom element "${name}" is already defined`);
3708
+ return; // skip redefinition
3709
+ }
3710
+ if(name.search('-') === -1){
3711
+ console.warn(`"${name}" is not a valid custom element name`);
3712
+ return;
3713
+ }
3664
3714
  globalThis.customElements?.define(
3665
3715
  name,
3666
3716
  class extends HTMLElement {
@@ -4522,7 +4572,7 @@
4522
4572
  }
4523
4573
  else if(("a" in b && "z" in a)){
4524
4574
  this.a=a.a;
4525
- this.b=sqrt$1((a.z**2)-(a.a**2));
4575
+ this.b=sqrt$2((a.z**2)-(a.a**2));
4526
4576
  }
4527
4577
  else if(("a" in b && "phi" in a)){
4528
4578
  this.a=a.a;
@@ -4530,15 +4580,15 @@
4530
4580
  }
4531
4581
  else if(("b" in b && "z" in a)){
4532
4582
  this.b=a.b;
4533
- this.a=sqrt$1((a.z**2)-(a.b**2));
4583
+ this.a=sqrt$2((a.z**2)-(a.b**2));
4534
4584
  }
4535
4585
  else if(("b" in b && "phi" in a)){
4536
4586
  this.b=b;
4537
4587
  this.a=a.b/tan(a.phi);
4538
4588
  }
4539
4589
  else if(("z" in b && "phi" in a)){
4540
- this.a=a.z*cos$1(a.phi);
4541
- this.a=a.z*sin$1(a.phi);
4590
+ this.a=a.z*cos$2(a.phi);
4591
+ this.a=a.z*sin$2(a.phi);
4542
4592
  }
4543
4593
  }
4544
4594
  else if(typeof(a)==="number"&&typeof(b)==="number"){
@@ -4606,8 +4656,8 @@
4606
4656
  }
4607
4657
  let Z=+prod(this.z,...z.map(n=>n.z)).toFixed(15);
4608
4658
  let phi=+sum(this.phi,...z.map(n=>n.phi)).toFixed(15);
4609
- this.a=+(Z*cos$1(phi).toFixed(15)).toFixed(14);
4610
- this.b=+(Z*sin$1(phi).toFixed(15)).toFixed(14);
4659
+ this.a=+(Z*cos$2(phi).toFixed(15)).toFixed(14);
4660
+ this.b=+(Z*sin$2(phi).toFixed(15)).toFixed(14);
4611
4661
  return this;
4612
4662
  }
4613
4663
  div(...z) {
@@ -4616,23 +4666,23 @@
4616
4666
  }
4617
4667
  let Z=+(this.z/prod(...z.map(n=>n.z))).toFixed(15);
4618
4668
  let phi=+(this.phi-sum(...z.map(n=>n.phi))).toFixed(15);
4619
- this.a=+(Z*cos$1(phi).toFixed(15)).toFixed(15);
4620
- this.b=+(Z*sin$1(phi).toFixed(15)).toFixed(15);
4669
+ this.a=+(Z*cos$2(phi).toFixed(15)).toFixed(15);
4670
+ this.b=+(Z*sin$2(phi).toFixed(15)).toFixed(15);
4621
4671
  return this;
4622
4672
  }
4623
4673
  pow(n) {
4624
4674
  if (floor(n) === n && n > 0) {
4625
4675
  let z=+(this.z**n).toFixed(15);
4626
4676
  let phi=+(this.phi*n).toFixed(15);
4627
- this.a=+(z*cos$1(phi).toFixed(15)).toFixed(15);
4628
- this.b=+(z*sin$1(phi).toFixed(15)).toFixed(15);
4677
+ this.a=+(z*cos$2(phi).toFixed(15)).toFixed(15);
4678
+ this.b=+(z*sin$2(phi).toFixed(15)).toFixed(15);
4629
4679
  }
4630
4680
  return this;
4631
4681
  }
4632
4682
  static fromExpo(z, phi) {
4633
4683
  return new Complex(
4634
- +(z * cos$1(phi)).toFixed(13),
4635
- +(z * sin$1(phi)).toFixed(13)
4684
+ +(z * cos$2(phi)).toFixed(13),
4685
+ +(z * sin$2(phi)).toFixed(13)
4636
4686
  );
4637
4687
  }
4638
4688
  get expo() {
@@ -4654,10 +4704,10 @@
4654
4704
  return z.clone.pow(n);
4655
4705
  }
4656
4706
  static xpowZ(x){
4657
- return complex((x**this.a)*cos$1(this.b*ln(x)),(x**this.a)*sin$1(this.b*ln(x)));
4707
+ return complex((x**this.a)*cos$2(this.b*ln(x)),(x**this.a)*sin$2(this.b*ln(x)));
4658
4708
  }
4659
4709
  sqrtn(n=2){
4660
- return complex(sqrtn(this.z,n)*cos$1(this.phi/n),sqrtn(this.z,n)*sin$1(this.phi/n));
4710
+ return complex(sqrtn(this.z,n)*cos$2(this.phi/n),sqrtn(this.z,n)*sin$2(this.phi/n));
4661
4711
  }
4662
4712
  get sqrt(){
4663
4713
  return this.sqrtn(2);
@@ -4666,14 +4716,14 @@
4666
4716
  return complex(this.z,this.phi);
4667
4717
  }
4668
4718
  get cos(){
4669
- return complex(cos$1(this.a)*cosh(this.b),sin$1(this.a)*sinh(this.b))
4719
+ return complex(cos$2(this.a)*cosh$1(this.b),sin$2(this.a)*sinh$1(this.b))
4670
4720
  }
4671
4721
  get sin(){
4672
- return complex(sin$1(this.a)*cosh(this.b),cos$1(this.a)*sinh(this.b))
4722
+ return complex(sin$2(this.a)*cosh$1(this.b),cos$2(this.a)*sinh$1(this.b))
4673
4723
  }
4674
4724
  get tan(){
4675
- const de=cos$1(this.a*2)+cosh(this.b*2);
4676
- return complex(sin$1(2*this.a)/de,sinh(2*this.b)/de);
4725
+ const de=cos$2(this.a*2)+cosh$1(this.b*2);
4726
+ return complex(sin$2(2*this.a)/de,sinh$1(2*this.b)/de);
4677
4727
  }
4678
4728
  printInConsole() {
4679
4729
  let string = this.a + " + " + this.b + " * i";
@@ -4704,7 +4754,7 @@
4704
4754
  // } from "../calculus/index.js";
4705
4755
 
4706
4756
  const abs=(...x)=>mapfun$1(Math.abs,...x);
4707
- const sqrt$1=(...x)=>mapfun$1(Math.sqrt,...x);
4757
+ const sqrt$2=(...x)=>mapfun$1(Math.sqrt,...x);
4708
4758
  const pow$1=(x,n)=>{
4709
4759
  if(typeof x === "number"){
4710
4760
  if(typeof n === "number")return Math.pow(x,n);
@@ -4752,8 +4802,8 @@
4752
4802
  };
4753
4803
  const e=(...x) => mapfun$1(Math.exp,...x);
4754
4804
  const ln=(...x) => mapfun$1(Math.log,...x);
4755
- const cos$1=(...x) => mapfun$1(Fixed.cos,...x);
4756
- const sin$1=(...x) => mapfun$1(Fixed.sin,...x);
4805
+ const cos$2=(...x) => mapfun$1(Fixed.cos,...x);
4806
+ const sin$2=(...x) => mapfun$1(Fixed.sin,...x);
4757
4807
  const tan=(...x) => mapfun$1(Fixed.tan,...x);
4758
4808
  const sec=(...x) => mapfun$1(Fixed.sec,...x);
4759
4809
  const sinc=(...x) => mapfun$1(Fixed.sinc,...x);
@@ -4763,8 +4813,8 @@
4763
4813
  const asin=(...x) => mapfun$1(Fixed.asin,...x);
4764
4814
  const atan=(...x) => mapfun$1(Fixed.atan,...x);
4765
4815
  const acot=(...x) => mapfun$1(Fixed.acot,...x);
4766
- const cosh=(...x) => mapfun$1(Fixed.cosh,...x);
4767
- const sinh=(...x) => mapfun$1(Fixed.sinh,...x);
4816
+ const cosh$1=(...x) => mapfun$1(Fixed.cosh,...x);
4817
+ const sinh$1=(...x) => mapfun$1(Fixed.sinh,...x);
4768
4818
  const tanh=(...x) => mapfun$1(Fixed.tanh,...x);
4769
4819
  const coth=(...x) => mapfun$1(Fixed.coth,...x);
4770
4820
  const acosh=(...x) => mapfun$1(Fixed.acosh,...x);
@@ -4813,12 +4863,12 @@
4813
4863
  )
4814
4864
  };
4815
4865
 
4816
- const {PI, sqrt, cos, sin, acos, pow} = Math;
4866
+ const {PI, sqrt: sqrt$1, cos: cos$1, sin: sin$1, acos, pow} = Math;
4817
4867
 
4818
4868
  const Linear = t => t;
4819
- const InSin = t => 1 - cos((t * PI) / 2);
4820
- const OutSin = t => sin((t * PI) / 2);
4821
- const InOutSin = t => -(cos(PI * t) - 1) / 2;
4869
+ const InSin = t => 1 - cos$1((t * PI) / 2);
4870
+ const OutSin = t => sin$1((t * PI) / 2);
4871
+ const InOutSin = t => -(cos$1(PI * t) - 1) / 2;
4822
4872
 
4823
4873
  const InQuad = t => t**2;
4824
4874
  const OutQuad = t => 1 - (1-t)**2;
@@ -4840,13 +4890,13 @@
4840
4890
  const OutExpo = t => t === 1 ? 1 : 1 - 2**(-10 * t);
4841
4891
  const InOutExpo = t => t === 0? 0: t === 1? 1: t < 0.5 ? 2**(20 * t - 10) / 2: (2 - 2**(-20 * t + 10)) / 2;
4842
4892
 
4843
- const InCirc = t => 1 - sqrt(1 - t**2);
4844
- const OutCirc = t => sqrt(1 - (t-1)**2);
4845
- const InOutCirc = t => t < 0.5? (1 - sqrt(1 - (2*t)**2)) / 2: (sqrt(1 - (-2*t+2)**2) + 1) / 2;
4893
+ const InCirc = t => 1 - sqrt$1(1 - t**2);
4894
+ const OutCirc = t => sqrt$1(1 - (t-1)**2);
4895
+ const InOutCirc = t => t < 0.5? (1 - sqrt$1(1 - (2*t)**2)) / 2: (sqrt$1(1 - (-2*t+2)**2) + 1) / 2;
4846
4896
 
4847
- const Arc = t => 1 - sin(acos(t));
4897
+ const Arc = t => 1 - sin$1(acos(t));
4848
4898
  const Back = (t, x = 1) => (t**2) * ((x+1)*t - x);
4849
- const Elastic = t => -2*pow(2, 10 * (t - 1)) * cos(20 * PI * t / 3 * t);
4899
+ const Elastic = t => -2*pow(2, 10 * (t - 1)) * cos$1(20 * PI * t / 3 * t);
4850
4900
 
4851
4901
  const InBack = (t, c1 = 1.70158, c3 = c1 + 1) => c3 * pow(t,3)- c1 * (t**2);
4852
4902
  const OutBack = (t, c1 = 1.70158, c3 = c1 + 1) => 1 + c3 * pow(t - 1, 3) + c1 * pow(t - 1, 2);
@@ -4857,7 +4907,7 @@
4857
4907
  ? 0
4858
4908
  : t === 1
4859
4909
  ? 1
4860
- : -pow(2, 10 * t - 10) * sin((t * 10 - 10.75) * c4);
4910
+ : -pow(2, 10 * t - 10) * sin$1((t * 10 - 10.75) * c4);
4861
4911
  };
4862
4912
 
4863
4913
  const OutElastic = (t, c4 = 2*PI/3) => {
@@ -4865,7 +4915,7 @@
4865
4915
  ? 0
4866
4916
  : t === 1
4867
4917
  ? 1
4868
- : pow(2, -10 * t) * sin((t * 10 - 0.75) * c4) + 1;
4918
+ : pow(2, -10 * t) * sin$1((t * 10 - 0.75) * c4) + 1;
4869
4919
  };
4870
4920
  const InOutElastic = (t, c5 = 2 * PI / 4.5) => {
4871
4921
  return t === 0
@@ -4873,8 +4923,8 @@
4873
4923
  : t === 1
4874
4924
  ? 1
4875
4925
  : t < 0.5
4876
- ? -(pow(2, 20 * t - 10) * sin((20 * t - 11.125) * c5)) / 2
4877
- : (pow(2, -20 * t + 10) * sin((20 * t - 11.125) * c5)) / 2 + 1;
4926
+ ? -(pow(2, 20 * t - 10) * sin$1((20 * t - 11.125) * c5)) / 2
4927
+ : (pow(2, -20 * t + 10) * sin$1((20 * t - 11.125) * c5)) / 2 + 1;
4878
4928
  };
4879
4929
 
4880
4930
  const InBounce = (t, n1 = 7.5625, d1 = 2.75) => 1 - OutBounce(1-t, n1, d1);
@@ -4982,17 +5032,28 @@
4982
5032
  new TimeAnimation(callback, {ease, t0, t1, start, duration});
4983
5033
 
4984
5034
  class Tick {
4985
- constructor(ms, fn) {
5035
+ constructor(fn, ms, count = Infinity, start) {
4986
5036
  this.ms = ms;
4987
5037
  this.fn = fn;
5038
+ this.count = count;
5039
+ this.frame = 1;
4988
5040
  this.id = null;
4989
5041
  this.running = false;
5042
+ if(start) this.start();
4990
5043
  }
4991
5044
 
4992
5045
  start() {
4993
5046
  if (!this.running) {
4994
5047
  this.running = true;
4995
- this.id = setInterval(this.fn, this.ms);
5048
+ this.frame = 1;
5049
+ this.id = setInterval(() => {
5050
+ if (this.frame > this.count) {
5051
+ this.stop();
5052
+ return;
5053
+ }
5054
+ this.fn.call(null, this);
5055
+ this.frame++;
5056
+ }, this.ms);
4996
5057
  }
4997
5058
  return this;
4998
5059
  }
@@ -5010,7 +5071,9 @@
5010
5071
  return this.running;
5011
5072
  }
5012
5073
  }
5013
- const tick = (ms, fn) => new Tick(ms, fn);
5074
+
5075
+ // Helper factory
5076
+ const tick = (fn, ms, count = Infinity, start = true) => new Tick(fn, ms, count, start);
5014
5077
 
5015
5078
  class Clock extends Tick {
5016
5079
  constructor(tickMs = 1000 / 60) {
@@ -5142,7 +5205,8 @@
5142
5205
  const step_fps = (step_or_fps) => 1000 / step_or_fps;
5143
5206
 
5144
5207
  const debounce=(fn,delay=1000)=>{
5145
- return (...args) => setTimeout(()=>fn(...args),delay);
5208
+ let id;
5209
+ return (...args) => id ? clearTimeout(id) : setTimeout(()=>fn(...args),delay);
5146
5210
  };
5147
5211
  const throttle=(fn,delay)=>{
5148
5212
  let lastTime=0;
@@ -5547,57 +5611,37 @@
5547
5611
  function useDerived(deriveFn, sources) {
5548
5612
  let value = deriveFn(...sources.map(s => s().value));
5549
5613
  const subscribers = new Set();
5550
- let paused = false;
5551
5614
 
5552
- function getValue() {
5553
- return {
5554
- value,
5555
- isStateGetter: () => true,
5556
- _subscribe: (fn) => {
5557
- subscribers.add(fn);
5558
- },
5559
- };
5560
- }
5561
-
5562
- function setValue(newValue) {
5563
- if (paused) return;
5564
- if (typeof newValue === "function") newValue = newValue(value);
5565
- if (newValue !== value) {
5566
- value = newValue;
5567
- subscribers.forEach(fn => fn(value));
5568
- }
5569
- }
5570
-
5571
- const controller = {
5572
- pause: () => { paused = true; },
5573
- resume: () => { paused = false; },
5574
- clear: () => { subscribers.clear(); },
5575
- force: (newValue) => {
5576
- if (typeof newValue === "function") newValue = newValue(value);
5577
- value = newValue;
5578
- subscribers.forEach(fn => fn(value));
5579
- },
5580
- getSubscribers: () => new Set(subscribers),
5581
- };
5582
-
5583
- // Subscribe to source states
5584
5615
  sources.forEach(source => {
5585
5616
  const srcValue = source(); // getValue()
5586
5617
  srcValue._subscribe(() => {
5587
- if (!paused) {
5618
+ {
5588
5619
  const newVal = deriveFn(...sources.map(s => s().value));
5589
5620
  if (newVal !== value) {
5590
5621
  value = newVal;
5591
5622
  subscribers.forEach(fn => fn(value));
5592
5623
  }
5593
5624
  }
5594
- }, { element: document.body }); // dummy UIElement
5625
+ });
5595
5626
  });
5596
-
5597
- return [getValue, setValue, controller];
5627
+ return () => ({
5628
+ value,
5629
+ isStateGetter : () => true,
5630
+ _subscribe: (fn) => subscribers.add(fn)
5631
+ })
5598
5632
  }
5599
5633
 
5600
- const useReactive = (nested_value) => mapfun$1(n => useState(n), nested_value);
5634
+ const useReactive = (nested_value) => mapfun$1(
5635
+ n => {
5636
+ const state = useState(n);
5637
+ // console.log(state)
5638
+ return {
5639
+ get : state[0],
5640
+ set : state[1],
5641
+ }
5642
+ },
5643
+ nested_value
5644
+ );
5601
5645
 
5602
5646
  class ZikoUseChannel{
5603
5647
  constructor(name = ""){
@@ -5833,6 +5877,65 @@
5833
5877
  const useLocaleStorage=(key,initialValue)=>new ZikoUseStorage(localStorage,key,initialValue);
5834
5878
  const useSessionStorage=(key,initialValue)=>new ZikoUseStorage(sessionStorage,key,initialValue);
5835
5879
 
5880
+ let {sqrt, cos, sin, exp, log, cosh, sinh} = Math;
5881
+ // Math.abs = new Proxy(Math.abs, {
5882
+ // apply(target, thisArg, args) {
5883
+ // const x = args[0]
5884
+ // if(typeof x === 'number') return target.apply(thisArg, args);
5885
+ // if(x?.isComplex?.()){
5886
+ // const {a, b, z, phi} = x
5887
+ // const complex = (a, b) => new x.constructor(a, b)
5888
+ // switch(target.name){
5889
+ // case 'abs' : return a.z;
5890
+ // case 'sqrt' : return complex(sqrt(z)*cos(phi/2),sqrt(z)*sin(phi/2));
5891
+ // }
5892
+ // }
5893
+
5894
+ // }
5895
+ // });
5896
+
5897
+
5898
+ for (const key of Object.getOwnPropertyNames(Math)) {
5899
+ const fn = Math[key];
5900
+ if (typeof fn === "function") {
5901
+ Math[key] = new Proxy(fn, {
5902
+ apply(target, thisArg, args) {
5903
+ // console.log(target)
5904
+ const x = args[0];
5905
+ if(typeof x === 'number' || args.length === 0) return target.apply(thisArg, args);
5906
+ if(x?.isComplex?.()){
5907
+ const {a, b, z, phi} = x;
5908
+ const complex = (a, b) => new x.constructor(a, b);
5909
+ switch(target.name){
5910
+ case 'abs' : return x.z;
5911
+ case 'sqrt' : return complex(sqrt(z)*cos(phi/2),sqrt(z)*sin(phi/2));
5912
+ case 'log' : return complex(log(z), phi);
5913
+ case 'exp' : return complex(exp(a)*cos(b),exp(a)*sin(b));
5914
+ case 'cos' : return complex(cos(a)*cosh(b),-(sin(a)*sinh(b)));
5915
+ case 'sin' : return complex(sin(a)*cosh(b),cos(a)*sinh(b));
5916
+ case 'tan' : {
5917
+ const DEN = cos(2*a)+cosh(2*b);
5918
+ return complex(sin(2*a) /DEN, sinh(2*b)/DEN);
5919
+ }
5920
+ case 'cosh' : return complex(cosh(a)*cos(b),sinh(a)*sin(b));
5921
+ case 'sinh' : return complex(sinh(a)*cos(b),cosh(a)*sin(b));
5922
+ case 'tanh' : {
5923
+ const DEN=cosh(2*a)+cos(2*b);
5924
+ return complex(sinh(2*a)/DEN,sin(2*b)/DEN)
5925
+ }
5926
+ default : return target.apply(thisArg, args)
5927
+ }
5928
+ }
5929
+ // if( x.isMatrix?.()){
5930
+ // const {rows, cols, arr} = x
5931
+ // // return new x.constructor(rows, cols, arr.flat(1).map(n=>));
5932
+ // }
5933
+ throw new TypeError(`Math.${key} expects only numbers`);
5934
+ }
5935
+ });
5936
+ }
5937
+ }
5938
+
5836
5939
  if(globalThis?.document){
5837
5940
  document?.addEventListener("DOMContentLoaded", __Ziko__.__Config__.init());
5838
5941
  }
@@ -5961,8 +6064,8 @@
5961
6064
  exports.clock = clock;
5962
6065
  exports.combinaison = combinaison;
5963
6066
  exports.complex = complex;
5964
- exports.cos = cos$1;
5965
- exports.cosh = cosh;
6067
+ exports.cos = cos$2;
6068
+ exports.cosh = cosh$1;
5966
6069
  exports.cot = cot;
5967
6070
  exports.coth = coth;
5968
6071
  exports.csc = csc;
@@ -5973,7 +6076,7 @@
5973
6076
  exports.csv2sql = csv2sql;
5974
6077
  exports.debounce = debounce;
5975
6078
  exports.defineParamsGetter = defineParamsGetter;
5976
- exports.defineWC = defineWC;
6079
+ exports.define_wc = define_wc;
5977
6080
  exports.deg2rad = deg2rad;
5978
6081
  exports.div = div;
5979
6082
  exports.e = e;
@@ -6023,11 +6126,11 @@
6023
6126
  exports.sec = sec;
6024
6127
  exports.sig = sig;
6025
6128
  exports.sign = sign;
6026
- exports.sin = sin$1;
6129
+ exports.sin = sin$2;
6027
6130
  exports.sinc = sinc;
6028
- exports.sinh = sinh;
6131
+ exports.sinh = sinh$1;
6029
6132
  exports.sleep = sleep;
6030
- exports.sqrt = sqrt$1;
6133
+ exports.sqrt = sqrt$2;
6031
6134
  exports.sqrtn = sqrtn;
6032
6135
  exports.step_fps = step_fps;
6033
6136
  exports.sub = sub;