@sigil-dev/runtime 0.9.3 → 0.9.5
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/async-boundary.ts +30 -30
- package/boundary.ts +44 -44
- package/easing.ts +66 -66
- package/index.test.ts +1843 -1618
- package/index.ts +164 -40
- package/jsr.json +8 -8
- package/package.json +1 -1
- package/reactivity/map.ts +98 -98
- package/reactivity/set.ts +74 -74
- package/test-preload.ts +9 -9
- package/transition.ts +69 -0
- package/tsconfig.json +30 -30
package/transition.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* transition:/in:/out: directive support.
|
|
3
|
+
*
|
|
4
|
+
* The compiler lowers `<div transition:fade={fade}>` to
|
|
5
|
+
* `mountTransition(el, fade, "transition")` (bare expression or
|
|
6
|
+
* `[fn, params]` tuple), and swaps anchor-mount cleanup's `node.remove()`
|
|
7
|
+
* for `removeAnimated(node)` so out-directions can play before unmount.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export type TransitionFn = (
|
|
11
|
+
el: Element,
|
|
12
|
+
params: unknown,
|
|
13
|
+
direction: "in" | "out",
|
|
14
|
+
) => Animation | undefined | void;
|
|
15
|
+
|
|
16
|
+
const outRegistry = new WeakMap<
|
|
17
|
+
Element,
|
|
18
|
+
{ fn: TransitionFn; params: unknown }
|
|
19
|
+
>();
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Play an in-animation immediately (when kind includes it) and register the
|
|
23
|
+
* element for an out-animation on removal (when kind includes that).
|
|
24
|
+
* Returns a cleanup that unregisters the element.
|
|
25
|
+
*/
|
|
26
|
+
export function mountTransition(
|
|
27
|
+
el: Element,
|
|
28
|
+
spec: TransitionFn | [TransitionFn, unknown],
|
|
29
|
+
kind: "in" | "out" | "transition",
|
|
30
|
+
): () => void {
|
|
31
|
+
const [fn, params] = Array.isArray(spec) ? spec : [spec, undefined];
|
|
32
|
+
if (kind === "in" || kind === "transition") {
|
|
33
|
+
fn(el, params, "in");
|
|
34
|
+
}
|
|
35
|
+
if (kind === "out" || kind === "transition") {
|
|
36
|
+
outRegistry.set(el, { fn, params });
|
|
37
|
+
}
|
|
38
|
+
return () => {
|
|
39
|
+
outRegistry.delete(el);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Remove a node, playing its registered out-animation first when one exists.
|
|
45
|
+
* No registration → immediate removal (plain remove() semantics).
|
|
46
|
+
*/
|
|
47
|
+
export function removeAnimated(node: Node): void {
|
|
48
|
+
if (!(node instanceof Element)) {
|
|
49
|
+
node.remove();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const entry = outRegistry.get(node);
|
|
53
|
+
if (!entry) {
|
|
54
|
+
node.remove();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const animation = entry.fn(node, entry.params, "out");
|
|
58
|
+
if (animation?.finished && typeof animation.finished.finally === "function") {
|
|
59
|
+
animation.finished
|
|
60
|
+
.finally(() => {
|
|
61
|
+
node.remove();
|
|
62
|
+
})
|
|
63
|
+
.catch(() => {
|
|
64
|
+
node.remove();
|
|
65
|
+
});
|
|
66
|
+
} else {
|
|
67
|
+
node.remove();
|
|
68
|
+
}
|
|
69
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
// Environment setup & latest features
|
|
4
|
-
"lib": ["ESNext", "DOM"],
|
|
5
|
-
"target": "ESNext",
|
|
6
|
-
"module": "Preserve",
|
|
7
|
-
"moduleDetection": "force",
|
|
8
|
-
"jsx": "react-jsx",
|
|
9
|
-
"allowJs": true,
|
|
10
|
-
"types": ["bun"],
|
|
11
|
-
|
|
12
|
-
// Bundler mode
|
|
13
|
-
"moduleResolution": "bundler",
|
|
14
|
-
"allowImportingTsExtensions": true,
|
|
15
|
-
"verbatimModuleSyntax": true,
|
|
16
|
-
"noEmit": true,
|
|
17
|
-
|
|
18
|
-
// Best practices
|
|
19
|
-
"strict": true,
|
|
20
|
-
"skipLibCheck": true,
|
|
21
|
-
"noFallthroughCasesInSwitch": true,
|
|
22
|
-
"noUncheckedIndexedAccess": true,
|
|
23
|
-
"noImplicitOverride": true,
|
|
24
|
-
|
|
25
|
-
// Some stricter flags (disabled by default)
|
|
26
|
-
"noUnusedLocals": false,
|
|
27
|
-
"noUnusedParameters": false,
|
|
28
|
-
"noPropertyAccessFromIndexSignature": false
|
|
29
|
-
}
|
|
30
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
// Environment setup & latest features
|
|
4
|
+
"lib": ["ESNext", "DOM"],
|
|
5
|
+
"target": "ESNext",
|
|
6
|
+
"module": "Preserve",
|
|
7
|
+
"moduleDetection": "force",
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
"types": ["bun"],
|
|
11
|
+
|
|
12
|
+
// Bundler mode
|
|
13
|
+
"moduleResolution": "bundler",
|
|
14
|
+
"allowImportingTsExtensions": true,
|
|
15
|
+
"verbatimModuleSyntax": true,
|
|
16
|
+
"noEmit": true,
|
|
17
|
+
|
|
18
|
+
// Best practices
|
|
19
|
+
"strict": true,
|
|
20
|
+
"skipLibCheck": true,
|
|
21
|
+
"noFallthroughCasesInSwitch": true,
|
|
22
|
+
"noUncheckedIndexedAccess": true,
|
|
23
|
+
"noImplicitOverride": true,
|
|
24
|
+
|
|
25
|
+
// Some stricter flags (disabled by default)
|
|
26
|
+
"noUnusedLocals": false,
|
|
27
|
+
"noUnusedParameters": false,
|
|
28
|
+
"noPropertyAccessFromIndexSignature": false
|
|
29
|
+
}
|
|
30
|
+
}
|