ziko 0.49.6 → 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 +253 -209
- package/dist/ziko.js +257 -213
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +251 -207
- package/package.json +1 -1
- package/src/hooks/index.js +9 -1
- package/src/hooks/use-channel.js +2 -19
- 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 +72 -46
- 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 +1 -1
- package/src/use/{use-event-emmiter.js → use-event-emmiter.js.txt} +3 -3
- package/types/hooks/index.d.ts +8 -1
- package/types/hooks/use-Thread.d.ts +33 -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-root.d.ts +15 -0
- package/types/hooks/use-storage.d.ts +47 -0
- package/types/hooks/use-title.d.ts +37 -0
package/dist/ziko.js
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
|
|
@@ -1184,36 +1184,28 @@
|
|
|
1184
1184
|
};
|
|
1185
1185
|
|
|
1186
1186
|
class UseChannel {
|
|
1187
|
-
// private fields
|
|
1188
1187
|
#channel;
|
|
1189
1188
|
#eventData;
|
|
1190
1189
|
#handlers;
|
|
1191
1190
|
#uuid;
|
|
1192
1191
|
#subscribers;
|
|
1193
|
-
#currentRooms;
|
|
1194
|
-
|
|
1192
|
+
#currentRooms;
|
|
1195
1193
|
constructor(name = "") {
|
|
1196
1194
|
this.#channel = new BroadcastChannel(name);
|
|
1197
1195
|
this.#eventData = new Map();
|
|
1198
1196
|
this.#handlers = new Map(); // Map<event, Array<{fn, rooms}>>
|
|
1199
1197
|
this.#uuid = "ziko-channel:" + Random.string(10);
|
|
1200
1198
|
this.#subscribers = new Set([this.#uuid]);
|
|
1201
|
-
this.#currentRooms = new Set();
|
|
1202
|
-
|
|
1199
|
+
this.#currentRooms = new Set();
|
|
1203
1200
|
this.#channel.addEventListener("message", (e) => {
|
|
1204
1201
|
const { last_sent_event, userId, eventData, rooms } = e.data;
|
|
1205
|
-
|
|
1206
1202
|
if (userId === this.#uuid) return; // ignore own messages
|
|
1207
|
-
|
|
1208
1203
|
// broadcast if no rooms, else check intersection
|
|
1209
1204
|
if (rooms && rooms.length && !rooms.some(r => this.#currentRooms.has(r))) return;
|
|
1210
|
-
|
|
1211
1205
|
this.#subscribers.add(userId);
|
|
1212
1206
|
this.#eventData = new Map(eventData);
|
|
1213
|
-
|
|
1214
1207
|
const handlersList = this.#handlers.get(last_sent_event);
|
|
1215
1208
|
if (!handlersList) return;
|
|
1216
|
-
|
|
1217
1209
|
handlersList.forEach(({ fn, rooms: handlerRooms }) => {
|
|
1218
1210
|
// trigger if listener has no room filter, or intersects subscriber rooms
|
|
1219
1211
|
if (!handlerRooms || handlerRooms.length === 0 ||
|
|
@@ -1227,24 +1219,20 @@
|
|
|
1227
1219
|
emit(event, data, rooms) {
|
|
1228
1220
|
this.#eventData.set(event, data);
|
|
1229
1221
|
if(typeof rooms === 'string') rooms = [rooms];
|
|
1230
|
-
|
|
1231
1222
|
this.#channel.postMessage({
|
|
1232
1223
|
eventData: Array.from(this.#eventData.entries()),
|
|
1233
1224
|
last_sent_event: event,
|
|
1234
1225
|
userId: this.#uuid,
|
|
1235
1226
|
rooms: rooms && rooms.length ? rooms : undefined
|
|
1236
1227
|
});
|
|
1237
|
-
|
|
1238
1228
|
return this;
|
|
1239
1229
|
}
|
|
1240
|
-
|
|
1241
1230
|
on(event, handler = console.log, rooms) {
|
|
1242
1231
|
if (!this.#handlers.has(event)) this.#handlers.set(event, []);
|
|
1243
1232
|
if(typeof rooms === 'string') rooms = [rooms];
|
|
1244
1233
|
this.#handlers.get(event).push({ fn: handler, rooms });
|
|
1245
1234
|
return this;
|
|
1246
1235
|
}
|
|
1247
|
-
|
|
1248
1236
|
off(event, handler) {
|
|
1249
1237
|
if (!this.#handlers.has(event)) return this;
|
|
1250
1238
|
this.#handlers.set(
|
|
@@ -1253,7 +1241,6 @@
|
|
|
1253
1241
|
);
|
|
1254
1242
|
return this;
|
|
1255
1243
|
}
|
|
1256
|
-
|
|
1257
1244
|
once(event, handler, rooms) {
|
|
1258
1245
|
const wrapper = (data) => {
|
|
1259
1246
|
handler(data);
|
|
@@ -1262,95 +1249,115 @@
|
|
|
1262
1249
|
this.on(event, wrapper, rooms);
|
|
1263
1250
|
return this;
|
|
1264
1251
|
}
|
|
1265
|
-
|
|
1266
1252
|
join(...rooms) {
|
|
1267
1253
|
rooms.forEach(r => this.#currentRooms.add(r));
|
|
1268
1254
|
return this;
|
|
1269
1255
|
}
|
|
1270
|
-
|
|
1271
1256
|
leave(...rooms) {
|
|
1272
1257
|
if (!rooms.length) this.#currentRooms.clear();
|
|
1273
1258
|
else rooms.forEach(r => this.#currentRooms.delete(r));
|
|
1274
1259
|
return this;
|
|
1275
1260
|
}
|
|
1276
|
-
|
|
1277
1261
|
close() {
|
|
1278
1262
|
this.#channel.close();
|
|
1279
1263
|
return this;
|
|
1280
1264
|
}
|
|
1281
|
-
|
|
1282
1265
|
}
|
|
1283
1266
|
|
|
1284
1267
|
const useChannel = (name) => new UseChannel(name);
|
|
1285
1268
|
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
this.cache={
|
|
1269
|
+
class UseStorage {
|
|
1270
|
+
constructor(storage, globalKey, initialValue, use_channel = true) {
|
|
1271
|
+
this.cache = {
|
|
1290
1272
|
storage,
|
|
1291
1273
|
globalKey,
|
|
1292
|
-
channel:useChannel(`Ziko:useStorage-${globalKey}`),
|
|
1293
|
-
oldItemKeys:new Set()
|
|
1274
|
+
channel: use_channel ? useChannel(`Ziko:useStorage-${globalKey}`) : null,
|
|
1275
|
+
oldItemKeys: new Set()
|
|
1294
1276
|
};
|
|
1295
|
-
|
|
1296
|
-
this.#
|
|
1277
|
+
|
|
1278
|
+
this.#init(initialValue, use_channel);
|
|
1297
1279
|
}
|
|
1298
|
-
|
|
1299
|
-
|
|
1280
|
+
|
|
1281
|
+
get items() {
|
|
1282
|
+
const raw = this.cache.storage.getItem(this.cache.globalKey);
|
|
1283
|
+
if (!raw) return {};
|
|
1284
|
+
try {
|
|
1285
|
+
return JSON.parse(raw);
|
|
1286
|
+
} catch {
|
|
1287
|
+
return {};
|
|
1288
|
+
}
|
|
1300
1289
|
}
|
|
1290
|
+
|
|
1301
1291
|
#maintain() {
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1292
|
+
const items = this.items;
|
|
1293
|
+
this.cache.oldItemKeys.forEach(k => delete this[k]);
|
|
1294
|
+
for (const key in items) {
|
|
1295
|
+
this[key] = items[key];
|
|
1296
|
+
this.cache.oldItemKeys.add(key);
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
#init(initialValue, use_channel) {
|
|
1300
|
+
if (use_channel && this.cache.channel) this.cache.channel.on("Ziko-Storage-Updated", () => this.#maintain());
|
|
1301
|
+
if (!initialValue) {
|
|
1302
|
+
this.#maintain();
|
|
1303
|
+
return;
|
|
1314
1304
|
}
|
|
1305
|
+
if (this.cache.storage.getItem(this.cache.globalKey)) {
|
|
1306
|
+
const existing = this.items;
|
|
1307
|
+
Object.keys(existing).forEach(k => this.cache.oldItemKeys.add(k));
|
|
1308
|
+
this.#maintain();
|
|
1309
|
+
}
|
|
1315
1310
|
else this.set(initialValue);
|
|
1316
1311
|
}
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
this.cache.
|
|
1320
|
-
|
|
1312
|
+
|
|
1313
|
+
set(data) {
|
|
1314
|
+
this.cache.storage.setItem(this.cache.globalKey, JSON.stringify(data));
|
|
1315
|
+
if (this.cache.channel) this.cache.channel.emit("Ziko-Storage-Updated", data);
|
|
1321
1316
|
this.#maintain();
|
|
1322
|
-
return this
|
|
1317
|
+
return this;
|
|
1323
1318
|
}
|
|
1324
|
-
|
|
1325
|
-
|
|
1319
|
+
|
|
1320
|
+
add(data) {
|
|
1321
|
+
this.set({
|
|
1326
1322
|
...this.items,
|
|
1327
1323
|
...data
|
|
1328
|
-
};
|
|
1329
|
-
this.cache.storage.setItem(this.cache.globalKey,JSON.stringify(db));
|
|
1330
|
-
this.#maintain();
|
|
1324
|
+
});
|
|
1331
1325
|
return this;
|
|
1332
1326
|
}
|
|
1333
|
-
remove(...keys){
|
|
1334
|
-
const
|
|
1335
|
-
|
|
1336
|
-
delete
|
|
1337
|
-
delete this[
|
|
1338
|
-
|
|
1339
|
-
|
|
1327
|
+
remove(...keys) {
|
|
1328
|
+
const items = { ...this.items };
|
|
1329
|
+
keys.forEach(key => {
|
|
1330
|
+
delete items[key];
|
|
1331
|
+
delete this[key];
|
|
1332
|
+
this.cache.oldItemKeys.delete(key);
|
|
1333
|
+
});
|
|
1334
|
+
this.set(items);
|
|
1340
1335
|
return this;
|
|
1341
1336
|
}
|
|
1342
|
-
get(key){
|
|
1337
|
+
get(key) {
|
|
1343
1338
|
return this.items[key];
|
|
1344
1339
|
}
|
|
1345
|
-
clear(){
|
|
1340
|
+
clear() {
|
|
1346
1341
|
this.cache.storage.removeItem(this.cache.globalKey);
|
|
1342
|
+
this.cache.oldItemKeys.forEach(k => delete this[k]);
|
|
1343
|
+
this.cache.oldItemKeys.clear();
|
|
1347
1344
|
this.#maintain();
|
|
1348
1345
|
return this;
|
|
1349
1346
|
}
|
|
1350
|
-
|
|
1347
|
+
onStorageUpdated(callback) {
|
|
1348
|
+
if (this.cache.channel) {
|
|
1349
|
+
this.cache.channel.on("Ziko-Storage-Updated", callback);
|
|
1350
|
+
}
|
|
1351
|
+
return this;
|
|
1352
|
+
}
|
|
1351
1353
|
}
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
+
|
|
1355
|
+
// factory functions
|
|
1356
|
+
const useLocaleStorage = (key, initialValue, use_channel = true) =>
|
|
1357
|
+
new UseStorage(localStorage, key, initialValue, use_channel);
|
|
1358
|
+
|
|
1359
|
+
const useSessionStorage = (key, initialValue, use_channel = true) =>
|
|
1360
|
+
new UseStorage(sessionStorage, key, initialValue, use_channel);
|
|
1354
1361
|
|
|
1355
1362
|
const __State__ = {
|
|
1356
1363
|
store : new Map(),
|
|
@@ -4802,76 +4809,79 @@
|
|
|
4802
4809
|
};
|
|
4803
4810
|
|
|
4804
4811
|
class UseEventEmitter {
|
|
4805
|
-
constructor() {
|
|
4806
|
-
|
|
4807
|
-
|
|
4812
|
+
constructor(maxListeners = 10) {
|
|
4813
|
+
this.events = {};
|
|
4814
|
+
this.maxListeners = maxListeners;
|
|
4808
4815
|
}
|
|
4816
|
+
|
|
4809
4817
|
on(event, listener) {
|
|
4810
|
-
|
|
4811
|
-
this.events[event]
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
}
|
|
4818
|
+
if (!this.events[event]) this.events[event] = [];
|
|
4819
|
+
this.events[event].push(listener);
|
|
4820
|
+
if (this.events[event].length > this.maxListeners) {
|
|
4821
|
+
console.warn(`Warning: Possible memory leak. Event '${event}' has more than ${this.maxListeners} listeners.`);
|
|
4822
|
+
}
|
|
4823
|
+
return this;
|
|
4817
4824
|
}
|
|
4825
|
+
|
|
4818
4826
|
once(event, listener) {
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
|
|
4827
|
+
const wrapper = (...args) => {
|
|
4828
|
+
this.off(event, wrapper);
|
|
4829
|
+
listener(...args);
|
|
4830
|
+
};
|
|
4831
|
+
return this.on(event, wrapper);
|
|
4824
4832
|
}
|
|
4825
|
-
|
|
4833
|
+
|
|
4826
4834
|
off(event, listener) {
|
|
4827
|
-
|
|
4828
|
-
|
|
4835
|
+
const listeners = this.events[event];
|
|
4836
|
+
if (!listeners) return this;
|
|
4837
|
+
|
|
4829
4838
|
const index = listeners.indexOf(listener);
|
|
4830
4839
|
if (index !== -1) {
|
|
4831
|
-
|
|
4840
|
+
listeners.splice(index, 1);
|
|
4832
4841
|
}
|
|
4833
|
-
|
|
4842
|
+
|
|
4843
|
+
return this;
|
|
4834
4844
|
}
|
|
4835
|
-
|
|
4845
|
+
|
|
4836
4846
|
emit(event, data) {
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4847
|
+
const listeners = this.events[event];
|
|
4848
|
+
if (!listeners) return false;
|
|
4849
|
+
|
|
4850
|
+
// Make a copy so removing listeners inside callbacks doesn't affect iteration
|
|
4851
|
+
[...listeners].forEach(listener => {
|
|
4852
|
+
try {
|
|
4853
|
+
listener(data);
|
|
4854
|
+
} catch (e) {
|
|
4855
|
+
console.error(`Error in listener for '${event}':`, e);
|
|
4856
|
+
}
|
|
4841
4857
|
});
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
clear(event) {
|
|
4846
|
-
if (event) {
|
|
4847
|
-
delete this.events[event];
|
|
4848
|
-
} else {
|
|
4849
|
-
this.events = {};
|
|
4850
|
-
}
|
|
4858
|
+
|
|
4859
|
+
return true;
|
|
4851
4860
|
}
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4861
|
+
remove(event){
|
|
4862
|
+
delete this.events[event];
|
|
4863
|
+
return this;
|
|
4855
4864
|
}
|
|
4856
|
-
|
|
4857
|
-
removeAllListeners(event) {
|
|
4858
|
-
if (event) {
|
|
4859
|
-
this.events[event] = [];
|
|
4860
|
-
} else {
|
|
4865
|
+
clear() {
|
|
4861
4866
|
this.events = {};
|
|
4862
|
-
|
|
4867
|
+
return this;
|
|
4863
4868
|
}
|
|
4864
|
-
}
|
|
4865
4869
|
|
|
4866
|
-
|
|
4870
|
+
setMaxListeners(max) {
|
|
4871
|
+
this.maxListeners = max;
|
|
4872
|
+
return this;
|
|
4873
|
+
}
|
|
4874
|
+
}
|
|
4875
|
+
|
|
4876
|
+
const useEventEmitter = (maxListeners) => new UseEventEmitter(maxListeners);
|
|
4867
4877
|
|
|
4868
4878
|
class ZikoUseFavIcon{
|
|
4869
|
-
constructor(FavIcon,
|
|
4879
|
+
constructor(FavIcon,withEmitter=true){
|
|
4870
4880
|
this.#init();
|
|
4871
4881
|
this.cache={
|
|
4872
4882
|
Emitter:null
|
|
4873
4883
|
};
|
|
4874
|
-
if(
|
|
4884
|
+
if(withEmitter)this.useEventEmitter();
|
|
4875
4885
|
this.set(FavIcon);
|
|
4876
4886
|
}
|
|
4877
4887
|
#init(){
|
|
@@ -4900,7 +4910,7 @@
|
|
|
4900
4910
|
}
|
|
4901
4911
|
|
|
4902
4912
|
}
|
|
4903
|
-
const useFavIcon=(FavIcon,
|
|
4913
|
+
const useFavIcon=(FavIcon,withEmitter)=>new ZikoUseFavIcon(FavIcon,withEmitter);
|
|
4904
4914
|
|
|
4905
4915
|
class ZikoMeta{
|
|
4906
4916
|
constructor({viewport,charset,description,author,keywords}){
|
|
@@ -4980,7 +4990,7 @@
|
|
|
4980
4990
|
return this;
|
|
4981
4991
|
}
|
|
4982
4992
|
}
|
|
4983
|
-
const useTitle=(title, useEventEmitter)=>new ZikoUseTitle(title, useEventEmitter);
|
|
4993
|
+
const useTitle$1=(title, useEventEmitter)=>new ZikoUseTitle(title, useEventEmitter);
|
|
4984
4994
|
|
|
4985
4995
|
// import {useLink} from "./";
|
|
4986
4996
|
class ZikoHead{
|
|
@@ -4988,7 +4998,7 @@
|
|
|
4988
4998
|
this.html = globalThis?.document?.documentElement;
|
|
4989
4999
|
this.head = globalThis?.document?.head;
|
|
4990
5000
|
|
|
4991
|
-
title && useTitle(title);
|
|
5001
|
+
title && useTitle$1(title);
|
|
4992
5002
|
lang && this.setLang(lang);
|
|
4993
5003
|
icon && useFavIcon(icon);
|
|
4994
5004
|
meta && useMeta(meta);
|
|
@@ -5225,7 +5235,7 @@
|
|
|
5225
5235
|
const subscribers = new Set();
|
|
5226
5236
|
|
|
5227
5237
|
sources.forEach(source => {
|
|
5228
|
-
const srcValue = source();
|
|
5238
|
+
const srcValue = source();
|
|
5229
5239
|
srcValue._subscribe(() => {
|
|
5230
5240
|
{
|
|
5231
5241
|
const newVal = deriveFn(...sources.map(s => s().value));
|
|
@@ -5254,121 +5264,155 @@
|
|
|
5254
5264
|
nested_value
|
|
5255
5265
|
);
|
|
5256
5266
|
|
|
5257
|
-
class
|
|
5258
|
-
#
|
|
5267
|
+
class UseThread {
|
|
5268
|
+
#worker;
|
|
5269
|
+
#callbacks = new Map();
|
|
5270
|
+
#idCounter = 0;
|
|
5271
|
+
|
|
5259
5272
|
constructor() {
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
|
|
5273
|
+
const workerCode = `
|
|
5274
|
+
this.onmessage = function(e) {
|
|
5275
|
+
const { id, funStr, args, close } = e.data;
|
|
5276
|
+
try {
|
|
5277
|
+
const func = new Function("return " + funStr)();
|
|
5278
|
+
const result = func(...args);
|
|
5279
|
+
postMessage({ id, result });
|
|
5280
|
+
} catch (error) {
|
|
5281
|
+
postMessage({ id, error: error.message });
|
|
5282
|
+
} finally {
|
|
5283
|
+
if (close) self.close();
|
|
5271
5284
|
}
|
|
5272
|
-
|
|
5273
|
-
|
|
5274
|
-
|
|
5285
|
+
}
|
|
5286
|
+
`;
|
|
5287
|
+
const blob = new Blob([workerCode], { type: "text/javascript" });
|
|
5288
|
+
this.#worker = new Worker(URL.createObjectURL(blob));
|
|
5289
|
+
|
|
5290
|
+
this.#worker.addEventListener("message", (e) => {
|
|
5291
|
+
const { id, result, error } = e.data;
|
|
5292
|
+
const callback = this.#callbacks.get(id);
|
|
5293
|
+
if (!callback) return;
|
|
5294
|
+
|
|
5295
|
+
callback(result, error);
|
|
5296
|
+
this.#callbacks.delete(id);
|
|
5297
|
+
});
|
|
5275
5298
|
}
|
|
5276
|
-
call(func, callback, close = true) {
|
|
5277
|
-
|
|
5278
|
-
|
|
5299
|
+
call(func, callback, args = [], close = true) {
|
|
5300
|
+
if (typeof func !== "function") throw new TypeError("func must be a function");
|
|
5301
|
+
const id = ++this.#idCounter;
|
|
5302
|
+
this.#callbacks.set(id, callback);
|
|
5303
|
+
|
|
5304
|
+
this.#worker.postMessage({
|
|
5305
|
+
id,
|
|
5306
|
+
funStr: func.toString(),
|
|
5307
|
+
args,
|
|
5279
5308
|
close
|
|
5280
5309
|
});
|
|
5281
|
-
|
|
5282
|
-
if (e.data.error) {
|
|
5283
|
-
console.error(e.data.error);
|
|
5284
|
-
} else {
|
|
5285
|
-
callback(e.data.result);
|
|
5286
|
-
}
|
|
5287
|
-
};
|
|
5310
|
+
|
|
5288
5311
|
return this;
|
|
5289
5312
|
}
|
|
5290
|
-
}
|
|
5291
5313
|
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
if (func) {
|
|
5295
|
-
T.call(func, callback , close);
|
|
5314
|
+
terminate() {
|
|
5315
|
+
this.#worker.terminate();
|
|
5296
5316
|
}
|
|
5297
|
-
|
|
5298
|
-
};
|
|
5317
|
+
}
|
|
5299
5318
|
|
|
5300
|
-
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
|
|
5309
|
-
use(PropsMap){
|
|
5310
|
-
if(this.ValidateCssProps) ValidateCssProps(PropsMap);
|
|
5311
|
-
this.currentPropsMap = PropsMap;
|
|
5312
|
-
this.#maintain();
|
|
5313
|
-
return this;
|
|
5319
|
+
/*
|
|
5320
|
+
[
|
|
5321
|
+
{
|
|
5322
|
+
query: '(min-width: 600px)',
|
|
5323
|
+
callback: () => console.log(1)
|
|
5324
|
+
},
|
|
5325
|
+
{
|
|
5326
|
+
query: '(max-width: 300px)',
|
|
5327
|
+
callback: () => console.log(2)
|
|
5314
5328
|
}
|
|
5315
|
-
|
|
5316
|
-
|
|
5317
|
-
|
|
5318
|
-
|
|
5319
|
-
|
|
5320
|
-
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
|
|
5324
|
-
|
|
5325
|
-
|
|
5326
|
-
|
|
5327
|
-
|
|
5328
|
-
writable: true,
|
|
5329
|
-
configurable: true,
|
|
5330
|
-
enumerable: false
|
|
5331
|
-
});
|
|
5332
|
-
}
|
|
5329
|
+
]
|
|
5330
|
+
*/
|
|
5331
|
+
|
|
5332
|
+
class UseMediaQuery {
|
|
5333
|
+
#mediaQueryRules;
|
|
5334
|
+
#fallback;
|
|
5335
|
+
#lastCalledCallback = null;
|
|
5336
|
+
|
|
5337
|
+
constructor(mediaQueryRules = [], fallback = () => {}) {
|
|
5338
|
+
this.#mediaQueryRules = mediaQueryRules;
|
|
5339
|
+
this.#fallback = fallback;
|
|
5340
|
+
|
|
5341
|
+
this.#init();
|
|
5333
5342
|
}
|
|
5334
|
-
}
|
|
5335
5343
|
|
|
5336
|
-
|
|
5337
|
-
|
|
5338
|
-
|
|
5339
|
-
|
|
5340
|
-
|
|
5341
|
-
}
|
|
5344
|
+
// PRIVATE: check if ANY rule matches
|
|
5345
|
+
#checkAllRules() {
|
|
5346
|
+
return this.#mediaQueryRules.some(
|
|
5347
|
+
({ query }) => globalThis.matchMedia(query).matches
|
|
5348
|
+
);
|
|
5342
5349
|
}
|
|
5343
|
-
}
|
|
5344
5350
|
|
|
5345
|
-
|
|
5351
|
+
// PRIVATE: installs listeners and initial checks
|
|
5352
|
+
#init() {
|
|
5353
|
+
this.#mediaQueryRules.forEach(({ query, callback }) => {
|
|
5354
|
+
const mediaQueryList = globalThis.matchMedia(query);
|
|
5346
5355
|
|
|
5347
|
-
|
|
5356
|
+
const checkMatches = () => {
|
|
5357
|
+
const anyMatch = this.#checkAllRules();
|
|
5348
5358
|
|
|
5349
|
-
|
|
5350
|
-
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
|
|
5358
|
-
|
|
5359
|
-
|
|
5360
|
-
|
|
5359
|
+
if (mediaQueryList.matches) {
|
|
5360
|
+
callback();
|
|
5361
|
+
this.#lastCalledCallback = callback;
|
|
5362
|
+
} else if (!anyMatch && this.#lastCalledCallback !== this.#fallback) {
|
|
5363
|
+
this.#fallback();
|
|
5364
|
+
this.#lastCalledCallback = this.#fallback;
|
|
5365
|
+
}
|
|
5366
|
+
};
|
|
5367
|
+
|
|
5368
|
+
checkMatches();
|
|
5369
|
+
mediaQueryList.addEventListener("change", checkMatches);
|
|
5370
|
+
});
|
|
5371
|
+
}
|
|
5361
5372
|
}
|
|
5362
|
-
const {use, border, background, color} = useRoot(Style.S1)
|
|
5363
5373
|
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
|
|
5374
|
+
const useMediaQuery = (mediaQueryRules, fallback) =>
|
|
5375
|
+
new UseMediaQuery(mediaQueryRules, fallback);
|
|
5376
|
+
|
|
5377
|
+
class UseTitle {
|
|
5378
|
+
constructor(title = document.title, withEmitter = true) {
|
|
5379
|
+
this.cache = {
|
|
5380
|
+
emitter: null
|
|
5381
|
+
};
|
|
5382
|
+
|
|
5383
|
+
if (withEmitter) this.useEventEmitter();
|
|
5384
|
+
this.set(title);
|
|
5385
|
+
}
|
|
5370
5386
|
|
|
5371
|
-
|
|
5387
|
+
useEventEmitter() {
|
|
5388
|
+
this.cache.emitter = useEventEmitter();
|
|
5389
|
+
return this;
|
|
5390
|
+
}
|
|
5391
|
+
|
|
5392
|
+
setTitle(title) {
|
|
5393
|
+
if (title !== document.title) {
|
|
5394
|
+
document.title = title;
|
|
5395
|
+
|
|
5396
|
+
if (this.cache.emitter) {
|
|
5397
|
+
this.cache.emitter.emit("ziko:title-changed", title);
|
|
5398
|
+
}
|
|
5399
|
+
}
|
|
5400
|
+
return this;
|
|
5401
|
+
}
|
|
5402
|
+
|
|
5403
|
+
get current() {
|
|
5404
|
+
return document.title;
|
|
5405
|
+
}
|
|
5406
|
+
|
|
5407
|
+
onChange(callback) {
|
|
5408
|
+
if (this.cache.emitter) {
|
|
5409
|
+
this.cache.emitter.on("ziko:title-changed", callback);
|
|
5410
|
+
}
|
|
5411
|
+
return this;
|
|
5412
|
+
}
|
|
5413
|
+
}
|
|
5414
|
+
|
|
5415
|
+
const useTitle = (title, withEmitter = true) => new UseTitle(title, withEmitter);
|
|
5372
5416
|
|
|
5373
5417
|
let {sqrt, cos, sin, exp, log, cosh, sinh} = Math;
|
|
5374
5418
|
// Math.abs = new Proxy(Math.abs, {
|
|
@@ -5463,7 +5507,7 @@
|
|
|
5463
5507
|
exports.UISVGWrapper = UISVGWrapper;
|
|
5464
5508
|
exports.UISwitch = UISwitch;
|
|
5465
5509
|
exports.UIView = UIView;
|
|
5466
|
-
exports.
|
|
5510
|
+
exports.UseThread = UseThread;
|
|
5467
5511
|
exports.Utils = Utils;
|
|
5468
5512
|
exports.View = View;
|
|
5469
5513
|
exports.ZikoApp = ZikoApp;
|
|
@@ -5639,11 +5683,11 @@
|
|
|
5639
5683
|
exports.useDerived = useDerived;
|
|
5640
5684
|
exports.useEventEmitter = useEventEmitter;
|
|
5641
5685
|
exports.useLocaleStorage = useLocaleStorage;
|
|
5686
|
+
exports.useMediaQuery = useMediaQuery;
|
|
5642
5687
|
exports.useReactive = useReactive;
|
|
5643
|
-
exports.useRoot = useRoot;
|
|
5644
5688
|
exports.useSessionStorage = useSessionStorage;
|
|
5645
5689
|
exports.useState = useState;
|
|
5646
|
-
exports.
|
|
5690
|
+
exports.useTitle = useTitle;
|
|
5647
5691
|
exports.wait = wait;
|
|
5648
5692
|
exports.waitForUIElm = waitForUIElm;
|
|
5649
5693
|
exports.waitForUIElmSync = waitForUIElmSync;
|