@gyral/core 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (343) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/README.md +7 -5
  3. package/dist/children.d.ts +5 -2
  4. package/dist/children.js +8 -3
  5. package/dist/children.js.map +1 -1
  6. package/dist/command.js +6 -0
  7. package/dist/command.js.map +1 -1
  8. package/dist/compiler/ast.d.ts +21 -0
  9. package/dist/compiler/ast.js +145 -0
  10. package/dist/compiler/ast.js.map +1 -0
  11. package/dist/compiler/compile.d.ts +38 -0
  12. package/dist/compiler/compile.js +129 -0
  13. package/dist/compiler/compile.js.map +1 -0
  14. package/dist/compiler/hooks.d.ts +18 -0
  15. package/dist/compiler/hooks.js +186 -0
  16. package/dist/compiler/hooks.js.map +1 -0
  17. package/dist/compiler/parse5-check.d.ts +21 -0
  18. package/dist/compiler/parse5-check.js +55 -0
  19. package/dist/compiler/parse5-check.js.map +1 -0
  20. package/dist/compiler/scan.d.ts +31 -0
  21. package/dist/compiler/scan.js +152 -0
  22. package/dist/compiler/scan.js.map +1 -0
  23. package/dist/compiler/source.d.ts +34 -0
  24. package/dist/compiler/source.js +114 -0
  25. package/dist/compiler/source.js.map +1 -0
  26. package/dist/define.d.ts +2 -2
  27. package/dist/define.js +35 -327
  28. package/dist/define.js.map +1 -1
  29. package/dist/devtools-events.d.ts +5 -0
  30. package/dist/devtools-events.js.map +1 -1
  31. package/dist/devtools-off.d.ts +1 -0
  32. package/dist/devtools-off.js +1 -0
  33. package/dist/devtools-off.js.map +1 -1
  34. package/dist/devtools.d.ts +1 -0
  35. package/dist/devtools.js +3 -2
  36. package/dist/devtools.js.map +1 -1
  37. package/dist/drivers-scope.d.ts +1 -1
  38. package/dist/drivers-scope.js +1 -8
  39. package/dist/drivers-scope.js.map +1 -1
  40. package/dist/element-types.d.ts +5 -3
  41. package/dist/element-types.js.map +1 -1
  42. package/dist/element.d.ts +3 -0
  43. package/dist/element.js +269 -0
  44. package/dist/element.js.map +1 -0
  45. package/dist/eslint/imports.d.ts +24 -0
  46. package/dist/eslint/imports.js +78 -0
  47. package/dist/eslint/imports.js.map +1 -0
  48. package/dist/eslint/index.d.ts +15 -0
  49. package/dist/eslint/index.js +15 -0
  50. package/dist/eslint/index.js.map +1 -0
  51. package/dist/eslint/locate.d.ts +33 -0
  52. package/dist/eslint/locate.js +132 -0
  53. package/dist/eslint/locate.js.map +1 -0
  54. package/dist/eslint/row-purity-rule.d.ts +2 -0
  55. package/dist/eslint/row-purity-rule.js +103 -0
  56. package/dist/eslint/row-purity-rule.js.map +1 -0
  57. package/dist/eslint/template-rule.d.ts +5 -0
  58. package/dist/eslint/template-rule.js +66 -0
  59. package/dist/eslint/template-rule.js.map +1 -0
  60. package/dist/features.d.ts +39 -0
  61. package/dist/features.js +2 -0
  62. package/dist/features.js.map +1 -0
  63. package/dist/focus.d.ts +7 -12
  64. package/dist/focus.js +13 -10
  65. package/dist/focus.js.map +1 -1
  66. package/dist/hooks/invalid.d.ts +14 -0
  67. package/dist/hooks/invalid.js +72 -0
  68. package/dist/hooks/invalid.js.map +1 -0
  69. package/dist/hooks/labelled-by.d.ts +13 -0
  70. package/dist/hooks/labelled-by.js +51 -0
  71. package/dist/hooks/labelled-by.js.map +1 -0
  72. package/dist/host-model.d.ts +48 -0
  73. package/dist/host-model.js +155 -0
  74. package/dist/host-model.js.map +1 -0
  75. package/dist/hydration-client.d.ts +9 -0
  76. package/dist/hydration-client.js +35 -0
  77. package/dist/hydration-client.js.map +1 -0
  78. package/dist/hydration.d.ts +13 -19
  79. package/dist/hydration.js +45 -45
  80. package/dist/hydration.js.map +1 -1
  81. package/dist/index.d.ts +9 -17
  82. package/dist/index.js +9 -18
  83. package/dist/index.js.map +1 -1
  84. package/dist/intent.d.ts +31 -8
  85. package/dist/intent.js +82 -27
  86. package/dist/intent.js.map +1 -1
  87. package/dist/internal/interpreter.d.ts +7 -1
  88. package/dist/internal/interpreter.js +11 -4
  89. package/dist/internal/interpreter.js.map +1 -1
  90. package/dist/invokers-shim.d.ts +6 -0
  91. package/dist/invokers-shim.js +32 -0
  92. package/dist/invokers-shim.js.map +1 -0
  93. package/dist/invokers.d.ts +3 -5
  94. package/dist/invokers.js +11 -51
  95. package/dist/invokers.js.map +1 -1
  96. package/dist/islands.d.ts +0 -2
  97. package/dist/islands.js +4 -11
  98. package/dist/islands.js.map +1 -1
  99. package/dist/light-dom.d.ts +3 -52
  100. package/dist/light-dom.js +5 -100
  101. package/dist/light-dom.js.map +1 -1
  102. package/dist/prop.d.ts +66 -0
  103. package/dist/prop.js +22 -0
  104. package/dist/prop.js.map +1 -0
  105. package/dist/props.d.ts +52 -21
  106. package/dist/props.js +150 -34
  107. package/dist/props.js.map +1 -1
  108. package/dist/scheduler.d.ts +39 -0
  109. package/dist/scheduler.js +230 -0
  110. package/dist/scheduler.js.map +1 -0
  111. package/dist/server-component.d.ts +10 -0
  112. package/dist/server-component.js +102 -0
  113. package/dist/server-component.js.map +1 -0
  114. package/dist/server-specs.d.ts +6 -0
  115. package/dist/server-specs.js +13 -0
  116. package/dist/server-specs.js.map +1 -0
  117. package/dist/server.d.ts +28 -0
  118. package/dist/server.js +50 -0
  119. package/dist/server.js.map +1 -0
  120. package/dist/settled.d.ts +10 -0
  121. package/dist/settled.js +40 -0
  122. package/dist/settled.js.map +1 -0
  123. package/dist/states.d.ts +3 -3
  124. package/dist/states.js +4 -7
  125. package/dist/states.js.map +1 -1
  126. package/dist/store-binding.d.ts +6 -3
  127. package/dist/store-binding.js +5 -6
  128. package/dist/store-binding.js.map +1 -1
  129. package/dist/store-scope.d.ts +6 -7
  130. package/dist/store-scope.js +11 -26
  131. package/dist/store-scope.js.map +1 -1
  132. package/dist/store.d.ts +3 -0
  133. package/dist/store.js +9 -2
  134. package/dist/store.js.map +1 -1
  135. package/dist/stores-provider.d.ts +2 -6
  136. package/dist/stores-provider.js +21 -55
  137. package/dist/stores-provider.js.map +1 -1
  138. package/dist/transitions.d.ts +5 -6
  139. package/dist/transitions.js +11 -20
  140. package/dist/transitions.js.map +1 -1
  141. package/dist/types.d.ts +19 -23
  142. package/dist/types.js.map +1 -1
  143. package/dist/view/attributes.d.ts +6 -0
  144. package/dist/view/attributes.js +10 -0
  145. package/dist/view/attributes.js.map +1 -0
  146. package/dist/view/compiled.d.ts +1 -0
  147. package/dist/view/compiled.js +6 -0
  148. package/dist/view/compiled.js.map +1 -0
  149. package/dist/view/dev-off.d.ts +1 -0
  150. package/dist/view/dev-off.js +4 -0
  151. package/dist/view/dev-off.js.map +1 -0
  152. package/dist/view/dev.d.ts +1 -0
  153. package/dist/view/dev.js +5 -0
  154. package/dist/view/dev.js.map +1 -0
  155. package/dist/view/flags.d.ts +1 -0
  156. package/dist/view/flags.js +4 -0
  157. package/dist/view/flags.js.map +1 -0
  158. package/dist/view/index.d.ts +21 -0
  159. package/dist/view/index.js +21 -0
  160. package/dist/view/index.js.map +1 -0
  161. package/dist/view/normalize/check.d.ts +20 -0
  162. package/dist/view/normalize/check.js +78 -0
  163. package/dist/view/normalize/check.js.map +1 -0
  164. package/dist/view/normalize/emit.d.ts +13 -0
  165. package/dist/view/normalize/emit.js +136 -0
  166. package/dist/view/normalize/emit.js.map +1 -0
  167. package/dist/view/normalize/entities.d.ts +4 -0
  168. package/dist/view/normalize/entities.js +38 -0
  169. package/dist/view/normalize/entities.js.map +1 -0
  170. package/dist/view/normalize/errors.d.ts +9 -0
  171. package/dist/view/normalize/errors.js +19 -0
  172. package/dist/view/normalize/errors.js.map +1 -0
  173. package/dist/view/normalize/id.d.ts +7 -0
  174. package/dist/view/normalize/id.js +48 -0
  175. package/dist/view/normalize/id.js.map +1 -0
  176. package/dist/view/normalize/normalize.d.ts +15 -0
  177. package/dist/view/normalize/normalize.js +36 -0
  178. package/dist/view/normalize/normalize.js.map +1 -0
  179. package/dist/view/normalize/repairs.d.ts +24 -0
  180. package/dist/view/normalize/repairs.js +166 -0
  181. package/dist/view/normalize/repairs.js.map +1 -0
  182. package/dist/view/normalize/rules.d.ts +30 -0
  183. package/dist/view/normalize/rules.js +90 -0
  184. package/dist/view/normalize/rules.js.map +1 -0
  185. package/dist/view/normalize/shape.d.ts +5 -0
  186. package/dist/view/normalize/shape.js +38 -0
  187. package/dist/view/normalize/shape.js.map +1 -0
  188. package/dist/view/normalize/source.d.ts +13 -0
  189. package/dist/view/normalize/source.js +34 -0
  190. package/dist/view/normalize/source.js.map +1 -0
  191. package/dist/view/normalize/tag-states.d.ts +23 -0
  192. package/dist/view/normalize/tag-states.js +192 -0
  193. package/dist/view/normalize/tag-states.js.map +1 -0
  194. package/dist/view/normalize/tokenizer.d.ts +5 -0
  195. package/dist/view/normalize/tokenizer.js +233 -0
  196. package/dist/view/normalize/tokenizer.js.map +1 -0
  197. package/dist/view/normalize/tokens.d.ts +51 -0
  198. package/dist/view/normalize/tokens.js +24 -0
  199. package/dist/view/normalize/tokens.js.map +1 -0
  200. package/dist/view/normalize/tree.d.ts +59 -0
  201. package/dist/view/normalize/tree.js +190 -0
  202. package/dist/view/normalize/tree.js.map +1 -0
  203. package/dist/view/normalize/types.d.ts +126 -0
  204. package/dist/view/normalize/types.js +26 -0
  205. package/dist/view/normalize/types.js.map +1 -0
  206. package/dist/view/normalize/whitespace.d.ts +2 -0
  207. package/dist/{template-whitespace.js → view/normalize/whitespace.js} +24 -34
  208. package/dist/view/normalize/whitespace.js.map +1 -0
  209. package/dist/view/prepare-stub.d.ts +3 -0
  210. package/dist/view/prepare-stub.js +7 -0
  211. package/dist/view/prepare-stub.js.map +1 -0
  212. package/dist/view/prepare.d.ts +8 -0
  213. package/dist/view/prepare.js +57 -0
  214. package/dist/view/prepare.js.map +1 -0
  215. package/dist/view/registry.d.ts +63 -0
  216. package/dist/view/registry.js +19 -0
  217. package/dist/view/registry.js.map +1 -0
  218. package/dist/view/render/adopt-attr.d.ts +14 -0
  219. package/dist/view/render/adopt-attr.js +77 -0
  220. package/dist/view/render/adopt-attr.js.map +1 -0
  221. package/dist/view/render/adopt-plan.d.ts +10 -0
  222. package/dist/view/render/adopt-plan.js +26 -0
  223. package/dist/view/render/adopt-plan.js.map +1 -0
  224. package/dist/view/render/adopt.d.ts +3 -0
  225. package/dist/view/render/adopt.js +269 -0
  226. package/dist/view/render/adopt.js.map +1 -0
  227. package/dist/view/render/attr-parts.d.ts +61 -0
  228. package/dist/view/render/attr-parts.js +229 -0
  229. package/dist/view/render/attr-parts.js.map +1 -0
  230. package/dist/view/render/child-part.d.ts +51 -0
  231. package/dist/view/render/child-part.js +170 -0
  232. package/dist/view/render/child-part.js.map +1 -0
  233. package/dist/view/render/dev-check.d.ts +12 -0
  234. package/dist/view/render/dev-check.js +122 -0
  235. package/dist/view/render/dev-check.js.map +1 -0
  236. package/dist/view/render/hook-part.d.ts +3 -0
  237. package/dist/view/render/hook-part.js +20 -0
  238. package/dist/view/render/hook-part.js.map +1 -0
  239. package/dist/view/render/hooks.d.ts +40 -0
  240. package/dist/view/render/hooks.js +46 -0
  241. package/dist/view/render/hooks.js.map +1 -0
  242. package/dist/view/render/hydrate.d.ts +10 -0
  243. package/dist/view/render/hydrate.js +33 -0
  244. package/dist/view/render/hydrate.js.map +1 -0
  245. package/dist/view/render/instance.d.ts +33 -0
  246. package/dist/view/render/instance.js +107 -0
  247. package/dist/view/render/instance.js.map +1 -0
  248. package/dist/view/render/list.d.ts +20 -0
  249. package/dist/view/render/list.js +156 -0
  250. package/dist/view/render/list.js.map +1 -0
  251. package/dist/view/render/mismatch.d.ts +10 -0
  252. package/dist/view/render/mismatch.js +53 -0
  253. package/dist/view/render/mismatch.js.map +1 -0
  254. package/dist/view/render/nodes.d.ts +10 -0
  255. package/dist/view/render/nodes.js +37 -0
  256. package/dist/view/render/nodes.js.map +1 -0
  257. package/dist/view/render/place.d.ts +18 -0
  258. package/dist/view/render/place.js +69 -0
  259. package/dist/view/render/place.js.map +1 -0
  260. package/dist/view/render/plan.d.ts +26 -0
  261. package/dist/view/render/plan.js +124 -0
  262. package/dist/view/render/plan.js.map +1 -0
  263. package/dist/view/render/raw.d.ts +18 -0
  264. package/dist/view/render/raw.js +68 -0
  265. package/dist/view/render/raw.js.map +1 -0
  266. package/dist/view/render/render.d.ts +12 -0
  267. package/dist/view/render/render.js +60 -0
  268. package/dist/view/render/render.js.map +1 -0
  269. package/dist/view/render/reorder.d.ts +4 -0
  270. package/dist/view/render/reorder.js +101 -0
  271. package/dist/view/render/reorder.js.map +1 -0
  272. package/dist/view/render/rows.d.ts +23 -0
  273. package/dist/view/render/rows.js +95 -0
  274. package/dist/view/render/rows.js.map +1 -0
  275. package/dist/view/render/seen.d.ts +11 -0
  276. package/dist/view/render/seen.js +17 -0
  277. package/dist/view/render/seen.js.map +1 -0
  278. package/dist/view/render/values.d.ts +29 -0
  279. package/dist/view/render/values.js +13 -0
  280. package/dist/view/render/values.js.map +1 -0
  281. package/dist/view/render/warn.d.ts +14 -0
  282. package/dist/view/render/warn.js +69 -0
  283. package/dist/view/render/warn.js.map +1 -0
  284. package/dist/view/server/component.d.ts +9 -0
  285. package/dist/view/server/component.js +42 -0
  286. package/dist/view/server/component.js.map +1 -0
  287. package/dist/view/server/escape.d.ts +10 -0
  288. package/dist/view/server/escape.js +34 -0
  289. package/dist/view/server/escape.js.map +1 -0
  290. package/dist/view/server/index.d.ts +28 -0
  291. package/dist/view/server/index.js +72 -0
  292. package/dist/view/server/index.js.map +1 -0
  293. package/dist/view/server/sha256.d.ts +2 -0
  294. package/dist/view/server/sha256.js +75 -0
  295. package/dist/view/server/sha256.js.map +1 -0
  296. package/dist/view/server/tags.d.ts +57 -0
  297. package/dist/view/server/tags.js +121 -0
  298. package/dist/view/server/tags.js.map +1 -0
  299. package/dist/view/server/values.d.ts +16 -0
  300. package/dist/view/server/values.js +86 -0
  301. package/dist/view/server/values.js.map +1 -0
  302. package/dist/view/server/writer.d.ts +16 -0
  303. package/dist/view/server/writer.js +155 -0
  304. package/dist/view/server/writer.js.map +1 -0
  305. package/dist/view/styles.d.ts +25 -0
  306. package/dist/view/styles.js +58 -0
  307. package/dist/view/styles.js.map +1 -0
  308. package/dist/view/template-element.d.ts +3 -0
  309. package/dist/view/template-element.js +25 -0
  310. package/dist/view/template-element.js.map +1 -0
  311. package/dist/view/template.d.ts +21 -0
  312. package/dist/view/template.js +30 -0
  313. package/dist/view/template.js.map +1 -0
  314. package/dist/vite.d.ts +45 -6
  315. package/dist/vite.js +150 -25
  316. package/dist/vite.js.map +1 -1
  317. package/package.json +39 -4
  318. package/dist/accessible-name.d.ts +0 -19
  319. package/dist/accessible-name.js +0 -56
  320. package/dist/accessible-name.js.map +0 -1
  321. package/dist/element-directive.d.ts +0 -20
  322. package/dist/element-directive.js +0 -31
  323. package/dist/element-directive.js.map +0 -1
  324. package/dist/invalid.d.ts +0 -21
  325. package/dist/invalid.js +0 -70
  326. package/dist/invalid.js.map +0 -1
  327. package/dist/lit-html-check.d.ts +0 -6
  328. package/dist/lit-html-check.js +0 -48
  329. package/dist/lit-html-check.js.map +0 -1
  330. package/dist/live-boolean.d.ts +0 -22
  331. package/dist/live-boolean.js +0 -34
  332. package/dist/live-boolean.js.map +0 -1
  333. package/dist/styles.d.ts +0 -12
  334. package/dist/styles.js +0 -11
  335. package/dist/styles.js.map +0 -1
  336. package/dist/template-whitespace.d.ts +0 -7
  337. package/dist/template-whitespace.js.map +0 -1
  338. package/dist/templates.d.ts +0 -5
  339. package/dist/templates.js +0 -15
  340. package/dist/templates.js.map +0 -1
  341. package/dist/textarea.d.ts +0 -26
  342. package/dist/textarea.js +0 -85
  343. package/dist/textarea.js.map +0 -1
@@ -0,0 +1,126 @@
1
+ /** Child-index path from the template's content root (`[]` is the root itself). */
2
+ export type Path = readonly number[];
3
+ /** `[CHILD_END, path]`: a child hole that inserts at the end of its parent. */
4
+ export declare const CHILD_END = 0;
5
+ /** `[CHILD_SOLE, path]`: a child hole that is its parent's only child node (so at its end). */
6
+ export declare const CHILD_SOLE = 1;
7
+ /** `[CHILD_BEFORE, path, ref]`: a child hole that inserts before the parent's child `ref`. */
8
+ export declare const CHILD_BEFORE = 2;
9
+ /** `[ATTR_PART, path, name]`: `name=${v}`. */
10
+ export declare const ATTR_PART = 3;
11
+ /** `[MULTI_PART, path, name, strings]`: `name="a ${x} b"`. */
12
+ export declare const MULTI_PART = 4;
13
+ /** `[BOOL_PART, path, name]`: `?name=${v}`. */
14
+ export declare const BOOL_PART = 5;
15
+ /** `[PROP_PART, path, name]`: `.name=${v}`. */
16
+ export declare const PROP_PART = 6;
17
+ /** `[HOOK_PART, path]`: `${hook(…)}` in a start tag. */
18
+ export declare const HOOK_PART = 7;
19
+ /** `[TEXT_PART, path]`: the whole content of a `<textarea>` or `<title>`. */
20
+ export declare const TEXT_PART = 8;
21
+ /**
22
+ * One entry per binding, in source order: a tuple whose first entry is its kind (above), whose
23
+ * second is a path, then the kind's own fields. Multi-attributes take several values.
24
+ *
25
+ * - Child holes: `path` leads to the parent element (`[]`: the template root). `ref` is the
26
+ * index, among the parent's child nodes in the template DOM, of the node the part inserts
27
+ * before: the next static element or comment, or the anchor comment the normalizer emitted.
28
+ * Without `ref` the hole inserts at the end of the parent (CHILD_END, CHILD_SOLE).
29
+ * - Attributes, booleans, properties: `path` leads to the element; `name` is the attribute or
30
+ * property name. A multi-attribute's `strings` are its static pieces (character references
31
+ * already decoded): `strings.length - 1` values are joined with them.
32
+ * - Hooks: `path` leads to the element. Text: `path` leads to the `<textarea>`/`<title>`.
33
+ */
34
+ export type PartSpec = readonly [
35
+ kind: typeof CHILD_END | typeof CHILD_SOLE | typeof HOOK_PART | typeof TEXT_PART,
36
+ path: Path
37
+ ] | readonly [kind: typeof CHILD_BEFORE, path: Path, ref: number] | readonly [
38
+ kind: typeof ATTR_PART | typeof BOOL_PART | typeof PROP_PART,
39
+ path: Path,
40
+ name: string
41
+ ] | readonly [kind: typeof MULTI_PART, path: Path, name: string, strings: readonly string[]];
42
+ /**
43
+ * What the server renderer writes (view/06-server.md), in order, with no tokenizing. Strings
44
+ * are static markup, written verbatim. Each hole op takes the next value(s); the custom-element
45
+ * ops take none and mark where a component's start tag ends and its end tag begins.
46
+ *
47
+ * - `child`: the value per 02's child table. Anchors are already in the next static string.
48
+ * `in` is the parent element's local name (absent at the template root, where the parent is
49
+ * wherever the instance is written): the development check for text the parser would move
50
+ * out of table structure needs it.
51
+ * - `text`: the value as escaped text (`<textarea>`, `<title>` content).
52
+ * - `attr`: ` name="escaped"`, or nothing for null/undefined/nothing. With `strings`, the
53
+ * pieces and `strings.length - 1` values are joined first (`nothing` in any piece: nothing).
54
+ * - `bool`: ` name` when the value is truthy.
55
+ * - `prop`: nothing in markup; a prop when the element is a Gyral component.
56
+ * - `hook`: the hook's `server(args)` attributes.
57
+ * - `open`: a custom element's start tag begins. `html` is `<tag` plus its static attributes,
58
+ * written verbatim; `attrs` are the same static attributes, decoded (props for a component).
59
+ * The element's attribute ops follow.
60
+ * - `openEnd`: write `>`. A component writes its seed attribute first, and its shadow root
61
+ * after.
62
+ * - `close`: write `</tag>`. Everything between `openEnd` and `close` is the element's children.
63
+ *
64
+ * Joining the strings with every op written empty (`open` as `html`, `openEnd` as `>`, `close`
65
+ * as `</tag>`) gives exactly the template's `html`.
66
+ */
67
+ export type Segment = string | {
68
+ readonly k: 'child';
69
+ readonly in?: string;
70
+ } | {
71
+ readonly k: 'text';
72
+ } | {
73
+ readonly k: 'attr';
74
+ readonly name: string;
75
+ readonly strings?: readonly string[];
76
+ } | {
77
+ readonly k: 'bool';
78
+ readonly name: string;
79
+ } | {
80
+ readonly k: 'prop';
81
+ readonly name: string;
82
+ } | {
83
+ readonly k: 'hook';
84
+ } | {
85
+ readonly k: 'open';
86
+ readonly tag: string;
87
+ readonly html: string;
88
+ readonly attrs: readonly (readonly [name: string, value: string])[];
89
+ } | {
90
+ readonly k: 'openEnd';
91
+ } | {
92
+ readonly k: 'close';
93
+ readonly tag: string;
94
+ };
95
+ export interface TemplateObject {
96
+ /**
97
+ * Deterministic id of the normalized strings (id.ts). Absent from objects compiled for a
98
+ * production client (01 "Template ids"): there the renderer compares templates by identity.
99
+ */
100
+ readonly id?: string;
101
+ /** Normalized template HTML for the client: bound attributes removed, anchors added. */
102
+ readonly html: string;
103
+ readonly parts: readonly PartSpec[];
104
+ /**
105
+ * `true` when it contains document-level tags (<!doctype>, <html>, <head>, <body>):
106
+ * server-only. Absent otherwise.
107
+ */
108
+ readonly server?: true;
109
+ /**
110
+ * Server writing plan. Absent from client-compiled template objects (the compiler drops it),
111
+ * so the client renderer never reads it; the runtime preparer and server builds keep it.
112
+ */
113
+ readonly segments?: readonly Segment[];
114
+ /** Development only: file:line:column of the call site. */
115
+ readonly loc?: string;
116
+ }
117
+ /** What the normalizer returns: a template object that always has its id. */
118
+ export type NormalizedTemplate = TemplateObject & {
119
+ readonly id: string;
120
+ };
121
+ /**
122
+ * The DOM the browser must build from `html`, for the runtime preparer's check (prepare.ts):
123
+ * `'#text'`, `'#comment'`, or `[localName (lower case), children]`.
124
+ */
125
+ export type ShapeNode = '#text' | '#comment' | readonly [name: string, children: Shape];
126
+ export type Shape = readonly ShapeNode[];
@@ -0,0 +1,26 @@
1
+ // The template object (view/01-templates.md "The template object") and its part table
2
+ // (view/02-bindings.md "Hole kinds"). Plain JSON data, no functions: the Vite compiler (Phase 6)
3
+ // emits it as code, the browser instantiates from it, and the server writes from it. Compact
4
+ // on purpose (numeric part kinds, tuples, `server` only when true), so the code compiled
5
+ // client builds carry stays small with nothing to decode.
6
+ // Part kinds: the first entry of a PartSpec tuple. Small numbers, because compiled client
7
+ // builds carry every template's part table as code (view/01-templates.md "Compiled").
8
+ /** `[CHILD_END, path]`: a child hole that inserts at the end of its parent. */
9
+ export const CHILD_END = 0;
10
+ /** `[CHILD_SOLE, path]`: a child hole that is its parent's only child node (so at its end). */
11
+ export const CHILD_SOLE = 1;
12
+ /** `[CHILD_BEFORE, path, ref]`: a child hole that inserts before the parent's child `ref`. */
13
+ export const CHILD_BEFORE = 2;
14
+ /** `[ATTR_PART, path, name]`: `name=${v}`. */
15
+ export const ATTR_PART = 3;
16
+ /** `[MULTI_PART, path, name, strings]`: `name="a ${x} b"`. */
17
+ export const MULTI_PART = 4;
18
+ /** `[BOOL_PART, path, name]`: `?name=${v}`. */
19
+ export const BOOL_PART = 5;
20
+ /** `[PROP_PART, path, name]`: `.name=${v}`. */
21
+ export const PROP_PART = 6;
22
+ /** `[HOOK_PART, path]`: `${hook(…)}` in a start tag. */
23
+ export const HOOK_PART = 7;
24
+ /** `[TEXT_PART, path]`: the whole content of a `<textarea>` or `<title>`. */
25
+ export const TEXT_PART = 8;
26
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/view/normalize/types.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,iGAAiG;AACjG,6FAA6F;AAC7F,yFAAyF;AACzF,0DAA0D;AAK1D,0FAA0F;AAC1F,sFAAsF;AACtF,+EAA+E;AAC/E,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAC3B,+FAA+F;AAC/F,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC;AAC5B,8FAA8F;AAC9F,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC;AAC9B,8CAA8C;AAC9C,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAC3B,8DAA8D;AAC9D,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC;AAC5B,+CAA+C;AAC/C,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAC3B,+CAA+C;AAC/C,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAC3B,wDAAwD;AACxD,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAC3B,6EAA6E;AAC7E,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC","sourcesContent":["// The template object (view/01-templates.md \"The template object\") and its part table\n// (view/02-bindings.md \"Hole kinds\"). Plain JSON data, no functions: the Vite compiler (Phase 6)\n// emits it as code, the browser instantiates from it, and the server writes from it. Compact\n// on purpose (numeric part kinds, tuples, `server` only when true), so the code compiled\n// client builds carry stays small with nothing to decode.\n\n/** Child-index path from the template's content root (`[]` is the root itself). */\nexport type Path = readonly number[];\n\n// Part kinds: the first entry of a PartSpec tuple. Small numbers, because compiled client\n// builds carry every template's part table as code (view/01-templates.md \"Compiled\").\n/** `[CHILD_END, path]`: a child hole that inserts at the end of its parent. */\nexport const CHILD_END = 0;\n/** `[CHILD_SOLE, path]`: a child hole that is its parent's only child node (so at its end). */\nexport const CHILD_SOLE = 1;\n/** `[CHILD_BEFORE, path, ref]`: a child hole that inserts before the parent's child `ref`. */\nexport const CHILD_BEFORE = 2;\n/** `[ATTR_PART, path, name]`: `name=${v}`. */\nexport const ATTR_PART = 3;\n/** `[MULTI_PART, path, name, strings]`: `name=\"a ${x} b\"`. */\nexport const MULTI_PART = 4;\n/** `[BOOL_PART, path, name]`: `?name=${v}`. */\nexport const BOOL_PART = 5;\n/** `[PROP_PART, path, name]`: `.name=${v}`. */\nexport const PROP_PART = 6;\n/** `[HOOK_PART, path]`: `${hook(…)}` in a start tag. */\nexport const HOOK_PART = 7;\n/** `[TEXT_PART, path]`: the whole content of a `<textarea>` or `<title>`. */\nexport const TEXT_PART = 8;\n\n/**\n * One entry per binding, in source order: a tuple whose first entry is its kind (above), whose\n * second is a path, then the kind's own fields. Multi-attributes take several values.\n *\n * - Child holes: `path` leads to the parent element (`[]`: the template root). `ref` is the\n * index, among the parent's child nodes in the template DOM, of the node the part inserts\n * before: the next static element or comment, or the anchor comment the normalizer emitted.\n * Without `ref` the hole inserts at the end of the parent (CHILD_END, CHILD_SOLE).\n * - Attributes, booleans, properties: `path` leads to the element; `name` is the attribute or\n * property name. A multi-attribute's `strings` are its static pieces (character references\n * already decoded): `strings.length - 1` values are joined with them.\n * - Hooks: `path` leads to the element. Text: `path` leads to the `<textarea>`/`<title>`.\n */\nexport type PartSpec =\n | readonly [\n kind: typeof CHILD_END | typeof CHILD_SOLE | typeof HOOK_PART | typeof TEXT_PART,\n path: Path,\n ]\n | readonly [kind: typeof CHILD_BEFORE, path: Path, ref: number]\n | readonly [\n kind: typeof ATTR_PART | typeof BOOL_PART | typeof PROP_PART,\n path: Path,\n name: string,\n ]\n | readonly [kind: typeof MULTI_PART, path: Path, name: string, strings: readonly string[]];\n\n/**\n * What the server renderer writes (view/06-server.md), in order, with no tokenizing. Strings\n * are static markup, written verbatim. Each hole op takes the next value(s); the custom-element\n * ops take none and mark where a component's start tag ends and its end tag begins.\n *\n * - `child`: the value per 02's child table. Anchors are already in the next static string.\n * `in` is the parent element's local name (absent at the template root, where the parent is\n * wherever the instance is written): the development check for text the parser would move\n * out of table structure needs it.\n * - `text`: the value as escaped text (`<textarea>`, `<title>` content).\n * - `attr`: ` name=\"escaped\"`, or nothing for null/undefined/nothing. With `strings`, the\n * pieces and `strings.length - 1` values are joined first (`nothing` in any piece: nothing).\n * - `bool`: ` name` when the value is truthy.\n * - `prop`: nothing in markup; a prop when the element is a Gyral component.\n * - `hook`: the hook's `server(args)` attributes.\n * - `open`: a custom element's start tag begins. `html` is `<tag` plus its static attributes,\n * written verbatim; `attrs` are the same static attributes, decoded (props for a component).\n * The element's attribute ops follow.\n * - `openEnd`: write `>`. A component writes its seed attribute first, and its shadow root\n * after.\n * - `close`: write `</tag>`. Everything between `openEnd` and `close` is the element's children.\n *\n * Joining the strings with every op written empty (`open` as `html`, `openEnd` as `>`, `close`\n * as `</tag>`) gives exactly the template's `html`.\n */\nexport type Segment =\n | string\n | { readonly k: 'child'; readonly in?: string }\n | { readonly k: 'text' }\n | { readonly k: 'attr'; readonly name: string; readonly strings?: readonly string[] }\n | { readonly k: 'bool'; readonly name: string }\n | { readonly k: 'prop'; readonly name: string }\n | { readonly k: 'hook' }\n | {\n readonly k: 'open';\n readonly tag: string;\n readonly html: string;\n readonly attrs: readonly (readonly [name: string, value: string])[];\n }\n | { readonly k: 'openEnd' }\n | { readonly k: 'close'; readonly tag: string };\n\nexport interface TemplateObject {\n /**\n * Deterministic id of the normalized strings (id.ts). Absent from objects compiled for a\n * production client (01 \"Template ids\"): there the renderer compares templates by identity.\n */\n readonly id?: string;\n /** Normalized template HTML for the client: bound attributes removed, anchors added. */\n readonly html: string;\n readonly parts: readonly PartSpec[];\n /**\n * `true` when it contains document-level tags (<!doctype>, <html>, <head>, <body>):\n * server-only. Absent otherwise.\n */\n readonly server?: true;\n /**\n * Server writing plan. Absent from client-compiled template objects (the compiler drops it),\n * so the client renderer never reads it; the runtime preparer and server builds keep it.\n */\n readonly segments?: readonly Segment[];\n /** Development only: file:line:column of the call site. */\n readonly loc?: string;\n}\n\n/** What the normalizer returns: a template object that always has its id. */\nexport type NormalizedTemplate = TemplateObject & { readonly id: string };\n\n/**\n * The DOM the browser must build from `html`, for the runtime preparer's check (prepare.ts):\n * `'#text'`, `'#comment'`, or `[localName (lower case), children]`.\n */\nexport type ShapeNode = '#text' | '#comment' | readonly [name: string, children: Shape];\nexport type Shape = readonly ShapeNode[];\n"]}
@@ -0,0 +1,2 @@
1
+ /** Minified copy of template strings (same length, bindings unmoved). Idempotent. */
2
+ export declare function minifyStrings(strings: readonly string[]): string[];
@@ -1,28 +1,27 @@
1
- // Template whitespace minification (gyral-9rf, ADR 0016 addendum).
1
+ // Whitespace minification for templates (view/01-templates.md "Whitespace", ADR 0016 addendum).
2
+ // Moved from core's template-whitespace.ts (Gyral's own design) into the view layer's
3
+ // normalizer, so the compiler, the runtime preparer and the server minify identically.
2
4
  //
3
- // lit-html keeps every newline and indent between tags as a DOM text node; compilers (Svelte,
4
- // Solid, JSX) drop them. In a benchmark table row that is 12 extra nodes out of 25, and removing
5
- // them made create/replace/clear 11-24% faster (gyral-1kq). Gyral's `html` and `svg` tags run the
6
- // template strings through `minifyTemplate()` once per call site (cached by strings identity),
7
- // so the server and the browser always build the same template: hydration digests match in any
8
- // toolchain (Vite, tsx, plain Node), with no build step.
9
- //
10
- // Rules (the same text everywhere, documented in docs/references/consumer-setup.md):
5
+ // Rules:
11
6
  // - Whitespace-only text that contains a newline is removed when it sits next to a template
12
- // edge, a block-level tag, or the inside edge of a <button>/<select> (CSS never renders it
13
- // there). Between two inline neighbours (phrasing elements, custom elements, bindings,
7
+ // edge, a block-level tag (head-only tags count: <head>, <meta>, <link>, <base>, <title>),
8
+ // or the inside edge of a <button>/<select> (CSS never renders it there). Inside <head>,
9
+ // whitespace-only text is always removed, newline or not, between holes too: nothing there
10
+ // renders. Between two inline neighbours (phrasing elements, custom elements, holes,
14
11
  // comments) it collapses to one space.
15
12
  // - Other runs of whitespace in text collapse to one space; a leading or trailing run with a
16
13
  // newline next to one of those edges is removed.
17
14
  // - <pre>, <textarea>, <script>, <style> and <title> contents, tags and attribute values,
18
- // and comments are copied unchanged. Binding positions never move: the result has the same
19
- // number of strings, so Lit parts and SSR hydration markers line up.
15
+ // and comments are copied unchanged. Holes never move: the result has the same number of
16
+ // strings.
20
17
  // The function is idempotent: minifying minified strings changes nothing.
21
18
  /** Elements whose box is block-level (or never laid out inline) by default. */
22
19
  const BLOCK = new Set(('address article aside blockquote body caption col colgroup datalist dd details dialog div ' +
23
20
  'dl dt fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 head header hgroup hr html ' +
24
21
  'legend li main menu nav ol optgroup option p pre search section select summary table tbody ' +
25
22
  'td tfoot th thead tr ul ' +
23
+ // Head-only elements: never rendered at all, so never inline.
24
+ 'base link meta title ' +
26
25
  // SVG containers and shapes: whitespace between them is never rendered.
27
26
  'circle clippath defs ellipse g line lineargradient marker mask path pattern polygon ' +
28
27
  'polyline radialgradient rect stop symbol use').split(' '));
@@ -46,12 +45,14 @@ function edgeOfTag(name, inside) {
46
45
  }
47
46
  const WS = /^[ \t\n\r\f]*$/;
48
47
  const RUN = /[ \t\n\r\f]+/g;
49
- function minifyChunk(text, left, right) {
48
+ /** `head`: the text is inside `<head>`, which is never rendered. */
49
+ function minifyChunk(text, left, right, head) {
50
50
  if (text === '')
51
51
  return text;
52
52
  if (WS.test(text)) {
53
- const removable = /[\n\r]/.test(text) &&
54
- (left === 'template' || right === 'template' || left === 'block' || right === 'block');
53
+ const removable = head ||
54
+ (/[\n\r]/.test(text) &&
55
+ (left === 'template' || right === 'template' || left === 'block' || right === 'block'));
55
56
  return removable ? '' : ' ';
56
57
  }
57
58
  // Mixed text: a leading or trailing run with a newline next to a removable edge goes too.
@@ -71,7 +72,7 @@ function minifySegment(segment, state, last) {
71
72
  let out = '';
72
73
  let chunk = '';
73
74
  const flushText = (right) => {
74
- out += state.preDepth > 0 ? chunk : minifyChunk(chunk, state.left, right);
75
+ out += state.preDepth > 0 ? chunk : minifyChunk(chunk, state.left, right, state.head);
75
76
  chunk = '';
76
77
  };
77
78
  let i = 0;
@@ -149,6 +150,10 @@ function endTag(state, selfClosing) {
149
150
  const name = state.tagName;
150
151
  state.mode = Mode.Text;
151
152
  state.left = edgeOfTag(name, !state.closing && !selfClosing);
153
+ if (name === 'head' && !selfClosing)
154
+ state.head = !state.closing;
155
+ if (name === 'body')
156
+ state.head = false;
152
157
  if (name === PRESERVE) {
153
158
  if (state.closing)
154
159
  state.preDepth = Math.max(0, state.preDepth - 1);
@@ -169,24 +174,9 @@ export function minifyStrings(strings) {
169
174
  closing: false,
170
175
  rawName: '',
171
176
  preDepth: 0,
177
+ head: false,
172
178
  left: 'template',
173
179
  };
174
180
  return strings.map((segment, index) => minifySegment(segment, state, index === strings.length - 1));
175
181
  }
176
- const cache = new WeakMap();
177
- /**
178
- * The minified TemplateStringsArray for a call site. Cached by identity, so Lit's own template
179
- * cache (keyed by the strings array) still hits once per call site.
180
- */
181
- export function minifyTemplate(strings) {
182
- const cached = cache.get(strings);
183
- if (cached !== undefined)
184
- return cached;
185
- const minified = minifyStrings(strings);
186
- // Lit accepts only arrays with an own `raw` field (its anti-spoofing check), as lit/static-html
187
- // builds them. Cooked strings are what Lit reads; `raw` mirrors them.
188
- const result = Object.freeze(Object.assign(minified, { raw: Object.freeze([...minified]) }));
189
- cache.set(strings, result);
190
- return result;
191
- }
192
- //# sourceMappingURL=template-whitespace.js.map
182
+ //# sourceMappingURL=whitespace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"whitespace.js","sourceRoot":"","sources":["../../../src/view/normalize/whitespace.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,sFAAsF;AACtF,uFAAuF;AACvF,EAAE;AACF,SAAS;AACT,4FAA4F;AAC5F,6FAA6F;AAC7F,2FAA2F;AAC3F,6FAA6F;AAC7F,uFAAuF;AACvF,yCAAyC;AACzC,6FAA6F;AAC7F,mDAAmD;AACnD,0FAA0F;AAC1F,2FAA2F;AAC3F,aAAa;AACb,0EAA0E;AAE1E,+EAA+E;AAC/E,MAAM,KAAK,GAAG,IAAI,GAAG,CACnB,CACE,4FAA4F;IAC5F,4FAA4F;IAC5F,6FAA6F;IAC7F,0BAA0B;IAC1B,8DAA8D;IAC9D,uBAAuB;IACvB,wEAAwE;IACxE,sFAAsF;IACtF,8CAA8C,CAC/C,CAAC,KAAK,CAAC,GAAG,CAAC,CACb,CAAC;AAEF,6FAA6F;AAC7F,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;AACnE,MAAM,QAAQ,GAAG,KAAK,CAAC;AAKvB;;;GAGG;AACH,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;AAEjD;;;GAGG;AACH,SAAS,SAAS,CAAC,IAAY,EAAE,MAAe;IAC9C,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IACjC,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC;IACrC,OAAO,MAAM,IAAI,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAA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G,CAAC,KAAK,CAAC,OAAO,CAAC;IACjE,IAAI,IAAI,KAAK,MAAM;QAAE,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC;IACxC,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtB,IAAI,KAAK,CAAC,OAAO;YAAE,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;aAC/D,IAAI,CAAC,WAAW;YAAE,KAAK,CAAC,QAAQ,IAAI,CAAC,CAAC;IAC7C,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,WAAW,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QACzD,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC;QAC1B,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;IACvB,CAAC;AACH,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,aAAa,CAAC,OAA0B;IACtD,MAAM,KAAK,GAAS;QAClB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,KAAK,EAAE,EAAE;QACT,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,KAAK;QACd,OAAO,EAAE,EAAE;QACX,QAAQ,EAAE,CAAC;QACX,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,UAAU;KACjB,CAAC;IACF,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CACpC,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAC5D,CAAC;AACJ,CAAC","sourcesContent":["// Whitespace minification for templates (view/01-templates.md \"Whitespace\", ADR 0016 addendum).\n// Moved from core's template-whitespace.ts (Gyral's own design) into the view layer's\n// normalizer, so the compiler, the runtime preparer and the server minify identically.\n//\n// Rules:\n// - Whitespace-only text that contains a newline is removed when it sits next to a template\n// edge, a block-level tag (head-only tags count: <head>, <meta>, <link>, <base>, <title>),\n// or the inside edge of a <button>/<select> (CSS never renders it there). Inside <head>,\n// whitespace-only text is always removed, newline or not, between holes too: nothing there\n// renders. Between two inline neighbours (phrasing elements, custom elements, holes,\n// comments) it collapses to one space.\n// - Other runs of whitespace in text collapse to one space; a leading or trailing run with a\n// newline next to one of those edges is removed.\n// - <pre>, <textarea>, <script>, <style> and <title> contents, tags and attribute values,\n// and comments are copied unchanged. Holes never move: the result has the same number of\n// strings.\n// The function is idempotent: minifying minified strings changes nothing.\n\n/** Elements whose box is block-level (or never laid out inline) by default. */\nconst BLOCK = new Set(\n (\n 'address article aside blockquote body caption col colgroup datalist dd details dialog div ' +\n 'dl dt fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 head header hgroup hr html ' +\n 'legend li main menu nav ol optgroup option p pre search section select summary table tbody ' +\n 'td tfoot th thead tr ul ' +\n // Head-only elements: never rendered at all, so never inline.\n 'base link meta title ' +\n // SVG containers and shapes: whitespace between them is never rendered.\n 'circle clippath defs ellipse g line lineargradient marker mask path pattern polygon ' +\n 'polyline radialgradient rect stop symbol use'\n ).split(' '),\n);\n\n/** Elements whose text content is copied verbatim (whitespace is meaningful or raw text). */\nconst RAW_TEXT = new Set(['script', 'style', 'textarea', 'title']);\nconst PRESERVE = 'pre';\n\n/** What sits on one side of a text chunk. */\ntype Edge = 'template' | 'inline' | 'block';\n\n/**\n * Inline-block controls: they sit inline among their neighbours, but whitespace at the start or\n * end of their own content is never rendered (it is at the edge of their own line box).\n */\nconst INLINE_BOX = new Set(['button', 'select']);\n\n/**\n * The edge a tag makes for the text next to it. `inside` is true when the text is inside the\n * element (after its start tag, or before its end tag).\n */\nfunction edgeOfTag(name: string, inside: boolean): Edge {\n const lower = name.toLowerCase();\n if (BLOCK.has(lower)) return 'block';\n return inside && INLINE_BOX.has(lower) ? 'block' : 'inline';\n}\n\nconst WS = /^[ \\t\\n\\r\\f]*$/;\nconst RUN = /[ \\t\\n\\r\\f]+/g;\n\n/** `head`: the text is inside `<head>`, which is never rendered. */\nfunction minifyChunk(text: string, left: Edge, right: Edge, head: boolean): string {\n if (text === '') return text;\n if (WS.test(text)) {\n const removable =\n head ||\n (/[\\n\\r]/.test(text) &&\n (left === 'template' || right === 'template' || left === 'block' || right === 'block'));\n return removable ? '' : ' ';\n }\n // Mixed text: a leading or trailing run with a newline next to a removable edge goes too.\n const dropStart = left !== 'inline' && /^[ \\t\\f]*[\\n\\r]/.test(text);\n const dropEnd = right !== 'inline' && /[\\n\\r][ \\t\\n\\r\\f]*$/.test(text);\n let body = text.replace(RUN, ' ');\n if (dropStart) body = body.replace(/^ /, '');\n if (dropEnd) body = body.replace(/ $/, '');\n return body;\n}\n\nconst Mode = { Text: 0, Tag: 1, Comment: 2, RawText: 3 } as const;\ntype Mode = (typeof Mode)[keyof typeof Mode];\n\ninterface Scan {\n mode: Mode;\n /** Quote char while inside an attribute value in a tag, else ''. */\n quote: string;\n /** Name of the tag being read (lower case), and whether it is a closing tag. */\n tagName: string;\n closing: boolean;\n /** Raw-text element we are inside (its contents are copied verbatim). */\n rawName: string;\n /** Depth of open <pre> elements: text is copied verbatim while > 0. */\n preDepth: number;\n /** Inside <head> (until </head> or <body>). */\n head: boolean;\n /** Edge type of the boundary before the current text chunk. */\n left: Edge;\n}\n\nconst TAG_START = /^<(\\/?)([A-Za-z!?][^\\s/>]*)/;\n\n/** Minify one segment, carrying the HTML scan state across bindings. */\nfunction minifySegment(segment: string, state: Scan, last: boolean): string {\n let out = '';\n let chunk = '';\n const flushText = (right: Edge): void => {\n out += state.preDepth > 0 ? chunk : minifyChunk(chunk, state.left, right, state.head);\n chunk = '';\n };\n let i = 0;\n while (i < segment.length) {\n const ch = segment.charAt(i);\n if (state.mode === Mode.Comment) {\n if (segment.startsWith('-->', i)) {\n out += '-->';\n i += 3;\n state.mode = Mode.Text;\n state.left = 'inline';\n } else {\n out += ch;\n i += 1;\n }\n continue;\n }\n if (state.mode === Mode.RawText) {\n const close = `</${state.rawName}`;\n if (segment.slice(i, i + close.length).toLowerCase() === close) {\n state.mode = Mode.Text;\n state.left = 'inline';\n continue; // the closing tag is read in Text mode\n }\n out += ch;\n i += 1;\n continue;\n }\n if (state.mode === Mode.Tag) {\n out += ch;\n i += 1;\n if (state.quote !== '') {\n if (ch === state.quote) state.quote = '';\n } else if (ch === '\"' || ch === \"'\") {\n state.quote = ch;\n } else if (ch === '>') {\n endTag(state, out.endsWith('/>'));\n }\n continue;\n }\n // Text mode.\n if (ch === '<' && segment.startsWith('<!--', i)) {\n flushText('inline');\n state.mode = Mode.Comment;\n out += '<!--';\n i += 4;\n continue;\n }\n const tag = ch === '<' ? TAG_START.exec(segment.slice(i)) : null;\n if (tag !== null) {\n const name = (tag[2] ?? '').toLowerCase();\n const closing = tag[1] === '/';\n flushText(edgeOfTag(name, closing));\n state.closing = closing;\n state.tagName = name;\n state.mode = Mode.Tag;\n out += tag[0];\n i += tag[0].length;\n continue;\n }\n chunk += ch;\n i += 1;\n }\n if (state.mode === Mode.Text) {\n flushText(last ? 'template' : 'inline');\n state.left = 'inline'; // the next segment starts after a binding\n }\n return out;\n}\n\nfunction endTag(state: Scan, selfClosing: boolean): void {\n const name = state.tagName;\n state.mode = Mode.Text;\n state.left = edgeOfTag(name, !state.closing && !selfClosing);\n if (name === 'head' && !selfClosing) state.head = !state.closing;\n if (name === 'body') state.head = false;\n if (name === PRESERVE) {\n if (state.closing) state.preDepth = Math.max(0, state.preDepth - 1);\n else if (!selfClosing) state.preDepth += 1;\n }\n if (!state.closing && !selfClosing && RAW_TEXT.has(name)) {\n state.mode = Mode.RawText;\n state.rawName = name;\n }\n}\n\n/** Minified copy of template strings (same length, bindings unmoved). Idempotent. */\nexport function minifyStrings(strings: readonly string[]): string[] {\n const state: Scan = {\n mode: Mode.Text,\n quote: '',\n tagName: '',\n closing: false,\n rawName: '',\n preDepth: 0,\n head: false,\n left: 'template',\n };\n return strings.map((segment, index) =>\n minifySegment(segment, state, index === strings.length - 1),\n );\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import type * as Prepare from './prepare.js';
2
+ export declare const prepare: typeof Prepare.prepare;
3
+ export declare const verify: typeof Prepare.verify;
@@ -0,0 +1,7 @@
1
+ export const prepare = (strings) => {
2
+ const start = strings.join('${…}').trim().slice(0, 80);
3
+ throw new Error(`gyral: an html template was not compiled: \`${start}\`. Under the gyral-compiled condition ` +
4
+ `every html\`…\` must be compiled by the Gyral Vite preset (view/01-templates.md).`);
5
+ };
6
+ export const verify = () => undefined;
7
+ //# sourceMappingURL=prepare-stub.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepare-stub.js","sourceRoot":"","sources":["../../src/view/prepare-stub.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,OAAO,GAA2B,CAAC,OAAO,EAAE,EAAE;IACzD,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACvD,MAAM,IAAI,KAAK,CACb,+CAA+C,KAAK,yCAAyC;QAC3F,mFAAmF,CACtF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAA0B,GAAG,EAAE,CAAC,SAAS,CAAC","sourcesContent":["// The `gyral-compiled` build of core's `#prepare` import (view/01-templates.md \"Compiled\"):\n// with the Vite preset's template compiler every `html` template is precompiled, so the\n// runtime preparer is left out of the bundle. Reaching this means one template was not.\nimport type * as Prepare from './prepare.js';\n\nexport const prepare: typeof Prepare.prepare = (strings) => {\n const start = strings.join('${…}').trim().slice(0, 80);\n throw new Error(\n `gyral: an html template was not compiled: \\`${start}\\`. Under the gyral-compiled condition ` +\n `every html\\`…\\` must be compiled by the Gyral Vite preset (view/01-templates.md).`,\n );\n};\n\nexport const verify: typeof Prepare.verify = () => undefined;\n"]}
@@ -0,0 +1,8 @@
1
+ import type { TemplateObject } from './normalize/types.js';
2
+ /** The template object of a call site's strings, normalized (with development checks) once. */
3
+ export declare function prepare(strings: readonly string[]): TemplateObject;
4
+ /**
5
+ * Throws rule 7 when the browser's parse of `template.html` (in `el`) differs from the tree
6
+ * the normalizer computed paths for. Templates that didn't come from `prepare` are skipped.
7
+ */
8
+ export declare function verify(template: TemplateObject, el: HTMLTemplateElement): void;
@@ -0,0 +1,57 @@
1
+ // The runtime template preparer (view/01-templates.md "Runtime"), resolved through core's
2
+ // `#prepare` import by default. It runs the normalizer once per call site (template.ts caches
3
+ // the result) and, when the browser first parses a template's HTML (template-element.ts),
4
+ // checks that the parse built exactly the DOM the normalizer's paths assume. A difference
5
+ // means the parser repaired the markup: rule 7 (view/09-template-rules.md). Builds made with
6
+ // the `gyral-compiled` condition get prepare-stub.ts instead.
7
+ import { recordTemplateId } from './normalize/id.js';
8
+ import { analyze } from './normalize/normalize.js';
9
+ import { repairError, shapeMismatch } from './normalize/shape.js';
10
+ const shapes = new WeakMap();
11
+ const prepared = new WeakMap();
12
+ // One-entry cache in front of the WeakMap: list rows ask for the same call site in a row.
13
+ let lastSource;
14
+ let lastTemplate;
15
+ /** The template object of a call site's strings, normalized (with development checks) once. */
16
+ export function prepare(strings) {
17
+ if (strings === lastSource)
18
+ return lastTemplate;
19
+ let template = prepared.get(strings);
20
+ if (template === undefined) {
21
+ const analysis = analyze(strings);
22
+ template = analysis.template;
23
+ recordTemplateId(analysis.template.id, analysis.strings);
24
+ shapes.set(template, analysis.shape);
25
+ prepared.set(strings, template);
26
+ }
27
+ lastSource = strings;
28
+ lastTemplate = template;
29
+ return template;
30
+ }
31
+ /** The DOM the browser built, as a Shape (lower-case names, <template> content inlined). */
32
+ function domShape(nodes) {
33
+ return [...nodes].map((node) => {
34
+ if (node.nodeType === 3)
35
+ return '#text';
36
+ if (node.nodeType === 8)
37
+ return '#comment';
38
+ if (node.nodeType !== 1)
39
+ return [node.nodeName.toLowerCase(), []];
40
+ const el = node;
41
+ const children = el.localName === 'template' ? el.content.childNodes : el.childNodes;
42
+ return [el.localName.toLowerCase(), domShape(children)];
43
+ });
44
+ }
45
+ /**
46
+ * Throws rule 7 when the browser's parse of `template.html` (in `el`) differs from the tree
47
+ * the normalizer computed paths for. Templates that didn't come from `prepare` are skipped.
48
+ */
49
+ export function verify(template, el) {
50
+ const shape = shapes.get(template);
51
+ if (shape === undefined)
52
+ return;
53
+ const problem = shapeMismatch(shape, domShape(el.content.childNodes));
54
+ if (problem !== undefined)
55
+ throw repairError(template, "The browser's HTML parser", problem);
56
+ }
57
+ //# sourceMappingURL=prepare.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepare.js","sourceRoot":"","sources":["../../src/view/prepare.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,8FAA8F;AAC9F,0FAA0F;AAC1F,0FAA0F;AAC1F,6FAA6F;AAC7F,8DAA8D;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGlE,MAAM,MAAM,GAAG,IAAI,OAAO,EAAyB,CAAC;AACpD,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAqC,CAAC;AAClE,0FAA0F;AAC1F,IAAI,UAAyC,CAAC;AAC9C,IAAI,YAAwC,CAAC;AAE7C,+FAA+F;AAC/F,MAAM,UAAU,OAAO,CAAC,OAA0B;IAChD,IAAI,OAAO,KAAK,UAAU;QAAE,OAAO,YAA8B,CAAC;IAClE,IAAI,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACrC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;QAClC,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC;QAC7B,gBAAgB,CA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,KAAK,EAAE,QAAQ,CAAC,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;IACtE,IAAI,OAAO,KAAK,SAAS;QAAE,MAAM,WAAW,CAAC,QAAQ,EAAE,2BAA2B,EAAE,OAAO,CAAC,CAAC;AAC/F,CAAC","sourcesContent":["// The runtime template preparer (view/01-templates.md \"Runtime\"), resolved through core's\n// `#prepare` import by default. It runs the normalizer once per call site (template.ts caches\n// the result) and, when the browser first parses a template's HTML (template-element.ts),\n// checks that the parse built exactly the DOM the normalizer's paths assume. A difference\n// means the parser repaired the markup: rule 7 (view/09-template-rules.md). Builds made with\n// the `gyral-compiled` condition get prepare-stub.ts instead.\nimport { recordTemplateId } from './normalize/id.js';\nimport { analyze } from './normalize/normalize.js';\nimport { repairError, shapeMismatch } from './normalize/shape.js';\nimport type { Shape, ShapeNode, TemplateObject } from './normalize/types.js';\n\nconst shapes = new WeakMap<TemplateObject, Shape>();\nconst prepared = new WeakMap<readonly string[], TemplateObject>();\n// One-entry cache in front of the WeakMap: list rows ask for the same call site in a row.\nlet lastSource: readonly string[] | undefined;\nlet lastTemplate: TemplateObject | undefined;\n\n/** The template object of a call site's strings, normalized (with development checks) once. */\nexport function prepare(strings: readonly string[]): TemplateObject {\n if (strings === lastSource) return lastTemplate as TemplateObject;\n let template = prepared.get(strings);\n if (template === undefined) {\n const analysis = analyze(strings);\n template = analysis.template;\n recordTemplateId(analysis.template.id, analysis.strings);\n shapes.set(template, analysis.shape);\n prepared.set(strings, template);\n }\n lastSource = strings;\n lastTemplate = template;\n return template;\n}\n\n/** The DOM the browser built, as a Shape (lower-case names, <template> content inlined). */\nfunction domShape(nodes: NodeListOf<ChildNode>): Shape {\n return [...nodes].map((node): ShapeNode => {\n if (node.nodeType === 3) return '#text';\n if (node.nodeType === 8) return '#comment';\n if (node.nodeType !== 1) return [node.nodeName.toLowerCase(), []];\n const el = node as Element;\n const children =\n el.localName === 'template' ? (el as HTMLTemplateElement).content.childNodes : el.childNodes;\n return [el.localName.toLowerCase(), domShape(children)];\n });\n}\n\n/**\n * Throws rule 7 when the browser's parse of `template.html` (in `el`) differs from the tree\n * the normalizer computed paths for. Templates that didn't come from `prepare` are skipped.\n */\nexport function verify(template: TemplateObject, el: HTMLTemplateElement): void {\n const shape = shapes.get(template);\n if (shape === undefined) return;\n const problem = shapeMismatch(shape, domShape(el.content.childNodes));\n if (problem !== undefined) throw repairError(template, \"The browser's HTML parser\", problem);\n}\n"]}
@@ -0,0 +1,63 @@
1
+ import type { ChildValue } from './render/values.js';
2
+ /** What a server render of one component returns: its view and what its seed must carry. */
3
+ export interface ServerRendering {
4
+ /** `view(state, intents, ctx)` for the resolved props and state. */
5
+ readonly view: ChildValue;
6
+ /**
7
+ * The `data-gyral-seed` payload (ADR 0012): `props` that no attribute carries, and `state`
8
+ * unless it equals `init(props)`'s state. JSON-serializable.
9
+ */
10
+ readonly seed: {
11
+ readonly state?: unknown;
12
+ readonly props: Readonly<Record<string, unknown>>;
13
+ };
14
+ }
15
+ /** The input of one server render, gathered from the start tag (06 "Components"). */
16
+ export interface ServerRenderInput {
17
+ /** Static attributes plus attribute/boolean holes, as strings (`''` for a present boolean). */
18
+ readonly attributes: Readonly<Record<string, string>>;
19
+ /** Property holes: values as is. */
20
+ readonly properties: Readonly<Record<string, unknown>>;
21
+ /** Messages run through their reducers after `init` (ADR 0008's rejected-form re-render). */
22
+ readonly initialMessages?: readonly unknown[] | undefined;
23
+ /**
24
+ * The nearest provider's scope (opaque to view/), or undefined for the request's own scope.
25
+ * The renderer passes it down: a provider's subtree can span several streamed chunks, so a
26
+ * global set around the subtree would not survive between pulls.
27
+ */
28
+ readonly scope?: unknown;
29
+ }
30
+ /** One registered component, as the server renderer sees it. */
31
+ export interface ServerComponent {
32
+ readonly tag: string;
33
+ /** `shadow: false` (ADR 0014): render as light-DOM children, not `<template shadowrootmode>`. */
34
+ readonly light: boolean;
35
+ /** CSS texts for the declarative shadow root's `<style>` (08). Empty for light components. */
36
+ readonly styles: readonly string[];
37
+ /** The island strategy (07): anything but `load` adds `defer-hydration` and `data-gyral-hydrate`. */
38
+ readonly hydrate: 'load' | 'idle' | 'visible' | 'interaction';
39
+ /** Parses props (validated as in the browser), runs `init` (commands dropped) and the view. */
40
+ render(input: ServerRenderInput): ServerRendering;
41
+ }
42
+ /** Records a component. A tag registered twice keeps its first entry, as `customElements` does. */
43
+ export declare function registerServerComponent(component: ServerComponent): void;
44
+ /** The component registered under `tag`, if any. */
45
+ export declare const serverComponent: (tag: string) => ServerComponent | undefined;
46
+ /** Every registered component (for `styleHashes()`, 06 "CSP"). */
47
+ export declare const serverComponents: () => readonly ServerComponent[];
48
+ /**
49
+ * A server-side provider element (`<gyral-stores>`, ADR 0013): written as a plain element, it
50
+ * gives its subtree a scope (passed to components as `ServerRenderInput.scope`) and may add
51
+ * attributes to its start tag (its seed).
52
+ */
53
+ export interface ServerProvider {
54
+ readonly tag: string;
55
+ open(input: ServerRenderInput): {
56
+ readonly scope: unknown;
57
+ readonly attributes: Readonly<Record<string, string>>;
58
+ };
59
+ }
60
+ /** Records a provider element. A tag registered twice keeps its first entry. */
61
+ export declare function registerServerProvider(provider: ServerProvider): void;
62
+ /** The provider registered under `tag`, if any. */
63
+ export declare const serverProvider: (tag: string) => ServerProvider | undefined;
@@ -0,0 +1,19 @@
1
+ const components = new Map();
2
+ /** Records a component. A tag registered twice keeps its first entry, as `customElements` does. */
3
+ export function registerServerComponent(component) {
4
+ if (!components.has(component.tag))
5
+ components.set(component.tag, component);
6
+ }
7
+ /** The component registered under `tag`, if any. */
8
+ export const serverComponent = (tag) => components.get(tag);
9
+ /** Every registered component (for `styleHashes()`, 06 "CSP"). */
10
+ export const serverComponents = () => [...components.values()];
11
+ const providers = new Map();
12
+ /** Records a provider element. A tag registered twice keeps its first entry. */
13
+ export function registerServerProvider(provider) {
14
+ if (!providers.has(provider.tag))
15
+ providers.set(provider.tag, provider);
16
+ }
17
+ /** The provider registered under `tag`, if any. */
18
+ export const serverProvider = (tag) => providers.get(tag);
19
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/view/registry.ts"],"names":[],"mappings":"AAgDA,MAAM,UAAU,GAAG,IAAI,GAAG,EAA2B,CAAC;AAEtD,mGAAmG;AACnG,MAAM,UAAU,uBAAuB,CAAC,SAA0B;IAChE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC;QAAE,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;AAC/E,CAAC;AAED,oDAAoD;AACpD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAAW,EAA+B,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAEjG,kEAAkE;AAClE,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAA+B,EAAE,CAAC,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;AAe3F,MAAM,SAAS,GAAG,IAAI,GAAG,EAA0B,CAAC;AAEpD,gFAAgF;AAChF,MAAM,UAAU,sBAAsB,CAAC,QAAwB;IAC7D,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;AAC1E,CAAC;AAED,mDAAmD;AACnD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAW,EAA8B,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC","sourcesContent":["// The server registry (view/05-element.md \"Registration\", view/06-server.md \"Components\").\n// Outside the browser `define()` records each spec (server-specs.ts); `@gyral/core/server`\n// turns them into entries here (server-component.ts `registerRecordedSpecs`) before each\n// render, and its renderer (view/server/) looks start tags up and renders the component in\n// place. Providers (`<gyral-stores>`, ADR 0013) register a scope for their subtree. Plain data\n// and functions, no DOM: it lives in view/ so view/server/ can read it.\nimport type { ChildValue } from './render/values.js';\n\n/** What a server render of one component returns: its view and what its seed must carry. */\nexport interface ServerRendering {\n /** `view(state, intents, ctx)` for the resolved props and state. */\n readonly view: ChildValue;\n /**\n * The `data-gyral-seed` payload (ADR 0012): `props` that no attribute carries, and `state`\n * unless it equals `init(props)`'s state. JSON-serializable.\n */\n readonly seed: { readonly state?: unknown; readonly props: Readonly<Record<string, unknown>> };\n}\n\n/** The input of one server render, gathered from the start tag (06 \"Components\"). */\nexport interface ServerRenderInput {\n /** Static attributes plus attribute/boolean holes, as strings (`''` for a present boolean). */\n readonly attributes: Readonly<Record<string, string>>;\n /** Property holes: values as is. */\n readonly properties: Readonly<Record<string, unknown>>;\n /** Messages run through their reducers after `init` (ADR 0008's rejected-form re-render). */\n readonly initialMessages?: readonly unknown[] | undefined;\n /**\n * The nearest provider's scope (opaque to view/), or undefined for the request's own scope.\n * The renderer passes it down: a provider's subtree can span several streamed chunks, so a\n * global set around the subtree would not survive between pulls.\n */\n readonly scope?: unknown;\n}\n\n/** One registered component, as the server renderer sees it. */\nexport interface ServerComponent {\n readonly tag: string;\n /** `shadow: false` (ADR 0014): render as light-DOM children, not `<template shadowrootmode>`. */\n readonly light: boolean;\n /** CSS texts for the declarative shadow root's `<style>` (08). Empty for light components. */\n readonly styles: readonly string[];\n /** The island strategy (07): anything but `load` adds `defer-hydration` and `data-gyral-hydrate`. */\n readonly hydrate: 'load' | 'idle' | 'visible' | 'interaction';\n /** Parses props (validated as in the browser), runs `init` (commands dropped) and the view. */\n render(input: ServerRenderInput): ServerRendering;\n}\n\nconst components = new Map<string, ServerComponent>();\n\n/** Records a component. A tag registered twice keeps its first entry, as `customElements` does. */\nexport function registerServerComponent(component: ServerComponent): void {\n if (!components.has(component.tag)) components.set(component.tag, component);\n}\n\n/** The component registered under `tag`, if any. */\nexport const serverComponent = (tag: string): ServerComponent | undefined => components.get(tag);\n\n/** Every registered component (for `styleHashes()`, 06 \"CSP\"). */\nexport const serverComponents = (): readonly ServerComponent[] => [...components.values()];\n\n/**\n * A server-side provider element (`<gyral-stores>`, ADR 0013): written as a plain element, it\n * gives its subtree a scope (passed to components as `ServerRenderInput.scope`) and may add\n * attributes to its start tag (its seed).\n */\nexport interface ServerProvider {\n readonly tag: string;\n open(input: ServerRenderInput): {\n readonly scope: unknown;\n readonly attributes: Readonly<Record<string, string>>;\n };\n}\n\nconst providers = new Map<string, ServerProvider>();\n\n/** Records a provider element. A tag registered twice keeps its first entry. */\nexport function registerServerProvider(provider: ServerProvider): void {\n if (!providers.has(provider.tag)) providers.set(provider.tag, provider);\n}\n\n/** The provider registered under `tag`, if any. */\nexport const serverProvider = (tag: string): ServerProvider | undefined => providers.get(tag);\n"]}
@@ -0,0 +1,14 @@
1
+ import { type AttrPart } from './attr-parts.js';
2
+ /**
3
+ * Takes this render's values as committed without writing (the server wrote them). Form state
4
+ * the user changed before scripts ran stays: like every part, it writes only when the model's
5
+ * value changes (07 "Form state"). `?indeterminate`, which no attribute carries, is set; a
6
+ * property is set unless a nested component already has it from its own seed.
7
+ */
8
+ export declare function adoptAttr(part: AttrPart, values: readonly unknown[]): void;
9
+ /**
10
+ * Development: the element shows what `part` adopted. Form state the user edits is compared
11
+ * by its attribute or default text, which edits don't change; `?open` isn't compared. `fail`
12
+ * throws the walk's mismatch.
13
+ */
14
+ export declare function checkAttr(part: AttrPart, fail: (expected: string, found: string, at: Node) => never): void;
@@ -0,0 +1,77 @@
1
+ // Element parts in hydration (view/07-hydration.md "The parallel walk", "Form state"): an
2
+ // attribute, property, hook or text part built over server DOM takes this render's values as
3
+ // committed. Lives with the walk, in the lazily loaded hydration code, not in attr-parts.ts.
4
+ import { absent, ATTR, BOOL, CHECKED, HOOK, MULTI, PLAIN, PROP, STATE, TEXTAREA, textOf, TITLE, truthy, VALUE, } from './attr-parts.js';
5
+ /**
6
+ * Takes this render's values as committed without writing (the server wrote them). Form state
7
+ * the user changed before scripts ran stays: like every part, it writes only when the model's
8
+ * value changes (07 "Form state"). `?indeterminate`, which no attribute carries, is set; a
9
+ * property is set unless a nested component already has it from its own seed.
10
+ */
11
+ export function adoptAttr(part, values) {
12
+ const v = values[part.at];
13
+ const el = part.el;
14
+ const live = el;
15
+ const name = part.name;
16
+ const kind = part.kind;
17
+ if (kind === HOOK)
18
+ part.hook(v);
19
+ else if (kind === PROP) {
20
+ part.value = v;
21
+ const own = live[name] !== undefined && el.localName.includes('-');
22
+ if (!own && !Object.is(live[name], v))
23
+ live[name] = v;
24
+ }
25
+ else if (kind === MULTI) {
26
+ const pieces = part.pieces;
27
+ for (let i = 0; i < pieces.length; i++)
28
+ pieces[i] = values[part.at + i];
29
+ part.value = part.join(pieces);
30
+ }
31
+ else if (kind === ATTR || kind === VALUE) {
32
+ part.value = v;
33
+ if (kind === VALUE && PLAIN.test(el.type))
34
+ part.kind = ATTR;
35
+ }
36
+ else if (kind === TITLE || kind === TEXTAREA)
37
+ part.value = textOf(part, v);
38
+ else {
39
+ part.value = truthy(v);
40
+ if (kind === STATE && live[name] !== part.value)
41
+ live[name] = part.value;
42
+ }
43
+ }
44
+ /**
45
+ * Development: the element shows what `part` adopted. Form state the user edits is compared
46
+ * by its attribute or default text, which edits don't change; `?open` isn't compared. `fail`
47
+ * throws the walk's mismatch.
48
+ */
49
+ export function checkAttr(part, fail) {
50
+ const { el, name, value } = part;
51
+ let want = value;
52
+ let got;
53
+ switch (part.kind) {
54
+ case ATTR:
55
+ case VALUE:
56
+ case MULTI:
57
+ if (part.kind !== MULTI)
58
+ want = absent(value) ? null : String(value);
59
+ got = el.getAttribute(name);
60
+ break;
61
+ case BOOL:
62
+ case CHECKED:
63
+ got = el.hasAttribute(name);
64
+ break;
65
+ case TITLE:
66
+ case TEXTAREA:
67
+ got = el.textContent;
68
+ break;
69
+ default:
70
+ return;
71
+ }
72
+ if (got !== want) {
73
+ const what = name === '' ? 'content' : name;
74
+ fail(`${what} ${JSON.stringify(want)}`, `${JSON.stringify(got)} on <${el.localName}>`, el);
75
+ }
76
+ }
77
+ //# sourceMappingURL=adopt-attr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adopt-attr.js","sourceRoot":"","sources":["../../../src/view/render/adopt-attr.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,6FAA6F;AAC7F,6FAA6F;AAC7F,OAAO,EACL,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,IAAI,EACJ,KAAK,EACL,KAAK,EACL,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,MAAM,EACN,KAAK,EACL,MAAM,EACN,KAAK,GAEN,MAAM,iBAAiB,CAAC;AAEzB;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,IAAc,EAAE,MAA0B;IAClE,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1B,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;IACnB,MAAM,IAAI,GAAG,EAAwC,CAAC;IACtD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;IACvB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;IACvB,IAAI,IAAI,KAAK,IAAI;QAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SAC3B,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;QACf,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,SAAS,IAAI,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QACnE,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACxD,CAAC;SAAM,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;QAC1B,MAAM,MAAM,GA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AC,IAAI,KAAK,KAAK;gBAAE,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACrE,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;YAC5B,MAAM;QACR,KAAK,IAAI,CAAC;QACV,KAAK,OAAO;YACV,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;YAC5B,MAAM;QACR,KAAK,KAAK,CAAC;QACX,KAAK,QAAQ;YACX,GAAG,GAAG,EAAE,CAAC,WAAW,CAAC;YACrB,MAAM;QACR;YACE,OAAO;IACX,CAAC;IACD,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QACjB,MAAM,IAAI,GAAG,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;QAC5C,IAAI,CAAC,GAAG,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,SAAS,GAAG,EAAE,EAAE,CAAC,CAAC;IAC7F,CAAC;AACH,CAAC","sourcesContent":["// Element parts in hydration (view/07-hydration.md \"The parallel walk\", \"Form state\"): an\n// attribute, property, hook or text part built over server DOM takes this render's values as\n// committed. Lives with the walk, in the lazily loaded hydration code, not in attr-parts.ts.\nimport {\n absent,\n ATTR,\n BOOL,\n CHECKED,\n HOOK,\n MULTI,\n PLAIN,\n PROP,\n STATE,\n TEXTAREA,\n textOf,\n TITLE,\n truthy,\n VALUE,\n type AttrPart,\n} from './attr-parts.js';\n\n/**\n * Takes this render's values as committed without writing (the server wrote them). Form state\n * the user changed before scripts ran stays: like every part, it writes only when the model's\n * value changes (07 \"Form state\"). `?indeterminate`, which no attribute carries, is set; a\n * property is set unless a nested component already has it from its own seed.\n */\nexport function adoptAttr(part: AttrPart, values: readonly unknown[]): void {\n const v = values[part.at];\n const el = part.el;\n const live = el as unknown as Record<string, unknown>;\n const name = part.name;\n const kind = part.kind;\n if (kind === HOOK) part.hook(v);\n else if (kind === PROP) {\n part.value = v;\n const own = live[name] !== undefined && el.localName.includes('-');\n if (!own && !Object.is(live[name], v)) live[name] = v;\n } else if (kind === MULTI) {\n const pieces = part.pieces as unknown[];\n for (let i = 0; i < pieces.length; i++) pieces[i] = values[part.at + i];\n part.value = part.join(pieces);\n } else if (kind === ATTR || kind === VALUE) {\n part.value = v;\n if (kind === VALUE && PLAIN.test((el as HTMLInputElement).type)) part.kind = ATTR;\n } else if (kind === TITLE || kind === TEXTAREA) part.value = textOf(part, v);\n else {\n part.value = truthy(v);\n if (kind === STATE && live[name] !== part.value) live[name] = part.value;\n }\n}\n\n/**\n * Development: the element shows what `part` adopted. Form state the user edits is compared\n * by its attribute or default text, which edits don't change; `?open` isn't compared. `fail`\n * throws the walk's mismatch.\n */\nexport function checkAttr(\n part: AttrPart,\n fail: (expected: string, found: string, at: Node) => never,\n): void {\n const { el, name, value } = part;\n let want: unknown = value;\n let got: unknown;\n switch (part.kind) {\n case ATTR:\n case VALUE:\n case MULTI:\n if (part.kind !== MULTI) want = absent(value) ? null : String(value);\n got = el.getAttribute(name);\n break;\n case BOOL:\n case CHECKED:\n got = el.hasAttribute(name);\n break;\n case TITLE:\n case TEXTAREA:\n got = el.textContent;\n break;\n default:\n return;\n }\n if (got !== want) {\n const what = name === '' ? 'content' : name;\n fail(`${what} ${JSON.stringify(want)}`, `${JSON.stringify(got)} on <${el.localName}>`, el);\n }\n}\n"]}