ziko 0.67.0 → 0.68.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ziko.cjs +276 -805
- package/dist/ziko.js +276 -805
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +276 -791
- package/package.json +1 -1
- package/src/events/controller/index.js +57 -0
- package/src/events/custom-events-registry/click-away.js +1 -0
- package/src/events/index.js +1 -3
- package/src/{exp-events → events-dep}/custom-events-registry/click-away.js +0 -1
- package/src/events-dep/index.js +3 -0
- package/src/ui/constructors/UIElement.js +17 -7
- package/src/ui/constructors/mixins/attrs.js +19 -5
- package/src/ui/constructors/mixins/dom.js +53 -1
- package/src/ui/constructors/mixins/events/click.js +22 -0
- package/src/ui/constructors/mixins/events/index.js +3 -0
- package/src/ui/constructors/mixins/events/key.js +24 -0
- package/src/ui/constructors/mixins/events/ptr.js +44 -0
- package/src/ui/constructors/mixins/events/utils/index.js +15 -0
- package/src/ui/constructors/mixins/index.js +4 -2
- package/src/exp-events/controller/index.js +0 -41
- package/src/exp-events/index.js +0 -1
- package/src/ui/constructors/mixins/events.js +0 -57
- package/src/ui/constructors/mixins/utils/index.js +0 -64
- /package/src/{events → events-dep}/binders/coordinates-based-event.js +0 -0
- /package/src/{events → events-dep}/binders/custom-event.js +0 -0
- /package/src/{events → events-dep}/binders/index.js +0 -0
- /package/src/{exp-events → events-dep}/custom-events-registry/index.js +0 -0
- /package/src/{exp-events → events-dep}/custom-events-registry/swipe.js +0 -0
- /package/src/{exp-events → events-dep}/custom-events-registry/view.js +0 -0
- /package/src/{events → events-dep}/customizers/normalise-coordinates.js +0 -0
- /package/src/{exp-events → events-dep}/details-setter/index.js +0 -0
- /package/src/{exp-events → events-dep}/details-setter/key.js +0 -0
- /package/src/{exp-events → events-dep}/details-setter/mouse.js +0 -0
- /package/src/{exp-events → events-dep}/details-setter/pointer.js +0 -0
- /package/src/{exp-events → events-dep}/details-setter/touch.js +0 -0
- /package/src/{events → events-dep}/events-map/index.js +0 -0
- /package/src/{events → events-dep}/types/__Shared__.d.ts +0 -0
- /package/src/{events → events-dep}/types/clipboard.d.ts +0 -0
- /package/src/{events → events-dep}/types/focus.d.ts +0 -0
- /package/src/{events → events-dep}/types/pointer.d.ts +0 -0
- /package/src/{events → events-dep}/utils.js +0 -0
- /package/src/{events → events-dep}/ziko-event.js +0 -0
package/dist/ziko.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/*
|
|
3
3
|
Project: ziko.js
|
|
4
4
|
Author: Zakaria Elalaoui
|
|
5
|
-
Date :
|
|
5
|
+
Date : Fri Feb 20 2026 11:36:37 GMT+0000 (UTC)
|
|
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
|
|
@@ -2392,89 +2392,14 @@ const isStateGetter = (arg) => {
|
|
|
2392
2392
|
return typeof arg === 'function' && arg?.()?.isStateGetter?.();
|
|
2393
2393
|
};
|
|
2394
2394
|
|
|
2395
|
-
const camel2hyphencase
|
|
2395
|
+
const camel2hyphencase = (text = '') => text.replace(/[A-Z]/g, match => '-' + match.toLowerCase());
|
|
2396
2396
|
|
|
2397
|
-
const is_camelcase
|
|
2397
|
+
const is_camelcase = (text = '') =>{
|
|
2398
2398
|
if (text.length === 0) return false;
|
|
2399
2399
|
const camelCasePattern = /^[a-z][a-zA-Z0-9]*$/;
|
|
2400
2400
|
return camelCasePattern.test(text);
|
|
2401
2401
|
};
|
|
2402
2402
|
|
|
2403
|
-
class ZikoUIText extends UINode {
|
|
2404
|
-
constructor(...value) {
|
|
2405
|
-
super("span", "text", false, ...value);
|
|
2406
|
-
this.element = globalThis?.document?.createTextNode(...value);
|
|
2407
|
-
}
|
|
2408
|
-
isText(){
|
|
2409
|
-
return true
|
|
2410
|
-
}
|
|
2411
|
-
}
|
|
2412
|
-
const text = (...str) => new ZikoUIText(...str);
|
|
2413
|
-
|
|
2414
|
-
async function __addItem__(adder, pusher, ...ele) {
|
|
2415
|
-
if (this.cache.isFrozzen) {
|
|
2416
|
-
console.warn("You can't append new item to frozzen element");
|
|
2417
|
-
return this;
|
|
2418
|
-
}
|
|
2419
|
-
for (let i = 0; i < ele.length; i++) {
|
|
2420
|
-
if (["number", "string"].includes(typeof ele[i])) ele[i] = text(ele[i]);
|
|
2421
|
-
// Fix Items Latter
|
|
2422
|
-
if (ele[i] instanceof Function) {
|
|
2423
|
-
const getter = ele[i]();
|
|
2424
|
-
if (getter.isStateGetter) {
|
|
2425
|
-
ele[i] = text(getter.value);
|
|
2426
|
-
getter._subscribe(
|
|
2427
|
-
(newValue) => (ele[i].element.textContent = newValue),
|
|
2428
|
-
ele[i]
|
|
2429
|
-
);
|
|
2430
|
-
// this.element.appendChild(textNode);
|
|
2431
|
-
}
|
|
2432
|
-
}
|
|
2433
|
-
if (typeof globalThis?.Node === "function" && ele[i] instanceof globalThis?.Node) ele[i] = new this.constructor(ele[i]);
|
|
2434
|
-
if (ele[i]?.isUINode) {
|
|
2435
|
-
ele[i].cache.parent = this;
|
|
2436
|
-
this.element?.[adder](ele[i].element);
|
|
2437
|
-
ele[i].target = this.element;
|
|
2438
|
-
this.items[pusher](ele[i]);
|
|
2439
|
-
}
|
|
2440
|
-
else if(ele[i] instanceof Promise){
|
|
2441
|
-
const UIEle = await ele[i];
|
|
2442
|
-
UIEle.cache.parent = this;
|
|
2443
|
-
this.element?.[adder](UIEle.element);
|
|
2444
|
-
UIEle.target = this.element;
|
|
2445
|
-
this.items[pusher](UIEle);
|
|
2446
|
-
}
|
|
2447
|
-
else if (ele[i] instanceof Object) {
|
|
2448
|
-
if (ele[i]?.style) this.style(ele[i]?.style);
|
|
2449
|
-
if (ele[i]?.attr) {
|
|
2450
|
-
Object.entries(ele[i].attr).forEach((n) =>
|
|
2451
|
-
this.setAttr("" + n[0], n[1]),
|
|
2452
|
-
);
|
|
2453
|
-
}
|
|
2454
|
-
}
|
|
2455
|
-
}
|
|
2456
|
-
this.maintain();
|
|
2457
|
-
return this;
|
|
2458
|
-
}
|
|
2459
|
-
function _set_attrs_(name, value){
|
|
2460
|
-
if(globalThis.SVGAElement && this.element instanceof globalThis.SVGAElement) name = is_camelcase$1(name) ? camel2hyphencase$1(name) : name;
|
|
2461
|
-
if(this?.attr[name] && this?.attr[name]===value) return;
|
|
2462
|
-
if(isStateGetter(value)){
|
|
2463
|
-
const getter = value();
|
|
2464
|
-
getter._subscribe(
|
|
2465
|
-
(newValue) => this.element?.setAttribute(name, newValue),
|
|
2466
|
-
this
|
|
2467
|
-
);
|
|
2468
|
-
}
|
|
2469
|
-
else this.element?.setAttribute(name, value);
|
|
2470
|
-
Object.assign(this.cache.attributes, {[name]:value});
|
|
2471
|
-
}
|
|
2472
|
-
|
|
2473
|
-
// import {
|
|
2474
|
-
// is_camelcase,
|
|
2475
|
-
// camel2hyphencase
|
|
2476
|
-
// } from '../../data/string/index.js'
|
|
2477
|
-
|
|
2478
2403
|
function setAttr(name, value) {
|
|
2479
2404
|
if(name instanceof Object){
|
|
2480
2405
|
const [names,values]=[Object.keys(name),Object.values(name)];
|
|
@@ -2500,16 +2425,49 @@ function getAttr(name){
|
|
|
2500
2425
|
function setContentEditable(bool = true) {
|
|
2501
2426
|
this.setAttr("contenteditable", bool);
|
|
2502
2427
|
return this;
|
|
2428
|
+
}
|
|
2429
|
+
|
|
2430
|
+
|
|
2431
|
+
function _set_attrs_(name, value){
|
|
2432
|
+
if(globalThis.SVGAElement && this.element instanceof globalThis.SVGAElement) name = is_camelcase(name) ? camel2hyphencase(name) : name;
|
|
2433
|
+
if(this?.attr[name] && this?.attr[name]===value) return;
|
|
2434
|
+
if(isStateGetter(value)){
|
|
2435
|
+
const getter = value();
|
|
2436
|
+
getter._subscribe(
|
|
2437
|
+
(newValue) => this.element?.setAttribute(name, newValue),
|
|
2438
|
+
this
|
|
2439
|
+
);
|
|
2440
|
+
}
|
|
2441
|
+
else this.element?.setAttribute(name, value);
|
|
2442
|
+
Object.assign(this.cache.attributes, {[name]:value});
|
|
2503
2443
|
}
|
|
2504
2444
|
|
|
2505
2445
|
var AttrsMethods = /*#__PURE__*/Object.freeze({
|
|
2506
2446
|
__proto__: null,
|
|
2447
|
+
_set_attrs_: _set_attrs_,
|
|
2507
2448
|
getAttr: getAttr,
|
|
2508
2449
|
removeAttr: removeAttr,
|
|
2509
2450
|
setAttr: setAttr,
|
|
2510
2451
|
setContentEditable: setContentEditable
|
|
2511
2452
|
});
|
|
2512
2453
|
|
|
2454
|
+
class ZikoUIText extends UINode {
|
|
2455
|
+
constructor(...value) {
|
|
2456
|
+
super("span", "text", false, ...value);
|
|
2457
|
+
this.element = globalThis?.document?.createTextNode(...value);
|
|
2458
|
+
}
|
|
2459
|
+
isText(){
|
|
2460
|
+
return true
|
|
2461
|
+
}
|
|
2462
|
+
}
|
|
2463
|
+
const text = (...str) => new ZikoUIText(...str);
|
|
2464
|
+
|
|
2465
|
+
// import { isStateGetter } from "../../../hooks/use-state.js";
|
|
2466
|
+
// import {
|
|
2467
|
+
// is_camelcase,
|
|
2468
|
+
// camel2hyphencase
|
|
2469
|
+
// } from '../../../data/string/index.js';
|
|
2470
|
+
|
|
2513
2471
|
function append(...ele) {
|
|
2514
2472
|
__addItem__.call(this, "append", "push", ...ele);
|
|
2515
2473
|
return this;
|
|
@@ -2561,713 +2519,68 @@ function before(ui){
|
|
|
2561
2519
|
if(ui?.isUIElement) ui=ui.element;
|
|
2562
2520
|
this.element?.before(ui);
|
|
2563
2521
|
return this;
|
|
2564
|
-
}
|
|
2565
|
-
|
|
2566
|
-
var DomMethods = /*#__PURE__*/Object.freeze({
|
|
2567
|
-
__proto__: null,
|
|
2568
|
-
after: after,
|
|
2569
|
-
append: append,
|
|
2570
|
-
before: before,
|
|
2571
|
-
clear: clear,
|
|
2572
|
-
insertAt: insertAt,
|
|
2573
|
-
prepend: prepend,
|
|
2574
|
-
remove: remove,
|
|
2575
|
-
replaceElementWith: replaceElementWith
|
|
2576
|
-
});
|
|
2577
|
-
|
|
2578
|
-
const EventsMap = {
|
|
2579
|
-
'Click' : [
|
|
2580
|
-
'Click',
|
|
2581
|
-
'DblClick',
|
|
2582
|
-
'ClickAway'
|
|
2583
|
-
],
|
|
2584
|
-
'Ptr' : [
|
|
2585
|
-
'PtrMove',
|
|
2586
|
-
'PtrDown',
|
|
2587
|
-
'PtrUp',
|
|
2588
|
-
'PtrLeave',
|
|
2589
|
-
'PtrEnter',
|
|
2590
|
-
'PtrOut',
|
|
2591
|
-
'PtrCancel'
|
|
2592
|
-
],
|
|
2593
|
-
'Mouse' : [
|
|
2594
|
-
'MouseMove',
|
|
2595
|
-
'MouseDown',
|
|
2596
|
-
'MouseUp',
|
|
2597
|
-
'MouseEnter',
|
|
2598
|
-
'MouseLeave',
|
|
2599
|
-
'MouseOut'
|
|
2600
|
-
],
|
|
2601
|
-
// 'Touch' : [],
|
|
2602
|
-
'Key' : [
|
|
2603
|
-
'KeyDown',
|
|
2604
|
-
'KeyPress',
|
|
2605
|
-
'KeyUp'
|
|
2606
|
-
],
|
|
2607
|
-
'Clipboard':[
|
|
2608
|
-
'Copy',
|
|
2609
|
-
'Cut',
|
|
2610
|
-
'Paste'
|
|
2611
|
-
],
|
|
2612
|
-
'Focus':[
|
|
2613
|
-
'focus',
|
|
2614
|
-
'blur'
|
|
2615
|
-
],
|
|
2616
|
-
'Drag':[
|
|
2617
|
-
"Drag",
|
|
2618
|
-
"DragStart",
|
|
2619
|
-
"DragEnd",
|
|
2620
|
-
"Drop"
|
|
2621
|
-
],
|
|
2622
|
-
'Wheel': [
|
|
2623
|
-
'Wheel'
|
|
2624
|
-
],
|
|
2625
|
-
// 'Media':[
|
|
2626
|
-
|
|
2627
|
-
// ],
|
|
2628
|
-
// 'Hash':[
|
|
2629
|
-
// "HashChange"
|
|
2630
|
-
// ]
|
|
2631
|
-
|
|
2632
|
-
'View':[
|
|
2633
|
-
'EnterView',
|
|
2634
|
-
'ExitView',
|
|
2635
|
-
'ResizeView'
|
|
2636
|
-
],
|
|
2637
|
-
'Swipe':[
|
|
2638
|
-
'SwipeLeft',
|
|
2639
|
-
'SwipeUp',
|
|
2640
|
-
'SwipeRight',
|
|
2641
|
-
'SwipeDown'
|
|
2642
|
-
]
|
|
2643
|
-
};
|
|
2644
|
-
|
|
2645
|
-
function event_controller(e, event_name, details_setter, customizer) {
|
|
2646
|
-
this.cache.currentEvent = event_name;
|
|
2647
|
-
this.cache.event = e;
|
|
2648
|
-
|
|
2649
|
-
details_setter?.call(this);
|
|
2650
|
-
if (customizer?.hasOwnProperty('prototype')) customizer?.call(this);
|
|
2651
|
-
else customizer?.call(null, this);
|
|
2652
|
-
|
|
2653
|
-
if (this.cache.preventDefault[event_name]) e.preventDefault();
|
|
2654
|
-
if (this.cache.stopPropagation[event_name]) e.stopPropagation();
|
|
2655
|
-
if (this.cache.stopImmediatePropagation[event_name]) e.stopImmediatePropagation();
|
|
2656
|
-
|
|
2657
|
-
// Call the single callback if it exists
|
|
2658
|
-
this.cache.callbacks[event_name]?.(this);
|
|
2659
|
-
}
|
|
2660
|
-
|
|
2661
|
-
function toggle_event_listener(method, ...events) {
|
|
2662
|
-
const keys = events.length === 0
|
|
2663
|
-
? Object.keys(this.cache.paused)
|
|
2664
|
-
: events;
|
|
2665
|
-
keys.forEach(key => {
|
|
2666
|
-
if (!this.cache.paused.hasOwnProperty(key)) return;
|
|
2667
|
-
this.targetElement?.[method](
|
|
2668
|
-
key,
|
|
2669
|
-
this.cache.__controllers__[key],
|
|
2670
|
-
this.cache.options[key]
|
|
2671
|
-
);
|
|
2672
|
-
this.cache.paused[key] = method === 'removeEventListener';
|
|
2673
|
-
});
|
|
2674
|
-
return this;
|
|
2675
2522
|
}
|
|
2676
|
-
const getEvent=(event = "")=>{
|
|
2677
|
-
if(event.startsWith("Ptr"))return `pointer${event.split("Ptr")[1].toLowerCase()}`;
|
|
2678
|
-
return event.toLowerCase()
|
|
2679
|
-
};
|
|
2680
|
-
|
|
2681
|
-
class ZikoEvent {
|
|
2682
|
-
constructor(signature, target = null, Events = [], details_setter, customizer){
|
|
2683
|
-
this.target = target;
|
|
2684
|
-
this.cache = {
|
|
2685
|
-
signature,
|
|
2686
|
-
currentEvent : null,
|
|
2687
|
-
event: null,
|
|
2688
|
-
options : {},
|
|
2689
|
-
preventDefault : {},
|
|
2690
|
-
stopPropagation : {},
|
|
2691
|
-
stopImmediatePropagation : {},
|
|
2692
|
-
paused : {},
|
|
2693
|
-
callbacks : {},
|
|
2694
|
-
__controllers__:{}
|
|
2695
|
-
};
|
|
2696
|
-
if (Events) this._register_events(Events, details_setter, customizer);
|
|
2697
|
-
}
|
|
2698
|
-
_register_events(Events, details_setter, customizer, REGISTER_METHODES = true) {
|
|
2699
|
-
const events = Events?.map(n => getEvent(n));
|
|
2700
|
-
events?.forEach((event, i) => {
|
|
2701
|
-
this.cache.preventDefault[event] = false;
|
|
2702
|
-
this.cache.options[event] = {};
|
|
2703
|
-
this.cache.paused[event] = false;
|
|
2704
|
-
this.cache.__controllers__[event] = (e) =>
|
|
2705
|
-
event_controller.call(this, e, event, details_setter, customizer);
|
|
2706
|
-
if (REGISTER_METHODES) {
|
|
2707
|
-
this[`on${Events[i]}`] = (callback) =>
|
|
2708
|
-
this.__onEvent(event, this.cache.options[event], {}, callback);
|
|
2709
|
-
}
|
|
2710
|
-
});
|
|
2711
|
-
return this;
|
|
2712
|
-
}
|
|
2713
|
-
__onEvent(event, options, dispose, callback) {
|
|
2714
|
-
if (!callback) return this;
|
|
2715
|
-
this.cache.callbacks[event] = callback;
|
|
2716
|
-
this.__handle(event, this.cache.__controllers__[event], options, dispose);
|
|
2717
|
-
return this;
|
|
2718
|
-
}
|
|
2719
|
-
get targetElement(){
|
|
2720
|
-
return this.target?.element;
|
|
2721
|
-
}
|
|
2722
|
-
get isParent(){
|
|
2723
|
-
return this.target?.element === this.event?.srcElement;
|
|
2724
|
-
}
|
|
2725
|
-
get item(){
|
|
2726
|
-
return this.target.find(n => n.element == this.event?.srcElement)?.[0];
|
|
2727
|
-
}
|
|
2728
|
-
get currentEvent(){
|
|
2729
|
-
return this.cache.currentEvent;
|
|
2730
|
-
}
|
|
2731
|
-
get event(){
|
|
2732
|
-
return this.cache.event;
|
|
2733
|
-
}
|
|
2734
|
-
get detail(){
|
|
2735
|
-
return this.cache.event.detail
|
|
2736
|
-
}
|
|
2737
|
-
setTarget(UI){
|
|
2738
|
-
this.target = UI;
|
|
2739
|
-
return this;
|
|
2740
|
-
}
|
|
2741
|
-
__handle(event, handler, options){
|
|
2742
|
-
this.targetElement?.addEventListener(event, handler, options);
|
|
2743
|
-
return this;
|
|
2744
|
-
}
|
|
2745
|
-
#override(method, ...events) {
|
|
2746
|
-
const keys = events.length === 0 ? Object.keys(this.cache[method]) : events;
|
|
2747
|
-
keys.forEach(e => {
|
|
2748
|
-
if (this.cache[method].hasOwnProperty(e)) this.cache[method][e] = true;
|
|
2749
|
-
});
|
|
2750
|
-
return this;
|
|
2751
|
-
}
|
|
2752
|
-
preventDefault(...events) {
|
|
2753
|
-
return this.#override('preventDefault', ...events);
|
|
2754
|
-
}
|
|
2755
|
-
stopPropagation(...events) {
|
|
2756
|
-
return this.#override('stopPropagation', ...events);
|
|
2757
|
-
}
|
|
2758
|
-
stopImmediatePropagation(...events) {
|
|
2759
|
-
return this.#override('stopImmediatePropagation', ...events);
|
|
2760
|
-
}
|
|
2761
|
-
setEventOptions(event, options){
|
|
2762
|
-
const evt = getEvent(event);
|
|
2763
|
-
this.pause();
|
|
2764
|
-
Object.assign(this.cache.options[evt], options);
|
|
2765
|
-
this.resume();
|
|
2766
|
-
return this;
|
|
2767
|
-
}
|
|
2768
|
-
pause(...events) {
|
|
2769
|
-
return toggle_event_listener.call(this, 'removeEventListener', ...events)
|
|
2770
|
-
}
|
|
2771
|
-
resume(...events) {
|
|
2772
|
-
return toggle_event_listener.call(this, 'addEventListener', ...events);
|
|
2773
|
-
}
|
|
2774
|
-
dispose(){
|
|
2775
|
-
this.pause();
|
|
2776
|
-
this.target.events[this.cache.signature] = null;
|
|
2777
|
-
return this;
|
|
2778
|
-
}
|
|
2779
|
-
}
|
|
2780
|
-
|
|
2781
|
-
function key_details_setter(){
|
|
2782
|
-
switch(this.currentEvent){
|
|
2783
|
-
case "keydown" : {
|
|
2784
|
-
this.kd = this.event.key;
|
|
2785
|
-
} break;
|
|
2786
|
-
case "keypress" : {
|
|
2787
|
-
this.kp = this.event.key;
|
|
2788
|
-
} break;
|
|
2789
|
-
case "keyup" : {
|
|
2790
|
-
this.ku = this.event.key;
|
|
2791
|
-
} break;
|
|
2792
|
-
|
|
2793
|
-
}
|
|
2794
|
-
}
|
|
2795
|
-
|
|
2796
|
-
function ptr_details_setter() {
|
|
2797
|
-
const rect = this.targetElement.getBoundingClientRect();
|
|
2798
|
-
const e = this.event;
|
|
2799
|
-
let x = (e.clientX - rect.left) | 0;
|
|
2800
|
-
let y = (e.clientY - rect.top) | 0;
|
|
2801
|
-
|
|
2802
|
-
if(this.cache.useNormalisedCoordinates){
|
|
2803
|
-
const w = this.targetElement.clientWidth;
|
|
2804
|
-
const h = this.targetElement.clientHeight;
|
|
2805
|
-
x = +((x / w) * 2 - 1).toFixed(8);
|
|
2806
|
-
y = +((y / h) * -2 + 1).toFixed(8);
|
|
2807
|
-
}
|
|
2808
|
-
switch (this.currentEvent) {
|
|
2809
|
-
|
|
2810
|
-
case "pointerdown":
|
|
2811
|
-
this.dx = x;
|
|
2812
|
-
this.dy = y;
|
|
2813
|
-
this.isDown = true;
|
|
2814
|
-
break;
|
|
2815
|
-
|
|
2816
|
-
case "pointermove":
|
|
2817
|
-
this.mx = x;
|
|
2818
|
-
this.my = y;
|
|
2819
|
-
this.isMoving = true;
|
|
2820
|
-
break;
|
|
2821
|
-
|
|
2822
|
-
case "pointerup":
|
|
2823
|
-
this.ux = x;
|
|
2824
|
-
this.uy = y;
|
|
2825
|
-
this.isDown = false;
|
|
2826
|
-
this.isMoving = false;
|
|
2827
|
-
break;
|
|
2828
|
-
}
|
|
2829
|
-
}
|
|
2830
|
-
|
|
2831
|
-
function mouse_details_setter() {
|
|
2832
|
-
const rect = this.targetElement.getBoundingClientRect();
|
|
2833
|
-
const e = this.event;
|
|
2834
|
-
let x = (e.clientX - rect.left) | 0;
|
|
2835
|
-
let y = (e.clientY - rect.top) | 0;
|
|
2836
|
-
|
|
2837
|
-
if(this.cache.useNormalisedCoordinates){
|
|
2838
|
-
const w = this.targetElement.clientWidth;
|
|
2839
|
-
const h = this.targetElement.clientHeight;
|
|
2840
|
-
x = +((x / w) * 2 - 1).toFixed(8);
|
|
2841
|
-
y = +((y / h) * -2 + 1).toFixed(8);
|
|
2842
|
-
}
|
|
2843
|
-
|
|
2844
|
-
switch (this.currentEvent) {
|
|
2845
|
-
|
|
2846
|
-
case "mousedown":
|
|
2847
|
-
this.dx = x;
|
|
2848
|
-
this.dy = y;
|
|
2849
|
-
this.isDown = true;
|
|
2850
|
-
break;
|
|
2851
2523
|
|
|
2852
|
-
case "mousemove":
|
|
2853
|
-
this.mx = x;
|
|
2854
|
-
this.my = y;
|
|
2855
|
-
this.isMoving = true;
|
|
2856
|
-
break;
|
|
2857
2524
|
|
|
2858
|
-
case "mouserup":
|
|
2859
|
-
this.ux = x;
|
|
2860
|
-
this.uy = y;
|
|
2861
|
-
this.isDown = false;
|
|
2862
|
-
this.isMoving = false;
|
|
2863
|
-
break;
|
|
2864
|
-
}
|
|
2865
|
-
}
|
|
2866
|
-
|
|
2867
|
-
function touch_details_setter() {
|
|
2868
|
-
const e = this.event;
|
|
2869
|
-
const touch = e.touches?.[0] || e.changedTouches?.[0];
|
|
2870
|
-
|
|
2871
|
-
if (!touch) return; // should never happen but safe
|
|
2872
|
-
|
|
2873
|
-
const rect = this.targetElement.getBoundingClientRect();
|
|
2874
|
-
let x = touch.clientX - rect.left;
|
|
2875
|
-
let y = touch.clientY - rect.top;
|
|
2876
|
-
|
|
2877
|
-
if(this.cache.useNormalisedCoordinates){
|
|
2878
|
-
const w = this.targetElement.clientWidth;
|
|
2879
|
-
const h = this.targetElement.clientHeight;
|
|
2880
|
-
x = +((x / w) * 2 - 1).toFixed(8);
|
|
2881
|
-
y = +((y / h) * -2 + 1).toFixed(8);
|
|
2882
|
-
}
|
|
2883
|
-
|
|
2884
|
-
switch (this.currentEvent) {
|
|
2885
|
-
case "touchstart":
|
|
2886
|
-
this.dx = x;
|
|
2887
|
-
this.dy = y;
|
|
2888
|
-
this.isDown = true;
|
|
2889
|
-
break;
|
|
2890
|
-
|
|
2891
|
-
case "touchmove":
|
|
2892
|
-
this.mx = x;
|
|
2893
|
-
this.my = y;
|
|
2894
|
-
this.isMoving = true;
|
|
2895
|
-
break;
|
|
2896
2525
|
|
|
2897
|
-
case "touchend":
|
|
2898
|
-
this.ux = x;
|
|
2899
|
-
this.uy = y;
|
|
2900
|
-
this.isDown = false;
|
|
2901
|
-
break;
|
|
2902
|
-
}
|
|
2903
|
-
}
|
|
2904
|
-
|
|
2905
|
-
class CoordinatesBasedEvent extends ZikoEvent{
|
|
2906
|
-
constructor(signature, target = null, Events = [], details_setter, customizer){
|
|
2907
|
-
super(signature, target, Events, details_setter, customizer);
|
|
2908
|
-
Object.assign(this.cache,{
|
|
2909
|
-
useNormalisedCoordinates : false
|
|
2910
|
-
});
|
|
2911
|
-
this.isDown = false;
|
|
2912
|
-
this.isMoving = false;
|
|
2913
|
-
this.dx = 0;
|
|
2914
|
-
this.dy = 0;
|
|
2915
|
-
this.mx = 0;
|
|
2916
|
-
this.my = 0;
|
|
2917
|
-
this.ux = 0;
|
|
2918
|
-
this.uy = 0;
|
|
2919
|
-
}
|
|
2920
|
-
get isDragging(){
|
|
2921
|
-
return this.isDown && this.isMoving
|
|
2922
|
-
}
|
|
2923
|
-
useNormalisedCoordinates(enable = true){
|
|
2924
|
-
this.cache.useNormalisedCoordinates = enable;
|
|
2925
|
-
return this;
|
|
2926
|
-
}
|
|
2927
|
-
}
|
|
2928
|
-
|
|
2929
|
-
class ClickAwayEvent extends Event {
|
|
2930
|
-
constructor(originalEvent, targetElement) {
|
|
2931
|
-
super("clickaway", { bubbles: true, cancelable: true });
|
|
2932
|
-
this.originalEvent = originalEvent;
|
|
2933
|
-
this.targetElement = targetElement;
|
|
2934
|
-
}
|
|
2935
|
-
}
|
|
2936
2526
|
|
|
2937
|
-
function
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
element.dispatchEvent(clickAwayEvent);
|
|
2942
|
-
}
|
|
2527
|
+
async function __addItem__(adder, pusher, ...ele) {
|
|
2528
|
+
if (this.cache.isFrozzen) {
|
|
2529
|
+
console.warn("You can't append new item to frozzen element");
|
|
2530
|
+
return this;
|
|
2943
2531
|
}
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
// console.log("Clicked outside box!", e);
|
|
2958
|
-
// });
|
|
2959
|
-
|
|
2960
|
-
// // later, you can stop listening:
|
|
2961
|
-
// // stop();
|
|
2962
|
-
|
|
2963
|
-
const debounce=(fn,delay=1000)=>{
|
|
2964
|
-
let id;
|
|
2965
|
-
return (...args) => id ? clearTimeout(id) : setTimeout(()=>fn(...args),delay);
|
|
2966
|
-
};
|
|
2967
|
-
const throttle=(fn,delay)=>{
|
|
2968
|
-
let lastTime=0;
|
|
2969
|
-
return (...args) => {
|
|
2970
|
-
const now = new Date().getTime();
|
|
2971
|
-
if(now-lastTime < delay) return;
|
|
2972
|
-
lastTime = now;
|
|
2973
|
-
fn(...args);
|
|
2974
|
-
}
|
|
2975
|
-
};
|
|
2976
|
-
|
|
2977
|
-
class ViewEvent extends CustomEvent {
|
|
2978
|
-
constructor(type, detail, { bubbles = true, cancelable = true } = {}) {
|
|
2979
|
-
super(type, { detail, bubbles, cancelable });
|
|
2980
|
-
}
|
|
2981
|
-
}
|
|
2982
|
-
|
|
2983
|
-
function register_view_event(
|
|
2984
|
-
element,
|
|
2985
|
-
{
|
|
2986
|
-
intersection = true,
|
|
2987
|
-
resize = true,
|
|
2988
|
-
threshold = 0,
|
|
2989
|
-
throttleResize = 100,
|
|
2990
|
-
throttleEnterExit = 0
|
|
2991
|
-
} = {}
|
|
2992
|
-
) {
|
|
2993
|
-
let intersectionObserver, resizeObserver;
|
|
2994
|
-
const resizeCallback = entries => {
|
|
2995
|
-
for (let entry of entries) {
|
|
2996
|
-
const { width, height } = entry.contentRect;
|
|
2997
|
-
|
|
2998
|
-
element.dispatchEvent(
|
|
2999
|
-
new ViewEvent("resizeview", {
|
|
3000
|
-
width,
|
|
3001
|
-
height,
|
|
3002
|
-
entry
|
|
3003
|
-
})
|
|
3004
|
-
);
|
|
3005
|
-
}
|
|
3006
|
-
};
|
|
3007
|
-
|
|
3008
|
-
const throttledResize = throttleResize > 0
|
|
3009
|
-
? throttle(resizeCallback, throttleResize)
|
|
3010
|
-
: resizeCallback;
|
|
3011
|
-
|
|
3012
|
-
const intersectionCallback = entries => {
|
|
3013
|
-
for (let entry of entries) {
|
|
3014
|
-
const type = entry.isIntersecting ? "enterview" : "exitview";
|
|
3015
|
-
element.dispatchEvent(new ViewEvent(type, entry));
|
|
3016
|
-
}
|
|
3017
|
-
};
|
|
3018
|
-
|
|
3019
|
-
const throttledIntersections = throttleEnterExit > 0
|
|
3020
|
-
? throttle(intersectionCallback, throttleEnterExit)
|
|
3021
|
-
: intersectionCallback;
|
|
3022
|
-
|
|
3023
|
-
if (intersection) {
|
|
3024
|
-
intersectionObserver = new IntersectionObserver(throttledIntersections, { threshold });
|
|
3025
|
-
intersectionObserver.observe(element);
|
|
2532
|
+
for (let i = 0; i < ele.length; i++) {
|
|
2533
|
+
if (["number", "string"].includes(typeof ele[i])) ele[i] = text(ele[i]);
|
|
2534
|
+
// Fix Items Latter
|
|
2535
|
+
if (ele[i] instanceof Function) {
|
|
2536
|
+
const getter = ele[i]();
|
|
2537
|
+
if (getter.isStateGetter) {
|
|
2538
|
+
ele[i] = text(getter.value);
|
|
2539
|
+
getter._subscribe(
|
|
2540
|
+
(newValue) => (ele[i].element.textContent = newValue),
|
|
2541
|
+
ele[i]
|
|
2542
|
+
);
|
|
2543
|
+
// this.element.appendChild(textNode);
|
|
2544
|
+
}
|
|
3026
2545
|
}
|
|
3027
|
-
|
|
3028
|
-
if (
|
|
3029
|
-
|
|
3030
|
-
|
|
2546
|
+
if (typeof globalThis?.Node === "function" && ele[i] instanceof globalThis?.Node) ele[i] = new this.constructor(ele[i]);
|
|
2547
|
+
if (ele[i]?.isUINode) {
|
|
2548
|
+
ele[i].cache.parent = this;
|
|
2549
|
+
this.element?.[adder](ele[i].element);
|
|
2550
|
+
ele[i].target = this.element;
|
|
2551
|
+
this.items[pusher](ele[i]);
|
|
2552
|
+
}
|
|
2553
|
+
else if(ele[i] instanceof Promise){
|
|
2554
|
+
const UIEle = await ele[i];
|
|
2555
|
+
UIEle.cache.parent = this;
|
|
2556
|
+
this.element?.[adder](UIEle.element);
|
|
2557
|
+
UIEle.target = this.element;
|
|
2558
|
+
this.items[pusher](UIEle);
|
|
3031
2559
|
}
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
}
|
|
3039
|
-
if (resizeObserver) {
|
|
3040
|
-
resizeObserver.unobserve(element);
|
|
3041
|
-
resizeObserver.disconnect();
|
|
3042
|
-
}
|
|
3043
|
-
};
|
|
3044
|
-
}
|
|
3045
|
-
|
|
3046
|
-
class SwipeEvent extends CustomEvent {
|
|
3047
|
-
constructor(type, detail) {
|
|
3048
|
-
super(type, {
|
|
3049
|
-
detail,
|
|
3050
|
-
bubbles: true,
|
|
3051
|
-
cancelable: true
|
|
3052
|
-
});
|
|
3053
|
-
}
|
|
3054
|
-
}
|
|
3055
|
-
|
|
3056
|
-
function register_swipe_event(
|
|
3057
|
-
element,
|
|
3058
|
-
threshold = 50,
|
|
3059
|
-
restraint = 100,
|
|
3060
|
-
allowedTime = 500
|
|
3061
|
-
) {
|
|
3062
|
-
let startX = 0,
|
|
3063
|
-
startY = 0,
|
|
3064
|
-
startTime = 0,
|
|
3065
|
-
isPointerDown = false;
|
|
3066
|
-
|
|
3067
|
-
function onPointerDown(e) {
|
|
3068
|
-
startX = e.clientX;
|
|
3069
|
-
startY = e.clientY;
|
|
3070
|
-
startTime = performance.now();
|
|
3071
|
-
isPointerDown = true;
|
|
3072
|
-
}
|
|
3073
|
-
|
|
3074
|
-
function onPointerUp(e) {
|
|
3075
|
-
if (!isPointerDown) return;
|
|
3076
|
-
isPointerDown = false;
|
|
3077
|
-
|
|
3078
|
-
const distX = e.clientX - startX;
|
|
3079
|
-
const distY = e.clientY - startY;
|
|
3080
|
-
const elapsed = performance.now() - startTime;
|
|
3081
|
-
|
|
3082
|
-
let direction = null;
|
|
3083
|
-
let eventName = null;
|
|
3084
|
-
|
|
3085
|
-
if (elapsed <= allowedTime) {
|
|
3086
|
-
if (Math.abs(distX) >= threshold && Math.abs(distY) <= restraint) {
|
|
3087
|
-
direction = distX < 0 ? "left" : "right";
|
|
3088
|
-
eventName = "swipe" + direction;
|
|
3089
|
-
}
|
|
3090
|
-
else if (Math.abs(distY) >= threshold && Math.abs(distX) <= restraint) {
|
|
3091
|
-
direction = distY < 0 ? "up" : "down";
|
|
3092
|
-
eventName = "swipe" + direction;
|
|
2560
|
+
else if (ele[i] instanceof Object) {
|
|
2561
|
+
if (ele[i]?.style) this.style(ele[i]?.style);
|
|
2562
|
+
if (ele[i]?.attr) {
|
|
2563
|
+
Object.entries(ele[i].attr).forEach((n) =>
|
|
2564
|
+
this.setAttr("" + n[0], n[1]),
|
|
2565
|
+
);
|
|
3093
2566
|
}
|
|
3094
2567
|
}
|
|
3095
|
-
|
|
3096
|
-
// Emit event
|
|
3097
|
-
if (eventName) {
|
|
3098
|
-
element.dispatchEvent(
|
|
3099
|
-
new SwipeEvent(eventName, {
|
|
3100
|
-
direction,
|
|
3101
|
-
distX,
|
|
3102
|
-
distY,
|
|
3103
|
-
originalEvent: e
|
|
3104
|
-
})
|
|
3105
|
-
);
|
|
3106
|
-
}
|
|
3107
2568
|
}
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
element.addEventListener("pointerup", onPointerUp, { passive: true });
|
|
3111
|
-
|
|
3112
|
-
return () => {
|
|
3113
|
-
element.removeEventListener("pointerdown", onPointerDown);
|
|
3114
|
-
element.removeEventListener("pointerup", onPointerUp);
|
|
3115
|
-
};
|
|
2569
|
+
this.maintain();
|
|
2570
|
+
return this;
|
|
3116
2571
|
}
|
|
3117
2572
|
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
'clipboard',
|
|
3130
|
-
target,
|
|
3131
|
-
EventsMap.Clipboard,
|
|
3132
|
-
null,
|
|
3133
|
-
customizer
|
|
3134
|
-
);
|
|
3135
|
-
const bind_drag_event = (target, customizer) => new ZikoEvent(
|
|
3136
|
-
'drag',
|
|
3137
|
-
target,
|
|
3138
|
-
EventsMap.Drag,
|
|
3139
|
-
null,
|
|
3140
|
-
customizer
|
|
3141
|
-
);
|
|
3142
|
-
const bind_focus_event = (target, customizer) => new ZikoEvent(
|
|
3143
|
-
'focus',
|
|
3144
|
-
target,
|
|
3145
|
-
EventsMap.Focus,
|
|
3146
|
-
null,
|
|
3147
|
-
customizer
|
|
3148
|
-
);
|
|
3149
|
-
const bind_key_event = (target, customizer) => new ZikoEvent(
|
|
3150
|
-
'key',
|
|
3151
|
-
target,
|
|
3152
|
-
EventsMap.Key,
|
|
3153
|
-
key_details_setter,
|
|
3154
|
-
customizer
|
|
3155
|
-
);
|
|
3156
|
-
const bind_mouse_event = (target, customizer) => new CoordinatesBasedEvent(
|
|
3157
|
-
'mouse',
|
|
3158
|
-
target,
|
|
3159
|
-
EventsMap.Mouse,
|
|
3160
|
-
mouse_details_setter,
|
|
3161
|
-
customizer
|
|
3162
|
-
);
|
|
3163
|
-
const bind_pointer_event = (target, customizer) => new CoordinatesBasedEvent(
|
|
3164
|
-
'ptr',
|
|
3165
|
-
target,
|
|
3166
|
-
EventsMap.Ptr,
|
|
3167
|
-
ptr_details_setter,
|
|
3168
|
-
customizer
|
|
3169
|
-
);
|
|
3170
|
-
const bind_touch_event = (target, customizer) => new CoordinatesBasedEvent(
|
|
3171
|
-
'touch',
|
|
3172
|
-
target,
|
|
3173
|
-
EventsMap.Touch,
|
|
3174
|
-
touch_details_setter,
|
|
3175
|
-
customizer
|
|
3176
|
-
);
|
|
3177
|
-
const bind_wheel_event = (target, customizer) => new ZikoEvent(
|
|
3178
|
-
'wheel',
|
|
3179
|
-
target,
|
|
3180
|
-
EventsMap.Wheel,
|
|
3181
|
-
null,
|
|
3182
|
-
customizer
|
|
3183
|
-
);
|
|
3184
|
-
|
|
3185
|
-
const bind_view_event = (target, customizer) => {
|
|
3186
|
-
register_view_event(target.element);
|
|
3187
|
-
return new ZikoEvent(
|
|
3188
|
-
'view',
|
|
3189
|
-
target,
|
|
3190
|
-
EventsMap.View,
|
|
3191
|
-
null,
|
|
3192
|
-
customizer
|
|
3193
|
-
)
|
|
3194
|
-
};
|
|
3195
|
-
|
|
3196
|
-
const bind_swipe_event = (target, customizer) => {
|
|
3197
|
-
register_swipe_event(target.element);
|
|
3198
|
-
return new ZikoEvent(
|
|
3199
|
-
'swipe',
|
|
3200
|
-
target,
|
|
3201
|
-
EventsMap.Swipe,
|
|
3202
|
-
null,
|
|
3203
|
-
customizer
|
|
3204
|
-
)
|
|
3205
|
-
};
|
|
3206
|
-
|
|
3207
|
-
class ZikoCustomEvent extends ZikoEvent{
|
|
3208
|
-
constructor(target, events, customizer){
|
|
3209
|
-
super('custom', target, events, details_setter, customizer);
|
|
3210
|
-
}
|
|
3211
|
-
_register_events(events){
|
|
3212
|
-
super._register_events(events, null, null, false);
|
|
3213
|
-
return this;
|
|
3214
|
-
}
|
|
3215
|
-
emit(event_name, detail = {}){
|
|
3216
|
-
const event = new CustomEvent(event_name, {
|
|
3217
|
-
detail,
|
|
3218
|
-
bubbles: true,
|
|
3219
|
-
cancelable: true
|
|
3220
|
-
});
|
|
3221
|
-
this.targetElement.dispatchEvent(event);
|
|
3222
|
-
return this;
|
|
3223
|
-
}
|
|
3224
|
-
on(event_name, ...callbacks){
|
|
3225
|
-
if(!this.cache.options.hasOwnProperty(event_name)) this._register_events([event_name]);
|
|
3226
|
-
this.__onEvent(event_name, this.cache.options[event_name], {}, ...callbacks);
|
|
3227
|
-
return this;
|
|
3228
|
-
}
|
|
3229
|
-
}
|
|
3230
|
-
function details_setter(){
|
|
3231
|
-
|
|
3232
|
-
}
|
|
3233
|
-
const bind_custom_event = (target, events, customizer) => new ZikoCustomEvent(target, events, customizer);
|
|
3234
|
-
|
|
3235
|
-
const binderMap = {
|
|
3236
|
-
ptr: bind_pointer_event,
|
|
3237
|
-
mouse : bind_mouse_event,
|
|
3238
|
-
key: bind_key_event,
|
|
3239
|
-
click : bind_click_event,
|
|
3240
|
-
drag : bind_drag_event,
|
|
3241
|
-
clipboard : bind_clipboard_event,
|
|
3242
|
-
focus : bind_focus_event,
|
|
3243
|
-
wheel : bind_wheel_event,
|
|
3244
|
-
view : bind_view_event,
|
|
3245
|
-
swipe : bind_swipe_event
|
|
3246
|
-
};
|
|
3247
|
-
|
|
3248
|
-
const EventsMethodes = {
|
|
3249
|
-
on(event_name,...callbacks){
|
|
3250
|
-
if(!this.events.custom)this.events.custom = bind_custom_event(this);
|
|
3251
|
-
this.events.custom.on(event_name,...callbacks);
|
|
3252
|
-
return this;
|
|
3253
|
-
},
|
|
3254
|
-
emit(event_name,detail={}){
|
|
3255
|
-
if(!this.events.custom)this.events.custom = bind_custom_event(this);
|
|
3256
|
-
this.events.custom.emit(event_name,detail);
|
|
3257
|
-
return this;
|
|
3258
|
-
}
|
|
3259
|
-
};
|
|
3260
|
-
|
|
3261
|
-
Object.entries(EventsMap).forEach(([name, eventList]) => {
|
|
3262
|
-
const lname = name.toLowerCase();
|
|
3263
|
-
eventList.forEach(event => {
|
|
3264
|
-
const methodName = `on${event}`;
|
|
3265
|
-
EventsMethodes[methodName] = function (callbacks) {
|
|
3266
|
-
if (!this.events[lname]) this.events[lname] = binderMap[lname](this);
|
|
3267
|
-
this.events[lname][methodName](callbacks);
|
|
3268
|
-
return this;
|
|
3269
|
-
};
|
|
3270
|
-
});
|
|
2573
|
+
var DomMethods = /*#__PURE__*/Object.freeze({
|
|
2574
|
+
__proto__: null,
|
|
2575
|
+
__addItem__: __addItem__,
|
|
2576
|
+
after: after,
|
|
2577
|
+
append: append,
|
|
2578
|
+
before: before,
|
|
2579
|
+
clear: clear,
|
|
2580
|
+
insertAt: insertAt,
|
|
2581
|
+
prepend: prepend,
|
|
2582
|
+
remove: remove,
|
|
2583
|
+
replaceElementWith: replaceElementWith
|
|
3271
2584
|
});
|
|
3272
2585
|
|
|
3273
2586
|
function at(index) {
|
|
@@ -3334,44 +2647,195 @@ var StyleMethods = /*#__PURE__*/Object.freeze({
|
|
|
3334
2647
|
style: style$1
|
|
3335
2648
|
});
|
|
3336
2649
|
|
|
2650
|
+
class ClickAwayEvent extends Event {
|
|
2651
|
+
constructor(originalEvent, targetElement) {
|
|
2652
|
+
super("clickaway", { bubbles: true, cancelable: true });
|
|
2653
|
+
this.originalEvent = originalEvent;
|
|
2654
|
+
this.targetElement = targetElement;
|
|
2655
|
+
}
|
|
2656
|
+
}
|
|
2657
|
+
|
|
2658
|
+
function register_click_away_event(element) {
|
|
2659
|
+
// console.log(element)
|
|
2660
|
+
function handler(e) {
|
|
2661
|
+
if (!element.contains(e.target)) {
|
|
2662
|
+
const clickAwayEvent = new ClickAwayEvent(e, element);
|
|
2663
|
+
element.dispatchEvent(clickAwayEvent);
|
|
2664
|
+
}
|
|
2665
|
+
}
|
|
2666
|
+
|
|
2667
|
+
globalThis?.document?.addEventListener("click", handler);
|
|
2668
|
+
|
|
2669
|
+
return () => globalThis?.document?.removeEventListener("click", handler);
|
|
2670
|
+
|
|
2671
|
+
}
|
|
2672
|
+
|
|
2673
|
+
// // Example usage
|
|
2674
|
+
// const box = document.querySelector("#my-box");
|
|
2675
|
+
|
|
2676
|
+
// const stop = listenClickAway(box);
|
|
2677
|
+
|
|
2678
|
+
// box.addEventListener("clickaway", (e) => {
|
|
2679
|
+
// console.log("Clicked outside box!", e);
|
|
2680
|
+
// });
|
|
2681
|
+
|
|
2682
|
+
// // later, you can stop listening:
|
|
2683
|
+
// // stop();
|
|
2684
|
+
|
|
2685
|
+
const CATEGORY$2 = 'click';
|
|
2686
|
+
const ClickListeners = {
|
|
2687
|
+
onClick(callback){
|
|
2688
|
+
this._on(
|
|
2689
|
+
'click', callback,
|
|
2690
|
+
{ category : CATEGORY$2 });
|
|
2691
|
+
},
|
|
2692
|
+
onDblClick(callback){
|
|
2693
|
+
this._on(
|
|
2694
|
+
'dblclick', callback,
|
|
2695
|
+
{ category : CATEGORY$2});
|
|
2696
|
+
},
|
|
2697
|
+
onClickAway(callback){
|
|
2698
|
+
register_click_away_event(this.element);
|
|
2699
|
+
this._on(
|
|
2700
|
+
'clickaway', callback,
|
|
2701
|
+
{ category : CATEGORY$2});
|
|
2702
|
+
},
|
|
2703
|
+
};
|
|
2704
|
+
|
|
2705
|
+
const getCoordinates = (ctx, normalized = false) =>{
|
|
2706
|
+
const rect = ctx.element.getBoundingClientRect();
|
|
2707
|
+
const e = ctx.event;
|
|
2708
|
+
let x = (e?.clientX - rect.left) | 0;
|
|
2709
|
+
let y = (e?.clientY - rect.top) | 0;
|
|
2710
|
+
|
|
2711
|
+
if(normalized){
|
|
2712
|
+
const w = ctx.element.clientWidth;
|
|
2713
|
+
const h = ctx.element.clientHeight;
|
|
2714
|
+
x = +((x / w) * 2 - 1).toFixed(8);
|
|
2715
|
+
y = +((y / h) * -2 + 1).toFixed(8);
|
|
2716
|
+
}
|
|
2717
|
+
|
|
2718
|
+
return {x, y};
|
|
2719
|
+
};
|
|
2720
|
+
|
|
2721
|
+
const CATEGORY$1 = 'ptr';
|
|
2722
|
+
const PtrListeners = {
|
|
2723
|
+
onPtrDown(callback, useNormalizedCoordinates = false){
|
|
2724
|
+
this._on(
|
|
2725
|
+
'pointerdown', callback,
|
|
2726
|
+
{ category : CATEGORY$1, details_setter : (ctx)=> {
|
|
2727
|
+
const {x, y} = getCoordinates(ctx, useNormalizedCoordinates);
|
|
2728
|
+
ctx.dx = x;
|
|
2729
|
+
ctx.dy = y;
|
|
2730
|
+
ctx.isDown = true;
|
|
2731
|
+
ctx.isDragging = ctx.isMoving ?? false;
|
|
2732
|
+
}}
|
|
2733
|
+
);
|
|
2734
|
+
},
|
|
2735
|
+
onPtrMove(callback, useNormalizedCoordinates = false){
|
|
2736
|
+
this._on(
|
|
2737
|
+
'pointermove', callback,
|
|
2738
|
+
{ category : CATEGORY$1, details_setter : (ctx)=> {
|
|
2739
|
+
const {x, y} = getCoordinates(ctx, useNormalizedCoordinates);
|
|
2740
|
+
ctx.mx = x;
|
|
2741
|
+
ctx.my = y;
|
|
2742
|
+
ctx.isMoving = true;
|
|
2743
|
+
ctx.isDragging = ctx.isDown ?? false;
|
|
2744
|
+
}}
|
|
2745
|
+
);
|
|
2746
|
+
},
|
|
2747
|
+
onPtrUp(callback, useNormalizedCoordinates = false){
|
|
2748
|
+
this._on(
|
|
2749
|
+
'pointerup', callback,
|
|
2750
|
+
{ category : CATEGORY$1, details_setter : (ctx)=> {
|
|
2751
|
+
const {x, y} = getCoordinates(ctx, useNormalizedCoordinates);
|
|
2752
|
+
ctx.ux = x;
|
|
2753
|
+
ctx.uy = y;
|
|
2754
|
+
ctx.isDown = false;
|
|
2755
|
+
ctx.isMoving = false;
|
|
2756
|
+
ctx.isDragging = false;
|
|
2757
|
+
}}
|
|
2758
|
+
);
|
|
2759
|
+
}
|
|
2760
|
+
};
|
|
2761
|
+
|
|
2762
|
+
const CATEGORY = 'key';
|
|
2763
|
+
const KeyListeners = {
|
|
2764
|
+
onKeyDown(callback){
|
|
2765
|
+
this._on(
|
|
2766
|
+
'keydown', callback,
|
|
2767
|
+
{ category : CATEGORY, details_setter : ctx=> { ctx.kd = ctx.event.key; }
|
|
2768
|
+
});
|
|
2769
|
+
},
|
|
2770
|
+
onKeyPress(callback){
|
|
2771
|
+
this._on(
|
|
2772
|
+
'keypress', callback,
|
|
2773
|
+
{ category : CATEGORY, details_setter : ctx=> { ctx.kp = ctx.event.key; }
|
|
2774
|
+
});
|
|
2775
|
+
},
|
|
2776
|
+
onKeyUp(callback){
|
|
2777
|
+
this._on(
|
|
2778
|
+
'keydown', callback,
|
|
2779
|
+
{ category : CATEGORY, details_setter : ctx=> { ctx.ku = ctx.event.key; }
|
|
2780
|
+
});
|
|
2781
|
+
},
|
|
2782
|
+
|
|
2783
|
+
};
|
|
2784
|
+
|
|
3337
2785
|
class EventController {
|
|
3338
2786
|
constructor(target, category){
|
|
3339
2787
|
this.cache = {
|
|
3340
2788
|
category,
|
|
3341
2789
|
target,
|
|
3342
2790
|
listeners : {},
|
|
3343
|
-
currentEvent : null
|
|
2791
|
+
currentEvent : null,
|
|
2792
|
+
event : null
|
|
3344
2793
|
};
|
|
3345
2794
|
}
|
|
2795
|
+
get event(){
|
|
2796
|
+
return this.cache.event
|
|
2797
|
+
}
|
|
3346
2798
|
get element(){
|
|
3347
2799
|
return this.cache.target.element;
|
|
3348
2800
|
}
|
|
3349
2801
|
get currentEvent(){
|
|
3350
2802
|
return this.cache.currentEvent;
|
|
3351
2803
|
}
|
|
3352
|
-
addListener(
|
|
3353
|
-
this.cache.listeners[
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
if(
|
|
3357
|
-
|
|
2804
|
+
addListener(event_name, callback, {preventDefault = false, paused = false} = {}){
|
|
2805
|
+
this.cache.listeners[event_name] = {
|
|
2806
|
+
callback : e =>{
|
|
2807
|
+
this.cache.event = e;
|
|
2808
|
+
if(this.cache.listeners[event_name].preventDefault) e.preventDefault();
|
|
2809
|
+
if(!this.cache.listeners[event_name].paused) {
|
|
2810
|
+
this.cache.currentEvent = event_name;
|
|
3358
2811
|
callback.call(this, this);
|
|
3359
2812
|
}
|
|
3360
2813
|
},
|
|
2814
|
+
preventDefault,
|
|
2815
|
+
paused,
|
|
3361
2816
|
};
|
|
3362
|
-
this.element.addEventListener(
|
|
2817
|
+
this.element.addEventListener(event_name, this.cache.listeners[event_name].callback);
|
|
2818
|
+
return this;
|
|
2819
|
+
}
|
|
2820
|
+
removeListener(event_name){
|
|
2821
|
+
this.element.removeEventListener(event_name, this.cache.listeners[event_name].callback);
|
|
3363
2822
|
return this;
|
|
3364
2823
|
}
|
|
3365
|
-
|
|
3366
|
-
this.
|
|
2824
|
+
pause(event_name){
|
|
2825
|
+
this.cache.listeners[event_name].paused = true;
|
|
3367
2826
|
return this;
|
|
3368
2827
|
}
|
|
3369
|
-
|
|
3370
|
-
this.cache.listeners[
|
|
2828
|
+
resume(event_name){
|
|
2829
|
+
this.cache.listeners[event_name].paused = false;
|
|
3371
2830
|
return this;
|
|
3372
2831
|
}
|
|
3373
|
-
|
|
3374
|
-
|
|
2832
|
+
preventDefault(event_name){
|
|
2833
|
+
// if(!event_name)
|
|
2834
|
+
this.cache.listeners[event_name].preventDefault = true;
|
|
2835
|
+
return this;
|
|
2836
|
+
}
|
|
2837
|
+
useDefault(event_name){
|
|
2838
|
+
this.cache.listeners[event_name].preventDefault = false;
|
|
3375
2839
|
return this;
|
|
3376
2840
|
}
|
|
3377
2841
|
}
|
|
@@ -3391,16 +2855,23 @@ let UIElement$1 = class UIElement extends UIElementCore{
|
|
|
3391
2855
|
DomMethods,
|
|
3392
2856
|
StyleMethods,
|
|
3393
2857
|
IndexingMethods,
|
|
3394
|
-
|
|
2858
|
+
PtrListeners,
|
|
2859
|
+
ClickListeners,
|
|
2860
|
+
KeyListeners
|
|
3395
2861
|
);
|
|
3396
2862
|
|
|
3397
2863
|
if(element)this.init(element, name, type, render);
|
|
3398
2864
|
}
|
|
3399
|
-
_on(event, callback, {details_setter, category = 'global'} = {}){
|
|
2865
|
+
_on(event, callback, {details_setter, category = 'global', preventDefault = false} = {}){
|
|
3400
2866
|
if(category && !this.exp.events.hasOwnProperty(category)) this.exp.events[category] = new EventController(this, category);
|
|
3401
2867
|
const EVENT = this.exp.events[category];
|
|
3402
|
-
EVENT.addListener(event,
|
|
3403
|
-
|
|
2868
|
+
EVENT.addListener(event, (e)=>{
|
|
2869
|
+
if(details_setter) details_setter(EVENT);
|
|
2870
|
+
callback(e);
|
|
2871
|
+
},{
|
|
2872
|
+
preventDefault
|
|
2873
|
+
});
|
|
2874
|
+
|
|
3404
2875
|
}
|
|
3405
2876
|
_off(event, category = 'global'){
|
|
3406
2877
|
this.exp.events[category].removeListener(event);
|
|
@@ -4388,6 +3859,20 @@ const Scheduler = (tasks, { repeat = null} = {}) => new TimeScheduler(tasks, { r
|
|
|
4388
3859
|
|
|
4389
3860
|
const step_fps = (step_or_fps) => 1000 / step_or_fps;
|
|
4390
3861
|
|
|
3862
|
+
const debounce=(fn,delay=1000)=>{
|
|
3863
|
+
let id;
|
|
3864
|
+
return (...args) => id ? clearTimeout(id) : setTimeout(()=>fn(...args),delay);
|
|
3865
|
+
};
|
|
3866
|
+
const throttle=(fn,delay)=>{
|
|
3867
|
+
let lastTime=0;
|
|
3868
|
+
return (...args) => {
|
|
3869
|
+
const now = new Date().getTime();
|
|
3870
|
+
if(now-lastTime < delay) return;
|
|
3871
|
+
lastTime = now;
|
|
3872
|
+
fn(...args);
|
|
3873
|
+
}
|
|
3874
|
+
};
|
|
3875
|
+
|
|
4391
3876
|
const sleep= ms => new Promise(res => setTimeout(res, ms));
|
|
4392
3877
|
function timeout(ms, fn) {
|
|
4393
3878
|
let id;
|
|
@@ -5404,4 +4889,4 @@ if(globalThis?.document){
|
|
|
5404
4889
|
document?.addEventListener("DOMContentLoaded", __Ziko__.__Config__.init());
|
|
5405
4890
|
}
|
|
5406
4891
|
|
|
5407
|
-
export { App, Clock, CloneElement, Complex, E, EPSILON, FileBasedRouting, Flex, HTMLWrapper, Matrix, PI$1 as PI, Random, SPA, SVGWrapper, Scheduler, Suspense, Switch, Tick, TimeAnimation, TimeLoop, TimeScheduler, UIElement$1 as UIElement, UIFlex, UIHTMLWrapper, UINode, UISVGWrapper, UISwitch, UIView, UseRoot, UseThread, Utils, View, ZikoApp,
|
|
4892
|
+
export { App, Clock, CloneElement, Complex, E, EPSILON, EventController, FileBasedRouting, Flex, HTMLWrapper, Matrix, PI$1 as PI, Random, SPA, SVGWrapper, Scheduler, Suspense, Switch, Tick, TimeAnimation, TimeLoop, TimeScheduler, UIElement$1 as UIElement, UIFlex, UIHTMLWrapper, UINode, UISVGWrapper, UISwitch, UIView, UseRoot, UseThread, Utils, View, ZikoApp, ZikoSPA, ZikoUISuspense, ZikoUIText, abs, accum_prod, accum_sum, acos$1 as acos, acosh, acot, add, add_class, add_vendor_prefix, and, animation, apply_fun, arange, arc, arr2str, asin, asinh, atan, atan2, atanh, back, binomial, call_with_optional_props, cartesianProduct, cbrt, ceil, clamp, clock, cloneUI, complex, cos$3 as cos, cosh$2 as cosh, coth, croot, csv2arr, csv2json, csv2matrix, csv2object, csv2sql, debounce, defineParamsGetter, define_wc, deg2rad, discret, div, elastic, exp$1 as exp, floor, fract, geomspace, hypot, inRange, in_back, in_bounce, in_circ, in_cubic, in_elastic, in_expo, in_out_back, in_out_bounce, in_out_circ, in_out_cubic, in_out_elastic, in_out_expo, in_out_quad, in_out_quart, in_out_quint, in_out_sin, in_quad, in_quart, in_quint, in_sin, isApproximatlyEqual, isPrimitive, isStateGetter, json2arr, json2css, json2csv, json2csvFile, json2xml, json2xmlFile, json2yml, json2ymlFile, lerp, linear, linkStyle, linspace, ln, logspace, loop, map$1 as map, mapfun, matrix, matrix2, matrix3, matrix4, max, mean, median, min, modulo, mul, nand, nor, norm, normalize_css_value, nthr, nums, obj2str, ones, or, out_back, out_bounce, out_circ, out_cubic, out_elastic, out_expo, out_quad, out_quart, out_quint, out_sin, percentile, pgcd, pow$1 as pow, ppcm, rad2deg, remove_class, round, script, sec, sig, sign, sin$3 as sin, sinh$1 as sinh, sleep, sqrt$2 as sqrt, std, step, step_fps, style, sub, svg2ascii, svg2img, svg2imgUrl, svg2str, tags, tan, tanh, text, throttle, tick, timeTaken, time_memory_Taken, timeout, trunc, useDerived, useEventEmitter, useIPC, useLocaleStorage, useMediaQuery, useReactive, useRoot, useSessionStorage, useState, useThread, useTitle, variance, wait, waitElm, waitForUIElm, waitForUIElmSync, xnor, xor, zeros };
|