@weapp-tailwindcss/postcss 3.0.0-next.9 → 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/index.mjs
CHANGED
|
@@ -6941,20 +6941,309 @@ function removeUnsupportedMiniProgramPrefixedAtRule(atRule) {
|
|
|
6941
6941
|
if (atRule.name.toLowerCase() === "-webkit-keyframes") atRule.remove();
|
|
6942
6942
|
}
|
|
6943
6943
|
//#endregion
|
|
6944
|
-
//#region src/
|
|
6944
|
+
//#region src/cssVarsV4.ts
|
|
6945
|
+
function property(ident, initialValue, _syntax) {
|
|
6946
|
+
return {
|
|
6947
|
+
prop: ident,
|
|
6948
|
+
value: initialValue || ""
|
|
6949
|
+
};
|
|
6950
|
+
}
|
|
6951
|
+
const nullShadow = "0 0 #0000";
|
|
6952
|
+
const nodes = [
|
|
6953
|
+
property("--tw-border-spacing-x", "0", "<length>"),
|
|
6954
|
+
property("--tw-border-spacing-y", "0", "<length>"),
|
|
6955
|
+
property("--tw-translate-x", "0"),
|
|
6956
|
+
property("--tw-translate-y", "0"),
|
|
6957
|
+
property("--tw-translate-z", "0"),
|
|
6958
|
+
property("--tw-scale-x", "1"),
|
|
6959
|
+
property("--tw-scale-y", "1"),
|
|
6960
|
+
property("--tw-scale-z", "1"),
|
|
6961
|
+
property("--tw-rotate-x"),
|
|
6962
|
+
property("--tw-rotate-y"),
|
|
6963
|
+
property("--tw-rotate-z"),
|
|
6964
|
+
property("--tw-skew-x"),
|
|
6965
|
+
property("--tw-skew-y"),
|
|
6966
|
+
property("--tw-pan-x"),
|
|
6967
|
+
property("--tw-pan-y"),
|
|
6968
|
+
property("--tw-pinch-zoom"),
|
|
6969
|
+
property("--tw-scroll-snap-strictness", "proximity", "*"),
|
|
6970
|
+
property("--tw-space-x-reverse", "0"),
|
|
6971
|
+
property("--tw-space-y-reverse", "0"),
|
|
6972
|
+
property("--tw-scrollbar-thumb", "#0000", "<color>"),
|
|
6973
|
+
property("--tw-scrollbar-track", "#0000", "<color>"),
|
|
6974
|
+
property("--tw-border-style", "solid"),
|
|
6975
|
+
property("--tw-divide-x-reverse", "0"),
|
|
6976
|
+
property("--tw-divide-y-reverse", "0"),
|
|
6977
|
+
property("--tw-gradient-position", "initial"),
|
|
6978
|
+
property("--tw-gradient-from", "#0000", "<color>"),
|
|
6979
|
+
property("--tw-gradient-via", "#0000", "<color>"),
|
|
6980
|
+
property("--tw-gradient-to", "#0000", "<color>"),
|
|
6981
|
+
property("--tw-gradient-stops", "initial"),
|
|
6982
|
+
property("--tw-gradient-via-stops", "initial"),
|
|
6983
|
+
property("--tw-gradient-from-position", "0%", "<length-percentage>"),
|
|
6984
|
+
property("--tw-gradient-via-position", "50%", "<length-percentage>"),
|
|
6985
|
+
property("--tw-gradient-to-position", "100%", "<length-percentage>"),
|
|
6986
|
+
property("--tw-mask-linear", "linear-gradient(#fff, #fff)"),
|
|
6987
|
+
property("--tw-mask-radial", "linear-gradient(#fff, #fff)"),
|
|
6988
|
+
property("--tw-mask-conic", "linear-gradient(#fff, #fff)"),
|
|
6989
|
+
property("--tw-mask-left", "linear-gradient(#fff, #fff)"),
|
|
6990
|
+
property("--tw-mask-right", "linear-gradient(#fff, #fff)"),
|
|
6991
|
+
property("--tw-mask-bottom", "linear-gradient(#fff, #fff)"),
|
|
6992
|
+
property("--tw-mask-top", "linear-gradient(#fff, #fff)"),
|
|
6993
|
+
property("--tw-mask-linear-position", "0deg"),
|
|
6994
|
+
property("--tw-mask-linear-from-position", "0%"),
|
|
6995
|
+
property("--tw-mask-linear-to-position", "100%"),
|
|
6996
|
+
property("--tw-mask-linear-from-color", "black"),
|
|
6997
|
+
property("--tw-mask-linear-to-color", "transparent"),
|
|
6998
|
+
property("--tw-mask-radial-from-position", "0%"),
|
|
6999
|
+
property("--tw-mask-radial-to-position", "100%"),
|
|
7000
|
+
property("--tw-mask-radial-from-color", "black"),
|
|
7001
|
+
property("--tw-mask-radial-to-color", "transparent"),
|
|
7002
|
+
property("--tw-mask-radial-shape", "ellipse"),
|
|
7003
|
+
property("--tw-mask-radial-size", "farthest-corner"),
|
|
7004
|
+
property("--tw-mask-radial-position", "center"),
|
|
7005
|
+
property("--tw-mask-conic-position", "0deg"),
|
|
7006
|
+
property("--tw-mask-conic-from-position", "0%"),
|
|
7007
|
+
property("--tw-mask-conic-to-position", "100%"),
|
|
7008
|
+
property("--tw-mask-conic-from-color", "black"),
|
|
7009
|
+
property("--tw-mask-conic-to-color", "transparent"),
|
|
7010
|
+
property("--tw-font-weight"),
|
|
7011
|
+
property("--tw-blur"),
|
|
7012
|
+
property("--tw-brightness"),
|
|
7013
|
+
property("--tw-contrast"),
|
|
7014
|
+
property("--tw-grayscale"),
|
|
7015
|
+
property("--tw-hue-rotate"),
|
|
7016
|
+
property("--tw-invert"),
|
|
7017
|
+
property("--tw-opacity"),
|
|
7018
|
+
property("--tw-saturate"),
|
|
7019
|
+
property("--tw-sepia"),
|
|
7020
|
+
property("--tw-drop-shadow"),
|
|
7021
|
+
property("--tw-drop-shadow-color"),
|
|
7022
|
+
property("--tw-drop-shadow-alpha", "100%", "<percentage>"),
|
|
7023
|
+
property("--tw-drop-shadow-size"),
|
|
7024
|
+
property("--tw-backdrop-blur"),
|
|
7025
|
+
property("--tw-backdrop-brightness"),
|
|
7026
|
+
property("--tw-backdrop-contrast"),
|
|
7027
|
+
property("--tw-backdrop-grayscale"),
|
|
7028
|
+
property("--tw-backdrop-hue-rotate"),
|
|
7029
|
+
property("--tw-backdrop-invert"),
|
|
7030
|
+
property("--tw-backdrop-opacity"),
|
|
7031
|
+
property("--tw-backdrop-saturate"),
|
|
7032
|
+
property("--tw-backdrop-sepia"),
|
|
7033
|
+
property("--tw-duration", "initial"),
|
|
7034
|
+
property("--tw-ease", "initial"),
|
|
7035
|
+
property("--tw-content", "\"\""),
|
|
7036
|
+
property("--tw-contain-size"),
|
|
7037
|
+
property("--tw-contain-layout"),
|
|
7038
|
+
property("--tw-contain-paint"),
|
|
7039
|
+
property("--tw-contain-style"),
|
|
7040
|
+
property("--tw-leading"),
|
|
7041
|
+
property("--tw-tracking"),
|
|
7042
|
+
property("--tw-ordinal"),
|
|
7043
|
+
property("--tw-slashed-zero"),
|
|
7044
|
+
property("--tw-numeric-figure"),
|
|
7045
|
+
property("--tw-numeric-spacing"),
|
|
7046
|
+
property("--tw-numeric-fraction"),
|
|
7047
|
+
property("--tw-outline-style", "solid"),
|
|
7048
|
+
property("--tw-text-shadow-color", "initial"),
|
|
7049
|
+
property("--tw-text-shadow-alpha", "100%", "<percentage>"),
|
|
7050
|
+
property("--tw-shadow", nullShadow),
|
|
7051
|
+
property("--tw-shadow-color", "initial"),
|
|
7052
|
+
property("--tw-shadow-alpha", "100%", "<percentage>"),
|
|
7053
|
+
property("--tw-inset-shadow", nullShadow),
|
|
7054
|
+
property("--tw-inset-shadow-color", "initial"),
|
|
7055
|
+
property("--tw-inset-shadow-alpha", "100%", "<percentage>"),
|
|
7056
|
+
property("--tw-ring-color"),
|
|
7057
|
+
property("--tw-ring-shadow", nullShadow),
|
|
7058
|
+
property("--tw-inset-ring-color"),
|
|
7059
|
+
property("--tw-inset-ring-shadow", nullShadow),
|
|
7060
|
+
property("--tw-ring-inset"),
|
|
7061
|
+
property("--tw-ring-offset-width", "0px", "<length>"),
|
|
7062
|
+
property("--tw-ring-offset-color", "#fff"),
|
|
7063
|
+
property("--tw-ring-offset-shadow", nullShadow)
|
|
7064
|
+
];
|
|
7065
|
+
for (const edge of [
|
|
7066
|
+
"top",
|
|
7067
|
+
"right",
|
|
7068
|
+
"bottom",
|
|
7069
|
+
"left"
|
|
7070
|
+
]) nodes.push(property(`--tw-mask-${edge}-from-position`, "0%"), property(`--tw-mask-${edge}-to-position`, "100%"), property(`--tw-mask-${edge}-from-color`, "black"), property(`--tw-mask-${edge}-to-color`, "transparent"));
|
|
7071
|
+
//#endregion
|
|
7072
|
+
//#region src/utils/css-vars.ts
|
|
7073
|
+
/**
|
|
7074
|
+
* 将 CSS 变量定义转换为可直接插入的 Declaration 节点列表。
|
|
7075
|
+
*/
|
|
7076
|
+
function createCssVarNodes(definitions) {
|
|
7077
|
+
return definitions.map((def) => new Declaration({
|
|
7078
|
+
prop: def.prop,
|
|
7079
|
+
value: def.value
|
|
7080
|
+
}));
|
|
7081
|
+
}
|
|
7082
|
+
//#endregion
|
|
7083
|
+
//#region src/compat/tailwindcss-v4.ts
|
|
7084
|
+
const OKLAB_SUFFIX = "in oklab";
|
|
7085
|
+
const INFINITY_CALC_REGEXP = /calc\(\s*infinity\s*\*\s*(?:\d+(?:\.\d*)?|\.\d+)r?px/;
|
|
7086
|
+
const RADIUS_THRESHOLD = 1e5;
|
|
7087
|
+
const CLAMP_PX = 9999;
|
|
7088
|
+
const MODERN_CHECK_WEBKIT_HYPHENS_RE = /-webkit-hyphens\s*:\s*none/;
|
|
7089
|
+
const MODERN_CHECK_MARGIN_TRIM_RE = /margin-trim\s*:\s*inline/;
|
|
7090
|
+
const MODERN_CHECK_MOZ_ORIENT_RE = /-moz-orient\s*:\s*inline/;
|
|
7091
|
+
const MODERN_CHECK_COLOR_RGB_RE = /color\s*:\s*rgb\(\s*from\s+red\s+r\s+g\s+b\s*\)/;
|
|
7092
|
+
const LINEAR_GRADIENT_LAB_RE = /background-image\s*:\s*linear-gradient\(\s*in\s+lab\s*,\s*red\s*,\s*red\s*\)/;
|
|
7093
|
+
const DISPLAY_P3_COLOR_RE = /color\s*:\s*color\(\s*display-p3\s+0\s+0\s+0%\s*\)/;
|
|
6945
7094
|
const DISPLAY_P3_VALUE_RE$1 = /color\(\s*display-p3\b/i;
|
|
6946
7095
|
const COLOR_GAMUT_P3_RE$1 = /\(\s*color-gamut\s*:\s*p3\s*\)/i;
|
|
6947
|
-
|
|
7096
|
+
const RADIUS_VALUE_RE = /\b([+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?)\s*(r?px)\b/gi;
|
|
7097
|
+
const SCIENTIFIC_NOTATION_RE = /e/i;
|
|
7098
|
+
const TW_VAR_FUNCTION_RE = /var\(\s*(--tw-[\w-]+)\b/g;
|
|
7099
|
+
const TW_CONTENT_VAR_RE$1 = /var\(\s*--tw-content\b/;
|
|
7100
|
+
const DEFAULT_VARIABLE_SCOPE_SELECTORS = new Set([
|
|
7101
|
+
"*",
|
|
7102
|
+
":root",
|
|
7103
|
+
":host",
|
|
7104
|
+
"page",
|
|
7105
|
+
".tw-root",
|
|
7106
|
+
"wx-root-portal-content",
|
|
7107
|
+
"view",
|
|
7108
|
+
"text",
|
|
7109
|
+
":before",
|
|
7110
|
+
":after",
|
|
7111
|
+
"::before",
|
|
7112
|
+
"::after",
|
|
7113
|
+
"::backdrop"
|
|
7114
|
+
]);
|
|
7115
|
+
function isTailwindcssV4(options) {
|
|
7116
|
+
return options?.majorVersion === 4;
|
|
7117
|
+
}
|
|
7118
|
+
function testIfRootHostForV4(node) {
|
|
7119
|
+
return node.type === "rule" && node.selector.includes(":root") && node.selector.includes(":host");
|
|
7120
|
+
}
|
|
7121
|
+
createCssVarNodes(nodes);
|
|
7122
|
+
function collectUsedTailwindcssV4Variables(root) {
|
|
7123
|
+
const props = /* @__PURE__ */ new Set();
|
|
7124
|
+
root.walkDecls((decl) => {
|
|
7125
|
+
if (decl.prop.startsWith("--tw-")) props.add(decl.prop);
|
|
7126
|
+
TW_VAR_FUNCTION_RE.lastIndex = 0;
|
|
7127
|
+
let match = TW_VAR_FUNCTION_RE.exec(decl.value);
|
|
7128
|
+
while (match !== null) {
|
|
7129
|
+
const prop = match[1];
|
|
7130
|
+
if (prop) props.add(prop);
|
|
7131
|
+
match = TW_VAR_FUNCTION_RE.exec(decl.value);
|
|
7132
|
+
}
|
|
7133
|
+
});
|
|
7134
|
+
root.walkAtRules("property", (atRule) => {
|
|
7135
|
+
const prop = atRule.params.trim();
|
|
7136
|
+
if (prop.startsWith("--tw-")) props.add(prop);
|
|
7137
|
+
});
|
|
7138
|
+
return props;
|
|
7139
|
+
}
|
|
7140
|
+
function usesTailwindcssV4ContentVariable(root) {
|
|
7141
|
+
let used = false;
|
|
7142
|
+
root.walkDecls((decl) => {
|
|
7143
|
+
if (TW_CONTENT_VAR_RE$1.test(decl.value)) used = true;
|
|
7144
|
+
});
|
|
7145
|
+
return used;
|
|
7146
|
+
}
|
|
7147
|
+
function createUsedCssVarsV4Nodes(usedProps) {
|
|
7148
|
+
return nodes.filter((def) => usedProps.has(def.prop)).map((def) => new Declaration({
|
|
7149
|
+
prop: def.prop,
|
|
7150
|
+
value: def.value
|
|
7151
|
+
}));
|
|
7152
|
+
}
|
|
7153
|
+
function isInsideAtRule(decl, name) {
|
|
7154
|
+
let parent = decl.parent;
|
|
7155
|
+
while (parent) {
|
|
7156
|
+
if (parent.type === "atrule" && parent.name === name) return true;
|
|
7157
|
+
parent = parent.parent;
|
|
7158
|
+
}
|
|
7159
|
+
return false;
|
|
7160
|
+
}
|
|
7161
|
+
function isDefaultVariableScopeRule(rule) {
|
|
7162
|
+
if (!rule.selectors.every((selector) => DEFAULT_VARIABLE_SCOPE_SELECTORS.has(selector.trim()))) return false;
|
|
7163
|
+
let hasDeclaration = false;
|
|
7164
|
+
let onlyCustomProperties = true;
|
|
7165
|
+
rule.each((node) => {
|
|
7166
|
+
if (node.type !== "decl") return;
|
|
7167
|
+
hasDeclaration = true;
|
|
7168
|
+
if (!node.prop.startsWith("--")) onlyCustomProperties = false;
|
|
7169
|
+
});
|
|
7170
|
+
return hasDeclaration && onlyCustomProperties;
|
|
7171
|
+
}
|
|
7172
|
+
function collectScopedTailwindcssV4DefaultVariables(root) {
|
|
7173
|
+
const props = /* @__PURE__ */ new Set();
|
|
7174
|
+
root.walkDecls((decl) => {
|
|
7175
|
+
if (!decl.prop.startsWith("--tw-")) return;
|
|
7176
|
+
if (isInsideAtRule(decl, "supports")) return;
|
|
7177
|
+
if (decl.parent?.type === "rule" && isDefaultVariableScopeRule(decl.parent)) props.add(decl.prop);
|
|
7178
|
+
});
|
|
7179
|
+
return props;
|
|
7180
|
+
}
|
|
7181
|
+
function createMissingCssVarsV4Nodes(root, usedProps) {
|
|
7182
|
+
const scopedProps = collectScopedTailwindcssV4DefaultVariables(root);
|
|
7183
|
+
return nodes.filter((def) => usedProps.has(def.prop) && !scopedProps.has(def.prop)).map((def) => new Declaration({
|
|
7184
|
+
prop: def.prop,
|
|
7185
|
+
value: def.value
|
|
7186
|
+
}));
|
|
7187
|
+
}
|
|
7188
|
+
function isTailwindcssV4ModernCheck(atRule) {
|
|
7189
|
+
return atRule.name === "supports" && [
|
|
7190
|
+
MODERN_CHECK_WEBKIT_HYPHENS_RE,
|
|
7191
|
+
MODERN_CHECK_MARGIN_TRIM_RE,
|
|
7192
|
+
MODERN_CHECK_MOZ_ORIENT_RE,
|
|
7193
|
+
MODERN_CHECK_COLOR_RGB_RE
|
|
7194
|
+
].every((regex) => regex.test(atRule.params));
|
|
7195
|
+
}
|
|
7196
|
+
function isTailwindcssV4LinearGradientSupports(atRule) {
|
|
7197
|
+
return atRule.name === "supports" && LINEAR_GRADIENT_LAB_RE.test(atRule.params);
|
|
7198
|
+
}
|
|
7199
|
+
function isTailwindcssV4DisplayP3Supports(atRule) {
|
|
7200
|
+
return atRule.name === "supports" && DISPLAY_P3_COLOR_RE.test(atRule.params);
|
|
7201
|
+
}
|
|
7202
|
+
function isTailwindcssV4DisplayP3Media(atRule) {
|
|
6948
7203
|
return atRule.name === "media" && COLOR_GAMUT_P3_RE$1.test(atRule.params);
|
|
6949
7204
|
}
|
|
6950
|
-
function
|
|
7205
|
+
function isTailwindcssV4DisplayP3Declaration(decl) {
|
|
6951
7206
|
return DISPLAY_P3_VALUE_RE$1.test(decl.value);
|
|
6952
7207
|
}
|
|
7208
|
+
function normalizeTailwindcssV4Declaration(decl) {
|
|
7209
|
+
if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OKLAB_SUFFIX)) {
|
|
7210
|
+
decl.value = decl.value.slice(0, decl.value.length - 8);
|
|
7211
|
+
return true;
|
|
7212
|
+
}
|
|
7213
|
+
if (INFINITY_CALC_REGEXP.test(decl.value)) {
|
|
7214
|
+
decl.value = `${CLAMP_PX}px`;
|
|
7215
|
+
return true;
|
|
7216
|
+
}
|
|
7217
|
+
if (decl.prop.includes("radius")) {
|
|
7218
|
+
RADIUS_VALUE_RE.lastIndex = 0;
|
|
7219
|
+
const next = decl.value.replace(RADIUS_VALUE_RE, (m, num) => {
|
|
7220
|
+
const n = Number(num);
|
|
7221
|
+
if (!Number.isFinite(n)) return `${CLAMP_PX}px`;
|
|
7222
|
+
if (SCIENTIFIC_NOTATION_RE.test(String(num)) || n > RADIUS_THRESHOLD) return `${CLAMP_PX}px`;
|
|
7223
|
+
return m;
|
|
7224
|
+
});
|
|
7225
|
+
if (next !== decl.value) {
|
|
7226
|
+
decl.value = next;
|
|
7227
|
+
return true;
|
|
7228
|
+
}
|
|
7229
|
+
}
|
|
7230
|
+
return false;
|
|
7231
|
+
}
|
|
7232
|
+
//#endregion
|
|
7233
|
+
//#region src/compat/mini-program-css/color-gamut.ts
|
|
7234
|
+
const DISPLAY_P3_VALUE_RE = /color\(\s*display-p3\b/i;
|
|
7235
|
+
const COLOR_GAMUT_P3_RE = /\(\s*color-gamut\s*:\s*p3\s*\)/i;
|
|
7236
|
+
function isDisplayP3MediaRule(atRule) {
|
|
7237
|
+
return atRule.name === "media" && COLOR_GAMUT_P3_RE.test(atRule.params);
|
|
7238
|
+
}
|
|
7239
|
+
function isDisplayP3Declaration(decl) {
|
|
7240
|
+
return DISPLAY_P3_VALUE_RE.test(decl.value);
|
|
7241
|
+
}
|
|
6953
7242
|
//#endregion
|
|
6954
7243
|
//#region src/compat/mini-program-css/selectors.ts
|
|
6955
7244
|
const MINI_PROGRAM_THEME_SCOPE_SELECTOR = ":host,page,.tw-root,wx-root-portal-content";
|
|
6956
|
-
const
|
|
6957
|
-
|
|
7245
|
+
const MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR = "view,text,::after,::before";
|
|
7246
|
+
const MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS = new Set([
|
|
6958
7247
|
"view",
|
|
6959
7248
|
"text",
|
|
6960
7249
|
":before",
|
|
@@ -6962,6 +7251,7 @@ const MINI_PROGRAM_PREFLIGHT_SELECTORS = new Set([
|
|
|
6962
7251
|
"::before",
|
|
6963
7252
|
"::after"
|
|
6964
7253
|
]);
|
|
7254
|
+
const MINI_PROGRAM_PREFLIGHT_SELECTORS = new Set(["*", ...MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS]);
|
|
6965
7255
|
const MINI_PROGRAM_THEME_SCOPE_SELECTORS = new Set([
|
|
6966
7256
|
":host",
|
|
6967
7257
|
":root",
|
|
@@ -7040,8 +7330,14 @@ const MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS = new Set([
|
|
|
7040
7330
|
function normalizeSelector$1(selector) {
|
|
7041
7331
|
return selector.trim().replace(/\s+/g, "");
|
|
7042
7332
|
}
|
|
7333
|
+
function normalizePseudoElementSelector(selector) {
|
|
7334
|
+
return normalizeSelector$1(selector).replace(/^:(before|after)$/, "::$1");
|
|
7335
|
+
}
|
|
7043
7336
|
function getRuleSelectors(rule) {
|
|
7044
|
-
return rule.selector.split(",").map(
|
|
7337
|
+
return rule.selector.split(",").map(normalizePseudoElementSelector).filter(Boolean);
|
|
7338
|
+
}
|
|
7339
|
+
function getSortedRuleSelectorKey(rule) {
|
|
7340
|
+
return getRuleSelectors(rule).sort().join(",");
|
|
7045
7341
|
}
|
|
7046
7342
|
function isUnsupportedBrowserSelector(selector) {
|
|
7047
7343
|
const normalized = normalizeSelector$1(selector);
|
|
@@ -7065,7 +7361,7 @@ const PREFLIGHT_RESET_PROPS = new Set([
|
|
|
7065
7361
|
"padding"
|
|
7066
7362
|
]);
|
|
7067
7363
|
const PSEUDO_CONTENT_SELECTOR_RE = /^(?:::before|::after|:before|:after)(?:,(?:::before|::after|:before|:after))*$/;
|
|
7068
|
-
const TW_CONTENT_VAR_RE
|
|
7364
|
+
const TW_CONTENT_VAR_RE = /var\(\s*--tw-content\b/;
|
|
7069
7365
|
function hasTailwindPreflightDeclaration(rule) {
|
|
7070
7366
|
let hasTailwindVar = false;
|
|
7071
7367
|
let hasResetProp = false;
|
|
@@ -7075,13 +7371,6 @@ function hasTailwindPreflightDeclaration(rule) {
|
|
|
7075
7371
|
});
|
|
7076
7372
|
return hasTailwindVar || hasResetProp;
|
|
7077
7373
|
}
|
|
7078
|
-
function hasTwContentDeclaration(rule) {
|
|
7079
|
-
let hasContentInit = false;
|
|
7080
|
-
rule.walkDecls("--tw-content", () => {
|
|
7081
|
-
hasContentInit = true;
|
|
7082
|
-
});
|
|
7083
|
-
return hasContentInit;
|
|
7084
|
-
}
|
|
7085
7374
|
function isCustomPropertyRule(rule) {
|
|
7086
7375
|
let hasDeclaration = false;
|
|
7087
7376
|
let allCustomProperties = true;
|
|
@@ -7111,7 +7400,7 @@ function isPseudoContentInitRule(rule) {
|
|
|
7111
7400
|
function usesTwContentVariable(root) {
|
|
7112
7401
|
let used = false;
|
|
7113
7402
|
root.walkDecls((decl) => {
|
|
7114
|
-
if (TW_CONTENT_VAR_RE
|
|
7403
|
+
if (TW_CONTENT_VAR_RE.test(decl.value)) used = true;
|
|
7115
7404
|
});
|
|
7116
7405
|
return used;
|
|
7117
7406
|
}
|
|
@@ -7194,8 +7483,11 @@ function removeUnsupportedModernColorDeclarations(root) {
|
|
|
7194
7483
|
//#endregion
|
|
7195
7484
|
//#region src/compat/mini-program-css/finalize.ts
|
|
7196
7485
|
const HOIST_ANCHOR_COMMENT = "__weapp_tailwindcss_base_anchor__";
|
|
7486
|
+
const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
|
|
7487
|
+
const MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR = "::before,\n::after";
|
|
7488
|
+
const MINI_PROGRAM_PSEUDO_CONTENT_SELECTORS = new Set(["::before", "::after"]);
|
|
7197
7489
|
function createPseudoContentInitRule() {
|
|
7198
|
-
const rule = postcss.rule({ selector:
|
|
7490
|
+
const rule = postcss.rule({ selector: MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR });
|
|
7199
7491
|
rule.append({
|
|
7200
7492
|
prop: "--tw-content",
|
|
7201
7493
|
value: "''"
|
|
@@ -7204,22 +7496,29 @@ function createPseudoContentInitRule() {
|
|
|
7204
7496
|
}
|
|
7205
7497
|
function collectPreflightRules(root, options = {}) {
|
|
7206
7498
|
const preflightNodes = [];
|
|
7207
|
-
|
|
7208
|
-
for (const node of root.nodes ?? []) if (isMiniProgramPreflightRule(node)) {
|
|
7209
|
-
preflightNodes.push(node);
|
|
7210
|
-
if (hasTwContentDeclaration(node)) hasContentInit = true;
|
|
7211
|
-
}
|
|
7499
|
+
for (const node of root.nodes ?? []) if (isMiniProgramPreflightRule(node)) preflightNodes.push(node);
|
|
7212
7500
|
if (preflightNodes.length === 0) return [];
|
|
7213
|
-
const clonedPreflightRules = preflightNodes.map((node) =>
|
|
7214
|
-
|
|
7215
|
-
|
|
7216
|
-
|
|
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];
|
|
7217
7516
|
for (const node of preflightNodes) node.remove();
|
|
7218
7517
|
return preflightRules;
|
|
7219
7518
|
}
|
|
7220
7519
|
function createPreflightResetRule(cssPreflight) {
|
|
7221
7520
|
if (!cssPreflight || typeof cssPreflight !== "object") return;
|
|
7222
|
-
const rule = postcss.rule({ selector:
|
|
7521
|
+
const rule = postcss.rule({ selector: MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR });
|
|
7223
7522
|
for (const [prop, value] of Object.entries(cssPreflight)) {
|
|
7224
7523
|
if (value === false) continue;
|
|
7225
7524
|
rule.append({
|
|
@@ -7248,6 +7547,18 @@ function collectThemeVariableRule(root, options = {}) {
|
|
|
7248
7547
|
for (const decl of declarations.values()) rule.append(decl);
|
|
7249
7548
|
return rule;
|
|
7250
7549
|
}
|
|
7550
|
+
function hasTailwindcssV4Signal(css) {
|
|
7551
|
+
if (TAILWIND_V4_BANNER_RE.test(css)) return true;
|
|
7552
|
+
const root = postcss.parse(css);
|
|
7553
|
+
let hasProperty = false;
|
|
7554
|
+
root.walkAtRules("property", (atRule) => {
|
|
7555
|
+
if (atRule.params.trim().startsWith("--tw-")) {
|
|
7556
|
+
hasProperty = true;
|
|
7557
|
+
return false;
|
|
7558
|
+
}
|
|
7559
|
+
});
|
|
7560
|
+
return hasProperty;
|
|
7561
|
+
}
|
|
7251
7562
|
function getTopDirectiveTail(root) {
|
|
7252
7563
|
let tail;
|
|
7253
7564
|
for (const node of root.nodes ?? []) {
|
|
@@ -7285,12 +7596,28 @@ function insertHoistedRules(root, rules, anchor) {
|
|
|
7285
7596
|
if (topDirectiveTail) topDirectiveTail.after(rules);
|
|
7286
7597
|
else root.prepend(rules);
|
|
7287
7598
|
}
|
|
7599
|
+
function mergeEquivalentHoistedRules(rules) {
|
|
7600
|
+
const mergedRules = [];
|
|
7601
|
+
const ruleBySelector = /* @__PURE__ */ new Map();
|
|
7602
|
+
for (const rule of rules) {
|
|
7603
|
+
const key = getSortedRuleSelectorKey(rule);
|
|
7604
|
+
const existingRule = ruleBySelector.get(key);
|
|
7605
|
+
if (existingRule) {
|
|
7606
|
+
existingRule.append(...(rule.nodes ?? []).map((node) => node.clone()));
|
|
7607
|
+
continue;
|
|
7608
|
+
}
|
|
7609
|
+
ruleBySelector.set(key, rule);
|
|
7610
|
+
mergedRules.push(rule);
|
|
7611
|
+
}
|
|
7612
|
+
return mergedRules;
|
|
7613
|
+
}
|
|
7288
7614
|
function unwrapTailwindSourceMedia(root) {
|
|
7289
7615
|
root.walkAtRules("media", (atRule) => {
|
|
7290
7616
|
if (atRule.params.startsWith("source(") && atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
|
|
7291
7617
|
});
|
|
7292
7618
|
}
|
|
7293
7619
|
function finalizeMiniProgramCssRoot(root, options = {}) {
|
|
7620
|
+
const tailwindcssV4DefaultNodes = options.isTailwindcssV4 === true ? createMissingCssVarsV4Nodes(root, collectUsedTailwindcssV4Variables(root)) : [];
|
|
7294
7621
|
removeUnsupportedCascadeLayers(root);
|
|
7295
7622
|
unwrapTailwindSourceMedia(root);
|
|
7296
7623
|
root.walkAtRules("property", (atRule) => {
|
|
@@ -7312,8 +7639,12 @@ function finalizeMiniProgramCssRoot(root, options = {}) {
|
|
|
7312
7639
|
const resetRule = createPreflightResetRule(options.cssPreflight);
|
|
7313
7640
|
if (resetRule) preflightRules.push(resetRule);
|
|
7314
7641
|
}
|
|
7642
|
+
if (tailwindcssV4DefaultNodes.length > 0) preflightRules.push(postcss.rule({
|
|
7643
|
+
selector: MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR,
|
|
7644
|
+
nodes: tailwindcssV4DefaultNodes
|
|
7645
|
+
}));
|
|
7315
7646
|
const themeRule = collectThemeVariableRule(root, options);
|
|
7316
|
-
insertHoistedRules(root, themeRule ? [...preflightRules, themeRule] : preflightRules, hoistAnchor);
|
|
7647
|
+
insertHoistedRules(root, mergeEquivalentHoistedRules(themeRule ? [...preflightRules, themeRule] : preflightRules), hoistAnchor);
|
|
7317
7648
|
}
|
|
7318
7649
|
function hoistTailwindPreflightBase(css) {
|
|
7319
7650
|
try {
|
|
@@ -7325,10 +7656,19 @@ function hoistTailwindPreflightBase(css) {
|
|
|
7325
7656
|
}
|
|
7326
7657
|
}
|
|
7327
7658
|
function finalizeMiniProgramCss(css, options = {}) {
|
|
7659
|
+
let isTailwindcssV4 = options.isTailwindcssV4;
|
|
7660
|
+
if (isTailwindcssV4 === void 0) try {
|
|
7661
|
+
isTailwindcssV4 = hasTailwindcssV4Signal(css);
|
|
7662
|
+
} catch {
|
|
7663
|
+
isTailwindcssV4 = TAILWIND_V4_BANNER_RE.test(css);
|
|
7664
|
+
}
|
|
7328
7665
|
const cleanedCss = removeUnsupportedMiniProgramAtRules(css);
|
|
7329
7666
|
try {
|
|
7330
7667
|
const root = postcss.parse(cleanedCss);
|
|
7331
|
-
finalizeMiniProgramCssRoot(root,
|
|
7668
|
+
finalizeMiniProgramCssRoot(root, {
|
|
7669
|
+
...options,
|
|
7670
|
+
isTailwindcssV4
|
|
7671
|
+
});
|
|
7332
7672
|
return root.toString();
|
|
7333
7673
|
} catch {
|
|
7334
7674
|
return cleanedCss;
|
|
@@ -7337,16 +7677,7 @@ function finalizeMiniProgramCss(css, options = {}) {
|
|
|
7337
7677
|
//#endregion
|
|
7338
7678
|
//#region src/compat/mini-program-css/prune-generated.ts
|
|
7339
7679
|
const DEFAULT_WEAPP_VARIABLE_SCOPE = "page,.tw-root,wx-root-portal-content,:host";
|
|
7340
|
-
const DEFAULT_WEAPP_ELEMENT_VARIABLE_SCOPE = "view,text,:before,:after";
|
|
7341
7680
|
const CLASS_SELECTOR_RE$1 = /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i;
|
|
7342
|
-
const MINI_PROGRAM_ELEMENT_VARIABLE_SCOPE_SELECTORS = new Set([
|
|
7343
|
-
"view",
|
|
7344
|
-
"text",
|
|
7345
|
-
":before",
|
|
7346
|
-
":after",
|
|
7347
|
-
"::before",
|
|
7348
|
-
"::after"
|
|
7349
|
-
]);
|
|
7350
7681
|
function isConditionalCompilationComment(text) {
|
|
7351
7682
|
return /#(?:ifn?def|endif)\b/.test(text);
|
|
7352
7683
|
}
|
|
@@ -7360,7 +7691,7 @@ function removeEmptyContentInitDeclarations(rule) {
|
|
|
7360
7691
|
}
|
|
7361
7692
|
function isMiniProgramElementVariableScopeRule(rule) {
|
|
7362
7693
|
const selectors = getRuleSelectors(rule);
|
|
7363
|
-
return selectors.length > 0 && selectors.every((selector) =>
|
|
7694
|
+
return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS.has(selector));
|
|
7364
7695
|
}
|
|
7365
7696
|
function isTailwindV4GradientRuntimeDeclaration(decl) {
|
|
7366
7697
|
return decl.prop.startsWith("--tw-gradient-");
|
|
@@ -7374,7 +7705,7 @@ function moveTailwindV4GradientRuntimeDeclarations(rule) {
|
|
|
7374
7705
|
}
|
|
7375
7706
|
});
|
|
7376
7707
|
if (gradientDeclarations.length > 0) rule.before(new postcss.Rule({
|
|
7377
|
-
selector:
|
|
7708
|
+
selector: MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR,
|
|
7378
7709
|
nodes: gradientDeclarations
|
|
7379
7710
|
}));
|
|
7380
7711
|
if (rule.nodes.length === 0) rule.remove();
|
|
@@ -7411,7 +7742,7 @@ function pruneMiniProgramGeneratedCss(css, options = {}) {
|
|
|
7411
7742
|
root.walkRules((rule) => {
|
|
7412
7743
|
if (isKeyframesRule(rule)) return;
|
|
7413
7744
|
if (isCustomPropertyRule(rule) && isMiniProgramElementVariableScopeRule(rule)) {
|
|
7414
|
-
rule.selector =
|
|
7745
|
+
rule.selector = MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR;
|
|
7415
7746
|
return;
|
|
7416
7747
|
}
|
|
7417
7748
|
if (isMiniProgramThemeVariableRule(rule)) {
|
|
@@ -52477,245 +52808,6 @@ function normalizeTailwindcssRpxDeclaration(decl, options) {
|
|
|
52477
52808
|
return false;
|
|
52478
52809
|
}
|
|
52479
52810
|
//#endregion
|
|
52480
|
-
//#region src/cssVarsV4.ts
|
|
52481
|
-
function property(ident, initialValue, _syntax) {
|
|
52482
|
-
return {
|
|
52483
|
-
prop: ident,
|
|
52484
|
-
value: initialValue || ""
|
|
52485
|
-
};
|
|
52486
|
-
}
|
|
52487
|
-
const nullShadow = "0 0 #0000";
|
|
52488
|
-
const nodes = [
|
|
52489
|
-
property("--tw-border-spacing-x", "0", "<length>"),
|
|
52490
|
-
property("--tw-border-spacing-y", "0", "<length>"),
|
|
52491
|
-
property("--tw-translate-x", "0"),
|
|
52492
|
-
property("--tw-translate-y", "0"),
|
|
52493
|
-
property("--tw-translate-z", "0"),
|
|
52494
|
-
property("--tw-scale-x", "1"),
|
|
52495
|
-
property("--tw-scale-y", "1"),
|
|
52496
|
-
property("--tw-scale-z", "1"),
|
|
52497
|
-
property("--tw-rotate-x"),
|
|
52498
|
-
property("--tw-rotate-y"),
|
|
52499
|
-
property("--tw-rotate-z"),
|
|
52500
|
-
property("--tw-skew-x"),
|
|
52501
|
-
property("--tw-skew-y"),
|
|
52502
|
-
property("--tw-pan-x"),
|
|
52503
|
-
property("--tw-pan-y"),
|
|
52504
|
-
property("--tw-pinch-zoom"),
|
|
52505
|
-
property("--tw-scroll-snap-strictness", "proximity", "*"),
|
|
52506
|
-
property("--tw-space-x-reverse", "0"),
|
|
52507
|
-
property("--tw-space-y-reverse", "0"),
|
|
52508
|
-
property("--tw-scrollbar-thumb", "#0000", "<color>"),
|
|
52509
|
-
property("--tw-scrollbar-track", "#0000", "<color>"),
|
|
52510
|
-
property("--tw-border-style", "solid"),
|
|
52511
|
-
property("--tw-divide-x-reverse", "0"),
|
|
52512
|
-
property("--tw-divide-y-reverse", "0"),
|
|
52513
|
-
property("--tw-gradient-position", "initial"),
|
|
52514
|
-
property("--tw-gradient-from", "#0000", "<color>"),
|
|
52515
|
-
property("--tw-gradient-via", "#0000", "<color>"),
|
|
52516
|
-
property("--tw-gradient-to", "#0000", "<color>"),
|
|
52517
|
-
property("--tw-gradient-stops", "initial"),
|
|
52518
|
-
property("--tw-gradient-via-stops", "initial"),
|
|
52519
|
-
property("--tw-gradient-from-position", "0%", "<length-percentage>"),
|
|
52520
|
-
property("--tw-gradient-via-position", "50%", "<length-percentage>"),
|
|
52521
|
-
property("--tw-gradient-to-position", "100%", "<length-percentage>"),
|
|
52522
|
-
property("--tw-mask-linear", "linear-gradient(#fff, #fff)"),
|
|
52523
|
-
property("--tw-mask-radial", "linear-gradient(#fff, #fff)"),
|
|
52524
|
-
property("--tw-mask-conic", "linear-gradient(#fff, #fff)"),
|
|
52525
|
-
property("--tw-mask-left", "linear-gradient(#fff, #fff)"),
|
|
52526
|
-
property("--tw-mask-right", "linear-gradient(#fff, #fff)"),
|
|
52527
|
-
property("--tw-mask-bottom", "linear-gradient(#fff, #fff)"),
|
|
52528
|
-
property("--tw-mask-top", "linear-gradient(#fff, #fff)"),
|
|
52529
|
-
property("--tw-mask-linear-position", "0deg"),
|
|
52530
|
-
property("--tw-mask-linear-from-position", "0%"),
|
|
52531
|
-
property("--tw-mask-linear-to-position", "100%"),
|
|
52532
|
-
property("--tw-mask-linear-from-color", "black"),
|
|
52533
|
-
property("--tw-mask-linear-to-color", "transparent"),
|
|
52534
|
-
property("--tw-mask-radial-from-position", "0%"),
|
|
52535
|
-
property("--tw-mask-radial-to-position", "100%"),
|
|
52536
|
-
property("--tw-mask-radial-from-color", "black"),
|
|
52537
|
-
property("--tw-mask-radial-to-color", "transparent"),
|
|
52538
|
-
property("--tw-mask-radial-shape", "ellipse"),
|
|
52539
|
-
property("--tw-mask-radial-size", "farthest-corner"),
|
|
52540
|
-
property("--tw-mask-radial-position", "center"),
|
|
52541
|
-
property("--tw-mask-conic-position", "0deg"),
|
|
52542
|
-
property("--tw-mask-conic-from-position", "0%"),
|
|
52543
|
-
property("--tw-mask-conic-to-position", "100%"),
|
|
52544
|
-
property("--tw-mask-conic-from-color", "black"),
|
|
52545
|
-
property("--tw-mask-conic-to-color", "transparent"),
|
|
52546
|
-
property("--tw-font-weight"),
|
|
52547
|
-
property("--tw-blur"),
|
|
52548
|
-
property("--tw-brightness"),
|
|
52549
|
-
property("--tw-contrast"),
|
|
52550
|
-
property("--tw-grayscale"),
|
|
52551
|
-
property("--tw-hue-rotate"),
|
|
52552
|
-
property("--tw-invert"),
|
|
52553
|
-
property("--tw-opacity"),
|
|
52554
|
-
property("--tw-saturate"),
|
|
52555
|
-
property("--tw-sepia"),
|
|
52556
|
-
property("--tw-drop-shadow"),
|
|
52557
|
-
property("--tw-drop-shadow-color"),
|
|
52558
|
-
property("--tw-drop-shadow-alpha", "100%", "<percentage>"),
|
|
52559
|
-
property("--tw-drop-shadow-size"),
|
|
52560
|
-
property("--tw-backdrop-blur"),
|
|
52561
|
-
property("--tw-backdrop-brightness"),
|
|
52562
|
-
property("--tw-backdrop-contrast"),
|
|
52563
|
-
property("--tw-backdrop-grayscale"),
|
|
52564
|
-
property("--tw-backdrop-hue-rotate"),
|
|
52565
|
-
property("--tw-backdrop-invert"),
|
|
52566
|
-
property("--tw-backdrop-opacity"),
|
|
52567
|
-
property("--tw-backdrop-saturate"),
|
|
52568
|
-
property("--tw-backdrop-sepia"),
|
|
52569
|
-
property("--tw-duration", "initial"),
|
|
52570
|
-
property("--tw-ease", "initial"),
|
|
52571
|
-
property("--tw-content", "\"\""),
|
|
52572
|
-
property("--tw-contain-size"),
|
|
52573
|
-
property("--tw-contain-layout"),
|
|
52574
|
-
property("--tw-contain-paint"),
|
|
52575
|
-
property("--tw-contain-style"),
|
|
52576
|
-
property("--tw-leading"),
|
|
52577
|
-
property("--tw-tracking"),
|
|
52578
|
-
property("--tw-ordinal"),
|
|
52579
|
-
property("--tw-slashed-zero"),
|
|
52580
|
-
property("--tw-numeric-figure"),
|
|
52581
|
-
property("--tw-numeric-spacing"),
|
|
52582
|
-
property("--tw-numeric-fraction"),
|
|
52583
|
-
property("--tw-outline-style", "solid"),
|
|
52584
|
-
property("--tw-text-shadow-color", "initial"),
|
|
52585
|
-
property("--tw-text-shadow-alpha", "100%", "<percentage>"),
|
|
52586
|
-
property("--tw-shadow", nullShadow),
|
|
52587
|
-
property("--tw-shadow-color", "initial"),
|
|
52588
|
-
property("--tw-shadow-alpha", "100%", "<percentage>"),
|
|
52589
|
-
property("--tw-inset-shadow", nullShadow),
|
|
52590
|
-
property("--tw-inset-shadow-color", "initial"),
|
|
52591
|
-
property("--tw-inset-shadow-alpha", "100%", "<percentage>"),
|
|
52592
|
-
property("--tw-ring-color"),
|
|
52593
|
-
property("--tw-ring-shadow", nullShadow),
|
|
52594
|
-
property("--tw-inset-ring-color"),
|
|
52595
|
-
property("--tw-inset-ring-shadow", nullShadow),
|
|
52596
|
-
property("--tw-ring-inset"),
|
|
52597
|
-
property("--tw-ring-offset-width", "0px", "<length>"),
|
|
52598
|
-
property("--tw-ring-offset-color", "#fff"),
|
|
52599
|
-
property("--tw-ring-offset-shadow", nullShadow)
|
|
52600
|
-
];
|
|
52601
|
-
for (const edge of [
|
|
52602
|
-
"top",
|
|
52603
|
-
"right",
|
|
52604
|
-
"bottom",
|
|
52605
|
-
"left"
|
|
52606
|
-
]) nodes.push(property(`--tw-mask-${edge}-from-position`, "0%"), property(`--tw-mask-${edge}-to-position`, "100%"), property(`--tw-mask-${edge}-from-color`, "black"), property(`--tw-mask-${edge}-to-color`, "transparent"));
|
|
52607
|
-
//#endregion
|
|
52608
|
-
//#region src/utils/css-vars.ts
|
|
52609
|
-
/**
|
|
52610
|
-
* 将 CSS 变量定义转换为可直接插入的 Declaration 节点列表。
|
|
52611
|
-
*/
|
|
52612
|
-
function createCssVarNodes(definitions) {
|
|
52613
|
-
return definitions.map((def) => new Declaration({
|
|
52614
|
-
prop: def.prop,
|
|
52615
|
-
value: def.value
|
|
52616
|
-
}));
|
|
52617
|
-
}
|
|
52618
|
-
//#endregion
|
|
52619
|
-
//#region src/compat/tailwindcss-v4.ts
|
|
52620
|
-
const OKLAB_SUFFIX = "in oklab";
|
|
52621
|
-
const INFINITY_CALC_REGEXP = /calc\(\s*infinity\s*\*\s*(?:\d+(?:\.\d*)?|\.\d+)r?px/;
|
|
52622
|
-
const RADIUS_THRESHOLD = 1e5;
|
|
52623
|
-
const CLAMP_PX = 9999;
|
|
52624
|
-
const MODERN_CHECK_WEBKIT_HYPHENS_RE = /-webkit-hyphens\s*:\s*none/;
|
|
52625
|
-
const MODERN_CHECK_MARGIN_TRIM_RE = /margin-trim\s*:\s*inline/;
|
|
52626
|
-
const MODERN_CHECK_MOZ_ORIENT_RE = /-moz-orient\s*:\s*inline/;
|
|
52627
|
-
const MODERN_CHECK_COLOR_RGB_RE = /color\s*:\s*rgb\(\s*from\s+red\s+r\s+g\s+b\s*\)/;
|
|
52628
|
-
const LINEAR_GRADIENT_LAB_RE = /background-image\s*:\s*linear-gradient\(\s*in\s+lab\s*,\s*red\s*,\s*red\s*\)/;
|
|
52629
|
-
const DISPLAY_P3_COLOR_RE = /color\s*:\s*color\(\s*display-p3\s+0\s+0\s+0%\s*\)/;
|
|
52630
|
-
const DISPLAY_P3_VALUE_RE = /color\(\s*display-p3\b/i;
|
|
52631
|
-
const COLOR_GAMUT_P3_RE = /\(\s*color-gamut\s*:\s*p3\s*\)/i;
|
|
52632
|
-
const RADIUS_VALUE_RE = /\b([+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?)\s*(r?px)\b/gi;
|
|
52633
|
-
const SCIENTIFIC_NOTATION_RE = /e/i;
|
|
52634
|
-
const TW_VAR_FUNCTION_RE = /var\(\s*(--tw-[\w-]+)\b/g;
|
|
52635
|
-
const TW_CONTENT_VAR_RE = /var\(\s*--tw-content\b/;
|
|
52636
|
-
function isTailwindcssV4(options) {
|
|
52637
|
-
return options?.majorVersion === 4;
|
|
52638
|
-
}
|
|
52639
|
-
function testIfRootHostForV4(node) {
|
|
52640
|
-
return node.type === "rule" && node.selector.includes(":root") && node.selector.includes(":host");
|
|
52641
|
-
}
|
|
52642
|
-
createCssVarNodes(nodes);
|
|
52643
|
-
function collectUsedTailwindcssV4Variables(root) {
|
|
52644
|
-
const props = /* @__PURE__ */ new Set();
|
|
52645
|
-
root.walkDecls((decl) => {
|
|
52646
|
-
if (decl.prop.startsWith("--tw-")) props.add(decl.prop);
|
|
52647
|
-
TW_VAR_FUNCTION_RE.lastIndex = 0;
|
|
52648
|
-
let match = TW_VAR_FUNCTION_RE.exec(decl.value);
|
|
52649
|
-
while (match !== null) {
|
|
52650
|
-
const prop = match[1];
|
|
52651
|
-
if (prop) props.add(prop);
|
|
52652
|
-
match = TW_VAR_FUNCTION_RE.exec(decl.value);
|
|
52653
|
-
}
|
|
52654
|
-
});
|
|
52655
|
-
root.walkAtRules("property", (atRule) => {
|
|
52656
|
-
const prop = atRule.params.trim();
|
|
52657
|
-
if (prop.startsWith("--tw-")) props.add(prop);
|
|
52658
|
-
});
|
|
52659
|
-
return props;
|
|
52660
|
-
}
|
|
52661
|
-
function usesTailwindcssV4ContentVariable(root) {
|
|
52662
|
-
let used = false;
|
|
52663
|
-
root.walkDecls((decl) => {
|
|
52664
|
-
if (TW_CONTENT_VAR_RE.test(decl.value)) used = true;
|
|
52665
|
-
});
|
|
52666
|
-
return used;
|
|
52667
|
-
}
|
|
52668
|
-
function createUsedCssVarsV4Nodes(usedProps) {
|
|
52669
|
-
return nodes.filter((def) => usedProps.has(def.prop)).map((def) => new Declaration({
|
|
52670
|
-
prop: def.prop,
|
|
52671
|
-
value: def.value
|
|
52672
|
-
}));
|
|
52673
|
-
}
|
|
52674
|
-
function isTailwindcssV4ModernCheck(atRule) {
|
|
52675
|
-
return atRule.name === "supports" && [
|
|
52676
|
-
MODERN_CHECK_WEBKIT_HYPHENS_RE,
|
|
52677
|
-
MODERN_CHECK_MARGIN_TRIM_RE,
|
|
52678
|
-
MODERN_CHECK_MOZ_ORIENT_RE,
|
|
52679
|
-
MODERN_CHECK_COLOR_RGB_RE
|
|
52680
|
-
].every((regex) => regex.test(atRule.params));
|
|
52681
|
-
}
|
|
52682
|
-
function isTailwindcssV4LinearGradientSupports(atRule) {
|
|
52683
|
-
return atRule.name === "supports" && LINEAR_GRADIENT_LAB_RE.test(atRule.params);
|
|
52684
|
-
}
|
|
52685
|
-
function isTailwindcssV4DisplayP3Supports(atRule) {
|
|
52686
|
-
return atRule.name === "supports" && DISPLAY_P3_COLOR_RE.test(atRule.params);
|
|
52687
|
-
}
|
|
52688
|
-
function isTailwindcssV4DisplayP3Media(atRule) {
|
|
52689
|
-
return atRule.name === "media" && COLOR_GAMUT_P3_RE.test(atRule.params);
|
|
52690
|
-
}
|
|
52691
|
-
function isTailwindcssV4DisplayP3Declaration(decl) {
|
|
52692
|
-
return DISPLAY_P3_VALUE_RE.test(decl.value);
|
|
52693
|
-
}
|
|
52694
|
-
function normalizeTailwindcssV4Declaration(decl) {
|
|
52695
|
-
if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OKLAB_SUFFIX)) {
|
|
52696
|
-
decl.value = decl.value.slice(0, decl.value.length - 8);
|
|
52697
|
-
return true;
|
|
52698
|
-
}
|
|
52699
|
-
if (INFINITY_CALC_REGEXP.test(decl.value)) {
|
|
52700
|
-
decl.value = `${CLAMP_PX}px`;
|
|
52701
|
-
return true;
|
|
52702
|
-
}
|
|
52703
|
-
if (decl.prop.includes("radius")) {
|
|
52704
|
-
RADIUS_VALUE_RE.lastIndex = 0;
|
|
52705
|
-
const next = decl.value.replace(RADIUS_VALUE_RE, (m, num) => {
|
|
52706
|
-
const n = Number(num);
|
|
52707
|
-
if (!Number.isFinite(n)) return `${CLAMP_PX}px`;
|
|
52708
|
-
if (SCIENTIFIC_NOTATION_RE.test(String(num)) || n > RADIUS_THRESHOLD) return `${CLAMP_PX}px`;
|
|
52709
|
-
return m;
|
|
52710
|
-
});
|
|
52711
|
-
if (next !== decl.value) {
|
|
52712
|
-
decl.value = next;
|
|
52713
|
-
return true;
|
|
52714
|
-
}
|
|
52715
|
-
}
|
|
52716
|
-
return false;
|
|
52717
|
-
}
|
|
52718
|
-
//#endregion
|
|
52719
52811
|
//#region src/constants.ts
|
|
52720
52812
|
const postcssPlugin = "postcss-weapp-tailwindcss-rename-plugin";
|
|
52721
52813
|
//#endregion
|
|
@@ -53105,6 +53197,7 @@ const MINI_PROGRAM_UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET = new Set([
|
|
|
53105
53197
|
"::-webkit-backdrop",
|
|
53106
53198
|
"::file-selector-button"
|
|
53107
53199
|
]);
|
|
53200
|
+
const NORMALIZED_PSEUDO_ELEMENT_SELECTOR = new Map([[":before", "::before"], [":after", "::after"]]);
|
|
53108
53201
|
function shouldRemoveUnsupportedPseudoElementSelector(selector, options) {
|
|
53109
53202
|
if (!isUniAppXEnabled(options)) return selector.nodes.some((node) => node.type === "pseudo" && MINI_PROGRAM_UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
|
|
53110
53203
|
return selector.nodes.some((node) => node.type === "pseudo" && UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
|
|
@@ -53141,6 +53234,11 @@ function handlePseudoNode(node, index, context, parent) {
|
|
|
53141
53234
|
node.value = context.rootReplacement;
|
|
53142
53235
|
return;
|
|
53143
53236
|
}
|
|
53237
|
+
const normalizedPseudoElement = NORMALIZED_PSEUDO_ELEMENT_SELECTOR.get(node.value);
|
|
53238
|
+
if (normalizedPseudoElement) {
|
|
53239
|
+
node.value = normalizedPseudoElement;
|
|
53240
|
+
return;
|
|
53241
|
+
}
|
|
53144
53242
|
if (node.value === ":where") flattenWherePseudo(node, context, index, parent);
|
|
53145
53243
|
}
|
|
53146
53244
|
function handleTagOrAttribute(node, context) {
|
|
@@ -53599,12 +53697,21 @@ function removeLegacyFlexboxPrefix(decl) {
|
|
|
53599
53697
|
}
|
|
53600
53698
|
if (LEGACY_FLEXBOX_DECLARATION_PROPS.has(decl.prop)) decl.remove();
|
|
53601
53699
|
}
|
|
53700
|
+
function injectMissingTailwindcssV4Defaults(root) {
|
|
53701
|
+
const nodes = createMissingCssVarsV4Nodes(root, collectUsedTailwindcssV4Variables(root));
|
|
53702
|
+
if (nodes.length === 0) return;
|
|
53703
|
+
root.append({
|
|
53704
|
+
selector: MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR,
|
|
53705
|
+
nodes
|
|
53706
|
+
});
|
|
53707
|
+
}
|
|
53602
53708
|
const postcssWeappTailwindcssPostPlugin = (options) => {
|
|
53603
53709
|
const opts = defu(options, { isMainChunk: true });
|
|
53604
53710
|
const p = { postcssPlugin };
|
|
53605
53711
|
const cleanRootSpecificity = createRootSpecificityCleaner(opts);
|
|
53606
53712
|
const cleanFallbackPlaceholder = createFallbackPlaceholderCleaner();
|
|
53607
53713
|
const shouldAppendHostSelector = createHostSelectorAppender(opts);
|
|
53714
|
+
let shouldInjectTailwindcssV4Defaults = false;
|
|
53608
53715
|
const enableMainChunkTransforms = opts.isMainChunk !== false;
|
|
53609
53716
|
if (enableMainChunkTransforms || cleanRootSpecificity) {
|
|
53610
53717
|
const fallbackRemove = enableMainChunkTransforms ? getFallbackRemove(void 0, opts) : void 0;
|
|
@@ -53641,13 +53748,17 @@ const postcssWeappTailwindcssPostPlugin = (options) => {
|
|
|
53641
53748
|
root.walkAtRules((atRule) => {
|
|
53642
53749
|
removeUnsupportedMiniProgramPrefixedAtRule(atRule);
|
|
53643
53750
|
});
|
|
53751
|
+
if (shouldInjectTailwindcssV4Defaults) injectMissingTailwindcssV4Defaults(root);
|
|
53644
53752
|
};
|
|
53645
53753
|
p.AtRuleExit = (atRule) => {
|
|
53646
53754
|
removeUnsupportedMiniProgramPrefixedAtRule(atRule);
|
|
53647
53755
|
/**
|
|
53648
53756
|
* @description 移除 property
|
|
53649
53757
|
*/
|
|
53650
|
-
if (opts.cssRemoveProperty && atRule.name === "property")
|
|
53758
|
+
if (opts.cssRemoveProperty && atRule.name === "property") {
|
|
53759
|
+
if (opts.majorVersion === 4 && atRule.params.trim().startsWith("--tw-")) shouldInjectTailwindcssV4Defaults = true;
|
|
53760
|
+
atRule.remove();
|
|
53761
|
+
}
|
|
53651
53762
|
/**
|
|
53652
53763
|
* 清除空节点
|
|
53653
53764
|
*/
|