@alecsibilia/ui-kit 0.0.0-stage → 0.1.0-alpha.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 (283) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +201 -0
  3. package/README.md +233 -2
  4. package/bin/ui-kit.js +12 -0
  5. package/dist/alchemy/app.d.ts +34 -0
  6. package/dist/alchemy/app.js +88 -0
  7. package/dist/alchemy/index.d.ts +11 -0
  8. package/dist/alchemy/index.js +11 -0
  9. package/dist/alchemy/live-rooms.d.ts +21 -0
  10. package/dist/alchemy/live-rooms.js +31 -0
  11. package/dist/alchemy/migrations.d.ts +28 -0
  12. package/dist/alchemy/migrations.js +56 -0
  13. package/dist/alchemy/stage.d.ts +20 -0
  14. package/dist/alchemy/stage.js +20 -0
  15. package/dist/alchemy/wrangler-config.d.ts +76 -0
  16. package/dist/alchemy/wrangler-config.js +82 -0
  17. package/dist/build/app-modules.d.ts +11 -0
  18. package/dist/build/app-modules.js +40 -0
  19. package/dist/build/check.d.ts +4 -0
  20. package/dist/build/check.js +170 -0
  21. package/dist/build/cli.d.ts +1 -0
  22. package/dist/build/cli.js +79 -0
  23. package/dist/build/feature.d.ts +8 -0
  24. package/dist/build/feature.js +24 -0
  25. package/dist/build/index.d.ts +13 -0
  26. package/dist/build/index.js +13 -0
  27. package/dist/build/measure-cpu.d.ts +2 -0
  28. package/dist/build/measure-cpu.js +196 -0
  29. package/dist/build/prerender.d.ts +5 -0
  30. package/dist/build/prerender.js +109 -0
  31. package/dist/build/preview.d.ts +7 -0
  32. package/dist/build/preview.js +41 -0
  33. package/dist/build/seo-files.d.ts +27 -0
  34. package/dist/build/seo-files.js +24 -0
  35. package/dist/client/head-swap.d.ts +45 -0
  36. package/dist/client/head-swap.js +183 -0
  37. package/dist/client/hydration-pass.d.ts +56 -0
  38. package/dist/client/hydration-pass.js +186 -0
  39. package/dist/client/hydration-reset.d.ts +82 -0
  40. package/dist/client/hydration-reset.js +154 -0
  41. package/dist/client/index.d.ts +37 -0
  42. package/dist/client/index.js +65 -0
  43. package/dist/client/nav-client.d.ts +35 -0
  44. package/dist/client/nav-client.js +371 -0
  45. package/dist/live/collab/doc-provider.d.ts +74 -0
  46. package/dist/live/collab/doc-provider.js +412 -0
  47. package/dist/live/collab/index.d.ts +51 -0
  48. package/dist/live/collab/index.jsx +142 -0
  49. package/dist/live/collab-status.d.ts +25 -0
  50. package/dist/live/collab-status.js +17 -0
  51. package/dist/live/cursors/cursor-engine.d.ts +57 -0
  52. package/dist/live/cursors/cursor-engine.js +243 -0
  53. package/dist/live/cursors/index.d.ts +46 -0
  54. package/dist/live/cursors/index.jsx +110 -0
  55. package/dist/live/declaration.d.ts +113 -0
  56. package/dist/live/declaration.js +94 -0
  57. package/dist/live/index.d.ts +8 -0
  58. package/dist/live/index.js +8 -0
  59. package/dist/live/protocol.d.ts +224 -0
  60. package/dist/live/protocol.js +272 -0
  61. package/dist/live/server/doc-store.d.ts +68 -0
  62. package/dist/live/server/doc-store.js +187 -0
  63. package/dist/live/server/index.d.ts +60 -0
  64. package/dist/live/server/index.js +77 -0
  65. package/dist/live/server/room-presence.d.ts +24 -0
  66. package/dist/live/server/room-presence.js +123 -0
  67. package/dist/live/server/room-sockets.d.ts +65 -0
  68. package/dist/live/server/room-sockets.js +97 -0
  69. package/dist/live/server/room.d.ts +20 -0
  70. package/dist/live/server/room.js +348 -0
  71. package/dist/live/server/route.d.ts +56 -0
  72. package/dist/live/server/route.js +159 -0
  73. package/dist/live/server/types.d.ts +163 -0
  74. package/dist/live/server/types.js +2 -0
  75. package/dist/logic/agent-actions.d.ts +133 -0
  76. package/dist/logic/agent-actions.js +150 -0
  77. package/dist/logic/command-types.d.ts +53 -0
  78. package/dist/logic/command-types.js +0 -0
  79. package/dist/logic/dev.d.ts +9 -0
  80. package/dist/logic/dev.js +10 -0
  81. package/dist/logic/draft-rebase.d.ts +59 -0
  82. package/dist/logic/draft-rebase.js +71 -0
  83. package/dist/logic/form-state.d.ts +105 -0
  84. package/dist/logic/form-state.js +93 -0
  85. package/dist/logic/head.d.ts +145 -0
  86. package/dist/logic/head.js +140 -0
  87. package/dist/logic/index.d.ts +27 -0
  88. package/dist/logic/index.js +25 -0
  89. package/dist/logic/island-def.d.ts +89 -0
  90. package/dist/logic/island-def.js +59 -0
  91. package/dist/logic/kit-commands.d.ts +104 -0
  92. package/dist/logic/kit-commands.js +72 -0
  93. package/dist/logic/kit-errors.d.ts +25 -0
  94. package/dist/logic/kit-errors.js +6 -0
  95. package/dist/logic/listen.d.ts +99 -0
  96. package/dist/logic/listen.js +92 -0
  97. package/dist/logic/mutation-def.d.ts +65 -0
  98. package/dist/logic/mutation-def.js +43 -0
  99. package/dist/logic/navigation-data.d.ts +50 -0
  100. package/dist/logic/navigation-data.js +55 -0
  101. package/dist/logic/navigation-policy.d.ts +74 -0
  102. package/dist/logic/navigation-policy.js +127 -0
  103. package/dist/logic/page-model-def.d.ts +108 -0
  104. package/dist/logic/page-model-def.js +31 -0
  105. package/dist/logic/path.d.ts +31 -0
  106. package/dist/logic/path.js +48 -0
  107. package/dist/logic/query-def.d.ts +56 -0
  108. package/dist/logic/query-def.js +37 -0
  109. package/dist/logic/query-key.d.ts +24 -0
  110. package/dist/logic/query-key.js +35 -0
  111. package/dist/logic/query-types.d.ts +28 -0
  112. package/dist/logic/query-types.js +2 -0
  113. package/dist/logic/resources.d.ts +163 -0
  114. package/dist/logic/resources.js +62 -0
  115. package/dist/logic/result.d.ts +30 -0
  116. package/dist/logic/result.js +23 -0
  117. package/dist/logic/route-model.d.ts +139 -0
  118. package/dist/logic/route-model.js +207 -0
  119. package/dist/logic/route-params.d.ts +80 -0
  120. package/dist/logic/route-params.js +114 -0
  121. package/dist/logic/route-table.d.ts +308 -0
  122. package/dist/logic/route-table.js +206 -0
  123. package/dist/logic/seo.d.ts +61 -0
  124. package/dist/logic/seo.js +101 -0
  125. package/dist/logic/site.d.ts +12 -0
  126. package/dist/logic/site.js +0 -0
  127. package/dist/logic/subscriptions.d.ts +177 -0
  128. package/dist/logic/subscriptions.js +152 -0
  129. package/dist/render/index.d.ts +32 -0
  130. package/dist/render/index.js +52 -0
  131. package/dist/runtime/island-wake.d.ts +38 -0
  132. package/dist/runtime/island-wake.js +147 -0
  133. package/dist/runtime/query-scope.d.ts +224 -0
  134. package/dist/runtime/query-scope.js +222 -0
  135. package/dist/runtime/room-hub.d.ts +107 -0
  136. package/dist/runtime/room-hub.js +307 -0
  137. package/dist/runtime/subscription-runner.d.ts +71 -0
  138. package/dist/runtime/subscription-runner.js +240 -0
  139. package/dist/server/bindings.d.ts +41 -0
  140. package/dist/server/bindings.js +74 -0
  141. package/dist/server/browser.d.ts +9 -0
  142. package/dist/server/browser.js +9 -0
  143. package/dist/server/edge-cache.d.ts +28 -0
  144. package/dist/server/edge-cache.js +35 -0
  145. package/dist/server/errors.d.ts +45 -0
  146. package/dist/server/errors.js +36 -0
  147. package/dist/server/form-actions-setup.d.ts +1 -0
  148. package/dist/server/form-actions-setup.js +15 -0
  149. package/dist/server/form-actions.d.ts +121 -0
  150. package/dist/server/form-actions.js +211 -0
  151. package/dist/server/index.d.ts +36 -0
  152. package/dist/server/index.js +35 -0
  153. package/dist/server/inputs.d.ts +45 -0
  154. package/dist/server/inputs.js +77 -0
  155. package/dist/server/rate-limit.d.ts +29 -0
  156. package/dist/server/rate-limit.js +32 -0
  157. package/dist/server/read-cache.d.ts +74 -0
  158. package/dist/server/read-cache.js +58 -0
  159. package/dist/server/request-info.d.ts +17 -0
  160. package/dist/server/request-info.js +11 -0
  161. package/dist/server/request.d.ts +52 -0
  162. package/dist/server/request.js +73 -0
  163. package/dist/server/response-cookies.d.ts +23 -0
  164. package/dist/server/response-cookies.js +24 -0
  165. package/dist/server/run-effect.d.ts +42 -0
  166. package/dist/server/run-effect.js +92 -0
  167. package/dist/server/run.d.ts +63 -0
  168. package/dist/server/run.js +66 -0
  169. package/dist/server/session.d.ts +125 -0
  170. package/dist/server/session.js +247 -0
  171. package/dist/test/fake-bindings.d.ts +32 -0
  172. package/dist/test/fake-bindings.js +108 -0
  173. package/dist/test/fake-room.d.ts +66 -0
  174. package/dist/test/fake-room.js +216 -0
  175. package/dist/test/index.d.ts +19 -0
  176. package/dist/test/index.js +44 -0
  177. package/dist/test/probe.d.ts +11 -0
  178. package/dist/test/probe.js +11 -0
  179. package/dist/test/solid-jsx.d.ts +23 -0
  180. package/dist/test/solid-jsx.js +28 -0
  181. package/dist/test/solid-preload.d.ts +1 -0
  182. package/dist/test/solid-preload.js +29 -0
  183. package/dist/ui/code-editor/index.d.ts +21 -0
  184. package/dist/ui/code-editor/index.jsx +286 -0
  185. package/dist/ui/collab-text/index.d.ts +29 -0
  186. package/dist/ui/collab-text/index.jsx +96 -0
  187. package/dist/ui/components/controls.d.ts +69 -0
  188. package/dist/ui/components/controls.jsx +81 -0
  189. package/dist/ui/components/feedback.d.ts +26 -0
  190. package/dist/ui/components/feedback.jsx +80 -0
  191. package/dist/ui/components/layout.d.ts +74 -0
  192. package/dist/ui/components/layout.jsx +146 -0
  193. package/dist/ui/components/lists.d.ts +69 -0
  194. package/dist/ui/components/lists.jsx +133 -0
  195. package/dist/ui/components/navigation.d.ts +73 -0
  196. package/dist/ui/components/navigation.jsx +112 -0
  197. package/dist/ui/components/text.d.ts +34 -0
  198. package/dist/ui/components/text.jsx +163 -0
  199. package/dist/ui/index.d.ts +7 -0
  200. package/dist/ui/index.js +7 -0
  201. package/dist/ui/jsx-runtime.d.ts +19 -0
  202. package/dist/ui/jsx-runtime.js +0 -0
  203. package/dist/ui/list-keys.d.ts +31 -0
  204. package/dist/ui/list-keys.js +45 -0
  205. package/dist/ui/styles/base.css +38 -0
  206. package/dist/ui/styles/components.css +608 -0
  207. package/dist/ui/styles/tokens.css +27 -0
  208. package/dist/ui/styles/transitions.css +23 -0
  209. package/dist/ui/styles/workbench.css +428 -0
  210. package/dist/ui/styles.css +9 -0
  211. package/dist/view/agent-actions-view.d.ts +30 -0
  212. package/dist/view/agent-actions-view.js +27 -0
  213. package/dist/view/agent-surface.d.ts +42 -0
  214. package/dist/view/agent-surface.js +123 -0
  215. package/dist/view/app-scope.d.ts +51 -0
  216. package/dist/view/app-scope.js +75 -0
  217. package/dist/view/boundary.d.ts +18 -0
  218. package/dist/view/boundary.jsx +26 -0
  219. package/dist/view/command-runner.d.ts +16 -0
  220. package/dist/view/command-runner.js +245 -0
  221. package/dist/view/form.d.ts +82 -0
  222. package/dist/view/form.jsx +109 -0
  223. package/dist/view/head-view.d.ts +31 -0
  224. package/dist/view/head-view.js +46 -0
  225. package/dist/view/index.d.ts +41 -0
  226. package/dist/view/index.js +40 -0
  227. package/dist/view/island-root.d.ts +30 -0
  228. package/dist/view/island-root.js +36 -0
  229. package/dist/view/island.d.ts +102 -0
  230. package/dist/view/island.jsx +154 -0
  231. package/dist/view/match.d.ts +41 -0
  232. package/dist/view/match.js +111 -0
  233. package/dist/view/model.d.ts +92 -0
  234. package/dist/view/model.js +162 -0
  235. package/dist/view/navigation-head.d.ts +29 -0
  236. package/dist/view/navigation-head.jsx +38 -0
  237. package/dist/view/page-model.d.ts +46 -0
  238. package/dist/view/page-model.js +146 -0
  239. package/dist/view/query-effects.d.ts +87 -0
  240. package/dist/view/query-effects.js +147 -0
  241. package/dist/view/query-ok.d.ts +45 -0
  242. package/dist/view/query-ok.js +96 -0
  243. package/dist/view/query.d.ts +115 -0
  244. package/dist/view/query.jsx +179 -0
  245. package/dist/view/result-view.d.ts +14 -0
  246. package/dist/view/result-view.jsx +15 -0
  247. package/dist/view/route-pages.d.ts +43 -0
  248. package/dist/view/route-pages.js +59 -0
  249. package/dist/view/router.d.ts +44 -0
  250. package/dist/view/router.js +123 -0
  251. package/dist/vite/dev-middleware.d.ts +12 -0
  252. package/dist/vite/dev-middleware.js +39 -0
  253. package/dist/vite/dev-objects.d.ts +25 -0
  254. package/dist/vite/dev-objects.js +127 -0
  255. package/dist/vite/dev-platform.d.ts +19 -0
  256. package/dist/vite/dev-platform.js +77 -0
  257. package/dist/vite/dev-seo-files.d.ts +11 -0
  258. package/dist/vite/dev-seo-files.js +40 -0
  259. package/dist/vite/index.d.ts +53 -0
  260. package/dist/vite/index.js +148 -0
  261. package/dist/vite/local-config.d.ts +34 -0
  262. package/dist/vite/local-config.js +72 -0
  263. package/dist/vite/worker-build.d.ts +24 -0
  264. package/dist/vite/worker-build.js +84 -0
  265. package/dist/worker/create-worker.d.ts +52 -0
  266. package/dist/worker/create-worker.js +90 -0
  267. package/dist/worker/index.d.ts +12 -0
  268. package/dist/worker/index.js +12 -0
  269. package/dist/worker/page-routes.d.ts +88 -0
  270. package/dist/worker/page-routes.js +100 -0
  271. package/dist/worker/page-status.d.ts +41 -0
  272. package/dist/worker/page-status.js +23 -0
  273. package/dist/worker/request-prelude.d.ts +69 -0
  274. package/dist/worker/request-prelude.js +107 -0
  275. package/dist/worker/security.d.ts +76 -0
  276. package/dist/worker/security.js +137 -0
  277. package/dist/worker/server-app.d.ts +54 -0
  278. package/dist/worker/server-app.js +76 -0
  279. package/guards/browser-only.js +5 -0
  280. package/guards/node-only.js +6 -0
  281. package/guards/server-only.js +5 -0
  282. package/migrations/0001-sessions.sql +22 -0
  283. package/package.json +233 -5
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Route params: the search param specs and their data-only decoder, the
3
+ * path and search param types a route table derives, and the pure URL
4
+ * matching helpers `route-table.ts` builds on. No Solid, no Effect, no DOM.
5
+ */
6
+ /** One of a fixed set of strings; anything else decodes as `fallback`. */
7
+ export interface OneOfParam<V extends string = string> {
8
+ readonly kind: 'oneOf';
9
+ readonly values: readonly V[];
10
+ readonly fallback: V;
11
+ }
12
+ /** Free text, trimmed and capped at `maxLength`; missing or empty decodes as `fallback`. */
13
+ export interface TextParam {
14
+ readonly kind: 'text';
15
+ readonly fallback: string;
16
+ readonly maxLength: number;
17
+ }
18
+ /** An integer in `[min, max]`; anything else decodes as `fallback`. */
19
+ export interface IntParam {
20
+ readonly kind: 'int';
21
+ readonly fallback: number;
22
+ readonly min: number;
23
+ readonly max: number;
24
+ }
25
+ export type SearchParamSpec = OneOfParam | TextParam | IntParam;
26
+ /** Search params of a route, by name. */
27
+ export type SearchSpec = {
28
+ readonly [name: string]: SearchParamSpec;
29
+ };
30
+ /** The decoded type of one search param spec. */
31
+ export type SearchParamValue<S> = S extends OneOfParam<infer V> ? V : S extends TextParam ? string : S extends IntParam ? number : never;
32
+ /** Builders for search param specs (plain data). */
33
+ export declare const searchParam: {
34
+ /**
35
+ * @example
36
+ * ```ts
37
+ * searchParam.oneOf(["gear", "stats"], "gear") // ?tab=stats -> "stats"; ?tab=x -> "gear"
38
+ * ```
39
+ */
40
+ readonly oneOf: <const V extends string>(values: readonly V[], fallback: NoInfer<V>) => OneOfParam<V>;
41
+ /** Free text (a relative `next` path, a search box). */
42
+ readonly text: (fallback?: string, maxLength?: number) => TextParam;
43
+ /** An integer (`?page=2`). */
44
+ readonly int: (fallback: number, min?: number, max?: number) => IntParam;
45
+ };
46
+ /** Param names of a path pattern: `"/plans/:planId"` -> `"planId"`. */
47
+ export type ParamNames<P> = P extends `${string}:${infer Name}/${infer Rest}` ? Name | ParamNames<`/${Rest}`> : P extends `${string}:${infer Name}` ? Name : never;
48
+ /** Decoded path params of a pattern (strings; `{}` for static paths and `NotFound`). */
49
+ export type ParamsOf<P> = {
50
+ readonly [K in ParamNames<P>]: string;
51
+ };
52
+ /** Decoded search params of a route entry (`{}` when it declares none). */
53
+ export type SearchOf<E> = E extends {
54
+ readonly search: infer S;
55
+ } ? {
56
+ readonly [K in keyof S]: SearchParamValue<S[K]>;
57
+ } : Readonly<Record<never, never>>;
58
+ /** `pathname` + `search` of a URL or path (`/x?a=1`, `https://h/x?a=1`). */
59
+ export declare function splitUrl(url: string): {
60
+ readonly pathname: string;
61
+ readonly query: string;
62
+ };
63
+ /**
64
+ * Params of `pathname` against a route pattern (`/plans/:planId`), or
65
+ * `undefined` when it does not match. Exported for the client navigation
66
+ * runtime, which matches link targets against the `client` routes' patterns.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * matchPattern("/plans/:planId", "/plans/voltar-main"); // { planId: "voltar-main" }
71
+ * matchPattern("/plans/:planId", "/account"); // undefined
72
+ * ```
73
+ */
74
+ export declare function matchPattern(pattern: string, pathname: string): Readonly<Record<string, string>> | undefined;
75
+ /**
76
+ * Decodes search params with a spec; missing or invalid values get the
77
+ * spec's fallback, unknown params are dropped.
78
+ */
79
+ export declare function decodeSearch(spec: SearchSpec, query: string): Readonly<Record<string, string | number>>;
80
+ export declare const isStatic: (path: string) => boolean;
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Route params: the search param specs and their data-only decoder, the
3
+ * path and search param types a route table derives, and the pure URL
4
+ * matching helpers `route-table.ts` builds on. No Solid, no Effect, no DOM.
5
+ */
6
+ /** Builders for search param specs (plain data). */
7
+ export const searchParam = {
8
+ /**
9
+ * @example
10
+ * ```ts
11
+ * searchParam.oneOf(["gear", "stats"], "gear") // ?tab=stats -> "stats"; ?tab=x -> "gear"
12
+ * ```
13
+ */
14
+ oneOf: (values, fallback) => ({
15
+ kind: 'oneOf',
16
+ values,
17
+ fallback,
18
+ }),
19
+ /** Free text (a relative `next` path, a search box). */
20
+ text: (fallback = '', maxLength = 200) => ({
21
+ kind: 'text',
22
+ fallback,
23
+ maxLength,
24
+ }),
25
+ /** An integer (`?page=2`). */
26
+ int: (fallback, min = 0, max = Number.MAX_SAFE_INTEGER) => ({
27
+ kind: 'int',
28
+ fallback,
29
+ min,
30
+ max,
31
+ }),
32
+ };
33
+ // ---------------------------------------------------------------------------
34
+ // The table.
35
+ // ---------------------------------------------------------------------------
36
+ /** `pathname` + `search` of a URL or path (`/x?a=1`, `https://h/x?a=1`). */
37
+ export function splitUrl(url) {
38
+ const withoutHash = url.split('#')[0] ?? '';
39
+ const noOrigin = withoutHash.replace(/^[a-z][a-z0-9+.-]*:\/\/[^/?]*/i, '');
40
+ const at = noOrigin.indexOf('?');
41
+ return at === -1
42
+ ? { pathname: noOrigin, query: '' }
43
+ : { pathname: noOrigin.slice(0, at), query: noOrigin.slice(at + 1) };
44
+ }
45
+ function decodeSegment(segment) {
46
+ try {
47
+ const value = decodeURIComponent(segment);
48
+ return value.length > 0 && !value.includes('/') ? value : undefined;
49
+ }
50
+ catch {
51
+ return undefined;
52
+ }
53
+ }
54
+ /**
55
+ * Params of `pathname` against a route pattern (`/plans/:planId`), or
56
+ * `undefined` when it does not match. Exported for the client navigation
57
+ * runtime, which matches link targets against the `client` routes' patterns.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * matchPattern("/plans/:planId", "/plans/voltar-main"); // { planId: "voltar-main" }
62
+ * matchPattern("/plans/:planId", "/account"); // undefined
63
+ * ```
64
+ */
65
+ export function matchPattern(pattern, pathname) {
66
+ const want = pattern.split('/');
67
+ const got = pathname.split('/');
68
+ if (want.length !== got.length)
69
+ return undefined;
70
+ const params = {};
71
+ for (let i = 0; i < want.length; i += 1) {
72
+ const w = want[i];
73
+ const g = got[i];
74
+ if (w.startsWith(':')) {
75
+ const value = decodeSegment(g);
76
+ if (value === undefined)
77
+ return undefined;
78
+ params[w.slice(1)] = value;
79
+ }
80
+ else if (w !== g) {
81
+ return undefined;
82
+ }
83
+ }
84
+ return params;
85
+ }
86
+ function decodeSearchParam(spec, raw) {
87
+ if (spec.kind === 'oneOf') {
88
+ return raw !== null && spec.values.includes(raw)
89
+ ? raw
90
+ : spec.fallback;
91
+ }
92
+ if (spec.kind === 'text') {
93
+ const text = (raw ?? '').trim().slice(0, spec.maxLength);
94
+ return text.length > 0 ? text : spec.fallback;
95
+ }
96
+ if (raw === null || !/^-?\d+$/.test(raw.trim()))
97
+ return spec.fallback;
98
+ const n = Number(raw.trim());
99
+ return Number.isSafeInteger(n) && n >= spec.min && n <= spec.max
100
+ ? n
101
+ : spec.fallback;
102
+ }
103
+ /**
104
+ * Decodes search params with a spec; missing or invalid values get the
105
+ * spec's fallback, unknown params are dropped.
106
+ */
107
+ export function decodeSearch(spec, query) {
108
+ const params = new URLSearchParams(query);
109
+ const out = {};
110
+ for (const name of Object.keys(spec))
111
+ out[name] = decodeSearchParam(spec[name], params.get(name));
112
+ return out;
113
+ }
114
+ export const isStatic = (path) => !path.includes(':');
@@ -0,0 +1,308 @@
1
+ import type { RouteHead } from './head.ts';
2
+ import { type ParamsOf, type SearchOf, type SearchSpec } from './route-params.ts';
3
+ export * from './route-params.ts';
4
+ /**
5
+ * The route table's types and pure helpers. Import-free (no Solid), so the
6
+ * app's `routes.ts` (read by the Worker, the prerender script, the router
7
+ * and `App.tsx`) and route models can use them.
8
+ *
9
+ * A route has a path pattern with typed params (`/plans/:planId`), optional
10
+ * search params decoded by a small data-only decoder (`?tab=gear|stats`), a
11
+ * render mode, an optional `auth: "required"` and a lazy page import. The
12
+ * same pure functions run in the Worker (`routeEntryFor`), in the route
13
+ * model (`matchRoute`, `hrefFor`) and in tests: no Effect, no DOM.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * export const routes = {
18
+ * PlanDetail: {
19
+ * path: "/plans/:planId",
20
+ * search: { tab: searchParam.oneOf(["gear", "stats"], "gear") },
21
+ * render: "ssr",
22
+ * page: () => import("./features/plan-detail/plan-detail-page.tsx"),
23
+ * },
24
+ * NotFound: { path: null, render: "ssr", page: () => import("./not-found-page.tsx") },
25
+ * } as const satisfies RouteTable;
26
+ *
27
+ * matchRoute(routePathsOf(routes), "/plans/voltar-main?tab=stats");
28
+ * // { _tag: "PlanDetail", params: { planId: "voltar-main" }, search: { tab: "stats" } }
29
+ * ```
30
+ */
31
+ /** How a route's page is produced. */
32
+ export type RenderMode =
33
+ /** Rendered once at build time into a static asset (CSP by script hashes). */
34
+ 'prerender'
35
+ /** Rendered per request by the Worker (streamed SSR, nonce CSP). */
36
+ | 'ssr';
37
+ /**
38
+ * How a per-request SSR page is sent. `whole` (default, owner decision
39
+ * 2026-12-04): the Worker waits for every query and sends finished HTML
40
+ * (Solid's `renderMode: "async"`), so every reader (browsers, crawlers,
41
+ * agents, JS off) gets the full content and its head. `stream` (opt-in):
42
+ * the shell first, each `<Query>` streams in behind it (swapped by inline
43
+ * scripts; invisible with JS off). Use `stream` only for signed-in app
44
+ * pages with slow, non-essential parts.
45
+ */
46
+ export type SsrMode = 'stream' | 'whole';
47
+ /** What an SSR route without `ssr` gets. */
48
+ export declare const DEFAULT_SSR_MODE: SsrMode;
49
+ /** Who may see a route. `required`: the Worker redirects to sign-in before any render. */
50
+ export type RouteAuth = 'required' | 'public';
51
+ /**
52
+ * How a route's page is reached, as data (`RoutePathSpec.navigation`):
53
+ * `document` (a full load) or `client` (the kit's swap, within the
54
+ * route's section).
55
+ */
56
+ export type NavigationMode = 'document' | 'client';
57
+ /**
58
+ * How links *into* this route are followed (`docs/guides/ui-kit-page-transitions.md`,
59
+ * owner decision "Named sections"):
60
+ * - `"document"` (default): a full page load. With layer 1 (the UI kit's
61
+ * cross-document view transition and the table's speculation rules) it
62
+ * is already animated and usually prefetched.
63
+ * - `{ client: "app" }` (opt-in): the route belongs to the named client
64
+ * section `"app"`. Between two routes of the **same** section, the kit's
65
+ * navigation runtime fetches the next page, swaps head and body, and
66
+ * hydrates its islands in a fresh pass, so `persist` islands and
67
+ * `persist` page models survive. Crossing into another section (or into
68
+ * a `document` route) is a full load, which resets persisted islands,
69
+ * page models and held room sockets. Only `render: "ssr"` routes (nonce
70
+ * CSP) can be in a section (lint `ui-kit/route-navigation`): a hash-CSP
71
+ * prerendered page can't run the next page's inline scripts.
72
+ *
73
+ * `S` is the app's closed set of section names
74
+ * (`satisfies RouteTable<"app" | "account">`): a typo is a type error.
75
+ */
76
+ export type NavigationSpec<S extends string = string> = 'document' | {
77
+ readonly client: S;
78
+ };
79
+ /** What `navigation` defaults to. */
80
+ export declare const DEFAULT_NAVIGATION: NavigationMode;
81
+ /**
82
+ * Speculation rules for links to this route (layer 1, zero JS):
83
+ * - `prefetch` (default): the browser fetches the page on hover (200 ms,
84
+ * Chrome's `moderate` eagerness), so the click is a cache hit.
85
+ * - `prerender` (opt-in): renders it in a hidden tab on hover. Its islands
86
+ * start only when the page is shown (the kit waits for
87
+ * `prerenderingchange`), so a prerender opens no socket.
88
+ * - `none`: never. `auth: "required"` routes are always `none` (a personal
89
+ * page is never fetched speculatively); so are `/_server` and every
90
+ * non-GET (rules only cover links).
91
+ */
92
+ export type Speculation = 'prefetch' | 'prerender' | 'none';
93
+ /** What `speculate` defaults to (public routes). */
94
+ export declare const DEFAULT_SPECULATION: Speculation;
95
+ /** A page module: default-exports a component taking `PageProps` (or nothing). */
96
+ export type PageModule = {
97
+ readonly default: (props: any) => unknown;
98
+ };
99
+ /**
100
+ * Declares a route's lazy page import: `page: lazyPage(() => import("./x-page.tsx"))`.
101
+ * Identity at runtime. It types the entry as `() => Promise<PageModule>`
102
+ * without TypeScript reading the page's props, so a page can type its
103
+ * props from the table it is listed in (`PageProps<RouteOf<AppRoutes>...>`)
104
+ * without a circular type.
105
+ */
106
+ export declare function lazyPage(load: () => Promise<{
107
+ readonly default: unknown;
108
+ }>): () => Promise<PageModule>;
109
+ export interface RouteEntry<S extends string = string> {
110
+ /** Path pattern (`/plans/:planId`, normalized form); `null` for `NotFound`. */
111
+ readonly path: string | null;
112
+ /** Search params this route reads (`?tab=...`), decoded with fallbacks. */
113
+ readonly search?: SearchSpec;
114
+ readonly render: RenderMode;
115
+ /** `ssr` pages only: send whole (default) or stream (opt-in, signed-in app pages). */
116
+ readonly ssr?: SsrMode;
117
+ /**
118
+ * Title, description, canonical, Open Graph / Twitter, robots, `hreflang`
119
+ * and JSON-LD (see `head.ts`): a spec, or a pure function of the route's
120
+ * params. Required with `title` + `description` on public routes (lint
121
+ * `ui-kit/route-head-required`); used by SSR, prerender, client navigation
122
+ * and the sitemap (a `robots: "noindex"` route is left out of it).
123
+ */
124
+ readonly head?: RouteHead;
125
+ /** `"required"`: unauthenticated requests are redirected to sign-in before render. */
126
+ readonly auth?: RouteAuth;
127
+ /**
128
+ * How links into this route are followed: `"document"` (default, a full
129
+ * load) or `{ client: "<section>" }` (client navigation within that
130
+ * named section; crossing sections is a full load).
131
+ */
132
+ readonly navigation?: NavigationSpec<S>;
133
+ /** Speculation rules for links to this route (default `prefetch`; always `none` with `auth: "required"`). */
134
+ readonly speculate?: Speculation;
135
+ /**
136
+ * Live presence on this page ("N people here", the page's `page:<Route>`
137
+ * room): opt-in per route (default `false`), so a page without it ships
138
+ * no presence JS (a page with no other island ships no JS at all). The
139
+ * app shell places the presence island from this flag
140
+ * (`routePresence(paths, route)`); the app's page room keys must be
141
+ * exactly the routes that set it (checked by the app's test).
142
+ */
143
+ readonly presence?: boolean;
144
+ /** Lazy page import: `() => import("./features/x/x-page.tsx")`. */
145
+ readonly page: () => Promise<PageModule>;
146
+ }
147
+ /**
148
+ * Every route of the app, by tag. `NotFound` (no path) renders for any
149
+ * unknown path (the Worker answers it with status 404).
150
+ *
151
+ * `S`: the app's client-navigation section names, a closed set
152
+ * (`as const satisfies RouteTable<"app" | "account">`). Lint
153
+ * `ui-kit/route-navigation` requires it once a route names a section.
154
+ */
155
+ export type RouteTable<S extends string = string> = {
156
+ readonly [tag: string]: RouteEntry<S>;
157
+ } & {
158
+ readonly NotFound: RouteEntry<S> & {
159
+ readonly path: null;
160
+ };
161
+ };
162
+ /** The client-navigation section names a table uses (`"app" | "account"`). */
163
+ export type SectionOf<T> = {
164
+ [K in keyof T]: T[K] extends {
165
+ readonly navigation: {
166
+ readonly client: infer S extends string;
167
+ };
168
+ } ? S : never;
169
+ }[keyof T];
170
+ /**
171
+ * A route's client-navigation section, or `undefined` for a full-load
172
+ * (`document`) route. A prerendered route never has one in effect (hash
173
+ * CSP; lint `ui-kit/route-navigation` reports writing it).
174
+ *
175
+ * @example
176
+ * ```ts
177
+ * routeSection({ render: "ssr", navigation: { client: "app" } }); // "app"
178
+ * routeSection({ render: "prerender", navigation: { client: "app" } }); // undefined
179
+ * routeSection({ render: "ssr" }); // undefined
180
+ * ```
181
+ */
182
+ export declare function routeSection(entry: Pick<RouteEntry, 'navigation' | 'render'>): string | undefined;
183
+ /** A route as data: its tag, decoded path params and decoded search params. */
184
+ export type RouteOf<T> = {
185
+ [K in keyof T & string]: {
186
+ readonly _tag: K;
187
+ readonly params: ParamsOf<T[K] extends {
188
+ readonly path: infer P;
189
+ } ? P : null>;
190
+ readonly search: SearchOf<T[K]>;
191
+ };
192
+ }[keyof T & string];
193
+ /** Routes that have a path (every route but `NotFound`): what links and `Navigated` target. */
194
+ export type PathRouteOf<T> = Exclude<RouteOf<T>, {
195
+ readonly _tag: 'NotFound';
196
+ }>;
197
+ /** The tags of a table that have a path. */
198
+ export type PathTagOf<T> = {
199
+ [K in keyof T & string]: T[K] extends {
200
+ readonly path: string;
201
+ } ? K : never;
202
+ }[keyof T & string];
203
+ /** One route's matching data: plain, clonable (no page import). */
204
+ export interface RoutePathSpec {
205
+ readonly path: string | null;
206
+ readonly search: SearchSpec;
207
+ readonly auth: RouteAuth;
208
+ readonly render: RenderMode;
209
+ readonly ssr: SsrMode;
210
+ readonly navigation: NavigationMode;
211
+ /** The route's client-navigation section (`null`: a full-load route). */
212
+ readonly section: string | null;
213
+ readonly speculate: Speculation;
214
+ readonly presence: boolean;
215
+ }
216
+ /**
217
+ * The speculation a route gets: its `speculate` (default `prefetch`),
218
+ * `none` for `auth: "required"` routes whatever they say.
219
+ */
220
+ export declare function effectiveSpeculation(entry: Pick<RouteEntry, 'auth' | 'speculate'>): Speculation;
221
+ /**
222
+ * The table without its page imports: plain data a route model holds as
223
+ * `init` flags (a `.model.ts` cannot import the table at runtime, since its
224
+ * lazy page imports reach Solid). Typed by the table it came from.
225
+ */
226
+ export type RoutePaths<T = RouteTable> = {
227
+ readonly [K in keyof T & string]: RoutePathSpec;
228
+ } & {
229
+ readonly __table?: T;
230
+ };
231
+ /**
232
+ * The table's matching data (paths, search specs, auth, render mode).
233
+ *
234
+ * @example
235
+ * ```ts
236
+ * const paths = routePathsOf(routes);
237
+ * initRouteModel(paths, currentUrl());
238
+ * ```
239
+ */
240
+ export declare function routePathsOf<T extends RouteTable>(table: T): RoutePaths<T>;
241
+ /**
242
+ * The route for a URL: its tag, decoded path params and search params.
243
+ * Static paths win over param paths (`/plans/new` before `/plans/:planId`);
244
+ * a path that matches nothing (or has a param that is not valid
245
+ * percent-encoding) is `NotFound`. Pure, server-safe.
246
+ *
247
+ * @param table - The table's `routePathsOf` data.
248
+ * @param url - A path with optional query (`/plans/x?tab=stats`) or a full URL.
249
+ *
250
+ * @example
251
+ * ```ts
252
+ * matchRoute(paths, "/plans/voltar-main?tab=stats&x=1");
253
+ * // { _tag: "PlanDetail", params: { planId: "voltar-main" }, search: { tab: "stats" } }
254
+ * ```
255
+ */
256
+ export declare function matchRoute<T>(table: RoutePaths<T>, url: string): RouteOf<T>;
257
+ /**
258
+ * The URL of a route: params percent-encoded into the pattern, search
259
+ * params in spec order, omitted when equal to their fallback (so the
260
+ * default tab's URL is the bare path). `matchRoute(t, hrefFor(t, r))`
261
+ * gives back `r`.
262
+ *
263
+ * @example
264
+ * ```ts
265
+ * hrefFor(paths, { _tag: "PlanDetail", params: { planId: "a b" }, search: { tab: "stats" } });
266
+ * // "/plans/a%20b?tab=stats"
267
+ * ```
268
+ */
269
+ export declare function hrefFor<T>(table: RoutePaths<T>, route: PathRouteOf<T>): string;
270
+ /** Whether two routes are the same URL (same tag, params and search). */
271
+ export declare function sameRoute<T>(table: RoutePaths<T>, a: RouteOf<T>, b: RouteOf<T>): boolean;
272
+ /**
273
+ * The table entry for a URL, with the matched tag and route (the `NotFound`
274
+ * entry when nothing matches). What the Worker reads before rendering:
275
+ * render mode, `auth`, params.
276
+ *
277
+ * @example
278
+ * ```ts
279
+ * const hit = routeEntryFor(routes, "/plans/x?tab=stats");
280
+ * hit.render; // "ssr"
281
+ * hit.auth; // undefined (public)
282
+ * hit.route; // { _tag: "PlanDetail", params: { planId: "x" }, search: { tab: "stats" } }
283
+ * ```
284
+ */
285
+ export declare function routeEntryFor<T extends RouteTable>(table: T, url: string): RouteMatch<T>;
286
+ /** What `routeEntryFor` returns: the entry (auth defaulted) plus the matched tag and route. */
287
+ export type RouteMatch<T extends RouteTable> = RouteEntry & {
288
+ readonly auth: RouteAuth;
289
+ readonly ssr: SsrMode;
290
+ readonly tag: keyof T & string;
291
+ readonly route: RouteOf<T>;
292
+ };
293
+ /**
294
+ * Paths whose render mode is `prerender` (what the prerender step writes).
295
+ * A prerendered route cannot have path params (there is no list of values
296
+ * to render at build time).
297
+ */
298
+ export declare function prerenderedPathsOf(table: RouteTable): readonly string[];
299
+ /**
300
+ * Whether a route shows live page presence (`presence: true` in the table).
301
+ * `NotFound` never does. Pure: a route model's selector can call it.
302
+ *
303
+ * @example
304
+ * ```ts
305
+ * routePresence(paths, matchRoute(paths, "/plans/x")); // true when PlanDetail sets `presence: true`
306
+ * ```
307
+ */
308
+ export declare function routePresence<T>(table: RoutePaths<T>, route: RouteOf<T>): boolean;