kenspeckle 0.1.3 → 0.1.4

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.
@@ -2,6 +2,8 @@
2
2
  export interface Navigation {
3
3
  complete: Promise<void>;
4
4
  type?: string;
5
+ /** Optional because SvelteKit 2 has no such field; only Kit 3 reports it. */
6
+ shallow?: boolean;
5
7
  delta?: number | null;
6
8
  from?: {
7
9
  url: URL;
@@ -25,30 +25,39 @@ export function isRetreat(navigation) {
25
25
  }
26
26
  /** @internal — the handler `viewTransition()` registers, exported so it is testable without a component. */
27
27
  export function navigationTransition({ onStart, onSettle, ...rest } = {}) {
28
- return (navigation) => new Promise((resolve) => {
29
- let transitioning = false;
30
- runViewTransition(async () => {
31
- // resolve() BEFORE awaiting breaks a mutual wait: Kit holds the navigation until this
32
- // promise settles, the browser holds the snapshot until the callback settles.
33
- resolve();
34
- await navigation.complete;
35
- if (transitioning)
36
- beginPhase(navigation, 'arrival');
37
- }, {
38
- ...rest,
39
- state: isRetreat(navigation) ? 'retreat' : 'forward',
40
- onStart: () => {
41
- transitioning = true;
42
- beginPhase(navigation, 'capture');
43
- onStart?.(navigation);
44
- },
45
- onSettle: () => {
46
- transitioning = false;
47
- endTransition();
48
- onSettle?.();
49
- }
28
+ return (navigation) => {
29
+ // SvelteKit 3 fires onNavigate for a shallow navigation; Kit 2 never did. The route is
30
+ // unchanged, so there is no arrival to cross-fade to, and holding the navigation suspends
31
+ // rendering — a call site that strips a query param and then calls window.print()
32
+ // synchronously would print a suspended page. A consumer who does want a shallow change
33
+ // animated has `viewTransition(update)`, which says so at the call site.
34
+ if (navigation.shallow)
35
+ return Promise.resolve();
36
+ return new Promise((resolve) => {
37
+ let transitioning = false;
38
+ runViewTransition(async () => {
39
+ // resolve() BEFORE awaiting breaks a mutual wait: Kit holds the navigation until this
40
+ // promise settles, the browser holds the snapshot until the callback settles.
41
+ resolve();
42
+ await navigation.complete;
43
+ if (transitioning)
44
+ beginPhase(navigation, 'arrival');
45
+ }, {
46
+ ...rest,
47
+ state: isRetreat(navigation) ? 'retreat' : 'forward',
48
+ onStart: () => {
49
+ transitioning = true;
50
+ beginPhase(navigation, 'capture');
51
+ onStart?.(navigation);
52
+ },
53
+ onSettle: () => {
54
+ transitioning = false;
55
+ endTransition();
56
+ onSettle?.();
57
+ }
58
+ });
50
59
  });
51
- });
60
+ };
52
61
  }
53
62
  export function viewTransition(first, second) {
54
63
  if (typeof first === 'function')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kenspeckle",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Svelte 5 utilities under one naming convention: attachments first-class, view transitions, and a state machine with context.",
5
5
  "license": "MIT",
6
6
  "author": "Brandon Pittman <brandon@brandonpittman.com>",
@@ -51,7 +51,7 @@
51
51
  },
52
52
  "peerDependencies": {
53
53
  "svelte": "^5.40.0",
54
- "@sveltejs/kit": "^2.0.0"
54
+ "@sveltejs/kit": "^2.0.0 || ^3.0.0-next.0"
55
55
  },
56
56
  "peerDependenciesMeta": {
57
57
  "@sveltejs/kit": {