@fluixi/compiler 1.0.0-alpha.94 → 1.0.0-alpha.96

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 (60) hide show
  1. package/LICENSE +1 -1
  2. package/dist/analyze/static-graph.cjs +1 -1
  3. package/dist/analyze/static-graph.mjs +1 -1
  4. package/dist/{babel-RJFQVFJW.mjs → babel-YG5PQAMX.mjs} +4 -4
  5. package/dist/{chunk-ZR2QHTEX.mjs → chunk-JHBI26FW.mjs} +6 -4
  6. package/dist/{chunk-DP2QDWWH.mjs → chunk-JJ4ZAZKY.mjs} +1 -1
  7. package/dist/{chunk-HCCBEJEZ.mjs → chunk-L6WBOEIO.mjs} +1 -1
  8. package/dist/{chunk-HIZU7WI2.mjs → chunk-UVH2BMMY.mjs} +1 -1
  9. package/dist/chunk-VX2OBUMB.mjs +92 -0
  10. package/dist/{chunk-E2RWTIYE.mjs → chunk-X735CULF.mjs} +4 -89
  11. package/dist/chunk-ZPEHDBCH.mjs +584 -0
  12. package/dist/codegen/backends/imperative.cjs +4 -2
  13. package/dist/codegen/backends/imperative.d.ts.map +1 -1
  14. package/dist/codegen/backends/imperative.js +9 -2
  15. package/dist/codegen/backends/imperative.mjs +4 -2
  16. package/dist/frontend/babel/build-ir-lit.cjs +4 -2
  17. package/dist/frontend/babel/build-ir-lit.mjs +4 -2
  18. package/dist/frontend/babel/build-ir.cjs +4 -2
  19. package/dist/frontend/babel/build-ir.mjs +4 -2
  20. package/dist/frontend/babel/index.cjs +5 -3
  21. package/dist/frontend/babel/index.mjs +5 -3
  22. package/dist/frontend/babel/lower-template.cjs +4 -2
  23. package/dist/frontend/babel/lower-template.mjs +4 -2
  24. package/dist/frontend/babel/plugin.cjs +4 -2
  25. package/dist/frontend/babel/plugin.mjs +4 -2
  26. package/dist/index.cjs +5 -3
  27. package/dist/index.mjs +5 -3
  28. package/dist/integrations.cjs +3330 -3269
  29. package/dist/integrations.d.ts.map +1 -1
  30. package/dist/integrations.js +19 -8
  31. package/dist/integrations.mjs +85 -40
  32. package/dist/lower/compile-template.cjs +5 -3
  33. package/dist/lower/compile-template.mjs +5 -3
  34. package/dist/lower/jsx.cjs +4 -2
  35. package/dist/lower/jsx.mjs +4 -2
  36. package/dist/lower/template.cjs +4 -2
  37. package/dist/lower/template.mjs +4 -2
  38. package/dist/resolve/builtins.cjs +1 -1
  39. package/dist/resolve/builtins.mjs +1 -1
  40. package/dist/{server-fns-JLSTKWPS.mjs → server-fns-PZEOON2D.mjs} +5 -4
  41. package/dist/{server-functions-BGY3RD4R.mjs → server-functions-JNSQMA63.mjs} +3 -3
  42. package/dist/transform/index.cjs +35 -16
  43. package/dist/transform/index.mjs +35 -16
  44. package/dist/transform/styles.cjs +31 -13
  45. package/dist/transform/styles.d.cts +27 -1
  46. package/dist/transform/styles.d.ts +27 -1
  47. package/dist/transform/styles.d.ts.map +1 -1
  48. package/dist/transform/styles.js +45 -16
  49. package/dist/transform/styles.mjs +31 -13
  50. package/dist/transform/templates.cjs +34 -15
  51. package/dist/transform/templates.mjs +34 -15
  52. package/dist/{transform-GBP6Y4UI.mjs → transform-UODP37VJ.mjs} +12 -563
  53. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  54. package/dist/vite-styles.cjs +66 -23
  55. package/dist/vite-styles.d.cts +16 -7
  56. package/dist/vite-styles.d.ts +16 -7
  57. package/dist/vite-styles.d.ts.map +1 -1
  58. package/dist/vite-styles.js +68 -25
  59. package/dist/vite-styles.mjs +78 -23
  60. package/package.json +4 -4
@@ -93,7 +93,7 @@ function collectStyles(program, sourceName, options, tags = { html: /* @__PURE__
93
93
  const imported = literalsOf.imports.get(name);
94
94
  if (imported) {
95
95
  const nodes = options?.imported?.get(`${imported.source}#${imported.name}`);
96
- if (nodes) return nodes.map(dropLoc);
96
+ if (nodes) return nodes.map((n) => keepLocIn(n, options?.importedModules));
97
97
  plan.references.push({ name: imported.name, source: imported.source, ...at });
98
98
  plan.diagnostics.push({
99
99
  ...at,
@@ -117,7 +117,7 @@ function collectStyles(program, sourceName, options, tags = { html: /* @__PURE__
117
117
  const nodes = resolveLiteral(name, at, []);
118
118
  const id = hash(`${sourceName}:css:${name}`);
119
119
  plan.edits.push({ start: literal.start, end: literal.end, code: `({ $fxStyle: ${JSON.stringify(id)} })` });
120
- if (nodes) plan.literals.push({ id, name, css: printStyle(nodes, options.minify) });
120
+ if (nodes) plan.literals.push({ id, name, css: printStyle(nodes, options.minify), nodes });
121
121
  }
122
122
  const scopeOf = /* @__PURE__ */ new Map();
123
123
  const names = /* @__PURE__ */ new Map();
@@ -192,7 +192,7 @@ function collectStyles(program, sourceName, options, tags = { html: /* @__PURE__
192
192
  if (!plan.scopes.some((s) => s.value === id)) plan.scopes.push({ start: owner.start, end: owner.end, value: id });
193
193
  nodes = scopeNodes(nodes, id, (message) => plan.diagnostics.push({ ...at, message }));
194
194
  }
195
- const printed = module2 ? printStyleWithMap(nodes, options.minify, sourceName, module2) : { css: printStyle(nodes, options.minify) };
195
+ const printed = module2 ? printStyleWithMap(nodes, options.minify, sourceName, module2, options.importedModules) : { css: printStyle(nodes, options.minify) };
196
196
  plan.styles.push({ id, scoped: scoped && !shadow, component, ...printed, ...shadow ? { shadow: true } : {}, ...at });
197
197
  if (shadow) shadow.indexes.push(plan.styles.length - 1);
198
198
  };
@@ -231,6 +231,11 @@ function staticMember(cls, name) {
231
231
  (m) => m.type === "ClassProperty" && m.static && (m.key.type === "Identifier" && m.key.name === name || m.key.type === "StringLiteral" && m.key.value === name)
232
232
  );
233
233
  }
234
+ var styleIds = {
235
+ block: (owner, index) => `${owner}.fx-${index}.css`,
236
+ inline: (owner, index) => `${owner}.fx-${index}.css?inline`,
237
+ literal: (owner, name) => `${owner}.fx-literal-${name}.css?inline`
238
+ };
234
239
  function finishShadowStyles(plan, code, moduleId) {
235
240
  const edits = [];
236
241
  const imports = [];
@@ -242,7 +247,7 @@ function finishShadowStyles(plan, code, moduleId) {
242
247
  return local;
243
248
  };
244
249
  for (const shadow of plan.shadowClasses.values()) {
245
- const blocks = shadow.indexes.map((i) => importOf(`${moduleId}?fx-style&index=${i}&inline&lang.css`));
250
+ const blocks = shadow.indexes.map((i) => importOf(styleIds.inline(moduleId, i)));
246
251
  let value;
247
252
  const prop = shadow.styles;
248
253
  if (prop?.value) {
@@ -250,7 +255,7 @@ function finishShadowStyles(plan, code, moduleId) {
250
255
  let text = code.slice(start, prop.value.end);
251
256
  const replacements = [];
252
257
  walkIdentifiers(prop.value, (id) => {
253
- const local = plan.names?.literals.has(id.name) ? importOf(`${moduleId}?fx-literal=${id.name}&inline&lang.css`) : plan.names?.imports.has(id.name) && !/\.css(\?|$)/.test(plan.names.imports.get(id.name).source) ? importOf(`${plan.names.imports.get(id.name).source}?fx-literal=${plan.names.imports.get(id.name).name}&inline&lang.css`) : void 0;
258
+ 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;
254
259
  if (local) replacements.push({ at: id.start - start, length: id.name.length, with: local });
255
260
  });
256
261
  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);
@@ -532,12 +537,23 @@ function shiftLoc(node, source, start) {
532
537
  if (node.kind === "rule" || node.kind === "at-rule") return { ...node, loc, nodes: node.nodes.map((n) => shiftLoc(n, source, start)) };
533
538
  return { ...node, loc };
534
539
  }
535
- function dropLoc(node) {
536
- const { loc: _loc, ...rest } = node;
537
- if (rest.kind === "rule" || rest.kind === "at-rule") return { ...rest, nodes: rest.nodes.map(dropLoc) };
538
- return rest;
539
- }
540
- function printStyleWithMap(nodes, minify, sourceName, module2) {
540
+ function keepLocIn(node, modules) {
541
+ const keep = node.loc !== void 0 && modules?.has(node.loc.source) === true;
542
+ const { loc, ...rest } = node;
543
+ const kept = keep ? { ...rest, loc } : rest;
544
+ if (kept.kind === "rule" || kept.kind === "at-rule") return { ...kept, nodes: kept.nodes.map((n) => keepLocIn(n, modules)) };
545
+ return kept;
546
+ }
547
+ function printStyleWithMap(nodes, minify, sourceName, module2, others) {
548
+ const sources = [module2];
549
+ const index = /* @__PURE__ */ new Map([[sourceName, 0]]);
550
+ const sourceOf = (name) => {
551
+ if (index.has(name)) return index.get(name);
552
+ const other = others?.get(name);
553
+ if (!other) return void 0;
554
+ index.set(name, sources.push(other) - 1);
555
+ return index.get(name);
556
+ };
541
557
  const lines = [[]];
542
558
  let css = "";
543
559
  let column = 0;
@@ -551,7 +567,8 @@ function printStyleWithMap(nodes, minify, sourceName, module2) {
551
567
  }
552
568
  };
553
569
  const mark = (loc) => {
554
- if (loc && loc.source === sourceName) lines[lines.length - 1].push([column, 0, loc.line - 1, loc.column]);
570
+ const at = loc ? sourceOf(loc.source) : void 0;
571
+ if (loc && at !== void 0) lines[lines.length - 1].push([column, at, loc.line - 1, loc.column]);
555
572
  };
556
573
  const write = (node, depth) => {
557
574
  const pad = minify ? "" : " ".repeat(depth);
@@ -570,7 +587,7 @@ function printStyleWithMap(nodes, minify, sourceName, module2) {
570
587
  }
571
588
  };
572
589
  for (const node of nodes) write(node, 0);
573
- return { css, map: { version: 3, sources: [module2.id], sourcesContent: [module2.code], names: [], mappings: (0, import_sourcemap_codec.encode)(lines) } };
590
+ return { css, map: { version: 3, sources: sources.map((s) => s.id), sourcesContent: sources.map((s) => s.code), names: [], mappings: (0, import_sourcemap_codec.encode)(lines) } };
574
591
  }
575
592
  function printStyle(nodes, minify = false) {
576
593
  const out = [];
@@ -1698,14 +1715,16 @@ function emitNode(node, used, templates) {
1698
1715
  for (const child of node.children) {
1699
1716
  used.add("insert");
1700
1717
  const childCode = emitNode(child, used, templates);
1701
- const isFn = child.kind === "expr" && child.reactive || child.kind === "component" || child.kind === "control";
1702
- parts.push(isFn ? `insert(${el}, ${childCode}, null);` : `insert(${el}, ${childCode});`);
1718
+ const anchored = child.kind === "expr" && (child.reactive || !isLiteralCode(child.code)) || child.kind === "component" || child.kind === "control";
1719
+ parts.push(anchored ? `insert(${el}, ${childCode}, null);` : `insert(${el}, ${childCode});`);
1703
1720
  }
1704
1721
  parts.push(`return ${el};`);
1705
1722
  return `(() => { ${parts.join(" ")} })()`;
1706
1723
  }
1707
1724
  }
1708
1725
  }
1726
+ var LITERAL = /^\s*(?:'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`[^`$]*`|-?\d[\d_.eE+-]*|true|false|null|undefined)\s*$/;
1727
+ var isLiteralCode = (code) => LITERAL.test(code);
1709
1728
  function inlineTemplates(code, templates) {
1710
1729
  if (!templates || templates.length === 0) return code;
1711
1730
  const byId = new Map(templates.map((t) => [t.id, JSON.stringify(t.html)]));
@@ -1135,7 +1135,7 @@ function collectStyles(program, sourceName, options, tags = { html: /* @__PURE__
1135
1135
  const imported = literalsOf.imports.get(name);
1136
1136
  if (imported) {
1137
1137
  const nodes = options?.imported?.get(`${imported.source}#${imported.name}`);
1138
- if (nodes) return nodes.map(dropLoc);
1138
+ if (nodes) return nodes.map((n2) => keepLocIn(n2, options?.importedModules));
1139
1139
  plan.references.push({ name: imported.name, source: imported.source, ...at });
1140
1140
  plan.diagnostics.push({
1141
1141
  ...at,
@@ -1159,7 +1159,7 @@ function collectStyles(program, sourceName, options, tags = { html: /* @__PURE__
1159
1159
  const nodes = resolveLiteral(name, at, []);
1160
1160
  const id = hash(`${sourceName}:css:${name}`);
1161
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) });
1162
+ if (nodes) plan.literals.push({ id, name, css: printStyle(nodes, options.minify), nodes });
1163
1163
  }
1164
1164
  const scopeOf = /* @__PURE__ */ new Map();
1165
1165
  const names = /* @__PURE__ */ new Map();
@@ -1234,7 +1234,7 @@ function collectStyles(program, sourceName, options, tags = { html: /* @__PURE__
1234
1234
  if (!plan.scopes.some((s) => s.value === id)) plan.scopes.push({ start: owner.start, end: owner.end, value: id });
1235
1235
  nodes = scopeNodes(nodes, id, (message) => plan.diagnostics.push({ ...at, message }));
1236
1236
  }
1237
- const printed = module ? printStyleWithMap(nodes, options.minify, sourceName, module) : { css: printStyle(nodes, options.minify) };
1237
+ const printed = module ? printStyleWithMap(nodes, options.minify, sourceName, module, options.importedModules) : { css: printStyle(nodes, options.minify) };
1238
1238
  plan.styles.push({ id, scoped: scoped && !shadow, component, ...printed, ...shadow ? { shadow: true } : {}, ...at });
1239
1239
  if (shadow) shadow.indexes.push(plan.styles.length - 1);
1240
1240
  };
@@ -1273,6 +1273,11 @@ function staticMember(cls, name) {
1273
1273
  (m) => m.type === "ClassProperty" && m.static && (m.key.type === "Identifier" && m.key.name === name || m.key.type === "StringLiteral" && m.key.value === name)
1274
1274
  );
1275
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
+ };
1276
1281
  function finishShadowStyles(plan, code, moduleId) {
1277
1282
  const edits = [];
1278
1283
  const imports = [];
@@ -1284,7 +1289,7 @@ function finishShadowStyles(plan, code, moduleId) {
1284
1289
  return local;
1285
1290
  };
1286
1291
  for (const shadow of plan.shadowClasses.values()) {
1287
- const blocks = shadow.indexes.map((i) => importOf(`${moduleId}?fx-style&index=${i}&inline&lang.css`));
1292
+ const blocks = shadow.indexes.map((i) => importOf(styleIds.inline(moduleId, i)));
1288
1293
  let value;
1289
1294
  const prop = shadow.styles;
1290
1295
  if (prop?.value) {
@@ -1292,7 +1297,7 @@ function finishShadowStyles(plan, code, moduleId) {
1292
1297
  let text = code.slice(start, prop.value.end);
1293
1298
  const replacements = [];
1294
1299
  walkIdentifiers(prop.value, (id) => {
1295
- const local = plan.names?.literals.has(id.name) ? importOf(`${moduleId}?fx-literal=${id.name}&inline&lang.css`) : plan.names?.imports.has(id.name) && !/\.css(\?|$)/.test(plan.names.imports.get(id.name).source) ? importOf(`${plan.names.imports.get(id.name).source}?fx-literal=${plan.names.imports.get(id.name).name}&inline&lang.css`) : void 0;
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;
1296
1301
  if (local) replacements.push({ at: id.start - start, length: id.name.length, with: local });
1297
1302
  });
1298
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);
@@ -1574,12 +1579,23 @@ function shiftLoc(node, source, start) {
1574
1579
  if (node.kind === "rule" || node.kind === "at-rule") return { ...node, loc, nodes: node.nodes.map((n2) => shiftLoc(n2, source, start)) };
1575
1580
  return { ...node, loc };
1576
1581
  }
1577
- function dropLoc(node) {
1578
- const { loc: _loc, ...rest } = node;
1579
- if (rest.kind === "rule" || rest.kind === "at-rule") return { ...rest, nodes: rest.nodes.map(dropLoc) };
1580
- return rest;
1581
- }
1582
- function printStyleWithMap(nodes, minify, sourceName, module) {
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
+ };
1583
1599
  const lines = [[]];
1584
1600
  let css = "";
1585
1601
  let column = 0;
@@ -1593,7 +1609,8 @@ function printStyleWithMap(nodes, minify, sourceName, module) {
1593
1609
  }
1594
1610
  };
1595
1611
  const mark = (loc) => {
1596
- if (loc && loc.source === sourceName) lines[lines.length - 1].push([column, 0, loc.line - 1, loc.column]);
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]);
1597
1614
  };
1598
1615
  const write = (node, depth) => {
1599
1616
  const pad = minify ? "" : " ".repeat(depth);
@@ -1612,7 +1629,7 @@ function printStyleWithMap(nodes, minify, sourceName, module) {
1612
1629
  }
1613
1630
  };
1614
1631
  for (const node of nodes) write(node, 0);
1615
- return { css, map: { version: 3, sources: [module.id], sourcesContent: [module.code], names: [], mappings: encode(lines) } };
1632
+ return { css, map: { version: 3, sources: sources.map((s) => s.id), sourcesContent: sources.map((s) => s.code), names: [], mappings: encode(lines) } };
1616
1633
  }
1617
1634
  function printStyle(nodes, minify = false) {
1618
1635
  const out = [];
@@ -2740,14 +2757,16 @@ function emitNode(node, used, templates) {
2740
2757
  for (const child of node.children) {
2741
2758
  used.add("insert");
2742
2759
  const childCode = emitNode(child, used, templates);
2743
- const isFn = child.kind === "expr" && child.reactive || child.kind === "component" || child.kind === "control";
2744
- parts.push(isFn ? `insert(${el}, ${childCode}, null);` : `insert(${el}, ${childCode});`);
2760
+ const anchored = child.kind === "expr" && (child.reactive || !isLiteralCode(child.code)) || child.kind === "component" || child.kind === "control";
2761
+ parts.push(anchored ? `insert(${el}, ${childCode}, null);` : `insert(${el}, ${childCode});`);
2745
2762
  }
2746
2763
  parts.push(`return ${el};`);
2747
2764
  return `(() => { ${parts.join(" ")} })()`;
2748
2765
  }
2749
2766
  }
2750
2767
  }
2768
+ var LITERAL = /^\s*(?:'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`[^`$]*`|-?\d[\d_.eE+-]*|true|false|null|undefined)\s*$/;
2769
+ var isLiteralCode = (code) => LITERAL.test(code);
2751
2770
  function inlineTemplates(code, templates) {
2752
2771
  if (!templates || templates.length === 0) return code;
2753
2772
  const byId = new Map(templates.map((t) => [t.id, JSON.stringify(t.html)]));