@timber-js/app 0.2.0-alpha.3 → 0.2.0-alpha.5

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 (85) hide show
  1. package/dist/_chunks/{als-registry-k-AtAQ9R.js → als-registry-B7DbZ2hS.js} +1 -1
  2. package/dist/_chunks/{als-registry-k-AtAQ9R.js.map → als-registry-B7DbZ2hS.js.map} +1 -1
  3. package/dist/_chunks/debug-gwlJkDuf.js +108 -0
  4. package/dist/_chunks/debug-gwlJkDuf.js.map +1 -0
  5. package/dist/_chunks/{format-DNt20Kt8.js → format-DviM89f0.js} +3 -2
  6. package/dist/_chunks/format-DviM89f0.js.map +1 -0
  7. package/dist/_chunks/{interception-DGDIjDbR.js → interception-BOoWmLUA.js} +2 -2
  8. package/dist/_chunks/{interception-DGDIjDbR.js.map → interception-BOoWmLUA.js.map} +1 -1
  9. package/dist/_chunks/{metadata-routes-CQCnF4VK.js → metadata-routes-Cjmvi3rQ.js} +1 -1
  10. package/dist/_chunks/{metadata-routes-CQCnF4VK.js.map → metadata-routes-Cjmvi3rQ.js.map} +1 -1
  11. package/dist/_chunks/{request-context-CRj2Zh1E.js → request-context-DIkVh_jG.js} +5 -4
  12. package/dist/_chunks/request-context-DIkVh_jG.js.map +1 -0
  13. package/dist/_chunks/{ssr-data-DLnbYpj1.js → ssr-data-MjmprTmO.js} +1 -1
  14. package/dist/_chunks/{ssr-data-DLnbYpj1.js.map → ssr-data-MjmprTmO.js.map} +1 -1
  15. package/dist/_chunks/{tracing-DF0G3FB7.js → tracing-Cwn7697K.js} +2 -2
  16. package/dist/_chunks/{tracing-DF0G3FB7.js.map → tracing-Cwn7697K.js.map} +1 -1
  17. package/dist/_chunks/{use-cookie-dDbpCTx-.js → use-cookie-DX-l1_5E.js} +2 -2
  18. package/dist/_chunks/{use-cookie-dDbpCTx-.js.map → use-cookie-DX-l1_5E.js.map} +1 -1
  19. package/dist/_chunks/{use-query-states-DAhgj8Gx.js → use-query-states-D5KaffOK.js} +1 -1
  20. package/dist/_chunks/{use-query-states-DAhgj8Gx.js.map → use-query-states-D5KaffOK.js.map} +1 -1
  21. package/dist/cache/index.js +2 -2
  22. package/dist/client/error-boundary.js +1 -1
  23. package/dist/client/index.js +3 -3
  24. package/dist/cookies/index.js +4 -4
  25. package/dist/fonts/local.d.ts +4 -2
  26. package/dist/fonts/local.d.ts.map +1 -1
  27. package/dist/index.d.ts +38 -0
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +211 -14
  30. package/dist/index.js.map +1 -1
  31. package/dist/plugins/build-report.d.ts +11 -1
  32. package/dist/plugins/build-report.d.ts.map +1 -1
  33. package/dist/plugins/entries.d.ts +7 -0
  34. package/dist/plugins/entries.d.ts.map +1 -1
  35. package/dist/plugins/fonts.d.ts +2 -1
  36. package/dist/plugins/fonts.d.ts.map +1 -1
  37. package/dist/plugins/mdx.d.ts +6 -0
  38. package/dist/plugins/mdx.d.ts.map +1 -1
  39. package/dist/plugins/server-bundle.d.ts.map +1 -1
  40. package/dist/routing/index.js +1 -1
  41. package/dist/search-params/index.js +1 -1
  42. package/dist/server/access-gate.d.ts.map +1 -1
  43. package/dist/server/action-client.d.ts.map +1 -1
  44. package/dist/server/debug.d.ts +82 -0
  45. package/dist/server/debug.d.ts.map +1 -0
  46. package/dist/server/deny-renderer.d.ts.map +1 -1
  47. package/dist/server/dev-warnings.d.ts.map +1 -1
  48. package/dist/server/index.js +14 -13
  49. package/dist/server/index.js.map +1 -1
  50. package/dist/server/logger.d.ts.map +1 -1
  51. package/dist/server/primitives.d.ts.map +1 -1
  52. package/dist/server/request-context.d.ts.map +1 -1
  53. package/dist/server/response-cache.d.ts +53 -0
  54. package/dist/server/response-cache.d.ts.map +1 -0
  55. package/dist/server/rsc-entry/index.d.ts.map +1 -1
  56. package/dist/server/rsc-entry/rsc-payload.d.ts.map +1 -1
  57. package/dist/server/rsc-entry/rsc-stream.d.ts.map +1 -1
  58. package/dist/server/rsc-entry/ssr-renderer.d.ts.map +1 -1
  59. package/dist/server/rsc-prop-warnings.d.ts.map +1 -1
  60. package/dist/shims/image.d.ts +15 -15
  61. package/package.json +1 -1
  62. package/src/client/stale-reload.ts +1 -1
  63. package/src/fonts/local.ts +7 -3
  64. package/src/index.ts +40 -0
  65. package/src/plugins/build-report.ts +23 -3
  66. package/src/plugins/entries.ts +9 -4
  67. package/src/plugins/fonts.ts +106 -5
  68. package/src/plugins/mdx.ts +9 -5
  69. package/src/plugins/server-bundle.ts +4 -0
  70. package/src/server/access-gate.tsx +3 -2
  71. package/src/server/action-client.ts +8 -4
  72. package/src/server/debug.ts +137 -0
  73. package/src/server/deny-renderer.ts +3 -2
  74. package/src/server/dev-warnings.ts +2 -1
  75. package/src/server/logger.ts +4 -3
  76. package/src/server/primitives.ts +2 -1
  77. package/src/server/request-context.ts +3 -2
  78. package/src/server/response-cache.ts +277 -0
  79. package/src/server/rsc-entry/index.ts +51 -13
  80. package/src/server/rsc-entry/rsc-payload.ts +4 -1
  81. package/src/server/rsc-entry/rsc-stream.ts +2 -1
  82. package/src/server/rsc-entry/ssr-renderer.ts +6 -2
  83. package/src/server/rsc-prop-warnings.ts +3 -1
  84. package/dist/_chunks/format-DNt20Kt8.js.map +0 -1
  85. package/dist/_chunks/request-context-CRj2Zh1E.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { r as setViteServer, t as formatSize } from "./_chunks/format-DNt20Kt8.js";
2
- import { i as scanRoutes, n as generateRouteMap, t as collectInterceptionRewrites } from "./_chunks/interception-DGDIjDbR.js";
1
+ import { r as setViteServer, t as formatSize } from "./_chunks/format-DviM89f0.js";
2
+ import { i as scanRoutes, n as generateRouteMap, t as collectInterceptionRewrites } from "./_chunks/interception-BOoWmLUA.js";
3
3
  import { existsSync, readFileSync } from "node:fs";
4
- import { dirname, extname, join, resolve } from "node:path";
4
+ import { dirname, extname, join, normalize, resolve } from "node:path";
5
5
  import { fileURLToPath, pathToFileURL } from "node:url";
6
6
  import { createRequire } from "node:module";
7
7
  import react from "@vitejs/plugin-react";
@@ -11933,7 +11933,9 @@ function generateConfigModule(ctx) {
11933
11933
  slowPhaseMs: ctx.config.dev?.slowPhaseMs ?? 200,
11934
11934
  slowRequestMs: ctx.config.slowRequestMs ?? 3e3,
11935
11935
  cookieSecrets,
11936
- topLoader: ctx.config.topLoader
11936
+ topLoader: ctx.config.topLoader,
11937
+ responseCache: ctx.config.responseCache,
11938
+ debug: ctx.config.debug ?? false
11937
11939
  };
11938
11940
  return [
11939
11941
  "// Auto-generated runtime config — do not edit.",
@@ -11951,12 +11953,14 @@ function generateConfigModule(ctx) {
11951
11953
  * extensions as timber.config.ts detection.
11952
11954
  */
11953
11955
  function detectInstrumentationFile(root) {
11954
- for (const ext of [
11956
+ const extensions = [
11955
11957
  ".ts",
11956
11958
  ".js",
11957
11959
  ".mjs"
11958
- ]) {
11959
- const candidate = resolve(root, `instrumentation${ext}`);
11960
+ ];
11961
+ const dirs = [root, resolve(root, "src")];
11962
+ for (const dir of dirs) for (const ext of extensions) {
11963
+ const candidate = resolve(dir, `instrumentation${ext}`);
11960
11964
  if (existsSync(candidate)) return candidate;
11961
11965
  }
11962
11966
  return null;
@@ -12016,17 +12020,20 @@ function timberEntries(ctx) {
12016
12020
  //#region src/plugins/mdx.ts
12017
12021
  var MDX_EXTENSIONS = ["mdx", "md"];
12018
12022
  /**
12019
- * Check if mdx-components.tsx (or .ts, .jsx, .js) exists at the project root.
12023
+ * Check if mdx-components.tsx (or .ts, .jsx, .js) exists at the project root
12024
+ * or in src/. Root takes precedence, matching Next.js behavior.
12020
12025
  * Returns the absolute path if found, otherwise undefined.
12021
12026
  */
12022
12027
  function findMdxComponents(root) {
12023
- for (const name of [
12028
+ const candidates = [
12024
12029
  "mdx-components.tsx",
12025
12030
  "mdx-components.ts",
12026
12031
  "mdx-components.jsx",
12027
12032
  "mdx-components.js"
12028
- ]) {
12029
- const p = join(root, name);
12033
+ ];
12034
+ const dirs = [root, join(root, "src")];
12035
+ for (const dir of dirs) for (const name of candidates) {
12036
+ const p = join(dir, name);
12030
12037
  if (existsSync(p)) return p;
12031
12038
  }
12032
12039
  }
@@ -12540,6 +12547,58 @@ export const coerce = stub;
12540
12547
  };
12541
12548
  }
12542
12549
  //#endregion
12550
+ //#region src/fonts/css.ts
12551
+ /**
12552
+ * Generate a single `@font-face` CSS rule from a descriptor.
12553
+ */
12554
+ function generateFontFace(desc) {
12555
+ const lines = [];
12556
+ lines.push("@font-face {");
12557
+ lines.push(` font-family: '${desc.family}';`);
12558
+ lines.push(` src: ${desc.src};`);
12559
+ if (desc.weight) lines.push(` font-weight: ${desc.weight};`);
12560
+ if (desc.style) lines.push(` font-style: ${desc.style};`);
12561
+ if (desc.display) lines.push(` font-display: ${desc.display};`);
12562
+ if (desc.unicodeRange) lines.push(` unicode-range: ${desc.unicodeRange};`);
12563
+ lines.push("}");
12564
+ return lines.join("\n");
12565
+ }
12566
+ /**
12567
+ * Generate multiple `@font-face` rules from an array of descriptors.
12568
+ */
12569
+ function generateFontFaces(descriptors) {
12570
+ return descriptors.map(generateFontFace).join("\n\n");
12571
+ }
12572
+ /**
12573
+ * Generate a scoped CSS class that sets a CSS custom property for the font.
12574
+ *
12575
+ * Example output:
12576
+ * ```css
12577
+ * .timber-font-inter {
12578
+ * --font-sans: 'Inter', 'Inter Fallback', system-ui, sans-serif;
12579
+ * }
12580
+ * ```
12581
+ */
12582
+ function generateVariableClass(className, variable, fontFamily) {
12583
+ return `.${className} {\n ${variable}: ${fontFamily};\n}`;
12584
+ }
12585
+ /**
12586
+ * Generate a scoped CSS class that applies font-family directly.
12587
+ *
12588
+ * Used when no `variable` is specified — the className applies
12589
+ * the font-family inline instead of through a CSS custom property.
12590
+ *
12591
+ * Example output:
12592
+ * ```css
12593
+ * .timber-font-inter {
12594
+ * font-family: 'Inter', 'Inter Fallback', system-ui, sans-serif;
12595
+ * }
12596
+ * ```
12597
+ */
12598
+ function generateFontFamilyClass(className, fontFamily) {
12599
+ return `.${className} {\n font-family: ${fontFamily};\n}`;
12600
+ }
12601
+ //#endregion
12543
12602
  //#region src/fonts/fallbacks.ts
12544
12603
  /**
12545
12604
  * Lookup table for commonly used Google Fonts.
@@ -12678,6 +12737,26 @@ function getGenericFamily(family) {
12678
12737
  return "sans-serif";
12679
12738
  }
12680
12739
  /**
12740
+ * Generate the full CSS for a size-adjusted fallback font.
12741
+ *
12742
+ * This produces a complete @font-face block with override descriptors
12743
+ * that FontFaceDescriptor doesn't natively support.
12744
+ */
12745
+ function generateFallbackCss(family) {
12746
+ const metrics = FALLBACK_METRICS[family.toLowerCase()];
12747
+ if (!metrics) return null;
12748
+ return [
12749
+ "@font-face {",
12750
+ ` font-family: '${`${family} Fallback`}';`,
12751
+ ` src: local('${metrics.fallbackFont}');`,
12752
+ ` size-adjust: ${metrics.sizeAdjust}%;`,
12753
+ ` ascent-override: ${metrics.ascentOverride}%;`,
12754
+ ` descent-override: ${metrics.descentOverride}%;`,
12755
+ ` line-gap-override: ${metrics.lineGapOverride}%;`,
12756
+ "}"
12757
+ ].join("\n");
12758
+ }
12759
+ /**
12681
12760
  * Check whether fallback metrics are available for a font family.
12682
12761
  */
12683
12762
  function hasFallbackMetrics(family) {
@@ -13026,6 +13105,26 @@ function generateFamilyName(sources) {
13026
13105
  return stem.replace(/[-_]?(Regular|Bold|Italic|Light|Medium|SemiBold|ExtraBold|Thin|Black|Heavy)$/i, "") || stem;
13027
13106
  }
13028
13107
  /**
13108
+ * Generate @font-face descriptors for local font sources.
13109
+ *
13110
+ * Each source entry produces one @font-face rule. The `src` descriptor
13111
+ * uses a `url()` pointing to the served path under `/_timber/fonts/`.
13112
+ * The `urlPrefix` defaults to `/_timber/fonts` — the path used by both
13113
+ * the dev server middleware and the production build output.
13114
+ */
13115
+ function generateLocalFontFaces(family, sources, display, urlPrefix = "/_timber/fonts") {
13116
+ return sources.map((entry) => {
13117
+ const format = inferFontFormat(entry.path);
13118
+ return {
13119
+ family,
13120
+ src: `url('${urlPrefix}/${entry.path.split("/").pop() ?? entry.path}') format('${format}')`,
13121
+ weight: entry.weight,
13122
+ style: entry.style,
13123
+ display
13124
+ };
13125
+ });
13126
+ }
13127
+ /**
13029
13128
  * Build the className for a local font, following the same convention
13030
13129
  * as Google fonts: `timber-font-<lowercase-hyphenated-family>`.
13031
13130
  */
@@ -13258,8 +13357,10 @@ async function isCacheHit(metaPath, dataPath) {
13258
13357
  //#region src/plugins/fonts.ts
13259
13358
  var VIRTUAL_GOOGLE = "@timber/fonts/google";
13260
13359
  var VIRTUAL_LOCAL = "@timber/fonts/local";
13360
+ var VIRTUAL_FONT_CSS = "virtual:timber-fonts-css";
13261
13361
  var RESOLVED_GOOGLE = "\0@timber/fonts/google";
13262
13362
  var RESOLVED_LOCAL = "\0@timber/fonts/local";
13363
+ var RESOLVED_FONT_CSS = "\0virtual:timber-fonts-css";
13263
13364
  /**
13264
13365
  * Convert a font family name to a PascalCase export name.
13265
13366
  * e.g. "JetBrains Mono" → "JetBrains_Mono"
@@ -13407,6 +13508,26 @@ function generateLocalVirtualModule() {
13407
13508
  ].join("\n");
13408
13509
  }
13409
13510
  /**
13511
+ * Generate the CSS output for all extracted fonts.
13512
+ *
13513
+ * Includes @font-face rules for local fonts, fallback @font-face rules,
13514
+ * and scoped classes.
13515
+ */
13516
+ function generateAllFontCss(registry) {
13517
+ const cssParts = [];
13518
+ for (const font of registry.values()) {
13519
+ if (font.provider === "local" && font.localSources) {
13520
+ const faceCss = generateFontFaces(generateLocalFontFaces(font.family, font.localSources, font.display));
13521
+ if (faceCss) cssParts.push(faceCss);
13522
+ }
13523
+ const fallbackCss = generateFallbackCss(font.family);
13524
+ if (fallbackCss) cssParts.push(fallbackCss);
13525
+ if (font.variable) cssParts.push(generateVariableClass(font.className, font.variable, font.fontFamily));
13526
+ else cssParts.push(generateFontFamilyClass(font.className, font.fontFamily));
13527
+ }
13528
+ return cssParts.join("\n\n");
13529
+ }
13530
+ /**
13410
13531
  * Parse the local name used for the default import of `@timber/fonts/local`.
13411
13532
  *
13412
13533
  * Handles:
@@ -13459,13 +13580,52 @@ function timberFonts(ctx) {
13459
13580
  resolveId(id) {
13460
13581
  if (id === VIRTUAL_GOOGLE) return RESOLVED_GOOGLE;
13461
13582
  if (id === VIRTUAL_LOCAL) return RESOLVED_LOCAL;
13583
+ if (id === VIRTUAL_FONT_CSS) return RESOLVED_FONT_CSS;
13462
13584
  return null;
13463
13585
  },
13464
13586
  load(id) {
13465
13587
  if (id === RESOLVED_GOOGLE) return generateGoogleVirtualModule(registry);
13466
13588
  if (id === RESOLVED_LOCAL) return generateLocalVirtualModule();
13589
+ if (id === RESOLVED_FONT_CSS) return generateAllFontCss(registry);
13467
13590
  return null;
13468
13591
  },
13592
+ configureServer(server) {
13593
+ server.middlewares.use((req, res, next) => {
13594
+ const url = req.url;
13595
+ if (!url || !url.startsWith("/_timber/fonts/")) return next();
13596
+ const requestedFilename = url.slice(15);
13597
+ if (requestedFilename.includes("..") || requestedFilename.includes("/")) {
13598
+ res.statusCode = 400;
13599
+ res.end("Bad request");
13600
+ return;
13601
+ }
13602
+ for (const font of registry.values()) {
13603
+ if (font.provider !== "local" || !font.localSources) continue;
13604
+ for (const src of font.localSources) if ((src.path.split("/").pop() ?? "") === requestedFilename) {
13605
+ const absolutePath = normalize(resolve(src.path));
13606
+ if (!existsSync(absolutePath)) {
13607
+ res.statusCode = 404;
13608
+ res.end("Not found");
13609
+ return;
13610
+ }
13611
+ const data = readFileSync(absolutePath);
13612
+ const ext = absolutePath.split(".").pop()?.toLowerCase();
13613
+ res.setHeader("Content-Type", {
13614
+ woff2: "font/woff2",
13615
+ woff: "font/woff",
13616
+ ttf: "font/ttf",
13617
+ otf: "font/otf",
13618
+ eot: "application/vnd.ms-fontopen"
13619
+ }[ext ?? ""] ?? "application/octet-stream");
13620
+ res.setHeader("Cache-Control", "public, max-age=31536000, immutable");
13621
+ res.setHeader("Access-Control-Allow-Origin", "*");
13622
+ res.end(data);
13623
+ return;
13624
+ }
13625
+ }
13626
+ next();
13627
+ });
13628
+ },
13469
13629
  async buildStart() {
13470
13630
  if (ctx.dev) return;
13471
13631
  const googleFonts = [...registry.values()].filter((f) => f.provider === "google");
@@ -13533,6 +13693,29 @@ function timberFonts(ctx) {
13533
13693
  fileName: `_timber/fonts/${cf.hashedFilename}`,
13534
13694
  source: cf.data
13535
13695
  });
13696
+ for (const font of registry.values()) {
13697
+ if (font.provider !== "local" || !font.localSources) continue;
13698
+ for (const src of font.localSources) {
13699
+ const absolutePath = normalize(resolve(src.path));
13700
+ if (!existsSync(absolutePath)) {
13701
+ this.warn(`Local font file not found: ${absolutePath}`);
13702
+ continue;
13703
+ }
13704
+ const basename = src.path.split("/").pop() ?? src.path;
13705
+ const data = readFileSync(absolutePath);
13706
+ this.emitFile({
13707
+ type: "asset",
13708
+ fileName: `_timber/fonts/${basename}`,
13709
+ source: data
13710
+ });
13711
+ }
13712
+ }
13713
+ const fontCss = generateAllFontCss(registry);
13714
+ if (fontCss) this.emitFile({
13715
+ type: "asset",
13716
+ fileName: "_timber/fonts/fonts.css",
13717
+ source: fontCss
13718
+ });
13536
13719
  if (!ctx.buildManifest) return;
13537
13720
  const cachedByFamily = /* @__PURE__ */ new Map();
13538
13721
  for (const cf of cachedFonts) {
@@ -14400,7 +14583,17 @@ function classifyRoute(segments, outputMode = "server") {
14400
14583
  function green(text) {
14401
14584
  return `\x1b[92m${text}\x1b[39m`;
14402
14585
  }
14403
- /** Walk the route tree and collect all leaf routes (pages + API endpoints). */
14586
+ /**
14587
+ * Walk the route tree and collect all leaf routes (pages + API endpoints).
14588
+ *
14589
+ * Parallel slots (`@artists`, `@shows`, etc.) are intentionally skipped —
14590
+ * they render alongside the parent page at the same URL and are not
14591
+ * separately URL-addressable. Their JS is captured in shared/layout chunks.
14592
+ *
14593
+ * After collection, entries are deduplicated by URL path so that overlapping
14594
+ * route groups (e.g. `(browse)` and `(marketing)` both producing `/`) only
14595
+ * appear once. The entry with the largest route-specific size wins.
14596
+ */
14404
14597
  function collectRoutes(tree) {
14405
14598
  const routes = [];
14406
14599
  function walk(node, chain) {
@@ -14417,10 +14610,14 @@ function collectRoutes(tree) {
14417
14610
  entryFilePath: node.route.filePath
14418
14611
  });
14419
14612
  for (const child of node.children) walk(child, currentChain);
14420
- for (const slot of node.slots.values()) walk(slot, currentChain);
14421
14613
  }
14422
14614
  walk(tree.root, []);
14423
- return routes;
14615
+ const seen = /* @__PURE__ */ new Map();
14616
+ for (const route of routes) {
14617
+ const existing = seen.get(route.path);
14618
+ if (!existing || route.segments.length > existing.segments.length) seen.set(route.path, route);
14619
+ }
14620
+ return Array.from(seen.values());
14424
14621
  }
14425
14622
  /** Produce formatted report lines for the Vite logger. */
14426
14623
  function buildRouteReport(entries, sharedSize) {