ziko 0.49.6 → 0.50.1

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.
Files changed (104) hide show
  1. package/dist/ziko.cjs +374 -363
  2. package/dist/ziko.js +686 -971
  3. package/dist/ziko.min.js +2 -2
  4. package/dist/ziko.mjs +678 -953
  5. package/package.json +4 -1
  6. package/src/{reactivity → --reactivity-deprecated}/hooks/head/useFavIcon.js +4 -4
  7. package/src/{reactivity → --reactivity-deprecated}/hooks/head/useTitle.js +1 -1
  8. package/src/{reactivity → --reactivity-deprecated}/hooks/index.js +3 -3
  9. package/src/{reactivity → --reactivity-deprecated}/index.js +1 -1
  10. package/src/{use → --use-deprecated}/index.js +1 -1
  11. package/src/{use/use-event-emmiter.js → --use-deprecated/use-event-emmiter.js.txt} +3 -3
  12. package/src/__ziko__/__state__.js +1 -1
  13. package/src/app/ziko-app.js +6 -6
  14. package/src/events/binders/custom-event.js +11 -7
  15. package/src/events/binders/index.js +69 -13
  16. package/src/events/details-setter/index.js +2 -0
  17. package/src/events/details-setter/key.js +14 -0
  18. package/src/events/{binders → details-setter}/pointer.js +1 -15
  19. package/src/events/{__Events__.js → events-map/index.js} +7 -3
  20. package/src/events/index.js +1 -1
  21. package/src/events/types/__Shared__.d.ts +3 -3
  22. package/src/events/types/clipboard.d.ts +2 -2
  23. package/src/events/types/focus.d.ts +2 -2
  24. package/src/events/types/pointer.d.ts +2 -2
  25. package/src/events/{__ZikoEvent__.js → ziko-event.js} +17 -16
  26. package/src/hooks/index.js +10 -2
  27. package/src/hooks/use-event-emitter.js +68 -0
  28. package/src/hooks/use-favicon.js +59 -0
  29. package/src/hooks/{use-channel.js → use-ipc.js} +5 -22
  30. package/src/hooks/use-media-query.js +59 -0
  31. package/src/hooks/use-root.js +73 -0
  32. package/src/hooks/use-storage.js +73 -47
  33. package/src/hooks/use-thread.js +55 -0
  34. package/src/hooks/use-title.js +43 -0
  35. package/src/index.js +1 -1
  36. package/src/ui/__methods__/events.js +19 -5
  37. package/src/ui/constructors/UIElement.js +14 -12
  38. package/src/ui/constructors/UIElementCore.js +3 -136
  39. package/types/hooks/index.d.ts +9 -2
  40. package/types/hooks/use-Thread.d.ts +33 -0
  41. package/types/hooks/use-event-emitter.d.ts +46 -0
  42. package/types/hooks/use-favicon.d.ts +41 -0
  43. package/types/hooks/{use-channel.d.ts → use-ipc.d.ts} +2 -2
  44. package/types/hooks/use-media-query.d.ts +24 -0
  45. package/types/hooks/use-root.d.ts +15 -0
  46. package/types/hooks/use-storage.d.ts +47 -0
  47. package/types/hooks/use-title.d.ts +37 -0
  48. package/src/events/binders/click.js +0 -20
  49. package/src/events/binders/clipboard.js +0 -16
  50. package/src/events/binders/drag.js +0 -16
  51. package/src/events/binders/focus.js +0 -16
  52. package/src/events/binders/hash.js +0 -16
  53. package/src/events/binders/key.js +0 -27
  54. package/src/events/binders/mouse.js +0 -16
  55. package/src/events/binders/touch.js +0 -16
  56. package/src/events/binders/wheel.js +0 -16
  57. package/src/events/index.d.ts.txt +0 -3
  58. /package/src/{reactivity → --reactivity-deprecated}/events/Input.js +0 -0
  59. /package/src/{reactivity → --reactivity-deprecated}/events/ZikoEvent.js +0 -0
  60. /package/src/{reactivity → --reactivity-deprecated}/events/__note__ +0 -0
  61. /package/src/{reactivity → --reactivity-deprecated}/events/custom-event.js +0 -0
  62. /package/src/{reactivity → --reactivity-deprecated}/events/hash.js +0 -0
  63. /package/src/{reactivity → --reactivity-deprecated}/events/index.js +0 -0
  64. /package/src/{reactivity → --reactivity-deprecated}/events/media.js +0 -0
  65. /package/src/{reactivity → --reactivity-deprecated}/events/mouse.js +0 -0
  66. /package/src/{reactivity → --reactivity-deprecated}/events/swipe.js +0 -0
  67. /package/src/{reactivity → --reactivity-deprecated}/events/touch.js +0 -0
  68. /package/src/{reactivity → --reactivity-deprecated}/hooks/Contexte/index.js +0 -0
  69. /package/src/{reactivity → --reactivity-deprecated}/hooks/Contexte/useSuccesifKeys.js +0 -0
  70. /package/src/{reactivity → --reactivity-deprecated}/hooks/UI/index.js +0 -0
  71. /package/src/{reactivity → --reactivity-deprecated}/hooks/UI/useCssLink.js +0 -0
  72. /package/src/{reactivity → --reactivity-deprecated}/hooks/UI/useLinearGradient.js +0 -0
  73. /package/src/{reactivity → --reactivity-deprecated}/hooks/UI/useMediaQuery.js +0 -0
  74. /package/src/{reactivity → --reactivity-deprecated}/hooks/UI/useRadialGradient.js +0 -0
  75. /package/src/{reactivity → --reactivity-deprecated}/hooks/UI/useRoot.js +0 -0
  76. /package/src/{reactivity → --reactivity-deprecated}/hooks/UI/useStyle.js +0 -0
  77. /package/src/{reactivity → --reactivity-deprecated}/hooks/UI/useTheme.js +0 -0
  78. /package/src/{reactivity → --reactivity-deprecated}/hooks/head/_useCssText.js +0 -0
  79. /package/src/{reactivity → --reactivity-deprecated}/hooks/head/index.js +0 -0
  80. /package/src/{reactivity → --reactivity-deprecated}/hooks/head/useHead.js +0 -0
  81. /package/src/{reactivity → --reactivity-deprecated}/hooks/head/useMeta.js +0 -0
  82. /package/src/{reactivity → --reactivity-deprecated}/hooks/todo.md +0 -0
  83. /package/src/{reactivity → --reactivity-deprecated}/idea +0 -0
  84. /package/src/{reactivity → --reactivity-deprecated}/observer/attributes.js +0 -0
  85. /package/src/{reactivity → --reactivity-deprecated}/observer/children.js +0 -0
  86. /package/src/{reactivity → --reactivity-deprecated}/observer/index.js +0 -0
  87. /package/src/{reactivity → --reactivity-deprecated}/observer/intersection.js +0 -0
  88. /package/src/{reactivity → --reactivity-deprecated}/observer/mutation.js +0 -0
  89. /package/src/{reactivity → --reactivity-deprecated}/observer/resize.js +0 -0
  90. /package/src/{reactivity → --reactivity-deprecated}/observer/screen.js +0 -0
  91. /package/src/{reactivity → --reactivity-deprecated}/observer/screen.js.txt +0 -0
  92. /package/src/{reactivity → --reactivity-deprecated}/observer/screen.txt +0 -0
  93. /package/src/{use → --use-deprecated}/use-channel.js.txt +0 -0
  94. /package/src/{use → --use-deprecated}/use-favicon.js +0 -0
  95. /package/src/{use → --use-deprecated}/use-link.js +0 -0
  96. /package/src/{use → --use-deprecated}/use-meta.js +0 -0
  97. /package/src/{use → --use-deprecated}/use-root.js +0 -0
  98. /package/src/{use → --use-deprecated}/use-storage.js.txt +0 -0
  99. /package/src/{use → --use-deprecated}/use-thread.js +0 -0
  100. /package/src/{use → --use-deprecated}/use-title.js +0 -0
  101. /package/src/events/{custom-events → custom-events-registry}/click-away.js +0 -0
  102. /package/src/events/{custom-events → custom-events-registry}/index.js +0 -0
  103. /package/src/events/{custom-events → custom-events-registry}/swipe.js +0 -0
  104. /package/src/events/{custom-events → custom-events-registry}/view.js +0 -0
package/dist/ziko.js CHANGED
@@ -2,7 +2,7 @@
2
2
  /*
3
3
  Project: ziko.js
4
4
  Author: Zakaria Elalaoui
5
- Date : Wed Nov 26 2025 12:01:55 GMT+0100 (UTC+01:00)
5
+ Date : Tue Dec 02 2025 16:28:22 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
@@ -1078,35 +1078,6 @@
1078
1078
 
1079
1079
  // globalThis.node = (node) => new UINode(node);
1080
1080
 
1081
- function parseQueryParams$1(queryString) {
1082
- const params = {};
1083
- queryString.replace(/[A-Z0-9]+?=([\w|:|\/\.]*)/gi, (match) => {
1084
- const [key, value] = match.split('=');
1085
- params[key] = value;
1086
- });
1087
- return params;
1088
- }
1089
-
1090
- function defineParamsGetter$1(target ){
1091
- Object.defineProperties(target, {
1092
- 'QueryParams': {
1093
- get: function() {
1094
- return parseQueryParams$1(globalThis.location.search.substring(1));
1095
- },
1096
- configurable: false,
1097
- enumerable: true
1098
- },
1099
- 'HashParams': {
1100
- get: function() {
1101
- const hash = globalThis.location.hash.substring(1);
1102
- return hash.split("#");
1103
- },
1104
- configurable: false,
1105
- enumerable: true
1106
- }
1107
- });
1108
- }
1109
-
1110
1081
  class UIStore extends Array {
1111
1082
  constructor(...args) {
1112
1083
  super(...args);
@@ -1140,6 +1111,141 @@
1140
1111
  // create the singleton
1141
1112
  const __UI__ = new UIStore();
1142
1113
 
1114
+ // __init__global__()
1115
+ class UIElementCore extends UINode{
1116
+ constructor(){
1117
+ super();
1118
+ }
1119
+ init(element, name, type, render){
1120
+ this.target = globalThis.__Ziko__.__Config__.default.target||globalThis?.document?.body;
1121
+ if(typeof element === "string") {
1122
+ switch(type){
1123
+ case "html" : {
1124
+ element = globalThis?.document?.createElement(element);
1125
+ // console.log('1')
1126
+ } break;
1127
+ case "svg" : {
1128
+ element = globalThis?.document?.createElementNS("http://www.w3.org/2000/svg", element);
1129
+ // console.log('2')
1130
+ } break;
1131
+ default : throw Error("Not supported")
1132
+ }
1133
+ }
1134
+ else this.target = element?.parentElement;
1135
+ Object.assign(this.cache, {
1136
+ name,
1137
+ isInteractive : false,
1138
+ parent:null,
1139
+ isBody:false,
1140
+ isRoot:false,
1141
+ isHidden: false,
1142
+ isFrozzen:false,
1143
+ legacyParent : null,
1144
+ attributes: {},
1145
+ filters: {},
1146
+ temp:{}
1147
+ });
1148
+ this.events = {
1149
+ ptr:null,
1150
+ mouse:null,
1151
+ wheel:null,
1152
+ key:null,
1153
+ drag:null,
1154
+ drop:null,
1155
+ click:null,
1156
+ clipboard:null,
1157
+ focus:null,
1158
+ swipe:null,
1159
+ custom:null,
1160
+ };
1161
+ this.observer={
1162
+ resize:null,
1163
+ intersection:null
1164
+ };
1165
+ if(element) Object.assign(this.cache,{element});
1166
+ // useDefaultStyle && this.style({
1167
+ // position: "relative",
1168
+ // boxSizing:"border-box",
1169
+ // margin:0,
1170
+ // padding:0,
1171
+ // width : "auto",
1172
+ // height : "auto"
1173
+ // });
1174
+ this.items = new UIStore();
1175
+ globalThis.__Ziko__.__UI__[this.cache.name]?globalThis.__Ziko__.__UI__[this.cache.name]?.push(this):globalThis.__Ziko__.__UI__[this.cache.name]=[this];
1176
+ element && render && this?.render?.();
1177
+ globalThis.__Ziko__.__UI__.push(this);
1178
+ }
1179
+ get element(){
1180
+ return this.cache.element;
1181
+ }
1182
+ [Symbol.iterator]() {
1183
+ return this.items[Symbol.iterator]();
1184
+ }
1185
+ maintain() {
1186
+ for (let i = 0; i < this.items.length; i++) {
1187
+ Object.defineProperty(this, i, {
1188
+ value: this.items[i],
1189
+ writable: true,
1190
+ configurable: true,
1191
+ enumerable: false
1192
+ });
1193
+ }
1194
+ }
1195
+ isInteractive(){
1196
+ return this.cache.isInteractive;
1197
+ }
1198
+ isUIElement(){
1199
+ return true;
1200
+ }
1201
+ }
1202
+
1203
+ function register_to_class(target, ...mixins){
1204
+ mixins.forEach(n => _register_to_class_(target, n));
1205
+ }
1206
+ function _register_to_class_(target, mixin) {
1207
+ const descriptors = Object.getOwnPropertyDescriptors(mixin);
1208
+ for (const key of Reflect.ownKeys(descriptors)) {
1209
+ const desc = descriptors[key];
1210
+ if ('get' in desc || 'set' in desc || typeof desc.value !== 'function') {
1211
+ Object.defineProperty(Object.getPrototypeOf(target), key, desc);
1212
+ } else if (typeof desc.value === 'function') {
1213
+ if (!Object.getPrototypeOf(target).hasOwnProperty(key)) {
1214
+ Object.defineProperty(Object.getPrototypeOf(target), key, desc);
1215
+ }
1216
+ }
1217
+ }
1218
+ }
1219
+
1220
+ function parseQueryParams$1(queryString) {
1221
+ const params = {};
1222
+ queryString.replace(/[A-Z0-9]+?=([\w|:|\/\.]*)/gi, (match) => {
1223
+ const [key, value] = match.split('=');
1224
+ params[key] = value;
1225
+ });
1226
+ return params;
1227
+ }
1228
+
1229
+ function defineParamsGetter$1(target ){
1230
+ Object.defineProperties(target, {
1231
+ 'QueryParams': {
1232
+ get: function() {
1233
+ return parseQueryParams$1(globalThis.location.search.substring(1));
1234
+ },
1235
+ configurable: false,
1236
+ enumerable: true
1237
+ },
1238
+ 'HashParams': {
1239
+ get: function() {
1240
+ const hash = globalThis.location.hash.substring(1);
1241
+ return hash.split("#");
1242
+ },
1243
+ configurable: false,
1244
+ enumerable: true
1245
+ }
1246
+ });
1247
+ }
1248
+
1143
1249
  const __Config__ = {
1144
1250
  default:{
1145
1251
  target:null,
@@ -1183,37 +1289,29 @@
1183
1289
  }
1184
1290
  };
1185
1291
 
1186
- class UseChannel {
1187
- // private fields
1292
+ class UseIPC {
1188
1293
  #channel;
1189
1294
  #eventData;
1190
1295
  #handlers;
1191
1296
  #uuid;
1192
1297
  #subscribers;
1193
- #currentRooms; // now a Set for multiple rooms
1194
-
1298
+ #currentRooms;
1195
1299
  constructor(name = "") {
1196
1300
  this.#channel = new BroadcastChannel(name);
1197
1301
  this.#eventData = new Map();
1198
1302
  this.#handlers = new Map(); // Map<event, Array<{fn, rooms}>>
1199
1303
  this.#uuid = "ziko-channel:" + Random.string(10);
1200
1304
  this.#subscribers = new Set([this.#uuid]);
1201
- this.#currentRooms = new Set(); // multiple rooms
1202
-
1305
+ this.#currentRooms = new Set();
1203
1306
  this.#channel.addEventListener("message", (e) => {
1204
1307
  const { last_sent_event, userId, eventData, rooms } = e.data;
1205
-
1206
1308
  if (userId === this.#uuid) return; // ignore own messages
1207
-
1208
1309
  // broadcast if no rooms, else check intersection
1209
1310
  if (rooms && rooms.length && !rooms.some(r => this.#currentRooms.has(r))) return;
1210
-
1211
1311
  this.#subscribers.add(userId);
1212
1312
  this.#eventData = new Map(eventData);
1213
-
1214
1313
  const handlersList = this.#handlers.get(last_sent_event);
1215
1314
  if (!handlersList) return;
1216
-
1217
1315
  handlersList.forEach(({ fn, rooms: handlerRooms }) => {
1218
1316
  // trigger if listener has no room filter, or intersects subscriber rooms
1219
1317
  if (!handlerRooms || handlerRooms.length === 0 ||
@@ -1227,24 +1325,20 @@
1227
1325
  emit(event, data, rooms) {
1228
1326
  this.#eventData.set(event, data);
1229
1327
  if(typeof rooms === 'string') rooms = [rooms];
1230
-
1231
1328
  this.#channel.postMessage({
1232
1329
  eventData: Array.from(this.#eventData.entries()),
1233
1330
  last_sent_event: event,
1234
1331
  userId: this.#uuid,
1235
1332
  rooms: rooms && rooms.length ? rooms : undefined
1236
1333
  });
1237
-
1238
1334
  return this;
1239
1335
  }
1240
-
1241
1336
  on(event, handler = console.log, rooms) {
1242
1337
  if (!this.#handlers.has(event)) this.#handlers.set(event, []);
1243
1338
  if(typeof rooms === 'string') rooms = [rooms];
1244
1339
  this.#handlers.get(event).push({ fn: handler, rooms });
1245
1340
  return this;
1246
1341
  }
1247
-
1248
1342
  off(event, handler) {
1249
1343
  if (!this.#handlers.has(event)) return this;
1250
1344
  this.#handlers.set(
@@ -1253,7 +1347,6 @@
1253
1347
  );
1254
1348
  return this;
1255
1349
  }
1256
-
1257
1350
  once(event, handler, rooms) {
1258
1351
  const wrapper = (data) => {
1259
1352
  handler(data);
@@ -1262,368 +1355,148 @@
1262
1355
  this.on(event, wrapper, rooms);
1263
1356
  return this;
1264
1357
  }
1265
-
1266
1358
  join(...rooms) {
1267
1359
  rooms.forEach(r => this.#currentRooms.add(r));
1268
1360
  return this;
1269
1361
  }
1270
-
1271
1362
  leave(...rooms) {
1272
1363
  if (!rooms.length) this.#currentRooms.clear();
1273
1364
  else rooms.forEach(r => this.#currentRooms.delete(r));
1274
1365
  return this;
1275
1366
  }
1276
-
1277
1367
  close() {
1278
1368
  this.#channel.close();
1279
1369
  return this;
1280
1370
  }
1281
-
1282
1371
  }
1283
1372
 
1284
- const useChannel = (name) => new UseChannel(name);
1373
+ const useIPC = (name) => new UseIPC(name);
1285
1374
 
1286
- // To do : remove old items
1287
- class UseStorage{
1288
- constructor(storage, globalKey, initialValue){
1289
- this.cache={
1375
+ class UseStorage {
1376
+ constructor(storage, globalKey, initialValue, use_channel = true) {
1377
+ this.cache = {
1290
1378
  storage,
1291
1379
  globalKey,
1292
- channel:useChannel(`Ziko:useStorage-${globalKey}`),
1293
- oldItemKeys:new Set()
1380
+ channel: use_channel ? useIPC(`Ziko:useStorage-${globalKey}`) : null,
1381
+ oldItemKeys: new Set()
1294
1382
  };
1295
- this.#init(initialValue);
1296
- this.#maintain();
1383
+
1384
+ this.#init(initialValue, use_channel);
1297
1385
  }
1298
- get items(){
1299
- return JSON.parse(this.cache.storage[this.cache.globalKey]??null);
1386
+
1387
+ get items() {
1388
+ const raw = this.cache.storage.getItem(this.cache.globalKey);
1389
+ if (!raw) return {};
1390
+ try {
1391
+ return JSON.parse(raw);
1392
+ } catch {
1393
+ return {};
1394
+ }
1300
1395
  }
1396
+
1301
1397
  #maintain() {
1302
- for(let i in this.items)Object.assign(this, { [[i]]: this.items[i] });
1303
- }
1304
- #init(initialValue){
1305
- this.cache.channel=useChannel(`Ziko:useStorage-${this.cache.globalKey}`);
1306
- this.cache.channel.on("Ziko-Storage-Updated",()=>this.#maintain());
1307
- if(!initialValue)return;
1308
- if(this.cache.storage[this.cache.globalKey]){
1309
- Object.keys(this.items).forEach(key=>this.cache.oldItemKeys.add(key));
1310
- // console.group("Ziko:useStorage")
1311
- // console.warn(`Storage key '${this.cache.globalKey}' already exists. we will not overwrite it.`);
1312
- // console.info(`%cWe'll keep the existing data.`,"background-color:#2222dd; color:gold;");
1313
- // console.group("")
1398
+ const items = this.items;
1399
+ this.cache.oldItemKeys.forEach(k => delete this[k]);
1400
+ for (const key in items) {
1401
+ this[key] = items[key];
1402
+ this.cache.oldItemKeys.add(key);
1314
1403
  }
1315
- else this.set(initialValue);
1316
1404
  }
1317
- set(data){
1318
- this.cache.storage.setItem(this.cache.globalKey,JSON.stringify(data));
1319
- this.cache.channel.emit("Ziko-Storage-Updated",{});
1320
- Object.keys(data).forEach(key=>this.cache.oldItemKeys.add(key));
1321
- this.#maintain();
1322
- return this
1323
- }
1324
- add(data){
1325
- const db={
1326
- ...this.items,
1327
- ...data
1328
- };
1329
- this.cache.storage.setItem(this.cache.globalKey,JSON.stringify(db));
1330
- this.#maintain();
1331
- return this;
1332
- }
1333
- remove(...keys){
1334
- const db={...this.items};
1335
- for(let i=0;i<keys.length;i++){
1336
- delete db[keys[i]];
1337
- delete this[keys[i]];
1405
+ #init(initialValue, use_channel) {
1406
+ if (use_channel && this.cache.channel) this.cache.channel.on("Ziko-Storage-Updated", () => this.#maintain());
1407
+ if (!initialValue) {
1408
+ this.#maintain();
1409
+ return;
1338
1410
  }
1339
- this.set(db);
1340
- return this;
1341
- }
1342
- get(key){
1343
- return this.items[key];
1411
+ if (this.cache.storage.getItem(this.cache.globalKey)) {
1412
+ const existing = this.items;
1413
+ Object.keys(existing).forEach(k => this.cache.oldItemKeys.add(k));
1414
+ this.#maintain();
1415
+ }
1416
+ else this.set(initialValue);
1344
1417
  }
1345
- clear(){
1346
- this.cache.storage.removeItem(this.cache.globalKey);
1418
+
1419
+ set(data) {
1420
+ this.cache.storage.setItem(this.cache.globalKey, JSON.stringify(data));
1421
+ if (this.cache.channel) this.cache.channel.emit("Ziko-Storage-Updated", data);
1347
1422
  this.#maintain();
1348
1423
  return this;
1349
1424
  }
1350
1425
 
1426
+ add(data) {
1427
+ this.set({
1428
+ ...this.items,
1429
+ ...data
1430
+ });
1431
+ return this;
1432
+ }
1433
+ remove(...keys) {
1434
+ const items = { ...this.items };
1435
+ keys.forEach(key => {
1436
+ delete items[key];
1437
+ delete this[key];
1438
+ this.cache.oldItemKeys.delete(key);
1439
+ });
1440
+ this.set(items);
1441
+ return this;
1442
+ }
1443
+ get(key) {
1444
+ return this.items[key];
1445
+ }
1446
+ clear() {
1447
+ this.cache.storage.removeItem(this.cache.globalKey);
1448
+ this.cache.oldItemKeys.forEach(k => delete this[k]);
1449
+ this.cache.oldItemKeys.clear();
1450
+ this.#maintain();
1451
+ return this;
1452
+ }
1453
+ onStorageUpdated(callback) {
1454
+ if (this.cache.channel) {
1455
+ this.cache.channel.on("Ziko-Storage-Updated", callback);
1456
+ }
1457
+ return this;
1458
+ }
1351
1459
  }
1352
- const useLocaleStorage=(key,initialValue)=>new UseStorage(localStorage,key,initialValue);
1353
- const useSessionStorage=(key,initialValue)=>new UseStorage(sessionStorage,key,initialValue);
1354
-
1355
- const __State__ = {
1356
- store : new Map(),
1357
- index : 0,
1358
- session_storage : null,
1359
- register: function(state){
1360
- if(!undefined.SSR && undefined.DEV){
1361
- if(!this.session) this.session_storage = useSessionStorage('ziko-state', {});
1362
- const savedValue = this.session_storage.get(this.index);
1363
- if(!savedValue) this.session_storage.add({[this.index] : state.value});
1364
- else state.value = savedValue;
1365
- }
1366
- this.store.set(this.index++, state);
1367
- },
1368
- update: function(index, value){
1369
- if(!undefined.SSR && undefined.DEV){
1370
- this.session_storage.add({[index] : value});
1371
- }
1372
- },
1373
-
1374
- };
1375
-
1376
- function __init__global__(){
1377
- if ( !globalThis?.__Ziko__ ){
1378
- globalThis.__Ziko__ = {
1379
- __UI__,
1380
- __HYDRATION__,
1381
- __State__,
1382
- __Config__,
1383
- __CACHE__,
1384
- };
1385
- defineParamsGetter$1(__Ziko__);
1386
- }
1387
- }
1388
-
1389
- __init__global__();
1390
- class UIElementCore extends UINode{
1391
- constructor(){
1392
- super();
1393
- }
1394
- init(element, name, type, render){
1395
- this.target = globalThis.__Ziko__.__Config__.default.target||globalThis?.document?.body;
1396
- if(typeof element === "string") {
1397
- switch(type){
1398
- case "html" : {
1399
- element = globalThis?.document?.createElement(element);
1400
- // console.log('1')
1401
- } break;
1402
- case "svg" : {
1403
- element = globalThis?.document?.createElementNS("http://www.w3.org/2000/svg", element);
1404
- // console.log('2')
1405
- } break;
1406
- default : throw Error("Not supported")
1407
- }
1408
- }
1409
- else this.target = element?.parentElement;
1410
- Object.assign(this.cache, {
1411
- name,
1412
- isInteractive : false,
1413
- parent:null,
1414
- isBody:false,
1415
- isRoot:false,
1416
- isHidden: false,
1417
- isFrozzen:false,
1418
- legacyParent : null,
1419
- attributes: {},
1420
- filters: {},
1421
- temp:{}
1422
- });
1423
- this.events = {
1424
- ptr:null,
1425
- mouse:null,
1426
- wheel:null,
1427
- key:null,
1428
- drag:null,
1429
- drop:null,
1430
- click:null,
1431
- clipboard:null,
1432
- focus:null,
1433
- swipe:null,
1434
- custom:null,
1435
- };
1436
- this.observer={
1437
- resize:null,
1438
- intersection:null
1439
- };
1440
- if(element) Object.assign(this.cache,{element});
1441
- // useDefaultStyle && this.style({
1442
- // position: "relative",
1443
- // boxSizing:"border-box",
1444
- // margin:0,
1445
- // padding:0,
1446
- // width : "auto",
1447
- // height : "auto"
1448
- // });
1449
- this.items = new UIStore();
1450
- globalThis.__Ziko__.__UI__[this.cache.name]?globalThis.__Ziko__.__UI__[this.cache.name]?.push(this):globalThis.__Ziko__.__UI__[this.cache.name]=[this];
1451
- element && render && this?.render?.();
1452
- globalThis.__Ziko__.__UI__.push(this);
1453
- }
1454
- get element(){
1455
- return this.cache.element;
1456
- }
1457
- [Symbol.iterator]() {
1458
- return this.items[Symbol.iterator]();
1459
- }
1460
- maintain() {
1461
- for (let i = 0; i < this.items.length; i++) {
1462
- Object.defineProperty(this, i, {
1463
- value: this.items[i],
1464
- writable: true,
1465
- configurable: true,
1466
- enumerable: false
1467
- });
1468
- }
1469
- }
1470
- isInteractive(){
1471
- return this.cache.isInteractive;
1472
- }
1473
- isUIElement(){
1474
- return true;
1475
- }
1476
- // get st(){
1477
- // return this.cache.style;
1478
- // }
1479
- // get attr(){
1480
- // return this.cache.attributes;
1481
- // }
1482
- // get evt(){
1483
- // return this.events;
1484
- // }
1485
- // get html(){
1486
- // return this.element.innerHTML;
1487
- // }
1488
- // get text(){
1489
- // return this.element.textContent;
1490
- // }
1491
- // get isBody(){
1492
- // return this.element === globalThis?.document.body;
1493
- // }
1494
- // get parent(){
1495
- // return this.cache.parent;
1496
- // }
1497
- // get width(){
1498
- // return this.element.getBoundingClientRect().width;
1499
- // }
1500
- // get height(){
1501
- // return this.element.getBoundingClientRect().height;
1502
- // }
1503
- // get top(){
1504
- // return this.element.getBoundingClientRect().top;
1505
- // }
1506
- // get right(){
1507
- // return this.element.getBoundingClientRect().right;
1508
- // }
1509
- // get bottom(){
1510
- // return this.element.getBoundingClientRect().bottom;
1511
- // }
1512
- // get left(){
1513
- // return this.element.getBoundingClientRect().left;
1514
- // }
1515
- // clone(render=false) {
1516
- // // UI.__proto__=this.__proto__;
1517
- // // if(this.items.length){
1518
- // // const items = [...this.items].map(n=>n.clone());
1519
- // // UI.append(...items);
1520
- // // }
1521
- // // else UI.element=this.element.cloneNode(true);
1522
- // // return UI.mount(render);
1523
- // }
1524
-
1525
- // freeze(freeze){
1526
- // this.cache.isFrozzen=freeze;
1527
- // return this;
1528
- // }
1529
- // setTarget(tg) {
1530
- // if(this.isBody) return ;
1531
- // if (tg?.isUIElement) tg = tg.element;
1532
- // this.unmount();
1533
- // this.target = tg;
1534
- // this.mount();
1535
- // return this;
1536
- // }
1537
- // describe(label){
1538
- // if(label)this.setAttr("aria-label",label)
1539
- // }
1540
- // get children() {
1541
- // return [...this.element.children];
1542
- // }
1543
- // get cloneElement() {
1544
- // return this.element.cloneNode(true);
1545
- // }
1546
- // setClasses(...value) {
1547
- // this.setAttr("class", value.join(" "));
1548
- // return this;
1549
- // }
1550
- // get classes(){
1551
- // const classes=this.element.getAttribute("class");
1552
- // return classes===null?[]:classes.split(" ");
1553
- // }
1554
- // addClass() {
1555
- // /*this.setAttr("class", value);
1556
- // return this;*/
1557
- // }
1558
- // setId(id) {
1559
- // this.setAttr("id", id);
1560
- // return this;
1561
- // }
1562
- // get id() {
1563
- // return this.element.getAttribute("id");
1564
- // }
1565
- // onSwipe(width_threshold, height_threshold,...callbacks){
1566
- // if(!this.events.swipe)this.events.swipe = useSwipeEvent(this, width_threshold, height_threshold);
1567
- // this.events.swipe.onSwipe(...callbacks);
1568
- // return this;
1569
- // }
1570
- // To Fix
1571
- // onKeysDown({keys=[],callback}={}){
1572
- // if(!this.events.key)this.events.key = useKeyEvent(this);
1573
- // this.events.key.handleSuccessifKeys({keys,callback});
1574
- // return this;
1575
- // }
1576
- // onSelect(...callbacks){
1577
- // if(!this.events.clipboard)this.events.clipboard = useClipboardEvent(this);
1578
- // this.events.clipboard.onSelect(...callbacks);
1579
- // return this;
1580
- // }
1581
- // on(event_name,...callbacks){
1582
- // if(!this.events.custom)this.events.custom = useCustomEvent(this);
1583
- // this.events.custom.on(event_name,...callbacks);
1584
- // return this;
1585
- // }
1586
- // emit(event_name,detail={}){
1587
- // if(!this.events.custom)this.events.custom = useCustomEvent(this);
1588
- // this.events.custom.emit(event_name,detail);
1589
- // return this;
1590
- // }
1591
- // watchAttr(callback){
1592
- // if(!this.observer.attr)this.observer.attr = watchAttr(this,callback);
1593
- // return this;
1594
- // }
1595
- // watchChildren(callback){
1596
- // if(!this.observer.children)this.observer.children = watchChildren(this,callback);
1597
- // return this;
1598
- // }
1599
- // watchSize(callback){
1600
- // if(!this.observer.resize)this.observer.resize = watchSize(this,callback);
1601
- // this.observer.resize.start();
1602
- // return this;
1603
- // }
1604
- // watchIntersection(callback,config){
1605
- // if(!this.observer.intersection)this.observer.intersection = watchIntersection(this,callback,config);
1606
- // this.observer.intersection.start();
1607
- // return this;
1608
- // }
1609
-
1610
- }
1611
-
1612
- function register_to_class(target, ...mixins){
1613
- mixins.forEach(n => _register_to_class_(target, n));
1614
- }
1615
- function _register_to_class_(target, mixin) {
1616
- const descriptors = Object.getOwnPropertyDescriptors(mixin);
1617
- for (const key of Reflect.ownKeys(descriptors)) {
1618
- const desc = descriptors[key];
1619
- if ('get' in desc || 'set' in desc || typeof desc.value !== 'function') {
1620
- Object.defineProperty(Object.getPrototypeOf(target), key, desc);
1621
- } else if (typeof desc.value === 'function') {
1622
- if (!Object.getPrototypeOf(target).hasOwnProperty(key)) {
1623
- Object.defineProperty(Object.getPrototypeOf(target), key, desc);
1624
- }
1460
+
1461
+ // factory functions
1462
+ const useLocaleStorage = (key, initialValue, use_channel = true) =>
1463
+ new UseStorage(localStorage, key, initialValue, use_channel);
1464
+
1465
+ const useSessionStorage = (key, initialValue, use_channel = true) =>
1466
+ new UseStorage(sessionStorage, key, initialValue, use_channel);
1467
+
1468
+ var __State__ = {
1469
+ store : new Map(),
1470
+ index : 0,
1471
+ session_storage : null,
1472
+ register: function(state){
1473
+ if(!undefined.SSR && undefined.DEV){
1474
+ if(!this.session) this.session_storage = useSessionStorage('ziko-state', {});
1475
+ const savedValue = this.session_storage.get(this.index);
1476
+ if(!savedValue) this.session_storage.add({[this.index] : state.value});
1477
+ else state.value = savedValue;
1478
+ }
1479
+ this.store.set(this.index++, state);
1480
+ },
1481
+ update: function(index, value){
1482
+ if(!undefined.SSR && undefined.DEV){
1483
+ this.session_storage.add({[index] : value});
1484
+ }
1485
+ },
1486
+
1487
+ };
1488
+
1489
+ function __init__global__(){
1490
+ if ( !globalThis?.__Ziko__ ){
1491
+ globalThis.__Ziko__ = {
1492
+ __UI__,
1493
+ __HYDRATION__,
1494
+ __State__,
1495
+ __Config__,
1496
+ __CACHE__,
1497
+ };
1498
+ defineParamsGetter$1(__Ziko__);
1625
1499
  }
1626
- }
1627
1500
  }
1628
1501
 
1629
1502
  if(!globalThis.__Ziko__) __init__global__();
@@ -1886,7 +1759,11 @@
1886
1759
  unrenderAfter: unrenderAfter
1887
1760
  });
1888
1761
 
1889
- const Events = {
1762
+ const EventsMap = {
1763
+ 'Custom' : [
1764
+ 'emit',
1765
+ 'on'
1766
+ ],
1890
1767
  'Click' : [
1891
1768
  'Click',
1892
1769
  'DblClick',
@@ -1946,21 +1823,7 @@
1946
1823
  return event.toLowerCase()
1947
1824
  };
1948
1825
 
1949
- function event_controller(e, event_name, details_setter, customizer, push_object){
1950
- this.cache.currentEvent = event_name;
1951
- this.cache.event = e;
1952
- details_setter?.call(this);
1953
- customizer?.hasOwnProperty("prototype") ? customizer?.call(this) : customizer?.call(null, this);
1954
- // if(customizer?.hasOwnProperty("prototype")) customizer?.call(this)
1955
- // else customizer?.call(null, this)
1956
- if(this.cache.preventDefault[event_name]) e.preventDefault();
1957
- if(this.cache.stopPropagation[event_name]) e.stopPropagation();
1958
- if(this.cache.stopImmediatePropagation[event_name]) e.stopImmediatePropagation();
1959
-
1960
- if(this.cache.stream.enabled[event_name]&&push_object)this.cache.stream.history[event_name].push(push_object);
1961
- this.cache.callbacks[event_name]?.map(n=>n(this));
1962
- }
1963
- class __ZikoEvent__ {
1826
+ class ZikoEvent {
1964
1827
  constructor(target = null, Events = [], details_setter, customizer){
1965
1828
  this.target = target;
1966
1829
  this.cache = {
@@ -2104,92 +1967,24 @@
2104
1967
 
2105
1968
  return this;
2106
1969
  }
2107
- }
2108
-
2109
- // import { register_click_away_event } from "./custom-events/click-away.js";
2110
- class ZikoEventClick extends __ZikoEvent__{
2111
- constructor(target, customizer){
2112
- super(target, Events.Click, details_setter$a, customizer);
2113
- // register_click_away_event(target.element)
2114
- }
2115
- }
2116
- function details_setter$a(){
2117
- if(this.currentEvent==="click") this.dx = 0;
2118
- else this.dx = 1;
2119
- // console.log(this.currentEvent)
2120
- }
2121
- const bind_click_event = (target, customizer) => new ZikoEventClick(target, customizer);
2122
-
2123
- class ZikoEventClipboard extends __ZikoEvent__{
2124
- constructor(target, customizer){
2125
- super(target, Events.Clipboard, details_setter$9, customizer);
2126
- }
2127
- }
2128
- function details_setter$9(){
2129
-
2130
- }
2131
- const bind_clipboard_event = (target, customizer) => new ZikoEventClipboard(target, customizer);
2132
-
2133
- class ZikoEventCustom extends __ZikoEvent__{
2134
- constructor(target, events, customizer){
2135
- super(target, events, details_setter$8, customizer);
2136
- }
2137
- _register_events(events){
2138
- super._register_events(events, null, null, false);
2139
- return this;
2140
- }
2141
- emit(event_name, details = {}){
2142
- const event=new Event(event_name);
2143
- this.targetElement.dispatchEvent(event);
2144
- return this;
2145
- }
2146
- on(event_name, ...callbacks){
2147
- if(!this.cache.options.hasOwnProperty(event_name)) this._register_events([event_name]);
2148
- this.__onEvent(event_name, this.cache.options[event_name], {}, ...callbacks);
2149
- return this;
2150
- }
2151
- }
2152
- function details_setter$8(){
2153
-
2154
- }
2155
- const bindCustomEvent = (target, events, customizer) => new ZikoEventCustom(target, events, customizer);
2156
-
2157
- class ZikoEventDrag extends __ZikoEvent__{
2158
- constructor(target, customizer){
2159
- super(target, Events.Drag, details_setter$7, customizer);
2160
- }
2161
- }
2162
- function details_setter$7(){
2163
-
2164
- }
2165
- const bind_drag_event = (target, customizer) => new ZikoEventDrag(target, customizer);
2166
-
2167
- class ZikoEventFocus extends __ZikoEvent__{
2168
- constructor(target, customizer){
2169
- super(target, Events.Focus, details_setter$6, customizer);
2170
- }
2171
- }
2172
- function details_setter$6(){
2173
-
2174
- }
2175
- const bind_focus_event = (target, customizer) => new ZikoEventFocus(target, customizer);
2176
-
2177
- class ZikoEventHash extends __ZikoEvent__{
2178
- constructor(target, customizer){
2179
- super(target, Events.Hash, details_setter$5, customizer);
2180
- }
2181
1970
  }
2182
- function details_setter$5(){
2183
1971
 
2184
- }
2185
- const bindHashEvent = (target, customizer) => new ZikoEventHash(target, customizer);
1972
+ function event_controller(e, event_name, details_setter, customizer, push_object){
1973
+ this.cache.currentEvent = event_name;
1974
+ this.cache.event = e;
1975
+ details_setter?.call(this);
1976
+ customizer?.hasOwnProperty("prototype") ? customizer?.call(this) : customizer?.call(null, this);
1977
+ // if(customizer?.hasOwnProperty("prototype")) customizer?.call(this)
1978
+ // else customizer?.call(null, this)
1979
+ if(this.cache.preventDefault[event_name]) e.preventDefault();
1980
+ if(this.cache.stopPropagation[event_name]) e.stopPropagation();
1981
+ if(this.cache.stopImmediatePropagation[event_name]) e.stopImmediatePropagation();
1982
+
1983
+ if(this.cache.stream.enabled[event_name]&&push_object)this.cache.stream.history[event_name].push(push_object);
1984
+ this.cache.callbacks[event_name]?.map(n=>n(this));
1985
+ }
2186
1986
 
2187
- class ZikoEventKey extends __ZikoEvent__{
2188
- constructor(target, customizer){
2189
- super(target, Events.Key, details_setter$4, customizer);
2190
- }
2191
- }
2192
- function details_setter$4(){
1987
+ function key_details_setter(){
2193
1988
  switch(this.currentEvent){
2194
1989
  case "keydown" : {
2195
1990
  this.kd = this.event.key;
@@ -2202,26 +1997,9 @@
2202
1997
  } break;
2203
1998
 
2204
1999
  }
2205
- }
2206
- const bind_key_event = (target, customizer) => new ZikoEventKey(target, customizer);
2207
-
2208
- class ZikoEventMouse extends __ZikoEvent__{
2209
- constructor(target, customizer){
2210
- super(target, Events.Mouse, details_setter$3, customizer);
2211
- }
2212
- }
2213
- function details_setter$3(){
2214
-
2215
- }
2216
- const bind_mouse_event = (target, customizer) => new ZikoEventMouse(target, customizer);
2000
+ }
2217
2001
 
2218
- class ZikoEventPointer extends __ZikoEvent__{
2219
- constructor(target, customizer){
2220
- super(target, Events.Ptr, details_setter$2, customizer);
2221
- this.isDown = false;
2222
- }
2223
- }
2224
- function details_setter$2(){
2002
+ function ptr_details_setter(){
2225
2003
  switch(this.currentEvent){
2226
2004
  case "pointerdown" : {
2227
2005
  this.dx = parseInt(this.event.offsetX);
@@ -2253,28 +2031,135 @@
2253
2031
  // if(this.currentEvent==="click") this.dx = 0
2254
2032
  // else this.dx = 1
2255
2033
  // console.log(this.currentEvent)
2256
- }
2257
- const bind_pointer_event = (target, customizer) => new ZikoEventPointer(target, customizer);
2034
+ }
2258
2035
 
2259
- class ZikoEventTouch extends __ZikoEvent__{
2260
- constructor(target, customizer){
2261
- super(target, Events.Touch, details_setter$1, customizer);
2262
- }
2036
+ class ClickAwayEvent extends Event {
2037
+ constructor(originalEvent, targetElement) {
2038
+ super("clickaway", { bubbles: true, cancelable: true });
2039
+ this.originalEvent = originalEvent;
2040
+ this.targetElement = targetElement;
2041
+ }
2263
2042
  }
2264
- function details_setter$1(){
2265
2043
 
2044
+ function register_click_away_event(element) {
2045
+ console.log(element);
2046
+ function handler(e) {
2047
+ if (!element.contains(e.target)) {
2048
+ const clickAwayEvent = new ClickAwayEvent(e, element);
2049
+ element.dispatchEvent(clickAwayEvent);
2050
+ }
2051
+ }
2052
+
2053
+ globalThis?.document?.addEventListener("click", handler);
2054
+
2055
+ return () => globalThis?.document?.removeEventListener("click", handler);
2056
+
2266
2057
  }
2267
- const bindTouchEvent = (target, customizer) => new ZikoEventTouch(target, customizer);
2058
+
2059
+ // // Example usage
2060
+ // const box = document.querySelector("#my-box");
2061
+
2062
+ // const stop = listenClickAway(box);
2063
+
2064
+ // box.addEventListener("clickaway", (e) => {
2065
+ // console.log("Clicked outside box!", e);
2066
+ // });
2067
+
2068
+ // // later, you can stop listening:
2069
+ // // stop();
2070
+
2071
+ const bind_click_event = (target, customizer) => {
2072
+ register_click_away_event(target.element);
2073
+ return new ZikoEvent(
2074
+ target,
2075
+ EventsMap.Click,
2076
+ null,
2077
+ customizer
2078
+ );
2079
+ };
2080
+ const bind_clipboard_event = (target, customizer) => new ZikoEvent(
2081
+ target,
2082
+ EventsMap.Clipboard,
2083
+ null,
2084
+ customizer
2085
+ );
2086
+ const bind_drag_event = (target, customizer) => new ZikoEvent(
2087
+ target,
2088
+ EventsMap.Drag,
2089
+ null,
2090
+ customizer
2091
+ );
2092
+ const bind_focus_event = (target, customizer) => new ZikoEvent(
2093
+ target,
2094
+ EventsMap.Focus,
2095
+ null,
2096
+ customizer
2097
+ );
2098
+ const bind_key_event = (target, customizer) => new ZikoEvent(
2099
+ target,
2100
+ EventsMap.Key,
2101
+ key_details_setter,
2102
+ customizer
2103
+ );
2104
+ const bind_mouse_event = (target, customizer) => new ZikoEvent(
2105
+ target,
2106
+ EventsMap.Mouse,
2107
+ null,
2108
+ customizer
2109
+ );
2110
+ const bind_pointer_event = (target, customizer) => new ZikoEvent(
2111
+ target,
2112
+ EventsMap.Ptr,
2113
+ ptr_details_setter,
2114
+ customizer
2115
+ );
2116
+ const bind_touch_event = (target, customizer) => new ZikoEvent(
2117
+ target,
2118
+ EventsMap.Touch,
2119
+ null,
2120
+ customizer
2121
+ );
2122
+ const bind_wheel_event = (target, customizer) => new ZikoEvent(
2123
+ target,
2124
+ EventsMap.Wheel,
2125
+ null,
2126
+ customizer
2127
+ );
2128
+
2129
+
2130
+ // function details_setter(){
2131
+ // if(this.currentEvent==="click") this.dx = 0
2132
+ // else this.dx = 1
2133
+ // // console.log(this.currentEvent)
2134
+ // }
2268
2135
 
2269
- class ZikoEventWheel extends __ZikoEvent__{
2270
- constructor(target, customizer){
2271
- super(target, Events.Wheel, details_setter, customizer);
2136
+ class ZikoCustomEvent extends ZikoEvent{
2137
+ constructor(target, events, customizer){
2138
+ super(target, events, details_setter, customizer);
2139
+ }
2140
+ _register_events(events){
2141
+ super._register_events(events, null, null, false);
2142
+ return this;
2143
+ }
2144
+ emit(event_name, detail = {}){
2145
+ const event = new CustomEvent(event_name, {
2146
+ detail,
2147
+ bubbles: true,
2148
+ cancelable: true
2149
+ });
2150
+ this.targetElement.dispatchEvent(event);
2151
+ return this;
2152
+ }
2153
+ on(event_name, ...callbacks){
2154
+ if(!this.cache.options.hasOwnProperty(event_name)) this._register_events([event_name]);
2155
+ this.__onEvent(event_name, this.cache.options[event_name], {}, ...callbacks);
2156
+ return this;
2272
2157
  }
2273
2158
  }
2274
2159
  function details_setter(){
2275
2160
 
2276
2161
  }
2277
- const bind_wheel_event = (target, customizer) => new ZikoEventWheel(target, customizer);
2162
+ const bind_custom_event = (target, events, customizer) => new ZikoCustomEvent(target, events, customizer);
2278
2163
 
2279
2164
  const binderMap = {
2280
2165
  ptr: bind_pointer_event,
@@ -2287,14 +2172,26 @@
2287
2172
  wheel : bind_wheel_event
2288
2173
  };
2289
2174
 
2290
- const EventsMethodes = {};
2175
+ const EventsMethodes = {
2176
+ on(event_name,...callbacks){
2177
+ if(!this.events.custom)this.events.custom = bind_custom_event(this);
2178
+ this.events.custom.on(event_name,...callbacks);
2179
+ return this;
2180
+ },
2181
+ emit(event_name,detail={}){
2182
+ if(!this.events.custom)this.events.custom = bind_custom_event(this);
2183
+ this.events.custom.emit(event_name,detail);
2184
+ return this;
2185
+ }
2186
+ };
2291
2187
 
2292
- Object.entries(Events).forEach(([name, eventList]) => {
2188
+ Object.entries(EventsMap).forEach(([name, eventList]) => {
2189
+ const lname = name.toLowerCase();
2293
2190
  eventList.forEach(event => {
2294
2191
  const methodName = `on${event}`;
2295
2192
  EventsMethodes[methodName] = function (...callbacks) {
2296
- if (!this.events[name]) this.events[name] = binderMap[name.toLowerCase()](this);
2297
- this.events[name][methodName](...callbacks);
2193
+ if (!this.events[lname]) this.events[lname] = binderMap[lname](this);
2194
+ this.events[lname][methodName](...callbacks);
2298
2195
  return this;
2299
2196
  };
2300
2197
  });
@@ -2331,182 +2228,38 @@
2331
2228
  Object.assign(this.element.style, {[key] : getter.value});
2332
2229
  getter._subscribe(
2333
2230
  (newValue) => {
2334
- console.log({newValue});
2335
- Object.assign(this.element.style, {[key] : newValue});
2336
- },
2337
- // this
2338
- );
2339
- }
2340
- else Object.assign(this.element.style, {[key] : value});
2341
- }
2342
- return this;
2343
- }
2344
- function size(width, height){
2345
- return this.style({width, height})
2346
- }
2347
- function hide(){
2348
-
2349
- }
2350
- function show(){
2351
-
2352
- }
2353
- function animate(keyframe, {duration=1000, iterations=1, easing="ease"}={}){
2354
- this.element?.animate(keyframe,{duration, iterations, easing});
2355
- return this;
2356
- }
2357
-
2358
- var StyleMethods = /*#__PURE__*/Object.freeze({
2359
- __proto__: null,
2360
- animate: animate,
2361
- hide: hide,
2362
- show: show,
2363
- size: size,
2364
- style: style
2365
- });
2366
-
2367
- function EVENT_CONTROLLER(e,EVENT,setter,push_object){
2368
- this.event=e;
2369
- if(this.cache.preventDefault[EVENT])e.preventDefault();
2370
- console.log({setter});
2371
- if(setter)setter();
2372
- if(this.cache.stream.enabled[EVENT]&&push_object)this.cache.stream.history[EVENT].push(push_object);
2373
- this.cache.callbacks[EVENT].map(n=>n(this));
2374
- return this;
2375
- }
2376
- class ZikoEvent{
2377
- constructor(target){
2378
- this.target=null;
2379
- this.setTarget(target);
2380
- this.__dispose=this.dispose.bind(this);
2381
- // this.EventIndex=Garbage.Pointer.data.length;
2382
- // Garbage.Pointer.data.push({event:this,index:this.EventIndex});
2383
- }
2384
- get targetElement(){
2385
- return this.target.element
2386
- }
2387
- setTarget(UI){
2388
- this.target=UI;
2389
- return this;
2390
- }
2391
- __handle(event,handler,dispose){
2392
- const EVENT=(event==="drag")?event:`${this.cache.prefixe}${event}`;
2393
- this.dispose(dispose);
2394
- this.targetElement?.addEventListener(EVENT,handler);
2395
- return this;
2396
- }
2397
- __onEvent(event,dispose,...callbacks){
2398
- if(callbacks.length===0){
2399
- if(this.cache.callbacks.length>1){
2400
- this.cache.callbacks.map(n=>e=>n.call(this,e));
2401
- }
2402
- else {
2403
- return this;
2404
- }
2405
- }
2406
- else this.cache.callbacks[event]=callbacks.map(n=>e=>n.call(this,e));
2407
- this.__handle(event,this.__controller[event],dispose);
2408
- return this;
2409
- }
2410
- preventDefault(config={}){
2411
- Object.assign(this.cache.preventDefault,config);
2412
- return this;
2413
- }
2414
- pause(config={}){
2415
- const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,true]));
2416
- config={...all,...config};
2417
- for(let key in config){
2418
- if(config[key]){
2419
- this.targetElement?.removeEventListener(`${this.cache.prefixe}${key}`,this.__controller[`${this.cache.prefixe}${key}`]);
2420
- this.cache.paused[`${this.cache.prefixe}${key}`]=true;
2421
- }
2422
- }
2423
- return this;
2424
- }
2425
- resume(config={}){
2426
- const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,true]));
2427
- config={...all,...config};
2428
- for(let key in config){
2429
- if(config[key]){
2430
- this.targetElement?.addEventListener(`${this.cache.prefixe}${key}`,this.__controller[`${this.cache.prefixe}${key}`]);
2431
- this.cache.paused[`${this.cache.prefixe}${key}`]=false;
2432
- }
2433
- }
2434
- return this;
2435
- }
2436
- dispose(config={}){
2437
- this.pause(config);
2438
- return this;
2439
- }
2440
- stream(config={}){
2441
- this.cache.stream.t0=Date.now();
2442
- const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,true]));
2443
- config={...all,...config};
2444
- Object.assign(this.cache.stream.enabled,config);
2445
- return this;
2446
- }
2447
- clear(config={}){
2448
- const all=Object.fromEntries(Object.keys(this.cache.stream.clear).map(n=>[n,true]));
2449
- config={...all,...config};
2450
- for(let key in config){
2451
- if(config[key]){
2452
- this.cache.stream.history[key]=[];
2453
- }
2231
+ console.log({newValue});
2232
+ Object.assign(this.element.style, {[key] : newValue});
2233
+ },
2234
+ // this
2235
+ );
2454
2236
  }
2455
- return this;
2237
+ else Object.assign(this.element.style, {[key] : value});
2456
2238
  }
2239
+ return this;
2240
+ }
2241
+ function size(width, height){
2242
+ return this.style({width, height})
2243
+ }
2244
+ function hide(){
2245
+
2246
+ }
2247
+ function show(){
2248
+
2249
+ }
2250
+ function animate(keyframe, {duration=1000, iterations=1, easing="ease"}={}){
2251
+ this.element?.animate(keyframe,{duration, iterations, easing});
2252
+ return this;
2457
2253
  }
2458
2254
 
2459
- const custom_event_controller=event_name=>function(e){
2460
- EVENT_CONTROLLER.call(this,e,event_name,null,null);
2461
- };
2462
- class ZikoCustomEvent extends ZikoEvent{
2463
- constructor(target){
2464
- super(target);
2465
- this.event=null;
2466
- this.cache={
2467
- prefixe:"",
2468
- preventDefault:{
2469
- },
2470
- paused:{
2471
- },
2472
- stream:{
2473
- enabled:{
2474
- },
2475
- clear:{
2476
- },
2477
- history:{
2478
- }
2479
- },
2480
- callbacks:{
2481
- }
2482
- };
2483
- this.__controller={
2484
- };
2485
- }
2486
- #init(event_name){
2487
- this.cache.preventDefault[event_name]=false;
2488
- this.cache.paused[event_name]=false;
2489
- this.cache.stream.enabled=false;
2490
- this.cache.stream.clear=false;
2491
- this.cache.stream.history=[];
2492
- this.cache.callbacks[event_name]=[];
2493
- this.__controller[event_name]=custom_event_controller(event_name).bind(this);
2494
- return this;
2495
- }
2496
- on(event_name,...callbacks){
2497
- if(!(this.__controller[event_name]))this.#init(event_name);
2498
- this.__onEvent(event_name,{},...callbacks);
2499
- return this;
2500
- }
2501
- emit(event_name,detail={}){
2502
- if(!(this.__controller[event_name]))this.#init(event_name);
2503
- this.detail=detail;
2504
- const event=new Event(event_name);
2505
- this.targetElement.dispatchEvent(event);
2506
- return this;
2507
- }
2508
- }
2509
- const useCustomEvent=target=>new ZikoCustomEvent(target);
2255
+ var StyleMethods = /*#__PURE__*/Object.freeze({
2256
+ __proto__: null,
2257
+ animate: animate,
2258
+ hide: hide,
2259
+ show: show,
2260
+ size: size,
2261
+ style: style
2262
+ });
2510
2263
 
2511
2264
  let UIElement$1 = class UIElement extends UIElementCore{
2512
2265
  constructor({element, name ='', type='html', render = __Ziko__.__Config__.default.render}={}){
@@ -2521,6 +2274,8 @@
2521
2274
  IndexingMethods,
2522
2275
  EventsMethodes
2523
2276
  );
2277
+
2278
+ // console.log(EventsMethodes)
2524
2279
  if(element)this.init(element, name, type, render);
2525
2280
  }
2526
2281
  get element(){
@@ -2658,16 +2413,16 @@
2658
2413
  // this.events.clipboard.onSelect(...callbacks);
2659
2414
  // return this;
2660
2415
  // }
2661
- on(event_name,...callbacks){
2662
- if(!this.events.custom)this.events.custom = useCustomEvent(this);
2663
- this.events.custom.on(event_name,...callbacks);
2664
- return this;
2665
- }
2666
- emit(event_name,detail={}){
2667
- if(!this.events.custom)this.events.custom = useCustomEvent(this);
2668
- this.events.custom.emit(event_name,detail);
2669
- return this;
2670
- }
2416
+ // on(event_name,...callbacks){
2417
+ // if(!this.events.custom)this.events.custom = useCustomEvent(this);
2418
+ // this.events.custom.on(event_name,...callbacks);
2419
+ // return this;
2420
+ // }
2421
+ // emit(event_name,detail={}){
2422
+ // if(!this.events.custom)this.events.custom = useCustomEvent(this);
2423
+ // this.events.custom.emit(event_name,detail);
2424
+ // return this;
2425
+ // }
2671
2426
  // watchAttr(callback){
2672
2427
  // if(!this.observer.attr)this.observer.attr = watchAttr(this,callback);
2673
2428
  // return this;
@@ -4801,209 +4556,7 @@
4801
4556
  return r;
4802
4557
  };
4803
4558
 
4804
- class UseEventEmitter {
4805
- constructor() {
4806
- this.events = {};
4807
- this.maxListeners = 10;
4808
- }
4809
- on(event, listener) {
4810
- if (!this.events[event]) {
4811
- this.events[event] = [];
4812
- }
4813
- this.events[event].push(listener);
4814
- if (this.events[event].length > this.maxListeners) {
4815
- console.warn(`Warning: Possible memory leak. Event '${event}' has more than ${this.maxListeners} listeners.`);
4816
- }
4817
- }
4818
- once(event, listener) {
4819
- const onceListener = (data) => {
4820
- this.off(event, onceListener); // Remove the listener after it's been called
4821
- listener(data);
4822
- };
4823
- this.on(event, onceListener);
4824
- }
4825
-
4826
- off(event, listener) {
4827
- const listeners = this.events[event];
4828
- if (listeners) {
4829
- const index = listeners.indexOf(listener);
4830
- if (index !== -1) {
4831
- listeners.splice(index, 1);
4832
- }
4833
- }
4834
- }
4835
-
4836
- emit(event, data) {
4837
- const listeners = this.events[event];
4838
- if (listeners) {
4839
- listeners.forEach(listener => {
4840
- listener(data);
4841
- });
4842
- }
4843
- }
4844
-
4845
- clear(event) {
4846
- if (event) {
4847
- delete this.events[event];
4848
- } else {
4849
- this.events = {};
4850
- }
4851
- }
4852
-
4853
- setMaxListener(event, max) {
4854
- this.maxListeners = max;
4855
- }
4856
-
4857
- removeAllListeners(event) {
4858
- if (event) {
4859
- this.events[event] = [];
4860
- } else {
4861
- this.events = {};
4862
- }
4863
- }
4864
- }
4865
-
4866
- const useEventEmitter=()=>new UseEventEmitter();
4867
-
4868
- class ZikoUseFavIcon{
4869
- constructor(FavIcon,useEventEmitter=true){
4870
- this.#init();
4871
- this.cache={
4872
- Emitter:null
4873
- };
4874
- if(useEventEmitter)this.useEventEmitter();
4875
- this.set(FavIcon);
4876
- }
4877
- #init(){
4878
- this.__FavIcon__ = document.querySelector("link[rel*='icon']") || document?.createElement('link');
4879
- this.__FavIcon__.type = 'image/x-icon';
4880
- this.__FavIcon__.rel = 'shortcut icon';
4881
- return this;
4882
- }
4883
- set(href){
4884
- if(href!==this.__FavIcon__.href){
4885
- this.__FavIcon__.href=href;
4886
- if(this.cache.Emitter)this.cache.Emitter.emit("ziko:favicon-changed");
4887
- }
4888
- return this;
4889
- }
4890
- get current(){
4891
- return document.__FavIcon__.href;
4892
- }
4893
- onChange(callback){
4894
- if(this.cache.Emitter)this.cache.Emitter.on("ziko:favicon-changed",callback);
4895
- return this;
4896
- }
4897
- useEventEmitter(){
4898
- this.cache.Emitter=useEventEmitter();
4899
- return this;
4900
- }
4901
-
4902
- }
4903
- const useFavIcon=(FavIcon,useEventEmitter)=>new ZikoUseFavIcon(FavIcon,useEventEmitter);
4904
-
4905
- class ZikoMeta{
4906
- constructor({viewport,charset,description,author,keywords}){
4907
- this.document = globalThis?.document;
4908
- this.meta={};
4909
- this.init({viewport,charset,description,author,keywords});
4910
- }
4911
- init({viewport,charset,description,author,keywords}){
4912
- viewport && this.setViewport(viewport);
4913
- charset && this.setCharset(charset);
4914
- description && this.describe(description);
4915
- author && this.setAuthor(author);
4916
- keywords && this.setKeywords(keywords);
4917
- }
4918
- set(key,value){
4919
- key = key.toLowerCase();
4920
- const isCharset = (key === "charset");
4921
- const meta = isCharset ? document.querySelector("meta[charset]"):document.querySelector(`meta[name=${key}]`);
4922
- this.meta=meta?? document?.createElement("meta");
4923
- if(isCharset) this.meta.setAttribute("charset",value);
4924
- else {
4925
- this.meta.setAttribute("name",key);
4926
- this.meta.setAttribute("content",value);
4927
- }
4928
- if(!meta)this.document.head.append(this.meta);
4929
- return this;
4930
- }
4931
- setCharset(charset="utf-8"){
4932
- this.set("charset",charset);
4933
- return this;
4934
- }
4935
- describe(description){
4936
- this.set("description",description);
4937
- return this;
4938
- }
4939
- setViewport(viewport="width=device-width, initial-scale=1.0"){
4940
- this.set("viewport",viewport);
4941
- return this;
4942
- }
4943
- setKeywords(...keywords){
4944
- // keywords.push("zikojs");
4945
- keywords=[...new Set(keywords)].join(", ");
4946
- this.set("keywords",keywords);
4947
- return this;
4948
- }
4949
- setAuthor(author){
4950
- this.set("author",author);
4951
- return this;
4952
- }
4953
- }
4954
- const useMeta=({viewport,charset,description,author,keywords})=>new ZikoMeta({viewport,charset,description,author,keywords});
4955
-
4956
- class ZikoUseTitle{
4957
- constructor(title=document.title,useEventEmitter=true){
4958
- this.cache={
4959
- Emitter:null
4960
- };
4961
- if(useEventEmitter)this.useEventEmitter();
4962
- this.set(title);
4963
- }
4964
- useEventEmitter(){
4965
- this.cache.Emitter=useEventEmitter();
4966
- return this;
4967
- }
4968
- set(title){
4969
- if(title!==document.title){
4970
- document.title=title;
4971
- if(this.cache.Emitter)this.cache.Emitter.emit("ziko:title-changed");
4972
- }
4973
- return this;
4974
- }
4975
- get current(){
4976
- return document.title;
4977
- }
4978
- onChange(callback){
4979
- if(this.cache.Emitter)this.cache.Emitter.on("ziko:title-changed",callback);
4980
- return this;
4981
- }
4982
- }
4983
- const useTitle=(title, useEventEmitter)=>new ZikoUseTitle(title, useEventEmitter);
4984
-
4985
- // import {useLink} from "./";
4986
- class ZikoHead{
4987
- constructor({title,lang,icon,meta,noscript}){
4988
- this.html = globalThis?.document?.documentElement;
4989
- this.head = globalThis?.document?.head;
4990
-
4991
- title && useTitle(title);
4992
- lang && this.setLang(lang);
4993
- icon && useFavIcon(icon);
4994
- meta && useMeta(meta);
4995
- noscript && this.setNoScript();
4996
- }
4997
- setLang(lang){
4998
- this.html.setAttribute("lang",lang);
4999
- }
5000
- setNoScript(content){
5001
-
5002
- }
5003
- }
5004
-
5005
- const useHead=({ title, lang, icon, meta, noscript })=>new ZikoHead({ title, lang, icon, meta, noscript });
5006
-
4559
+ // import { ZikoHead , useHead} from "../reactivity/hooks/head/index.js";
5007
4560
  class ZikoApp {
5008
4561
  constructor({head = null, wrapper = null, target = null}){
5009
4562
  this.head = head;
@@ -5030,11 +4583,11 @@
5030
4583
  else if(typeof wrapper === "function") this.wrapper = wrapper();
5031
4584
  return this;
5032
4585
  }
5033
- setHead(head){
5034
- if(head instanceof ZikoHead) this.head = head;
5035
- else this.head = useHead(head);
5036
- return this;
5037
- }
4586
+ // setHead(head){
4587
+ // if(head instanceof ZikoHead) this.head = head;
4588
+ // else this.head = useHead(head);
4589
+ // return this;
4590
+ // }
5038
4591
 
5039
4592
  }
5040
4593
  const App = ({head, wrapper, target}) => new ZikoApp({head, wrapper, target});
@@ -5225,7 +4778,7 @@
5225
4778
  const subscribers = new Set();
5226
4779
 
5227
4780
  sources.forEach(source => {
5228
- const srcValue = source(); // getValue()
4781
+ const srcValue = source();
5229
4782
  srcValue._subscribe(() => {
5230
4783
  {
5231
4784
  const newVal = deriveFn(...sources.map(s => s().value));
@@ -5254,95 +4807,267 @@
5254
4807
  nested_value
5255
4808
  );
5256
4809
 
5257
- class UseThreed {
5258
- #workerContent;
4810
+ class UseThread {
4811
+ #worker;
4812
+ #callbacks = new Map();
4813
+ #idCounter = 0;
4814
+
5259
4815
  constructor() {
5260
- this.#workerContent = (
5261
- function (msg) {
5262
- try {
5263
- const func = new Function("return " + msg.data.fun)();
5264
- let result = func();
5265
- postMessage({ result });
5266
- } catch (error) {
5267
- postMessage({ error: error.message });
5268
- } finally {
5269
- if (msg.data.close) self.close();
5270
- }
4816
+ const workerCode = `
4817
+ this.onmessage = function(e) {
4818
+ const { id, funStr, args, close } = e.data;
4819
+ try {
4820
+ const func = new Function("return " + funStr)();
4821
+ const result = func(...args);
4822
+ postMessage({ id, result });
4823
+ } catch (error) {
4824
+ postMessage({ id, error: error.message });
4825
+ } finally {
4826
+ if (close) self.close();
5271
4827
  }
5272
- ).toString();
5273
- this.blob = new Blob(["this.onmessage = " + this.#workerContent], { type: "text/javascript" });
5274
- this.worker = new Worker(window.URL.createObjectURL(this.blob));
4828
+ }
4829
+ `;
4830
+ const blob = new Blob([workerCode], { type: "text/javascript" });
4831
+ this.#worker = new Worker(URL.createObjectURL(blob));
4832
+
4833
+ this.#worker.addEventListener("message", (e) => {
4834
+ const { id, result, error } = e.data;
4835
+ const callback = this.#callbacks.get(id);
4836
+ if (!callback) return;
4837
+
4838
+ callback(result, error);
4839
+ this.#callbacks.delete(id);
4840
+ });
5275
4841
  }
5276
- call(func, callback, close = true) {
5277
- this.worker.postMessage({
5278
- fun: func.toString(),
4842
+ call(func, callback, args = [], close = true) {
4843
+ if (typeof func !== "function") throw new TypeError("func must be a function");
4844
+ const id = ++this.#idCounter;
4845
+ this.#callbacks.set(id, callback);
4846
+
4847
+ this.#worker.postMessage({
4848
+ id,
4849
+ funStr: func.toString(),
4850
+ args,
5279
4851
  close
5280
4852
  });
5281
- this.worker.onmessage = function (e) {
5282
- if (e.data.error) {
5283
- console.error(e.data.error);
5284
- } else {
5285
- callback(e.data.result);
5286
- }
4853
+
4854
+ return this;
4855
+ }
4856
+
4857
+ terminate() {
4858
+ this.#worker.terminate();
4859
+ }
4860
+ }
4861
+
4862
+ const useThread = (func, callback, args = [], close = true) => new UseThread().call(func, callback, args, close);
4863
+
4864
+ class UseEventEmitter {
4865
+ constructor(maxListeners = 10) {
4866
+ this.events = {};
4867
+ this.maxListeners = maxListeners;
4868
+ }
4869
+
4870
+ on(event, listener) {
4871
+ if (!this.events[event]) this.events[event] = [];
4872
+ this.events[event].push(listener);
4873
+ if (this.events[event].length > this.maxListeners) {
4874
+ console.warn(`Warning: Possible memory leak. Event '${event}' has more than ${this.maxListeners} listeners.`);
4875
+ }
4876
+ return this;
4877
+ }
4878
+
4879
+ once(event, listener) {
4880
+ const wrapper = (...args) => {
4881
+ this.off(event, wrapper);
4882
+ listener(...args);
5287
4883
  };
4884
+ return this.on(event, wrapper);
4885
+ }
4886
+
4887
+ off(event, listener) {
4888
+ const listeners = this.events[event];
4889
+ if (!listeners) return this;
4890
+
4891
+ const index = listeners.indexOf(listener);
4892
+ if (index !== -1) {
4893
+ listeners.splice(index, 1);
4894
+ }
4895
+
4896
+ return this;
4897
+ }
4898
+
4899
+ emit(event, data) {
4900
+ const listeners = this.events[event];
4901
+ if (!listeners) return false;
4902
+
4903
+ // Make a copy so removing listeners inside callbacks doesn't affect iteration
4904
+ [...listeners].forEach(listener => {
4905
+ try {
4906
+ listener(data);
4907
+ } catch (e) {
4908
+ console.error(`Error in listener for '${event}':`, e);
4909
+ }
4910
+ });
4911
+
4912
+ return true;
4913
+ }
4914
+ remove(event){
4915
+ delete this.events[event];
4916
+ return this;
4917
+ }
4918
+ clear() {
4919
+ this.events = {};
4920
+ return this;
4921
+ }
4922
+
4923
+ setMaxListeners(max) {
4924
+ this.maxListeners = max;
5288
4925
  return this;
5289
4926
  }
5290
4927
  }
5291
4928
 
5292
- const useThread = (func, callback , close) => {
5293
- const T = new UseThreed();
5294
- if (func) {
5295
- T.call(func, callback , close);
4929
+ const useEventEmitter = (maxListeners) => new UseEventEmitter(maxListeners);
4930
+
4931
+ /*
4932
+ [
4933
+ {
4934
+ query: '(min-width: 600px)',
4935
+ callback: () => console.log(1)
4936
+ },
4937
+ {
4938
+ query: '(max-width: 300px)',
4939
+ callback: () => console.log(2)
5296
4940
  }
5297
- return T;
5298
- };
4941
+ ]
4942
+ */
4943
+
4944
+ class UseMediaQuery {
4945
+ #mediaQueryRules;
4946
+ #fallback;
4947
+ #lastCalledCallback = null;
4948
+
4949
+ constructor(mediaQueryRules = [], fallback = () => {}) {
4950
+ this.#mediaQueryRules = mediaQueryRules;
4951
+ this.#fallback = fallback;
4952
+
4953
+ this.#init();
4954
+ }
4955
+
4956
+ // PRIVATE: check if ANY rule matches
4957
+ #checkAllRules() {
4958
+ return this.#mediaQueryRules.some(
4959
+ ({ query }) => globalThis.matchMedia(query).matches
4960
+ );
4961
+ }
4962
+
4963
+ // PRIVATE: installs listeners and initial checks
4964
+ #init() {
4965
+ this.#mediaQueryRules.forEach(({ query, callback }) => {
4966
+ const mediaQueryList = globalThis.matchMedia(query);
4967
+
4968
+ const checkMatches = () => {
4969
+ const anyMatch = this.#checkAllRules();
4970
+
4971
+ if (mediaQueryList.matches) {
4972
+ callback();
4973
+ this.#lastCalledCallback = callback;
4974
+ } else if (!anyMatch && this.#lastCalledCallback !== this.#fallback) {
4975
+ this.#fallback();
4976
+ this.#lastCalledCallback = this.#fallback;
4977
+ }
4978
+ };
4979
+
4980
+ checkMatches();
4981
+ mediaQueryList.addEventListener("change", checkMatches);
4982
+ });
4983
+ }
4984
+ }
4985
+
4986
+ const useMediaQuery = (mediaQueryRules, fallback) =>
4987
+ new UseMediaQuery(mediaQueryRules, fallback);
4988
+
4989
+ class UseTitle {
4990
+ constructor(title = document.title, withEmitter = true) {
4991
+ this.cache = {
4992
+ emitter: null
4993
+ };
4994
+
4995
+ if (withEmitter) this.useEventEmitter();
4996
+ this.set(title);
4997
+ }
4998
+
4999
+ useEventEmitter() {
5000
+ this.cache.emitter = useEventEmitter();
5001
+ return this;
5002
+ }
5003
+
5004
+ setTitle(title) {
5005
+ if (title !== document.title) {
5006
+ document.title = title;
5007
+
5008
+ if (this.cache.emitter) {
5009
+ this.cache.emitter.emit("ziko:title-changed", title);
5010
+ }
5011
+ }
5012
+ return this;
5013
+ }
5014
+
5015
+ get current() {
5016
+ return document.title;
5017
+ }
5018
+
5019
+ onChange(callback) {
5020
+ if (this.cache.emitter) {
5021
+ this.cache.emitter.on("ziko:title-changed", callback);
5022
+ }
5023
+ return this;
5024
+ }
5025
+ }
5026
+
5027
+ const useTitle = (title, withEmitter = true) => new UseTitle(title, withEmitter);
5299
5028
 
5300
5029
  class UseRoot {
5301
- constructor(PropsMap, {namespace = 'Ziko', register, ValidateCssProps = false} = {}){
5030
+ constructor(PropsMap, { namespace = 'Ziko', ValidateCssProps = false } = {}) {
5302
5031
  this.currentPropsMap = PropsMap;
5303
5032
  this.namespace = namespace;
5304
5033
  this.ValidateCssProps = ValidateCssProps;
5305
- // this.pairs = {};
5306
- // this.#maintain()
5307
5034
  this.use(PropsMap);
5308
5035
  }
5309
- use(PropsMap){
5310
- if(this.ValidateCssProps) ValidateCssProps(PropsMap);
5036
+
5037
+ use(PropsMap) {
5038
+ if (this.ValidateCssProps) ValidateCssPropsFn(PropsMap);
5311
5039
  this.currentPropsMap = PropsMap;
5312
5040
  this.#maintain();
5313
5041
  return this;
5314
5042
  }
5315
- #maintain(){
5316
- const root = globalThis?.document?.documentElement?.style;
5317
- for(let prop in this.currentPropsMap){
5318
- const cssProp = this.namespace ? `--${this.namespace}-${prop}` : `--${prop}`;
5319
- root.setProperty(
5320
- cssProp,
5321
- this.currentPropsMap[prop]
5322
- );
5323
- // Object.assign(this.pairs, {
5324
- // [prop] : `var(--${this.namespace}-${prop})`
5325
- // })
5326
- Object.defineProperty(this, prop, {
5043
+
5044
+ #maintain() {
5045
+ const root = globalThis?.document?.documentElement?.style;
5046
+ for (const prop in this.currentPropsMap) {
5047
+ const cssProp = this.namespace ? `--${this.namespace}-${prop}` : `--${prop}`;
5048
+ root.setProperty(cssProp, this.currentPropsMap[prop]);
5049
+
5050
+ Object.defineProperty(this, prop, {
5327
5051
  value: `var(${cssProp})`,
5328
5052
  writable: true,
5329
5053
  configurable: true,
5330
- enumerable: false
5331
- });
5332
- }
5054
+ enumerable: false
5055
+ });
5056
+ }
5333
5057
  }
5334
5058
  }
5335
5059
 
5336
- function ValidateCssProps(PropsMap){
5060
+ function ValidateCssPropsFn(PropsMap) {
5337
5061
  const validProps = new Set(Object.keys(document.documentElement.style));
5338
- for (let key in PropsMap) {
5062
+ for (const key in PropsMap) {
5339
5063
  if (!validProps.has(key)) {
5340
5064
  throw new Error(`Invalid CSS property: "${key}"`);
5341
5065
  }
5342
5066
  }
5343
5067
  }
5344
5068
 
5345
- const useRoot = (PropsMap, {namespace, register, ValidateCssProps} = {}) => new UseRoot(PropsMap, {namespace, register, ValidateCssProps});
5069
+ const useRoot = (PropsMap, options = {}) => new UseRoot(PropsMap, options);
5070
+
5346
5071
 
5347
5072
  // Usage
5348
5073
 
@@ -5464,25 +5189,15 @@
5464
5189
  exports.UISwitch = UISwitch;
5465
5190
  exports.UIView = UIView;
5466
5191
  exports.UseRoot = UseRoot;
5192
+ exports.UseThread = UseThread;
5467
5193
  exports.Utils = Utils;
5468
5194
  exports.View = View;
5469
5195
  exports.ZikoApp = ZikoApp;
5470
- exports.ZikoEventClick = ZikoEventClick;
5471
- exports.ZikoEventClipboard = ZikoEventClipboard;
5472
- exports.ZikoEventCustom = ZikoEventCustom;
5473
- exports.ZikoEventDrag = ZikoEventDrag;
5474
- exports.ZikoEventFocus = ZikoEventFocus;
5475
- exports.ZikoEventHash = ZikoEventHash;
5476
- exports.ZikoEventKey = ZikoEventKey;
5477
- exports.ZikoEventMouse = ZikoEventMouse;
5478
- exports.ZikoEventPointer = ZikoEventPointer;
5479
- exports.ZikoEventTouch = ZikoEventTouch;
5480
- exports.ZikoEventWheel = ZikoEventWheel;
5196
+ exports.ZikoEvent = ZikoEvent;
5481
5197
  exports.ZikoSPA = ZikoSPA;
5482
5198
  exports.ZikoUIFlex = ZikoUIFlex;
5483
5199
  exports.ZikoUISuspense = ZikoUISuspense;
5484
5200
  exports.ZikoUIText = ZikoUIText;
5485
- exports.__ZikoEvent__ = __ZikoEvent__;
5486
5201
  exports.abs = abs;
5487
5202
  exports.accum = accum;
5488
5203
  exports.acos = acos$1;
@@ -5499,9 +5214,6 @@
5499
5214
  exports.atan2 = atan2;
5500
5215
  exports.atanh = atanh;
5501
5216
  exports.back = back;
5502
- exports.bindCustomEvent = bindCustomEvent;
5503
- exports.bindHashEvent = bindHashEvent;
5504
- exports.bindTouchEvent = bindTouchEvent;
5505
5217
  exports.bind_click_event = bind_click_event;
5506
5218
  exports.bind_clipboard_event = bind_clipboard_event;
5507
5219
  exports.bind_drag_event = bind_drag_event;
@@ -5509,6 +5221,7 @@
5509
5221
  exports.bind_key_event = bind_key_event;
5510
5222
  exports.bind_mouse_event = bind_mouse_event;
5511
5223
  exports.bind_pointer_event = bind_pointer_event;
5224
+ exports.bind_touch_event = bind_touch_event;
5512
5225
  exports.bind_wheel_event = bind_wheel_event;
5513
5226
  exports.cartesianProduct = cartesianProduct;
5514
5227
  exports.ceil = ceil;
@@ -5635,15 +5348,17 @@
5635
5348
  exports.timeTaken = timeTaken;
5636
5349
  exports.time_memory_Taken = time_memory_Taken;
5637
5350
  exports.timeout = timeout;
5638
- exports.useChannel = useChannel;
5639
5351
  exports.useDerived = useDerived;
5640
5352
  exports.useEventEmitter = useEventEmitter;
5353
+ exports.useIPC = useIPC;
5641
5354
  exports.useLocaleStorage = useLocaleStorage;
5355
+ exports.useMediaQuery = useMediaQuery;
5642
5356
  exports.useReactive = useReactive;
5643
5357
  exports.useRoot = useRoot;
5644
5358
  exports.useSessionStorage = useSessionStorage;
5645
5359
  exports.useState = useState;
5646
5360
  exports.useThread = useThread;
5361
+ exports.useTitle = useTitle;
5647
5362
  exports.wait = wait;
5648
5363
  exports.waitForUIElm = waitForUIElm;
5649
5364
  exports.waitForUIElmSync = waitForUIElmSync;