@weapp-tailwindcss/postcss 3.0.0-next.6 → 3.0.0-next.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts
CHANGED
|
@@ -8,3 +8,4 @@ export { createFallbackPlaceholderReplacer } from './plugins/post/specificity-cl
|
|
|
8
8
|
export { createInjectPreflight } from './preflight';
|
|
9
9
|
export { internalCssSelectorReplacer } from './shared';
|
|
10
10
|
export * from './types';
|
|
11
|
+
export { composeRules as unitConversionComposeRules, presets as unitConversionPresets, } from 'postcss-rule-unit-converter';
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,8 @@ let postcss_pxtrans = require("postcss-pxtrans");
|
|
|
22
22
|
postcss_pxtrans = require_html_transform.__toESM(postcss_pxtrans);
|
|
23
23
|
let postcss_rem_to_responsive_pixel = require("postcss-rem-to-responsive-pixel");
|
|
24
24
|
postcss_rem_to_responsive_pixel = require_html_transform.__toESM(postcss_rem_to_responsive_pixel);
|
|
25
|
+
let node_process = require("node:process");
|
|
26
|
+
node_process = require_html_transform.__toESM(node_process);
|
|
25
27
|
let postcss_rule_unit_converter = require("postcss-rule-unit-converter");
|
|
26
28
|
postcss_rule_unit_converter = require_html_transform.__toESM(postcss_rule_unit_converter);
|
|
27
29
|
let _weapp_core_escape = require("@weapp-core/escape");
|
|
@@ -836,6 +838,9 @@ const MINI_PROGRAM_ELEMENT_VARIABLE_SCOPE_SELECTORS = new Set([
|
|
|
836
838
|
"::before",
|
|
837
839
|
"::after"
|
|
838
840
|
]);
|
|
841
|
+
function isConditionalCompilationComment(text) {
|
|
842
|
+
return /#(?:ifn?def|endif)\b/.test(text);
|
|
843
|
+
}
|
|
839
844
|
function hasClassSelector$2(selector) {
|
|
840
845
|
return CLASS_SELECTOR_RE$1.test(selector);
|
|
841
846
|
}
|
|
@@ -880,6 +885,7 @@ function pruneMiniProgramGeneratedCss(css, options = {}) {
|
|
|
880
885
|
const root = postcss.default.parse(css);
|
|
881
886
|
const shouldPreserveContentInit = options.preservePreflight || usesTwContentVariable(root);
|
|
882
887
|
root.walkComments((comment) => {
|
|
888
|
+
if (options.preserveConditionalComments && isConditionalCompilationComment(comment.text)) return;
|
|
883
889
|
comment.remove();
|
|
884
890
|
});
|
|
885
891
|
removeUnsupportedCascadeLayers(root);
|
|
@@ -1202,6 +1208,8 @@ function getSimpleOverrideCacheKey(options) {
|
|
|
1202
1208
|
let rem2rpx = SIMPLE_OVERRIDE_UNSET;
|
|
1203
1209
|
let px2rpx = SIMPLE_OVERRIDE_UNSET;
|
|
1204
1210
|
let unitsToPx = SIMPLE_OVERRIDE_UNSET;
|
|
1211
|
+
let unitConversion = SIMPLE_OVERRIDE_UNSET;
|
|
1212
|
+
let platform = SIMPLE_OVERRIDE_UNSET;
|
|
1205
1213
|
let cssCalc = SIMPLE_OVERRIDE_UNSET;
|
|
1206
1214
|
let cssChildCombinatorReplaceValue = SIMPLE_OVERRIDE_UNSET;
|
|
1207
1215
|
let cssPreflight = SIMPLE_OVERRIDE_UNSET;
|
|
@@ -1249,6 +1257,14 @@ function getSimpleOverrideCacheKey(options) {
|
|
|
1249
1257
|
if (typeof value !== "boolean") return;
|
|
1250
1258
|
unitsToPx = value ? "1" : "0";
|
|
1251
1259
|
break;
|
|
1260
|
+
case "unitConversion":
|
|
1261
|
+
if (value !== false) return;
|
|
1262
|
+
unitConversion = "0";
|
|
1263
|
+
break;
|
|
1264
|
+
case "platform":
|
|
1265
|
+
if (typeof value !== "string") return;
|
|
1266
|
+
platform = value;
|
|
1267
|
+
break;
|
|
1252
1268
|
case "cssCalc":
|
|
1253
1269
|
if (typeof value !== "boolean") return;
|
|
1254
1270
|
cssCalc = value ? "1" : "0";
|
|
@@ -1280,6 +1296,8 @@ function getSimpleOverrideCacheKey(options) {
|
|
|
1280
1296
|
rem2rpx,
|
|
1281
1297
|
px2rpx,
|
|
1282
1298
|
unitsToPx,
|
|
1299
|
+
unitConversion,
|
|
1300
|
+
platform,
|
|
1283
1301
|
cssCalc,
|
|
1284
1302
|
cssChildCombinatorReplaceValue,
|
|
1285
1303
|
cssPreflight,
|
|
@@ -1468,7 +1486,24 @@ function getCalcDuplicateCleaner(options) {
|
|
|
1468
1486
|
return calcDuplicateCleanerPlugin;
|
|
1469
1487
|
}
|
|
1470
1488
|
//#endregion
|
|
1471
|
-
//#region ../../node_modules/.pnpm/es-toolkit@1.
|
|
1489
|
+
//#region ../../node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/object/omit.mjs
|
|
1490
|
+
/**
|
|
1491
|
+
* Creates a new object with specified keys omitted.
|
|
1492
|
+
*
|
|
1493
|
+
* This function takes an object and an array of keys, and returns a new object that
|
|
1494
|
+
* excludes the properties corresponding to the specified keys.
|
|
1495
|
+
*
|
|
1496
|
+
* @template T - The type of object.
|
|
1497
|
+
* @template K - The type of keys in object.
|
|
1498
|
+
* @param {T} obj - The object to omit keys from.
|
|
1499
|
+
* @param {K[]} keys - An array of keys to be omitted from the object.
|
|
1500
|
+
* @returns {Omit<T, K>} A new object with the specified keys omitted.
|
|
1501
|
+
*
|
|
1502
|
+
* @example
|
|
1503
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
1504
|
+
* const result = omit(obj, ['b', 'c']);
|
|
1505
|
+
* // result will be { a: 1 }
|
|
1506
|
+
*/
|
|
1472
1507
|
function omit(obj, keys) {
|
|
1473
1508
|
const result = { ...obj };
|
|
1474
1509
|
for (let i = 0; i < keys.length; i++) {
|
|
@@ -1557,6 +1592,110 @@ function getRemTransformPlugin(options) {
|
|
|
1557
1592
|
return (0, postcss_rem_to_responsive_pixel.default)((0, _weapp_tailwindcss_shared.defuOverrideArray)(options.rem2rpx, defaultStage));
|
|
1558
1593
|
}
|
|
1559
1594
|
//#endregion
|
|
1595
|
+
//#region src/plugins/getUnitConversionPlugin.ts
|
|
1596
|
+
const DEFAULT_PLATFORM_KEYS = ["default", "*"];
|
|
1597
|
+
const PLATFORM_ENV_KEYS = [
|
|
1598
|
+
"WEAPP_TW_TARGET",
|
|
1599
|
+
"WEAPP_TAILWINDCSS_TARGET",
|
|
1600
|
+
"UNI_PLATFORM",
|
|
1601
|
+
"UNI_UTS_PLATFORM",
|
|
1602
|
+
"TARO_ENV",
|
|
1603
|
+
"MPX_CLI_MODE",
|
|
1604
|
+
"MPX_CURRENT_TARGET_MODE"
|
|
1605
|
+
];
|
|
1606
|
+
const PLATFORM_ALIASES = {
|
|
1607
|
+
"weapp": [
|
|
1608
|
+
"mp-weixin",
|
|
1609
|
+
"weixin",
|
|
1610
|
+
"wechat",
|
|
1611
|
+
"wx",
|
|
1612
|
+
"mp"
|
|
1613
|
+
],
|
|
1614
|
+
"mp-weixin": [
|
|
1615
|
+
"weapp",
|
|
1616
|
+
"weixin",
|
|
1617
|
+
"wechat",
|
|
1618
|
+
"wx",
|
|
1619
|
+
"mp"
|
|
1620
|
+
],
|
|
1621
|
+
"wx": [
|
|
1622
|
+
"weapp",
|
|
1623
|
+
"mp-weixin",
|
|
1624
|
+
"weixin",
|
|
1625
|
+
"wechat",
|
|
1626
|
+
"mp"
|
|
1627
|
+
],
|
|
1628
|
+
"h5": ["web"],
|
|
1629
|
+
"web": ["h5"],
|
|
1630
|
+
"app": [
|
|
1631
|
+
"app-plus",
|
|
1632
|
+
"app-android",
|
|
1633
|
+
"app-ios",
|
|
1634
|
+
"android",
|
|
1635
|
+
"ios"
|
|
1636
|
+
],
|
|
1637
|
+
"app-plus": ["app"],
|
|
1638
|
+
"app-android": ["app", "android"],
|
|
1639
|
+
"app-ios": ["app", "ios"],
|
|
1640
|
+
"android": ["app", "app-android"],
|
|
1641
|
+
"ios": ["app", "app-ios"]
|
|
1642
|
+
};
|
|
1643
|
+
function normalizePlatform(value) {
|
|
1644
|
+
return value?.trim().toLowerCase() || void 0;
|
|
1645
|
+
}
|
|
1646
|
+
function readEnvValue(key) {
|
|
1647
|
+
return typeof node_process.default === "undefined" ? void 0 : node_process.default.env[key];
|
|
1648
|
+
}
|
|
1649
|
+
function resolveUnitConversionPlatform(options) {
|
|
1650
|
+
const explicit = normalizePlatform(options.platform);
|
|
1651
|
+
if (explicit) return explicit;
|
|
1652
|
+
for (const key of PLATFORM_ENV_KEYS) {
|
|
1653
|
+
const value = normalizePlatform(readEnvValue(key));
|
|
1654
|
+
if (value) return value;
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
function isPlatformUnitConversionOptions(options) {
|
|
1658
|
+
return Boolean(options && typeof options === "object" && "platforms" in options);
|
|
1659
|
+
}
|
|
1660
|
+
function hasRules(config) {
|
|
1661
|
+
return Array.isArray(config.rules) && config.rules.length > 0;
|
|
1662
|
+
}
|
|
1663
|
+
function getPlatformCandidateKeys(platform) {
|
|
1664
|
+
if (!platform) return [];
|
|
1665
|
+
const normalized = normalizePlatform(platform);
|
|
1666
|
+
if (!normalized) return [];
|
|
1667
|
+
return [normalized, ...PLATFORM_ALIASES[normalized] ?? []];
|
|
1668
|
+
}
|
|
1669
|
+
function getPlatformConfig(platforms, key) {
|
|
1670
|
+
if (Object.hasOwn(platforms, key)) return platforms[key];
|
|
1671
|
+
for (const [platform, config] of Object.entries(platforms)) if (normalizePlatform(platform) === key) return config;
|
|
1672
|
+
}
|
|
1673
|
+
function resolvePlatformConfig(options, platform) {
|
|
1674
|
+
if (!isPlatformUnitConversionOptions(options)) return options;
|
|
1675
|
+
const platforms = options.platforms;
|
|
1676
|
+
for (const key of getPlatformCandidateKeys(platform)) {
|
|
1677
|
+
const config = getPlatformConfig(platforms, key);
|
|
1678
|
+
if (config !== void 0) return config;
|
|
1679
|
+
}
|
|
1680
|
+
if (options.default !== void 0) return options.default;
|
|
1681
|
+
for (const key of DEFAULT_PLATFORM_KEYS) {
|
|
1682
|
+
const config = getPlatformConfig(platforms, key);
|
|
1683
|
+
if (config !== void 0) return config;
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
function resolveUnitConversionConfig(options) {
|
|
1687
|
+
const unitConversion = options.unitConversion;
|
|
1688
|
+
if (!unitConversion || unitConversion === false) return;
|
|
1689
|
+
const config = resolvePlatformConfig(unitConversion, resolveUnitConversionPlatform(options));
|
|
1690
|
+
if (!config || config === false || config.disabled || !hasRules(config)) return;
|
|
1691
|
+
return config;
|
|
1692
|
+
}
|
|
1693
|
+
function getUnitConversionPlugin(options) {
|
|
1694
|
+
const config = resolveUnitConversionConfig(options);
|
|
1695
|
+
if (!config) return null;
|
|
1696
|
+
return (0, postcss_rule_unit_converter.default)(config);
|
|
1697
|
+
}
|
|
1698
|
+
//#endregion
|
|
1560
1699
|
//#region src/plugins/getUnitsToPxPlugin.ts
|
|
1561
1700
|
function getUnitsToPxPlugin(options) {
|
|
1562
1701
|
if (!options.unitsToPx) return null;
|
|
@@ -3253,6 +3392,8 @@ function createPreparedNodes(options, signal) {
|
|
|
3253
3392
|
if (pxTransformPlugin) preparedNodes.push(createPreparedNode("normal:px-transform", "normal", () => pxTransformPlugin));
|
|
3254
3393
|
const remTransformPlugin = getRemTransformPlugin(options);
|
|
3255
3394
|
if (remTransformPlugin) preparedNodes.push(createPreparedNode("normal:rem-transform", "normal", () => remTransformPlugin));
|
|
3395
|
+
const unitConversionPlugin = getUnitConversionPlugin(options);
|
|
3396
|
+
if (unitConversionPlugin) preparedNodes.push(createPreparedNode("normal:unit-conversion", "normal", () => unitConversionPlugin));
|
|
3256
3397
|
const calcPlugin = getCalcPlugin(options);
|
|
3257
3398
|
if (calcPlugin) preparedNodes.push(createPreparedNode("normal:calc", "normal", () => calcPlugin));
|
|
3258
3399
|
const calcDuplicateCleaner = getCalcDuplicateCleaner(options);
|
|
@@ -3514,3 +3655,15 @@ exports.removeUnsupportedAtSupports = removeUnsupportedAtSupports;
|
|
|
3514
3655
|
exports.removeUnsupportedCascadeLayers = removeUnsupportedCascadeLayers;
|
|
3515
3656
|
exports.removeUnsupportedMiniProgramAtRules = removeUnsupportedMiniProgramAtRules;
|
|
3516
3657
|
exports.removeUnsupportedMiniProgramPrefixedAtRule = removeUnsupportedMiniProgramPrefixedAtRule;
|
|
3658
|
+
Object.defineProperty(exports, "unitConversionComposeRules", {
|
|
3659
|
+
enumerable: true,
|
|
3660
|
+
get: function() {
|
|
3661
|
+
return postcss_rule_unit_converter.composeRules;
|
|
3662
|
+
}
|
|
3663
|
+
});
|
|
3664
|
+
Object.defineProperty(exports, "unitConversionPresets", {
|
|
3665
|
+
enumerable: true,
|
|
3666
|
+
get: function() {
|
|
3667
|
+
return postcss_rule_unit_converter.presets;
|
|
3668
|
+
}
|
|
3669
|
+
});
|
package/dist/index.mjs
CHANGED
|
@@ -13,7 +13,8 @@ import autoprefixerPlugin from "autoprefixer";
|
|
|
13
13
|
import postcssCalc from "@weapp-tailwindcss/postcss-calc";
|
|
14
14
|
import postcssPxtrans from "postcss-pxtrans";
|
|
15
15
|
import postcssRem2rpx from "postcss-rem-to-responsive-pixel";
|
|
16
|
-
import
|
|
16
|
+
import process from "node:process";
|
|
17
|
+
import postcssUnitConverter, { composeRules as unitConversionComposeRules, presets, presets as unitConversionPresets } from "postcss-rule-unit-converter";
|
|
17
18
|
import { MappingChars2String, escape } from "@weapp-core/escape";
|
|
18
19
|
//#region src/compat/color-mix.ts
|
|
19
20
|
const COLOR_MIX_NAME = "color-mix";
|
|
@@ -826,6 +827,9 @@ const MINI_PROGRAM_ELEMENT_VARIABLE_SCOPE_SELECTORS = new Set([
|
|
|
826
827
|
"::before",
|
|
827
828
|
"::after"
|
|
828
829
|
]);
|
|
830
|
+
function isConditionalCompilationComment(text) {
|
|
831
|
+
return /#(?:ifn?def|endif)\b/.test(text);
|
|
832
|
+
}
|
|
829
833
|
function hasClassSelector$2(selector) {
|
|
830
834
|
return CLASS_SELECTOR_RE$1.test(selector);
|
|
831
835
|
}
|
|
@@ -870,6 +874,7 @@ function pruneMiniProgramGeneratedCss(css, options = {}) {
|
|
|
870
874
|
const root = postcss.parse(css);
|
|
871
875
|
const shouldPreserveContentInit = options.preservePreflight || usesTwContentVariable(root);
|
|
872
876
|
root.walkComments((comment) => {
|
|
877
|
+
if (options.preserveConditionalComments && isConditionalCompilationComment(comment.text)) return;
|
|
873
878
|
comment.remove();
|
|
874
879
|
});
|
|
875
880
|
removeUnsupportedCascadeLayers(root);
|
|
@@ -1192,6 +1197,8 @@ function getSimpleOverrideCacheKey(options) {
|
|
|
1192
1197
|
let rem2rpx = SIMPLE_OVERRIDE_UNSET;
|
|
1193
1198
|
let px2rpx = SIMPLE_OVERRIDE_UNSET;
|
|
1194
1199
|
let unitsToPx = SIMPLE_OVERRIDE_UNSET;
|
|
1200
|
+
let unitConversion = SIMPLE_OVERRIDE_UNSET;
|
|
1201
|
+
let platform = SIMPLE_OVERRIDE_UNSET;
|
|
1195
1202
|
let cssCalc = SIMPLE_OVERRIDE_UNSET;
|
|
1196
1203
|
let cssChildCombinatorReplaceValue = SIMPLE_OVERRIDE_UNSET;
|
|
1197
1204
|
let cssPreflight = SIMPLE_OVERRIDE_UNSET;
|
|
@@ -1239,6 +1246,14 @@ function getSimpleOverrideCacheKey(options) {
|
|
|
1239
1246
|
if (typeof value !== "boolean") return;
|
|
1240
1247
|
unitsToPx = value ? "1" : "0";
|
|
1241
1248
|
break;
|
|
1249
|
+
case "unitConversion":
|
|
1250
|
+
if (value !== false) return;
|
|
1251
|
+
unitConversion = "0";
|
|
1252
|
+
break;
|
|
1253
|
+
case "platform":
|
|
1254
|
+
if (typeof value !== "string") return;
|
|
1255
|
+
platform = value;
|
|
1256
|
+
break;
|
|
1242
1257
|
case "cssCalc":
|
|
1243
1258
|
if (typeof value !== "boolean") return;
|
|
1244
1259
|
cssCalc = value ? "1" : "0";
|
|
@@ -1270,6 +1285,8 @@ function getSimpleOverrideCacheKey(options) {
|
|
|
1270
1285
|
rem2rpx,
|
|
1271
1286
|
px2rpx,
|
|
1272
1287
|
unitsToPx,
|
|
1288
|
+
unitConversion,
|
|
1289
|
+
platform,
|
|
1273
1290
|
cssCalc,
|
|
1274
1291
|
cssChildCombinatorReplaceValue,
|
|
1275
1292
|
cssPreflight,
|
|
@@ -1458,7 +1475,24 @@ function getCalcDuplicateCleaner(options) {
|
|
|
1458
1475
|
return calcDuplicateCleanerPlugin;
|
|
1459
1476
|
}
|
|
1460
1477
|
//#endregion
|
|
1461
|
-
//#region ../../node_modules/.pnpm/es-toolkit@1.
|
|
1478
|
+
//#region ../../node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/object/omit.mjs
|
|
1479
|
+
/**
|
|
1480
|
+
* Creates a new object with specified keys omitted.
|
|
1481
|
+
*
|
|
1482
|
+
* This function takes an object and an array of keys, and returns a new object that
|
|
1483
|
+
* excludes the properties corresponding to the specified keys.
|
|
1484
|
+
*
|
|
1485
|
+
* @template T - The type of object.
|
|
1486
|
+
* @template K - The type of keys in object.
|
|
1487
|
+
* @param {T} obj - The object to omit keys from.
|
|
1488
|
+
* @param {K[]} keys - An array of keys to be omitted from the object.
|
|
1489
|
+
* @returns {Omit<T, K>} A new object with the specified keys omitted.
|
|
1490
|
+
*
|
|
1491
|
+
* @example
|
|
1492
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
1493
|
+
* const result = omit(obj, ['b', 'c']);
|
|
1494
|
+
* // result will be { a: 1 }
|
|
1495
|
+
*/
|
|
1462
1496
|
function omit(obj, keys) {
|
|
1463
1497
|
const result = { ...obj };
|
|
1464
1498
|
for (let i = 0; i < keys.length; i++) {
|
|
@@ -1547,6 +1581,110 @@ function getRemTransformPlugin(options) {
|
|
|
1547
1581
|
return postcssRem2rpx(defuOverrideArray(options.rem2rpx, defaultStage));
|
|
1548
1582
|
}
|
|
1549
1583
|
//#endregion
|
|
1584
|
+
//#region src/plugins/getUnitConversionPlugin.ts
|
|
1585
|
+
const DEFAULT_PLATFORM_KEYS = ["default", "*"];
|
|
1586
|
+
const PLATFORM_ENV_KEYS = [
|
|
1587
|
+
"WEAPP_TW_TARGET",
|
|
1588
|
+
"WEAPP_TAILWINDCSS_TARGET",
|
|
1589
|
+
"UNI_PLATFORM",
|
|
1590
|
+
"UNI_UTS_PLATFORM",
|
|
1591
|
+
"TARO_ENV",
|
|
1592
|
+
"MPX_CLI_MODE",
|
|
1593
|
+
"MPX_CURRENT_TARGET_MODE"
|
|
1594
|
+
];
|
|
1595
|
+
const PLATFORM_ALIASES = {
|
|
1596
|
+
"weapp": [
|
|
1597
|
+
"mp-weixin",
|
|
1598
|
+
"weixin",
|
|
1599
|
+
"wechat",
|
|
1600
|
+
"wx",
|
|
1601
|
+
"mp"
|
|
1602
|
+
],
|
|
1603
|
+
"mp-weixin": [
|
|
1604
|
+
"weapp",
|
|
1605
|
+
"weixin",
|
|
1606
|
+
"wechat",
|
|
1607
|
+
"wx",
|
|
1608
|
+
"mp"
|
|
1609
|
+
],
|
|
1610
|
+
"wx": [
|
|
1611
|
+
"weapp",
|
|
1612
|
+
"mp-weixin",
|
|
1613
|
+
"weixin",
|
|
1614
|
+
"wechat",
|
|
1615
|
+
"mp"
|
|
1616
|
+
],
|
|
1617
|
+
"h5": ["web"],
|
|
1618
|
+
"web": ["h5"],
|
|
1619
|
+
"app": [
|
|
1620
|
+
"app-plus",
|
|
1621
|
+
"app-android",
|
|
1622
|
+
"app-ios",
|
|
1623
|
+
"android",
|
|
1624
|
+
"ios"
|
|
1625
|
+
],
|
|
1626
|
+
"app-plus": ["app"],
|
|
1627
|
+
"app-android": ["app", "android"],
|
|
1628
|
+
"app-ios": ["app", "ios"],
|
|
1629
|
+
"android": ["app", "app-android"],
|
|
1630
|
+
"ios": ["app", "app-ios"]
|
|
1631
|
+
};
|
|
1632
|
+
function normalizePlatform(value) {
|
|
1633
|
+
return value?.trim().toLowerCase() || void 0;
|
|
1634
|
+
}
|
|
1635
|
+
function readEnvValue(key) {
|
|
1636
|
+
return typeof process === "undefined" ? void 0 : process.env[key];
|
|
1637
|
+
}
|
|
1638
|
+
function resolveUnitConversionPlatform(options) {
|
|
1639
|
+
const explicit = normalizePlatform(options.platform);
|
|
1640
|
+
if (explicit) return explicit;
|
|
1641
|
+
for (const key of PLATFORM_ENV_KEYS) {
|
|
1642
|
+
const value = normalizePlatform(readEnvValue(key));
|
|
1643
|
+
if (value) return value;
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
function isPlatformUnitConversionOptions(options) {
|
|
1647
|
+
return Boolean(options && typeof options === "object" && "platforms" in options);
|
|
1648
|
+
}
|
|
1649
|
+
function hasRules(config) {
|
|
1650
|
+
return Array.isArray(config.rules) && config.rules.length > 0;
|
|
1651
|
+
}
|
|
1652
|
+
function getPlatformCandidateKeys(platform) {
|
|
1653
|
+
if (!platform) return [];
|
|
1654
|
+
const normalized = normalizePlatform(platform);
|
|
1655
|
+
if (!normalized) return [];
|
|
1656
|
+
return [normalized, ...PLATFORM_ALIASES[normalized] ?? []];
|
|
1657
|
+
}
|
|
1658
|
+
function getPlatformConfig(platforms, key) {
|
|
1659
|
+
if (Object.hasOwn(platforms, key)) return platforms[key];
|
|
1660
|
+
for (const [platform, config] of Object.entries(platforms)) if (normalizePlatform(platform) === key) return config;
|
|
1661
|
+
}
|
|
1662
|
+
function resolvePlatformConfig(options, platform) {
|
|
1663
|
+
if (!isPlatformUnitConversionOptions(options)) return options;
|
|
1664
|
+
const platforms = options.platforms;
|
|
1665
|
+
for (const key of getPlatformCandidateKeys(platform)) {
|
|
1666
|
+
const config = getPlatformConfig(platforms, key);
|
|
1667
|
+
if (config !== void 0) return config;
|
|
1668
|
+
}
|
|
1669
|
+
if (options.default !== void 0) return options.default;
|
|
1670
|
+
for (const key of DEFAULT_PLATFORM_KEYS) {
|
|
1671
|
+
const config = getPlatformConfig(platforms, key);
|
|
1672
|
+
if (config !== void 0) return config;
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
function resolveUnitConversionConfig(options) {
|
|
1676
|
+
const unitConversion = options.unitConversion;
|
|
1677
|
+
if (!unitConversion || unitConversion === false) return;
|
|
1678
|
+
const config = resolvePlatformConfig(unitConversion, resolveUnitConversionPlatform(options));
|
|
1679
|
+
if (!config || config === false || config.disabled || !hasRules(config)) return;
|
|
1680
|
+
return config;
|
|
1681
|
+
}
|
|
1682
|
+
function getUnitConversionPlugin(options) {
|
|
1683
|
+
const config = resolveUnitConversionConfig(options);
|
|
1684
|
+
if (!config) return null;
|
|
1685
|
+
return postcssUnitConverter(config);
|
|
1686
|
+
}
|
|
1687
|
+
//#endregion
|
|
1550
1688
|
//#region src/plugins/getUnitsToPxPlugin.ts
|
|
1551
1689
|
function getUnitsToPxPlugin(options) {
|
|
1552
1690
|
if (!options.unitsToPx) return null;
|
|
@@ -3243,6 +3381,8 @@ function createPreparedNodes(options, signal) {
|
|
|
3243
3381
|
if (pxTransformPlugin) preparedNodes.push(createPreparedNode("normal:px-transform", "normal", () => pxTransformPlugin));
|
|
3244
3382
|
const remTransformPlugin = getRemTransformPlugin(options);
|
|
3245
3383
|
if (remTransformPlugin) preparedNodes.push(createPreparedNode("normal:rem-transform", "normal", () => remTransformPlugin));
|
|
3384
|
+
const unitConversionPlugin = getUnitConversionPlugin(options);
|
|
3385
|
+
if (unitConversionPlugin) preparedNodes.push(createPreparedNode("normal:unit-conversion", "normal", () => unitConversionPlugin));
|
|
3246
3386
|
const calcPlugin = getCalcPlugin(options);
|
|
3247
3387
|
if (calcPlugin) preparedNodes.push(createPreparedNode("normal:calc", "normal", () => calcPlugin));
|
|
3248
3388
|
const calcDuplicateCleaner = getCalcDuplicateCleaner(options);
|
|
@@ -3488,4 +3628,4 @@ function createStyleHandler(options) {
|
|
|
3488
3628
|
return handler;
|
|
3489
3629
|
}
|
|
3490
3630
|
//#endregion
|
|
3491
|
-
export { createFallbackPlaceholderReplacer, createInjectPreflight, createStyleHandler, createStylePipeline, finalizeMiniProgramCss, hoistTailwindPreflightBase, internalCssSelectorReplacer, normalizeMiniProgramPrefixedDeclaration, normalizeModernColorValue, postcssHtmlTransform, protectDynamicColorMixAlpha, pruneMiniProgramGeneratedCss, removeUnsupportedAtSupports, removeUnsupportedCascadeLayers, removeUnsupportedMiniProgramAtRules, removeUnsupportedMiniProgramPrefixedAtRule };
|
|
3631
|
+
export { createFallbackPlaceholderReplacer, createInjectPreflight, createStyleHandler, createStylePipeline, finalizeMiniProgramCss, hoistTailwindPreflightBase, internalCssSelectorReplacer, normalizeMiniProgramPrefixedDeclaration, normalizeModernColorValue, postcssHtmlTransform, protectDynamicColorMixAlpha, pruneMiniProgramGeneratedCss, removeUnsupportedAtSupports, removeUnsupportedCascadeLayers, removeUnsupportedMiniProgramAtRules, removeUnsupportedMiniProgramPrefixedAtRule, unitConversionComposeRules, unitConversionPresets };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AcceptedPlugin } from 'postcss';
|
|
2
|
+
import type { IStyleHandlerOptions, UnitConversionConfig } from '../types';
|
|
3
|
+
export declare function resolveUnitConversionPlatform(options: Pick<IStyleHandlerOptions, 'platform'>): string | undefined;
|
|
4
|
+
export declare function resolveUnitConversionConfig(options: Pick<IStyleHandlerOptions, 'platform' | 'unitConversion'>): UnitConversionConfig | undefined;
|
|
5
|
+
export declare function getUnitConversionPlugin(options: IStyleHandlerOptions): AcceptedPlugin | null;
|
package/dist/types.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export type RequiredStyleHandlerOptions = {
|
|
|
27
27
|
cssPreflight?: CssPreflightOptions | undefined;
|
|
28
28
|
cssInjectPreflight?: InjectPreflight | undefined;
|
|
29
29
|
escapeMap?: Record<string, string> | undefined;
|
|
30
|
-
} & Pick<UserDefinedPostcssOptions, 'cssPreflightRange' | 'cssChildCombinatorReplaceValue' | 'injectAdditionalCssVarScope' | 'cssSelectorReplacement' | 'rem2rpx' | 'px2rpx' | 'unitsToPx'>;
|
|
30
|
+
} & Pick<UserDefinedPostcssOptions, 'cssPreflightRange' | 'cssChildCombinatorReplaceValue' | 'injectAdditionalCssVarScope' | 'cssSelectorReplacement' | 'rem2rpx' | 'px2rpx' | 'unitsToPx' | 'unitConversion'>;
|
|
31
31
|
export interface InternalCssSelectorReplacerOptions {
|
|
32
32
|
escapeMap?: Record<string, string> | undefined;
|
|
33
33
|
}
|
|
@@ -40,8 +40,22 @@ export interface UnitsToPxOptions extends Pick<UnitConverterOptions, 'disabled'
|
|
|
40
40
|
unitMap?: UnitMap;
|
|
41
41
|
transform?: GlobalUnitTransform | false;
|
|
42
42
|
}
|
|
43
|
+
export type UnitConversionConfig = UnitConverterOptions;
|
|
44
|
+
export type UnitConversionPlatformMap = Record<string, UnitConversionConfig | false | undefined>;
|
|
45
|
+
export interface PlatformUnitConversionOptions {
|
|
46
|
+
/**
|
|
47
|
+
* 未匹配到具体平台时使用的兜底转换规则。
|
|
48
|
+
*/
|
|
49
|
+
default?: UnitConversionConfig | false | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* 按平台名称配置转换规则,平台键会做小写归一化并兼容常见别名。
|
|
52
|
+
*/
|
|
53
|
+
platforms: UnitConversionPlatformMap;
|
|
54
|
+
}
|
|
55
|
+
export type UnitConversionOptions = UnitConversionConfig | PlatformUnitConversionOptions | false;
|
|
43
56
|
export type IStyleHandlerOptions = {
|
|
44
57
|
ctx?: PostcssContext | undefined;
|
|
58
|
+
platform?: string | undefined;
|
|
45
59
|
postcssOptions?: LoadedPostcssOptions | undefined;
|
|
46
60
|
cssRemoveProperty?: boolean | undefined;
|
|
47
61
|
cssRemoveHoverPseudoClass?: boolean | undefined;
|
|
@@ -72,6 +86,7 @@ export interface UserDefinedPostcssOptions {
|
|
|
72
86
|
rem2rpx?: boolean | Rem2rpxOptions | undefined;
|
|
73
87
|
px2rpx?: boolean | Px2rpxOptions | undefined;
|
|
74
88
|
unitsToPx?: boolean | UnitsToPxOptions | undefined;
|
|
89
|
+
unitConversion?: UnitConversionOptions | undefined;
|
|
75
90
|
postcssOptions?: LoadedPostcssOptions | undefined;
|
|
76
91
|
cssRemoveHoverPseudoClass?: boolean | undefined;
|
|
77
92
|
cssRemoveProperty?: boolean | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-tailwindcss/postcss",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.7",
|
|
4
4
|
"description": "@weapp-tailwindcss/postcss",
|
|
5
5
|
"author": "ice breaker <1324318532@qq.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -59,12 +59,12 @@
|
|
|
59
59
|
"@csstools/css-color-parser": "^4.1.1",
|
|
60
60
|
"@csstools/css-parser-algorithms": "^4.0.0",
|
|
61
61
|
"@csstools/css-tokenizer": "^4.0.0",
|
|
62
|
-
"@weapp-core/escape": "~
|
|
62
|
+
"@weapp-core/escape": "~8.0.0",
|
|
63
63
|
"@weapp-tailwindcss/postcss-calc": "^1.0.0",
|
|
64
64
|
"autoprefixer": "^10.5.0",
|
|
65
|
-
"lru-cache": "
|
|
65
|
+
"lru-cache": "11.5.0",
|
|
66
66
|
"postcss": "^8.5.15",
|
|
67
|
-
"postcss-preset-env": "^
|
|
67
|
+
"postcss-preset-env": "^11.3.0",
|
|
68
68
|
"postcss-pxtrans": "^1.0.4",
|
|
69
69
|
"postcss-rem-to-responsive-pixel": "^7.0.4",
|
|
70
70
|
"postcss-rule-unit-converter": "^0.2.2",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"@csstools/postcss-is-pseudo-class": "^6.0.0",
|
|
77
77
|
"fast-check": "^4.8.0",
|
|
78
78
|
"postcss-calc": "^10.1.1",
|
|
79
|
-
"postcss-custom-properties": "^
|
|
79
|
+
"postcss-custom-properties": "^15.0.1"
|
|
80
80
|
},
|
|
81
81
|
"scripts": {
|
|
82
82
|
"dev": "tsdown --watch --sourcemap",
|