@gyral/core 0.3.0 → 0.3.2

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 (386) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/NOTICE +19 -0
  3. package/README.md +36 -8
  4. package/dist/call.d.ts +32 -0
  5. package/dist/call.js +63 -0
  6. package/dist/call.js.map +1 -0
  7. package/dist/children.d.ts +25 -3
  8. package/dist/children.js +18 -1
  9. package/dist/children.js.map +1 -1
  10. package/dist/cli/gyral-types.d.ts +2 -0
  11. package/dist/cli/gyral-types.js +23 -0
  12. package/dist/cli/gyral-types.js.map +1 -0
  13. package/dist/command.d.ts +54 -12
  14. package/dist/command.js +25 -11
  15. package/dist/command.js.map +1 -1
  16. package/dist/compiler/ast.d.ts +2 -0
  17. package/dist/compiler/ast.js +5 -1
  18. package/dist/compiler/ast.js.map +1 -1
  19. package/dist/compiler/compile.d.ts +5 -2
  20. package/dist/compiler/compile.js +36 -17
  21. package/dist/compiler/compile.js.map +1 -1
  22. package/dist/compiler/component-entries.d.ts +7 -0
  23. package/dist/compiler/component-entries.js +42 -0
  24. package/dist/compiler/component-entries.js.map +1 -0
  25. package/dist/compiler/components.d.ts +4 -0
  26. package/dist/compiler/components.js +190 -0
  27. package/dist/compiler/components.js.map +1 -0
  28. package/dist/compiler/facts.d.ts +31 -0
  29. package/dist/compiler/facts.js +285 -0
  30. package/dist/compiler/facts.js.map +1 -0
  31. package/dist/compiler/features.d.ts +34 -0
  32. package/dist/compiler/features.js +158 -0
  33. package/dist/compiler/features.js.map +1 -0
  34. package/dist/compiler/hooks.d.ts +4 -0
  35. package/dist/compiler/hooks.js +144 -89
  36. package/dist/compiler/hooks.js.map +1 -1
  37. package/dist/compiler/loader-source.d.ts +14 -0
  38. package/dist/compiler/loader-source.js +86 -0
  39. package/dist/compiler/loader-source.js.map +1 -0
  40. package/dist/compiler/locate.d.ts +14 -0
  41. package/dist/compiler/locate.js +90 -0
  42. package/dist/compiler/locate.js.map +1 -0
  43. package/dist/compiler/parse5-check.d.ts +1 -1
  44. package/dist/compiler/parse5-check.js +8 -3
  45. package/dist/compiler/parse5-check.js.map +1 -1
  46. package/dist/compiler/prop-schemas.d.ts +4 -0
  47. package/dist/compiler/prop-schemas.js +108 -0
  48. package/dist/compiler/prop-schemas.js.map +1 -0
  49. package/dist/compiler/scan.d.ts +13 -3
  50. package/dist/compiler/scan.js +21 -13
  51. package/dist/compiler/scan.js.map +1 -1
  52. package/dist/compiler/scope.d.ts +8 -0
  53. package/dist/compiler/scope.js +116 -0
  54. package/dist/compiler/scope.js.map +1 -0
  55. package/dist/compiler/tag-map.d.ts +41 -0
  56. package/dist/compiler/tag-map.js +126 -0
  57. package/dist/compiler/tag-map.js.map +1 -0
  58. package/dist/components-ready.d.ts +7 -0
  59. package/dist/components-ready.js +19 -0
  60. package/dist/components-ready.js.map +1 -0
  61. package/dist/define.d.ts +12 -4
  62. package/dist/define.js +8 -12
  63. package/dist/define.js.map +1 -1
  64. package/dist/devtools-events.d.ts +8 -0
  65. package/dist/devtools-events.js.map +1 -1
  66. package/dist/devtools-off.d.ts +1 -0
  67. package/dist/devtools-off.js +1 -0
  68. package/dist/devtools-off.js.map +1 -1
  69. package/dist/devtools.d.ts +3 -0
  70. package/dist/devtools.js +14 -0
  71. package/dist/devtools.js.map +1 -1
  72. package/dist/drivers-scope.js.map +1 -1
  73. package/dist/element-internals.d.ts +1 -0
  74. package/dist/element-internals.js +11 -0
  75. package/dist/element-internals.js.map +1 -0
  76. package/dist/element-types.d.ts +7 -4
  77. package/dist/element-types.js.map +1 -1
  78. package/dist/element.js +80 -27
  79. package/dist/element.js.map +1 -1
  80. package/dist/error-view.d.ts +10 -0
  81. package/dist/error-view.js +30 -0
  82. package/dist/error-view.js.map +1 -0
  83. package/dist/errors.d.ts +21 -0
  84. package/dist/errors.js +47 -0
  85. package/dist/errors.js.map +1 -0
  86. package/dist/errors.json +289 -0
  87. package/dist/eslint/imports.d.ts +2 -0
  88. package/dist/eslint/imports.js +2 -2
  89. package/dist/eslint/imports.js.map +1 -1
  90. package/dist/eslint/index.d.ts +2 -1
  91. package/dist/eslint/index.js +11 -3
  92. package/dist/eslint/index.js.map +1 -1
  93. package/dist/eslint/template-rule.d.ts +1 -0
  94. package/dist/eslint/template-rule.js +15 -5
  95. package/dist/eslint/template-rule.js.map +1 -1
  96. package/dist/eslint/unused-intent-rule.d.ts +2 -0
  97. package/dist/eslint/unused-intent-rule.js +186 -0
  98. package/dist/eslint/unused-intent-rule.js.map +1 -0
  99. package/dist/features.d.ts +2 -2
  100. package/dist/features.js.map +1 -1
  101. package/dist/focus.d.ts +6 -0
  102. package/dist/focus.js +32 -2
  103. package/dist/focus.js.map +1 -1
  104. package/dist/form-associated.d.ts +46 -0
  105. package/dist/form-associated.js +77 -0
  106. package/dist/form-associated.js.map +1 -0
  107. package/dist/forms.d.ts +42 -30
  108. package/dist/forms.js +85 -41
  109. package/dist/forms.js.map +1 -1
  110. package/dist/frame-lane.d.ts +11 -0
  111. package/dist/frame-lane.js +28 -0
  112. package/dist/frame-lane.js.map +1 -0
  113. package/dist/head.d.ts +61 -0
  114. package/dist/head.js +85 -0
  115. package/dist/head.js.map +1 -0
  116. package/dist/host-model.d.ts +34 -5
  117. package/dist/host-model.js +146 -23
  118. package/dist/host-model.js.map +1 -1
  119. package/dist/hydration-client.js +2 -2
  120. package/dist/hydration-client.js.map +1 -1
  121. package/dist/hydration-loader.d.ts +13 -0
  122. package/dist/hydration-loader.js +58 -0
  123. package/dist/hydration-loader.js.map +1 -0
  124. package/dist/hydration-off.d.ts +8 -0
  125. package/dist/hydration-off.js +25 -0
  126. package/dist/hydration-off.js.map +1 -0
  127. package/dist/hydration.d.ts +0 -12
  128. package/dist/hydration.js +3 -52
  129. package/dist/hydration.js.map +1 -1
  130. package/dist/index.d.ts +21 -24
  131. package/dist/index.js +10 -19
  132. package/dist/index.js.map +1 -1
  133. package/dist/indexeddb-types.d.ts +97 -0
  134. package/dist/indexeddb-types.js +2 -0
  135. package/dist/indexeddb-types.js.map +1 -0
  136. package/dist/indexeddb.d.ts +5 -0
  137. package/dist/indexeddb.js +118 -0
  138. package/dist/indexeddb.js.map +1 -0
  139. package/dist/intent.d.ts +42 -20
  140. package/dist/intent.js +145 -107
  141. package/dist/intent.js.map +1 -1
  142. package/dist/internal/indexeddb-open.d.ts +8 -0
  143. package/dist/internal/indexeddb-open.js +96 -0
  144. package/dist/internal/indexeddb-open.js.map +1 -0
  145. package/dist/internal/indexeddb-transaction.d.ts +4 -0
  146. package/dist/internal/indexeddb-transaction.js +134 -0
  147. package/dist/internal/indexeddb-transaction.js.map +1 -0
  148. package/dist/internal/interpreter.d.ts +12 -4
  149. package/dist/internal/interpreter.js +36 -48
  150. package/dist/internal/interpreter.js.map +1 -1
  151. package/dist/internal/token.d.ts +1 -0
  152. package/dist/internal/token.js +7 -0
  153. package/dist/internal/token.js.map +1 -0
  154. package/dist/internal.d.ts +20 -0
  155. package/dist/internal.js +22 -0
  156. package/dist/internal.js.map +1 -0
  157. package/dist/invoker-fallback-used.d.ts +4 -0
  158. package/dist/invoker-fallback-used.js +10 -0
  159. package/dist/invoker-fallback-used.js.map +1 -0
  160. package/dist/invoker-fallback.d.ts +4 -0
  161. package/dist/invoker-fallback.js +15 -0
  162. package/dist/invoker-fallback.js.map +1 -0
  163. package/dist/light-dom.d.ts +1 -1
  164. package/dist/light-dom.js.map +1 -1
  165. package/dist/prop.d.ts +30 -7
  166. package/dist/prop.js +19 -0
  167. package/dist/prop.js.map +1 -1
  168. package/dist/props.d.ts +8 -3
  169. package/dist/props.js +22 -15
  170. package/dist/props.js.map +1 -1
  171. package/dist/retry.d.ts +15 -0
  172. package/dist/retry.js +48 -0
  173. package/dist/retry.js.map +1 -0
  174. package/dist/scheduler.d.ts +7 -3
  175. package/dist/scheduler.js +38 -56
  176. package/dist/scheduler.js.map +1 -1
  177. package/dist/script-json.d.ts +2 -0
  178. package/dist/script-json.js +13 -0
  179. package/dist/script-json.js.map +1 -0
  180. package/dist/server-component.d.ts +1 -1
  181. package/dist/server-component.js +45 -14
  182. package/dist/server-component.js.map +1 -1
  183. package/dist/server.d.ts +9 -3
  184. package/dist/server.js +12 -3
  185. package/dist/server.js.map +1 -1
  186. package/dist/settled.d.ts +4 -3
  187. package/dist/settled.js +48 -26
  188. package/dist/settled.js.map +1 -1
  189. package/dist/spec-features-used.d.ts +21 -0
  190. package/dist/spec-features-used.js +50 -0
  191. package/dist/spec-features-used.js.map +1 -0
  192. package/dist/spec-features.d.ts +28 -0
  193. package/dist/spec-features.js +42 -0
  194. package/dist/spec-features.js.map +1 -0
  195. package/dist/states.d.ts +3 -5
  196. package/dist/states.js +22 -8
  197. package/dist/states.js.map +1 -1
  198. package/dist/storage.d.ts +69 -0
  199. package/dist/storage.js +158 -0
  200. package/dist/storage.js.map +1 -0
  201. package/dist/store-binding.js +2 -2
  202. package/dist/store-binding.js.map +1 -1
  203. package/dist/store-scope.d.ts +2 -4
  204. package/dist/store-scope.js +6 -16
  205. package/dist/store-scope.js.map +1 -1
  206. package/dist/store.d.ts +2 -6
  207. package/dist/store.js +36 -8
  208. package/dist/store.js.map +1 -1
  209. package/dist/subscription.d.ts +35 -0
  210. package/dist/subscription.js +74 -0
  211. package/dist/subscription.js.map +1 -0
  212. package/dist/subscriptions.d.ts +26 -0
  213. package/dist/subscriptions.js +98 -0
  214. package/dist/subscriptions.js.map +1 -0
  215. package/dist/transitions.d.ts +4 -5
  216. package/dist/transitions.js +10 -4
  217. package/dist/transitions.js.map +1 -1
  218. package/dist/types.d.ts +141 -32
  219. package/dist/types.js.map +1 -1
  220. package/dist/use-dialogs.d.ts +2 -0
  221. package/dist/use-dialogs.js +9 -0
  222. package/dist/use-dialogs.js.map +1 -0
  223. package/dist/use-disposal.d.ts +2 -0
  224. package/dist/use-disposal.js +9 -0
  225. package/dist/use-disposal.js.map +1 -0
  226. package/dist/use-error-view.d.ts +2 -0
  227. package/dist/use-error-view.js +9 -0
  228. package/dist/use-error-view.js.map +1 -0
  229. package/dist/use-errored.d.ts +2 -0
  230. package/dist/use-errored.js +9 -0
  231. package/dist/use-errored.js.map +1 -0
  232. package/dist/use-form-associated.d.ts +2 -0
  233. package/dist/use-form-associated.js +7 -0
  234. package/dist/use-form-associated.js.map +1 -0
  235. package/dist/use-frame-lane.d.ts +2 -0
  236. package/dist/use-frame-lane.js +10 -0
  237. package/dist/use-frame-lane.js.map +1 -0
  238. package/dist/use-invokers.d.ts +2 -0
  239. package/dist/use-invokers.js +10 -0
  240. package/dist/use-invokers.js.map +1 -0
  241. package/dist/use-states.d.ts +2 -0
  242. package/dist/use-states.js +10 -0
  243. package/dist/use-states.js.map +1 -0
  244. package/dist/use-subscriptions.d.ts +2 -0
  245. package/dist/use-subscriptions.js +10 -0
  246. package/dist/use-subscriptions.js.map +1 -0
  247. package/dist/use-transitions.d.ts +2 -0
  248. package/dist/use-transitions.js +10 -0
  249. package/dist/use-transitions.js.map +1 -0
  250. package/dist/view/attributes.d.ts +5 -0
  251. package/dist/view/attributes.js +5 -0
  252. package/dist/view/attributes.js.map +1 -1
  253. package/dist/view/compiled.d.ts +1 -1
  254. package/dist/view/compiled.js +1 -1
  255. package/dist/view/compiled.js.map +1 -1
  256. package/dist/view/index.d.ts +9 -4
  257. package/dist/view/index.js +9 -3
  258. package/dist/view/index.js.map +1 -1
  259. package/dist/view/loc.d.ts +9 -0
  260. package/dist/view/loc.js +50 -0
  261. package/dist/view/loc.js.map +1 -0
  262. package/dist/view/message.d.ts +17 -0
  263. package/dist/view/message.js +40 -0
  264. package/dist/view/message.js.map +1 -0
  265. package/dist/view/messages.d.ts +43 -0
  266. package/dist/view/messages.js +84 -0
  267. package/dist/view/messages.js.map +1 -0
  268. package/dist/view/normalize/check.d.ts +5 -2
  269. package/dist/view/normalize/check.js +6 -3
  270. package/dist/view/normalize/check.js.map +1 -1
  271. package/dist/view/normalize/emit.d.ts +2 -0
  272. package/dist/view/normalize/emit.js +40 -11
  273. package/dist/view/normalize/emit.js.map +1 -1
  274. package/dist/view/normalize/errors.js +1 -1
  275. package/dist/view/normalize/errors.js.map +1 -1
  276. package/dist/view/normalize/id.d.ts +5 -2
  277. package/dist/view/normalize/id.js +9 -2
  278. package/dist/view/normalize/id.js.map +1 -1
  279. package/dist/view/normalize/normalize.d.ts +7 -4
  280. package/dist/view/normalize/normalize.js +15 -9
  281. package/dist/view/normalize/normalize.js.map +1 -1
  282. package/dist/view/normalize/rules.d.ts +9 -0
  283. package/dist/view/normalize/rules.js +35 -5
  284. package/dist/view/normalize/rules.js.map +1 -1
  285. package/dist/view/normalize/svg.d.ts +14 -0
  286. package/dist/view/normalize/svg.js +40 -0
  287. package/dist/view/normalize/svg.js.map +1 -0
  288. package/dist/view/normalize/tokens.d.ts +5 -1
  289. package/dist/view/normalize/tokens.js.map +1 -1
  290. package/dist/view/normalize/tree.d.ts +8 -2
  291. package/dist/view/normalize/tree.js +58 -13
  292. package/dist/view/normalize/tree.js.map +1 -1
  293. package/dist/view/normalize/types.d.ts +24 -4
  294. package/dist/view/normalize/types.js +4 -1
  295. package/dist/view/normalize/types.js.map +1 -1
  296. package/dist/view/normalize/whitespace.js +4 -3
  297. package/dist/view/normalize/whitespace.js.map +1 -1
  298. package/dist/view/prepare-stub.js +2 -2
  299. package/dist/view/prepare-stub.js.map +1 -1
  300. package/dist/view/prepare.d.ts +5 -2
  301. package/dist/view/prepare.js +9 -3
  302. package/dist/view/prepare.js.map +1 -1
  303. package/dist/view/registry.d.ts +15 -0
  304. package/dist/view/registry.js +10 -2
  305. package/dist/view/registry.js.map +1 -1
  306. package/dist/view/render/adopt-attr.js +7 -1
  307. package/dist/view/render/adopt-attr.js.map +1 -1
  308. package/dist/view/render/adopt.js +21 -4
  309. package/dist/view/render/adopt.js.map +1 -1
  310. package/dist/view/render/attr-parts.d.ts +12 -1
  311. package/dist/view/render/attr-parts.js +38 -5
  312. package/dist/view/render/attr-parts.js.map +1 -1
  313. package/dist/view/render/child-part.js +5 -2
  314. package/dist/view/render/child-part.js.map +1 -1
  315. package/dist/view/render/dispose.d.ts +3 -0
  316. package/dist/view/render/dispose.js +76 -0
  317. package/dist/view/render/dispose.js.map +1 -0
  318. package/dist/view/render/hook-part.d.ts +3 -1
  319. package/dist/view/render/hook-part.js +21 -5
  320. package/dist/view/render/hook-part.js.map +1 -1
  321. package/dist/view/render/hook-run.d.ts +2 -0
  322. package/dist/view/render/hook-run.js +72 -0
  323. package/dist/view/render/hook-run.js.map +1 -0
  324. package/dist/view/render/hooks.d.ts +74 -6
  325. package/dist/view/render/hooks.js +79 -17
  326. package/dist/view/render/hooks.js.map +1 -1
  327. package/dist/view/render/hydrate.js +2 -2
  328. package/dist/view/render/hydrate.js.map +1 -1
  329. package/dist/view/render/keyed.d.ts +6 -0
  330. package/dist/view/render/keyed.js +15 -0
  331. package/dist/view/render/keyed.js.map +1 -0
  332. package/dist/view/render/list.d.ts +1 -1
  333. package/dist/view/render/list.js.map +1 -1
  334. package/dist/view/render/mismatch.js +5 -3
  335. package/dist/view/render/mismatch.js.map +1 -1
  336. package/dist/view/render/modal.d.ts +3 -0
  337. package/dist/view/render/modal.js +39 -0
  338. package/dist/view/render/modal.js.map +1 -0
  339. package/dist/view/render/raw.d.ts +4 -1
  340. package/dist/view/render/raw.js +6 -2
  341. package/dist/view/render/raw.js.map +1 -1
  342. package/dist/view/render/render.d.ts +4 -1
  343. package/dist/view/render/render.js +17 -12
  344. package/dist/view/render/render.js.map +1 -1
  345. package/dist/view/render/toggles.d.ts +6 -0
  346. package/dist/view/render/toggles.js +6 -0
  347. package/dist/view/render/toggles.js.map +1 -0
  348. package/dist/view/render/values.d.ts +1 -1
  349. package/dist/view/render/values.js.map +1 -1
  350. package/dist/view/render/warn.d.ts +14 -0
  351. package/dist/view/render/warn.js +45 -0
  352. package/dist/view/render/warn.js.map +1 -1
  353. package/dist/view/server/component.d.ts +6 -3
  354. package/dist/view/server/component.js +29 -7
  355. package/dist/view/server/component.js.map +1 -1
  356. package/dist/view/server/index.d.ts +20 -0
  357. package/dist/view/server/index.js +12 -4
  358. package/dist/view/server/index.js.map +1 -1
  359. package/dist/view/server/tags.d.ts +13 -2
  360. package/dist/view/server/tags.js +13 -2
  361. package/dist/view/server/tags.js.map +1 -1
  362. package/dist/view/server/values.d.ts +2 -0
  363. package/dist/view/server/values.js +8 -0
  364. package/dist/view/server/values.js.map +1 -1
  365. package/dist/view/server/writer.d.ts +9 -4
  366. package/dist/view/server/writer.js +33 -18
  367. package/dist/view/server/writer.js.map +1 -1
  368. package/dist/view/template-element.d.ts +7 -0
  369. package/dist/view/template-element.js +25 -5
  370. package/dist/view/template-element.js.map +1 -1
  371. package/dist/view/template.d.ts +9 -2
  372. package/dist/view/template.js +61 -8
  373. package/dist/view/template.js.map +1 -1
  374. package/dist/view/trusted-html.d.ts +6 -0
  375. package/dist/view/trusted-html.js +34 -0
  376. package/dist/view/trusted-html.js.map +1 -0
  377. package/dist/vite.d.ts +38 -31
  378. package/dist/vite.js +206 -31
  379. package/dist/vite.js.map +1 -1
  380. package/package.json +34 -3
  381. package/dist/hooks/labelled-by.d.ts +0 -13
  382. package/dist/hooks/labelled-by.js +0 -51
  383. package/dist/hooks/labelled-by.js.map +0 -1
  384. package/dist/random.d.ts +0 -13
  385. package/dist/random.js +0 -19
  386. package/dist/random.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"template.js","sourceRoot":"","sources":["../../src/view/template.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,8FAA8F;AAC9F,6FAA6F;AAC7F,8FAA8F;AAC9F,yFAAyF;AACzF,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAGnC,MAAM,MAAM,GAAkB,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAQvD,sDAAsD;AACtD,MAAM,UAAU,IAAI,CAAC,OAA6B,EAAE,GAAG,MAAiB;IACtE,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AACvC,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,QAAQ,CAAC,QAAwB,EAAE,MAA0B;IAC3E,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK,CAAC;AACxE,CAAC;AAED,yFAAyF;AACzF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,MAAsB,EAAsC,EAAE,CACrF,MAAM,CAAC,MAAM,CAAC,CAAC;AAEjB;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,MAAsB;IAC/C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC9B,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAE,MAAyB,CAAC;AAC9E,CAAC","sourcesContent":["// Template results and the `html` tag (view/01-templates.md \"Authoring\", \"Template results\").\n// A result is a template source (the call site's strings, or a compiled template object) plus\n// this call's values, recognised by a module-private symbol so data from JSON can never pass\n// for one. `templateOf` turns the source into the template object: compiled results carry it,\n// runtime results are normalized once per strings array through `#prepare` (prepare.ts).\nimport { prepare } from '#prepare';\nimport type { TemplateObject } from './normalize/types.js';\n\nconst SOURCE: unique symbol = Symbol('gyral.template');\n\n/** What `html` returns: a template plus this render's values. */\nexport interface TemplateResult {\n readonly [SOURCE]: readonly string[] | TemplateObject;\n readonly values: readonly unknown[];\n}\n\n/** The template tag: `` html`<p>${s.text}</p>` ``. */\nexport function html(strings: TemplateStringsArray, ...values: unknown[]): TemplateResult {\n return { [SOURCE]: strings, values };\n}\n\n/** Internal: what the template compiler (Phase 6) rewrites `html` calls into. */\nexport function compiled(template: TemplateObject, values: readonly unknown[]): TemplateResult {\n return { [SOURCE]: template, values };\n}\n\nexport function isTemplateResult(value: unknown): value is TemplateResult {\n return typeof value === 'object' && value !== null && SOURCE in value;\n}\n\n/** Internal: a result's source, compared by identity to skip `templateOf` on updates. */\nexport const sourceOf = (result: TemplateResult): readonly string[] | TemplateObject =>\n result[SOURCE];\n\n/**\n * The template object of a result: compiled results carry it; a runtime result's call site is\n * normalized once by `#prepare` (cached there, so compiled builds carry neither the preparer\n * nor its cache).\n */\nexport function templateOf(result: TemplateResult): TemplateObject {\n const source = result[SOURCE];\n return Array.isArray(source) ? prepare(source) : (source as TemplateObject);\n}\n"]}
1
+ {"version":3,"file":"template.js","sourceRoot":"","sources":["../../src/view/template.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,2FAA2F;AAC3F,+FAA+F;AAC/F,gGAAgG;AAChG,uFAAuF;AACvF,6FAA6F;AAC7F,kBAAkB;AAClB,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,MAAM,MAAM,GAAkB,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAQvD,oDAAoD;AACpD,SAAS,GAAG,CAAC,OAA6B,EAAE,GAAG,MAAiB;IAC9D,yFAAyF;IACzF,IAAI,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,SAAS;QAAE,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IACtF,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AACvC,CAAC;AAED,2FAA2F;AAC3F,SAAS,MAAM,CAAC,OAA6B,EAAE,GAAG,MAAiB;IACjE,2FAA2F;IAC3F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,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AACxC,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,WAAW,CAAC,QAAwB,EAAE,MAA0B;IAC9E,WAAW,CAAC,QAAQ,CAAC,CAAC;IACtB,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK,CAAC;AACxE,CAAC;AAED,yFAAyF;AACzF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,MAAsB,EAAsC,EAAE,CACrF,MAAM,CAAC,MAAM,CAAC,CAAC;AAEjB;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,MAAsB;IAC/C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC9B,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAE,MAAyB,CAAC;AAC9E,CAAC","sourcesContent":["// Template results and the `html` and `svg` tags (view/01-templates.md \"Authoring\", \"Template\n// results\", \"svg templates\"). A result is a template source (the call site's strings, or a\n// template object) plus this call's values, recognised by a module-private symbol so data from\n// JSON can never pass for one. `templateOf` turns the source into the template object: compiled\n// and svg results carry it, html results are normalized once per strings array through\n// `#prepare` (prepare.ts). Development records each call site's source location (loc.ts) for\n// error messages.\nimport { prepare } from '#prepare';\nimport { DEV } from '#view-dev';\nimport { callSite, locOf, setLoc } from './loc.js';\nimport type { TemplateObject } from './normalize/types.js';\nimport { svgTemplate } from './template-element.js';\n\nconst SOURCE: unique symbol = Symbol('gyral.template');\n\n/** What `html` returns: a template plus this render's values. */\nexport interface TemplateResult {\n readonly [SOURCE]: readonly string[] | TemplateObject;\n readonly values: readonly unknown[];\n}\n\n/** The template tag, as `html` is in production. */\nfunction tag(strings: TemplateStringsArray, ...values: unknown[]): TemplateResult {\n // Development: the call site, from the stack, the first time (unless `html.at` gave it).\n if (DEV && locOf(strings) === undefined) setLoc(strings, callSite(new Error().stack));\n return { [SOURCE]: strings, values };\n}\n\n/** The svg tag, as `svg` is in production: svg results carry their (prepared) template. */\nfunction svgTag(strings: TemplateStringsArray, ...values: unknown[]): TemplateResult {\n // Development: the call site, from the stack, the first time (unless `svg.at` gave it), so\n // the normalizer's rule errors name it.\n if (DEV && locOf(strings) === undefined) setLoc(strings, callSite(new Error().stack));\n return compiledSvg(prepare(strings, true), values);\n}\n\ntype Tag = typeof tag;\n\n/**\n * Development: `html.at(loc)` (and `svg.at(loc)`) is the tag with a known call site. The Vite\n * preset's dev transform (compiler/locate.ts) writes it at every call site, since stack\n * positions in transformed modules aren't the author's lines. Attached here, not by a statement\n * that mentions the tag, so production builds don't keep it alive (the compiler checks that).\n */\nfunction withAt(html: Tag): Tag {\n const tags = new Map<string, Tag>();\n const at = (loc: string): Tag => {\n let located = tags.get(loc);\n if (located === undefined) {\n located = (strings, ...values) => {\n setLoc(strings, loc);\n return html(strings, ...values);\n };\n tags.set(loc, located);\n }\n return located;\n };\n return Object.assign(html, { at });\n}\n\n/** The template tag: `` html`<p>${s.text}</p>` ``. */\nexport const html: (strings: TemplateStringsArray, ...values: unknown[]) => TemplateResult = DEV\n ? withAt(tag)\n : tag;\n\n/**\n * The SVG fragment tag: `` svg`<path d=${s.d} />` ``. Its top level is SVG content, so it\n * renders only inside an `<svg>` (or another SVG element) of an html template. A whole `<svg>` graphic is written with html.\n */\nexport const svg: (strings: TemplateStringsArray, ...values: unknown[]) => TemplateResult = DEV\n ? withAt(svgTag)\n : svgTag;\n\n/** Internal: what the template compiler (`@gyral/core/vite`) rewrites `html` calls into. */\nexport function compiled(template: TemplateObject, values: readonly unknown[]): TemplateResult {\n return { [SOURCE]: template, values };\n}\n\n/** Internal: what the template compiler rewrites `svg` calls into. */\nexport function compiledSvg(template: TemplateObject, values: readonly unknown[]): TemplateResult {\n svgTemplate(template);\n return { [SOURCE]: template, values };\n}\n\nexport function isTemplateResult(value: unknown): value is TemplateResult {\n return typeof value === 'object' && value !== null && SOURCE in value;\n}\n\n/** Internal: a result's source, compared by identity to skip `templateOf` on updates. */\nexport const sourceOf = (result: TemplateResult): readonly string[] | TemplateObject =>\n result[SOURCE];\n\n/**\n * The template object of a result: compiled results carry it; a runtime result's call site is\n * normalized once by `#prepare` (cached there, so compiled builds carry neither the preparer\n * nor its cache).\n */\nexport function templateOf(result: TemplateResult): TemplateObject {\n const source = result[SOURCE];\n return Array.isArray(source) ? prepare(source) : (source as TemplateObject);\n}\n"]}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * `html` as an HTML sink accepts it: a `TrustedHTML` from the `gyral` policy where the browser
3
+ * has Trusted Types, the string itself elsewhere. Typed as `string` because lib.dom's
4
+ * `innerHTML` setter takes only strings; the browser stringifies a `TrustedHTML` to the same text.
5
+ */
6
+ export declare function trustedHTML(html: string): string;
@@ -0,0 +1,34 @@
1
+ // Trusted Types (view/01-templates.md "Instantiation", gyral-ei9): a document whose CSP says
2
+ // `require-trusted-types-for 'script'` refuses plain strings at HTML sinks such as `innerHTML`.
3
+ // The browser parses only two kinds of HTML for Gyral: a template's HTML, which is the author's
4
+ // own template strings (holes are markers, never values), and `raw()` markup, trusted by
5
+ // contract (view/02 "raw(html)"). Both go through one policy named `gyral`, created on first use
6
+ // where the browser has Trusted Types; an app allows it with `trusted-types gyral`. On first use
7
+ // rather than at import, so a policy that refuses the name fails where HTML is parsed, not when
8
+ // a module loads. A CSP whose `trusted-types` list leaves `gyral` out (with or without
9
+ // enforcement) makes `createPolicy` throw: Gyral then parses plain strings, as before Trusted
10
+ // Types, and warns in development; where Trusted Types are enforced the sink reports it.
11
+ import { DEV } from '#view-dev';
12
+ import { message } from './message.js';
13
+ const passThrough = { createHTML: (input) => input };
14
+ let policy;
15
+ /**
16
+ * `html` as an HTML sink accepts it: a `TrustedHTML` from the `gyral` policy where the browser
17
+ * has Trusted Types, the string itself elsewhere. Typed as `string` because lib.dom's
18
+ * `innerHTML` setter takes only strings; the browser stringifies a `TrustedHTML` to the same text.
19
+ */
20
+ export function trustedHTML(html) {
21
+ policy ??= create();
22
+ return policy.createHTML(html);
23
+ }
24
+ function create() {
25
+ try {
26
+ return (globalThis.trustedTypes?.createPolicy('gyral', passThrough) ?? passThrough);
27
+ }
28
+ catch (error) {
29
+ if (DEV)
30
+ console.warn(message(72), error);
31
+ return passThrough;
32
+ }
33
+ }
34
+ //# sourceMappingURL=trusted-html.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trusted-html.js","sourceRoot":"","sources":["../../src/view/trusted-html.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,gGAAgG;AAChG,gGAAgG;AAChG,yFAAyF;AACzF,iGAAiG;AACjG,iGAAiG;AACjG,gGAAgG;AAChG,uFAAuF;AACvF,8FAA8F;AAC9F,yFAAyF;AACzF,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAUvC,MAAM,WAAW,GAAW,EAAE,UAAU,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC;AAE7D,IAAI,MAA0B,CAAC;AAE/B;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,MAAM,KAAK,MAAM,EAAE,CAAC;IACpB,OAAO,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;AACjC,CAAC;AAED,SAAS,MAAM;IACb,IAAI,CAAC;QACH,OAAO,CACJ,UAA+C,CAAC,YAAY,EAAE,YAAY,CACzE,OAAO,EACP,WAAW,CACZ,IAAI,WAAW,CACjB,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,GAAG;YAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;QAC1C,OAAO,WAAW,CAAC;IACrB,CAAC;AACH,CAAC","sourcesContent":["// Trusted Types (view/01-templates.md \"Instantiation\", gyral-ei9): a document whose CSP says\n// `require-trusted-types-for 'script'` refuses plain strings at HTML sinks such as `innerHTML`.\n// The browser parses only two kinds of HTML for Gyral: a template's HTML, which is the author's\n// own template strings (holes are markers, never values), and `raw()` markup, trusted by\n// contract (view/02 \"raw(html)\"). Both go through one policy named `gyral`, created on first use\n// where the browser has Trusted Types; an app allows it with `trusted-types gyral`. On first use\n// rather than at import, so a policy that refuses the name fails where HTML is parsed, not when\n// a module loads. A CSP whose `trusted-types` list leaves `gyral` out (with or without\n// enforcement) makes `createPolicy` throw: Gyral then parses plain strings, as before Trusted\n// Types, and warns in development; where Trusted Types are enforced the sink reports it.\nimport { DEV } from '#view-dev';\nimport { message } from './message.js';\n\ninterface Policy {\n createHTML(input: string): string;\n}\n\ninterface PolicyFactory {\n createPolicy(name: string, rules: Policy): Policy;\n}\n\nconst passThrough: Policy = { createHTML: (input) => input };\n\nlet policy: Policy | undefined;\n\n/**\n * `html` as an HTML sink accepts it: a `TrustedHTML` from the `gyral` policy where the browser\n * has Trusted Types, the string itself elsewhere. Typed as `string` because lib.dom's\n * `innerHTML` setter takes only strings; the browser stringifies a `TrustedHTML` to the same text.\n */\nexport function trustedHTML(html: string): string {\n policy ??= create();\n return policy.createHTML(html);\n}\n\nfunction create(): Policy {\n try {\n return (\n (globalThis as { trustedTypes?: PolicyFactory }).trustedTypes?.createPolicy(\n 'gyral',\n passThrough,\n ) ?? passThrough\n );\n } catch (error) {\n if (DEV) console.warn(message(72), error);\n return passThrough;\n }\n}\n"]}
package/dist/vite.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import type { Plugin } from 'vite';
2
2
  export interface TemplateCompilerOptions {
3
3
  /**
4
- * Module specifiers whose `html` export is the view layer's tag (default
4
+ * Module specifiers whose `html` (and `svg`) exports are the view layer's tags (default
5
5
  * `DEFAULT_TEMPLATE_SOURCES`). An import matches when its specifier is listed, or when it
6
6
  * resolves to the same module as a listed one; core's own view modules always match. A
7
- * source other than '@gyral/core' must also export `compiled`.
7
+ * source other than '@gyral/core' must also export `compiled` (and `compiledSvg` when it
8
+ * exports `svg`).
8
9
  */
9
10
  readonly sources?: readonly string[];
10
11
  /**
@@ -13,43 +14,49 @@ export interface TemplateCompilerOptions {
13
14
  */
14
15
  readonly parse5?: boolean | string;
15
16
  }
16
- /** Where the view layer's `html` comes from: core's main entry (ADR 0018, Phase 3). */
17
- export declare const DEFAULT_TEMPLATE_SOURCES: readonly string[];
18
- /** The resolve condition that maps core's `#prepare` to its stub (ADR 0017's mechanism). */
19
- export declare const COMPILED_CONDITION = "gyral-compiled";
20
- /** Vite 8's default resolve conditions (`defaultClientConditions`, server ones without browser). */
21
- export declare const CLIENT_CONDITIONS: readonly string[];
22
- export declare const SERVER_CONDITIONS: readonly string[];
23
- /** The template compiler alone (`gyralVitePreset()` includes it). */
24
- export declare function gyralTemplateCompiler(options?: TemplateCompilerOptions): Plugin;
25
- /** Gyral's packages: the dev server runs them through Vite, never Node (view/06). */
26
- export declare const GYRAL_PACKAGES: RegExp;
27
- /**
28
- * The app's direct dependencies that depend on a Gyral package (a design system, say). They
29
- * import @gyral/core, so they must share the copy the dev server runs.
30
- */
31
- export declare function gyralDependents(root: string): string[];
32
- /**
33
- * Development output from the dev server's SSR (`ssrLoadModule`, view/06 "Development
34
- * markers"). Vite externalizes installed packages there and Node imports them itself, resolving
35
- * core's `#view-dev` without the `development` condition (Vite's `externalConditions` only pick
36
- * the entry file, not the package's own imports), so the server rendered production output.
37
- * In serve mode this plugin keeps Gyral's packages, and the app's dependencies that use them,
38
- * out of externalization in server environments: Vite resolves them with its conditions
39
- * (`development` in dev), and they all share one copy of core. `vite build` is unaffected.
40
- */
41
- export declare function gyralDevServer(): Plugin;
17
+ /** Where the preset looks for components and writes their typings. */
18
+ export interface ElementTypesOptions {
19
+ /** Source directories to scan, relative to the Vite root. Default `['src']`. */
20
+ readonly dirs?: readonly string[];
21
+ /** The declaration file to write, relative to the Vite root. Default `.gyral/elements.d.ts`. */
22
+ readonly out?: string;
23
+ }
42
24
  export interface GyralViteOptions {
25
+ /**
26
+ * Generated element typings (`.gyral/elements.d.ts`, see `ElementTypesOptions`), or `false`
27
+ * to write none. Default: on, scanning `src`.
28
+ */
29
+ readonly types?: ElementTypesOptions | false;
43
30
  /** Modules to pre-bundle in dev, so Vite doesn't discover them mid-run and reload. */
44
31
  readonly optimize?: readonly string[];
45
32
  /** Template compiler options (`vite build` only). */
46
33
  readonly compiler?: TemplateCompilerOptions;
34
+ /**
35
+ * The app is never server-rendered: leave the hydration code out of the browser bundle
36
+ * (`gyralClientOnly()`). Default false.
37
+ */
38
+ readonly clientOnly?: boolean;
39
+ /**
40
+ * Automatic component loading (ADR 0016 addendum): every component defined under `include`
41
+ * gets a client module the build splits out, and a loader (`virtual:gyral/components`, added
42
+ * to the client build's input) imports a tag's module once that tag is in the page.
43
+ * `renderPage({ components })` then links exactly the components a page rendered, so pages
44
+ * need no client entry of their own and no side-effect imports. Default off.
45
+ */
46
+ readonly components?: boolean | ComponentsOptions;
47
+ }
48
+ export interface ComponentsOptions {
49
+ /** Directories (relative to Vite's root) whose modules' `define()` tags are found. Default `['src']`. */
50
+ readonly include?: readonly string[];
51
+ /**
52
+ * Tag → module (relative to Vite's root) for components the scan can't find: those defined
53
+ * through a wrapper such as `defineMemberForm({ tag: 'member-form' })`, which calls
54
+ * `define()` itself. Listed entries win over scanned ones.
55
+ */
56
+ readonly modules?: Readonly<Record<string, string>>;
47
57
  }
48
58
  export interface GyralViteConfig {
49
59
  readonly plugins: Plugin[];
50
- readonly resolve: {
51
- readonly dedupe: string[];
52
- };
53
60
  readonly optimizeDeps: {
54
61
  readonly include: string[];
55
62
  };
package/dist/vite.js CHANGED
@@ -6,37 +6,42 @@
6
6
  // runner. The compiler is a plugin applied in `vite build` only, so dev servers and test runs
7
7
  // keep the runtime template path; its implementation (./compiler/) loads on the first build
8
8
  // hook, with `require` (Node loads ES modules with it too): a module runner that loaded this
9
- // file may be closed by then, and would reject a dynamic import().
9
+ // file may be closed by then, and would reject a dynamic import(). Public: the preset,
10
+ // gyralTemplateCompiler and gyralClientOnly (docs/references/public-api-0.3.1.md); the other
11
+ // plugins and constants here are internal.
10
12
  import { readFileSync } from 'node:fs';
11
13
  import { createRequire } from 'node:module';
12
14
  import { dirname, join, resolve } from 'node:path';
13
15
  import { fileURLToPath } from 'node:url';
14
16
  /** Where the view layer's `html` comes from: core's main entry (ADR 0018, Phase 3). */
15
- export const DEFAULT_TEMPLATE_SOURCES = ['@gyral/core'];
17
+ const DEFAULT_TEMPLATE_SOURCES = ['@gyral/core'];
16
18
  /** The resolve condition that maps core's `#prepare` to its stub (ADR 0017's mechanism). */
17
- export const COMPILED_CONDITION = 'gyral-compiled';
19
+ const COMPILED_CONDITION = 'gyral-compiled';
20
+ /** The client's resolve condition in client-only builds (view/07 "Client-only builds"). */
21
+ const CLIENT_ONLY_CONDITION = 'gyral-client-only';
18
22
  /** Vite 8's default resolve conditions (`defaultClientConditions`, server ones without browser). */
19
- export const CLIENT_CONDITIONS = ['module', 'browser', 'development|production'];
20
- export const SERVER_CONDITIONS = ['module', 'node', 'development|production'];
23
+ const CLIENT_CONDITIONS = ['module', 'browser', 'development|production'];
24
+ const SERVER_CONDITIONS = ['module', 'node', 'development|production'];
21
25
  /**
22
- * Adds the `gyral-compiled` condition to an environment, on top of the app's conditions or
23
- * Vite's defaults: Vite replaces the defaults when a config names any condition.
26
+ * Adds `condition` (default `gyral-compiled`) to an environment, on top of the app's
27
+ * conditions or Vite's defaults: Vite replaces the defaults when a config names any condition.
28
+ * `clientOnly`: only to environments that build for the browser.
24
29
  */
25
- function addCondition(name, config, env) {
30
+ function addCondition(name, config, env, condition = COMPILED_CONDITION, clientOnly = false) {
26
31
  const consumer = config.consumer ?? (name === 'client' ? 'client' : 'server');
27
32
  const client = consumer === 'client' || env.isSsrTargetWebworker === true;
33
+ if (clientOnly && consumer !== 'client')
34
+ return;
28
35
  const current = config.resolve?.conditions ?? (client ? CLIENT_CONDITIONS : SERVER_CONDITIONS);
29
- if (!current.includes(COMPILED_CONDITION)) {
30
- config.resolve = { ...config.resolve, conditions: [...current, COMPILED_CONDITION] };
36
+ if (!current.includes(condition)) {
37
+ config.resolve = { ...config.resolve, conditions: [...current, condition] };
31
38
  }
32
39
  }
33
- /**
34
- * The compiler's hooks. From core's TypeScript source (this workspace, `link:` checkouts) they
35
- * load through Vite's module runner, as a vite.config.ts would; from the published package,
36
- * with require.
37
- */
38
- async function loadHooks(options) {
39
- const settings = {
40
+ /** The compiled entry of this copy of core, next to this module. */
41
+ const OWN_COMPILED = fileURLToPath(new URL(import.meta.url.endsWith('.ts') ? './view/compiled.ts' : './view/compiled.js', import.meta.url));
42
+ /** The settings both plugins pass to their lazily loaded implementation. */
43
+ function settingsOf(options) {
44
+ return {
40
45
  sources: options.sources ?? DEFAULT_TEMPLATE_SOURCES,
41
46
  parse5: options.parse5 === false
42
47
  ? undefined
@@ -44,21 +49,32 @@ async function loadHooks(options) {
44
49
  ? options.parse5
45
50
  : 'parse5',
46
51
  };
52
+ }
53
+ /**
54
+ * A module of ./compiler/. From core's TypeScript source (this workspace, `link:` checkouts) it
55
+ * loads through Vite's module runner, as a vite.config.ts would; from the published package,
56
+ * with require.
57
+ */
58
+ async function loadCompiler(name) {
47
59
  const require = createRequire(import.meta.url);
48
- if (!import.meta.url.endsWith('.ts')) {
49
- return require('./compiler/hooks.js').createCompiler(settings);
50
- }
60
+ if (!import.meta.url.endsWith('.ts'))
61
+ return require(`./compiler/${name}.js`);
51
62
  const { runnerImport } = require('vite');
52
63
  const nodeEnv = process.env['NODE_ENV']; // the runner sets it when unset; the build owns it
53
- const { module } = await runnerImport(fileURLToPath(new URL('./compiler/hooks.ts', import.meta.url)), { configFile: false, logLevel: 'silent' });
64
+ const { module } = await runnerImport(fileURLToPath(new URL(`./compiler/${name}.ts`, import.meta.url)), { configFile: false, logLevel: 'silent' });
54
65
  if (nodeEnv === undefined)
55
66
  delete process.env['NODE_ENV'];
56
67
  else
57
68
  process.env['NODE_ENV'] = nodeEnv;
58
- return module.createCompiler(settings);
69
+ return module;
70
+ }
71
+ /** The compiler's hooks (`vite build`). */
72
+ async function loadHooks(options) {
73
+ const hooks = await loadCompiler('hooks');
74
+ return hooks.createCompiler({ ...settingsOf(options), ownEntry: OWN_COMPILED });
59
75
  }
60
76
  /** The template compiler alone (`gyralVitePreset()` includes it). */
61
- export function gyralTemplateCompiler(options = {}) {
77
+ function gyralTemplateCompiler(options = {}) {
62
78
  let hooks;
63
79
  const ready = () => {
64
80
  if (hooks === undefined)
@@ -77,8 +93,20 @@ export function gyralTemplateCompiler(options = {}) {
77
93
  buildStart(input) {
78
94
  return ready().buildStart.call(this, input);
79
95
  },
96
+ // The registration modules of spec-field features (./compiler/features.ts).
97
+ resolveId(source, importer, opts) {
98
+ return ready().resolveId.call(this, source, importer, opts);
99
+ },
100
+ load(id, opts) {
101
+ return ready().load.call(this, id, opts);
102
+ },
80
103
  transform: {
81
- filter: { id: /\.[cm]?[jt]sx?$/, code: 'html' },
104
+ // Modules naming a template tag (html or svg; core's template module names both), or a
105
+ // spec field whose machinery the build adds only when named (view/05).
106
+ filter: {
107
+ id: /\.[cm]?[jt]sx?$/,
108
+ code: /html|svg|viewTransition|renderOnFrame|states|formAssociated|subscriptions|\.value\s*\(/,
109
+ },
82
110
  handler(code, id, opts) {
83
111
  return ready().transform.call(this, code, id, opts);
84
112
  },
@@ -88,8 +116,51 @@ export function gyralTemplateCompiler(options = {}) {
88
116
  },
89
117
  };
90
118
  }
91
- /** Gyral's packages: the dev server runs them through Vite, never Node (view/06). */
92
- export const GYRAL_PACKAGES = /^@gyral\//;
119
+ /**
120
+ * Development source locations (view/01-templates.md "Source locations"): in `vite serve` (the
121
+ * dev server, Vitest) each html`…` and svg`…` call site of the template sources tells the
122
+ * runtime where it was written, so template rule errors and hydration mismatches name
123
+ * `file:line:col` (./compiler/locate.ts, loaded on the first hook). `vite build` compiles
124
+ * templates instead.
125
+ */
126
+ function gyralTemplateLocations(options = {}) {
127
+ let hooks;
128
+ const ready = () => {
129
+ if (hooks === undefined)
130
+ throw new Error('gyral: the template locator is not loaded yet');
131
+ return hooks;
132
+ };
133
+ return {
134
+ name: 'gyral:template-locations',
135
+ enforce: 'pre',
136
+ apply: 'serve',
137
+ resolveId(source) {
138
+ return source === 'virtual:gyral/template-locations' ? '\0gyral:template-locations' : null;
139
+ },
140
+ load(id) {
141
+ return id === '\0gyral:template-locations'
142
+ ? 'export const locate = (tag, loc) => tag.at?.(loc) ?? tag;'
143
+ : null;
144
+ },
145
+ async configResolved(config) {
146
+ const locate = await loadCompiler('locate');
147
+ hooks = locate.createLocator(settingsOf(options).sources);
148
+ await hooks.configResolved.call(this, config);
149
+ },
150
+ transform: {
151
+ // Modules naming a template tag (html or svg), as the compiler's filter.
152
+ filter: { id: /\.[cm]?[jt]sx?$/, code: /html|svg/ },
153
+ handler(code, id, opts) {
154
+ return ready().transform.call(this, code, id, opts);
155
+ },
156
+ },
157
+ };
158
+ }
159
+ /**
160
+ * Gyral's packages: the dev server runs them through Vite, never Node (view/06). The feature
161
+ * scan's scope (./compiler/scope.ts) uses the same pattern.
162
+ */
163
+ const GYRAL_PACKAGES = /^@gyral\//;
93
164
  function manifest(file) {
94
165
  try {
95
166
  return JSON.parse(readFileSync(file, 'utf8'));
@@ -108,9 +179,9 @@ function installed(root, name) {
108
179
  }
109
180
  /**
110
181
  * The app's direct dependencies that depend on a Gyral package (a design system, say). They
111
- * import @gyral/core, so they must share the copy the dev server runs.
182
+ * import `@gyral/core`, so they must share the copy the dev server runs.
112
183
  */
113
- export function gyralDependents(root) {
184
+ function gyralDependents(root) {
114
185
  const app = manifest(join(root, 'package.json'));
115
186
  const names = Object.keys({ ...app?.dependencies, ...app?.devDependencies });
116
187
  return names.filter((name) => {
@@ -129,7 +200,7 @@ export function gyralDependents(root) {
129
200
  * out of externalization in server environments: Vite resolves them with its conditions
130
201
  * (`development` in dev), and they all share one copy of core. `vite build` is unaffected.
131
202
  */
132
- export function gyralDevServer() {
203
+ function gyralDevSsr() {
133
204
  let root = process.cwd();
134
205
  return {
135
206
  name: 'gyral:dev-server',
@@ -145,6 +216,71 @@ export function gyralDevServer() {
145
216
  },
146
217
  };
147
218
  }
219
+ /**
220
+ * Client-only builds (view/07-hydration.md "Client-only builds", gyral-c5d.11), for apps no
221
+ * server renders: the browser environment resolves core with the `gyral-client-only`
222
+ * condition, so the bundle carries no hydration code (no seed reading, no hydration chunk and
223
+ * its import()), and in `vite build` the invoker-command fallback only when a module that can
224
+ * affect Gyral components (the app's own, or a package that reaches a Gyral package) may use
225
+ * command intents (./compiler/features.ts). With no other import(), Vite's preload helper goes
226
+ * too. Server-rendered markup met anyway renders fresh (development warns). Dev servers and
227
+ * test runs get the condition too, and always keep the invoker fallback.
228
+ */
229
+ function gyralClientOnly() {
230
+ let hooks;
231
+ let root = process.cwd();
232
+ return {
233
+ name: 'gyral:client-only',
234
+ enforce: 'pre',
235
+ configEnvironment(name, config, env) {
236
+ addCondition(name, config, env, CLIENT_ONLY_CONDITION, true);
237
+ },
238
+ async configResolved(config) {
239
+ root = config.root;
240
+ if (config.command !== 'build')
241
+ return;
242
+ const features = await loadCompiler('features');
243
+ hooks = features.createFeatures(['invokers'], OWN_COMPILED);
244
+ },
245
+ async buildStart() {
246
+ await hooks?.buildStart((source, importer) => this.resolve(source, importer), root);
247
+ },
248
+ resolveId(source) {
249
+ return hooks?.resolveId(source) ?? null;
250
+ },
251
+ load(id) {
252
+ return hooks?.load(id) ?? null;
253
+ },
254
+ transform: {
255
+ // features.ts FEATURE_HINTS.invokers: any import or export may reach `raw`.
256
+ filter: { id: /\.[cm]?[jt]sx?$/, code: /data-intent-on|command|raw|import|export/i },
257
+ async handler(code, id) {
258
+ if (hooks === undefined || this.environment.config.consumer !== 'client')
259
+ return null;
260
+ const imports = await hooks.inject(code, id, {
261
+ parse: (text, lang) => this.parse(text, { lang }),
262
+ resolve: (source, importer) => this.resolve(source, importer),
263
+ });
264
+ // Appended after the last line: no code moves, so the incoming source map holds.
265
+ return imports === '' ? null : { code: code + imports, map: null };
266
+ },
267
+ },
268
+ };
269
+ }
270
+ /**
271
+ * Writes `HTMLElementTagNameMap` entries for every exported `define()` component (a
272
+ * `.gyral/elements.d.ts` to gitignore and include in tsconfig) at the start of a build, dev
273
+ * server or test run, and again when a source file changes. ./compiler/tag-map imports Node
274
+ * built-ins only, so Node's require loads it, from TypeScript source too: no module runner,
275
+ * which may be closed by the time a build starts (see loadCompiler).
276
+ */
277
+ function gyralElementTypes(options) {
278
+ const source = import.meta.url.endsWith('.ts')
279
+ ? './compiler/tag-map.ts'
280
+ : './compiler/tag-map.js';
281
+ const tagMap = createRequire(import.meta.url)(source);
282
+ return tagMap.elementTypesPlugin(options);
283
+ }
148
284
  /**
149
285
  * Spread into a Vite config, or into each Vitest project:
150
286
  *
@@ -154,9 +290,48 @@ export function gyralDevServer() {
154
290
  */
155
291
  export function gyralVitePreset(options = {}) {
156
292
  return {
157
- plugins: [gyralTemplateCompiler(options.compiler), gyralDevServer()],
158
- resolve: { dedupe: [] },
293
+ plugins: [
294
+ // Before the compiler: its feature scan reads the author's templates, not compiled ones.
295
+ ...(options.clientOnly === true ? [gyralClientOnly()] : []),
296
+ gyralTemplateCompiler(options.compiler),
297
+ gyralTemplateLocations(options.compiler),
298
+ gyralDevSsr(),
299
+ ...(options.components === undefined || options.components === false
300
+ ? []
301
+ : [gyralComponents(options.components === true ? {} : options.components)]),
302
+ ...(options.types === false ? [] : [gyralElementTypes(options.types ?? {})]),
303
+ ],
159
304
  optimizeDeps: { include: [...new Set(options.optimize ?? [])] },
160
305
  };
161
306
  }
307
+ /**
308
+ * Automatic component loading (`gyralVitePreset({ components })`): a shell whose hooks run
309
+ * ./compiler/components.ts, loaded on the first hook (`config`) like the compiler.
310
+ */
311
+ function gyralComponents(options) {
312
+ let impl;
313
+ const run = (name) => function (...args) {
314
+ const hook = impl?.[name];
315
+ return hook?.call(this, ...args) ?? null;
316
+ };
317
+ const hook = (name) => run(name);
318
+ return {
319
+ name: 'gyral:components',
320
+ api: {
321
+ tags: () => impl?.api?.tags?.() ??
322
+ new Map(),
323
+ },
324
+ async config(...args) {
325
+ const components = await loadCompiler('components');
326
+ impl = components.createComponents(options);
327
+ return run('config').apply(this, args);
328
+ },
329
+ configResolved: hook('configResolved'),
330
+ buildStart: hook('buildStart'),
331
+ resolveId: hook('resolveId'),
332
+ load: hook('load'),
333
+ configureServer: hook('configureServer'),
334
+ generateBundle: hook('generateBundle'),
335
+ };
336
+ }
162
337
  //# sourceMappingURL=vite.js.map
package/dist/vite.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"vite.js","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,0FAA0F;AAC1F,wFAAwF;AACxF,+FAA+F;AAC/F,0FAA0F;AAC1F,8FAA8F;AAC9F,4FAA4F;AAC5F,6FAA6F;AAC7F,mEAAmE;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAmBzC,uFAAuF;AACvF,MAAM,CAAC,MAAM,wBAAwB,GAAsB,CAAC,aAAa,CAAC,CAAC;AAE3E,4FAA4F;AAC5F,MAAM,CAAC,MAAM,kBAAkB,GAAG,gBAAgB,CAAC;AACnD,oGAAoG;AACpG,MAAM,CAAC,MAAM,iBAAiB,GAAsB,CAAC,QAAQ,EAAE,SAAS,EAAE,wBAAwB,CAAC,CAAC;AACpG,MAAM,CAAC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AU,EAAE,CAAC,cAAc,EAAE,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC;QACjF,CAAC;KACF,CAAC;AACJ,CAAC;AAeD;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,UAA4B,EAAE;IAC5D,OAAO;QACL,OAAO,EAAE,CAAC,qBAAqB,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,cAAc,EAAE,CAAC;QACpE,OAAO,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;QACvB,YAAY,EAAE,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,EAAE;KAChE,CAAC;AACJ,CAAC","sourcesContent":["// Vite / Vitest settings every Gyral app needs (gyral-a7r, docs/references/consumer-setup.md):\n// the template compiler (view/01-templates.md \"Compiled\") and, in serve mode, development\n// output from the dev server's SSR (view/06-server.md \"Development markers\"). Only Node\n// built-ins are imported up front, so it loads from vite.config.ts and vitest.config.ts in any\n// way: bundled with the config, by Node from source (type stripping), or by a Vite module\n// runner. The compiler is a plugin applied in `vite build` only, so dev servers and test runs\n// keep the runtime template path; its implementation (./compiler/) loads on the first build\n// hook, with `require` (Node loads ES modules with it too): a module runner that loaded this\n// file may be closed by then, and would reject a dynamic import().\nimport { readFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { dirname, join, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { ConfigEnv, EnvironmentOptions, Plugin } from 'vite';\nimport type { CompilerHooks } from './compiler/hooks.js';\n\nexport interface TemplateCompilerOptions {\n /**\n * Module specifiers whose `html` export is the view layer's tag (default\n * `DEFAULT_TEMPLATE_SOURCES`). An import matches when its specifier is listed, or when it\n * resolves to the same module as a listed one; core's own view modules always match. A\n * source other than '@gyral/core' must also export `compiled`.\n */\n readonly sources?: readonly string[];\n /**\n * Rule 7's extra check with parse5 (an optional peer dependency): `true` (default) uses\n * 'parse5' when it is installed, a string names the module to load, `false` skips it.\n */\n readonly parse5?: boolean | string;\n}\n\n/** Where the view layer's `html` comes from: core's main entry (ADR 0018, Phase 3). */\nexport const DEFAULT_TEMPLATE_SOURCES: readonly string[] = ['@gyral/core'];\n\n/** The resolve condition that maps core's `#prepare` to its stub (ADR 0017's mechanism). */\nexport const COMPILED_CONDITION = 'gyral-compiled';\n/** Vite 8's default resolve conditions (`defaultClientConditions`, server ones without browser). */\nexport const CLIENT_CONDITIONS: readonly string[] = ['module', 'browser', 'development|production'];\nexport const SERVER_CONDITIONS: readonly string[] = ['module', 'node', 'development|production'];\n\n/**\n * Adds the `gyral-compiled` condition to an environment, on top of the app's conditions or\n * Vite's defaults: Vite replaces the defaults when a config names any condition.\n */\nfunction addCondition(\n name: string,\n config: EnvironmentOptions,\n env: ConfigEnv & { isSsrTargetWebworker?: boolean },\n): void {\n const consumer = config.consumer ?? (name === 'client' ? 'client' : 'server');\n const client = consumer === 'client' || env.isSsrTargetWebworker === true;\n const current = config.resolve?.conditions ?? (client ? CLIENT_CONDITIONS : SERVER_CONDITIONS);\n if (!current.includes(COMPILED_CONDITION)) {\n config.resolve = { ...config.resolve, conditions: [...current, COMPILED_CONDITION] };\n }\n}\n\n/**\n * The compiler's hooks. From core's TypeScript source (this workspace, `link:` checkouts) they\n * load through Vite's module runner, as a vite.config.ts would; from the published package,\n * with require.\n */\nasync function loadHooks(options: TemplateCompilerOptions): Promise<CompilerHooks> {\n const settings = {\n sources: options.sources ?? DEFAULT_TEMPLATE_SOURCES,\n parse5:\n options.parse5 === false\n ? undefined\n : typeof options.parse5 === 'string'\n ? options.parse5\n : 'parse5',\n };\n const require = createRequire(import.meta.url);\n if (!import.meta.url.endsWith('.ts')) {\n return (require('./compiler/hooks.js') as typeof import('./compiler/hooks.js')).createCompiler(\n settings,\n );\n }\n const { runnerImport } = require('vite') as typeof import('vite');\n const nodeEnv = process.env['NODE_ENV']; // the runner sets it when unset; the build owns it\n const { module } = await runnerImport<typeof import('./compiler/hooks.js')>(\n fileURLToPath(new URL('./compiler/hooks.ts', import.meta.url)),\n { configFile: false, logLevel: 'silent' },\n );\n if (nodeEnv === undefined) delete process.env['NODE_ENV'];\n else process.env['NODE_ENV'] = nodeEnv;\n return module.createCompiler(settings);\n}\n\n/** The template compiler alone (`gyralVitePreset()` includes it). */\nexport function gyralTemplateCompiler(options: TemplateCompilerOptions = {}): Plugin {\n let hooks: CompilerHooks | undefined;\n const ready = (): CompilerHooks => {\n if (hooks === undefined) throw new Error('gyral: the template compiler is not loaded yet');\n return hooks;\n };\n return {\n name: 'gyral:template-compiler',\n enforce: 'pre',\n apply: 'build',\n configEnvironment: addCondition,\n async configResolved(config) {\n hooks = await loadHooks(options);\n await hooks.configResolved.call(this, config);\n },\n buildStart(input) {\n return ready().buildStart.call(this, input);\n },\n transform: {\n filter: { id: /\\.[cm]?[jt]sx?$/, code: 'html' },\n handler(code, id, opts) {\n return ready().transform.call(this, code, id, opts);\n },\n },\n generateBundle(output, bundle, isWrite) {\n return ready().generateBundle.call(this, output, bundle, isWrite);\n },\n };\n}\n\n/** Gyral's packages: the dev server runs them through Vite, never Node (view/06). */\nexport const GYRAL_PACKAGES = /^@gyral\\//;\n\ntype Manifest = Partial<Record<'dependencies' | 'devDependencies' | 'peerDependencies', object>>;\n\nfunction manifest(file: string): Manifest | undefined {\n try {\n return JSON.parse(readFileSync(file, 'utf8')) as Manifest;\n } catch {\n return undefined;\n }\n}\n\n/** The installed manifest of `name`, looked up from `root` the way Node does (no exports map). */\nfunction installed(root: string, name: string): Manifest | undefined {\n for (let dir = root; ; dir = dirname(dir)) {\n const found = manifest(join(dir, 'node_modules', name, 'package.json'));\n if (found !== undefined || dirname(dir) === dir) return found;\n }\n}\n\n/**\n * The app's direct dependencies that depend on a Gyral package (a design system, say). They\n * import @gyral/core, so they must share the copy the dev server runs.\n */\nexport function gyralDependents(root: string): string[] {\n const app = manifest(join(root, 'package.json'));\n const names = Object.keys({ ...app?.dependencies, ...app?.devDependencies });\n return names.filter((name) => {\n if (GYRAL_PACKAGES.test(name)) return false;\n const dep = installed(root, name);\n return Object.keys({ ...dep?.dependencies, ...dep?.peerDependencies }).some((d) =>\n GYRAL_PACKAGES.test(d),\n );\n });\n}\n\n/**\n * Development output from the dev server's SSR (`ssrLoadModule`, view/06 \"Development\n * markers\"). Vite externalizes installed packages there and Node imports them itself, resolving\n * core's `#view-dev` without the `development` condition (Vite's `externalConditions` only pick\n * the entry file, not the package's own imports), so the server rendered production output.\n * In serve mode this plugin keeps Gyral's packages, and the app's dependencies that use them,\n * out of externalization in server environments: Vite resolves them with its conditions\n * (`development` in dev), and they all share one copy of core. `vite build` is unaffected.\n */\nexport function gyralDevServer(): Plugin {\n let root = process.cwd();\n return {\n name: 'gyral:dev-server',\n apply: 'serve',\n config(config) {\n root = resolve(config.root ?? process.cwd());\n },\n configEnvironment(name, config) {\n const consumer = config.consumer ?? (name === 'client' ? 'client' : 'server');\n if (consumer === 'client') return undefined;\n return { resolve: { noExternal: [GYRAL_PACKAGES, ...gyralDependents(root)] } };\n },\n };\n}\n\nexport interface GyralViteOptions {\n /** Modules to pre-bundle in dev, so Vite doesn't discover them mid-run and reload. */\n readonly optimize?: readonly string[];\n /** Template compiler options (`vite build` only). */\n readonly compiler?: TemplateCompilerOptions;\n}\n\nexport interface GyralViteConfig {\n readonly plugins: Plugin[];\n readonly resolve: { readonly dedupe: string[] };\n readonly optimizeDeps: { readonly include: string[] };\n}\n\n/**\n * Spread into a Vite config, or into each Vitest project:\n *\n * export default defineConfig({ ...gyralVitePreset(), build: { … } });\n *\n * With plugins of your own, list both: `plugins: [...preset.plugins, mine()]`.\n */\nexport function gyralVitePreset(options: GyralViteOptions = {}): GyralViteConfig {\n return {\n plugins: [gyralTemplateCompiler(options.compiler), gyralDevServer()],\n resolve: { dedupe: [] },\n optimizeDeps: { include: [...new Set(options.optimize ?? [])] },\n };\n}\n"]}
1
+ {"version":3,"file":"vite.js","sourceRoot":"","sources":["../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I,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,IAAI,IAAI,CAAC;IAC3C,CAAC,CAAC;IACJ,MAAM,IAAI,GAAG,CAAyB,IAAO,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAA2B,CAAC;IACtF,OAAO;QACL,IAAI,EAAE,kBAAkB;QACxB,GAAG,EAAE;YACH,IAAI,EAAE,GAAgC,EAAE,CACrC,IAAI,EAAE,GAAgE,EAAE,IAAI,EAAE,EAAE;gBACjF,IAAI,GAAG,EAAE;SACZ;QACD,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI;YAClB,MAAM,UAAU,GACd,MAAM,YAAY,CAA4C,YAAY,CAAC,CAAC;YAC9E,IAAI,GAAG,UAAU,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;YAC5C,OAAO,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAc,CAAC;QACtD,CAAC;QACD,cAAc,EAAE,IAAI,CAAC,gBAAgB,CAAC;QACtC,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC;QAC9B,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC;QAC5B,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;QAClB,eAAe,EAAE,IAAI,CAAC,iBAAiB,CAAC;QACxC,cAAc,EAAE,IAAI,CAAC,gBAAgB,CAAC;KACvC,CAAC;AACJ,CAAC","sourcesContent":["// Vite / Vitest settings every Gyral app needs (gyral-a7r, docs/references/consumer-setup.md):\n// the template compiler (view/01-templates.md \"Compiled\") and, in serve mode, development\n// output from the dev server's SSR (view/06-server.md \"Development markers\"). Only Node\n// built-ins are imported up front, so it loads from vite.config.ts and vitest.config.ts in any\n// way: bundled with the config, by Node from source (type stripping), or by a Vite module\n// runner. The compiler is a plugin applied in `vite build` only, so dev servers and test runs\n// keep the runtime template path; its implementation (./compiler/) loads on the first build\n// hook, with `require` (Node loads ES modules with it too): a module runner that loaded this\n// file may be closed by then, and would reject a dynamic import(). Public: the preset,\n// gyralTemplateCompiler and gyralClientOnly (docs/references/public-api-0.3.1.md); the other\n// plugins and constants here are internal.\nimport { readFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { dirname, join, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { ConfigEnv, EnvironmentOptions, Plugin } from 'vite';\nimport type { FeatureHooks } from './compiler/features.js';\nimport type { CompilerHooks } from './compiler/hooks.js';\nimport type { LocatorHooks } from './compiler/locate.js';\n\nexport interface TemplateCompilerOptions {\n /**\n * Module specifiers whose `html` (and `svg`) exports are the view layer's tags (default\n * `DEFAULT_TEMPLATE_SOURCES`). An import matches when its specifier is listed, or when it\n * resolves to the same module as a listed one; core's own view modules always match. A\n * source other than '@gyral/core' must also export `compiled` (and `compiledSvg` when it\n * exports `svg`).\n */\n readonly sources?: readonly string[];\n /**\n * Rule 7's extra check with parse5 (an optional peer dependency): `true` (default) uses\n * 'parse5' when it is installed, a string names the module to load, `false` skips it.\n */\n readonly parse5?: boolean | string;\n}\n\n/** Where the view layer's `html` comes from: core's main entry (ADR 0018, Phase 3). */\nconst DEFAULT_TEMPLATE_SOURCES: readonly string[] = ['@gyral/core'];\n\n/** The resolve condition that maps core's `#prepare` to its stub (ADR 0017's mechanism). */\nconst COMPILED_CONDITION = 'gyral-compiled';\n/** The client's resolve condition in client-only builds (view/07 \"Client-only builds\"). */\nconst CLIENT_ONLY_CONDITION = 'gyral-client-only';\n/** Vite 8's default resolve conditions (`defaultClientConditions`, server ones without browser). */\nconst CLIENT_CONDITIONS: readonly string[] = ['module', 'browser', 'development|production'];\nconst SERVER_CONDITIONS: readonly string[] = ['module', 'node', 'development|production'];\n\n/**\n * Adds `condition` (default `gyral-compiled`) to an environment, on top of the app's\n * conditions or Vite's defaults: Vite replaces the defaults when a config names any condition.\n * `clientOnly`: only to environments that build for the browser.\n */\nfunction addCondition(\n name: string,\n config: EnvironmentOptions,\n env: ConfigEnv & { isSsrTargetWebworker?: boolean },\n condition = COMPILED_CONDITION,\n clientOnly = false,\n): void {\n const consumer = config.consumer ?? (name === 'client' ? 'client' : 'server');\n const client = consumer === 'client' || env.isSsrTargetWebworker === true;\n if (clientOnly && consumer !== 'client') return;\n const current = config.resolve?.conditions ?? (client ? CLIENT_CONDITIONS : SERVER_CONDITIONS);\n if (!current.includes(condition)) {\n config.resolve = { ...config.resolve, conditions: [...current, condition] };\n }\n}\n\n/** The compiled entry of this copy of core, next to this module. */\nconst OWN_COMPILED = fileURLToPath(\n new URL(\n import.meta.url.endsWith('.ts') ? './view/compiled.ts' : './view/compiled.js',\n import.meta.url,\n ),\n);\n\n/** The settings both plugins pass to their lazily loaded implementation. */\nfunction settingsOf(options: TemplateCompilerOptions) {\n return {\n sources: options.sources ?? DEFAULT_TEMPLATE_SOURCES,\n parse5:\n options.parse5 === false\n ? undefined\n : typeof options.parse5 === 'string'\n ? options.parse5\n : 'parse5',\n };\n}\n\n/**\n * A module of ./compiler/. From core's TypeScript source (this workspace, `link:` checkouts) it\n * loads through Vite's module runner, as a vite.config.ts would; from the published package,\n * with require.\n */\nasync function loadCompiler<M>(name: string): Promise<M> {\n const require = createRequire(import.meta.url);\n if (!import.meta.url.endsWith('.ts')) return require(`./compiler/${name}.js`) as M;\n const { runnerImport } = require('vite') as typeof import('vite');\n const nodeEnv = process.env['NODE_ENV']; // the runner sets it when unset; the build owns it\n const { module } = await runnerImport<M>(\n fileURLToPath(new URL(`./compiler/${name}.ts`, import.meta.url)),\n { configFile: false, logLevel: 'silent' },\n );\n if (nodeEnv === undefined) delete process.env['NODE_ENV'];\n else process.env['NODE_ENV'] = nodeEnv;\n return module;\n}\n\n/** The compiler's hooks (`vite build`). */\nasync function loadHooks(options: TemplateCompilerOptions): Promise<CompilerHooks> {\n const hooks = await loadCompiler<typeof import('./compiler/hooks.js')>('hooks');\n return hooks.createCompiler({ ...settingsOf(options), ownEntry: OWN_COMPILED });\n}\n\n/** The template compiler alone (`gyralVitePreset()` includes it). */\nfunction gyralTemplateCompiler(options: TemplateCompilerOptions = {}): Plugin {\n let hooks: CompilerHooks | undefined;\n const ready = (): CompilerHooks => {\n if (hooks === undefined) throw new Error('gyral: the template compiler is not loaded yet');\n return hooks;\n };\n return {\n name: 'gyral:template-compiler',\n enforce: 'pre',\n apply: 'build',\n configEnvironment: addCondition,\n async configResolved(config) {\n hooks = await loadHooks(options);\n await hooks.configResolved.call(this, config);\n },\n buildStart(input) {\n return ready().buildStart.call(this, input);\n },\n // The registration modules of spec-field features (./compiler/features.ts).\n resolveId(source, importer, opts) {\n return ready().resolveId.call(this, source, importer, opts);\n },\n load(id, opts) {\n return ready().load.call(this, id, opts);\n },\n transform: {\n // Modules naming a template tag (html or svg; core's template module names both), or a\n // spec field whose machinery the build adds only when named (view/05).\n filter: {\n id: /\\.[cm]?[jt]sx?$/,\n code: /html|svg|viewTransition|renderOnFrame|states|formAssociated|subscriptions|\\.value\\s*\\(/,\n },\n handler(code, id, opts) {\n return ready().transform.call(this, code, id, opts);\n },\n },\n generateBundle(output, bundle, isWrite) {\n return ready().generateBundle.call(this, output, bundle, isWrite);\n },\n };\n}\n\n/**\n * Development source locations (view/01-templates.md \"Source locations\"): in `vite serve` (the\n * dev server, Vitest) each html`…` and svg`…` call site of the template sources tells the\n * runtime where it was written, so template rule errors and hydration mismatches name\n * `file:line:col` (./compiler/locate.ts, loaded on the first hook). `vite build` compiles\n * templates instead.\n */\nfunction gyralTemplateLocations(options: TemplateCompilerOptions = {}): Plugin {\n let hooks: LocatorHooks | undefined;\n const ready = (): LocatorHooks => {\n if (hooks === undefined) throw new Error('gyral: the template locator is not loaded yet');\n return hooks;\n };\n return {\n name: 'gyral:template-locations',\n enforce: 'pre',\n apply: 'serve',\n resolveId(source) {\n return source === 'virtual:gyral/template-locations' ? '\\0gyral:template-locations' : null;\n },\n load(id) {\n return id === '\\0gyral:template-locations'\n ? 'export const locate = (tag, loc) => tag.at?.(loc) ?? tag;'\n : null;\n },\n async configResolved(config) {\n const locate = await loadCompiler<typeof import('./compiler/locate.js')>('locate');\n hooks = locate.createLocator(settingsOf(options).sources);\n await hooks.configResolved.call(this, config);\n },\n transform: {\n // Modules naming a template tag (html or svg), as the compiler's filter.\n filter: { id: /\\.[cm]?[jt]sx?$/, code: /html|svg/ },\n handler(code, id, opts) {\n return ready().transform.call(this, code, id, opts);\n },\n },\n };\n}\n\n/**\n * Gyral's packages: the dev server runs them through Vite, never Node (view/06). The feature\n * scan's scope (./compiler/scope.ts) uses the same pattern.\n */\nconst GYRAL_PACKAGES = /^@gyral\\//;\n\ntype Manifest = Partial<Record<'dependencies' | 'devDependencies' | 'peerDependencies', object>>;\n\nfunction manifest(file: string): Manifest | undefined {\n try {\n return JSON.parse(readFileSync(file, 'utf8')) as Manifest;\n } catch {\n return undefined;\n }\n}\n\n/** The installed manifest of `name`, looked up from `root` the way Node does (no exports map). */\nfunction installed(root: string, name: string): Manifest | undefined {\n for (let dir = root; ; dir = dirname(dir)) {\n const found = manifest(join(dir, 'node_modules', name, 'package.json'));\n if (found !== undefined || dirname(dir) === dir) return found;\n }\n}\n\n/**\n * The app's direct dependencies that depend on a Gyral package (a design system, say). They\n * import `@gyral/core`, so they must share the copy the dev server runs.\n */\nfunction gyralDependents(root: string): string[] {\n const app = manifest(join(root, 'package.json'));\n const names = Object.keys({ ...app?.dependencies, ...app?.devDependencies });\n return names.filter((name) => {\n if (GYRAL_PACKAGES.test(name)) return false;\n const dep = installed(root, name);\n return Object.keys({ ...dep?.dependencies, ...dep?.peerDependencies }).some((d) =>\n GYRAL_PACKAGES.test(d),\n );\n });\n}\n\n/**\n * Development output from the dev server's SSR (`ssrLoadModule`, view/06 \"Development\n * markers\"). Vite externalizes installed packages there and Node imports them itself, resolving\n * core's `#view-dev` without the `development` condition (Vite's `externalConditions` only pick\n * the entry file, not the package's own imports), so the server rendered production output.\n * In serve mode this plugin keeps Gyral's packages, and the app's dependencies that use them,\n * out of externalization in server environments: Vite resolves them with its conditions\n * (`development` in dev), and they all share one copy of core. `vite build` is unaffected.\n */\nfunction gyralDevSsr(): Plugin {\n let root = process.cwd();\n return {\n name: 'gyral:dev-server',\n apply: 'serve',\n config(config) {\n root = resolve(config.root ?? process.cwd());\n },\n configEnvironment(name, config) {\n const consumer = config.consumer ?? (name === 'client' ? 'client' : 'server');\n if (consumer === 'client') return undefined;\n return { resolve: { noExternal: [GYRAL_PACKAGES, ...gyralDependents(root)] } };\n },\n };\n}\n\n/**\n * Client-only builds (view/07-hydration.md \"Client-only builds\", gyral-c5d.11), for apps no\n * server renders: the browser environment resolves core with the `gyral-client-only`\n * condition, so the bundle carries no hydration code (no seed reading, no hydration chunk and\n * its import()), and in `vite build` the invoker-command fallback only when a module that can\n * affect Gyral components (the app's own, or a package that reaches a Gyral package) may use\n * command intents (./compiler/features.ts). With no other import(), Vite's preload helper goes\n * too. Server-rendered markup met anyway renders fresh (development warns). Dev servers and\n * test runs get the condition too, and always keep the invoker fallback.\n */\nfunction gyralClientOnly(): Plugin {\n let hooks: FeatureHooks | undefined;\n let root = process.cwd();\n return {\n name: 'gyral:client-only',\n enforce: 'pre',\n configEnvironment(name, config, env) {\n addCondition(name, config, env, CLIENT_ONLY_CONDITION, true);\n },\n async configResolved(config) {\n root = config.root;\n if (config.command !== 'build') return;\n const features = await loadCompiler<typeof import('./compiler/features.js')>('features');\n hooks = features.createFeatures(['invokers'], OWN_COMPILED);\n },\n async buildStart() {\n await hooks?.buildStart((source, importer) => this.resolve(source, importer), root);\n },\n resolveId(source) {\n return hooks?.resolveId(source) ?? null;\n },\n load(id) {\n return hooks?.load(id) ?? null;\n },\n transform: {\n // features.ts FEATURE_HINTS.invokers: any import or export may reach `raw`.\n filter: { id: /\\.[cm]?[jt]sx?$/, code: /data-intent-on|command|raw|import|export/i },\n async handler(code, id) {\n if (hooks === undefined || this.environment.config.consumer !== 'client') return null;\n const imports = await hooks.inject(code, id, {\n parse: (text, lang) => this.parse(text, { lang }),\n resolve: (source, importer) => this.resolve(source, importer),\n });\n // Appended after the last line: no code moves, so the incoming source map holds.\n return imports === '' ? null : { code: code + imports, map: null };\n },\n },\n };\n}\n\n/** Where the preset looks for components and writes their typings. */\nexport interface ElementTypesOptions {\n /** Source directories to scan, relative to the Vite root. Default `['src']`. */\n readonly dirs?: readonly string[];\n /** The declaration file to write, relative to the Vite root. Default `.gyral/elements.d.ts`. */\n readonly out?: string;\n}\n\n/**\n * Writes `HTMLElementTagNameMap` entries for every exported `define()` component (a\n * `.gyral/elements.d.ts` to gitignore and include in tsconfig) at the start of a build, dev\n * server or test run, and again when a source file changes. ./compiler/tag-map imports Node\n * built-ins only, so Node's require loads it, from TypeScript source too: no module runner,\n * which may be closed by the time a build starts (see loadCompiler).\n */\nfunction gyralElementTypes(options: ElementTypesOptions): Plugin {\n const source = import.meta.url.endsWith('.ts')\n ? './compiler/tag-map.ts'\n : './compiler/tag-map.js';\n const tagMap = createRequire(import.meta.url)(source) as typeof import('./compiler/tag-map.js');\n return tagMap.elementTypesPlugin(options);\n}\n\nexport interface GyralViteOptions {\n /**\n * Generated element typings (`.gyral/elements.d.ts`, see `ElementTypesOptions`), or `false`\n * to write none. Default: on, scanning `src`.\n */\n readonly types?: ElementTypesOptions | false;\n /** Modules to pre-bundle in dev, so Vite doesn't discover them mid-run and reload. */\n readonly optimize?: readonly string[];\n /** Template compiler options (`vite build` only). */\n readonly compiler?: TemplateCompilerOptions;\n /**\n * The app is never server-rendered: leave the hydration code out of the browser bundle\n * (`gyralClientOnly()`). Default false.\n */\n readonly clientOnly?: boolean;\n /**\n * Automatic component loading (ADR 0016 addendum): every component defined under `include`\n * gets a client module the build splits out, and a loader (`virtual:gyral/components`, added\n * to the client build's input) imports a tag's module once that tag is in the page.\n * `renderPage({ components })` then links exactly the components a page rendered, so pages\n * need no client entry of their own and no side-effect imports. Default off.\n */\n readonly components?: boolean | ComponentsOptions;\n}\n\nexport interface ComponentsOptions {\n /** Directories (relative to Vite's root) whose modules' `define()` tags are found. Default `['src']`. */\n readonly include?: readonly string[];\n /**\n * Tag → module (relative to Vite's root) for components the scan can't find: those defined\n * through a wrapper such as `defineMemberForm({ tag: 'member-form' })`, which calls\n * `define()` itself. Listed entries win over scanned ones.\n */\n readonly modules?: Readonly<Record<string, string>>;\n}\n\nexport interface GyralViteConfig {\n readonly plugins: Plugin[];\n readonly optimizeDeps: { readonly include: string[] };\n}\n\n/**\n * Spread into a Vite config, or into each Vitest project:\n *\n * export default defineConfig({ ...gyralVitePreset(), build: { … } });\n *\n * With plugins of your own, list both: `plugins: [...preset.plugins, mine()]`.\n */\nexport function gyralVitePreset(options: GyralViteOptions = {}): GyralViteConfig {\n return {\n plugins: [\n // Before the compiler: its feature scan reads the author's templates, not compiled ones.\n ...(options.clientOnly === true ? [gyralClientOnly()] : []),\n gyralTemplateCompiler(options.compiler),\n gyralTemplateLocations(options.compiler),\n gyralDevSsr(),\n ...(options.components === undefined || options.components === false\n ? []\n : [gyralComponents(options.components === true ? {} : options.components)]),\n ...(options.types === false ? [] : [gyralElementTypes(options.types ?? {})]),\n ],\n optimizeDeps: { include: [...new Set(options.optimize ?? [])] },\n };\n}\n\ntype Hook = (this: unknown, ...args: unknown[]) => unknown;\n\n/**\n * Automatic component loading (`gyralVitePreset({ components })`): a shell whose hooks run\n * ./compiler/components.ts, loaded on the first hook (`config`) like the compiler.\n */\nfunction gyralComponents(options: ComponentsOptions): Plugin {\n let impl: Plugin | undefined;\n const run = (name: keyof Plugin) =>\n function (this: unknown, ...args: unknown[]): unknown {\n const hook = impl?.[name] as Hook | undefined;\n return hook?.call(this, ...args) ?? null;\n };\n const hook = <K extends keyof Plugin>(name: K) => run(name) as NonNullable<Plugin[K]>;\n return {\n name: 'gyral:components',\n api: {\n tags: (): ReadonlyMap<string, string> =>\n (impl?.api as { tags?: () => ReadonlyMap<string, string> } | undefined)?.tags?.() ??\n new Map(),\n },\n async config(...args) {\n const components =\n await loadCompiler<typeof import('./compiler/components.js')>('components');\n impl = components.createComponents(options);\n return run('config').apply(this, args) as undefined;\n },\n configResolved: hook('configResolved'),\n buildStart: hook('buildStart'),\n resolveId: hook('resolveId'),\n load: hook('load'),\n configureServer: hook('configureServer'),\n generateBundle: hook('generateBundle'),\n };\n}\n"]}