@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.js
CHANGED
|
@@ -25,6 +25,38 @@ node_process = require_html_transform.__toESM(node_process);
|
|
|
25
25
|
let postcss_rule_unit_converter = require("postcss-rule-unit-converter");
|
|
26
26
|
postcss_rule_unit_converter = require_html_transform.__toESM(postcss_rule_unit_converter);
|
|
27
27
|
let _weapp_core_escape = require("@weapp-core/escape");
|
|
28
|
+
const MODERN_COLOR_FUNCTION_NAMES = new Set([
|
|
29
|
+
"oklch",
|
|
30
|
+
"oklab",
|
|
31
|
+
"lch",
|
|
32
|
+
"lab"
|
|
33
|
+
]);
|
|
34
|
+
const PLACEHOLDER_PREFIX = "__weapp_tw_color_mix_";
|
|
35
|
+
const DYNAMIC_ALPHA_RE = /\b(?:var|env)\(|--[\w-]+\b/;
|
|
36
|
+
const INTERNAL_TAILWIND_ALPHA_RE = /var\(\s*--tw-[^)]+-alpha\s*\)/;
|
|
37
|
+
const TRANSPARENT_COLOR_RE = /^transparent$/i;
|
|
38
|
+
const CURRENT_COLOR_RE = /^currentcolor$/i;
|
|
39
|
+
const CSS_WIDE_KEYWORD_RE = /^(?:inherit|initial|unset|revert|revert-layer)$/i;
|
|
40
|
+
const CUSTOM_PROPERTY_RE = /^--[\w-]+$/;
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/compat/color-mix/modern.ts
|
|
43
|
+
function isDisplayP3ColorFunction(colorSource) {
|
|
44
|
+
return /^color\(\s*display-p3\b/i.test(colorSource.trim());
|
|
45
|
+
}
|
|
46
|
+
function hasUnsupportedModernColorFunction(value) {
|
|
47
|
+
const parsed = (0, postcss_value_parser.default)(value);
|
|
48
|
+
let hasUnsupported = false;
|
|
49
|
+
parsed.walk((node) => {
|
|
50
|
+
if (node.type !== "function") return;
|
|
51
|
+
const name = node.value.toLowerCase();
|
|
52
|
+
if (name === "color-mix" || MODERN_COLOR_FUNCTION_NAMES.has(name) || name === "color" && isDisplayP3ColorFunction(postcss_value_parser.default.stringify(node))) {
|
|
53
|
+
hasUnsupported = true;
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return hasUnsupported;
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
28
60
|
//#region ../../node_modules/.pnpm/@csstools+css-tokenizer@4.0.0/node_modules/@csstools/css-tokenizer/dist/index.mjs
|
|
29
61
|
var ParseError$1 = class extends Error {
|
|
30
62
|
sourceStart;
|
|
@@ -6524,21 +6556,7 @@ function color(e) {
|
|
|
6524
6556
|
return !1;
|
|
6525
6557
|
}
|
|
6526
6558
|
//#endregion
|
|
6527
|
-
//#region src/compat/color-mix.ts
|
|
6528
|
-
const COLOR_MIX_NAME = "color-mix";
|
|
6529
|
-
const MODERN_COLOR_FUNCTION_NAMES = new Set([
|
|
6530
|
-
"oklch",
|
|
6531
|
-
"oklab",
|
|
6532
|
-
"lch",
|
|
6533
|
-
"lab"
|
|
6534
|
-
]);
|
|
6535
|
-
const PLACEHOLDER_PREFIX = "__weapp_tw_color_mix_";
|
|
6536
|
-
const DYNAMIC_ALPHA_RE = /\b(?:var|env)\(|--[\w-]+\b/;
|
|
6537
|
-
const INTERNAL_TAILWIND_ALPHA_RE = /var\(\s*--tw-[^)]+-alpha\s*\)/;
|
|
6538
|
-
const TRANSPARENT_COLOR_RE = /^transparent$/i;
|
|
6539
|
-
const CURRENT_COLOR_RE = /^currentcolor$/i;
|
|
6540
|
-
const CSS_WIDE_KEYWORD_RE = /^(?:inherit|initial|unset|revert|revert-layer)$/i;
|
|
6541
|
-
const CUSTOM_PROPERTY_RE = /^--[\w-]+$/;
|
|
6559
|
+
//#region src/compat/color-mix/parse.ts
|
|
6542
6560
|
function splitArguments(nodes) {
|
|
6543
6561
|
const args = [];
|
|
6544
6562
|
let current = [];
|
|
@@ -6621,51 +6639,8 @@ function normalizeStandaloneColorFunction(colorSource) {
|
|
|
6621
6639
|
const resolvedColor = getParsedColorData(colorSource);
|
|
6622
6640
|
return resolvedColor ? serializeRGB(resolvedColor).toString() : void 0;
|
|
6623
6641
|
}
|
|
6624
|
-
|
|
6625
|
-
|
|
6626
|
-
}
|
|
6627
|
-
function hasUnsupportedModernColorFunction(value) {
|
|
6628
|
-
const parsed = (0, postcss_value_parser.default)(value);
|
|
6629
|
-
let hasUnsupported = false;
|
|
6630
|
-
parsed.walk((node) => {
|
|
6631
|
-
if (node.type !== "function") return;
|
|
6632
|
-
const name = node.value.toLowerCase();
|
|
6633
|
-
if (name === COLOR_MIX_NAME || MODERN_COLOR_FUNCTION_NAMES.has(name) || name === "color" && isDisplayP3ColorFunction(postcss_value_parser.default.stringify(node))) {
|
|
6634
|
-
hasUnsupported = true;
|
|
6635
|
-
return false;
|
|
6636
|
-
}
|
|
6637
|
-
});
|
|
6638
|
-
return hasUnsupported;
|
|
6639
|
-
}
|
|
6640
|
-
function normalizeModernColorValue(value, customPropertyValues = /* @__PURE__ */ new Map()) {
|
|
6641
|
-
if (!hasUnsupportedModernColorFunction(value)) return {
|
|
6642
|
-
value,
|
|
6643
|
-
changed: false,
|
|
6644
|
-
hasUnsupported: false
|
|
6645
|
-
};
|
|
6646
|
-
const parsed = (0, postcss_value_parser.default)(value);
|
|
6647
|
-
let changed = false;
|
|
6648
|
-
parsed.walk((node) => {
|
|
6649
|
-
if (node.type !== "function") return;
|
|
6650
|
-
const name = node.value.toLowerCase();
|
|
6651
|
-
const source = postcss_value_parser.default.stringify(node);
|
|
6652
|
-
let normalized;
|
|
6653
|
-
if (MODERN_COLOR_FUNCTION_NAMES.has(name) || name === "color" && isDisplayP3ColorFunction(source)) normalized = normalizeStandaloneColorFunction(source);
|
|
6654
|
-
else if (name === COLOR_MIX_NAME) normalized = tryResolveColorMix(node, customPropertyValues)?.value;
|
|
6655
|
-
if (!normalized) return;
|
|
6656
|
-
const mutableNode = node;
|
|
6657
|
-
mutableNode.type = "word";
|
|
6658
|
-
mutableNode.value = normalized;
|
|
6659
|
-
delete mutableNode.nodes;
|
|
6660
|
-
changed = true;
|
|
6661
|
-
});
|
|
6662
|
-
const nextValue = changed ? parsed.toString() : value;
|
|
6663
|
-
return {
|
|
6664
|
-
value: nextValue,
|
|
6665
|
-
changed,
|
|
6666
|
-
hasUnsupported: hasUnsupportedModernColorFunction(nextValue)
|
|
6667
|
-
};
|
|
6668
|
-
}
|
|
6642
|
+
//#endregion
|
|
6643
|
+
//#region src/compat/color-mix/resolve.ts
|
|
6669
6644
|
function createRgbaWithAlpha(colorSource, alphaSource, customPropertyValues) {
|
|
6670
6645
|
const resolvedColor = resolveColorData(colorSource, customPropertyValues);
|
|
6671
6646
|
if (!resolvedColor) return;
|
|
@@ -6711,17 +6686,48 @@ function tryResolveColorMix(node, customPropertyValues) {
|
|
|
6711
6686
|
deferred: false
|
|
6712
6687
|
};
|
|
6713
6688
|
}
|
|
6689
|
+
//#endregion
|
|
6690
|
+
//#region src/compat/color-mix.ts
|
|
6691
|
+
function normalizeModernColorValue(value, customPropertyValues = /* @__PURE__ */ new Map()) {
|
|
6692
|
+
if (!hasUnsupportedModernColorFunction(value)) return {
|
|
6693
|
+
value,
|
|
6694
|
+
changed: false,
|
|
6695
|
+
hasUnsupported: false
|
|
6696
|
+
};
|
|
6697
|
+
const parsed = (0, postcss_value_parser.default)(value);
|
|
6698
|
+
let changed = false;
|
|
6699
|
+
parsed.walk((node) => {
|
|
6700
|
+
if (node.type !== "function") return;
|
|
6701
|
+
const name = node.value.toLowerCase();
|
|
6702
|
+
const source = postcss_value_parser.default.stringify(node);
|
|
6703
|
+
let normalized;
|
|
6704
|
+
if (MODERN_COLOR_FUNCTION_NAMES.has(name) || name === "color" && isDisplayP3ColorFunction(source)) normalized = normalizeStandaloneColorFunction(source);
|
|
6705
|
+
else if (name === "color-mix") normalized = tryResolveColorMix(node, customPropertyValues)?.value;
|
|
6706
|
+
if (!normalized) return;
|
|
6707
|
+
const mutableNode = node;
|
|
6708
|
+
mutableNode.type = "word";
|
|
6709
|
+
mutableNode.value = normalized;
|
|
6710
|
+
delete mutableNode.nodes;
|
|
6711
|
+
changed = true;
|
|
6712
|
+
});
|
|
6713
|
+
const nextValue = changed ? parsed.toString() : value;
|
|
6714
|
+
return {
|
|
6715
|
+
value: nextValue,
|
|
6716
|
+
changed,
|
|
6717
|
+
hasUnsupported: hasUnsupportedModernColorFunction(nextValue)
|
|
6718
|
+
};
|
|
6719
|
+
}
|
|
6714
6720
|
function createPlaceholder(index) {
|
|
6715
6721
|
return `${PLACEHOLDER_PREFIX}${index}__`;
|
|
6716
6722
|
}
|
|
6717
6723
|
function unwrapProtectedSupports(cssRoot) {
|
|
6718
6724
|
cssRoot.walkAtRules("supports", (atRule) => {
|
|
6719
|
-
if (!atRule.nodes || !atRule.toString().includes(
|
|
6725
|
+
if (!atRule.nodes || !atRule.toString().includes("__weapp_tw_color_mix_")) return;
|
|
6720
6726
|
atRule.replaceWith(atRule.nodes);
|
|
6721
6727
|
});
|
|
6722
6728
|
}
|
|
6723
6729
|
function protectDynamicColorMixAlpha(css, options = {}) {
|
|
6724
|
-
if (!css.includes(
|
|
6730
|
+
if (!css.includes("color-mix")) return {
|
|
6725
6731
|
css,
|
|
6726
6732
|
restore: (value) => value
|
|
6727
6733
|
};
|
|
@@ -6730,14 +6736,14 @@ function protectDynamicColorMixAlpha(css, options = {}) {
|
|
|
6730
6736
|
const customPropertyValues = new Map(options.customPropertyValues);
|
|
6731
6737
|
let changed = false;
|
|
6732
6738
|
root.walkDecls((decl) => {
|
|
6733
|
-
if (decl.prop.startsWith("--") && !decl.value.includes(
|
|
6739
|
+
if (decl.prop.startsWith("--") && !decl.value.includes("color-mix")) customPropertyValues.set(decl.prop, decl.value.trim());
|
|
6734
6740
|
});
|
|
6735
6741
|
root.walkDecls((decl) => {
|
|
6736
|
-
if (!decl.value.includes(
|
|
6742
|
+
if (!decl.value.includes("color-mix")) return;
|
|
6737
6743
|
const parsed = (0, postcss_value_parser.default)(decl.value);
|
|
6738
6744
|
let mutated = false;
|
|
6739
6745
|
parsed.walk((node) => {
|
|
6740
|
-
if (node.type !== "function" || node.value.toLowerCase() !==
|
|
6746
|
+
if (node.type !== "function" || node.value.toLowerCase() !== "color-mix") return;
|
|
6741
6747
|
const resolved = tryResolveColorMix(node, customPropertyValues);
|
|
6742
6748
|
if (resolved) {
|
|
6743
6749
|
if (resolved.deferred) {
|
|
@@ -7193,7 +7199,27 @@ function isTailwindcssV4DisplayP3Media(atRule) {
|
|
|
7193
7199
|
function isTailwindcssV4DisplayP3Declaration(decl) {
|
|
7194
7200
|
return DISPLAY_P3_VALUE_RE$1.test(decl.value);
|
|
7195
7201
|
}
|
|
7202
|
+
function normalizeTailwindcssV4EmptyVarFallback(value) {
|
|
7203
|
+
if (!value.includes("var(") || !value.includes("--tw-")) return value;
|
|
7204
|
+
const parsed = (0, postcss_value_parser.default)(value);
|
|
7205
|
+
let changed = false;
|
|
7206
|
+
parsed.walk((node) => {
|
|
7207
|
+
if (node.type !== "function" || node.value.toLowerCase() !== "var") return;
|
|
7208
|
+
const firstArg = node.nodes.find((child) => child.type !== "space");
|
|
7209
|
+
const lastArg = node.nodes.findLast((child) => child.type !== "space");
|
|
7210
|
+
if (firstArg?.type !== "word" || !firstArg.value.startsWith("--tw-") || lastArg?.type !== "div" || lastArg.value !== "," || node.after === " ") return;
|
|
7211
|
+
node.after = " ";
|
|
7212
|
+
changed = true;
|
|
7213
|
+
});
|
|
7214
|
+
return changed ? parsed.toString() : value;
|
|
7215
|
+
}
|
|
7196
7216
|
function normalizeTailwindcssV4Declaration(decl) {
|
|
7217
|
+
let changed = false;
|
|
7218
|
+
const normalizedEmptyVarFallback = normalizeTailwindcssV4EmptyVarFallback(decl.value);
|
|
7219
|
+
if (normalizedEmptyVarFallback !== decl.value) {
|
|
7220
|
+
decl.value = normalizedEmptyVarFallback;
|
|
7221
|
+
changed = true;
|
|
7222
|
+
}
|
|
7197
7223
|
if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OKLAB_SUFFIX)) {
|
|
7198
7224
|
decl.value = decl.value.slice(0, decl.value.length - 8).trimEnd();
|
|
7199
7225
|
return true;
|
|
@@ -7215,17 +7241,38 @@ function normalizeTailwindcssV4Declaration(decl) {
|
|
|
7215
7241
|
return true;
|
|
7216
7242
|
}
|
|
7217
7243
|
}
|
|
7218
|
-
return
|
|
7244
|
+
return changed;
|
|
7219
7245
|
}
|
|
7220
7246
|
//#endregion
|
|
7221
|
-
//#region src/compat/mini-program-css/
|
|
7222
|
-
const
|
|
7223
|
-
const
|
|
7224
|
-
function
|
|
7225
|
-
|
|
7247
|
+
//#region src/compat/mini-program-css/directives.ts
|
|
7248
|
+
const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
|
|
7249
|
+
const GENERATOR_PLACEHOLDER_COMMENT_RE = /^\s*(?:!\s*)?weapp-tailwindcss generator-placeholder\s*$/i;
|
|
7250
|
+
function hasTailwindcssV4Signal(css) {
|
|
7251
|
+
if (TAILWIND_V4_BANNER_RE.test(css)) return true;
|
|
7252
|
+
const root = postcss.default.parse(css);
|
|
7253
|
+
let hasProperty = false;
|
|
7254
|
+
root.walkAtRules("property", (atRule) => {
|
|
7255
|
+
if (atRule.params.trim().startsWith("--tw-")) {
|
|
7256
|
+
hasProperty = true;
|
|
7257
|
+
return false;
|
|
7258
|
+
}
|
|
7259
|
+
});
|
|
7260
|
+
return hasProperty;
|
|
7226
7261
|
}
|
|
7227
|
-
function
|
|
7228
|
-
|
|
7262
|
+
function unwrapTailwindSourceMedia(root) {
|
|
7263
|
+
root.walkAtRules("media", (atRule) => {
|
|
7264
|
+
if (!atRule.params.startsWith("source(")) return;
|
|
7265
|
+
if (atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
|
|
7266
|
+
else atRule.remove();
|
|
7267
|
+
});
|
|
7268
|
+
}
|
|
7269
|
+
function removeTailwindGenerationDirectives(root) {
|
|
7270
|
+
root.walkComments((comment) => {
|
|
7271
|
+
if (GENERATOR_PLACEHOLDER_COMMENT_RE.test(comment.text)) comment.remove();
|
|
7272
|
+
});
|
|
7273
|
+
root.walkAtRules((atRule) => {
|
|
7274
|
+
if (atRule.name === "config" || atRule.name === "source" || atRule.name === "tailwind" || atRule.name === "reference" || atRule.name === "plugin") atRule.remove();
|
|
7275
|
+
});
|
|
7229
7276
|
}
|
|
7230
7277
|
//#endregion
|
|
7231
7278
|
//#region src/compat/mini-program-css/selectors.ts
|
|
@@ -7372,7 +7419,7 @@ function isCustomPropertyRule(rule) {
|
|
|
7372
7419
|
function isEmptyTwContentDeclaration(decl) {
|
|
7373
7420
|
return decl.prop === "--tw-content" && (decl.value === "\"\"" || decl.value === "''");
|
|
7374
7421
|
}
|
|
7375
|
-
function isOnlyTwContentDeclarations(rule) {
|
|
7422
|
+
function isOnlyTwContentDeclarations$1(rule) {
|
|
7376
7423
|
let hasDeclaration = false;
|
|
7377
7424
|
let onlyContentVariable = true;
|
|
7378
7425
|
rule.walkDecls((decl) => {
|
|
@@ -7383,7 +7430,7 @@ function isOnlyTwContentDeclarations(rule) {
|
|
|
7383
7430
|
}
|
|
7384
7431
|
function isPseudoContentInitRule(rule) {
|
|
7385
7432
|
const selector = rule.selector.replace(/\s+/g, "");
|
|
7386
|
-
return PSEUDO_CONTENT_SELECTOR_RE.test(selector) && isOnlyTwContentDeclarations(rule);
|
|
7433
|
+
return PSEUDO_CONTENT_SELECTOR_RE.test(selector) && isOnlyTwContentDeclarations$1(rule);
|
|
7387
7434
|
}
|
|
7388
7435
|
function usesTwContentVariable(root) {
|
|
7389
7436
|
let used = false;
|
|
@@ -7401,6 +7448,166 @@ function isMiniProgramThemeVariableRule(node) {
|
|
|
7401
7448
|
return isMiniProgramThemeScopeSelector(getRuleSelectors(node)) && isCustomPropertyRule(node);
|
|
7402
7449
|
}
|
|
7403
7450
|
//#endregion
|
|
7451
|
+
//#region src/compat/mini-program-css/hoist.ts
|
|
7452
|
+
const HOIST_ANCHOR_COMMENT = "__weapp_tailwindcss_base_anchor__";
|
|
7453
|
+
function getTopDirectiveTail(root) {
|
|
7454
|
+
let tail;
|
|
7455
|
+
for (const node of root.nodes ?? []) {
|
|
7456
|
+
if (node.type === "atrule" && (node.name === "charset" || node.name === "import")) {
|
|
7457
|
+
tail = node;
|
|
7458
|
+
continue;
|
|
7459
|
+
}
|
|
7460
|
+
break;
|
|
7461
|
+
}
|
|
7462
|
+
return tail;
|
|
7463
|
+
}
|
|
7464
|
+
function reorderPreflightResetDeclarations(rule) {
|
|
7465
|
+
const declarations = (rule.nodes ?? []).filter((node) => node.type === "decl");
|
|
7466
|
+
if (declarations.length <= 1) return;
|
|
7467
|
+
const resetDeclarations = [];
|
|
7468
|
+
const otherDeclarations = [];
|
|
7469
|
+
for (const declaration of declarations) if (PREFLIGHT_RESET_PROPS.has(declaration.prop)) resetDeclarations.push(declaration);
|
|
7470
|
+
else otherDeclarations.push(declaration);
|
|
7471
|
+
if (resetDeclarations.length === 0 || otherDeclarations.length === 0) return;
|
|
7472
|
+
const orderedDeclarations = [...resetDeclarations, ...otherDeclarations];
|
|
7473
|
+
if (orderedDeclarations.every((declaration, index) => declaration === declarations[index])) return;
|
|
7474
|
+
for (const declaration of declarations) declaration.remove();
|
|
7475
|
+
rule.prepend(...orderedDeclarations);
|
|
7476
|
+
rule.raws.semicolon = true;
|
|
7477
|
+
}
|
|
7478
|
+
function createHoistInsertionAnchor(root) {
|
|
7479
|
+
for (const node of root.nodes ?? []) if (isMiniProgramPreflightRule(node) || isMiniProgramThemeVariableRule(node)) {
|
|
7480
|
+
const anchor = postcss.default.comment({ text: HOIST_ANCHOR_COMMENT });
|
|
7481
|
+
node.before(anchor);
|
|
7482
|
+
return anchor;
|
|
7483
|
+
}
|
|
7484
|
+
}
|
|
7485
|
+
function insertHoistedRules(root, rules, anchor) {
|
|
7486
|
+
if (anchor && !anchor.parent) anchor = void 0;
|
|
7487
|
+
if (rules.length === 0) {
|
|
7488
|
+
anchor?.remove();
|
|
7489
|
+
return;
|
|
7490
|
+
}
|
|
7491
|
+
const topDirectiveTail = getTopDirectiveTail(root);
|
|
7492
|
+
const firstRule = rules[0];
|
|
7493
|
+
if (!firstRule) return;
|
|
7494
|
+
if (anchor) {
|
|
7495
|
+
if (anchor.raws.before === void 0) delete firstRule.raws.before;
|
|
7496
|
+
else firstRule.raws.before = anchor.raws.before;
|
|
7497
|
+
anchor.replaceWith(rules);
|
|
7498
|
+
return;
|
|
7499
|
+
}
|
|
7500
|
+
firstRule.raws.before = topDirectiveTail ? "\n" : "";
|
|
7501
|
+
if (topDirectiveTail) topDirectiveTail.after(rules);
|
|
7502
|
+
else root.prepend(rules);
|
|
7503
|
+
}
|
|
7504
|
+
function mergeEquivalentHoistedRules(rules) {
|
|
7505
|
+
const mergedRules = [];
|
|
7506
|
+
const ruleBySelector = /* @__PURE__ */ new Map();
|
|
7507
|
+
const propsBySelector = /* @__PURE__ */ new Map();
|
|
7508
|
+
for (const rule of rules) {
|
|
7509
|
+
const key = getSortedRuleSelectorKey(rule);
|
|
7510
|
+
const existingRule = ruleBySelector.get(key);
|
|
7511
|
+
if (existingRule) {
|
|
7512
|
+
const existingProps = propsBySelector.get(key) ?? /* @__PURE__ */ new Set();
|
|
7513
|
+
const nextNodes = (rule.nodes ?? []).filter((node) => {
|
|
7514
|
+
if (node.type !== "decl") return true;
|
|
7515
|
+
if (existingProps.has(node.prop)) return false;
|
|
7516
|
+
existingProps.add(node.prop);
|
|
7517
|
+
return true;
|
|
7518
|
+
});
|
|
7519
|
+
existingRule.append(...nextNodes.map((node) => node.clone()));
|
|
7520
|
+
reorderPreflightResetDeclarations(existingRule);
|
|
7521
|
+
propsBySelector.set(key, existingProps);
|
|
7522
|
+
continue;
|
|
7523
|
+
}
|
|
7524
|
+
ruleBySelector.set(key, rule);
|
|
7525
|
+
propsBySelector.set(key, new Set((rule.nodes ?? []).flatMap((node) => node.type === "decl" ? [node.prop] : [])));
|
|
7526
|
+
reorderPreflightResetDeclarations(rule);
|
|
7527
|
+
mergedRules.push(rule);
|
|
7528
|
+
}
|
|
7529
|
+
return mergedRules;
|
|
7530
|
+
}
|
|
7531
|
+
//#endregion
|
|
7532
|
+
//#region src/compat/mini-program-css/preflight.ts
|
|
7533
|
+
const MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR$1 = "::before,\n::after";
|
|
7534
|
+
const MINI_PROGRAM_PSEUDO_CONTENT_SELECTORS = new Set(["::before", "::after"]);
|
|
7535
|
+
function createPseudoContentInitRule() {
|
|
7536
|
+
const rule = postcss.default.rule({ selector: MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR$1 });
|
|
7537
|
+
rule.append({
|
|
7538
|
+
prop: "--tw-content",
|
|
7539
|
+
value: "''"
|
|
7540
|
+
});
|
|
7541
|
+
return rule;
|
|
7542
|
+
}
|
|
7543
|
+
function applyConfiguredPreflightDeclarations(rule, cssPreflight) {
|
|
7544
|
+
if (!cssPreflight || typeof cssPreflight !== "object") return;
|
|
7545
|
+
const configuredProps = new Set(Object.keys(cssPreflight));
|
|
7546
|
+
rule.walkDecls((decl) => {
|
|
7547
|
+
if (!configuredProps.has(decl.prop)) return;
|
|
7548
|
+
const value = cssPreflight[decl.prop];
|
|
7549
|
+
if (value === false) {
|
|
7550
|
+
decl.remove();
|
|
7551
|
+
return;
|
|
7552
|
+
}
|
|
7553
|
+
decl.value = value.toString();
|
|
7554
|
+
});
|
|
7555
|
+
for (const [prop, value] of Object.entries(cssPreflight)) {
|
|
7556
|
+
if (value === false || rule.nodes?.some((node) => node.type === "decl" && node.prop === prop)) continue;
|
|
7557
|
+
rule.append({
|
|
7558
|
+
prop,
|
|
7559
|
+
value: value.toString()
|
|
7560
|
+
});
|
|
7561
|
+
}
|
|
7562
|
+
}
|
|
7563
|
+
function collectPreflightRules(root, options = {}) {
|
|
7564
|
+
const preflightNodes = [];
|
|
7565
|
+
for (const node of root.nodes ?? []) if (isMiniProgramPreflightRule(node)) preflightNodes.push(node);
|
|
7566
|
+
if (preflightNodes.length === 0) return [];
|
|
7567
|
+
const clonedPreflightRules = preflightNodes.map((node) => {
|
|
7568
|
+
const rule = node.clone();
|
|
7569
|
+
rule.walkDecls("--tw-content", (decl) => {
|
|
7570
|
+
if (isEmptyTwContentDeclaration(decl)) decl.remove();
|
|
7571
|
+
});
|
|
7572
|
+
return rule;
|
|
7573
|
+
});
|
|
7574
|
+
for (const rule of clonedPreflightRules) {
|
|
7575
|
+
const selectors = getRuleSelectors(rule);
|
|
7576
|
+
const hasElementSelector = selectors.some((selector) => selector === "view" || selector === "text");
|
|
7577
|
+
if (selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_PSEUDO_CONTENT_SELECTORS.has(selector))) rule.selector = MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR$1;
|
|
7578
|
+
else if (hasElementSelector && selectors.every((selector) => MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS.has(selector))) {
|
|
7579
|
+
rule.selector = MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR;
|
|
7580
|
+
applyConfiguredPreflightDeclarations(rule, options.cssPreflight);
|
|
7581
|
+
}
|
|
7582
|
+
}
|
|
7583
|
+
const nonEmptyPreflightRules = clonedPreflightRules.filter((rule) => (rule.nodes?.length ?? 0) > 0);
|
|
7584
|
+
const preflightRules = [...options.preservePseudoContentInit ? [createPseudoContentInitRule()] : [], ...nonEmptyPreflightRules];
|
|
7585
|
+
for (const node of preflightNodes) node.remove();
|
|
7586
|
+
return preflightRules;
|
|
7587
|
+
}
|
|
7588
|
+
function createPreflightResetRule(cssPreflight) {
|
|
7589
|
+
if (!cssPreflight || typeof cssPreflight !== "object") return;
|
|
7590
|
+
const rule = postcss.default.rule({ selector: MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR });
|
|
7591
|
+
for (const [prop, value] of Object.entries(cssPreflight)) {
|
|
7592
|
+
if (value === false) continue;
|
|
7593
|
+
rule.append({
|
|
7594
|
+
prop,
|
|
7595
|
+
value: value.toString()
|
|
7596
|
+
});
|
|
7597
|
+
}
|
|
7598
|
+
return rule.nodes?.length ? rule : void 0;
|
|
7599
|
+
}
|
|
7600
|
+
//#endregion
|
|
7601
|
+
//#region src/compat/mini-program-css/color-gamut.ts
|
|
7602
|
+
const DISPLAY_P3_VALUE_RE = /color\(\s*display-p3\b/i;
|
|
7603
|
+
const COLOR_GAMUT_P3_RE = /\(\s*color-gamut\s*:\s*p3\s*\)/i;
|
|
7604
|
+
function isDisplayP3MediaRule(atRule) {
|
|
7605
|
+
return atRule.name === "media" && COLOR_GAMUT_P3_RE.test(atRule.params);
|
|
7606
|
+
}
|
|
7607
|
+
function isDisplayP3Declaration(decl) {
|
|
7608
|
+
return DISPLAY_P3_VALUE_RE.test(decl.value);
|
|
7609
|
+
}
|
|
7610
|
+
//#endregion
|
|
7404
7611
|
//#region src/compat/mini-program-css/root-cleanups.ts
|
|
7405
7612
|
function removeSpecificityPlaceholders(root) {
|
|
7406
7613
|
root.walkRules((rule) => {
|
|
@@ -7415,8 +7622,11 @@ function removeSpecificityPlaceholders(root) {
|
|
|
7415
7622
|
if (changed) rule.selectors = selectors;
|
|
7416
7623
|
});
|
|
7417
7624
|
}
|
|
7625
|
+
function isEffectivelyEmptyContainer(container) {
|
|
7626
|
+
return !container.nodes || container.nodes.every((node) => node.type === "comment");
|
|
7627
|
+
}
|
|
7418
7628
|
function removeEmptyAtRuleAncestors(parent) {
|
|
7419
|
-
while (parent?.type === "atrule" && (
|
|
7629
|
+
while (parent?.type === "atrule" && isEffectivelyEmptyContainer(parent)) {
|
|
7420
7630
|
const nextParent = parent.parent;
|
|
7421
7631
|
parent.remove();
|
|
7422
7632
|
parent = nextParent?.type === "atrule" ? nextParent : void 0;
|
|
@@ -7454,6 +7664,43 @@ function removeDisplayP3Declarations(root) {
|
|
|
7454
7664
|
}
|
|
7455
7665
|
});
|
|
7456
7666
|
}
|
|
7667
|
+
const SIMPLE_MIN_WIDTH_MEDIA_RE = /^\(\s*min-width\s*:[^)]+\)$/i;
|
|
7668
|
+
const TAILWIND_GENERATED_TOKEN_COMMENT_RE = /^\s*tokens:\s*container\s*<=\s*<tailwind generated>\s*$/i;
|
|
7669
|
+
function isContainerMaxWidthOnlyRule(rule) {
|
|
7670
|
+
if (!rule.selectors || rule.selectors.length !== 1 || rule.selectors[0] !== ".container") return false;
|
|
7671
|
+
const declarations = rule.nodes?.filter((node) => node.type === "decl") ?? [];
|
|
7672
|
+
return declarations.length === 1 && declarations[0]?.prop === "max-width" && (rule.nodes ?? []).every((node) => node.type === "decl" || node.type === "comment");
|
|
7673
|
+
}
|
|
7674
|
+
function removeTailwindContainerMaxWidthMediaRules(root) {
|
|
7675
|
+
root.walkAtRules("media", (atRule) => {
|
|
7676
|
+
if (!SIMPLE_MIN_WIDTH_MEDIA_RE.test(atRule.params.trim())) return;
|
|
7677
|
+
atRule.walkRules((rule) => {
|
|
7678
|
+
if (!isContainerMaxWidthOnlyRule(rule)) return;
|
|
7679
|
+
const parent = rule.parent;
|
|
7680
|
+
rule.remove();
|
|
7681
|
+
removeEmptyAtRuleAncestors(parent);
|
|
7682
|
+
});
|
|
7683
|
+
});
|
|
7684
|
+
}
|
|
7685
|
+
function isContainerWidthOnlyRule(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 === "width" && declarations[0].value.trim() === "100%" && (rule.nodes ?? []).every((node) => node.type === "decl" || node.type === "comment");
|
|
7689
|
+
}
|
|
7690
|
+
function isTailwindGeneratedContainerRule(rule) {
|
|
7691
|
+
const previous = rule.prev();
|
|
7692
|
+
return previous?.type === "comment" && TAILWIND_GENERATED_TOKEN_COMMENT_RE.test(previous.text);
|
|
7693
|
+
}
|
|
7694
|
+
function removeTailwindContainerWidthRules(root, options = {}) {
|
|
7695
|
+
root.walkRules((rule) => {
|
|
7696
|
+
if (!isContainerWidthOnlyRule(rule)) return;
|
|
7697
|
+
if (options.generatedOnly && !isTailwindGeneratedContainerRule(rule)) return;
|
|
7698
|
+
const parent = rule.parent;
|
|
7699
|
+
if (isTailwindGeneratedContainerRule(rule)) rule.prev()?.remove();
|
|
7700
|
+
rule.remove();
|
|
7701
|
+
removeEmptyAtRuleAncestors(parent);
|
|
7702
|
+
});
|
|
7703
|
+
}
|
|
7457
7704
|
function removeUnsupportedModernColorDeclarations(root) {
|
|
7458
7705
|
const customPropertyValues = /* @__PURE__ */ new Map();
|
|
7459
7706
|
root.walkDecls((decl) => {
|
|
@@ -7469,53 +7716,7 @@ function removeUnsupportedModernColorDeclarations(root) {
|
|
|
7469
7716
|
});
|
|
7470
7717
|
}
|
|
7471
7718
|
//#endregion
|
|
7472
|
-
//#region src/compat/mini-program-css/
|
|
7473
|
-
const HOIST_ANCHOR_COMMENT = "__weapp_tailwindcss_base_anchor__";
|
|
7474
|
-
const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
|
|
7475
|
-
const MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR = "::before,\n::after";
|
|
7476
|
-
const MINI_PROGRAM_PSEUDO_CONTENT_SELECTORS = new Set(["::before", "::after"]);
|
|
7477
|
-
function createPseudoContentInitRule() {
|
|
7478
|
-
const rule = postcss.default.rule({ selector: MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR });
|
|
7479
|
-
rule.append({
|
|
7480
|
-
prop: "--tw-content",
|
|
7481
|
-
value: "''"
|
|
7482
|
-
});
|
|
7483
|
-
return rule;
|
|
7484
|
-
}
|
|
7485
|
-
function collectPreflightRules(root, options = {}) {
|
|
7486
|
-
const preflightNodes = [];
|
|
7487
|
-
for (const node of root.nodes ?? []) if (isMiniProgramPreflightRule(node)) preflightNodes.push(node);
|
|
7488
|
-
if (preflightNodes.length === 0) return [];
|
|
7489
|
-
const clonedPreflightRules = preflightNodes.map((node) => {
|
|
7490
|
-
const rule = node.clone();
|
|
7491
|
-
rule.walkDecls("--tw-content", (decl) => {
|
|
7492
|
-
if (isEmptyTwContentDeclaration(decl)) decl.remove();
|
|
7493
|
-
});
|
|
7494
|
-
return rule;
|
|
7495
|
-
});
|
|
7496
|
-
for (const rule of clonedPreflightRules) {
|
|
7497
|
-
const selectors = getRuleSelectors(rule);
|
|
7498
|
-
const hasElementSelector = selectors.some((selector) => selector === "view" || selector === "text");
|
|
7499
|
-
if (selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_PSEUDO_CONTENT_SELECTORS.has(selector))) rule.selector = MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR;
|
|
7500
|
-
else if (hasElementSelector && selectors.every((selector) => MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS.has(selector))) rule.selector = MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR;
|
|
7501
|
-
}
|
|
7502
|
-
const nonEmptyPreflightRules = clonedPreflightRules.filter((rule) => (rule.nodes?.length ?? 0) > 0);
|
|
7503
|
-
const preflightRules = [...options.preservePseudoContentInit ? [createPseudoContentInitRule()] : [], ...nonEmptyPreflightRules];
|
|
7504
|
-
for (const node of preflightNodes) node.remove();
|
|
7505
|
-
return preflightRules;
|
|
7506
|
-
}
|
|
7507
|
-
function createPreflightResetRule(cssPreflight) {
|
|
7508
|
-
if (!cssPreflight || typeof cssPreflight !== "object") return;
|
|
7509
|
-
const rule = postcss.default.rule({ selector: MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR });
|
|
7510
|
-
for (const [prop, value] of Object.entries(cssPreflight)) {
|
|
7511
|
-
if (value === false) continue;
|
|
7512
|
-
rule.append({
|
|
7513
|
-
prop,
|
|
7514
|
-
value: value.toString()
|
|
7515
|
-
});
|
|
7516
|
-
}
|
|
7517
|
-
return rule.nodes?.length ? rule : void 0;
|
|
7518
|
-
}
|
|
7719
|
+
//#region src/compat/mini-program-css/theme.ts
|
|
7519
7720
|
function collectThemeVariableRule(root, options = {}) {
|
|
7520
7721
|
const themeRules = [];
|
|
7521
7722
|
const declarations = /* @__PURE__ */ new Map();
|
|
@@ -7535,86 +7736,22 @@ function collectThemeVariableRule(root, options = {}) {
|
|
|
7535
7736
|
for (const decl of declarations.values()) rule.append(decl);
|
|
7536
7737
|
return rule;
|
|
7537
7738
|
}
|
|
7538
|
-
|
|
7539
|
-
|
|
7540
|
-
const root = postcss.default.parse(css);
|
|
7541
|
-
let hasProperty = false;
|
|
7542
|
-
root.walkAtRules("property", (atRule) => {
|
|
7543
|
-
if (atRule.params.trim().startsWith("--tw-")) {
|
|
7544
|
-
hasProperty = true;
|
|
7545
|
-
return false;
|
|
7546
|
-
}
|
|
7547
|
-
});
|
|
7548
|
-
return hasProperty;
|
|
7549
|
-
}
|
|
7550
|
-
function getTopDirectiveTail(root) {
|
|
7551
|
-
let tail;
|
|
7552
|
-
for (const node of root.nodes ?? []) {
|
|
7553
|
-
if (node.type === "atrule" && (node.name === "charset" || node.name === "import")) {
|
|
7554
|
-
tail = node;
|
|
7555
|
-
continue;
|
|
7556
|
-
}
|
|
7557
|
-
break;
|
|
7558
|
-
}
|
|
7559
|
-
return tail;
|
|
7560
|
-
}
|
|
7561
|
-
function createHoistInsertionAnchor(root) {
|
|
7562
|
-
for (const node of root.nodes ?? []) if (isMiniProgramPreflightRule(node) || isMiniProgramThemeVariableRule(node)) {
|
|
7563
|
-
const anchor = postcss.default.comment({ text: HOIST_ANCHOR_COMMENT });
|
|
7564
|
-
node.before(anchor);
|
|
7565
|
-
return anchor;
|
|
7566
|
-
}
|
|
7567
|
-
}
|
|
7568
|
-
function insertHoistedRules(root, rules, anchor) {
|
|
7569
|
-
if (anchor && !anchor.parent) anchor = void 0;
|
|
7570
|
-
if (rules.length === 0) {
|
|
7571
|
-
anchor?.remove();
|
|
7572
|
-
return;
|
|
7573
|
-
}
|
|
7574
|
-
const topDirectiveTail = getTopDirectiveTail(root);
|
|
7575
|
-
const firstRule = rules[0];
|
|
7576
|
-
if (!firstRule) return;
|
|
7577
|
-
if (anchor) {
|
|
7578
|
-
if (anchor.raws.before === void 0) delete firstRule.raws.before;
|
|
7579
|
-
else firstRule.raws.before = anchor.raws.before;
|
|
7580
|
-
anchor.replaceWith(rules);
|
|
7581
|
-
return;
|
|
7582
|
-
}
|
|
7583
|
-
firstRule.raws.before = topDirectiveTail ? "\n" : "";
|
|
7584
|
-
if (topDirectiveTail) topDirectiveTail.after(rules);
|
|
7585
|
-
else root.prepend(rules);
|
|
7586
|
-
}
|
|
7587
|
-
function mergeEquivalentHoistedRules(rules) {
|
|
7588
|
-
const mergedRules = [];
|
|
7589
|
-
const ruleBySelector = /* @__PURE__ */ new Map();
|
|
7590
|
-
for (const rule of rules) {
|
|
7591
|
-
const key = getSortedRuleSelectorKey(rule);
|
|
7592
|
-
const existingRule = ruleBySelector.get(key);
|
|
7593
|
-
if (existingRule) {
|
|
7594
|
-
existingRule.append(...(rule.nodes ?? []).map((node) => node.clone()));
|
|
7595
|
-
continue;
|
|
7596
|
-
}
|
|
7597
|
-
ruleBySelector.set(key, rule);
|
|
7598
|
-
mergedRules.push(rule);
|
|
7599
|
-
}
|
|
7600
|
-
return mergedRules;
|
|
7601
|
-
}
|
|
7602
|
-
function unwrapTailwindSourceMedia(root) {
|
|
7603
|
-
root.walkAtRules("media", (atRule) => {
|
|
7604
|
-
if (atRule.params.startsWith("source(") && atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
|
|
7605
|
-
});
|
|
7606
|
-
}
|
|
7739
|
+
//#endregion
|
|
7740
|
+
//#region src/compat/mini-program-css/finalize.ts
|
|
7607
7741
|
function finalizeMiniProgramCssRoot(root, options = {}) {
|
|
7608
7742
|
const shouldInjectTailwindcssV4Defaults = options.isTailwindcssV4 === true;
|
|
7609
7743
|
const tailwindcssV4DefaultNodes = shouldInjectTailwindcssV4Defaults ? createMissingCssVarsV4Nodes(root, collectUsedTailwindcssV4Variables(root)) : [];
|
|
7610
7744
|
removeUnsupportedCascadeLayers(root);
|
|
7611
7745
|
unwrapTailwindSourceMedia(root);
|
|
7746
|
+
removeTailwindGenerationDirectives(root);
|
|
7612
7747
|
root.walkAtRules("property", (atRule) => {
|
|
7613
7748
|
atRule.remove();
|
|
7614
7749
|
});
|
|
7615
7750
|
removeSpecificityPlaceholders(root);
|
|
7616
7751
|
removeUnsupportedBrowserSelectors(root);
|
|
7617
7752
|
removeDisplayP3Declarations(root);
|
|
7753
|
+
removeTailwindContainerMaxWidthMediaRules(root);
|
|
7754
|
+
removeTailwindContainerWidthRules(root, { generatedOnly: true });
|
|
7618
7755
|
removeUnsupportedModernColorDeclarations(root);
|
|
7619
7756
|
root.walkDecls((decl) => {
|
|
7620
7757
|
if (shouldInjectTailwindcssV4Defaults) normalizeTailwindcssV4Declaration(decl);
|
|
@@ -7667,6 +7804,7 @@ function finalizeMiniProgramCss(css, options = {}) {
|
|
|
7667
7804
|
//#endregion
|
|
7668
7805
|
//#region src/compat/mini-program-css/prune-generated.ts
|
|
7669
7806
|
const DEFAULT_WEAPP_VARIABLE_SCOPE = "page,.tw-root,wx-root-portal-content,:host";
|
|
7807
|
+
const MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR = "::before,\n::after";
|
|
7670
7808
|
const CLASS_SELECTOR_RE$1 = /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i;
|
|
7671
7809
|
function isConditionalCompilationComment(text) {
|
|
7672
7810
|
return /#(?:ifn?def|endif)\b/.test(text);
|
|
@@ -7683,6 +7821,23 @@ function isMiniProgramElementVariableScopeRule(rule) {
|
|
|
7683
7821
|
const selectors = getRuleSelectors(rule);
|
|
7684
7822
|
return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS.has(selector));
|
|
7685
7823
|
}
|
|
7824
|
+
function isOnlyTwContentDeclarations(rule) {
|
|
7825
|
+
let hasDeclaration = false;
|
|
7826
|
+
let onlyContentVariable = true;
|
|
7827
|
+
rule.walkDecls((decl) => {
|
|
7828
|
+
hasDeclaration = true;
|
|
7829
|
+
if (decl.prop !== "--tw-content") onlyContentVariable = false;
|
|
7830
|
+
});
|
|
7831
|
+
return hasDeclaration && onlyContentVariable;
|
|
7832
|
+
}
|
|
7833
|
+
function isMiniProgramElementContentInitRule(rule) {
|
|
7834
|
+
if (!isMiniProgramElementVariableScopeRule(rule)) return false;
|
|
7835
|
+
let hasElementSelector = false;
|
|
7836
|
+
let hasPseudoSelector = false;
|
|
7837
|
+
for (const selector of getRuleSelectors(rule)) if (selector === "view" || selector === "text") hasElementSelector = true;
|
|
7838
|
+
else if (selector === "::before" || selector === "::after") hasPseudoSelector = true;
|
|
7839
|
+
return hasElementSelector && hasPseudoSelector && isOnlyTwContentDeclarations(rule);
|
|
7840
|
+
}
|
|
7686
7841
|
function isTailwindV4GradientRuntimeDeclaration(decl) {
|
|
7687
7842
|
return decl.prop.startsWith("--tw-gradient-");
|
|
7688
7843
|
}
|
|
@@ -7720,6 +7875,8 @@ function pruneMiniProgramGeneratedCss(css, options = {}) {
|
|
|
7720
7875
|
});
|
|
7721
7876
|
removeUnsupportedCascadeLayers(root);
|
|
7722
7877
|
removeUnsupportedModernColorDeclarations(root);
|
|
7878
|
+
removeTailwindContainerMaxWidthMediaRules(root);
|
|
7879
|
+
removeTailwindContainerWidthRules(root);
|
|
7723
7880
|
root.walkAtRules("supports", (atRule) => {
|
|
7724
7881
|
atRule.remove();
|
|
7725
7882
|
});
|
|
@@ -7731,6 +7888,18 @@ function pruneMiniProgramGeneratedCss(css, options = {}) {
|
|
|
7731
7888
|
});
|
|
7732
7889
|
root.walkRules((rule) => {
|
|
7733
7890
|
if (isKeyframesRule(rule)) return;
|
|
7891
|
+
if (isPseudoContentInitRule(rule)) {
|
|
7892
|
+
if (!shouldPreserveContentInit) rule.remove();
|
|
7893
|
+
return;
|
|
7894
|
+
}
|
|
7895
|
+
if (isMiniProgramElementContentInitRule(rule)) {
|
|
7896
|
+
if (!shouldPreserveContentInit) {
|
|
7897
|
+
rule.remove();
|
|
7898
|
+
return;
|
|
7899
|
+
}
|
|
7900
|
+
rule.selector = MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR;
|
|
7901
|
+
return;
|
|
7902
|
+
}
|
|
7734
7903
|
if (isCustomPropertyRule(rule) && isMiniProgramElementVariableScopeRule(rule)) {
|
|
7735
7904
|
rule.selector = MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR;
|
|
7736
7905
|
return;
|
|
@@ -7743,10 +7912,6 @@ function pruneMiniProgramGeneratedCss(css, options = {}) {
|
|
|
7743
7912
|
}
|
|
7744
7913
|
if (hasClassSelector$2(rule.selector)) return;
|
|
7745
7914
|
if (!shouldPreserveContentInit) removeEmptyContentInitDeclarations(rule);
|
|
7746
|
-
if (isPseudoContentInitRule(rule)) {
|
|
7747
|
-
if (!shouldPreserveContentInit) rule.remove();
|
|
7748
|
-
return;
|
|
7749
|
-
}
|
|
7750
7915
|
if (options.preservePreflight && isMiniProgramPreflightRule(rule)) return;
|
|
7751
7916
|
if (isCustomPropertyRule(rule)) {
|
|
7752
7917
|
moveTailwindV4GradientRuntimeDeclarations(rule);
|
|
@@ -43134,7 +43299,7 @@ var require_postcss_page_break = /* @__PURE__ */ require_html_transform.__common
|
|
|
43134
43299
|
module.exports.postcss = true;
|
|
43135
43300
|
}));
|
|
43136
43301
|
//#endregion
|
|
43137
|
-
//#region ../../node_modules/.pnpm/@csstools+selector-specificity@6.0.0_postcss-selector-parser@7.1.
|
|
43302
|
+
//#region ../../node_modules/.pnpm/@csstools+selector-specificity@6.0.0_postcss-selector-parser@7.1.2/node_modules/@csstools/selector-specificity/dist/index.mjs
|
|
43138
43303
|
var import_postcss_page_break = /* @__PURE__ */ require_html_transform.__toESM(require_postcss_page_break(), 1);
|
|
43139
43304
|
function compare(e, t) {
|
|
43140
43305
|
return e.a === t.a ? e.b === t.b ? e.c - t.c : e.b - t.b : e.a - t.a;
|
|
@@ -49908,7 +50073,7 @@ const creator$18 = (s) => {
|
|
|
49908
50073
|
};
|
|
49909
50074
|
creator$18.postcss = !0;
|
|
49910
50075
|
//#endregion
|
|
49911
|
-
//#region ../../node_modules/.pnpm/@csstools+selector-resolve-nested@4.0.0_postcss-selector-parser@7.1.
|
|
50076
|
+
//#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
50077
|
function sourceFrom(e) {
|
|
49913
50078
|
return {
|
|
49914
50079
|
sourceIndex: e.sourceIndex ?? 0,
|
|
@@ -53122,10 +53287,7 @@ function normalizeSpacingDeclarations(rule) {
|
|
|
53122
53287
|
for (const declarations of grouped.values()) dedupeSpacingGroup(rule, declarations);
|
|
53123
53288
|
}
|
|
53124
53289
|
//#endregion
|
|
53125
|
-
//#region src/selectorParser/rule-transformer.ts
|
|
53126
|
-
const ruleTransformCache = /* @__PURE__ */ new WeakMap();
|
|
53127
|
-
const SELECTOR_TRANSFORM_OPTIONS = normalizeTransformOptions();
|
|
53128
|
-
const SIMPLE_SELECTOR_FAST_PATH = /^[#.][\w-]+(?:\s+[#.][\w-]+)*$/;
|
|
53290
|
+
//#region src/selectorParser/rule-transformer/pseudos.ts
|
|
53129
53291
|
const RTL_LANGUAGE_ANY_PSEUDO_SET = new Set([
|
|
53130
53292
|
":-moz-any",
|
|
53131
53293
|
":-webkit-any",
|
|
@@ -53141,6 +53303,23 @@ const EMPTY_FUNCTIONAL_PSEUDO_CLEANUP_SET = new Set([
|
|
|
53141
53303
|
":-moz-any",
|
|
53142
53304
|
":lang"
|
|
53143
53305
|
]);
|
|
53306
|
+
const UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET = new Set([
|
|
53307
|
+
":after",
|
|
53308
|
+
":before",
|
|
53309
|
+
"::after",
|
|
53310
|
+
"::before",
|
|
53311
|
+
"::backdrop",
|
|
53312
|
+
"::-ms-backdrop",
|
|
53313
|
+
"::-webkit-backdrop",
|
|
53314
|
+
"::file-selector-button"
|
|
53315
|
+
]);
|
|
53316
|
+
const MINI_PROGRAM_UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET = new Set([
|
|
53317
|
+
"::backdrop",
|
|
53318
|
+
"::-ms-backdrop",
|
|
53319
|
+
"::-webkit-backdrop",
|
|
53320
|
+
"::file-selector-button"
|
|
53321
|
+
]);
|
|
53322
|
+
const NORMALIZED_PSEUDO_ELEMENT_SELECTOR = new Map([[":before", "::before"], [":after", "::after"]]);
|
|
53144
53323
|
function isRtlLanguageAnyPseudo(node) {
|
|
53145
53324
|
return node.type === "pseudo" && RTL_LANGUAGE_ANY_PSEUDO_SET.has(node.value);
|
|
53146
53325
|
}
|
|
@@ -53177,6 +53356,29 @@ function flattenWherePseudo(node, context, index, parent) {
|
|
|
53177
53356
|
if (parent && parent.type === "selector" && parent.length === 0) parent.remove();
|
|
53178
53357
|
}
|
|
53179
53358
|
}
|
|
53359
|
+
function shouldRemoveUnsupportedPseudoElementSelector(selector, options) {
|
|
53360
|
+
if (!isUniAppXEnabled(options)) return selector.nodes.some((node) => node.type === "pseudo" && MINI_PROGRAM_UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
|
|
53361
|
+
return selector.nodes.some((node) => node.type === "pseudo" && UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
|
|
53362
|
+
}
|
|
53363
|
+
function handlePseudoNode(node, index, context, parent) {
|
|
53364
|
+
if (node.type !== "pseudo") return;
|
|
53365
|
+
if (isRtlLanguageAnyPseudo(node)) {
|
|
53366
|
+
stripUnsupportedRtlLanguagePseudo(node);
|
|
53367
|
+
return;
|
|
53368
|
+
}
|
|
53369
|
+
if (node.value === ":root" && context.rootReplacement) {
|
|
53370
|
+
node.value = context.rootReplacement;
|
|
53371
|
+
return;
|
|
53372
|
+
}
|
|
53373
|
+
const normalizedPseudoElement = NORMALIZED_PSEUDO_ELEMENT_SELECTOR.get(node.value);
|
|
53374
|
+
if (normalizedPseudoElement) {
|
|
53375
|
+
node.value = normalizedPseudoElement;
|
|
53376
|
+
return;
|
|
53377
|
+
}
|
|
53378
|
+
if (node.value === ":where") flattenWherePseudo(node, context, index, parent);
|
|
53379
|
+
}
|
|
53380
|
+
//#endregion
|
|
53381
|
+
//#region src/selectorParser/rule-transformer/nodes.ts
|
|
53180
53382
|
function handleClassNode(node, context) {
|
|
53181
53383
|
if (node.type !== "class") return;
|
|
53182
53384
|
node.value = context.selectorReplacerOptions === void 0 ? internalCssSelectorReplacer(node.value) : internalCssSelectorReplacer(node.value, context.selectorReplacerOptions);
|
|
@@ -53189,27 +53391,6 @@ function shouldRemoveHoverSelector(selector, options) {
|
|
|
53189
53391
|
if (!options.cssRemoveHoverPseudoClass) return false;
|
|
53190
53392
|
return selector.nodes.some((node) => node.type === "pseudo" && node.value === ":hover");
|
|
53191
53393
|
}
|
|
53192
|
-
const UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET = new Set([
|
|
53193
|
-
":after",
|
|
53194
|
-
":before",
|
|
53195
|
-
"::after",
|
|
53196
|
-
"::before",
|
|
53197
|
-
"::backdrop",
|
|
53198
|
-
"::-ms-backdrop",
|
|
53199
|
-
"::-webkit-backdrop",
|
|
53200
|
-
"::file-selector-button"
|
|
53201
|
-
]);
|
|
53202
|
-
const MINI_PROGRAM_UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET = new Set([
|
|
53203
|
-
"::backdrop",
|
|
53204
|
-
"::-ms-backdrop",
|
|
53205
|
-
"::-webkit-backdrop",
|
|
53206
|
-
"::file-selector-button"
|
|
53207
|
-
]);
|
|
53208
|
-
const NORMALIZED_PSEUDO_ELEMENT_SELECTOR = new Map([[":before", "::before"], [":after", "::after"]]);
|
|
53209
|
-
function shouldRemoveUnsupportedPseudoElementSelector(selector, options) {
|
|
53210
|
-
if (!isUniAppXEnabled(options)) return selector.nodes.some((node) => node.type === "pseudo" && MINI_PROGRAM_UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
|
|
53211
|
-
return selector.nodes.some((node) => node.type === "pseudo" && UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
|
|
53212
|
-
}
|
|
53213
53394
|
function isHiddenOrTemplateNotPseudo(node) {
|
|
53214
53395
|
if (!node || node.type !== "pseudo" || node.value !== ":not") return false;
|
|
53215
53396
|
const selector = node.first;
|
|
@@ -53232,23 +53413,6 @@ function handleCombinatorNode(node, index, context) {
|
|
|
53232
53413
|
nodes.splice(index + 1, 3, ...ast);
|
|
53233
53414
|
}
|
|
53234
53415
|
}
|
|
53235
|
-
function handlePseudoNode(node, index, context, parent) {
|
|
53236
|
-
if (node.type !== "pseudo") return;
|
|
53237
|
-
if (isRtlLanguageAnyPseudo(node)) {
|
|
53238
|
-
stripUnsupportedRtlLanguagePseudo(node);
|
|
53239
|
-
return;
|
|
53240
|
-
}
|
|
53241
|
-
if (node.value === ":root" && context.rootReplacement) {
|
|
53242
|
-
node.value = context.rootReplacement;
|
|
53243
|
-
return;
|
|
53244
|
-
}
|
|
53245
|
-
const normalizedPseudoElement = NORMALIZED_PSEUDO_ELEMENT_SELECTOR.get(node.value);
|
|
53246
|
-
if (normalizedPseudoElement) {
|
|
53247
|
-
node.value = normalizedPseudoElement;
|
|
53248
|
-
return;
|
|
53249
|
-
}
|
|
53250
|
-
if (node.value === ":where") flattenWherePseudo(node, context, index, parent);
|
|
53251
|
-
}
|
|
53252
53416
|
function handleTagOrAttribute(node, context) {
|
|
53253
53417
|
stripUnsupportedNodeForUniAppX(node, context.options);
|
|
53254
53418
|
}
|
|
@@ -53263,6 +53427,11 @@ function handleSelectorNode(selector, context) {
|
|
|
53263
53427
|
}
|
|
53264
53428
|
if (transformSpacingSelector(selector.nodes, context.options)) context.requiresSpacingNormalization = true;
|
|
53265
53429
|
}
|
|
53430
|
+
//#endregion
|
|
53431
|
+
//#region src/selectorParser/rule-transformer.ts
|
|
53432
|
+
const ruleTransformCache = /* @__PURE__ */ new WeakMap();
|
|
53433
|
+
const SELECTOR_TRANSFORM_OPTIONS = normalizeTransformOptions();
|
|
53434
|
+
const SIMPLE_SELECTOR_FAST_PATH = /^[#.][\w-]+(?:\s+[#.][\w-]+)*$/;
|
|
53266
53435
|
function canSkipRuleTransform(rule) {
|
|
53267
53436
|
const selector = rule.selector.trim();
|
|
53268
53437
|
if (!selector) return false;
|
|
@@ -54043,11 +54212,46 @@ function makePseudoVarRule() {
|
|
|
54043
54212
|
function isEmptyContentInitDeclaration(decl) {
|
|
54044
54213
|
return decl.prop === "--tw-content" && (decl.value === "\"\"" || decl.value === "''");
|
|
54045
54214
|
}
|
|
54215
|
+
function isPseudoContentInitSelector(selector) {
|
|
54216
|
+
return selector === ":before" || selector === ":after" || selector === "::before" || selector === "::after";
|
|
54217
|
+
}
|
|
54218
|
+
function isElementContentInitSelector(selector) {
|
|
54219
|
+
return selector === "*" || selector === "view" || selector === "text";
|
|
54220
|
+
}
|
|
54221
|
+
function isOnlyEmptyContentInitRule(node) {
|
|
54222
|
+
let hasDeclaration = false;
|
|
54223
|
+
let onlyEmptyContentInit = true;
|
|
54224
|
+
node.walkDecls((decl) => {
|
|
54225
|
+
hasDeclaration = true;
|
|
54226
|
+
if (!isEmptyContentInitDeclaration(decl)) onlyEmptyContentInit = false;
|
|
54227
|
+
});
|
|
54228
|
+
return hasDeclaration && onlyEmptyContentInit;
|
|
54229
|
+
}
|
|
54230
|
+
function restorePseudoContentInitScope(node) {
|
|
54231
|
+
if (!isOnlyEmptyContentInitRule(node)) return false;
|
|
54232
|
+
let hasPseudoSelector = false;
|
|
54233
|
+
let hasElementSelector = false;
|
|
54234
|
+
for (const selector of node.selectors) if (isPseudoContentInitSelector(selector)) hasPseudoSelector = true;
|
|
54235
|
+
else if (isElementContentInitSelector(selector)) hasElementSelector = true;
|
|
54236
|
+
else return false;
|
|
54237
|
+
if (!hasPseudoSelector || !hasElementSelector) return false;
|
|
54238
|
+
assignRuleSelectors(node, ["::before", "::after"], {
|
|
54239
|
+
phase: "pre",
|
|
54240
|
+
reason: "restore-pseudo-content-init-scope"
|
|
54241
|
+
});
|
|
54242
|
+
return true;
|
|
54243
|
+
}
|
|
54046
54244
|
function removeTailwindV4EmptyContentInit(node) {
|
|
54047
54245
|
node.walkDecls((decl) => {
|
|
54048
54246
|
if (isEmptyContentInitDeclaration(decl)) decl.remove();
|
|
54049
54247
|
});
|
|
54050
54248
|
}
|
|
54249
|
+
function injectPreflightDeclarations(node, options) {
|
|
54250
|
+
const preflightDeclarations = options.cssInjectPreflight?.();
|
|
54251
|
+
if (!preflightDeclarations || preflightDeclarations.length === 0) return;
|
|
54252
|
+
node.prepend(...preflightDeclarations);
|
|
54253
|
+
node.raws.semicolon = true;
|
|
54254
|
+
}
|
|
54051
54255
|
function hasClassSelector(node) {
|
|
54052
54256
|
return node.selectors.some((selector) => selector.includes("."));
|
|
54053
54257
|
}
|
|
@@ -54073,7 +54277,7 @@ function resolveUniAppXVariableScopeSelectors(options) {
|
|
|
54073
54277
|
return ["view", "text"];
|
|
54074
54278
|
}
|
|
54075
54279
|
function commonChunkPreflight(node, options) {
|
|
54076
|
-
const { ctx,
|
|
54280
|
+
const { ctx, injectAdditionalCssVarScope } = options;
|
|
54077
54281
|
const uniAppXEnabled = isUniAppXEnabled(options);
|
|
54078
54282
|
const isTailwindcss4 = isTailwindcssV4(options);
|
|
54079
54283
|
const rootOption = options.cssSelectorReplacement?.root;
|
|
@@ -54086,6 +54290,7 @@ function commonChunkPreflight(node, options) {
|
|
|
54086
54290
|
reason: "append-host-selector"
|
|
54087
54291
|
});
|
|
54088
54292
|
if (isTailwindcss4 && !usesTailwindcssV4ContentVariable(node.root()) && (!hasClassSelector(node) || isRootThemeScopeRule(node))) removeTailwindV4EmptyContentInit(node);
|
|
54293
|
+
if (!isTailwindcss4 && restorePseudoContentInitScope(node)) return;
|
|
54089
54294
|
if (testIfVariablesScope(node) || uniAppXEnabled && node.selectors.includes("*") && hasTwVars(node, 2)) {
|
|
54090
54295
|
ctx?.markVariablesScope(node);
|
|
54091
54296
|
assignRuleSelectors(node, uniAppXEnabled ? resolveUniAppXVariableScopeSelectors(options) : remakeCssVarSelector(node.selectors, options), {
|
|
@@ -54093,7 +54298,7 @@ function commonChunkPreflight(node, options) {
|
|
|
54093
54298
|
reason: "rewrite-variable-scope"
|
|
54094
54299
|
});
|
|
54095
54300
|
if (!uniAppXEnabled && !isTailwindcss4) node.before(makePseudoVarRule());
|
|
54096
|
-
|
|
54301
|
+
injectPreflightDeclarations(node, options);
|
|
54097
54302
|
}
|
|
54098
54303
|
if (injectAdditionalCssVarScope && (isTailwindcss4 ? testIfRootHostForV4(node) : testIfTwBackdrop(node))) {
|
|
54099
54304
|
const nodes = isTailwindcss4 ? createUsedCssVarsV4Nodes(collectUsedTailwindcssV4Variables(node.root())) : cssVarsV3Nodes;
|
|
@@ -54112,7 +54317,7 @@ function commonChunkPreflight(node, options) {
|
|
|
54112
54317
|
});
|
|
54113
54318
|
node.before(syntheticRule);
|
|
54114
54319
|
if (!uniAppXEnabled && !isTailwindcss4) node.before(makePseudoVarRule());
|
|
54115
|
-
|
|
54320
|
+
injectPreflightDeclarations(syntheticRule, options);
|
|
54116
54321
|
}
|
|
54117
54322
|
}
|
|
54118
54323
|
//#endregion
|