@weapp-tailwindcss/postcss 3.0.0 → 3.0.1
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/mini-program-css/selectors.d.ts +2 -1
- package/dist/index.js +30 -19
- package/dist/index.mjs +30 -19
- package/package.json +1 -1
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type postcss from 'postcss';
|
|
2
2
|
export declare const MINI_PROGRAM_THEME_SCOPE_SELECTOR = ":host,page,.tw-root,wx-root-portal-content";
|
|
3
|
-
export declare const MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR = "view,text
|
|
3
|
+
export declare const MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR = "view,text,::after,::before";
|
|
4
4
|
export declare const MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS: Set<string>;
|
|
5
5
|
export declare const MINI_PROGRAM_PREFLIGHT_SELECTORS: Set<string>;
|
|
6
6
|
export declare const MINI_PROGRAM_THEME_SCOPE_SELECTORS: Set<string>;
|
|
7
7
|
export declare const SPECIFICITY_PLACEHOLDER_SUFFIXES: string[];
|
|
8
8
|
export declare function normalizeSelector(selector: string): string;
|
|
9
|
+
export declare function normalizePseudoElementSelector(selector: string): string;
|
|
9
10
|
export declare function getRuleSelectors(rule: postcss.Rule): string[];
|
|
10
11
|
export declare function getSortedRuleSelectorKey(rule: postcss.Rule): string;
|
|
11
12
|
export declare function isUnsupportedBrowserSelector(selector: string): boolean;
|
package/dist/index.js
CHANGED
|
@@ -7230,7 +7230,7 @@ function isDisplayP3Declaration(decl) {
|
|
|
7230
7230
|
//#endregion
|
|
7231
7231
|
//#region src/compat/mini-program-css/selectors.ts
|
|
7232
7232
|
const MINI_PROGRAM_THEME_SCOPE_SELECTOR = ":host,page,.tw-root,wx-root-portal-content";
|
|
7233
|
-
const MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR = "view,text
|
|
7233
|
+
const MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR = "view,text,::after,::before";
|
|
7234
7234
|
const MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS = new Set([
|
|
7235
7235
|
"view",
|
|
7236
7236
|
"text",
|
|
@@ -7318,8 +7318,11 @@ const MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS = new Set([
|
|
|
7318
7318
|
function normalizeSelector$1(selector) {
|
|
7319
7319
|
return selector.trim().replace(/\s+/g, "");
|
|
7320
7320
|
}
|
|
7321
|
+
function normalizePseudoElementSelector(selector) {
|
|
7322
|
+
return normalizeSelector$1(selector).replace(/^:(before|after)$/, "::$1");
|
|
7323
|
+
}
|
|
7321
7324
|
function getRuleSelectors(rule) {
|
|
7322
|
-
return rule.selector.split(",").map(
|
|
7325
|
+
return rule.selector.split(",").map(normalizePseudoElementSelector).filter(Boolean);
|
|
7323
7326
|
}
|
|
7324
7327
|
function getSortedRuleSelectorKey(rule) {
|
|
7325
7328
|
return getRuleSelectors(rule).sort().join(",");
|
|
@@ -7356,13 +7359,6 @@ function hasTailwindPreflightDeclaration(rule) {
|
|
|
7356
7359
|
});
|
|
7357
7360
|
return hasTailwindVar || hasResetProp;
|
|
7358
7361
|
}
|
|
7359
|
-
function hasTwContentDeclaration(rule) {
|
|
7360
|
-
let hasContentInit = false;
|
|
7361
|
-
rule.walkDecls("--tw-content", () => {
|
|
7362
|
-
hasContentInit = true;
|
|
7363
|
-
});
|
|
7364
|
-
return hasContentInit;
|
|
7365
|
-
}
|
|
7366
7362
|
function isCustomPropertyRule(rule) {
|
|
7367
7363
|
let hasDeclaration = false;
|
|
7368
7364
|
let allCustomProperties = true;
|
|
@@ -7476,8 +7472,10 @@ function removeUnsupportedModernColorDeclarations(root) {
|
|
|
7476
7472
|
//#region src/compat/mini-program-css/finalize.ts
|
|
7477
7473
|
const HOIST_ANCHOR_COMMENT = "__weapp_tailwindcss_base_anchor__";
|
|
7478
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"]);
|
|
7479
7477
|
function createPseudoContentInitRule() {
|
|
7480
|
-
const rule = postcss.default.rule({ selector:
|
|
7478
|
+
const rule = postcss.default.rule({ selector: MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR });
|
|
7481
7479
|
rule.append({
|
|
7482
7480
|
prop: "--tw-content",
|
|
7483
7481
|
value: "''"
|
|
@@ -7486,16 +7484,23 @@ function createPseudoContentInitRule() {
|
|
|
7486
7484
|
}
|
|
7487
7485
|
function collectPreflightRules(root, options = {}) {
|
|
7488
7486
|
const preflightNodes = [];
|
|
7489
|
-
|
|
7490
|
-
for (const node of root.nodes ?? []) if (isMiniProgramPreflightRule(node)) {
|
|
7491
|
-
preflightNodes.push(node);
|
|
7492
|
-
if (hasTwContentDeclaration(node)) hasContentInit = true;
|
|
7493
|
-
}
|
|
7487
|
+
for (const node of root.nodes ?? []) if (isMiniProgramPreflightRule(node)) preflightNodes.push(node);
|
|
7494
7488
|
if (preflightNodes.length === 0) return [];
|
|
7495
|
-
const clonedPreflightRules = preflightNodes.map((node) =>
|
|
7496
|
-
|
|
7497
|
-
|
|
7498
|
-
|
|
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];
|
|
7499
7504
|
for (const node of preflightNodes) node.remove();
|
|
7500
7505
|
return preflightRules;
|
|
7501
7506
|
}
|
|
@@ -53198,6 +53203,7 @@ const MINI_PROGRAM_UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET = new Set([
|
|
|
53198
53203
|
"::-webkit-backdrop",
|
|
53199
53204
|
"::file-selector-button"
|
|
53200
53205
|
]);
|
|
53206
|
+
const NORMALIZED_PSEUDO_ELEMENT_SELECTOR = new Map([[":before", "::before"], [":after", "::after"]]);
|
|
53201
53207
|
function shouldRemoveUnsupportedPseudoElementSelector(selector, options) {
|
|
53202
53208
|
if (!isUniAppXEnabled(options)) return selector.nodes.some((node) => node.type === "pseudo" && MINI_PROGRAM_UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
|
|
53203
53209
|
return selector.nodes.some((node) => node.type === "pseudo" && UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
|
|
@@ -53234,6 +53240,11 @@ function handlePseudoNode(node, index, context, parent) {
|
|
|
53234
53240
|
node.value = context.rootReplacement;
|
|
53235
53241
|
return;
|
|
53236
53242
|
}
|
|
53243
|
+
const normalizedPseudoElement = NORMALIZED_PSEUDO_ELEMENT_SELECTOR.get(node.value);
|
|
53244
|
+
if (normalizedPseudoElement) {
|
|
53245
|
+
node.value = normalizedPseudoElement;
|
|
53246
|
+
return;
|
|
53247
|
+
}
|
|
53237
53248
|
if (node.value === ":where") flattenWherePseudo(node, context, index, parent);
|
|
53238
53249
|
}
|
|
53239
53250
|
function handleTagOrAttribute(node, context) {
|
package/dist/index.mjs
CHANGED
|
@@ -7242,7 +7242,7 @@ function isDisplayP3Declaration(decl) {
|
|
|
7242
7242
|
//#endregion
|
|
7243
7243
|
//#region src/compat/mini-program-css/selectors.ts
|
|
7244
7244
|
const MINI_PROGRAM_THEME_SCOPE_SELECTOR = ":host,page,.tw-root,wx-root-portal-content";
|
|
7245
|
-
const MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR = "view,text
|
|
7245
|
+
const MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR = "view,text,::after,::before";
|
|
7246
7246
|
const MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS = new Set([
|
|
7247
7247
|
"view",
|
|
7248
7248
|
"text",
|
|
@@ -7330,8 +7330,11 @@ const MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS = new Set([
|
|
|
7330
7330
|
function normalizeSelector$1(selector) {
|
|
7331
7331
|
return selector.trim().replace(/\s+/g, "");
|
|
7332
7332
|
}
|
|
7333
|
+
function normalizePseudoElementSelector(selector) {
|
|
7334
|
+
return normalizeSelector$1(selector).replace(/^:(before|after)$/, "::$1");
|
|
7335
|
+
}
|
|
7333
7336
|
function getRuleSelectors(rule) {
|
|
7334
|
-
return rule.selector.split(",").map(
|
|
7337
|
+
return rule.selector.split(",").map(normalizePseudoElementSelector).filter(Boolean);
|
|
7335
7338
|
}
|
|
7336
7339
|
function getSortedRuleSelectorKey(rule) {
|
|
7337
7340
|
return getRuleSelectors(rule).sort().join(",");
|
|
@@ -7368,13 +7371,6 @@ function hasTailwindPreflightDeclaration(rule) {
|
|
|
7368
7371
|
});
|
|
7369
7372
|
return hasTailwindVar || hasResetProp;
|
|
7370
7373
|
}
|
|
7371
|
-
function hasTwContentDeclaration(rule) {
|
|
7372
|
-
let hasContentInit = false;
|
|
7373
|
-
rule.walkDecls("--tw-content", () => {
|
|
7374
|
-
hasContentInit = true;
|
|
7375
|
-
});
|
|
7376
|
-
return hasContentInit;
|
|
7377
|
-
}
|
|
7378
7374
|
function isCustomPropertyRule(rule) {
|
|
7379
7375
|
let hasDeclaration = false;
|
|
7380
7376
|
let allCustomProperties = true;
|
|
@@ -7488,8 +7484,10 @@ function removeUnsupportedModernColorDeclarations(root) {
|
|
|
7488
7484
|
//#region src/compat/mini-program-css/finalize.ts
|
|
7489
7485
|
const HOIST_ANCHOR_COMMENT = "__weapp_tailwindcss_base_anchor__";
|
|
7490
7486
|
const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
|
|
7487
|
+
const MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR = "::before,\n::after";
|
|
7488
|
+
const MINI_PROGRAM_PSEUDO_CONTENT_SELECTORS = new Set(["::before", "::after"]);
|
|
7491
7489
|
function createPseudoContentInitRule() {
|
|
7492
|
-
const rule = postcss.rule({ selector:
|
|
7490
|
+
const rule = postcss.rule({ selector: MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR });
|
|
7493
7491
|
rule.append({
|
|
7494
7492
|
prop: "--tw-content",
|
|
7495
7493
|
value: "''"
|
|
@@ -7498,16 +7496,23 @@ function createPseudoContentInitRule() {
|
|
|
7498
7496
|
}
|
|
7499
7497
|
function collectPreflightRules(root, options = {}) {
|
|
7500
7498
|
const preflightNodes = [];
|
|
7501
|
-
|
|
7502
|
-
for (const node of root.nodes ?? []) if (isMiniProgramPreflightRule(node)) {
|
|
7503
|
-
preflightNodes.push(node);
|
|
7504
|
-
if (hasTwContentDeclaration(node)) hasContentInit = true;
|
|
7505
|
-
}
|
|
7499
|
+
for (const node of root.nodes ?? []) if (isMiniProgramPreflightRule(node)) preflightNodes.push(node);
|
|
7506
7500
|
if (preflightNodes.length === 0) return [];
|
|
7507
|
-
const clonedPreflightRules = preflightNodes.map((node) =>
|
|
7508
|
-
|
|
7509
|
-
|
|
7510
|
-
|
|
7501
|
+
const clonedPreflightRules = preflightNodes.map((node) => {
|
|
7502
|
+
const rule = node.clone();
|
|
7503
|
+
rule.walkDecls("--tw-content", (decl) => {
|
|
7504
|
+
if (isEmptyTwContentDeclaration(decl)) decl.remove();
|
|
7505
|
+
});
|
|
7506
|
+
return rule;
|
|
7507
|
+
});
|
|
7508
|
+
for (const rule of clonedPreflightRules) {
|
|
7509
|
+
const selectors = getRuleSelectors(rule);
|
|
7510
|
+
const hasElementSelector = selectors.some((selector) => selector === "view" || selector === "text");
|
|
7511
|
+
if (selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_PSEUDO_CONTENT_SELECTORS.has(selector))) rule.selector = MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR;
|
|
7512
|
+
else if (hasElementSelector && selectors.every((selector) => MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS.has(selector))) rule.selector = MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR;
|
|
7513
|
+
}
|
|
7514
|
+
const nonEmptyPreflightRules = clonedPreflightRules.filter((rule) => (rule.nodes?.length ?? 0) > 0);
|
|
7515
|
+
const preflightRules = [...options.preservePseudoContentInit ? [createPseudoContentInitRule()] : [], ...nonEmptyPreflightRules];
|
|
7511
7516
|
for (const node of preflightNodes) node.remove();
|
|
7512
7517
|
return preflightRules;
|
|
7513
7518
|
}
|
|
@@ -53192,6 +53197,7 @@ const MINI_PROGRAM_UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET = new Set([
|
|
|
53192
53197
|
"::-webkit-backdrop",
|
|
53193
53198
|
"::file-selector-button"
|
|
53194
53199
|
]);
|
|
53200
|
+
const NORMALIZED_PSEUDO_ELEMENT_SELECTOR = new Map([[":before", "::before"], [":after", "::after"]]);
|
|
53195
53201
|
function shouldRemoveUnsupportedPseudoElementSelector(selector, options) {
|
|
53196
53202
|
if (!isUniAppXEnabled(options)) return selector.nodes.some((node) => node.type === "pseudo" && MINI_PROGRAM_UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
|
|
53197
53203
|
return selector.nodes.some((node) => node.type === "pseudo" && UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
|
|
@@ -53228,6 +53234,11 @@ function handlePseudoNode(node, index, context, parent) {
|
|
|
53228
53234
|
node.value = context.rootReplacement;
|
|
53229
53235
|
return;
|
|
53230
53236
|
}
|
|
53237
|
+
const normalizedPseudoElement = NORMALIZED_PSEUDO_ELEMENT_SELECTOR.get(node.value);
|
|
53238
|
+
if (normalizedPseudoElement) {
|
|
53239
|
+
node.value = normalizedPseudoElement;
|
|
53240
|
+
return;
|
|
53241
|
+
}
|
|
53231
53242
|
if (node.value === ":where") flattenWherePseudo(node, context, index, parent);
|
|
53232
53243
|
}
|
|
53233
53244
|
function handleTagOrAttribute(node, context) {
|