@weapp-tailwindcss/postcss 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +136 -34
- package/dist/index.mjs +109 -7
- package/dist/{types-SytH0h-o.d.mts → types-6NcGD9Zr.d.mts} +2 -5
- package/dist/{types-SytH0h-o.d.ts → types-6NcGD9Zr.d.ts} +2 -5
- package/dist/types.d.mts +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { I as IStyleHandlerOptions, S as StyleHandler, a as InternalCssSelectorReplacerOptions } from './types-
|
|
2
|
-
export { C as CssCalcOptions,
|
|
1
|
+
import { I as IStyleHandlerOptions, S as StyleHandler, a as InternalCssSelectorReplacerOptions } from './types-6NcGD9Zr.mjs';
|
|
2
|
+
export { C as CssCalcOptions, h as CssPreflightOptions, g as IPropValue, L as LoadedPostcssOptions, P as PipelineNodeContext, b as PipelineNodeCursor, d as PipelineStage, i as RequiredStyleHandlerOptions, R as ResolvedPipelineNode, e as StyleProcessingPipeline, U as UserDefinedPostcssOptions, f as createInjectPreflight, c as createStylePipeline } from './types-6NcGD9Zr.mjs';
|
|
3
3
|
export { pluginOptions as PresetEnvOptions } from 'postcss-preset-env';
|
|
4
4
|
export { PxtransformOptions as Px2rpxOptions } from 'postcss-pxtransform';
|
|
5
5
|
export { UserDefinedOptions as Rem2rpxOptions } from 'postcss-rem-to-responsive-pixel';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { I as IStyleHandlerOptions, S as StyleHandler, a as InternalCssSelectorReplacerOptions } from './types-
|
|
2
|
-
export { C as CssCalcOptions,
|
|
1
|
+
import { I as IStyleHandlerOptions, S as StyleHandler, a as InternalCssSelectorReplacerOptions } from './types-6NcGD9Zr.js';
|
|
2
|
+
export { C as CssCalcOptions, h as CssPreflightOptions, g as IPropValue, L as LoadedPostcssOptions, P as PipelineNodeContext, b as PipelineNodeCursor, d as PipelineStage, i as RequiredStyleHandlerOptions, R as ResolvedPipelineNode, e as StyleProcessingPipeline, U as UserDefinedPostcssOptions, f as createInjectPreflight, c as createStylePipeline } from './types-6NcGD9Zr.js';
|
|
3
3
|
export { pluginOptions as PresetEnvOptions } from 'postcss-preset-env';
|
|
4
4
|
export { PxtransformOptions as Px2rpxOptions } from 'postcss-pxtransform';
|
|
5
5
|
export { UserDefinedOptions as Rem2rpxOptions } from 'postcss-rem-to-responsive-pixel';
|
package/dist/index.js
CHANGED
|
@@ -16,8 +16,9 @@ function getDefaultOptions(options) {
|
|
|
16
16
|
},
|
|
17
17
|
"oklab-function": true,
|
|
18
18
|
"color-mix": true,
|
|
19
|
+
"color-functional-notation": _nullishCoalesce(_optionalChain([options, 'optionalAccess', _ => _.cssPresetEnv, 'optionalAccess', _2 => _2.features, 'optionalAccess', _3 => _3["color-functional-notation"]]), () => ( { preserve: false })),
|
|
19
20
|
// 在 calc 下,这个需要开启
|
|
20
|
-
"custom-properties": _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
21
|
+
"custom-properties": _nullishCoalesce(_optionalChain([options, 'optionalAccess', _4 => _4.cssPresetEnv, 'optionalAccess', _5 => _5.features, 'optionalAccess', _6 => _6["custom-properties"]]), () => ( _optionalChain([options, 'optionalAccess', _7 => _7.cssCalc]))) ? { preserve: true } : false
|
|
21
22
|
},
|
|
22
23
|
autoprefixer: {
|
|
23
24
|
add: false
|
|
@@ -37,6 +38,103 @@ function getDefaultOptions(options) {
|
|
|
37
38
|
// src/pipeline.ts
|
|
38
39
|
var _postcsspresetenv = require('postcss-preset-env'); var _postcsspresetenv2 = _interopRequireDefault(_postcsspresetenv);
|
|
39
40
|
|
|
41
|
+
// src/plugins/colorFunctionalFallback.ts
|
|
42
|
+
var _postcssvalueparser = require('postcss-value-parser'); var _postcssvalueparser2 = _interopRequireDefault(_postcssvalueparser);
|
|
43
|
+
var RGB_FUNCTION_NAME = "rgb";
|
|
44
|
+
var isSlashDiv = (node) => node.type === "div" && node.value === "/";
|
|
45
|
+
function trimNodes(nodes2) {
|
|
46
|
+
let start = 0;
|
|
47
|
+
let end = nodes2.length;
|
|
48
|
+
while (start < end && _optionalChain([nodes2, 'access', _8 => _8[start], 'optionalAccess', _9 => _9.type]) === "space") {
|
|
49
|
+
start += 1;
|
|
50
|
+
}
|
|
51
|
+
while (end > start && _optionalChain([nodes2, 'access', _10 => _10[end - 1], 'optionalAccess', _11 => _11.type]) === "space") {
|
|
52
|
+
end -= 1;
|
|
53
|
+
}
|
|
54
|
+
return nodes2.slice(start, end);
|
|
55
|
+
}
|
|
56
|
+
function splitColorComponents(nodes2) {
|
|
57
|
+
const parts = [];
|
|
58
|
+
let current = [];
|
|
59
|
+
nodes2.forEach((node) => {
|
|
60
|
+
if (node.type === "div" && node.value === ",") {
|
|
61
|
+
if (current.length) {
|
|
62
|
+
parts.push(current);
|
|
63
|
+
current = [];
|
|
64
|
+
}
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (node.type === "space") {
|
|
68
|
+
if (current.length) {
|
|
69
|
+
parts.push(current);
|
|
70
|
+
current = [];
|
|
71
|
+
}
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
current.push(node);
|
|
75
|
+
});
|
|
76
|
+
if (current.length) {
|
|
77
|
+
parts.push(current);
|
|
78
|
+
}
|
|
79
|
+
return parts;
|
|
80
|
+
}
|
|
81
|
+
var buildFunctionNodes = (content) => _postcssvalueparser2.default.call(void 0, content).nodes;
|
|
82
|
+
function convertRgbFunction(fnNode) {
|
|
83
|
+
const slashIndex = fnNode.nodes.findIndex(isSlashDiv);
|
|
84
|
+
if (slashIndex === -1) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
const colorNodes = trimNodes(fnNode.nodes.slice(0, slashIndex));
|
|
88
|
+
const alphaNodes = trimNodes(fnNode.nodes.slice(slashIndex + 1));
|
|
89
|
+
if (!colorNodes.length || !alphaNodes.length) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
const colorParts = splitColorComponents(colorNodes);
|
|
93
|
+
if (colorParts.length !== 3) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
const normalizedColors = colorParts.map((part) => _postcssvalueparser2.default.stringify(part).trim()).filter(Boolean);
|
|
97
|
+
if (normalizedColors.length !== 3) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
const alphaText = _postcssvalueparser2.default.stringify(alphaNodes).trim();
|
|
101
|
+
if (!alphaText) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
fnNode.value = "rgba";
|
|
105
|
+
const nextValue = `${normalizedColors.join(", ")}, ${alphaText}`;
|
|
106
|
+
fnNode.nodes = buildFunctionNodes(nextValue);
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
function transformDeclaration(decl) {
|
|
110
|
+
if (!decl.value || !decl.value.toLowerCase().includes(RGB_FUNCTION_NAME)) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const parsed = _postcssvalueparser2.default.call(void 0, decl.value);
|
|
114
|
+
let mutated = false;
|
|
115
|
+
parsed.walk((node) => {
|
|
116
|
+
if (node.type !== "function") {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (node.value.toLowerCase() !== RGB_FUNCTION_NAME) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (convertRgbFunction(node)) {
|
|
123
|
+
mutated = true;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
if (mutated) {
|
|
127
|
+
decl.value = parsed.toString();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function createColorFunctionalFallback() {
|
|
131
|
+
return {
|
|
132
|
+
postcssPlugin: "weapp-tailwindcss-color-functional-fallback",
|
|
133
|
+
Declaration: transformDeclaration
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
createColorFunctionalFallback.postcss = true;
|
|
137
|
+
|
|
40
138
|
// src/plugins/ctx.ts
|
|
41
139
|
function createContext() {
|
|
42
140
|
const variablesScopeWeakMap = /* @__PURE__ */ new WeakMap();
|
|
@@ -77,7 +175,7 @@ function getCalcPlugin(options) {
|
|
|
77
175
|
|
|
78
176
|
// src/plugins/getCustomPropertyCleaner.ts
|
|
79
177
|
|
|
80
|
-
|
|
178
|
+
|
|
81
179
|
function getCustomPropertyCleaner(options) {
|
|
82
180
|
const includeCustomProperties = Array.isArray(options.cssCalc) ? options.cssCalc : typeof options.cssCalc === "object" ? options.cssCalc.includeCustomProperties : [];
|
|
83
181
|
const shouldMatchCustomProperties = Array.isArray(includeCustomProperties) && includeCustomProperties.length > 0;
|
|
@@ -190,7 +288,7 @@ var beforeAfterParser = _postcssselectorparser2.default.call(void 0, (selectors)
|
|
|
190
288
|
return;
|
|
191
289
|
}
|
|
192
290
|
selectors.walkPseudos((s) => {
|
|
193
|
-
if (_optionalChain([s, 'access',
|
|
291
|
+
if (_optionalChain([s, 'access', _12 => _12.parent, 'optionalAccess', _13 => _13.length]) === 1) {
|
|
194
292
|
if (/^:?:before$/.test(s.value)) {
|
|
195
293
|
state.before = true;
|
|
196
294
|
}
|
|
@@ -268,7 +366,7 @@ function getFallbackRemove(_rule, options) {
|
|
|
268
366
|
const cacheKey = _nullishCoalesce(options, () => ( fallbackDefaultKey));
|
|
269
367
|
let entry = fallbackRemoveCache.get(cacheKey);
|
|
270
368
|
if (!entry) {
|
|
271
|
-
const uniAppX = Boolean(_optionalChain([options, 'optionalAccess',
|
|
369
|
+
const uniAppX = Boolean(_optionalChain([options, 'optionalAccess', _14 => _14.uniAppX]));
|
|
272
370
|
let currentRule;
|
|
273
371
|
const parser = _postcssselectorparser2.default.call(void 0, (selectors) => {
|
|
274
372
|
const activeRule = currentRule;
|
|
@@ -278,13 +376,13 @@ function getFallbackRemove(_rule, options) {
|
|
|
278
376
|
maybeImportantId = true;
|
|
279
377
|
}
|
|
280
378
|
if (selector.type === "universal") {
|
|
281
|
-
_optionalChain([selector, 'access',
|
|
379
|
+
_optionalChain([selector, 'access', _15 => _15.parent, 'optionalAccess', _16 => _16.remove, 'call', _17 => _17()]);
|
|
282
380
|
} else if (selector.type === "pseudo") {
|
|
283
381
|
if (selector.value === ":is") {
|
|
284
|
-
if (maybeImportantId && _optionalChain([selector, 'access',
|
|
382
|
+
if (maybeImportantId && _optionalChain([selector, 'access', _18 => _18.nodes, 'access', _19 => _19[0], 'optionalAccess', _20 => _20.type]) === "selector") {
|
|
285
383
|
selector.replaceWith(selector.nodes[0]);
|
|
286
384
|
} else {
|
|
287
|
-
_optionalChain([selector, 'access',
|
|
385
|
+
_optionalChain([selector, 'access', _21 => _21.parent, 'optionalAccess', _22 => _22.remove, 'call', _23 => _23()]);
|
|
288
386
|
}
|
|
289
387
|
} else if (selector.value === ":not") {
|
|
290
388
|
for (const x of selector.nodes) {
|
|
@@ -307,7 +405,7 @@ function getFallbackRemove(_rule, options) {
|
|
|
307
405
|
}
|
|
308
406
|
} else if (selector.type === "attribute") {
|
|
309
407
|
if (selector.attribute === "hidden") {
|
|
310
|
-
_optionalChain([activeRule, 'optionalAccess',
|
|
408
|
+
_optionalChain([activeRule, 'optionalAccess', _24 => _24.remove, 'call', _25 => _25()]);
|
|
311
409
|
}
|
|
312
410
|
}
|
|
313
411
|
});
|
|
@@ -455,7 +553,7 @@ function dedupeSpacingProps(rule) {
|
|
|
455
553
|
if (alreadyOrdered) {
|
|
456
554
|
continue;
|
|
457
555
|
}
|
|
458
|
-
const anchor = _nullishCoalesce(_optionalChain([unique, 'access',
|
|
556
|
+
const anchor = _nullishCoalesce(_optionalChain([unique, 'access', _26 => _26[unique.length - 1], 'optionalAccess', _27 => _27.next, 'call', _28 => _28()]), () => ( void 0));
|
|
459
557
|
for (const decl of unique) {
|
|
460
558
|
decl.remove();
|
|
461
559
|
}
|
|
@@ -480,7 +578,7 @@ function isNotLastChildPseudo(node) {
|
|
|
480
578
|
if (firstSelector.type !== "selector") {
|
|
481
579
|
return false;
|
|
482
580
|
}
|
|
483
|
-
const target = _optionalChain([firstSelector, 'access',
|
|
581
|
+
const target = _optionalChain([firstSelector, 'access', _29 => _29.nodes, 'optionalAccess', _30 => _30[0]]);
|
|
484
582
|
return Boolean(target && target.type === "pseudo" && target.value === ":last-child");
|
|
485
583
|
}
|
|
486
584
|
function transformSpacingSelector(nodes2, options) {
|
|
@@ -527,7 +625,7 @@ function flattenWherePseudo(node, context, index, parent) {
|
|
|
527
625
|
node.value = ":is";
|
|
528
626
|
}
|
|
529
627
|
if (index === 0 && node.length === 1) {
|
|
530
|
-
const targetSelector = _optionalChain([node, 'access',
|
|
628
|
+
const targetSelector = _optionalChain([node, 'access', _31 => _31.nodes, 'optionalAccess', _32 => _32[0]]);
|
|
531
629
|
if (targetSelector && targetSelector.type === "selector" && transformSpacingSelector(targetSelector.nodes, context.options)) {
|
|
532
630
|
context.requiresSpacingNormalization = true;
|
|
533
631
|
}
|
|
@@ -547,7 +645,7 @@ function handleUniversalNode(node, context) {
|
|
|
547
645
|
if (node.type !== "universal") {
|
|
548
646
|
return;
|
|
549
647
|
}
|
|
550
|
-
const replacement = _optionalChain([context, 'access',
|
|
648
|
+
const replacement = _optionalChain([context, 'access', _33 => _33.options, 'access', _34 => _34.cssSelectorReplacement, 'optionalAccess', _35 => _35.universal]);
|
|
551
649
|
if (replacement) {
|
|
552
650
|
node.value = composeIsPseudo(replacement);
|
|
553
651
|
}
|
|
@@ -582,7 +680,7 @@ function handleCombinatorNode(node, index, context) {
|
|
|
582
680
|
if (node.type !== "combinator" || node.value !== ">") {
|
|
583
681
|
return;
|
|
584
682
|
}
|
|
585
|
-
const nodes2 = _optionalChain([node, 'access',
|
|
683
|
+
const nodes2 = _optionalChain([node, 'access', _36 => _36.parent, 'optionalAccess', _37 => _37.nodes]);
|
|
586
684
|
if (!nodes2) {
|
|
587
685
|
return;
|
|
588
686
|
}
|
|
@@ -598,7 +696,7 @@ function handlePseudoNode(node, index, context, parent) {
|
|
|
598
696
|
if (node.type !== "pseudo") {
|
|
599
697
|
return;
|
|
600
698
|
}
|
|
601
|
-
if (node.value === ":root" && _optionalChain([context, 'access',
|
|
699
|
+
if (node.value === ":root" && _optionalChain([context, 'access', _38 => _38.options, 'access', _39 => _39.cssSelectorReplacement, 'optionalAccess', _40 => _40.root])) {
|
|
602
700
|
node.value = composeIsPseudo(context.options.cssSelectorReplacement.root);
|
|
603
701
|
return;
|
|
604
702
|
}
|
|
@@ -625,7 +723,7 @@ function handleSelectorNode(selector, context) {
|
|
|
625
723
|
}
|
|
626
724
|
function transformSelectors(selectors, context) {
|
|
627
725
|
selectors.walk((node, index) => {
|
|
628
|
-
const parent = _optionalChain([node, 'access',
|
|
726
|
+
const parent = _optionalChain([node, 'access', _41 => _41.parent, 'optionalAccess', _42 => _42.type]) === "selector" ? node.parent : void 0;
|
|
629
727
|
switch (node.type) {
|
|
630
728
|
case "class":
|
|
631
729
|
handleClassNode(node, context);
|
|
@@ -703,7 +801,7 @@ function normalizeSelectorList(value) {
|
|
|
703
801
|
return Array.isArray(value) ? value.filter(Boolean) : [value];
|
|
704
802
|
}
|
|
705
803
|
function getSpecificityMatchingName(options) {
|
|
706
|
-
const feature = _optionalChain([options, 'access',
|
|
804
|
+
const feature = _optionalChain([options, 'access', _43 => _43.cssPresetEnv, 'optionalAccess', _44 => _44.features, 'optionalAccess', _45 => _45["is-pseudo-class"]]);
|
|
707
805
|
if (feature && typeof feature === "object" && "specificityMatchingName" in feature) {
|
|
708
806
|
const specificityName = feature.specificityMatchingName;
|
|
709
807
|
return typeof specificityName === "string" && specificityName.length > 0 ? specificityName : void 0;
|
|
@@ -712,12 +810,12 @@ function getSpecificityMatchingName(options) {
|
|
|
712
810
|
}
|
|
713
811
|
function createRootSpecificityCleaner(options) {
|
|
714
812
|
const specificityMatchingName = getSpecificityMatchingName(options);
|
|
715
|
-
const selectors = normalizeSelectorList(_optionalChain([options, 'access',
|
|
813
|
+
const selectors = normalizeSelectorList(_optionalChain([options, 'access', _46 => _46.cssSelectorReplacement, 'optionalAccess', _47 => _47.root]));
|
|
716
814
|
if (!specificityMatchingName || selectors.length === 0) {
|
|
717
815
|
return void 0;
|
|
718
816
|
}
|
|
719
817
|
const suffix = `:not(.${specificityMatchingName})`;
|
|
720
|
-
const targets = selectors.map((selector) => _optionalChain([selector, 'optionalAccess',
|
|
818
|
+
const targets = selectors.map((selector) => _optionalChain([selector, 'optionalAccess', _48 => _48.trim, 'call', _49 => _49()])).filter((selector) => Boolean(_optionalChain([selector, 'optionalAccess', _50 => _50.length]))).map((selector) => ({
|
|
721
819
|
match: `${selector}${suffix}`,
|
|
722
820
|
spacedMatch: `${selector} ${suffix}`,
|
|
723
821
|
replacement: selector
|
|
@@ -863,7 +961,7 @@ function dedupeDeclarations(rule) {
|
|
|
863
961
|
if (!needReorder) {
|
|
864
962
|
continue;
|
|
865
963
|
}
|
|
866
|
-
const anchor = _nullishCoalesce(_optionalChain([declarations, 'access',
|
|
964
|
+
const anchor = _nullishCoalesce(_optionalChain([declarations, 'access', _51 => _51[declarations.length - 1], 'optionalAccess', _52 => _52.next, 'call', _53 => _53()]), () => ( void 0));
|
|
867
965
|
for (const decl of declarations) {
|
|
868
966
|
decl.remove();
|
|
869
967
|
}
|
|
@@ -908,9 +1006,9 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
|
|
|
908
1006
|
const fallbackRemove = enableMainChunkTransforms ? getFallbackRemove(void 0, opts) : void 0;
|
|
909
1007
|
p.RuleExit = (rule) => {
|
|
910
1008
|
if (enableMainChunkTransforms) {
|
|
911
|
-
_optionalChain([fallbackRemove, 'optionalAccess',
|
|
1009
|
+
_optionalChain([fallbackRemove, 'optionalAccess', _54 => _54.transformSync, 'call', _55 => _55(rule)]);
|
|
912
1010
|
}
|
|
913
|
-
_optionalChain([cleanRootSpecificity, 'optionalCall',
|
|
1011
|
+
_optionalChain([cleanRootSpecificity, 'optionalCall', _56 => _56(rule)]);
|
|
914
1012
|
if (enableMainChunkTransforms) {
|
|
915
1013
|
dedupeDeclarations(rule);
|
|
916
1014
|
if (rule.selectors.length === 0 || rule.selectors.length === 1 && rule.selector.trim() === "") {
|
|
@@ -934,12 +1032,7 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
|
|
|
934
1032
|
if (opts.cssRemoveProperty && atRule.name === "property") {
|
|
935
1033
|
atRule.remove();
|
|
936
1034
|
}
|
|
937
|
-
_optionalChain([atRule, 'access',
|
|
938
|
-
};
|
|
939
|
-
}
|
|
940
|
-
if (typeof opts.customRuleCallback === "function") {
|
|
941
|
-
p.Rule = (rule) => {
|
|
942
|
-
_optionalChain([opts, 'access', _52 => _52.customRuleCallback, 'optionalCall', _53 => _53(rule, opts)]);
|
|
1035
|
+
_optionalChain([atRule, 'access', _57 => _57.nodes, 'optionalAccess', _58 => _58.length]) === 0 && atRule.remove();
|
|
943
1036
|
};
|
|
944
1037
|
}
|
|
945
1038
|
return p;
|
|
@@ -1380,7 +1473,7 @@ function remakeCssVarSelector(selectors, options) {
|
|
|
1380
1473
|
function commonChunkPreflight(node, options) {
|
|
1381
1474
|
const { ctx, cssInjectPreflight, injectAdditionalCssVarScope } = options;
|
|
1382
1475
|
if (testIfVariablesScope(node)) {
|
|
1383
|
-
_optionalChain([ctx, 'optionalAccess',
|
|
1476
|
+
_optionalChain([ctx, 'optionalAccess', _59 => _59.markVariablesScope, 'call', _60 => _60(node)]);
|
|
1384
1477
|
node.selectors = remakeCssVarSelector(node.selectors, options);
|
|
1385
1478
|
node.before(makePseudoVarRule());
|
|
1386
1479
|
if (typeof cssInjectPreflight === "function") {
|
|
@@ -1445,9 +1538,9 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
|
|
|
1445
1538
|
root.walkAtRules((atRule) => {
|
|
1446
1539
|
if (atRule.name === "layer") {
|
|
1447
1540
|
if (atRule.params === "properties") {
|
|
1448
|
-
if (atRule.nodes === void 0 || _optionalChain([atRule, 'access',
|
|
1541
|
+
if (atRule.nodes === void 0 || _optionalChain([atRule, 'access', _61 => _61.nodes, 'optionalAccess', _62 => _62.length]) === 0) {
|
|
1449
1542
|
layerProperties = atRule;
|
|
1450
|
-
} else if (_optionalChain([atRule, 'access',
|
|
1543
|
+
} else if (_optionalChain([atRule, 'access', _63 => _63.first, 'optionalAccess', _64 => _64.type]) === "atrule" && isTailwindcssV4ModernCheck(atRule.first)) {
|
|
1451
1544
|
if (layerProperties) {
|
|
1452
1545
|
layerProperties.replaceWith(atRule.first.nodes);
|
|
1453
1546
|
atRule.remove();
|
|
@@ -1459,7 +1552,7 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
|
|
|
1459
1552
|
atRule.replaceWith(atRule.nodes);
|
|
1460
1553
|
}
|
|
1461
1554
|
} else if (isTailwindcssV4ModernCheck(atRule)) {
|
|
1462
|
-
if (_optionalChain([atRule, 'access',
|
|
1555
|
+
if (_optionalChain([atRule, 'access', _65 => _65.first, 'optionalAccess', _66 => _66.type]) === "atrule" && atRule.first.name === "layer") {
|
|
1463
1556
|
atRule.replaceWith(atRule.first.nodes);
|
|
1464
1557
|
}
|
|
1465
1558
|
}
|
|
@@ -1504,7 +1597,7 @@ function createPipelineDefinitions(options) {
|
|
|
1504
1597
|
normal: [],
|
|
1505
1598
|
post: []
|
|
1506
1599
|
};
|
|
1507
|
-
const userPlugins = normalizeUserPlugins(_optionalChain([options, 'access',
|
|
1600
|
+
const userPlugins = normalizeUserPlugins(_optionalChain([options, 'access', _67 => _67.postcssOptions, 'optionalAccess', _68 => _68.plugins]));
|
|
1508
1601
|
userPlugins.forEach((plugin, index) => {
|
|
1509
1602
|
stages.pre.push(createStaticDefinition(`pre:user-${index}`, "pre", plugin));
|
|
1510
1603
|
});
|
|
@@ -1526,6 +1619,15 @@ function createPipelineDefinitions(options) {
|
|
|
1526
1619
|
createPlugin: () => _postcsspresetenv2.default.call(void 0, options.cssPresetEnv)
|
|
1527
1620
|
})
|
|
1528
1621
|
});
|
|
1622
|
+
stages.normal.push({
|
|
1623
|
+
id: "normal:color-functional-fallback",
|
|
1624
|
+
stage: "normal",
|
|
1625
|
+
prepare: () => ({
|
|
1626
|
+
id: "normal:color-functional-fallback",
|
|
1627
|
+
stage: "normal",
|
|
1628
|
+
createPlugin: () => createColorFunctionalFallback()
|
|
1629
|
+
})
|
|
1630
|
+
});
|
|
1529
1631
|
stages.normal.push({
|
|
1530
1632
|
id: "normal:px-transform",
|
|
1531
1633
|
stage: "normal",
|
|
@@ -1655,7 +1757,7 @@ function createInjectPreflight(options) {
|
|
|
1655
1757
|
function createProcessOptions(options) {
|
|
1656
1758
|
return {
|
|
1657
1759
|
from: void 0,
|
|
1658
|
-
..._nullishCoalesce(_optionalChain([options, 'access',
|
|
1760
|
+
..._nullishCoalesce(_optionalChain([options, 'access', _69 => _69.postcssOptions, 'optionalAccess', _70 => _70.options]), () => ( {}))
|
|
1659
1761
|
};
|
|
1660
1762
|
}
|
|
1661
1763
|
var pipelineCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -1670,7 +1772,7 @@ function getCachedPipeline(options) {
|
|
|
1670
1772
|
return pipeline;
|
|
1671
1773
|
}
|
|
1672
1774
|
function getCachedProcessOptions(options) {
|
|
1673
|
-
const source = _optionalChain([options, 'access',
|
|
1775
|
+
const source = _optionalChain([options, 'access', _71 => _71.postcssOptions, 'optionalAccess', _72 => _72.options]);
|
|
1674
1776
|
let cached = processOptionsCache.get(options);
|
|
1675
1777
|
const cachedSource = processOptionsSourceCache.get(options);
|
|
1676
1778
|
if (!cached || cachedSource !== source) {
|
package/dist/index.mjs
CHANGED
|
@@ -16,6 +16,7 @@ function getDefaultOptions(options) {
|
|
|
16
16
|
},
|
|
17
17
|
"oklab-function": true,
|
|
18
18
|
"color-mix": true,
|
|
19
|
+
"color-functional-notation": options?.cssPresetEnv?.features?.["color-functional-notation"] ?? { preserve: false },
|
|
19
20
|
// 在 calc 下,这个需要开启
|
|
20
21
|
"custom-properties": options?.cssPresetEnv?.features?.["custom-properties"] ?? options?.cssCalc ? { preserve: true } : false
|
|
21
22
|
},
|
|
@@ -37,6 +38,103 @@ function getDefaultOptions(options) {
|
|
|
37
38
|
// src/pipeline.ts
|
|
38
39
|
import postcssPresetEnv from "postcss-preset-env";
|
|
39
40
|
|
|
41
|
+
// src/plugins/colorFunctionalFallback.ts
|
|
42
|
+
import valueParser from "postcss-value-parser";
|
|
43
|
+
var RGB_FUNCTION_NAME = "rgb";
|
|
44
|
+
var isSlashDiv = (node) => node.type === "div" && node.value === "/";
|
|
45
|
+
function trimNodes(nodes2) {
|
|
46
|
+
let start = 0;
|
|
47
|
+
let end = nodes2.length;
|
|
48
|
+
while (start < end && nodes2[start]?.type === "space") {
|
|
49
|
+
start += 1;
|
|
50
|
+
}
|
|
51
|
+
while (end > start && nodes2[end - 1]?.type === "space") {
|
|
52
|
+
end -= 1;
|
|
53
|
+
}
|
|
54
|
+
return nodes2.slice(start, end);
|
|
55
|
+
}
|
|
56
|
+
function splitColorComponents(nodes2) {
|
|
57
|
+
const parts = [];
|
|
58
|
+
let current = [];
|
|
59
|
+
nodes2.forEach((node) => {
|
|
60
|
+
if (node.type === "div" && node.value === ",") {
|
|
61
|
+
if (current.length) {
|
|
62
|
+
parts.push(current);
|
|
63
|
+
current = [];
|
|
64
|
+
}
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (node.type === "space") {
|
|
68
|
+
if (current.length) {
|
|
69
|
+
parts.push(current);
|
|
70
|
+
current = [];
|
|
71
|
+
}
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
current.push(node);
|
|
75
|
+
});
|
|
76
|
+
if (current.length) {
|
|
77
|
+
parts.push(current);
|
|
78
|
+
}
|
|
79
|
+
return parts;
|
|
80
|
+
}
|
|
81
|
+
var buildFunctionNodes = (content) => valueParser(content).nodes;
|
|
82
|
+
function convertRgbFunction(fnNode) {
|
|
83
|
+
const slashIndex = fnNode.nodes.findIndex(isSlashDiv);
|
|
84
|
+
if (slashIndex === -1) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
const colorNodes = trimNodes(fnNode.nodes.slice(0, slashIndex));
|
|
88
|
+
const alphaNodes = trimNodes(fnNode.nodes.slice(slashIndex + 1));
|
|
89
|
+
if (!colorNodes.length || !alphaNodes.length) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
const colorParts = splitColorComponents(colorNodes);
|
|
93
|
+
if (colorParts.length !== 3) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
const normalizedColors = colorParts.map((part) => valueParser.stringify(part).trim()).filter(Boolean);
|
|
97
|
+
if (normalizedColors.length !== 3) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
const alphaText = valueParser.stringify(alphaNodes).trim();
|
|
101
|
+
if (!alphaText) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
fnNode.value = "rgba";
|
|
105
|
+
const nextValue = `${normalizedColors.join(", ")}, ${alphaText}`;
|
|
106
|
+
fnNode.nodes = buildFunctionNodes(nextValue);
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
function transformDeclaration(decl) {
|
|
110
|
+
if (!decl.value || !decl.value.toLowerCase().includes(RGB_FUNCTION_NAME)) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const parsed = valueParser(decl.value);
|
|
114
|
+
let mutated = false;
|
|
115
|
+
parsed.walk((node) => {
|
|
116
|
+
if (node.type !== "function") {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (node.value.toLowerCase() !== RGB_FUNCTION_NAME) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (convertRgbFunction(node)) {
|
|
123
|
+
mutated = true;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
if (mutated) {
|
|
127
|
+
decl.value = parsed.toString();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function createColorFunctionalFallback() {
|
|
131
|
+
return {
|
|
132
|
+
postcssPlugin: "weapp-tailwindcss-color-functional-fallback",
|
|
133
|
+
Declaration: transformDeclaration
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
createColorFunctionalFallback.postcss = true;
|
|
137
|
+
|
|
40
138
|
// src/plugins/ctx.ts
|
|
41
139
|
function createContext() {
|
|
42
140
|
const variablesScopeWeakMap = /* @__PURE__ */ new WeakMap();
|
|
@@ -77,7 +175,7 @@ function getCalcPlugin(options) {
|
|
|
77
175
|
|
|
78
176
|
// src/plugins/getCustomPropertyCleaner.ts
|
|
79
177
|
import { regExpTest } from "@weapp-tailwindcss/shared";
|
|
80
|
-
import
|
|
178
|
+
import valueParser2 from "postcss-value-parser";
|
|
81
179
|
function getCustomPropertyCleaner(options) {
|
|
82
180
|
const includeCustomProperties = Array.isArray(options.cssCalc) ? options.cssCalc : typeof options.cssCalc === "object" ? options.cssCalc.includeCustomProperties : [];
|
|
83
181
|
const shouldMatchCustomProperties = Array.isArray(includeCustomProperties) && includeCustomProperties.length > 0;
|
|
@@ -99,7 +197,7 @@ function getCustomPropertyCleaner(options) {
|
|
|
99
197
|
if (!shouldMatchCustomProperties || !/--/.test(decl.value)) {
|
|
100
198
|
return;
|
|
101
199
|
}
|
|
102
|
-
const parsed =
|
|
200
|
+
const parsed = valueParser2(decl.value);
|
|
103
201
|
let containsIncludedCustomProperty = false;
|
|
104
202
|
parsed.walk((node) => {
|
|
105
203
|
if (node.type !== "function" || node.value !== "var" || containsIncludedCustomProperty) {
|
|
@@ -937,11 +1035,6 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
|
|
|
937
1035
|
atRule.nodes?.length === 0 && atRule.remove();
|
|
938
1036
|
};
|
|
939
1037
|
}
|
|
940
|
-
if (typeof opts.customRuleCallback === "function") {
|
|
941
|
-
p.Rule = (rule) => {
|
|
942
|
-
opts.customRuleCallback?.(rule, opts);
|
|
943
|
-
};
|
|
944
|
-
}
|
|
945
1038
|
return p;
|
|
946
1039
|
};
|
|
947
1040
|
postcssWeappTailwindcssPostPlugin.postcss = true;
|
|
@@ -1526,6 +1619,15 @@ function createPipelineDefinitions(options) {
|
|
|
1526
1619
|
createPlugin: () => postcssPresetEnv(options.cssPresetEnv)
|
|
1527
1620
|
})
|
|
1528
1621
|
});
|
|
1622
|
+
stages.normal.push({
|
|
1623
|
+
id: "normal:color-functional-fallback",
|
|
1624
|
+
stage: "normal",
|
|
1625
|
+
prepare: () => ({
|
|
1626
|
+
id: "normal:color-functional-fallback",
|
|
1627
|
+
stage: "normal",
|
|
1628
|
+
createPlugin: () => createColorFunctionalFallback()
|
|
1629
|
+
})
|
|
1630
|
+
});
|
|
1529
1631
|
stages.normal.push({
|
|
1530
1632
|
id: "normal:px-transform",
|
|
1531
1633
|
stage: "normal",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PostCssCalcOptions } from '@weapp-tailwindcss/postcss-calc';
|
|
2
|
-
import { AcceptedPlugin,
|
|
2
|
+
import { AcceptedPlugin, Result as Result$1 } from 'postcss';
|
|
3
3
|
import { Result } from 'postcss-load-config';
|
|
4
4
|
import { pluginOptions } from 'postcss-preset-env';
|
|
5
5
|
import { PxtransformOptions } from 'postcss-pxtransform';
|
|
@@ -58,7 +58,6 @@ type InjectPreflight = () => IPropValue[];
|
|
|
58
58
|
declare function createInjectPreflight(options?: CssPreflightOptions): InjectPreflight;
|
|
59
59
|
|
|
60
60
|
type LoadedPostcssOptions = Partial<Omit<Result, 'file'>>;
|
|
61
|
-
type CustomRuleCallback = (node: Rule, options: Readonly<UserDefinedPostcssOptions>) => void;
|
|
62
61
|
interface IPropValue {
|
|
63
62
|
prop: string;
|
|
64
63
|
value: string;
|
|
@@ -82,7 +81,6 @@ interface CssCalcOptions extends PostCssCalcOptions {
|
|
|
82
81
|
includeCustomProperties?: (string | RegExp)[];
|
|
83
82
|
}
|
|
84
83
|
type IStyleHandlerOptions = {
|
|
85
|
-
customRuleCallback?: CustomRuleCallback;
|
|
86
84
|
ctx?: IContext;
|
|
87
85
|
postcssOptions?: LoadedPostcssOptions;
|
|
88
86
|
cssRemoveProperty?: boolean;
|
|
@@ -112,7 +110,6 @@ interface UserDefinedPostcssOptions {
|
|
|
112
110
|
postcssOptions?: LoadedPostcssOptions;
|
|
113
111
|
cssRemoveHoverPseudoClass?: boolean;
|
|
114
112
|
cssRemoveProperty?: boolean;
|
|
115
|
-
customRuleCallback?: CustomRuleCallback;
|
|
116
113
|
uniAppX?: boolean;
|
|
117
114
|
}
|
|
118
115
|
|
|
@@ -121,4 +118,4 @@ interface StyleHandler {
|
|
|
121
118
|
getPipeline: (opt?: Partial<IStyleHandlerOptions>) => StyleProcessingPipeline;
|
|
122
119
|
}
|
|
123
120
|
|
|
124
|
-
export { type CssCalcOptions as C, type IStyleHandlerOptions as I, type LoadedPostcssOptions as L, type PipelineNodeContext as P, type ResolvedPipelineNode as R, type StyleHandler as S, type UserDefinedPostcssOptions as U, type InternalCssSelectorReplacerOptions as a, type PipelineNodeCursor as b, createStylePipeline as c, type PipelineStage as d, type StyleProcessingPipeline as e, createInjectPreflight as f, type
|
|
121
|
+
export { type CssCalcOptions as C, type IStyleHandlerOptions as I, type LoadedPostcssOptions as L, type PipelineNodeContext as P, type ResolvedPipelineNode as R, type StyleHandler as S, type UserDefinedPostcssOptions as U, type InternalCssSelectorReplacerOptions as a, type PipelineNodeCursor as b, createStylePipeline as c, type PipelineStage as d, type StyleProcessingPipeline as e, createInjectPreflight as f, type IPropValue as g, type CssPreflightOptions as h, type RequiredStyleHandlerOptions as i };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PostCssCalcOptions } from '@weapp-tailwindcss/postcss-calc';
|
|
2
|
-
import { AcceptedPlugin,
|
|
2
|
+
import { AcceptedPlugin, Result as Result$1 } from 'postcss';
|
|
3
3
|
import { Result } from 'postcss-load-config';
|
|
4
4
|
import { pluginOptions } from 'postcss-preset-env';
|
|
5
5
|
import { PxtransformOptions } from 'postcss-pxtransform';
|
|
@@ -58,7 +58,6 @@ type InjectPreflight = () => IPropValue[];
|
|
|
58
58
|
declare function createInjectPreflight(options?: CssPreflightOptions): InjectPreflight;
|
|
59
59
|
|
|
60
60
|
type LoadedPostcssOptions = Partial<Omit<Result, 'file'>>;
|
|
61
|
-
type CustomRuleCallback = (node: Rule, options: Readonly<UserDefinedPostcssOptions>) => void;
|
|
62
61
|
interface IPropValue {
|
|
63
62
|
prop: string;
|
|
64
63
|
value: string;
|
|
@@ -82,7 +81,6 @@ interface CssCalcOptions extends PostCssCalcOptions {
|
|
|
82
81
|
includeCustomProperties?: (string | RegExp)[];
|
|
83
82
|
}
|
|
84
83
|
type IStyleHandlerOptions = {
|
|
85
|
-
customRuleCallback?: CustomRuleCallback;
|
|
86
84
|
ctx?: IContext;
|
|
87
85
|
postcssOptions?: LoadedPostcssOptions;
|
|
88
86
|
cssRemoveProperty?: boolean;
|
|
@@ -112,7 +110,6 @@ interface UserDefinedPostcssOptions {
|
|
|
112
110
|
postcssOptions?: LoadedPostcssOptions;
|
|
113
111
|
cssRemoveHoverPseudoClass?: boolean;
|
|
114
112
|
cssRemoveProperty?: boolean;
|
|
115
|
-
customRuleCallback?: CustomRuleCallback;
|
|
116
113
|
uniAppX?: boolean;
|
|
117
114
|
}
|
|
118
115
|
|
|
@@ -121,4 +118,4 @@ interface StyleHandler {
|
|
|
121
118
|
getPipeline: (opt?: Partial<IStyleHandlerOptions>) => StyleProcessingPipeline;
|
|
122
119
|
}
|
|
123
120
|
|
|
124
|
-
export { type CssCalcOptions as C, type IStyleHandlerOptions as I, type LoadedPostcssOptions as L, type PipelineNodeContext as P, type ResolvedPipelineNode as R, type StyleHandler as S, type UserDefinedPostcssOptions as U, type InternalCssSelectorReplacerOptions as a, type PipelineNodeCursor as b, createStylePipeline as c, type PipelineStage as d, type StyleProcessingPipeline as e, createInjectPreflight as f, type
|
|
121
|
+
export { type CssCalcOptions as C, type IStyleHandlerOptions as I, type LoadedPostcssOptions as L, type PipelineNodeContext as P, type ResolvedPipelineNode as R, type StyleHandler as S, type UserDefinedPostcssOptions as U, type InternalCssSelectorReplacerOptions as a, type PipelineNodeCursor as b, createStylePipeline as c, type PipelineStage as d, type StyleProcessingPipeline as e, createInjectPreflight as f, type IPropValue as g, type CssPreflightOptions as h, type RequiredStyleHandlerOptions as i };
|
package/dist/types.d.mts
CHANGED
|
@@ -4,4 +4,4 @@ import 'postcss-load-config';
|
|
|
4
4
|
export { pluginOptions as PresetEnvOptions } from 'postcss-preset-env';
|
|
5
5
|
export { PxtransformOptions as Px2rpxOptions } from 'postcss-pxtransform';
|
|
6
6
|
export { UserDefinedOptions as Rem2rpxOptions } from 'postcss-rem-to-responsive-pixel';
|
|
7
|
-
export { C as CssCalcOptions,
|
|
7
|
+
export { C as CssCalcOptions, h as CssPreflightOptions, g as IPropValue, I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions, L as LoadedPostcssOptions, i as RequiredStyleHandlerOptions, S as StyleHandler, U as UserDefinedPostcssOptions } from './types-6NcGD9Zr.mjs';
|
package/dist/types.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ import 'postcss-load-config';
|
|
|
4
4
|
export { pluginOptions as PresetEnvOptions } from 'postcss-preset-env';
|
|
5
5
|
export { PxtransformOptions as Px2rpxOptions } from 'postcss-pxtransform';
|
|
6
6
|
export { UserDefinedOptions as Rem2rpxOptions } from 'postcss-rem-to-responsive-pixel';
|
|
7
|
-
export { C as CssCalcOptions,
|
|
7
|
+
export { C as CssCalcOptions, h as CssPreflightOptions, g as IPropValue, I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions, L as LoadedPostcssOptions, i as RequiredStyleHandlerOptions, S as StyleHandler, U as UserDefinedPostcssOptions } from './types-6NcGD9Zr.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-tailwindcss/postcss",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "@weapp-tailwindcss/postcss",
|
|
5
5
|
"author": "ice breaker <1324318532@qq.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"dist"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@weapp-core/escape": "~
|
|
42
|
+
"@weapp-core/escape": "~5.0.1",
|
|
43
43
|
"@weapp-tailwindcss/postcss-calc": "^1.0.0",
|
|
44
44
|
"postcss": "~8.5.6",
|
|
45
45
|
"postcss-preset-env": "^10.4.0",
|