ziko 1.7.0 → 1.9.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.
Files changed (59) hide show
  1. package/dist/ziko.cjs +458 -174
  2. package/dist/ziko.js +458 -174
  3. package/dist/ziko.min.js +2 -2
  4. package/dist/ziko.mjs +453 -173
  5. package/package.json +1 -1
  6. package/src/dom/{flex → components/Flex}/index.js +1 -1
  7. package/src/dom/components/{for → For}/index.js +1 -1
  8. package/src/dom/{suspense → components/Suspense}/index.js +3 -7
  9. package/src/dom/components/View/index.js +9 -0
  10. package/src/dom/{graphics/canvas.js → components/graphics/Canvas/index.js} +6 -6
  11. package/src/dom/{graphics/svg.js → components/graphics/Svg/index.js} +4 -4
  12. package/src/dom/components/graphics/index.js +2 -0
  13. package/src/dom/components/index.js +10 -3
  14. package/src/dom/{wrappers/html → components/wrappers/HTMLWrapper}/index.js +1 -1
  15. package/src/dom/{wrappers/svg → components/wrappers/SVGWrapper}/index.js +1 -1
  16. package/src/dom/components/wrappers/index.js +2 -0
  17. package/src/dom/constructors/mixins/dom.js +1 -0
  18. package/src/dom/index.js +0 -8
  19. package/src/hooks/index.d.ts +1 -0
  20. package/src/hooks/index.js +1 -0
  21. package/src/hooks/use-derived.js +24 -17
  22. package/src/hooks/use-effect.d.ts +39 -0
  23. package/src/hooks/use-effect.js +40 -0
  24. package/src/hooks/use-state.d.ts +28 -10
  25. package/src/hooks/use-state.js +3 -1
  26. package/src/symbols/index.d.ts +39 -0
  27. package/src/symbols/index.js +5 -0
  28. package/src/dom/graphics/index.js +0 -2
  29. package/src/dom/logic/index.js +0 -1
  30. package/src/dom/view/index.js +0 -13
  31. package/src/dom/wrappers/index.js +0 -2
  32. package/src/events-dep/binders/coordinates-based-event.js +0 -25
  33. package/src/events-dep/binders/custom-event.js +0 -33
  34. package/src/events-dep/binders/index.js +0 -105
  35. package/src/events-dep/custom-events-registry/click-away.js +0 -38
  36. package/src/events-dep/custom-events-registry/index.js +0 -3
  37. package/src/events-dep/custom-events-registry/swipe.js +0 -76
  38. package/src/events-dep/custom-events-registry/view.js +0 -74
  39. package/src/events-dep/customizers/normalise-coordinates.js +0 -0
  40. package/src/events-dep/details-setter/index.js +0 -4
  41. package/src/events-dep/details-setter/key.js +0 -14
  42. package/src/events-dep/details-setter/mouse.js +0 -35
  43. package/src/events-dep/details-setter/pointer.js +0 -35
  44. package/src/events-dep/details-setter/touch.js +0 -37
  45. package/src/events-dep/events-map/index.js +0 -70
  46. package/src/events-dep/index.js +0 -3
  47. package/src/events-dep/types/__Shared__.d.ts +0 -155
  48. package/src/events-dep/types/clipboard.d.ts +0 -20
  49. package/src/events-dep/types/focus.d.ts +0 -19
  50. package/src/events-dep/types/pointer.d.ts +0 -45
  51. package/src/events-dep/utils.js +0 -38
  52. package/src/events-dep/ziko-event.js +0 -108
  53. package/src/watch/dom-observer/ziko-observer.js +0 -15
  54. /package/src/dom/{flex → components/Flex}/utils/index.js +0 -0
  55. /package/src/dom/components/{fragment → Fragment}/index.d.ts +0 -0
  56. /package/src/dom/components/{fragment → Fragment}/index.js +0 -0
  57. /package/src/dom/components/{swap → Swap}/index.d.ts +0 -0
  58. /package/src/dom/components/{swap → Swap}/index.js +0 -0
  59. /package/src/dom/{logic/switch → components/Switch}/index.js +0 -0
@@ -1,76 +0,0 @@
1
- class SwipeEvent extends CustomEvent {
2
- constructor(type, detail) {
3
- super(type, {
4
- detail,
5
- bubbles: true,
6
- cancelable: true
7
- });
8
- }
9
- }
10
-
11
- function register_swipe_event(
12
- element,
13
- threshold = 50,
14
- restraint = 100,
15
- allowedTime = 500
16
- ) {
17
- let startX = 0,
18
- startY = 0,
19
- startTime = 0,
20
- isPointerDown = false;
21
-
22
- function onPointerDown(e) {
23
- startX = e.clientX;
24
- startY = e.clientY;
25
- startTime = performance.now();
26
- isPointerDown = true;
27
- }
28
-
29
- function onPointerUp(e) {
30
- if (!isPointerDown) return;
31
- isPointerDown = false;
32
-
33
- const distX = e.clientX - startX;
34
- const distY = e.clientY - startY;
35
- const elapsed = performance.now() - startTime;
36
-
37
- let direction = null;
38
- let eventName = null;
39
-
40
- if (elapsed <= allowedTime) {
41
- if (Math.abs(distX) >= threshold && Math.abs(distY) <= restraint) {
42
- direction = distX < 0 ? "left" : "right";
43
- eventName = "swipe" + direction;
44
- }
45
- else if (Math.abs(distY) >= threshold && Math.abs(distX) <= restraint) {
46
- direction = distY < 0 ? "up" : "down";
47
- eventName = "swipe" + direction;
48
- }
49
- }
50
-
51
- // Emit event
52
- if (eventName) {
53
- element.dispatchEvent(
54
- new SwipeEvent(eventName, {
55
- direction,
56
- distX,
57
- distY,
58
- originalEvent: e
59
- })
60
- );
61
- }
62
- }
63
-
64
- element.addEventListener("pointerdown", onPointerDown, { passive: true });
65
- element.addEventListener("pointerup", onPointerUp, { passive: true });
66
-
67
- return () => {
68
- element.removeEventListener("pointerdown", onPointerDown);
69
- element.removeEventListener("pointerup", onPointerUp);
70
- };
71
- }
72
-
73
- export {
74
- SwipeEvent,
75
- register_swipe_event
76
- };
@@ -1,74 +0,0 @@
1
- import { throttle } from "../../time/decorators/index.js";
2
- class ViewEvent extends CustomEvent {
3
- constructor(type, detail, { bubbles = true, cancelable = true } = {}) {
4
- super(type, { detail, bubbles, cancelable });
5
- }
6
- }
7
-
8
- function register_view_event(
9
- element,
10
- {
11
- intersection = true,
12
- resize = true,
13
- threshold = 0,
14
- throttleResize = 100,
15
- throttleEnterExit = 0
16
- } = {}
17
- ) {
18
- let intersectionObserver, resizeObserver;
19
- const resizeCallback = entries => {
20
- for (let entry of entries) {
21
- const { width, height } = entry.contentRect;
22
-
23
- element.dispatchEvent(
24
- new ViewEvent("resizeview", {
25
- width,
26
- height,
27
- entry
28
- })
29
- );
30
- }
31
- };
32
-
33
- const throttledResize = throttleResize > 0
34
- ? throttle(resizeCallback, throttleResize)
35
- : resizeCallback;
36
-
37
- const intersectionCallback = entries => {
38
- for (let entry of entries) {
39
- const type = entry.isIntersecting ? "enterview" : "exitview";
40
- element.dispatchEvent(new ViewEvent(type, entry));
41
- }
42
- };
43
-
44
- const throttledIntersections = throttleEnterExit > 0
45
- ? throttle(intersectionCallback, throttleEnterExit)
46
- : intersectionCallback;
47
-
48
- if (intersection) {
49
- intersectionObserver = new IntersectionObserver(throttledIntersections, { threshold });
50
- intersectionObserver.observe(element);
51
- }
52
-
53
- if (resize) {
54
- resizeObserver = new ResizeObserver(throttledResize);
55
- resizeObserver.observe(element);
56
- }
57
-
58
- // ---- UNREGISTER ----
59
- return () => {
60
- if (intersectionObserver) {
61
- intersectionObserver.unobserve(element);
62
- intersectionObserver.disconnect();
63
- }
64
- if (resizeObserver) {
65
- resizeObserver.unobserve(element);
66
- resizeObserver.disconnect();
67
- }
68
- };
69
- }
70
-
71
- export {
72
- ViewEvent,
73
- register_view_event
74
- };
@@ -1,4 +0,0 @@
1
- export * from './key.js'
2
- export * from './pointer.js'
3
- export * from './mouse.js'
4
- export * from './touch.js'
@@ -1,14 +0,0 @@
1
- export function key_details_setter(){
2
- switch(this.currentEvent){
3
- case "keydown" : {
4
- this.kd = this.event.key
5
- }; break;
6
- case "keypress" : {
7
- this.kp = this.event.key
8
- }; break;
9
- case "keyup" : {
10
- this.ku = this.event.key
11
- }; break;
12
-
13
- }
14
- }
@@ -1,35 +0,0 @@
1
- export function mouse_details_setter() {
2
- const rect = this.targetElement.getBoundingClientRect();
3
- const e = this.event;
4
- let x = (e.clientX - rect.left) | 0;
5
- let y = (e.clientY - rect.top) | 0;
6
-
7
- if(this.cache.useNormalisedCoordinates){
8
- const w = this.targetElement.clientWidth;
9
- const h = this.targetElement.clientHeight;
10
- x = +((x / w) * 2 - 1).toFixed(8);
11
- y = +((y / h) * -2 + 1).toFixed(8);
12
- }
13
-
14
- switch (this.currentEvent) {
15
-
16
- case "mousedown":
17
- this.dx = x;
18
- this.dy = y;
19
- this.isDown = true;
20
- break;
21
-
22
- case "mousemove":
23
- this.mx = x;
24
- this.my = y;
25
- this.isMoving = true;
26
- break;
27
-
28
- case "mouserup":
29
- this.ux = x;
30
- this.uy = y;
31
- this.isDown = false;
32
- this.isMoving = false;
33
- break;
34
- }
35
- }
@@ -1,35 +0,0 @@
1
- export function ptr_details_setter() {
2
- const rect = this.targetElement.getBoundingClientRect();
3
- const e = this.event;
4
- let x = (e.clientX - rect.left) | 0;
5
- let y = (e.clientY - rect.top) | 0;
6
-
7
- if(this.cache.useNormalisedCoordinates){
8
- const w = this.targetElement.clientWidth;
9
- const h = this.targetElement.clientHeight;
10
- x = +((x / w) * 2 - 1).toFixed(8);
11
- y = +((y / h) * -2 + 1).toFixed(8);
12
- }
13
- switch (this.currentEvent) {
14
-
15
- case "pointerdown":
16
- this.dx = x;
17
- this.dy = y;
18
- this.isDown = true;
19
- break;
20
-
21
- case "pointermove":
22
- this.mx = x;
23
- this.my = y;
24
- this.isMoving = true;
25
- break;
26
-
27
- case "pointerup":
28
- this.ux = x;
29
- this.uy = y;
30
- this.isDown = false;
31
- this.isMoving = false;
32
- break;
33
- }
34
- }
35
-
@@ -1,37 +0,0 @@
1
- export function touch_details_setter() {
2
- const e = this.event;
3
- const touch = e.touches?.[0] || e.changedTouches?.[0];
4
-
5
- if (!touch) return; // should never happen but safe
6
-
7
- const rect = this.targetElement.getBoundingClientRect();
8
- let x = touch.clientX - rect.left;
9
- let y = touch.clientY - rect.top;
10
-
11
- if(this.cache.useNormalisedCoordinates){
12
- const w = this.targetElement.clientWidth;
13
- const h = this.targetElement.clientHeight;
14
- x = +((x / w) * 2 - 1).toFixed(8);
15
- y = +((y / h) * -2 + 1).toFixed(8);
16
- }
17
-
18
- switch (this.currentEvent) {
19
- case "touchstart":
20
- this.dx = x;
21
- this.dy = y;
22
- this.isDown = true;
23
- break;
24
-
25
- case "touchmove":
26
- this.mx = x;
27
- this.my = y;
28
- this.isMoving = true;
29
- break;
30
-
31
- case "touchend":
32
- this.ux = x;
33
- this.uy = y;
34
- this.isDown = false;
35
- break;
36
- }
37
- }
@@ -1,70 +0,0 @@
1
- const EventsMap = {
2
- 'Click' : [
3
- 'Click',
4
- 'DblClick',
5
- 'ClickAway'
6
- ],
7
- 'Ptr' : [
8
- 'PtrMove',
9
- 'PtrDown',
10
- 'PtrUp',
11
- 'PtrLeave',
12
- 'PtrEnter',
13
- 'PtrOut',
14
- 'PtrCancel'
15
- ],
16
- 'Mouse' : [
17
- 'MouseMove',
18
- 'MouseDown',
19
- 'MouseUp',
20
- 'MouseEnter',
21
- 'MouseLeave',
22
- 'MouseOut'
23
- ],
24
- // 'Touch' : [],
25
- 'Key' : [
26
- 'KeyDown',
27
- 'KeyPress',
28
- 'KeyUp'
29
- ],
30
- 'Clipboard':[
31
- 'Copy',
32
- 'Cut',
33
- 'Paste'
34
- ],
35
- 'Focus':[
36
- 'focus',
37
- 'blur'
38
- ],
39
- 'Drag':[
40
- "Drag",
41
- "DragStart",
42
- "DragEnd",
43
- "Drop"
44
- ],
45
- 'Wheel': [
46
- 'Wheel'
47
- ],
48
- // 'Media':[
49
-
50
- // ],
51
- // 'Hash':[
52
- // "HashChange"
53
- // ]
54
-
55
- 'View':[
56
- 'EnterView',
57
- 'ExitView',
58
- 'ResizeView'
59
- ],
60
- 'Swipe':[
61
- 'SwipeLeft',
62
- 'SwipeUp',
63
- 'SwipeRight',
64
- 'SwipeDown'
65
- ]
66
- }
67
-
68
- export {
69
- EventsMap
70
- }
@@ -1,3 +0,0 @@
1
- // export * from './binders/index.js'
2
- // export * from "./ziko-event.js"
3
- // export * from "./utils.js";
@@ -1,155 +0,0 @@
1
- export type EventCustomizer = ((this: ZikoEvent) => void) | ((ctx: ZikoEvent) => void);
2
-
3
- export type EventMethodesBinder<
4
- EventKeys extends string,
5
- InstanceType
6
- > = {
7
- [K in EventKeys as `on${K}`]: (...callbacks: ((ctx: InstanceType) => void)[]) => InstanceType
8
- };
9
-
10
- export type Callback<InstanceType> = (ctx: InstanceType) => void;
11
-
12
- export interface ZikoEventStream {
13
- enabled: Record<string, boolean>;
14
- clear: Record<string, boolean>;
15
- history: Record<string, any[]>;
16
- t0?: number;
17
- }
18
-
19
- export interface ZikoEventCache {
20
- currentEvent: string | null;
21
- event: Event | null;
22
- options: Record<string, AddEventListenerOptions>;
23
- preventDefault: Record<string, boolean>;
24
- stopPropagation: Record<string, boolean>;
25
- stopImmediatePropagation: Record<string, boolean>;
26
- event_flow: Record<string, unknown>;
27
- paused: Record<string, boolean>;
28
- stream: ZikoEventStream;
29
- callbacks: Record<string, ((e: any) => void)[]>;
30
- __controllers__: Record<string, (e: Event) => void>;
31
- }
32
-
33
- export declare class ZikoEvent {
34
- constructor(
35
- target: any,
36
- Events: string[],
37
- details_setter?: (this: ZikoEvent) => void,
38
- customizer?: EventCustomizer
39
- );
40
-
41
- target: any;
42
- cache: ZikoEventCache;
43
-
44
- get targetElement(): HTMLElement | null;
45
- get isParent(): boolean;
46
- get item(): any;
47
- get currentEvent(): string | null;
48
- get event(): Event | null;
49
-
50
- _register_events(
51
- Events: string[] | undefined,
52
- details_setter: (e: this) => any,
53
- customizer: (e: this) => any, // To Check
54
- REGISTER_METHODES?: boolean
55
- ): this;
56
-
57
- setTarget(UI: any): this;
58
-
59
- preventDefault(
60
- overrides?: Partial<Record<string, boolean>>,
61
- defaultValue?: boolean | "default"
62
- ): this;
63
-
64
- stopPropagation(
65
- overrides?: Partial<Record<string, boolean>>,
66
- defaultValue?: boolean | "default"
67
- ): this;
68
-
69
- stopImmediatePropagation(
70
- overrides?: Partial<Record<string, boolean>>,
71
- defaultValue?: boolean | "default"
72
- ): this;
73
-
74
- setEventOptions(
75
- event: string,
76
- options: AddEventListenerOptions
77
- ): this;
78
-
79
- pause(
80
- overrides?: Partial<Record<string, boolean>>,
81
- defaultValue?: boolean | "default"
82
- ): this;
83
-
84
- resume(
85
- overrides?: Partial<Record<string, boolean>>,
86
- defaultValue?: boolean | "default"
87
- ): this;
88
-
89
- stream(
90
- overrides?: Partial<Record<string, boolean>>,
91
- defaultValue?: boolean | "default"
92
- ): this;
93
-
94
- clear(): this;
95
-
96
- dispose(
97
- overrides?: Partial<Record<string, boolean>>,
98
- defaultValue?: boolean | "default"
99
- ): this;
100
-
101
- // Internal
102
- protected __handle(
103
- event: string,
104
- handler: EventListenerOrEventListenerObject,
105
- options?: AddEventListenerOptions,
106
- dispose?: any
107
- ): this;
108
-
109
- protected __onEvent(
110
- event: string,
111
- options?: AddEventListenerOptions,
112
- dispose?: any,
113
- ...callbacks: ((ctx: this) => void)[]
114
- ): this;
115
- }
116
- // export type ClickEventKeys =
117
- // | 'Click'
118
- // | 'DblClick';
119
-
120
- // export type PointerEventKeys =
121
- // | 'PtrMove'
122
- // | 'PtrDown'
123
- // | 'PtrUp'
124
- // | 'PtrLeave'
125
- // | 'PtrEnter'
126
- // | 'PtrOut'
127
- // | 'PtrCancel'
128
-
129
- // export type MouseEventKeys =
130
- // | 'MouseMove'
131
- // | 'MouseDown';
132
- // export type TouchEventKeys =
133
- // | 'ToucMove'
134
- // | 'ToucDown';
135
- // export type KeyEventKeys =
136
- // | 'keyDown'
137
- // | 'keyPress'
138
- // | 'keyUs';
139
- // export type ClipboardEventKeys =
140
- // | 'Copy'
141
- // | 'Cut'
142
- // | 'Paste';
143
- // export type FocusEventKeys =
144
- // | 'focus'
145
- // | 'blur';
146
- // export type DragEventKeys =
147
- // | 'Drag'
148
- // | 'DragStart'
149
- // | 'DragEnd'
150
- // | 'Drop';
151
- // export type MediaEventKeys =
152
- // | '__';
153
- // export type HashEventKeys =
154
- // | 'HashChange'
155
-
@@ -1,20 +0,0 @@
1
- import { ZikoEvent } from "../ziko-event.js";
2
- import type { Callback, ClipboardEventKeys } from './__Shared__.js';
3
- import { UIElement } from "../../ui/index.js";
4
-
5
- declare class ZikoEventClipboard extends ZikoEvent {
6
- constructor(target: any, customizer?: Function);
7
-
8
- // Explicitly declare the dynamic methods to get editor support
9
- onCopy(...callbacks: Callback<ZikoEventClipboard>[]): this;
10
- onCut(...callbacks: Callback<ZikoEventClipboard>[]): this;
11
- onPaste(...callbacks: Callback<ZikoEventClipboard>[]): this;
12
-
13
- }
14
-
15
- declare const bind_clipboard_event: (target: UIElement, customizer?: Function) => ZikoEventClipboard;
16
-
17
- export {
18
- ZikoEventClipboard,
19
- bind_clipboard_event,
20
- };
@@ -1,19 +0,0 @@
1
- import { ZikoEvent } from "../ziko-event.js";
2
- import type { Callback } from './__Shared__.js';
3
- import { UIElement } from "../../ui/index.js";
4
-
5
- declare class ZikoEventFocus extends ZikoEvent {
6
- constructor(target: any, customizer?: Function);
7
-
8
- // Explicitly declare the dynamic methods to get editor support
9
- onFocus(...callbacks: Callback<ZikoEventFocus>[]): this;
10
- onBlur(...callbacks: Callback<ZikoEventFocus>[]): this;
11
-
12
- }
13
-
14
- declare const bind_focus_event: (target: UIElement, customizer?: Function) => ZikoEventFocus;
15
-
16
- export {
17
- ZikoEventFocus,
18
- bind_focus_event,
19
- };
@@ -1,45 +0,0 @@
1
- import { ZikoEvent } from "../ziko-event.js";
2
- import type { EventMethodesBinder, Callback, PointerEventKeys } from './__Shared__.js';
3
- import { UIElement } from "../../ui/index.js";
4
-
5
- type PointerEventMethodesBinder = EventMethodesBinder<PointerEventKeys, ZikoEventPointer>;
6
-
7
- declare class ZikoEventPointer extends ZikoEvent implements PointerEventMethodesBinder {
8
- constructor(target: any, customizer?: Function);
9
-
10
- isDown: boolean;
11
-
12
- dx?: number;
13
- dy?: number;
14
-
15
- mx?: number;
16
- my?: number;
17
- isMoving?: boolean;
18
-
19
- ux?: number;
20
- uy?: number;
21
-
22
- swippe?: {
23
- h: "left" | "right" | "none";
24
- v: "top" | "bottom" | "none";
25
- delta_x: number;
26
- delta_y: number;
27
- };
28
-
29
- // Explicitly declare the dynamic methods to get editor support
30
- onPtrMove(...callbacks: Callback<ZikoEventPointer>[]): this;
31
- onPtrDown(...callbacks: Callback<ZikoEventPointer>[]): this;
32
- onPtrUp(...callbacks: Callback<ZikoEventPointer>[]): this;
33
- onPtrLeave(...callbacks: Callback<ZikoEventPointer>[]): this;
34
- onPtrEnter(...callbacks: Callback<ZikoEventPointer>[]): this;
35
- onPtrOut(...callbacks: Callback<ZikoEventPointer>[]): this;
36
- onPtrCancel(...callbacks: Callback<ZikoEventPointer>[]): this;
37
-
38
- }
39
-
40
- declare const bind_pointer_event: (target: UIElement, customizer?: Function) => ZikoEventPointer;
41
-
42
- export {
43
- ZikoEventPointer,
44
- bind_pointer_event,
45
- };
@@ -1,38 +0,0 @@
1
- export function event_controller(e, event_name, details_setter, customizer) {
2
- this.cache.currentEvent = event_name;
3
- this.cache.event = e;
4
-
5
- details_setter?.call(this);
6
- if (customizer?.hasOwnProperty('prototype')) customizer?.call(this);
7
- else customizer?.call(null, this);
8
-
9
- if (this.cache.preventDefault[event_name]) e.preventDefault();
10
- if (this.cache.stopPropagation[event_name]) e.stopPropagation();
11
- if (this.cache.stopImmediatePropagation[event_name]) e.stopImmediatePropagation();
12
-
13
- // Call the single callback if it exists
14
- this.cache.callbacks[event_name]?.(this);
15
- }
16
-
17
- export function toggle_event_listener(method, ...events) {
18
- const keys = events.length === 0
19
- ? Object.keys(this.cache.paused)
20
- : events;
21
- keys.forEach(key => {
22
- if (!this.cache.paused.hasOwnProperty(key)) return;
23
- this.targetElement?.[method](
24
- key,
25
- this.cache.__controllers__[key],
26
- this.cache.options[key]
27
- );
28
- this.cache.paused[key] = method === 'removeEventListener';
29
- });
30
- return this;
31
- }
32
- const getEvent=(event = "")=>{
33
- if(event.startsWith("Ptr"))return `pointer${event.split("Ptr")[1].toLowerCase()}`;
34
- return event.toLowerCase()
35
- }
36
- export{
37
- getEvent
38
- }