ziko 0.41.1 → 0.42.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.
package/dist/ziko.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
  /*
3
3
  Project: ziko.js
4
4
  Author: Zakaria Elalaoui
5
- Date : Fri Aug 22 2025 10:51:33 GMT+0100 (UTC+01:00)
5
+ Date : Sun Aug 24 2025 12:13:24 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
@@ -13,23 +13,23 @@
13
13
  const { PI: PI$2, E } = Math;
14
14
  const EPSILON=Number.EPSILON;
15
15
 
16
- 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;
16
+ 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;
17
17
  let Fixed={
18
- cos: cos$2,
19
- sin: sin$2,
18
+ cos: cos$3,
19
+ sin: sin$3,
20
20
  tan: tan$1,
21
- sinc: x => sin$2(PI$1*x)/(PI$1*x),
22
- sec: x => 1/cos$2(x),
23
- csc: x => 1/sin$2(x),
21
+ sinc: x => sin$3(PI$1*x)/(PI$1*x),
22
+ sec: x => 1/cos$3(x),
23
+ csc: x => 1/sin$3(x),
24
24
  cot: x => 1/tan$1(x),
25
25
  acos: acos$2,
26
26
  asin: asin$1,
27
27
  atan: atan$1,
28
28
  acot: x => PI$1/2-atan$1(x),
29
- cosh: cosh$1,
30
- sinh: sinh$1,
29
+ cosh: cosh$2,
30
+ sinh: sinh$2,
31
31
  tanh: tanh$1,
32
- coth: n => (1/2*log((1+n)/(1-n))),
32
+ coth: n => (1/2*log$1((1+n)/(1-n))),
33
33
  acosh: acosh$1,
34
34
  asinh: asinh$1,
35
35
  atanh: atanh$1,
@@ -63,20 +63,20 @@ const mapfun$1=(fun,...X)=>{
63
63
  const [a,b,z,phi]=[x.a,x.b,x.z,x.phi];
64
64
  switch(fun){
65
65
  case Math.log: return complex(ln(z),phi); // Done
66
- case Math.exp: return complex(e(a)*cos$1(b),e(a)*sin$1(b)); // Done
66
+ case Math.exp: return complex(e(a)*cos$2(b),e(a)*sin$2(b)); // Done
67
67
  case Math.abs: return z; // Done
68
- case Math.sqrt: return complex(sqrt$1(z)*cos$1(phi/2),sqrt$1(z)*sin$1(phi/2)); // Done
69
- case Fixed.cos: return complex(cos$1(a)*cosh(b),-(sin$1(a)*sinh(b)));
70
- case Fixed.sin: return complex(sin$1(a)*cosh(b),cos$1(a)*sinh(b));
68
+ case Math.sqrt: return complex(sqrt$2(z)*cos$2(phi/2),sqrt$2(z)*sin$2(phi/2)); // Done
69
+ case Fixed.cos: return complex(cos$2(a)*cosh$1(b),-(sin$2(a)*sinh$1(b)));
70
+ case Fixed.sin: return complex(sin$2(a)*cosh$1(b),cos$2(a)*sinh$1(b));
71
71
  case Fixed.tan:{
72
- const DEN = cos$1(2*a)+cosh(2*b);
73
- return complex(sin$1(2*a)/DEN,sinh(2*b)/DEN);
72
+ const DEN = cos$2(2*a)+cosh$1(2*b);
73
+ return complex(sin$2(2*a)/DEN,sinh$1(2*b)/DEN);
74
74
  }
75
- case Fixed.cosh:return complex(cosh(a)*cos$1(b),sinh(a)*sin$1(b));
76
- case Fixed.sinh:return complex(sinh(a)*cos$1(b),cosh(a)*sin$1(b));
75
+ case Fixed.cosh:return complex(cosh$1(a)*cos$2(b),sinh$1(a)*sin$2(b));
76
+ case Fixed.sinh:return complex(sinh$1(a)*cos$2(b),cosh$1(a)*sin$2(b));
77
77
  case Fixed.tanh:{
78
- const DEN=cosh(2*a)+cos$1(2*b);
79
- return complex(sinh(2*a)/DEN,sin$1(2*b)/DEN)
78
+ const DEN=cosh$1(2*a)+cos$2(2*b);
79
+ return complex(sinh$1(2*a)/DEN,sin$2(2*b)/DEN)
80
80
  }
81
81
  default : return fun(x)
82
82
  }
@@ -947,6 +947,21 @@ const preload=(url)=>{
947
947
  }
948
948
  };
949
949
 
950
+ async function fetchdom(url='https://github.com/zakarialaoui10'){
951
+ const data=await fetch(url);
952
+ const html=await data.text();
953
+ const dom= new DOMParser().parseFromString(html,'text/xml');
954
+ return dom.documentElement
955
+ }
956
+ function fetchdomSync(url='https://github.com/zakarialaoui10'){
957
+ const data=preload(url);
958
+ const dom= new DOMParser().parseFromString(data,'text/xml');
959
+ return dom.documentElement;
960
+ }
961
+
962
+ globalThis.fetchdom=fetchdom;
963
+ globalThis.fetchdomSync=fetchdomSync;
964
+
950
965
  const csv2arr = (csv, delimiter = ",")=>csv.trim().trimEnd().split("\n").map(n=>n.split(delimiter));
951
966
  const csv2matrix = (csv, delimiter = ",")=>new Matrix(csv2arr(csv,delimiter));
952
967
  const csv2object = (csv, delimiter = ",") => {
@@ -1102,59 +1117,180 @@ const register = (target, ...mixins) => {
1102
1117
  else register_to_instance(target, ...mixins);
1103
1118
  };
1104
1119
 
1120
+ function parseQueryParams$1(queryString) {
1121
+ const params = {};
1122
+ queryString.replace(/[A-Z0-9]+?=([\w|:|\/\.]*)/gi, (match) => {
1123
+ const [key, value] = match.split('=');
1124
+ params[key] = value;
1125
+ });
1126
+ return params;
1127
+ }
1128
+
1129
+ function defineParamsGetter$1(target ){
1130
+ Object.defineProperties(target, {
1131
+ 'QueryParams': {
1132
+ get: function() {
1133
+ return parseQueryParams$1(globalThis.location.search.substring(1));
1134
+ },
1135
+ configurable: false,
1136
+ enumerable: true
1137
+ },
1138
+ 'HashParams': {
1139
+ get: function() {
1140
+ const hash = globalThis.location.hash.substring(1);
1141
+ return hash.split("#");
1142
+ },
1143
+ configurable: false,
1144
+ enumerable: true
1145
+ }
1146
+ });
1147
+ }
1148
+
1149
+ const __UI__={
1150
+ __all__(){
1151
+ return Object.values(this)
1152
+ .filter(Array.isArray)
1153
+ .flat();
1154
+ },
1155
+ querySelectorAll(){
1156
+ return this.__all__().filter(n=>n)
1157
+ },
1158
+ getElementByIndex(index){
1159
+ return this.__all__().find(n=>n.ui_index===index);
1160
+ },
1161
+ getElementById(id){
1162
+ return null;
1163
+ },
1164
+ getElementsByClass(){
1165
+
1166
+ },
1167
+ getElementsByTagName(){
1168
+
1169
+ }
1170
+ };
1171
+
1172
+ const __Config__ = {
1173
+ default:{
1174
+ target:null,
1175
+ render:true,
1176
+ math:{
1177
+ mode:"deg"
1178
+ }
1179
+ },
1180
+ setDefault:function(pairs){
1181
+ const keys=Object.keys(pairs);
1182
+ const values=Object.values(pairs);
1183
+ for(let i=0; i<keys.length; i++) this.default[keys[i]]=values[i];
1184
+ },
1185
+ init:()=>{
1186
+ // document.documentElement.setAttribute("data-engine","zikojs")
1187
+ },
1188
+ renderingMode :"spa",
1189
+ isSSC : false,
1190
+ };
1191
+
1192
+ const __HYDRATION__ = {
1193
+ map : new Map(),
1194
+ index : 0,
1195
+ increment : function(){
1196
+ return this.index ++
1197
+ }
1198
+ };
1199
+
1200
+ const __CACHE__ = {
1201
+ ui_index : 0,
1202
+ get_ui_index:function(){
1203
+ return this.ui_index ++
1204
+ }
1205
+ };
1206
+
1207
+ const __State__ = {
1208
+ store : new Map(),
1209
+ index : undefined?.data?.__Ziko__?.__State__?.index ?? 0,
1210
+ register: function(state){
1211
+ console.log({
1212
+ hmr : undefined?.data.__Ziko__.__State__.index,
1213
+ index : this.index
1214
+ });
1215
+ this.store.set(this.index++, state);
1216
+ }
1217
+
1218
+ };
1219
+
1220
+ function __init__global__(){
1221
+ if ( !globalThis?.__Ziko__ ){
1222
+ globalThis.__Ziko__ = {
1223
+ __UI__,
1224
+ __HYDRATION__,
1225
+ __State__,
1226
+ // __HYDRATION_MAP__,
1227
+ __Config__,
1228
+ __CACHE__,
1229
+ };
1230
+ defineParamsGetter$1(__Ziko__);
1231
+ }
1232
+ }
1233
+
1234
+ if(!globalThis.__Ziko__) __init__global__();
1235
+
1236
+ // HMR persistence
1237
+ if (undefined) {
1238
+ undefined.data.__Ziko__ = undefined.data.__Ziko__ || globalThis.__Ziko__;
1239
+ globalThis.__Ziko__ = undefined.data.__Ziko__;
1240
+ // import.meta.hot.accept(n=>console.log(n));
1241
+ // console.log(import.meta.hot.data.__Ziko__.__State__.store)
1242
+ }
1243
+
1244
+
1245
+
1105
1246
  function useState(initialValue) {
1106
- let value = initialValue;
1107
- const subscribers = new Set();
1108
- let paused = false;
1247
+
1248
+ // console.log(import.meta.hot.data.__Ziko__.__State__.store.get(0))
1249
+
1250
+ const {store, index} = __Ziko__.__State__;
1251
+ __Ziko__.__State__.register({
1252
+ value : initialValue,
1253
+ subscribers : new Set(),
1254
+ paused : false
1255
+ });
1256
+
1257
+ const current = store.get(index);
1109
1258
 
1110
1259
  function getValue() {
1111
1260
  return {
1112
- value,
1261
+ value: current.value,
1113
1262
  isStateGetter: () => true,
1114
- _subscribe: (
1115
- fn,
1116
- // UIElement
1117
- ) => {
1118
- subscribers.add(fn);
1119
-
1120
- // const observer = new MutationObserver(() => {
1121
- // if (!document.body.contains(UIElement.element)) {
1122
- // subscribers.delete(fn);
1123
- // observer.disconnect();
1124
- // }
1125
- // });
1126
-
1127
- // observer.observe(document.body, { childList: true, subtree: true });
1128
- },
1263
+ _subscribe: (fn) => current.subscribers.add(fn),
1129
1264
  };
1130
1265
  }
1131
1266
 
1132
1267
  function setValue(newValue) {
1133
- if (paused) return;
1134
- if (typeof newValue === "function") newValue = newValue(value);
1135
- if (newValue !== value) {
1136
- value = newValue;
1137
- subscribers.forEach(fn => fn(value));
1268
+ if (current.paused) return;
1269
+ if (typeof newValue === "function") newValue = newValue(current.value);
1270
+ if (newValue !== current.value) {
1271
+ current.value = newValue;
1272
+ current.subscribers.forEach(fn => fn(current.value));
1138
1273
  }
1139
1274
  }
1140
1275
 
1141
1276
  const controller = {
1142
- pause: () => { paused = true; },
1143
- resume: () => { paused = false; },
1144
- clear: () => { subscribers.clear(); },
1145
- force: (newValue) => { // force update even if paused
1146
- if (typeof newValue === "function") newValue = newValue(value);
1147
- value = newValue;
1148
- subscribers.forEach(fn => fn(value));
1277
+ pause: () => { current.paused = true; },
1278
+ resume: () => { current.paused = false; },
1279
+ clear: () => { current.subscribers.clear(); },
1280
+ force: (newValue) => {
1281
+ if (typeof newValue === "function") newValue = newValue(current.value);
1282
+ current.value = newValue;
1283
+ current.subscribers.forEach(fn => fn(current.value));
1149
1284
  },
1150
- getSubscribers: () => new Set(subscribers),
1285
+ getSubscribers: () => new Set(current.subscribers),
1151
1286
  };
1152
1287
 
1153
1288
  return [getValue, setValue, controller];
1154
1289
  }
1155
1290
 
1291
+
1156
1292
  const isStateGetter = (arg) => {
1157
- return typeof(arg) === 'function' && arg?.()?.isStateGetter?.()
1293
+ return typeof arg === 'function' && arg?.()?.isStateGetter?.();
1158
1294
  };
1159
1295
 
1160
1296
  const camel2hyphencase = (text = '') => text.replace(/[A-Z]/g, match => '-' + match.toLowerCase());
@@ -2733,107 +2869,6 @@ class ZikoUseMediaQuery {
2733
2869
 
2734
2870
  const useMediaQuery = (mediaQueryRules,fallback) => new ZikoUseMediaQuery(mediaQueryRules,fallback);
2735
2871
 
2736
- function parseQueryParams$1(queryString) {
2737
- const params = {};
2738
- queryString.replace(/[A-Z0-9]+?=([\w|:|\/\.]*)/gi, (match) => {
2739
- const [key, value] = match.split('=');
2740
- params[key] = value;
2741
- });
2742
- return params;
2743
- }
2744
-
2745
- function defineParamsGetter$1(target ){
2746
- Object.defineProperties(target, {
2747
- 'QueryParams': {
2748
- get: function() {
2749
- return parseQueryParams$1(globalThis.location.search.substring(1));
2750
- },
2751
- configurable: false,
2752
- enumerable: true
2753
- },
2754
- 'HashParams': {
2755
- get: function() {
2756
- const hash = globalThis.location.hash.substring(1);
2757
- return hash.split("#");
2758
- },
2759
- configurable: false,
2760
- enumerable: true
2761
- }
2762
- });
2763
- }
2764
-
2765
- const __UI__={
2766
- __all__(){
2767
- return Object.values(this)
2768
- .filter(Array.isArray)
2769
- .flat();
2770
- },
2771
- querySelectorAll(){
2772
- return this.__all__().filter(n=>n)
2773
- },
2774
- getElementByIndex(index){
2775
- return this.__all__().find(n=>n.ui_index===index);
2776
- },
2777
- getElementById(id){
2778
- return null;
2779
- },
2780
- getElementsByClass(){
2781
-
2782
- },
2783
- getElementsByTagName(){
2784
-
2785
- }
2786
- };
2787
-
2788
- const __Config__ = {
2789
- default:{
2790
- target:null,
2791
- render:true,
2792
- math:{
2793
- mode:"deg"
2794
- }
2795
- },
2796
- setDefault:function(pairs){
2797
- const keys=Object.keys(pairs);
2798
- const values=Object.values(pairs);
2799
- for(let i=0; i<keys.length; i++) this.default[keys[i]]=values[i];
2800
- },
2801
- init:()=>{
2802
- // document.documentElement.setAttribute("data-engine","zikojs")
2803
- },
2804
- renderingMode :"spa",
2805
- isSSC : false,
2806
- };
2807
-
2808
- const __HYDRATION__ = {
2809
- map : new Map(),
2810
- index : 0,
2811
- increment : function(){
2812
- return this.index ++
2813
- }
2814
- };
2815
- const __HYDRATION_MAP__ = new Map();
2816
-
2817
- const __CACHE__ = {
2818
- ui_index : 0,
2819
- get_ui_index:function(){
2820
- return this.ui_index ++
2821
- }
2822
- };
2823
-
2824
- function __init__global__(){
2825
- if ( !globalThis?.__Ziko__ ){
2826
- globalThis.__Ziko__ = {
2827
- __UI__,
2828
- __HYDRATION__,
2829
- __HYDRATION_MAP__,
2830
- __Config__,
2831
- __CACHE__,
2832
- };
2833
- defineParamsGetter$1(__Ziko__);
2834
- }
2835
- }
2836
-
2837
2872
  __init__global__();
2838
2873
  class UIElement extends UINode{
2839
2874
  constructor({element, name ='', type="html", useDefaultStyle=false}={}){
@@ -3656,38 +3691,45 @@ class ZikoUISvg extends UIElement {
3656
3691
 
3657
3692
  const Svg =(w,h)=>new ZikoUISvg(w,h);
3658
3693
 
3659
- function defineWC(name, UIElement, props = {}, { mode = 'open'} = {}){
3694
+ function define_wc(name, UIElement, props = {}, { mode = 'open'} = {}) {
3695
+ if (globalThis.customElements?.get(name)) {
3696
+ console.warn(`Custom element "${name}" is already defined`);
3697
+ return; // skip redefinition
3698
+ }
3699
+ if(name.search('-') === -1){
3700
+ console.warn(`"${name}" is not a valid custom element name`);
3701
+ return;
3702
+ }
3660
3703
  globalThis.customElements?.define(
3661
3704
  name,
3662
- class extends HTMLElement{
3663
- static observedAttributes = ['style',...Object.keys(props)];
3664
- constructor(){
3705
+ class extends HTMLElement {
3706
+ static get observedAttributes() {
3707
+ return ['style', ...Object.keys(props)];
3708
+ }
3709
+
3710
+ constructor() {
3665
3711
  super();
3666
3712
  this.attachShadow({ mode });
3667
3713
  this.props = {};
3668
3714
  this.mask = {
3669
3715
  ...props,
3670
- // ...{
3671
- // style : { type : Object}
3672
- // }
3716
+ // style: { type: Object }
3673
3717
  };
3674
3718
  }
3675
- connectedCallback(){
3719
+
3720
+ connectedCallback() {
3676
3721
  this.render();
3677
- // console.log(this.props)
3678
3722
  }
3679
- render(){
3723
+
3724
+ render() {
3680
3725
  this.shadowRoot.innerHTML = '';
3681
- // this.UIElement = UIElement(this.props).render(this.shadowRoot)
3682
- UIElement({attrs:(key, value) => console.log({key, value})}).render(this.shadowRoot);
3683
- UIElement(a => console.log(a)).render(this.shadowRoot);
3684
- // this.UIElement = (()=>{
3685
- // UIElement(this.props).render(this.shadowRoot);
3686
- // })()
3687
- // this.UIElement.setTarget(this.shadowRoot);
3726
+ this.UIElement = UIElement(this.props).render(this.shadowRoot);
3688
3727
  }
3728
+
3689
3729
  attributeChangedCallback(name, _, newValue) {
3690
- Object.assign(this.props, {[name] : this.mask[name].type(newValue)});
3730
+ Object.assign(this.props, {
3731
+ [name]: this.mask[name].type(newValue)
3732
+ });
3691
3733
  this.render();
3692
3734
  }
3693
3735
  }
@@ -4519,7 +4561,7 @@ class Complex extends ZikoMath{
4519
4561
  }
4520
4562
  else if(("a" in b && "z" in a)){
4521
4563
  this.a=a.a;
4522
- this.b=sqrt$1((a.z**2)-(a.a**2));
4564
+ this.b=sqrt$2((a.z**2)-(a.a**2));
4523
4565
  }
4524
4566
  else if(("a" in b && "phi" in a)){
4525
4567
  this.a=a.a;
@@ -4527,15 +4569,15 @@ class Complex extends ZikoMath{
4527
4569
  }
4528
4570
  else if(("b" in b && "z" in a)){
4529
4571
  this.b=a.b;
4530
- this.a=sqrt$1((a.z**2)-(a.b**2));
4572
+ this.a=sqrt$2((a.z**2)-(a.b**2));
4531
4573
  }
4532
4574
  else if(("b" in b && "phi" in a)){
4533
4575
  this.b=b;
4534
4576
  this.a=a.b/tan(a.phi);
4535
4577
  }
4536
4578
  else if(("z" in b && "phi" in a)){
4537
- this.a=a.z*cos$1(a.phi);
4538
- this.a=a.z*sin$1(a.phi);
4579
+ this.a=a.z*cos$2(a.phi);
4580
+ this.a=a.z*sin$2(a.phi);
4539
4581
  }
4540
4582
  }
4541
4583
  else if(typeof(a)==="number"&&typeof(b)==="number"){
@@ -4603,8 +4645,8 @@ class Complex extends ZikoMath{
4603
4645
  }
4604
4646
  let Z=+prod(this.z,...z.map(n=>n.z)).toFixed(15);
4605
4647
  let phi=+sum(this.phi,...z.map(n=>n.phi)).toFixed(15);
4606
- this.a=+(Z*cos$1(phi).toFixed(15)).toFixed(14);
4607
- this.b=+(Z*sin$1(phi).toFixed(15)).toFixed(14);
4648
+ this.a=+(Z*cos$2(phi).toFixed(15)).toFixed(14);
4649
+ this.b=+(Z*sin$2(phi).toFixed(15)).toFixed(14);
4608
4650
  return this;
4609
4651
  }
4610
4652
  div(...z) {
@@ -4613,23 +4655,23 @@ class Complex extends ZikoMath{
4613
4655
  }
4614
4656
  let Z=+(this.z/prod(...z.map(n=>n.z))).toFixed(15);
4615
4657
  let phi=+(this.phi-sum(...z.map(n=>n.phi))).toFixed(15);
4616
- this.a=+(Z*cos$1(phi).toFixed(15)).toFixed(15);
4617
- this.b=+(Z*sin$1(phi).toFixed(15)).toFixed(15);
4658
+ this.a=+(Z*cos$2(phi).toFixed(15)).toFixed(15);
4659
+ this.b=+(Z*sin$2(phi).toFixed(15)).toFixed(15);
4618
4660
  return this;
4619
4661
  }
4620
4662
  pow(n) {
4621
4663
  if (floor(n) === n && n > 0) {
4622
4664
  let z=+(this.z**n).toFixed(15);
4623
4665
  let phi=+(this.phi*n).toFixed(15);
4624
- this.a=+(z*cos$1(phi).toFixed(15)).toFixed(15);
4625
- this.b=+(z*sin$1(phi).toFixed(15)).toFixed(15);
4666
+ this.a=+(z*cos$2(phi).toFixed(15)).toFixed(15);
4667
+ this.b=+(z*sin$2(phi).toFixed(15)).toFixed(15);
4626
4668
  }
4627
4669
  return this;
4628
4670
  }
4629
4671
  static fromExpo(z, phi) {
4630
4672
  return new Complex(
4631
- +(z * cos$1(phi)).toFixed(13),
4632
- +(z * sin$1(phi)).toFixed(13)
4673
+ +(z * cos$2(phi)).toFixed(13),
4674
+ +(z * sin$2(phi)).toFixed(13)
4633
4675
  );
4634
4676
  }
4635
4677
  get expo() {
@@ -4651,10 +4693,10 @@ class Complex extends ZikoMath{
4651
4693
  return z.clone.pow(n);
4652
4694
  }
4653
4695
  static xpowZ(x){
4654
- return complex((x**this.a)*cos$1(this.b*ln(x)),(x**this.a)*sin$1(this.b*ln(x)));
4696
+ return complex((x**this.a)*cos$2(this.b*ln(x)),(x**this.a)*sin$2(this.b*ln(x)));
4655
4697
  }
4656
4698
  sqrtn(n=2){
4657
- return complex(sqrtn(this.z,n)*cos$1(this.phi/n),sqrtn(this.z,n)*sin$1(this.phi/n));
4699
+ return complex(sqrtn(this.z,n)*cos$2(this.phi/n),sqrtn(this.z,n)*sin$2(this.phi/n));
4658
4700
  }
4659
4701
  get sqrt(){
4660
4702
  return this.sqrtn(2);
@@ -4663,14 +4705,14 @@ class Complex extends ZikoMath{
4663
4705
  return complex(this.z,this.phi);
4664
4706
  }
4665
4707
  get cos(){
4666
- return complex(cos$1(this.a)*cosh(this.b),sin$1(this.a)*sinh(this.b))
4708
+ return complex(cos$2(this.a)*cosh$1(this.b),sin$2(this.a)*sinh$1(this.b))
4667
4709
  }
4668
4710
  get sin(){
4669
- return complex(sin$1(this.a)*cosh(this.b),cos$1(this.a)*sinh(this.b))
4711
+ return complex(sin$2(this.a)*cosh$1(this.b),cos$2(this.a)*sinh$1(this.b))
4670
4712
  }
4671
4713
  get tan(){
4672
- const de=cos$1(this.a*2)+cosh(this.b*2);
4673
- return complex(sin$1(2*this.a)/de,sinh(2*this.b)/de);
4714
+ const de=cos$2(this.a*2)+cosh$1(this.b*2);
4715
+ return complex(sin$2(2*this.a)/de,sinh$1(2*this.b)/de);
4674
4716
  }
4675
4717
  printInConsole() {
4676
4718
  let string = this.a + " + " + this.b + " * i";
@@ -4701,7 +4743,7 @@ const complex=(a,b)=>{
4701
4743
  // } from "../calculus/index.js";
4702
4744
 
4703
4745
  const abs=(...x)=>mapfun$1(Math.abs,...x);
4704
- const sqrt$1=(...x)=>mapfun$1(Math.sqrt,...x);
4746
+ const sqrt$2=(...x)=>mapfun$1(Math.sqrt,...x);
4705
4747
  const pow$1=(x,n)=>{
4706
4748
  if(typeof x === "number"){
4707
4749
  if(typeof n === "number")return Math.pow(x,n);
@@ -4749,8 +4791,8 @@ const sqrtn=(x,n)=>{
4749
4791
  };
4750
4792
  const e=(...x) => mapfun$1(Math.exp,...x);
4751
4793
  const ln=(...x) => mapfun$1(Math.log,...x);
4752
- const cos$1=(...x) => mapfun$1(Fixed.cos,...x);
4753
- const sin$1=(...x) => mapfun$1(Fixed.sin,...x);
4794
+ const cos$2=(...x) => mapfun$1(Fixed.cos,...x);
4795
+ const sin$2=(...x) => mapfun$1(Fixed.sin,...x);
4754
4796
  const tan=(...x) => mapfun$1(Fixed.tan,...x);
4755
4797
  const sec=(...x) => mapfun$1(Fixed.sec,...x);
4756
4798
  const sinc=(...x) => mapfun$1(Fixed.sinc,...x);
@@ -4760,8 +4802,8 @@ const acos$1=(...x) => mapfun$1(Fixed.acos,...x);
4760
4802
  const asin=(...x) => mapfun$1(Fixed.asin,...x);
4761
4803
  const atan=(...x) => mapfun$1(Fixed.atan,...x);
4762
4804
  const acot=(...x) => mapfun$1(Fixed.acot,...x);
4763
- const cosh=(...x) => mapfun$1(Fixed.cosh,...x);
4764
- const sinh=(...x) => mapfun$1(Fixed.sinh,...x);
4805
+ const cosh$1=(...x) => mapfun$1(Fixed.cosh,...x);
4806
+ const sinh$1=(...x) => mapfun$1(Fixed.sinh,...x);
4765
4807
  const tanh=(...x) => mapfun$1(Fixed.tanh,...x);
4766
4808
  const coth=(...x) => mapfun$1(Fixed.coth,...x);
4767
4809
  const acosh=(...x) => mapfun$1(Fixed.acosh,...x);
@@ -4810,12 +4852,12 @@ const hypot=(...x)=>{
4810
4852
  )
4811
4853
  };
4812
4854
 
4813
- const {PI, sqrt, cos, sin, acos, pow} = Math;
4855
+ const {PI, sqrt: sqrt$1, cos: cos$1, sin: sin$1, acos, pow} = Math;
4814
4856
 
4815
4857
  const Linear = t => t;
4816
- const InSin = t => 1 - cos((t * PI) / 2);
4817
- const OutSin = t => sin((t * PI) / 2);
4818
- const InOutSin = t => -(cos(PI * t) - 1) / 2;
4858
+ const InSin = t => 1 - cos$1((t * PI) / 2);
4859
+ const OutSin = t => sin$1((t * PI) / 2);
4860
+ const InOutSin = t => -(cos$1(PI * t) - 1) / 2;
4819
4861
 
4820
4862
  const InQuad = t => t**2;
4821
4863
  const OutQuad = t => 1 - (1-t)**2;
@@ -4837,13 +4879,13 @@ const InExpo = t => t === 0 ? 0 : 2**(10*t - 10);
4837
4879
  const OutExpo = t => t === 1 ? 1 : 1 - 2**(-10 * t);
4838
4880
  const InOutExpo = t => t === 0? 0: t === 1? 1: t < 0.5 ? 2**(20 * t - 10) / 2: (2 - 2**(-20 * t + 10)) / 2;
4839
4881
 
4840
- const InCirc = t => 1 - sqrt(1 - t**2);
4841
- const OutCirc = t => sqrt(1 - (t-1)**2);
4842
- const InOutCirc = t => t < 0.5? (1 - sqrt(1 - (2*t)**2)) / 2: (sqrt(1 - (-2*t+2)**2) + 1) / 2;
4882
+ const InCirc = t => 1 - sqrt$1(1 - t**2);
4883
+ const OutCirc = t => sqrt$1(1 - (t-1)**2);
4884
+ const InOutCirc = t => t < 0.5? (1 - sqrt$1(1 - (2*t)**2)) / 2: (sqrt$1(1 - (-2*t+2)**2) + 1) / 2;
4843
4885
 
4844
- const Arc = t => 1 - sin(acos(t));
4886
+ const Arc = t => 1 - sin$1(acos(t));
4845
4887
  const Back = (t, x = 1) => (t**2) * ((x+1)*t - x);
4846
- const Elastic = t => -2*pow(2, 10 * (t - 1)) * cos(20 * PI * t / 3 * t);
4888
+ const Elastic = t => -2*pow(2, 10 * (t - 1)) * cos$1(20 * PI * t / 3 * t);
4847
4889
 
4848
4890
  const InBack = (t, c1 = 1.70158, c3 = c1 + 1) => c3 * pow(t,3)- c1 * (t**2);
4849
4891
  const OutBack = (t, c1 = 1.70158, c3 = c1 + 1) => 1 + c3 * pow(t - 1, 3) + c1 * pow(t - 1, 2);
@@ -4854,7 +4896,7 @@ const InElastic = (t, c4 = 2*PI/3) => {
4854
4896
  ? 0
4855
4897
  : t === 1
4856
4898
  ? 1
4857
- : -pow(2, 10 * t - 10) * sin((t * 10 - 10.75) * c4);
4899
+ : -pow(2, 10 * t - 10) * sin$1((t * 10 - 10.75) * c4);
4858
4900
  };
4859
4901
 
4860
4902
  const OutElastic = (t, c4 = 2*PI/3) => {
@@ -4862,7 +4904,7 @@ const OutElastic = (t, c4 = 2*PI/3) => {
4862
4904
  ? 0
4863
4905
  : t === 1
4864
4906
  ? 1
4865
- : pow(2, -10 * t) * sin((t * 10 - 0.75) * c4) + 1;
4907
+ : pow(2, -10 * t) * sin$1((t * 10 - 0.75) * c4) + 1;
4866
4908
  };
4867
4909
  const InOutElastic = (t, c5 = 2 * PI / 4.5) => {
4868
4910
  return t === 0
@@ -4870,8 +4912,8 @@ const InOutElastic = (t, c5 = 2 * PI / 4.5) => {
4870
4912
  : t === 1
4871
4913
  ? 1
4872
4914
  : t < 0.5
4873
- ? -(pow(2, 20 * t - 10) * sin((20 * t - 11.125) * c5)) / 2
4874
- : (pow(2, -20 * t + 10) * sin((20 * t - 11.125) * c5)) / 2 + 1;
4915
+ ? -(pow(2, 20 * t - 10) * sin$1((20 * t - 11.125) * c5)) / 2
4916
+ : (pow(2, -20 * t + 10) * sin$1((20 * t - 11.125) * c5)) / 2 + 1;
4875
4917
  };
4876
4918
 
4877
4919
  const InBounce = (t, n1 = 7.5625, d1 = 2.75) => 1 - OutBounce(1-t, n1, d1);
@@ -4979,17 +5021,28 @@ const animation = (callback, {ease, t0, t1, start, duration} = {}) =>
4979
5021
  new TimeAnimation(callback, {ease, t0, t1, start, duration});
4980
5022
 
4981
5023
  class Tick {
4982
- constructor(ms, fn) {
5024
+ constructor(fn, ms, count = Infinity, start) {
4983
5025
  this.ms = ms;
4984
5026
  this.fn = fn;
5027
+ this.count = count;
5028
+ this.frame = 1;
4985
5029
  this.id = null;
4986
5030
  this.running = false;
5031
+ if(start) this.start();
4987
5032
  }
4988
5033
 
4989
5034
  start() {
4990
5035
  if (!this.running) {
4991
5036
  this.running = true;
4992
- this.id = setInterval(this.fn, this.ms);
5037
+ this.frame = 1;
5038
+ this.id = setInterval(() => {
5039
+ if (this.frame > this.count) {
5040
+ this.stop();
5041
+ return;
5042
+ }
5043
+ this.fn.call(null, this);
5044
+ this.frame++;
5045
+ }, this.ms);
4993
5046
  }
4994
5047
  return this;
4995
5048
  }
@@ -5007,7 +5060,9 @@ class Tick {
5007
5060
  return this.running;
5008
5061
  }
5009
5062
  }
5010
- const tick = (ms, fn) => new Tick(ms, fn);
5063
+
5064
+ // Helper factory
5065
+ const tick = (fn, ms, count = Infinity, start = true) => new Tick(fn, ms, count, start);
5011
5066
 
5012
5067
  class Clock extends Tick {
5013
5068
  constructor(tickMs = 1000 / 60) {
@@ -5139,7 +5194,8 @@ const Scheduler = (tasks, { repeat = null} = {}) => new TimeScheduler(tasks, { r
5139
5194
  const step_fps = (step_or_fps) => 1000 / step_or_fps;
5140
5195
 
5141
5196
  const debounce=(fn,delay=1000)=>{
5142
- return (...args) => setTimeout(()=>fn(...args),delay);
5197
+ let id;
5198
+ return (...args) => id ? clearTimeout(id) : setTimeout(()=>fn(...args),delay);
5143
5199
  };
5144
5200
  const throttle=(fn,delay)=>{
5145
5201
  let lastTime=0;
@@ -5544,66 +5600,37 @@ function findCommonPath(paths) {
5544
5600
  function useDerived(deriveFn, sources) {
5545
5601
  let value = deriveFn(...sources.map(s => s().value));
5546
5602
  const subscribers = new Set();
5547
- let paused = false;
5548
-
5549
- function getValue() {
5550
- return {
5551
- value,
5552
- isStateGetter: () => true,
5553
- _subscribe: (fn, UIElement) => {
5554
- subscribers.add(fn);
5555
-
5556
- const observer = new MutationObserver(() => {
5557
- if (!document.body.contains(UIElement.element)) {
5558
- subscribers.delete(fn);
5559
- observer.disconnect();
5560
- }
5561
- });
5562
-
5563
- observer.observe(document.body, { childList: true, subtree: true });
5564
- },
5565
- };
5566
- }
5567
-
5568
- function setValue(newValue) {
5569
- if (paused) return;
5570
- if (typeof newValue === "function") newValue = newValue(value);
5571
- if (newValue !== value) {
5572
- value = newValue;
5573
- subscribers.forEach(fn => fn(value));
5574
- }
5575
- }
5576
-
5577
- const controller = {
5578
- pause: () => { paused = true; },
5579
- resume: () => { paused = false; },
5580
- clear: () => { subscribers.clear(); },
5581
- force: (newValue) => {
5582
- if (typeof newValue === "function") newValue = newValue(value);
5583
- value = newValue;
5584
- subscribers.forEach(fn => fn(value));
5585
- },
5586
- getSubscribers: () => new Set(subscribers),
5587
- };
5588
5603
 
5589
- // Subscribe to source states
5590
5604
  sources.forEach(source => {
5591
5605
  const srcValue = source(); // getValue()
5592
5606
  srcValue._subscribe(() => {
5593
- if (!paused) {
5607
+ {
5594
5608
  const newVal = deriveFn(...sources.map(s => s().value));
5595
5609
  if (newVal !== value) {
5596
5610
  value = newVal;
5597
5611
  subscribers.forEach(fn => fn(value));
5598
5612
  }
5599
5613
  }
5600
- }, { element: document.body }); // dummy UIElement
5614
+ });
5601
5615
  });
5602
-
5603
- return [getValue, setValue, controller];
5616
+ return () => ({
5617
+ value,
5618
+ isStateGetter : () => true,
5619
+ _subscribe: (fn) => subscribers.add(fn)
5620
+ })
5604
5621
  }
5605
5622
 
5606
- const useReactive = (nested_value) => mapfun$1(n => useState(n), nested_value);
5623
+ const useReactive = (nested_value) => mapfun$1(
5624
+ n => {
5625
+ const state = useState(n);
5626
+ // console.log(state)
5627
+ return {
5628
+ get : state[0],
5629
+ set : state[1],
5630
+ }
5631
+ },
5632
+ nested_value
5633
+ );
5607
5634
 
5608
5635
  class ZikoUseChannel{
5609
5636
  constructor(name = ""){
@@ -5839,6 +5866,65 @@ class ZikoUseStorage{
5839
5866
  const useLocaleStorage=(key,initialValue)=>new ZikoUseStorage(localStorage,key,initialValue);
5840
5867
  const useSessionStorage=(key,initialValue)=>new ZikoUseStorage(sessionStorage,key,initialValue);
5841
5868
 
5869
+ let {sqrt, cos, sin, exp, log, cosh, sinh} = Math;
5870
+ // Math.abs = new Proxy(Math.abs, {
5871
+ // apply(target, thisArg, args) {
5872
+ // const x = args[0]
5873
+ // if(typeof x === 'number') return target.apply(thisArg, args);
5874
+ // if(x?.isComplex?.()){
5875
+ // const {a, b, z, phi} = x
5876
+ // const complex = (a, b) => new x.constructor(a, b)
5877
+ // switch(target.name){
5878
+ // case 'abs' : return a.z;
5879
+ // case 'sqrt' : return complex(sqrt(z)*cos(phi/2),sqrt(z)*sin(phi/2));
5880
+ // }
5881
+ // }
5882
+
5883
+ // }
5884
+ // });
5885
+
5886
+
5887
+ for (const key of Object.getOwnPropertyNames(Math)) {
5888
+ const fn = Math[key];
5889
+ if (typeof fn === "function") {
5890
+ Math[key] = new Proxy(fn, {
5891
+ apply(target, thisArg, args) {
5892
+ // console.log(target)
5893
+ const x = args[0];
5894
+ if(typeof x === 'number' || args.length === 0) return target.apply(thisArg, args);
5895
+ if(x?.isComplex?.()){
5896
+ const {a, b, z, phi} = x;
5897
+ const complex = (a, b) => new x.constructor(a, b);
5898
+ switch(target.name){
5899
+ case 'abs' : return x.z;
5900
+ case 'sqrt' : return complex(sqrt(z)*cos(phi/2),sqrt(z)*sin(phi/2));
5901
+ case 'log' : return complex(log(z), phi);
5902
+ case 'exp' : return complex(exp(a)*cos(b),exp(a)*sin(b));
5903
+ case 'cos' : return complex(cos(a)*cosh(b),-(sin(a)*sinh(b)));
5904
+ case 'sin' : return complex(sin(a)*cosh(b),cos(a)*sinh(b));
5905
+ case 'tan' : {
5906
+ const DEN = cos(2*a)+cosh(2*b);
5907
+ return complex(sin(2*a) /DEN, sinh(2*b)/DEN);
5908
+ }
5909
+ case 'cosh' : return complex(cosh(a)*cos(b),sinh(a)*sin(b));
5910
+ case 'sinh' : return complex(sinh(a)*cos(b),cosh(a)*sin(b));
5911
+ case 'tanh' : {
5912
+ const DEN=cosh(2*a)+cos(2*b);
5913
+ return complex(sinh(2*a)/DEN,sin(2*b)/DEN)
5914
+ }
5915
+ default : return target.apply(thisArg, args)
5916
+ }
5917
+ }
5918
+ // if( x.isMatrix?.()){
5919
+ // const {rows, cols, arr} = x
5920
+ // // return new x.constructor(rows, cols, arr.flat(1).map(n=>));
5921
+ // }
5922
+ throw new TypeError(`Math.${key} expects only numbers`);
5923
+ }
5924
+ });
5925
+ }
5926
+ }
5927
+
5842
5928
  if(globalThis?.document){
5843
5929
  document?.addEventListener("DOMContentLoaded", __Ziko__.__Config__.init());
5844
5930
  }
@@ -5967,8 +6053,8 @@ exports.clamp = clamp;
5967
6053
  exports.clock = clock;
5968
6054
  exports.combinaison = combinaison;
5969
6055
  exports.complex = complex;
5970
- exports.cos = cos$1;
5971
- exports.cosh = cosh;
6056
+ exports.cos = cos$2;
6057
+ exports.cosh = cosh$1;
5972
6058
  exports.cot = cot;
5973
6059
  exports.coth = coth;
5974
6060
  exports.csc = csc;
@@ -5979,7 +6065,7 @@ exports.csv2object = csv2object;
5979
6065
  exports.csv2sql = csv2sql;
5980
6066
  exports.debounce = debounce;
5981
6067
  exports.defineParamsGetter = defineParamsGetter;
5982
- exports.defineWC = defineWC;
6068
+ exports.define_wc = define_wc;
5983
6069
  exports.deg2rad = deg2rad;
5984
6070
  exports.div = div;
5985
6071
  exports.e = e;
@@ -6029,11 +6115,11 @@ exports.round = round;
6029
6115
  exports.sec = sec;
6030
6116
  exports.sig = sig;
6031
6117
  exports.sign = sign;
6032
- exports.sin = sin$1;
6118
+ exports.sin = sin$2;
6033
6119
  exports.sinc = sinc;
6034
- exports.sinh = sinh;
6120
+ exports.sinh = sinh$1;
6035
6121
  exports.sleep = sleep;
6036
- exports.sqrt = sqrt$1;
6122
+ exports.sqrt = sqrt$2;
6037
6123
  exports.sqrtn = sqrtn;
6038
6124
  exports.step_fps = step_fps;
6039
6125
  exports.sub = sub;