@nifrajs/web 3.1.0 → 3.3.0

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 (114) hide show
  1. package/dist/build-plan.d.ts +228 -0
  2. package/dist/build-plan.d.ts.map +1 -0
  3. package/dist/build-plan.js +514 -0
  4. package/dist/build-plan.js.map +1 -0
  5. package/dist/build-vite.d.ts +2 -1
  6. package/dist/build-vite.d.ts.map +1 -1
  7. package/dist/build-vite.js.map +1 -1
  8. package/dist/build.d.ts +2 -197
  9. package/dist/build.d.ts.map +1 -1
  10. package/dist/build.js +61 -502
  11. package/dist/build.js.map +1 -1
  12. package/dist/chunk-names.d.ts.map +1 -1
  13. package/dist/chunk-names.js +3 -2
  14. package/dist/chunk-names.js.map +1 -1
  15. package/dist/dev-ssr-graph.d.ts.map +1 -1
  16. package/dist/dev-ssr-graph.js +63 -28
  17. package/dist/dev-ssr-graph.js.map +1 -1
  18. package/dist/diagnostic.d.ts.map +1 -1
  19. package/dist/diagnostic.js +9 -2
  20. package/dist/diagnostic.js.map +1 -1
  21. package/dist/fonts-google.d.ts.map +1 -1
  22. package/dist/fonts-google.js +3 -1
  23. package/dist/fonts-google.js.map +1 -1
  24. package/dist/fs.d.ts.map +1 -1
  25. package/dist/fs.js +2 -1
  26. package/dist/fs.js.map +1 -1
  27. package/dist/index.d.ts +15 -609
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +22 -1935
  30. package/dist/index.js.map +1 -1
  31. package/dist/internal/codegen.d.ts +68 -0
  32. package/dist/internal/codegen.d.ts.map +1 -0
  33. package/dist/internal/codegen.js +317 -0
  34. package/dist/internal/codegen.js.map +1 -0
  35. package/dist/internal/head-merge.d.ts +2 -0
  36. package/dist/internal/head-merge.d.ts.map +1 -1
  37. package/dist/internal/head-merge.js +17 -1
  38. package/dist/internal/head-merge.js.map +1 -1
  39. package/dist/internal/parity.d.ts +7 -0
  40. package/dist/internal/parity.d.ts.map +1 -1
  41. package/dist/internal/parity.js +212 -30
  42. package/dist/internal/parity.js.map +1 -1
  43. package/dist/internal/render-document.d.ts +372 -0
  44. package/dist/internal/render-document.d.ts.map +1 -0
  45. package/dist/internal/render-document.js +744 -0
  46. package/dist/internal/render-document.js.map +1 -0
  47. package/dist/internal/runtime-contract.d.ts +48 -0
  48. package/dist/internal/runtime-contract.d.ts.map +1 -0
  49. package/dist/internal/runtime-contract.js +27 -0
  50. package/dist/internal/runtime-contract.js.map +1 -0
  51. package/dist/internal/web-app.d.ts +171 -0
  52. package/dist/internal/web-app.d.ts.map +1 -0
  53. package/dist/internal/web-app.js +844 -0
  54. package/dist/internal/web-app.js.map +1 -0
  55. package/dist/islands.d.ts +48 -0
  56. package/dist/islands.d.ts.map +1 -1
  57. package/dist/islands.js +79 -0
  58. package/dist/islands.js.map +1 -1
  59. package/dist/module-graph.d.ts.map +1 -1
  60. package/dist/module-graph.js +22 -9
  61. package/dist/module-graph.js.map +1 -1
  62. package/dist/nano.d.ts +125 -0
  63. package/dist/nano.d.ts.map +1 -0
  64. package/dist/nano.js +190 -0
  65. package/dist/nano.js.map +1 -0
  66. package/dist/plugins/css-modules.js +2 -2
  67. package/dist/plugins/css-modules.js.map +1 -1
  68. package/dist/plugins/kit.d.ts +12 -0
  69. package/dist/plugins/kit.d.ts.map +1 -1
  70. package/dist/plugins/kit.js +62 -12
  71. package/dist/plugins/kit.js.map +1 -1
  72. package/dist/plugins/postcss.js +2 -2
  73. package/dist/plugins/postcss.js.map +1 -1
  74. package/dist/plugins/scss.js +2 -2
  75. package/dist/plugins/scss.js.map +1 -1
  76. package/dist/plugins/stylex.d.ts +70 -0
  77. package/dist/plugins/stylex.d.ts.map +1 -0
  78. package/dist/plugins/stylex.js +166 -0
  79. package/dist/plugins/stylex.js.map +1 -0
  80. package/dist/plugins/svg.js +2 -2
  81. package/dist/plugins/svg.js.map +1 -1
  82. package/dist/router.d.ts +1 -1
  83. package/dist/router.js +23 -23
  84. package/dist/router.js.map +1 -1
  85. package/dist/vite.d.ts.map +1 -1
  86. package/dist/vite.js +26 -10
  87. package/dist/vite.js.map +1 -1
  88. package/package.json +39 -3
  89. package/src/build-plan.ts +741 -0
  90. package/src/build-vite.ts +1 -4
  91. package/src/build.ts +84 -716
  92. package/src/chunk-names.ts +3 -2
  93. package/src/dev-ssr-graph.ts +63 -28
  94. package/src/diagnostic.ts +14 -2
  95. package/src/fonts-google.ts +3 -1
  96. package/src/fs.ts +2 -1
  97. package/src/index.ts +73 -2705
  98. package/src/internal/codegen.ts +400 -0
  99. package/src/internal/head-merge.ts +19 -1
  100. package/src/internal/parity.ts +215 -35
  101. package/src/internal/render-document.ts +1116 -0
  102. package/src/internal/runtime-contract.ts +54 -0
  103. package/src/internal/web-app.ts +1114 -0
  104. package/src/islands.ts +85 -0
  105. package/src/module-graph.ts +23 -9
  106. package/src/nano.ts +246 -0
  107. package/src/plugins/css-modules.ts +2 -2
  108. package/src/plugins/kit.ts +65 -12
  109. package/src/plugins/postcss.ts +2 -2
  110. package/src/plugins/scss.ts +2 -2
  111. package/src/plugins/stylex.ts +298 -0
  112. package/src/plugins/svg.ts +2 -2
  113. package/src/router.ts +24 -24
  114. package/src/vite.ts +33 -9
@@ -0,0 +1,54 @@
1
+ /** Phantom brand key for {@link ServerOnly}. */
2
+ declare const SERVER_ONLY_BRAND: unique symbol
3
+
4
+ /**
5
+ * Type-level intent marker for a value that must only exist on the server - a secret, a DB handle, a
6
+ * server-only client. `ServerOnly<T>` is structurally `T` (the brand is an optional phantom field, so
7
+ * existing code keeps type-checking), but it advertises to readers + the compiler that the value is
8
+ * not meant to cross to the browser. It is **purely type-level** and erases at build - it does NOT,
9
+ * by itself, keep the value out of the client bundle.
10
+ *
11
+ * The enforcement is two runtime conventions:
12
+ * - add the side-effect import `import "@nifrajs/web/server-only"` at the top of the module - the
13
+ * client build ({@link buildClient}) fails loud, with the import chain, if it reaches a browser
14
+ * chunk (the poison-import marker);
15
+ * - or name the file `*.server.ts` - the `.server` convention empties it in the client build.
16
+ *
17
+ * Use this brand to express the intent in the types; pair it with one of those runtime markers so a
18
+ * leak is caught at build time rather than shipping a secret to the client.
19
+ *
20
+ * @example
21
+ * import "@nifrajs/web/server-only"
22
+ * import type { ServerOnly } from "@nifrajs/web"
23
+ * export const apiKey: ServerOnly<string> = process.env.SECRET_API_KEY!
24
+ */
25
+ export type ServerOnly<T> = T & { readonly [SERVER_ONLY_BRAND]?: never }
26
+
27
+ /**
28
+ * Pre-hydration form guard - a tiny inline script flushed in `<head>` (it runs in the window between
29
+ * first paint and the island bundle taking over). It neutralizes the one real hydration footgun: a
30
+ * JS-only form (a hand-wired `onSubmit` with no native fallback) submitting *natively* before its
31
+ * handler is attached, which navigates the browser to a broken `?field=…` GET of the current page.
32
+ *
33
+ * It blocks ONLY that shape - an effective-GET form whose action targets the current document - and
34
+ * only until hydration commits (`data-nifra-hydrated`, set by the client entry). Method-`post` forms
35
+ * (progressive enhancement: the native POST hits the route `action`) and GET forms with a real action
36
+ * (a search box → `/search`) pass through untouched. Opt out per-form with `data-native`. Static text
37
+ * (no interpolation), so it can't carry injected markup. See the Hydration guide.
38
+ */
39
+ export const PRE_HYDRATION_GUARD =
40
+ "(function(){addEventListener('submit',function(e){var f=e.target;" +
41
+ "if(!f||f.tagName!=='FORM'||f.hasAttribute('data-native'))return;" +
42
+ "if(document.documentElement.hasAttribute('data-nifra-hydrated'))return;" +
43
+ "var m=(f.getAttribute('method')||'get').toLowerCase();if(m==='post')return;" +
44
+ "var a=f.getAttribute('action');" +
45
+ "if(!a||a===''||a==='#'||a===location.pathname||a===location.href)e.preventDefault()" +
46
+ "},true)})()"
47
+
48
+ /**
49
+ * The single default port for the dev server (`@nifrajs/web/dev`, `@nifrajs/web/vite`) **and**
50
+ * `nifra start`. Deliberately uncommon: `3000`/`5173`/`8080` collide with whatever else is running
51
+ * (Next, Vite, a stray Node API). `4321` rarely is - and being the *same* constant across `nifra dev`
52
+ * and `nifra start` means a project's URL doesn't change between commands. Override per-run with
53
+ * `--port <n>` or the `PORT` env var. */
54
+ export const DEFAULT_DEV_PORT = 4321