resuxjs 0.2.43 → 0.3.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 (266) hide show
  1. package/README.md +993 -666
  2. package/dist/cli.js +1990 -355
  3. package/dist/cli.js.map +1 -1
  4. package/dist/compiler/adapter.d.ts +17 -0
  5. package/dist/compiler/adapter.js +106 -0
  6. package/dist/compiler/adapter.js.map +1 -0
  7. package/dist/compiler/dev-warnings.d.ts +11 -0
  8. package/dist/compiler/dev-warnings.js +360 -0
  9. package/dist/compiler/dev-warnings.js.map +1 -0
  10. package/dist/compiler/directives.d.ts +13 -0
  11. package/dist/compiler/directives.js +167 -0
  12. package/dist/compiler/directives.js.map +1 -0
  13. package/dist/compiler/implementation.d.ts +129 -0
  14. package/dist/compiler/implementation.js +3745 -0
  15. package/dist/compiler/implementation.js.map +1 -0
  16. package/dist/compiler/index.d.ts +9 -103
  17. package/dist/compiler/index.js +74 -1971
  18. package/dist/compiler/index.js.map +1 -1
  19. package/dist/core/config.d.ts +8 -0
  20. package/dist/core/config.js +21 -0
  21. package/dist/core/config.js.map +1 -0
  22. package/dist/core/hooks.d.ts +133 -0
  23. package/dist/core/hooks.js +54 -0
  24. package/dist/core/hooks.js.map +1 -0
  25. package/dist/core/index.d.ts +4 -0
  26. package/dist/core/index.js +5 -0
  27. package/dist/core/index.js.map +1 -0
  28. package/dist/core/module-container.d.ts +100 -0
  29. package/dist/core/module-container.js +171 -0
  30. package/dist/core/module-container.js.map +1 -0
  31. package/dist/core/resux.d.ts +18 -0
  32. package/dist/core/resux.js +18 -0
  33. package/dist/core/resux.js.map +1 -0
  34. package/dist/create.d.ts +1 -0
  35. package/dist/create.js +878 -22
  36. package/dist/create.js.map +1 -1
  37. package/dist/deploy/cloudflare.js +17 -3
  38. package/dist/deploy/cloudflare.js.map +1 -1
  39. package/dist/deploy/common.js +4 -3
  40. package/dist/deploy/common.js.map +1 -1
  41. package/dist/fonts/index.d.ts +16 -0
  42. package/dist/fonts/index.js +154 -0
  43. package/dist/fonts/index.js.map +1 -0
  44. package/dist/globals.d.ts +27 -2
  45. package/dist/halal-core/ai/classifyProject.d.ts +4 -0
  46. package/dist/halal-core/ai/classifyProject.js +104 -0
  47. package/dist/halal-core/ai/classifyProject.js.map +1 -0
  48. package/dist/halal-core/ai/createProjectSummary.d.ts +39 -0
  49. package/dist/halal-core/ai/createProjectSummary.js +42 -0
  50. package/dist/halal-core/ai/createProjectSummary.js.map +1 -0
  51. package/dist/halal-core/ai/halalClassifierPrompt.d.ts +1 -0
  52. package/dist/halal-core/ai/halalClassifierPrompt.js +20 -0
  53. package/dist/halal-core/ai/halalClassifierPrompt.js.map +1 -0
  54. package/dist/halal-core/ai/redactSensitiveData.d.ts +1 -0
  55. package/dist/halal-core/ai/redactSensitiveData.js +139 -0
  56. package/dist/halal-core/ai/redactSensitiveData.js.map +1 -0
  57. package/dist/halal-core/ai/validateAiResponse.d.ts +2 -0
  58. package/dist/halal-core/ai/validateAiResponse.js +97 -0
  59. package/dist/halal-core/ai/validateAiResponse.js.map +1 -0
  60. package/dist/halal-core/cli/check.d.ts +1 -0
  61. package/dist/halal-core/cli/check.js +36 -0
  62. package/dist/halal-core/cli/check.js.map +1 -0
  63. package/dist/halal-core/cli/explain.d.ts +1 -0
  64. package/dist/halal-core/cli/explain.js +35 -0
  65. package/dist/halal-core/cli/explain.js.map +1 -0
  66. package/dist/halal-core/cli/report.d.ts +1 -0
  67. package/dist/halal-core/cli/report.js +15 -0
  68. package/dist/halal-core/cli/report.js.map +1 -0
  69. package/dist/halal-core/cli/submitReview.d.ts +1 -0
  70. package/dist/halal-core/cli/submitReview.js +12 -0
  71. package/dist/halal-core/cli/submitReview.js.map +1 -0
  72. package/dist/halal-core/cli/verifyReview.d.ts +1 -0
  73. package/dist/halal-core/cli/verifyReview.js +19 -0
  74. package/dist/halal-core/cli/verifyReview.js.map +1 -0
  75. package/dist/halal-core/config.d.ts +40 -0
  76. package/dist/halal-core/config.js +128 -0
  77. package/dist/halal-core/config.js.map +1 -0
  78. package/dist/halal-core/crypto/integrity.d.ts +9 -0
  79. package/dist/halal-core/crypto/integrity.js +101 -0
  80. package/dist/halal-core/crypto/integrity.js.map +1 -0
  81. package/dist/halal-core/enforce.d.ts +5 -0
  82. package/dist/halal-core/enforce.js +119 -0
  83. package/dist/halal-core/enforce.js.map +1 -0
  84. package/dist/halal-core/index.d.ts +14 -0
  85. package/dist/halal-core/index.js +17 -0
  86. package/dist/halal-core/index.js.map +1 -0
  87. package/dist/halal-core/lifecycle.d.ts +1 -0
  88. package/dist/halal-core/lifecycle.js +15 -0
  89. package/dist/halal-core/lifecycle.js.map +1 -0
  90. package/dist/halal-core/policy.d.ts +2 -0
  91. package/dist/halal-core/policy.js +5 -0
  92. package/dist/halal-core/policy.js.map +1 -0
  93. package/dist/halal-core/report/formatBrowserOverlay.d.ts +2 -0
  94. package/dist/halal-core/report/formatBrowserOverlay.js +41 -0
  95. package/dist/halal-core/report/formatBrowserOverlay.js.map +1 -0
  96. package/dist/halal-core/report/formatTerminalReport.d.ts +2 -0
  97. package/dist/halal-core/report/formatTerminalReport.js +39 -0
  98. package/dist/halal-core/report/formatTerminalReport.js.map +1 -0
  99. package/dist/halal-core/report/generateHalalReport.d.ts +7 -0
  100. package/dist/halal-core/report/generateHalalReport.js +46 -0
  101. package/dist/halal-core/report/generateHalalReport.js.map +1 -0
  102. package/dist/halal-core/report/signReport.d.ts +3 -0
  103. package/dist/halal-core/report/signReport.js +17 -0
  104. package/dist/halal-core/report/signReport.js.map +1 -0
  105. package/dist/halal-core/report/verifyReport.d.ts +11 -0
  106. package/dist/halal-core/report/verifyReport.js +45 -0
  107. package/dist/halal-core/report/verifyReport.js.map +1 -0
  108. package/dist/halal-core/review/createReviewRequest.d.ts +2 -0
  109. package/dist/halal-core/review/createReviewRequest.js +21 -0
  110. package/dist/halal-core/review/createReviewRequest.js.map +1 -0
  111. package/dist/halal-core/review/reviewPolicy.d.ts +3 -0
  112. package/dist/halal-core/review/reviewPolicy.js +21 -0
  113. package/dist/halal-core/review/reviewPolicy.js.map +1 -0
  114. package/dist/halal-core/review/signedReviewFile.d.ts +13 -0
  115. package/dist/halal-core/review/signedReviewFile.js +28 -0
  116. package/dist/halal-core/review/signedReviewFile.js.map +1 -0
  117. package/dist/halal-core/review/verifyReviewApproval.d.ts +10 -0
  118. package/dist/halal-core/review/verifyReviewApproval.js +68 -0
  119. package/dist/halal-core/review/verifyReviewApproval.js.map +1 -0
  120. package/dist/halal-core/rules/adultContentRules.d.ts +2 -0
  121. package/dist/halal-core/rules/adultContentRules.js +26 -0
  122. package/dist/halal-core/rules/adultContentRules.js.map +1 -0
  123. package/dist/halal-core/rules/alcoholDrugVapeRules.d.ts +2 -0
  124. package/dist/halal-core/rules/alcoholDrugVapeRules.js +25 -0
  125. package/dist/halal-core/rules/alcoholDrugVapeRules.js.map +1 -0
  126. package/dist/halal-core/rules/childSafetyRules.d.ts +2 -0
  127. package/dist/halal-core/rules/childSafetyRules.js +22 -0
  128. package/dist/halal-core/rules/childSafetyRules.js.map +1 -0
  129. package/dist/halal-core/rules/coreCategories.d.ts +7 -0
  130. package/dist/halal-core/rules/coreCategories.js +112 -0
  131. package/dist/halal-core/rules/coreCategories.js.map +1 -0
  132. package/dist/halal-core/rules/cyberAbuseRules.d.ts +2 -0
  133. package/dist/halal-core/rules/cyberAbuseRules.js +30 -0
  134. package/dist/halal-core/rules/cyberAbuseRules.js.map +1 -0
  135. package/dist/halal-core/rules/defaultBlockedRules.d.ts +20 -0
  136. package/dist/halal-core/rules/defaultBlockedRules.js +216 -0
  137. package/dist/halal-core/rules/defaultBlockedRules.js.map +1 -0
  138. package/dist/halal-core/rules/dependencyRules.d.ts +9 -0
  139. package/dist/halal-core/rules/dependencyRules.js +59 -0
  140. package/dist/halal-core/rules/dependencyRules.js.map +1 -0
  141. package/dist/halal-core/rules/endpointRules.d.ts +6 -0
  142. package/dist/halal-core/rules/endpointRules.js +26 -0
  143. package/dist/halal-core/rules/endpointRules.js.map +1 -0
  144. package/dist/halal-core/rules/environmentalHarmRules.d.ts +2 -0
  145. package/dist/halal-core/rules/environmentalHarmRules.js +20 -0
  146. package/dist/halal-core/rules/environmentalHarmRules.js.map +1 -0
  147. package/dist/halal-core/rules/financeRibaRules.d.ts +2 -0
  148. package/dist/halal-core/rules/financeRibaRules.js +23 -0
  149. package/dist/halal-core/rules/financeRibaRules.js.map +1 -0
  150. package/dist/halal-core/rules/gamblingRules.d.ts +2 -0
  151. package/dist/halal-core/rules/gamblingRules.js +25 -0
  152. package/dist/halal-core/rules/gamblingRules.js.map +1 -0
  153. package/dist/halal-core/rules/generalHarmRules.d.ts +2 -0
  154. package/dist/halal-core/rules/generalHarmRules.js +18 -0
  155. package/dist/halal-core/rules/generalHarmRules.js.map +1 -0
  156. package/dist/halal-core/rules/healthHarmRules.d.ts +2 -0
  157. package/dist/halal-core/rules/healthHarmRules.js +22 -0
  158. package/dist/halal-core/rules/healthHarmRules.js.map +1 -0
  159. package/dist/halal-core/rules/keywordRules.d.ts +10 -0
  160. package/dist/halal-core/rules/keywordRules.js +41 -0
  161. package/dist/halal-core/rules/keywordRules.js.map +1 -0
  162. package/dist/halal-core/rules/privacyAbuseRules.d.ts +2 -0
  163. package/dist/halal-core/rules/privacyAbuseRules.js +24 -0
  164. package/dist/halal-core/rules/privacyAbuseRules.js.map +1 -0
  165. package/dist/halal-core/rules/scamFraudRules.d.ts +2 -0
  166. package/dist/halal-core/rules/scamFraudRules.js +32 -0
  167. package/dist/halal-core/rules/scamFraudRules.js.map +1 -0
  168. package/dist/halal-core/rules/selfHarmRules.d.ts +2 -0
  169. package/dist/halal-core/rules/selfHarmRules.js +20 -0
  170. package/dist/halal-core/rules/selfHarmRules.js.map +1 -0
  171. package/dist/halal-core/rules/violenceExtremismRules.d.ts +2 -0
  172. package/dist/halal-core/rules/violenceExtremismRules.js +33 -0
  173. package/dist/halal-core/rules/violenceExtremismRules.js.map +1 -0
  174. package/dist/halal-core/scanner/scanApiRoutes.d.ts +1 -0
  175. package/dist/halal-core/scanner/scanApiRoutes.js +40 -0
  176. package/dist/halal-core/scanner/scanApiRoutes.js.map +1 -0
  177. package/dist/halal-core/scanner/scanComponents.d.ts +1 -0
  178. package/dist/halal-core/scanner/scanComponents.js +17 -0
  179. package/dist/halal-core/scanner/scanComponents.js.map +1 -0
  180. package/dist/halal-core/scanner/scanContent.d.ts +5 -0
  181. package/dist/halal-core/scanner/scanContent.js +302 -0
  182. package/dist/halal-core/scanner/scanContent.js.map +1 -0
  183. package/dist/halal-core/scanner/scanDependencies.d.ts +1 -0
  184. package/dist/halal-core/scanner/scanDependencies.js +19 -0
  185. package/dist/halal-core/scanner/scanDependencies.js.map +1 -0
  186. package/dist/halal-core/scanner/scanDomains.d.ts +4 -0
  187. package/dist/halal-core/scanner/scanDomains.js +14 -0
  188. package/dist/halal-core/scanner/scanDomains.js.map +1 -0
  189. package/dist/halal-core/scanner/scanEnvNames.d.ts +1 -0
  190. package/dist/halal-core/scanner/scanEnvNames.js +30 -0
  191. package/dist/halal-core/scanner/scanEnvNames.js.map +1 -0
  192. package/dist/halal-core/scanner/scanMetadata.d.ts +6 -0
  193. package/dist/halal-core/scanner/scanMetadata.js +33 -0
  194. package/dist/halal-core/scanner/scanMetadata.js.map +1 -0
  195. package/dist/halal-core/scanner/scanPages.d.ts +1 -0
  196. package/dist/halal-core/scanner/scanPages.js +19 -0
  197. package/dist/halal-core/scanner/scanPages.js.map +1 -0
  198. package/dist/halal-core/scanner/scanProject.d.ts +13 -0
  199. package/dist/halal-core/scanner/scanProject.js +62 -0
  200. package/dist/halal-core/scanner/scanProject.js.map +1 -0
  201. package/dist/halal-core/scanner/scanRoutes.d.ts +1 -0
  202. package/dist/halal-core/scanner/scanRoutes.js +43 -0
  203. package/dist/halal-core/scanner/scanRoutes.js.map +1 -0
  204. package/dist/halal-core/scanner/scanTranslations.d.ts +1 -0
  205. package/dist/halal-core/scanner/scanTranslations.js +32 -0
  206. package/dist/halal-core/scanner/scanTranslations.js.map +1 -0
  207. package/dist/halal-core/status.d.ts +14 -0
  208. package/dist/halal-core/status.js +2 -0
  209. package/dist/halal-core/status.js.map +1 -0
  210. package/dist/halal-core/tamper/verifyCoreIntegrity.d.ts +1 -0
  211. package/dist/halal-core/tamper/verifyCoreIntegrity.js +28 -0
  212. package/dist/halal-core/tamper/verifyCoreIntegrity.js.map +1 -0
  213. package/dist/halal-core/tamper/verifyLifecycleHooks.d.ts +1 -0
  214. package/dist/halal-core/tamper/verifyLifecycleHooks.js +14 -0
  215. package/dist/halal-core/tamper/verifyLifecycleHooks.js.map +1 -0
  216. package/dist/halal-core/tamper/verifyReportSignature.d.ts +5 -0
  217. package/dist/halal-core/tamper/verifyReportSignature.js +18 -0
  218. package/dist/halal-core/tamper/verifyReportSignature.js.map +1 -0
  219. package/dist/i18n/index.d.ts +45 -0
  220. package/dist/i18n/index.js +284 -0
  221. package/dist/i18n/index.js.map +1 -0
  222. package/dist/i18n/shared.d.ts +35 -0
  223. package/dist/i18n/shared.js +270 -0
  224. package/dist/i18n/shared.js.map +1 -0
  225. package/dist/icons/index.d.ts +159 -0
  226. package/dist/icons/index.js +286 -0
  227. package/dist/icons/index.js.map +1 -0
  228. package/dist/kit/index.d.ts +29 -0
  229. package/dist/kit/index.js +72 -0
  230. package/dist/kit/index.js.map +1 -0
  231. package/dist/nitro-server/index.d.ts +7 -0
  232. package/dist/nitro-server/index.js +4 -0
  233. package/dist/nitro-server/index.js.map +1 -0
  234. package/dist/reactivity/computed.js +9 -4
  235. package/dist/reactivity/computed.js.map +1 -1
  236. package/dist/reactivity/effect.d.ts +3 -1
  237. package/dist/reactivity/effect.js +56 -6
  238. package/dist/reactivity/effect.js.map +1 -1
  239. package/dist/reactivity/reactive.js +64 -15
  240. package/dist/reactivity/reactive.js.map +1 -1
  241. package/dist/reactivity/ref.d.ts +1 -0
  242. package/dist/reactivity/ref.js +13 -6
  243. package/dist/reactivity/ref.js.map +1 -1
  244. package/dist/reactivity/scheduler.js +36 -4
  245. package/dist/reactivity/scheduler.js.map +1 -1
  246. package/dist/reactivity/watch.js +27 -5
  247. package/dist/reactivity/watch.js.map +1 -1
  248. package/dist/runtime/index.d.ts +226 -3
  249. package/dist/runtime/index.js +13344 -6395
  250. package/dist/runtime/index.js.map +1 -1
  251. package/dist/ui/index.d.ts +1828 -0
  252. package/dist/ui/index.js +938 -0
  253. package/dist/ui/index.js.map +1 -0
  254. package/dist/vite-builder/index.d.ts +6 -0
  255. package/dist/vite-builder/index.js +4 -0
  256. package/dist/vite-builder/index.js.map +1 -0
  257. package/package.json +150 -105
  258. package/templates/default/.env.example +1 -0
  259. package/templates/default/README.md +18 -14
  260. package/templates/default/_gitignore +8 -5
  261. package/templates/default/assets/css/main.css +4 -0
  262. package/templates/default/nitro.config.ts +9 -5
  263. package/templates/default/pages/index.vue +102 -87
  264. package/templates/default/public/favicon.svg +4 -0
  265. package/templates/default/types/app.d.ts +3 -0
  266. package/templates/default/.resux-nitro/handler.ts +0 -21
package/README.md CHANGED
@@ -1,666 +1,993 @@
1
- # Resux
2
-
3
- Resux is an experimental web framework with a custom resumable runtime.
4
-
5
- It uses familiar `.vue` files and `pages/` routing, but normal Resux components do not use Vue hydration or the Vue runtime. The compiler parses a small Vue-like SFC subset, renders HTML on the server, serializes route and component state, then loads client code only when an event is triggered. Vue runtime is available as an opt-in island escape hatch for complex client widgets.
6
-
7
- The v1 release line treats the documented compiler, SSR renderer, resume runtime, routing, and CLI commands as the stable core. Advanced Vue compatibility, Vue islands, Nitro adapter behavior, and unsupported Vue SFC syntax are still experimental and should fail loudly instead of silently falling back to hydration.
8
-
9
- ## Create App
10
-
11
- Create a new app with the latest published Resux package:
12
-
13
- ```sh
14
- npx resuxjs@latest init
15
- ```
16
-
17
- With a project directory:
18
-
19
- ```sh
20
- npx resuxjs@latest init my-app
21
- ```
22
-
23
- With create options:
24
-
25
- ```sh
26
- npx resuxjs@latest init my-app --no-install
27
- ```
28
-
29
- Generated apps use a single Resux dependency, similar to Nuxt apps installing `nuxt`:
30
-
31
- ```json
32
- {
33
- "dependencies": {
34
- "resuxjs": "^<current-version>"
35
- }
36
- }
37
- ```
38
-
39
- For local development before publishing:
40
-
41
- ```sh
42
- npm install
43
- npm run typecheck
44
- npm run build
45
- npm run create:local -- my-app --no-install
46
- ```
47
-
48
- Then run the generated app:
49
-
50
- ```sh
51
- cd my-app
52
- npm install
53
- npm run dev
54
- ```
55
-
56
- ## Package Layout
57
-
58
- ```txt
59
- src/
60
- compiler/ SFC parser, route manifest builder, code generator
61
- runtime/ SSR renderer, composables, client resume loader source
62
- index.ts Runtime-only public root export
63
- cli.ts Resux CLI, dev server, preview server, deploy helpers
64
- node.ts Node server handler export for adapters
65
- create.ts App scaffolder used by `resux init`
66
-
67
- templates/ Starter files copied by `resux init`
68
- tests/ Compiler, SSR, and client resume tests
69
- ```
70
-
71
- Public imports are split so browser/client bundles do not accidentally pull compiler or server code:
72
-
73
- ```ts
74
- import { renderApp } from "resuxjs/runtime"
75
- import { createResuxNodeHandler } from "resuxjs/node"
76
- ```
77
-
78
- ## Development
79
-
80
- ```sh
81
- npm install
82
- npm run typecheck
83
- npm run build
84
- npm test
85
- ```
86
-
87
- Run the full publish-readiness check:
88
-
89
- ```sh
90
- npm run pack:check
91
- ```
92
-
93
- This builds, tests, and dry-runs npm packing for the single `resuxjs` package.
94
-
95
- CI runs on every push and pull request with `npm ci`, optional linting, typecheck, build, tests, and package dry-run checks.
96
-
97
- ## Release Process
98
-
99
- Normal pushes never publish to npm. They only run CI. Publishing is intentionally gated to version tags or GitHub Releases so an ordinary `main` push cannot publish a broken package.
100
-
101
- To release:
102
-
103
- 1. Update the version and create the release commit/tag with `npm version 1.0.0`.
104
- 2. Push the release commit with `git push origin main`.
105
- 3. Push the version tag with `git push origin v1.0.0`.
106
- 4. The GitHub Action publishes `resuxjs@1.0.0` to npm.
107
-
108
- The npm publish workflow validates that the tag matches `package.json`, runs `npm ci` and `npm run pack:check`, skips publishing if the package version already exists, then publishes with `NPM_TOKEN` and npm provenance.
109
-
110
- ## CLI
111
-
112
- The `resux` CLI supports:
113
-
114
- ```sh
115
- resux init <project-dir>
116
- resux dev <app-root>
117
- resux build <app-root>
118
- resux preview <app-root>
119
- resux start <app-root>
120
- resux inspect <app-root>
121
- resux deploy <app-root>
122
- ```
123
-
124
- If `<app-root>` is omitted, Resux uses the current directory.
125
-
126
- Useful server flags:
127
-
128
- ```sh
129
- resux dev --port 4000
130
- resux preview --host 0.0.0.0 --port 4000
131
- resux start --host 0.0.0.0 --port 3000
132
- resux inspect
133
- resux inspect --json
134
- resux deploy . --preset docker
135
- resux deploy . --preset nitro
136
- resux --help
137
- resux --version
138
- ```
139
-
140
- Build output is written to:
141
-
142
- ```txt
143
- <app-root>/.resux
144
- ```
145
-
146
- ## App Types
147
-
148
- Generated apps include `env.d.ts` and `tsconfig.json` wired to `resuxjs/globals`, so app files can use the Resux-style globals without imports:
149
-
150
- ```ts
151
- const count = useState("count", () => 0)
152
- const route = useRoute()
153
- const router = useRouter()
154
- useSeoMeta({
155
- title: "My App",
156
- description: "My app description",
157
- ogTitle: "My App"
158
- })
159
-
160
- function openAbout() {
161
- router.push("/about")
162
- }
163
-
164
- export default defineResuxConfig({
165
- app: {
166
- head: {
167
- title: "My App"
168
- }
169
- }
170
- })
171
- ```
172
-
173
- ## Reactivity APIs
174
-
175
- Resux includes a native reactivity layer for resumable components. You can use it with globals in app files, or import directly:
176
-
177
- ```ts
178
- import {
179
- ref,
180
- reactive,
181
- computed,
182
- watch,
183
- watchEffect,
184
- readonly,
185
- toRef,
186
- toRefs,
187
- unref,
188
- isRef,
189
- isReactive,
190
- isReadonly,
191
- nextTick
192
- } from "resuxjs"
193
- ```
194
-
195
- Or from the focused subpath:
196
-
197
- ```ts
198
- import { ref, reactive, computed } from "resuxjs/reactivity"
199
- ```
200
-
201
- These APIs are Resux-native. Normal Resux components do not depend on Vue hydration runtime.
202
-
203
- ## Vite
204
-
205
- Resux uses Vite in both main app commands:
206
-
207
- - `resux dev` emits Resux client modules into `.resux/vite-client` and serves the resume runtime plus handler modules through Vite middleware.
208
- - `resux dev` also opens a dev-only update channel at `/__resux/dev-events`; when source files change, Resux rebuilds and reloads the browser so route, template, and style changes are visible without restarting the dev server.
209
- - `resux build` uses Vite production bundling for the resume runtime, handler chunks, and server manifest, then writes optimized output into `.resux/client` and `.resux/server-bundle` before producing a Nitro `.output` server.
210
-
211
- The generated starter keeps Resux-style scripts:
212
-
213
- ```json
214
- {
215
- "scripts": {
216
- "dev": "resux dev .",
217
- "build": "resux build .",
218
- "preview": "resux preview .",
219
- "start": "node .output/server/index.mjs",
220
- "inspect": "resux inspect ."
221
- }
222
- }
223
- ```
224
-
225
- Tailwind can stay Nuxt-style simple too. If your app has `assets/css/tailwind.css` and `tailwindcss` installed, `resux dev` automatically runs Tailwind in watch mode and `resux build` generates a minified `public/tailwind.css` before bundling. No separate `concurrently` script is required.
226
-
227
- ## Deployment
228
-
229
- Build and serve with the Node server:
230
-
231
- ```sh
232
- npm run build
233
- npm run start
234
- ```
235
-
236
- Production serving enables default hardening headers such as `x-content-type-options`, `referrer-policy`, `x-frame-options`, `cross-origin-opener-policy`, and a restrictive `permissions-policy`. Disable them only when the host or reverse proxy owns those headers:
237
-
238
- ```sh
239
- resux start . --no-security-headers
240
- ```
241
-
242
- Generated apps include a `Dockerfile`, `.dockerignore`, and `DEPLOYMENT.md`. Use `resux inspect --json` in CI to capture the built routes, server handlers, route rules, feature flags, and diagnostics.
243
-
244
- Existing apps can generate or refresh deployment files without changing application code:
245
-
246
- ```sh
247
- resux deploy . --preset node
248
- resux deploy . --preset docker --force
249
- resux deploy . --preset nitro --force
250
- ```
251
-
252
- The Nitro preset writes `nitro.config.ts` and a small `.resux-nitro/handler.ts` adapter. `resux build` now produces Nuxt-style `.output` by default:
253
-
254
- ```sh
255
- npm run build
256
- node .output/server/index.mjs
257
- ```
258
-
259
- The generated Nitro config is conservative for resumability: SSR pages, API routes, and route payloads use `cache-control: no-store`, while build-stable Resux runtime and handler assets use long immutable caching. Nitro prerender crawling is disabled by default.
260
-
261
- Deployment target selection is automatic by default (`deploy.target = "auto"`). Resux resolves target/preset from:
262
-
263
- - explicit `deploy.target` / `deploy.nitroPreset` in `resux.config.ts`
264
- - `NITRO_PRESET` / `RESUX_NITRO_PRESET`
265
- - provider environment variables
266
- - project build config detection (`vercel.json`, `netlify.toml`, `wrangler.*`)
267
- - package scripts heuristics
268
-
269
- You can pin target behavior explicitly:
270
-
271
- ```ts
272
- export default defineResuxConfig({
273
- deploy: {
274
- target: "vercel", // "auto" | "node" | "netlify" | "cloudflare" | "static"
275
- nitroPreset: "vercel"
276
- }
277
- })
278
- ```
279
-
280
- Cloudflare worker presets are opt-in via `deploy.target = "cloudflare"` (or explicit `deploy.nitroPreset`) so Node-style Nitro adapters do not get selected automatically in auto mode.
281
-
282
- Production and dev servers expose a health endpoint for hosts and uptime checks:
283
-
284
- ```txt
285
- /__resux/health
286
- ```
287
-
288
- ## Modules And Route Rules
289
-
290
- Resux supports first-party and third-party build-time modules in `resux.config.ts`. Modules run during the Resux build and can extend config without adding hydration:
291
-
292
- ```ts
293
- export default defineResuxConfig({
294
- modules: [
295
- "resux:security",
296
- ["resux:performance", { assetMaxAge: 31536000 }],
297
- ["./modules/security.ts", { header: "enabled" }]
298
- ],
299
- routeRules: {
300
- "/old": { redirect: { to: "/", statusCode: 301 } },
301
- "/admin/**": { headers: { "x-robots-tag": "noindex" } }
302
- }
303
- })
304
- ```
305
-
306
- Built-in modules:
307
-
308
- - `resux:security`: adds default production hardening headers and optional custom headers or CSP through route rules.
309
- - `resux:performance`: adds immutable cache rules for built Resux runtime/handler assets and `no-store` for route payloads.
310
-
311
- Modules can be built-in `resux:*` specifiers, npm package specifiers, local files, inline functions, or objects returned by `defineResuxModule`.
312
-
313
- ```ts
314
- // modules/security.ts
315
- export default defineResuxModule({
316
- defaults: { header: "enabled" },
317
- setup(options, resux) {
318
- resux.addCss("/module.css")
319
- resux.addHead({ meta: [{ name: "module", content: options.header }] })
320
- resux.addRouteRule("/secure/**", {
321
- headers: { "x-module": options.header },
322
- cache: { maxAge: 60, swr: 30 }
323
- })
324
- resux.extendRuntimeConfig({
325
- public: { securityModule: options.header }
326
- })
327
- }
328
- })
329
- ```
330
-
331
- The module API includes `addCss`, `addHead`, `addRouteRule`, and `extendRuntimeConfig`. Route rules currently support redirects, response headers, status codes, cache headers, and CORS headers.
332
-
333
- ## Plugins
334
-
335
- Resux auto-discovers app plugins from `plugins/` (and `app/plugins/`) without manual imports:
336
-
337
- - `plugins/*.ts`
338
- - `plugins/**/*.ts`
339
- - `plugins/*.client.ts`
340
- - `plugins/*.server.ts`
341
-
342
- Use `defineResuxPlugin`:
343
-
344
- ```ts
345
- // plugins/01.api.ts
346
- export default defineResuxPlugin((resuxApp) => {
347
- resuxApp.provide("apiBase", "/api")
348
- })
349
- ```
350
-
351
- Plugin execution order is deterministic and sorted by discovered filename path. Numeric prefixes are supported, for example `01.auth.ts` runs before `02.analytics.ts`.
352
-
353
- Mode behavior:
354
-
355
- - `.client` plugins run only in the browser.
356
- - `.server` plugins run only on the server.
357
- - Unsuffixed plugins run on both server and client.
358
-
359
- Use `useResuxApp()` inside setup code to access provided values:
360
-
361
- ```ts
362
- const app = useResuxApp()
363
- const apiBase = String(app.provides.apiBase ?? "/api")
364
- ```
365
-
366
- TypeScript app helpers are available globally when your app includes:
367
-
368
- ```ts
369
- /// <reference types="resuxjs/globals" />
370
- ```
371
-
372
- For typed plugin injections, augment `ResuxAppInjections`:
373
-
374
- ```ts
375
- declare module "resuxjs/runtime" {
376
- interface ResuxAppInjections {
377
- apiBase: string
378
- }
379
- }
380
- ```
381
-
382
- ## Route Middleware
383
-
384
- Resux auto-discovers route middleware from `middleware/` (and `app/middleware/`) without manual imports:
385
-
386
- - `middleware/*.ts`
387
- - `middleware/**/*.ts`
388
- - `middleware/*.global.ts`
389
- - `middleware/*.client.ts`
390
- - `middleware/*.server.ts`
391
-
392
- Create middleware with `defineResuxRouteMiddleware`:
393
-
394
- ```ts
395
- // middleware/auth.ts
396
- export default defineResuxRouteMiddleware((to) => {
397
- if (to.path.startsWith("/admin")) {
398
- return navigateTo("/login")
399
- }
400
- })
401
- ```
402
-
403
- Apply named middleware from page meta:
404
-
405
- ```ts
406
- definePageMeta({ middleware: "auth" })
407
- definePageMeta({ middleware: ["auth", "admin"] })
408
- ```
409
-
410
- Global middleware (`*.global.ts`) runs for every route. Middleware return handling:
411
-
412
- - `undefined` or no return: continue
413
- - `false`: abort with `403`
414
- - `"/path"`: redirect
415
- - `{ redirect: "/path" }` or `{ redirect: { to: "/path", statusCode: 302 } }`: redirect
416
- - `navigateTo("/path")`: redirect helper
417
- - `abortNavigation("message")`: abort helper
418
-
419
- Mode behavior:
420
-
421
- - `.client` middleware runs in browser navigation.
422
- - `.server` middleware runs only during server rendering/navigation handling.
423
- - Unsuffixed middleware runs on server route resolution.
424
-
425
- ## Server Middleware
426
-
427
- Files in `server/middleware` run for each request before server handlers, public files, and page rendering:
428
-
429
- ```ts
430
- export default defineServerMiddleware((event) => {
431
- setHeader(event, "x-app", "resux")
432
-
433
- if (event.path.startsWith("/private")) {
434
- return { type: "redirect", to: "/login", statusCode: 302 }
435
- }
436
- })
437
- ```
438
-
439
- Server middleware can continue by returning nothing, use h3-style helpers such as `setHeader(event, name, value)`, end the Node response directly when necessary, return a `Response`, return a JSON-serializable value, return `false` to send `403`, or return a redirect/abort object.
440
-
441
- `server/middleware` is request middleware for raw HTTP handling and API/page requests. Route middleware in `middleware/` is navigation middleware for page routing decisions (`definePageMeta({ middleware })` + globals).
442
-
443
- ## What Works
444
-
445
- - `.vue`-style SFC files with `<template>`, `<script setup lang="ts">`, and plain CSS `<style>` blocks.
446
- - File-based routing from `pages/`.
447
- - Dynamic route params like `pages/post/[id].vue`.
448
- - Catch-all route params like `pages/docs/[...slug].vue`.
449
- - `app.vue` with `<ResuxPage />`.
450
- - Layouts with `<ResuxLayout>`, `<slot />`, and `definePageMeta({ layout })`.
451
- - `<ResuxLink to="...">` rendered as an `<a href="...">` and intercepted for client-side navigation.
452
- - Static and dynamic component props with `defineProps()`.
453
- - Server-side rendering.
454
- - Head/meta rendering from `resux.config.ts`, `definePageMeta`, `useHead`, and `useSeoMeta`.
455
- - Component CSS from `<style>` and `<style scoped>`, included in SSR output and updated during client-side navigation.
456
- - Auto-discovered route middleware from `middleware/**/*`, including `.global`, `.client`, and `.server` files.
457
- - Request-time server middleware from `server/middleware`.
458
- - Auto-discovered plugins from `plugins/**/*` with `.client` / `.server` mode suffix support and stable filename ordering.
459
- - Server API/routes from `server/api` and `server/routes`.
460
- - Server handler helpers: `readBody(event)`, `getQuery(event)`, and `setHeader(event, name, value)`, backed by h3.
461
- - `error.vue` for custom 404/500 rendering.
462
- - Public file serving from `public/`.
463
- - Built-in health checks at `/__resux/health`.
464
- - Basic `resux.config.ts` support for `runtimeConfig`, `app.head`, and `css`.
465
- - Built-in and package/local Resux modules for extending CSS, head, route rules, and runtime config during build.
466
- - Route rules for redirects, response headers, status codes, cache headers, and CORS headers.
467
- - Default production security headers with an opt-out flag.
468
- - Vite-powered dev serving, production client/server bundling, and minification for the resume runtime and handler chunks.
469
- - Dev rebuilds with automatic browser reloads, without adding Vue hydration.
470
- - `resux inspect` and `resux inspect --json` for route and build diagnostics.
471
- - `resux deploy --preset node|docker|nitro` for deployment file generation.
472
- - Serialized route, state, and async data payloads.
473
- - Resumable event handlers such as `@click="increment"`.
474
- - Lazy client handler chunks loaded on first interaction.
475
- - Client-side navigation, persistent same-layout DOM, built-in route transition progress, and hover/focus route payload prefetch for same-origin links.
476
- - Stable core composables: `useState`, `useAsyncData`, `useRoute`, `useRouter`, `useHead`, `useSeoMeta`, `useRuntimeConfig`, `useResuxApp`, `apiURL`, `useFetch`, `$fetch`, and `onMounted`.
477
- - `useAsyncData` returns a Nuxt-like resource with reactive `data`, `pending`, and `error` refs, plus `value` as a data alias for compatibility. Use `await useAsyncData(...)` when you want SSR to fetch before rendering the page; omit `await` when you intentionally want an SSR skeleton that resumes in the browser.
478
-
479
- ## Component Syntax
480
-
481
- ```vue
482
- <script setup lang="ts">
483
- const count = useState("count", () => 0)
484
-
485
- function increment() {
486
- count.value++
487
- }
488
- </script>
489
-
490
- <template>
491
- <button @click="increment">
492
- Count: {{ count }}
493
- </button>
494
- </template>
495
- ```
496
-
497
- On the server, Resux renders the button as HTML and serializes `count`.
498
-
499
- In the browser, Resux installs a tiny delegated event listener. The component handler module is not imported until the user clicks the button. After that, the scope is resumed from serialized state and only the marked DOM bindings are patched.
500
-
501
- ## Async Data Skeletons
502
-
503
- To fetch during SSR and render the resolved data in the first HTML response, await the call:
504
-
505
- ```vue
506
- <script setup lang="ts">
507
- type Stats = {
508
- response: string
509
- }
510
-
511
- const { data, pending, error } = await useAsyncData("stats", ({ signal }) => {
512
- return $fetch<Stats>("/api/stats", { signal })
513
- })
514
- </script>
515
-
516
- <template>
517
- <p v-if="pending">Loading</p>
518
- <p v-if="error">{{ error.message }}</p>
519
- <strong v-if="data">{{ data.response }}</strong>
520
- </template>
521
- ```
522
-
523
- For a Next-style loading skeleton, call `useAsyncData` without `await` and branch on `pending`:
524
-
525
- ```vue
526
- <script setup lang="ts">
527
- type Stats = {
528
- response: string
529
- }
530
-
531
- const { data, pending, error } = useAsyncData("stats", ({ signal }) => {
532
- return $fetch<Stats>("/api/stats", { signal })
533
- })
534
- </script>
535
-
536
- <template>
537
- <div v-if="pending" class="skeleton"></div>
538
- <p v-if="error">{{ error.message }}</p>
539
- <strong v-if="!pending && !error && data">{{ data.response }}</strong>
540
- </template>
541
- ```
542
-
543
- Resux serializes the pending state, renders the skeleton immediately, resumes only scopes with pending async data in the browser, and patches the marked DOM blocks after the data resolves. The handler receives an abort `signal`; pass it to `$fetch` or `fetch` so pending client requests are aborted when the user leaves the route before data resolves.
544
-
545
- Templates auto-unwrap refs returned from `useState`, `useAsyncData`, `useFetch`, Vue `ref`, and `computed`, so template examples use `count`, `pending`, and `data.response`. In `<script setup>`, keep using `.value` when mutating refs, such as `count.value++`.
546
-
547
- ## Server API Fetches
548
-
549
- Browser-only fetches can use relative API URLs:
550
-
551
- ```ts
552
- await fetch("/api/test")
553
- ```
554
-
555
- Code that can run during SSR should use `$fetch()` for internal APIs. Resux automatically resolves internal `/api/...` URLs to an absolute request-origin URL on the server, while keeping them relative in the browser:
556
-
557
- ```vue
558
- <script setup lang="ts">
559
- const { data, pending, error } = useAsyncData("test", ({ signal }) => {
560
- return $fetch("/api/test", { signal })
561
- })
562
- </script>
563
-
564
- <template>
565
- <p v-if="pending">Loading</p>
566
- <p v-if="error">{{ error.message }}</p>
567
- <pre v-if="data">{{ data }}</pre>
568
- </template>
569
- ```
570
-
571
- On the server, `$fetch("/api/test")` uses the current request origin, then configured public origins such as `runtimeConfig.public.appOrigin`, and finally `http://localhost:3000`. In the browser it keeps `/api/test` relative. Use `apiURL("/api/test")` only when you call native `fetch()` yourself in code that can run during SSR.
572
-
573
- ## Supported Syntax
574
-
575
- The v1 compiler supports:
576
-
577
- - Static elements and text.
578
- - Interpolation: `{{ value }}`.
579
- - Static attributes: `class="box"`.
580
- - Dynamic attributes: `:class="className"`.
581
- - Dynamic class arrays/objects and style objects for `:class` and `:style`.
582
- - Plain CSS `<style>` blocks, including `<style scoped>`.
583
- - Plain named events: `@click="increment"`.
584
- - Inline event expressions that only capture resumable values, plus named handlers such as `@click="increment"`.
585
- - Resumability-safe event modifiers: `.prevent`, `.stop`, `.self`, `.once`, system/mouse modifiers, and key filters such as `.enter`.
586
- - `v-if`, `v-else-if`, and `v-else`.
587
- - `v-show`.
588
- - `v-text`.
589
- - Sanitized `v-html`.
590
- - Basic `v-model` for form values.
591
- - Simple `v-for`, such as `item in items` or `(item, index) in items`.
592
- - Component tags from `components/`.
593
- - `<ResuxPage />`.
594
- - `<ResuxLayout />`.
595
- - `<slot />` inside layouts.
596
- - `<ResuxLink to="/path">`.
597
- - `defineProps()` in components.
598
- - `definePageMeta({ layout, middleware, title, meta })`.
599
- - `useRoute()` for the current path, params, and query.
600
- - `useRouter().push("/path")`, `replace`, `back`, `forward`, and `go`.
601
- - `useHead({ title, meta, link })`.
602
- - `useSeoMeta({ title, description, ogTitle, ogImage, twitterCard })`.
603
- - `apiURL("/api/path")` for SSR-safe API fetch URLs.
604
- - `onMounted()`, run when the component scope is first resumed in the browser.
605
- - Vue runtime islands via `<VueIsland name="CounterIsland" :props="{ start: 1 }" />` and files in `islands/vue`.
606
-
607
- Handlers and inline event expressions must only capture resumable values, such as refs returned by `useState`.
608
-
609
- ## Current Limits
610
-
611
- Resux intentionally rejects or does not support many advanced framework/Vue features yet:
612
-
613
- - Vue runtime is island-only; Resux components still do not hydrate through Vue.
614
- - Nitro support is an adapter/deployment preset, not the primary dev server.
615
- - SFC styles support plain CSS only; preprocessors like SCSS and CSS modules are not implemented for resumable components yet.
616
- - Event `.capture` and `.passive` are accepted in templates, but the browser runtime still uses delegated resumable listeners.
617
- - No fallback hydration for unsupported components.
618
-
619
- Unsupported resumability patterns should fail at compile time instead of silently hydrating.
620
-
621
- ## Troubleshooting
622
-
623
- - `Failed to parse URL from /api/...` during SSR: use `apiURL("/api/...")` or `$fetch("/api/...")` from Resux setup code so server-side fetches get an absolute URL.
624
- - Skeletons that never disappear: render `error` from `useAsyncData` and guard success UI with `!pending && !error && data`.
625
- - Dev edits do not appear: keep `resux dev .` running and make sure the browser is connected to `/__resux/dev-events`; Resux reloads the page after successful rebuilds.
626
- - Port already in use: pass another port, for example `resux dev --port 4000`.
627
- - Handler capture compile errors: move non-serializable values out of resumable handlers or store resumable state with `useState`.
628
-
629
- ## Architecture
630
-
631
- Resux is one package with five internal parts:
632
-
633
- - Compiler: parses `.vue` files, creates routes, validates resumable handlers, and emits server/client modules.
634
- - Runtime: renders HTML on the server, provides Resux-style composables, runs plugins, applies layouts, collects head entries, and serializes payloads.
635
- - CLI and Node server: builds apps, starts the dev server, previews generated output, and exposes `resuxjs/node`.
636
- - Create CLI: scaffolds a starter app for `resux init`.
637
- - Package entrypoints: keep the root runtime-only while `resuxjs/compiler`, `resuxjs/runtime`, `resuxjs/node`, `resuxjs/globals`, and `resuxjs/create` expose focused surfaces.
638
-
639
- The browser initially receives only server-rendered HTML, the serialized payload, and the small resume loader.
640
-
641
- For internal navigation, the client runtime prefetches route payloads on hover/focus, intercepts same-origin links, fetches a fresh SSR route payload from `/__resux/route`, updates a server-rendered transition progress shell through start/fetch/swap/complete/error phases, keeps the active layout DOM when the layout name matches, swaps the page slot, updates `<head>`, updates browser history, and clears only non-persistent resumed page scopes.
642
-
643
- ## Testing
644
-
645
- Run:
646
-
647
- ```sh
648
- npm test
649
- ```
650
-
651
- The tests cover:
652
-
653
- - Route generation.
654
- - SFC compiler output.
655
- - Compile errors for unsupported resumability captures.
656
- - Sanitized `v-html`, `v-model`, inline handlers, and mounted resume hooks.
657
- - SSR payload serialization.
658
- - Dynamic route params and catch-all params.
659
- - Layout rendering.
660
- - Head/meta rendering.
661
- - Runtime config and plugin provides.
662
- - Recursive project discovery for layouts, middleware, server middleware, plugins, API routes, and config.
663
- - Plugin order and client/server mode filtering.
664
- - Route middleware execution for SSR and client navigation.
665
- - Extended route-rule serialization.
666
- - Client resume behavior after interaction.
1
+ # Resux
2
+
3
+ Resux is an experimental web framework with a custom resumable runtime.
4
+
5
+ 📖 **Documentation**: [https://mahmoudabdalrhmanmohamed.github.io/resux-docs/](https://mahmoudabdalrhmanmohamed.github.io/resux-docs/)
6
+
7
+ It uses familiar `.vue` files and `pages/` routing, but normal Resux components do not use Vue hydration or the Vue runtime. The compiler parses a small Vue-like SFC subset, renders HTML on the server, serializes route and component state, then loads client code only when an event is triggered. Vue runtime is available as an opt-in island escape hatch for complex client widgets.
8
+
9
+ The v1 release line treats the documented compiler, SSR renderer, resume runtime, routing, and CLI commands as the stable core. Advanced Vue compatibility, Vue islands, Nitro adapter behavior, and unsupported Vue SFC syntax are still experimental and should fail loudly instead of silently falling back to hydration.
10
+
11
+ ## Create App
12
+
13
+ Create a new app with the latest published Resux package:
14
+
15
+ ```sh
16
+ npx resuxjs@latest init
17
+ ```
18
+
19
+ You can also use the lightweight create wrapper:
20
+
21
+ ```sh
22
+ npx create-resuxjs@latest
23
+ ```
24
+
25
+ With a project directory:
26
+
27
+ ```sh
28
+ npx resuxjs@latest init my-app
29
+ ```
30
+
31
+ With create options:
32
+
33
+ ```sh
34
+ npx resuxjs@latest init my-app --no-install
35
+ ```
36
+
37
+ Choose optional starter features:
38
+
39
+ ```sh
40
+ npx resuxjs@latest init my-app --features i18n,pwa
41
+ ```
42
+
43
+ Enable i18n hreflang alternate links explicitly:
44
+
45
+ ```sh
46
+ npx resuxjs@latest init my-app --features i18n --hreflang
47
+ ```
48
+
49
+ Generated apps use a single Resux dependency, similar to Nuxt apps installing `nuxt`:
50
+
51
+ ```json
52
+ {
53
+ "dependencies": {
54
+ "resuxjs": "^<current-version>"
55
+ }
56
+ }
57
+ ```
58
+
59
+ For local development before publishing:
60
+
61
+ ```sh
62
+ npm install
63
+ npm run typecheck
64
+ npm run build
65
+ npm run create:local -- my-app --no-install
66
+ ```
67
+
68
+ Then run the generated app:
69
+
70
+ ```sh
71
+ cd my-app
72
+ npm install
73
+ npm run dev
74
+ ```
75
+
76
+ ## Package Layout
77
+
78
+ ```txt
79
+ src/
80
+ compiler/ SFC parser, route manifest builder, code generator
81
+ runtime/ SSR renderer, composables, client resume loader source
82
+ index.ts Runtime-only public root export
83
+ cli.ts Resux CLI, dev server, preview server, deploy helpers
84
+ node.ts Node server handler export for adapters
85
+ create.ts App scaffolder used by `resux init`
86
+
87
+ templates/ Starter files copied by `resux init`
88
+ tests/ Compiler, SSR, and client resume tests
89
+ ```
90
+
91
+ Public imports are split so browser/client bundles do not accidentally pull compiler or server code:
92
+
93
+ ```ts
94
+ import { renderApp } from "resuxjs/runtime"
95
+ import { createResuxNodeHandler } from "resuxjs/node"
96
+ ```
97
+
98
+ Optional modules and features stay tree-shakable and are only included when configured.
99
+
100
+ ## Optional i18n
101
+
102
+ Resux i18n is opt-in through the `resuxjs/i18n` module. It is not included in default runtime output unless enabled.
103
+
104
+ ```ts
105
+ export default defineResuxConfig({
106
+ modules: ["resuxjs/i18n"],
107
+ i18n: {
108
+ defaultLocale: "en",
109
+ fallbackLocale: "en",
110
+ strategy: "prefix_except_default",
111
+ locales: [
112
+ { code: "en", name: "English", dir: "ltr" },
113
+ { code: "ar", name: "العربية", dir: "rtl" }
114
+ ],
115
+ messages: {
116
+ en: () => import("./locales/en.json"),
117
+ ar: () => import("./locales/ar.json")
118
+ },
119
+ seo: {
120
+ hreflang: true
121
+ }
122
+ }
123
+ })
124
+ ```
125
+
126
+ Use i18n helpers in pages/components:
127
+
128
+ ```ts
129
+ import { useI18n } from "resuxjs/i18n"
130
+
131
+ const i18n = useI18n()
132
+ const title = i18n.t("demo.title")
133
+ const toArabic = i18n.switchLocalePath("ar")
134
+ ```
135
+
136
+ ## Icons (`resuxjs/icons`)
137
+
138
+ The `resuxjs/icons` module enables dynamic Iconify SVG fetching, pre-populated collections, and viewport visibility lazy loading.
139
+
140
+ ```ts
141
+ export default defineResuxConfig({
142
+ modules: [
143
+ ["resuxjs/icons", {
144
+ component: "Icon",
145
+ mode: "svg",
146
+ apiProvider: "https://api.iconify.design",
147
+ collections: ["material-symbols", "mdi", "mingcute", "cib", "uil", "line-md", "solar", "ph"],
148
+ lazy: true
149
+ }]
150
+ ]
151
+ })
152
+ ```
153
+
154
+ Use `<Icon>` or `<ResuxIcon>` natively in templates without manual imports:
155
+
156
+ ```vue
157
+ <template>
158
+ <!-- Eager / Pre-registered Icon -->
159
+ <Icon name="material-symbols:call" size="1.5rem" />
160
+
161
+ <!-- Dynamic Iconify Icon -->
162
+ <Icon name="ph:check-circle-thin" size="2rem" />
163
+
164
+ <!-- Viewport IntersectionObserver Lazy Loaded Icon -->
165
+ <Icon name="solar:leaf-outline" size="2rem" lazy />
166
+ </template>
167
+ ```
168
+
169
+ ## Fonts (`resuxjs/fonts`)
170
+
171
+ The `resuxjs/fonts` module manages preconnect optimizations, Google Fonts URL building, font loading priority strategies (`lazy`, `preload`, `eager`), and post-onload deferral.
172
+
173
+ ```ts
174
+ export default defineResuxConfig({
175
+ modules: [
176
+ ["resuxjs/fonts", {
177
+ preconnect: true,
178
+ strategy: "lazy",
179
+ deferUntilPageLoad: true,
180
+ google: [
181
+ { name: "Inter", weights: [400, 500, 600, 700, 800], display: "swap" },
182
+ { name: "Alexandria", weights: [300, 400, 500, 600, 700], display: "swap" }
183
+ ]
184
+ }]
185
+ ]
186
+ })
187
+ ```
188
+
189
+ ## UI & Animations (`resuxjs/ui`)
190
+
191
+ The `resuxjs/ui` module provides design tokens, Web Animations API (WAAPI) helpers (`useAnimate()`), scroll-reveal directives (`v-anime`), and animation presets.
192
+
193
+ ```ts
194
+ export default defineResuxConfig({
195
+ modules: [
196
+ ["resuxjs/ui", {
197
+ tokens: {
198
+ accent: "#03C8BF"
199
+ },
200
+ animations: {
201
+ enabled: true,
202
+ defaultPreset: "fade-up"
203
+ }
204
+ }]
205
+ ]
206
+ })
207
+ ```
208
+
209
+ Use the `v-anime` directive or `useAnimate` composable in components:
210
+
211
+ ```vue
212
+ <template>
213
+ <div v-anime="'fade-up'">
214
+ <h2>Title</h2>
215
+ </div>
216
+
217
+ <button v-anime="{ type: 'scale-in', duration: 400, delay: 100 }">
218
+ Animate Me
219
+ </button>
220
+ </template>
221
+ ```
222
+
223
+ ## Halal Core integrity keys
224
+
225
+ Local reports use a deterministic `sha256:` checksum when no key is configured. Production server and deployment guards require authenticated HMAC reports. Configure private keys with at least 32 characters before building production artifacts:
226
+
227
+ ```sh
228
+ export RESUX_HALAL_REPORT_SIGNING_SECRET="replace-with-a-private-random-secret"
229
+ export RESUX_HALAL_REVIEW_SIGNING_SECRET="replace-with-a-different-private-random-secret"
230
+ ```
231
+
232
+ Do not commit these values. The report key signs the complete generated report; the review key authenticates human review approval files. Optional remote AI classification also requires an HTTPS endpoint (localhost HTTP is allowed for development) and supports `RESUX_AI_TIMEOUT_MS`.
233
+
234
+ ## Development
235
+
236
+ ```sh
237
+ npm install
238
+ npm run typecheck
239
+ npm run build
240
+ npm test
241
+ npm run test:templates
242
+ ```
243
+
244
+ Run the full publish-readiness check:
245
+
246
+ ```sh
247
+ npm run pack:check
248
+ ```
249
+
250
+ This builds, tests, and dry-runs npm packing for the single `resuxjs` package.
251
+
252
+ CI runs on every push and pull request with `npm ci`, optional linting, typecheck, build, tests, and package dry-run checks.
253
+
254
+ ## Release Process
255
+
256
+ Normal pushes never publish to npm. They only run CI. Publishing is intentionally gated to version tags or GitHub Releases so an ordinary `main` push cannot publish a broken package.
257
+
258
+ To release:
259
+
260
+ 1. Update the version and create the release commit/tag with `npm version 1.0.0`.
261
+ 2. Push the release commit with `git push origin main`.
262
+ 3. Push the version tag with `git push origin v1.0.0`.
263
+ 4. The GitHub Action publishes `resuxjs@1.0.0` to npm.
264
+
265
+ The npm publish workflow validates that the tag matches `package.json`, installs only the locked dependency graph, runs typecheck, build, tests, and package checks, skips versions that already exist, then publishes through npm Trusted Publishing (GitHub OIDC) with provenance. Configure the npm Trusted Publisher for repository `MahmoudAbdalrhmanMohamed/resux` and workflow `npm-publish.yml`; no long-lived `NPM_TOKEN` is used.
266
+
267
+ ## CLI
268
+
269
+ The `resux` CLI supports:
270
+
271
+ ```sh
272
+ resux init <project-dir>
273
+ resux dev <app-root>
274
+ resux build <app-root>
275
+ resux prepare <app-root>
276
+ resux preview <app-root>
277
+ resux start <app-root>
278
+ resux inspect <app-root>
279
+ resux check <app-root>
280
+ resux deploy <app-root>
281
+ ```
282
+
283
+ If `<app-root>` is omitted, Resux uses the current directory.
284
+
285
+ Starter templates are selectable from `resux init` / `npm create resuxjs@latest`:
286
+
287
+ ```sh
288
+ npx create-resuxjs@latest my-app --template default
289
+ # templates: minimal, default, full, i18n, pwa, media, package-compatibility, dashboard
290
+ ```
291
+
292
+ Useful server flags:
293
+
294
+ ```sh
295
+ resux dev --port 4000
296
+ resux preview --host 0.0.0.0 --port 4000
297
+ resux start --host 0.0.0.0 --port 3000
298
+ resux inspect
299
+ resux inspect --json
300
+ resux inspect routes
301
+ resux inspect packages
302
+ resux inspect bundles --json
303
+ resux inspect seo --json
304
+ resux check
305
+ resux check --json
306
+ resux check --fix
307
+ resux prepare
308
+ resux deploy . --preset docker
309
+ resux deploy . --preset nitro
310
+ resux --help
311
+ resux --version
312
+ ```
313
+
314
+ Build output is written to:
315
+
316
+ ```txt
317
+ <app-root>/.resux
318
+ ```
319
+
320
+ Generated integration directories are bootstrapped automatically by `resux dev`, `resux build`, `resux preview`, `resux prepare`, and `resux check --fix`:
321
+
322
+ ```txt
323
+ <app-root>/.resux
324
+ <app-root>/.resux-nitro
325
+ <app-root>/.nitro
326
+ ```
327
+
328
+ ## App Types
329
+
330
+ Generated apps include `env.d.ts` and `tsconfig.json` wired to `resuxjs/globals`, so app files can use the Resux-style globals without imports:
331
+
332
+ ```ts
333
+ const count = useState("count", () => 0)
334
+ const route = useRoute()
335
+ const router = useRouter()
336
+ useSeoMeta({
337
+ title: "My App",
338
+ description: "My app description",
339
+ ogTitle: "My App"
340
+ })
341
+
342
+ function openAbout() {
343
+ router.push("/about")
344
+ }
345
+
346
+ export default defineResuxConfig({
347
+ app: {
348
+ head: {
349
+ title: "My App"
350
+ }
351
+ }
352
+ })
353
+ ```
354
+
355
+ ## Reactivity APIs
356
+
357
+ Resux includes a native reactivity layer for resumable components. You can use it with globals in app files, or import directly:
358
+
359
+ ```ts
360
+ import {
361
+ ref,
362
+ reactive,
363
+ computed,
364
+ watch,
365
+ watchEffect,
366
+ readonly,
367
+ toRef,
368
+ toRefs,
369
+ unref,
370
+ isRef,
371
+ isReactive,
372
+ isReadonly,
373
+ nextTick
374
+ } from "resuxjs"
375
+ ```
376
+
377
+ Or from the focused subpath:
378
+
379
+ ```ts
380
+ import { ref, reactive, computed } from "resuxjs/reactivity"
381
+ ```
382
+
383
+ These APIs are Resux-native. Normal Resux components do not depend on Vue hydration runtime.
384
+
385
+ ## Vite
386
+
387
+ Resux uses Vite in both main app commands:
388
+
389
+ - `resux dev` emits Resux client modules into `.resux/vite-client` and serves the resume runtime plus handler modules through Vite middleware.
390
+ - `resux dev` also opens a dev-only update channel at `/__resux/dev-events`; when source files change, Resux rebuilds and reloads the browser so route, template, and style changes are visible without restarting the dev server.
391
+ - `resux build` uses Vite production bundling for the resume runtime, handler chunks, and server manifest, then writes optimized output into `.resux/client` and `.resux/server-bundle` before producing a Nitro `.output` server.
392
+
393
+ The generated starter keeps Resux-style scripts:
394
+
395
+ ```json
396
+ {
397
+ "scripts": {
398
+ "prepare": "resux prepare",
399
+ "dev": "resux dev",
400
+ "build": "resux build",
401
+ "preview": "resux preview",
402
+ "start": "resux start",
403
+ "inspect": "resux inspect",
404
+ "typecheck": "vue-tsc --noEmit"
405
+ }
406
+ }
407
+ ```
408
+
409
+ Tailwind can stay Nuxt-style simple too. If your app has `assets/css/tailwind.css` and `tailwindcss` installed, `resux dev` automatically runs Tailwind in watch mode and `resux build` generates a minified `public/tailwind.css` before bundling. No separate `concurrently` script is required.
410
+
411
+ ## Deployment
412
+
413
+ Build and serve with the Node server:
414
+
415
+ ```sh
416
+ npm run build
417
+ npm run start
418
+ ```
419
+
420
+ Production serving enables default hardening headers such as `x-content-type-options`, `referrer-policy`, `x-frame-options`, `cross-origin-opener-policy`, and a restrictive `permissions-policy`. Disable them only when the host or reverse proxy owns those headers:
421
+
422
+ ```sh
423
+ resux start . --no-security-headers
424
+ ```
425
+
426
+ Generated apps include a `Dockerfile`, `.dockerignore`, and `DEPLOYMENT.md`. Use `resux inspect --json` in CI to capture the built routes, server handlers, route rules, feature flags, and diagnostics.
427
+
428
+ Existing apps can generate or refresh deployment files without changing application code:
429
+
430
+ ```sh
431
+ resux deploy . --preset node
432
+ resux deploy . --preset docker --force
433
+ resux deploy . --preset nitro --force
434
+ ```
435
+
436
+ The Nitro preset writes `nitro.config.ts` and a small `.resux-nitro/handler.ts` adapter. `resux build` now produces Nuxt-style `.output` by default:
437
+
438
+ ```sh
439
+ npm run build
440
+ node .output/server/index.mjs
441
+ ```
442
+
443
+ The generated Nitro config is conservative for resumability: SSR pages, API routes, and route payloads use `cache-control: no-store`, while build-stable Resux runtime and handler assets use long immutable caching. Nitro prerender crawling is disabled by default.
444
+
445
+ Deployment target selection is automatic by default (`deploy.target = "auto"`). Resux resolves target/preset from:
446
+
447
+ - explicit `deploy.target` / `deploy.nitroPreset` in `resux.config.ts`
448
+ - `NITRO_PRESET` / `RESUX_NITRO_PRESET`
449
+ - provider environment variables
450
+ - project build config detection (`vercel.json`, `netlify.toml`, `wrangler.*`)
451
+ - package scripts heuristics
452
+
453
+ You can pin target behavior explicitly:
454
+
455
+ ```ts
456
+ export default defineResuxConfig({
457
+ deploy: {
458
+ target: "vercel", // "auto" | "node" | "netlify" | "cloudflare" | "static"
459
+ nitroPreset: "vercel"
460
+ }
461
+ })
462
+ ```
463
+
464
+ Cloudflare worker presets are opt-in via `deploy.target = "cloudflare"` (or explicit `deploy.nitroPreset`) so Node-style Nitro adapters do not get selected automatically in auto mode.
465
+
466
+ Production and dev servers expose a health endpoint for hosts and uptime checks:
467
+
468
+ ```txt
469
+ /__resux/health
470
+ ```
471
+
472
+ ## Modules And Route Rules
473
+
474
+ Resux supports first-party and third-party build-time modules in `resux.config.ts`. Modules run during the Resux build and can extend config without adding hydration:
475
+
476
+ ```ts
477
+ export default defineResuxConfig({
478
+ modules: [
479
+ "resux:security",
480
+ ["resux:performance", { assetMaxAge: 31536000 }],
481
+ ["./modules/security.ts", { header: "enabled" }]
482
+ ],
483
+ routeRules: {
484
+ "/old": { redirect: { to: "/", statusCode: 301 } },
485
+ "/admin/**": { headers: { "x-robots-tag": "noindex" } }
486
+ }
487
+ })
488
+ ```
489
+
490
+ Built-in modules:
491
+
492
+ - `resux:security`: adds default production hardening headers and optional custom headers or CSP through route rules.
493
+ - `resux:performance`: adds immutable cache rules for built Resux runtime/handler assets and `no-store` for route payloads.
494
+
495
+ Modules can be built-in `resux:*` specifiers, npm package specifiers, local files, inline functions, or objects returned by `defineResuxModule`.
496
+
497
+ ```ts
498
+ // modules/security.ts
499
+ export default defineResuxModule({
500
+ defaults: { header: "enabled" },
501
+ setup(options, resux) {
502
+ resux.addCss("/module.css")
503
+ resux.addHead({ meta: [{ name: "module", content: options.header }] })
504
+ resux.addRouteRule("/secure/**", {
505
+ headers: { "x-module": options.header },
506
+ cache: { maxAge: 60, swr: 30 }
507
+ })
508
+ resux.extendRuntimeConfig({
509
+ public: { securityModule: options.header }
510
+ })
511
+ }
512
+ })
513
+ ```
514
+
515
+ The module API includes `addCss`, `addHead`, `addRouteRule`, and `extendRuntimeConfig`. Route rules currently support redirects, response headers, status codes, cache headers, and CORS headers.
516
+
517
+ ## Plugins
518
+
519
+ Resux auto-discovers app plugins from `plugins/` (and `app/plugins/`) without manual imports:
520
+
521
+ - `plugins/*.ts`
522
+ - `plugins/**/*.ts`
523
+ - `plugins/*.client.ts`
524
+ - `plugins/*.server.ts`
525
+
526
+ Use `defineResuxPlugin`:
527
+
528
+ ```ts
529
+ // plugins/01.api.ts
530
+ export default defineResuxPlugin((resuxApp) => {
531
+ resuxApp.provide("apiBase", "/api")
532
+ })
533
+ ```
534
+
535
+ Plugin execution order is deterministic and sorted by discovered filename path. Numeric prefixes are supported, for example `01.auth.ts` runs before `02.analytics.ts`.
536
+
537
+ Mode behavior:
538
+
539
+ - `.client` plugins run only in the browser.
540
+ - `.server` plugins run only on the server.
541
+ - Unsuffixed plugins run on both server and client.
542
+
543
+ Use `useResuxApp()` inside setup code to access provided values:
544
+
545
+ ```ts
546
+ const app = useResuxApp()
547
+ const apiBase = String(app.provides.apiBase ?? "/api")
548
+ ```
549
+
550
+ TypeScript app helpers are available globally when your app includes:
551
+
552
+ ```ts
553
+ /// <reference types="resuxjs/globals" />
554
+ ```
555
+
556
+ For typed plugin injections, augment `ResuxAppInjections`:
557
+
558
+ ```ts
559
+ declare module "resuxjs/runtime" {
560
+ interface ResuxAppInjections {
561
+ apiBase: string
562
+ }
563
+ }
564
+ ```
565
+
566
+ ## Route Middleware
567
+
568
+ Resux auto-discovers route middleware from `middleware/` (and `app/middleware/`) without manual imports:
569
+
570
+ - `middleware/*.ts`
571
+ - `middleware/**/*.ts`
572
+ - `middleware/*.global.ts`
573
+ - `middleware/*.client.ts`
574
+ - `middleware/*.server.ts`
575
+
576
+ Create middleware with `defineResuxRouteMiddleware`:
577
+
578
+ ```ts
579
+ // middleware/auth.ts
580
+ export default defineResuxRouteMiddleware((to) => {
581
+ if (to.path.startsWith("/admin")) {
582
+ return navigateTo("/login")
583
+ }
584
+ })
585
+ ```
586
+
587
+ Apply named middleware from page meta:
588
+
589
+ ```ts
590
+ definePageMeta({ middleware: "auth" })
591
+ definePageMeta({ middleware: ["auth", "admin"] })
592
+ ```
593
+
594
+ Global middleware (`*.global.ts`) runs for every route. Middleware return handling:
595
+
596
+ - `undefined` or no return: continue
597
+ - `false`: abort with `403`
598
+ - `"/path"`: redirect
599
+ - `{ redirect: "/path" }` or `{ redirect: { to: "/path", statusCode: 302 } }`: redirect
600
+ - `navigateTo("/path")`: redirect helper
601
+ - `abortNavigation("message")`: abort helper
602
+
603
+ Mode behavior:
604
+
605
+ - `.client` middleware runs in browser navigation.
606
+ - `.server` middleware runs only during server rendering/navigation handling.
607
+ - Unsuffixed middleware runs on server route resolution.
608
+
609
+ ## Server Middleware
610
+
611
+ Files in `server/middleware` run for each request before server handlers, public files, and page rendering:
612
+
613
+ ```ts
614
+ export default defineServerMiddleware((event) => {
615
+ setHeader(event, "x-app", "resux")
616
+
617
+ if (event.path.startsWith("/private")) {
618
+ return { type: "redirect", to: "/login", statusCode: 302 }
619
+ }
620
+ })
621
+ ```
622
+
623
+ Server middleware can continue by returning nothing, use h3-style helpers such as `setHeader(event, name, value)`, end the Node response directly when necessary, return a `Response`, return a JSON-serializable value, return `false` to send `403`, or return a redirect/abort object.
624
+
625
+ `server/middleware` is request middleware for raw HTTP handling and API/page requests. Route middleware in `middleware/` is navigation middleware for page routing decisions (`definePageMeta({ middleware })` + globals).
626
+
627
+ ## What Works
628
+
629
+ - `.vue`-style SFC files with `<template>`, `<script setup lang="ts">`, and plain CSS `<style>` blocks.
630
+ - File-based routing from `pages/`.
631
+ - Dynamic route params like `pages/post/[id].vue`.
632
+ - Catch-all route params like `pages/docs/[...slug].vue`.
633
+ - `app.vue` with `<ResuxPage />`.
634
+ - Layouts with `<ResuxLayout>`, `<slot />`, and `definePageMeta({ layout })`.
635
+ - `<ResuxLink to="...">` rendered as an `<a href="...">` and intercepted for client-side navigation.
636
+ - Static and dynamic component props with `defineProps()`.
637
+ - Server-side rendering.
638
+ - Head/meta rendering from `resux.config.ts`, `definePageMeta`, `useHead`, and `useSeoMeta`.
639
+ - Component CSS from `<style>` and `<style scoped>`, included in SSR output and updated during client-side navigation.
640
+ - Auto-discovered route middleware from `middleware/**/*`, including `.global`, `.client`, and `.server` files.
641
+ - Request-time server middleware from `server/middleware`.
642
+ - Auto-discovered plugins from `plugins/**/*` plus client enhancement entries from `enhancements/**/*` and `client-enhancements/**/*` (including `app/*` variants), with `.client` / `.server` mode suffix support and stable filename ordering.
643
+ - Server API/routes from `server/api` and `server/routes`.
644
+ - Server handler helpers: `readBody(event)`, `getQuery(event)`, and `setHeader(event, name, value)`, backed by h3.
645
+ - `error.vue` for custom 404/500 rendering.
646
+ - Public file serving from `public/`.
647
+ - Built-in health checks at `/__resux/health`.
648
+ - Basic `resux.config.ts` support for `runtimeConfig`, `app.head`, and `css`.
649
+ - Built-in and package/local Resux modules for extending CSS, head, route rules, and runtime config during build.
650
+ - Route rules for redirects, response headers, status codes, cache headers, and CORS headers.
651
+ - Default production security headers with an opt-out flag.
652
+ - Vite-powered dev serving, production client/server bundling, and minification for the resume runtime and handler chunks.
653
+ - Dev rebuilds with automatic browser reloads, without adding Vue hydration.
654
+ - `resux inspect` and `resux inspect --json` for route and build diagnostics.
655
+ - `resux inspect routes|plugins|middleware|imports|components|build|images|server|packages|templates|bundles|seo`.
656
+ - `resux check`, `resux check --json`, and `resux check --fix` for project readiness checks and safe file scaffolding.
657
+ - `resux deploy --preset node|docker|nitro` for deployment file generation.
658
+ - Serialized route, state, and async data payloads.
659
+ - Resumable event handlers such as `@click="increment"`.
660
+ - Lazy client handler chunks loaded on first interaction.
661
+ - Client-side navigation, persistent same-layout DOM, built-in route transition progress, and hover/focus route payload prefetch for same-origin links.
662
+ - Stable core composables: `useState`, `useAsyncData`, `useRoute`, `useRouter`, `useHead`, `useSeoMeta`, `useRuntimeConfig`, `useResuxApp`, `apiURL`, `useFetch`, `$fetch`, `useError`, `clearError`, `showError`, `createError`, and `onMounted`.
663
+ - Lazy package helpers: `useLazyPackage`, `useClientPackage`, `usePackageReady`, `defineLazyPackage`, `defineClientOnlyPackage`, `defineClientEnhancement`, and `useClientEnhancement`.
664
+ - Package mode classification via `packages.mode` (`ssr`, `clientOnly`, `serverOnly`, `progressive`) with diagnostics in `resux inspect packages`.
665
+ - Client runtime package registries are generated with static importers (no raw `import(packageName)` in generated runtime), including package API calls that use const string identifiers and package subpaths (for example `swiper/modules` and `swiper/css/*`).
666
+ - `useAsyncData` returns a Nuxt-like resource with reactive `data`, `pending`, and `error` refs, plus `value` as a data alias for compatibility. Use `await useAsyncData(...)` when you want SSR to fetch before rendering the page; omit `await` when you intentionally want an SSR skeleton that resumes in the browser.
667
+
668
+ ## SSR-First Package Enhancements
669
+
670
+ Use semantic SSR markup first, then enhance only in the browser:
671
+
672
+ ```vue
673
+ <section
674
+ use-client-enhancement="swiper-carousel"
675
+ data-trigger="visible"
676
+ >
677
+ <ul class="swiper-wrapper">
678
+ <li class="swiper-slide">...</li>
679
+ </ul>
680
+ </section>
681
+ ```
682
+
683
+ Register the enhancement in a client-only support file (for example `client-enhancements/swiper-carousel.client.ts`):
684
+
685
+ ```ts
686
+ defineClientEnhancement("swiper-carousel", async (target) => {
687
+ const [
688
+ { default: Swiper },
689
+ { Navigation, Pagination },
690
+ ] = await Promise.all([
691
+ useClientPackage("swiper"),
692
+ useClientPackage("swiper/modules", { preferDefault: false }),
693
+ ])
694
+ await useClientPackage("swiper", {
695
+ css: ["swiper/css", "swiper/css/navigation", "swiper/css/pagination"],
696
+ })
697
+ const instance = new Swiper(target.querySelector(".swiper") as HTMLElement, {
698
+ modules: [Navigation, Pagination],
699
+ })
700
+ return () => instance.destroy?.(true, true)
701
+ })
702
+ ```
703
+
704
+ Resux injects runtime helper imports for support modules automatically, so `defineClientEnhancement` and `useClientPackage` are available without global assumptions. This pattern keeps package instances inside client-only closures and avoids resumability-unsafe captures in template handlers.
705
+
706
+ In dev, enhancement and package lifecycles emit events you can observe in custom status UIs:
707
+ - `resux:enhancement:found|triggered|loading|ready|error|cleanup-ready`
708
+ - `resux:package:loading|loaded|error`
709
+ - `resux:package-css:loaded`
710
+
711
+ ## Component Syntax
712
+
713
+ ```vue
714
+ <script setup lang="ts">
715
+ const count = useState("count", () => 0)
716
+
717
+ function increment() {
718
+ count.value++
719
+ }
720
+ </script>
721
+
722
+ <template>
723
+ <button @click="increment">
724
+ Count: {{ count }}
725
+ </button>
726
+ </template>
727
+ ```
728
+
729
+ On the server, Resux renders the button as HTML and serializes `count`.
730
+
731
+ In the browser, Resux installs a tiny delegated event listener. The component handler module is not imported until the user clicks the button. After that, the scope is resumed from serialized state and only the marked DOM bindings are patched.
732
+
733
+ ## Async Data Skeletons
734
+
735
+ To fetch during SSR and render the resolved data in the first HTML response, await the call:
736
+
737
+ ```vue
738
+ <script setup lang="ts">
739
+ type Stats = {
740
+ response: string
741
+ }
742
+
743
+ const { data, pending, error } = await useAsyncData("stats", ({ signal }) => {
744
+ return $fetch<Stats>("/api/stats", { signal })
745
+ })
746
+ </script>
747
+
748
+ <template>
749
+ <p v-if="pending">Loading</p>
750
+ <p v-if="error">{{ error.message }}</p>
751
+ <strong v-if="data">{{ data.response }}</strong>
752
+ </template>
753
+ ```
754
+
755
+ For a Next-style loading skeleton, call `useAsyncData` without `await` and branch on `pending`:
756
+
757
+ ```vue
758
+ <script setup lang="ts">
759
+ type Stats = {
760
+ response: string
761
+ }
762
+
763
+ const { data, pending, error } = useAsyncData("stats", ({ signal }) => {
764
+ return $fetch<Stats>("/api/stats", { signal })
765
+ })
766
+ </script>
767
+
768
+ <template>
769
+ <div v-if="pending" class="skeleton"></div>
770
+ <p v-if="error">{{ error.message }}</p>
771
+ <strong v-if="!pending && !error && data">{{ data.response }}</strong>
772
+ </template>
773
+ ```
774
+
775
+ Resux serializes the pending state, renders the skeleton immediately, resumes only scopes with pending async data in the browser, and patches the marked DOM blocks after the data resolves. The handler receives an abort `signal`; pass it to `$fetch` or `fetch` so pending client requests are aborted when the user leaves the route before data resolves.
776
+
777
+ Templates auto-unwrap refs returned from `useState`, `useAsyncData`, `useFetch`, Vue `ref`, and `computed`, so template examples use `count`, `pending`, and `data.response`. In `<script setup>`, keep using `.value` when mutating refs, such as `count.value++`.
778
+
779
+ ## Server API Fetches
780
+
781
+ Browser-only fetches can use relative API URLs:
782
+
783
+ ```ts
784
+ await fetch("/api/test")
785
+ ```
786
+
787
+ Code that can run during SSR should use `$fetch()` for internal APIs. Resux automatically resolves internal `/api/...` URLs to an absolute request-origin URL on the server, while keeping them relative in the browser:
788
+
789
+ ```vue
790
+ <script setup lang="ts">
791
+ const { data, pending, error } = useAsyncData("test", ({ signal }) => {
792
+ return $fetch("/api/test", { signal })
793
+ })
794
+ </script>
795
+
796
+ <template>
797
+ <p v-if="pending">Loading</p>
798
+ <p v-if="error">{{ error.message }}</p>
799
+ <pre v-if="data">{{ data }}</pre>
800
+ </template>
801
+ ```
802
+
803
+ On the server, `$fetch("/api/test")` uses the current request origin, then configured public origins such as `runtimeConfig.public.appOrigin`, and finally `http://localhost:3000`. In the browser it keeps `/api/test` relative. Use `apiURL("/api/test")` only when you call native `fetch()` yourself in code that can run during SSR.
804
+
805
+ ## Media Components
806
+
807
+ ### `ResuxVideo`
808
+
809
+ `ResuxVideo` supports resumable click zones without hydration. By default, the surface is divided into horizontal thirds:
810
+
811
+ - left third: skip backward
812
+ - center third: single click play/pause
813
+ - center third double click: fullscreen
814
+ - right third: skip forward
815
+
816
+ Controls remain interactive because zones exclude the controls hit area and control targets are ignored.
817
+
818
+ ```vue
819
+ <ResuxVideo
820
+ src="/media-test/videos/sample-720.mp4"
821
+ poster="/media-test/images/sample-poster.jpg"
822
+ controls
823
+ skip-seconds="10"
824
+ side-click-skip
825
+ click-to-play
826
+ double-click-fullscreen
827
+ />
828
+ ```
829
+
830
+ `ResuxVideo` props (media interaction subset):
831
+
832
+ - `controls` default `true`
833
+ - `nativeControls` optional
834
+ - `customControls` optional
835
+ - `speedControl`, `speeds`, `defaultSpeed`, `persistSpeed`
836
+ - `qualityControl`, `qualities`, `defaultQuality`
837
+ - `sources` supports `{ src, type, quality }`
838
+ - `skipSeconds` default `10`
839
+ - `sideClickSkip` default `true`
840
+ - `clickToPlay` default `true`
841
+ - `doubleClickFullscreen` default `true`
842
+ - `lazy`, `priority`, `preload`, `poster`, `placeholder`
843
+ - optional transforms: `format`, `formats`, `quality` (for resolution height)
844
+
845
+ Video state attributes:
846
+
847
+ - `data-resux-video="idle|loading|ready|playing|paused|error"`
848
+ - `data-rx-video-controls-ready="true|false"`
849
+ - `data-resux-video-control` on interactive control elements
850
+ - `data-resux-video-zone="left|center|right"` on surface zones
851
+
852
+ Optional video transforms can generate cacheable assets in `public/_resux/generated/videos/*` when enabled:
853
+
854
+ ```ts
855
+ export default defineResuxConfig({
856
+ video: {
857
+ transforms: {
858
+ enabled: true,
859
+ formats: ["mp4", "webm"],
860
+ qualities: [480, 720, 1080],
861
+ cache: "1d"
862
+ }
863
+ }
864
+ })
865
+ ```
866
+
867
+ When transforms are requested (for example `format="webm"` or `:qualities="[480,720]"`), Resux emits deterministic URLs under `/_resux/generated/videos/*` and serves them through the built-in `__resux/video` runtime endpoint. If `ffmpeg` is unavailable, Resux falls back with a clear 501 error instead of breaking standard video rendering.
868
+
869
+ ### `ResuxImg` and `ResuxPicture`
870
+
871
+ `ResuxImg` and `ResuxPicture` keep placeholders active until the real image load/decode completes.
872
+
873
+ ```vue
874
+ <ResuxImg
875
+ src="/media-test/images/hero-large.jpg"
876
+ width="1600"
877
+ height="900"
878
+ priority
879
+ placeholder="blur"
880
+ sizes="(min-width: 1280px) 960px, 100vw"
881
+ />
882
+ ```
883
+
884
+ Placeholder modes:
885
+
886
+ - `placeholder="empty"`
887
+ - `placeholder="blur"`
888
+ - `placeholder="skeleton"`
889
+ - `placeholder="spinner"`
890
+ - `placeholder="/custom-placeholder.svg"`
891
+
892
+ Image state attributes:
893
+
894
+ - `data-resux-img="idle|loading|loaded|error"`
895
+ - `data-rx-placeholder-active="true"` while placeholder is visible
896
+ - `data-rx-lazy-image="true"` for deferred lazy sources
897
+
898
+ Priority images emit preload links near the top of `<head>` with `fetchpriority="high"` and responsive `imagesrcset`/`imagesizes`.
899
+
900
+ ## Supported Syntax
901
+
902
+ The v1 compiler supports:
903
+
904
+ - Static elements and text.
905
+ - Interpolation: `{{ value }}`.
906
+ - Static attributes: `class="box"`.
907
+ - Dynamic attributes: `:class="className"`.
908
+ - Dynamic class arrays/objects and style objects for `:class` and `:style`.
909
+ - Plain CSS `<style>` blocks, including `<style scoped>`.
910
+ - Plain named events: `@click="increment"`.
911
+ - Inline event expressions that only capture resumable values, plus named handlers such as `@click="increment"`.
912
+ - Resumability-safe event modifiers: `.prevent`, `.stop`, `.self`, `.once`, system/mouse modifiers, and key filters such as `.enter`.
913
+ - `v-if`, `v-else-if`, and `v-else`.
914
+ - `v-show`.
915
+ - `v-text`.
916
+ - Sanitized `v-html`.
917
+ - Basic `v-model` for form values.
918
+ - Simple `v-for`, such as `item in items` or `(item, index) in items`.
919
+ - Component tags from `components/`.
920
+ - `<ResuxPage />`.
921
+ - `<ResuxLayout />`.
922
+ - `<slot />` inside layouts.
923
+ - `<ResuxLink to="/path">`.
924
+ - `defineProps()` in components.
925
+ - `definePageMeta({ layout, middleware, title, meta })`.
926
+ - `useRoute()` for the current path, params, and query.
927
+ - `useRouter().push("/path")`, `replace`, `back`, `forward`, and `go`.
928
+ - `useHead({ title, meta, link })`.
929
+ - `useSeoMeta({ title, description, ogTitle, ogImage, twitterCard })`.
930
+ - `apiURL("/api/path")` for SSR-safe API fetch URLs.
931
+ - `onMounted()`, run when the component scope is first resumed in the browser.
932
+ - Vue runtime islands via `<VueIsland name="CounterIsland" :props="{ start: 1 }" />` and files in `islands/vue`.
933
+
934
+ Handlers and inline event expressions must only capture resumable values, such as refs returned by `useState`.
935
+
936
+ ## Current Limits
937
+
938
+ Resux intentionally rejects or does not support many advanced framework/Vue features yet:
939
+
940
+ - Vue runtime is island-only; Resux components still do not hydrate through Vue.
941
+ - Nitro support is an adapter/deployment preset, not the primary dev server.
942
+ - SFC styles support plain CSS only; preprocessors like SCSS and CSS modules are not implemented for resumable components yet.
943
+ - Event `.capture` and `.passive` are accepted in templates, but the browser runtime still uses delegated resumable listeners.
944
+ - No fallback hydration for unsupported components.
945
+
946
+ Unsupported resumability patterns should fail at compile time instead of silently hydrating.
947
+
948
+ ## Troubleshooting
949
+
950
+ - `Failed to parse URL from /api/...` during SSR: use `apiURL("/api/...")` or `$fetch("/api/...")` from Resux setup code so server-side fetches get an absolute URL.
951
+ - Skeletons that never disappear: render `error` from `useAsyncData` and guard success UI with `!pending && !error && data`.
952
+ - Dev edits do not appear: keep `resux dev .` running and make sure the browser is connected to `/__resux/dev-events`; Resux reloads the page after successful rebuilds.
953
+ - Port already in use: pass another port, for example `resux dev --port 4000`.
954
+ - Handler capture compile errors: move non-serializable values out of resumable handlers or store resumable state with `useState`.
955
+
956
+ ## Architecture
957
+
958
+ Resux is one package with five internal parts:
959
+
960
+ - Compiler: parses `.vue` files, creates routes, validates resumable handlers, and emits server/client modules.
961
+ - Runtime: renders HTML on the server, provides Resux-style composables, runs plugins, applies layouts, collects head entries, and serializes payloads.
962
+ - CLI and Node server: builds apps, starts the dev server, previews generated output, and exposes `resuxjs/node`.
963
+ - Create CLI: scaffolds a starter app for `resux init`.
964
+ - Package entrypoints: keep the root runtime-only while `resuxjs/compiler`, `resuxjs/runtime`, `resuxjs/node`, `resuxjs/globals`, and `resuxjs/create` expose focused surfaces.
965
+
966
+ The browser initially receives only server-rendered HTML, the serialized payload, and the small resume loader.
967
+
968
+ For internal navigation, the client runtime prefetches route payloads on hover/focus, intercepts same-origin links, fetches a fresh SSR route payload from `/__resux/route`, updates a server-rendered transition progress shell through start/fetch/swap/complete/error phases, keeps the active layout DOM when the layout name matches, swaps the page slot, updates `<head>`, updates browser history, and clears only non-persistent resumed page scopes.
969
+
970
+ ## Testing
971
+
972
+ Run:
973
+
974
+ ```sh
975
+ npm test
976
+ ```
977
+
978
+ The tests cover:
979
+
980
+ - Route generation.
981
+ - SFC compiler output.
982
+ - Compile errors for unsupported resumability captures.
983
+ - Sanitized `v-html`, `v-model`, inline handlers, and mounted resume hooks.
984
+ - SSR payload serialization.
985
+ - Dynamic route params and catch-all params.
986
+ - Layout rendering.
987
+ - Head/meta rendering.
988
+ - Runtime config and plugin provides.
989
+ - Recursive project discovery for layouts, middleware, server middleware, plugins, API routes, and config.
990
+ - Plugin order and client/server mode filtering.
991
+ - Route middleware execution for SSR and client navigation.
992
+ - Extended route-rule serialization.
993
+ - Client resume behavior after interaction.