@csszyx/unplugin 0.10.10 → 0.10.12
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 +4 -2
- package/dist/index.d.cts +3 -158
- package/dist/index.d.mts +3 -158
- package/dist/index.mjs +2 -2
- package/dist/next-prebuild.cjs +2 -2
- package/dist/next-prebuild.mjs +2 -2
- package/dist/next-turbo-loader.cjs +2 -2
- package/dist/next-turbo-loader.mjs +2 -2
- package/dist/shared/{unplugin.uLmLkr10.mjs → unplugin.B45ZkNXD.mjs} +1 -1
- package/dist/shared/{unplugin.BImj9Vcx.cjs → unplugin.Bh2aAL4a.cjs} +1 -1
- package/dist/shared/{unplugin.BpWUtI9U.mjs → unplugin.CGqFVGlB.mjs} +14 -1
- package/dist/shared/{unplugin.Cq_8AIBn.cjs → unplugin.CoiN0OSE.cjs} +152 -41
- package/dist/shared/{unplugin.pmTknYLy.cjs → unplugin.D32Rb29j.cjs} +14 -0
- package/dist/shared/{unplugin.CK6U5gAP.d.mts → unplugin.D3qsS8Pe.d.cts} +269 -3
- package/dist/shared/{unplugin.CK6U5gAP.d.cts → unplugin.D3qsS8Pe.d.mts} +269 -3
- package/dist/shared/{unplugin.Ble541_h.mjs → unplugin.DO7Y2Y-X.mjs} +149 -40
- package/dist/vite.cjs +2 -2
- package/dist/vite.d.cts +1 -1
- package/dist/vite.d.mts +1 -1
- package/dist/vite.mjs +2 -2
- package/dist/webpack.cjs +2 -2
- package/dist/webpack.d.cts +1 -1
- package/dist/webpack.d.mts +1 -1
- package/dist/webpack.mjs +2 -2
- package/package.json +7 -7
|
@@ -15,7 +15,7 @@ const unplugin$1 = require('unplugin');
|
|
|
15
15
|
const cssMangler = require('../css-mangler.cjs');
|
|
16
16
|
const htmlEscape = require('./unplugin.BCwRIUs_.cjs');
|
|
17
17
|
const node_crypto = require('node:crypto');
|
|
18
|
-
const transformCache = require('./unplugin.
|
|
18
|
+
const transformCache = require('./unplugin.D32Rb29j.cjs');
|
|
19
19
|
const postcss = require('postcss');
|
|
20
20
|
const valueParser = require('postcss-value-parser');
|
|
21
21
|
|
|
@@ -1026,6 +1026,8 @@ const EMPTY_THEME = {
|
|
|
1026
1026
|
colors: [],
|
|
1027
1027
|
spacings: [],
|
|
1028
1028
|
fonts: [],
|
|
1029
|
+
textSizes: [],
|
|
1030
|
+
fontWeights: [],
|
|
1029
1031
|
radii: [],
|
|
1030
1032
|
shadows: [],
|
|
1031
1033
|
breakpoints: []
|
|
@@ -1095,7 +1097,12 @@ function categorizeProperty(prop) {
|
|
|
1095
1097
|
const categoryMap = [
|
|
1096
1098
|
["color-", "colors"],
|
|
1097
1099
|
["spacing-", "spacings"],
|
|
1100
|
+
// `font-weight-` MUST precede `font-`: startsWith would otherwise route
|
|
1101
|
+
// `font-weight-chunky` into font FAMILIES as token "weight-chunky".
|
|
1102
|
+
["font-weight-", "fontWeights"],
|
|
1098
1103
|
["font-", "fonts"],
|
|
1104
|
+
// `--text-*` defines font-size utilities (text-huge) in Tailwind v4.
|
|
1105
|
+
["text-", "textSizes"],
|
|
1099
1106
|
["radius-", "radii"],
|
|
1100
1107
|
["shadow-", "shadows"],
|
|
1101
1108
|
["breakpoint-", "breakpoints"]
|
|
@@ -1118,6 +1125,8 @@ function parseThemeBlocks(cssContent) {
|
|
|
1118
1125
|
colors: /* @__PURE__ */ new Set(),
|
|
1119
1126
|
spacings: /* @__PURE__ */ new Set(),
|
|
1120
1127
|
fonts: /* @__PURE__ */ new Set(),
|
|
1128
|
+
textSizes: /* @__PURE__ */ new Set(),
|
|
1129
|
+
fontWeights: /* @__PURE__ */ new Set(),
|
|
1121
1130
|
radii: /* @__PURE__ */ new Set(),
|
|
1122
1131
|
shadows: /* @__PURE__ */ new Set(),
|
|
1123
1132
|
breakpoints: /* @__PURE__ */ new Set()
|
|
@@ -1137,6 +1146,8 @@ function parseThemeBlocks(cssContent) {
|
|
|
1137
1146
|
colors: htmlEscape.sortStrings(result.colors),
|
|
1138
1147
|
spacings: htmlEscape.sortStrings(result.spacings),
|
|
1139
1148
|
fonts: htmlEscape.sortStrings(result.fonts),
|
|
1149
|
+
textSizes: htmlEscape.sortStrings(result.textSizes),
|
|
1150
|
+
fontWeights: htmlEscape.sortStrings(result.fontWeights),
|
|
1140
1151
|
radii: htmlEscape.sortStrings(result.radii),
|
|
1141
1152
|
shadows: htmlEscape.sortStrings(result.shadows),
|
|
1142
1153
|
breakpoints: htmlEscape.sortStrings(result.breakpoints)
|
|
@@ -1150,6 +1161,8 @@ function mergeThemes(themes) {
|
|
|
1150
1161
|
colors: /* @__PURE__ */ new Set(),
|
|
1151
1162
|
spacings: /* @__PURE__ */ new Set(),
|
|
1152
1163
|
fonts: /* @__PURE__ */ new Set(),
|
|
1164
|
+
textSizes: /* @__PURE__ */ new Set(),
|
|
1165
|
+
fontWeights: /* @__PURE__ */ new Set(),
|
|
1153
1166
|
radii: /* @__PURE__ */ new Set(),
|
|
1154
1167
|
shadows: /* @__PURE__ */ new Set(),
|
|
1155
1168
|
breakpoints: /* @__PURE__ */ new Set()
|
|
@@ -1165,6 +1178,8 @@ function mergeThemes(themes) {
|
|
|
1165
1178
|
colors: htmlEscape.sortStrings(merged.colors),
|
|
1166
1179
|
spacings: htmlEscape.sortStrings(merged.spacings),
|
|
1167
1180
|
fonts: htmlEscape.sortStrings(merged.fonts),
|
|
1181
|
+
textSizes: htmlEscape.sortStrings(merged.textSizes),
|
|
1182
|
+
fontWeights: htmlEscape.sortStrings(merged.fontWeights),
|
|
1168
1183
|
radii: htmlEscape.sortStrings(merged.radii),
|
|
1169
1184
|
shadows: htmlEscape.sortStrings(merged.shadows),
|
|
1170
1185
|
breakpoints: htmlEscape.sortStrings(merged.breakpoints)
|
|
@@ -1488,6 +1503,12 @@ function generateThemeDts(opts) {
|
|
|
1488
1503
|
if (theme.fonts.length > 0) {
|
|
1489
1504
|
entries.push(` fonts: ${toUnion(theme.fonts)};`);
|
|
1490
1505
|
}
|
|
1506
|
+
if (theme.textSizes.length > 0) {
|
|
1507
|
+
entries.push(` textSizes: ${toUnion(theme.textSizes)};`);
|
|
1508
|
+
}
|
|
1509
|
+
if (theme.fontWeights.length > 0) {
|
|
1510
|
+
entries.push(` fontWeights: ${toUnion(theme.fontWeights)};`);
|
|
1511
|
+
}
|
|
1491
1512
|
if (theme.radii.length > 0) {
|
|
1492
1513
|
entries.push(` radii: ${toUnion(theme.radii)};`);
|
|
1493
1514
|
}
|
|
@@ -1538,6 +1559,8 @@ function writeThemeDts(opts) {
|
|
|
1538
1559
|
|
|
1539
1560
|
const VIRTUAL_MODULE_ID = "virtual:csszyx/mangle-map";
|
|
1540
1561
|
const RESOLVED_VIRTUAL_MODULE_ID = `\0${VIRTUAL_MODULE_ID}`;
|
|
1562
|
+
const THEME_GROUPS_VIRTUAL_ID = "virtual:csszyx/theme-groups";
|
|
1563
|
+
const RESOLVED_THEME_GROUPS_VIRTUAL_ID = `\0${THEME_GROUPS_VIRTUAL_ID}`;
|
|
1541
1564
|
const VIRTUAL_CHECKSUM_ID = "virtual:csszyx/checksum";
|
|
1542
1565
|
const RESOLVED_VIRTUAL_CHECKSUM_ID = `\0${VIRTUAL_CHECKSUM_ID}`;
|
|
1543
1566
|
function createMangleMapModule(mangleMap, checksum, varMangleMap = {}, cssVarMetrics = null) {
|
|
@@ -1578,7 +1601,7 @@ export default checksum;
|
|
|
1578
1601
|
`;
|
|
1579
1602
|
}
|
|
1580
1603
|
function isVirtualModule(id) {
|
|
1581
|
-
return id === VIRTUAL_MODULE_ID || id === VIRTUAL_CHECKSUM_ID;
|
|
1604
|
+
return id === VIRTUAL_MODULE_ID || id === VIRTUAL_CHECKSUM_ID || id === THEME_GROUPS_VIRTUAL_ID;
|
|
1582
1605
|
}
|
|
1583
1606
|
function resolveVirtualModule(id) {
|
|
1584
1607
|
if (id === VIRTUAL_MODULE_ID) {
|
|
@@ -1587,8 +1610,25 @@ function resolveVirtualModule(id) {
|
|
|
1587
1610
|
if (id === VIRTUAL_CHECKSUM_ID) {
|
|
1588
1611
|
return RESOLVED_VIRTUAL_CHECKSUM_ID;
|
|
1589
1612
|
}
|
|
1613
|
+
if (id === THEME_GROUPS_VIRTUAL_ID) {
|
|
1614
|
+
return RESOLVED_THEME_GROUPS_VIRTUAL_ID;
|
|
1615
|
+
}
|
|
1590
1616
|
return void 0;
|
|
1591
1617
|
}
|
|
1618
|
+
function createThemeGroupsModule(tokens) {
|
|
1619
|
+
const payload = JSON.stringify({
|
|
1620
|
+
colors: tokens.colors,
|
|
1621
|
+
textSizes: tokens.textSizes,
|
|
1622
|
+
fontFamilies: tokens.fontFamilies,
|
|
1623
|
+
fontWeights: tokens.fontWeights
|
|
1624
|
+
});
|
|
1625
|
+
return [
|
|
1626
|
+
"// Auto-generated by csszyx from the @theme blocks in scanned CSS.",
|
|
1627
|
+
"import { registerSzcnGroups } from '@csszyx/runtime';",
|
|
1628
|
+
`registerSzcnGroups(${payload});`,
|
|
1629
|
+
"export {};"
|
|
1630
|
+
].join("\n");
|
|
1631
|
+
}
|
|
1592
1632
|
|
|
1593
1633
|
const CHECKSUM_PLACEHOLDER = "___CSSZYX_CHECKSUM___";
|
|
1594
1634
|
const MANGLE_MAP_PLACEHOLDER = "___CSSZYX_MANGLE_MAP___";
|
|
@@ -1597,6 +1637,7 @@ const UNKNOWN_PACKAGE_VERSION = "0.0.0";
|
|
|
1597
1637
|
const TRANSFORM_CACHE_MAX_AGE_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
1598
1638
|
const TRANSFORM_CACHE_MAX_ENTRIES = 1e4;
|
|
1599
1639
|
const TRANSFORM_MEMORY_CACHE_MAX_ENTRIES = 1e3;
|
|
1640
|
+
const TRANSFORM_MEMORY_CACHE_MAX_CODE_CHARS = 32e6;
|
|
1600
1641
|
const MAX_SAFELIST_CLASSES = 1e5;
|
|
1601
1642
|
const DEFAULT_VAR_MANGLE_MAP_MAX_BYTES = 100 * 1024;
|
|
1602
1643
|
const GLOBAL_VAR_ALIAS_MAP_OWNER = "\0csszyx:global-var-aliases";
|
|
@@ -1609,11 +1650,11 @@ const RUNTIME_HELPER_IMPORT_RE = {
|
|
|
1609
1650
|
let _hasWarnedTsConfig = false;
|
|
1610
1651
|
let _hasWarnedTransformCacheVersion = false;
|
|
1611
1652
|
let _hasWarnedNativeFallback = false;
|
|
1612
|
-
|
|
1653
|
+
const _loggedActiveParsers = /* @__PURE__ */ new Set();
|
|
1613
1654
|
const _babelFallbackFiles = /* @__PURE__ */ new Set();
|
|
1614
|
-
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.
|
|
1655
|
+
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.CoiN0OSE.cjs', document.baseURI).href)));
|
|
1615
1656
|
const PLUGIN_VERSION = findPackageVersionFromFile(
|
|
1616
|
-
node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/unplugin.
|
|
1657
|
+
node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/unplugin.CoiN0OSE.cjs', document.baseURI).href))),
|
|
1617
1658
|
UNKNOWN_PACKAGE_VERSION
|
|
1618
1659
|
);
|
|
1619
1660
|
const COMPILER_VERSION = findPackageVersionFromModule("@csszyx/compiler", UNKNOWN_PACKAGE_VERSION);
|
|
@@ -1817,7 +1858,10 @@ function isHardIgnoredPath(id, sourceDirs = []) {
|
|
|
1817
1858
|
return false;
|
|
1818
1859
|
}
|
|
1819
1860
|
function fileMayContainSafelistableSz(content) {
|
|
1820
|
-
return content.includes("sz=") || content.includes("szs=") || content.includes("sz:") || content.includes("szv(")
|
|
1861
|
+
return content.includes("sz=") || content.includes("szs=") || content.includes("sz:") || content.includes("szv(") || content.includes("szr(") || // dynamic() literal args are extracted for the safelist, but a module
|
|
1862
|
+
// containing ONLY dynamic() calls never passed this gate — the
|
|
1863
|
+
// engine-parity harness caught its classes missing on all engines.
|
|
1864
|
+
content.includes("dynamic(");
|
|
1821
1865
|
}
|
|
1822
1866
|
function isPackagesSkippedSource(id, sourceDirs = []) {
|
|
1823
1867
|
const p = normalizeForMatch(id);
|
|
@@ -1869,9 +1913,12 @@ function recordFileVarMangleEntries(state, filename, entries) {
|
|
|
1869
1913
|
}
|
|
1870
1914
|
state.varMangleMap = buildVarMangleMap(state.varMangleEntriesByFile);
|
|
1871
1915
|
}
|
|
1916
|
+
function shouldTrackGlobalVarSources(config) {
|
|
1917
|
+
return config?.enabled === true;
|
|
1918
|
+
}
|
|
1872
1919
|
function recordGlobalVarSourceFile(state, filename, code) {
|
|
1873
1920
|
const normalizedFilename = normalizeSourceFilename(filename);
|
|
1874
|
-
if (
|
|
1921
|
+
if (!matchesScriptExtension(normalizedFilename, SCRIPT_ID_EXTENSIONS)) {
|
|
1875
1922
|
return;
|
|
1876
1923
|
}
|
|
1877
1924
|
if (code === null) {
|
|
@@ -2143,11 +2190,11 @@ function traceBenchTiming(label, filename, elapsedMs) {
|
|
|
2143
2190
|
}
|
|
2144
2191
|
function runThemeScan(rootDir, scanCss) {
|
|
2145
2192
|
if (!scanCss) {
|
|
2146
|
-
return;
|
|
2193
|
+
return null;
|
|
2147
2194
|
}
|
|
2148
2195
|
const sourceFiles = expandFilePatterns(rootDir, scanCss).filter((file) => file.endsWith(".css"));
|
|
2149
2196
|
if (sourceFiles.length === 0) {
|
|
2150
|
-
return;
|
|
2197
|
+
return null;
|
|
2151
2198
|
}
|
|
2152
2199
|
const themes = sourceFiles.map((f) => {
|
|
2153
2200
|
try {
|
|
@@ -2187,6 +2234,7 @@ function runThemeScan(rootDir, scanCss) {
|
|
|
2187
2234
|
} catch {
|
|
2188
2235
|
}
|
|
2189
2236
|
}
|
|
2237
|
+
return merged;
|
|
2190
2238
|
}
|
|
2191
2239
|
function findPackageVersionFromModule(specifier, fallback) {
|
|
2192
2240
|
try {
|
|
@@ -2217,6 +2265,11 @@ function findPackageVersionFromFile(file, fallback) {
|
|
|
2217
2265
|
function normalizeSourceFilename(filename) {
|
|
2218
2266
|
return filename.replace(/\\/g, "/");
|
|
2219
2267
|
}
|
|
2268
|
+
const SCRIPT_ID_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx"];
|
|
2269
|
+
const SOURCE_MODULE_EXTENSIONS = [...SCRIPT_ID_EXTENSIONS, ".cts", ".mts", ".cjs", ".mjs"];
|
|
2270
|
+
function matchesScriptExtension(id, extensions) {
|
|
2271
|
+
return extensions.some((ext) => id.endsWith(ext) || id.includes(`${ext}?`));
|
|
2272
|
+
}
|
|
2220
2273
|
function insertRuntimeImport(code, importStmt) {
|
|
2221
2274
|
const directiveMatch = code.match(DIRECTIVE_PROLOGUE_PREFIX_RE);
|
|
2222
2275
|
if (!directiveMatch) {
|
|
@@ -2469,6 +2522,7 @@ function createCsszyxPlugins(options = {}) {
|
|
|
2469
2522
|
const cacheEnabled = cacheRequested && cacheVersionsKnown;
|
|
2470
2523
|
const varMangleMapMaxBytes = resolveVarMangleMapMaxBytes();
|
|
2471
2524
|
const globalVarMangleConfig = options.production?.mangleGlobalVars;
|
|
2525
|
+
const globalVarSourceTrackingEnabled = shouldTrackGlobalVarSources(globalVarMangleConfig);
|
|
2472
2526
|
const globalVarAliasPrefix = globalVarMangleConfig?.aliasPrefix ?? types.CSSZYX_GLOBAL_ALIAS_PREFIX;
|
|
2473
2527
|
const encodedGlobalVarAliasPrefix = encodeURIComponent(globalVarAliasPrefix);
|
|
2474
2528
|
const earlyGlobalVarAliasEntries = createEarlyGlobalVarAliasEntries(
|
|
@@ -2494,21 +2548,25 @@ function createCsszyxPlugins(options = {}) {
|
|
|
2494
2548
|
defaultParser: types.DEFAULT_BUILD_CONFIG.parser ?? "rust",
|
|
2495
2549
|
isRustAvailable: compiler.isRustTransformAvailable
|
|
2496
2550
|
});
|
|
2497
|
-
|
|
2498
|
-
_hasWarnedNativeFallback
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2551
|
+
function announceActiveParser() {
|
|
2552
|
+
if (parserDegraded && !_hasWarnedNativeFallback) {
|
|
2553
|
+
_hasWarnedNativeFallback = true;
|
|
2554
|
+
console.warn(
|
|
2555
|
+
"[csszyx] No prebuilt native binary (@csszyx/core-*) is available for this platform, so the default `rust` parser fell back to `oxc`. Output classes are identical (parity-tested); only parse speed differs. To use the native engine, install the matching @csszyx/core-<platform> package (or do not omit optional dependencies). Set `build.parser` explicitly to silence this."
|
|
2556
|
+
);
|
|
2557
|
+
}
|
|
2558
|
+
if (!_loggedActiveParsers.has(parserMode)) {
|
|
2559
|
+
_loggedActiveParsers.add(parserMode);
|
|
2560
|
+
const detail = parserDegraded ? "oxc (degraded from default `rust`: no native binary for this platform)" : parserMode === "rust" ? "rust (native engine)" : parserMode;
|
|
2561
|
+
console.warn(`[csszyx] active parser: ${detail}`);
|
|
2562
|
+
}
|
|
2507
2563
|
}
|
|
2508
2564
|
let evictedCacheRoot = null;
|
|
2509
2565
|
const transformMemoryCache = /* @__PURE__ */ new Map();
|
|
2566
|
+
let transformMemoryCacheCodeChars = 0;
|
|
2510
2567
|
const state = {
|
|
2511
2568
|
classes: /* @__PURE__ */ new Set(),
|
|
2569
|
+
parsedTheme: null,
|
|
2512
2570
|
sawTailwindEntry: false,
|
|
2513
2571
|
sawAnyCss: false,
|
|
2514
2572
|
tailwindWarningEmitted: false,
|
|
@@ -2536,7 +2594,16 @@ function createCsszyxPlugins(options = {}) {
|
|
|
2536
2594
|
state.varMangleEntriesByFile.set(GLOBAL_VAR_ALIAS_MAP_OWNER, earlyGlobalVarAliasEntries);
|
|
2537
2595
|
}
|
|
2538
2596
|
const SAFELIST_FILENAME = "csszyx-classes.html";
|
|
2539
|
-
const SOURCE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
2597
|
+
const SOURCE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
2598
|
+
".tsx",
|
|
2599
|
+
".jsx",
|
|
2600
|
+
".ts",
|
|
2601
|
+
".js",
|
|
2602
|
+
".mjs",
|
|
2603
|
+
".cjs",
|
|
2604
|
+
".mts",
|
|
2605
|
+
".cts"
|
|
2606
|
+
]);
|
|
2540
2607
|
const IGNORE_DIRS = /* @__PURE__ */ new Set(["node_modules", ".next", ".git", "dist", "build", ".turbo"]);
|
|
2541
2608
|
function isUserExcluded(id) {
|
|
2542
2609
|
return matchesAnyPattern(id, options.exclude, state.rootDir);
|
|
@@ -2578,6 +2645,12 @@ function createCsszyxPlugins(options = {}) {
|
|
|
2578
2645
|
assertGlobalVarPlanMatchesEarlyAliases(result, earlyGlobalVarAliasEntries);
|
|
2579
2646
|
return result;
|
|
2580
2647
|
}
|
|
2648
|
+
function trackGlobalVarSourceFile(filename, code) {
|
|
2649
|
+
if (!globalVarSourceTrackingEnabled) {
|
|
2650
|
+
return;
|
|
2651
|
+
}
|
|
2652
|
+
recordGlobalVarSourceFile(state, filename, code);
|
|
2653
|
+
}
|
|
2581
2654
|
let compileSourceDirs = [];
|
|
2582
2655
|
let compileSourceDirsRoot = null;
|
|
2583
2656
|
function refreshCompileSourceDirs() {
|
|
@@ -2598,7 +2671,7 @@ function createCsszyxPlugins(options = {}) {
|
|
|
2598
2671
|
return isHardIgnoredPath(id, compileSourceDirs);
|
|
2599
2672
|
}
|
|
2600
2673
|
function shouldProcessSource(id) {
|
|
2601
|
-
return !isHardIgnored(id) && !isUserExcluded(id) && isUserIncluded(id) && (
|
|
2674
|
+
return !isHardIgnored(id) && !isUserExcluded(id) && isUserIncluded(id) && (matchesScriptExtension(id, SOURCE_MODULE_EXTENSIONS) || id.endsWith(".vue") || id.endsWith(".svelte"));
|
|
2602
2675
|
}
|
|
2603
2676
|
function shouldProcessCss(id) {
|
|
2604
2677
|
return !isHardIgnored(id) && !isUserExcluded(id) && /\.css(\?.*)?$/.test(id);
|
|
@@ -2779,21 +2852,28 @@ function createCsszyxPlugins(options = {}) {
|
|
|
2779
2852
|
filePath: file.filePath,
|
|
2780
2853
|
result: transformConfiguredSource(file.content, file.filePath)
|
|
2781
2854
|
});
|
|
2782
|
-
} catch {
|
|
2855
|
+
} catch (err) {
|
|
2856
|
+
console.warn(
|
|
2857
|
+
`[csszyx] prescan skipped ${file.filePath}: transform failed, so none of its classes reached the safelist. ${err instanceof Error ? err.message : String(err)}`
|
|
2858
|
+
);
|
|
2783
2859
|
}
|
|
2784
2860
|
}
|
|
2785
2861
|
return results;
|
|
2786
2862
|
}
|
|
2787
2863
|
function rememberTransformCacheEntry(key, result) {
|
|
2788
|
-
transformMemoryCache.
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
}
|
|
2793
|
-
const oldest = transformMemoryCache.keys().next().value;
|
|
2794
|
-
if (oldest) {
|
|
2795
|
-
transformMemoryCache.delete(oldest);
|
|
2864
|
+
const existing = transformMemoryCache.get(key);
|
|
2865
|
+
if (existing) {
|
|
2866
|
+
transformMemoryCacheCodeChars -= existing.code.length;
|
|
2867
|
+
transformMemoryCache.delete(key);
|
|
2796
2868
|
}
|
|
2869
|
+
transformMemoryCache.set(key, result);
|
|
2870
|
+
transformMemoryCacheCodeChars += result.code.length;
|
|
2871
|
+
transformMemoryCacheCodeChars = transformCache.evictMemoryCacheToBudget(
|
|
2872
|
+
transformMemoryCache,
|
|
2873
|
+
transformMemoryCacheCodeChars,
|
|
2874
|
+
TRANSFORM_MEMORY_CACHE_MAX_ENTRIES,
|
|
2875
|
+
TRANSFORM_MEMORY_CACHE_MAX_CODE_CHARS
|
|
2876
|
+
);
|
|
2797
2877
|
}
|
|
2798
2878
|
function evictTransformCacheOnce() {
|
|
2799
2879
|
if (!cacheEnabled) {
|
|
@@ -2901,6 +2981,12 @@ function createCsszyxPlugins(options = {}) {
|
|
|
2901
2981
|
scanDir(sourceDir);
|
|
2902
2982
|
}
|
|
2903
2983
|
for (const { filePath, result } of transformPrescanSources(prescanSources)) {
|
|
2984
|
+
if (result.classes.size === 0 && result.rawClassNames.size === 0 && result.diagnostics.some((d) => d.includes("[csszyx] parse error in "))) {
|
|
2985
|
+
console.warn(
|
|
2986
|
+
`[csszyx] prescan skipped ${filePath}: the file failed to parse, so none of its classes reached the safelist. Fix the syntax error (or check the file extension matches its contents).`
|
|
2987
|
+
);
|
|
2988
|
+
continue;
|
|
2989
|
+
}
|
|
2904
2990
|
if (!result.transformed && result.classes.size === 0) {
|
|
2905
2991
|
continue;
|
|
2906
2992
|
}
|
|
@@ -3091,7 +3177,7 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3091
3177
|
* @returns true only for csszyx virtual modules
|
|
3092
3178
|
*/
|
|
3093
3179
|
loadInclude(id) {
|
|
3094
|
-
return id === RESOLVED_VIRTUAL_MODULE_ID || id === RESOLVED_VIRTUAL_CHECKSUM_ID;
|
|
3180
|
+
return id === RESOLVED_VIRTUAL_MODULE_ID || id === RESOLVED_VIRTUAL_CHECKSUM_ID || id === RESOLVED_THEME_GROUPS_VIRTUAL_ID;
|
|
3095
3181
|
},
|
|
3096
3182
|
/**
|
|
3097
3183
|
* Loads virtual module content — generates mangle map or checksum module code.
|
|
@@ -3112,6 +3198,15 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3112
3198
|
finalizeMangleMap();
|
|
3113
3199
|
return createChecksumModule(state.checksum);
|
|
3114
3200
|
}
|
|
3201
|
+
if (id === RESOLVED_THEME_GROUPS_VIRTUAL_ID) {
|
|
3202
|
+
const theme = state.parsedTheme;
|
|
3203
|
+
return createThemeGroupsModule({
|
|
3204
|
+
colors: theme?.colors ?? [],
|
|
3205
|
+
textSizes: theme?.textSizes ?? [],
|
|
3206
|
+
fontFamilies: theme?.fonts ?? [],
|
|
3207
|
+
fontWeights: theme?.fontWeights ?? []
|
|
3208
|
+
});
|
|
3209
|
+
}
|
|
3115
3210
|
return null;
|
|
3116
3211
|
},
|
|
3117
3212
|
/**
|
|
@@ -3134,13 +3229,14 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3134
3229
|
* @returns transformed code with source map, or null if no changes were made
|
|
3135
3230
|
*/
|
|
3136
3231
|
transform(code, id) {
|
|
3232
|
+
announceActiveParser();
|
|
3137
3233
|
if (!shouldProcessCss(id) && !shouldProcessSource(id)) {
|
|
3138
3234
|
return null;
|
|
3139
3235
|
}
|
|
3140
3236
|
if (shouldProcessSource(id)) {
|
|
3141
|
-
|
|
3237
|
+
trackGlobalVarSourceFile(id, code);
|
|
3142
3238
|
}
|
|
3143
|
-
if (
|
|
3239
|
+
if (matchesScriptExtension(id, SCRIPT_ID_EXTENSIONS)) {
|
|
3144
3240
|
assertNoRSCBoundaryViolation(code, id);
|
|
3145
3241
|
}
|
|
3146
3242
|
if (/\.css(\?.*)?$/.test(id)) {
|
|
@@ -3268,7 +3364,12 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3268
3364
|
transformed = true;
|
|
3269
3365
|
}
|
|
3270
3366
|
}
|
|
3271
|
-
if (
|
|
3367
|
+
if (/\bszcn\s*\(/.test(code) && !transformedCode.includes(THEME_GROUPS_VIRTUAL_ID) && shouldProcessSource(id)) {
|
|
3368
|
+
transformedCode = `import '${THEME_GROUPS_VIRTUAL_ID}';
|
|
3369
|
+
${transformedCode}`;
|
|
3370
|
+
transformed = true;
|
|
3371
|
+
}
|
|
3372
|
+
if (matchesScriptExtension(id, SCRIPT_ID_EXTENSIONS)) {
|
|
3272
3373
|
assertNoRSCBoundaryViolation(transformedCode, id);
|
|
3273
3374
|
const record = createRSCModuleRecord(transformedCode, id);
|
|
3274
3375
|
state.rscModules.set(record.id, record);
|
|
@@ -3344,13 +3445,14 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3344
3445
|
*/
|
|
3345
3446
|
webpack(compiler) {
|
|
3346
3447
|
compiler.hooks.beforeCompile.tap("csszyx:prescan", () => {
|
|
3448
|
+
announceActiveParser();
|
|
3347
3449
|
const root = compiler.context || process.cwd();
|
|
3348
3450
|
state.rootDir = root;
|
|
3349
3451
|
evictTransformCacheOnce();
|
|
3350
3452
|
if (state.classes.size === 0) {
|
|
3351
3453
|
prescanAndWriteClasses();
|
|
3352
3454
|
}
|
|
3353
|
-
runThemeScan(root, options.build?.scanCss);
|
|
3455
|
+
state.parsedTheme = runThemeScan(root, options.build?.scanCss) ?? state.parsedTheme;
|
|
3354
3456
|
});
|
|
3355
3457
|
if (options.build?.scanCss) {
|
|
3356
3458
|
compiler.hooks.thisCompilation.tap("csszyx:theme-deps", (compilation) => {
|
|
@@ -3368,6 +3470,7 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3368
3470
|
* @param config - the resolved Vite configuration object
|
|
3369
3471
|
*/
|
|
3370
3472
|
configResolved(config) {
|
|
3473
|
+
announceActiveParser();
|
|
3371
3474
|
const root = config.root || process.cwd();
|
|
3372
3475
|
state.rootDir = root;
|
|
3373
3476
|
if (config.command === "serve") {
|
|
@@ -3375,7 +3478,7 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3375
3478
|
}
|
|
3376
3479
|
evictTransformCacheOnce();
|
|
3377
3480
|
prescanAndWriteClasses();
|
|
3378
|
-
runThemeScan(root, options.build?.scanCss);
|
|
3481
|
+
state.parsedTheme = runThemeScan(root, options.build?.scanCss) ?? state.parsedTheme;
|
|
3379
3482
|
},
|
|
3380
3483
|
/**
|
|
3381
3484
|
* Vite HMR hook: re-runs theme scan when a watched CSS file changes,
|
|
@@ -3387,7 +3490,13 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3387
3490
|
if (scanCss) {
|
|
3388
3491
|
const root = ctx.server.config.root || process.cwd();
|
|
3389
3492
|
if (matchesAnyPattern(ctx.file, scanCss, root)) {
|
|
3390
|
-
runThemeScan(root, scanCss);
|
|
3493
|
+
state.parsedTheme = runThemeScan(root, scanCss) ?? state.parsedTheme;
|
|
3494
|
+
const themeGroupsModule = ctx.server.moduleGraph.getModuleById(
|
|
3495
|
+
RESOLVED_THEME_GROUPS_VIRTUAL_ID
|
|
3496
|
+
);
|
|
3497
|
+
if (themeGroupsModule) {
|
|
3498
|
+
ctx.server.moduleGraph.invalidateModule(themeGroupsModule);
|
|
3499
|
+
}
|
|
3391
3500
|
}
|
|
3392
3501
|
}
|
|
3393
3502
|
if (!shouldProcessSource(ctx.file)) {
|
|
@@ -3400,7 +3509,7 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3400
3509
|
return;
|
|
3401
3510
|
}
|
|
3402
3511
|
if (!fileContent.includes("sz=") && !fileContent.includes("szs=") && !/\bsz\s*:\s*["'{]/.test(fileContent)) {
|
|
3403
|
-
|
|
3512
|
+
trackGlobalVarSourceFile(ctx.file, fileContent);
|
|
3404
3513
|
recordFileVarMangleEntries(state, ctx.file, []);
|
|
3405
3514
|
recordFileCSSVariableMetrics(state, ctx.file, null);
|
|
3406
3515
|
return;
|
|
@@ -3414,19 +3523,19 @@ function createCsszyxPlugins(options = {}) {
|
|
|
3414
3523
|
node_perf_hooks.performance.now() - hmrTransformStarted
|
|
3415
3524
|
);
|
|
3416
3525
|
} catch {
|
|
3417
|
-
|
|
3526
|
+
trackGlobalVarSourceFile(ctx.file, fileContent);
|
|
3418
3527
|
recordFileVarMangleEntries(state, ctx.file, []);
|
|
3419
3528
|
recordFileCSSVariableMetrics(state, ctx.file, null);
|
|
3420
3529
|
return;
|
|
3421
3530
|
}
|
|
3422
3531
|
if (!result.transformed) {
|
|
3423
|
-
|
|
3532
|
+
trackGlobalVarSourceFile(ctx.file, fileContent);
|
|
3424
3533
|
recordFileVarMangleEntries(state, ctx.file, []);
|
|
3425
3534
|
recordFileCSSVariableMetrics(state, ctx.file, null);
|
|
3426
3535
|
return;
|
|
3427
3536
|
}
|
|
3428
3537
|
const sizeBefore = state.classes.size;
|
|
3429
|
-
|
|
3538
|
+
trackGlobalVarSourceFile(ctx.file, fileContent);
|
|
3430
3539
|
for (const cls of result.classes) {
|
|
3431
3540
|
addSafelistClass(cls);
|
|
3432
3541
|
state.ownedClasses.add(cls);
|
|
@@ -3846,6 +3955,7 @@ exports.normalizeGlobalVarAliasesForCache = normalizeGlobalVarAliasesForCache;
|
|
|
3846
3955
|
exports.parseThemeBlocks = parseThemeBlocks;
|
|
3847
3956
|
exports.planGlobalVarAliases = planGlobalVarAliases;
|
|
3848
3957
|
exports.readGlobalVarScanCache = readGlobalVarScanCache;
|
|
3958
|
+
exports.recordGlobalVarSourceFile = recordGlobalVarSourceFile;
|
|
3849
3959
|
exports.resolveCompileSourceDirs = resolveCompileSourceDirs;
|
|
3850
3960
|
exports.resolveGlobalVarScanCacheDir = resolveGlobalVarScanCacheDir;
|
|
3851
3961
|
exports.resolveNativeCacheIdentity = resolveNativeCacheIdentity;
|
|
@@ -3853,6 +3963,7 @@ exports.rewriteGlobalVarCssAliases = rewriteGlobalVarCssAliases;
|
|
|
3853
3963
|
exports.rollupPlugin = rollupPlugin;
|
|
3854
3964
|
exports.scanGlobalVarCss = scanGlobalVarCss;
|
|
3855
3965
|
exports.shouldEmitWarning = shouldEmitWarning;
|
|
3966
|
+
exports.shouldTrackGlobalVarSources = shouldTrackGlobalVarSources;
|
|
3856
3967
|
exports.shouldWarnMissingTailwindEntry = shouldWarnMissingTailwindEntry;
|
|
3857
3968
|
exports.shouldWarnUnscopedMonorepo = shouldWarnUnscopedMonorepo;
|
|
3858
3969
|
exports.skippedSzFilesMessage = skippedSzFilesMessage;
|
|
@@ -199,8 +199,22 @@ function listJsonFiles(dir) {
|
|
|
199
199
|
}
|
|
200
200
|
return files;
|
|
201
201
|
}
|
|
202
|
+
function evictMemoryCacheToBudget(cache, totalCodeChars, maxEntries, maxCodeChars) {
|
|
203
|
+
let total = totalCodeChars;
|
|
204
|
+
while (cache.size > maxEntries || total > maxCodeChars && cache.size > 1) {
|
|
205
|
+
const oldest = cache.keys().next().value;
|
|
206
|
+
if (oldest === void 0) {
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
const evicted = cache.get(oldest);
|
|
210
|
+
cache.delete(oldest);
|
|
211
|
+
total -= evicted?.code.length ?? 0;
|
|
212
|
+
}
|
|
213
|
+
return total;
|
|
214
|
+
}
|
|
202
215
|
|
|
203
216
|
exports.createTransformCacheKey = createTransformCacheKey;
|
|
217
|
+
exports.evictMemoryCacheToBudget = evictMemoryCacheToBudget;
|
|
204
218
|
exports.evictOldTransformCacheEntries = evictOldTransformCacheEntries;
|
|
205
219
|
exports.readTransformCache = readTransformCache;
|
|
206
220
|
exports.resolveTransformCacheDir = resolveTransformCacheDir;
|