@nifrajs/web 2.11.0 → 2.12.1

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 (59) hide show
  1. package/dist/build-vite.d.ts.map +1 -1
  2. package/dist/build-vite.js +10 -0
  3. package/dist/build-vite.js.map +1 -1
  4. package/dist/build.d.ts +7 -0
  5. package/dist/build.d.ts.map +1 -1
  6. package/dist/build.js +5 -2
  7. package/dist/build.js.map +1 -1
  8. package/dist/client.d.ts.map +1 -1
  9. package/dist/client.js +12 -7
  10. package/dist/client.js.map +1 -1
  11. package/dist/conformance.d.ts +1 -1
  12. package/dist/conformance.d.ts.map +1 -1
  13. package/dist/deferred.d.ts +1 -1
  14. package/dist/deferred.d.ts.map +1 -1
  15. package/dist/deferred.js +14 -3
  16. package/dist/deferred.js.map +1 -1
  17. package/dist/dev.d.ts.map +1 -1
  18. package/dist/dev.js +16 -0
  19. package/dist/dev.js.map +1 -1
  20. package/dist/fonts-google.d.ts +2 -2
  21. package/dist/fonts-google.d.ts.map +1 -1
  22. package/dist/fonts-google.js +12 -3
  23. package/dist/fonts-google.js.map +1 -1
  24. package/dist/index.d.ts +65 -117
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +60 -66
  27. package/dist/index.js.map +1 -1
  28. package/dist/isr.d.ts.map +1 -1
  29. package/dist/isr.js +4 -1
  30. package/dist/isr.js.map +1 -1
  31. package/dist/llms-txt.d.ts +3 -1
  32. package/dist/llms-txt.d.ts.map +1 -1
  33. package/dist/llms-txt.js +23 -20
  34. package/dist/llms-txt.js.map +1 -1
  35. package/dist/manifest.d.ts +5 -3
  36. package/dist/manifest.d.ts.map +1 -1
  37. package/dist/manifest.js.map +1 -1
  38. package/dist/navigation.d.ts +9 -0
  39. package/dist/navigation.d.ts.map +1 -1
  40. package/dist/navigation.js +8 -1
  41. package/dist/navigation.js.map +1 -1
  42. package/dist/render-seam.d.ts +61 -0
  43. package/dist/render-seam.d.ts.map +1 -0
  44. package/dist/render-seam.js +22 -0
  45. package/dist/render-seam.js.map +1 -0
  46. package/package.json +2 -2
  47. package/src/build-vite.ts +11 -0
  48. package/src/build.ts +18 -1
  49. package/src/client.ts +13 -7
  50. package/src/conformance.ts +1 -1
  51. package/src/deferred.ts +14 -2
  52. package/src/dev.ts +14 -0
  53. package/src/fonts-google.ts +14 -5
  54. package/src/index.ts +137 -156
  55. package/src/isr.ts +4 -1
  56. package/src/llms-txt.ts +24 -20
  57. package/src/manifest.ts +5 -3
  58. package/src/navigation.ts +14 -1
  59. package/src/render-seam.ts +76 -0
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Framework-agnostic rendering protocol shared by the web runtime and every render adapter.
3
+ *
4
+ * This module is intentionally small and has no runtime dependencies. Keeping the protocol and the
5
+ * dev SSR-loader singleton here lets adapters and conformance tests depend on the seam directly
6
+ * without importing the document renderer through the root module. The singleton is stored on
7
+ * globalThis because the Bun and Vite dev pipelines can evaluate two copies in one process.
8
+ */
9
+ import type { Submission } from "./router.ts"
10
+
11
+ /** The data handed to a route component. */
12
+ export interface RenderProps {
13
+ readonly data: unknown
14
+ /** Per-layout loader data, aligned index-for-index with the layout prefix of `chain`. */
15
+ readonly layoutData?: readonly unknown[]
16
+ readonly actionData?: unknown
17
+ /** True while a client navigation or submit is in flight (client-only; absent/false on SSR). */
18
+ readonly pending?: boolean
19
+ /** The path a client navigation is transitioning TO while `pending` (client-only; absent on SSR). */
20
+ readonly pendingPath?: string
21
+ /** The in-flight client submit, for optimistic UI (client-only; absent on SSR). */
22
+ readonly submission?: Submission
23
+ /** The matched route's decoded path params. */
24
+ readonly params?: Readonly<Record<string, string>>
25
+ /** The current URL's `pathname + search` (no hash). */
26
+ readonly path?: string
27
+ /** The route's typed, validated search params. */
28
+ readonly search?: Record<string, unknown>
29
+ }
30
+
31
+ /**
32
+ * The seam every render adapter implements. New adapters should prove these invariants with
33
+ * `assertRenderAdapterConformance`; framework-specific behavior remains locally tested.
34
+ */
35
+ export interface RenderAdapter {
36
+ /**
37
+ * Render a route's layout `chain` (outermost layout → page) to a Web stream of HTML bytes,
38
+ * including the framework's hydration markers.
39
+ */
40
+ renderToStream(
41
+ chain: readonly unknown[],
42
+ props: RenderProps,
43
+ ): ReadableStream<Uint8Array> | Promise<ReadableStream<Uint8Array>>
44
+ /** Render the chain to a complete HTML string when no content is deferred. */
45
+ renderToString?(chain: readonly unknown[], props: RenderProps): string | Promise<string>
46
+ /** Per-document bootstrap markup injected into `<head>` for client hydration. */
47
+ hydrationHead(nonce?: string): string
48
+ }
49
+
50
+ /** Loads a module through the dev server's module graph rather than the runtime's resolver. */
51
+ export type SsrModuleLoader = (id: string) => Promise<unknown>
52
+
53
+ const SSR_MODULE_LOADER_SLOT = Symbol.for("nifra.web.ssr-module-loader")
54
+ const loaderSlot = globalThis as { [SSR_MODULE_LOADER_SLOT]?: SsrModuleLoader | undefined }
55
+
56
+ /** Publish or clear the dev server's SSR module loader. */
57
+ export function setSsrModuleLoader(load: SsrModuleLoader | undefined): void {
58
+ loaderSlot[SSR_MODULE_LOADER_SLOT] = load
59
+ }
60
+
61
+ /** Return the dev server's SSR module loader, when one owns SSR resolution. */
62
+ export function ssrModuleLoader(): SsrModuleLoader | undefined {
63
+ return loaderSlot[SSR_MODULE_LOADER_SLOT]
64
+ }
65
+
66
+ /** Global the server serializes loader data into; the client reads it to hydrate. */
67
+ export const DATA_GLOBAL = "__NIFRA_DATA__"
68
+ /** Per-layout loader data for hydration. */
69
+ export const LAYOUT_DATA_GLOBAL = "__NIFRA_LAYOUT_DATA__"
70
+ /** Global the server writes the matched route id into. */
71
+ export const ROUTE_GLOBAL = "__NIFRA_ROUTE__"
72
+ /** Global the server serializes an action's data return into (absent on GETs); the client reads it
73
+ * so hydration after a native form POST matches the server-rendered markup. */
74
+ export const ACTION_GLOBAL = "__NIFRA_ACTION__"
75
+ /** Marker attribute used to find a non-default hydration container. */
76
+ export const ROOT_ATTRIBUTE = "data-nifra-root"