@weapp-tailwindcss/postcss 3.0.2 → 3.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +9 -0
- package/README.md +5 -95
- package/dist/compat/color-mix/constants.d.ts +9 -0
- package/dist/compat/color-mix/modern.d.ts +2 -0
- package/dist/compat/color-mix/parse.d.ts +9 -0
- package/dist/compat/color-mix/resolve.d.ts +5 -0
- package/dist/compat/mini-program-css/directives.d.ts +5 -0
- package/dist/compat/mini-program-css/finalize-options.d.ts +6 -0
- package/dist/compat/mini-program-css/finalize.d.ts +4 -11
- package/dist/compat/mini-program-css/hoist.d.ts +4 -0
- package/dist/compat/mini-program-css/preflight.d.ts +7 -0
- package/dist/compat/mini-program-css/root-cleanups.d.ts +6 -0
- package/dist/compat/mini-program-css/theme.d.ts +3 -0
- package/dist/index.js +448 -243
- package/dist/index.mjs +447 -243
- package/dist/selectorParser/rule-transformer/nodes.d.ts +7 -0
- package/dist/selectorParser/rule-transformer/pseudos.d.ts +6 -0
- package/dist/selectorParser/rule-transformer/types.d.ts +14 -0
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -36,6 +36,37 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
36
36
|
enumerable: true
|
|
37
37
|
}) : target, mod));
|
|
38
38
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
39
|
+
const MODERN_COLOR_FUNCTION_NAMES = new Set([
|
|
40
|
+
"oklch",
|
|
41
|
+
"oklab",
|
|
42
|
+
"lch",
|
|
43
|
+
"lab"
|
|
44
|
+
]);
|
|
45
|
+
const PLACEHOLDER_PREFIX = "__weapp_tw_color_mix_";
|
|
46
|
+
const DYNAMIC_ALPHA_RE = /\b(?:var|env)\(|--[\w-]+\b/;
|
|
47
|
+
const INTERNAL_TAILWIND_ALPHA_RE = /var\(\s*--tw-[^)]+-alpha\s*\)/;
|
|
48
|
+
const TRANSPARENT_COLOR_RE = /^transparent$/i;
|
|
49
|
+
const CURRENT_COLOR_RE = /^currentcolor$/i;
|
|
50
|
+
const CSS_WIDE_KEYWORD_RE = /^(?:inherit|initial|unset|revert|revert-layer)$/i;
|
|
51
|
+
const CUSTOM_PROPERTY_RE = /^--[\w-]+$/;
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/compat/color-mix/modern.ts
|
|
54
|
+
function isDisplayP3ColorFunction(colorSource) {
|
|
55
|
+
return /^color\(\s*display-p3\b/i.test(colorSource.trim());
|
|
56
|
+
}
|
|
57
|
+
function hasUnsupportedModernColorFunction(value) {
|
|
58
|
+
const parsed = valueParser(value);
|
|
59
|
+
let hasUnsupported = false;
|
|
60
|
+
parsed.walk((node) => {
|
|
61
|
+
if (node.type !== "function") return;
|
|
62
|
+
const name = node.value.toLowerCase();
|
|
63
|
+
if (name === "color-mix" || MODERN_COLOR_FUNCTION_NAMES.has(name) || name === "color" && isDisplayP3ColorFunction(valueParser.stringify(node))) {
|
|
64
|
+
hasUnsupported = true;
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return hasUnsupported;
|
|
69
|
+
}
|
|
39
70
|
//#endregion
|
|
40
71
|
//#region ../../node_modules/.pnpm/@csstools+css-tokenizer@4.0.0/node_modules/@csstools/css-tokenizer/dist/index.mjs
|
|
41
72
|
var ParseError$1 = class extends Error {
|
|
@@ -6536,21 +6567,7 @@ function color(e) {
|
|
|
6536
6567
|
return !1;
|
|
6537
6568
|
}
|
|
6538
6569
|
//#endregion
|
|
6539
|
-
//#region src/compat/color-mix.ts
|
|
6540
|
-
const COLOR_MIX_NAME = "color-mix";
|
|
6541
|
-
const MODERN_COLOR_FUNCTION_NAMES = new Set([
|
|
6542
|
-
"oklch",
|
|
6543
|
-
"oklab",
|
|
6544
|
-
"lch",
|
|
6545
|
-
"lab"
|
|
6546
|
-
]);
|
|
6547
|
-
const PLACEHOLDER_PREFIX = "__weapp_tw_color_mix_";
|
|
6548
|
-
const DYNAMIC_ALPHA_RE = /\b(?:var|env)\(|--[\w-]+\b/;
|
|
6549
|
-
const INTERNAL_TAILWIND_ALPHA_RE = /var\(\s*--tw-[^)]+-alpha\s*\)/;
|
|
6550
|
-
const TRANSPARENT_COLOR_RE = /^transparent$/i;
|
|
6551
|
-
const CURRENT_COLOR_RE = /^currentcolor$/i;
|
|
6552
|
-
const CSS_WIDE_KEYWORD_RE = /^(?:inherit|initial|unset|revert|revert-layer)$/i;
|
|
6553
|
-
const CUSTOM_PROPERTY_RE = /^--[\w-]+$/;
|
|
6570
|
+
//#region src/compat/color-mix/parse.ts
|
|
6554
6571
|
function splitArguments(nodes) {
|
|
6555
6572
|
const args = [];
|
|
6556
6573
|
let current = [];
|
|
@@ -6633,51 +6650,8 @@ function normalizeStandaloneColorFunction(colorSource) {
|
|
|
6633
6650
|
const resolvedColor = getParsedColorData(colorSource);
|
|
6634
6651
|
return resolvedColor ? serializeRGB(resolvedColor).toString() : void 0;
|
|
6635
6652
|
}
|
|
6636
|
-
|
|
6637
|
-
|
|
6638
|
-
}
|
|
6639
|
-
function hasUnsupportedModernColorFunction(value) {
|
|
6640
|
-
const parsed = valueParser(value);
|
|
6641
|
-
let hasUnsupported = false;
|
|
6642
|
-
parsed.walk((node) => {
|
|
6643
|
-
if (node.type !== "function") return;
|
|
6644
|
-
const name = node.value.toLowerCase();
|
|
6645
|
-
if (name === COLOR_MIX_NAME || MODERN_COLOR_FUNCTION_NAMES.has(name) || name === "color" && isDisplayP3ColorFunction(valueParser.stringify(node))) {
|
|
6646
|
-
hasUnsupported = true;
|
|
6647
|
-
return false;
|
|
6648
|
-
}
|
|
6649
|
-
});
|
|
6650
|
-
return hasUnsupported;
|
|
6651
|
-
}
|
|
6652
|
-
function normalizeModernColorValue(value, customPropertyValues = /* @__PURE__ */ new Map()) {
|
|
6653
|
-
if (!hasUnsupportedModernColorFunction(value)) return {
|
|
6654
|
-
value,
|
|
6655
|
-
changed: false,
|
|
6656
|
-
hasUnsupported: false
|
|
6657
|
-
};
|
|
6658
|
-
const parsed = valueParser(value);
|
|
6659
|
-
let changed = false;
|
|
6660
|
-
parsed.walk((node) => {
|
|
6661
|
-
if (node.type !== "function") return;
|
|
6662
|
-
const name = node.value.toLowerCase();
|
|
6663
|
-
const source = valueParser.stringify(node);
|
|
6664
|
-
let normalized;
|
|
6665
|
-
if (MODERN_COLOR_FUNCTION_NAMES.has(name) || name === "color" && isDisplayP3ColorFunction(source)) normalized = normalizeStandaloneColorFunction(source);
|
|
6666
|
-
else if (name === COLOR_MIX_NAME) normalized = tryResolveColorMix(node, customPropertyValues)?.value;
|
|
6667
|
-
if (!normalized) return;
|
|
6668
|
-
const mutableNode = node;
|
|
6669
|
-
mutableNode.type = "word";
|
|
6670
|
-
mutableNode.value = normalized;
|
|
6671
|
-
delete mutableNode.nodes;
|
|
6672
|
-
changed = true;
|
|
6673
|
-
});
|
|
6674
|
-
const nextValue = changed ? parsed.toString() : value;
|
|
6675
|
-
return {
|
|
6676
|
-
value: nextValue,
|
|
6677
|
-
changed,
|
|
6678
|
-
hasUnsupported: hasUnsupportedModernColorFunction(nextValue)
|
|
6679
|
-
};
|
|
6680
|
-
}
|
|
6653
|
+
//#endregion
|
|
6654
|
+
//#region src/compat/color-mix/resolve.ts
|
|
6681
6655
|
function createRgbaWithAlpha(colorSource, alphaSource, customPropertyValues) {
|
|
6682
6656
|
const resolvedColor = resolveColorData(colorSource, customPropertyValues);
|
|
6683
6657
|
if (!resolvedColor) return;
|
|
@@ -6723,17 +6697,48 @@ function tryResolveColorMix(node, customPropertyValues) {
|
|
|
6723
6697
|
deferred: false
|
|
6724
6698
|
};
|
|
6725
6699
|
}
|
|
6700
|
+
//#endregion
|
|
6701
|
+
//#region src/compat/color-mix.ts
|
|
6702
|
+
function normalizeModernColorValue(value, customPropertyValues = /* @__PURE__ */ new Map()) {
|
|
6703
|
+
if (!hasUnsupportedModernColorFunction(value)) return {
|
|
6704
|
+
value,
|
|
6705
|
+
changed: false,
|
|
6706
|
+
hasUnsupported: false
|
|
6707
|
+
};
|
|
6708
|
+
const parsed = valueParser(value);
|
|
6709
|
+
let changed = false;
|
|
6710
|
+
parsed.walk((node) => {
|
|
6711
|
+
if (node.type !== "function") return;
|
|
6712
|
+
const name = node.value.toLowerCase();
|
|
6713
|
+
const source = valueParser.stringify(node);
|
|
6714
|
+
let normalized;
|
|
6715
|
+
if (MODERN_COLOR_FUNCTION_NAMES.has(name) || name === "color" && isDisplayP3ColorFunction(source)) normalized = normalizeStandaloneColorFunction(source);
|
|
6716
|
+
else if (name === "color-mix") normalized = tryResolveColorMix(node, customPropertyValues)?.value;
|
|
6717
|
+
if (!normalized) return;
|
|
6718
|
+
const mutableNode = node;
|
|
6719
|
+
mutableNode.type = "word";
|
|
6720
|
+
mutableNode.value = normalized;
|
|
6721
|
+
delete mutableNode.nodes;
|
|
6722
|
+
changed = true;
|
|
6723
|
+
});
|
|
6724
|
+
const nextValue = changed ? parsed.toString() : value;
|
|
6725
|
+
return {
|
|
6726
|
+
value: nextValue,
|
|
6727
|
+
changed,
|
|
6728
|
+
hasUnsupported: hasUnsupportedModernColorFunction(nextValue)
|
|
6729
|
+
};
|
|
6730
|
+
}
|
|
6726
6731
|
function createPlaceholder(index) {
|
|
6727
6732
|
return `${PLACEHOLDER_PREFIX}${index}__`;
|
|
6728
6733
|
}
|
|
6729
6734
|
function unwrapProtectedSupports(cssRoot) {
|
|
6730
6735
|
cssRoot.walkAtRules("supports", (atRule) => {
|
|
6731
|
-
if (!atRule.nodes || !atRule.toString().includes(
|
|
6736
|
+
if (!atRule.nodes || !atRule.toString().includes("__weapp_tw_color_mix_")) return;
|
|
6732
6737
|
atRule.replaceWith(atRule.nodes);
|
|
6733
6738
|
});
|
|
6734
6739
|
}
|
|
6735
6740
|
function protectDynamicColorMixAlpha(css, options = {}) {
|
|
6736
|
-
if (!css.includes(
|
|
6741
|
+
if (!css.includes("color-mix")) return {
|
|
6737
6742
|
css,
|
|
6738
6743
|
restore: (value) => value
|
|
6739
6744
|
};
|
|
@@ -6742,14 +6747,14 @@ function protectDynamicColorMixAlpha(css, options = {}) {
|
|
|
6742
6747
|
const customPropertyValues = new Map(options.customPropertyValues);
|
|
6743
6748
|
let changed = false;
|
|
6744
6749
|
root.walkDecls((decl) => {
|
|
6745
|
-
if (decl.prop.startsWith("--") && !decl.value.includes(
|
|
6750
|
+
if (decl.prop.startsWith("--") && !decl.value.includes("color-mix")) customPropertyValues.set(decl.prop, decl.value.trim());
|
|
6746
6751
|
});
|
|
6747
6752
|
root.walkDecls((decl) => {
|
|
6748
|
-
if (!decl.value.includes(
|
|
6753
|
+
if (!decl.value.includes("color-mix")) return;
|
|
6749
6754
|
const parsed = valueParser(decl.value);
|
|
6750
6755
|
let mutated = false;
|
|
6751
6756
|
parsed.walk((node) => {
|
|
6752
|
-
if (node.type !== "function" || node.value.toLowerCase() !==
|
|
6757
|
+
if (node.type !== "function" || node.value.toLowerCase() !== "color-mix") return;
|
|
6753
6758
|
const resolved = tryResolveColorMix(node, customPropertyValues);
|
|
6754
6759
|
if (resolved) {
|
|
6755
6760
|
if (resolved.deferred) {
|
|
@@ -7205,7 +7210,27 @@ function isTailwindcssV4DisplayP3Media(atRule) {
|
|
|
7205
7210
|
function isTailwindcssV4DisplayP3Declaration(decl) {
|
|
7206
7211
|
return DISPLAY_P3_VALUE_RE$1.test(decl.value);
|
|
7207
7212
|
}
|
|
7213
|
+
function normalizeTailwindcssV4EmptyVarFallback(value) {
|
|
7214
|
+
if (!value.includes("var(") || !value.includes("--tw-")) return value;
|
|
7215
|
+
const parsed = valueParser(value);
|
|
7216
|
+
let changed = false;
|
|
7217
|
+
parsed.walk((node) => {
|
|
7218
|
+
if (node.type !== "function" || node.value.toLowerCase() !== "var") return;
|
|
7219
|
+
const firstArg = node.nodes.find((child) => child.type !== "space");
|
|
7220
|
+
const lastArg = node.nodes.findLast((child) => child.type !== "space");
|
|
7221
|
+
if (firstArg?.type !== "word" || !firstArg.value.startsWith("--tw-") || lastArg?.type !== "div" || lastArg.value !== "," || node.after === " ") return;
|
|
7222
|
+
node.after = " ";
|
|
7223
|
+
changed = true;
|
|
7224
|
+
});
|
|
7225
|
+
return changed ? parsed.toString() : value;
|
|
7226
|
+
}
|
|
7208
7227
|
function normalizeTailwindcssV4Declaration(decl) {
|
|
7228
|
+
let changed = false;
|
|
7229
|
+
const normalizedEmptyVarFallback = normalizeTailwindcssV4EmptyVarFallback(decl.value);
|
|
7230
|
+
if (normalizedEmptyVarFallback !== decl.value) {
|
|
7231
|
+
decl.value = normalizedEmptyVarFallback;
|
|
7232
|
+
changed = true;
|
|
7233
|
+
}
|
|
7209
7234
|
if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OKLAB_SUFFIX)) {
|
|
7210
7235
|
decl.value = decl.value.slice(0, decl.value.length - 8).trimEnd();
|
|
7211
7236
|
return true;
|
|
@@ -7227,17 +7252,38 @@ function normalizeTailwindcssV4Declaration(decl) {
|
|
|
7227
7252
|
return true;
|
|
7228
7253
|
}
|
|
7229
7254
|
}
|
|
7230
|
-
return
|
|
7255
|
+
return changed;
|
|
7231
7256
|
}
|
|
7232
7257
|
//#endregion
|
|
7233
|
-
//#region src/compat/mini-program-css/
|
|
7234
|
-
const
|
|
7235
|
-
const
|
|
7236
|
-
function
|
|
7237
|
-
|
|
7258
|
+
//#region src/compat/mini-program-css/directives.ts
|
|
7259
|
+
const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
|
|
7260
|
+
const GENERATOR_PLACEHOLDER_COMMENT_RE = /^\s*(?:!\s*)?weapp-tailwindcss generator-placeholder\s*$/i;
|
|
7261
|
+
function hasTailwindcssV4Signal(css) {
|
|
7262
|
+
if (TAILWIND_V4_BANNER_RE.test(css)) return true;
|
|
7263
|
+
const root = postcss.parse(css);
|
|
7264
|
+
let hasProperty = false;
|
|
7265
|
+
root.walkAtRules("property", (atRule) => {
|
|
7266
|
+
if (atRule.params.trim().startsWith("--tw-")) {
|
|
7267
|
+
hasProperty = true;
|
|
7268
|
+
return false;
|
|
7269
|
+
}
|
|
7270
|
+
});
|
|
7271
|
+
return hasProperty;
|
|
7238
7272
|
}
|
|
7239
|
-
function
|
|
7240
|
-
|
|
7273
|
+
function unwrapTailwindSourceMedia(root) {
|
|
7274
|
+
root.walkAtRules("media", (atRule) => {
|
|
7275
|
+
if (!atRule.params.startsWith("source(")) return;
|
|
7276
|
+
if (atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
|
|
7277
|
+
else atRule.remove();
|
|
7278
|
+
});
|
|
7279
|
+
}
|
|
7280
|
+
function removeTailwindGenerationDirectives(root) {
|
|
7281
|
+
root.walkComments((comment) => {
|
|
7282
|
+
if (GENERATOR_PLACEHOLDER_COMMENT_RE.test(comment.text)) comment.remove();
|
|
7283
|
+
});
|
|
7284
|
+
root.walkAtRules((atRule) => {
|
|
7285
|
+
if (atRule.name === "config" || atRule.name === "source" || atRule.name === "tailwind" || atRule.name === "reference" || atRule.name === "plugin") atRule.remove();
|
|
7286
|
+
});
|
|
7241
7287
|
}
|
|
7242
7288
|
//#endregion
|
|
7243
7289
|
//#region src/compat/mini-program-css/selectors.ts
|
|
@@ -7384,7 +7430,7 @@ function isCustomPropertyRule(rule) {
|
|
|
7384
7430
|
function isEmptyTwContentDeclaration(decl) {
|
|
7385
7431
|
return decl.prop === "--tw-content" && (decl.value === "\"\"" || decl.value === "''");
|
|
7386
7432
|
}
|
|
7387
|
-
function isOnlyTwContentDeclarations(rule) {
|
|
7433
|
+
function isOnlyTwContentDeclarations$1(rule) {
|
|
7388
7434
|
let hasDeclaration = false;
|
|
7389
7435
|
let onlyContentVariable = true;
|
|
7390
7436
|
rule.walkDecls((decl) => {
|
|
@@ -7395,7 +7441,7 @@ function isOnlyTwContentDeclarations(rule) {
|
|
|
7395
7441
|
}
|
|
7396
7442
|
function isPseudoContentInitRule(rule) {
|
|
7397
7443
|
const selector = rule.selector.replace(/\s+/g, "");
|
|
7398
|
-
return PSEUDO_CONTENT_SELECTOR_RE.test(selector) && isOnlyTwContentDeclarations(rule);
|
|
7444
|
+
return PSEUDO_CONTENT_SELECTOR_RE.test(selector) && isOnlyTwContentDeclarations$1(rule);
|
|
7399
7445
|
}
|
|
7400
7446
|
function usesTwContentVariable(root) {
|
|
7401
7447
|
let used = false;
|
|
@@ -7413,6 +7459,166 @@ function isMiniProgramThemeVariableRule(node) {
|
|
|
7413
7459
|
return isMiniProgramThemeScopeSelector(getRuleSelectors(node)) && isCustomPropertyRule(node);
|
|
7414
7460
|
}
|
|
7415
7461
|
//#endregion
|
|
7462
|
+
//#region src/compat/mini-program-css/hoist.ts
|
|
7463
|
+
const HOIST_ANCHOR_COMMENT = "__weapp_tailwindcss_base_anchor__";
|
|
7464
|
+
function getTopDirectiveTail(root) {
|
|
7465
|
+
let tail;
|
|
7466
|
+
for (const node of root.nodes ?? []) {
|
|
7467
|
+
if (node.type === "atrule" && (node.name === "charset" || node.name === "import")) {
|
|
7468
|
+
tail = node;
|
|
7469
|
+
continue;
|
|
7470
|
+
}
|
|
7471
|
+
break;
|
|
7472
|
+
}
|
|
7473
|
+
return tail;
|
|
7474
|
+
}
|
|
7475
|
+
function reorderPreflightResetDeclarations(rule) {
|
|
7476
|
+
const declarations = (rule.nodes ?? []).filter((node) => node.type === "decl");
|
|
7477
|
+
if (declarations.length <= 1) return;
|
|
7478
|
+
const resetDeclarations = [];
|
|
7479
|
+
const otherDeclarations = [];
|
|
7480
|
+
for (const declaration of declarations) if (PREFLIGHT_RESET_PROPS.has(declaration.prop)) resetDeclarations.push(declaration);
|
|
7481
|
+
else otherDeclarations.push(declaration);
|
|
7482
|
+
if (resetDeclarations.length === 0 || otherDeclarations.length === 0) return;
|
|
7483
|
+
const orderedDeclarations = [...resetDeclarations, ...otherDeclarations];
|
|
7484
|
+
if (orderedDeclarations.every((declaration, index) => declaration === declarations[index])) return;
|
|
7485
|
+
for (const declaration of declarations) declaration.remove();
|
|
7486
|
+
rule.prepend(...orderedDeclarations);
|
|
7487
|
+
rule.raws.semicolon = true;
|
|
7488
|
+
}
|
|
7489
|
+
function createHoistInsertionAnchor(root) {
|
|
7490
|
+
for (const node of root.nodes ?? []) if (isMiniProgramPreflightRule(node) || isMiniProgramThemeVariableRule(node)) {
|
|
7491
|
+
const anchor = postcss.comment({ text: HOIST_ANCHOR_COMMENT });
|
|
7492
|
+
node.before(anchor);
|
|
7493
|
+
return anchor;
|
|
7494
|
+
}
|
|
7495
|
+
}
|
|
7496
|
+
function insertHoistedRules(root, rules, anchor) {
|
|
7497
|
+
if (anchor && !anchor.parent) anchor = void 0;
|
|
7498
|
+
if (rules.length === 0) {
|
|
7499
|
+
anchor?.remove();
|
|
7500
|
+
return;
|
|
7501
|
+
}
|
|
7502
|
+
const topDirectiveTail = getTopDirectiveTail(root);
|
|
7503
|
+
const firstRule = rules[0];
|
|
7504
|
+
if (!firstRule) return;
|
|
7505
|
+
if (anchor) {
|
|
7506
|
+
if (anchor.raws.before === void 0) delete firstRule.raws.before;
|
|
7507
|
+
else firstRule.raws.before = anchor.raws.before;
|
|
7508
|
+
anchor.replaceWith(rules);
|
|
7509
|
+
return;
|
|
7510
|
+
}
|
|
7511
|
+
firstRule.raws.before = topDirectiveTail ? "\n" : "";
|
|
7512
|
+
if (topDirectiveTail) topDirectiveTail.after(rules);
|
|
7513
|
+
else root.prepend(rules);
|
|
7514
|
+
}
|
|
7515
|
+
function mergeEquivalentHoistedRules(rules) {
|
|
7516
|
+
const mergedRules = [];
|
|
7517
|
+
const ruleBySelector = /* @__PURE__ */ new Map();
|
|
7518
|
+
const propsBySelector = /* @__PURE__ */ new Map();
|
|
7519
|
+
for (const rule of rules) {
|
|
7520
|
+
const key = getSortedRuleSelectorKey(rule);
|
|
7521
|
+
const existingRule = ruleBySelector.get(key);
|
|
7522
|
+
if (existingRule) {
|
|
7523
|
+
const existingProps = propsBySelector.get(key) ?? /* @__PURE__ */ new Set();
|
|
7524
|
+
const nextNodes = (rule.nodes ?? []).filter((node) => {
|
|
7525
|
+
if (node.type !== "decl") return true;
|
|
7526
|
+
if (existingProps.has(node.prop)) return false;
|
|
7527
|
+
existingProps.add(node.prop);
|
|
7528
|
+
return true;
|
|
7529
|
+
});
|
|
7530
|
+
existingRule.append(...nextNodes.map((node) => node.clone()));
|
|
7531
|
+
reorderPreflightResetDeclarations(existingRule);
|
|
7532
|
+
propsBySelector.set(key, existingProps);
|
|
7533
|
+
continue;
|
|
7534
|
+
}
|
|
7535
|
+
ruleBySelector.set(key, rule);
|
|
7536
|
+
propsBySelector.set(key, new Set((rule.nodes ?? []).flatMap((node) => node.type === "decl" ? [node.prop] : [])));
|
|
7537
|
+
reorderPreflightResetDeclarations(rule);
|
|
7538
|
+
mergedRules.push(rule);
|
|
7539
|
+
}
|
|
7540
|
+
return mergedRules;
|
|
7541
|
+
}
|
|
7542
|
+
//#endregion
|
|
7543
|
+
//#region src/compat/mini-program-css/preflight.ts
|
|
7544
|
+
const MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR$1 = "::before,\n::after";
|
|
7545
|
+
const MINI_PROGRAM_PSEUDO_CONTENT_SELECTORS = new Set(["::before", "::after"]);
|
|
7546
|
+
function createPseudoContentInitRule() {
|
|
7547
|
+
const rule = postcss.rule({ selector: MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR$1 });
|
|
7548
|
+
rule.append({
|
|
7549
|
+
prop: "--tw-content",
|
|
7550
|
+
value: "''"
|
|
7551
|
+
});
|
|
7552
|
+
return rule;
|
|
7553
|
+
}
|
|
7554
|
+
function applyConfiguredPreflightDeclarations(rule, cssPreflight) {
|
|
7555
|
+
if (!cssPreflight || typeof cssPreflight !== "object") return;
|
|
7556
|
+
const configuredProps = new Set(Object.keys(cssPreflight));
|
|
7557
|
+
rule.walkDecls((decl) => {
|
|
7558
|
+
if (!configuredProps.has(decl.prop)) return;
|
|
7559
|
+
const value = cssPreflight[decl.prop];
|
|
7560
|
+
if (value === false) {
|
|
7561
|
+
decl.remove();
|
|
7562
|
+
return;
|
|
7563
|
+
}
|
|
7564
|
+
decl.value = value.toString();
|
|
7565
|
+
});
|
|
7566
|
+
for (const [prop, value] of Object.entries(cssPreflight)) {
|
|
7567
|
+
if (value === false || rule.nodes?.some((node) => node.type === "decl" && node.prop === prop)) continue;
|
|
7568
|
+
rule.append({
|
|
7569
|
+
prop,
|
|
7570
|
+
value: value.toString()
|
|
7571
|
+
});
|
|
7572
|
+
}
|
|
7573
|
+
}
|
|
7574
|
+
function collectPreflightRules(root, options = {}) {
|
|
7575
|
+
const preflightNodes = [];
|
|
7576
|
+
for (const node of root.nodes ?? []) if (isMiniProgramPreflightRule(node)) preflightNodes.push(node);
|
|
7577
|
+
if (preflightNodes.length === 0) return [];
|
|
7578
|
+
const clonedPreflightRules = preflightNodes.map((node) => {
|
|
7579
|
+
const rule = node.clone();
|
|
7580
|
+
rule.walkDecls("--tw-content", (decl) => {
|
|
7581
|
+
if (isEmptyTwContentDeclaration(decl)) decl.remove();
|
|
7582
|
+
});
|
|
7583
|
+
return rule;
|
|
7584
|
+
});
|
|
7585
|
+
for (const rule of clonedPreflightRules) {
|
|
7586
|
+
const selectors = getRuleSelectors(rule);
|
|
7587
|
+
const hasElementSelector = selectors.some((selector) => selector === "view" || selector === "text");
|
|
7588
|
+
if (selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_PSEUDO_CONTENT_SELECTORS.has(selector))) rule.selector = MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR$1;
|
|
7589
|
+
else if (hasElementSelector && selectors.every((selector) => MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS.has(selector))) {
|
|
7590
|
+
rule.selector = MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR;
|
|
7591
|
+
applyConfiguredPreflightDeclarations(rule, options.cssPreflight);
|
|
7592
|
+
}
|
|
7593
|
+
}
|
|
7594
|
+
const nonEmptyPreflightRules = clonedPreflightRules.filter((rule) => (rule.nodes?.length ?? 0) > 0);
|
|
7595
|
+
const preflightRules = [...options.preservePseudoContentInit ? [createPseudoContentInitRule()] : [], ...nonEmptyPreflightRules];
|
|
7596
|
+
for (const node of preflightNodes) node.remove();
|
|
7597
|
+
return preflightRules;
|
|
7598
|
+
}
|
|
7599
|
+
function createPreflightResetRule(cssPreflight) {
|
|
7600
|
+
if (!cssPreflight || typeof cssPreflight !== "object") return;
|
|
7601
|
+
const rule = postcss.rule({ selector: MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR });
|
|
7602
|
+
for (const [prop, value] of Object.entries(cssPreflight)) {
|
|
7603
|
+
if (value === false) continue;
|
|
7604
|
+
rule.append({
|
|
7605
|
+
prop,
|
|
7606
|
+
value: value.toString()
|
|
7607
|
+
});
|
|
7608
|
+
}
|
|
7609
|
+
return rule.nodes?.length ? rule : void 0;
|
|
7610
|
+
}
|
|
7611
|
+
//#endregion
|
|
7612
|
+
//#region src/compat/mini-program-css/color-gamut.ts
|
|
7613
|
+
const DISPLAY_P3_VALUE_RE = /color\(\s*display-p3\b/i;
|
|
7614
|
+
const COLOR_GAMUT_P3_RE = /\(\s*color-gamut\s*:\s*p3\s*\)/i;
|
|
7615
|
+
function isDisplayP3MediaRule(atRule) {
|
|
7616
|
+
return atRule.name === "media" && COLOR_GAMUT_P3_RE.test(atRule.params);
|
|
7617
|
+
}
|
|
7618
|
+
function isDisplayP3Declaration(decl) {
|
|
7619
|
+
return DISPLAY_P3_VALUE_RE.test(decl.value);
|
|
7620
|
+
}
|
|
7621
|
+
//#endregion
|
|
7416
7622
|
//#region src/compat/mini-program-css/root-cleanups.ts
|
|
7417
7623
|
function removeSpecificityPlaceholders(root) {
|
|
7418
7624
|
root.walkRules((rule) => {
|
|
@@ -7427,8 +7633,11 @@ function removeSpecificityPlaceholders(root) {
|
|
|
7427
7633
|
if (changed) rule.selectors = selectors;
|
|
7428
7634
|
});
|
|
7429
7635
|
}
|
|
7636
|
+
function isEffectivelyEmptyContainer(container) {
|
|
7637
|
+
return !container.nodes || container.nodes.every((node) => node.type === "comment");
|
|
7638
|
+
}
|
|
7430
7639
|
function removeEmptyAtRuleAncestors(parent) {
|
|
7431
|
-
while (parent?.type === "atrule" && (
|
|
7640
|
+
while (parent?.type === "atrule" && isEffectivelyEmptyContainer(parent)) {
|
|
7432
7641
|
const nextParent = parent.parent;
|
|
7433
7642
|
parent.remove();
|
|
7434
7643
|
parent = nextParent?.type === "atrule" ? nextParent : void 0;
|
|
@@ -7466,6 +7675,43 @@ function removeDisplayP3Declarations(root) {
|
|
|
7466
7675
|
}
|
|
7467
7676
|
});
|
|
7468
7677
|
}
|
|
7678
|
+
const SIMPLE_MIN_WIDTH_MEDIA_RE = /^\(\s*min-width\s*:[^)]+\)$/i;
|
|
7679
|
+
const TAILWIND_GENERATED_TOKEN_COMMENT_RE = /^\s*tokens:\s*container\s*<=\s*<tailwind generated>\s*$/i;
|
|
7680
|
+
function isContainerMaxWidthOnlyRule(rule) {
|
|
7681
|
+
if (!rule.selectors || rule.selectors.length !== 1 || rule.selectors[0] !== ".container") return false;
|
|
7682
|
+
const declarations = rule.nodes?.filter((node) => node.type === "decl") ?? [];
|
|
7683
|
+
return declarations.length === 1 && declarations[0]?.prop === "max-width" && (rule.nodes ?? []).every((node) => node.type === "decl" || node.type === "comment");
|
|
7684
|
+
}
|
|
7685
|
+
function removeTailwindContainerMaxWidthMediaRules(root) {
|
|
7686
|
+
root.walkAtRules("media", (atRule) => {
|
|
7687
|
+
if (!SIMPLE_MIN_WIDTH_MEDIA_RE.test(atRule.params.trim())) return;
|
|
7688
|
+
atRule.walkRules((rule) => {
|
|
7689
|
+
if (!isContainerMaxWidthOnlyRule(rule)) return;
|
|
7690
|
+
const parent = rule.parent;
|
|
7691
|
+
rule.remove();
|
|
7692
|
+
removeEmptyAtRuleAncestors(parent);
|
|
7693
|
+
});
|
|
7694
|
+
});
|
|
7695
|
+
}
|
|
7696
|
+
function isContainerWidthOnlyRule(rule) {
|
|
7697
|
+
if (!rule.selectors || rule.selectors.length !== 1 || rule.selectors[0] !== ".container") return false;
|
|
7698
|
+
const declarations = rule.nodes?.filter((node) => node.type === "decl") ?? [];
|
|
7699
|
+
return declarations.length === 1 && declarations[0]?.prop === "width" && declarations[0].value.trim() === "100%" && (rule.nodes ?? []).every((node) => node.type === "decl" || node.type === "comment");
|
|
7700
|
+
}
|
|
7701
|
+
function isTailwindGeneratedContainerRule(rule) {
|
|
7702
|
+
const previous = rule.prev();
|
|
7703
|
+
return previous?.type === "comment" && TAILWIND_GENERATED_TOKEN_COMMENT_RE.test(previous.text);
|
|
7704
|
+
}
|
|
7705
|
+
function removeTailwindContainerWidthRules(root, options = {}) {
|
|
7706
|
+
root.walkRules((rule) => {
|
|
7707
|
+
if (!isContainerWidthOnlyRule(rule)) return;
|
|
7708
|
+
if (options.generatedOnly && !isTailwindGeneratedContainerRule(rule)) return;
|
|
7709
|
+
const parent = rule.parent;
|
|
7710
|
+
if (isTailwindGeneratedContainerRule(rule)) rule.prev()?.remove();
|
|
7711
|
+
rule.remove();
|
|
7712
|
+
removeEmptyAtRuleAncestors(parent);
|
|
7713
|
+
});
|
|
7714
|
+
}
|
|
7469
7715
|
function removeUnsupportedModernColorDeclarations(root) {
|
|
7470
7716
|
const customPropertyValues = /* @__PURE__ */ new Map();
|
|
7471
7717
|
root.walkDecls((decl) => {
|
|
@@ -7481,53 +7727,7 @@ function removeUnsupportedModernColorDeclarations(root) {
|
|
|
7481
7727
|
});
|
|
7482
7728
|
}
|
|
7483
7729
|
//#endregion
|
|
7484
|
-
//#region src/compat/mini-program-css/
|
|
7485
|
-
const HOIST_ANCHOR_COMMENT = "__weapp_tailwindcss_base_anchor__";
|
|
7486
|
-
const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
|
|
7487
|
-
const MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR = "::before,\n::after";
|
|
7488
|
-
const MINI_PROGRAM_PSEUDO_CONTENT_SELECTORS = new Set(["::before", "::after"]);
|
|
7489
|
-
function createPseudoContentInitRule() {
|
|
7490
|
-
const rule = postcss.rule({ selector: MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR });
|
|
7491
|
-
rule.append({
|
|
7492
|
-
prop: "--tw-content",
|
|
7493
|
-
value: "''"
|
|
7494
|
-
});
|
|
7495
|
-
return rule;
|
|
7496
|
-
}
|
|
7497
|
-
function collectPreflightRules(root, options = {}) {
|
|
7498
|
-
const preflightNodes = [];
|
|
7499
|
-
for (const node of root.nodes ?? []) if (isMiniProgramPreflightRule(node)) preflightNodes.push(node);
|
|
7500
|
-
if (preflightNodes.length === 0) return [];
|
|
7501
|
-
const clonedPreflightRules = preflightNodes.map((node) => {
|
|
7502
|
-
const rule = node.clone();
|
|
7503
|
-
rule.walkDecls("--tw-content", (decl) => {
|
|
7504
|
-
if (isEmptyTwContentDeclaration(decl)) decl.remove();
|
|
7505
|
-
});
|
|
7506
|
-
return rule;
|
|
7507
|
-
});
|
|
7508
|
-
for (const rule of clonedPreflightRules) {
|
|
7509
|
-
const selectors = getRuleSelectors(rule);
|
|
7510
|
-
const hasElementSelector = selectors.some((selector) => selector === "view" || selector === "text");
|
|
7511
|
-
if (selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_PSEUDO_CONTENT_SELECTORS.has(selector))) rule.selector = MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR;
|
|
7512
|
-
else if (hasElementSelector && selectors.every((selector) => MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS.has(selector))) rule.selector = MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR;
|
|
7513
|
-
}
|
|
7514
|
-
const nonEmptyPreflightRules = clonedPreflightRules.filter((rule) => (rule.nodes?.length ?? 0) > 0);
|
|
7515
|
-
const preflightRules = [...options.preservePseudoContentInit ? [createPseudoContentInitRule()] : [], ...nonEmptyPreflightRules];
|
|
7516
|
-
for (const node of preflightNodes) node.remove();
|
|
7517
|
-
return preflightRules;
|
|
7518
|
-
}
|
|
7519
|
-
function createPreflightResetRule(cssPreflight) {
|
|
7520
|
-
if (!cssPreflight || typeof cssPreflight !== "object") return;
|
|
7521
|
-
const rule = postcss.rule({ selector: MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR });
|
|
7522
|
-
for (const [prop, value] of Object.entries(cssPreflight)) {
|
|
7523
|
-
if (value === false) continue;
|
|
7524
|
-
rule.append({
|
|
7525
|
-
prop,
|
|
7526
|
-
value: value.toString()
|
|
7527
|
-
});
|
|
7528
|
-
}
|
|
7529
|
-
return rule.nodes?.length ? rule : void 0;
|
|
7530
|
-
}
|
|
7730
|
+
//#region src/compat/mini-program-css/theme.ts
|
|
7531
7731
|
function collectThemeVariableRule(root, options = {}) {
|
|
7532
7732
|
const themeRules = [];
|
|
7533
7733
|
const declarations = /* @__PURE__ */ new Map();
|
|
@@ -7547,86 +7747,22 @@ function collectThemeVariableRule(root, options = {}) {
|
|
|
7547
7747
|
for (const decl of declarations.values()) rule.append(decl);
|
|
7548
7748
|
return rule;
|
|
7549
7749
|
}
|
|
7550
|
-
|
|
7551
|
-
|
|
7552
|
-
const root = postcss.parse(css);
|
|
7553
|
-
let hasProperty = false;
|
|
7554
|
-
root.walkAtRules("property", (atRule) => {
|
|
7555
|
-
if (atRule.params.trim().startsWith("--tw-")) {
|
|
7556
|
-
hasProperty = true;
|
|
7557
|
-
return false;
|
|
7558
|
-
}
|
|
7559
|
-
});
|
|
7560
|
-
return hasProperty;
|
|
7561
|
-
}
|
|
7562
|
-
function getTopDirectiveTail(root) {
|
|
7563
|
-
let tail;
|
|
7564
|
-
for (const node of root.nodes ?? []) {
|
|
7565
|
-
if (node.type === "atrule" && (node.name === "charset" || node.name === "import")) {
|
|
7566
|
-
tail = node;
|
|
7567
|
-
continue;
|
|
7568
|
-
}
|
|
7569
|
-
break;
|
|
7570
|
-
}
|
|
7571
|
-
return tail;
|
|
7572
|
-
}
|
|
7573
|
-
function createHoistInsertionAnchor(root) {
|
|
7574
|
-
for (const node of root.nodes ?? []) if (isMiniProgramPreflightRule(node) || isMiniProgramThemeVariableRule(node)) {
|
|
7575
|
-
const anchor = postcss.comment({ text: HOIST_ANCHOR_COMMENT });
|
|
7576
|
-
node.before(anchor);
|
|
7577
|
-
return anchor;
|
|
7578
|
-
}
|
|
7579
|
-
}
|
|
7580
|
-
function insertHoistedRules(root, rules, anchor) {
|
|
7581
|
-
if (anchor && !anchor.parent) anchor = void 0;
|
|
7582
|
-
if (rules.length === 0) {
|
|
7583
|
-
anchor?.remove();
|
|
7584
|
-
return;
|
|
7585
|
-
}
|
|
7586
|
-
const topDirectiveTail = getTopDirectiveTail(root);
|
|
7587
|
-
const firstRule = rules[0];
|
|
7588
|
-
if (!firstRule) return;
|
|
7589
|
-
if (anchor) {
|
|
7590
|
-
if (anchor.raws.before === void 0) delete firstRule.raws.before;
|
|
7591
|
-
else firstRule.raws.before = anchor.raws.before;
|
|
7592
|
-
anchor.replaceWith(rules);
|
|
7593
|
-
return;
|
|
7594
|
-
}
|
|
7595
|
-
firstRule.raws.before = topDirectiveTail ? "\n" : "";
|
|
7596
|
-
if (topDirectiveTail) topDirectiveTail.after(rules);
|
|
7597
|
-
else root.prepend(rules);
|
|
7598
|
-
}
|
|
7599
|
-
function mergeEquivalentHoistedRules(rules) {
|
|
7600
|
-
const mergedRules = [];
|
|
7601
|
-
const ruleBySelector = /* @__PURE__ */ new Map();
|
|
7602
|
-
for (const rule of rules) {
|
|
7603
|
-
const key = getSortedRuleSelectorKey(rule);
|
|
7604
|
-
const existingRule = ruleBySelector.get(key);
|
|
7605
|
-
if (existingRule) {
|
|
7606
|
-
existingRule.append(...(rule.nodes ?? []).map((node) => node.clone()));
|
|
7607
|
-
continue;
|
|
7608
|
-
}
|
|
7609
|
-
ruleBySelector.set(key, rule);
|
|
7610
|
-
mergedRules.push(rule);
|
|
7611
|
-
}
|
|
7612
|
-
return mergedRules;
|
|
7613
|
-
}
|
|
7614
|
-
function unwrapTailwindSourceMedia(root) {
|
|
7615
|
-
root.walkAtRules("media", (atRule) => {
|
|
7616
|
-
if (atRule.params.startsWith("source(") && atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
|
|
7617
|
-
});
|
|
7618
|
-
}
|
|
7750
|
+
//#endregion
|
|
7751
|
+
//#region src/compat/mini-program-css/finalize.ts
|
|
7619
7752
|
function finalizeMiniProgramCssRoot(root, options = {}) {
|
|
7620
7753
|
const shouldInjectTailwindcssV4Defaults = options.isTailwindcssV4 === true;
|
|
7621
7754
|
const tailwindcssV4DefaultNodes = shouldInjectTailwindcssV4Defaults ? createMissingCssVarsV4Nodes(root, collectUsedTailwindcssV4Variables(root)) : [];
|
|
7622
7755
|
removeUnsupportedCascadeLayers(root);
|
|
7623
7756
|
unwrapTailwindSourceMedia(root);
|
|
7757
|
+
removeTailwindGenerationDirectives(root);
|
|
7624
7758
|
root.walkAtRules("property", (atRule) => {
|
|
7625
7759
|
atRule.remove();
|
|
7626
7760
|
});
|
|
7627
7761
|
removeSpecificityPlaceholders(root);
|
|
7628
7762
|
removeUnsupportedBrowserSelectors(root);
|
|
7629
7763
|
removeDisplayP3Declarations(root);
|
|
7764
|
+
removeTailwindContainerMaxWidthMediaRules(root);
|
|
7765
|
+
removeTailwindContainerWidthRules(root, { generatedOnly: true });
|
|
7630
7766
|
removeUnsupportedModernColorDeclarations(root);
|
|
7631
7767
|
root.walkDecls((decl) => {
|
|
7632
7768
|
if (shouldInjectTailwindcssV4Defaults) normalizeTailwindcssV4Declaration(decl);
|
|
@@ -7679,6 +7815,7 @@ function finalizeMiniProgramCss(css, options = {}) {
|
|
|
7679
7815
|
//#endregion
|
|
7680
7816
|
//#region src/compat/mini-program-css/prune-generated.ts
|
|
7681
7817
|
const DEFAULT_WEAPP_VARIABLE_SCOPE = "page,.tw-root,wx-root-portal-content,:host";
|
|
7818
|
+
const MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR = "::before,\n::after";
|
|
7682
7819
|
const CLASS_SELECTOR_RE$1 = /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i;
|
|
7683
7820
|
function isConditionalCompilationComment(text) {
|
|
7684
7821
|
return /#(?:ifn?def|endif)\b/.test(text);
|
|
@@ -7695,6 +7832,23 @@ function isMiniProgramElementVariableScopeRule(rule) {
|
|
|
7695
7832
|
const selectors = getRuleSelectors(rule);
|
|
7696
7833
|
return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS.has(selector));
|
|
7697
7834
|
}
|
|
7835
|
+
function isOnlyTwContentDeclarations(rule) {
|
|
7836
|
+
let hasDeclaration = false;
|
|
7837
|
+
let onlyContentVariable = true;
|
|
7838
|
+
rule.walkDecls((decl) => {
|
|
7839
|
+
hasDeclaration = true;
|
|
7840
|
+
if (decl.prop !== "--tw-content") onlyContentVariable = false;
|
|
7841
|
+
});
|
|
7842
|
+
return hasDeclaration && onlyContentVariable;
|
|
7843
|
+
}
|
|
7844
|
+
function isMiniProgramElementContentInitRule(rule) {
|
|
7845
|
+
if (!isMiniProgramElementVariableScopeRule(rule)) return false;
|
|
7846
|
+
let hasElementSelector = false;
|
|
7847
|
+
let hasPseudoSelector = false;
|
|
7848
|
+
for (const selector of getRuleSelectors(rule)) if (selector === "view" || selector === "text") hasElementSelector = true;
|
|
7849
|
+
else if (selector === "::before" || selector === "::after") hasPseudoSelector = true;
|
|
7850
|
+
return hasElementSelector && hasPseudoSelector && isOnlyTwContentDeclarations(rule);
|
|
7851
|
+
}
|
|
7698
7852
|
function isTailwindV4GradientRuntimeDeclaration(decl) {
|
|
7699
7853
|
return decl.prop.startsWith("--tw-gradient-");
|
|
7700
7854
|
}
|
|
@@ -7732,6 +7886,8 @@ function pruneMiniProgramGeneratedCss(css, options = {}) {
|
|
|
7732
7886
|
});
|
|
7733
7887
|
removeUnsupportedCascadeLayers(root);
|
|
7734
7888
|
removeUnsupportedModernColorDeclarations(root);
|
|
7889
|
+
removeTailwindContainerMaxWidthMediaRules(root);
|
|
7890
|
+
removeTailwindContainerWidthRules(root);
|
|
7735
7891
|
root.walkAtRules("supports", (atRule) => {
|
|
7736
7892
|
atRule.remove();
|
|
7737
7893
|
});
|
|
@@ -7743,6 +7899,18 @@ function pruneMiniProgramGeneratedCss(css, options = {}) {
|
|
|
7743
7899
|
});
|
|
7744
7900
|
root.walkRules((rule) => {
|
|
7745
7901
|
if (isKeyframesRule(rule)) return;
|
|
7902
|
+
if (isPseudoContentInitRule(rule)) {
|
|
7903
|
+
if (!shouldPreserveContentInit) rule.remove();
|
|
7904
|
+
return;
|
|
7905
|
+
}
|
|
7906
|
+
if (isMiniProgramElementContentInitRule(rule)) {
|
|
7907
|
+
if (!shouldPreserveContentInit) {
|
|
7908
|
+
rule.remove();
|
|
7909
|
+
return;
|
|
7910
|
+
}
|
|
7911
|
+
rule.selector = MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR;
|
|
7912
|
+
return;
|
|
7913
|
+
}
|
|
7746
7914
|
if (isCustomPropertyRule(rule) && isMiniProgramElementVariableScopeRule(rule)) {
|
|
7747
7915
|
rule.selector = MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR;
|
|
7748
7916
|
return;
|
|
@@ -7755,10 +7923,6 @@ function pruneMiniProgramGeneratedCss(css, options = {}) {
|
|
|
7755
7923
|
}
|
|
7756
7924
|
if (hasClassSelector$2(rule.selector)) return;
|
|
7757
7925
|
if (!shouldPreserveContentInit) removeEmptyContentInitDeclarations(rule);
|
|
7758
|
-
if (isPseudoContentInitRule(rule)) {
|
|
7759
|
-
if (!shouldPreserveContentInit) rule.remove();
|
|
7760
|
-
return;
|
|
7761
|
-
}
|
|
7762
7926
|
if (options.preservePreflight && isMiniProgramPreflightRule(rule)) return;
|
|
7763
7927
|
if (isCustomPropertyRule(rule)) {
|
|
7764
7928
|
moveTailwindV4GradientRuntimeDeclarations(rule);
|
|
@@ -43113,7 +43277,7 @@ const n$9 = "js-blank-pseudo", t$12 = ":blank", creator$48 = (s) => {
|
|
|
43113
43277
|
};
|
|
43114
43278
|
creator$48.postcss = !0;
|
|
43115
43279
|
//#endregion
|
|
43116
|
-
//#region ../../node_modules/.pnpm/@csstools+selector-specificity@6.0.0_postcss-selector-parser@7.1.
|
|
43280
|
+
//#region ../../node_modules/.pnpm/@csstools+selector-specificity@6.0.0_postcss-selector-parser@7.1.2/node_modules/@csstools/selector-specificity/dist/index.mjs
|
|
43117
43281
|
var import_postcss_page_break = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
43118
43282
|
module.exports = function(options) {
|
|
43119
43283
|
return {
|
|
@@ -49908,7 +50072,7 @@ const creator$18 = (s) => {
|
|
|
49908
50072
|
};
|
|
49909
50073
|
creator$18.postcss = !0;
|
|
49910
50074
|
//#endregion
|
|
49911
|
-
//#region ../../node_modules/.pnpm/@csstools+selector-resolve-nested@4.0.0_postcss-selector-parser@7.1.
|
|
50075
|
+
//#region ../../node_modules/.pnpm/@csstools+selector-resolve-nested@4.0.0_postcss-selector-parser@7.1.2/node_modules/@csstools/selector-resolve-nested/dist/index.mjs
|
|
49912
50076
|
function sourceFrom(e) {
|
|
49913
50077
|
return {
|
|
49914
50078
|
sourceIndex: e.sourceIndex ?? 0,
|
|
@@ -53116,10 +53280,7 @@ function normalizeSpacingDeclarations(rule) {
|
|
|
53116
53280
|
for (const declarations of grouped.values()) dedupeSpacingGroup(rule, declarations);
|
|
53117
53281
|
}
|
|
53118
53282
|
//#endregion
|
|
53119
|
-
//#region src/selectorParser/rule-transformer.ts
|
|
53120
|
-
const ruleTransformCache = /* @__PURE__ */ new WeakMap();
|
|
53121
|
-
const SELECTOR_TRANSFORM_OPTIONS = normalizeTransformOptions();
|
|
53122
|
-
const SIMPLE_SELECTOR_FAST_PATH = /^[#.][\w-]+(?:\s+[#.][\w-]+)*$/;
|
|
53283
|
+
//#region src/selectorParser/rule-transformer/pseudos.ts
|
|
53123
53284
|
const RTL_LANGUAGE_ANY_PSEUDO_SET = new Set([
|
|
53124
53285
|
":-moz-any",
|
|
53125
53286
|
":-webkit-any",
|
|
@@ -53135,6 +53296,23 @@ const EMPTY_FUNCTIONAL_PSEUDO_CLEANUP_SET = new Set([
|
|
|
53135
53296
|
":-moz-any",
|
|
53136
53297
|
":lang"
|
|
53137
53298
|
]);
|
|
53299
|
+
const UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET = new Set([
|
|
53300
|
+
":after",
|
|
53301
|
+
":before",
|
|
53302
|
+
"::after",
|
|
53303
|
+
"::before",
|
|
53304
|
+
"::backdrop",
|
|
53305
|
+
"::-ms-backdrop",
|
|
53306
|
+
"::-webkit-backdrop",
|
|
53307
|
+
"::file-selector-button"
|
|
53308
|
+
]);
|
|
53309
|
+
const MINI_PROGRAM_UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET = new Set([
|
|
53310
|
+
"::backdrop",
|
|
53311
|
+
"::-ms-backdrop",
|
|
53312
|
+
"::-webkit-backdrop",
|
|
53313
|
+
"::file-selector-button"
|
|
53314
|
+
]);
|
|
53315
|
+
const NORMALIZED_PSEUDO_ELEMENT_SELECTOR = new Map([[":before", "::before"], [":after", "::after"]]);
|
|
53138
53316
|
function isRtlLanguageAnyPseudo(node) {
|
|
53139
53317
|
return node.type === "pseudo" && RTL_LANGUAGE_ANY_PSEUDO_SET.has(node.value);
|
|
53140
53318
|
}
|
|
@@ -53171,6 +53349,29 @@ function flattenWherePseudo(node, context, index, parent) {
|
|
|
53171
53349
|
if (parent && parent.type === "selector" && parent.length === 0) parent.remove();
|
|
53172
53350
|
}
|
|
53173
53351
|
}
|
|
53352
|
+
function shouldRemoveUnsupportedPseudoElementSelector(selector, options) {
|
|
53353
|
+
if (!isUniAppXEnabled(options)) return selector.nodes.some((node) => node.type === "pseudo" && MINI_PROGRAM_UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
|
|
53354
|
+
return selector.nodes.some((node) => node.type === "pseudo" && UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
|
|
53355
|
+
}
|
|
53356
|
+
function handlePseudoNode(node, index, context, parent) {
|
|
53357
|
+
if (node.type !== "pseudo") return;
|
|
53358
|
+
if (isRtlLanguageAnyPseudo(node)) {
|
|
53359
|
+
stripUnsupportedRtlLanguagePseudo(node);
|
|
53360
|
+
return;
|
|
53361
|
+
}
|
|
53362
|
+
if (node.value === ":root" && context.rootReplacement) {
|
|
53363
|
+
node.value = context.rootReplacement;
|
|
53364
|
+
return;
|
|
53365
|
+
}
|
|
53366
|
+
const normalizedPseudoElement = NORMALIZED_PSEUDO_ELEMENT_SELECTOR.get(node.value);
|
|
53367
|
+
if (normalizedPseudoElement) {
|
|
53368
|
+
node.value = normalizedPseudoElement;
|
|
53369
|
+
return;
|
|
53370
|
+
}
|
|
53371
|
+
if (node.value === ":where") flattenWherePseudo(node, context, index, parent);
|
|
53372
|
+
}
|
|
53373
|
+
//#endregion
|
|
53374
|
+
//#region src/selectorParser/rule-transformer/nodes.ts
|
|
53174
53375
|
function handleClassNode(node, context) {
|
|
53175
53376
|
if (node.type !== "class") return;
|
|
53176
53377
|
node.value = context.selectorReplacerOptions === void 0 ? internalCssSelectorReplacer(node.value) : internalCssSelectorReplacer(node.value, context.selectorReplacerOptions);
|
|
@@ -53183,27 +53384,6 @@ function shouldRemoveHoverSelector(selector, options) {
|
|
|
53183
53384
|
if (!options.cssRemoveHoverPseudoClass) return false;
|
|
53184
53385
|
return selector.nodes.some((node) => node.type === "pseudo" && node.value === ":hover");
|
|
53185
53386
|
}
|
|
53186
|
-
const UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET = new Set([
|
|
53187
|
-
":after",
|
|
53188
|
-
":before",
|
|
53189
|
-
"::after",
|
|
53190
|
-
"::before",
|
|
53191
|
-
"::backdrop",
|
|
53192
|
-
"::-ms-backdrop",
|
|
53193
|
-
"::-webkit-backdrop",
|
|
53194
|
-
"::file-selector-button"
|
|
53195
|
-
]);
|
|
53196
|
-
const MINI_PROGRAM_UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET = new Set([
|
|
53197
|
-
"::backdrop",
|
|
53198
|
-
"::-ms-backdrop",
|
|
53199
|
-
"::-webkit-backdrop",
|
|
53200
|
-
"::file-selector-button"
|
|
53201
|
-
]);
|
|
53202
|
-
const NORMALIZED_PSEUDO_ELEMENT_SELECTOR = new Map([[":before", "::before"], [":after", "::after"]]);
|
|
53203
|
-
function shouldRemoveUnsupportedPseudoElementSelector(selector, options) {
|
|
53204
|
-
if (!isUniAppXEnabled(options)) return selector.nodes.some((node) => node.type === "pseudo" && MINI_PROGRAM_UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
|
|
53205
|
-
return selector.nodes.some((node) => node.type === "pseudo" && UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
|
|
53206
|
-
}
|
|
53207
53387
|
function isHiddenOrTemplateNotPseudo(node) {
|
|
53208
53388
|
if (!node || node.type !== "pseudo" || node.value !== ":not") return false;
|
|
53209
53389
|
const selector = node.first;
|
|
@@ -53226,23 +53406,6 @@ function handleCombinatorNode(node, index, context) {
|
|
|
53226
53406
|
nodes.splice(index + 1, 3, ...ast);
|
|
53227
53407
|
}
|
|
53228
53408
|
}
|
|
53229
|
-
function handlePseudoNode(node, index, context, parent) {
|
|
53230
|
-
if (node.type !== "pseudo") return;
|
|
53231
|
-
if (isRtlLanguageAnyPseudo(node)) {
|
|
53232
|
-
stripUnsupportedRtlLanguagePseudo(node);
|
|
53233
|
-
return;
|
|
53234
|
-
}
|
|
53235
|
-
if (node.value === ":root" && context.rootReplacement) {
|
|
53236
|
-
node.value = context.rootReplacement;
|
|
53237
|
-
return;
|
|
53238
|
-
}
|
|
53239
|
-
const normalizedPseudoElement = NORMALIZED_PSEUDO_ELEMENT_SELECTOR.get(node.value);
|
|
53240
|
-
if (normalizedPseudoElement) {
|
|
53241
|
-
node.value = normalizedPseudoElement;
|
|
53242
|
-
return;
|
|
53243
|
-
}
|
|
53244
|
-
if (node.value === ":where") flattenWherePseudo(node, context, index, parent);
|
|
53245
|
-
}
|
|
53246
53409
|
function handleTagOrAttribute(node, context) {
|
|
53247
53410
|
stripUnsupportedNodeForUniAppX(node, context.options);
|
|
53248
53411
|
}
|
|
@@ -53257,6 +53420,11 @@ function handleSelectorNode(selector, context) {
|
|
|
53257
53420
|
}
|
|
53258
53421
|
if (transformSpacingSelector(selector.nodes, context.options)) context.requiresSpacingNormalization = true;
|
|
53259
53422
|
}
|
|
53423
|
+
//#endregion
|
|
53424
|
+
//#region src/selectorParser/rule-transformer.ts
|
|
53425
|
+
const ruleTransformCache = /* @__PURE__ */ new WeakMap();
|
|
53426
|
+
const SELECTOR_TRANSFORM_OPTIONS = normalizeTransformOptions();
|
|
53427
|
+
const SIMPLE_SELECTOR_FAST_PATH = /^[#.][\w-]+(?:\s+[#.][\w-]+)*$/;
|
|
53260
53428
|
function canSkipRuleTransform(rule) {
|
|
53261
53429
|
const selector = rule.selector.trim();
|
|
53262
53430
|
if (!selector) return false;
|
|
@@ -54037,11 +54205,46 @@ function makePseudoVarRule() {
|
|
|
54037
54205
|
function isEmptyContentInitDeclaration(decl) {
|
|
54038
54206
|
return decl.prop === "--tw-content" && (decl.value === "\"\"" || decl.value === "''");
|
|
54039
54207
|
}
|
|
54208
|
+
function isPseudoContentInitSelector(selector) {
|
|
54209
|
+
return selector === ":before" || selector === ":after" || selector === "::before" || selector === "::after";
|
|
54210
|
+
}
|
|
54211
|
+
function isElementContentInitSelector(selector) {
|
|
54212
|
+
return selector === "*" || selector === "view" || selector === "text";
|
|
54213
|
+
}
|
|
54214
|
+
function isOnlyEmptyContentInitRule(node) {
|
|
54215
|
+
let hasDeclaration = false;
|
|
54216
|
+
let onlyEmptyContentInit = true;
|
|
54217
|
+
node.walkDecls((decl) => {
|
|
54218
|
+
hasDeclaration = true;
|
|
54219
|
+
if (!isEmptyContentInitDeclaration(decl)) onlyEmptyContentInit = false;
|
|
54220
|
+
});
|
|
54221
|
+
return hasDeclaration && onlyEmptyContentInit;
|
|
54222
|
+
}
|
|
54223
|
+
function restorePseudoContentInitScope(node) {
|
|
54224
|
+
if (!isOnlyEmptyContentInitRule(node)) return false;
|
|
54225
|
+
let hasPseudoSelector = false;
|
|
54226
|
+
let hasElementSelector = false;
|
|
54227
|
+
for (const selector of node.selectors) if (isPseudoContentInitSelector(selector)) hasPseudoSelector = true;
|
|
54228
|
+
else if (isElementContentInitSelector(selector)) hasElementSelector = true;
|
|
54229
|
+
else return false;
|
|
54230
|
+
if (!hasPseudoSelector || !hasElementSelector) return false;
|
|
54231
|
+
assignRuleSelectors(node, ["::before", "::after"], {
|
|
54232
|
+
phase: "pre",
|
|
54233
|
+
reason: "restore-pseudo-content-init-scope"
|
|
54234
|
+
});
|
|
54235
|
+
return true;
|
|
54236
|
+
}
|
|
54040
54237
|
function removeTailwindV4EmptyContentInit(node) {
|
|
54041
54238
|
node.walkDecls((decl) => {
|
|
54042
54239
|
if (isEmptyContentInitDeclaration(decl)) decl.remove();
|
|
54043
54240
|
});
|
|
54044
54241
|
}
|
|
54242
|
+
function injectPreflightDeclarations(node, options) {
|
|
54243
|
+
const preflightDeclarations = options.cssInjectPreflight?.();
|
|
54244
|
+
if (!preflightDeclarations || preflightDeclarations.length === 0) return;
|
|
54245
|
+
node.prepend(...preflightDeclarations);
|
|
54246
|
+
node.raws.semicolon = true;
|
|
54247
|
+
}
|
|
54045
54248
|
function hasClassSelector(node) {
|
|
54046
54249
|
return node.selectors.some((selector) => selector.includes("."));
|
|
54047
54250
|
}
|
|
@@ -54067,7 +54270,7 @@ function resolveUniAppXVariableScopeSelectors(options) {
|
|
|
54067
54270
|
return ["view", "text"];
|
|
54068
54271
|
}
|
|
54069
54272
|
function commonChunkPreflight(node, options) {
|
|
54070
|
-
const { ctx,
|
|
54273
|
+
const { ctx, injectAdditionalCssVarScope } = options;
|
|
54071
54274
|
const uniAppXEnabled = isUniAppXEnabled(options);
|
|
54072
54275
|
const isTailwindcss4 = isTailwindcssV4(options);
|
|
54073
54276
|
const rootOption = options.cssSelectorReplacement?.root;
|
|
@@ -54080,6 +54283,7 @@ function commonChunkPreflight(node, options) {
|
|
|
54080
54283
|
reason: "append-host-selector"
|
|
54081
54284
|
});
|
|
54082
54285
|
if (isTailwindcss4 && !usesTailwindcssV4ContentVariable(node.root()) && (!hasClassSelector(node) || isRootThemeScopeRule(node))) removeTailwindV4EmptyContentInit(node);
|
|
54286
|
+
if (!isTailwindcss4 && restorePseudoContentInitScope(node)) return;
|
|
54083
54287
|
if (testIfVariablesScope(node) || uniAppXEnabled && node.selectors.includes("*") && hasTwVars(node, 2)) {
|
|
54084
54288
|
ctx?.markVariablesScope(node);
|
|
54085
54289
|
assignRuleSelectors(node, uniAppXEnabled ? resolveUniAppXVariableScopeSelectors(options) : remakeCssVarSelector(node.selectors, options), {
|
|
@@ -54087,7 +54291,7 @@ function commonChunkPreflight(node, options) {
|
|
|
54087
54291
|
reason: "rewrite-variable-scope"
|
|
54088
54292
|
});
|
|
54089
54293
|
if (!uniAppXEnabled && !isTailwindcss4) node.before(makePseudoVarRule());
|
|
54090
|
-
|
|
54294
|
+
injectPreflightDeclarations(node, options);
|
|
54091
54295
|
}
|
|
54092
54296
|
if (injectAdditionalCssVarScope && (isTailwindcss4 ? testIfRootHostForV4(node) : testIfTwBackdrop(node))) {
|
|
54093
54297
|
const nodes = isTailwindcss4 ? createUsedCssVarsV4Nodes(collectUsedTailwindcssV4Variables(node.root())) : cssVarsV3Nodes;
|
|
@@ -54106,7 +54310,7 @@ function commonChunkPreflight(node, options) {
|
|
|
54106
54310
|
});
|
|
54107
54311
|
node.before(syntheticRule);
|
|
54108
54312
|
if (!uniAppXEnabled && !isTailwindcss4) node.before(makePseudoVarRule());
|
|
54109
|
-
|
|
54313
|
+
injectPreflightDeclarations(syntheticRule, options);
|
|
54110
54314
|
}
|
|
54111
54315
|
}
|
|
54112
54316
|
//#endregion
|