@pithyjs/ssr 0.0.0-stage → 0.1.2-beta.9

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 (156) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +100 -2
  3. package/bin/pithy-ssg.mjs +23 -0
  4. package/dist/browser.d.ts +38 -0
  5. package/dist/browser.d.ts.map +1 -0
  6. package/dist/browser.js +40 -0
  7. package/dist/browser.js.map +1 -0
  8. package/dist/build/cli-args.d.ts +104 -0
  9. package/dist/build/cli-args.d.ts.map +1 -0
  10. package/dist/build/cli-args.js +88 -0
  11. package/dist/build/cli-args.js.map +1 -0
  12. package/dist/build/cli-exit.d.ts +95 -0
  13. package/dist/build/cli-exit.d.ts.map +1 -0
  14. package/dist/build/cli-exit.js +237 -0
  15. package/dist/build/cli-exit.js.map +1 -0
  16. package/dist/build/cli.d.ts +11 -0
  17. package/dist/build/cli.d.ts.map +1 -0
  18. package/dist/build/cli.js +93 -0
  19. package/dist/build/cli.js.map +1 -0
  20. package/dist/build/collect-css.d.ts +168 -0
  21. package/dist/build/collect-css.d.ts.map +1 -0
  22. package/dist/build/collect-css.js +479 -0
  23. package/dist/build/collect-css.js.map +1 -0
  24. package/dist/build/css-live-props.d.ts +89 -0
  25. package/dist/build/css-live-props.d.ts.map +1 -0
  26. package/dist/build/css-live-props.js +704 -0
  27. package/dist/build/css-live-props.js.map +1 -0
  28. package/dist/build/css-purge.d.ts +153 -0
  29. package/dist/build/css-purge.d.ts.map +1 -0
  30. package/dist/build/css-purge.js +463 -0
  31. package/dist/build/css-purge.js.map +1 -0
  32. package/dist/build/index.d.ts +24 -0
  33. package/dist/build/index.d.ts.map +1 -0
  34. package/dist/build/index.js +31 -0
  35. package/dist/build/index.js.map +1 -0
  36. package/dist/build/not-found.d.ts +94 -0
  37. package/dist/build/not-found.d.ts.map +1 -0
  38. package/dist/build/not-found.js +99 -0
  39. package/dist/build/not-found.js.map +1 -0
  40. package/dist/build/relative-links.d.ts +31 -0
  41. package/dist/build/relative-links.d.ts.map +1 -0
  42. package/dist/build/relative-links.js +79 -0
  43. package/dist/build/relative-links.js.map +1 -0
  44. package/dist/build/shell-head.d.ts +68 -0
  45. package/dist/build/shell-head.d.ts.map +1 -0
  46. package/dist/build/shell-head.js +236 -0
  47. package/dist/build/shell-head.js.map +1 -0
  48. package/dist/build/sprite-ssg.d.ts +61 -0
  49. package/dist/build/sprite-ssg.d.ts.map +1 -0
  50. package/dist/build/sprite-ssg.js +114 -0
  51. package/dist/build/sprite-ssg.js.map +1 -0
  52. package/dist/build/ssg.d.ts +117 -0
  53. package/dist/build/ssg.d.ts.map +1 -0
  54. package/dist/build/ssg.js +404 -0
  55. package/dist/build/ssg.js.map +1 -0
  56. package/dist/build/vite-ssg.d.ts +396 -0
  57. package/dist/build/vite-ssg.d.ts.map +1 -0
  58. package/dist/build/vite-ssg.js +1130 -0
  59. package/dist/build/vite-ssg.js.map +1 -0
  60. package/dist/client/bootstrap.d.ts +51 -0
  61. package/dist/client/bootstrap.d.ts.map +1 -0
  62. package/dist/client/bootstrap.js +121 -0
  63. package/dist/client/bootstrap.js.map +1 -0
  64. package/dist/client/hydrate.d.ts +60 -0
  65. package/dist/client/hydrate.d.ts.map +1 -0
  66. package/dist/client/hydrate.js +168 -0
  67. package/dist/client/hydrate.js.map +1 -0
  68. package/dist/client/index.d.ts +21 -0
  69. package/dist/client/index.d.ts.map +1 -0
  70. package/dist/client/index.js +16 -0
  71. package/dist/client/index.js.map +1 -0
  72. package/dist/index.d.ts +32 -0
  73. package/dist/index.d.ts.map +1 -0
  74. package/dist/index.js +31 -0
  75. package/dist/index.js.map +1 -0
  76. package/dist/server/app.d.ts +166 -0
  77. package/dist/server/app.d.ts.map +1 -0
  78. package/dist/server/app.js +200 -0
  79. package/dist/server/app.js.map +1 -0
  80. package/dist/server/context.d.ts +238 -0
  81. package/dist/server/context.d.ts.map +1 -0
  82. package/dist/server/context.js +371 -0
  83. package/dist/server/context.js.map +1 -0
  84. package/dist/server/environment.d.ts +88 -0
  85. package/dist/server/environment.d.ts.map +1 -0
  86. package/dist/server/environment.js +261 -0
  87. package/dist/server/environment.js.map +1 -0
  88. package/dist/server/html-shell.d.ts +41 -0
  89. package/dist/server/html-shell.d.ts.map +1 -0
  90. package/dist/server/html-shell.js +208 -0
  91. package/dist/server/html-shell.js.map +1 -0
  92. package/dist/server/index.d.ts +26 -0
  93. package/dist/server/index.d.ts.map +1 -0
  94. package/dist/server/index.js +37 -0
  95. package/dist/server/index.js.map +1 -0
  96. package/dist/server/layout-taint.d.ts +62 -0
  97. package/dist/server/layout-taint.d.ts.map +1 -0
  98. package/dist/server/layout-taint.js +313 -0
  99. package/dist/server/layout-taint.js.map +1 -0
  100. package/dist/server/loaders.d.ts +194 -0
  101. package/dist/server/loaders.d.ts.map +1 -0
  102. package/dist/server/loaders.js +479 -0
  103. package/dist/server/loaders.js.map +1 -0
  104. package/dist/server/render-route.d.ts +102 -0
  105. package/dist/server/render-route.d.ts.map +1 -0
  106. package/dist/server/render-route.js +182 -0
  107. package/dist/server/render-route.js.map +1 -0
  108. package/dist/server/render.d.ts +80 -0
  109. package/dist/server/render.d.ts.map +1 -0
  110. package/dist/server/render.js +256 -0
  111. package/dist/server/render.js.map +1 -0
  112. package/dist/server/router-adapter.d.ts +134 -0
  113. package/dist/server/router-adapter.d.ts.map +1 -0
  114. package/dist/server/router-adapter.js +225 -0
  115. package/dist/server/router-adapter.js.map +1 -0
  116. package/dist/server/serialization.d.ts +54 -0
  117. package/dist/server/serialization.d.ts.map +1 -0
  118. package/dist/server/serialization.js +287 -0
  119. package/dist/server/serialization.js.map +1 -0
  120. package/dist/server/ssr-worker.d.ts +18 -0
  121. package/dist/server/ssr-worker.d.ts.map +1 -0
  122. package/dist/server/ssr-worker.js +118 -0
  123. package/dist/server/ssr-worker.js.map +1 -0
  124. package/dist/server/utils.d.ts +11 -0
  125. package/dist/server/utils.d.ts.map +1 -0
  126. package/dist/server/utils.js +14 -0
  127. package/dist/server/utils.js.map +1 -0
  128. package/dist/server/worker-pool.d.ts +153 -0
  129. package/dist/server/worker-pool.d.ts.map +1 -0
  130. package/dist/server/worker-pool.js +451 -0
  131. package/dist/server/worker-pool.js.map +1 -0
  132. package/dist/server/worker-protocol.d.ts +61 -0
  133. package/dist/server/worker-protocol.d.ts.map +1 -0
  134. package/dist/server/worker-protocol.js +9 -0
  135. package/dist/server/worker-protocol.js.map +1 -0
  136. package/dist/shared/css-purge.d.ts +71 -0
  137. package/dist/shared/css-purge.d.ts.map +1 -0
  138. package/dist/shared/css-purge.js +177 -0
  139. package/dist/shared/css-purge.js.map +1 -0
  140. package/dist/shared/entry-path.d.ts +41 -0
  141. package/dist/shared/entry-path.d.ts.map +1 -0
  142. package/dist/shared/entry-path.js +87 -0
  143. package/dist/shared/entry-path.js.map +1 -0
  144. package/dist/shared/head.d.ts +87 -0
  145. package/dist/shared/head.d.ts.map +1 -0
  146. package/dist/shared/head.js +412 -0
  147. package/dist/shared/head.js.map +1 -0
  148. package/dist/shared/shell-helpers.d.ts +69 -0
  149. package/dist/shared/shell-helpers.d.ts.map +1 -0
  150. package/dist/shared/shell-helpers.js +160 -0
  151. package/dist/shared/shell-helpers.js.map +1 -0
  152. package/dist/shared/types.d.ts +332 -0
  153. package/dist/shared/types.d.ts.map +1 -0
  154. package/dist/shared/types.js +27 -0
  155. package/dist/shared/types.js.map +1 -0
  156. package/package.json +84 -3
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Shared helpers for SSR shell assembly.
3
+ *
4
+ * Used by both the Vite SSR dev plugin (via ssrLoadModule) and the SSG
5
+ * build pipeline (direct import). Keeping a single source of truth avoids
6
+ * behavioral drift between dev and production rendering.
7
+ */
8
+ import { getMetaKey } from './head.js';
9
+ // =============================================================================
10
+ // Path utilities
11
+ // =============================================================================
12
+ /**
13
+ * Convert a URL path to a file path for the output directory.
14
+ *
15
+ * Segment text passes through VERBATIM, by design — no slugifying, no
16
+ * escaping. Naming an entry and rewriting the links that point at it are one
17
+ * policy: `pithy-ssg` pairs a raw name with raw links (`makeLinksRelative`
18
+ * only adds a `../` prefix; `generateStaticSite` does not rebase at all), so
19
+ * renaming here alone emits pages whose links resolve to nothing. Exception:
20
+ * `makeLinksRelative` skips a final `/\.\w+$/` segment as an asset, so `/v1.0`
21
+ * lands here with links pointing at `v1.0` — Bug 10 / BACKLOG #61. Escaping was
22
+ * added (`f1b6ea5b`) and reverted 13 minutes later (`a5d77f40`) for exactly
23
+ * that. Pinned by `build/tests/ssg-helpers.test.ts`; rationale in
24
+ * `docs/ssg/static-export-unification.md`.
25
+ *
26
+ * Examples:
27
+ * - '/' → 'index.html'
28
+ * - '/about' → 'about/index.html'
29
+ * - '/blog/post-1' → 'blog/post-1/index.html'
30
+ *
31
+ * @param urlPath - URL path (e.g., '/about')
32
+ * @returns Relative file path (e.g., 'about/index.html')
33
+ */
34
+ export function pathToFilePath(urlPath) {
35
+ // Strip query string and hash fragment — these are not valid in file paths
36
+ const cleanPath = urlPath.split(/[?#]/)[0];
37
+ // Normalize: remove leading/trailing slashes, collapse double slashes,
38
+ // and reject traversal segments to prevent writing outside outDir
39
+ const normalized = cleanPath
40
+ .replace(/\/+/g, '/')
41
+ .replace(/^\//, '')
42
+ .replace(/\/$/, '')
43
+ .split('/')
44
+ .filter(seg => seg !== '.' && seg !== '..')
45
+ .join('/');
46
+ if (!normalized)
47
+ return 'index.html';
48
+ return `${normalized}/index.html`;
49
+ }
50
+ // =============================================================================
51
+ // Head merging
52
+ // =============================================================================
53
+ /**
54
+ * Merge shell head with page head. Page values take priority:
55
+ * - title: page wins if non-empty
56
+ * - meta: page replaces a shell tag of the same identity, otherwise appended
57
+ * - link/script arrays: concatenated (page after shell)
58
+ * - htmlAttrs/bodyAttrs: merged (page wins on conflict)
59
+ *
60
+ * Meta is keyed the way `head()` already keys its own merge, so a description
61
+ * replaced across shell and page and one replaced across two `head()` calls
62
+ * agree. Concatenating instead shipped two `<meta name="description">`, which
63
+ * is undefined for crawlers.
64
+ */
65
+ export function mergeHead(shell, page) {
66
+ const meta = new Map();
67
+ for (const tag of [...(shell.meta ?? []), ...(page.meta ?? [])]) {
68
+ meta.set(getMetaKey(tag), tag);
69
+ }
70
+ return {
71
+ title: page.title || shell.title || '',
72
+ meta: [...meta.values()],
73
+ link: [...(shell.link ?? []), ...(page.link ?? [])],
74
+ script: [...(shell.script ?? []), ...(page.script ?? [])],
75
+ base: page.base ?? shell.base,
76
+ htmlAttrs: { ...(shell.htmlAttrs ?? {}), ...(page.htmlAttrs ?? {}) },
77
+ bodyAttrs: { ...(shell.bodyAttrs ?? {}), ...(page.bodyAttrs ?? {}) },
78
+ };
79
+ }
80
+ // =============================================================================
81
+ // Outlet injection
82
+ // =============================================================================
83
+ /**
84
+ * Find the router outlet element in the shell HTML.
85
+ *
86
+ * Detection order:
87
+ * 1. `data-router-outlet` attribute (auto-generated by @routerOutlet directive)
88
+ * 2. `id="{outletId}"` attribute (explicit fallback via config.outletId)
89
+ *
90
+ * This means users only need `@routerOutlet` on their outlet element —
91
+ * no extra `id` attribute required.
92
+ */
93
+ export function findOutletMatch(shellHtml, outletId) {
94
+ // 1. Try data-router-outlet (from @routerOutlet directive)
95
+ const directiveRe = /(<[a-z][a-z0-9-]*[^>]*\bdata-router-outlet\b[^>]*>)/i;
96
+ const directiveMatch = shellHtml.match(directiveRe);
97
+ if (directiveMatch && directiveMatch.index !== undefined)
98
+ return directiveMatch;
99
+ // 2. Fall back to id="{outletId}" (escape for safe regex interpolation)
100
+ const escaped = outletId.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
101
+ const idRe = new RegExp(`(<[a-z][a-z0-9-]*[^>]*\\bid="${escaped}"[^>]*>)`, 'i');
102
+ return shellHtml.match(idRe);
103
+ }
104
+ /**
105
+ * Inject page HTML into the App shell's outlet element.
106
+ *
107
+ * Auto-detects the outlet via `@routerOutlet` (data-router-outlet attribute),
108
+ * falling back to `id="{outletId}"` from config.
109
+ * Uses depth-counting to handle nested elements of the same tag correctly.
110
+ *
111
+ * @param shellHtml - Full shell HTML string
112
+ * @param pageHtml - Rendered page content to inject
113
+ * @param outletId - Outlet element ID (default: 'outlet')
114
+ * @param logPrefix - Prefix for warning messages (e.g. '[SSG]' or '[pithy-ssr]')
115
+ */
116
+ export function injectIntoOutlet(shellHtml, pageHtml, outletId, logPrefix = '[SSR]') {
117
+ const match = findOutletMatch(shellHtml, outletId);
118
+ if (!match || match.index === undefined) {
119
+ console.warn(`${logPrefix} Router outlet not found in App shell. ` +
120
+ `Add @routerOutlet to your outlet element, or set outletId in pithy.config.ts. ` +
121
+ `Using page HTML only.`);
122
+ return pageHtml;
123
+ }
124
+ // Extract the tag name for depth tracking
125
+ const tagMatch = match[1].match(/^<([a-z][a-z0-9-]*)/i);
126
+ if (!tagMatch)
127
+ return pageHtml;
128
+ const tagName = tagMatch[1].toLowerCase();
129
+ const openTagEnd = match.index + match[0].length;
130
+ // Find the matching closing tag by counting depth
131
+ const openRe = new RegExp(`<${tagName}[\\s>]`, 'gi');
132
+ const closeRe = new RegExp(`</${tagName}>`, 'gi');
133
+ let depth = 1;
134
+ let pos = openTagEnd;
135
+ while (depth > 0 && pos < shellHtml.length) {
136
+ openRe.lastIndex = pos;
137
+ closeRe.lastIndex = pos;
138
+ const nextOpen = openRe.exec(shellHtml);
139
+ const nextClose = closeRe.exec(shellHtml);
140
+ if (!nextClose)
141
+ break;
142
+ if (nextOpen && nextOpen.index < nextClose.index) {
143
+ depth++;
144
+ pos = nextOpen.index + nextOpen[0].length;
145
+ }
146
+ else {
147
+ depth--;
148
+ if (depth === 0) {
149
+ // Replace content between open tag end and this closing tag
150
+ return (shellHtml.slice(0, openTagEnd) +
151
+ pageHtml +
152
+ shellHtml.slice(nextClose.index));
153
+ }
154
+ pos = nextClose.index + nextClose[0].length;
155
+ }
156
+ }
157
+ console.warn(`${logPrefix} Could not find matching </${tagName}> for outlet. Using page HTML only.`);
158
+ return pageHtml;
159
+ }
160
+ //# sourceM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MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACxC,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAE1C,IAAI,CAAC,SAAS;YAAE,MAAM;QAEtB,IAAI,QAAQ,IAAI,QAAQ,CAAC,KAAK,GAAG,SAAS,CAAC,KAAK,EAAE,CAAC;YACjD,KAAK,EAAE,CAAC;YACR,GAAG,GAAG,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAC5C,CAAC;aAAM,CAAC;YACN,KAAK,EAAE,CAAC;YACR,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;gBAChB,4DAA4D;gBAC5D,OAAO,CACL,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC;oBAC9B,QAAQ;oBACR,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CACjC,CAAC;YACJ,CAAC;YACD,GAAG,GAAG,SAAS,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAC9C,CAAC;IACH,CAAC;IAED,OAAO,CAAC,IAAI,CACV,GAAG,SAAS,8BAA8B,OAAO,qCAAqC,CACvF,CAAC;IACF,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["/**\n * Shared helpers for SSR shell assembly.\n *\n * Used by both the Vite SSR dev plugin (via ssrLoadModule) and the SSG\n * build pipeline (direct import). Keeping a single source of truth avoids\n * behavioral drift between dev and production rendering.\n */\n\nimport type { HeadState, MetaTag } from './types.js';\nimport { getMetaKey } from './head.js';\n\n// =============================================================================\n// Path utilities\n// =============================================================================\n\n/**\n * Convert a URL path to a file path for the output directory.\n *\n * Segment text passes through VERBATIM, by design — no slugifying, no\n * escaping. Naming an entry and rewriting the links that point at it are one\n * policy: `pithy-ssg` pairs a raw name with raw links (`makeLinksRelative`\n * only adds a `../` prefix; `generateStaticSite` does not rebase at all), so\n * renaming here alone emits pages whose links resolve to nothing. Exception:\n * `makeLinksRelative` skips a final `/\\.\\w+$/` segment as an asset, so `/v1.0`\n * lands here with links pointing at `v1.0` — Bug 10 / BACKLOG #61. Escaping was\n * added (`f1b6ea5b`) and reverted 13 minutes later (`a5d77f40`) for exactly\n * that. Pinned by `build/tests/ssg-helpers.test.ts`; rationale in\n * `docs/ssg/static-export-unification.md`.\n *\n * Examples:\n * - '/' → 'index.html'\n * - '/about' → 'about/index.html'\n * - '/blog/post-1' → 'blog/post-1/index.html'\n *\n * @param urlPath - URL path (e.g., '/about')\n * @returns Relative file path (e.g., 'about/index.html')\n */\nexport function pathToFilePath(urlPath: string): string {\n // Strip query string and hash fragment — these are not valid in file paths\n const cleanPath = urlPath.split(/[?#]/)[0];\n\n // Normalize: remove leading/trailing slashes, collapse double slashes,\n // and reject traversal segments to prevent writing outside outDir\n const normalized = cleanPath\n .replace(/\\/+/g, '/')\n .replace(/^\\//, '')\n .replace(/\\/$/, '')\n .split('/')\n .filter(seg => seg !== '.' && seg !== '..')\n .join('/');\n\n if (!normalized) return 'index.html';\n return `${normalized}/index.html`;\n}\n\n// =============================================================================\n// Head merging\n// =============================================================================\n\n/**\n * Merge shell head with page head. Page values take priority:\n * - title: page wins if non-empty\n * - meta: page replaces a shell tag of the same identity, otherwise appended\n * - link/script arrays: concatenated (page after shell)\n * - htmlAttrs/bodyAttrs: merged (page wins on conflict)\n *\n * Meta is keyed the way `head()` already keys its own merge, so a description\n * replaced across shell and page and one replaced across two `head()` calls\n * agree. Concatenating instead shipped two `<meta name=\"description\">`, which\n * is undefined for crawlers.\n */\nexport function mergeHead(\n shell: Partial<HeadState>,\n page: Partial<HeadState>\n): HeadState {\n const meta = new Map<string, MetaTag>();\n for (const tag of [...(shell.meta ?? []), ...(page.meta ?? [])]) {\n meta.set(getMetaKey(tag), tag);\n }\n\n return {\n title: page.title || shell.title || '',\n meta: [...meta.values()],\n link: [...(shell.link ?? []), ...(page.link ?? [])],\n script: [...(shell.script ?? []), ...(page.script ?? [])],\n base: page.base ?? shell.base,\n htmlAttrs: { ...(shell.htmlAttrs ?? {}), ...(page.htmlAttrs ?? {}) },\n bodyAttrs: { ...(shell.bodyAttrs ?? {}), ...(page.bodyAttrs ?? {}) },\n };\n}\n\n// =============================================================================\n// Outlet injection\n// =============================================================================\n\n/**\n * Find the router outlet element in the shell HTML.\n *\n * Detection order:\n * 1. `data-router-outlet` attribute (auto-generated by @routerOutlet directive)\n * 2. `id=\"{outletId}\"` attribute (explicit fallback via config.outletId)\n *\n * This means users only need `@routerOutlet` on their outlet element —\n * no extra `id` attribute required.\n */\nexport function findOutletMatch(\n shellHtml: string,\n outletId: string\n): RegExpMatchArray | null {\n // 1. Try data-router-outlet (from @routerOutlet directive)\n const directiveRe = /(<[a-z][a-z0-9-]*[^>]*\\bdata-router-outlet\\b[^>]*>)/i;\n const directiveMatch = shellHtml.match(directiveRe);\n if (directiveMatch && directiveMatch.index !== undefined)\n return directiveMatch;\n\n // 2. Fall back to id=\"{outletId}\" (escape for safe regex interpolation)\n const escaped = outletId.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n const idRe = new RegExp(\n `(<[a-z][a-z0-9-]*[^>]*\\\\bid=\"${escaped}\"[^>]*>)`,\n 'i'\n );\n return shellHtml.match(idRe);\n}\n\n/**\n * Inject page HTML into the App shell's outlet element.\n *\n * Auto-detects the outlet via `@routerOutlet` (data-router-outlet attribute),\n * falling back to `id=\"{outletId}\"` from config.\n * Uses depth-counting to handle nested elements of the same tag correctly.\n *\n * @param shellHtml - Full shell HTML string\n * @param pageHtml - Rendered page content to inject\n * @param outletId - Outlet element ID (default: 'outlet')\n * @param logPrefix - Prefix for warning messages (e.g. '[SSG]' or '[pithy-ssr]')\n */\nexport function injectIntoOutlet(\n shellHtml: string,\n pageHtml: string,\n outletId: string,\n logPrefix = '[SSR]'\n): string {\n const match = findOutletMatch(shellHtml, outletId);\n\n if (!match || match.index === undefined) {\n console.warn(\n `${logPrefix} Router outlet not found in App shell. ` +\n `Add @routerOutlet to your outlet element, or set outletId in pithy.config.ts. ` +\n `Using page HTML only.`\n );\n return pageHtml;\n }\n\n // Extract the tag name for depth tracking\n const tagMatch = match[1].match(/^<([a-z][a-z0-9-]*)/i);\n if (!tagMatch) return pageHtml;\n const tagName = tagMatch[1].toLowerCase();\n\n const openTagEnd = match.index + match[0].length;\n\n // Find the matching closing tag by counting depth\n const openRe = new RegExp(`<${tagName}[\\\\s>]`, 'gi');\n const closeRe = new RegExp(`</${tagName}>`, 'gi');\n\n let depth = 1;\n let pos = openTagEnd;\n\n while (depth > 0 && pos < shellHtml.length) {\n openRe.lastIndex = pos;\n closeRe.lastIndex = pos;\n\n const nextOpen = openRe.exec(shellHtml);\n const nextClose = closeRe.exec(shellHtml);\n\n if (!nextClose) break;\n\n if (nextOpen && nextOpen.index < nextClose.index) {\n depth++;\n pos = nextOpen.index + nextOpen[0].length;\n } else {\n depth--;\n if (depth === 0) {\n // Replace content between open tag end and this closing tag\n return (\n shellHtml.slice(0, openTagEnd) +\n pageHtml +\n shellHtml.slice(nextClose.index)\n );\n }\n pos = nextClose.index + nextClose[0].length;\n }\n }\n\n console.warn(\n `${logPrefix} Could not find matching </${tagName}> for outlet. Using page HTML only.`\n );\n return pageHtml;\n}\n"]}
@@ -0,0 +1,332 @@
1
+ /** @codex
2
+ {
3
+ "id": "pithy.ssr.types",
4
+ "title": "SSR Type Definitions",
5
+ "category": "types"
6
+ }
7
+ */
8
+ /**
9
+ * @pithyjs/ssr - Type Definitions
10
+ *
11
+ * SSR-specific types for Server-Side Rendering and Static Site Generation.
12
+ * Router types (RouteNode, LoaderContext, etc.) are imported from @pithyjs/router where needed.
13
+ */
14
+ /**
15
+ * Cross-origin attribute values for resources
16
+ */
17
+ export type CrossOrigin = 'anonymous' | 'use-credentials';
18
+ /**
19
+ * Fetch priority hint for resources
20
+ */
21
+ export type FetchPriority = 'high' | 'low' | 'auto';
22
+ /**
23
+ * Referrer policy for resources
24
+ */
25
+ export type ReferrerPolicy = 'no-referrer' | 'no-referrer-when-downgrade' | 'origin' | 'origin-when-cross-origin' | 'same-origin' | 'strict-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url';
26
+ /**
27
+ * Link target attribute values
28
+ */
29
+ export type LinkTarget = '_self' | '_blank' | '_parent' | '_top';
30
+ /**
31
+ * Head configuration for SEO
32
+ */
33
+ export interface HeadConfig {
34
+ /** Page title */
35
+ title?: string;
36
+ /** Meta tags */
37
+ meta?: MetaTag[];
38
+ /** Link tags (stylesheets, preloads, etc.) */
39
+ link?: LinkTag[];
40
+ /** Script tags */
41
+ script?: ScriptTag[];
42
+ /** Base tag */
43
+ base?: BaseTag;
44
+ /** HTML attributes for <html> element */
45
+ htmlAttrs?: Record<string, string>;
46
+ /** Attributes for <body> element */
47
+ bodyAttrs?: Record<string, string>;
48
+ }
49
+ /**
50
+ * Meta tag definition
51
+ */
52
+ export interface MetaTag {
53
+ /** Name attribute (e.g., "description", "viewport") */
54
+ name?: string;
55
+ /** Property attribute (e.g., "og:title", "og:image") */
56
+ property?: string;
57
+ /** HTTP-equiv attribute */
58
+ httpEquiv?: string;
59
+ /** Content value */
60
+ content: string;
61
+ /** Charset (for charset meta tag) */
62
+ charset?: string;
63
+ }
64
+ /**
65
+ * Link tag definition
66
+ */
67
+ export interface LinkTag {
68
+ /** Relationship (e.g., "stylesheet", "preload", "icon") */
69
+ rel: string;
70
+ /** URL */
71
+ href: string;
72
+ /** MIME type */
73
+ type?: string;
74
+ /** Cross-origin setting */
75
+ crossorigin?: CrossOrigin;
76
+ /** As attribute for preload */
77
+ as?: string;
78
+ /** Media query */
79
+ media?: string;
80
+ /** Sizes for icons */
81
+ sizes?: string;
82
+ /** Fetch priority */
83
+ fetchpriority?: FetchPriority;
84
+ /** Referrer policy */
85
+ referrerpolicy?: ReferrerPolicy;
86
+ }
87
+ /**
88
+ * Script tag definition
89
+ */
90
+ export interface ScriptTag {
91
+ /** Script source URL */
92
+ src?: string;
93
+ /** Inline script content */
94
+ content?: string;
95
+ /** Script type (defaults to module for src, text/javascript for inline) */
96
+ type?: string;
97
+ /** Async loading */
98
+ async?: boolean;
99
+ /** Defer loading */
100
+ defer?: boolean;
101
+ /** Cross-origin setting */
102
+ crossorigin?: CrossOrigin;
103
+ /** Fetch priority */
104
+ fetchpriority?: FetchPriority;
105
+ /** Referrer policy */
106
+ referrerpolicy?: ReferrerPolicy;
107
+ /** Integrity hash for SRI */
108
+ integrity?: string;
109
+ /** Nonce for CSP */
110
+ nonce?: string;
111
+ }
112
+ /**
113
+ * Base tag definition
114
+ */
115
+ export interface BaseTag {
116
+ href?: string;
117
+ target?: LinkTarget;
118
+ }
119
+ /**
120
+ * Collected head state during SSR
121
+ */
122
+ export interface HeadState {
123
+ title: string;
124
+ meta: MetaTag[];
125
+ link: LinkTag[];
126
+ script: ScriptTag[];
127
+ base?: BaseTag;
128
+ htmlAttrs: Record<string, string>;
129
+ bodyAttrs: Record<string, string>;
130
+ }
131
+ /**
132
+ * SSR context available during server-side rendering
133
+ */
134
+ export interface SSRContext {
135
+ /** Current URL being rendered */
136
+ url: string;
137
+ /** Route parameters */
138
+ params: Record<string, string>;
139
+ /** Query parameters */
140
+ query: Record<string, string>;
141
+ /** Collected head state */
142
+ head: HeadState;
143
+ /** Loader data by route segment ID */
144
+ loaderData: Record<string, unknown>;
145
+ /** Flag indicating SSR mode */
146
+ isSSR: true;
147
+ /** Redirect URL if a redirect was triggered */
148
+ redirectTo?: string;
149
+ /** HTTP status code */
150
+ status: number;
151
+ }
152
+ /**
153
+ * Result from renderToString
154
+ */
155
+ export interface RenderResult {
156
+ /** Rendered HTML content */
157
+ html: string;
158
+ /** Collected head state */
159
+ head: HeadState;
160
+ /** Serialized state for hydration */
161
+ state: SerializedState;
162
+ /** HTTP status code */
163
+ status: number;
164
+ /** Redirect URL if redirect occurred */
165
+ redirectTo?: string;
166
+ /** Timing information */
167
+ timing?: RenderTiming;
168
+ /**
169
+ * What the layout taint dropped, and what looks like it escaped.
170
+ *
171
+ * Returned rather than logged: `renderToString()` is the per-request SSR path
172
+ * as well as the static-export one, so writing directly to the console here
173
+ * would emit on every production request for a page that is behaving exactly
174
+ * as designed. The static-export CLI reports these; a server can ignore them.
175
+ */
176
+ layoutDiagnostics?: LayoutDiagnostics;
177
+ }
178
+ /**
179
+ * Layout-taint findings for one render.
180
+ */
181
+ export interface LayoutDiagnostics {
182
+ /** Measurement-derived declarations removed before serialization. */
183
+ droppedStyles: string[];
184
+ /**
185
+ * Zero-valued geometry left in the output — the fingerprint of a measurement
186
+ * laundered through a comparison. A heuristic; a genuine zero is possible.
187
+ */
188
+ suspiciousGeometry: string[];
189
+ }
190
+ /**
191
+ * Timing information for render
192
+ */
193
+ export interface RenderTiming {
194
+ /** Total render time (ms) */
195
+ total: number;
196
+ /** Route matching time (ms) */
197
+ routeMatch: number;
198
+ /** Loader execution time (ms) */
199
+ loaders: number;
200
+ /** Component render time (ms) */
201
+ render: number;
202
+ /** Serialization time (ms) */
203
+ serialize: number;
204
+ }
205
+ /**
206
+ * Serialized state for hydration
207
+ */
208
+ export interface SerializedState {
209
+ /** URL that was rendered */
210
+ url: string;
211
+ /** Route parameters */
212
+ params: Record<string, string>;
213
+ /**
214
+ * Query parameters (always serialized; defaults to `{}` when no query params are present)
215
+ */
216
+ query: Record<string, string>;
217
+ /** Loader data by route segment */
218
+ loaderData: Record<string, unknown>;
219
+ /** Timestamp of render */
220
+ timestamp: number;
221
+ /** Version for compatibility checking */
222
+ version: string;
223
+ }
224
+ /**
225
+ * Options for client hydration
226
+ */
227
+ export interface HydrateOptions {
228
+ /** Target element to hydrate */
229
+ target: HTMLElement;
230
+ /** Serialized state from server */
231
+ state?: SerializedState;
232
+ /** Callback when hydration completes */
233
+ onHydrated?: () => void;
234
+ /** Callback on hydration error */
235
+ onError?: (error: Error) => void;
236
+ }
237
+ /**
238
+ * Options for HTML shell generation
239
+ */
240
+ export interface ShellOptions {
241
+ /** Rendered HTML content */
242
+ html: string;
243
+ /** Head state */
244
+ head: HeadState;
245
+ /** Serialized state for hydration (omit in static/no-JS mode to skip the state script) */
246
+ state?: SerializedState;
247
+ /** Script URLs to include */
248
+ scripts?: string[];
249
+ /** Stylesheet URLs to include */
250
+ styles?: string[];
251
+ /** HTML lang attribute */
252
+ lang?: string;
253
+ /** Additional body attributes */
254
+ bodyAttrs?: Record<string, string>;
255
+ /** ID of app container element */
256
+ appId?: string;
257
+ /** Inline critical CSS */
258
+ criticalCss?: string;
259
+ /** Preload hints */
260
+ preloads?: PreloadHint[];
261
+ }
262
+ /**
263
+ * Resource preload hint
264
+ */
265
+ export interface PreloadHint {
266
+ href: string;
267
+ as: 'script' | 'style' | 'font' | 'image' | 'fetch';
268
+ type?: string;
269
+ crossorigin?: CrossOrigin;
270
+ }
271
+ /**
272
+ * Result from SSG build
273
+ */
274
+ export interface SSGResult {
275
+ /**
276
+ * Successfully rendered ROUTE paths.
277
+ *
278
+ * The site-wide not-found document is not one of these. It has no route path
279
+ * of its own — it is rendered at a synthetic URL and written to a fixed
280
+ * filename — so reporting it as `/404` both invented a route the app may not
281
+ * have and, for an app that *does* define `/404`, listed that path twice with
282
+ * no way to tell the two entries apart. See {@link SSGResult.notFound}.
283
+ */
284
+ rendered: string[];
285
+ /** Failed paths with errors */
286
+ failed: Array<{
287
+ path: string;
288
+ error: Error;
289
+ }>;
290
+ /**
291
+ * Entry the site-wide not-found document was written to (`404.html`), or
292
+ * `null` when none was written.
293
+ *
294
+ * This is `generateStaticSite()`'s result. It emits a 404 only when given a
295
+ * `routes` tree containing a top-level catch-all, so `null` means either no
296
+ * such route or a render that wrote no file (a redirect). The extra reasons
297
+ * `buildSSG()` can decline — a catch-all that rendered no content, or a
298
+ * hand-authored `public/404.html` — belong to its own `SSGBuildResult`; this
299
+ * engine implements neither.
300
+ */
301
+ notFound: string | null;
302
+ /** Total build time (ms) */
303
+ totalTime: number;
304
+ }
305
+ /**
306
+ * SSR environment setup result
307
+ */
308
+ export interface SSREnvironment {
309
+ /** Cleanup function to release resources */
310
+ cleanup: () => void;
311
+ /** The window object (from happy-dom) */
312
+ window: Window;
313
+ /** The document object */
314
+ document: Document;
315
+ }
316
+ /**
317
+ * Current SSR package version (for state compatibility)
318
+ */
319
+ export declare const SSR_VERSION = "0.1.0";
320
+ /**
321
+ * Default state variable name on window
322
+ */
323
+ export declare const STATE_VAR_NAME = "__PITHY__";
324
+ /**
325
+ * Hydration complete flag name
326
+ */
327
+ export declare const HYDRATED_FLAG = "__PITHY_HYDRATED__";
328
+ /**
329
+ * Default app container ID
330
+ */
331
+ export declare const DEFAULT_APP_ID = "app";
332
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF;;;;;GAKG;AAMH;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,iBAAiB,CAAC;AAE1D;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,CAAC;AAEpD;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB,aAAa,GACb,4BAA4B,GAC5B,QAAQ,GACR,0BAA0B,GAC1B,aAAa,GACb,eAAe,GACf,iCAAiC,GACjC,YAAY,CAAC;AAEjB;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAC;AAMjE;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,iBAAiB;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB;IAChB,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;IACjB,8CAA8C;IAC9C,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;IACjB,kBAAkB;IAClB,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC;IACrB,eAAe;IACf,IAAI,CAAC,EAAE,OAA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,CAAC,CAAC;IAC9C;;;;;;;;;;OAUG;IACH,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,4BAA4B;IAC5B,SAAS,EAAE,MAAM,CAAC;CACnB;AAMD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,4CAA4C;IAC5C,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,yCAAyC;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,0BAA0B;IAC1B,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAMD;;GAEG;AACH,eAAO,MAAM,WAAW,UAAU,CAAC;AAEnC;;GAEG;AACH,eAAO,MAAM,cAAc,cAAc,CAAC;AAE1C;;GAEG;AACH,eAAO,MAAM,aAAa,uBAAuB,CAAC;AAElD;;GAEG;AACH,eAAO,MAAM,cAAc,QAAQ,CAAC"}
@@ -0,0 +1,27 @@
1
+ /** @codex
2
+ {
3
+ "id": "pithy.ssr.types",
4
+ "title": "SSR Type Definitions",
5
+ "category": "types"
6
+ }
7
+ */
8
+ // =============================================================================
9
+ // Constants
10
+ // =============================================================================
11
+ /**
12
+ * Current SSR package version (for state compatibility)
13
+ */
14
+ export const SSR_VERSION = '0.1.0';
15
+ /**
16
+ * Default state variable name on window
17
+ */
18
+ export const STATE_VAR_NAME = '__PITHY__';
19
+ /**
20
+ * Hydration complete flag name
21
+ */
22
+ export const HYDRATED_FLAG = '__PITHY_HYDRATED__';
23
+ /**
24
+ * Default app container ID
25
+ */
26
+ export const DEFAULT_APP_ID = 'app';
27
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAgXF,gFAAgF;AAChF,YAAY;AACZ,gFAAgF;AAEhF;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC;AAEnC;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC;AAE1C;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,oBAAoB,CAAC;AAElD;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.ssr.types\",\n \"title\": \"SSR Type Definitions\",\n \"category\": \"types\"\n}\n*/\n\n/**\n * @pithyjs/ssr - Type Definitions\n *\n * SSR-specific types for Server-Side Rendering and Static Site Generation.\n * Router types (RouteNode, LoaderContext, etc.) are imported from @pithyjs/router where needed.\n */\n\n// =============================================================================\n// Common Utility Types\n// =============================================================================\n\n/**\n * Cross-origin attribute values for resources\n */\nexport type CrossOrigin = 'anonymous' | 'use-credentials';\n\n/**\n * Fetch priority hint for resources\n */\nexport type FetchPriority = 'high' | 'low' | 'auto';\n\n/**\n * Referrer policy for resources\n */\nexport type ReferrerPolicy =\n | 'no-referrer'\n | 'no-referrer-when-downgrade'\n | 'origin'\n | 'origin-when-cross-origin'\n | 'same-origin'\n | 'strict-origin'\n | 'strict-origin-when-cross-origin'\n | 'unsafe-url';\n\n/**\n * Link target attribute values\n */\nexport type LinkTarget = '_self' | '_blank' | '_parent' | '_top';\n\n// =============================================================================\n// Head/SEO Types\n// =============================================================================\n\n/**\n * Head configuration for SEO\n */\nexport interface HeadConfig {\n /** Page title */\n title?: string;\n /** Meta tags */\n meta?: MetaTag[];\n /** Link tags (stylesheets, preloads, etc.) */\n link?: LinkTag[];\n /** Script tags */\n script?: ScriptTag[];\n /** Base tag */\n base?: BaseTag;\n /** HTML attributes for <html> element */\n htmlAttrs?: Record<string, string>;\n /** Attributes for <body> element */\n bodyAttrs?: Record<string, string>;\n}\n\n/**\n * Meta tag definition\n */\nexport interface MetaTag {\n /** Name attribute (e.g., \"description\", \"viewport\") */\n name?: string;\n /** Property attribute (e.g., \"og:title\", \"og:image\") */\n property?: string;\n /** HTTP-equiv attribute */\n httpEquiv?: string;\n /** Content value */\n content: string;\n /** Charset (for charset meta tag) */\n charset?: string;\n}\n\n/**\n * Link tag definition\n */\nexport interface LinkTag {\n /** Relationship (e.g., \"stylesheet\", \"preload\", \"icon\") */\n rel: string;\n /** URL */\n href: string;\n /** MIME type */\n type?: string;\n /** Cross-origin setting */\n crossorigin?: CrossOrigin;\n /** As attribute for preload */\n as?: string;\n /** Media query */\n media?: string;\n /** Sizes for icons */\n sizes?: string;\n /** Fetch priority */\n fetchpriority?: FetchPriority;\n /** Referrer policy */\n referrerpolicy?: ReferrerPolicy;\n}\n\n/**\n * Script tag definition\n */\nexport interface ScriptTag {\n /** Script source URL */\n src?: string;\n /** Inline script content */\n content?: string;\n /** Script type (defaults to module for src, text/javascript for inline) */\n type?: string;\n /** Async loading */\n async?: boolean;\n /** Defer loading */\n defer?: boolean;\n /** Cross-origin setting */\n crossorigin?: CrossOrigin;\n /** Fetch priority */\n fetchpriority?: FetchPriority;\n /** Referrer policy */\n referrerpolicy?: ReferrerPolicy;\n /** Integrity hash for SRI */\n integrity?: string;\n /** Nonce for CSP */\n nonce?: string;\n}\n\n/**\n * Base tag definition\n */\nexport interface BaseTag {\n href?: string;\n target?: LinkTarget;\n}\n\n/**\n * Collected head state during SSR\n */\nexport interface HeadState {\n title: string;\n meta: MetaTag[];\n link: LinkTag[];\n script: ScriptTag[];\n base?: BaseTag;\n htmlAttrs: Record<string, string>;\n bodyAttrs: Record<string, string>;\n}\n\n// =============================================================================\n// SSR Context Types\n// =============================================================================\n\n/**\n * SSR context available during server-side rendering\n */\nexport interface SSRContext {\n /** Current URL being rendered */\n url: string;\n /** Route parameters */\n params: Record<string, string>;\n /** Query parameters */\n query: Record<string, string>;\n /** Collected head state */\n head: HeadState;\n /** Loader data by route segment ID */\n loaderData: Record<string, unknown>;\n /** Flag indicating SSR mode */\n isSSR: true;\n /** Redirect URL if a redirect was triggered */\n redirectTo?: string;\n /** HTTP status code */\n status: number;\n}\n\n// =============================================================================\n// Render Types\n// =============================================================================\n\n/**\n * Result from renderToString\n */\nexport interface RenderResult {\n /** Rendered HTML content */\n html: string;\n /** Collected head state */\n head: HeadState;\n /** Serialized state for hydration */\n state: SerializedState;\n /** HTTP status code */\n status: number;\n /** Redirect URL if redirect occurred */\n redirectTo?: string;\n /** Timing information */\n timing?: RenderTiming;\n /**\n * What the layout taint dropped, and what looks like it escaped.\n *\n * Returned rather than logged: `renderToString()` is the per-request SSR path\n * as well as the static-export one, so writing directly to the console here\n * would emit on every production request for a page that is behaving exactly\n * as designed. The static-export CLI reports these; a server can ignore them.\n */\n layoutDiagnostics?: LayoutDiagnostics;\n}\n\n/**\n * Layout-taint findings for one render.\n */\nexport interface LayoutDiagnostics {\n /** Measurement-derived declarations removed before serialization. */\n droppedStyles: string[];\n /**\n * Zero-valued geometry left in the output — the fingerprint of a measurement\n * laundered through a comparison. A heuristic; a genuine zero is possible.\n */\n suspiciousGeometry: string[];\n}\n\n/**\n * Timing information for render\n */\nexport interface RenderTiming {\n /** Total render time (ms) */\n total: number;\n /** Route matching time (ms) */\n routeMatch: number;\n /** Loader execution time (ms) */\n loaders: number;\n /** Component render time (ms) */\n render: number;\n /** Serialization time (ms) */\n serialize: number;\n}\n\n// =============================================================================\n// Hydration Types\n// =============================================================================\n\n/**\n * Serialized state for hydration\n */\nexport interface SerializedState {\n /** URL that was rendered */\n url: string;\n /** Route parameters */\n params: Record<string, string>;\n /**\n * Query parameters (always serialized; defaults to `{}` when no query params are present)\n */\n query: Record<string, string>;\n /** Loader data by route segment */\n loaderData: Record<string, unknown>;\n /** Timestamp of render */\n timestamp: number;\n /** Version for compatibility checking */\n version: string;\n}\n\n/**\n * Options for client hydration\n */\nexport interface HydrateOptions {\n /** Target element to hydrate */\n target: HTMLElement;\n /** Serialized state from server */\n state?: SerializedState;\n /** Callback when hydration completes */\n onHydrated?: () => void;\n /** Callback on hydration error */\n onError?: (error: Error) => void;\n}\n\n// =============================================================================\n// HTML Shell Types\n// =============================================================================\n\n/**\n * Options for HTML shell generation\n */\nexport interface ShellOptions {\n /** Rendered HTML content */\n html: string;\n /** Head state */\n head: HeadState;\n /** Serialized state for hydration (omit in static/no-JS mode to skip the state script) */\n state?: SerializedState;\n /** Script URLs to include */\n scripts?: string[];\n /** Stylesheet URLs to include */\n styles?: string[];\n /** HTML lang attribute */\n lang?: string;\n /** Additional body attributes */\n bodyAttrs?: Record<string, string>;\n /** ID of app container element */\n appId?: string;\n /** Inline critical CSS */\n criticalCss?: string;\n /** Preload hints */\n preloads?: PreloadHint[];\n}\n\n/**\n * Resource preload hint\n */\nexport interface PreloadHint {\n href: string;\n as: 'script' | 'style' | 'font' | 'image' | 'fetch';\n type?: string;\n crossorigin?: CrossOrigin;\n}\n\n// =============================================================================\n// SSG Types\n// =============================================================================\n\n/**\n * Result from SSG build\n */\nexport interface SSGResult {\n /**\n * Successfully rendered ROUTE paths.\n *\n * The site-wide not-found document is not one of these. It has no route path\n * of its own — it is rendered at a synthetic URL and written to a fixed\n * filename — so reporting it as `/404` both invented a route the app may not\n * have and, for an app that *does* define `/404`, listed that path twice with\n * no way to tell the two entries apart. See {@link SSGResult.notFound}.\n */\n rendered: string[];\n /** Failed paths with errors */\n failed: Array<{ path: string; error: Error }>;\n /**\n * Entry the site-wide not-found document was written to (`404.html`), or\n * `null` when none was written.\n *\n * This is `generateStaticSite()`'s result. It emits a 404 only when given a\n * `routes` tree containing a top-level catch-all, so `null` means either no\n * such route or a render that wrote no file (a redirect). The extra reasons\n * `buildSSG()` can decline — a catch-all that rendered no content, or a\n * hand-authored `public/404.html` — belong to its own `SSGBuildResult`; this\n * engine implements neither.\n */\n notFound: string | null;\n /** Total build time (ms) */\n totalTime: number;\n}\n\n// =============================================================================\n// Environment Types\n// =============================================================================\n\n/**\n * SSR environment setup result\n */\nexport interface SSREnvironment {\n /** Cleanup function to release resources */\n cleanup: () => void;\n /** The window object (from happy-dom) */\n window: Window;\n /** The document object */\n document: Document;\n}\n\n// =============================================================================\n// Constants\n// =============================================================================\n\n/**\n * Current SSR package version (for state compatibility)\n */\nexport const SSR_VERSION = '0.1.0';\n\n/**\n * Default state variable name on window\n */\nexport const STATE_VAR_NAME = '__PITHY__';\n\n/**\n * Hydration complete flag name\n */\nexport const HYDRATED_FLAG = '__PITHY_HYDRATED__';\n\n/**\n * Default app container ID\n */\nexport const DEFAULT_APP_ID = 'app';\n"]}