@weapp-tailwindcss/postcss 3.3.0 → 3.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import postcss from 'postcss';
|
|
2
2
|
export declare const TAILWIND_V4_BANNER_RE: RegExp;
|
|
3
|
+
/**
|
|
4
|
+
* 严格移除文件末尾残留的 Tailwind source media 开始标记。
|
|
5
|
+
* 仅处理可确认属于 Tailwind 的尾部残片,其它非法 CSS 保持原样。
|
|
6
|
+
*/
|
|
7
|
+
export declare function repairTrailingUnclosedTailwindSourceMedia(css: string): string;
|
|
3
8
|
export declare function hasTailwindcssV4Signal(css: string): boolean;
|
|
4
9
|
export declare function unwrapTailwindSourceMedia(root: postcss.Root): void;
|
|
5
10
|
export declare function removeTailwindGenerationDirectives(root: postcss.Root): void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { removeUnsupportedAtSupports, removeUnsupportedCascadeLayers, removeUnsupportedMiniProgramAtRules, unwrapUnsupportedCascadeLayers, } from './at-rules.js';
|
|
2
2
|
export { consumeCascadeLayers } from './cascade-layers.js';
|
|
3
|
+
export { repairTrailingUnclosedTailwindSourceMedia } from './directives.js';
|
|
3
4
|
export { finalizeMiniProgramCss, type FinalizeMiniProgramCssOptions, finalizeMiniProgramCssRoot, hoistTailwindPreflightBase, } from './finalize.js';
|
|
4
5
|
export { normalizeMiniProgramGeneratedCssForPostcss, pruneMiniProgramGeneratedCss, type PruneMiniProgramGeneratedCssOptions, } from './prune-generated.js';
|
|
5
|
-
export { hasMiniProgramCssSpecificityPlaceholders, removeEmptyAtRules, stripMiniProgramCssSpecificityPlaceholders, } from './root-cleanups.js';
|
|
6
|
+
export { hasMiniProgramCssSpecificityPlaceholders, removeEmptyAtRules, removeEmptyRules, stripMiniProgramCssSpecificityPlaceholders, } from './root-cleanups.js';
|
|
@@ -6,6 +6,7 @@ export declare const removeSpecificityPlaceholdersFromSource: typeof stripMiniPr
|
|
|
6
6
|
export declare function removeRootSpecificityPlaceholders(root: postcss.Root): void;
|
|
7
7
|
export declare function removeEmptyAtRules(root: postcss.Root): number;
|
|
8
8
|
export declare function removeEmptyBlockAtRules(root: postcss.Root): number;
|
|
9
|
+
export declare function removeEmptyRules(root: postcss.Root): number;
|
|
9
10
|
export declare function removeUnsupportedBrowserSelectors(root: postcss.Root): void;
|
|
10
11
|
export declare function removeEmptyStandardDeclarations(root: postcss.Root): void;
|
|
11
12
|
export declare function removeDisplayP3Declarations(root: postcss.Root): void;
|
package/dist/index.cjs
CHANGED
|
@@ -1049,6 +1049,9 @@ function removeRootSpecificityPlaceholders(root) {
|
|
|
1049
1049
|
function isEffectivelyEmptyContainer(container) {
|
|
1050
1050
|
return container.nodes !== void 0 && container.nodes.every((node) => node.type === "comment");
|
|
1051
1051
|
}
|
|
1052
|
+
function isKeyframeStepRule(rule) {
|
|
1053
|
+
return rule.parent?.type === "atrule" && rule.parent.name.toLowerCase().endsWith("keyframes");
|
|
1054
|
+
}
|
|
1052
1055
|
function removeEmptyAtRules(root) {
|
|
1053
1056
|
let removed = 0;
|
|
1054
1057
|
const visit = (container) => {
|
|
@@ -1081,6 +1084,17 @@ function removeEmptyAtRuleAncestors(parent) {
|
|
|
1081
1084
|
parent = nextParent?.type === "atrule" ? nextParent : void 0;
|
|
1082
1085
|
}
|
|
1083
1086
|
}
|
|
1087
|
+
function removeEmptyRules(root) {
|
|
1088
|
+
let removed = 0;
|
|
1089
|
+
root.walkRules((rule) => {
|
|
1090
|
+
if (isKeyframeStepRule(rule) || !rule.parent || !isEffectivelyEmptyContainer(rule)) return;
|
|
1091
|
+
const parent = rule.parent;
|
|
1092
|
+
rule.remove();
|
|
1093
|
+
removeEmptyAtRuleAncestors(parent);
|
|
1094
|
+
removed++;
|
|
1095
|
+
});
|
|
1096
|
+
return removed;
|
|
1097
|
+
}
|
|
1084
1098
|
function removeUnsupportedBrowserSelectors(root) {
|
|
1085
1099
|
root.walkRules((rule) => {
|
|
1086
1100
|
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
@@ -2484,6 +2498,120 @@ function unwrapUnsupportedCascadeLayers(css) {
|
|
|
2484
2498
|
}
|
|
2485
2499
|
}
|
|
2486
2500
|
//#endregion
|
|
2501
|
+
//#region src/compat/mini-program-css/directives.ts
|
|
2502
|
+
const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
|
|
2503
|
+
const GENERATOR_PLACEHOLDER_COMMENT_RE = /^\s*(?:!\s*)?weapp-tailwindcss generator-placeholder\s*$/i;
|
|
2504
|
+
function isCssWhitespace(code) {
|
|
2505
|
+
return code === 9 || code === 10 || code === 12 || code === 13 || code === 32;
|
|
2506
|
+
}
|
|
2507
|
+
function skipCssWhitespace(css, start) {
|
|
2508
|
+
let index = start;
|
|
2509
|
+
while (index < css.length && isCssWhitespace(css.charCodeAt(index))) index++;
|
|
2510
|
+
return index;
|
|
2511
|
+
}
|
|
2512
|
+
function findClosingParenthesis(css, openingIndex) {
|
|
2513
|
+
let depth = 0;
|
|
2514
|
+
let quote = 0;
|
|
2515
|
+
for (let index = openingIndex; index < css.length; index++) {
|
|
2516
|
+
const code = css.charCodeAt(index);
|
|
2517
|
+
if (quote !== 0) {
|
|
2518
|
+
if (code === 92) index++;
|
|
2519
|
+
else if (code === quote) quote = 0;
|
|
2520
|
+
continue;
|
|
2521
|
+
}
|
|
2522
|
+
if (code === 34 || code === 39) {
|
|
2523
|
+
quote = code;
|
|
2524
|
+
continue;
|
|
2525
|
+
}
|
|
2526
|
+
if (code === 92) {
|
|
2527
|
+
index++;
|
|
2528
|
+
continue;
|
|
2529
|
+
}
|
|
2530
|
+
if (code === 47 && css.charCodeAt(index + 1) === 42) {
|
|
2531
|
+
const commentEnd = css.indexOf("*/", index + 2);
|
|
2532
|
+
if (commentEnd < 0) return -1;
|
|
2533
|
+
index = commentEnd + 1;
|
|
2534
|
+
continue;
|
|
2535
|
+
}
|
|
2536
|
+
if (code === 40) {
|
|
2537
|
+
depth++;
|
|
2538
|
+
continue;
|
|
2539
|
+
}
|
|
2540
|
+
if (code === 41) {
|
|
2541
|
+
depth--;
|
|
2542
|
+
if (depth === 0) return index;
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
return -1;
|
|
2546
|
+
}
|
|
2547
|
+
function isCssCodePosition(css, position) {
|
|
2548
|
+
let quote = 0;
|
|
2549
|
+
for (let index = 0; index < position; index++) {
|
|
2550
|
+
const code = css.charCodeAt(index);
|
|
2551
|
+
if (quote !== 0) {
|
|
2552
|
+
if (code === 92) index++;
|
|
2553
|
+
else if (code === quote) quote = 0;
|
|
2554
|
+
continue;
|
|
2555
|
+
}
|
|
2556
|
+
if (code === 34 || code === 39) {
|
|
2557
|
+
quote = code;
|
|
2558
|
+
continue;
|
|
2559
|
+
}
|
|
2560
|
+
if (code === 47 && css.charCodeAt(index + 1) === 42) {
|
|
2561
|
+
const commentEnd = css.indexOf("*/", index + 2);
|
|
2562
|
+
if (commentEnd < 0 || commentEnd >= position) return false;
|
|
2563
|
+
index = commentEnd + 1;
|
|
2564
|
+
}
|
|
2565
|
+
}
|
|
2566
|
+
return quote === 0;
|
|
2567
|
+
}
|
|
2568
|
+
/**
|
|
2569
|
+
* 严格移除文件末尾残留的 Tailwind source media 开始标记。
|
|
2570
|
+
* 仅处理可确认属于 Tailwind 的尾部残片,其它非法 CSS 保持原样。
|
|
2571
|
+
*/
|
|
2572
|
+
function repairTrailingUnclosedTailwindSourceMedia(css) {
|
|
2573
|
+
const sourceMediaPattern = /(?:^|\r?\n)[\t\f ]*@media\s+source\(/g;
|
|
2574
|
+
for (let match = sourceMediaPattern.exec(css); match !== null; match = sourceMediaPattern.exec(css)) {
|
|
2575
|
+
const prefixLength = match[0].startsWith("\n") ? 1 : match[0].startsWith("\r\n") ? 2 : 0;
|
|
2576
|
+
const start = match.index + prefixLength;
|
|
2577
|
+
if (!isCssCodePosition(css, start)) continue;
|
|
2578
|
+
const closingIndex = findClosingParenthesis(css, start + match[0].length - prefixLength - 1);
|
|
2579
|
+
if (closingIndex < 0) continue;
|
|
2580
|
+
const blockStart = skipCssWhitespace(css, closingIndex + 1);
|
|
2581
|
+
if (css.charCodeAt(blockStart) !== 123) continue;
|
|
2582
|
+
if (skipCssWhitespace(css, blockStart + 1) !== css.length) continue;
|
|
2583
|
+
return css.slice(0, match.index);
|
|
2584
|
+
}
|
|
2585
|
+
return css;
|
|
2586
|
+
}
|
|
2587
|
+
function hasTailwindcssV4Signal(css) {
|
|
2588
|
+
if (TAILWIND_V4_BANNER_RE.test(css)) return true;
|
|
2589
|
+
const root = postcss.default.parse(css);
|
|
2590
|
+
let hasProperty = false;
|
|
2591
|
+
root.walkAtRules("property", (atRule) => {
|
|
2592
|
+
if (atRule.params.trim().startsWith("--tw-")) {
|
|
2593
|
+
hasProperty = true;
|
|
2594
|
+
return false;
|
|
2595
|
+
}
|
|
2596
|
+
});
|
|
2597
|
+
return hasProperty;
|
|
2598
|
+
}
|
|
2599
|
+
function unwrapTailwindSourceMedia(root) {
|
|
2600
|
+
root.walkAtRules("media", (atRule) => {
|
|
2601
|
+
if (!atRule.params.startsWith("source(")) return;
|
|
2602
|
+
if (atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
|
|
2603
|
+
else atRule.remove();
|
|
2604
|
+
});
|
|
2605
|
+
}
|
|
2606
|
+
function removeTailwindGenerationDirectives(root) {
|
|
2607
|
+
root.walkComments((comment) => {
|
|
2608
|
+
if (GENERATOR_PLACEHOLDER_COMMENT_RE.test(comment.text)) comment.remove();
|
|
2609
|
+
});
|
|
2610
|
+
root.walkAtRules((atRule) => {
|
|
2611
|
+
if (atRule.name === "config" || atRule.name === "source" || atRule.name === "tailwind" || atRule.name === "reference" || atRule.name === "plugin") atRule.remove();
|
|
2612
|
+
});
|
|
2613
|
+
}
|
|
2614
|
+
//#endregion
|
|
2487
2615
|
//#region src/compat/mini-program-prefixes.ts
|
|
2488
2616
|
const PRESERVED_WEBKIT_DECLARATION_PROPS = /* @__PURE__ */ new Set([
|
|
2489
2617
|
"-webkit-box-orient",
|
|
@@ -2574,37 +2702,6 @@ function removeUnsupportedMiniProgramPrefixedAtRule(atRule) {
|
|
|
2574
2702
|
if (atRule.name.toLowerCase() === "-webkit-keyframes") atRule.remove();
|
|
2575
2703
|
}
|
|
2576
2704
|
//#endregion
|
|
2577
|
-
//#region src/compat/mini-program-css/directives.ts
|
|
2578
|
-
const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
|
|
2579
|
-
const GENERATOR_PLACEHOLDER_COMMENT_RE = /^\s*(?:!\s*)?weapp-tailwindcss generator-placeholder\s*$/i;
|
|
2580
|
-
function hasTailwindcssV4Signal(css) {
|
|
2581
|
-
if (TAILWIND_V4_BANNER_RE.test(css)) return true;
|
|
2582
|
-
const root = postcss.default.parse(css);
|
|
2583
|
-
let hasProperty = false;
|
|
2584
|
-
root.walkAtRules("property", (atRule) => {
|
|
2585
|
-
if (atRule.params.trim().startsWith("--tw-")) {
|
|
2586
|
-
hasProperty = true;
|
|
2587
|
-
return false;
|
|
2588
|
-
}
|
|
2589
|
-
});
|
|
2590
|
-
return hasProperty;
|
|
2591
|
-
}
|
|
2592
|
-
function unwrapTailwindSourceMedia(root) {
|
|
2593
|
-
root.walkAtRules("media", (atRule) => {
|
|
2594
|
-
if (!atRule.params.startsWith("source(")) return;
|
|
2595
|
-
if (atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
|
|
2596
|
-
else atRule.remove();
|
|
2597
|
-
});
|
|
2598
|
-
}
|
|
2599
|
-
function removeTailwindGenerationDirectives(root) {
|
|
2600
|
-
root.walkComments((comment) => {
|
|
2601
|
-
if (GENERATOR_PLACEHOLDER_COMMENT_RE.test(comment.text)) comment.remove();
|
|
2602
|
-
});
|
|
2603
|
-
root.walkAtRules((atRule) => {
|
|
2604
|
-
if (atRule.name === "config" || atRule.name === "source" || atRule.name === "tailwind" || atRule.name === "reference" || atRule.name === "plugin") atRule.remove();
|
|
2605
|
-
});
|
|
2606
|
-
}
|
|
2607
|
-
//#endregion
|
|
2608
2705
|
//#region src/compat/mini-program-css/hoist.ts
|
|
2609
2706
|
const HOIST_ANCHOR_COMMENT = "__weapp_tailwindcss_base_anchor__";
|
|
2610
2707
|
function getTopDirectiveTail(root) {
|
|
@@ -2823,8 +2920,10 @@ function finalizeMiniProgramCssRoot(root, options = {}) {
|
|
|
2823
2920
|
}));
|
|
2824
2921
|
const themeRule = collectThemeVariableRule(root, options);
|
|
2825
2922
|
insertHoistedRules(root, mergeEquivalentHoistedRules(themeRule ? [...preflightRules, themeRule] : preflightRules), hoistAnchor);
|
|
2826
|
-
if (options.removeEmptyAtRuleAncestors !== false)
|
|
2827
|
-
|
|
2923
|
+
if (options.removeEmptyAtRuleAncestors !== false) {
|
|
2924
|
+
removeEmptyRules(root);
|
|
2925
|
+
removeEmptyAtRules(root);
|
|
2926
|
+
} else root.walkAtRules((atRule) => {
|
|
2828
2927
|
if (atRule.nodes?.length === 0) atRule.remove();
|
|
2829
2928
|
});
|
|
2830
2929
|
}
|
|
@@ -2838,13 +2937,14 @@ function hoistTailwindPreflightBase(css) {
|
|
|
2838
2937
|
}
|
|
2839
2938
|
}
|
|
2840
2939
|
function finalizeMiniProgramCss(css, options = {}) {
|
|
2940
|
+
const repairedCss = repairTrailingUnclosedTailwindSourceMedia(css);
|
|
2841
2941
|
let isTailwindcssV4 = options.isTailwindcssV4;
|
|
2842
2942
|
if (isTailwindcssV4 === void 0) try {
|
|
2843
|
-
isTailwindcssV4 = hasTailwindcssV4Signal(
|
|
2943
|
+
isTailwindcssV4 = hasTailwindcssV4Signal(repairedCss);
|
|
2844
2944
|
} catch {
|
|
2845
|
-
isTailwindcssV4 = TAILWIND_V4_BANNER_RE.test(
|
|
2945
|
+
isTailwindcssV4 = TAILWIND_V4_BANNER_RE.test(repairedCss);
|
|
2846
2946
|
}
|
|
2847
|
-
const cleanedCss = removeUnsupportedMiniProgramAtRules(
|
|
2947
|
+
const cleanedCss = removeUnsupportedMiniProgramAtRules(repairedCss);
|
|
2848
2948
|
try {
|
|
2849
2949
|
const root = postcss.default.parse(cleanedCss);
|
|
2850
2950
|
finalizeMiniProgramCssRoot(root, {
|
|
@@ -7755,6 +7855,7 @@ exports.protectDynamicColorMixAlpha = protectDynamicColorMixAlpha;
|
|
|
7755
7855
|
exports.protectDynamicVarFallbacks = protectDynamicVarFallbacks;
|
|
7756
7856
|
exports.pruneMiniProgramGeneratedCss = pruneMiniProgramGeneratedCss;
|
|
7757
7857
|
exports.removeEmptyAtRules = removeEmptyAtRules;
|
|
7858
|
+
exports.removeEmptyRules = removeEmptyRules;
|
|
7758
7859
|
exports.removeMatchingLocalCssImports = removeMatchingLocalCssImports;
|
|
7759
7860
|
exports.removeMatchingLocalCssImportsRoot = removeMatchingLocalCssImportsRoot;
|
|
7760
7861
|
exports.removeTailwindPostcssPlugins = removeTailwindPostcssPlugins;
|
|
@@ -7764,6 +7865,7 @@ exports.removeUnsupportedCascadeLayers = removeUnsupportedCascadeLayers;
|
|
|
7764
7865
|
exports.removeUnsupportedMiniProgramAtRules = removeUnsupportedMiniProgramAtRules;
|
|
7765
7866
|
exports.removeUnsupportedMiniProgramCssImportsRoot = removeUnsupportedMiniProgramCssImportsRoot;
|
|
7766
7867
|
exports.removeUnsupportedMiniProgramPrefixedAtRule = removeUnsupportedMiniProgramPrefixedAtRule;
|
|
7868
|
+
exports.repairTrailingUnclosedTailwindSourceMedia = repairTrailingUnclosedTailwindSourceMedia;
|
|
7767
7869
|
exports.resolveCssSourceEntries = resolveCssSourceEntries;
|
|
7768
7870
|
exports.resolveFilteredPostcssConfig = resolveFilteredPostcssConfig;
|
|
7769
7871
|
exports.resolvePostcssConfig = resolvePostcssConfig;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { type PostcssAppType, type PostcssStyleBranch, type PostcssStyleBranchProfile, resolvePostcssStyleBranch, type ResolvePostcssStyleBranchOptions, resolvePostcssStyleBranchProfile, } from './branches/index.js';
|
|
2
2
|
export { type DynamicColorMixAlphaProtection, type DynamicColorMixAlphaProtectionOptions, type ModernColorValueNormalization, normalizeModernColorValue, protectDynamicColorMixAlpha, protectDynamicVarFallbacks, } from './compat/color-mix.js';
|
|
3
3
|
export { transformLynxCssCompat } from './compat/lynx-css.js';
|
|
4
|
-
export { consumeCascadeLayers, finalizeMiniProgramCss, type FinalizeMiniProgramCssOptions, finalizeMiniProgramCssRoot, hasMiniProgramCssSpecificityPlaceholders, hoistTailwindPreflightBase, normalizeMiniProgramGeneratedCssForPostcss, pruneMiniProgramGeneratedCss, removeEmptyAtRules, removeUnsupportedAtSupports, removeUnsupportedCascadeLayers, removeUnsupportedMiniProgramAtRules, stripMiniProgramCssSpecificityPlaceholders, unwrapUnsupportedCascadeLayers, } from './compat/mini-program-css/index.js';
|
|
4
|
+
export { consumeCascadeLayers, finalizeMiniProgramCss, type FinalizeMiniProgramCssOptions, finalizeMiniProgramCssRoot, hasMiniProgramCssSpecificityPlaceholders, hoistTailwindPreflightBase, normalizeMiniProgramGeneratedCssForPostcss, pruneMiniProgramGeneratedCss, removeEmptyAtRules, removeEmptyRules, removeUnsupportedAtSupports, removeUnsupportedCascadeLayers, removeUnsupportedMiniProgramAtRules, repairTrailingUnclosedTailwindSourceMedia, stripMiniProgramCssSpecificityPlaceholders, unwrapUnsupportedCascadeLayers, } from './compat/mini-program-css/index.js';
|
|
5
5
|
export { normalizeMiniProgramPrefixedDeclaration, removeUnsupportedMiniProgramPrefixedAtRule, } from './compat/mini-program-prefixes.js';
|
|
6
6
|
export { convertTailwindcssRpxDeclarationsToRem, convertTailwindcssRpxDeclarationToRem, convertTailwindcssRpxValueToRem, normalizeTailwindcssRpxDeclaration, normalizeTailwindcssRpxDeclarations, normalizeTailwindcssWebRpxDeclarations, type TailwindcssRpxToRemOptions, } from './compat/tailwindcss-rpx.js';
|
|
7
7
|
export { normalizeTailwindcssV4InfinityCalcCss } from './compat/tailwindcss-v4.js';
|
package/dist/index.js
CHANGED
|
@@ -1033,6 +1033,9 @@ function removeRootSpecificityPlaceholders(root) {
|
|
|
1033
1033
|
function isEffectivelyEmptyContainer(container) {
|
|
1034
1034
|
return container.nodes !== void 0 && container.nodes.every((node) => node.type === "comment");
|
|
1035
1035
|
}
|
|
1036
|
+
function isKeyframeStepRule(rule) {
|
|
1037
|
+
return rule.parent?.type === "atrule" && rule.parent.name.toLowerCase().endsWith("keyframes");
|
|
1038
|
+
}
|
|
1036
1039
|
function removeEmptyAtRules(root) {
|
|
1037
1040
|
let removed = 0;
|
|
1038
1041
|
const visit = (container) => {
|
|
@@ -1065,6 +1068,17 @@ function removeEmptyAtRuleAncestors(parent) {
|
|
|
1065
1068
|
parent = nextParent?.type === "atrule" ? nextParent : void 0;
|
|
1066
1069
|
}
|
|
1067
1070
|
}
|
|
1071
|
+
function removeEmptyRules(root) {
|
|
1072
|
+
let removed = 0;
|
|
1073
|
+
root.walkRules((rule) => {
|
|
1074
|
+
if (isKeyframeStepRule(rule) || !rule.parent || !isEffectivelyEmptyContainer(rule)) return;
|
|
1075
|
+
const parent = rule.parent;
|
|
1076
|
+
rule.remove();
|
|
1077
|
+
removeEmptyAtRuleAncestors(parent);
|
|
1078
|
+
removed++;
|
|
1079
|
+
});
|
|
1080
|
+
return removed;
|
|
1081
|
+
}
|
|
1068
1082
|
function removeUnsupportedBrowserSelectors(root) {
|
|
1069
1083
|
root.walkRules((rule) => {
|
|
1070
1084
|
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
@@ -2468,6 +2482,120 @@ function unwrapUnsupportedCascadeLayers(css) {
|
|
|
2468
2482
|
}
|
|
2469
2483
|
}
|
|
2470
2484
|
//#endregion
|
|
2485
|
+
//#region src/compat/mini-program-css/directives.ts
|
|
2486
|
+
const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
|
|
2487
|
+
const GENERATOR_PLACEHOLDER_COMMENT_RE = /^\s*(?:!\s*)?weapp-tailwindcss generator-placeholder\s*$/i;
|
|
2488
|
+
function isCssWhitespace(code) {
|
|
2489
|
+
return code === 9 || code === 10 || code === 12 || code === 13 || code === 32;
|
|
2490
|
+
}
|
|
2491
|
+
function skipCssWhitespace(css, start) {
|
|
2492
|
+
let index = start;
|
|
2493
|
+
while (index < css.length && isCssWhitespace(css.charCodeAt(index))) index++;
|
|
2494
|
+
return index;
|
|
2495
|
+
}
|
|
2496
|
+
function findClosingParenthesis(css, openingIndex) {
|
|
2497
|
+
let depth = 0;
|
|
2498
|
+
let quote = 0;
|
|
2499
|
+
for (let index = openingIndex; index < css.length; index++) {
|
|
2500
|
+
const code = css.charCodeAt(index);
|
|
2501
|
+
if (quote !== 0) {
|
|
2502
|
+
if (code === 92) index++;
|
|
2503
|
+
else if (code === quote) quote = 0;
|
|
2504
|
+
continue;
|
|
2505
|
+
}
|
|
2506
|
+
if (code === 34 || code === 39) {
|
|
2507
|
+
quote = code;
|
|
2508
|
+
continue;
|
|
2509
|
+
}
|
|
2510
|
+
if (code === 92) {
|
|
2511
|
+
index++;
|
|
2512
|
+
continue;
|
|
2513
|
+
}
|
|
2514
|
+
if (code === 47 && css.charCodeAt(index + 1) === 42) {
|
|
2515
|
+
const commentEnd = css.indexOf("*/", index + 2);
|
|
2516
|
+
if (commentEnd < 0) return -1;
|
|
2517
|
+
index = commentEnd + 1;
|
|
2518
|
+
continue;
|
|
2519
|
+
}
|
|
2520
|
+
if (code === 40) {
|
|
2521
|
+
depth++;
|
|
2522
|
+
continue;
|
|
2523
|
+
}
|
|
2524
|
+
if (code === 41) {
|
|
2525
|
+
depth--;
|
|
2526
|
+
if (depth === 0) return index;
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
2529
|
+
return -1;
|
|
2530
|
+
}
|
|
2531
|
+
function isCssCodePosition(css, position) {
|
|
2532
|
+
let quote = 0;
|
|
2533
|
+
for (let index = 0; index < position; index++) {
|
|
2534
|
+
const code = css.charCodeAt(index);
|
|
2535
|
+
if (quote !== 0) {
|
|
2536
|
+
if (code === 92) index++;
|
|
2537
|
+
else if (code === quote) quote = 0;
|
|
2538
|
+
continue;
|
|
2539
|
+
}
|
|
2540
|
+
if (code === 34 || code === 39) {
|
|
2541
|
+
quote = code;
|
|
2542
|
+
continue;
|
|
2543
|
+
}
|
|
2544
|
+
if (code === 47 && css.charCodeAt(index + 1) === 42) {
|
|
2545
|
+
const commentEnd = css.indexOf("*/", index + 2);
|
|
2546
|
+
if (commentEnd < 0 || commentEnd >= position) return false;
|
|
2547
|
+
index = commentEnd + 1;
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
return quote === 0;
|
|
2551
|
+
}
|
|
2552
|
+
/**
|
|
2553
|
+
* 严格移除文件末尾残留的 Tailwind source media 开始标记。
|
|
2554
|
+
* 仅处理可确认属于 Tailwind 的尾部残片,其它非法 CSS 保持原样。
|
|
2555
|
+
*/
|
|
2556
|
+
function repairTrailingUnclosedTailwindSourceMedia(css) {
|
|
2557
|
+
const sourceMediaPattern = /(?:^|\r?\n)[\t\f ]*@media\s+source\(/g;
|
|
2558
|
+
for (let match = sourceMediaPattern.exec(css); match !== null; match = sourceMediaPattern.exec(css)) {
|
|
2559
|
+
const prefixLength = match[0].startsWith("\n") ? 1 : match[0].startsWith("\r\n") ? 2 : 0;
|
|
2560
|
+
const start = match.index + prefixLength;
|
|
2561
|
+
if (!isCssCodePosition(css, start)) continue;
|
|
2562
|
+
const closingIndex = findClosingParenthesis(css, start + match[0].length - prefixLength - 1);
|
|
2563
|
+
if (closingIndex < 0) continue;
|
|
2564
|
+
const blockStart = skipCssWhitespace(css, closingIndex + 1);
|
|
2565
|
+
if (css.charCodeAt(blockStart) !== 123) continue;
|
|
2566
|
+
if (skipCssWhitespace(css, blockStart + 1) !== css.length) continue;
|
|
2567
|
+
return css.slice(0, match.index);
|
|
2568
|
+
}
|
|
2569
|
+
return css;
|
|
2570
|
+
}
|
|
2571
|
+
function hasTailwindcssV4Signal(css) {
|
|
2572
|
+
if (TAILWIND_V4_BANNER_RE.test(css)) return true;
|
|
2573
|
+
const root = postcss$1.parse(css);
|
|
2574
|
+
let hasProperty = false;
|
|
2575
|
+
root.walkAtRules("property", (atRule) => {
|
|
2576
|
+
if (atRule.params.trim().startsWith("--tw-")) {
|
|
2577
|
+
hasProperty = true;
|
|
2578
|
+
return false;
|
|
2579
|
+
}
|
|
2580
|
+
});
|
|
2581
|
+
return hasProperty;
|
|
2582
|
+
}
|
|
2583
|
+
function unwrapTailwindSourceMedia(root) {
|
|
2584
|
+
root.walkAtRules("media", (atRule) => {
|
|
2585
|
+
if (!atRule.params.startsWith("source(")) return;
|
|
2586
|
+
if (atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
|
|
2587
|
+
else atRule.remove();
|
|
2588
|
+
});
|
|
2589
|
+
}
|
|
2590
|
+
function removeTailwindGenerationDirectives(root) {
|
|
2591
|
+
root.walkComments((comment) => {
|
|
2592
|
+
if (GENERATOR_PLACEHOLDER_COMMENT_RE.test(comment.text)) comment.remove();
|
|
2593
|
+
});
|
|
2594
|
+
root.walkAtRules((atRule) => {
|
|
2595
|
+
if (atRule.name === "config" || atRule.name === "source" || atRule.name === "tailwind" || atRule.name === "reference" || atRule.name === "plugin") atRule.remove();
|
|
2596
|
+
});
|
|
2597
|
+
}
|
|
2598
|
+
//#endregion
|
|
2471
2599
|
//#region src/compat/mini-program-prefixes.ts
|
|
2472
2600
|
const PRESERVED_WEBKIT_DECLARATION_PROPS = /* @__PURE__ */ new Set([
|
|
2473
2601
|
"-webkit-box-orient",
|
|
@@ -2558,37 +2686,6 @@ function removeUnsupportedMiniProgramPrefixedAtRule(atRule) {
|
|
|
2558
2686
|
if (atRule.name.toLowerCase() === "-webkit-keyframes") atRule.remove();
|
|
2559
2687
|
}
|
|
2560
2688
|
//#endregion
|
|
2561
|
-
//#region src/compat/mini-program-css/directives.ts
|
|
2562
|
-
const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
|
|
2563
|
-
const GENERATOR_PLACEHOLDER_COMMENT_RE = /^\s*(?:!\s*)?weapp-tailwindcss generator-placeholder\s*$/i;
|
|
2564
|
-
function hasTailwindcssV4Signal(css) {
|
|
2565
|
-
if (TAILWIND_V4_BANNER_RE.test(css)) return true;
|
|
2566
|
-
const root = postcss$1.parse(css);
|
|
2567
|
-
let hasProperty = false;
|
|
2568
|
-
root.walkAtRules("property", (atRule) => {
|
|
2569
|
-
if (atRule.params.trim().startsWith("--tw-")) {
|
|
2570
|
-
hasProperty = true;
|
|
2571
|
-
return false;
|
|
2572
|
-
}
|
|
2573
|
-
});
|
|
2574
|
-
return hasProperty;
|
|
2575
|
-
}
|
|
2576
|
-
function unwrapTailwindSourceMedia(root) {
|
|
2577
|
-
root.walkAtRules("media", (atRule) => {
|
|
2578
|
-
if (!atRule.params.startsWith("source(")) return;
|
|
2579
|
-
if (atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
|
|
2580
|
-
else atRule.remove();
|
|
2581
|
-
});
|
|
2582
|
-
}
|
|
2583
|
-
function removeTailwindGenerationDirectives(root) {
|
|
2584
|
-
root.walkComments((comment) => {
|
|
2585
|
-
if (GENERATOR_PLACEHOLDER_COMMENT_RE.test(comment.text)) comment.remove();
|
|
2586
|
-
});
|
|
2587
|
-
root.walkAtRules((atRule) => {
|
|
2588
|
-
if (atRule.name === "config" || atRule.name === "source" || atRule.name === "tailwind" || atRule.name === "reference" || atRule.name === "plugin") atRule.remove();
|
|
2589
|
-
});
|
|
2590
|
-
}
|
|
2591
|
-
//#endregion
|
|
2592
2689
|
//#region src/compat/mini-program-css/hoist.ts
|
|
2593
2690
|
const HOIST_ANCHOR_COMMENT = "__weapp_tailwindcss_base_anchor__";
|
|
2594
2691
|
function getTopDirectiveTail(root) {
|
|
@@ -2807,8 +2904,10 @@ function finalizeMiniProgramCssRoot(root, options = {}) {
|
|
|
2807
2904
|
}));
|
|
2808
2905
|
const themeRule = collectThemeVariableRule(root, options);
|
|
2809
2906
|
insertHoistedRules(root, mergeEquivalentHoistedRules(themeRule ? [...preflightRules, themeRule] : preflightRules), hoistAnchor);
|
|
2810
|
-
if (options.removeEmptyAtRuleAncestors !== false)
|
|
2811
|
-
|
|
2907
|
+
if (options.removeEmptyAtRuleAncestors !== false) {
|
|
2908
|
+
removeEmptyRules(root);
|
|
2909
|
+
removeEmptyAtRules(root);
|
|
2910
|
+
} else root.walkAtRules((atRule) => {
|
|
2812
2911
|
if (atRule.nodes?.length === 0) atRule.remove();
|
|
2813
2912
|
});
|
|
2814
2913
|
}
|
|
@@ -2822,13 +2921,14 @@ function hoistTailwindPreflightBase(css) {
|
|
|
2822
2921
|
}
|
|
2823
2922
|
}
|
|
2824
2923
|
function finalizeMiniProgramCss(css, options = {}) {
|
|
2924
|
+
const repairedCss = repairTrailingUnclosedTailwindSourceMedia(css);
|
|
2825
2925
|
let isTailwindcssV4 = options.isTailwindcssV4;
|
|
2826
2926
|
if (isTailwindcssV4 === void 0) try {
|
|
2827
|
-
isTailwindcssV4 = hasTailwindcssV4Signal(
|
|
2927
|
+
isTailwindcssV4 = hasTailwindcssV4Signal(repairedCss);
|
|
2828
2928
|
} catch {
|
|
2829
|
-
isTailwindcssV4 = TAILWIND_V4_BANNER_RE.test(
|
|
2929
|
+
isTailwindcssV4 = TAILWIND_V4_BANNER_RE.test(repairedCss);
|
|
2830
2930
|
}
|
|
2831
|
-
const cleanedCss = removeUnsupportedMiniProgramAtRules(
|
|
2931
|
+
const cleanedCss = removeUnsupportedMiniProgramAtRules(repairedCss);
|
|
2832
2932
|
try {
|
|
2833
2933
|
const root = postcss$1.parse(cleanedCss);
|
|
2834
2934
|
finalizeMiniProgramCssRoot(root, {
|
|
@@ -7651,4 +7751,4 @@ function mergeMiniProgramThemeScopeRuleDeclarations(baseCss, css) {
|
|
|
7651
7751
|
}
|
|
7652
7752
|
}
|
|
7653
7753
|
//#endregion
|
|
7654
|
-
export { CSS_MACRO_POSTCSS_PLUGIN_NAME, CSS_MACRO_STYLE_OPTIONS_MARKER, FULL_SOURCE_SCAN_EXTENSIONS, FULL_SOURCE_SCAN_EXTENSION_RE, FULL_SOURCE_SCAN_PATTERN, UNI_APP_X_IMPORTANT_APPLY_MARKER, analyzeTailwindCssDirectives, cleanLocalCssImportWrapperTailwindDirectives, cleanLocalCssImportWrapperTailwindDirectivesRoot, collectApplyOnlyCssSelectors, collectApplyOnlyCssSelectorsRoot, collectCssImportRequestsRoot, collectCssInlineSourceCandidates, compileCssMacroConditionalComments, consumeCascadeLayers, containsCssAfterMinify, convertTailwindcssRpxDeclarationToRem, convertTailwindcssRpxDeclarationsToRem, convertTailwindcssRpxValueToRem, createCssSourceOrderAppend, createFallbackPlaceholderReplacer, createInjectPreflight, createPostcssStyleTargetProfile, createSourceScanPattern, createStyleHandler, createStylePipeline, createTailwindSourceEntryMatcher, createWeappTailwindcssPostcssPlugin, creator as cssMacroPostcssPlugin, dedupeCoveredCssRules, expandInlineSourceCandidatePattern, expandTailwindSourceEntries, filterApplyOnlyGeneratedCss, filterApplyOnlyGeneratedCssRoot, filterExistingCssRules, finalizeMiniProgramCss, finalizeMiniProgramCssRoot, getPostcssPluginName, hasCssMacroStyleOptions, hasCssMacroTailwindV4CustomVariantConditionalComments, hasCssMacroTailwindV4Directive, hasCssMacroTailwindV4InternalAtRules, hasCssMacroTailwindV4Source, hasMiniProgramCssSpecificityPlaceholders, hoistTailwindPreflightBase, internalCssSelectorReplacer, isFileExcludedByTailwindSourceEntries, isFileMatchedByTailwindSourceEntries, isLocalCssImportRequest, isMiniProgramLocalCssImportRequest, isPureLocalCssImportWrapper, isPureLocalCssImportWrapperRoot, isTailwindCssGenerationDirective, isTailwindCssImportAtRule, isTailwindCssImportRequest, isTailwindCssPackageJsonImportRequest, isWeappTailwindcssImportRequest, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, normalizeLegacyContentEntries, normalizeMiniProgramGeneratedCssForPostcss, normalizeMiniProgramPrefixedDeclaration, normalizeModernColorValue, normalizeOutputImportRequest, normalizeTailwindCssImportRequest, normalizeTailwindcssRpxDeclaration, normalizeTailwindcssRpxDeclarations, normalizeTailwindcssV4InfinityCalcCss, normalizeTailwindcssWebRpxDeclarations, normalizeUniAppXImportantApplyForSass, normalizeWebCssCompatOptions, parseConfigParam, parseSourceFileParam, parseTailwindCssConfigRequest, parseTailwindCssDirectiveRequest, postcss, postcssHtmlTransform, prefixLocalCssImportsWithWebpackIgnoreRoot, protectDynamicColorMixAlpha, protectDynamicVarFallbacks, pruneMiniProgramGeneratedCss, removeEmptyAtRules, removeMatchingLocalCssImports, removeMatchingLocalCssImportsRoot, removeTailwindPostcssPlugins, removeTailwindSourceDirectivesRoot, removeUnsupportedAtSupports, removeUnsupportedCascadeLayers, removeUnsupportedMiniProgramAtRules, removeUnsupportedMiniProgramCssImportsRoot, removeUnsupportedMiniProgramPrefixedAtRule, resolveCssSourceEntries, resolveFilteredPostcssConfig, resolvePostcssConfig, resolvePostcssFrameworkProfile, resolvePostcssFrameworkStrategy, resolvePostcssStyleBranch, resolvePostcssStyleBranchProfile, resolvePostcssStyleTarget, resolveSourceScanPath, resolveTailwindSourceEntry, restoreLocalCssImports, restoreUniAppXImportantApplyMarker, rewriteLocalCssImportRequestsForOutput, rewriteLocalCssImportRequestsForOutputRoot, selectorContainsPseudoClass, splitLocalCssImports, splitLocalCssImportsRoot, stripMiniProgramCssSpecificityPlaceholders, toPosixPath, transformCssMacroCss, transformCssMacroTailwindV4Source, transformLynxCssCompat, transformWebCssCompat, transformWebCssSafeSelectors, unitConversionComposeRules, unitConversionPresets, unwrapUnsupportedCascadeLayers, withCssMacroStyleOptions };
|
|
7754
|
+
export { CSS_MACRO_POSTCSS_PLUGIN_NAME, CSS_MACRO_STYLE_OPTIONS_MARKER, FULL_SOURCE_SCAN_EXTENSIONS, FULL_SOURCE_SCAN_EXTENSION_RE, FULL_SOURCE_SCAN_PATTERN, UNI_APP_X_IMPORTANT_APPLY_MARKER, analyzeTailwindCssDirectives, cleanLocalCssImportWrapperTailwindDirectives, cleanLocalCssImportWrapperTailwindDirectivesRoot, collectApplyOnlyCssSelectors, collectApplyOnlyCssSelectorsRoot, collectCssImportRequestsRoot, collectCssInlineSourceCandidates, compileCssMacroConditionalComments, consumeCascadeLayers, containsCssAfterMinify, convertTailwindcssRpxDeclarationToRem, convertTailwindcssRpxDeclarationsToRem, convertTailwindcssRpxValueToRem, createCssSourceOrderAppend, createFallbackPlaceholderReplacer, createInjectPreflight, createPostcssStyleTargetProfile, createSourceScanPattern, createStyleHandler, createStylePipeline, createTailwindSourceEntryMatcher, createWeappTailwindcssPostcssPlugin, creator as cssMacroPostcssPlugin, dedupeCoveredCssRules, expandInlineSourceCandidatePattern, expandTailwindSourceEntries, filterApplyOnlyGeneratedCss, filterApplyOnlyGeneratedCssRoot, filterExistingCssRules, finalizeMiniProgramCss, finalizeMiniProgramCssRoot, getPostcssPluginName, hasCssMacroStyleOptions, hasCssMacroTailwindV4CustomVariantConditionalComments, hasCssMacroTailwindV4Directive, hasCssMacroTailwindV4InternalAtRules, hasCssMacroTailwindV4Source, hasMiniProgramCssSpecificityPlaceholders, hoistTailwindPreflightBase, internalCssSelectorReplacer, isFileExcludedByTailwindSourceEntries, isFileMatchedByTailwindSourceEntries, isLocalCssImportRequest, isMiniProgramLocalCssImportRequest, isPureLocalCssImportWrapper, isPureLocalCssImportWrapperRoot, isTailwindCssGenerationDirective, isTailwindCssImportAtRule, isTailwindCssImportRequest, isTailwindCssPackageJsonImportRequest, isWeappTailwindcssImportRequest, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, normalizeLegacyContentEntries, normalizeMiniProgramGeneratedCssForPostcss, normalizeMiniProgramPrefixedDeclaration, normalizeModernColorValue, normalizeOutputImportRequest, normalizeTailwindCssImportRequest, normalizeTailwindcssRpxDeclaration, normalizeTailwindcssRpxDeclarations, normalizeTailwindcssV4InfinityCalcCss, normalizeTailwindcssWebRpxDeclarations, normalizeUniAppXImportantApplyForSass, normalizeWebCssCompatOptions, parseConfigParam, parseSourceFileParam, parseTailwindCssConfigRequest, parseTailwindCssDirectiveRequest, postcss, postcssHtmlTransform, prefixLocalCssImportsWithWebpackIgnoreRoot, protectDynamicColorMixAlpha, protectDynamicVarFallbacks, pruneMiniProgramGeneratedCss, removeEmptyAtRules, removeEmptyRules, removeMatchingLocalCssImports, removeMatchingLocalCssImportsRoot, removeTailwindPostcssPlugins, removeTailwindSourceDirectivesRoot, removeUnsupportedAtSupports, removeUnsupportedCascadeLayers, removeUnsupportedMiniProgramAtRules, removeUnsupportedMiniProgramCssImportsRoot, removeUnsupportedMiniProgramPrefixedAtRule, repairTrailingUnclosedTailwindSourceMedia, resolveCssSourceEntries, resolveFilteredPostcssConfig, resolvePostcssConfig, resolvePostcssFrameworkProfile, resolvePostcssFrameworkStrategy, resolvePostcssStyleBranch, resolvePostcssStyleBranchProfile, resolvePostcssStyleTarget, resolveSourceScanPath, resolveTailwindSourceEntry, restoreLocalCssImports, restoreUniAppXImportantApplyMarker, rewriteLocalCssImportRequestsForOutput, rewriteLocalCssImportRequestsForOutputRoot, selectorContainsPseudoClass, splitLocalCssImports, splitLocalCssImportsRoot, stripMiniProgramCssSpecificityPlaceholders, toPosixPath, transformCssMacroCss, transformCssMacroTailwindV4Source, transformLynxCssCompat, transformWebCssCompat, transformWebCssSafeSelectors, unitConversionComposeRules, unitConversionPresets, unwrapUnsupportedCascadeLayers, withCssMacroStyleOptions };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-tailwindcss/postcss",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.3.
|
|
4
|
+
"version": "3.3.2",
|
|
5
5
|
"description": "PostCSS transforms that bring Tailwind CSS compatibility to every platform. 将 Tailwind CSS 兼容能力带到全端的 PostCSS 转换工具。",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"node": "^20.19.0 || >=22.12.0"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@csstools/css-color-parser": "^4.2.
|
|
69
|
+
"@csstools/css-color-parser": "^4.2.2",
|
|
70
70
|
"@csstools/css-parser-algorithms": "^4.0.0",
|
|
71
71
|
"@csstools/css-tokenizer": "^4.0.0",
|
|
72
72
|
"@tailwindcss-mangle/engine": "0.2.0",
|
|
@@ -74,12 +74,12 @@
|
|
|
74
74
|
"@weapp-tailwindcss/postcss-calc": "1.0.5",
|
|
75
75
|
"@weapp-tailwindcss/shared": "2.0.3",
|
|
76
76
|
"autoprefixer": "^10.5.4",
|
|
77
|
-
"es-toolkit": "^1.
|
|
77
|
+
"es-toolkit": "^1.52.0",
|
|
78
78
|
"lru-cache": "11.5.2",
|
|
79
79
|
"micromatch": "^4.0.8",
|
|
80
80
|
"postcss": "^8.5.26",
|
|
81
81
|
"postcss-load-config": "^6.0.1",
|
|
82
|
-
"postcss-preset-env": "^11.5.
|
|
82
|
+
"postcss-preset-env": "^11.5.1",
|
|
83
83
|
"postcss-pxtrans": "^1.0.4",
|
|
84
84
|
"postcss-rem-to-responsive-pixel": "^7.0.5",
|
|
85
85
|
"postcss-rule-unit-converter": "^0.2.3",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"devDependencies": {
|
|
92
92
|
"@csstools/postcss-is-pseudo-class": "^6.0.0",
|
|
93
93
|
"fast-check": "^4.9.0",
|
|
94
|
-
"postcss-calc": "link
|
|
94
|
+
"postcss-calc": "link:../postcss-calc",
|
|
95
95
|
"postcss-custom-properties": "^15.0.1"
|
|
96
96
|
},
|
|
97
97
|
"scripts": {
|