ziko 0.49.5 → 0.49.7
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 +316 -230
- package/dist/ziko.js +320 -234
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +313 -228
- package/package.json +1 -1
- package/src/__ziko__/__state__.js +1 -1
- package/src/hooks/index.js +10 -1
- package/src/hooks/use-channel.js +2 -19
- package/src/hooks/use-derived.js +1 -1
- package/src/hooks/use-event-emitter.js +68 -0
- package/src/hooks/use-favicon.js +59 -0
- package/src/hooks/use-media-query.js +59 -0
- package/src/hooks/use-root.js +73 -0
- package/src/hooks/use-storage.js +99 -0
- package/src/hooks/use-thread.js +55 -0
- package/src/hooks/use-title.js +43 -0
- package/src/reactivity/hooks/head/useFavIcon.js +4 -4
- package/src/reactivity/hooks/head/useTitle.js +1 -1
- package/src/use/index.js +3 -3
- package/src/use/{use-event-emmiter.js → use-event-emmiter.js.txt} +3 -3
- package/types/hooks/index.d.ts +11 -1
- package/types/hooks/use-Thread.d.ts +33 -0
- package/types/hooks/use-derived.d.ts +14 -0
- package/types/hooks/use-event-emitter.d.ts +46 -0
- package/types/hooks/use-favicon.d.ts +41 -0
- package/types/hooks/use-media-query.d.ts +24 -0
- package/types/hooks/use-reactive.d.ts +14 -0
- package/types/hooks/use-root.d.ts +15 -0
- package/types/hooks/use-state.d.ts +25 -0
- package/types/hooks/use-storage.d.ts +47 -0
- package/types/hooks/use-title.d.ts +37 -0
- /package/src/use/{use-channel.js → use-channel.js.txt} +0 -0
- /package/src/use/{use-storage.js → use-storage.js.txt} +0 -0
package/dist/ziko.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/*
|
|
3
3
|
Project: ziko.js
|
|
4
4
|
Author: Zakaria Elalaoui
|
|
5
|
-
Date :
|
|
5
|
+
Date : Sat Nov 29 2025 19:48:11 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
|
|
@@ -1180,132 +1180,180 @@ const __CACHE__ = {
|
|
|
1180
1180
|
};
|
|
1181
1181
|
|
|
1182
1182
|
class UseChannel {
|
|
1183
|
+
#channel;
|
|
1184
|
+
#eventData;
|
|
1185
|
+
#handlers;
|
|
1186
|
+
#uuid;
|
|
1187
|
+
#subscribers;
|
|
1188
|
+
#currentRooms;
|
|
1183
1189
|
constructor(name = "") {
|
|
1184
|
-
this
|
|
1185
|
-
this
|
|
1186
|
-
this
|
|
1187
|
-
this
|
|
1188
|
-
this
|
|
1189
|
-
|
|
1190
|
-
this
|
|
1191
|
-
const { last_sent_event, userId, eventData } = e.data;
|
|
1192
|
-
|
|
1193
|
-
//
|
|
1194
|
-
if (
|
|
1195
|
-
|
|
1196
|
-
this
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
}
|
|
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();
|
|
1196
|
+
this.#channel.addEventListener("message", (e) => {
|
|
1197
|
+
const { last_sent_event, userId, eventData, rooms } = e.data;
|
|
1198
|
+
if (userId === this.#uuid) return; // ignore own messages
|
|
1199
|
+
// broadcast if no rooms, else check intersection
|
|
1200
|
+
if (rooms && rooms.length && !rooms.some(r => this.#currentRooms.has(r))) return;
|
|
1201
|
+
this.#subscribers.add(userId);
|
|
1202
|
+
this.#eventData = new Map(eventData);
|
|
1203
|
+
const handlersList = this.#handlers.get(last_sent_event);
|
|
1204
|
+
if (!handlersList) return;
|
|
1205
|
+
handlersList.forEach(({ fn, rooms: handlerRooms }) => {
|
|
1206
|
+
// trigger if listener has no room filter, or intersects subscriber rooms
|
|
1207
|
+
if (!handlerRooms || handlerRooms.length === 0 ||
|
|
1208
|
+
!rooms || rooms.some(r => handlerRooms.includes(r))) {
|
|
1209
|
+
fn(this.#eventData.get(last_sent_event));
|
|
1210
|
+
}
|
|
1211
|
+
});
|
|
1207
1212
|
});
|
|
1208
1213
|
}
|
|
1209
1214
|
|
|
1210
|
-
emit(event, data) {
|
|
1211
|
-
this
|
|
1212
|
-
|
|
1213
|
-
this
|
|
1214
|
-
eventData: this.
|
|
1215
|
+
emit(event, data, rooms) {
|
|
1216
|
+
this.#eventData.set(event, data);
|
|
1217
|
+
if(typeof rooms === 'string') rooms = [rooms];
|
|
1218
|
+
this.#channel.postMessage({
|
|
1219
|
+
eventData: Array.from(this.#eventData.entries()),
|
|
1215
1220
|
last_sent_event: event,
|
|
1216
|
-
userId: this
|
|
1221
|
+
userId: this.#uuid,
|
|
1222
|
+
rooms: rooms && rooms.length ? rooms : undefined
|
|
1217
1223
|
});
|
|
1218
1224
|
return this;
|
|
1219
1225
|
}
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
if
|
|
1223
|
-
|
|
1224
|
-
}
|
|
1225
|
-
this.handlers.get(event).push(handler);
|
|
1226
|
+
on(event, handler = console.log, rooms) {
|
|
1227
|
+
if (!this.#handlers.has(event)) this.#handlers.set(event, []);
|
|
1228
|
+
if(typeof rooms === 'string') rooms = [rooms];
|
|
1229
|
+
this.#handlers.get(event).push({ fn: handler, rooms });
|
|
1226
1230
|
return this;
|
|
1227
1231
|
}
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
this.
|
|
1232
|
+
off(event, handler) {
|
|
1233
|
+
if (!this.#handlers.has(event)) return this;
|
|
1234
|
+
this.#handlers.set(
|
|
1235
|
+
event,
|
|
1236
|
+
this.#handlers.get(event).filter(h => h.fn !== handler)
|
|
1237
|
+
);
|
|
1231
1238
|
return this;
|
|
1232
1239
|
}
|
|
1233
|
-
|
|
1234
|
-
|
|
1240
|
+
once(event, handler, rooms) {
|
|
1241
|
+
const wrapper = (data) => {
|
|
1242
|
+
handler(data);
|
|
1243
|
+
this.off(event, wrapper);
|
|
1244
|
+
};
|
|
1245
|
+
this.on(event, wrapper, rooms);
|
|
1246
|
+
return this;
|
|
1247
|
+
}
|
|
1248
|
+
join(...rooms) {
|
|
1249
|
+
rooms.forEach(r => this.#currentRooms.add(r));
|
|
1250
|
+
return this;
|
|
1251
|
+
}
|
|
1252
|
+
leave(...rooms) {
|
|
1253
|
+
if (!rooms.length) this.#currentRooms.clear();
|
|
1254
|
+
else rooms.forEach(r => this.#currentRooms.delete(r));
|
|
1255
|
+
return this;
|
|
1256
|
+
}
|
|
1257
|
+
close() {
|
|
1258
|
+
this.#channel.close();
|
|
1235
1259
|
return this;
|
|
1236
1260
|
}
|
|
1237
1261
|
}
|
|
1238
1262
|
|
|
1239
1263
|
const useChannel = (name) => new UseChannel(name);
|
|
1240
1264
|
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
this.cache={
|
|
1265
|
+
class UseStorage {
|
|
1266
|
+
constructor(storage, globalKey, initialValue, use_channel = true) {
|
|
1267
|
+
this.cache = {
|
|
1245
1268
|
storage,
|
|
1246
1269
|
globalKey,
|
|
1247
|
-
channel:useChannel(`Ziko:useStorage-${globalKey}`),
|
|
1248
|
-
oldItemKeys:new Set()
|
|
1270
|
+
channel: use_channel ? useChannel(`Ziko:useStorage-${globalKey}`) : null,
|
|
1271
|
+
oldItemKeys: new Set()
|
|
1249
1272
|
};
|
|
1250
|
-
|
|
1251
|
-
this.#
|
|
1273
|
+
|
|
1274
|
+
this.#init(initialValue, use_channel);
|
|
1252
1275
|
}
|
|
1253
|
-
|
|
1254
|
-
|
|
1276
|
+
|
|
1277
|
+
get items() {
|
|
1278
|
+
const raw = this.cache.storage.getItem(this.cache.globalKey);
|
|
1279
|
+
if (!raw) return {};
|
|
1280
|
+
try {
|
|
1281
|
+
return JSON.parse(raw);
|
|
1282
|
+
} catch {
|
|
1283
|
+
return {};
|
|
1284
|
+
}
|
|
1255
1285
|
}
|
|
1286
|
+
|
|
1256
1287
|
#maintain() {
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1288
|
+
const items = this.items;
|
|
1289
|
+
this.cache.oldItemKeys.forEach(k => delete this[k]);
|
|
1290
|
+
for (const key in items) {
|
|
1291
|
+
this[key] = items[key];
|
|
1292
|
+
this.cache.oldItemKeys.add(key);
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
#init(initialValue, use_channel) {
|
|
1296
|
+
if (use_channel && this.cache.channel) this.cache.channel.on("Ziko-Storage-Updated", () => this.#maintain());
|
|
1297
|
+
if (!initialValue) {
|
|
1298
|
+
this.#maintain();
|
|
1299
|
+
return;
|
|
1269
1300
|
}
|
|
1301
|
+
if (this.cache.storage.getItem(this.cache.globalKey)) {
|
|
1302
|
+
const existing = this.items;
|
|
1303
|
+
Object.keys(existing).forEach(k => this.cache.oldItemKeys.add(k));
|
|
1304
|
+
this.#maintain();
|
|
1305
|
+
}
|
|
1270
1306
|
else this.set(initialValue);
|
|
1271
1307
|
}
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
this.cache.
|
|
1275
|
-
|
|
1308
|
+
|
|
1309
|
+
set(data) {
|
|
1310
|
+
this.cache.storage.setItem(this.cache.globalKey, JSON.stringify(data));
|
|
1311
|
+
if (this.cache.channel) this.cache.channel.emit("Ziko-Storage-Updated", data);
|
|
1276
1312
|
this.#maintain();
|
|
1277
|
-
return this
|
|
1313
|
+
return this;
|
|
1278
1314
|
}
|
|
1279
|
-
|
|
1280
|
-
|
|
1315
|
+
|
|
1316
|
+
add(data) {
|
|
1317
|
+
this.set({
|
|
1281
1318
|
...this.items,
|
|
1282
1319
|
...data
|
|
1283
|
-
};
|
|
1284
|
-
this.cache.storage.setItem(this.cache.globalKey,JSON.stringify(db));
|
|
1285
|
-
this.#maintain();
|
|
1320
|
+
});
|
|
1286
1321
|
return this;
|
|
1287
1322
|
}
|
|
1288
|
-
remove(...keys){
|
|
1289
|
-
const
|
|
1290
|
-
|
|
1291
|
-
delete
|
|
1292
|
-
delete this[
|
|
1293
|
-
|
|
1294
|
-
|
|
1323
|
+
remove(...keys) {
|
|
1324
|
+
const items = { ...this.items };
|
|
1325
|
+
keys.forEach(key => {
|
|
1326
|
+
delete items[key];
|
|
1327
|
+
delete this[key];
|
|
1328
|
+
this.cache.oldItemKeys.delete(key);
|
|
1329
|
+
});
|
|
1330
|
+
this.set(items);
|
|
1295
1331
|
return this;
|
|
1296
1332
|
}
|
|
1297
|
-
get(key){
|
|
1333
|
+
get(key) {
|
|
1298
1334
|
return this.items[key];
|
|
1299
1335
|
}
|
|
1300
|
-
clear(){
|
|
1336
|
+
clear() {
|
|
1301
1337
|
this.cache.storage.removeItem(this.cache.globalKey);
|
|
1338
|
+
this.cache.oldItemKeys.forEach(k => delete this[k]);
|
|
1339
|
+
this.cache.oldItemKeys.clear();
|
|
1302
1340
|
this.#maintain();
|
|
1303
1341
|
return this;
|
|
1304
1342
|
}
|
|
1305
|
-
|
|
1343
|
+
onStorageUpdated(callback) {
|
|
1344
|
+
if (this.cache.channel) {
|
|
1345
|
+
this.cache.channel.on("Ziko-Storage-Updated", callback);
|
|
1346
|
+
}
|
|
1347
|
+
return this;
|
|
1348
|
+
}
|
|
1306
1349
|
}
|
|
1307
|
-
|
|
1308
|
-
|
|
1350
|
+
|
|
1351
|
+
// factory functions
|
|
1352
|
+
const useLocaleStorage = (key, initialValue, use_channel = true) =>
|
|
1353
|
+
new UseStorage(localStorage, key, initialValue, use_channel);
|
|
1354
|
+
|
|
1355
|
+
const useSessionStorage = (key, initialValue, use_channel = true) =>
|
|
1356
|
+
new UseStorage(sessionStorage, key, initialValue, use_channel);
|
|
1309
1357
|
|
|
1310
1358
|
const __State__ = {
|
|
1311
1359
|
store : new Map(),
|
|
@@ -4757,76 +4805,79 @@ const timeTaken = callback => {
|
|
|
4757
4805
|
};
|
|
4758
4806
|
|
|
4759
4807
|
class UseEventEmitter {
|
|
4760
|
-
constructor() {
|
|
4761
|
-
|
|
4762
|
-
|
|
4808
|
+
constructor(maxListeners = 10) {
|
|
4809
|
+
this.events = {};
|
|
4810
|
+
this.maxListeners = maxListeners;
|
|
4763
4811
|
}
|
|
4812
|
+
|
|
4764
4813
|
on(event, listener) {
|
|
4765
|
-
|
|
4766
|
-
this.events[event]
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
}
|
|
4814
|
+
if (!this.events[event]) this.events[event] = [];
|
|
4815
|
+
this.events[event].push(listener);
|
|
4816
|
+
if (this.events[event].length > this.maxListeners) {
|
|
4817
|
+
console.warn(`Warning: Possible memory leak. Event '${event}' has more than ${this.maxListeners} listeners.`);
|
|
4818
|
+
}
|
|
4819
|
+
return this;
|
|
4772
4820
|
}
|
|
4821
|
+
|
|
4773
4822
|
once(event, listener) {
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4823
|
+
const wrapper = (...args) => {
|
|
4824
|
+
this.off(event, wrapper);
|
|
4825
|
+
listener(...args);
|
|
4826
|
+
};
|
|
4827
|
+
return this.on(event, wrapper);
|
|
4779
4828
|
}
|
|
4780
|
-
|
|
4829
|
+
|
|
4781
4830
|
off(event, listener) {
|
|
4782
|
-
|
|
4783
|
-
|
|
4831
|
+
const listeners = this.events[event];
|
|
4832
|
+
if (!listeners) return this;
|
|
4833
|
+
|
|
4784
4834
|
const index = listeners.indexOf(listener);
|
|
4785
4835
|
if (index !== -1) {
|
|
4786
|
-
|
|
4836
|
+
listeners.splice(index, 1);
|
|
4787
4837
|
}
|
|
4788
|
-
|
|
4838
|
+
|
|
4839
|
+
return this;
|
|
4789
4840
|
}
|
|
4790
|
-
|
|
4841
|
+
|
|
4791
4842
|
emit(event, data) {
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4843
|
+
const listeners = this.events[event];
|
|
4844
|
+
if (!listeners) return false;
|
|
4845
|
+
|
|
4846
|
+
// Make a copy so removing listeners inside callbacks doesn't affect iteration
|
|
4847
|
+
[...listeners].forEach(listener => {
|
|
4848
|
+
try {
|
|
4849
|
+
listener(data);
|
|
4850
|
+
} catch (e) {
|
|
4851
|
+
console.error(`Error in listener for '${event}':`, e);
|
|
4852
|
+
}
|
|
4796
4853
|
});
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
clear(event) {
|
|
4801
|
-
if (event) {
|
|
4802
|
-
delete this.events[event];
|
|
4803
|
-
} else {
|
|
4804
|
-
this.events = {};
|
|
4805
|
-
}
|
|
4854
|
+
|
|
4855
|
+
return true;
|
|
4806
4856
|
}
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4857
|
+
remove(event){
|
|
4858
|
+
delete this.events[event];
|
|
4859
|
+
return this;
|
|
4810
4860
|
}
|
|
4811
|
-
|
|
4812
|
-
removeAllListeners(event) {
|
|
4813
|
-
if (event) {
|
|
4814
|
-
this.events[event] = [];
|
|
4815
|
-
} else {
|
|
4861
|
+
clear() {
|
|
4816
4862
|
this.events = {};
|
|
4817
|
-
|
|
4863
|
+
return this;
|
|
4818
4864
|
}
|
|
4819
|
-
}
|
|
4820
4865
|
|
|
4821
|
-
|
|
4866
|
+
setMaxListeners(max) {
|
|
4867
|
+
this.maxListeners = max;
|
|
4868
|
+
return this;
|
|
4869
|
+
}
|
|
4870
|
+
}
|
|
4871
|
+
|
|
4872
|
+
const useEventEmitter = (maxListeners) => new UseEventEmitter(maxListeners);
|
|
4822
4873
|
|
|
4823
4874
|
class ZikoUseFavIcon{
|
|
4824
|
-
constructor(FavIcon,
|
|
4875
|
+
constructor(FavIcon,withEmitter=true){
|
|
4825
4876
|
this.#init();
|
|
4826
4877
|
this.cache={
|
|
4827
4878
|
Emitter:null
|
|
4828
4879
|
};
|
|
4829
|
-
if(
|
|
4880
|
+
if(withEmitter)this.useEventEmitter();
|
|
4830
4881
|
this.set(FavIcon);
|
|
4831
4882
|
}
|
|
4832
4883
|
#init(){
|
|
@@ -4855,7 +4906,7 @@ class ZikoUseFavIcon{
|
|
|
4855
4906
|
}
|
|
4856
4907
|
|
|
4857
4908
|
}
|
|
4858
|
-
const useFavIcon=(FavIcon,
|
|
4909
|
+
const useFavIcon=(FavIcon,withEmitter)=>new ZikoUseFavIcon(FavIcon,withEmitter);
|
|
4859
4910
|
|
|
4860
4911
|
class ZikoMeta{
|
|
4861
4912
|
constructor({viewport,charset,description,author,keywords}){
|
|
@@ -4935,7 +4986,7 @@ class ZikoUseTitle{
|
|
|
4935
4986
|
return this;
|
|
4936
4987
|
}
|
|
4937
4988
|
}
|
|
4938
|
-
const useTitle=(title, useEventEmitter)=>new ZikoUseTitle(title, useEventEmitter);
|
|
4989
|
+
const useTitle$1=(title, useEventEmitter)=>new ZikoUseTitle(title, useEventEmitter);
|
|
4939
4990
|
|
|
4940
4991
|
// import {useLink} from "./";
|
|
4941
4992
|
class ZikoHead{
|
|
@@ -4943,7 +4994,7 @@ class ZikoHead{
|
|
|
4943
4994
|
this.html = globalThis?.document?.documentElement;
|
|
4944
4995
|
this.head = globalThis?.document?.head;
|
|
4945
4996
|
|
|
4946
|
-
title && useTitle(title);
|
|
4997
|
+
title && useTitle$1(title);
|
|
4947
4998
|
lang && this.setLang(lang);
|
|
4948
4999
|
icon && useFavIcon(icon);
|
|
4949
5000
|
meta && useMeta(meta);
|
|
@@ -5180,7 +5231,7 @@ function useDerived(deriveFn, sources) {
|
|
|
5180
5231
|
const subscribers = new Set();
|
|
5181
5232
|
|
|
5182
5233
|
sources.forEach(source => {
|
|
5183
|
-
const srcValue = source();
|
|
5234
|
+
const srcValue = source();
|
|
5184
5235
|
srcValue._subscribe(() => {
|
|
5185
5236
|
{
|
|
5186
5237
|
const newVal = deriveFn(...sources.map(s => s().value));
|
|
@@ -5209,121 +5260,155 @@ const useReactive = (nested_value) => mapfun$1(
|
|
|
5209
5260
|
nested_value
|
|
5210
5261
|
);
|
|
5211
5262
|
|
|
5212
|
-
class
|
|
5213
|
-
#
|
|
5263
|
+
class UseThread {
|
|
5264
|
+
#worker;
|
|
5265
|
+
#callbacks = new Map();
|
|
5266
|
+
#idCounter = 0;
|
|
5267
|
+
|
|
5214
5268
|
constructor() {
|
|
5215
|
-
|
|
5216
|
-
function
|
|
5269
|
+
const workerCode = `
|
|
5270
|
+
this.onmessage = function(e) {
|
|
5271
|
+
const { id, funStr, args, close } = e.data;
|
|
5217
5272
|
try {
|
|
5218
|
-
const func = new Function("return " +
|
|
5219
|
-
|
|
5220
|
-
postMessage({ result });
|
|
5273
|
+
const func = new Function("return " + funStr)();
|
|
5274
|
+
const result = func(...args);
|
|
5275
|
+
postMessage({ id, result });
|
|
5221
5276
|
} catch (error) {
|
|
5222
|
-
postMessage({ error: error.message });
|
|
5277
|
+
postMessage({ id, error: error.message });
|
|
5223
5278
|
} finally {
|
|
5224
|
-
if (
|
|
5279
|
+
if (close) self.close();
|
|
5225
5280
|
}
|
|
5226
5281
|
}
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
this
|
|
5282
|
+
`;
|
|
5283
|
+
const blob = new Blob([workerCode], { type: "text/javascript" });
|
|
5284
|
+
this.#worker = new Worker(URL.createObjectURL(blob));
|
|
5285
|
+
|
|
5286
|
+
this.#worker.addEventListener("message", (e) => {
|
|
5287
|
+
const { id, result, error } = e.data;
|
|
5288
|
+
const callback = this.#callbacks.get(id);
|
|
5289
|
+
if (!callback) return;
|
|
5290
|
+
|
|
5291
|
+
callback(result, error);
|
|
5292
|
+
this.#callbacks.delete(id);
|
|
5293
|
+
});
|
|
5230
5294
|
}
|
|
5231
|
-
call(func, callback, close = true) {
|
|
5232
|
-
|
|
5233
|
-
|
|
5295
|
+
call(func, callback, args = [], close = true) {
|
|
5296
|
+
if (typeof func !== "function") throw new TypeError("func must be a function");
|
|
5297
|
+
const id = ++this.#idCounter;
|
|
5298
|
+
this.#callbacks.set(id, callback);
|
|
5299
|
+
|
|
5300
|
+
this.#worker.postMessage({
|
|
5301
|
+
id,
|
|
5302
|
+
funStr: func.toString(),
|
|
5303
|
+
args,
|
|
5234
5304
|
close
|
|
5235
5305
|
});
|
|
5236
|
-
|
|
5237
|
-
if (e.data.error) {
|
|
5238
|
-
console.error(e.data.error);
|
|
5239
|
-
} else {
|
|
5240
|
-
callback(e.data.result);
|
|
5241
|
-
}
|
|
5242
|
-
};
|
|
5306
|
+
|
|
5243
5307
|
return this;
|
|
5244
5308
|
}
|
|
5245
|
-
}
|
|
5246
5309
|
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
if (func) {
|
|
5250
|
-
T.call(func, callback , close);
|
|
5310
|
+
terminate() {
|
|
5311
|
+
this.#worker.terminate();
|
|
5251
5312
|
}
|
|
5252
|
-
|
|
5253
|
-
};
|
|
5313
|
+
}
|
|
5254
5314
|
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
use(PropsMap){
|
|
5265
|
-
if(this.ValidateCssProps) ValidateCssProps(PropsMap);
|
|
5266
|
-
this.currentPropsMap = PropsMap;
|
|
5267
|
-
this.#maintain();
|
|
5268
|
-
return this;
|
|
5315
|
+
/*
|
|
5316
|
+
[
|
|
5317
|
+
{
|
|
5318
|
+
query: '(min-width: 600px)',
|
|
5319
|
+
callback: () => console.log(1)
|
|
5320
|
+
},
|
|
5321
|
+
{
|
|
5322
|
+
query: '(max-width: 300px)',
|
|
5323
|
+
callback: () => console.log(2)
|
|
5269
5324
|
}
|
|
5270
|
-
|
|
5271
|
-
|
|
5272
|
-
|
|
5273
|
-
|
|
5274
|
-
|
|
5275
|
-
|
|
5276
|
-
|
|
5277
|
-
|
|
5278
|
-
|
|
5279
|
-
|
|
5280
|
-
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
writable: true,
|
|
5284
|
-
configurable: true,
|
|
5285
|
-
enumerable: false
|
|
5286
|
-
});
|
|
5287
|
-
}
|
|
5325
|
+
]
|
|
5326
|
+
*/
|
|
5327
|
+
|
|
5328
|
+
class UseMediaQuery {
|
|
5329
|
+
#mediaQueryRules;
|
|
5330
|
+
#fallback;
|
|
5331
|
+
#lastCalledCallback = null;
|
|
5332
|
+
|
|
5333
|
+
constructor(mediaQueryRules = [], fallback = () => {}) {
|
|
5334
|
+
this.#mediaQueryRules = mediaQueryRules;
|
|
5335
|
+
this.#fallback = fallback;
|
|
5336
|
+
|
|
5337
|
+
this.#init();
|
|
5288
5338
|
}
|
|
5289
|
-
}
|
|
5290
5339
|
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
}
|
|
5340
|
+
// PRIVATE: check if ANY rule matches
|
|
5341
|
+
#checkAllRules() {
|
|
5342
|
+
return this.#mediaQueryRules.some(
|
|
5343
|
+
({ query }) => globalThis.matchMedia(query).matches
|
|
5344
|
+
);
|
|
5297
5345
|
}
|
|
5298
|
-
}
|
|
5299
5346
|
|
|
5300
|
-
|
|
5347
|
+
// PRIVATE: installs listeners and initial checks
|
|
5348
|
+
#init() {
|
|
5349
|
+
this.#mediaQueryRules.forEach(({ query, callback }) => {
|
|
5350
|
+
const mediaQueryList = globalThis.matchMedia(query);
|
|
5301
5351
|
|
|
5302
|
-
|
|
5352
|
+
const checkMatches = () => {
|
|
5353
|
+
const anyMatch = this.#checkAllRules();
|
|
5303
5354
|
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
|
|
5309
|
-
|
|
5310
|
-
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
|
|
5315
|
-
|
|
5355
|
+
if (mediaQueryList.matches) {
|
|
5356
|
+
callback();
|
|
5357
|
+
this.#lastCalledCallback = callback;
|
|
5358
|
+
} else if (!anyMatch && this.#lastCalledCallback !== this.#fallback) {
|
|
5359
|
+
this.#fallback();
|
|
5360
|
+
this.#lastCalledCallback = this.#fallback;
|
|
5361
|
+
}
|
|
5362
|
+
};
|
|
5363
|
+
|
|
5364
|
+
checkMatches();
|
|
5365
|
+
mediaQueryList.addEventListener("change", checkMatches);
|
|
5366
|
+
});
|
|
5367
|
+
}
|
|
5316
5368
|
}
|
|
5317
|
-
const {use, border, background, color} = useRoot(Style.S1)
|
|
5318
5369
|
|
|
5319
|
-
|
|
5320
|
-
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
|
|
5324
|
-
|
|
5370
|
+
const useMediaQuery = (mediaQueryRules, fallback) =>
|
|
5371
|
+
new UseMediaQuery(mediaQueryRules, fallback);
|
|
5372
|
+
|
|
5373
|
+
class UseTitle {
|
|
5374
|
+
constructor(title = document.title, withEmitter = true) {
|
|
5375
|
+
this.cache = {
|
|
5376
|
+
emitter: null
|
|
5377
|
+
};
|
|
5325
5378
|
|
|
5326
|
-
|
|
5379
|
+
if (withEmitter) this.useEventEmitter();
|
|
5380
|
+
this.set(title);
|
|
5381
|
+
}
|
|
5382
|
+
|
|
5383
|
+
useEventEmitter() {
|
|
5384
|
+
this.cache.emitter = useEventEmitter();
|
|
5385
|
+
return this;
|
|
5386
|
+
}
|
|
5387
|
+
|
|
5388
|
+
setTitle(title) {
|
|
5389
|
+
if (title !== document.title) {
|
|
5390
|
+
document.title = title;
|
|
5391
|
+
|
|
5392
|
+
if (this.cache.emitter) {
|
|
5393
|
+
this.cache.emitter.emit("ziko:title-changed", title);
|
|
5394
|
+
}
|
|
5395
|
+
}
|
|
5396
|
+
return this;
|
|
5397
|
+
}
|
|
5398
|
+
|
|
5399
|
+
get current() {
|
|
5400
|
+
return document.title;
|
|
5401
|
+
}
|
|
5402
|
+
|
|
5403
|
+
onChange(callback) {
|
|
5404
|
+
if (this.cache.emitter) {
|
|
5405
|
+
this.cache.emitter.on("ziko:title-changed", callback);
|
|
5406
|
+
}
|
|
5407
|
+
return this;
|
|
5408
|
+
}
|
|
5409
|
+
}
|
|
5410
|
+
|
|
5411
|
+
const useTitle = (title, withEmitter = true) => new UseTitle(title, withEmitter);
|
|
5327
5412
|
|
|
5328
5413
|
let {sqrt, cos, sin, exp, log, cosh, sinh} = Math;
|
|
5329
5414
|
// Math.abs = new Proxy(Math.abs, {
|
|
@@ -5418,7 +5503,7 @@ exports.UINode = UINode;
|
|
|
5418
5503
|
exports.UISVGWrapper = UISVGWrapper;
|
|
5419
5504
|
exports.UISwitch = UISwitch;
|
|
5420
5505
|
exports.UIView = UIView;
|
|
5421
|
-
exports.
|
|
5506
|
+
exports.UseThread = UseThread;
|
|
5422
5507
|
exports.Utils = Utils;
|
|
5423
5508
|
exports.View = View;
|
|
5424
5509
|
exports.ZikoApp = ZikoApp;
|
|
@@ -5590,14 +5675,15 @@ exports.tick = tick;
|
|
|
5590
5675
|
exports.timeTaken = timeTaken;
|
|
5591
5676
|
exports.time_memory_Taken = time_memory_Taken;
|
|
5592
5677
|
exports.timeout = timeout;
|
|
5678
|
+
exports.useChannel = useChannel;
|
|
5593
5679
|
exports.useDerived = useDerived;
|
|
5594
5680
|
exports.useEventEmitter = useEventEmitter;
|
|
5595
5681
|
exports.useLocaleStorage = useLocaleStorage;
|
|
5682
|
+
exports.useMediaQuery = useMediaQuery;
|
|
5596
5683
|
exports.useReactive = useReactive;
|
|
5597
|
-
exports.useRoot = useRoot;
|
|
5598
5684
|
exports.useSessionStorage = useSessionStorage;
|
|
5599
5685
|
exports.useState = useState;
|
|
5600
|
-
exports.
|
|
5686
|
+
exports.useTitle = useTitle;
|
|
5601
5687
|
exports.wait = wait;
|
|
5602
5688
|
exports.waitForUIElm = waitForUIElm;
|
|
5603
5689
|
exports.waitForUIElmSync = waitForUIElmSync;
|