ziko 0.49.4 → 0.49.6
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 +101 -61
- package/dist/ziko.js +101 -61
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +101 -61
- package/package.json +2 -1
- package/src/__ziko__/__state__.js +1 -1
- package/src/hooks/index.js +3 -1
- package/src/hooks/use-channel.js +102 -0
- package/src/hooks/use-derived.js +1 -1
- package/src/hooks/use-reactive.js +1 -2
- package/src/{use → hooks}/use-storage.js +3 -3
- package/src/math/complex/index.js +1 -3
- package/src/math/matrix/Matrix.js +1 -3
- package/src/reactivity/hooks/UI/useMediaQuery.js +2 -2
- package/src/reactivity/hooks/UI/useStyle.js +3 -3
- package/src/reactivity/hooks/UI/useTheme.js +2 -2
- package/src/use/index.js +2 -2
- package/src/use/use-channel.js.txt +61 -0
- package/src/use/use-event-emmiter.js +2 -2
- package/src/use/use-root.js +3 -3
- package/src/use/use-storage.js.txt +73 -0
- package/src/use/use-thread.js +2 -2
- package/types/hooks/index.d.ts +4 -0
- package/types/hooks/use-channel.d.ts +12 -0
- package/types/hooks/use-derived.d.ts +14 -0
- package/types/hooks/use-reactive.d.ts +14 -0
- package/types/hooks/use-state.d.ts +25 -0
- package/types/index.d.ts +2 -1
- package/src/math/absract.js +0 -1
- package/src/use/use-channel.js +0 -50
package/dist/ziko.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/*
|
|
3
3
|
Project: ziko.js
|
|
4
4
|
Author: Zakaria Elalaoui
|
|
5
|
-
Date :
|
|
5
|
+
Date : Wed Nov 26 2025 12:01:55 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,108 @@ const __CACHE__ = {
|
|
|
1179
1177
|
}
|
|
1180
1178
|
};
|
|
1181
1179
|
|
|
1182
|
-
class
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1180
|
+
class UseChannel {
|
|
1181
|
+
// private fields
|
|
1182
|
+
#channel;
|
|
1183
|
+
#eventData;
|
|
1184
|
+
#handlers;
|
|
1185
|
+
#uuid;
|
|
1186
|
+
#subscribers;
|
|
1187
|
+
#currentRooms; // now a Set for multiple rooms
|
|
1188
|
+
|
|
1189
|
+
constructor(name = "") {
|
|
1190
|
+
this.#channel = new BroadcastChannel(name);
|
|
1191
|
+
this.#eventData = new Map();
|
|
1192
|
+
this.#handlers = new Map(); // Map<event, Array<{fn, rooms}>>
|
|
1193
|
+
this.#uuid = "ziko-channel:" + Random.string(10);
|
|
1194
|
+
this.#subscribers = new Set([this.#uuid]);
|
|
1195
|
+
this.#currentRooms = new Set(); // multiple rooms
|
|
1196
|
+
|
|
1197
|
+
this.#channel.addEventListener("message", (e) => {
|
|
1198
|
+
const { last_sent_event, userId, eventData, rooms } = e.data;
|
|
1199
|
+
|
|
1200
|
+
if (userId === this.#uuid) return; // ignore own messages
|
|
1201
|
+
|
|
1202
|
+
// broadcast if no rooms, else check intersection
|
|
1203
|
+
if (rooms && rooms.length && !rooms.some(r => this.#currentRooms.has(r))) return;
|
|
1204
|
+
|
|
1205
|
+
this.#subscribers.add(userId);
|
|
1206
|
+
this.#eventData = new Map(eventData);
|
|
1207
|
+
|
|
1208
|
+
const handlersList = this.#handlers.get(last_sent_event);
|
|
1209
|
+
if (!handlersList) return;
|
|
1210
|
+
|
|
1211
|
+
handlersList.forEach(({ fn, rooms: handlerRooms }) => {
|
|
1212
|
+
// trigger if listener has no room filter, or intersects subscriber rooms
|
|
1213
|
+
if (!handlerRooms || handlerRooms.length === 0 ||
|
|
1214
|
+
!rooms || rooms.some(r => handlerRooms.includes(r))) {
|
|
1215
|
+
fn(this.#eventData.get(last_sent_event));
|
|
1216
|
+
}
|
|
1217
|
+
});
|
|
1218
|
+
});
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
emit(event, data, rooms) {
|
|
1222
|
+
this.#eventData.set(event, data);
|
|
1223
|
+
if(typeof rooms === 'string') rooms = [rooms];
|
|
1224
|
+
|
|
1225
|
+
this.#channel.postMessage({
|
|
1226
|
+
eventData: Array.from(this.#eventData.entries()),
|
|
1227
|
+
last_sent_event: event,
|
|
1228
|
+
userId: this.#uuid,
|
|
1229
|
+
rooms: rooms && rooms.length ? rooms : undefined
|
|
1230
|
+
});
|
|
1231
|
+
|
|
1193
1232
|
return this;
|
|
1194
1233
|
}
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
this.#
|
|
1234
|
+
|
|
1235
|
+
on(event, handler = console.log, rooms) {
|
|
1236
|
+
if (!this.#handlers.has(event)) this.#handlers.set(event, []);
|
|
1237
|
+
if(typeof rooms === 'string') rooms = [rooms];
|
|
1238
|
+
this.#handlers.get(event).push({ fn: handler, rooms });
|
|
1198
1239
|
return this;
|
|
1199
1240
|
}
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
this.#
|
|
1241
|
+
|
|
1242
|
+
off(event, handler) {
|
|
1243
|
+
if (!this.#handlers.has(event)) return this;
|
|
1244
|
+
this.#handlers.set(
|
|
1245
|
+
event,
|
|
1246
|
+
this.#handlers.get(event).filter(h => h.fn !== handler)
|
|
1247
|
+
);
|
|
1203
1248
|
return this;
|
|
1204
1249
|
}
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
this.
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
this
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1250
|
+
|
|
1251
|
+
once(event, handler, rooms) {
|
|
1252
|
+
const wrapper = (data) => {
|
|
1253
|
+
handler(data);
|
|
1254
|
+
this.off(event, wrapper);
|
|
1255
|
+
};
|
|
1256
|
+
this.on(event, wrapper, rooms);
|
|
1257
|
+
return this;
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
join(...rooms) {
|
|
1261
|
+
rooms.forEach(r => this.#currentRooms.add(r));
|
|
1262
|
+
return this;
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
leave(...rooms) {
|
|
1266
|
+
if (!rooms.length) this.#currentRooms.clear();
|
|
1267
|
+
else rooms.forEach(r => this.#currentRooms.delete(r));
|
|
1222
1268
|
return this;
|
|
1223
1269
|
}
|
|
1224
|
-
|
|
1225
|
-
|
|
1270
|
+
|
|
1271
|
+
close() {
|
|
1272
|
+
this.#channel.close();
|
|
1226
1273
|
return this;
|
|
1227
1274
|
}
|
|
1275
|
+
|
|
1228
1276
|
}
|
|
1229
|
-
|
|
1277
|
+
|
|
1278
|
+
const useChannel = (name) => new UseChannel(name);
|
|
1230
1279
|
|
|
1231
1280
|
// To do : remove old items
|
|
1232
|
-
class
|
|
1281
|
+
class UseStorage{
|
|
1233
1282
|
constructor(storage, globalKey, initialValue){
|
|
1234
1283
|
this.cache={
|
|
1235
1284
|
storage,
|
|
@@ -1294,8 +1343,8 @@ class ZikoUseStorage{
|
|
|
1294
1343
|
}
|
|
1295
1344
|
|
|
1296
1345
|
}
|
|
1297
|
-
const useLocaleStorage=(key,initialValue)=>new
|
|
1298
|
-
const useSessionStorage=(key,initialValue)=>new
|
|
1346
|
+
const useLocaleStorage=(key,initialValue)=>new UseStorage(localStorage,key,initialValue);
|
|
1347
|
+
const useSessionStorage=(key,initialValue)=>new UseStorage(sessionStorage,key,initialValue);
|
|
1299
1348
|
|
|
1300
1349
|
const __State__ = {
|
|
1301
1350
|
store : new Map(),
|
|
@@ -3225,9 +3274,8 @@ function trimKeys(obj) {
|
|
|
3225
3274
|
}, Array.isArray(obj) ? [] : {});
|
|
3226
3275
|
}
|
|
3227
3276
|
|
|
3228
|
-
class Matrix
|
|
3277
|
+
class Matrix{
|
|
3229
3278
|
constructor(rows, cols, element = [] ) {
|
|
3230
|
-
super();
|
|
3231
3279
|
if(rows instanceof Matrix){
|
|
3232
3280
|
this.arr=rows.arr;
|
|
3233
3281
|
this.rows=rows.rows;
|
|
@@ -3892,9 +3940,8 @@ const matrix2=(...element)=>new Matrix(2, 2, element);
|
|
|
3892
3940
|
const matrix3=(...element)=>new Matrix(3, 3, element);
|
|
3893
3941
|
const matrix4=(...element)=>new Matrix(4, 4, element);
|
|
3894
3942
|
|
|
3895
|
-
class Complex
|
|
3943
|
+
class Complex{
|
|
3896
3944
|
constructor(a = 0, b = 0) {
|
|
3897
|
-
super();
|
|
3898
3945
|
if(a instanceof Complex){
|
|
3899
3946
|
this.a=a.a;
|
|
3900
3947
|
this.b=a.b;
|
|
@@ -4070,12 +4117,6 @@ const complex=(a,b)=>{
|
|
|
4070
4117
|
return new Complex(a,b)
|
|
4071
4118
|
};
|
|
4072
4119
|
|
|
4073
|
-
// import {
|
|
4074
|
-
// gamma,
|
|
4075
|
-
// bessel,
|
|
4076
|
-
// beta
|
|
4077
|
-
// } from "../calculus/index.js";
|
|
4078
|
-
|
|
4079
4120
|
const abs=(...x)=>mapfun$1(Math.abs,...x);
|
|
4080
4121
|
const sqrt$2=(...x)=>mapfun$1(Math.sqrt,...x);
|
|
4081
4122
|
const pow$1=(x,n)=>{
|
|
@@ -4754,7 +4795,7 @@ const timeTaken = callback => {
|
|
|
4754
4795
|
return r;
|
|
4755
4796
|
};
|
|
4756
4797
|
|
|
4757
|
-
class
|
|
4798
|
+
class UseEventEmitter {
|
|
4758
4799
|
constructor() {
|
|
4759
4800
|
this.events = {};
|
|
4760
4801
|
this.maxListeners = 10;
|
|
@@ -4816,7 +4857,7 @@ class ZikoUseEventEmitter {
|
|
|
4816
4857
|
}
|
|
4817
4858
|
}
|
|
4818
4859
|
|
|
4819
|
-
const useEventEmitter=()=>new
|
|
4860
|
+
const useEventEmitter=()=>new UseEventEmitter();
|
|
4820
4861
|
|
|
4821
4862
|
class ZikoUseFavIcon{
|
|
4822
4863
|
constructor(FavIcon,useEventEmitter=true){
|
|
@@ -5199,7 +5240,6 @@ function useDerived(deriveFn, sources) {
|
|
|
5199
5240
|
const useReactive = (nested_value) => mapfun$1(
|
|
5200
5241
|
n => {
|
|
5201
5242
|
const state = useState(n);
|
|
5202
|
-
// console.log(state)
|
|
5203
5243
|
return {
|
|
5204
5244
|
get : state[0],
|
|
5205
5245
|
set : state[1],
|
|
@@ -5208,7 +5248,7 @@ const useReactive = (nested_value) => mapfun$1(
|
|
|
5208
5248
|
nested_value
|
|
5209
5249
|
);
|
|
5210
5250
|
|
|
5211
|
-
class
|
|
5251
|
+
class UseThreed {
|
|
5212
5252
|
#workerContent;
|
|
5213
5253
|
constructor() {
|
|
5214
5254
|
this.#workerContent = (
|
|
@@ -5244,14 +5284,14 @@ class ZikoUseThreed {
|
|
|
5244
5284
|
}
|
|
5245
5285
|
|
|
5246
5286
|
const useThread = (func, callback , close) => {
|
|
5247
|
-
const T = new
|
|
5287
|
+
const T = new UseThreed();
|
|
5248
5288
|
if (func) {
|
|
5249
5289
|
T.call(func, callback , close);
|
|
5250
5290
|
}
|
|
5251
5291
|
return T;
|
|
5252
5292
|
};
|
|
5253
5293
|
|
|
5254
|
-
class
|
|
5294
|
+
class UseRoot {
|
|
5255
5295
|
constructor(PropsMap, {namespace = 'Ziko', register, ValidateCssProps = false} = {}){
|
|
5256
5296
|
this.currentPropsMap = PropsMap;
|
|
5257
5297
|
this.namespace = namespace;
|
|
@@ -5296,7 +5336,7 @@ function ValidateCssProps(PropsMap){
|
|
|
5296
5336
|
}
|
|
5297
5337
|
}
|
|
5298
5338
|
|
|
5299
|
-
const useRoot = (PropsMap, {namespace, register, ValidateCssProps} = {}) => new
|
|
5339
|
+
const useRoot = (PropsMap, {namespace, register, ValidateCssProps} = {}) => new UseRoot(PropsMap, {namespace, register, ValidateCssProps});
|
|
5300
5340
|
|
|
5301
5341
|
// Usage
|
|
5302
5342
|
|
|
@@ -5387,4 +5427,4 @@ if(globalThis?.document){
|
|
|
5387
5427
|
document?.addEventListener("DOMContentLoaded", __Ziko__.__Config__.init());
|
|
5388
5428
|
}
|
|
5389
5429
|
|
|
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,
|
|
5430
|
+
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, useChannel, 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
|
+
"version": "0.49.6",
|
|
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",
|
|
@@ -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": {
|
package/src/hooks/index.js
CHANGED
|
@@ -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 };
|
package/src/hooks/use-derived.js
CHANGED
|
@@ -4,7 +4,7 @@ export function useDerived(deriveFn, sources) {
|
|
|
4
4
|
let paused = false;
|
|
5
5
|
|
|
6
6
|
sources.forEach(source => {
|
|
7
|
-
const srcValue = source();
|
|
7
|
+
const srcValue = source();
|
|
8
8
|
srcValue._subscribe(() => {
|
|
9
9
|
if (!paused) {
|
|
10
10
|
const newVal = deriveFn(...sources.map(s => s().value));
|
|
@@ -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,6 +1,6 @@
|
|
|
1
1
|
// To do : remove old items
|
|
2
2
|
import { useChannel } from "./use-channel.js";
|
|
3
|
-
class
|
|
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
|
|
69
|
-
const useSessionStorage=(key,initialValue)=>new
|
|
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,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
|
|
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;
|
|
@@ -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
|
|
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
|
|
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
|
|
40
|
+
const useMediaQuery = (mediaQueryRules,fallback) => new UseMediaQuery(mediaQueryRules,fallback);
|
|
41
41
|
export {
|
|
42
42
|
useMediaQuery
|
|
43
43
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
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
|
|
75
|
+
const useStyle = (styles, use, id) => new UseStyle(styles, use, id)
|
|
76
76
|
export {
|
|
77
77
|
useStyle,
|
|
78
|
-
|
|
78
|
+
UseStyle
|
|
79
79
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Themes } from "../../../global/themes";
|
|
2
|
-
class
|
|
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
|
|
56
|
+
const useTheme=(theme, id=0)=>new UseTheme(theme,id)
|
|
57
57
|
export {
|
|
58
58
|
useTheme,
|
|
59
59
|
// Themes,
|
package/src/use/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './use-channel.js';
|
|
1
|
+
// export * from './use-channel.js';
|
|
2
2
|
export * from './use-event-emmiter.js';
|
|
3
3
|
export * from './use-thread.js';
|
|
4
4
|
|
|
@@ -8,4 +8,4 @@ export * from './use-favicon.js'
|
|
|
8
8
|
// export * from './use-link.js'
|
|
9
9
|
// export * from 'use-meta.js'
|
|
10
10
|
|
|
11
|
-
export * from './use-storage.js'
|
|
11
|
+
// export * from './use-storage.js'
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Random } from "../math/random/index.js";
|
|
2
|
+
|
|
3
|
+
class UseChannel {
|
|
4
|
+
constructor(name = "") {
|
|
5
|
+
this.channel = new BroadcastChannel(name);
|
|
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
|
+
});
|
|
29
|
+
}
|
|
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
|
+
});
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
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);
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
close() {
|
|
51
|
+
this.channel.close();
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
get broadcast() {
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const useChannel = (name) => new UseChannel(name);
|
|
61
|
+
export { useChannel };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
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
|
|
63
|
+
const useEventEmitter=()=>new UseEventEmitter()
|
|
64
64
|
export{useEventEmitter}
|
package/src/use/use-root.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
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
|
|
46
|
+
const useRoot = (PropsMap, {namespace, register, ValidateCssProps} = {}) => new UseRoot(PropsMap, {namespace, register, ValidateCssProps});
|
|
47
47
|
|
|
48
48
|
export{
|
|
49
|
-
|
|
49
|
+
UseRoot,
|
|
50
50
|
useRoot
|
|
51
51
|
}
|
|
52
52
|
|