ziko 0.49.7 → 0.50.2
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 +817 -976
- package/dist/ziko.js +817 -976
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +808 -961
- package/package.json +4 -1
- package/src/{reactivity → --reactivity-deprecated}/hooks/index.js +3 -3
- package/src/{reactivity → --reactivity-deprecated}/index.js +1 -1
- package/src/__ziko__/__state__.js +1 -1
- package/src/app/ziko-app.js +6 -6
- package/src/data/api/fetchdom.js +27 -11
- package/src/events/binders/custom-event.js +12 -8
- package/src/events/binders/index.js +97 -13
- package/src/events/custom-events-registry/index.js +3 -0
- package/src/events/custom-events-registry/swipe.js +76 -0
- package/src/events/custom-events-registry/view.js +74 -0
- package/src/events/details-setter/index.js +2 -0
- package/src/events/details-setter/key.js +14 -0
- package/src/events/{binders → details-setter}/pointer.js +1 -15
- package/src/events/{__Events__.js → events-map/index.js} +16 -4
- package/src/events/index.js +1 -1
- package/src/events/types/__Shared__.d.ts +3 -3
- package/src/events/types/clipboard.d.ts +2 -2
- package/src/events/types/focus.d.ts +2 -2
- package/src/events/types/pointer.d.ts +2 -2
- package/src/events/utils.js +31 -0
- package/src/events/ziko-event.js +108 -0
- package/src/hooks/index.js +1 -1
- package/src/hooks/{use-channel.js → use-ipc.js} +3 -3
- package/src/hooks/use-storage.js +2 -2
- package/src/index.js +1 -1
- package/src/ui/__methods__/dom.js +0 -20
- package/src/ui/__methods__/events.js +26 -8
- package/src/ui/__methods__/index.js +3 -0
- package/src/ui/__methods__/lifecycle.js +54 -0
- package/src/ui/constructors/UIElement.js +8 -32
- package/src/ui/constructors/UIElementCore.js +3 -136
- 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/hooks/index.d.ts +1 -1
- package/types/hooks/{use-channel.d.ts → use-ipc.d.ts} +2 -2
- package/types/index.d.ts +2 -1
- package/src/events/__ZikoEvent__.js +0 -165
- package/src/events/binders/click.js +0 -20
- package/src/events/binders/clipboard.js +0 -16
- package/src/events/binders/drag.js +0 -16
- package/src/events/binders/focus.js +0 -16
- package/src/events/binders/hash.js +0 -16
- package/src/events/binders/key.js +0 -27
- package/src/events/binders/mouse.js +0 -16
- package/src/events/binders/touch.js +0 -16
- package/src/events/binders/wheel.js +0 -16
- package/src/events/custom-events/index.js +0 -1
- package/src/events/custom-events/swipe.js +0 -58
- package/src/events/custom-events/view.js +0 -43
- package/src/events/index.d.ts.txt +0 -3
- /package/src/{reactivity → --reactivity-deprecated}/events/Input.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/events/ZikoEvent.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/events/__note__ +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/events/custom-event.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/events/hash.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/events/index.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/events/media.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/events/mouse.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/events/swipe.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/events/touch.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/Contexte/index.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/Contexte/useSuccesifKeys.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/UI/index.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/UI/useCssLink.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/UI/useLinearGradient.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/UI/useMediaQuery.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/UI/useRadialGradient.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/UI/useRoot.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/UI/useStyle.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/UI/useTheme.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/head/_useCssText.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/head/index.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/head/useFavIcon.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/head/useHead.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/head/useMeta.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/head/useTitle.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/todo.md +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/idea +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/observer/attributes.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/observer/children.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/observer/index.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/observer/intersection.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/observer/mutation.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/observer/resize.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/observer/screen.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/observer/screen.js.txt +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/observer/screen.txt +0 -0
- /package/src/{use → --use-deprecated}/index.js +0 -0
- /package/src/{use → --use-deprecated}/use-channel.js.txt +0 -0
- /package/src/{use → --use-deprecated}/use-event-emmiter.js.txt +0 -0
- /package/src/{use → --use-deprecated}/use-favicon.js +0 -0
- /package/src/{use → --use-deprecated}/use-link.js +0 -0
- /package/src/{use → --use-deprecated}/use-meta.js +0 -0
- /package/src/{use → --use-deprecated}/use-root.js +0 -0
- /package/src/{use → --use-deprecated}/use-storage.js.txt +0 -0
- /package/src/{use → --use-deprecated}/use-thread.js +0 -0
- /package/src/{use → --use-deprecated}/use-title.js +0 -0
- /package/src/events/{custom-events → custom-events-registry}/click-away.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 :
|
|
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
|
|
@@ -949,16 +949,28 @@
|
|
|
949
949
|
}
|
|
950
950
|
};
|
|
951
951
|
|
|
952
|
-
async function fetchdom(url='https://github.com/zakarialaoui10'){
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
952
|
+
async function fetchdom(url='https://github.com/zakarialaoui10') {
|
|
953
|
+
try {
|
|
954
|
+
const response = await fetch(url);
|
|
955
|
+
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
|
956
|
+
const html = await response.text();
|
|
957
|
+
const dom = new DOMParser().parseFromString(html, 'text/html');
|
|
958
|
+
return dom.documentElement;
|
|
959
|
+
} catch (err) {
|
|
960
|
+
console.error('Failed to fetch DOM:', err);
|
|
961
|
+
throw err;
|
|
962
|
+
}
|
|
957
963
|
}
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
964
|
+
|
|
965
|
+
function fetchdomSync(url='https://github.com/zakarialaoui10') {
|
|
966
|
+
try {
|
|
967
|
+
const data = preload(url);
|
|
968
|
+
const dom = new DOMParser().parseFromString(data, 'text/html');
|
|
969
|
+
return dom.documentElement;
|
|
970
|
+
} catch (err) {
|
|
971
|
+
console.error('Failed to fetch DOM synchronously:', err);
|
|
972
|
+
throw err;
|
|
973
|
+
}
|
|
962
974
|
}
|
|
963
975
|
|
|
964
976
|
globalThis.fetchdom=fetchdom;
|
|
@@ -1078,35 +1090,6 @@
|
|
|
1078
1090
|
|
|
1079
1091
|
// globalThis.node = (node) => new UINode(node);
|
|
1080
1092
|
|
|
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
1093
|
class UIStore extends Array {
|
|
1111
1094
|
constructor(...args) {
|
|
1112
1095
|
super(...args);
|
|
@@ -1140,6 +1123,202 @@
|
|
|
1140
1123
|
// create the singleton
|
|
1141
1124
|
const __UI__ = new UIStore();
|
|
1142
1125
|
|
|
1126
|
+
// __init__global__()
|
|
1127
|
+
class UIElementCore extends UINode{
|
|
1128
|
+
constructor(){
|
|
1129
|
+
super();
|
|
1130
|
+
}
|
|
1131
|
+
init(element, name, type, render){
|
|
1132
|
+
this.target = globalThis.__Ziko__.__Config__.default.target||globalThis?.document?.body;
|
|
1133
|
+
if(typeof element === "string") {
|
|
1134
|
+
switch(type){
|
|
1135
|
+
case "html" : {
|
|
1136
|
+
element = globalThis?.document?.createElement(element);
|
|
1137
|
+
// console.log('1')
|
|
1138
|
+
} break;
|
|
1139
|
+
case "svg" : {
|
|
1140
|
+
element = globalThis?.document?.createElementNS("http://www.w3.org/2000/svg", element);
|
|
1141
|
+
// console.log('2')
|
|
1142
|
+
} break;
|
|
1143
|
+
default : throw Error("Not supported")
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
else this.target = element?.parentElement;
|
|
1147
|
+
Object.assign(this.cache, {
|
|
1148
|
+
name,
|
|
1149
|
+
isInteractive : false,
|
|
1150
|
+
parent:null,
|
|
1151
|
+
isBody:false,
|
|
1152
|
+
isRoot:false,
|
|
1153
|
+
isHidden: false,
|
|
1154
|
+
isFrozzen:false,
|
|
1155
|
+
legacyParent : null,
|
|
1156
|
+
attributes: {},
|
|
1157
|
+
filters: {},
|
|
1158
|
+
temp:{}
|
|
1159
|
+
});
|
|
1160
|
+
this.events = {
|
|
1161
|
+
ptr:null,
|
|
1162
|
+
mouse:null,
|
|
1163
|
+
wheel:null,
|
|
1164
|
+
key:null,
|
|
1165
|
+
drag:null,
|
|
1166
|
+
drop:null,
|
|
1167
|
+
click:null,
|
|
1168
|
+
clipboard:null,
|
|
1169
|
+
focus:null,
|
|
1170
|
+
swipe:null,
|
|
1171
|
+
custom:null,
|
|
1172
|
+
};
|
|
1173
|
+
this.observer={
|
|
1174
|
+
resize:null,
|
|
1175
|
+
intersection:null
|
|
1176
|
+
};
|
|
1177
|
+
if(element) Object.assign(this.cache,{element});
|
|
1178
|
+
// useDefaultStyle && this.style({
|
|
1179
|
+
// position: "relative",
|
|
1180
|
+
// boxSizing:"border-box",
|
|
1181
|
+
// margin:0,
|
|
1182
|
+
// padding:0,
|
|
1183
|
+
// width : "auto",
|
|
1184
|
+
// height : "auto"
|
|
1185
|
+
// });
|
|
1186
|
+
this.items = new UIStore();
|
|
1187
|
+
globalThis.__Ziko__.__UI__[this.cache.name]?globalThis.__Ziko__.__UI__[this.cache.name]?.push(this):globalThis.__Ziko__.__UI__[this.cache.name]=[this];
|
|
1188
|
+
element && render && this?.render?.();
|
|
1189
|
+
globalThis.__Ziko__.__UI__.push(this);
|
|
1190
|
+
}
|
|
1191
|
+
get element(){
|
|
1192
|
+
return this.cache.element;
|
|
1193
|
+
}
|
|
1194
|
+
[Symbol.iterator]() {
|
|
1195
|
+
return this.items[Symbol.iterator]();
|
|
1196
|
+
}
|
|
1197
|
+
maintain() {
|
|
1198
|
+
for (let i = 0; i < this.items.length; i++) {
|
|
1199
|
+
Object.defineProperty(this, i, {
|
|
1200
|
+
value: this.items[i],
|
|
1201
|
+
writable: true,
|
|
1202
|
+
configurable: true,
|
|
1203
|
+
enumerable: false
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
isInteractive(){
|
|
1208
|
+
return this.cache.isInteractive;
|
|
1209
|
+
}
|
|
1210
|
+
isUIElement(){
|
|
1211
|
+
return true;
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
function register_to_class(target, ...mixins){
|
|
1216
|
+
mixins.forEach(n => _register_to_class_(target, n));
|
|
1217
|
+
}
|
|
1218
|
+
function _register_to_class_(target, mixin) {
|
|
1219
|
+
const descriptors = Object.getOwnPropertyDescriptors(mixin);
|
|
1220
|
+
for (const key of Reflect.ownKeys(descriptors)) {
|
|
1221
|
+
const desc = descriptors[key];
|
|
1222
|
+
if ('get' in desc || 'set' in desc || typeof desc.value !== 'function') {
|
|
1223
|
+
Object.defineProperty(Object.getPrototypeOf(target), key, desc);
|
|
1224
|
+
} else if (typeof desc.value === 'function') {
|
|
1225
|
+
if (!Object.getPrototypeOf(target).hasOwnProperty(key)) {
|
|
1226
|
+
Object.defineProperty(Object.getPrototypeOf(target), key, desc);
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
// export function mount(target = this.target) {
|
|
1233
|
+
// if(this.isBody) return ;
|
|
1234
|
+
// if(target?.isUIElement)target=target.element;
|
|
1235
|
+
// this.target=target;
|
|
1236
|
+
// this.target?.appendChild(this.element);
|
|
1237
|
+
// return this;
|
|
1238
|
+
// }
|
|
1239
|
+
// export function unmount(){
|
|
1240
|
+
// if(this.cache.parent)this.cache.parent.remove(this);
|
|
1241
|
+
// else if(this.target?.children?.length && [...this.target?.children].includes(this.element)) this.target.removeChild(this.element);
|
|
1242
|
+
// return this;
|
|
1243
|
+
// }
|
|
1244
|
+
|
|
1245
|
+
// export function mountAfter(target = this.target, t = 1) {
|
|
1246
|
+
// setTimeout(() => this.mount(), t);
|
|
1247
|
+
// return this;
|
|
1248
|
+
// }
|
|
1249
|
+
// export function unmountAfter(t = 1) {
|
|
1250
|
+
// setTimeout(() => this.unmount(), t);
|
|
1251
|
+
// return this;
|
|
1252
|
+
// }
|
|
1253
|
+
|
|
1254
|
+
function mount(target = this.target, delay = 0) {
|
|
1255
|
+
if (delay > 0) {
|
|
1256
|
+
setTimeout(() => this.mount(target, 0), delay);
|
|
1257
|
+
return this;
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
if (this.isBody) return this;
|
|
1261
|
+
|
|
1262
|
+
if (target?.isUIElement) target = target.element;
|
|
1263
|
+
this.target = target;
|
|
1264
|
+
|
|
1265
|
+
this.target?.appendChild(this.element);
|
|
1266
|
+
return this;
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
function unmount(delay = 0) {
|
|
1270
|
+
if (delay > 0) {
|
|
1271
|
+
setTimeout(() => this.unmount(0), delay);
|
|
1272
|
+
return this;
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
if (this.cache.parent) {
|
|
1276
|
+
this.cache.parent.remove(this);
|
|
1277
|
+
} else if (
|
|
1278
|
+
this.target?.children?.length &&
|
|
1279
|
+
[...this.target.children].includes(this.element)
|
|
1280
|
+
) {
|
|
1281
|
+
this.target.removeChild(this.element);
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
return this;
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
var LifecycleMethods = /*#__PURE__*/Object.freeze({
|
|
1288
|
+
__proto__: null,
|
|
1289
|
+
mount: mount,
|
|
1290
|
+
unmount: unmount
|
|
1291
|
+
});
|
|
1292
|
+
|
|
1293
|
+
function parseQueryParams$1(queryString) {
|
|
1294
|
+
const params = {};
|
|
1295
|
+
queryString.replace(/[A-Z0-9]+?=([\w|:|\/\.]*)/gi, (match) => {
|
|
1296
|
+
const [key, value] = match.split('=');
|
|
1297
|
+
params[key] = value;
|
|
1298
|
+
});
|
|
1299
|
+
return params;
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
function defineParamsGetter$1(target ){
|
|
1303
|
+
Object.defineProperties(target, {
|
|
1304
|
+
'QueryParams': {
|
|
1305
|
+
get: function() {
|
|
1306
|
+
return parseQueryParams$1(globalThis.location.search.substring(1));
|
|
1307
|
+
},
|
|
1308
|
+
configurable: false,
|
|
1309
|
+
enumerable: true
|
|
1310
|
+
},
|
|
1311
|
+
'HashParams': {
|
|
1312
|
+
get: function() {
|
|
1313
|
+
const hash = globalThis.location.hash.substring(1);
|
|
1314
|
+
return hash.split("#");
|
|
1315
|
+
},
|
|
1316
|
+
configurable: false,
|
|
1317
|
+
enumerable: true
|
|
1318
|
+
}
|
|
1319
|
+
});
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1143
1322
|
const __Config__ = {
|
|
1144
1323
|
default:{
|
|
1145
1324
|
target:null,
|
|
@@ -1183,7 +1362,7 @@
|
|
|
1183
1362
|
}
|
|
1184
1363
|
};
|
|
1185
1364
|
|
|
1186
|
-
class
|
|
1365
|
+
class UseIPC {
|
|
1187
1366
|
#channel;
|
|
1188
1367
|
#eventData;
|
|
1189
1368
|
#handlers;
|
|
@@ -1264,14 +1443,14 @@
|
|
|
1264
1443
|
}
|
|
1265
1444
|
}
|
|
1266
1445
|
|
|
1267
|
-
const
|
|
1446
|
+
const useIPC = (name) => new UseIPC(name);
|
|
1268
1447
|
|
|
1269
1448
|
class UseStorage {
|
|
1270
1449
|
constructor(storage, globalKey, initialValue, use_channel = true) {
|
|
1271
1450
|
this.cache = {
|
|
1272
1451
|
storage,
|
|
1273
1452
|
globalKey,
|
|
1274
|
-
channel: use_channel ?
|
|
1453
|
+
channel: use_channel ? useIPC(`Ziko:useStorage-${globalKey}`) : null,
|
|
1275
1454
|
oldItemKeys: new Set()
|
|
1276
1455
|
};
|
|
1277
1456
|
|
|
@@ -1359,7 +1538,7 @@
|
|
|
1359
1538
|
const useSessionStorage = (key, initialValue, use_channel = true) =>
|
|
1360
1539
|
new UseStorage(sessionStorage, key, initialValue, use_channel);
|
|
1361
1540
|
|
|
1362
|
-
|
|
1541
|
+
var __State__ = {
|
|
1363
1542
|
store : new Map(),
|
|
1364
1543
|
index : 0,
|
|
1365
1544
|
session_storage : null,
|
|
@@ -1393,255 +1572,15 @@
|
|
|
1393
1572
|
}
|
|
1394
1573
|
}
|
|
1395
1574
|
|
|
1396
|
-
__init__global__();
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
case "html" : {
|
|
1406
|
-
element = globalThis?.document?.createElement(element);
|
|
1407
|
-
// console.log('1')
|
|
1408
|
-
} break;
|
|
1409
|
-
case "svg" : {
|
|
1410
|
-
element = globalThis?.document?.createElementNS("http://www.w3.org/2000/svg", element);
|
|
1411
|
-
// console.log('2')
|
|
1412
|
-
} break;
|
|
1413
|
-
default : throw Error("Not supported")
|
|
1414
|
-
}
|
|
1415
|
-
}
|
|
1416
|
-
else this.target = element?.parentElement;
|
|
1417
|
-
Object.assign(this.cache, {
|
|
1418
|
-
name,
|
|
1419
|
-
isInteractive : false,
|
|
1420
|
-
parent:null,
|
|
1421
|
-
isBody:false,
|
|
1422
|
-
isRoot:false,
|
|
1423
|
-
isHidden: false,
|
|
1424
|
-
isFrozzen:false,
|
|
1425
|
-
legacyParent : null,
|
|
1426
|
-
attributes: {},
|
|
1427
|
-
filters: {},
|
|
1428
|
-
temp:{}
|
|
1429
|
-
});
|
|
1430
|
-
this.events = {
|
|
1431
|
-
ptr:null,
|
|
1432
|
-
mouse:null,
|
|
1433
|
-
wheel:null,
|
|
1434
|
-
key:null,
|
|
1435
|
-
drag:null,
|
|
1436
|
-
drop:null,
|
|
1437
|
-
click:null,
|
|
1438
|
-
clipboard:null,
|
|
1439
|
-
focus:null,
|
|
1440
|
-
swipe:null,
|
|
1441
|
-
custom:null,
|
|
1442
|
-
};
|
|
1443
|
-
this.observer={
|
|
1444
|
-
resize:null,
|
|
1445
|
-
intersection:null
|
|
1446
|
-
};
|
|
1447
|
-
if(element) Object.assign(this.cache,{element});
|
|
1448
|
-
// useDefaultStyle && this.style({
|
|
1449
|
-
// position: "relative",
|
|
1450
|
-
// boxSizing:"border-box",
|
|
1451
|
-
// margin:0,
|
|
1452
|
-
// padding:0,
|
|
1453
|
-
// width : "auto",
|
|
1454
|
-
// height : "auto"
|
|
1455
|
-
// });
|
|
1456
|
-
this.items = new UIStore();
|
|
1457
|
-
globalThis.__Ziko__.__UI__[this.cache.name]?globalThis.__Ziko__.__UI__[this.cache.name]?.push(this):globalThis.__Ziko__.__UI__[this.cache.name]=[this];
|
|
1458
|
-
element && render && this?.render?.();
|
|
1459
|
-
globalThis.__Ziko__.__UI__.push(this);
|
|
1460
|
-
}
|
|
1461
|
-
get element(){
|
|
1462
|
-
return this.cache.element;
|
|
1463
|
-
}
|
|
1464
|
-
[Symbol.iterator]() {
|
|
1465
|
-
return this.items[Symbol.iterator]();
|
|
1466
|
-
}
|
|
1467
|
-
maintain() {
|
|
1468
|
-
for (let i = 0; i < this.items.length; i++) {
|
|
1469
|
-
Object.defineProperty(this, i, {
|
|
1470
|
-
value: this.items[i],
|
|
1471
|
-
writable: true,
|
|
1472
|
-
configurable: true,
|
|
1473
|
-
enumerable: false
|
|
1474
|
-
});
|
|
1475
|
-
}
|
|
1476
|
-
}
|
|
1477
|
-
isInteractive(){
|
|
1478
|
-
return this.cache.isInteractive;
|
|
1479
|
-
}
|
|
1480
|
-
isUIElement(){
|
|
1481
|
-
return true;
|
|
1482
|
-
}
|
|
1483
|
-
// get st(){
|
|
1484
|
-
// return this.cache.style;
|
|
1485
|
-
// }
|
|
1486
|
-
// get attr(){
|
|
1487
|
-
// return this.cache.attributes;
|
|
1488
|
-
// }
|
|
1489
|
-
// get evt(){
|
|
1490
|
-
// return this.events;
|
|
1491
|
-
// }
|
|
1492
|
-
// get html(){
|
|
1493
|
-
// return this.element.innerHTML;
|
|
1494
|
-
// }
|
|
1495
|
-
// get text(){
|
|
1496
|
-
// return this.element.textContent;
|
|
1497
|
-
// }
|
|
1498
|
-
// get isBody(){
|
|
1499
|
-
// return this.element === globalThis?.document.body;
|
|
1500
|
-
// }
|
|
1501
|
-
// get parent(){
|
|
1502
|
-
// return this.cache.parent;
|
|
1503
|
-
// }
|
|
1504
|
-
// get width(){
|
|
1505
|
-
// return this.element.getBoundingClientRect().width;
|
|
1506
|
-
// }
|
|
1507
|
-
// get height(){
|
|
1508
|
-
// return this.element.getBoundingClientRect().height;
|
|
1509
|
-
// }
|
|
1510
|
-
// get top(){
|
|
1511
|
-
// return this.element.getBoundingClientRect().top;
|
|
1512
|
-
// }
|
|
1513
|
-
// get right(){
|
|
1514
|
-
// return this.element.getBoundingClientRect().right;
|
|
1515
|
-
// }
|
|
1516
|
-
// get bottom(){
|
|
1517
|
-
// return this.element.getBoundingClientRect().bottom;
|
|
1518
|
-
// }
|
|
1519
|
-
// get left(){
|
|
1520
|
-
// return this.element.getBoundingClientRect().left;
|
|
1521
|
-
// }
|
|
1522
|
-
// clone(render=false) {
|
|
1523
|
-
// // UI.__proto__=this.__proto__;
|
|
1524
|
-
// // if(this.items.length){
|
|
1525
|
-
// // const items = [...this.items].map(n=>n.clone());
|
|
1526
|
-
// // UI.append(...items);
|
|
1527
|
-
// // }
|
|
1528
|
-
// // else UI.element=this.element.cloneNode(true);
|
|
1529
|
-
// // return UI.mount(render);
|
|
1530
|
-
// }
|
|
1531
|
-
|
|
1532
|
-
// freeze(freeze){
|
|
1533
|
-
// this.cache.isFrozzen=freeze;
|
|
1534
|
-
// return this;
|
|
1535
|
-
// }
|
|
1536
|
-
// setTarget(tg) {
|
|
1537
|
-
// if(this.isBody) return ;
|
|
1538
|
-
// if (tg?.isUIElement) tg = tg.element;
|
|
1539
|
-
// this.unmount();
|
|
1540
|
-
// this.target = tg;
|
|
1541
|
-
// this.mount();
|
|
1542
|
-
// return this;
|
|
1543
|
-
// }
|
|
1544
|
-
// describe(label){
|
|
1545
|
-
// if(label)this.setAttr("aria-label",label)
|
|
1546
|
-
// }
|
|
1547
|
-
// get children() {
|
|
1548
|
-
// return [...this.element.children];
|
|
1549
|
-
// }
|
|
1550
|
-
// get cloneElement() {
|
|
1551
|
-
// return this.element.cloneNode(true);
|
|
1552
|
-
// }
|
|
1553
|
-
// setClasses(...value) {
|
|
1554
|
-
// this.setAttr("class", value.join(" "));
|
|
1555
|
-
// return this;
|
|
1556
|
-
// }
|
|
1557
|
-
// get classes(){
|
|
1558
|
-
// const classes=this.element.getAttribute("class");
|
|
1559
|
-
// return classes===null?[]:classes.split(" ");
|
|
1560
|
-
// }
|
|
1561
|
-
// addClass() {
|
|
1562
|
-
// /*this.setAttr("class", value);
|
|
1563
|
-
// return this;*/
|
|
1564
|
-
// }
|
|
1565
|
-
// setId(id) {
|
|
1566
|
-
// this.setAttr("id", id);
|
|
1567
|
-
// return this;
|
|
1568
|
-
// }
|
|
1569
|
-
// get id() {
|
|
1570
|
-
// return this.element.getAttribute("id");
|
|
1571
|
-
// }
|
|
1572
|
-
// onSwipe(width_threshold, height_threshold,...callbacks){
|
|
1573
|
-
// if(!this.events.swipe)this.events.swipe = useSwipeEvent(this, width_threshold, height_threshold);
|
|
1574
|
-
// this.events.swipe.onSwipe(...callbacks);
|
|
1575
|
-
// return this;
|
|
1576
|
-
// }
|
|
1577
|
-
// To Fix
|
|
1578
|
-
// onKeysDown({keys=[],callback}={}){
|
|
1579
|
-
// if(!this.events.key)this.events.key = useKeyEvent(this);
|
|
1580
|
-
// this.events.key.handleSuccessifKeys({keys,callback});
|
|
1581
|
-
// return this;
|
|
1582
|
-
// }
|
|
1583
|
-
// onSelect(...callbacks){
|
|
1584
|
-
// if(!this.events.clipboard)this.events.clipboard = useClipboardEvent(this);
|
|
1585
|
-
// this.events.clipboard.onSelect(...callbacks);
|
|
1586
|
-
// return this;
|
|
1587
|
-
// }
|
|
1588
|
-
// on(event_name,...callbacks){
|
|
1589
|
-
// if(!this.events.custom)this.events.custom = useCustomEvent(this);
|
|
1590
|
-
// this.events.custom.on(event_name,...callbacks);
|
|
1591
|
-
// return this;
|
|
1592
|
-
// }
|
|
1593
|
-
// emit(event_name,detail={}){
|
|
1594
|
-
// if(!this.events.custom)this.events.custom = useCustomEvent(this);
|
|
1595
|
-
// this.events.custom.emit(event_name,detail);
|
|
1596
|
-
// return this;
|
|
1597
|
-
// }
|
|
1598
|
-
// watchAttr(callback){
|
|
1599
|
-
// if(!this.observer.attr)this.observer.attr = watchAttr(this,callback);
|
|
1600
|
-
// return this;
|
|
1601
|
-
// }
|
|
1602
|
-
// watchChildren(callback){
|
|
1603
|
-
// if(!this.observer.children)this.observer.children = watchChildren(this,callback);
|
|
1604
|
-
// return this;
|
|
1605
|
-
// }
|
|
1606
|
-
// watchSize(callback){
|
|
1607
|
-
// if(!this.observer.resize)this.observer.resize = watchSize(this,callback);
|
|
1608
|
-
// this.observer.resize.start();
|
|
1609
|
-
// return this;
|
|
1610
|
-
// }
|
|
1611
|
-
// watchIntersection(callback,config){
|
|
1612
|
-
// if(!this.observer.intersection)this.observer.intersection = watchIntersection(this,callback,config);
|
|
1613
|
-
// this.observer.intersection.start();
|
|
1614
|
-
// return this;
|
|
1615
|
-
// }
|
|
1616
|
-
|
|
1617
|
-
}
|
|
1618
|
-
|
|
1619
|
-
function register_to_class(target, ...mixins){
|
|
1620
|
-
mixins.forEach(n => _register_to_class_(target, n));
|
|
1621
|
-
}
|
|
1622
|
-
function _register_to_class_(target, mixin) {
|
|
1623
|
-
const descriptors = Object.getOwnPropertyDescriptors(mixin);
|
|
1624
|
-
for (const key of Reflect.ownKeys(descriptors)) {
|
|
1625
|
-
const desc = descriptors[key];
|
|
1626
|
-
if ('get' in desc || 'set' in desc || typeof desc.value !== 'function') {
|
|
1627
|
-
Object.defineProperty(Object.getPrototypeOf(target), key, desc);
|
|
1628
|
-
} else if (typeof desc.value === 'function') {
|
|
1629
|
-
if (!Object.getPrototypeOf(target).hasOwnProperty(key)) {
|
|
1630
|
-
Object.defineProperty(Object.getPrototypeOf(target), key, desc);
|
|
1631
|
-
}
|
|
1632
|
-
}
|
|
1633
|
-
}
|
|
1634
|
-
}
|
|
1635
|
-
|
|
1636
|
-
if(!globalThis.__Ziko__) __init__global__();
|
|
1637
|
-
|
|
1638
|
-
function useState(initialValue) {
|
|
1639
|
-
|
|
1640
|
-
const {store, index} = __Ziko__.__State__;
|
|
1641
|
-
__Ziko__.__State__.register({
|
|
1642
|
-
value : initialValue,
|
|
1643
|
-
subscribers : new Set(),
|
|
1644
|
-
paused : false
|
|
1575
|
+
if(!globalThis.__Ziko__) __init__global__();
|
|
1576
|
+
|
|
1577
|
+
function useState(initialValue) {
|
|
1578
|
+
|
|
1579
|
+
const {store, index} = __Ziko__.__State__;
|
|
1580
|
+
__Ziko__.__State__.register({
|
|
1581
|
+
value : initialValue,
|
|
1582
|
+
subscribers : new Set(),
|
|
1583
|
+
paused : false
|
|
1645
1584
|
});
|
|
1646
1585
|
|
|
1647
1586
|
let current = store.get(index);
|
|
@@ -1839,18 +1778,6 @@
|
|
|
1839
1778
|
this.element.innerHTML = "";
|
|
1840
1779
|
return this;
|
|
1841
1780
|
}
|
|
1842
|
-
function mount(target = this.target) {
|
|
1843
|
-
if(this.isBody)return ;
|
|
1844
|
-
if(target?.isUIElement)target=target.element;
|
|
1845
|
-
this.target=target;
|
|
1846
|
-
this.target?.appendChild(this.element);
|
|
1847
|
-
return this;
|
|
1848
|
-
}
|
|
1849
|
-
function unmount(){
|
|
1850
|
-
if(this.cache.parent)this.cache.parent.remove(this);
|
|
1851
|
-
else if(this.target?.children?.length && [...this.target?.children].includes(this.element)) this.target.removeChild(this.element);
|
|
1852
|
-
return this;
|
|
1853
|
-
}
|
|
1854
1781
|
function replaceElementWith(new_element){
|
|
1855
1782
|
this.cache.element.replaceWith(new_element);
|
|
1856
1783
|
this.cache.element = new_element;
|
|
@@ -1858,14 +1785,6 @@
|
|
|
1858
1785
|
// To do : Dispose Events and States
|
|
1859
1786
|
return this
|
|
1860
1787
|
}
|
|
1861
|
-
function renderAfter(t = 1) {
|
|
1862
|
-
setTimeout(() => this.mount(), t);
|
|
1863
|
-
return this;
|
|
1864
|
-
}
|
|
1865
|
-
function unrenderAfter(t = 1) {
|
|
1866
|
-
setTimeout(() => this.unmount(), t);
|
|
1867
|
-
return this;
|
|
1868
|
-
}
|
|
1869
1788
|
function after(ui){
|
|
1870
1789
|
if(ui?.isUIElement) ui=ui.element;
|
|
1871
1790
|
this.element?.after(ui);
|
|
@@ -1884,16 +1803,12 @@
|
|
|
1884
1803
|
before: before,
|
|
1885
1804
|
clear: clear,
|
|
1886
1805
|
insertAt: insertAt,
|
|
1887
|
-
mount: mount,
|
|
1888
1806
|
prepend: prepend,
|
|
1889
1807
|
remove: remove,
|
|
1890
|
-
|
|
1891
|
-
replaceElementWith: replaceElementWith,
|
|
1892
|
-
unmount: unmount,
|
|
1893
|
-
unrenderAfter: unrenderAfter
|
|
1808
|
+
replaceElementWith: replaceElementWith
|
|
1894
1809
|
});
|
|
1895
1810
|
|
|
1896
|
-
const
|
|
1811
|
+
const EventsMap = {
|
|
1897
1812
|
'Click' : [
|
|
1898
1813
|
'Click',
|
|
1899
1814
|
'DblClick',
|
|
@@ -1939,78 +1854,109 @@
|
|
|
1939
1854
|
],
|
|
1940
1855
|
'Wheel': [
|
|
1941
1856
|
'Wheel'
|
|
1942
|
-
]
|
|
1857
|
+
],
|
|
1943
1858
|
// 'Media':[
|
|
1944
1859
|
|
|
1945
1860
|
// ],
|
|
1946
1861
|
// 'Hash':[
|
|
1947
1862
|
// "HashChange"
|
|
1948
1863
|
// ]
|
|
1864
|
+
|
|
1865
|
+
'View':[
|
|
1866
|
+
'EnterView',
|
|
1867
|
+
'ExitView',
|
|
1868
|
+
'ResizeView'
|
|
1869
|
+
],
|
|
1870
|
+
'Swipe':[
|
|
1871
|
+
'SwipeLeft',
|
|
1872
|
+
'SwipeUp',
|
|
1873
|
+
'SwipeRight',
|
|
1874
|
+
'SwipeDown'
|
|
1875
|
+
]
|
|
1949
1876
|
};
|
|
1950
1877
|
|
|
1878
|
+
function event_controller(e, event_name, details_setter, customizer) {
|
|
1879
|
+
this.cache.currentEvent = event_name;
|
|
1880
|
+
this.cache.event = e;
|
|
1881
|
+
|
|
1882
|
+
details_setter?.call(this);
|
|
1883
|
+
if (customizer?.hasOwnProperty('prototype')) customizer?.call(this);
|
|
1884
|
+
else customizer?.call(null, this);
|
|
1885
|
+
|
|
1886
|
+
if (this.cache.preventDefault[event_name]) e.preventDefault();
|
|
1887
|
+
if (this.cache.stopPropagation[event_name]) e.stopPropagation();
|
|
1888
|
+
if (this.cache.stopImmediatePropagation[event_name]) e.stopImmediatePropagation();
|
|
1889
|
+
|
|
1890
|
+
// Call the single callback if it exists
|
|
1891
|
+
this.cache.callbacks[event_name]?.(this);
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1894
|
+
function toggle_event_listener(method, ...events) {
|
|
1895
|
+
const keys = events.length === 0
|
|
1896
|
+
? Object.keys(this.cache.paused)
|
|
1897
|
+
: events;
|
|
1898
|
+
keys.forEach(key => {
|
|
1899
|
+
if (!this.cache.paused.hasOwnProperty(key)) return;
|
|
1900
|
+
this.targetElement?.[method](
|
|
1901
|
+
key,
|
|
1902
|
+
this.cache.__controllers__[key],
|
|
1903
|
+
this.cache.options[key]
|
|
1904
|
+
);
|
|
1905
|
+
this.cache.paused[key] = method === 'removeEventListener';
|
|
1906
|
+
});
|
|
1907
|
+
return this;
|
|
1908
|
+
}
|
|
1951
1909
|
const getEvent=(event = "")=>{
|
|
1952
1910
|
if(event.startsWith("Ptr"))return `pointer${event.split("Ptr")[1].toLowerCase()}`;
|
|
1953
1911
|
return event.toLowerCase()
|
|
1954
1912
|
};
|
|
1955
1913
|
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
this.cache.event = e;
|
|
1959
|
-
details_setter?.call(this);
|
|
1960
|
-
customizer?.hasOwnProperty("prototype") ? customizer?.call(this) : customizer?.call(null, this);
|
|
1961
|
-
// if(customizer?.hasOwnProperty("prototype")) customizer?.call(this)
|
|
1962
|
-
// else customizer?.call(null, this)
|
|
1963
|
-
if(this.cache.preventDefault[event_name]) e.preventDefault();
|
|
1964
|
-
if(this.cache.stopPropagation[event_name]) e.stopPropagation();
|
|
1965
|
-
if(this.cache.stopImmediatePropagation[event_name]) e.stopImmediatePropagation();
|
|
1966
|
-
|
|
1967
|
-
if(this.cache.stream.enabled[event_name]&&push_object)this.cache.stream.history[event_name].push(push_object);
|
|
1968
|
-
this.cache.callbacks[event_name]?.map(n=>n(this));
|
|
1969
|
-
}
|
|
1970
|
-
class __ZikoEvent__ {
|
|
1971
|
-
constructor(target = null, Events = [], details_setter, customizer){
|
|
1914
|
+
class ZikoEvent {
|
|
1915
|
+
constructor(signature, target = null, Events = [], details_setter, customizer){
|
|
1972
1916
|
this.target = target;
|
|
1973
1917
|
this.cache = {
|
|
1918
|
+
signature,
|
|
1974
1919
|
currentEvent : null,
|
|
1975
1920
|
event: null,
|
|
1976
1921
|
options : {},
|
|
1977
1922
|
preventDefault : {},
|
|
1978
1923
|
stopPropagation : {},
|
|
1979
1924
|
stopImmediatePropagation : {},
|
|
1980
|
-
event_flow : {},
|
|
1981
1925
|
paused : {},
|
|
1982
|
-
stream : {
|
|
1983
|
-
enabled : {},
|
|
1984
|
-
clear : {},
|
|
1985
|
-
history : {}
|
|
1986
|
-
},
|
|
1987
1926
|
callbacks : {},
|
|
1988
1927
|
__controllers__:{}
|
|
1989
1928
|
};
|
|
1990
|
-
if(Events)this._register_events(Events, details_setter, customizer);
|
|
1991
|
-
}
|
|
1992
|
-
_register_events(Events, details_setter, customizer, REGISTER_METHODES = true){
|
|
1993
|
-
const events = Events?.map(n=>getEvent(n));
|
|
1994
|
-
events?.forEach((event,i)=>{
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
1929
|
+
if (Events) this._register_events(Events, details_setter, customizer);
|
|
1930
|
+
}
|
|
1931
|
+
_register_events(Events, details_setter, customizer, REGISTER_METHODES = true) {
|
|
1932
|
+
const events = Events?.map(n => getEvent(n));
|
|
1933
|
+
events?.forEach((event, i) => {
|
|
1934
|
+
this.cache.preventDefault[event] = false;
|
|
1935
|
+
this.cache.options[event] = {};
|
|
1936
|
+
this.cache.paused[event] = false;
|
|
1937
|
+
this.cache.__controllers__[event] = (e) =>
|
|
1938
|
+
event_controller.call(this, e, event, details_setter, customizer);
|
|
1939
|
+
if (REGISTER_METHODES) {
|
|
1940
|
+
this[`on${Events[i]}`] = (callback) =>
|
|
1941
|
+
this.__onEvent(event, this.cache.options[event], {}, callback);
|
|
1942
|
+
}
|
|
2003
1943
|
});
|
|
2004
1944
|
return this;
|
|
2005
1945
|
}
|
|
1946
|
+
__onEvent(event, options, dispose, callback) {
|
|
1947
|
+
if (!callback) return this;
|
|
1948
|
+
this.cache.callbacks[event] = callback;
|
|
1949
|
+
this.__handle(event, this.cache.__controllers__[event], options, dispose);
|
|
1950
|
+
return this;
|
|
1951
|
+
}
|
|
2006
1952
|
get targetElement(){
|
|
2007
1953
|
return this.target?.element;
|
|
2008
1954
|
}
|
|
2009
1955
|
get isParent(){
|
|
2010
|
-
return this.target?.element === this.event
|
|
1956
|
+
return this.target?.element === this.event?.srcElement;
|
|
2011
1957
|
}
|
|
2012
1958
|
get item(){
|
|
2013
|
-
return this.target.find(n=>n.element == this.event?.srcElement)?.[0];
|
|
1959
|
+
return this.target.find(n => n.element == this.event?.srcElement)?.[0];
|
|
2014
1960
|
}
|
|
2015
1961
|
get currentEvent(){
|
|
2016
1962
|
return this.cache.currentEvent;
|
|
@@ -2018,185 +1964,54 @@
|
|
|
2018
1964
|
get event(){
|
|
2019
1965
|
return this.cache.event;
|
|
2020
1966
|
}
|
|
1967
|
+
get detail(){
|
|
1968
|
+
return this.cache.event.detail
|
|
1969
|
+
}
|
|
2021
1970
|
setTarget(UI){
|
|
2022
|
-
this.target=UI;
|
|
1971
|
+
this.target = UI;
|
|
2023
1972
|
return this;
|
|
2024
1973
|
}
|
|
2025
|
-
__handle(event, handler, options
|
|
1974
|
+
__handle(event, handler, options){
|
|
2026
1975
|
this.targetElement?.addEventListener(event, handler, options);
|
|
2027
1976
|
return this;
|
|
2028
1977
|
}
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
if(this.cache.
|
|
2033
|
-
|
|
2034
|
-
// this.cache.callbacks.map(n=>e=>n.call(this,e));
|
|
2035
|
-
this.cache.callbacks[event].map(n=>e=>n.call(this,e));
|
|
2036
|
-
}
|
|
2037
|
-
else {
|
|
2038
|
-
return this;
|
|
2039
|
-
}
|
|
2040
|
-
}
|
|
2041
|
-
else this.cache.callbacks[event] = callbacks.map(n=>e=>n.call(this,e));
|
|
2042
|
-
this.__handle(event, this.cache.__controllers__[event],options, dispose);
|
|
2043
|
-
return this;
|
|
2044
|
-
}
|
|
2045
|
-
#override(methode, overrides, defaultValue){
|
|
2046
|
-
if(defaultValue === "default") Object.assign(this.cache[methode], {...this.cache[methode], ...overrides});
|
|
2047
|
-
const all = defaultValue === "default"
|
|
2048
|
-
? this.cache[methode]
|
|
2049
|
-
: Object.fromEntries(Object.keys(this.cache.preventDefault).map(n=>[n,defaultValue]));
|
|
2050
|
-
Object.assign(this.cache[methode], {...all,...overrides});
|
|
2051
|
-
return this
|
|
2052
|
-
}
|
|
2053
|
-
preventDefault(overrides = {}, defaultValue = "default"){
|
|
2054
|
-
this.#override("preventDefault", overrides, defaultValue);
|
|
2055
|
-
// const all=Object.fromEntries(Object.keys(this.cache.preventDefault).map(n=>[n,defaultValue]))
|
|
2056
|
-
// Object.assign(this.cache.preventDefault, {...all,...overrides});
|
|
1978
|
+
#override(method, ...events) {
|
|
1979
|
+
const keys = events.length === 0 ? Object.keys(this.cache[method]) : events;
|
|
1980
|
+
keys.forEach(e => {
|
|
1981
|
+
if (this.cache[method].hasOwnProperty(e)) this.cache[method][e] = true;
|
|
1982
|
+
});
|
|
2057
1983
|
return this;
|
|
2058
1984
|
}
|
|
2059
|
-
|
|
2060
|
-
this.#override(
|
|
2061
|
-
return this;
|
|
1985
|
+
preventDefault(...events) {
|
|
1986
|
+
return this.#override('preventDefault', ...events);
|
|
2062
1987
|
}
|
|
2063
|
-
|
|
2064
|
-
this.#override(
|
|
2065
|
-
|
|
1988
|
+
stopPropagation(...events) {
|
|
1989
|
+
return this.#override('stopPropagation', ...events);
|
|
1990
|
+
}
|
|
1991
|
+
stopImmediatePropagation(...events) {
|
|
1992
|
+
return this.#override('stopImmediatePropagation', ...events);
|
|
2066
1993
|
}
|
|
2067
1994
|
setEventOptions(event, options){
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
this.
|
|
1995
|
+
const evt = getEvent(event);
|
|
1996
|
+
this.pause();
|
|
1997
|
+
Object.assign(this.cache.options[evt], options);
|
|
1998
|
+
this.resume();
|
|
2071
1999
|
return this;
|
|
2072
2000
|
}
|
|
2073
|
-
pause(
|
|
2074
|
-
|
|
2075
|
-
? this.cache.stream.enabled
|
|
2076
|
-
: Object.entries(Object.keys(this.cache.stream.enabled).map(n=>[n,defaultValue]));
|
|
2077
|
-
overrides={...all,...overrides};
|
|
2078
|
-
for(let key in overrides){
|
|
2079
|
-
if(overrides[key]){
|
|
2080
|
-
this.targetElement?.removeEventListener(key, this.cache.__controllers__[key], this.cache.options[key]);
|
|
2081
|
-
this.cache.paused[key]=true;
|
|
2082
|
-
}
|
|
2083
|
-
}
|
|
2084
|
-
return this;
|
|
2001
|
+
pause(...events) {
|
|
2002
|
+
return toggle_event_listener.call(this, 'removeEventListener', ...events)
|
|
2085
2003
|
}
|
|
2086
|
-
resume(
|
|
2087
|
-
|
|
2088
|
-
? this.cache.stream.enabled
|
|
2089
|
-
: Object.entries(Object.keys(this.cache.stream.enabled).map(n=>[n,defaultValue]));
|
|
2090
|
-
overrides={...all,...overrides};
|
|
2091
|
-
for(let key in overrides){
|
|
2092
|
-
if(overrides[key]){
|
|
2093
|
-
this.targetElement?.addEventListener(key,this.cache.__controllers__[key], this.cache.options[key]);
|
|
2094
|
-
this.cache.paused[key]=false;
|
|
2095
|
-
}
|
|
2096
|
-
}
|
|
2097
|
-
return this;
|
|
2098
|
-
}
|
|
2099
|
-
stream(overrides = {}, defaultValue = "default"){
|
|
2100
|
-
this.cache.stream.t0=Date.now();
|
|
2101
|
-
const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,defaultValue]));
|
|
2102
|
-
overrides={...all,...overrides};
|
|
2103
|
-
Object.assign(this.cache.stream.enabled,overrides);
|
|
2104
|
-
return this;
|
|
2105
|
-
}
|
|
2106
|
-
clear(){
|
|
2107
|
-
return this;
|
|
2004
|
+
resume(...events) {
|
|
2005
|
+
return toggle_event_listener.call(this, 'addEventListener', ...events);
|
|
2108
2006
|
}
|
|
2109
|
-
dispose(
|
|
2110
|
-
this.pause(
|
|
2111
|
-
|
|
2007
|
+
dispose(){
|
|
2008
|
+
this.pause();
|
|
2009
|
+
this.target.events[this.cache.signature] = null;
|
|
2112
2010
|
return this;
|
|
2113
2011
|
}
|
|
2114
2012
|
}
|
|
2115
2013
|
|
|
2116
|
-
|
|
2117
|
-
class ZikoEventClick extends __ZikoEvent__{
|
|
2118
|
-
constructor(target, customizer){
|
|
2119
|
-
super(target, Events.Click, details_setter$a, customizer);
|
|
2120
|
-
// register_click_away_event(target.element)
|
|
2121
|
-
}
|
|
2122
|
-
}
|
|
2123
|
-
function details_setter$a(){
|
|
2124
|
-
if(this.currentEvent==="click") this.dx = 0;
|
|
2125
|
-
else this.dx = 1;
|
|
2126
|
-
// console.log(this.currentEvent)
|
|
2127
|
-
}
|
|
2128
|
-
const bind_click_event = (target, customizer) => new ZikoEventClick(target, customizer);
|
|
2129
|
-
|
|
2130
|
-
class ZikoEventClipboard extends __ZikoEvent__{
|
|
2131
|
-
constructor(target, customizer){
|
|
2132
|
-
super(target, Events.Clipboard, details_setter$9, customizer);
|
|
2133
|
-
}
|
|
2134
|
-
}
|
|
2135
|
-
function details_setter$9(){
|
|
2136
|
-
|
|
2137
|
-
}
|
|
2138
|
-
const bind_clipboard_event = (target, customizer) => new ZikoEventClipboard(target, customizer);
|
|
2139
|
-
|
|
2140
|
-
class ZikoEventCustom extends __ZikoEvent__{
|
|
2141
|
-
constructor(target, events, customizer){
|
|
2142
|
-
super(target, events, details_setter$8, customizer);
|
|
2143
|
-
}
|
|
2144
|
-
_register_events(events){
|
|
2145
|
-
super._register_events(events, null, null, false);
|
|
2146
|
-
return this;
|
|
2147
|
-
}
|
|
2148
|
-
emit(event_name, details = {}){
|
|
2149
|
-
const event=new Event(event_name);
|
|
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;
|
|
2157
|
-
}
|
|
2158
|
-
}
|
|
2159
|
-
function details_setter$8(){
|
|
2160
|
-
|
|
2161
|
-
}
|
|
2162
|
-
const bindCustomEvent = (target, events, customizer) => new ZikoEventCustom(target, events, customizer);
|
|
2163
|
-
|
|
2164
|
-
class ZikoEventDrag extends __ZikoEvent__{
|
|
2165
|
-
constructor(target, customizer){
|
|
2166
|
-
super(target, Events.Drag, details_setter$7, customizer);
|
|
2167
|
-
}
|
|
2168
|
-
}
|
|
2169
|
-
function details_setter$7(){
|
|
2170
|
-
|
|
2171
|
-
}
|
|
2172
|
-
const bind_drag_event = (target, customizer) => new ZikoEventDrag(target, customizer);
|
|
2173
|
-
|
|
2174
|
-
class ZikoEventFocus extends __ZikoEvent__{
|
|
2175
|
-
constructor(target, customizer){
|
|
2176
|
-
super(target, Events.Focus, details_setter$6, customizer);
|
|
2177
|
-
}
|
|
2178
|
-
}
|
|
2179
|
-
function details_setter$6(){
|
|
2180
|
-
|
|
2181
|
-
}
|
|
2182
|
-
const bind_focus_event = (target, customizer) => new ZikoEventFocus(target, customizer);
|
|
2183
|
-
|
|
2184
|
-
class ZikoEventHash extends __ZikoEvent__{
|
|
2185
|
-
constructor(target, customizer){
|
|
2186
|
-
super(target, Events.Hash, details_setter$5, customizer);
|
|
2187
|
-
}
|
|
2188
|
-
}
|
|
2189
|
-
function details_setter$5(){
|
|
2190
|
-
|
|
2191
|
-
}
|
|
2192
|
-
const bindHashEvent = (target, customizer) => new ZikoEventHash(target, customizer);
|
|
2193
|
-
|
|
2194
|
-
class ZikoEventKey extends __ZikoEvent__{
|
|
2195
|
-
constructor(target, customizer){
|
|
2196
|
-
super(target, Events.Key, details_setter$4, customizer);
|
|
2197
|
-
}
|
|
2198
|
-
}
|
|
2199
|
-
function details_setter$4(){
|
|
2014
|
+
function key_details_setter(){
|
|
2200
2015
|
switch(this.currentEvent){
|
|
2201
2016
|
case "keydown" : {
|
|
2202
2017
|
this.kd = this.event.key;
|
|
@@ -2209,26 +2024,9 @@
|
|
|
2209
2024
|
} break;
|
|
2210
2025
|
|
|
2211
2026
|
}
|
|
2212
|
-
}
|
|
2213
|
-
const bind_key_event = (target, customizer) => new ZikoEventKey(target, customizer);
|
|
2214
|
-
|
|
2215
|
-
class ZikoEventMouse extends __ZikoEvent__{
|
|
2216
|
-
constructor(target, customizer){
|
|
2217
|
-
super(target, Events.Mouse, details_setter$3, customizer);
|
|
2218
|
-
}
|
|
2219
|
-
}
|
|
2220
|
-
function details_setter$3(){
|
|
2221
|
-
|
|
2222
|
-
}
|
|
2223
|
-
const bind_mouse_event = (target, customizer) => new ZikoEventMouse(target, customizer);
|
|
2027
|
+
}
|
|
2224
2028
|
|
|
2225
|
-
|
|
2226
|
-
constructor(target, customizer){
|
|
2227
|
-
super(target, Events.Ptr, details_setter$2, customizer);
|
|
2228
|
-
this.isDown = false;
|
|
2229
|
-
}
|
|
2230
|
-
}
|
|
2231
|
-
function details_setter$2(){
|
|
2029
|
+
function ptr_details_setter(){
|
|
2232
2030
|
switch(this.currentEvent){
|
|
2233
2031
|
case "pointerdown" : {
|
|
2234
2032
|
this.dx = parseInt(this.event.offsetX);
|
|
@@ -2260,28 +2058,314 @@
|
|
|
2260
2058
|
// if(this.currentEvent==="click") this.dx = 0
|
|
2261
2059
|
// else this.dx = 1
|
|
2262
2060
|
// console.log(this.currentEvent)
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
class ClickAwayEvent extends Event {
|
|
2064
|
+
constructor(originalEvent, targetElement) {
|
|
2065
|
+
super("clickaway", { bubbles: true, cancelable: true });
|
|
2066
|
+
this.originalEvent = originalEvent;
|
|
2067
|
+
this.targetElement = targetElement;
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
|
|
2071
|
+
function register_click_away_event(element) {
|
|
2072
|
+
console.log(element);
|
|
2073
|
+
function handler(e) {
|
|
2074
|
+
if (!element.contains(e.target)) {
|
|
2075
|
+
const clickAwayEvent = new ClickAwayEvent(e, element);
|
|
2076
|
+
element.dispatchEvent(clickAwayEvent);
|
|
2077
|
+
}
|
|
2078
|
+
}
|
|
2079
|
+
|
|
2080
|
+
globalThis?.document?.addEventListener("click", handler);
|
|
2081
|
+
|
|
2082
|
+
return () => globalThis?.document?.removeEventListener("click", handler);
|
|
2083
|
+
|
|
2263
2084
|
}
|
|
2264
|
-
|
|
2085
|
+
|
|
2086
|
+
// // Example usage
|
|
2087
|
+
// const box = document.querySelector("#my-box");
|
|
2088
|
+
|
|
2089
|
+
// const stop = listenClickAway(box);
|
|
2090
|
+
|
|
2091
|
+
// box.addEventListener("clickaway", (e) => {
|
|
2092
|
+
// console.log("Clicked outside box!", e);
|
|
2093
|
+
// });
|
|
2094
|
+
|
|
2095
|
+
// // later, you can stop listening:
|
|
2096
|
+
// // stop();
|
|
2097
|
+
|
|
2098
|
+
const debounce=(fn,delay=1000)=>{
|
|
2099
|
+
let id;
|
|
2100
|
+
return (...args) => id ? clearTimeout(id) : setTimeout(()=>fn(...args),delay);
|
|
2101
|
+
};
|
|
2102
|
+
const throttle=(fn,delay)=>{
|
|
2103
|
+
let lastTime=0;
|
|
2104
|
+
return (...args) => {
|
|
2105
|
+
const now = new Date().getTime();
|
|
2106
|
+
if(now-lastTime < delay) return;
|
|
2107
|
+
lastTime = now;
|
|
2108
|
+
fn(...args);
|
|
2109
|
+
}
|
|
2110
|
+
};
|
|
2265
2111
|
|
|
2266
|
-
class
|
|
2267
|
-
constructor(
|
|
2268
|
-
super(
|
|
2112
|
+
class ViewEvent extends CustomEvent {
|
|
2113
|
+
constructor(type, detail, { bubbles = true, cancelable = true } = {}) {
|
|
2114
|
+
super(type, { detail, bubbles, cancelable });
|
|
2269
2115
|
}
|
|
2270
2116
|
}
|
|
2271
|
-
function details_setter$1(){
|
|
2272
2117
|
|
|
2118
|
+
function register_view_event(
|
|
2119
|
+
element,
|
|
2120
|
+
{
|
|
2121
|
+
intersection = true,
|
|
2122
|
+
resize = true,
|
|
2123
|
+
threshold = 0,
|
|
2124
|
+
throttleResize = 100,
|
|
2125
|
+
throttleEnterExit = 0
|
|
2126
|
+
} = {}
|
|
2127
|
+
) {
|
|
2128
|
+
let intersectionObserver, resizeObserver;
|
|
2129
|
+
const resizeCallback = entries => {
|
|
2130
|
+
for (let entry of entries) {
|
|
2131
|
+
const { width, height } = entry.contentRect;
|
|
2132
|
+
|
|
2133
|
+
element.dispatchEvent(
|
|
2134
|
+
new ViewEvent("resizeview", {
|
|
2135
|
+
width,
|
|
2136
|
+
height,
|
|
2137
|
+
entry
|
|
2138
|
+
})
|
|
2139
|
+
);
|
|
2140
|
+
}
|
|
2141
|
+
};
|
|
2142
|
+
|
|
2143
|
+
const throttledResize = throttleResize > 0
|
|
2144
|
+
? throttle(resizeCallback, throttleResize)
|
|
2145
|
+
: resizeCallback;
|
|
2146
|
+
|
|
2147
|
+
const intersectionCallback = entries => {
|
|
2148
|
+
for (let entry of entries) {
|
|
2149
|
+
const type = entry.isIntersecting ? "enterview" : "exitview";
|
|
2150
|
+
element.dispatchEvent(new ViewEvent(type, entry));
|
|
2151
|
+
}
|
|
2152
|
+
};
|
|
2153
|
+
|
|
2154
|
+
const throttledIntersections = throttleEnterExit > 0
|
|
2155
|
+
? throttle(intersectionCallback, throttleEnterExit)
|
|
2156
|
+
: intersectionCallback;
|
|
2157
|
+
|
|
2158
|
+
if (intersection) {
|
|
2159
|
+
intersectionObserver = new IntersectionObserver(throttledIntersections, { threshold });
|
|
2160
|
+
intersectionObserver.observe(element);
|
|
2161
|
+
}
|
|
2162
|
+
|
|
2163
|
+
if (resize) {
|
|
2164
|
+
resizeObserver = new ResizeObserver(throttledResize);
|
|
2165
|
+
resizeObserver.observe(element);
|
|
2166
|
+
}
|
|
2167
|
+
|
|
2168
|
+
// ---- UNREGISTER ----
|
|
2169
|
+
return () => {
|
|
2170
|
+
if (intersectionObserver) {
|
|
2171
|
+
intersectionObserver.unobserve(element);
|
|
2172
|
+
intersectionObserver.disconnect();
|
|
2173
|
+
}
|
|
2174
|
+
if (resizeObserver) {
|
|
2175
|
+
resizeObserver.unobserve(element);
|
|
2176
|
+
resizeObserver.disconnect();
|
|
2177
|
+
}
|
|
2178
|
+
};
|
|
2179
|
+
}
|
|
2180
|
+
|
|
2181
|
+
class SwipeEvent extends CustomEvent {
|
|
2182
|
+
constructor(type, detail) {
|
|
2183
|
+
super(type, {
|
|
2184
|
+
detail,
|
|
2185
|
+
bubbles: true,
|
|
2186
|
+
cancelable: true
|
|
2187
|
+
});
|
|
2188
|
+
}
|
|
2273
2189
|
}
|
|
2274
|
-
|
|
2190
|
+
|
|
2191
|
+
function register_swipe_event(
|
|
2192
|
+
element,
|
|
2193
|
+
threshold = 50,
|
|
2194
|
+
restraint = 100,
|
|
2195
|
+
allowedTime = 500
|
|
2196
|
+
) {
|
|
2197
|
+
let startX = 0,
|
|
2198
|
+
startY = 0,
|
|
2199
|
+
startTime = 0,
|
|
2200
|
+
isPointerDown = false;
|
|
2201
|
+
|
|
2202
|
+
function onPointerDown(e) {
|
|
2203
|
+
startX = e.clientX;
|
|
2204
|
+
startY = e.clientY;
|
|
2205
|
+
startTime = performance.now();
|
|
2206
|
+
isPointerDown = true;
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2209
|
+
function onPointerUp(e) {
|
|
2210
|
+
if (!isPointerDown) return;
|
|
2211
|
+
isPointerDown = false;
|
|
2212
|
+
|
|
2213
|
+
const distX = e.clientX - startX;
|
|
2214
|
+
const distY = e.clientY - startY;
|
|
2215
|
+
const elapsed = performance.now() - startTime;
|
|
2216
|
+
|
|
2217
|
+
let direction = null;
|
|
2218
|
+
let eventName = null;
|
|
2219
|
+
|
|
2220
|
+
if (elapsed <= allowedTime) {
|
|
2221
|
+
if (Math.abs(distX) >= threshold && Math.abs(distY) <= restraint) {
|
|
2222
|
+
direction = distX < 0 ? "left" : "right";
|
|
2223
|
+
eventName = "swipe" + direction;
|
|
2224
|
+
}
|
|
2225
|
+
else if (Math.abs(distY) >= threshold && Math.abs(distX) <= restraint) {
|
|
2226
|
+
direction = distY < 0 ? "up" : "down";
|
|
2227
|
+
eventName = "swipe" + direction;
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2231
|
+
// Emit event
|
|
2232
|
+
if (eventName) {
|
|
2233
|
+
element.dispatchEvent(
|
|
2234
|
+
new SwipeEvent(eventName, {
|
|
2235
|
+
direction,
|
|
2236
|
+
distX,
|
|
2237
|
+
distY,
|
|
2238
|
+
originalEvent: e
|
|
2239
|
+
})
|
|
2240
|
+
);
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
|
|
2244
|
+
element.addEventListener("pointerdown", onPointerDown, { passive: true });
|
|
2245
|
+
element.addEventListener("pointerup", onPointerUp, { passive: true });
|
|
2246
|
+
|
|
2247
|
+
return () => {
|
|
2248
|
+
element.removeEventListener("pointerdown", onPointerDown);
|
|
2249
|
+
element.removeEventListener("pointerup", onPointerUp);
|
|
2250
|
+
};
|
|
2251
|
+
}
|
|
2252
|
+
|
|
2253
|
+
const bind_click_event = (target, customizer) => {
|
|
2254
|
+
register_click_away_event(target.element);
|
|
2255
|
+
return new ZikoEvent(
|
|
2256
|
+
'click',
|
|
2257
|
+
target,
|
|
2258
|
+
EventsMap.Click,
|
|
2259
|
+
null,
|
|
2260
|
+
customizer
|
|
2261
|
+
);
|
|
2262
|
+
};
|
|
2263
|
+
const bind_clipboard_event = (target, customizer) => new ZikoEvent(
|
|
2264
|
+
'clipboard',
|
|
2265
|
+
target,
|
|
2266
|
+
EventsMap.Clipboard,
|
|
2267
|
+
null,
|
|
2268
|
+
customizer
|
|
2269
|
+
);
|
|
2270
|
+
const bind_drag_event = (target, customizer) => new ZikoEvent(
|
|
2271
|
+
'drag',
|
|
2272
|
+
target,
|
|
2273
|
+
EventsMap.Drag,
|
|
2274
|
+
null,
|
|
2275
|
+
customizer
|
|
2276
|
+
);
|
|
2277
|
+
const bind_focus_event = (target, customizer) => new ZikoEvent(
|
|
2278
|
+
'focus',
|
|
2279
|
+
target,
|
|
2280
|
+
EventsMap.Focus,
|
|
2281
|
+
null,
|
|
2282
|
+
customizer
|
|
2283
|
+
);
|
|
2284
|
+
const bind_key_event = (target, customizer) => new ZikoEvent(
|
|
2285
|
+
'key',
|
|
2286
|
+
target,
|
|
2287
|
+
EventsMap.Key,
|
|
2288
|
+
key_details_setter,
|
|
2289
|
+
customizer
|
|
2290
|
+
);
|
|
2291
|
+
const bind_mouse_event = (target, customizer) => new ZikoEvent(
|
|
2292
|
+
'mouse',
|
|
2293
|
+
target,
|
|
2294
|
+
EventsMap.Mouse,
|
|
2295
|
+
null,
|
|
2296
|
+
customizer
|
|
2297
|
+
);
|
|
2298
|
+
const bind_pointer_event = (target, customizer) => new ZikoEvent(
|
|
2299
|
+
'ptr',
|
|
2300
|
+
target,
|
|
2301
|
+
EventsMap.Ptr,
|
|
2302
|
+
ptr_details_setter,
|
|
2303
|
+
customizer
|
|
2304
|
+
);
|
|
2305
|
+
const bind_touch_event = (target, customizer) => new ZikoEvent(
|
|
2306
|
+
'touch',
|
|
2307
|
+
target,
|
|
2308
|
+
EventsMap.Touch,
|
|
2309
|
+
null,
|
|
2310
|
+
customizer
|
|
2311
|
+
);
|
|
2312
|
+
const bind_wheel_event = (target, customizer) => new ZikoEvent(
|
|
2313
|
+
'wheel',
|
|
2314
|
+
target,
|
|
2315
|
+
EventsMap.Wheel,
|
|
2316
|
+
null,
|
|
2317
|
+
customizer
|
|
2318
|
+
);
|
|
2319
|
+
|
|
2320
|
+
const bind_view_event = (target, customizer) => {
|
|
2321
|
+
register_view_event(target.element);
|
|
2322
|
+
return new ZikoEvent(
|
|
2323
|
+
'view',
|
|
2324
|
+
target,
|
|
2325
|
+
EventsMap.View,
|
|
2326
|
+
null,
|
|
2327
|
+
customizer
|
|
2328
|
+
)
|
|
2329
|
+
};
|
|
2330
|
+
|
|
2331
|
+
const bind_swipe_event = (target, customizer) => {
|
|
2332
|
+
register_swipe_event(target.element);
|
|
2333
|
+
return new ZikoEvent(
|
|
2334
|
+
'swipe',
|
|
2335
|
+
target,
|
|
2336
|
+
EventsMap.Swipe,
|
|
2337
|
+
null,
|
|
2338
|
+
customizer
|
|
2339
|
+
)
|
|
2340
|
+
};
|
|
2275
2341
|
|
|
2276
|
-
class
|
|
2277
|
-
constructor(target, customizer){
|
|
2278
|
-
super(target,
|
|
2342
|
+
class ZikoCustomEvent extends ZikoEvent{
|
|
2343
|
+
constructor(target, events, customizer){
|
|
2344
|
+
super('custom', target, events, details_setter, customizer);
|
|
2345
|
+
}
|
|
2346
|
+
_register_events(events){
|
|
2347
|
+
super._register_events(events, null, null, false);
|
|
2348
|
+
return this;
|
|
2349
|
+
}
|
|
2350
|
+
emit(event_name, detail = {}){
|
|
2351
|
+
const event = new CustomEvent(event_name, {
|
|
2352
|
+
detail,
|
|
2353
|
+
bubbles: true,
|
|
2354
|
+
cancelable: true
|
|
2355
|
+
});
|
|
2356
|
+
this.targetElement.dispatchEvent(event);
|
|
2357
|
+
return this;
|
|
2358
|
+
}
|
|
2359
|
+
on(event_name, ...callbacks){
|
|
2360
|
+
if(!this.cache.options.hasOwnProperty(event_name)) this._register_events([event_name]);
|
|
2361
|
+
this.__onEvent(event_name, this.cache.options[event_name], {}, ...callbacks);
|
|
2362
|
+
return this;
|
|
2279
2363
|
}
|
|
2280
2364
|
}
|
|
2281
2365
|
function details_setter(){
|
|
2282
2366
|
|
|
2283
2367
|
}
|
|
2284
|
-
const
|
|
2368
|
+
const bind_custom_event = (target, events, customizer) => new ZikoCustomEvent(target, events, customizer);
|
|
2285
2369
|
|
|
2286
2370
|
const binderMap = {
|
|
2287
2371
|
ptr: bind_pointer_event,
|
|
@@ -2291,17 +2375,31 @@
|
|
|
2291
2375
|
drag : bind_drag_event,
|
|
2292
2376
|
clipboard : bind_clipboard_event,
|
|
2293
2377
|
focus : bind_focus_event,
|
|
2294
|
-
wheel : bind_wheel_event
|
|
2378
|
+
wheel : bind_wheel_event,
|
|
2379
|
+
view : bind_view_event,
|
|
2380
|
+
swipe : bind_swipe_event
|
|
2295
2381
|
};
|
|
2296
2382
|
|
|
2297
|
-
const EventsMethodes = {
|
|
2383
|
+
const EventsMethodes = {
|
|
2384
|
+
on(event_name,...callbacks){
|
|
2385
|
+
if(!this.events.custom)this.events.custom = bind_custom_event(this);
|
|
2386
|
+
this.events.custom.on(event_name,...callbacks);
|
|
2387
|
+
return this;
|
|
2388
|
+
},
|
|
2389
|
+
emit(event_name,detail={}){
|
|
2390
|
+
if(!this.events.custom)this.events.custom = bind_custom_event(this);
|
|
2391
|
+
this.events.custom.emit(event_name,detail);
|
|
2392
|
+
return this;
|
|
2393
|
+
}
|
|
2394
|
+
};
|
|
2298
2395
|
|
|
2299
|
-
Object.entries(
|
|
2396
|
+
Object.entries(EventsMap).forEach(([name, eventList]) => {
|
|
2397
|
+
const lname = name.toLowerCase();
|
|
2300
2398
|
eventList.forEach(event => {
|
|
2301
2399
|
const methodName = `on${event}`;
|
|
2302
|
-
EventsMethodes[methodName] = function (
|
|
2303
|
-
if (!this.events[
|
|
2304
|
-
this.events[
|
|
2400
|
+
EventsMethodes[methodName] = function (callbacks) {
|
|
2401
|
+
if (!this.events[lname]) this.events[lname] = binderMap[lname](this);
|
|
2402
|
+
this.events[lname][methodName](callbacks);
|
|
2305
2403
|
return this;
|
|
2306
2404
|
};
|
|
2307
2405
|
});
|
|
@@ -2362,158 +2460,14 @@
|
|
|
2362
2460
|
return this;
|
|
2363
2461
|
}
|
|
2364
2462
|
|
|
2365
|
-
var StyleMethods = /*#__PURE__*/Object.freeze({
|
|
2366
|
-
__proto__: null,
|
|
2367
|
-
animate: animate,
|
|
2368
|
-
hide: hide,
|
|
2369
|
-
show: show,
|
|
2370
|
-
size: size,
|
|
2371
|
-
style: style
|
|
2372
|
-
});
|
|
2373
|
-
|
|
2374
|
-
function EVENT_CONTROLLER(e,EVENT,setter,push_object){
|
|
2375
|
-
this.event=e;
|
|
2376
|
-
if(this.cache.preventDefault[EVENT])e.preventDefault();
|
|
2377
|
-
console.log({setter});
|
|
2378
|
-
if(setter)setter();
|
|
2379
|
-
if(this.cache.stream.enabled[EVENT]&&push_object)this.cache.stream.history[EVENT].push(push_object);
|
|
2380
|
-
this.cache.callbacks[EVENT].map(n=>n(this));
|
|
2381
|
-
return this;
|
|
2382
|
-
}
|
|
2383
|
-
class ZikoEvent{
|
|
2384
|
-
constructor(target){
|
|
2385
|
-
this.target=null;
|
|
2386
|
-
this.setTarget(target);
|
|
2387
|
-
this.__dispose=this.dispose.bind(this);
|
|
2388
|
-
// this.EventIndex=Garbage.Pointer.data.length;
|
|
2389
|
-
// Garbage.Pointer.data.push({event:this,index:this.EventIndex});
|
|
2390
|
-
}
|
|
2391
|
-
get targetElement(){
|
|
2392
|
-
return this.target.element
|
|
2393
|
-
}
|
|
2394
|
-
setTarget(UI){
|
|
2395
|
-
this.target=UI;
|
|
2396
|
-
return this;
|
|
2397
|
-
}
|
|
2398
|
-
__handle(event,handler,dispose){
|
|
2399
|
-
const EVENT=(event==="drag")?event:`${this.cache.prefixe}${event}`;
|
|
2400
|
-
this.dispose(dispose);
|
|
2401
|
-
this.targetElement?.addEventListener(EVENT,handler);
|
|
2402
|
-
return this;
|
|
2403
|
-
}
|
|
2404
|
-
__onEvent(event,dispose,...callbacks){
|
|
2405
|
-
if(callbacks.length===0){
|
|
2406
|
-
if(this.cache.callbacks.length>1){
|
|
2407
|
-
this.cache.callbacks.map(n=>e=>n.call(this,e));
|
|
2408
|
-
}
|
|
2409
|
-
else {
|
|
2410
|
-
return this;
|
|
2411
|
-
}
|
|
2412
|
-
}
|
|
2413
|
-
else this.cache.callbacks[event]=callbacks.map(n=>e=>n.call(this,e));
|
|
2414
|
-
this.__handle(event,this.__controller[event],dispose);
|
|
2415
|
-
return this;
|
|
2416
|
-
}
|
|
2417
|
-
preventDefault(config={}){
|
|
2418
|
-
Object.assign(this.cache.preventDefault,config);
|
|
2419
|
-
return this;
|
|
2420
|
-
}
|
|
2421
|
-
pause(config={}){
|
|
2422
|
-
const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,true]));
|
|
2423
|
-
config={...all,...config};
|
|
2424
|
-
for(let key in config){
|
|
2425
|
-
if(config[key]){
|
|
2426
|
-
this.targetElement?.removeEventListener(`${this.cache.prefixe}${key}`,this.__controller[`${this.cache.prefixe}${key}`]);
|
|
2427
|
-
this.cache.paused[`${this.cache.prefixe}${key}`]=true;
|
|
2428
|
-
}
|
|
2429
|
-
}
|
|
2430
|
-
return this;
|
|
2431
|
-
}
|
|
2432
|
-
resume(config={}){
|
|
2433
|
-
const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,true]));
|
|
2434
|
-
config={...all,...config};
|
|
2435
|
-
for(let key in config){
|
|
2436
|
-
if(config[key]){
|
|
2437
|
-
this.targetElement?.addEventListener(`${this.cache.prefixe}${key}`,this.__controller[`${this.cache.prefixe}${key}`]);
|
|
2438
|
-
this.cache.paused[`${this.cache.prefixe}${key}`]=false;
|
|
2439
|
-
}
|
|
2440
|
-
}
|
|
2441
|
-
return this;
|
|
2442
|
-
}
|
|
2443
|
-
dispose(config={}){
|
|
2444
|
-
this.pause(config);
|
|
2445
|
-
return this;
|
|
2446
|
-
}
|
|
2447
|
-
stream(config={}){
|
|
2448
|
-
this.cache.stream.t0=Date.now();
|
|
2449
|
-
const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,true]));
|
|
2450
|
-
config={...all,...config};
|
|
2451
|
-
Object.assign(this.cache.stream.enabled,config);
|
|
2452
|
-
return this;
|
|
2453
|
-
}
|
|
2454
|
-
clear(config={}){
|
|
2455
|
-
const all=Object.fromEntries(Object.keys(this.cache.stream.clear).map(n=>[n,true]));
|
|
2456
|
-
config={...all,...config};
|
|
2457
|
-
for(let key in config){
|
|
2458
|
-
if(config[key]){
|
|
2459
|
-
this.cache.stream.history[key]=[];
|
|
2460
|
-
}
|
|
2461
|
-
}
|
|
2462
|
-
return this;
|
|
2463
|
-
}
|
|
2464
|
-
}
|
|
2465
|
-
|
|
2466
|
-
const custom_event_controller=event_name=>function(e){
|
|
2467
|
-
EVENT_CONTROLLER.call(this,e,event_name,null,null);
|
|
2468
|
-
};
|
|
2469
|
-
class ZikoCustomEvent extends ZikoEvent{
|
|
2470
|
-
constructor(target){
|
|
2471
|
-
super(target);
|
|
2472
|
-
this.event=null;
|
|
2473
|
-
this.cache={
|
|
2474
|
-
prefixe:"",
|
|
2475
|
-
preventDefault:{
|
|
2476
|
-
},
|
|
2477
|
-
paused:{
|
|
2478
|
-
},
|
|
2479
|
-
stream:{
|
|
2480
|
-
enabled:{
|
|
2481
|
-
},
|
|
2482
|
-
clear:{
|
|
2483
|
-
},
|
|
2484
|
-
history:{
|
|
2485
|
-
}
|
|
2486
|
-
},
|
|
2487
|
-
callbacks:{
|
|
2488
|
-
}
|
|
2489
|
-
};
|
|
2490
|
-
this.__controller={
|
|
2491
|
-
};
|
|
2492
|
-
}
|
|
2493
|
-
#init(event_name){
|
|
2494
|
-
this.cache.preventDefault[event_name]=false;
|
|
2495
|
-
this.cache.paused[event_name]=false;
|
|
2496
|
-
this.cache.stream.enabled=false;
|
|
2497
|
-
this.cache.stream.clear=false;
|
|
2498
|
-
this.cache.stream.history=[];
|
|
2499
|
-
this.cache.callbacks[event_name]=[];
|
|
2500
|
-
this.__controller[event_name]=custom_event_controller(event_name).bind(this);
|
|
2501
|
-
return this;
|
|
2502
|
-
}
|
|
2503
|
-
on(event_name,...callbacks){
|
|
2504
|
-
if(!(this.__controller[event_name]))this.#init(event_name);
|
|
2505
|
-
this.__onEvent(event_name,{},...callbacks);
|
|
2506
|
-
return this;
|
|
2507
|
-
}
|
|
2508
|
-
emit(event_name,detail={}){
|
|
2509
|
-
if(!(this.__controller[event_name]))this.#init(event_name);
|
|
2510
|
-
this.detail=detail;
|
|
2511
|
-
const event=new Event(event_name);
|
|
2512
|
-
this.targetElement.dispatchEvent(event);
|
|
2513
|
-
return this;
|
|
2514
|
-
}
|
|
2515
|
-
}
|
|
2516
|
-
const useCustomEvent=target=>new ZikoCustomEvent(target);
|
|
2463
|
+
var StyleMethods = /*#__PURE__*/Object.freeze({
|
|
2464
|
+
__proto__: null,
|
|
2465
|
+
animate: animate,
|
|
2466
|
+
hide: hide,
|
|
2467
|
+
show: show,
|
|
2468
|
+
size: size,
|
|
2469
|
+
style: style
|
|
2470
|
+
});
|
|
2517
2471
|
|
|
2518
2472
|
let UIElement$1 = class UIElement extends UIElementCore{
|
|
2519
2473
|
constructor({element, name ='', type='html', render = __Ziko__.__Config__.default.render}={}){
|
|
@@ -2522,12 +2476,15 @@
|
|
|
2522
2476
|
// console.log(this)
|
|
2523
2477
|
register_to_class(
|
|
2524
2478
|
this,
|
|
2479
|
+
LifecycleMethods,
|
|
2525
2480
|
AttrsMethods,
|
|
2526
2481
|
DomMethods,
|
|
2527
2482
|
StyleMethods,
|
|
2528
2483
|
IndexingMethods,
|
|
2529
2484
|
EventsMethodes
|
|
2530
2485
|
);
|
|
2486
|
+
|
|
2487
|
+
// console.log(EventsMethodes)
|
|
2531
2488
|
if(element)this.init(element, name, type, render);
|
|
2532
2489
|
}
|
|
2533
2490
|
get element(){
|
|
@@ -2649,32 +2606,12 @@
|
|
|
2649
2606
|
// get id() {
|
|
2650
2607
|
// return this.element.getAttribute("id");
|
|
2651
2608
|
// }
|
|
2652
|
-
// onSwipe(width_threshold, height_threshold,...callbacks){
|
|
2653
|
-
// if(!this.events.swipe)this.events.swipe = useSwipeEvent(this, width_threshold, height_threshold);
|
|
2654
|
-
// this.events.swipe.onSwipe(...callbacks);
|
|
2655
|
-
// return this;
|
|
2656
|
-
// }
|
|
2657
2609
|
// To Fix
|
|
2658
2610
|
// onKeysDown({keys=[],callback}={}){
|
|
2659
2611
|
// if(!this.events.key)this.events.key = useKeyEvent(this);
|
|
2660
2612
|
// this.events.key.handleSuccessifKeys({keys,callback});
|
|
2661
2613
|
// return this;
|
|
2662
2614
|
// }
|
|
2663
|
-
// onSelect(...callbacks){
|
|
2664
|
-
// if(!this.events.clipboard)this.events.clipboard = useClipboardEvent(this);
|
|
2665
|
-
// this.events.clipboard.onSelect(...callbacks);
|
|
2666
|
-
// return this;
|
|
2667
|
-
// }
|
|
2668
|
-
on(event_name,...callbacks){
|
|
2669
|
-
if(!this.events.custom)this.events.custom = useCustomEvent(this);
|
|
2670
|
-
this.events.custom.on(event_name,...callbacks);
|
|
2671
|
-
return this;
|
|
2672
|
-
}
|
|
2673
|
-
emit(event_name,detail={}){
|
|
2674
|
-
if(!this.events.custom)this.events.custom = useCustomEvent(this);
|
|
2675
|
-
this.events.custom.emit(event_name,detail);
|
|
2676
|
-
return this;
|
|
2677
|
-
}
|
|
2678
2615
|
// watchAttr(callback){
|
|
2679
2616
|
// if(!this.observer.attr)this.observer.attr = watchAttr(this,callback);
|
|
2680
2617
|
// return this;
|
|
@@ -2683,16 +2620,8 @@
|
|
|
2683
2620
|
// if(!this.observer.children)this.observer.children = watchChildren(this,callback);
|
|
2684
2621
|
// return this;
|
|
2685
2622
|
// }
|
|
2686
|
-
// watchSize(callback)
|
|
2687
|
-
//
|
|
2688
|
-
// this.observer.resize.start();
|
|
2689
|
-
// return this;
|
|
2690
|
-
// }
|
|
2691
|
-
// watchIntersection(callback,config){
|
|
2692
|
-
// if(!this.observer.intersection)this.observer.intersection = watchIntersection(this,callback,config);
|
|
2693
|
-
// this.observer.intersection.start();
|
|
2694
|
-
// return this;
|
|
2695
|
-
// }
|
|
2623
|
+
// watchSize(callback)Remplaced By on onViewResize
|
|
2624
|
+
// watchIntersection(callback,config) Remplaced By onViewEnter and onViewExit
|
|
2696
2625
|
|
|
2697
2626
|
};
|
|
2698
2627
|
|
|
@@ -2991,7 +2920,6 @@
|
|
|
2991
2920
|
const ui = await callback();
|
|
2992
2921
|
fallback_ui.unmount();
|
|
2993
2922
|
this.append(ui);
|
|
2994
|
-
// console.log(content)
|
|
2995
2923
|
}
|
|
2996
2924
|
catch(error){
|
|
2997
2925
|
console.log({error});
|
|
@@ -4622,20 +4550,6 @@
|
|
|
4622
4550
|
|
|
4623
4551
|
const step_fps = (step_or_fps) => 1000 / step_or_fps;
|
|
4624
4552
|
|
|
4625
|
-
const debounce=(fn,delay=1000)=>{
|
|
4626
|
-
let id;
|
|
4627
|
-
return (...args) => id ? clearTimeout(id) : setTimeout(()=>fn(...args),delay);
|
|
4628
|
-
};
|
|
4629
|
-
const throttle=(fn,delay)=>{
|
|
4630
|
-
let lastTime=0;
|
|
4631
|
-
return (...args) => {
|
|
4632
|
-
const now = new Date().getTime();
|
|
4633
|
-
if(now-lastTime < delay) return;
|
|
4634
|
-
lastTime = now;
|
|
4635
|
-
fn(...args);
|
|
4636
|
-
}
|
|
4637
|
-
};
|
|
4638
|
-
|
|
4639
4553
|
const sleep= ms => new Promise(res => setTimeout(res, ms));
|
|
4640
4554
|
function timeout(ms, fn) {
|
|
4641
4555
|
let id;
|
|
@@ -4808,212 +4722,7 @@
|
|
|
4808
4722
|
return r;
|
|
4809
4723
|
};
|
|
4810
4724
|
|
|
4811
|
-
|
|
4812
|
-
constructor(maxListeners = 10) {
|
|
4813
|
-
this.events = {};
|
|
4814
|
-
this.maxListeners = maxListeners;
|
|
4815
|
-
}
|
|
4816
|
-
|
|
4817
|
-
on(event, listener) {
|
|
4818
|
-
if (!this.events[event]) this.events[event] = [];
|
|
4819
|
-
this.events[event].push(listener);
|
|
4820
|
-
if (this.events[event].length > this.maxListeners) {
|
|
4821
|
-
console.warn(`Warning: Possible memory leak. Event '${event}' has more than ${this.maxListeners} listeners.`);
|
|
4822
|
-
}
|
|
4823
|
-
return this;
|
|
4824
|
-
}
|
|
4825
|
-
|
|
4826
|
-
once(event, listener) {
|
|
4827
|
-
const wrapper = (...args) => {
|
|
4828
|
-
this.off(event, wrapper);
|
|
4829
|
-
listener(...args);
|
|
4830
|
-
};
|
|
4831
|
-
return this.on(event, wrapper);
|
|
4832
|
-
}
|
|
4833
|
-
|
|
4834
|
-
off(event, listener) {
|
|
4835
|
-
const listeners = this.events[event];
|
|
4836
|
-
if (!listeners) return this;
|
|
4837
|
-
|
|
4838
|
-
const index = listeners.indexOf(listener);
|
|
4839
|
-
if (index !== -1) {
|
|
4840
|
-
listeners.splice(index, 1);
|
|
4841
|
-
}
|
|
4842
|
-
|
|
4843
|
-
return this;
|
|
4844
|
-
}
|
|
4845
|
-
|
|
4846
|
-
emit(event, data) {
|
|
4847
|
-
const listeners = this.events[event];
|
|
4848
|
-
if (!listeners) return false;
|
|
4849
|
-
|
|
4850
|
-
// Make a copy so removing listeners inside callbacks doesn't affect iteration
|
|
4851
|
-
[...listeners].forEach(listener => {
|
|
4852
|
-
try {
|
|
4853
|
-
listener(data);
|
|
4854
|
-
} catch (e) {
|
|
4855
|
-
console.error(`Error in listener for '${event}':`, e);
|
|
4856
|
-
}
|
|
4857
|
-
});
|
|
4858
|
-
|
|
4859
|
-
return true;
|
|
4860
|
-
}
|
|
4861
|
-
remove(event){
|
|
4862
|
-
delete this.events[event];
|
|
4863
|
-
return this;
|
|
4864
|
-
}
|
|
4865
|
-
clear() {
|
|
4866
|
-
this.events = {};
|
|
4867
|
-
return this;
|
|
4868
|
-
}
|
|
4869
|
-
|
|
4870
|
-
setMaxListeners(max) {
|
|
4871
|
-
this.maxListeners = max;
|
|
4872
|
-
return this;
|
|
4873
|
-
}
|
|
4874
|
-
}
|
|
4875
|
-
|
|
4876
|
-
const useEventEmitter = (maxListeners) => new UseEventEmitter(maxListeners);
|
|
4877
|
-
|
|
4878
|
-
class ZikoUseFavIcon{
|
|
4879
|
-
constructor(FavIcon,withEmitter=true){
|
|
4880
|
-
this.#init();
|
|
4881
|
-
this.cache={
|
|
4882
|
-
Emitter:null
|
|
4883
|
-
};
|
|
4884
|
-
if(withEmitter)this.useEventEmitter();
|
|
4885
|
-
this.set(FavIcon);
|
|
4886
|
-
}
|
|
4887
|
-
#init(){
|
|
4888
|
-
this.__FavIcon__ = document.querySelector("link[rel*='icon']") || document?.createElement('link');
|
|
4889
|
-
this.__FavIcon__.type = 'image/x-icon';
|
|
4890
|
-
this.__FavIcon__.rel = 'shortcut icon';
|
|
4891
|
-
return this;
|
|
4892
|
-
}
|
|
4893
|
-
set(href){
|
|
4894
|
-
if(href!==this.__FavIcon__.href){
|
|
4895
|
-
this.__FavIcon__.href=href;
|
|
4896
|
-
if(this.cache.Emitter)this.cache.Emitter.emit("ziko:favicon-changed");
|
|
4897
|
-
}
|
|
4898
|
-
return this;
|
|
4899
|
-
}
|
|
4900
|
-
get current(){
|
|
4901
|
-
return document.__FavIcon__.href;
|
|
4902
|
-
}
|
|
4903
|
-
onChange(callback){
|
|
4904
|
-
if(this.cache.Emitter)this.cache.Emitter.on("ziko:favicon-changed",callback);
|
|
4905
|
-
return this;
|
|
4906
|
-
}
|
|
4907
|
-
useEventEmitter(){
|
|
4908
|
-
this.cache.Emitter=useEventEmitter();
|
|
4909
|
-
return this;
|
|
4910
|
-
}
|
|
4911
|
-
|
|
4912
|
-
}
|
|
4913
|
-
const useFavIcon=(FavIcon,withEmitter)=>new ZikoUseFavIcon(FavIcon,withEmitter);
|
|
4914
|
-
|
|
4915
|
-
class ZikoMeta{
|
|
4916
|
-
constructor({viewport,charset,description,author,keywords}){
|
|
4917
|
-
this.document = globalThis?.document;
|
|
4918
|
-
this.meta={};
|
|
4919
|
-
this.init({viewport,charset,description,author,keywords});
|
|
4920
|
-
}
|
|
4921
|
-
init({viewport,charset,description,author,keywords}){
|
|
4922
|
-
viewport && this.setViewport(viewport);
|
|
4923
|
-
charset && this.setCharset(charset);
|
|
4924
|
-
description && this.describe(description);
|
|
4925
|
-
author && this.setAuthor(author);
|
|
4926
|
-
keywords && this.setKeywords(keywords);
|
|
4927
|
-
}
|
|
4928
|
-
set(key,value){
|
|
4929
|
-
key = key.toLowerCase();
|
|
4930
|
-
const isCharset = (key === "charset");
|
|
4931
|
-
const meta = isCharset ? document.querySelector("meta[charset]"):document.querySelector(`meta[name=${key}]`);
|
|
4932
|
-
this.meta=meta?? document?.createElement("meta");
|
|
4933
|
-
if(isCharset) this.meta.setAttribute("charset",value);
|
|
4934
|
-
else {
|
|
4935
|
-
this.meta.setAttribute("name",key);
|
|
4936
|
-
this.meta.setAttribute("content",value);
|
|
4937
|
-
}
|
|
4938
|
-
if(!meta)this.document.head.append(this.meta);
|
|
4939
|
-
return this;
|
|
4940
|
-
}
|
|
4941
|
-
setCharset(charset="utf-8"){
|
|
4942
|
-
this.set("charset",charset);
|
|
4943
|
-
return this;
|
|
4944
|
-
}
|
|
4945
|
-
describe(description){
|
|
4946
|
-
this.set("description",description);
|
|
4947
|
-
return this;
|
|
4948
|
-
}
|
|
4949
|
-
setViewport(viewport="width=device-width, initial-scale=1.0"){
|
|
4950
|
-
this.set("viewport",viewport);
|
|
4951
|
-
return this;
|
|
4952
|
-
}
|
|
4953
|
-
setKeywords(...keywords){
|
|
4954
|
-
// keywords.push("zikojs");
|
|
4955
|
-
keywords=[...new Set(keywords)].join(", ");
|
|
4956
|
-
this.set("keywords",keywords);
|
|
4957
|
-
return this;
|
|
4958
|
-
}
|
|
4959
|
-
setAuthor(author){
|
|
4960
|
-
this.set("author",author);
|
|
4961
|
-
return this;
|
|
4962
|
-
}
|
|
4963
|
-
}
|
|
4964
|
-
const useMeta=({viewport,charset,description,author,keywords})=>new ZikoMeta({viewport,charset,description,author,keywords});
|
|
4965
|
-
|
|
4966
|
-
class ZikoUseTitle{
|
|
4967
|
-
constructor(title=document.title,useEventEmitter=true){
|
|
4968
|
-
this.cache={
|
|
4969
|
-
Emitter:null
|
|
4970
|
-
};
|
|
4971
|
-
if(useEventEmitter)this.useEventEmitter();
|
|
4972
|
-
this.set(title);
|
|
4973
|
-
}
|
|
4974
|
-
useEventEmitter(){
|
|
4975
|
-
this.cache.Emitter=useEventEmitter();
|
|
4976
|
-
return this;
|
|
4977
|
-
}
|
|
4978
|
-
set(title){
|
|
4979
|
-
if(title!==document.title){
|
|
4980
|
-
document.title=title;
|
|
4981
|
-
if(this.cache.Emitter)this.cache.Emitter.emit("ziko:title-changed");
|
|
4982
|
-
}
|
|
4983
|
-
return this;
|
|
4984
|
-
}
|
|
4985
|
-
get current(){
|
|
4986
|
-
return document.title;
|
|
4987
|
-
}
|
|
4988
|
-
onChange(callback){
|
|
4989
|
-
if(this.cache.Emitter)this.cache.Emitter.on("ziko:title-changed",callback);
|
|
4990
|
-
return this;
|
|
4991
|
-
}
|
|
4992
|
-
}
|
|
4993
|
-
const useTitle$1=(title, useEventEmitter)=>new ZikoUseTitle(title, useEventEmitter);
|
|
4994
|
-
|
|
4995
|
-
// import {useLink} from "./";
|
|
4996
|
-
class ZikoHead{
|
|
4997
|
-
constructor({title,lang,icon,meta,noscript}){
|
|
4998
|
-
this.html = globalThis?.document?.documentElement;
|
|
4999
|
-
this.head = globalThis?.document?.head;
|
|
5000
|
-
|
|
5001
|
-
title && useTitle$1(title);
|
|
5002
|
-
lang && this.setLang(lang);
|
|
5003
|
-
icon && useFavIcon(icon);
|
|
5004
|
-
meta && useMeta(meta);
|
|
5005
|
-
noscript && this.setNoScript();
|
|
5006
|
-
}
|
|
5007
|
-
setLang(lang){
|
|
5008
|
-
this.html.setAttribute("lang",lang);
|
|
5009
|
-
}
|
|
5010
|
-
setNoScript(content){
|
|
5011
|
-
|
|
5012
|
-
}
|
|
5013
|
-
}
|
|
5014
|
-
|
|
5015
|
-
const useHead=({ title, lang, icon, meta, noscript })=>new ZikoHead({ title, lang, icon, meta, noscript });
|
|
5016
|
-
|
|
4725
|
+
// import { ZikoHead , useHead} from "../reactivity/hooks/head/index.js";
|
|
5017
4726
|
class ZikoApp {
|
|
5018
4727
|
constructor({head = null, wrapper = null, target = null}){
|
|
5019
4728
|
this.head = head;
|
|
@@ -5040,11 +4749,11 @@
|
|
|
5040
4749
|
else if(typeof wrapper === "function") this.wrapper = wrapper();
|
|
5041
4750
|
return this;
|
|
5042
4751
|
}
|
|
5043
|
-
setHead(head){
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
}
|
|
4752
|
+
// setHead(head){
|
|
4753
|
+
// if(head instanceof ZikoHead) this.head = head;
|
|
4754
|
+
// else this.head = useHead(head);
|
|
4755
|
+
// return this;
|
|
4756
|
+
// }
|
|
5048
4757
|
|
|
5049
4758
|
}
|
|
5050
4759
|
const App = ({head, wrapper, target}) => new ZikoApp({head, wrapper, target});
|
|
@@ -5314,7 +5023,76 @@
|
|
|
5314
5023
|
terminate() {
|
|
5315
5024
|
this.#worker.terminate();
|
|
5316
5025
|
}
|
|
5317
|
-
}
|
|
5026
|
+
}
|
|
5027
|
+
|
|
5028
|
+
const useThread = (func, callback, args = [], close = true) => new UseThread().call(func, callback, args, close);
|
|
5029
|
+
|
|
5030
|
+
class UseEventEmitter {
|
|
5031
|
+
constructor(maxListeners = 10) {
|
|
5032
|
+
this.events = {};
|
|
5033
|
+
this.maxListeners = maxListeners;
|
|
5034
|
+
}
|
|
5035
|
+
|
|
5036
|
+
on(event, listener) {
|
|
5037
|
+
if (!this.events[event]) this.events[event] = [];
|
|
5038
|
+
this.events[event].push(listener);
|
|
5039
|
+
if (this.events[event].length > this.maxListeners) {
|
|
5040
|
+
console.warn(`Warning: Possible memory leak. Event '${event}' has more than ${this.maxListeners} listeners.`);
|
|
5041
|
+
}
|
|
5042
|
+
return this;
|
|
5043
|
+
}
|
|
5044
|
+
|
|
5045
|
+
once(event, listener) {
|
|
5046
|
+
const wrapper = (...args) => {
|
|
5047
|
+
this.off(event, wrapper);
|
|
5048
|
+
listener(...args);
|
|
5049
|
+
};
|
|
5050
|
+
return this.on(event, wrapper);
|
|
5051
|
+
}
|
|
5052
|
+
|
|
5053
|
+
off(event, listener) {
|
|
5054
|
+
const listeners = this.events[event];
|
|
5055
|
+
if (!listeners) return this;
|
|
5056
|
+
|
|
5057
|
+
const index = listeners.indexOf(listener);
|
|
5058
|
+
if (index !== -1) {
|
|
5059
|
+
listeners.splice(index, 1);
|
|
5060
|
+
}
|
|
5061
|
+
|
|
5062
|
+
return this;
|
|
5063
|
+
}
|
|
5064
|
+
|
|
5065
|
+
emit(event, data) {
|
|
5066
|
+
const listeners = this.events[event];
|
|
5067
|
+
if (!listeners) return false;
|
|
5068
|
+
|
|
5069
|
+
// Make a copy so removing listeners inside callbacks doesn't affect iteration
|
|
5070
|
+
[...listeners].forEach(listener => {
|
|
5071
|
+
try {
|
|
5072
|
+
listener(data);
|
|
5073
|
+
} catch (e) {
|
|
5074
|
+
console.error(`Error in listener for '${event}':`, e);
|
|
5075
|
+
}
|
|
5076
|
+
});
|
|
5077
|
+
|
|
5078
|
+
return true;
|
|
5079
|
+
}
|
|
5080
|
+
remove(event){
|
|
5081
|
+
delete this.events[event];
|
|
5082
|
+
return this;
|
|
5083
|
+
}
|
|
5084
|
+
clear() {
|
|
5085
|
+
this.events = {};
|
|
5086
|
+
return this;
|
|
5087
|
+
}
|
|
5088
|
+
|
|
5089
|
+
setMaxListeners(max) {
|
|
5090
|
+
this.maxListeners = max;
|
|
5091
|
+
return this;
|
|
5092
|
+
}
|
|
5093
|
+
}
|
|
5094
|
+
|
|
5095
|
+
const useEventEmitter = (maxListeners) => new UseEventEmitter(maxListeners);
|
|
5318
5096
|
|
|
5319
5097
|
/*
|
|
5320
5098
|
[
|
|
@@ -5414,6 +5192,75 @@
|
|
|
5414
5192
|
|
|
5415
5193
|
const useTitle = (title, withEmitter = true) => new UseTitle(title, withEmitter);
|
|
5416
5194
|
|
|
5195
|
+
class UseRoot {
|
|
5196
|
+
constructor(PropsMap, { namespace = 'Ziko', ValidateCssProps = false } = {}) {
|
|
5197
|
+
this.currentPropsMap = PropsMap;
|
|
5198
|
+
this.namespace = namespace;
|
|
5199
|
+
this.ValidateCssProps = ValidateCssProps;
|
|
5200
|
+
this.use(PropsMap);
|
|
5201
|
+
}
|
|
5202
|
+
|
|
5203
|
+
use(PropsMap) {
|
|
5204
|
+
if (this.ValidateCssProps) ValidateCssPropsFn(PropsMap);
|
|
5205
|
+
this.currentPropsMap = PropsMap;
|
|
5206
|
+
this.#maintain();
|
|
5207
|
+
return this;
|
|
5208
|
+
}
|
|
5209
|
+
|
|
5210
|
+
#maintain() {
|
|
5211
|
+
const root = globalThis?.document?.documentElement?.style;
|
|
5212
|
+
for (const prop in this.currentPropsMap) {
|
|
5213
|
+
const cssProp = this.namespace ? `--${this.namespace}-${prop}` : `--${prop}`;
|
|
5214
|
+
root.setProperty(cssProp, this.currentPropsMap[prop]);
|
|
5215
|
+
|
|
5216
|
+
Object.defineProperty(this, prop, {
|
|
5217
|
+
value: `var(${cssProp})`,
|
|
5218
|
+
writable: true,
|
|
5219
|
+
configurable: true,
|
|
5220
|
+
enumerable: false
|
|
5221
|
+
});
|
|
5222
|
+
}
|
|
5223
|
+
}
|
|
5224
|
+
}
|
|
5225
|
+
|
|
5226
|
+
function ValidateCssPropsFn(PropsMap) {
|
|
5227
|
+
const validProps = new Set(Object.keys(document.documentElement.style));
|
|
5228
|
+
for (const key in PropsMap) {
|
|
5229
|
+
if (!validProps.has(key)) {
|
|
5230
|
+
throw new Error(`Invalid CSS property: "${key}"`);
|
|
5231
|
+
}
|
|
5232
|
+
}
|
|
5233
|
+
}
|
|
5234
|
+
|
|
5235
|
+
const useRoot = (PropsMap, options = {}) => new UseRoot(PropsMap, options);
|
|
5236
|
+
|
|
5237
|
+
|
|
5238
|
+
// Usage
|
|
5239
|
+
|
|
5240
|
+
/*
|
|
5241
|
+
const Styles = {
|
|
5242
|
+
S1 : {
|
|
5243
|
+
background : 'white',
|
|
5244
|
+
color : 'darkblue'
|
|
5245
|
+
border : '2px darkblue solid"'
|
|
5246
|
+
},
|
|
5247
|
+
S2 : {
|
|
5248
|
+
background : 'darkblue',
|
|
5249
|
+
color : 'white'
|
|
5250
|
+
border : '2px green solid"'
|
|
5251
|
+
}
|
|
5252
|
+
}
|
|
5253
|
+
const {use, border, background, color} = useRoot(Style.S1)
|
|
5254
|
+
|
|
5255
|
+
tags.p("Test useRoot ").style({
|
|
5256
|
+
border,
|
|
5257
|
+
color,
|
|
5258
|
+
background,
|
|
5259
|
+
padding : '10px'
|
|
5260
|
+
})
|
|
5261
|
+
|
|
5262
|
+
*/
|
|
5263
|
+
|
|
5417
5264
|
let {sqrt, cos, sin, exp, log, cosh, sinh} = Math;
|
|
5418
5265
|
// Math.abs = new Proxy(Math.abs, {
|
|
5419
5266
|
// apply(target, thisArg, args) {
|
|
@@ -5507,26 +5354,16 @@
|
|
|
5507
5354
|
exports.UISVGWrapper = UISVGWrapper;
|
|
5508
5355
|
exports.UISwitch = UISwitch;
|
|
5509
5356
|
exports.UIView = UIView;
|
|
5357
|
+
exports.UseRoot = UseRoot;
|
|
5510
5358
|
exports.UseThread = UseThread;
|
|
5511
5359
|
exports.Utils = Utils;
|
|
5512
5360
|
exports.View = View;
|
|
5513
5361
|
exports.ZikoApp = ZikoApp;
|
|
5514
|
-
exports.
|
|
5515
|
-
exports.ZikoEventClipboard = ZikoEventClipboard;
|
|
5516
|
-
exports.ZikoEventCustom = ZikoEventCustom;
|
|
5517
|
-
exports.ZikoEventDrag = ZikoEventDrag;
|
|
5518
|
-
exports.ZikoEventFocus = ZikoEventFocus;
|
|
5519
|
-
exports.ZikoEventHash = ZikoEventHash;
|
|
5520
|
-
exports.ZikoEventKey = ZikoEventKey;
|
|
5521
|
-
exports.ZikoEventMouse = ZikoEventMouse;
|
|
5522
|
-
exports.ZikoEventPointer = ZikoEventPointer;
|
|
5523
|
-
exports.ZikoEventTouch = ZikoEventTouch;
|
|
5524
|
-
exports.ZikoEventWheel = ZikoEventWheel;
|
|
5362
|
+
exports.ZikoEvent = ZikoEvent;
|
|
5525
5363
|
exports.ZikoSPA = ZikoSPA;
|
|
5526
5364
|
exports.ZikoUIFlex = ZikoUIFlex;
|
|
5527
5365
|
exports.ZikoUISuspense = ZikoUISuspense;
|
|
5528
5366
|
exports.ZikoUIText = ZikoUIText;
|
|
5529
|
-
exports.__ZikoEvent__ = __ZikoEvent__;
|
|
5530
5367
|
exports.abs = abs;
|
|
5531
5368
|
exports.accum = accum;
|
|
5532
5369
|
exports.acos = acos$1;
|
|
@@ -5543,9 +5380,6 @@
|
|
|
5543
5380
|
exports.atan2 = atan2;
|
|
5544
5381
|
exports.atanh = atanh;
|
|
5545
5382
|
exports.back = back;
|
|
5546
|
-
exports.bindCustomEvent = bindCustomEvent;
|
|
5547
|
-
exports.bindHashEvent = bindHashEvent;
|
|
5548
|
-
exports.bindTouchEvent = bindTouchEvent;
|
|
5549
5383
|
exports.bind_click_event = bind_click_event;
|
|
5550
5384
|
exports.bind_clipboard_event = bind_clipboard_event;
|
|
5551
5385
|
exports.bind_drag_event = bind_drag_event;
|
|
@@ -5553,6 +5387,9 @@
|
|
|
5553
5387
|
exports.bind_key_event = bind_key_event;
|
|
5554
5388
|
exports.bind_mouse_event = bind_mouse_event;
|
|
5555
5389
|
exports.bind_pointer_event = bind_pointer_event;
|
|
5390
|
+
exports.bind_swipe_event = bind_swipe_event;
|
|
5391
|
+
exports.bind_touch_event = bind_touch_event;
|
|
5392
|
+
exports.bind_view_event = bind_view_event;
|
|
5556
5393
|
exports.bind_wheel_event = bind_wheel_event;
|
|
5557
5394
|
exports.cartesianProduct = cartesianProduct;
|
|
5558
5395
|
exports.ceil = ceil;
|
|
@@ -5578,6 +5415,7 @@
|
|
|
5578
5415
|
exports.div = div;
|
|
5579
5416
|
exports.e = e;
|
|
5580
5417
|
exports.elastic = elastic;
|
|
5418
|
+
exports.event_controller = event_controller;
|
|
5581
5419
|
exports.fact = fact;
|
|
5582
5420
|
exports.floor = floor;
|
|
5583
5421
|
exports.geomspace = geomspace;
|
|
@@ -5679,14 +5517,17 @@
|
|
|
5679
5517
|
exports.timeTaken = timeTaken;
|
|
5680
5518
|
exports.time_memory_Taken = time_memory_Taken;
|
|
5681
5519
|
exports.timeout = timeout;
|
|
5682
|
-
exports.
|
|
5520
|
+
exports.toggle_event_listener = toggle_event_listener;
|
|
5683
5521
|
exports.useDerived = useDerived;
|
|
5684
5522
|
exports.useEventEmitter = useEventEmitter;
|
|
5523
|
+
exports.useIPC = useIPC;
|
|
5685
5524
|
exports.useLocaleStorage = useLocaleStorage;
|
|
5686
5525
|
exports.useMediaQuery = useMediaQuery;
|
|
5687
5526
|
exports.useReactive = useReactive;
|
|
5527
|
+
exports.useRoot = useRoot;
|
|
5688
5528
|
exports.useSessionStorage = useSessionStorage;
|
|
5689
5529
|
exports.useState = useState;
|
|
5530
|
+
exports.useThread = useThread;
|
|
5690
5531
|
exports.useTitle = useTitle;
|
|
5691
5532
|
exports.wait = wait;
|
|
5692
5533
|
exports.waitForUIElm = waitForUIElm;
|