@weapp-tailwindcss/postcss 3.0.0 → 3.0.2
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 +34 -21
- package/dist/index.mjs +34 -21
- package/package.json +2 -2
|
@@ -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
|
@@ -7195,7 +7195,7 @@ function isTailwindcssV4DisplayP3Declaration(decl) {
|
|
|
7195
7195
|
}
|
|
7196
7196
|
function normalizeTailwindcssV4Declaration(decl) {
|
|
7197
7197
|
if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OKLAB_SUFFIX)) {
|
|
7198
|
-
decl.value = decl.value.slice(0, decl.value.length - 8);
|
|
7198
|
+
decl.value = decl.value.slice(0, decl.value.length - 8).trimEnd();
|
|
7199
7199
|
return true;
|
|
7200
7200
|
}
|
|
7201
7201
|
if (INFINITY_CALC_REGEXP.test(decl.value)) {
|
|
@@ -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
|
}
|
|
@@ -7600,7 +7605,8 @@ function unwrapTailwindSourceMedia(root) {
|
|
|
7600
7605
|
});
|
|
7601
7606
|
}
|
|
7602
7607
|
function finalizeMiniProgramCssRoot(root, options = {}) {
|
|
7603
|
-
const
|
|
7608
|
+
const shouldInjectTailwindcssV4Defaults = options.isTailwindcssV4 === true;
|
|
7609
|
+
const tailwindcssV4DefaultNodes = shouldInjectTailwindcssV4Defaults ? createMissingCssVarsV4Nodes(root, collectUsedTailwindcssV4Variables(root)) : [];
|
|
7604
7610
|
removeUnsupportedCascadeLayers(root);
|
|
7605
7611
|
unwrapTailwindSourceMedia(root);
|
|
7606
7612
|
root.walkAtRules("property", (atRule) => {
|
|
@@ -7611,6 +7617,7 @@ function finalizeMiniProgramCssRoot(root, options = {}) {
|
|
|
7611
7617
|
removeDisplayP3Declarations(root);
|
|
7612
7618
|
removeUnsupportedModernColorDeclarations(root);
|
|
7613
7619
|
root.walkDecls((decl) => {
|
|
7620
|
+
if (shouldInjectTailwindcssV4Defaults) normalizeTailwindcssV4Declaration(decl);
|
|
7614
7621
|
normalizeMiniProgramPrefixedDeclaration(decl);
|
|
7615
7622
|
});
|
|
7616
7623
|
root.walkAtRules((atRule) => {
|
|
@@ -53198,6 +53205,7 @@ const MINI_PROGRAM_UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET = new Set([
|
|
|
53198
53205
|
"::-webkit-backdrop",
|
|
53199
53206
|
"::file-selector-button"
|
|
53200
53207
|
]);
|
|
53208
|
+
const NORMALIZED_PSEUDO_ELEMENT_SELECTOR = new Map([[":before", "::before"], [":after", "::after"]]);
|
|
53201
53209
|
function shouldRemoveUnsupportedPseudoElementSelector(selector, options) {
|
|
53202
53210
|
if (!isUniAppXEnabled(options)) return selector.nodes.some((node) => node.type === "pseudo" && MINI_PROGRAM_UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
|
|
53203
53211
|
return selector.nodes.some((node) => node.type === "pseudo" && UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
|
|
@@ -53234,6 +53242,11 @@ function handlePseudoNode(node, index, context, parent) {
|
|
|
53234
53242
|
node.value = context.rootReplacement;
|
|
53235
53243
|
return;
|
|
53236
53244
|
}
|
|
53245
|
+
const normalizedPseudoElement = NORMALIZED_PSEUDO_ELEMENT_SELECTOR.get(node.value);
|
|
53246
|
+
if (normalizedPseudoElement) {
|
|
53247
|
+
node.value = normalizedPseudoElement;
|
|
53248
|
+
return;
|
|
53249
|
+
}
|
|
53237
53250
|
if (node.value === ":where") flattenWherePseudo(node, context, index, parent);
|
|
53238
53251
|
}
|
|
53239
53252
|
function handleTagOrAttribute(node, context) {
|
package/dist/index.mjs
CHANGED
|
@@ -7207,7 +7207,7 @@ function isTailwindcssV4DisplayP3Declaration(decl) {
|
|
|
7207
7207
|
}
|
|
7208
7208
|
function normalizeTailwindcssV4Declaration(decl) {
|
|
7209
7209
|
if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OKLAB_SUFFIX)) {
|
|
7210
|
-
decl.value = decl.value.slice(0, decl.value.length - 8);
|
|
7210
|
+
decl.value = decl.value.slice(0, decl.value.length - 8).trimEnd();
|
|
7211
7211
|
return true;
|
|
7212
7212
|
}
|
|
7213
7213
|
if (INFINITY_CALC_REGEXP.test(decl.value)) {
|
|
@@ -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
|
}
|
|
@@ -7612,7 +7617,8 @@ function unwrapTailwindSourceMedia(root) {
|
|
|
7612
7617
|
});
|
|
7613
7618
|
}
|
|
7614
7619
|
function finalizeMiniProgramCssRoot(root, options = {}) {
|
|
7615
|
-
const
|
|
7620
|
+
const shouldInjectTailwindcssV4Defaults = options.isTailwindcssV4 === true;
|
|
7621
|
+
const tailwindcssV4DefaultNodes = shouldInjectTailwindcssV4Defaults ? createMissingCssVarsV4Nodes(root, collectUsedTailwindcssV4Variables(root)) : [];
|
|
7616
7622
|
removeUnsupportedCascadeLayers(root);
|
|
7617
7623
|
unwrapTailwindSourceMedia(root);
|
|
7618
7624
|
root.walkAtRules("property", (atRule) => {
|
|
@@ -7623,6 +7629,7 @@ function finalizeMiniProgramCssRoot(root, options = {}) {
|
|
|
7623
7629
|
removeDisplayP3Declarations(root);
|
|
7624
7630
|
removeUnsupportedModernColorDeclarations(root);
|
|
7625
7631
|
root.walkDecls((decl) => {
|
|
7632
|
+
if (shouldInjectTailwindcssV4Defaults) normalizeTailwindcssV4Declaration(decl);
|
|
7626
7633
|
normalizeMiniProgramPrefixedDeclaration(decl);
|
|
7627
7634
|
});
|
|
7628
7635
|
root.walkAtRules((atRule) => {
|
|
@@ -53192,6 +53199,7 @@ const MINI_PROGRAM_UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET = new Set([
|
|
|
53192
53199
|
"::-webkit-backdrop",
|
|
53193
53200
|
"::file-selector-button"
|
|
53194
53201
|
]);
|
|
53202
|
+
const NORMALIZED_PSEUDO_ELEMENT_SELECTOR = new Map([[":before", "::before"], [":after", "::after"]]);
|
|
53195
53203
|
function shouldRemoveUnsupportedPseudoElementSelector(selector, options) {
|
|
53196
53204
|
if (!isUniAppXEnabled(options)) return selector.nodes.some((node) => node.type === "pseudo" && MINI_PROGRAM_UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
|
|
53197
53205
|
return selector.nodes.some((node) => node.type === "pseudo" && UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
|
|
@@ -53228,6 +53236,11 @@ function handlePseudoNode(node, index, context, parent) {
|
|
|
53228
53236
|
node.value = context.rootReplacement;
|
|
53229
53237
|
return;
|
|
53230
53238
|
}
|
|
53239
|
+
const normalizedPseudoElement = NORMALIZED_PSEUDO_ELEMENT_SELECTOR.get(node.value);
|
|
53240
|
+
if (normalizedPseudoElement) {
|
|
53241
|
+
node.value = normalizedPseudoElement;
|
|
53242
|
+
return;
|
|
53243
|
+
}
|
|
53231
53244
|
if (node.value === ":where") flattenWherePseudo(node, context, index, parent);
|
|
53232
53245
|
}
|
|
53233
53246
|
function handleTagOrAttribute(node, context) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-tailwindcss/postcss",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"description": "@weapp-tailwindcss/postcss",
|
|
5
5
|
"author": "ice breaker <1324318532@qq.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -57,7 +57,6 @@
|
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@weapp-core/escape": "~8.0.0",
|
|
60
|
-
"@weapp-tailwindcss/postcss-calc": "^1.0.0",
|
|
61
60
|
"autoprefixer": "^10.5.0",
|
|
62
61
|
"lru-cache": "11.5.1",
|
|
63
62
|
"postcss": "^8.5.15",
|
|
@@ -66,6 +65,7 @@
|
|
|
66
65
|
"postcss-rule-unit-converter": "^0.2.2",
|
|
67
66
|
"postcss-selector-parser": "~7.1.1",
|
|
68
67
|
"postcss-value-parser": "^4.2.0",
|
|
68
|
+
"@weapp-tailwindcss/postcss-calc": "^1.0.1",
|
|
69
69
|
"@weapp-tailwindcss/shared": "2.0.0"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|