ziko 0.50.1 → 0.51.0
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 +772 -898
- package/dist/ziko.js +509 -240
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +506 -241
- package/package.json +1 -1
- package/src/__helpers__/checkers/index.js +1 -0
- package/src/data/api/fetchdom.js +27 -11
- package/src/events/binders/coordinates-based-event.js +25 -0
- package/src/events/binders/custom-event.js +1 -1
- package/src/events/binders/index.js +45 -12
- package/src/events/custom-events-registry/index.js +3 -1
- package/src/events/custom-events-registry/swipe.js +41 -23
- package/src/events/custom-events-registry/view.js +50 -19
- package/src/events/customizers/normalise-coordinates.js +0 -0
- package/src/events/details-setter/index.js +3 -1
- package/src/events/details-setter/mouse.js +35 -0
- package/src/events/details-setter/pointer.js +33 -31
- package/src/events/details-setter/touch.js +37 -0
- package/src/events/events-map/index.js +13 -5
- package/src/events/utils.js +31 -0
- package/src/events/ziko-event.js +59 -117
- package/src/router/file-based-router/index.js +46 -0
- package/src/router/index.js +2 -0
- package/src/router/utils/dynamic-routes-parser.js +76 -0
- package/src/router/utils/get-root.js +16 -0
- package/src/router/utils/index.js +5 -0
- package/src/router/utils/normalize-path.js +17 -0
- package/src/router/utils/routes-grouper.js +22 -0
- package/src/router/utils/routes-matcher.js +60 -0
- package/src/ui/__methods__/dom.js +0 -20
- package/src/ui/__methods__/events.js +8 -4
- package/src/ui/__methods__/index.js +3 -0
- package/src/ui/__methods__/lifecycle.js +54 -0
- package/src/ui/constructors/UIElement.js +4 -30
- package/src/ui/{constructors/UIElement-lite.js → mini/UIElement.js} +1 -1
- package/src/ui/suspense/index.js +1 -2
- package/types/data/api/index.d.ts +15 -0
- package/types/data/index.d.ts +1 -0
- package/types/data/string/checkers.d.ts +51 -0
- package/types/data/string/converters.d.ts +101 -0
- package/types/data/string/index.d.ts +2 -0
- package/types/index.d.ts +3 -1
- package/types/router/file-based-router/index.d.ts +20 -0
- package/types/router/index.d.ts +2 -0
- package/types/router/utils/dynamic-routes-parser.d.ts +14 -0
- package/types/router/utils/get-root.d.ts +11 -0
- package/types/router/utils/index.d.ts +5 -0
- package/types/router/utils/normalize-path.d.ts +15 -0
- package/types/router/utils/routes-grouper.d.ts +29 -0
- package/types/router/utils/routes-matcher.d.ts +1 -0
package/dist/ziko.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/*
|
|
3
3
|
Project: ziko.js
|
|
4
4
|
Author: Zakaria Elalaoui
|
|
5
|
-
Date :
|
|
5
|
+
Date : Wed Dec 03 2025 10:48:15 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
|
|
@@ -945,16 +945,28 @@ const preload=(url)=>{
|
|
|
945
945
|
}
|
|
946
946
|
};
|
|
947
947
|
|
|
948
|
-
async function fetchdom(url='https://github.com/zakarialaoui10'){
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
948
|
+
async function fetchdom(url='https://github.com/zakarialaoui10') {
|
|
949
|
+
try {
|
|
950
|
+
const response = await fetch(url);
|
|
951
|
+
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
|
952
|
+
const html = await response.text();
|
|
953
|
+
const dom = new DOMParser().parseFromString(html, 'text/html');
|
|
954
|
+
return dom.documentElement;
|
|
955
|
+
} catch (err) {
|
|
956
|
+
console.error('Failed to fetch DOM:', err);
|
|
957
|
+
throw err;
|
|
958
|
+
}
|
|
953
959
|
}
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
960
|
+
|
|
961
|
+
function fetchdomSync(url='https://github.com/zakarialaoui10') {
|
|
962
|
+
try {
|
|
963
|
+
const data = preload(url);
|
|
964
|
+
const dom = new DOMParser().parseFromString(data, 'text/html');
|
|
965
|
+
return dom.documentElement;
|
|
966
|
+
} catch (err) {
|
|
967
|
+
console.error('Failed to fetch DOM synchronously:', err);
|
|
968
|
+
throw err;
|
|
969
|
+
}
|
|
958
970
|
}
|
|
959
971
|
|
|
960
972
|
globalThis.fetchdom=fetchdom;
|
|
@@ -1074,35 +1086,6 @@ class UINode {
|
|
|
1074
1086
|
|
|
1075
1087
|
// globalThis.node = (node) => new UINode(node);
|
|
1076
1088
|
|
|
1077
|
-
function parseQueryParams$1(queryString) {
|
|
1078
|
-
const params = {};
|
|
1079
|
-
queryString.replace(/[A-Z0-9]+?=([\w|:|\/\.]*)/gi, (match) => {
|
|
1080
|
-
const [key, value] = match.split('=');
|
|
1081
|
-
params[key] = value;
|
|
1082
|
-
});
|
|
1083
|
-
return params;
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
function defineParamsGetter$1(target ){
|
|
1087
|
-
Object.defineProperties(target, {
|
|
1088
|
-
'QueryParams': {
|
|
1089
|
-
get: function() {
|
|
1090
|
-
return parseQueryParams$1(globalThis.location.search.substring(1));
|
|
1091
|
-
},
|
|
1092
|
-
configurable: false,
|
|
1093
|
-
enumerable: true
|
|
1094
|
-
},
|
|
1095
|
-
'HashParams': {
|
|
1096
|
-
get: function() {
|
|
1097
|
-
const hash = globalThis.location.hash.substring(1);
|
|
1098
|
-
return hash.split("#");
|
|
1099
|
-
},
|
|
1100
|
-
configurable: false,
|
|
1101
|
-
enumerable: true
|
|
1102
|
-
}
|
|
1103
|
-
});
|
|
1104
|
-
}
|
|
1105
|
-
|
|
1106
1089
|
class UIStore extends Array {
|
|
1107
1090
|
constructor(...args) {
|
|
1108
1091
|
super(...args);
|
|
@@ -1136,6 +1119,202 @@ class UIStore extends Array {
|
|
|
1136
1119
|
// create the singleton
|
|
1137
1120
|
const __UI__ = new UIStore();
|
|
1138
1121
|
|
|
1122
|
+
// __init__global__()
|
|
1123
|
+
class UIElementCore extends UINode{
|
|
1124
|
+
constructor(){
|
|
1125
|
+
super();
|
|
1126
|
+
}
|
|
1127
|
+
init(element, name, type, render){
|
|
1128
|
+
this.target = globalThis.__Ziko__.__Config__.default.target||globalThis?.document?.body;
|
|
1129
|
+
if(typeof element === "string") {
|
|
1130
|
+
switch(type){
|
|
1131
|
+
case "html" : {
|
|
1132
|
+
element = globalThis?.document?.createElement(element);
|
|
1133
|
+
// console.log('1')
|
|
1134
|
+
} break;
|
|
1135
|
+
case "svg" : {
|
|
1136
|
+
element = globalThis?.document?.createElementNS("http://www.w3.org/2000/svg", element);
|
|
1137
|
+
// console.log('2')
|
|
1138
|
+
} break;
|
|
1139
|
+
default : throw Error("Not supported")
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
else this.target = element?.parentElement;
|
|
1143
|
+
Object.assign(this.cache, {
|
|
1144
|
+
name,
|
|
1145
|
+
isInteractive : false,
|
|
1146
|
+
parent:null,
|
|
1147
|
+
isBody:false,
|
|
1148
|
+
isRoot:false,
|
|
1149
|
+
isHidden: false,
|
|
1150
|
+
isFrozzen:false,
|
|
1151
|
+
legacyParent : null,
|
|
1152
|
+
attributes: {},
|
|
1153
|
+
filters: {},
|
|
1154
|
+
temp:{}
|
|
1155
|
+
});
|
|
1156
|
+
this.events = {
|
|
1157
|
+
ptr:null,
|
|
1158
|
+
mouse:null,
|
|
1159
|
+
wheel:null,
|
|
1160
|
+
key:null,
|
|
1161
|
+
drag:null,
|
|
1162
|
+
drop:null,
|
|
1163
|
+
click:null,
|
|
1164
|
+
clipboard:null,
|
|
1165
|
+
focus:null,
|
|
1166
|
+
swipe:null,
|
|
1167
|
+
custom:null,
|
|
1168
|
+
};
|
|
1169
|
+
this.observer={
|
|
1170
|
+
resize:null,
|
|
1171
|
+
intersection:null
|
|
1172
|
+
};
|
|
1173
|
+
if(element) Object.assign(this.cache,{element});
|
|
1174
|
+
// useDefaultStyle && this.style({
|
|
1175
|
+
// position: "relative",
|
|
1176
|
+
// boxSizing:"border-box",
|
|
1177
|
+
// margin:0,
|
|
1178
|
+
// padding:0,
|
|
1179
|
+
// width : "auto",
|
|
1180
|
+
// height : "auto"
|
|
1181
|
+
// });
|
|
1182
|
+
this.items = new UIStore();
|
|
1183
|
+
globalThis.__Ziko__.__UI__[this.cache.name]?globalThis.__Ziko__.__UI__[this.cache.name]?.push(this):globalThis.__Ziko__.__UI__[this.cache.name]=[this];
|
|
1184
|
+
element && render && this?.render?.();
|
|
1185
|
+
globalThis.__Ziko__.__UI__.push(this);
|
|
1186
|
+
}
|
|
1187
|
+
get element(){
|
|
1188
|
+
return this.cache.element;
|
|
1189
|
+
}
|
|
1190
|
+
[Symbol.iterator]() {
|
|
1191
|
+
return this.items[Symbol.iterator]();
|
|
1192
|
+
}
|
|
1193
|
+
maintain() {
|
|
1194
|
+
for (let i = 0; i < this.items.length; i++) {
|
|
1195
|
+
Object.defineProperty(this, i, {
|
|
1196
|
+
value: this.items[i],
|
|
1197
|
+
writable: true,
|
|
1198
|
+
configurable: true,
|
|
1199
|
+
enumerable: false
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
isInteractive(){
|
|
1204
|
+
return this.cache.isInteractive;
|
|
1205
|
+
}
|
|
1206
|
+
isUIElement(){
|
|
1207
|
+
return true;
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
function register_to_class(target, ...mixins){
|
|
1212
|
+
mixins.forEach(n => _register_to_class_(target, n));
|
|
1213
|
+
}
|
|
1214
|
+
function _register_to_class_(target, mixin) {
|
|
1215
|
+
const descriptors = Object.getOwnPropertyDescriptors(mixin);
|
|
1216
|
+
for (const key of Reflect.ownKeys(descriptors)) {
|
|
1217
|
+
const desc = descriptors[key];
|
|
1218
|
+
if ('get' in desc || 'set' in desc || typeof desc.value !== 'function') {
|
|
1219
|
+
Object.defineProperty(Object.getPrototypeOf(target), key, desc);
|
|
1220
|
+
} else if (typeof desc.value === 'function') {
|
|
1221
|
+
if (!Object.getPrototypeOf(target).hasOwnProperty(key)) {
|
|
1222
|
+
Object.defineProperty(Object.getPrototypeOf(target), key, desc);
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
// export function mount(target = this.target) {
|
|
1229
|
+
// if(this.isBody) return ;
|
|
1230
|
+
// if(target?.isUIElement)target=target.element;
|
|
1231
|
+
// this.target=target;
|
|
1232
|
+
// this.target?.appendChild(this.element);
|
|
1233
|
+
// return this;
|
|
1234
|
+
// }
|
|
1235
|
+
// export function unmount(){
|
|
1236
|
+
// if(this.cache.parent)this.cache.parent.remove(this);
|
|
1237
|
+
// else if(this.target?.children?.length && [...this.target?.children].includes(this.element)) this.target.removeChild(this.element);
|
|
1238
|
+
// return this;
|
|
1239
|
+
// }
|
|
1240
|
+
|
|
1241
|
+
// export function mountAfter(target = this.target, t = 1) {
|
|
1242
|
+
// setTimeout(() => this.mount(), t);
|
|
1243
|
+
// return this;
|
|
1244
|
+
// }
|
|
1245
|
+
// export function unmountAfter(t = 1) {
|
|
1246
|
+
// setTimeout(() => this.unmount(), t);
|
|
1247
|
+
// return this;
|
|
1248
|
+
// }
|
|
1249
|
+
|
|
1250
|
+
function mount(target = this.target, delay = 0) {
|
|
1251
|
+
if (delay > 0) {
|
|
1252
|
+
setTimeout(() => this.mount(target, 0), delay);
|
|
1253
|
+
return this;
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
if (this.isBody) return this;
|
|
1257
|
+
|
|
1258
|
+
if (target?.isUIElement) target = target.element;
|
|
1259
|
+
this.target = target;
|
|
1260
|
+
|
|
1261
|
+
this.target?.appendChild(this.element);
|
|
1262
|
+
return this;
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
function unmount(delay = 0) {
|
|
1266
|
+
if (delay > 0) {
|
|
1267
|
+
setTimeout(() => this.unmount(0), delay);
|
|
1268
|
+
return this;
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
if (this.cache.parent) {
|
|
1272
|
+
this.cache.parent.remove(this);
|
|
1273
|
+
} else if (
|
|
1274
|
+
this.target?.children?.length &&
|
|
1275
|
+
[...this.target.children].includes(this.element)
|
|
1276
|
+
) {
|
|
1277
|
+
this.target.removeChild(this.element);
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
return this;
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
var LifecycleMethods = /*#__PURE__*/Object.freeze({
|
|
1284
|
+
__proto__: null,
|
|
1285
|
+
mount: mount,
|
|
1286
|
+
unmount: unmount
|
|
1287
|
+
});
|
|
1288
|
+
|
|
1289
|
+
function parseQueryParams$1(queryString) {
|
|
1290
|
+
const params = {};
|
|
1291
|
+
queryString.replace(/[A-Z0-9]+?=([\w|:|\/\.]*)/gi, (match) => {
|
|
1292
|
+
const [key, value] = match.split('=');
|
|
1293
|
+
params[key] = value;
|
|
1294
|
+
});
|
|
1295
|
+
return params;
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
function defineParamsGetter$1(target ){
|
|
1299
|
+
Object.defineProperties(target, {
|
|
1300
|
+
'QueryParams': {
|
|
1301
|
+
get: function() {
|
|
1302
|
+
return parseQueryParams$1(globalThis.location.search.substring(1));
|
|
1303
|
+
},
|
|
1304
|
+
configurable: false,
|
|
1305
|
+
enumerable: true
|
|
1306
|
+
},
|
|
1307
|
+
'HashParams': {
|
|
1308
|
+
get: function() {
|
|
1309
|
+
const hash = globalThis.location.hash.substring(1);
|
|
1310
|
+
return hash.split("#");
|
|
1311
|
+
},
|
|
1312
|
+
configurable: false,
|
|
1313
|
+
enumerable: true
|
|
1314
|
+
}
|
|
1315
|
+
});
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1139
1318
|
const __Config__ = {
|
|
1140
1319
|
default:{
|
|
1141
1320
|
target:null,
|
|
@@ -1334,299 +1513,59 @@ class UseStorage {
|
|
|
1334
1513
|
return this.items[key];
|
|
1335
1514
|
}
|
|
1336
1515
|
clear() {
|
|
1337
|
-
this.cache.storage.removeItem(this.cache.globalKey);
|
|
1338
|
-
this.cache.oldItemKeys.forEach(k => delete this[k]);
|
|
1339
|
-
this.cache.oldItemKeys.clear();
|
|
1340
|
-
this.#maintain();
|
|
1341
|
-
return this;
|
|
1342
|
-
}
|
|
1343
|
-
onStorageUpdated(callback) {
|
|
1344
|
-
if (this.cache.channel) {
|
|
1345
|
-
this.cache.channel.on("Ziko-Storage-Updated", callback);
|
|
1346
|
-
}
|
|
1347
|
-
return this;
|
|
1348
|
-
}
|
|
1349
|
-
}
|
|
1350
|
-
|
|
1351
|
-
// factory functions
|
|
1352
|
-
const useLocaleStorage = (key, initialValue, use_channel = true) =>
|
|
1353
|
-
new UseStorage(localStorage, key, initialValue, use_channel);
|
|
1354
|
-
|
|
1355
|
-
const useSessionStorage = (key, initialValue, use_channel = true) =>
|
|
1356
|
-
new UseStorage(sessionStorage, key, initialValue, use_channel);
|
|
1357
|
-
|
|
1358
|
-
const __State__ = {
|
|
1359
|
-
store : new Map(),
|
|
1360
|
-
index : 0,
|
|
1361
|
-
session_storage : null,
|
|
1362
|
-
register: function(state){
|
|
1363
|
-
if(!undefined.SSR && undefined.DEV){
|
|
1364
|
-
if(!this.session) this.session_storage = useSessionStorage('ziko-state', {});
|
|
1365
|
-
const savedValue = this.session_storage.get(this.index);
|
|
1366
|
-
if(!savedValue) this.session_storage.add({[this.index] : state.value});
|
|
1367
|
-
else state.value = savedValue;
|
|
1368
|
-
}
|
|
1369
|
-
this.store.set(this.index++, state);
|
|
1370
|
-
},
|
|
1371
|
-
update: function(index, value){
|
|
1372
|
-
if(!undefined.SSR && undefined.DEV){
|
|
1373
|
-
this.session_storage.add({[index] : value});
|
|
1374
|
-
}
|
|
1375
|
-
},
|
|
1376
|
-
|
|
1377
|
-
};
|
|
1378
|
-
|
|
1379
|
-
function __init__global__(){
|
|
1380
|
-
if ( !globalThis?.__Ziko__ ){
|
|
1381
|
-
globalThis.__Ziko__ = {
|
|
1382
|
-
__UI__,
|
|
1383
|
-
__HYDRATION__,
|
|
1384
|
-
__State__,
|
|
1385
|
-
__Config__,
|
|
1386
|
-
__CACHE__,
|
|
1387
|
-
};
|
|
1388
|
-
defineParamsGetter$1(__Ziko__);
|
|
1389
|
-
}
|
|
1390
|
-
}
|
|
1391
|
-
|
|
1392
|
-
__init__global__();
|
|
1393
|
-
class UIElementCore extends UINode{
|
|
1394
|
-
constructor(){
|
|
1395
|
-
super();
|
|
1396
|
-
}
|
|
1397
|
-
init(element, name, type, render){
|
|
1398
|
-
this.target = globalThis.__Ziko__.__Config__.default.target||globalThis?.document?.body;
|
|
1399
|
-
if(typeof element === "string") {
|
|
1400
|
-
switch(type){
|
|
1401
|
-
case "html" : {
|
|
1402
|
-
element = globalThis?.document?.createElement(element);
|
|
1403
|
-
// console.log('1')
|
|
1404
|
-
} break;
|
|
1405
|
-
case "svg" : {
|
|
1406
|
-
element = globalThis?.document?.createElementNS("http://www.w3.org/2000/svg", element);
|
|
1407
|
-
// console.log('2')
|
|
1408
|
-
} break;
|
|
1409
|
-
default : throw Error("Not supported")
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
else this.target = element?.parentElement;
|
|
1413
|
-
Object.assign(this.cache, {
|
|
1414
|
-
name,
|
|
1415
|
-
isInteractive : false,
|
|
1416
|
-
parent:null,
|
|
1417
|
-
isBody:false,
|
|
1418
|
-
isRoot:false,
|
|
1419
|
-
isHidden: false,
|
|
1420
|
-
isFrozzen:false,
|
|
1421
|
-
legacyParent : null,
|
|
1422
|
-
attributes: {},
|
|
1423
|
-
filters: {},
|
|
1424
|
-
temp:{}
|
|
1425
|
-
});
|
|
1426
|
-
this.events = {
|
|
1427
|
-
ptr:null,
|
|
1428
|
-
mouse:null,
|
|
1429
|
-
wheel:null,
|
|
1430
|
-
key:null,
|
|
1431
|
-
drag:null,
|
|
1432
|
-
drop:null,
|
|
1433
|
-
click:null,
|
|
1434
|
-
clipboard:null,
|
|
1435
|
-
focus:null,
|
|
1436
|
-
swipe:null,
|
|
1437
|
-
custom:null,
|
|
1438
|
-
};
|
|
1439
|
-
this.observer={
|
|
1440
|
-
resize:null,
|
|
1441
|
-
intersection:null
|
|
1442
|
-
};
|
|
1443
|
-
if(element) Object.assign(this.cache,{element});
|
|
1444
|
-
// useDefaultStyle && this.style({
|
|
1445
|
-
// position: "relative",
|
|
1446
|
-
// boxSizing:"border-box",
|
|
1447
|
-
// margin:0,
|
|
1448
|
-
// padding:0,
|
|
1449
|
-
// width : "auto",
|
|
1450
|
-
// height : "auto"
|
|
1451
|
-
// });
|
|
1452
|
-
this.items = new UIStore();
|
|
1453
|
-
globalThis.__Ziko__.__UI__[this.cache.name]?globalThis.__Ziko__.__UI__[this.cache.name]?.push(this):globalThis.__Ziko__.__UI__[this.cache.name]=[this];
|
|
1454
|
-
element && render && this?.render?.();
|
|
1455
|
-
globalThis.__Ziko__.__UI__.push(this);
|
|
1456
|
-
}
|
|
1457
|
-
get element(){
|
|
1458
|
-
return this.cache.element;
|
|
1459
|
-
}
|
|
1460
|
-
[Symbol.iterator]() {
|
|
1461
|
-
return this.items[Symbol.iterator]();
|
|
1462
|
-
}
|
|
1463
|
-
maintain() {
|
|
1464
|
-
for (let i = 0; i < this.items.length; i++) {
|
|
1465
|
-
Object.defineProperty(this, i, {
|
|
1466
|
-
value: this.items[i],
|
|
1467
|
-
writable: true,
|
|
1468
|
-
configurable: true,
|
|
1469
|
-
enumerable: false
|
|
1470
|
-
});
|
|
1471
|
-
}
|
|
1472
|
-
}
|
|
1473
|
-
isInteractive(){
|
|
1474
|
-
return this.cache.isInteractive;
|
|
1475
|
-
}
|
|
1476
|
-
isUIElement(){
|
|
1477
|
-
return true;
|
|
1478
|
-
}
|
|
1479
|
-
// get st(){
|
|
1480
|
-
// return this.cache.style;
|
|
1481
|
-
// }
|
|
1482
|
-
// get attr(){
|
|
1483
|
-
// return this.cache.attributes;
|
|
1484
|
-
// }
|
|
1485
|
-
// get evt(){
|
|
1486
|
-
// return this.events;
|
|
1487
|
-
// }
|
|
1488
|
-
// get html(){
|
|
1489
|
-
// return this.element.innerHTML;
|
|
1490
|
-
// }
|
|
1491
|
-
// get text(){
|
|
1492
|
-
// return this.element.textContent;
|
|
1493
|
-
// }
|
|
1494
|
-
// get isBody(){
|
|
1495
|
-
// return this.element === globalThis?.document.body;
|
|
1496
|
-
// }
|
|
1497
|
-
// get parent(){
|
|
1498
|
-
// return this.cache.parent;
|
|
1499
|
-
// }
|
|
1500
|
-
// get width(){
|
|
1501
|
-
// return this.element.getBoundingClientRect().width;
|
|
1502
|
-
// }
|
|
1503
|
-
// get height(){
|
|
1504
|
-
// return this.element.getBoundingClientRect().height;
|
|
1505
|
-
// }
|
|
1506
|
-
// get top(){
|
|
1507
|
-
// return this.element.getBoundingClientRect().top;
|
|
1508
|
-
// }
|
|
1509
|
-
// get right(){
|
|
1510
|
-
// return this.element.getBoundingClientRect().right;
|
|
1511
|
-
// }
|
|
1512
|
-
// get bottom(){
|
|
1513
|
-
// return this.element.getBoundingClientRect().bottom;
|
|
1514
|
-
// }
|
|
1515
|
-
// get left(){
|
|
1516
|
-
// return this.element.getBoundingClientRect().left;
|
|
1517
|
-
// }
|
|
1518
|
-
// clone(render=false) {
|
|
1519
|
-
// // UI.__proto__=this.__proto__;
|
|
1520
|
-
// // if(this.items.length){
|
|
1521
|
-
// // const items = [...this.items].map(n=>n.clone());
|
|
1522
|
-
// // UI.append(...items);
|
|
1523
|
-
// // }
|
|
1524
|
-
// // else UI.element=this.element.cloneNode(true);
|
|
1525
|
-
// // return UI.mount(render);
|
|
1526
|
-
// }
|
|
1527
|
-
|
|
1528
|
-
// freeze(freeze){
|
|
1529
|
-
// this.cache.isFrozzen=freeze;
|
|
1530
|
-
// return this;
|
|
1531
|
-
// }
|
|
1532
|
-
// setTarget(tg) {
|
|
1533
|
-
// if(this.isBody) return ;
|
|
1534
|
-
// if (tg?.isUIElement) tg = tg.element;
|
|
1535
|
-
// this.unmount();
|
|
1536
|
-
// this.target = tg;
|
|
1537
|
-
// this.mount();
|
|
1538
|
-
// return this;
|
|
1539
|
-
// }
|
|
1540
|
-
// describe(label){
|
|
1541
|
-
// if(label)this.setAttr("aria-label",label)
|
|
1542
|
-
// }
|
|
1543
|
-
// get children() {
|
|
1544
|
-
// return [...this.element.children];
|
|
1545
|
-
// }
|
|
1546
|
-
// get cloneElement() {
|
|
1547
|
-
// return this.element.cloneNode(true);
|
|
1548
|
-
// }
|
|
1549
|
-
// setClasses(...value) {
|
|
1550
|
-
// this.setAttr("class", value.join(" "));
|
|
1551
|
-
// return this;
|
|
1552
|
-
// }
|
|
1553
|
-
// get classes(){
|
|
1554
|
-
// const classes=this.element.getAttribute("class");
|
|
1555
|
-
// return classes===null?[]:classes.split(" ");
|
|
1556
|
-
// }
|
|
1557
|
-
// addClass() {
|
|
1558
|
-
// /*this.setAttr("class", value);
|
|
1559
|
-
// return this;*/
|
|
1560
|
-
// }
|
|
1561
|
-
// setId(id) {
|
|
1562
|
-
// this.setAttr("id", id);
|
|
1563
|
-
// return this;
|
|
1564
|
-
// }
|
|
1565
|
-
// get id() {
|
|
1566
|
-
// return this.element.getAttribute("id");
|
|
1567
|
-
// }
|
|
1568
|
-
// onSwipe(width_threshold, height_threshold,...callbacks){
|
|
1569
|
-
// if(!this.events.swipe)this.events.swipe = useSwipeEvent(this, width_threshold, height_threshold);
|
|
1570
|
-
// this.events.swipe.onSwipe(...callbacks);
|
|
1571
|
-
// return this;
|
|
1572
|
-
// }
|
|
1573
|
-
// To Fix
|
|
1574
|
-
// onKeysDown({keys=[],callback}={}){
|
|
1575
|
-
// if(!this.events.key)this.events.key = useKeyEvent(this);
|
|
1576
|
-
// this.events.key.handleSuccessifKeys({keys,callback});
|
|
1577
|
-
// return this;
|
|
1578
|
-
// }
|
|
1579
|
-
// onSelect(...callbacks){
|
|
1580
|
-
// if(!this.events.clipboard)this.events.clipboard = useClipboardEvent(this);
|
|
1581
|
-
// this.events.clipboard.onSelect(...callbacks);
|
|
1582
|
-
// return this;
|
|
1583
|
-
// }
|
|
1584
|
-
// on(event_name,...callbacks){
|
|
1585
|
-
// if(!this.events.custom)this.events.custom = useCustomEvent(this);
|
|
1586
|
-
// this.events.custom.on(event_name,...callbacks);
|
|
1587
|
-
// return this;
|
|
1588
|
-
// }
|
|
1589
|
-
// emit(event_name,detail={}){
|
|
1590
|
-
// if(!this.events.custom)this.events.custom = useCustomEvent(this);
|
|
1591
|
-
// this.events.custom.emit(event_name,detail);
|
|
1592
|
-
// return this;
|
|
1593
|
-
// }
|
|
1594
|
-
// watchAttr(callback){
|
|
1595
|
-
// if(!this.observer.attr)this.observer.attr = watchAttr(this,callback);
|
|
1596
|
-
// return this;
|
|
1597
|
-
// }
|
|
1598
|
-
// watchChildren(callback){
|
|
1599
|
-
// if(!this.observer.children)this.observer.children = watchChildren(this,callback);
|
|
1600
|
-
// return this;
|
|
1601
|
-
// }
|
|
1602
|
-
// watchSize(callback){
|
|
1603
|
-
// if(!this.observer.resize)this.observer.resize = watchSize(this,callback);
|
|
1604
|
-
// this.observer.resize.start();
|
|
1605
|
-
// return this;
|
|
1606
|
-
// }
|
|
1607
|
-
// watchIntersection(callback,config){
|
|
1608
|
-
// if(!this.observer.intersection)this.observer.intersection = watchIntersection(this,callback,config);
|
|
1609
|
-
// this.observer.intersection.start();
|
|
1610
|
-
// return this;
|
|
1611
|
-
// }
|
|
1516
|
+
this.cache.storage.removeItem(this.cache.globalKey);
|
|
1517
|
+
this.cache.oldItemKeys.forEach(k => delete this[k]);
|
|
1518
|
+
this.cache.oldItemKeys.clear();
|
|
1519
|
+
this.#maintain();
|
|
1520
|
+
return this;
|
|
1521
|
+
}
|
|
1522
|
+
onStorageUpdated(callback) {
|
|
1523
|
+
if (this.cache.channel) {
|
|
1524
|
+
this.cache.channel.on("Ziko-Storage-Updated", callback);
|
|
1525
|
+
}
|
|
1526
|
+
return this;
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1612
1529
|
|
|
1613
|
-
|
|
1530
|
+
// factory functions
|
|
1531
|
+
const useLocaleStorage = (key, initialValue, use_channel = true) =>
|
|
1532
|
+
new UseStorage(localStorage, key, initialValue, use_channel);
|
|
1533
|
+
|
|
1534
|
+
const useSessionStorage = (key, initialValue, use_channel = true) =>
|
|
1535
|
+
new UseStorage(sessionStorage, key, initialValue, use_channel);
|
|
1614
1536
|
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1537
|
+
var __State__ = {
|
|
1538
|
+
store : new Map(),
|
|
1539
|
+
index : 0,
|
|
1540
|
+
session_storage : null,
|
|
1541
|
+
register: function(state){
|
|
1542
|
+
if(!undefined.SSR && undefined.DEV){
|
|
1543
|
+
if(!this.session) this.session_storage = useSessionStorage('ziko-state', {});
|
|
1544
|
+
const savedValue = this.session_storage.get(this.index);
|
|
1545
|
+
if(!savedValue) this.session_storage.add({[this.index] : state.value});
|
|
1546
|
+
else state.value = savedValue;
|
|
1547
|
+
}
|
|
1548
|
+
this.store.set(this.index++, state);
|
|
1549
|
+
},
|
|
1550
|
+
update: function(index, value){
|
|
1551
|
+
if(!undefined.SSR && undefined.DEV){
|
|
1552
|
+
this.session_storage.add({[index] : value});
|
|
1553
|
+
}
|
|
1554
|
+
},
|
|
1555
|
+
|
|
1556
|
+
};
|
|
1557
|
+
|
|
1558
|
+
function __init__global__(){
|
|
1559
|
+
if ( !globalThis?.__Ziko__ ){
|
|
1560
|
+
globalThis.__Ziko__ = {
|
|
1561
|
+
__UI__,
|
|
1562
|
+
__HYDRATION__,
|
|
1563
|
+
__State__,
|
|
1564
|
+
__Config__,
|
|
1565
|
+
__CACHE__,
|
|
1566
|
+
};
|
|
1567
|
+
defineParamsGetter$1(__Ziko__);
|
|
1628
1568
|
}
|
|
1629
|
-
}
|
|
1630
1569
|
}
|
|
1631
1570
|
|
|
1632
1571
|
if(!globalThis.__Ziko__) __init__global__();
|
|
@@ -1835,18 +1774,6 @@ function clear(){
|
|
|
1835
1774
|
this.element.innerHTML = "";
|
|
1836
1775
|
return this;
|
|
1837
1776
|
}
|
|
1838
|
-
function mount(target = this.target) {
|
|
1839
|
-
if(this.isBody)return ;
|
|
1840
|
-
if(target?.isUIElement)target=target.element;
|
|
1841
|
-
this.target=target;
|
|
1842
|
-
this.target?.appendChild(this.element);
|
|
1843
|
-
return this;
|
|
1844
|
-
}
|
|
1845
|
-
function unmount(){
|
|
1846
|
-
if(this.cache.parent)this.cache.parent.remove(this);
|
|
1847
|
-
else if(this.target?.children?.length && [...this.target?.children].includes(this.element)) this.target.removeChild(this.element);
|
|
1848
|
-
return this;
|
|
1849
|
-
}
|
|
1850
1777
|
function replaceElementWith(new_element){
|
|
1851
1778
|
this.cache.element.replaceWith(new_element);
|
|
1852
1779
|
this.cache.element = new_element;
|
|
@@ -1854,14 +1781,6 @@ function replaceElementWith(new_element){
|
|
|
1854
1781
|
// To do : Dispose Events and States
|
|
1855
1782
|
return this
|
|
1856
1783
|
}
|
|
1857
|
-
function renderAfter(t = 1) {
|
|
1858
|
-
setTimeout(() => this.mount(), t);
|
|
1859
|
-
return this;
|
|
1860
|
-
}
|
|
1861
|
-
function unrenderAfter(t = 1) {
|
|
1862
|
-
setTimeout(() => this.unmount(), t);
|
|
1863
|
-
return this;
|
|
1864
|
-
}
|
|
1865
1784
|
function after(ui){
|
|
1866
1785
|
if(ui?.isUIElement) ui=ui.element;
|
|
1867
1786
|
this.element?.after(ui);
|
|
@@ -1880,13 +1799,9 @@ var DomMethods = /*#__PURE__*/Object.freeze({
|
|
|
1880
1799
|
before: before,
|
|
1881
1800
|
clear: clear,
|
|
1882
1801
|
insertAt: insertAt,
|
|
1883
|
-
mount: mount,
|
|
1884
1802
|
prepend: prepend,
|
|
1885
1803
|
remove: remove,
|
|
1886
|
-
|
|
1887
|
-
replaceElementWith: replaceElementWith,
|
|
1888
|
-
unmount: unmount,
|
|
1889
|
-
unrenderAfter: unrenderAfter
|
|
1804
|
+
replaceElementWith: replaceElementWith
|
|
1890
1805
|
});
|
|
1891
1806
|
|
|
1892
1807
|
const EventsMap = {
|
|
@@ -1935,64 +1850,109 @@ const EventsMap = {
|
|
|
1935
1850
|
],
|
|
1936
1851
|
'Wheel': [
|
|
1937
1852
|
'Wheel'
|
|
1938
|
-
]
|
|
1853
|
+
],
|
|
1939
1854
|
// 'Media':[
|
|
1940
1855
|
|
|
1941
1856
|
// ],
|
|
1942
1857
|
// 'Hash':[
|
|
1943
1858
|
// "HashChange"
|
|
1944
1859
|
// ]
|
|
1860
|
+
|
|
1861
|
+
'View':[
|
|
1862
|
+
'EnterView',
|
|
1863
|
+
'ExitView',
|
|
1864
|
+
'ResizeView'
|
|
1865
|
+
],
|
|
1866
|
+
'Swipe':[
|
|
1867
|
+
'SwipeLeft',
|
|
1868
|
+
'SwipeUp',
|
|
1869
|
+
'SwipeRight',
|
|
1870
|
+
'SwipeDown'
|
|
1871
|
+
]
|
|
1945
1872
|
};
|
|
1946
1873
|
|
|
1874
|
+
function event_controller(e, event_name, details_setter, customizer) {
|
|
1875
|
+
this.cache.currentEvent = event_name;
|
|
1876
|
+
this.cache.event = e;
|
|
1877
|
+
|
|
1878
|
+
details_setter?.call(this);
|
|
1879
|
+
if (customizer?.hasOwnProperty('prototype')) customizer?.call(this);
|
|
1880
|
+
else customizer?.call(null, this);
|
|
1881
|
+
|
|
1882
|
+
if (this.cache.preventDefault[event_name]) e.preventDefault();
|
|
1883
|
+
if (this.cache.stopPropagation[event_name]) e.stopPropagation();
|
|
1884
|
+
if (this.cache.stopImmediatePropagation[event_name]) e.stopImmediatePropagation();
|
|
1885
|
+
|
|
1886
|
+
// Call the single callback if it exists
|
|
1887
|
+
this.cache.callbacks[event_name]?.(this);
|
|
1888
|
+
}
|
|
1889
|
+
|
|
1890
|
+
function toggle_event_listener(method, ...events) {
|
|
1891
|
+
const keys = events.length === 0
|
|
1892
|
+
? Object.keys(this.cache.paused)
|
|
1893
|
+
: events;
|
|
1894
|
+
keys.forEach(key => {
|
|
1895
|
+
if (!this.cache.paused.hasOwnProperty(key)) return;
|
|
1896
|
+
this.targetElement?.[method](
|
|
1897
|
+
key,
|
|
1898
|
+
this.cache.__controllers__[key],
|
|
1899
|
+
this.cache.options[key]
|
|
1900
|
+
);
|
|
1901
|
+
this.cache.paused[key] = method === 'removeEventListener';
|
|
1902
|
+
});
|
|
1903
|
+
return this;
|
|
1904
|
+
}
|
|
1947
1905
|
const getEvent=(event = "")=>{
|
|
1948
1906
|
if(event.startsWith("Ptr"))return `pointer${event.split("Ptr")[1].toLowerCase()}`;
|
|
1949
1907
|
return event.toLowerCase()
|
|
1950
1908
|
};
|
|
1951
1909
|
|
|
1952
|
-
|
|
1953
|
-
constructor(target = null, Events = [], details_setter, customizer){
|
|
1910
|
+
class ZikoEvent {
|
|
1911
|
+
constructor(signature, target = null, Events = [], details_setter, customizer){
|
|
1954
1912
|
this.target = target;
|
|
1955
1913
|
this.cache = {
|
|
1914
|
+
signature,
|
|
1956
1915
|
currentEvent : null,
|
|
1957
1916
|
event: null,
|
|
1958
1917
|
options : {},
|
|
1959
1918
|
preventDefault : {},
|
|
1960
1919
|
stopPropagation : {},
|
|
1961
1920
|
stopImmediatePropagation : {},
|
|
1962
|
-
event_flow : {},
|
|
1963
1921
|
paused : {},
|
|
1964
|
-
stream : {
|
|
1965
|
-
enabled : {},
|
|
1966
|
-
clear : {},
|
|
1967
|
-
history : {}
|
|
1968
|
-
},
|
|
1969
1922
|
callbacks : {},
|
|
1970
1923
|
__controllers__:{}
|
|
1971
1924
|
};
|
|
1972
|
-
if(Events)this._register_events(Events, details_setter, customizer);
|
|
1973
|
-
}
|
|
1974
|
-
_register_events(Events, details_setter, customizer, REGISTER_METHODES = true){
|
|
1975
|
-
const events = Events?.map(n=>getEvent(n));
|
|
1976
|
-
events?.forEach((event,i)=>{
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1925
|
+
if (Events) this._register_events(Events, details_setter, customizer);
|
|
1926
|
+
}
|
|
1927
|
+
_register_events(Events, details_setter, customizer, REGISTER_METHODES = true) {
|
|
1928
|
+
const events = Events?.map(n => getEvent(n));
|
|
1929
|
+
events?.forEach((event, i) => {
|
|
1930
|
+
this.cache.preventDefault[event] = false;
|
|
1931
|
+
this.cache.options[event] = {};
|
|
1932
|
+
this.cache.paused[event] = false;
|
|
1933
|
+
this.cache.__controllers__[event] = (e) =>
|
|
1934
|
+
event_controller.call(this, e, event, details_setter, customizer);
|
|
1935
|
+
if (REGISTER_METHODES) {
|
|
1936
|
+
this[`on${Events[i]}`] = (callback) =>
|
|
1937
|
+
this.__onEvent(event, this.cache.options[event], {}, callback);
|
|
1938
|
+
}
|
|
1985
1939
|
});
|
|
1986
1940
|
return this;
|
|
1987
1941
|
}
|
|
1942
|
+
__onEvent(event, options, dispose, callback) {
|
|
1943
|
+
if (!callback) return this;
|
|
1944
|
+
this.cache.callbacks[event] = callback;
|
|
1945
|
+
this.__handle(event, this.cache.__controllers__[event], options, dispose);
|
|
1946
|
+
return this;
|
|
1947
|
+
}
|
|
1988
1948
|
get targetElement(){
|
|
1989
1949
|
return this.target?.element;
|
|
1990
1950
|
}
|
|
1991
1951
|
get isParent(){
|
|
1992
|
-
return this.target?.element === this.event
|
|
1952
|
+
return this.target?.element === this.event?.srcElement;
|
|
1993
1953
|
}
|
|
1994
1954
|
get item(){
|
|
1995
|
-
return this.target.find(n=>n.element == this.event?.srcElement)?.[0];
|
|
1955
|
+
return this.target.find(n => n.element == this.event?.srcElement)?.[0];
|
|
1996
1956
|
}
|
|
1997
1957
|
get currentEvent(){
|
|
1998
1958
|
return this.cache.currentEvent;
|
|
@@ -2000,114 +1960,51 @@ let ZikoEvent$1 = class ZikoEvent {
|
|
|
2000
1960
|
get event(){
|
|
2001
1961
|
return this.cache.event;
|
|
2002
1962
|
}
|
|
1963
|
+
get detail(){
|
|
1964
|
+
return this.cache.event.detail
|
|
1965
|
+
}
|
|
2003
1966
|
setTarget(UI){
|
|
2004
|
-
this.target=UI;
|
|
1967
|
+
this.target = UI;
|
|
2005
1968
|
return this;
|
|
2006
1969
|
}
|
|
2007
|
-
__handle(event, handler, options
|
|
1970
|
+
__handle(event, handler, options){
|
|
2008
1971
|
this.targetElement?.addEventListener(event, handler, options);
|
|
2009
1972
|
return this;
|
|
2010
1973
|
}
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
if(this.cache.
|
|
2015
|
-
|
|
2016
|
-
// this.cache.callbacks.map(n=>e=>n.call(this,e));
|
|
2017
|
-
this.cache.callbacks[event].map(n=>e=>n.call(this,e));
|
|
2018
|
-
}
|
|
2019
|
-
else {
|
|
2020
|
-
return this;
|
|
2021
|
-
}
|
|
2022
|
-
}
|
|
2023
|
-
else this.cache.callbacks[event] = callbacks.map(n=>e=>n.call(this,e));
|
|
2024
|
-
this.__handle(event, this.cache.__controllers__[event],options, dispose);
|
|
2025
|
-
return this;
|
|
2026
|
-
}
|
|
2027
|
-
#override(methode, overrides, defaultValue){
|
|
2028
|
-
if(defaultValue === "default") Object.assign(this.cache[methode], {...this.cache[methode], ...overrides});
|
|
2029
|
-
const all = defaultValue === "default"
|
|
2030
|
-
? this.cache[methode]
|
|
2031
|
-
: Object.fromEntries(Object.keys(this.cache.preventDefault).map(n=>[n,defaultValue]));
|
|
2032
|
-
Object.assign(this.cache[methode], {...all,...overrides});
|
|
2033
|
-
return this
|
|
2034
|
-
}
|
|
2035
|
-
preventDefault(overrides = {}, defaultValue = "default"){
|
|
2036
|
-
this.#override("preventDefault", overrides, defaultValue);
|
|
2037
|
-
// const all=Object.fromEntries(Object.keys(this.cache.preventDefault).map(n=>[n,defaultValue]))
|
|
2038
|
-
// Object.assign(this.cache.preventDefault, {...all,...overrides});
|
|
1974
|
+
#override(method, ...events) {
|
|
1975
|
+
const keys = events.length === 0 ? Object.keys(this.cache[method]) : events;
|
|
1976
|
+
keys.forEach(e => {
|
|
1977
|
+
if (this.cache[method].hasOwnProperty(e)) this.cache[method][e] = true;
|
|
1978
|
+
});
|
|
2039
1979
|
return this;
|
|
2040
1980
|
}
|
|
2041
|
-
|
|
2042
|
-
this.#override(
|
|
2043
|
-
return this;
|
|
1981
|
+
preventDefault(...events) {
|
|
1982
|
+
return this.#override('preventDefault', ...events);
|
|
2044
1983
|
}
|
|
2045
|
-
|
|
2046
|
-
this.#override(
|
|
2047
|
-
|
|
1984
|
+
stopPropagation(...events) {
|
|
1985
|
+
return this.#override('stopPropagation', ...events);
|
|
1986
|
+
}
|
|
1987
|
+
stopImmediatePropagation(...events) {
|
|
1988
|
+
return this.#override('stopImmediatePropagation', ...events);
|
|
2048
1989
|
}
|
|
2049
1990
|
setEventOptions(event, options){
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
this.
|
|
1991
|
+
const evt = getEvent(event);
|
|
1992
|
+
this.pause();
|
|
1993
|
+
Object.assign(this.cache.options[evt], options);
|
|
1994
|
+
this.resume();
|
|
2053
1995
|
return this;
|
|
2054
1996
|
}
|
|
2055
|
-
pause(
|
|
2056
|
-
|
|
2057
|
-
? this.cache.stream.enabled
|
|
2058
|
-
: Object.entries(Object.keys(this.cache.stream.enabled).map(n=>[n,defaultValue]));
|
|
2059
|
-
overrides={...all,...overrides};
|
|
2060
|
-
for(let key in overrides){
|
|
2061
|
-
if(overrides[key]){
|
|
2062
|
-
this.targetElement?.removeEventListener(key, this.cache.__controllers__[key], this.cache.options[key]);
|
|
2063
|
-
this.cache.paused[key]=true;
|
|
2064
|
-
}
|
|
2065
|
-
}
|
|
2066
|
-
return this;
|
|
1997
|
+
pause(...events) {
|
|
1998
|
+
return toggle_event_listener.call(this, 'removeEventListener', ...events)
|
|
2067
1999
|
}
|
|
2068
|
-
resume(
|
|
2069
|
-
|
|
2070
|
-
? this.cache.stream.enabled
|
|
2071
|
-
: Object.entries(Object.keys(this.cache.stream.enabled).map(n=>[n,defaultValue]));
|
|
2072
|
-
overrides={...all,...overrides};
|
|
2073
|
-
for(let key in overrides){
|
|
2074
|
-
if(overrides[key]){
|
|
2075
|
-
this.targetElement?.addEventListener(key,this.cache.__controllers__[key], this.cache.options[key]);
|
|
2076
|
-
this.cache.paused[key]=false;
|
|
2077
|
-
}
|
|
2078
|
-
}
|
|
2079
|
-
return this;
|
|
2080
|
-
}
|
|
2081
|
-
stream(overrides = {}, defaultValue = "default"){
|
|
2082
|
-
this.cache.stream.t0=Date.now();
|
|
2083
|
-
const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,defaultValue]));
|
|
2084
|
-
overrides={...all,...overrides};
|
|
2085
|
-
Object.assign(this.cache.stream.enabled,overrides);
|
|
2086
|
-
return this;
|
|
2087
|
-
}
|
|
2088
|
-
clear(){
|
|
2089
|
-
return this;
|
|
2000
|
+
resume(...events) {
|
|
2001
|
+
return toggle_event_listener.call(this, 'addEventListener', ...events);
|
|
2090
2002
|
}
|
|
2091
|
-
dispose(
|
|
2092
|
-
this.pause(
|
|
2093
|
-
|
|
2003
|
+
dispose(){
|
|
2004
|
+
this.pause();
|
|
2005
|
+
this.target.events[this.cache.signature] = null;
|
|
2094
2006
|
return this;
|
|
2095
2007
|
}
|
|
2096
|
-
};
|
|
2097
|
-
|
|
2098
|
-
function event_controller(e, event_name, details_setter, customizer, push_object){
|
|
2099
|
-
this.cache.currentEvent = event_name;
|
|
2100
|
-
this.cache.event = e;
|
|
2101
|
-
details_setter?.call(this);
|
|
2102
|
-
customizer?.hasOwnProperty("prototype") ? customizer?.call(this) : customizer?.call(null, this);
|
|
2103
|
-
// if(customizer?.hasOwnProperty("prototype")) customizer?.call(this)
|
|
2104
|
-
// else customizer?.call(null, this)
|
|
2105
|
-
if(this.cache.preventDefault[event_name]) e.preventDefault();
|
|
2106
|
-
if(this.cache.stopPropagation[event_name]) e.stopPropagation();
|
|
2107
|
-
if(this.cache.stopImmediatePropagation[event_name]) e.stopImmediatePropagation();
|
|
2108
|
-
|
|
2109
|
-
if(this.cache.stream.enabled[event_name]&&push_object)this.cache.stream.history[event_name].push(push_object);
|
|
2110
|
-
this.cache.callbacks[event_name]?.map(n=>n(this));
|
|
2111
2008
|
}
|
|
2112
2009
|
|
|
2113
2010
|
function key_details_setter(){
|
|
@@ -2194,70 +2091,277 @@ function register_click_away_event(element) {
|
|
|
2194
2091
|
// // later, you can stop listening:
|
|
2195
2092
|
// // stop();
|
|
2196
2093
|
|
|
2094
|
+
const debounce=(fn,delay=1000)=>{
|
|
2095
|
+
let id;
|
|
2096
|
+
return (...args) => id ? clearTimeout(id) : setTimeout(()=>fn(...args),delay);
|
|
2097
|
+
};
|
|
2098
|
+
const throttle=(fn,delay)=>{
|
|
2099
|
+
let lastTime=0;
|
|
2100
|
+
return (...args) => {
|
|
2101
|
+
const now = new Date().getTime();
|
|
2102
|
+
if(now-lastTime < delay) return;
|
|
2103
|
+
lastTime = now;
|
|
2104
|
+
fn(...args);
|
|
2105
|
+
}
|
|
2106
|
+
};
|
|
2107
|
+
|
|
2108
|
+
class ViewEvent extends CustomEvent {
|
|
2109
|
+
constructor(type, detail, { bubbles = true, cancelable = true } = {}) {
|
|
2110
|
+
super(type, { detail, bubbles, cancelable });
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
|
|
2114
|
+
function register_view_event(
|
|
2115
|
+
element,
|
|
2116
|
+
{
|
|
2117
|
+
intersection = true,
|
|
2118
|
+
resize = true,
|
|
2119
|
+
threshold = 0,
|
|
2120
|
+
throttleResize = 100,
|
|
2121
|
+
throttleEnterExit = 0
|
|
2122
|
+
} = {}
|
|
2123
|
+
) {
|
|
2124
|
+
let intersectionObserver, resizeObserver;
|
|
2125
|
+
const resizeCallback = entries => {
|
|
2126
|
+
for (let entry of entries) {
|
|
2127
|
+
const { width, height } = entry.contentRect;
|
|
2128
|
+
|
|
2129
|
+
element.dispatchEvent(
|
|
2130
|
+
new ViewEvent("resizeview", {
|
|
2131
|
+
width,
|
|
2132
|
+
height,
|
|
2133
|
+
entry
|
|
2134
|
+
})
|
|
2135
|
+
);
|
|
2136
|
+
}
|
|
2137
|
+
};
|
|
2138
|
+
|
|
2139
|
+
const throttledResize = throttleResize > 0
|
|
2140
|
+
? throttle(resizeCallback, throttleResize)
|
|
2141
|
+
: resizeCallback;
|
|
2142
|
+
|
|
2143
|
+
const intersectionCallback = entries => {
|
|
2144
|
+
for (let entry of entries) {
|
|
2145
|
+
const type = entry.isIntersecting ? "enterview" : "exitview";
|
|
2146
|
+
element.dispatchEvent(new ViewEvent(type, entry));
|
|
2147
|
+
}
|
|
2148
|
+
};
|
|
2149
|
+
|
|
2150
|
+
const throttledIntersections = throttleEnterExit > 0
|
|
2151
|
+
? throttle(intersectionCallback, throttleEnterExit)
|
|
2152
|
+
: intersectionCallback;
|
|
2153
|
+
|
|
2154
|
+
if (intersection) {
|
|
2155
|
+
intersectionObserver = new IntersectionObserver(throttledIntersections, { threshold });
|
|
2156
|
+
intersectionObserver.observe(element);
|
|
2157
|
+
}
|
|
2158
|
+
|
|
2159
|
+
if (resize) {
|
|
2160
|
+
resizeObserver = new ResizeObserver(throttledResize);
|
|
2161
|
+
resizeObserver.observe(element);
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
// ---- UNREGISTER ----
|
|
2165
|
+
return () => {
|
|
2166
|
+
if (intersectionObserver) {
|
|
2167
|
+
intersectionObserver.unobserve(element);
|
|
2168
|
+
intersectionObserver.disconnect();
|
|
2169
|
+
}
|
|
2170
|
+
if (resizeObserver) {
|
|
2171
|
+
resizeObserver.unobserve(element);
|
|
2172
|
+
resizeObserver.disconnect();
|
|
2173
|
+
}
|
|
2174
|
+
};
|
|
2175
|
+
}
|
|
2176
|
+
|
|
2177
|
+
class SwipeEvent extends CustomEvent {
|
|
2178
|
+
constructor(type, detail) {
|
|
2179
|
+
super(type, {
|
|
2180
|
+
detail,
|
|
2181
|
+
bubbles: true,
|
|
2182
|
+
cancelable: true
|
|
2183
|
+
});
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
2186
|
+
|
|
2187
|
+
function register_swipe_event(
|
|
2188
|
+
element,
|
|
2189
|
+
threshold = 50,
|
|
2190
|
+
restraint = 100,
|
|
2191
|
+
allowedTime = 500
|
|
2192
|
+
) {
|
|
2193
|
+
let startX = 0,
|
|
2194
|
+
startY = 0,
|
|
2195
|
+
startTime = 0,
|
|
2196
|
+
isPointerDown = false;
|
|
2197
|
+
|
|
2198
|
+
function onPointerDown(e) {
|
|
2199
|
+
startX = e.clientX;
|
|
2200
|
+
startY = e.clientY;
|
|
2201
|
+
startTime = performance.now();
|
|
2202
|
+
isPointerDown = true;
|
|
2203
|
+
}
|
|
2204
|
+
|
|
2205
|
+
function onPointerUp(e) {
|
|
2206
|
+
if (!isPointerDown) return;
|
|
2207
|
+
isPointerDown = false;
|
|
2208
|
+
|
|
2209
|
+
const distX = e.clientX - startX;
|
|
2210
|
+
const distY = e.clientY - startY;
|
|
2211
|
+
const elapsed = performance.now() - startTime;
|
|
2212
|
+
|
|
2213
|
+
let direction = null;
|
|
2214
|
+
let eventName = null;
|
|
2215
|
+
|
|
2216
|
+
if (elapsed <= allowedTime) {
|
|
2217
|
+
if (Math.abs(distX) >= threshold && Math.abs(distY) <= restraint) {
|
|
2218
|
+
direction = distX < 0 ? "left" : "right";
|
|
2219
|
+
eventName = "swipe" + direction;
|
|
2220
|
+
}
|
|
2221
|
+
else if (Math.abs(distY) >= threshold && Math.abs(distX) <= restraint) {
|
|
2222
|
+
direction = distY < 0 ? "up" : "down";
|
|
2223
|
+
eventName = "swipe" + direction;
|
|
2224
|
+
}
|
|
2225
|
+
}
|
|
2226
|
+
|
|
2227
|
+
// Emit event
|
|
2228
|
+
if (eventName) {
|
|
2229
|
+
element.dispatchEvent(
|
|
2230
|
+
new SwipeEvent(eventName, {
|
|
2231
|
+
direction,
|
|
2232
|
+
distX,
|
|
2233
|
+
distY,
|
|
2234
|
+
originalEvent: e
|
|
2235
|
+
})
|
|
2236
|
+
);
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
|
|
2240
|
+
element.addEventListener("pointerdown", onPointerDown, { passive: true });
|
|
2241
|
+
element.addEventListener("pointerup", onPointerUp, { passive: true });
|
|
2242
|
+
|
|
2243
|
+
return () => {
|
|
2244
|
+
element.removeEventListener("pointerdown", onPointerDown);
|
|
2245
|
+
element.removeEventListener("pointerup", onPointerUp);
|
|
2246
|
+
};
|
|
2247
|
+
}
|
|
2248
|
+
|
|
2197
2249
|
const bind_click_event = (target, customizer) => {
|
|
2198
2250
|
register_click_away_event(target.element);
|
|
2199
|
-
return new ZikoEvent
|
|
2251
|
+
return new ZikoEvent(
|
|
2252
|
+
'click',
|
|
2200
2253
|
target,
|
|
2201
2254
|
EventsMap.Click,
|
|
2202
2255
|
null,
|
|
2203
2256
|
customizer
|
|
2204
2257
|
);
|
|
2205
2258
|
};
|
|
2206
|
-
const bind_clipboard_event = (target, customizer) => new ZikoEvent
|
|
2259
|
+
const bind_clipboard_event = (target, customizer) => new ZikoEvent(
|
|
2260
|
+
'clipboard',
|
|
2207
2261
|
target,
|
|
2208
2262
|
EventsMap.Clipboard,
|
|
2209
2263
|
null,
|
|
2210
2264
|
customizer
|
|
2211
2265
|
);
|
|
2212
|
-
const bind_drag_event = (target, customizer) => new ZikoEvent
|
|
2266
|
+
const bind_drag_event = (target, customizer) => new ZikoEvent(
|
|
2267
|
+
'drag',
|
|
2213
2268
|
target,
|
|
2214
2269
|
EventsMap.Drag,
|
|
2215
2270
|
null,
|
|
2216
2271
|
customizer
|
|
2217
2272
|
);
|
|
2218
|
-
const bind_focus_event = (target, customizer) => new ZikoEvent
|
|
2273
|
+
const bind_focus_event = (target, customizer) => new ZikoEvent(
|
|
2274
|
+
'focus',
|
|
2219
2275
|
target,
|
|
2220
2276
|
EventsMap.Focus,
|
|
2221
2277
|
null,
|
|
2222
2278
|
customizer
|
|
2223
2279
|
);
|
|
2224
|
-
const bind_key_event = (target, customizer) => new ZikoEvent
|
|
2280
|
+
const bind_key_event = (target, customizer) => new ZikoEvent(
|
|
2281
|
+
'key',
|
|
2225
2282
|
target,
|
|
2226
2283
|
EventsMap.Key,
|
|
2227
2284
|
key_details_setter,
|
|
2228
2285
|
customizer
|
|
2229
2286
|
);
|
|
2230
|
-
const bind_mouse_event = (target, customizer) => new ZikoEvent
|
|
2287
|
+
const bind_mouse_event = (target, customizer) => new ZikoEvent(
|
|
2288
|
+
'mouse',
|
|
2231
2289
|
target,
|
|
2232
2290
|
EventsMap.Mouse,
|
|
2233
2291
|
null,
|
|
2234
2292
|
customizer
|
|
2235
2293
|
);
|
|
2236
|
-
const bind_pointer_event = (target, customizer) => new ZikoEvent
|
|
2294
|
+
const bind_pointer_event = (target, customizer) => new ZikoEvent(
|
|
2295
|
+
'ptr',
|
|
2237
2296
|
target,
|
|
2238
2297
|
EventsMap.Ptr,
|
|
2239
2298
|
ptr_details_setter,
|
|
2240
2299
|
customizer
|
|
2241
2300
|
);
|
|
2242
|
-
const bind_touch_event = (target, customizer) => new ZikoEvent
|
|
2301
|
+
const bind_touch_event = (target, customizer) => new ZikoEvent(
|
|
2302
|
+
'touch',
|
|
2243
2303
|
target,
|
|
2244
2304
|
EventsMap.Touch,
|
|
2245
2305
|
null,
|
|
2246
2306
|
customizer
|
|
2247
2307
|
);
|
|
2248
|
-
const bind_wheel_event = (target, customizer) => new ZikoEvent
|
|
2308
|
+
const bind_wheel_event = (target, customizer) => new ZikoEvent(
|
|
2309
|
+
'wheel',
|
|
2249
2310
|
target,
|
|
2250
2311
|
EventsMap.Wheel,
|
|
2251
2312
|
null,
|
|
2252
2313
|
customizer
|
|
2253
2314
|
);
|
|
2254
2315
|
|
|
2316
|
+
const bind_view_event = (target, customizer) => {
|
|
2317
|
+
register_view_event(target.element);
|
|
2318
|
+
return new ZikoEvent(
|
|
2319
|
+
'view',
|
|
2320
|
+
target,
|
|
2321
|
+
EventsMap.View,
|
|
2322
|
+
null,
|
|
2323
|
+
customizer
|
|
2324
|
+
)
|
|
2325
|
+
};
|
|
2255
2326
|
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2327
|
+
const bind_swipe_event = (target, customizer) => {
|
|
2328
|
+
register_swipe_event(target.element);
|
|
2329
|
+
return new ZikoEvent(
|
|
2330
|
+
'swipe',
|
|
2331
|
+
target,
|
|
2332
|
+
EventsMap.Swipe,
|
|
2333
|
+
null,
|
|
2334
|
+
customizer
|
|
2335
|
+
)
|
|
2336
|
+
};
|
|
2337
|
+
|
|
2338
|
+
class ZikoCustomEvent extends ZikoEvent{
|
|
2339
|
+
constructor(target, events, customizer){
|
|
2340
|
+
super('custom', target, events, details_setter, customizer);
|
|
2341
|
+
}
|
|
2342
|
+
_register_events(events){
|
|
2343
|
+
super._register_events(events, null, null, false);
|
|
2344
|
+
return this;
|
|
2345
|
+
}
|
|
2346
|
+
emit(event_name, detail = {}){
|
|
2347
|
+
const event = new CustomEvent(event_name, {
|
|
2348
|
+
detail,
|
|
2349
|
+
bubbles: true,
|
|
2350
|
+
cancelable: true
|
|
2351
|
+
});
|
|
2352
|
+
this.targetElement.dispatchEvent(event);
|
|
2353
|
+
return this;
|
|
2354
|
+
}
|
|
2355
|
+
on(event_name, ...callbacks){
|
|
2356
|
+
if(!this.cache.options.hasOwnProperty(event_name)) this._register_events([event_name]);
|
|
2357
|
+
this.__onEvent(event_name, this.cache.options[event_name], {}, ...callbacks);
|
|
2358
|
+
return this;
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
function details_setter(){
|
|
2362
|
+
|
|
2363
|
+
}
|
|
2364
|
+
const bind_custom_event = (target, events, customizer) => new ZikoCustomEvent(target, events, customizer);
|
|
2261
2365
|
|
|
2262
2366
|
const binderMap = {
|
|
2263
2367
|
ptr: bind_pointer_event,
|
|
@@ -2267,17 +2371,31 @@ const binderMap = {
|
|
|
2267
2371
|
drag : bind_drag_event,
|
|
2268
2372
|
clipboard : bind_clipboard_event,
|
|
2269
2373
|
focus : bind_focus_event,
|
|
2270
|
-
wheel : bind_wheel_event
|
|
2374
|
+
wheel : bind_wheel_event,
|
|
2375
|
+
view : bind_view_event,
|
|
2376
|
+
swipe : bind_swipe_event
|
|
2271
2377
|
};
|
|
2272
2378
|
|
|
2273
|
-
const EventsMethodes = {
|
|
2379
|
+
const EventsMethodes = {
|
|
2380
|
+
on(event_name,...callbacks){
|
|
2381
|
+
if(!this.events.custom)this.events.custom = bind_custom_event(this);
|
|
2382
|
+
this.events.custom.on(event_name,...callbacks);
|
|
2383
|
+
return this;
|
|
2384
|
+
},
|
|
2385
|
+
emit(event_name,detail={}){
|
|
2386
|
+
if(!this.events.custom)this.events.custom = bind_custom_event(this);
|
|
2387
|
+
this.events.custom.emit(event_name,detail);
|
|
2388
|
+
return this;
|
|
2389
|
+
}
|
|
2390
|
+
};
|
|
2274
2391
|
|
|
2275
2392
|
Object.entries(EventsMap).forEach(([name, eventList]) => {
|
|
2393
|
+
const lname = name.toLowerCase();
|
|
2276
2394
|
eventList.forEach(event => {
|
|
2277
2395
|
const methodName = `on${event}`;
|
|
2278
|
-
EventsMethodes[methodName] = function (
|
|
2279
|
-
if (!this.events[
|
|
2280
|
-
this.events[
|
|
2396
|
+
EventsMethodes[methodName] = function (callbacks) {
|
|
2397
|
+
if (!this.events[lname]) this.events[lname] = binderMap[lname](this);
|
|
2398
|
+
this.events[lname][methodName](callbacks);
|
|
2281
2399
|
return this;
|
|
2282
2400
|
};
|
|
2283
2401
|
});
|
|
@@ -2338,158 +2456,14 @@ function animate(keyframe, {duration=1000, iterations=1, easing="ease"}={}){
|
|
|
2338
2456
|
return this;
|
|
2339
2457
|
}
|
|
2340
2458
|
|
|
2341
|
-
var StyleMethods = /*#__PURE__*/Object.freeze({
|
|
2342
|
-
__proto__: null,
|
|
2343
|
-
animate: animate,
|
|
2344
|
-
hide: hide,
|
|
2345
|
-
show: show,
|
|
2346
|
-
size: size,
|
|
2347
|
-
style: style
|
|
2348
|
-
});
|
|
2349
|
-
|
|
2350
|
-
function EVENT_CONTROLLER(e,EVENT,setter,push_object){
|
|
2351
|
-
this.event=e;
|
|
2352
|
-
if(this.cache.preventDefault[EVENT])e.preventDefault();
|
|
2353
|
-
console.log({setter});
|
|
2354
|
-
if(setter)setter();
|
|
2355
|
-
if(this.cache.stream.enabled[EVENT]&&push_object)this.cache.stream.history[EVENT].push(push_object);
|
|
2356
|
-
this.cache.callbacks[EVENT].map(n=>n(this));
|
|
2357
|
-
return this;
|
|
2358
|
-
}
|
|
2359
|
-
class ZikoEvent{
|
|
2360
|
-
constructor(target){
|
|
2361
|
-
this.target=null;
|
|
2362
|
-
this.setTarget(target);
|
|
2363
|
-
this.__dispose=this.dispose.bind(this);
|
|
2364
|
-
// this.EventIndex=Garbage.Pointer.data.length;
|
|
2365
|
-
// Garbage.Pointer.data.push({event:this,index:this.EventIndex});
|
|
2366
|
-
}
|
|
2367
|
-
get targetElement(){
|
|
2368
|
-
return this.target.element
|
|
2369
|
-
}
|
|
2370
|
-
setTarget(UI){
|
|
2371
|
-
this.target=UI;
|
|
2372
|
-
return this;
|
|
2373
|
-
}
|
|
2374
|
-
__handle(event,handler,dispose){
|
|
2375
|
-
const EVENT=(event==="drag")?event:`${this.cache.prefixe}${event}`;
|
|
2376
|
-
this.dispose(dispose);
|
|
2377
|
-
this.targetElement?.addEventListener(EVENT,handler);
|
|
2378
|
-
return this;
|
|
2379
|
-
}
|
|
2380
|
-
__onEvent(event,dispose,...callbacks){
|
|
2381
|
-
if(callbacks.length===0){
|
|
2382
|
-
if(this.cache.callbacks.length>1){
|
|
2383
|
-
this.cache.callbacks.map(n=>e=>n.call(this,e));
|
|
2384
|
-
}
|
|
2385
|
-
else {
|
|
2386
|
-
return this;
|
|
2387
|
-
}
|
|
2388
|
-
}
|
|
2389
|
-
else this.cache.callbacks[event]=callbacks.map(n=>e=>n.call(this,e));
|
|
2390
|
-
this.__handle(event,this.__controller[event],dispose);
|
|
2391
|
-
return this;
|
|
2392
|
-
}
|
|
2393
|
-
preventDefault(config={}){
|
|
2394
|
-
Object.assign(this.cache.preventDefault,config);
|
|
2395
|
-
return this;
|
|
2396
|
-
}
|
|
2397
|
-
pause(config={}){
|
|
2398
|
-
const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,true]));
|
|
2399
|
-
config={...all,...config};
|
|
2400
|
-
for(let key in config){
|
|
2401
|
-
if(config[key]){
|
|
2402
|
-
this.targetElement?.removeEventListener(`${this.cache.prefixe}${key}`,this.__controller[`${this.cache.prefixe}${key}`]);
|
|
2403
|
-
this.cache.paused[`${this.cache.prefixe}${key}`]=true;
|
|
2404
|
-
}
|
|
2405
|
-
}
|
|
2406
|
-
return this;
|
|
2407
|
-
}
|
|
2408
|
-
resume(config={}){
|
|
2409
|
-
const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,true]));
|
|
2410
|
-
config={...all,...config};
|
|
2411
|
-
for(let key in config){
|
|
2412
|
-
if(config[key]){
|
|
2413
|
-
this.targetElement?.addEventListener(`${this.cache.prefixe}${key}`,this.__controller[`${this.cache.prefixe}${key}`]);
|
|
2414
|
-
this.cache.paused[`${this.cache.prefixe}${key}`]=false;
|
|
2415
|
-
}
|
|
2416
|
-
}
|
|
2417
|
-
return this;
|
|
2418
|
-
}
|
|
2419
|
-
dispose(config={}){
|
|
2420
|
-
this.pause(config);
|
|
2421
|
-
return this;
|
|
2422
|
-
}
|
|
2423
|
-
stream(config={}){
|
|
2424
|
-
this.cache.stream.t0=Date.now();
|
|
2425
|
-
const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,true]));
|
|
2426
|
-
config={...all,...config};
|
|
2427
|
-
Object.assign(this.cache.stream.enabled,config);
|
|
2428
|
-
return this;
|
|
2429
|
-
}
|
|
2430
|
-
clear(config={}){
|
|
2431
|
-
const all=Object.fromEntries(Object.keys(this.cache.stream.clear).map(n=>[n,true]));
|
|
2432
|
-
config={...all,...config};
|
|
2433
|
-
for(let key in config){
|
|
2434
|
-
if(config[key]){
|
|
2435
|
-
this.cache.stream.history[key]=[];
|
|
2436
|
-
}
|
|
2437
|
-
}
|
|
2438
|
-
return this;
|
|
2439
|
-
}
|
|
2440
|
-
}
|
|
2441
|
-
|
|
2442
|
-
const custom_event_controller=event_name=>function(e){
|
|
2443
|
-
EVENT_CONTROLLER.call(this,e,event_name,null,null);
|
|
2444
|
-
};
|
|
2445
|
-
class ZikoCustomEvent extends ZikoEvent{
|
|
2446
|
-
constructor(target){
|
|
2447
|
-
super(target);
|
|
2448
|
-
this.event=null;
|
|
2449
|
-
this.cache={
|
|
2450
|
-
prefixe:"",
|
|
2451
|
-
preventDefault:{
|
|
2452
|
-
},
|
|
2453
|
-
paused:{
|
|
2454
|
-
},
|
|
2455
|
-
stream:{
|
|
2456
|
-
enabled:{
|
|
2457
|
-
},
|
|
2458
|
-
clear:{
|
|
2459
|
-
},
|
|
2460
|
-
history:{
|
|
2461
|
-
}
|
|
2462
|
-
},
|
|
2463
|
-
callbacks:{
|
|
2464
|
-
}
|
|
2465
|
-
};
|
|
2466
|
-
this.__controller={
|
|
2467
|
-
};
|
|
2468
|
-
}
|
|
2469
|
-
#init(event_name){
|
|
2470
|
-
this.cache.preventDefault[event_name]=false;
|
|
2471
|
-
this.cache.paused[event_name]=false;
|
|
2472
|
-
this.cache.stream.enabled=false;
|
|
2473
|
-
this.cache.stream.clear=false;
|
|
2474
|
-
this.cache.stream.history=[];
|
|
2475
|
-
this.cache.callbacks[event_name]=[];
|
|
2476
|
-
this.__controller[event_name]=custom_event_controller(event_name).bind(this);
|
|
2477
|
-
return this;
|
|
2478
|
-
}
|
|
2479
|
-
on(event_name,...callbacks){
|
|
2480
|
-
if(!(this.__controller[event_name]))this.#init(event_name);
|
|
2481
|
-
this.__onEvent(event_name,{},...callbacks);
|
|
2482
|
-
return this;
|
|
2483
|
-
}
|
|
2484
|
-
emit(event_name,detail={}){
|
|
2485
|
-
if(!(this.__controller[event_name]))this.#init(event_name);
|
|
2486
|
-
this.detail=detail;
|
|
2487
|
-
const event=new Event(event_name);
|
|
2488
|
-
this.targetElement.dispatchEvent(event);
|
|
2489
|
-
return this;
|
|
2490
|
-
}
|
|
2491
|
-
}
|
|
2492
|
-
const useCustomEvent=target=>new ZikoCustomEvent(target);
|
|
2459
|
+
var StyleMethods = /*#__PURE__*/Object.freeze({
|
|
2460
|
+
__proto__: null,
|
|
2461
|
+
animate: animate,
|
|
2462
|
+
hide: hide,
|
|
2463
|
+
show: show,
|
|
2464
|
+
size: size,
|
|
2465
|
+
style: style
|
|
2466
|
+
});
|
|
2493
2467
|
|
|
2494
2468
|
let UIElement$1 = class UIElement extends UIElementCore{
|
|
2495
2469
|
constructor({element, name ='', type='html', render = __Ziko__.__Config__.default.render}={}){
|
|
@@ -2498,12 +2472,15 @@ let UIElement$1 = class UIElement extends UIElementCore{
|
|
|
2498
2472
|
// console.log(this)
|
|
2499
2473
|
register_to_class(
|
|
2500
2474
|
this,
|
|
2475
|
+
LifecycleMethods,
|
|
2501
2476
|
AttrsMethods,
|
|
2502
2477
|
DomMethods,
|
|
2503
2478
|
StyleMethods,
|
|
2504
2479
|
IndexingMethods,
|
|
2505
2480
|
EventsMethodes
|
|
2506
2481
|
);
|
|
2482
|
+
|
|
2483
|
+
// console.log(EventsMethodes)
|
|
2507
2484
|
if(element)this.init(element, name, type, render);
|
|
2508
2485
|
}
|
|
2509
2486
|
get element(){
|
|
@@ -2625,32 +2602,12 @@ let UIElement$1 = class UIElement extends UIElementCore{
|
|
|
2625
2602
|
// get id() {
|
|
2626
2603
|
// return this.element.getAttribute("id");
|
|
2627
2604
|
// }
|
|
2628
|
-
// onSwipe(width_threshold, height_threshold,...callbacks){
|
|
2629
|
-
// if(!this.events.swipe)this.events.swipe = useSwipeEvent(this, width_threshold, height_threshold);
|
|
2630
|
-
// this.events.swipe.onSwipe(...callbacks);
|
|
2631
|
-
// return this;
|
|
2632
|
-
// }
|
|
2633
2605
|
// To Fix
|
|
2634
2606
|
// onKeysDown({keys=[],callback}={}){
|
|
2635
2607
|
// if(!this.events.key)this.events.key = useKeyEvent(this);
|
|
2636
2608
|
// this.events.key.handleSuccessifKeys({keys,callback});
|
|
2637
2609
|
// return this;
|
|
2638
2610
|
// }
|
|
2639
|
-
// onSelect(...callbacks){
|
|
2640
|
-
// if(!this.events.clipboard)this.events.clipboard = useClipboardEvent(this);
|
|
2641
|
-
// this.events.clipboard.onSelect(...callbacks);
|
|
2642
|
-
// return this;
|
|
2643
|
-
// }
|
|
2644
|
-
on(event_name,...callbacks){
|
|
2645
|
-
if(!this.events.custom)this.events.custom = useCustomEvent(this);
|
|
2646
|
-
this.events.custom.on(event_name,...callbacks);
|
|
2647
|
-
return this;
|
|
2648
|
-
}
|
|
2649
|
-
emit(event_name,detail={}){
|
|
2650
|
-
if(!this.events.custom)this.events.custom = useCustomEvent(this);
|
|
2651
|
-
this.events.custom.emit(event_name,detail);
|
|
2652
|
-
return this;
|
|
2653
|
-
}
|
|
2654
2611
|
// watchAttr(callback){
|
|
2655
2612
|
// if(!this.observer.attr)this.observer.attr = watchAttr(this,callback);
|
|
2656
2613
|
// return this;
|
|
@@ -2659,16 +2616,8 @@ let UIElement$1 = class UIElement extends UIElementCore{
|
|
|
2659
2616
|
// if(!this.observer.children)this.observer.children = watchChildren(this,callback);
|
|
2660
2617
|
// return this;
|
|
2661
2618
|
// }
|
|
2662
|
-
// watchSize(callback)
|
|
2663
|
-
//
|
|
2664
|
-
// this.observer.resize.start();
|
|
2665
|
-
// return this;
|
|
2666
|
-
// }
|
|
2667
|
-
// watchIntersection(callback,config){
|
|
2668
|
-
// if(!this.observer.intersection)this.observer.intersection = watchIntersection(this,callback,config);
|
|
2669
|
-
// this.observer.intersection.start();
|
|
2670
|
-
// return this;
|
|
2671
|
-
// }
|
|
2619
|
+
// watchSize(callback)Remplaced By on onViewResize
|
|
2620
|
+
// watchIntersection(callback,config) Remplaced By onViewEnter and onViewExit
|
|
2672
2621
|
|
|
2673
2622
|
};
|
|
2674
2623
|
|
|
@@ -2967,7 +2916,6 @@ class ZikoUISuspense extends UIElement{
|
|
|
2967
2916
|
const ui = await callback();
|
|
2968
2917
|
fallback_ui.unmount();
|
|
2969
2918
|
this.append(ui);
|
|
2970
|
-
// console.log(content)
|
|
2971
2919
|
}
|
|
2972
2920
|
catch(error){
|
|
2973
2921
|
console.log({error});
|
|
@@ -4598,20 +4546,6 @@ const Scheduler = (tasks, { repeat = null} = {}) => new TimeScheduler(tasks, { r
|
|
|
4598
4546
|
|
|
4599
4547
|
const step_fps = (step_or_fps) => 1000 / step_or_fps;
|
|
4600
4548
|
|
|
4601
|
-
const debounce=(fn,delay=1000)=>{
|
|
4602
|
-
let id;
|
|
4603
|
-
return (...args) => id ? clearTimeout(id) : setTimeout(()=>fn(...args),delay);
|
|
4604
|
-
};
|
|
4605
|
-
const throttle=(fn,delay)=>{
|
|
4606
|
-
let lastTime=0;
|
|
4607
|
-
return (...args) => {
|
|
4608
|
-
const now = new Date().getTime();
|
|
4609
|
-
if(now-lastTime < delay) return;
|
|
4610
|
-
lastTime = now;
|
|
4611
|
-
fn(...args);
|
|
4612
|
-
}
|
|
4613
|
-
};
|
|
4614
|
-
|
|
4615
4549
|
const sleep= ms => new Promise(res => setTimeout(res, ms));
|
|
4616
4550
|
function timeout(ms, fn) {
|
|
4617
4551
|
let id;
|
|
@@ -4784,212 +4718,7 @@ const timeTaken = callback => {
|
|
|
4784
4718
|
return r;
|
|
4785
4719
|
};
|
|
4786
4720
|
|
|
4787
|
-
|
|
4788
|
-
constructor(maxListeners = 10) {
|
|
4789
|
-
this.events = {};
|
|
4790
|
-
this.maxListeners = maxListeners;
|
|
4791
|
-
}
|
|
4792
|
-
|
|
4793
|
-
on(event, listener) {
|
|
4794
|
-
if (!this.events[event]) this.events[event] = [];
|
|
4795
|
-
this.events[event].push(listener);
|
|
4796
|
-
if (this.events[event].length > this.maxListeners) {
|
|
4797
|
-
console.warn(`Warning: Possible memory leak. Event '${event}' has more than ${this.maxListeners} listeners.`);
|
|
4798
|
-
}
|
|
4799
|
-
return this;
|
|
4800
|
-
}
|
|
4801
|
-
|
|
4802
|
-
once(event, listener) {
|
|
4803
|
-
const wrapper = (...args) => {
|
|
4804
|
-
this.off(event, wrapper);
|
|
4805
|
-
listener(...args);
|
|
4806
|
-
};
|
|
4807
|
-
return this.on(event, wrapper);
|
|
4808
|
-
}
|
|
4809
|
-
|
|
4810
|
-
off(event, listener) {
|
|
4811
|
-
const listeners = this.events[event];
|
|
4812
|
-
if (!listeners) return this;
|
|
4813
|
-
|
|
4814
|
-
const index = listeners.indexOf(listener);
|
|
4815
|
-
if (index !== -1) {
|
|
4816
|
-
listeners.splice(index, 1);
|
|
4817
|
-
}
|
|
4818
|
-
|
|
4819
|
-
return this;
|
|
4820
|
-
}
|
|
4821
|
-
|
|
4822
|
-
emit(event, data) {
|
|
4823
|
-
const listeners = this.events[event];
|
|
4824
|
-
if (!listeners) return false;
|
|
4825
|
-
|
|
4826
|
-
// Make a copy so removing listeners inside callbacks doesn't affect iteration
|
|
4827
|
-
[...listeners].forEach(listener => {
|
|
4828
|
-
try {
|
|
4829
|
-
listener(data);
|
|
4830
|
-
} catch (e) {
|
|
4831
|
-
console.error(`Error in listener for '${event}':`, e);
|
|
4832
|
-
}
|
|
4833
|
-
});
|
|
4834
|
-
|
|
4835
|
-
return true;
|
|
4836
|
-
}
|
|
4837
|
-
remove(event){
|
|
4838
|
-
delete this.events[event];
|
|
4839
|
-
return this;
|
|
4840
|
-
}
|
|
4841
|
-
clear() {
|
|
4842
|
-
this.events = {};
|
|
4843
|
-
return this;
|
|
4844
|
-
}
|
|
4845
|
-
|
|
4846
|
-
setMaxListeners(max) {
|
|
4847
|
-
this.maxListeners = max;
|
|
4848
|
-
return this;
|
|
4849
|
-
}
|
|
4850
|
-
}
|
|
4851
|
-
|
|
4852
|
-
const useEventEmitter = (maxListeners) => new UseEventEmitter(maxListeners);
|
|
4853
|
-
|
|
4854
|
-
class ZikoUseFavIcon{
|
|
4855
|
-
constructor(FavIcon,withEmitter=true){
|
|
4856
|
-
this.#init();
|
|
4857
|
-
this.cache={
|
|
4858
|
-
Emitter:null
|
|
4859
|
-
};
|
|
4860
|
-
if(withEmitter)this.useEventEmitter();
|
|
4861
|
-
this.set(FavIcon);
|
|
4862
|
-
}
|
|
4863
|
-
#init(){
|
|
4864
|
-
this.__FavIcon__ = document.querySelector("link[rel*='icon']") || document?.createElement('link');
|
|
4865
|
-
this.__FavIcon__.type = 'image/x-icon';
|
|
4866
|
-
this.__FavIcon__.rel = 'shortcut icon';
|
|
4867
|
-
return this;
|
|
4868
|
-
}
|
|
4869
|
-
set(href){
|
|
4870
|
-
if(href!==this.__FavIcon__.href){
|
|
4871
|
-
this.__FavIcon__.href=href;
|
|
4872
|
-
if(this.cache.Emitter)this.cache.Emitter.emit("ziko:favicon-changed");
|
|
4873
|
-
}
|
|
4874
|
-
return this;
|
|
4875
|
-
}
|
|
4876
|
-
get current(){
|
|
4877
|
-
return document.__FavIcon__.href;
|
|
4878
|
-
}
|
|
4879
|
-
onChange(callback){
|
|
4880
|
-
if(this.cache.Emitter)this.cache.Emitter.on("ziko:favicon-changed",callback);
|
|
4881
|
-
return this;
|
|
4882
|
-
}
|
|
4883
|
-
useEventEmitter(){
|
|
4884
|
-
this.cache.Emitter=useEventEmitter();
|
|
4885
|
-
return this;
|
|
4886
|
-
}
|
|
4887
|
-
|
|
4888
|
-
}
|
|
4889
|
-
const useFavIcon=(FavIcon,withEmitter)=>new ZikoUseFavIcon(FavIcon,withEmitter);
|
|
4890
|
-
|
|
4891
|
-
class ZikoMeta{
|
|
4892
|
-
constructor({viewport,charset,description,author,keywords}){
|
|
4893
|
-
this.document = globalThis?.document;
|
|
4894
|
-
this.meta={};
|
|
4895
|
-
this.init({viewport,charset,description,author,keywords});
|
|
4896
|
-
}
|
|
4897
|
-
init({viewport,charset,description,author,keywords}){
|
|
4898
|
-
viewport && this.setViewport(viewport);
|
|
4899
|
-
charset && this.setCharset(charset);
|
|
4900
|
-
description && this.describe(description);
|
|
4901
|
-
author && this.setAuthor(author);
|
|
4902
|
-
keywords && this.setKeywords(keywords);
|
|
4903
|
-
}
|
|
4904
|
-
set(key,value){
|
|
4905
|
-
key = key.toLowerCase();
|
|
4906
|
-
const isCharset = (key === "charset");
|
|
4907
|
-
const meta = isCharset ? document.querySelector("meta[charset]"):document.querySelector(`meta[name=${key}]`);
|
|
4908
|
-
this.meta=meta?? document?.createElement("meta");
|
|
4909
|
-
if(isCharset) this.meta.setAttribute("charset",value);
|
|
4910
|
-
else {
|
|
4911
|
-
this.meta.setAttribute("name",key);
|
|
4912
|
-
this.meta.setAttribute("content",value);
|
|
4913
|
-
}
|
|
4914
|
-
if(!meta)this.document.head.append(this.meta);
|
|
4915
|
-
return this;
|
|
4916
|
-
}
|
|
4917
|
-
setCharset(charset="utf-8"){
|
|
4918
|
-
this.set("charset",charset);
|
|
4919
|
-
return this;
|
|
4920
|
-
}
|
|
4921
|
-
describe(description){
|
|
4922
|
-
this.set("description",description);
|
|
4923
|
-
return this;
|
|
4924
|
-
}
|
|
4925
|
-
setViewport(viewport="width=device-width, initial-scale=1.0"){
|
|
4926
|
-
this.set("viewport",viewport);
|
|
4927
|
-
return this;
|
|
4928
|
-
}
|
|
4929
|
-
setKeywords(...keywords){
|
|
4930
|
-
// keywords.push("zikojs");
|
|
4931
|
-
keywords=[...new Set(keywords)].join(", ");
|
|
4932
|
-
this.set("keywords",keywords);
|
|
4933
|
-
return this;
|
|
4934
|
-
}
|
|
4935
|
-
setAuthor(author){
|
|
4936
|
-
this.set("author",author);
|
|
4937
|
-
return this;
|
|
4938
|
-
}
|
|
4939
|
-
}
|
|
4940
|
-
const useMeta=({viewport,charset,description,author,keywords})=>new ZikoMeta({viewport,charset,description,author,keywords});
|
|
4941
|
-
|
|
4942
|
-
class ZikoUseTitle{
|
|
4943
|
-
constructor(title=document.title,useEventEmitter=true){
|
|
4944
|
-
this.cache={
|
|
4945
|
-
Emitter:null
|
|
4946
|
-
};
|
|
4947
|
-
if(useEventEmitter)this.useEventEmitter();
|
|
4948
|
-
this.set(title);
|
|
4949
|
-
}
|
|
4950
|
-
useEventEmitter(){
|
|
4951
|
-
this.cache.Emitter=useEventEmitter();
|
|
4952
|
-
return this;
|
|
4953
|
-
}
|
|
4954
|
-
set(title){
|
|
4955
|
-
if(title!==document.title){
|
|
4956
|
-
document.title=title;
|
|
4957
|
-
if(this.cache.Emitter)this.cache.Emitter.emit("ziko:title-changed");
|
|
4958
|
-
}
|
|
4959
|
-
return this;
|
|
4960
|
-
}
|
|
4961
|
-
get current(){
|
|
4962
|
-
return document.title;
|
|
4963
|
-
}
|
|
4964
|
-
onChange(callback){
|
|
4965
|
-
if(this.cache.Emitter)this.cache.Emitter.on("ziko:title-changed",callback);
|
|
4966
|
-
return this;
|
|
4967
|
-
}
|
|
4968
|
-
}
|
|
4969
|
-
const useTitle$1=(title, useEventEmitter)=>new ZikoUseTitle(title, useEventEmitter);
|
|
4970
|
-
|
|
4971
|
-
// import {useLink} from "./";
|
|
4972
|
-
class ZikoHead{
|
|
4973
|
-
constructor({title,lang,icon,meta,noscript}){
|
|
4974
|
-
this.html = globalThis?.document?.documentElement;
|
|
4975
|
-
this.head = globalThis?.document?.head;
|
|
4976
|
-
|
|
4977
|
-
title && useTitle$1(title);
|
|
4978
|
-
lang && this.setLang(lang);
|
|
4979
|
-
icon && useFavIcon(icon);
|
|
4980
|
-
meta && useMeta(meta);
|
|
4981
|
-
noscript && this.setNoScript();
|
|
4982
|
-
}
|
|
4983
|
-
setLang(lang){
|
|
4984
|
-
this.html.setAttribute("lang",lang);
|
|
4985
|
-
}
|
|
4986
|
-
setNoScript(content){
|
|
4987
|
-
|
|
4988
|
-
}
|
|
4989
|
-
}
|
|
4990
|
-
|
|
4991
|
-
const useHead=({ title, lang, icon, meta, noscript })=>new ZikoHead({ title, lang, icon, meta, noscript });
|
|
4992
|
-
|
|
4721
|
+
// import { ZikoHead , useHead} from "../reactivity/hooks/head/index.js";
|
|
4993
4722
|
class ZikoApp {
|
|
4994
4723
|
constructor({head = null, wrapper = null, target = null}){
|
|
4995
4724
|
this.head = head;
|
|
@@ -5016,11 +4745,11 @@ class ZikoApp {
|
|
|
5016
4745
|
else if(typeof wrapper === "function") this.wrapper = wrapper();
|
|
5017
4746
|
return this;
|
|
5018
4747
|
}
|
|
5019
|
-
setHead(head){
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
}
|
|
4748
|
+
// setHead(head){
|
|
4749
|
+
// if(head instanceof ZikoHead) this.head = head;
|
|
4750
|
+
// else this.head = useHead(head);
|
|
4751
|
+
// return this;
|
|
4752
|
+
// }
|
|
5024
4753
|
|
|
5025
4754
|
}
|
|
5026
4755
|
const App = ({head, wrapper, target}) => new ZikoApp({head, wrapper, target});
|
|
@@ -5290,7 +5019,76 @@ class UseThread {
|
|
|
5290
5019
|
terminate() {
|
|
5291
5020
|
this.#worker.terminate();
|
|
5292
5021
|
}
|
|
5293
|
-
}
|
|
5022
|
+
}
|
|
5023
|
+
|
|
5024
|
+
const useThread = (func, callback, args = [], close = true) => new UseThread().call(func, callback, args, close);
|
|
5025
|
+
|
|
5026
|
+
class UseEventEmitter {
|
|
5027
|
+
constructor(maxListeners = 10) {
|
|
5028
|
+
this.events = {};
|
|
5029
|
+
this.maxListeners = maxListeners;
|
|
5030
|
+
}
|
|
5031
|
+
|
|
5032
|
+
on(event, listener) {
|
|
5033
|
+
if (!this.events[event]) this.events[event] = [];
|
|
5034
|
+
this.events[event].push(listener);
|
|
5035
|
+
if (this.events[event].length > this.maxListeners) {
|
|
5036
|
+
console.warn(`Warning: Possible memory leak. Event '${event}' has more than ${this.maxListeners} listeners.`);
|
|
5037
|
+
}
|
|
5038
|
+
return this;
|
|
5039
|
+
}
|
|
5040
|
+
|
|
5041
|
+
once(event, listener) {
|
|
5042
|
+
const wrapper = (...args) => {
|
|
5043
|
+
this.off(event, wrapper);
|
|
5044
|
+
listener(...args);
|
|
5045
|
+
};
|
|
5046
|
+
return this.on(event, wrapper);
|
|
5047
|
+
}
|
|
5048
|
+
|
|
5049
|
+
off(event, listener) {
|
|
5050
|
+
const listeners = this.events[event];
|
|
5051
|
+
if (!listeners) return this;
|
|
5052
|
+
|
|
5053
|
+
const index = listeners.indexOf(listener);
|
|
5054
|
+
if (index !== -1) {
|
|
5055
|
+
listeners.splice(index, 1);
|
|
5056
|
+
}
|
|
5057
|
+
|
|
5058
|
+
return this;
|
|
5059
|
+
}
|
|
5060
|
+
|
|
5061
|
+
emit(event, data) {
|
|
5062
|
+
const listeners = this.events[event];
|
|
5063
|
+
if (!listeners) return false;
|
|
5064
|
+
|
|
5065
|
+
// Make a copy so removing listeners inside callbacks doesn't affect iteration
|
|
5066
|
+
[...listeners].forEach(listener => {
|
|
5067
|
+
try {
|
|
5068
|
+
listener(data);
|
|
5069
|
+
} catch (e) {
|
|
5070
|
+
console.error(`Error in listener for '${event}':`, e);
|
|
5071
|
+
}
|
|
5072
|
+
});
|
|
5073
|
+
|
|
5074
|
+
return true;
|
|
5075
|
+
}
|
|
5076
|
+
remove(event){
|
|
5077
|
+
delete this.events[event];
|
|
5078
|
+
return this;
|
|
5079
|
+
}
|
|
5080
|
+
clear() {
|
|
5081
|
+
this.events = {};
|
|
5082
|
+
return this;
|
|
5083
|
+
}
|
|
5084
|
+
|
|
5085
|
+
setMaxListeners(max) {
|
|
5086
|
+
this.maxListeners = max;
|
|
5087
|
+
return this;
|
|
5088
|
+
}
|
|
5089
|
+
}
|
|
5090
|
+
|
|
5091
|
+
const useEventEmitter = (maxListeners) => new UseEventEmitter(maxListeners);
|
|
5294
5092
|
|
|
5295
5093
|
/*
|
|
5296
5094
|
[
|
|
@@ -5390,6 +5188,75 @@ class UseTitle {
|
|
|
5390
5188
|
|
|
5391
5189
|
const useTitle = (title, withEmitter = true) => new UseTitle(title, withEmitter);
|
|
5392
5190
|
|
|
5191
|
+
class UseRoot {
|
|
5192
|
+
constructor(PropsMap, { namespace = 'Ziko', ValidateCssProps = false } = {}) {
|
|
5193
|
+
this.currentPropsMap = PropsMap;
|
|
5194
|
+
this.namespace = namespace;
|
|
5195
|
+
this.ValidateCssProps = ValidateCssProps;
|
|
5196
|
+
this.use(PropsMap);
|
|
5197
|
+
}
|
|
5198
|
+
|
|
5199
|
+
use(PropsMap) {
|
|
5200
|
+
if (this.ValidateCssProps) ValidateCssPropsFn(PropsMap);
|
|
5201
|
+
this.currentPropsMap = PropsMap;
|
|
5202
|
+
this.#maintain();
|
|
5203
|
+
return this;
|
|
5204
|
+
}
|
|
5205
|
+
|
|
5206
|
+
#maintain() {
|
|
5207
|
+
const root = globalThis?.document?.documentElement?.style;
|
|
5208
|
+
for (const prop in this.currentPropsMap) {
|
|
5209
|
+
const cssProp = this.namespace ? `--${this.namespace}-${prop}` : `--${prop}`;
|
|
5210
|
+
root.setProperty(cssProp, this.currentPropsMap[prop]);
|
|
5211
|
+
|
|
5212
|
+
Object.defineProperty(this, prop, {
|
|
5213
|
+
value: `var(${cssProp})`,
|
|
5214
|
+
writable: true,
|
|
5215
|
+
configurable: true,
|
|
5216
|
+
enumerable: false
|
|
5217
|
+
});
|
|
5218
|
+
}
|
|
5219
|
+
}
|
|
5220
|
+
}
|
|
5221
|
+
|
|
5222
|
+
function ValidateCssPropsFn(PropsMap) {
|
|
5223
|
+
const validProps = new Set(Object.keys(document.documentElement.style));
|
|
5224
|
+
for (const key in PropsMap) {
|
|
5225
|
+
if (!validProps.has(key)) {
|
|
5226
|
+
throw new Error(`Invalid CSS property: "${key}"`);
|
|
5227
|
+
}
|
|
5228
|
+
}
|
|
5229
|
+
}
|
|
5230
|
+
|
|
5231
|
+
const useRoot = (PropsMap, options = {}) => new UseRoot(PropsMap, options);
|
|
5232
|
+
|
|
5233
|
+
|
|
5234
|
+
// Usage
|
|
5235
|
+
|
|
5236
|
+
/*
|
|
5237
|
+
const Styles = {
|
|
5238
|
+
S1 : {
|
|
5239
|
+
background : 'white',
|
|
5240
|
+
color : 'darkblue'
|
|
5241
|
+
border : '2px darkblue solid"'
|
|
5242
|
+
},
|
|
5243
|
+
S2 : {
|
|
5244
|
+
background : 'darkblue',
|
|
5245
|
+
color : 'white'
|
|
5246
|
+
border : '2px green solid"'
|
|
5247
|
+
}
|
|
5248
|
+
}
|
|
5249
|
+
const {use, border, background, color} = useRoot(Style.S1)
|
|
5250
|
+
|
|
5251
|
+
tags.p("Test useRoot ").style({
|
|
5252
|
+
border,
|
|
5253
|
+
color,
|
|
5254
|
+
background,
|
|
5255
|
+
padding : '10px'
|
|
5256
|
+
})
|
|
5257
|
+
|
|
5258
|
+
*/
|
|
5259
|
+
|
|
5393
5260
|
let {sqrt, cos, sin, exp, log, cosh, sinh} = Math;
|
|
5394
5261
|
// Math.abs = new Proxy(Math.abs, {
|
|
5395
5262
|
// apply(target, thisArg, args) {
|
|
@@ -5483,11 +5350,12 @@ exports.UINode = UINode;
|
|
|
5483
5350
|
exports.UISVGWrapper = UISVGWrapper;
|
|
5484
5351
|
exports.UISwitch = UISwitch;
|
|
5485
5352
|
exports.UIView = UIView;
|
|
5353
|
+
exports.UseRoot = UseRoot;
|
|
5486
5354
|
exports.UseThread = UseThread;
|
|
5487
5355
|
exports.Utils = Utils;
|
|
5488
5356
|
exports.View = View;
|
|
5489
5357
|
exports.ZikoApp = ZikoApp;
|
|
5490
|
-
exports.ZikoEvent = ZikoEvent
|
|
5358
|
+
exports.ZikoEvent = ZikoEvent;
|
|
5491
5359
|
exports.ZikoSPA = ZikoSPA;
|
|
5492
5360
|
exports.ZikoUIFlex = ZikoUIFlex;
|
|
5493
5361
|
exports.ZikoUISuspense = ZikoUISuspense;
|
|
@@ -5515,7 +5383,9 @@ exports.bind_focus_event = bind_focus_event;
|
|
|
5515
5383
|
exports.bind_key_event = bind_key_event;
|
|
5516
5384
|
exports.bind_mouse_event = bind_mouse_event;
|
|
5517
5385
|
exports.bind_pointer_event = bind_pointer_event;
|
|
5386
|
+
exports.bind_swipe_event = bind_swipe_event;
|
|
5518
5387
|
exports.bind_touch_event = bind_touch_event;
|
|
5388
|
+
exports.bind_view_event = bind_view_event;
|
|
5519
5389
|
exports.bind_wheel_event = bind_wheel_event;
|
|
5520
5390
|
exports.cartesianProduct = cartesianProduct;
|
|
5521
5391
|
exports.ceil = ceil;
|
|
@@ -5541,6 +5411,7 @@ exports.discret = discret;
|
|
|
5541
5411
|
exports.div = div;
|
|
5542
5412
|
exports.e = e;
|
|
5543
5413
|
exports.elastic = elastic;
|
|
5414
|
+
exports.event_controller = event_controller;
|
|
5544
5415
|
exports.fact = fact;
|
|
5545
5416
|
exports.floor = floor;
|
|
5546
5417
|
exports.geomspace = geomspace;
|
|
@@ -5642,14 +5513,17 @@ exports.tick = tick;
|
|
|
5642
5513
|
exports.timeTaken = timeTaken;
|
|
5643
5514
|
exports.time_memory_Taken = time_memory_Taken;
|
|
5644
5515
|
exports.timeout = timeout;
|
|
5516
|
+
exports.toggle_event_listener = toggle_event_listener;
|
|
5645
5517
|
exports.useDerived = useDerived;
|
|
5646
5518
|
exports.useEventEmitter = useEventEmitter;
|
|
5647
5519
|
exports.useIPC = useIPC;
|
|
5648
5520
|
exports.useLocaleStorage = useLocaleStorage;
|
|
5649
5521
|
exports.useMediaQuery = useMediaQuery;
|
|
5650
5522
|
exports.useReactive = useReactive;
|
|
5523
|
+
exports.useRoot = useRoot;
|
|
5651
5524
|
exports.useSessionStorage = useSessionStorage;
|
|
5652
5525
|
exports.useState = useState;
|
|
5526
|
+
exports.useThread = useThread;
|
|
5653
5527
|
exports.useTitle = useTitle;
|
|
5654
5528
|
exports.wait = wait;
|
|
5655
5529
|
exports.waitForUIElm = waitForUIElm;
|