@fluixi/compiler 1.0.0-alpha.100

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 (303) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +131 -0
  3. package/dist/analyze/expr-shape.cjs +62 -0
  4. package/dist/analyze/expr-shape.d.cts +14 -0
  5. package/dist/analyze/expr-shape.d.ts +15 -0
  6. package/dist/analyze/expr-shape.d.ts.map +1 -0
  7. package/dist/analyze/expr-shape.js +37 -0
  8. package/dist/analyze/expr-shape.mjs +41 -0
  9. package/dist/analyze/intrinsics.cjs +112 -0
  10. package/dist/analyze/intrinsics.d.cts +80 -0
  11. package/dist/analyze/intrinsics.d.ts +81 -0
  12. package/dist/analyze/intrinsics.d.ts.map +1 -0
  13. package/dist/analyze/intrinsics.js +126 -0
  14. package/dist/analyze/intrinsics.mjs +91 -0
  15. package/dist/analyze/paren.cjs +134 -0
  16. package/dist/analyze/paren.d.cts +23 -0
  17. package/dist/analyze/paren.d.ts +24 -0
  18. package/dist/analyze/paren.d.ts.map +1 -0
  19. package/dist/analyze/paren.js +168 -0
  20. package/dist/analyze/paren.mjs +113 -0
  21. package/dist/analyze/props-destructure.cjs +226 -0
  22. package/dist/analyze/props-destructure.d.cts +83 -0
  23. package/dist/analyze/props-destructure.d.ts +84 -0
  24. package/dist/analyze/props-destructure.d.ts.map +1 -0
  25. package/dist/analyze/props-destructure.js +272 -0
  26. package/dist/analyze/props-destructure.mjs +205 -0
  27. package/dist/analyze/reactive-bindings.cjs +210 -0
  28. package/dist/analyze/reactive-bindings.d.cts +42 -0
  29. package/dist/analyze/reactive-bindings.d.ts +43 -0
  30. package/dist/analyze/reactive-bindings.d.ts.map +1 -0
  31. package/dist/analyze/reactive-bindings.js +191 -0
  32. package/dist/analyze/reactive-bindings.mjs +187 -0
  33. package/dist/analyze/reactive-expr.cjs +38 -0
  34. package/dist/analyze/reactive-expr.d.cts +38 -0
  35. package/dist/analyze/reactive-expr.d.ts +39 -0
  36. package/dist/analyze/reactive-expr.d.ts.map +1 -0
  37. package/dist/analyze/reactive-expr.js +31 -0
  38. package/dist/analyze/reactive-expr.mjs +17 -0
  39. package/dist/analyze/static-graph.cjs +831 -0
  40. package/dist/analyze/static-graph.d.cts +102 -0
  41. package/dist/analyze/static-graph.d.ts +103 -0
  42. package/dist/analyze/static-graph.d.ts.map +1 -0
  43. package/dist/analyze/static-graph.js +871 -0
  44. package/dist/analyze/static-graph.mjs +813 -0
  45. package/dist/babel-I6BUWUCU.mjs +636 -0
  46. package/dist/chunk-3AICWNF7.mjs +92 -0
  47. package/dist/chunk-6CWJWGE2.mjs +2170 -0
  48. package/dist/chunk-C3XPDB4Y.mjs +16 -0
  49. package/dist/chunk-GX5XV6Z7.mjs +190 -0
  50. package/dist/chunk-HXEXPWJ2.mjs +999 -0
  51. package/dist/chunk-NU3W67UZ.mjs +584 -0
  52. package/dist/chunk-SKAVY75W.mjs +11 -0
  53. package/dist/codegen/backend.cjs +18 -0
  54. package/dist/codegen/backend.d.cts +35 -0
  55. package/dist/codegen/backend.d.ts +36 -0
  56. package/dist/codegen/backend.d.ts.map +1 -0
  57. package/dist/codegen/backend.js +1 -0
  58. package/dist/codegen/backend.mjs +0 -0
  59. package/dist/codegen/backends/imperative.cjs +577 -0
  60. package/dist/codegen/backends/imperative.d.cts +11 -0
  61. package/dist/codegen/backends/imperative.d.ts +12 -0
  62. package/dist/codegen/backends/imperative.d.ts.map +1 -0
  63. package/dist/codegen/backends/imperative.js +362 -0
  64. package/dist/codegen/backends/imperative.mjs +554 -0
  65. package/dist/codegen/contract.cjs +52 -0
  66. package/dist/codegen/contract.d.cts +24 -0
  67. package/dist/codegen/contract.d.ts +25 -0
  68. package/dist/codegen/contract.d.ts.map +1 -0
  69. package/dist/codegen/contract.js +30 -0
  70. package/dist/codegen/contract.mjs +31 -0
  71. package/dist/codegen/partial-template.cjs +176 -0
  72. package/dist/codegen/partial-template.d.cts +61 -0
  73. package/dist/codegen/partial-template.d.ts +62 -0
  74. package/dist/codegen/partial-template.d.ts.map +1 -0
  75. package/dist/codegen/partial-template.js +0 -0
  76. package/dist/codegen/partial-template.mjs +153 -0
  77. package/dist/codegen/serialize-static.cjs +125 -0
  78. package/dist/codegen/serialize-static.d.cts +38 -0
  79. package/dist/codegen/serialize-static.d.ts +39 -0
  80. package/dist/codegen/serialize-static.d.ts.map +1 -0
  81. package/dist/codegen/serialize-static.js +165 -0
  82. package/dist/codegen/serialize-static.mjs +104 -0
  83. package/dist/frontend/babel/build-ir-lit.cjs +1933 -0
  84. package/dist/frontend/babel/build-ir-lit.d.cts +26 -0
  85. package/dist/frontend/babel/build-ir-lit.d.ts +27 -0
  86. package/dist/frontend/babel/build-ir-lit.d.ts.map +1 -0
  87. package/dist/frontend/babel/build-ir-lit.js +13 -0
  88. package/dist/frontend/babel/build-ir-lit.mjs +1902 -0
  89. package/dist/frontend/babel/build-ir.cjs +1948 -0
  90. package/dist/frontend/babel/build-ir.d.cts +35 -0
  91. package/dist/frontend/babel/build-ir.d.ts +36 -0
  92. package/dist/frontend/babel/build-ir.d.ts.map +1 -0
  93. package/dist/frontend/babel/build-ir.js +124 -0
  94. package/dist/frontend/babel/build-ir.mjs +1919 -0
  95. package/dist/frontend/babel/index.cjs +2610 -0
  96. package/dist/frontend/babel/index.d.cts +33 -0
  97. package/dist/frontend/babel/index.d.ts +34 -0
  98. package/dist/frontend/babel/index.d.ts.map +1 -0
  99. package/dist/frontend/babel/index.js +65 -0
  100. package/dist/frontend/babel/index.mjs +2580 -0
  101. package/dist/frontend/babel/lower-template.cjs +1931 -0
  102. package/dist/frontend/babel/lower-template.d.cts +23 -0
  103. package/dist/frontend/babel/lower-template.d.ts +24 -0
  104. package/dist/frontend/babel/lower-template.d.ts.map +1 -0
  105. package/dist/frontend/babel/lower-template.js +64 -0
  106. package/dist/frontend/babel/lower-template.mjs +1902 -0
  107. package/dist/frontend/babel/plugin.cjs +2556 -0
  108. package/dist/frontend/babel/plugin.d.cts +95 -0
  109. package/dist/frontend/babel/plugin.d.ts +96 -0
  110. package/dist/frontend/babel/plugin.d.ts.map +1 -0
  111. package/dist/frontend/babel/plugin.js +523 -0
  112. package/dist/frontend/babel/plugin.mjs +2527 -0
  113. package/dist/frontend/babel/server-functions.cjs +110 -0
  114. package/dist/frontend/babel/server-functions.d.cts +10 -0
  115. package/dist/frontend/babel/server-functions.d.ts +11 -0
  116. package/dist/frontend/babel/server-functions.d.ts.map +1 -0
  117. package/dist/frontend/babel/server-functions.js +81 -0
  118. package/dist/frontend/babel/server-functions.mjs +89 -0
  119. package/dist/frontend/babel/types.cjs +18 -0
  120. package/dist/frontend/babel/types.d.cts +33 -0
  121. package/dist/frontend/babel/types.d.ts +34 -0
  122. package/dist/frontend/babel/types.d.ts.map +1 -0
  123. package/dist/frontend/babel/types.js +1 -0
  124. package/dist/frontend/babel/types.mjs +0 -0
  125. package/dist/frontend/types.cjs +18 -0
  126. package/dist/frontend/types.d.cts +25 -0
  127. package/dist/frontend/types.d.ts +26 -0
  128. package/dist/frontend/types.d.ts.map +1 -0
  129. package/dist/frontend/types.js +1 -0
  130. package/dist/frontend/types.mjs +0 -0
  131. package/dist/frontend/vocabulary.cjs +98 -0
  132. package/dist/frontend/vocabulary.d.cts +79 -0
  133. package/dist/frontend/vocabulary.d.ts +80 -0
  134. package/dist/frontend/vocabulary.d.ts.map +1 -0
  135. package/dist/frontend/vocabulary.js +124 -0
  136. package/dist/frontend/vocabulary.mjs +77 -0
  137. package/dist/index.cjs +1957 -0
  138. package/dist/index.d.cts +27 -0
  139. package/dist/index.d.ts +28 -0
  140. package/dist/index.d.ts.map +1 -0
  141. package/dist/index.js +38 -0
  142. package/dist/index.mjs +1949 -0
  143. package/dist/integrations.cjs +5705 -0
  144. package/dist/integrations.d.cts +215 -0
  145. package/dist/integrations.d.ts +216 -0
  146. package/dist/integrations.d.ts.map +1 -0
  147. package/dist/integrations.js +566 -0
  148. package/dist/integrations.mjs +810 -0
  149. package/dist/ir/nodes.cjs +18 -0
  150. package/dist/ir/nodes.d.cts +168 -0
  151. package/dist/ir/nodes.d.ts +169 -0
  152. package/dist/ir/nodes.d.ts.map +1 -0
  153. package/dist/ir/nodes.js +1 -0
  154. package/dist/ir/nodes.mjs +0 -0
  155. package/dist/lower/compile-template.cjs +1670 -0
  156. package/dist/lower/compile-template.d.cts +82 -0
  157. package/dist/lower/compile-template.d.ts +83 -0
  158. package/dist/lower/compile-template.d.ts.map +1 -0
  159. package/dist/lower/compile-template.js +79 -0
  160. package/dist/lower/compile-template.mjs +1662 -0
  161. package/dist/lower/entities.cjs +288 -0
  162. package/dist/lower/entities.d.cts +1 -0
  163. package/dist/lower/entities.d.ts +2 -0
  164. package/dist/lower/entities.d.ts.map +1 -0
  165. package/dist/lower/entities.js +54 -0
  166. package/dist/lower/entities.mjs +267 -0
  167. package/dist/lower/jsx.cjs +1101 -0
  168. package/dist/lower/jsx.d.cts +33 -0
  169. package/dist/lower/jsx.d.ts +34 -0
  170. package/dist/lower/jsx.d.ts.map +1 -0
  171. package/dist/lower/jsx.js +414 -0
  172. package/dist/lower/jsx.mjs +1078 -0
  173. package/dist/lower/template.cjs +1354 -0
  174. package/dist/lower/template.d.cts +53 -0
  175. package/dist/lower/template.d.ts +54 -0
  176. package/dist/lower/template.d.ts.map +1 -0
  177. package/dist/lower/template.js +542 -0
  178. package/dist/lower/template.mjs +1335 -0
  179. package/dist/lower/text.cjs +42 -0
  180. package/dist/lower/text.d.cts +10 -0
  181. package/dist/lower/text.d.ts +11 -0
  182. package/dist/lower/text.d.ts.map +1 -0
  183. package/dist/lower/text.js +31 -0
  184. package/dist/lower/text.mjs +21 -0
  185. package/dist/optimize/analyze-static.cjs +112 -0
  186. package/dist/optimize/analyze-static.d.cts +39 -0
  187. package/dist/optimize/analyze-static.d.ts +40 -0
  188. package/dist/optimize/analyze-static.d.ts.map +1 -0
  189. package/dist/optimize/analyze-static.js +131 -0
  190. package/dist/optimize/analyze-static.mjs +91 -0
  191. package/dist/optimize/collapse-strategies.cjs +90 -0
  192. package/dist/optimize/collapse-strategies.d.cts +30 -0
  193. package/dist/optimize/collapse-strategies.d.ts +31 -0
  194. package/dist/optimize/collapse-strategies.d.ts.map +1 -0
  195. package/dist/optimize/collapse-strategies.js +33 -0
  196. package/dist/optimize/collapse-strategies.mjs +67 -0
  197. package/dist/options.cjs +33 -0
  198. package/dist/options.d.cts +39 -0
  199. package/dist/options.d.ts +40 -0
  200. package/dist/options.d.ts.map +1 -0
  201. package/dist/options.js +8 -0
  202. package/dist/options.mjs +12 -0
  203. package/dist/resolve/builtins.cjs +73 -0
  204. package/dist/resolve/builtins.d.cts +68 -0
  205. package/dist/resolve/builtins.d.ts +69 -0
  206. package/dist/resolve/builtins.d.ts.map +1 -0
  207. package/dist/resolve/builtins.js +64 -0
  208. package/dist/resolve/builtins.mjs +53 -0
  209. package/dist/resolve/component-globals.cjs +272 -0
  210. package/dist/resolve/component-globals.d.cts +88 -0
  211. package/dist/resolve/component-globals.d.ts +89 -0
  212. package/dist/resolve/component-globals.d.ts.map +1 -0
  213. package/dist/resolve/component-globals.js +160 -0
  214. package/dist/resolve/component-globals.mjs +249 -0
  215. package/dist/resolve/component-resolver.cjs +80 -0
  216. package/dist/resolve/component-resolver.d.cts +68 -0
  217. package/dist/resolve/component-resolver.d.ts +69 -0
  218. package/dist/resolve/component-resolver.d.ts.map +1 -0
  219. package/dist/resolve/component-resolver.js +95 -0
  220. package/dist/resolve/component-resolver.mjs +59 -0
  221. package/dist/resolve/load-directive.cjs +93 -0
  222. package/dist/resolve/load-directive.d.cts +53 -0
  223. package/dist/resolve/load-directive.d.ts +54 -0
  224. package/dist/resolve/load-directive.d.ts.map +1 -0
  225. package/dist/resolve/load-directive.js +93 -0
  226. package/dist/resolve/load-directive.mjs +72 -0
  227. package/dist/resolve/resolve-ir.cjs +108 -0
  228. package/dist/resolve/resolve-ir.d.cts +53 -0
  229. package/dist/resolve/resolve-ir.d.ts +54 -0
  230. package/dist/resolve/resolve-ir.d.ts.map +1 -0
  231. package/dist/resolve/resolve-ir.js +58 -0
  232. package/dist/resolve/resolve-ir.mjs +85 -0
  233. package/dist/resolve/write-globals.cjs +383 -0
  234. package/dist/resolve/write-globals.d.cts +36 -0
  235. package/dist/resolve/write-globals.d.ts +37 -0
  236. package/dist/resolve/write-globals.d.ts.map +1 -0
  237. package/dist/resolve/write-globals.js +169 -0
  238. package/dist/resolve/write-globals.mjs +362 -0
  239. package/dist/server-fns-VZLHMQTC.mjs +79 -0
  240. package/dist/server-functions-UAZKOLZW.mjs +82 -0
  241. package/dist/transform/bindings.cjs +71 -0
  242. package/dist/transform/bindings.d.cts +16 -0
  243. package/dist/transform/bindings.d.ts +17 -0
  244. package/dist/transform/bindings.d.ts.map +1 -0
  245. package/dist/transform/bindings.js +69 -0
  246. package/dist/transform/bindings.mjs +50 -0
  247. package/dist/transform/index.cjs +3837 -0
  248. package/dist/transform/index.d.cts +15 -0
  249. package/dist/transform/index.d.ts +16 -0
  250. package/dist/transform/index.d.ts.map +1 -0
  251. package/dist/transform/index.js +12 -0
  252. package/dist/transform/index.mjs +4882 -0
  253. package/dist/transform/intrinsics.cjs +261 -0
  254. package/dist/transform/intrinsics.d.cts +33 -0
  255. package/dist/transform/intrinsics.d.ts +34 -0
  256. package/dist/transform/intrinsics.d.ts.map +1 -0
  257. package/dist/transform/intrinsics.js +120 -0
  258. package/dist/transform/intrinsics.mjs +238 -0
  259. package/dist/transform/props.cjs +441 -0
  260. package/dist/transform/props.d.cts +45 -0
  261. package/dist/transform/props.d.ts +46 -0
  262. package/dist/transform/props.d.ts.map +1 -0
  263. package/dist/transform/props.js +221 -0
  264. package/dist/transform/props.mjs +1487 -0
  265. package/dist/transform/server-fn-id.cjs +35 -0
  266. package/dist/transform/server-fn-id.d.cts +9 -0
  267. package/dist/transform/server-fn-id.d.ts +10 -0
  268. package/dist/transform/server-fn-id.d.ts.map +1 -0
  269. package/dist/transform/server-fn-id.js +18 -0
  270. package/dist/transform/server-fn-id.mjs +14 -0
  271. package/dist/transform/server-fns.cjs +114 -0
  272. package/dist/transform/server-fns.d.cts +12 -0
  273. package/dist/transform/server-fns.d.ts +13 -0
  274. package/dist/transform/server-fns.d.ts.map +1 -0
  275. package/dist/transform/server-fns.js +94 -0
  276. package/dist/transform/server-fns.mjs +1160 -0
  277. package/dist/transform/source-locations.cjs +393 -0
  278. package/dist/transform/source-locations.d.cts +48 -0
  279. package/dist/transform/source-locations.d.ts +49 -0
  280. package/dist/transform/source-locations.d.ts.map +1 -0
  281. package/dist/transform/source-locations.js +303 -0
  282. package/dist/transform/source-locations.mjs +370 -0
  283. package/dist/transform/styles.cjs +606 -0
  284. package/dist/transform/styles.d.cts +237 -0
  285. package/dist/transform/styles.d.ts +238 -0
  286. package/dist/transform/styles.d.ts.map +1 -0
  287. package/dist/transform/styles.js +743 -0
  288. package/dist/transform/styles.mjs +671 -0
  289. package/dist/transform/templates.cjs +3806 -0
  290. package/dist/transform/templates.d.cts +82 -0
  291. package/dist/transform/templates.d.ts +83 -0
  292. package/dist/transform/templates.d.ts.map +1 -0
  293. package/dist/transform/templates.js +613 -0
  294. package/dist/transform/templates.mjs +4852 -0
  295. package/dist/transform-3W45L3EA.mjs +951 -0
  296. package/dist/tsconfig.lib.tsbuildinfo +1 -0
  297. package/dist/vite-styles.cjs +223 -0
  298. package/dist/vite-styles.d.cts +68 -0
  299. package/dist/vite-styles.d.ts +69 -0
  300. package/dist/vite-styles.d.ts.map +1 -0
  301. package/dist/vite-styles.js +241 -0
  302. package/dist/vite-styles.mjs +214 -0
  303. package/package.json +141 -0
@@ -0,0 +1,1354 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/lower/template.ts
21
+ var template_exports = {};
22
+ __export(template_exports, {
23
+ lowerTemplate: () => lowerTemplate
24
+ });
25
+ module.exports = __toCommonJS(template_exports);
26
+ var import_template_parser = require("@fluixi/template-parser");
27
+
28
+ // src/resolve/load-directive.ts
29
+ var EAGER = { kind: "eager" };
30
+ var DEFAULT_INTERACTION_EVENTS = ["pointerdown", "focusin", "keydown"];
31
+ var STRATEGIES = /* @__PURE__ */ new Set(["eager", "idle", "visible", "interaction", "media", "never"]);
32
+ var LoadDirectiveError = class extends Error {
33
+ };
34
+ function parseLoadDirective(name, value) {
35
+ const strategy = name.slice("load:".length);
36
+ if (!STRATEGIES.has(strategy)) {
37
+ throw new LoadDirectiveError(
38
+ `Unknown load strategy 'load:${strategy}'. Expected one of ${[...STRATEGIES].join(", ")}.`
39
+ );
40
+ }
41
+ switch (strategy) {
42
+ case "eager":
43
+ return EAGER;
44
+ case "idle":
45
+ return { kind: "idle" };
46
+ case "never":
47
+ return { kind: "never" };
48
+ case "visible":
49
+ return value ? { kind: "visible", rootMargin: value } : { kind: "visible" };
50
+ case "interaction":
51
+ return {
52
+ kind: "interaction",
53
+ events: value ? splitEvents(value) : [...DEFAULT_INTERACTION_EVENTS]
54
+ };
55
+ case "media":
56
+ if (!value) {
57
+ throw new LoadDirectiveError(
58
+ `'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`
59
+ );
60
+ }
61
+ return { kind: "media", query: value };
62
+ default:
63
+ throw new LoadDirectiveError(`Unhandled load strategy '${strategy}'.`);
64
+ }
65
+ }
66
+ function splitEvents(value) {
67
+ const events = value.split(/[\s,]+/).map((e) => e.trim()).filter(Boolean);
68
+ if (events.length === 0) {
69
+ throw new LoadDirectiveError(`'load:interaction' was given no event names.`);
70
+ }
71
+ return events;
72
+ }
73
+
74
+ // src/codegen/serialize-static.ts
75
+ var VOID_ELEMENTS = /* @__PURE__ */ new Set([
76
+ "area",
77
+ "base",
78
+ "br",
79
+ "col",
80
+ "embed",
81
+ "hr",
82
+ "img",
83
+ "input",
84
+ "link",
85
+ "meta",
86
+ "param",
87
+ "source",
88
+ "track",
89
+ "wbr"
90
+ ]);
91
+ var HTML_NAME = {
92
+ className: "class",
93
+ htmlFor: "for"
94
+ };
95
+ var PROPERTY_ONLY = /* @__PURE__ */ new Set([
96
+ "innerHTML",
97
+ "outerHTML",
98
+ "innerText",
99
+ "textContent",
100
+ "value",
101
+ "checked",
102
+ "selected",
103
+ "muted",
104
+ "defaultValue",
105
+ "defaultChecked",
106
+ "children",
107
+ "ref"
108
+ ]);
109
+ var RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set(["script", "style", "textarea", "title"]);
110
+ function isRawTextElement(tag) {
111
+ return RAW_TEXT_ELEMENTS.has(tag);
112
+ }
113
+ function htmlAttrName(name) {
114
+ return HTML_NAME[name] ?? name;
115
+ }
116
+ function isPlainLiteralAttr(prop) {
117
+ if (prop.kind !== "attr") return false;
118
+ if (prop.expr !== void 0) return false;
119
+ if (prop.name.includes(":")) return false;
120
+ return !PROPERTY_ONLY.has(prop.name);
121
+ }
122
+ function isSerializable(node) {
123
+ if (!node.static) return false;
124
+ if (isRawTextElement(node.tag)) return false;
125
+ for (const prop of node.props) {
126
+ if (!isPlainLiteralAttr(prop)) return false;
127
+ }
128
+ for (const child of node.children) {
129
+ if (child.kind === "text") continue;
130
+ if (child.kind === "element" && isSerializable(child)) continue;
131
+ return false;
132
+ }
133
+ return true;
134
+ }
135
+ function serializeStatic(node) {
136
+ const attrs = node.props.map(serializeProp).filter(Boolean).join("");
137
+ const open = `<${node.tag}${attrs}>`;
138
+ if (VOID_ELEMENTS.has(node.tag)) return open;
139
+ return `${open}${node.children.map(serializeChild).join("")}</${node.tag}>`;
140
+ }
141
+ function serializeChild(child) {
142
+ if (child.kind === "text") return escapeText(child.value);
143
+ if (child.kind !== "element") throw new Error(`serializeStatic: unexpected ${child.kind}`);
144
+ return serializeStatic(child);
145
+ }
146
+ function serializeProp(prop) {
147
+ const name = HTML_NAME[prop.name] ?? prop.name;
148
+ const value = prop.literal;
149
+ if (value === true || value === void 0) return ` ${name}`;
150
+ if (value === false || value === null) return "";
151
+ return ` ${name}="${escapeAttr(String(value))}"`;
152
+ }
153
+ function escapeAttr(value) {
154
+ return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
155
+ }
156
+ function escapeText(value) {
157
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
158
+ }
159
+ function templatePositions(root) {
160
+ const pos = [];
161
+ let file;
162
+ const walk = (el) => {
163
+ file ??= el.at?.file;
164
+ pos.push(el.at?.line ?? 0, el.at?.column ?? 0);
165
+ for (const child of el.children) if (child.kind === "element") walk(child);
166
+ };
167
+ walk(root);
168
+ return file && pos.some((n) => n !== 0) ? { file, pos } : void 0;
169
+ }
170
+
171
+ // src/codegen/partial-template.ts
172
+ var HOLE_START = "<!--fx-->";
173
+ var HOLE_END = "<!--fx/-->";
174
+ function isHole(node) {
175
+ return node.kind === "expr" || node.kind === "component" || node.kind === "control";
176
+ }
177
+ function isTemplateChild(node) {
178
+ return node.kind === "text" || node.kind === "element" && isTemplateElement(node);
179
+ }
180
+ function isTemplateElement(node) {
181
+ if (node.svg) return false;
182
+ if (isRawTextElement(node.tag)) return false;
183
+ if (!node.props.every((p) => isPlainLiteralAttr(p))) return false;
184
+ return node.children.every((c) => isTemplateChild(c) || isHole(c));
185
+ }
186
+ function containsHole(node) {
187
+ if (isHole(node)) return true;
188
+ const children = node.children;
189
+ return children ? children.some(containsHole) : false;
190
+ }
191
+ function addressable(el) {
192
+ for (let i = 0; i < el.children.length; i++) {
193
+ const child = el.children[i];
194
+ if (child.kind === "text") {
195
+ if (child.value === "") return false;
196
+ if (el.children[i + 1]?.kind === "text") return false;
197
+ }
198
+ }
199
+ return el.children.every((c) => c.kind !== "element" || addressable(c));
200
+ }
201
+ function planPartialTemplate(root) {
202
+ if (!isTemplateElement(root)) return null;
203
+ if (!addressable(root)) return null;
204
+ if (!root.children.some(containsHole)) return null;
205
+ const steps = [];
206
+ const holes = [];
207
+ let refCount = 0;
208
+ const declare = (expr) => {
209
+ const ref = `_n$${refCount++}`;
210
+ steps.push({ ref, expr });
211
+ return ref;
212
+ };
213
+ walk(root, "_el$");
214
+ return { html: serializeWithMarkers(root), tag: root.tag, steps, holes };
215
+ function walk(el, elementRef) {
216
+ let last = -1;
217
+ el.children.forEach((child, i) => {
218
+ if (containsHole(child)) last = i;
219
+ });
220
+ let previous = null;
221
+ for (let i = 0; i <= last; i++) {
222
+ const child = el.children[i];
223
+ const expr = previous ? `${previous}.nextSibling` : `${elementRef}.firstChild`;
224
+ if (isHole(child)) {
225
+ const startRef = declare(expr);
226
+ const endRef = declare(`holeEnd(${startRef})`);
227
+ holes.push({ parentRef: elementRef, startRef, endRef, node: child });
228
+ previous = endRef;
229
+ continue;
230
+ }
231
+ const ref = declare(expr);
232
+ if (child.kind === "element" && containsHole(child)) walk(child, ref);
233
+ previous = ref;
234
+ }
235
+ }
236
+ }
237
+ function serializeWithMarkers(el) {
238
+ return serializeStatic(withSentinels(el)).split(SENTINEL).join(HOLE_START + HOLE_END);
239
+ }
240
+ function withSentinels(el) {
241
+ return {
242
+ ...el,
243
+ children: el.children.map(
244
+ (child) => isHole(child) ? { kind: "text", value: SENTINEL } : child.kind === "element" ? withSentinels(child) : child
245
+ )
246
+ };
247
+ }
248
+ var SENTINEL = "\0fx-hole\0";
249
+
250
+ // src/codegen/contract.ts
251
+ var RUNTIME_CONTRACT_V1 = {
252
+ version: 1,
253
+ module: "@fluixi/dom",
254
+ symbols: [
255
+ "createNativeElement",
256
+ "insert",
257
+ "spread",
258
+ "setAttribute",
259
+ "delegateEvents",
260
+ "createComponent",
261
+ "createMemo",
262
+ "untrack",
263
+ "Show",
264
+ "For",
265
+ "Index",
266
+ "Switch",
267
+ "Match",
268
+ "Dynamic",
269
+ "ErrorBoundary"
270
+ ]
271
+ };
272
+ var RUNTIME_CONTRACT_V2 = {
273
+ version: 2,
274
+ module: "@fluixi/dom",
275
+ symbols: [...RUNTIME_CONTRACT_V1.symbols, "template", "cloneTemplate", "walk"]
276
+ };
277
+
278
+ // src/analyze/intrinsics.ts
279
+ var REACTIVE_MODULE = "@fluixi/reactive/signal";
280
+ var INTRINSICS = {
281
+ $signal: { export: "signal", module: REACTIVE_MODULE, returns: "signal-handle" },
282
+ $memo: { export: "memo", module: REACTIVE_MODULE, returns: "memo-handle" },
283
+ $effect: { export: "effect", module: REACTIVE_MODULE, returns: "effect" },
284
+ $store: { export: "store", module: "@fluixi/reactive/store", returns: "store-handle" },
285
+ $resource: { export: "resource", module: REACTIVE_MODULE, returns: "resource-handle" },
286
+ $cachedResource: { export: "cachedResource", module: "@fluixi/reactive/cached-resource", returns: "resource-handle" },
287
+ // No short runtime form for these yet, so the intrinsic stands for the `create*`
288
+ // name. Still worth having: no import to write, and when a shorter form is
289
+ // designed, the change is this line rather than a compiler pass.
290
+ $selector: { export: "createSelector", module: REACTIVE_MODULE, returns: "memo-accessor" },
291
+ $deferred: { export: "createDeferred", module: REACTIVE_MODULE, returns: "memo-accessor" },
292
+ // Not value constructors, but the compiler has to know them: they change what a read
293
+ // does. `untrack` suppresses dependency collection, which is exactly the kind of thing
294
+ // dependency analysis must not guess at.
295
+ $untrack: { export: "untrack", module: REACTIVE_MODULE, returns: "plain" },
296
+ $untrackStore: { export: "untrackStore", module: "@fluixi/reactive/store", returns: "plain" },
297
+ // Scopes, scheduling and lifecycle: no value to classify, but the same authoring promise,
298
+ // no import to write. `$cleanup` registers a callback on the current owner (`onCleanup`).
299
+ $batch: { export: "batch", module: REACTIVE_MODULE, returns: "plain" },
300
+ $cleanup: { export: "onCleanup", module: REACTIVE_MODULE, returns: "plain" },
301
+ $root: { export: "root", module: REACTIVE_MODULE, returns: "plain" },
302
+ $context: { export: "context", module: REACTIVE_MODULE, returns: "plain" },
303
+ $renderEffect: { export: "renderEffect", module: REACTIVE_MODULE, returns: "effect" },
304
+ $computed: { export: "computed", module: REACTIVE_MODULE, returns: "effect" },
305
+ // Storage for where the code runs, and a signal kept in it. `$persisted` is a signal
306
+ // handle as far as reads go: the same accessor with `set` on it.
307
+ $storage: { export: "useStorage", module: "@fluixi/core/storage", returns: "plain" },
308
+ $asyncStorage: { export: "useAsyncStorage", module: "@fluixi/core/storage", returns: "plain" },
309
+ $persisted: { export: "persisted", module: "@fluixi/core/storage", returns: "signal-handle" },
310
+ // An environment variable, public or server-only; the browser build refuses a secret.
311
+ $env: { export: "env", module: "@fluixi/start/env", returns: "plain" }
312
+ };
313
+ var INTRINSIC_CALL = new RegExp(`\\$(?:${Object.keys(INTRINSICS).map((n) => n.slice(1)).join("|")})\\s*\\(`);
314
+
315
+ // src/transform/source-locations.ts
316
+ var SOURCE_MARKER = "__fx_source";
317
+ var HOLE_MARKER = "__fx_hole";
318
+ var markHole = (accessor, line, column, name) => `(globalThis.${HOLE_MARKER} ?? ((f) => f))(${accessor},${line},${column}${name === void 0 ? "" : `,${JSON.stringify(name)}`})`;
319
+ var PROPS_MARKER = "__fx_props";
320
+ var markProps = (object, at) => `(globalThis.${PROPS_MARKER} ?? ((p) => p))(${object},${JSON.stringify(at)})`;
321
+
322
+ // src/analyze/paren.ts
323
+ function skipQuoted(src, start) {
324
+ const quote = src[start];
325
+ for (let i = start + 1; i < src.length; i++) {
326
+ const c = src[i];
327
+ if (c === "\\") i++;
328
+ else if (c === quote) return i + 1;
329
+ else if (c === "\n") return -1;
330
+ }
331
+ return -1;
332
+ }
333
+ function skipTemplate(src, start) {
334
+ let i = start + 1;
335
+ while (i < src.length) {
336
+ const c = src[i];
337
+ if (c === "\\") {
338
+ i += 2;
339
+ } else if (c === "`") {
340
+ return i + 1;
341
+ } else if (c === "$" && src[i + 1] === "{") {
342
+ let depth = 1;
343
+ i += 2;
344
+ while (i < src.length && depth > 0) {
345
+ const k = src[i];
346
+ if (k === "\\") i += 2;
347
+ else if (k === "`") {
348
+ const end = skipTemplate(src, i);
349
+ if (end < 0) return -1;
350
+ i = end;
351
+ } else if (k === '"' || k === "'") {
352
+ const end = skipQuoted(src, i);
353
+ if (end < 0) return -1;
354
+ i = end;
355
+ } else {
356
+ if (k === "{") depth++;
357
+ else if (k === "}") depth--;
358
+ i++;
359
+ }
360
+ }
361
+ } else {
362
+ i++;
363
+ }
364
+ }
365
+ return -1;
366
+ }
367
+ function skipRegex(src, start) {
368
+ let inClass = false;
369
+ for (let i = start + 1; i < src.length; i++) {
370
+ const c = src[i];
371
+ if (c === "\\") i++;
372
+ else if (c === "[") inClass = true;
373
+ else if (c === "]") inClass = false;
374
+ else if (c === "\n") return -1;
375
+ else if (c === "/" && !inClass) {
376
+ let end = i + 1;
377
+ while (end < src.length && /[a-z]/i.test(src[end])) end++;
378
+ return end;
379
+ }
380
+ }
381
+ return -1;
382
+ }
383
+ function divides(prev) {
384
+ return prev !== "" && /[A-Za-z0-9_$)\]]/.test(prev);
385
+ }
386
+ function topLevelComma(src) {
387
+ let depth = 0;
388
+ let prev = "";
389
+ let i = 0;
390
+ while (i < src.length) {
391
+ const c = src[i];
392
+ if (c === '"' || c === "'") {
393
+ const end = skipQuoted(src, i);
394
+ if (end < 0) return null;
395
+ i = end;
396
+ prev = c;
397
+ } else if (c === "`") {
398
+ const end = skipTemplate(src, i);
399
+ if (end < 0) return null;
400
+ i = end;
401
+ prev = c;
402
+ } else if (c === "/" && src[i + 1] === "/") {
403
+ return null;
404
+ } else if (c === "/" && src[i + 1] === "*") {
405
+ const end = src.indexOf("*/", i + 2);
406
+ if (end < 0) return null;
407
+ i = end + 2;
408
+ } else if (c === "/" && !divides(prev)) {
409
+ const end = skipRegex(src, i);
410
+ if (end < 0) return null;
411
+ i = end;
412
+ prev = "/";
413
+ } else {
414
+ if (c === "(" || c === "[" || c === "{") depth++;
415
+ else if (c === ")" || c === "]" || c === "}") {
416
+ depth--;
417
+ if (depth < 0) return null;
418
+ } else if (c === "," && depth === 0) return true;
419
+ if (!/\s/.test(c)) prev = c;
420
+ i++;
421
+ }
422
+ }
423
+ return depth === 0 ? false : null;
424
+ }
425
+ function paren(code, position) {
426
+ const src = code.trim();
427
+ if (src === "") return `(${code})`;
428
+ if (position === "arrowBody" && src[0] === "{") return `(${code})`;
429
+ return topLevelComma(src) === false ? code : `(${code})`;
430
+ }
431
+
432
+ // src/codegen/backends/imperative.ts
433
+ var CONTROL_COMPONENT = {
434
+ show: "Show",
435
+ for: "For",
436
+ index: "Index",
437
+ switch: "Switch",
438
+ match: "Match",
439
+ dynamic: "Dynamic",
440
+ errorBoundary: "ErrorBoundary",
441
+ suspense: "Suspense"
442
+ };
443
+ function isIdent(name) {
444
+ return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name);
445
+ }
446
+ function propKey(name) {
447
+ return isIdent(name) ? name : JSON.stringify(name);
448
+ }
449
+ function propValue(p) {
450
+ if (p.expr !== void 0) {
451
+ if (p.name === "ref" && p.at)
452
+ return markHole(paren(p.expr, "value"), p.at.line, p.at.column, p.expr);
453
+ if (!p.reactive) return paren(p.expr, "value");
454
+ const accessor = `() => ${paren(p.expr, "arrowBody")}`;
455
+ return p.at ? markHole(accessor, p.at.line, p.at.column, p.directive) : accessor;
456
+ }
457
+ return JSON.stringify(p.literal ?? true);
458
+ }
459
+ function componentPropValue(p) {
460
+ if (p.expr !== void 0) return paren(p.expr, "value");
461
+ return JSON.stringify(p.literal ?? true);
462
+ }
463
+ function emitProps(props, childrenExpr, used) {
464
+ const spreads = props.filter((p) => p.kind === "spread");
465
+ const normal = props.filter((p) => p.kind !== "spread");
466
+ const entries = normal.map((p) => `${propKey(p.name)}: ${propValue(p)}`);
467
+ if (childrenExpr != null) entries.push(`children: ${childrenExpr}`);
468
+ const obj = `{ ${entries.join(", ")} }`;
469
+ if (spreads.length > 0) {
470
+ used.add("mergeProps");
471
+ return `mergeProps(${spreads.map((s) => s.expr).join(", ")}, ${obj})`;
472
+ }
473
+ return obj;
474
+ }
475
+ function markBind(code, at) {
476
+ return at ? markHole(code, at.line, at.column) : code;
477
+ }
478
+ function emitChildren(children, used, templates) {
479
+ if (children.length === 1) return emitNode(children[0], used, templates);
480
+ let deferred = false;
481
+ const items = children.map((child) => {
482
+ const code = emitNode(child, used, templates);
483
+ if (child.kind === "element" && deferred) {
484
+ used.add("deferElement");
485
+ return `deferElement(() => ${paren(code, "arrowBody")})`;
486
+ }
487
+ if (child.kind === "component" || child.kind === "control" || child.kind === "expr" && child.reactive) deferred = true;
488
+ return code;
489
+ });
490
+ return `[${items.join(", ")}]`;
491
+ }
492
+ function emitComponent(name, props, children, used, templates, at) {
493
+ used.add("createMemo");
494
+ used.add("createComponent");
495
+ const spreads = props.filter((p) => p.kind === "spread");
496
+ const normal = props.filter((p) => p.kind !== "spread");
497
+ const bodies = normal.map((p) => [p.name, componentPropValue(p)]);
498
+ if (children.length > 0) {
499
+ bodies.push(["children", emitChildren(children, used, templates)]);
500
+ }
501
+ let obj = `{ ${bodies.map(([name2, body]) => `get ${propKey(name2)}() { return ${body}; }`).join(", ")} }`;
502
+ if (bodies.some(([, body]) => /\bthis\b/.test(body))) {
503
+ const thunks = bodies.map(([name2, body]) => `${JSON.stringify(name2)}: () => (${body})`);
504
+ const getters = bodies.map(([name2]) => `get ${propKey(name2)}() { return _$t[${JSON.stringify(name2)}](); }`);
505
+ obj = `((_$t) => ({ ${getters.join(", ")} }))({ ${thunks.join(", ")} })`;
506
+ }
507
+ if (spreads.length > 0) {
508
+ used.add("mergeProps");
509
+ obj = `mergeProps(${spreads.map((s) => s.expr).join(", ")}, ${obj})`;
510
+ }
511
+ const propAt = {};
512
+ for (const p of normal) if (p.at) propAt[p.name] = [p.at.line, p.at.column];
513
+ if (Object.keys(propAt).length) obj = markProps(obj, propAt);
514
+ const mark = at ? `globalThis.${SOURCE_MARKER}?.(${JSON.stringify(at.file)},${at.line},${at.column},${JSON.stringify(name)}), ` : "";
515
+ return `createMemo(${paren(`${mark}() => createComponent(${name}, ${obj})`, "value")})`;
516
+ }
517
+ function staticAttrAssignment(el, prop) {
518
+ const name = htmlAttrName(prop.name);
519
+ const value = prop.literal;
520
+ if (value === true || value === void 0) return `${el}.setAttribute(${JSON.stringify(name)}, "");`;
521
+ if (value === false || value === null) return "";
522
+ return `${el}.setAttribute(${JSON.stringify(name)}, ${JSON.stringify(String(value))});`;
523
+ }
524
+ var partial = false;
525
+ function emitNode(node, used, templates) {
526
+ switch (node.kind) {
527
+ case "text":
528
+ return JSON.stringify(node.value);
529
+ case "expr": {
530
+ if (!node.reactive) return paren(node.code, "value");
531
+ const accessor = `() => ${paren(node.code, "arrowBody")}`;
532
+ return node.at ? markHole(accessor, node.at.line, node.at.column) : accessor;
533
+ }
534
+ case "fragment":
535
+ if (node.children.length === 0) return "null";
536
+ return emitChildren(node.children, used, templates);
537
+ case "component":
538
+ return markBind(emitComponent(node.name, node.props, node.children, used, templates, node.at), node.bindAt ?? node.at);
539
+ case "control": {
540
+ const name = CONTROL_COMPONENT[node.control] ?? node.control;
541
+ used.add(name);
542
+ return markBind(emitComponent(name, node.props, node.children, used, templates), node.bindAt);
543
+ }
544
+ case "element": {
545
+ if (templates && node.static && !node.svg && isSerializable(node)) {
546
+ used.add("templateNode");
547
+ const id = `_tmpl$${templates.length}`;
548
+ templates.push({ id, html: serializeStatic(node), tag: node.tag, svg: false });
549
+ const at = templatePositions(node);
550
+ return at ? `templateNode(${id}, ${JSON.stringify(node.tag)}, false, false, ${JSON.stringify(at)})` : `templateNode(${id}, ${JSON.stringify(node.tag)})`;
551
+ }
552
+ if (templates && partial) {
553
+ const plan = planPartialTemplate(node);
554
+ if (plan) {
555
+ used.add("templateNode");
556
+ used.add("insert");
557
+ used.add("holeEnd");
558
+ used.add("holeContent");
559
+ used.add("holeScope");
560
+ const id = `_tmpl$${templates.length}`;
561
+ templates.push({ id, html: plan.html, tag: plan.tag, svg: false });
562
+ const at = templatePositions(node);
563
+ const lines = [
564
+ `const _el$ = templateNode(${id}, ${JSON.stringify(plan.tag)}, true${at ? `, false, ${JSON.stringify(at)}` : ""});`
565
+ ];
566
+ for (const step of plan.steps) lines.push(`const ${step.ref} = ${step.expr};`);
567
+ for (const hole of plan.holes) {
568
+ lines.push(
569
+ `insert(${hole.parentRef}, holeScope(${hole.startRef}, () => ${paren(emitNode(hole.node, used, templates), "arrowBody")}), ${hole.endRef}, holeContent(${hole.startRef}, ${hole.endRef}));`
570
+ );
571
+ }
572
+ lines.push("return _el$;");
573
+ return `(() => { ${lines.join(" ")} })()`;
574
+ }
575
+ }
576
+ used.add("createNativeElement");
577
+ const tag = JSON.stringify(node.tag);
578
+ const el = "_el$";
579
+ const parts = [];
580
+ const createArgs = node.at ? `${tag}, ${node.svg}, ${JSON.stringify(node.at)}` : node.svg ? `${tag}, true` : tag;
581
+ parts.push(`const ${el} = createNativeElement(${createArgs});`);
582
+ if (node.props.length > 0) {
583
+ if (!node.svg && node.props.every(isPlainLiteralAttr)) {
584
+ for (const p of node.props) parts.push(staticAttrAssignment(el, p));
585
+ } else {
586
+ used.add("spread");
587
+ const svgFlag = node.svg ? ", isSVG: true" : "";
588
+ const accessors = node.props.filter((p) => p.kind !== "spread" && p.expr !== void 0 && p.reactive && p.name !== "ref").map((p) => p.name);
589
+ const customFlag = node.tag.includes("-") ? `, isCustomElement: true, accessors: ${JSON.stringify(accessors)}` : "";
590
+ parts.push(
591
+ `spread({ element: ${el}, props: ${emitProps(node.props, null, used)}${svgFlag}${customFlag} });`
592
+ );
593
+ }
594
+ }
595
+ for (const child of node.children) {
596
+ used.add("insert");
597
+ const childCode = emitNode(child, used, templates);
598
+ const anchored = child.kind === "expr" && (child.reactive || !isLiteralCode(child.code)) || child.kind === "component" || child.kind === "control";
599
+ parts.push(anchored ? `insert(${el}, ${childCode}, null);` : `insert(${el}, ${childCode});`);
600
+ }
601
+ parts.push(`return ${el};`);
602
+ return `(() => { ${parts.join(" ")} })()`;
603
+ }
604
+ }
605
+ }
606
+ var LITERAL = /^\s*(?:'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`[^`$]*`|-?\d[\d_.eE+-]*|true|false|null|undefined)\s*$/;
607
+ var isLiteralCode = (code) => LITERAL.test(code);
608
+ function inlineTemplates(code, templates) {
609
+ if (!templates || templates.length === 0) return code;
610
+ const byId = new Map(templates.map((t) => [t.id, JSON.stringify(t.html)]));
611
+ return code.replace(/_tmpl\$\d+/g, (id) => byId.get(id) ?? id);
612
+ }
613
+ var imperativeBackend = {
614
+ name: "imperative",
615
+ contract: RUNTIME_CONTRACT_V1,
616
+ emit(node, options) {
617
+ const used = /* @__PURE__ */ new Set();
618
+ const templates = options?.templateClone !== false ? [] : void 0;
619
+ partial = options?.partialTemplates === true;
620
+ const code = emitNode(node, used, templates);
621
+ return { code, imports: Array.from(used), templates };
622
+ }
623
+ };
624
+
625
+ // src/lower/text.ts
626
+ function cleanTemplateText(value) {
627
+ const lines = value.split(/\r\n|\n|\r/);
628
+ let lastNonEmpty = 0;
629
+ for (let i = 0; i < lines.length; i++) {
630
+ if (/[^ \t]/.test(lines[i])) lastNonEmpty = i;
631
+ }
632
+ let out = "";
633
+ for (let i = 0; i < lines.length; i++) {
634
+ let line = lines[i].replace(/\t/g, " ");
635
+ if (i !== 0) line = line.replace(/^ +/, "");
636
+ if (i !== lines.length - 1) line = line.replace(/ +$/, "");
637
+ if (!line) continue;
638
+ if (i !== lastNonEmpty) line += " ";
639
+ out += line;
640
+ }
641
+ return out;
642
+ }
643
+
644
+ // src/lower/entities.ts
645
+ var NAMED = {
646
+ quot: 34,
647
+ amp: 38,
648
+ apos: 39,
649
+ lt: 60,
650
+ gt: 62,
651
+ nbsp: 160,
652
+ iexcl: 161,
653
+ cent: 162,
654
+ pound: 163,
655
+ curren: 164,
656
+ yen: 165,
657
+ brvbar: 166,
658
+ sect: 167,
659
+ uml: 168,
660
+ copy: 169,
661
+ ordf: 170,
662
+ laquo: 171,
663
+ not: 172,
664
+ shy: 173,
665
+ reg: 174,
666
+ macr: 175,
667
+ deg: 176,
668
+ plusmn: 177,
669
+ sup2: 178,
670
+ sup3: 179,
671
+ acute: 180,
672
+ micro: 181,
673
+ para: 182,
674
+ middot: 183,
675
+ cedil: 184,
676
+ sup1: 185,
677
+ ordm: 186,
678
+ raquo: 187,
679
+ frac14: 188,
680
+ frac12: 189,
681
+ frac34: 190,
682
+ iquest: 191,
683
+ Agrave: 192,
684
+ Aacute: 193,
685
+ Acirc: 194,
686
+ Atilde: 195,
687
+ Auml: 196,
688
+ Aring: 197,
689
+ AElig: 198,
690
+ Ccedil: 199,
691
+ Egrave: 200,
692
+ Eacute: 201,
693
+ Ecirc: 202,
694
+ Euml: 203,
695
+ Igrave: 204,
696
+ Iacute: 205,
697
+ Icirc: 206,
698
+ Iuml: 207,
699
+ ETH: 208,
700
+ Ntilde: 209,
701
+ Ograve: 210,
702
+ Oacute: 211,
703
+ Ocirc: 212,
704
+ Otilde: 213,
705
+ Ouml: 214,
706
+ times: 215,
707
+ Oslash: 216,
708
+ Ugrave: 217,
709
+ Uacute: 218,
710
+ Ucirc: 219,
711
+ Uuml: 220,
712
+ Yacute: 221,
713
+ THORN: 222,
714
+ szlig: 223,
715
+ agrave: 224,
716
+ aacute: 225,
717
+ acirc: 226,
718
+ atilde: 227,
719
+ auml: 228,
720
+ aring: 229,
721
+ aelig: 230,
722
+ ccedil: 231,
723
+ egrave: 232,
724
+ eacute: 233,
725
+ ecirc: 234,
726
+ euml: 235,
727
+ igrave: 236,
728
+ iacute: 237,
729
+ icirc: 238,
730
+ iuml: 239,
731
+ eth: 240,
732
+ ntilde: 241,
733
+ ograve: 242,
734
+ oacute: 243,
735
+ ocirc: 244,
736
+ otilde: 245,
737
+ ouml: 246,
738
+ divide: 247,
739
+ oslash: 248,
740
+ ugrave: 249,
741
+ uacute: 250,
742
+ ucirc: 251,
743
+ uuml: 252,
744
+ yacute: 253,
745
+ thorn: 254,
746
+ yuml: 255,
747
+ OElig: 338,
748
+ oelig: 339,
749
+ Scaron: 352,
750
+ scaron: 353,
751
+ Yuml: 376,
752
+ fnof: 402,
753
+ circ: 710,
754
+ tilde: 732,
755
+ Alpha: 913,
756
+ Beta: 914,
757
+ Gamma: 915,
758
+ Delta: 916,
759
+ Epsilon: 917,
760
+ Zeta: 918,
761
+ Eta: 919,
762
+ Theta: 920,
763
+ Iota: 921,
764
+ Kappa: 922,
765
+ Lambda: 923,
766
+ Mu: 924,
767
+ Nu: 925,
768
+ Xi: 926,
769
+ Omicron: 927,
770
+ Pi: 928,
771
+ Rho: 929,
772
+ Sigma: 931,
773
+ Tau: 932,
774
+ Upsilon: 933,
775
+ Phi: 934,
776
+ Chi: 935,
777
+ Psi: 936,
778
+ Omega: 937,
779
+ alpha: 945,
780
+ beta: 946,
781
+ gamma: 947,
782
+ delta: 948,
783
+ epsilon: 949,
784
+ zeta: 950,
785
+ eta: 951,
786
+ theta: 952,
787
+ iota: 953,
788
+ kappa: 954,
789
+ lambda: 955,
790
+ mu: 956,
791
+ nu: 957,
792
+ xi: 958,
793
+ omicron: 959,
794
+ pi: 960,
795
+ rho: 961,
796
+ sigmaf: 962,
797
+ sigma: 963,
798
+ tau: 964,
799
+ upsilon: 965,
800
+ phi: 966,
801
+ chi: 967,
802
+ psi: 968,
803
+ omega: 969,
804
+ thetasym: 977,
805
+ upsih: 978,
806
+ piv: 982,
807
+ ensp: 8194,
808
+ emsp: 8195,
809
+ thinsp: 8201,
810
+ zwnj: 8204,
811
+ zwj: 8205,
812
+ lrm: 8206,
813
+ rlm: 8207,
814
+ ndash: 8211,
815
+ mdash: 8212,
816
+ lsquo: 8216,
817
+ rsquo: 8217,
818
+ sbquo: 8218,
819
+ ldquo: 8220,
820
+ rdquo: 8221,
821
+ bdquo: 8222,
822
+ dagger: 8224,
823
+ Dagger: 8225,
824
+ bull: 8226,
825
+ hellip: 8230,
826
+ permil: 8240,
827
+ prime: 8242,
828
+ Prime: 8243,
829
+ lsaquo: 8249,
830
+ rsaquo: 8250,
831
+ oline: 8254,
832
+ frasl: 8260,
833
+ euro: 8364,
834
+ image: 8465,
835
+ weierp: 8472,
836
+ real: 8476,
837
+ trade: 8482,
838
+ alefsym: 8501,
839
+ larr: 8592,
840
+ uarr: 8593,
841
+ rarr: 8594,
842
+ darr: 8595,
843
+ harr: 8596,
844
+ crarr: 8629,
845
+ lArr: 8656,
846
+ uArr: 8657,
847
+ rArr: 8658,
848
+ dArr: 8659,
849
+ hArr: 8660,
850
+ forall: 8704,
851
+ part: 8706,
852
+ exist: 8707,
853
+ empty: 8709,
854
+ nabla: 8711,
855
+ isin: 8712,
856
+ notin: 8713,
857
+ ni: 8715,
858
+ prod: 8719,
859
+ sum: 8721,
860
+ minus: 8722,
861
+ lowast: 8727,
862
+ radic: 8730,
863
+ prop: 8733,
864
+ infin: 8734,
865
+ ang: 8736,
866
+ and: 8743,
867
+ or: 8744,
868
+ cap: 8745,
869
+ cup: 8746,
870
+ int: 8747,
871
+ there4: 8756,
872
+ sim: 8764,
873
+ cong: 8773,
874
+ asymp: 8776,
875
+ ne: 8800,
876
+ equiv: 8801,
877
+ le: 8804,
878
+ ge: 8805,
879
+ sub: 8834,
880
+ sup: 8835,
881
+ nsub: 8836,
882
+ sube: 8838,
883
+ supe: 8839,
884
+ oplus: 8853,
885
+ otimes: 8855,
886
+ perp: 8869,
887
+ sdot: 8901,
888
+ lceil: 8968,
889
+ rceil: 8969,
890
+ lfloor: 8970,
891
+ rfloor: 8971,
892
+ lang: 9001,
893
+ rang: 9002,
894
+ loz: 9674,
895
+ spades: 9824,
896
+ clubs: 9827,
897
+ hearts: 9829,
898
+ diams: 9830
899
+ };
900
+ var REFERENCE = /&(?:#[xX]([0-9a-fA-F]{1,6})|#([0-9]{1,7})|([a-zA-Z][a-zA-Z0-9]{1,31}));/g;
901
+ function decodeEntities(value) {
902
+ if (!value.includes("&")) return value;
903
+ return value.replace(REFERENCE, (match, hex, dec, name) => {
904
+ const code = hex ? parseInt(hex, 16) : dec ? parseInt(dec, 10) : Object.prototype.hasOwnProperty.call(NAMED, name) ? NAMED[name] : void 0;
905
+ return code !== void 0 && code <= 1114111 ? String.fromCodePoint(code) : match;
906
+ });
907
+ }
908
+
909
+ // src/lower/template.ts
910
+ var DELEGATED = /* @__PURE__ */ new Set([
911
+ "click",
912
+ "dblclick",
913
+ "input",
914
+ "change",
915
+ "submit",
916
+ "focus",
917
+ "blur",
918
+ "keydown",
919
+ "keyup",
920
+ "keypress",
921
+ "mousedown",
922
+ "mouseup"
923
+ ]);
924
+ function escapeTemplate(s) {
925
+ return s.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
926
+ }
927
+ var CONTAINER = "container";
928
+ function capitalize(s) {
929
+ return s.charAt(0).toUpperCase() + s.slice(1);
930
+ }
931
+ var Lowerer = class {
932
+ constructor(holes, used, sourceFile, positionAt) {
933
+ this.holes = holes;
934
+ this.used = used;
935
+ this.sourceFile = sourceFile;
936
+ this.positionAt = positionAt;
937
+ }
938
+ /**
939
+ * Where a tag is written, for the mark a component node carries.
940
+ *
941
+ * The parser reports offsets, and they are offsets into the file: the pieces it was given
942
+ * carry the positions the front-end recorded. Only built when the host asked for source
943
+ * locations, which is the only time either of these is set.
944
+ */
945
+ tagAt(node) {
946
+ const start = node.loc?.start;
947
+ if (!this.sourceFile || !this.positionAt || start == null) return void 0;
948
+ const { line, column } = this.positionAt(start);
949
+ return { file: this.sourceFile, line, column };
950
+ }
951
+ hole(i) {
952
+ return this.holes[i] ?? { code: "undefined", reactive: false };
953
+ }
954
+ /** Emit a nested IR subtree to code (for `Show` fallback / `For` children). */
955
+ emit(node) {
956
+ const { code, imports, templates } = imperativeBackend.emit(node, {});
957
+ for (const s of imports) this.used.add(s);
958
+ return inlineTemplates(code, templates);
959
+ }
960
+ // --- content ------------------------------------------------------------
961
+ lowerRoot(children) {
962
+ const nodes = this.lowerChildren(children);
963
+ if (nodes.length === 1) return nodes[0];
964
+ return { kind: "fragment", children: nodes };
965
+ }
966
+ /** Lower a sibling list, handling text-drop and if/else/each restructuring. */
967
+ lowerChildren(children) {
968
+ const out = [];
969
+ for (let i = 0; i < children.length; i++) {
970
+ const child = children[i];
971
+ if (child.kind === "Element" || child.kind === "Component") {
972
+ const ifDir = child.attributes.find((a) => a.kind === "IfDirective");
973
+ if (ifDir && ifDir.kind === "IfDirective") {
974
+ let elseIdx = i + 1;
975
+ if (elseIdx < children.length && this.isBlankText(children[elseIdx])) elseIdx++;
976
+ const elseNode = children[elseIdx];
977
+ const hasElse = elseNode && (elseNode.kind === "Element" || elseNode.kind === "Component") && elseNode.attributes.some((a) => a.kind === "ElseDirective");
978
+ out.push(this.lowerIf(child, ifDir.hole, hasElse ? elseNode : null));
979
+ if (hasElse) i = elseIdx;
980
+ continue;
981
+ }
982
+ }
983
+ const node = this.lowerNode(child);
984
+ if (node) out.push(node);
985
+ }
986
+ return out;
987
+ }
988
+ isBlankText(n) {
989
+ return n.kind === "Text" && !n.raw && cleanTemplateText(n.value) === "";
990
+ }
991
+ lowerNode(node) {
992
+ switch (node.kind) {
993
+ case "Text": {
994
+ if (node.raw) return { kind: "text", value: node.value };
995
+ const cleaned = decodeEntities(cleanTemplateText(node.value));
996
+ return cleaned ? { kind: "text", value: cleaned } : null;
997
+ }
998
+ case "Comment":
999
+ return null;
1000
+ // dropped, like JSX comments
1001
+ case "Expression": {
1002
+ const h = this.hole(node.hole);
1003
+ return { kind: "expr", code: h.code, reactive: h.reactive, ...h.at ? { at: h.at } : {} };
1004
+ }
1005
+ case "Fragment":
1006
+ return { kind: "fragment", children: this.lowerChildren(node.children) };
1007
+ case "Element":
1008
+ return this.lowerElement(node);
1009
+ case "Component":
1010
+ return this.lowerComponent(node);
1011
+ default:
1012
+ return null;
1013
+ }
1014
+ }
1015
+ lowerElement(el) {
1016
+ const isAttr = el.attributes.find((a) => a.kind === "Attribute" && a.name === "is");
1017
+ if (el.tag === "component" && isAttr && isAttr.value && isAttr.value.kind === "hole") {
1018
+ const rest = el.attributes.filter((a) => a !== isAttr);
1019
+ const node = this.lowerComponent({ ...el, kind: "Component", tag: "Dynamic", tagHole: null, attributes: rest });
1020
+ node.props.unshift({ name: "component", kind: "attr", expr: `() => ${paren(this.hole(isAttr.value.hole).code, "arrowBody")}` });
1021
+ return node;
1022
+ }
1023
+ const each = this.lowerEach(el);
1024
+ const children = each ? [each] : this.lowerChildren(el.children);
1025
+ if (el.tag === CONTAINER) return children.length === 1 ? children[0] : { kind: "fragment", children };
1026
+ const at = this.tagAt(el);
1027
+ return {
1028
+ kind: "element",
1029
+ tag: el.tag,
1030
+ svg: el.namespace === "svg",
1031
+ props: this.lowerAttributes(el.attributes, true),
1032
+ children,
1033
+ static: false,
1034
+ ...at ? { at } : {}
1035
+ };
1036
+ }
1037
+ lowerComponent(el) {
1038
+ const name = el.tagHole != null ? this.hole(el.tagHole).code : el.tag;
1039
+ const props = this.lowerAttributes(el.attributes);
1040
+ const { slots, rest } = this.partitionSlots(el.children);
1041
+ for (const [slotName, nodes] of slots) {
1042
+ const ir = nodes.length === 1 ? nodes[0] : { kind: "fragment", children: nodes };
1043
+ const slotProp = {
1044
+ name: slotName,
1045
+ kind: "attr",
1046
+ expr: this.emit(ir),
1047
+ jsxElement: true
1048
+ };
1049
+ const clash = props.findIndex((p) => p.name === slotName);
1050
+ if (clash >= 0) props[clash] = slotProp;
1051
+ else props.push(slotProp);
1052
+ }
1053
+ const loadAttr = el.attributes.find((a) => a.kind === "LoadDirective");
1054
+ const load = loadAttr ? parseLoadDirective(`load:${loadAttr.strategy}`, loadAttr.modifier) : void 0;
1055
+ const bindAt = props.find((p) => p.at && p.reactive)?.at;
1056
+ const at = this.tagAt(el);
1057
+ return {
1058
+ kind: "component",
1059
+ name,
1060
+ props,
1061
+ children: this.lowerChildren(rest),
1062
+ ...at ? { at } : {},
1063
+ ...bindAt ? { bindAt } : {},
1064
+ ...load ? { load } : {}
1065
+ };
1066
+ }
1067
+ /** Split a component's children into named slots (`slot="x"`) and the rest. */
1068
+ partitionSlots(children) {
1069
+ const slots = /* @__PURE__ */ new Map();
1070
+ const rest = [];
1071
+ for (const child of children) {
1072
+ if (child.kind === "Element" || child.kind === "Component") {
1073
+ const slot = child.attributes.find(
1074
+ (a) => a.kind === "Attribute" && a.name === "slot"
1075
+ );
1076
+ if (slot && slot.value && slot.value.kind === "static") {
1077
+ const stripped = { ...child, attributes: child.attributes.filter((a) => a !== slot) };
1078
+ const ir = stripped.kind === "Element" ? this.lowerElement(stripped) : this.lowerComponent(stripped);
1079
+ const bucket = slots.get(slot.value.value) ?? [];
1080
+ bucket.push(ir);
1081
+ slots.set(slot.value.value, bucket);
1082
+ continue;
1083
+ }
1084
+ }
1085
+ rest.push(child);
1086
+ }
1087
+ return { slots, rest };
1088
+ }
1089
+ // --- control-flow sugar -------------------------------------------------
1090
+ /** `<el if=${cond}>…</el>` (+ optional `<el else>`) → `<Show when fallback>`. */
1091
+ lowerIf(el, condHole, elseEl) {
1092
+ const cond = this.hole(condHole);
1093
+ const props = [
1094
+ { name: "when", kind: "attr", expr: cond.code, reactive: cond.reactive, ...cond.at ? { at: cond.at } : {} }
1095
+ ];
1096
+ if (elseEl) {
1097
+ const elseIR = this.stripAndLower(elseEl, (a) => a.kind === "ElseDirective");
1098
+ props.push({ name: "fallback", kind: "attr", expr: this.emit(elseIR), jsxElement: true });
1099
+ }
1100
+ const child = this.stripAndLower(el, (a) => a.kind === "IfDirective");
1101
+ const at = this.tagAt(el);
1102
+ return { kind: "component", name: "Show", props, children: [child], ...at ? { at } : {}, ...cond.at ? { bindAt: cond.at } : {} };
1103
+ }
1104
+ /**
1105
+ * `<el each=${items} key?>${item => …}</el>` → `<el><For each>{item => …}</For></el>`: the
1106
+ * content is repeated per item. Content that is not a `${item => …}` arrow is repeated as
1107
+ * it is. Null when the element has no `each`.
1108
+ */
1109
+ lowerEach(el) {
1110
+ const eachDir = el.attributes.find((a) => a.kind === "EachDirective");
1111
+ if (!eachDir || eachDir.kind !== "EachDirective") return null;
1112
+ const each = this.hole(eachDir.hole);
1113
+ const props = [{ name: "each", kind: "attr", expr: each.code, reactive: each.reactive, ...each.at ? { at: each.at } : {} }];
1114
+ if (eachDir.key) {
1115
+ const by = "static" in eachDir.key ? `(item) => item[${JSON.stringify(eachDir.key.static)}]` : this.hole(eachDir.key.hole).code;
1116
+ props.push({ name: "by", kind: "attr", expr: by });
1117
+ }
1118
+ const arrow = this.itemArrow(el);
1119
+ let childrenCode;
1120
+ if (arrow) {
1121
+ const body = arrow.bodyReactive ? `() => ${paren(arrow.body, "arrowBody")}` : paren(arrow.body, "arrowBody");
1122
+ childrenCode = `(${arrow.params.join(", ")}) => ${body}`;
1123
+ } else {
1124
+ const content = this.lowerChildren(el.children);
1125
+ const ir = content.length === 1 ? content[0] : { kind: "fragment", children: content };
1126
+ childrenCode = `() => ${paren(this.emit(ir), "arrowBody")}`;
1127
+ }
1128
+ const children = [{ kind: "expr", code: childrenCode, reactive: false }];
1129
+ const at = this.tagAt(el);
1130
+ return { kind: "component", name: "For", props, children, ...at ? { at } : {}, ...each.at ? { bindAt: each.at } : {} };
1131
+ }
1132
+ /** The single `${item => expr}` child arrow, if that's the element's content. */
1133
+ itemArrow(el) {
1134
+ const kids = el.children.filter((c) => !this.isBlankText(c));
1135
+ if (kids.length !== 1 || kids[0].kind !== "Expression") return null;
1136
+ return this.hole(kids[0].hole).arrow ?? null;
1137
+ }
1138
+ /** Lower an element to IR, dropping the directive attribute matched by `drop`. */
1139
+ stripAndLower(el, drop) {
1140
+ const clone = { ...el, attributes: el.attributes.filter((a) => !drop(a)) };
1141
+ return clone.kind === "Element" ? this.lowerElement(clone) : this.lowerComponent(clone);
1142
+ }
1143
+ // --- attributes ---------------------------------------------------------
1144
+ /**
1145
+ * `element`: a DOM element, where each class:/style: value that moves is its own accessor.
1146
+ * A component gets the object as before, rebuilt whole when any value moves.
1147
+ */
1148
+ lowerAttributes(attrs, element = false) {
1149
+ let anyReactive = false;
1150
+ const entry = (name, h) => {
1151
+ anyReactive ||= h.reactive;
1152
+ if (!element || !h.reactive) return `${JSON.stringify(name)}: ${h.code}`;
1153
+ const accessor = `() => ${paren(h.code, "arrowBody")}`;
1154
+ return `${JSON.stringify(name)}: ${h.at ? markHole(accessor, h.at.line, h.at.column) : accessor}`;
1155
+ };
1156
+ const props = [];
1157
+ const classEntries = [];
1158
+ let classAt;
1159
+ const styleEntries = [];
1160
+ let styleAt;
1161
+ const usePairs = [];
1162
+ for (const a of attrs) {
1163
+ switch (a.kind) {
1164
+ case "IfDirective":
1165
+ case "EachDirective":
1166
+ case "ElseDirective":
1167
+ break;
1168
+ // handled as control-flow at the parent level
1169
+ case "Attribute":
1170
+ props.push(this.plainAttr(a));
1171
+ break;
1172
+ case "PropertyBinding":
1173
+ props.push({
1174
+ name: a.name,
1175
+ kind: "prop",
1176
+ expr: this.hole(a.hole).code,
1177
+ reactive: this.hole(a.hole).reactive,
1178
+ ...this.hole(a.hole).at ? { at: this.hole(a.hole).at } : {}
1179
+ });
1180
+ break;
1181
+ case "EventBinding":
1182
+ props.push(this.eventProp(a));
1183
+ break;
1184
+ case "RefBinding":
1185
+ props.push({
1186
+ name: "ref",
1187
+ kind: "ref",
1188
+ expr: this.hole(a.hole).code,
1189
+ reactive: this.hole(a.hole).reactive,
1190
+ // Which variable ends up holding the element, and where it was written.
1191
+ ...this.hole(a.hole).at ? { at: this.hole(a.hole).at } : {}
1192
+ });
1193
+ break;
1194
+ case "Spread":
1195
+ props.push({ name: "", kind: "spread", expr: this.hole(a.hole).code });
1196
+ break;
1197
+ case "ClassDirective": {
1198
+ const h = this.hole(a.hole);
1199
+ classEntries.push(entry(a.name, h));
1200
+ classAt ??= h.at;
1201
+ break;
1202
+ }
1203
+ case "StyleDirective": {
1204
+ const h = this.hole(a.hole);
1205
+ styleEntries.push(entry(a.name, h));
1206
+ styleAt ??= h.at;
1207
+ break;
1208
+ }
1209
+ case "BindDirective":
1210
+ props.push(...this.bindProps(a.name, this.hole(a.hole)));
1211
+ break;
1212
+ case "UseDirective": {
1213
+ const dir = a.name ?? (a.hole != null ? this.hole(a.hole).code : null);
1214
+ if (!dir) break;
1215
+ usePairs.push(a.name != null && a.hole != null ? `[${dir}, () => ${paren(this.hole(a.hole).code, "arrowBody")}]` : `[${dir}]`);
1216
+ break;
1217
+ }
1218
+ }
1219
+ }
1220
+ if (classEntries.length > 0) {
1221
+ props.push({
1222
+ name: "classList",
1223
+ kind: "attr",
1224
+ expr: `{ ${classEntries.join(", ")} }`,
1225
+ reactive: !element && anyReactive,
1226
+ ...classAt ? { at: classAt } : {}
1227
+ });
1228
+ }
1229
+ if (styleEntries.length > 0) {
1230
+ const entries = `{ ${styleEntries.join(", ")} }`;
1231
+ const base = props.findIndex((p) => p.name === "style");
1232
+ if (base === -1) props.push({ name: "style", kind: "attr", expr: entries, reactive: !element && anyReactive, ...styleAt ? { at: styleAt } : {} });
1233
+ else {
1234
+ const prop = props[base];
1235
+ const value = prop.expr === void 0 ? JSON.stringify(prop.literal) : prop.reactive ? `() => ${paren(prop.expr, "arrowBody")}` : prop.expr;
1236
+ props[base] = { name: "style", kind: "attr", expr: `[${value}, ${entries}]`, reactive: false, ...prop.at ? { at: prop.at } : {} };
1237
+ }
1238
+ }
1239
+ if (usePairs.length > 0) {
1240
+ props.push({ name: "use", kind: "attr", expr: `[${usePairs.join(", ")}]` });
1241
+ }
1242
+ return props;
1243
+ }
1244
+ /**
1245
+ * Lower an event binding. Plain `@click`/`onClick` (no modifiers) stays a
1246
+ * DELEGATED handler (unchanged, byte-identical with JSX). `on:click` or any
1247
+ * modifier (`.capture`/`.once`/`.passive`/`.prevent`/`.stop`/`.self`) emits a
1248
+ * NATIVE `on:name` prop the runtime attaches via addEventListener.
1249
+ */
1250
+ eventProp(a) {
1251
+ const dom = a.name.toLowerCase();
1252
+ const handler = this.hole(a.hole).code;
1253
+ const native = a.syntax === "colon" || a.modifiers.length > 0;
1254
+ if (!native) {
1255
+ return {
1256
+ name: "on" + capitalize(a.name),
1257
+ kind: "event",
1258
+ event: { name: dom, delegated: DELEGATED.has(dom) },
1259
+ expr: handler
1260
+ };
1261
+ }
1262
+ const wrapped = this.wrapHandler(handler, a.modifiers);
1263
+ const options = this.eventOptions(a.modifiers);
1264
+ const value = options ? `[${wrapped}, ${options}]` : wrapped;
1265
+ return { name: "on:" + dom, kind: "attr", expr: value };
1266
+ }
1267
+ /** Wrap a handler for `.prevent`/`.stop`/`.self` (no wrap when none apply). */
1268
+ wrapHandler(handler, mods) {
1269
+ const guard = mods.includes("self") ? "if (e.target !== e.currentTarget) return; " : "";
1270
+ const pre = [];
1271
+ if (mods.includes("prevent")) pre.push("e.preventDefault();");
1272
+ if (mods.includes("stop")) pre.push("e.stopPropagation();");
1273
+ if (!guard && pre.length === 0) return handler;
1274
+ return `(e) => { ${guard}${pre.join(" ")} return (${handler})(e); }`;
1275
+ }
1276
+ /** addEventListener options object from `.capture`/`.once`/`.passive`, or null. */
1277
+ eventOptions(mods) {
1278
+ const opts = [];
1279
+ if (mods.includes("capture")) opts.push("capture: true");
1280
+ if (mods.includes("once")) opts.push("once: true");
1281
+ if (mods.includes("passive")) opts.push("passive: true");
1282
+ return opts.length ? `{ ${opts.join(", ")} }` : null;
1283
+ }
1284
+ /** `bind:value=${sig}` → `value={read()}` + `onInput={e => write(e…value)}`. */
1285
+ bindProps(prop, h) {
1286
+ const sigCode = h.code;
1287
+ const checked = prop === "checked";
1288
+ const evt = checked ? "change" : "input";
1289
+ const accessor = checked ? "checked" : "value";
1290
+ this.used.add("bindPair");
1291
+ const sig = `bindPair(${sigCode})`;
1292
+ return [
1293
+ {
1294
+ name: prop,
1295
+ kind: "attr",
1296
+ expr: `${sig}[0]()`,
1297
+ reactive: true,
1298
+ directive: `bind:${prop}`,
1299
+ ...h.at ? { at: h.at } : {}
1300
+ },
1301
+ {
1302
+ name: "on" + capitalize(evt),
1303
+ kind: "event",
1304
+ event: { name: evt, delegated: DELEGATED.has(evt) },
1305
+ // delegated handler: `target` is the bound element (currentTarget is the root)
1306
+ expr: `(e) => ${sig}[1](e.target.${accessor})`
1307
+ }
1308
+ ];
1309
+ }
1310
+ /** A plain attribute (incl. lit `?bool`, mixed values), old `mkProp` behavior. */
1311
+ plainAttr(a) {
1312
+ const v = a.value;
1313
+ let name = a.name;
1314
+ if (a.name === "class") {
1315
+ name = v && v.kind === "hole" && this.hole(v.hole).object ? "classList" : "className";
1316
+ } else if (a.name === "html") {
1317
+ name = "innerHTML";
1318
+ }
1319
+ const kind = "attr";
1320
+ const base = { name, kind };
1321
+ if (v == null) {
1322
+ base.literal = true;
1323
+ return base;
1324
+ }
1325
+ if (v.kind === "static") {
1326
+ base.literal = decodeEntities(v.value);
1327
+ return base;
1328
+ }
1329
+ if (v.kind === "hole") {
1330
+ const h = this.hole(v.hole);
1331
+ base.expr = h.code;
1332
+ base.reactive = h.reactive;
1333
+ if (h.at) base.at = h.at;
1334
+ return base;
1335
+ }
1336
+ let reactive = false;
1337
+ let at;
1338
+ const body = v.parts.map((p) => {
1339
+ if ("text" in p) return escapeTemplate(decodeEntities(p.text));
1340
+ const h = this.hole(p.hole);
1341
+ reactive = reactive || h.reactive;
1342
+ at ??= h.at;
1343
+ return "${" + h.code + "}";
1344
+ }).join("");
1345
+ base.expr = "`" + body + "`";
1346
+ base.reactive = reactive;
1347
+ if (at) base.at = at;
1348
+ return base;
1349
+ }
1350
+ };
1351
+ function lowerTemplate(pieces, holes, used, opts = {}) {
1352
+ const { root } = (0, import_template_parser.parseTemplate)(pieces, { svg: opts.svg });
1353
+ return new Lowerer(holes, used, opts.sourceFile, opts.positionAt).lowerRoot(root.children);
1354
+ }