@csszyx/unplugin 0.12.0 → 0.13.0
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/dist/index.cjs +8 -7
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +3 -3
- package/dist/next-config.cjs +3 -0
- package/dist/next-config.d.cts +10 -0
- package/dist/next-config.d.mts +10 -0
- package/dist/next-config.mjs +3 -0
- package/dist/next-prebuild.cjs +12 -5
- package/dist/next-prebuild.d.cts +7 -0
- package/dist/next-prebuild.d.mts +7 -0
- package/dist/next-prebuild.mjs +12 -5
- package/dist/next-turbo-loader.cjs +29 -11
- package/dist/next-turbo-loader.d.cts +10 -0
- package/dist/next-turbo-loader.d.mts +10 -0
- package/dist/next-turbo-loader.mjs +28 -10
- package/dist/next-watcher.cjs +1 -1
- package/dist/next-watcher.mjs +1 -1
- package/dist/shared/unplugin.4du3qMst.cjs +529 -0
- package/dist/shared/unplugin.5l4RHMQh.mjs +578 -0
- package/dist/shared/unplugin.BB0iWSds.mjs +495 -0
- package/dist/shared/{unplugin.DMcbmP01.mjs → unplugin.BU0O4IkX.mjs} +4 -1
- package/dist/shared/{unplugin.BK3XVHe8.cjs → unplugin.Bf4fNbp7.cjs} +318 -532
- package/dist/shared/{unplugin.Bb5TeU9B.cjs → unplugin.CUTa6bY9.cjs} +89 -1
- package/dist/shared/{unplugin.DblMogcN.cjs → unplugin.Cji6O5jv.cjs} +4 -1
- package/dist/shared/{unplugin.DXgxFHzO.mjs → unplugin.CogPHmDs.mjs} +73 -3
- package/dist/shared/{unplugin.CtnKJhAi.d.cts → unplugin.DCT7DDG6.d.cts} +75 -30
- package/dist/shared/{unplugin.CtnKJhAi.d.mts → unplugin.DCT7DDG6.d.mts} +75 -30
- package/dist/shared/unplugin.X9a9SL_s.cjs +612 -0
- package/dist/shared/{unplugin.B9vpjOhD.mjs → unplugin.ymMe428s.mjs} +288 -499
- package/dist/vite.cjs +3 -3
- package/dist/vite.d.cts +2 -2
- package/dist/vite.d.mts +1 -1
- package/dist/vite.mjs +3 -3
- package/dist/webpack.cjs +3 -3
- package/dist/webpack.d.cts +2 -2
- package/dist/webpack.d.mts +1 -1
- package/dist/webpack.mjs +3 -3
- package/package.json +9 -9
- package/dist/shared/unplugin.C2lHQFii.cjs +0 -114
- package/dist/shared/unplugin.CBMJufQ8.mjs +0 -108
- package/dist/shared/unplugin.CDqY7kmk.mjs +0 -224
- package/dist/shared/unplugin.DbZ7tCfN.cjs +0 -248
|
@@ -13,9 +13,9 @@ const svelteAdapter = require('@csszyx/svelte-adapter');
|
|
|
13
13
|
const types = require('@csszyx/types');
|
|
14
14
|
const vueAdapter = require('@csszyx/vue-adapter');
|
|
15
15
|
const unplugin$1 = require('unplugin');
|
|
16
|
-
const transformCache = require('./unplugin.
|
|
16
|
+
const transformCache = require('./unplugin.4du3qMst.cjs');
|
|
17
17
|
const cssMangler = require('../css-mangler.cjs');
|
|
18
|
-
const
|
|
18
|
+
const themeGroupsFile = require('./unplugin.X9a9SL_s.cjs');
|
|
19
19
|
const htmlEscape = require('./unplugin.BkRah5Ot.cjs');
|
|
20
20
|
const node_zlib = require('node:zlib');
|
|
21
21
|
const postcss = require('postcss');
|
|
@@ -312,7 +312,7 @@ function validateCandidates(candidates, definitions, reserved, aliasPrefix) {
|
|
|
312
312
|
code: "registered-property",
|
|
313
313
|
severity: "error",
|
|
314
314
|
name,
|
|
315
|
-
message: `Registered custom property ${name}
|
|
315
|
+
message: `Registered custom property ${name} cannot be aliased: @property gives it a type and inheritance behaviour that an alias would not carry.`,
|
|
316
316
|
location: registeredDefinition
|
|
317
317
|
});
|
|
318
318
|
}
|
|
@@ -1132,237 +1132,6 @@ function maskBlockComment(code, start) {
|
|
|
1132
1132
|
return { end, value };
|
|
1133
1133
|
}
|
|
1134
1134
|
|
|
1135
|
-
const EMPTY_THEME = {
|
|
1136
|
-
colors: [],
|
|
1137
|
-
spacings: [],
|
|
1138
|
-
fonts: [],
|
|
1139
|
-
textSizes: [],
|
|
1140
|
-
fontWeights: [],
|
|
1141
|
-
radii: [],
|
|
1142
|
-
shadows: [],
|
|
1143
|
-
breakpoints: []
|
|
1144
|
-
};
|
|
1145
|
-
function findMatchingBrace(source, openBrace) {
|
|
1146
|
-
let depth = 0;
|
|
1147
|
-
for (let index = openBrace; index < source.length; index++) {
|
|
1148
|
-
if (source[index] === "{") {
|
|
1149
|
-
depth++;
|
|
1150
|
-
} else if (source[index] === "}") {
|
|
1151
|
-
depth--;
|
|
1152
|
-
if (depth === 0) {
|
|
1153
|
-
return index;
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
}
|
|
1157
|
-
return -1;
|
|
1158
|
-
}
|
|
1159
|
-
function stripLayerWrappers(css) {
|
|
1160
|
-
let result = "";
|
|
1161
|
-
let i = 0;
|
|
1162
|
-
while (i < css.length) {
|
|
1163
|
-
const layerIdx = css.indexOf("@layer", i);
|
|
1164
|
-
if (layerIdx === -1) {
|
|
1165
|
-
result += css.slice(i);
|
|
1166
|
-
break;
|
|
1167
|
-
}
|
|
1168
|
-
result += css.slice(i, layerIdx);
|
|
1169
|
-
const openBrace = css.indexOf("{", layerIdx);
|
|
1170
|
-
if (openBrace === -1) {
|
|
1171
|
-
result += css.slice(layerIdx);
|
|
1172
|
-
break;
|
|
1173
|
-
}
|
|
1174
|
-
const closeBrace = findMatchingBrace(css, openBrace);
|
|
1175
|
-
if (closeBrace === -1) {
|
|
1176
|
-
result += css.slice(openBrace);
|
|
1177
|
-
break;
|
|
1178
|
-
}
|
|
1179
|
-
result += css.slice(openBrace + 1, closeBrace);
|
|
1180
|
-
i = closeBrace + 1;
|
|
1181
|
-
}
|
|
1182
|
-
return result;
|
|
1183
|
-
}
|
|
1184
|
-
function themePreludeStart(css, at) {
|
|
1185
|
-
const cursor = at + "@theme".length;
|
|
1186
|
-
const next = css[cursor];
|
|
1187
|
-
const validBoundary = next === "{" || next === " " || next === " " || next === "\n" || next === "\r";
|
|
1188
|
-
return validBoundary ? cursor : null;
|
|
1189
|
-
}
|
|
1190
|
-
function readThemeBlock(css, start) {
|
|
1191
|
-
for (let cursor = start; cursor < css.length; cursor++) {
|
|
1192
|
-
const character = css[cursor];
|
|
1193
|
-
if (character === "{") {
|
|
1194
|
-
const close = findMatchingBrace(css, cursor);
|
|
1195
|
-
return {
|
|
1196
|
-
body: close === -1 ? null : css.slice(cursor + 1, close),
|
|
1197
|
-
end: close === -1 ? cursor : close
|
|
1198
|
-
};
|
|
1199
|
-
}
|
|
1200
|
-
if (character === ";" || character === "}" || character === "@") {
|
|
1201
|
-
return { body: null, end: cursor };
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
return { body: null, end: css.length };
|
|
1205
|
-
}
|
|
1206
|
-
function extractThemeBlocks(css) {
|
|
1207
|
-
const blocks = [];
|
|
1208
|
-
let searchFrom = 0;
|
|
1209
|
-
for (; ; ) {
|
|
1210
|
-
const at = css.indexOf("@theme", searchFrom);
|
|
1211
|
-
if (at === -1) {
|
|
1212
|
-
break;
|
|
1213
|
-
}
|
|
1214
|
-
const preludeStart = themePreludeStart(css, at);
|
|
1215
|
-
if (preludeStart === null) {
|
|
1216
|
-
searchFrom = at + "@theme".length;
|
|
1217
|
-
continue;
|
|
1218
|
-
}
|
|
1219
|
-
const match = readThemeBlock(css, preludeStart);
|
|
1220
|
-
if (match.body !== null) blocks.push(match.body);
|
|
1221
|
-
searchFrom = Math.max(match.end, at + "@theme".length);
|
|
1222
|
-
}
|
|
1223
|
-
return blocks;
|
|
1224
|
-
}
|
|
1225
|
-
function categorizeProperty(prop) {
|
|
1226
|
-
const categoryMap = [
|
|
1227
|
-
["color-", "colors"],
|
|
1228
|
-
["spacing-", "spacings"],
|
|
1229
|
-
// `font-weight-` MUST precede `font-`: startsWith would otherwise route
|
|
1230
|
-
// `font-weight-chunky` into font FAMILIES as token "weight-chunky".
|
|
1231
|
-
["font-weight-", "fontWeights"],
|
|
1232
|
-
["font-", "fonts"],
|
|
1233
|
-
// `--text-*` defines font-size utilities (text-huge) in Tailwind v4.
|
|
1234
|
-
["text-", "textSizes"],
|
|
1235
|
-
["radius-", "radii"],
|
|
1236
|
-
["shadow-", "shadows"],
|
|
1237
|
-
["breakpoint-", "breakpoints"]
|
|
1238
|
-
];
|
|
1239
|
-
for (const [prefix, category] of categoryMap) {
|
|
1240
|
-
if (prop.startsWith(prefix)) {
|
|
1241
|
-
let token = prop.slice(prefix.length);
|
|
1242
|
-
if (category !== "breakpoints") {
|
|
1243
|
-
token = token.replace(/-\d+$/, "");
|
|
1244
|
-
}
|
|
1245
|
-
if (token) {
|
|
1246
|
-
return { category, token };
|
|
1247
|
-
}
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
return null;
|
|
1251
|
-
}
|
|
1252
|
-
function parseThemeBlocks(cssContent) {
|
|
1253
|
-
const result = {
|
|
1254
|
-
colors: /* @__PURE__ */ new Set(),
|
|
1255
|
-
spacings: /* @__PURE__ */ new Set(),
|
|
1256
|
-
fonts: /* @__PURE__ */ new Set(),
|
|
1257
|
-
textSizes: /* @__PURE__ */ new Set(),
|
|
1258
|
-
fontWeights: /* @__PURE__ */ new Set(),
|
|
1259
|
-
radii: /* @__PURE__ */ new Set(),
|
|
1260
|
-
shadows: /* @__PURE__ */ new Set(),
|
|
1261
|
-
breakpoints: /* @__PURE__ */ new Set()
|
|
1262
|
-
};
|
|
1263
|
-
const stripped = stripLayerWrappers(cssContent);
|
|
1264
|
-
const blocks = extractThemeBlocks(stripped);
|
|
1265
|
-
for (const block of blocks) {
|
|
1266
|
-
for (const name of scanCustomPropertyNames(block)) {
|
|
1267
|
-
const categorized = categorizeProperty(name);
|
|
1268
|
-
if (categorized) {
|
|
1269
|
-
result[categorized.category].add(categorized.token);
|
|
1270
|
-
}
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
return {
|
|
1274
|
-
colors: htmlEscape.sortStrings(result.colors),
|
|
1275
|
-
spacings: htmlEscape.sortStrings(result.spacings),
|
|
1276
|
-
fonts: htmlEscape.sortStrings(result.fonts),
|
|
1277
|
-
textSizes: htmlEscape.sortStrings(result.textSizes),
|
|
1278
|
-
fontWeights: htmlEscape.sortStrings(result.fontWeights),
|
|
1279
|
-
radii: htmlEscape.sortStrings(result.radii),
|
|
1280
|
-
shadows: htmlEscape.sortStrings(result.shadows),
|
|
1281
|
-
breakpoints: htmlEscape.sortStrings(result.breakpoints)
|
|
1282
|
-
};
|
|
1283
|
-
}
|
|
1284
|
-
function mergeThemes(themes) {
|
|
1285
|
-
if (themes.length === 0) {
|
|
1286
|
-
return { ...EMPTY_THEME };
|
|
1287
|
-
}
|
|
1288
|
-
const merged = {
|
|
1289
|
-
colors: /* @__PURE__ */ new Set(),
|
|
1290
|
-
spacings: /* @__PURE__ */ new Set(),
|
|
1291
|
-
fonts: /* @__PURE__ */ new Set(),
|
|
1292
|
-
textSizes: /* @__PURE__ */ new Set(),
|
|
1293
|
-
fontWeights: /* @__PURE__ */ new Set(),
|
|
1294
|
-
radii: /* @__PURE__ */ new Set(),
|
|
1295
|
-
shadows: /* @__PURE__ */ new Set(),
|
|
1296
|
-
breakpoints: /* @__PURE__ */ new Set()
|
|
1297
|
-
};
|
|
1298
|
-
for (const theme of themes) {
|
|
1299
|
-
for (const cat of Object.keys(merged)) {
|
|
1300
|
-
for (const token of theme[cat]) {
|
|
1301
|
-
merged[cat].add(token);
|
|
1302
|
-
}
|
|
1303
|
-
}
|
|
1304
|
-
}
|
|
1305
|
-
return {
|
|
1306
|
-
colors: htmlEscape.sortStrings(merged.colors),
|
|
1307
|
-
spacings: htmlEscape.sortStrings(merged.spacings),
|
|
1308
|
-
fonts: htmlEscape.sortStrings(merged.fonts),
|
|
1309
|
-
textSizes: htmlEscape.sortStrings(merged.textSizes),
|
|
1310
|
-
fontWeights: htmlEscape.sortStrings(merged.fontWeights),
|
|
1311
|
-
radii: htmlEscape.sortStrings(merged.radii),
|
|
1312
|
-
shadows: htmlEscape.sortStrings(merged.shadows),
|
|
1313
|
-
breakpoints: htmlEscape.sortStrings(merged.breakpoints)
|
|
1314
|
-
};
|
|
1315
|
-
}
|
|
1316
|
-
function hasTokens(theme) {
|
|
1317
|
-
return Object.values(theme).some((arr) => arr.length > 0);
|
|
1318
|
-
}
|
|
1319
|
-
function readCustomPropertyName(block, dashes) {
|
|
1320
|
-
let end = dashes + 2;
|
|
1321
|
-
if (end >= block.length || !/[a-z]/.test(block[end])) {
|
|
1322
|
-
return null;
|
|
1323
|
-
}
|
|
1324
|
-
end++;
|
|
1325
|
-
while (end < block.length && /[a-z0-9-]/.test(block[end])) {
|
|
1326
|
-
end++;
|
|
1327
|
-
}
|
|
1328
|
-
return { name: block.slice(dashes + 2, end), end };
|
|
1329
|
-
}
|
|
1330
|
-
function findCustomPropertyDeclarationEnd(block, nameEnd) {
|
|
1331
|
-
let cursor = nameEnd;
|
|
1332
|
-
while (cursor < block.length && /\s/.test(block[cursor])) {
|
|
1333
|
-
cursor++;
|
|
1334
|
-
}
|
|
1335
|
-
if (block[cursor] === ":") {
|
|
1336
|
-
const valueStart = cursor + 1;
|
|
1337
|
-
const semicolon = block.indexOf(";", valueStart);
|
|
1338
|
-
return semicolon > valueStart ? semicolon + 1 : -1;
|
|
1339
|
-
}
|
|
1340
|
-
return block[nameEnd] === ";" ? nameEnd + 1 : -1;
|
|
1341
|
-
}
|
|
1342
|
-
function scanCustomPropertyNames(block) {
|
|
1343
|
-
const names = [];
|
|
1344
|
-
let i = 0;
|
|
1345
|
-
while (i < block.length) {
|
|
1346
|
-
const dashes = block.indexOf("--", i);
|
|
1347
|
-
if (dashes === -1) {
|
|
1348
|
-
break;
|
|
1349
|
-
}
|
|
1350
|
-
const property = readCustomPropertyName(block, dashes);
|
|
1351
|
-
if (!property) {
|
|
1352
|
-
i = dashes + 1;
|
|
1353
|
-
continue;
|
|
1354
|
-
}
|
|
1355
|
-
const matchEnd = findCustomPropertyDeclarationEnd(block, property.end);
|
|
1356
|
-
if (matchEnd === -1) {
|
|
1357
|
-
i = dashes + 1;
|
|
1358
|
-
continue;
|
|
1359
|
-
}
|
|
1360
|
-
names.push(property.name);
|
|
1361
|
-
i = matchEnd;
|
|
1362
|
-
}
|
|
1363
|
-
return names;
|
|
1364
|
-
}
|
|
1365
|
-
|
|
1366
1135
|
const REGEX_PREFIXES = new Set("([{:,;=!?&|+-*%^~<>/");
|
|
1367
1136
|
const REGEX_PREFIX_KEYWORDS = /* @__PURE__ */ new Set([
|
|
1368
1137
|
"await",
|
|
@@ -1732,6 +1501,78 @@ function collectAuthoredClassNames(source) {
|
|
|
1732
1501
|
return classes;
|
|
1733
1502
|
}
|
|
1734
1503
|
|
|
1504
|
+
const KNOWN_TOP_LEVEL_KEYS = /* @__PURE__ */ new Set([
|
|
1505
|
+
"include",
|
|
1506
|
+
"exclude",
|
|
1507
|
+
"compileSources",
|
|
1508
|
+
"contentScopeCheck",
|
|
1509
|
+
"quiet",
|
|
1510
|
+
"mode",
|
|
1511
|
+
"development",
|
|
1512
|
+
"production",
|
|
1513
|
+
"build",
|
|
1514
|
+
"hydration"
|
|
1515
|
+
]);
|
|
1516
|
+
const RENAMED_KEYS = {
|
|
1517
|
+
// Replaced by the path-based form: package NAMES could not express a
|
|
1518
|
+
// sibling directory outside the project root, and resolving them meant
|
|
1519
|
+
// guessing at workspace layout.
|
|
1520
|
+
compilePackages: "compileSources"
|
|
1521
|
+
};
|
|
1522
|
+
function nearestKnownConfigKey(key) {
|
|
1523
|
+
const lower = key.toLowerCase();
|
|
1524
|
+
let best = null;
|
|
1525
|
+
let bestDistance = Number.POSITIVE_INFINITY;
|
|
1526
|
+
for (const candidate of KNOWN_TOP_LEVEL_KEYS) {
|
|
1527
|
+
const distance = editDistance(lower, candidate.toLowerCase());
|
|
1528
|
+
if (distance < bestDistance) {
|
|
1529
|
+
bestDistance = distance;
|
|
1530
|
+
best = candidate;
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
return best !== null && bestDistance <= Math.max(1, Math.floor(key.length / 4)) ? best : null;
|
|
1534
|
+
}
|
|
1535
|
+
function editDistance(a, b) {
|
|
1536
|
+
let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
|
|
1537
|
+
for (let i = 1; i <= a.length; i += 1) {
|
|
1538
|
+
const current = [i];
|
|
1539
|
+
for (let j = 1; j <= b.length; j += 1) {
|
|
1540
|
+
const substitution = previous[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1);
|
|
1541
|
+
current.push(Math.min(substitution, previous[j] + 1, current[j - 1] + 1));
|
|
1542
|
+
}
|
|
1543
|
+
previous = current;
|
|
1544
|
+
}
|
|
1545
|
+
return previous[b.length];
|
|
1546
|
+
}
|
|
1547
|
+
function findUnknownConfigKeys(options) {
|
|
1548
|
+
if (options === null || typeof options !== "object" || Array.isArray(options)) {
|
|
1549
|
+
return [];
|
|
1550
|
+
}
|
|
1551
|
+
const unknown = [];
|
|
1552
|
+
for (const key of Object.keys(options)) {
|
|
1553
|
+
if (KNOWN_TOP_LEVEL_KEYS.has(key)) continue;
|
|
1554
|
+
const renamedTo = RENAMED_KEYS[key];
|
|
1555
|
+
if (renamedTo !== void 0) {
|
|
1556
|
+
unknown.push({ key, renamedTo });
|
|
1557
|
+
continue;
|
|
1558
|
+
}
|
|
1559
|
+
const suggestion = nearestKnownConfigKey(key);
|
|
1560
|
+
unknown.push(suggestion === null ? { key } : { key, suggestion });
|
|
1561
|
+
}
|
|
1562
|
+
return unknown;
|
|
1563
|
+
}
|
|
1564
|
+
function unknownConfigKeysMessage(unknown) {
|
|
1565
|
+
const lines = unknown.map((entry) => {
|
|
1566
|
+
if (entry.renamedTo !== void 0) {
|
|
1567
|
+
return ` - \`${entry.key}\` was replaced by \`${entry.renamedTo}\``;
|
|
1568
|
+
}
|
|
1569
|
+
return entry.suggestion === void 0 ? ` - \`${entry.key}\`` : ` - \`${entry.key}\` \u2014 did you mean \`${entry.suggestion}\`?`;
|
|
1570
|
+
});
|
|
1571
|
+
return `[csszyx] ${unknown.length} plugin option(s) are not recognized and have no effect:
|
|
1572
|
+
${lines.join("\n")}
|
|
1573
|
+
An unread option is silent, so whatever you configured it for is not happening.`;
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1735
1576
|
const GLOB_MAGIC_RE = /[*?[\]{}]/;
|
|
1736
1577
|
const DEFAULT_IGNORED_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git", ".next", ".turbo", "dist", "build"]);
|
|
1737
1578
|
function normalizeFileId(id) {
|
|
@@ -2081,41 +1922,6 @@ function isSameFileVersion(before, after) {
|
|
|
2081
1922
|
return before.dev === after.dev && before.ino === after.ino && before.size === after.size && before.mtimeNs === after.mtimeNs && before.ctimeNs === after.ctimeNs;
|
|
2082
1923
|
}
|
|
2083
1924
|
|
|
2084
|
-
function recordSzvRegistryFile(registry, filePath, content) {
|
|
2085
|
-
const key = transformCache.normalizePathSeparators(filePath);
|
|
2086
|
-
const qualifies = content.includes("szv(") && content.includes("export");
|
|
2087
|
-
const entries = qualifies ? compiler.extractSzvRegistryEntries(content, filePath) : [];
|
|
2088
|
-
if (entries.length === 0) {
|
|
2089
|
-
registry.delete(key);
|
|
2090
|
-
return;
|
|
2091
|
-
}
|
|
2092
|
-
const byName = {};
|
|
2093
|
-
for (const entry of entries) {
|
|
2094
|
-
byName[entry.exportName] = entry.config;
|
|
2095
|
-
}
|
|
2096
|
-
registry.set(key, byName);
|
|
2097
|
-
}
|
|
2098
|
-
const SPECIFIER_PROBES = ["", ".ts", ".tsx", ".js", ".jsx", "/index.ts", "/index.tsx"];
|
|
2099
|
-
function resolveCrossModuleStaticsFor(registry, filename, source) {
|
|
2100
|
-
if (registry.size === 0 || !source.includes("from")) return void 0;
|
|
2101
|
-
const directory = path__namespace.dirname(filename);
|
|
2102
|
-
let resolved;
|
|
2103
|
-
for (const match of source.matchAll(/from\s*['"](\.[^'"]*)['"]/g)) {
|
|
2104
|
-
const specifier = match[1];
|
|
2105
|
-
if (resolved?.[specifier] !== void 0) continue;
|
|
2106
|
-
const base = transformCache.normalizePathSeparators(path__namespace.resolve(directory, specifier));
|
|
2107
|
-
for (const probe of SPECIFIER_PROBES) {
|
|
2108
|
-
const entries = registry.get(`${base}${probe}`);
|
|
2109
|
-
if (entries !== void 0) {
|
|
2110
|
-
resolved ??= {};
|
|
2111
|
-
resolved[specifier] = entries;
|
|
2112
|
-
break;
|
|
2113
|
-
}
|
|
2114
|
-
}
|
|
2115
|
-
}
|
|
2116
|
-
return resolved;
|
|
2117
|
-
}
|
|
2118
|
-
|
|
2119
1925
|
function generateThemeDts(opts) {
|
|
2120
1926
|
const { theme, sourceFiles } = opts;
|
|
2121
1927
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -2187,127 +1993,6 @@ function writeThemeDts(opts) {
|
|
|
2187
1993
|
fs.writeFileSync(opts.outputPath, content, "utf-8");
|
|
2188
1994
|
}
|
|
2189
1995
|
|
|
2190
|
-
const VIRTUAL_MODULE_ID = "virtual:csszyx/mangle-map";
|
|
2191
|
-
const RESOLVED_VIRTUAL_MODULE_ID = `\0${VIRTUAL_MODULE_ID}`;
|
|
2192
|
-
const THEME_GROUPS_VIRTUAL_ID = "virtual:csszyx/theme-groups";
|
|
2193
|
-
const RESOLVED_THEME_GROUPS_VIRTUAL_ID = `\0${THEME_GROUPS_VIRTUAL_ID}`;
|
|
2194
|
-
const VIRTUAL_CHECKSUM_ID = "virtual:csszyx/checksum";
|
|
2195
|
-
const RESOLVED_VIRTUAL_CHECKSUM_ID = `\0${VIRTUAL_CHECKSUM_ID}`;
|
|
2196
|
-
function createMangleMapModule(mangleMap, checksum, varMangleMap = {}, cssVarMetrics = null) {
|
|
2197
|
-
return `/**
|
|
2198
|
-
* Auto-generated mangle map for csszyx.
|
|
2199
|
-
* This module is generated at build time and contains the mapping
|
|
2200
|
-
* from original class names and CSS variable names to mangled names.
|
|
2201
|
-
*
|
|
2202
|
-
* @generated
|
|
2203
|
-
*/
|
|
2204
|
-
|
|
2205
|
-
export const mangleMap = ${JSON.stringify(mangleMap, null, 2)};
|
|
2206
|
-
|
|
2207
|
-
export const varMangleMap = ${JSON.stringify(varMangleMap, null, 2)};
|
|
2208
|
-
|
|
2209
|
-
export const cssVarMetrics = ${JSON.stringify(cssVarMetrics, null, 2)};
|
|
2210
|
-
|
|
2211
|
-
export const checksum = ${JSON.stringify(checksum)};
|
|
2212
|
-
|
|
2213
|
-
export default {
|
|
2214
|
-
mangleMap,
|
|
2215
|
-
varMangleMap,
|
|
2216
|
-
cssVarMetrics,
|
|
2217
|
-
checksum,
|
|
2218
|
-
};
|
|
2219
|
-
`;
|
|
2220
|
-
}
|
|
2221
|
-
function createChecksumModule(checksum) {
|
|
2222
|
-
return `/**
|
|
2223
|
-
* Auto-generated checksum for csszyx mangle map.
|
|
2224
|
-
*
|
|
2225
|
-
* @generated
|
|
2226
|
-
*/
|
|
2227
|
-
|
|
2228
|
-
export const checksum = ${JSON.stringify(checksum)};
|
|
2229
|
-
|
|
2230
|
-
export default checksum;
|
|
2231
|
-
`;
|
|
2232
|
-
}
|
|
2233
|
-
function isVirtualModule(id) {
|
|
2234
|
-
return id === VIRTUAL_MODULE_ID || id === VIRTUAL_CHECKSUM_ID || id === THEME_GROUPS_VIRTUAL_ID || id === MANGLE_RUNTIME_VIRTUAL_ID;
|
|
2235
|
-
}
|
|
2236
|
-
function resolveVirtualModule(id) {
|
|
2237
|
-
if (id === VIRTUAL_MODULE_ID) {
|
|
2238
|
-
return RESOLVED_VIRTUAL_MODULE_ID;
|
|
2239
|
-
}
|
|
2240
|
-
if (id === VIRTUAL_CHECKSUM_ID) {
|
|
2241
|
-
return RESOLVED_VIRTUAL_CHECKSUM_ID;
|
|
2242
|
-
}
|
|
2243
|
-
if (id === THEME_GROUPS_VIRTUAL_ID) {
|
|
2244
|
-
return RESOLVED_THEME_GROUPS_VIRTUAL_ID;
|
|
2245
|
-
}
|
|
2246
|
-
if (id === MANGLE_RUNTIME_VIRTUAL_ID) {
|
|
2247
|
-
return RESOLVED_MANGLE_RUNTIME_VIRTUAL_ID;
|
|
2248
|
-
}
|
|
2249
|
-
return void 0;
|
|
2250
|
-
}
|
|
2251
|
-
const MANGLE_RUNTIME_VIRTUAL_ID = "virtual:csszyx/mangle-runtime";
|
|
2252
|
-
const RESOLVED_MANGLE_RUNTIME_VIRTUAL_ID = `\0${MANGLE_RUNTIME_VIRTUAL_ID}`;
|
|
2253
|
-
const MANGLE_MAP_PLACEHOLDER = "___CSSZYX_MANGLE_MAP___";
|
|
2254
|
-
const VAR_MANGLE_MAP_PLACEHOLDER = "___CSSZYX_VAR_MANGLE_MAP___";
|
|
2255
|
-
const CHECKSUM_PLACEHOLDER = "___CSSZYX_CHECKSUM___";
|
|
2256
|
-
function createMangleRuntimeModule(globalVarAliasPrefix) {
|
|
2257
|
-
return `/**
|
|
2258
|
-
* Auto-generated by csszyx: installs the runtime mangle map from the bundle.
|
|
2259
|
-
*
|
|
2260
|
-
* @generated
|
|
2261
|
-
*/
|
|
2262
|
-
|
|
2263
|
-
const m = ${MANGLE_MAP_PLACEHOLDER};
|
|
2264
|
-
const vm = ${VAR_MANGLE_MAP_PLACEHOLDER};
|
|
2265
|
-
const gp = ${JSON.stringify(globalVarAliasPrefix)};
|
|
2266
|
-
const checksum = "${CHECKSUM_PLACEHOLDER}";
|
|
2267
|
-
|
|
2268
|
-
if (typeof window !== 'undefined' && !window.__csszyx) {
|
|
2269
|
-
const r = {};
|
|
2270
|
-
const vr = {};
|
|
2271
|
-
for (const k in m) r[m[k]] = k;
|
|
2272
|
-
for (const vk in vm) {
|
|
2273
|
-
const vv = vm[vk];
|
|
2274
|
-
const vs = Array.isArray(vv) ? vv : [vv];
|
|
2275
|
-
for (const v of vs) (vr[v] || (vr[v] = [])).push(vk);
|
|
2276
|
-
}
|
|
2277
|
-
window.__csszyx = {
|
|
2278
|
-
mangleMap: m,
|
|
2279
|
-
varMangleMap: vm,
|
|
2280
|
-
checksum,
|
|
2281
|
-
decode: (c) => r[c],
|
|
2282
|
-
encode: (c) => m[c],
|
|
2283
|
-
decodeVar: (v) => vr[v] || [],
|
|
2284
|
-
encodeVar: (v) => vm[v],
|
|
2285
|
-
decodeGlobalVar: (v) => {
|
|
2286
|
-
const a = vr[v] || [];
|
|
2287
|
-
return v.indexOf(gp) === 0 ? a[0] : undefined;
|
|
2288
|
-
},
|
|
2289
|
-
decodeAll: (el) => (el.className || '').split(' ').map((c) => r[c] || c),
|
|
2290
|
-
};
|
|
2291
|
-
}
|
|
2292
|
-
|
|
2293
|
-
export {};
|
|
2294
|
-
`;
|
|
2295
|
-
}
|
|
2296
|
-
function createThemeGroupsModule(tokens) {
|
|
2297
|
-
const payload = JSON.stringify({
|
|
2298
|
-
colors: tokens.colors,
|
|
2299
|
-
textSizes: tokens.textSizes,
|
|
2300
|
-
fontFamilies: tokens.fontFamilies,
|
|
2301
|
-
fontWeights: tokens.fontWeights
|
|
2302
|
-
});
|
|
2303
|
-
return [
|
|
2304
|
-
"// Auto-generated by csszyx from the @theme blocks in scanned CSS.",
|
|
2305
|
-
"import { registerSzcnGroups } from '@csszyx/runtime';",
|
|
2306
|
-
`registerSzcnGroups(${payload});`,
|
|
2307
|
-
"export {};"
|
|
2308
|
-
].join("\n");
|
|
2309
|
-
}
|
|
2310
|
-
|
|
2311
1996
|
function registerWebpackAssetProcessor(compiler, processAssets) {
|
|
2312
1997
|
compiler.hooks.compilation.tap("csszyx:post", (compilation) => {
|
|
2313
1998
|
const stage = compiler.webpack?.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE || compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE;
|
|
@@ -2350,9 +2035,9 @@ let _hasWarnedTransformCacheVersion = false;
|
|
|
2350
2035
|
let _hasWarnedNativeFallback = false;
|
|
2351
2036
|
const _loggedActiveParsers = /* @__PURE__ */ new Set();
|
|
2352
2037
|
const _babelFallbackFiles = /* @__PURE__ */ new Set();
|
|
2353
|
-
const requireFromHere = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/unplugin.
|
|
2038
|
+
const requireFromHere = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/unplugin.Bf4fNbp7.cjs', document.baseURI).href)));
|
|
2354
2039
|
const PLUGIN_VERSION = findPackageVersionFromFile(
|
|
2355
|
-
node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/unplugin.
|
|
2040
|
+
node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/unplugin.Bf4fNbp7.cjs', document.baseURI).href))),
|
|
2356
2041
|
UNKNOWN_PACKAGE_VERSION
|
|
2357
2042
|
);
|
|
2358
2043
|
const COMPILER_VERSION = findPackageVersionFromModule("@csszyx/compiler", UNKNOWN_PACKAGE_VERSION);
|
|
@@ -2496,17 +2181,23 @@ function shouldWarnUnscopedMonorepo(sawTailwindEntry, tailwindEntryScoped, inMon
|
|
|
2496
2181
|
function unscopedMonorepoMessage() {
|
|
2497
2182
|
return '[csszyx] Tailwind content detection is UNSCOPED in a monorepo. Tailwind v4 climbs to the workspace root and scans sibling packages + docs (.md/.mdx/.txt are not ignored), which can generate phantom or broken url() classes and fail the build. Scope it in your Tailwind CSS entry:\n @import "tailwindcss" source(none);\n @source "."; /* this package, relative to the CSS file */\ncsszyx auto-injects @source for its generated classes, so only your own templates need listing. Guide: https://csszyx.com/docs/monorepo-content-scope/\nSilence (if a broad scan is intentional): csszyx({ contentScopeCheck: false }).';
|
|
2498
2183
|
}
|
|
2184
|
+
function resolveQuietMode(quiet) {
|
|
2185
|
+
if (quiet === true || quiet === "all") return "all";
|
|
2186
|
+
if (quiet === "nudges") return "nudges";
|
|
2187
|
+
return "off";
|
|
2188
|
+
}
|
|
2499
2189
|
function shouldEmitWarning(quiet, devOnly, isProduction) {
|
|
2500
|
-
|
|
2190
|
+
const mode = resolveQuietMode(quiet);
|
|
2191
|
+
if (mode === "all") {
|
|
2501
2192
|
return false;
|
|
2502
2193
|
}
|
|
2503
|
-
if (devOnly && isProduction) {
|
|
2194
|
+
if (devOnly && (isProduction || mode === "nudges")) {
|
|
2504
2195
|
return false;
|
|
2505
2196
|
}
|
|
2506
2197
|
return true;
|
|
2507
2198
|
}
|
|
2508
2199
|
function shouldEmitMissingCssFallback(quiet, message) {
|
|
2509
|
-
return
|
|
2200
|
+
return resolveQuietMode(quiet) !== "all" && compiler.szFallbackConsequenceOf(message) === "missing-css";
|
|
2510
2201
|
}
|
|
2511
2202
|
function emitMissingCssFallback(quiet, message, id, emit) {
|
|
2512
2203
|
if (shouldEmitMissingCssFallback(quiet, message)) emit(`[csszyx] ${id}
|
|
@@ -2616,11 +2307,13 @@ function isPackagesSkippedSource(id, sourceDirs = []) {
|
|
|
2616
2307
|
}
|
|
2617
2308
|
return !isCompileSourceOptedIn(p, sourceDirs);
|
|
2618
2309
|
}
|
|
2619
|
-
function skippedSzFilesMessage(files) {
|
|
2310
|
+
function skippedSzFilesMessage(files, szvExportFiles = []) {
|
|
2620
2311
|
const list = files.map((file) => ` - ${file}`).join("\n");
|
|
2621
|
-
|
|
2312
|
+
const registryClause = szvExportFiles.length === 0 ? "" : `
|
|
2313
|
+
${szvExportFiles.length} of them may export \`szv\` factories, so they stay out of the cross-module registry and every importer falls back to the runtime path.`;
|
|
2314
|
+
return `[csszyx] ${files.length} file(s) under packages/ use csszyx but were skipped by ignore rules:
|
|
2622
2315
|
${list}
|
|
2623
|
-
Add the package directory to \`compileSources\` (or move the file out of packages/) \u2014 otherwise their
|
|
2316
|
+
Add the package directory to \`compileSources\` (or move the file out of packages/) \u2014 otherwise their classes never reach the safelist.` + registryClause;
|
|
2624
2317
|
}
|
|
2625
2318
|
function computeSafelistRelPath(rootDir, safelistFilename, cssId) {
|
|
2626
2319
|
const safelistPath = transformCache.normalizePathSeparators(path__namespace.join(rootDir, safelistFilename));
|
|
@@ -2944,12 +2637,12 @@ function runThemeScan(rootDir, scanCss) {
|
|
|
2944
2637
|
}
|
|
2945
2638
|
const themes = sourceFiles.map((f) => {
|
|
2946
2639
|
try {
|
|
2947
|
-
return parseThemeBlocks(readStableTextFileSnapshotSync(f).source);
|
|
2640
|
+
return themeGroupsFile.parseThemeBlocks(readStableTextFileSnapshotSync(f).source);
|
|
2948
2641
|
} catch {
|
|
2949
2642
|
return null;
|
|
2950
2643
|
}
|
|
2951
2644
|
}).filter((t) => t !== null);
|
|
2952
|
-
const merged = mergeThemes(themes);
|
|
2645
|
+
const merged = themeGroupsFile.mergeThemes(themes);
|
|
2953
2646
|
const outputPath = path__namespace.join(rootDir, ".csszyx", "theme.d.ts");
|
|
2954
2647
|
writeThemeDts({ outputPath, theme: merged, sourceFiles });
|
|
2955
2648
|
if (!_hasWarnedTsConfig) {
|
|
@@ -3017,7 +2710,7 @@ function matchesScriptExtension(id, extensions) {
|
|
|
3017
2710
|
return extensions.some((ext) => id.endsWith(ext) || id.includes(`${ext}?`));
|
|
3018
2711
|
}
|
|
3019
2712
|
function insertRuntimeImport(code, importStmt) {
|
|
3020
|
-
return
|
|
2713
|
+
return themeGroupsFile.insertAfterUseDirective(code, importStmt);
|
|
3021
2714
|
}
|
|
3022
2715
|
function scanClassExpression(source, from) {
|
|
3023
2716
|
let depth = 0;
|
|
@@ -3261,12 +2954,12 @@ ${errors.join("\n")}`
|
|
|
3261
2954
|
if (config?.enabled === true) {
|
|
3262
2955
|
if (!config.tokens || config.tokens.length === 0) {
|
|
3263
2956
|
throw new Error(
|
|
3264
|
-
"[csszyx] production.mangleGlobalVars.enabled requires explicit tokens
|
|
2957
|
+
"[csszyx] production.mangleGlobalVars.enabled requires explicit tokens. Aliasing a property csszyx was not told about would rename references it cannot see."
|
|
3265
2958
|
);
|
|
3266
2959
|
}
|
|
3267
2960
|
if (config.autoPrefix !== void 0 && config.autoPrefix !== "") {
|
|
3268
2961
|
throw new Error(
|
|
3269
|
-
"[csszyx] production.mangleGlobalVars.autoPrefix
|
|
2962
|
+
"[csszyx] production.mangleGlobalVars.autoPrefix is not available: choosing tokens by prefix needs a CSS pre-scan that does not exist yet. List the tokens instead."
|
|
3270
2963
|
);
|
|
3271
2964
|
}
|
|
3272
2965
|
}
|
|
@@ -3274,8 +2967,10 @@ ${errors.join("\n")}`
|
|
|
3274
2967
|
function createCsszyxPlugins(options = {}) {
|
|
3275
2968
|
assertGlobalVarMangleConfig(options);
|
|
3276
2969
|
let manglingEnabled = options.production?.mangle === true;
|
|
3277
|
-
|
|
2970
|
+
const importedStaticSzEnabled = options.build?.importedStaticSz ?? types.DEFAULT_IMPORTED_STATIC_SZ;
|
|
3278
2971
|
const szvCrossModuleRegistry = /* @__PURE__ */ new Map();
|
|
2972
|
+
const szObjectProvidersExamined = /* @__PURE__ */ new Set();
|
|
2973
|
+
let specifierAliases = [];
|
|
3279
2974
|
const mangleReserved = new Set(options.production?.mangleExclude ?? []);
|
|
3280
2975
|
const mangleMapDelivery = options.production?.mangleMapDelivery ?? "both";
|
|
3281
2976
|
if (!["both", "html", "bundle"].includes(mangleMapDelivery)) {
|
|
@@ -3307,7 +3002,11 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3307
3002
|
);
|
|
3308
3003
|
}
|
|
3309
3004
|
const compileSources = options.compileSources ?? [];
|
|
3310
|
-
const quiet = options.quiet
|
|
3005
|
+
const quiet = resolveQuietMode(options.quiet);
|
|
3006
|
+
const unknownConfigKeys = findUnknownConfigKeys(options);
|
|
3007
|
+
if (unknownConfigKeys.length > 0) {
|
|
3008
|
+
emitWarning(unknownConfigKeysMessage(unknownConfigKeys));
|
|
3009
|
+
}
|
|
3311
3010
|
function emitWarning(message, opts = {}) {
|
|
3312
3011
|
if (shouldEmitWarning(quiet, opts.devOnly ?? false, process.env.NODE_ENV === "production")) {
|
|
3313
3012
|
console.warn(message);
|
|
@@ -3344,6 +3043,7 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3344
3043
|
const state = {
|
|
3345
3044
|
classes: /* @__PURE__ */ new Set(),
|
|
3346
3045
|
parsedTheme: null,
|
|
3046
|
+
scanCssTheme: null,
|
|
3347
3047
|
autoThemeCssFiles: [],
|
|
3348
3048
|
sawTailwindEntry: false,
|
|
3349
3049
|
sawAnyCss: false,
|
|
@@ -3352,6 +3052,7 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3352
3052
|
contentScopeWarningEmitted: false,
|
|
3353
3053
|
spreadWarnings: /* @__PURE__ */ new Set(),
|
|
3354
3054
|
skippedSzFiles: /* @__PURE__ */ new Set(),
|
|
3055
|
+
skippedSzvExportFiles: /* @__PURE__ */ new Set(),
|
|
3355
3056
|
skipWarningEmitted: false,
|
|
3356
3057
|
classesCapped: false,
|
|
3357
3058
|
ownedClasses: /* @__PURE__ */ new Set(),
|
|
@@ -3446,56 +3147,14 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3446
3147
|
}
|
|
3447
3148
|
}
|
|
3448
3149
|
function runAutoThemeScan(rootDir) {
|
|
3449
|
-
if (options.build?.scanCss) {
|
|
3450
|
-
return;
|
|
3451
|
-
}
|
|
3452
3150
|
refreshCompileSourceDirs();
|
|
3453
|
-
const
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
}
|
|
3461
|
-
for (const entry of entries) {
|
|
3462
|
-
if (entry.isDirectory()) {
|
|
3463
|
-
if (!IGNORE_DIRS.has(entry.name) && !entry.name.startsWith(".")) {
|
|
3464
|
-
walk(path__namespace.join(dir, entry.name));
|
|
3465
|
-
}
|
|
3466
|
-
continue;
|
|
3467
|
-
}
|
|
3468
|
-
if (entry.name.endsWith(".css")) {
|
|
3469
|
-
cssFiles.push(path__namespace.join(dir, entry.name));
|
|
3470
|
-
}
|
|
3471
|
-
}
|
|
3472
|
-
};
|
|
3473
|
-
walk(rootDir);
|
|
3474
|
-
const normRoot = normalizeForMatch(rootDir);
|
|
3475
|
-
for (const sourceDir of compileSourceDirs) {
|
|
3476
|
-
if (sourceDir === normRoot || sourceDir.startsWith(`${normRoot}/`)) {
|
|
3477
|
-
continue;
|
|
3478
|
-
}
|
|
3479
|
-
walk(sourceDir);
|
|
3480
|
-
}
|
|
3481
|
-
const themes = [];
|
|
3482
|
-
const themeFiles = [];
|
|
3483
|
-
for (const file of cssFiles) {
|
|
3484
|
-
let content;
|
|
3485
|
-
try {
|
|
3486
|
-
content = fs__namespace.readFileSync(file, "utf-8");
|
|
3487
|
-
} catch {
|
|
3488
|
-
continue;
|
|
3489
|
-
}
|
|
3490
|
-
if (!content.includes("@theme")) {
|
|
3491
|
-
continue;
|
|
3492
|
-
}
|
|
3493
|
-
themes.push(parseThemeBlocks(content));
|
|
3494
|
-
themeFiles.push(file);
|
|
3495
|
-
}
|
|
3496
|
-
state.autoThemeCssFiles = themeFiles;
|
|
3497
|
-
if (themes.length > 0) {
|
|
3498
|
-
state.parsedTheme = mergeThemes(themes);
|
|
3151
|
+
const discovered = themeGroupsFile.discoverProjectTheme(rootDir, [...compileSourceDirs]);
|
|
3152
|
+
state.autoThemeCssFiles = discovered.files;
|
|
3153
|
+
const sources = [state.scanCssTheme, discovered.theme].filter(
|
|
3154
|
+
(theme) => theme !== null
|
|
3155
|
+
);
|
|
3156
|
+
if (sources.length > 0) {
|
|
3157
|
+
state.parsedTheme = themeGroupsFile.mergeThemes(sources);
|
|
3499
3158
|
}
|
|
3500
3159
|
}
|
|
3501
3160
|
function isHardIgnored(id) {
|
|
@@ -3511,13 +3170,17 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3511
3170
|
function transformConfiguredSource(source, filename, astBudget) {
|
|
3512
3171
|
const compilerOptions = createCompilerOptions(astBudget);
|
|
3513
3172
|
const effectiveFilename = normalizeSourceFilename(filename);
|
|
3514
|
-
const crossModuleStatics = resolveCrossModuleStaticsFor(
|
|
3173
|
+
const crossModuleStatics = transformCache.resolveCrossModuleStaticsFor(
|
|
3515
3174
|
szvCrossModuleRegistry,
|
|
3516
3175
|
filename,
|
|
3517
|
-
source
|
|
3176
|
+
source,
|
|
3177
|
+
specifierAliases
|
|
3518
3178
|
);
|
|
3519
|
-
if (crossModuleStatics !== void 0) {
|
|
3520
|
-
compilerOptions.crossModuleStatics = crossModuleStatics;
|
|
3179
|
+
if (crossModuleStatics.szvConfigs !== void 0) {
|
|
3180
|
+
compilerOptions.crossModuleStatics = crossModuleStatics.szvConfigs;
|
|
3181
|
+
}
|
|
3182
|
+
if (crossModuleStatics.szObjects !== void 0) {
|
|
3183
|
+
compilerOptions.crossModuleSzObjects = crossModuleStatics.szObjects;
|
|
3521
3184
|
}
|
|
3522
3185
|
const cacheRoot = transformCache.resolveTransformCacheDir(state.rootDir, options.build?.cacheDir);
|
|
3523
3186
|
if (cacheEnabled) {
|
|
@@ -3634,6 +3297,7 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3634
3297
|
// module A's config change must miss B's cached transform, or the
|
|
3635
3298
|
// cache serves a stale table.
|
|
3636
3299
|
crossModuleStatics: compilerOptions.crossModuleStatics === void 0 ? void 0 : JSON.stringify(compilerOptions.crossModuleStatics),
|
|
3300
|
+
crossModuleSzObjects: compilerOptions.crossModuleSzObjects === void 0 ? void 0 : JSON.stringify(compilerOptions.crossModuleSzObjects),
|
|
3637
3301
|
filename: effectiveFilename,
|
|
3638
3302
|
source
|
|
3639
3303
|
};
|
|
@@ -3642,19 +3306,35 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3642
3306
|
if (parserMode !== "rust" || files.length <= 1) {
|
|
3643
3307
|
return transformPrescanSourcesIndividually(files);
|
|
3644
3308
|
}
|
|
3309
|
+
const perFile = [];
|
|
3310
|
+
const batchable = [];
|
|
3311
|
+
for (const file of files) {
|
|
3312
|
+
(hasCrossModuleStatics(file) ? perFile : batchable).push(file);
|
|
3313
|
+
}
|
|
3314
|
+
const individual = transformPrescanSourcesIndividually(perFile);
|
|
3645
3315
|
const compilerOptions = createCompilerOptions(prescanAstBudget);
|
|
3646
3316
|
const cacheRoot = transformCache.resolveTransformCacheDir(state.rootDir, options.build?.cacheDir);
|
|
3647
3317
|
const results = /* @__PURE__ */ new Map();
|
|
3648
3318
|
if (cacheEnabled) evictTransformCacheOnce();
|
|
3649
3319
|
compiler.ensureRustTransformAvailable();
|
|
3650
|
-
const misses = collectRustPrescanMisses(
|
|
3651
|
-
if (misses.length
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3320
|
+
const misses = collectRustPrescanMisses(batchable, compilerOptions, cacheRoot, results);
|
|
3321
|
+
if (misses.length > 0) {
|
|
3322
|
+
try {
|
|
3323
|
+
runRustPrescanBatch(misses, compilerOptions, cacheRoot, results);
|
|
3324
|
+
} catch {
|
|
3325
|
+
runRustPrescanFallback(misses, results);
|
|
3326
|
+
}
|
|
3656
3327
|
}
|
|
3657
|
-
return orderPrescanResults(
|
|
3328
|
+
return [...individual, ...orderPrescanResults(batchable, results)];
|
|
3329
|
+
}
|
|
3330
|
+
function hasCrossModuleStatics(file) {
|
|
3331
|
+
const resolved = transformCache.resolveCrossModuleStaticsFor(
|
|
3332
|
+
szvCrossModuleRegistry,
|
|
3333
|
+
file.filePath,
|
|
3334
|
+
file.content,
|
|
3335
|
+
specifierAliases
|
|
3336
|
+
);
|
|
3337
|
+
return resolved.szvConfigs !== void 0 || resolved.szObjects !== void 0;
|
|
3658
3338
|
}
|
|
3659
3339
|
function collectRustPrescanMisses(files, compilerOptions, cacheRoot, results) {
|
|
3660
3340
|
const misses = [];
|
|
@@ -3802,7 +3482,7 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3802
3482
|
}
|
|
3803
3483
|
}
|
|
3804
3484
|
function recordPackagesSkipIfSz(filePath) {
|
|
3805
|
-
if (!isPackagesSkippedSource(filePath, compileSourceDirs)) {
|
|
3485
|
+
if (state.skippedSzFiles.has(filePath) || !isPackagesSkippedSource(filePath, compileSourceDirs)) {
|
|
3806
3486
|
return;
|
|
3807
3487
|
}
|
|
3808
3488
|
let content;
|
|
@@ -3811,8 +3491,12 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3811
3491
|
} catch {
|
|
3812
3492
|
return;
|
|
3813
3493
|
}
|
|
3814
|
-
if (
|
|
3815
|
-
|
|
3494
|
+
if (!fileMayContainSafelistableSz(content)) {
|
|
3495
|
+
return;
|
|
3496
|
+
}
|
|
3497
|
+
state.skippedSzFiles.add(filePath);
|
|
3498
|
+
if (transformCache.mayExportSzvFactories(content)) {
|
|
3499
|
+
state.skippedSzvExportFiles.add(filePath);
|
|
3816
3500
|
}
|
|
3817
3501
|
}
|
|
3818
3502
|
function processPrescanTransform(filePath, content, result, discoveredClasses, rawDiscoveredClasses) {
|
|
@@ -3843,13 +3527,73 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3843
3527
|
}
|
|
3844
3528
|
collectPrescanResult(result, filePath, discoveredClasses, rawDiscoveredClasses);
|
|
3845
3529
|
}
|
|
3530
|
+
function refreshSzvRegistryEntry(filePath, content) {
|
|
3531
|
+
if (!shouldProcessSource(filePath)) return;
|
|
3532
|
+
if (content === null) {
|
|
3533
|
+
szvCrossModuleRegistry.delete(transformCache.normalizePathSeparators(filePath));
|
|
3534
|
+
return;
|
|
3535
|
+
}
|
|
3536
|
+
transformCache.recordSzvRegistryFile(szvCrossModuleRegistry, filePath, content);
|
|
3537
|
+
if (importedStaticSzEnabled) {
|
|
3538
|
+
transformCache.recordSzObjectRegistryFile(szvCrossModuleRegistry, filePath, content);
|
|
3539
|
+
szObjectProvidersExamined.add(transformCache.normalizePathSeparators(filePath));
|
|
3540
|
+
recordProvidersDemandedBy(filePath, content);
|
|
3541
|
+
}
|
|
3542
|
+
}
|
|
3543
|
+
function recordProvidersDemandedBy(filePath, content) {
|
|
3544
|
+
if (!fileMayContainSafelistableSz(content)) return;
|
|
3545
|
+
const directory = path__namespace.dirname(filePath);
|
|
3546
|
+
for (const specifier of transformCache.importedSpecifiersIn(content)) {
|
|
3547
|
+
for (const base of transformCache.specifierBases(specifier, directory, specifierAliases)) {
|
|
3548
|
+
const providerPath = transformCache.resolveProviderPathWith(base, transformCache.isReadableProviderFile);
|
|
3549
|
+
if (providerPath === void 0) continue;
|
|
3550
|
+
const key = transformCache.normalizePathSeparators(providerPath);
|
|
3551
|
+
if (!szObjectProvidersExamined.has(key)) {
|
|
3552
|
+
szObjectProvidersExamined.add(key);
|
|
3553
|
+
readAndRecordSzObjectProvider(providerPath);
|
|
3554
|
+
}
|
|
3555
|
+
break;
|
|
3556
|
+
}
|
|
3557
|
+
}
|
|
3558
|
+
}
|
|
3559
|
+
function readAndRecordSzObjectProvider(providerPath) {
|
|
3560
|
+
let content;
|
|
3561
|
+
try {
|
|
3562
|
+
content = fs__namespace.readFileSync(providerPath, "utf-8");
|
|
3563
|
+
} catch {
|
|
3564
|
+
return;
|
|
3565
|
+
}
|
|
3566
|
+
transformCache.recordSzObjectRegistryFile(szvCrossModuleRegistry, providerPath, content);
|
|
3567
|
+
}
|
|
3568
|
+
function recordDemandedSzObjectProviders(seenSourcePaths, demand) {
|
|
3569
|
+
for (const base of demand) {
|
|
3570
|
+
const providerPath = transformCache.resolveProviderPath(seenSourcePaths, base);
|
|
3571
|
+
if (providerPath === void 0) continue;
|
|
3572
|
+
szObjectProvidersExamined.add(transformCache.normalizePathSeparators(providerPath));
|
|
3573
|
+
readAndRecordSzObjectProvider(providerPath);
|
|
3574
|
+
}
|
|
3575
|
+
}
|
|
3576
|
+
function refreshSzvRegistryEntryFromDisk(filePath) {
|
|
3577
|
+
if (!shouldProcessSource(filePath)) return;
|
|
3578
|
+
let content;
|
|
3579
|
+
try {
|
|
3580
|
+
content = fs__namespace.readFileSync(filePath, "utf-8");
|
|
3581
|
+
} catch {
|
|
3582
|
+
refreshSzvRegistryEntry(filePath, null);
|
|
3583
|
+
return;
|
|
3584
|
+
}
|
|
3585
|
+
refreshSzvRegistryEntry(filePath, content);
|
|
3586
|
+
}
|
|
3846
3587
|
function prescanAndWriteClasses() {
|
|
3847
3588
|
refreshCompileSourceDirs();
|
|
3848
3589
|
szvCrossModuleRegistry.clear();
|
|
3590
|
+
szObjectProvidersExamined.clear();
|
|
3849
3591
|
const prescanStarted = node_perf_hooks.performance.now();
|
|
3850
3592
|
const discoveredClasses = /* @__PURE__ */ new Set();
|
|
3851
3593
|
const rawDiscoveredClasses = /* @__PURE__ */ new Set();
|
|
3852
3594
|
const prescanSources = [];
|
|
3595
|
+
const seenSourcePaths = /* @__PURE__ */ new Set();
|
|
3596
|
+
const szObjectDemand = /* @__PURE__ */ new Set();
|
|
3853
3597
|
function collectPrescanSource(filePath) {
|
|
3854
3598
|
if (!shouldProcessSource(filePath)) {
|
|
3855
3599
|
recordPackagesSkipIfSz(filePath);
|
|
@@ -3863,13 +3607,23 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3863
3607
|
}
|
|
3864
3608
|
recordAuthoredClasses(content);
|
|
3865
3609
|
recordSzvRegistryEntries(filePath, content);
|
|
3610
|
+
seenSourcePaths.add(transformCache.normalizePathSeparators(filePath));
|
|
3866
3611
|
if (fileMayContainSafelistableSz(content)) {
|
|
3867
3612
|
prescanSources.push({ filePath, content });
|
|
3613
|
+
recordSzObjectDemand(filePath, content);
|
|
3614
|
+
}
|
|
3615
|
+
}
|
|
3616
|
+
function recordSzObjectDemand(filePath, content) {
|
|
3617
|
+
if (!importedStaticSzEnabled) return;
|
|
3618
|
+
const directory = path__namespace.dirname(filePath);
|
|
3619
|
+
for (const specifier of transformCache.importedSpecifiersIn(content)) {
|
|
3620
|
+
for (const base of transformCache.specifierBases(specifier, directory, specifierAliases)) {
|
|
3621
|
+
szObjectDemand.add(base);
|
|
3622
|
+
}
|
|
3868
3623
|
}
|
|
3869
3624
|
}
|
|
3870
3625
|
function recordSzvRegistryEntries(filePath, content) {
|
|
3871
|
-
|
|
3872
|
-
recordSzvRegistryFile(szvCrossModuleRegistry, filePath, content);
|
|
3626
|
+
transformCache.recordSzvRegistryFile(szvCrossModuleRegistry, filePath, content);
|
|
3873
3627
|
}
|
|
3874
3628
|
function scanDir(dir) {
|
|
3875
3629
|
let entries;
|
|
@@ -3898,6 +3652,7 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3898
3652
|
}
|
|
3899
3653
|
scanDir(sourceDir);
|
|
3900
3654
|
}
|
|
3655
|
+
recordDemandedSzObjectProviders(seenSourcePaths, szObjectDemand);
|
|
3901
3656
|
const prescanContentByPath = new Map(
|
|
3902
3657
|
prescanSources.map((file) => [file.filePath, file.content])
|
|
3903
3658
|
);
|
|
@@ -4067,19 +3822,19 @@ function createCsszyxPlugins(options = {}) {
|
|
|
4067
3822
|
}
|
|
4068
3823
|
function replacePlaceholders(code) {
|
|
4069
3824
|
let result = code;
|
|
4070
|
-
if (result.includes(CHECKSUM_PLACEHOLDER)) {
|
|
4071
|
-
result = result.split(CHECKSUM_PLACEHOLDER).join(state.checksum);
|
|
3825
|
+
if (result.includes(themeGroupsFile.CHECKSUM_PLACEHOLDER)) {
|
|
3826
|
+
result = result.split(themeGroupsFile.CHECKSUM_PLACEHOLDER).join(state.checksum);
|
|
4072
3827
|
}
|
|
4073
3828
|
const isEvalWrapped = result.includes("eval(") && result.includes("sourceURL=webpack");
|
|
4074
|
-
if (result.includes(MANGLE_MAP_PLACEHOLDER)) {
|
|
3829
|
+
if (result.includes(themeGroupsFile.MANGLE_MAP_PLACEHOLDER)) {
|
|
4075
3830
|
const jsonMap = escapeJsonForInlineScript(JSON.stringify(state.mangleMap));
|
|
4076
3831
|
const escapedMap = isEvalWrapped ? escapeForDoubleQuotedString(jsonMap) : jsonMap;
|
|
4077
|
-
result = result.split(MANGLE_MAP_PLACEHOLDER).join(escapedMap);
|
|
3832
|
+
result = result.split(themeGroupsFile.MANGLE_MAP_PLACEHOLDER).join(escapedMap);
|
|
4078
3833
|
}
|
|
4079
|
-
if (result.includes(VAR_MANGLE_MAP_PLACEHOLDER)) {
|
|
3834
|
+
if (result.includes(themeGroupsFile.VAR_MANGLE_MAP_PLACEHOLDER)) {
|
|
4080
3835
|
const jsonMap = escapeJsonForInlineScript(JSON.stringify(state.varMangleMap));
|
|
4081
3836
|
const escapedMap = isEvalWrapped ? escapeForDoubleQuotedString(jsonMap) : jsonMap;
|
|
4082
|
-
result = result.split(VAR_MANGLE_MAP_PLACEHOLDER).join(escapedMap);
|
|
3837
|
+
result = result.split(themeGroupsFile.VAR_MANGLE_MAP_PLACEHOLDER).join(escapedMap);
|
|
4083
3838
|
}
|
|
4084
3839
|
return result;
|
|
4085
3840
|
}
|
|
@@ -4123,7 +3878,7 @@ function createCsszyxPlugins(options = {}) {
|
|
|
4123
3878
|
}
|
|
4124
3879
|
emitMissingCssFallback(quiet, message, id, console.warn);
|
|
4125
3880
|
}
|
|
4126
|
-
if (quiet || result.diagnostics.length === 0 || process.env.NODE_ENV === "production") {
|
|
3881
|
+
if (quiet !== "off" || result.diagnostics.length === 0 || process.env.NODE_ENV === "production") {
|
|
4127
3882
|
return;
|
|
4128
3883
|
}
|
|
4129
3884
|
for (const message of result.diagnostics) {
|
|
@@ -4177,9 +3932,9 @@ function createCsszyxPlugins(options = {}) {
|
|
|
4177
3932
|
const attrName = options.production?.minify ? "data-sz-cs" : "data-sz-checksum";
|
|
4178
3933
|
const htmlTag = findOpeningTag(transformedCode, "html");
|
|
4179
3934
|
if (htmlTag) {
|
|
4180
|
-
transformedCode = `${transformedCode.slice(0, htmlTag.close)} ${attrName}="${CHECKSUM_PLACEHOLDER}"${transformedCode.slice(htmlTag.close)}`;
|
|
3935
|
+
transformedCode = `${transformedCode.slice(0, htmlTag.close)} ${attrName}="${themeGroupsFile.CHECKSUM_PLACEHOLDER}"${transformedCode.slice(htmlTag.close)}`;
|
|
4181
3936
|
}
|
|
4182
|
-
const debugScript = `<script dangerouslySetInnerHTML={{__html: \`(function(){var m=${MANGLE_MAP_PLACEHOLDER};var vm=${VAR_MANGLE_MAP_PLACEHOLDER};var gp=decodeURIComponent(${escapeJsonForInlineScript(JSON.stringify(encodedGlobalVarAliasPrefix))});var r={};var vr={};for(var k in m)r[m[k]]=k;for(var vk in vm){var vv=vm[vk];var vs=Array.isArray(vv)?vv:[vv];for(var vi=0;vi<vs.length;vi++)(vr[vs[vi]]||(vr[vs[vi]]=[])).push(vk)}window.__csszyx={mangleMap:m,varMangleMap:vm,checksum:"${CHECKSUM_PLACEHOLDER}",decode:function(c){return r[c]},encode:function(c){return m[c]},decodeVar:function(v){return vr[v]||[]},encodeVar:function(v){return vm[v]},decodeGlobalVar:function(v){var a=vr[v]||[];return v.indexOf(gp)===0?a[0]:void 0},decodeAll:function(el){return(el.className||"").split(" ").map(function(c){return r[c]||c})}}})()\`}} />`;
|
|
3937
|
+
const debugScript = `<script dangerouslySetInnerHTML={{__html: \`(function(){var m=${themeGroupsFile.MANGLE_MAP_PLACEHOLDER};var vm=${themeGroupsFile.VAR_MANGLE_MAP_PLACEHOLDER};var gp=decodeURIComponent(${escapeJsonForInlineScript(JSON.stringify(encodedGlobalVarAliasPrefix))});var r={};var vr={};for(var k in m)r[m[k]]=k;for(var vk in vm){var vv=vm[vk];var vs=Array.isArray(vv)?vv:[vv];for(var vi=0;vi<vs.length;vi++)(vr[vs[vi]]||(vr[vs[vi]]=[])).push(vk)}window.__csszyx={mangleMap:m,varMangleMap:vm,checksum:"${themeGroupsFile.CHECKSUM_PLACEHOLDER}",decode:function(c){return r[c]},encode:function(c){return m[c]},decodeVar:function(v){return vr[v]||[]},encodeVar:function(v){return vm[v]},decodeGlobalVar:function(v){var a=vr[v]||[];return v.indexOf(gp)===0?a[0]:void 0},decodeAll:function(el){return(el.className||"").split(" ").map(function(c){return r[c]||c})}}})()\`}} />`;
|
|
4183
3938
|
const bodyTag = findOpeningTag(transformedCode, "body");
|
|
4184
3939
|
if (bodyTag) {
|
|
4185
3940
|
transformedCode = `${transformedCode.slice(0, bodyTag.close + 1)}${debugScript}${transformedCode.slice(bodyTag.close + 1)}`;
|
|
@@ -4187,7 +3942,7 @@ function createCsszyxPlugins(options = {}) {
|
|
|
4187
3942
|
return transformedCode;
|
|
4188
3943
|
}
|
|
4189
3944
|
function requiredRuntimeHelpers(output) {
|
|
4190
|
-
return
|
|
3945
|
+
return themeGroupsFile.runtimeHelperGroupsFromUsage(output);
|
|
4191
3946
|
}
|
|
4192
3947
|
function injectRuntimeHelpers(code, output) {
|
|
4193
3948
|
const groups = requiredRuntimeHelpers(output);
|
|
@@ -4203,9 +3958,9 @@ function createCsszyxPlugins(options = {}) {
|
|
|
4203
3958
|
}
|
|
4204
3959
|
const imports = groups.barrel;
|
|
4205
3960
|
const hasRuntimeImport = imports.length > 0 && current.includes("@csszyx/runtime");
|
|
4206
|
-
const needed = hasRuntimeImport ? imports.filter((name) => !
|
|
3961
|
+
const needed = hasRuntimeImport ? imports.filter((name) => !themeGroupsFile.importsRuntimeHelper(current, name)) : imports;
|
|
4207
3962
|
if (needed.length === 0) return result;
|
|
4208
|
-
const existingImport =
|
|
3963
|
+
const existingImport = themeGroupsFile.findRuntimeImportClause(current);
|
|
4209
3964
|
if (existingImport) {
|
|
4210
3965
|
return current.replace(
|
|
4211
3966
|
existingImport.statement,
|
|
@@ -4216,11 +3971,30 @@ function createCsszyxPlugins(options = {}) {
|
|
|
4216
3971
|
`;
|
|
4217
3972
|
return insertRuntimeImport(current, importStatement);
|
|
4218
3973
|
}
|
|
3974
|
+
function themeGroupTokens() {
|
|
3975
|
+
const theme = state.parsedTheme;
|
|
3976
|
+
return {
|
|
3977
|
+
colors: theme?.colors ?? [],
|
|
3978
|
+
textSizes: theme?.textSizes ?? [],
|
|
3979
|
+
fontFamilies: theme?.fonts ?? [],
|
|
3980
|
+
fontWeights: theme?.fontWeights ?? []
|
|
3981
|
+
};
|
|
3982
|
+
}
|
|
4219
3983
|
function injectThemeGroups(code, transformedCode, id, usesSzcn) {
|
|
4220
|
-
if (!usesSzcn && !/\bszcn\s*\(/.test(code) || transformedCode.includes(THEME_GROUPS_VIRTUAL_ID) || !shouldProcessSource(id)) {
|
|
3984
|
+
if (!usesSzcn && !/\bszcn\s*\(/.test(code) || transformedCode.includes(themeGroupsFile.THEME_GROUPS_VIRTUAL_ID) || transformedCode.includes(themeGroupsFile.THEME_GROUPS_FILE_MARKER) || !shouldProcessSource(id)) {
|
|
4221
3985
|
return null;
|
|
4222
3986
|
}
|
|
4223
|
-
|
|
3987
|
+
if (activeFramework === "webpack") {
|
|
3988
|
+
const groups = themeGroupsFile.ensureThemeGroupsFile(
|
|
3989
|
+
state.rootDir,
|
|
3990
|
+
path__namespace.join(state.rootDir, ".csszyx")
|
|
3991
|
+
);
|
|
3992
|
+
if (groups.file === null) return null;
|
|
3993
|
+
const [from] = id.split("?");
|
|
3994
|
+
return `import '${themeGroupsFile.themeGroupsSpecifier(from, groups.file)}';
|
|
3995
|
+
${transformedCode}`;
|
|
3996
|
+
}
|
|
3997
|
+
return `import '${themeGroupsFile.THEME_GROUPS_VIRTUAL_ID}';
|
|
4224
3998
|
${transformedCode}`;
|
|
4225
3999
|
}
|
|
4226
4000
|
const MANGLE_RUNTIME_CONSUMER_RE = /from\s*['"](?:csszyx|@csszyx\/runtime)['"]/;
|
|
@@ -4229,10 +4003,10 @@ ${transformedCode}`;
|
|
|
4229
4003
|
if (activeFramework !== "vite" && activeFramework !== "rollup") {
|
|
4230
4004
|
return null;
|
|
4231
4005
|
}
|
|
4232
|
-
if (!manglingEnabled || !deliverMapInBundle || !shouldProcessSource(id) || !MANGLE_RUNTIME_CONSUMER_RE.test(transformedCode) || transformedCode.includes(MANGLE_RUNTIME_VIRTUAL_ID)) {
|
|
4006
|
+
if (!manglingEnabled || !deliverMapInBundle || !shouldProcessSource(id) || !MANGLE_RUNTIME_CONSUMER_RE.test(transformedCode) || transformedCode.includes(themeGroupsFile.MANGLE_RUNTIME_VIRTUAL_ID)) {
|
|
4233
4007
|
return null;
|
|
4234
4008
|
}
|
|
4235
|
-
return insertRuntimeImport(transformedCode, `import '${MANGLE_RUNTIME_VIRTUAL_ID}';
|
|
4009
|
+
return insertRuntimeImport(transformedCode, `import '${themeGroupsFile.MANGLE_RUNTIME_VIRTUAL_ID}';
|
|
4236
4010
|
`);
|
|
4237
4011
|
}
|
|
4238
4012
|
function collectPreTransformClasses(output) {
|
|
@@ -4259,8 +4033,8 @@ ${transformedCode}`;
|
|
|
4259
4033
|
* @returns resolved ID if virtual, null otherwise
|
|
4260
4034
|
*/
|
|
4261
4035
|
resolveId(id) {
|
|
4262
|
-
if (isVirtualModule(id)) {
|
|
4263
|
-
return resolveVirtualModule(id);
|
|
4036
|
+
if (themeGroupsFile.isVirtualModule(id)) {
|
|
4037
|
+
return themeGroupsFile.resolveVirtualModule(id);
|
|
4264
4038
|
}
|
|
4265
4039
|
return null;
|
|
4266
4040
|
},
|
|
@@ -4277,7 +4051,7 @@ ${transformedCode}`;
|
|
|
4277
4051
|
* @returns true only for csszyx virtual modules
|
|
4278
4052
|
*/
|
|
4279
4053
|
loadInclude(id) {
|
|
4280
|
-
return id === RESOLVED_VIRTUAL_MODULE_ID || id === RESOLVED_VIRTUAL_CHECKSUM_ID || id === RESOLVED_THEME_GROUPS_VIRTUAL_ID || id === RESOLVED_MANGLE_RUNTIME_VIRTUAL_ID;
|
|
4054
|
+
return id === themeGroupsFile.RESOLVED_VIRTUAL_MODULE_ID || id === themeGroupsFile.RESOLVED_VIRTUAL_CHECKSUM_ID || id === themeGroupsFile.RESOLVED_THEME_GROUPS_VIRTUAL_ID || id === themeGroupsFile.RESOLVED_MANGLE_RUNTIME_VIRTUAL_ID;
|
|
4281
4055
|
},
|
|
4282
4056
|
/**
|
|
4283
4057
|
* Loads virtual module content — generates mangle map or checksum module code.
|
|
@@ -4285,31 +4059,25 @@ ${transformedCode}`;
|
|
|
4285
4059
|
* @returns generated module source if virtual, null otherwise
|
|
4286
4060
|
*/
|
|
4287
4061
|
load(id) {
|
|
4288
|
-
if (id === RESOLVED_VIRTUAL_MODULE_ID) {
|
|
4062
|
+
if (id === themeGroupsFile.RESOLVED_VIRTUAL_MODULE_ID) {
|
|
4289
4063
|
finalizeMangleMap();
|
|
4290
|
-
return createMangleMapModule(
|
|
4064
|
+
return themeGroupsFile.createMangleMapModule(
|
|
4291
4065
|
state.mangleMap,
|
|
4292
4066
|
state.checksum,
|
|
4293
4067
|
state.varMangleMap,
|
|
4294
4068
|
state.cssVarMetrics
|
|
4295
4069
|
);
|
|
4296
4070
|
}
|
|
4297
|
-
if (id === RESOLVED_VIRTUAL_CHECKSUM_ID) {
|
|
4071
|
+
if (id === themeGroupsFile.RESOLVED_VIRTUAL_CHECKSUM_ID) {
|
|
4298
4072
|
finalizeMangleMap();
|
|
4299
|
-
return createChecksumModule(state.checksum);
|
|
4073
|
+
return themeGroupsFile.createChecksumModule(state.checksum);
|
|
4300
4074
|
}
|
|
4301
|
-
if (id === RESOLVED_MANGLE_RUNTIME_VIRTUAL_ID) {
|
|
4075
|
+
if (id === themeGroupsFile.RESOLVED_MANGLE_RUNTIME_VIRTUAL_ID) {
|
|
4302
4076
|
sizeAccount.channels.add("bundle");
|
|
4303
|
-
return createMangleRuntimeModule(globalVarAliasPrefix);
|
|
4077
|
+
return themeGroupsFile.createMangleRuntimeModule(globalVarAliasPrefix);
|
|
4304
4078
|
}
|
|
4305
|
-
if (id === RESOLVED_THEME_GROUPS_VIRTUAL_ID) {
|
|
4306
|
-
|
|
4307
|
-
return createThemeGroupsModule({
|
|
4308
|
-
colors: theme?.colors ?? [],
|
|
4309
|
-
textSizes: theme?.textSizes ?? [],
|
|
4310
|
-
fontFamilies: theme?.fonts ?? [],
|
|
4311
|
-
fontWeights: theme?.fontWeights ?? []
|
|
4312
|
-
});
|
|
4079
|
+
if (id === themeGroupsFile.RESOLVED_THEME_GROUPS_VIRTUAL_ID) {
|
|
4080
|
+
return themeGroupsFile.createThemeGroupsModule(themeGroupTokens());
|
|
4313
4081
|
}
|
|
4314
4082
|
return null;
|
|
4315
4083
|
},
|
|
@@ -4323,7 +4091,11 @@ ${transformedCode}`;
|
|
|
4323
4091
|
if (shouldProcessCss(id)) {
|
|
4324
4092
|
return true;
|
|
4325
4093
|
}
|
|
4326
|
-
|
|
4094
|
+
if (shouldProcessSource(id)) {
|
|
4095
|
+
return true;
|
|
4096
|
+
}
|
|
4097
|
+
recordPackagesSkipIfSz(id);
|
|
4098
|
+
return false;
|
|
4327
4099
|
},
|
|
4328
4100
|
/**
|
|
4329
4101
|
* Core transform: detects sz prop, compiles to className, injects runtime, collects classes.
|
|
@@ -4410,9 +4182,13 @@ ${transformedCode}`;
|
|
|
4410
4182
|
}
|
|
4411
4183
|
if (!state.skipWarningEmitted && state.skippedSzFiles.size > 0) {
|
|
4412
4184
|
state.skipWarningEmitted = true;
|
|
4413
|
-
emitWarning(
|
|
4414
|
-
|
|
4415
|
-
|
|
4185
|
+
emitWarning(
|
|
4186
|
+
skippedSzFilesMessage(
|
|
4187
|
+
compiler.sortStrings(state.skippedSzFiles),
|
|
4188
|
+
compiler.sortStrings(state.skippedSzvExportFiles)
|
|
4189
|
+
),
|
|
4190
|
+
{ devOnly: state.skippedSzvExportFiles.size === 0 }
|
|
4191
|
+
);
|
|
4416
4192
|
}
|
|
4417
4193
|
if (state.classesCapped) {
|
|
4418
4194
|
emitWarning(
|
|
@@ -4434,7 +4210,10 @@ ${transformedCode}`;
|
|
|
4434
4210
|
recordGlobalVarSourceFile(state, id, null);
|
|
4435
4211
|
recordFileVarMangleEntries(state, id, []);
|
|
4436
4212
|
recordFileCSSVariableMetrics(state, id, null);
|
|
4213
|
+
refreshSzvRegistryEntry(id, null);
|
|
4214
|
+
return;
|
|
4437
4215
|
}
|
|
4216
|
+
refreshSzvRegistryEntryFromDisk(id);
|
|
4438
4217
|
},
|
|
4439
4218
|
/**
|
|
4440
4219
|
* Webpack hook: pre-scans source files before compilation for Tailwind class discovery.
|
|
@@ -4442,12 +4221,13 @@ ${transformedCode}`;
|
|
|
4442
4221
|
*/
|
|
4443
4222
|
webpack(compiler) {
|
|
4444
4223
|
activeFramework = "webpack";
|
|
4224
|
+
compiler.hooks?.beforeCompile?.tap?.("csszyx:theme-groups", () => {
|
|
4225
|
+
const root = compiler.context || process.cwd();
|
|
4226
|
+
themeGroupsFile.ensureThemeGroupsFile(root, path__namespace.join(root, ".csszyx"));
|
|
4227
|
+
});
|
|
4445
4228
|
if (compiler.options?.mode === "development") {
|
|
4446
4229
|
manglingEnabled = false;
|
|
4447
4230
|
}
|
|
4448
|
-
if (compiler.watchMode === true || compiler.options?.watch === true) {
|
|
4449
|
-
crossModuleRegistryEnabled = false;
|
|
4450
|
-
}
|
|
4451
4231
|
if (manglingEnabled && mangleMapDelivery !== "both") {
|
|
4452
4232
|
console.warn(
|
|
4453
4233
|
`[csszyx] production.mangleMapDelivery: '${mangleMapDelivery}' has no effect on the webpack lane \u2014 map delivery only narrows on vite/rollup builds.`
|
|
@@ -4457,11 +4237,21 @@ ${transformedCode}`;
|
|
|
4457
4237
|
announceActiveParser();
|
|
4458
4238
|
const root = compiler.context || process.cwd();
|
|
4459
4239
|
state.rootDir = root;
|
|
4240
|
+
specifierAliases = transformCache.collectSpecifierAliases(
|
|
4241
|
+
root,
|
|
4242
|
+
compiler.options?.resolve?.alias
|
|
4243
|
+
);
|
|
4460
4244
|
evictTransformCacheOnce();
|
|
4461
4245
|
if (state.classes.size === 0) {
|
|
4462
4246
|
prescanAndWriteClasses();
|
|
4463
4247
|
}
|
|
4464
|
-
|
|
4248
|
+
for (const changed of compiler.modifiedFiles ?? []) {
|
|
4249
|
+
refreshSzvRegistryEntryFromDisk(changed);
|
|
4250
|
+
}
|
|
4251
|
+
for (const removed of compiler.removedFiles ?? []) {
|
|
4252
|
+
refreshSzvRegistryEntry(removed, null);
|
|
4253
|
+
}
|
|
4254
|
+
state.scanCssTheme = runThemeScan(root, options.build?.scanCss) ?? state.scanCssTheme;
|
|
4465
4255
|
runAutoThemeScan(root);
|
|
4466
4256
|
});
|
|
4467
4257
|
if (options.build?.scanCss) {
|
|
@@ -4477,10 +4267,6 @@ ${transformedCode}`;
|
|
|
4477
4267
|
/** Records the rollup lane for the mangle-runtime gate. */
|
|
4478
4268
|
buildStart() {
|
|
4479
4269
|
activeFramework = "rollup";
|
|
4480
|
-
const meta = this.meta;
|
|
4481
|
-
if (meta?.watchMode) {
|
|
4482
|
-
crossModuleRegistryEnabled = false;
|
|
4483
|
-
}
|
|
4484
4270
|
}
|
|
4485
4271
|
},
|
|
4486
4272
|
vite: {
|
|
@@ -4494,16 +4280,13 @@ ${transformedCode}`;
|
|
|
4494
4280
|
announceActiveParser();
|
|
4495
4281
|
const root = config.root || process.cwd();
|
|
4496
4282
|
state.rootDir = root;
|
|
4283
|
+
specifierAliases = transformCache.collectSpecifierAliases(root, config.resolve?.alias);
|
|
4497
4284
|
if (config.command === "serve") {
|
|
4498
4285
|
manglingEnabled = false;
|
|
4499
|
-
crossModuleRegistryEnabled = false;
|
|
4500
|
-
}
|
|
4501
|
-
if (config.build?.watch) {
|
|
4502
|
-
crossModuleRegistryEnabled = false;
|
|
4503
4286
|
}
|
|
4504
4287
|
evictTransformCacheOnce();
|
|
4505
4288
|
prescanAndWriteClasses();
|
|
4506
|
-
state.
|
|
4289
|
+
state.scanCssTheme = runThemeScan(root, options.build?.scanCss) ?? state.scanCssTheme;
|
|
4507
4290
|
runAutoThemeScan(root);
|
|
4508
4291
|
},
|
|
4509
4292
|
/**
|
|
@@ -4516,21 +4299,23 @@ ${transformedCode}`;
|
|
|
4516
4299
|
const scanCss = options.build?.scanCss;
|
|
4517
4300
|
const reloadThemeGroupsModule = () => {
|
|
4518
4301
|
const themeGroupsModule = ctx.server.moduleGraph.getModuleById(
|
|
4519
|
-
RESOLVED_THEME_GROUPS_VIRTUAL_ID
|
|
4302
|
+
themeGroupsFile.RESOLVED_THEME_GROUPS_VIRTUAL_ID
|
|
4520
4303
|
);
|
|
4521
4304
|
if (themeGroupsModule) {
|
|
4522
4305
|
ctx.server.moduleGraph.invalidateModule(themeGroupsModule);
|
|
4523
4306
|
}
|
|
4524
4307
|
};
|
|
4525
|
-
if (
|
|
4308
|
+
if (ctx.file.endsWith(".css")) {
|
|
4526
4309
|
const root = ctx.server.config.root || process.cwd();
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
|
|
4310
|
+
const before = themeGroupsFile.createThemeGroupsModule(themeGroupTokens());
|
|
4311
|
+
if (scanCss && matchesAnyPattern(ctx.file, scanCss, root)) {
|
|
4312
|
+
state.scanCssTheme = runThemeScan(root, scanCss) ?? state.scanCssTheme;
|
|
4530
4313
|
}
|
|
4531
|
-
|
|
4532
|
-
runAutoThemeScan(ctx.server.config.root || process.cwd());
|
|
4314
|
+
runAutoThemeScan(root);
|
|
4533
4315
|
reloadThemeGroupsModule();
|
|
4316
|
+
if (themeGroupsFile.createThemeGroupsModule(themeGroupTokens()) !== before) {
|
|
4317
|
+
ctx.server.ws.send({ type: "full-reload" });
|
|
4318
|
+
}
|
|
4534
4319
|
}
|
|
4535
4320
|
if (!shouldProcessSource(ctx.file)) {
|
|
4536
4321
|
return;
|
|
@@ -4539,8 +4324,10 @@ ${transformedCode}`;
|
|
|
4539
4324
|
try {
|
|
4540
4325
|
fileContent = fs__namespace.readFileSync(ctx.file, "utf-8");
|
|
4541
4326
|
} catch {
|
|
4327
|
+
refreshSzvRegistryEntry(ctx.file, null);
|
|
4542
4328
|
return;
|
|
4543
4329
|
}
|
|
4330
|
+
refreshSzvRegistryEntry(ctx.file, fileContent);
|
|
4544
4331
|
if (!fileContent.includes("sz=") && !fileContent.includes("szs=") && !/\bsz\s*:\s*["'{]/.test(fileContent)) {
|
|
4545
4332
|
trackGlobalVarSourceFile(ctx.file, fileContent);
|
|
4546
4333
|
recordFileVarMangleEntries(state, ctx.file, []);
|
|
@@ -4775,7 +4562,9 @@ ${transformedCode}`;
|
|
|
4775
4562
|
collectRollupGlobalVarCssAssets(bundle)
|
|
4776
4563
|
);
|
|
4777
4564
|
const shouldMangle = manglingEnabled && Object.keys(state.mangleMap).length > 0;
|
|
4778
|
-
|
|
4565
|
+
if (options.build?.emitManifest === true) {
|
|
4566
|
+
emitAsset("csszyx-manifest.json", JSON.stringify(createBundleManifest(shouldMangle)));
|
|
4567
|
+
}
|
|
4779
4568
|
if (shouldEmitGlobalVarMapAsset(globalVarMangleConfig)) {
|
|
4780
4569
|
const globalVarMap = createGlobalVarMapAssetSource(
|
|
4781
4570
|
state.varMangleMap,
|
|
@@ -4897,7 +4686,6 @@ exports.findLocalImportSources = findLocalImportSources;
|
|
|
4897
4686
|
exports.findRSCBoundaryViolation = findRSCBoundaryViolation;
|
|
4898
4687
|
exports.findRSCGraphViolation = findRSCGraphViolation;
|
|
4899
4688
|
exports.hasInjectableTailwindCandidate = hasInjectableTailwindCandidate;
|
|
4900
|
-
exports.hasTokens = hasTokens;
|
|
4901
4689
|
exports.hasUseClientDirective = hasUseClientDirective;
|
|
4902
4690
|
exports.hasUseServerDirective = hasUseServerDirective;
|
|
4903
4691
|
exports.isCompileSourceOptedIn = isCompileSourceOptedIn;
|
|
@@ -4909,19 +4697,17 @@ exports.isTailwindReservedGlobalVar = isTailwindReservedGlobalVar;
|
|
|
4909
4697
|
exports.mangleCodeClassesSync = mangleCodeClassesSync;
|
|
4910
4698
|
exports.mangleEligibleClasses = mangleEligibleClasses;
|
|
4911
4699
|
exports.mangleHybridHazardMessage = mangleHybridHazardMessage;
|
|
4912
|
-
exports.mergeThemes = mergeThemes;
|
|
4913
4700
|
exports.missingTailwindEntryMessage = missingTailwindEntryMessage;
|
|
4914
4701
|
exports.normalizeGlobalVarAliasesForCache = normalizeGlobalVarAliasesForCache;
|
|
4915
|
-
exports.parseThemeBlocks = parseThemeBlocks;
|
|
4916
4702
|
exports.planGlobalVarAliases = planGlobalVarAliases;
|
|
4917
4703
|
exports.readGlobalVarScanCache = readGlobalVarScanCache;
|
|
4918
4704
|
exports.recordGlobalVarSourceFile = recordGlobalVarSourceFile;
|
|
4919
4705
|
exports.resolveCompileSourceDirs = resolveCompileSourceDirs;
|
|
4920
4706
|
exports.resolveGlobalVarScanCacheDir = resolveGlobalVarScanCacheDir;
|
|
4921
4707
|
exports.resolveNativeCacheIdentity = resolveNativeCacheIdentity;
|
|
4708
|
+
exports.resolveQuietMode = resolveQuietMode;
|
|
4922
4709
|
exports.rewriteGlobalVarCssAliases = rewriteGlobalVarCssAliases;
|
|
4923
4710
|
exports.rollupPlugin = rollupPlugin;
|
|
4924
|
-
exports.scanCustomPropertyNames = scanCustomPropertyNames;
|
|
4925
4711
|
exports.scanGlobalVarCss = scanGlobalVarCss;
|
|
4926
4712
|
exports.shouldEmitMissingCssFallback = shouldEmitMissingCssFallback;
|
|
4927
4713
|
exports.shouldEmitWarning = shouldEmitWarning;
|