@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.
- package/LICENSE +1 -1
- package/dist/analyze/static-graph.cjs +1 -1
- package/dist/analyze/static-graph.mjs +1 -1
- package/dist/{babel-RJFQVFJW.mjs → babel-YG5PQAMX.mjs} +4 -4
- package/dist/{chunk-ZR2QHTEX.mjs → chunk-JHBI26FW.mjs} +6 -4
- package/dist/{chunk-DP2QDWWH.mjs → chunk-JJ4ZAZKY.mjs} +1 -1
- package/dist/{chunk-HCCBEJEZ.mjs → chunk-L6WBOEIO.mjs} +1 -1
- package/dist/{chunk-HIZU7WI2.mjs → chunk-UVH2BMMY.mjs} +1 -1
- package/dist/chunk-VX2OBUMB.mjs +92 -0
- package/dist/{chunk-E2RWTIYE.mjs → chunk-X735CULF.mjs} +4 -89
- package/dist/chunk-ZPEHDBCH.mjs +584 -0
- package/dist/codegen/backends/imperative.cjs +4 -2
- package/dist/codegen/backends/imperative.d.ts.map +1 -1
- package/dist/codegen/backends/imperative.js +9 -2
- package/dist/codegen/backends/imperative.mjs +4 -2
- package/dist/frontend/babel/build-ir-lit.cjs +4 -2
- package/dist/frontend/babel/build-ir-lit.mjs +4 -2
- package/dist/frontend/babel/build-ir.cjs +4 -2
- package/dist/frontend/babel/build-ir.mjs +4 -2
- package/dist/frontend/babel/index.cjs +5 -3
- package/dist/frontend/babel/index.mjs +5 -3
- package/dist/frontend/babel/lower-template.cjs +4 -2
- package/dist/frontend/babel/lower-template.mjs +4 -2
- package/dist/frontend/babel/plugin.cjs +4 -2
- package/dist/frontend/babel/plugin.mjs +4 -2
- package/dist/index.cjs +5 -3
- package/dist/index.mjs +5 -3
- package/dist/integrations.cjs +3330 -3269
- package/dist/integrations.d.ts.map +1 -1
- package/dist/integrations.js +19 -8
- package/dist/integrations.mjs +85 -40
- package/dist/lower/compile-template.cjs +5 -3
- package/dist/lower/compile-template.mjs +5 -3
- package/dist/lower/jsx.cjs +4 -2
- package/dist/lower/jsx.mjs +4 -2
- package/dist/lower/template.cjs +4 -2
- package/dist/lower/template.mjs +4 -2
- package/dist/resolve/builtins.cjs +1 -1
- package/dist/resolve/builtins.mjs +1 -1
- package/dist/{server-fns-JLSTKWPS.mjs → server-fns-PZEOON2D.mjs} +5 -4
- package/dist/{server-functions-BGY3RD4R.mjs → server-functions-JNSQMA63.mjs} +3 -3
- package/dist/transform/index.cjs +35 -16
- package/dist/transform/index.mjs +35 -16
- package/dist/transform/styles.cjs +31 -13
- package/dist/transform/styles.d.cts +27 -1
- package/dist/transform/styles.d.ts +27 -1
- package/dist/transform/styles.d.ts.map +1 -1
- package/dist/transform/styles.js +45 -16
- package/dist/transform/styles.mjs +31 -13
- package/dist/transform/templates.cjs +34 -15
- package/dist/transform/templates.mjs +34 -15
- package/dist/{transform-GBP6Y4UI.mjs → transform-UODP37VJ.mjs} +12 -563
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/vite-styles.cjs +66 -23
- package/dist/vite-styles.d.cts +16 -7
- package/dist/vite-styles.d.ts +16 -7
- package/dist/vite-styles.d.ts.map +1 -1
- package/dist/vite-styles.js +68 -25
- package/dist/vite-styles.mjs +78 -23
- package/package.json +4 -4
package/dist/transform/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @fluixi/compiler v1.0.0-alpha.
|
|
1
|
+
/*! @fluixi/compiler v1.0.0-alpha.96 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
2
|
|
|
3
3
|
// src/transform/templates.ts
|
|
4
4
|
import { parse as parse2 } from "@babel/parser";
|
|
@@ -1137,7 +1137,7 @@ function collectStyles(program, sourceName, options, tags = { html: /* @__PURE__
|
|
|
1137
1137
|
const imported = literalsOf.imports.get(name);
|
|
1138
1138
|
if (imported) {
|
|
1139
1139
|
const nodes = options?.imported?.get(`${imported.source}#${imported.name}`);
|
|
1140
|
-
if (nodes) return nodes.map(
|
|
1140
|
+
if (nodes) return nodes.map((n2) => keepLocIn(n2, options?.importedModules));
|
|
1141
1141
|
plan.references.push({ name: imported.name, source: imported.source, ...at });
|
|
1142
1142
|
plan.diagnostics.push({
|
|
1143
1143
|
...at,
|
|
@@ -1161,7 +1161,7 @@ function collectStyles(program, sourceName, options, tags = { html: /* @__PURE__
|
|
|
1161
1161
|
const nodes = resolveLiteral(name, at, []);
|
|
1162
1162
|
const id = hash(`${sourceName}:css:${name}`);
|
|
1163
1163
|
plan.edits.push({ start: literal.start, end: literal.end, code: `({ $fxStyle: ${JSON.stringify(id)} })` });
|
|
1164
|
-
if (nodes) plan.literals.push({ id, name, css: printStyle(nodes, options.minify) });
|
|
1164
|
+
if (nodes) plan.literals.push({ id, name, css: printStyle(nodes, options.minify), nodes });
|
|
1165
1165
|
}
|
|
1166
1166
|
const scopeOf = /* @__PURE__ */ new Map();
|
|
1167
1167
|
const names = /* @__PURE__ */ new Map();
|
|
@@ -1236,7 +1236,7 @@ function collectStyles(program, sourceName, options, tags = { html: /* @__PURE__
|
|
|
1236
1236
|
if (!plan.scopes.some((s) => s.value === id)) plan.scopes.push({ start: owner.start, end: owner.end, value: id });
|
|
1237
1237
|
nodes = scopeNodes(nodes, id, (message) => plan.diagnostics.push({ ...at, message }));
|
|
1238
1238
|
}
|
|
1239
|
-
const printed = module ? printStyleWithMap(nodes, options.minify, sourceName, module) : { css: printStyle(nodes, options.minify) };
|
|
1239
|
+
const printed = module ? printStyleWithMap(nodes, options.minify, sourceName, module, options.importedModules) : { css: printStyle(nodes, options.minify) };
|
|
1240
1240
|
plan.styles.push({ id, scoped: scoped && !shadow, component, ...printed, ...shadow ? { shadow: true } : {}, ...at });
|
|
1241
1241
|
if (shadow) shadow.indexes.push(plan.styles.length - 1);
|
|
1242
1242
|
};
|
|
@@ -1275,6 +1275,11 @@ function staticMember(cls, name) {
|
|
|
1275
1275
|
(m) => m.type === "ClassProperty" && m.static && (m.key.type === "Identifier" && m.key.name === name || m.key.type === "StringLiteral" && m.key.value === name)
|
|
1276
1276
|
);
|
|
1277
1277
|
}
|
|
1278
|
+
var styleIds = {
|
|
1279
|
+
block: (owner, index) => `${owner}.fx-${index}.css`,
|
|
1280
|
+
inline: (owner, index) => `${owner}.fx-${index}.css?inline`,
|
|
1281
|
+
literal: (owner, name) => `${owner}.fx-literal-${name}.css?inline`
|
|
1282
|
+
};
|
|
1278
1283
|
function finishShadowStyles(plan, code, moduleId) {
|
|
1279
1284
|
const edits = [];
|
|
1280
1285
|
const imports = [];
|
|
@@ -1286,7 +1291,7 @@ function finishShadowStyles(plan, code, moduleId) {
|
|
|
1286
1291
|
return local;
|
|
1287
1292
|
};
|
|
1288
1293
|
for (const shadow of plan.shadowClasses.values()) {
|
|
1289
|
-
const blocks = shadow.indexes.map((i) => importOf(
|
|
1294
|
+
const blocks = shadow.indexes.map((i) => importOf(styleIds.inline(moduleId, i)));
|
|
1290
1295
|
let value;
|
|
1291
1296
|
const prop = shadow.styles;
|
|
1292
1297
|
if (prop?.value) {
|
|
@@ -1294,7 +1299,7 @@ function finishShadowStyles(plan, code, moduleId) {
|
|
|
1294
1299
|
let text = code.slice(start, prop.value.end);
|
|
1295
1300
|
const replacements = [];
|
|
1296
1301
|
walkIdentifiers(prop.value, (id) => {
|
|
1297
|
-
const local = plan.names?.literals.has(id.name) ? importOf(
|
|
1302
|
+
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;
|
|
1298
1303
|
if (local) replacements.push({ at: id.start - start, length: id.name.length, with: local });
|
|
1299
1304
|
});
|
|
1300
1305
|
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);
|
|
@@ -1576,12 +1581,23 @@ function shiftLoc(node, source, start) {
|
|
|
1576
1581
|
if (node.kind === "rule" || node.kind === "at-rule") return { ...node, loc, nodes: node.nodes.map((n2) => shiftLoc(n2, source, start)) };
|
|
1577
1582
|
return { ...node, loc };
|
|
1578
1583
|
}
|
|
1579
|
-
function
|
|
1580
|
-
const
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
}
|
|
1584
|
-
|
|
1584
|
+
function keepLocIn(node, modules) {
|
|
1585
|
+
const keep = node.loc !== void 0 && modules?.has(node.loc.source) === true;
|
|
1586
|
+
const { loc, ...rest } = node;
|
|
1587
|
+
const kept = keep ? { ...rest, loc } : rest;
|
|
1588
|
+
if (kept.kind === "rule" || kept.kind === "at-rule") return { ...kept, nodes: kept.nodes.map((n2) => keepLocIn(n2, modules)) };
|
|
1589
|
+
return kept;
|
|
1590
|
+
}
|
|
1591
|
+
function printStyleWithMap(nodes, minify, sourceName, module, others) {
|
|
1592
|
+
const sources = [module];
|
|
1593
|
+
const index = /* @__PURE__ */ new Map([[sourceName, 0]]);
|
|
1594
|
+
const sourceOf = (name) => {
|
|
1595
|
+
if (index.has(name)) return index.get(name);
|
|
1596
|
+
const other = others?.get(name);
|
|
1597
|
+
if (!other) return void 0;
|
|
1598
|
+
index.set(name, sources.push(other) - 1);
|
|
1599
|
+
return index.get(name);
|
|
1600
|
+
};
|
|
1585
1601
|
const lines = [[]];
|
|
1586
1602
|
let css = "";
|
|
1587
1603
|
let column = 0;
|
|
@@ -1595,7 +1611,8 @@ function printStyleWithMap(nodes, minify, sourceName, module) {
|
|
|
1595
1611
|
}
|
|
1596
1612
|
};
|
|
1597
1613
|
const mark = (loc) => {
|
|
1598
|
-
|
|
1614
|
+
const at = loc ? sourceOf(loc.source) : void 0;
|
|
1615
|
+
if (loc && at !== void 0) lines[lines.length - 1].push([column, at, loc.line - 1, loc.column]);
|
|
1599
1616
|
};
|
|
1600
1617
|
const write = (node, depth) => {
|
|
1601
1618
|
const pad = minify ? "" : " ".repeat(depth);
|
|
@@ -1614,7 +1631,7 @@ function printStyleWithMap(nodes, minify, sourceName, module) {
|
|
|
1614
1631
|
}
|
|
1615
1632
|
};
|
|
1616
1633
|
for (const node of nodes) write(node, 0);
|
|
1617
|
-
return { css, map: { version: 3, sources:
|
|
1634
|
+
return { css, map: { version: 3, sources: sources.map((s) => s.id), sourcesContent: sources.map((s) => s.code), names: [], mappings: encode(lines) } };
|
|
1618
1635
|
}
|
|
1619
1636
|
function printStyle(nodes, minify = false) {
|
|
1620
1637
|
const out = [];
|
|
@@ -2742,14 +2759,16 @@ function emitNode(node, used, templates) {
|
|
|
2742
2759
|
for (const child of node.children) {
|
|
2743
2760
|
used.add("insert");
|
|
2744
2761
|
const childCode = emitNode(child, used, templates);
|
|
2745
|
-
const
|
|
2746
|
-
parts.push(
|
|
2762
|
+
const anchored = child.kind === "expr" && (child.reactive || !isLiteralCode(child.code)) || child.kind === "component" || child.kind === "control";
|
|
2763
|
+
parts.push(anchored ? `insert(${el}, ${childCode}, null);` : `insert(${el}, ${childCode});`);
|
|
2747
2764
|
}
|
|
2748
2765
|
parts.push(`return ${el};`);
|
|
2749
2766
|
return `(() => { ${parts.join(" ")} })()`;
|
|
2750
2767
|
}
|
|
2751
2768
|
}
|
|
2752
2769
|
}
|
|
2770
|
+
var LITERAL = /^\s*(?:'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`[^`$]*`|-?\d[\d_.eE+-]*|true|false|null|undefined)\s*$/;
|
|
2771
|
+
var isLiteralCode = (code) => LITERAL.test(code);
|
|
2753
2772
|
function inlineTemplates(code, templates) {
|
|
2754
2773
|
if (!templates || templates.length === 0) return code;
|
|
2755
2774
|
const byId = new Map(templates.map((t) => [t.id, JSON.stringify(t.html)]));
|
|
@@ -28,7 +28,8 @@ __export(styles_exports, {
|
|
|
28
28
|
printStyle: () => printStyle,
|
|
29
29
|
printStyleWithMap: () => printStyleWithMap,
|
|
30
30
|
scopeNodes: () => scopeNodes,
|
|
31
|
-
scopeSelector: () => scopeSelector
|
|
31
|
+
scopeSelector: () => scopeSelector,
|
|
32
|
+
styleIds: () => styleIds
|
|
32
33
|
});
|
|
33
34
|
module.exports = __toCommonJS(styles_exports);
|
|
34
35
|
var import_sourcemap_codec = require("@jridgewell/sourcemap-codec");
|
|
@@ -87,7 +88,7 @@ function collectStyles(program, sourceName, options, tags = { html: /* @__PURE__
|
|
|
87
88
|
const imported = literalsOf.imports.get(name);
|
|
88
89
|
if (imported) {
|
|
89
90
|
const nodes = options?.imported?.get(`${imported.source}#${imported.name}`);
|
|
90
|
-
if (nodes) return nodes.map(
|
|
91
|
+
if (nodes) return nodes.map((n) => keepLocIn(n, options?.importedModules));
|
|
91
92
|
plan.references.push({ name: imported.name, source: imported.source, ...at });
|
|
92
93
|
plan.diagnostics.push({
|
|
93
94
|
...at,
|
|
@@ -111,7 +112,7 @@ function collectStyles(program, sourceName, options, tags = { html: /* @__PURE__
|
|
|
111
112
|
const nodes = resolveLiteral(name, at, []);
|
|
112
113
|
const id = hash(`${sourceName}:css:${name}`);
|
|
113
114
|
plan.edits.push({ start: literal.start, end: literal.end, code: `({ $fxStyle: ${JSON.stringify(id)} })` });
|
|
114
|
-
if (nodes) plan.literals.push({ id, name, css: printStyle(nodes, options.minify) });
|
|
115
|
+
if (nodes) plan.literals.push({ id, name, css: printStyle(nodes, options.minify), nodes });
|
|
115
116
|
}
|
|
116
117
|
const scopeOf = /* @__PURE__ */ new Map();
|
|
117
118
|
const names = /* @__PURE__ */ new Map();
|
|
@@ -186,7 +187,7 @@ function collectStyles(program, sourceName, options, tags = { html: /* @__PURE__
|
|
|
186
187
|
if (!plan.scopes.some((s) => s.value === id)) plan.scopes.push({ start: owner.start, end: owner.end, value: id });
|
|
187
188
|
nodes = scopeNodes(nodes, id, (message) => plan.diagnostics.push({ ...at, message }));
|
|
188
189
|
}
|
|
189
|
-
const printed = module2 ? printStyleWithMap(nodes, options.minify, sourceName, module2) : { css: printStyle(nodes, options.minify) };
|
|
190
|
+
const printed = module2 ? printStyleWithMap(nodes, options.minify, sourceName, module2, options.importedModules) : { css: printStyle(nodes, options.minify) };
|
|
190
191
|
plan.styles.push({ id, scoped: scoped && !shadow, component, ...printed, ...shadow ? { shadow: true } : {}, ...at });
|
|
191
192
|
if (shadow) shadow.indexes.push(plan.styles.length - 1);
|
|
192
193
|
};
|
|
@@ -225,6 +226,11 @@ function staticMember(cls, name) {
|
|
|
225
226
|
(m) => m.type === "ClassProperty" && m.static && (m.key.type === "Identifier" && m.key.name === name || m.key.type === "StringLiteral" && m.key.value === name)
|
|
226
227
|
);
|
|
227
228
|
}
|
|
229
|
+
var styleIds = {
|
|
230
|
+
block: (owner, index) => `${owner}.fx-${index}.css`,
|
|
231
|
+
inline: (owner, index) => `${owner}.fx-${index}.css?inline`,
|
|
232
|
+
literal: (owner, name) => `${owner}.fx-literal-${name}.css?inline`
|
|
233
|
+
};
|
|
228
234
|
function finishShadowStyles(plan, code, moduleId) {
|
|
229
235
|
const edits = [];
|
|
230
236
|
const imports = [];
|
|
@@ -236,7 +242,7 @@ function finishShadowStyles(plan, code, moduleId) {
|
|
|
236
242
|
return local;
|
|
237
243
|
};
|
|
238
244
|
for (const shadow of plan.shadowClasses.values()) {
|
|
239
|
-
const blocks = shadow.indexes.map((i) => importOf(
|
|
245
|
+
const blocks = shadow.indexes.map((i) => importOf(styleIds.inline(moduleId, i)));
|
|
240
246
|
let value;
|
|
241
247
|
const prop = shadow.styles;
|
|
242
248
|
if (prop?.value) {
|
|
@@ -244,7 +250,7 @@ function finishShadowStyles(plan, code, moduleId) {
|
|
|
244
250
|
let text = code.slice(start, prop.value.end);
|
|
245
251
|
const replacements = [];
|
|
246
252
|
walkIdentifiers(prop.value, (id) => {
|
|
247
|
-
const local = plan.names?.literals.has(id.name) ? importOf(
|
|
253
|
+
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;
|
|
248
254
|
if (local) replacements.push({ at: id.start - start, length: id.name.length, with: local });
|
|
249
255
|
});
|
|
250
256
|
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);
|
|
@@ -526,12 +532,23 @@ function shiftLoc(node, source, start) {
|
|
|
526
532
|
if (node.kind === "rule" || node.kind === "at-rule") return { ...node, loc, nodes: node.nodes.map((n) => shiftLoc(n, source, start)) };
|
|
527
533
|
return { ...node, loc };
|
|
528
534
|
}
|
|
529
|
-
function
|
|
530
|
-
const
|
|
531
|
-
|
|
532
|
-
|
|
535
|
+
function keepLocIn(node, modules) {
|
|
536
|
+
const keep = node.loc !== void 0 && modules?.has(node.loc.source) === true;
|
|
537
|
+
const { loc, ...rest } = node;
|
|
538
|
+
const kept = keep ? { ...rest, loc } : rest;
|
|
539
|
+
if (kept.kind === "rule" || kept.kind === "at-rule") return { ...kept, nodes: kept.nodes.map((n) => keepLocIn(n, modules)) };
|
|
540
|
+
return kept;
|
|
533
541
|
}
|
|
534
|
-
function printStyleWithMap(nodes, minify, sourceName, module2) {
|
|
542
|
+
function printStyleWithMap(nodes, minify, sourceName, module2, others) {
|
|
543
|
+
const sources = [module2];
|
|
544
|
+
const index = /* @__PURE__ */ new Map([[sourceName, 0]]);
|
|
545
|
+
const sourceOf = (name) => {
|
|
546
|
+
if (index.has(name)) return index.get(name);
|
|
547
|
+
const other = others?.get(name);
|
|
548
|
+
if (!other) return void 0;
|
|
549
|
+
index.set(name, sources.push(other) - 1);
|
|
550
|
+
return index.get(name);
|
|
551
|
+
};
|
|
535
552
|
const lines = [[]];
|
|
536
553
|
let css = "";
|
|
537
554
|
let column = 0;
|
|
@@ -545,7 +562,8 @@ function printStyleWithMap(nodes, minify, sourceName, module2) {
|
|
|
545
562
|
}
|
|
546
563
|
};
|
|
547
564
|
const mark = (loc) => {
|
|
548
|
-
|
|
565
|
+
const at = loc ? sourceOf(loc.source) : void 0;
|
|
566
|
+
if (loc && at !== void 0) lines[lines.length - 1].push([column, at, loc.line - 1, loc.column]);
|
|
549
567
|
};
|
|
550
568
|
const write = (node, depth) => {
|
|
551
569
|
const pad = minify ? "" : " ".repeat(depth);
|
|
@@ -564,7 +582,7 @@ function printStyleWithMap(nodes, minify, sourceName, module2) {
|
|
|
564
582
|
}
|
|
565
583
|
};
|
|
566
584
|
for (const node of nodes) write(node, 0);
|
|
567
|
-
return { css, map: { version: 3, sources:
|
|
585
|
+
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) } };
|
|
568
586
|
}
|
|
569
587
|
function printStyle(nodes, minify = false) {
|
|
570
588
|
const out = [];
|
|
@@ -59,6 +59,14 @@ export interface StyleOptions {
|
|
|
59
59
|
* the import names them. A reference not in here is reported in `styleReferences`.
|
|
60
60
|
*/
|
|
61
61
|
imported?: Map<string, StyleNode[]>;
|
|
62
|
+
/**
|
|
63
|
+
* The modules those values were written in, by the name their positions carry: with them, a
|
|
64
|
+
* composed value's rules map back to that module's lines. Without, they are left unmapped.
|
|
65
|
+
*/
|
|
66
|
+
importedModules?: Map<string, {
|
|
67
|
+
id: string;
|
|
68
|
+
code: string;
|
|
69
|
+
}>;
|
|
62
70
|
}
|
|
63
71
|
/** A `css`` value: portable, unscoped, emitted only where something uses it. */
|
|
64
72
|
export interface StyleLiteral {
|
|
@@ -66,6 +74,8 @@ export interface StyleLiteral {
|
|
|
66
74
|
/** The variable it is bound to. */
|
|
67
75
|
name: string;
|
|
68
76
|
css: string;
|
|
77
|
+
/** Its rules, positions in this module kept, for a module that composes it. */
|
|
78
|
+
nodes: StyleNode[];
|
|
69
79
|
}
|
|
70
80
|
/** An interpolated style value from another module, for the build to resolve. */
|
|
71
81
|
export interface StyleReference {
|
|
@@ -185,6 +195,17 @@ export declare function applyTemplateStyles(ir: IRLike, t: TemplateStyles): void
|
|
|
185
195
|
* `css`` values named in its `static styles` become `?inline` imports of their processed CSS
|
|
186
196
|
* (the text `static styles` takes), and the class's `static styles` lists them.
|
|
187
197
|
*/
|
|
198
|
+
/**
|
|
199
|
+
* Where a component's style blocks and css`` values are served: next to the component, a path
|
|
200
|
+
* ending in `.css`. Every CSS tool in the bundler then sees CSS, and none sees TSX: Vite 8
|
|
201
|
+
* matches its transforms on the path without the query, so `card.tsx?…` would read as a .tsx.
|
|
202
|
+
* `?inline` (Vite's own) asks for the CSS as a string, for a shadow root.
|
|
203
|
+
*/
|
|
204
|
+
export declare const styleIds: {
|
|
205
|
+
block: (owner: string, index: number) => string;
|
|
206
|
+
inline: (owner: string, index: number) => string;
|
|
207
|
+
literal: (owner: string, name: string) => string;
|
|
208
|
+
};
|
|
188
209
|
export declare function finishShadowStyles(plan: StylePlan, code: string, moduleId: string): {
|
|
189
210
|
start: number;
|
|
190
211
|
end: number;
|
|
@@ -203,7 +224,12 @@ export declare function scopeSelector(selector: string, id: string, warn?: (mess
|
|
|
203
224
|
export declare function printStyleWithMap(nodes: StyleNode[], minify: boolean | undefined, sourceName: string, module: {
|
|
204
225
|
id: string;
|
|
205
226
|
code: string;
|
|
206
|
-
}
|
|
227
|
+
},
|
|
228
|
+
/** Other modules rules came from (composed css`` values), by the name their positions carry. */
|
|
229
|
+
others?: ReadonlyMap<string, {
|
|
230
|
+
id: string;
|
|
231
|
+
code: string;
|
|
232
|
+
}>): {
|
|
207
233
|
css: string;
|
|
208
234
|
map: StyleMap;
|
|
209
235
|
};
|
|
@@ -59,6 +59,14 @@ export interface StyleOptions {
|
|
|
59
59
|
* the import names them. A reference not in here is reported in `styleReferences`.
|
|
60
60
|
*/
|
|
61
61
|
imported?: Map<string, StyleNode[]>;
|
|
62
|
+
/**
|
|
63
|
+
* The modules those values were written in, by the name their positions carry: with them, a
|
|
64
|
+
* composed value's rules map back to that module's lines. Without, they are left unmapped.
|
|
65
|
+
*/
|
|
66
|
+
importedModules?: Map<string, {
|
|
67
|
+
id: string;
|
|
68
|
+
code: string;
|
|
69
|
+
}>;
|
|
62
70
|
}
|
|
63
71
|
/** A `css`` value: portable, unscoped, emitted only where something uses it. */
|
|
64
72
|
export interface StyleLiteral {
|
|
@@ -66,6 +74,8 @@ export interface StyleLiteral {
|
|
|
66
74
|
/** The variable it is bound to. */
|
|
67
75
|
name: string;
|
|
68
76
|
css: string;
|
|
77
|
+
/** Its rules, positions in this module kept, for a module that composes it. */
|
|
78
|
+
nodes: StyleNode[];
|
|
69
79
|
}
|
|
70
80
|
/** An interpolated style value from another module, for the build to resolve. */
|
|
71
81
|
export interface StyleReference {
|
|
@@ -185,6 +195,17 @@ export declare function applyTemplateStyles(ir: IRLike, t: TemplateStyles): void
|
|
|
185
195
|
* `css`` values named in its `static styles` become `?inline` imports of their processed CSS
|
|
186
196
|
* (the text `static styles` takes), and the class's `static styles` lists them.
|
|
187
197
|
*/
|
|
198
|
+
/**
|
|
199
|
+
* Where a component's style blocks and css`` values are served: next to the component, a path
|
|
200
|
+
* ending in `.css`. Every CSS tool in the bundler then sees CSS, and none sees TSX: Vite 8
|
|
201
|
+
* matches its transforms on the path without the query, so `card.tsx?…` would read as a .tsx.
|
|
202
|
+
* `?inline` (Vite's own) asks for the CSS as a string, for a shadow root.
|
|
203
|
+
*/
|
|
204
|
+
export declare const styleIds: {
|
|
205
|
+
block: (owner: string, index: number) => string;
|
|
206
|
+
inline: (owner: string, index: number) => string;
|
|
207
|
+
literal: (owner: string, name: string) => string;
|
|
208
|
+
};
|
|
188
209
|
export declare function finishShadowStyles(plan: StylePlan, code: string, moduleId: string): {
|
|
189
210
|
start: number;
|
|
190
211
|
end: number;
|
|
@@ -203,7 +224,12 @@ export declare function scopeSelector(selector: string, id: string, warn?: (mess
|
|
|
203
224
|
export declare function printStyleWithMap(nodes: StyleNode[], minify: boolean | undefined, sourceName: string, module: {
|
|
204
225
|
id: string;
|
|
205
226
|
code: string;
|
|
206
|
-
}
|
|
227
|
+
},
|
|
228
|
+
/** Other modules rules came from (composed css`` values), by the name their positions carry. */
|
|
229
|
+
others?: ReadonlyMap<string, {
|
|
230
|
+
id: string;
|
|
231
|
+
code: string;
|
|
232
|
+
}>): {
|
|
207
233
|
css: string;
|
|
208
234
|
map: StyleMap;
|
|
209
235
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../src/transform/styles.ts"],"names":[],"mappings":"AAcA,uEAAuE;AACvE,UAAU,IAAI;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,GAAG,CAAC,EAAE;QAAE,KAAK,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,GAAG,IAAI,CAAC;IACzD,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,oEAAoE;AACpE,4DAA4D;AAC5D,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,SAAS,GACjB;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAC;IAAC,GAAG,CAAC,EAAE,QAAQ,CAAA;CAAE,GAC5F;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,SAAS,EAAE,CAAC;IAAC,GAAG,CAAC,EAAE,QAAQ,CAAA;CAAE,GACtE;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE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GAAoG;AACpG,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,GAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAe,GAAG,SAAS,EAAE,CAMlH;AAED,yFAAyF;AACzF,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,GAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAe,GAAG,MAAM,CAI9G;AA4JD;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,SAAS,EAAE,EAClB,MAAM,EAAE,OAAO,GAAG,SAAS,EAC3B,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE;AACpC,gGAAgG;AAChG,MAAM,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,GACzD;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,QAAQ,CAAA;CAAE,CA4ChC;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,MAAM,UAAQ,GAAG,MAAM,CAmBrE"}
|
package/dist/transform/styles.js
CHANGED
|
@@ -75,9 +75,9 @@ module) {
|
|
|
75
75
|
const imported = literalsOf.imports.get(name);
|
|
76
76
|
if (imported) {
|
|
77
77
|
const nodes = options?.imported?.get(`${imported.source}#${imported.name}`);
|
|
78
|
-
//
|
|
78
|
+
// Positions in a module the build named stay, for the map; any other is dropped.
|
|
79
79
|
if (nodes)
|
|
80
|
-
return nodes.map(
|
|
80
|
+
return nodes.map((n) => keepLocIn(n, options?.importedModules));
|
|
81
81
|
plan.references.push({ name: imported.name, source: imported.source, ...at });
|
|
82
82
|
// Without `imported` the host has not looked yet; with it, it looked and found nothing.
|
|
83
83
|
plan.diagnostics.push({
|
|
@@ -106,7 +106,7 @@ module) {
|
|
|
106
106
|
const id = hash(`${sourceName}:css:${name}`);
|
|
107
107
|
plan.edits.push({ start: literal.start, end: literal.end, code: `({ $fxStyle: ${JSON.stringify(id)} })` });
|
|
108
108
|
if (nodes)
|
|
109
|
-
plan.literals.push({ id, name, css: printStyle(nodes, options.minify) });
|
|
109
|
+
plan.literals.push({ id, name, css: printStyle(nodes, options.minify), nodes });
|
|
110
110
|
}
|
|
111
111
|
const scopeOf = new Map();
|
|
112
112
|
const names = new Map();
|
|
@@ -202,7 +202,9 @@ module) {
|
|
|
202
202
|
plan.scopes.push({ start: owner.start, end: owner.end, value: id });
|
|
203
203
|
nodes = scopeNodes(nodes, id, (message) => plan.diagnostics.push({ ...at, message }));
|
|
204
204
|
}
|
|
205
|
-
const printed = module
|
|
205
|
+
const printed = module
|
|
206
|
+
? printStyleWithMap(nodes, options.minify, sourceName, module, options.importedModules)
|
|
207
|
+
: { css: printStyle(nodes, options.minify) };
|
|
206
208
|
plan.styles.push({ id, scoped: scoped && !shadow, component, ...printed, ...(shadow ? { shadow: true } : {}), ...at });
|
|
207
209
|
if (shadow)
|
|
208
210
|
shadow.indexes.push(plan.styles.length - 1);
|
|
@@ -252,6 +254,17 @@ function staticMember(cls, name) {
|
|
|
252
254
|
* `css`` values named in its `static styles` become `?inline` imports of their processed CSS
|
|
253
255
|
* (the text `static styles` takes), and the class's `static styles` lists them.
|
|
254
256
|
*/
|
|
257
|
+
/**
|
|
258
|
+
* Where a component's style blocks and css`` values are served: next to the component, a path
|
|
259
|
+
* ending in `.css`. Every CSS tool in the bundler then sees CSS, and none sees TSX: Vite 8
|
|
260
|
+
* matches its transforms on the path without the query, so `card.tsx?…` would read as a .tsx.
|
|
261
|
+
* `?inline` (Vite's own) asks for the CSS as a string, for a shadow root.
|
|
262
|
+
*/
|
|
263
|
+
export const styleIds = {
|
|
264
|
+
block: (owner, index) => `${owner}.fx-${index}.css`,
|
|
265
|
+
inline: (owner, index) => `${owner}.fx-${index}.css?inline`,
|
|
266
|
+
literal: (owner, name) => `${owner}.fx-literal-${name}.css?inline`,
|
|
267
|
+
};
|
|
255
268
|
export function finishShadowStyles(plan, code, moduleId) {
|
|
256
269
|
const edits = [];
|
|
257
270
|
const imports = [];
|
|
@@ -262,7 +275,7 @@ export function finishShadowStyles(plan, code, moduleId) {
|
|
|
262
275
|
return local;
|
|
263
276
|
};
|
|
264
277
|
for (const shadow of plan.shadowClasses.values()) {
|
|
265
|
-
const blocks = shadow.indexes.map((i) => importOf(
|
|
278
|
+
const blocks = shadow.indexes.map((i) => importOf(styleIds.inline(moduleId, i)));
|
|
266
279
|
let value;
|
|
267
280
|
const prop = shadow.styles;
|
|
268
281
|
if (prop?.value) {
|
|
@@ -272,9 +285,9 @@ export function finishShadowStyles(plan, code, moduleId) {
|
|
|
272
285
|
const replacements = [];
|
|
273
286
|
walkIdentifiers(prop.value, (id) => {
|
|
274
287
|
const local = plan.names?.literals.has(id.name)
|
|
275
|
-
? importOf(
|
|
288
|
+
? importOf(styleIds.literal(moduleId, id.name))
|
|
276
289
|
: plan.names?.imports.has(id.name) && !/\.css(\?|$)/.test(plan.names.imports.get(id.name).source)
|
|
277
|
-
? importOf(
|
|
290
|
+
? importOf(styleIds.literal(plan.names.imports.get(id.name).source, plan.names.imports.get(id.name).name))
|
|
278
291
|
: undefined;
|
|
279
292
|
if (local)
|
|
280
293
|
replacements.push({ at: id.start - start, length: id.name.length, with: local });
|
|
@@ -636,17 +649,32 @@ function shiftLoc(node, source, start) {
|
|
|
636
649
|
return { ...node, loc, nodes: node.nodes.map((n) => shiftLoc(n, source, start)) };
|
|
637
650
|
return { ...node, loc };
|
|
638
651
|
}
|
|
639
|
-
function
|
|
640
|
-
const
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
652
|
+
function keepLocIn(node, modules) {
|
|
653
|
+
const keep = node.loc !== undefined && modules?.has(node.loc.source) === true;
|
|
654
|
+
const { loc, ...rest } = node;
|
|
655
|
+
const kept = keep ? { ...rest, loc } : rest;
|
|
656
|
+
if (kept.kind === 'rule' || kept.kind === 'at-rule')
|
|
657
|
+
return { ...kept, nodes: kept.nodes.map((n) => keepLocIn(n, modules)) };
|
|
658
|
+
return kept;
|
|
644
659
|
}
|
|
645
660
|
/**
|
|
646
661
|
* Prints like `printStyle`, with a map from each rule and declaration back to where it was
|
|
647
662
|
* written in the module: the browser's devtools then show the `.tsx` line, not the generated CSS.
|
|
648
663
|
*/
|
|
649
|
-
export function printStyleWithMap(nodes, minify, sourceName, module
|
|
664
|
+
export function printStyleWithMap(nodes, minify, sourceName, module,
|
|
665
|
+
/** Other modules rules came from (composed css`` values), by the name their positions carry. */
|
|
666
|
+
others) {
|
|
667
|
+
const sources = [module];
|
|
668
|
+
const index = new Map([[sourceName, 0]]);
|
|
669
|
+
const sourceOf = (name) => {
|
|
670
|
+
if (index.has(name))
|
|
671
|
+
return index.get(name);
|
|
672
|
+
const other = others?.get(name);
|
|
673
|
+
if (!other)
|
|
674
|
+
return undefined;
|
|
675
|
+
index.set(name, sources.push(other) - 1);
|
|
676
|
+
return index.get(name);
|
|
677
|
+
};
|
|
650
678
|
const lines = [[]];
|
|
651
679
|
let css = '';
|
|
652
680
|
let column = 0;
|
|
@@ -662,8 +690,9 @@ export function printStyleWithMap(nodes, minify, sourceName, module) {
|
|
|
662
690
|
}
|
|
663
691
|
};
|
|
664
692
|
const mark = (loc) => {
|
|
665
|
-
|
|
666
|
-
|
|
693
|
+
const at = loc ? sourceOf(loc.source) : undefined;
|
|
694
|
+
if (loc && at !== undefined)
|
|
695
|
+
lines[lines.length - 1].push([column, at, loc.line - 1, loc.column]);
|
|
667
696
|
};
|
|
668
697
|
const write = (node, depth) => {
|
|
669
698
|
const pad = minify ? '' : ' '.repeat(depth);
|
|
@@ -686,7 +715,7 @@ export function printStyleWithMap(nodes, minify, sourceName, module) {
|
|
|
686
715
|
};
|
|
687
716
|
for (const node of nodes)
|
|
688
717
|
write(node, 0);
|
|
689
|
-
return { css, map: { version: 3, sources:
|
|
718
|
+
return { css, map: { version: 3, sources: sources.map((s) => s.id), sourcesContent: sources.map((s) => s.code), names: [], mappings: encode(lines) } };
|
|
690
719
|
}
|
|
691
720
|
export function printStyle(nodes, minify = false) {
|
|
692
721
|
const out = [];
|
|
@@ -141,7 +141,7 @@ function collectStyles(program, sourceName, options, tags = { html: /* @__PURE__
|
|
|
141
141
|
const imported = literalsOf.imports.get(name);
|
|
142
142
|
if (imported) {
|
|
143
143
|
const nodes = options?.imported?.get(`${imported.source}#${imported.name}`);
|
|
144
|
-
if (nodes) return nodes.map(
|
|
144
|
+
if (nodes) return nodes.map((n) => keepLocIn(n, options?.importedModules));
|
|
145
145
|
plan.references.push({ name: imported.name, source: imported.source, ...at });
|
|
146
146
|
plan.diagnostics.push({
|
|
147
147
|
...at,
|
|
@@ -165,7 +165,7 @@ function collectStyles(program, sourceName, options, tags = { html: /* @__PURE__
|
|
|
165
165
|
const nodes = resolveLiteral(name, at, []);
|
|
166
166
|
const id = hash(`${sourceName}:css:${name}`);
|
|
167
167
|
plan.edits.push({ start: literal.start, end: literal.end, code: `({ $fxStyle: ${JSON.stringify(id)} })` });
|
|
168
|
-
if (nodes) plan.literals.push({ id, name, css: printStyle(nodes, options.minify) });
|
|
168
|
+
if (nodes) plan.literals.push({ id, name, css: printStyle(nodes, options.minify), nodes });
|
|
169
169
|
}
|
|
170
170
|
const scopeOf = /* @__PURE__ */ new Map();
|
|
171
171
|
const names = /* @__PURE__ */ new Map();
|
|
@@ -240,7 +240,7 @@ function collectStyles(program, sourceName, options, tags = { html: /* @__PURE__
|
|
|
240
240
|
if (!plan.scopes.some((s) => s.value === id)) plan.scopes.push({ start: owner.start, end: owner.end, value: id });
|
|
241
241
|
nodes = scopeNodes(nodes, id, (message) => plan.diagnostics.push({ ...at, message }));
|
|
242
242
|
}
|
|
243
|
-
const printed = module ? printStyleWithMap(nodes, options.minify, sourceName, module) : { css: printStyle(nodes, options.minify) };
|
|
243
|
+
const printed = module ? printStyleWithMap(nodes, options.minify, sourceName, module, options.importedModules) : { css: printStyle(nodes, options.minify) };
|
|
244
244
|
plan.styles.push({ id, scoped: scoped && !shadow, component, ...printed, ...shadow ? { shadow: true } : {}, ...at });
|
|
245
245
|
if (shadow) shadow.indexes.push(plan.styles.length - 1);
|
|
246
246
|
};
|
|
@@ -279,6 +279,11 @@ function staticMember(cls, name) {
|
|
|
279
279
|
(m) => m.type === "ClassProperty" && m.static && (m.key.type === "Identifier" && m.key.name === name || m.key.type === "StringLiteral" && m.key.value === name)
|
|
280
280
|
);
|
|
281
281
|
}
|
|
282
|
+
var styleIds = {
|
|
283
|
+
block: (owner, index) => `${owner}.fx-${index}.css`,
|
|
284
|
+
inline: (owner, index) => `${owner}.fx-${index}.css?inline`,
|
|
285
|
+
literal: (owner, name) => `${owner}.fx-literal-${name}.css?inline`
|
|
286
|
+
};
|
|
282
287
|
function finishShadowStyles(plan, code, moduleId) {
|
|
283
288
|
const edits = [];
|
|
284
289
|
const imports = [];
|
|
@@ -290,7 +295,7 @@ function finishShadowStyles(plan, code, moduleId) {
|
|
|
290
295
|
return local;
|
|
291
296
|
};
|
|
292
297
|
for (const shadow of plan.shadowClasses.values()) {
|
|
293
|
-
const blocks = shadow.indexes.map((i) => importOf(
|
|
298
|
+
const blocks = shadow.indexes.map((i) => importOf(styleIds.inline(moduleId, i)));
|
|
294
299
|
let value;
|
|
295
300
|
const prop = shadow.styles;
|
|
296
301
|
if (prop?.value) {
|
|
@@ -298,7 +303,7 @@ function finishShadowStyles(plan, code, moduleId) {
|
|
|
298
303
|
let text = code.slice(start, prop.value.end);
|
|
299
304
|
const replacements = [];
|
|
300
305
|
walkIdentifiers(prop.value, (id) => {
|
|
301
|
-
const local = plan.names?.literals.has(id.name) ? importOf(
|
|
306
|
+
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;
|
|
302
307
|
if (local) replacements.push({ at: id.start - start, length: id.name.length, with: local });
|
|
303
308
|
});
|
|
304
309
|
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);
|
|
@@ -580,12 +585,23 @@ function shiftLoc(node, source, start) {
|
|
|
580
585
|
if (node.kind === "rule" || node.kind === "at-rule") return { ...node, loc, nodes: node.nodes.map((n) => shiftLoc(n, source, start)) };
|
|
581
586
|
return { ...node, loc };
|
|
582
587
|
}
|
|
583
|
-
function
|
|
584
|
-
const
|
|
585
|
-
|
|
586
|
-
|
|
588
|
+
function keepLocIn(node, modules) {
|
|
589
|
+
const keep = node.loc !== void 0 && modules?.has(node.loc.source) === true;
|
|
590
|
+
const { loc, ...rest } = node;
|
|
591
|
+
const kept = keep ? { ...rest, loc } : rest;
|
|
592
|
+
if (kept.kind === "rule" || kept.kind === "at-rule") return { ...kept, nodes: kept.nodes.map((n) => keepLocIn(n, modules)) };
|
|
593
|
+
return kept;
|
|
587
594
|
}
|
|
588
|
-
function printStyleWithMap(nodes, minify, sourceName, module) {
|
|
595
|
+
function printStyleWithMap(nodes, minify, sourceName, module, others) {
|
|
596
|
+
const sources = [module];
|
|
597
|
+
const index = /* @__PURE__ */ new Map([[sourceName, 0]]);
|
|
598
|
+
const sourceOf = (name) => {
|
|
599
|
+
if (index.has(name)) return index.get(name);
|
|
600
|
+
const other = others?.get(name);
|
|
601
|
+
if (!other) return void 0;
|
|
602
|
+
index.set(name, sources.push(other) - 1);
|
|
603
|
+
return index.get(name);
|
|
604
|
+
};
|
|
589
605
|
const lines = [[]];
|
|
590
606
|
let css = "";
|
|
591
607
|
let column = 0;
|
|
@@ -599,7 +615,8 @@ function printStyleWithMap(nodes, minify, sourceName, module) {
|
|
|
599
615
|
}
|
|
600
616
|
};
|
|
601
617
|
const mark = (loc) => {
|
|
602
|
-
|
|
618
|
+
const at = loc ? sourceOf(loc.source) : void 0;
|
|
619
|
+
if (loc && at !== void 0) lines[lines.length - 1].push([column, at, loc.line - 1, loc.column]);
|
|
603
620
|
};
|
|
604
621
|
const write = (node, depth) => {
|
|
605
622
|
const pad = minify ? "" : " ".repeat(depth);
|
|
@@ -618,7 +635,7 @@ function printStyleWithMap(nodes, minify, sourceName, module) {
|
|
|
618
635
|
}
|
|
619
636
|
};
|
|
620
637
|
for (const node of nodes) write(node, 0);
|
|
621
|
-
return { css, map: { version: 3, sources:
|
|
638
|
+
return { css, map: { version: 3, sources: sources.map((s) => s.id), sourcesContent: sources.map((s) => s.code), names: [], mappings: encode(lines) } };
|
|
622
639
|
}
|
|
623
640
|
function printStyle(nodes, minify = false) {
|
|
624
641
|
const out = [];
|
|
@@ -649,5 +666,6 @@ export {
|
|
|
649
666
|
printStyle,
|
|
650
667
|
printStyleWithMap,
|
|
651
668
|
scopeNodes,
|
|
652
|
-
scopeSelector
|
|
669
|
+
scopeSelector,
|
|
670
|
+
styleIds
|
|
653
671
|
};
|