@csszyx/unplugin 0.11.7 → 0.11.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +6 -1
  2. package/dist/css-mangler.cjs +9 -6
  3. package/dist/css-mangler.mjs +9 -6
  4. package/dist/index.cjs +5 -4
  5. package/dist/index.d.cts +2 -2
  6. package/dist/index.d.mts +2 -2
  7. package/dist/index.mjs +4 -4
  8. package/dist/next-config.cjs +1 -1
  9. package/dist/next-config.mjs +1 -1
  10. package/dist/next-prebuild.cjs +5 -5
  11. package/dist/next-prebuild.mjs +5 -5
  12. package/dist/next-turbo-loader.cjs +7 -12
  13. package/dist/next-turbo-loader.mjs +7 -12
  14. package/dist/next-watcher.cjs +2 -2
  15. package/dist/next-watcher.mjs +2 -2
  16. package/dist/shared/{unplugin.Dqt1aLCX.mjs → unplugin.7TELUwsj.mjs} +5 -3
  17. package/dist/shared/unplugin.B3XoSRB8.mjs +40 -0
  18. package/dist/shared/unplugin.BkRah5Ot.cjs +48 -0
  19. package/dist/shared/{unplugin.VSslRpfN.mjs → unplugin.Bqx2WfBV.mjs} +51 -50
  20. package/dist/shared/{unplugin.PhOFTQpB.d.cts → unplugin.CjCKWnoX.d.cts} +25 -6
  21. package/dist/shared/{unplugin.PhOFTQpB.d.mts → unplugin.CjCKWnoX.d.mts} +25 -6
  22. package/dist/shared/{unplugin.CwcOd1q3.mjs → unplugin.D-K57LNR.mjs} +6 -1
  23. package/dist/shared/{unplugin.ByAzFdqO.cjs → unplugin.DUI48s3S.cjs} +1181 -766
  24. package/dist/shared/{unplugin.D8vSG36M.cjs → unplugin.DVCQC5wq.cjs} +6 -0
  25. package/dist/shared/{unplugin.Rov-j_Wm.cjs → unplugin.DmuOKVS4.cjs} +21 -0
  26. package/dist/shared/{unplugin.D6hes1O8.cjs → unplugin.WVn08Fln.cjs} +5 -3
  27. package/dist/shared/{unplugin.CZKUWN1J.cjs → unplugin.jZsBqx54.cjs} +51 -50
  28. package/dist/shared/unplugin.nnsa7OVW.mjs +49 -0
  29. package/dist/shared/{unplugin.CtHwCYxE.mjs → unplugin.wx3cvxxX.mjs} +1180 -766
  30. package/dist/vite.cjs +4 -4
  31. package/dist/vite.d.cts +2 -25
  32. package/dist/vite.d.mts +1 -25
  33. package/dist/vite.mjs +4 -8
  34. package/dist/webpack.cjs +4 -4
  35. package/dist/webpack.d.cts +2 -5
  36. package/dist/webpack.d.mts +1 -5
  37. package/dist/webpack.mjs +4 -8
  38. package/package.json +7 -7
  39. package/dist/shared/unplugin.B1mblcm-.mjs +0 -9
  40. package/dist/shared/unplugin.B3RHYokB.mjs +0 -29
  41. package/dist/shared/unplugin.BCwRIUs_.cjs +0 -12
@@ -14,9 +14,9 @@ const types = require('@csszyx/types');
14
14
  const vueAdapter = require('@csszyx/vue-adapter');
15
15
  const unplugin$1 = require('unplugin');
16
16
  const cssMangler = require('../css-mangler.cjs');
17
- const htmlEscape = require('./unplugin.BCwRIUs_.cjs');
18
- const runtimeImportScan = require('./unplugin.Rov-j_Wm.cjs');
19
- const transformCache = require('./unplugin.D8vSG36M.cjs');
17
+ const runtimeImportScan = require('./unplugin.DmuOKVS4.cjs');
18
+ const transformCache = require('./unplugin.DVCQC5wq.cjs');
19
+ const htmlEscape = require('./unplugin.BkRah5Ot.cjs');
20
20
  const postcss = require('postcss');
21
21
  const valueParser = require('postcss-value-parser');
22
22
 
@@ -116,7 +116,8 @@ function buildScopeId(node) {
116
116
  }
117
117
  current = current.parent;
118
118
  }
119
- return parts.reverse().join(" > ") || DEFAULT_SCOPE_ID;
119
+ parts.reverse();
120
+ return parts.join(" > ") || DEFAULT_SCOPE_ID;
120
121
  }
121
122
 
122
123
  const VAR_REFERENCE_RE = /var\(\s*(--[\w-]+)/g;
@@ -389,7 +390,7 @@ function rewriteGlobalVarValue(value, aliases) {
389
390
  return;
390
391
  }
391
392
  const firstArgument = node.nodes.find((child) => child.type !== "space");
392
- if (!firstArgument || firstArgument.type !== "word") {
393
+ if (firstArgument?.type !== "word") {
393
394
  return;
394
395
  }
395
396
  const alias = aliases.get(firstArgument.value);
@@ -539,8 +540,8 @@ function createRSCModuleRecord(code, id) {
539
540
  }
540
541
  function deleteRSCModuleRecord(records, id) {
541
542
  const normalized = normalizeModuleId(id);
542
- const clean = id.split("?")[0]?.replace(/\\/g, "/") ?? id;
543
- const resolved = path__namespace.resolve(clean).replace(/\\/g, "/");
543
+ const clean = transformCache.normalizePathSeparators(id.split("?")[0] ?? id);
544
+ const resolved = transformCache.normalizePathSeparators(path__namespace.resolve(clean));
544
545
  pruneRSCModulePathCaches(/* @__PURE__ */ new Set([normalized, resolved, clean]));
545
546
  let deleted = records.delete(normalized);
546
547
  if (resolved !== normalized) {
@@ -586,7 +587,7 @@ const APP_ROUTER_ENTRIES = /* @__PURE__ */ new Set([
586
587
  "route"
587
588
  ]);
588
589
  function isNextAppRouterEntry(id) {
589
- const clean = id.split("?")[0]?.replace(/\\/g, "/") ?? id;
590
+ const clean = transformCache.normalizePathSeparators(id.split("?")[0] ?? id);
590
591
  if (!clean.includes("/app/") && !clean.startsWith("app/")) return false;
591
592
  const basename = clean.split("/").pop() ?? "";
592
593
  const dotIdx = basename.indexOf(".");
@@ -658,7 +659,7 @@ function findDirectiveStatementEnd(code, start) {
658
659
  }
659
660
  function readDirectivePrologue(code) {
660
661
  const out = [];
661
- let i = code.charCodeAt(0) === 65279 ? 1 : 0;
662
+ let i = readCodePoint(code, 0) === 65279 ? 1 : 0;
662
663
  while (i < code.length) {
663
664
  i = skipWhitespaceAndComments(code, i);
664
665
  const quote = code[i];
@@ -725,55 +726,50 @@ function findStaticImports(code) {
725
726
  let cursor = 0;
726
727
  while (cursor < code.length) {
727
728
  const importStart = code.indexOf("import", cursor);
728
- if (importStart === -1) {
729
- break;
730
- }
731
- cursor = importStart + 6;
732
- if (importStart > 0 && isIdentifierPart(code.charCodeAt(importStart - 1)) || isIdentifierPart(code.charCodeAt(cursor))) {
733
- continue;
734
- }
735
- let position = skipAsciiWhitespace(code, cursor);
736
- const opener = code.charAt(position);
737
- if (opener === "(") {
738
- continue;
739
- }
740
- if (opener === '"' || opener === "'") {
741
- const literal2 = readQuotedString(code, position);
742
- if (literal2) {
743
- imports.push({ clause: null, source: literal2.value });
744
- cursor = literal2.end;
745
- }
746
- continue;
747
- }
748
- const clauseStart = position;
749
- let fromStart = -1;
750
- while (position < code.length) {
751
- if (code.startsWith("from", position) && (position === clauseStart || !isIdentifierPart(code.charCodeAt(position - 1))) && !isIdentifierPart(code.charCodeAt(position + 4))) {
752
- fromStart = position;
753
- break;
754
- }
755
- if (code.charAt(position) === ";") {
756
- break;
757
- }
758
- position += 1;
759
- }
760
- if (fromStart === -1) {
761
- continue;
762
- }
763
- const clause = code.slice(clauseStart, fromStart).trim();
764
- if (splitAsciiWhitespace(clause)[0] === "type") {
765
- cursor = fromStart + 4;
766
- continue;
767
- }
768
- position = skipAsciiWhitespace(code, fromStart + 4);
769
- const literal = readQuotedString(code, position);
770
- if (literal) {
771
- imports.push({ clause, source: literal.value });
772
- cursor = literal.end;
773
- }
729
+ if (importStart === -1) break;
730
+ const result = scanStaticImport(code, importStart);
731
+ cursor = result.nextCursor;
732
+ if (result.value) imports.push(result.value);
774
733
  }
775
734
  return imports;
776
735
  }
736
+ function scanStaticImport(code, importStart) {
737
+ const afterKeyword = importStart + 6;
738
+ if (importStart > 0 && isIdentifierPart(readCodePoint(code, importStart - 1)) || isIdentifierPart(readCodePoint(code, afterKeyword))) {
739
+ return { nextCursor: afterKeyword };
740
+ }
741
+ const clauseStart = skipAsciiWhitespace(code, afterKeyword);
742
+ const opener = code.charAt(clauseStart);
743
+ if (opener === "(") return { nextCursor: afterKeyword };
744
+ if (opener === '"' || opener === "'") {
745
+ return scanSideEffectImport(code, clauseStart, afterKeyword);
746
+ }
747
+ return scanImportClause(code, clauseStart, afterKeyword);
748
+ }
749
+ function scanSideEffectImport(code, literalStart, fallbackCursor) {
750
+ const literal = readQuotedString(code, literalStart);
751
+ return literal ? { nextCursor: literal.end, value: { clause: null, source: literal.value } } : { nextCursor: fallbackCursor };
752
+ }
753
+ function scanImportClause(code, clauseStart, fallbackCursor) {
754
+ const fromStart = findImportFromKeyword(code, clauseStart);
755
+ if (fromStart === -1) return { nextCursor: fallbackCursor };
756
+ const clause = code.slice(clauseStart, fromStart).trim();
757
+ if (splitAsciiWhitespace(clause)[0] === "type") {
758
+ return { nextCursor: fromStart + 4 };
759
+ }
760
+ const literalStart = skipAsciiWhitespace(code, fromStart + 4);
761
+ const literal = readQuotedString(code, literalStart);
762
+ return literal ? { nextCursor: literal.end, value: { clause, source: literal.value } } : { nextCursor: fallbackCursor };
763
+ }
764
+ function findImportFromKeyword(code, clauseStart) {
765
+ for (let position = clauseStart; position < code.length; position += 1) {
766
+ if (code.charAt(position) === ";") return -1;
767
+ if (code.startsWith("from", position) && (position === clauseStart || !isIdentifierPart(readCodePoint(code, position - 1))) && !isIdentifierPart(readCodePoint(code, position + 4))) {
768
+ return position;
769
+ }
770
+ }
771
+ return -1;
772
+ }
777
773
  function readQuotedString(code, start) {
778
774
  const quote = code.charAt(start);
779
775
  if (quote !== '"' && quote !== "'") {
@@ -801,7 +797,7 @@ function readQuotedString(code, start) {
801
797
  function skipAsciiWhitespace(code, start) {
802
798
  let index = start;
803
799
  while (index < code.length) {
804
- const charCode = code.charCodeAt(index);
800
+ const charCode = readCodePoint(code, index);
805
801
  if (charCode !== 9 && charCode !== 10 && charCode !== 13 && charCode !== 32) {
806
802
  break;
807
803
  }
@@ -946,9 +942,9 @@ function normalizeModuleId(id) {
946
942
  }
947
943
  let normalized;
948
944
  try {
949
- normalized = fs__namespace.realpathSync.native(clean).replace(/\\/g, "/");
945
+ normalized = transformCache.normalizePathSeparators(fs__namespace.realpathSync.native(clean));
950
946
  } catch {
951
- normalized = path__namespace.resolve(clean).replace(/\\/g, "/");
947
+ normalized = transformCache.normalizePathSeparators(path__namespace.resolve(clean));
952
948
  }
953
949
  normalizedModuleIdCache.set(clean, normalized);
954
950
  return normalized;
@@ -994,7 +990,7 @@ function resolveLocalModule(importer, source) {
994
990
  }
995
991
  function pruneRSCModulePathCaches(moduleIds) {
996
992
  for (const [key, value] of normalizedModuleIdCache) {
997
- const normalizedKey = key.replace(/\\/g, "/");
993
+ const normalizedKey = transformCache.normalizePathSeparators(key);
998
994
  if (moduleIds.has(value) || moduleIds.has(normalizedKey)) {
999
995
  normalizedModuleIdCache.delete(key);
1000
996
  }
@@ -1038,11 +1034,11 @@ function readImportedSymbols(clause) {
1038
1034
  return symbols;
1039
1035
  }
1040
1036
  function isIdentifier(value) {
1041
- if (value.length === 0 || !isIdentifierStart(value.charCodeAt(0))) {
1037
+ if (value.length === 0 || !isIdentifierStart(readCodePoint(value, 0))) {
1042
1038
  return false;
1043
1039
  }
1044
1040
  for (let index = 1; index < value.length; index += 1) {
1045
- const code = value.charCodeAt(index);
1041
+ const code = readCodePoint(value, index);
1046
1042
  if (!isIdentifierStart(code) && (code < 48 || code > 57)) {
1047
1043
  return false;
1048
1044
  }
@@ -1052,11 +1048,14 @@ function isIdentifier(value) {
1052
1048
  function isIdentifierStart(code) {
1053
1049
  return code === 36 || code === 95 || code >= 65 && code <= 90 || code >= 97 && code <= 122;
1054
1050
  }
1051
+ function readCodePoint(value, index) {
1052
+ return value.codePointAt(index) ?? -1;
1053
+ }
1055
1054
  function splitAsciiWhitespace(value) {
1056
1055
  const parts = [];
1057
1056
  let start = -1;
1058
1057
  for (let index = 0; index <= value.length; index += 1) {
1059
- const code = index < value.length ? value.charCodeAt(index) : 32;
1058
+ const code = index < value.length ? readCodePoint(value, index) : 32;
1060
1059
  const whitespace = code === 9 || code === 10 || code === 13 || code === 32;
1061
1060
  if (whitespace) {
1062
1061
  if (start !== -1) {
@@ -1079,13 +1078,7 @@ function stripCommentsForImportScan(code) {
1079
1078
  const next = code[i + 1];
1080
1079
  if (quote) {
1081
1080
  out += ch;
1082
- if (escaped) {
1083
- escaped = false;
1084
- } else if (ch === "\\") {
1085
- escaped = true;
1086
- } else if (ch === quote) {
1087
- quote = null;
1088
- }
1081
+ ({ quote, escaped } = advanceQuotedImportScan(ch, quote, escaped));
1089
1082
  i++;
1090
1083
  continue;
1091
1084
  }
@@ -1096,28 +1089,15 @@ function stripCommentsForImportScan(code) {
1096
1089
  continue;
1097
1090
  }
1098
1091
  if (ch === "/" && next === "/") {
1099
- out += " ";
1100
- i += 2;
1101
- while (i < code.length && code[i] !== "\n") {
1102
- out += " ";
1103
- i++;
1104
- }
1092
+ const masked = maskLineComment(code, i);
1093
+ out += masked.value;
1094
+ i = masked.end;
1105
1095
  continue;
1106
1096
  }
1107
1097
  if (ch === "/" && next === "*") {
1108
- out += " ";
1109
- i += 2;
1110
- while (i < code.length) {
1111
- const blockCh = code[i];
1112
- const blockNext = code[i + 1];
1113
- if (blockCh === "*" && blockNext === "/") {
1114
- out += " ";
1115
- i += 2;
1116
- break;
1117
- }
1118
- out += blockCh === "\n" ? "\n" : " ";
1119
- i++;
1120
- }
1098
+ const masked = maskBlockComment(code, i);
1099
+ out += masked.value;
1100
+ i = masked.end;
1121
1101
  continue;
1122
1102
  }
1123
1103
  out += ch;
@@ -1125,6 +1105,31 @@ function stripCommentsForImportScan(code) {
1125
1105
  }
1126
1106
  return out;
1127
1107
  }
1108
+ function advanceQuotedImportScan(character, quote, escaped) {
1109
+ if (escaped) return { quote, escaped: false };
1110
+ if (character === "\\") return { quote, escaped: true };
1111
+ return { quote: character === quote ? null : quote, escaped: false };
1112
+ }
1113
+ function maskLineComment(code, start) {
1114
+ const newline = code.indexOf("\n", start + 2);
1115
+ const end = newline === -1 ? code.length : newline;
1116
+ return { end, value: " ".repeat(end - start) };
1117
+ }
1118
+ function maskBlockComment(code, start) {
1119
+ let end = start + 2;
1120
+ while (end < code.length) {
1121
+ if (code.charAt(end) === "*" && code.charAt(end + 1) === "/") {
1122
+ end += 2;
1123
+ break;
1124
+ }
1125
+ end += 1;
1126
+ }
1127
+ let value = "";
1128
+ for (let index = start; index < end; index += 1) {
1129
+ value += code.charAt(index) === "\n" ? "\n" : " ";
1130
+ }
1131
+ return { end, value };
1132
+ }
1128
1133
 
1129
1134
  const EMPTY_THEME = {
1130
1135
  colors: [],
@@ -1175,15 +1180,44 @@ function stripLayerWrappers(css) {
1175
1180
  }
1176
1181
  return result;
1177
1182
  }
1183
+ function themePreludeStart(css, at) {
1184
+ const cursor = at + "@theme".length;
1185
+ const next = css[cursor];
1186
+ const validBoundary = next === "{" || next === " " || next === " " || next === "\n" || next === "\r";
1187
+ return validBoundary ? cursor : null;
1188
+ }
1189
+ function readThemeBlock(css, start) {
1190
+ for (let cursor = start; cursor < css.length; cursor++) {
1191
+ const character = css[cursor];
1192
+ if (character === "{") {
1193
+ const close = findMatchingBrace(css, cursor);
1194
+ return {
1195
+ body: close === -1 ? null : css.slice(cursor + 1, close),
1196
+ end: close === -1 ? cursor : close
1197
+ };
1198
+ }
1199
+ if (character === ";" || character === "}" || character === "@") {
1200
+ return { body: null, end: cursor };
1201
+ }
1202
+ }
1203
+ return { body: null, end: css.length };
1204
+ }
1178
1205
  function extractThemeBlocks(css) {
1179
1206
  const blocks = [];
1180
- const themeStart = /@theme\s+(?:inline\s+)?\{|@theme\{/g;
1181
- for (const match of css.matchAll(themeStart)) {
1182
- const openPos = css.indexOf("{", match.index);
1183
- const closePos = findMatchingBrace(css, openPos);
1184
- if (closePos !== -1) {
1185
- blocks.push(css.slice(openPos + 1, closePos));
1207
+ let searchFrom = 0;
1208
+ for (; ; ) {
1209
+ const at = css.indexOf("@theme", searchFrom);
1210
+ if (at === -1) {
1211
+ break;
1186
1212
  }
1213
+ const preludeStart = themePreludeStart(css, at);
1214
+ if (preludeStart === null) {
1215
+ searchFrom = at + "@theme".length;
1216
+ continue;
1217
+ }
1218
+ const match = readThemeBlock(css, preludeStart);
1219
+ if (match.body !== null) blocks.push(match.body);
1220
+ searchFrom = Math.max(match.end, at + "@theme".length);
1187
1221
  }
1188
1222
  return blocks;
1189
1223
  }
@@ -1328,13 +1362,382 @@ function scanCustomPropertyNames(block) {
1328
1362
  return names;
1329
1363
  }
1330
1364
 
1365
+ const REGEX_PREFIXES = new Set("([{:,;=!?&|+-*%^~<>/");
1366
+ const REGEX_PREFIX_KEYWORDS = /* @__PURE__ */ new Set([
1367
+ "await",
1368
+ "case",
1369
+ "delete",
1370
+ "do",
1371
+ "else",
1372
+ "in",
1373
+ "instanceof",
1374
+ "of",
1375
+ "return",
1376
+ "throw",
1377
+ "typeof",
1378
+ "void",
1379
+ "yield"
1380
+ ]);
1381
+ const SIMPLE_ESCAPES = {
1382
+ b: "\b",
1383
+ f: "\f",
1384
+ n: "\n",
1385
+ r: "\r",
1386
+ t: " ",
1387
+ v: "\v",
1388
+ "0": "\0"
1389
+ };
1390
+ function decodeBracedUnicodeEscape(value, cursor) {
1391
+ if (value[cursor] !== "u" || value[cursor + 1] !== "{") return null;
1392
+ const close = value.indexOf("}", cursor + 2);
1393
+ const hex = close === -1 ? "" : value.slice(cursor + 2, close);
1394
+ const codePoint = hex && /^[\dA-F]+$/i.test(hex) ? Number.parseInt(hex, 16) : -1;
1395
+ if (codePoint < 0 || codePoint > 1114111) return null;
1396
+ return { value: String.fromCodePoint(codePoint), cursor: close };
1397
+ }
1398
+ function decodeFixedWidthEscape(value, cursor) {
1399
+ const escaped = value[cursor];
1400
+ let width = 0;
1401
+ if (escaped === "x") width = 2;
1402
+ if (escaped === "u") width = 4;
1403
+ const hex = value.slice(cursor + 1, cursor + width + 1);
1404
+ if (width === 0 || !isFixedHex(hex, width)) return null;
1405
+ return {
1406
+ value: String.fromCodePoint(Number.parseInt(hex, 16)),
1407
+ cursor: cursor + width
1408
+ };
1409
+ }
1410
+ function isFixedHex(value, width) {
1411
+ if (value.length !== width) return false;
1412
+ for (const character of value) {
1413
+ if (!"0123456789abcdefABCDEF".includes(character)) return false;
1414
+ }
1415
+ return true;
1416
+ }
1417
+ function decodeEscape(value, cursor) {
1418
+ const escaped = value[cursor];
1419
+ if (SIMPLE_ESCAPES[escaped] !== void 0) {
1420
+ return { value: SIMPLE_ESCAPES[escaped], cursor };
1421
+ }
1422
+ if (escaped === "\r" && value[cursor + 1] === "\n") {
1423
+ return { value: "", cursor: cursor + 1 };
1424
+ }
1425
+ const bracedUnicode = decodeBracedUnicodeEscape(value, cursor);
1426
+ if (bracedUnicode) return bracedUnicode;
1427
+ const fixedWidth = decodeFixedWidthEscape(value, cursor);
1428
+ if (fixedWidth) return fixedWidth;
1429
+ const decoded = escaped === "\n" || escaped === "\r" ? "" : escaped;
1430
+ return { value: decoded, cursor };
1431
+ }
1432
+ function decodeJavaScriptString(value) {
1433
+ let output = "";
1434
+ let cursor = 0;
1435
+ while (cursor < value.length) {
1436
+ if (value[cursor] !== "\\" || cursor + 1 >= value.length) {
1437
+ output += value[cursor++];
1438
+ continue;
1439
+ }
1440
+ const decoded = decodeEscape(value, cursor + 1);
1441
+ output += decoded.value;
1442
+ cursor = decoded.cursor + 1;
1443
+ }
1444
+ return output;
1445
+ }
1446
+ function decodeAttributeWhitespace(value) {
1447
+ return value.replace(
1448
+ /&#(?:(\d+)|x([\da-f]+));|&(?:Tab|NewLine);/gi,
1449
+ (entity, decimal, hexadecimal) => {
1450
+ if (!decimal && !hexadecimal) return " ";
1451
+ const codePoint = Number.parseInt(decimal ?? hexadecimal ?? "", decimal ? 10 : 16);
1452
+ return [9, 10, 12, 13, 32].includes(codePoint) ? " " : entity;
1453
+ }
1454
+ );
1455
+ }
1456
+ function collectClassTokens(target, value) {
1457
+ for (const className of value.split(/\s+/)) {
1458
+ if (className) target.add(className);
1459
+ }
1460
+ }
1461
+ function quotedEnd(source, start, quote) {
1462
+ let cursor = start + 1;
1463
+ while (cursor < source.length) {
1464
+ if (source[cursor] === "\\") cursor += 2;
1465
+ else if (source[cursor++] === quote) break;
1466
+ }
1467
+ return cursor;
1468
+ }
1469
+ function commentEnd(source, start) {
1470
+ if (source[start + 1] === "/") {
1471
+ const end2 = source.indexOf("\n", start + 2);
1472
+ return end2 === -1 ? source.length : end2 + 1;
1473
+ }
1474
+ const end = source.indexOf("*/", start + 2);
1475
+ return end === -1 ? source.length : end + 2;
1476
+ }
1477
+ function isRegexStart(source, start) {
1478
+ let cursor = start - 1;
1479
+ while (cursor >= 0 && /\s/.test(source[cursor])) cursor--;
1480
+ if (source[cursor] === "<" && /[A-Z]/i.test(source[start + 1] ?? "")) return false;
1481
+ if (cursor < 0 || REGEX_PREFIXES.has(source[cursor])) return true;
1482
+ if (!/[\w$]/.test(source[cursor])) return false;
1483
+ const end = cursor + 1;
1484
+ while (cursor >= 0 && /[\w$]/.test(source[cursor])) cursor--;
1485
+ return REGEX_PREFIX_KEYWORDS.has(source.slice(cursor + 1, end));
1486
+ }
1487
+ function regexEnd(source, start) {
1488
+ let cursor = start + 1;
1489
+ let inCharacterClass = false;
1490
+ while (cursor < source.length) {
1491
+ const character = source[cursor];
1492
+ if (character === "\\") cursor += 2;
1493
+ else if (character === "[") {
1494
+ inCharacterClass = true;
1495
+ cursor++;
1496
+ } else if (character === "]") {
1497
+ inCharacterClass = false;
1498
+ cursor++;
1499
+ } else if (character === "/" && !inCharacterClass) {
1500
+ cursor++;
1501
+ while (/[A-Z]/i.test(source[cursor] ?? "")) cursor++;
1502
+ break;
1503
+ } else cursor++;
1504
+ }
1505
+ return cursor;
1506
+ }
1507
+ function templateEnd(source, start) {
1508
+ let cursor = start + 1;
1509
+ while (cursor < source.length) {
1510
+ if (source[cursor] === "\\") cursor += 2;
1511
+ else if (source[cursor] === "`") return cursor + 1;
1512
+ else if (source[cursor] === "$" && source[cursor + 1] === "{") {
1513
+ cursor = findBalancedCodeEnd(source, cursor + 2);
1514
+ } else cursor++;
1515
+ }
1516
+ return source.length;
1517
+ }
1518
+ function lexicalRegionEnd(source, start) {
1519
+ const character = source[start];
1520
+ if (character === '"' || character === "'") return quotedEnd(source, start, character);
1521
+ if (character === "`") return templateEnd(source, start);
1522
+ if (character === "/" && (source[start + 1] === "/" || source[start + 1] === "*")) {
1523
+ return commentEnd(source, start);
1524
+ }
1525
+ if (character === "/" && isRegexStart(source, start)) return regexEnd(source, start);
1526
+ return start;
1527
+ }
1528
+ function findBalancedCodeEnd(source, bodyStart) {
1529
+ let depth = 1;
1530
+ let cursor = bodyStart;
1531
+ while (cursor < source.length) {
1532
+ const regionEnd = lexicalRegionEnd(source, cursor);
1533
+ if (regionEnd !== cursor) {
1534
+ cursor = regionEnd;
1535
+ continue;
1536
+ }
1537
+ if (source[cursor] === "{") depth++;
1538
+ else if (source[cursor] === "}" && --depth === 0) return cursor;
1539
+ cursor++;
1540
+ }
1541
+ return source.length;
1542
+ }
1543
+ function collectTemplateTokens(target, source, start) {
1544
+ let cursor = start + 1;
1545
+ let quasiStart = cursor;
1546
+ while (cursor < source.length) {
1547
+ if (source[cursor] === "\\") {
1548
+ cursor += 2;
1549
+ continue;
1550
+ }
1551
+ if (source[cursor] === "`") {
1552
+ collectClassTokens(target, decodeJavaScriptString(source.slice(quasiStart, cursor)));
1553
+ return cursor + 1;
1554
+ }
1555
+ if (source[cursor] === "$" && source[cursor + 1] === "{") {
1556
+ collectClassTokens(target, decodeJavaScriptString(source.slice(quasiStart, cursor)));
1557
+ const expressionEnd = findBalancedCodeEnd(source, cursor + 2);
1558
+ collectExpressionTokens(target, source.slice(cursor + 2, expressionEnd));
1559
+ cursor = expressionEnd + 1;
1560
+ quasiStart = cursor;
1561
+ continue;
1562
+ }
1563
+ cursor++;
1564
+ }
1565
+ collectClassTokens(target, decodeJavaScriptString(source.slice(quasiStart)));
1566
+ return source.length;
1567
+ }
1568
+ function collectExpressionTokens(target, expression) {
1569
+ let cursor = 0;
1570
+ let pendingLiteral = "";
1571
+ let previousLiteralEnd = -1;
1572
+ const flushPending = () => {
1573
+ if (pendingLiteral) collectClassTokens(target, pendingLiteral);
1574
+ pendingLiteral = "";
1575
+ };
1576
+ while (cursor < expression.length) {
1577
+ const character = expression[cursor];
1578
+ if (character === "/" && (expression[cursor + 1] === "/" || expression[cursor + 1] === "*")) {
1579
+ cursor = commentEnd(expression, cursor);
1580
+ continue;
1581
+ }
1582
+ if (character === "/" && isRegexStart(expression, cursor)) {
1583
+ cursor = regexEnd(expression, cursor);
1584
+ continue;
1585
+ }
1586
+ if (character === "`") {
1587
+ flushPending();
1588
+ cursor = collectTemplateTokens(target, expression, cursor);
1589
+ previousLiteralEnd = -1;
1590
+ continue;
1591
+ }
1592
+ if (character !== '"' && character !== "'") {
1593
+ cursor++;
1594
+ continue;
1595
+ }
1596
+ const end = quotedEnd(expression, cursor, character);
1597
+ const decoded = decodeJavaScriptString(expression.slice(cursor + 1, end - 1));
1598
+ const joinsPrevious = previousLiteralEnd >= 0 && expression.slice(previousLiteralEnd, cursor).trim() === "+";
1599
+ if (!joinsPrevious) flushPending();
1600
+ pendingLiteral += decoded;
1601
+ previousLiteralEnd = end;
1602
+ cursor = end;
1603
+ }
1604
+ flushPending();
1605
+ }
1606
+ function triviaEnd(source, start) {
1607
+ let cursor = start;
1608
+ while (cursor < source.length) {
1609
+ if (/\s/.test(source[cursor])) cursor++;
1610
+ else if (source[cursor] === "/" && (source[cursor + 1] === "/" || source[cursor + 1] === "*")) {
1611
+ cursor = commentEnd(source, cursor);
1612
+ } else break;
1613
+ }
1614
+ return cursor;
1615
+ }
1616
+ function propertyExpressionEnd(source, start) {
1617
+ let cursor = start;
1618
+ let parenDepth = 0;
1619
+ let bracketDepth = 0;
1620
+ let braceDepth = 0;
1621
+ while (cursor < source.length) {
1622
+ const regionEnd = lexicalRegionEnd(source, cursor);
1623
+ if (regionEnd !== cursor) {
1624
+ cursor = regionEnd;
1625
+ continue;
1626
+ }
1627
+ const character = source[cursor];
1628
+ if (character === "(") parenDepth++;
1629
+ else if (character === ")") parenDepth--;
1630
+ else if (character === "[") bracketDepth++;
1631
+ else if (character === "]") bracketDepth--;
1632
+ else if (character === "{") braceDepth++;
1633
+ else if (character === "}" && braceDepth > 0) braceDepth--;
1634
+ else if ((character === "," || character === ";" || character === "}") && parenDepth === 0 && bracketDepth === 0 && braceDepth === 0)
1635
+ return cursor;
1636
+ cursor++;
1637
+ }
1638
+ return source.length;
1639
+ }
1640
+ function isClassSink(source, start, end) {
1641
+ const name = source.slice(start, end);
1642
+ if (name !== "class" && name !== "className") return false;
1643
+ let previous = start - 1;
1644
+ while (previous >= 0 && /\s/.test(source[previous])) previous--;
1645
+ return source[previous] !== "." && source[previous] !== "-";
1646
+ }
1647
+ function collectClassDirective(target, source, sinkStart, valueStart) {
1648
+ if (!/[\w$-]/.test(source[valueStart] ?? "")) return null;
1649
+ let directiveEnd = valueStart;
1650
+ while (/[\w$-]/.test(source[directiveEnd] ?? "")) directiveEnd++;
1651
+ const equals = triviaEnd(source, directiveEnd);
1652
+ if (source[equals] !== "=") {
1653
+ const insideMarkupTag = source.lastIndexOf("<", sinkStart) > source.lastIndexOf(">", sinkStart);
1654
+ const next = source[equals] ?? "";
1655
+ const continuesMarkupTag = next === "/" || next === ">" || next === "{" || /[A-Z_:]/i.test(next);
1656
+ if (!insideMarkupTag || !continuesMarkupTag) return null;
1657
+ collectClassTokens(target, source.slice(valueStart, directiveEnd));
1658
+ return directiveEnd;
1659
+ }
1660
+ const directive = source.slice(valueStart, directiveEnd);
1661
+ const directiveValueStart = triviaEnd(source, equals + 1);
1662
+ const directiveQuote = source[directiveValueStart];
1663
+ if (directive !== "list") collectClassTokens(target, directive);
1664
+ if (directiveQuote === "{") {
1665
+ const end = findBalancedCodeEnd(source, directiveValueStart + 1);
1666
+ if (directive === "list") {
1667
+ collectExpressionTokens(target, source.slice(directiveValueStart + 1, end));
1668
+ }
1669
+ return end + 1;
1670
+ }
1671
+ if (directive === "list" && (directiveQuote === '"' || directiveQuote === "'")) {
1672
+ const end = quotedEnd(source, directiveValueStart, directiveQuote);
1673
+ collectExpressionTokens(target, source.slice(directiveValueStart, end));
1674
+ return end;
1675
+ }
1676
+ return directiveValueStart;
1677
+ }
1678
+ function collectClassSink(target, source, start, nameEnd) {
1679
+ const operatorStart = triviaEnd(source, nameEnd);
1680
+ const operator = source[operatorStart];
1681
+ if (operator !== "=" && operator !== ":") return nameEnd;
1682
+ const valueStart = triviaEnd(source, operatorStart + 1);
1683
+ const quote = source[valueStart];
1684
+ const vueBinding = operator === "=" && source.slice(Math.max(0, start - 1), start) === ":";
1685
+ if (operator === ":" && valueStart === operatorStart + 1) {
1686
+ const directiveEnd = collectClassDirective(target, source, start, valueStart);
1687
+ if (directiveEnd !== null) return directiveEnd;
1688
+ }
1689
+ if (quote === '"' || quote === "'") {
1690
+ const end = quotedEnd(source, valueStart, quote);
1691
+ const value = source.slice(valueStart + 1, end - 1);
1692
+ if (vueBinding) collectExpressionTokens(target, decodeAttributeWhitespace(value));
1693
+ else collectClassTokens(target, decodeAttributeWhitespace(value));
1694
+ return end;
1695
+ }
1696
+ if (operator === "=" && quote === "{") {
1697
+ const end = findBalancedCodeEnd(source, valueStart + 1);
1698
+ collectExpressionTokens(target, source.slice(valueStart + 1, end));
1699
+ return end + 1;
1700
+ }
1701
+ if (operator === ":") {
1702
+ const end = propertyExpressionEnd(source, valueStart);
1703
+ collectExpressionTokens(target, source.slice(valueStart, end));
1704
+ return end;
1705
+ }
1706
+ return valueStart;
1707
+ }
1708
+ function collectAuthoredClassNames(source) {
1709
+ const classes = /* @__PURE__ */ new Set();
1710
+ let cursor = 0;
1711
+ while (cursor < source.length) {
1712
+ if (source[cursor] === '"' || source[cursor] === "'") {
1713
+ const keyEnd = quotedEnd(source, cursor, source[cursor]);
1714
+ const key = decodeJavaScriptString(source.slice(cursor + 1, keyEnd - 1));
1715
+ cursor = key === "class" || key === "className" ? collectClassSink(classes, source, cursor, keyEnd) : keyEnd;
1716
+ continue;
1717
+ }
1718
+ const regionEnd = lexicalRegionEnd(source, cursor);
1719
+ if (regionEnd !== cursor) {
1720
+ cursor = regionEnd;
1721
+ continue;
1722
+ }
1723
+ if (!/[A-Z_$]/i.test(source[cursor])) {
1724
+ cursor++;
1725
+ continue;
1726
+ }
1727
+ let nameEnd = cursor + 1;
1728
+ while (/[\w$]/.test(source[nameEnd] ?? "")) nameEnd++;
1729
+ cursor = isClassSink(source, cursor, nameEnd) ? collectClassSink(classes, source, cursor, nameEnd) : nameEnd;
1730
+ }
1731
+ return classes;
1732
+ }
1733
+
1331
1734
  const GLOB_MAGIC_RE = /[*?[\]{}]/;
1332
1735
  const DEFAULT_IGNORED_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git", ".next", ".turbo", "dist", "build"]);
1333
1736
  function normalizeFileId(id) {
1334
- return id.split(/[?#]/, 1)[0].replace(/\\/g, "/");
1737
+ return transformCache.normalizePathSeparators(id.split(/[?#]/, 1)[0]);
1335
1738
  }
1336
1739
  function normalizeRoot(rootDir) {
1337
- return path__namespace.resolve(rootDir).replace(/\\/g, "/");
1740
+ return transformCache.normalizePathSeparators(path__namespace.resolve(rootDir));
1338
1741
  }
1339
1742
  function hasGlobMagic(pattern) {
1340
1743
  return GLOB_MAGIC_RE.test(pattern);
@@ -1343,7 +1746,7 @@ function escapeRegExp(ch) {
1343
1746
  return /[|\\{}()[\]^$+?.]/.test(ch) ? `\\${ch}` : ch;
1344
1747
  }
1345
1748
  function globToRegExp(pattern) {
1346
- const normalized = pattern.replace(/\\/g, "/");
1749
+ const normalized = transformCache.normalizePathSeparators(pattern);
1347
1750
  let out = "^";
1348
1751
  for (let i = 0; i < normalized.length; i++) {
1349
1752
  const ch = normalized[i];
@@ -1366,7 +1769,7 @@ function globToRegExp(pattern) {
1366
1769
  function relativeToRoot(file, rootDir) {
1367
1770
  const root = normalizeRoot(rootDir);
1368
1771
  const normalizedFile = normalizeFileId(file);
1369
- return path__namespace.posix.relative(root, normalizedFile).replace(/\\/g, "/");
1772
+ return transformCache.normalizePathSeparators(path__namespace.posix.relative(root, normalizedFile));
1370
1773
  }
1371
1774
  function matchesPattern(id, pattern, rootDir) {
1372
1775
  const file = normalizeFileId(id);
@@ -1375,7 +1778,7 @@ function matchesPattern(id, pattern, rootDir) {
1375
1778
  pattern.lastIndex = 0;
1376
1779
  return pattern.test(file) || pattern.test(relative);
1377
1780
  }
1378
- const normalizedPattern = pattern.replace(/\\/g, "/");
1781
+ const normalizedPattern = transformCache.normalizePathSeparators(pattern);
1379
1782
  if (hasGlobMagic(normalizedPattern)) {
1380
1783
  const re = globToRegExp(normalizedPattern);
1381
1784
  return re.test(file) || re.test(relative);
@@ -1442,9 +1845,15 @@ function expandFilePatterns(rootDir, patterns) {
1442
1845
  return htmlEscape.sortStrings(files);
1443
1846
  }
1444
1847
 
1848
+ const LINE_SEPARATOR$1 = String.fromCodePoint(8232);
1849
+ const PARAGRAPH_SEPARATOR$1 = String.fromCodePoint(8233);
1445
1850
  function safeJsonForScriptTag(value, prettyPrint = false) {
1446
1851
  const json = prettyPrint ? JSON.stringify(value, null, 2) : JSON.stringify(value);
1447
- return json.replace(/</g, "\\u003C").replace(/>/g, "\\u003E").replace(/&/g, "\\u0026").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
1852
+ let escaped = htmlEscape.replaceEveryLiteral(json, "<", htmlEscape.unicodeEscape("003C"));
1853
+ escaped = htmlEscape.replaceEveryLiteral(escaped, ">", htmlEscape.unicodeEscape("003E"));
1854
+ escaped = htmlEscape.replaceEveryLiteral(escaped, "&", htmlEscape.unicodeEscape("0026"));
1855
+ escaped = htmlEscape.replaceEveryLiteral(escaped, LINE_SEPARATOR$1, htmlEscape.unicodeEscape("2028"));
1856
+ return htmlEscape.replaceEveryLiteral(escaped, PARAGRAPH_SEPARATOR$1, htmlEscape.unicodeEscape("2029"));
1448
1857
  }
1449
1858
  function injectHtmlOpeningAttr(html, attr) {
1450
1859
  const lower = html.toLowerCase();
@@ -1576,11 +1985,17 @@ function injectRecoveryManifest(html, manifest) {
1576
1985
  return html + scriptTag;
1577
1986
  }
1578
1987
 
1988
+ const LINE_SEPARATOR = String.fromCodePoint(8232);
1989
+ const PARAGRAPH_SEPARATOR = String.fromCodePoint(8233);
1579
1990
  function escapeJsonForInlineScript(json) {
1580
- return json.replace(/`/g, "\\u0060").replace(/\$/g, "\\u0024").replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
1991
+ let escaped = htmlEscape.replaceEveryLiteral(json, "`", htmlEscape.unicodeEscape("0060"));
1992
+ escaped = htmlEscape.replaceEveryLiteral(escaped, "$", htmlEscape.unicodeEscape("0024"));
1993
+ escaped = htmlEscape.replaceEveryLiteral(escaped, "<", htmlEscape.unicodeEscape("003c"));
1994
+ escaped = htmlEscape.replaceEveryLiteral(escaped, LINE_SEPARATOR, htmlEscape.unicodeEscape("2028"));
1995
+ return htmlEscape.replaceEveryLiteral(escaped, PARAGRAPH_SEPARATOR, htmlEscape.unicodeEscape("2029"));
1581
1996
  }
1582
1997
  function escapeForDoubleQuotedString(value) {
1583
- return value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
1998
+ return htmlEscape.escapeDoubleQuotedString(value);
1584
1999
  }
1585
2000
 
1586
2001
  function isParserMode(value) {
@@ -1627,15 +2042,13 @@ function isSameFileVersion(before, after) {
1627
2042
  return before.dev === after.dev && before.ino === after.ino && before.size === after.size && before.mtimeNs === after.mtimeNs && before.ctimeNs === after.ctimeNs;
1628
2043
  }
1629
2044
 
1630
- function escapeTsString(value) {
1631
- return value.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\r/g, "\\r").replace(/\n/g, "\\n");
1632
- }
1633
2045
  function generateThemeDts(opts) {
1634
2046
  const { theme, sourceFiles } = opts;
1635
2047
  const timestamp = (/* @__PURE__ */ new Date()).toISOString();
1636
- const sources = sourceFiles.join(", ").replace(/[\r\n]/g, " ");
1637
- const toUnion = (tokens) => tokens.map((t) => `'${escapeTsString(t)}'`).join(" | ");
1638
- const quoteKey = (key) => /^[a-z_$][\w$]*$/i.test(key) ? key : `'${escapeTsString(key)}'`;
2048
+ const withoutCarriageReturns = htmlEscape.replaceEveryLiteral(sourceFiles.join(", "), "\r", " ");
2049
+ const sources = htmlEscape.replaceEveryLiteral(withoutCarriageReturns, "\n", " ");
2050
+ const toUnion = (tokens) => tokens.map((t) => `'${htmlEscape.escapeSingleQuotedString(t)}'`).join(" | ");
2051
+ const quoteKey = (key) => /^[a-z_$][\w$]*$/i.test(key) ? key : `'${htmlEscape.escapeSingleQuotedString(key)}'`;
1639
2052
  const entries = [];
1640
2053
  if (theme.colors.length > 0) {
1641
2054
  entries.push(` colors: ${toUnion(theme.colors)};`);
@@ -1773,6 +2186,15 @@ function createThemeGroupsModule(tokens) {
1773
2186
  ].join("\n");
1774
2187
  }
1775
2188
 
2189
+ function registerWebpackAssetProcessor(compiler, processAssets) {
2190
+ compiler.hooks.compilation.tap("csszyx:post", (compilation) => {
2191
+ const stage = compiler.webpack?.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE || compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE;
2192
+ compilation.hooks.processAssets.tap(
2193
+ { name: "csszyx:post", stage: stage || 400 },
2194
+ (assets) => processAssets(assets, compilation, compiler)
2195
+ );
2196
+ });
2197
+ }
1776
2198
  const CHECKSUM_PLACEHOLDER = "___CSSZYX_CHECKSUM___";
1777
2199
  const MANGLE_MAP_PLACEHOLDER = "___CSSZYX_MANGLE_MAP___";
1778
2200
  const VAR_MANGLE_MAP_PLACEHOLDER = "___CSSZYX_VAR_MANGLE_MAP___";
@@ -1784,7 +2206,6 @@ const TRANSFORM_MEMORY_CACHE_MAX_CODE_CHARS = 32e6;
1784
2206
  const MAX_SAFELIST_CLASSES = 1e5;
1785
2207
  const DEFAULT_VAR_MANGLE_MAP_MAX_BYTES = 100 * 1024;
1786
2208
  const GLOBAL_VAR_ALIAS_MAP_OWNER = "\0csszyx:global-var-aliases";
1787
- const DIRECTIVE_PROLOGUE_PREFIX_RE = /^((?:\s|\/\/[^\n]*\n|\/\*(?:[^*]|\*(?!\/))*\*\/)*)(['"]use (?:client|server)['"];?\s*)/;
1788
2209
  function findOpeningTag(source, tag) {
1789
2210
  const lower = source.toLowerCase();
1790
2211
  const marker = `<${tag}`;
@@ -1810,9 +2231,9 @@ let _hasWarnedTransformCacheVersion = false;
1810
2231
  let _hasWarnedNativeFallback = false;
1811
2232
  const _loggedActiveParsers = /* @__PURE__ */ new Set();
1812
2233
  const _babelFallbackFiles = /* @__PURE__ */ new Set();
1813
- 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.ByAzFdqO.cjs', document.baseURI).href)));
2234
+ 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.DUI48s3S.cjs', document.baseURI).href)));
1814
2235
  const PLUGIN_VERSION = findPackageVersionFromFile(
1815
- node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/unplugin.ByAzFdqO.cjs', document.baseURI).href))),
2236
+ node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/unplugin.DUI48s3S.cjs', document.baseURI).href))),
1816
2237
  UNKNOWN_PACKAGE_VERSION
1817
2238
  );
1818
2239
  const COMPILER_VERSION = findPackageVersionFromModule("@csszyx/compiler", UNKNOWN_PACKAGE_VERSION);
@@ -1857,10 +2278,10 @@ function stripCssBlockComments(code) {
1857
2278
  let i = 0;
1858
2279
  const n = code.length;
1859
2280
  while (i < n) {
1860
- if (code.charCodeAt(i) === SLASH && code.charCodeAt(i + 1) === STAR) {
2281
+ if (code.codePointAt(i) === SLASH && code.codePointAt(i + 1) === STAR) {
1861
2282
  out += code.slice(last, i);
1862
2283
  i += 2;
1863
- while (i < n && !(code.charCodeAt(i) === STAR && code.charCodeAt(i + 1) === SLASH)) {
2284
+ while (i < n && !(code.codePointAt(i) === STAR && code.codePointAt(i + 1) === SLASH)) {
1864
2285
  i++;
1865
2286
  }
1866
2287
  i += 2;
@@ -1966,9 +2387,17 @@ function shouldEmitWarning(quiet, devOnly, isProduction) {
1966
2387
  return true;
1967
2388
  }
1968
2389
  function normalizeForMatch(p) {
1969
- const n = p.replace(/\\/g, "/");
2390
+ const n = transformCache.normalizePathSeparators(p);
1970
2391
  return n.length > 1 && n.endsWith("/") ? n.slice(0, -1) : n;
1971
2392
  }
2393
+ function findJsxExpressionEnd(code, bodyStart) {
2394
+ return findBalancedCodeEnd(code, bodyStart);
2395
+ }
2396
+ function warnPrescanBudgetSkip(filePath) {
2397
+ console.warn(
2398
+ `[csszyx] prescan skipped ${filePath}: the file exceeds the AST node budget, so NONE of its classes reached the safelist and their CSS will not be generated. Raise \`build.astBudgetLimit\` in the csszyx plugin options, or split the file.`
2399
+ );
2400
+ }
1972
2401
  function resolveCompileSourceDirs(root, sources, realpathDir = (p) => {
1973
2402
  try {
1974
2403
  const real = fs__namespace.realpathSync(p);
@@ -2021,6 +2450,9 @@ function fileMayContainSafelistableSz(content) {
2021
2450
  // engine-parity harness caught its classes missing on all engines.
2022
2451
  content.includes("dynamic(");
2023
2452
  }
2453
+ function mangleEligibleClasses(ownedClasses, authoredClasses) {
2454
+ return compiler.sortStrings([...ownedClasses].filter((className) => !authoredClasses.has(className)));
2455
+ }
2024
2456
  function isPackagesSkippedSource(id, sourceDirs = []) {
2025
2457
  const p = normalizeForMatch(id);
2026
2458
  if (p.includes("node_modules")) {
@@ -2041,8 +2473,8 @@ ${list}
2041
2473
  Add the package directory to \`compileSources\` (or move the file out of packages/) \u2014 otherwise their \`sz\` produces no CSS.`;
2042
2474
  }
2043
2475
  function computeSafelistRelPath(rootDir, safelistFilename, cssId) {
2044
- const safelistPath = path__namespace.join(rootDir, safelistFilename).replace(/\\/g, "/");
2045
- const cssDir = path__namespace.dirname(cssId).replace(/\\/g, "/");
2476
+ const safelistPath = transformCache.normalizePathSeparators(path__namespace.join(rootDir, safelistFilename));
2477
+ const cssDir = transformCache.normalizePathSeparators(path__namespace.dirname(cssId));
2046
2478
  let relPath = path__namespace.posix.relative(cssDir, safelistPath);
2047
2479
  if (!relPath.startsWith(".")) {
2048
2480
  relPath = `./${relPath}`;
@@ -2216,7 +2648,10 @@ function normalizeGlobalVarAliasesForCache(aliases) {
2216
2648
  if (!aliases) {
2217
2649
  return [];
2218
2650
  }
2219
- const entries = aliases instanceof Map ? aliases.entries() : Array.isArray(aliases) ? aliases : Object.entries(aliases);
2651
+ let entries;
2652
+ if (aliases instanceof Map) entries = aliases.entries();
2653
+ else if (Array.isArray(aliases)) entries = aliases;
2654
+ else entries = Object.entries(aliases);
2220
2655
  const normalized = /* @__PURE__ */ new Map();
2221
2656
  for (const [original, alias] of entries) {
2222
2657
  if (original.startsWith("--") && alias.startsWith("--")) {
@@ -2421,7 +2856,7 @@ function findPackageVersionFromFile(file, fallback) {
2421
2856
  }
2422
2857
  }
2423
2858
  function normalizeSourceFilename(filename) {
2424
- return filename.replace(/\\/g, "/");
2859
+ return transformCache.normalizePathSeparators(filename);
2425
2860
  }
2426
2861
  const SCRIPT_ID_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx"];
2427
2862
  const SOURCE_MODULE_EXTENSIONS = [...SCRIPT_ID_EXTENSIONS, ".cts", ".mts", ".cjs", ".mjs"];
@@ -2429,11 +2864,26 @@ function matchesScriptExtension(id, extensions) {
2429
2864
  return extensions.some((ext) => id.endsWith(ext) || id.includes(`${ext}?`));
2430
2865
  }
2431
2866
  function insertRuntimeImport(code, importStmt) {
2432
- const directiveMatch = code.match(DIRECTIVE_PROLOGUE_PREFIX_RE);
2433
- if (!directiveMatch) {
2434
- return `${importStmt}${code}`;
2867
+ return runtimeImportScan.insertAfterUseDirective(code, importStmt);
2868
+ }
2869
+ function scanClassExpression(source, from) {
2870
+ let depth = 0;
2871
+ let index = from;
2872
+ while (index < source.length) {
2873
+ const char = source[index];
2874
+ if (char === "(" || char === "[") {
2875
+ depth++;
2876
+ } else if (char === ")" || char === "]") {
2877
+ if (depth === 0) {
2878
+ break;
2879
+ }
2880
+ depth--;
2881
+ } else if (depth === 0 && (char === "," || char === ";" || char === "\n" || char === "}")) {
2882
+ break;
2883
+ }
2884
+ index++;
2435
2885
  }
2436
- return code.replace(directiveMatch[0], `${directiveMatch[1]}${directiveMatch[2]}${importStmt}`);
2886
+ return index;
2437
2887
  }
2438
2888
  function mangleCodeClassesSync(code, mangleMap) {
2439
2889
  function mangleClassString(classString) {
@@ -2441,6 +2891,58 @@ function mangleCodeClassesSync(code, mangleMap) {
2441
2891
  return mangleMap[cls.replace(/\\(.)/g, "$1")] || cls;
2442
2892
  }).join(" ");
2443
2893
  }
2894
+ function mangleClassTemplate(fullMatch, templateContent) {
2895
+ let changed = false;
2896
+ let output = "";
2897
+ let cursor = 0;
2898
+ while (cursor < templateContent.length) {
2899
+ const interpolationStart = templateContent.indexOf("${", cursor);
2900
+ const quasiEnd = interpolationStart === -1 ? templateContent.length : interpolationStart;
2901
+ const quasi = mangleTemplateQuasi(templateContent.slice(cursor, quasiEnd));
2902
+ output += quasi.value;
2903
+ changed ||= quasi.changed;
2904
+ if (interpolationStart === -1) break;
2905
+ const interpolationEnd = findTemplateInterpolationEnd(
2906
+ templateContent,
2907
+ interpolationStart + 2
2908
+ );
2909
+ const inner = templateContent.slice(interpolationStart + 2, interpolationEnd - 1);
2910
+ const interpolation = mangleTemplateInterpolation(inner);
2911
+ output += `\${${interpolation.value}}`;
2912
+ changed ||= interpolation.changed;
2913
+ cursor = interpolationEnd;
2914
+ }
2915
+ return changed ? `className:\`${output}\`` : fullMatch;
2916
+ }
2917
+ function mangleTemplateQuasi(quasi) {
2918
+ const trimmed = quasi.trim();
2919
+ if (!trimmed) return { value: quasi, changed: false };
2920
+ const mangled = mangleClassString(trimmed);
2921
+ return {
2922
+ value: mangled === trimmed ? quasi : quasi.replace(trimmed, mangled),
2923
+ changed: mangled !== trimmed
2924
+ };
2925
+ }
2926
+ function findTemplateInterpolationEnd(templateContent, bodyStart) {
2927
+ let depth = 0;
2928
+ for (let cursor = bodyStart; cursor < templateContent.length; cursor++) {
2929
+ if (templateContent[cursor] === "{") depth++;
2930
+ else if (templateContent[cursor] === "}" && depth-- === 0) return cursor + 1;
2931
+ }
2932
+ return templateContent.length;
2933
+ }
2934
+ function mangleTemplateInterpolation(inner) {
2935
+ let changed = false;
2936
+ const value = inner.replace(/"([^"]*)"/g, (quoted, classString) => {
2937
+ const parts = classString.split(/\s+/).filter(Boolean);
2938
+ if (parts.length === 0) return quoted;
2939
+ const mangled = parts.map((className) => mangleMap[className] || className).join(" ");
2940
+ if (mangled === classString) return quoted;
2941
+ changed = true;
2942
+ return `"${mangled}"`;
2943
+ });
2944
+ return { value, changed };
2945
+ }
2444
2946
  let result = code.replace(/(?:class(?:Name)?|sz)[:=]\s*"((?:[^"\\]|\\.)*)"/g, (match, classes) => {
2445
2947
  const mangled = mangleClassString(classes);
2446
2948
  if (mangled === classes) {
@@ -2454,92 +2956,7 @@ function mangleCodeClassesSync(code, mangleMap) {
2454
2956
  }
2455
2957
  return match.replace(classes, mangled);
2456
2958
  });
2457
- result = result.replace(/className:\s*`([^`]+)`/g, (fullMatch, tplContent) => {
2458
- let changed = false;
2459
- let out = "";
2460
- let i = 0;
2461
- while (i < tplContent.length) {
2462
- const interStart = tplContent.indexOf("${", i);
2463
- if (interStart === -1) {
2464
- const quasi2 = tplContent.slice(i);
2465
- const trimmed2 = quasi2.trim();
2466
- if (trimmed2) {
2467
- const m = mangleClassString(trimmed2);
2468
- if (m !== trimmed2) {
2469
- changed = true;
2470
- out += quasi2.replace(trimmed2, m);
2471
- } else {
2472
- out += quasi2;
2473
- }
2474
- } else {
2475
- out += quasi2;
2476
- }
2477
- break;
2478
- }
2479
- const quasi = tplContent.slice(i, interStart);
2480
- const trimmed = quasi.trim();
2481
- if (trimmed) {
2482
- const m = mangleClassString(trimmed);
2483
- if (m !== trimmed) {
2484
- changed = true;
2485
- out += quasi.replace(trimmed, m);
2486
- } else {
2487
- out += quasi;
2488
- }
2489
- } else {
2490
- out += quasi;
2491
- }
2492
- let j = interStart + 2;
2493
- let depth = 0;
2494
- while (j < tplContent.length) {
2495
- if (tplContent[j] === "{") {
2496
- depth++;
2497
- } else if (tplContent[j] === "}") {
2498
- if (depth === 0) {
2499
- j++;
2500
- break;
2501
- }
2502
- depth--;
2503
- }
2504
- j++;
2505
- }
2506
- const interInner = tplContent.slice(interStart + 2, j - 1);
2507
- const mangledInner = interInner.replace(/"([^"]*)"/g, (qm, inner) => {
2508
- const parts = inner.split(/\s+/).filter(Boolean);
2509
- if (parts.length === 0) {
2510
- return qm;
2511
- }
2512
- const m = parts.map((p) => mangleMap[p] || p).join(" ");
2513
- if (m === inner) {
2514
- return qm;
2515
- }
2516
- changed = true;
2517
- return `"${m}"`;
2518
- });
2519
- out += `\${${mangledInner}}`;
2520
- i = j;
2521
- }
2522
- return changed ? `className:\`${out}\`` : fullMatch;
2523
- });
2524
- function scanClassExpression(source, from) {
2525
- let depth = 0;
2526
- let j = from;
2527
- while (j < source.length) {
2528
- const ch = source[j];
2529
- if (ch === "(" || ch === "[") {
2530
- depth++;
2531
- } else if (ch === ")" || ch === "]") {
2532
- if (depth === 0) {
2533
- break;
2534
- }
2535
- depth--;
2536
- } else if (depth === 0 && (ch === "," || ch === ";" || ch === "\n" || ch === "}")) {
2537
- break;
2538
- }
2539
- j++;
2540
- }
2541
- return j;
2542
- }
2959
+ result = result.replace(/className:\s*`([^`]+)`/g, mangleClassTemplate);
2543
2960
  function mangleTernaryClassStrings(expr) {
2544
2961
  const qIdx = expr.indexOf("?");
2545
2962
  if (qIdx === -1 || !expr.slice(qIdx).includes(":")) {
@@ -2747,7 +3164,12 @@ function createCsszyxPlugins(options = {}) {
2747
3164
  }
2748
3165
  if (!_loggedActiveParsers.has(parserMode)) {
2749
3166
  _loggedActiveParsers.add(parserMode);
2750
- const detail = parserDegraded ? "oxc (degraded from default `rust`: no native binary for this platform)" : parserMode === "rust" ? "rust (native engine)" : parserMode;
3167
+ let detail = parserMode;
3168
+ if (parserDegraded) {
3169
+ detail = "oxc (degraded from default `rust`: no native binary for this platform)";
3170
+ } else if (parserMode === "rust") {
3171
+ detail = "rust (native engine)";
3172
+ }
2751
3173
  console.warn(`[csszyx] active parser: ${detail}`);
2752
3174
  }
2753
3175
  }
@@ -2758,6 +3180,7 @@ function createCsszyxPlugins(options = {}) {
2758
3180
  const state = {
2759
3181
  classes: /* @__PURE__ */ new Set(),
2760
3182
  parsedTheme: null,
3183
+ autoThemeCssFiles: [],
2761
3184
  sawTailwindEntry: false,
2762
3185
  sawAnyCss: false,
2763
3186
  tailwindWarningEmitted: false,
@@ -2768,6 +3191,7 @@ function createCsszyxPlugins(options = {}) {
2768
3191
  skipWarningEmitted: false,
2769
3192
  classesCapped: false,
2770
3193
  ownedClasses: /* @__PURE__ */ new Set(),
3194
+ authoredClasses: /* @__PURE__ */ new Set(),
2771
3195
  mangleMap: {},
2772
3196
  varMangleEntriesByFile: /* @__PURE__ */ new Map(),
2773
3197
  varMangleMap: Object.fromEntries(earlyGlobalVarAliasEntries),
@@ -2857,6 +3281,59 @@ function createCsszyxPlugins(options = {}) {
2857
3281
  );
2858
3282
  }
2859
3283
  }
3284
+ function runAutoThemeScan(rootDir) {
3285
+ if (options.build?.scanCss) {
3286
+ return;
3287
+ }
3288
+ refreshCompileSourceDirs();
3289
+ const cssFiles = [];
3290
+ const walk = (dir) => {
3291
+ let entries;
3292
+ try {
3293
+ entries = fs__namespace.readdirSync(dir, { withFileTypes: true });
3294
+ } catch {
3295
+ return;
3296
+ }
3297
+ for (const entry of entries) {
3298
+ if (entry.isDirectory()) {
3299
+ if (!IGNORE_DIRS.has(entry.name) && !entry.name.startsWith(".")) {
3300
+ walk(path__namespace.join(dir, entry.name));
3301
+ }
3302
+ continue;
3303
+ }
3304
+ if (entry.name.endsWith(".css")) {
3305
+ cssFiles.push(path__namespace.join(dir, entry.name));
3306
+ }
3307
+ }
3308
+ };
3309
+ walk(rootDir);
3310
+ const normRoot = normalizeForMatch(rootDir);
3311
+ for (const sourceDir of compileSourceDirs) {
3312
+ if (sourceDir === normRoot || sourceDir.startsWith(`${normRoot}/`)) {
3313
+ continue;
3314
+ }
3315
+ walk(sourceDir);
3316
+ }
3317
+ const themes = [];
3318
+ const themeFiles = [];
3319
+ for (const file of cssFiles) {
3320
+ let content;
3321
+ try {
3322
+ content = fs__namespace.readFileSync(file, "utf-8");
3323
+ } catch {
3324
+ continue;
3325
+ }
3326
+ if (!content.includes("@theme")) {
3327
+ continue;
3328
+ }
3329
+ themes.push(parseThemeBlocks(content));
3330
+ themeFiles.push(file);
3331
+ }
3332
+ state.autoThemeCssFiles = themeFiles;
3333
+ if (themes.length > 0) {
3334
+ state.parsedTheme = mergeThemes(themes);
3335
+ }
3336
+ }
2860
3337
  function isHardIgnored(id) {
2861
3338
  refreshCompileSourceDirs();
2862
3339
  return isHardIgnoredPath(id, compileSourceDirs);
@@ -2884,53 +3361,76 @@ function createCsszyxPlugins(options = {}) {
2884
3361
  }
2885
3362
  const cacheKey = cacheEnabled ? transformCache.createTransformCacheKey(cacheInput) : null;
2886
3363
  if (cacheEnabled && cacheKey) {
2887
- const memoryCached = transformMemoryCache.get(cacheKey.key);
2888
- if (memoryCached) {
2889
- transformMemoryCache.delete(cacheKey.key);
2890
- transformMemoryCache.set(cacheKey.key, memoryCached);
2891
- return memoryCached;
2892
- }
2893
- const cached = transformCache.readTransformCache(cacheRoot, cacheInput, cacheKey);
2894
- if (cached) {
2895
- rememberTransformCacheEntry(cacheKey.key, cached);
2896
- return cached;
2897
- }
2898
- if (astBudget === void 0) {
2899
- const handoff = prescanResultHandoff.get(effectiveFilename);
2900
- if (handoff) {
2901
- prescanResultHandoff.delete(effectiveFilename);
2902
- if (handoff.inputSha256 === cacheKey.inputSha256) {
2903
- return handoff.result;
2904
- }
2905
- }
2906
- }
2907
- }
2908
- let result;
3364
+ const cached = findConfiguredTransformCacheEntry(
3365
+ cacheRoot,
3366
+ cacheInput,
3367
+ cacheKey,
3368
+ effectiveFilename,
3369
+ astBudget
3370
+ );
3371
+ if (cached) return cached;
3372
+ }
3373
+ const execution = runConfiguredParser(source, effectiveFilename, compilerOptions);
3374
+ if (cacheEnabled && cacheKey && execution.cacheable) {
3375
+ transformCache.writeTransformCache(cacheRoot, cacheInput, execution.result, cacheKey);
3376
+ rememberTransformCacheEntry(cacheKey.key, execution.result);
3377
+ }
3378
+ return execution.result;
3379
+ }
3380
+ function findConfiguredTransformCacheEntry(cacheRoot, cacheInput, cacheKey, effectiveFilename, astBudget) {
3381
+ const memoryCached = transformMemoryCache.get(cacheKey.key);
3382
+ if (memoryCached) {
3383
+ transformMemoryCache.delete(cacheKey.key);
3384
+ transformMemoryCache.set(cacheKey.key, memoryCached);
3385
+ return memoryCached;
3386
+ }
3387
+ const diskCached = transformCache.readTransformCache(cacheRoot, cacheInput, cacheKey);
3388
+ if (diskCached) {
3389
+ rememberTransformCacheEntry(cacheKey.key, diskCached);
3390
+ return diskCached;
3391
+ }
3392
+ if (astBudget !== void 0) return null;
3393
+ const handoff = prescanResultHandoff.get(effectiveFilename);
3394
+ if (!handoff) return null;
3395
+ prescanResultHandoff.delete(effectiveFilename);
3396
+ return handoff.inputSha256 === cacheKey.inputSha256 ? handoff.result : null;
3397
+ }
3398
+ function runConfiguredParser(source, effectiveFilename, compilerOptions) {
2909
3399
  if (parserMode === "babel") {
2910
- result = compiler.transformSourceCode(source, effectiveFilename, compilerOptions);
2911
- } else if (parserMode === "rust") {
2912
- result = compiler.transformRust(source, effectiveFilename, compilerOptions);
2913
- } else {
2914
- try {
2915
- result = compiler.transformOxc(source, effectiveFilename, compilerOptions);
2916
- } catch (err) {
2917
- result = compiler.transformSourceCode(source, effectiveFilename, compilerOptions);
2918
- const reason = err instanceof Error ? err.message : String(err);
2919
- result.diagnostics.push(
2920
- `[csszyx] oxc parser fell back to Babel for ${effectiveFilename}: ${reason}`
2921
- );
2922
- if (!_babelFallbackFiles.has(effectiveFilename)) {
2923
- _babelFallbackFiles.add(effectiveFilename);
2924
- console.warn(
2925
- `[csszyx] oxc parser fell back to Babel for ${effectiveFilename}: ${reason} (${_babelFallbackFiles.size} file(s) so far). Output is still correct; this usually means the file uses a syntax the oxc lane does not yet handle.`
2926
- );
2927
- }
2928
- return result;
2929
- }
3400
+ return {
3401
+ result: compiler.transformSourceCode(source, effectiveFilename, compilerOptions),
3402
+ cacheable: true
3403
+ };
2930
3404
  }
2931
- if (cacheEnabled && cacheKey) {
2932
- transformCache.writeTransformCache(cacheRoot, cacheInput, result, cacheKey);
2933
- rememberTransformCacheEntry(cacheKey.key, result);
3405
+ if (parserMode === "rust") {
3406
+ return {
3407
+ result: compiler.transformRust(source, effectiveFilename, compilerOptions),
3408
+ cacheable: true
3409
+ };
3410
+ }
3411
+ try {
3412
+ return {
3413
+ result: compiler.transformOxc(source, effectiveFilename, compilerOptions),
3414
+ cacheable: true
3415
+ };
3416
+ } catch (error) {
3417
+ return {
3418
+ result: runBabelFallback(source, effectiveFilename, compilerOptions, error),
3419
+ cacheable: false
3420
+ };
3421
+ }
3422
+ }
3423
+ function runBabelFallback(source, effectiveFilename, compilerOptions, error) {
3424
+ const result = compiler.transformSourceCode(source, effectiveFilename, compilerOptions);
3425
+ const reason = error instanceof Error ? error.message : String(error);
3426
+ result.diagnostics.push(
3427
+ `[csszyx] oxc parser fell back to Babel for ${effectiveFilename}: ${reason}`
3428
+ );
3429
+ if (!_babelFallbackFiles.has(effectiveFilename)) {
3430
+ _babelFallbackFiles.add(effectiveFilename);
3431
+ console.warn(
3432
+ `[csszyx] oxc parser fell back to Babel for ${effectiveFilename}: ${reason} (${_babelFallbackFiles.size} file(s) so far). Output is still correct; this usually means the file uses a syntax the oxc lane does not yet handle.`
3433
+ );
2934
3434
  }
2935
3435
  return result;
2936
3436
  }
@@ -2969,11 +3469,19 @@ function createCsszyxPlugins(options = {}) {
2969
3469
  const compilerOptions = createCompilerOptions(prescanAstBudget);
2970
3470
  const cacheRoot = transformCache.resolveTransformCacheDir(state.rootDir, options.build?.cacheDir);
2971
3471
  const results = /* @__PURE__ */ new Map();
2972
- const misses = [];
2973
- if (cacheEnabled) {
2974
- evictTransformCacheOnce();
2975
- }
3472
+ if (cacheEnabled) evictTransformCacheOnce();
2976
3473
  compiler.ensureRustTransformAvailable();
3474
+ const misses = collectRustPrescanMisses(files, compilerOptions, cacheRoot, results);
3475
+ if (misses.length === 0) return orderPrescanResults(files, results);
3476
+ try {
3477
+ runRustPrescanBatch(misses, compilerOptions, cacheRoot, results);
3478
+ } catch {
3479
+ runRustPrescanFallback(misses, results);
3480
+ }
3481
+ return orderPrescanResults(files, results);
3482
+ }
3483
+ function collectRustPrescanMisses(files, compilerOptions, cacheRoot, results) {
3484
+ const misses = [];
2977
3485
  for (const file of files) {
2978
3486
  const effectiveFilename = normalizeSourceFilename(file.filePath);
2979
3487
  const cacheInput = createConfiguredTransformCacheInput(
@@ -2982,79 +3490,54 @@ function createCsszyxPlugins(options = {}) {
2982
3490
  compilerOptions
2983
3491
  );
2984
3492
  const cacheKey = cacheEnabled ? transformCache.createTransformCacheKey(cacheInput) : null;
2985
- if (cacheEnabled && cacheKey) {
2986
- const memoryCached = transformMemoryCache.get(cacheKey.key);
2987
- if (memoryCached) {
2988
- transformMemoryCache.delete(cacheKey.key);
2989
- transformMemoryCache.set(cacheKey.key, memoryCached);
2990
- results.set(file.filePath, memoryCached);
2991
- continue;
2992
- }
2993
- const cached = transformCache.readTransformCache(cacheRoot, cacheInput, cacheKey);
2994
- if (cached) {
2995
- rememberTransformCacheEntry(cacheKey.key, cached);
2996
- results.set(file.filePath, cached);
2997
- continue;
2998
- }
2999
- }
3000
- misses.push({
3001
- filePath: file.filePath,
3002
- effectiveFilename,
3003
- content: file.content,
3493
+ const cached = cacheKey ? findConfiguredTransformCacheEntry(
3494
+ cacheRoot,
3004
3495
  cacheInput,
3005
- cacheKey
3006
- });
3496
+ cacheKey,
3497
+ effectiveFilename,
3498
+ prescanAstBudget
3499
+ ) : null;
3500
+ if (cached) results.set(file.filePath, cached);
3501
+ else misses.push({ ...file, effectiveFilename, cacheInput, cacheKey });
3007
3502
  }
3008
- if (misses.length === 0) {
3009
- return files.map((file) => {
3010
- const result = results.get(file.filePath);
3011
- return result ? { filePath: file.filePath, result } : null;
3012
- }).filter((entry) => entry !== null);
3503
+ return misses;
3504
+ }
3505
+ function runRustPrescanBatch(misses, compilerOptions, cacheRoot, results) {
3506
+ const batchResults = compiler.transformRustBatch(
3507
+ misses.map((file) => ({ filename: file.effectiveFilename, source: file.content })),
3508
+ compilerOptions
3509
+ );
3510
+ for (let index = 0; index < misses.length; index++) {
3511
+ const miss = misses[index];
3512
+ const result = batchResults[index];
3513
+ if (!miss || !result) continue;
3514
+ cacheRustPrescanResult(miss, result, cacheRoot);
3515
+ results.set(miss.filePath, result);
3013
3516
  }
3014
- try {
3015
- const batchResults = compiler.transformRustBatch(
3016
- misses.map((file) => ({
3017
- filename: file.effectiveFilename,
3018
- source: file.content
3019
- })),
3020
- compilerOptions
3021
- );
3022
- for (let index = 0; index < misses.length; index++) {
3023
- const miss = misses[index];
3024
- const result = batchResults[index];
3025
- if (!miss || !result) {
3026
- continue;
3027
- }
3028
- if (cacheEnabled && miss.cacheKey) {
3029
- transformCache.writeTransformCache(cacheRoot, miss.cacheInput, result, miss.cacheKey);
3030
- rememberTransformCacheEntry(miss.cacheKey.key, result);
3031
- }
3517
+ }
3518
+ function cacheRustPrescanResult(miss, result, cacheRoot) {
3519
+ if (!cacheEnabled || !miss.cacheKey) return;
3520
+ transformCache.writeTransformCache(cacheRoot, miss.cacheInput, result, miss.cacheKey);
3521
+ rememberTransformCacheEntry(miss.cacheKey.key, result);
3522
+ }
3523
+ function runRustPrescanFallback(misses, results) {
3524
+ for (const miss of misses) {
3525
+ try {
3526
+ const result = transformConfiguredSource(
3527
+ miss.content,
3528
+ miss.effectiveFilename,
3529
+ prescanAstBudget
3530
+ );
3032
3531
  results.set(miss.filePath, result);
3033
- }
3034
- } catch {
3035
- for (const miss of misses) {
3036
- try {
3037
- results.set(
3038
- miss.filePath,
3039
- transformConfiguredSource(
3040
- miss.content,
3041
- miss.effectiveFilename,
3042
- prescanAstBudget
3043
- )
3044
- );
3045
- } catch {
3046
- }
3532
+ } catch {
3047
3533
  }
3048
3534
  }
3049
- return files.map((file) => {
3050
- const result = results.get(file.filePath);
3051
- return result ? { filePath: file.filePath, result } : null;
3052
- }).filter((entry) => entry !== null);
3053
3535
  }
3054
- function warnPrescanBudgetSkip(filePath) {
3055
- console.warn(
3056
- `[csszyx] prescan skipped ${filePath}: the file exceeds the AST node budget, so NONE of its classes reached the safelist and their CSS will not be generated. Raise \`build.astBudgetLimit\` in the csszyx plugin options, or split the file.`
3057
- );
3536
+ function orderPrescanResults(files, results) {
3537
+ return files.flatMap((file) => {
3538
+ const result = results.get(file.filePath);
3539
+ return result ? [{ filePath: file.filePath, result }] : [];
3540
+ });
3058
3541
  }
3059
3542
  function transformPrescanSourcesIndividually(files) {
3060
3543
  const results = [];
@@ -3121,11 +3604,12 @@ function createCsszyxPlugins(options = {}) {
3121
3604
  return;
3122
3605
  }
3123
3606
  const safelistPath = path__namespace.join(state.rootDir, SAFELIST_FILENAME);
3124
- const classList = htmlEscape.escapeHtmlAttribute(Array.from(classes).join(" "));
3607
+ const classNames = Array.from(classes);
3608
+ const classList = htmlEscape.escapeHtmlAttribute(classNames.join(" "));
3125
3609
  const content = `<!-- Auto-generated by csszyx \u2014 DO NOT EDIT -->
3126
3610
  <!-- Tailwind CSS scans this file for class name detection -->
3127
3611
  <div class="${classList}"><div class="${classList}">x</div><div class="${classList}">x</div></div>
3128
- `;
3612
+ ` + htmlEscape.renderTailwindScannerCandidates(classNames);
3129
3613
  try {
3130
3614
  let existing = "";
3131
3615
  try {
@@ -3200,6 +3684,7 @@ function createCsszyxPlugins(options = {}) {
3200
3684
  } catch {
3201
3685
  return;
3202
3686
  }
3687
+ recordAuthoredClasses(content);
3203
3688
  if (fileMayContainSafelistableSz(content)) {
3204
3689
  prescanSources.push({ filePath, content });
3205
3690
  }
@@ -3302,7 +3787,7 @@ function createCsszyxPlugins(options = {}) {
3302
3787
  for (const kv of objStr.matchAll(numKv)) {
3303
3788
  try {
3304
3789
  collectTransformClasses(
3305
- compiler.transform({ [kv[1]]: parseFloat(kv[2]) }),
3790
+ compiler.transform({ [kv[1]]: Number.parseFloat(kv[2]) }),
3306
3791
  discoveredClasses
3307
3792
  );
3308
3793
  } catch {
@@ -3342,19 +3827,6 @@ function createCsszyxPlugins(options = {}) {
3342
3827
  }
3343
3828
  }
3344
3829
  }
3345
- function findJsxExpressionEnd(code, bodyStart) {
3346
- let depth = 1;
3347
- let index = bodyStart;
3348
- while (index < code.length && depth > 0) {
3349
- if (code[index] === "{") {
3350
- depth++;
3351
- } else if (code[index] === "}") {
3352
- depth--;
3353
- }
3354
- index++;
3355
- }
3356
- return index - 1;
3357
- }
3358
3830
  function collectExpressionClasses(code) {
3359
3831
  for (const match of code.matchAll(/className=\{/g)) {
3360
3832
  const bodyStart = (match.index ?? 0) + match[0].length;
@@ -3368,17 +3840,22 @@ function createCsszyxPlugins(options = {}) {
3368
3840
  collectQuotedAttributeClasses(code);
3369
3841
  collectExpressionClasses(code);
3370
3842
  }
3843
+ function recordAuthoredClasses(code) {
3844
+ for (const className of collectAuthoredClassNames(code)) {
3845
+ addSafelistClass(className);
3846
+ state.authoredClasses.add(className);
3847
+ }
3848
+ }
3371
3849
  function finalizeMangleMap() {
3372
- const sortedClasses = Array.from(state.ownedClasses);
3373
3850
  const newMap = {};
3374
3851
  let tokenIndex = 0;
3375
- for (let i = 0; i < sortedClasses.length; i++) {
3852
+ for (const className of mangleEligibleClasses(state.ownedClasses, state.authoredClasses)) {
3376
3853
  let token = core.encode(tokenIndex);
3377
- while (mangleReserved.has(token)) {
3854
+ while (mangleReserved.has(token) || state.authoredClasses.has(token)) {
3378
3855
  tokenIndex++;
3379
3856
  token = core.encode(tokenIndex);
3380
3857
  }
3381
- newMap[sortedClasses[i]] = token;
3858
+ newMap[className] = token;
3382
3859
  tokenIndex++;
3383
3860
  }
3384
3861
  state.mangleMap = newMap;
@@ -3426,6 +3903,147 @@ function createCsszyxPlugins(options = {}) {
3426
3903
  }
3427
3904
  return result;
3428
3905
  }
3906
+ function unchangedPreTransform(code) {
3907
+ return {
3908
+ code,
3909
+ transformed: false,
3910
+ usesRuntime: false,
3911
+ usesMerge: false,
3912
+ usesSzcn: false,
3913
+ usesSzPart: false,
3914
+ usesColorVar: false,
3915
+ usesSpacingVar: false,
3916
+ usesUnitVar: false
3917
+ };
3918
+ }
3919
+ function transformTailwindCssEntry(code, id) {
3920
+ state.sawAnyCss = true;
3921
+ if (!cssImportsTailwind(code)) return null;
3922
+ state.sawTailwindEntry = true;
3923
+ if (cssHasContentScope(code)) state.tailwindEntryScoped = true;
3924
+ if (!hasInjectableTailwindCandidate(state.classes)) return null;
3925
+ const relPath = computeSafelistRelPath(state.rootDir, SAFELIST_FILENAME, id);
3926
+ const transformed = appendTailwindSourceDirective(code, relPath);
3927
+ return transformed === null ? null : { code: transformed, map: null };
3928
+ }
3929
+ function reportTransformDiagnostics(result, id, warn) {
3930
+ for (const message of result.diagnostics) {
3931
+ if (message.includes("unresolvable sz spread")) {
3932
+ state.spreadWarnings.add(`${id}
3933
+ ${message}`);
3934
+ } else if (message.includes("AST budget exceeded")) {
3935
+ console.warn(`[csszyx] ${id}
3936
+ ${message}`);
3937
+ }
3938
+ }
3939
+ if (quiet || result.diagnostics.length === 0 || process.env.NODE_ENV === "production") {
3940
+ return;
3941
+ }
3942
+ for (const message of result.diagnostics) {
3943
+ if (message.includes("unresolvable sz spread") || message.includes("AST budget exceeded")) {
3944
+ continue;
3945
+ }
3946
+ warn(`[csszyx] ${id}
3947
+ ${message}`);
3948
+ }
3949
+ }
3950
+ function compilerPreTransformOutput(result) {
3951
+ return {
3952
+ code: result.code,
3953
+ transformed: result.transformed,
3954
+ usesRuntime: result.usesRuntime,
3955
+ usesMerge: result.usesMerge,
3956
+ usesSzcn: result.usesSzcn,
3957
+ usesSzPart: result.usesSzPart,
3958
+ usesColorVar: result.usesColorVar,
3959
+ usesSpacingVar: result.usesSpacingVar,
3960
+ usesUnitVar: result.usesUnitVar,
3961
+ szClasses: result.classes
3962
+ };
3963
+ }
3964
+ function transformSzSource(code, id, warn) {
3965
+ if (id.endsWith(".vue")) {
3966
+ const result2 = vueAdapter.preprocess(code, options);
3967
+ return { ...unchangedPreTransform(result2.code), transformed: result2.transformed };
3968
+ }
3969
+ if (id.endsWith(".svelte")) {
3970
+ const result2 = svelteAdapter.preprocess(code, options);
3971
+ return result2 ? { ...unchangedPreTransform(result2.code), transformed: true } : unchangedPreTransform(code);
3972
+ }
3973
+ const transformStarted = node_perf_hooks.performance.now();
3974
+ const result = transformConfiguredSource(code, id);
3975
+ traceBenchTiming("transform-hook", id, node_perf_hooks.performance.now() - transformStarted);
3976
+ recordFileVarMangleEntries(state, id, cssVariableEntries(result));
3977
+ recordFileCSSVariableMetrics(state, id, result.code);
3978
+ reportTransformDiagnostics(result, id, warn);
3979
+ for (const [token, data] of result.recoveryTokens) state.recoveryTokens.set(token, data);
3980
+ return compilerPreTransformOutput(result);
3981
+ }
3982
+ function injectLayoutHydration(code, id) {
3983
+ if (!code.includes("<html") || !/(?:layout|Root|Document|app)\.tsx?$/i.test(id)) {
3984
+ return null;
3985
+ }
3986
+ let transformedCode = code;
3987
+ const attrName = options.production?.minify ? "data-sz-cs" : "data-sz-checksum";
3988
+ const htmlTag = findOpeningTag(transformedCode, "html");
3989
+ if (htmlTag) {
3990
+ transformedCode = `${transformedCode.slice(0, htmlTag.close)} ${attrName}="${CHECKSUM_PLACEHOLDER}"${transformedCode.slice(htmlTag.close)}`;
3991
+ }
3992
+ 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})}}})()\`}} />`;
3993
+ const bodyTag = findOpeningTag(transformedCode, "body");
3994
+ if (bodyTag) {
3995
+ transformedCode = `${transformedCode.slice(0, bodyTag.close + 1)}${debugScript}${transformedCode.slice(bodyTag.close + 1)}`;
3996
+ }
3997
+ return transformedCode;
3998
+ }
3999
+ function requiredRuntimeHelpers(output) {
4000
+ const helpers = [];
4001
+ if (output.usesRuntime) helpers.push("_sz");
4002
+ if (output.usesMerge) helpers.push("_szMerge");
4003
+ if (output.usesSzcn) helpers.push("_szcn");
4004
+ if (output.usesSzPart) helpers.push("_szPart");
4005
+ if (output.usesColorVar) helpers.push("__szColorVar");
4006
+ if (output.usesSpacingVar) helpers.push("__szSpacingVar");
4007
+ if (output.usesUnitVar) helpers.push("__szUnitVar");
4008
+ return helpers;
4009
+ }
4010
+ function injectRuntimeHelpers(code, output) {
4011
+ const imports = requiredRuntimeHelpers(output);
4012
+ const hasRuntimeImport = imports.length > 0 && code.includes("@csszyx/runtime");
4013
+ const needed = hasRuntimeImport ? imports.filter((name) => !runtimeImportScan.importsRuntimeHelper(code, name)) : imports;
4014
+ if (needed.length === 0) return null;
4015
+ const existingImport = runtimeImportScan.findRuntimeImportClause(code);
4016
+ if (existingImport) {
4017
+ return code.replace(
4018
+ existingImport.statement,
4019
+ `${existingImport.prefixWithBody}, ${needed.join(", ")} } from '@csszyx/runtime'`
4020
+ );
4021
+ }
4022
+ const importStatement = `import { ${needed.join(", ")} } from '@csszyx/runtime';
4023
+ `;
4024
+ return insertRuntimeImport(code, importStatement);
4025
+ }
4026
+ function injectThemeGroups(code, transformedCode, id, usesSzcn) {
4027
+ if (!usesSzcn && !/\bszcn\s*\(/.test(code) || transformedCode.includes(THEME_GROUPS_VIRTUAL_ID) || !shouldProcessSource(id)) {
4028
+ return null;
4029
+ }
4030
+ return `import '${THEME_GROUPS_VIRTUAL_ID}';
4031
+ ${transformedCode}`;
4032
+ }
4033
+ function collectPreTransformClasses(output) {
4034
+ if (!output.transformed && !output.code.includes("class=") && !output.code.includes("className=")) {
4035
+ return null;
4036
+ }
4037
+ if (output.szClasses) {
4038
+ for (const className of output.szClasses) {
4039
+ addSafelistClass(className);
4040
+ state.ownedClasses.add(className);
4041
+ }
4042
+ } else {
4043
+ extractClasses(output.code);
4044
+ }
4045
+ return { code: output.code, map: null };
4046
+ }
3429
4047
  const prePlugin = unplugin$1.createUnplugin(
3430
4048
  (_pluginOptions) => ({
3431
4049
  name: "csszyx:pre",
@@ -3512,176 +4130,41 @@ function createCsszyxPlugins(options = {}) {
3512
4130
  }
3513
4131
  if (shouldProcessSource(id)) {
3514
4132
  trackGlobalVarSourceFile(id, code);
4133
+ recordAuthoredClasses(code);
3515
4134
  }
3516
4135
  if (matchesScriptExtension(id, SCRIPT_ID_EXTENSIONS)) {
3517
4136
  assertNoRSCBoundaryViolation(code, id);
3518
4137
  }
3519
4138
  if (matchesScriptExtension(id, [".css"])) {
3520
- state.sawAnyCss = true;
3521
- if (cssImportsTailwind(code)) {
3522
- state.sawTailwindEntry = true;
3523
- if (cssHasContentScope(code)) {
3524
- state.tailwindEntryScoped = true;
3525
- }
3526
- if (hasInjectableTailwindCandidate(state.classes)) {
3527
- const relPath = computeSafelistRelPath(
3528
- state.rootDir,
3529
- SAFELIST_FILENAME,
3530
- id
3531
- );
3532
- const transformed2 = appendTailwindSourceDirective(code, relPath);
3533
- if (transformed2 !== null) {
3534
- return { code: transformed2, map: null };
3535
- }
3536
- }
3537
- }
3538
- return null;
4139
+ return transformTailwindCssEntry(code, id);
3539
4140
  }
3540
- let transformedCode = code;
3541
- let usesRuntime = false;
3542
- let usesMerge = false;
3543
- let usesSzcn = false;
3544
- let usesSzPart = false;
3545
- let usesColorVar = false;
3546
- let usesSpacingVar = false;
3547
- let usesUnitVar = false;
3548
- let transformed = false;
3549
- let szClasses;
3550
4141
  const hasSzProp = code.includes("sz=") || code.includes("szs=") || /\bsz\s*:\s*["'{]/.test(code) || code.includes('sz: "');
3551
- if (hasSzProp) {
3552
- if (id.endsWith(".vue")) {
3553
- const result = vueAdapter.preprocess(code, options);
3554
- if (result.transformed) {
3555
- transformedCode = result.code;
3556
- transformed = true;
3557
- }
3558
- } else if (id.endsWith(".svelte")) {
3559
- const result = svelteAdapter.preprocess(code, options);
3560
- if (result) {
3561
- transformedCode = result.code;
3562
- transformed = true;
3563
- }
3564
- } else {
3565
- const transformStarted = node_perf_hooks.performance.now();
3566
- const result = transformConfiguredSource(code, id);
3567
- traceBenchTiming(
3568
- "transform-hook",
3569
- id,
3570
- node_perf_hooks.performance.now() - transformStarted
3571
- );
3572
- transformedCode = result.code;
3573
- usesRuntime = result.usesRuntime;
3574
- usesMerge = result.usesMerge;
3575
- usesSzcn = result.usesSzcn;
3576
- usesSzPart = result.usesSzPart;
3577
- usesColorVar = result.usesColorVar;
3578
- usesSpacingVar = result.usesSpacingVar;
3579
- usesUnitVar = result.usesUnitVar;
3580
- transformed = result.transformed;
3581
- szClasses = result.classes;
3582
- recordFileVarMangleEntries(state, id, cssVariableEntries(result));
3583
- recordFileCSSVariableMetrics(state, id, result.code);
3584
- for (const msg of result.diagnostics) {
3585
- if (msg.includes("unresolvable sz spread")) {
3586
- state.spreadWarnings.add(`${id}
3587
- ${msg}`);
3588
- } else if (msg.includes("AST budget exceeded")) {
3589
- console.warn(`[csszyx] ${id}
3590
- ${msg}`);
3591
- }
3592
- }
3593
- if (!quiet && result.diagnostics.length > 0 && process.env.NODE_ENV !== "production") {
3594
- for (const msg of result.diagnostics) {
3595
- if (msg.includes("unresolvable sz spread") || msg.includes("AST budget exceeded")) {
3596
- continue;
3597
- }
3598
- this.warn(`[csszyx] ${id}
3599
- ${msg}`);
3600
- }
3601
- }
3602
- for (const [token, data] of result.recoveryTokens) {
3603
- state.recoveryTokens.set(token, data);
3604
- }
3605
- }
3606
- } else if (shouldProcessSource(id)) {
4142
+ const output = hasSzProp ? transformSzSource(code, id, (message) => this.warn(message)) : unchangedPreTransform(code);
4143
+ if (!hasSzProp && shouldProcessSource(id)) {
3607
4144
  recordFileVarMangleEntries(state, id, []);
3608
4145
  recordFileCSSVariableMetrics(state, id, null);
3609
4146
  }
3610
- if (transformedCode.includes("<html") && /(?:layout|Root|Document|app)\.tsx?$/i.test(id)) {
3611
- const attrName = options.production?.minify ? "data-sz-cs" : "data-sz-checksum";
3612
- const htmlTag = findOpeningTag(transformedCode, "html");
3613
- if (htmlTag) {
3614
- transformedCode = `${transformedCode.slice(0, htmlTag.close)} ${attrName}="${CHECKSUM_PLACEHOLDER}"${transformedCode.slice(htmlTag.close)}`;
3615
- }
3616
- 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})}}})()\`}} />`;
3617
- const bodyTag = findOpeningTag(transformedCode, "body");
3618
- if (bodyTag) {
3619
- transformedCode = `${transformedCode.slice(0, bodyTag.close + 1)}${debugScript}${transformedCode.slice(bodyTag.close + 1)}`;
3620
- }
3621
- transformed = true;
4147
+ const layoutCode = injectLayoutHydration(output.code, id);
4148
+ if (layoutCode !== null) {
4149
+ output.code = layoutCode;
4150
+ output.transformed = true;
3622
4151
  }
3623
- {
3624
- const imports = [];
3625
- if (usesRuntime) {
3626
- imports.push("_sz");
3627
- }
3628
- if (usesMerge) {
3629
- imports.push("_szMerge");
3630
- }
3631
- if (usesSzcn) {
3632
- imports.push("_szcn");
3633
- }
3634
- if (usesSzPart) {
3635
- imports.push("_szPart");
3636
- }
3637
- if (usesColorVar) {
3638
- imports.push("__szColorVar");
3639
- }
3640
- if (usesSpacingVar) {
3641
- imports.push("__szSpacingVar");
3642
- }
3643
- if (usesUnitVar) {
3644
- imports.push("__szUnitVar");
3645
- }
3646
- const hasRuntimeImport = imports.length > 0 && transformedCode.includes("@csszyx/runtime");
3647
- const needed = hasRuntimeImport ? imports.filter((name) => !runtimeImportScan.importsRuntimeHelper(transformedCode, name)) : imports;
3648
- if (needed.length > 0) {
3649
- const existingImport = runtimeImportScan.findRuntimeImportClause(transformedCode);
3650
- if (existingImport) {
3651
- transformedCode = transformedCode.replace(
3652
- existingImport.statement,
3653
- `${existingImport.prefixWithBody}, ${needed.join(", ")} } from '@csszyx/runtime'`
3654
- );
3655
- } else {
3656
- const importStmt = `import { ${needed.join(", ")} } from '@csszyx/runtime';
3657
- `;
3658
- transformedCode = insertRuntimeImport(transformedCode, importStmt);
3659
- }
3660
- transformed = true;
3661
- }
4152
+ const runtimeCode = injectRuntimeHelpers(output.code, output);
4153
+ if (runtimeCode !== null) {
4154
+ output.code = runtimeCode;
4155
+ output.transformed = true;
3662
4156
  }
3663
- if ((usesSzcn || /\bszcn\s*\(/.test(code)) && !transformedCode.includes(THEME_GROUPS_VIRTUAL_ID) && shouldProcessSource(id)) {
3664
- transformedCode = `import '${THEME_GROUPS_VIRTUAL_ID}';
3665
- ${transformedCode}`;
3666
- transformed = true;
4157
+ const themedCode = injectThemeGroups(code, output.code, id, output.usesSzcn);
4158
+ if (themedCode !== null) {
4159
+ output.code = themedCode;
4160
+ output.transformed = true;
3667
4161
  }
3668
4162
  if (matchesScriptExtension(id, SCRIPT_ID_EXTENSIONS)) {
3669
- assertNoRSCBoundaryViolation(transformedCode, id);
3670
- const record = createRSCModuleRecord(transformedCode, id);
4163
+ assertNoRSCBoundaryViolation(output.code, id);
4164
+ const record = createRSCModuleRecord(output.code, id);
3671
4165
  state.rscModules.set(record.id, record);
3672
4166
  }
3673
- if (transformed || transformedCode.includes("class=") || transformedCode.includes("className=")) {
3674
- if (szClasses !== void 0) {
3675
- for (const cls of szClasses) {
3676
- addSafelistClass(cls);
3677
- state.ownedClasses.add(cls);
3678
- }
3679
- } else {
3680
- extractClasses(transformedCode);
3681
- }
3682
- return { code: transformedCode, map: null };
3683
- }
3684
- return null;
4167
+ return collectPreTransformClasses(output);
3685
4168
  },
3686
4169
  /** Finalizes the mangle map after all source modules have been processed. */
3687
4170
  buildEnd() {
@@ -3750,6 +4233,7 @@ ${transformedCode}`;
3750
4233
  prescanAndWriteClasses();
3751
4234
  }
3752
4235
  state.parsedTheme = runThemeScan(root, options.build?.scanCss) ?? state.parsedTheme;
4236
+ runAutoThemeScan(root);
3753
4237
  });
3754
4238
  if (options.build?.scanCss) {
3755
4239
  compiler.hooks.thisCompilation.tap("csszyx:theme-deps", (compilation) => {
@@ -3776,6 +4260,7 @@ ${transformedCode}`;
3776
4260
  evictTransformCacheOnce();
3777
4261
  prescanAndWriteClasses();
3778
4262
  state.parsedTheme = runThemeScan(root, options.build?.scanCss) ?? state.parsedTheme;
4263
+ runAutoThemeScan(root);
3779
4264
  },
3780
4265
  /**
3781
4266
  * Vite HMR hook: re-runs theme scan when a watched CSS file changes,
@@ -3785,17 +4270,23 @@ ${transformedCode}`;
3785
4270
  handleHotUpdate(ctx) {
3786
4271
  prescanResultHandoff.clear();
3787
4272
  const scanCss = options.build?.scanCss;
4273
+ const reloadThemeGroupsModule = () => {
4274
+ const themeGroupsModule = ctx.server.moduleGraph.getModuleById(
4275
+ RESOLVED_THEME_GROUPS_VIRTUAL_ID
4276
+ );
4277
+ if (themeGroupsModule) {
4278
+ ctx.server.moduleGraph.invalidateModule(themeGroupsModule);
4279
+ }
4280
+ };
3788
4281
  if (scanCss) {
3789
4282
  const root = ctx.server.config.root || process.cwd();
3790
4283
  if (matchesAnyPattern(ctx.file, scanCss, root)) {
3791
4284
  state.parsedTheme = runThemeScan(root, scanCss) ?? state.parsedTheme;
3792
- const themeGroupsModule = ctx.server.moduleGraph.getModuleById(
3793
- RESOLVED_THEME_GROUPS_VIRTUAL_ID
3794
- );
3795
- if (themeGroupsModule) {
3796
- ctx.server.moduleGraph.invalidateModule(themeGroupsModule);
3797
- }
4285
+ reloadThemeGroupsModule();
3798
4286
  }
4287
+ } else if (ctx.file.endsWith(".css")) {
4288
+ runAutoThemeScan(ctx.server.config.root || process.cwd());
4289
+ reloadThemeGroupsModule();
3799
4290
  }
3800
4291
  if (!shouldProcessSource(ctx.file)) {
3801
4292
  return;
@@ -3890,6 +4381,166 @@ ${transformedCode}`;
3890
4381
  }
3891
4382
  })
3892
4383
  );
4384
+ function createBundleManifest(includeMangleMap) {
4385
+ const manifest = {
4386
+ version: "0.4.0",
4387
+ buildId: state.checksum,
4388
+ classes: Object.keys(state.mangleMap)
4389
+ };
4390
+ if (includeMangleMap && Object.keys(state.mangleMap).length > 0) {
4391
+ manifest.mangleMap = state.mangleMap;
4392
+ }
4393
+ if (Object.keys(state.varMangleMap).length > 0) {
4394
+ manifest.varMangleMap = state.varMangleMap;
4395
+ }
4396
+ const globalVarAliases = extractGlobalVarAliasesForManifest(
4397
+ state.varMangleMap,
4398
+ globalVarAliasPrefix,
4399
+ state.globalVarValidationResult
4400
+ );
4401
+ if (Object.keys(globalVarAliases).length > 0) {
4402
+ manifest.globalVarAliases = globalVarAliases;
4403
+ }
4404
+ if (hasCSSVariableMetrics(state.cssVarMetrics)) {
4405
+ manifest.cssVarMetrics = state.cssVarMetrics;
4406
+ }
4407
+ return manifest;
4408
+ }
4409
+ function isCssSyntaxError(error) {
4410
+ return !!error && typeof error === "object" && "name" in error && error.name === "CssSyntaxError";
4411
+ }
4412
+ function rewriteOutputCss(source, file, shouldMangle, mangledSources, externalClasses) {
4413
+ let css = rewriteCssWithValidatedGlobalVarPlan(
4414
+ source,
4415
+ file,
4416
+ state.globalVarValidationResult
4417
+ );
4418
+ if (!shouldMangle) return css;
4419
+ try {
4420
+ const result = cssMangler.mangleCSSSync(css, state.mangleMap, {
4421
+ debug: options.development?.debug,
4422
+ from: file
4423
+ });
4424
+ for (const className of result.mangledClasses) mangledSources.add(className);
4425
+ for (const className of result.unmangledClasses) externalClasses.add(className);
4426
+ if (result.transformedCount > 0) css = result.css;
4427
+ return css;
4428
+ } catch (error) {
4429
+ if (isCssSyntaxError(error)) return css;
4430
+ throw error;
4431
+ }
4432
+ }
4433
+ function reportOutputMangleHazards(shouldMangle, mangledSources, externalClasses) {
4434
+ if (!shouldMangle) return;
4435
+ const message = mangleHybridHazardMessage(
4436
+ collectMangleHybridHazards(state.mangleMap, mangledSources, externalClasses)
4437
+ );
4438
+ if (message) console.warn(message);
4439
+ }
4440
+ function rewriteWebpackCodeAsset(file, source, shouldMangle, compilation, compiler) {
4441
+ if (shouldMangle && file.endsWith(".html")) {
4442
+ const mangledHtml = mangleHtmlClasses(source);
4443
+ if (mangledHtml !== source) {
4444
+ compilation.updateAsset(file, new compiler.webpack.sources.RawSource(mangledHtml));
4445
+ }
4446
+ return;
4447
+ }
4448
+ if (!file.endsWith(".js")) return;
4449
+ const rewritten = shouldMangle ? replacePlaceholders(mangleCodeClasses(source)) : replacePlaceholders(source);
4450
+ if (rewritten !== source) {
4451
+ compilation.updateAsset(file, new compiler.webpack.sources.RawSource(rewritten));
4452
+ }
4453
+ }
4454
+ function processWebpackAssets(assets, compilation, compiler) {
4455
+ finalizeMangleMap();
4456
+ state.globalVarValidationResult = validateGlobalVarBundleInputs(
4457
+ collectWebpackGlobalVarCssAssets(assets)
4458
+ );
4459
+ const shouldMangle = manglingEnabled && compiler.options.mode !== "development" && Object.keys(state.mangleMap).length > 0;
4460
+ const manifest = createBundleManifest(shouldMangle);
4461
+ compilation.emitAsset(
4462
+ "csszyx-manifest.json",
4463
+ new compiler.webpack.sources.RawSource(JSON.stringify(manifest))
4464
+ );
4465
+ if (shouldEmitGlobalVarMapAsset(globalVarMangleConfig)) {
4466
+ const globalVarMap = createGlobalVarMapAssetSource(
4467
+ state.varMangleMap,
4468
+ globalVarAliasPrefix,
4469
+ state.globalVarValidationResult
4470
+ );
4471
+ if (globalVarMap) {
4472
+ compilation.emitAsset(
4473
+ ".csszyx/global-var-map.json",
4474
+ new compiler.webpack.sources.RawSource(globalVarMap)
4475
+ );
4476
+ }
4477
+ }
4478
+ const mangledSources = /* @__PURE__ */ new Set();
4479
+ const externalClasses = /* @__PURE__ */ new Set();
4480
+ for (const file in assets) {
4481
+ const source = assets[file].source().toString();
4482
+ if (file.endsWith(".css")) {
4483
+ const css = rewriteOutputCss(
4484
+ source,
4485
+ file,
4486
+ shouldMangle,
4487
+ mangledSources,
4488
+ externalClasses
4489
+ );
4490
+ if (css !== source) {
4491
+ compilation.updateAsset(file, new compiler.webpack.sources.RawSource(css));
4492
+ }
4493
+ } else {
4494
+ rewriteWebpackCodeAsset(file, source, shouldMangle, compilation, compiler);
4495
+ }
4496
+ }
4497
+ reportOutputMangleHazards(shouldMangle, mangledSources, externalClasses);
4498
+ }
4499
+ function rewriteViteBundleEntry(chunk, file, shouldMangle, mangledSources, externalClasses) {
4500
+ if (chunk.type === "asset" && chunk.fileName.endsWith(".css") && chunk.source !== void 0) {
4501
+ const originalCss = chunk.source.toString();
4502
+ const css = rewriteOutputCss(
4503
+ originalCss,
4504
+ file,
4505
+ shouldMangle,
4506
+ mangledSources,
4507
+ externalClasses
4508
+ );
4509
+ if (css !== originalCss) chunk.source = css;
4510
+ return;
4511
+ }
4512
+ if (chunk.type !== "chunk" || chunk.code === void 0) return;
4513
+ const rewritten = shouldMangle ? replacePlaceholders(mangleCodeClasses(chunk.code)) : replacePlaceholders(chunk.code);
4514
+ if (rewritten !== chunk.code) chunk.code = rewritten;
4515
+ }
4516
+ function processRollupBundle(bundle, emitAsset) {
4517
+ finalizeMangleMap();
4518
+ state.globalVarValidationResult = validateGlobalVarBundleInputs(
4519
+ collectRollupGlobalVarCssAssets(bundle)
4520
+ );
4521
+ const shouldMangle = manglingEnabled && Object.keys(state.mangleMap).length > 0;
4522
+ emitAsset("csszyx-manifest.json", JSON.stringify(createBundleManifest(shouldMangle)));
4523
+ if (shouldEmitGlobalVarMapAsset(globalVarMangleConfig)) {
4524
+ const globalVarMap = createGlobalVarMapAssetSource(
4525
+ state.varMangleMap,
4526
+ globalVarAliasPrefix,
4527
+ state.globalVarValidationResult
4528
+ );
4529
+ if (globalVarMap) emitAsset(".csszyx/global-var-map.json", globalVarMap);
4530
+ }
4531
+ const mangledSources = /* @__PURE__ */ new Set();
4532
+ const externalClasses = /* @__PURE__ */ new Set();
4533
+ for (const file in bundle) {
4534
+ rewriteViteBundleEntry(
4535
+ bundle[file],
4536
+ file,
4537
+ shouldMangle,
4538
+ mangledSources,
4539
+ externalClasses
4540
+ );
4541
+ }
4542
+ reportOutputMangleHazards(shouldMangle, mangledSources, externalClasses);
4543
+ }
3893
4544
  const postPlugin = unplugin$1.createUnplugin(() => ({
3894
4545
  name: "csszyx:post",
3895
4546
  enforce: "post",
@@ -3900,266 +4551,20 @@ ${transformedCode}`;
3900
4551
  * @param compiler - the Webpack compiler instance
3901
4552
  */
3902
4553
  webpack(compiler) {
3903
- compiler.hooks.compilation.tap("csszyx:post", (compilation) => {
3904
- const stage = compiler.webpack?.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE || compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE;
3905
- compilation.hooks.processAssets.tap(
3906
- {
3907
- name: "csszyx:post",
3908
- stage: stage || 400
3909
- // Fallback integer
3910
- },
3911
- (assets) => {
3912
- finalizeMangleMap();
3913
- state.globalVarValidationResult = validateGlobalVarBundleInputs(
3914
- collectWebpackGlobalVarCssAssets(assets)
3915
- );
3916
- const isWebpackDevMode = compiler.options.mode === "development";
3917
- const manifestData = {
3918
- version: "0.4.0",
3919
- buildId: state.checksum,
3920
- classes: Object.keys(state.mangleMap)
3921
- };
3922
- if (manglingEnabled && !isWebpackDevMode && Object.keys(state.mangleMap).length > 0) {
3923
- manifestData.mangleMap = state.mangleMap;
3924
- }
3925
- if (Object.keys(state.varMangleMap).length > 0) {
3926
- manifestData.varMangleMap = state.varMangleMap;
3927
- }
3928
- const globalVarAliases = extractGlobalVarAliasesForManifest(
3929
- state.varMangleMap,
3930
- globalVarAliasPrefix,
3931
- state.globalVarValidationResult
3932
- );
3933
- if (Object.keys(globalVarAliases).length > 0) {
3934
- manifestData.globalVarAliases = globalVarAliases;
3935
- }
3936
- if (hasCSSVariableMetrics(state.cssVarMetrics)) {
3937
- manifestData.cssVarMetrics = state.cssVarMetrics;
3938
- }
3939
- compilation.emitAsset(
3940
- "csszyx-manifest.json",
3941
- new compiler.webpack.sources.RawSource(JSON.stringify(manifestData))
3942
- );
3943
- if (shouldEmitGlobalVarMapAsset(globalVarMangleConfig)) {
3944
- const globalVarMapAsset = createGlobalVarMapAssetSource(
3945
- state.varMangleMap,
3946
- globalVarAliasPrefix,
3947
- state.globalVarValidationResult
3948
- );
3949
- if (globalVarMapAsset) {
3950
- compilation.emitAsset(
3951
- ".csszyx/global-var-map.json",
3952
- new compiler.webpack.sources.RawSource(globalVarMapAsset)
3953
- );
3954
- }
3955
- }
3956
- const mangledSources = /* @__PURE__ */ new Set();
3957
- const externalClasses = /* @__PURE__ */ new Set();
3958
- for (const file in assets) {
3959
- const asset = assets[file];
3960
- const source = asset.source().toString();
3961
- if (file.endsWith(".css")) {
3962
- let css = rewriteCssWithValidatedGlobalVarPlan(
3963
- source,
3964
- file,
3965
- state.globalVarValidationResult
3966
- );
3967
- if (manglingEnabled && !isWebpackDevMode && Object.keys(state.mangleMap).length > 0) {
3968
- try {
3969
- const result = cssMangler.mangleCSSSync(css, state.mangleMap, {
3970
- debug: options.development?.debug,
3971
- from: file
3972
- });
3973
- for (const c of result.mangledClasses) {
3974
- mangledSources.add(c);
3975
- }
3976
- for (const c of result.unmangledClasses) {
3977
- externalClasses.add(c);
3978
- }
3979
- if (result.transformedCount > 0) {
3980
- css = result.css;
3981
- }
3982
- } catch (e) {
3983
- if (e && typeof e === "object" && "name" in e && e.name === "CssSyntaxError") ; else {
3984
- throw e;
3985
- }
3986
- }
3987
- }
3988
- if (css !== source) {
3989
- compilation.updateAsset(
3990
- file,
3991
- new compiler.webpack.sources.RawSource(css)
3992
- );
3993
- }
3994
- continue;
3995
- }
3996
- if (manglingEnabled && !isWebpackDevMode && Object.keys(state.mangleMap).length > 0) {
3997
- if (file.endsWith(".html")) {
3998
- const mangledHtml = mangleHtmlClasses(source);
3999
- if (mangledHtml !== source) {
4000
- compilation.updateAsset(
4001
- file,
4002
- new compiler.webpack.sources.RawSource(mangledHtml)
4003
- );
4004
- continue;
4005
- }
4006
- } else if (file.endsWith(".js")) {
4007
- let mangled = mangleCodeClasses(source);
4008
- mangled = replacePlaceholders(mangled);
4009
- if (mangled !== source) {
4010
- compilation.updateAsset(
4011
- file,
4012
- new compiler.webpack.sources.RawSource(mangled)
4013
- );
4014
- continue;
4015
- }
4016
- }
4017
- }
4018
- if (file.endsWith(".js") && (source.includes(CHECKSUM_PLACEHOLDER) || source.includes(MANGLE_MAP_PLACEHOLDER))) {
4019
- const replaced = replacePlaceholders(source);
4020
- if (replaced !== source) {
4021
- compilation.updateAsset(
4022
- file,
4023
- new compiler.webpack.sources.RawSource(replaced)
4024
- );
4025
- }
4026
- }
4027
- }
4028
- if (manglingEnabled && !isWebpackDevMode && Object.keys(state.mangleMap).length > 0) {
4029
- const hazardMessage = mangleHybridHazardMessage(
4030
- collectMangleHybridHazards(
4031
- state.mangleMap,
4032
- mangledSources,
4033
- externalClasses
4034
- )
4035
- );
4036
- if (hazardMessage) {
4037
- console.warn(hazardMessage);
4038
- }
4039
- }
4040
- }
4041
- );
4042
- });
4554
+ registerWebpackAssetProcessor(compiler, processWebpackAssets);
4043
4555
  },
4044
- vite: {
4045
- /**
4046
- * Vite hook: mangles CSS selectors and JS class strings in the final bundle.
4047
- * @param _options - the output options (unused)
4048
- * @param bundle - the output bundle containing chunks and assets to process
4049
- */
4050
- generateBundle(_options, bundle) {
4051
- finalizeMangleMap();
4052
- state.globalVarValidationResult = validateGlobalVarBundleInputs(
4053
- collectRollupGlobalVarCssAssets(bundle)
4054
- );
4055
- const manifestData = {
4056
- version: "0.4.0",
4057
- buildId: state.checksum,
4058
- classes: Object.keys(state.mangleMap)
4059
- };
4060
- if (manglingEnabled && Object.keys(state.mangleMap).length > 0) {
4061
- manifestData.mangleMap = state.mangleMap;
4062
- }
4063
- if (Object.keys(state.varMangleMap).length > 0) {
4064
- manifestData.varMangleMap = state.varMangleMap;
4065
- }
4066
- const globalVarAliases = extractGlobalVarAliasesForManifest(
4067
- state.varMangleMap,
4068
- globalVarAliasPrefix,
4069
- state.globalVarValidationResult
4070
- );
4071
- if (Object.keys(globalVarAliases).length > 0) {
4072
- manifestData.globalVarAliases = globalVarAliases;
4073
- }
4074
- if (hasCSSVariableMetrics(state.cssVarMetrics)) {
4075
- manifestData.cssVarMetrics = state.cssVarMetrics;
4076
- }
4077
- this.emitFile({
4078
- type: "asset",
4079
- fileName: "csszyx-manifest.json",
4080
- source: JSON.stringify(manifestData)
4081
- });
4082
- if (shouldEmitGlobalVarMapAsset(globalVarMangleConfig)) {
4083
- const globalVarMapAsset = createGlobalVarMapAssetSource(
4084
- state.varMangleMap,
4085
- globalVarAliasPrefix,
4086
- state.globalVarValidationResult
4087
- );
4088
- if (globalVarMapAsset) {
4089
- this.emitFile({
4090
- type: "asset",
4091
- fileName: ".csszyx/global-var-map.json",
4092
- source: globalVarMapAsset
4093
- });
4094
- }
4095
- }
4096
- const mangledSources = /* @__PURE__ */ new Set();
4097
- const externalClasses = /* @__PURE__ */ new Set();
4098
- for (const file in bundle) {
4099
- const chunk = bundle[file];
4100
- if (chunk.type === "asset" && chunk.fileName.endsWith(".css")) {
4101
- const originalCss = chunk.source.toString();
4102
- let css = rewriteCssWithValidatedGlobalVarPlan(
4103
- originalCss,
4104
- file,
4105
- state.globalVarValidationResult
4106
- );
4107
- if (manglingEnabled && Object.keys(state.mangleMap).length > 0) {
4108
- try {
4109
- const result = cssMangler.mangleCSSSync(css, state.mangleMap, {
4110
- debug: options.development?.debug,
4111
- from: file
4112
- });
4113
- for (const c of result.mangledClasses) {
4114
- mangledSources.add(c);
4115
- }
4116
- for (const c of result.unmangledClasses) {
4117
- externalClasses.add(c);
4118
- }
4119
- if (result.transformedCount > 0) {
4120
- css = result.css;
4121
- }
4122
- } catch (e) {
4123
- if (e && typeof e === "object" && "name" in e && e.name === "CssSyntaxError") ; else {
4124
- throw e;
4125
- }
4126
- }
4127
- }
4128
- if (css !== originalCss) {
4129
- chunk.source = css;
4130
- }
4131
- continue;
4132
- }
4133
- if (manglingEnabled && Object.keys(state.mangleMap).length > 0) {
4134
- if (chunk.type === "chunk") {
4135
- let mangledCode = mangleCodeClasses(chunk.code);
4136
- mangledCode = replacePlaceholders(mangledCode);
4137
- if (mangledCode !== chunk.code) {
4138
- chunk.code = mangledCode;
4139
- }
4140
- continue;
4141
- }
4142
- }
4143
- if (chunk.type === "chunk" && (chunk.code.includes(CHECKSUM_PLACEHOLDER) || chunk.code.includes(MANGLE_MAP_PLACEHOLDER))) {
4144
- const replaced = replacePlaceholders(chunk.code);
4145
- if (replaced !== chunk.code) {
4146
- chunk.code = replaced;
4147
- }
4148
- }
4149
- }
4150
- if (manglingEnabled && Object.keys(state.mangleMap).length > 0) {
4151
- const hazardMessage = mangleHybridHazardMessage(
4152
- collectMangleHybridHazards(
4153
- state.mangleMap,
4154
- mangledSources,
4155
- externalClasses
4156
- )
4157
- );
4158
- if (hazardMessage) {
4159
- console.warn(hazardMessage);
4160
- }
4161
- }
4162
- }
4556
+ /**
4557
+ * Rollup-compatible hook used by both pure Rollup and Vite adapters.
4558
+ *
4559
+ * @param this Rollup-compatible output hook context.
4560
+ * @param this.emitFile Output asset emitter.
4561
+ * @param _options Output options (unused).
4562
+ * @param bundle Complete Rollup output bundle.
4563
+ */
4564
+ generateBundle(_options, bundle) {
4565
+ processRollupBundle(bundle, (fileName, source) => {
4566
+ this.emitFile({ type: "asset", fileName, source });
4567
+ });
4163
4568
  }
4164
4569
  }));
4165
4570
  return { prePlugin, postPlugin };
@@ -4191,7 +4596,16 @@ const rollupPlugin = (options = {}) => {
4191
4596
  ];
4192
4597
  };
4193
4598
  const esbuildPlugin = (options = {}) => {
4194
- const { prePlugin, postPlugin } = createCsszyxPlugins(options);
4599
+ if (options.production?.mangle === true) {
4600
+ console.warn(
4601
+ "[csszyx] production.mangle is not supported by the esbuild adapter; class mangling is disabled so emitted JS and CSS keep matching names."
4602
+ );
4603
+ }
4604
+ const safeOptions = {
4605
+ ...options,
4606
+ production: { ...options.production, mangle: false }
4607
+ };
4608
+ const { prePlugin, postPlugin } = createCsszyxPlugins(safeOptions);
4195
4609
  return {
4196
4610
  name: "csszyx",
4197
4611
  /**
@@ -4200,8 +4614,8 @@ const esbuildPlugin = (options = {}) => {
4200
4614
  */
4201
4615
  setup(build) {
4202
4616
  const b = build;
4203
- prePlugin.esbuild(options).setup(b);
4204
- postPlugin.esbuild(options).setup(b);
4617
+ prePlugin.esbuild(safeOptions).setup(b);
4618
+ postPlugin.esbuild(safeOptions).setup(b);
4205
4619
  }
4206
4620
  };
4207
4621
  };
@@ -4235,6 +4649,7 @@ exports.isPackagesSkippedSource = isPackagesSkippedSource;
4235
4649
  exports.isRSCServerModule = isRSCServerModule;
4236
4650
  exports.isTailwindReservedGlobalVar = isTailwindReservedGlobalVar;
4237
4651
  exports.mangleCodeClassesSync = mangleCodeClassesSync;
4652
+ exports.mangleEligibleClasses = mangleEligibleClasses;
4238
4653
  exports.mangleHybridHazardMessage = mangleHybridHazardMessage;
4239
4654
  exports.mergeThemes = mergeThemes;
4240
4655
  exports.missingTailwindEntryMessage = missingTailwindEntryMessage;