ziko 0.46.0 → 0.46.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 +254 -864
- package/dist/ziko.js +254 -864
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +254 -844
- package/package.json +1 -1
- package/src/index.js +1 -1
- package/src/ui/__methods__/events.js +1 -1
- package/src/ui/__methods__/utils/index.js +1 -1
- package/src/ui/constructors/UIElement-lite.js +1 -1
- package/src/ui/constructors/UIElement.js +6 -6
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 : Thu Oct 09 2025 16:04:28 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
|
|
@@ -1575,7 +1575,7 @@ async function __addItem__(adder, pusher, ...ele) {
|
|
|
1575
1575
|
return this;
|
|
1576
1576
|
}
|
|
1577
1577
|
function _set_attrs_(name, value){
|
|
1578
|
-
if(this.element instanceof globalThis
|
|
1578
|
+
if(globalThis.SVGAElement && this.element instanceof globalThis.SVGAElement) name = is_camelcase$1(name) ? camel2hyphencase$1(name) : name;
|
|
1579
1579
|
if(this?.attr[name] && this?.attr[name]===value) return;
|
|
1580
1580
|
if(isStateGetter(value)){
|
|
1581
1581
|
const getter = value();
|
|
@@ -2005,15 +2005,15 @@ function details_setter$6(){
|
|
|
2005
2005
|
}
|
|
2006
2006
|
const bind_focus_event = (target, customizer) => new ZikoEventFocus(target, customizer);
|
|
2007
2007
|
|
|
2008
|
-
|
|
2008
|
+
class ZikoEventHash extends __ZikoEvent__{
|
|
2009
2009
|
constructor(target, customizer){
|
|
2010
2010
|
super(target, Events.Hash, details_setter$5, customizer);
|
|
2011
2011
|
}
|
|
2012
|
-
}
|
|
2012
|
+
}
|
|
2013
2013
|
function details_setter$5(){
|
|
2014
2014
|
|
|
2015
2015
|
}
|
|
2016
|
-
const bindHashEvent = (target, customizer) => new ZikoEventHash
|
|
2016
|
+
const bindHashEvent = (target, customizer) => new ZikoEventHash(target, customizer);
|
|
2017
2017
|
|
|
2018
2018
|
class ZikoEventKey extends __ZikoEvent__{
|
|
2019
2019
|
constructor(target, customizer){
|
|
@@ -2287,850 +2287,57 @@ class ZikoEvent{
|
|
|
2287
2287
|
}
|
|
2288
2288
|
}
|
|
2289
2289
|
|
|
2290
|
-
function input_controller(e){
|
|
2291
|
-
EVENT_CONTROLLER.call(this,e,"input",null,null);
|
|
2292
|
-
}
|
|
2293
|
-
function change_controller(e){
|
|
2294
|
-
EVENT_CONTROLLER.call(this,e,"change",null,null);
|
|
2295
|
-
}
|
|
2296
|
-
class ZikoEventInput extends ZikoEvent{
|
|
2297
|
-
constructor(target){
|
|
2298
|
-
super(target);
|
|
2299
|
-
this.event=null;
|
|
2300
|
-
this.cache={
|
|
2301
|
-
prefixe:"",
|
|
2302
|
-
preventDefault:{
|
|
2303
|
-
input:false,
|
|
2304
|
-
change:false,
|
|
2305
|
-
},
|
|
2306
|
-
paused:{
|
|
2307
|
-
input:false,
|
|
2308
|
-
change:false,
|
|
2309
|
-
},
|
|
2310
|
-
stream:{
|
|
2311
|
-
enabled:{
|
|
2312
|
-
input:false,
|
|
2313
|
-
change:false,
|
|
2314
|
-
},
|
|
2315
|
-
clear:{
|
|
2316
|
-
input:false,
|
|
2317
|
-
change:false,
|
|
2318
|
-
},
|
|
2319
|
-
history:{
|
|
2320
|
-
input:[],
|
|
2321
|
-
change:[],
|
|
2322
|
-
}
|
|
2323
|
-
},
|
|
2324
|
-
callbacks:{
|
|
2325
|
-
input:[],
|
|
2326
|
-
change:[],
|
|
2327
|
-
}
|
|
2328
|
-
};
|
|
2329
|
-
this.__controller={
|
|
2330
|
-
input:input_controller.bind(this),
|
|
2331
|
-
change:change_controller.bind(this),
|
|
2332
|
-
};
|
|
2333
|
-
}
|
|
2334
|
-
get value(){
|
|
2335
|
-
return this.target.value;
|
|
2336
|
-
}
|
|
2337
|
-
onInput(...callbacks){
|
|
2338
|
-
this.__onEvent("input",{},...callbacks);
|
|
2339
|
-
return this;
|
|
2340
|
-
}
|
|
2341
|
-
onChange(...callbacks){
|
|
2342
|
-
this.__onEvent("change",{},...callbacks);
|
|
2343
|
-
return this;
|
|
2344
|
-
}
|
|
2345
|
-
}
|
|
2346
|
-
const useInputEvent=target=>new ZikoEventInput(target);
|
|
2347
|
-
|
|
2348
|
-
function hashchange_controller(e){
|
|
2349
|
-
EVENT_CONTROLLER.call(this,e,"hashchange",null,null);
|
|
2350
|
-
}
|
|
2351
|
-
class ZikoEventHash extends ZikoEvent{
|
|
2352
|
-
constructor(target){
|
|
2353
|
-
super(target);
|
|
2354
|
-
this.event=null;
|
|
2355
|
-
this.cache={
|
|
2356
|
-
prefixe:"",
|
|
2357
|
-
preventDefault:{
|
|
2358
|
-
hashchange:false,
|
|
2359
|
-
},
|
|
2360
|
-
paused:{
|
|
2361
|
-
hashchange:false,
|
|
2362
|
-
},
|
|
2363
|
-
stream:{
|
|
2364
|
-
enabled:{
|
|
2365
|
-
hashchange:false,
|
|
2366
|
-
|
|
2367
|
-
},
|
|
2368
|
-
clear:{
|
|
2369
|
-
hashchange:false,
|
|
2370
|
-
|
|
2371
|
-
},
|
|
2372
|
-
history:{
|
|
2373
|
-
hashchange:[],
|
|
2374
|
-
}
|
|
2375
|
-
},
|
|
2376
|
-
callbacks:{
|
|
2377
|
-
hashchange:[],
|
|
2378
|
-
}
|
|
2379
|
-
};
|
|
2380
|
-
this.__controller={
|
|
2381
|
-
hashchange:hashchange_controller.bind(this),
|
|
2382
|
-
};
|
|
2383
|
-
}
|
|
2384
|
-
onChange(...callbacks){
|
|
2385
|
-
this.__onEvent("hashchange",{},...callbacks);
|
|
2386
|
-
return this;
|
|
2387
|
-
}
|
|
2388
|
-
}
|
|
2389
|
-
const useHashEvent=target=>new ZikoEventHash(target);
|
|
2390
|
-
|
|
2391
2290
|
const custom_event_controller=event_name=>function(e){
|
|
2392
|
-
EVENT_CONTROLLER.call(this,e,event_name,null,null);
|
|
2393
|
-
};
|
|
2394
|
-
class ZikoCustomEvent extends ZikoEvent{
|
|
2395
|
-
constructor(target){
|
|
2396
|
-
super(target);
|
|
2397
|
-
this.event=null;
|
|
2398
|
-
this.cache={
|
|
2399
|
-
prefixe:"",
|
|
2400
|
-
preventDefault:{
|
|
2401
|
-
},
|
|
2402
|
-
paused:{
|
|
2403
|
-
},
|
|
2404
|
-
stream:{
|
|
2405
|
-
enabled:{
|
|
2406
|
-
},
|
|
2407
|
-
clear:{
|
|
2408
|
-
},
|
|
2409
|
-
history:{
|
|
2410
|
-
}
|
|
2411
|
-
},
|
|
2412
|
-
callbacks:{
|
|
2413
|
-
}
|
|
2414
|
-
};
|
|
2415
|
-
this.__controller={
|
|
2416
|
-
};
|
|
2417
|
-
}
|
|
2418
|
-
#init(event_name){
|
|
2419
|
-
this.cache.preventDefault[event_name]=false;
|
|
2420
|
-
this.cache.paused[event_name]=false;
|
|
2421
|
-
this.cache.stream.enabled=false;
|
|
2422
|
-
this.cache.stream.clear=false;
|
|
2423
|
-
this.cache.stream.history=[];
|
|
2424
|
-
this.cache.callbacks[event_name]=[];
|
|
2425
|
-
this.__controller[event_name]=custom_event_controller(event_name).bind(this);
|
|
2426
|
-
return this;
|
|
2427
|
-
}
|
|
2428
|
-
on(event_name,...callbacks){
|
|
2429
|
-
if(!(this.__controller[event_name]))this.#init(event_name);
|
|
2430
|
-
this.__onEvent(event_name,{},...callbacks);
|
|
2431
|
-
return this;
|
|
2432
|
-
}
|
|
2433
|
-
emit(event_name,detail={}){
|
|
2434
|
-
if(!(this.__controller[event_name]))this.#init(event_name);
|
|
2435
|
-
this.detail=detail;
|
|
2436
|
-
const event=new Event(event_name);
|
|
2437
|
-
this.targetElement.dispatchEvent(event);
|
|
2438
|
-
return this;
|
|
2439
|
-
}
|
|
2440
|
-
}
|
|
2441
|
-
const useCustomEvent=target=>new ZikoCustomEvent(target);
|
|
2442
|
-
|
|
2443
|
-
class ZikoEventSwipe extends ZikoEvent {
|
|
2444
|
-
constructor(target, width_threshold = 0.3, height_threshold = 0.3) {
|
|
2445
|
-
super(target);
|
|
2446
|
-
const { removeListener, setWidthThreshold, setHeightThreshold } = init_swipe_event_handler(
|
|
2447
|
-
this.target?.element,
|
|
2448
|
-
width_threshold,
|
|
2449
|
-
height_threshold,
|
|
2450
|
-
this.target.width,
|
|
2451
|
-
this.target.height,
|
|
2452
|
-
);
|
|
2453
|
-
this.cache = {
|
|
2454
|
-
width_threshold,
|
|
2455
|
-
height_threshold,
|
|
2456
|
-
removeListener,
|
|
2457
|
-
setWidthThreshold,
|
|
2458
|
-
setHeightThreshold,
|
|
2459
|
-
legacyTouchAction : globalThis?.document?.body?.style?.touchAction,
|
|
2460
|
-
prefixe: "",
|
|
2461
|
-
preventDefault: {
|
|
2462
|
-
swipe: false,
|
|
2463
|
-
},
|
|
2464
|
-
paused: {
|
|
2465
|
-
swipe: false,
|
|
2466
|
-
},
|
|
2467
|
-
stream: {
|
|
2468
|
-
enabled: {
|
|
2469
|
-
swipe: false,
|
|
2470
|
-
},
|
|
2471
|
-
clear: {
|
|
2472
|
-
swipe: false,
|
|
2473
|
-
},
|
|
2474
|
-
history: {
|
|
2475
|
-
swipe: [],
|
|
2476
|
-
},
|
|
2477
|
-
},
|
|
2478
|
-
callbacks: {
|
|
2479
|
-
swipe: [],
|
|
2480
|
-
},
|
|
2481
|
-
};
|
|
2482
|
-
this.__controller = {
|
|
2483
|
-
swipe: swipe_controller.bind(this),
|
|
2484
|
-
};
|
|
2485
|
-
}
|
|
2486
|
-
onSwipe(...callbacks) {
|
|
2487
|
-
Object.assign(globalThis?.document?.body?.style,{touchAction:"none"});
|
|
2488
|
-
this.__onEvent("swipe", {}, ...callbacks);
|
|
2489
|
-
return this;
|
|
2490
|
-
}
|
|
2491
|
-
updateThresholds(width_threshold = this.cache.width_threshold, height_threshold = this.cache.height_threshold) {
|
|
2492
|
-
if (width_threshold !== undefined) {
|
|
2493
|
-
this.cache.setWidthThreshold(width_threshold);
|
|
2494
|
-
}
|
|
2495
|
-
if (height_threshold !== undefined) {
|
|
2496
|
-
this.cache.setHeightThreshold(height_threshold);
|
|
2497
|
-
}
|
|
2498
|
-
return this;
|
|
2499
|
-
}
|
|
2500
|
-
destroy() {
|
|
2501
|
-
this.cache.removeListener();
|
|
2502
|
-
Object.assign(globalThis?.document?.body?.style,{touchAction:this.cache.legacyTouchAction});
|
|
2503
|
-
return this;
|
|
2504
|
-
}
|
|
2505
|
-
}
|
|
2506
|
-
function init_swipe_event_handler(element, width_threshold = 0.50, height_threshold = 0.5, width, height) {
|
|
2507
|
-
let Interpolated_width_threshold = lerp(width_threshold, 0, width);
|
|
2508
|
-
let Interpolated_height_threshold = lerp(height_threshold, 0, height);
|
|
2509
|
-
let startX = 0, startY = 0, endX = 0, endY = 0;
|
|
2510
|
-
const pointerDownHandler = (event) => {
|
|
2511
|
-
startX = event.clientX;
|
|
2512
|
-
startY = event.clientY;
|
|
2513
|
-
};
|
|
2514
|
-
const pointerUpHandler = (event) => {
|
|
2515
|
-
endX = event.clientX;
|
|
2516
|
-
endY = event.clientY;
|
|
2517
|
-
handleSwipe();
|
|
2518
|
-
};
|
|
2519
|
-
element?.addEventListener('pointerdown', pointerDownHandler);
|
|
2520
|
-
element?.addEventListener('pointerup', pointerUpHandler);
|
|
2521
|
-
function handleSwipe() {
|
|
2522
|
-
const deltaX = endX - startX;
|
|
2523
|
-
const deltaY = endY - startY;
|
|
2524
|
-
if (Math.abs(deltaX) > Interpolated_width_threshold || Math.abs(deltaY) > Interpolated_height_threshold) {
|
|
2525
|
-
dispatchSwipeEvent(deltaX, deltaY);
|
|
2526
|
-
}
|
|
2527
|
-
}
|
|
2528
|
-
function dispatchSwipeEvent(deltaX, deltaY) {
|
|
2529
|
-
const event = globalThis?.CustomEvent ? new CustomEvent('swipe', {
|
|
2530
|
-
detail: {
|
|
2531
|
-
deltaX: abs(deltaX) < Interpolated_width_threshold ? 0 : sign(deltaX) * norm(abs(deltaX), 0, width),
|
|
2532
|
-
deltaY: abs(deltaY) < Interpolated_height_threshold ? 0 : sign(deltaY) * norm(abs(deltaY), 0, height),
|
|
2533
|
-
direction: {
|
|
2534
|
-
x : abs(deltaX) < Interpolated_width_threshold ? "none" : deltaX > 0 ? "right" : "left",
|
|
2535
|
-
y : abs(deltaY) < Interpolated_height_threshold ? "none" : deltaY > 0 ? 'down' : 'up',
|
|
2536
|
-
},
|
|
2537
|
-
},
|
|
2538
|
-
}) : null;
|
|
2539
|
-
element?.dispatchEvent(event);
|
|
2540
|
-
}
|
|
2541
|
-
function setWidthThreshold(new_width_threshold) {
|
|
2542
|
-
Interpolated_width_threshold = lerp(new_width_threshold, 0, width);
|
|
2543
|
-
}
|
|
2544
|
-
function setHeightThreshold(new_height_threshold) {
|
|
2545
|
-
Interpolated_height_threshold = lerp(new_height_threshold, 0, height);
|
|
2546
|
-
}
|
|
2547
|
-
return {
|
|
2548
|
-
removeListener() {
|
|
2549
|
-
element?.removeEventListener('pointerdown', pointerDownHandler);
|
|
2550
|
-
element?.removeEventListener('pointerup', pointerUpHandler);
|
|
2551
|
-
console.log('Swipe event listeners removed');
|
|
2552
|
-
},
|
|
2553
|
-
setWidthThreshold,
|
|
2554
|
-
setHeightThreshold,
|
|
2555
|
-
};
|
|
2556
|
-
}
|
|
2557
|
-
function swipe_controller(e) {
|
|
2558
|
-
EVENT_CONTROLLER.call(this, e, "swipe", null, null);
|
|
2559
|
-
}
|
|
2560
|
-
const useSwipeEvent = (target, width_threshold, height_threshold) => new ZikoEventSwipe(target, width_threshold, height_threshold);
|
|
2561
|
-
/*
|
|
2562
|
-
a=p("ALLL").size("300px","300px").style({background:"red",userSelect:"none"})
|
|
2563
|
-
t=text("")
|
|
2564
|
-
ev=useSwipeEvent(a, .1, .3)
|
|
2565
|
-
ev.onSwipe(e=>{
|
|
2566
|
-
// t.setValue(`
|
|
2567
|
-
// vertical direction : ${e.event.detail.direction.y}
|
|
2568
|
-
// horizontal direction : ${e.event.detail.direction.x}
|
|
2569
|
-
// deltaX : ${e.event.detail.deltaX}
|
|
2570
|
-
// deltaY : ${e.event.detail.deltaY}
|
|
2571
|
-
// `)
|
|
2572
|
-
e.target.st.translate(e.event.detail.deltaX * 200, e.event.detail.deltaY * 200,0, 500)
|
|
2573
|
-
})
|
|
2574
|
-
*/
|
|
2575
|
-
/*
|
|
2576
|
-
a=p("ALLL")
|
|
2577
|
-
.size("300px","300px")
|
|
2578
|
-
.style({background:"red",userSelect:"none"})
|
|
2579
|
-
.onSwipe(
|
|
2580
|
-
.3,
|
|
2581
|
-
.3,
|
|
2582
|
-
e=>{
|
|
2583
|
-
e.target.st.translate(e.event.detail.deltaX * 200, e.event.detail.deltaY * 200,0, 500)
|
|
2584
|
-
})
|
|
2585
|
-
*/
|
|
2586
|
-
|
|
2587
|
-
class ZikoMutationObserver {
|
|
2588
|
-
constructor(targetUIElement, options) {
|
|
2589
|
-
this.target = targetUIElement;
|
|
2590
|
-
this.observer = null;
|
|
2591
|
-
this.cache = {
|
|
2592
|
-
options : options || { attributes: true, childList: true, subtree: true },
|
|
2593
|
-
streamingEnabled : true,
|
|
2594
|
-
lastMutation : null,
|
|
2595
|
-
mutationHistory : {
|
|
2596
|
-
// attributes: [],
|
|
2597
|
-
// childList: [],
|
|
2598
|
-
// subtree: [],
|
|
2599
|
-
},
|
|
2600
|
-
};
|
|
2601
|
-
// children to Items : a.items.filter(n=>n.element === a[0].element)
|
|
2602
|
-
this.observeCallback = (mutationsList, observer) => {
|
|
2603
|
-
// if(this.cache.lastUpdatedAttr){
|
|
2604
|
-
// this.cache.lastUpdatedAttr = mutation.target.getAttribute(mutation.attributeName)
|
|
2605
|
-
// }
|
|
2606
|
-
if (this.cache.streamingEnabled) {
|
|
2607
|
-
for (const mutation of mutationsList) {
|
|
2608
|
-
switch(mutation.type){
|
|
2609
|
-
case 'attributes':this.cache.mutationHistory.attributes.push(mutation.target.getAttribute(mutation.attributeName));break;
|
|
2610
|
-
case 'childList':this.cache.mutationHistory.childList.push(mutation);break;
|
|
2611
|
-
case 'subtree':this.cache.mutationHistory.subtree.push(mutation);break;
|
|
2612
|
-
}
|
|
2613
|
-
}
|
|
2614
|
-
}
|
|
2615
|
-
if (this.callback) {
|
|
2616
|
-
this.callback(mutationsList, observer);
|
|
2617
|
-
}
|
|
2618
|
-
};
|
|
2619
|
-
}
|
|
2620
|
-
|
|
2621
|
-
observe(callback) {
|
|
2622
|
-
if(!this.observer) {
|
|
2623
|
-
if(!globalThis.MutationObserver) {
|
|
2624
|
-
console.log("MutationObserver Nor Supported");
|
|
2625
|
-
return;
|
|
2626
|
-
}
|
|
2627
|
-
this.observer = new MutationObserver(this.cache.observeCallback);
|
|
2628
|
-
this.observer.observe(this.target.element, this.cache.options);
|
|
2629
|
-
// this.callback = ([e]) => callback.call(e,this.target);
|
|
2630
|
-
this.callback = ([e]) => callback.call(e, this);
|
|
2631
|
-
this.cache.streamingEnabled = true;
|
|
2632
|
-
}
|
|
2633
|
-
}
|
|
2634
|
-
|
|
2635
|
-
pause(options) {
|
|
2636
|
-
if (this.observer) {
|
|
2637
|
-
this.observer.disconnect();
|
|
2638
|
-
if (options) {
|
|
2639
|
-
this.observer.observe(this.target, options);
|
|
2640
|
-
}
|
|
2641
|
-
}
|
|
2642
|
-
}
|
|
2643
|
-
|
|
2644
|
-
reset(options) {
|
|
2645
|
-
if (this.observer) {
|
|
2646
|
-
this.observer.disconnect();
|
|
2647
|
-
this.observer.observe(this.target, options || this.cache.options);
|
|
2648
|
-
}
|
|
2649
|
-
}
|
|
2650
|
-
|
|
2651
|
-
clear() {
|
|
2652
|
-
if (this.observer) {
|
|
2653
|
-
this.observer.disconnect();
|
|
2654
|
-
this.observer = null;
|
|
2655
|
-
this.cache.mutationHistory = {
|
|
2656
|
-
attributes: [],
|
|
2657
|
-
childList: [],
|
|
2658
|
-
subtree: [],
|
|
2659
|
-
};
|
|
2660
|
-
}
|
|
2661
|
-
this.cache.streamingEnabled = false;
|
|
2662
|
-
return this;
|
|
2663
|
-
}
|
|
2664
|
-
|
|
2665
|
-
getMutationHistory() {
|
|
2666
|
-
return this.cache.mutationHistory;
|
|
2667
|
-
}
|
|
2668
|
-
|
|
2669
|
-
enableStreaming() {
|
|
2670
|
-
this.cache.streamingEnabled = true;
|
|
2671
|
-
return this;
|
|
2672
|
-
}
|
|
2673
|
-
|
|
2674
|
-
disableStreaming() {
|
|
2675
|
-
this.cache.streamingEnabled = false;
|
|
2676
|
-
return this;
|
|
2677
|
-
}
|
|
2678
|
-
}
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
const watch=(targetUIElement,options={},callback=null)=>{
|
|
2683
|
-
const Observer= new ZikoMutationObserver(targetUIElement,options);
|
|
2684
|
-
if(callback)Observer.observe(callback);
|
|
2685
|
-
return Observer
|
|
2686
|
-
};
|
|
2687
|
-
|
|
2688
|
-
class ZikoWatchAttr extends ZikoMutationObserver{
|
|
2689
|
-
constructor(targetUIElement,callback){
|
|
2690
|
-
super(targetUIElement,{ attributes: true, childList: false, subtree: false });
|
|
2691
|
-
Object.assign(this.cache,{
|
|
2692
|
-
observeCallback : (mutationsList, observer) =>{
|
|
2693
|
-
for (const mutation of mutationsList) {
|
|
2694
|
-
this.cache.lastMutation = {
|
|
2695
|
-
name : mutation.attributeName,
|
|
2696
|
-
value : mutation.target.getAttribute(mutation.attributeName)
|
|
2697
|
-
};
|
|
2698
|
-
if (this.cache.streamingEnabled) this.cache.mutationHistory.attributes.push(this.cache.lastMutation);
|
|
2699
|
-
}
|
|
2700
|
-
if (this.callback) this.callback(mutationsList, observer);
|
|
2701
|
-
}
|
|
2702
|
-
});
|
|
2703
|
-
this.cache.mutationHistory.attributes = [];
|
|
2704
|
-
if(callback)this.observe(callback);
|
|
2705
|
-
}
|
|
2706
|
-
get history(){
|
|
2707
|
-
return this.cache.mutationHistory.attributes;
|
|
2708
|
-
}
|
|
2709
|
-
}
|
|
2710
|
-
const watchAttr=(targetUIElement, callback)=>new ZikoWatchAttr(targetUIElement, callback);
|
|
2711
|
-
|
|
2712
|
-
class ZikoWatchChildren extends ZikoMutationObserver{
|
|
2713
|
-
constructor(targetUIElement,callback){
|
|
2714
|
-
super(targetUIElement,{ attributes: false, childList: true, subtree: false });
|
|
2715
|
-
Object.assign(this.cache,{
|
|
2716
|
-
observeCallback : (mutationsList, observer) =>{
|
|
2717
|
-
for (const mutation of mutationsList) {
|
|
2718
|
-
if(mutation.addedNodes)this.cache.lastMutation = {
|
|
2719
|
-
type : "add",
|
|
2720
|
-
item : this.target.find(n=>n.element === mutation.addedNodes[0])[0],
|
|
2721
|
-
previous : this.target.find(n=>n.element === mutation.previousSibling)[0]
|
|
2722
|
-
};
|
|
2723
|
-
else if(mutation.addedNodes)this.cache.lastMutation = {
|
|
2724
|
-
type : "remove",
|
|
2725
|
-
item : this.target.find(n=>n.element === mutation.removedNodes[0])[0],
|
|
2726
|
-
previous : this.target.find(n=>n.element === mutation.previousSibling)[0]
|
|
2727
|
-
};
|
|
2728
|
-
if (this.cache.streamingEnabled) this.cache.mutationHistory.children.push(this.cache.lastMutation);
|
|
2729
|
-
}
|
|
2730
|
-
if (this.callback) this.callback(mutationsList, observer);
|
|
2731
|
-
}
|
|
2732
|
-
});
|
|
2733
|
-
this.cache.mutationHistory.children = [];
|
|
2734
|
-
if(callback)this.observe(callback);
|
|
2735
|
-
}
|
|
2736
|
-
get item(){
|
|
2737
|
-
return this.cache.lastMutation.item;
|
|
2738
|
-
}
|
|
2739
|
-
get history(){
|
|
2740
|
-
return this.cache.mutationHistory.children;
|
|
2741
|
-
}
|
|
2742
|
-
}
|
|
2743
|
-
|
|
2744
|
-
const watchChildren=(targetUIElement, callback)=>new ZikoWatchChildren(targetUIElement, callback);
|
|
2745
|
-
|
|
2746
|
-
class ZikoIntersectionObserver{
|
|
2747
|
-
constructor(UIElement,callback,{threshold=0,margin=0}={}){
|
|
2748
|
-
this.target=UIElement;
|
|
2749
|
-
this.config={
|
|
2750
|
-
threshold,
|
|
2751
|
-
margin
|
|
2752
|
-
};
|
|
2753
|
-
if(!globalThis.IntersectionObserver){
|
|
2754
|
-
console.log("IntersectionObserver Not Supported");
|
|
2755
|
-
return;
|
|
2756
|
-
}
|
|
2757
|
-
this.observer=new IntersectionObserver((entries)=>{
|
|
2758
|
-
this.entrie=entries[0];
|
|
2759
|
-
callback(this);
|
|
2760
|
-
},{
|
|
2761
|
-
threshold:this.threshold,
|
|
2762
|
-
});
|
|
2763
|
-
}
|
|
2764
|
-
get ratio(){
|
|
2765
|
-
return this.entrie.intersectionRatio;
|
|
2766
|
-
}
|
|
2767
|
-
get isIntersecting(){
|
|
2768
|
-
return this.entrie.isIntersecting;
|
|
2769
|
-
}
|
|
2770
|
-
setThreshould(threshold){
|
|
2771
|
-
this.config.threshold=threshold;
|
|
2772
|
-
return this;
|
|
2773
|
-
}
|
|
2774
|
-
setMargin(margin){
|
|
2775
|
-
margin=(typeof margin === "number")?margin+"px":margin;
|
|
2776
|
-
this.config.margin=margin;
|
|
2777
|
-
return this;
|
|
2778
|
-
}
|
|
2779
|
-
start(){
|
|
2780
|
-
this.observer.observe(this.target.element);
|
|
2781
|
-
return this;
|
|
2782
|
-
}
|
|
2783
|
-
stop(){
|
|
2784
|
-
return this;
|
|
2785
|
-
}
|
|
2786
|
-
}
|
|
2787
|
-
|
|
2788
|
-
const watchIntersection=(UI,callback,config)=>new ZikoIntersectionObserver(UI,callback,config);
|
|
2789
|
-
|
|
2790
|
-
class ZikoResizeObserver{
|
|
2791
|
-
constructor(UIElement,callback){
|
|
2792
|
-
this.target=UIElement;
|
|
2793
|
-
this.contentRect=null;
|
|
2794
|
-
this.observer=new ResizeObserver(()=>{
|
|
2795
|
-
callback(this);
|
|
2796
|
-
});
|
|
2797
|
-
}
|
|
2798
|
-
get BoundingRect(){
|
|
2799
|
-
return this.target.element.getBoundingClientRect();
|
|
2800
|
-
}
|
|
2801
|
-
get width(){
|
|
2802
|
-
return this.BoundingRect.width;
|
|
2803
|
-
}
|
|
2804
|
-
get height(){
|
|
2805
|
-
return this.BoundingRect.height;
|
|
2806
|
-
}
|
|
2807
|
-
get top(){
|
|
2808
|
-
return this.BoundingRect.top;
|
|
2809
|
-
}
|
|
2810
|
-
get bottom(){
|
|
2811
|
-
return this.BoundingRect.bottom;
|
|
2812
|
-
}
|
|
2813
|
-
get right(){
|
|
2814
|
-
return this.BoundingRect.right;
|
|
2815
|
-
}
|
|
2816
|
-
get left(){
|
|
2817
|
-
return this.BoundingRect.left;
|
|
2818
|
-
}
|
|
2819
|
-
get x(){
|
|
2820
|
-
return this.BoundingRect.x;
|
|
2821
|
-
}
|
|
2822
|
-
get y(){
|
|
2823
|
-
return this.BoundingRect.y;
|
|
2824
|
-
}
|
|
2825
|
-
start(){
|
|
2826
|
-
this.observer.observe(this.target.element);
|
|
2827
|
-
return this;
|
|
2828
|
-
}
|
|
2829
|
-
stop(){
|
|
2830
|
-
this.observer.unobserve(this.target.element);
|
|
2831
|
-
return this;
|
|
2832
|
-
}
|
|
2833
|
-
}
|
|
2834
|
-
|
|
2835
|
-
const watchSize=(UI,callback)=>new ZikoResizeObserver(UI,callback);
|
|
2836
|
-
|
|
2837
|
-
class ZikoScreenObserver {
|
|
2838
|
-
constructor(callback=e=>console.log({x:e.x,y:e.y})) {
|
|
2839
|
-
this.cache={};
|
|
2840
|
-
this.previousX = globalThis?.screenX;
|
|
2841
|
-
this.previousY = globalThis?.screenY;
|
|
2842
|
-
}
|
|
2843
|
-
update(){
|
|
2844
|
-
Object.assign(this.cache,{
|
|
2845
|
-
screenXLeft : globalThis?.screenX, // CORRECT
|
|
2846
|
-
screenXRight : globalThis?.screen.availWidth - globalThis?.screenX, // CORRECT
|
|
2847
|
-
screenYTop : globalThis?.screenY, // CORRECT
|
|
2848
|
-
screenYBottom : globalThis?.screen.availHeight - globalThis?.screenY - globalThis?.outerHeight, // TO TEST
|
|
2849
|
-
screenCenterX : globalThis?.screen.availWidth/2, // CORRECT
|
|
2850
|
-
screenCenterY : globalThis?.screen.availHeight/2,// CORRECT
|
|
2851
|
-
windowCenterX : globalThis?.outerWidth/2+globalThis?.screenX, // CORRECT
|
|
2852
|
-
windowCenterY : globalThis?.outerHeight/2+ globalThis?.screenY, // FALSE
|
|
2853
|
-
deltaCenterX : globalThis?.screen.availWidth/2-globalThis?.outerWidth/2+globalThis?.screenX, // CORRECT
|
|
2854
|
-
deltaCenterY : null //
|
|
2855
|
-
});
|
|
2856
|
-
}
|
|
2857
|
-
get x0(){
|
|
2858
|
-
return map$1(globalThis?.screenX, 0, globalThis.screen.availWidth, -1, 1);
|
|
2859
|
-
}
|
|
2860
|
-
get y0(){
|
|
2861
|
-
return - map$1(globalThis?.screenY, 0, globalThis.screen.availHeight, -1, 1);
|
|
2862
|
-
}
|
|
2863
|
-
get x1(){
|
|
2864
|
-
return map$1(globalThis?.screenX + globalThis?.outerWidth, 0, globalThis.screen.availWidth, -1, 1);
|
|
2865
|
-
}
|
|
2866
|
-
get y1(){
|
|
2867
|
-
return - map$1(globalThis?.screenY + globalThis?.outerHeight, 0, globalThis.screen.availHeight, -1, 1);
|
|
2868
|
-
}
|
|
2869
|
-
get cx(){
|
|
2870
|
-
return map$1(globalThis?.outerWidth/2+globalThis?.screenX, 0, globalThis.screen.availWidth, -1, 1);
|
|
2871
|
-
}
|
|
2872
|
-
get cy(){
|
|
2873
|
-
return - map$1(globalThis?.outerHeight/2+ globalThis?.screenY, 0, globalThis.screen.availHeight, -1, 1);
|
|
2874
|
-
}
|
|
2875
|
-
}
|
|
2876
|
-
|
|
2877
|
-
const watchScreen=(callback)=>new ZikoScreenObserver(callback);
|
|
2878
|
-
|
|
2879
|
-
const useSuccesifKeys=(self,keys=[],callback=()=>{})=>{
|
|
2880
|
-
self.cache.stream.enabled.down=true;
|
|
2881
|
-
const length=keys.length;
|
|
2882
|
-
const LastKeysDown=self.cache.stream.history.down.slice(-length).map(n=>n.key);
|
|
2883
|
-
|
|
2884
|
-
if(keys.join("")===LastKeysDown.join("")){
|
|
2885
|
-
self.event.preventDefault();
|
|
2886
|
-
callback.call(self,self);
|
|
2887
|
-
}
|
|
2888
|
-
|
|
2889
|
-
};
|
|
2890
|
-
|
|
2891
|
-
class ZikoUseEventEmitter {
|
|
2892
|
-
constructor() {
|
|
2893
|
-
this.events = {};
|
|
2894
|
-
this.maxListeners = 10;
|
|
2895
|
-
}
|
|
2896
|
-
on(event, listener) {
|
|
2897
|
-
if (!this.events[event]) {
|
|
2898
|
-
this.events[event] = [];
|
|
2899
|
-
}
|
|
2900
|
-
this.events[event].push(listener);
|
|
2901
|
-
if (this.events[event].length > this.maxListeners) {
|
|
2902
|
-
console.warn(`Warning: Possible memory leak. Event '${event}' has more than ${this.maxListeners} listeners.`);
|
|
2903
|
-
}
|
|
2904
|
-
}
|
|
2905
|
-
once(event, listener) {
|
|
2906
|
-
const onceListener = (data) => {
|
|
2907
|
-
this.off(event, onceListener); // Remove the listener after it's been called
|
|
2908
|
-
listener(data);
|
|
2909
|
-
};
|
|
2910
|
-
this.on(event, onceListener);
|
|
2911
|
-
}
|
|
2912
|
-
|
|
2913
|
-
off(event, listener) {
|
|
2914
|
-
const listeners = this.events[event];
|
|
2915
|
-
if (listeners) {
|
|
2916
|
-
const index = listeners.indexOf(listener);
|
|
2917
|
-
if (index !== -1) {
|
|
2918
|
-
listeners.splice(index, 1);
|
|
2919
|
-
}
|
|
2920
|
-
}
|
|
2921
|
-
}
|
|
2922
|
-
|
|
2923
|
-
emit(event, data) {
|
|
2924
|
-
const listeners = this.events[event];
|
|
2925
|
-
if (listeners) {
|
|
2926
|
-
listeners.forEach(listener => {
|
|
2927
|
-
listener(data);
|
|
2928
|
-
});
|
|
2929
|
-
}
|
|
2930
|
-
}
|
|
2931
|
-
|
|
2932
|
-
clear(event) {
|
|
2933
|
-
if (event) {
|
|
2934
|
-
delete this.events[event];
|
|
2935
|
-
} else {
|
|
2936
|
-
this.events = {};
|
|
2937
|
-
}
|
|
2938
|
-
}
|
|
2939
|
-
|
|
2940
|
-
setMaxListener(event, max) {
|
|
2941
|
-
this.maxListeners = max;
|
|
2942
|
-
}
|
|
2943
|
-
|
|
2944
|
-
removeAllListeners(event) {
|
|
2945
|
-
if (event) {
|
|
2946
|
-
this.events[event] = [];
|
|
2947
|
-
} else {
|
|
2948
|
-
this.events = {};
|
|
2949
|
-
}
|
|
2950
|
-
}
|
|
2951
|
-
}
|
|
2952
|
-
|
|
2953
|
-
const useEventEmitter=()=>new ZikoUseEventEmitter();
|
|
2954
|
-
|
|
2955
|
-
class ZikoUseFavIcon{
|
|
2956
|
-
constructor(FavIcon,useEventEmitter=true){
|
|
2957
|
-
this.#init();
|
|
2958
|
-
this.cache={
|
|
2959
|
-
Emitter:null
|
|
2960
|
-
};
|
|
2961
|
-
if(useEventEmitter)this.useEventEmitter();
|
|
2962
|
-
this.set(FavIcon);
|
|
2963
|
-
}
|
|
2964
|
-
#init(){
|
|
2965
|
-
this.__FavIcon__ = document.querySelector("link[rel*='icon']") || document?.createElement('link');
|
|
2966
|
-
this.__FavIcon__.type = 'image/x-icon';
|
|
2967
|
-
this.__FavIcon__.rel = 'shortcut icon';
|
|
2968
|
-
return this;
|
|
2969
|
-
}
|
|
2970
|
-
set(href){
|
|
2971
|
-
if(href!==this.__FavIcon__.href){
|
|
2972
|
-
this.__FavIcon__.href=href;
|
|
2973
|
-
if(this.cache.Emitter)this.cache.Emitter.emit("ziko:favicon-changed");
|
|
2974
|
-
}
|
|
2975
|
-
return this;
|
|
2976
|
-
}
|
|
2977
|
-
get current(){
|
|
2978
|
-
return document.__FavIcon__.href;
|
|
2979
|
-
}
|
|
2980
|
-
onChange(callback){
|
|
2981
|
-
if(this.cache.Emitter)this.cache.Emitter.on("ziko:favicon-changed",callback);
|
|
2982
|
-
return this;
|
|
2983
|
-
}
|
|
2984
|
-
useEventEmitter(){
|
|
2985
|
-
this.cache.Emitter=useEventEmitter();
|
|
2986
|
-
return this;
|
|
2987
|
-
}
|
|
2988
|
-
|
|
2989
|
-
}
|
|
2990
|
-
const useFavIcon=(FavIcon,useEventEmitter)=>new ZikoUseFavIcon(FavIcon,useEventEmitter);
|
|
2991
|
-
|
|
2992
|
-
class ZikoMeta{
|
|
2993
|
-
constructor({viewport,charset,description,author,keywords}){
|
|
2994
|
-
this.document = globalThis?.document;
|
|
2995
|
-
this.meta={};
|
|
2996
|
-
this.init({viewport,charset,description,author,keywords});
|
|
2997
|
-
}
|
|
2998
|
-
init({viewport,charset,description,author,keywords}){
|
|
2999
|
-
viewport && this.setViewport(viewport);
|
|
3000
|
-
charset && this.setCharset(charset);
|
|
3001
|
-
description && this.describe(description);
|
|
3002
|
-
author && this.setAuthor(author);
|
|
3003
|
-
keywords && this.setKeywords(keywords);
|
|
3004
|
-
}
|
|
3005
|
-
set(key,value){
|
|
3006
|
-
key = key.toLowerCase();
|
|
3007
|
-
const isCharset = (key === "charset");
|
|
3008
|
-
const meta = isCharset ? document.querySelector("meta[charset]"):document.querySelector(`meta[name=${key}]`);
|
|
3009
|
-
this.meta=meta?? document?.createElement("meta");
|
|
3010
|
-
if(isCharset) this.meta.setAttribute("charset",value);
|
|
3011
|
-
else {
|
|
3012
|
-
this.meta.setAttribute("name",key);
|
|
3013
|
-
this.meta.setAttribute("content",value);
|
|
3014
|
-
}
|
|
3015
|
-
if(!meta)this.document.head.append(this.meta);
|
|
3016
|
-
return this;
|
|
3017
|
-
}
|
|
3018
|
-
setCharset(charset="utf-8"){
|
|
3019
|
-
this.set("charset",charset);
|
|
3020
|
-
return this;
|
|
3021
|
-
}
|
|
3022
|
-
describe(description){
|
|
3023
|
-
this.set("description",description);
|
|
3024
|
-
return this;
|
|
3025
|
-
}
|
|
3026
|
-
setViewport(viewport="width=device-width, initial-scale=1.0"){
|
|
3027
|
-
this.set("viewport",viewport);
|
|
3028
|
-
return this;
|
|
3029
|
-
}
|
|
3030
|
-
setKeywords(...keywords){
|
|
3031
|
-
// keywords.push("zikojs");
|
|
3032
|
-
keywords=[...new Set(keywords)].join(", ");
|
|
3033
|
-
this.set("keywords",keywords);
|
|
3034
|
-
return this;
|
|
3035
|
-
}
|
|
3036
|
-
setAuthor(author){
|
|
3037
|
-
this.set("author",author);
|
|
3038
|
-
return this;
|
|
3039
|
-
}
|
|
3040
|
-
}
|
|
3041
|
-
const useMeta=({viewport,charset,description,author,keywords})=>new ZikoMeta({viewport,charset,description,author,keywords});
|
|
3042
|
-
|
|
3043
|
-
class ZikoUseTitle{
|
|
3044
|
-
constructor(title=document.title,useEventEmitter=true){
|
|
3045
|
-
this.cache={
|
|
3046
|
-
Emitter:null
|
|
3047
|
-
};
|
|
3048
|
-
if(useEventEmitter)this.useEventEmitter();
|
|
3049
|
-
this.set(title);
|
|
3050
|
-
}
|
|
3051
|
-
useEventEmitter(){
|
|
3052
|
-
this.cache.Emitter=useEventEmitter();
|
|
3053
|
-
return this;
|
|
3054
|
-
}
|
|
3055
|
-
set(title){
|
|
3056
|
-
if(title!==document.title){
|
|
3057
|
-
document.title=title;
|
|
3058
|
-
if(this.cache.Emitter)this.cache.Emitter.emit("ziko:title-changed");
|
|
3059
|
-
}
|
|
3060
|
-
return this;
|
|
3061
|
-
}
|
|
3062
|
-
get current(){
|
|
3063
|
-
return document.title;
|
|
3064
|
-
}
|
|
3065
|
-
onChange(callback){
|
|
3066
|
-
if(this.cache.Emitter)this.cache.Emitter.on("ziko:title-changed",callback);
|
|
3067
|
-
return this;
|
|
3068
|
-
}
|
|
3069
|
-
}
|
|
3070
|
-
const useTitle=(title, useEventEmitter)=>new ZikoUseTitle(title, useEventEmitter);
|
|
3071
|
-
|
|
3072
|
-
// import {useLink} from "./";
|
|
3073
|
-
class ZikoHead{
|
|
3074
|
-
constructor({title,lang,icon,meta,noscript}){
|
|
3075
|
-
this.html = globalThis?.document?.documentElement;
|
|
3076
|
-
this.head = globalThis?.document?.head;
|
|
3077
|
-
|
|
3078
|
-
title && useTitle(title);
|
|
3079
|
-
lang && this.setLang(lang);
|
|
3080
|
-
icon && useFavIcon(icon);
|
|
3081
|
-
meta && useMeta(meta);
|
|
3082
|
-
noscript && this.setNoScript();
|
|
3083
|
-
}
|
|
3084
|
-
setLang(lang){
|
|
3085
|
-
this.html.setAttribute("lang",lang);
|
|
3086
|
-
}
|
|
3087
|
-
setNoScript(content){
|
|
3088
|
-
|
|
3089
|
-
}
|
|
3090
|
-
}
|
|
3091
|
-
|
|
3092
|
-
const useHead=({ title, lang, icon, meta, noscript })=>new ZikoHead({ title, lang, icon, meta, noscript });
|
|
3093
|
-
|
|
3094
|
-
/*
|
|
3095
|
-
[
|
|
3096
|
-
{
|
|
3097
|
-
query: '(min-width: 600px)',
|
|
3098
|
-
callback: () => console.log(1)
|
|
2291
|
+
EVENT_CONTROLLER.call(this,e,event_name,null,null);
|
|
2292
|
+
};
|
|
2293
|
+
class ZikoCustomEvent extends ZikoEvent{
|
|
2294
|
+
constructor(target){
|
|
2295
|
+
super(target);
|
|
2296
|
+
this.event=null;
|
|
2297
|
+
this.cache={
|
|
2298
|
+
prefixe:"",
|
|
2299
|
+
preventDefault:{
|
|
3099
2300
|
},
|
|
3100
|
-
{
|
|
3101
|
-
|
|
3102
|
-
|
|
2301
|
+
paused:{
|
|
2302
|
+
},
|
|
2303
|
+
stream:{
|
|
2304
|
+
enabled:{
|
|
2305
|
+
},
|
|
2306
|
+
clear:{
|
|
2307
|
+
},
|
|
2308
|
+
history:{
|
|
2309
|
+
}
|
|
2310
|
+
},
|
|
2311
|
+
callbacks:{
|
|
3103
2312
|
}
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
constructor(mediaQueryRules=[],fallback=()=>{}) {
|
|
3108
|
-
this.mediaQueryRules = mediaQueryRules;
|
|
3109
|
-
this.fallback = fallback;
|
|
3110
|
-
this.lastCalledCallback = null;
|
|
3111
|
-
this.init();
|
|
2313
|
+
};
|
|
2314
|
+
this.__controller={
|
|
2315
|
+
};
|
|
3112
2316
|
}
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
this.
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
2317
|
+
#init(event_name){
|
|
2318
|
+
this.cache.preventDefault[event_name]=false;
|
|
2319
|
+
this.cache.paused[event_name]=false;
|
|
2320
|
+
this.cache.stream.enabled=false;
|
|
2321
|
+
this.cache.stream.clear=false;
|
|
2322
|
+
this.cache.stream.history=[];
|
|
2323
|
+
this.cache.callbacks[event_name]=[];
|
|
2324
|
+
this.__controller[event_name]=custom_event_controller(event_name).bind(this);
|
|
2325
|
+
return this;
|
|
2326
|
+
}
|
|
2327
|
+
on(event_name,...callbacks){
|
|
2328
|
+
if(!(this.__controller[event_name]))this.#init(event_name);
|
|
2329
|
+
this.__onEvent(event_name,{},...callbacks);
|
|
2330
|
+
return this;
|
|
2331
|
+
}
|
|
2332
|
+
emit(event_name,detail={}){
|
|
2333
|
+
if(!(this.__controller[event_name]))this.#init(event_name);
|
|
2334
|
+
this.detail=detail;
|
|
2335
|
+
const event=new Event(event_name);
|
|
2336
|
+
this.targetElement.dispatchEvent(event);
|
|
2337
|
+
return this;
|
|
3130
2338
|
}
|
|
3131
2339
|
}
|
|
3132
|
-
|
|
3133
|
-
const useMediaQuery = (mediaQueryRules,fallback) => new ZikoUseMediaQuery(mediaQueryRules,fallback);
|
|
2340
|
+
const useCustomEvent=target=>new ZikoCustomEvent(target);
|
|
3134
2341
|
|
|
3135
2342
|
let UIElement$1 = class UIElement extends UIElementCore{
|
|
3136
2343
|
constructor({element, name ='', type='html', render = __Ziko__.__Config__.default.render}={}){
|
|
@@ -5396,6 +4603,209 @@ const timeTaken = callback => {
|
|
|
5396
4603
|
return r;
|
|
5397
4604
|
};
|
|
5398
4605
|
|
|
4606
|
+
class ZikoUseEventEmitter {
|
|
4607
|
+
constructor() {
|
|
4608
|
+
this.events = {};
|
|
4609
|
+
this.maxListeners = 10;
|
|
4610
|
+
}
|
|
4611
|
+
on(event, listener) {
|
|
4612
|
+
if (!this.events[event]) {
|
|
4613
|
+
this.events[event] = [];
|
|
4614
|
+
}
|
|
4615
|
+
this.events[event].push(listener);
|
|
4616
|
+
if (this.events[event].length > this.maxListeners) {
|
|
4617
|
+
console.warn(`Warning: Possible memory leak. Event '${event}' has more than ${this.maxListeners} listeners.`);
|
|
4618
|
+
}
|
|
4619
|
+
}
|
|
4620
|
+
once(event, listener) {
|
|
4621
|
+
const onceListener = (data) => {
|
|
4622
|
+
this.off(event, onceListener); // Remove the listener after it's been called
|
|
4623
|
+
listener(data);
|
|
4624
|
+
};
|
|
4625
|
+
this.on(event, onceListener);
|
|
4626
|
+
}
|
|
4627
|
+
|
|
4628
|
+
off(event, listener) {
|
|
4629
|
+
const listeners = this.events[event];
|
|
4630
|
+
if (listeners) {
|
|
4631
|
+
const index = listeners.indexOf(listener);
|
|
4632
|
+
if (index !== -1) {
|
|
4633
|
+
listeners.splice(index, 1);
|
|
4634
|
+
}
|
|
4635
|
+
}
|
|
4636
|
+
}
|
|
4637
|
+
|
|
4638
|
+
emit(event, data) {
|
|
4639
|
+
const listeners = this.events[event];
|
|
4640
|
+
if (listeners) {
|
|
4641
|
+
listeners.forEach(listener => {
|
|
4642
|
+
listener(data);
|
|
4643
|
+
});
|
|
4644
|
+
}
|
|
4645
|
+
}
|
|
4646
|
+
|
|
4647
|
+
clear(event) {
|
|
4648
|
+
if (event) {
|
|
4649
|
+
delete this.events[event];
|
|
4650
|
+
} else {
|
|
4651
|
+
this.events = {};
|
|
4652
|
+
}
|
|
4653
|
+
}
|
|
4654
|
+
|
|
4655
|
+
setMaxListener(event, max) {
|
|
4656
|
+
this.maxListeners = max;
|
|
4657
|
+
}
|
|
4658
|
+
|
|
4659
|
+
removeAllListeners(event) {
|
|
4660
|
+
if (event) {
|
|
4661
|
+
this.events[event] = [];
|
|
4662
|
+
} else {
|
|
4663
|
+
this.events = {};
|
|
4664
|
+
}
|
|
4665
|
+
}
|
|
4666
|
+
}
|
|
4667
|
+
|
|
4668
|
+
const useEventEmitter=()=>new ZikoUseEventEmitter();
|
|
4669
|
+
|
|
4670
|
+
class ZikoUseFavIcon{
|
|
4671
|
+
constructor(FavIcon,useEventEmitter=true){
|
|
4672
|
+
this.#init();
|
|
4673
|
+
this.cache={
|
|
4674
|
+
Emitter:null
|
|
4675
|
+
};
|
|
4676
|
+
if(useEventEmitter)this.useEventEmitter();
|
|
4677
|
+
this.set(FavIcon);
|
|
4678
|
+
}
|
|
4679
|
+
#init(){
|
|
4680
|
+
this.__FavIcon__ = document.querySelector("link[rel*='icon']") || document?.createElement('link');
|
|
4681
|
+
this.__FavIcon__.type = 'image/x-icon';
|
|
4682
|
+
this.__FavIcon__.rel = 'shortcut icon';
|
|
4683
|
+
return this;
|
|
4684
|
+
}
|
|
4685
|
+
set(href){
|
|
4686
|
+
if(href!==this.__FavIcon__.href){
|
|
4687
|
+
this.__FavIcon__.href=href;
|
|
4688
|
+
if(this.cache.Emitter)this.cache.Emitter.emit("ziko:favicon-changed");
|
|
4689
|
+
}
|
|
4690
|
+
return this;
|
|
4691
|
+
}
|
|
4692
|
+
get current(){
|
|
4693
|
+
return document.__FavIcon__.href;
|
|
4694
|
+
}
|
|
4695
|
+
onChange(callback){
|
|
4696
|
+
if(this.cache.Emitter)this.cache.Emitter.on("ziko:favicon-changed",callback);
|
|
4697
|
+
return this;
|
|
4698
|
+
}
|
|
4699
|
+
useEventEmitter(){
|
|
4700
|
+
this.cache.Emitter=useEventEmitter();
|
|
4701
|
+
return this;
|
|
4702
|
+
}
|
|
4703
|
+
|
|
4704
|
+
}
|
|
4705
|
+
const useFavIcon=(FavIcon,useEventEmitter)=>new ZikoUseFavIcon(FavIcon,useEventEmitter);
|
|
4706
|
+
|
|
4707
|
+
class ZikoMeta{
|
|
4708
|
+
constructor({viewport,charset,description,author,keywords}){
|
|
4709
|
+
this.document = globalThis?.document;
|
|
4710
|
+
this.meta={};
|
|
4711
|
+
this.init({viewport,charset,description,author,keywords});
|
|
4712
|
+
}
|
|
4713
|
+
init({viewport,charset,description,author,keywords}){
|
|
4714
|
+
viewport && this.setViewport(viewport);
|
|
4715
|
+
charset && this.setCharset(charset);
|
|
4716
|
+
description && this.describe(description);
|
|
4717
|
+
author && this.setAuthor(author);
|
|
4718
|
+
keywords && this.setKeywords(keywords);
|
|
4719
|
+
}
|
|
4720
|
+
set(key,value){
|
|
4721
|
+
key = key.toLowerCase();
|
|
4722
|
+
const isCharset = (key === "charset");
|
|
4723
|
+
const meta = isCharset ? document.querySelector("meta[charset]"):document.querySelector(`meta[name=${key}]`);
|
|
4724
|
+
this.meta=meta?? document?.createElement("meta");
|
|
4725
|
+
if(isCharset) this.meta.setAttribute("charset",value);
|
|
4726
|
+
else {
|
|
4727
|
+
this.meta.setAttribute("name",key);
|
|
4728
|
+
this.meta.setAttribute("content",value);
|
|
4729
|
+
}
|
|
4730
|
+
if(!meta)this.document.head.append(this.meta);
|
|
4731
|
+
return this;
|
|
4732
|
+
}
|
|
4733
|
+
setCharset(charset="utf-8"){
|
|
4734
|
+
this.set("charset",charset);
|
|
4735
|
+
return this;
|
|
4736
|
+
}
|
|
4737
|
+
describe(description){
|
|
4738
|
+
this.set("description",description);
|
|
4739
|
+
return this;
|
|
4740
|
+
}
|
|
4741
|
+
setViewport(viewport="width=device-width, initial-scale=1.0"){
|
|
4742
|
+
this.set("viewport",viewport);
|
|
4743
|
+
return this;
|
|
4744
|
+
}
|
|
4745
|
+
setKeywords(...keywords){
|
|
4746
|
+
// keywords.push("zikojs");
|
|
4747
|
+
keywords=[...new Set(keywords)].join(", ");
|
|
4748
|
+
this.set("keywords",keywords);
|
|
4749
|
+
return this;
|
|
4750
|
+
}
|
|
4751
|
+
setAuthor(author){
|
|
4752
|
+
this.set("author",author);
|
|
4753
|
+
return this;
|
|
4754
|
+
}
|
|
4755
|
+
}
|
|
4756
|
+
const useMeta=({viewport,charset,description,author,keywords})=>new ZikoMeta({viewport,charset,description,author,keywords});
|
|
4757
|
+
|
|
4758
|
+
class ZikoUseTitle{
|
|
4759
|
+
constructor(title=document.title,useEventEmitter=true){
|
|
4760
|
+
this.cache={
|
|
4761
|
+
Emitter:null
|
|
4762
|
+
};
|
|
4763
|
+
if(useEventEmitter)this.useEventEmitter();
|
|
4764
|
+
this.set(title);
|
|
4765
|
+
}
|
|
4766
|
+
useEventEmitter(){
|
|
4767
|
+
this.cache.Emitter=useEventEmitter();
|
|
4768
|
+
return this;
|
|
4769
|
+
}
|
|
4770
|
+
set(title){
|
|
4771
|
+
if(title!==document.title){
|
|
4772
|
+
document.title=title;
|
|
4773
|
+
if(this.cache.Emitter)this.cache.Emitter.emit("ziko:title-changed");
|
|
4774
|
+
}
|
|
4775
|
+
return this;
|
|
4776
|
+
}
|
|
4777
|
+
get current(){
|
|
4778
|
+
return document.title;
|
|
4779
|
+
}
|
|
4780
|
+
onChange(callback){
|
|
4781
|
+
if(this.cache.Emitter)this.cache.Emitter.on("ziko:title-changed",callback);
|
|
4782
|
+
return this;
|
|
4783
|
+
}
|
|
4784
|
+
}
|
|
4785
|
+
const useTitle=(title, useEventEmitter)=>new ZikoUseTitle(title, useEventEmitter);
|
|
4786
|
+
|
|
4787
|
+
// import {useLink} from "./";
|
|
4788
|
+
class ZikoHead{
|
|
4789
|
+
constructor({title,lang,icon,meta,noscript}){
|
|
4790
|
+
this.html = globalThis?.document?.documentElement;
|
|
4791
|
+
this.head = globalThis?.document?.head;
|
|
4792
|
+
|
|
4793
|
+
title && useTitle(title);
|
|
4794
|
+
lang && this.setLang(lang);
|
|
4795
|
+
icon && useFavIcon(icon);
|
|
4796
|
+
meta && useMeta(meta);
|
|
4797
|
+
noscript && this.setNoScript();
|
|
4798
|
+
}
|
|
4799
|
+
setLang(lang){
|
|
4800
|
+
this.html.setAttribute("lang",lang);
|
|
4801
|
+
}
|
|
4802
|
+
setNoScript(content){
|
|
4803
|
+
|
|
4804
|
+
}
|
|
4805
|
+
}
|
|
4806
|
+
|
|
4807
|
+
const useHead=({ title, lang, icon, meta, noscript })=>new ZikoHead({ title, lang, icon, meta, noscript });
|
|
4808
|
+
|
|
5399
4809
|
class ZikoApp {
|
|
5400
4810
|
constructor({head = null, wrapper = null, target = null}){
|
|
5401
4811
|
this.head = head;
|
|
@@ -6013,21 +5423,17 @@ exports.UIView = UIView;
|
|
|
6013
5423
|
exports.Utils = Utils;
|
|
6014
5424
|
exports.View = View;
|
|
6015
5425
|
exports.ZikoApp = ZikoApp;
|
|
6016
|
-
exports.ZikoCustomEvent = ZikoCustomEvent;
|
|
6017
5426
|
exports.ZikoEventClick = ZikoEventClick;
|
|
6018
5427
|
exports.ZikoEventClipboard = ZikoEventClipboard;
|
|
6019
5428
|
exports.ZikoEventCustom = ZikoEventCustom;
|
|
6020
5429
|
exports.ZikoEventDrag = ZikoEventDrag;
|
|
6021
5430
|
exports.ZikoEventFocus = ZikoEventFocus;
|
|
6022
|
-
exports.
|
|
5431
|
+
exports.ZikoEventHash = ZikoEventHash;
|
|
6023
5432
|
exports.ZikoEventKey = ZikoEventKey;
|
|
6024
5433
|
exports.ZikoEventMouse = ZikoEventMouse;
|
|
6025
5434
|
exports.ZikoEventPointer = ZikoEventPointer;
|
|
6026
|
-
exports.ZikoEventSwipe = ZikoEventSwipe;
|
|
6027
5435
|
exports.ZikoEventTouch = ZikoEventTouch;
|
|
6028
5436
|
exports.ZikoEventWheel = ZikoEventWheel;
|
|
6029
|
-
exports.ZikoHead = ZikoHead;
|
|
6030
|
-
exports.ZikoMutationObserver = ZikoMutationObserver;
|
|
6031
5437
|
exports.ZikoSPA = ZikoSPA;
|
|
6032
5438
|
exports.ZikoUIFlex = ZikoUIFlex;
|
|
6033
5439
|
exports.ZikoUISuspense = ZikoUISuspense;
|
|
@@ -6151,31 +5557,15 @@ exports.timeTaken = timeTaken;
|
|
|
6151
5557
|
exports.time_memory_Taken = time_memory_Taken;
|
|
6152
5558
|
exports.timeout = timeout;
|
|
6153
5559
|
exports.useChannel = useChannel;
|
|
6154
|
-
exports.useCustomEvent = useCustomEvent;
|
|
6155
5560
|
exports.useDerived = useDerived;
|
|
6156
5561
|
exports.useEventEmitter = useEventEmitter;
|
|
6157
|
-
exports.useFavIcon = useFavIcon;
|
|
6158
|
-
exports.useHashEvent = useHashEvent;
|
|
6159
|
-
exports.useHead = useHead;
|
|
6160
|
-
exports.useInputEvent = useInputEvent;
|
|
6161
5562
|
exports.useLocaleStorage = useLocaleStorage;
|
|
6162
|
-
exports.useMediaQuery = useMediaQuery;
|
|
6163
|
-
exports.useMeta = useMeta;
|
|
6164
5563
|
exports.useReactive = useReactive;
|
|
6165
5564
|
exports.useRoot = useRoot;
|
|
6166
5565
|
exports.useSessionStorage = useSessionStorage;
|
|
6167
5566
|
exports.useState = useState;
|
|
6168
|
-
exports.useSuccesifKeys = useSuccesifKeys;
|
|
6169
|
-
exports.useSwipeEvent = useSwipeEvent;
|
|
6170
5567
|
exports.useThread = useThread;
|
|
6171
|
-
exports.useTitle = useTitle;
|
|
6172
5568
|
exports.wait = wait;
|
|
6173
5569
|
exports.waitForUIElm = waitForUIElm;
|
|
6174
5570
|
exports.waitForUIElmSync = waitForUIElmSync;
|
|
6175
|
-
exports.watch = watch;
|
|
6176
|
-
exports.watchAttr = watchAttr;
|
|
6177
|
-
exports.watchChildren = watchChildren;
|
|
6178
|
-
exports.watchIntersection = watchIntersection;
|
|
6179
|
-
exports.watchScreen = watchScreen;
|
|
6180
|
-
exports.watchSize = watchSize;
|
|
6181
5571
|
exports.zeros = zeros;
|