@weapp-tailwindcss/postcss 3.2.5 → 3.2.7
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/root-cleanups.d.ts +1 -1
- package/dist/index.cjs +1187 -1161
- package/dist/index.js +1187 -1161
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -144,6 +144,187 @@ function stripUnsupportedNodeForUniAppX(node, options) {
|
|
|
144
144
|
function shouldRemoveEmptyRuleForUniAppX(rule, options) {
|
|
145
145
|
return isUniAppXEnabled(options) && rule.nodes.length === 0;
|
|
146
146
|
}
|
|
147
|
+
const MODERN_COLOR_FUNCTION_NAMES = /* @__PURE__ */ new Set([
|
|
148
|
+
"oklch",
|
|
149
|
+
"oklab",
|
|
150
|
+
"lch",
|
|
151
|
+
"lab"
|
|
152
|
+
]);
|
|
153
|
+
const MODERN_COLOR_SYNTAX_FUNCTION_NAMES = /* @__PURE__ */ new Set([
|
|
154
|
+
"rgb",
|
|
155
|
+
"rgba",
|
|
156
|
+
"hsl",
|
|
157
|
+
"hsla",
|
|
158
|
+
"hwb"
|
|
159
|
+
]);
|
|
160
|
+
const PLACEHOLDER_PREFIX = "__weapp_tw_color_mix_";
|
|
161
|
+
const DYNAMIC_ALPHA_RE = /\b(?:var|env)\(|--[\w-]+\b/;
|
|
162
|
+
const INTERNAL_TAILWIND_ALPHA_RE = /var\(\s*--tw-[^)]+-alpha\s*\)/;
|
|
163
|
+
const TRANSPARENT_COLOR_RE = /^transparent$/i;
|
|
164
|
+
const CURRENT_COLOR_RE = /^currentcolor$/i;
|
|
165
|
+
const CSS_WIDE_KEYWORD_RE = /^(?:inherit|initial|unset|revert|revert-layer)$/i;
|
|
166
|
+
const CUSTOM_PROPERTY_RE = /^--[\w-]+$/;
|
|
167
|
+
//#endregion
|
|
168
|
+
//#region src/compat/color-mix/modern.ts
|
|
169
|
+
function isDisplayP3ColorFunction(colorSource) {
|
|
170
|
+
return /^color\(\s*display-p3\b/i.test(colorSource.trim());
|
|
171
|
+
}
|
|
172
|
+
function isModernColorSyntaxFunction(colorSource) {
|
|
173
|
+
const parsed = (0, postcss_value_parser.default)(colorSource.trim());
|
|
174
|
+
const node = parsed.nodes.length === 1 ? parsed.nodes[0] : void 0;
|
|
175
|
+
if (node?.type !== "function") return false;
|
|
176
|
+
const name = node.value.toLowerCase();
|
|
177
|
+
if (!MODERN_COLOR_SYNTAX_FUNCTION_NAMES.has(name)) return false;
|
|
178
|
+
return !node.nodes.some((child) => child.type === "div" && child.value === ",");
|
|
179
|
+
}
|
|
180
|
+
function hasUnsupportedModernColorFunction(value) {
|
|
181
|
+
const parsed = (0, postcss_value_parser.default)(value);
|
|
182
|
+
let hasUnsupported = false;
|
|
183
|
+
parsed.walk((node) => {
|
|
184
|
+
if (node.type !== "function") return;
|
|
185
|
+
const name = node.value.toLowerCase();
|
|
186
|
+
if (name === "color-mix" || MODERN_COLOR_FUNCTION_NAMES.has(name) || name === "color" && isDisplayP3ColorFunction(postcss_value_parser.default.stringify(node)) || isModernColorSyntaxFunction(postcss_value_parser.default.stringify(node))) {
|
|
187
|
+
hasUnsupported = true;
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
return hasUnsupported;
|
|
192
|
+
}
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/compat/color-mix/parse.ts
|
|
195
|
+
function splitArguments(nodes) {
|
|
196
|
+
const args = [];
|
|
197
|
+
let current = [];
|
|
198
|
+
for (const node of nodes) {
|
|
199
|
+
if (node.type === "div" && node.value === ",") {
|
|
200
|
+
args.push(current);
|
|
201
|
+
current = [];
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
current.push(node);
|
|
205
|
+
}
|
|
206
|
+
args.push(current);
|
|
207
|
+
return args;
|
|
208
|
+
}
|
|
209
|
+
function splitStopSegments(nodes) {
|
|
210
|
+
const segments = [];
|
|
211
|
+
let current = [];
|
|
212
|
+
for (const node of nodes) {
|
|
213
|
+
if (node.type === "space") {
|
|
214
|
+
if (current.length > 0) {
|
|
215
|
+
segments.push(current);
|
|
216
|
+
current = [];
|
|
217
|
+
}
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
current.push(node);
|
|
221
|
+
}
|
|
222
|
+
if (current.length > 0) segments.push(current);
|
|
223
|
+
return segments;
|
|
224
|
+
}
|
|
225
|
+
function trimNodes$1(nodes) {
|
|
226
|
+
let start = 0;
|
|
227
|
+
let end = nodes.length;
|
|
228
|
+
while (start < end && nodes[start]?.type === "space") start += 1;
|
|
229
|
+
while (end > start && nodes[end - 1]?.type === "space") end -= 1;
|
|
230
|
+
return nodes.slice(start, end);
|
|
231
|
+
}
|
|
232
|
+
function getParsedColorData(colorSource) {
|
|
233
|
+
try {
|
|
234
|
+
return (0, _csstools_css_color_parser.color)((0, _csstools_css_parser_algorithms.parseComponentValue)((0, _csstools_css_tokenizer.tokenize)({ css: colorSource })));
|
|
235
|
+
} catch {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function parseAlphaValue(alphaSource) {
|
|
240
|
+
const parsed = Number.parseFloat(alphaSource);
|
|
241
|
+
if (Number.isFinite(parsed)) return alphaSource.trim().endsWith("%") ? parsed / 100 : parsed;
|
|
242
|
+
}
|
|
243
|
+
function resolveVarColor(colorSource, customPropertyValues, depth = 0) {
|
|
244
|
+
if (depth > 5) return;
|
|
245
|
+
const parsed = (0, postcss_value_parser.default)(colorSource.trim());
|
|
246
|
+
const node = parsed.nodes.length === 1 ? parsed.nodes[0] : void 0;
|
|
247
|
+
if (node?.type !== "function" || node.value.toLowerCase() !== "var") return;
|
|
248
|
+
const args = splitArguments(node.nodes);
|
|
249
|
+
const propertyName = postcss_value_parser.default.stringify(trimNodes$1(args[0] ?? [])).trim();
|
|
250
|
+
if (!CUSTOM_PROPERTY_RE.test(propertyName)) return;
|
|
251
|
+
const resolved = customPropertyValues.get(propertyName);
|
|
252
|
+
if (!resolved) {
|
|
253
|
+
const fallback = args[1] ? postcss_value_parser.default.stringify(trimNodes$1(args[1])).trim() : void 0;
|
|
254
|
+
return fallback ? resolveColorData(fallback, customPropertyValues, depth + 1) : void 0;
|
|
255
|
+
}
|
|
256
|
+
return resolveColorData(resolved, customPropertyValues, depth + 1);
|
|
257
|
+
}
|
|
258
|
+
function resolveColorData(colorSource, customPropertyValues, depth = 0) {
|
|
259
|
+
if (typeof colorSource !== "string") return;
|
|
260
|
+
const trimmed = colorSource.trim();
|
|
261
|
+
if (TRANSPARENT_COLOR_RE.test(trimmed)) return getParsedColorData(trimmed) || void 0;
|
|
262
|
+
if (CURRENT_COLOR_RE.test(trimmed) || CSS_WIDE_KEYWORD_RE.test(trimmed)) return;
|
|
263
|
+
const resolvedVar = resolveVarColor(trimmed, customPropertyValues, depth);
|
|
264
|
+
if (resolvedVar) return resolvedVar;
|
|
265
|
+
return getParsedColorData(trimmed) || void 0;
|
|
266
|
+
}
|
|
267
|
+
function normalizeColorFunctionName(colorSource, alpha, customPropertyValues) {
|
|
268
|
+
const resolvedColor = resolveColorData(colorSource, customPropertyValues);
|
|
269
|
+
if (!resolvedColor) return;
|
|
270
|
+
resolvedColor.alpha = alpha;
|
|
271
|
+
return (0, _csstools_css_color_parser.serializeRGB)(resolvedColor).toString();
|
|
272
|
+
}
|
|
273
|
+
function normalizeColorFunctionWithDynamicAlpha(colorSource, alphaSource, customPropertyValues) {
|
|
274
|
+
const resolvedColor = resolveColorData(colorSource, customPropertyValues);
|
|
275
|
+
const alphaColor = getParsedColorData(`rgb(0 0 0 / ${alphaSource})`);
|
|
276
|
+
if (!resolvedColor || !alphaColor || typeof alphaColor.alpha === "number") return;
|
|
277
|
+
resolvedColor.alpha = alphaColor.alpha;
|
|
278
|
+
return (0, _csstools_css_color_parser.serializeRGB)(resolvedColor).toString();
|
|
279
|
+
}
|
|
280
|
+
function normalizeStandaloneColorFunction(colorSource) {
|
|
281
|
+
const resolvedColor = getParsedColorData(colorSource);
|
|
282
|
+
return resolvedColor ? (0, _csstools_css_color_parser.serializeRGB)(resolvedColor).toString() : void 0;
|
|
283
|
+
}
|
|
284
|
+
//#endregion
|
|
285
|
+
//#region src/compat/color-mix/resolve.ts
|
|
286
|
+
function createRgbaWithAlpha(colorSource, alphaSource, customPropertyValues) {
|
|
287
|
+
const alpha = alphaSource.trim();
|
|
288
|
+
return normalizeColorFunctionWithDynamicAlpha(colorSource, CUSTOM_PROPERTY_RE.test(alpha) ? `var(${alpha})` : alpha, customPropertyValues);
|
|
289
|
+
}
|
|
290
|
+
function tryResolveColorMix(node, customPropertyValues) {
|
|
291
|
+
const args = splitArguments(node.nodes);
|
|
292
|
+
if (args.length < 3) return;
|
|
293
|
+
const colorStopNodes = splitStopSegments(args[1] ?? []);
|
|
294
|
+
if (colorStopNodes.length < 2) return;
|
|
295
|
+
const colorNodes = trimNodes$1(colorStopNodes[0] ?? []);
|
|
296
|
+
const alphaNodes = trimNodes$1(colorStopNodes[1] ?? []);
|
|
297
|
+
const trailingNodes = trimNodes$1(args[2] ?? []);
|
|
298
|
+
if (!colorNodes.length || !alphaNodes.length || postcss_value_parser.default.stringify(trailingNodes).trim().toLowerCase() !== "transparent") return;
|
|
299
|
+
const colorSource = postcss_value_parser.default.stringify(colorNodes).trim();
|
|
300
|
+
const alphaSource = postcss_value_parser.default.stringify(alphaNodes).trim();
|
|
301
|
+
if (!colorSource || !alphaSource || INTERNAL_TAILWIND_ALPHA_RE.test(alphaSource)) return;
|
|
302
|
+
if (CURRENT_COLOR_RE.test(colorSource)) return {
|
|
303
|
+
value: colorSource,
|
|
304
|
+
deferred: false
|
|
305
|
+
};
|
|
306
|
+
if (DYNAMIC_ALPHA_RE.test(alphaSource)) {
|
|
307
|
+
const normalized = createRgbaWithAlpha(colorSource, alphaSource, customPropertyValues);
|
|
308
|
+
return normalized ? {
|
|
309
|
+
value: normalized,
|
|
310
|
+
deferred: true
|
|
311
|
+
} : {
|
|
312
|
+
value: colorSource,
|
|
313
|
+
deferred: true
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
const alpha = parseAlphaValue(alphaSource);
|
|
317
|
+
if (alpha === void 0) return;
|
|
318
|
+
const normalized = normalizeColorFunctionName(colorSource, alpha, customPropertyValues);
|
|
319
|
+
if (normalized) return {
|
|
320
|
+
value: normalized,
|
|
321
|
+
deferred: false
|
|
322
|
+
};
|
|
323
|
+
return {
|
|
324
|
+
value: colorSource,
|
|
325
|
+
deferred: false
|
|
326
|
+
};
|
|
327
|
+
}
|
|
147
328
|
//#endregion
|
|
148
329
|
//#region src/cssVarsV4.ts
|
|
149
330
|
function property(ident, initialValue, _syntax) {
|
|
@@ -398,52 +579,599 @@ function createMissingCssVarsV4Nodes(root, usedProps) {
|
|
|
398
579
|
}));
|
|
399
580
|
}
|
|
400
581
|
//#endregion
|
|
401
|
-
//#region src/compat/
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
});
|
|
410
|
-
return variables;
|
|
411
|
-
}
|
|
412
|
-
function resolveTailwindcssV4GradientColor(value, themeVariables) {
|
|
413
|
-
const trimmed = value.trim();
|
|
414
|
-
const match = COLOR_VAR_RE.exec(trimmed);
|
|
415
|
-
if (!match) return trimmed;
|
|
416
|
-
return themeVariables.get(match[1]) ?? trimmed;
|
|
417
|
-
}
|
|
418
|
-
function getSingleClassSelector(selector) {
|
|
419
|
-
const match = SIMPLE_CLASS_SELECTOR_RE.exec(selector.trim());
|
|
420
|
-
return match ? match[1] : void 0;
|
|
421
|
-
}
|
|
422
|
-
function normalizeDeclarationValue(value) {
|
|
423
|
-
return value.replace(/\s+/g, " ").trim();
|
|
424
|
-
}
|
|
425
|
-
function normalizeTailwindcssV4GradientPosition(value) {
|
|
426
|
-
return value.replace(/calc\(\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:deg|grad|rad|turn))\s*\*\s*-1\s*\)/gi, "-$1").replace(/^in\s+(?:oklab|oklch|hsl|srgb)(?:\s+(?:longer|shorter|increasing|decreasing)\s+hue)?$/i, "").replace(/\s+in\s+(?:oklab|oklch|hsl|srgb)(?:\s+(?:longer|shorter|increasing|decreasing)\s+hue)?\s*$/i, "").replace(/\s+(?:longer|shorter|increasing|decreasing)\s*$/i, "").trim();
|
|
427
|
-
}
|
|
428
|
-
function normalizeTailwindcssV4InfinityCalcValue(value) {
|
|
429
|
-
return INFINITY_CALC_VALUE_REGEXP.test(value.trim()) ? `${CLAMP_PX}px` : value;
|
|
430
|
-
}
|
|
431
|
-
const INFINITY_CALC_CSS_RE = /calc\(\s*infinity\s*\*\s*(?:\d+(?:\.\d*)?|\.\d+)r?px\s*\)/gi;
|
|
432
|
-
/** 在预处理器解析前收敛 Tailwind v4 生成的无限圆角,避免 Sass 将 infinity 当作非法表达式。 */
|
|
433
|
-
function normalizeTailwindcssV4InfinityCalcCss(css) {
|
|
434
|
-
return css.replace(INFINITY_CALC_CSS_RE, `${CLAMP_PX}px`);
|
|
582
|
+
//#region src/compat/color-mix.ts
|
|
583
|
+
const DYNAMIC_VAR_FALLBACK_PLACEHOLDER_PREFIX = "__weapp_tw_var_fallback_";
|
|
584
|
+
function getStandaloneDynamicVarWithFallback(value) {
|
|
585
|
+
const nodes = (0, postcss_value_parser.default)(value).nodes.filter((node) => node.type !== "space" && node.type !== "comment");
|
|
586
|
+
const variable = nodes.length === 1 ? nodes[0] : void 0;
|
|
587
|
+
const property = variable?.type === "function" ? variable.nodes.find((node) => node.type === "word" && node.value.startsWith("--")) : void 0;
|
|
588
|
+
if (variable?.type !== "function" || variable.value.toLowerCase() !== "var" || property?.type !== "word" || isTailwindcssV4ThemeVariable(property.value) || !variable.nodes.some((node) => node.type === "div" && node.value === ",")) return;
|
|
589
|
+
return variable;
|
|
435
590
|
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
591
|
+
/**
|
|
592
|
+
* 保护带 fallback 的作者 CSS 变量,避免兼容插件把它错误静态化。
|
|
593
|
+
*/
|
|
594
|
+
function protectDynamicVarFallbacks(css) {
|
|
595
|
+
if (!css.includes("var(") || !css.includes(",")) return {
|
|
596
|
+
css,
|
|
597
|
+
restore: (value) => value
|
|
598
|
+
};
|
|
599
|
+
const replacements = /* @__PURE__ */ new Map();
|
|
600
|
+
let root;
|
|
601
|
+
try {
|
|
602
|
+
root = postcss.default.parse(css);
|
|
603
|
+
} catch {
|
|
604
|
+
return {
|
|
605
|
+
css,
|
|
606
|
+
restore: (value) => value
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
root.walkDecls((decl) => {
|
|
610
|
+
if (!getStandaloneDynamicVarWithFallback(decl.value)) return;
|
|
611
|
+
const placeholder = `${DYNAMIC_VAR_FALLBACK_PLACEHOLDER_PREFIX}${replacements.size}__`;
|
|
612
|
+
replacements.set(placeholder, decl.value);
|
|
613
|
+
decl.value = placeholder;
|
|
441
614
|
});
|
|
442
|
-
if (
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
615
|
+
if (replacements.size === 0) return {
|
|
616
|
+
css,
|
|
617
|
+
restore: (value) => value
|
|
618
|
+
};
|
|
619
|
+
return {
|
|
620
|
+
css: root.toString(),
|
|
621
|
+
restore(value) {
|
|
622
|
+
let restored = value;
|
|
623
|
+
for (const [placeholder, replacement] of replacements) restored = restored.split(placeholder).join(replacement);
|
|
624
|
+
return restored;
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
function normalizeModernColorValue(value, customPropertyValues = /* @__PURE__ */ new Map()) {
|
|
629
|
+
if (!hasUnsupportedModernColorFunction(value)) return {
|
|
630
|
+
value,
|
|
631
|
+
changed: false,
|
|
632
|
+
hasUnsupported: false
|
|
633
|
+
};
|
|
634
|
+
const parsed = (0, postcss_value_parser.default)(value);
|
|
635
|
+
let changed = false;
|
|
636
|
+
parsed.walk((node) => {
|
|
637
|
+
if (node.type !== "function") return;
|
|
638
|
+
const name = node.value.toLowerCase();
|
|
639
|
+
const source = postcss_value_parser.default.stringify(node);
|
|
640
|
+
let normalized;
|
|
641
|
+
if (MODERN_COLOR_FUNCTION_NAMES.has(name) || name === "color" && isDisplayP3ColorFunction(source) || isModernColorSyntaxFunction(source)) normalized = normalizeStandaloneColorFunction(source);
|
|
642
|
+
else if (name === "color-mix") normalized = tryResolveColorMix(node, customPropertyValues)?.value;
|
|
643
|
+
if (!normalized) return;
|
|
644
|
+
const mutableNode = node;
|
|
645
|
+
mutableNode.type = "word";
|
|
646
|
+
mutableNode.value = normalized;
|
|
647
|
+
delete mutableNode.nodes;
|
|
648
|
+
changed = true;
|
|
649
|
+
});
|
|
650
|
+
const nextValue = changed ? parsed.toString() : value;
|
|
651
|
+
return {
|
|
652
|
+
value: nextValue,
|
|
653
|
+
changed,
|
|
654
|
+
hasUnsupported: hasUnsupportedModernColorFunction(nextValue)
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
function createPlaceholder(index) {
|
|
658
|
+
return `${PLACEHOLDER_PREFIX}${index}__`;
|
|
659
|
+
}
|
|
660
|
+
function unwrapProtectedSupports(cssRoot) {
|
|
661
|
+
cssRoot.walkAtRules("supports", (atRule) => {
|
|
662
|
+
if (!atRule.nodes || !atRule.toString().includes("__weapp_tw_color_mix_")) return;
|
|
663
|
+
atRule.replaceWith(atRule.nodes);
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
function protectDynamicColorMixAlpha(css, options = {}) {
|
|
667
|
+
if (!css.includes("color-mix")) return {
|
|
668
|
+
css,
|
|
669
|
+
restore: (value) => value
|
|
670
|
+
};
|
|
671
|
+
const replacements = /* @__PURE__ */ new Map();
|
|
672
|
+
const root = postcss.default.parse(css);
|
|
673
|
+
const customPropertyValues = new Map(options.customPropertyValues);
|
|
674
|
+
let changed = false;
|
|
675
|
+
root.walkDecls((decl) => {
|
|
676
|
+
if (decl.prop.startsWith("--") && !decl.value.includes("color-mix")) customPropertyValues.set(decl.prop, decl.value.trim());
|
|
677
|
+
});
|
|
678
|
+
root.walkDecls((decl) => {
|
|
679
|
+
if (!decl.value.includes("color-mix")) return;
|
|
680
|
+
const parsed = (0, postcss_value_parser.default)(decl.value);
|
|
681
|
+
let mutated = false;
|
|
682
|
+
parsed.walk((node) => {
|
|
683
|
+
if (node.type !== "function" || node.value.toLowerCase() !== "color-mix") return;
|
|
684
|
+
const resolved = tryResolveColorMix(node, customPropertyValues);
|
|
685
|
+
if (resolved) {
|
|
686
|
+
if (resolved.deferred) {
|
|
687
|
+
const placeholder = createPlaceholder(replacements.size);
|
|
688
|
+
replacements.set(placeholder, resolved.value);
|
|
689
|
+
const mutableNode = node;
|
|
690
|
+
mutableNode.type = "word";
|
|
691
|
+
mutableNode.value = placeholder;
|
|
692
|
+
delete mutableNode.nodes;
|
|
693
|
+
mutated = true;
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
const mutableNode = node;
|
|
697
|
+
mutableNode.type = "word";
|
|
698
|
+
mutableNode.value = resolved.value;
|
|
699
|
+
delete mutableNode.nodes;
|
|
700
|
+
mutated = true;
|
|
701
|
+
}
|
|
702
|
+
});
|
|
703
|
+
if (mutated) {
|
|
704
|
+
decl.value = parsed.toString();
|
|
705
|
+
changed = true;
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
if (replacements.size > 0) unwrapProtectedSupports(root);
|
|
709
|
+
return {
|
|
710
|
+
css: changed ? root.toString() : css,
|
|
711
|
+
restore(value) {
|
|
712
|
+
let restored = value;
|
|
713
|
+
for (const [placeholder, replacement] of replacements) restored = restored.split(placeholder).join(replacement);
|
|
714
|
+
return restored;
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
//#endregion
|
|
719
|
+
//#region src/compat/mini-program-css/color-gamut.ts
|
|
720
|
+
const DISPLAY_P3_VALUE_RE = /color\(\s*display-p3\b/i;
|
|
721
|
+
const COLOR_GAMUT_P3_RE = /\(\s*color-gamut\s*:\s*p3\s*\)/i;
|
|
722
|
+
function isDisplayP3MediaRule(atRule) {
|
|
723
|
+
return atRule.name === "media" && COLOR_GAMUT_P3_RE.test(atRule.params);
|
|
724
|
+
}
|
|
725
|
+
function isDisplayP3Declaration(decl) {
|
|
726
|
+
return DISPLAY_P3_VALUE_RE.test(decl.value);
|
|
727
|
+
}
|
|
728
|
+
//#endregion
|
|
729
|
+
//#region src/compat/mini-program-css/selectors.ts
|
|
730
|
+
const MINI_PROGRAM_THEME_SCOPE_SELECTOR = ":host,page,.tw-root,wx-root-portal-content";
|
|
731
|
+
const MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR = "view,text,::after,::before";
|
|
732
|
+
const MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS = /* @__PURE__ */ new Set([
|
|
733
|
+
"view",
|
|
734
|
+
"text",
|
|
735
|
+
":before",
|
|
736
|
+
":after",
|
|
737
|
+
"::before",
|
|
738
|
+
"::after"
|
|
739
|
+
]);
|
|
740
|
+
const MINI_PROGRAM_NATIVE_ELEMENT_SELECTORS = /* @__PURE__ */ new Set([
|
|
741
|
+
...MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS,
|
|
742
|
+
"button",
|
|
743
|
+
"input",
|
|
744
|
+
"textarea",
|
|
745
|
+
"canvas",
|
|
746
|
+
"video",
|
|
747
|
+
"audio"
|
|
748
|
+
]);
|
|
749
|
+
const MINI_PROGRAM_PREFLIGHT_SELECTORS$1 = /* @__PURE__ */ new Set(["*", ...MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS]);
|
|
750
|
+
const MINI_PROGRAM_THEME_SCOPE_SELECTORS = /* @__PURE__ */ new Set([
|
|
751
|
+
":host",
|
|
752
|
+
":root",
|
|
753
|
+
"page",
|
|
754
|
+
".tw-root",
|
|
755
|
+
"wx-root-portal-content"
|
|
756
|
+
]);
|
|
757
|
+
function normalizeMiniProgramThemeScopeSelector(root) {
|
|
758
|
+
if (root === false) return ":host";
|
|
759
|
+
if (root === void 0) return MINI_PROGRAM_THEME_SCOPE_SELECTOR;
|
|
760
|
+
const selectors = Array.isArray(root) ? root.filter(Boolean) : [root];
|
|
761
|
+
return [.../* @__PURE__ */ new Set([":host", ...selectors])].join(",");
|
|
762
|
+
}
|
|
763
|
+
const SPECIFICITY_PLACEHOLDER_SUFFIXES = [":not(#n)", ":not(#\\#)"];
|
|
764
|
+
const ROOT_SPECIFICITY_PLACEHOLDER_SUFFIXES = [":not(.does-not-exist)"];
|
|
765
|
+
const MINI_PROGRAM_UNSUPPORTED_BROWSER_SELECTORS = /* @__PURE__ */ new Set([
|
|
766
|
+
":-moz-focusring",
|
|
767
|
+
":-moz-ui-invalid",
|
|
768
|
+
"::-webkit-calendar-picker-indicator",
|
|
769
|
+
"::-webkit-date-and-time-value",
|
|
770
|
+
"::-webkit-datetime-edit",
|
|
771
|
+
"::-webkit-datetime-edit-day-field",
|
|
772
|
+
"::-webkit-datetime-edit-fields-wrapper",
|
|
773
|
+
"::-webkit-datetime-edit-hour-field",
|
|
774
|
+
"::-webkit-datetime-edit-meridiem-field",
|
|
775
|
+
"::-webkit-datetime-edit-millisecond-field",
|
|
776
|
+
"::-webkit-datetime-edit-minute-field",
|
|
777
|
+
"::-webkit-datetime-edit-month-field",
|
|
778
|
+
"::-webkit-datetime-edit-second-field",
|
|
779
|
+
"::-webkit-datetime-edit-year-field",
|
|
780
|
+
"::-webkit-inner-spin-button",
|
|
781
|
+
"::-webkit-input-placeholder",
|
|
782
|
+
"::-webkit-outer-spin-button",
|
|
783
|
+
"::-webkit-search-decoration",
|
|
784
|
+
"::placeholder",
|
|
785
|
+
"[hidden]:where(:not([hidden='until-found']))"
|
|
786
|
+
]);
|
|
787
|
+
const MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS = /* @__PURE__ */ new Set([
|
|
788
|
+
"a",
|
|
789
|
+
"abbr:where([title])",
|
|
790
|
+
"audio",
|
|
791
|
+
"b",
|
|
792
|
+
"button",
|
|
793
|
+
"canvas",
|
|
794
|
+
"code",
|
|
795
|
+
"embed",
|
|
796
|
+
"h1",
|
|
797
|
+
"h2",
|
|
798
|
+
"h3",
|
|
799
|
+
"h4",
|
|
800
|
+
"h5",
|
|
801
|
+
"h6",
|
|
802
|
+
"hr",
|
|
803
|
+
"html",
|
|
804
|
+
"iframe",
|
|
805
|
+
"img",
|
|
806
|
+
"input",
|
|
807
|
+
"input:where([type='button'],[type='reset'],[type='submit'])",
|
|
808
|
+
"kbd",
|
|
809
|
+
"menu",
|
|
810
|
+
"object",
|
|
811
|
+
"ol",
|
|
812
|
+
"optgroup",
|
|
813
|
+
"pre",
|
|
814
|
+
"progress",
|
|
815
|
+
"samp",
|
|
816
|
+
"select",
|
|
817
|
+
"select[multiple]optgroup",
|
|
818
|
+
"select[multiple]optgroupoption",
|
|
819
|
+
"select[size]optgroup",
|
|
820
|
+
"select[size]optgroupoption",
|
|
821
|
+
"small",
|
|
822
|
+
"strong",
|
|
823
|
+
"sub",
|
|
824
|
+
"summary",
|
|
825
|
+
"sup",
|
|
826
|
+
"svg",
|
|
827
|
+
"table",
|
|
828
|
+
"textarea",
|
|
829
|
+
"ul",
|
|
830
|
+
"video"
|
|
831
|
+
]);
|
|
832
|
+
const MINI_PROGRAM_UNSUPPORTED_BROWSER_PREFLIGHT_SELECTOR_PARTS = /* @__PURE__ */ new Set([...MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS, "::file-selector-button"]);
|
|
833
|
+
function normalizeSelector$2(selector) {
|
|
834
|
+
return selector.trim().replace(/\s+/g, "");
|
|
835
|
+
}
|
|
836
|
+
function normalizePseudoElementSelector(selector) {
|
|
837
|
+
return normalizeSelector$2(selector).replace(/^:(before|after)$/, "::$1");
|
|
838
|
+
}
|
|
839
|
+
function getRuleSelectors(rule) {
|
|
840
|
+
return rule.selector.split(",").map(normalizePseudoElementSelector).filter(Boolean);
|
|
841
|
+
}
|
|
842
|
+
function getSortedRuleSelectorKey(rule) {
|
|
843
|
+
return getRuleSelectors(rule).sort().join(",");
|
|
844
|
+
}
|
|
845
|
+
function isUnsupportedBrowserSelector(selector) {
|
|
846
|
+
const normalized = normalizeSelector$2(selector);
|
|
847
|
+
return MINI_PROGRAM_UNSUPPORTED_BROWSER_SELECTORS.has(normalized) || MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS.has(normalized) && !MINI_PROGRAM_NATIVE_ELEMENT_SELECTORS.has(normalized);
|
|
848
|
+
}
|
|
849
|
+
function isUnsupportedBrowserPreflightSelector(selector) {
|
|
850
|
+
const normalizedParts = selector.split(",").map(normalizeSelector$2).filter(Boolean);
|
|
851
|
+
return normalizedParts.length > 1 && normalizedParts.every((part) => MINI_PROGRAM_UNSUPPORTED_BROWSER_PREFLIGHT_SELECTOR_PARTS.has(part));
|
|
852
|
+
}
|
|
853
|
+
function isMiniProgramNativeElementSelector(selector) {
|
|
854
|
+
return MINI_PROGRAM_NATIVE_ELEMENT_SELECTORS.has(normalizePseudoElementSelector(selector));
|
|
855
|
+
}
|
|
856
|
+
function isMiniProgramPreflightSelector(selectors) {
|
|
857
|
+
return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_PREFLIGHT_SELECTORS$1.has(selector)) && selectors.some((selector) => selector === "*" || selector === ":before" || selector === ":after" || selector === "::before" || selector === "::after");
|
|
858
|
+
}
|
|
859
|
+
function isMiniProgramThemeScopeSelector(selectors) {
|
|
860
|
+
return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_THEME_SCOPE_SELECTORS.has(selector));
|
|
861
|
+
}
|
|
862
|
+
//#endregion
|
|
863
|
+
//#region src/compat/mini-program-css/predicates.ts
|
|
864
|
+
const PREFLIGHT_RESET_PROPS = /* @__PURE__ */ new Set([
|
|
865
|
+
"box-sizing",
|
|
866
|
+
"border",
|
|
867
|
+
"border-width",
|
|
868
|
+
"border-style",
|
|
869
|
+
"border-color",
|
|
870
|
+
"margin",
|
|
871
|
+
"padding"
|
|
872
|
+
]);
|
|
873
|
+
const PSEUDO_CONTENT_SELECTOR_RE = /^(?:::before|::after|:before|:after)(?:,(?:::before|::after|:before|:after))*$/;
|
|
874
|
+
const TW_CONTENT_VAR_RE = /var\(\s*--tw-content\b/;
|
|
875
|
+
const BROWSER_PREFLIGHT_SINGLE_ELEMENT_DECLARATIONS = /* @__PURE__ */ new Map([["button", /* @__PURE__ */ new Set(["appearance:button", "-moz-appearance:button"])], ["textarea", /* @__PURE__ */ new Set(["resize:vertical"])]]);
|
|
876
|
+
function hasTailwindPreflightDeclaration(rule) {
|
|
877
|
+
let hasTailwindVar = false;
|
|
878
|
+
let hasResetProp = false;
|
|
879
|
+
rule.walkDecls((decl) => {
|
|
880
|
+
if (decl.prop.startsWith("--tw-")) hasTailwindVar = true;
|
|
881
|
+
if (PREFLIGHT_RESET_PROPS.has(decl.prop)) hasResetProp = true;
|
|
882
|
+
});
|
|
883
|
+
return hasTailwindVar || hasResetProp;
|
|
884
|
+
}
|
|
885
|
+
function hasTailwindVariableDeclaration(rule) {
|
|
886
|
+
let hasTailwindVar = false;
|
|
887
|
+
rule.walkDecls((decl) => {
|
|
888
|
+
if (decl.prop.startsWith("--tw-")) hasTailwindVar = true;
|
|
889
|
+
});
|
|
890
|
+
return hasTailwindVar;
|
|
891
|
+
}
|
|
892
|
+
function isCustomPropertyRule(rule) {
|
|
893
|
+
let hasDeclaration = false;
|
|
894
|
+
let allCustomProperties = true;
|
|
895
|
+
rule.each((node) => {
|
|
896
|
+
if (node.type !== "decl") return;
|
|
897
|
+
hasDeclaration = true;
|
|
898
|
+
if (!node.prop.startsWith("--")) allCustomProperties = false;
|
|
899
|
+
});
|
|
900
|
+
return hasDeclaration && allCustomProperties;
|
|
901
|
+
}
|
|
902
|
+
function isEmptyTwContentDeclaration(decl) {
|
|
903
|
+
return decl.prop === "--tw-content" && (decl.value === "\"\"" || decl.value === "''");
|
|
904
|
+
}
|
|
905
|
+
function isOnlyTwContentDeclarations$1(rule) {
|
|
906
|
+
let hasDeclaration = false;
|
|
907
|
+
let onlyContentVariable = true;
|
|
908
|
+
rule.walkDecls((decl) => {
|
|
909
|
+
hasDeclaration = true;
|
|
910
|
+
if (decl.prop !== "--tw-content") onlyContentVariable = false;
|
|
911
|
+
});
|
|
912
|
+
return hasDeclaration && onlyContentVariable;
|
|
913
|
+
}
|
|
914
|
+
function isPseudoContentInitRule(rule) {
|
|
915
|
+
const selector = rule.selector.replace(/\s+/g, "");
|
|
916
|
+
return PSEUDO_CONTENT_SELECTOR_RE.test(selector) && isOnlyTwContentDeclarations$1(rule);
|
|
917
|
+
}
|
|
918
|
+
function usesTwContentVariable(root) {
|
|
919
|
+
let used = false;
|
|
920
|
+
root.walkDecls((decl) => {
|
|
921
|
+
if (TW_CONTENT_VAR_RE.test(decl.value)) used = true;
|
|
922
|
+
});
|
|
923
|
+
return used;
|
|
924
|
+
}
|
|
925
|
+
function isMiniProgramPreflightRule(node) {
|
|
926
|
+
if (node.type !== "rule") return false;
|
|
927
|
+
const selectors = getRuleSelectors(node);
|
|
928
|
+
if (!isMiniProgramPreflightSelector(selectors)) return false;
|
|
929
|
+
if (selectors.includes("*")) return hasTailwindPreflightDeclaration(node);
|
|
930
|
+
if (hasTailwindVariableDeclaration(node)) return true;
|
|
931
|
+
return selectors.some((selector) => selector === ":before" || selector === ":after" || selector === "::before" || selector === "::after") && selectors.some((selector) => selector === "view" || selector === "text") && hasTailwindPreflightDeclaration(node);
|
|
932
|
+
}
|
|
933
|
+
function isBrowserElementPreflightRule(node) {
|
|
934
|
+
if (node.type !== "rule") return false;
|
|
935
|
+
const selectors = getRuleSelectors(node);
|
|
936
|
+
if (selectors.length !== 1) return false;
|
|
937
|
+
const declarations = BROWSER_PREFLIGHT_SINGLE_ELEMENT_DECLARATIONS.get(selectors[0]);
|
|
938
|
+
if (!declarations) return false;
|
|
939
|
+
let hasDeclaration = false;
|
|
940
|
+
let allBrowserPreflightDeclarations = true;
|
|
941
|
+
node.each((child) => {
|
|
942
|
+
if (child.type !== "decl") return;
|
|
943
|
+
hasDeclaration = true;
|
|
944
|
+
const key = `${child.prop.toLowerCase()}:${child.value.trim().toLowerCase()}`;
|
|
945
|
+
if (!declarations.has(key)) allBrowserPreflightDeclarations = false;
|
|
946
|
+
});
|
|
947
|
+
return hasDeclaration && allBrowserPreflightDeclarations;
|
|
948
|
+
}
|
|
949
|
+
function isMiniProgramThemeVariableRule(node) {
|
|
950
|
+
if (node.type !== "rule") return false;
|
|
951
|
+
return isMiniProgramThemeScopeSelector(getRuleSelectors(node)) && isCustomPropertyRule(node);
|
|
952
|
+
}
|
|
953
|
+
//#endregion
|
|
954
|
+
//#region src/compat/mini-program-css/root-cleanups.ts
|
|
955
|
+
function removeSpecificityPlaceholders(root) {
|
|
956
|
+
root.walkRules((rule) => {
|
|
957
|
+
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
958
|
+
let changed = false;
|
|
959
|
+
const selectors = rule.selectors.map((selector) => {
|
|
960
|
+
let next = selector;
|
|
961
|
+
for (const suffix of SPECIFICITY_PLACEHOLDER_SUFFIXES) if (next.includes(suffix)) next = next.split(suffix).join("");
|
|
962
|
+
if (next !== selector) changed = true;
|
|
963
|
+
return next;
|
|
964
|
+
});
|
|
965
|
+
if (changed) rule.selectors = selectors;
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
function hasMiniProgramCssSpecificityPlaceholders(source) {
|
|
969
|
+
return SPECIFICITY_PLACEHOLDER_SUFFIXES.some((suffix) => source.includes(suffix));
|
|
970
|
+
}
|
|
971
|
+
function stripMiniProgramCssSpecificityPlaceholders(source) {
|
|
972
|
+
let output = source;
|
|
973
|
+
for (const suffix of SPECIFICITY_PLACEHOLDER_SUFFIXES) if (output.includes(suffix)) output = output.split(suffix).join("");
|
|
974
|
+
return output;
|
|
975
|
+
}
|
|
976
|
+
const removeSpecificityPlaceholdersFromSource = stripMiniProgramCssSpecificityPlaceholders;
|
|
977
|
+
function removeRootSpecificityPlaceholders(root) {
|
|
978
|
+
root.walkRules((rule) => {
|
|
979
|
+
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
980
|
+
let changed = false;
|
|
981
|
+
const selectors = rule.selectors.map((selector) => {
|
|
982
|
+
let next = selector;
|
|
983
|
+
for (const scopeSelector of MINI_PROGRAM_THEME_SCOPE_SELECTORS) for (const suffix of ROOT_SPECIFICITY_PLACEHOLDER_SUFFIXES) {
|
|
984
|
+
const target = `${scopeSelector}${suffix}`;
|
|
985
|
+
if (next.includes(target)) next = next.split(target).join(scopeSelector);
|
|
986
|
+
}
|
|
987
|
+
if (next !== selector) changed = true;
|
|
988
|
+
return next;
|
|
989
|
+
});
|
|
990
|
+
if (changed) rule.selectors = selectors;
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
function isEffectivelyEmptyContainer(container) {
|
|
994
|
+
return container.nodes !== void 0 && container.nodes.every((node) => node.type === "comment");
|
|
995
|
+
}
|
|
996
|
+
function removeEmptyAtRules(root) {
|
|
997
|
+
let removed = 0;
|
|
998
|
+
const visit = (container) => {
|
|
999
|
+
for (const node of [...container.nodes ?? []]) {
|
|
1000
|
+
if (!("nodes" in node) || node.nodes === void 0) continue;
|
|
1001
|
+
visit(node);
|
|
1002
|
+
if (node.type === "atrule" && node.parent && isEffectivelyEmptyContainer(node)) {
|
|
1003
|
+
node.remove();
|
|
1004
|
+
removed++;
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
};
|
|
1008
|
+
visit(root);
|
|
1009
|
+
return removed;
|
|
1010
|
+
}
|
|
1011
|
+
function removeEmptyBlockAtRules(root) {
|
|
1012
|
+
let removed = 0;
|
|
1013
|
+
root.walkAtRules((atRule) => {
|
|
1014
|
+
if (atRule.nodes?.length === 0) {
|
|
1015
|
+
atRule.remove();
|
|
1016
|
+
removed++;
|
|
1017
|
+
}
|
|
1018
|
+
});
|
|
1019
|
+
return removed;
|
|
1020
|
+
}
|
|
1021
|
+
function removeEmptyAtRuleAncestors(parent) {
|
|
1022
|
+
while (parent?.type === "atrule" && isEffectivelyEmptyContainer(parent)) {
|
|
1023
|
+
const nextParent = parent.parent;
|
|
1024
|
+
parent.remove();
|
|
1025
|
+
parent = nextParent?.type === "atrule" ? nextParent : void 0;
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
function removeUnsupportedBrowserSelectors(root) {
|
|
1029
|
+
root.walkRules((rule) => {
|
|
1030
|
+
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
1031
|
+
if (isUnsupportedBrowserPreflightSelector(rule.selector)) {
|
|
1032
|
+
const parent = rule.parent;
|
|
1033
|
+
rule.remove();
|
|
1034
|
+
removeEmptyAtRuleAncestors(parent);
|
|
1035
|
+
return;
|
|
1036
|
+
}
|
|
1037
|
+
if (isBrowserElementPreflightRule(rule)) {
|
|
1038
|
+
const parent = rule.parent;
|
|
1039
|
+
rule.remove();
|
|
1040
|
+
removeEmptyAtRuleAncestors(parent);
|
|
1041
|
+
return;
|
|
1042
|
+
}
|
|
1043
|
+
const selectors = rule.selectors.filter((selector) => !isUnsupportedBrowserSelector(selector));
|
|
1044
|
+
if (selectors.length === rule.selectors.length) return;
|
|
1045
|
+
if (selectors.length === 0) {
|
|
1046
|
+
const parent = rule.parent;
|
|
1047
|
+
rule.remove();
|
|
1048
|
+
removeEmptyAtRuleAncestors(parent);
|
|
1049
|
+
return;
|
|
1050
|
+
}
|
|
1051
|
+
rule.selectors = selectors;
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
function removeDeclarationAndEmptyRule$1(decl) {
|
|
1055
|
+
const parent = decl.parent;
|
|
1056
|
+
decl.remove();
|
|
1057
|
+
if (parent?.type === "rule" && parent.nodes.length === 0) {
|
|
1058
|
+
const ruleParent = parent.parent;
|
|
1059
|
+
parent.remove();
|
|
1060
|
+
removeEmptyAtRuleAncestors(ruleParent);
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
function removeEmptyStandardDeclarations(root) {
|
|
1064
|
+
root.walkDecls((decl) => {
|
|
1065
|
+
if (!decl.prop.startsWith("--") && decl.value.trim().length === 0 && decl.next()?.type !== "comment") removeDeclarationAndEmptyRule$1(decl);
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
function removeDisplayP3Declarations(root) {
|
|
1069
|
+
root.walkAtRules((atRule) => {
|
|
1070
|
+
if (isDisplayP3MediaRule(atRule)) {
|
|
1071
|
+
const parent = atRule.parent;
|
|
1072
|
+
atRule.remove();
|
|
1073
|
+
removeEmptyAtRuleAncestors(parent);
|
|
1074
|
+
}
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
const SIMPLE_MIN_WIDTH_MEDIA_RE = /^\(\s*min-width\s*:[^)]+\)$/i;
|
|
1078
|
+
const TAILWIND_GENERATED_TOKEN_COMMENT_RE = /^\s*tokens:\s*container\s*<=\s*<tailwind generated>\s*$/i;
|
|
1079
|
+
function isContainerMaxWidthOnlyRule(rule) {
|
|
1080
|
+
if (!rule.selectors || rule.selectors.length !== 1 || rule.selectors[0] !== ".container") return false;
|
|
1081
|
+
const declarations = rule.nodes?.filter((node) => node.type === "decl") ?? [];
|
|
1082
|
+
return declarations.length === 1 && declarations[0]?.prop === "max-width" && (rule.nodes ?? []).every((node) => node.type === "decl" || node.type === "comment");
|
|
1083
|
+
}
|
|
1084
|
+
function removeTailwindContainerMaxWidthMediaRules(root) {
|
|
1085
|
+
root.walkAtRules("media", (atRule) => {
|
|
1086
|
+
if (!SIMPLE_MIN_WIDTH_MEDIA_RE.test(atRule.params.trim())) return;
|
|
1087
|
+
atRule.walkRules((rule) => {
|
|
1088
|
+
if (!isContainerMaxWidthOnlyRule(rule)) return;
|
|
1089
|
+
const parent = rule.parent;
|
|
1090
|
+
rule.remove();
|
|
1091
|
+
removeEmptyAtRuleAncestors(parent);
|
|
1092
|
+
});
|
|
1093
|
+
});
|
|
1094
|
+
}
|
|
1095
|
+
function isContainerWidthOnlyRule(rule) {
|
|
1096
|
+
if (!rule.selectors || rule.selectors.length !== 1 || rule.selectors[0] !== ".container") return false;
|
|
1097
|
+
const declarations = rule.nodes?.filter((node) => node.type === "decl") ?? [];
|
|
1098
|
+
return declarations.length === 1 && declarations[0]?.prop === "width" && declarations[0].value.trim() === "100%" && (rule.nodes ?? []).every((node) => node.type === "decl" || node.type === "comment");
|
|
1099
|
+
}
|
|
1100
|
+
function isTailwindGeneratedContainerRule(rule) {
|
|
1101
|
+
const previous = rule.prev();
|
|
1102
|
+
return previous?.type === "comment" && TAILWIND_GENERATED_TOKEN_COMMENT_RE.test(previous.text);
|
|
1103
|
+
}
|
|
1104
|
+
function removeTailwindContainerWidthRules(root, options = {}) {
|
|
1105
|
+
root.walkRules((rule) => {
|
|
1106
|
+
if (!isContainerWidthOnlyRule(rule)) return;
|
|
1107
|
+
if (options.generatedOnly && !isTailwindGeneratedContainerRule(rule)) return;
|
|
1108
|
+
const parent = rule.parent;
|
|
1109
|
+
if (isTailwindGeneratedContainerRule(rule)) rule.prev()?.remove();
|
|
1110
|
+
rule.remove();
|
|
1111
|
+
removeEmptyAtRuleAncestors(parent);
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1114
|
+
function removeUnsupportedModernColorDeclarations(root) {
|
|
1115
|
+
const customPropertyValues = /* @__PURE__ */ new Map();
|
|
1116
|
+
root.walkDecls((decl) => {
|
|
1117
|
+
if (decl.prop.startsWith("--")) customPropertyValues.set(decl.prop, decl.value.trim());
|
|
1118
|
+
});
|
|
1119
|
+
root.walkDecls((decl) => {
|
|
1120
|
+
const normalized = normalizeModernColorValue(decl.value, customPropertyValues);
|
|
1121
|
+
if (normalized.changed) {
|
|
1122
|
+
decl.value = normalized.value;
|
|
1123
|
+
if (decl.prop.startsWith("--")) customPropertyValues.set(decl.prop, decl.value.trim());
|
|
1124
|
+
}
|
|
1125
|
+
if (normalized.hasUnsupported) removeDeclarationAndEmptyRule$1(decl);
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
//#endregion
|
|
1129
|
+
//#region src/compat/tailwindcss-v4/gradients.ts
|
|
1130
|
+
function collectTailwindcssV4ThemeVariables(root) {
|
|
1131
|
+
const variables = /* @__PURE__ */ new Map();
|
|
1132
|
+
root.walkRules((rule) => {
|
|
1133
|
+
if (!testIfRootHostForV4(rule) && !rule.selector.includes("page") && !rule.selector.includes(".tw-root")) return;
|
|
1134
|
+
rule.walkDecls((decl) => {
|
|
1135
|
+
if (decl.prop.startsWith("--color-")) variables.set(decl.prop, decl.value);
|
|
1136
|
+
});
|
|
1137
|
+
});
|
|
1138
|
+
return variables;
|
|
1139
|
+
}
|
|
1140
|
+
function resolveTailwindcssV4GradientColor(value, themeVariables) {
|
|
1141
|
+
const trimmed = value.trim();
|
|
1142
|
+
const match = COLOR_VAR_RE.exec(trimmed);
|
|
1143
|
+
if (!match) return trimmed;
|
|
1144
|
+
return themeVariables.get(match[1]) ?? trimmed;
|
|
1145
|
+
}
|
|
1146
|
+
function getSingleClassSelector(selector) {
|
|
1147
|
+
const match = SIMPLE_CLASS_SELECTOR_RE.exec(selector.trim());
|
|
1148
|
+
return match ? match[1] : void 0;
|
|
1149
|
+
}
|
|
1150
|
+
function normalizeDeclarationValue(value) {
|
|
1151
|
+
return value.replace(/\s+/g, " ").trim();
|
|
1152
|
+
}
|
|
1153
|
+
function normalizeTailwindcssV4GradientPosition(value) {
|
|
1154
|
+
return value.replace(/calc\(\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:deg|grad|rad|turn))\s*\*\s*-1\s*\)/gi, "-$1").replace(/^in\s+(?:oklab|oklch|hsl|srgb)(?:\s+(?:longer|shorter|increasing|decreasing)\s+hue)?$/i, "").replace(/\s+in\s+(?:oklab|oklch|hsl|srgb)(?:\s+(?:longer|shorter|increasing|decreasing)\s+hue)?\s*$/i, "").replace(/\s+(?:longer|shorter|increasing|decreasing)\s*$/i, "").trim();
|
|
1155
|
+
}
|
|
1156
|
+
function normalizeTailwindcssV4InfinityCalcValue(value) {
|
|
1157
|
+
return INFINITY_CALC_VALUE_REGEXP.test(value.trim()) ? `${CLAMP_PX}px` : value;
|
|
1158
|
+
}
|
|
1159
|
+
const INFINITY_CALC_CSS_RE = /calc\(\s*infinity\s*\*\s*(?:\d+(?:\.\d*)?|\.\d+)r?px\s*\)/gi;
|
|
1160
|
+
/** 在预处理器解析前收敛 Tailwind v4 生成的无限圆角,避免 Sass 将 infinity 当作非法表达式。 */
|
|
1161
|
+
function normalizeTailwindcssV4InfinityCalcCss(css) {
|
|
1162
|
+
return css.replace(INFINITY_CALC_CSS_RE, `${CLAMP_PX}px`);
|
|
1163
|
+
}
|
|
1164
|
+
function normalizeTailwindcssV4GradientDirectionDeclaration(rule, decl) {
|
|
1165
|
+
const normalized = normalizeTailwindcssV4GradientPosition(decl.value);
|
|
1166
|
+
if (normalized) return normalized;
|
|
1167
|
+
const backgroundImageDecl = rule.nodes.find((node) => {
|
|
1168
|
+
return node.type === "decl" && node.prop === "background-image";
|
|
1169
|
+
});
|
|
1170
|
+
if (!backgroundImageDecl) return normalized;
|
|
1171
|
+
if (/^radial-gradient\(/i.test(backgroundImageDecl.value)) return "at center";
|
|
1172
|
+
if (/^conic-gradient\(/i.test(backgroundImageDecl.value)) return "from 0deg";
|
|
1173
|
+
return normalized;
|
|
1174
|
+
}
|
|
447
1175
|
function appendStopPosition(color, position) {
|
|
448
1176
|
const normalizedPosition = position?.trim();
|
|
449
1177
|
return normalizedPosition ? `${color} ${normalizedPosition}` : color;
|
|
@@ -817,7 +1545,7 @@ function isTailwindcssV4DisplayP3Declaration(decl) {
|
|
|
817
1545
|
}
|
|
818
1546
|
//#endregion
|
|
819
1547
|
//#region src/compat/uni-app-x-uvue/scoped-style.ts
|
|
820
|
-
const MINI_PROGRAM_PREFLIGHT_SELECTORS
|
|
1548
|
+
const MINI_PROGRAM_PREFLIGHT_SELECTORS = /* @__PURE__ */ new Set([
|
|
821
1549
|
"view",
|
|
822
1550
|
"text",
|
|
823
1551
|
"::after",
|
|
@@ -968,7 +1696,7 @@ function isUnscopedMiniProgramTailwindPreflightRule(rule, hasTailwindBanner) {
|
|
|
968
1696
|
const selectors = rule.selectors ?? [rule.selector];
|
|
969
1697
|
if (selectors.length === 0 || !selectors.every((selector) => {
|
|
970
1698
|
const normalized = normalizeCssSignatureValue(selector);
|
|
971
|
-
return !hasVueScopedAttr(selector) && MINI_PROGRAM_PREFLIGHT_SELECTORS
|
|
1699
|
+
return !hasVueScopedAttr(selector) && MINI_PROGRAM_PREFLIGHT_SELECTORS.has(normalized);
|
|
972
1700
|
})) return false;
|
|
973
1701
|
const declarations = getDeclarations(rule);
|
|
974
1702
|
return declarations.length > 0 && declarations.every((decl) => decl.prop.startsWith("--tw-") || [
|
|
@@ -978,733 +1706,416 @@ function isUnscopedMiniProgramTailwindPreflightRule(rule, hasTailwindBanner) {
|
|
|
978
1706
|
"border"
|
|
979
1707
|
].includes(decl.prop)) && hasTailwindSourceEvidence(declarations, hasTailwindBanner);
|
|
980
1708
|
}
|
|
981
|
-
function isScopedMiniProgramTailwindContentInitRule(rule) {
|
|
982
|
-
const selectors = rule.selectors ?? [rule.selector];
|
|
983
|
-
if (selectors.length === 0 || !selectors.every((selector) => {
|
|
984
|
-
const normalized = normalizeCssSignatureValue(selector);
|
|
985
|
-
return hasVueScopedAttr(selector) && MINI_PROGRAM_PREFLIGHT_SELECTORS
|
|
986
|
-
})) return false;
|
|
987
|
-
const declarations = getDeclarations(rule);
|
|
988
|
-
return declarations.length > 0 && declarations.every((decl) => decl.prop === "--tw-content");
|
|
989
|
-
}
|
|
990
|
-
function isLikelyTailwindPropertyAtRule(atRule) {
|
|
991
|
-
return typeof atRule.name === "string" && atRule.name.toLowerCase() === "property" && normalizeCssSignatureValue(atRule.params).startsWith("--tw-");
|
|
992
|
-
}
|
|
993
|
-
function stripScopedTailwindNoise(root) {
|
|
994
|
-
let hasTailwindBanner = false;
|
|
995
|
-
root.walkComments((comment) => {
|
|
996
|
-
if (TAILWIND_VERSION_COMMENT_RE.test(comment.text)) hasTailwindBanner = true;
|
|
997
|
-
});
|
|
998
|
-
root.walkComments((comment) => {
|
|
999
|
-
if (TAILWIND_VERSION_COMMENT_RE.test(comment.text)) comment.remove();
|
|
1000
|
-
});
|
|
1001
|
-
root.walkRules((rule) => {
|
|
1002
|
-
if (isScopedTailwindThemeCarrierRule(rule, hasTailwindBanner) || isScopedUniversalTailwindPreflightRule(rule, hasTailwindBanner) || isScopedTailwindElementPreflightRule(rule, hasTailwindBanner) || isUnscopedMiniProgramTailwindPreflightRule(rule, hasTailwindBanner) || isScopedMiniProgramTailwindContentInitRule(rule)) rule.remove();
|
|
1003
|
-
});
|
|
1004
|
-
root.walkAtRules((atRule) => {
|
|
1005
|
-
if (isLikelyTailwindPropertyAtRule(atRule)) {
|
|
1006
|
-
atRule.remove();
|
|
1007
|
-
return;
|
|
1008
|
-
}
|
|
1009
|
-
if ((atRule.nodes?.length ?? 0) === 0) atRule.remove();
|
|
1010
|
-
});
|
|
1011
|
-
}
|
|
1012
|
-
//#endregion
|
|
1013
|
-
//#region src/compat/uni-app-x-uvue/theme.ts
|
|
1014
|
-
const SYSTEM_ROOT_SELECTORS = /* @__PURE__ */ new Set([
|
|
1015
|
-
":host",
|
|
1016
|
-
":root",
|
|
1017
|
-
".tw-root",
|
|
1018
|
-
"page",
|
|
1019
|
-
"uni-page-body",
|
|
1020
|
-
"wx-root-portal-content"
|
|
1021
|
-
]);
|
|
1022
|
-
function normalizeSelector$2(selector) {
|
|
1023
|
-
return selector.replace(/\s+/g, "").toLowerCase();
|
|
1024
|
-
}
|
|
1025
|
-
function isUniAppXSystemRootCarrierRule(rule) {
|
|
1026
|
-
const selectors = rule.selectors ?? [];
|
|
1027
|
-
if (selectors.length === 0) return false;
|
|
1028
|
-
let hasRootMarker = false;
|
|
1029
|
-
for (const selector of selectors) {
|
|
1030
|
-
const normalized = normalizeSelector$2(selector);
|
|
1031
|
-
if (!SYSTEM_ROOT_SELECTORS.has(normalized)) return false;
|
|
1032
|
-
if (normalized === ":host" || normalized === ":root" || normalized === ".tw-root") hasRootMarker = true;
|
|
1033
|
-
}
|
|
1034
|
-
return hasRootMarker;
|
|
1035
|
-
}
|
|
1036
|
-
function resolveNodes(nodes, variables, resolving) {
|
|
1037
|
-
for (let index = 0; index < nodes.length; index++) {
|
|
1038
|
-
const node = nodes[index];
|
|
1039
|
-
if (node?.type !== "function") continue;
|
|
1040
|
-
if (node.value.toLowerCase() !== "var") {
|
|
1041
|
-
resolveNodes(node.nodes, variables, resolving);
|
|
1042
|
-
continue;
|
|
1043
|
-
}
|
|
1044
|
-
const variable = node.nodes.find((child) => child.type === "word");
|
|
1045
|
-
if (variable?.type !== "word" || !variable.value.startsWith("--")) {
|
|
1046
|
-
resolveNodes(node.nodes, variables, resolving);
|
|
1047
|
-
continue;
|
|
1048
|
-
}
|
|
1049
|
-
const commaIndex = node.nodes.findIndex((child) => child.type === "div" && child.value === ",");
|
|
1050
|
-
const fallback = commaIndex >= 0 ? postcss_value_parser.default.stringify(node.nodes.slice(commaIndex + 1)).trim() : "";
|
|
1051
|
-
const configured = variables.get(variable.value);
|
|
1052
|
-
let replacement;
|
|
1053
|
-
if (configured !== void 0 && !resolving.has(variable.value)) replacement = resolveThemeValue(configured, variables, /* @__PURE__ */ new Set([...resolving, variable.value]));
|
|
1054
|
-
else if (fallback && isTailwindcssV4ThemeVariable(variable.value)) replacement = resolveThemeValue(fallback, variables, resolving);
|
|
1055
|
-
if (replacement === void 0) {
|
|
1056
|
-
resolveNodes(node.nodes, variables, resolving);
|
|
1057
|
-
continue;
|
|
1058
|
-
}
|
|
1059
|
-
const replacementNodes = (0, postcss_value_parser.default)(replacement).nodes;
|
|
1060
|
-
nodes.splice(index, 1, ...replacementNodes);
|
|
1061
|
-
index += replacementNodes.length - 1;
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
function resolveThemeValue(value, variables, resolving = /* @__PURE__ */ new Set()) {
|
|
1065
|
-
if (!value.includes("var(")) return value;
|
|
1066
|
-
const parsed = (0, postcss_value_parser.default)(value);
|
|
1067
|
-
resolveNodes(parsed.nodes, variables, resolving);
|
|
1068
|
-
return parsed.toString();
|
|
1069
|
-
}
|
|
1070
|
-
function getUnresolvedAuthorVariableFallback(value) {
|
|
1071
|
-
const nodes = (0, postcss_value_parser.default)(value).nodes.filter((node) => node.type !== "space" && node.type !== "comment");
|
|
1072
|
-
const variable = nodes.length === 1 ? nodes[0] : void 0;
|
|
1073
|
-
if (variable?.type !== "function" || variable.value.toLowerCase() !== "var") return;
|
|
1074
|
-
const variableNode = variable.nodes.find((node) => node.type === "word");
|
|
1075
|
-
const commaIndex = variable.nodes.findIndex((node) => node.type === "div" && node.value === ",");
|
|
1076
|
-
if (variableNode?.type !== "word" || !variableNode.value.startsWith("--") || isTailwindcssV4ThemeVariable(variableNode.value) || variableNode.value.startsWith("--default-") || commaIndex < 0) return;
|
|
1077
|
-
const fallback = postcss_value_parser.default.stringify(variable.nodes.slice(commaIndex + 1)).trim();
|
|
1078
|
-
if (!fallback) return;
|
|
1079
|
-
return {
|
|
1080
|
-
name: variableNode.value,
|
|
1081
|
-
fallback
|
|
1082
|
-
};
|
|
1083
|
-
}
|
|
1084
|
-
/**
|
|
1085
|
-
* HBuilderX 不接受带 fallback 的 var() 声明,拆成静态 fallback 与动态变量两条声明。
|
|
1086
|
-
*/
|
|
1087
|
-
function splitUnresolvedAuthorVariableFallbacks(root, variables) {
|
|
1088
|
-
if (typeof root.walkDecls !== "function") return false;
|
|
1089
|
-
let changed = false;
|
|
1090
|
-
root.walkDecls((decl) => {
|
|
1091
|
-
if (decl.prop.startsWith("--")) return;
|
|
1092
|
-
const unresolved = getUnresolvedAuthorVariableFallback(decl.value);
|
|
1093
|
-
if (!unresolved || variables.has(unresolved.name)) return;
|
|
1094
|
-
decl.parent?.insertBefore(decl, decl.clone({ value: unresolved.fallback }));
|
|
1095
|
-
decl.value = `var(${unresolved.name})`;
|
|
1096
|
-
changed = true;
|
|
1097
|
-
});
|
|
1098
|
-
return changed;
|
|
1099
|
-
}
|
|
1100
|
-
/**
|
|
1101
|
-
* UVUE 不支持 Tailwind 的混合根选择器,因此先把根作用域中的静态主题 token
|
|
1102
|
-
* 内联到实际 utility,再移除仅用于变量承载的系统规则。
|
|
1103
|
-
*/
|
|
1104
|
-
function consumeUniAppXSystemRootTheme(root, customPropertyValues) {
|
|
1105
|
-
const carrierRules = [];
|
|
1106
|
-
const variables = new Map(customPropertyValues);
|
|
1107
|
-
root.walkRules((rule) => {
|
|
1108
|
-
if (!isUniAppXSystemRootCarrierRule(rule)) return;
|
|
1109
|
-
carrierRules.push(rule);
|
|
1110
|
-
rule.walkDecls((decl) => {
|
|
1111
|
-
if (decl.prop.startsWith("--")) variables.set(decl.prop, decl.value);
|
|
1112
|
-
});
|
|
1113
|
-
});
|
|
1114
|
-
if (variables.size > 0) {
|
|
1115
|
-
const carriers = new Set(carrierRules);
|
|
1116
|
-
root.walkDecls((decl) => {
|
|
1117
|
-
if (decl.parent?.type === "rule" && carriers.has(decl.parent)) return;
|
|
1118
|
-
decl.value = resolveThemeValue(decl.value, variables);
|
|
1119
|
-
});
|
|
1120
|
-
}
|
|
1121
|
-
splitUnresolvedAuthorVariableFallbacks(root, variables);
|
|
1122
|
-
for (const rule of carrierRules) rule.remove();
|
|
1123
|
-
}
|
|
1124
|
-
//#endregion
|
|
1125
|
-
//#region src/compat/uni-app-x-uvue.ts
|
|
1126
|
-
const ALLOWED_DISPLAY_VALUES = /* @__PURE__ */ new Set(["flex", "none"]);
|
|
1127
|
-
const FALLBACK_CLASS_RE = /\.((?:\\.|[\w-])+)/g;
|
|
1128
|
-
const IMPORTANT_SUFFIX_RE = /\s*!important$/i;
|
|
1129
|
-
const TRANSFORM_PROPERTIES = /* @__PURE__ */ new Set(["transform", "-webkit-transform"]);
|
|
1130
|
-
function isUniAppXUvueTarget(options) {
|
|
1131
|
-
return Boolean(options?.uniAppX) && options?.uniAppXCssTarget === "uvue";
|
|
1132
|
-
}
|
|
1133
|
-
function normalizeUnsupportedMode(mode) {
|
|
1134
|
-
return mode ?? "warn";
|
|
1135
|
-
}
|
|
1136
|
-
function normalizeValue(value) {
|
|
1137
|
-
return value.trim().toLowerCase().replace(IMPORTANT_SUFFIX_RE, "");
|
|
1138
|
-
}
|
|
1139
|
-
function hasCalcFunction(value) {
|
|
1140
|
-
const parsed = (0, postcss_value_parser.default)(value);
|
|
1141
|
-
let found = false;
|
|
1142
|
-
parsed.walk((node) => {
|
|
1143
|
-
if (node.type === "function" && node.value.toLowerCase() === "calc") found = true;
|
|
1144
|
-
});
|
|
1145
|
-
return found;
|
|
1146
|
-
}
|
|
1147
|
-
function normalizeUniAppXTransformValue(value) {
|
|
1148
|
-
if (!value.toLowerCase().includes("translate(") || !value.includes(",")) return value;
|
|
1149
|
-
const parsed = (0, postcss_value_parser.default)(value);
|
|
1150
|
-
let changed = false;
|
|
1151
|
-
parsed.walk((node) => {
|
|
1152
|
-
if (node.type !== "function" || node.value.toLowerCase() !== "translate") return;
|
|
1153
|
-
for (const child of node.nodes) {
|
|
1154
|
-
if (child.type !== "div" || child.value !== ",") continue;
|
|
1155
|
-
child.value = " ";
|
|
1156
|
-
child.before = "";
|
|
1157
|
-
child.after = "";
|
|
1158
|
-
changed = true;
|
|
1159
|
-
}
|
|
1160
|
-
});
|
|
1161
|
-
return changed ? parsed.toString() : value;
|
|
1162
|
-
}
|
|
1163
|
-
function getSourceFile(rule, result) {
|
|
1164
|
-
return rule.source?.input.from ?? result.opts.from ?? "unknown source";
|
|
1165
|
-
}
|
|
1166
|
-
function collectUtilityClassNames(rule) {
|
|
1167
|
-
const classNames = /* @__PURE__ */ new Set();
|
|
1168
|
-
for (const selector of rule.selectors ?? []) try {
|
|
1169
|
-
(0, postcss_selector_parser.default)().astSync(selector).walkClasses((node) => {
|
|
1170
|
-
if (node.value) classNames.add(node.value);
|
|
1171
|
-
});
|
|
1172
|
-
} catch {
|
|
1173
|
-
for (const match of selector.matchAll(FALLBACK_CLASS_RE)) if (match[1]) classNames.add(match[1].replaceAll("\\", ""));
|
|
1174
|
-
}
|
|
1175
|
-
return [...classNames];
|
|
1176
|
-
}
|
|
1177
|
-
function hasOnlyClassSelectors(rule) {
|
|
1178
|
-
const selectors = rule.selectors ?? [];
|
|
1179
|
-
if (selectors.length === 0) return false;
|
|
1180
|
-
return selectors.every((selector) => {
|
|
1181
|
-
try {
|
|
1182
|
-
return (0, postcss_selector_parser.default)().astSync(selector).nodes.every((node) => node.nodes.length > 0 && node.nodes.every((child) => child.type === "class"));
|
|
1183
|
-
} catch {
|
|
1184
|
-
return false;
|
|
1185
|
-
}
|
|
1186
|
-
});
|
|
1187
|
-
}
|
|
1188
|
-
function getUnsupportedDeclarationReason(prop, value) {
|
|
1189
|
-
const normalizedProp = prop.trim().toLowerCase();
|
|
1190
|
-
const normalizedValue = normalizeValue(value);
|
|
1191
|
-
if (hasCalcFunction(value)) return `${normalizedProp}: ${value}`;
|
|
1192
|
-
if (normalizedProp === "display" && !ALLOWED_DISPLAY_VALUES.has(normalizedValue)) return `${normalizedProp}: ${value}`;
|
|
1193
|
-
if (normalizedProp === "min-height" && normalizedValue === "100vh") return `${normalizedProp}: ${value}`;
|
|
1194
|
-
if (normalizedProp === "grid-template-columns" || normalizedProp === "grid-template-rows" || normalizedProp === "grid-auto-columns" || normalizedProp === "grid-auto-rows" || normalizedProp === "grid-auto-flow") return `${normalizedProp}: ${value}`;
|
|
1195
|
-
if (normalizedProp === "gap" || normalizedProp === "row-gap" || normalizedProp === "column-gap") return `${normalizedProp}: ${value}`;
|
|
1709
|
+
function isScopedMiniProgramTailwindContentInitRule(rule) {
|
|
1710
|
+
const selectors = rule.selectors ?? [rule.selector];
|
|
1711
|
+
if (selectors.length === 0 || !selectors.every((selector) => {
|
|
1712
|
+
const normalized = normalizeCssSignatureValue(selector);
|
|
1713
|
+
return hasVueScopedAttr(selector) && MINI_PROGRAM_PREFLIGHT_SELECTORS.has(normalized);
|
|
1714
|
+
})) return false;
|
|
1715
|
+
const declarations = getDeclarations(rule);
|
|
1716
|
+
return declarations.length > 0 && declarations.every((decl) => decl.prop === "--tw-content");
|
|
1196
1717
|
}
|
|
1197
|
-
function
|
|
1198
|
-
|
|
1199
|
-
const classNames = collectUtilityClassNames(rule);
|
|
1200
|
-
const message = `uni-app x uvue unsupported utility: ${classNames.length > 0 ? classNames.join(", ") : rule.selector} (${reason}) in ${getSourceFile(rule, result)}`;
|
|
1201
|
-
if (mode === "error") throw rule.error(message);
|
|
1202
|
-
if (warningCache.has(message)) return;
|
|
1203
|
-
warningCache.add(message);
|
|
1204
|
-
rule.warn(result, message);
|
|
1718
|
+
function isLikelyTailwindPropertyAtRule(atRule) {
|
|
1719
|
+
return typeof atRule.name === "string" && atRule.name.toLowerCase() === "property" && normalizeCssSignatureValue(atRule.params).startsWith("--tw-");
|
|
1205
1720
|
}
|
|
1206
|
-
function
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
if (root.type === "root" && Array.isArray(root.nodes) && typeof root.walkDecls === "function") {
|
|
1215
|
-
root.walkDecls((decl) => {
|
|
1216
|
-
normalizeTailwindcssV4Declaration(decl);
|
|
1217
|
-
if (TRANSFORM_PROPERTIES.has(decl.prop.toLowerCase())) decl.value = normalizeUniAppXTransformValue(decl.value);
|
|
1218
|
-
});
|
|
1219
|
-
const calcResult = (0, postcss.default)([(0, _weapp_tailwindcss_postcss_calc.default)()]).process(root, result.opts).sync();
|
|
1220
|
-
root = calcResult.root;
|
|
1221
|
-
calcMessages = calcResult.messages;
|
|
1222
|
-
}
|
|
1223
|
-
if (sfcStyleRequest) {
|
|
1224
|
-
stripScopedTailwindNoise(root);
|
|
1225
|
-
const nextResult = root.toResult(result.opts);
|
|
1226
|
-
nextResult.messages.push(...result.messages);
|
|
1227
|
-
nextResult.messages.push(...calcMessages);
|
|
1228
|
-
return nextResult;
|
|
1229
|
-
}
|
|
1721
|
+
function stripScopedTailwindNoise(root) {
|
|
1722
|
+
let hasTailwindBanner = false;
|
|
1723
|
+
root.walkComments((comment) => {
|
|
1724
|
+
if (TAILWIND_VERSION_COMMENT_RE.test(comment.text)) hasTailwindBanner = true;
|
|
1725
|
+
});
|
|
1726
|
+
root.walkComments((comment) => {
|
|
1727
|
+
if (TAILWIND_VERSION_COMMENT_RE.test(comment.text)) comment.remove();
|
|
1728
|
+
});
|
|
1230
1729
|
root.walkRules((rule) => {
|
|
1231
|
-
if (
|
|
1232
|
-
reportUnsupportedRule(rule, result, mode, warningCache, "selector must be class-only");
|
|
1233
|
-
rule.remove();
|
|
1234
|
-
return;
|
|
1235
|
-
}
|
|
1236
|
-
rule.walkDecls((decl) => {
|
|
1237
|
-
const reason = getUnsupportedDeclarationReason(decl.prop, decl.value);
|
|
1238
|
-
if (!reason) return;
|
|
1239
|
-
reportUnsupportedRule(rule, result, mode, warningCache, reason);
|
|
1240
|
-
decl.remove();
|
|
1241
|
-
});
|
|
1242
|
-
if ((rule.nodes?.length ?? 0) === 0) rule.remove();
|
|
1730
|
+
if (isScopedTailwindThemeCarrierRule(rule, hasTailwindBanner) || isScopedUniversalTailwindPreflightRule(rule, hasTailwindBanner) || isScopedTailwindElementPreflightRule(rule, hasTailwindBanner) || isUnscopedMiniProgramTailwindPreflightRule(rule, hasTailwindBanner) || isScopedMiniProgramTailwindContentInitRule(rule)) rule.remove();
|
|
1243
1731
|
});
|
|
1244
1732
|
root.walkAtRules((atRule) => {
|
|
1245
|
-
if (atRule
|
|
1733
|
+
if (isLikelyTailwindPropertyAtRule(atRule)) {
|
|
1246
1734
|
atRule.remove();
|
|
1247
1735
|
return;
|
|
1248
1736
|
}
|
|
1249
1737
|
if ((atRule.nodes?.length ?? 0) === 0) atRule.remove();
|
|
1250
1738
|
});
|
|
1251
|
-
const nextResult = root.toResult(result.opts);
|
|
1252
|
-
nextResult.messages.push(...result.messages);
|
|
1253
|
-
nextResult.messages.push(...calcMessages);
|
|
1254
|
-
return nextResult;
|
|
1255
|
-
}
|
|
1256
|
-
//#endregion
|
|
1257
|
-
//#region src/branches/uni-app-x-css-uvue/index.ts
|
|
1258
|
-
function postprocessUniAppXUvueCss(result, options) {
|
|
1259
|
-
return applyUniAppXUvueCompatibility(applyUniAppXBaseCompatibility(result, options), options);
|
|
1260
|
-
}
|
|
1261
|
-
//#endregion
|
|
1262
|
-
//#region src/branches/uni-app-x-css-webview/index.ts
|
|
1263
|
-
function postprocessUniAppXWebviewCss(result, options) {
|
|
1264
|
-
return applyUniAppXBaseCompatibility(result, options);
|
|
1265
|
-
}
|
|
1266
|
-
//#endregion
|
|
1267
|
-
//#region src/branches/web/index.ts
|
|
1268
|
-
function postprocessWebCss(result, _options) {
|
|
1269
|
-
return result;
|
|
1270
1739
|
}
|
|
1271
1740
|
//#endregion
|
|
1272
|
-
//#region src/
|
|
1273
|
-
|
|
1274
|
-
|
|
1741
|
+
//#region src/compat/uni-app-x-uvue/theme.ts
|
|
1742
|
+
const SYSTEM_ROOT_SELECTORS = /* @__PURE__ */ new Set([
|
|
1743
|
+
":host",
|
|
1744
|
+
":root",
|
|
1745
|
+
".tw-root",
|
|
1746
|
+
"page",
|
|
1747
|
+
"uni-page-body",
|
|
1748
|
+
"wx-root-portal-content"
|
|
1749
|
+
]);
|
|
1750
|
+
function normalizeSelector$1(selector) {
|
|
1751
|
+
return selector.replace(/\s+/g, "").toLowerCase();
|
|
1275
1752
|
}
|
|
1276
|
-
function
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
postprocess: postprocessUniAppXUvueCss
|
|
1285
|
-
};
|
|
1286
|
-
case "uni-app-x-css-webview": return {
|
|
1287
|
-
target,
|
|
1288
|
-
postprocess: postprocessUniAppXWebviewCss
|
|
1289
|
-
};
|
|
1290
|
-
case "web": return {
|
|
1291
|
-
target,
|
|
1292
|
-
postprocess: postprocessWebCss
|
|
1293
|
-
};
|
|
1294
|
-
default: return {
|
|
1295
|
-
target,
|
|
1296
|
-
postprocess: postprocessGenericCss
|
|
1297
|
-
};
|
|
1753
|
+
function isUniAppXSystemRootCarrierRule(rule) {
|
|
1754
|
+
const selectors = rule.selectors ?? [];
|
|
1755
|
+
if (selectors.length === 0) return false;
|
|
1756
|
+
let hasRootMarker = false;
|
|
1757
|
+
for (const selector of selectors) {
|
|
1758
|
+
const normalized = normalizeSelector$1(selector);
|
|
1759
|
+
if (!SYSTEM_ROOT_SELECTORS.has(normalized)) return false;
|
|
1760
|
+
if (normalized === ":host" || normalized === ":root" || normalized === ".tw-root") hasRootMarker = true;
|
|
1298
1761
|
}
|
|
1762
|
+
return hasRootMarker;
|
|
1299
1763
|
}
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1764
|
+
function resolveNodes(nodes, variables, resolving) {
|
|
1765
|
+
for (let index = 0; index < nodes.length; index++) {
|
|
1766
|
+
const node = nodes[index];
|
|
1767
|
+
if (node?.type !== "function") continue;
|
|
1768
|
+
if (node.value.toLowerCase() !== "var") {
|
|
1769
|
+
resolveNodes(node.nodes, variables, resolving);
|
|
1770
|
+
continue;
|
|
1771
|
+
}
|
|
1772
|
+
const variable = node.nodes.find((child) => child.type === "word");
|
|
1773
|
+
if (variable?.type !== "word" || !variable.value.startsWith("--")) {
|
|
1774
|
+
resolveNodes(node.nodes, variables, resolving);
|
|
1775
|
+
continue;
|
|
1776
|
+
}
|
|
1777
|
+
const commaIndex = node.nodes.findIndex((child) => child.type === "div" && child.value === ",");
|
|
1778
|
+
const fallback = commaIndex >= 0 ? postcss_value_parser.default.stringify(node.nodes.slice(commaIndex + 1)).trim() : "";
|
|
1779
|
+
const configured = variables.get(variable.value);
|
|
1780
|
+
let replacement;
|
|
1781
|
+
if (configured !== void 0 && !resolving.has(variable.value)) replacement = resolveThemeValue(configured, variables, /* @__PURE__ */ new Set([...resolving, variable.value]));
|
|
1782
|
+
else if (fallback && isTailwindcssV4ThemeVariable(variable.value)) replacement = resolveThemeValue(fallback, variables, resolving);
|
|
1783
|
+
if (replacement === void 0) {
|
|
1784
|
+
resolveNodes(node.nodes, variables, resolving);
|
|
1785
|
+
continue;
|
|
1786
|
+
}
|
|
1787
|
+
const replacementNodes = (0, postcss_value_parser.default)(replacement).nodes;
|
|
1788
|
+
nodes.splice(index, 1, ...replacementNodes);
|
|
1789
|
+
index += replacementNodes.length - 1;
|
|
1790
|
+
}
|
|
1305
1791
|
}
|
|
1306
|
-
function
|
|
1307
|
-
|
|
1792
|
+
function resolveThemeValue(value, variables, resolving = /* @__PURE__ */ new Set()) {
|
|
1793
|
+
if (!value.includes("var(")) return value;
|
|
1794
|
+
const parsed = (0, postcss_value_parser.default)(value);
|
|
1795
|
+
resolveNodes(parsed.nodes, variables, resolving);
|
|
1796
|
+
return parsed.toString();
|
|
1308
1797
|
}
|
|
1309
|
-
function
|
|
1798
|
+
function getUnresolvedAuthorVariableFallback(value) {
|
|
1799
|
+
const nodes = (0, postcss_value_parser.default)(value).nodes.filter((node) => node.type !== "space" && node.type !== "comment");
|
|
1800
|
+
const variable = nodes.length === 1 ? nodes[0] : void 0;
|
|
1801
|
+
if (variable?.type !== "function" || variable.value.toLowerCase() !== "var") return;
|
|
1802
|
+
const variableNode = variable.nodes.find((node) => node.type === "word");
|
|
1803
|
+
const commaIndex = variable.nodes.findIndex((node) => node.type === "div" && node.value === ",");
|
|
1804
|
+
if (variableNode?.type !== "word" || !variableNode.value.startsWith("--") || isTailwindcssV4ThemeVariable(variableNode.value) || variableNode.value.startsWith("--default-") || commaIndex < 0) return;
|
|
1805
|
+
const fallback = postcss_value_parser.default.stringify(variable.nodes.slice(commaIndex + 1)).trim();
|
|
1806
|
+
if (!fallback) return;
|
|
1310
1807
|
return {
|
|
1311
|
-
|
|
1312
|
-
|
|
1808
|
+
name: variableNode.value,
|
|
1809
|
+
fallback
|
|
1313
1810
|
};
|
|
1314
1811
|
}
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
const
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
//#endregion
|
|
1331
|
-
//#region src/frameworks/taro/index.ts
|
|
1332
|
-
const taroPostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("taro", "mini-program");
|
|
1333
|
-
//#endregion
|
|
1334
|
-
//#region src/frameworks/uni-app/index.ts
|
|
1335
|
-
const uniAppPostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("uni-app", "mini-program");
|
|
1336
|
-
//#endregion
|
|
1337
|
-
//#region src/frameworks/uni-app-vite/index.ts
|
|
1338
|
-
const uniAppVitePostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("uni-app-vite", "mini-program");
|
|
1339
|
-
//#endregion
|
|
1340
|
-
//#region src/frameworks/uni-app-x/index.ts
|
|
1341
|
-
const uniAppXPostcssFrameworkStrategy = {
|
|
1342
|
-
framework: "uni-app-x",
|
|
1343
|
-
resolveStyleTarget: (options) => options.uniAppXCssTarget === "uvue" ? "uni-app-x-css-uvue" : "uni-app-x-css-webview"
|
|
1344
|
-
};
|
|
1345
|
-
//#endregion
|
|
1346
|
-
//#region src/frameworks/weapp-vite/index.ts
|
|
1347
|
-
const weappVitePostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("weapp-vite", "mini-program");
|
|
1348
|
-
//#endregion
|
|
1349
|
-
//#region src/frameworks/index.ts
|
|
1350
|
-
function isUniAppXFramework(options) {
|
|
1351
|
-
if (options.uniAppX === false) return false;
|
|
1352
|
-
return options.uniAppX === true || options.appType === "uni-app-x";
|
|
1353
|
-
}
|
|
1354
|
-
function resolvePostcssFrameworkStrategy(options) {
|
|
1355
|
-
if (isUniAppXFramework(options)) return uniAppXPostcssFrameworkStrategy;
|
|
1356
|
-
switch (options.appType) {
|
|
1357
|
-
case "kbone": return kbonePostcssFrameworkStrategy;
|
|
1358
|
-
case "mpx": return mpxPostcssFrameworkStrategy;
|
|
1359
|
-
case "native": return nativePostcssFrameworkStrategy;
|
|
1360
|
-
case "remax": return remaxPostcssFrameworkStrategy;
|
|
1361
|
-
case "taro": return taroPostcssFrameworkStrategy;
|
|
1362
|
-
case "uni-app": return uniAppPostcssFrameworkStrategy;
|
|
1363
|
-
case "uni-app-vite": return uniAppVitePostcssFrameworkStrategy;
|
|
1364
|
-
case "weapp-vite": return weappVitePostcssFrameworkStrategy;
|
|
1365
|
-
default: return genericPostcssFrameworkStrategy;
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
function resolvePostcssFrameworkProfile(options) {
|
|
1369
|
-
const strategy = resolvePostcssFrameworkStrategy(options);
|
|
1370
|
-
const target = strategy.resolveStyleTarget(options);
|
|
1371
|
-
const targetProfile = createPostcssStyleTargetProfile(target);
|
|
1372
|
-
return {
|
|
1373
|
-
framework: strategy.framework,
|
|
1374
|
-
target,
|
|
1375
|
-
branch: target,
|
|
1376
|
-
postprocess: targetProfile.postprocess
|
|
1377
|
-
};
|
|
1812
|
+
/**
|
|
1813
|
+
* HBuilderX 不接受带 fallback 的 var() 声明,拆成静态 fallback 与动态变量两条声明。
|
|
1814
|
+
*/
|
|
1815
|
+
function splitUnresolvedAuthorVariableFallbacks(root, variables) {
|
|
1816
|
+
if (typeof root.walkDecls !== "function") return false;
|
|
1817
|
+
let changed = false;
|
|
1818
|
+
root.walkDecls((decl) => {
|
|
1819
|
+
if (decl.prop.startsWith("--")) return;
|
|
1820
|
+
const unresolved = getUnresolvedAuthorVariableFallback(decl.value);
|
|
1821
|
+
if (!unresolved || variables.has(unresolved.name)) return;
|
|
1822
|
+
decl.parent?.insertBefore(decl, decl.clone({ value: unresolved.fallback }));
|
|
1823
|
+
decl.value = `var(${unresolved.name})`;
|
|
1824
|
+
changed = true;
|
|
1825
|
+
});
|
|
1826
|
+
return changed;
|
|
1378
1827
|
}
|
|
1379
|
-
|
|
1380
|
-
|
|
1828
|
+
/**
|
|
1829
|
+
* UVUE 不支持 Tailwind 的混合根选择器,因此先把根作用域中的静态主题 token
|
|
1830
|
+
* 内联到实际 utility,再移除仅用于变量承载的系统规则。
|
|
1831
|
+
*/
|
|
1832
|
+
function consumeUniAppXSystemRootTheme(root, customPropertyValues) {
|
|
1833
|
+
const carrierRules = [];
|
|
1834
|
+
const variables = new Map(customPropertyValues);
|
|
1835
|
+
root.walkRules((rule) => {
|
|
1836
|
+
if (!isUniAppXSystemRootCarrierRule(rule)) return;
|
|
1837
|
+
carrierRules.push(rule);
|
|
1838
|
+
rule.walkDecls((decl) => {
|
|
1839
|
+
if (decl.prop.startsWith("--")) variables.set(decl.prop, decl.value);
|
|
1840
|
+
});
|
|
1841
|
+
});
|
|
1842
|
+
if (variables.size > 0) {
|
|
1843
|
+
const carriers = new Set(carrierRules);
|
|
1844
|
+
root.walkDecls((decl) => {
|
|
1845
|
+
if (decl.parent?.type === "rule" && carriers.has(decl.parent)) return;
|
|
1846
|
+
decl.value = resolveThemeValue(decl.value, variables);
|
|
1847
|
+
});
|
|
1848
|
+
}
|
|
1849
|
+
splitUnresolvedAuthorVariableFallbacks(root, variables);
|
|
1850
|
+
for (const rule of carrierRules) rule.remove();
|
|
1381
1851
|
}
|
|
1382
1852
|
//#endregion
|
|
1383
|
-
//#region src/
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1853
|
+
//#region src/compat/uni-app-x-uvue.ts
|
|
1854
|
+
const ALLOWED_DISPLAY_VALUES = /* @__PURE__ */ new Set(["flex", "none"]);
|
|
1855
|
+
const FALLBACK_CLASS_RE = /\.((?:\\.|[\w-])+)/g;
|
|
1856
|
+
const IMPORTANT_SUFFIX_RE = /\s*!important$/i;
|
|
1857
|
+
const TRANSFORM_PROPERTIES = /* @__PURE__ */ new Set(["transform", "-webkit-transform"]);
|
|
1858
|
+
function isUniAppXUvueTarget(options) {
|
|
1859
|
+
return Boolean(options?.uniAppX) && options?.uniAppXCssTarget === "uvue";
|
|
1389
1860
|
}
|
|
1390
|
-
|
|
1391
|
-
"
|
|
1392
|
-
"oklab",
|
|
1393
|
-
"lch",
|
|
1394
|
-
"lab"
|
|
1395
|
-
]);
|
|
1396
|
-
const MODERN_COLOR_SYNTAX_FUNCTION_NAMES = /* @__PURE__ */ new Set([
|
|
1397
|
-
"rgb",
|
|
1398
|
-
"rgba",
|
|
1399
|
-
"hsl",
|
|
1400
|
-
"hsla",
|
|
1401
|
-
"hwb"
|
|
1402
|
-
]);
|
|
1403
|
-
const PLACEHOLDER_PREFIX = "__weapp_tw_color_mix_";
|
|
1404
|
-
const DYNAMIC_ALPHA_RE = /\b(?:var|env)\(|--[\w-]+\b/;
|
|
1405
|
-
const INTERNAL_TAILWIND_ALPHA_RE = /var\(\s*--tw-[^)]+-alpha\s*\)/;
|
|
1406
|
-
const TRANSPARENT_COLOR_RE = /^transparent$/i;
|
|
1407
|
-
const CURRENT_COLOR_RE = /^currentcolor$/i;
|
|
1408
|
-
const CSS_WIDE_KEYWORD_RE = /^(?:inherit|initial|unset|revert|revert-layer)$/i;
|
|
1409
|
-
const CUSTOM_PROPERTY_RE = /^--[\w-]+$/;
|
|
1410
|
-
//#endregion
|
|
1411
|
-
//#region src/compat/color-mix/modern.ts
|
|
1412
|
-
function isDisplayP3ColorFunction(colorSource) {
|
|
1413
|
-
return /^color\(\s*display-p3\b/i.test(colorSource.trim());
|
|
1861
|
+
function normalizeUnsupportedMode(mode) {
|
|
1862
|
+
return mode ?? "warn";
|
|
1414
1863
|
}
|
|
1415
|
-
function
|
|
1416
|
-
|
|
1417
|
-
const node = parsed.nodes.length === 1 ? parsed.nodes[0] : void 0;
|
|
1418
|
-
if (node?.type !== "function") return false;
|
|
1419
|
-
const name = node.value.toLowerCase();
|
|
1420
|
-
if (!MODERN_COLOR_SYNTAX_FUNCTION_NAMES.has(name)) return false;
|
|
1421
|
-
return !node.nodes.some((child) => child.type === "div" && child.value === ",");
|
|
1864
|
+
function normalizeValue(value) {
|
|
1865
|
+
return value.trim().toLowerCase().replace(IMPORTANT_SUFFIX_RE, "");
|
|
1422
1866
|
}
|
|
1423
|
-
function
|
|
1867
|
+
function hasCalcFunction(value) {
|
|
1424
1868
|
const parsed = (0, postcss_value_parser.default)(value);
|
|
1425
|
-
let
|
|
1869
|
+
let found = false;
|
|
1426
1870
|
parsed.walk((node) => {
|
|
1427
|
-
if (node.type
|
|
1428
|
-
const name = node.value.toLowerCase();
|
|
1429
|
-
if (name === "color-mix" || MODERN_COLOR_FUNCTION_NAMES.has(name) || name === "color" && isDisplayP3ColorFunction(postcss_value_parser.default.stringify(node)) || isModernColorSyntaxFunction(postcss_value_parser.default.stringify(node))) {
|
|
1430
|
-
hasUnsupported = true;
|
|
1431
|
-
return false;
|
|
1432
|
-
}
|
|
1871
|
+
if (node.type === "function" && node.value.toLowerCase() === "calc") found = true;
|
|
1433
1872
|
});
|
|
1434
|
-
return
|
|
1435
|
-
}
|
|
1436
|
-
//#endregion
|
|
1437
|
-
//#region src/compat/color-mix/parse.ts
|
|
1438
|
-
function splitArguments(nodes) {
|
|
1439
|
-
const args = [];
|
|
1440
|
-
let current = [];
|
|
1441
|
-
for (const node of nodes) {
|
|
1442
|
-
if (node.type === "div" && node.value === ",") {
|
|
1443
|
-
args.push(current);
|
|
1444
|
-
current = [];
|
|
1445
|
-
continue;
|
|
1446
|
-
}
|
|
1447
|
-
current.push(node);
|
|
1448
|
-
}
|
|
1449
|
-
args.push(current);
|
|
1450
|
-
return args;
|
|
1873
|
+
return found;
|
|
1451
1874
|
}
|
|
1452
|
-
function
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1875
|
+
function normalizeUniAppXTransformValue(value) {
|
|
1876
|
+
if (!value.toLowerCase().includes("translate(") || !value.includes(",")) return value;
|
|
1877
|
+
const parsed = (0, postcss_value_parser.default)(value);
|
|
1878
|
+
let changed = false;
|
|
1879
|
+
parsed.walk((node) => {
|
|
1880
|
+
if (node.type !== "function" || node.value.toLowerCase() !== "translate") return;
|
|
1881
|
+
for (const child of node.nodes) {
|
|
1882
|
+
if (child.type !== "div" || child.value !== ",") continue;
|
|
1883
|
+
child.value = " ";
|
|
1884
|
+
child.before = "";
|
|
1885
|
+
child.after = "";
|
|
1886
|
+
changed = true;
|
|
1462
1887
|
}
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
if (current.length > 0) segments.push(current);
|
|
1466
|
-
return segments;
|
|
1888
|
+
});
|
|
1889
|
+
return changed ? parsed.toString() : value;
|
|
1467
1890
|
}
|
|
1468
|
-
function
|
|
1469
|
-
|
|
1470
|
-
let end = nodes.length;
|
|
1471
|
-
while (start < end && nodes[start]?.type === "space") start += 1;
|
|
1472
|
-
while (end > start && nodes[end - 1]?.type === "space") end -= 1;
|
|
1473
|
-
return nodes.slice(start, end);
|
|
1891
|
+
function getSourceFile(rule, result) {
|
|
1892
|
+
return rule.source?.input.from ?? result.opts.from ?? "unknown source";
|
|
1474
1893
|
}
|
|
1475
|
-
function
|
|
1476
|
-
|
|
1477
|
-
|
|
1894
|
+
function collectUtilityClassNames(rule) {
|
|
1895
|
+
const classNames = /* @__PURE__ */ new Set();
|
|
1896
|
+
for (const selector of rule.selectors ?? []) try {
|
|
1897
|
+
(0, postcss_selector_parser.default)().astSync(selector).walkClasses((node) => {
|
|
1898
|
+
if (node.value) classNames.add(node.value);
|
|
1899
|
+
});
|
|
1478
1900
|
} catch {
|
|
1479
|
-
|
|
1901
|
+
for (const match of selector.matchAll(FALLBACK_CLASS_RE)) if (match[1]) classNames.add(match[1].replaceAll("\\", ""));
|
|
1480
1902
|
}
|
|
1903
|
+
return [...classNames];
|
|
1481
1904
|
}
|
|
1482
|
-
function
|
|
1483
|
-
const
|
|
1484
|
-
if (
|
|
1905
|
+
function hasOnlyClassSelectors(rule) {
|
|
1906
|
+
const selectors = rule.selectors ?? [];
|
|
1907
|
+
if (selectors.length === 0) return false;
|
|
1908
|
+
return selectors.every((selector) => {
|
|
1909
|
+
try {
|
|
1910
|
+
return (0, postcss_selector_parser.default)().astSync(selector).nodes.every((node) => node.nodes.length > 0 && node.nodes.every((child) => child.type === "class"));
|
|
1911
|
+
} catch {
|
|
1912
|
+
return false;
|
|
1913
|
+
}
|
|
1914
|
+
});
|
|
1485
1915
|
}
|
|
1486
|
-
function
|
|
1487
|
-
|
|
1488
|
-
const
|
|
1489
|
-
|
|
1490
|
-
if (
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
if (
|
|
1494
|
-
const resolved = customPropertyValues.get(propertyName);
|
|
1495
|
-
if (!resolved) {
|
|
1496
|
-
const fallback = args[1] ? postcss_value_parser.default.stringify(trimNodes$1(args[1])).trim() : void 0;
|
|
1497
|
-
return fallback ? resolveColorData(fallback, customPropertyValues, depth + 1) : void 0;
|
|
1498
|
-
}
|
|
1499
|
-
return resolveColorData(resolved, customPropertyValues, depth + 1);
|
|
1916
|
+
function getUnsupportedDeclarationReason(prop, value) {
|
|
1917
|
+
const normalizedProp = prop.trim().toLowerCase();
|
|
1918
|
+
const normalizedValue = normalizeValue(value);
|
|
1919
|
+
if (hasCalcFunction(value)) return `${normalizedProp}: ${value}`;
|
|
1920
|
+
if (normalizedProp === "display" && !ALLOWED_DISPLAY_VALUES.has(normalizedValue)) return `${normalizedProp}: ${value}`;
|
|
1921
|
+
if (normalizedProp === "min-height" && normalizedValue === "100vh") return `${normalizedProp}: ${value}`;
|
|
1922
|
+
if (normalizedProp === "grid-template-columns" || normalizedProp === "grid-template-rows" || normalizedProp === "grid-auto-columns" || normalizedProp === "grid-auto-rows" || normalizedProp === "grid-auto-flow") return `${normalizedProp}: ${value}`;
|
|
1923
|
+
if (normalizedProp === "gap" || normalizedProp === "row-gap" || normalizedProp === "column-gap") return `${normalizedProp}: ${value}`;
|
|
1500
1924
|
}
|
|
1501
|
-
function
|
|
1502
|
-
if (
|
|
1503
|
-
const
|
|
1504
|
-
|
|
1505
|
-
if (
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1925
|
+
function reportUnsupportedRule(rule, result, mode, warningCache, reason) {
|
|
1926
|
+
if (mode === "silent") return;
|
|
1927
|
+
const classNames = collectUtilityClassNames(rule);
|
|
1928
|
+
const message = `uni-app x uvue unsupported utility: ${classNames.length > 0 ? classNames.join(", ") : rule.selector} (${reason}) in ${getSourceFile(rule, result)}`;
|
|
1929
|
+
if (mode === "error") throw rule.error(message);
|
|
1930
|
+
if (warningCache.has(message)) return;
|
|
1931
|
+
warningCache.add(message);
|
|
1932
|
+
rule.warn(result, message);
|
|
1509
1933
|
}
|
|
1510
|
-
function
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1934
|
+
function applyUniAppXUvueCompatibility(result, options) {
|
|
1935
|
+
if (!isUniAppXUvueTarget(options)) return result;
|
|
1936
|
+
const mode = normalizeUnsupportedMode(options?.uniAppXUnsupported);
|
|
1937
|
+
const warningCache = /* @__PURE__ */ new Set();
|
|
1938
|
+
const sfcStyleRequest = options?.isMainChunk !== true && isUvueSfcStyleRequest(result);
|
|
1939
|
+
let root = result.root;
|
|
1940
|
+
let calcMessages = [];
|
|
1941
|
+
consumeUniAppXSystemRootTheme(root, options?.customPropertyValues);
|
|
1942
|
+
if (root.type === "root" && Array.isArray(root.nodes) && typeof root.walkDecls === "function") {
|
|
1943
|
+
root.walkDecls((decl) => {
|
|
1944
|
+
normalizeTailwindcssV4Declaration(decl);
|
|
1945
|
+
if (TRANSFORM_PROPERTIES.has(decl.prop.toLowerCase())) decl.value = normalizeUniAppXTransformValue(decl.value);
|
|
1946
|
+
});
|
|
1947
|
+
const calcResult = (0, postcss.default)([(0, _weapp_tailwindcss_postcss_calc.default)()]).process(root, result.opts).sync();
|
|
1948
|
+
root = calcResult.root;
|
|
1949
|
+
calcMessages = calcResult.messages;
|
|
1950
|
+
removeEmptyStandardDeclarations(root);
|
|
1951
|
+
}
|
|
1952
|
+
if (sfcStyleRequest) {
|
|
1953
|
+
stripScopedTailwindNoise(root);
|
|
1954
|
+
const nextResult = root.toResult(result.opts);
|
|
1955
|
+
nextResult.messages.push(...result.messages);
|
|
1956
|
+
nextResult.messages.push(...calcMessages);
|
|
1957
|
+
return nextResult;
|
|
1958
|
+
}
|
|
1959
|
+
root.walkRules((rule) => {
|
|
1960
|
+
if (!hasOnlyClassSelectors(rule)) {
|
|
1961
|
+
reportUnsupportedRule(rule, result, mode, warningCache, "selector must be class-only");
|
|
1962
|
+
rule.remove();
|
|
1963
|
+
return;
|
|
1964
|
+
}
|
|
1965
|
+
rule.walkDecls((decl) => {
|
|
1966
|
+
const reason = getUnsupportedDeclarationReason(decl.prop, decl.value);
|
|
1967
|
+
if (!reason) return;
|
|
1968
|
+
reportUnsupportedRule(rule, result, mode, warningCache, reason);
|
|
1969
|
+
decl.remove();
|
|
1970
|
+
});
|
|
1971
|
+
if ((rule.nodes?.length ?? 0) === 0) rule.remove();
|
|
1972
|
+
});
|
|
1973
|
+
root.walkAtRules((atRule) => {
|
|
1974
|
+
if (atRule.name?.toLowerCase() === "property") {
|
|
1975
|
+
atRule.remove();
|
|
1976
|
+
return;
|
|
1977
|
+
}
|
|
1978
|
+
if ((atRule.nodes?.length ?? 0) === 0) atRule.remove();
|
|
1979
|
+
});
|
|
1980
|
+
const nextResult = root.toResult(result.opts);
|
|
1981
|
+
nextResult.messages.push(...result.messages);
|
|
1982
|
+
nextResult.messages.push(...calcMessages);
|
|
1983
|
+
return nextResult;
|
|
1515
1984
|
}
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
resolvedColor.alpha = alphaColor.alpha;
|
|
1521
|
-
return (0, _csstools_css_color_parser.serializeRGB)(resolvedColor).toString();
|
|
1985
|
+
//#endregion
|
|
1986
|
+
//#region src/branches/uni-app-x-css-uvue/index.ts
|
|
1987
|
+
function postprocessUniAppXUvueCss(result, options) {
|
|
1988
|
+
return applyUniAppXUvueCompatibility(applyUniAppXBaseCompatibility(result, options), options);
|
|
1522
1989
|
}
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1990
|
+
//#endregion
|
|
1991
|
+
//#region src/branches/uni-app-x-css-webview/index.ts
|
|
1992
|
+
function postprocessUniAppXWebviewCss(result, options) {
|
|
1993
|
+
return applyUniAppXBaseCompatibility(result, options);
|
|
1526
1994
|
}
|
|
1527
1995
|
//#endregion
|
|
1528
|
-
//#region src/
|
|
1529
|
-
function
|
|
1530
|
-
|
|
1531
|
-
return normalizeColorFunctionWithDynamicAlpha(colorSource, CUSTOM_PROPERTY_RE.test(alpha) ? `var(${alpha})` : alpha, customPropertyValues);
|
|
1996
|
+
//#region src/branches/web/index.ts
|
|
1997
|
+
function postprocessWebCss(result, _options) {
|
|
1998
|
+
return result;
|
|
1532
1999
|
}
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
2000
|
+
//#endregion
|
|
2001
|
+
//#region src/style-targets/style.ts
|
|
2002
|
+
function postprocessGenericCss(result, _options) {
|
|
2003
|
+
return result;
|
|
2004
|
+
}
|
|
2005
|
+
function createPostcssStyleTargetProfile(target) {
|
|
2006
|
+
switch (target) {
|
|
2007
|
+
case "mini-program": return {
|
|
2008
|
+
target,
|
|
2009
|
+
postprocess: postprocessMiniProgramCss
|
|
2010
|
+
};
|
|
2011
|
+
case "uni-app-x-css-uvue": return {
|
|
2012
|
+
target,
|
|
2013
|
+
postprocess: postprocessUniAppXUvueCss
|
|
2014
|
+
};
|
|
2015
|
+
case "uni-app-x-css-webview": return {
|
|
2016
|
+
target,
|
|
2017
|
+
postprocess: postprocessUniAppXWebviewCss
|
|
2018
|
+
};
|
|
2019
|
+
case "web": return {
|
|
2020
|
+
target,
|
|
2021
|
+
postprocess: postprocessWebCss
|
|
2022
|
+
};
|
|
2023
|
+
default: return {
|
|
2024
|
+
target,
|
|
2025
|
+
postprocess: postprocessGenericCss
|
|
1557
2026
|
};
|
|
1558
2027
|
}
|
|
1559
|
-
const alpha = parseAlphaValue(alphaSource);
|
|
1560
|
-
if (alpha === void 0) return;
|
|
1561
|
-
const normalized = normalizeColorFunctionName(colorSource, alpha, customPropertyValues);
|
|
1562
|
-
if (normalized) return {
|
|
1563
|
-
value: normalized,
|
|
1564
|
-
deferred: false
|
|
1565
|
-
};
|
|
1566
|
-
return {
|
|
1567
|
-
value: colorSource,
|
|
1568
|
-
deferred: false
|
|
1569
|
-
};
|
|
1570
2028
|
}
|
|
1571
2029
|
//#endregion
|
|
1572
|
-
//#region src/
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
const variable = nodes.length === 1 ? nodes[0] : void 0;
|
|
1577
|
-
const property = variable?.type === "function" ? variable.nodes.find((node) => node.type === "word" && node.value.startsWith("--")) : void 0;
|
|
1578
|
-
if (variable?.type !== "function" || variable.value.toLowerCase() !== "var" || property?.type !== "word" || isTailwindcssV4ThemeVariable(property.value) || !variable.nodes.some((node) => node.type === "div" && node.value === ",")) return;
|
|
1579
|
-
return variable;
|
|
2030
|
+
//#region src/frameworks/shared.ts
|
|
2031
|
+
function isWebLikeStylePlatform(platform) {
|
|
2032
|
+
const normalized = platform?.trim().toLowerCase();
|
|
2033
|
+
return normalized === "h5" || normalized === "web" || normalized?.startsWith("web-") === true || normalized === "app" || normalized === "app-plus" || normalized?.startsWith("app-") === true;
|
|
1580
2034
|
}
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
*/
|
|
1584
|
-
function protectDynamicVarFallbacks(css) {
|
|
1585
|
-
if (!css.includes("var(") || !css.includes(",")) return {
|
|
1586
|
-
css,
|
|
1587
|
-
restore: (value) => value
|
|
1588
|
-
};
|
|
1589
|
-
const replacements = /* @__PURE__ */ new Map();
|
|
1590
|
-
let root;
|
|
1591
|
-
try {
|
|
1592
|
-
root = postcss.default.parse(css);
|
|
1593
|
-
} catch {
|
|
1594
|
-
return {
|
|
1595
|
-
css,
|
|
1596
|
-
restore: (value) => value
|
|
1597
|
-
};
|
|
1598
|
-
}
|
|
1599
|
-
root.walkDecls((decl) => {
|
|
1600
|
-
if (!getStandaloneDynamicVarWithFallback(decl.value)) return;
|
|
1601
|
-
const placeholder = `${DYNAMIC_VAR_FALLBACK_PLACEHOLDER_PREFIX}${replacements.size}__`;
|
|
1602
|
-
replacements.set(placeholder, decl.value);
|
|
1603
|
-
decl.value = placeholder;
|
|
1604
|
-
});
|
|
1605
|
-
if (replacements.size === 0) return {
|
|
1606
|
-
css,
|
|
1607
|
-
restore: (value) => value
|
|
1608
|
-
};
|
|
1609
|
-
return {
|
|
1610
|
-
css: root.toString(),
|
|
1611
|
-
restore(value) {
|
|
1612
|
-
let restored = value;
|
|
1613
|
-
for (const [placeholder, replacement] of replacements) restored = restored.split(placeholder).join(replacement);
|
|
1614
|
-
return restored;
|
|
1615
|
-
}
|
|
1616
|
-
};
|
|
2035
|
+
function resolveWebPlatformOrTarget(options, fallbackTarget) {
|
|
2036
|
+
return isWebLikeStylePlatform(options.platform) ? "web" : fallbackTarget;
|
|
1617
2037
|
}
|
|
1618
|
-
function
|
|
1619
|
-
if (!hasUnsupportedModernColorFunction(value)) return {
|
|
1620
|
-
value,
|
|
1621
|
-
changed: false,
|
|
1622
|
-
hasUnsupported: false
|
|
1623
|
-
};
|
|
1624
|
-
const parsed = (0, postcss_value_parser.default)(value);
|
|
1625
|
-
let changed = false;
|
|
1626
|
-
parsed.walk((node) => {
|
|
1627
|
-
if (node.type !== "function") return;
|
|
1628
|
-
const name = node.value.toLowerCase();
|
|
1629
|
-
const source = postcss_value_parser.default.stringify(node);
|
|
1630
|
-
let normalized;
|
|
1631
|
-
if (MODERN_COLOR_FUNCTION_NAMES.has(name) || name === "color" && isDisplayP3ColorFunction(source) || isModernColorSyntaxFunction(source)) normalized = normalizeStandaloneColorFunction(source);
|
|
1632
|
-
else if (name === "color-mix") normalized = tryResolveColorMix(node, customPropertyValues)?.value;
|
|
1633
|
-
if (!normalized) return;
|
|
1634
|
-
const mutableNode = node;
|
|
1635
|
-
mutableNode.type = "word";
|
|
1636
|
-
mutableNode.value = normalized;
|
|
1637
|
-
delete mutableNode.nodes;
|
|
1638
|
-
changed = true;
|
|
1639
|
-
});
|
|
1640
|
-
const nextValue = changed ? parsed.toString() : value;
|
|
2038
|
+
function createStaticTargetFrameworkStrategy(framework, fallbackTarget) {
|
|
1641
2039
|
return {
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
hasUnsupported: hasUnsupportedModernColorFunction(nextValue)
|
|
2040
|
+
framework,
|
|
2041
|
+
resolveStyleTarget: (options) => resolveWebPlatformOrTarget(options, fallbackTarget)
|
|
1645
2042
|
};
|
|
1646
2043
|
}
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
2044
|
+
//#endregion
|
|
2045
|
+
//#region src/frameworks/generic/index.ts
|
|
2046
|
+
const genericPostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("generic", "generic");
|
|
2047
|
+
//#endregion
|
|
2048
|
+
//#region src/frameworks/kbone/index.ts
|
|
2049
|
+
const kbonePostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("kbone", "generic");
|
|
2050
|
+
//#endregion
|
|
2051
|
+
//#region src/frameworks/mpx/index.ts
|
|
2052
|
+
const mpxPostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("mpx", "mini-program");
|
|
2053
|
+
//#endregion
|
|
2054
|
+
//#region src/frameworks/native/index.ts
|
|
2055
|
+
const nativePostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("native", "mini-program");
|
|
2056
|
+
//#endregion
|
|
2057
|
+
//#region src/frameworks/remax/index.ts
|
|
2058
|
+
const remaxPostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("remax", "mini-program");
|
|
2059
|
+
//#endregion
|
|
2060
|
+
//#region src/frameworks/taro/index.ts
|
|
2061
|
+
const taroPostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("taro", "mini-program");
|
|
2062
|
+
//#endregion
|
|
2063
|
+
//#region src/frameworks/uni-app/index.ts
|
|
2064
|
+
const uniAppPostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("uni-app", "mini-program");
|
|
2065
|
+
//#endregion
|
|
2066
|
+
//#region src/frameworks/uni-app-vite/index.ts
|
|
2067
|
+
const uniAppVitePostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("uni-app-vite", "mini-program");
|
|
2068
|
+
//#endregion
|
|
2069
|
+
//#region src/frameworks/uni-app-x/index.ts
|
|
2070
|
+
const uniAppXPostcssFrameworkStrategy = {
|
|
2071
|
+
framework: "uni-app-x",
|
|
2072
|
+
resolveStyleTarget: (options) => options.uniAppXCssTarget === "uvue" ? "uni-app-x-css-uvue" : "uni-app-x-css-webview"
|
|
2073
|
+
};
|
|
2074
|
+
//#endregion
|
|
2075
|
+
//#region src/frameworks/weapp-vite/index.ts
|
|
2076
|
+
const weappVitePostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("weapp-vite", "mini-program");
|
|
2077
|
+
//#endregion
|
|
2078
|
+
//#region src/frameworks/index.ts
|
|
2079
|
+
function isUniAppXFramework(options) {
|
|
2080
|
+
if (options.uniAppX === false) return false;
|
|
2081
|
+
return options.uniAppX === true || options.appType === "uni-app-x";
|
|
1655
2082
|
}
|
|
1656
|
-
function
|
|
1657
|
-
if (
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
const resolved = tryResolveColorMix(node, customPropertyValues);
|
|
1675
|
-
if (resolved) {
|
|
1676
|
-
if (resolved.deferred) {
|
|
1677
|
-
const placeholder = createPlaceholder(replacements.size);
|
|
1678
|
-
replacements.set(placeholder, resolved.value);
|
|
1679
|
-
const mutableNode = node;
|
|
1680
|
-
mutableNode.type = "word";
|
|
1681
|
-
mutableNode.value = placeholder;
|
|
1682
|
-
delete mutableNode.nodes;
|
|
1683
|
-
mutated = true;
|
|
1684
|
-
return;
|
|
1685
|
-
}
|
|
1686
|
-
const mutableNode = node;
|
|
1687
|
-
mutableNode.type = "word";
|
|
1688
|
-
mutableNode.value = resolved.value;
|
|
1689
|
-
delete mutableNode.nodes;
|
|
1690
|
-
mutated = true;
|
|
1691
|
-
}
|
|
1692
|
-
});
|
|
1693
|
-
if (mutated) {
|
|
1694
|
-
decl.value = parsed.toString();
|
|
1695
|
-
changed = true;
|
|
1696
|
-
}
|
|
1697
|
-
});
|
|
1698
|
-
if (replacements.size > 0) unwrapProtectedSupports(root);
|
|
2083
|
+
function resolvePostcssFrameworkStrategy(options) {
|
|
2084
|
+
if (isUniAppXFramework(options)) return uniAppXPostcssFrameworkStrategy;
|
|
2085
|
+
switch (options.appType) {
|
|
2086
|
+
case "kbone": return kbonePostcssFrameworkStrategy;
|
|
2087
|
+
case "mpx": return mpxPostcssFrameworkStrategy;
|
|
2088
|
+
case "native": return nativePostcssFrameworkStrategy;
|
|
2089
|
+
case "remax": return remaxPostcssFrameworkStrategy;
|
|
2090
|
+
case "taro": return taroPostcssFrameworkStrategy;
|
|
2091
|
+
case "uni-app": return uniAppPostcssFrameworkStrategy;
|
|
2092
|
+
case "uni-app-vite": return uniAppVitePostcssFrameworkStrategy;
|
|
2093
|
+
case "weapp-vite": return weappVitePostcssFrameworkStrategy;
|
|
2094
|
+
default: return genericPostcssFrameworkStrategy;
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
function resolvePostcssFrameworkProfile(options) {
|
|
2098
|
+
const strategy = resolvePostcssFrameworkStrategy(options);
|
|
2099
|
+
const target = strategy.resolveStyleTarget(options);
|
|
2100
|
+
const targetProfile = createPostcssStyleTargetProfile(target);
|
|
1699
2101
|
return {
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
return restored;
|
|
1705
|
-
}
|
|
2102
|
+
framework: strategy.framework,
|
|
2103
|
+
target,
|
|
2104
|
+
branch: target,
|
|
2105
|
+
postprocess: targetProfile.postprocess
|
|
1706
2106
|
};
|
|
1707
2107
|
}
|
|
2108
|
+
function resolvePostcssStyleTarget(options) {
|
|
2109
|
+
return resolvePostcssFrameworkProfile(options).target;
|
|
2110
|
+
}
|
|
2111
|
+
//#endregion
|
|
2112
|
+
//#region src/branches/style.ts
|
|
2113
|
+
function resolvePostcssStyleBranch(options) {
|
|
2114
|
+
return resolvePostcssStyleTarget(options);
|
|
2115
|
+
}
|
|
2116
|
+
function resolvePostcssStyleBranchProfile(options) {
|
|
2117
|
+
return resolvePostcssFrameworkProfile(options);
|
|
2118
|
+
}
|
|
1708
2119
|
//#endregion
|
|
1709
2120
|
//#region src/compat/mini-program-css/cascade-layers.ts
|
|
1710
2121
|
const LAYER_PATH_SEPARATOR = "";
|
|
@@ -2012,269 +2423,44 @@ function normalizeMiniProgramPrefixedDeclaration(decl) {
|
|
|
2012
2423
|
decl.value = value;
|
|
2013
2424
|
}
|
|
2014
2425
|
if (prop.startsWith("-webkit-") && !isPreservedWebkitDeclaration(decl)) {
|
|
2015
|
-
decl.remove();
|
|
2016
|
-
return;
|
|
2017
|
-
}
|
|
2018
|
-
if (hasUnsupportedWebkitKeywordValue(decl)) decl.remove();
|
|
2019
|
-
}
|
|
2020
|
-
function removeUnsupportedMiniProgramPrefixedAtRule(atRule) {
|
|
2021
|
-
if (atRule.name.toLowerCase() === "-webkit-keyframes") atRule.remove();
|
|
2022
|
-
}
|
|
2023
|
-
//#endregion
|
|
2024
|
-
//#region src/compat/mini-program-css/directives.ts
|
|
2025
|
-
const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
|
|
2026
|
-
const GENERATOR_PLACEHOLDER_COMMENT_RE = /^\s*(?:!\s*)?weapp-tailwindcss generator-placeholder\s*$/i;
|
|
2027
|
-
function hasTailwindcssV4Signal(css) {
|
|
2028
|
-
if (TAILWIND_V4_BANNER_RE.test(css)) return true;
|
|
2029
|
-
const root = postcss.default.parse(css);
|
|
2030
|
-
let hasProperty = false;
|
|
2031
|
-
root.walkAtRules("property", (atRule) => {
|
|
2032
|
-
if (atRule.params.trim().startsWith("--tw-")) {
|
|
2033
|
-
hasProperty = true;
|
|
2034
|
-
return false;
|
|
2035
|
-
}
|
|
2036
|
-
});
|
|
2037
|
-
return hasProperty;
|
|
2038
|
-
}
|
|
2039
|
-
function unwrapTailwindSourceMedia(root) {
|
|
2040
|
-
root.walkAtRules("media", (atRule) => {
|
|
2041
|
-
if (!atRule.params.startsWith("source(")) return;
|
|
2042
|
-
if (atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
|
|
2043
|
-
else atRule.remove();
|
|
2044
|
-
});
|
|
2045
|
-
}
|
|
2046
|
-
function removeTailwindGenerationDirectives(root) {
|
|
2047
|
-
root.walkComments((comment) => {
|
|
2048
|
-
if (GENERATOR_PLACEHOLDER_COMMENT_RE.test(comment.text)) comment.remove();
|
|
2049
|
-
});
|
|
2050
|
-
root.walkAtRules((atRule) => {
|
|
2051
|
-
if (atRule.name === "config" || atRule.name === "source" || atRule.name === "tailwind" || atRule.name === "reference" || atRule.name === "plugin") atRule.remove();
|
|
2052
|
-
});
|
|
2053
|
-
}
|
|
2054
|
-
//#endregion
|
|
2055
|
-
//#region src/compat/mini-program-css/selectors.ts
|
|
2056
|
-
const MINI_PROGRAM_THEME_SCOPE_SELECTOR = ":host,page,.tw-root,wx-root-portal-content";
|
|
2057
|
-
const MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR = "view,text,::after,::before";
|
|
2058
|
-
const MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS = /* @__PURE__ */ new Set([
|
|
2059
|
-
"view",
|
|
2060
|
-
"text",
|
|
2061
|
-
":before",
|
|
2062
|
-
":after",
|
|
2063
|
-
"::before",
|
|
2064
|
-
"::after"
|
|
2065
|
-
]);
|
|
2066
|
-
const MINI_PROGRAM_NATIVE_ELEMENT_SELECTORS = /* @__PURE__ */ new Set([
|
|
2067
|
-
...MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS,
|
|
2068
|
-
"button",
|
|
2069
|
-
"input",
|
|
2070
|
-
"textarea",
|
|
2071
|
-
"canvas",
|
|
2072
|
-
"video",
|
|
2073
|
-
"audio"
|
|
2074
|
-
]);
|
|
2075
|
-
const MINI_PROGRAM_PREFLIGHT_SELECTORS = /* @__PURE__ */ new Set(["*", ...MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS]);
|
|
2076
|
-
const MINI_PROGRAM_THEME_SCOPE_SELECTORS = /* @__PURE__ */ new Set([
|
|
2077
|
-
":host",
|
|
2078
|
-
":root",
|
|
2079
|
-
"page",
|
|
2080
|
-
".tw-root",
|
|
2081
|
-
"wx-root-portal-content"
|
|
2082
|
-
]);
|
|
2083
|
-
function normalizeMiniProgramThemeScopeSelector(root) {
|
|
2084
|
-
if (root === false) return ":host";
|
|
2085
|
-
if (root === void 0) return MINI_PROGRAM_THEME_SCOPE_SELECTOR;
|
|
2086
|
-
const selectors = Array.isArray(root) ? root.filter(Boolean) : [root];
|
|
2087
|
-
return [.../* @__PURE__ */ new Set([":host", ...selectors])].join(",");
|
|
2088
|
-
}
|
|
2089
|
-
const SPECIFICITY_PLACEHOLDER_SUFFIXES = [":not(#n)", ":not(#\\#)"];
|
|
2090
|
-
const ROOT_SPECIFICITY_PLACEHOLDER_SUFFIXES = [":not(.does-not-exist)"];
|
|
2091
|
-
const MINI_PROGRAM_UNSUPPORTED_BROWSER_SELECTORS = /* @__PURE__ */ new Set([
|
|
2092
|
-
":-moz-focusring",
|
|
2093
|
-
":-moz-ui-invalid",
|
|
2094
|
-
"::-webkit-calendar-picker-indicator",
|
|
2095
|
-
"::-webkit-date-and-time-value",
|
|
2096
|
-
"::-webkit-datetime-edit",
|
|
2097
|
-
"::-webkit-datetime-edit-day-field",
|
|
2098
|
-
"::-webkit-datetime-edit-fields-wrapper",
|
|
2099
|
-
"::-webkit-datetime-edit-hour-field",
|
|
2100
|
-
"::-webkit-datetime-edit-meridiem-field",
|
|
2101
|
-
"::-webkit-datetime-edit-millisecond-field",
|
|
2102
|
-
"::-webkit-datetime-edit-minute-field",
|
|
2103
|
-
"::-webkit-datetime-edit-month-field",
|
|
2104
|
-
"::-webkit-datetime-edit-second-field",
|
|
2105
|
-
"::-webkit-datetime-edit-year-field",
|
|
2106
|
-
"::-webkit-inner-spin-button",
|
|
2107
|
-
"::-webkit-input-placeholder",
|
|
2108
|
-
"::-webkit-outer-spin-button",
|
|
2109
|
-
"::-webkit-search-decoration",
|
|
2110
|
-
"::placeholder",
|
|
2111
|
-
"[hidden]:where(:not([hidden='until-found']))"
|
|
2112
|
-
]);
|
|
2113
|
-
const MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS = /* @__PURE__ */ new Set([
|
|
2114
|
-
"a",
|
|
2115
|
-
"abbr:where([title])",
|
|
2116
|
-
"audio",
|
|
2117
|
-
"b",
|
|
2118
|
-
"button",
|
|
2119
|
-
"canvas",
|
|
2120
|
-
"code",
|
|
2121
|
-
"embed",
|
|
2122
|
-
"h1",
|
|
2123
|
-
"h2",
|
|
2124
|
-
"h3",
|
|
2125
|
-
"h4",
|
|
2126
|
-
"h5",
|
|
2127
|
-
"h6",
|
|
2128
|
-
"hr",
|
|
2129
|
-
"html",
|
|
2130
|
-
"iframe",
|
|
2131
|
-
"img",
|
|
2132
|
-
"input",
|
|
2133
|
-
"input:where([type='button'],[type='reset'],[type='submit'])",
|
|
2134
|
-
"kbd",
|
|
2135
|
-
"menu",
|
|
2136
|
-
"object",
|
|
2137
|
-
"ol",
|
|
2138
|
-
"optgroup",
|
|
2139
|
-
"pre",
|
|
2140
|
-
"progress",
|
|
2141
|
-
"samp",
|
|
2142
|
-
"select",
|
|
2143
|
-
"select[multiple]optgroup",
|
|
2144
|
-
"select[multiple]optgroupoption",
|
|
2145
|
-
"select[size]optgroup",
|
|
2146
|
-
"select[size]optgroupoption",
|
|
2147
|
-
"small",
|
|
2148
|
-
"strong",
|
|
2149
|
-
"sub",
|
|
2150
|
-
"summary",
|
|
2151
|
-
"sup",
|
|
2152
|
-
"svg",
|
|
2153
|
-
"table",
|
|
2154
|
-
"textarea",
|
|
2155
|
-
"ul",
|
|
2156
|
-
"video"
|
|
2157
|
-
]);
|
|
2158
|
-
const MINI_PROGRAM_UNSUPPORTED_BROWSER_PREFLIGHT_SELECTOR_PARTS = /* @__PURE__ */ new Set([...MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS, "::file-selector-button"]);
|
|
2159
|
-
function normalizeSelector$1(selector) {
|
|
2160
|
-
return selector.trim().replace(/\s+/g, "");
|
|
2161
|
-
}
|
|
2162
|
-
function normalizePseudoElementSelector(selector) {
|
|
2163
|
-
return normalizeSelector$1(selector).replace(/^:(before|after)$/, "::$1");
|
|
2164
|
-
}
|
|
2165
|
-
function getRuleSelectors(rule) {
|
|
2166
|
-
return rule.selector.split(",").map(normalizePseudoElementSelector).filter(Boolean);
|
|
2167
|
-
}
|
|
2168
|
-
function getSortedRuleSelectorKey(rule) {
|
|
2169
|
-
return getRuleSelectors(rule).sort().join(",");
|
|
2170
|
-
}
|
|
2171
|
-
function isUnsupportedBrowserSelector(selector) {
|
|
2172
|
-
const normalized = normalizeSelector$1(selector);
|
|
2173
|
-
return MINI_PROGRAM_UNSUPPORTED_BROWSER_SELECTORS.has(normalized) || MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS.has(normalized) && !MINI_PROGRAM_NATIVE_ELEMENT_SELECTORS.has(normalized);
|
|
2174
|
-
}
|
|
2175
|
-
function isUnsupportedBrowserPreflightSelector(selector) {
|
|
2176
|
-
const normalizedParts = selector.split(",").map(normalizeSelector$1).filter(Boolean);
|
|
2177
|
-
return normalizedParts.length > 1 && normalizedParts.every((part) => MINI_PROGRAM_UNSUPPORTED_BROWSER_PREFLIGHT_SELECTOR_PARTS.has(part));
|
|
2178
|
-
}
|
|
2179
|
-
function isMiniProgramNativeElementSelector(selector) {
|
|
2180
|
-
return MINI_PROGRAM_NATIVE_ELEMENT_SELECTORS.has(normalizePseudoElementSelector(selector));
|
|
2181
|
-
}
|
|
2182
|
-
function isMiniProgramPreflightSelector(selectors) {
|
|
2183
|
-
return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_PREFLIGHT_SELECTORS.has(selector)) && selectors.some((selector) => selector === "*" || selector === ":before" || selector === ":after" || selector === "::before" || selector === "::after");
|
|
2184
|
-
}
|
|
2185
|
-
function isMiniProgramThemeScopeSelector(selectors) {
|
|
2186
|
-
return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_THEME_SCOPE_SELECTORS.has(selector));
|
|
2187
|
-
}
|
|
2188
|
-
//#endregion
|
|
2189
|
-
//#region src/compat/mini-program-css/predicates.ts
|
|
2190
|
-
const PREFLIGHT_RESET_PROPS = /* @__PURE__ */ new Set([
|
|
2191
|
-
"box-sizing",
|
|
2192
|
-
"border",
|
|
2193
|
-
"border-width",
|
|
2194
|
-
"border-style",
|
|
2195
|
-
"border-color",
|
|
2196
|
-
"margin",
|
|
2197
|
-
"padding"
|
|
2198
|
-
]);
|
|
2199
|
-
const PSEUDO_CONTENT_SELECTOR_RE = /^(?:::before|::after|:before|:after)(?:,(?:::before|::after|:before|:after))*$/;
|
|
2200
|
-
const TW_CONTENT_VAR_RE = /var\(\s*--tw-content\b/;
|
|
2201
|
-
const BROWSER_PREFLIGHT_SINGLE_ELEMENT_DECLARATIONS = /* @__PURE__ */ new Map([["button", /* @__PURE__ */ new Set(["appearance:button", "-moz-appearance:button"])], ["textarea", /* @__PURE__ */ new Set(["resize:vertical"])]]);
|
|
2202
|
-
function hasTailwindPreflightDeclaration(rule) {
|
|
2203
|
-
let hasTailwindVar = false;
|
|
2204
|
-
let hasResetProp = false;
|
|
2205
|
-
rule.walkDecls((decl) => {
|
|
2206
|
-
if (decl.prop.startsWith("--tw-")) hasTailwindVar = true;
|
|
2207
|
-
if (PREFLIGHT_RESET_PROPS.has(decl.prop)) hasResetProp = true;
|
|
2208
|
-
});
|
|
2209
|
-
return hasTailwindVar || hasResetProp;
|
|
2210
|
-
}
|
|
2211
|
-
function hasTailwindVariableDeclaration(rule) {
|
|
2212
|
-
let hasTailwindVar = false;
|
|
2213
|
-
rule.walkDecls((decl) => {
|
|
2214
|
-
if (decl.prop.startsWith("--tw-")) hasTailwindVar = true;
|
|
2215
|
-
});
|
|
2216
|
-
return hasTailwindVar;
|
|
2217
|
-
}
|
|
2218
|
-
function isCustomPropertyRule(rule) {
|
|
2219
|
-
let hasDeclaration = false;
|
|
2220
|
-
let allCustomProperties = true;
|
|
2221
|
-
rule.each((node) => {
|
|
2222
|
-
if (node.type !== "decl") return;
|
|
2223
|
-
hasDeclaration = true;
|
|
2224
|
-
if (!node.prop.startsWith("--")) allCustomProperties = false;
|
|
2225
|
-
});
|
|
2226
|
-
return hasDeclaration && allCustomProperties;
|
|
2227
|
-
}
|
|
2228
|
-
function isEmptyTwContentDeclaration(decl) {
|
|
2229
|
-
return decl.prop === "--tw-content" && (decl.value === "\"\"" || decl.value === "''");
|
|
2230
|
-
}
|
|
2231
|
-
function isOnlyTwContentDeclarations$1(rule) {
|
|
2232
|
-
let hasDeclaration = false;
|
|
2233
|
-
let onlyContentVariable = true;
|
|
2234
|
-
rule.walkDecls((decl) => {
|
|
2235
|
-
hasDeclaration = true;
|
|
2236
|
-
if (decl.prop !== "--tw-content") onlyContentVariable = false;
|
|
2237
|
-
});
|
|
2238
|
-
return hasDeclaration && onlyContentVariable;
|
|
2426
|
+
decl.remove();
|
|
2427
|
+
return;
|
|
2428
|
+
}
|
|
2429
|
+
if (hasUnsupportedWebkitKeywordValue(decl)) decl.remove();
|
|
2239
2430
|
}
|
|
2240
|
-
function
|
|
2241
|
-
|
|
2242
|
-
return PSEUDO_CONTENT_SELECTOR_RE.test(selector) && isOnlyTwContentDeclarations$1(rule);
|
|
2431
|
+
function removeUnsupportedMiniProgramPrefixedAtRule(atRule) {
|
|
2432
|
+
if (atRule.name.toLowerCase() === "-webkit-keyframes") atRule.remove();
|
|
2243
2433
|
}
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2434
|
+
//#endregion
|
|
2435
|
+
//#region src/compat/mini-program-css/directives.ts
|
|
2436
|
+
const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
|
|
2437
|
+
const GENERATOR_PLACEHOLDER_COMMENT_RE = /^\s*(?:!\s*)?weapp-tailwindcss generator-placeholder\s*$/i;
|
|
2438
|
+
function hasTailwindcssV4Signal(css) {
|
|
2439
|
+
if (TAILWIND_V4_BANNER_RE.test(css)) return true;
|
|
2440
|
+
const root = postcss.default.parse(css);
|
|
2441
|
+
let hasProperty = false;
|
|
2442
|
+
root.walkAtRules("property", (atRule) => {
|
|
2443
|
+
if (atRule.params.trim().startsWith("--tw-")) {
|
|
2444
|
+
hasProperty = true;
|
|
2445
|
+
return false;
|
|
2446
|
+
}
|
|
2248
2447
|
});
|
|
2249
|
-
return
|
|
2250
|
-
}
|
|
2251
|
-
function isMiniProgramPreflightRule(node) {
|
|
2252
|
-
if (node.type !== "rule") return false;
|
|
2253
|
-
const selectors = getRuleSelectors(node);
|
|
2254
|
-
if (!isMiniProgramPreflightSelector(selectors)) return false;
|
|
2255
|
-
if (selectors.includes("*")) return hasTailwindPreflightDeclaration(node);
|
|
2256
|
-
if (hasTailwindVariableDeclaration(node)) return true;
|
|
2257
|
-
return selectors.some((selector) => selector === ":before" || selector === ":after" || selector === "::before" || selector === "::after") && selectors.some((selector) => selector === "view" || selector === "text") && hasTailwindPreflightDeclaration(node);
|
|
2448
|
+
return hasProperty;
|
|
2258
2449
|
}
|
|
2259
|
-
function
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
if (!declarations) return false;
|
|
2265
|
-
let hasDeclaration = false;
|
|
2266
|
-
let allBrowserPreflightDeclarations = true;
|
|
2267
|
-
node.each((child) => {
|
|
2268
|
-
if (child.type !== "decl") return;
|
|
2269
|
-
hasDeclaration = true;
|
|
2270
|
-
const key = `${child.prop.toLowerCase()}:${child.value.trim().toLowerCase()}`;
|
|
2271
|
-
if (!declarations.has(key)) allBrowserPreflightDeclarations = false;
|
|
2450
|
+
function unwrapTailwindSourceMedia(root) {
|
|
2451
|
+
root.walkAtRules("media", (atRule) => {
|
|
2452
|
+
if (!atRule.params.startsWith("source(")) return;
|
|
2453
|
+
if (atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
|
|
2454
|
+
else atRule.remove();
|
|
2272
2455
|
});
|
|
2273
|
-
return hasDeclaration && allBrowserPreflightDeclarations;
|
|
2274
2456
|
}
|
|
2275
|
-
function
|
|
2276
|
-
|
|
2277
|
-
|
|
2457
|
+
function removeTailwindGenerationDirectives(root) {
|
|
2458
|
+
root.walkComments((comment) => {
|
|
2459
|
+
if (GENERATOR_PLACEHOLDER_COMMENT_RE.test(comment.text)) comment.remove();
|
|
2460
|
+
});
|
|
2461
|
+
root.walkAtRules((atRule) => {
|
|
2462
|
+
if (atRule.name === "config" || atRule.name === "source" || atRule.name === "tailwind" || atRule.name === "reference" || atRule.name === "plugin") atRule.remove();
|
|
2463
|
+
});
|
|
2278
2464
|
}
|
|
2279
2465
|
//#endregion
|
|
2280
2466
|
//#region src/compat/mini-program-css/hoist.ts
|
|
@@ -2429,191 +2615,6 @@ function createPreflightResetRule(cssPreflight) {
|
|
|
2429
2615
|
return rule.nodes?.length ? rule : void 0;
|
|
2430
2616
|
}
|
|
2431
2617
|
//#endregion
|
|
2432
|
-
//#region src/compat/mini-program-css/color-gamut.ts
|
|
2433
|
-
const DISPLAY_P3_VALUE_RE = /color\(\s*display-p3\b/i;
|
|
2434
|
-
const COLOR_GAMUT_P3_RE = /\(\s*color-gamut\s*:\s*p3\s*\)/i;
|
|
2435
|
-
function isDisplayP3MediaRule(atRule) {
|
|
2436
|
-
return atRule.name === "media" && COLOR_GAMUT_P3_RE.test(atRule.params);
|
|
2437
|
-
}
|
|
2438
|
-
function isDisplayP3Declaration(decl) {
|
|
2439
|
-
return DISPLAY_P3_VALUE_RE.test(decl.value);
|
|
2440
|
-
}
|
|
2441
|
-
//#endregion
|
|
2442
|
-
//#region src/compat/mini-program-css/root-cleanups.ts
|
|
2443
|
-
function removeSpecificityPlaceholders(root) {
|
|
2444
|
-
root.walkRules((rule) => {
|
|
2445
|
-
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
2446
|
-
let changed = false;
|
|
2447
|
-
const selectors = rule.selectors.map((selector) => {
|
|
2448
|
-
let next = selector;
|
|
2449
|
-
for (const suffix of SPECIFICITY_PLACEHOLDER_SUFFIXES) if (next.includes(suffix)) next = next.split(suffix).join("");
|
|
2450
|
-
if (next !== selector) changed = true;
|
|
2451
|
-
return next;
|
|
2452
|
-
});
|
|
2453
|
-
if (changed) rule.selectors = selectors;
|
|
2454
|
-
});
|
|
2455
|
-
}
|
|
2456
|
-
function hasMiniProgramCssSpecificityPlaceholders(source) {
|
|
2457
|
-
return SPECIFICITY_PLACEHOLDER_SUFFIXES.some((suffix) => source.includes(suffix));
|
|
2458
|
-
}
|
|
2459
|
-
function stripMiniProgramCssSpecificityPlaceholders(source) {
|
|
2460
|
-
let output = source;
|
|
2461
|
-
for (const suffix of SPECIFICITY_PLACEHOLDER_SUFFIXES) if (output.includes(suffix)) output = output.split(suffix).join("");
|
|
2462
|
-
return output;
|
|
2463
|
-
}
|
|
2464
|
-
const removeSpecificityPlaceholdersFromSource = stripMiniProgramCssSpecificityPlaceholders;
|
|
2465
|
-
function removeRootSpecificityPlaceholders(root) {
|
|
2466
|
-
root.walkRules((rule) => {
|
|
2467
|
-
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
2468
|
-
let changed = false;
|
|
2469
|
-
const selectors = rule.selectors.map((selector) => {
|
|
2470
|
-
let next = selector;
|
|
2471
|
-
for (const scopeSelector of MINI_PROGRAM_THEME_SCOPE_SELECTORS) for (const suffix of ROOT_SPECIFICITY_PLACEHOLDER_SUFFIXES) {
|
|
2472
|
-
const target = `${scopeSelector}${suffix}`;
|
|
2473
|
-
if (next.includes(target)) next = next.split(target).join(scopeSelector);
|
|
2474
|
-
}
|
|
2475
|
-
if (next !== selector) changed = true;
|
|
2476
|
-
return next;
|
|
2477
|
-
});
|
|
2478
|
-
if (changed) rule.selectors = selectors;
|
|
2479
|
-
});
|
|
2480
|
-
}
|
|
2481
|
-
function isEffectivelyEmptyContainer(container) {
|
|
2482
|
-
return container.nodes !== void 0 && container.nodes.every((node) => node.type === "comment");
|
|
2483
|
-
}
|
|
2484
|
-
function removeEmptyAtRules(root) {
|
|
2485
|
-
let removed = 0;
|
|
2486
|
-
const visit = (container) => {
|
|
2487
|
-
for (const node of [...container.nodes ?? []]) {
|
|
2488
|
-
if (!("nodes" in node) || node.nodes === void 0) continue;
|
|
2489
|
-
visit(node);
|
|
2490
|
-
if (node.type === "atrule" && node.parent && isEffectivelyEmptyContainer(node)) {
|
|
2491
|
-
node.remove();
|
|
2492
|
-
removed++;
|
|
2493
|
-
}
|
|
2494
|
-
}
|
|
2495
|
-
};
|
|
2496
|
-
visit(root);
|
|
2497
|
-
return removed;
|
|
2498
|
-
}
|
|
2499
|
-
function removeEmptyBlockAtRules(root) {
|
|
2500
|
-
let removed = 0;
|
|
2501
|
-
root.walkAtRules((atRule) => {
|
|
2502
|
-
if (atRule.nodes?.length === 0) {
|
|
2503
|
-
atRule.remove();
|
|
2504
|
-
removed++;
|
|
2505
|
-
}
|
|
2506
|
-
});
|
|
2507
|
-
return removed;
|
|
2508
|
-
}
|
|
2509
|
-
function removeEmptyAtRuleAncestors(parent) {
|
|
2510
|
-
while (parent?.type === "atrule" && isEffectivelyEmptyContainer(parent)) {
|
|
2511
|
-
const nextParent = parent.parent;
|
|
2512
|
-
parent.remove();
|
|
2513
|
-
parent = nextParent?.type === "atrule" ? nextParent : void 0;
|
|
2514
|
-
}
|
|
2515
|
-
}
|
|
2516
|
-
function removeUnsupportedBrowserSelectors(root) {
|
|
2517
|
-
root.walkRules((rule) => {
|
|
2518
|
-
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
2519
|
-
if (isUnsupportedBrowserPreflightSelector(rule.selector)) {
|
|
2520
|
-
const parent = rule.parent;
|
|
2521
|
-
rule.remove();
|
|
2522
|
-
removeEmptyAtRuleAncestors(parent);
|
|
2523
|
-
return;
|
|
2524
|
-
}
|
|
2525
|
-
if (isBrowserElementPreflightRule(rule)) {
|
|
2526
|
-
const parent = rule.parent;
|
|
2527
|
-
rule.remove();
|
|
2528
|
-
removeEmptyAtRuleAncestors(parent);
|
|
2529
|
-
return;
|
|
2530
|
-
}
|
|
2531
|
-
const selectors = rule.selectors.filter((selector) => !isUnsupportedBrowserSelector(selector));
|
|
2532
|
-
if (selectors.length === rule.selectors.length) return;
|
|
2533
|
-
if (selectors.length === 0) {
|
|
2534
|
-
const parent = rule.parent;
|
|
2535
|
-
rule.remove();
|
|
2536
|
-
removeEmptyAtRuleAncestors(parent);
|
|
2537
|
-
return;
|
|
2538
|
-
}
|
|
2539
|
-
rule.selectors = selectors;
|
|
2540
|
-
});
|
|
2541
|
-
}
|
|
2542
|
-
function removeDeclarationAndEmptyRule$1(decl) {
|
|
2543
|
-
const parent = decl.parent;
|
|
2544
|
-
decl.remove();
|
|
2545
|
-
if (parent?.type === "rule" && parent.nodes.length === 0) {
|
|
2546
|
-
const ruleParent = parent.parent;
|
|
2547
|
-
parent.remove();
|
|
2548
|
-
removeEmptyAtRuleAncestors(ruleParent);
|
|
2549
|
-
}
|
|
2550
|
-
}
|
|
2551
|
-
function removeEmptyStandardPropertyFallbacks(root) {
|
|
2552
|
-
root.walkDecls((decl) => {
|
|
2553
|
-
if (!decl.prop.startsWith("--") && decl.value.trim().length === 0 && decl.parent?.nodes.some((node) => node !== decl && node.type === "decl" && node.prop === decl.prop && node.value.trim().length > 0)) removeDeclarationAndEmptyRule$1(decl);
|
|
2554
|
-
});
|
|
2555
|
-
}
|
|
2556
|
-
function removeDisplayP3Declarations(root) {
|
|
2557
|
-
root.walkAtRules((atRule) => {
|
|
2558
|
-
if (isDisplayP3MediaRule(atRule)) {
|
|
2559
|
-
const parent = atRule.parent;
|
|
2560
|
-
atRule.remove();
|
|
2561
|
-
removeEmptyAtRuleAncestors(parent);
|
|
2562
|
-
}
|
|
2563
|
-
});
|
|
2564
|
-
}
|
|
2565
|
-
const SIMPLE_MIN_WIDTH_MEDIA_RE = /^\(\s*min-width\s*:[^)]+\)$/i;
|
|
2566
|
-
const TAILWIND_GENERATED_TOKEN_COMMENT_RE = /^\s*tokens:\s*container\s*<=\s*<tailwind generated>\s*$/i;
|
|
2567
|
-
function isContainerMaxWidthOnlyRule(rule) {
|
|
2568
|
-
if (!rule.selectors || rule.selectors.length !== 1 || rule.selectors[0] !== ".container") return false;
|
|
2569
|
-
const declarations = rule.nodes?.filter((node) => node.type === "decl") ?? [];
|
|
2570
|
-
return declarations.length === 1 && declarations[0]?.prop === "max-width" && (rule.nodes ?? []).every((node) => node.type === "decl" || node.type === "comment");
|
|
2571
|
-
}
|
|
2572
|
-
function removeTailwindContainerMaxWidthMediaRules(root) {
|
|
2573
|
-
root.walkAtRules("media", (atRule) => {
|
|
2574
|
-
if (!SIMPLE_MIN_WIDTH_MEDIA_RE.test(atRule.params.trim())) return;
|
|
2575
|
-
atRule.walkRules((rule) => {
|
|
2576
|
-
if (!isContainerMaxWidthOnlyRule(rule)) return;
|
|
2577
|
-
const parent = rule.parent;
|
|
2578
|
-
rule.remove();
|
|
2579
|
-
removeEmptyAtRuleAncestors(parent);
|
|
2580
|
-
});
|
|
2581
|
-
});
|
|
2582
|
-
}
|
|
2583
|
-
function isContainerWidthOnlyRule(rule) {
|
|
2584
|
-
if (!rule.selectors || rule.selectors.length !== 1 || rule.selectors[0] !== ".container") return false;
|
|
2585
|
-
const declarations = rule.nodes?.filter((node) => node.type === "decl") ?? [];
|
|
2586
|
-
return declarations.length === 1 && declarations[0]?.prop === "width" && declarations[0].value.trim() === "100%" && (rule.nodes ?? []).every((node) => node.type === "decl" || node.type === "comment");
|
|
2587
|
-
}
|
|
2588
|
-
function isTailwindGeneratedContainerRule(rule) {
|
|
2589
|
-
const previous = rule.prev();
|
|
2590
|
-
return previous?.type === "comment" && TAILWIND_GENERATED_TOKEN_COMMENT_RE.test(previous.text);
|
|
2591
|
-
}
|
|
2592
|
-
function removeTailwindContainerWidthRules(root, options = {}) {
|
|
2593
|
-
root.walkRules((rule) => {
|
|
2594
|
-
if (!isContainerWidthOnlyRule(rule)) return;
|
|
2595
|
-
if (options.generatedOnly && !isTailwindGeneratedContainerRule(rule)) return;
|
|
2596
|
-
const parent = rule.parent;
|
|
2597
|
-
if (isTailwindGeneratedContainerRule(rule)) rule.prev()?.remove();
|
|
2598
|
-
rule.remove();
|
|
2599
|
-
removeEmptyAtRuleAncestors(parent);
|
|
2600
|
-
});
|
|
2601
|
-
}
|
|
2602
|
-
function removeUnsupportedModernColorDeclarations(root) {
|
|
2603
|
-
const customPropertyValues = /* @__PURE__ */ new Map();
|
|
2604
|
-
root.walkDecls((decl) => {
|
|
2605
|
-
if (decl.prop.startsWith("--")) customPropertyValues.set(decl.prop, decl.value.trim());
|
|
2606
|
-
});
|
|
2607
|
-
root.walkDecls((decl) => {
|
|
2608
|
-
const normalized = normalizeModernColorValue(decl.value, customPropertyValues);
|
|
2609
|
-
if (normalized.changed) {
|
|
2610
|
-
decl.value = normalized.value;
|
|
2611
|
-
if (decl.prop.startsWith("--")) customPropertyValues.set(decl.prop, decl.value.trim());
|
|
2612
|
-
}
|
|
2613
|
-
if (normalized.hasUnsupported) removeDeclarationAndEmptyRule$1(decl);
|
|
2614
|
-
});
|
|
2615
|
-
}
|
|
2616
|
-
//#endregion
|
|
2617
2618
|
//#region src/compat/mini-program-css/theme.ts
|
|
2618
2619
|
function collectThemeVariableRule(root, options = {}) {
|
|
2619
2620
|
const themeRules = [];
|
|
@@ -2650,7 +2651,7 @@ function finalizeMiniProgramCssRoot(root, options = {}) {
|
|
|
2650
2651
|
removeRootSpecificityPlaceholders(root);
|
|
2651
2652
|
removeUnsupportedBrowserSelectors(root);
|
|
2652
2653
|
removeDisplayP3Declarations(root);
|
|
2653
|
-
|
|
2654
|
+
removeEmptyStandardDeclarations(root);
|
|
2654
2655
|
removeTailwindContainerMaxWidthMediaRules(root);
|
|
2655
2656
|
removeTailwindContainerWidthRules(root, { generatedOnly: true });
|
|
2656
2657
|
removeUnsupportedModernColorDeclarations(root);
|
|
@@ -3047,8 +3048,14 @@ function isWebCssCompatEnabled(options) {
|
|
|
3047
3048
|
}
|
|
3048
3049
|
function collectCustomPropertyValues(root) {
|
|
3049
3050
|
const values = /* @__PURE__ */ new Map();
|
|
3050
|
-
root.
|
|
3051
|
-
if (
|
|
3051
|
+
root.walkRules((rule) => {
|
|
3052
|
+
if (!rule.selectors.some((selector) => selector.trim() === ":root" || selector.trim() === ":host")) return;
|
|
3053
|
+
rule.each((node) => {
|
|
3054
|
+
if (node.type === "decl" && node.prop.startsWith("--") && !node.prop.startsWith("--tw-")) {
|
|
3055
|
+
const decl = node;
|
|
3056
|
+
values.set(decl.prop, decl.value.trim());
|
|
3057
|
+
}
|
|
3058
|
+
});
|
|
3052
3059
|
});
|
|
3053
3060
|
return values;
|
|
3054
3061
|
}
|
|
@@ -6507,8 +6514,27 @@ function shouldUseDefaultAutoprefixer(options, userPlugins) {
|
|
|
6507
6514
|
if (options.autoprefixer === true || typeof options.autoprefixer === "object") return true;
|
|
6508
6515
|
return options.majorVersion === 4;
|
|
6509
6516
|
}
|
|
6517
|
+
function isUniAppXNativeAuthorStyle(options) {
|
|
6518
|
+
const source = options.uniAppXCssSource;
|
|
6519
|
+
return options.uniAppX === true && options.uniAppXCssTarget === "uvue" && (source === "author" || source === "author-apply");
|
|
6520
|
+
}
|
|
6521
|
+
function appendUniAppXNativeAuthorDeclarationNodes(preparedNodes, options) {
|
|
6522
|
+
if (options.uniAppXCssSource !== "author-apply") return;
|
|
6523
|
+
const declarationPlugins = [
|
|
6524
|
+
["normal:units-to-px", getUnitsToPxPlugin(options)],
|
|
6525
|
+
["normal:px-transform", getPxTransformPlugin(options)],
|
|
6526
|
+
["normal:rem-transform", getRemTransformPlugin(options)],
|
|
6527
|
+
["normal:unit-conversion", getUnitConversionPlugin(options)],
|
|
6528
|
+
["normal:calc", getCalcPlugin(options)]
|
|
6529
|
+
];
|
|
6530
|
+
for (const [id, plugin] of declarationPlugins) if (plugin) preparedNodes.push(createPreparedNode(id, "normal", () => plugin));
|
|
6531
|
+
}
|
|
6510
6532
|
function createPreparedNodes(options, signal) {
|
|
6511
6533
|
const preparedNodes = [];
|
|
6534
|
+
if (isUniAppXNativeAuthorStyle(options)) {
|
|
6535
|
+
appendUniAppXNativeAuthorDeclarationNodes(preparedNodes, options);
|
|
6536
|
+
return preparedNodes;
|
|
6537
|
+
}
|
|
6512
6538
|
const userPlugins = normalizeUserPlugins(options.postcssOptions?.plugins);
|
|
6513
6539
|
const presetEnvOptions = {
|
|
6514
6540
|
...options.cssPresetEnv,
|