@timber-js/app 0.2.0-alpha.16 → 0.2.0-alpha.161

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 (998) hide show
  1. package/LICENSE +8 -0
  2. package/agent-skill.md +344 -0
  3. package/dist/_chunks/actions-cjklt63G.js +317 -0
  4. package/dist/_chunks/actions-cjklt63G.js.map +1 -0
  5. package/dist/_chunks/build-output-helper-DF5uScqS.js +158 -0
  6. package/dist/_chunks/build-output-helper-DF5uScqS.js.map +1 -0
  7. package/dist/_chunks/cache-api-CzYUlgXA.js +1125 -0
  8. package/dist/_chunks/cache-api-CzYUlgXA.js.map +1 -0
  9. package/dist/_chunks/{metadata-routes-Cjmvi3rQ.js → canonicalize-P41GR6tY.js} +94 -18
  10. package/dist/_chunks/canonicalize-P41GR6tY.js.map +1 -0
  11. package/dist/_chunks/cli-schema-sync-NfLbLnDw.js +638 -0
  12. package/dist/_chunks/cli-schema-sync-NfLbLnDw.js.map +1 -0
  13. package/dist/_chunks/codec-registry-oOUxugz3.js +21 -0
  14. package/dist/_chunks/codec-registry-oOUxugz3.js.map +1 -0
  15. package/dist/_chunks/define-Bssfp6ot.js +82 -0
  16. package/dist/_chunks/define-Bssfp6ot.js.map +1 -0
  17. package/dist/_chunks/define-CFmvb4Bt.js +203 -0
  18. package/dist/_chunks/define-CFmvb4Bt.js.map +1 -0
  19. package/dist/_chunks/dist-BA3u1z3W.js +423 -0
  20. package/dist/_chunks/dist-BA3u1z3W.js.map +1 -0
  21. package/dist/_chunks/fast-hash-D6hIVt1Y.js +36 -0
  22. package/dist/_chunks/fast-hash-D6hIVt1Y.js.map +1 -0
  23. package/dist/_chunks/format-CfwjgPz9.js +14 -0
  24. package/dist/_chunks/format-CfwjgPz9.js.map +1 -0
  25. package/dist/_chunks/href-validation-CMc5JRls.js +141 -0
  26. package/dist/_chunks/href-validation-CMc5JRls.js.map +1 -0
  27. package/dist/_chunks/logger-B_O6-mdJ.js +1485 -0
  28. package/dist/_chunks/logger-B_O6-mdJ.js.map +1 -0
  29. package/dist/_chunks/navigation-root-bUDZLw74.js +124 -0
  30. package/dist/_chunks/navigation-root-bUDZLw74.js.map +1 -0
  31. package/dist/_chunks/plugin-context-DeAxFRMq.js +280 -0
  32. package/dist/_chunks/plugin-context-DeAxFRMq.js.map +1 -0
  33. package/dist/_chunks/registry-DbJPKoBp.js +20 -0
  34. package/dist/_chunks/registry-DbJPKoBp.js.map +1 -0
  35. package/dist/_chunks/resolve-schema-3iUvBV5T.js +50 -0
  36. package/dist/_chunks/resolve-schema-3iUvBV5T.js.map +1 -0
  37. package/dist/_chunks/router-ref-CtmF-aPv.js +28 -0
  38. package/dist/_chunks/router-ref-CtmF-aPv.js.map +1 -0
  39. package/dist/_chunks/schema-bridge-BY3QLBL7.js +119 -0
  40. package/dist/_chunks/schema-bridge-BY3QLBL7.js.map +1 -0
  41. package/dist/_chunks/segment-classify-CDDRVKs7.js +137 -0
  42. package/dist/_chunks/segment-classify-CDDRVKs7.js.map +1 -0
  43. package/dist/_chunks/segment-context-ZDnXDkbz.js +34 -0
  44. package/dist/_chunks/segment-context-ZDnXDkbz.js.map +1 -0
  45. package/dist/_chunks/sizeof-lXffQ1Vr.js +35 -0
  46. package/dist/_chunks/sizeof-lXffQ1Vr.js.map +1 -0
  47. package/dist/_chunks/{ssr-data-MjmprTmO.js → ssr-data-BOWsq18U.js} +1 -1
  48. package/dist/_chunks/ssr-data-BOWsq18U.js.map +1 -0
  49. package/dist/_chunks/tree-match-D2l830j2.js +102 -0
  50. package/dist/_chunks/tree-match-D2l830j2.js.map +1 -0
  51. package/dist/_chunks/{use-query-states-D5KaffOK.js → use-query-states-CbeQmext.js} +7 -20
  52. package/dist/_chunks/use-query-states-CbeQmext.js.map +1 -0
  53. package/dist/_chunks/use-segment-params-D1CzlgBo.js +151 -0
  54. package/dist/_chunks/use-segment-params-D1CzlgBo.js.map +1 -0
  55. package/dist/_chunks/walkers-9mz9T7mb.js +988 -0
  56. package/dist/_chunks/walkers-9mz9T7mb.js.map +1 -0
  57. package/dist/adapters/build-output-helper.d.ts +29 -0
  58. package/dist/adapters/build-output-helper.d.ts.map +1 -0
  59. package/dist/adapters/cloudflare-dev.d.ts +109 -0
  60. package/dist/adapters/cloudflare-dev.d.ts.map +1 -0
  61. package/dist/adapters/cloudflare-dev.js +73 -0
  62. package/dist/adapters/cloudflare-dev.js.map +1 -0
  63. package/dist/adapters/cloudflare-kv-cache.d.ts +64 -0
  64. package/dist/adapters/cloudflare-kv-cache.d.ts.map +1 -0
  65. package/dist/adapters/cloudflare-kv-cache.js +117 -0
  66. package/dist/adapters/cloudflare-kv-cache.js.map +1 -0
  67. package/dist/adapters/cloudflare.d.ts +177 -20
  68. package/dist/adapters/cloudflare.d.ts.map +1 -1
  69. package/dist/adapters/cloudflare.js +337 -64
  70. package/dist/adapters/cloudflare.js.map +1 -1
  71. package/dist/adapters/compress-module.d.ts +5 -4
  72. package/dist/adapters/compress-module.d.ts.map +1 -1
  73. package/dist/adapters/nitro.d.ts +1 -3
  74. package/dist/adapters/nitro.d.ts.map +1 -1
  75. package/dist/adapters/nitro.js +144 -152
  76. package/dist/adapters/nitro.js.map +1 -1
  77. package/dist/adapters/shared.d.ts +6 -0
  78. package/dist/adapters/shared.d.ts.map +1 -0
  79. package/dist/adapters/types.d.ts +0 -6
  80. package/dist/adapters/types.d.ts.map +1 -1
  81. package/dist/cache/cache-api.d.ts +26 -0
  82. package/dist/cache/cache-api.d.ts.map +1 -0
  83. package/dist/cache/handler-store.d.ts +33 -0
  84. package/dist/cache/handler-store.d.ts.map +1 -0
  85. package/dist/cache/index.d.ts +27 -7
  86. package/dist/cache/index.d.ts.map +1 -1
  87. package/dist/cache/index.js +3 -326
  88. package/dist/cache/invalidation-epoch.d.ts +43 -0
  89. package/dist/cache/invalidation-epoch.d.ts.map +1 -0
  90. package/dist/cache/redis-handler.d.ts +97 -8
  91. package/dist/cache/redis-handler.d.ts.map +1 -1
  92. package/dist/cache/singleflight.d.ts +19 -2
  93. package/dist/cache/singleflight.d.ts.map +1 -1
  94. package/dist/cache/sizeof.d.ts +22 -0
  95. package/dist/cache/sizeof.d.ts.map +1 -0
  96. package/dist/cache/stable-stringify.d.ts +9 -0
  97. package/dist/cache/stable-stringify.d.ts.map +1 -1
  98. package/dist/cache/store.d.ts +53 -0
  99. package/dist/cache/store.d.ts.map +1 -0
  100. package/dist/cache/stores/cloudflare-kv.d.ts +38 -0
  101. package/dist/cache/stores/cloudflare-kv.d.ts.map +1 -0
  102. package/dist/cache/stores/cloudflare-kv.js +29 -0
  103. package/dist/cache/stores/cloudflare-kv.js.map +1 -0
  104. package/dist/cache/stores/memory.d.ts +42 -0
  105. package/dist/cache/stores/memory.d.ts.map +1 -0
  106. package/dist/cache/stores/memory.js +90 -0
  107. package/dist/cache/stores/memory.js.map +1 -0
  108. package/dist/cache/stores/redis.d.ts +69 -0
  109. package/dist/cache/stores/redis.d.ts.map +1 -0
  110. package/dist/cache/stores/redis.js +35 -0
  111. package/dist/cache/stores/redis.js.map +1 -0
  112. package/dist/cache/stores/vercel.d.ts +36 -0
  113. package/dist/cache/stores/vercel.d.ts.map +1 -0
  114. package/dist/cache/stores/vercel.js +33 -0
  115. package/dist/cache/stores/vercel.js.map +1 -0
  116. package/dist/cache/tag-aware-handler.d.ts +51 -0
  117. package/dist/cache/tag-aware-handler.d.ts.map +1 -0
  118. package/dist/cache/timber-cache.d.ts +20 -10
  119. package/dist/cache/timber-cache.d.ts.map +1 -1
  120. package/dist/cdn/cloudflare-purge.d.ts +23 -0
  121. package/dist/cdn/cloudflare-purge.d.ts.map +1 -0
  122. package/dist/cdn/fastly-purge.d.ts +25 -0
  123. package/dist/cdn/fastly-purge.d.ts.map +1 -0
  124. package/dist/cdn/headers.d.ts +97 -0
  125. package/dist/cdn/headers.d.ts.map +1 -0
  126. package/dist/cdn/index.d.ts +5 -0
  127. package/dist/cdn/index.d.ts.map +1 -0
  128. package/dist/cdn/purge-store.d.ts +23 -0
  129. package/dist/cdn/purge-store.d.ts.map +1 -0
  130. package/dist/cdn/workers-cache-purge.d.ts +16 -0
  131. package/dist/cdn/workers-cache-purge.d.ts.map +1 -0
  132. package/dist/cli-schema-sync.d.ts +59 -0
  133. package/dist/cli-schema-sync.d.ts.map +1 -0
  134. package/dist/cli.d.ts +34 -2
  135. package/dist/cli.d.ts.map +1 -1
  136. package/dist/cli.js +107 -33
  137. package/dist/cli.js.map +1 -1
  138. package/dist/client/browser-dev.d.ts +37 -1
  139. package/dist/client/browser-dev.d.ts.map +1 -1
  140. package/dist/client/browser-entry/action-dispatch.d.ts +17 -0
  141. package/dist/client/browser-entry/action-dispatch.d.ts.map +1 -0
  142. package/dist/client/browser-entry/hmr.d.ts +21 -0
  143. package/dist/client/browser-entry/hmr.d.ts.map +1 -0
  144. package/dist/client/browser-entry/hydrate.d.ts +46 -0
  145. package/dist/client/browser-entry/hydrate.d.ts.map +1 -0
  146. package/dist/client/browser-entry/index.d.ts +29 -0
  147. package/dist/client/browser-entry/index.d.ts.map +1 -0
  148. package/dist/client/browser-entry/post-hydration.d.ts +26 -0
  149. package/dist/client/browser-entry/post-hydration.d.ts.map +1 -0
  150. package/dist/client/browser-entry/router-init.d.ts +26 -0
  151. package/dist/client/browser-entry/router-init.d.ts.map +1 -0
  152. package/dist/client/browser-entry/rsc-stream.d.ts +24 -0
  153. package/dist/client/browser-entry/rsc-stream.d.ts.map +1 -0
  154. package/dist/client/browser-entry/scroll.d.ts +28 -0
  155. package/dist/client/browser-entry/scroll.d.ts.map +1 -0
  156. package/dist/client/child-segment-context.d.ts +22 -0
  157. package/dist/client/child-segment-context.d.ts.map +1 -0
  158. package/dist/client/child-segment-outlet.d.ts +18 -0
  159. package/dist/client/child-segment-outlet.d.ts.map +1 -0
  160. package/dist/client/child-segment-provider.d.ts +21 -0
  161. package/dist/client/child-segment-provider.d.ts.map +1 -0
  162. package/dist/client/error-boundary.d.ts +12 -5
  163. package/dist/client/error-boundary.d.ts.map +1 -1
  164. package/dist/client/error-boundary.js +47 -10
  165. package/dist/client/error-boundary.js.map +1 -1
  166. package/dist/client/error-reconstituter.d.ts +61 -0
  167. package/dist/client/error-reconstituter.d.ts.map +1 -0
  168. package/dist/client/form.d.ts +16 -27
  169. package/dist/client/form.d.ts.map +1 -1
  170. package/dist/client/history.d.ts +11 -6
  171. package/dist/client/history.d.ts.map +1 -1
  172. package/dist/client/index.d.ts +10 -24
  173. package/dist/client/index.d.ts.map +1 -1
  174. package/dist/client/index.js +182 -1134
  175. package/dist/client/index.js.map +1 -1
  176. package/dist/client/internal.d.ts +19 -0
  177. package/dist/client/internal.d.ts.map +1 -0
  178. package/dist/client/internal.js +825 -0
  179. package/dist/client/internal.js.map +1 -0
  180. package/dist/client/link.d.ts +69 -60
  181. package/dist/client/link.d.ts.map +1 -1
  182. package/dist/client/navigation-api.d.ts +120 -0
  183. package/dist/client/navigation-api.d.ts.map +1 -0
  184. package/dist/client/navigation-context.d.ts +3 -2
  185. package/dist/client/navigation-context.d.ts.map +1 -1
  186. package/dist/client/navigation-root.d.ts +119 -0
  187. package/dist/client/navigation-root.d.ts.map +1 -0
  188. package/dist/client/nuqs-adapter.d.ts +1 -1
  189. package/dist/client/nuqs-adapter.d.ts.map +1 -1
  190. package/dist/client/router-ref.d.ts +1 -1
  191. package/dist/client/router.d.ts +87 -14
  192. package/dist/client/router.d.ts.map +1 -1
  193. package/dist/client/rsc-fetch.d.ts +47 -14
  194. package/dist/client/rsc-fetch.d.ts.map +1 -1
  195. package/dist/client/segment-cache.d.ts +4 -4
  196. package/dist/client/segment-cache.d.ts.map +1 -1
  197. package/dist/client/segment-outlet.d.ts +49 -0
  198. package/dist/client/segment-outlet.d.ts.map +1 -0
  199. package/dist/client/segment-update-context.d.ts +21 -0
  200. package/dist/client/segment-update-context.d.ts.map +1 -0
  201. package/dist/client/shallow-url.d.ts +10 -0
  202. package/dist/client/shallow-url.d.ts.map +1 -0
  203. package/dist/client/ssr-data.d.ts +13 -4
  204. package/dist/client/ssr-data.d.ts.map +1 -1
  205. package/dist/client/state.d.ts +1 -1
  206. package/dist/client/top-loader.d.ts +5 -5
  207. package/dist/client/top-loader.d.ts.map +1 -1
  208. package/dist/client/use-cookie.d.ts +12 -0
  209. package/dist/client/use-cookie.d.ts.map +1 -1
  210. package/dist/client/use-link-status.d.ts +5 -5
  211. package/dist/client/use-link-status.d.ts.map +1 -1
  212. package/dist/client/use-pathname.d.ts.map +1 -1
  213. package/dist/client/use-pending-navigation.d.ts +23 -0
  214. package/dist/client/use-pending-navigation.d.ts.map +1 -0
  215. package/dist/client/use-query-states.d.ts +1 -1
  216. package/dist/client/use-query-states.d.ts.map +1 -1
  217. package/dist/client/use-router.d.ts +1 -1
  218. package/dist/client/use-router.d.ts.map +1 -1
  219. package/dist/client/use-search-params.d.ts +12 -5
  220. package/dist/client/use-search-params.d.ts.map +1 -1
  221. package/dist/client/{use-params.d.ts → use-segment-params.d.ts} +8 -6
  222. package/dist/client/use-segment-params.d.ts.map +1 -0
  223. package/dist/codec.d.ts +69 -0
  224. package/dist/codec.d.ts.map +1 -0
  225. package/dist/codec.js +75 -0
  226. package/dist/codec.js.map +1 -0
  227. package/dist/config-types.d.ts +304 -0
  228. package/dist/config-types.d.ts.map +1 -0
  229. package/dist/config-validation.d.ts +51 -0
  230. package/dist/config-validation.d.ts.map +1 -0
  231. package/dist/content/index.d.ts +1 -10
  232. package/dist/content/index.d.ts.map +1 -1
  233. package/dist/content/index.js +0 -2
  234. package/dist/cookies/define-cookie.d.ts +58 -25
  235. package/dist/cookies/define-cookie.d.ts.map +1 -1
  236. package/dist/cookies/index.d.ts +2 -1
  237. package/dist/cookies/index.d.ts.map +1 -1
  238. package/dist/cookies/index.js +257 -36
  239. package/dist/cookies/index.js.map +1 -1
  240. package/dist/cookies/json-cookie.d.ts +64 -0
  241. package/dist/cookies/json-cookie.d.ts.map +1 -0
  242. package/dist/cookies/validation.d.ts +34 -0
  243. package/dist/cookies/validation.d.ts.map +1 -0
  244. package/dist/dev-tools/404-page.d.ts +50 -0
  245. package/dist/dev-tools/404-page.d.ts.map +1 -0
  246. package/dist/dev-tools/browser-logs.d.ts +40 -0
  247. package/dist/dev-tools/browser-logs.d.ts.map +1 -0
  248. package/dist/dev-tools/dev-page-shell.d.ts +78 -0
  249. package/dist/dev-tools/dev-page-shell.d.ts.map +1 -0
  250. package/dist/dev-tools/error-page.d.ts +32 -0
  251. package/dist/dev-tools/error-page.d.ts.map +1 -0
  252. package/dist/dev-tools/holding-server.d.ts +54 -0
  253. package/dist/dev-tools/holding-server.d.ts.map +1 -0
  254. package/dist/dev-tools/hydration-overlay.d.ts +11 -0
  255. package/dist/dev-tools/hydration-overlay.d.ts.map +1 -0
  256. package/dist/dev-tools/index.d.ts +31 -0
  257. package/dist/dev-tools/index.d.ts.map +1 -0
  258. package/dist/dev-tools/instrumentation.d.ts +59 -0
  259. package/dist/dev-tools/instrumentation.d.ts.map +1 -0
  260. package/dist/{server/dev-logger.d.ts → dev-tools/logger.d.ts} +1 -1
  261. package/dist/dev-tools/logger.d.ts.map +1 -0
  262. package/dist/{plugins/dev-logs.d.ts → dev-tools/logs.d.ts} +2 -2
  263. package/dist/dev-tools/logs.d.ts.map +1 -0
  264. package/dist/dev-tools/overlay.d.ts +91 -0
  265. package/dist/dev-tools/overlay.d.ts.map +1 -0
  266. package/dist/dev-tools/stack-classifier.d.ts +34 -0
  267. package/dist/dev-tools/stack-classifier.d.ts.map +1 -0
  268. package/dist/dev-tools/terminal.d.ts +28 -0
  269. package/dist/dev-tools/terminal.d.ts.map +1 -0
  270. package/dist/fonts/ast-walk.d.ts +68 -0
  271. package/dist/fonts/ast-walk.d.ts.map +1 -0
  272. package/dist/fonts/ast.d.ts +110 -6
  273. package/dist/fonts/ast.d.ts.map +1 -1
  274. package/dist/fonts/bundle.d.ts +50 -0
  275. package/dist/fonts/bundle.d.ts.map +1 -0
  276. package/dist/fonts/dev-middleware.d.ts +22 -0
  277. package/dist/fonts/dev-middleware.d.ts.map +1 -0
  278. package/dist/fonts/fallbacks.d.ts +0 -7
  279. package/dist/fonts/fallbacks.d.ts.map +1 -1
  280. package/dist/fonts/google.d.ts +4 -2
  281. package/dist/fonts/google.d.ts.map +1 -1
  282. package/dist/fonts/local.d.ts +4 -4
  283. package/dist/fonts/local.d.ts.map +1 -1
  284. package/dist/fonts/paths.d.ts +43 -0
  285. package/dist/fonts/paths.d.ts.map +1 -0
  286. package/dist/fonts/pipeline.d.ts +158 -0
  287. package/dist/fonts/pipeline.d.ts.map +1 -0
  288. package/dist/fonts/transform.d.ts +82 -0
  289. package/dist/fonts/transform.d.ts.map +1 -0
  290. package/dist/fonts/types.d.ts +47 -1
  291. package/dist/fonts/types.d.ts.map +1 -1
  292. package/dist/fonts/virtual-modules.d.ts +77 -0
  293. package/dist/fonts/virtual-modules.d.ts.map +1 -0
  294. package/dist/index.d.ts +46 -180
  295. package/dist/index.d.ts.map +1 -1
  296. package/dist/index.js +8471 -14108
  297. package/dist/index.js.map +1 -1
  298. package/dist/params/codec-registry.d.ts +26 -0
  299. package/dist/params/codec-registry.d.ts.map +1 -0
  300. package/dist/params/define-schema.d.ts +81 -0
  301. package/dist/params/define-schema.d.ts.map +1 -0
  302. package/dist/params/index.d.ts +5 -0
  303. package/dist/params/index.d.ts.map +1 -0
  304. package/dist/params/index.js +34 -0
  305. package/dist/params/index.js.map +1 -0
  306. package/dist/params/resolve-schema.d.ts +34 -0
  307. package/dist/params/resolve-schema.d.ts.map +1 -0
  308. package/dist/plugin-context.d.ts +190 -0
  309. package/dist/plugin-context.d.ts.map +1 -0
  310. package/dist/plugins/adapter-build.d.ts +20 -1
  311. package/dist/plugins/adapter-build.d.ts.map +1 -1
  312. package/dist/plugins/build-manifest.d.ts +7 -3
  313. package/dist/plugins/build-manifest.d.ts.map +1 -1
  314. package/dist/plugins/build-report.d.ts +43 -7
  315. package/dist/plugins/build-report.d.ts.map +1 -1
  316. package/dist/plugins/cache.d.ts +64 -0
  317. package/dist/plugins/cache.d.ts.map +1 -0
  318. package/dist/plugins/callsite-ast.d.ts +117 -0
  319. package/dist/plugins/callsite-ast.d.ts.map +1 -0
  320. package/dist/plugins/callsite-jsx.d.ts +35 -0
  321. package/dist/plugins/callsite-jsx.d.ts.map +1 -0
  322. package/dist/plugins/chunks.d.ts +11 -4
  323. package/dist/plugins/chunks.d.ts.map +1 -1
  324. package/dist/plugins/client-chunks.d.ts +40 -0
  325. package/dist/plugins/client-chunks.d.ts.map +1 -0
  326. package/dist/plugins/cloudflare-wasm.d.ts +21 -0
  327. package/dist/plugins/cloudflare-wasm.d.ts.map +1 -0
  328. package/dist/plugins/content.d.ts +1 -1
  329. package/dist/plugins/content.d.ts.map +1 -1
  330. package/dist/plugins/dev-server.d.ts +17 -1
  331. package/dist/plugins/dev-server.d.ts.map +1 -1
  332. package/dist/plugins/entries.d.ts +1 -1
  333. package/dist/plugins/entries.d.ts.map +1 -1
  334. package/dist/plugins/fonts.d.ts +16 -73
  335. package/dist/plugins/fonts.d.ts.map +1 -1
  336. package/dist/plugins/mdx.d.ts +1 -1
  337. package/dist/plugins/mdx.d.ts.map +1 -1
  338. package/dist/plugins/prebuilt-capture.d.ts +60 -0
  339. package/dist/plugins/prebuilt-capture.d.ts.map +1 -0
  340. package/dist/plugins/prebuilt.d.ts +82 -0
  341. package/dist/plugins/prebuilt.d.ts.map +1 -0
  342. package/dist/plugins/prerender-sugar.d.ts +42 -0
  343. package/dist/plugins/prerender-sugar.d.ts.map +1 -0
  344. package/dist/plugins/routing.d.ts +1 -1
  345. package/dist/plugins/routing.d.ts.map +1 -1
  346. package/dist/plugins/server-bundle.d.ts.map +1 -1
  347. package/dist/plugins/shims.d.ts +29 -5
  348. package/dist/plugins/shims.d.ts.map +1 -1
  349. package/dist/plugins/static-build.d.ts +5 -26
  350. package/dist/plugins/static-build.d.ts.map +1 -1
  351. package/dist/routing/codegen-shared.d.ts +67 -0
  352. package/dist/routing/codegen-shared.d.ts.map +1 -0
  353. package/dist/routing/codegen-types.d.ts +64 -0
  354. package/dist/routing/codegen-types.d.ts.map +1 -0
  355. package/dist/routing/codegen.d.ts +7 -2
  356. package/dist/routing/codegen.d.ts.map +1 -1
  357. package/dist/routing/convention-lint.d.ts +41 -0
  358. package/dist/routing/convention-lint.d.ts.map +1 -0
  359. package/dist/routing/export-detect.d.ts +56 -0
  360. package/dist/routing/export-detect.d.ts.map +1 -0
  361. package/dist/routing/file-cache.d.ts +8 -0
  362. package/dist/routing/file-cache.d.ts.map +1 -0
  363. package/dist/routing/index.d.ts +7 -1
  364. package/dist/routing/index.d.ts.map +1 -1
  365. package/dist/routing/index.js +4 -2
  366. package/dist/routing/interception.d.ts +0 -5
  367. package/dist/routing/interception.d.ts.map +1 -1
  368. package/dist/routing/link-codegen.d.ts +90 -0
  369. package/dist/routing/link-codegen.d.ts.map +1 -0
  370. package/dist/routing/manifest-codegen.d.ts +32 -0
  371. package/dist/routing/manifest-codegen.d.ts.map +1 -0
  372. package/dist/routing/scanner.d.ts +1 -10
  373. package/dist/routing/scanner.d.ts.map +1 -1
  374. package/dist/routing/schema-validation.d.ts +35 -0
  375. package/dist/routing/schema-validation.d.ts.map +1 -0
  376. package/dist/routing/segment-classify.d.ts +75 -0
  377. package/dist/routing/segment-classify.d.ts.map +1 -0
  378. package/dist/routing/segment-codegen.d.ts +38 -0
  379. package/dist/routing/segment-codegen.d.ts.map +1 -0
  380. package/dist/routing/types.d.ts +77 -25
  381. package/dist/routing/types.d.ts.map +1 -1
  382. package/dist/routing/walkers.d.ts +51 -0
  383. package/dist/routing/walkers.d.ts.map +1 -0
  384. package/dist/rsc-runtime/rsc.d.ts +1 -1
  385. package/dist/rsc-runtime/rsc.d.ts.map +1 -1
  386. package/dist/rsc-runtime/ssr.d.ts +12 -0
  387. package/dist/rsc-runtime/ssr.d.ts.map +1 -1
  388. package/dist/schema-bridge.d.ts +91 -0
  389. package/dist/schema-bridge.d.ts.map +1 -0
  390. package/dist/search-params/define.d.ts +157 -0
  391. package/dist/search-params/define.d.ts.map +1 -0
  392. package/dist/search-params/index.d.ts +4 -7
  393. package/dist/search-params/index.d.ts.map +1 -1
  394. package/dist/search-params/index.js +37 -440
  395. package/dist/search-params/index.js.map +1 -1
  396. package/dist/search-params/registry.d.ts +2 -2
  397. package/dist/search-params/registry.d.ts.map +1 -1
  398. package/dist/search-params/wrappers.d.ts +53 -0
  399. package/dist/search-params/wrappers.d.ts.map +1 -0
  400. package/dist/segment-params/define.d.ts +89 -0
  401. package/dist/segment-params/define.d.ts.map +1 -0
  402. package/dist/segment-params/index.d.ts +3 -0
  403. package/dist/segment-params/index.d.ts.map +1 -0
  404. package/dist/segment-params/index.js +2 -0
  405. package/dist/server/access-gate.d.ts +8 -3
  406. package/dist/server/access-gate.d.ts.map +1 -1
  407. package/dist/server/action-client.d.ts +41 -6
  408. package/dist/server/action-client.d.ts.map +1 -1
  409. package/dist/server/action-encryption.d.ts +76 -0
  410. package/dist/server/action-encryption.d.ts.map +1 -0
  411. package/dist/server/action-handler.d.ts +35 -1
  412. package/dist/server/action-handler.d.ts.map +1 -1
  413. package/dist/server/actions.d.ts +6 -30
  414. package/dist/server/actions.d.ts.map +1 -1
  415. package/dist/server/als-registry.d.ts +86 -11
  416. package/dist/server/als-registry.d.ts.map +1 -1
  417. package/dist/server/asset-headers.d.ts +8 -18
  418. package/dist/server/asset-headers.d.ts.map +1 -1
  419. package/dist/server/body-limits.d.ts.map +1 -1
  420. package/dist/server/build-manifest.d.ts +6 -29
  421. package/dist/server/build-manifest.d.ts.map +1 -1
  422. package/dist/server/canonicalize.d.ts +10 -0
  423. package/dist/server/canonicalize.d.ts.map +1 -1
  424. package/dist/server/coalesce-tick.d.ts +40 -0
  425. package/dist/server/coalesce-tick.d.ts.map +1 -0
  426. package/dist/server/cookie-context.d.ts +170 -0
  427. package/dist/server/cookie-context.d.ts.map +1 -0
  428. package/dist/server/cookie-parsing.d.ts +65 -0
  429. package/dist/server/cookie-parsing.d.ts.map +1 -0
  430. package/dist/server/csrf.d.ts +3 -2
  431. package/dist/server/csrf.d.ts.map +1 -1
  432. package/dist/server/default-logger.d.ts +22 -0
  433. package/dist/server/default-logger.d.ts.map +1 -0
  434. package/dist/server/deny-boundary.d.ts +115 -0
  435. package/dist/server/deny-boundary.d.ts.map +1 -0
  436. package/dist/server/deny-renderer.d.ts +2 -2
  437. package/dist/server/deny-renderer.d.ts.map +1 -1
  438. package/dist/server/dev-source-map.d.ts +22 -0
  439. package/dist/server/dev-source-map.d.ts.map +1 -0
  440. package/dist/server/early-hints-sender.d.ts.map +1 -1
  441. package/dist/server/early-hints.d.ts +13 -11
  442. package/dist/server/early-hints.d.ts.map +1 -1
  443. package/dist/server/error-boundary-wrapper.d.ts +7 -1
  444. package/dist/server/error-boundary-wrapper.d.ts.map +1 -1
  445. package/dist/server/fallback-error.d.ts +12 -7
  446. package/dist/server/fallback-error.d.ts.map +1 -1
  447. package/dist/server/flight-injection-state.d.ts +66 -0
  448. package/dist/server/flight-injection-state.d.ts.map +1 -0
  449. package/dist/server/flight-scripts.d.ts +42 -0
  450. package/dist/server/flight-scripts.d.ts.map +1 -0
  451. package/dist/server/form-data.d.ts +41 -0
  452. package/dist/server/form-data.d.ts.map +1 -1
  453. package/dist/server/html-injector-core.d.ts +221 -0
  454. package/dist/server/html-injector-core.d.ts.map +1 -0
  455. package/dist/server/html-injectors.d.ts +82 -41
  456. package/dist/server/html-injectors.d.ts.map +1 -1
  457. package/dist/server/index.d.ts +11 -47
  458. package/dist/server/index.d.ts.map +1 -1
  459. package/dist/server/index.js +170 -2911
  460. package/dist/server/index.js.map +1 -1
  461. package/dist/server/internal.d.ts +49 -0
  462. package/dist/server/internal.d.ts.map +1 -0
  463. package/dist/server/internal.js +3652 -0
  464. package/dist/server/internal.js.map +1 -0
  465. package/dist/server/logger.d.ts +39 -7
  466. package/dist/server/logger.d.ts.map +1 -1
  467. package/dist/server/metadata-routes.d.ts +23 -7
  468. package/dist/server/metadata-routes.d.ts.map +1 -1
  469. package/dist/server/middleware-runner.d.ts +36 -4
  470. package/dist/server/middleware-runner.d.ts.map +1 -1
  471. package/dist/server/node-stream-transforms.d.ts +119 -0
  472. package/dist/server/node-stream-transforms.d.ts.map +1 -0
  473. package/dist/server/param-coercion.d.ts +54 -0
  474. package/dist/server/param-coercion.d.ts.map +1 -0
  475. package/dist/server/pipeline-helpers.d.ts +95 -0
  476. package/dist/server/pipeline-helpers.d.ts.map +1 -0
  477. package/dist/server/pipeline-interception.d.ts +1 -1
  478. package/dist/server/pipeline-interception.d.ts.map +1 -1
  479. package/dist/server/pipeline-metadata.d.ts +6 -0
  480. package/dist/server/pipeline-metadata.d.ts.map +1 -1
  481. package/dist/server/pipeline-outcome.d.ts +49 -0
  482. package/dist/server/pipeline-outcome.d.ts.map +1 -0
  483. package/dist/server/pipeline-phases.d.ts +56 -0
  484. package/dist/server/pipeline-phases.d.ts.map +1 -0
  485. package/dist/server/pipeline.d.ts +122 -19
  486. package/dist/server/pipeline.d.ts.map +1 -1
  487. package/dist/server/port-resolution.d.ts +117 -0
  488. package/dist/server/port-resolution.d.ts.map +1 -0
  489. package/dist/server/prebuilt/cache-key.d.ts +58 -0
  490. package/dist/server/prebuilt/cache-key.d.ts.map +1 -0
  491. package/dist/server/prebuilt/capture-state.d.ts +57 -0
  492. package/dist/server/prebuilt/capture-state.d.ts.map +1 -0
  493. package/dist/server/prebuilt/manifest-tag-index.d.ts +27 -0
  494. package/dist/server/prebuilt/manifest-tag-index.d.ts.map +1 -0
  495. package/dist/server/prebuilt/overlay.d.ts +100 -0
  496. package/dist/server/prebuilt/overlay.d.ts.map +1 -0
  497. package/dist/server/prebuilt/payload-source.d.ts +78 -0
  498. package/dist/server/prebuilt/payload-source.d.ts.map +1 -0
  499. package/dist/server/prebuilt/synthetic-store.d.ts +66 -0
  500. package/dist/server/prebuilt/synthetic-store.d.ts.map +1 -0
  501. package/dist/server/prebuilt-builder.d.ts +120 -0
  502. package/dist/server/prebuilt-builder.d.ts.map +1 -0
  503. package/dist/server/prebuilt-runtime.d.ts +101 -0
  504. package/dist/server/prebuilt-runtime.d.ts.map +1 -0
  505. package/dist/server/primitives.d.ts +88 -43
  506. package/dist/server/primitives.d.ts.map +1 -1
  507. package/dist/server/render-timeout.d.ts +51 -0
  508. package/dist/server/render-timeout.d.ts.map +1 -0
  509. package/dist/server/render-utils.d.ts +25 -0
  510. package/dist/server/render-utils.d.ts.map +1 -0
  511. package/dist/server/request-context.d.ts +62 -107
  512. package/dist/server/request-context.d.ts.map +1 -1
  513. package/dist/server/route-element-builder.d.ts +46 -25
  514. package/dist/server/route-element-builder.d.ts.map +1 -1
  515. package/dist/server/route-handler.d.ts.map +1 -1
  516. package/dist/server/route-matcher.d.ts +25 -36
  517. package/dist/server/route-matcher.d.ts.map +1 -1
  518. package/dist/server/rsc-entry/action-middleware-runner.d.ts +66 -0
  519. package/dist/server/rsc-entry/action-middleware-runner.d.ts.map +1 -0
  520. package/dist/server/rsc-entry/api-handler.d.ts +12 -3
  521. package/dist/server/rsc-entry/api-handler.d.ts.map +1 -1
  522. package/dist/server/rsc-entry/error-renderer.d.ts +26 -13
  523. package/dist/server/rsc-entry/error-renderer.d.ts.map +1 -1
  524. package/dist/server/rsc-entry/helpers.d.ts +51 -28
  525. package/dist/server/rsc-entry/helpers.d.ts.map +1 -1
  526. package/dist/server/rsc-entry/index.d.ts +28 -6
  527. package/dist/server/rsc-entry/index.d.ts.map +1 -1
  528. package/dist/server/rsc-entry/render-route.d.ts +50 -0
  529. package/dist/server/rsc-entry/render-route.d.ts.map +1 -0
  530. package/dist/server/rsc-entry/revalidate-renderer.d.ts +108 -0
  531. package/dist/server/rsc-entry/revalidate-renderer.d.ts.map +1 -0
  532. package/dist/server/rsc-entry/rsc-payload.d.ts +5 -6
  533. package/dist/server/rsc-entry/rsc-payload.d.ts.map +1 -1
  534. package/dist/server/rsc-entry/rsc-stream.d.ts +17 -1
  535. package/dist/server/rsc-entry/rsc-stream.d.ts.map +1 -1
  536. package/dist/server/rsc-entry/ssr-bridge.d.ts +5 -1
  537. package/dist/server/rsc-entry/ssr-bridge.d.ts.map +1 -1
  538. package/dist/server/rsc-entry/ssr-renderer.d.ts +34 -4
  539. package/dist/server/rsc-entry/ssr-renderer.d.ts.map +1 -1
  540. package/dist/server/rsc-entry/wrap-action-dispatch.d.ts +119 -0
  541. package/dist/server/rsc-entry/wrap-action-dispatch.d.ts.map +1 -0
  542. package/dist/server/safe-load.d.ts +46 -0
  543. package/dist/server/safe-load.d.ts.map +1 -0
  544. package/dist/server/sensitive-fields.d.ts +74 -0
  545. package/dist/server/sensitive-fields.d.ts.map +1 -0
  546. package/dist/server/sitemap-generator.d.ts +129 -0
  547. package/dist/server/sitemap-generator.d.ts.map +1 -0
  548. package/dist/server/sitemap-handler.d.ts +22 -0
  549. package/dist/server/sitemap-handler.d.ts.map +1 -0
  550. package/dist/server/slot-resolver.d.ts +7 -5
  551. package/dist/server/slot-resolver.d.ts.map +1 -1
  552. package/dist/server/ssr-bridge-types.d.ts +121 -0
  553. package/dist/server/ssr-bridge-types.d.ts.map +1 -0
  554. package/dist/server/ssr-entry.d.ts +2 -43
  555. package/dist/server/ssr-entry.d.ts.map +1 -1
  556. package/dist/server/ssr-render.d.ts +64 -21
  557. package/dist/server/ssr-render.d.ts.map +1 -1
  558. package/dist/server/ssr-wrappers.d.ts +50 -0
  559. package/dist/server/ssr-wrappers.d.ts.map +1 -0
  560. package/dist/server/state-tree-diff.d.ts +12 -5
  561. package/dist/server/state-tree-diff.d.ts.map +1 -1
  562. package/dist/server/status-code-resolver.d.ts +22 -11
  563. package/dist/server/status-code-resolver.d.ts.map +1 -1
  564. package/dist/server/stream-utils.d.ts +47 -0
  565. package/dist/server/stream-utils.d.ts.map +1 -0
  566. package/dist/server/tracing.d.ts +44 -9
  567. package/dist/server/tracing.d.ts.map +1 -1
  568. package/dist/server/tree-builder.d.ts +62 -30
  569. package/dist/server/tree-builder.d.ts.map +1 -1
  570. package/dist/server/tree-match.d.ts +49 -0
  571. package/dist/server/tree-match.d.ts.map +1 -0
  572. package/dist/server/types.d.ts +71 -6
  573. package/dist/server/types.d.ts.map +1 -1
  574. package/dist/server/utils/escape-html.d.ts +14 -0
  575. package/dist/server/utils/escape-html.d.ts.map +1 -0
  576. package/dist/server/utils/mdx-file.d.ts +15 -0
  577. package/dist/server/utils/mdx-file.d.ts.map +1 -0
  578. package/dist/server/version-skew.d.ts +61 -0
  579. package/dist/server/version-skew.d.ts.map +1 -0
  580. package/dist/server/workers-cache-bridge.d.ts +26 -0
  581. package/dist/server/workers-cache-bridge.d.ts.map +1 -0
  582. package/dist/shared/href-validation.d.ts +49 -0
  583. package/dist/shared/href-validation.d.ts.map +1 -0
  584. package/dist/shared/merge-search-params.d.ts +22 -0
  585. package/dist/shared/merge-search-params.d.ts.map +1 -0
  586. package/dist/shared/redirect-type.d.ts +17 -0
  587. package/dist/shared/redirect-type.d.ts.map +1 -0
  588. package/dist/shims/font-google.d.ts +1 -1
  589. package/dist/shims/font-google.d.ts.map +1 -1
  590. package/dist/shims/font-google.js +42 -0
  591. package/dist/shims/font-google.js.map +1 -0
  592. package/dist/shims/font-local.d.ts +26 -0
  593. package/dist/shims/font-local.d.ts.map +1 -0
  594. package/dist/shims/font-local.js +20 -0
  595. package/dist/shims/font-local.js.map +1 -0
  596. package/dist/shims/headers.d.ts +53 -1
  597. package/dist/shims/headers.d.ts.map +1 -1
  598. package/dist/shims/image.d.ts +16 -16
  599. package/dist/shims/navigation-client.d.ts +35 -11
  600. package/dist/shims/navigation-client.d.ts.map +1 -1
  601. package/dist/shims/navigation.d.ts +11 -5
  602. package/dist/shims/navigation.d.ts.map +1 -1
  603. package/dist/utils/state-machine.d.ts +80 -0
  604. package/dist/utils/state-machine.d.ts.map +1 -0
  605. package/docs/api/30-api-server.mdx +233 -0
  606. package/docs/api/31-api-client.mdx +161 -0
  607. package/docs/api/32-api-cache.mdx +199 -0
  608. package/docs/api/33-api-search-params.mdx +141 -0
  609. package/docs/api/34-api-config.mdx +189 -0
  610. package/docs/api/35-api-typescript.mdx +170 -0
  611. package/docs/api/36-cli.mdx +143 -0
  612. package/docs/learn/00-introduction.mdx +76 -0
  613. package/docs/learn/01-quick-start.mdx +94 -0
  614. package/docs/learn/02-pages-and-layouts.mdx +147 -0
  615. package/docs/learn/03-fetching-data.mdx +211 -0
  616. package/docs/learn/03b-access-control.mdx +130 -0
  617. package/docs/learn/04-loading-states.mdx +67 -0
  618. package/docs/learn/04b-the-flush-point.mdx +115 -0
  619. package/docs/learn/05-typed-params.mdx +275 -0
  620. package/docs/learn/06-forms-and-actions.mdx +146 -0
  621. package/docs/learn/07-typed-routes.mdx +127 -0
  622. package/docs/learn/08-streaming.mdx +146 -0
  623. package/docs/learn/09-caching.mdx +136 -0
  624. package/docs/learn/10-middleware.mdx +157 -0
  625. package/docs/learn/11-error-handling.mdx +156 -0
  626. package/docs/learn/12-client-navigation.mdx +168 -0
  627. package/docs/learn/13-configuration.mdx +145 -0
  628. package/docs/learn/14-deploying.mdx +264 -0
  629. package/docs/more/01-advanced-routing.mdx +139 -0
  630. package/docs/more/02-advanced-forms.mdx +137 -0
  631. package/docs/more/03-coming-from-nextjs.mdx +186 -0
  632. package/docs/more/04-metadata-and-fonts.mdx +193 -0
  633. package/docs/more/04b-mdx.mdx +209 -0
  634. package/docs/more/05-content-collections.mdx +90 -0
  635. package/docs/more/06-instrumentation.mdx +214 -0
  636. package/docs/more/07-security.mdx +129 -0
  637. package/docs/more/08-developer-experience.mdx +134 -0
  638. package/docs/more/40-why-timber.mdx +50 -0
  639. package/docs/more/41-timber-vs-nextjs.mdx +81 -0
  640. package/docs/more/42-timber-vs-others.mdx +68 -0
  641. package/docs/more/50-ai-agent-instructions.mdx +169 -0
  642. package/llms.txt +55 -0
  643. package/package.json +103 -26
  644. package/src/adapters/build-output-helper.ts +199 -0
  645. package/src/adapters/cloudflare-dev.ts +177 -0
  646. package/src/adapters/cloudflare-kv-cache.ts +179 -0
  647. package/src/adapters/cloudflare.ts +571 -118
  648. package/src/adapters/compress-module.ts +27 -92
  649. package/src/adapters/nitro.ts +131 -107
  650. package/src/adapters/raw-imports.d.ts +5 -0
  651. package/src/adapters/shared.ts +68 -0
  652. package/src/adapters/types.ts +0 -7
  653. package/src/adapters/wrangler.d.ts +7 -0
  654. package/src/cache/cache-api.ts +107 -0
  655. package/src/cache/handler-store.ts +76 -0
  656. package/src/cache/index.ts +88 -18
  657. package/src/cache/invalidation-epoch.ts +93 -0
  658. package/src/cache/redis-handler.ts +122 -15
  659. package/src/cache/singleflight.ts +64 -6
  660. package/src/cache/sizeof.ts +33 -0
  661. package/src/cache/stable-stringify.ts +65 -2
  662. package/src/cache/store.ts +71 -0
  663. package/src/cache/stores/cloudflare-kv.ts +52 -0
  664. package/src/cache/stores/memory.ts +125 -0
  665. package/src/cache/stores/redis.ts +97 -0
  666. package/src/cache/stores/vercel.ts +59 -0
  667. package/src/cache/tag-aware-handler.ts +233 -0
  668. package/src/cache/timber-cache.ts +142 -36
  669. package/src/cdn/cloudflare-purge.ts +50 -0
  670. package/src/cdn/fastly-purge.ts +63 -0
  671. package/src/cdn/headers.ts +153 -0
  672. package/src/cdn/index.ts +17 -0
  673. package/src/cdn/purge-store.ts +34 -0
  674. package/src/cdn/workers-cache-purge.ts +30 -0
  675. package/src/cli-schema-sync.ts +388 -0
  676. package/src/cli.ts +157 -34
  677. package/src/client/browser-dev.ts +156 -1
  678. package/src/client/browser-entry/action-dispatch.ts +124 -0
  679. package/src/client/browser-entry/hmr.ts +70 -0
  680. package/src/client/browser-entry/hydrate.ts +187 -0
  681. package/src/client/browser-entry/index.ts +111 -0
  682. package/src/client/browser-entry/post-hydration.ts +103 -0
  683. package/src/client/browser-entry/router-init.ts +287 -0
  684. package/src/client/browser-entry/rsc-stream.ts +157 -0
  685. package/src/client/browser-entry/scroll.ts +50 -0
  686. package/src/client/child-segment-context.ts +40 -0
  687. package/src/client/child-segment-outlet.tsx +25 -0
  688. package/src/client/child-segment-provider.tsx +27 -0
  689. package/src/client/error-boundary.tsx +127 -22
  690. package/src/client/error-reconstituter.tsx +79 -0
  691. package/src/client/form.tsx +31 -32
  692. package/src/client/history.ts +11 -7
  693. package/src/client/index.ts +67 -45
  694. package/src/client/internal.ts +58 -0
  695. package/src/client/link.tsx +346 -150
  696. package/src/client/navigation-api.ts +341 -0
  697. package/src/client/navigation-context.ts +15 -7
  698. package/src/client/navigation-root.tsx +355 -0
  699. package/src/client/nuqs-adapter.tsx +16 -3
  700. package/src/client/router-ref.ts +1 -1
  701. package/src/client/router.ts +482 -166
  702. package/src/client/rsc-fetch.ts +214 -33
  703. package/src/client/segment-cache.ts +7 -7
  704. package/src/client/segment-outlet.tsx +77 -0
  705. package/src/client/segment-update-context.ts +42 -0
  706. package/src/client/shallow-url.ts +22 -0
  707. package/src/client/ssr-data.ts +13 -5
  708. package/src/client/state.ts +2 -2
  709. package/src/client/top-loader.tsx +11 -9
  710. package/src/client/use-cookie.ts +60 -15
  711. package/src/client/use-link-status.ts +7 -7
  712. package/src/client/use-pathname.ts +1 -0
  713. package/src/client/use-pending-navigation.ts +40 -0
  714. package/src/client/use-query-states.ts +9 -3
  715. package/src/client/use-router.ts +4 -1
  716. package/src/client/use-search-params.ts +31 -44
  717. package/src/client/{use-params.ts → use-segment-params.ts} +9 -6
  718. package/src/codec.ts +147 -0
  719. package/src/config-types.ts +302 -0
  720. package/src/config-validation.ts +328 -0
  721. package/src/content/index.ts +5 -13
  722. package/src/cookies/define-cookie.ts +217 -53
  723. package/src/cookies/index.ts +12 -1
  724. package/src/cookies/json-cookie.ts +105 -0
  725. package/src/cookies/validation.ts +192 -0
  726. package/src/dev-tools/404-page.ts +286 -0
  727. package/src/dev-tools/browser-logs.ts +55 -0
  728. package/src/dev-tools/dev-page-shell.ts +260 -0
  729. package/src/dev-tools/error-page.ts +331 -0
  730. package/src/dev-tools/holding-server.ts +187 -0
  731. package/src/dev-tools/hydration-overlay.ts +158 -0
  732. package/src/dev-tools/index.ts +83 -0
  733. package/src/dev-tools/instrumentation.ts +213 -0
  734. package/src/{server/dev-logger.ts → dev-tools/logger.ts} +33 -51
  735. package/src/{plugins/dev-logs.ts → dev-tools/logs.ts} +9 -5
  736. package/src/dev-tools/overlay.ts +469 -0
  737. package/src/dev-tools/stack-classifier.ts +75 -0
  738. package/src/dev-tools/terminal.ts +182 -0
  739. package/src/fonts/ast-walk.ts +235 -0
  740. package/src/fonts/ast.ts +477 -126
  741. package/src/fonts/bundle.ts +138 -0
  742. package/src/fonts/dev-middleware.ts +85 -0
  743. package/src/fonts/fallbacks.ts +0 -23
  744. package/src/fonts/google.ts +63 -8
  745. package/src/fonts/local.ts +9 -8
  746. package/src/fonts/paths.ts +58 -0
  747. package/src/fonts/pipeline.ts +316 -0
  748. package/src/fonts/transform.ts +305 -0
  749. package/src/fonts/types.ts +52 -1
  750. package/src/fonts/virtual-modules.ts +179 -0
  751. package/src/index.ts +431 -352
  752. package/src/params/codec-registry.ts +34 -0
  753. package/src/params/define-schema.ts +115 -0
  754. package/src/params/index.ts +17 -0
  755. package/src/params/resolve-schema.ts +84 -0
  756. package/src/plugin-context.ts +378 -0
  757. package/src/plugins/adapter-build.ts +98 -4
  758. package/src/plugins/build-manifest.ts +168 -23
  759. package/src/plugins/build-report.ts +253 -35
  760. package/src/plugins/cache.ts +229 -0
  761. package/src/plugins/callsite-ast.ts +472 -0
  762. package/src/plugins/callsite-jsx.ts +243 -0
  763. package/src/plugins/chunks.ts +74 -5
  764. package/src/plugins/client-chunks.ts +144 -0
  765. package/src/plugins/cloudflare-wasm.ts +141 -0
  766. package/src/plugins/content.ts +1 -1
  767. package/src/plugins/dev-server.ts +293 -46
  768. package/src/plugins/entries.ts +129 -8
  769. package/src/plugins/fonts.ts +199 -664
  770. package/src/plugins/mdx.ts +47 -10
  771. package/src/plugins/prebuilt-capture.ts +217 -0
  772. package/src/plugins/prebuilt.ts +700 -0
  773. package/src/plugins/prerender-sugar.ts +329 -0
  774. package/src/plugins/routing.ts +237 -241
  775. package/src/plugins/server-bundle.ts +97 -12
  776. package/src/plugins/shims.ts +241 -64
  777. package/src/plugins/static-build.ts +15 -90
  778. package/src/routing/codegen-shared.ts +115 -0
  779. package/src/routing/codegen-types.ts +65 -0
  780. package/src/routing/codegen.ts +360 -178
  781. package/src/routing/convention-lint.ts +394 -0
  782. package/src/routing/export-detect.ts +304 -0
  783. package/src/routing/file-cache.ts +23 -0
  784. package/src/routing/index.ts +10 -1
  785. package/src/routing/interception.ts +3 -22
  786. package/src/routing/link-codegen.ts +310 -0
  787. package/src/routing/manifest-codegen.ts +281 -0
  788. package/src/routing/scanner.ts +248 -188
  789. package/src/routing/schema-validation.ts +149 -0
  790. package/src/routing/segment-classify.ts +188 -0
  791. package/src/routing/segment-codegen.ts +98 -0
  792. package/src/routing/types.ts +78 -25
  793. package/src/routing/walkers.ts +90 -0
  794. package/src/rsc-runtime/rsc.ts +9 -0
  795. package/src/rsc-runtime/ssr.ts +50 -0
  796. package/src/rsc-runtime/vendor-types.d.ts +7 -0
  797. package/src/schema-bridge.ts +252 -0
  798. package/src/search-params/define.ts +570 -0
  799. package/src/search-params/index.ts +14 -20
  800. package/src/search-params/registry.ts +2 -2
  801. package/src/search-params/wrappers.ts +110 -0
  802. package/src/segment-params/define.ts +249 -0
  803. package/src/segment-params/index.ts +9 -0
  804. package/src/server/access-gate.tsx +84 -34
  805. package/src/server/action-client.ts +119 -28
  806. package/src/server/action-encryption.ts +144 -0
  807. package/src/server/action-handler.ts +123 -33
  808. package/src/server/actions.ts +48 -54
  809. package/src/server/als-registry.ts +130 -20
  810. package/src/server/asset-headers.ts +15 -37
  811. package/src/server/body-limits.ts +10 -2
  812. package/src/server/build-manifest.ts +13 -56
  813. package/src/server/canonicalize.ts +6 -3
  814. package/src/server/coalesce-tick.ts +75 -0
  815. package/src/server/compress.ts +34 -7
  816. package/src/server/cookie-context.ts +484 -0
  817. package/src/server/cookie-parsing.ts +163 -0
  818. package/src/server/csrf.ts +39 -6
  819. package/src/server/default-logger.ts +99 -0
  820. package/src/server/deny-boundary.ts +311 -0
  821. package/src/server/deny-renderer.ts +85 -77
  822. package/src/server/dev-source-map.ts +31 -0
  823. package/src/server/early-hints-sender.ts +3 -2
  824. package/src/server/early-hints.ts +37 -27
  825. package/src/server/error-boundary-wrapper.ts +61 -22
  826. package/src/server/fallback-error.ts +79 -102
  827. package/src/server/flight-injection-state.ts +113 -0
  828. package/src/server/flight-scripts.ts +62 -0
  829. package/src/server/form-data.ts +124 -12
  830. package/src/server/html-injector-core.ts +437 -0
  831. package/src/server/html-injectors.ts +267 -254
  832. package/src/server/index.ts +31 -185
  833. package/src/server/internal.ts +181 -0
  834. package/src/server/logger.ts +72 -36
  835. package/src/server/metadata-routes.ts +44 -19
  836. package/src/server/middleware-runner.ts +75 -4
  837. package/src/server/node-stream-transforms.ts +331 -0
  838. package/src/server/param-coercion.ts +206 -0
  839. package/src/server/pipeline-helpers.ts +204 -0
  840. package/src/server/pipeline-interception.ts +32 -18
  841. package/src/server/pipeline-metadata.ts +14 -0
  842. package/src/server/pipeline-outcome.ts +197 -0
  843. package/src/server/pipeline-phases.ts +538 -0
  844. package/src/server/pipeline.ts +226 -382
  845. package/src/server/port-resolution.ts +215 -0
  846. package/src/server/prebuilt/cache-key.ts +224 -0
  847. package/src/server/prebuilt/capture-state.ts +89 -0
  848. package/src/server/prebuilt/manifest-tag-index.ts +46 -0
  849. package/src/server/prebuilt/overlay.ts +256 -0
  850. package/src/server/prebuilt/payload-source.ts +201 -0
  851. package/src/server/prebuilt/synthetic-store.ts +121 -0
  852. package/src/server/prebuilt-builder.ts +774 -0
  853. package/src/server/prebuilt-runtime.ts +731 -0
  854. package/src/server/primitives.ts +160 -83
  855. package/src/server/render-timeout.ts +108 -0
  856. package/src/server/render-utils.ts +31 -0
  857. package/src/server/request-context.ts +168 -337
  858. package/src/server/route-element-builder.ts +548 -233
  859. package/src/server/route-handler.ts +31 -4
  860. package/src/server/route-matcher.ts +144 -277
  861. package/src/server/rsc-entry/action-middleware-runner.ts +167 -0
  862. package/src/server/rsc-entry/api-handler.ts +69 -32
  863. package/src/server/rsc-entry/error-renderer.ts +306 -89
  864. package/src/server/rsc-entry/helpers.ts +160 -76
  865. package/src/server/rsc-entry/index.ts +394 -330
  866. package/src/server/rsc-entry/render-route.ts +288 -0
  867. package/src/server/rsc-entry/revalidate-renderer.ts +349 -0
  868. package/src/server/rsc-entry/rsc-payload.ts +74 -35
  869. package/src/server/rsc-entry/rsc-stream.ts +85 -13
  870. package/src/server/rsc-entry/ssr-bridge.ts +18 -5
  871. package/src/server/rsc-entry/ssr-renderer.ts +273 -43
  872. package/src/server/rsc-entry/wrap-action-dispatch.ts +449 -0
  873. package/src/server/safe-load.ts +60 -0
  874. package/src/server/sensitive-fields.ts +230 -0
  875. package/src/server/server-only-guard-noop.js +3 -0
  876. package/src/server/sitemap-generator.ts +344 -0
  877. package/src/server/sitemap-handler.ts +157 -0
  878. package/src/server/slot-resolver.ts +258 -257
  879. package/src/server/ssr-bridge-types.ts +124 -0
  880. package/src/server/ssr-entry.ts +206 -78
  881. package/src/server/ssr-render.ts +345 -82
  882. package/src/server/ssr-wrappers.tsx +141 -0
  883. package/src/server/state-tree-diff.ts +30 -23
  884. package/src/server/status-code-resolver.ts +115 -130
  885. package/src/server/stream-utils.ts +286 -0
  886. package/src/server/tracing.ts +126 -14
  887. package/src/server/tree-builder.ts +204 -90
  888. package/src/server/tree-match.ts +220 -0
  889. package/src/server/types.ts +78 -9
  890. package/src/server/utils/escape-html.ts +20 -0
  891. package/src/server/utils/mdx-file.ts +22 -0
  892. package/src/server/version-skew.ts +104 -0
  893. package/src/server/workers-cache-bridge.ts +33 -0
  894. package/src/shared/href-validation.ts +159 -0
  895. package/src/shared/merge-search-params.ts +55 -0
  896. package/src/shared/redirect-type.ts +17 -0
  897. package/src/shims/font-google.ts +1 -1
  898. package/src/shims/font-local.ts +34 -0
  899. package/src/shims/headers.ts +122 -1
  900. package/src/shims/navigation-client.ts +51 -29
  901. package/src/shims/navigation.ts +14 -7
  902. package/src/utils/state-machine.ts +111 -0
  903. package/dist/_chunks/als-registry-B7DbZ2hS.js +0 -41
  904. package/dist/_chunks/als-registry-B7DbZ2hS.js.map +0 -1
  905. package/dist/_chunks/debug-B3Gypr3D.js +0 -108
  906. package/dist/_chunks/debug-B3Gypr3D.js.map +0 -1
  907. package/dist/_chunks/format-RyoGQL74.js +0 -164
  908. package/dist/_chunks/format-RyoGQL74.js.map +0 -1
  909. package/dist/_chunks/interception-BOoWmLUA.js +0 -676
  910. package/dist/_chunks/interception-BOoWmLUA.js.map +0 -1
  911. package/dist/_chunks/metadata-routes-Cjmvi3rQ.js.map +0 -1
  912. package/dist/_chunks/request-context-BQUC8PHn.js +0 -330
  913. package/dist/_chunks/request-context-BQUC8PHn.js.map +0 -1
  914. package/dist/_chunks/ssr-data-MjmprTmO.js.map +0 -1
  915. package/dist/_chunks/tracing-CemImE6h.js +0 -187
  916. package/dist/_chunks/tracing-CemImE6h.js.map +0 -1
  917. package/dist/_chunks/use-cookie-DX-l1_5E.js +0 -91
  918. package/dist/_chunks/use-cookie-DX-l1_5E.js.map +0 -1
  919. package/dist/_chunks/use-query-states-D5KaffOK.js.map +0 -1
  920. package/dist/cache/index.js.map +0 -1
  921. package/dist/cache/register-cached-function.d.ts +0 -17
  922. package/dist/cache/register-cached-function.d.ts.map +0 -1
  923. package/dist/client/browser-entry.d.ts +0 -21
  924. package/dist/client/browser-entry.d.ts.map +0 -1
  925. package/dist/client/head.d.ts +0 -16
  926. package/dist/client/head.d.ts.map +0 -1
  927. package/dist/client/link-status-provider.d.ts +0 -11
  928. package/dist/client/link-status-provider.d.ts.map +0 -1
  929. package/dist/client/segment-merger.d.ts +0 -119
  930. package/dist/client/segment-merger.d.ts.map +0 -1
  931. package/dist/client/stale-reload.d.ts +0 -44
  932. package/dist/client/stale-reload.d.ts.map +0 -1
  933. package/dist/client/transition-root.d.ts +0 -74
  934. package/dist/client/transition-root.d.ts.map +0 -1
  935. package/dist/client/use-navigation-pending.d.ts +0 -26
  936. package/dist/client/use-navigation-pending.d.ts.map +0 -1
  937. package/dist/client/use-params.d.ts.map +0 -1
  938. package/dist/plugins/cache-transform.d.ts +0 -36
  939. package/dist/plugins/cache-transform.d.ts.map +0 -1
  940. package/dist/plugins/dev-error-overlay.d.ts +0 -60
  941. package/dist/plugins/dev-error-overlay.d.ts.map +0 -1
  942. package/dist/plugins/dev-logs.d.ts.map +0 -1
  943. package/dist/plugins/dynamic-transform.d.ts +0 -72
  944. package/dist/plugins/dynamic-transform.d.ts.map +0 -1
  945. package/dist/plugins/server-action-exports.d.ts +0 -26
  946. package/dist/plugins/server-action-exports.d.ts.map +0 -1
  947. package/dist/routing/status-file-lint.d.ts +0 -33
  948. package/dist/routing/status-file-lint.d.ts.map +0 -1
  949. package/dist/search-params/analyze.d.ts +0 -54
  950. package/dist/search-params/analyze.d.ts.map +0 -1
  951. package/dist/search-params/builtin-codecs.d.ts +0 -105
  952. package/dist/search-params/builtin-codecs.d.ts.map +0 -1
  953. package/dist/search-params/codecs.d.ts +0 -53
  954. package/dist/search-params/codecs.d.ts.map +0 -1
  955. package/dist/search-params/create.d.ts +0 -106
  956. package/dist/search-params/create.d.ts.map +0 -1
  957. package/dist/server/client-module-map.d.ts +0 -47
  958. package/dist/server/client-module-map.d.ts.map +0 -1
  959. package/dist/server/dev-fetch-instrumentation.d.ts +0 -22
  960. package/dist/server/dev-fetch-instrumentation.d.ts.map +0 -1
  961. package/dist/server/dev-logger.d.ts.map +0 -1
  962. package/dist/server/dev-span-processor.d.ts +0 -29
  963. package/dist/server/dev-span-processor.d.ts.map +0 -1
  964. package/dist/server/dev-warnings.d.ts +0 -129
  965. package/dist/server/dev-warnings.d.ts.map +0 -1
  966. package/dist/server/flush.d.ts +0 -74
  967. package/dist/server/flush.d.ts.map +0 -1
  968. package/dist/server/manifest-status-resolver.d.ts +0 -58
  969. package/dist/server/manifest-status-resolver.d.ts.map +0 -1
  970. package/dist/server/prerender.d.ts +0 -77
  971. package/dist/server/prerender.d.ts.map +0 -1
  972. package/dist/utils/directive-parser.d.ts +0 -70
  973. package/dist/utils/directive-parser.d.ts.map +0 -1
  974. package/src/cache/register-cached-function.ts +0 -103
  975. package/src/client/browser-entry.ts +0 -678
  976. package/src/client/head.ts +0 -61
  977. package/src/client/link-status-provider.tsx +0 -30
  978. package/src/client/segment-merger.ts +0 -339
  979. package/src/client/stale-reload.ts +0 -87
  980. package/src/client/transition-root.tsx +0 -166
  981. package/src/client/use-navigation-pending.ts +0 -38
  982. package/src/plugins/cache-transform.ts +0 -199
  983. package/src/plugins/dev-error-overlay.ts +0 -230
  984. package/src/plugins/dynamic-transform.ts +0 -161
  985. package/src/plugins/server-action-exports.ts +0 -220
  986. package/src/routing/status-file-lint.ts +0 -112
  987. package/src/search-params/analyze.ts +0 -192
  988. package/src/search-params/builtin-codecs.ts +0 -228
  989. package/src/search-params/codecs.ts +0 -153
  990. package/src/search-params/create.ts +0 -321
  991. package/src/server/client-module-map.ts +0 -58
  992. package/src/server/dev-fetch-instrumentation.ts +0 -96
  993. package/src/server/dev-span-processor.ts +0 -78
  994. package/src/server/dev-warnings.ts +0 -283
  995. package/src/server/flush.ts +0 -182
  996. package/src/server/manifest-status-resolver.ts +0 -215
  997. package/src/server/prerender.ts +0 -139
  998. package/src/utils/directive-parser.ts +0 -529
@@ -1,411 +1,124 @@
1
1
  /**
2
- * timber-fonts — Vite sub-plugin for build-time font processing.
2
+ * timber-fonts — Vite sub-plugin shell for build-time font processing.
3
3
  *
4
- * Handles:
5
- * - Virtual module resolution for `@timber/fonts/google` and `@timber/fonts/local`
6
- * - Static analysis of font function calls during `transform`
7
- * - @font-face CSS generation and scoped class output
8
- * - Size-adjusted fallback font generation
4
+ * This file is intentionally thin: it wires the Vite plugin hooks to the
5
+ * pipeline + per-concern modules under `../fonts/`. All real logic lives
6
+ * in:
9
7
  *
10
- * Does NOT handle (separate tasks):
11
- * - Google Fonts downloading/caching (timber-nk5)
12
- * - Build manifest / Early Hints integration (timber-qnx)
8
+ * - `../fonts/pipeline.ts` — `FontPipeline` (state, mutators)
9
+ * - `../fonts/transform.ts` — transform-hook logic, parsing helpers
10
+ * - `../fonts/dev-middleware.ts` — dev font binary server
11
+ * - `../fonts/virtual-modules.ts` — virtual module ID constants + source
12
+ *
13
+ * The public exports below are the stable API that the test suite and
14
+ * other parts of the framework import. Anything new should be added to
15
+ * one of the per-concern modules and re-exported here only if external
16
+ * consumers need it.
13
17
  *
14
18
  * Design doc: 24-fonts.md
15
19
  */
16
20
 
17
- import type { Plugin, ViteDevServer } from 'vite';
18
- import { readFileSync, existsSync } from 'node:fs';
19
- import { resolve, normalize } from 'node:path';
20
- import type { PluginContext } from '#/index.js';
21
- import type { ExtractedFont, GoogleFontConfig } from '#/fonts/types.js';
22
- import type { ManifestFontEntry } from '#/server/build-manifest.js';
23
- import { generateVariableClass, generateFontFamilyClass, generateFontFaces } from '#/fonts/css.js';
24
- import { generateFallbackCss, buildFontStack } from '#/fonts/fallbacks.js';
25
- import { processLocalFont, generateLocalFontFaces } from '#/fonts/local.js';
26
- import { inferFontFormat } from '#/fonts/local.js';
27
- import { downloadAndCacheFonts, type CachedFont } from '#/fonts/google.js';
21
+ import type { Plugin, ResolvedConfig, ViteDevServer } from 'vite';
22
+ import type { PluginContext } from '../plugin-context.js';
28
23
  import {
29
- extractFontConfigAst,
30
- extractLocalFontConfigAst,
31
- detectDynamicFontCallAst,
32
- } from '#/fonts/ast.js';
33
-
34
- const VIRTUAL_GOOGLE = '@timber/fonts/google';
35
- const VIRTUAL_LOCAL = '@timber/fonts/local';
36
- const RESOLVED_GOOGLE = '\0@timber/fonts/google';
37
- const RESOLVED_LOCAL = '\0@timber/fonts/local';
38
-
39
- /**
40
- * Virtual side-effect module that registers font CSS on globalThis.
41
- *
42
- * When a file calls localFont() or a Google font function, the transform
43
- * hook injects `import 'virtual:timber-font-css-register'` into that file.
44
- * This virtual module sets `globalThis.__timber_font_css` with the combined
45
- * @font-face CSS. The RSC entry reads it at render time to inline a <style> tag.
46
- *
47
- * This approach avoids timing issues because:
48
- * 1. The font file is in the RSC module graph (imported by layout.tsx)
49
- * 2. The side-effect import is added to the font file during transform
50
- * 3. When layout.tsx is loaded, fonts.ts runs → side-effect module runs → globalThis is set
51
- * 4. RSC entry renders → reads globalThis → inlines <style>
52
- */
53
- const VIRTUAL_FONT_CSS_REGISTER = 'virtual:timber-font-css-register';
54
- const RESOLVED_FONT_CSS_REGISTER = '\0virtual:timber-font-css-register';
55
-
56
- /**
57
- * Registry of fonts extracted during transform.
58
- * Keyed by a unique font ID derived from family + config.
59
- */
60
- export type FontRegistry = Map<string, ExtractedFont>;
61
-
62
- /**
63
- * Convert a font family name to a PascalCase export name.
64
- * e.g. "JetBrains Mono" → "JetBrains_Mono"
65
- */
66
- function familyToExportName(family: string): string {
67
- return family.replace(/\s+/g, '_');
68
- }
69
-
70
- /**
71
- * Convert a font family name to a scoped class name.
72
- * e.g. "JetBrains Mono" → "timber-font-jetbrains-mono"
73
- */
74
- function familyToClassName(family: string): string {
75
- return `timber-font-${family.toLowerCase().replace(/\s+/g, '-')}`;
76
- }
77
-
78
- /**
79
- * Generate a unique font ID from family + config hash.
80
- */
81
- function generateFontId(family: string, config: GoogleFontConfig): string {
82
- const weights = normalizeToArray(config.weight);
83
- const styles = normalizeToArray(config.style);
84
- const subsets = config.subsets ?? ['latin'];
85
- return `${family.toLowerCase()}-${weights.join(',')}-${styles.join(',')}-${subsets.join(',')}`;
86
- }
87
-
88
- /**
89
- * Normalize a string or string array to an array.
90
- */
91
- function normalizeToArray(value: string | string[] | undefined): string[] {
92
- if (!value) return ['400'];
93
- return Array.isArray(value) ? value : [value];
94
- }
95
-
96
- /**
97
- * Normalize style to an array.
98
- */
99
- function normalizeStyleArray(value: string | string[] | undefined): string[] {
100
- if (!value) return ['normal'];
101
- return Array.isArray(value) ? value : [value];
102
- }
103
-
104
- /**
105
- * Extract static font config from a font function call in source code.
106
- *
107
- * Parses patterns like:
108
- * const inter = Inter({ subsets: ['latin'], weight: '400', display: 'swap', variable: '--font-sans' })
109
- *
110
- * Returns null if the call cannot be statically analyzed.
111
- *
112
- * Uses acorn AST parsing for robust handling of comments, trailing commas,
113
- * and multi-line configs.
114
- */
115
- export function extractFontConfig(callSource: string): GoogleFontConfig | null {
116
- return extractFontConfigAst(callSource);
117
- }
118
-
119
- /**
120
- * Detect if a source file contains dynamic/computed font function calls
121
- * that cannot be statically analyzed.
122
- *
123
- * Returns the offending expression if found, null if all calls are static.
124
- *
125
- * Uses acorn AST parsing for accurate detection.
126
- */
127
- export function detectDynamicFontCall(source: string, importedNames: string[]): string | null {
128
- return detectDynamicFontCallAst(source, importedNames);
129
- }
130
-
131
- /**
132
- * Regex that matches imports from either `@timber/fonts/google` or `next/font/google`.
133
- * The shims plugin resolves `next/font/google` to the same virtual module,
134
- * but the source code still contains the original import specifier.
135
- */
136
- const GOOGLE_FONT_IMPORT_RE =
137
- /import\s*\{([^}]+)\}\s*from\s*['"](?:@timber\/fonts\/google|next\/font\/google)['"]/g;
138
-
139
- /**
140
- * Parse import specifiers from a source file that imports from
141
- * `@timber/fonts/google` or `next/font/google`.
142
- *
143
- * Returns the list of imported font names (e.g. ['Inter', 'JetBrains_Mono']).
144
- */
145
- export function parseGoogleFontImports(source: string): string[] {
146
- const importPattern = new RegExp(GOOGLE_FONT_IMPORT_RE.source, 'g');
147
- const names: string[] = [];
148
-
149
- let match;
150
- while ((match = importPattern.exec(source)) !== null) {
151
- const specifiers = match[1]
152
- .split(',')
153
- .map((s) => s.trim())
154
- .filter(Boolean);
155
- for (const spec of specifiers) {
156
- // Handle `Inter as MyInter` — we want the local name
157
- const parts = spec.split(/\s+as\s+/);
158
- names.push(parts[parts.length - 1].trim());
159
- }
160
- }
161
-
162
- return names;
163
- }
164
-
165
- /**
166
- * Parse the original (remote) font family names from imports.
167
- *
168
- * Returns a map of local name → family name.
169
- * e.g. { Inter: 'Inter', JetBrains_Mono: 'JetBrains Mono' }
170
- */
171
- export function parseGoogleFontFamilies(source: string): Map<string, string> {
172
- const importPattern = new RegExp(GOOGLE_FONT_IMPORT_RE.source, 'g');
173
- const families = new Map<string, string>();
174
-
175
- let match;
176
- while ((match = importPattern.exec(source)) !== null) {
177
- const specifiers = match[1]
178
- .split(',')
179
- .map((s) => s.trim())
180
- .filter(Boolean);
181
- for (const spec of specifiers) {
182
- const parts = spec.split(/\s+as\s+/);
183
- const originalName = parts[0].trim();
184
- const localName = parts[parts.length - 1].trim();
185
- // Convert export name back to family name: JetBrains_Mono → JetBrains Mono
186
- const family = originalName.replace(/_/g, ' ');
187
- families.set(localName, family);
188
- }
189
- }
190
-
191
- return families;
192
- }
193
-
194
- /**
195
- * Generate the virtual module source for `@timber/fonts/google`.
196
- *
197
- * Each Google Font family gets a named export that returns a FontResult.
198
- * In this base implementation, the functions return static data.
199
- * The Google Fonts download task (timber-nk5) will add real font file URLs.
200
- */
201
- function generateGoogleVirtualModule(registry: FontRegistry): string {
202
- // Collect unique families from the registry
203
- const families = new Set<string>();
204
- for (const font of registry.values()) {
205
- if (font.provider === 'google') families.add(font.family);
206
- }
207
-
208
- const lines = [
209
- '// Auto-generated virtual module: @timber/fonts/google',
210
- '// Each export is a font loader function that returns a FontResult.',
211
- '',
212
- ];
213
-
214
- // If no fonts registered yet, export a generic loader for any font
215
- // This is the initial load — the transform hook will process actual calls
216
- lines.push('function createFontResult(family, config) {');
217
- lines.push(' return {');
218
- lines.push(' className: `timber-font-${family.toLowerCase().replace(/\\s+/g, "-")}`,');
219
- lines.push(' style: { fontFamily: family },');
220
- lines.push(' variable: config?.variable,');
221
- lines.push(' };');
222
- lines.push('}');
223
- lines.push('');
224
-
225
- // Export a Proxy-based default that handles any font name import
226
- lines.push('export default new Proxy({}, {');
227
- lines.push(' get(_, prop) {');
228
- lines.push(' if (typeof prop === "string") {');
229
- lines.push(' return (config) => createFontResult(prop.replace(/_/g, " "), config);');
230
- lines.push(' }');
231
- lines.push(' }');
232
- lines.push('});');
233
-
234
- // Also export known families as named exports for tree-shaking
235
- for (const family of families) {
236
- const exportName = familyToExportName(family);
237
- lines.push('');
238
- lines.push(`export function ${exportName}(config) {`);
239
- lines.push(` return createFontResult('${family}', config);`);
240
- lines.push('}');
241
- }
242
-
243
- return lines.join('\n');
244
- }
245
-
246
- /**
247
- * Generate the virtual module source for `@timber/fonts/local`.
248
- */
249
- function generateLocalVirtualModule(): string {
250
- return [
251
- '// Auto-generated virtual module: @timber/fonts/local',
252
- '',
253
- 'export default function localFont(config) {',
254
- ' const family = config?.family || "Local Font";',
255
- ' return {',
256
- ' className: `timber-font-${family.toLowerCase().replace(/\\s+/g, "-")}`,',
257
- ' style: { fontFamily: family },',
258
- ' variable: config?.variable,',
259
- ' };',
260
- '}',
261
- ].join('\n');
262
- }
263
-
264
- /**
265
- * Generate CSS for a single extracted font.
266
- *
267
- * Includes @font-face rules (for local fonts), fallback @font-face,
268
- * and the scoped class rule.
269
- */
270
- export function generateFontCss(font: ExtractedFont): string {
271
- const cssParts: string[] = [];
272
-
273
- if (font.provider === 'local' && font.localSources) {
274
- const faces = generateLocalFontFaces(font.family, font.localSources, font.display);
275
- const faceCss = generateFontFaces(faces);
276
- if (faceCss) cssParts.push(faceCss);
277
- }
278
-
279
- const fallbackCss = generateFallbackCss(font.family);
280
- if (fallbackCss) cssParts.push(fallbackCss);
281
-
282
- if (font.variable) {
283
- cssParts.push(generateVariableClass(font.className, font.variable, font.fontFamily));
284
- } else {
285
- cssParts.push(generateFontFamilyClass(font.className, font.fontFamily));
286
- }
287
-
288
- return cssParts.join('\n\n');
289
- }
290
-
291
- /**
292
- * Generate the CSS output for all extracted fonts.
293
- *
294
- * Includes @font-face rules for local fonts, fallback @font-face rules,
295
- * and scoped classes.
296
- */
297
- export function generateAllFontCss(registry: FontRegistry): string {
298
- const cssParts: string[] = [];
299
- for (const font of registry.values()) {
300
- cssParts.push(generateFontCss(font));
301
- }
302
- return cssParts.join('\n\n');
303
- }
304
-
305
- /**
306
- * Parse the local name used for the default import of `@timber/fonts/local`.
307
- *
308
- * Handles:
309
- * import localFont from '@timber/fonts/local'
310
- * import myLoader from '@timber/fonts/local'
311
- */
312
- export function parseLocalFontImportName(source: string): string | null {
313
- const match = source.match(
314
- /import\s+(\w+)\s+from\s*['"](?:@timber\/fonts\/local|next\/font\/local)['"]/
315
- );
316
- return match ? match[1] : null;
317
- }
318
-
319
- /**
320
- * Transform local font calls in source code.
321
- *
322
- * Finds `localFont({ ... })` calls, extracts the config,
323
- * registers the font, and replaces the call with a static FontResult.
324
- */
325
- function transformLocalFonts(
326
- transformedCode: string,
327
- originalCode: string,
328
- importerId: string,
329
- registry: FontRegistry,
330
- emitError: (msg: string) => void
331
- ): string {
332
- const localName = parseLocalFontImportName(originalCode);
333
- if (!localName) return transformedCode;
334
-
335
- // Check for dynamic calls
336
- const dynamicCall = detectDynamicFontCall(originalCode, [localName]);
337
- if (dynamicCall) {
338
- emitError(
339
- `Font function calls must be statically analyzable. ` +
340
- `Found dynamic call: ${dynamicCall}. ` +
341
- `Pass a literal object with string/array values instead.`
342
- );
343
- }
344
-
345
- // Find all calls: const varName = localFont({ ... })
346
- const callPattern = new RegExp(
347
- `(?:const|let|var)\\s+(\\w+)\\s*=\\s*${localName}\\s*\\(\\s*(\\{[\\s\\S]*?\\})\\s*\\)`,
348
- 'g'
349
- );
350
-
351
- let callMatch;
352
- while ((callMatch = callPattern.exec(originalCode)) !== null) {
353
- const varName = callMatch[1];
354
- const configSource = callMatch[2];
355
- const fullMatch = callMatch[0];
356
-
357
- const config = extractLocalFontConfigAst(`(${configSource})`);
358
- if (!config) {
359
- emitError(
360
- `Could not statically analyze local font config. ` +
361
- `Ensure src is a string or array of { path, weight?, style? } objects.`
362
- );
363
- return transformedCode;
364
- }
365
-
366
- const extracted = processLocalFont(config, importerId);
367
- registry.set(extracted.id, extracted);
368
-
369
- const resultObj = extracted.variable
370
- ? `{ className: "${extracted.className}", style: { fontFamily: "${extracted.fontFamily}" }, variable: "${extracted.variable}" }`
371
- : `{ className: "${extracted.className}", style: { fontFamily: "${extracted.fontFamily}" } }`;
372
-
373
- const replacement = `const ${varName} = ${resultObj}`;
374
- transformedCode = transformedCode.replace(fullMatch, replacement);
375
- }
376
-
377
- // Remove the import statement
378
- transformedCode = transformedCode.replace(
379
- /import\s+\w+\s+from\s*['"](?:@timber\/fonts\/local|next\/font\/local)['"];?\s*\n?/g,
380
- ''
381
- );
382
-
383
- return transformedCode;
384
- }
24
+ downloadAndCacheFonts,
25
+ generateProductionFontFaces,
26
+ resolveDevFontFaces,
27
+ } from '../fonts/google.js';
28
+ import { fontUrlPrefix } from '../fonts/paths.js';
29
+ import { FontPipeline } from '../fonts/pipeline.js';
30
+ import { runFontsTransform } from '../fonts/transform.js';
31
+ import { installFontDevMiddleware } from '../fonts/dev-middleware.js';
32
+ import { emitFontAssets, writeFontManifest, groupCachedFontsByFamily } from '../fonts/bundle.js';
33
+ import {
34
+ RESOLVED_GOOGLE,
35
+ RESOLVED_LOCAL,
36
+ VIRTUAL_GOOGLE,
37
+ VIRTUAL_LOCAL,
38
+ generateGoogleVirtualModule,
39
+ generateLocalVirtualModule,
40
+ } from '../fonts/virtual-modules.js';
41
+
42
+ // ── Public re-exports ────────────────────────────────────────────────────
43
+ //
44
+ // These exports are part of the stable surface area imported by tests and
45
+ // downstream consumers. Do NOT change their names or signatures without
46
+ // updating every caller. New helpers should be added to the per-concern
47
+ // module first and re-exported here only if external code needs them.
48
+
49
+ export { FontPipeline } from '../fonts/pipeline.js';
50
+ export {
51
+ generateFontId,
52
+ extractFontConfig,
53
+ detectDynamicFontCall,
54
+ parseGoogleFontImports,
55
+ parseGoogleFontFamilies,
56
+ parseLocalFontImportName,
57
+ } from '../fonts/transform.js';
385
58
 
386
59
  /**
387
60
  * Create the timber-fonts Vite plugin.
388
61
  */
389
62
  export function timberFonts(ctx: PluginContext): Plugin {
390
- const registry: FontRegistry = new Map();
391
- /** Fonts downloaded during buildStart (production only). */
392
- let cachedFonts: CachedFont[] = [];
63
+ const pipeline = new FontPipeline({ hashOnRegister: !ctx.dev });
64
+ let resolvedBase = '/';
393
65
 
394
66
  return {
395
67
  name: 'timber-fonts',
396
68
 
397
69
  /**
398
- * Resolve `@timber/fonts/google`, `@timber/fonts/local`,
399
- * and `virtual:timber-font-css` virtual modules.
70
+ * Capture Vite's resolved `base` so every font URL the pipeline emits
71
+ * (@font-face src, manifest hrefs, dev middleware matching) carries
72
+ * the prefix. Emitted file locations are unaffected — only URLs.
73
+ */
74
+ configResolved(config: ResolvedConfig) {
75
+ resolvedBase = config.base;
76
+ pipeline.setBase(config.base);
77
+
78
+ // Font binaries are emitted in generateBundle, after Vite's CSS
79
+ // url() resolution runs. The warnings are benign — suppress them.
80
+ const originalWarnOnce = config.logger.warnOnce.bind(config.logger);
81
+ config.logger.warnOnce = (msg, options) => {
82
+ if (msg.includes('_timber/fonts/') && msg.includes("didn't resolve at build time")) return;
83
+ originalWarnOnce(msg, options);
84
+ };
85
+ },
86
+
87
+ /**
88
+ * `enforce: 'pre'` is load-bearing for the font CSS pipeline (TIM-828).
89
+ *
90
+ * The transform hook injects a side-effect
91
+ * `import 'virtual:timber-font-css/<hash>.css'` into every file that
92
+ * registers a font. @vitejs/plugin-rsc's `rsc:rsc-css-export-transform`
93
+ * later inspects each server component's source for CSS imports and
94
+ * wraps the default export in `import.meta.viteRsc.loadCss(...)` so
95
+ * the matched virtual CSS module ends up `preinit`'d as
96
+ * `<link rel="stylesheet" data-rsc-css-href=...>`.
97
+ *
98
+ * If timber-fonts ran in normal order it would inject the CSS import
99
+ * *after* plugin-rsc had already scanned the source, and the font CSS
100
+ * would be silently dropped from the rendered HTML. Running in the
101
+ * `pre` slot guarantees our injected import is visible to plugin-rsc's
102
+ * later CSS-export scan.
103
+ */
104
+ enforce: 'pre',
105
+
106
+ /**
107
+ * Resolve `@timber/fonts/google`, `@timber/fonts/local`, and the
108
+ * per-importer `virtual:timber-font-css/<hash>.css` modules injected
109
+ * by the transform hook.
400
110
  *
401
- * Handles \0 prefix and root prefix stripping for RSC/SSR
402
- * environments where the RSC plugin re-imports virtual modules
403
- * with additional prefixes.
111
+ * Strips the `\0` prefix added by the RSC plugin's re-imports and the
112
+ * absolute root prefix added by SSR build entries before comparing
113
+ * against the public IDs. The `.css` suffix on font-css ids is
114
+ * preserved so Vite's CSS pipeline (`isCSSRequest`) recognises the
115
+ * resolved id as CSS.
404
116
  */
405
117
  resolveId(id: string) {
406
- // Strip \0 prefix (RSC plugin re-imports)
407
118
  let cleanId = id.startsWith('\0') ? id.slice(1) : id;
408
- // Strip root prefix (SSR build entries)
119
+ const qIdx = cleanId.indexOf('?');
120
+ const query = qIdx !== -1 ? cleanId.slice(qIdx) : '';
121
+ if (qIdx !== -1) cleanId = cleanId.slice(0, qIdx);
409
122
  if (cleanId.startsWith(ctx.root)) {
410
123
  const stripped = cleanId.slice(ctx.root.length);
411
124
  if (stripped.startsWith('/') || stripped.startsWith('\\')) {
@@ -417,317 +130,139 @@ export function timberFonts(ctx: PluginContext): Plugin {
417
130
 
418
131
  if (cleanId === VIRTUAL_GOOGLE) return RESOLVED_GOOGLE;
419
132
  if (cleanId === VIRTUAL_LOCAL) return RESOLVED_LOCAL;
420
- if (cleanId === VIRTUAL_FONT_CSS_REGISTER) return RESOLVED_FONT_CSS_REGISTER;
133
+ // Preserve query suffix (notably `?direct`) on the resolved CSS id.
134
+ // Vite's transform middleware appends `?direct` when the browser
135
+ // fetches the URL as a `<link rel="stylesheet">`, and the CSS plugin
136
+ // only skips its JS-wrapping step when `isDirectCSSRequest(id)` sees
137
+ // that query on the resolved id. Dropping it here caused virtual
138
+ // font CSS to be served as Vite's HMR JS shim, leaving the
139
+ // `<link>`-loaded stylesheet empty (TIM-937 follow-up).
140
+ if (pipeline.cssIdMap.matches(cleanId)) return '\0' + cleanId + query;
421
141
  return null;
422
142
  },
423
143
 
424
144
  /**
425
145
  * Return generated source for font virtual modules.
426
146
  *
427
- * `virtual:timber-font-css` exports the combined @font-face CSS
428
- * as a string. The RSC entry imports it and inlines a <style> tag.
429
- * Because this is loaded lazily (on first request), the font
430
- * registry is always populated by the time it's needed.
431
- */
432
- load(id: string) {
433
- if (id === RESOLVED_GOOGLE) return generateGoogleVirtualModule(registry);
434
- if (id === RESOLVED_LOCAL) return generateLocalVirtualModule();
435
-
436
- if (id === RESOLVED_FONT_CSS_REGISTER) {
437
- const css = generateAllFontCss(registry);
438
- // Side-effect module: sets font CSS on globalThis for the RSC entry to read.
439
- return `globalThis.__timber_font_css = ${JSON.stringify(css)};`;
440
- }
441
- return null;
442
- },
443
-
444
- /**
445
- * Serve local font files and font CSS in dev mode under `/_timber/fonts/`.
446
- *
447
- * Serves:
448
- * - `/_timber/fonts/fonts.css` — combined @font-face + scoped class CSS
449
- * - `/_timber/fonts/<filename>` — individual font files from the registry
147
+ * The per-importer `virtual:timber-font-css/<hash>.css` modules
148
+ * return the combined font CSS for the specific importer that
149
+ * registered them. Vite's CSS pipeline handles injection from here:
150
+ * in dev the module rides the CSS HMR channel; in production it is
151
+ * emitted as a real CSS asset and @vitejs/plugin-rsc's `collectCss`
152
+ * walks the RSC module graph to find it.
450
153
  *
451
- * Only files registered in the font registry are served.
452
- * Paths are validated to prevent directory traversal.
154
+ * Google `@font-face` descriptors are resolved lazily here (both
155
+ * dev and production) because `load` runs after `transform` has
156
+ * registered the font. `buildStart` runs before any transforms,
157
+ * so fonts aren't in the pipeline yet when it fires for the first
158
+ * environment.
453
159
  */
454
- configureServer(server: ViteDevServer) {
455
- server.middlewares.use((req, res, next) => {
456
- const url = req.url;
457
- if (!url || !url.startsWith('/_timber/fonts/')) return next();
160
+ async load(id: string) {
161
+ if (id === RESOLVED_GOOGLE) return generateGoogleVirtualModule(pipeline.fonts());
162
+ if (id === RESOLVED_LOCAL) return generateLocalVirtualModule();
458
163
 
459
- const requestedFilename = url.slice('/_timber/fonts/'.length);
460
- // Reject path traversal attempts
461
- if (requestedFilename.includes('..') || requestedFilename.includes('/')) {
462
- res.statusCode = 400;
463
- res.end('Bad request');
464
- return;
164
+ if (pipeline.cssIdMap.matches(id)) {
165
+ const importer = pipeline.cssIdMap.importerFor(id);
166
+ if (!importer) {
167
+ return '';
465
168
  }
466
169
 
467
- // Font CSS is now injected via Vite's CSS pipeline (virtual:timber-font-css modules).
468
- // This middleware only serves font binary files (woff2, etc.).
170
+ const skipFonts = process.env.TIMBER_SKIP_FONTS === '1';
469
171
 
470
- // Find the matching font file in the registry
471
- for (const font of registry.values()) {
472
- if (font.provider !== 'local' || !font.localSources) continue;
473
- for (const src of font.localSources) {
474
- const basename = src.path.split('/').pop() ?? '';
475
- if (basename === requestedFilename) {
476
- const absolutePath = normalize(resolve(src.path));
477
- if (!existsSync(absolutePath)) {
478
- res.statusCode = 404;
479
- res.end('Not found');
480
- return;
481
- }
482
- const data = readFileSync(absolutePath);
483
- const ext = absolutePath.split('.').pop()?.toLowerCase();
484
- const mimeMap: Record<string, string> = {
485
- woff2: 'font/woff2',
486
- woff: 'font/woff',
487
- ttf: 'font/ttf',
488
- otf: 'font/otf',
489
- eot: 'application/vnd.ms-fontopen',
490
- };
491
- res.setHeader('Content-Type', mimeMap[ext ?? ''] ?? 'application/octet-stream');
492
- res.setHeader('Cache-Control', 'public, max-age=31536000, immutable');
493
- res.setHeader('Access-Control-Allow-Origin', '*');
494
- res.end(data);
495
- return;
172
+ for (const font of pipeline.googleFonts()) {
173
+ if (font.importer !== importer) continue;
174
+ if (pipeline.hasFaces(font.id)) continue;
175
+ if (skipFonts && !ctx.dev) {
176
+ console.warn(`[timber-fonts] Skipping font "${font.family}" (TIMBER_SKIP_FONTS=1)`);
177
+ continue;
178
+ }
179
+ try {
180
+ if (ctx.dev) {
181
+ const faces = await resolveDevFontFaces(font);
182
+ pipeline.attachFaces(font.id, faces);
183
+ } else {
184
+ const cached = await downloadAndCacheFonts([font], ctx.root);
185
+ const byFamily = groupCachedFontsByFamily(cached);
186
+ const familyCached = byFamily.get(font.family.toLowerCase()) ?? [];
187
+ pipeline.attachCachedFiles(font.id, familyCached);
188
+ pipeline.attachFaces(
189
+ font.id,
190
+ generateProductionFontFaces(familyCached, font.display, fontUrlPrefix(resolvedBase))
191
+ );
496
192
  }
193
+ } catch (e) {
194
+ if (!ctx.dev) throw e;
195
+ const msg = e instanceof Error ? e.message : String(e);
196
+ console.warn(
197
+ `[timber-fonts] Failed to resolve Google font "${font.family}": ${msg}. Will retry on next request.`
198
+ );
497
199
  }
498
200
  }
499
201
 
500
- next();
501
- });
202
+ return pipeline.getCssForSegment(importer);
203
+ }
204
+ return null;
502
205
  },
503
206
 
504
207
  /**
505
- * Download and cache Google Fonts during production builds.
506
- *
507
- * In dev mode this is a no-op — fonts point to the Google CDN.
508
- * The registry is populated by the transform hook which runs before
509
- * buildStart in the build pipeline, so all fonts are known here.
208
+ * Serve local font files in dev mode under `/_timber/fonts/<basename>`.
209
+ * Font CSS goes through Vite's CSS pipeline (virtual modules), not
210
+ * this middleware.
510
211
  */
511
- async buildStart() {
512
- if (ctx.dev) return;
513
-
514
- const googleFonts = [...registry.values()].filter((f) => f.provider === 'google');
515
- if (googleFonts.length === 0) return;
516
-
517
- cachedFonts = await downloadAndCacheFonts(googleFonts, ctx.root);
212
+ configureServer(server: ViteDevServer) {
213
+ installFontDevMiddleware(server, pipeline, resolvedBase);
518
214
  },
519
215
 
520
216
  /**
521
- * Scan source files for font function calls and extract static config.
217
+ * No-op. Font downloading and face attachment happen lazily in `load()`
218
+ * because `buildStart` runs before `transform` — fonts aren't registered
219
+ * in the pipeline yet when this fires for the first environment.
522
220
  *
523
- * When a file imports from `@timber/fonts/google`, we:
524
- * 1. Parse the import specifiers to get font family names
525
- * 2. Find each font function call and extract its config
526
- * 3. Validate that all calls are statically analyzable
527
- * 4. Register extracted fonts in the registry
528
- * 5. Replace the function call with a static FontResult object
221
+ * Local font hashing is handled at registration time by the pipeline
222
+ * (when `hashOnRegister` is set) so hashed filenames are available
223
+ * before the virtual CSS `load()` hook runs.
529
224
  */
530
- transform(code: string, id: string) {
531
- // Skip virtual modules and node_modules
532
- if (id.startsWith('\0') || id.includes('node_modules')) return null;
533
-
534
- const hasGoogleImport =
535
- code.includes('@timber/fonts/google') || code.includes('next/font/google');
536
- const hasLocalImport =
537
- code.includes('@timber/fonts/local') || code.includes('next/font/local');
538
- if (!hasGoogleImport && !hasLocalImport) return null;
539
-
540
- let transformedCode = code;
541
-
542
- // ── Google font transform ──────────────────────────────────────────
543
- if (hasGoogleImport) {
544
- const families = parseGoogleFontFamilies(code);
545
- if (families.size > 0) {
546
- const importedNames = [...families.keys()];
547
-
548
- const dynamicCall = detectDynamicFontCall(code, importedNames);
549
- if (dynamicCall) {
550
- this.error(
551
- `Font function calls must be statically analyzable. ` +
552
- `Found dynamic call: ${dynamicCall}. ` +
553
- `Pass a literal object with string/array values instead.`
554
- );
555
- }
556
-
557
- for (const [localName, family] of families) {
558
- const callPattern = new RegExp(
559
- `(?:const|let|var)\\s+(\\w+)\\s*=\\s*${localName}\\s*\\(\\s*(\\{[\\s\\S]*?\\})\\s*\\)`,
560
- 'g'
561
- );
562
-
563
- let callMatch;
564
- while ((callMatch = callPattern.exec(code)) !== null) {
565
- const varName = callMatch[1];
566
- const configSource = callMatch[2];
567
- const fullMatch = callMatch[0];
568
-
569
- const config = extractFontConfig(`(${configSource})`);
570
- if (!config) {
571
- this.error(
572
- `Could not statically analyze font config for ${family}. ` +
573
- `Ensure all config values are string literals or arrays of string literals.`
574
- );
575
- return null;
576
- }
577
-
578
- const fontId = generateFontId(family, config);
579
- const className = familyToClassName(family);
580
- const fontStack = buildFontStack(family);
581
- const display = config.display ?? 'swap';
582
-
583
- const extracted: ExtractedFont = {
584
- id: fontId,
585
- family,
586
- provider: 'google',
587
- weights: normalizeToArray(config.weight),
588
- styles: normalizeStyleArray(config.style),
589
- subsets: config.subsets ?? ['latin'],
590
- display,
591
- variable: config.variable,
592
- className,
593
- fontFamily: fontStack,
594
- importer: id,
595
- };
596
-
597
- registry.set(fontId, extracted);
598
-
599
- const resultObj = config.variable
600
- ? `{ className: "${className}", style: { fontFamily: "${fontStack}" }, variable: "${config.variable}" }`
601
- : `{ className: "${className}", style: { fontFamily: "${fontStack}" } }`;
602
-
603
- const replacement = `const ${varName} = ${resultObj}`;
604
- transformedCode = transformedCode.replace(fullMatch, replacement);
605
- }
606
- }
607
-
608
- transformedCode = transformedCode.replace(
609
- /import\s*\{[^}]+\}\s*from\s*['"](?:@timber\/fonts\/google|next\/font\/google)['"];?\s*\n?/g,
610
- ''
611
- );
612
- }
613
- }
614
-
615
- // ── Local font transform ───────────────────────────────────────────
616
- if (hasLocalImport) {
617
- transformedCode = transformLocalFonts(
618
- transformedCode,
619
- code,
620
- id,
621
- registry,
622
- this.error.bind(this)
623
- );
624
- }
625
-
626
- if (transformedCode !== code) {
627
- // Inject side-effect import that registers font CSS on globalThis.
628
- // The RSC entry reads globalThis.__timber_font_css to inline a <style> tag.
629
- if (registry.size > 0) {
630
- transformedCode = `import '${VIRTUAL_FONT_CSS_REGISTER}';\n` + transformedCode;
631
- }
632
- return { code: transformedCode, map: null };
633
- }
634
-
635
- return null;
636
- },
225
+ buildStart() {},
637
226
 
638
227
  /**
639
- * Emit font files and metadata into the build output.
228
+ * Scan source files for font function calls and extract static config.
640
229
  *
641
- * For Google fonts: emits the downloaded, content-hashed woff2 files
642
- * and writes ManifestFontEntry arrays using real hashed URLs.
230
+ * Delegates to `runFontsTransform`. Errors raised through the
231
+ * `this.error` callback are surfaced as Vite plugin errors.
643
232
  *
644
- * For local fonts: emits entries using the source file paths.
233
+ * The `filter` option uses Vite 8's rolldown-native hook filters to
234
+ * skip non-JS/TS files and files that don't mention any font module
235
+ * before crossing into JS — replacing the hand-rolled pre-filter that
236
+ * was previously inside `runFontsTransform` (TIM-840, TIM-1147).
237
+ */
238
+ transform: {
239
+ filter: {
240
+ id: {
241
+ include: /^[^?]*\.(?:js|jsx|ts|tsx|mjs|cjs|mts|cts)(?:\?|$)/,
242
+ exclude: /(?:^\0|(?:^|\/)node_modules\/)/,
243
+ },
244
+ code: ['@timber/fonts/', '@timber-js/app/fonts/', 'next/font/'],
245
+ },
246
+ handler(code: string, id: string) {
247
+ return runFontsTransform(code, id, pipeline, (msg) => this.error(msg));
248
+ },
249
+ },
250
+
251
+ /**
252
+ * Emit font binaries and build-manifest entries.
645
253
  *
646
- * In dev mode the build manifest is null, so this is a no-op.
254
+ * All font binaries (Google and local) use content-hashed filenames
255
+ * for immutable caching. Font CSS is handled by Vite's CSS pipeline
256
+ * via virtual modules — we only emit binaries here.
647
257
  */
648
258
  generateBundle() {
649
- // Emit cached Google Font files into the build output
650
- for (const cf of cachedFonts) {
651
- this.emitFile({
652
- type: 'asset',
653
- fileName: `_timber/fonts/${cf.hashedFilename}`,
654
- source: cf.data,
655
- });
656
- }
657
-
658
- // Emit local font files as assets
659
- for (const font of registry.values()) {
660
- if (font.provider !== 'local' || !font.localSources) continue;
661
- for (const src of font.localSources) {
662
- const absolutePath = normalize(resolve(src.path));
663
- if (!existsSync(absolutePath)) {
664
- this.warn(`Local font file not found: ${absolutePath}`);
665
- continue;
666
- }
667
- const basename = src.path.split('/').pop() ?? src.path;
668
- const data = readFileSync(absolutePath);
669
- this.emitFile({
670
- type: 'asset',
671
- fileName: `_timber/fonts/${basename}`,
672
- source: data,
673
- });
674
- }
675
- }
676
-
677
- // Font CSS is emitted by Vite's CSS pipeline via virtual:timber-font-css modules.
678
- // We only need to emit font binary files and update the build manifest here.
679
-
259
+ emitFontAssets(
260
+ pipeline,
261
+ (asset) => this.emitFile(asset),
262
+ (msg) => this.warn(msg)
263
+ );
680
264
  if (!ctx.buildManifest) return;
681
-
682
- // Build a lookup from font family → cached files for manifest entries
683
- const cachedByFamily = new Map<string, CachedFont[]>();
684
- for (const cf of cachedFonts) {
685
- const key = cf.face.family.toLowerCase();
686
- const arr = cachedByFamily.get(key) ?? [];
687
- arr.push(cf);
688
- cachedByFamily.set(key, arr);
689
- }
690
-
691
- const fontsByImporter = new Map<string, ManifestFontEntry[]>();
692
-
693
- for (const font of registry.values()) {
694
- const entries = fontsByImporter.get(font.importer) ?? [];
695
-
696
- if (font.provider === 'local' && font.localSources) {
697
- // Local fonts: one entry per source file
698
- for (const src of font.localSources) {
699
- const filename = src.path.split('/').pop() ?? src.path;
700
- const format = inferFontFormat(src.path);
701
- entries.push({
702
- href: `/_timber/fonts/${filename}`,
703
- format,
704
- crossOrigin: 'anonymous',
705
- });
706
- }
707
- } else {
708
- // Google fonts: use real content-hashed URLs from cached downloads
709
- const familyKey = font.family.toLowerCase();
710
- const familyCached = cachedByFamily.get(familyKey) ?? [];
711
- for (const cf of familyCached) {
712
- entries.push({
713
- href: `/_timber/fonts/${cf.hashedFilename}`,
714
- format: 'woff2',
715
- crossOrigin: 'anonymous',
716
- });
717
- }
718
- }
719
-
720
- fontsByImporter.set(font.importer, entries);
721
- }
722
-
723
- // Normalize importer paths to be relative to project root (matching
724
- // how Vite's manifest.json keys work for css/js).
725
- for (const [importer, entries] of fontsByImporter) {
726
- const relativePath = importer.startsWith(ctx.root)
727
- ? importer.slice(ctx.root.length + 1)
728
- : importer;
729
- ctx.buildManifest.fonts[relativePath] = entries;
730
- }
265
+ writeFontManifest(pipeline, ctx.buildManifest, resolvedBase);
731
266
  },
732
267
  };
733
268
  }