@weapp-tailwindcss/postcss 3.2.3 → 3.2.5
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.
|
@@ -7,6 +7,7 @@ export declare function removeRootSpecificityPlaceholders(root: postcss.Root): v
|
|
|
7
7
|
export declare function removeEmptyAtRules(root: postcss.Root): number;
|
|
8
8
|
export declare function removeEmptyBlockAtRules(root: postcss.Root): number;
|
|
9
9
|
export declare function removeUnsupportedBrowserSelectors(root: postcss.Root): void;
|
|
10
|
+
export declare function removeEmptyStandardPropertyFallbacks(root: postcss.Root): void;
|
|
10
11
|
export declare function removeDisplayP3Declarations(root: postcss.Root): void;
|
|
11
12
|
interface RemoveTailwindContainerRulesOptions {
|
|
12
13
|
generatedOnly?: boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Result as PostcssResult } from 'postcss';
|
|
2
2
|
import type { IStyleHandlerOptions } from '../types.js';
|
|
3
3
|
import postcss from 'postcss';
|
|
4
|
-
export declare function applyUniAppXUvueCompatibility(result: PostcssResult, options?: Pick<IStyleHandlerOptions, 'customPropertyValues' | 'uniAppX' | 'uniAppXCssTarget' | 'uniAppXUnsupported'>): PostcssResult<postcss.Document | postcss.Root>;
|
|
4
|
+
export declare function applyUniAppXUvueCompatibility(result: PostcssResult, options?: Pick<IStyleHandlerOptions, 'customPropertyValues' | 'isMainChunk' | 'uniAppX' | 'uniAppXCssTarget' | 'uniAppXUnsupported'>): PostcssResult<postcss.Document | postcss.Root>;
|
package/dist/index.cjs
CHANGED
|
@@ -816,6 +816,200 @@ function isTailwindcssV4DisplayP3Declaration(decl) {
|
|
|
816
816
|
return DISPLAY_P3_VALUE_RE$1.test(decl.value);
|
|
817
817
|
}
|
|
818
818
|
//#endregion
|
|
819
|
+
//#region src/compat/uni-app-x-uvue/scoped-style.ts
|
|
820
|
+
const MINI_PROGRAM_PREFLIGHT_SELECTORS$1 = /* @__PURE__ */ new Set([
|
|
821
|
+
"view",
|
|
822
|
+
"text",
|
|
823
|
+
"::after",
|
|
824
|
+
"::before"
|
|
825
|
+
]);
|
|
826
|
+
const SCOPED_UNIVERSAL_PREFLIGHT_SELECTORS = /* @__PURE__ */ new Set([
|
|
827
|
+
"*",
|
|
828
|
+
"::after",
|
|
829
|
+
"::before",
|
|
830
|
+
"::backdrop",
|
|
831
|
+
"::file-selector-button"
|
|
832
|
+
]);
|
|
833
|
+
const TAILWIND_VERSION_COMMENT_RE = /tailwindcss v\d/i;
|
|
834
|
+
const VUE_SCOPED_ATTR_RE = /\[data-v-[^\]]+\]/gi;
|
|
835
|
+
const VUE_SCOPED_CLASS_RE = /\.data-v-[\w-]+/gi;
|
|
836
|
+
const TAILWIND_PREFLIGHT_DECLARATIONS = /* @__PURE__ */ new Set([
|
|
837
|
+
"-moz-tab-size:4",
|
|
838
|
+
"-webkit-appearance:none",
|
|
839
|
+
"-webkit-appearance:button",
|
|
840
|
+
"-webkit-tap-highlight-color:transparent",
|
|
841
|
+
"-webkit-text-decoration:inherit",
|
|
842
|
+
"-webkit-text-decoration:underline dotted",
|
|
843
|
+
"-webkit-text-size-adjust:100%",
|
|
844
|
+
"-o-tab-size:4",
|
|
845
|
+
"appearance:button",
|
|
846
|
+
"background-color:transparent",
|
|
847
|
+
"border-collapse:collapse",
|
|
848
|
+
"border-color:inherit",
|
|
849
|
+
"border-radius:0",
|
|
850
|
+
"border-top-width:1px",
|
|
851
|
+
"bottom:-.25em",
|
|
852
|
+
"color:inherit",
|
|
853
|
+
"display:block",
|
|
854
|
+
"display:inline-flex",
|
|
855
|
+
"display:list-item",
|
|
856
|
+
"font:inherit",
|
|
857
|
+
"font-family:inherit",
|
|
858
|
+
"font-feature-settings:inherit",
|
|
859
|
+
"font-size:1em",
|
|
860
|
+
"font-size:75%",
|
|
861
|
+
"font-size:80%",
|
|
862
|
+
"font-size:inherit",
|
|
863
|
+
"font-variation-settings:inherit",
|
|
864
|
+
"font-weight:bolder",
|
|
865
|
+
"font-weight:inherit",
|
|
866
|
+
"height:0",
|
|
867
|
+
"height:auto",
|
|
868
|
+
"letter-spacing:inherit",
|
|
869
|
+
"line-height:1",
|
|
870
|
+
"line-height:1.5",
|
|
871
|
+
"line-height:0",
|
|
872
|
+
"line-height:inherit",
|
|
873
|
+
"list-style:none",
|
|
874
|
+
"margin-inline-end:4px",
|
|
875
|
+
"max-width:100%",
|
|
876
|
+
"min-height:1lh",
|
|
877
|
+
"opacity:1",
|
|
878
|
+
"outline:auto",
|
|
879
|
+
"padding:0",
|
|
880
|
+
"padding-block:0",
|
|
881
|
+
"position:relative",
|
|
882
|
+
"resize:vertical",
|
|
883
|
+
"tab-size:4",
|
|
884
|
+
"text-align:inherit",
|
|
885
|
+
"text-decoration:inherit",
|
|
886
|
+
"text-decoration:underline dotted",
|
|
887
|
+
"text-indent:0",
|
|
888
|
+
"text-transform:none",
|
|
889
|
+
"top:-.5em",
|
|
890
|
+
"vertical-align:baseline",
|
|
891
|
+
"vertical-align:middle"
|
|
892
|
+
]);
|
|
893
|
+
function hasVueScopedAttr(value) {
|
|
894
|
+
VUE_SCOPED_ATTR_RE.lastIndex = 0;
|
|
895
|
+
VUE_SCOPED_CLASS_RE.lastIndex = 0;
|
|
896
|
+
const matched = VUE_SCOPED_ATTR_RE.test(value) || VUE_SCOPED_CLASS_RE.test(value);
|
|
897
|
+
VUE_SCOPED_ATTR_RE.lastIndex = 0;
|
|
898
|
+
VUE_SCOPED_CLASS_RE.lastIndex = 0;
|
|
899
|
+
return matched;
|
|
900
|
+
}
|
|
901
|
+
function normalizeCssSignatureValue(value) {
|
|
902
|
+
return value.replace(VUE_SCOPED_ATTR_RE, "").replace(VUE_SCOPED_CLASS_RE, "").replace(/\s+/g, " ").replace(/\s*([>+~])\s*/g, "$1").replace(/\(\s+/g, "(").replace(/\s+\)/g, ")").trim();
|
|
903
|
+
}
|
|
904
|
+
function isSfcStyleRequestSource(source) {
|
|
905
|
+
if (typeof source !== "string") return false;
|
|
906
|
+
const queryIndex = source.indexOf("?");
|
|
907
|
+
if (queryIndex < 0 || !source.slice(0, queryIndex).toLowerCase().endsWith(".uvue")) return false;
|
|
908
|
+
const hashIndex = source.indexOf("#", queryIndex);
|
|
909
|
+
const query = source.slice(queryIndex + 1, hashIndex < 0 ? void 0 : hashIndex);
|
|
910
|
+
return new URLSearchParams(query).get("type") === "style";
|
|
911
|
+
}
|
|
912
|
+
function isUvueSfcStyleRequest(result) {
|
|
913
|
+
if (isSfcStyleRequestSource(result.opts.from)) return true;
|
|
914
|
+
if ((result.root.nodes ?? []).some((node) => isSfcStyleRequestSource(node.source?.input.from))) return true;
|
|
915
|
+
let hasScopedSelector = false;
|
|
916
|
+
result.root.walkRules((rule) => {
|
|
917
|
+
if ((rule.selectors ?? [rule.selector]).some(hasVueScopedAttr)) {
|
|
918
|
+
hasScopedSelector = true;
|
|
919
|
+
return false;
|
|
920
|
+
}
|
|
921
|
+
});
|
|
922
|
+
return hasScopedSelector;
|
|
923
|
+
}
|
|
924
|
+
function getDeclarations(rule) {
|
|
925
|
+
return rule.nodes?.filter((node) => node.type === "decl") ?? [];
|
|
926
|
+
}
|
|
927
|
+
function isLikelyTailwindGlobalSelector(selector) {
|
|
928
|
+
const normalized = normalizeCssSignatureValue(selector);
|
|
929
|
+
return normalized === "*" || normalized.startsWith("::") || normalized.startsWith(":root") || normalized.startsWith(":host") || /^(?:html|body|hr|abbr|h1|h2|h3|h4|h5|h6|a|b|strong|code|kbd|samp|pre|small|sub|sup|table|button|input|select|optgroup|textarea|summary|blockquote|dl|dd|fieldset|legend|ol|ul|menu|dialog|progress|video|audio|canvas|embed|iframe|img|object|svg|details|template|[uo]ni-progress)(?:$|[:,[\s>+~.#])/.test(normalized);
|
|
930
|
+
}
|
|
931
|
+
function isTailwindPreflightDeclaration(decl) {
|
|
932
|
+
const prop = decl.prop.trim().toLowerCase();
|
|
933
|
+
const value = normalizeCssSignatureValue(decl.value.trim().toLowerCase());
|
|
934
|
+
if (prop.startsWith("--tw-")) return true;
|
|
935
|
+
if (prop === "color" && value.startsWith("color-mix(") && value.includes("currentcolor") && value.includes("transparent")) return true;
|
|
936
|
+
if (prop === "color" && value === "currentcolor") return true;
|
|
937
|
+
if (prop === "font-family" && value.startsWith("var(--default-font-family") || prop === "font-feature-settings" && value.startsWith("var(--default-font-feature-settings") || prop === "font-variation-settings" && value.startsWith("var(--default-font-variation-settings")) return true;
|
|
938
|
+
return TAILWIND_PREFLIGHT_DECLARATIONS.has(`${prop}:${value}`);
|
|
939
|
+
}
|
|
940
|
+
function hasTailwindSourceEvidence(declarations, hasTailwindBanner) {
|
|
941
|
+
return hasTailwindBanner || declarations.some((decl) => decl.prop.startsWith("--tw-"));
|
|
942
|
+
}
|
|
943
|
+
function isScopedTailwindThemeCarrierRule(rule, hasTailwindBanner) {
|
|
944
|
+
const selectors = rule.selectors ?? [rule.selector];
|
|
945
|
+
const declarations = getDeclarations(rule);
|
|
946
|
+
return selectors.length > 0 && selectors.every((selector) => {
|
|
947
|
+
const normalized = normalizeCssSignatureValue(selector);
|
|
948
|
+
return hasVueScopedAttr(selector) && (normalized.startsWith(":root") || normalized.startsWith(":host"));
|
|
949
|
+
}) && declarations.length > 0 && declarations.every((decl) => decl.prop.startsWith("--")) && hasTailwindSourceEvidence(declarations, hasTailwindBanner);
|
|
950
|
+
}
|
|
951
|
+
function isScopedUniversalTailwindPreflightRule(rule, hasTailwindBanner) {
|
|
952
|
+
const selectors = rule.selectors ?? [rule.selector];
|
|
953
|
+
const declarations = getDeclarations(rule);
|
|
954
|
+
return selectors.length > 0 && selectors.every((selector) => hasVueScopedAttr(selector) && SCOPED_UNIVERSAL_PREFLIGHT_SELECTORS.has(normalizeCssSignatureValue(selector))) && declarations.length > 0 && declarations.every((decl) => decl.prop.startsWith("--tw-") || [
|
|
955
|
+
"box-sizing",
|
|
956
|
+
"margin",
|
|
957
|
+
"padding",
|
|
958
|
+
"border"
|
|
959
|
+
].includes(decl.prop)) && hasTailwindSourceEvidence(declarations, hasTailwindBanner);
|
|
960
|
+
}
|
|
961
|
+
function isScopedTailwindElementPreflightRule(rule, hasTailwindBanner) {
|
|
962
|
+
if (!hasTailwindBanner) return false;
|
|
963
|
+
const selectors = rule.selectors ?? [rule.selector];
|
|
964
|
+
const declarations = getDeclarations(rule);
|
|
965
|
+
return selectors.length > 0 && selectors.every((selector) => hasVueScopedAttr(selector) && isLikelyTailwindGlobalSelector(selector)) && declarations.length > 0 && declarations.every(isTailwindPreflightDeclaration);
|
|
966
|
+
}
|
|
967
|
+
function isUnscopedMiniProgramTailwindPreflightRule(rule, hasTailwindBanner) {
|
|
968
|
+
const selectors = rule.selectors ?? [rule.selector];
|
|
969
|
+
if (selectors.length === 0 || !selectors.every((selector) => {
|
|
970
|
+
const normalized = normalizeCssSignatureValue(selector);
|
|
971
|
+
return !hasVueScopedAttr(selector) && MINI_PROGRAM_PREFLIGHT_SELECTORS$1.has(normalized);
|
|
972
|
+
})) return false;
|
|
973
|
+
const declarations = getDeclarations(rule);
|
|
974
|
+
return declarations.length > 0 && declarations.every((decl) => decl.prop.startsWith("--tw-") || [
|
|
975
|
+
"box-sizing",
|
|
976
|
+
"margin",
|
|
977
|
+
"padding",
|
|
978
|
+
"border"
|
|
979
|
+
].includes(decl.prop)) && hasTailwindSourceEvidence(declarations, hasTailwindBanner);
|
|
980
|
+
}
|
|
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$1.has(normalized);
|
|
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
|
|
819
1013
|
//#region src/compat/uni-app-x-uvue/theme.ts
|
|
820
1014
|
const SYSTEM_ROOT_SELECTORS = /* @__PURE__ */ new Set([
|
|
821
1015
|
":host",
|
|
@@ -1013,6 +1207,7 @@ function applyUniAppXUvueCompatibility(result, options) {
|
|
|
1013
1207
|
if (!isUniAppXUvueTarget(options)) return result;
|
|
1014
1208
|
const mode = normalizeUnsupportedMode(options?.uniAppXUnsupported);
|
|
1015
1209
|
const warningCache = /* @__PURE__ */ new Set();
|
|
1210
|
+
const sfcStyleRequest = options?.isMainChunk !== true && isUvueSfcStyleRequest(result);
|
|
1016
1211
|
let root = result.root;
|
|
1017
1212
|
let calcMessages = [];
|
|
1018
1213
|
consumeUniAppXSystemRootTheme(root, options?.customPropertyValues);
|
|
@@ -1025,6 +1220,13 @@ function applyUniAppXUvueCompatibility(result, options) {
|
|
|
1025
1220
|
root = calcResult.root;
|
|
1026
1221
|
calcMessages = calcResult.messages;
|
|
1027
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
|
+
}
|
|
1028
1230
|
root.walkRules((rule) => {
|
|
1029
1231
|
if (!hasOnlyClassSelectors(rule)) {
|
|
1030
1232
|
reportUnsupportedRule(rule, result, mode, warningCache, "selector must be class-only");
|
|
@@ -2346,6 +2548,11 @@ function removeDeclarationAndEmptyRule$1(decl) {
|
|
|
2346
2548
|
removeEmptyAtRuleAncestors(ruleParent);
|
|
2347
2549
|
}
|
|
2348
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
|
+
}
|
|
2349
2556
|
function removeDisplayP3Declarations(root) {
|
|
2350
2557
|
root.walkAtRules((atRule) => {
|
|
2351
2558
|
if (isDisplayP3MediaRule(atRule)) {
|
|
@@ -2443,6 +2650,7 @@ function finalizeMiniProgramCssRoot(root, options = {}) {
|
|
|
2443
2650
|
removeRootSpecificityPlaceholders(root);
|
|
2444
2651
|
removeUnsupportedBrowserSelectors(root);
|
|
2445
2652
|
removeDisplayP3Declarations(root);
|
|
2653
|
+
removeEmptyStandardPropertyFallbacks(root);
|
|
2446
2654
|
removeTailwindContainerMaxWidthMediaRules(root);
|
|
2447
2655
|
removeTailwindContainerWidthRules(root, { generatedOnly: true });
|
|
2448
2656
|
removeUnsupportedModernColorDeclarations(root);
|
|
@@ -2990,6 +3198,16 @@ function removeEmptyAtRules$2(root) {
|
|
|
2990
3198
|
if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
|
|
2991
3199
|
});
|
|
2992
3200
|
}
|
|
3201
|
+
function insertWebkitBackgroundClipText(root) {
|
|
3202
|
+
root.walkDecls("background-clip", (decl) => {
|
|
3203
|
+
if (decl.value.trim().toLowerCase() !== "text") return;
|
|
3204
|
+
const parent = decl.parent;
|
|
3205
|
+
if (!parent || !("nodes" in parent)) return;
|
|
3206
|
+
if (!parent.nodes.some((node) => {
|
|
3207
|
+
return node.type === "decl" && node.prop.toLowerCase() === "-webkit-background-clip" && node.value.trim().toLowerCase() === "text";
|
|
3208
|
+
})) decl.cloneBefore({ prop: "-webkit-background-clip" });
|
|
3209
|
+
});
|
|
3210
|
+
}
|
|
2993
3211
|
function transformCssNesting(root) {
|
|
2994
3212
|
(0, postcss.default)([(0, postcss_preset_env.default)({
|
|
2995
3213
|
stage: false,
|
|
@@ -2999,7 +3217,7 @@ function transformCssNesting(root) {
|
|
|
2999
3217
|
}
|
|
3000
3218
|
function transformWebCssCompat(css, options) {
|
|
3001
3219
|
const normalized = normalizeWebCssCompatOptions(options);
|
|
3002
|
-
if (!isWebCssCompatEnabled(normalized)) return css;
|
|
3220
|
+
if (!isWebCssCompatEnabled(normalized) && normalized.preset !== "legacy-web") return css;
|
|
3003
3221
|
try {
|
|
3004
3222
|
const root = postcss.default.parse(css);
|
|
3005
3223
|
if (normalized.features.theme) unwrapThemeAtRules(root);
|
|
@@ -3013,6 +3231,7 @@ function transformWebCssCompat(css, options) {
|
|
|
3013
3231
|
normalizeTailwindcssV4GradientPositionDeclarations(root);
|
|
3014
3232
|
normalizeTailwindcssV4InfinityCalcDeclarations(root);
|
|
3015
3233
|
normalizeModernColorDeclarations(root, normalized.features);
|
|
3234
|
+
if (normalized.preset === "legacy-web") insertWebkitBackgroundClipText(root);
|
|
3016
3235
|
if (normalized.features.layer) removeUnsupportedCascadeLayers(root);
|
|
3017
3236
|
removeEmptyAtRules$2(root);
|
|
3018
3237
|
return root.toString();
|
|
@@ -4275,6 +4494,81 @@ function rewriteLocalCssImportRequestsForOutput(css, options = {}) {
|
|
|
4275
4494
|
}
|
|
4276
4495
|
}
|
|
4277
4496
|
//#endregion
|
|
4497
|
+
//#region src/compat/line-comments.ts
|
|
4498
|
+
/**
|
|
4499
|
+
* 将常见预处理器风格的行注释转换为 PostCSS 可解析的块注释。
|
|
4500
|
+
* 避免改写字符串、块注释和未加引号的 URL。
|
|
4501
|
+
*/
|
|
4502
|
+
function normalizeCssLineComments(source) {
|
|
4503
|
+
if (!source.includes("//")) return source;
|
|
4504
|
+
const parts = [];
|
|
4505
|
+
let lastWriteIndex = 0;
|
|
4506
|
+
const syntaxCharacter = /[/"'(]/g;
|
|
4507
|
+
for (let match = syntaxCharacter.exec(source); match; match = syntaxCharacter.exec(source)) {
|
|
4508
|
+
const index = match.index;
|
|
4509
|
+
const char = match[0];
|
|
4510
|
+
const next = source[index + 1];
|
|
4511
|
+
if (char === "/" && next === "*" && !isEscaped(source, index)) {
|
|
4512
|
+
const commentEnd = source.indexOf("*/", index + 2);
|
|
4513
|
+
syntaxCharacter.lastIndex = commentEnd === -1 ? source.length : commentEnd + 2;
|
|
4514
|
+
continue;
|
|
4515
|
+
}
|
|
4516
|
+
if ((char === "\"" || char === "'") && !isEscaped(source, index)) {
|
|
4517
|
+
const quoteEnd = findUnescapedCharacter(source, char, index + 1);
|
|
4518
|
+
syntaxCharacter.lastIndex = quoteEnd === -1 ? source.length : quoteEnd + 1;
|
|
4519
|
+
continue;
|
|
4520
|
+
}
|
|
4521
|
+
if (char === "(" && isUrlFunctionStart(source, index)) {
|
|
4522
|
+
let valueStart = index + 1;
|
|
4523
|
+
while (valueStart < source.length && /\s/.test(source[valueStart] ?? "")) valueStart++;
|
|
4524
|
+
const valueStartChar = source[valueStart];
|
|
4525
|
+
if (valueStartChar !== "\"" && valueStartChar !== "'") {
|
|
4526
|
+
const urlEnd = findUnescapedCharacter(source, ")", valueStart);
|
|
4527
|
+
syntaxCharacter.lastIndex = urlEnd === -1 ? source.length : urlEnd + 1;
|
|
4528
|
+
}
|
|
4529
|
+
continue;
|
|
4530
|
+
}
|
|
4531
|
+
if (char === "/" && next === "/" && !isEscaped(source, index)) {
|
|
4532
|
+
let lineStart = index - 1;
|
|
4533
|
+
while (lineStart >= 0 && source[lineStart] !== "\n" && source[lineStart] !== "\r") lineStart--;
|
|
4534
|
+
const linePrefix = source.slice(lineStart + 1, index);
|
|
4535
|
+
const trimmedLinePrefix = linePrefix.trimEnd();
|
|
4536
|
+
const needsSemicolon = trimmedLinePrefix.length > 0 && !/[;{}]$/.test(trimmedLinePrefix);
|
|
4537
|
+
let unchangedPrefix = source.slice(lastWriteIndex, index);
|
|
4538
|
+
if (needsSemicolon) {
|
|
4539
|
+
const trailingWhitespaceLength = linePrefix.length - trimmedLinePrefix.length;
|
|
4540
|
+
const insertionIndex = unchangedPrefix.length - trailingWhitespaceLength;
|
|
4541
|
+
unchangedPrefix = `${unchangedPrefix.slice(0, insertionIndex)};${unchangedPrefix.slice(insertionIndex)}`;
|
|
4542
|
+
}
|
|
4543
|
+
let lineEnd = index + 2;
|
|
4544
|
+
while (lineEnd < source.length && source[lineEnd] !== "\n" && source[lineEnd] !== "\r") lineEnd++;
|
|
4545
|
+
parts.push(unchangedPrefix, "/*", source.slice(index + 2, lineEnd), "*/");
|
|
4546
|
+
lastWriteIndex = lineEnd;
|
|
4547
|
+
syntaxCharacter.lastIndex = lineEnd;
|
|
4548
|
+
continue;
|
|
4549
|
+
}
|
|
4550
|
+
}
|
|
4551
|
+
if (parts.length === 0) return source;
|
|
4552
|
+
parts.push(source.slice(lastWriteIndex));
|
|
4553
|
+
return parts.join("");
|
|
4554
|
+
}
|
|
4555
|
+
function isEscaped(source, index) {
|
|
4556
|
+
let backslashCount = 0;
|
|
4557
|
+
for (let cursor = index - 1; cursor >= 0 && source[cursor] === "\\"; cursor--) backslashCount++;
|
|
4558
|
+
return backslashCount % 2 === 1;
|
|
4559
|
+
}
|
|
4560
|
+
function findUnescapedCharacter(source, character, fromIndex) {
|
|
4561
|
+
let index = source.indexOf(character, fromIndex);
|
|
4562
|
+
while (index !== -1 && isEscaped(source, index)) index = source.indexOf(character, index + 1);
|
|
4563
|
+
return index;
|
|
4564
|
+
}
|
|
4565
|
+
function isUrlFunctionStart(source, index) {
|
|
4566
|
+
if (isEscaped(source, index) || index < 3) return false;
|
|
4567
|
+
const prefix = source.slice(index - 3, index);
|
|
4568
|
+
const beforePrefix = source[index - 4];
|
|
4569
|
+
return prefix.toLowerCase() === "url" && (beforePrefix === void 0 || !/\w/.test(beforePrefix));
|
|
4570
|
+
}
|
|
4571
|
+
//#endregion
|
|
4278
4572
|
//#region src/content-probe.ts
|
|
4279
4573
|
/**
|
|
4280
4574
|
* 所有标志均为 false 的空信号
|
|
@@ -6459,14 +6753,15 @@ function createStyleHandler(options) {
|
|
|
6459
6753
|
}
|
|
6460
6754
|
function processSource(rawSource, root, cloneOutput, opt) {
|
|
6461
6755
|
const resolvedOptions = resolver.resolve(opt);
|
|
6756
|
+
const normalizedRawSource = normalizeCssLineComments(rawSource);
|
|
6462
6757
|
const isUniAppXFramework = resolvedOptions.appType === "uni-app-x";
|
|
6463
|
-
const protectedVarFallbacks = resolvedOptions.uniAppX || isUniAppXFramework ? protectDynamicVarFallbacks(
|
|
6464
|
-
css:
|
|
6758
|
+
const protectedVarFallbacks = resolvedOptions.uniAppX || isUniAppXFramework ? protectDynamicVarFallbacks(normalizedRawSource) : {
|
|
6759
|
+
css: normalizedRawSource,
|
|
6465
6760
|
restore: (value) => value
|
|
6466
6761
|
};
|
|
6467
6762
|
const protectedColorMix = resolvedOptions.majorVersion === 4 ? protectDynamicColorMixAlpha(protectedVarFallbacks.css) : void 0;
|
|
6468
6763
|
const source = protectedColorMix?.css ?? protectedVarFallbacks.css;
|
|
6469
|
-
const processInput = source !==
|
|
6764
|
+
const processInput = source !== normalizedRawSource ? source : root?.clone() ?? source;
|
|
6470
6765
|
let signal;
|
|
6471
6766
|
if (!hasUserPlugins) try {
|
|
6472
6767
|
signal = probeFeatures(source);
|
|
@@ -6493,7 +6788,7 @@ function createStyleHandler(options) {
|
|
|
6493
6788
|
finalResult = nextResult;
|
|
6494
6789
|
}
|
|
6495
6790
|
}
|
|
6496
|
-
if (protectedColorMix || protectedVarFallbacks.css !==
|
|
6791
|
+
if (protectedColorMix || protectedVarFallbacks.css !== normalizedRawSource) {
|
|
6497
6792
|
const restoredCss = protectedVarFallbacks.restore(protectedColorMix?.restore(finalResult.css) ?? finalResult.css);
|
|
6498
6793
|
if (restoredCss !== finalResult.css) {
|
|
6499
6794
|
const nextResult = finalResult.root.clone().toResult(finalResult.opts);
|
package/dist/index.js
CHANGED
|
@@ -801,6 +801,200 @@ function isTailwindcssV4DisplayP3Declaration(decl) {
|
|
|
801
801
|
return DISPLAY_P3_VALUE_RE$1.test(decl.value);
|
|
802
802
|
}
|
|
803
803
|
//#endregion
|
|
804
|
+
//#region src/compat/uni-app-x-uvue/scoped-style.ts
|
|
805
|
+
const MINI_PROGRAM_PREFLIGHT_SELECTORS$1 = /* @__PURE__ */ new Set([
|
|
806
|
+
"view",
|
|
807
|
+
"text",
|
|
808
|
+
"::after",
|
|
809
|
+
"::before"
|
|
810
|
+
]);
|
|
811
|
+
const SCOPED_UNIVERSAL_PREFLIGHT_SELECTORS = /* @__PURE__ */ new Set([
|
|
812
|
+
"*",
|
|
813
|
+
"::after",
|
|
814
|
+
"::before",
|
|
815
|
+
"::backdrop",
|
|
816
|
+
"::file-selector-button"
|
|
817
|
+
]);
|
|
818
|
+
const TAILWIND_VERSION_COMMENT_RE = /tailwindcss v\d/i;
|
|
819
|
+
const VUE_SCOPED_ATTR_RE = /\[data-v-[^\]]+\]/gi;
|
|
820
|
+
const VUE_SCOPED_CLASS_RE = /\.data-v-[\w-]+/gi;
|
|
821
|
+
const TAILWIND_PREFLIGHT_DECLARATIONS = /* @__PURE__ */ new Set([
|
|
822
|
+
"-moz-tab-size:4",
|
|
823
|
+
"-webkit-appearance:none",
|
|
824
|
+
"-webkit-appearance:button",
|
|
825
|
+
"-webkit-tap-highlight-color:transparent",
|
|
826
|
+
"-webkit-text-decoration:inherit",
|
|
827
|
+
"-webkit-text-decoration:underline dotted",
|
|
828
|
+
"-webkit-text-size-adjust:100%",
|
|
829
|
+
"-o-tab-size:4",
|
|
830
|
+
"appearance:button",
|
|
831
|
+
"background-color:transparent",
|
|
832
|
+
"border-collapse:collapse",
|
|
833
|
+
"border-color:inherit",
|
|
834
|
+
"border-radius:0",
|
|
835
|
+
"border-top-width:1px",
|
|
836
|
+
"bottom:-.25em",
|
|
837
|
+
"color:inherit",
|
|
838
|
+
"display:block",
|
|
839
|
+
"display:inline-flex",
|
|
840
|
+
"display:list-item",
|
|
841
|
+
"font:inherit",
|
|
842
|
+
"font-family:inherit",
|
|
843
|
+
"font-feature-settings:inherit",
|
|
844
|
+
"font-size:1em",
|
|
845
|
+
"font-size:75%",
|
|
846
|
+
"font-size:80%",
|
|
847
|
+
"font-size:inherit",
|
|
848
|
+
"font-variation-settings:inherit",
|
|
849
|
+
"font-weight:bolder",
|
|
850
|
+
"font-weight:inherit",
|
|
851
|
+
"height:0",
|
|
852
|
+
"height:auto",
|
|
853
|
+
"letter-spacing:inherit",
|
|
854
|
+
"line-height:1",
|
|
855
|
+
"line-height:1.5",
|
|
856
|
+
"line-height:0",
|
|
857
|
+
"line-height:inherit",
|
|
858
|
+
"list-style:none",
|
|
859
|
+
"margin-inline-end:4px",
|
|
860
|
+
"max-width:100%",
|
|
861
|
+
"min-height:1lh",
|
|
862
|
+
"opacity:1",
|
|
863
|
+
"outline:auto",
|
|
864
|
+
"padding:0",
|
|
865
|
+
"padding-block:0",
|
|
866
|
+
"position:relative",
|
|
867
|
+
"resize:vertical",
|
|
868
|
+
"tab-size:4",
|
|
869
|
+
"text-align:inherit",
|
|
870
|
+
"text-decoration:inherit",
|
|
871
|
+
"text-decoration:underline dotted",
|
|
872
|
+
"text-indent:0",
|
|
873
|
+
"text-transform:none",
|
|
874
|
+
"top:-.5em",
|
|
875
|
+
"vertical-align:baseline",
|
|
876
|
+
"vertical-align:middle"
|
|
877
|
+
]);
|
|
878
|
+
function hasVueScopedAttr(value) {
|
|
879
|
+
VUE_SCOPED_ATTR_RE.lastIndex = 0;
|
|
880
|
+
VUE_SCOPED_CLASS_RE.lastIndex = 0;
|
|
881
|
+
const matched = VUE_SCOPED_ATTR_RE.test(value) || VUE_SCOPED_CLASS_RE.test(value);
|
|
882
|
+
VUE_SCOPED_ATTR_RE.lastIndex = 0;
|
|
883
|
+
VUE_SCOPED_CLASS_RE.lastIndex = 0;
|
|
884
|
+
return matched;
|
|
885
|
+
}
|
|
886
|
+
function normalizeCssSignatureValue(value) {
|
|
887
|
+
return value.replace(VUE_SCOPED_ATTR_RE, "").replace(VUE_SCOPED_CLASS_RE, "").replace(/\s+/g, " ").replace(/\s*([>+~])\s*/g, "$1").replace(/\(\s+/g, "(").replace(/\s+\)/g, ")").trim();
|
|
888
|
+
}
|
|
889
|
+
function isSfcStyleRequestSource(source) {
|
|
890
|
+
if (typeof source !== "string") return false;
|
|
891
|
+
const queryIndex = source.indexOf("?");
|
|
892
|
+
if (queryIndex < 0 || !source.slice(0, queryIndex).toLowerCase().endsWith(".uvue")) return false;
|
|
893
|
+
const hashIndex = source.indexOf("#", queryIndex);
|
|
894
|
+
const query = source.slice(queryIndex + 1, hashIndex < 0 ? void 0 : hashIndex);
|
|
895
|
+
return new URLSearchParams(query).get("type") === "style";
|
|
896
|
+
}
|
|
897
|
+
function isUvueSfcStyleRequest(result) {
|
|
898
|
+
if (isSfcStyleRequestSource(result.opts.from)) return true;
|
|
899
|
+
if ((result.root.nodes ?? []).some((node) => isSfcStyleRequestSource(node.source?.input.from))) return true;
|
|
900
|
+
let hasScopedSelector = false;
|
|
901
|
+
result.root.walkRules((rule) => {
|
|
902
|
+
if ((rule.selectors ?? [rule.selector]).some(hasVueScopedAttr)) {
|
|
903
|
+
hasScopedSelector = true;
|
|
904
|
+
return false;
|
|
905
|
+
}
|
|
906
|
+
});
|
|
907
|
+
return hasScopedSelector;
|
|
908
|
+
}
|
|
909
|
+
function getDeclarations(rule) {
|
|
910
|
+
return rule.nodes?.filter((node) => node.type === "decl") ?? [];
|
|
911
|
+
}
|
|
912
|
+
function isLikelyTailwindGlobalSelector(selector) {
|
|
913
|
+
const normalized = normalizeCssSignatureValue(selector);
|
|
914
|
+
return normalized === "*" || normalized.startsWith("::") || normalized.startsWith(":root") || normalized.startsWith(":host") || /^(?:html|body|hr|abbr|h1|h2|h3|h4|h5|h6|a|b|strong|code|kbd|samp|pre|small|sub|sup|table|button|input|select|optgroup|textarea|summary|blockquote|dl|dd|fieldset|legend|ol|ul|menu|dialog|progress|video|audio|canvas|embed|iframe|img|object|svg|details|template|[uo]ni-progress)(?:$|[:,[\s>+~.#])/.test(normalized);
|
|
915
|
+
}
|
|
916
|
+
function isTailwindPreflightDeclaration(decl) {
|
|
917
|
+
const prop = decl.prop.trim().toLowerCase();
|
|
918
|
+
const value = normalizeCssSignatureValue(decl.value.trim().toLowerCase());
|
|
919
|
+
if (prop.startsWith("--tw-")) return true;
|
|
920
|
+
if (prop === "color" && value.startsWith("color-mix(") && value.includes("currentcolor") && value.includes("transparent")) return true;
|
|
921
|
+
if (prop === "color" && value === "currentcolor") return true;
|
|
922
|
+
if (prop === "font-family" && value.startsWith("var(--default-font-family") || prop === "font-feature-settings" && value.startsWith("var(--default-font-feature-settings") || prop === "font-variation-settings" && value.startsWith("var(--default-font-variation-settings")) return true;
|
|
923
|
+
return TAILWIND_PREFLIGHT_DECLARATIONS.has(`${prop}:${value}`);
|
|
924
|
+
}
|
|
925
|
+
function hasTailwindSourceEvidence(declarations, hasTailwindBanner) {
|
|
926
|
+
return hasTailwindBanner || declarations.some((decl) => decl.prop.startsWith("--tw-"));
|
|
927
|
+
}
|
|
928
|
+
function isScopedTailwindThemeCarrierRule(rule, hasTailwindBanner) {
|
|
929
|
+
const selectors = rule.selectors ?? [rule.selector];
|
|
930
|
+
const declarations = getDeclarations(rule);
|
|
931
|
+
return selectors.length > 0 && selectors.every((selector) => {
|
|
932
|
+
const normalized = normalizeCssSignatureValue(selector);
|
|
933
|
+
return hasVueScopedAttr(selector) && (normalized.startsWith(":root") || normalized.startsWith(":host"));
|
|
934
|
+
}) && declarations.length > 0 && declarations.every((decl) => decl.prop.startsWith("--")) && hasTailwindSourceEvidence(declarations, hasTailwindBanner);
|
|
935
|
+
}
|
|
936
|
+
function isScopedUniversalTailwindPreflightRule(rule, hasTailwindBanner) {
|
|
937
|
+
const selectors = rule.selectors ?? [rule.selector];
|
|
938
|
+
const declarations = getDeclarations(rule);
|
|
939
|
+
return selectors.length > 0 && selectors.every((selector) => hasVueScopedAttr(selector) && SCOPED_UNIVERSAL_PREFLIGHT_SELECTORS.has(normalizeCssSignatureValue(selector))) && declarations.length > 0 && declarations.every((decl) => decl.prop.startsWith("--tw-") || [
|
|
940
|
+
"box-sizing",
|
|
941
|
+
"margin",
|
|
942
|
+
"padding",
|
|
943
|
+
"border"
|
|
944
|
+
].includes(decl.prop)) && hasTailwindSourceEvidence(declarations, hasTailwindBanner);
|
|
945
|
+
}
|
|
946
|
+
function isScopedTailwindElementPreflightRule(rule, hasTailwindBanner) {
|
|
947
|
+
if (!hasTailwindBanner) return false;
|
|
948
|
+
const selectors = rule.selectors ?? [rule.selector];
|
|
949
|
+
const declarations = getDeclarations(rule);
|
|
950
|
+
return selectors.length > 0 && selectors.every((selector) => hasVueScopedAttr(selector) && isLikelyTailwindGlobalSelector(selector)) && declarations.length > 0 && declarations.every(isTailwindPreflightDeclaration);
|
|
951
|
+
}
|
|
952
|
+
function isUnscopedMiniProgramTailwindPreflightRule(rule, hasTailwindBanner) {
|
|
953
|
+
const selectors = rule.selectors ?? [rule.selector];
|
|
954
|
+
if (selectors.length === 0 || !selectors.every((selector) => {
|
|
955
|
+
const normalized = normalizeCssSignatureValue(selector);
|
|
956
|
+
return !hasVueScopedAttr(selector) && MINI_PROGRAM_PREFLIGHT_SELECTORS$1.has(normalized);
|
|
957
|
+
})) return false;
|
|
958
|
+
const declarations = getDeclarations(rule);
|
|
959
|
+
return declarations.length > 0 && declarations.every((decl) => decl.prop.startsWith("--tw-") || [
|
|
960
|
+
"box-sizing",
|
|
961
|
+
"margin",
|
|
962
|
+
"padding",
|
|
963
|
+
"border"
|
|
964
|
+
].includes(decl.prop)) && hasTailwindSourceEvidence(declarations, hasTailwindBanner);
|
|
965
|
+
}
|
|
966
|
+
function isScopedMiniProgramTailwindContentInitRule(rule) {
|
|
967
|
+
const selectors = rule.selectors ?? [rule.selector];
|
|
968
|
+
if (selectors.length === 0 || !selectors.every((selector) => {
|
|
969
|
+
const normalized = normalizeCssSignatureValue(selector);
|
|
970
|
+
return hasVueScopedAttr(selector) && MINI_PROGRAM_PREFLIGHT_SELECTORS$1.has(normalized);
|
|
971
|
+
})) return false;
|
|
972
|
+
const declarations = getDeclarations(rule);
|
|
973
|
+
return declarations.length > 0 && declarations.every((decl) => decl.prop === "--tw-content");
|
|
974
|
+
}
|
|
975
|
+
function isLikelyTailwindPropertyAtRule(atRule) {
|
|
976
|
+
return typeof atRule.name === "string" && atRule.name.toLowerCase() === "property" && normalizeCssSignatureValue(atRule.params).startsWith("--tw-");
|
|
977
|
+
}
|
|
978
|
+
function stripScopedTailwindNoise(root) {
|
|
979
|
+
let hasTailwindBanner = false;
|
|
980
|
+
root.walkComments((comment) => {
|
|
981
|
+
if (TAILWIND_VERSION_COMMENT_RE.test(comment.text)) hasTailwindBanner = true;
|
|
982
|
+
});
|
|
983
|
+
root.walkComments((comment) => {
|
|
984
|
+
if (TAILWIND_VERSION_COMMENT_RE.test(comment.text)) comment.remove();
|
|
985
|
+
});
|
|
986
|
+
root.walkRules((rule) => {
|
|
987
|
+
if (isScopedTailwindThemeCarrierRule(rule, hasTailwindBanner) || isScopedUniversalTailwindPreflightRule(rule, hasTailwindBanner) || isScopedTailwindElementPreflightRule(rule, hasTailwindBanner) || isUnscopedMiniProgramTailwindPreflightRule(rule, hasTailwindBanner) || isScopedMiniProgramTailwindContentInitRule(rule)) rule.remove();
|
|
988
|
+
});
|
|
989
|
+
root.walkAtRules((atRule) => {
|
|
990
|
+
if (isLikelyTailwindPropertyAtRule(atRule)) {
|
|
991
|
+
atRule.remove();
|
|
992
|
+
return;
|
|
993
|
+
}
|
|
994
|
+
if ((atRule.nodes?.length ?? 0) === 0) atRule.remove();
|
|
995
|
+
});
|
|
996
|
+
}
|
|
997
|
+
//#endregion
|
|
804
998
|
//#region src/compat/uni-app-x-uvue/theme.ts
|
|
805
999
|
const SYSTEM_ROOT_SELECTORS = /* @__PURE__ */ new Set([
|
|
806
1000
|
":host",
|
|
@@ -998,6 +1192,7 @@ function applyUniAppXUvueCompatibility(result, options) {
|
|
|
998
1192
|
if (!isUniAppXUvueTarget(options)) return result;
|
|
999
1193
|
const mode = normalizeUnsupportedMode(options?.uniAppXUnsupported);
|
|
1000
1194
|
const warningCache = /* @__PURE__ */ new Set();
|
|
1195
|
+
const sfcStyleRequest = options?.isMainChunk !== true && isUvueSfcStyleRequest(result);
|
|
1001
1196
|
let root = result.root;
|
|
1002
1197
|
let calcMessages = [];
|
|
1003
1198
|
consumeUniAppXSystemRootTheme(root, options?.customPropertyValues);
|
|
@@ -1010,6 +1205,13 @@ function applyUniAppXUvueCompatibility(result, options) {
|
|
|
1010
1205
|
root = calcResult.root;
|
|
1011
1206
|
calcMessages = calcResult.messages;
|
|
1012
1207
|
}
|
|
1208
|
+
if (sfcStyleRequest) {
|
|
1209
|
+
stripScopedTailwindNoise(root);
|
|
1210
|
+
const nextResult = root.toResult(result.opts);
|
|
1211
|
+
nextResult.messages.push(...result.messages);
|
|
1212
|
+
nextResult.messages.push(...calcMessages);
|
|
1213
|
+
return nextResult;
|
|
1214
|
+
}
|
|
1013
1215
|
root.walkRules((rule) => {
|
|
1014
1216
|
if (!hasOnlyClassSelectors(rule)) {
|
|
1015
1217
|
reportUnsupportedRule(rule, result, mode, warningCache, "selector must be class-only");
|
|
@@ -2331,6 +2533,11 @@ function removeDeclarationAndEmptyRule$1(decl) {
|
|
|
2331
2533
|
removeEmptyAtRuleAncestors(ruleParent);
|
|
2332
2534
|
}
|
|
2333
2535
|
}
|
|
2536
|
+
function removeEmptyStandardPropertyFallbacks(root) {
|
|
2537
|
+
root.walkDecls((decl) => {
|
|
2538
|
+
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);
|
|
2539
|
+
});
|
|
2540
|
+
}
|
|
2334
2541
|
function removeDisplayP3Declarations(root) {
|
|
2335
2542
|
root.walkAtRules((atRule) => {
|
|
2336
2543
|
if (isDisplayP3MediaRule(atRule)) {
|
|
@@ -2428,6 +2635,7 @@ function finalizeMiniProgramCssRoot(root, options = {}) {
|
|
|
2428
2635
|
removeRootSpecificityPlaceholders(root);
|
|
2429
2636
|
removeUnsupportedBrowserSelectors(root);
|
|
2430
2637
|
removeDisplayP3Declarations(root);
|
|
2638
|
+
removeEmptyStandardPropertyFallbacks(root);
|
|
2431
2639
|
removeTailwindContainerMaxWidthMediaRules(root);
|
|
2432
2640
|
removeTailwindContainerWidthRules(root, { generatedOnly: true });
|
|
2433
2641
|
removeUnsupportedModernColorDeclarations(root);
|
|
@@ -2975,6 +3183,16 @@ function removeEmptyAtRules$2(root) {
|
|
|
2975
3183
|
if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
|
|
2976
3184
|
});
|
|
2977
3185
|
}
|
|
3186
|
+
function insertWebkitBackgroundClipText(root) {
|
|
3187
|
+
root.walkDecls("background-clip", (decl) => {
|
|
3188
|
+
if (decl.value.trim().toLowerCase() !== "text") return;
|
|
3189
|
+
const parent = decl.parent;
|
|
3190
|
+
if (!parent || !("nodes" in parent)) return;
|
|
3191
|
+
if (!parent.nodes.some((node) => {
|
|
3192
|
+
return node.type === "decl" && node.prop.toLowerCase() === "-webkit-background-clip" && node.value.trim().toLowerCase() === "text";
|
|
3193
|
+
})) decl.cloneBefore({ prop: "-webkit-background-clip" });
|
|
3194
|
+
});
|
|
3195
|
+
}
|
|
2978
3196
|
function transformCssNesting(root) {
|
|
2979
3197
|
postcss$1([postcssPresetEnv({
|
|
2980
3198
|
stage: false,
|
|
@@ -2984,7 +3202,7 @@ function transformCssNesting(root) {
|
|
|
2984
3202
|
}
|
|
2985
3203
|
function transformWebCssCompat(css, options) {
|
|
2986
3204
|
const normalized = normalizeWebCssCompatOptions(options);
|
|
2987
|
-
if (!isWebCssCompatEnabled(normalized)) return css;
|
|
3205
|
+
if (!isWebCssCompatEnabled(normalized) && normalized.preset !== "legacy-web") return css;
|
|
2988
3206
|
try {
|
|
2989
3207
|
const root = postcss$1.parse(css);
|
|
2990
3208
|
if (normalized.features.theme) unwrapThemeAtRules(root);
|
|
@@ -2998,6 +3216,7 @@ function transformWebCssCompat(css, options) {
|
|
|
2998
3216
|
normalizeTailwindcssV4GradientPositionDeclarations(root);
|
|
2999
3217
|
normalizeTailwindcssV4InfinityCalcDeclarations(root);
|
|
3000
3218
|
normalizeModernColorDeclarations(root, normalized.features);
|
|
3219
|
+
if (normalized.preset === "legacy-web") insertWebkitBackgroundClipText(root);
|
|
3001
3220
|
if (normalized.features.layer) removeUnsupportedCascadeLayers(root);
|
|
3002
3221
|
removeEmptyAtRules$2(root);
|
|
3003
3222
|
return root.toString();
|
|
@@ -4260,6 +4479,81 @@ function rewriteLocalCssImportRequestsForOutput(css, options = {}) {
|
|
|
4260
4479
|
}
|
|
4261
4480
|
}
|
|
4262
4481
|
//#endregion
|
|
4482
|
+
//#region src/compat/line-comments.ts
|
|
4483
|
+
/**
|
|
4484
|
+
* 将常见预处理器风格的行注释转换为 PostCSS 可解析的块注释。
|
|
4485
|
+
* 避免改写字符串、块注释和未加引号的 URL。
|
|
4486
|
+
*/
|
|
4487
|
+
function normalizeCssLineComments(source) {
|
|
4488
|
+
if (!source.includes("//")) return source;
|
|
4489
|
+
const parts = [];
|
|
4490
|
+
let lastWriteIndex = 0;
|
|
4491
|
+
const syntaxCharacter = /[/"'(]/g;
|
|
4492
|
+
for (let match = syntaxCharacter.exec(source); match; match = syntaxCharacter.exec(source)) {
|
|
4493
|
+
const index = match.index;
|
|
4494
|
+
const char = match[0];
|
|
4495
|
+
const next = source[index + 1];
|
|
4496
|
+
if (char === "/" && next === "*" && !isEscaped(source, index)) {
|
|
4497
|
+
const commentEnd = source.indexOf("*/", index + 2);
|
|
4498
|
+
syntaxCharacter.lastIndex = commentEnd === -1 ? source.length : commentEnd + 2;
|
|
4499
|
+
continue;
|
|
4500
|
+
}
|
|
4501
|
+
if ((char === "\"" || char === "'") && !isEscaped(source, index)) {
|
|
4502
|
+
const quoteEnd = findUnescapedCharacter(source, char, index + 1);
|
|
4503
|
+
syntaxCharacter.lastIndex = quoteEnd === -1 ? source.length : quoteEnd + 1;
|
|
4504
|
+
continue;
|
|
4505
|
+
}
|
|
4506
|
+
if (char === "(" && isUrlFunctionStart(source, index)) {
|
|
4507
|
+
let valueStart = index + 1;
|
|
4508
|
+
while (valueStart < source.length && /\s/.test(source[valueStart] ?? "")) valueStart++;
|
|
4509
|
+
const valueStartChar = source[valueStart];
|
|
4510
|
+
if (valueStartChar !== "\"" && valueStartChar !== "'") {
|
|
4511
|
+
const urlEnd = findUnescapedCharacter(source, ")", valueStart);
|
|
4512
|
+
syntaxCharacter.lastIndex = urlEnd === -1 ? source.length : urlEnd + 1;
|
|
4513
|
+
}
|
|
4514
|
+
continue;
|
|
4515
|
+
}
|
|
4516
|
+
if (char === "/" && next === "/" && !isEscaped(source, index)) {
|
|
4517
|
+
let lineStart = index - 1;
|
|
4518
|
+
while (lineStart >= 0 && source[lineStart] !== "\n" && source[lineStart] !== "\r") lineStart--;
|
|
4519
|
+
const linePrefix = source.slice(lineStart + 1, index);
|
|
4520
|
+
const trimmedLinePrefix = linePrefix.trimEnd();
|
|
4521
|
+
const needsSemicolon = trimmedLinePrefix.length > 0 && !/[;{}]$/.test(trimmedLinePrefix);
|
|
4522
|
+
let unchangedPrefix = source.slice(lastWriteIndex, index);
|
|
4523
|
+
if (needsSemicolon) {
|
|
4524
|
+
const trailingWhitespaceLength = linePrefix.length - trimmedLinePrefix.length;
|
|
4525
|
+
const insertionIndex = unchangedPrefix.length - trailingWhitespaceLength;
|
|
4526
|
+
unchangedPrefix = `${unchangedPrefix.slice(0, insertionIndex)};${unchangedPrefix.slice(insertionIndex)}`;
|
|
4527
|
+
}
|
|
4528
|
+
let lineEnd = index + 2;
|
|
4529
|
+
while (lineEnd < source.length && source[lineEnd] !== "\n" && source[lineEnd] !== "\r") lineEnd++;
|
|
4530
|
+
parts.push(unchangedPrefix, "/*", source.slice(index + 2, lineEnd), "*/");
|
|
4531
|
+
lastWriteIndex = lineEnd;
|
|
4532
|
+
syntaxCharacter.lastIndex = lineEnd;
|
|
4533
|
+
continue;
|
|
4534
|
+
}
|
|
4535
|
+
}
|
|
4536
|
+
if (parts.length === 0) return source;
|
|
4537
|
+
parts.push(source.slice(lastWriteIndex));
|
|
4538
|
+
return parts.join("");
|
|
4539
|
+
}
|
|
4540
|
+
function isEscaped(source, index) {
|
|
4541
|
+
let backslashCount = 0;
|
|
4542
|
+
for (let cursor = index - 1; cursor >= 0 && source[cursor] === "\\"; cursor--) backslashCount++;
|
|
4543
|
+
return backslashCount % 2 === 1;
|
|
4544
|
+
}
|
|
4545
|
+
function findUnescapedCharacter(source, character, fromIndex) {
|
|
4546
|
+
let index = source.indexOf(character, fromIndex);
|
|
4547
|
+
while (index !== -1 && isEscaped(source, index)) index = source.indexOf(character, index + 1);
|
|
4548
|
+
return index;
|
|
4549
|
+
}
|
|
4550
|
+
function isUrlFunctionStart(source, index) {
|
|
4551
|
+
if (isEscaped(source, index) || index < 3) return false;
|
|
4552
|
+
const prefix = source.slice(index - 3, index);
|
|
4553
|
+
const beforePrefix = source[index - 4];
|
|
4554
|
+
return prefix.toLowerCase() === "url" && (beforePrefix === void 0 || !/\w/.test(beforePrefix));
|
|
4555
|
+
}
|
|
4556
|
+
//#endregion
|
|
4263
4557
|
//#region src/content-probe.ts
|
|
4264
4558
|
/**
|
|
4265
4559
|
* 所有标志均为 false 的空信号
|
|
@@ -6444,14 +6738,15 @@ function createStyleHandler(options) {
|
|
|
6444
6738
|
}
|
|
6445
6739
|
function processSource(rawSource, root, cloneOutput, opt) {
|
|
6446
6740
|
const resolvedOptions = resolver.resolve(opt);
|
|
6741
|
+
const normalizedRawSource = normalizeCssLineComments(rawSource);
|
|
6447
6742
|
const isUniAppXFramework = resolvedOptions.appType === "uni-app-x";
|
|
6448
|
-
const protectedVarFallbacks = resolvedOptions.uniAppX || isUniAppXFramework ? protectDynamicVarFallbacks(
|
|
6449
|
-
css:
|
|
6743
|
+
const protectedVarFallbacks = resolvedOptions.uniAppX || isUniAppXFramework ? protectDynamicVarFallbacks(normalizedRawSource) : {
|
|
6744
|
+
css: normalizedRawSource,
|
|
6450
6745
|
restore: (value) => value
|
|
6451
6746
|
};
|
|
6452
6747
|
const protectedColorMix = resolvedOptions.majorVersion === 4 ? protectDynamicColorMixAlpha(protectedVarFallbacks.css) : void 0;
|
|
6453
6748
|
const source = protectedColorMix?.css ?? protectedVarFallbacks.css;
|
|
6454
|
-
const processInput = source !==
|
|
6749
|
+
const processInput = source !== normalizedRawSource ? source : root?.clone() ?? source;
|
|
6455
6750
|
let signal;
|
|
6456
6751
|
if (!hasUserPlugins) try {
|
|
6457
6752
|
signal = probeFeatures(source);
|
|
@@ -6478,7 +6773,7 @@ function createStyleHandler(options) {
|
|
|
6478
6773
|
finalResult = nextResult;
|
|
6479
6774
|
}
|
|
6480
6775
|
}
|
|
6481
|
-
if (protectedColorMix || protectedVarFallbacks.css !==
|
|
6776
|
+
if (protectedColorMix || protectedVarFallbacks.css !== normalizedRawSource) {
|
|
6482
6777
|
const restoredCss = protectedVarFallbacks.restore(protectedColorMix?.restore(finalResult.css) ?? finalResult.css);
|
|
6483
6778
|
if (restoredCss !== finalResult.css) {
|
|
6484
6779
|
const nextResult = finalResult.root.clone().toResult(finalResult.opts);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-tailwindcss/postcss",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.2.
|
|
4
|
+
"version": "3.2.5",
|
|
5
5
|
"description": "@weapp-tailwindcss/postcss",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -71,10 +71,10 @@
|
|
|
71
71
|
"@tailwindcss-mangle/engine": "0.2.0",
|
|
72
72
|
"@weapp-core/escape": "~8.0.0",
|
|
73
73
|
"autoprefixer": "^10.5.4",
|
|
74
|
-
"es-toolkit": "^1.
|
|
74
|
+
"es-toolkit": "^1.50.0",
|
|
75
75
|
"lru-cache": "11.5.2",
|
|
76
76
|
"micromatch": "^4.0.8",
|
|
77
|
-
"postcss": "^8.5.
|
|
77
|
+
"postcss": "^8.5.24",
|
|
78
78
|
"postcss-load-config": "^6.0.1",
|
|
79
79
|
"postcss-preset-env": "^11.3.2",
|
|
80
80
|
"postcss-pxtrans": "^1.0.4",
|