ziko 0.68.0 → 0.68.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ziko.cjs +291 -110
- package/dist/ziko.js +291 -110
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +282 -111
- package/package.json +1 -1
- package/src/events/controller/index.js +5 -1
- package/src/events/custom-events-registry/swipe.js +1 -1
- package/src/events/index.js +3 -1
- package/src/events/mixins/click.js +23 -0
- package/src/events/mixins/index.js +5 -0
- package/src/{ui/constructors/mixins/events → events/mixins}/key.js +3 -3
- package/src/{ui/constructors/mixins/events → events/mixins}/ptr.js +3 -3
- package/src/events/mixins/swipe.js +30 -0
- package/src/{ui/constructors/mixins/events → events/mixins}/utils/index.js +3 -1
- package/src/events/mixins/view.js +24 -0
- package/src/ui/constructors/UIElement.js +13 -11
- package/src/ui/constructors/mixins/index.js +0 -3
- package/src/events/details-setter/index.js +0 -4
- package/src/events/details-setter/key.js +0 -14
- package/src/events/details-setter/mouse.js +0 -35
- package/src/events/details-setter/pointer.js +0 -35
- package/src/events/details-setter/touch.js +0 -37
- package/src/ui/constructors/mixins/events/click.js +0 -22
- package/src/ui/constructors/mixins/events/index.js +0 -3
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 : Thu Feb 26 2026 13:06:11 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
|
|
@@ -2647,6 +2647,68 @@ var StyleMethods = /*#__PURE__*/Object.freeze({
|
|
|
2647
2647
|
style: style$1
|
|
2648
2648
|
});
|
|
2649
2649
|
|
|
2650
|
+
class EventController {
|
|
2651
|
+
constructor(target, category){
|
|
2652
|
+
this.cache = {
|
|
2653
|
+
category,
|
|
2654
|
+
target,
|
|
2655
|
+
listeners : {},
|
|
2656
|
+
currentEvent : null,
|
|
2657
|
+
event : null,
|
|
2658
|
+
customEvents : new Set()
|
|
2659
|
+
};
|
|
2660
|
+
}
|
|
2661
|
+
get event(){
|
|
2662
|
+
return this.cache.event
|
|
2663
|
+
}
|
|
2664
|
+
get target(){
|
|
2665
|
+
return this.cache.target;
|
|
2666
|
+
}
|
|
2667
|
+
get element(){
|
|
2668
|
+
return this.cache.target.element;
|
|
2669
|
+
}
|
|
2670
|
+
get currentEvent(){
|
|
2671
|
+
return this.cache.currentEvent;
|
|
2672
|
+
}
|
|
2673
|
+
addListener(event_name, callback, {preventDefault = false, paused = false} = {}){
|
|
2674
|
+
this.cache.listeners[event_name] = {
|
|
2675
|
+
callback : e =>{
|
|
2676
|
+
this.cache.event = e;
|
|
2677
|
+
if(this.cache.listeners[event_name].preventDefault) e.preventDefault();
|
|
2678
|
+
if(!this.cache.listeners[event_name].paused) {
|
|
2679
|
+
this.cache.currentEvent = event_name;
|
|
2680
|
+
callback.call(this, this);
|
|
2681
|
+
}
|
|
2682
|
+
},
|
|
2683
|
+
preventDefault,
|
|
2684
|
+
paused,
|
|
2685
|
+
};
|
|
2686
|
+
this.element.addEventListener(event_name, this.cache.listeners[event_name].callback);
|
|
2687
|
+
return this;
|
|
2688
|
+
}
|
|
2689
|
+
removeListener(event_name){
|
|
2690
|
+
this.element.removeEventListener(event_name, this.cache.listeners[event_name].callback);
|
|
2691
|
+
return this;
|
|
2692
|
+
}
|
|
2693
|
+
pause(event_name){
|
|
2694
|
+
this.cache.listeners[event_name].paused = true;
|
|
2695
|
+
return this;
|
|
2696
|
+
}
|
|
2697
|
+
resume(event_name){
|
|
2698
|
+
this.cache.listeners[event_name].paused = false;
|
|
2699
|
+
return this;
|
|
2700
|
+
}
|
|
2701
|
+
preventDefault(event_name){
|
|
2702
|
+
// if(!event_name)
|
|
2703
|
+
this.cache.listeners[event_name].preventDefault = true;
|
|
2704
|
+
return this;
|
|
2705
|
+
}
|
|
2706
|
+
useDefault(event_name){
|
|
2707
|
+
this.cache.listeners[event_name].preventDefault = false;
|
|
2708
|
+
return this;
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
|
|
2650
2712
|
class ClickAwayEvent extends Event {
|
|
2651
2713
|
constructor(originalEvent, targetElement) {
|
|
2652
2714
|
super("clickaway", { bubbles: true, cancelable: true });
|
|
@@ -2682,26 +2744,6 @@ function register_click_away_event(element) {
|
|
|
2682
2744
|
// // later, you can stop listening:
|
|
2683
2745
|
// // stop();
|
|
2684
2746
|
|
|
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
2747
|
const getCoordinates = (ctx, normalized = false) =>{
|
|
2706
2748
|
const rect = ctx.element.getBoundingClientRect();
|
|
2707
2749
|
const e = ctx.event;
|
|
@@ -2716,38 +2758,60 @@ const getCoordinates = (ctx, normalized = false) =>{
|
|
|
2716
2758
|
}
|
|
2717
2759
|
|
|
2718
2760
|
return {x, y};
|
|
2761
|
+
};
|
|
2762
|
+
|
|
2763
|
+
const isCustomEventRegistred = (ctx, category, event_name) => ctx.exp.events?.[category]?.cache?.customEvents?.has(event_name);
|
|
2764
|
+
|
|
2765
|
+
const CATEGORY$3 = 'click';
|
|
2766
|
+
const ClickListeners = {
|
|
2767
|
+
onClick(callback){
|
|
2768
|
+
return this.on(
|
|
2769
|
+
'click', callback,
|
|
2770
|
+
{ category : CATEGORY$3 })
|
|
2771
|
+
},
|
|
2772
|
+
onDblClick(callback){
|
|
2773
|
+
return this.on(
|
|
2774
|
+
'dblclick', callback,
|
|
2775
|
+
{ category : CATEGORY$3})
|
|
2776
|
+
},
|
|
2777
|
+
onClickAway(callback){
|
|
2778
|
+
if(!isCustomEventRegistred(this, CATEGORY$3, 'clickaway')) register_click_away_event(this.element);
|
|
2779
|
+
return this.on(
|
|
2780
|
+
'clickaway', callback,
|
|
2781
|
+
{ category : CATEGORY$3, isCustom : true})
|
|
2782
|
+
},
|
|
2719
2783
|
};
|
|
2720
2784
|
|
|
2721
|
-
const CATEGORY$
|
|
2785
|
+
const CATEGORY$2 = 'ptr';
|
|
2722
2786
|
const PtrListeners = {
|
|
2723
2787
|
onPtrDown(callback, useNormalizedCoordinates = false){
|
|
2724
|
-
this.
|
|
2788
|
+
return this.on(
|
|
2725
2789
|
'pointerdown', callback,
|
|
2726
|
-
{ category : CATEGORY$
|
|
2790
|
+
{ category : CATEGORY$2, details_setter : (ctx)=> {
|
|
2727
2791
|
const {x, y} = getCoordinates(ctx, useNormalizedCoordinates);
|
|
2728
2792
|
ctx.dx = x;
|
|
2729
2793
|
ctx.dy = y;
|
|
2730
2794
|
ctx.isDown = true;
|
|
2731
2795
|
ctx.isDragging = ctx.isMoving ?? false;
|
|
2732
2796
|
}}
|
|
2733
|
-
)
|
|
2797
|
+
)
|
|
2734
2798
|
},
|
|
2735
2799
|
onPtrMove(callback, useNormalizedCoordinates = false){
|
|
2736
|
-
this.
|
|
2800
|
+
return this.on(
|
|
2737
2801
|
'pointermove', callback,
|
|
2738
|
-
{ category : CATEGORY$
|
|
2802
|
+
{ category : CATEGORY$2, details_setter : (ctx)=> {
|
|
2739
2803
|
const {x, y} = getCoordinates(ctx, useNormalizedCoordinates);
|
|
2740
2804
|
ctx.mx = x;
|
|
2741
2805
|
ctx.my = y;
|
|
2742
2806
|
ctx.isMoving = true;
|
|
2743
2807
|
ctx.isDragging = ctx.isDown ?? false;
|
|
2744
2808
|
}}
|
|
2745
|
-
)
|
|
2809
|
+
)
|
|
2746
2810
|
},
|
|
2747
2811
|
onPtrUp(callback, useNormalizedCoordinates = false){
|
|
2748
|
-
this.
|
|
2812
|
+
return this.on(
|
|
2749
2813
|
'pointerup', callback,
|
|
2750
|
-
{ category : CATEGORY$
|
|
2814
|
+
{ category : CATEGORY$2, details_setter : (ctx)=> {
|
|
2751
2815
|
const {x, y} = getCoordinates(ctx, useNormalizedCoordinates);
|
|
2752
2816
|
ctx.ux = x;
|
|
2753
2817
|
ctx.uy = y;
|
|
@@ -2755,89 +2819,208 @@ const PtrListeners = {
|
|
|
2755
2819
|
ctx.isMoving = false;
|
|
2756
2820
|
ctx.isDragging = false;
|
|
2757
2821
|
}}
|
|
2758
|
-
)
|
|
2822
|
+
)
|
|
2759
2823
|
}
|
|
2760
2824
|
};
|
|
2761
2825
|
|
|
2762
|
-
const CATEGORY = 'key';
|
|
2826
|
+
const CATEGORY$1 = 'key';
|
|
2763
2827
|
const KeyListeners = {
|
|
2764
2828
|
onKeyDown(callback){
|
|
2765
|
-
this.
|
|
2829
|
+
return this.on(
|
|
2766
2830
|
'keydown', callback,
|
|
2767
|
-
{ category : CATEGORY, details_setter : ctx=> { ctx.kd = ctx.event.key; }
|
|
2768
|
-
})
|
|
2831
|
+
{ category : CATEGORY$1, details_setter : ctx=> { ctx.kd = ctx.event.key; }
|
|
2832
|
+
})
|
|
2769
2833
|
},
|
|
2770
2834
|
onKeyPress(callback){
|
|
2771
|
-
this.
|
|
2835
|
+
return this.on(
|
|
2772
2836
|
'keypress', callback,
|
|
2773
|
-
{ category : CATEGORY, details_setter : ctx=> { ctx.kp = ctx.event.key; }
|
|
2774
|
-
})
|
|
2837
|
+
{ category : CATEGORY$1, details_setter : ctx=> { ctx.kp = ctx.event.key; }
|
|
2838
|
+
})
|
|
2775
2839
|
},
|
|
2776
2840
|
onKeyUp(callback){
|
|
2777
|
-
this.
|
|
2841
|
+
return this.on(
|
|
2778
2842
|
'keydown', callback,
|
|
2779
|
-
{ category : CATEGORY, details_setter : ctx=> { ctx.ku = ctx.event.key; }
|
|
2780
|
-
})
|
|
2843
|
+
{ category : CATEGORY$1, details_setter : ctx=> { ctx.ku = ctx.event.key; }
|
|
2844
|
+
})
|
|
2781
2845
|
},
|
|
2782
2846
|
|
|
2783
2847
|
};
|
|
2784
2848
|
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2849
|
+
const debounce=(fn,delay=1000)=>{
|
|
2850
|
+
let id;
|
|
2851
|
+
return (...args) => id ? clearTimeout(id) : setTimeout(()=>fn(...args),delay);
|
|
2852
|
+
};
|
|
2853
|
+
const throttle=(fn,delay)=>{
|
|
2854
|
+
let lastTime=0;
|
|
2855
|
+
return (...args) => {
|
|
2856
|
+
const now = new Date().getTime();
|
|
2857
|
+
if(now-lastTime < delay) return;
|
|
2858
|
+
lastTime = now;
|
|
2859
|
+
fn(...args);
|
|
2860
|
+
}
|
|
2861
|
+
};
|
|
2862
|
+
|
|
2863
|
+
class ViewEvent extends CustomEvent {
|
|
2864
|
+
constructor(type, detail, { bubbles = true, cancelable = true } = {}) {
|
|
2865
|
+
super(type, { detail, bubbles, cancelable });
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2868
|
+
|
|
2869
|
+
function register_view_event(
|
|
2870
|
+
element,
|
|
2871
|
+
{
|
|
2872
|
+
intersection = true,
|
|
2873
|
+
resize = true,
|
|
2874
|
+
threshold = 0,
|
|
2875
|
+
throttleResize = 100,
|
|
2876
|
+
throttleEnterExit = 0
|
|
2877
|
+
} = {}
|
|
2878
|
+
) {
|
|
2879
|
+
let intersectionObserver, resizeObserver;
|
|
2880
|
+
const resizeCallback = entries => {
|
|
2881
|
+
for (let entry of entries) {
|
|
2882
|
+
const { width, height } = entry.contentRect;
|
|
2883
|
+
|
|
2884
|
+
element.dispatchEvent(
|
|
2885
|
+
new ViewEvent("resizeview", {
|
|
2886
|
+
width,
|
|
2887
|
+
height,
|
|
2888
|
+
entry
|
|
2889
|
+
})
|
|
2890
|
+
);
|
|
2891
|
+
}
|
|
2793
2892
|
};
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
}
|
|
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;
|
|
2811
|
-
callback.call(this, this);
|
|
2893
|
+
|
|
2894
|
+
const throttledResize = throttleResize > 0
|
|
2895
|
+
? throttle(resizeCallback, throttleResize)
|
|
2896
|
+
: resizeCallback;
|
|
2897
|
+
|
|
2898
|
+
const intersectionCallback = entries => {
|
|
2899
|
+
for (let entry of entries) {
|
|
2900
|
+
const type = entry.isIntersecting ? "enterview" : "exitview";
|
|
2901
|
+
element.dispatchEvent(new ViewEvent(type, entry));
|
|
2812
2902
|
}
|
|
2813
|
-
},
|
|
2814
|
-
preventDefault,
|
|
2815
|
-
paused,
|
|
2816
2903
|
};
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2904
|
+
|
|
2905
|
+
const throttledIntersections = throttleEnterExit > 0
|
|
2906
|
+
? throttle(intersectionCallback, throttleEnterExit)
|
|
2907
|
+
: intersectionCallback;
|
|
2908
|
+
|
|
2909
|
+
if (intersection) {
|
|
2910
|
+
intersectionObserver = new IntersectionObserver(throttledIntersections, { threshold });
|
|
2911
|
+
intersectionObserver.observe(element);
|
|
2912
|
+
}
|
|
2913
|
+
|
|
2914
|
+
if (resize) {
|
|
2915
|
+
resizeObserver = new ResizeObserver(throttledResize);
|
|
2916
|
+
resizeObserver.observe(element);
|
|
2917
|
+
}
|
|
2918
|
+
|
|
2919
|
+
// ---- UNREGISTER ----
|
|
2920
|
+
return () => {
|
|
2921
|
+
if (intersectionObserver) {
|
|
2922
|
+
intersectionObserver.unobserve(element);
|
|
2923
|
+
intersectionObserver.disconnect();
|
|
2924
|
+
}
|
|
2925
|
+
if (resizeObserver) {
|
|
2926
|
+
resizeObserver.unobserve(element);
|
|
2927
|
+
resizeObserver.disconnect();
|
|
2928
|
+
}
|
|
2929
|
+
};
|
|
2930
|
+
}
|
|
2931
|
+
|
|
2932
|
+
const CATEGORY = 'view';
|
|
2933
|
+
const ViewListeners = {
|
|
2934
|
+
onEnterView(callback){
|
|
2935
|
+
if(!this.exp.events?.[CATEGORY]) register_view_event(this.element);
|
|
2936
|
+
return this.on(
|
|
2937
|
+
'enterview', callback,
|
|
2938
|
+
{ category : CATEGORY, isCustom : true})
|
|
2939
|
+
},
|
|
2940
|
+
onExitView(callback){
|
|
2941
|
+
if(!this.exp.events?.[CATEGORY]) register_view_event(this.element);
|
|
2942
|
+
return this.on(
|
|
2943
|
+
'exitview', callback,
|
|
2944
|
+
{ category : CATEGORY, isCustom : true})
|
|
2945
|
+
},
|
|
2946
|
+
onResizeView(callback){
|
|
2947
|
+
if(!this.exp.events?.[CATEGORY]) register_view_event(this.element);
|
|
2948
|
+
return this.on(
|
|
2949
|
+
'resizeview', callback,
|
|
2950
|
+
{ category : CATEGORY, isCustom : true})
|
|
2951
|
+
},
|
|
2952
|
+
};
|
|
2953
|
+
|
|
2954
|
+
class SwipeEvent extends CustomEvent {
|
|
2955
|
+
constructor(type, detail) {
|
|
2956
|
+
super(type, {
|
|
2957
|
+
detail,
|
|
2958
|
+
bubbles: true,
|
|
2959
|
+
cancelable: true
|
|
2960
|
+
});
|
|
2831
2961
|
}
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2962
|
+
}
|
|
2963
|
+
|
|
2964
|
+
function register_swipe_event(
|
|
2965
|
+
element,
|
|
2966
|
+
threshold = 5,
|
|
2967
|
+
restraint = 100,
|
|
2968
|
+
allowedTime = 500
|
|
2969
|
+
) {
|
|
2970
|
+
let startX = 0,
|
|
2971
|
+
startY = 0,
|
|
2972
|
+
startTime = 0,
|
|
2973
|
+
isPointerDown = false;
|
|
2974
|
+
|
|
2975
|
+
function onPointerDown(e) {
|
|
2976
|
+
startX = e.clientX;
|
|
2977
|
+
startY = e.clientY;
|
|
2978
|
+
startTime = performance.now();
|
|
2979
|
+
isPointerDown = true;
|
|
2836
2980
|
}
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
return
|
|
2981
|
+
|
|
2982
|
+
function onPointerUp(e) {
|
|
2983
|
+
if (!isPointerDown) return;
|
|
2984
|
+
isPointerDown = false;
|
|
2985
|
+
|
|
2986
|
+
const distX = e.clientX - startX;
|
|
2987
|
+
const distY = e.clientY - startY;
|
|
2988
|
+
const elapsed = performance.now() - startTime;
|
|
2989
|
+
|
|
2990
|
+
let direction = null;
|
|
2991
|
+
let eventName = null;
|
|
2992
|
+
|
|
2993
|
+
if (elapsed <= allowedTime) {
|
|
2994
|
+
if (Math.abs(distX) >= threshold && Math.abs(distY) <= restraint) {
|
|
2995
|
+
direction = distX < 0 ? "left" : "right";
|
|
2996
|
+
eventName = "swipe" + direction;
|
|
2997
|
+
}
|
|
2998
|
+
else if (Math.abs(distY) >= threshold && Math.abs(distX) <= restraint) {
|
|
2999
|
+
direction = distY < 0 ? "up" : "down";
|
|
3000
|
+
eventName = "swipe" + direction;
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
|
|
3004
|
+
// Emit event
|
|
3005
|
+
if (eventName) {
|
|
3006
|
+
element.dispatchEvent(
|
|
3007
|
+
new SwipeEvent(eventName, {
|
|
3008
|
+
direction,
|
|
3009
|
+
distX,
|
|
3010
|
+
distY,
|
|
3011
|
+
originalEvent: e
|
|
3012
|
+
})
|
|
3013
|
+
);
|
|
3014
|
+
}
|
|
2840
3015
|
}
|
|
3016
|
+
|
|
3017
|
+
element.addEventListener("pointerdown", onPointerDown, { passive: true });
|
|
3018
|
+
element.addEventListener("pointerup", onPointerUp, { passive: true });
|
|
3019
|
+
|
|
3020
|
+
return () => {
|
|
3021
|
+
element.removeEventListener("pointerdown", onPointerDown);
|
|
3022
|
+
element.removeEventListener("pointerup", onPointerUp);
|
|
3023
|
+
};
|
|
2841
3024
|
}
|
|
2842
3025
|
|
|
2843
3026
|
let UIElement$1 = class UIElement extends UIElementCore{
|
|
@@ -2854,24 +3037,26 @@ let UIElement$1 = class UIElement extends UIElementCore{
|
|
|
2854
3037
|
AttrsMethods,
|
|
2855
3038
|
DomMethods,
|
|
2856
3039
|
StyleMethods,
|
|
2857
|
-
IndexingMethods,
|
|
3040
|
+
IndexingMethods,
|
|
2858
3041
|
PtrListeners,
|
|
2859
3042
|
ClickListeners,
|
|
2860
|
-
KeyListeners
|
|
3043
|
+
KeyListeners,
|
|
3044
|
+
ViewListeners,
|
|
2861
3045
|
);
|
|
2862
3046
|
|
|
2863
3047
|
if(element)this.init(element, name, type, render);
|
|
2864
3048
|
}
|
|
2865
|
-
|
|
3049
|
+
on(event_name, callback, {details_setter, category = 'global', isCustom = false,preventDefault = false} = {}){
|
|
2866
3050
|
if(category && !this.exp.events.hasOwnProperty(category)) this.exp.events[category] = new EventController(this, category);
|
|
3051
|
+
isCustom && this.exp.events[category].cache.customEvents.add(event_name);
|
|
2867
3052
|
const EVENT = this.exp.events[category];
|
|
2868
|
-
EVENT.addListener(
|
|
3053
|
+
EVENT.addListener(event_name, (e)=>{
|
|
2869
3054
|
if(details_setter) details_setter(EVENT);
|
|
2870
3055
|
callback(e);
|
|
2871
3056
|
},{
|
|
2872
3057
|
preventDefault
|
|
2873
3058
|
});
|
|
2874
|
-
|
|
3059
|
+
return this;
|
|
2875
3060
|
}
|
|
2876
3061
|
_off(event, category = 'global'){
|
|
2877
3062
|
this.exp.events[category].removeListener(event);
|
|
@@ -3859,20 +4044,6 @@ const Scheduler = (tasks, { repeat = null} = {}) => new TimeScheduler(tasks, { r
|
|
|
3859
4044
|
|
|
3860
4045
|
const step_fps = (step_or_fps) => 1000 / step_or_fps;
|
|
3861
4046
|
|
|
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
|
-
|
|
3876
4047
|
const sleep= ms => new Promise(res => setTimeout(res, ms));
|
|
3877
4048
|
function timeout(ms, fn) {
|
|
3878
4049
|
let id;
|
|
@@ -4889,4 +5060,4 @@ if(globalThis?.document){
|
|
|
4889
5060
|
document?.addEventListener("DOMContentLoaded", __Ziko__.__Config__.init());
|
|
4890
5061
|
}
|
|
4891
5062
|
|
|
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 };
|
|
5063
|
+
export { App, ClickAwayEvent, ClickListeners, Clock, CloneElement, Complex, E, EPSILON, EventController, FileBasedRouting, Flex, HTMLWrapper, KeyListeners, Matrix, PI$1 as PI, PtrListeners, Random, SPA, SVGWrapper, Scheduler, Suspense, SwipeEvent, Switch, Tick, TimeAnimation, TimeLoop, TimeScheduler, UIElement$1 as UIElement, UIFlex, UIHTMLWrapper, UINode, UISVGWrapper, UISwitch, UIView, UseRoot, UseThread, Utils, View, ViewEvent, ViewListeners, 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, register_click_away_event, register_swipe_event, register_view_event, 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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ziko",
|
|
3
|
-
"version": "0.68.
|
|
3
|
+
"version": "0.68.2",
|
|
4
4
|
"description": "A versatile JavaScript library offering a rich set of Hyperscript Based UI components, advanced mathematical utilities, interactivity ,animations, client side routing and more ...",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"front-end",
|
|
@@ -5,12 +5,16 @@ export class EventController {
|
|
|
5
5
|
target,
|
|
6
6
|
listeners : {},
|
|
7
7
|
currentEvent : null,
|
|
8
|
-
event : null
|
|
8
|
+
event : null,
|
|
9
|
+
customEvents : new Set()
|
|
9
10
|
}
|
|
10
11
|
}
|
|
11
12
|
get event(){
|
|
12
13
|
return this.cache.event
|
|
13
14
|
}
|
|
15
|
+
get target(){
|
|
16
|
+
return this.cache.target;
|
|
17
|
+
}
|
|
14
18
|
get element(){
|
|
15
19
|
return this.cache.target.element;
|
|
16
20
|
}
|
package/src/events/index.js
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {register_click_away_event} from '../custom-events-registry/click-away.js';
|
|
2
|
+
import { isCustomEventRegistred } from './utils/index.js';
|
|
3
|
+
const CATEGORY = 'click';
|
|
4
|
+
export const ClickListeners = {
|
|
5
|
+
onClick(callback){
|
|
6
|
+
return this.on(
|
|
7
|
+
'click', callback,
|
|
8
|
+
{ category : CATEGORY })
|
|
9
|
+
},
|
|
10
|
+
onDblClick(callback){
|
|
11
|
+
return this.on(
|
|
12
|
+
'dblclick', callback,
|
|
13
|
+
{ category : CATEGORY})
|
|
14
|
+
},
|
|
15
|
+
onClickAway(callback){
|
|
16
|
+
if(!isCustomEventRegistred(this, CATEGORY, 'clickaway')) register_click_away_event(this.element);
|
|
17
|
+
return this.on(
|
|
18
|
+
'clickaway', callback,
|
|
19
|
+
{ category : CATEGORY, isCustom : true})
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
const CATEGORY = 'key'
|
|
2
2
|
export const KeyListeners = {
|
|
3
3
|
onKeyDown(callback){
|
|
4
|
-
this.
|
|
4
|
+
return this.on(
|
|
5
5
|
'keydown', callback,
|
|
6
6
|
{ category : CATEGORY, details_setter : ctx=> { ctx.kd = ctx.event.key }
|
|
7
7
|
})
|
|
8
8
|
},
|
|
9
9
|
onKeyPress(callback){
|
|
10
|
-
this.
|
|
10
|
+
return this.on(
|
|
11
11
|
'keypress', callback,
|
|
12
12
|
{ category : CATEGORY, details_setter : ctx=> { ctx.kp = ctx.event.key }
|
|
13
13
|
})
|
|
14
14
|
},
|
|
15
15
|
onKeyUp(callback){
|
|
16
|
-
this.
|
|
16
|
+
return this.on(
|
|
17
17
|
'keydown', callback,
|
|
18
18
|
{ category : CATEGORY, details_setter : ctx=> { ctx.ku = ctx.event.key }
|
|
19
19
|
})
|
|
@@ -2,7 +2,7 @@ import { getCoordinates } from "./utils/index.js";
|
|
|
2
2
|
const CATEGORY = 'ptr';
|
|
3
3
|
export const PtrListeners = {
|
|
4
4
|
onPtrDown(callback, useNormalizedCoordinates = false){
|
|
5
|
-
this.
|
|
5
|
+
return this.on(
|
|
6
6
|
'pointerdown', callback,
|
|
7
7
|
{ category : CATEGORY, details_setter : (ctx)=> {
|
|
8
8
|
const {x, y} = getCoordinates(ctx, useNormalizedCoordinates);
|
|
@@ -14,7 +14,7 @@ export const PtrListeners = {
|
|
|
14
14
|
)
|
|
15
15
|
},
|
|
16
16
|
onPtrMove(callback, useNormalizedCoordinates = false){
|
|
17
|
-
this.
|
|
17
|
+
return this.on(
|
|
18
18
|
'pointermove', callback,
|
|
19
19
|
{ category : CATEGORY, details_setter : (ctx)=> {
|
|
20
20
|
const {x, y} = getCoordinates(ctx, useNormalizedCoordinates);
|
|
@@ -26,7 +26,7 @@ export const PtrListeners = {
|
|
|
26
26
|
)
|
|
27
27
|
},
|
|
28
28
|
onPtrUp(callback, useNormalizedCoordinates = false){
|
|
29
|
-
this.
|
|
29
|
+
return this.on(
|
|
30
30
|
'pointerup', callback,
|
|
31
31
|
{ category : CATEGORY, details_setter : (ctx)=> {
|
|
32
32
|
const {x, y} = getCoordinates(ctx, useNormalizedCoordinates);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { register_swipe_event } from '../custom-events-registry/swipe.js';
|
|
2
|
+
const CATEGORY = 'swipe';
|
|
3
|
+
export const SwipeListeners = {
|
|
4
|
+
onSwipeLeft(callback){
|
|
5
|
+
if(!this.exp.events?.[CATEGORY]) register_swipe_event(this.element);
|
|
6
|
+
return this.on(
|
|
7
|
+
'swipeleft', callback,
|
|
8
|
+
{ category : CATEGORY, isCustom : true})
|
|
9
|
+
},
|
|
10
|
+
onSwipeRight(callback){
|
|
11
|
+
if(!this.exp.events?.[CATEGORY]) register_swipe_event(this.element);
|
|
12
|
+
return this.on(
|
|
13
|
+
'swiperight', callback,
|
|
14
|
+
{ category : CATEGORY, isCustom : true})
|
|
15
|
+
},
|
|
16
|
+
onSwipeUp(callback){
|
|
17
|
+
if(!this.exp.events?.[CATEGORY]) register_swipe_event(this.element);
|
|
18
|
+
return this.on(
|
|
19
|
+
'swipeup', callback,
|
|
20
|
+
{ category : CATEGORY, isCustom : true})
|
|
21
|
+
},
|
|
22
|
+
onSwipeDown(callback){
|
|
23
|
+
if(!this.exp.events?.[CATEGORY]) register_swipe_event(this.element);
|
|
24
|
+
return this.on(
|
|
25
|
+
'swipedown', callback,
|
|
26
|
+
{ category : CATEGORY, isCustom : true})
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|