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.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,
|
|
@@ -1179,7 +1358,7 @@ const __CACHE__ = {
|
|
|
1179
1358
|
}
|
|
1180
1359
|
};
|
|
1181
1360
|
|
|
1182
|
-
class
|
|
1361
|
+
class UseIPC {
|
|
1183
1362
|
#channel;
|
|
1184
1363
|
#eventData;
|
|
1185
1364
|
#handlers;
|
|
@@ -1260,14 +1439,14 @@ class UseChannel {
|
|
|
1260
1439
|
}
|
|
1261
1440
|
}
|
|
1262
1441
|
|
|
1263
|
-
const
|
|
1442
|
+
const useIPC = (name) => new UseIPC(name);
|
|
1264
1443
|
|
|
1265
1444
|
class UseStorage {
|
|
1266
1445
|
constructor(storage, globalKey, initialValue, use_channel = true) {
|
|
1267
1446
|
this.cache = {
|
|
1268
1447
|
storage,
|
|
1269
1448
|
globalKey,
|
|
1270
|
-
channel: use_channel ?
|
|
1449
|
+
channel: use_channel ? useIPC(`Ziko:useStorage-${globalKey}`) : null,
|
|
1271
1450
|
oldItemKeys: new Set()
|
|
1272
1451
|
};
|
|
1273
1452
|
|
|
@@ -1355,7 +1534,7 @@ const useLocaleStorage = (key, initialValue, use_channel = true) =>
|
|
|
1355
1534
|
const useSessionStorage = (key, initialValue, use_channel = true) =>
|
|
1356
1535
|
new UseStorage(sessionStorage, key, initialValue, use_channel);
|
|
1357
1536
|
|
|
1358
|
-
|
|
1537
|
+
var __State__ = {
|
|
1359
1538
|
store : new Map(),
|
|
1360
1539
|
index : 0,
|
|
1361
1540
|
session_storage : null,
|
|
@@ -1389,255 +1568,15 @@ function __init__global__(){
|
|
|
1389
1568
|
}
|
|
1390
1569
|
}
|
|
1391
1570
|
|
|
1392
|
-
__init__global__();
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
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
|
-
// }
|
|
1612
|
-
|
|
1613
|
-
}
|
|
1614
|
-
|
|
1615
|
-
function register_to_class(target, ...mixins){
|
|
1616
|
-
mixins.forEach(n => _register_to_class_(target, n));
|
|
1617
|
-
}
|
|
1618
|
-
function _register_to_class_(target, mixin) {
|
|
1619
|
-
const descriptors = Object.getOwnPropertyDescriptors(mixin);
|
|
1620
|
-
for (const key of Reflect.ownKeys(descriptors)) {
|
|
1621
|
-
const desc = descriptors[key];
|
|
1622
|
-
if ('get' in desc || 'set' in desc || typeof desc.value !== 'function') {
|
|
1623
|
-
Object.defineProperty(Object.getPrototypeOf(target), key, desc);
|
|
1624
|
-
} else if (typeof desc.value === 'function') {
|
|
1625
|
-
if (!Object.getPrototypeOf(target).hasOwnProperty(key)) {
|
|
1626
|
-
Object.defineProperty(Object.getPrototypeOf(target), key, desc);
|
|
1627
|
-
}
|
|
1628
|
-
}
|
|
1629
|
-
}
|
|
1630
|
-
}
|
|
1631
|
-
|
|
1632
|
-
if(!globalThis.__Ziko__) __init__global__();
|
|
1633
|
-
|
|
1634
|
-
function useState(initialValue) {
|
|
1635
|
-
|
|
1636
|
-
const {store, index} = __Ziko__.__State__;
|
|
1637
|
-
__Ziko__.__State__.register({
|
|
1638
|
-
value : initialValue,
|
|
1639
|
-
subscribers : new Set(),
|
|
1640
|
-
paused : false
|
|
1571
|
+
if(!globalThis.__Ziko__) __init__global__();
|
|
1572
|
+
|
|
1573
|
+
function useState(initialValue) {
|
|
1574
|
+
|
|
1575
|
+
const {store, index} = __Ziko__.__State__;
|
|
1576
|
+
__Ziko__.__State__.register({
|
|
1577
|
+
value : initialValue,
|
|
1578
|
+
subscribers : new Set(),
|
|
1579
|
+
paused : false
|
|
1641
1580
|
});
|
|
1642
1581
|
|
|
1643
1582
|
let current = store.get(index);
|
|
@@ -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,16 +1799,12 @@ 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
|
-
const
|
|
1807
|
+
const EventsMap = {
|
|
1893
1808
|
'Click' : [
|
|
1894
1809
|
'Click',
|
|
1895
1810
|
'DblClick',
|
|
@@ -1935,78 +1850,109 @@ const Events = {
|
|
|
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
|
-
|
|
1954
|
-
this.cache.event = e;
|
|
1955
|
-
details_setter?.call(this);
|
|
1956
|
-
customizer?.hasOwnProperty("prototype") ? customizer?.call(this) : customizer?.call(null, this);
|
|
1957
|
-
// if(customizer?.hasOwnProperty("prototype")) customizer?.call(this)
|
|
1958
|
-
// else customizer?.call(null, this)
|
|
1959
|
-
if(this.cache.preventDefault[event_name]) e.preventDefault();
|
|
1960
|
-
if(this.cache.stopPropagation[event_name]) e.stopPropagation();
|
|
1961
|
-
if(this.cache.stopImmediatePropagation[event_name]) e.stopImmediatePropagation();
|
|
1962
|
-
|
|
1963
|
-
if(this.cache.stream.enabled[event_name]&&push_object)this.cache.stream.history[event_name].push(push_object);
|
|
1964
|
-
this.cache.callbacks[event_name]?.map(n=>n(this));
|
|
1965
|
-
}
|
|
1966
|
-
class __ZikoEvent__ {
|
|
1967
|
-
constructor(target = null, Events = [], details_setter, customizer){
|
|
1910
|
+
class ZikoEvent {
|
|
1911
|
+
constructor(signature, target = null, Events = [], details_setter, customizer){
|
|
1968
1912
|
this.target = target;
|
|
1969
1913
|
this.cache = {
|
|
1914
|
+
signature,
|
|
1970
1915
|
currentEvent : null,
|
|
1971
1916
|
event: null,
|
|
1972
1917
|
options : {},
|
|
1973
1918
|
preventDefault : {},
|
|
1974
1919
|
stopPropagation : {},
|
|
1975
1920
|
stopImmediatePropagation : {},
|
|
1976
|
-
event_flow : {},
|
|
1977
1921
|
paused : {},
|
|
1978
|
-
stream : {
|
|
1979
|
-
enabled : {},
|
|
1980
|
-
clear : {},
|
|
1981
|
-
history : {}
|
|
1982
|
-
},
|
|
1983
1922
|
callbacks : {},
|
|
1984
1923
|
__controllers__:{}
|
|
1985
1924
|
};
|
|
1986
|
-
if(Events)this._register_events(Events, details_setter, customizer);
|
|
1987
|
-
}
|
|
1988
|
-
_register_events(Events, details_setter, customizer, REGISTER_METHODES = true){
|
|
1989
|
-
const events = Events?.map(n=>getEvent(n));
|
|
1990
|
-
events?.forEach((event,i)=>{
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
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
|
+
}
|
|
1999
1939
|
});
|
|
2000
1940
|
return this;
|
|
2001
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
|
+
}
|
|
2002
1948
|
get targetElement(){
|
|
2003
1949
|
return this.target?.element;
|
|
2004
1950
|
}
|
|
2005
1951
|
get isParent(){
|
|
2006
|
-
return this.target?.element === this.event
|
|
1952
|
+
return this.target?.element === this.event?.srcElement;
|
|
2007
1953
|
}
|
|
2008
1954
|
get item(){
|
|
2009
|
-
return this.target.find(n=>n.element == this.event?.srcElement)?.[0];
|
|
1955
|
+
return this.target.find(n => n.element == this.event?.srcElement)?.[0];
|
|
2010
1956
|
}
|
|
2011
1957
|
get currentEvent(){
|
|
2012
1958
|
return this.cache.currentEvent;
|
|
@@ -2014,185 +1960,54 @@ class __ZikoEvent__ {
|
|
|
2014
1960
|
get event(){
|
|
2015
1961
|
return this.cache.event;
|
|
2016
1962
|
}
|
|
1963
|
+
get detail(){
|
|
1964
|
+
return this.cache.event.detail
|
|
1965
|
+
}
|
|
2017
1966
|
setTarget(UI){
|
|
2018
|
-
this.target=UI;
|
|
1967
|
+
this.target = UI;
|
|
2019
1968
|
return this;
|
|
2020
1969
|
}
|
|
2021
|
-
__handle(event, handler, options
|
|
1970
|
+
__handle(event, handler, options){
|
|
2022
1971
|
this.targetElement?.addEventListener(event, handler, options);
|
|
2023
1972
|
return this;
|
|
2024
1973
|
}
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
if(this.cache.
|
|
2029
|
-
|
|
2030
|
-
// this.cache.callbacks.map(n=>e=>n.call(this,e));
|
|
2031
|
-
this.cache.callbacks[event].map(n=>e=>n.call(this,e));
|
|
2032
|
-
}
|
|
2033
|
-
else {
|
|
2034
|
-
return this;
|
|
2035
|
-
}
|
|
2036
|
-
}
|
|
2037
|
-
else this.cache.callbacks[event] = callbacks.map(n=>e=>n.call(this,e));
|
|
2038
|
-
this.__handle(event, this.cache.__controllers__[event],options, dispose);
|
|
2039
|
-
return this;
|
|
2040
|
-
}
|
|
2041
|
-
#override(methode, overrides, defaultValue){
|
|
2042
|
-
if(defaultValue === "default") Object.assign(this.cache[methode], {...this.cache[methode], ...overrides});
|
|
2043
|
-
const all = defaultValue === "default"
|
|
2044
|
-
? this.cache[methode]
|
|
2045
|
-
: Object.fromEntries(Object.keys(this.cache.preventDefault).map(n=>[n,defaultValue]));
|
|
2046
|
-
Object.assign(this.cache[methode], {...all,...overrides});
|
|
2047
|
-
return this
|
|
2048
|
-
}
|
|
2049
|
-
preventDefault(overrides = {}, defaultValue = "default"){
|
|
2050
|
-
this.#override("preventDefault", overrides, defaultValue);
|
|
2051
|
-
// const all=Object.fromEntries(Object.keys(this.cache.preventDefault).map(n=>[n,defaultValue]))
|
|
2052
|
-
// 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
|
+
});
|
|
2053
1979
|
return this;
|
|
2054
1980
|
}
|
|
2055
|
-
|
|
2056
|
-
this.#override(
|
|
2057
|
-
return this;
|
|
1981
|
+
preventDefault(...events) {
|
|
1982
|
+
return this.#override('preventDefault', ...events);
|
|
2058
1983
|
}
|
|
2059
|
-
|
|
2060
|
-
this.#override(
|
|
2061
|
-
|
|
1984
|
+
stopPropagation(...events) {
|
|
1985
|
+
return this.#override('stopPropagation', ...events);
|
|
1986
|
+
}
|
|
1987
|
+
stopImmediatePropagation(...events) {
|
|
1988
|
+
return this.#override('stopImmediatePropagation', ...events);
|
|
2062
1989
|
}
|
|
2063
1990
|
setEventOptions(event, options){
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
this.
|
|
1991
|
+
const evt = getEvent(event);
|
|
1992
|
+
this.pause();
|
|
1993
|
+
Object.assign(this.cache.options[evt], options);
|
|
1994
|
+
this.resume();
|
|
2067
1995
|
return this;
|
|
2068
1996
|
}
|
|
2069
|
-
pause(
|
|
2070
|
-
|
|
2071
|
-
? this.cache.stream.enabled
|
|
2072
|
-
: Object.entries(Object.keys(this.cache.stream.enabled).map(n=>[n,defaultValue]));
|
|
2073
|
-
overrides={...all,...overrides};
|
|
2074
|
-
for(let key in overrides){
|
|
2075
|
-
if(overrides[key]){
|
|
2076
|
-
this.targetElement?.removeEventListener(key, this.cache.__controllers__[key], this.cache.options[key]);
|
|
2077
|
-
this.cache.paused[key]=true;
|
|
2078
|
-
}
|
|
2079
|
-
}
|
|
2080
|
-
return this;
|
|
1997
|
+
pause(...events) {
|
|
1998
|
+
return toggle_event_listener.call(this, 'removeEventListener', ...events)
|
|
2081
1999
|
}
|
|
2082
|
-
resume(
|
|
2083
|
-
|
|
2084
|
-
? this.cache.stream.enabled
|
|
2085
|
-
: Object.entries(Object.keys(this.cache.stream.enabled).map(n=>[n,defaultValue]));
|
|
2086
|
-
overrides={...all,...overrides};
|
|
2087
|
-
for(let key in overrides){
|
|
2088
|
-
if(overrides[key]){
|
|
2089
|
-
this.targetElement?.addEventListener(key,this.cache.__controllers__[key], this.cache.options[key]);
|
|
2090
|
-
this.cache.paused[key]=false;
|
|
2091
|
-
}
|
|
2092
|
-
}
|
|
2093
|
-
return this;
|
|
2094
|
-
}
|
|
2095
|
-
stream(overrides = {}, defaultValue = "default"){
|
|
2096
|
-
this.cache.stream.t0=Date.now();
|
|
2097
|
-
const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,defaultValue]));
|
|
2098
|
-
overrides={...all,...overrides};
|
|
2099
|
-
Object.assign(this.cache.stream.enabled,overrides);
|
|
2100
|
-
return this;
|
|
2101
|
-
}
|
|
2102
|
-
clear(){
|
|
2103
|
-
return this;
|
|
2000
|
+
resume(...events) {
|
|
2001
|
+
return toggle_event_listener.call(this, 'addEventListener', ...events);
|
|
2104
2002
|
}
|
|
2105
|
-
dispose(
|
|
2106
|
-
this.pause(
|
|
2107
|
-
|
|
2003
|
+
dispose(){
|
|
2004
|
+
this.pause();
|
|
2005
|
+
this.target.events[this.cache.signature] = null;
|
|
2108
2006
|
return this;
|
|
2109
2007
|
}
|
|
2110
2008
|
}
|
|
2111
2009
|
|
|
2112
|
-
|
|
2113
|
-
class ZikoEventClick extends __ZikoEvent__{
|
|
2114
|
-
constructor(target, customizer){
|
|
2115
|
-
super(target, Events.Click, details_setter$a, customizer);
|
|
2116
|
-
// register_click_away_event(target.element)
|
|
2117
|
-
}
|
|
2118
|
-
}
|
|
2119
|
-
function details_setter$a(){
|
|
2120
|
-
if(this.currentEvent==="click") this.dx = 0;
|
|
2121
|
-
else this.dx = 1;
|
|
2122
|
-
// console.log(this.currentEvent)
|
|
2123
|
-
}
|
|
2124
|
-
const bind_click_event = (target, customizer) => new ZikoEventClick(target, customizer);
|
|
2125
|
-
|
|
2126
|
-
class ZikoEventClipboard extends __ZikoEvent__{
|
|
2127
|
-
constructor(target, customizer){
|
|
2128
|
-
super(target, Events.Clipboard, details_setter$9, customizer);
|
|
2129
|
-
}
|
|
2130
|
-
}
|
|
2131
|
-
function details_setter$9(){
|
|
2132
|
-
|
|
2133
|
-
}
|
|
2134
|
-
const bind_clipboard_event = (target, customizer) => new ZikoEventClipboard(target, customizer);
|
|
2135
|
-
|
|
2136
|
-
class ZikoEventCustom extends __ZikoEvent__{
|
|
2137
|
-
constructor(target, events, customizer){
|
|
2138
|
-
super(target, events, details_setter$8, customizer);
|
|
2139
|
-
}
|
|
2140
|
-
_register_events(events){
|
|
2141
|
-
super._register_events(events, null, null, false);
|
|
2142
|
-
return this;
|
|
2143
|
-
}
|
|
2144
|
-
emit(event_name, details = {}){
|
|
2145
|
-
const event=new Event(event_name);
|
|
2146
|
-
this.targetElement.dispatchEvent(event);
|
|
2147
|
-
return this;
|
|
2148
|
-
}
|
|
2149
|
-
on(event_name, ...callbacks){
|
|
2150
|
-
if(!this.cache.options.hasOwnProperty(event_name)) this._register_events([event_name]);
|
|
2151
|
-
this.__onEvent(event_name, this.cache.options[event_name], {}, ...callbacks);
|
|
2152
|
-
return this;
|
|
2153
|
-
}
|
|
2154
|
-
}
|
|
2155
|
-
function details_setter$8(){
|
|
2156
|
-
|
|
2157
|
-
}
|
|
2158
|
-
const bindCustomEvent = (target, events, customizer) => new ZikoEventCustom(target, events, customizer);
|
|
2159
|
-
|
|
2160
|
-
class ZikoEventDrag extends __ZikoEvent__{
|
|
2161
|
-
constructor(target, customizer){
|
|
2162
|
-
super(target, Events.Drag, details_setter$7, customizer);
|
|
2163
|
-
}
|
|
2164
|
-
}
|
|
2165
|
-
function details_setter$7(){
|
|
2166
|
-
|
|
2167
|
-
}
|
|
2168
|
-
const bind_drag_event = (target, customizer) => new ZikoEventDrag(target, customizer);
|
|
2169
|
-
|
|
2170
|
-
class ZikoEventFocus extends __ZikoEvent__{
|
|
2171
|
-
constructor(target, customizer){
|
|
2172
|
-
super(target, Events.Focus, details_setter$6, customizer);
|
|
2173
|
-
}
|
|
2174
|
-
}
|
|
2175
|
-
function details_setter$6(){
|
|
2176
|
-
|
|
2177
|
-
}
|
|
2178
|
-
const bind_focus_event = (target, customizer) => new ZikoEventFocus(target, customizer);
|
|
2179
|
-
|
|
2180
|
-
class ZikoEventHash extends __ZikoEvent__{
|
|
2181
|
-
constructor(target, customizer){
|
|
2182
|
-
super(target, Events.Hash, details_setter$5, customizer);
|
|
2183
|
-
}
|
|
2184
|
-
}
|
|
2185
|
-
function details_setter$5(){
|
|
2186
|
-
|
|
2187
|
-
}
|
|
2188
|
-
const bindHashEvent = (target, customizer) => new ZikoEventHash(target, customizer);
|
|
2189
|
-
|
|
2190
|
-
class ZikoEventKey extends __ZikoEvent__{
|
|
2191
|
-
constructor(target, customizer){
|
|
2192
|
-
super(target, Events.Key, details_setter$4, customizer);
|
|
2193
|
-
}
|
|
2194
|
-
}
|
|
2195
|
-
function details_setter$4(){
|
|
2010
|
+
function key_details_setter(){
|
|
2196
2011
|
switch(this.currentEvent){
|
|
2197
2012
|
case "keydown" : {
|
|
2198
2013
|
this.kd = this.event.key;
|
|
@@ -2205,26 +2020,9 @@ function details_setter$4(){
|
|
|
2205
2020
|
} break;
|
|
2206
2021
|
|
|
2207
2022
|
}
|
|
2208
|
-
}
|
|
2209
|
-
const bind_key_event = (target, customizer) => new ZikoEventKey(target, customizer);
|
|
2210
|
-
|
|
2211
|
-
class ZikoEventMouse extends __ZikoEvent__{
|
|
2212
|
-
constructor(target, customizer){
|
|
2213
|
-
super(target, Events.Mouse, details_setter$3, customizer);
|
|
2214
|
-
}
|
|
2215
|
-
}
|
|
2216
|
-
function details_setter$3(){
|
|
2217
|
-
|
|
2218
|
-
}
|
|
2219
|
-
const bind_mouse_event = (target, customizer) => new ZikoEventMouse(target, customizer);
|
|
2023
|
+
}
|
|
2220
2024
|
|
|
2221
|
-
|
|
2222
|
-
constructor(target, customizer){
|
|
2223
|
-
super(target, Events.Ptr, details_setter$2, customizer);
|
|
2224
|
-
this.isDown = false;
|
|
2225
|
-
}
|
|
2226
|
-
}
|
|
2227
|
-
function details_setter$2(){
|
|
2025
|
+
function ptr_details_setter(){
|
|
2228
2026
|
switch(this.currentEvent){
|
|
2229
2027
|
case "pointerdown" : {
|
|
2230
2028
|
this.dx = parseInt(this.event.offsetX);
|
|
@@ -2256,28 +2054,314 @@ function details_setter$2(){
|
|
|
2256
2054
|
// if(this.currentEvent==="click") this.dx = 0
|
|
2257
2055
|
// else this.dx = 1
|
|
2258
2056
|
// console.log(this.currentEvent)
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2059
|
+
class ClickAwayEvent extends Event {
|
|
2060
|
+
constructor(originalEvent, targetElement) {
|
|
2061
|
+
super("clickaway", { bubbles: true, cancelable: true });
|
|
2062
|
+
this.originalEvent = originalEvent;
|
|
2063
|
+
this.targetElement = targetElement;
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
|
|
2067
|
+
function register_click_away_event(element) {
|
|
2068
|
+
console.log(element);
|
|
2069
|
+
function handler(e) {
|
|
2070
|
+
if (!element.contains(e.target)) {
|
|
2071
|
+
const clickAwayEvent = new ClickAwayEvent(e, element);
|
|
2072
|
+
element.dispatchEvent(clickAwayEvent);
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
|
|
2076
|
+
globalThis?.document?.addEventListener("click", handler);
|
|
2077
|
+
|
|
2078
|
+
return () => globalThis?.document?.removeEventListener("click", handler);
|
|
2079
|
+
|
|
2259
2080
|
}
|
|
2260
|
-
|
|
2081
|
+
|
|
2082
|
+
// // Example usage
|
|
2083
|
+
// const box = document.querySelector("#my-box");
|
|
2084
|
+
|
|
2085
|
+
// const stop = listenClickAway(box);
|
|
2086
|
+
|
|
2087
|
+
// box.addEventListener("clickaway", (e) => {
|
|
2088
|
+
// console.log("Clicked outside box!", e);
|
|
2089
|
+
// });
|
|
2090
|
+
|
|
2091
|
+
// // later, you can stop listening:
|
|
2092
|
+
// // stop();
|
|
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
|
+
};
|
|
2261
2107
|
|
|
2262
|
-
class
|
|
2263
|
-
constructor(
|
|
2264
|
-
super(
|
|
2108
|
+
class ViewEvent extends CustomEvent {
|
|
2109
|
+
constructor(type, detail, { bubbles = true, cancelable = true } = {}) {
|
|
2110
|
+
super(type, { detail, bubbles, cancelable });
|
|
2265
2111
|
}
|
|
2266
2112
|
}
|
|
2267
|
-
function details_setter$1(){
|
|
2268
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
|
+
}
|
|
2269
2185
|
}
|
|
2270
|
-
|
|
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
|
+
|
|
2249
|
+
const bind_click_event = (target, customizer) => {
|
|
2250
|
+
register_click_away_event(target.element);
|
|
2251
|
+
return new ZikoEvent(
|
|
2252
|
+
'click',
|
|
2253
|
+
target,
|
|
2254
|
+
EventsMap.Click,
|
|
2255
|
+
null,
|
|
2256
|
+
customizer
|
|
2257
|
+
);
|
|
2258
|
+
};
|
|
2259
|
+
const bind_clipboard_event = (target, customizer) => new ZikoEvent(
|
|
2260
|
+
'clipboard',
|
|
2261
|
+
target,
|
|
2262
|
+
EventsMap.Clipboard,
|
|
2263
|
+
null,
|
|
2264
|
+
customizer
|
|
2265
|
+
);
|
|
2266
|
+
const bind_drag_event = (target, customizer) => new ZikoEvent(
|
|
2267
|
+
'drag',
|
|
2268
|
+
target,
|
|
2269
|
+
EventsMap.Drag,
|
|
2270
|
+
null,
|
|
2271
|
+
customizer
|
|
2272
|
+
);
|
|
2273
|
+
const bind_focus_event = (target, customizer) => new ZikoEvent(
|
|
2274
|
+
'focus',
|
|
2275
|
+
target,
|
|
2276
|
+
EventsMap.Focus,
|
|
2277
|
+
null,
|
|
2278
|
+
customizer
|
|
2279
|
+
);
|
|
2280
|
+
const bind_key_event = (target, customizer) => new ZikoEvent(
|
|
2281
|
+
'key',
|
|
2282
|
+
target,
|
|
2283
|
+
EventsMap.Key,
|
|
2284
|
+
key_details_setter,
|
|
2285
|
+
customizer
|
|
2286
|
+
);
|
|
2287
|
+
const bind_mouse_event = (target, customizer) => new ZikoEvent(
|
|
2288
|
+
'mouse',
|
|
2289
|
+
target,
|
|
2290
|
+
EventsMap.Mouse,
|
|
2291
|
+
null,
|
|
2292
|
+
customizer
|
|
2293
|
+
);
|
|
2294
|
+
const bind_pointer_event = (target, customizer) => new ZikoEvent(
|
|
2295
|
+
'ptr',
|
|
2296
|
+
target,
|
|
2297
|
+
EventsMap.Ptr,
|
|
2298
|
+
ptr_details_setter,
|
|
2299
|
+
customizer
|
|
2300
|
+
);
|
|
2301
|
+
const bind_touch_event = (target, customizer) => new ZikoEvent(
|
|
2302
|
+
'touch',
|
|
2303
|
+
target,
|
|
2304
|
+
EventsMap.Touch,
|
|
2305
|
+
null,
|
|
2306
|
+
customizer
|
|
2307
|
+
);
|
|
2308
|
+
const bind_wheel_event = (target, customizer) => new ZikoEvent(
|
|
2309
|
+
'wheel',
|
|
2310
|
+
target,
|
|
2311
|
+
EventsMap.Wheel,
|
|
2312
|
+
null,
|
|
2313
|
+
customizer
|
|
2314
|
+
);
|
|
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
|
+
};
|
|
2326
|
+
|
|
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
|
+
};
|
|
2271
2337
|
|
|
2272
|
-
class
|
|
2273
|
-
constructor(target, customizer){
|
|
2274
|
-
super(target,
|
|
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;
|
|
2275
2359
|
}
|
|
2276
2360
|
}
|
|
2277
2361
|
function details_setter(){
|
|
2278
2362
|
|
|
2279
2363
|
}
|
|
2280
|
-
const
|
|
2364
|
+
const bind_custom_event = (target, events, customizer) => new ZikoCustomEvent(target, events, customizer);
|
|
2281
2365
|
|
|
2282
2366
|
const binderMap = {
|
|
2283
2367
|
ptr: bind_pointer_event,
|
|
@@ -2287,17 +2371,31 @@ const binderMap = {
|
|
|
2287
2371
|
drag : bind_drag_event,
|
|
2288
2372
|
clipboard : bind_clipboard_event,
|
|
2289
2373
|
focus : bind_focus_event,
|
|
2290
|
-
wheel : bind_wheel_event
|
|
2374
|
+
wheel : bind_wheel_event,
|
|
2375
|
+
view : bind_view_event,
|
|
2376
|
+
swipe : bind_swipe_event
|
|
2291
2377
|
};
|
|
2292
2378
|
|
|
2293
|
-
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
|
+
};
|
|
2294
2391
|
|
|
2295
|
-
Object.entries(
|
|
2392
|
+
Object.entries(EventsMap).forEach(([name, eventList]) => {
|
|
2393
|
+
const lname = name.toLowerCase();
|
|
2296
2394
|
eventList.forEach(event => {
|
|
2297
2395
|
const methodName = `on${event}`;
|
|
2298
|
-
EventsMethodes[methodName] = function (
|
|
2299
|
-
if (!this.events[
|
|
2300
|
-
this.events[
|
|
2396
|
+
EventsMethodes[methodName] = function (callbacks) {
|
|
2397
|
+
if (!this.events[lname]) this.events[lname] = binderMap[lname](this);
|
|
2398
|
+
this.events[lname][methodName](callbacks);
|
|
2301
2399
|
return this;
|
|
2302
2400
|
};
|
|
2303
2401
|
});
|
|
@@ -2358,158 +2456,14 @@ function animate(keyframe, {duration=1000, iterations=1, easing="ease"}={}){
|
|
|
2358
2456
|
return this;
|
|
2359
2457
|
}
|
|
2360
2458
|
|
|
2361
|
-
var StyleMethods = /*#__PURE__*/Object.freeze({
|
|
2362
|
-
__proto__: null,
|
|
2363
|
-
animate: animate,
|
|
2364
|
-
hide: hide,
|
|
2365
|
-
show: show,
|
|
2366
|
-
size: size,
|
|
2367
|
-
style: style
|
|
2368
|
-
});
|
|
2369
|
-
|
|
2370
|
-
function EVENT_CONTROLLER(e,EVENT,setter,push_object){
|
|
2371
|
-
this.event=e;
|
|
2372
|
-
if(this.cache.preventDefault[EVENT])e.preventDefault();
|
|
2373
|
-
console.log({setter});
|
|
2374
|
-
if(setter)setter();
|
|
2375
|
-
if(this.cache.stream.enabled[EVENT]&&push_object)this.cache.stream.history[EVENT].push(push_object);
|
|
2376
|
-
this.cache.callbacks[EVENT].map(n=>n(this));
|
|
2377
|
-
return this;
|
|
2378
|
-
}
|
|
2379
|
-
class ZikoEvent{
|
|
2380
|
-
constructor(target){
|
|
2381
|
-
this.target=null;
|
|
2382
|
-
this.setTarget(target);
|
|
2383
|
-
this.__dispose=this.dispose.bind(this);
|
|
2384
|
-
// this.EventIndex=Garbage.Pointer.data.length;
|
|
2385
|
-
// Garbage.Pointer.data.push({event:this,index:this.EventIndex});
|
|
2386
|
-
}
|
|
2387
|
-
get targetElement(){
|
|
2388
|
-
return this.target.element
|
|
2389
|
-
}
|
|
2390
|
-
setTarget(UI){
|
|
2391
|
-
this.target=UI;
|
|
2392
|
-
return this;
|
|
2393
|
-
}
|
|
2394
|
-
__handle(event,handler,dispose){
|
|
2395
|
-
const EVENT=(event==="drag")?event:`${this.cache.prefixe}${event}`;
|
|
2396
|
-
this.dispose(dispose);
|
|
2397
|
-
this.targetElement?.addEventListener(EVENT,handler);
|
|
2398
|
-
return this;
|
|
2399
|
-
}
|
|
2400
|
-
__onEvent(event,dispose,...callbacks){
|
|
2401
|
-
if(callbacks.length===0){
|
|
2402
|
-
if(this.cache.callbacks.length>1){
|
|
2403
|
-
this.cache.callbacks.map(n=>e=>n.call(this,e));
|
|
2404
|
-
}
|
|
2405
|
-
else {
|
|
2406
|
-
return this;
|
|
2407
|
-
}
|
|
2408
|
-
}
|
|
2409
|
-
else this.cache.callbacks[event]=callbacks.map(n=>e=>n.call(this,e));
|
|
2410
|
-
this.__handle(event,this.__controller[event],dispose);
|
|
2411
|
-
return this;
|
|
2412
|
-
}
|
|
2413
|
-
preventDefault(config={}){
|
|
2414
|
-
Object.assign(this.cache.preventDefault,config);
|
|
2415
|
-
return this;
|
|
2416
|
-
}
|
|
2417
|
-
pause(config={}){
|
|
2418
|
-
const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,true]));
|
|
2419
|
-
config={...all,...config};
|
|
2420
|
-
for(let key in config){
|
|
2421
|
-
if(config[key]){
|
|
2422
|
-
this.targetElement?.removeEventListener(`${this.cache.prefixe}${key}`,this.__controller[`${this.cache.prefixe}${key}`]);
|
|
2423
|
-
this.cache.paused[`${this.cache.prefixe}${key}`]=true;
|
|
2424
|
-
}
|
|
2425
|
-
}
|
|
2426
|
-
return this;
|
|
2427
|
-
}
|
|
2428
|
-
resume(config={}){
|
|
2429
|
-
const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,true]));
|
|
2430
|
-
config={...all,...config};
|
|
2431
|
-
for(let key in config){
|
|
2432
|
-
if(config[key]){
|
|
2433
|
-
this.targetElement?.addEventListener(`${this.cache.prefixe}${key}`,this.__controller[`${this.cache.prefixe}${key}`]);
|
|
2434
|
-
this.cache.paused[`${this.cache.prefixe}${key}`]=false;
|
|
2435
|
-
}
|
|
2436
|
-
}
|
|
2437
|
-
return this;
|
|
2438
|
-
}
|
|
2439
|
-
dispose(config={}){
|
|
2440
|
-
this.pause(config);
|
|
2441
|
-
return this;
|
|
2442
|
-
}
|
|
2443
|
-
stream(config={}){
|
|
2444
|
-
this.cache.stream.t0=Date.now();
|
|
2445
|
-
const all=Object.fromEntries(Object.keys(this.cache.stream.enabled).map(n=>[n,true]));
|
|
2446
|
-
config={...all,...config};
|
|
2447
|
-
Object.assign(this.cache.stream.enabled,config);
|
|
2448
|
-
return this;
|
|
2449
|
-
}
|
|
2450
|
-
clear(config={}){
|
|
2451
|
-
const all=Object.fromEntries(Object.keys(this.cache.stream.clear).map(n=>[n,true]));
|
|
2452
|
-
config={...all,...config};
|
|
2453
|
-
for(let key in config){
|
|
2454
|
-
if(config[key]){
|
|
2455
|
-
this.cache.stream.history[key]=[];
|
|
2456
|
-
}
|
|
2457
|
-
}
|
|
2458
|
-
return this;
|
|
2459
|
-
}
|
|
2460
|
-
}
|
|
2461
|
-
|
|
2462
|
-
const custom_event_controller=event_name=>function(e){
|
|
2463
|
-
EVENT_CONTROLLER.call(this,e,event_name,null,null);
|
|
2464
|
-
};
|
|
2465
|
-
class ZikoCustomEvent extends ZikoEvent{
|
|
2466
|
-
constructor(target){
|
|
2467
|
-
super(target);
|
|
2468
|
-
this.event=null;
|
|
2469
|
-
this.cache={
|
|
2470
|
-
prefixe:"",
|
|
2471
|
-
preventDefault:{
|
|
2472
|
-
},
|
|
2473
|
-
paused:{
|
|
2474
|
-
},
|
|
2475
|
-
stream:{
|
|
2476
|
-
enabled:{
|
|
2477
|
-
},
|
|
2478
|
-
clear:{
|
|
2479
|
-
},
|
|
2480
|
-
history:{
|
|
2481
|
-
}
|
|
2482
|
-
},
|
|
2483
|
-
callbacks:{
|
|
2484
|
-
}
|
|
2485
|
-
};
|
|
2486
|
-
this.__controller={
|
|
2487
|
-
};
|
|
2488
|
-
}
|
|
2489
|
-
#init(event_name){
|
|
2490
|
-
this.cache.preventDefault[event_name]=false;
|
|
2491
|
-
this.cache.paused[event_name]=false;
|
|
2492
|
-
this.cache.stream.enabled=false;
|
|
2493
|
-
this.cache.stream.clear=false;
|
|
2494
|
-
this.cache.stream.history=[];
|
|
2495
|
-
this.cache.callbacks[event_name]=[];
|
|
2496
|
-
this.__controller[event_name]=custom_event_controller(event_name).bind(this);
|
|
2497
|
-
return this;
|
|
2498
|
-
}
|
|
2499
|
-
on(event_name,...callbacks){
|
|
2500
|
-
if(!(this.__controller[event_name]))this.#init(event_name);
|
|
2501
|
-
this.__onEvent(event_name,{},...callbacks);
|
|
2502
|
-
return this;
|
|
2503
|
-
}
|
|
2504
|
-
emit(event_name,detail={}){
|
|
2505
|
-
if(!(this.__controller[event_name]))this.#init(event_name);
|
|
2506
|
-
this.detail=detail;
|
|
2507
|
-
const event=new Event(event_name);
|
|
2508
|
-
this.targetElement.dispatchEvent(event);
|
|
2509
|
-
return this;
|
|
2510
|
-
}
|
|
2511
|
-
}
|
|
2512
|
-
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
|
+
});
|
|
2513
2467
|
|
|
2514
2468
|
let UIElement$1 = class UIElement extends UIElementCore{
|
|
2515
2469
|
constructor({element, name ='', type='html', render = __Ziko__.__Config__.default.render}={}){
|
|
@@ -2518,12 +2472,15 @@ let UIElement$1 = class UIElement extends UIElementCore{
|
|
|
2518
2472
|
// console.log(this)
|
|
2519
2473
|
register_to_class(
|
|
2520
2474
|
this,
|
|
2475
|
+
LifecycleMethods,
|
|
2521
2476
|
AttrsMethods,
|
|
2522
2477
|
DomMethods,
|
|
2523
2478
|
StyleMethods,
|
|
2524
2479
|
IndexingMethods,
|
|
2525
2480
|
EventsMethodes
|
|
2526
2481
|
);
|
|
2482
|
+
|
|
2483
|
+
// console.log(EventsMethodes)
|
|
2527
2484
|
if(element)this.init(element, name, type, render);
|
|
2528
2485
|
}
|
|
2529
2486
|
get element(){
|
|
@@ -2645,32 +2602,12 @@ let UIElement$1 = class UIElement extends UIElementCore{
|
|
|
2645
2602
|
// get id() {
|
|
2646
2603
|
// return this.element.getAttribute("id");
|
|
2647
2604
|
// }
|
|
2648
|
-
// onSwipe(width_threshold, height_threshold,...callbacks){
|
|
2649
|
-
// if(!this.events.swipe)this.events.swipe = useSwipeEvent(this, width_threshold, height_threshold);
|
|
2650
|
-
// this.events.swipe.onSwipe(...callbacks);
|
|
2651
|
-
// return this;
|
|
2652
|
-
// }
|
|
2653
2605
|
// To Fix
|
|
2654
2606
|
// onKeysDown({keys=[],callback}={}){
|
|
2655
2607
|
// if(!this.events.key)this.events.key = useKeyEvent(this);
|
|
2656
2608
|
// this.events.key.handleSuccessifKeys({keys,callback});
|
|
2657
2609
|
// return this;
|
|
2658
2610
|
// }
|
|
2659
|
-
// onSelect(...callbacks){
|
|
2660
|
-
// if(!this.events.clipboard)this.events.clipboard = useClipboardEvent(this);
|
|
2661
|
-
// this.events.clipboard.onSelect(...callbacks);
|
|
2662
|
-
// return this;
|
|
2663
|
-
// }
|
|
2664
|
-
on(event_name,...callbacks){
|
|
2665
|
-
if(!this.events.custom)this.events.custom = useCustomEvent(this);
|
|
2666
|
-
this.events.custom.on(event_name,...callbacks);
|
|
2667
|
-
return this;
|
|
2668
|
-
}
|
|
2669
|
-
emit(event_name,detail={}){
|
|
2670
|
-
if(!this.events.custom)this.events.custom = useCustomEvent(this);
|
|
2671
|
-
this.events.custom.emit(event_name,detail);
|
|
2672
|
-
return this;
|
|
2673
|
-
}
|
|
2674
2611
|
// watchAttr(callback){
|
|
2675
2612
|
// if(!this.observer.attr)this.observer.attr = watchAttr(this,callback);
|
|
2676
2613
|
// return this;
|
|
@@ -2679,16 +2616,8 @@ let UIElement$1 = class UIElement extends UIElementCore{
|
|
|
2679
2616
|
// if(!this.observer.children)this.observer.children = watchChildren(this,callback);
|
|
2680
2617
|
// return this;
|
|
2681
2618
|
// }
|
|
2682
|
-
// watchSize(callback)
|
|
2683
|
-
//
|
|
2684
|
-
// this.observer.resize.start();
|
|
2685
|
-
// return this;
|
|
2686
|
-
// }
|
|
2687
|
-
// watchIntersection(callback,config){
|
|
2688
|
-
// if(!this.observer.intersection)this.observer.intersection = watchIntersection(this,callback,config);
|
|
2689
|
-
// this.observer.intersection.start();
|
|
2690
|
-
// return this;
|
|
2691
|
-
// }
|
|
2619
|
+
// watchSize(callback)Remplaced By on onViewResize
|
|
2620
|
+
// watchIntersection(callback,config) Remplaced By onViewEnter and onViewExit
|
|
2692
2621
|
|
|
2693
2622
|
};
|
|
2694
2623
|
|
|
@@ -2987,7 +2916,6 @@ class ZikoUISuspense extends UIElement{
|
|
|
2987
2916
|
const ui = await callback();
|
|
2988
2917
|
fallback_ui.unmount();
|
|
2989
2918
|
this.append(ui);
|
|
2990
|
-
// console.log(content)
|
|
2991
2919
|
}
|
|
2992
2920
|
catch(error){
|
|
2993
2921
|
console.log({error});
|
|
@@ -4618,20 +4546,6 @@ const Scheduler = (tasks, { repeat = null} = {}) => new TimeScheduler(tasks, { r
|
|
|
4618
4546
|
|
|
4619
4547
|
const step_fps = (step_or_fps) => 1000 / step_or_fps;
|
|
4620
4548
|
|
|
4621
|
-
const debounce=(fn,delay=1000)=>{
|
|
4622
|
-
let id;
|
|
4623
|
-
return (...args) => id ? clearTimeout(id) : setTimeout(()=>fn(...args),delay);
|
|
4624
|
-
};
|
|
4625
|
-
const throttle=(fn,delay)=>{
|
|
4626
|
-
let lastTime=0;
|
|
4627
|
-
return (...args) => {
|
|
4628
|
-
const now = new Date().getTime();
|
|
4629
|
-
if(now-lastTime < delay) return;
|
|
4630
|
-
lastTime = now;
|
|
4631
|
-
fn(...args);
|
|
4632
|
-
}
|
|
4633
|
-
};
|
|
4634
|
-
|
|
4635
4549
|
const sleep= ms => new Promise(res => setTimeout(res, ms));
|
|
4636
4550
|
function timeout(ms, fn) {
|
|
4637
4551
|
let id;
|
|
@@ -4804,212 +4718,7 @@ const timeTaken = callback => {
|
|
|
4804
4718
|
return r;
|
|
4805
4719
|
};
|
|
4806
4720
|
|
|
4807
|
-
|
|
4808
|
-
constructor(maxListeners = 10) {
|
|
4809
|
-
this.events = {};
|
|
4810
|
-
this.maxListeners = maxListeners;
|
|
4811
|
-
}
|
|
4812
|
-
|
|
4813
|
-
on(event, listener) {
|
|
4814
|
-
if (!this.events[event]) this.events[event] = [];
|
|
4815
|
-
this.events[event].push(listener);
|
|
4816
|
-
if (this.events[event].length > this.maxListeners) {
|
|
4817
|
-
console.warn(`Warning: Possible memory leak. Event '${event}' has more than ${this.maxListeners} listeners.`);
|
|
4818
|
-
}
|
|
4819
|
-
return this;
|
|
4820
|
-
}
|
|
4821
|
-
|
|
4822
|
-
once(event, listener) {
|
|
4823
|
-
const wrapper = (...args) => {
|
|
4824
|
-
this.off(event, wrapper);
|
|
4825
|
-
listener(...args);
|
|
4826
|
-
};
|
|
4827
|
-
return this.on(event, wrapper);
|
|
4828
|
-
}
|
|
4829
|
-
|
|
4830
|
-
off(event, listener) {
|
|
4831
|
-
const listeners = this.events[event];
|
|
4832
|
-
if (!listeners) return this;
|
|
4833
|
-
|
|
4834
|
-
const index = listeners.indexOf(listener);
|
|
4835
|
-
if (index !== -1) {
|
|
4836
|
-
listeners.splice(index, 1);
|
|
4837
|
-
}
|
|
4838
|
-
|
|
4839
|
-
return this;
|
|
4840
|
-
}
|
|
4841
|
-
|
|
4842
|
-
emit(event, data) {
|
|
4843
|
-
const listeners = this.events[event];
|
|
4844
|
-
if (!listeners) return false;
|
|
4845
|
-
|
|
4846
|
-
// Make a copy so removing listeners inside callbacks doesn't affect iteration
|
|
4847
|
-
[...listeners].forEach(listener => {
|
|
4848
|
-
try {
|
|
4849
|
-
listener(data);
|
|
4850
|
-
} catch (e) {
|
|
4851
|
-
console.error(`Error in listener for '${event}':`, e);
|
|
4852
|
-
}
|
|
4853
|
-
});
|
|
4854
|
-
|
|
4855
|
-
return true;
|
|
4856
|
-
}
|
|
4857
|
-
remove(event){
|
|
4858
|
-
delete this.events[event];
|
|
4859
|
-
return this;
|
|
4860
|
-
}
|
|
4861
|
-
clear() {
|
|
4862
|
-
this.events = {};
|
|
4863
|
-
return this;
|
|
4864
|
-
}
|
|
4865
|
-
|
|
4866
|
-
setMaxListeners(max) {
|
|
4867
|
-
this.maxListeners = max;
|
|
4868
|
-
return this;
|
|
4869
|
-
}
|
|
4870
|
-
}
|
|
4871
|
-
|
|
4872
|
-
const useEventEmitter = (maxListeners) => new UseEventEmitter(maxListeners);
|
|
4873
|
-
|
|
4874
|
-
class ZikoUseFavIcon{
|
|
4875
|
-
constructor(FavIcon,withEmitter=true){
|
|
4876
|
-
this.#init();
|
|
4877
|
-
this.cache={
|
|
4878
|
-
Emitter:null
|
|
4879
|
-
};
|
|
4880
|
-
if(withEmitter)this.useEventEmitter();
|
|
4881
|
-
this.set(FavIcon);
|
|
4882
|
-
}
|
|
4883
|
-
#init(){
|
|
4884
|
-
this.__FavIcon__ = document.querySelector("link[rel*='icon']") || document?.createElement('link');
|
|
4885
|
-
this.__FavIcon__.type = 'image/x-icon';
|
|
4886
|
-
this.__FavIcon__.rel = 'shortcut icon';
|
|
4887
|
-
return this;
|
|
4888
|
-
}
|
|
4889
|
-
set(href){
|
|
4890
|
-
if(href!==this.__FavIcon__.href){
|
|
4891
|
-
this.__FavIcon__.href=href;
|
|
4892
|
-
if(this.cache.Emitter)this.cache.Emitter.emit("ziko:favicon-changed");
|
|
4893
|
-
}
|
|
4894
|
-
return this;
|
|
4895
|
-
}
|
|
4896
|
-
get current(){
|
|
4897
|
-
return document.__FavIcon__.href;
|
|
4898
|
-
}
|
|
4899
|
-
onChange(callback){
|
|
4900
|
-
if(this.cache.Emitter)this.cache.Emitter.on("ziko:favicon-changed",callback);
|
|
4901
|
-
return this;
|
|
4902
|
-
}
|
|
4903
|
-
useEventEmitter(){
|
|
4904
|
-
this.cache.Emitter=useEventEmitter();
|
|
4905
|
-
return this;
|
|
4906
|
-
}
|
|
4907
|
-
|
|
4908
|
-
}
|
|
4909
|
-
const useFavIcon=(FavIcon,withEmitter)=>new ZikoUseFavIcon(FavIcon,withEmitter);
|
|
4910
|
-
|
|
4911
|
-
class ZikoMeta{
|
|
4912
|
-
constructor({viewport,charset,description,author,keywords}){
|
|
4913
|
-
this.document = globalThis?.document;
|
|
4914
|
-
this.meta={};
|
|
4915
|
-
this.init({viewport,charset,description,author,keywords});
|
|
4916
|
-
}
|
|
4917
|
-
init({viewport,charset,description,author,keywords}){
|
|
4918
|
-
viewport && this.setViewport(viewport);
|
|
4919
|
-
charset && this.setCharset(charset);
|
|
4920
|
-
description && this.describe(description);
|
|
4921
|
-
author && this.setAuthor(author);
|
|
4922
|
-
keywords && this.setKeywords(keywords);
|
|
4923
|
-
}
|
|
4924
|
-
set(key,value){
|
|
4925
|
-
key = key.toLowerCase();
|
|
4926
|
-
const isCharset = (key === "charset");
|
|
4927
|
-
const meta = isCharset ? document.querySelector("meta[charset]"):document.querySelector(`meta[name=${key}]`);
|
|
4928
|
-
this.meta=meta?? document?.createElement("meta");
|
|
4929
|
-
if(isCharset) this.meta.setAttribute("charset",value);
|
|
4930
|
-
else {
|
|
4931
|
-
this.meta.setAttribute("name",key);
|
|
4932
|
-
this.meta.setAttribute("content",value);
|
|
4933
|
-
}
|
|
4934
|
-
if(!meta)this.document.head.append(this.meta);
|
|
4935
|
-
return this;
|
|
4936
|
-
}
|
|
4937
|
-
setCharset(charset="utf-8"){
|
|
4938
|
-
this.set("charset",charset);
|
|
4939
|
-
return this;
|
|
4940
|
-
}
|
|
4941
|
-
describe(description){
|
|
4942
|
-
this.set("description",description);
|
|
4943
|
-
return this;
|
|
4944
|
-
}
|
|
4945
|
-
setViewport(viewport="width=device-width, initial-scale=1.0"){
|
|
4946
|
-
this.set("viewport",viewport);
|
|
4947
|
-
return this;
|
|
4948
|
-
}
|
|
4949
|
-
setKeywords(...keywords){
|
|
4950
|
-
// keywords.push("zikojs");
|
|
4951
|
-
keywords=[...new Set(keywords)].join(", ");
|
|
4952
|
-
this.set("keywords",keywords);
|
|
4953
|
-
return this;
|
|
4954
|
-
}
|
|
4955
|
-
setAuthor(author){
|
|
4956
|
-
this.set("author",author);
|
|
4957
|
-
return this;
|
|
4958
|
-
}
|
|
4959
|
-
}
|
|
4960
|
-
const useMeta=({viewport,charset,description,author,keywords})=>new ZikoMeta({viewport,charset,description,author,keywords});
|
|
4961
|
-
|
|
4962
|
-
class ZikoUseTitle{
|
|
4963
|
-
constructor(title=document.title,useEventEmitter=true){
|
|
4964
|
-
this.cache={
|
|
4965
|
-
Emitter:null
|
|
4966
|
-
};
|
|
4967
|
-
if(useEventEmitter)this.useEventEmitter();
|
|
4968
|
-
this.set(title);
|
|
4969
|
-
}
|
|
4970
|
-
useEventEmitter(){
|
|
4971
|
-
this.cache.Emitter=useEventEmitter();
|
|
4972
|
-
return this;
|
|
4973
|
-
}
|
|
4974
|
-
set(title){
|
|
4975
|
-
if(title!==document.title){
|
|
4976
|
-
document.title=title;
|
|
4977
|
-
if(this.cache.Emitter)this.cache.Emitter.emit("ziko:title-changed");
|
|
4978
|
-
}
|
|
4979
|
-
return this;
|
|
4980
|
-
}
|
|
4981
|
-
get current(){
|
|
4982
|
-
return document.title;
|
|
4983
|
-
}
|
|
4984
|
-
onChange(callback){
|
|
4985
|
-
if(this.cache.Emitter)this.cache.Emitter.on("ziko:title-changed",callback);
|
|
4986
|
-
return this;
|
|
4987
|
-
}
|
|
4988
|
-
}
|
|
4989
|
-
const useTitle$1=(title, useEventEmitter)=>new ZikoUseTitle(title, useEventEmitter);
|
|
4990
|
-
|
|
4991
|
-
// import {useLink} from "./";
|
|
4992
|
-
class ZikoHead{
|
|
4993
|
-
constructor({title,lang,icon,meta,noscript}){
|
|
4994
|
-
this.html = globalThis?.document?.documentElement;
|
|
4995
|
-
this.head = globalThis?.document?.head;
|
|
4996
|
-
|
|
4997
|
-
title && useTitle$1(title);
|
|
4998
|
-
lang && this.setLang(lang);
|
|
4999
|
-
icon && useFavIcon(icon);
|
|
5000
|
-
meta && useMeta(meta);
|
|
5001
|
-
noscript && this.setNoScript();
|
|
5002
|
-
}
|
|
5003
|
-
setLang(lang){
|
|
5004
|
-
this.html.setAttribute("lang",lang);
|
|
5005
|
-
}
|
|
5006
|
-
setNoScript(content){
|
|
5007
|
-
|
|
5008
|
-
}
|
|
5009
|
-
}
|
|
5010
|
-
|
|
5011
|
-
const useHead=({ title, lang, icon, meta, noscript })=>new ZikoHead({ title, lang, icon, meta, noscript });
|
|
5012
|
-
|
|
4721
|
+
// import { ZikoHead , useHead} from "../reactivity/hooks/head/index.js";
|
|
5013
4722
|
class ZikoApp {
|
|
5014
4723
|
constructor({head = null, wrapper = null, target = null}){
|
|
5015
4724
|
this.head = head;
|
|
@@ -5036,11 +4745,11 @@ class ZikoApp {
|
|
|
5036
4745
|
else if(typeof wrapper === "function") this.wrapper = wrapper();
|
|
5037
4746
|
return this;
|
|
5038
4747
|
}
|
|
5039
|
-
setHead(head){
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
}
|
|
4748
|
+
// setHead(head){
|
|
4749
|
+
// if(head instanceof ZikoHead) this.head = head;
|
|
4750
|
+
// else this.head = useHead(head);
|
|
4751
|
+
// return this;
|
|
4752
|
+
// }
|
|
5044
4753
|
|
|
5045
4754
|
}
|
|
5046
4755
|
const App = ({head, wrapper, target}) => new ZikoApp({head, wrapper, target});
|
|
@@ -5310,7 +5019,76 @@ class UseThread {
|
|
|
5310
5019
|
terminate() {
|
|
5311
5020
|
this.#worker.terminate();
|
|
5312
5021
|
}
|
|
5313
|
-
}
|
|
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);
|
|
5314
5092
|
|
|
5315
5093
|
/*
|
|
5316
5094
|
[
|
|
@@ -5410,6 +5188,75 @@ class UseTitle {
|
|
|
5410
5188
|
|
|
5411
5189
|
const useTitle = (title, withEmitter = true) => new UseTitle(title, withEmitter);
|
|
5412
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
|
+
|
|
5413
5260
|
let {sqrt, cos, sin, exp, log, cosh, sinh} = Math;
|
|
5414
5261
|
// Math.abs = new Proxy(Math.abs, {
|
|
5415
5262
|
// apply(target, thisArg, args) {
|
|
@@ -5503,26 +5350,16 @@ exports.UINode = UINode;
|
|
|
5503
5350
|
exports.UISVGWrapper = UISVGWrapper;
|
|
5504
5351
|
exports.UISwitch = UISwitch;
|
|
5505
5352
|
exports.UIView = UIView;
|
|
5353
|
+
exports.UseRoot = UseRoot;
|
|
5506
5354
|
exports.UseThread = UseThread;
|
|
5507
5355
|
exports.Utils = Utils;
|
|
5508
5356
|
exports.View = View;
|
|
5509
5357
|
exports.ZikoApp = ZikoApp;
|
|
5510
|
-
exports.
|
|
5511
|
-
exports.ZikoEventClipboard = ZikoEventClipboard;
|
|
5512
|
-
exports.ZikoEventCustom = ZikoEventCustom;
|
|
5513
|
-
exports.ZikoEventDrag = ZikoEventDrag;
|
|
5514
|
-
exports.ZikoEventFocus = ZikoEventFocus;
|
|
5515
|
-
exports.ZikoEventHash = ZikoEventHash;
|
|
5516
|
-
exports.ZikoEventKey = ZikoEventKey;
|
|
5517
|
-
exports.ZikoEventMouse = ZikoEventMouse;
|
|
5518
|
-
exports.ZikoEventPointer = ZikoEventPointer;
|
|
5519
|
-
exports.ZikoEventTouch = ZikoEventTouch;
|
|
5520
|
-
exports.ZikoEventWheel = ZikoEventWheel;
|
|
5358
|
+
exports.ZikoEvent = ZikoEvent;
|
|
5521
5359
|
exports.ZikoSPA = ZikoSPA;
|
|
5522
5360
|
exports.ZikoUIFlex = ZikoUIFlex;
|
|
5523
5361
|
exports.ZikoUISuspense = ZikoUISuspense;
|
|
5524
5362
|
exports.ZikoUIText = ZikoUIText;
|
|
5525
|
-
exports.__ZikoEvent__ = __ZikoEvent__;
|
|
5526
5363
|
exports.abs = abs;
|
|
5527
5364
|
exports.accum = accum;
|
|
5528
5365
|
exports.acos = acos$1;
|
|
@@ -5539,9 +5376,6 @@ exports.atan = atan;
|
|
|
5539
5376
|
exports.atan2 = atan2;
|
|
5540
5377
|
exports.atanh = atanh;
|
|
5541
5378
|
exports.back = back;
|
|
5542
|
-
exports.bindCustomEvent = bindCustomEvent;
|
|
5543
|
-
exports.bindHashEvent = bindHashEvent;
|
|
5544
|
-
exports.bindTouchEvent = bindTouchEvent;
|
|
5545
5379
|
exports.bind_click_event = bind_click_event;
|
|
5546
5380
|
exports.bind_clipboard_event = bind_clipboard_event;
|
|
5547
5381
|
exports.bind_drag_event = bind_drag_event;
|
|
@@ -5549,6 +5383,9 @@ exports.bind_focus_event = bind_focus_event;
|
|
|
5549
5383
|
exports.bind_key_event = bind_key_event;
|
|
5550
5384
|
exports.bind_mouse_event = bind_mouse_event;
|
|
5551
5385
|
exports.bind_pointer_event = bind_pointer_event;
|
|
5386
|
+
exports.bind_swipe_event = bind_swipe_event;
|
|
5387
|
+
exports.bind_touch_event = bind_touch_event;
|
|
5388
|
+
exports.bind_view_event = bind_view_event;
|
|
5552
5389
|
exports.bind_wheel_event = bind_wheel_event;
|
|
5553
5390
|
exports.cartesianProduct = cartesianProduct;
|
|
5554
5391
|
exports.ceil = ceil;
|
|
@@ -5574,6 +5411,7 @@ exports.discret = discret;
|
|
|
5574
5411
|
exports.div = div;
|
|
5575
5412
|
exports.e = e;
|
|
5576
5413
|
exports.elastic = elastic;
|
|
5414
|
+
exports.event_controller = event_controller;
|
|
5577
5415
|
exports.fact = fact;
|
|
5578
5416
|
exports.floor = floor;
|
|
5579
5417
|
exports.geomspace = geomspace;
|
|
@@ -5675,14 +5513,17 @@ exports.tick = tick;
|
|
|
5675
5513
|
exports.timeTaken = timeTaken;
|
|
5676
5514
|
exports.time_memory_Taken = time_memory_Taken;
|
|
5677
5515
|
exports.timeout = timeout;
|
|
5678
|
-
exports.
|
|
5516
|
+
exports.toggle_event_listener = toggle_event_listener;
|
|
5679
5517
|
exports.useDerived = useDerived;
|
|
5680
5518
|
exports.useEventEmitter = useEventEmitter;
|
|
5519
|
+
exports.useIPC = useIPC;
|
|
5681
5520
|
exports.useLocaleStorage = useLocaleStorage;
|
|
5682
5521
|
exports.useMediaQuery = useMediaQuery;
|
|
5683
5522
|
exports.useReactive = useReactive;
|
|
5523
|
+
exports.useRoot = useRoot;
|
|
5684
5524
|
exports.useSessionStorage = useSessionStorage;
|
|
5685
5525
|
exports.useState = useState;
|
|
5526
|
+
exports.useThread = useThread;
|
|
5686
5527
|
exports.useTitle = useTitle;
|
|
5687
5528
|
exports.wait = wait;
|
|
5688
5529
|
exports.waitForUIElm = waitForUIElm;
|