@gyral/core 0.1.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 (340) hide show
  1. package/CHANGELOG.md +112 -0
  2. package/LICENSE +1 -1
  3. package/NOTICE +1 -1
  4. package/README.md +9 -7
  5. package/dist/children.d.ts +5 -2
  6. package/dist/children.js +8 -3
  7. package/dist/children.js.map +1 -1
  8. package/dist/command.js +6 -0
  9. package/dist/command.js.map +1 -1
  10. package/dist/compiler/ast.d.ts +21 -0
  11. package/dist/compiler/ast.js +145 -0
  12. package/dist/compiler/ast.js.map +1 -0
  13. package/dist/compiler/compile.d.ts +38 -0
  14. package/dist/compiler/compile.js +129 -0
  15. package/dist/compiler/compile.js.map +1 -0
  16. package/dist/compiler/hooks.d.ts +18 -0
  17. package/dist/compiler/hooks.js +186 -0
  18. package/dist/compiler/hooks.js.map +1 -0
  19. package/dist/compiler/parse5-check.d.ts +21 -0
  20. package/dist/compiler/parse5-check.js +55 -0
  21. package/dist/compiler/parse5-check.js.map +1 -0
  22. package/dist/compiler/scan.d.ts +31 -0
  23. package/dist/compiler/scan.js +152 -0
  24. package/dist/compiler/scan.js.map +1 -0
  25. package/dist/compiler/source.d.ts +34 -0
  26. package/dist/compiler/source.js +114 -0
  27. package/dist/compiler/source.js.map +1 -0
  28. package/dist/define.d.ts +2 -2
  29. package/dist/define.js +35 -334
  30. package/dist/define.js.map +1 -1
  31. package/dist/devtools-events.d.ts +5 -0
  32. package/dist/devtools-events.js.map +1 -1
  33. package/dist/devtools-off.d.ts +1 -0
  34. package/dist/devtools-off.js +1 -0
  35. package/dist/devtools-off.js.map +1 -1
  36. package/dist/devtools.d.ts +1 -0
  37. package/dist/devtools.js +3 -0
  38. package/dist/devtools.js.map +1 -1
  39. package/dist/drivers-scope.d.ts +1 -1
  40. package/dist/drivers-scope.js +1 -8
  41. package/dist/drivers-scope.js.map +1 -1
  42. package/dist/element-types.d.ts +5 -3
  43. package/dist/element-types.js.map +1 -1
  44. package/dist/element.d.ts +3 -0
  45. package/dist/element.js +269 -0
  46. package/dist/element.js.map +1 -0
  47. package/dist/eslint/imports.d.ts +24 -0
  48. package/dist/eslint/imports.js +78 -0
  49. package/dist/eslint/imports.js.map +1 -0
  50. package/dist/eslint/index.d.ts +15 -0
  51. package/dist/eslint/index.js +15 -0
  52. package/dist/eslint/index.js.map +1 -0
  53. package/dist/eslint/locate.d.ts +33 -0
  54. package/dist/eslint/locate.js +132 -0
  55. package/dist/eslint/locate.js.map +1 -0
  56. package/dist/eslint/row-purity-rule.d.ts +2 -0
  57. package/dist/eslint/row-purity-rule.js +103 -0
  58. package/dist/eslint/row-purity-rule.js.map +1 -0
  59. package/dist/eslint/template-rule.d.ts +5 -0
  60. package/dist/eslint/template-rule.js +66 -0
  61. package/dist/eslint/template-rule.js.map +1 -0
  62. package/dist/features.d.ts +39 -0
  63. package/dist/features.js +2 -0
  64. package/dist/features.js.map +1 -0
  65. package/dist/focus.d.ts +9 -2
  66. package/dist/focus.js +17 -2
  67. package/dist/focus.js.map +1 -1
  68. package/dist/hooks/invalid.d.ts +14 -0
  69. package/dist/hooks/invalid.js +72 -0
  70. package/dist/hooks/invalid.js.map +1 -0
  71. package/dist/hooks/labelled-by.d.ts +13 -0
  72. package/dist/hooks/labelled-by.js +51 -0
  73. package/dist/hooks/labelled-by.js.map +1 -0
  74. package/dist/host-model.d.ts +48 -0
  75. package/dist/host-model.js +155 -0
  76. package/dist/host-model.js.map +1 -0
  77. package/dist/hydration-client.d.ts +9 -0
  78. package/dist/hydration-client.js +35 -0
  79. package/dist/hydration-client.js.map +1 -0
  80. package/dist/hydration.d.ts +13 -19
  81. package/dist/hydration.js +45 -45
  82. package/dist/hydration.js.map +1 -1
  83. package/dist/index.d.ts +9 -16
  84. package/dist/index.js +9 -16
  85. package/dist/index.js.map +1 -1
  86. package/dist/intent.d.ts +31 -8
  87. package/dist/intent.js +82 -27
  88. package/dist/intent.js.map +1 -1
  89. package/dist/internal/interpreter.d.ts +7 -1
  90. package/dist/internal/interpreter.js +118 -73
  91. package/dist/internal/interpreter.js.map +1 -1
  92. package/dist/invokers-shim.d.ts +6 -0
  93. package/dist/invokers-shim.js +32 -0
  94. package/dist/invokers-shim.js.map +1 -0
  95. package/dist/invokers.d.ts +3 -5
  96. package/dist/invokers.js +11 -51
  97. package/dist/invokers.js.map +1 -1
  98. package/dist/islands.d.ts +0 -2
  99. package/dist/islands.js +4 -11
  100. package/dist/islands.js.map +1 -1
  101. package/dist/light-dom.d.ts +3 -52
  102. package/dist/light-dom.js +5 -100
  103. package/dist/light-dom.js.map +1 -1
  104. package/dist/prop.d.ts +66 -0
  105. package/dist/prop.js +22 -0
  106. package/dist/prop.js.map +1 -0
  107. package/dist/props.d.ts +52 -21
  108. package/dist/props.js +150 -34
  109. package/dist/props.js.map +1 -1
  110. package/dist/scheduler.d.ts +39 -0
  111. package/dist/scheduler.js +230 -0
  112. package/dist/scheduler.js.map +1 -0
  113. package/dist/server-component.d.ts +10 -0
  114. package/dist/server-component.js +102 -0
  115. package/dist/server-component.js.map +1 -0
  116. package/dist/server-specs.d.ts +6 -0
  117. package/dist/server-specs.js +13 -0
  118. package/dist/server-specs.js.map +1 -0
  119. package/dist/server.d.ts +28 -0
  120. package/dist/server.js +50 -0
  121. package/dist/server.js.map +1 -0
  122. package/dist/settled.d.ts +10 -0
  123. package/dist/settled.js +40 -0
  124. package/dist/settled.js.map +1 -0
  125. package/dist/states.d.ts +3 -3
  126. package/dist/states.js +4 -7
  127. package/dist/states.js.map +1 -1
  128. package/dist/store-binding.d.ts +6 -3
  129. package/dist/store-binding.js +5 -6
  130. package/dist/store-binding.js.map +1 -1
  131. package/dist/store-scope.d.ts +6 -7
  132. package/dist/store-scope.js +11 -26
  133. package/dist/store-scope.js.map +1 -1
  134. package/dist/store.d.ts +3 -0
  135. package/dist/store.js +9 -2
  136. package/dist/store.js.map +1 -1
  137. package/dist/stores-provider.d.ts +2 -6
  138. package/dist/stores-provider.js +21 -55
  139. package/dist/stores-provider.js.map +1 -1
  140. package/dist/transitions.d.ts +5 -6
  141. package/dist/transitions.js +11 -20
  142. package/dist/transitions.js.map +1 -1
  143. package/dist/types.d.ts +19 -23
  144. package/dist/types.js.map +1 -1
  145. package/dist/view/attributes.d.ts +6 -0
  146. package/dist/view/attributes.js +10 -0
  147. package/dist/view/attributes.js.map +1 -0
  148. package/dist/view/compiled.d.ts +1 -0
  149. package/dist/view/compiled.js +6 -0
  150. package/dist/view/compiled.js.map +1 -0
  151. package/dist/view/dev-off.d.ts +1 -0
  152. package/dist/view/dev-off.js +4 -0
  153. package/dist/view/dev-off.js.map +1 -0
  154. package/dist/view/dev.d.ts +1 -0
  155. package/dist/view/dev.js +5 -0
  156. package/dist/view/dev.js.map +1 -0
  157. package/dist/view/flags.d.ts +1 -0
  158. package/dist/view/flags.js +4 -0
  159. package/dist/view/flags.js.map +1 -0
  160. package/dist/view/index.d.ts +21 -0
  161. package/dist/view/index.js +21 -0
  162. package/dist/view/index.js.map +1 -0
  163. package/dist/view/normalize/check.d.ts +20 -0
  164. package/dist/view/normalize/check.js +78 -0
  165. package/dist/view/normalize/check.js.map +1 -0
  166. package/dist/view/normalize/emit.d.ts +13 -0
  167. package/dist/view/normalize/emit.js +136 -0
  168. package/dist/view/normalize/emit.js.map +1 -0
  169. package/dist/view/normalize/entities.d.ts +4 -0
  170. package/dist/view/normalize/entities.js +38 -0
  171. package/dist/view/normalize/entities.js.map +1 -0
  172. package/dist/view/normalize/errors.d.ts +9 -0
  173. package/dist/view/normalize/errors.js +19 -0
  174. package/dist/view/normalize/errors.js.map +1 -0
  175. package/dist/view/normalize/id.d.ts +7 -0
  176. package/dist/view/normalize/id.js +48 -0
  177. package/dist/view/normalize/id.js.map +1 -0
  178. package/dist/view/normalize/normalize.d.ts +15 -0
  179. package/dist/view/normalize/normalize.js +36 -0
  180. package/dist/view/normalize/normalize.js.map +1 -0
  181. package/dist/view/normalize/repairs.d.ts +24 -0
  182. package/dist/view/normalize/repairs.js +166 -0
  183. package/dist/view/normalize/repairs.js.map +1 -0
  184. package/dist/view/normalize/rules.d.ts +30 -0
  185. package/dist/view/normalize/rules.js +90 -0
  186. package/dist/view/normalize/rules.js.map +1 -0
  187. package/dist/view/normalize/shape.d.ts +5 -0
  188. package/dist/view/normalize/shape.js +38 -0
  189. package/dist/view/normalize/shape.js.map +1 -0
  190. package/dist/view/normalize/source.d.ts +13 -0
  191. package/dist/view/normalize/source.js +34 -0
  192. package/dist/view/normalize/source.js.map +1 -0
  193. package/dist/view/normalize/tag-states.d.ts +23 -0
  194. package/dist/view/normalize/tag-states.js +192 -0
  195. package/dist/view/normalize/tag-states.js.map +1 -0
  196. package/dist/view/normalize/tokenizer.d.ts +5 -0
  197. package/dist/view/normalize/tokenizer.js +233 -0
  198. package/dist/view/normalize/tokenizer.js.map +1 -0
  199. package/dist/view/normalize/tokens.d.ts +51 -0
  200. package/dist/view/normalize/tokens.js +24 -0
  201. package/dist/view/normalize/tokens.js.map +1 -0
  202. package/dist/view/normalize/tree.d.ts +59 -0
  203. package/dist/view/normalize/tree.js +190 -0
  204. package/dist/view/normalize/tree.js.map +1 -0
  205. package/dist/view/normalize/types.d.ts +126 -0
  206. package/dist/view/normalize/types.js +26 -0
  207. package/dist/view/normalize/types.js.map +1 -0
  208. package/dist/view/normalize/whitespace.d.ts +2 -0
  209. package/dist/view/normalize/whitespace.js +182 -0
  210. package/dist/view/normalize/whitespace.js.map +1 -0
  211. package/dist/view/prepare-stub.d.ts +3 -0
  212. package/dist/view/prepare-stub.js +7 -0
  213. package/dist/view/prepare-stub.js.map +1 -0
  214. package/dist/view/prepare.d.ts +8 -0
  215. package/dist/view/prepare.js +57 -0
  216. package/dist/view/prepare.js.map +1 -0
  217. package/dist/view/registry.d.ts +63 -0
  218. package/dist/view/registry.js +19 -0
  219. package/dist/view/registry.js.map +1 -0
  220. package/dist/view/render/adopt-attr.d.ts +14 -0
  221. package/dist/view/render/adopt-attr.js +77 -0
  222. package/dist/view/render/adopt-attr.js.map +1 -0
  223. package/dist/view/render/adopt-plan.d.ts +10 -0
  224. package/dist/view/render/adopt-plan.js +26 -0
  225. package/dist/view/render/adopt-plan.js.map +1 -0
  226. package/dist/view/render/adopt.d.ts +3 -0
  227. package/dist/view/render/adopt.js +269 -0
  228. package/dist/view/render/adopt.js.map +1 -0
  229. package/dist/view/render/attr-parts.d.ts +61 -0
  230. package/dist/view/render/attr-parts.js +229 -0
  231. package/dist/view/render/attr-parts.js.map +1 -0
  232. package/dist/view/render/child-part.d.ts +51 -0
  233. package/dist/view/render/child-part.js +170 -0
  234. package/dist/view/render/child-part.js.map +1 -0
  235. package/dist/view/render/dev-check.d.ts +12 -0
  236. package/dist/view/render/dev-check.js +122 -0
  237. package/dist/view/render/dev-check.js.map +1 -0
  238. package/dist/view/render/hook-part.d.ts +3 -0
  239. package/dist/view/render/hook-part.js +20 -0
  240. package/dist/view/render/hook-part.js.map +1 -0
  241. package/dist/view/render/hooks.d.ts +40 -0
  242. package/dist/view/render/hooks.js +46 -0
  243. package/dist/view/render/hooks.js.map +1 -0
  244. package/dist/view/render/hydrate.d.ts +10 -0
  245. package/dist/view/render/hydrate.js +33 -0
  246. package/dist/view/render/hydrate.js.map +1 -0
  247. package/dist/view/render/instance.d.ts +33 -0
  248. package/dist/view/render/instance.js +107 -0
  249. package/dist/view/render/instance.js.map +1 -0
  250. package/dist/view/render/list.d.ts +20 -0
  251. package/dist/view/render/list.js +156 -0
  252. package/dist/view/render/list.js.map +1 -0
  253. package/dist/view/render/mismatch.d.ts +10 -0
  254. package/dist/view/render/mismatch.js +53 -0
  255. package/dist/view/render/mismatch.js.map +1 -0
  256. package/dist/view/render/nodes.d.ts +10 -0
  257. package/dist/view/render/nodes.js +37 -0
  258. package/dist/view/render/nodes.js.map +1 -0
  259. package/dist/view/render/place.d.ts +18 -0
  260. package/dist/view/render/place.js +69 -0
  261. package/dist/view/render/place.js.map +1 -0
  262. package/dist/view/render/plan.d.ts +26 -0
  263. package/dist/view/render/plan.js +124 -0
  264. package/dist/view/render/plan.js.map +1 -0
  265. package/dist/view/render/raw.d.ts +18 -0
  266. package/dist/view/render/raw.js +68 -0
  267. package/dist/view/render/raw.js.map +1 -0
  268. package/dist/view/render/render.d.ts +12 -0
  269. package/dist/view/render/render.js +60 -0
  270. package/dist/view/render/render.js.map +1 -0
  271. package/dist/view/render/reorder.d.ts +4 -0
  272. package/dist/view/render/reorder.js +101 -0
  273. package/dist/view/render/reorder.js.map +1 -0
  274. package/dist/view/render/rows.d.ts +23 -0
  275. package/dist/view/render/rows.js +95 -0
  276. package/dist/view/render/rows.js.map +1 -0
  277. package/dist/view/render/seen.d.ts +11 -0
  278. package/dist/view/render/seen.js +17 -0
  279. package/dist/view/render/seen.js.map +1 -0
  280. package/dist/view/render/values.d.ts +29 -0
  281. package/dist/view/render/values.js +13 -0
  282. package/dist/view/render/values.js.map +1 -0
  283. package/dist/view/render/warn.d.ts +14 -0
  284. package/dist/view/render/warn.js +69 -0
  285. package/dist/view/render/warn.js.map +1 -0
  286. package/dist/view/server/component.d.ts +9 -0
  287. package/dist/view/server/component.js +42 -0
  288. package/dist/view/server/component.js.map +1 -0
  289. package/dist/view/server/escape.d.ts +10 -0
  290. package/dist/view/server/escape.js +34 -0
  291. package/dist/view/server/escape.js.map +1 -0
  292. package/dist/view/server/index.d.ts +28 -0
  293. package/dist/view/server/index.js +72 -0
  294. package/dist/view/server/index.js.map +1 -0
  295. package/dist/view/server/sha256.d.ts +2 -0
  296. package/dist/view/server/sha256.js +75 -0
  297. package/dist/view/server/sha256.js.map +1 -0
  298. package/dist/view/server/tags.d.ts +57 -0
  299. package/dist/view/server/tags.js +121 -0
  300. package/dist/view/server/tags.js.map +1 -0
  301. package/dist/view/server/values.d.ts +16 -0
  302. package/dist/view/server/values.js +86 -0
  303. package/dist/view/server/values.js.map +1 -0
  304. package/dist/view/server/writer.d.ts +16 -0
  305. package/dist/view/server/writer.js +155 -0
  306. package/dist/view/server/writer.js.map +1 -0
  307. package/dist/view/styles.d.ts +25 -0
  308. package/dist/view/styles.js +58 -0
  309. package/dist/view/styles.js.map +1 -0
  310. package/dist/view/template-element.d.ts +3 -0
  311. package/dist/view/template-element.js +25 -0
  312. package/dist/view/template-element.js.map +1 -0
  313. package/dist/view/template.d.ts +21 -0
  314. package/dist/view/template.js +30 -0
  315. package/dist/view/template.js.map +1 -0
  316. package/dist/vite.d.ts +45 -6
  317. package/dist/vite.js +150 -25
  318. package/dist/vite.js.map +1 -1
  319. package/package.json +41 -7
  320. package/dist/accessible-name.d.ts +0 -19
  321. package/dist/accessible-name.js +0 -56
  322. package/dist/accessible-name.js.map +0 -1
  323. package/dist/element-directive.d.ts +0 -20
  324. package/dist/element-directive.js +0 -31
  325. package/dist/element-directive.js.map +0 -1
  326. package/dist/internal/runtime.d.ts +0 -7
  327. package/dist/internal/runtime.js +0 -8
  328. package/dist/internal/runtime.js.map +0 -1
  329. package/dist/invalid.d.ts +0 -21
  330. package/dist/invalid.js +0 -70
  331. package/dist/invalid.js.map +0 -1
  332. package/dist/live-boolean.d.ts +0 -22
  333. package/dist/live-boolean.js +0 -34
  334. package/dist/live-boolean.js.map +0 -1
  335. package/dist/styles.d.ts +0 -12
  336. package/dist/styles.js +0 -11
  337. package/dist/styles.js.map +0 -1
  338. package/dist/textarea.d.ts +0 -26
  339. package/dist/textarea.js +0 -85
  340. package/dist/textarea.js.map +0 -1
@@ -0,0 +1,190 @@
1
+ // Tree builder for the normalizer (view/01-templates.md "Normalization"): turns the tokenizer's
2
+ // tokens into the tree the HTML parser builds for valid markup (WHATWG "tree construction":
3
+ // namespaces, void elements, raw text, the leading newline of <pre>/<listing>/<textarea>), so
4
+ // part paths match the browser's DOM. Markup the parser would repair is an error instead of
5
+ // being modelled (rule 7, repairs.ts), as are rules 3, 4, 6, 10, 12 and 13.
6
+ import { decodeRefs, unquote } from './entities.js';
7
+ import { breaksOutOfForeign, contextOf, rootContext, startRepair, textRepair, } from './repairs.js';
8
+ import { formStateFix, msg, SVG_ONLY, VOID } from './rules.js';
9
+ const RAWTEXT = new Set('script style xmp iframe noembed noframes noscript plaintext'.split(' '));
10
+ const RCDATA = new Set(['textarea', 'title']);
11
+ const LEADING_NEWLINE = new Set(['pre', 'listing', 'textarea']);
12
+ const DOCUMENT = new Set(['html', 'head', 'body']);
13
+ function integrationPoint(el) {
14
+ if (el.ns === 'svg')
15
+ return /^(foreignobject|desc|title)$/.test(el.name);
16
+ return el.ns === 'math' && /^(mi|mo|mn|ms|mtext)$/.test(el.name);
17
+ }
18
+ export class TreeBuilder {
19
+ constructor(src) {
20
+ this.src = src;
21
+ this.root = [];
22
+ this.server = false;
23
+ this.stack = [];
24
+ }
25
+ get children() {
26
+ return this.stack.at(-1)?.children ?? this.root;
27
+ }
28
+ context() {
29
+ const top = this.stack.at(-1);
30
+ if (top === undefined)
31
+ return { ctx: this.rootCtx ?? 'body', atRoot: true };
32
+ if (top.ns !== 'html')
33
+ return { ctx: 'body', atRoot: false };
34
+ if (top.name === 'template')
35
+ return { ctx: top.inner ?? 'body', atRoot: true };
36
+ return { ctx: contextOf(top.name), atRoot: false };
37
+ }
38
+ inTemplate() {
39
+ return this.stack.some((el) => el.ns === 'html' && el.name === 'template');
40
+ }
41
+ text(raw) {
42
+ const text = this.fresh !== undefined && raw.startsWith('\n') ? raw.slice(1) : raw;
43
+ this.fresh = undefined;
44
+ if (text === '')
45
+ return;
46
+ const { ctx, atRoot } = this.context();
47
+ const repair = textRepair(text, ctx, atRoot);
48
+ if (repair !== undefined)
49
+ this.src.fail(7, repair);
50
+ this.children.push({ type: 'text', raw: text });
51
+ }
52
+ comment(raw) {
53
+ this.fresh = undefined;
54
+ this.children.push({ type: 'comment', raw });
55
+ }
56
+ doctype(raw) {
57
+ this.fresh = undefined;
58
+ this.server = true;
59
+ this.children.push({ type: 'doctype', raw });
60
+ }
61
+ hole(kind) {
62
+ this.fresh = undefined;
63
+ if (this.inTemplate())
64
+ this.src.fail(3, msg.inTemplate());
65
+ this.children.push({ type: 'hole', kind });
66
+ }
67
+ start(tag) {
68
+ this.fresh = undefined;
69
+ const { name } = tag;
70
+ const ns = this.namespace(tag);
71
+ if (ns === 'html')
72
+ this.checkHtml(tag);
73
+ if (this.inTemplate() && tag.attrs.some((a) => a.kind !== 'static')) {
74
+ this.src.fail(3, msg.inTemplate());
75
+ }
76
+ const empty = ns === 'html' ? VOID.has(name) : tag.selfClosing;
77
+ const custom = ns === 'html' && name.includes('-');
78
+ const el = {
79
+ type: 'el',
80
+ name,
81
+ raw: tag.raw,
82
+ ns,
83
+ attrs: this.attributes(tag, ns),
84
+ props: custom ? this.props(tag) : undefined,
85
+ empty,
86
+ children: [],
87
+ };
88
+ this.children.push(el);
89
+ if (empty)
90
+ return 'data';
91
+ this.stack.push(el);
92
+ if (ns !== 'html')
93
+ return 'data';
94
+ if (LEADING_NEWLINE.has(name))
95
+ this.fresh = el;
96
+ return RAWTEXT.has(name) ? 'rawtext' : RCDATA.has(name) ? 'rcdata' : 'data';
97
+ }
98
+ namespace(tag) {
99
+ const parent = this.stack.at(-1);
100
+ if (parent === undefined || parent.ns === 'html' || integrationPoint(parent)) {
101
+ return tag.name === 'svg' ? 'svg' : tag.name === 'math' ? 'math' : 'html';
102
+ }
103
+ if (parent.name === 'annotation-xml' && tag.name === 'svg')
104
+ return 'svg';
105
+ const fontAttr = tag.attrs.some((a) => /^(color|face|size)$/i.test(a.name));
106
+ if (breaksOutOfForeign(tag.name, fontAttr)) {
107
+ this.src.fail(7, msg.repaired(`<${tag.name}> inside <${parent.ns}> ends the <${parent.ns}> element`, `Put HTML inside <foreignObject>, or move it out of the <${parent.ns}>.`));
108
+ }
109
+ return parent.ns;
110
+ }
111
+ checkHtml(tag) {
112
+ const { name } = tag;
113
+ if (SVG_ONLY.has(name))
114
+ this.src.fail(10, msg.svgOnly(tag.raw));
115
+ if (DOCUMENT.has(name))
116
+ this.server = true;
117
+ if (tag.selfClosing && !VOID.has(name))
118
+ this.src.fail(6, msg.selfClosing(tag.raw));
119
+ const top = this.stack.at(-1);
120
+ if (top === undefined)
121
+ this.rootCtx ??= rootContext(name);
122
+ else if (top.ns === 'html' && top.name === 'template')
123
+ top.inner ??= rootContext(name);
124
+ const { ctx, atRoot } = this.context();
125
+ const hidden = tag.attrs.some((a) => a.kind === 'static' &&
126
+ a.name.toLowerCase() === 'type' &&
127
+ /^["']?hidden["']?$/i.test(a.value ?? ''));
128
+ const repair = startRepair(name, ctx, atRoot, this.stack, hidden);
129
+ if (repair !== undefined)
130
+ this.src.fail(7, repair);
131
+ }
132
+ /** Bound names lower-cased on HTML elements (not properties); rules 4, 7 (duplicates), 13. */
133
+ attributes(tag, ns) {
134
+ const seen = new Set();
135
+ return tag.attrs.map((a) => {
136
+ const lower = ns === 'html' && a.kind !== 'prop' ? a.name.toLowerCase() : a.name;
137
+ if (a.kind === 'prop' && ns === 'html') {
138
+ const fix = formStateFix(tag.name, a.name);
139
+ if (fix !== undefined)
140
+ this.src.fail(4, msg.formState(tag.name, a.name, fix));
141
+ }
142
+ if (a.kind !== 'prop' && a.kind !== 'hook') {
143
+ const key = ns === 'html' ? lower : a.name;
144
+ if (seen.has(key)) {
145
+ this.src.fail(7, msg.repaired(`${key} appears twice on <${tag.raw}>, and the parser keeps only the first`, `Write it once; to mix static and dynamic text, quote one value: ${key}="a \${…}".`));
146
+ }
147
+ seen.add(key);
148
+ }
149
+ if (a.kind === 'static')
150
+ return a;
151
+ const strings = a.strings?.map((s) => this.decode(s));
152
+ return strings === undefined
153
+ ? { kind: a.kind, name: lower }
154
+ : { kind: a.kind, name: lower, strings };
155
+ });
156
+ }
157
+ props(tag) {
158
+ return tag.attrs.flatMap((a) => a.kind === 'static'
159
+ ? [[a.name.toLowerCase(), a.value === null ? '' : this.decode(unquote(a.value))]]
160
+ : []);
161
+ }
162
+ decode(raw) {
163
+ return decodeRefs(raw, (ref) => this.src.fail(13, msg.charRef(ref)));
164
+ }
165
+ end(name) {
166
+ this.fresh = undefined;
167
+ const top = this.stack.at(-1);
168
+ if (top?.name === name) {
169
+ this.close(top);
170
+ return;
171
+ }
172
+ if (VOID.has(name) && name !== 'br')
173
+ return; // ignored by the parser
174
+ const open = this.stack.some((el) => el.name === name);
175
+ this.src.fail(7, open && top !== undefined
176
+ ? msg.repaired(`</${name}> while <${top.raw}> is still open`, `Close </${top.raw}> first (end tags must match their start tags).`)
177
+ : msg.repaired(`</${name}> has no matching start tag${name === 'br' || name === 'p' ? `, so the parser creates an empty <${name}>` : ''}`, name === 'br' ? 'Write <br>.' : 'Remove it.'));
178
+ }
179
+ close(el) {
180
+ this.stack.pop();
181
+ const hasText = el.children.some((c) => c.type === 'hole' && c.kind === 'text');
182
+ if (hasText && el.children.length !== 1)
183
+ this.src.fail(12, msg.textContent(el.raw));
184
+ }
185
+ finish() {
186
+ for (let el = this.stack.at(-1); el !== undefined; el = this.stack.at(-1))
187
+ this.close(el);
188
+ }
189
+ }
190
+ //# sourceMappingURL=tree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree.js","sourceRoot":"","sources":["../../../src/view/normalize/tree.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,4FAA4F;AAC5F,8FAA8F;AAC9F,4FAA4F;AAC5F,4EAA4E;AAC5E,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,WAAW,EACX,WAAW,EACX,UAAU,GAGX,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AA4B/D,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,6DAA6D,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AAClG,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;AAC9C,MAAM,eAAe,GAAG,IAAI,GAAG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,iDAAiD,CACpE;YACH,CAAC,CAAC,GAAG,CAAC,QAAQ,CACV,KAAK,IAAI,8BAA8B,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,qCAAqC,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,EAC1H,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY,CAC7C,CACN,CAAC;IACJ,CAAC;IAEO,KAAK,CAAC,EAAe;QAC3B,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;QACjB,MAAM,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC;QAChF,IAAI,OAAO,IAAI,EAAE,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC;YAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACtF,CAAC;IAED,MAAM;QACJ,KAAK,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,SAAS,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC5F,CAAC;CACF","sourcesContent":["// Tree builder for the normalizer (view/01-templates.md \"Normalization\"): turns the tokenizer's\n// tokens into the tree the HTML parser builds for valid markup (WHATWG \"tree construction\":\n// namespaces, void elements, raw text, the leading newline of <pre>/<listing>/<textarea>), so\n// part paths match the browser's DOM. Markup the parser would repair is an error instead of\n// being modelled (rule 7, repairs.ts), as are rules 3, 4, 6, 10, 12 and 13.\nimport { decodeRefs, unquote } from './entities.js';\nimport {\n breaksOutOfForeign,\n contextOf,\n rootContext,\n startRepair,\n textRepair,\n type Context,\n type Ns,\n} from './repairs.js';\nimport { formStateFix, msg, SVG_ONLY, VOID } from './rules.js';\nimport type { Source } from './source.js';\nimport type { AttrToken, ContentMode, Sink, StartTag } from './tokenizer.js';\n\nexport interface ElementNode {\n readonly type: 'el';\n /** Lower-case name, and the name as written. */\n readonly name: string;\n readonly raw: string;\n readonly ns: Ns;\n /** Static and bound attributes; bound names normalized, multi strings decoded. */\n readonly attrs: readonly AttrToken[];\n /** A custom element's static attributes, decoded (server props); undefined otherwise. */\n readonly props: readonly (readonly [string, string])[] | undefined;\n /** No end tag: a void element, or a self-closed SVG/MathML element. */\n readonly empty: boolean;\n readonly children: TreeNode[];\n /** For <template>: the context its first start tag chose. */\n inner?: Context;\n}\n\nexport type TreeNode =\n | ElementNode\n | { readonly type: 'text'; readonly raw: string }\n | { readonly type: 'comment'; readonly raw: string }\n | { readonly type: 'doctype'; readonly raw: string }\n | { readonly type: 'hole'; readonly kind: 'child' | 'text' };\n\nconst RAWTEXT = new Set('script style xmp iframe noembed noframes noscript plaintext'.split(' '));\nconst RCDATA = new Set(['textarea', 'title']);\nconst LEADING_NEWLINE = new Set(['pre', 'listing', 'textarea']);\nconst DOCUMENT = new Set(['html', 'head', 'body']);\n\nfunction integrationPoint(el: ElementNode): boolean {\n if (el.ns === 'svg') return /^(foreignobject|desc|title)$/.test(el.name);\n return el.ns === 'math' && /^(mi|mo|mn|ms|mtext)$/.test(el.name);\n}\n\nexport class TreeBuilder implements Sink {\n readonly root: TreeNode[] = [];\n server = false;\n private readonly stack: ElementNode[] = [];\n private rootCtx: Context | undefined;\n /** The <pre>/<listing>/<textarea> whose first newline the parser drops, if just opened. */\n private fresh: ElementNode | undefined;\n\n constructor(private readonly src: Source) {}\n\n private get children(): TreeNode[] {\n return this.stack.at(-1)?.children ?? this.root;\n }\n\n private context(): { ctx: Context; atRoot: boolean } {\n const top = this.stack.at(-1);\n if (top === undefined) return { ctx: this.rootCtx ?? 'body', atRoot: true };\n if (top.ns !== 'html') return { ctx: 'body', atRoot: false };\n if (top.name === 'template') return { ctx: top.inner ?? 'body', atRoot: true };\n return { ctx: contextOf(top.name), atRoot: false };\n }\n\n private inTemplate(): boolean {\n return this.stack.some((el) => el.ns === 'html' && el.name === 'template');\n }\n\n text(raw: string): void {\n const text = this.fresh !== undefined && raw.startsWith('\\n') ? raw.slice(1) : raw;\n this.fresh = undefined;\n if (text === '') return;\n const { ctx, atRoot } = this.context();\n const repair = textRepair(text, ctx, atRoot);\n if (repair !== undefined) this.src.fail(7, repair);\n this.children.push({ type: 'text', raw: text });\n }\n\n comment(raw: string): void {\n this.fresh = undefined;\n this.children.push({ type: 'comment', raw });\n }\n\n doctype(raw: string): void {\n this.fresh = undefined;\n this.server = true;\n this.children.push({ type: 'doctype', raw });\n }\n\n hole(kind: 'child' | 'text'): void {\n this.fresh = undefined;\n if (this.inTemplate()) this.src.fail(3, msg.inTemplate());\n this.children.push({ type: 'hole', kind });\n }\n\n start(tag: StartTag): ContentMode {\n this.fresh = undefined;\n const { name } = tag;\n const ns = this.namespace(tag);\n if (ns === 'html') this.checkHtml(tag);\n if (this.inTemplate() && tag.attrs.some((a) => a.kind !== 'static')) {\n this.src.fail(3, msg.inTemplate());\n }\n const empty = ns === 'html' ? VOID.has(name) : tag.selfClosing;\n const custom = ns === 'html' && name.includes('-');\n const el: ElementNode = {\n type: 'el',\n name,\n raw: tag.raw,\n ns,\n attrs: this.attributes(tag, ns),\n props: custom ? this.props(tag) : undefined,\n empty,\n children: [],\n };\n this.children.push(el);\n if (empty) return 'data';\n this.stack.push(el);\n if (ns !== 'html') return 'data';\n if (LEADING_NEWLINE.has(name)) this.fresh = el;\n return RAWTEXT.has(name) ? 'rawtext' : RCDATA.has(name) ? 'rcdata' : 'data';\n }\n\n private namespace(tag: StartTag): Ns {\n const parent = this.stack.at(-1);\n if (parent === undefined || parent.ns === 'html' || integrationPoint(parent)) {\n return tag.name === 'svg' ? 'svg' : tag.name === 'math' ? 'math' : 'html';\n }\n if (parent.name === 'annotation-xml' && tag.name === 'svg') return 'svg';\n const fontAttr = tag.attrs.some((a) => /^(color|face|size)$/i.test(a.name));\n if (breaksOutOfForeign(tag.name, fontAttr)) {\n this.src.fail(\n 7,\n msg.repaired(\n `<${tag.name}> inside <${parent.ns}> ends the <${parent.ns}> element`,\n `Put HTML inside <foreignObject>, or move it out of the <${parent.ns}>.`,\n ),\n );\n }\n return parent.ns;\n }\n\n private checkHtml(tag: StartTag): void {\n const { name } = tag;\n if (SVG_ONLY.has(name)) this.src.fail(10, msg.svgOnly(tag.raw));\n if (DOCUMENT.has(name)) this.server = true;\n if (tag.selfClosing && !VOID.has(name)) this.src.fail(6, msg.selfClosing(tag.raw));\n const top = this.stack.at(-1);\n if (top === undefined) this.rootCtx ??= rootContext(name);\n else if (top.ns === 'html' && top.name === 'template') top.inner ??= rootContext(name);\n const { ctx, atRoot } = this.context();\n const hidden = tag.attrs.some(\n (a) =>\n a.kind === 'static' &&\n a.name.toLowerCase() === 'type' &&\n /^[\"']?hidden[\"']?$/i.test(a.value ?? ''),\n );\n const repair = startRepair(name, ctx, atRoot, this.stack, hidden);\n if (repair !== undefined) this.src.fail(7, repair);\n }\n\n /** Bound names lower-cased on HTML elements (not properties); rules 4, 7 (duplicates), 13. */\n private attributes(tag: StartTag, ns: Ns): AttrToken[] {\n const seen = new Set<string>();\n return tag.attrs.map((a) => {\n const lower = ns === 'html' && a.kind !== 'prop' ? a.name.toLowerCase() : a.name;\n if (a.kind === 'prop' && ns === 'html') {\n const fix = formStateFix(tag.name, a.name);\n if (fix !== undefined) this.src.fail(4, msg.formState(tag.name, a.name, fix));\n }\n if (a.kind !== 'prop' && a.kind !== 'hook') {\n const key = ns === 'html' ? lower : a.name;\n if (seen.has(key)) {\n this.src.fail(\n 7,\n msg.repaired(\n `${key} appears twice on <${tag.raw}>, and the parser keeps only the first`,\n `Write it once; to mix static and dynamic text, quote one value: ${key}=\"a \\${…}\".`,\n ),\n );\n }\n seen.add(key);\n }\n if (a.kind === 'static') return a;\n const strings = a.strings?.map((s) => this.decode(s));\n return strings === undefined\n ? { kind: a.kind, name: lower }\n : { kind: a.kind, name: lower, strings };\n });\n }\n\n private props(tag: StartTag): [string, string][] {\n return tag.attrs.flatMap((a) =>\n a.kind === 'static'\n ? [[a.name.toLowerCase(), a.value === null ? '' : this.decode(unquote(a.value))]]\n : [],\n );\n }\n\n private decode(raw: string): string {\n return decodeRefs(raw, (ref) => this.src.fail(13, msg.charRef(ref)));\n }\n\n end(name: string): void {\n this.fresh = undefined;\n const top = this.stack.at(-1);\n if (top?.name === name) {\n this.close(top);\n return;\n }\n if (VOID.has(name) && name !== 'br') return; // ignored by the parser\n const open = this.stack.some((el) => el.name === name);\n this.src.fail(\n 7,\n open && top !== undefined\n ? msg.repaired(\n `</${name}> while <${top.raw}> is still open`,\n `Close </${top.raw}> first (end tags must match their start tags).`,\n )\n : msg.repaired(\n `</${name}> has no matching start tag${name === 'br' || name === 'p' ? `, so the parser creates an empty <${name}>` : ''}`,\n name === 'br' ? 'Write <br>.' : 'Remove it.',\n ),\n );\n }\n\n private close(el: ElementNode): void {\n this.stack.pop();\n const hasText = el.children.some((c) => c.type === 'hole' && c.kind === 'text');\n if (hasText && el.children.length !== 1) this.src.fail(12, msg.textContent(el.raw));\n }\n\n finish(): void {\n for (let el = this.stack.at(-1); el !== undefined; el = this.stack.at(-1)) this.close(el);\n }\n}\n"]}
@@ -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[];
@@ -0,0 +1,182 @@
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.
4
+ //
5
+ // Rules:
6
+ // - Whitespace-only text that contains a newline is removed when it sits next to a template
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,
11
+ // comments) it collapses to one space.
12
+ // - Other runs of whitespace in text collapse to one space; a leading or trailing run with a
13
+ // newline next to one of those edges is removed.
14
+ // - <pre>, <textarea>, <script>, <style> and <title> contents, tags and attribute values,
15
+ // and comments are copied unchanged. Holes never move: the result has the same number of
16
+ // strings.
17
+ // The function is idempotent: minifying minified strings changes nothing.
18
+ /** Elements whose box is block-level (or never laid out inline) by default. */
19
+ const BLOCK = new Set(('address article aside blockquote body caption col colgroup datalist dd details dialog div ' +
20
+ 'dl dt fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 head header hgroup hr html ' +
21
+ 'legend li main menu nav ol optgroup option p pre search section select summary table tbody ' +
22
+ 'td tfoot th thead tr ul ' +
23
+ // Head-only elements: never rendered at all, so never inline.
24
+ 'base link meta title ' +
25
+ // SVG containers and shapes: whitespace between them is never rendered.
26
+ 'circle clippath defs ellipse g line lineargradient marker mask path pattern polygon ' +
27
+ 'polyline radialgradient rect stop symbol use').split(' '));
28
+ /** Elements whose text content is copied verbatim (whitespace is meaningful or raw text). */
29
+ const RAW_TEXT = new Set(['script', 'style', 'textarea', 'title']);
30
+ const PRESERVE = 'pre';
31
+ /**
32
+ * Inline-block controls: they sit inline among their neighbours, but whitespace at the start or
33
+ * end of their own content is never rendered (it is at the edge of their own line box).
34
+ */
35
+ const INLINE_BOX = new Set(['button', 'select']);
36
+ /**
37
+ * The edge a tag makes for the text next to it. `inside` is true when the text is inside the
38
+ * element (after its start tag, or before its end tag).
39
+ */
40
+ function edgeOfTag(name, inside) {
41
+ const lower = name.toLowerCase();
42
+ if (BLOCK.has(lower))
43
+ return 'block';
44
+ return inside && INLINE_BOX.has(lower) ? 'block' : 'inline';
45
+ }
46
+ const WS = /^[ \t\n\r\f]*$/;
47
+ const RUN = /[ \t\n\r\f]+/g;
48
+ /** `head`: the text is inside `<head>`, which is never rendered. */
49
+ function minifyChunk(text, left, right, head) {
50
+ if (text === '')
51
+ return text;
52
+ if (WS.test(text)) {
53
+ const removable = head ||
54
+ (/[\n\r]/.test(text) &&
55
+ (left === 'template' || right === 'template' || left === 'block' || right === 'block'));
56
+ return removable ? '' : ' ';
57
+ }
58
+ // Mixed text: a leading or trailing run with a newline next to a removable edge goes too.
59
+ const dropStart = left !== 'inline' && /^[ \t\f]*[\n\r]/.test(text);
60
+ const dropEnd = right !== 'inline' && /[\n\r][ \t\n\r\f]*$/.test(text);
61
+ let body = text.replace(RUN, ' ');
62
+ if (dropStart)
63
+ body = body.replace(/^ /, '');
64
+ if (dropEnd)
65
+ body = body.replace(/ $/, '');
66
+ return body;
67
+ }
68
+ const Mode = { Text: 0, Tag: 1, Comment: 2, RawText: 3 };
69
+ const TAG_START = /^<(\/?)([A-Za-z!?][^\s/>]*)/;
70
+ /** Minify one segment, carrying the HTML scan state across bindings. */
71
+ function minifySegment(segment, state, last) {
72
+ let out = '';
73
+ let chunk = '';
74
+ const flushText = (right) => {
75
+ out += state.preDepth > 0 ? chunk : minifyChunk(chunk, state.left, right, state.head);
76
+ chunk = '';
77
+ };
78
+ let i = 0;
79
+ while (i < segment.length) {
80
+ const ch = segment.charAt(i);
81
+ if (state.mode === Mode.Comment) {
82
+ if (segment.startsWith('-->', i)) {
83
+ out += '-->';
84
+ i += 3;
85
+ state.mode = Mode.Text;
86
+ state.left = 'inline';
87
+ }
88
+ else {
89
+ out += ch;
90
+ i += 1;
91
+ }
92
+ continue;
93
+ }
94
+ if (state.mode === Mode.RawText) {
95
+ const close = `</${state.rawName}`;
96
+ if (segment.slice(i, i + close.length).toLowerCase() === close) {
97
+ state.mode = Mode.Text;
98
+ state.left = 'inline';
99
+ continue; // the closing tag is read in Text mode
100
+ }
101
+ out += ch;
102
+ i += 1;
103
+ continue;
104
+ }
105
+ if (state.mode === Mode.Tag) {
106
+ out += ch;
107
+ i += 1;
108
+ if (state.quote !== '') {
109
+ if (ch === state.quote)
110
+ state.quote = '';
111
+ }
112
+ else if (ch === '"' || ch === "'") {
113
+ state.quote = ch;
114
+ }
115
+ else if (ch === '>') {
116
+ endTag(state, out.endsWith('/>'));
117
+ }
118
+ continue;
119
+ }
120
+ // Text mode.
121
+ if (ch === '<' && segment.startsWith('<!--', i)) {
122
+ flushText('inline');
123
+ state.mode = Mode.Comment;
124
+ out += '<!--';
125
+ i += 4;
126
+ continue;
127
+ }
128
+ const tag = ch === '<' ? TAG_START.exec(segment.slice(i)) : null;
129
+ if (tag !== null) {
130
+ const name = (tag[2] ?? '').toLowerCase();
131
+ const closing = tag[1] === '/';
132
+ flushText(edgeOfTag(name, closing));
133
+ state.closing = closing;
134
+ state.tagName = name;
135
+ state.mode = Mode.Tag;
136
+ out += tag[0];
137
+ i += tag[0].length;
138
+ continue;
139
+ }
140
+ chunk += ch;
141
+ i += 1;
142
+ }
143
+ if (state.mode === Mode.Text) {
144
+ flushText(last ? 'template' : 'inline');
145
+ state.left = 'inline'; // the next segment starts after a binding
146
+ }
147
+ return out;
148
+ }
149
+ function endTag(state, selfClosing) {
150
+ const name = state.tagName;
151
+ state.mode = Mode.Text;
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;
157
+ if (name === PRESERVE) {
158
+ if (state.closing)
159
+ state.preDepth = Math.max(0, state.preDepth - 1);
160
+ else if (!selfClosing)
161
+ state.preDepth += 1;
162
+ }
163
+ if (!state.closing && !selfClosing && RAW_TEXT.has(name)) {
164
+ state.mode = Mode.RawText;
165
+ state.rawName = name;
166
+ }
167
+ }
168
+ /** Minified copy of template strings (same length, bindings unmoved). Idempotent. */
169
+ export function minifyStrings(strings) {
170
+ const state = {
171
+ mode: Mode.Text,
172
+ quote: '',
173
+ tagName: '',
174
+ closing: false,
175
+ rawName: '',
176
+ preDepth: 0,
177
+ head: false,
178
+ left: 'template',
179
+ };
180
+ return strings.map((segment, index) => minifySegment(segment, state, index === strings.length - 1));
181
+ }
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,uFAA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,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"]}