@fluixi/core 1.0.0-alpha.83 → 1.0.0-alpha.85

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 (182) hide show
  1. package/dist/cdn/core.global.js +2 -1
  2. package/dist/cli/generate.cjs +4117 -292
  3. package/dist/cli/generate.mjs +4122 -292
  4. package/dist/cli/index.cjs +4117 -292
  5. package/dist/cli/index.mjs +4122 -292
  6. package/dist/cli/run.cjs +63 -1
  7. package/dist/cli/run.mjs +39 -1
  8. package/dist/src/cdn/chunk-MDJLC3PE.mjs +830 -0
  9. package/dist/src/cdn/core.cjs +1365 -1
  10. package/dist/src/cdn/core.d.ts +3 -3
  11. package/dist/src/cdn/core.js +3 -3
  12. package/dist/src/cdn/core.mjs +642 -1
  13. package/dist/src/cdn/router-JYFZP3EZ.mjs +70 -0
  14. package/dist/src/index.cjs +1280 -1
  15. package/dist/src/index.d.ts.map +1 -1
  16. package/dist/src/index.js +1 -11
  17. package/dist/src/index.mjs +1393 -1
  18. package/dist/src/jsx-dev-runtime.cjs +26 -1
  19. package/dist/src/jsx-dev-runtime.mjs +24 -1
  20. package/dist/src/jsx-runtime.cjs +26 -1
  21. package/dist/src/jsx-runtime.js +0 -9
  22. package/dist/src/jsx-runtime.mjs +24 -1
  23. package/dist/src/lib/client/chunk-7IUN2FLI.mjs +133 -0
  24. package/dist/src/lib/client/index.cjs +956 -1
  25. package/dist/src/lib/client/index.d.ts +17 -6
  26. package/dist/src/lib/client/index.d.ts.map +1 -1
  27. package/dist/src/lib/client/index.js +26 -19
  28. package/dist/src/lib/client/index.mjs +222 -1
  29. package/dist/src/lib/client/router-NOFEMOEH.mjs +631 -0
  30. package/dist/src/lib/context/context.cjs +118 -1
  31. package/dist/src/lib/context/context.d.ts +19 -37
  32. package/dist/src/lib/context/context.d.ts.map +1 -1
  33. package/dist/src/lib/context/context.js +8 -45
  34. package/dist/src/lib/context/context.mjs +99 -1
  35. package/dist/src/lib/context/index.cjs +120 -1
  36. package/dist/src/lib/context/index.mjs +99 -1
  37. package/dist/src/lib/control-flow.cjs +35 -1
  38. package/dist/src/lib/control-flow.mjs +25 -1
  39. package/dist/src/lib/core.cjs +1279 -1
  40. package/dist/src/lib/core.d.ts +0 -2
  41. package/dist/src/lib/core.d.ts.map +1 -1
  42. package/dist/src/lib/core.js +14 -48
  43. package/dist/src/lib/core.mjs +1393 -1
  44. package/dist/src/lib/env/index.cjs +60 -1
  45. package/dist/src/lib/env/index.d.ts +5 -5
  46. package/dist/src/lib/env/index.js +5 -5
  47. package/dist/src/lib/env/index.mjs +39 -1
  48. package/dist/src/lib/i18n/index.cjs +108 -1
  49. package/dist/src/lib/i18n/index.d.ts +31 -10
  50. package/dist/src/lib/i18n/index.d.ts.map +1 -1
  51. package/dist/src/lib/i18n/index.js +31 -10
  52. package/dist/src/lib/i18n/index.mjs +88 -1
  53. package/dist/src/lib/index.cjs +633 -1
  54. package/dist/src/lib/index.d.ts +0 -2
  55. package/dist/src/lib/index.d.ts.map +1 -1
  56. package/dist/src/lib/index.js +5 -11
  57. package/dist/src/lib/index.mjs +721 -1
  58. package/dist/src/lib/isomorphic.cjs +85 -1
  59. package/dist/src/lib/isomorphic.d.ts +41 -8
  60. package/dist/src/lib/isomorphic.d.ts.map +1 -1
  61. package/dist/src/lib/isomorphic.js +38 -5
  62. package/dist/src/lib/isomorphic.mjs +64 -1
  63. package/dist/src/lib/jsx-runtime/index.cjs +21 -1
  64. package/dist/src/lib/jsx-runtime/index.d.ts +1 -1
  65. package/dist/src/lib/jsx-runtime/index.js +1 -11
  66. package/dist/src/lib/jsx-runtime/index.mjs +4 -1
  67. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.cjs +21 -1
  68. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.mjs +4 -1
  69. package/dist/src/lib/plugins/fluixi-routes-plugin.cjs +302 -8
  70. package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts +15 -1
  71. package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts.map +1 -1
  72. package/dist/src/lib/plugins/fluixi-routes-plugin.js +19 -5
  73. package/dist/src/lib/plugins/fluixi-routes-plugin.mjs +271 -8
  74. package/dist/src/lib/plugins/index.cjs +311 -8
  75. package/dist/src/lib/plugins/index.mjs +279 -8
  76. package/dist/src/lib/plugins/route-codegen.cjs +73 -8
  77. package/dist/src/lib/plugins/route-codegen.d.ts +0 -1
  78. package/dist/src/lib/plugins/route-codegen.d.ts.map +1 -1
  79. package/dist/src/lib/plugins/route-codegen.js +4 -5
  80. package/dist/src/lib/plugins/route-codegen.mjs +52 -8
  81. package/dist/src/lib/plugins/route-scanner.cjs +189 -1
  82. package/dist/src/lib/plugins/route-scanner.d.ts +1 -2
  83. package/dist/src/lib/plugins/route-scanner.d.ts.map +1 -1
  84. package/dist/src/lib/plugins/route-scanner.js +7 -8
  85. package/dist/src/lib/plugins/route-scanner.mjs +158 -1
  86. package/dist/src/lib/plugins/vite.cjs +27 -1
  87. package/dist/src/lib/plugins/vite.mjs +6 -1
  88. package/dist/src/lib/render/await.cjs +38 -1
  89. package/dist/src/lib/render/await.d.ts +18 -0
  90. package/dist/src/lib/render/await.d.ts.map +1 -1
  91. package/dist/src/lib/render/await.js +20 -2
  92. package/dist/src/lib/render/await.mjs +17 -1
  93. package/dist/src/lib/render/component.cjs +221 -1
  94. package/dist/src/lib/render/component.d.ts +3 -44
  95. package/dist/src/lib/render/component.d.ts.map +1 -1
  96. package/dist/src/lib/render/component.js +23 -55
  97. package/dist/src/lib/render/component.mjs +214 -1
  98. package/dist/src/lib/render/deferred.cjs +175 -1
  99. package/dist/src/lib/render/deferred.js +5 -5
  100. package/dist/src/lib/render/deferred.mjs +158 -1
  101. package/dist/src/lib/render/index.cjs +573 -1
  102. package/dist/src/lib/render/index.d.ts +3 -17
  103. package/dist/src/lib/render/index.d.ts.map +1 -1
  104. package/dist/src/lib/render/index.js +8 -22
  105. package/dist/src/lib/render/index.mjs +590 -1
  106. package/dist/src/lib/render/lazy.cjs +67 -1
  107. package/dist/src/lib/render/lazy.d.ts +22 -1
  108. package/dist/src/lib/render/lazy.d.ts.map +1 -1
  109. package/dist/src/lib/render/lazy.js +26 -5
  110. package/dist/src/lib/render/lazy.mjs +50 -1
  111. package/dist/src/lib/render/suspense.cjs +141 -1
  112. package/dist/src/lib/render/suspense.d.ts +40 -0
  113. package/dist/src/lib/render/suspense.d.ts.map +1 -1
  114. package/dist/src/lib/render/suspense.js +46 -6
  115. package/dist/src/lib/render/suspense.mjs +136 -1
  116. package/dist/src/lib/render/versions.cjs +35 -1
  117. package/dist/src/lib/render/versions.js +6 -6
  118. package/dist/src/lib/render/versions.mjs +14 -1
  119. package/dist/src/lib/router/data.cjs +230 -1
  120. package/dist/src/lib/router/data.d.ts +1 -13
  121. package/dist/src/lib/router/data.d.ts.map +1 -1
  122. package/dist/src/lib/router/data.js +0 -12
  123. package/dist/src/lib/router/data.mjs +214 -1
  124. package/dist/src/lib/router/index.cjs +709 -1
  125. package/dist/src/lib/router/index.d.ts +78 -23
  126. package/dist/src/lib/router/index.d.ts.map +1 -1
  127. package/dist/src/lib/router/index.js +161 -37
  128. package/dist/src/lib/router/index.mjs +722 -1
  129. package/dist/src/lib/router/transition.cjs +75 -0
  130. package/dist/src/lib/router/transition.d.ts +81 -0
  131. package/dist/src/lib/router/transition.d.ts.map +1 -0
  132. package/dist/src/lib/router/transition.js +136 -0
  133. package/dist/src/lib/router/transition.mjs +54 -0
  134. package/dist/src/lib/server/hydration.cjs +169 -1
  135. package/dist/src/lib/server/hydration.d.ts +15 -55
  136. package/dist/src/lib/server/hydration.d.ts.map +1 -1
  137. package/dist/src/lib/server/hydration.js +23 -62
  138. package/dist/src/lib/server/hydration.mjs +148 -1
  139. package/dist/src/lib/server/index.cjs +401 -11
  140. package/dist/src/lib/server/index.d.ts +30 -6
  141. package/dist/src/lib/server/index.d.ts.map +1 -1
  142. package/dist/src/lib/server/index.js +34 -11
  143. package/dist/src/lib/server/index.mjs +379 -11
  144. package/dist/src/lib/server/reactive.cjs +197 -1
  145. package/dist/src/lib/server/reactive.d.ts +18 -77
  146. package/dist/src/lib/server/reactive.d.ts.map +1 -1
  147. package/dist/src/lib/server/reactive.js +19 -78
  148. package/dist/src/lib/server/reactive.mjs +176 -1
  149. package/dist/src/lib/theme/index.cjs +110 -1
  150. package/dist/src/lib/theme/index.d.ts +19 -4
  151. package/dist/src/lib/theme/index.d.ts.map +1 -1
  152. package/dist/src/lib/theme/index.js +17 -2
  153. package/dist/src/lib/theme/index.mjs +89 -1
  154. package/dist/src/lib/utils/index.cjs +209 -1
  155. package/dist/src/lib/utils/index.d.ts +0 -93
  156. package/dist/src/lib/utils/index.d.ts.map +1 -1
  157. package/dist/src/lib/utils/index.js +0 -93
  158. package/dist/src/lib/utils/index.mjs +188 -1
  159. package/dist/src/routes.cjs +37 -1
  160. package/dist/src/routes.d.ts +1 -1
  161. package/dist/src/routes.js +2 -2
  162. package/dist/src/routes.mjs +17 -1
  163. package/dist/src/server.cjs +400 -11
  164. package/dist/src/server.d.ts +0 -1
  165. package/dist/src/server.d.ts.map +1 -1
  166. package/dist/src/server.js +0 -1
  167. package/dist/src/server.mjs +377 -11
  168. package/dist/src/utils.cjs +21 -1
  169. package/dist/src/utils.d.ts +1 -1
  170. package/dist/src/utils.js +1 -1
  171. package/dist/src/utils.mjs +4 -1
  172. package/dist/src/version.generated.cjs +26 -1
  173. package/dist/src/version.generated.d.ts +1 -1
  174. package/dist/src/version.generated.js +2 -2
  175. package/dist/src/version.generated.mjs +5 -1
  176. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  177. package/package.json +17 -16
  178. package/src/index.ts +2 -14
  179. package/dist/src/cdn/chunk-55BT3H6E.mjs +0 -1
  180. package/dist/src/cdn/router-5JJZBK4E.mjs +0 -1
  181. package/dist/src/lib/client/chunk-SM4WHBOP.mjs +0 -1
  182. package/dist/src/lib/client/router-IBD4WPQT.mjs +0 -1
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/lib/router/transition.ts
21
+ var transition_exports = {};
22
+ __export(transition_exports, {
23
+ prefersReducedMotion: () => prefersReducedMotion,
24
+ prepareComponents: () => prepareComponents,
25
+ runTransition: () => runTransition,
26
+ shouldAnimate: () => shouldAnimate,
27
+ supportsViewTransitions: () => supportsViewTransitions
28
+ });
29
+ module.exports = __toCommonJS(transition_exports);
30
+ function supportsViewTransitions() {
31
+ return typeof document !== "undefined" && typeof document.startViewTransition === "function";
32
+ }
33
+ function prefersReducedMotion() {
34
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
35
+ return false;
36
+ }
37
+ try {
38
+ return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
39
+ } catch {
40
+ return false;
41
+ }
42
+ }
43
+ function shouldAnimate(mode) {
44
+ return mode !== "none" && supportsViewTransitions() && !prefersReducedMotion();
45
+ }
46
+ function prepareComponents(components) {
47
+ const pending = [];
48
+ for (const component of components) {
49
+ const preload = component?.preload;
50
+ if (typeof preload === "function") {
51
+ try {
52
+ const result = preload();
53
+ if (result && typeof result.then === "function") {
54
+ pending.push(result.catch(() => void 0));
55
+ }
56
+ } catch {
57
+ }
58
+ }
59
+ }
60
+ return pending.length ? Promise.all(pending).then(() => void 0) : null;
61
+ }
62
+ function runTransition(mode, commit) {
63
+ if (!shouldAnimate(mode)) {
64
+ return Promise.resolve(commit()).then(() => void 0);
65
+ }
66
+ const start = document.startViewTransition;
67
+ try {
68
+ const transition = start.call(document, () => commit());
69
+ transition.finished?.catch(() => void 0);
70
+ transition.ready?.catch(() => void 0);
71
+ return transition.updateCallbackDone.catch(() => void 0);
72
+ } catch {
73
+ return Promise.resolve(commit()).then(() => void 0);
74
+ }
75
+ }
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Navigation presentation: preparing a route before it is shown, and handing the DOM
3
+ * swap to the browser's View Transition API when there is one.
4
+ *
5
+ * ## The lifecycle this replaces
6
+ *
7
+ * Navigation used to be one synchronous chain. `navigate()` pushed history, the core
8
+ * router recomputed the match and notified, the `Router` component wrote the match
9
+ * signal, and the render memo rebuilt the layer at the depth that changed. The old DOM
10
+ * came out at that moment: whether or not the new route had anything to put in its
11
+ * place:
12
+ *
13
+ * - a route with a `data` loader renders `null` until the resource resolves,
14
+ * - a `lazy()` route whose chunk is not loaded suspends to the nearest fallback.
15
+ *
16
+ * Both are an empty intermediate state with the old page already gone, which is what
17
+ * reads as a flash. It is not a paint-timing artifact and no animation would hide it.
18
+ *
19
+ * ## The lifecycle now
20
+ *
21
+ * navigation-start
22
+ * │ the match is computed, but not committed
23
+ * prepare
24
+ * │ every matched layer's module is loaded (`lazy().preload()`), so the
25
+ * │ component renders synchronously instead of suspending
26
+ * begin transition
27
+ * │ `document.startViewTransition`, when it applies
28
+ * commit
29
+ * │ the match signal is written and effects are flushed, inside the
30
+ * │ transition's callback, so the browser snapshots a settled DOM
31
+ * navigation-complete
32
+ *
33
+ * Nothing here delays anything. The commit happens as soon as preparation resolves; on
34
+ * a warm route that is the same tick it always was.
35
+ */
36
+ /** How a navigation should be presented. */
37
+ export type TransitionMode = 'auto' | 'none';
38
+ /**
39
+ * Whether this environment can animate a route swap.
40
+ *
41
+ * Read at call time rather than cached at module load: a test swaps the API in and out,
42
+ * and a cached answer would make the second case unreachable.
43
+ */
44
+ export declare function supportsViewTransitions(): boolean;
45
+ /**
46
+ * Whether the reader asked not to be animated.
47
+ *
48
+ * A stated preference outranks the app's configuration, so this is checked on every
49
+ * navigation rather than once: the setting can change while the page is open.
50
+ */
51
+ export declare function prefersReducedMotion(): boolean;
52
+ /** Whether this particular commit should go through a view transition. */
53
+ export declare function shouldAnimate(mode: TransitionMode): boolean;
54
+ /**
55
+ * Load what the next route needs to render without suspending.
56
+ *
57
+ * Only the route's own modules. Data loaders are deliberately left alone: the resource
58
+ * belongs to the layer's owner and is created when that layer renders, so calling the
59
+ * loader here would either run the request twice or require a cache this router does not
60
+ * own. See the note in the router on what that leaves.
61
+ *
62
+ * A module that fails to load resolves anyway. Preparation is an optimisation, and a
63
+ * rejected import should surface through the route's own error handling when it renders,
64
+ * not by leaving the navigation permanently pending.
65
+ */
66
+ export declare function prepareComponents(components: readonly unknown[]): Promise<void> | null;
67
+ /**
68
+ * Run `commit` inside a view transition, or directly when one does not apply.
69
+ *
70
+ * The callback is async because writing the match signal only queues the work: effects
71
+ * are scheduled, so the DOM is not settled when the write returns. `startViewTransition`
72
+ * waits for the returned promise before snapshotting the new state, so flushing inside
73
+ * it is what makes the browser compare two finished frames rather than one finished and
74
+ * one half-built.
75
+ *
76
+ * The returned promise resolves when the DOM has been updated, not when the animation
77
+ * ends. A caller waiting on navigation wants the former; blocking on the latter would
78
+ * make every navigation as slow as its animation.
79
+ */
80
+ export declare function runTransition(mode: TransitionMode, commit: () => void | Promise<void>): Promise<void>;
81
+ //# sourceMappingURL=transition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transition.d.ts","sourceRoot":"","sources":["../../../../src/lib/router/transition.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAcH,4CAA4C;AAC5C,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,CAAC;AAE7C;;;;;GAKG;AACH,wBAAgB,uBAAuB,IAAI,OAAO,CAMjD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,IAAI,OAAO,CAU9C;AAED,0EAA0E;AAC1E,wBAAgB,aAAa,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAE3D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,SAAS,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAqBtF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,cAAc,EACpB,MAAM,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GACjC,OAAO,CAAC,IAAI,CAAC,CAsBf"}
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Navigation presentation: preparing a route before it is shown, and handing the DOM
3
+ * swap to the browser's View Transition API when there is one.
4
+ *
5
+ * ## The lifecycle this replaces
6
+ *
7
+ * Navigation used to be one synchronous chain. `navigate()` pushed history, the core
8
+ * router recomputed the match and notified, the `Router` component wrote the match
9
+ * signal, and the render memo rebuilt the layer at the depth that changed. The old DOM
10
+ * came out at that moment: whether or not the new route had anything to put in its
11
+ * place:
12
+ *
13
+ * - a route with a `data` loader renders `null` until the resource resolves,
14
+ * - a `lazy()` route whose chunk is not loaded suspends to the nearest fallback.
15
+ *
16
+ * Both are an empty intermediate state with the old page already gone, which is what
17
+ * reads as a flash. It is not a paint-timing artifact and no animation would hide it.
18
+ *
19
+ * ## The lifecycle now
20
+ *
21
+ * navigation-start
22
+ * │ the match is computed, but not committed
23
+ * prepare
24
+ * │ every matched layer's module is loaded (`lazy().preload()`), so the
25
+ * │ component renders synchronously instead of suspending
26
+ * begin transition
27
+ * │ `document.startViewTransition`, when it applies
28
+ * commit
29
+ * │ the match signal is written and effects are flushed, inside the
30
+ * │ transition's callback, so the browser snapshots a settled DOM
31
+ * navigation-complete
32
+ *
33
+ * Nothing here delays anything. The commit happens as soon as preparation resolves; on
34
+ * a warm route that is the same tick it always was.
35
+ */
36
+ /**
37
+ * Whether this environment can animate a route swap.
38
+ *
39
+ * Read at call time rather than cached at module load: a test swaps the API in and out,
40
+ * and a cached answer would make the second case unreachable.
41
+ */
42
+ export function supportsViewTransitions() {
43
+ return (typeof document !== 'undefined' &&
44
+ typeof document
45
+ .startViewTransition === 'function');
46
+ }
47
+ /**
48
+ * Whether the reader asked not to be animated.
49
+ *
50
+ * A stated preference outranks the app's configuration, so this is checked on every
51
+ * navigation rather than once: the setting can change while the page is open.
52
+ */
53
+ export function prefersReducedMotion() {
54
+ if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') {
55
+ return false;
56
+ }
57
+ try {
58
+ return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
59
+ }
60
+ catch {
61
+ // A matchMedia that throws on an unknown query is not a reason to fail navigation.
62
+ return false;
63
+ }
64
+ }
65
+ /** Whether this particular commit should go through a view transition. */
66
+ export function shouldAnimate(mode) {
67
+ return mode !== 'none' && supportsViewTransitions() && !prefersReducedMotion();
68
+ }
69
+ /**
70
+ * Load what the next route needs to render without suspending.
71
+ *
72
+ * Only the route's own modules. Data loaders are deliberately left alone: the resource
73
+ * belongs to the layer's owner and is created when that layer renders, so calling the
74
+ * loader here would either run the request twice or require a cache this router does not
75
+ * own. See the note in the router on what that leaves.
76
+ *
77
+ * A module that fails to load resolves anyway. Preparation is an optimisation, and a
78
+ * rejected import should surface through the route's own error handling when it renders,
79
+ * not by leaving the navigation permanently pending.
80
+ */
81
+ export function prepareComponents(components) {
82
+ const pending = [];
83
+ for (const component of components) {
84
+ const preload = component
85
+ ?.preload;
86
+ if (typeof preload === 'function') {
87
+ try {
88
+ const result = preload();
89
+ if (result && typeof result.then === 'function') {
90
+ pending.push(result.catch(() => undefined));
91
+ }
92
+ }
93
+ catch {
94
+ // A preload that throws synchronously is the same as one that rejects.
95
+ }
96
+ }
97
+ }
98
+ // Null rather than a resolved promise: the caller commits synchronously when there is
99
+ // nothing to wait for, which keeps a warm navigation on the tick it was already on.
100
+ return pending.length ? Promise.all(pending).then(() => undefined) : null;
101
+ }
102
+ /**
103
+ * Run `commit` inside a view transition, or directly when one does not apply.
104
+ *
105
+ * The callback is async because writing the match signal only queues the work: effects
106
+ * are scheduled, so the DOM is not settled when the write returns. `startViewTransition`
107
+ * waits for the returned promise before snapshotting the new state, so flushing inside
108
+ * it is what makes the browser compare two finished frames rather than one finished and
109
+ * one half-built.
110
+ *
111
+ * The returned promise resolves when the DOM has been updated, not when the animation
112
+ * ends. A caller waiting on navigation wants the former; blocking on the latter would
113
+ * make every navigation as slow as its animation.
114
+ */
115
+ export function runTransition(mode, commit) {
116
+ if (!shouldAnimate(mode)) {
117
+ return Promise.resolve(commit()).then(() => undefined);
118
+ }
119
+ const start = document
120
+ .startViewTransition;
121
+ try {
122
+ const transition = start.call(document, () => commit());
123
+ // Swallow the rejections a skipped or interrupted transition produces. Both of
124
+ // these reject when the animation is cut short, by `skipTransition()`, by another
125
+ // navigation starting, or by the tab going to the background. The DOM update inside
126
+ // the callback still happened, so a navigation must not fail because an animation
127
+ // did not play, and an unobserved rejection here would surface as an unhandled one.
128
+ transition.finished?.catch(() => undefined);
129
+ transition.ready?.catch(() => undefined);
130
+ return transition.updateCallbackDone.catch(() => undefined);
131
+ }
132
+ catch {
133
+ // A browser that has the method but refuses the call still has to navigate.
134
+ return Promise.resolve(commit()).then(() => undefined);
135
+ }
136
+ }
@@ -0,0 +1,54 @@
1
+ // src/lib/router/transition.ts
2
+ function supportsViewTransitions() {
3
+ return typeof document !== "undefined" && typeof document.startViewTransition === "function";
4
+ }
5
+ function prefersReducedMotion() {
6
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
7
+ return false;
8
+ }
9
+ try {
10
+ return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
11
+ } catch {
12
+ return false;
13
+ }
14
+ }
15
+ function shouldAnimate(mode) {
16
+ return mode !== "none" && supportsViewTransitions() && !prefersReducedMotion();
17
+ }
18
+ function prepareComponents(components) {
19
+ const pending = [];
20
+ for (const component of components) {
21
+ const preload = component?.preload;
22
+ if (typeof preload === "function") {
23
+ try {
24
+ const result = preload();
25
+ if (result && typeof result.then === "function") {
26
+ pending.push(result.catch(() => void 0));
27
+ }
28
+ } catch {
29
+ }
30
+ }
31
+ }
32
+ return pending.length ? Promise.all(pending).then(() => void 0) : null;
33
+ }
34
+ function runTransition(mode, commit) {
35
+ if (!shouldAnimate(mode)) {
36
+ return Promise.resolve(commit()).then(() => void 0);
37
+ }
38
+ const start = document.startViewTransition;
39
+ try {
40
+ const transition = start.call(document, () => commit());
41
+ transition.finished?.catch(() => void 0);
42
+ transition.ready?.catch(() => void 0);
43
+ return transition.updateCallbackDone.catch(() => void 0);
44
+ } catch {
45
+ return Promise.resolve(commit()).then(() => void 0);
46
+ }
47
+ }
48
+ export {
49
+ prefersReducedMotion,
50
+ prepareComponents,
51
+ runTransition,
52
+ shouldAnimate,
53
+ supportsViewTransitions
54
+ };
@@ -1 +1,169 @@
1
- "use strict";var a=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var w=(t,n)=>{for(var e in n)a(t,e,{get:n[e],enumerable:!0})},x=(t,n,e,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of g(n))!m.call(t,o)&&o!==e&&a(t,o,{get:()=>n[o],enumerable:!(r=l(n,o))||r.enumerable});return t};var h=t=>x(a({},"__esModule",{value:!0}),t);var F={};w(F,{cleanupHydration:()=>y,clearHydrationData:()=>p,clearHydrationDataKey:()=>D,createHydratableResource:()=>M,deserializeHydrationData:()=>b,generateMarkerID:()=>v,getHydrationData:()=>s,hasHydrationData:()=>_,hydrationMarker:()=>E,hydrationMarkerEnd:()=>O,hydrationMarkerStart:()=>N,isClientEnvironment:()=>C,isHydrating:()=>f,isServerEnvironment:()=>k,serializeHydrationData:()=>I,setHydrating:()=>T,setHydrationData:()=>d,useHydrationData:()=>j});module.exports=h(F);var c=!1,i=new Map,H=0;function f(){return c}function T(t){c=t}function d(t,n){i.set(t,n)}function s(t){return i.get(t)}function _(t){return i.has(t)}function p(){i.clear()}function D(t){i.delete(t)}function I(){if(i.size===0)return"";let t=Object.fromEntries(i);return`<script type="application/json" id="__FLUIXI_HYDRATION__">${JSON.stringify(t)}<\/script>`}function b(){if(typeof window>"u")return!1;let t=document.getElementById("__FLUIXI_HYDRATION__");if(!t||t.getAttribute("type")!=="application/json")return!1;try{let n=t.textContent||"{}",e=JSON.parse(n);for(let[r,o]of Object.entries(e))i.set(r,o);return!0}catch(n){return console.error("Failed to deserialize hydration data:",n),!1}}function v(){return`h${H++}`}function E(t){return`<!--#${t}-->`}function N(t){return`<!--#${t}-->`}function O(t){return`<!--/${t}-->`}function M(t,n){return async()=>{if(f()||typeof window<"u"){let r=s(t);if(r!==void 0)return r}let e=await n();return typeof window>"u"&&d(t,e),e}}function j(t,n){let e=s(t);if(e!==void 0)return e;let r=typeof n=="function"?n():n;return typeof window>"u"&&d(t,r),r}function y(){if(typeof window>"u")return;let t=document.getElementById("__FLUIXI_HYDRATION__");t&&t.remove();let n=document.createTreeWalker(document.body,NodeFilter.SHOW_COMMENT,null),e=[],r;for(;r=n.nextNode();){let o=r,u=o.nodeValue||"";(u.startsWith("#")||u.startsWith("/"))&&e.push(o)}e.forEach(o=>o.remove()),p()}typeof window<"u"&&window.addEventListener("load",()=>{setTimeout(y,100)});function k(){return typeof window>"u"}function C(){return typeof window<"u"}
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/lib/server/hydration.ts
21
+ var hydration_exports = {};
22
+ __export(hydration_exports, {
23
+ cleanupHydration: () => cleanupHydration,
24
+ clearHydrationData: () => clearHydrationData,
25
+ clearHydrationDataKey: () => clearHydrationDataKey,
26
+ createHydratableResource: () => createHydratableResource,
27
+ deserializeHydrationData: () => deserializeHydrationData,
28
+ generateMarkerID: () => generateMarkerID,
29
+ getHydrationData: () => getHydrationData,
30
+ hasHydrationData: () => hasHydrationData,
31
+ hydrationMarker: () => hydrationMarker,
32
+ hydrationMarkerEnd: () => hydrationMarkerEnd,
33
+ hydrationMarkerStart: () => hydrationMarkerStart,
34
+ isClientEnvironment: () => isClientEnvironment,
35
+ isHydrating: () => isHydrating,
36
+ isServerEnvironment: () => isServerEnvironment,
37
+ serializeHydrationData: () => serializeHydrationData,
38
+ setHydrating: () => setHydrating,
39
+ setHydrationData: () => setHydrationData,
40
+ useHydrationData: () => useHydrationData
41
+ });
42
+ module.exports = __toCommonJS(hydration_exports);
43
+ var import_dom = require("@fluixi/dom");
44
+ var hydrating = false;
45
+ var hydrationDataMap = /* @__PURE__ */ new Map();
46
+ var markerCounter = 0;
47
+ function isHydrating() {
48
+ return hydrating;
49
+ }
50
+ function setHydrating(state) {
51
+ hydrating = state;
52
+ }
53
+ function setHydrationData(key, data) {
54
+ hydrationDataMap.set(key, data);
55
+ }
56
+ function getHydrationData(key) {
57
+ return hydrationDataMap.get(key);
58
+ }
59
+ function hasHydrationData(key) {
60
+ return hydrationDataMap.has(key);
61
+ }
62
+ function clearHydrationData() {
63
+ hydrationDataMap.clear();
64
+ }
65
+ function clearHydrationDataKey(key) {
66
+ hydrationDataMap.delete(key);
67
+ }
68
+ function serializeHydrationData() {
69
+ if (hydrationDataMap.size === 0) {
70
+ return "";
71
+ }
72
+ const data = Object.fromEntries(hydrationDataMap);
73
+ const json = JSON.stringify(data);
74
+ return `<script type="application/json" id="__FLUIXI_HYDRATION__">${json}<\/script>`;
75
+ }
76
+ function deserializeHydrationData() {
77
+ if (typeof window === "undefined") {
78
+ return false;
79
+ }
80
+ const script = document.getElementById("__FLUIXI_HYDRATION__");
81
+ if (!script || script.getAttribute("type") !== "application/json") {
82
+ return false;
83
+ }
84
+ try {
85
+ const json = script.textContent || "{}";
86
+ const data = JSON.parse(json);
87
+ for (const [key, value] of Object.entries(data)) {
88
+ hydrationDataMap.set(key, value);
89
+ }
90
+ return true;
91
+ } catch (error) {
92
+ console.error("Failed to deserialize hydration data:", error);
93
+ return false;
94
+ }
95
+ }
96
+ function generateMarkerID() {
97
+ return `h${markerCounter++}`;
98
+ }
99
+ function hydrationMarker(id) {
100
+ return `<!--#${id}-->`;
101
+ }
102
+ function hydrationMarkerStart(id) {
103
+ return `<!--#${id}-->`;
104
+ }
105
+ function hydrationMarkerEnd(id) {
106
+ return `<!--/${id}-->`;
107
+ }
108
+ function createHydratableResource(key, fetcher) {
109
+ return async () => {
110
+ if (isHydrating() || typeof window !== "undefined") {
111
+ const cached = getHydrationData(key);
112
+ if (cached !== void 0) {
113
+ return cached;
114
+ }
115
+ }
116
+ const data = await fetcher();
117
+ if (typeof window === "undefined") {
118
+ setHydrationData(key, data);
119
+ }
120
+ return data;
121
+ };
122
+ }
123
+ function useHydrationData(key, value) {
124
+ const hydrationData = getHydrationData(key);
125
+ if (hydrationData !== void 0) {
126
+ return hydrationData;
127
+ }
128
+ const computedValue = typeof value === "function" ? value() : value;
129
+ if (typeof window === "undefined") {
130
+ setHydrationData(key, computedValue);
131
+ }
132
+ return computedValue;
133
+ }
134
+ function cleanupHydration() {
135
+ if (typeof window === "undefined") {
136
+ return;
137
+ }
138
+ const script = document.getElementById("__FLUIXI_HYDRATION__");
139
+ if (script) {
140
+ script.remove();
141
+ }
142
+ const walker = document.createTreeWalker(
143
+ document.body,
144
+ NodeFilter.SHOW_COMMENT,
145
+ null
146
+ );
147
+ const comments = [];
148
+ let node;
149
+ while (node = walker.nextNode()) {
150
+ const comment = node;
151
+ const text = comment.nodeValue || "";
152
+ if (text.startsWith("#") || text.startsWith("/")) {
153
+ comments.push(comment);
154
+ }
155
+ }
156
+ comments.forEach((comment) => comment.remove());
157
+ clearHydrationData();
158
+ }
159
+ if (typeof window !== "undefined") {
160
+ window.addEventListener("load", () => {
161
+ setTimeout(cleanupHydration, 100);
162
+ });
163
+ }
164
+ function isServerEnvironment() {
165
+ return (0, import_dom.isServer)();
166
+ }
167
+ function isClientEnvironment() {
168
+ return !(0, import_dom.isServer)();
169
+ }