@tschk/moonshine-svelte 0.4.49 → 0.4.80
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/README.md +46 -8
- package/package.json +17 -5
- package/src/abort-signal.ts +60 -0
- package/src/animate.ts +71 -0
- package/src/attachments.ts +93 -0
- package/src/derived.ts +35 -5
- package/src/easing.ts +176 -0
- package/src/effect.ts +17 -4
- package/src/events.ts +76 -0
- package/src/kit.ts +1973 -0
- package/src/legacy.ts +361 -0
- package/src/motion.ts +504 -0
- package/src/navigation.ts +1134 -0
- package/src/pre.ts +18 -4
- package/src/prop-id.ts +43 -0
- package/src/reactivity-window.ts +173 -0
- package/src/reactivity.ts +983 -0
- package/src/runes.ts +1 -0
- package/src/server.ts +56 -0
- package/src/ssr.ts +34 -3
- package/src/svelte.ts +30 -1
- package/src/tick-queue.ts +3 -0
- package/src/transition.ts +348 -0
package/src/events.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/** Independent host-free Svelte 5 DOM event helper (`svelte/events`). */
|
|
2
|
+
|
|
3
|
+
export type EventListenerWithTarget<
|
|
4
|
+
Target extends EventTarget,
|
|
5
|
+
E extends Event,
|
|
6
|
+
> = (this: Target, event: E & { currentTarget: Target }) => any;
|
|
7
|
+
|
|
8
|
+
export function on<
|
|
9
|
+
K extends keyof WindowEventMap,
|
|
10
|
+
Target extends Window = Window,
|
|
11
|
+
>(
|
|
12
|
+
window: Target,
|
|
13
|
+
type: K,
|
|
14
|
+
handler: EventListenerWithTarget<Target, WindowEventMap[K]>,
|
|
15
|
+
options?: AddEventListenerOptions | boolean,
|
|
16
|
+
): () => void;
|
|
17
|
+
export function on<
|
|
18
|
+
K extends keyof DocumentEventMap,
|
|
19
|
+
Target extends Document = Document,
|
|
20
|
+
>(
|
|
21
|
+
document: Target,
|
|
22
|
+
type: K,
|
|
23
|
+
handler: EventListenerWithTarget<Target, DocumentEventMap[K]>,
|
|
24
|
+
options?: AddEventListenerOptions | boolean,
|
|
25
|
+
): () => void;
|
|
26
|
+
export function on<
|
|
27
|
+
K extends keyof HTMLElementEventMap,
|
|
28
|
+
Target extends HTMLElement = HTMLElement,
|
|
29
|
+
>(
|
|
30
|
+
element: Target,
|
|
31
|
+
type: K,
|
|
32
|
+
handler: EventListenerWithTarget<Target, HTMLElementEventMap[K]>,
|
|
33
|
+
options?: AddEventListenerOptions | boolean,
|
|
34
|
+
): () => void;
|
|
35
|
+
export function on<
|
|
36
|
+
K extends keyof MediaQueryListEventMap,
|
|
37
|
+
Target extends MediaQueryList = MediaQueryList,
|
|
38
|
+
>(
|
|
39
|
+
target: Target,
|
|
40
|
+
type: K,
|
|
41
|
+
handler: EventListenerWithTarget<Target, MediaQueryListEventMap[K]>,
|
|
42
|
+
options?: AddEventListenerOptions | boolean,
|
|
43
|
+
): () => void;
|
|
44
|
+
export function on<Target extends EventTarget, E extends Event = Event>(
|
|
45
|
+
element: Target,
|
|
46
|
+
type: string,
|
|
47
|
+
handler: EventListenerWithTarget<Target, E>,
|
|
48
|
+
options?: AddEventListenerOptions | boolean,
|
|
49
|
+
): () => void;
|
|
50
|
+
export function on(
|
|
51
|
+
element: EventTarget,
|
|
52
|
+
type: string,
|
|
53
|
+
handler: EventListenerWithTarget<EventTarget, Event>,
|
|
54
|
+
options?: AddEventListenerOptions | boolean,
|
|
55
|
+
): () => void {
|
|
56
|
+
if (
|
|
57
|
+
!element ||
|
|
58
|
+
typeof element.addEventListener !== "function" ||
|
|
59
|
+
typeof element.removeEventListener !== "function"
|
|
60
|
+
) {
|
|
61
|
+
throw new TypeError("on() requires an EventTarget");
|
|
62
|
+
}
|
|
63
|
+
if (typeof handler !== "function") {
|
|
64
|
+
throw new TypeError("on() requires a callback function");
|
|
65
|
+
}
|
|
66
|
+
const listener: EventListener = (event) => {
|
|
67
|
+
return handler.call(
|
|
68
|
+
element,
|
|
69
|
+
event as Event & { currentTarget: EventTarget },
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
element.addEventListener(type, listener, options);
|
|
73
|
+
return () => {
|
|
74
|
+
element.removeEventListener(type, listener, options);
|
|
75
|
+
};
|
|
76
|
+
}
|