@weapp-tailwindcss/postcss 3.3.2 → 3.3.4
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/README.md +4 -0
- package/README.zh-CN.md +4 -0
- package/dist/compat/tailwindcss-v4/infinity-radius.d.ts +2 -0
- package/dist/index.cjs +114 -25
- package/dist/index.d.ts +2 -1
- package/dist/index.js +114 -27
- package/dist/types.d.ts +13 -0
- package/dist/vite-css-rules/containment.d.ts +5 -0
- package/dist/vite-css-rules/structure.d.ts +2 -2
- package/dist/vite-css-rules.d.ts +1 -1
- package/package.json +7 -8
package/README.md
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
This package is the CSS processing core of weapp-tailwindcss. It handles PostCSS AST transforms, selector compatibility, platform differences, and Tailwind output post-processing for mini programs.
|
|
6
6
|
|
|
7
|
+
## Repeated CSS Comparisons
|
|
8
|
+
|
|
9
|
+
For repeated comparisons against one CSS string, `createCssRuleMatcher(baseCss)` provides `contains(css)` and `filter(css)` with reusable, lazy comparison indexes. It preserves the semantics of `containsCssAfterMinify` and `filterExistingCssRules`. Create a new matcher when the base CSS changes; release it after the batch.
|
|
10
|
+
|
|
7
11
|
## Website
|
|
8
12
|
|
|
9
13
|
For setup guides, configuration references, and framework examples, see the [official weapp-tailwindcss documentation](https://tw.weapp.dev).
|
package/README.zh-CN.md
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
这个包是 weapp-tailwindcss 的 CSS 处理核心,负责小程序端的 PostCSS AST 转换、选择器兼容、平台差异处理和 Tailwind 输出后处理。
|
|
6
6
|
|
|
7
|
+
## 批量 CSS 比较
|
|
8
|
+
|
|
9
|
+
对同一份 CSS 连续比较时,`createCssRuleMatcher(baseCss)` 提供 `contains(css)` 和 `filter(css)`,按需构建并复用比较索引,语义与 `containsCssAfterMinify`、`filterExistingCssRules` 相同。主样式变化后应创建新的 matcher,批量比较结束后释放引用。
|
|
10
|
+
|
|
7
11
|
## 官网
|
|
8
12
|
|
|
9
13
|
更多接入方式、配置说明和框架示例见 [weapp-tailwindcss 官方文档](https://tw.weapp.dev)。
|
package/dist/index.cjs
CHANGED
|
@@ -29,11 +29,11 @@ let node_fs_promises = require("node:fs/promises");
|
|
|
29
29
|
let micromatch = require("micromatch");
|
|
30
30
|
micromatch = require_rolldown_runtime.__toESM(micromatch, 1);
|
|
31
31
|
let tailwindcss_config = require("tailwindcss-config");
|
|
32
|
+
let node_perf_hooks = require("node:perf_hooks");
|
|
32
33
|
let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
|
|
33
34
|
let lru_cache = require("lru-cache");
|
|
34
35
|
let autoprefixer = require("autoprefixer");
|
|
35
36
|
autoprefixer = require_rolldown_runtime.__toESM(autoprefixer, 1);
|
|
36
|
-
let es_toolkit = require("es-toolkit");
|
|
37
37
|
let postcss_pxtrans = require("postcss-pxtrans");
|
|
38
38
|
postcss_pxtrans = require_rolldown_runtime.__toESM(postcss_pxtrans, 1);
|
|
39
39
|
let postcss_rem_to_responsive_pixel = require("postcss-rem-to-responsive-pixel");
|
|
@@ -81,10 +81,7 @@ function rewriteApplyParams(params, marker) {
|
|
|
81
81
|
/** 将 Sass 不可直接解析的 important utility 改写成跨预处理器中间形式。 */
|
|
82
82
|
function normalizeUniAppXImportantApplyForSass(css) {
|
|
83
83
|
try {
|
|
84
|
-
const root =
|
|
85
|
-
from: void 0,
|
|
86
|
-
syntax: postcss_scss.default
|
|
87
|
-
});
|
|
84
|
+
const root = postcss_scss.default.parse(css, { from: void 0 });
|
|
88
85
|
let changed = false;
|
|
89
86
|
root.walkAtRules("apply", (rule) => {
|
|
90
87
|
const params = rewriteApplyParams(rule.params, UNI_APP_X_IMPORTANT_APPLY_MARKER);
|
|
@@ -93,7 +90,7 @@ function normalizeUniAppXImportantApplyForSass(css) {
|
|
|
93
90
|
changed = true;
|
|
94
91
|
}
|
|
95
92
|
});
|
|
96
|
-
return changed ? root.toString() : css;
|
|
93
|
+
return changed ? root.toString(postcss_scss.default.stringify) : css;
|
|
97
94
|
} catch {
|
|
98
95
|
return css;
|
|
99
96
|
}
|
|
@@ -521,7 +518,7 @@ function createCssVarNodes(definitions) {
|
|
|
521
518
|
}));
|
|
522
519
|
}
|
|
523
520
|
const CLAMP_PX = 9999;
|
|
524
|
-
const INFINITY_CALC_VALUE_REGEXP = /^calc\(\s*infinity\s*\*\s*(
|
|
521
|
+
const INFINITY_CALC_VALUE_REGEXP = /^calc\(\s*infinity\s*\*\s*(\d+(?:\.\d*)?|\.\d+)r?px\s*\)$/i;
|
|
525
522
|
const MODERN_CHECK_WEBKIT_HYPHENS_RE = /-webkit-hyphens\s*:\s*none/;
|
|
526
523
|
const MODERN_CHECK_MARGIN_TRIM_RE = /margin-trim\s*:\s*inline/;
|
|
527
524
|
const MODERN_CHECK_MOZ_ORIENT_RE = /-moz-orient\s*:\s*inline/;
|
|
@@ -3230,6 +3227,20 @@ function normalizeTailwindcssWebRpxDeclarations(root, options) {
|
|
|
3230
3227
|
return normalized || converted;
|
|
3231
3228
|
}
|
|
3232
3229
|
//#endregion
|
|
3230
|
+
//#region src/compat/tailwindcss-v4/infinity-radius.ts
|
|
3231
|
+
const BORDER_RADIUS_PROPERTY_RE = /^border-(?:radius|(?:top-left|top-right|bottom-left|bottom-right|start-start|start-end|end-start|end-end)-radius)$/i;
|
|
3232
|
+
/** 在下游 PostCSS 解析前,仅将圆角声明中的完整正无限长度收敛为有限值。 */
|
|
3233
|
+
function normalizeTailwindcssV4InfinityRadiusCss(css) {
|
|
3234
|
+
if (!/infinity/i.test(css)) return css;
|
|
3235
|
+
const root = (0, postcss.parse)(css);
|
|
3236
|
+
root.walkDecls((decl) => {
|
|
3237
|
+
if (!BORDER_RADIUS_PROPERTY_RE.test(decl.prop) && decl.prop !== "--radius" && !decl.prop.startsWith("--radius-")) return;
|
|
3238
|
+
const match = INFINITY_CALC_VALUE_REGEXP.exec(decl.value.trim());
|
|
3239
|
+
if (match && Number.parseFloat(match[1]) > 0) decl.value = `${CLAMP_PX}px`;
|
|
3240
|
+
});
|
|
3241
|
+
return root.toString();
|
|
3242
|
+
}
|
|
3243
|
+
//#endregion
|
|
3233
3244
|
//#region src/shared.ts
|
|
3234
3245
|
const escapeOptionsCache = /* @__PURE__ */ new WeakMap();
|
|
3235
3246
|
function getEscapeOptions(escapeMap) {
|
|
@@ -5322,8 +5333,20 @@ function getCalcDuplicateCleaner(options) {
|
|
|
5322
5333
|
const EMPTY_CALC_OPTIONS = {};
|
|
5323
5334
|
function getCalcPlugin(options) {
|
|
5324
5335
|
if (!options.cssCalc) return null;
|
|
5325
|
-
if (options.cssCalc === true || Array.isArray(options.cssCalc))
|
|
5326
|
-
|
|
5336
|
+
if (options.cssCalc === true || Array.isArray(options.cssCalc)) {
|
|
5337
|
+
const calcOptions = Array.isArray(options.cssCalc) ? {
|
|
5338
|
+
includeCustomProperties: options.cssCalc,
|
|
5339
|
+
...options.customPropertyValues ? { customPropertyValues: options.customPropertyValues } : {}
|
|
5340
|
+
} : options.customPropertyValues ? {
|
|
5341
|
+
customPropertyValues: options.customPropertyValues,
|
|
5342
|
+
includeCustomProperties: [...options.customPropertyValues.keys()]
|
|
5343
|
+
} : EMPTY_CALC_OPTIONS;
|
|
5344
|
+
return (0, _weapp_tailwindcss_postcss_calc.default)(calcOptions);
|
|
5345
|
+
}
|
|
5346
|
+
return (0, _weapp_tailwindcss_postcss_calc.default)({
|
|
5347
|
+
...options.cssCalc,
|
|
5348
|
+
...options.customPropertyValues ? { customPropertyValues: options.customPropertyValues } : {}
|
|
5349
|
+
});
|
|
5327
5350
|
}
|
|
5328
5351
|
//#endregion
|
|
5329
5352
|
//#region src/plugins/getCustomPropertyCleaner.ts
|
|
@@ -7224,10 +7247,21 @@ function createStyleHandler(options) {
|
|
|
7224
7247
|
}
|
|
7225
7248
|
const cacheKey = `${getOptionsFingerprint(resolvedOptions)}|${signal ? signalToCacheKey(signal) : ""}|${simpleHash(source)}`;
|
|
7226
7249
|
const cachedResult = resultCache.get(cacheKey);
|
|
7227
|
-
if (cachedResult)
|
|
7250
|
+
if (cachedResult) {
|
|
7251
|
+
resolvedOptions.onDiagnostic?.({
|
|
7252
|
+
phase: "postcss",
|
|
7253
|
+
durationMs: 0,
|
|
7254
|
+
cache: {
|
|
7255
|
+
hit: true,
|
|
7256
|
+
key: cacheKey
|
|
7257
|
+
}
|
|
7258
|
+
});
|
|
7259
|
+
return Promise.resolve(cloneOutput ? cloneResult(cachedResult) : cachedResult);
|
|
7260
|
+
}
|
|
7228
7261
|
const processor = processorCache.getProcessor(resolvedOptions, signal);
|
|
7229
7262
|
const processOptions = processorCache.getProcessOptions(resolvedOptions);
|
|
7230
|
-
|
|
7263
|
+
const startedAt = node_perf_hooks.performance.now();
|
|
7264
|
+
return processor.process(processInput, processOptions).async().then(async (result) => {
|
|
7231
7265
|
let finalResult = resolvePostcssFrameworkProfile(resolvedOptions).postprocess(result, resolvedOptions);
|
|
7232
7266
|
if (resolvedOptions.isMainChunk !== false && finalResult.root) {
|
|
7233
7267
|
let removed = 0;
|
|
@@ -7256,7 +7290,29 @@ function createStyleHandler(options) {
|
|
|
7256
7290
|
if (splitUnresolvedAuthorVariableFallbacks(finalResult.root, /* @__PURE__ */ new Map())) finalResult.css = finalResult.root.toString();
|
|
7257
7291
|
}
|
|
7258
7292
|
resultCache.set(cacheKey, finalResult);
|
|
7293
|
+
await resolvedOptions.onDiagnostic?.({
|
|
7294
|
+
phase: "postcss",
|
|
7295
|
+
durationMs: node_perf_hooks.performance.now() - startedAt,
|
|
7296
|
+
cache: {
|
|
7297
|
+
hit: false,
|
|
7298
|
+
key: cacheKey
|
|
7299
|
+
}
|
|
7300
|
+
});
|
|
7259
7301
|
return cloneOutput ? cloneResult(finalResult) : finalResult;
|
|
7302
|
+
}).catch(async (error) => {
|
|
7303
|
+
await resolvedOptions.onDiagnostic?.({
|
|
7304
|
+
phase: "postcss",
|
|
7305
|
+
durationMs: node_perf_hooks.performance.now() - startedAt,
|
|
7306
|
+
cache: {
|
|
7307
|
+
hit: false,
|
|
7308
|
+
key: cacheKey
|
|
7309
|
+
},
|
|
7310
|
+
error: {
|
|
7311
|
+
name: error instanceof Error ? error.name : void 0,
|
|
7312
|
+
message: error instanceof Error ? error.message : String(error)
|
|
7313
|
+
}
|
|
7314
|
+
});
|
|
7315
|
+
throw error;
|
|
7260
7316
|
});
|
|
7261
7317
|
}
|
|
7262
7318
|
const handler = ((rawSource, opt) => {
|
|
@@ -7368,17 +7424,24 @@ function getCssRuleStructuralKey(rule) {
|
|
|
7368
7424
|
function getCssRuleStructuralKeyWithSelectorKey(rule, selectorKey) {
|
|
7369
7425
|
return [...getRuleAtRuleChain(rule), selectorKey].join("|");
|
|
7370
7426
|
}
|
|
7371
|
-
function getCssRuleContentKey(rule) {
|
|
7427
|
+
function getCssRuleContentKey(rule, content = normalizeCssForContainment(rule.toString())) {
|
|
7372
7428
|
const structuralKey = getCssRuleStructuralKey(rule);
|
|
7373
7429
|
if (!structuralKey) return;
|
|
7374
|
-
return [structuralKey,
|
|
7430
|
+
return [structuralKey, content].join("|");
|
|
7375
7431
|
}
|
|
7376
|
-
function collectCssRuleContentKeys(css) {
|
|
7432
|
+
function collectCssRuleContentKeys(css, requiredBaseContent) {
|
|
7377
7433
|
const keys = /* @__PURE__ */ new Set();
|
|
7378
7434
|
try {
|
|
7379
7435
|
postcss.default.parse(css).walkRules((rule) => {
|
|
7380
|
-
const
|
|
7381
|
-
|
|
7436
|
+
const content = normalizeCssForContainment(rule.toString());
|
|
7437
|
+
const key = getCssRuleContentKey(rule, content);
|
|
7438
|
+
if (key) {
|
|
7439
|
+
if (requiredBaseContent !== void 0 && !requiredBaseContent.includes(content)) {
|
|
7440
|
+
keys.clear();
|
|
7441
|
+
return false;
|
|
7442
|
+
}
|
|
7443
|
+
keys.add(key);
|
|
7444
|
+
}
|
|
7382
7445
|
});
|
|
7383
7446
|
} catch {}
|
|
7384
7447
|
return keys;
|
|
@@ -7590,12 +7653,12 @@ function removeEmptyAtRules$1(root) {
|
|
|
7590
7653
|
}
|
|
7591
7654
|
//#endregion
|
|
7592
7655
|
//#region src/vite-css-rules/containment.ts
|
|
7593
|
-
function
|
|
7594
|
-
const baseRuleKeys =
|
|
7656
|
+
function filterCssRules(base, css) {
|
|
7657
|
+
const baseRuleKeys = base.ruleKeys();
|
|
7595
7658
|
if (baseRuleKeys.size === 0) return css;
|
|
7596
7659
|
try {
|
|
7597
7660
|
const root = postcss.default.parse(css);
|
|
7598
|
-
const baseRuleDeclarationKeys =
|
|
7661
|
+
const baseRuleDeclarationKeys = base.declarations();
|
|
7599
7662
|
let changed = false;
|
|
7600
7663
|
root.walkRules((rule) => {
|
|
7601
7664
|
const key = getCssRuleContentKey(rule);
|
|
@@ -7611,16 +7674,40 @@ function filterExistingCssRules(baseCss, css) {
|
|
|
7611
7674
|
return css;
|
|
7612
7675
|
}
|
|
7613
7676
|
}
|
|
7614
|
-
function
|
|
7615
|
-
if (
|
|
7616
|
-
const normalizedBaseCss =
|
|
7677
|
+
function containsCss(base, css) {
|
|
7678
|
+
if (base.css.includes(css)) return true;
|
|
7679
|
+
const normalizedBaseCss = base.normalized();
|
|
7617
7680
|
const normalizedCss = normalizeCssForContainment(css);
|
|
7618
7681
|
if (normalizedCss.length > 0 && normalizedBaseCss.includes(normalizedCss)) return true;
|
|
7619
7682
|
const normalizedNodes = collectNormalizedCssNodes(css);
|
|
7620
7683
|
if (normalizedNodes.length > 0 && normalizedNodes.every((node) => normalizedBaseCss.includes(node))) return true;
|
|
7621
|
-
const
|
|
7622
|
-
|
|
7623
|
-
|
|
7684
|
+
const ruleKeys = collectCssRuleContentKeys(css, normalizedBaseCss);
|
|
7685
|
+
return ruleKeys.size > 0 && [...ruleKeys].every((key) => base.ruleKeys().has(key));
|
|
7686
|
+
}
|
|
7687
|
+
function prepareCssBase(css) {
|
|
7688
|
+
let normalized;
|
|
7689
|
+
let ruleKeys;
|
|
7690
|
+
let declarations;
|
|
7691
|
+
return {
|
|
7692
|
+
css,
|
|
7693
|
+
normalized: () => normalized ??= normalizeCssForContainment(css),
|
|
7694
|
+
ruleKeys: () => ruleKeys ??= collectCssRuleContentKeys(css),
|
|
7695
|
+
declarations: () => declarations ??= collectCssRuleDeclarationKeyMap(css)
|
|
7696
|
+
};
|
|
7697
|
+
}
|
|
7698
|
+
/** 对同一份不可变主样式复用比较索引;调用方在主样式更新后创建新的 matcher。 */
|
|
7699
|
+
function createCssRuleMatcher(baseCss) {
|
|
7700
|
+
const base = prepareCssBase(baseCss);
|
|
7701
|
+
return {
|
|
7702
|
+
contains: (css) => containsCss(base, css),
|
|
7703
|
+
filter: (css) => filterCssRules(base, css)
|
|
7704
|
+
};
|
|
7705
|
+
}
|
|
7706
|
+
function filterExistingCssRules(baseCss, css) {
|
|
7707
|
+
return filterCssRules(prepareCssBase(baseCss), css);
|
|
7708
|
+
}
|
|
7709
|
+
function containsCssAfterMinify(baseCss, css) {
|
|
7710
|
+
return containsCss(prepareCssBase(baseCss), css);
|
|
7624
7711
|
}
|
|
7625
7712
|
//#endregion
|
|
7626
7713
|
//#region src/vite-css-rules/mini-program.ts
|
|
@@ -7786,6 +7873,7 @@ exports.containsCssAfterMinify = containsCssAfterMinify;
|
|
|
7786
7873
|
exports.convertTailwindcssRpxDeclarationToRem = convertTailwindcssRpxDeclarationToRem;
|
|
7787
7874
|
exports.convertTailwindcssRpxDeclarationsToRem = convertTailwindcssRpxDeclarationsToRem;
|
|
7788
7875
|
exports.convertTailwindcssRpxValueToRem = convertTailwindcssRpxValueToRem;
|
|
7876
|
+
exports.createCssRuleMatcher = createCssRuleMatcher;
|
|
7789
7877
|
exports.createCssSourceOrderAppend = createCssSourceOrderAppend;
|
|
7790
7878
|
exports.createFallbackPlaceholderReplacer = createFallbackPlaceholderReplacer;
|
|
7791
7879
|
exports.createInjectPreflight = createInjectPreflight;
|
|
@@ -7836,6 +7924,7 @@ exports.normalizeTailwindCssImportRequest = normalizeTailwindCssImportRequest;
|
|
|
7836
7924
|
exports.normalizeTailwindcssRpxDeclaration = normalizeTailwindcssRpxDeclaration;
|
|
7837
7925
|
exports.normalizeTailwindcssRpxDeclarations = normalizeTailwindcssRpxDeclarations;
|
|
7838
7926
|
exports.normalizeTailwindcssV4InfinityCalcCss = normalizeTailwindcssV4InfinityCalcCss;
|
|
7927
|
+
exports.normalizeTailwindcssV4InfinityRadiusCss = normalizeTailwindcssV4InfinityRadiusCss;
|
|
7839
7928
|
exports.normalizeTailwindcssWebRpxDeclarations = normalizeTailwindcssWebRpxDeclarations;
|
|
7840
7929
|
exports.normalizeUniAppXImportantApplyForSass = normalizeUniAppXImportantApplyForSass;
|
|
7841
7930
|
exports.normalizeWebCssCompatOptions = normalizeWebCssCompatOptions;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export { consumeCascadeLayers, finalizeMiniProgramCss, type FinalizeMiniProgramC
|
|
|
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';
|
|
8
|
+
export { normalizeTailwindcssV4InfinityRadiusCss } from './compat/tailwindcss-v4/infinity-radius.js';
|
|
8
9
|
export { normalizeUniAppXImportantApplyForSass, restoreUniAppXImportantApplyMarker, UNI_APP_X_IMPORTANT_APPLY_MARKER, } from './compat/uni-app-x.js';
|
|
9
10
|
export { type NormalizedWebCssCompatOptions, normalizeWebCssCompatOptions, transformWebCssCompat, transformWebCssSafeSelectors, } from './compat/web-css.js';
|
|
10
11
|
export { compileCssMacroConditionalComments, CSS_MACRO_STYLE_OPTIONS_MARKER, hasCssMacroStyleOptions, hasCssMacroTailwindV4CustomVariantConditionalComments, hasCssMacroTailwindV4Directive, hasCssMacroTailwindV4InternalAtRules, hasCssMacroTailwindV4Source, transformCssMacroCss, transformCssMacroTailwindV4Source, withCssMacroStyleOptions, } from './css-macro/auto.js';
|
|
@@ -28,5 +29,5 @@ export { internalCssSelectorReplacer } from './shared.js';
|
|
|
28
29
|
export { collectCssInlineSourceCandidates, createSourceScanPattern, createTailwindSourceEntryMatcher, expandInlineSourceCandidatePattern, expandTailwindSourceEntries, FULL_SOURCE_SCAN_EXTENSION_RE, FULL_SOURCE_SCAN_EXTENSIONS, FULL_SOURCE_SCAN_PATTERN, isFileExcludedByTailwindSourceEntries, isFileMatchedByTailwindSourceEntries, normalizeLegacyContentEntries, parseConfigParam, parseSourceFileParam, resolveCssSourceEntries, resolveSourceScanPath, resolveTailwindSourceEntry, type TailwindInlineSourceCandidates, type TailwindSourceEntry, toPosixPath, } from './source-scan.js';
|
|
29
30
|
export { createPostcssStyleTargetProfile, type PostcssStyleTarget, type PostcssStyleTargetProfile, } from './style-targets/index.js';
|
|
30
31
|
export * from './types.js';
|
|
31
|
-
export { containsCssAfterMinify, dedupeCoveredCssRules, filterExistingCssRules, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, } from './vite-css-rules.js';
|
|
32
|
+
export { containsCssAfterMinify, createCssRuleMatcher, dedupeCoveredCssRules, filterExistingCssRules, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, } from './vite-css-rules.js';
|
|
32
33
|
export { composeRules as unitConversionComposeRules, presets as unitConversionPresets, } from 'postcss-rule-unit-converter';
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { CSS_MACRO_POSTCSS_PLUGIN_NAME, creator, ifdefAtRule, ifndefAtRule } fro
|
|
|
2
2
|
import postcssHtmlTransform from "./html-transform.js";
|
|
3
3
|
import "./types.js";
|
|
4
4
|
import { extractValidCandidates, resolveProjectSourceFiles, splitCandidateTokens } from "@tailwindcss-mangle/engine";
|
|
5
|
-
import postcss, { Declaration, Rule, rule, default as postcss$1 } from "postcss";
|
|
5
|
+
import postcss, { Declaration, Rule, parse, rule, default as postcss$1 } from "postcss";
|
|
6
6
|
import scssSyntax from "postcss-scss";
|
|
7
7
|
import postcssCalc from "@weapp-tailwindcss/postcss-calc";
|
|
8
8
|
import selectorParser from "postcss-selector-parser";
|
|
@@ -18,10 +18,10 @@ import { realpathSync } from "node:fs";
|
|
|
18
18
|
import { readFile, stat } from "node:fs/promises";
|
|
19
19
|
import micromatch from "micromatch";
|
|
20
20
|
import { loadConfig } from "tailwindcss-config";
|
|
21
|
+
import { performance } from "node:perf_hooks";
|
|
21
22
|
import { defu, defuOverrideArray, regExpTest } from "@weapp-tailwindcss/shared";
|
|
22
23
|
import { LRUCache } from "lru-cache";
|
|
23
24
|
import autoprefixerPlugin from "autoprefixer";
|
|
24
|
-
import { omit } from "es-toolkit";
|
|
25
25
|
import postcssPxtrans from "postcss-pxtrans";
|
|
26
26
|
import postcssRem2rpx from "postcss-rem-to-responsive-pixel";
|
|
27
27
|
import postcssUnitConverter, { composeRules as unitConversionComposeRules, presets, presets as unitConversionPresets } from "postcss-rule-unit-converter";
|
|
@@ -65,10 +65,7 @@ function rewriteApplyParams(params, marker) {
|
|
|
65
65
|
/** 将 Sass 不可直接解析的 important utility 改写成跨预处理器中间形式。 */
|
|
66
66
|
function normalizeUniAppXImportantApplyForSass(css) {
|
|
67
67
|
try {
|
|
68
|
-
const root =
|
|
69
|
-
from: void 0,
|
|
70
|
-
syntax: scssSyntax
|
|
71
|
-
});
|
|
68
|
+
const root = scssSyntax.parse(css, { from: void 0 });
|
|
72
69
|
let changed = false;
|
|
73
70
|
root.walkAtRules("apply", (rule) => {
|
|
74
71
|
const params = rewriteApplyParams(rule.params, UNI_APP_X_IMPORTANT_APPLY_MARKER);
|
|
@@ -77,7 +74,7 @@ function normalizeUniAppXImportantApplyForSass(css) {
|
|
|
77
74
|
changed = true;
|
|
78
75
|
}
|
|
79
76
|
});
|
|
80
|
-
return changed ? root.toString() : css;
|
|
77
|
+
return changed ? root.toString(scssSyntax.stringify) : css;
|
|
81
78
|
} catch {
|
|
82
79
|
return css;
|
|
83
80
|
}
|
|
@@ -505,7 +502,7 @@ function createCssVarNodes(definitions) {
|
|
|
505
502
|
}));
|
|
506
503
|
}
|
|
507
504
|
const CLAMP_PX = 9999;
|
|
508
|
-
const INFINITY_CALC_VALUE_REGEXP = /^calc\(\s*infinity\s*\*\s*(
|
|
505
|
+
const INFINITY_CALC_VALUE_REGEXP = /^calc\(\s*infinity\s*\*\s*(\d+(?:\.\d*)?|\.\d+)r?px\s*\)$/i;
|
|
509
506
|
const MODERN_CHECK_WEBKIT_HYPHENS_RE = /-webkit-hyphens\s*:\s*none/;
|
|
510
507
|
const MODERN_CHECK_MARGIN_TRIM_RE = /margin-trim\s*:\s*inline/;
|
|
511
508
|
const MODERN_CHECK_MOZ_ORIENT_RE = /-moz-orient\s*:\s*inline/;
|
|
@@ -3214,6 +3211,20 @@ function normalizeTailwindcssWebRpxDeclarations(root, options) {
|
|
|
3214
3211
|
return normalized || converted;
|
|
3215
3212
|
}
|
|
3216
3213
|
//#endregion
|
|
3214
|
+
//#region src/compat/tailwindcss-v4/infinity-radius.ts
|
|
3215
|
+
const BORDER_RADIUS_PROPERTY_RE = /^border-(?:radius|(?:top-left|top-right|bottom-left|bottom-right|start-start|start-end|end-start|end-end)-radius)$/i;
|
|
3216
|
+
/** 在下游 PostCSS 解析前,仅将圆角声明中的完整正无限长度收敛为有限值。 */
|
|
3217
|
+
function normalizeTailwindcssV4InfinityRadiusCss(css) {
|
|
3218
|
+
if (!/infinity/i.test(css)) return css;
|
|
3219
|
+
const root = parse(css);
|
|
3220
|
+
root.walkDecls((decl) => {
|
|
3221
|
+
if (!BORDER_RADIUS_PROPERTY_RE.test(decl.prop) && decl.prop !== "--radius" && !decl.prop.startsWith("--radius-")) return;
|
|
3222
|
+
const match = INFINITY_CALC_VALUE_REGEXP.exec(decl.value.trim());
|
|
3223
|
+
if (match && Number.parseFloat(match[1]) > 0) decl.value = `${CLAMP_PX}px`;
|
|
3224
|
+
});
|
|
3225
|
+
return root.toString();
|
|
3226
|
+
}
|
|
3227
|
+
//#endregion
|
|
3217
3228
|
//#region src/shared.ts
|
|
3218
3229
|
const escapeOptionsCache = /* @__PURE__ */ new WeakMap();
|
|
3219
3230
|
function getEscapeOptions(escapeMap) {
|
|
@@ -5306,8 +5317,20 @@ function getCalcDuplicateCleaner(options) {
|
|
|
5306
5317
|
const EMPTY_CALC_OPTIONS = {};
|
|
5307
5318
|
function getCalcPlugin(options) {
|
|
5308
5319
|
if (!options.cssCalc) return null;
|
|
5309
|
-
if (options.cssCalc === true || Array.isArray(options.cssCalc))
|
|
5310
|
-
|
|
5320
|
+
if (options.cssCalc === true || Array.isArray(options.cssCalc)) {
|
|
5321
|
+
const calcOptions = Array.isArray(options.cssCalc) ? {
|
|
5322
|
+
includeCustomProperties: options.cssCalc,
|
|
5323
|
+
...options.customPropertyValues ? { customPropertyValues: options.customPropertyValues } : {}
|
|
5324
|
+
} : options.customPropertyValues ? {
|
|
5325
|
+
customPropertyValues: options.customPropertyValues,
|
|
5326
|
+
includeCustomProperties: [...options.customPropertyValues.keys()]
|
|
5327
|
+
} : EMPTY_CALC_OPTIONS;
|
|
5328
|
+
return postcssCalc(calcOptions);
|
|
5329
|
+
}
|
|
5330
|
+
return postcssCalc({
|
|
5331
|
+
...options.cssCalc,
|
|
5332
|
+
...options.customPropertyValues ? { customPropertyValues: options.customPropertyValues } : {}
|
|
5333
|
+
});
|
|
5311
5334
|
}
|
|
5312
5335
|
//#endregion
|
|
5313
5336
|
//#region src/plugins/getCustomPropertyCleaner.ts
|
|
@@ -7208,10 +7231,21 @@ function createStyleHandler(options) {
|
|
|
7208
7231
|
}
|
|
7209
7232
|
const cacheKey = `${getOptionsFingerprint(resolvedOptions)}|${signal ? signalToCacheKey(signal) : ""}|${simpleHash(source)}`;
|
|
7210
7233
|
const cachedResult = resultCache.get(cacheKey);
|
|
7211
|
-
if (cachedResult)
|
|
7234
|
+
if (cachedResult) {
|
|
7235
|
+
resolvedOptions.onDiagnostic?.({
|
|
7236
|
+
phase: "postcss",
|
|
7237
|
+
durationMs: 0,
|
|
7238
|
+
cache: {
|
|
7239
|
+
hit: true,
|
|
7240
|
+
key: cacheKey
|
|
7241
|
+
}
|
|
7242
|
+
});
|
|
7243
|
+
return Promise.resolve(cloneOutput ? cloneResult(cachedResult) : cachedResult);
|
|
7244
|
+
}
|
|
7212
7245
|
const processor = processorCache.getProcessor(resolvedOptions, signal);
|
|
7213
7246
|
const processOptions = processorCache.getProcessOptions(resolvedOptions);
|
|
7214
|
-
|
|
7247
|
+
const startedAt = performance.now();
|
|
7248
|
+
return processor.process(processInput, processOptions).async().then(async (result) => {
|
|
7215
7249
|
let finalResult = resolvePostcssFrameworkProfile(resolvedOptions).postprocess(result, resolvedOptions);
|
|
7216
7250
|
if (resolvedOptions.isMainChunk !== false && finalResult.root) {
|
|
7217
7251
|
let removed = 0;
|
|
@@ -7240,7 +7274,29 @@ function createStyleHandler(options) {
|
|
|
7240
7274
|
if (splitUnresolvedAuthorVariableFallbacks(finalResult.root, /* @__PURE__ */ new Map())) finalResult.css = finalResult.root.toString();
|
|
7241
7275
|
}
|
|
7242
7276
|
resultCache.set(cacheKey, finalResult);
|
|
7277
|
+
await resolvedOptions.onDiagnostic?.({
|
|
7278
|
+
phase: "postcss",
|
|
7279
|
+
durationMs: performance.now() - startedAt,
|
|
7280
|
+
cache: {
|
|
7281
|
+
hit: false,
|
|
7282
|
+
key: cacheKey
|
|
7283
|
+
}
|
|
7284
|
+
});
|
|
7243
7285
|
return cloneOutput ? cloneResult(finalResult) : finalResult;
|
|
7286
|
+
}).catch(async (error) => {
|
|
7287
|
+
await resolvedOptions.onDiagnostic?.({
|
|
7288
|
+
phase: "postcss",
|
|
7289
|
+
durationMs: performance.now() - startedAt,
|
|
7290
|
+
cache: {
|
|
7291
|
+
hit: false,
|
|
7292
|
+
key: cacheKey
|
|
7293
|
+
},
|
|
7294
|
+
error: {
|
|
7295
|
+
name: error instanceof Error ? error.name : void 0,
|
|
7296
|
+
message: error instanceof Error ? error.message : String(error)
|
|
7297
|
+
}
|
|
7298
|
+
});
|
|
7299
|
+
throw error;
|
|
7244
7300
|
});
|
|
7245
7301
|
}
|
|
7246
7302
|
const handler = ((rawSource, opt) => {
|
|
@@ -7352,17 +7408,24 @@ function getCssRuleStructuralKey(rule) {
|
|
|
7352
7408
|
function getCssRuleStructuralKeyWithSelectorKey(rule, selectorKey) {
|
|
7353
7409
|
return [...getRuleAtRuleChain(rule), selectorKey].join("|");
|
|
7354
7410
|
}
|
|
7355
|
-
function getCssRuleContentKey(rule) {
|
|
7411
|
+
function getCssRuleContentKey(rule, content = normalizeCssForContainment(rule.toString())) {
|
|
7356
7412
|
const structuralKey = getCssRuleStructuralKey(rule);
|
|
7357
7413
|
if (!structuralKey) return;
|
|
7358
|
-
return [structuralKey,
|
|
7414
|
+
return [structuralKey, content].join("|");
|
|
7359
7415
|
}
|
|
7360
|
-
function collectCssRuleContentKeys(css) {
|
|
7416
|
+
function collectCssRuleContentKeys(css, requiredBaseContent) {
|
|
7361
7417
|
const keys = /* @__PURE__ */ new Set();
|
|
7362
7418
|
try {
|
|
7363
7419
|
postcss.parse(css).walkRules((rule) => {
|
|
7364
|
-
const
|
|
7365
|
-
|
|
7420
|
+
const content = normalizeCssForContainment(rule.toString());
|
|
7421
|
+
const key = getCssRuleContentKey(rule, content);
|
|
7422
|
+
if (key) {
|
|
7423
|
+
if (requiredBaseContent !== void 0 && !requiredBaseContent.includes(content)) {
|
|
7424
|
+
keys.clear();
|
|
7425
|
+
return false;
|
|
7426
|
+
}
|
|
7427
|
+
keys.add(key);
|
|
7428
|
+
}
|
|
7366
7429
|
});
|
|
7367
7430
|
} catch {}
|
|
7368
7431
|
return keys;
|
|
@@ -7574,12 +7637,12 @@ function removeEmptyAtRules$1(root) {
|
|
|
7574
7637
|
}
|
|
7575
7638
|
//#endregion
|
|
7576
7639
|
//#region src/vite-css-rules/containment.ts
|
|
7577
|
-
function
|
|
7578
|
-
const baseRuleKeys =
|
|
7640
|
+
function filterCssRules(base, css) {
|
|
7641
|
+
const baseRuleKeys = base.ruleKeys();
|
|
7579
7642
|
if (baseRuleKeys.size === 0) return css;
|
|
7580
7643
|
try {
|
|
7581
7644
|
const root = postcss.parse(css);
|
|
7582
|
-
const baseRuleDeclarationKeys =
|
|
7645
|
+
const baseRuleDeclarationKeys = base.declarations();
|
|
7583
7646
|
let changed = false;
|
|
7584
7647
|
root.walkRules((rule) => {
|
|
7585
7648
|
const key = getCssRuleContentKey(rule);
|
|
@@ -7595,16 +7658,40 @@ function filterExistingCssRules(baseCss, css) {
|
|
|
7595
7658
|
return css;
|
|
7596
7659
|
}
|
|
7597
7660
|
}
|
|
7598
|
-
function
|
|
7599
|
-
if (
|
|
7600
|
-
const normalizedBaseCss =
|
|
7661
|
+
function containsCss(base, css) {
|
|
7662
|
+
if (base.css.includes(css)) return true;
|
|
7663
|
+
const normalizedBaseCss = base.normalized();
|
|
7601
7664
|
const normalizedCss = normalizeCssForContainment(css);
|
|
7602
7665
|
if (normalizedCss.length > 0 && normalizedBaseCss.includes(normalizedCss)) return true;
|
|
7603
7666
|
const normalizedNodes = collectNormalizedCssNodes(css);
|
|
7604
7667
|
if (normalizedNodes.length > 0 && normalizedNodes.every((node) => normalizedBaseCss.includes(node))) return true;
|
|
7605
|
-
const
|
|
7606
|
-
|
|
7607
|
-
|
|
7668
|
+
const ruleKeys = collectCssRuleContentKeys(css, normalizedBaseCss);
|
|
7669
|
+
return ruleKeys.size > 0 && [...ruleKeys].every((key) => base.ruleKeys().has(key));
|
|
7670
|
+
}
|
|
7671
|
+
function prepareCssBase(css) {
|
|
7672
|
+
let normalized;
|
|
7673
|
+
let ruleKeys;
|
|
7674
|
+
let declarations;
|
|
7675
|
+
return {
|
|
7676
|
+
css,
|
|
7677
|
+
normalized: () => normalized ??= normalizeCssForContainment(css),
|
|
7678
|
+
ruleKeys: () => ruleKeys ??= collectCssRuleContentKeys(css),
|
|
7679
|
+
declarations: () => declarations ??= collectCssRuleDeclarationKeyMap(css)
|
|
7680
|
+
};
|
|
7681
|
+
}
|
|
7682
|
+
/** 对同一份不可变主样式复用比较索引;调用方在主样式更新后创建新的 matcher。 */
|
|
7683
|
+
function createCssRuleMatcher(baseCss) {
|
|
7684
|
+
const base = prepareCssBase(baseCss);
|
|
7685
|
+
return {
|
|
7686
|
+
contains: (css) => containsCss(base, css),
|
|
7687
|
+
filter: (css) => filterCssRules(base, css)
|
|
7688
|
+
};
|
|
7689
|
+
}
|
|
7690
|
+
function filterExistingCssRules(baseCss, css) {
|
|
7691
|
+
return filterCssRules(prepareCssBase(baseCss), css);
|
|
7692
|
+
}
|
|
7693
|
+
function containsCssAfterMinify(baseCss, css) {
|
|
7694
|
+
return containsCss(prepareCssBase(baseCss), css);
|
|
7608
7695
|
}
|
|
7609
7696
|
//#endregion
|
|
7610
7697
|
//#region src/vite-css-rules/mini-program.ts
|
|
@@ -7751,4 +7838,4 @@ function mergeMiniProgramThemeScopeRuleDeclarations(baseCss, css) {
|
|
|
7751
7838
|
}
|
|
7752
7839
|
}
|
|
7753
7840
|
//#endregion
|
|
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 };
|
|
7841
|
+
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, createCssRuleMatcher, 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, normalizeTailwindcssV4InfinityRadiusCss, 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/dist/types.d.ts
CHANGED
|
@@ -140,6 +140,19 @@ export interface CssOptions {
|
|
|
140
140
|
tailwindcssV4GradientFallback?: boolean | undefined;
|
|
141
141
|
}
|
|
142
142
|
export type IStyleHandlerOptions = {
|
|
143
|
+
/** 编译诊断回调;由上层 bundler 注入,保持 PostCSS 包与 compiler 解耦。 */
|
|
144
|
+
onDiagnostic?: (event: {
|
|
145
|
+
phase: 'postcss';
|
|
146
|
+
durationMs: number;
|
|
147
|
+
cache?: {
|
|
148
|
+
hit: boolean;
|
|
149
|
+
key?: string;
|
|
150
|
+
};
|
|
151
|
+
error?: {
|
|
152
|
+
name?: string;
|
|
153
|
+
message: string;
|
|
154
|
+
};
|
|
155
|
+
}) => void | Promise<void>;
|
|
143
156
|
appType?: PostcssAppType | undefined;
|
|
144
157
|
ctx?: PostcssContext | undefined;
|
|
145
158
|
/**
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
/** 对同一份不可变主样式复用比较索引;调用方在主样式更新后创建新的 matcher。 */
|
|
2
|
+
export declare function createCssRuleMatcher(baseCss: string): {
|
|
3
|
+
contains: (css: string) => boolean;
|
|
4
|
+
filter: (css: string) => string;
|
|
5
|
+
};
|
|
1
6
|
export declare function filterExistingCssRules(baseCss: string, css: string): string;
|
|
2
7
|
export declare function containsCssAfterMinify(baseCss: string, css: string): boolean;
|
|
@@ -7,8 +7,8 @@ export declare function normalizeCssForContainment(css: string): string;
|
|
|
7
7
|
export declare function collectNormalizedCssNodes(css: string): string[];
|
|
8
8
|
export declare function getCssRuleStructuralKey(rule: postcss.Rule): string | undefined;
|
|
9
9
|
export declare function getCssRuleStructuralKeyWithSelectorKey(rule: postcss.Rule, selectorKey: string): string;
|
|
10
|
-
export declare function getCssRuleContentKey(rule: postcss.Rule): string | undefined;
|
|
11
|
-
export declare function collectCssRuleContentKeys(css: string): Set<string>;
|
|
10
|
+
export declare function getCssRuleContentKey(rule: postcss.Rule, content?: string): string | undefined;
|
|
11
|
+
export declare function collectCssRuleContentKeys(css: string, requiredBaseContent?: string): Set<string>;
|
|
12
12
|
export declare function normalizeCssDeclarationKey(decl: postcss.Declaration): string;
|
|
13
13
|
export declare function parseVarReferenceValue(value: string): string | undefined;
|
|
14
14
|
export declare function isEquivalentVarFallbackDeclaration(incoming: postcss.Declaration, baseDeclarations: Set<string>): boolean;
|
package/dist/vite-css-rules.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { containsCssAfterMinify, filterExistingCssRules } from './vite-css-rules/containment.js';
|
|
1
|
+
export { containsCssAfterMinify, createCssRuleMatcher, filterExistingCssRules } from './vite-css-rules/containment.js';
|
|
2
2
|
export { dedupeCoveredCssRules, mergeCoveredCssRuleDeclarations } from './vite-css-rules/coverage.js';
|
|
3
3
|
export { mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations } from './vite-css-rules/mini-program.js';
|
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.4",
|
|
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",
|
|
@@ -71,27 +71,26 @@
|
|
|
71
71
|
"@csstools/css-tokenizer": "^4.0.0",
|
|
72
72
|
"@tailwindcss-mangle/engine": "0.2.0",
|
|
73
73
|
"@weapp-core/escape": "~8.0.0",
|
|
74
|
-
"@weapp-tailwindcss/postcss-calc": "1.0.
|
|
74
|
+
"@weapp-tailwindcss/postcss-calc": "1.0.7",
|
|
75
75
|
"@weapp-tailwindcss/shared": "2.0.3",
|
|
76
|
-
"autoprefixer": "^10.5.
|
|
76
|
+
"autoprefixer": "^10.5.6",
|
|
77
77
|
"es-toolkit": "^1.52.0",
|
|
78
78
|
"lru-cache": "11.5.2",
|
|
79
79
|
"micromatch": "^4.0.8",
|
|
80
|
-
"postcss": "^8.5.
|
|
80
|
+
"postcss": "^8.5.28",
|
|
81
81
|
"postcss-load-config": "^6.0.1",
|
|
82
|
-
"postcss-preset-env": "^11.5.
|
|
82
|
+
"postcss-preset-env": "^11.5.2",
|
|
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",
|
|
86
86
|
"postcss-scss": "^4.0.9",
|
|
87
|
-
"postcss-selector-parser": "^7.1.
|
|
87
|
+
"postcss-selector-parser": "^7.1.6",
|
|
88
88
|
"postcss-value-parser": "^4.2.0",
|
|
89
89
|
"tailwindcss-config": "2.0.4"
|
|
90
90
|
},
|
|
91
91
|
"devDependencies": {
|
|
92
92
|
"@csstools/postcss-is-pseudo-class": "^6.0.0",
|
|
93
|
-
"fast-check": "^4.
|
|
94
|
-
"postcss-calc": "link:../postcss-calc",
|
|
93
|
+
"fast-check": "^4.10.0",
|
|
95
94
|
"postcss-custom-properties": "^15.0.1"
|
|
96
95
|
},
|
|
97
96
|
"scripts": {
|