@fluixi/compiler 1.0.0-alpha.93 → 1.0.0-alpha.95

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 (93) hide show
  1. package/LICENSE +1 -1
  2. package/dist/analyze/intrinsics.cjs +13 -1
  3. package/dist/analyze/intrinsics.d.cts +14 -0
  4. package/dist/analyze/intrinsics.d.ts +14 -0
  5. package/dist/analyze/intrinsics.d.ts.map +1 -1
  6. package/dist/analyze/intrinsics.js +17 -0
  7. package/dist/analyze/intrinsics.mjs +13 -1
  8. package/dist/analyze/static-graph.cjs +1 -1
  9. package/dist/analyze/static-graph.mjs +1 -1
  10. package/dist/{babel-RJHJQVEM.mjs → babel-V33QLJBF.mjs} +4 -4
  11. package/dist/{chunk-56QSOVVL.mjs → chunk-62F2LLBM.mjs} +1 -1
  12. package/dist/{chunk-R7PPFBCL.mjs → chunk-7GNSGUHK.mjs} +4 -83
  13. package/dist/{chunk-U7HCFLZ2.mjs → chunk-B64LVPTU.mjs} +356 -24
  14. package/dist/{chunk-OD53TMER.mjs → chunk-C3AK5PBV.mjs} +13 -1
  15. package/dist/{chunk-TJIH7TLX.mjs → chunk-GLFUPZ27.mjs} +1 -1
  16. package/dist/chunk-HUABRVWB.mjs +92 -0
  17. package/dist/chunk-XCWP7WJG.mjs +584 -0
  18. package/dist/codegen/backends/imperative.cjs +1 -1
  19. package/dist/codegen/backends/imperative.d.ts.map +1 -1
  20. package/dist/codegen/backends/imperative.js +2 -1
  21. package/dist/codegen/backends/imperative.mjs +1 -1
  22. package/dist/frontend/babel/build-ir-lit.cjs +352 -22
  23. package/dist/frontend/babel/build-ir-lit.mjs +352 -22
  24. package/dist/frontend/babel/build-ir.cjs +352 -22
  25. package/dist/frontend/babel/build-ir.mjs +352 -22
  26. package/dist/frontend/babel/index.cjs +353 -23
  27. package/dist/frontend/babel/index.mjs +353 -23
  28. package/dist/frontend/babel/lower-template.cjs +352 -22
  29. package/dist/frontend/babel/lower-template.mjs +352 -22
  30. package/dist/frontend/babel/plugin.cjs +352 -22
  31. package/dist/frontend/babel/plugin.mjs +352 -22
  32. package/dist/index.cjs +321 -22
  33. package/dist/index.mjs +333 -22
  34. package/dist/integrations.cjs +1240 -56
  35. package/dist/integrations.d.ts.map +1 -1
  36. package/dist/integrations.js +62 -9
  37. package/dist/integrations.mjs +257 -26
  38. package/dist/lower/compile-template.cjs +315 -21
  39. package/dist/lower/compile-template.d.cts +13 -0
  40. package/dist/lower/compile-template.d.ts +13 -0
  41. package/dist/lower/compile-template.d.ts.map +1 -1
  42. package/dist/lower/compile-template.js +3 -0
  43. package/dist/lower/compile-template.mjs +327 -21
  44. package/dist/lower/entities.cjs +288 -0
  45. package/dist/lower/entities.d.cts +1 -0
  46. package/dist/lower/entities.d.ts +2 -0
  47. package/dist/lower/entities.d.ts.map +1 -0
  48. package/dist/lower/entities.js +54 -0
  49. package/dist/lower/entities.mjs +267 -0
  50. package/dist/lower/jsx.cjs +104 -47
  51. package/dist/lower/jsx.d.cts +8 -0
  52. package/dist/lower/jsx.d.ts +8 -0
  53. package/dist/lower/jsx.d.ts.map +1 -1
  54. package/dist/lower/jsx.js +92 -2
  55. package/dist/lower/jsx.mjs +104 -47
  56. package/dist/lower/template.cjs +293 -20
  57. package/dist/lower/template.d.ts.map +1 -1
  58. package/dist/lower/template.js +35 -19
  59. package/dist/lower/template.mjs +293 -20
  60. package/dist/resolve/builtins.cjs +1 -1
  61. package/dist/resolve/builtins.mjs +1 -1
  62. package/dist/resolve/component-globals.cjs +6 -1
  63. package/dist/resolve/component-globals.js +2 -2
  64. package/dist/resolve/component-globals.mjs +6 -1
  65. package/dist/resolve/write-globals.cjs +6 -1
  66. package/dist/resolve/write-globals.mjs +6 -1
  67. package/dist/{server-fns-ZFRDIQ2X.mjs → server-fns-N3SDJXA7.mjs} +5 -4
  68. package/dist/{server-functions-CTDXX67X.mjs → server-functions-LVS66Q4R.mjs} +3 -3
  69. package/dist/transform/index.cjs +973 -33
  70. package/dist/transform/index.mjs +991 -47
  71. package/dist/transform/props.mjs +19 -14
  72. package/dist/transform/server-fns.mjs +19 -14
  73. package/dist/transform/styles.cjs +606 -0
  74. package/dist/transform/styles.d.cts +237 -0
  75. package/dist/transform/styles.d.ts +238 -0
  76. package/dist/transform/styles.d.ts.map +1 -0
  77. package/dist/transform/styles.js +743 -0
  78. package/dist/transform/styles.mjs +671 -0
  79. package/dist/transform/templates.cjs +972 -32
  80. package/dist/transform/templates.d.cts +13 -0
  81. package/dist/transform/templates.d.ts +13 -0
  82. package/dist/transform/templates.d.ts.map +1 -1
  83. package/dist/transform/templates.js +49 -12
  84. package/dist/transform/templates.mjs +990 -46
  85. package/dist/{transform-QWWQDCXE.mjs → transform-P4AETYV4.mjs} +49 -16
  86. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  87. package/dist/vite-styles.cjs +223 -0
  88. package/dist/vite-styles.d.cts +68 -0
  89. package/dist/vite-styles.d.ts +69 -0
  90. package/dist/vite-styles.d.ts.map +1 -0
  91. package/dist/vite-styles.js +241 -0
  92. package/dist/vite-styles.mjs +214 -0
  93. package/package.json +5 -4
@@ -1,7 +1,7 @@
1
1
  // src/transform/templates.ts
2
2
  import { parse as parse2 } from "@babel/parser";
3
3
 
4
- // ../../node_modules/.pnpm/@jridgewell+sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
4
+ // ../../node_modules/.pnpm/@jridgewell+sourcemap-codec@1.6.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
5
5
  var comma = ",".charCodeAt(0);
6
6
  var semicolon = ";".charCodeAt(0);
7
7
  var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -12,16 +12,16 @@ for (let i = 0; i < chars.length; i++) {
12
12
  intToChar[i] = c;
13
13
  charToInt[c] = i;
14
14
  }
15
- function encodeInteger(builder, num, relative) {
16
- let delta = num - relative;
17
- delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
15
+ function encodeInteger(builder, num) {
18
16
  do {
19
- let clamped = delta & 31;
20
- delta >>>= 5;
21
- if (delta > 0) clamped |= 32;
17
+ let clamped = num & 31;
18
+ num >>>= 5;
19
+ if (num > 0) clamped |= 32;
22
20
  builder.write(intToChar[clamped]);
23
- } while (delta > 0);
24
- return num;
21
+ } while (num > 0);
22
+ }
23
+ function encodeSign(num) {
24
+ return num < 0 ? -num << 1 | 1 : num << 1;
25
25
  }
26
26
  var bufLength = 1024 * 16;
27
27
  var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? {
@@ -71,13 +71,18 @@ function encode(decoded) {
71
71
  for (let j = 0; j < line.length; j++) {
72
72
  const segment = line[j];
73
73
  if (j > 0) writer.write(comma);
74
- genColumn = encodeInteger(writer, segment[0], genColumn);
74
+ encodeInteger(writer, encodeSign(segment[0] - genColumn));
75
+ genColumn = segment[0];
75
76
  if (segment.length === 1) continue;
76
- sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
77
- sourceLine = encodeInteger(writer, segment[2], sourceLine);
78
- sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
77
+ encodeInteger(writer, encodeSign(segment[1] - sourcesIndex));
78
+ encodeInteger(writer, encodeSign(segment[2] - sourceLine));
79
+ encodeInteger(writer, encodeSign(segment[3] - sourceColumn));
80
+ sourcesIndex = segment[1];
81
+ sourceLine = segment[2];
82
+ sourceColumn = segment[3];
79
83
  if (segment.length === 4) continue;
80
- namesIndex = encodeInteger(writer, segment[4], namesIndex);
84
+ encodeInteger(writer, encodeSign(segment[4] - namesIndex));
85
+ namesIndex = segment[4];
81
86
  }
82
87
  }
83
88
  return writer.flush();
@@ -1074,6 +1079,579 @@ var MagicString = class _MagicString {
1074
1079
  }
1075
1080
  };
1076
1081
 
1082
+ // src/transform/styles.ts
1083
+ var SCOPE_ATTR = "data-fx-s";
1084
+ var FUNCTIONS = /* @__PURE__ */ new Set(["FunctionDeclaration", "FunctionExpression", "ArrowFunctionExpression", "ObjectMethod", "ClassMethod"]);
1085
+ function collectStyles(program, sourceName, options, tags = { html: /* @__PURE__ */ new Map([["html", "html"]]) }, module) {
1086
+ const plan = {
1087
+ scopes: [],
1088
+ templateOwners: /* @__PURE__ */ new Map(),
1089
+ drop: /* @__PURE__ */ new Set(),
1090
+ styles: [],
1091
+ diagnostics: [],
1092
+ edits: [],
1093
+ literals: [],
1094
+ references: [],
1095
+ shadowClasses: /* @__PURE__ */ new Map()
1096
+ };
1097
+ if (!options) return plan;
1098
+ const literalsOf = findLiterals(program, options.cssModules ?? ["@fluixi/core", "@fluixi/dom"], plan, tags.css ?? []);
1099
+ plan.names = literalsOf;
1100
+ const classOf = /* @__PURE__ */ new Map();
1101
+ const shadowOf = (owner) => {
1102
+ const cls = classOf.get(owner);
1103
+ return cls ? plan.shadowClasses.get(cls) : void 0;
1104
+ };
1105
+ const resolved = /* @__PURE__ */ new Map();
1106
+ const piecesToNodes = (quasis, expressions, at, stack) => {
1107
+ const out = [];
1108
+ for (let i = 0; i < quasis.length; i++) {
1109
+ const text = quasis[i].value.cooked ?? quasis[i].value.raw;
1110
+ if (text.trim()) {
1111
+ try {
1112
+ const start = quasis[i].loc?.start;
1113
+ out.push(...options.process(text, sourceName).map((n2) => start ? shiftLoc(n2, sourceName, start) : n2));
1114
+ } catch (error) {
1115
+ plan.diagnostics.push({ ...at, message: `CSS could not be processed: ${error.message}` });
1116
+ return null;
1117
+ }
1118
+ }
1119
+ const expr = expressions[i];
1120
+ if (!expr) continue;
1121
+ const value = expr.type === "Identifier" ? resolveLiteral(expr.name, at, stack) : void 0;
1122
+ if (value === void 0) {
1123
+ plan.diagnostics.push({
1124
+ ...at,
1125
+ message: "Only css`` values can be interpolated into styles, and only by name: ${base}. Dynamic values go through custom properties (style:--x={...} and var(--x))."
1126
+ });
1127
+ return null;
1128
+ }
1129
+ if (value === null) return null;
1130
+ out.push(...value);
1131
+ }
1132
+ return out;
1133
+ };
1134
+ function resolveLiteral(name, at, stack) {
1135
+ const imported = literalsOf.imports.get(name);
1136
+ if (imported) {
1137
+ const nodes = options?.imported?.get(`${imported.source}#${imported.name}`);
1138
+ if (nodes) return nodes.map((n2) => keepLocIn(n2, options?.importedModules));
1139
+ plan.references.push({ name: imported.name, source: imported.source, ...at });
1140
+ plan.diagnostics.push({
1141
+ ...at,
1142
+ message: options?.imported ? `${name} from ${imported.source} is not a css\`\` value the build could find.` : `${name} comes from ${imported.source}: style values from another module are resolved by the build.`
1143
+ });
1144
+ return null;
1145
+ }
1146
+ const literal = literalsOf.literals.get(name);
1147
+ if (!literal) return void 0;
1148
+ if (stack.includes(name)) {
1149
+ plan.diagnostics.push({ ...at, message: `css\`\` values include each other: ${[...stack, name].join(" → ")}.` });
1150
+ return null;
1151
+ }
1152
+ if (!resolved.has(name)) {
1153
+ resolved.set(name, piecesToNodes(literal.quasi.quasis, literal.quasi.expressions, at, [...stack, name]));
1154
+ }
1155
+ return resolved.get(name);
1156
+ }
1157
+ for (const [name, literal] of literalsOf.literals) {
1158
+ const at = { line: literal.loc?.start.line ?? 0, column: literal.loc?.start.column ?? 0 };
1159
+ const nodes = resolveLiteral(name, at, []);
1160
+ const id = hash(`${sourceName}:css:${name}`);
1161
+ plan.edits.push({ start: literal.start, end: literal.end, code: `({ $fxStyle: ${JSON.stringify(id)} })` });
1162
+ if (nodes) plan.literals.push({ id, name, css: printStyle(nodes, options.minify), nodes });
1163
+ }
1164
+ const scopeOf = /* @__PURE__ */ new Map();
1165
+ const names = /* @__PURE__ */ new Map();
1166
+ const named = /* @__PURE__ */ new Map();
1167
+ const visit = (node, owners) => {
1168
+ if (!node || typeof node !== "object") return;
1169
+ if (node.type === "VariableDeclarator" && node.id.type === "Identifier" && node.init && FUNCTIONS.has(node.init.type)) {
1170
+ named.set(node.init, node.id.name);
1171
+ }
1172
+ if ((node.type === "ClassDeclaration" || node.type === "ClassExpression") && node.id) {
1173
+ for (const member of node.body.body) if (member.type === "ClassMethod") named.set(member, node.id.name);
1174
+ }
1175
+ if (node.type === "ClassDeclaration" || node.type === "ClassExpression") {
1176
+ for (const member of node.body.body) if (member.type === "ClassMethod") classOf.set(member, node);
1177
+ const shadow = staticMember(node, "shadow");
1178
+ if (shadow?.value && !(shadow.value.type === "BooleanLiteral" && shadow.value.value === false)) {
1179
+ plan.shadowClasses.set(node, { node, styles: staticMember(node, "styles"), indexes: [] });
1180
+ }
1181
+ }
1182
+ if (node.type === "TaggedTemplateExpression" && node.tag.type === "Identifier" && tags.html.get(node.tag.name) === "html") {
1183
+ const text = node.quasi.quasis.map((q) => q.value.raw).join("");
1184
+ if (/<style[\s>]/.test(text)) {
1185
+ const at = { line: node.loc?.start.line ?? 0, column: node.loc?.start.column ?? 0 };
1186
+ const owner = owners[0];
1187
+ if (!owner) plan.diagnostics.push({ ...at, message: "<style> has to be written inside a component." });
1188
+ else {
1189
+ const id = idFor(owner);
1190
+ const shadow = shadowOf(owner);
1191
+ plan.templateOwners.set(node.start, { id, component: functionName(owner, named) });
1192
+ for (const block of templateBlocks(node.quasi)) compileBlock(block, block.scoped, owner, at);
1193
+ }
1194
+ }
1195
+ }
1196
+ const inner = FUNCTIONS.has(node.type) ? [...owners, node] : owners;
1197
+ if (node.type === "JSXElement" && isStyle(node)) {
1198
+ handle(node, owners);
1199
+ return;
1200
+ }
1201
+ for (const key of Object.keys(node)) {
1202
+ if (key === "loc" || key === "leadingComments" || key === "trailingComments" || key === "innerComments") continue;
1203
+ const value = node[key];
1204
+ if (Array.isArray(value)) for (const v of value) visit(v, inner);
1205
+ else if (value && typeof value === "object" && "type" in value) visit(value, inner);
1206
+ }
1207
+ };
1208
+ const handle = (node, owners) => {
1209
+ const at = { line: node.loc?.start.line ?? 0, column: node.loc?.start.column ?? 0 };
1210
+ const pieces = blockPieces(node);
1211
+ if (pieces === null) {
1212
+ plan.diagnostics.push({
1213
+ ...at,
1214
+ message: "<style> needs its CSS as one template literal, <style>{`...`}</style>: JSX reads a bare `{` as an expression."
1215
+ });
1216
+ return;
1217
+ }
1218
+ const owner = owners[0];
1219
+ if (!owner) {
1220
+ plan.diagnostics.push({ ...at, message: "<style> has to be written inside a component." });
1221
+ return;
1222
+ }
1223
+ compileBlock(pieces, isScoped(node), owner, at);
1224
+ plan.drop.add(node.start);
1225
+ };
1226
+ const compileBlock = (pieces, scoped, owner, at) => {
1227
+ const component = functionName(owner, named);
1228
+ const id = idFor(owner);
1229
+ const processed = piecesToNodes(pieces.quasis, pieces.expressions, at, []);
1230
+ if (!processed) return;
1231
+ let nodes = processed;
1232
+ const shadow = shadowOf(owner);
1233
+ if (scoped && !shadow) {
1234
+ if (!plan.scopes.some((s) => s.value === id)) plan.scopes.push({ start: owner.start, end: owner.end, value: id });
1235
+ nodes = scopeNodes(nodes, id, (message) => plan.diagnostics.push({ ...at, message }));
1236
+ }
1237
+ const printed = module ? printStyleWithMap(nodes, options.minify, sourceName, module, options.importedModules) : { css: printStyle(nodes, options.minify) };
1238
+ plan.styles.push({ id, scoped: scoped && !shadow, component, ...printed, ...shadow ? { shadow: true } : {}, ...at });
1239
+ if (shadow) shadow.indexes.push(plan.styles.length - 1);
1240
+ };
1241
+ function idFor(owner) {
1242
+ let id = scopeOf.get(owner);
1243
+ if (!id) {
1244
+ const component = functionName(owner, named);
1245
+ const seen = names.get(component) ?? 0;
1246
+ names.set(component, seen + 1);
1247
+ id = hash(`${sourceName}:${component}${seen ? ":" + seen : ""}`);
1248
+ scopeOf.set(owner, id);
1249
+ }
1250
+ return id;
1251
+ }
1252
+ visit(program, []);
1253
+ return plan;
1254
+ }
1255
+ function applyTemplateStyles(ir, t) {
1256
+ const walk8 = (node) => {
1257
+ const children = node.children;
1258
+ if (children) {
1259
+ for (let i = children.length - 1; i >= 0; i--) {
1260
+ const child = children[i];
1261
+ if (child.kind === "element" && child.tag === "style" && t.owner) children.splice(i, 1);
1262
+ else walk8(child);
1263
+ }
1264
+ }
1265
+ if (t.scope && node.kind === "element" && node.tag !== "style" && node.props && !node.props.some((p) => p.name === SCOPE_ATTR)) {
1266
+ node.props.unshift({ name: SCOPE_ATTR, kind: "attr", literal: t.scope });
1267
+ }
1268
+ };
1269
+ walk8(ir);
1270
+ }
1271
+ function staticMember(cls, name) {
1272
+ return cls.body.body.find(
1273
+ (m) => m.type === "ClassProperty" && m.static && (m.key.type === "Identifier" && m.key.name === name || m.key.type === "StringLiteral" && m.key.value === name)
1274
+ );
1275
+ }
1276
+ var styleIds = {
1277
+ block: (owner, index) => `${owner}.fx-${index}.css`,
1278
+ inline: (owner, index) => `${owner}.fx-${index}.css?inline`,
1279
+ literal: (owner, name) => `${owner}.fx-literal-${name}.css?inline`
1280
+ };
1281
+ function finishShadowStyles(plan, code, moduleId) {
1282
+ const edits = [];
1283
+ const imports = [];
1284
+ let next = 0;
1285
+ const importOf = (specifier) => {
1286
+ const local = `__fxShadow${next++}`;
1287
+ imports.push(`import ${local} from ${JSON.stringify(specifier)};
1288
+ `);
1289
+ return local;
1290
+ };
1291
+ for (const shadow of plan.shadowClasses.values()) {
1292
+ const blocks = shadow.indexes.map((i) => importOf(styleIds.inline(moduleId, i)));
1293
+ let value;
1294
+ const prop = shadow.styles;
1295
+ if (prop?.value) {
1296
+ const start = prop.value.start;
1297
+ let text = code.slice(start, prop.value.end);
1298
+ const replacements = [];
1299
+ walkIdentifiers(prop.value, (id) => {
1300
+ const local = plan.names?.literals.has(id.name) ? importOf(styleIds.literal(moduleId, id.name)) : plan.names?.imports.has(id.name) && !/\.css(\?|$)/.test(plan.names.imports.get(id.name).source) ? importOf(styleIds.literal(plan.names.imports.get(id.name).source, plan.names.imports.get(id.name).name)) : void 0;
1301
+ if (local) replacements.push({ at: id.start - start, length: id.name.length, with: local });
1302
+ });
1303
+ for (const r of replacements.sort((a, b) => b.at - a.at)) text = text.slice(0, r.at) + r.with + text.slice(r.at + r.length);
1304
+ value = text;
1305
+ }
1306
+ if (!blocks.length && value === void 0) continue;
1307
+ if (prop?.value) {
1308
+ const merged = blocks.length ? `[${value}, ${blocks.join(", ")}]` : value;
1309
+ edits.push({ start: prop.value.start, end: prop.value.end, code: merged });
1310
+ } else if (blocks.length) {
1311
+ const open = shadow.node.body.start + 1;
1312
+ edits.push({ start: open, end: open, code: ` static styles = [${blocks.join(", ")}];` });
1313
+ }
1314
+ }
1315
+ if (imports.length) edits.push({ start: 0, end: 0, code: imports.join("") });
1316
+ return edits;
1317
+ }
1318
+ function walkIdentifiers(node, visit) {
1319
+ if (!node || typeof node !== "object") return;
1320
+ if (node.type === "Identifier") return visit(node);
1321
+ if (node.type === "MemberExpression") return walkIdentifiers(node.object, visit);
1322
+ if (node.type === "ObjectProperty") return walkIdentifiers(node.value, visit);
1323
+ for (const key of Object.keys(node)) {
1324
+ if (key === "loc") continue;
1325
+ const value = node[key];
1326
+ if (Array.isArray(value)) for (const v of value) walkIdentifiers(v, visit);
1327
+ else if (value && typeof value === "object" && "type" in value) walkIdentifiers(value, visit);
1328
+ }
1329
+ }
1330
+ function isStyle(node) {
1331
+ const name = node.openingElement.name;
1332
+ return name.type === "JSXIdentifier" && name.name === "style";
1333
+ }
1334
+ function isScoped(node) {
1335
+ return node.openingElement.attributes.some((a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === "scoped");
1336
+ }
1337
+ function templateBlocks(quasi) {
1338
+ const blocks = [];
1339
+ let open = null;
1340
+ quasi.quasis.forEach((q, i) => {
1341
+ const raw = q.value.raw;
1342
+ let from = 0;
1343
+ while (from <= raw.length) {
1344
+ if (!open) {
1345
+ const tag = /<style\b([^>]*)>/g;
1346
+ tag.lastIndex = from;
1347
+ const m = tag.exec(raw);
1348
+ if (!m) break;
1349
+ open = { quasis: [], expressions: [], scoped: /\bscoped\b/.test(m[1]) };
1350
+ from = m.index + m[0].length;
1351
+ }
1352
+ const close = raw.indexOf("</style", from);
1353
+ open.quasis.push(slicePiece(q, raw, from, close === -1 ? raw.length : close));
1354
+ if (close === -1) break;
1355
+ blocks.push(open);
1356
+ open = null;
1357
+ from = close;
1358
+ }
1359
+ const expr = quasi.expressions[i];
1360
+ if (open && expr) open.expressions.push(expr);
1361
+ });
1362
+ return blocks;
1363
+ }
1364
+ function slicePiece(q, raw, from, to) {
1365
+ const text = raw.slice(from, to);
1366
+ const start = q.loc?.start;
1367
+ if (!start) return { type: "TemplateElement", value: { raw: text, cooked: text } };
1368
+ const before = raw.slice(0, from).split("\n");
1369
+ const line = start.line + before.length - 1;
1370
+ const column = before.length > 1 ? before[before.length - 1].length : start.column + from;
1371
+ return { type: "TemplateElement", value: { raw: text, cooked: text }, loc: { start: { line, column } } };
1372
+ }
1373
+ function blockPieces(node) {
1374
+ const meaningful = node.children.filter((c) => !(c.type === "JSXText" && !c.value.trim()));
1375
+ if (meaningful.length === 0) return { quasis: [], expressions: [] };
1376
+ if (meaningful.length !== 1) return null;
1377
+ const only = meaningful[0];
1378
+ if (only.type !== "JSXExpressionContainer") return null;
1379
+ const expr = only.expression;
1380
+ if (expr.type === "StringLiteral") return { quasis: [{ type: "TemplateElement", value: { raw: expr.value, cooked: expr.value } }], expressions: [] };
1381
+ if (expr.type === "TemplateLiteral") return { quasis: expr.quasis, expressions: expr.expressions };
1382
+ return null;
1383
+ }
1384
+ function findLiterals(program, modules, plan, intrinsic) {
1385
+ const literals = /* @__PURE__ */ new Map();
1386
+ const imports = /* @__PURE__ */ new Map();
1387
+ const tags = new Set(intrinsic);
1388
+ for (const statement of program.body ?? []) {
1389
+ if (statement.type !== "ImportDeclaration") continue;
1390
+ const source = statement.source.value;
1391
+ const specifiers = statement.specifiers;
1392
+ for (const sp of specifiers) {
1393
+ if (sp.type === "ImportSpecifier") imports.set(sp.local.name, { source, name: sp.imported.name ?? sp.imported.value });
1394
+ }
1395
+ if (!modules.includes(source)) continue;
1396
+ const css = specifiers.find((sp) => sp.type === "ImportSpecifier" && (sp.imported.name ?? sp.imported.value) === "css");
1397
+ if (!css) continue;
1398
+ const local = css.local.name;
1399
+ tags.add(local);
1400
+ imports.delete(local);
1401
+ plan.edits.push({ start: statement.start, end: statement.end, code: importWithout(statement, css) });
1402
+ }
1403
+ if (tags.size === 0) return { literals, imports };
1404
+ const visit = (node) => {
1405
+ if (!node || typeof node !== "object") return;
1406
+ if (node.type === "VariableDeclarator" && node.id.type === "Identifier" && node.init?.type === "TaggedTemplateExpression" && node.init.tag.type === "Identifier" && tags.has(node.init.tag.name)) {
1407
+ literals.set(node.id.name, node.init);
1408
+ }
1409
+ for (const key of Object.keys(node)) {
1410
+ if (key === "loc") continue;
1411
+ const value = node[key];
1412
+ if (Array.isArray(value)) for (const v of value) visit(v);
1413
+ else if (value && typeof value === "object" && "type" in value) visit(value);
1414
+ }
1415
+ };
1416
+ visit(program);
1417
+ return { literals, imports };
1418
+ }
1419
+ function importWithout(statement, removed) {
1420
+ const rest = statement.specifiers.filter((sp) => sp !== removed);
1421
+ const source = JSON.stringify(statement.source.value);
1422
+ if (rest.length === 0) return "";
1423
+ const def = rest.find((sp) => sp.type === "ImportDefaultSpecifier");
1424
+ const ns = rest.find((sp) => sp.type === "ImportNamespaceSpecifier");
1425
+ const named = rest.filter((sp) => sp.type === "ImportSpecifier").map((sp) => {
1426
+ const imported = sp.imported.name ?? JSON.stringify(sp.imported.value);
1427
+ return imported === sp.local.name ? imported : `${imported} as ${sp.local.name}`;
1428
+ });
1429
+ const parts = [def?.local.name, ns ? `* as ${ns.local.name}` : void 0, named.length ? `{ ${named.join(", ")} }` : void 0].filter(Boolean);
1430
+ return `import ${parts.join(", ")} from ${source};`;
1431
+ }
1432
+ function functionName(fn, named) {
1433
+ if ((fn.type === "FunctionDeclaration" || fn.type === "FunctionExpression") && fn.id) return fn.id.name;
1434
+ return named.get(fn) ?? "anonymous";
1435
+ }
1436
+ function hash(text) {
1437
+ let h = 2166136261;
1438
+ for (let i = 0; i < text.length; i++) {
1439
+ h ^= text.charCodeAt(i);
1440
+ h = Math.imul(h, 16777619);
1441
+ }
1442
+ return (h >>> 0).toString(36);
1443
+ }
1444
+ var OPAQUE = /(^|-)keyframes$|^font-face$|^property$|^counter-style$|^page$|^font-feature-values$/;
1445
+ function scopeNodes(nodes, id, warn = () => {
1446
+ }) {
1447
+ return nodes.map((node) => {
1448
+ if (node.kind === "rule") return { ...node, selector: scopeSelector(node.selector, id, warn) };
1449
+ if (node.kind === "at-rule" && !OPAQUE.test(node.name)) return { ...node, nodes: scopeNodes(node.nodes, id, warn) };
1450
+ return node;
1451
+ });
1452
+ }
1453
+ function scopeSelector(selector, id, warn = () => {
1454
+ }) {
1455
+ return splitTop(selector, ",").map((complex) => scopeComplex(complex.trim(), `[${SCOPE_ATTR}="${id}"]`, warn)).join(", ");
1456
+ }
1457
+ function scopeComplex(selector, attr, warn) {
1458
+ if (/:host\b|::slotted\(/.test(selector)) {
1459
+ warn(`\`${selector}\` only means something in a shadow root; in a light-DOM component it is left as written.`);
1460
+ return selector;
1461
+ }
1462
+ const parts = compounds(selector);
1463
+ const deep = parts.findIndex((p) => p.text.startsWith(":deep("));
1464
+ if (deep !== -1) {
1465
+ const inner = unwrap(parts[deep].text, ":deep(");
1466
+ const before = parts.slice(0, deep);
1467
+ if (before.length === 0) return `${attr} ${inner}`;
1468
+ const scopedBefore = scopeAt(before, before.length - 1, attr);
1469
+ return `${join(scopedBefore)} ${inner}`;
1470
+ }
1471
+ let target = -1;
1472
+ for (let i = parts.length - 1; i >= 0; i--) {
1473
+ if (!parts[i].text.startsWith(":global(")) {
1474
+ target = i;
1475
+ break;
1476
+ }
1477
+ }
1478
+ const out = target === -1 ? parts : scopeAt(parts, target, attr);
1479
+ return join(out.map((p) => p.text.startsWith(":global(") ? { ...p, text: unwrap(p.text, ":global(") } : p));
1480
+ }
1481
+ function scopeAt(parts, index, attr) {
1482
+ return parts.map((p, i) => i === index ? { ...p, text: insertAttr(p.text, attr) } : p);
1483
+ }
1484
+ function insertAttr(compound, attr) {
1485
+ let depth = 0;
1486
+ let quote = "";
1487
+ for (let i = 0; i < compound.length; i++) {
1488
+ const c = compound[i];
1489
+ if (quote) {
1490
+ if (c === "\\") i++;
1491
+ else if (c === quote) quote = "";
1492
+ continue;
1493
+ }
1494
+ if (c === "\\") {
1495
+ i++;
1496
+ continue;
1497
+ }
1498
+ if (c === '"' || c === "'") quote = c;
1499
+ else if (c === "(" || c === "[") depth++;
1500
+ else if (c === ")" || c === "]") depth--;
1501
+ else if (c === ":" && depth === 0 && i > 0) return compound.slice(0, i) + attr + compound.slice(i);
1502
+ }
1503
+ return compound + attr;
1504
+ }
1505
+ function compounds(selector) {
1506
+ const out = [];
1507
+ let depth = 0;
1508
+ let quote = "";
1509
+ let current = "";
1510
+ let combinator = "";
1511
+ const push = () => {
1512
+ if (current.trim()) out.push({ combinator: out.length ? combinator || " " : "", text: current.trim() });
1513
+ current = "";
1514
+ combinator = "";
1515
+ };
1516
+ for (let i = 0; i < selector.length; i++) {
1517
+ const c = selector[i];
1518
+ if (quote) {
1519
+ current += c;
1520
+ if (c === "\\") current += selector[++i] ?? "";
1521
+ else if (c === quote) quote = "";
1522
+ continue;
1523
+ }
1524
+ if (c === "\\") {
1525
+ current += c + (selector[++i] ?? "");
1526
+ continue;
1527
+ }
1528
+ if (c === '"' || c === "'") quote = c;
1529
+ if (c === "(" || c === "[") depth++;
1530
+ if (c === ")" || c === "]") depth--;
1531
+ if (depth === 0 && (c === ">" || c === "+" || c === "~")) {
1532
+ push();
1533
+ combinator = c;
1534
+ continue;
1535
+ }
1536
+ if (depth === 0 && /\s/.test(c)) {
1537
+ if (current.trim()) {
1538
+ const keep = combinator;
1539
+ push();
1540
+ combinator = keep;
1541
+ }
1542
+ continue;
1543
+ }
1544
+ current += c;
1545
+ }
1546
+ push();
1547
+ return out;
1548
+ }
1549
+ function join(parts) {
1550
+ return parts.map((p, i) => i === 0 ? p.text : p.combinator === " " ? ` ${p.text}` : ` ${p.combinator} ${p.text}`).join("");
1551
+ }
1552
+ function unwrap(text, prefix) {
1553
+ return text.slice(prefix.length, text.lastIndexOf(")")).trim() + text.slice(text.lastIndexOf(")") + 1);
1554
+ }
1555
+ function splitTop(selector, separator) {
1556
+ const parts = [];
1557
+ let depth = 0;
1558
+ let quote = "";
1559
+ let start = 0;
1560
+ for (let i = 0; i < selector.length; i++) {
1561
+ const c = selector[i];
1562
+ if (quote) {
1563
+ if (c === "\\") i++;
1564
+ else if (c === quote) quote = "";
1565
+ } else if (c === '"' || c === "'") quote = c;
1566
+ else if (c === "\\") i++;
1567
+ else if (c === "(" || c === "[") depth++;
1568
+ else if (c === ")" || c === "]") depth--;
1569
+ else if (c === separator && depth === 0) {
1570
+ parts.push(selector.slice(start, i));
1571
+ start = i + 1;
1572
+ }
1573
+ }
1574
+ parts.push(selector.slice(start));
1575
+ return parts.filter((p) => p.trim());
1576
+ }
1577
+ function shiftLoc(node, source, start) {
1578
+ const loc = node.loc && node.loc.source === source ? { source, line: start.line + node.loc.line - 1, column: node.loc.line === 1 ? start.column + node.loc.column : node.loc.column } : node.loc;
1579
+ if (node.kind === "rule" || node.kind === "at-rule") return { ...node, loc, nodes: node.nodes.map((n2) => shiftLoc(n2, source, start)) };
1580
+ return { ...node, loc };
1581
+ }
1582
+ function keepLocIn(node, modules) {
1583
+ const keep = node.loc !== void 0 && modules?.has(node.loc.source) === true;
1584
+ const { loc, ...rest } = node;
1585
+ const kept = keep ? { ...rest, loc } : rest;
1586
+ if (kept.kind === "rule" || kept.kind === "at-rule") return { ...kept, nodes: kept.nodes.map((n2) => keepLocIn(n2, modules)) };
1587
+ return kept;
1588
+ }
1589
+ function printStyleWithMap(nodes, minify, sourceName, module, others) {
1590
+ const sources = [module];
1591
+ const index = /* @__PURE__ */ new Map([[sourceName, 0]]);
1592
+ const sourceOf = (name) => {
1593
+ if (index.has(name)) return index.get(name);
1594
+ const other = others?.get(name);
1595
+ if (!other) return void 0;
1596
+ index.set(name, sources.push(other) - 1);
1597
+ return index.get(name);
1598
+ };
1599
+ const lines = [[]];
1600
+ let css = "";
1601
+ let column = 0;
1602
+ const emit = (text) => {
1603
+ for (const ch of text) {
1604
+ css += ch;
1605
+ if (ch === "\n") {
1606
+ lines.push([]);
1607
+ column = 0;
1608
+ } else column++;
1609
+ }
1610
+ };
1611
+ const mark = (loc) => {
1612
+ const at = loc ? sourceOf(loc.source) : void 0;
1613
+ if (loc && at !== void 0) lines[lines.length - 1].push([column, at, loc.line - 1, loc.column]);
1614
+ };
1615
+ const write = (node, depth) => {
1616
+ const pad = minify ? "" : " ".repeat(depth);
1617
+ const nl = minify ? "" : "\n";
1618
+ const sp = minify ? "" : " ";
1619
+ emit(pad);
1620
+ mark(node.loc);
1621
+ if (node.kind === "declaration") {
1622
+ emit(`${node.property}:${sp}${node.value}${node.important ? `${sp}!important` : ""};${nl}`);
1623
+ } else if (node.kind === "raw") {
1624
+ emit(`${node.text}${nl}`);
1625
+ } else {
1626
+ emit(`${node.kind === "rule" ? node.selector : `@${node.name}${node.params ? " " + node.params : ""}`}${sp}{${nl}`);
1627
+ for (const child of node.nodes) write(child, depth + 1);
1628
+ emit(`${pad}}${nl}`);
1629
+ }
1630
+ };
1631
+ for (const node of nodes) write(node, 0);
1632
+ return { css, map: { version: 3, sources: sources.map((s) => s.id), sourcesContent: sources.map((s) => s.code), names: [], mappings: encode(lines) } };
1633
+ }
1634
+ function printStyle(nodes, minify = false) {
1635
+ const out = [];
1636
+ const write = (node, depth) => {
1637
+ const pad = minify ? "" : " ".repeat(depth);
1638
+ const nl = minify ? "" : "\n";
1639
+ const sp = minify ? "" : " ";
1640
+ if (node.kind === "declaration") {
1641
+ out.push(`${pad}${node.property}:${sp}${node.value}${node.important ? `${sp}!important` : ""};${nl}`);
1642
+ } else if (node.kind === "raw") {
1643
+ out.push(`${pad}${node.text}${nl}`);
1644
+ } else {
1645
+ const header = node.kind === "rule" ? node.selector : `@${node.name}${node.params ? " " + node.params : ""}`;
1646
+ out.push(`${pad}${header}${sp}{${nl}`);
1647
+ for (const child of node.nodes) write(child, depth + 1);
1648
+ out.push(`${pad}}${nl}`);
1649
+ }
1650
+ };
1651
+ for (const node of nodes) write(node, 0);
1652
+ return out.join("");
1653
+ }
1654
+
1077
1655
  // src/optimize/analyze-static.ts
1078
1656
  function propReason(prop) {
1079
1657
  switch (prop.kind) {
@@ -1571,6 +2149,16 @@ var PRIMITIVE_MODULES = [
1571
2149
  "@fluixi/reactive/cached-resource",
1572
2150
  "@fluixi/core"
1573
2151
  ];
2152
+ var TAG_INTRINSICS = {
2153
+ $html: { export: "html", module: "@fluixi/core" },
2154
+ $svg: { export: "svg", module: "@fluixi/core" },
2155
+ $css: { export: "css", module: "@fluixi/core" }
2156
+ };
2157
+ function tagIntrinsics(bound) {
2158
+ const tags = /* @__PURE__ */ new Map();
2159
+ for (const [name, tag] of Object.entries(TAG_INTRINSICS)) if (!bound.has(name)) tags.set(name, tag.export);
2160
+ return tags;
2161
+ }
1574
2162
  var INTRINSIC_CALL = new RegExp(`\\$(?:${Object.keys(INTRINSICS).map((n2) => n2.slice(1)).join("|")})\\s*\\(`);
1575
2163
  function mayHaveIntrinsic(code) {
1576
2164
  return INTRINSIC_CALL.test(code);
@@ -2074,7 +2662,7 @@ function emitComponent(name, props, children, used, templates, at) {
2074
2662
  }
2075
2663
  let obj = `{ ${bodies.map(([name2, body]) => `get ${propKey(name2)}() { return ${body}; }`).join(", ")} }`;
2076
2664
  if (bodies.some(([, body]) => /\bthis\b/.test(body))) {
2077
- const thunks = bodies.map(([name2, body]) => `${JSON.stringify(name2)}: () => ${body}`);
2665
+ const thunks = bodies.map(([name2, body]) => `${JSON.stringify(name2)}: () => (${body})`);
2078
2666
  const getters = bodies.map(([name2]) => `get ${propKey(name2)}() { return _$t[${JSON.stringify(name2)}](); }`);
2079
2667
  obj = `((_$t) => ({ ${getters.join(", ")} }))({ ${thunks.join(", ")} })`;
2080
2668
  }
@@ -2275,6 +2863,271 @@ function cleanTemplateText(value) {
2275
2863
  return out;
2276
2864
  }
2277
2865
 
2866
+ // src/lower/entities.ts
2867
+ var NAMED = {
2868
+ quot: 34,
2869
+ amp: 38,
2870
+ apos: 39,
2871
+ lt: 60,
2872
+ gt: 62,
2873
+ nbsp: 160,
2874
+ iexcl: 161,
2875
+ cent: 162,
2876
+ pound: 163,
2877
+ curren: 164,
2878
+ yen: 165,
2879
+ brvbar: 166,
2880
+ sect: 167,
2881
+ uml: 168,
2882
+ copy: 169,
2883
+ ordf: 170,
2884
+ laquo: 171,
2885
+ not: 172,
2886
+ shy: 173,
2887
+ reg: 174,
2888
+ macr: 175,
2889
+ deg: 176,
2890
+ plusmn: 177,
2891
+ sup2: 178,
2892
+ sup3: 179,
2893
+ acute: 180,
2894
+ micro: 181,
2895
+ para: 182,
2896
+ middot: 183,
2897
+ cedil: 184,
2898
+ sup1: 185,
2899
+ ordm: 186,
2900
+ raquo: 187,
2901
+ frac14: 188,
2902
+ frac12: 189,
2903
+ frac34: 190,
2904
+ iquest: 191,
2905
+ Agrave: 192,
2906
+ Aacute: 193,
2907
+ Acirc: 194,
2908
+ Atilde: 195,
2909
+ Auml: 196,
2910
+ Aring: 197,
2911
+ AElig: 198,
2912
+ Ccedil: 199,
2913
+ Egrave: 200,
2914
+ Eacute: 201,
2915
+ Ecirc: 202,
2916
+ Euml: 203,
2917
+ Igrave: 204,
2918
+ Iacute: 205,
2919
+ Icirc: 206,
2920
+ Iuml: 207,
2921
+ ETH: 208,
2922
+ Ntilde: 209,
2923
+ Ograve: 210,
2924
+ Oacute: 211,
2925
+ Ocirc: 212,
2926
+ Otilde: 213,
2927
+ Ouml: 214,
2928
+ times: 215,
2929
+ Oslash: 216,
2930
+ Ugrave: 217,
2931
+ Uacute: 218,
2932
+ Ucirc: 219,
2933
+ Uuml: 220,
2934
+ Yacute: 221,
2935
+ THORN: 222,
2936
+ szlig: 223,
2937
+ agrave: 224,
2938
+ aacute: 225,
2939
+ acirc: 226,
2940
+ atilde: 227,
2941
+ auml: 228,
2942
+ aring: 229,
2943
+ aelig: 230,
2944
+ ccedil: 231,
2945
+ egrave: 232,
2946
+ eacute: 233,
2947
+ ecirc: 234,
2948
+ euml: 235,
2949
+ igrave: 236,
2950
+ iacute: 237,
2951
+ icirc: 238,
2952
+ iuml: 239,
2953
+ eth: 240,
2954
+ ntilde: 241,
2955
+ ograve: 242,
2956
+ oacute: 243,
2957
+ ocirc: 244,
2958
+ otilde: 245,
2959
+ ouml: 246,
2960
+ divide: 247,
2961
+ oslash: 248,
2962
+ ugrave: 249,
2963
+ uacute: 250,
2964
+ ucirc: 251,
2965
+ uuml: 252,
2966
+ yacute: 253,
2967
+ thorn: 254,
2968
+ yuml: 255,
2969
+ OElig: 338,
2970
+ oelig: 339,
2971
+ Scaron: 352,
2972
+ scaron: 353,
2973
+ Yuml: 376,
2974
+ fnof: 402,
2975
+ circ: 710,
2976
+ tilde: 732,
2977
+ Alpha: 913,
2978
+ Beta: 914,
2979
+ Gamma: 915,
2980
+ Delta: 916,
2981
+ Epsilon: 917,
2982
+ Zeta: 918,
2983
+ Eta: 919,
2984
+ Theta: 920,
2985
+ Iota: 921,
2986
+ Kappa: 922,
2987
+ Lambda: 923,
2988
+ Mu: 924,
2989
+ Nu: 925,
2990
+ Xi: 926,
2991
+ Omicron: 927,
2992
+ Pi: 928,
2993
+ Rho: 929,
2994
+ Sigma: 931,
2995
+ Tau: 932,
2996
+ Upsilon: 933,
2997
+ Phi: 934,
2998
+ Chi: 935,
2999
+ Psi: 936,
3000
+ Omega: 937,
3001
+ alpha: 945,
3002
+ beta: 946,
3003
+ gamma: 947,
3004
+ delta: 948,
3005
+ epsilon: 949,
3006
+ zeta: 950,
3007
+ eta: 951,
3008
+ theta: 952,
3009
+ iota: 953,
3010
+ kappa: 954,
3011
+ lambda: 955,
3012
+ mu: 956,
3013
+ nu: 957,
3014
+ xi: 958,
3015
+ omicron: 959,
3016
+ pi: 960,
3017
+ rho: 961,
3018
+ sigmaf: 962,
3019
+ sigma: 963,
3020
+ tau: 964,
3021
+ upsilon: 965,
3022
+ phi: 966,
3023
+ chi: 967,
3024
+ psi: 968,
3025
+ omega: 969,
3026
+ thetasym: 977,
3027
+ upsih: 978,
3028
+ piv: 982,
3029
+ ensp: 8194,
3030
+ emsp: 8195,
3031
+ thinsp: 8201,
3032
+ zwnj: 8204,
3033
+ zwj: 8205,
3034
+ lrm: 8206,
3035
+ rlm: 8207,
3036
+ ndash: 8211,
3037
+ mdash: 8212,
3038
+ lsquo: 8216,
3039
+ rsquo: 8217,
3040
+ sbquo: 8218,
3041
+ ldquo: 8220,
3042
+ rdquo: 8221,
3043
+ bdquo: 8222,
3044
+ dagger: 8224,
3045
+ Dagger: 8225,
3046
+ bull: 8226,
3047
+ hellip: 8230,
3048
+ permil: 8240,
3049
+ prime: 8242,
3050
+ Prime: 8243,
3051
+ lsaquo: 8249,
3052
+ rsaquo: 8250,
3053
+ oline: 8254,
3054
+ frasl: 8260,
3055
+ euro: 8364,
3056
+ image: 8465,
3057
+ weierp: 8472,
3058
+ real: 8476,
3059
+ trade: 8482,
3060
+ alefsym: 8501,
3061
+ larr: 8592,
3062
+ uarr: 8593,
3063
+ rarr: 8594,
3064
+ darr: 8595,
3065
+ harr: 8596,
3066
+ crarr: 8629,
3067
+ lArr: 8656,
3068
+ uArr: 8657,
3069
+ rArr: 8658,
3070
+ dArr: 8659,
3071
+ hArr: 8660,
3072
+ forall: 8704,
3073
+ part: 8706,
3074
+ exist: 8707,
3075
+ empty: 8709,
3076
+ nabla: 8711,
3077
+ isin: 8712,
3078
+ notin: 8713,
3079
+ ni: 8715,
3080
+ prod: 8719,
3081
+ sum: 8721,
3082
+ minus: 8722,
3083
+ lowast: 8727,
3084
+ radic: 8730,
3085
+ prop: 8733,
3086
+ infin: 8734,
3087
+ ang: 8736,
3088
+ and: 8743,
3089
+ or: 8744,
3090
+ cap: 8745,
3091
+ cup: 8746,
3092
+ int: 8747,
3093
+ there4: 8756,
3094
+ sim: 8764,
3095
+ cong: 8773,
3096
+ asymp: 8776,
3097
+ ne: 8800,
3098
+ equiv: 8801,
3099
+ le: 8804,
3100
+ ge: 8805,
3101
+ sub: 8834,
3102
+ sup: 8835,
3103
+ nsub: 8836,
3104
+ sube: 8838,
3105
+ supe: 8839,
3106
+ oplus: 8853,
3107
+ otimes: 8855,
3108
+ perp: 8869,
3109
+ sdot: 8901,
3110
+ lceil: 8968,
3111
+ rceil: 8969,
3112
+ lfloor: 8970,
3113
+ rfloor: 8971,
3114
+ lang: 9001,
3115
+ rang: 9002,
3116
+ loz: 9674,
3117
+ spades: 9824,
3118
+ clubs: 9827,
3119
+ hearts: 9829,
3120
+ diams: 9830
3121
+ };
3122
+ var REFERENCE = /&(?:#[xX]([0-9a-fA-F]{1,6})|#([0-9]{1,7})|([a-zA-Z][a-zA-Z0-9]{1,31}));/g;
3123
+ function decodeEntities(value) {
3124
+ if (!value.includes("&")) return value;
3125
+ return value.replace(REFERENCE, (match, hex, dec, name) => {
3126
+ const code = hex ? parseInt(hex, 16) : dec ? parseInt(dec, 10) : Object.prototype.hasOwnProperty.call(NAMED, name) ? NAMED[name] : void 0;
3127
+ return code !== void 0 && code <= 1114111 ? String.fromCodePoint(code) : match;
3128
+ });
3129
+ }
3130
+
2278
3131
  // src/lower/template.ts
2279
3132
  var DELEGATED = /* @__PURE__ */ new Set([
2280
3133
  "click",
@@ -2361,7 +3214,7 @@ var Lowerer = class {
2361
3214
  switch (node.kind) {
2362
3215
  case "Text": {
2363
3216
  if (node.raw) return { kind: "text", value: node.value };
2364
- const cleaned = cleanTemplateText(node.value);
3217
+ const cleaned = decodeEntities(cleanTemplateText(node.value));
2365
3218
  return cleaned ? { kind: "text", value: cleaned } : null;
2366
3219
  }
2367
3220
  case "Comment":
@@ -2397,7 +3250,7 @@ var Lowerer = class {
2397
3250
  kind: "element",
2398
3251
  tag: el.tag,
2399
3252
  svg: el.namespace === "svg",
2400
- props: this.lowerAttributes(el.attributes),
3253
+ props: this.lowerAttributes(el.attributes, true),
2401
3254
  children,
2402
3255
  static: false,
2403
3256
  ...at ? { at } : {}
@@ -2510,13 +3363,22 @@ var Lowerer = class {
2510
3363
  return clone.kind === "Element" ? this.lowerElement(clone) : this.lowerComponent(clone);
2511
3364
  }
2512
3365
  // --- attributes ---------------------------------------------------------
2513
- lowerAttributes(attrs) {
3366
+ /**
3367
+ * `element`: a DOM element, where each class:/style: value that moves is its own accessor.
3368
+ * A component gets the object as before, rebuilt whole when any value moves.
3369
+ */
3370
+ lowerAttributes(attrs, element = false) {
3371
+ let anyReactive = false;
3372
+ const entry = (name, h) => {
3373
+ anyReactive ||= h.reactive;
3374
+ if (!element || !h.reactive) return `${JSON.stringify(name)}: ${h.code}`;
3375
+ const accessor = `() => ${paren(h.code, "arrowBody")}`;
3376
+ return `${JSON.stringify(name)}: ${h.at ? markHole(accessor, h.at.line, h.at.column) : accessor}`;
3377
+ };
2514
3378
  const props = [];
2515
3379
  const classEntries = [];
2516
- let classReactive = false;
2517
3380
  let classAt;
2518
3381
  const styleEntries = [];
2519
- let styleReactive = false;
2520
3382
  let styleAt;
2521
3383
  const usePairs = [];
2522
3384
  for (const a of attrs) {
@@ -2556,15 +3418,13 @@ var Lowerer = class {
2556
3418
  break;
2557
3419
  case "ClassDirective": {
2558
3420
  const h = this.hole(a.hole);
2559
- classEntries.push(`${JSON.stringify(a.name)}: ${h.code}`);
2560
- classReactive = classReactive || h.reactive;
3421
+ classEntries.push(entry(a.name, h));
2561
3422
  classAt ??= h.at;
2562
3423
  break;
2563
3424
  }
2564
3425
  case "StyleDirective": {
2565
3426
  const h = this.hole(a.hole);
2566
- styleEntries.push(`${JSON.stringify(a.name)}: ${h.code}`);
2567
- styleReactive = styleReactive || h.reactive;
3427
+ styleEntries.push(entry(a.name, h));
2568
3428
  styleAt ??= h.at;
2569
3429
  break;
2570
3430
  }
@@ -2584,18 +3444,19 @@ var Lowerer = class {
2584
3444
  name: "classList",
2585
3445
  kind: "attr",
2586
3446
  expr: `{ ${classEntries.join(", ")} }`,
2587
- reactive: classReactive,
3447
+ reactive: !element && anyReactive,
2588
3448
  ...classAt ? { at: classAt } : {}
2589
3449
  });
2590
3450
  }
2591
3451
  if (styleEntries.length > 0) {
2592
- props.push({
2593
- name: "style",
2594
- kind: "attr",
2595
- expr: `{ ${styleEntries.join(", ")} }`,
2596
- reactive: styleReactive,
2597
- ...styleAt ? { at: styleAt } : {}
2598
- });
3452
+ const entries = `{ ${styleEntries.join(", ")} }`;
3453
+ const base = props.findIndex((p) => p.name === "style");
3454
+ if (base === -1) props.push({ name: "style", kind: "attr", expr: entries, reactive: !element && anyReactive, ...styleAt ? { at: styleAt } : {} });
3455
+ else {
3456
+ const prop = props[base];
3457
+ const value = prop.expr === void 0 ? JSON.stringify(prop.literal) : prop.reactive ? `() => ${paren(prop.expr, "arrowBody")}` : prop.expr;
3458
+ props[base] = { name: "style", kind: "attr", expr: `[${value}, ${entries}]`, reactive: false, ...prop.at ? { at: prop.at } : {} };
3459
+ }
2599
3460
  }
2600
3461
  if (usePairs.length > 0) {
2601
3462
  props.push({ name: "use", kind: "attr", expr: `[${usePairs.join(", ")}]` });
@@ -2684,7 +3545,7 @@ var Lowerer = class {
2684
3545
  return base;
2685
3546
  }
2686
3547
  if (v.kind === "static") {
2687
- base.literal = v.value;
3548
+ base.literal = decodeEntities(v.value);
2688
3549
  return base;
2689
3550
  }
2690
3551
  if (v.kind === "hole") {
@@ -2697,7 +3558,7 @@ var Lowerer = class {
2697
3558
  let reactive = false;
2698
3559
  let at;
2699
3560
  const body = v.parts.map((p) => {
2700
- if ("text" in p) return escapeTemplate(p.text);
3561
+ if ("text" in p) return escapeTemplate(decodeEntities(p.text));
2701
3562
  const h = this.hole(p.hole);
2702
3563
  reactive = reactive || h.reactive;
2703
3564
  at ??= h.at;
@@ -2722,6 +3583,7 @@ function compilePieces(pieces, holes, options = {}) {
2722
3583
  ...options.sourceFile ? { sourceFile: options.sourceFile } : {},
2723
3584
  ...options.positionAt ? { positionAt: options.positionAt } : {}
2724
3585
  });
3586
+ if (options.templateStyles) applyTemplateStyles(ir, options.templateStyles);
2725
3587
  analyzeStatic(ir);
2726
3588
  resolveComponentSources(ir, {
2727
3589
  resolver: createComponentResolver(options.resolve ?? []),
@@ -2920,9 +3782,12 @@ function attrExprCode(attr, ctx) {
2920
3782
  }
2921
3783
  return null;
2922
3784
  }
2923
- function buildProps(attrs, ctx) {
3785
+ function buildProps(attrs, ctx, element = false) {
2924
3786
  const props = [];
2925
3787
  const usePairs = [];
3788
+ const classEntries = [];
3789
+ const styleEntries = [];
3790
+ let styleAt;
2926
3791
  for (const a of attrs) {
2927
3792
  if (a.type === "JSXSpreadAttribute") {
2928
3793
  props.push({ name: "", kind: "spread", expr: ctx.code(a.argument) });
@@ -2938,6 +3803,27 @@ function buildProps(attrs, ctx) {
2938
3803
  usePairs.push(opts != null ? `[${dir}, () => ${paren(opts, "arrowBody")}]` : `[${dir}]`);
2939
3804
  continue;
2940
3805
  }
3806
+ if (element && (ns === "class" || ns === "style")) {
3807
+ const key = JSON.stringify(a.name.name.name);
3808
+ const v = a.value;
3809
+ let value;
3810
+ if (v == null) value = "true";
3811
+ else if (isString(v)) value = JSON.stringify(literalOf(v));
3812
+ else if (v.type === "JSXExpressionContainer" && v.expression?.type !== "JSXEmptyExpression") {
3813
+ value = keyValue(v.expression, ctx);
3814
+ if (ns === "style") styleAt ??= posOf(v.expression, ctx);
3815
+ } else continue;
3816
+ (ns === "class" ? classEntries : styleEntries).push(`${key}: ${value}`);
3817
+ continue;
3818
+ }
3819
+ if (element && a.name.type === "JSXIdentifier" && a.name.name === "style" && a.value?.type === "JSXExpressionContainer") {
3820
+ const entries = objectEntries(a.value.expression, ctx);
3821
+ if (entries) {
3822
+ styleEntries.unshift(...entries);
3823
+ styleAt = posOf(a.value.expression, ctx);
3824
+ continue;
3825
+ }
3826
+ }
2941
3827
  if (ns === "oncapture") {
2942
3828
  const evt = a.name.name.name.toLowerCase();
2943
3829
  const h = attrExprCode(a, ctx) ?? "undefined";
@@ -2946,9 +3832,37 @@ function buildProps(attrs, ctx) {
2946
3832
  }
2947
3833
  props.push(buildAttr(a, ctx));
2948
3834
  }
3835
+ if (classEntries.length > 0) props.push({ name: "classList", kind: "attr", expr: `{ ${classEntries.join(", ")} }`, reactive: false });
3836
+ if (styleEntries.length > 0) {
3837
+ const entries = `{ ${styleEntries.join(", ")} }`;
3838
+ const base = props.findIndex((p) => p.name === "style" && p.kind === "attr");
3839
+ if (base === -1) props.push({ name: "style", kind: "attr", expr: entries, reactive: false, ...styleAt ? { at: styleAt } : {} });
3840
+ else {
3841
+ const prop = props[base];
3842
+ const value = prop.literal !== void 0 ? JSON.stringify(prop.literal) : prop.reactive ? `() => ${paren(prop.expr, "arrowBody")}` : prop.expr;
3843
+ props[base] = { name: "style", kind: "attr", expr: `[${value}, ${entries}]`, reactive: false, ...prop.at ? { at: prop.at } : {} };
3844
+ }
3845
+ }
2949
3846
  if (usePairs.length > 0) props.push({ name: "use", kind: "attr", expr: `[${usePairs.join(", ")}]` });
2950
3847
  return props;
2951
3848
  }
3849
+ function keyValue(expr, ctx) {
3850
+ const code = ctx.code(expr);
3851
+ if (!isReactive(expr)) return code;
3852
+ const accessor = `() => ${paren(code, "arrowBody")}`;
3853
+ const at = posOf(expr, ctx);
3854
+ return at ? markHole(accessor, at.line, at.column) : accessor;
3855
+ }
3856
+ function objectEntries(expr, ctx) {
3857
+ if (expr?.type !== "ObjectExpression") return null;
3858
+ const entries = [];
3859
+ for (const p of expr.properties) {
3860
+ if (p.type !== "ObjectProperty") return null;
3861
+ const key = p.computed ? `[${ctx.code(p.key)}]` : p.key.type === "Identifier" ? JSON.stringify(p.key.name) : JSON.stringify(String(p.key.value));
3862
+ entries.push(`${key}: ${keyValue(p.value, ctx)}`);
3863
+ }
3864
+ return entries;
3865
+ }
2952
3866
  function buildChildren(children, ctx) {
2953
3867
  const out = [];
2954
3868
  for (let i = 0; i < children.length; i++) {
@@ -2976,6 +3890,7 @@ function buildChildren(children, ctx) {
2976
3890
  });
2977
3891
  }
2978
3892
  } else if (child.type === "JSXElement" || child.type === "JSXFragment") {
3893
+ if (ctx.dropStyles?.has(child.start)) continue;
2979
3894
  out.push(buildNode(child, ctx));
2980
3895
  } else if (child.type === "JSXSpreadChild") {
2981
3896
  out.push({ kind: "expr", code: ctx.code(child.expression), reactive: false });
@@ -3045,13 +3960,17 @@ function buildElement(node, ctx, handled) {
3045
3960
  const children = each ? [each] : buildChildren(node.children, ctx);
3046
3961
  if (tag === CONTAINER2) return children.length === 1 ? children[0] : { kind: "fragment", children };
3047
3962
  const at = ctx.sourceFile && node.loc?.start ? { file: ctx.sourceFile, line: node.loc.start.line, column: node.loc.start.column } : void 0;
3048
- return { kind: "element", tag, svg: SVG_TAGS.has(tag), props: buildProps(attributes, ctx), children, static: false, ...at ? { at } : {} };
3963
+ const props = buildProps(attributes, ctx, true);
3964
+ const scope = ctx.scopes?.find((s) => node.start >= s.start && node.end <= s.end);
3965
+ if (scope) props.unshift({ name: "data-fx-s", kind: "attr", literal: scope.value });
3966
+ return { kind: "element", tag, svg: SVG_TAGS.has(tag), props, children, static: false, ...at ? { at } : {} };
3049
3967
  }
3050
3968
  function buildNode(node, ctx) {
3051
3969
  if (node.type === "JSXFragment") {
3052
3970
  return { kind: "fragment", children: buildChildren(node.children, ctx) };
3053
3971
  }
3054
3972
  if (directive(node, "if")) return buildIf(node, null, ctx);
3973
+ if (ctx.dropStyles?.has(node.start)) return { kind: "fragment", children: [] };
3055
3974
  const { tag, component } = tagInfo(node.openingElement.name, ctx);
3056
3975
  if (!component) return buildElement(node, ctx, []);
3057
3976
  const props = buildProps(node.openingElement.attributes, ctx);
@@ -3556,8 +4475,8 @@ function isJsxRoot(node, parent, key) {
3556
4475
  if (!isJsx(node)) return false;
3557
4476
  return !(parent && isJsx(parent) && key === "children");
3558
4477
  }
3559
- function isTemplateTag(node, litTag) {
3560
- return node.type === "TaggedTemplateExpression" && node.tag?.type === "Identifier" && (node.tag.name === litTag || node.tag.name === "svg");
4478
+ function isTemplateTag(node, tags) {
4479
+ return node.type === "TaggedTemplateExpression" && node.tag?.type === "Identifier" && tags.has(node.tag.name);
3561
4480
  }
3562
4481
  function outermost(list) {
3563
4482
  return list.filter(
@@ -3705,22 +4624,28 @@ function transformTemplates(code, id, options = {}) {
3705
4624
  const wantsIntrinsics = options.intrinsics !== false && mayHaveIntrinsic(code);
3706
4625
  const wantsSources = options.sourceLocations === true && mayHaveSourceMarks(code);
3707
4626
  const sourceName = relativeToRoot(id, options.sourceRoot);
3708
- if (!mayHaveTemplate && !(wantsJsx && code.includes("<")) && !wantsIntrinsics && !wantsSources) return null;
4627
+ const wantsStyles = options.styles !== void 0 && (code.includes("<style") || code.includes("css`"));
4628
+ if (!mayHaveTemplate && !(wantsJsx && code.includes("<")) && !wantsIntrinsics && !wantsSources && !wantsStyles) return null;
3709
4629
  const ast = parse2(code, {
3710
4630
  sourceType: "module",
3711
4631
  plugins: ["jsx", "typescript"],
3712
4632
  errorRecovery: true
3713
4633
  });
4634
+ const intrinsicTags = options.intrinsics === false ? /* @__PURE__ */ new Map() : tagIntrinsics(moduleBindings(ast.program));
4635
+ const templateTags = /* @__PURE__ */ new Map([[litTag, "html"], ["svg", "svg"]]);
4636
+ for (const [name, tag] of intrinsicTags) if (tag !== "css") templateTags.set(name, tag);
4637
+ const cssTags = [...intrinsicTags].filter(([, tag]) => tag === "css").map(([name]) => name);
3714
4638
  const found = [];
3715
4639
  walk7(ast.program, (n2, parent, key) => {
3716
- if (wantsLit && isTemplateTag(n2, litTag)) found.push(n2);
4640
+ if (wantsLit && isTemplateTag(n2, templateTags)) found.push(n2);
3717
4641
  else if (wantsJsx && isJsxRoot(n2, parent, key)) found.push(n2);
3718
4642
  });
3719
4643
  const props = options.propsDestructure === false ? { edits: [], diagnostics: [], used: /* @__PURE__ */ new Set() } : collectPropsEdits(ast.program, code, { runtimeModule: options.runtimeModule });
3720
4644
  const intrinsics = options.intrinsics === false ? { edits: [], diagnostics: [], imports: /* @__PURE__ */ new Map() } : collectIntrinsicEdits(ast.program);
3721
4645
  if (intrinsics.edits.length) avoidBindingClashes(ast.program, intrinsics, moduleBindings(ast.program));
3722
4646
  const sources = options.sourceLocations === true ? collectSourceEdits(ast.program, sourceName) : { edits: [], marked: 0 };
3723
- const silent = found.length === 0 && props.edits.length === 0 && sources.edits.length === 0 && intrinsics.edits.length === 0 && intrinsics.diagnostics.length === 0 && props.diagnostics.length === 0;
4647
+ const styles = wantsStyles ? collectStyles(ast.program, sourceName, options.styles, { html: templateTags, css: cssTags }, { id, code }) : void 0;
4648
+ const silent = found.length === 0 && props.edits.length === 0 && sources.edits.length === 0 && intrinsics.edits.length === 0 && intrinsics.diagnostics.length === 0 && props.diagnostics.length === 0 && !styles?.edits.length && !styles?.diagnostics.length;
3724
4649
  if (silent) return null;
3725
4650
  found.sort((a, b) => b.start - a.start || a.end - b.end);
3726
4651
  const used = new Set(props.used);
@@ -3734,20 +4659,32 @@ function transformTemplates(code, id, options = {}) {
3734
4659
  declared: declaredNames(ast.program)
3735
4660
  };
3736
4661
  const hoisted = /* @__PURE__ */ new Map();
3737
- const edits = [...props.edits, ...intrinsics.edits, ...sources.edits];
4662
+ const edits = [...props.edits, ...intrinsics.edits, ...sources.edits, ...styles?.edits ?? []];
3738
4663
  for (const node of found) {
3739
4664
  const nested = found.some(
3740
4665
  (o) => o !== node && o.start <= node.start && o.end >= node.end && o.end - o.start > node.end - node.start
3741
4666
  );
3742
4667
  if (isJsx(node)) {
3743
- edits.push({ start: node.start, end: node.end, code: compileJsx(code, node, edits, nested, used, needs, hoisted, options, sourceName) });
4668
+ edits.push({ start: node.start, end: node.end, code: compileJsx(code, node, edits, nested, used, needs, hoisted, options, sourceName, styles) });
3744
4669
  continue;
3745
4670
  }
3746
4671
  const holes = node.quasi.expressions.map(
3747
4672
  (e) => bindHole(code, e, edits, options.sourceLocations === true)
3748
4673
  );
4674
+ const scope = styles?.scopes.find((s) => node.start >= s.start && node.end <= s.end)?.value;
4675
+ const owner = styles?.templateOwners.get(node.start);
4676
+ const templateStyles = options.styles && styles && (scope || owner) ? {
4677
+ options: options.styles,
4678
+ ...scope ? { scope } : {},
4679
+ ...owner ? { owner } : {},
4680
+ line: node.loc?.start.line ?? 0,
4681
+ column: node.loc?.start.column ?? 0,
4682
+ styles: styles.styles,
4683
+ diagnostics: styles.diagnostics
4684
+ } : void 0;
3749
4685
  const result = compilePieces(toPieces(node), holes, {
3750
4686
  ...options,
4687
+ ...templateStyles ? { templateStyles } : {},
3751
4688
  hoistTemplates: true,
3752
4689
  // A tag inside a template gets the same mark a JSX tag does. Without one, the nodes it
3753
4690
  // makes are the only ones in the module carrying no mark, and they take whichever was
@@ -3756,12 +4693,13 @@ function transformTemplates(code, id, options = {}) {
3756
4693
  // Same defaults as the plugin, so moving a build over is not a rendering change.
3757
4694
  templateClone: options.templateClone ?? true,
3758
4695
  partialTemplates: nested ? false : options.partialTemplates ?? true,
3759
- svg: node.tag.name === "svg"
4696
+ svg: templateTags.get(node.tag.name) === "svg"
3760
4697
  });
3761
4698
  for (const symbol of result.imports) used.add(symbol);
3762
4699
  collectNeeds(result.ir, needs);
3763
4700
  edits.push({ start: node.start, end: node.end, code: adoptTemplates(result.code, result.templates, hoisted) });
3764
4701
  }
4702
+ if (styles && options.styles) edits.push(...finishShadowStyles(styles, code, id));
3765
4703
  const out = new MagicString(code);
3766
4704
  for (const e of outermost(edits)) {
3767
4705
  if (e.start === e.end) out.appendLeft(e.start, e.code);
@@ -3819,13 +4757,19 @@ function transformTemplates(code, id, options = {}) {
3819
4757
  ...loadDiagnostics.length ? { loadDiagnostics } : {},
3820
4758
  ...unresolvedDiagnostics.length ? { unresolvedDiagnostics } : {},
3821
4759
  ...props.diagnostics.length ? { propsDiagnostics: props.diagnostics } : {},
3822
- ...intrinsics.diagnostics.length ? { intrinsicDiagnostics: intrinsics.diagnostics } : {}
4760
+ ...intrinsics.diagnostics.length ? { intrinsicDiagnostics: intrinsics.diagnostics } : {},
4761
+ ...styles?.styles.length ? { styles: styles.styles } : {},
4762
+ ...styles?.diagnostics.length ? { styleDiagnostics: styles.diagnostics } : {},
4763
+ ...styles?.literals.length ? { styleLiterals: styles.literals } : {},
4764
+ ...styles?.references.length ? { styleReferences: styles.references } : {}
3823
4765
  };
3824
4766
  }
3825
- function compileJsx(code, node, edits, nested, used, needs, hoisted, options, sourceFile) {
4767
+ function compileJsx(code, node, edits, nested, used, needs, hoisted, options, sourceFile, styles) {
3826
4768
  const ir = buildJsxIR(node, {
3827
4769
  code: (n2) => slice(code, n2.start, n2.end, edits),
3828
4770
  used,
4771
+ ...styles?.scopes.length ? { scopes: styles.scopes } : {},
4772
+ ...styles?.drop.size ? { dropStyles: styles.drop } : {},
3829
4773
  ...options.sourceLocations === true && sourceFile ? { sourceFile } : {}
3830
4774
  });
3831
4775
  analyzeStatic(ir);