@weapp-tailwindcss/postcss 3.2.1 → 3.2.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/color-mix.d.ts +4 -0
- package/dist/compat/tailwindcss-v4/variables.d.ts +2 -0
- package/dist/compat/tailwindcss-v4.d.ts +1 -1
- package/dist/compat/uni-app-x-uvue/theme.d.ts +4 -0
- package/dist/index.cjs +105 -7
- package/dist/index.d.ts +1 -1
- package/dist/index.js +104 -7
- package/package.json +2 -2
|
@@ -10,5 +10,9 @@ export interface ModernColorValueNormalization {
|
|
|
10
10
|
changed: boolean;
|
|
11
11
|
hasUnsupported: boolean;
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* 保护带 fallback 的作者 CSS 变量,避免兼容插件把它错误静态化。
|
|
15
|
+
*/
|
|
16
|
+
export declare function protectDynamicVarFallbacks(css: string): DynamicColorMixAlphaProtection;
|
|
13
17
|
export declare function normalizeModernColorValue(value: string, customPropertyValues?: ReadonlyMap<string, string>): ModernColorValueNormalization;
|
|
14
18
|
export declare function protectDynamicColorMixAlpha(css: string, options?: DynamicColorMixAlphaProtectionOptions): DynamicColorMixAlphaProtection;
|
|
@@ -15,6 +15,7 @@ export declare const GRADIENT_BACKGROUND_RE: RegExp;
|
|
|
15
15
|
export declare const GRADIENT_STOPS_VAR_RE: RegExp;
|
|
16
16
|
export declare const SIMPLE_CLASS_SELECTOR_RE: RegExp;
|
|
17
17
|
export declare const COLOR_VAR_RE: RegExp;
|
|
18
|
+
export declare const TAILWIND_THEME_VARIABLE_RE: RegExp;
|
|
18
19
|
export declare const GRADIENT_DIRECTION_CLASS_RE: RegExp;
|
|
19
20
|
export declare const RADIUS_VALUE_RE: RegExp;
|
|
20
21
|
export declare const SCIENTIFIC_NOTATION_RE: RegExp;
|
|
@@ -22,6 +23,7 @@ export declare const TW_GRADIENT_POSITION_PROPS: Set<string>;
|
|
|
22
23
|
export declare function isTailwindcssV4(options?: {
|
|
23
24
|
majorVersion?: 4;
|
|
24
25
|
}): boolean;
|
|
26
|
+
export declare function isTailwindcssV4ThemeVariable(property: string): boolean;
|
|
25
27
|
export declare function testIfRootHostForV4(node: Rule): boolean;
|
|
26
28
|
export declare const cssVarsV4Nodes: Declaration[];
|
|
27
29
|
export declare function collectUsedTailwindcssV4Variables(root: Root): Set<string>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { normalizeTailwindcssV4Declaration } from './tailwindcss-v4/declarations.js';
|
|
2
2
|
export { appendTailwindcssV4MiniProgramGradientRules, mergeTailwindcssV4GradientDirectionRules, normalizeTailwindcssV4GradientPosition, normalizeTailwindcssV4InfinityCalcCss, normalizeTailwindcssV4InfinityCalcValue } from './tailwindcss-v4/gradients.js';
|
|
3
3
|
export { isTailwindcssV4DisplayP3Declaration, isTailwindcssV4DisplayP3Media, isTailwindcssV4DisplayP3Supports, isTailwindcssV4LinearGradientSupports, isTailwindcssV4ModernCheck } from './tailwindcss-v4/modern-syntax.js';
|
|
4
|
-
export { collectUsedTailwindcssV4Variables, createMissingCssVarsV4Nodes, createUsedCssVarsV4Nodes, cssVarsV4Nodes, isTailwindcssV4, testIfRootHostForV4, usesTailwindcssV4ContentVariable } from './tailwindcss-v4/variables.js';
|
|
4
|
+
export { collectUsedTailwindcssV4Variables, createMissingCssVarsV4Nodes, createUsedCssVarsV4Nodes, cssVarsV4Nodes, isTailwindcssV4, isTailwindcssV4ThemeVariable, testIfRootHostForV4, usesTailwindcssV4ContentVariable } from './tailwindcss-v4/variables.js';
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { Root, Rule } from 'postcss';
|
|
2
2
|
export declare function isUniAppXSystemRootCarrierRule(rule: Rule): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* HBuilderX 不接受带 fallback 的 var() 声明,拆成静态 fallback 与动态变量两条声明。
|
|
5
|
+
*/
|
|
6
|
+
export declare function splitUnresolvedAuthorVariableFallbacks(root: Root, variables: ReadonlyMap<string, string>): boolean;
|
|
3
7
|
/**
|
|
4
8
|
* UVUE 不支持 Tailwind 的混合根选择器,因此先把根作用域中的静态主题 token
|
|
5
9
|
* 内联到实际 utility,再移除仅用于变量承载的系统规则。
|
package/dist/index.cjs
CHANGED
|
@@ -3597,6 +3597,7 @@ const GRADIENT_BACKGROUND_RE = /^(linear|radial|conic)-gradient\(/i;
|
|
|
3597
3597
|
const GRADIENT_STOPS_VAR_RE = /^(?:linear|radial|conic)-gradient\(\s*var\(\s*--tw-gradient-stops\b/i;
|
|
3598
3598
|
const SIMPLE_CLASS_SELECTOR_RE = /^\.([_a-z\u00A0-\uFFFF\\-][\w\u00A0-\uFFFF\\-]*)$/i;
|
|
3599
3599
|
const COLOR_VAR_RE = /^var\(\s*(--color-[\w-]+)\s*\)$/i;
|
|
3600
|
+
const TAILWIND_THEME_VARIABLE_RE = /^--(?:animate|aspect|blur|breakpoint|color|container|drop-shadow|ease|font|inset-shadow|leading|perspective|radius|shadow|spacing|text|tracking)(?:-|$)/;
|
|
3600
3601
|
const GRADIENT_DIRECTION_CLASS_RE = /^(?:-?bg-linear|bg-gradient-to-|-?bg-conic|bg-radial)/;
|
|
3601
3602
|
const RADIUS_VALUE_RE = /\b([+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?)\s*(r?px)\b/gi;
|
|
3602
3603
|
const SCIENTIFIC_NOTATION_RE = /e/i;
|
|
@@ -3621,6 +3622,9 @@ const DEFAULT_VARIABLE_SCOPE_SELECTORS = /* @__PURE__ */ new Set([
|
|
|
3621
3622
|
function isTailwindcssV4(options) {
|
|
3622
3623
|
return options?.majorVersion === 4;
|
|
3623
3624
|
}
|
|
3625
|
+
function isTailwindcssV4ThemeVariable(property) {
|
|
3626
|
+
return property.startsWith("--tw-") || TAILWIND_THEME_VARIABLE_RE.test(property);
|
|
3627
|
+
}
|
|
3624
3628
|
function testIfRootHostForV4(node) {
|
|
3625
3629
|
return node.type === "rule" && node.selector.includes(":root") && node.selector.includes(":host");
|
|
3626
3630
|
}
|
|
@@ -4113,6 +4117,7 @@ function isTailwindcssV4DisplayP3Declaration(decl) {
|
|
|
4113
4117
|
}
|
|
4114
4118
|
//#endregion
|
|
4115
4119
|
//#region src/compat/uni-app-x-uvue/theme.ts
|
|
4120
|
+
var import_dist$1 = /* @__PURE__ */ require_rolldown_runtime.__toESM(require_dist$2(), 1);
|
|
4116
4121
|
const SYSTEM_ROOT_SELECTORS = /* @__PURE__ */ new Set([
|
|
4117
4122
|
":host",
|
|
4118
4123
|
":root",
|
|
@@ -4153,7 +4158,7 @@ function resolveNodes(nodes, variables, resolving) {
|
|
|
4153
4158
|
const configured = variables.get(variable.value);
|
|
4154
4159
|
let replacement;
|
|
4155
4160
|
if (configured !== void 0 && !resolving.has(variable.value)) replacement = resolveThemeValue(configured, variables, /* @__PURE__ */ new Set([...resolving, variable.value]));
|
|
4156
|
-
else if (variable.value
|
|
4161
|
+
else if (fallback && isTailwindcssV4ThemeVariable(variable.value)) replacement = resolveThemeValue(fallback, variables, resolving);
|
|
4157
4162
|
if (replacement === void 0) {
|
|
4158
4163
|
resolveNodes(node.nodes, variables, resolving);
|
|
4159
4164
|
continue;
|
|
@@ -4169,6 +4174,36 @@ function resolveThemeValue(value, variables, resolving = /* @__PURE__ */ new Set
|
|
|
4169
4174
|
resolveNodes(parsed.nodes, variables, resolving);
|
|
4170
4175
|
return parsed.toString();
|
|
4171
4176
|
}
|
|
4177
|
+
function getUnresolvedAuthorVariableFallback(value) {
|
|
4178
|
+
const nodes = (0, postcss_value_parser.default)(value).nodes.filter((node) => node.type !== "space" && node.type !== "comment");
|
|
4179
|
+
const variable = nodes.length === 1 ? nodes[0] : void 0;
|
|
4180
|
+
if (variable?.type !== "function" || variable.value.toLowerCase() !== "var") return;
|
|
4181
|
+
const variableNode = variable.nodes.find((node) => node.type === "word");
|
|
4182
|
+
const commaIndex = variable.nodes.findIndex((node) => node.type === "div" && node.value === ",");
|
|
4183
|
+
if (variableNode?.type !== "word" || !variableNode.value.startsWith("--") || isTailwindcssV4ThemeVariable(variableNode.value) || variableNode.value.startsWith("--default-") || commaIndex < 0) return;
|
|
4184
|
+
const fallback = postcss_value_parser.default.stringify(variable.nodes.slice(commaIndex + 1)).trim();
|
|
4185
|
+
if (!fallback) return;
|
|
4186
|
+
return {
|
|
4187
|
+
name: variableNode.value,
|
|
4188
|
+
fallback
|
|
4189
|
+
};
|
|
4190
|
+
}
|
|
4191
|
+
/**
|
|
4192
|
+
* HBuilderX 不接受带 fallback 的 var() 声明,拆成静态 fallback 与动态变量两条声明。
|
|
4193
|
+
*/
|
|
4194
|
+
function splitUnresolvedAuthorVariableFallbacks(root, variables) {
|
|
4195
|
+
if (typeof root.walkDecls !== "function") return false;
|
|
4196
|
+
let changed = false;
|
|
4197
|
+
root.walkDecls((decl) => {
|
|
4198
|
+
if (decl.prop.startsWith("--")) return;
|
|
4199
|
+
const unresolved = getUnresolvedAuthorVariableFallback(decl.value);
|
|
4200
|
+
if (!unresolved || variables.has(unresolved.name)) return;
|
|
4201
|
+
decl.parent?.insertBefore(decl, decl.clone({ value: unresolved.fallback }));
|
|
4202
|
+
decl.value = `var(${unresolved.name})`;
|
|
4203
|
+
changed = true;
|
|
4204
|
+
});
|
|
4205
|
+
return changed;
|
|
4206
|
+
}
|
|
4172
4207
|
/**
|
|
4173
4208
|
* UVUE 不支持 Tailwind 的混合根选择器,因此先把根作用域中的静态主题 token
|
|
4174
4209
|
* 内联到实际 utility,再移除仅用于变量承载的系统规则。
|
|
@@ -4190,11 +4225,11 @@ function consumeUniAppXSystemRootTheme(root, customPropertyValues) {
|
|
|
4190
4225
|
decl.value = resolveThemeValue(decl.value, variables);
|
|
4191
4226
|
});
|
|
4192
4227
|
}
|
|
4228
|
+
splitUnresolvedAuthorVariableFallbacks(root, variables);
|
|
4193
4229
|
for (const rule of carrierRules) rule.remove();
|
|
4194
4230
|
}
|
|
4195
4231
|
//#endregion
|
|
4196
4232
|
//#region src/compat/uni-app-x-uvue.ts
|
|
4197
|
-
var import_dist$1 = /* @__PURE__ */ require_rolldown_runtime.__toESM(require_dist$2(), 1);
|
|
4198
4233
|
const ALLOWED_DISPLAY_VALUES = /* @__PURE__ */ new Set(["flex", "none"]);
|
|
4199
4234
|
const FALLBACK_CLASS_RE = /\.((?:\\.|[\w-])+)/g;
|
|
4200
4235
|
const IMPORTANT_SUFFIX_RE = /\s*!important$/i;
|
|
@@ -4208,6 +4243,14 @@ function normalizeUnsupportedMode(mode) {
|
|
|
4208
4243
|
function normalizeValue(value) {
|
|
4209
4244
|
return value.trim().toLowerCase().replace(IMPORTANT_SUFFIX_RE, "");
|
|
4210
4245
|
}
|
|
4246
|
+
function hasCalcFunction(value) {
|
|
4247
|
+
const parsed = (0, postcss_value_parser.default)(value);
|
|
4248
|
+
let found = false;
|
|
4249
|
+
parsed.walk((node) => {
|
|
4250
|
+
if (node.type === "function" && node.value.toLowerCase() === "calc") found = true;
|
|
4251
|
+
});
|
|
4252
|
+
return found;
|
|
4253
|
+
}
|
|
4211
4254
|
function normalizeUniAppXTransformValue(value) {
|
|
4212
4255
|
if (!value.toLowerCase().includes("translate(") || !value.includes(",")) return value;
|
|
4213
4256
|
const parsed = (0, postcss_value_parser.default)(value);
|
|
@@ -4252,6 +4295,7 @@ function hasOnlyClassSelectors(rule) {
|
|
|
4252
4295
|
function getUnsupportedDeclarationReason(prop, value) {
|
|
4253
4296
|
const normalizedProp = prop.trim().toLowerCase();
|
|
4254
4297
|
const normalizedValue = normalizeValue(value);
|
|
4298
|
+
if (hasCalcFunction(value)) return `${normalizedProp}: ${value}`;
|
|
4255
4299
|
if (normalizedProp === "display" && !ALLOWED_DISPLAY_VALUES.has(normalizedValue)) return `${normalizedProp}: ${value}`;
|
|
4256
4300
|
if (normalizedProp === "min-height" && normalizedValue === "100vh") return `${normalizedProp}: ${value}`;
|
|
4257
4301
|
if (normalizedProp === "grid-template-columns" || normalizedProp === "grid-template-rows" || normalizedProp === "grid-auto-columns" || normalizedProp === "grid-auto-rows" || normalizedProp === "grid-auto-flow") return `${normalizedProp}: ${value}`;
|
|
@@ -11375,6 +11419,51 @@ function tryResolveColorMix(node, customPropertyValues) {
|
|
|
11375
11419
|
}
|
|
11376
11420
|
//#endregion
|
|
11377
11421
|
//#region src/compat/color-mix.ts
|
|
11422
|
+
const DYNAMIC_VAR_FALLBACK_PLACEHOLDER_PREFIX = "__weapp_tw_var_fallback_";
|
|
11423
|
+
function getStandaloneDynamicVarWithFallback(value) {
|
|
11424
|
+
const nodes = (0, postcss_value_parser.default)(value).nodes.filter((node) => node.type !== "space" && node.type !== "comment");
|
|
11425
|
+
const variable = nodes.length === 1 ? nodes[0] : void 0;
|
|
11426
|
+
const property = variable?.type === "function" ? variable.nodes.find((node) => node.type === "word" && node.value.startsWith("--")) : void 0;
|
|
11427
|
+
if (variable?.type !== "function" || variable.value.toLowerCase() !== "var" || property?.type !== "word" || isTailwindcssV4ThemeVariable(property.value) || !variable.nodes.some((node) => node.type === "div" && node.value === ",")) return;
|
|
11428
|
+
return variable;
|
|
11429
|
+
}
|
|
11430
|
+
/**
|
|
11431
|
+
* 保护带 fallback 的作者 CSS 变量,避免兼容插件把它错误静态化。
|
|
11432
|
+
*/
|
|
11433
|
+
function protectDynamicVarFallbacks(css) {
|
|
11434
|
+
if (!css.includes("var(") || !css.includes(",")) return {
|
|
11435
|
+
css,
|
|
11436
|
+
restore: (value) => value
|
|
11437
|
+
};
|
|
11438
|
+
const replacements = /* @__PURE__ */ new Map();
|
|
11439
|
+
let root;
|
|
11440
|
+
try {
|
|
11441
|
+
root = postcss.default.parse(css);
|
|
11442
|
+
} catch {
|
|
11443
|
+
return {
|
|
11444
|
+
css,
|
|
11445
|
+
restore: (value) => value
|
|
11446
|
+
};
|
|
11447
|
+
}
|
|
11448
|
+
root.walkDecls((decl) => {
|
|
11449
|
+
if (!getStandaloneDynamicVarWithFallback(decl.value)) return;
|
|
11450
|
+
const placeholder = `${DYNAMIC_VAR_FALLBACK_PLACEHOLDER_PREFIX}${replacements.size}__`;
|
|
11451
|
+
replacements.set(placeholder, decl.value);
|
|
11452
|
+
decl.value = placeholder;
|
|
11453
|
+
});
|
|
11454
|
+
if (replacements.size === 0) return {
|
|
11455
|
+
css,
|
|
11456
|
+
restore: (value) => value
|
|
11457
|
+
};
|
|
11458
|
+
return {
|
|
11459
|
+
css: root.toString(),
|
|
11460
|
+
restore(value) {
|
|
11461
|
+
let restored = value;
|
|
11462
|
+
for (const [placeholder, replacement] of replacements) restored = restored.split(placeholder).join(replacement);
|
|
11463
|
+
return restored;
|
|
11464
|
+
}
|
|
11465
|
+
};
|
|
11466
|
+
}
|
|
11378
11467
|
function normalizeModernColorValue(value, customPropertyValues = /* @__PURE__ */ new Map()) {
|
|
11379
11468
|
if (!hasUnsupportedModernColorFunction(value)) return {
|
|
11380
11469
|
value,
|
|
@@ -48786,9 +48875,14 @@ function createStyleHandler(options) {
|
|
|
48786
48875
|
}
|
|
48787
48876
|
function processSource(rawSource, root, cloneOutput, opt) {
|
|
48788
48877
|
const resolvedOptions = resolver.resolve(opt);
|
|
48789
|
-
const
|
|
48790
|
-
const
|
|
48791
|
-
|
|
48878
|
+
const isUniAppXFramework = resolvedOptions.appType === "uni-app-x";
|
|
48879
|
+
const protectedVarFallbacks = resolvedOptions.uniAppX || isUniAppXFramework ? protectDynamicVarFallbacks(rawSource) : {
|
|
48880
|
+
css: rawSource,
|
|
48881
|
+
restore: (value) => value
|
|
48882
|
+
};
|
|
48883
|
+
const protectedColorMix = resolvedOptions.majorVersion === 4 ? protectDynamicColorMixAlpha(protectedVarFallbacks.css) : void 0;
|
|
48884
|
+
const source = protectedColorMix?.css ?? protectedVarFallbacks.css;
|
|
48885
|
+
const processInput = source !== rawSource ? source : root?.clone() ?? source;
|
|
48792
48886
|
let signal;
|
|
48793
48887
|
if (!hasUserPlugins) try {
|
|
48794
48888
|
signal = probeFeatures(source);
|
|
@@ -48815,8 +48909,8 @@ function createStyleHandler(options) {
|
|
|
48815
48909
|
finalResult = nextResult;
|
|
48816
48910
|
}
|
|
48817
48911
|
}
|
|
48818
|
-
if (protectedColorMix) {
|
|
48819
|
-
const restoredCss =
|
|
48912
|
+
if (protectedColorMix || protectedVarFallbacks.css !== rawSource) {
|
|
48913
|
+
const restoredCss = protectedVarFallbacks.restore(protectedColorMix?.restore(finalResult.css) ?? finalResult.css);
|
|
48820
48914
|
if (restoredCss !== finalResult.css) {
|
|
48821
48915
|
const nextResult = finalResult.root.clone().toResult(finalResult.opts);
|
|
48822
48916
|
nextResult.css = restoredCss;
|
|
@@ -48825,6 +48919,9 @@ function createStyleHandler(options) {
|
|
|
48825
48919
|
finalResult = nextResult;
|
|
48826
48920
|
}
|
|
48827
48921
|
}
|
|
48922
|
+
if (resolvedOptions.uniAppX && (resolvedOptions.uniAppXCssTarget === "uvue" || !isUniAppXFramework) && finalResult.root) {
|
|
48923
|
+
if (splitUnresolvedAuthorVariableFallbacks(finalResult.root, /* @__PURE__ */ new Map())) finalResult.css = finalResult.root.toString();
|
|
48924
|
+
}
|
|
48828
48925
|
resultCache.set(cacheKey, finalResult);
|
|
48829
48926
|
return cloneOutput ? cloneResult(finalResult) : finalResult;
|
|
48830
48927
|
});
|
|
@@ -49419,6 +49516,7 @@ Object.defineProperty(exports, "postcss", {
|
|
|
49419
49516
|
exports.postcssHtmlTransform = require_html_transform;
|
|
49420
49517
|
exports.prefixLocalCssImportsWithWebpackIgnoreRoot = prefixLocalCssImportsWithWebpackIgnoreRoot;
|
|
49421
49518
|
exports.protectDynamicColorMixAlpha = protectDynamicColorMixAlpha;
|
|
49519
|
+
exports.protectDynamicVarFallbacks = protectDynamicVarFallbacks;
|
|
49422
49520
|
exports.pruneMiniProgramGeneratedCss = pruneMiniProgramGeneratedCss;
|
|
49423
49521
|
exports.removeEmptyAtRules = removeEmptyAtRules;
|
|
49424
49522
|
exports.removeMatchingLocalCssImports = removeMatchingLocalCssImports;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { type PostcssAppType, type PostcssStyleBranch, type PostcssStyleBranchProfile, resolvePostcssStyleBranch, type ResolvePostcssStyleBranchOptions, resolvePostcssStyleBranchProfile, } from './branches/index.js';
|
|
2
|
-
export { type DynamicColorMixAlphaProtection, type DynamicColorMixAlphaProtectionOptions, type ModernColorValueNormalization, normalizeModernColorValue, protectDynamicColorMixAlpha, } from './compat/color-mix.js';
|
|
2
|
+
export { type DynamicColorMixAlphaProtection, type DynamicColorMixAlphaProtectionOptions, type ModernColorValueNormalization, normalizeModernColorValue, protectDynamicColorMixAlpha, protectDynamicVarFallbacks, } from './compat/color-mix.js';
|
|
3
3
|
export { consumeCascadeLayers, finalizeMiniProgramCss, hasMiniProgramCssSpecificityPlaceholders, hoistTailwindPreflightBase, normalizeMiniProgramGeneratedCssForPostcss, pruneMiniProgramGeneratedCss, removeEmptyAtRules, removeUnsupportedAtSupports, removeUnsupportedCascadeLayers, removeUnsupportedMiniProgramAtRules, stripMiniProgramCssSpecificityPlaceholders, unwrapUnsupportedCascadeLayers, } from './compat/mini-program-css/index.js';
|
|
4
4
|
export { normalizeMiniProgramPrefixedDeclaration, removeUnsupportedMiniProgramPrefixedAtRule, } from './compat/mini-program-prefixes.js';
|
|
5
5
|
export { convertTailwindcssRpxDeclarationsToRem, convertTailwindcssRpxDeclarationToRem, convertTailwindcssRpxValueToRem, normalizeTailwindcssRpxDeclaration, normalizeTailwindcssRpxDeclarations, normalizeTailwindcssWebRpxDeclarations, type TailwindcssRpxToRemOptions, } from './compat/tailwindcss-rpx.js';
|
package/dist/index.js
CHANGED
|
@@ -282,6 +282,7 @@ const GRADIENT_BACKGROUND_RE = /^(linear|radial|conic)-gradient\(/i;
|
|
|
282
282
|
const GRADIENT_STOPS_VAR_RE = /^(?:linear|radial|conic)-gradient\(\s*var\(\s*--tw-gradient-stops\b/i;
|
|
283
283
|
const SIMPLE_CLASS_SELECTOR_RE = /^\.([_a-z\u00A0-\uFFFF\\-][\w\u00A0-\uFFFF\\-]*)$/i;
|
|
284
284
|
const COLOR_VAR_RE = /^var\(\s*(--color-[\w-]+)\s*\)$/i;
|
|
285
|
+
const TAILWIND_THEME_VARIABLE_RE = /^--(?:animate|aspect|blur|breakpoint|color|container|drop-shadow|ease|font|inset-shadow|leading|perspective|radius|shadow|spacing|text|tracking)(?:-|$)/;
|
|
285
286
|
const GRADIENT_DIRECTION_CLASS_RE = /^(?:-?bg-linear|bg-gradient-to-|-?bg-conic|bg-radial)/;
|
|
286
287
|
const RADIUS_VALUE_RE = /\b([+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?)\s*(r?px)\b/gi;
|
|
287
288
|
const SCIENTIFIC_NOTATION_RE = /e/i;
|
|
@@ -306,6 +307,9 @@ const DEFAULT_VARIABLE_SCOPE_SELECTORS = /* @__PURE__ */ new Set([
|
|
|
306
307
|
function isTailwindcssV4(options) {
|
|
307
308
|
return options?.majorVersion === 4;
|
|
308
309
|
}
|
|
310
|
+
function isTailwindcssV4ThemeVariable(property) {
|
|
311
|
+
return property.startsWith("--tw-") || TAILWIND_THEME_VARIABLE_RE.test(property);
|
|
312
|
+
}
|
|
309
313
|
function testIfRootHostForV4(node) {
|
|
310
314
|
return node.type === "rule" && node.selector.includes(":root") && node.selector.includes(":host");
|
|
311
315
|
}
|
|
@@ -838,7 +842,7 @@ function resolveNodes(nodes, variables, resolving) {
|
|
|
838
842
|
const configured = variables.get(variable.value);
|
|
839
843
|
let replacement;
|
|
840
844
|
if (configured !== void 0 && !resolving.has(variable.value)) replacement = resolveThemeValue(configured, variables, /* @__PURE__ */ new Set([...resolving, variable.value]));
|
|
841
|
-
else if (variable.value
|
|
845
|
+
else if (fallback && isTailwindcssV4ThemeVariable(variable.value)) replacement = resolveThemeValue(fallback, variables, resolving);
|
|
842
846
|
if (replacement === void 0) {
|
|
843
847
|
resolveNodes(node.nodes, variables, resolving);
|
|
844
848
|
continue;
|
|
@@ -854,6 +858,36 @@ function resolveThemeValue(value, variables, resolving = /* @__PURE__ */ new Set
|
|
|
854
858
|
resolveNodes(parsed.nodes, variables, resolving);
|
|
855
859
|
return parsed.toString();
|
|
856
860
|
}
|
|
861
|
+
function getUnresolvedAuthorVariableFallback(value) {
|
|
862
|
+
const nodes = valueParser(value).nodes.filter((node) => node.type !== "space" && node.type !== "comment");
|
|
863
|
+
const variable = nodes.length === 1 ? nodes[0] : void 0;
|
|
864
|
+
if (variable?.type !== "function" || variable.value.toLowerCase() !== "var") return;
|
|
865
|
+
const variableNode = variable.nodes.find((node) => node.type === "word");
|
|
866
|
+
const commaIndex = variable.nodes.findIndex((node) => node.type === "div" && node.value === ",");
|
|
867
|
+
if (variableNode?.type !== "word" || !variableNode.value.startsWith("--") || isTailwindcssV4ThemeVariable(variableNode.value) || variableNode.value.startsWith("--default-") || commaIndex < 0) return;
|
|
868
|
+
const fallback = valueParser.stringify(variable.nodes.slice(commaIndex + 1)).trim();
|
|
869
|
+
if (!fallback) return;
|
|
870
|
+
return {
|
|
871
|
+
name: variableNode.value,
|
|
872
|
+
fallback
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* HBuilderX 不接受带 fallback 的 var() 声明,拆成静态 fallback 与动态变量两条声明。
|
|
877
|
+
*/
|
|
878
|
+
function splitUnresolvedAuthorVariableFallbacks(root, variables) {
|
|
879
|
+
if (typeof root.walkDecls !== "function") return false;
|
|
880
|
+
let changed = false;
|
|
881
|
+
root.walkDecls((decl) => {
|
|
882
|
+
if (decl.prop.startsWith("--")) return;
|
|
883
|
+
const unresolved = getUnresolvedAuthorVariableFallback(decl.value);
|
|
884
|
+
if (!unresolved || variables.has(unresolved.name)) return;
|
|
885
|
+
decl.parent?.insertBefore(decl, decl.clone({ value: unresolved.fallback }));
|
|
886
|
+
decl.value = `var(${unresolved.name})`;
|
|
887
|
+
changed = true;
|
|
888
|
+
});
|
|
889
|
+
return changed;
|
|
890
|
+
}
|
|
857
891
|
/**
|
|
858
892
|
* UVUE 不支持 Tailwind 的混合根选择器,因此先把根作用域中的静态主题 token
|
|
859
893
|
* 内联到实际 utility,再移除仅用于变量承载的系统规则。
|
|
@@ -875,6 +909,7 @@ function consumeUniAppXSystemRootTheme(root, customPropertyValues) {
|
|
|
875
909
|
decl.value = resolveThemeValue(decl.value, variables);
|
|
876
910
|
});
|
|
877
911
|
}
|
|
912
|
+
splitUnresolvedAuthorVariableFallbacks(root, variables);
|
|
878
913
|
for (const rule of carrierRules) rule.remove();
|
|
879
914
|
}
|
|
880
915
|
//#endregion
|
|
@@ -892,6 +927,14 @@ function normalizeUnsupportedMode(mode) {
|
|
|
892
927
|
function normalizeValue(value) {
|
|
893
928
|
return value.trim().toLowerCase().replace(IMPORTANT_SUFFIX_RE, "");
|
|
894
929
|
}
|
|
930
|
+
function hasCalcFunction(value) {
|
|
931
|
+
const parsed = valueParser(value);
|
|
932
|
+
let found = false;
|
|
933
|
+
parsed.walk((node) => {
|
|
934
|
+
if (node.type === "function" && node.value.toLowerCase() === "calc") found = true;
|
|
935
|
+
});
|
|
936
|
+
return found;
|
|
937
|
+
}
|
|
895
938
|
function normalizeUniAppXTransformValue(value) {
|
|
896
939
|
if (!value.toLowerCase().includes("translate(") || !value.includes(",")) return value;
|
|
897
940
|
const parsed = valueParser(value);
|
|
@@ -936,6 +979,7 @@ function hasOnlyClassSelectors(rule) {
|
|
|
936
979
|
function getUnsupportedDeclarationReason(prop, value) {
|
|
937
980
|
const normalizedProp = prop.trim().toLowerCase();
|
|
938
981
|
const normalizedValue = normalizeValue(value);
|
|
982
|
+
if (hasCalcFunction(value)) return `${normalizedProp}: ${value}`;
|
|
939
983
|
if (normalizedProp === "display" && !ALLOWED_DISPLAY_VALUES.has(normalizedValue)) return `${normalizedProp}: ${value}`;
|
|
940
984
|
if (normalizedProp === "min-height" && normalizedValue === "100vh") return `${normalizedProp}: ${value}`;
|
|
941
985
|
if (normalizedProp === "grid-template-columns" || normalizedProp === "grid-template-rows" || normalizedProp === "grid-auto-columns" || normalizedProp === "grid-auto-rows" || normalizedProp === "grid-auto-flow") return `${normalizedProp}: ${value}`;
|
|
@@ -1309,6 +1353,51 @@ function tryResolveColorMix(node, customPropertyValues) {
|
|
|
1309
1353
|
}
|
|
1310
1354
|
//#endregion
|
|
1311
1355
|
//#region src/compat/color-mix.ts
|
|
1356
|
+
const DYNAMIC_VAR_FALLBACK_PLACEHOLDER_PREFIX = "__weapp_tw_var_fallback_";
|
|
1357
|
+
function getStandaloneDynamicVarWithFallback(value) {
|
|
1358
|
+
const nodes = valueParser(value).nodes.filter((node) => node.type !== "space" && node.type !== "comment");
|
|
1359
|
+
const variable = nodes.length === 1 ? nodes[0] : void 0;
|
|
1360
|
+
const property = variable?.type === "function" ? variable.nodes.find((node) => node.type === "word" && node.value.startsWith("--")) : void 0;
|
|
1361
|
+
if (variable?.type !== "function" || variable.value.toLowerCase() !== "var" || property?.type !== "word" || isTailwindcssV4ThemeVariable(property.value) || !variable.nodes.some((node) => node.type === "div" && node.value === ",")) return;
|
|
1362
|
+
return variable;
|
|
1363
|
+
}
|
|
1364
|
+
/**
|
|
1365
|
+
* 保护带 fallback 的作者 CSS 变量,避免兼容插件把它错误静态化。
|
|
1366
|
+
*/
|
|
1367
|
+
function protectDynamicVarFallbacks(css) {
|
|
1368
|
+
if (!css.includes("var(") || !css.includes(",")) return {
|
|
1369
|
+
css,
|
|
1370
|
+
restore: (value) => value
|
|
1371
|
+
};
|
|
1372
|
+
const replacements = /* @__PURE__ */ new Map();
|
|
1373
|
+
let root;
|
|
1374
|
+
try {
|
|
1375
|
+
root = postcss$1.parse(css);
|
|
1376
|
+
} catch {
|
|
1377
|
+
return {
|
|
1378
|
+
css,
|
|
1379
|
+
restore: (value) => value
|
|
1380
|
+
};
|
|
1381
|
+
}
|
|
1382
|
+
root.walkDecls((decl) => {
|
|
1383
|
+
if (!getStandaloneDynamicVarWithFallback(decl.value)) return;
|
|
1384
|
+
const placeholder = `${DYNAMIC_VAR_FALLBACK_PLACEHOLDER_PREFIX}${replacements.size}__`;
|
|
1385
|
+
replacements.set(placeholder, decl.value);
|
|
1386
|
+
decl.value = placeholder;
|
|
1387
|
+
});
|
|
1388
|
+
if (replacements.size === 0) return {
|
|
1389
|
+
css,
|
|
1390
|
+
restore: (value) => value
|
|
1391
|
+
};
|
|
1392
|
+
return {
|
|
1393
|
+
css: root.toString(),
|
|
1394
|
+
restore(value) {
|
|
1395
|
+
let restored = value;
|
|
1396
|
+
for (const [placeholder, replacement] of replacements) restored = restored.split(placeholder).join(replacement);
|
|
1397
|
+
return restored;
|
|
1398
|
+
}
|
|
1399
|
+
};
|
|
1400
|
+
}
|
|
1312
1401
|
function normalizeModernColorValue(value, customPropertyValues = /* @__PURE__ */ new Map()) {
|
|
1313
1402
|
if (!hasUnsupportedModernColorFunction(value)) return {
|
|
1314
1403
|
value,
|
|
@@ -6355,9 +6444,14 @@ function createStyleHandler(options) {
|
|
|
6355
6444
|
}
|
|
6356
6445
|
function processSource(rawSource, root, cloneOutput, opt) {
|
|
6357
6446
|
const resolvedOptions = resolver.resolve(opt);
|
|
6358
|
-
const
|
|
6359
|
-
const
|
|
6360
|
-
|
|
6447
|
+
const isUniAppXFramework = resolvedOptions.appType === "uni-app-x";
|
|
6448
|
+
const protectedVarFallbacks = resolvedOptions.uniAppX || isUniAppXFramework ? protectDynamicVarFallbacks(rawSource) : {
|
|
6449
|
+
css: rawSource,
|
|
6450
|
+
restore: (value) => value
|
|
6451
|
+
};
|
|
6452
|
+
const protectedColorMix = resolvedOptions.majorVersion === 4 ? protectDynamicColorMixAlpha(protectedVarFallbacks.css) : void 0;
|
|
6453
|
+
const source = protectedColorMix?.css ?? protectedVarFallbacks.css;
|
|
6454
|
+
const processInput = source !== rawSource ? source : root?.clone() ?? source;
|
|
6361
6455
|
let signal;
|
|
6362
6456
|
if (!hasUserPlugins) try {
|
|
6363
6457
|
signal = probeFeatures(source);
|
|
@@ -6384,8 +6478,8 @@ function createStyleHandler(options) {
|
|
|
6384
6478
|
finalResult = nextResult;
|
|
6385
6479
|
}
|
|
6386
6480
|
}
|
|
6387
|
-
if (protectedColorMix) {
|
|
6388
|
-
const restoredCss =
|
|
6481
|
+
if (protectedColorMix || protectedVarFallbacks.css !== rawSource) {
|
|
6482
|
+
const restoredCss = protectedVarFallbacks.restore(protectedColorMix?.restore(finalResult.css) ?? finalResult.css);
|
|
6389
6483
|
if (restoredCss !== finalResult.css) {
|
|
6390
6484
|
const nextResult = finalResult.root.clone().toResult(finalResult.opts);
|
|
6391
6485
|
nextResult.css = restoredCss;
|
|
@@ -6394,6 +6488,9 @@ function createStyleHandler(options) {
|
|
|
6394
6488
|
finalResult = nextResult;
|
|
6395
6489
|
}
|
|
6396
6490
|
}
|
|
6491
|
+
if (resolvedOptions.uniAppX && (resolvedOptions.uniAppXCssTarget === "uvue" || !isUniAppXFramework) && finalResult.root) {
|
|
6492
|
+
if (splitUnresolvedAuthorVariableFallbacks(finalResult.root, /* @__PURE__ */ new Map())) finalResult.css = finalResult.root.toString();
|
|
6493
|
+
}
|
|
6397
6494
|
resultCache.set(cacheKey, finalResult);
|
|
6398
6495
|
return cloneOutput ? cloneResult(finalResult) : finalResult;
|
|
6399
6496
|
});
|
|
@@ -6906,4 +7003,4 @@ function mergeMiniProgramThemeScopeRuleDeclarations(baseCss, css) {
|
|
|
6906
7003
|
}
|
|
6907
7004
|
}
|
|
6908
7005
|
//#endregion
|
|
6909
|
-
export { CSS_MACRO_POSTCSS_PLUGIN_NAME, CSS_MACRO_STYLE_OPTIONS_MARKER, FULL_SOURCE_SCAN_EXTENSIONS, FULL_SOURCE_SCAN_EXTENSION_RE, FULL_SOURCE_SCAN_PATTERN, analyzeTailwindCssDirectives, cleanLocalCssImportWrapperTailwindDirectives, cleanLocalCssImportWrapperTailwindDirectivesRoot, collectApplyOnlyCssSelectors, collectApplyOnlyCssSelectorsRoot, collectCssImportRequestsRoot, collectCssInlineSourceCandidates, compileCssMacroConditionalComments, consumeCascadeLayers, containsCssAfterMinify, convertTailwindcssRpxDeclarationToRem, convertTailwindcssRpxDeclarationsToRem, convertTailwindcssRpxValueToRem, createCssSourceOrderAppend, createFallbackPlaceholderReplacer, createInjectPreflight, createPostcssStyleTargetProfile, createSourceScanPattern, createStyleHandler, createStylePipeline, createTailwindSourceEntryMatcher, createWeappTailwindcssPostcssPlugin, creator as cssMacroPostcssPlugin, dedupeCoveredCssRules, expandInlineSourceCandidatePattern, expandTailwindSourceEntries, filterApplyOnlyGeneratedCss, filterApplyOnlyGeneratedCssRoot, filterExistingCssRules, finalizeMiniProgramCss, getPostcssPluginName, hasCssMacroStyleOptions, hasCssMacroTailwindV4CustomVariantConditionalComments, hasCssMacroTailwindV4Directive, hasCssMacroTailwindV4InternalAtRules, hasCssMacroTailwindV4Source, hasMiniProgramCssSpecificityPlaceholders, hoistTailwindPreflightBase, internalCssSelectorReplacer, isFileExcludedByTailwindSourceEntries, isFileMatchedByTailwindSourceEntries, isLocalCssImportRequest, isMiniProgramLocalCssImportRequest, isPureLocalCssImportWrapper, isPureLocalCssImportWrapperRoot, isTailwindCssGenerationDirective, isTailwindCssImportAtRule, isTailwindCssImportRequest, isTailwindCssPackageJsonImportRequest, isWeappTailwindcssImportRequest, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, normalizeLegacyContentEntries, normalizeMiniProgramGeneratedCssForPostcss, normalizeMiniProgramPrefixedDeclaration, normalizeModernColorValue, normalizeOutputImportRequest, normalizeTailwindCssImportRequest, normalizeTailwindcssRpxDeclaration, normalizeTailwindcssRpxDeclarations, normalizeTailwindcssV4InfinityCalcCss, normalizeTailwindcssWebRpxDeclarations, normalizeWebCssCompatOptions, parseConfigParam, parseSourceFileParam, parseTailwindCssConfigRequest, parseTailwindCssDirectiveRequest, postcss, postcssHtmlTransform, prefixLocalCssImportsWithWebpackIgnoreRoot, protectDynamicColorMixAlpha, pruneMiniProgramGeneratedCss, removeEmptyAtRules, removeMatchingLocalCssImports, removeMatchingLocalCssImportsRoot, removeTailwindPostcssPlugins, removeTailwindSourceDirectivesRoot, removeUnsupportedAtSupports, removeUnsupportedCascadeLayers, removeUnsupportedMiniProgramAtRules, removeUnsupportedMiniProgramCssImportsRoot, removeUnsupportedMiniProgramPrefixedAtRule, resolveCssSourceEntries, resolveFilteredPostcssConfig, resolvePostcssConfig, resolvePostcssFrameworkProfile, resolvePostcssFrameworkStrategy, resolvePostcssStyleBranch, resolvePostcssStyleBranchProfile, resolvePostcssStyleTarget, resolveSourceScanPath, resolveTailwindSourceEntry, restoreLocalCssImports, rewriteLocalCssImportRequestsForOutput, rewriteLocalCssImportRequestsForOutputRoot, splitLocalCssImports, splitLocalCssImportsRoot, stripMiniProgramCssSpecificityPlaceholders, toPosixPath, transformCssMacroCss, transformCssMacroTailwindV4Source, transformWebCssCompat, transformWebCssSafeSelectors, unitConversionComposeRules, unitConversionPresets, unwrapUnsupportedCascadeLayers, withCssMacroStyleOptions };
|
|
7006
|
+
export { CSS_MACRO_POSTCSS_PLUGIN_NAME, CSS_MACRO_STYLE_OPTIONS_MARKER, FULL_SOURCE_SCAN_EXTENSIONS, FULL_SOURCE_SCAN_EXTENSION_RE, FULL_SOURCE_SCAN_PATTERN, analyzeTailwindCssDirectives, cleanLocalCssImportWrapperTailwindDirectives, cleanLocalCssImportWrapperTailwindDirectivesRoot, collectApplyOnlyCssSelectors, collectApplyOnlyCssSelectorsRoot, collectCssImportRequestsRoot, collectCssInlineSourceCandidates, compileCssMacroConditionalComments, consumeCascadeLayers, containsCssAfterMinify, convertTailwindcssRpxDeclarationToRem, convertTailwindcssRpxDeclarationsToRem, convertTailwindcssRpxValueToRem, createCssSourceOrderAppend, createFallbackPlaceholderReplacer, createInjectPreflight, createPostcssStyleTargetProfile, createSourceScanPattern, createStyleHandler, createStylePipeline, createTailwindSourceEntryMatcher, createWeappTailwindcssPostcssPlugin, creator as cssMacroPostcssPlugin, dedupeCoveredCssRules, expandInlineSourceCandidatePattern, expandTailwindSourceEntries, filterApplyOnlyGeneratedCss, filterApplyOnlyGeneratedCssRoot, filterExistingCssRules, finalizeMiniProgramCss, getPostcssPluginName, hasCssMacroStyleOptions, hasCssMacroTailwindV4CustomVariantConditionalComments, hasCssMacroTailwindV4Directive, hasCssMacroTailwindV4InternalAtRules, hasCssMacroTailwindV4Source, hasMiniProgramCssSpecificityPlaceholders, hoistTailwindPreflightBase, internalCssSelectorReplacer, isFileExcludedByTailwindSourceEntries, isFileMatchedByTailwindSourceEntries, isLocalCssImportRequest, isMiniProgramLocalCssImportRequest, isPureLocalCssImportWrapper, isPureLocalCssImportWrapperRoot, isTailwindCssGenerationDirective, isTailwindCssImportAtRule, isTailwindCssImportRequest, isTailwindCssPackageJsonImportRequest, isWeappTailwindcssImportRequest, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, normalizeLegacyContentEntries, normalizeMiniProgramGeneratedCssForPostcss, normalizeMiniProgramPrefixedDeclaration, normalizeModernColorValue, normalizeOutputImportRequest, normalizeTailwindCssImportRequest, normalizeTailwindcssRpxDeclaration, normalizeTailwindcssRpxDeclarations, normalizeTailwindcssV4InfinityCalcCss, normalizeTailwindcssWebRpxDeclarations, normalizeWebCssCompatOptions, parseConfigParam, parseSourceFileParam, parseTailwindCssConfigRequest, parseTailwindCssDirectiveRequest, postcss, postcssHtmlTransform, prefixLocalCssImportsWithWebpackIgnoreRoot, protectDynamicColorMixAlpha, protectDynamicVarFallbacks, pruneMiniProgramGeneratedCss, removeEmptyAtRules, removeMatchingLocalCssImports, removeMatchingLocalCssImportsRoot, removeTailwindPostcssPlugins, removeTailwindSourceDirectivesRoot, removeUnsupportedAtSupports, removeUnsupportedCascadeLayers, removeUnsupportedMiniProgramAtRules, removeUnsupportedMiniProgramCssImportsRoot, removeUnsupportedMiniProgramPrefixedAtRule, resolveCssSourceEntries, resolveFilteredPostcssConfig, resolvePostcssConfig, resolvePostcssFrameworkProfile, resolvePostcssFrameworkStrategy, resolvePostcssStyleBranch, resolvePostcssStyleBranchProfile, resolvePostcssStyleTarget, resolveSourceScanPath, resolveTailwindSourceEntry, restoreLocalCssImports, rewriteLocalCssImportRequestsForOutput, rewriteLocalCssImportRequestsForOutputRoot, splitLocalCssImports, splitLocalCssImportsRoot, stripMiniProgramCssSpecificityPlaceholders, toPosixPath, transformCssMacroCss, transformCssMacroTailwindV4Source, transformWebCssCompat, transformWebCssSafeSelectors, unitConversionComposeRules, unitConversionPresets, unwrapUnsupportedCascadeLayers, withCssMacroStyleOptions };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-tailwindcss/postcss",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.2.
|
|
4
|
+
"version": "3.2.2",
|
|
5
5
|
"description": "@weapp-tailwindcss/postcss",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -82,8 +82,8 @@
|
|
|
82
82
|
"postcss-rule-unit-converter": "^0.2.2",
|
|
83
83
|
"postcss-selector-parser": "~7.1.4",
|
|
84
84
|
"postcss-value-parser": "^4.2.0",
|
|
85
|
-
"@weapp-tailwindcss/postcss-calc": "^1.0.3",
|
|
86
85
|
"@weapp-tailwindcss/shared": "2.0.1",
|
|
86
|
+
"@weapp-tailwindcss/postcss-calc": "^1.0.3",
|
|
87
87
|
"tailwindcss-config": "2.0.2"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|