@multiplatform.one/router 9.16.1 → 10.0.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.
Files changed (250) hide show
  1. package/dist/cjs/hooks/index.cjs +17 -19
  2. package/dist/cjs/hooks/index.native.cjs +31 -0
  3. package/dist/cjs/hooks/index.native.js +17 -18
  4. package/dist/cjs/hooks/index.native.js.map +1 -1
  5. package/dist/cjs/hooks/useUrlState.cjs +175 -180
  6. package/dist/cjs/hooks/useUrlState.native.cjs +215 -0
  7. package/dist/cjs/hooks/useUrlState.native.js +187 -196
  8. package/dist/cjs/hooks/useUrlState.native.js.map +1 -1
  9. package/dist/cjs/index.cjs +9 -11
  10. package/dist/cjs/index.native.cjs +22 -0
  11. package/dist/cjs/index.native.js +9 -10
  12. package/dist/cjs/index.native.js.map +1 -1
  13. package/dist/cjs/index.storybook.cjs +17 -19
  14. package/dist/cjs/index.storybook.native.cjs +34 -0
  15. package/dist/cjs/index.storybook.native.js +17 -18
  16. package/dist/cjs/index.storybook.native.js.map +1 -1
  17. package/dist/cjs/router/EmptyRouter.cjs +51 -58
  18. package/dist/cjs/router/EmptyRouter.native.cjs +98 -0
  19. package/dist/cjs/router/EmptyRouter.native.js +72 -78
  20. package/dist/cjs/router/EmptyRouter.native.js.map +1 -1
  21. package/dist/cjs/router/ReactRouter.cjs +72 -87
  22. package/dist/cjs/router/ReactRouter.native.cjs +119 -0
  23. package/dist/cjs/router/ReactRouter.native.js +95 -109
  24. package/dist/cjs/router/ReactRouter.native.js.map +1 -1
  25. package/dist/cjs/router/binding.cjs +18 -20
  26. package/dist/cjs/router/binding.native.cjs +35 -0
  27. package/dist/cjs/router/binding.native.js +18 -19
  28. package/dist/cjs/router/binding.native.js.map +1 -1
  29. package/dist/cjs/router/expoRouter.cjs +22 -26
  30. package/dist/cjs/router/expoRouter.native.cjs +45 -0
  31. package/dist/cjs/router/expoRouter.native.js +22 -25
  32. package/dist/cjs/router/expoRouter.native.js.map +1 -1
  33. package/dist/cjs/router/expoRouterBinding.cjs +35 -39
  34. package/dist/cjs/router/expoRouterBinding.native.cjs +61 -0
  35. package/dist/cjs/router/expoRouterBinding.native.js +43 -46
  36. package/dist/cjs/router/expoRouterBinding.native.js.map +1 -1
  37. package/dist/cjs/router/index.cjs +17 -19
  38. package/dist/cjs/router/index.native.cjs +51 -0
  39. package/dist/cjs/router/index.native.js +28 -29
  40. package/dist/cjs/router/index.native.js.map +1 -1
  41. package/dist/cjs/router/index.storybook-expo.cjs +9 -11
  42. package/dist/cjs/router/index.storybook-expo.native.cjs +20 -0
  43. package/dist/cjs/router/index.storybook-expo.native.js +9 -10
  44. package/dist/cjs/router/index.storybook-expo.native.js.map +1 -1
  45. package/dist/cjs/router/index.storybook.cjs +9 -11
  46. package/dist/cjs/router/index.storybook.native.cjs +20 -0
  47. package/dist/cjs/router/index.storybook.native.js +9 -10
  48. package/dist/cjs/router/index.storybook.native.js.map +1 -1
  49. package/dist/cjs/router/index.webext.cjs +9 -11
  50. package/dist/cjs/router/index.webext.native.cjs +20 -0
  51. package/dist/cjs/router/index.webext.native.js +9 -10
  52. package/dist/cjs/router/index.webext.native.js.map +1 -1
  53. package/dist/cjs/router/nativeRouter.cjs +33 -41
  54. package/dist/cjs/router/nativeRouter.native.cjs +72 -0
  55. package/dist/cjs/router/nativeRouter.native.js +42 -49
  56. package/dist/cjs/router/nativeRouter.native.js.map +1 -1
  57. package/dist/cjs/seam/DomNavigationHost.cjs +138 -150
  58. package/dist/cjs/seam/DomNavigationHost.native.cjs +233 -0
  59. package/dist/cjs/seam/DomNavigationHost.native.js +201 -207
  60. package/dist/cjs/seam/DomNavigationHost.native.js.map +1 -1
  61. package/dist/cjs/seam/index.cjs +31 -33
  62. package/dist/cjs/seam/index.native.cjs +47 -0
  63. package/dist/cjs/seam/index.native.js +31 -32
  64. package/dist/cjs/seam/index.native.js.map +1 -1
  65. package/dist/cjs/seam/navigator.cjs +309 -319
  66. package/dist/cjs/seam/navigator.native.cjs +525 -0
  67. package/dist/cjs/seam/navigator.native.js +490 -498
  68. package/dist/cjs/seam/navigator.native.js.map +1 -1
  69. package/dist/cjs/seam/oneAdapter.cjs +86 -93
  70. package/dist/cjs/seam/oneAdapter.native.cjs +133 -0
  71. package/dist/cjs/seam/oneAdapter.native.js +94 -104
  72. package/dist/cjs/seam/oneAdapter.native.js.map +1 -1
  73. package/dist/cjs/types.cjs +9 -11
  74. package/dist/cjs/types.native.cjs +18 -0
  75. package/dist/cjs/types.native.js +9 -10
  76. package/dist/cjs/types.native.js.map +1 -1
  77. package/dist/esm/hooks/index.mjs +3 -3
  78. package/dist/esm/hooks/index.native.js +3 -3
  79. package/dist/esm/hooks/useUrlState.mjs +160 -161
  80. package/dist/esm/hooks/useUrlState.mjs.map +1 -1
  81. package/dist/esm/hooks/useUrlState.native.js +171 -177
  82. package/dist/esm/hooks/useUrlState.native.js.map +1 -1
  83. package/dist/esm/index.mjs +5 -4
  84. package/dist/esm/index.native.js +5 -4
  85. package/dist/esm/index.storybook.mjs +7 -5
  86. package/dist/esm/index.storybook.native.js +7 -5
  87. package/dist/esm/router/EmptyRouter.mjs +35 -38
  88. package/dist/esm/router/EmptyRouter.mjs.map +1 -1
  89. package/dist/esm/router/EmptyRouter.native.js +57 -60
  90. package/dist/esm/router/EmptyRouter.native.js.map +1 -1
  91. package/dist/esm/router/ReactRouter.mjs +59 -70
  92. package/dist/esm/router/ReactRouter.mjs.map +1 -1
  93. package/dist/esm/router/ReactRouter.native.js +82 -93
  94. package/dist/esm/router/ReactRouter.native.js.map +1 -1
  95. package/dist/esm/router/binding.mjs +4 -3
  96. package/dist/esm/router/binding.mjs.map +1 -1
  97. package/dist/esm/router/binding.native.js +4 -3
  98. package/dist/esm/router/binding.native.js.map +1 -1
  99. package/dist/esm/router/expoRouter.mjs +7 -7
  100. package/dist/esm/router/expoRouter.mjs.map +1 -1
  101. package/dist/esm/router/expoRouter.native.js +7 -7
  102. package/dist/esm/router/expoRouter.native.js.map +1 -1
  103. package/dist/esm/router/expoRouterBinding.mjs +23 -21
  104. package/dist/esm/router/expoRouterBinding.mjs.map +1 -1
  105. package/dist/esm/router/expoRouterBinding.native.js +31 -29
  106. package/dist/esm/router/expoRouterBinding.native.js.map +1 -1
  107. package/dist/esm/router/index.mjs +2 -2
  108. package/dist/esm/router/index.native.js +13 -11
  109. package/dist/esm/router/index.native.js.map +1 -1
  110. package/dist/esm/router/index.storybook-expo.mjs +1 -2
  111. package/dist/esm/router/index.storybook-expo.native.js +1 -2
  112. package/dist/esm/router/index.storybook.mjs +1 -2
  113. package/dist/esm/router/index.storybook.native.js +1 -2
  114. package/dist/esm/router/index.webext.mjs +1 -2
  115. package/dist/esm/router/index.webext.native.js +1 -2
  116. package/dist/esm/router/nativeRouter.mjs +19 -23
  117. package/dist/esm/router/nativeRouter.mjs.map +1 -1
  118. package/dist/esm/router/nativeRouter.native.js +29 -33
  119. package/dist/esm/router/nativeRouter.native.js.map +1 -1
  120. package/dist/esm/seam/DomNavigationHost.mjs +125 -133
  121. package/dist/esm/seam/DomNavigationHost.mjs.map +1 -1
  122. package/dist/esm/seam/DomNavigationHost.native.js +189 -192
  123. package/dist/esm/seam/DomNavigationHost.native.js.map +1 -1
  124. package/dist/esm/seam/index.mjs +2 -2
  125. package/dist/esm/seam/index.native.js +2 -2
  126. package/dist/esm/seam/navigator.mjs +292 -298
  127. package/dist/esm/seam/navigator.mjs.map +1 -1
  128. package/dist/esm/seam/navigator.native.js +473 -478
  129. package/dist/esm/seam/navigator.native.js.map +1 -1
  130. package/dist/esm/seam/oneAdapter.mjs +61 -64
  131. package/dist/esm/seam/oneAdapter.mjs.map +1 -1
  132. package/dist/esm/seam/oneAdapter.native.js +70 -77
  133. package/dist/esm/seam/oneAdapter.native.js.map +1 -1
  134. package/dist/esm/types.mjs +0 -2
  135. package/dist/esm/types.native.js +0 -2
  136. package/dist/jsx/hooks/index.mjs +3 -3
  137. package/dist/jsx/hooks/index.native.cjs +31 -0
  138. package/dist/jsx/hooks/index.native.js +17 -18
  139. package/dist/jsx/hooks/index.native.js.map +1 -1
  140. package/dist/jsx/hooks/useUrlState.mjs +160 -161
  141. package/dist/jsx/hooks/useUrlState.mjs.map +1 -1
  142. package/dist/jsx/hooks/useUrlState.native.cjs +215 -0
  143. package/dist/jsx/hooks/useUrlState.native.js +187 -196
  144. package/dist/jsx/hooks/useUrlState.native.js.map +1 -1
  145. package/dist/jsx/index.js +5 -4
  146. package/dist/jsx/index.mjs +5 -4
  147. package/dist/jsx/index.native.cjs +22 -0
  148. package/dist/jsx/index.native.js +9 -10
  149. package/dist/jsx/index.native.js.map +1 -1
  150. package/dist/jsx/index.storybook.mjs +7 -5
  151. package/dist/jsx/index.storybook.native.cjs +34 -0
  152. package/dist/jsx/index.storybook.native.js +17 -18
  153. package/dist/jsx/index.storybook.native.js.map +1 -1
  154. package/dist/jsx/router/EmptyRouter.mjs +35 -38
  155. package/dist/jsx/router/EmptyRouter.mjs.map +1 -1
  156. package/dist/jsx/router/EmptyRouter.native.cjs +98 -0
  157. package/dist/jsx/router/EmptyRouter.native.js +72 -78
  158. package/dist/jsx/router/EmptyRouter.native.js.map +1 -1
  159. package/dist/jsx/router/ReactRouter.mjs +59 -70
  160. package/dist/jsx/router/ReactRouter.mjs.map +1 -1
  161. package/dist/jsx/router/ReactRouter.native.cjs +119 -0
  162. package/dist/jsx/router/ReactRouter.native.js +95 -109
  163. package/dist/jsx/router/ReactRouter.native.js.map +1 -1
  164. package/dist/jsx/router/binding.mjs +4 -3
  165. package/dist/jsx/router/binding.mjs.map +1 -1
  166. package/dist/jsx/router/binding.native.cjs +35 -0
  167. package/dist/jsx/router/binding.native.js +18 -19
  168. package/dist/jsx/router/binding.native.js.map +1 -1
  169. package/dist/jsx/router/expoRouter.mjs +7 -7
  170. package/dist/jsx/router/expoRouter.mjs.map +1 -1
  171. package/dist/jsx/router/expoRouter.native.cjs +45 -0
  172. package/dist/jsx/router/expoRouter.native.js +22 -25
  173. package/dist/jsx/router/expoRouter.native.js.map +1 -1
  174. package/dist/jsx/router/expoRouterBinding.mjs +23 -21
  175. package/dist/jsx/router/expoRouterBinding.mjs.map +1 -1
  176. package/dist/jsx/router/expoRouterBinding.native.cjs +61 -0
  177. package/dist/jsx/router/expoRouterBinding.native.js +43 -46
  178. package/dist/jsx/router/expoRouterBinding.native.js.map +1 -1
  179. package/dist/jsx/router/index.mjs +2 -2
  180. package/dist/jsx/router/index.native.cjs +51 -0
  181. package/dist/jsx/router/index.native.js +28 -29
  182. package/dist/jsx/router/index.native.js.map +1 -1
  183. package/dist/jsx/router/index.storybook-expo.mjs +1 -2
  184. package/dist/jsx/router/index.storybook-expo.native.cjs +20 -0
  185. package/dist/jsx/router/index.storybook-expo.native.js +9 -10
  186. package/dist/jsx/router/index.storybook-expo.native.js.map +1 -1
  187. package/dist/jsx/router/index.storybook.mjs +1 -2
  188. package/dist/jsx/router/index.storybook.native.cjs +20 -0
  189. package/dist/jsx/router/index.storybook.native.js +9 -10
  190. package/dist/jsx/router/index.storybook.native.js.map +1 -1
  191. package/dist/jsx/router/index.webext.mjs +1 -2
  192. package/dist/jsx/router/index.webext.native.cjs +20 -0
  193. package/dist/jsx/router/index.webext.native.js +9 -10
  194. package/dist/jsx/router/index.webext.native.js.map +1 -1
  195. package/dist/jsx/router/nativeRouter.mjs +19 -23
  196. package/dist/jsx/router/nativeRouter.mjs.map +1 -1
  197. package/dist/jsx/router/nativeRouter.native.cjs +72 -0
  198. package/dist/jsx/router/nativeRouter.native.js +42 -49
  199. package/dist/jsx/router/nativeRouter.native.js.map +1 -1
  200. package/dist/jsx/seam/DomNavigationHost.mjs +125 -133
  201. package/dist/jsx/seam/DomNavigationHost.mjs.map +1 -1
  202. package/dist/jsx/seam/DomNavigationHost.native.cjs +233 -0
  203. package/dist/jsx/seam/DomNavigationHost.native.js +201 -207
  204. package/dist/jsx/seam/DomNavigationHost.native.js.map +1 -1
  205. package/dist/jsx/seam/index.mjs +2 -2
  206. package/dist/jsx/seam/index.native.cjs +47 -0
  207. package/dist/jsx/seam/index.native.js +31 -32
  208. package/dist/jsx/seam/index.native.js.map +1 -1
  209. package/dist/jsx/seam/navigator.mjs +292 -298
  210. package/dist/jsx/seam/navigator.mjs.map +1 -1
  211. package/dist/jsx/seam/navigator.native.cjs +525 -0
  212. package/dist/jsx/seam/navigator.native.js +490 -498
  213. package/dist/jsx/seam/navigator.native.js.map +1 -1
  214. package/dist/jsx/seam/oneAdapter.mjs +61 -64
  215. package/dist/jsx/seam/oneAdapter.mjs.map +1 -1
  216. package/dist/jsx/seam/oneAdapter.native.cjs +133 -0
  217. package/dist/jsx/seam/oneAdapter.native.js +94 -104
  218. package/dist/jsx/seam/oneAdapter.native.js.map +1 -1
  219. package/dist/jsx/types.mjs +0 -2
  220. package/dist/jsx/types.native.cjs +18 -0
  221. package/dist/jsx/types.native.js +9 -10
  222. package/dist/jsx/types.native.js.map +1 -1
  223. package/package.json +14 -14
  224. package/dist/esm/hooks/index.mjs.map +0 -1
  225. package/dist/esm/hooks/index.native.js.map +0 -1
  226. package/dist/esm/index.mjs.map +0 -1
  227. package/dist/esm/index.native.js.map +0 -1
  228. package/dist/esm/index.storybook.mjs.map +0 -1
  229. package/dist/esm/index.storybook.native.js.map +0 -1
  230. package/dist/esm/router/index.mjs.map +0 -1
  231. package/dist/esm/router/index.storybook-expo.mjs.map +0 -1
  232. package/dist/esm/router/index.storybook-expo.native.js.map +0 -1
  233. package/dist/esm/router/index.storybook.mjs.map +0 -1
  234. package/dist/esm/router/index.storybook.native.js.map +0 -1
  235. package/dist/esm/router/index.webext.mjs.map +0 -1
  236. package/dist/esm/router/index.webext.native.js.map +0 -1
  237. package/dist/esm/seam/index.mjs.map +0 -1
  238. package/dist/esm/seam/index.native.js.map +0 -1
  239. package/dist/esm/types.mjs.map +0 -1
  240. package/dist/esm/types.native.js.map +0 -1
  241. package/dist/jsx/hooks/index.mjs.map +0 -1
  242. package/dist/jsx/index.js.map +0 -1
  243. package/dist/jsx/index.mjs.map +0 -1
  244. package/dist/jsx/index.storybook.mjs.map +0 -1
  245. package/dist/jsx/router/index.mjs.map +0 -1
  246. package/dist/jsx/router/index.storybook-expo.mjs.map +0 -1
  247. package/dist/jsx/router/index.storybook.mjs.map +0 -1
  248. package/dist/jsx/router/index.webext.mjs.map +0 -1
  249. package/dist/jsx/seam/index.mjs.map +0 -1
  250. package/dist/jsx/types.mjs.map +0 -1
@@ -3,342 +3,332 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
5
  var __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: true
9
- });
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
10
  };
11
11
  var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
- get: () => from[key],
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- });
17
- }
18
- return to;
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
19
  };
20
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
- value: true
22
- }), mod);
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
21
  var navigator_exports = {};
24
22
  __export(navigator_exports, {
25
- RouteTagContext: () => RouteTagContext,
26
- StackNavigator: () => StackNavigator,
27
- hrefToString: () => hrefToString,
28
- stackNavigator: () => stackNavigator,
29
- useNavState: () => useNavState,
30
- useRouteParams: () => useRouteParams
23
+ RouteTagContext: () => RouteTagContext,
24
+ StackNavigator: () => StackNavigator,
25
+ hrefToString: () => hrefToString,
26
+ stackNavigator: () => stackNavigator,
27
+ useNavState: () => useNavState,
28
+ useRouteParams: () => useRouteParams
31
29
  });
32
30
  module.exports = __toCommonJS(navigator_exports);
33
31
  var import_react = require("react");
34
32
  function compileRoute(def) {
35
- const segments = def.pattern.split("/").filter(Boolean).map(seg => {
36
- const m = seg.match(/^\[(\.{3})?(.+)\]$/);
37
- return m ? {
38
- param: m[2]
39
- } : {
40
- literal: seg
41
- };
42
- });
43
- return {
44
- ...def,
45
- segments
46
- };
33
+ const segments = def.pattern.split("/").filter(Boolean).map((seg) => {
34
+ const m = seg.match(/^\[(\.{3})?(.+)\]$/);
35
+ return m ? { param: m[2] } : { literal: seg };
36
+ });
37
+ return {
38
+ ...def,
39
+ segments
40
+ };
47
41
  }
48
42
  function parseQuery(query) {
49
- const params = {};
50
- if (!query) return params;
51
- for (const pair of query.split("&")) {
52
- if (!pair) continue;
53
- const eq = pair.indexOf("=");
54
- const key = decodeURIComponent(eq === -1 ? pair : pair.slice(0, eq));
55
- const value = eq === -1 ? "" : decodeURIComponent(pair.slice(eq + 1));
56
- const prev = params[key];
57
- if (prev === void 0) params[key] = value;else if (Array.isArray(prev)) prev.push(value);else params[key] = [prev, value];
58
- }
59
- return params;
43
+ const params = {};
44
+ if (!query) return params;
45
+ for (const pair of query.split("&")) {
46
+ if (!pair) continue;
47
+ const eq = pair.indexOf("=");
48
+ const key = decodeURIComponent(eq === -1 ? pair : pair.slice(0, eq));
49
+ const value = eq === -1 ? "" : decodeURIComponent(pair.slice(eq + 1));
50
+ const prev = params[key];
51
+ if (prev === void 0) params[key] = value;
52
+ else if (Array.isArray(prev)) prev.push(value);
53
+ else params[key] = [prev, value];
54
+ }
55
+ return params;
60
56
  }
61
57
  function hrefToString(href) {
62
- if (typeof href === "string") return href;
63
- let path = href.pathname;
64
- const leftover = [];
65
- for (const [key, raw] of Object.entries(href.params ?? {})) {
66
- const value = String(raw);
67
- const token = `[${key}]`;
68
- if (path.includes(token)) path = path.replace(token, encodeURIComponent(value));else leftover.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
69
- }
70
- return leftover.length ? `${path}?${leftover.join("&")}` : path;
58
+ if (typeof href === "string") return href;
59
+ let path = href.pathname;
60
+ const leftover = [];
61
+ for (const [key, raw] of Object.entries(href.params ?? {})) {
62
+ const value = String(raw);
63
+ const token = `[${key}]`;
64
+ if (path.includes(token)) path = path.replace(token, encodeURIComponent(value));
65
+ else leftover.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
66
+ }
67
+ return leftover.length ? `${path}?${leftover.join("&")}` : path;
71
68
  }
72
69
  const EMPTY_PARAMS = Object.freeze({});
73
- class StackNavigator {
74
- routes = [];
75
- host = null;
76
- listeners = /* @__PURE__ */new Set();
77
- /** Stack mirror rebuilt from the host on every pushed/popped/replaced
78
- * signal. */
79
- stackTags = [];
80
- paramsByTag = /* @__PURE__ */new Map();
81
- pathnameByTag = /* @__PURE__ */new Map();
82
- /** Tags whose page content has been navigated to at least once. The host
83
- * gates each page's React content on this (lazy mounting) — a tag enters
84
- * the set right before its first host push and never leaves (backgrounded
85
- * pages stay alive, same as One keeping stack screens mounted). */
86
- visitedTags = /* @__PURE__ */new Set();
87
- /** Route-loader results, per tag (the loader bridge's store). */
88
- loaderDataByTag = /* @__PURE__ */new Map();
89
- /** Monotonic navigation sequence — a loader that resolves after a NEWER
90
- * navigation started must not perform its (stale) host action. */
91
- navSeq = 0;
92
- /** Navigations that arrived while no host was attached — flushed FIFO on
93
- * attach() so deep links survive mount ordering and remount cycles. */
94
- pendingNavigations = [];
95
- generation = 0;
96
- snapshot = {
97
- pathname: "/",
98
- tag: "",
99
- depth: 0,
100
- canGoBack: false,
101
- generation: 0
102
- };
103
- get isConfigured() {
104
- return this.routes.length > 0;
105
- }
106
- /** Register the route manifest. The FIRST route is the root page. */
107
- configure(defs) {
108
- this.routes = defs.map(compileRoute);
109
- this.visitedTags = /* @__PURE__ */new Set();
110
- this.loaderDataByTag = /* @__PURE__ */new Map();
111
- this.pendingNavigations = [];
112
- const root = defs[0];
113
- if (root) {
114
- this.stackTags = [root.tag];
115
- this.visitedTags.add(root.tag);
116
- this.pathnameByTag.set(root.tag, root.pattern);
117
- this.rebuildSnapshot();
118
- }
119
- }
120
- /** Has this route's page been navigated to (⇒ its content may mount)? */
121
- isVisited(tag) {
122
- return tag !== null && this.visitedTags.has(tag);
123
- }
124
- /** The route's last loader result (stable identity until the loader runs
125
- * again). undefined when the route has no loader / hasn't resolved. */
126
- loaderSnapshot(tag) {
127
- if (!tag) return void 0;
128
- return this.loaderDataByTag.get(tag);
129
- }
130
- /** Seed a restored route's params/pathname BEFORE the first React render
131
- * (no host action, no stack mutation). The navigation host applies
132
- * `initialHref` from its attach EFFECT, which runs after the root page's
133
- * content already rendered once — a restored route's query params would
134
- * miss any mount-time state seeding (e.g. a list initializing filters
135
- * from useLocalSearchParams). Hosts call this while lazily initializing,
136
- * when no subscribers exist yet, so the rebuild notifies nobody. */
137
- seedInitialRoute(href) {
138
- const hit = this.match(href);
139
- if (!hit) return;
140
- this.setRouteState(hit.route.tag, hit.pathname, hit.params);
141
- }
142
- /** Resolve a route's loader WITHOUT navigating. For the initial page:
143
- * entries can `await stackNavigator.preload("/")` during top-level await
144
- * (where GJS reliably drains promise jobs) so even the root page's first
145
- * paint has loader data. */
146
- async preload(href) {
147
- const hit = this.match(href);
148
- if (!hit?.route.loader) return;
149
- try {
150
- const data = await hit.route.loader({
151
- path: hit.pathname,
152
- params: hit.params
153
- });
154
- this.loaderDataByTag.set(hit.route.tag, data);
155
- this.rebuildSnapshot();
156
- } catch (err) {
157
- console.error(`[stack nav] preload loader for ${hit.route.tag} failed: ${String(err)}`);
158
- }
159
- }
160
- /** Bind the live host stack (an Adw.NavigationView widget on GTK, a
161
- * DomStackAdapter on DOM targets). `initialHref` (state restore) applies
162
- * as a replace BEFORE queued navigations flush: a deep link that arrived
163
- * while unattached is fresher intent than a persisted route, so it lands
164
- * on top. */
165
- attach(host, options) {
166
- this.host = host;
167
- this.syncFromHost();
168
- const initialHref = options?.initialHref;
169
- if (initialHref !== void 0) this.replace(initialHref);
170
- for (const {
171
- href,
172
- mode
173
- } of this.pendingNavigations.splice(0)) {
174
- void this.navigate(href, mode);
175
- }
176
- }
177
- detach() {
178
- this.host = null;
179
- }
180
- subscribe = fn => {
181
- this.listeners.add(fn);
182
- return () => this.listeners.delete(fn);
183
- };
184
- getSnapshot = () => this.snapshot;
185
- paramsSnapshot(tag) {
186
- if (!tag) return EMPTY_PARAMS;
187
- return this.paramsByTag.get(tag) ?? EMPTY_PARAMS;
188
- }
189
- match(href) {
190
- const str = hrefToString(href);
191
- const [path = "", query] = str.split("?");
192
- const parts = path.split("/").filter(Boolean);
193
- for (const route of this.routes) {
194
- if (route.segments.length !== parts.length) continue;
195
- const params = parseQuery(query);
196
- let ok = true;
197
- for (let i = 0; i < parts.length; i++) {
198
- const seg = route.segments[i];
199
- const part = decodeURIComponent(parts[i]);
200
- if (seg.literal !== void 0) {
201
- if (seg.literal !== part) {
202
- ok = false;
203
- break;
204
- }
205
- } else if (seg.param !== void 0) {
206
- params[seg.param] = part;
207
- }
208
- }
209
- if (ok) return {
210
- route,
211
- pathname: path === "" ? "/" : `/${parts.join("/")}`,
212
- params
213
- };
214
- }
215
- return null;
216
- }
217
- push = href => {
218
- void this.navigate(href, "push");
219
- };
220
- replace = href => {
221
- void this.navigate(href, "replace");
222
- };
223
- /** Shared push/replace flow, incl. the loader bridge. When the target
224
- * route has no loader the whole body runs SYNCHRONOUSLY (an async
225
- * function only yields at its first await), preserving the original
226
- * timing. With a loader, the host action waits for the loader to resolve
227
- * — same contract as One on web, where client navigation completes only
228
- * after the route's loader data arrived — so the page's first paint has
229
- * its data (and the lazily-mounted content mounts with it). */
230
- async navigate(href, mode) {
231
- const hit = this.match(href);
232
- if (!hit) {
233
- console.log(`[stack nav] ${mode} ${hrefToString(href)} \u2014 no page in the route manifest, ignored`);
234
- return;
235
- }
236
- if (!this.host) {
237
- this.pendingNavigations.push({
238
- href,
239
- mode
240
- });
241
- console.log(`[stack nav] ${mode} ${hrefToString(href)} \u2014 queued until a stack host attaches`);
242
- return;
243
- }
244
- const {
245
- route,
246
- pathname,
247
- params
248
- } = hit;
249
- const seq = ++this.navSeq;
250
- if (route.loader) {
251
- try {
252
- const data = await route.loader({
253
- path: pathname,
254
- params
255
- });
256
- if (seq !== this.navSeq) return;
257
- this.loaderDataByTag.set(route.tag, data);
258
- } catch (err) {
259
- if (seq !== this.navSeq) return;
260
- console.error(`[stack nav] loader for ${route.tag} failed: ${String(err)}`);
261
- }
262
- }
263
- this.visitedTags.add(route.tag);
264
- this.setRouteState(route.tag, pathname, params);
265
- if (mode === "replace") {
266
- const top = this.stackTags.at(-1);
267
- if (top === route.tag) return;
268
- if (this.stackTags.length <= 1) {
269
- this.host.replace_with_tags([...this.stackTags, route.tag]);
270
- return;
271
- }
272
- const below = this.stackTags.slice(0, -1).filter(tag => tag !== route.tag);
273
- this.host.replace_with_tags([...below, route.tag]);
274
- return;
275
- }
276
- const idx = this.stackTags.indexOf(route.tag);
277
- if (idx === -1) {
278
- this.host.push_by_tag(route.tag);
279
- } else if (idx < this.stackTags.length - 1) {
280
- this.host.pop_to_tag(route.tag);
281
- }
282
- }
283
- back = () => {
284
- if (!this.host) {
285
- console.log("[stack nav] back \u2014 no stack host attached, ignored");
286
- return;
287
- }
288
- this.navSeq++;
289
- this.host.pop();
290
- };
291
- setParams = params => {
292
- const top = this.stackTags.at(-1);
293
- if (!top) return;
294
- const prev = this.paramsByTag.get(top) ?? {};
295
- this.paramsByTag.set(top, {
296
- ...prev,
297
- ...params
298
- });
299
- this.rebuildSnapshot();
300
- };
301
- /** Re-read the host navigation stack (called from pushed/popped/replaced
302
- * signal handlers and attach). The host is the source of truth. */
303
- syncFromHost = () => {
304
- if (!this.host) return;
305
- this.navSeq++;
306
- const model = this.host.get_navigation_stack();
307
- const tags = [];
308
- const count = model.get_n_items();
309
- for (let i = 0; i < count; i++) {
310
- const tag = model.get_item(i)?.get_tag();
311
- if (tag) tags.push(tag);
312
- }
313
- if (tags.length > 0) this.stackTags = tags;
314
- for (const tag of this.stackTags) this.visitedTags.add(tag);
315
- this.rebuildSnapshot();
316
- };
317
- setRouteState(tag, pathname, params) {
318
- this.paramsByTag.set(tag, params);
319
- this.pathnameByTag.set(tag, pathname);
320
- this.rebuildSnapshot();
321
- }
322
- rebuildSnapshot() {
323
- const tag = this.stackTags.at(-1) ?? "";
324
- const route = this.routes.find(r => r.tag === tag);
325
- this.generation++;
326
- this.snapshot = {
327
- pathname: this.pathnameByTag.get(tag) ?? route?.pattern ?? "/",
328
- tag,
329
- depth: this.stackTags.length,
330
- canGoBack: this.stackTags.length > 1,
331
- generation: this.generation
332
- };
333
- for (const fn of this.listeners) fn();
334
- }
335
- }
70
+ var StackNavigator = class {
71
+ routes = [];
72
+ host = null;
73
+ listeners = /* @__PURE__ */ new Set();
74
+ /** Stack mirror rebuilt from the host on every pushed/popped/replaced
75
+ * signal. */
76
+ stackTags = [];
77
+ paramsByTag = /* @__PURE__ */ new Map();
78
+ pathnameByTag = /* @__PURE__ */ new Map();
79
+ /** Tags whose page content has been navigated to at least once. The host
80
+ * gates each page's React content on this (lazy mounting) — a tag enters
81
+ * the set right before its first host push and never leaves (backgrounded
82
+ * pages stay alive, same as One keeping stack screens mounted). */
83
+ visitedTags = /* @__PURE__ */ new Set();
84
+ /** Route-loader results, per tag (the loader bridge's store). */
85
+ loaderDataByTag = /* @__PURE__ */ new Map();
86
+ /** Monotonic navigation sequence — a loader that resolves after a NEWER
87
+ * navigation started must not perform its (stale) host action. */
88
+ navSeq = 0;
89
+ /** Navigations that arrived while no host was attached — flushed FIFO on
90
+ * attach() so deep links survive mount ordering and remount cycles. */
91
+ pendingNavigations = [];
92
+ generation = 0;
93
+ snapshot = {
94
+ pathname: "/",
95
+ tag: "",
96
+ depth: 0,
97
+ canGoBack: false,
98
+ generation: 0
99
+ };
100
+ get isConfigured() {
101
+ return this.routes.length > 0;
102
+ }
103
+ /** Register the route manifest. The FIRST route is the root page. */
104
+ configure(defs) {
105
+ this.routes = defs.map(compileRoute);
106
+ this.visitedTags = /* @__PURE__ */ new Set();
107
+ this.loaderDataByTag = /* @__PURE__ */ new Map();
108
+ this.pendingNavigations = [];
109
+ const root = defs[0];
110
+ if (root) {
111
+ this.stackTags = [root.tag];
112
+ this.visitedTags.add(root.tag);
113
+ this.pathnameByTag.set(root.tag, root.pattern);
114
+ this.rebuildSnapshot();
115
+ }
116
+ }
117
+ /** Has this route's page been navigated to (⇒ its content may mount)? */
118
+ isVisited(tag) {
119
+ return tag !== null && this.visitedTags.has(tag);
120
+ }
121
+ /** The route's last loader result (stable identity until the loader runs
122
+ * again). undefined when the route has no loader / hasn't resolved. */
123
+ loaderSnapshot(tag) {
124
+ if (!tag) return void 0;
125
+ return this.loaderDataByTag.get(tag);
126
+ }
127
+ /** Seed a restored route's params/pathname BEFORE the first React render
128
+ * (no host action, no stack mutation). The navigation host applies
129
+ * `initialHref` from its attach EFFECT, which runs after the root page's
130
+ * content already rendered once — a restored route's query params would
131
+ * miss any mount-time state seeding (e.g. a list initializing filters
132
+ * from useLocalSearchParams). Hosts call this while lazily initializing,
133
+ * when no subscribers exist yet, so the rebuild notifies nobody. */
134
+ seedInitialRoute(href) {
135
+ const hit = this.match(href);
136
+ if (!hit) return;
137
+ this.setRouteState(hit.route.tag, hit.pathname, hit.params);
138
+ }
139
+ /** Resolve a route's loader WITHOUT navigating. For the initial page:
140
+ * entries can `await stackNavigator.preload("/")` during top-level await
141
+ * (where GJS reliably drains promise jobs) so even the root page's first
142
+ * paint has loader data. */
143
+ async preload(href) {
144
+ const hit = this.match(href);
145
+ if (!hit?.route.loader) return;
146
+ try {
147
+ const data = await hit.route.loader({
148
+ path: hit.pathname,
149
+ params: hit.params
150
+ });
151
+ this.loaderDataByTag.set(hit.route.tag, data);
152
+ this.rebuildSnapshot();
153
+ } catch (err) {
154
+ console.error(`[stack nav] preload loader for ${hit.route.tag} failed: ${String(err)}`);
155
+ }
156
+ }
157
+ /** Bind the live host stack (an Adw.NavigationView widget on GTK, a
158
+ * DomStackAdapter on DOM targets). `initialHref` (state restore) applies
159
+ * as a replace BEFORE queued navigations flush: a deep link that arrived
160
+ * while unattached is fresher intent than a persisted route, so it lands
161
+ * on top. */
162
+ attach(host, options) {
163
+ this.host = host;
164
+ this.syncFromHost();
165
+ const initialHref = options?.initialHref;
166
+ if (initialHref !== void 0) this.replace(initialHref);
167
+ for (const { href, mode } of this.pendingNavigations.splice(0)) {
168
+ void this.navigate(href, mode);
169
+ }
170
+ }
171
+ detach() {
172
+ this.host = null;
173
+ }
174
+ subscribe = (fn) => {
175
+ this.listeners.add(fn);
176
+ return () => this.listeners.delete(fn);
177
+ };
178
+ getSnapshot = () => this.snapshot;
179
+ paramsSnapshot(tag) {
180
+ if (!tag) return EMPTY_PARAMS;
181
+ return this.paramsByTag.get(tag) ?? EMPTY_PARAMS;
182
+ }
183
+ match(href) {
184
+ const str = hrefToString(href);
185
+ const [path = "", query] = str.split("?");
186
+ const parts = path.split("/").filter(Boolean);
187
+ for (const route of this.routes) {
188
+ if (route.segments.length !== parts.length) continue;
189
+ const params = parseQuery(query);
190
+ let ok = true;
191
+ for (let i = 0; i < parts.length; i++) {
192
+ const seg = route.segments[i];
193
+ const part = decodeURIComponent(parts[i]);
194
+ if (seg.literal !== void 0) {
195
+ if (seg.literal !== part) {
196
+ ok = false;
197
+ break;
198
+ }
199
+ } else if (seg.param !== void 0) {
200
+ params[seg.param] = part;
201
+ }
202
+ }
203
+ if (ok) return {
204
+ route,
205
+ pathname: path === "" ? "/" : `/${parts.join("/")}`,
206
+ params
207
+ };
208
+ }
209
+ return null;
210
+ }
211
+ push = (href) => {
212
+ void this.navigate(href, "push");
213
+ };
214
+ replace = (href) => {
215
+ void this.navigate(href, "replace");
216
+ };
217
+ /** Shared push/replace flow, incl. the loader bridge. When the target
218
+ * route has no loader the whole body runs SYNCHRONOUSLY (an async
219
+ * function only yields at its first await), preserving the original
220
+ * timing. With a loader, the host action waits for the loader to resolve
221
+ * — same contract as One on web, where client navigation completes only
222
+ * after the route's loader data arrived — so the page's first paint has
223
+ * its data (and the lazily-mounted content mounts with it). */
224
+ async navigate(href, mode) {
225
+ const hit = this.match(href);
226
+ if (!hit) {
227
+ console.log(`[stack nav] ${mode} ${hrefToString(href)} \u2014 no page in the route manifest, ignored`);
228
+ return;
229
+ }
230
+ if (!this.host) {
231
+ this.pendingNavigations.push({
232
+ href,
233
+ mode
234
+ });
235
+ console.log(`[stack nav] ${mode} ${hrefToString(href)} \u2014 queued until a stack host attaches`);
236
+ return;
237
+ }
238
+ const { route, pathname, params } = hit;
239
+ const seq = ++this.navSeq;
240
+ if (route.loader) {
241
+ try {
242
+ const data = await route.loader({
243
+ path: pathname,
244
+ params
245
+ });
246
+ if (seq !== this.navSeq) return;
247
+ this.loaderDataByTag.set(route.tag, data);
248
+ } catch (err) {
249
+ if (seq !== this.navSeq) return;
250
+ console.error(`[stack nav] loader for ${route.tag} failed: ${String(err)}`);
251
+ }
252
+ }
253
+ this.visitedTags.add(route.tag);
254
+ this.setRouteState(route.tag, pathname, params);
255
+ if (mode === "replace") {
256
+ const top = this.stackTags.at(-1);
257
+ if (top === route.tag) return;
258
+ if (this.stackTags.length <= 1) {
259
+ this.host.replace_with_tags([...this.stackTags, route.tag]);
260
+ return;
261
+ }
262
+ const below = this.stackTags.slice(0, -1).filter((tag) => tag !== route.tag);
263
+ this.host.replace_with_tags([...below, route.tag]);
264
+ return;
265
+ }
266
+ const idx = this.stackTags.indexOf(route.tag);
267
+ if (idx === -1) {
268
+ this.host.push_by_tag(route.tag);
269
+ } else if (idx < this.stackTags.length - 1) {
270
+ this.host.pop_to_tag(route.tag);
271
+ }
272
+ }
273
+ back = () => {
274
+ if (!this.host) {
275
+ console.log("[stack nav] back — no stack host attached, ignored");
276
+ return;
277
+ }
278
+ this.navSeq++;
279
+ this.host.pop();
280
+ };
281
+ setParams = (params) => {
282
+ const top = this.stackTags.at(-1);
283
+ if (!top) return;
284
+ const prev = this.paramsByTag.get(top) ?? {};
285
+ this.paramsByTag.set(top, {
286
+ ...prev,
287
+ ...params
288
+ });
289
+ this.rebuildSnapshot();
290
+ };
291
+ /** Re-read the host navigation stack (called from pushed/popped/replaced
292
+ * signal handlers and attach). The host is the source of truth. */
293
+ syncFromHost = () => {
294
+ if (!this.host) return;
295
+ this.navSeq++;
296
+ const model = this.host.get_navigation_stack();
297
+ const tags = [];
298
+ const count = model.get_n_items();
299
+ for (let i = 0; i < count; i++) {
300
+ const tag = model.get_item(i)?.get_tag();
301
+ if (tag) tags.push(tag);
302
+ }
303
+ if (tags.length > 0) this.stackTags = tags;
304
+ for (const tag of this.stackTags) this.visitedTags.add(tag);
305
+ this.rebuildSnapshot();
306
+ };
307
+ setRouteState(tag, pathname, params) {
308
+ this.paramsByTag.set(tag, params);
309
+ this.pathnameByTag.set(tag, pathname);
310
+ this.rebuildSnapshot();
311
+ }
312
+ rebuildSnapshot() {
313
+ const tag = this.stackTags.at(-1) ?? "";
314
+ const route = this.routes.find((r) => r.tag === tag);
315
+ this.generation++;
316
+ this.snapshot = {
317
+ pathname: this.pathnameByTag.get(tag) ?? route?.pattern ?? "/",
318
+ tag,
319
+ depth: this.stackTags.length,
320
+ canGoBack: this.stackTags.length > 1,
321
+ generation: this.generation
322
+ };
323
+ for (const fn of this.listeners) fn();
324
+ }
325
+ };
336
326
  const stackNavigator = new StackNavigator();
337
327
  const RouteTagContext = (0, import_react.createContext)(null);
338
328
  function useNavState() {
339
- return (0, import_react.useSyncExternalStore)(stackNavigator.subscribe, stackNavigator.getSnapshot);
329
+ return (0, import_react.useSyncExternalStore)(stackNavigator.subscribe, stackNavigator.getSnapshot);
340
330
  }
341
331
  function useRouteParams() {
342
- const tag = (0, import_react.useContext)(RouteTagContext);
343
- return (0, import_react.useSyncExternalStore)(stackNavigator.subscribe, () => stackNavigator.paramsSnapshot(tag));
344
- }
332
+ const tag = (0, import_react.useContext)(RouteTagContext);
333
+ return (0, import_react.useSyncExternalStore)(stackNavigator.subscribe, () => stackNavigator.paramsSnapshot(tag));
334
+ }