@gyral/core 0.3.0 → 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 (381) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/NOTICE +19 -0
  3. package/README.md +30 -5
  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 +182 -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 +78 -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 +13 -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 +6 -2
  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 +20 -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 +41 -19
  140. package/dist/intent.js +144 -106
  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 +8 -2
  184. package/dist/server.js +11 -2
  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.js +36 -8
  207. package/dist/store.js.map +1 -1
  208. package/dist/subscription.d.ts +35 -0
  209. package/dist/subscription.js +74 -0
  210. package/dist/subscription.js.map +1 -0
  211. package/dist/subscriptions.d.ts +26 -0
  212. package/dist/subscriptions.js +98 -0
  213. package/dist/subscriptions.js.map +1 -0
  214. package/dist/transitions.d.ts +4 -5
  215. package/dist/transitions.js +10 -4
  216. package/dist/transitions.js.map +1 -1
  217. package/dist/types.d.ts +124 -27
  218. package/dist/types.js.map +1 -1
  219. package/dist/use-dialogs.d.ts +2 -0
  220. package/dist/use-dialogs.js +9 -0
  221. package/dist/use-dialogs.js.map +1 -0
  222. package/dist/use-disposal.d.ts +2 -0
  223. package/dist/use-disposal.js +9 -0
  224. package/dist/use-disposal.js.map +1 -0
  225. package/dist/use-error-view.d.ts +2 -0
  226. package/dist/use-error-view.js +9 -0
  227. package/dist/use-error-view.js.map +1 -0
  228. package/dist/use-errored.d.ts +2 -0
  229. package/dist/use-errored.js +9 -0
  230. package/dist/use-errored.js.map +1 -0
  231. package/dist/use-form-associated.d.ts +2 -0
  232. package/dist/use-form-associated.js +7 -0
  233. package/dist/use-form-associated.js.map +1 -0
  234. package/dist/use-frame-lane.d.ts +2 -0
  235. package/dist/use-frame-lane.js +10 -0
  236. package/dist/use-frame-lane.js.map +1 -0
  237. package/dist/use-invokers.d.ts +2 -0
  238. package/dist/use-invokers.js +10 -0
  239. package/dist/use-invokers.js.map +1 -0
  240. package/dist/use-states.d.ts +2 -0
  241. package/dist/use-states.js +10 -0
  242. package/dist/use-states.js.map +1 -0
  243. package/dist/use-subscriptions.d.ts +2 -0
  244. package/dist/use-subscriptions.js +10 -0
  245. package/dist/use-subscriptions.js.map +1 -0
  246. package/dist/use-transitions.d.ts +2 -0
  247. package/dist/use-transitions.js +10 -0
  248. package/dist/use-transitions.js.map +1 -0
  249. package/dist/view/attributes.d.ts +5 -0
  250. package/dist/view/attributes.js +5 -0
  251. package/dist/view/attributes.js.map +1 -1
  252. package/dist/view/compiled.d.ts +1 -1
  253. package/dist/view/compiled.js +1 -1
  254. package/dist/view/compiled.js.map +1 -1
  255. package/dist/view/index.d.ts +9 -4
  256. package/dist/view/index.js +9 -3
  257. package/dist/view/index.js.map +1 -1
  258. package/dist/view/loc.d.ts +9 -0
  259. package/dist/view/loc.js +50 -0
  260. package/dist/view/loc.js.map +1 -0
  261. package/dist/view/message.d.ts +17 -0
  262. package/dist/view/message.js +40 -0
  263. package/dist/view/message.js.map +1 -0
  264. package/dist/view/messages.d.ts +43 -0
  265. package/dist/view/messages.js +84 -0
  266. package/dist/view/messages.js.map +1 -0
  267. package/dist/view/normalize/check.d.ts +5 -2
  268. package/dist/view/normalize/check.js +6 -3
  269. package/dist/view/normalize/check.js.map +1 -1
  270. package/dist/view/normalize/emit.d.ts +2 -0
  271. package/dist/view/normalize/emit.js +40 -11
  272. package/dist/view/normalize/emit.js.map +1 -1
  273. package/dist/view/normalize/errors.js +1 -1
  274. package/dist/view/normalize/errors.js.map +1 -1
  275. package/dist/view/normalize/id.d.ts +5 -2
  276. package/dist/view/normalize/id.js +9 -2
  277. package/dist/view/normalize/id.js.map +1 -1
  278. package/dist/view/normalize/normalize.d.ts +7 -4
  279. package/dist/view/normalize/normalize.js +15 -9
  280. package/dist/view/normalize/normalize.js.map +1 -1
  281. package/dist/view/normalize/rules.d.ts +9 -0
  282. package/dist/view/normalize/rules.js +35 -5
  283. package/dist/view/normalize/rules.js.map +1 -1
  284. package/dist/view/normalize/svg.d.ts +14 -0
  285. package/dist/view/normalize/svg.js +40 -0
  286. package/dist/view/normalize/svg.js.map +1 -0
  287. package/dist/view/normalize/tokens.d.ts +5 -1
  288. package/dist/view/normalize/tokens.js.map +1 -1
  289. package/dist/view/normalize/tree.d.ts +8 -2
  290. package/dist/view/normalize/tree.js +58 -13
  291. package/dist/view/normalize/tree.js.map +1 -1
  292. package/dist/view/normalize/types.d.ts +24 -4
  293. package/dist/view/normalize/types.js +4 -1
  294. package/dist/view/normalize/types.js.map +1 -1
  295. package/dist/view/normalize/whitespace.js +4 -3
  296. package/dist/view/normalize/whitespace.js.map +1 -1
  297. package/dist/view/prepare-stub.js +2 -2
  298. package/dist/view/prepare-stub.js.map +1 -1
  299. package/dist/view/prepare.d.ts +5 -2
  300. package/dist/view/prepare.js +9 -3
  301. package/dist/view/prepare.js.map +1 -1
  302. package/dist/view/registry.d.ts +15 -0
  303. package/dist/view/registry.js +10 -2
  304. package/dist/view/registry.js.map +1 -1
  305. package/dist/view/render/adopt-attr.js +7 -1
  306. package/dist/view/render/adopt-attr.js.map +1 -1
  307. package/dist/view/render/adopt.js +21 -4
  308. package/dist/view/render/adopt.js.map +1 -1
  309. package/dist/view/render/attr-parts.d.ts +12 -1
  310. package/dist/view/render/attr-parts.js +38 -5
  311. package/dist/view/render/attr-parts.js.map +1 -1
  312. package/dist/view/render/child-part.js +5 -2
  313. package/dist/view/render/child-part.js.map +1 -1
  314. package/dist/view/render/dispose.d.ts +3 -0
  315. package/dist/view/render/dispose.js +76 -0
  316. package/dist/view/render/dispose.js.map +1 -0
  317. package/dist/view/render/hook-part.d.ts +3 -1
  318. package/dist/view/render/hook-part.js +21 -5
  319. package/dist/view/render/hook-part.js.map +1 -1
  320. package/dist/view/render/hook-run.d.ts +2 -0
  321. package/dist/view/render/hook-run.js +72 -0
  322. package/dist/view/render/hook-run.js.map +1 -0
  323. package/dist/view/render/hooks.d.ts +73 -5
  324. package/dist/view/render/hooks.js +79 -17
  325. package/dist/view/render/hooks.js.map +1 -1
  326. package/dist/view/render/hydrate.js +2 -2
  327. package/dist/view/render/hydrate.js.map +1 -1
  328. package/dist/view/render/keyed.d.ts +6 -0
  329. package/dist/view/render/keyed.js +15 -0
  330. package/dist/view/render/keyed.js.map +1 -0
  331. package/dist/view/render/mismatch.js +5 -3
  332. package/dist/view/render/mismatch.js.map +1 -1
  333. package/dist/view/render/modal.d.ts +3 -0
  334. package/dist/view/render/modal.js +39 -0
  335. package/dist/view/render/modal.js.map +1 -0
  336. package/dist/view/render/raw.d.ts +4 -1
  337. package/dist/view/render/raw.js +6 -2
  338. package/dist/view/render/raw.js.map +1 -1
  339. package/dist/view/render/render.d.ts +4 -1
  340. package/dist/view/render/render.js +17 -12
  341. package/dist/view/render/render.js.map +1 -1
  342. package/dist/view/render/toggles.d.ts +6 -0
  343. package/dist/view/render/toggles.js +6 -0
  344. package/dist/view/render/toggles.js.map +1 -0
  345. package/dist/view/render/warn.d.ts +14 -0
  346. package/dist/view/render/warn.js +45 -0
  347. package/dist/view/render/warn.js.map +1 -1
  348. package/dist/view/server/component.d.ts +6 -3
  349. package/dist/view/server/component.js +29 -7
  350. package/dist/view/server/component.js.map +1 -1
  351. package/dist/view/server/index.d.ts +20 -0
  352. package/dist/view/server/index.js +12 -4
  353. package/dist/view/server/index.js.map +1 -1
  354. package/dist/view/server/tags.d.ts +13 -2
  355. package/dist/view/server/tags.js +13 -2
  356. package/dist/view/server/tags.js.map +1 -1
  357. package/dist/view/server/values.d.ts +2 -0
  358. package/dist/view/server/values.js +8 -0
  359. package/dist/view/server/values.js.map +1 -1
  360. package/dist/view/server/writer.d.ts +9 -4
  361. package/dist/view/server/writer.js +33 -18
  362. package/dist/view/server/writer.js.map +1 -1
  363. package/dist/view/template-element.d.ts +7 -0
  364. package/dist/view/template-element.js +25 -5
  365. package/dist/view/template-element.js.map +1 -1
  366. package/dist/view/template.d.ts +10 -2
  367. package/dist/view/template.js +62 -8
  368. package/dist/view/template.js.map +1 -1
  369. package/dist/view/trusted-html.d.ts +6 -0
  370. package/dist/view/trusted-html.js +34 -0
  371. package/dist/view/trusted-html.js.map +1 -0
  372. package/dist/vite.d.ts +38 -31
  373. package/dist/vite.js +198 -31
  374. package/dist/vite.js.map +1 -1
  375. package/package.json +34 -3
  376. package/dist/hooks/labelled-by.d.ts +0 -13
  377. package/dist/hooks/labelled-by.js +0 -51
  378. package/dist/hooks/labelled-by.js.map +0 -1
  379. package/dist/random.d.ts +0 -13
  380. package/dist/random.js +0 -19
  381. package/dist/random.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"tags.js","sourceRoot":"","sources":["../../../src/view/server/tags.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,eAAe,EACf,cAAc,GAIf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAmB,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AA0B7F,MAAM,CAAC,MAAM,KAAK,GAAU,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC;AAE3C,MAAM,OAAO,MAAM;IAIjB;;;OAGG;IACH,YACqB,G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ChB,MAAM,KAAK,GAAU,EAAE,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;YAC1D,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;YAC5B,OAAO,KAAK,CAAC;QACf,CAAC;QACD,MAAM,SAAS,GAAG,OAAO,CAAC,SAA4B,CAAC,CAAC,oCAAoC;QAC5F,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;QACtC,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;IAC9F,CAAC;IAES,KAAK,CAAC,KAAY,EAAE,GAAW;QACvC,IAAI,KAAK,CAAC,CAAC,KAAK,UAAU;YAAE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;aAChD,IAAI,KAAK,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC;YAC7B,8EAA8E;YAC9E,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,KAAK,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;gBACnE,kBAAkB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAChC,CAAC;YACD,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;QAChB,CAAC;QACD,IAAI,CAAC,GAAG,IAAI,KAAK,GAAG,GAAG,CAAC;IAC1B,CAAC;CACF","sourcesContent":["// Start tags and custom elements for the server renderer (view/06-server.md \"Writing a template\n// result\", \"Components\"): attribute, boolean and hook holes, and what a custom element's\n// `open`/`openEnd`/`close` segments do. A Gyral component's start tag is written here, but\n// its content (seed, shadow root, view) is deferred: the walk returns strings with the\n// deferred components between them, and `render` (index.ts) expands each one in its own step,\n// so every component boundary is a chunk boundary. A provider (`<gyral-stores>`) is a plain\n// element that gives its subtree a scope until its end tag.\nimport type { Segment } from '../normalize/types.js';\nimport {\n serverComponent,\n serverProvider,\n type ServerComponent,\n type ServerProvider,\n type ServerRenderInput,\n} from '../registry.js';\nimport { hookSpec, type HookResult } from '../render/hooks.js';\nimport { badHook } from '../render/warn.js';\nimport { escapeAttr, onlyWhitespace } from './escape.js';\nimport { absent, attrText, checkAttrName, lightChildrenError, multiText } from './values.js';\n\n/** A component whose content is written later, in its own render step. */\nexport interface Deferred {\n readonly component: ServerComponent;\n readonly input: ServerRenderInput;\n}\n\n/** What a walk produces: markup, with deferred components in document order. */\nexport type Item = string | Deferred;\n\n/** A custom element's start tag while its attribute holes are written. */\nexport interface Opening {\n readonly tag: string;\n readonly component: ServerComponent | undefined;\n readonly provider: ServerProvider | undefined;\n readonly attributes: Record<string, string>;\n readonly properties: Record<string, unknown>;\n}\n\n/** An open custom element until its end tag: plain, a provider, or a light component. */\nexport type Frame =\n | { readonly k: 'plain' }\n | { readonly k: 'provider'; readonly outer: unknown }\n | { readonly k: 'light'; readonly tag: string; readonly items: number };\n\nexport const PLAIN: Frame = { k: 'plain' };\n\nexport class Markup {\n protected buf = '';\n protected readonly items: Item[] = [];\n\n /**\n * `dev`: development markers and checks. `scope`: the nearest provider's scope, passed to\n * components (undefined: the request's).\n */\n constructor(\n protected readonly dev: boolean,\n protected scope: unknown,\n ) {}\n\n write(markup: string): void {\n this.buf += markup;\n }\n\n /** The markup and deferred components written so far. */\n done(): Item[] {\n this.flush();\n return this.items;\n }\n\n private flush(): void {\n if (this.buf !== '') this.items.push(this.buf);\n this.buf = '';\n }\n\n /** `name=${v}` or `name=\"a ${v} b\"`; returns the index of the next value. */\n protected attr(\n s: Extract<Segment, { k: 'attr' }>,\n values: readonly unknown[],\n at: number,\n opening: Opening | undefined,\n ): number {\n const { name, strings } = s;\n const value =\n strings === undefined\n ? attrText(values[at], s, name, this.dev)\n : multiText(values, at, strings, s, name, this.dev);\n if (value !== null) this.valued(name, value, opening);\n return at + (strings === undefined ? 1 : strings.length - 1);\n }\n\n private valued(name: string, value: string, opening: Opening | undefined): void {\n this.buf += ` ${name}=\"${escapeAttr(value)}\"`;\n if (opening !== undefined) opening.attributes[name] = value;\n }\n\n /** A present boolean attribute (`?name`, or `true` from a hook's server half). */\n protected bare(name: string, opening: Opening | undefined): void {\n this.buf += ` ${name}`;\n if (opening !== undefined) opening.attributes[name] = '';\n }\n\n /** An element hook: its server half's attributes (02 \"Element hooks\"). */\n protected hook(v: unknown, opening: Opening | undefined): void {\n if (absent(v)) return;\n const spec = hookSpec(v);\n if (spec === undefined) {\n if (this.dev) badHook(v);\n return;\n }\n const attributes = spec.server?.((v as HookResult).args) ?? {};\n for (const [name, value] of Object.entries(attributes)) {\n checkAttrName(name);\n if (value === true) this.bare(name, opening);\n else this.valued(name, value, opening);\n }\n }\n\n /** A custom element's start tag: a Gyral component, a provider, or a plain element. */\n protected open(\n tag: string,\n html: string,\n attrs: readonly (readonly [string, string])[],\n ): Opening | undefined {\n this.buf += html;\n const component = serverComponent(tag);\n const provider = component === undefined ? serverProvider(tag) : undefined;\n if (component === undefined && provider === undefined) return undefined;\n return { tag, component, provider, attributes: Object.fromEntries(attrs), properties: {} };\n }\n\n protected openEnd(opening: Opening | undefined): Frame {\n if (opening === undefined) {\n this.buf += '>';\n return PLAIN;\n }\n const { attributes, properties } = opening;\n const messages = properties['initialMessages'];\n const input: ServerRenderInput = {\n attributes,\n properties,\n initialMessages: Array.isArray(messages) ? (messages as readonly unknown[]) : undefined,\n scope: this.scope,\n };\n if (opening.provider !== undefined) {\n const provided = opening.provider.open(input);\n for (const [name, value] of Object.entries(provided.attributes)) {\n this.buf += ` ${name}=\"${escapeAttr(value)}\"`;\n }\n this.buf += '>';\n const frame: Frame = { k: 'provider', outer: this.scope };\n this.scope = provided.scope;\n return frame;\n }\n const component = opening.component as ServerComponent; // Sound: open() set one of the two.\n this.flush();\n this.items.push({ component, input });\n return component.light ? { k: 'light', tag: opening.tag, items: this.items.length } : PLAIN;\n }\n\n protected close(frame: Frame, tag: string): void {\n if (frame.k === 'provider') this.scope = frame.outer;\n else if (frame.k === 'light') {\n // Whitespace-only children are dropped; anything else is an error (ADR 0014).\n if (this.items.length !== frame.items || !onlyWhitespace(this.buf)) {\n lightChildrenError(frame.tag);\n }\n this.buf = '';\n }\n this.buf += `</${tag}>`;\n }\n}\n"]}
1
+ {"version":3,"file":"tags.js","sourceRoot":"","sources":["../../../src/view/server/tags.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,eAAe,EACf,cAAc,GAIf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAmB,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAiC7F,MAAM,CAAC,MAAM,KAAK,GAAU,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC;AAE3C,MAAM,OAAO,MAAM;IAOjB;;;OAGG;IACH,YACqB,GAAY,EACrB,KAAc,EACL,MAAoB;QAFpB,QAAG,GAAH,GAAG,CAAS;QACrB,UAAK,GAAL,KAAK,CAAS;QACL,WAAM,GAAN,MAAM,CAAc;QAb/B,QAAG,GAAG,EAAE,CAAC;QACA,UAAK,GAAW,EAAE,CAAC;QAEtC,kEAAkE;QACxD,UAAK,GAAG,EAAE,CAAC;IAUlB,CAAC;IAEJ,+EAA+E;IACrE,KAAK,CAAC,KAAa;QAC3B,IAAI,KAAK,KAAK,EAAE,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,IAAI,CAAC,IAAI,CAAC,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Components\"): attribute, boolean and hook holes, and what a custom element's\n// `open`/`openEnd`/`close` segments do. A Gyral component's start tag is written here, but\n// its content (seed, shadow root, view) is deferred: the walk returns strings with the\n// deferred components between them, and `render` (index.ts) expands each one in its own step,\n// so every component boundary is a chunk boundary. A provider (`<gyral-stores>`) is a plain\n// element that gives its subtree a scope until its end tag.\nimport type { Segment } from '../normalize/types.js';\nimport {\n serverComponent,\n serverProvider,\n type ServerComponent,\n type ServerProvider,\n type ServerRenderInput,\n} from '../registry.js';\nimport { hookSpec, type HookResult } from '../render/hooks.js';\nimport { badHook } from '../render/warn.js';\nimport { escapeAttr, onlyWhitespace } from './escape.js';\nimport { absent, attrText, checkAttrName, lightChildrenError, multiText } from './values.js';\n\n/** A component whose content is written later, in its own render step. */\nexport interface Deferred {\n readonly component: ServerComponent;\n readonly input: ServerRenderInput;\n}\n\n/**\n * A render's `style` attribute values for a CSP (ADR 0020): each distinct value as the DOM sees\n * it (decoded), mapped to where it was first written (the template's `loc` or id; `''` when\n * neither is known).\n */\nexport type StyleValues = Map<string, string>;\n\n/** What a walk produces: markup, with deferred components in document order. */\nexport type Item = string | Deferred;\n\n/** A custom element's start tag while its attribute holes are written. */\nexport interface Opening {\n readonly tag: string;\n readonly component: ServerComponent | undefined;\n readonly provider: ServerProvider | undefined;\n readonly attributes: Record<string, string>;\n readonly properties: Record<string, unknown>;\n}\n\n/** An open custom element until its end tag: plain, a provider, or a light component. */\nexport type Frame =\n | { readonly k: 'plain' }\n | { readonly k: 'provider'; readonly outer: unknown }\n | { readonly k: 'light'; readonly tag: string; readonly items: number };\n\nexport const PLAIN: Frame = { k: 'plain' };\n\nexport class Markup {\n protected buf = '';\n protected readonly items: Item[] = [];\n\n /** The template being written, for `styles` (its `loc` or id). */\n protected where = '';\n\n /**\n * `dev`: development markers and checks. `scope`: the nearest provider's scope, passed to\n * components (undefined: the request's). `styles`: collects every `style` value written.\n */\n constructor(\n protected readonly dev: boolean,\n protected scope: unknown,\n protected readonly styles?: StyleValues,\n ) {}\n\n /** Records a `style` value the DOM will see (empty values declare nothing). */\n protected style(value: string): void {\n if (value !== '' && this.styles !== undefined && !this.styles.has(value)) {\n this.styles.set(value, this.where);\n }\n }\n\n write(markup: string): void {\n this.buf += markup;\n }\n\n /** The markup and deferred components written so far. */\n done(): Item[] {\n this.flush();\n return this.items;\n }\n\n private flush(): void {\n if (this.buf !== '') this.items.push(this.buf);\n this.buf = '';\n }\n\n /** `name=${v}` or `name=\"a ${v} b\"`; returns the index of the next value. */\n protected attr(\n s: Extract<Segment, { k: 'attr' }>,\n values: readonly unknown[],\n at: number,\n opening: Opening | undefined,\n ): number {\n const { name, strings } = s;\n const value =\n strings === undefined\n ? attrText(values[at], s, name, this.dev)\n : multiText(values, at, strings, s, name, this.dev);\n if (value !== null) this.valued(name, value, opening);\n return at + (strings === undefined ? 1 : strings.length - 1);\n }\n\n private valued(name: string, value: string, opening: Opening | undefined): void {\n this.buf += ` ${name}=\"${escapeAttr(value)}\"`;\n if (name === 'style') this.style(value);\n if (opening !== undefined) opening.attributes[name] = value;\n }\n\n /** A present boolean attribute (`?name`, or `true` from a hook's server half). */\n protected bare(name: string, opening: Opening | undefined): void {\n this.buf += ` ${name}`;\n if (opening !== undefined) opening.attributes[name] = '';\n }\n\n /** An element hook: its server half's attributes (02 \"Element hooks\"). */\n protected hook(v: unknown, opening: Opening | undefined): void {\n if (absent(v)) return;\n const spec = hookSpec(v);\n if (spec === undefined) {\n if (this.dev) badHook(v);\n return;\n }\n const attributes = spec.server?.((v as HookResult).args) ?? {};\n for (const [name, value] of Object.entries(attributes)) {\n checkAttrName(name);\n if (value === true) this.bare(name, opening);\n else this.valued(name, value, opening);\n }\n }\n\n /** A custom element's start tag: a Gyral component, a provider, or a plain element. */\n protected open(\n tag: string,\n html: string,\n attrs: readonly (readonly [string, string])[],\n ): Opening | undefined {\n this.buf += html;\n const component = serverComponent(tag);\n const provider = component === undefined ? serverProvider(tag) : undefined;\n if (component === undefined && provider === undefined) return undefined;\n return { tag, component, provider, attributes: Object.fromEntries(attrs), properties: {} };\n }\n\n protected openEnd(opening: Opening | undefined): Frame {\n if (opening === undefined) {\n this.buf += '>';\n return PLAIN;\n }\n const { attributes, properties } = opening;\n const messages = properties['initialMessages'];\n const input: ServerRenderInput = {\n attributes,\n properties,\n initialMessages: Array.isArray(messages) ? (messages as readonly unknown[]) : undefined,\n scope: this.scope,\n };\n if (opening.provider !== undefined) {\n const provided = opening.provider.open(input);\n for (const [name, value] of Object.entries(provided.attributes)) {\n this.buf += ` ${name}=\"${escapeAttr(value)}\"`;\n }\n this.buf += '>';\n const frame: Frame = { k: 'provider', outer: this.scope };\n this.scope = provided.scope;\n return frame;\n }\n const component = opening.component as ServerComponent; // Sound: open() set one of the two.\n this.flush();\n this.items.push({ component, input });\n return component.light ? { k: 'light', tag: opening.tag, items: this.items.length } : PLAIN;\n }\n\n protected close(frame: Frame, tag: string): void {\n if (frame.k === 'provider') this.scope = frame.outer;\n else if (frame.k === 'light') {\n // Whitespace-only children are dropped; anything else is an error (ADR 0014).\n if (this.items.length !== frame.items || !onlyWhitespace(this.buf)) {\n lightChildrenError(frame.tag);\n }\n this.buf = '';\n }\n this.buf += `</${tag}>`;\n }\n}\n"]}
@@ -10,6 +10,8 @@ export declare function multiText(values: readonly unknown[], from: number, stri
10
10
  export declare function textContent(v: unknown, at: object, dev: boolean): string;
11
11
  /** Text written directly in table structure would be foster-parented (rule 7). */
12
12
  export declare function fosterError(text: string, parent: string): never;
13
+ /** An svg template written outside SVG content (`parent`: its parent's name, if known). */
14
+ export declare function svgPlacementError(parent: string | undefined): never;
13
15
  /** A light-DOM component owns its children (ADR 0014). */
14
16
  export declare function lightChildrenError(tag: string): never;
15
17
  /** An attribute name from a hook's server half must not break the start tag. */
@@ -70,6 +70,14 @@ export function fosterError(text, parent) {
70
70
  'the page would differ from what the client renders. Put text inside a <td>, <th> or ' +
71
71
  `<caption> (${SPEC}/09-template-rules.md, rule 7).`);
72
72
  }
73
+ /** An svg template written outside SVG content (`parent`: its parent's name, if known). */
74
+ export function svgPlacementError(parent) {
75
+ throw new Error(`gyral: an svg template is written ${parent === undefined ? 'at the root of a view' : `inside <${parent}>`}, ` +
76
+ "which isn't SVG content, so the parser would not create SVG elements and the page " +
77
+ 'would differ from what the client renders. Render svg`…` fragments inside an <svg> (or ' +
78
+ 'another SVG element, not <foreignObject>) of an html template, or write the whole ' +
79
+ `graphic with html (${SPEC}/01-templates.md "svg templates").`);
80
+ }
73
81
  /** A light-DOM component owns its children (ADR 0014). */
74
82
  export function lightChildrenError(tag) {
75
83
  throw new Error(`gyral: <${tag}> renders in light DOM (shadow: false), so it owns its children, but its ` +
@@ -1 +1 @@
1
- {"version":3,"file":"values.js","sourceRoot":"","sources":["../../../src/view/server/values.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,yFAAyF;AACzF,4FAA4F;AAC5F,4FAA4F;AAC5F,8EAA8E;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAExD,MAAM,IAAI,GAAG,uBAAuB,CAAC;AAErC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAU,EAAW,EAAE,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,OAAO,CAAC;AAC9F,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAU,EAAW,EAAE,CAAC,CAAC,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC;AAEpE,MAAM,QAAQ,GAAG,CAAC,CAAU,EAAe,EAAE,CAC3C,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,OAAO,CAAC,KAAK,UAAU,CAAC;AAEnE,2FAA2F;AAC3F,MAAM,IAAI,GAAG,MAAoC,CAAC;AAElD,MAAM,UAAU,GAAG,CAAC,CAAS,EAAW,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CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC5C,MAAM,IAAI,KAAK,CACb,WAAW,GAAG,2EAA2E;QACvF,uFAAuF;QACvF,6BAA6B,IAAI,wCAAwC,CAC5E,CAAC;AACJ,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,IAAI,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO;IACzC,MAAM,IAAI,SAAS,CACjB,oEAAoE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI;QAC1F,uCAAuC,IAAI,mCAAmC,CACjF,CAAC;AACJ,CAAC","sourcesContent":["// Value rules for attribute and text-content holes on the server (view/02-bindings.md\n// \"Attribute values\", \"Live form state\"; view/06-server.md \"Writing a template result\"),\n// identical to the client's (render/attr-parts.ts) so both sides write the same attributes.\n// And the server-only errors: a Promise anywhere (renders are synchronous), text the parser\n// would move out of table structure, children given to a light-DOM component.\nimport { nothing } from '../render/values.js';\nimport { warnTrue, warnValue } from '../render/warn.js';\n\nconst SPEC = 'docs/design-docs/view';\n\nexport const absent = (v: unknown): boolean => v === null || v === undefined || v === nothing;\nexport const truthy = (v: unknown): boolean => v !== nothing && !!v;\n\nconst isObject = (v: unknown): v is object =>\n (typeof v === 'object' && v !== null) || typeof v === 'function';\n\n/** `String(v)`: objects and functions as the client writes them (render/attr-parts.ts). */\nconst text = String as (value: unknown) => string;\n\nconst isThenable = (v: object): boolean =>\n typeof (v as { readonly then?: unknown }).then === 'function';\n\n/** A Promise in any hole: server renders are synchronous (06 \"API\"). Always an error. */\nexport function checkPromise(v: object, where: string): void {\n if (!isThenable(v)) return;\n throw new TypeError(\n `gyral: ${where} got a Promise. Server renders are synchronous: state is known before ` +\n 'rendering, so load the data first (in the route handler or a form action) and pass ' +\n `it as props (${SPEC}/06-server.md \"API\").`,\n );\n}\n\n/** `String(v)` for an attribute value, with the development warning for objects. */\nfunction written(v: unknown, at: object, name: string, dev: boolean): string {\n if (typeof v === 'string') return v;\n if (isObject(v)) {\n checkPromise(v, `the attribute ${name}`);\n if (dev) warnValue(at, v, `the attribute ${name}`);\n }\n return text(v);\n}\n\n/** `name=${v}`: the value to write, or null to leave the attribute out. */\nexport function attrText(v: unknown, at: object, name: string, dev: boolean): string | null {\n return absent(v) ? null : written(v, at, name, dev);\n}\n\n/** `name=\"a ${x} b\"`: pieces joined; `nothing` in any piece leaves the attribute out. */\nexport function multiText(\n values: readonly unknown[],\n from: number,\n strings: readonly string[],\n at: object,\n name: string,\n dev: boolean,\n): string | null {\n let joined = strings[0] ?? '';\n for (let i = 1; i < strings.length; i++) {\n const v = values[from + i - 1];\n if (v === nothing) return null;\n joined +=\n (v === null || v === undefined ? '' : written(v, at, name, dev)) + (strings[i] as string);\n }\n return joined;\n}\n\n/** `<textarea>`/`<title>` content: child-hole rules flattened to a string, as on the client. */\nexport function textContent(v: unknown, at: object, dev: boolean): string {\n if (typeof v === 'string') return v;\n if (typeof v === 'number') return String(v);\n if (isObject(v)) {\n checkPromise(v, 'the text content');\n if (dev) warnValue(at, v, 'the text content');\n return text(v);\n }\n if (dev && v === true) warnTrue(at);\n return '';\n}\n\n/** Text written directly in table structure would be foster-parented (rule 7). */\nexport function fosterError(text: string, parent: string): never {\n throw new Error(\n `gyral: the text ${JSON.stringify(text.slice(0, 40))} is written directly inside ` +\n `<${parent}>. The HTML parser moves text out of table structure (foster parenting), so ` +\n 'the page would differ from what the client renders. Put text inside a <td>, <th> or ' +\n `<caption> (${SPEC}/09-template-rules.md, rule 7).`,\n );\n}\n\n/** A light-DOM component owns its children (ADR 0014). */\nexport function lightChildrenError(tag: string): never {\n throw new Error(\n `gyral: <${tag}> renders in light DOM (shadow: false), so it owns its children, but its ` +\n 'parent wrote children inside it. Pass the data as props instead, or make it a shadow ' +\n `component and use <slot> (${SPEC}/06-server.md \"Components\", ADR 0014).`,\n );\n}\n\n/** An attribute name from a hook's server half must not break the start tag. */\nexport function checkAttrName(name: string): void {\n if (/^[^\\s\"'>/=\\0]+$/.test(name)) return;\n throw new TypeError(\n `gyral: an element hook's server half returned the attribute name ${JSON.stringify(name)}, ` +\n `which isn't a valid attribute name (${SPEC}/02-bindings.md \"Element hooks\").`,\n );\n}\n"]}
1
+ {"version":3,"file":"values.js","sourceRoot":"","sources":["../../../src/view/server/values.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,yFAAyF;AACzF,4FAA4F;AAC5F,4FAA4F;AAC5F,8EAA8E;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAExD,MAAM,IAAI,GAAG,uBAAuB,CAAC;AAErC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAU,EAAW,EAAE,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,OAAO,CAAC;AAC9F,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAU,EAAW,EAAE,CAAC,CAAC,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC;AAEpE,MAAM,QAAQ,GAAG,CAAC,CAAU,EAAe,EAAE,CAC3C,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,OAAO,CAAC,KAAK,UAAU,CAAC;AAEnE,2FAA2F;AAC3F,MAAM,IAAI,GAAG,MAAoC,CAAC;AAElD,MAAM,UAAU,GAAG,CAAC,CAAS,EAAW,EAAE,CACxC,OAAQ,CAAiC,CAAC,IAAI,KAAK,UAAU,CAAC;AAEhE,yFAAyF;AACzF,MAAM,UAAU,YAAY,CAAC,CAAS,EAAE,KAAa;IACnD,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;QAAE,OAAO;IAC3B,MAAM,IAAI,SAAS,CACjB,UAAU,KAAK,wEAAwE;QACrF,qFAAqF;QACrF,gBAAgB,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oC,CACjE,CAAC;AACJ,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC5C,MAAM,IAAI,KAAK,CACb,WAAW,GAAG,2EAA2E;QACvF,uFAAuF;QACvF,6BAA6B,IAAI,wCAAwC,CAC5E,CAAC;AACJ,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,IAAI,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO;IACzC,MAAM,IAAI,SAAS,CACjB,oEAAoE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI;QAC1F,uCAAuC,IAAI,mCAAmC,CACjF,CAAC;AACJ,CAAC","sourcesContent":["// Value rules for attribute and text-content holes on the server (view/02-bindings.md\n// \"Attribute values\", \"Live form state\"; view/06-server.md \"Writing a template result\"),\n// identical to the client's (render/attr-parts.ts) so both sides write the same attributes.\n// And the server-only errors: a Promise anywhere (renders are synchronous), text the parser\n// would move out of table structure, children given to a light-DOM component.\nimport { nothing } from '../render/values.js';\nimport { warnTrue, warnValue } from '../render/warn.js';\n\nconst SPEC = 'docs/design-docs/view';\n\nexport const absent = (v: unknown): boolean => v === null || v === undefined || v === nothing;\nexport const truthy = (v: unknown): boolean => v !== nothing && !!v;\n\nconst isObject = (v: unknown): v is object =>\n (typeof v === 'object' && v !== null) || typeof v === 'function';\n\n/** `String(v)`: objects and functions as the client writes them (render/attr-parts.ts). */\nconst text = String as (value: unknown) => string;\n\nconst isThenable = (v: object): boolean =>\n typeof (v as { readonly then?: unknown }).then === 'function';\n\n/** A Promise in any hole: server renders are synchronous (06 \"API\"). Always an error. */\nexport function checkPromise(v: object, where: string): void {\n if (!isThenable(v)) return;\n throw new TypeError(\n `gyral: ${where} got a Promise. Server renders are synchronous: state is known before ` +\n 'rendering, so load the data first (in the route handler or a form action) and pass ' +\n `it as props (${SPEC}/06-server.md \"API\").`,\n );\n}\n\n/** `String(v)` for an attribute value, with the development warning for objects. */\nfunction written(v: unknown, at: object, name: string, dev: boolean): string {\n if (typeof v === 'string') return v;\n if (isObject(v)) {\n checkPromise(v, `the attribute ${name}`);\n if (dev) warnValue(at, v, `the attribute ${name}`);\n }\n return text(v);\n}\n\n/** `name=${v}`: the value to write, or null to leave the attribute out. */\nexport function attrText(v: unknown, at: object, name: string, dev: boolean): string | null {\n return absent(v) ? null : written(v, at, name, dev);\n}\n\n/** `name=\"a ${x} b\"`: pieces joined; `nothing` in any piece leaves the attribute out. */\nexport function multiText(\n values: readonly unknown[],\n from: number,\n strings: readonly string[],\n at: object,\n name: string,\n dev: boolean,\n): string | null {\n let joined = strings[0] ?? '';\n for (let i = 1; i < strings.length; i++) {\n const v = values[from + i - 1];\n if (v === nothing) return null;\n joined +=\n (v === null || v === undefined ? '' : written(v, at, name, dev)) + (strings[i] as string);\n }\n return joined;\n}\n\n/** `<textarea>`/`<title>` content: child-hole rules flattened to a string, as on the client. */\nexport function textContent(v: unknown, at: object, dev: boolean): string {\n if (typeof v === 'string') return v;\n if (typeof v === 'number') return String(v);\n if (isObject(v)) {\n checkPromise(v, 'the text content');\n if (dev) warnValue(at, v, 'the text content');\n return text(v);\n }\n if (dev && v === true) warnTrue(at);\n return '';\n}\n\n/** Text written directly in table structure would be foster-parented (rule 7). */\nexport function fosterError(text: string, parent: string): never {\n throw new Error(\n `gyral: the text ${JSON.stringify(text.slice(0, 40))} is written directly inside ` +\n `<${parent}>. The HTML parser moves text out of table structure (foster parenting), so ` +\n 'the page would differ from what the client renders. Put text inside a <td>, <th> or ' +\n `<caption> (${SPEC}/09-template-rules.md, rule 7).`,\n );\n}\n\n/** An svg template written outside SVG content (`parent`: its parent's name, if known). */\nexport function svgPlacementError(parent: string | undefined): never {\n throw new Error(\n `gyral: an svg template is written ${parent === undefined ? 'at the root of a view' : `inside <${parent}>`}, ` +\n \"which isn't SVG content, so the parser would not create SVG elements and the page \" +\n 'would differ from what the client renders. Render svg`…` fragments inside an <svg> (or ' +\n 'another SVG element, not <foreignObject>) of an html template, or write the whole ' +\n `graphic with html (${SPEC}/01-templates.md \"svg templates\").`,\n );\n}\n\n/** A light-DOM component owns its children (ADR 0014). */\nexport function lightChildrenError(tag: string): never {\n throw new Error(\n `gyral: <${tag}> renders in light DOM (shadow: false), so it owns its children, but its ` +\n 'parent wrote children inside it. Pass the data as props instead, or make it a shadow ' +\n `component and use <slot> (${SPEC}/06-server.md \"Components\", ADR 0014).`,\n );\n}\n\n/** An attribute name from a hook's server half must not break the start tag. */\nexport function checkAttrName(name: string): void {\n if (/^[^\\s\"'>/=\\0]+$/.test(name)) return;\n throw new TypeError(\n `gyral: an element hook's server half returned the attribute name ${JSON.stringify(name)}, ` +\n `which isn't a valid attribute name (${SPEC}/02-bindings.md \"Element hooks\").`,\n );\n}\n"]}
@@ -1,16 +1,21 @@
1
1
  import { type TemplateResult } from '../template.js';
2
2
  import { Markup } from './tags.js';
3
- export type { Deferred, Item } from './tags.js';
3
+ export type { Deferred, Item, StyleValues } from './tags.js';
4
+ /**
5
+ * What a child hole's parent means for its value (the development checks): a table tag (text
6
+ * would be foster-parented), SVG content (where svg templates may render), or nothing.
7
+ */
8
+ type Ctx = string | undefined;
4
9
  /** Warning key for values outside any template (the render root, a component's view). */
5
10
  export declare const ROOT: object;
6
11
  export declare class Writer extends Markup {
7
12
  /** Writing a page shell's holes (a `server` template): never hydrated, so no anchors (06). */
8
13
  private shell;
9
- /** A child value (02 "Child values"). `table`: the parent, when it is table structure. */
10
- child(v: unknown, table: string | undefined, at: object): void;
14
+ /** A child value (02 "Child values"). `ctx`: what its parent is (`Ctx`). */
15
+ child(v: unknown, ctx: Ctx, at: object): void;
11
16
  private object;
12
17
  /** `each(…)`: rows one after another, no markers (03). Keys are checked in development. */
13
18
  private list;
14
19
  /** One template instance: its segments with this render's values. */
15
- template(result: TemplateResult, table: string | undefined): void;
20
+ template(result: TemplateResult, ctx: Ctx): void;
16
21
  }
@@ -7,10 +7,13 @@ import { badChild, badKey, warnTrue } from '../render/warn.js';
7
7
  import { isTemplateResult, templateOf } from '../template.js';
8
8
  import { escapeText, onlyWhitespace } from './escape.js';
9
9
  import { Markup, PLAIN } from './tags.js';
10
- import { checkPromise, fosterError, textContent, truthy } from './values.js';
10
+ import { checkPromise, fosterError, svgPlacementError, textContent, truthy } from './values.js';
11
11
  /** Parents in which the parser moves non-whitespace text out (foster parenting). */
12
12
  const TABLE = new Set(['table', 'tbody', 'thead', 'tfoot', 'tr']);
13
- const tableTag = (parent) => (TABLE.has(parent) ? parent : undefined);
13
+ const SVG = '#svg';
14
+ const isTable = (ctx) => ctx !== undefined && TABLE.has(ctx);
15
+ /** A child op's context: its parent's, or the enclosing one at the template root. */
16
+ const ctxOf = (s, outer) => s.svg ? SVG : s.in === undefined ? outer : s.in;
14
17
  /** Warning key for values outside any template (the render root, a component's view). */
15
18
  export const ROOT = {};
16
19
  export class Writer extends Markup {
@@ -19,24 +22,24 @@ export class Writer extends Markup {
19
22
  /** Writing a page shell's holes (a `server` template): never hydrated, so no anchors (06). */
20
23
  this.shell = false;
21
24
  }
22
- /** A child value (02 "Child values"). `table`: the parent, when it is table structure. */
23
- child(v, table, at) {
25
+ /** A child value (02 "Child values"). `ctx`: what its parent is (`Ctx`). */
26
+ child(v, ctx, at) {
24
27
  switch (typeof v) {
25
28
  case 'string':
26
29
  if (v === '')
27
30
  return;
28
- if (table !== undefined && this.dev && !onlyWhitespace(v))
29
- fosterError(v, table);
31
+ if (this.dev && isTable(ctx) && !onlyWhitespace(v))
32
+ fosterError(v, ctx);
30
33
  this.buf += escapeText(v);
31
34
  return;
32
35
  case 'number':
33
- if (table !== undefined && this.dev)
34
- fosterError(String(v), table);
36
+ if (this.dev && isTable(ctx))
37
+ fosterError(String(v), ctx);
35
38
  this.buf += String(v);
36
39
  return;
37
40
  case 'object':
38
41
  if (v !== null)
39
- this.object(v, table, at);
42
+ this.object(v, ctx, at);
40
43
  return;
41
44
  case 'boolean':
42
45
  if (v && this.dev)
@@ -49,18 +52,18 @@ export class Writer extends Markup {
49
52
  badChild(v);
50
53
  }
51
54
  }
52
- object(v, table, at) {
55
+ object(v, ctx, at) {
53
56
  if (isTemplateResult(v)) {
54
- this.template(v, table);
57
+ this.template(v, ctx);
55
58
  return;
56
59
  }
57
60
  if (isList(v)) {
58
- this.list(v, table, at);
61
+ this.list(v, ctx, at);
59
62
  return;
60
63
  }
61
64
  if (Array.isArray(v)) {
62
65
  for (const item of v)
63
- this.child(item, table, at);
66
+ this.child(item, ctx, at);
64
67
  return;
65
68
  }
66
69
  const raw = rawHtml(v);
@@ -74,7 +77,7 @@ export class Writer extends Markup {
74
77
  badChild(v);
75
78
  }
76
79
  /** `each(…)`: rows one after another, no markers (03). Keys are checked in development. */
77
- list(v, table, at) {
80
+ list(v, ctx, at) {
78
81
  const { items, key, row, pick } = v;
79
82
  const seen = this.dev ? new Set() : undefined;
80
83
  for (let i = 0; i < items.length; i++) {
@@ -86,11 +89,11 @@ export class Writer extends Markup {
86
89
  badKey(k, i, dup);
87
90
  seen.add(k);
88
91
  }
89
- this.child(row(item, pick === undefined ? undefined : pick(item)), table, at);
92
+ this.child(row(item, pick === undefined ? undefined : pick(item)), ctx, at);
90
93
  }
91
94
  }
92
95
  /** One template instance: its segments with this render's values. */
93
- template(result, table) {
96
+ template(result, ctx) {
94
97
  const template = templateOf(result);
95
98
  const segments = template.segments;
96
99
  if (segments === undefined) {
@@ -99,13 +102,22 @@ export class Writer extends Markup {
99
102
  '(or the runtime normalizer), which keeps them ' +
100
103
  '(docs/design-docs/view/01-templates.md "Compiled").');
101
104
  }
105
+ // An svg template is SVG content: the parser creates SVG elements only inside SVG (01).
106
+ if (this.dev && template.svg && ctx !== SVG)
107
+ svgPlacementError(ctx);
102
108
  // Development marker: hydration checks the id before each instance (07). Page shells are
103
109
  // never hydrated.
104
110
  if (this.dev && !template.server)
105
111
  this.buf += `<!--gyral:${template.id ?? ''}-->`;
106
112
  const values = result.values;
107
113
  const outer = this.shell;
114
+ const outerWhere = this.where;
108
115
  this.shell = template.server === true;
116
+ if (this.styles !== undefined) {
117
+ this.where = template.loc ?? template.id ?? '';
118
+ for (const css of template.staticStyles ?? [])
119
+ this.style(css);
120
+ }
109
121
  let at = 0;
110
122
  let opening;
111
123
  let frames;
@@ -116,7 +128,7 @@ export class Writer extends Markup {
116
128
  }
117
129
  switch (s.k) {
118
130
  case 'child':
119
- this.child(values[at++], s.in === undefined ? table : tableTag(s.in), s);
131
+ this.child(values[at++], ctxOf(s, ctx), s);
120
132
  break;
121
133
  case 'text':
122
134
  this.buf += escapeText(textContent(values[at++], s, this.dev));
@@ -126,8 +138,10 @@ export class Writer extends Markup {
126
138
  break;
127
139
  case 'bool':
128
140
  // `?indeterminate` has no attribute: it is the property only (02 "Live form state").
129
- if (truthy(values[at]) && s.name !== 'indeterminate')
141
+ // `?modal`/`?popover-open` neither: the browser opens them after hydration (02).
142
+ if (truthy(values[at]) && !/^(indeterminate|modal|popover-open)$/.test(s.name)) {
130
143
  this.bare(s.name, opening);
144
+ }
131
145
  at++;
132
146
  break;
133
147
  case 'prop':
@@ -150,6 +164,7 @@ export class Writer extends Markup {
150
164
  }
151
165
  }
152
166
  this.shell = outer;
167
+ this.where = outerWhere;
153
168
  }
154
169
  }
155
170
  //# sourceMappingURL=writer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"writer.js","sourceRoot":"","sources":["../../../src/view/server/writer.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,+FAA+F;AAC/F,6FAA6F;AAC7F,wBAAwB;AACxB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAmB,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAuB,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACzD,OAA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BACR,KAAK,MAAM;oBACT,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;oBACvC,MAAM;gBACR,KAAK,MAAM;oBACT,qFAAqF;oBACrF,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,eAAe;wBAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;oBACjF,EAAE,EAAE,CAAC;oBACL,MAAM;gBACR,KAAK,MAAM;oBACT,IAAI,OAAO,KAAK,SAAS;wBAAE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;oBACnE,EAAE,EAAE,CAAC;oBACL,MAAM;gBACR,KAAK,MAAM;oBACT,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;oBACjC,MAAM;gBACR,KAAK,MAAM;oBACT,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;oBAC5C,MAAM;gBACR,KAAK,SAAS;oBACZ,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;oBAC5C,OAAO,GAAG,SAAS,CAAC;oBACpB,MAAM;gBACR,KAAK,OAAO;oBACV,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,KAAK,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;YAC9C,CAAC;QACH,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF","sourcesContent":["// The server renderer's walk (view/06-server.md \"Writing a template result\"): writes a child\n// value by walking template objects' `segments` (01), never tokenizing or building a DOM. Each\n// string segment is written verbatim; each hole op takes its value(s). Start tags and custom\n// elements are tags.ts.\nimport { isList, nothing, rawHtml, type ListResult } from '../render/values.js';\nimport { badChild, badKey, warnTrue } from '../render/warn.js';\nimport { isTemplateResult, templateOf, type TemplateResult } from '../template.js';\nimport { escapeText, onlyWhitespace } from './escape.js';\nimport { Markup, PLAIN, type Frame, type Opening } from './tags.js';\nimport { checkPromise, fosterError, textContent, truthy } from './values.js';\n\nexport type { Deferred, Item } from './tags.js';\n\n/** Parents in which the parser moves non-whitespace text out (foster parenting). */\nconst TABLE = new Set(['table', 'tbody', 'thead', 'tfoot', 'tr']);\n\nconst tableTag = (parent: string): string | undefined => (TABLE.has(parent) ? parent : undefined);\n\n/** Warning key for values outside any template (the render root, a component's view). */\nexport const ROOT: object = {};\n\nexport class Writer extends Markup {\n /** Writing a page shell's holes (a `server` template): never hydrated, so no anchors (06). */\n private shell = false;\n\n /** A child value (02 \"Child values\"). `table`: the parent, when it is table structure. */\n child(v: unknown, table: string | undefined, at: object): void {\n switch (typeof v) {\n case 'string':\n if (v === '') return;\n if (table !== undefined && this.dev && !onlyWhitespace(v)) fosterError(v, table);\n this.buf += escapeText(v);\n return;\n case 'number':\n if (table !== undefined && this.dev) fosterError(String(v), table);\n this.buf += String(v);\n return;\n case 'object':\n if (v !== null) this.object(v, table, at);\n return;\n case 'boolean':\n if (v && this.dev) warnTrue(at);\n return;\n case 'undefined':\n return;\n default:\n if (v !== nothing && this.dev) badChild(v);\n }\n }\n\n private object(v: object, table: string | undefined, at: object): void {\n if (isTemplateResult(v)) {\n this.template(v, table);\n return;\n }\n if (isList(v)) {\n this.list(v, table, at);\n return;\n }\n if (Array.isArray(v)) {\n for (const item of v as readonly unknown[]) this.child(item, table, at);\n return;\n }\n const raw = rawHtml(v);\n if (raw !== undefined) {\n // The start anchor hydration finds (02 \"raw(html)\"); a page shell is never hydrated.\n this.buf += this.shell ? raw : `<!---->${raw}`;\n return;\n }\n checkPromise(v, 'a child hole');\n if (this.dev) badChild(v);\n }\n\n /** `each(…)`: rows one after another, no markers (03). Keys are checked in development. */\n private list(v: ListResult, table: string | undefined, at: object): void {\n const { items, key, row, pick } = v;\n const seen = this.dev ? new Set<unknown>() : undefined;\n for (let i = 0; i < items.length; i++) {\n const item = items[i];\n if (seen !== undefined) {\n const k = key(item);\n const dup = seen.has(k);\n if (dup || (typeof k !== 'string' && typeof k !== 'number')) badKey(k, i, dup);\n seen.add(k);\n }\n this.child(row(item, pick === undefined ? undefined : pick(item)), table, at);\n }\n }\n\n /** One template instance: its segments with this render's values. */\n template(result: TemplateResult, table: string | undefined): void {\n const template = templateOf(result);\n const segments = template.segments;\n if (segments === undefined) {\n throw new Error(\n `gyral: template ${JSON.stringify(template.html.slice(0, 40))} has no server ` +\n 'segments: it was compiled for the client. Render on the server with an SSR build ' +\n '(or the runtime normalizer), which keeps them ' +\n '(docs/design-docs/view/01-templates.md \"Compiled\").',\n );\n }\n // Development marker: hydration checks the id before each instance (07). Page shells are\n // never hydrated.\n if (this.dev && !template.server) this.buf += `<!--gyral:${template.id ?? ''}-->`;\n const values = result.values;\n const outer = this.shell;\n this.shell = template.server === true;\n let at = 0;\n let opening: Opening | undefined;\n let frames: Frame[] | undefined;\n for (const s of segments) {\n if (typeof s === 'string') {\n this.buf += s;\n continue;\n }\n switch (s.k) {\n case 'child':\n this.child(values[at++], s.in === undefined ? table : tableTag(s.in), s);\n break;\n case 'text':\n this.buf += escapeText(textContent(values[at++], s, this.dev));\n break;\n case 'attr':\n at = this.attr(s, values, at, opening);\n break;\n case 'bool':\n // `?indeterminate` has no attribute: it is the property only (02 \"Live form state\").\n if (truthy(values[at]) && s.name !== 'indeterminate') this.bare(s.name, opening);\n at++;\n break;\n case 'prop':\n if (opening !== undefined) opening.properties[s.name] = values[at];\n at++;\n break;\n case 'hook':\n this.hook(values[at++], opening);\n break;\n case 'open':\n opening = this.open(s.tag, s.html, s.attrs);\n break;\n case 'openEnd':\n (frames ??= []).push(this.openEnd(opening));\n opening = undefined;\n break;\n case 'close':\n this.close(frames?.pop() ?? PLAIN, s.tag);\n }\n }\n this.shell = outer;\n }\n}\n"]}
1
+ {"version":3,"file":"writer.js","sourceRoot":"","sources":["../../../src/view/server/writer.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,+FAA+F;AAC/F,6FAA6F;AAC7F,wBAAwB;AACxB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAmB,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAuB,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,KAAK,EAA4B,MAAM,WAAW,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIhG,oFAAoF;AACpF,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;AAOlE,MAAM,GAAG,GAAQ,MAAM,CAAC;AAExB,MAAM,OAAO,GAAG,CAAC,GAAQ,EAAiB,EAAE,CAAC,GAAG,KAAK,SAAS,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAEjF,qFAAqF;AACrF,MAAM,KAAK,GAAG,CAAC,CAAgD,EAAE,KAAU,EAAO,EAAE,CAClF,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAElD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B,CAAC;CACF","sourcesContent":["// The server renderer's walk (view/06-server.md \"Writing a template result\"): writes a child\n// value by walking template objects' `segments` (01), never tokenizing or building a DOM. Each\n// string segment is written verbatim; each hole op takes its value(s). Start tags and custom\n// elements are tags.ts.\nimport { isList, nothing, rawHtml, type ListResult } from '../render/values.js';\nimport { badChild, badKey, warnTrue } from '../render/warn.js';\nimport { isTemplateResult, templateOf, type TemplateResult } from '../template.js';\nimport { escapeText, onlyWhitespace } from './escape.js';\nimport { Markup, PLAIN, type Frame, type Opening } from './tags.js';\nimport { checkPromise, fosterError, svgPlacementError, textContent, truthy } from './values.js';\n\nexport type { Deferred, Item, StyleValues } from './tags.js';\n\n/** Parents in which the parser moves non-whitespace text out (foster parenting). */\nconst TABLE = new Set(['table', 'tbody', 'thead', 'tfoot', 'tr']);\n\n/**\n * What a child hole's parent means for its value (the development checks): a table tag (text\n * would be foster-parented), SVG content (where svg templates may render), or nothing.\n */\ntype Ctx = string | undefined;\nconst SVG: Ctx = '#svg';\n\nconst isTable = (ctx: Ctx): ctx is string => ctx !== undefined && TABLE.has(ctx);\n\n/** A child op's context: its parent's, or the enclosing one at the template root. */\nconst ctxOf = (s: { readonly in?: string; readonly svg?: true }, outer: Ctx): Ctx =>\n s.svg ? SVG : s.in === undefined ? outer : s.in;\n\n/** Warning key for values outside any template (the render root, a component's view). */\nexport const ROOT: object = {};\n\nexport class Writer extends Markup {\n /** Writing a page shell's holes (a `server` template): never hydrated, so no anchors (06). */\n private shell = false;\n\n /** A child value (02 \"Child values\"). `ctx`: what its parent is (`Ctx`). */\n child(v: unknown, ctx: Ctx, at: object): void {\n switch (typeof v) {\n case 'string':\n if (v === '') return;\n if (this.dev && isTable(ctx) && !onlyWhitespace(v)) fosterError(v, ctx);\n this.buf += escapeText(v);\n return;\n case 'number':\n if (this.dev && isTable(ctx)) fosterError(String(v), ctx);\n this.buf += String(v);\n return;\n case 'object':\n if (v !== null) this.object(v, ctx, at);\n return;\n case 'boolean':\n if (v && this.dev) warnTrue(at);\n return;\n case 'undefined':\n return;\n default:\n if (v !== nothing && this.dev) badChild(v);\n }\n }\n\n private object(v: object, ctx: Ctx, at: object): void {\n if (isTemplateResult(v)) {\n this.template(v, ctx);\n return;\n }\n if (isList(v)) {\n this.list(v, ctx, at);\n return;\n }\n if (Array.isArray(v)) {\n for (const item of v as readonly unknown[]) this.child(item, ctx, at);\n return;\n }\n const raw = rawHtml(v);\n if (raw !== undefined) {\n // The start anchor hydration finds (02 \"raw(html)\"); a page shell is never hydrated.\n this.buf += this.shell ? raw : `<!---->${raw}`;\n return;\n }\n checkPromise(v, 'a child hole');\n if (this.dev) badChild(v);\n }\n\n /** `each(…)`: rows one after another, no markers (03). Keys are checked in development. */\n private list(v: ListResult, ctx: Ctx, at: object): void {\n const { items, key, row, pick } = v;\n const seen = this.dev ? new Set<unknown>() : undefined;\n for (let i = 0; i < items.length; i++) {\n const item = items[i];\n if (seen !== undefined) {\n const k = key(item);\n const dup = seen.has(k);\n if (dup || (typeof k !== 'string' && typeof k !== 'number')) badKey(k, i, dup);\n seen.add(k);\n }\n this.child(row(item, pick === undefined ? undefined : pick(item)), ctx, at);\n }\n }\n\n /** One template instance: its segments with this render's values. */\n template(result: TemplateResult, ctx: Ctx): void {\n const template = templateOf(result);\n const segments = template.segments;\n if (segments === undefined) {\n throw new Error(\n `gyral: template ${JSON.stringify(template.html.slice(0, 40))} has no server ` +\n 'segments: it was compiled for the client. Render on the server with an SSR build ' +\n '(or the runtime normalizer), which keeps them ' +\n '(docs/design-docs/view/01-templates.md \"Compiled\").',\n );\n }\n // An svg template is SVG content: the parser creates SVG elements only inside SVG (01).\n if (this.dev && template.svg && ctx !== SVG) svgPlacementError(ctx);\n // Development marker: hydration checks the id before each instance (07). Page shells are\n // never hydrated.\n if (this.dev && !template.server) this.buf += `<!--gyral:${template.id ?? ''}-->`;\n const values = result.values;\n const outer = this.shell;\n const outerWhere = this.where;\n this.shell = template.server === true;\n if (this.styles !== undefined) {\n this.where = template.loc ?? template.id ?? '';\n for (const css of template.staticStyles ?? []) this.style(css);\n }\n let at = 0;\n let opening: Opening | undefined;\n let frames: Frame[] | undefined;\n for (const s of segments) {\n if (typeof s === 'string') {\n this.buf += s;\n continue;\n }\n switch (s.k) {\n case 'child':\n this.child(values[at++], ctxOf(s, ctx), s);\n break;\n case 'text':\n this.buf += escapeText(textContent(values[at++], s, this.dev));\n break;\n case 'attr':\n at = this.attr(s, values, at, opening);\n break;\n case 'bool':\n // `?indeterminate` has no attribute: it is the property only (02 \"Live form state\").\n // `?modal`/`?popover-open` neither: the browser opens them after hydration (02).\n if (truthy(values[at]) && !/^(indeterminate|modal|popover-open)$/.test(s.name)) {\n this.bare(s.name, opening);\n }\n at++;\n break;\n case 'prop':\n if (opening !== undefined) opening.properties[s.name] = values[at];\n at++;\n break;\n case 'hook':\n this.hook(values[at++], opening);\n break;\n case 'open':\n opening = this.open(s.tag, s.html, s.attrs);\n break;\n case 'openEnd':\n (frames ??= []).push(this.openEnd(opening));\n opening = undefined;\n break;\n case 'close':\n this.close(frames?.pop() ?? PLAIN, s.tag);\n }\n }\n this.shell = outer;\n this.where = outerWhere;\n }\n}\n"]}
@@ -1,3 +1,10 @@
1
1
  import type { TemplateObject } from './normalize/types.js';
2
2
  /** The cached <template> element for `template`, parsed (and checked) on first use. */
3
3
  export declare function templateElement(template: TemplateObject): HTMLTemplateElement;
4
+ /**
5
+ * Prepares an svg template's <template> element (01 "svg templates"): its HTML is parsed inside
6
+ * an <svg>, so the parser creates SVG elements (camelCase names and attributes, namespaced
7
+ * static attributes), and that <svg>'s children become the content. Called with every svg
8
+ * result, before anything renders it; outside a document (the server) there is nothing to do.
9
+ */
10
+ export declare function svgTemplate(template: TemplateObject): void;
@@ -1,9 +1,14 @@
1
1
  // One <template> element per template object, created on first use (view/01-templates.md
2
2
  // "Instantiation"). The browser's own parser builds it from the template HTML; the runtime
3
- // preparer then checks the parse (rule 7). Server templates never get one (rule 11).
3
+ // preparer then checks the parse (rule 7). Server templates never get one (rule 11). An svg
4
+ // template's is prepared by `svgTemplate` when its first result is made (template.ts `svg`), so
5
+ // apps without svg templates don't carry that code. Both parse through the `gyral` Trusted Types
6
+ // policy (trusted-html.ts).
4
7
  import { verify } from '#prepare';
5
8
  import { DEV } from '#view-dev';
9
+ import { message } from './message.js';
6
10
  import { SERVER_ONLY, TemplateError } from './normalize/errors.js';
11
+ import { trustedHTML } from './trusted-html.js';
7
12
  const elements = new WeakMap();
8
13
  /** The cached <template> element for `template`, parsed (and checked) on first use. */
9
14
  export function templateElement(template) {
@@ -12,14 +17,29 @@ export function templateElement(template) {
12
17
  return cached;
13
18
  if (template.server) {
14
19
  // Production keeps a short message: the class and its explanation stay out of the bundle.
15
- throw DEV
16
- ? new TemplateError(11, SERVER_ONLY, template.loc)
17
- : new Error('gyral: template rule 11: a page shell rendered in the browser.');
20
+ throw DEV ? new TemplateError(11, SERVER_ONLY, template.loc) : new Error(message(71));
18
21
  }
19
22
  const el = document.createElement('template');
20
- el.innerHTML = template.html;
23
+ el.innerHTML = trustedHTML(template.html);
21
24
  verify(template, el);
22
25
  elements.set(template, el);
23
26
  return el;
24
27
  }
28
+ /**
29
+ * Prepares an svg template's <template> element (01 "svg templates"): its HTML is parsed inside
30
+ * an <svg>, so the parser creates SVG elements (camelCase names and attributes, namespaced
31
+ * static attributes), and that <svg>'s children become the content. Called with every svg
32
+ * result, before anything renders it; outside a document (the server) there is nothing to do.
33
+ */
34
+ export function svgTemplate(template) {
35
+ if (elements.has(template) || typeof document === 'undefined')
36
+ return;
37
+ const el = document.createElement('template');
38
+ el.innerHTML = trustedHTML(`<svg>${template.html}</svg>`);
39
+ const content = el.content;
40
+ // Anything the parser moved out of the <svg> is dropped here, and the check reports it.
41
+ content.replaceChildren(...content.firstChild.childNodes);
42
+ verify(template, el);
43
+ elements.set(template, el);
44
+ }
25
45
  //# sourceMappingURL=template-element.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"template-element.js","sourceRoot":"","sources":["../../src/view/template-element.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,2FAA2F;AAC3F,qFAAqF;AACrF,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAGnE,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAuC,CAAC;AAEpE,uFAAuF;AACvF,MAAM,UAAU,eAAe,CAAC,QAAwB;IACtD,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACtC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC;IACxC,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;QACpB,0FAA0F;QAC1F,MAAM,GAAG;YACP,CAAC,CAAC,IAAI,aAAa,CAAC,EAAE,EAAE,WAAW,EAAE,QAAQ,CAAC,GAAG,CAAC;YAClD,CAAC,CAAC,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;IAClF,CAAC;IACD,MAAM,EAAE,GAAG,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IAC9C,EAAE,CAAC,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC;IAC7B,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IACrB,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAC3B,OAAO,EAAE,CAAC;AACZ,CAAC","sourcesContent":["// One <template> element per template object, created on first use (view/01-templates.md\n// \"Instantiation\"). The browser's own parser builds it from the template HTML; the runtime\n// preparer then checks the parse (rule 7). Server templates never get one (rule 11).\nimport { verify } from '#prepare';\nimport { DEV } from '#view-dev';\nimport { SERVER_ONLY, TemplateError } from './normalize/errors.js';\nimport type { TemplateObject } from './normalize/types.js';\n\nconst elements = new WeakMap<TemplateObject, HTMLTemplateElement>();\n\n/** The cached <template> element for `template`, parsed (and checked) on first use. */\nexport function templateElement(template: TemplateObject): HTMLTemplateElement {\n const cached = elements.get(template);\n if (cached !== undefined) return cached;\n if (template.server) {\n // Production keeps a short message: the class and its explanation stay out of the bundle.\n throw DEV\n ? new TemplateError(11, SERVER_ONLY, template.loc)\n : new Error('gyral: template rule 11: a page shell rendered in the browser.');\n }\n const el = document.createElement('template');\n el.innerHTML = template.html;\n verify(template, el);\n elements.set(template, el);\n return el;\n}\n"]}
1
+ {"version":3,"file":"template-element.js","sourceRoot":"","sources":["../../src/view/template-element.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,2FAA2F;AAC3F,4FAA4F;AAC5F,gGAAgG;AAChG,iGAAiG;AACjG,4BAA4B;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEnE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAuC,CAAC;AAEpE,uFAAuF;AACvF,MAAM,UAAU,eAAe,CAAC,QAAwB;IACtD,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACtC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC;IACxC,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;QACpB,0FAA0F;QAC1F,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,aAAa,CAAC,EAAE,EAAE,WAAW,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IACxF,CAAC;IACD,MAAM,EAAE,GAAG,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IAC9C,EAAE,CAAC,SAAS,GAAG,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC1C,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IACrB,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAC3B,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,QAAwB;IAClD,IAAI,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,OAAO,QAAQ,KAAK,WAAW;QAAE,OAAO;IACtE,MAAM,EAAE,GAAG,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IAC9C,EAAE,CAAC,SAAS,GAAG,WAAW,CAAC,QAAQ,QAAQ,CAAC,IAAI,QAAQ,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC;IAC3B,wFAAwF;IACxF,OAAO,CAAC,eAAe,CAAC,GAAI,OAAO,CAAC,UAAsB,CAAC,UAAU,CAAC,CAAC;IACvE,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IACrB,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["// One <template> element per template object, created on first use (view/01-templates.md\n// \"Instantiation\"). The browser's own parser builds it from the template HTML; the runtime\n// preparer then checks the parse (rule 7). Server templates never get one (rule 11). An svg\n// template's is prepared by `svgTemplate` when its first result is made (template.ts `svg`), so\n// apps without svg templates don't carry that code. Both parse through the `gyral` Trusted Types\n// policy (trusted-html.ts).\nimport { verify } from '#prepare';\nimport { DEV } from '#view-dev';\nimport { message } from './message.js';\nimport { SERVER_ONLY, TemplateError } from './normalize/errors.js';\nimport type { TemplateObject } from './normalize/types.js';\nimport { trustedHTML } from './trusted-html.js';\n\nconst elements = new WeakMap<TemplateObject, HTMLTemplateElement>();\n\n/** The cached <template> element for `template`, parsed (and checked) on first use. */\nexport function templateElement(template: TemplateObject): HTMLTemplateElement {\n const cached = elements.get(template);\n if (cached !== undefined) return cached;\n if (template.server) {\n // Production keeps a short message: the class and its explanation stay out of the bundle.\n throw DEV ? new TemplateError(11, SERVER_ONLY, template.loc) : new Error(message(71));\n }\n const el = document.createElement('template');\n el.innerHTML = trustedHTML(template.html);\n verify(template, el);\n elements.set(template, el);\n return el;\n}\n\n/**\n * Prepares an svg template's <template> element (01 \"svg templates\"): its HTML is parsed inside\n * an <svg>, so the parser creates SVG elements (camelCase names and attributes, namespaced\n * static attributes), and that <svg>'s children become the content. Called with every svg\n * result, before anything renders it; outside a document (the server) there is nothing to do.\n */\nexport function svgTemplate(template: TemplateObject): void {\n if (elements.has(template) || typeof document === 'undefined') return;\n const el = document.createElement('template');\n el.innerHTML = trustedHTML(`<svg>${template.html}</svg>`);\n const content = el.content;\n // Anything the parser moved out of the <svg> is dropped here, and the check reports it.\n content.replaceChildren(...(content.firstChild as Element).childNodes);\n verify(template, el);\n elements.set(template, el);\n}\n"]}
@@ -6,9 +6,17 @@ export interface TemplateResult {
6
6
  readonly values: readonly unknown[];
7
7
  }
8
8
  /** The template tag: `` html`<p>${s.text}</p>` ``. */
9
- export declare function html(strings: TemplateStringsArray, ...values: unknown[]): TemplateResult;
10
- /** Internal: what the template compiler (Phase 6) rewrites `html` calls into. */
9
+ export declare const html: (strings: TemplateStringsArray, ...values: unknown[]) => TemplateResult;
10
+ /**
11
+ * The SVG fragment tag: `` svg`<path d=${s.d} />` ``. Its top level is SVG content, so it
12
+ * renders only inside an `<svg>` (or another SVG element) of an html template
13
+ * (view/01-templates.md "svg templates"). A whole `<svg>` graphic is written with html.
14
+ */
15
+ export declare const svg: (strings: TemplateStringsArray, ...values: unknown[]) => TemplateResult;
16
+ /** Internal: what the template compiler (`@gyral/core/vite`) rewrites `html` calls into. */
11
17
  export declare function compiled(template: TemplateObject, values: readonly unknown[]): TemplateResult;
18
+ /** Internal: what the template compiler rewrites `svg` calls into. */
19
+ export declare function compiledSvg(template: TemplateObject, values: readonly unknown[]): TemplateResult;
12
20
  export declare function isTemplateResult(value: unknown): value is TemplateResult;
13
21
  /** Internal: a result's source, compared by identity to skip `templateOf` on updates. */
14
22
  export declare const sourceOf: (result: TemplateResult) => readonly string[] | TemplateObject;
@@ -1,18 +1,72 @@
1
- // Template results and the `html` tag (view/01-templates.md "Authoring", "Template results").
2
- // A result is a template source (the call site's strings, or a compiled template object) plus
3
- // this call's values, recognised by a module-private symbol so data from JSON can never pass
4
- // for one. `templateOf` turns the source into the template object: compiled results carry it,
5
- // runtime results are normalized once per strings array through `#prepare` (prepare.ts).
1
+ // Template results and the `html` and `svg` tags (view/01-templates.md "Authoring", "Template
2
+ // results", "svg templates"). A result is a template source (the call site's strings, or a
3
+ // template object) plus this call's values, recognised by a module-private symbol so data from
4
+ // JSON can never pass for one. `templateOf` turns the source into the template object: compiled
5
+ // and svg results carry it, html results are normalized once per strings array through
6
+ // `#prepare` (prepare.ts). Development records each call site's source location (loc.ts) for
7
+ // error messages.
6
8
  import { prepare } from '#prepare';
9
+ import { DEV } from '#view-dev';
10
+ import { callSite, locOf, setLoc } from './loc.js';
11
+ import { svgTemplate } from './template-element.js';
7
12
  const SOURCE = Symbol('gyral.template');
8
- /** The template tag: `` html`<p>${s.text}</p>` ``. */
9
- export function html(strings, ...values) {
13
+ /** The template tag, as `html` is in production. */
14
+ function tag(strings, ...values) {
15
+ // Development: the call site, from the stack, the first time (unless `html.at` gave it).
16
+ if (DEV && locOf(strings) === undefined)
17
+ setLoc(strings, callSite(new Error().stack));
10
18
  return { [SOURCE]: strings, values };
11
19
  }
12
- /** Internal: what the template compiler (Phase 6) rewrites `html` calls into. */
20
+ /** The svg tag, as `svg` is in production: svg results carry their (prepared) template. */
21
+ function svgTag(strings, ...values) {
22
+ // Development: the call site, from the stack, the first time (unless `svg.at` gave it), so
23
+ // the normalizer's rule errors name it.
24
+ if (DEV && locOf(strings) === undefined)
25
+ setLoc(strings, callSite(new Error().stack));
26
+ return compiledSvg(prepare(strings, true), values);
27
+ }
28
+ /**
29
+ * Development: `html.at(loc)` (and `svg.at(loc)`) is the tag with a known call site. The Vite
30
+ * preset's dev transform (compiler/locate.ts) writes it at every call site, since stack
31
+ * positions in transformed modules aren't the author's lines. Attached here, not by a statement
32
+ * that mentions the tag, so production builds don't keep it alive (the compiler checks that).
33
+ */
34
+ function withAt(html) {
35
+ const tags = new Map();
36
+ const at = (loc) => {
37
+ let located = tags.get(loc);
38
+ if (located === undefined) {
39
+ located = (strings, ...values) => {
40
+ setLoc(strings, loc);
41
+ return html(strings, ...values);
42
+ };
43
+ tags.set(loc, located);
44
+ }
45
+ return located;
46
+ };
47
+ return Object.assign(html, { at });
48
+ }
49
+ /** The template tag: `` html`<p>${s.text}</p>` ``. */
50
+ export const html = DEV
51
+ ? withAt(tag)
52
+ : tag;
53
+ /**
54
+ * The SVG fragment tag: `` svg`<path d=${s.d} />` ``. Its top level is SVG content, so it
55
+ * renders only inside an `<svg>` (or another SVG element) of an html template
56
+ * (view/01-templates.md "svg templates"). A whole `<svg>` graphic is written with html.
57
+ */
58
+ export const svg = DEV
59
+ ? withAt(svgTag)
60
+ : svgTag;
61
+ /** Internal: what the template compiler (`@gyral/core/vite`) rewrites `html` calls into. */
13
62
  export function compiled(template, values) {
14
63
  return { [SOURCE]: template, values };
15
64
  }
65
+ /** Internal: what the template compiler rewrites `svg` calls into. */
66
+ export function compiledSvg(template, values) {
67
+ svgTemplate(template);
68
+ return { [SOURCE]: template, values };
69
+ }
16
70
  export function isTemplateResult(value) {
17
71
  return typeof value === 'object' && value !== null && SOURCE in value;
18
72
  }
@@ -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,IA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,GAAG,CAAC;AAER;;;;GAIG;AACH,MAAM,CAAC,MAAM,GAAG,GAA4E,GAAG;IAC7F,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;IAChB,CAAC,CAAC,MAAM,CAAC;AAEX,4FAA4F;AAC5F,MAAM,UAAU,QAAQ,CAAC,QAAwB,EAAE,MAA0B;IAC3E,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\n * (view/01-templates.md \"svg templates\"). 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;