ziko 0.49.3 → 0.49.5

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.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  /*
3
3
  Project: ziko.js
4
4
  Author: Zakaria Elalaoui
5
- Date : Tue Nov 25 2025 19:11:53 GMT+0100 (UTC+01:00)
5
+ Date : Wed Nov 26 2025 11:58:54 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
@@ -42,8 +42,6 @@ Fixed = new Proxy(Fixed, {
42
42
  }
43
43
  });
44
44
 
45
- class ZikoMath {}
46
-
47
45
  // To generalise
48
46
 
49
47
  const mapfun$1=(fun,...X)=>{
@@ -1179,57 +1177,67 @@ const __CACHE__ = {
1179
1177
  }
1180
1178
  };
1181
1179
 
1182
- class ZikoUseChannel{
1183
- constructor(name = ""){
1180
+ class UseChannel {
1181
+ constructor(name = "") {
1184
1182
  this.channel = new BroadcastChannel(name);
1185
- this.EVENTS_DATAS_PAIRS = new Map();
1186
- this.EVENTS_HANDLERS_PAIRS = new Map();
1187
- this.LAST_RECEIVED_EVENT = "";
1188
- this.UUID="ziko-channel"+Random.string(10);
1189
- this.SUBSCRIBERS = new Set([this.UUID]);
1190
- }
1191
- get broadcast(){
1192
- // update receiver
1193
- return this;
1183
+ this.eventData = new Map();
1184
+ this.handlers = new Map();
1185
+ this.uuid = "ziko-channel:" + Random.string(10);
1186
+ this.subscribers = new Set([this.uuid]);
1187
+
1188
+ this.channel.addEventListener("message", (e) => {
1189
+ const { last_sent_event, userId, eventData } = e.data;
1190
+
1191
+ // ignore own events
1192
+ if (userId === this.uuid) return;
1193
+
1194
+ this.subscribers.add(userId);
1195
+
1196
+ // sync data
1197
+ this.eventData = new Map(eventData);
1198
+
1199
+ const data = this.eventData.get(last_sent_event);
1200
+ const handlers = this.handlers.get(last_sent_event);
1201
+
1202
+ if (handlers) {
1203
+ handlers.forEach(fn => fn(data));
1204
+ }
1205
+ });
1194
1206
  }
1195
- emit(event, data){
1196
- this.EVENTS_DATAS_PAIRS.set(event,data);
1197
- this.#maintainEmit(event);
1207
+
1208
+ emit(event, data) {
1209
+ this.eventData.set(event, data);
1210
+
1211
+ this.channel.postMessage({
1212
+ eventData: this.eventData,
1213
+ last_sent_event: event,
1214
+ userId: this.uuid
1215
+ });
1198
1216
  return this;
1199
1217
  }
1200
- on(event,handler=console.log){
1201
- this.EVENTS_HANDLERS_PAIRS.set(event,handler);
1202
- this.#maintainOn();
1218
+
1219
+ on(event, handler = console.log) {
1220
+ if (!this.handlers.has(event)) {
1221
+ this.handlers.set(event, []);
1222
+ }
1223
+ this.handlers.get(event).push(handler);
1203
1224
  return this;
1204
1225
  }
1205
- #maintainOn(){
1206
- this.channel.onmessage = (e) => {
1207
- this.LAST_RECEIVED_EVENT=e.data.last_sended_event;
1208
- const USER_ID=e.data.userId;
1209
- this.SUBSCRIBERS.add(USER_ID);
1210
- const Data=e.data.EVENTS_DATAS_PAIRS.get(this.LAST_RECEIVED_EVENT);
1211
- const Handler=this.EVENTS_HANDLERS_PAIRS.get(this.LAST_RECEIVED_EVENT);
1212
- if(Data && Handler)Handler(Data);
1213
- };
1214
- return this;
1215
- }
1216
- #maintainEmit(event){
1217
- this.channel.postMessage({
1218
- EVENTS_DATAS_PAIRS:this.EVENTS_DATAS_PAIRS,
1219
- last_sended_event:event,
1220
- userId:this.UUID
1221
- });
1226
+
1227
+ close() {
1228
+ this.channel.close();
1222
1229
  return this;
1223
1230
  }
1224
- close(){
1225
- this.channel.close();
1231
+
1232
+ get broadcast() {
1226
1233
  return this;
1227
1234
  }
1228
1235
  }
1229
- const useChannel = name => new ZikoUseChannel(name);
1236
+
1237
+ const useChannel = (name) => new UseChannel(name);
1230
1238
 
1231
1239
  // To do : remove old items
1232
- class ZikoUseStorage{
1240
+ class UseStorage{
1233
1241
  constructor(storage, globalKey, initialValue){
1234
1242
  this.cache={
1235
1243
  storage,
@@ -1294,8 +1302,8 @@ class ZikoUseStorage{
1294
1302
  }
1295
1303
 
1296
1304
  }
1297
- const useLocaleStorage=(key,initialValue)=>new ZikoUseStorage(localStorage,key,initialValue);
1298
- const useSessionStorage=(key,initialValue)=>new ZikoUseStorage(sessionStorage,key,initialValue);
1305
+ const useLocaleStorage=(key,initialValue)=>new UseStorage(localStorage,key,initialValue);
1306
+ const useSessionStorage=(key,initialValue)=>new UseStorage(sessionStorage,key,initialValue);
1299
1307
 
1300
1308
  const __State__ = {
1301
1309
  store : new Map(),
@@ -3225,9 +3233,8 @@ function trimKeys(obj) {
3225
3233
  }, Array.isArray(obj) ? [] : {});
3226
3234
  }
3227
3235
 
3228
- class Matrix extends ZikoMath{
3236
+ class Matrix{
3229
3237
  constructor(rows, cols, element = [] ) {
3230
- super();
3231
3238
  if(rows instanceof Matrix){
3232
3239
  this.arr=rows.arr;
3233
3240
  this.rows=rows.rows;
@@ -3892,9 +3899,8 @@ const matrix2=(...element)=>new Matrix(2, 2, element);
3892
3899
  const matrix3=(...element)=>new Matrix(3, 3, element);
3893
3900
  const matrix4=(...element)=>new Matrix(4, 4, element);
3894
3901
 
3895
- class Complex extends ZikoMath{
3902
+ class Complex{
3896
3903
  constructor(a = 0, b = 0) {
3897
- super();
3898
3904
  if(a instanceof Complex){
3899
3905
  this.a=a.a;
3900
3906
  this.b=a.b;
@@ -4070,12 +4076,6 @@ const complex=(a,b)=>{
4070
4076
  return new Complex(a,b)
4071
4077
  };
4072
4078
 
4073
- // import {
4074
- // gamma,
4075
- // bessel,
4076
- // beta
4077
- // } from "../calculus/index.js";
4078
-
4079
4079
  const abs=(...x)=>mapfun$1(Math.abs,...x);
4080
4080
  const sqrt$2=(...x)=>mapfun$1(Math.sqrt,...x);
4081
4081
  const pow$1=(x,n)=>{
@@ -4754,7 +4754,7 @@ const timeTaken = callback => {
4754
4754
  return r;
4755
4755
  };
4756
4756
 
4757
- class ZikoUseEventEmitter {
4757
+ class UseEventEmitter {
4758
4758
  constructor() {
4759
4759
  this.events = {};
4760
4760
  this.maxListeners = 10;
@@ -4816,7 +4816,7 @@ class ZikoUseEventEmitter {
4816
4816
  }
4817
4817
  }
4818
4818
 
4819
- const useEventEmitter=()=>new ZikoUseEventEmitter();
4819
+ const useEventEmitter=()=>new UseEventEmitter();
4820
4820
 
4821
4821
  class ZikoUseFavIcon{
4822
4822
  constructor(FavIcon,useEventEmitter=true){
@@ -5199,7 +5199,6 @@ function useDerived(deriveFn, sources) {
5199
5199
  const useReactive = (nested_value) => mapfun$1(
5200
5200
  n => {
5201
5201
  const state = useState(n);
5202
- // console.log(state)
5203
5202
  return {
5204
5203
  get : state[0],
5205
5204
  set : state[1],
@@ -5208,7 +5207,7 @@ const useReactive = (nested_value) => mapfun$1(
5208
5207
  nested_value
5209
5208
  );
5210
5209
 
5211
- class ZikoUseThreed {
5210
+ class UseThreed {
5212
5211
  #workerContent;
5213
5212
  constructor() {
5214
5213
  this.#workerContent = (
@@ -5244,14 +5243,14 @@ class ZikoUseThreed {
5244
5243
  }
5245
5244
 
5246
5245
  const useThread = (func, callback , close) => {
5247
- const T = new ZikoUseThreed();
5246
+ const T = new UseThreed();
5248
5247
  if (func) {
5249
5248
  T.call(func, callback , close);
5250
5249
  }
5251
5250
  return T;
5252
5251
  };
5253
5252
 
5254
- class ZikoUseRoot {
5253
+ class UseRoot {
5255
5254
  constructor(PropsMap, {namespace = 'Ziko', register, ValidateCssProps = false} = {}){
5256
5255
  this.currentPropsMap = PropsMap;
5257
5256
  this.namespace = namespace;
@@ -5296,7 +5295,7 @@ function ValidateCssProps(PropsMap){
5296
5295
  }
5297
5296
  }
5298
5297
 
5299
- const useRoot = (PropsMap, {namespace, register, ValidateCssProps} = {}) => new ZikoUseRoot(PropsMap, {namespace, register, ValidateCssProps});
5298
+ const useRoot = (PropsMap, {namespace, register, ValidateCssProps} = {}) => new UseRoot(PropsMap, {namespace, register, ValidateCssProps});
5300
5299
 
5301
5300
  // Usage
5302
5301
 
@@ -5387,4 +5386,4 @@ if(globalThis?.document){
5387
5386
  document?.addEventListener("DOMContentLoaded", __Ziko__.__Config__.init());
5388
5387
  }
5389
5388
 
5390
- export { App, Base, Clock, Combinaison, Complex, E, EPSILON, FileBasedRouting, Flex, HTMLWrapper, Logic$1 as Logic, Matrix, PI$2 as PI, Permutation, Random, SPA, SVGWrapper, Scheduler, Suspense, Switch, Tick, TimeAnimation, TimeLoop, TimeScheduler, UIElement$1 as UIElement, UIHTMLWrapper, UINode, UISVGWrapper, UISwitch, UIView, Utils, View, ZikoApp, ZikoEventClick, ZikoEventClipboard, ZikoEventCustom, ZikoEventDrag, ZikoEventFocus, ZikoEventHash, ZikoEventKey, ZikoEventMouse, ZikoEventPointer, ZikoEventTouch, ZikoEventWheel, ZikoSPA, ZikoUIFlex, ZikoUISuspense, ZikoUIText, ZikoUseRoot, __ZikoEvent__, abs, accum, acos$1 as acos, acosh, acot, add, animation, arange, arc, arr2str, asin, asinh, atan, atan2, atanh, back, bindCustomEvent, bindHashEvent, bindTouchEvent, bind_click_event, bind_clipboard_event, bind_drag_event, bind_focus_event, bind_key_event, bind_mouse_event, bind_pointer_event, bind_wheel_event, cartesianProduct, ceil, clamp, clock, combinaison, complex, cos$2 as cos, cosh$1 as cosh, cot, coth, csc, csv2arr, csv2json, csv2matrix, csv2object, csv2sql, debounce, defineParamsGetter, define_wc, deg2rad, discret, div, e, elastic, fact, floor, geomspace, getEvent, hypot, inRange, in_back, in_bounce, in_circ, in_cubic, in_elastic, in_expo, in_out_back, in_out_bounce, in_out_circ, in_out_cubic, in_out_elastic, in_out_expo, in_out_quad, in_out_quart, in_out_quint, in_out_sin, in_quad, in_quart, in_quint, in_sin, isApproximatlyEqual, isStateGetter, json2arr, json2css, json2csv, json2csvFile, json2xml, json2xmlFile, json2yml, json2ymlFile, lerp, linear, linspace, ln, logspace, loop, map$1 as map, mapfun$1 as mapfun, matrix, matrix2, matrix3, matrix4, max, min, modulo, mul, norm, nums, obj2str, ones, out_back, out_bounce, out_circ, out_cubic, out_elastic, out_expo, out_quad, out_quart, out_quint, out_sin, pgcd, pow$1 as pow, powerSet, ppcm, preload, prod, rad2deg, round, sec, sig, sign, sin$2 as sin, sinc, sinh$1 as sinh, sleep, sqrt$2 as sqrt, sqrtn, step, step_fps, sub, subSet, sum, svg2ascii, svg2img, svg2imgUrl, svg2str, tags, tan, tanh, text, throttle, tick, timeTaken, time_memory_Taken, timeout, useChannel, useDerived, useEventEmitter, useLocaleStorage, useReactive, useRoot, useSessionStorage, useState, useThread, wait, waitForUIElm, waitForUIElmSync, zeros };
5389
+ export { App, Base, Clock, Combinaison, Complex, E, EPSILON, FileBasedRouting, Flex, HTMLWrapper, Logic$1 as Logic, Matrix, PI$2 as PI, Permutation, Random, SPA, SVGWrapper, Scheduler, Suspense, Switch, Tick, TimeAnimation, TimeLoop, TimeScheduler, UIElement$1 as UIElement, UIHTMLWrapper, UINode, UISVGWrapper, UISwitch, UIView, UseRoot, Utils, View, ZikoApp, ZikoEventClick, ZikoEventClipboard, ZikoEventCustom, ZikoEventDrag, ZikoEventFocus, ZikoEventHash, ZikoEventKey, ZikoEventMouse, ZikoEventPointer, ZikoEventTouch, ZikoEventWheel, ZikoSPA, ZikoUIFlex, ZikoUISuspense, ZikoUIText, __ZikoEvent__, abs, accum, acos$1 as acos, acosh, acot, add, animation, arange, arc, arr2str, asin, asinh, atan, atan2, atanh, back, bindCustomEvent, bindHashEvent, bindTouchEvent, bind_click_event, bind_clipboard_event, bind_drag_event, bind_focus_event, bind_key_event, bind_mouse_event, bind_pointer_event, bind_wheel_event, cartesianProduct, ceil, clamp, clock, combinaison, complex, cos$2 as cos, cosh$1 as cosh, cot, coth, csc, csv2arr, csv2json, csv2matrix, csv2object, csv2sql, debounce, defineParamsGetter, define_wc, deg2rad, discret, div, e, elastic, fact, floor, geomspace, getEvent, hypot, inRange, in_back, in_bounce, in_circ, in_cubic, in_elastic, in_expo, in_out_back, in_out_bounce, in_out_circ, in_out_cubic, in_out_elastic, in_out_expo, in_out_quad, in_out_quart, in_out_quint, in_out_sin, in_quad, in_quart, in_quint, in_sin, isApproximatlyEqual, isStateGetter, json2arr, json2css, json2csv, json2csvFile, json2xml, json2xmlFile, json2yml, json2ymlFile, lerp, linear, linspace, ln, logspace, loop, map$1 as map, mapfun$1 as mapfun, matrix, matrix2, matrix3, matrix4, max, min, modulo, mul, norm, nums, obj2str, ones, out_back, out_bounce, out_circ, out_cubic, out_elastic, out_expo, out_quad, out_quart, out_quint, out_sin, pgcd, pow$1 as pow, powerSet, ppcm, preload, prod, rad2deg, round, sec, sig, sign, sin$2 as sin, sinc, sinh$1 as sinh, sleep, sqrt$2 as sqrt, sqrtn, step, step_fps, sub, subSet, sum, svg2ascii, svg2img, svg2imgUrl, svg2str, tags, tan, tanh, text, throttle, tick, timeTaken, time_memory_Taken, timeout, useDerived, useEventEmitter, useLocaleStorage, useReactive, useRoot, useSessionStorage, useState, useThread, wait, waitForUIElm, waitForUIElmSync, zeros };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ziko",
3
- "version": "0.49.3",
3
+ "version": "0.49.5",
4
4
  "description": "A versatile JavaScript library offering a rich set of Hyperscript Based UI components, advanced mathematical utilities, interactivity ,animations, client side routing and more ...",
5
5
  "keywords": [
6
6
  "front-end",
@@ -26,13 +26,13 @@
26
26
  ],
27
27
  "exports": {
28
28
  "./*": {
29
- "import" : "./src/*/index.js",
30
- "types" : "./types/*/index.d.ts"
29
+ "types" : "./types/*/index.d.ts",
30
+ "import" : "./src/*/index.js"
31
31
  },
32
32
  ".": {
33
+ "types" : "./types/index.d.ts",
33
34
  "import": "./dist/ziko.mjs",
34
- "require": "./dist/ziko.cjs",
35
- "types" : "./types/index.d.ts"
35
+ "require": "./dist/ziko.cjs"
36
36
  },
37
37
 
38
38
  "./helpers": {
@@ -48,6 +48,7 @@
48
48
  "import": "./src/use/index.js"
49
49
  },
50
50
  "./hooks": {
51
+ "types": "./types/hooks/index.d.ts",
51
52
  "import": "./src/hooks/index.js"
52
53
  },
53
54
  "./ui": {
@@ -1,3 +1,4 @@
1
1
  export * from './use-state.js';
2
2
  export * from './use-derived.js';
3
- export * from './use-reactive.js';
3
+ export * from './use-reactive.js';
4
+ export * from './use-channel.js'
@@ -0,0 +1,102 @@
1
+ import { Random } from "../math/random/index.js";
2
+
3
+ class UseChannel {
4
+ // private fields
5
+ #channel;
6
+ #eventData;
7
+ #handlers;
8
+ #uuid;
9
+ #subscribers;
10
+ #currentRooms; // now a Set for multiple rooms
11
+
12
+ constructor(name = "") {
13
+ this.#channel = new BroadcastChannel(name);
14
+ this.#eventData = new Map();
15
+ this.#handlers = new Map(); // Map<event, Array<{fn, rooms}>>
16
+ this.#uuid = "ziko-channel:" + Random.string(10);
17
+ this.#subscribers = new Set([this.#uuid]);
18
+ this.#currentRooms = new Set(); // multiple rooms
19
+
20
+ this.#channel.addEventListener("message", (e) => {
21
+ const { last_sent_event, userId, eventData, rooms } = e.data;
22
+
23
+ if (userId === this.#uuid) return; // ignore own messages
24
+
25
+ // broadcast if no rooms, else check intersection
26
+ if (rooms && rooms.length && !rooms.some(r => this.#currentRooms.has(r))) return;
27
+
28
+ this.#subscribers.add(userId);
29
+ this.#eventData = new Map(eventData);
30
+
31
+ const handlersList = this.#handlers.get(last_sent_event);
32
+ if (!handlersList) return;
33
+
34
+ handlersList.forEach(({ fn, rooms: handlerRooms }) => {
35
+ // trigger if listener has no room filter, or intersects subscriber rooms
36
+ if (!handlerRooms || handlerRooms.length === 0 ||
37
+ !rooms || rooms.some(r => handlerRooms.includes(r))) {
38
+ fn(this.#eventData.get(last_sent_event));
39
+ }
40
+ });
41
+ });
42
+ }
43
+
44
+ emit(event, data, rooms) {
45
+ this.#eventData.set(event, data);
46
+ if(typeof rooms === 'string') rooms = [rooms]
47
+
48
+ this.#channel.postMessage({
49
+ eventData: Array.from(this.#eventData.entries()),
50
+ last_sent_event: event,
51
+ userId: this.#uuid,
52
+ rooms: rooms && rooms.length ? rooms : undefined
53
+ });
54
+
55
+ return this;
56
+ }
57
+
58
+ on(event, handler = console.log, rooms) {
59
+ if (!this.#handlers.has(event)) this.#handlers.set(event, []);
60
+ if(typeof rooms === 'string') rooms = [rooms]
61
+ this.#handlers.get(event).push({ fn: handler, rooms });
62
+ return this;
63
+ }
64
+
65
+ off(event, handler) {
66
+ if (!this.#handlers.has(event)) return this;
67
+ this.#handlers.set(
68
+ event,
69
+ this.#handlers.get(event).filter(h => h.fn !== handler)
70
+ );
71
+ return this;
72
+ }
73
+
74
+ once(event, handler, rooms) {
75
+ const wrapper = (data) => {
76
+ handler(data);
77
+ this.off(event, wrapper);
78
+ };
79
+ this.on(event, wrapper, rooms);
80
+ return this;
81
+ }
82
+
83
+ join(...rooms) {
84
+ rooms.forEach(r => this.#currentRooms.add(r));
85
+ return this;
86
+ }
87
+
88
+ leave(...rooms) {
89
+ if (!rooms.length) this.#currentRooms.clear();
90
+ else rooms.forEach(r => this.#currentRooms.delete(r));
91
+ return this;
92
+ }
93
+
94
+ close() {
95
+ this.#channel.close();
96
+ return this;
97
+ }
98
+
99
+ }
100
+
101
+ const useChannel = (name) => new UseChannel(name);
102
+ export { useChannel };
@@ -1,10 +1,9 @@
1
- import {mapfun} from '../math'
1
+ import { mapfun } from '../math/index.js'
2
2
  import { useState } from './use-state.js'
3
3
 
4
4
  const useReactive = (nested_value) => mapfun(
5
5
  n => {
6
6
  const state = useState(n)
7
- // console.log(state)
8
7
  return {
9
8
  get : state[0],
10
9
  set : state[1],
@@ -1,4 +1,3 @@
1
- import ZikoMath from "../absract.js";
2
1
  import{
3
2
  cos,
4
3
  sin,
@@ -15,9 +14,8 @@ import{
15
14
  }from "../functions/index.js"
16
15
  import { Matrix } from "../matrix/index.js";
17
16
  import {sum,prod,deg2rad} from "../utils/index.js";
18
- class Complex extends ZikoMath{
17
+ class Complex{
19
18
  constructor(a = 0, b = 0) {
20
- super()
21
19
  if(a instanceof Complex){
22
20
  this.a=a.a;
23
21
  this.b=a.b;
@@ -5,11 +5,6 @@ import {
5
5
  min,
6
6
  max
7
7
  }from "../statistics/index.js";
8
- // import {
9
- // gamma,
10
- // bessel,
11
- // beta
12
- // } from "../calculus/index.js";
13
8
 
14
9
  const abs=(...x)=>mapfun(Math.abs,...x);
15
10
  const sqrt=(...x)=>mapfun(Math.sqrt,...x);
@@ -1,4 +1,3 @@
1
- import ZikoMath from "../absract.js";
2
1
  import{
3
2
  pow,
4
3
  min,
@@ -8,9 +7,8 @@ import {Utils} from "../utils/index.js";
8
7
  import {Complex } from "../complex/index.js";
9
8
  import {Random} from "../random/index.js"
10
9
  import { arr2str } from "../../data/index.js";
11
- class Matrix extends ZikoMath{
10
+ class Matrix{
12
11
  constructor(rows, cols, element = [] ) {
13
- super()
14
12
  if(rows instanceof Matrix){
15
13
  this.arr=rows.arr;
16
14
  this.rows=rows.rows;
@@ -10,7 +10,7 @@
10
10
  }
11
11
  ]
12
12
  */
13
- class ZikoUseMediaQuery {
13
+ class UseMediaQuery {
14
14
  constructor(mediaQueryRules=[],fallback=()=>{}) {
15
15
  this.mediaQueryRules = mediaQueryRules;
16
16
  this.fallback = fallback;
@@ -37,7 +37,7 @@ class ZikoUseMediaQuery {
37
37
  }
38
38
  }
39
39
 
40
- const useMediaQuery = (mediaQueryRules,fallback) => new ZikoUseMediaQuery(mediaQueryRules,fallback);
40
+ const useMediaQuery = (mediaQueryRules,fallback) => new UseMediaQuery(mediaQueryRules,fallback);
41
41
  export {
42
42
  useMediaQuery
43
43
  };
@@ -1,4 +1,4 @@
1
- class ZikoUseStyle {
1
+ class UseStyle {
2
2
  constructor(style = {}, use = style.hasOwnProperty("default")? "default" : Object.keys(style)[0], id = 0) {
3
3
  this.id = "Ziko-Style-" + id;
4
4
  this.keys = new Set();
@@ -72,8 +72,8 @@ class ZikoUseStyle {
72
72
  }
73
73
  }
74
74
 
75
- const useStyle = (styles, use, id) => new ZikoUseStyle(styles, use, id)
75
+ const useStyle = (styles, use, id) => new UseStyle(styles, use, id)
76
76
  export {
77
77
  useStyle,
78
- ZikoUseStyle
78
+ UseStyle
79
79
  };
@@ -1,5 +1,5 @@
1
1
  import { Themes } from "../../../global/themes";
2
- class ZikoUseTheme{
2
+ class UseTheme{
3
3
  constructor(theme,id=0){
4
4
  this.id="Ziko-Theme-"+id;
5
5
  this.use(theme)
@@ -53,7 +53,7 @@ class ZikoUseTheme{
53
53
  return this;
54
54
  }
55
55
  }
56
- const useTheme=(theme, id=0)=>new ZikoUseTheme(theme,id)
56
+ const useTheme=(theme, id=0)=>new UseTheme(theme,id)
57
57
  export {
58
58
  useTheme,
59
59
  // Themes,
@@ -1,50 +1,61 @@
1
1
  import { Random } from "../math/random/index.js";
2
- class ZikoUseChannel{
3
- constructor(name = ""){
2
+
3
+ class UseChannel {
4
+ constructor(name = "") {
4
5
  this.channel = new BroadcastChannel(name);
5
- this.EVENTS_DATAS_PAIRS = new Map();
6
- this.EVENTS_HANDLERS_PAIRS = new Map();
7
- this.LAST_RECEIVED_EVENT = "";
8
- this.UUID="ziko-channel"+Random.string(10);
9
- this.SUBSCRIBERS = new Set([this.UUID]);
10
- }
11
- get broadcast(){
12
- // update receiver
13
- return this;
6
+ this.eventData = new Map();
7
+ this.handlers = new Map();
8
+ this.uuid = "ziko-channel:" + Random.string(10);
9
+ this.subscribers = new Set([this.uuid]);
10
+
11
+ this.channel.addEventListener("message", (e) => {
12
+ const { last_sent_event, userId, eventData } = e.data;
13
+
14
+ // ignore own events
15
+ if (userId === this.uuid) return;
16
+
17
+ this.subscribers.add(userId);
18
+
19
+ // sync data
20
+ this.eventData = new Map(eventData);
21
+
22
+ const data = this.eventData.get(last_sent_event);
23
+ const handlers = this.handlers.get(last_sent_event);
24
+
25
+ if (handlers) {
26
+ handlers.forEach(fn => fn(data));
27
+ }
28
+ });
14
29
  }
15
- emit(event, data){
16
- this.EVENTS_DATAS_PAIRS.set(event,data)
17
- this.#maintainEmit(event);
30
+
31
+ emit(event, data) {
32
+ this.eventData.set(event, data);
33
+
34
+ this.channel.postMessage({
35
+ eventData: this.eventData,
36
+ last_sent_event: event,
37
+ userId: this.uuid
38
+ });
18
39
  return this;
19
40
  }
20
- on(event,handler=console.log){
21
- this.EVENTS_HANDLERS_PAIRS.set(event,handler);
22
- this.#maintainOn()
41
+
42
+ on(event, handler = console.log) {
43
+ if (!this.handlers.has(event)) {
44
+ this.handlers.set(event, []);
45
+ }
46
+ this.handlers.get(event).push(handler);
23
47
  return this;
24
48
  }
25
- #maintainOn(){
26
- this.channel.onmessage = (e) => {
27
- this.LAST_RECEIVED_EVENT=e.data.last_sended_event;
28
- const USER_ID=e.data.userId;
29
- this.SUBSCRIBERS.add(USER_ID)
30
- const Data=e.data.EVENTS_DATAS_PAIRS.get(this.LAST_RECEIVED_EVENT)
31
- const Handler=this.EVENTS_HANDLERS_PAIRS.get(this.LAST_RECEIVED_EVENT)
32
- if(Data && Handler)Handler(Data)
33
- };
34
- return this;
35
- }
36
- #maintainEmit(event){
37
- this.channel.postMessage({
38
- EVENTS_DATAS_PAIRS:this.EVENTS_DATAS_PAIRS,
39
- last_sended_event:event,
40
- userId:this.UUID
41
- });
49
+
50
+ close() {
51
+ this.channel.close();
42
52
  return this;
43
53
  }
44
- close(){
45
- this.channel.close();
54
+
55
+ get broadcast() {
46
56
  return this;
47
57
  }
48
58
  }
49
- const useChannel = name => new ZikoUseChannel(name);
50
- export{ useChannel }
59
+
60
+ const useChannel = (name) => new UseChannel(name);
61
+ export { useChannel };
@@ -1,4 +1,4 @@
1
- class ZikoUseEventEmitter {
1
+ class UseEventEmitter {
2
2
  constructor() {
3
3
  this.events = {};
4
4
  this.maxListeners = 10;
@@ -60,5 +60,5 @@ class ZikoUseEventEmitter {
60
60
  }
61
61
  }
62
62
 
63
- const useEventEmitter=()=>new ZikoUseEventEmitter()
63
+ const useEventEmitter=()=>new UseEventEmitter()
64
64
  export{useEventEmitter}
@@ -1,4 +1,4 @@
1
- class ZikoUseRoot {
1
+ class UseRoot {
2
2
  constructor(PropsMap, {namespace = 'Ziko', register, ValidateCssProps = false} = {}){
3
3
  this.currentPropsMap = PropsMap;
4
4
  this.namespace = namespace;
@@ -43,10 +43,10 @@ function ValidateCssProps(PropsMap){
43
43
  }
44
44
  }
45
45
 
46
- const useRoot = (PropsMap, {namespace, register, ValidateCssProps} = {}) => new ZikoUseRoot(PropsMap, {namespace, register, ValidateCssProps});
46
+ const useRoot = (PropsMap, {namespace, register, ValidateCssProps} = {}) => new UseRoot(PropsMap, {namespace, register, ValidateCssProps});
47
47
 
48
48
  export{
49
- ZikoUseRoot,
49
+ UseRoot,
50
50
  useRoot
51
51
  }
52
52
 
@@ -1,6 +1,6 @@
1
1
  // To do : remove old items
2
2
  import { useChannel } from "./use-channel.js";
3
- class ZikoUseStorage{
3
+ class UseStorage{
4
4
  constructor(storage, globalKey, initialValue){
5
5
  this.cache={
6
6
  storage,
@@ -65,8 +65,8 @@ class ZikoUseStorage{
65
65
  }
66
66
 
67
67
  }
68
- const useLocaleStorage=(key,initialValue)=>new ZikoUseStorage(localStorage,key,initialValue);
69
- const useSessionStorage=(key,initialValue)=>new ZikoUseStorage(sessionStorage,key,initialValue);
68
+ const useLocaleStorage=(key,initialValue)=>new UseStorage(localStorage,key,initialValue);
69
+ const useSessionStorage=(key,initialValue)=>new UseStorage(sessionStorage,key,initialValue);
70
70
  export{
71
71
  useLocaleStorage,
72
72
  useSessionStorage
@@ -1,4 +1,4 @@
1
- class ZikoUseThreed {
1
+ class UseThreed {
2
2
  #workerContent;
3
3
  constructor() {
4
4
  this.#workerContent = (
@@ -34,7 +34,7 @@ class ZikoUseThreed {
34
34
  }
35
35
 
36
36
  const useThread = (func, callback , close) => {
37
- const T = new ZikoUseThreed();
37
+ const T = new UseThreed();
38
38
  if (func) {
39
39
  T.call(func, callback , close);
40
40
  }
@@ -0,0 +1 @@
1
+ export type * from './use-channel.d.ts'