@weapp-tailwindcss/postcss 3.0.3 → 3.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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 -12
- 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 +7 -0
- package/dist/compat/mini-program-css/theme.d.ts +3 -0
- package/dist/index.js +447 -281
- package/dist/index.mjs +446 -281
- 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 +3 -3
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,82 +7459,92 @@ function isMiniProgramThemeVariableRule(node) {
|
|
|
7413
7459
|
return isMiniProgramThemeScopeSelector(getRuleSelectors(node)) && isCustomPropertyRule(node);
|
|
7414
7460
|
}
|
|
7415
7461
|
//#endregion
|
|
7416
|
-
//#region src/compat/mini-program-css/
|
|
7417
|
-
|
|
7418
|
-
|
|
7419
|
-
|
|
7420
|
-
|
|
7421
|
-
|
|
7422
|
-
|
|
7423
|
-
|
|
7424
|
-
|
|
7425
|
-
|
|
7426
|
-
});
|
|
7427
|
-
if (changed) rule.selectors = selectors;
|
|
7428
|
-
});
|
|
7429
|
-
}
|
|
7430
|
-
function removeEmptyAtRuleAncestors(parent) {
|
|
7431
|
-
while (parent?.type === "atrule" && (!parent.nodes || parent.nodes.length === 0)) {
|
|
7432
|
-
const nextParent = parent.parent;
|
|
7433
|
-
parent.remove();
|
|
7434
|
-
parent = nextParent?.type === "atrule" ? nextParent : void 0;
|
|
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;
|
|
7435
7472
|
}
|
|
7473
|
+
return tail;
|
|
7436
7474
|
}
|
|
7437
|
-
function
|
|
7438
|
-
|
|
7439
|
-
|
|
7440
|
-
|
|
7441
|
-
|
|
7442
|
-
|
|
7443
|
-
|
|
7444
|
-
|
|
7445
|
-
|
|
7446
|
-
|
|
7447
|
-
|
|
7448
|
-
|
|
7449
|
-
|
|
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;
|
|
7450
7488
|
}
|
|
7451
|
-
function
|
|
7452
|
-
const
|
|
7453
|
-
|
|
7454
|
-
|
|
7455
|
-
|
|
7456
|
-
parent.remove();
|
|
7457
|
-
removeEmptyAtRuleAncestors(ruleParent);
|
|
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;
|
|
7458
7494
|
}
|
|
7459
7495
|
}
|
|
7460
|
-
function
|
|
7461
|
-
|
|
7462
|
-
|
|
7463
|
-
|
|
7464
|
-
|
|
7465
|
-
|
|
7466
|
-
|
|
7467
|
-
|
|
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);
|
|
7468
7514
|
}
|
|
7469
|
-
function
|
|
7470
|
-
const
|
|
7471
|
-
|
|
7472
|
-
|
|
7473
|
-
|
|
7474
|
-
|
|
7475
|
-
const
|
|
7476
|
-
if (
|
|
7477
|
-
|
|
7478
|
-
|
|
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;
|
|
7479
7534
|
}
|
|
7480
|
-
|
|
7481
|
-
|
|
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;
|
|
7482
7541
|
}
|
|
7483
7542
|
//#endregion
|
|
7484
|
-
//#region src/compat/mini-program-css/
|
|
7485
|
-
const
|
|
7486
|
-
const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
|
|
7487
|
-
const GENERATOR_PLACEHOLDER_COMMENT_RE = /^\s*(?:!\s*)?weapp-tailwindcss generator-placeholder\s*$/i;
|
|
7488
|
-
const MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR = "::before,\n::after";
|
|
7543
|
+
//#region src/compat/mini-program-css/preflight.ts
|
|
7544
|
+
const MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR$1 = "::before,\n::after";
|
|
7489
7545
|
const MINI_PROGRAM_PSEUDO_CONTENT_SELECTORS = new Set(["::before", "::after"]);
|
|
7490
7546
|
function createPseudoContentInitRule() {
|
|
7491
|
-
const rule = postcss.rule({ selector: MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR });
|
|
7547
|
+
const rule = postcss.rule({ selector: MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR$1 });
|
|
7492
7548
|
rule.append({
|
|
7493
7549
|
prop: "--tw-content",
|
|
7494
7550
|
value: "''"
|
|
@@ -7529,7 +7585,7 @@ function collectPreflightRules(root, options = {}) {
|
|
|
7529
7585
|
for (const rule of clonedPreflightRules) {
|
|
7530
7586
|
const selectors = getRuleSelectors(rule);
|
|
7531
7587
|
const hasElementSelector = selectors.some((selector) => selector === "view" || selector === "text");
|
|
7532
|
-
if (selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_PSEUDO_CONTENT_SELECTORS.has(selector))) rule.selector = MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR;
|
|
7588
|
+
if (selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_PSEUDO_CONTENT_SELECTORS.has(selector))) rule.selector = MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR$1;
|
|
7533
7589
|
else if (hasElementSelector && selectors.every((selector) => MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS.has(selector))) {
|
|
7534
7590
|
rule.selector = MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR;
|
|
7535
7591
|
applyConfiguredPreflightDeclarations(rule, options.cssPreflight);
|
|
@@ -7552,6 +7608,131 @@ function createPreflightResetRule(cssPreflight) {
|
|
|
7552
7608
|
}
|
|
7553
7609
|
return rule.nodes?.length ? rule : void 0;
|
|
7554
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
|
|
7622
|
+
//#region src/compat/mini-program-css/root-cleanups.ts
|
|
7623
|
+
function removeSpecificityPlaceholders(root) {
|
|
7624
|
+
root.walkRules((rule) => {
|
|
7625
|
+
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
7626
|
+
let changed = false;
|
|
7627
|
+
const selectors = rule.selectors.map((selector) => {
|
|
7628
|
+
let next = selector;
|
|
7629
|
+
for (const suffix of SPECIFICITY_PLACEHOLDER_SUFFIXES) if (next.includes(suffix)) next = next.split(suffix).join("");
|
|
7630
|
+
if (next !== selector) changed = true;
|
|
7631
|
+
return next;
|
|
7632
|
+
});
|
|
7633
|
+
if (changed) rule.selectors = selectors;
|
|
7634
|
+
});
|
|
7635
|
+
}
|
|
7636
|
+
function isEffectivelyEmptyContainer(container) {
|
|
7637
|
+
return !container.nodes || container.nodes.every((node) => node.type === "comment");
|
|
7638
|
+
}
|
|
7639
|
+
function removeEmptyAtRules(root) {
|
|
7640
|
+
root.walkAtRules((atRule) => {
|
|
7641
|
+
if (isEffectivelyEmptyContainer(atRule)) atRule.remove();
|
|
7642
|
+
});
|
|
7643
|
+
}
|
|
7644
|
+
function removeEmptyAtRuleAncestors(parent) {
|
|
7645
|
+
while (parent?.type === "atrule" && isEffectivelyEmptyContainer(parent)) {
|
|
7646
|
+
const nextParent = parent.parent;
|
|
7647
|
+
parent.remove();
|
|
7648
|
+
parent = nextParent?.type === "atrule" ? nextParent : void 0;
|
|
7649
|
+
}
|
|
7650
|
+
}
|
|
7651
|
+
function removeUnsupportedBrowserSelectors(root) {
|
|
7652
|
+
root.walkRules((rule) => {
|
|
7653
|
+
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
7654
|
+
const selectors = rule.selectors.filter((selector) => !isUnsupportedBrowserSelector(selector));
|
|
7655
|
+
if (selectors.length === rule.selectors.length) return;
|
|
7656
|
+
if (selectors.length === 0) {
|
|
7657
|
+
const parent = rule.parent;
|
|
7658
|
+
rule.remove();
|
|
7659
|
+
removeEmptyAtRuleAncestors(parent);
|
|
7660
|
+
return;
|
|
7661
|
+
}
|
|
7662
|
+
rule.selectors = selectors;
|
|
7663
|
+
});
|
|
7664
|
+
}
|
|
7665
|
+
function removeDeclarationAndEmptyRule$1(decl) {
|
|
7666
|
+
const parent = decl.parent;
|
|
7667
|
+
decl.remove();
|
|
7668
|
+
if (parent?.type === "rule" && parent.nodes.length === 0) {
|
|
7669
|
+
const ruleParent = parent.parent;
|
|
7670
|
+
parent.remove();
|
|
7671
|
+
removeEmptyAtRuleAncestors(ruleParent);
|
|
7672
|
+
}
|
|
7673
|
+
}
|
|
7674
|
+
function removeDisplayP3Declarations(root) {
|
|
7675
|
+
root.walkAtRules((atRule) => {
|
|
7676
|
+
if (isDisplayP3MediaRule(atRule)) {
|
|
7677
|
+
const parent = atRule.parent;
|
|
7678
|
+
atRule.remove();
|
|
7679
|
+
removeEmptyAtRuleAncestors(parent);
|
|
7680
|
+
}
|
|
7681
|
+
});
|
|
7682
|
+
}
|
|
7683
|
+
const SIMPLE_MIN_WIDTH_MEDIA_RE = /^\(\s*min-width\s*:[^)]+\)$/i;
|
|
7684
|
+
const TAILWIND_GENERATED_TOKEN_COMMENT_RE = /^\s*tokens:\s*container\s*<=\s*<tailwind generated>\s*$/i;
|
|
7685
|
+
function isContainerMaxWidthOnlyRule(rule) {
|
|
7686
|
+
if (!rule.selectors || rule.selectors.length !== 1 || rule.selectors[0] !== ".container") return false;
|
|
7687
|
+
const declarations = rule.nodes?.filter((node) => node.type === "decl") ?? [];
|
|
7688
|
+
return declarations.length === 1 && declarations[0]?.prop === "max-width" && (rule.nodes ?? []).every((node) => node.type === "decl" || node.type === "comment");
|
|
7689
|
+
}
|
|
7690
|
+
function removeTailwindContainerMaxWidthMediaRules(root) {
|
|
7691
|
+
root.walkAtRules("media", (atRule) => {
|
|
7692
|
+
if (!SIMPLE_MIN_WIDTH_MEDIA_RE.test(atRule.params.trim())) return;
|
|
7693
|
+
atRule.walkRules((rule) => {
|
|
7694
|
+
if (!isContainerMaxWidthOnlyRule(rule)) return;
|
|
7695
|
+
const parent = rule.parent;
|
|
7696
|
+
rule.remove();
|
|
7697
|
+
removeEmptyAtRuleAncestors(parent);
|
|
7698
|
+
});
|
|
7699
|
+
});
|
|
7700
|
+
}
|
|
7701
|
+
function isContainerWidthOnlyRule(rule) {
|
|
7702
|
+
if (!rule.selectors || rule.selectors.length !== 1 || rule.selectors[0] !== ".container") return false;
|
|
7703
|
+
const declarations = rule.nodes?.filter((node) => node.type === "decl") ?? [];
|
|
7704
|
+
return declarations.length === 1 && declarations[0]?.prop === "width" && declarations[0].value.trim() === "100%" && (rule.nodes ?? []).every((node) => node.type === "decl" || node.type === "comment");
|
|
7705
|
+
}
|
|
7706
|
+
function isTailwindGeneratedContainerRule(rule) {
|
|
7707
|
+
const previous = rule.prev();
|
|
7708
|
+
return previous?.type === "comment" && TAILWIND_GENERATED_TOKEN_COMMENT_RE.test(previous.text);
|
|
7709
|
+
}
|
|
7710
|
+
function removeTailwindContainerWidthRules(root, options = {}) {
|
|
7711
|
+
root.walkRules((rule) => {
|
|
7712
|
+
if (!isContainerWidthOnlyRule(rule)) return;
|
|
7713
|
+
if (options.generatedOnly && !isTailwindGeneratedContainerRule(rule)) return;
|
|
7714
|
+
const parent = rule.parent;
|
|
7715
|
+
if (isTailwindGeneratedContainerRule(rule)) rule.prev()?.remove();
|
|
7716
|
+
rule.remove();
|
|
7717
|
+
removeEmptyAtRuleAncestors(parent);
|
|
7718
|
+
});
|
|
7719
|
+
}
|
|
7720
|
+
function removeUnsupportedModernColorDeclarations(root) {
|
|
7721
|
+
const customPropertyValues = /* @__PURE__ */ new Map();
|
|
7722
|
+
root.walkDecls((decl) => {
|
|
7723
|
+
if (decl.prop.startsWith("--")) customPropertyValues.set(decl.prop, decl.value.trim());
|
|
7724
|
+
});
|
|
7725
|
+
root.walkDecls((decl) => {
|
|
7726
|
+
const normalized = normalizeModernColorValue(decl.value, customPropertyValues);
|
|
7727
|
+
if (normalized.changed) {
|
|
7728
|
+
decl.value = normalized.value;
|
|
7729
|
+
if (decl.prop.startsWith("--")) customPropertyValues.set(decl.prop, decl.value.trim());
|
|
7730
|
+
}
|
|
7731
|
+
if (normalized.hasUnsupported) removeDeclarationAndEmptyRule$1(decl);
|
|
7732
|
+
});
|
|
7733
|
+
}
|
|
7734
|
+
//#endregion
|
|
7735
|
+
//#region src/compat/mini-program-css/theme.ts
|
|
7555
7736
|
function collectThemeVariableRule(root, options = {}) {
|
|
7556
7737
|
const themeRules = [];
|
|
7557
7738
|
const declarations = /* @__PURE__ */ new Map();
|
|
@@ -7571,95 +7752,8 @@ function collectThemeVariableRule(root, options = {}) {
|
|
|
7571
7752
|
for (const decl of declarations.values()) rule.append(decl);
|
|
7572
7753
|
return rule;
|
|
7573
7754
|
}
|
|
7574
|
-
|
|
7575
|
-
|
|
7576
|
-
const root = postcss.parse(css);
|
|
7577
|
-
let hasProperty = false;
|
|
7578
|
-
root.walkAtRules("property", (atRule) => {
|
|
7579
|
-
if (atRule.params.trim().startsWith("--tw-")) {
|
|
7580
|
-
hasProperty = true;
|
|
7581
|
-
return false;
|
|
7582
|
-
}
|
|
7583
|
-
});
|
|
7584
|
-
return hasProperty;
|
|
7585
|
-
}
|
|
7586
|
-
function getTopDirectiveTail(root) {
|
|
7587
|
-
let tail;
|
|
7588
|
-
for (const node of root.nodes ?? []) {
|
|
7589
|
-
if (node.type === "atrule" && (node.name === "charset" || node.name === "import")) {
|
|
7590
|
-
tail = node;
|
|
7591
|
-
continue;
|
|
7592
|
-
}
|
|
7593
|
-
break;
|
|
7594
|
-
}
|
|
7595
|
-
return tail;
|
|
7596
|
-
}
|
|
7597
|
-
function createHoistInsertionAnchor(root) {
|
|
7598
|
-
for (const node of root.nodes ?? []) if (isMiniProgramPreflightRule(node) || isMiniProgramThemeVariableRule(node)) {
|
|
7599
|
-
const anchor = postcss.comment({ text: HOIST_ANCHOR_COMMENT });
|
|
7600
|
-
node.before(anchor);
|
|
7601
|
-
return anchor;
|
|
7602
|
-
}
|
|
7603
|
-
}
|
|
7604
|
-
function insertHoistedRules(root, rules, anchor) {
|
|
7605
|
-
if (anchor && !anchor.parent) anchor = void 0;
|
|
7606
|
-
if (rules.length === 0) {
|
|
7607
|
-
anchor?.remove();
|
|
7608
|
-
return;
|
|
7609
|
-
}
|
|
7610
|
-
const topDirectiveTail = getTopDirectiveTail(root);
|
|
7611
|
-
const firstRule = rules[0];
|
|
7612
|
-
if (!firstRule) return;
|
|
7613
|
-
if (anchor) {
|
|
7614
|
-
if (anchor.raws.before === void 0) delete firstRule.raws.before;
|
|
7615
|
-
else firstRule.raws.before = anchor.raws.before;
|
|
7616
|
-
anchor.replaceWith(rules);
|
|
7617
|
-
return;
|
|
7618
|
-
}
|
|
7619
|
-
firstRule.raws.before = topDirectiveTail ? "\n" : "";
|
|
7620
|
-
if (topDirectiveTail) topDirectiveTail.after(rules);
|
|
7621
|
-
else root.prepend(rules);
|
|
7622
|
-
}
|
|
7623
|
-
function mergeEquivalentHoistedRules(rules) {
|
|
7624
|
-
const mergedRules = [];
|
|
7625
|
-
const ruleBySelector = /* @__PURE__ */ new Map();
|
|
7626
|
-
const propsBySelector = /* @__PURE__ */ new Map();
|
|
7627
|
-
for (const rule of rules) {
|
|
7628
|
-
const key = getSortedRuleSelectorKey(rule);
|
|
7629
|
-
const existingRule = ruleBySelector.get(key);
|
|
7630
|
-
if (existingRule) {
|
|
7631
|
-
const existingProps = propsBySelector.get(key) ?? /* @__PURE__ */ new Set();
|
|
7632
|
-
const nextNodes = (rule.nodes ?? []).filter((node) => {
|
|
7633
|
-
if (node.type !== "decl") return true;
|
|
7634
|
-
if (existingProps.has(node.prop)) return false;
|
|
7635
|
-
existingProps.add(node.prop);
|
|
7636
|
-
return true;
|
|
7637
|
-
});
|
|
7638
|
-
existingRule.append(...nextNodes.map((node) => node.clone()));
|
|
7639
|
-
propsBySelector.set(key, existingProps);
|
|
7640
|
-
continue;
|
|
7641
|
-
}
|
|
7642
|
-
ruleBySelector.set(key, rule);
|
|
7643
|
-
propsBySelector.set(key, new Set((rule.nodes ?? []).flatMap((node) => node.type === "decl" ? [node.prop] : [])));
|
|
7644
|
-
mergedRules.push(rule);
|
|
7645
|
-
}
|
|
7646
|
-
return mergedRules;
|
|
7647
|
-
}
|
|
7648
|
-
function unwrapTailwindSourceMedia(root) {
|
|
7649
|
-
root.walkAtRules("media", (atRule) => {
|
|
7650
|
-
if (!atRule.params.startsWith("source(")) return;
|
|
7651
|
-
if (atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
|
|
7652
|
-
else atRule.remove();
|
|
7653
|
-
});
|
|
7654
|
-
}
|
|
7655
|
-
function removeTailwindGenerationDirectives(root) {
|
|
7656
|
-
root.walkComments((comment) => {
|
|
7657
|
-
if (GENERATOR_PLACEHOLDER_COMMENT_RE.test(comment.text)) comment.remove();
|
|
7658
|
-
});
|
|
7659
|
-
root.walkAtRules((atRule) => {
|
|
7660
|
-
if (atRule.name === "config" || atRule.name === "source" || atRule.name === "tailwind" || atRule.name === "reference" || atRule.name === "plugin") atRule.remove();
|
|
7661
|
-
});
|
|
7662
|
-
}
|
|
7755
|
+
//#endregion
|
|
7756
|
+
//#region src/compat/mini-program-css/finalize.ts
|
|
7663
7757
|
function finalizeMiniProgramCssRoot(root, options = {}) {
|
|
7664
7758
|
const shouldInjectTailwindcssV4Defaults = options.isTailwindcssV4 === true;
|
|
7665
7759
|
const tailwindcssV4DefaultNodes = shouldInjectTailwindcssV4Defaults ? createMissingCssVarsV4Nodes(root, collectUsedTailwindcssV4Variables(root)) : [];
|
|
@@ -7672,6 +7766,8 @@ function finalizeMiniProgramCssRoot(root, options = {}) {
|
|
|
7672
7766
|
removeSpecificityPlaceholders(root);
|
|
7673
7767
|
removeUnsupportedBrowserSelectors(root);
|
|
7674
7768
|
removeDisplayP3Declarations(root);
|
|
7769
|
+
removeTailwindContainerMaxWidthMediaRules(root);
|
|
7770
|
+
removeTailwindContainerWidthRules(root, { generatedOnly: true });
|
|
7675
7771
|
removeUnsupportedModernColorDeclarations(root);
|
|
7676
7772
|
root.walkDecls((decl) => {
|
|
7677
7773
|
if (shouldInjectTailwindcssV4Defaults) normalizeTailwindcssV4Declaration(decl);
|
|
@@ -7692,6 +7788,7 @@ function finalizeMiniProgramCssRoot(root, options = {}) {
|
|
|
7692
7788
|
}));
|
|
7693
7789
|
const themeRule = collectThemeVariableRule(root, options);
|
|
7694
7790
|
insertHoistedRules(root, mergeEquivalentHoistedRules(themeRule ? [...preflightRules, themeRule] : preflightRules), hoistAnchor);
|
|
7791
|
+
removeEmptyAtRules(root);
|
|
7695
7792
|
}
|
|
7696
7793
|
function hoistTailwindPreflightBase(css) {
|
|
7697
7794
|
try {
|
|
@@ -7724,6 +7821,7 @@ function finalizeMiniProgramCss(css, options = {}) {
|
|
|
7724
7821
|
//#endregion
|
|
7725
7822
|
//#region src/compat/mini-program-css/prune-generated.ts
|
|
7726
7823
|
const DEFAULT_WEAPP_VARIABLE_SCOPE = "page,.tw-root,wx-root-portal-content,:host";
|
|
7824
|
+
const MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR = "::before,\n::after";
|
|
7727
7825
|
const CLASS_SELECTOR_RE$1 = /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i;
|
|
7728
7826
|
function isConditionalCompilationComment(text) {
|
|
7729
7827
|
return /#(?:ifn?def|endif)\b/.test(text);
|
|
@@ -7740,6 +7838,23 @@ function isMiniProgramElementVariableScopeRule(rule) {
|
|
|
7740
7838
|
const selectors = getRuleSelectors(rule);
|
|
7741
7839
|
return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS.has(selector));
|
|
7742
7840
|
}
|
|
7841
|
+
function isOnlyTwContentDeclarations(rule) {
|
|
7842
|
+
let hasDeclaration = false;
|
|
7843
|
+
let onlyContentVariable = true;
|
|
7844
|
+
rule.walkDecls((decl) => {
|
|
7845
|
+
hasDeclaration = true;
|
|
7846
|
+
if (decl.prop !== "--tw-content") onlyContentVariable = false;
|
|
7847
|
+
});
|
|
7848
|
+
return hasDeclaration && onlyContentVariable;
|
|
7849
|
+
}
|
|
7850
|
+
function isMiniProgramElementContentInitRule(rule) {
|
|
7851
|
+
if (!isMiniProgramElementVariableScopeRule(rule)) return false;
|
|
7852
|
+
let hasElementSelector = false;
|
|
7853
|
+
let hasPseudoSelector = false;
|
|
7854
|
+
for (const selector of getRuleSelectors(rule)) if (selector === "view" || selector === "text") hasElementSelector = true;
|
|
7855
|
+
else if (selector === "::before" || selector === "::after") hasPseudoSelector = true;
|
|
7856
|
+
return hasElementSelector && hasPseudoSelector && isOnlyTwContentDeclarations(rule);
|
|
7857
|
+
}
|
|
7743
7858
|
function isTailwindV4GradientRuntimeDeclaration(decl) {
|
|
7744
7859
|
return decl.prop.startsWith("--tw-gradient-");
|
|
7745
7860
|
}
|
|
@@ -7777,6 +7892,8 @@ function pruneMiniProgramGeneratedCss(css, options = {}) {
|
|
|
7777
7892
|
});
|
|
7778
7893
|
removeUnsupportedCascadeLayers(root);
|
|
7779
7894
|
removeUnsupportedModernColorDeclarations(root);
|
|
7895
|
+
removeTailwindContainerMaxWidthMediaRules(root);
|
|
7896
|
+
removeTailwindContainerWidthRules(root);
|
|
7780
7897
|
root.walkAtRules("supports", (atRule) => {
|
|
7781
7898
|
atRule.remove();
|
|
7782
7899
|
});
|
|
@@ -7788,6 +7905,18 @@ function pruneMiniProgramGeneratedCss(css, options = {}) {
|
|
|
7788
7905
|
});
|
|
7789
7906
|
root.walkRules((rule) => {
|
|
7790
7907
|
if (isKeyframesRule(rule)) return;
|
|
7908
|
+
if (isPseudoContentInitRule(rule)) {
|
|
7909
|
+
if (!shouldPreserveContentInit) rule.remove();
|
|
7910
|
+
return;
|
|
7911
|
+
}
|
|
7912
|
+
if (isMiniProgramElementContentInitRule(rule)) {
|
|
7913
|
+
if (!shouldPreserveContentInit) {
|
|
7914
|
+
rule.remove();
|
|
7915
|
+
return;
|
|
7916
|
+
}
|
|
7917
|
+
rule.selector = MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR;
|
|
7918
|
+
return;
|
|
7919
|
+
}
|
|
7791
7920
|
if (isCustomPropertyRule(rule) && isMiniProgramElementVariableScopeRule(rule)) {
|
|
7792
7921
|
rule.selector = MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR;
|
|
7793
7922
|
return;
|
|
@@ -7800,10 +7929,6 @@ function pruneMiniProgramGeneratedCss(css, options = {}) {
|
|
|
7800
7929
|
}
|
|
7801
7930
|
if (hasClassSelector$2(rule.selector)) return;
|
|
7802
7931
|
if (!shouldPreserveContentInit) removeEmptyContentInitDeclarations(rule);
|
|
7803
|
-
if (isPseudoContentInitRule(rule)) {
|
|
7804
|
-
if (!shouldPreserveContentInit) rule.remove();
|
|
7805
|
-
return;
|
|
7806
|
-
}
|
|
7807
7932
|
if (options.preservePreflight && isMiniProgramPreflightRule(rule)) return;
|
|
7808
7933
|
if (isCustomPropertyRule(rule)) {
|
|
7809
7934
|
moveTailwindV4GradientRuntimeDeclarations(rule);
|
|
@@ -43158,7 +43283,7 @@ const n$9 = "js-blank-pseudo", t$12 = ":blank", creator$48 = (s) => {
|
|
|
43158
43283
|
};
|
|
43159
43284
|
creator$48.postcss = !0;
|
|
43160
43285
|
//#endregion
|
|
43161
|
-
//#region ../../node_modules/.pnpm/@csstools+selector-specificity@6.0.0_postcss-selector-parser@7.1.
|
|
43286
|
+
//#region ../../node_modules/.pnpm/@csstools+selector-specificity@6.0.0_postcss-selector-parser@7.1.2/node_modules/@csstools/selector-specificity/dist/index.mjs
|
|
43162
43287
|
var import_postcss_page_break = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
43163
43288
|
module.exports = function(options) {
|
|
43164
43289
|
return {
|
|
@@ -49953,7 +50078,7 @@ const creator$18 = (s) => {
|
|
|
49953
50078
|
};
|
|
49954
50079
|
creator$18.postcss = !0;
|
|
49955
50080
|
//#endregion
|
|
49956
|
-
//#region ../../node_modules/.pnpm/@csstools+selector-resolve-nested@4.0.0_postcss-selector-parser@7.1.
|
|
50081
|
+
//#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
|
|
49957
50082
|
function sourceFrom(e) {
|
|
49958
50083
|
return {
|
|
49959
50084
|
sourceIndex: e.sourceIndex ?? 0,
|
|
@@ -53161,10 +53286,7 @@ function normalizeSpacingDeclarations(rule) {
|
|
|
53161
53286
|
for (const declarations of grouped.values()) dedupeSpacingGroup(rule, declarations);
|
|
53162
53287
|
}
|
|
53163
53288
|
//#endregion
|
|
53164
|
-
//#region src/selectorParser/rule-transformer.ts
|
|
53165
|
-
const ruleTransformCache = /* @__PURE__ */ new WeakMap();
|
|
53166
|
-
const SELECTOR_TRANSFORM_OPTIONS = normalizeTransformOptions();
|
|
53167
|
-
const SIMPLE_SELECTOR_FAST_PATH = /^[#.][\w-]+(?:\s+[#.][\w-]+)*$/;
|
|
53289
|
+
//#region src/selectorParser/rule-transformer/pseudos.ts
|
|
53168
53290
|
const RTL_LANGUAGE_ANY_PSEUDO_SET = new Set([
|
|
53169
53291
|
":-moz-any",
|
|
53170
53292
|
":-webkit-any",
|
|
@@ -53180,6 +53302,23 @@ const EMPTY_FUNCTIONAL_PSEUDO_CLEANUP_SET = new Set([
|
|
|
53180
53302
|
":-moz-any",
|
|
53181
53303
|
":lang"
|
|
53182
53304
|
]);
|
|
53305
|
+
const UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET = new Set([
|
|
53306
|
+
":after",
|
|
53307
|
+
":before",
|
|
53308
|
+
"::after",
|
|
53309
|
+
"::before",
|
|
53310
|
+
"::backdrop",
|
|
53311
|
+
"::-ms-backdrop",
|
|
53312
|
+
"::-webkit-backdrop",
|
|
53313
|
+
"::file-selector-button"
|
|
53314
|
+
]);
|
|
53315
|
+
const MINI_PROGRAM_UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET = new Set([
|
|
53316
|
+
"::backdrop",
|
|
53317
|
+
"::-ms-backdrop",
|
|
53318
|
+
"::-webkit-backdrop",
|
|
53319
|
+
"::file-selector-button"
|
|
53320
|
+
]);
|
|
53321
|
+
const NORMALIZED_PSEUDO_ELEMENT_SELECTOR = new Map([[":before", "::before"], [":after", "::after"]]);
|
|
53183
53322
|
function isRtlLanguageAnyPseudo(node) {
|
|
53184
53323
|
return node.type === "pseudo" && RTL_LANGUAGE_ANY_PSEUDO_SET.has(node.value);
|
|
53185
53324
|
}
|
|
@@ -53216,6 +53355,29 @@ function flattenWherePseudo(node, context, index, parent) {
|
|
|
53216
53355
|
if (parent && parent.type === "selector" && parent.length === 0) parent.remove();
|
|
53217
53356
|
}
|
|
53218
53357
|
}
|
|
53358
|
+
function shouldRemoveUnsupportedPseudoElementSelector(selector, options) {
|
|
53359
|
+
if (!isUniAppXEnabled(options)) return selector.nodes.some((node) => node.type === "pseudo" && MINI_PROGRAM_UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
|
|
53360
|
+
return selector.nodes.some((node) => node.type === "pseudo" && UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
|
|
53361
|
+
}
|
|
53362
|
+
function handlePseudoNode(node, index, context, parent) {
|
|
53363
|
+
if (node.type !== "pseudo") return;
|
|
53364
|
+
if (isRtlLanguageAnyPseudo(node)) {
|
|
53365
|
+
stripUnsupportedRtlLanguagePseudo(node);
|
|
53366
|
+
return;
|
|
53367
|
+
}
|
|
53368
|
+
if (node.value === ":root" && context.rootReplacement) {
|
|
53369
|
+
node.value = context.rootReplacement;
|
|
53370
|
+
return;
|
|
53371
|
+
}
|
|
53372
|
+
const normalizedPseudoElement = NORMALIZED_PSEUDO_ELEMENT_SELECTOR.get(node.value);
|
|
53373
|
+
if (normalizedPseudoElement) {
|
|
53374
|
+
node.value = normalizedPseudoElement;
|
|
53375
|
+
return;
|
|
53376
|
+
}
|
|
53377
|
+
if (node.value === ":where") flattenWherePseudo(node, context, index, parent);
|
|
53378
|
+
}
|
|
53379
|
+
//#endregion
|
|
53380
|
+
//#region src/selectorParser/rule-transformer/nodes.ts
|
|
53219
53381
|
function handleClassNode(node, context) {
|
|
53220
53382
|
if (node.type !== "class") return;
|
|
53221
53383
|
node.value = context.selectorReplacerOptions === void 0 ? internalCssSelectorReplacer(node.value) : internalCssSelectorReplacer(node.value, context.selectorReplacerOptions);
|
|
@@ -53228,27 +53390,6 @@ function shouldRemoveHoverSelector(selector, options) {
|
|
|
53228
53390
|
if (!options.cssRemoveHoverPseudoClass) return false;
|
|
53229
53391
|
return selector.nodes.some((node) => node.type === "pseudo" && node.value === ":hover");
|
|
53230
53392
|
}
|
|
53231
|
-
const UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET = new Set([
|
|
53232
|
-
":after",
|
|
53233
|
-
":before",
|
|
53234
|
-
"::after",
|
|
53235
|
-
"::before",
|
|
53236
|
-
"::backdrop",
|
|
53237
|
-
"::-ms-backdrop",
|
|
53238
|
-
"::-webkit-backdrop",
|
|
53239
|
-
"::file-selector-button"
|
|
53240
|
-
]);
|
|
53241
|
-
const MINI_PROGRAM_UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET = new Set([
|
|
53242
|
-
"::backdrop",
|
|
53243
|
-
"::-ms-backdrop",
|
|
53244
|
-
"::-webkit-backdrop",
|
|
53245
|
-
"::file-selector-button"
|
|
53246
|
-
]);
|
|
53247
|
-
const NORMALIZED_PSEUDO_ELEMENT_SELECTOR = new Map([[":before", "::before"], [":after", "::after"]]);
|
|
53248
|
-
function shouldRemoveUnsupportedPseudoElementSelector(selector, options) {
|
|
53249
|
-
if (!isUniAppXEnabled(options)) return selector.nodes.some((node) => node.type === "pseudo" && MINI_PROGRAM_UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
|
|
53250
|
-
return selector.nodes.some((node) => node.type === "pseudo" && UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
|
|
53251
|
-
}
|
|
53252
53393
|
function isHiddenOrTemplateNotPseudo(node) {
|
|
53253
53394
|
if (!node || node.type !== "pseudo" || node.value !== ":not") return false;
|
|
53254
53395
|
const selector = node.first;
|
|
@@ -53271,23 +53412,6 @@ function handleCombinatorNode(node, index, context) {
|
|
|
53271
53412
|
nodes.splice(index + 1, 3, ...ast);
|
|
53272
53413
|
}
|
|
53273
53414
|
}
|
|
53274
|
-
function handlePseudoNode(node, index, context, parent) {
|
|
53275
|
-
if (node.type !== "pseudo") return;
|
|
53276
|
-
if (isRtlLanguageAnyPseudo(node)) {
|
|
53277
|
-
stripUnsupportedRtlLanguagePseudo(node);
|
|
53278
|
-
return;
|
|
53279
|
-
}
|
|
53280
|
-
if (node.value === ":root" && context.rootReplacement) {
|
|
53281
|
-
node.value = context.rootReplacement;
|
|
53282
|
-
return;
|
|
53283
|
-
}
|
|
53284
|
-
const normalizedPseudoElement = NORMALIZED_PSEUDO_ELEMENT_SELECTOR.get(node.value);
|
|
53285
|
-
if (normalizedPseudoElement) {
|
|
53286
|
-
node.value = normalizedPseudoElement;
|
|
53287
|
-
return;
|
|
53288
|
-
}
|
|
53289
|
-
if (node.value === ":where") flattenWherePseudo(node, context, index, parent);
|
|
53290
|
-
}
|
|
53291
53415
|
function handleTagOrAttribute(node, context) {
|
|
53292
53416
|
stripUnsupportedNodeForUniAppX(node, context.options);
|
|
53293
53417
|
}
|
|
@@ -53302,6 +53426,11 @@ function handleSelectorNode(selector, context) {
|
|
|
53302
53426
|
}
|
|
53303
53427
|
if (transformSpacingSelector(selector.nodes, context.options)) context.requiresSpacingNormalization = true;
|
|
53304
53428
|
}
|
|
53429
|
+
//#endregion
|
|
53430
|
+
//#region src/selectorParser/rule-transformer.ts
|
|
53431
|
+
const ruleTransformCache = /* @__PURE__ */ new WeakMap();
|
|
53432
|
+
const SELECTOR_TRANSFORM_OPTIONS = normalizeTransformOptions();
|
|
53433
|
+
const SIMPLE_SELECTOR_FAST_PATH = /^[#.][\w-]+(?:\s+[#.][\w-]+)*$/;
|
|
53305
53434
|
function canSkipRuleTransform(rule) {
|
|
53306
53435
|
const selector = rule.selector.trim();
|
|
53307
53436
|
if (!selector) return false;
|
|
@@ -54082,11 +54211,46 @@ function makePseudoVarRule() {
|
|
|
54082
54211
|
function isEmptyContentInitDeclaration(decl) {
|
|
54083
54212
|
return decl.prop === "--tw-content" && (decl.value === "\"\"" || decl.value === "''");
|
|
54084
54213
|
}
|
|
54214
|
+
function isPseudoContentInitSelector(selector) {
|
|
54215
|
+
return selector === ":before" || selector === ":after" || selector === "::before" || selector === "::after";
|
|
54216
|
+
}
|
|
54217
|
+
function isElementContentInitSelector(selector) {
|
|
54218
|
+
return selector === "*" || selector === "view" || selector === "text";
|
|
54219
|
+
}
|
|
54220
|
+
function isOnlyEmptyContentInitRule(node) {
|
|
54221
|
+
let hasDeclaration = false;
|
|
54222
|
+
let onlyEmptyContentInit = true;
|
|
54223
|
+
node.walkDecls((decl) => {
|
|
54224
|
+
hasDeclaration = true;
|
|
54225
|
+
if (!isEmptyContentInitDeclaration(decl)) onlyEmptyContentInit = false;
|
|
54226
|
+
});
|
|
54227
|
+
return hasDeclaration && onlyEmptyContentInit;
|
|
54228
|
+
}
|
|
54229
|
+
function restorePseudoContentInitScope(node) {
|
|
54230
|
+
if (!isOnlyEmptyContentInitRule(node)) return false;
|
|
54231
|
+
let hasPseudoSelector = false;
|
|
54232
|
+
let hasElementSelector = false;
|
|
54233
|
+
for (const selector of node.selectors) if (isPseudoContentInitSelector(selector)) hasPseudoSelector = true;
|
|
54234
|
+
else if (isElementContentInitSelector(selector)) hasElementSelector = true;
|
|
54235
|
+
else return false;
|
|
54236
|
+
if (!hasPseudoSelector || !hasElementSelector) return false;
|
|
54237
|
+
assignRuleSelectors(node, ["::before", "::after"], {
|
|
54238
|
+
phase: "pre",
|
|
54239
|
+
reason: "restore-pseudo-content-init-scope"
|
|
54240
|
+
});
|
|
54241
|
+
return true;
|
|
54242
|
+
}
|
|
54085
54243
|
function removeTailwindV4EmptyContentInit(node) {
|
|
54086
54244
|
node.walkDecls((decl) => {
|
|
54087
54245
|
if (isEmptyContentInitDeclaration(decl)) decl.remove();
|
|
54088
54246
|
});
|
|
54089
54247
|
}
|
|
54248
|
+
function injectPreflightDeclarations(node, options) {
|
|
54249
|
+
const preflightDeclarations = options.cssInjectPreflight?.();
|
|
54250
|
+
if (!preflightDeclarations || preflightDeclarations.length === 0) return;
|
|
54251
|
+
node.prepend(...preflightDeclarations);
|
|
54252
|
+
node.raws.semicolon = true;
|
|
54253
|
+
}
|
|
54090
54254
|
function hasClassSelector(node) {
|
|
54091
54255
|
return node.selectors.some((selector) => selector.includes("."));
|
|
54092
54256
|
}
|
|
@@ -54112,7 +54276,7 @@ function resolveUniAppXVariableScopeSelectors(options) {
|
|
|
54112
54276
|
return ["view", "text"];
|
|
54113
54277
|
}
|
|
54114
54278
|
function commonChunkPreflight(node, options) {
|
|
54115
|
-
const { ctx,
|
|
54279
|
+
const { ctx, injectAdditionalCssVarScope } = options;
|
|
54116
54280
|
const uniAppXEnabled = isUniAppXEnabled(options);
|
|
54117
54281
|
const isTailwindcss4 = isTailwindcssV4(options);
|
|
54118
54282
|
const rootOption = options.cssSelectorReplacement?.root;
|
|
@@ -54125,6 +54289,7 @@ function commonChunkPreflight(node, options) {
|
|
|
54125
54289
|
reason: "append-host-selector"
|
|
54126
54290
|
});
|
|
54127
54291
|
if (isTailwindcss4 && !usesTailwindcssV4ContentVariable(node.root()) && (!hasClassSelector(node) || isRootThemeScopeRule(node))) removeTailwindV4EmptyContentInit(node);
|
|
54292
|
+
if (!isTailwindcss4 && restorePseudoContentInitScope(node)) return;
|
|
54128
54293
|
if (testIfVariablesScope(node) || uniAppXEnabled && node.selectors.includes("*") && hasTwVars(node, 2)) {
|
|
54129
54294
|
ctx?.markVariablesScope(node);
|
|
54130
54295
|
assignRuleSelectors(node, uniAppXEnabled ? resolveUniAppXVariableScopeSelectors(options) : remakeCssVarSelector(node.selectors, options), {
|
|
@@ -54132,7 +54297,7 @@ function commonChunkPreflight(node, options) {
|
|
|
54132
54297
|
reason: "rewrite-variable-scope"
|
|
54133
54298
|
});
|
|
54134
54299
|
if (!uniAppXEnabled && !isTailwindcss4) node.before(makePseudoVarRule());
|
|
54135
|
-
|
|
54300
|
+
injectPreflightDeclarations(node, options);
|
|
54136
54301
|
}
|
|
54137
54302
|
if (injectAdditionalCssVarScope && (isTailwindcss4 ? testIfRootHostForV4(node) : testIfTwBackdrop(node))) {
|
|
54138
54303
|
const nodes = isTailwindcss4 ? createUsedCssVarsV4Nodes(collectUsedTailwindcssV4Variables(node.root())) : cssVarsV3Nodes;
|
|
@@ -54151,7 +54316,7 @@ function commonChunkPreflight(node, options) {
|
|
|
54151
54316
|
});
|
|
54152
54317
|
node.before(syntheticRule);
|
|
54153
54318
|
if (!uniAppXEnabled && !isTailwindcss4) node.before(makePseudoVarRule());
|
|
54154
|
-
|
|
54319
|
+
injectPreflightDeclarations(syntheticRule, options);
|
|
54155
54320
|
}
|
|
54156
54321
|
}
|
|
54157
54322
|
//#endregion
|