ziko 0.49.2 → 0.49.3

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 : Tue Nov 25 2025 11:09:43 GMT+0100 (UTC+01:00)
5
+ Date : Tue Nov 25 2025 19:11:53 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
@@ -1181,17 +1181,143 @@ const __CACHE__ = {
1181
1181
  }
1182
1182
  };
1183
1183
 
1184
+ class ZikoUseChannel{
1185
+ constructor(name = ""){
1186
+ this.channel = new BroadcastChannel(name);
1187
+ this.EVENTS_DATAS_PAIRS = new Map();
1188
+ this.EVENTS_HANDLERS_PAIRS = new Map();
1189
+ this.LAST_RECEIVED_EVENT = "";
1190
+ this.UUID="ziko-channel"+Random.string(10);
1191
+ this.SUBSCRIBERS = new Set([this.UUID]);
1192
+ }
1193
+ get broadcast(){
1194
+ // update receiver
1195
+ return this;
1196
+ }
1197
+ emit(event, data){
1198
+ this.EVENTS_DATAS_PAIRS.set(event,data);
1199
+ this.#maintainEmit(event);
1200
+ return this;
1201
+ }
1202
+ on(event,handler=console.log){
1203
+ this.EVENTS_HANDLERS_PAIRS.set(event,handler);
1204
+ this.#maintainOn();
1205
+ return this;
1206
+ }
1207
+ #maintainOn(){
1208
+ this.channel.onmessage = (e) => {
1209
+ this.LAST_RECEIVED_EVENT=e.data.last_sended_event;
1210
+ const USER_ID=e.data.userId;
1211
+ this.SUBSCRIBERS.add(USER_ID);
1212
+ const Data=e.data.EVENTS_DATAS_PAIRS.get(this.LAST_RECEIVED_EVENT);
1213
+ const Handler=this.EVENTS_HANDLERS_PAIRS.get(this.LAST_RECEIVED_EVENT);
1214
+ if(Data && Handler)Handler(Data);
1215
+ };
1216
+ return this;
1217
+ }
1218
+ #maintainEmit(event){
1219
+ this.channel.postMessage({
1220
+ EVENTS_DATAS_PAIRS:this.EVENTS_DATAS_PAIRS,
1221
+ last_sended_event:event,
1222
+ userId:this.UUID
1223
+ });
1224
+ return this;
1225
+ }
1226
+ close(){
1227
+ this.channel.close();
1228
+ return this;
1229
+ }
1230
+ }
1231
+ const useChannel = name => new ZikoUseChannel(name);
1232
+
1233
+ // To do : remove old items
1234
+ class ZikoUseStorage{
1235
+ constructor(storage, globalKey, initialValue){
1236
+ this.cache={
1237
+ storage,
1238
+ globalKey,
1239
+ channel:useChannel(`Ziko:useStorage-${globalKey}`),
1240
+ oldItemKeys:new Set()
1241
+ };
1242
+ this.#init(initialValue);
1243
+ this.#maintain();
1244
+ }
1245
+ get items(){
1246
+ return JSON.parse(this.cache.storage[this.cache.globalKey]??null);
1247
+ }
1248
+ #maintain() {
1249
+ for(let i in this.items)Object.assign(this, { [[i]]: this.items[i] });
1250
+ }
1251
+ #init(initialValue){
1252
+ this.cache.channel=useChannel(`Ziko:useStorage-${this.cache.globalKey}`);
1253
+ this.cache.channel.on("Ziko-Storage-Updated",()=>this.#maintain());
1254
+ if(!initialValue)return;
1255
+ if(this.cache.storage[this.cache.globalKey]){
1256
+ Object.keys(this.items).forEach(key=>this.cache.oldItemKeys.add(key));
1257
+ // console.group("Ziko:useStorage")
1258
+ // console.warn(`Storage key '${this.cache.globalKey}' already exists. we will not overwrite it.`);
1259
+ // console.info(`%cWe'll keep the existing data.`,"background-color:#2222dd; color:gold;");
1260
+ // console.group("")
1261
+ }
1262
+ else this.set(initialValue);
1263
+ }
1264
+ set(data){
1265
+ this.cache.storage.setItem(this.cache.globalKey,JSON.stringify(data));
1266
+ this.cache.channel.emit("Ziko-Storage-Updated",{});
1267
+ Object.keys(data).forEach(key=>this.cache.oldItemKeys.add(key));
1268
+ this.#maintain();
1269
+ return this
1270
+ }
1271
+ add(data){
1272
+ const db={
1273
+ ...this.items,
1274
+ ...data
1275
+ };
1276
+ this.cache.storage.setItem(this.cache.globalKey,JSON.stringify(db));
1277
+ this.#maintain();
1278
+ return this;
1279
+ }
1280
+ remove(...keys){
1281
+ const db={...this.items};
1282
+ for(let i=0;i<keys.length;i++){
1283
+ delete db[keys[i]];
1284
+ delete this[keys[i]];
1285
+ }
1286
+ this.set(db);
1287
+ return this;
1288
+ }
1289
+ get(key){
1290
+ return this.items[key];
1291
+ }
1292
+ clear(){
1293
+ this.cache.storage.removeItem(this.cache.globalKey);
1294
+ this.#maintain();
1295
+ return this;
1296
+ }
1297
+
1298
+ }
1299
+ const useLocaleStorage=(key,initialValue)=>new ZikoUseStorage(localStorage,key,initialValue);
1300
+ const useSessionStorage=(key,initialValue)=>new ZikoUseStorage(sessionStorage,key,initialValue);
1301
+
1184
1302
  const __State__ = {
1185
1303
  store : new Map(),
1186
- index : undefined?.data?.__Ziko__?.__State__?.index ?? 0,
1304
+ index : 0,
1305
+ session_storage : null,
1187
1306
  register: function(state){
1188
- console.log({
1189
- // hmr : import.meta.hot?.data.__Ziko__.__State__.index,
1190
- index : this.index
1191
- });
1307
+ if(!undefined.SSR && undefined.DEV){
1308
+ if(!this.session) this.session_storage = useSessionStorage('ziko-state', {});
1309
+ const savedValue = this.session_storage.get(this.index);
1310
+ if(!savedValue) this.session_storage.add({[this.index] : state.value});
1311
+ else state.value = savedValue;
1312
+ }
1192
1313
  this.store.set(this.index++, state);
1193
- }
1194
-
1314
+ },
1315
+ update: function(index, value){
1316
+ if(!undefined.SSR && undefined.DEV){
1317
+ this.session_storage.add({[index] : value});
1318
+ }
1319
+ },
1320
+
1195
1321
  };
1196
1322
 
1197
1323
  function __init__global__(){
@@ -1449,20 +1575,8 @@ function _register_to_class_(target, mixin) {
1449
1575
 
1450
1576
  if(!globalThis.__Ziko__) __init__global__();
1451
1577
 
1452
- // HMR persistence
1453
- if (undefined?.data) {
1454
- undefined.data.__Ziko__ = undefined.data?.__Ziko__ || globalThis?.__Ziko__;
1455
- globalThis.__Ziko__ = undefined.data.__Ziko__;
1456
- // import.meta.hot.accept(n=>console.log(n));
1457
- // console.log(import.meta.hot.data.__Ziko__.__State__.store)
1458
- }
1459
-
1460
-
1461
-
1462
1578
  function useState(initialValue) {
1463
-
1464
- // console.log(import.meta.hot.data.__Ziko__.__State__.store.get(0))
1465
-
1579
+
1466
1580
  const {store, index} = __Ziko__.__State__;
1467
1581
  __Ziko__.__State__.register({
1468
1582
  value : initialValue,
@@ -1470,7 +1584,7 @@ function useState(initialValue) {
1470
1584
  paused : false
1471
1585
  });
1472
1586
 
1473
- const current = store.get(index);
1587
+ let current = store.get(index);
1474
1588
 
1475
1589
  function getValue() {
1476
1590
  return {
@@ -1482,10 +1596,13 @@ function useState(initialValue) {
1482
1596
 
1483
1597
  function setValue(newValue) {
1484
1598
  if (current.paused) return;
1485
- if (typeof newValue === "function") newValue = newValue(current.value);
1599
+ if (typeof newValue === "function") {
1600
+ newValue = newValue(current.value);
1601
+ }
1486
1602
  if (newValue !== current.value) {
1487
1603
  current.value = newValue;
1488
1604
  current.subscribers.forEach(fn => fn(current.value));
1605
+ __Ziko__.__State__.update(index, newValue);
1489
1606
  }
1490
1607
  }
1491
1608
 
@@ -4467,6 +4584,7 @@ const throttle=(fn,delay)=>{
4467
4584
  }
4468
4585
  };
4469
4586
 
4587
+ const sleep= ms => new Promise(res => setTimeout(res, ms));
4470
4588
  function timeout(ms, fn) {
4471
4589
  let id;
4472
4590
  const promise = new Promise((resolve) => {
@@ -4483,10 +4601,6 @@ function timeout(ms, fn) {
4483
4601
  };
4484
4602
  }
4485
4603
 
4486
- const sleep= ms => new Promise(res => setTimeout(res, ms));
4487
-
4488
- // use it with await
4489
-
4490
4604
  class TimeLoop {
4491
4605
  constructor(callback, { step = 1000, t0 = 0, t1 = Infinity, autoplay = true } = {}) {
4492
4606
  this.callback = callback;
@@ -5096,55 +5210,6 @@ const useReactive = (nested_value) => mapfun$1(
5096
5210
  nested_value
5097
5211
  );
5098
5212
 
5099
- class ZikoUseChannel{
5100
- constructor(name = ""){
5101
- this.channel = new BroadcastChannel(name);
5102
- this.EVENTS_DATAS_PAIRS = new Map();
5103
- this.EVENTS_HANDLERS_PAIRS = new Map();
5104
- this.LAST_RECEIVED_EVENT = "";
5105
- this.UUID="ziko-channel"+Random.string(10);
5106
- this.SUBSCRIBERS = new Set([this.UUID]);
5107
- }
5108
- get broadcast(){
5109
- // update receiver
5110
- return this;
5111
- }
5112
- emit(event, data){
5113
- this.EVENTS_DATAS_PAIRS.set(event,data);
5114
- this.#maintainEmit(event);
5115
- return this;
5116
- }
5117
- on(event,handler=console.log){
5118
- this.EVENTS_HANDLERS_PAIRS.set(event,handler);
5119
- this.#maintainOn();
5120
- return this;
5121
- }
5122
- #maintainOn(){
5123
- this.channel.onmessage = (e) => {
5124
- this.LAST_RECEIVED_EVENT=e.data.last_sended_event;
5125
- const USER_ID=e.data.userId;
5126
- this.SUBSCRIBERS.add(USER_ID);
5127
- const Data=e.data.EVENTS_DATAS_PAIRS.get(this.LAST_RECEIVED_EVENT);
5128
- const Handler=this.EVENTS_HANDLERS_PAIRS.get(this.LAST_RECEIVED_EVENT);
5129
- if(Data && Handler)Handler(Data);
5130
- };
5131
- return this;
5132
- }
5133
- #maintainEmit(event){
5134
- this.channel.postMessage({
5135
- EVENTS_DATAS_PAIRS:this.EVENTS_DATAS_PAIRS,
5136
- last_sended_event:event,
5137
- userId:this.UUID
5138
- });
5139
- return this;
5140
- }
5141
- close(){
5142
- this.channel.close();
5143
- return this;
5144
- }
5145
- }
5146
- const useChannel = name => new ZikoUseChannel(name);
5147
-
5148
5213
  class ZikoUseThreed {
5149
5214
  #workerContent;
5150
5215
  constructor() {
@@ -5261,75 +5326,6 @@ tags.p("Test useRoot ").style({
5261
5326
 
5262
5327
  */
5263
5328
 
5264
- // To do : remove old items
5265
- class ZikoUseStorage{
5266
- constructor(storage, globalKey, initialValue){
5267
- this.cache={
5268
- storage,
5269
- globalKey,
5270
- channel:useChannel(`Ziko:useStorage-${globalKey}`),
5271
- oldItemKeys:new Set()
5272
- };
5273
- this.#init(initialValue);
5274
- this.#maintain();
5275
- }
5276
- get items(){
5277
- return JSON.parse(this.cache.storage[this.cache.globalKey]??null);
5278
- }
5279
- #maintain() {
5280
- for(let i in this.items)Object.assign(this, { [[i]]: this.items[i] });
5281
- }
5282
- #init(initialValue){
5283
- this.cache.channel=useChannel(`Ziko:useStorage-${this.cache.globalKey}`);
5284
- this.cache.channel.on("Ziko-Storage-Updated",()=>this.#maintain());
5285
- if(!initialValue)return;
5286
- if(this.cache.storage[this.cache.globalKey]){
5287
- Object.keys(this.items).forEach(key=>this.cache.oldItemKeys.add(key));
5288
- console.group("Ziko:useStorage");
5289
- console.warn(`Storage key '${this.cache.globalKey}' already exists. we will not overwrite it.`);
5290
- console.info(`%cWe'll keep the existing data.`,"background-color:#2222dd; color:gold;");
5291
- console.group("");
5292
- }
5293
- else this.set(initialValue);
5294
- }
5295
- set(data){
5296
- this.cache.storage.setItem(this.cache.globalKey,JSON.stringify(data));
5297
- this.cache.channel.emit("Ziko-Storage-Updated",{});
5298
- Object.keys(data).forEach(key=>this.cache.oldItemKeys.add(key));
5299
- this.#maintain();
5300
- return this
5301
- }
5302
- add(data){
5303
- const db={
5304
- ...this.items,
5305
- ...data
5306
- };
5307
- this.cache.storage.setItem(this.cache.globalKey,JSON.stringify(db));
5308
- this.#maintain();
5309
- return this;
5310
- }
5311
- remove(...keys){
5312
- const db={...this.items};
5313
- for(let i=0;i<keys.length;i++){
5314
- delete db[keys[i]];
5315
- delete this[keys[i]];
5316
- }
5317
- this.set(db);
5318
- return this;
5319
- }
5320
- get(key){
5321
- return this.items[key];
5322
- }
5323
- clear(){
5324
- this.cache.storage.removeItem(this.cache.globalKey);
5325
- this.#maintain();
5326
- return this;
5327
- }
5328
-
5329
- }
5330
- const useLocaleStorage=(key,initialValue)=>new ZikoUseStorage(localStorage,key,initialValue);
5331
- const useSessionStorage=(key,initialValue)=>new ZikoUseStorage(sessionStorage,key,initialValue);
5332
-
5333
5329
  let {sqrt, cos, sin, exp, log, cosh, sinh} = Math;
5334
5330
  // Math.abs = new Proxy(Math.abs, {
5335
5331
  // apply(target, thisArg, args) {
package/dist/ziko.js CHANGED
@@ -2,7 +2,7 @@
2
2
  /*
3
3
  Project: ziko.js
4
4
  Author: Zakaria Elalaoui
5
- Date : Tue Nov 25 2025 11:09:43 GMT+0100 (UTC+01:00)
5
+ Date : Tue Nov 25 2025 19:11:53 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
@@ -1185,17 +1185,143 @@
1185
1185
  }
1186
1186
  };
1187
1187
 
1188
+ class ZikoUseChannel{
1189
+ constructor(name = ""){
1190
+ this.channel = new BroadcastChannel(name);
1191
+ this.EVENTS_DATAS_PAIRS = new Map();
1192
+ this.EVENTS_HANDLERS_PAIRS = new Map();
1193
+ this.LAST_RECEIVED_EVENT = "";
1194
+ this.UUID="ziko-channel"+Random.string(10);
1195
+ this.SUBSCRIBERS = new Set([this.UUID]);
1196
+ }
1197
+ get broadcast(){
1198
+ // update receiver
1199
+ return this;
1200
+ }
1201
+ emit(event, data){
1202
+ this.EVENTS_DATAS_PAIRS.set(event,data);
1203
+ this.#maintainEmit(event);
1204
+ return this;
1205
+ }
1206
+ on(event,handler=console.log){
1207
+ this.EVENTS_HANDLERS_PAIRS.set(event,handler);
1208
+ this.#maintainOn();
1209
+ return this;
1210
+ }
1211
+ #maintainOn(){
1212
+ this.channel.onmessage = (e) => {
1213
+ this.LAST_RECEIVED_EVENT=e.data.last_sended_event;
1214
+ const USER_ID=e.data.userId;
1215
+ this.SUBSCRIBERS.add(USER_ID);
1216
+ const Data=e.data.EVENTS_DATAS_PAIRS.get(this.LAST_RECEIVED_EVENT);
1217
+ const Handler=this.EVENTS_HANDLERS_PAIRS.get(this.LAST_RECEIVED_EVENT);
1218
+ if(Data && Handler)Handler(Data);
1219
+ };
1220
+ return this;
1221
+ }
1222
+ #maintainEmit(event){
1223
+ this.channel.postMessage({
1224
+ EVENTS_DATAS_PAIRS:this.EVENTS_DATAS_PAIRS,
1225
+ last_sended_event:event,
1226
+ userId:this.UUID
1227
+ });
1228
+ return this;
1229
+ }
1230
+ close(){
1231
+ this.channel.close();
1232
+ return this;
1233
+ }
1234
+ }
1235
+ const useChannel = name => new ZikoUseChannel(name);
1236
+
1237
+ // To do : remove old items
1238
+ class ZikoUseStorage{
1239
+ constructor(storage, globalKey, initialValue){
1240
+ this.cache={
1241
+ storage,
1242
+ globalKey,
1243
+ channel:useChannel(`Ziko:useStorage-${globalKey}`),
1244
+ oldItemKeys:new Set()
1245
+ };
1246
+ this.#init(initialValue);
1247
+ this.#maintain();
1248
+ }
1249
+ get items(){
1250
+ return JSON.parse(this.cache.storage[this.cache.globalKey]??null);
1251
+ }
1252
+ #maintain() {
1253
+ for(let i in this.items)Object.assign(this, { [[i]]: this.items[i] });
1254
+ }
1255
+ #init(initialValue){
1256
+ this.cache.channel=useChannel(`Ziko:useStorage-${this.cache.globalKey}`);
1257
+ this.cache.channel.on("Ziko-Storage-Updated",()=>this.#maintain());
1258
+ if(!initialValue)return;
1259
+ if(this.cache.storage[this.cache.globalKey]){
1260
+ Object.keys(this.items).forEach(key=>this.cache.oldItemKeys.add(key));
1261
+ // console.group("Ziko:useStorage")
1262
+ // console.warn(`Storage key '${this.cache.globalKey}' already exists. we will not overwrite it.`);
1263
+ // console.info(`%cWe'll keep the existing data.`,"background-color:#2222dd; color:gold;");
1264
+ // console.group("")
1265
+ }
1266
+ else this.set(initialValue);
1267
+ }
1268
+ set(data){
1269
+ this.cache.storage.setItem(this.cache.globalKey,JSON.stringify(data));
1270
+ this.cache.channel.emit("Ziko-Storage-Updated",{});
1271
+ Object.keys(data).forEach(key=>this.cache.oldItemKeys.add(key));
1272
+ this.#maintain();
1273
+ return this
1274
+ }
1275
+ add(data){
1276
+ const db={
1277
+ ...this.items,
1278
+ ...data
1279
+ };
1280
+ this.cache.storage.setItem(this.cache.globalKey,JSON.stringify(db));
1281
+ this.#maintain();
1282
+ return this;
1283
+ }
1284
+ remove(...keys){
1285
+ const db={...this.items};
1286
+ for(let i=0;i<keys.length;i++){
1287
+ delete db[keys[i]];
1288
+ delete this[keys[i]];
1289
+ }
1290
+ this.set(db);
1291
+ return this;
1292
+ }
1293
+ get(key){
1294
+ return this.items[key];
1295
+ }
1296
+ clear(){
1297
+ this.cache.storage.removeItem(this.cache.globalKey);
1298
+ this.#maintain();
1299
+ return this;
1300
+ }
1301
+
1302
+ }
1303
+ const useLocaleStorage=(key,initialValue)=>new ZikoUseStorage(localStorage,key,initialValue);
1304
+ const useSessionStorage=(key,initialValue)=>new ZikoUseStorage(sessionStorage,key,initialValue);
1305
+
1188
1306
  const __State__ = {
1189
1307
  store : new Map(),
1190
- index : undefined?.data?.__Ziko__?.__State__?.index ?? 0,
1308
+ index : 0,
1309
+ session_storage : null,
1191
1310
  register: function(state){
1192
- console.log({
1193
- // hmr : import.meta.hot?.data.__Ziko__.__State__.index,
1194
- index : this.index
1195
- });
1311
+ if(!undefined.SSR && undefined.DEV){
1312
+ if(!this.session) this.session_storage = useSessionStorage('ziko-state', {});
1313
+ const savedValue = this.session_storage.get(this.index);
1314
+ if(!savedValue) this.session_storage.add({[this.index] : state.value});
1315
+ else state.value = savedValue;
1316
+ }
1196
1317
  this.store.set(this.index++, state);
1197
- }
1198
-
1318
+ },
1319
+ update: function(index, value){
1320
+ if(!undefined.SSR && undefined.DEV){
1321
+ this.session_storage.add({[index] : value});
1322
+ }
1323
+ },
1324
+
1199
1325
  };
1200
1326
 
1201
1327
  function __init__global__(){
@@ -1453,20 +1579,8 @@
1453
1579
 
1454
1580
  if(!globalThis.__Ziko__) __init__global__();
1455
1581
 
1456
- // HMR persistence
1457
- if (undefined?.data) {
1458
- undefined.data.__Ziko__ = undefined.data?.__Ziko__ || globalThis?.__Ziko__;
1459
- globalThis.__Ziko__ = undefined.data.__Ziko__;
1460
- // import.meta.hot.accept(n=>console.log(n));
1461
- // console.log(import.meta.hot.data.__Ziko__.__State__.store)
1462
- }
1463
-
1464
-
1465
-
1466
1582
  function useState(initialValue) {
1467
-
1468
- // console.log(import.meta.hot.data.__Ziko__.__State__.store.get(0))
1469
-
1583
+
1470
1584
  const {store, index} = __Ziko__.__State__;
1471
1585
  __Ziko__.__State__.register({
1472
1586
  value : initialValue,
@@ -1474,7 +1588,7 @@
1474
1588
  paused : false
1475
1589
  });
1476
1590
 
1477
- const current = store.get(index);
1591
+ let current = store.get(index);
1478
1592
 
1479
1593
  function getValue() {
1480
1594
  return {
@@ -1486,10 +1600,13 @@
1486
1600
 
1487
1601
  function setValue(newValue) {
1488
1602
  if (current.paused) return;
1489
- if (typeof newValue === "function") newValue = newValue(current.value);
1603
+ if (typeof newValue === "function") {
1604
+ newValue = newValue(current.value);
1605
+ }
1490
1606
  if (newValue !== current.value) {
1491
1607
  current.value = newValue;
1492
1608
  current.subscribers.forEach(fn => fn(current.value));
1609
+ __Ziko__.__State__.update(index, newValue);
1493
1610
  }
1494
1611
  }
1495
1612
 
@@ -4471,6 +4588,7 @@
4471
4588
  }
4472
4589
  };
4473
4590
 
4591
+ const sleep= ms => new Promise(res => setTimeout(res, ms));
4474
4592
  function timeout(ms, fn) {
4475
4593
  let id;
4476
4594
  const promise = new Promise((resolve) => {
@@ -4487,10 +4605,6 @@
4487
4605
  };
4488
4606
  }
4489
4607
 
4490
- const sleep= ms => new Promise(res => setTimeout(res, ms));
4491
-
4492
- // use it with await
4493
-
4494
4608
  class TimeLoop {
4495
4609
  constructor(callback, { step = 1000, t0 = 0, t1 = Infinity, autoplay = true } = {}) {
4496
4610
  this.callback = callback;
@@ -5100,55 +5214,6 @@
5100
5214
  nested_value
5101
5215
  );
5102
5216
 
5103
- class ZikoUseChannel{
5104
- constructor(name = ""){
5105
- this.channel = new BroadcastChannel(name);
5106
- this.EVENTS_DATAS_PAIRS = new Map();
5107
- this.EVENTS_HANDLERS_PAIRS = new Map();
5108
- this.LAST_RECEIVED_EVENT = "";
5109
- this.UUID="ziko-channel"+Random.string(10);
5110
- this.SUBSCRIBERS = new Set([this.UUID]);
5111
- }
5112
- get broadcast(){
5113
- // update receiver
5114
- return this;
5115
- }
5116
- emit(event, data){
5117
- this.EVENTS_DATAS_PAIRS.set(event,data);
5118
- this.#maintainEmit(event);
5119
- return this;
5120
- }
5121
- on(event,handler=console.log){
5122
- this.EVENTS_HANDLERS_PAIRS.set(event,handler);
5123
- this.#maintainOn();
5124
- return this;
5125
- }
5126
- #maintainOn(){
5127
- this.channel.onmessage = (e) => {
5128
- this.LAST_RECEIVED_EVENT=e.data.last_sended_event;
5129
- const USER_ID=e.data.userId;
5130
- this.SUBSCRIBERS.add(USER_ID);
5131
- const Data=e.data.EVENTS_DATAS_PAIRS.get(this.LAST_RECEIVED_EVENT);
5132
- const Handler=this.EVENTS_HANDLERS_PAIRS.get(this.LAST_RECEIVED_EVENT);
5133
- if(Data && Handler)Handler(Data);
5134
- };
5135
- return this;
5136
- }
5137
- #maintainEmit(event){
5138
- this.channel.postMessage({
5139
- EVENTS_DATAS_PAIRS:this.EVENTS_DATAS_PAIRS,
5140
- last_sended_event:event,
5141
- userId:this.UUID
5142
- });
5143
- return this;
5144
- }
5145
- close(){
5146
- this.channel.close();
5147
- return this;
5148
- }
5149
- }
5150
- const useChannel = name => new ZikoUseChannel(name);
5151
-
5152
5217
  class ZikoUseThreed {
5153
5218
  #workerContent;
5154
5219
  constructor() {
@@ -5265,75 +5330,6 @@
5265
5330
 
5266
5331
  */
5267
5332
 
5268
- // To do : remove old items
5269
- class ZikoUseStorage{
5270
- constructor(storage, globalKey, initialValue){
5271
- this.cache={
5272
- storage,
5273
- globalKey,
5274
- channel:useChannel(`Ziko:useStorage-${globalKey}`),
5275
- oldItemKeys:new Set()
5276
- };
5277
- this.#init(initialValue);
5278
- this.#maintain();
5279
- }
5280
- get items(){
5281
- return JSON.parse(this.cache.storage[this.cache.globalKey]??null);
5282
- }
5283
- #maintain() {
5284
- for(let i in this.items)Object.assign(this, { [[i]]: this.items[i] });
5285
- }
5286
- #init(initialValue){
5287
- this.cache.channel=useChannel(`Ziko:useStorage-${this.cache.globalKey}`);
5288
- this.cache.channel.on("Ziko-Storage-Updated",()=>this.#maintain());
5289
- if(!initialValue)return;
5290
- if(this.cache.storage[this.cache.globalKey]){
5291
- Object.keys(this.items).forEach(key=>this.cache.oldItemKeys.add(key));
5292
- console.group("Ziko:useStorage");
5293
- console.warn(`Storage key '${this.cache.globalKey}' already exists. we will not overwrite it.`);
5294
- console.info(`%cWe'll keep the existing data.`,"background-color:#2222dd; color:gold;");
5295
- console.group("");
5296
- }
5297
- else this.set(initialValue);
5298
- }
5299
- set(data){
5300
- this.cache.storage.setItem(this.cache.globalKey,JSON.stringify(data));
5301
- this.cache.channel.emit("Ziko-Storage-Updated",{});
5302
- Object.keys(data).forEach(key=>this.cache.oldItemKeys.add(key));
5303
- this.#maintain();
5304
- return this
5305
- }
5306
- add(data){
5307
- const db={
5308
- ...this.items,
5309
- ...data
5310
- };
5311
- this.cache.storage.setItem(this.cache.globalKey,JSON.stringify(db));
5312
- this.#maintain();
5313
- return this;
5314
- }
5315
- remove(...keys){
5316
- const db={...this.items};
5317
- for(let i=0;i<keys.length;i++){
5318
- delete db[keys[i]];
5319
- delete this[keys[i]];
5320
- }
5321
- this.set(db);
5322
- return this;
5323
- }
5324
- get(key){
5325
- return this.items[key];
5326
- }
5327
- clear(){
5328
- this.cache.storage.removeItem(this.cache.globalKey);
5329
- this.#maintain();
5330
- return this;
5331
- }
5332
-
5333
- }
5334
- const useLocaleStorage=(key,initialValue)=>new ZikoUseStorage(localStorage,key,initialValue);
5335
- const useSessionStorage=(key,initialValue)=>new ZikoUseStorage(sessionStorage,key,initialValue);
5336
-
5337
5333
  let {sqrt, cos, sin, exp, log, cosh, sinh} = Math;
5338
5334
  // Math.abs = new Proxy(Math.abs, {
5339
5335
  // apply(target, thisArg, args) {