@timber-js/app 0.2.0-alpha.230 → 0.2.0-alpha.231

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 (77) hide show
  1. package/agent-skill.md +13 -0
  2. package/dist/_chunks/{actions-DHum77eH.js → actions-CYjRMpZI.js} +3 -2
  3. package/dist/_chunks/{actions-DHum77eH.js.map → actions-CYjRMpZI.js.map} +1 -1
  4. package/dist/_chunks/{cli-check-B-JZkpBD.js → cli-check-BAKOSTkg.js} +2 -2
  5. package/dist/_chunks/{cli-check-B-JZkpBD.js.map → cli-check-BAKOSTkg.js.map} +1 -1
  6. package/dist/_chunks/codec-registry-C8hOGmZo.js +13 -0
  7. package/dist/_chunks/codec-registry-C8hOGmZo.js.map +1 -0
  8. package/dist/_chunks/{codegen-B9oWkWGf.js → codegen-vaCyFyVN.js} +67 -17
  9. package/dist/_chunks/codegen-vaCyFyVN.js.map +1 -0
  10. package/dist/_chunks/{convention-lint-CrDKERHg.js → convention-lint-D54k6uUM.js} +2 -2
  11. package/dist/_chunks/{convention-lint-CrDKERHg.js.map → convention-lint-D54k6uUM.js.map} +1 -1
  12. package/dist/_chunks/href-BtspoNc9.js +164 -0
  13. package/dist/_chunks/href-BtspoNc9.js.map +1 -0
  14. package/dist/_chunks/href-validation-DNg-zV7u.js +102 -0
  15. package/dist/_chunks/href-validation-DNg-zV7u.js.map +1 -0
  16. package/dist/_chunks/merge-search-params-7o_5yX0L.js +111 -0
  17. package/dist/_chunks/merge-search-params-7o_5yX0L.js.map +1 -0
  18. package/dist/cli.js +1 -1
  19. package/dist/client/index.d.ts +2 -1
  20. package/dist/client/index.d.ts.map +1 -1
  21. package/dist/client/index.js +3 -121
  22. package/dist/client/index.js.map +1 -1
  23. package/dist/client/link.d.ts +4 -25
  24. package/dist/client/link.d.ts.map +1 -1
  25. package/dist/index.d.ts +2 -0
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +4 -1
  28. package/dist/index.js.map +1 -1
  29. package/dist/params/codec-registry.d.ts +21 -11
  30. package/dist/params/codec-registry.d.ts.map +1 -1
  31. package/dist/params/index.d.ts +0 -1
  32. package/dist/params/index.d.ts.map +1 -1
  33. package/dist/params/index.js +1 -2
  34. package/dist/params/index.js.map +1 -1
  35. package/dist/plugins/shims.d.ts.map +1 -1
  36. package/dist/routes/href.d.ts +124 -0
  37. package/dist/routes/href.d.ts.map +1 -0
  38. package/dist/routes/index.d.ts +4 -0
  39. package/dist/routes/index.d.ts.map +1 -0
  40. package/dist/routes/index.js +8 -0
  41. package/dist/routes/index.js.map +1 -0
  42. package/dist/routing/codegen.d.ts.map +1 -1
  43. package/dist/routing/index.js +1 -1
  44. package/dist/routing/link-codegen.d.ts +39 -8
  45. package/dist/routing/link-codegen.d.ts.map +1 -1
  46. package/dist/server/index.js +1 -1
  47. package/dist/server/internal.js +4 -6
  48. package/dist/server/internal.js.map +1 -1
  49. package/dist/server/param-coercion.d.ts +0 -7
  50. package/dist/server/param-coercion.d.ts.map +1 -1
  51. package/dist/server/rsc-entry/index.d.ts.map +1 -1
  52. package/dist/shared/href.d.ts +88 -0
  53. package/dist/shared/href.d.ts.map +1 -0
  54. package/docs/api/31-api-client.mdx +1 -1
  55. package/docs/api/35-api-typescript.mdx +47 -15
  56. package/docs/learn/07-typed-routes.mdx +75 -10
  57. package/package.json +5 -1
  58. package/src/client/browser-entry/index.ts +4 -4
  59. package/src/client/index.ts +3 -1
  60. package/src/client/link.tsx +5 -238
  61. package/src/index.ts +3 -0
  62. package/src/params/codec-registry.ts +24 -11
  63. package/src/params/index.ts +0 -1
  64. package/src/plugins/shims.ts +10 -0
  65. package/src/routes/href.ts +171 -0
  66. package/src/routes/index.ts +10 -0
  67. package/src/routing/codegen.ts +8 -1
  68. package/src/routing/link-codegen.ts +103 -37
  69. package/src/server/param-coercion.ts +5 -23
  70. package/src/server/rsc-entry/index.ts +6 -3
  71. package/src/server/ssr-entry.ts +2 -2
  72. package/src/shared/href.ts +257 -0
  73. package/dist/_chunks/codec-registry-CPc6bjVl.js +0 -20
  74. package/dist/_chunks/codec-registry-CPc6bjVl.js.map +0 -1
  75. package/dist/_chunks/codegen-B9oWkWGf.js.map +0 -1
  76. package/dist/_chunks/href-validation-CEZy1V-k.js +0 -210
  77. package/dist/_chunks/href-validation-CEZy1V-k.js.map +0 -1
@@ -0,0 +1,111 @@
1
+ // src/shared/slot-params.ts
2
+ /**
3
+ * The params a slot sees: the main route's as a base, the slot's own on top.
4
+ *
5
+ * Params from segments *above* the slot are not re-derived by the slot's own
6
+ * chain, so they have to come from the main route; params the slot does
7
+ * re-derive may have a different type than the main route gave them, so the
8
+ * slot's win.
9
+ *
10
+ * Null-prototype, like every other param record the framework hands out
11
+ * (`coerceSegmentParams` installs one unconditionally). A spread literal would
12
+ * inherit `Object.prototype`, so a lookup for a param the route does not
13
+ * define would resolve to an inherited member — `params.constructor` returning
14
+ * a function instead of `undefined` — in the one param record that was built
15
+ * by merging. See design/13-security.md #36c.
16
+ */
17
+ function mergeSlotParams(mainParams, slotParams) {
18
+ return Object.assign(Object.create(null), mainParams, slotParams);
19
+ }
20
+ /**
21
+ * Resolve the params for a segment path against a published slot map.
22
+ *
23
+ * Returns the merge when `segmentPath` names a slot that published params,
24
+ * and the main route's record otherwise — an ordinary (non-slot) segment
25
+ * path, an unknown path, or a request with no slots at all. Mirrors the
26
+ * server's `getSegmentParams(segmentPath)` branch exactly.
27
+ *
28
+ * `Object.hasOwn` rather than `in` or a truthiness test: the map arrives from
29
+ * JSON, so a segment path of `constructor` or `toString` would otherwise
30
+ * resolve to an inherited member of `Object.prototype`.
31
+ */
32
+ function resolveSegmentParams(mainParams, slotParams, segmentPath) {
33
+ if (!segmentPath || !slotParams || !Object.hasOwn(slotParams, segmentPath)) return mainParams;
34
+ return cachedMerge(mainParams, slotParams, segmentPath);
35
+ }
36
+ /**
37
+ * The merged record for one (main record, slot map, path) triple, reused until
38
+ * one of the three changes.
39
+ *
40
+ * `useSegmentParams(slotPath)` calls this on every render. Returning a fresh
41
+ * object each time makes the hook's result change by reference on renders where
42
+ * nothing navigated, so a component using it as a `useEffect` dependency
43
+ * re-runs the effect — and re-renders in a loop if that effect sets state —
44
+ * while memoized children below it lose their memoization.
45
+ *
46
+ * Keyed on the *identities* of the two records, not their contents: both are
47
+ * replaced rather than mutated on every navigation (`ParamsProvider`'s memoized
48
+ * value and the server's per-request store), so identity is the correct
49
+ * equality here and a deep comparison would be slower and no more accurate.
50
+ *
51
+ * A `WeakMap` chain rather than a `Map`, so a superseded navigation's records
52
+ * and their merges become collectable as soon as nothing else holds them.
53
+ */
54
+ var mergeCache = /* @__PURE__ */ new WeakMap();
55
+ function cachedMerge(mainParams, slotParams, segmentPath) {
56
+ let bySlotMap = mergeCache.get(mainParams);
57
+ if (!bySlotMap) {
58
+ bySlotMap = /* @__PURE__ */ new WeakMap();
59
+ mergeCache.set(mainParams, bySlotMap);
60
+ }
61
+ let byPath = bySlotMap.get(slotParams);
62
+ if (!byPath) {
63
+ byPath = /* @__PURE__ */ new Map();
64
+ bySlotMap.set(slotParams, byPath);
65
+ }
66
+ const cached = byPath.get(segmentPath);
67
+ if (cached) return cached;
68
+ const merged = mergeSlotParams(mainParams, slotParams[segmentPath]);
69
+ byPath.set(segmentPath, merged);
70
+ return merged;
71
+ }
72
+ // src/shared/merge-search-params.ts
73
+ /**
74
+ * Shared utility for merging preserved search params into a target URL.
75
+ *
76
+ * Used by both <Link> (client) and redirect() (server). Extracted to a shared
77
+ * module to avoid importing client code ('use client') from server modules.
78
+ */
79
+ /**
80
+ * Merge preserved search params from the current URL into a target href.
81
+ *
82
+ * When `preserve` is `true`, all current search params are merged.
83
+ * When `preserve` is a `string[]`, only the named params are merged.
84
+ *
85
+ * The target href's own search params take precedence — preserved params
86
+ * are only added if the target doesn't already define them.
87
+ *
88
+ * @param targetHref - The resolved target href (may already contain query string)
89
+ * @param currentSearch - The current URL's search string (e.g. "?private=access&page=2")
90
+ * @param preserve - `true` to preserve all, or `string[]` to preserve specific params
91
+ * @returns The target href with preserved search params merged in
92
+ */
93
+ function mergePreservedSearchParams(targetHref, currentSearch, preserve) {
94
+ const currentParams = new URLSearchParams(currentSearch);
95
+ if (currentParams.size === 0) return targetHref;
96
+ const hashIdx = targetHref.indexOf("#");
97
+ const hrefWithoutHash = hashIdx >= 0 ? targetHref.slice(0, hashIdx) : targetHref;
98
+ const hash = hashIdx >= 0 ? targetHref.slice(hashIdx) : "";
99
+ const qIdx = hrefWithoutHash.indexOf("?");
100
+ const targetPath = qIdx >= 0 ? hrefWithoutHash.slice(0, qIdx) : hrefWithoutHash;
101
+ const targetParams = new URLSearchParams(qIdx >= 0 ? hrefWithoutHash.slice(qIdx + 1) : "");
102
+ const merged = new URLSearchParams(targetParams);
103
+ for (const [key, value] of currentParams) if (!targetParams.has(key)) {
104
+ if (preserve === true || preserve.includes(key)) merged.append(key, value);
105
+ }
106
+ const qs = merged.toString();
107
+ return (qs ? `${targetPath}?${qs}` : targetPath) + hash;
108
+ }
109
+ export { resolveSegmentParams as n, mergePreservedSearchParams as t };
110
+
111
+ //# sourceMappingURL=merge-search-params-7o_5yX0L.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-search-params-7o_5yX0L.js","names":[],"sources":["../../src/shared/slot-params.ts","../../src/shared/merge-search-params.ts"],"sourcesContent":["/**\n * Per-slot segment params — the one definition both halves of the API read.\n *\n * A parallel slot matches the URL through its *own* sub-tree, so it can derive\n * a param the main route never had, or derive the same name with a different\n * type (`[...year]` → `string[]` where the main route's `[year]` gave\n * `string`). The server answers `getSegmentParams(slotPath)` from a per-slot\n * map; the client answers `useSegmentParams(slotPath)` from the same map,\n * published on the RSC payload (TIM-1285).\n *\n * The merge lives here rather than in either half because the two must agree\n * about what \"the slot's params\" are — a divergence is invisible until\n * somebody reads a param of the wrong type, which is exactly the class of bug\n * this module closes.\n *\n * Isomorphic: no server or client imports.\n *\n * See design/41-global-params.md §\"Params in a parallel slot\".\n */\n\nimport type { CoercedParams } from './param-value.ts';\n\n/** Slot tree path → that slot's own coerced params. */\nexport type SlotParamsRecord = Record<string, CoercedParams>;\n\n/**\n * The params a slot sees: the main route's as a base, the slot's own on top.\n *\n * Params from segments *above* the slot are not re-derived by the slot's own\n * chain, so they have to come from the main route; params the slot does\n * re-derive may have a different type than the main route gave them, so the\n * slot's win.\n *\n * Null-prototype, like every other param record the framework hands out\n * (`coerceSegmentParams` installs one unconditionally). A spread literal would\n * inherit `Object.prototype`, so a lookup for a param the route does not\n * define would resolve to an inherited member — `params.constructor` returning\n * a function instead of `undefined` — in the one param record that was built\n * by merging. See design/13-security.md #36c.\n */\nexport function mergeSlotParams(\n mainParams: CoercedParams,\n slotParams: CoercedParams\n): CoercedParams {\n return Object.assign(Object.create(null), mainParams, slotParams);\n}\n\n/**\n * Resolve the params for a segment path against a published slot map.\n *\n * Returns the merge when `segmentPath` names a slot that published params,\n * and the main route's record otherwise — an ordinary (non-slot) segment\n * path, an unknown path, or a request with no slots at all. Mirrors the\n * server's `getSegmentParams(segmentPath)` branch exactly.\n *\n * `Object.hasOwn` rather than `in` or a truthiness test: the map arrives from\n * JSON, so a segment path of `constructor` or `toString` would otherwise\n * resolve to an inherited member of `Object.prototype`.\n */\nexport function resolveSegmentParams(\n mainParams: CoercedParams,\n slotParams: SlotParamsRecord | null | undefined,\n segmentPath: string | undefined\n): CoercedParams {\n if (!segmentPath || !slotParams || !Object.hasOwn(slotParams, segmentPath)) return mainParams;\n return cachedMerge(mainParams, slotParams, segmentPath);\n}\n\n/**\n * The merged record for one (main record, slot map, path) triple, reused until\n * one of the three changes.\n *\n * `useSegmentParams(slotPath)` calls this on every render. Returning a fresh\n * object each time makes the hook's result change by reference on renders where\n * nothing navigated, so a component using it as a `useEffect` dependency\n * re-runs the effect — and re-renders in a loop if that effect sets state —\n * while memoized children below it lose their memoization.\n *\n * Keyed on the *identities* of the two records, not their contents: both are\n * replaced rather than mutated on every navigation (`ParamsProvider`'s memoized\n * value and the server's per-request store), so identity is the correct\n * equality here and a deep comparison would be slower and no more accurate.\n *\n * A `WeakMap` chain rather than a `Map`, so a superseded navigation's records\n * and their merges become collectable as soon as nothing else holds them.\n */\nconst mergeCache = new WeakMap<object, WeakMap<object, Map<string, CoercedParams>>>();\n\nfunction cachedMerge(\n mainParams: CoercedParams,\n slotParams: SlotParamsRecord,\n segmentPath: string\n): CoercedParams {\n let bySlotMap = mergeCache.get(mainParams);\n if (!bySlotMap) {\n bySlotMap = new WeakMap();\n mergeCache.set(mainParams, bySlotMap);\n }\n let byPath = bySlotMap.get(slotParams);\n if (!byPath) {\n byPath = new Map();\n bySlotMap.set(slotParams, byPath);\n }\n const cached = byPath.get(segmentPath);\n if (cached) return cached;\n const merged = mergeSlotParams(mainParams, slotParams[segmentPath]);\n byPath.set(segmentPath, merged);\n return merged;\n}\n","/**\n * Shared utility for merging preserved search params into a target URL.\n *\n * Used by both <Link> (client) and redirect() (server). Extracted to a shared\n * module to avoid importing client code ('use client') from server modules.\n */\n\n/**\n * Merge preserved search params from the current URL into a target href.\n *\n * When `preserve` is `true`, all current search params are merged.\n * When `preserve` is a `string[]`, only the named params are merged.\n *\n * The target href's own search params take precedence — preserved params\n * are only added if the target doesn't already define them.\n *\n * @param targetHref - The resolved target href (may already contain query string)\n * @param currentSearch - The current URL's search string (e.g. \"?private=access&page=2\")\n * @param preserve - `true` to preserve all, or `string[]` to preserve specific params\n * @returns The target href with preserved search params merged in\n */\nexport function mergePreservedSearchParams(\n targetHref: string,\n currentSearch: string,\n preserve: true | string[]\n): string {\n const currentParams = new URLSearchParams(currentSearch);\n if (currentParams.size === 0) return targetHref;\n\n // Split hash fragment from target before processing query params.\n // Hash must come after query string: /path?query=value#hash\n const hashIdx = targetHref.indexOf('#');\n const hrefWithoutHash = hashIdx >= 0 ? targetHref.slice(0, hashIdx) : targetHref;\n const hash = hashIdx >= 0 ? targetHref.slice(hashIdx) : '';\n\n // Split target into path and existing query\n const qIdx = hrefWithoutHash.indexOf('?');\n const targetPath = qIdx >= 0 ? hrefWithoutHash.slice(0, qIdx) : hrefWithoutHash;\n const targetParams = new URLSearchParams(qIdx >= 0 ? hrefWithoutHash.slice(qIdx + 1) : '');\n\n // Collect params to preserve (that aren't already in the target)\n const merged = new URLSearchParams(targetParams);\n for (const [key, value] of currentParams) {\n // Only preserve if: (a) not already in target, and (b) included in preserve list\n if (!targetParams.has(key)) {\n if (preserve === true || preserve.includes(key)) {\n merged.append(key, value);\n }\n }\n }\n\n const qs = merged.toString();\n const pathWithQuery = qs ? `${targetPath}?${qs}` : targetPath;\n return pathWithQuery + hash;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAwCA,SAAgB,gBACd,YACA,YACe;CACf,OAAO,OAAO,OAAO,OAAO,OAAO,IAAI,GAAG,YAAY,UAAU;AAClE;;;;;;;;;;;;;AAcA,SAAgB,qBACd,YACA,YACA,aACe;CACf,IAAI,CAAC,eAAe,CAAC,cAAc,CAAC,OAAO,OAAO,YAAY,WAAW,GAAG,OAAO;CACnF,OAAO,YAAY,YAAY,YAAY,WAAW;AACxD;;;;;;;;;;;;;;;;;;;AAoBA,IAAM,6BAAa,IAAI,QAA6D;AAEpF,SAAS,YACP,YACA,YACA,aACe;CACf,IAAI,YAAY,WAAW,IAAI,UAAU;CACzC,IAAI,CAAC,WAAW;EACd,4BAAY,IAAI,QAAQ;EACxB,WAAW,IAAI,YAAY,SAAS;CACtC;CACA,IAAI,SAAS,UAAU,IAAI,UAAU;CACrC,IAAI,CAAC,QAAQ;EACX,yBAAS,IAAI,IAAI;EACjB,UAAU,IAAI,YAAY,MAAM;CAClC;CACA,MAAM,SAAS,OAAO,IAAI,WAAW;CACrC,IAAI,QAAQ,OAAO;CACnB,MAAM,SAAS,gBAAgB,YAAY,WAAW,YAAY;CAClE,OAAO,IAAI,aAAa,MAAM;CAC9B,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;ACvFA,SAAgB,2BACd,YACA,eACA,UACQ;CACR,MAAM,gBAAgB,IAAI,gBAAgB,aAAa;CACvD,IAAI,cAAc,SAAS,GAAG,OAAO;CAIrC,MAAM,UAAU,WAAW,QAAQ,GAAG;CACtC,MAAM,kBAAkB,WAAW,IAAI,WAAW,MAAM,GAAG,OAAO,IAAI;CACtE,MAAM,OAAO,WAAW,IAAI,WAAW,MAAM,OAAO,IAAI;CAGxD,MAAM,OAAO,gBAAgB,QAAQ,GAAG;CACxC,MAAM,aAAa,QAAQ,IAAI,gBAAgB,MAAM,GAAG,IAAI,IAAI;CAChE,MAAM,eAAe,IAAI,gBAAgB,QAAQ,IAAI,gBAAgB,MAAM,OAAO,CAAC,IAAI,EAAE;CAGzF,MAAM,SAAS,IAAI,gBAAgB,YAAY;CAC/C,KAAK,MAAM,CAAC,KAAK,UAAU,eAEzB,IAAI,CAAC,aAAa,IAAI,GAAG,GACnB;MAAA,aAAa,QAAQ,SAAS,SAAS,GAAG,GAC5C,OAAO,OAAO,KAAK,KAAK;CAAA;CAK9B,MAAM,KAAK,OAAO,SAAS;CAE3B,QADsB,KAAK,GAAG,WAAW,GAAG,OAAO,cAC5B;AACzB"}
package/dist/cli.js CHANGED
@@ -179,7 +179,7 @@ async function runPreview(options, _deps) {
179
179
  * `--project` names the tsconfig handed to tsgo.
180
180
  */
181
181
  async function runCheck(options, _deps) {
182
- const { checkRoutes, runTypeCheck } = await import("./_chunks/cli-check-B-JZkpBD.js");
182
+ const { checkRoutes, runTypeCheck } = await import("./_chunks/cli-check-BAKOSTkg.js");
183
183
  const { root } = await checkRoutes({ viteConfigFile: options.config }, _deps);
184
184
  await runTypeCheck({
185
185
  root,
@@ -1,4 +1,5 @@
1
- export { Link, interpolateParams, resolveHref, validateLinkHref, buildLinkProps } from './link.tsx';
1
+ export { Link, validateLinkHref, buildLinkProps } from './link.tsx';
2
+ export { interpolateParams, resolveHref } from '../shared/href.ts';
2
3
  export { mergePreservedSearchParams } from '../shared/merge-search-params.ts';
3
4
  export type { LinkProps, LinkPropsWithHref, LinkPropsWithParams, LinkBaseProps } from './link.tsx';
4
5
  export type { LinkSegmentParams, OnNavigateHandler, OnNavigateEvent } from './link.tsx';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,WAAW,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACpG,OAAO,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC;AAC9E,YAAY,EAAE,SAAS,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACnG,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AA4CxF,MAAM,WAAW,YAAY;CAG5B;AACD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,YAAY,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACxE,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC1E,YAAY,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EACL,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAK7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAY3D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAIvD,YAAY,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEpE,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC;AAC9E,YAAY,EAAE,SAAS,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACnG,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AA4CxF,MAAM,WAAW,YAAY;CAG5B;AACD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,YAAY,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACxE,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC1E,YAAY,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EACL,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAK7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAY3D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAIvD,YAAY,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
@@ -1,12 +1,12 @@
1
1
  "use client";
2
- import { n as classifyUrlSegment } from "../_chunks/segment-classify-Ho8jXWeC.js";
3
2
  import { c as stripRscCacheKey } from "../_chunks/rsc-cache-key-D0cb0Gmc.js";
4
- import { a as mergePreservedSearchParams, i as validateNavigationHref, n as isInternalHref, o as resolveSegmentParams } from "../_chunks/href-validation-CEZy1V-k.js";
3
+ import { n as resolveSegmentParams, t as mergePreservedSearchParams } from "../_chunks/merge-search-params-7o_5yX0L.js";
4
+ import { i as validateNavigationHref, n as isInternalHref } from "../_chunks/href-validation-DNg-zV7u.js";
5
5
  import "../_chunks/param-value-DqlGfF57.js";
6
6
  import { t as createGlobalContext } from "../_chunks/global-context-CFSSysdJ.js";
7
+ import { n as interpolateParams, r as resolveHref } from "../_chunks/href-BtspoNc9.js";
7
8
  import { i as useNavigationContext, n as usePendingNavigation, o as getRouterOrNull } from "../_chunks/navigation-root-CoGHIMiE.js";
8
9
  import { t as getSsrData } from "../_chunks/ssr-data-9hPtcNOr.js";
9
- import { t as getLinkCodec } from "../_chunks/codec-registry-CPc6bjVl.js";
10
10
  import { n as useSegmentContext } from "../_chunks/segment-context-GAyTjjtS.js";
11
11
  import { n as useQueryStates } from "../_chunks/use-query-states-pkDV-jSg.js";
12
12
  import React, { createContext, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState } from "react";
@@ -82,124 +82,6 @@ function isNativeFragmentLink(anchor) {
82
82
  return hashIndex !== -1 && href.slice(0, hashIndex) === window.location.href.split("#", 1)[0];
83
83
  }
84
84
  /**
85
- * Interpolate dynamic segments in a route pattern with actual values.
86
- * e.g. interpolateParams("/products/[id]", { id: "123" }) → "/products/123"
87
- *
88
- * Supports:
89
- * - [param] → single segment
90
- * - [...param] → catch-all (joined with /)
91
- * - [[...param]] → optional catch-all (omitted if undefined/empty)
92
- */
93
- /**
94
- * Parse a route pattern's path portion into classified segments.
95
- * Exported for testing. Uses the shared character-based classifier.
96
- */
97
- function parseSegments(pattern) {
98
- return pattern.split("/").filter(Boolean).map(classifyUrlSegment);
99
- }
100
- /**
101
- * Resolve a single classified segment into its string representation.
102
- * Returns null for optional catch-all with no value (filtered out before join).
103
- *
104
- * When schema codecs are registered (via virtual:timber-schema), uses
105
- * codec.serialize() for URL construction instead of plain String().
106
- */
107
- function resolveSegment(seg, params, pattern) {
108
- switch (seg.kind) {
109
- case "static": return seg.value;
110
- case "optional-catch-all": {
111
- const value = params[seg.name];
112
- if (value === void 0 || Array.isArray(value) && value.length === 0) return null;
113
- const codec = getLinkCodec(`[[...${seg.name}]]`);
114
- if (codec) {
115
- const serialized = codec.serialize(value);
116
- if (!serialized) return null;
117
- return serialized.split("/").map(encodeURIComponent).join("/");
118
- }
119
- return (Array.isArray(value) ? value : [value]).map(encodeURIComponent).join("/");
120
- }
121
- case "catch-all": {
122
- const value = params[seg.name];
123
- if (value === void 0) throw new Error(`<Link> missing required catch-all param "${seg.name}" for pattern "${pattern}".`);
124
- const codec = getLinkCodec(`[...${seg.name}]`);
125
- if (codec) {
126
- const serialized = codec.serialize(value);
127
- if (!serialized) throw new Error(`<Link> catch-all param "${seg.name}" codec returned null for pattern "${pattern}".`);
128
- return serialized.split("/").map(encodeURIComponent).join("/");
129
- }
130
- const segments = Array.isArray(value) ? value : [value];
131
- if (segments.length === 0) throw new Error(`<Link> catch-all param "${seg.name}" must have at least one segment for pattern "${pattern}".`);
132
- return segments.map(encodeURIComponent).join("/");
133
- }
134
- case "dynamic": {
135
- const value = params[seg.name];
136
- if (value === void 0) throw new Error(`<Link> missing required param "${seg.name}" for pattern "${pattern}".`);
137
- if (Array.isArray(value)) throw new Error(`<Link> param "${seg.name}" expected a string but received an array for pattern "${pattern}".`);
138
- const codec = getLinkCodec(`[${seg.name}]`);
139
- const str = codec ? codec.serialize(value) ?? String(value) : String(value);
140
- const encoded = encodeURIComponent(str);
141
- const prefix = seg.prefix ?? "";
142
- const suffix = seg.suffix ?? "";
143
- return prefix + encoded + suffix;
144
- }
145
- }
146
- }
147
- /**
148
- * Split a URL pattern into the path portion and any trailing ?query/#hash suffix.
149
- * Uses URL parsing for correctness rather than manual index arithmetic.
150
- */
151
- function splitPatternSuffix(pattern) {
152
- if (!pattern.includes("?") && !pattern.includes("#")) return [pattern, ""];
153
- const url = new URL(pattern, "http://x");
154
- const suffix = url.search + url.hash;
155
- return [pattern.slice(0, pattern.length - suffix.length), suffix];
156
- }
157
- function interpolateParams(pattern, params) {
158
- const [pathPart, suffix] = splitPatternSuffix(pattern);
159
- return ("/" + parseSegments(pathPart).map((seg) => resolveSegment(seg, params, pattern)).filter((s) => s !== null).join("/") || "/") + suffix;
160
- }
161
- /**
162
- * Resolve the final href string from Link props.
163
- *
164
- * Handles:
165
- * - params interpolation into route patterns
166
- * - searchParams serialization (see the two shapes documented above)
167
- * - Validation that searchParams and inline query strings are exclusive
168
- */
169
- /**
170
- * Tolerate a leading '?'. `buildSearchParams()` never emits one, but callers
171
- * hand-rolling a query string reasonably might, and silently producing
172
- * `?%3Fa=b` for it would be a worse failure than accepting both.
173
- */
174
- function stripLeadingQuestionMark(qs) {
175
- return qs.startsWith("?") ? qs.slice(1) : qs;
176
- }
177
- /**
178
- * Escape-hatch serialization for a plain object: String()-coerce every
179
- * value, append arrays as repeated keys, skip null/undefined.
180
- *
181
- * Deliberately codec-free and alias-free — see the shape docs above.
182
- */
183
- function coerceToQueryString(values) {
184
- const usp = new URLSearchParams();
185
- for (const [key, val] of Object.entries(values)) {
186
- if (val === void 0 || val === null) continue;
187
- if (Array.isArray(val)) for (const item of val) usp.append(key, String(item));
188
- else usp.set(key, String(val));
189
- }
190
- return usp.toString();
191
- }
192
- function resolveHref(href, params, searchParams) {
193
- let resolvedPath = href;
194
- if (params) resolvedPath = interpolateParams(href, params);
195
- if (searchParams) {
196
- if (resolvedPath.includes("?")) throw new Error("<Link> received both a searchParams prop and a query string in href. These are mutually exclusive — use one or the other.");
197
- const qs = typeof searchParams === "string" ? stripLeadingQuestionMark(searchParams) : coerceToQueryString(searchParams);
198
- if (qs) resolvedPath = `${resolvedPath}?${qs}`;
199
- }
200
- return resolvedPath;
201
- }
202
- /**
203
85
  * Build the HTML attributes for a Link. Separated from the component
204
86
  * for testability — the component just spreads these onto an <a>.
205
87
  */