@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,1101 @@
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/jsx.ts
21
+ var jsx_exports = {};
22
+ __export(jsx_exports, {
23
+ SVG_TAGS: () => SVG_TAGS,
24
+ buildJsxIR: () => buildJsxIR
25
+ });
26
+ module.exports = __toCommonJS(jsx_exports);
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 isLoadDirective(name) {
35
+ return name.startsWith("load:");
36
+ }
37
+ function parseLoadDirective(name, value) {
38
+ const strategy = name.slice("load:".length);
39
+ if (!STRATEGIES.has(strategy)) {
40
+ throw new LoadDirectiveError(
41
+ `Unknown load strategy 'load:${strategy}'. Expected one of ${[...STRATEGIES].join(", ")}.`
42
+ );
43
+ }
44
+ switch (strategy) {
45
+ case "eager":
46
+ return EAGER;
47
+ case "idle":
48
+ return { kind: "idle" };
49
+ case "never":
50
+ return { kind: "never" };
51
+ case "visible":
52
+ return value ? { kind: "visible", rootMargin: value } : { kind: "visible" };
53
+ case "interaction":
54
+ return {
55
+ kind: "interaction",
56
+ events: value ? splitEvents(value) : [...DEFAULT_INTERACTION_EVENTS]
57
+ };
58
+ case "media":
59
+ if (!value) {
60
+ throw new LoadDirectiveError(
61
+ `'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`
62
+ );
63
+ }
64
+ return { kind: "media", query: value };
65
+ default:
66
+ throw new LoadDirectiveError(`Unhandled load strategy '${strategy}'.`);
67
+ }
68
+ }
69
+ function splitEvents(value) {
70
+ const events = value.split(/[\s,]+/).map((e) => e.trim()).filter(Boolean);
71
+ if (events.length === 0) {
72
+ throw new LoadDirectiveError(`'load:interaction' was given no event names.`);
73
+ }
74
+ return events;
75
+ }
76
+
77
+ // src/analyze/reactive-expr.ts
78
+ var STABLE_MEMBER = "children";
79
+ function isReactiveShape(shape) {
80
+ switch (shape.kind) {
81
+ case "call":
82
+ return true;
83
+ case "member":
84
+ return shape.property !== STABLE_MEMBER;
85
+ case "compound":
86
+ return shape.parts.some(isReactiveShape);
87
+ case "opaque":
88
+ return false;
89
+ }
90
+ }
91
+
92
+ // src/analyze/expr-shape.ts
93
+ var CALL = /* @__PURE__ */ new Set(["CallExpression", "OptionalCallExpression"]);
94
+ var MEMBER = /* @__PURE__ */ new Set(["MemberExpression", "OptionalMemberExpression"]);
95
+ function shapeOf(node) {
96
+ if (!node) return { kind: "opaque" };
97
+ if (CALL.has(node.type)) return { kind: "call" };
98
+ if (MEMBER.has(node.type)) {
99
+ const property = node.property;
100
+ const computed = node.computed === true;
101
+ return {
102
+ kind: "member",
103
+ property: !computed && property?.type === "Identifier" ? property.name : null
104
+ };
105
+ }
106
+ if (node.type === "ConditionalExpression") {
107
+ return { kind: "compound", parts: [node.test, node.consequent, node.alternate].map(part) };
108
+ }
109
+ if (node.type === "LogicalExpression" || node.type === "BinaryExpression") {
110
+ return { kind: "compound", parts: [node.left, node.right].map(part) };
111
+ }
112
+ if (node.type === "TemplateLiteral") {
113
+ return { kind: "compound", parts: node.expressions.map(part) };
114
+ }
115
+ if (node.type === "ObjectExpression") {
116
+ const props = node.properties.filter(
117
+ (p) => (p.type === "ObjectProperty" || p.type === "Property") && p.computed !== true
118
+ );
119
+ return { kind: "compound", parts: props.map((p) => part(p.value)) };
120
+ }
121
+ if (node.type === "ArrayExpression") {
122
+ const items = node.elements.filter(
123
+ (e) => e != null && e.type !== "SpreadElement"
124
+ );
125
+ return { kind: "compound", parts: items.map(part) };
126
+ }
127
+ return { kind: "opaque" };
128
+ }
129
+ var part = (n) => shapeOf(n);
130
+
131
+ // src/optimize/analyze-static.ts
132
+ function propReason(prop) {
133
+ switch (prop.kind) {
134
+ case "event":
135
+ return "event";
136
+ case "ref":
137
+ return "ref";
138
+ case "spread":
139
+ return "spread";
140
+ case "class":
141
+ case "style":
142
+ return "class-or-style-directive";
143
+ case "attr":
144
+ case "prop":
145
+ if (prop.reactive) return "reactive-prop";
146
+ if (prop.expr !== void 0) return "expression-prop";
147
+ return void 0;
148
+ /* c8 ignore next 2 */
149
+ default:
150
+ return "expression-prop";
151
+ }
152
+ }
153
+ function analyzeStatic(root) {
154
+ const staticElements = [];
155
+ const reasons = /* @__PURE__ */ new Map();
156
+ const visit = (node) => {
157
+ switch (node.kind) {
158
+ case "text":
159
+ return true;
160
+ case "expr":
161
+ return false;
162
+ case "component":
163
+ case "control":
164
+ for (const child of node.children) visit(child);
165
+ return false;
166
+ case "fragment":
167
+ for (const child of node.children) visit(child);
168
+ return false;
169
+ case "element": {
170
+ let childrenStatic = true;
171
+ for (const child of node.children) {
172
+ if (!visit(child)) childrenStatic = false;
173
+ }
174
+ let reason;
175
+ for (const prop of node.props) {
176
+ reason = propReason(prop);
177
+ if (reason) break;
178
+ }
179
+ if (!reason && !childrenStatic) {
180
+ reason = childReason(node);
181
+ }
182
+ node.static = !reason;
183
+ if (reason) reasons.set(node, reason);
184
+ else staticElements.push(node);
185
+ return node.static;
186
+ }
187
+ /* c8 ignore next 2 */
188
+ default:
189
+ return false;
190
+ }
191
+ };
192
+ for (const node of Array.isArray(root) ? root : [root]) visit(node);
193
+ return { staticElements, reasons };
194
+ }
195
+ function childReason(node) {
196
+ for (const child of node.children) {
197
+ if (child.kind === "expr") return "expression-child";
198
+ if (child.kind === "component") return "component-child";
199
+ if (child.kind === "control") return "control-child";
200
+ if (child.kind === "element" && !child.static) return "expression-child";
201
+ if (child.kind === "fragment") return "expression-child";
202
+ }
203
+ return "expression-child";
204
+ }
205
+
206
+ // src/lower/text.ts
207
+ function cleanTemplateText(value) {
208
+ const lines = value.split(/\r\n|\n|\r/);
209
+ let lastNonEmpty = 0;
210
+ for (let i = 0; i < lines.length; i++) {
211
+ if (/[^ \t]/.test(lines[i])) lastNonEmpty = i;
212
+ }
213
+ let out = "";
214
+ for (let i = 0; i < lines.length; i++) {
215
+ let line = lines[i].replace(/\t/g, " ");
216
+ if (i !== 0) line = line.replace(/^ +/, "");
217
+ if (i !== lines.length - 1) line = line.replace(/ +$/, "");
218
+ if (!line) continue;
219
+ if (i !== lastNonEmpty) line += " ";
220
+ out += line;
221
+ }
222
+ return out;
223
+ }
224
+
225
+ // src/analyze/paren.ts
226
+ function skipQuoted(src, start) {
227
+ const quote = src[start];
228
+ for (let i = start + 1; i < src.length; i++) {
229
+ const c = src[i];
230
+ if (c === "\\") i++;
231
+ else if (c === quote) return i + 1;
232
+ else if (c === "\n") return -1;
233
+ }
234
+ return -1;
235
+ }
236
+ function skipTemplate(src, start) {
237
+ let i = start + 1;
238
+ while (i < src.length) {
239
+ const c = src[i];
240
+ if (c === "\\") {
241
+ i += 2;
242
+ } else if (c === "`") {
243
+ return i + 1;
244
+ } else if (c === "$" && src[i + 1] === "{") {
245
+ let depth = 1;
246
+ i += 2;
247
+ while (i < src.length && depth > 0) {
248
+ const k = src[i];
249
+ if (k === "\\") i += 2;
250
+ else if (k === "`") {
251
+ const end = skipTemplate(src, i);
252
+ if (end < 0) return -1;
253
+ i = end;
254
+ } else if (k === '"' || k === "'") {
255
+ const end = skipQuoted(src, i);
256
+ if (end < 0) return -1;
257
+ i = end;
258
+ } else {
259
+ if (k === "{") depth++;
260
+ else if (k === "}") depth--;
261
+ i++;
262
+ }
263
+ }
264
+ } else {
265
+ i++;
266
+ }
267
+ }
268
+ return -1;
269
+ }
270
+ function skipRegex(src, start) {
271
+ let inClass = false;
272
+ for (let i = start + 1; i < src.length; i++) {
273
+ const c = src[i];
274
+ if (c === "\\") i++;
275
+ else if (c === "[") inClass = true;
276
+ else if (c === "]") inClass = false;
277
+ else if (c === "\n") return -1;
278
+ else if (c === "/" && !inClass) {
279
+ let end = i + 1;
280
+ while (end < src.length && /[a-z]/i.test(src[end])) end++;
281
+ return end;
282
+ }
283
+ }
284
+ return -1;
285
+ }
286
+ function divides(prev) {
287
+ return prev !== "" && /[A-Za-z0-9_$)\]]/.test(prev);
288
+ }
289
+ function topLevelComma(src) {
290
+ let depth = 0;
291
+ let prev = "";
292
+ let i = 0;
293
+ while (i < src.length) {
294
+ const c = src[i];
295
+ if (c === '"' || c === "'") {
296
+ const end = skipQuoted(src, i);
297
+ if (end < 0) return null;
298
+ i = end;
299
+ prev = c;
300
+ } else if (c === "`") {
301
+ const end = skipTemplate(src, i);
302
+ if (end < 0) return null;
303
+ i = end;
304
+ prev = c;
305
+ } else if (c === "/" && src[i + 1] === "/") {
306
+ return null;
307
+ } else if (c === "/" && src[i + 1] === "*") {
308
+ const end = src.indexOf("*/", i + 2);
309
+ if (end < 0) return null;
310
+ i = end + 2;
311
+ } else if (c === "/" && !divides(prev)) {
312
+ const end = skipRegex(src, i);
313
+ if (end < 0) return null;
314
+ i = end;
315
+ prev = "/";
316
+ } else {
317
+ if (c === "(" || c === "[" || c === "{") depth++;
318
+ else if (c === ")" || c === "]" || c === "}") {
319
+ depth--;
320
+ if (depth < 0) return null;
321
+ } else if (c === "," && depth === 0) return true;
322
+ if (!/\s/.test(c)) prev = c;
323
+ i++;
324
+ }
325
+ }
326
+ return depth === 0 ? false : null;
327
+ }
328
+ function paren(code, position) {
329
+ const src = code.trim();
330
+ if (src === "") return `(${code})`;
331
+ if (position === "arrowBody" && src[0] === "{") return `(${code})`;
332
+ return topLevelComma(src) === false ? code : `(${code})`;
333
+ }
334
+
335
+ // src/analyze/intrinsics.ts
336
+ var REACTIVE_MODULE = "@fluixi/reactive/signal";
337
+ var INTRINSICS = {
338
+ $signal: { export: "signal", module: REACTIVE_MODULE, returns: "signal-handle" },
339
+ $memo: { export: "memo", module: REACTIVE_MODULE, returns: "memo-handle" },
340
+ $effect: { export: "effect", module: REACTIVE_MODULE, returns: "effect" },
341
+ $store: { export: "store", module: "@fluixi/reactive/store", returns: "store-handle" },
342
+ $resource: { export: "resource", module: REACTIVE_MODULE, returns: "resource-handle" },
343
+ $cachedResource: { export: "cachedResource", module: "@fluixi/reactive/cached-resource", returns: "resource-handle" },
344
+ // No short runtime form for these yet, so the intrinsic stands for the `create*`
345
+ // name. Still worth having: no import to write, and when a shorter form is
346
+ // designed, the change is this line rather than a compiler pass.
347
+ $selector: { export: "createSelector", module: REACTIVE_MODULE, returns: "memo-accessor" },
348
+ $deferred: { export: "createDeferred", module: REACTIVE_MODULE, returns: "memo-accessor" },
349
+ // Not value constructors, but the compiler has to know them: they change what a read
350
+ // does. `untrack` suppresses dependency collection, which is exactly the kind of thing
351
+ // dependency analysis must not guess at.
352
+ $untrack: { export: "untrack", module: REACTIVE_MODULE, returns: "plain" },
353
+ $untrackStore: { export: "untrackStore", module: "@fluixi/reactive/store", returns: "plain" },
354
+ // Scopes, scheduling and lifecycle: no value to classify, but the same authoring promise,
355
+ // no import to write. `$cleanup` registers a callback on the current owner (`onCleanup`).
356
+ $batch: { export: "batch", module: REACTIVE_MODULE, returns: "plain" },
357
+ $cleanup: { export: "onCleanup", module: REACTIVE_MODULE, returns: "plain" },
358
+ $root: { export: "root", module: REACTIVE_MODULE, returns: "plain" },
359
+ $context: { export: "context", module: REACTIVE_MODULE, returns: "plain" },
360
+ $renderEffect: { export: "renderEffect", module: REACTIVE_MODULE, returns: "effect" },
361
+ $computed: { export: "computed", module: REACTIVE_MODULE, returns: "effect" },
362
+ // Storage for where the code runs, and a signal kept in it. `$persisted` is a signal
363
+ // handle as far as reads go: the same accessor with `set` on it.
364
+ $storage: { export: "useStorage", module: "@fluixi/core/storage", returns: "plain" },
365
+ $asyncStorage: { export: "useAsyncStorage", module: "@fluixi/core/storage", returns: "plain" },
366
+ $persisted: { export: "persisted", module: "@fluixi/core/storage", returns: "signal-handle" },
367
+ // An environment variable, public or server-only; the browser build refuses a secret.
368
+ $env: { export: "env", module: "@fluixi/start/env", returns: "plain" }
369
+ };
370
+ var INTRINSIC_CALL = new RegExp(`\\$(?:${Object.keys(INTRINSICS).map((n) => n.slice(1)).join("|")})\\s*\\(`);
371
+
372
+ // src/transform/source-locations.ts
373
+ var SOURCE_MARKER = "__fx_source";
374
+ var HOLE_MARKER = "__fx_hole";
375
+ var markHole = (accessor, line, column, name) => `(globalThis.${HOLE_MARKER} ?? ((f) => f))(${accessor},${line},${column}${name === void 0 ? "" : `,${JSON.stringify(name)}`})`;
376
+ var PROPS_MARKER = "__fx_props";
377
+ var markProps = (object, at) => `(globalThis.${PROPS_MARKER} ?? ((p) => p))(${object},${JSON.stringify(at)})`;
378
+
379
+ // src/codegen/serialize-static.ts
380
+ var VOID_ELEMENTS = /* @__PURE__ */ new Set([
381
+ "area",
382
+ "base",
383
+ "br",
384
+ "col",
385
+ "embed",
386
+ "hr",
387
+ "img",
388
+ "input",
389
+ "link",
390
+ "meta",
391
+ "param",
392
+ "source",
393
+ "track",
394
+ "wbr"
395
+ ]);
396
+ var HTML_NAME = {
397
+ className: "class",
398
+ htmlFor: "for"
399
+ };
400
+ var PROPERTY_ONLY = /* @__PURE__ */ new Set([
401
+ "innerHTML",
402
+ "outerHTML",
403
+ "innerText",
404
+ "textContent",
405
+ "value",
406
+ "checked",
407
+ "selected",
408
+ "muted",
409
+ "defaultValue",
410
+ "defaultChecked",
411
+ "children",
412
+ "ref"
413
+ ]);
414
+ var RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set(["script", "style", "textarea", "title"]);
415
+ function isRawTextElement(tag) {
416
+ return RAW_TEXT_ELEMENTS.has(tag);
417
+ }
418
+ function htmlAttrName(name) {
419
+ return HTML_NAME[name] ?? name;
420
+ }
421
+ function isPlainLiteralAttr(prop) {
422
+ if (prop.kind !== "attr") return false;
423
+ if (prop.expr !== void 0) return false;
424
+ if (prop.name.includes(":")) return false;
425
+ return !PROPERTY_ONLY.has(prop.name);
426
+ }
427
+ function isSerializable(node) {
428
+ if (!node.static) return false;
429
+ if (isRawTextElement(node.tag)) return false;
430
+ for (const prop of node.props) {
431
+ if (!isPlainLiteralAttr(prop)) return false;
432
+ }
433
+ for (const child of node.children) {
434
+ if (child.kind === "text") continue;
435
+ if (child.kind === "element" && isSerializable(child)) continue;
436
+ return false;
437
+ }
438
+ return true;
439
+ }
440
+ function serializeStatic(node) {
441
+ const attrs = node.props.map(serializeProp).filter(Boolean).join("");
442
+ const open = `<${node.tag}${attrs}>`;
443
+ if (VOID_ELEMENTS.has(node.tag)) return open;
444
+ return `${open}${node.children.map(serializeChild).join("")}</${node.tag}>`;
445
+ }
446
+ function serializeChild(child) {
447
+ if (child.kind === "text") return escapeText(child.value);
448
+ if (child.kind !== "element") throw new Error(`serializeStatic: unexpected ${child.kind}`);
449
+ return serializeStatic(child);
450
+ }
451
+ function serializeProp(prop) {
452
+ const name = HTML_NAME[prop.name] ?? prop.name;
453
+ const value = prop.literal;
454
+ if (value === true || value === void 0) return ` ${name}`;
455
+ if (value === false || value === null) return "";
456
+ return ` ${name}="${escapeAttr(String(value))}"`;
457
+ }
458
+ function escapeAttr(value) {
459
+ return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
460
+ }
461
+ function escapeText(value) {
462
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
463
+ }
464
+ function templatePositions(root) {
465
+ const pos = [];
466
+ let file;
467
+ const walk = (el) => {
468
+ file ??= el.at?.file;
469
+ pos.push(el.at?.line ?? 0, el.at?.column ?? 0);
470
+ for (const child of el.children) if (child.kind === "element") walk(child);
471
+ };
472
+ walk(root);
473
+ return file && pos.some((n) => n !== 0) ? { file, pos } : void 0;
474
+ }
475
+
476
+ // src/codegen/partial-template.ts
477
+ var HOLE_START = "<!--fx-->";
478
+ var HOLE_END = "<!--fx/-->";
479
+ function isHole(node) {
480
+ return node.kind === "expr" || node.kind === "component" || node.kind === "control";
481
+ }
482
+ function isTemplateChild(node) {
483
+ return node.kind === "text" || node.kind === "element" && isTemplateElement(node);
484
+ }
485
+ function isTemplateElement(node) {
486
+ if (node.svg) return false;
487
+ if (isRawTextElement(node.tag)) return false;
488
+ if (!node.props.every((p) => isPlainLiteralAttr(p))) return false;
489
+ return node.children.every((c) => isTemplateChild(c) || isHole(c));
490
+ }
491
+ function containsHole(node) {
492
+ if (isHole(node)) return true;
493
+ const children = node.children;
494
+ return children ? children.some(containsHole) : false;
495
+ }
496
+ function addressable(el) {
497
+ for (let i = 0; i < el.children.length; i++) {
498
+ const child = el.children[i];
499
+ if (child.kind === "text") {
500
+ if (child.value === "") return false;
501
+ if (el.children[i + 1]?.kind === "text") return false;
502
+ }
503
+ }
504
+ return el.children.every((c) => c.kind !== "element" || addressable(c));
505
+ }
506
+ function planPartialTemplate(root) {
507
+ if (!isTemplateElement(root)) return null;
508
+ if (!addressable(root)) return null;
509
+ if (!root.children.some(containsHole)) return null;
510
+ const steps = [];
511
+ const holes = [];
512
+ let refCount = 0;
513
+ const declare = (expr) => {
514
+ const ref = `_n$${refCount++}`;
515
+ steps.push({ ref, expr });
516
+ return ref;
517
+ };
518
+ walk(root, "_el$");
519
+ return { html: serializeWithMarkers(root), tag: root.tag, steps, holes };
520
+ function walk(el, elementRef) {
521
+ let last = -1;
522
+ el.children.forEach((child, i) => {
523
+ if (containsHole(child)) last = i;
524
+ });
525
+ let previous = null;
526
+ for (let i = 0; i <= last; i++) {
527
+ const child = el.children[i];
528
+ const expr = previous ? `${previous}.nextSibling` : `${elementRef}.firstChild`;
529
+ if (isHole(child)) {
530
+ const startRef = declare(expr);
531
+ const endRef = declare(`holeEnd(${startRef})`);
532
+ holes.push({ parentRef: elementRef, startRef, endRef, node: child });
533
+ previous = endRef;
534
+ continue;
535
+ }
536
+ const ref = declare(expr);
537
+ if (child.kind === "element" && containsHole(child)) walk(child, ref);
538
+ previous = ref;
539
+ }
540
+ }
541
+ }
542
+ function serializeWithMarkers(el) {
543
+ return serializeStatic(withSentinels(el)).split(SENTINEL).join(HOLE_START + HOLE_END);
544
+ }
545
+ function withSentinels(el) {
546
+ return {
547
+ ...el,
548
+ children: el.children.map(
549
+ (child) => isHole(child) ? { kind: "text", value: SENTINEL } : child.kind === "element" ? withSentinels(child) : child
550
+ )
551
+ };
552
+ }
553
+ var SENTINEL = "\0fx-hole\0";
554
+
555
+ // src/codegen/contract.ts
556
+ var RUNTIME_CONTRACT_V1 = {
557
+ version: 1,
558
+ module: "@fluixi/dom",
559
+ symbols: [
560
+ "createNativeElement",
561
+ "insert",
562
+ "spread",
563
+ "setAttribute",
564
+ "delegateEvents",
565
+ "createComponent",
566
+ "createMemo",
567
+ "untrack",
568
+ "Show",
569
+ "For",
570
+ "Index",
571
+ "Switch",
572
+ "Match",
573
+ "Dynamic",
574
+ "ErrorBoundary"
575
+ ]
576
+ };
577
+ var RUNTIME_CONTRACT_V2 = {
578
+ version: 2,
579
+ module: "@fluixi/dom",
580
+ symbols: [...RUNTIME_CONTRACT_V1.symbols, "template", "cloneTemplate", "walk"]
581
+ };
582
+
583
+ // src/codegen/backends/imperative.ts
584
+ var CONTROL_COMPONENT = {
585
+ show: "Show",
586
+ for: "For",
587
+ index: "Index",
588
+ switch: "Switch",
589
+ match: "Match",
590
+ dynamic: "Dynamic",
591
+ errorBoundary: "ErrorBoundary",
592
+ suspense: "Suspense"
593
+ };
594
+ function isIdent(name) {
595
+ return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name);
596
+ }
597
+ function propKey(name) {
598
+ return isIdent(name) ? name : JSON.stringify(name);
599
+ }
600
+ function propValue(p) {
601
+ if (p.expr !== void 0) {
602
+ if (p.name === "ref" && p.at)
603
+ return markHole(paren(p.expr, "value"), p.at.line, p.at.column, p.expr);
604
+ if (!p.reactive) return paren(p.expr, "value");
605
+ const accessor = `() => ${paren(p.expr, "arrowBody")}`;
606
+ return p.at ? markHole(accessor, p.at.line, p.at.column, p.directive) : accessor;
607
+ }
608
+ return JSON.stringify(p.literal ?? true);
609
+ }
610
+ function componentPropValue(p) {
611
+ if (p.expr !== void 0) return paren(p.expr, "value");
612
+ return JSON.stringify(p.literal ?? true);
613
+ }
614
+ function emitProps(props, childrenExpr, used) {
615
+ const spreads = props.filter((p) => p.kind === "spread");
616
+ const normal = props.filter((p) => p.kind !== "spread");
617
+ const entries = normal.map((p) => `${propKey(p.name)}: ${propValue(p)}`);
618
+ if (childrenExpr != null) entries.push(`children: ${childrenExpr}`);
619
+ const obj = `{ ${entries.join(", ")} }`;
620
+ if (spreads.length > 0) {
621
+ used.add("mergeProps");
622
+ return `mergeProps(${spreads.map((s) => s.expr).join(", ")}, ${obj})`;
623
+ }
624
+ return obj;
625
+ }
626
+ function markBind(code, at) {
627
+ return at ? markHole(code, at.line, at.column) : code;
628
+ }
629
+ function emitChildren(children, used, templates) {
630
+ if (children.length === 1) return emitNode(children[0], used, templates);
631
+ let deferred = false;
632
+ const items = children.map((child) => {
633
+ const code = emitNode(child, used, templates);
634
+ if (child.kind === "element" && deferred) {
635
+ used.add("deferElement");
636
+ return `deferElement(() => ${paren(code, "arrowBody")})`;
637
+ }
638
+ if (child.kind === "component" || child.kind === "control" || child.kind === "expr" && child.reactive) deferred = true;
639
+ return code;
640
+ });
641
+ return `[${items.join(", ")}]`;
642
+ }
643
+ function emitComponent(name, props, children, used, templates, at) {
644
+ used.add("createMemo");
645
+ used.add("createComponent");
646
+ const spreads = props.filter((p) => p.kind === "spread");
647
+ const normal = props.filter((p) => p.kind !== "spread");
648
+ const bodies = normal.map((p) => [p.name, componentPropValue(p)]);
649
+ if (children.length > 0) {
650
+ bodies.push(["children", emitChildren(children, used, templates)]);
651
+ }
652
+ let obj = `{ ${bodies.map(([name2, body]) => `get ${propKey(name2)}() { return ${body}; }`).join(", ")} }`;
653
+ if (bodies.some(([, body]) => /\bthis\b/.test(body))) {
654
+ const thunks = bodies.map(([name2, body]) => `${JSON.stringify(name2)}: () => (${body})`);
655
+ const getters = bodies.map(([name2]) => `get ${propKey(name2)}() { return _$t[${JSON.stringify(name2)}](); }`);
656
+ obj = `((_$t) => ({ ${getters.join(", ")} }))({ ${thunks.join(", ")} })`;
657
+ }
658
+ if (spreads.length > 0) {
659
+ used.add("mergeProps");
660
+ obj = `mergeProps(${spreads.map((s) => s.expr).join(", ")}, ${obj})`;
661
+ }
662
+ const propAt = {};
663
+ for (const p of normal) if (p.at) propAt[p.name] = [p.at.line, p.at.column];
664
+ if (Object.keys(propAt).length) obj = markProps(obj, propAt);
665
+ const mark = at ? `globalThis.${SOURCE_MARKER}?.(${JSON.stringify(at.file)},${at.line},${at.column},${JSON.stringify(name)}), ` : "";
666
+ return `createMemo(${paren(`${mark}() => createComponent(${name}, ${obj})`, "value")})`;
667
+ }
668
+ function staticAttrAssignment(el, prop) {
669
+ const name = htmlAttrName(prop.name);
670
+ const value = prop.literal;
671
+ if (value === true || value === void 0) return `${el}.setAttribute(${JSON.stringify(name)}, "");`;
672
+ if (value === false || value === null) return "";
673
+ return `${el}.setAttribute(${JSON.stringify(name)}, ${JSON.stringify(String(value))});`;
674
+ }
675
+ var partial = false;
676
+ function emitNode(node, used, templates) {
677
+ switch (node.kind) {
678
+ case "text":
679
+ return JSON.stringify(node.value);
680
+ case "expr": {
681
+ if (!node.reactive) return paren(node.code, "value");
682
+ const accessor = `() => ${paren(node.code, "arrowBody")}`;
683
+ return node.at ? markHole(accessor, node.at.line, node.at.column) : accessor;
684
+ }
685
+ case "fragment":
686
+ if (node.children.length === 0) return "null";
687
+ return emitChildren(node.children, used, templates);
688
+ case "component":
689
+ return markBind(emitComponent(node.name, node.props, node.children, used, templates, node.at), node.bindAt ?? node.at);
690
+ case "control": {
691
+ const name = CONTROL_COMPONENT[node.control] ?? node.control;
692
+ used.add(name);
693
+ return markBind(emitComponent(name, node.props, node.children, used, templates), node.bindAt);
694
+ }
695
+ case "element": {
696
+ if (templates && node.static && !node.svg && isSerializable(node)) {
697
+ used.add("templateNode");
698
+ const id = `_tmpl$${templates.length}`;
699
+ templates.push({ id, html: serializeStatic(node), tag: node.tag, svg: false });
700
+ const at = templatePositions(node);
701
+ return at ? `templateNode(${id}, ${JSON.stringify(node.tag)}, false, false, ${JSON.stringify(at)})` : `templateNode(${id}, ${JSON.stringify(node.tag)})`;
702
+ }
703
+ if (templates && partial) {
704
+ const plan = planPartialTemplate(node);
705
+ if (plan) {
706
+ used.add("templateNode");
707
+ used.add("insert");
708
+ used.add("holeEnd");
709
+ used.add("holeContent");
710
+ used.add("holeScope");
711
+ const id = `_tmpl$${templates.length}`;
712
+ templates.push({ id, html: plan.html, tag: plan.tag, svg: false });
713
+ const at = templatePositions(node);
714
+ const lines = [
715
+ `const _el$ = templateNode(${id}, ${JSON.stringify(plan.tag)}, true${at ? `, false, ${JSON.stringify(at)}` : ""});`
716
+ ];
717
+ for (const step of plan.steps) lines.push(`const ${step.ref} = ${step.expr};`);
718
+ for (const hole of plan.holes) {
719
+ lines.push(
720
+ `insert(${hole.parentRef}, holeScope(${hole.startRef}, () => ${paren(emitNode(hole.node, used, templates), "arrowBody")}), ${hole.endRef}, holeContent(${hole.startRef}, ${hole.endRef}));`
721
+ );
722
+ }
723
+ lines.push("return _el$;");
724
+ return `(() => { ${lines.join(" ")} })()`;
725
+ }
726
+ }
727
+ used.add("createNativeElement");
728
+ const tag = JSON.stringify(node.tag);
729
+ const el = "_el$";
730
+ const parts = [];
731
+ const createArgs = node.at ? `${tag}, ${node.svg}, ${JSON.stringify(node.at)}` : node.svg ? `${tag}, true` : tag;
732
+ parts.push(`const ${el} = createNativeElement(${createArgs});`);
733
+ if (node.props.length > 0) {
734
+ if (!node.svg && node.props.every(isPlainLiteralAttr)) {
735
+ for (const p of node.props) parts.push(staticAttrAssignment(el, p));
736
+ } else {
737
+ used.add("spread");
738
+ const svgFlag = node.svg ? ", isSVG: true" : "";
739
+ const accessors = node.props.filter((p) => p.kind !== "spread" && p.expr !== void 0 && p.reactive && p.name !== "ref").map((p) => p.name);
740
+ const customFlag = node.tag.includes("-") ? `, isCustomElement: true, accessors: ${JSON.stringify(accessors)}` : "";
741
+ parts.push(
742
+ `spread({ element: ${el}, props: ${emitProps(node.props, null, used)}${svgFlag}${customFlag} });`
743
+ );
744
+ }
745
+ }
746
+ for (const child of node.children) {
747
+ used.add("insert");
748
+ const childCode = emitNode(child, used, templates);
749
+ const anchored = child.kind === "expr" && (child.reactive || !isLiteralCode(child.code)) || child.kind === "component" || child.kind === "control";
750
+ parts.push(anchored ? `insert(${el}, ${childCode}, null);` : `insert(${el}, ${childCode});`);
751
+ }
752
+ parts.push(`return ${el};`);
753
+ return `(() => { ${parts.join(" ")} })()`;
754
+ }
755
+ }
756
+ }
757
+ var LITERAL = /^\s*(?:'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`[^`$]*`|-?\d[\d_.eE+-]*|true|false|null|undefined)\s*$/;
758
+ var isLiteralCode = (code) => LITERAL.test(code);
759
+ function inlineTemplates(code, templates) {
760
+ if (!templates || templates.length === 0) return code;
761
+ const byId = new Map(templates.map((t) => [t.id, JSON.stringify(t.html)]));
762
+ return code.replace(/_tmpl\$\d+/g, (id) => byId.get(id) ?? id);
763
+ }
764
+ var imperativeBackend = {
765
+ name: "imperative",
766
+ contract: RUNTIME_CONTRACT_V1,
767
+ emit(node, options) {
768
+ const used = /* @__PURE__ */ new Set();
769
+ const templates = options?.templateClone !== false ? [] : void 0;
770
+ partial = options?.partialTemplates === true;
771
+ const code = emitNode(node, used, templates);
772
+ return { code, imports: Array.from(used), templates };
773
+ }
774
+ };
775
+
776
+ // src/lower/jsx.ts
777
+ var SVG_TAGS = /* @__PURE__ */ new Set([
778
+ "svg",
779
+ "path",
780
+ "circle",
781
+ "rect",
782
+ "line",
783
+ "polygon",
784
+ "polyline",
785
+ "ellipse",
786
+ "g",
787
+ "defs",
788
+ "clipPath",
789
+ "text"
790
+ ]);
791
+ var EVENT_RE = /^on[A-Z]/;
792
+ var DELEGATED = /* @__PURE__ */ new Set([
793
+ "click",
794
+ "dblclick",
795
+ "input",
796
+ "change",
797
+ "submit",
798
+ "focus",
799
+ "blur",
800
+ "keydown",
801
+ "keyup",
802
+ "keypress",
803
+ "mousedown",
804
+ "mouseup"
805
+ ]);
806
+ var isReactive = (node) => isReactiveShape(shapeOf(node));
807
+ var CONTAINER = "container";
808
+ function directive(node, name) {
809
+ if (node.type !== "JSXElement") return void 0;
810
+ const opening = node.openingElement;
811
+ if (opening.name.type !== "JSXIdentifier" || opening.name.name[0] !== opening.name.name[0].toLowerCase()) return void 0;
812
+ return opening.attributes.find((a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === name);
813
+ }
814
+ function directiveExpr(attr) {
815
+ const v = attr.value;
816
+ return v?.type === "JSXExpressionContainer" && v.expression?.type !== "JSXEmptyExpression" ? v.expression : void 0;
817
+ }
818
+ function emitIR(ir, ctx) {
819
+ const { code, imports, templates } = imperativeBackend.emit(ir, {});
820
+ for (const s of imports) ctx.used.add(s);
821
+ return inlineTemplates(code, templates);
822
+ }
823
+ var posOf = (node, ctx) => {
824
+ if (!ctx.sourceFile) return void 0;
825
+ const at = node.loc?.start;
826
+ return at ? { line: at.line, column: at.column } : void 0;
827
+ };
828
+ function literalOf(node) {
829
+ if (node.type === "StringLiteral" || node.type === "NumericLiteral" || node.type === "BooleanLiteral") {
830
+ return node.value;
831
+ }
832
+ if (node.type === "Literal" && (typeof node.value === "string" || typeof node.value === "number" || typeof node.value === "boolean")) {
833
+ return node.value;
834
+ }
835
+ return void 0;
836
+ }
837
+ var isString = (node) => !!node && typeof literalOf(node) === "string";
838
+ function tagInfo(name, ctx) {
839
+ if (name.type === "JSXIdentifier") {
840
+ return { tag: name.name, component: name.name[0] !== name.name[0].toLowerCase() };
841
+ }
842
+ if (name.type === "JSXMemberExpression") return { tag: ctx.code(name), component: true };
843
+ if (name.type === "JSXNamespacedName") {
844
+ return { tag: `${name.namespace.name}:${name.name.name}`, component: false };
845
+ }
846
+ return { tag: "div", component: false };
847
+ }
848
+ function attrName(name) {
849
+ if (name.type === "JSXIdentifier") return name.name === "class" ? "className" : name.name;
850
+ if (name.type === "JSXNamespacedName") return `${name.namespace.name}:${name.name.name}`;
851
+ return "unknown";
852
+ }
853
+ function buildAttr(attr, ctx) {
854
+ const name = attrName(attr.name);
855
+ const isEvent = EVENT_RE.test(name);
856
+ const isHandler = isEvent || name.startsWith("on:") || name === "ref";
857
+ const kind = isEvent ? "event" : "attr";
858
+ const base = { name, kind };
859
+ if (isEvent) {
860
+ const evt = name.slice(2).toLowerCase();
861
+ base.event = { name: evt, delegated: DELEGATED.has(evt) };
862
+ }
863
+ const v = attr.value;
864
+ if (v == null) {
865
+ base.literal = true;
866
+ base.at = posOf(attr, ctx);
867
+ return base;
868
+ }
869
+ if (isString(v)) {
870
+ base.literal = literalOf(v);
871
+ base.at = posOf(v, ctx);
872
+ return base;
873
+ }
874
+ if (v.type === "JSXExpressionContainer" && v.expression?.type !== "JSXEmptyExpression") {
875
+ const expr = v.expression;
876
+ const literal = literalOf(expr);
877
+ if (literal !== void 0) {
878
+ base.literal = literal;
879
+ base.at = posOf(expr, ctx);
880
+ return base;
881
+ }
882
+ base.expr = ctx.code(expr);
883
+ base.reactive = isHandler ? false : isReactive(expr);
884
+ base.at = posOf(expr, ctx);
885
+ if (expr.type === "JSXElement" || expr.type === "JSXFragment") base.jsxElement = true;
886
+ return base;
887
+ }
888
+ base.literal = true;
889
+ return base;
890
+ }
891
+ function attrExprCode(attr, ctx) {
892
+ const v = attr.value;
893
+ if (v == null) return null;
894
+ if (isString(v)) return JSON.stringify(literalOf(v));
895
+ if (v.type === "JSXExpressionContainer" && v.expression?.type !== "JSXEmptyExpression") {
896
+ return ctx.code(v.expression);
897
+ }
898
+ return null;
899
+ }
900
+ function buildProps(attrs, ctx, element = false) {
901
+ const props = [];
902
+ const usePairs = [];
903
+ const classEntries = [];
904
+ const styleEntries = [];
905
+ let styleAt;
906
+ for (const a of attrs) {
907
+ if (a.type === "JSXSpreadAttribute") {
908
+ props.push({ name: "", kind: "spread", expr: ctx.code(a.argument) });
909
+ continue;
910
+ }
911
+ if (a.type !== "JSXAttribute") continue;
912
+ if (isLoadDirective(attrName(a.name))) continue;
913
+ const ns = a.name.type === "JSXNamespacedName" ? a.name.namespace.name : null;
914
+ if (ns === "use") {
915
+ const dir = a.name.name.name;
916
+ ctx.used.add(dir);
917
+ const opts = attrExprCode(a, ctx);
918
+ usePairs.push(opts != null ? `[${dir}, () => ${paren(opts, "arrowBody")}]` : `[${dir}]`);
919
+ continue;
920
+ }
921
+ if (element && (ns === "class" || ns === "style")) {
922
+ const key = JSON.stringify(a.name.name.name);
923
+ const v = a.value;
924
+ let value;
925
+ if (v == null) value = "true";
926
+ else if (isString(v)) value = JSON.stringify(literalOf(v));
927
+ else if (v.type === "JSXExpressionContainer" && v.expression?.type !== "JSXEmptyExpression") {
928
+ value = keyValue(v.expression, ctx);
929
+ if (ns === "style") styleAt ??= posOf(v.expression, ctx);
930
+ } else continue;
931
+ (ns === "class" ? classEntries : styleEntries).push(`${key}: ${value}`);
932
+ continue;
933
+ }
934
+ if (element && a.name.type === "JSXIdentifier" && a.name.name === "style" && a.value?.type === "JSXExpressionContainer") {
935
+ const entries = objectEntries(a.value.expression, ctx);
936
+ if (entries) {
937
+ styleEntries.unshift(...entries);
938
+ styleAt = posOf(a.value.expression, ctx);
939
+ continue;
940
+ }
941
+ }
942
+ if (ns === "oncapture") {
943
+ const evt = a.name.name.name.toLowerCase();
944
+ const h = attrExprCode(a, ctx) ?? "undefined";
945
+ props.push({ name: "on:" + evt, kind: "attr", expr: `[${h}, { capture: true }]` });
946
+ continue;
947
+ }
948
+ props.push(buildAttr(a, ctx));
949
+ }
950
+ if (classEntries.length > 0) props.push({ name: "classList", kind: "attr", expr: `{ ${classEntries.join(", ")} }`, reactive: false });
951
+ if (styleEntries.length > 0) {
952
+ const entries = `{ ${styleEntries.join(", ")} }`;
953
+ const base = props.findIndex((p) => p.name === "style" && p.kind === "attr");
954
+ if (base === -1) props.push({ name: "style", kind: "attr", expr: entries, reactive: false, ...styleAt ? { at: styleAt } : {} });
955
+ else {
956
+ const prop = props[base];
957
+ const value = prop.literal !== void 0 ? JSON.stringify(prop.literal) : prop.reactive ? `() => ${paren(prop.expr, "arrowBody")}` : prop.expr;
958
+ props[base] = { name: "style", kind: "attr", expr: `[${value}, ${entries}]`, reactive: false, ...prop.at ? { at: prop.at } : {} };
959
+ }
960
+ }
961
+ if (usePairs.length > 0) props.push({ name: "use", kind: "attr", expr: `[${usePairs.join(", ")}]` });
962
+ return props;
963
+ }
964
+ function keyValue(expr, ctx) {
965
+ const code = ctx.code(expr);
966
+ if (!isReactive(expr)) return code;
967
+ const accessor = `() => ${paren(code, "arrowBody")}`;
968
+ const at = posOf(expr, ctx);
969
+ return at ? markHole(accessor, at.line, at.column) : accessor;
970
+ }
971
+ function objectEntries(expr, ctx) {
972
+ if (expr?.type !== "ObjectExpression") return null;
973
+ const entries = [];
974
+ for (const p of expr.properties) {
975
+ if (p.type !== "ObjectProperty") return null;
976
+ const key = p.computed ? `[${ctx.code(p.key)}]` : p.key.type === "Identifier" ? JSON.stringify(p.key.name) : JSON.stringify(String(p.key.value));
977
+ entries.push(`${key}: ${keyValue(p.value, ctx)}`);
978
+ }
979
+ return entries;
980
+ }
981
+ function buildChildren(children, ctx) {
982
+ const out = [];
983
+ for (let i = 0; i < children.length; i++) {
984
+ const child = children[i];
985
+ if (directive(child, "if")) {
986
+ let next = i + 1;
987
+ while (next < children.length && children[next].type === "JSXText" && !cleanTemplateText(children[next].value)) next++;
988
+ const fallback = directive(children[next], "else") ? children[next] : null;
989
+ out.push(buildIf(child, fallback, ctx));
990
+ if (fallback) i = next;
991
+ continue;
992
+ }
993
+ if (child.type === "JSXText") {
994
+ const text = cleanTemplateText(child.value);
995
+ if (text) out.push({ kind: "text", value: text });
996
+ } else if (child.type === "JSXExpressionContainer") {
997
+ if (child.expression?.type !== "JSXEmptyExpression") {
998
+ const expr = child.expression;
999
+ const reactive = isReactive(expr);
1000
+ out.push({
1001
+ kind: "expr",
1002
+ code: ctx.code(expr),
1003
+ reactive,
1004
+ ...reactive ? { at: posOf(expr, ctx) } : {}
1005
+ });
1006
+ }
1007
+ } else if (child.type === "JSXElement" || child.type === "JSXFragment") {
1008
+ if (ctx.dropStyles?.has(child.start)) continue;
1009
+ out.push(buildNode(child, ctx));
1010
+ } else if (child.type === "JSXSpreadChild") {
1011
+ out.push({ kind: "expr", code: ctx.code(child.expression), reactive: false });
1012
+ }
1013
+ }
1014
+ return out;
1015
+ }
1016
+ function readLoad(attrs) {
1017
+ for (const a of attrs) {
1018
+ if (a.type !== "JSXAttribute") continue;
1019
+ const name = attrName(a.name);
1020
+ if (!isLoadDirective(name)) continue;
1021
+ if (a.value && !isString(a.value)) {
1022
+ throw new LoadDirectiveError(
1023
+ `'${name}' needs a literal value, not an expression — the strategy is compile-time.`
1024
+ );
1025
+ }
1026
+ return parseLoadDirective(name, a.value ? literalOf(a.value) : null);
1027
+ }
1028
+ return void 0;
1029
+ }
1030
+ function buildIf(node, fallback, ctx) {
1031
+ const cond = directiveExpr(directive(node, "if"));
1032
+ const props = [
1033
+ cond ? { name: "when", kind: "attr", expr: ctx.code(cond), reactive: isReactive(cond), at: posOf(cond, ctx) } : { name: "when", kind: "attr", literal: true }
1034
+ ];
1035
+ if (fallback) {
1036
+ props.push({ name: "fallback", kind: "attr", expr: emitIR(buildElement(fallback, ctx, ["else"]), ctx), jsxElement: true });
1037
+ }
1038
+ return { kind: "component", name: "Show", props, children: [buildElement(node, ctx, ["if"])] };
1039
+ }
1040
+ function buildEach(node, ctx) {
1041
+ const attr = directive(node, "each");
1042
+ if (!attr) return null;
1043
+ const list = directiveExpr(attr);
1044
+ const props = [
1045
+ list ? { name: "each", kind: "attr", expr: ctx.code(list), reactive: isReactive(list), at: posOf(list, ctx) } : { name: "each", kind: "attr", expr: "[]" }
1046
+ ];
1047
+ const key = directive(node, "key");
1048
+ if (key) {
1049
+ const keyExpr = directiveExpr(key);
1050
+ const by = isString(key.value) ? `(item) => item[${JSON.stringify(literalOf(key.value))}]` : keyExpr ? ctx.code(keyExpr) : void 0;
1051
+ if (by) props.push({ name: "by", kind: "attr", expr: by });
1052
+ }
1053
+ const content = node.children.filter((c) => !(c.type === "JSXText" && !cleanTemplateText(c.value)));
1054
+ const only = content.length === 1 && content[0].type === "JSXExpressionContainer" ? content[0].expression : null;
1055
+ let render;
1056
+ if (only && (only.type === "ArrowFunctionExpression" || only.type === "FunctionExpression")) {
1057
+ const fn = ctx.code(only);
1058
+ const live = only.type === "ArrowFunctionExpression" && only.body.type !== "BlockStatement" && isReactive(only.body);
1059
+ render = live ? `(...args) => () => (${fn})(...args)` : fn;
1060
+ } else {
1061
+ const built = buildChildren(node.children, ctx);
1062
+ const ir = built.length === 1 ? built[0] : { kind: "fragment", children: built };
1063
+ render = `() => ${paren(emitIR(ir, ctx), "arrowBody")}`;
1064
+ }
1065
+ return { kind: "component", name: "For", props, children: [{ kind: "expr", code: render, reactive: false }] };
1066
+ }
1067
+ function buildElement(node, ctx, handled) {
1068
+ const skip = new Set(handled);
1069
+ const directives = /* @__PURE__ */ new Set(["if", "else", "each", ...directive(node, "each") ? ["key"] : []]);
1070
+ const attributes = node.openingElement.attributes.filter(
1071
+ (a) => !(a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && (skip.has(a.name.name) || directives.has(a.name.name)))
1072
+ );
1073
+ const { tag } = tagInfo(node.openingElement.name, ctx);
1074
+ const each = buildEach(node, ctx);
1075
+ const children = each ? [each] : buildChildren(node.children, ctx);
1076
+ if (tag === CONTAINER) return children.length === 1 ? children[0] : { kind: "fragment", children };
1077
+ const at = ctx.sourceFile && node.loc?.start ? { file: ctx.sourceFile, line: node.loc.start.line, column: node.loc.start.column } : void 0;
1078
+ const props = buildProps(attributes, ctx, true);
1079
+ const scope = ctx.scopes?.find((s) => node.start >= s.start && node.end <= s.end);
1080
+ if (scope) props.unshift({ name: "data-fx-s", kind: "attr", literal: scope.value });
1081
+ return { kind: "element", tag, svg: SVG_TAGS.has(tag), props, children, static: false, ...at ? { at } : {} };
1082
+ }
1083
+ function buildNode(node, ctx) {
1084
+ if (node.type === "JSXFragment") {
1085
+ return { kind: "fragment", children: buildChildren(node.children, ctx) };
1086
+ }
1087
+ if (directive(node, "if")) return buildIf(node, null, ctx);
1088
+ if (ctx.dropStyles?.has(node.start)) return { kind: "fragment", children: [] };
1089
+ const { tag, component } = tagInfo(node.openingElement.name, ctx);
1090
+ if (!component) return buildElement(node, ctx, []);
1091
+ const props = buildProps(node.openingElement.attributes, ctx);
1092
+ const children = buildChildren(node.children, ctx);
1093
+ const at = ctx.sourceFile && node.loc?.start ? { file: ctx.sourceFile, line: node.loc.start.line, column: node.loc.start.column } : void 0;
1094
+ const load = readLoad(node.openingElement.attributes);
1095
+ return { kind: "component", name: tag, props, children, ...load ? { load } : {}, ...at ? { at } : {} };
1096
+ }
1097
+ function buildJsxIR(node, ctx) {
1098
+ const ir = buildNode(node, ctx);
1099
+ analyzeStatic(ir);
1100
+ return ir;
1101
+ }