@ssgoi/svelte 7.0.4 → 7.1.0-beta.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/sveltekit/index.d.ts +2 -0
- package/dist/sveltekit/index.js +1 -0
- package/dist/sveltekit/ssgoi-route-boundary.svelte +61 -0
- package/dist/sveltekit/ssgoi-route-boundary.svelte.d.ts +4 -0
- package/dist/sveltekit/types.d.ts +16 -0
- package/dist/sveltekit/types.js +1 -0
- package/package.json +19 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as SsgoiRouteBoundary } from "./ssgoi-route-boundary.svelte";
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onNavigate } from "$app/navigation";
|
|
3
|
+
// Stores work throughout SvelteKit 2, including releases before $app/state.
|
|
4
|
+
import { page } from "$app/stores";
|
|
5
|
+
import { flushSync, onDestroy, untrack } from "svelte";
|
|
6
|
+
import type { SsgoiRouteBoundaryProps } from "./types.js";
|
|
7
|
+
|
|
8
|
+
let {
|
|
9
|
+
children,
|
|
10
|
+
as = "div",
|
|
11
|
+
routeKey,
|
|
12
|
+
resolve,
|
|
13
|
+
...rest
|
|
14
|
+
}: SsgoiRouteBoundaryProps = $props();
|
|
15
|
+
|
|
16
|
+
const getBoundary = (url: URL) => {
|
|
17
|
+
const boundary = resolve?.({ pathname: url.pathname, url }) ?? {
|
|
18
|
+
id: url.pathname,
|
|
19
|
+
};
|
|
20
|
+
return { id: boundary.id, key: routeKey ?? boundary.key ?? boundary.id };
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
let current = $state(untrack(() => getBoundary($page.url)));
|
|
24
|
+
let mounted = $state(true);
|
|
25
|
+
let alive = true;
|
|
26
|
+
|
|
27
|
+
onDestroy(() => {
|
|
28
|
+
alive = false;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
onNavigate((navigation) => {
|
|
32
|
+
if (!alive || !navigation.to) return;
|
|
33
|
+
const next = getBoundary(navigation.to.url);
|
|
34
|
+
|
|
35
|
+
if (next.key === current.key) {
|
|
36
|
+
// A persistent shell keeps its DOM, but its outgoing id must stay current.
|
|
37
|
+
return () => {
|
|
38
|
+
if (alive) current = next;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Detach before Kit updates its live children snippet, preserving real OUT DOM.
|
|
43
|
+
flushSync(() => {
|
|
44
|
+
mounted = false;
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return () => {
|
|
48
|
+
if (!alive) return;
|
|
49
|
+
flushSync(() => {
|
|
50
|
+
current = next;
|
|
51
|
+
mounted = true;
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
{#if mounted}
|
|
58
|
+
<svelte:element this={as} {...rest} data-ssgoi-transition={current.id}>
|
|
59
|
+
{@render children()}
|
|
60
|
+
</svelte:element>
|
|
61
|
+
{/if}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
3
|
+
export interface RouteBoundaryState {
|
|
4
|
+
id: string;
|
|
5
|
+
key?: string | number;
|
|
6
|
+
}
|
|
7
|
+
export interface SveltekitRouteLocation {
|
|
8
|
+
pathname: string;
|
|
9
|
+
url: URL;
|
|
10
|
+
}
|
|
11
|
+
export interface SsgoiRouteBoundaryProps extends HTMLAttributes<HTMLElement> {
|
|
12
|
+
children: Snippet;
|
|
13
|
+
as?: keyof HTMLElementTagNameMap;
|
|
14
|
+
routeKey?: string | number;
|
|
15
|
+
resolve?: (location: SveltekitRouteLocation) => RouteBoundaryState;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ssgoi/svelte",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.1.0-beta.0",
|
|
4
4
|
"description": "Svelte bindings for SSGOI - Native app-like page transitions for Svelte and SvelteKit applications",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -14,10 +14,11 @@
|
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ssgoi/core": "^7.0.
|
|
17
|
+
"@ssgoi/core": "^7.1.0-beta.0"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"svelte": "^5.0.0"
|
|
20
|
+
"svelte": "^5.0.0",
|
|
21
|
+
"@sveltejs/kit": "*"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
23
24
|
"@eslint/compat": "^1.2.5",
|
|
@@ -37,7 +38,9 @@
|
|
|
37
38
|
"svelte-check": "^4.0.0",
|
|
38
39
|
"typescript": "^5.0.0",
|
|
39
40
|
"typescript-eslint": "^8.20.0",
|
|
40
|
-
"vite": "^6.2.6"
|
|
41
|
+
"vite": "^6.2.6",
|
|
42
|
+
"vitest": "^3.2.4",
|
|
43
|
+
"jsdom": "^26.1.0"
|
|
41
44
|
},
|
|
42
45
|
"keywords": [
|
|
43
46
|
"svelte",
|
|
@@ -86,12 +89,23 @@
|
|
|
86
89
|
"types": "./dist/view-transitions.d.ts",
|
|
87
90
|
"svelte": "./dist/view-transitions.js",
|
|
88
91
|
"import": "./dist/view-transitions.js"
|
|
92
|
+
},
|
|
93
|
+
"./sveltekit": {
|
|
94
|
+
"types": "./dist/sveltekit/index.d.ts",
|
|
95
|
+
"svelte": "./dist/sveltekit/index.js",
|
|
96
|
+
"import": "./dist/sveltekit/index.js"
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
"peerDependenciesMeta": {
|
|
100
|
+
"@sveltejs/kit": {
|
|
101
|
+
"optional": true
|
|
89
102
|
}
|
|
90
103
|
},
|
|
91
104
|
"scripts": {
|
|
92
105
|
"watch": "svelte-package --watch",
|
|
93
106
|
"build": "svelte-package",
|
|
94
107
|
"format": "prettier --write .",
|
|
95
|
-
"lint": "prettier --check . && eslint ."
|
|
108
|
+
"lint": "prettier --check . && eslint .",
|
|
109
|
+
"test:run": "vitest run"
|
|
96
110
|
}
|
|
97
111
|
}
|