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