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.js
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
|
|
@@ -2398,89 +2398,14 @@
|
|
|
2398
2398
|
return typeof arg === 'function' && arg?.()?.isStateGetter?.();
|
|
2399
2399
|
};
|
|
2400
2400
|
|
|
2401
|
-
const camel2hyphencase
|
|
2401
|
+
const camel2hyphencase = (text = '') => text.replace(/[A-Z]/g, match => '-' + match.toLowerCase());
|
|
2402
2402
|
|
|
2403
|
-
const is_camelcase
|
|
2403
|
+
const is_camelcase = (text = '') =>{
|
|
2404
2404
|
if (text.length === 0) return false;
|
|
2405
2405
|
const camelCasePattern = /^[a-z][a-zA-Z0-9]*$/;
|
|
2406
2406
|
return camelCasePattern.test(text);
|
|
2407
2407
|
};
|
|
2408
2408
|
|
|
2409
|
-
class ZikoUIText extends UINode {
|
|
2410
|
-
constructor(...value) {
|
|
2411
|
-
super("span", "text", false, ...value);
|
|
2412
|
-
this.element = globalThis?.document?.createTextNode(...value);
|
|
2413
|
-
}
|
|
2414
|
-
isText(){
|
|
2415
|
-
return true
|
|
2416
|
-
}
|
|
2417
|
-
}
|
|
2418
|
-
const text = (...str) => new ZikoUIText(...str);
|
|
2419
|
-
|
|
2420
|
-
async function __addItem__(adder, pusher, ...ele) {
|
|
2421
|
-
if (this.cache.isFrozzen) {
|
|
2422
|
-
console.warn("You can't append new item to frozzen element");
|
|
2423
|
-
return this;
|
|
2424
|
-
}
|
|
2425
|
-
for (let i = 0; i < ele.length; i++) {
|
|
2426
|
-
if (["number", "string"].includes(typeof ele[i])) ele[i] = text(ele[i]);
|
|
2427
|
-
// Fix Items Latter
|
|
2428
|
-
if (ele[i] instanceof Function) {
|
|
2429
|
-
const getter = ele[i]();
|
|
2430
|
-
if (getter.isStateGetter) {
|
|
2431
|
-
ele[i] = text(getter.value);
|
|
2432
|
-
getter._subscribe(
|
|
2433
|
-
(newValue) => (ele[i].element.textContent = newValue),
|
|
2434
|
-
ele[i]
|
|
2435
|
-
);
|
|
2436
|
-
// this.element.appendChild(textNode);
|
|
2437
|
-
}
|
|
2438
|
-
}
|
|
2439
|
-
if (typeof globalThis?.Node === "function" && ele[i] instanceof globalThis?.Node) ele[i] = new this.constructor(ele[i]);
|
|
2440
|
-
if (ele[i]?.isUINode) {
|
|
2441
|
-
ele[i].cache.parent = this;
|
|
2442
|
-
this.element?.[adder](ele[i].element);
|
|
2443
|
-
ele[i].target = this.element;
|
|
2444
|
-
this.items[pusher](ele[i]);
|
|
2445
|
-
}
|
|
2446
|
-
else if(ele[i] instanceof Promise){
|
|
2447
|
-
const UIEle = await ele[i];
|
|
2448
|
-
UIEle.cache.parent = this;
|
|
2449
|
-
this.element?.[adder](UIEle.element);
|
|
2450
|
-
UIEle.target = this.element;
|
|
2451
|
-
this.items[pusher](UIEle);
|
|
2452
|
-
}
|
|
2453
|
-
else if (ele[i] instanceof Object) {
|
|
2454
|
-
if (ele[i]?.style) this.style(ele[i]?.style);
|
|
2455
|
-
if (ele[i]?.attr) {
|
|
2456
|
-
Object.entries(ele[i].attr).forEach((n) =>
|
|
2457
|
-
this.setAttr("" + n[0], n[1]),
|
|
2458
|
-
);
|
|
2459
|
-
}
|
|
2460
|
-
}
|
|
2461
|
-
}
|
|
2462
|
-
this.maintain();
|
|
2463
|
-
return this;
|
|
2464
|
-
}
|
|
2465
|
-
function _set_attrs_(name, value){
|
|
2466
|
-
if(globalThis.SVGAElement && this.element instanceof globalThis.SVGAElement) name = is_camelcase$1(name) ? camel2hyphencase$1(name) : name;
|
|
2467
|
-
if(this?.attr[name] && this?.attr[name]===value) return;
|
|
2468
|
-
if(isStateGetter(value)){
|
|
2469
|
-
const getter = value();
|
|
2470
|
-
getter._subscribe(
|
|
2471
|
-
(newValue) => this.element?.setAttribute(name, newValue),
|
|
2472
|
-
this
|
|
2473
|
-
);
|
|
2474
|
-
}
|
|
2475
|
-
else this.element?.setAttribute(name, value);
|
|
2476
|
-
Object.assign(this.cache.attributes, {[name]:value});
|
|
2477
|
-
}
|
|
2478
|
-
|
|
2479
|
-
// import {
|
|
2480
|
-
// is_camelcase,
|
|
2481
|
-
// camel2hyphencase
|
|
2482
|
-
// } from '../../data/string/index.js'
|
|
2483
|
-
|
|
2484
2409
|
function setAttr(name, value) {
|
|
2485
2410
|
if(name instanceof Object){
|
|
2486
2411
|
const [names,values]=[Object.keys(name),Object.values(name)];
|
|
@@ -2506,16 +2431,49 @@
|
|
|
2506
2431
|
function setContentEditable(bool = true) {
|
|
2507
2432
|
this.setAttr("contenteditable", bool);
|
|
2508
2433
|
return this;
|
|
2434
|
+
}
|
|
2435
|
+
|
|
2436
|
+
|
|
2437
|
+
function _set_attrs_(name, value){
|
|
2438
|
+
if(globalThis.SVGAElement && this.element instanceof globalThis.SVGAElement) name = is_camelcase(name) ? camel2hyphencase(name) : name;
|
|
2439
|
+
if(this?.attr[name] && this?.attr[name]===value) return;
|
|
2440
|
+
if(isStateGetter(value)){
|
|
2441
|
+
const getter = value();
|
|
2442
|
+
getter._subscribe(
|
|
2443
|
+
(newValue) => this.element?.setAttribute(name, newValue),
|
|
2444
|
+
this
|
|
2445
|
+
);
|
|
2446
|
+
}
|
|
2447
|
+
else this.element?.setAttribute(name, value);
|
|
2448
|
+
Object.assign(this.cache.attributes, {[name]:value});
|
|
2509
2449
|
}
|
|
2510
2450
|
|
|
2511
2451
|
var AttrsMethods = /*#__PURE__*/Object.freeze({
|
|
2512
2452
|
__proto__: null,
|
|
2453
|
+
_set_attrs_: _set_attrs_,
|
|
2513
2454
|
getAttr: getAttr,
|
|
2514
2455
|
removeAttr: removeAttr,
|
|
2515
2456
|
setAttr: setAttr,
|
|
2516
2457
|
setContentEditable: setContentEditable
|
|
2517
2458
|
});
|
|
2518
2459
|
|
|
2460
|
+
class ZikoUIText extends UINode {
|
|
2461
|
+
constructor(...value) {
|
|
2462
|
+
super("span", "text", false, ...value);
|
|
2463
|
+
this.element = globalThis?.document?.createTextNode(...value);
|
|
2464
|
+
}
|
|
2465
|
+
isText(){
|
|
2466
|
+
return true
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
const text = (...str) => new ZikoUIText(...str);
|
|
2470
|
+
|
|
2471
|
+
// import { isStateGetter } from "../../../hooks/use-state.js";
|
|
2472
|
+
// import {
|
|
2473
|
+
// is_camelcase,
|
|
2474
|
+
// camel2hyphencase
|
|
2475
|
+
// } from '../../../data/string/index.js';
|
|
2476
|
+
|
|
2519
2477
|
function append(...ele) {
|
|
2520
2478
|
__addItem__.call(this, "append", "push", ...ele);
|
|
2521
2479
|
return this;
|
|
@@ -2567,713 +2525,68 @@
|
|
|
2567
2525
|
if(ui?.isUIElement) ui=ui.element;
|
|
2568
2526
|
this.element?.before(ui);
|
|
2569
2527
|
return this;
|
|
2570
|
-
}
|
|
2571
|
-
|
|
2572
|
-
var DomMethods = /*#__PURE__*/Object.freeze({
|
|
2573
|
-
__proto__: null,
|
|
2574
|
-
after: after,
|
|
2575
|
-
append: append,
|
|
2576
|
-
before: before,
|
|
2577
|
-
clear: clear,
|
|
2578
|
-
insertAt: insertAt,
|
|
2579
|
-
prepend: prepend,
|
|
2580
|
-
remove: remove,
|
|
2581
|
-
replaceElementWith: replaceElementWith
|
|
2582
|
-
});
|
|
2583
|
-
|
|
2584
|
-
const EventsMap = {
|
|
2585
|
-
'Click' : [
|
|
2586
|
-
'Click',
|
|
2587
|
-
'DblClick',
|
|
2588
|
-
'ClickAway'
|
|
2589
|
-
],
|
|
2590
|
-
'Ptr' : [
|
|
2591
|
-
'PtrMove',
|
|
2592
|
-
'PtrDown',
|
|
2593
|
-
'PtrUp',
|
|
2594
|
-
'PtrLeave',
|
|
2595
|
-
'PtrEnter',
|
|
2596
|
-
'PtrOut',
|
|
2597
|
-
'PtrCancel'
|
|
2598
|
-
],
|
|
2599
|
-
'Mouse' : [
|
|
2600
|
-
'MouseMove',
|
|
2601
|
-
'MouseDown',
|
|
2602
|
-
'MouseUp',
|
|
2603
|
-
'MouseEnter',
|
|
2604
|
-
'MouseLeave',
|
|
2605
|
-
'MouseOut'
|
|
2606
|
-
],
|
|
2607
|
-
// 'Touch' : [],
|
|
2608
|
-
'Key' : [
|
|
2609
|
-
'KeyDown',
|
|
2610
|
-
'KeyPress',
|
|
2611
|
-
'KeyUp'
|
|
2612
|
-
],
|
|
2613
|
-
'Clipboard':[
|
|
2614
|
-
'Copy',
|
|
2615
|
-
'Cut',
|
|
2616
|
-
'Paste'
|
|
2617
|
-
],
|
|
2618
|
-
'Focus':[
|
|
2619
|
-
'focus',
|
|
2620
|
-
'blur'
|
|
2621
|
-
],
|
|
2622
|
-
'Drag':[
|
|
2623
|
-
"Drag",
|
|
2624
|
-
"DragStart",
|
|
2625
|
-
"DragEnd",
|
|
2626
|
-
"Drop"
|
|
2627
|
-
],
|
|
2628
|
-
'Wheel': [
|
|
2629
|
-
'Wheel'
|
|
2630
|
-
],
|
|
2631
|
-
// 'Media':[
|
|
2632
|
-
|
|
2633
|
-
// ],
|
|
2634
|
-
// 'Hash':[
|
|
2635
|
-
// "HashChange"
|
|
2636
|
-
// ]
|
|
2637
|
-
|
|
2638
|
-
'View':[
|
|
2639
|
-
'EnterView',
|
|
2640
|
-
'ExitView',
|
|
2641
|
-
'ResizeView'
|
|
2642
|
-
],
|
|
2643
|
-
'Swipe':[
|
|
2644
|
-
'SwipeLeft',
|
|
2645
|
-
'SwipeUp',
|
|
2646
|
-
'SwipeRight',
|
|
2647
|
-
'SwipeDown'
|
|
2648
|
-
]
|
|
2649
|
-
};
|
|
2650
|
-
|
|
2651
|
-
function event_controller(e, event_name, details_setter, customizer) {
|
|
2652
|
-
this.cache.currentEvent = event_name;
|
|
2653
|
-
this.cache.event = e;
|
|
2654
|
-
|
|
2655
|
-
details_setter?.call(this);
|
|
2656
|
-
if (customizer?.hasOwnProperty('prototype')) customizer?.call(this);
|
|
2657
|
-
else customizer?.call(null, this);
|
|
2658
|
-
|
|
2659
|
-
if (this.cache.preventDefault[event_name]) e.preventDefault();
|
|
2660
|
-
if (this.cache.stopPropagation[event_name]) e.stopPropagation();
|
|
2661
|
-
if (this.cache.stopImmediatePropagation[event_name]) e.stopImmediatePropagation();
|
|
2662
|
-
|
|
2663
|
-
// Call the single callback if it exists
|
|
2664
|
-
this.cache.callbacks[event_name]?.(this);
|
|
2665
|
-
}
|
|
2666
|
-
|
|
2667
|
-
function toggle_event_listener(method, ...events) {
|
|
2668
|
-
const keys = events.length === 0
|
|
2669
|
-
? Object.keys(this.cache.paused)
|
|
2670
|
-
: events;
|
|
2671
|
-
keys.forEach(key => {
|
|
2672
|
-
if (!this.cache.paused.hasOwnProperty(key)) return;
|
|
2673
|
-
this.targetElement?.[method](
|
|
2674
|
-
key,
|
|
2675
|
-
this.cache.__controllers__[key],
|
|
2676
|
-
this.cache.options[key]
|
|
2677
|
-
);
|
|
2678
|
-
this.cache.paused[key] = method === 'removeEventListener';
|
|
2679
|
-
});
|
|
2680
|
-
return this;
|
|
2681
2528
|
}
|
|
2682
|
-
const getEvent=(event = "")=>{
|
|
2683
|
-
if(event.startsWith("Ptr"))return `pointer${event.split("Ptr")[1].toLowerCase()}`;
|
|
2684
|
-
return event.toLowerCase()
|
|
2685
|
-
};
|
|
2686
|
-
|
|
2687
|
-
class ZikoEvent {
|
|
2688
|
-
constructor(signature, target = null, Events = [], details_setter, customizer){
|
|
2689
|
-
this.target = target;
|
|
2690
|
-
this.cache = {
|
|
2691
|
-
signature,
|
|
2692
|
-
currentEvent : null,
|
|
2693
|
-
event: null,
|
|
2694
|
-
options : {},
|
|
2695
|
-
preventDefault : {},
|
|
2696
|
-
stopPropagation : {},
|
|
2697
|
-
stopImmediatePropagation : {},
|
|
2698
|
-
paused : {},
|
|
2699
|
-
callbacks : {},
|
|
2700
|
-
__controllers__:{}
|
|
2701
|
-
};
|
|
2702
|
-
if (Events) this._register_events(Events, details_setter, customizer);
|
|
2703
|
-
}
|
|
2704
|
-
_register_events(Events, details_setter, customizer, REGISTER_METHODES = true) {
|
|
2705
|
-
const events = Events?.map(n => getEvent(n));
|
|
2706
|
-
events?.forEach((event, i) => {
|
|
2707
|
-
this.cache.preventDefault[event] = false;
|
|
2708
|
-
this.cache.options[event] = {};
|
|
2709
|
-
this.cache.paused[event] = false;
|
|
2710
|
-
this.cache.__controllers__[event] = (e) =>
|
|
2711
|
-
event_controller.call(this, e, event, details_setter, customizer);
|
|
2712
|
-
if (REGISTER_METHODES) {
|
|
2713
|
-
this[`on${Events[i]}`] = (callback) =>
|
|
2714
|
-
this.__onEvent(event, this.cache.options[event], {}, callback);
|
|
2715
|
-
}
|
|
2716
|
-
});
|
|
2717
|
-
return this;
|
|
2718
|
-
}
|
|
2719
|
-
__onEvent(event, options, dispose, callback) {
|
|
2720
|
-
if (!callback) return this;
|
|
2721
|
-
this.cache.callbacks[event] = callback;
|
|
2722
|
-
this.__handle(event, this.cache.__controllers__[event], options, dispose);
|
|
2723
|
-
return this;
|
|
2724
|
-
}
|
|
2725
|
-
get targetElement(){
|
|
2726
|
-
return this.target?.element;
|
|
2727
|
-
}
|
|
2728
|
-
get isParent(){
|
|
2729
|
-
return this.target?.element === this.event?.srcElement;
|
|
2730
|
-
}
|
|
2731
|
-
get item(){
|
|
2732
|
-
return this.target.find(n => n.element == this.event?.srcElement)?.[0];
|
|
2733
|
-
}
|
|
2734
|
-
get currentEvent(){
|
|
2735
|
-
return this.cache.currentEvent;
|
|
2736
|
-
}
|
|
2737
|
-
get event(){
|
|
2738
|
-
return this.cache.event;
|
|
2739
|
-
}
|
|
2740
|
-
get detail(){
|
|
2741
|
-
return this.cache.event.detail
|
|
2742
|
-
}
|
|
2743
|
-
setTarget(UI){
|
|
2744
|
-
this.target = UI;
|
|
2745
|
-
return this;
|
|
2746
|
-
}
|
|
2747
|
-
__handle(event, handler, options){
|
|
2748
|
-
this.targetElement?.addEventListener(event, handler, options);
|
|
2749
|
-
return this;
|
|
2750
|
-
}
|
|
2751
|
-
#override(method, ...events) {
|
|
2752
|
-
const keys = events.length === 0 ? Object.keys(this.cache[method]) : events;
|
|
2753
|
-
keys.forEach(e => {
|
|
2754
|
-
if (this.cache[method].hasOwnProperty(e)) this.cache[method][e] = true;
|
|
2755
|
-
});
|
|
2756
|
-
return this;
|
|
2757
|
-
}
|
|
2758
|
-
preventDefault(...events) {
|
|
2759
|
-
return this.#override('preventDefault', ...events);
|
|
2760
|
-
}
|
|
2761
|
-
stopPropagation(...events) {
|
|
2762
|
-
return this.#override('stopPropagation', ...events);
|
|
2763
|
-
}
|
|
2764
|
-
stopImmediatePropagation(...events) {
|
|
2765
|
-
return this.#override('stopImmediatePropagation', ...events);
|
|
2766
|
-
}
|
|
2767
|
-
setEventOptions(event, options){
|
|
2768
|
-
const evt = getEvent(event);
|
|
2769
|
-
this.pause();
|
|
2770
|
-
Object.assign(this.cache.options[evt], options);
|
|
2771
|
-
this.resume();
|
|
2772
|
-
return this;
|
|
2773
|
-
}
|
|
2774
|
-
pause(...events) {
|
|
2775
|
-
return toggle_event_listener.call(this, 'removeEventListener', ...events)
|
|
2776
|
-
}
|
|
2777
|
-
resume(...events) {
|
|
2778
|
-
return toggle_event_listener.call(this, 'addEventListener', ...events);
|
|
2779
|
-
}
|
|
2780
|
-
dispose(){
|
|
2781
|
-
this.pause();
|
|
2782
|
-
this.target.events[this.cache.signature] = null;
|
|
2783
|
-
return this;
|
|
2784
|
-
}
|
|
2785
|
-
}
|
|
2786
|
-
|
|
2787
|
-
function key_details_setter(){
|
|
2788
|
-
switch(this.currentEvent){
|
|
2789
|
-
case "keydown" : {
|
|
2790
|
-
this.kd = this.event.key;
|
|
2791
|
-
} break;
|
|
2792
|
-
case "keypress" : {
|
|
2793
|
-
this.kp = this.event.key;
|
|
2794
|
-
} break;
|
|
2795
|
-
case "keyup" : {
|
|
2796
|
-
this.ku = this.event.key;
|
|
2797
|
-
} break;
|
|
2798
|
-
|
|
2799
|
-
}
|
|
2800
|
-
}
|
|
2801
|
-
|
|
2802
|
-
function ptr_details_setter() {
|
|
2803
|
-
const rect = this.targetElement.getBoundingClientRect();
|
|
2804
|
-
const e = this.event;
|
|
2805
|
-
let x = (e.clientX - rect.left) | 0;
|
|
2806
|
-
let y = (e.clientY - rect.top) | 0;
|
|
2807
|
-
|
|
2808
|
-
if(this.cache.useNormalisedCoordinates){
|
|
2809
|
-
const w = this.targetElement.clientWidth;
|
|
2810
|
-
const h = this.targetElement.clientHeight;
|
|
2811
|
-
x = +((x / w) * 2 - 1).toFixed(8);
|
|
2812
|
-
y = +((y / h) * -2 + 1).toFixed(8);
|
|
2813
|
-
}
|
|
2814
|
-
switch (this.currentEvent) {
|
|
2815
|
-
|
|
2816
|
-
case "pointerdown":
|
|
2817
|
-
this.dx = x;
|
|
2818
|
-
this.dy = y;
|
|
2819
|
-
this.isDown = true;
|
|
2820
|
-
break;
|
|
2821
|
-
|
|
2822
|
-
case "pointermove":
|
|
2823
|
-
this.mx = x;
|
|
2824
|
-
this.my = y;
|
|
2825
|
-
this.isMoving = true;
|
|
2826
|
-
break;
|
|
2827
|
-
|
|
2828
|
-
case "pointerup":
|
|
2829
|
-
this.ux = x;
|
|
2830
|
-
this.uy = y;
|
|
2831
|
-
this.isDown = false;
|
|
2832
|
-
this.isMoving = false;
|
|
2833
|
-
break;
|
|
2834
|
-
}
|
|
2835
|
-
}
|
|
2836
|
-
|
|
2837
|
-
function mouse_details_setter() {
|
|
2838
|
-
const rect = this.targetElement.getBoundingClientRect();
|
|
2839
|
-
const e = this.event;
|
|
2840
|
-
let x = (e.clientX - rect.left) | 0;
|
|
2841
|
-
let y = (e.clientY - rect.top) | 0;
|
|
2842
|
-
|
|
2843
|
-
if(this.cache.useNormalisedCoordinates){
|
|
2844
|
-
const w = this.targetElement.clientWidth;
|
|
2845
|
-
const h = this.targetElement.clientHeight;
|
|
2846
|
-
x = +((x / w) * 2 - 1).toFixed(8);
|
|
2847
|
-
y = +((y / h) * -2 + 1).toFixed(8);
|
|
2848
|
-
}
|
|
2849
|
-
|
|
2850
|
-
switch (this.currentEvent) {
|
|
2851
|
-
|
|
2852
|
-
case "mousedown":
|
|
2853
|
-
this.dx = x;
|
|
2854
|
-
this.dy = y;
|
|
2855
|
-
this.isDown = true;
|
|
2856
|
-
break;
|
|
2857
2529
|
|
|
2858
|
-
case "mousemove":
|
|
2859
|
-
this.mx = x;
|
|
2860
|
-
this.my = y;
|
|
2861
|
-
this.isMoving = true;
|
|
2862
|
-
break;
|
|
2863
2530
|
|
|
2864
|
-
case "mouserup":
|
|
2865
|
-
this.ux = x;
|
|
2866
|
-
this.uy = y;
|
|
2867
|
-
this.isDown = false;
|
|
2868
|
-
this.isMoving = false;
|
|
2869
|
-
break;
|
|
2870
|
-
}
|
|
2871
|
-
}
|
|
2872
|
-
|
|
2873
|
-
function touch_details_setter() {
|
|
2874
|
-
const e = this.event;
|
|
2875
|
-
const touch = e.touches?.[0] || e.changedTouches?.[0];
|
|
2876
|
-
|
|
2877
|
-
if (!touch) return; // should never happen but safe
|
|
2878
|
-
|
|
2879
|
-
const rect = this.targetElement.getBoundingClientRect();
|
|
2880
|
-
let x = touch.clientX - rect.left;
|
|
2881
|
-
let y = touch.clientY - rect.top;
|
|
2882
|
-
|
|
2883
|
-
if(this.cache.useNormalisedCoordinates){
|
|
2884
|
-
const w = this.targetElement.clientWidth;
|
|
2885
|
-
const h = this.targetElement.clientHeight;
|
|
2886
|
-
x = +((x / w) * 2 - 1).toFixed(8);
|
|
2887
|
-
y = +((y / h) * -2 + 1).toFixed(8);
|
|
2888
|
-
}
|
|
2889
|
-
|
|
2890
|
-
switch (this.currentEvent) {
|
|
2891
|
-
case "touchstart":
|
|
2892
|
-
this.dx = x;
|
|
2893
|
-
this.dy = y;
|
|
2894
|
-
this.isDown = true;
|
|
2895
|
-
break;
|
|
2896
|
-
|
|
2897
|
-
case "touchmove":
|
|
2898
|
-
this.mx = x;
|
|
2899
|
-
this.my = y;
|
|
2900
|
-
this.isMoving = true;
|
|
2901
|
-
break;
|
|
2902
2531
|
|
|
2903
|
-
case "touchend":
|
|
2904
|
-
this.ux = x;
|
|
2905
|
-
this.uy = y;
|
|
2906
|
-
this.isDown = false;
|
|
2907
|
-
break;
|
|
2908
|
-
}
|
|
2909
|
-
}
|
|
2910
|
-
|
|
2911
|
-
class CoordinatesBasedEvent extends ZikoEvent{
|
|
2912
|
-
constructor(signature, target = null, Events = [], details_setter, customizer){
|
|
2913
|
-
super(signature, target, Events, details_setter, customizer);
|
|
2914
|
-
Object.assign(this.cache,{
|
|
2915
|
-
useNormalisedCoordinates : false
|
|
2916
|
-
});
|
|
2917
|
-
this.isDown = false;
|
|
2918
|
-
this.isMoving = false;
|
|
2919
|
-
this.dx = 0;
|
|
2920
|
-
this.dy = 0;
|
|
2921
|
-
this.mx = 0;
|
|
2922
|
-
this.my = 0;
|
|
2923
|
-
this.ux = 0;
|
|
2924
|
-
this.uy = 0;
|
|
2925
|
-
}
|
|
2926
|
-
get isDragging(){
|
|
2927
|
-
return this.isDown && this.isMoving
|
|
2928
|
-
}
|
|
2929
|
-
useNormalisedCoordinates(enable = true){
|
|
2930
|
-
this.cache.useNormalisedCoordinates = enable;
|
|
2931
|
-
return this;
|
|
2932
|
-
}
|
|
2933
|
-
}
|
|
2934
|
-
|
|
2935
|
-
class ClickAwayEvent extends Event {
|
|
2936
|
-
constructor(originalEvent, targetElement) {
|
|
2937
|
-
super("clickaway", { bubbles: true, cancelable: true });
|
|
2938
|
-
this.originalEvent = originalEvent;
|
|
2939
|
-
this.targetElement = targetElement;
|
|
2940
|
-
}
|
|
2941
|
-
}
|
|
2942
2532
|
|
|
2943
|
-
function
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
element.dispatchEvent(clickAwayEvent);
|
|
2948
|
-
}
|
|
2533
|
+
async function __addItem__(adder, pusher, ...ele) {
|
|
2534
|
+
if (this.cache.isFrozzen) {
|
|
2535
|
+
console.warn("You can't append new item to frozzen element");
|
|
2536
|
+
return this;
|
|
2949
2537
|
}
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
// console.log("Clicked outside box!", e);
|
|
2964
|
-
// });
|
|
2965
|
-
|
|
2966
|
-
// // later, you can stop listening:
|
|
2967
|
-
// // stop();
|
|
2968
|
-
|
|
2969
|
-
const debounce=(fn,delay=1000)=>{
|
|
2970
|
-
let id;
|
|
2971
|
-
return (...args) => id ? clearTimeout(id) : setTimeout(()=>fn(...args),delay);
|
|
2972
|
-
};
|
|
2973
|
-
const throttle=(fn,delay)=>{
|
|
2974
|
-
let lastTime=0;
|
|
2975
|
-
return (...args) => {
|
|
2976
|
-
const now = new Date().getTime();
|
|
2977
|
-
if(now-lastTime < delay) return;
|
|
2978
|
-
lastTime = now;
|
|
2979
|
-
fn(...args);
|
|
2980
|
-
}
|
|
2981
|
-
};
|
|
2982
|
-
|
|
2983
|
-
class ViewEvent extends CustomEvent {
|
|
2984
|
-
constructor(type, detail, { bubbles = true, cancelable = true } = {}) {
|
|
2985
|
-
super(type, { detail, bubbles, cancelable });
|
|
2986
|
-
}
|
|
2987
|
-
}
|
|
2988
|
-
|
|
2989
|
-
function register_view_event(
|
|
2990
|
-
element,
|
|
2991
|
-
{
|
|
2992
|
-
intersection = true,
|
|
2993
|
-
resize = true,
|
|
2994
|
-
threshold = 0,
|
|
2995
|
-
throttleResize = 100,
|
|
2996
|
-
throttleEnterExit = 0
|
|
2997
|
-
} = {}
|
|
2998
|
-
) {
|
|
2999
|
-
let intersectionObserver, resizeObserver;
|
|
3000
|
-
const resizeCallback = entries => {
|
|
3001
|
-
for (let entry of entries) {
|
|
3002
|
-
const { width, height } = entry.contentRect;
|
|
3003
|
-
|
|
3004
|
-
element.dispatchEvent(
|
|
3005
|
-
new ViewEvent("resizeview", {
|
|
3006
|
-
width,
|
|
3007
|
-
height,
|
|
3008
|
-
entry
|
|
3009
|
-
})
|
|
3010
|
-
);
|
|
3011
|
-
}
|
|
3012
|
-
};
|
|
3013
|
-
|
|
3014
|
-
const throttledResize = throttleResize > 0
|
|
3015
|
-
? throttle(resizeCallback, throttleResize)
|
|
3016
|
-
: resizeCallback;
|
|
3017
|
-
|
|
3018
|
-
const intersectionCallback = entries => {
|
|
3019
|
-
for (let entry of entries) {
|
|
3020
|
-
const type = entry.isIntersecting ? "enterview" : "exitview";
|
|
3021
|
-
element.dispatchEvent(new ViewEvent(type, entry));
|
|
3022
|
-
}
|
|
3023
|
-
};
|
|
3024
|
-
|
|
3025
|
-
const throttledIntersections = throttleEnterExit > 0
|
|
3026
|
-
? throttle(intersectionCallback, throttleEnterExit)
|
|
3027
|
-
: intersectionCallback;
|
|
3028
|
-
|
|
3029
|
-
if (intersection) {
|
|
3030
|
-
intersectionObserver = new IntersectionObserver(throttledIntersections, { threshold });
|
|
3031
|
-
intersectionObserver.observe(element);
|
|
2538
|
+
for (let i = 0; i < ele.length; i++) {
|
|
2539
|
+
if (["number", "string"].includes(typeof ele[i])) ele[i] = text(ele[i]);
|
|
2540
|
+
// Fix Items Latter
|
|
2541
|
+
if (ele[i] instanceof Function) {
|
|
2542
|
+
const getter = ele[i]();
|
|
2543
|
+
if (getter.isStateGetter) {
|
|
2544
|
+
ele[i] = text(getter.value);
|
|
2545
|
+
getter._subscribe(
|
|
2546
|
+
(newValue) => (ele[i].element.textContent = newValue),
|
|
2547
|
+
ele[i]
|
|
2548
|
+
);
|
|
2549
|
+
// this.element.appendChild(textNode);
|
|
2550
|
+
}
|
|
3032
2551
|
}
|
|
3033
|
-
|
|
3034
|
-
if (
|
|
3035
|
-
|
|
3036
|
-
|
|
2552
|
+
if (typeof globalThis?.Node === "function" && ele[i] instanceof globalThis?.Node) ele[i] = new this.constructor(ele[i]);
|
|
2553
|
+
if (ele[i]?.isUINode) {
|
|
2554
|
+
ele[i].cache.parent = this;
|
|
2555
|
+
this.element?.[adder](ele[i].element);
|
|
2556
|
+
ele[i].target = this.element;
|
|
2557
|
+
this.items[pusher](ele[i]);
|
|
2558
|
+
}
|
|
2559
|
+
else if(ele[i] instanceof Promise){
|
|
2560
|
+
const UIEle = await ele[i];
|
|
2561
|
+
UIEle.cache.parent = this;
|
|
2562
|
+
this.element?.[adder](UIEle.element);
|
|
2563
|
+
UIEle.target = this.element;
|
|
2564
|
+
this.items[pusher](UIEle);
|
|
3037
2565
|
}
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
}
|
|
3045
|
-
if (resizeObserver) {
|
|
3046
|
-
resizeObserver.unobserve(element);
|
|
3047
|
-
resizeObserver.disconnect();
|
|
3048
|
-
}
|
|
3049
|
-
};
|
|
3050
|
-
}
|
|
3051
|
-
|
|
3052
|
-
class SwipeEvent extends CustomEvent {
|
|
3053
|
-
constructor(type, detail) {
|
|
3054
|
-
super(type, {
|
|
3055
|
-
detail,
|
|
3056
|
-
bubbles: true,
|
|
3057
|
-
cancelable: true
|
|
3058
|
-
});
|
|
3059
|
-
}
|
|
3060
|
-
}
|
|
3061
|
-
|
|
3062
|
-
function register_swipe_event(
|
|
3063
|
-
element,
|
|
3064
|
-
threshold = 50,
|
|
3065
|
-
restraint = 100,
|
|
3066
|
-
allowedTime = 500
|
|
3067
|
-
) {
|
|
3068
|
-
let startX = 0,
|
|
3069
|
-
startY = 0,
|
|
3070
|
-
startTime = 0,
|
|
3071
|
-
isPointerDown = false;
|
|
3072
|
-
|
|
3073
|
-
function onPointerDown(e) {
|
|
3074
|
-
startX = e.clientX;
|
|
3075
|
-
startY = e.clientY;
|
|
3076
|
-
startTime = performance.now();
|
|
3077
|
-
isPointerDown = true;
|
|
3078
|
-
}
|
|
3079
|
-
|
|
3080
|
-
function onPointerUp(e) {
|
|
3081
|
-
if (!isPointerDown) return;
|
|
3082
|
-
isPointerDown = false;
|
|
3083
|
-
|
|
3084
|
-
const distX = e.clientX - startX;
|
|
3085
|
-
const distY = e.clientY - startY;
|
|
3086
|
-
const elapsed = performance.now() - startTime;
|
|
3087
|
-
|
|
3088
|
-
let direction = null;
|
|
3089
|
-
let eventName = null;
|
|
3090
|
-
|
|
3091
|
-
if (elapsed <= allowedTime) {
|
|
3092
|
-
if (Math.abs(distX) >= threshold && Math.abs(distY) <= restraint) {
|
|
3093
|
-
direction = distX < 0 ? "left" : "right";
|
|
3094
|
-
eventName = "swipe" + direction;
|
|
3095
|
-
}
|
|
3096
|
-
else if (Math.abs(distY) >= threshold && Math.abs(distX) <= restraint) {
|
|
3097
|
-
direction = distY < 0 ? "up" : "down";
|
|
3098
|
-
eventName = "swipe" + direction;
|
|
2566
|
+
else if (ele[i] instanceof Object) {
|
|
2567
|
+
if (ele[i]?.style) this.style(ele[i]?.style);
|
|
2568
|
+
if (ele[i]?.attr) {
|
|
2569
|
+
Object.entries(ele[i].attr).forEach((n) =>
|
|
2570
|
+
this.setAttr("" + n[0], n[1]),
|
|
2571
|
+
);
|
|
3099
2572
|
}
|
|
3100
2573
|
}
|
|
3101
|
-
|
|
3102
|
-
// Emit event
|
|
3103
|
-
if (eventName) {
|
|
3104
|
-
element.dispatchEvent(
|
|
3105
|
-
new SwipeEvent(eventName, {
|
|
3106
|
-
direction,
|
|
3107
|
-
distX,
|
|
3108
|
-
distY,
|
|
3109
|
-
originalEvent: e
|
|
3110
|
-
})
|
|
3111
|
-
);
|
|
3112
|
-
}
|
|
3113
2574
|
}
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
element.addEventListener("pointerup", onPointerUp, { passive: true });
|
|
3117
|
-
|
|
3118
|
-
return () => {
|
|
3119
|
-
element.removeEventListener("pointerdown", onPointerDown);
|
|
3120
|
-
element.removeEventListener("pointerup", onPointerUp);
|
|
3121
|
-
};
|
|
2575
|
+
this.maintain();
|
|
2576
|
+
return this;
|
|
3122
2577
|
}
|
|
3123
2578
|
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
'clipboard',
|
|
3136
|
-
target,
|
|
3137
|
-
EventsMap.Clipboard,
|
|
3138
|
-
null,
|
|
3139
|
-
customizer
|
|
3140
|
-
);
|
|
3141
|
-
const bind_drag_event = (target, customizer) => new ZikoEvent(
|
|
3142
|
-
'drag',
|
|
3143
|
-
target,
|
|
3144
|
-
EventsMap.Drag,
|
|
3145
|
-
null,
|
|
3146
|
-
customizer
|
|
3147
|
-
);
|
|
3148
|
-
const bind_focus_event = (target, customizer) => new ZikoEvent(
|
|
3149
|
-
'focus',
|
|
3150
|
-
target,
|
|
3151
|
-
EventsMap.Focus,
|
|
3152
|
-
null,
|
|
3153
|
-
customizer
|
|
3154
|
-
);
|
|
3155
|
-
const bind_key_event = (target, customizer) => new ZikoEvent(
|
|
3156
|
-
'key',
|
|
3157
|
-
target,
|
|
3158
|
-
EventsMap.Key,
|
|
3159
|
-
key_details_setter,
|
|
3160
|
-
customizer
|
|
3161
|
-
);
|
|
3162
|
-
const bind_mouse_event = (target, customizer) => new CoordinatesBasedEvent(
|
|
3163
|
-
'mouse',
|
|
3164
|
-
target,
|
|
3165
|
-
EventsMap.Mouse,
|
|
3166
|
-
mouse_details_setter,
|
|
3167
|
-
customizer
|
|
3168
|
-
);
|
|
3169
|
-
const bind_pointer_event = (target, customizer) => new CoordinatesBasedEvent(
|
|
3170
|
-
'ptr',
|
|
3171
|
-
target,
|
|
3172
|
-
EventsMap.Ptr,
|
|
3173
|
-
ptr_details_setter,
|
|
3174
|
-
customizer
|
|
3175
|
-
);
|
|
3176
|
-
const bind_touch_event = (target, customizer) => new CoordinatesBasedEvent(
|
|
3177
|
-
'touch',
|
|
3178
|
-
target,
|
|
3179
|
-
EventsMap.Touch,
|
|
3180
|
-
touch_details_setter,
|
|
3181
|
-
customizer
|
|
3182
|
-
);
|
|
3183
|
-
const bind_wheel_event = (target, customizer) => new ZikoEvent(
|
|
3184
|
-
'wheel',
|
|
3185
|
-
target,
|
|
3186
|
-
EventsMap.Wheel,
|
|
3187
|
-
null,
|
|
3188
|
-
customizer
|
|
3189
|
-
);
|
|
3190
|
-
|
|
3191
|
-
const bind_view_event = (target, customizer) => {
|
|
3192
|
-
register_view_event(target.element);
|
|
3193
|
-
return new ZikoEvent(
|
|
3194
|
-
'view',
|
|
3195
|
-
target,
|
|
3196
|
-
EventsMap.View,
|
|
3197
|
-
null,
|
|
3198
|
-
customizer
|
|
3199
|
-
)
|
|
3200
|
-
};
|
|
3201
|
-
|
|
3202
|
-
const bind_swipe_event = (target, customizer) => {
|
|
3203
|
-
register_swipe_event(target.element);
|
|
3204
|
-
return new ZikoEvent(
|
|
3205
|
-
'swipe',
|
|
3206
|
-
target,
|
|
3207
|
-
EventsMap.Swipe,
|
|
3208
|
-
null,
|
|
3209
|
-
customizer
|
|
3210
|
-
)
|
|
3211
|
-
};
|
|
3212
|
-
|
|
3213
|
-
class ZikoCustomEvent extends ZikoEvent{
|
|
3214
|
-
constructor(target, events, customizer){
|
|
3215
|
-
super('custom', target, events, details_setter, customizer);
|
|
3216
|
-
}
|
|
3217
|
-
_register_events(events){
|
|
3218
|
-
super._register_events(events, null, null, false);
|
|
3219
|
-
return this;
|
|
3220
|
-
}
|
|
3221
|
-
emit(event_name, detail = {}){
|
|
3222
|
-
const event = new CustomEvent(event_name, {
|
|
3223
|
-
detail,
|
|
3224
|
-
bubbles: true,
|
|
3225
|
-
cancelable: true
|
|
3226
|
-
});
|
|
3227
|
-
this.targetElement.dispatchEvent(event);
|
|
3228
|
-
return this;
|
|
3229
|
-
}
|
|
3230
|
-
on(event_name, ...callbacks){
|
|
3231
|
-
if(!this.cache.options.hasOwnProperty(event_name)) this._register_events([event_name]);
|
|
3232
|
-
this.__onEvent(event_name, this.cache.options[event_name], {}, ...callbacks);
|
|
3233
|
-
return this;
|
|
3234
|
-
}
|
|
3235
|
-
}
|
|
3236
|
-
function details_setter(){
|
|
3237
|
-
|
|
3238
|
-
}
|
|
3239
|
-
const bind_custom_event = (target, events, customizer) => new ZikoCustomEvent(target, events, customizer);
|
|
3240
|
-
|
|
3241
|
-
const binderMap = {
|
|
3242
|
-
ptr: bind_pointer_event,
|
|
3243
|
-
mouse : bind_mouse_event,
|
|
3244
|
-
key: bind_key_event,
|
|
3245
|
-
click : bind_click_event,
|
|
3246
|
-
drag : bind_drag_event,
|
|
3247
|
-
clipboard : bind_clipboard_event,
|
|
3248
|
-
focus : bind_focus_event,
|
|
3249
|
-
wheel : bind_wheel_event,
|
|
3250
|
-
view : bind_view_event,
|
|
3251
|
-
swipe : bind_swipe_event
|
|
3252
|
-
};
|
|
3253
|
-
|
|
3254
|
-
const EventsMethodes = {
|
|
3255
|
-
on(event_name,...callbacks){
|
|
3256
|
-
if(!this.events.custom)this.events.custom = bind_custom_event(this);
|
|
3257
|
-
this.events.custom.on(event_name,...callbacks);
|
|
3258
|
-
return this;
|
|
3259
|
-
},
|
|
3260
|
-
emit(event_name,detail={}){
|
|
3261
|
-
if(!this.events.custom)this.events.custom = bind_custom_event(this);
|
|
3262
|
-
this.events.custom.emit(event_name,detail);
|
|
3263
|
-
return this;
|
|
3264
|
-
}
|
|
3265
|
-
};
|
|
3266
|
-
|
|
3267
|
-
Object.entries(EventsMap).forEach(([name, eventList]) => {
|
|
3268
|
-
const lname = name.toLowerCase();
|
|
3269
|
-
eventList.forEach(event => {
|
|
3270
|
-
const methodName = `on${event}`;
|
|
3271
|
-
EventsMethodes[methodName] = function (callbacks) {
|
|
3272
|
-
if (!this.events[lname]) this.events[lname] = binderMap[lname](this);
|
|
3273
|
-
this.events[lname][methodName](callbacks);
|
|
3274
|
-
return this;
|
|
3275
|
-
};
|
|
3276
|
-
});
|
|
2579
|
+
var DomMethods = /*#__PURE__*/Object.freeze({
|
|
2580
|
+
__proto__: null,
|
|
2581
|
+
__addItem__: __addItem__,
|
|
2582
|
+
after: after,
|
|
2583
|
+
append: append,
|
|
2584
|
+
before: before,
|
|
2585
|
+
clear: clear,
|
|
2586
|
+
insertAt: insertAt,
|
|
2587
|
+
prepend: prepend,
|
|
2588
|
+
remove: remove,
|
|
2589
|
+
replaceElementWith: replaceElementWith
|
|
3277
2590
|
});
|
|
3278
2591
|
|
|
3279
2592
|
function at(index) {
|
|
@@ -3340,44 +2653,195 @@
|
|
|
3340
2653
|
style: style$1
|
|
3341
2654
|
});
|
|
3342
2655
|
|
|
2656
|
+
class ClickAwayEvent extends Event {
|
|
2657
|
+
constructor(originalEvent, targetElement) {
|
|
2658
|
+
super("clickaway", { bubbles: true, cancelable: true });
|
|
2659
|
+
this.originalEvent = originalEvent;
|
|
2660
|
+
this.targetElement = targetElement;
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2664
|
+
function register_click_away_event(element) {
|
|
2665
|
+
// console.log(element)
|
|
2666
|
+
function handler(e) {
|
|
2667
|
+
if (!element.contains(e.target)) {
|
|
2668
|
+
const clickAwayEvent = new ClickAwayEvent(e, element);
|
|
2669
|
+
element.dispatchEvent(clickAwayEvent);
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
|
|
2673
|
+
globalThis?.document?.addEventListener("click", handler);
|
|
2674
|
+
|
|
2675
|
+
return () => globalThis?.document?.removeEventListener("click", handler);
|
|
2676
|
+
|
|
2677
|
+
}
|
|
2678
|
+
|
|
2679
|
+
// // Example usage
|
|
2680
|
+
// const box = document.querySelector("#my-box");
|
|
2681
|
+
|
|
2682
|
+
// const stop = listenClickAway(box);
|
|
2683
|
+
|
|
2684
|
+
// box.addEventListener("clickaway", (e) => {
|
|
2685
|
+
// console.log("Clicked outside box!", e);
|
|
2686
|
+
// });
|
|
2687
|
+
|
|
2688
|
+
// // later, you can stop listening:
|
|
2689
|
+
// // stop();
|
|
2690
|
+
|
|
2691
|
+
const CATEGORY$2 = 'click';
|
|
2692
|
+
const ClickListeners = {
|
|
2693
|
+
onClick(callback){
|
|
2694
|
+
this._on(
|
|
2695
|
+
'click', callback,
|
|
2696
|
+
{ category : CATEGORY$2 });
|
|
2697
|
+
},
|
|
2698
|
+
onDblClick(callback){
|
|
2699
|
+
this._on(
|
|
2700
|
+
'dblclick', callback,
|
|
2701
|
+
{ category : CATEGORY$2});
|
|
2702
|
+
},
|
|
2703
|
+
onClickAway(callback){
|
|
2704
|
+
register_click_away_event(this.element);
|
|
2705
|
+
this._on(
|
|
2706
|
+
'clickaway', callback,
|
|
2707
|
+
{ category : CATEGORY$2});
|
|
2708
|
+
},
|
|
2709
|
+
};
|
|
2710
|
+
|
|
2711
|
+
const getCoordinates = (ctx, normalized = false) =>{
|
|
2712
|
+
const rect = ctx.element.getBoundingClientRect();
|
|
2713
|
+
const e = ctx.event;
|
|
2714
|
+
let x = (e?.clientX - rect.left) | 0;
|
|
2715
|
+
let y = (e?.clientY - rect.top) | 0;
|
|
2716
|
+
|
|
2717
|
+
if(normalized){
|
|
2718
|
+
const w = ctx.element.clientWidth;
|
|
2719
|
+
const h = ctx.element.clientHeight;
|
|
2720
|
+
x = +((x / w) * 2 - 1).toFixed(8);
|
|
2721
|
+
y = +((y / h) * -2 + 1).toFixed(8);
|
|
2722
|
+
}
|
|
2723
|
+
|
|
2724
|
+
return {x, y};
|
|
2725
|
+
};
|
|
2726
|
+
|
|
2727
|
+
const CATEGORY$1 = 'ptr';
|
|
2728
|
+
const PtrListeners = {
|
|
2729
|
+
onPtrDown(callback, useNormalizedCoordinates = false){
|
|
2730
|
+
this._on(
|
|
2731
|
+
'pointerdown', callback,
|
|
2732
|
+
{ category : CATEGORY$1, details_setter : (ctx)=> {
|
|
2733
|
+
const {x, y} = getCoordinates(ctx, useNormalizedCoordinates);
|
|
2734
|
+
ctx.dx = x;
|
|
2735
|
+
ctx.dy = y;
|
|
2736
|
+
ctx.isDown = true;
|
|
2737
|
+
ctx.isDragging = ctx.isMoving ?? false;
|
|
2738
|
+
}}
|
|
2739
|
+
);
|
|
2740
|
+
},
|
|
2741
|
+
onPtrMove(callback, useNormalizedCoordinates = false){
|
|
2742
|
+
this._on(
|
|
2743
|
+
'pointermove', callback,
|
|
2744
|
+
{ category : CATEGORY$1, details_setter : (ctx)=> {
|
|
2745
|
+
const {x, y} = getCoordinates(ctx, useNormalizedCoordinates);
|
|
2746
|
+
ctx.mx = x;
|
|
2747
|
+
ctx.my = y;
|
|
2748
|
+
ctx.isMoving = true;
|
|
2749
|
+
ctx.isDragging = ctx.isDown ?? false;
|
|
2750
|
+
}}
|
|
2751
|
+
);
|
|
2752
|
+
},
|
|
2753
|
+
onPtrUp(callback, useNormalizedCoordinates = false){
|
|
2754
|
+
this._on(
|
|
2755
|
+
'pointerup', callback,
|
|
2756
|
+
{ category : CATEGORY$1, details_setter : (ctx)=> {
|
|
2757
|
+
const {x, y} = getCoordinates(ctx, useNormalizedCoordinates);
|
|
2758
|
+
ctx.ux = x;
|
|
2759
|
+
ctx.uy = y;
|
|
2760
|
+
ctx.isDown = false;
|
|
2761
|
+
ctx.isMoving = false;
|
|
2762
|
+
ctx.isDragging = false;
|
|
2763
|
+
}}
|
|
2764
|
+
);
|
|
2765
|
+
}
|
|
2766
|
+
};
|
|
2767
|
+
|
|
2768
|
+
const CATEGORY = 'key';
|
|
2769
|
+
const KeyListeners = {
|
|
2770
|
+
onKeyDown(callback){
|
|
2771
|
+
this._on(
|
|
2772
|
+
'keydown', callback,
|
|
2773
|
+
{ category : CATEGORY, details_setter : ctx=> { ctx.kd = ctx.event.key; }
|
|
2774
|
+
});
|
|
2775
|
+
},
|
|
2776
|
+
onKeyPress(callback){
|
|
2777
|
+
this._on(
|
|
2778
|
+
'keypress', callback,
|
|
2779
|
+
{ category : CATEGORY, details_setter : ctx=> { ctx.kp = ctx.event.key; }
|
|
2780
|
+
});
|
|
2781
|
+
},
|
|
2782
|
+
onKeyUp(callback){
|
|
2783
|
+
this._on(
|
|
2784
|
+
'keydown', callback,
|
|
2785
|
+
{ category : CATEGORY, details_setter : ctx=> { ctx.ku = ctx.event.key; }
|
|
2786
|
+
});
|
|
2787
|
+
},
|
|
2788
|
+
|
|
2789
|
+
};
|
|
2790
|
+
|
|
3343
2791
|
class EventController {
|
|
3344
2792
|
constructor(target, category){
|
|
3345
2793
|
this.cache = {
|
|
3346
2794
|
category,
|
|
3347
2795
|
target,
|
|
3348
2796
|
listeners : {},
|
|
3349
|
-
currentEvent : null
|
|
2797
|
+
currentEvent : null,
|
|
2798
|
+
event : null
|
|
3350
2799
|
};
|
|
3351
2800
|
}
|
|
2801
|
+
get event(){
|
|
2802
|
+
return this.cache.event
|
|
2803
|
+
}
|
|
3352
2804
|
get element(){
|
|
3353
2805
|
return this.cache.target.element;
|
|
3354
2806
|
}
|
|
3355
2807
|
get currentEvent(){
|
|
3356
2808
|
return this.cache.currentEvent;
|
|
3357
2809
|
}
|
|
3358
|
-
addListener(
|
|
3359
|
-
this.cache.listeners[
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
if(
|
|
3363
|
-
|
|
2810
|
+
addListener(event_name, callback, {preventDefault = false, paused = false} = {}){
|
|
2811
|
+
this.cache.listeners[event_name] = {
|
|
2812
|
+
callback : e =>{
|
|
2813
|
+
this.cache.event = e;
|
|
2814
|
+
if(this.cache.listeners[event_name].preventDefault) e.preventDefault();
|
|
2815
|
+
if(!this.cache.listeners[event_name].paused) {
|
|
2816
|
+
this.cache.currentEvent = event_name;
|
|
3364
2817
|
callback.call(this, this);
|
|
3365
2818
|
}
|
|
3366
2819
|
},
|
|
2820
|
+
preventDefault,
|
|
2821
|
+
paused,
|
|
3367
2822
|
};
|
|
3368
|
-
this.element.addEventListener(
|
|
2823
|
+
this.element.addEventListener(event_name, this.cache.listeners[event_name].callback);
|
|
2824
|
+
return this;
|
|
2825
|
+
}
|
|
2826
|
+
removeListener(event_name){
|
|
2827
|
+
this.element.removeEventListener(event_name, this.cache.listeners[event_name].callback);
|
|
3369
2828
|
return this;
|
|
3370
2829
|
}
|
|
3371
|
-
|
|
3372
|
-
this.
|
|
2830
|
+
pause(event_name){
|
|
2831
|
+
this.cache.listeners[event_name].paused = true;
|
|
3373
2832
|
return this;
|
|
3374
2833
|
}
|
|
3375
|
-
|
|
3376
|
-
this.cache.listeners[
|
|
2834
|
+
resume(event_name){
|
|
2835
|
+
this.cache.listeners[event_name].paused = false;
|
|
3377
2836
|
return this;
|
|
3378
2837
|
}
|
|
3379
|
-
|
|
3380
|
-
|
|
2838
|
+
preventDefault(event_name){
|
|
2839
|
+
// if(!event_name)
|
|
2840
|
+
this.cache.listeners[event_name].preventDefault = true;
|
|
2841
|
+
return this;
|
|
2842
|
+
}
|
|
2843
|
+
useDefault(event_name){
|
|
2844
|
+
this.cache.listeners[event_name].preventDefault = false;
|
|
3381
2845
|
return this;
|
|
3382
2846
|
}
|
|
3383
2847
|
}
|
|
@@ -3397,16 +2861,23 @@
|
|
|
3397
2861
|
DomMethods,
|
|
3398
2862
|
StyleMethods,
|
|
3399
2863
|
IndexingMethods,
|
|
3400
|
-
|
|
2864
|
+
PtrListeners,
|
|
2865
|
+
ClickListeners,
|
|
2866
|
+
KeyListeners
|
|
3401
2867
|
);
|
|
3402
2868
|
|
|
3403
2869
|
if(element)this.init(element, name, type, render);
|
|
3404
2870
|
}
|
|
3405
|
-
_on(event, callback, {details_setter, category = 'global'} = {}){
|
|
2871
|
+
_on(event, callback, {details_setter, category = 'global', preventDefault = false} = {}){
|
|
3406
2872
|
if(category && !this.exp.events.hasOwnProperty(category)) this.exp.events[category] = new EventController(this, category);
|
|
3407
2873
|
const EVENT = this.exp.events[category];
|
|
3408
|
-
EVENT.addListener(event,
|
|
3409
|
-
|
|
2874
|
+
EVENT.addListener(event, (e)=>{
|
|
2875
|
+
if(details_setter) details_setter(EVENT);
|
|
2876
|
+
callback(e);
|
|
2877
|
+
},{
|
|
2878
|
+
preventDefault
|
|
2879
|
+
});
|
|
2880
|
+
|
|
3410
2881
|
}
|
|
3411
2882
|
_off(event, category = 'global'){
|
|
3412
2883
|
this.exp.events[category].removeListener(event);
|
|
@@ -4394,6 +3865,20 @@
|
|
|
4394
3865
|
|
|
4395
3866
|
const step_fps = (step_or_fps) => 1000 / step_or_fps;
|
|
4396
3867
|
|
|
3868
|
+
const debounce=(fn,delay=1000)=>{
|
|
3869
|
+
let id;
|
|
3870
|
+
return (...args) => id ? clearTimeout(id) : setTimeout(()=>fn(...args),delay);
|
|
3871
|
+
};
|
|
3872
|
+
const throttle=(fn,delay)=>{
|
|
3873
|
+
let lastTime=0;
|
|
3874
|
+
return (...args) => {
|
|
3875
|
+
const now = new Date().getTime();
|
|
3876
|
+
if(now-lastTime < delay) return;
|
|
3877
|
+
lastTime = now;
|
|
3878
|
+
fn(...args);
|
|
3879
|
+
}
|
|
3880
|
+
};
|
|
3881
|
+
|
|
4397
3882
|
const sleep= ms => new Promise(res => setTimeout(res, ms));
|
|
4398
3883
|
function timeout(ms, fn) {
|
|
4399
3884
|
let id;
|
|
@@ -5416,6 +4901,7 @@
|
|
|
5416
4901
|
exports.Complex = Complex;
|
|
5417
4902
|
exports.E = E;
|
|
5418
4903
|
exports.EPSILON = EPSILON;
|
|
4904
|
+
exports.EventController = EventController;
|
|
5419
4905
|
exports.FileBasedRouting = FileBasedRouting;
|
|
5420
4906
|
exports.Flex = Flex;
|
|
5421
4907
|
exports.HTMLWrapper = HTMLWrapper;
|
|
@@ -5443,7 +4929,6 @@
|
|
|
5443
4929
|
exports.Utils = Utils;
|
|
5444
4930
|
exports.View = View;
|
|
5445
4931
|
exports.ZikoApp = ZikoApp;
|
|
5446
|
-
exports.ZikoEvent = ZikoEvent;
|
|
5447
4932
|
exports.ZikoSPA = ZikoSPA;
|
|
5448
4933
|
exports.ZikoUISuspense = ZikoUISuspense;
|
|
5449
4934
|
exports.ZikoUIText = ZikoUIText;
|
|
@@ -5468,17 +4953,6 @@
|
|
|
5468
4953
|
exports.atan2 = atan2;
|
|
5469
4954
|
exports.atanh = atanh;
|
|
5470
4955
|
exports.back = back;
|
|
5471
|
-
exports.bind_click_event = bind_click_event;
|
|
5472
|
-
exports.bind_clipboard_event = bind_clipboard_event;
|
|
5473
|
-
exports.bind_drag_event = bind_drag_event;
|
|
5474
|
-
exports.bind_focus_event = bind_focus_event;
|
|
5475
|
-
exports.bind_key_event = bind_key_event;
|
|
5476
|
-
exports.bind_mouse_event = bind_mouse_event;
|
|
5477
|
-
exports.bind_pointer_event = bind_pointer_event;
|
|
5478
|
-
exports.bind_swipe_event = bind_swipe_event;
|
|
5479
|
-
exports.bind_touch_event = bind_touch_event;
|
|
5480
|
-
exports.bind_view_event = bind_view_event;
|
|
5481
|
-
exports.bind_wheel_event = bind_wheel_event;
|
|
5482
4956
|
exports.binomial = binomial;
|
|
5483
4957
|
exports.call_with_optional_props = call_with_optional_props;
|
|
5484
4958
|
exports.cartesianProduct = cartesianProduct;
|
|
@@ -5504,12 +4978,10 @@
|
|
|
5504
4978
|
exports.discret = discret;
|
|
5505
4979
|
exports.div = div;
|
|
5506
4980
|
exports.elastic = elastic;
|
|
5507
|
-
exports.event_controller = event_controller;
|
|
5508
4981
|
exports.exp = exp$1;
|
|
5509
4982
|
exports.floor = floor;
|
|
5510
4983
|
exports.fract = fract;
|
|
5511
4984
|
exports.geomspace = geomspace;
|
|
5512
|
-
exports.getEvent = getEvent;
|
|
5513
4985
|
exports.hypot = hypot;
|
|
5514
4986
|
exports.inRange = inRange;
|
|
5515
4987
|
exports.in_back = in_back;
|
|
@@ -5614,7 +5086,6 @@
|
|
|
5614
5086
|
exports.timeTaken = timeTaken;
|
|
5615
5087
|
exports.time_memory_Taken = time_memory_Taken;
|
|
5616
5088
|
exports.timeout = timeout;
|
|
5617
|
-
exports.toggle_event_listener = toggle_event_listener;
|
|
5618
5089
|
exports.trunc = trunc;
|
|
5619
5090
|
exports.useDerived = useDerived;
|
|
5620
5091
|
exports.useEventEmitter = useEventEmitter;
|