@weapp-tailwindcss/postcss 1.1.1 → 1.2.0
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 +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +84 -38
- package/dist/index.mjs +62 -16
- package/dist/{types-tu70dcVo.d.mts → types-C5X6IWCb.d.mts} +5 -1
- package/dist/{types-tu70dcVo.d.ts → types-C5X6IWCb.d.ts} +5 -1
- package/dist/types.d.mts +3 -1
- package/dist/types.d.ts +3 -1
- package/package.json +4 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions } from './types-
|
|
2
|
-
export { d as CssPreflightOptions, C as CustomRuleCallback, b as IPropValue, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions, c as createInjectPreflight } from './types-
|
|
1
|
+
import { I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions } from './types-C5X6IWCb.mjs';
|
|
2
|
+
export { d as CssPreflightOptions, C as CustomRuleCallback, b as IPropValue, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions, c as createInjectPreflight } from './types-C5X6IWCb.mjs';
|
|
3
3
|
import postcss from 'postcss';
|
|
4
4
|
import '@weapp-tailwindcss/mangle';
|
|
5
|
+
import '@weapp-tailwindcss/postcss-calc';
|
|
5
6
|
import 'postcss-load-config';
|
|
6
7
|
import 'postcss-preset-env';
|
|
8
|
+
import 'postcss-pxtransform';
|
|
7
9
|
import 'postcss-rem-to-responsive-pixel';
|
|
8
10
|
|
|
9
|
-
declare function createStyleHandler(options
|
|
11
|
+
declare function createStyleHandler(options?: Partial<IStyleHandlerOptions>): (rawSource: string, opt?: Partial<IStyleHandlerOptions>) => Promise<postcss.Result<postcss.Document | postcss.Root>>;
|
|
10
12
|
|
|
11
13
|
declare function internalCssSelectorReplacer(selectors: string, options?: InternalCssSelectorReplacerOptions): string;
|
|
12
14
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions } from './types-
|
|
2
|
-
export { d as CssPreflightOptions, C as CustomRuleCallback, b as IPropValue, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions, c as createInjectPreflight } from './types-
|
|
1
|
+
import { I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions } from './types-C5X6IWCb.js';
|
|
2
|
+
export { d as CssPreflightOptions, C as CustomRuleCallback, b as IPropValue, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions, c as createInjectPreflight } from './types-C5X6IWCb.js';
|
|
3
3
|
import postcss from 'postcss';
|
|
4
4
|
import '@weapp-tailwindcss/mangle';
|
|
5
|
+
import '@weapp-tailwindcss/postcss-calc';
|
|
5
6
|
import 'postcss-load-config';
|
|
6
7
|
import 'postcss-preset-env';
|
|
8
|
+
import 'postcss-pxtransform';
|
|
7
9
|
import 'postcss-rem-to-responsive-pixel';
|
|
8
10
|
|
|
9
|
-
declare function createStyleHandler(options
|
|
11
|
+
declare function createStyleHandler(options?: Partial<IStyleHandlerOptions>): (rawSource: string, opt?: Partial<IStyleHandlerOptions>) => Promise<postcss.Result<postcss.Document | postcss.Root>>;
|
|
10
12
|
|
|
11
13
|
declare function internalCssSelectorReplacer(selectors: string, options?: InternalCssSelectorReplacerOptions): string;
|
|
12
14
|
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var _shared = require('@weapp-tailwindcss/shared');
|
|
|
5
5
|
var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postcss);
|
|
6
6
|
|
|
7
7
|
// src/defaults.ts
|
|
8
|
-
function getDefaultOptions() {
|
|
8
|
+
function getDefaultOptions(options) {
|
|
9
9
|
return {
|
|
10
10
|
// https://github.com/postcss/postcss-calc
|
|
11
11
|
cssPresetEnv: {
|
|
@@ -16,12 +16,14 @@ function getDefaultOptions() {
|
|
|
16
16
|
},
|
|
17
17
|
"oklab-function": true,
|
|
18
18
|
"color-mix": true,
|
|
19
|
-
|
|
19
|
+
// 在 calc 下,这个需要开启
|
|
20
|
+
"custom-properties": _optionalChain([options, 'optionalAccess', _ => _.cssCalc]) ? { preserve: false } : _nullishCoalesce(_optionalChain([options, 'optionalAccess', _2 => _2.cssPresetEnv, 'optionalAccess', _3 => _3.features, 'optionalAccess', _4 => _4["custom-properties"]]), () => ( false))
|
|
20
21
|
},
|
|
21
22
|
autoprefixer: {
|
|
22
23
|
add: false
|
|
23
24
|
}
|
|
24
25
|
},
|
|
26
|
+
// 支付宝小程序不支持,所以默认关闭
|
|
25
27
|
cssRemoveProperty: true,
|
|
26
28
|
// cssRemoveAtSupports: true,
|
|
27
29
|
// cssRemoveAtMedia: true,
|
|
@@ -33,7 +35,10 @@ function getDefaultOptions() {
|
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
// src/plugins/index.ts
|
|
38
|
+
var _postcsscalc = require('@weapp-tailwindcss/postcss-calc'); var _postcsscalc2 = _interopRequireDefault(_postcsscalc);
|
|
39
|
+
|
|
36
40
|
var _postcsspresetenv = require('postcss-preset-env'); var _postcsspresetenv2 = _interopRequireDefault(_postcsspresetenv);
|
|
41
|
+
var _postcsspxtransform = require('postcss-pxtransform'); var _postcsspxtransform2 = _interopRequireDefault(_postcsspxtransform);
|
|
37
42
|
var _postcssremtoresponsivepixel = require('postcss-rem-to-responsive-pixel'); var _postcssremtoresponsivepixel2 = _interopRequireDefault(_postcssremtoresponsivepixel);
|
|
38
43
|
|
|
39
44
|
// src/plugins/ctx.ts
|
|
@@ -133,7 +138,7 @@ function createRuleTransform(rule, options) {
|
|
|
133
138
|
mangleContext
|
|
134
139
|
});
|
|
135
140
|
} else if (selector.type === "universal") {
|
|
136
|
-
if (_optionalChain([cssSelectorReplacement, 'optionalAccess',
|
|
141
|
+
if (_optionalChain([cssSelectorReplacement, 'optionalAccess', _5 => _5.universal])) {
|
|
137
142
|
selector.value = composeIsPseudo(cssSelectorReplacement.universal);
|
|
138
143
|
}
|
|
139
144
|
} else if (selector.type === "selector") {
|
|
@@ -144,7 +149,7 @@ function createRuleTransform(rule, options) {
|
|
|
144
149
|
}
|
|
145
150
|
}
|
|
146
151
|
} else if (selector.type === "pseudo") {
|
|
147
|
-
if (selector.value === ":root" && _optionalChain([cssSelectorReplacement, 'optionalAccess',
|
|
152
|
+
if (selector.value === ":root" && _optionalChain([cssSelectorReplacement, 'optionalAccess', _6 => _6.root])) {
|
|
148
153
|
selector.value = composeIsPseudo(cssSelectorReplacement.root);
|
|
149
154
|
} else if (selector.value === ":where") {
|
|
150
155
|
if (uniAppX) {
|
|
@@ -153,7 +158,7 @@ function createRuleTransform(rule, options) {
|
|
|
153
158
|
if (index === 0 && selector.length === 1) {
|
|
154
159
|
selector.walk((node, idx) => {
|
|
155
160
|
if (idx === 0 && node.type === "class") {
|
|
156
|
-
const nodes2 = _optionalChain([node, 'access',
|
|
161
|
+
const nodes2 = _optionalChain([node, 'access', _7 => _7.parent, 'optionalAccess', _8 => _8.nodes]);
|
|
157
162
|
if (nodes2) {
|
|
158
163
|
const first = nodes2[idx + 1];
|
|
159
164
|
if (first && first.type === "combinator" && first.value === ">") {
|
|
@@ -196,7 +201,7 @@ function createRuleTransform(rule, options) {
|
|
|
196
201
|
}
|
|
197
202
|
} else if (selector.type === "combinator") {
|
|
198
203
|
if (selector.value === ">") {
|
|
199
|
-
const nodes2 = _optionalChain([selector, 'access',
|
|
204
|
+
const nodes2 = _optionalChain([selector, 'access', _9 => _9.parent, 'optionalAccess', _10 => _10.nodes]);
|
|
200
205
|
if (nodes2) {
|
|
201
206
|
const first = nodes2[index + 1];
|
|
202
207
|
if (first && first.type === "pseudo" && first.value === ":not" && (first.first.first.type === "attribute" && first.first.first.attribute === "hidden" || first.first.first.type === "tag" && first.first.first.value === "template")) {
|
|
@@ -205,7 +210,7 @@ function createRuleTransform(rule, options) {
|
|
|
205
210
|
const third = nodes2[index + 3];
|
|
206
211
|
if (third && third.type === "pseudo" && third.value === ":not" && (third.first.first.type === "attribute" && third.first.first.attribute === "hidden" || third.first.first.type === "tag" && third.first.first.value === "template")) {
|
|
207
212
|
const ast = getCombinatorSelectorAst(options);
|
|
208
|
-
_optionalChain([selector, 'access',
|
|
213
|
+
_optionalChain([selector, 'access', _11 => _11.parent, 'optionalAccess', _12 => _12.nodes, 'access', _13 => _13.splice, 'call', _14 => _14(
|
|
209
214
|
index + 1,
|
|
210
215
|
3,
|
|
211
216
|
...ast
|
|
@@ -248,7 +253,7 @@ function isOnlyBeforeAndAfterPseudoElement(node) {
|
|
|
248
253
|
let a = false;
|
|
249
254
|
_postcssselectorparser2.default.call(void 0, (selectors) => {
|
|
250
255
|
selectors.walkPseudos((s) => {
|
|
251
|
-
if (_optionalChain([s, 'access',
|
|
256
|
+
if (_optionalChain([s, 'access', _15 => _15.parent, 'optionalAccess', _16 => _16.length]) === 1) {
|
|
252
257
|
if (/^:?:before$/.test(s.value)) {
|
|
253
258
|
b = true;
|
|
254
259
|
}
|
|
@@ -269,13 +274,13 @@ function getFallbackRemove(rule, options) {
|
|
|
269
274
|
maybeImportantId = true;
|
|
270
275
|
}
|
|
271
276
|
if (selector.type === "universal") {
|
|
272
|
-
_optionalChain([selector, 'access',
|
|
277
|
+
_optionalChain([selector, 'access', _17 => _17.parent, 'optionalAccess', _18 => _18.remove, 'call', _19 => _19()]);
|
|
273
278
|
} else if (selector.type === "pseudo") {
|
|
274
279
|
if (selector.value === ":is") {
|
|
275
|
-
if (maybeImportantId && _optionalChain([selector, 'access',
|
|
280
|
+
if (maybeImportantId && _optionalChain([selector, 'access', _20 => _20.nodes, 'access', _21 => _21[0], 'optionalAccess', _22 => _22.type]) === "selector") {
|
|
276
281
|
selector.replaceWith(selector.nodes[0]);
|
|
277
282
|
} else {
|
|
278
|
-
_optionalChain([selector, 'access',
|
|
283
|
+
_optionalChain([selector, 'access', _23 => _23.parent, 'optionalAccess', _24 => _24.remove, 'call', _25 => _25()]);
|
|
279
284
|
}
|
|
280
285
|
} else if (selector.value === ":not") {
|
|
281
286
|
for (const x of selector.nodes) {
|
|
@@ -298,7 +303,7 @@ function getFallbackRemove(rule, options) {
|
|
|
298
303
|
}
|
|
299
304
|
} else if (selector.type === "attribute") {
|
|
300
305
|
if (selector.attribute === "hidden") {
|
|
301
|
-
_optionalChain([rule, 'optionalAccess',
|
|
306
|
+
_optionalChain([rule, 'optionalAccess', _26 => _26.remove, 'call', _27 => _27()]);
|
|
302
307
|
}
|
|
303
308
|
}
|
|
304
309
|
});
|
|
@@ -347,7 +352,7 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
|
|
|
347
352
|
p.DeclarationExit = (decl) => {
|
|
348
353
|
if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OklabSuffix)) {
|
|
349
354
|
decl.value = decl.value.slice(0, decl.value.length - OklabSuffix.length);
|
|
350
|
-
} else if (/calc\(\s*infinity\s*\*\s*
|
|
355
|
+
} else if (/calc\(\s*infinity\s*\*\s*(?:\d+(?:\.\d*)?|\.\d+)r?px/.test(decl.value)) {
|
|
351
356
|
decl.value = "9999px";
|
|
352
357
|
}
|
|
353
358
|
};
|
|
@@ -355,12 +360,12 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
|
|
|
355
360
|
if (opts.cssRemoveProperty && atRule.name === "property") {
|
|
356
361
|
atRule.remove();
|
|
357
362
|
}
|
|
358
|
-
_optionalChain([atRule, 'access',
|
|
363
|
+
_optionalChain([atRule, 'access', _28 => _28.nodes, 'optionalAccess', _29 => _29.length]) === 0 && atRule.remove();
|
|
359
364
|
};
|
|
360
365
|
}
|
|
361
366
|
if (typeof opts.customRuleCallback === "function") {
|
|
362
367
|
p.Rule = (rule) => {
|
|
363
|
-
_optionalChain([opts, 'access',
|
|
368
|
+
_optionalChain([opts, 'access', _30 => _30.customRuleCallback, 'optionalCall', _31 => _31(rule, opts)]);
|
|
364
369
|
};
|
|
365
370
|
}
|
|
366
371
|
return p;
|
|
@@ -801,7 +806,7 @@ function remakeCssVarSelector(selectors, options) {
|
|
|
801
806
|
function commonChunkPreflight(node, options) {
|
|
802
807
|
const { ctx, cssInjectPreflight, injectAdditionalCssVarScope } = options;
|
|
803
808
|
if (testIfVariablesScope(node)) {
|
|
804
|
-
_optionalChain([ctx, 'optionalAccess',
|
|
809
|
+
_optionalChain([ctx, 'optionalAccess', _32 => _32.markVariablesScope, 'call', _33 => _33(node)]);
|
|
805
810
|
node.selectors = remakeCssVarSelector(node.selectors, options);
|
|
806
811
|
node.before(makePseudoVarRule());
|
|
807
812
|
if (typeof cssInjectPreflight === "function") {
|
|
@@ -866,9 +871,9 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
|
|
|
866
871
|
root.walkAtRules((atRule) => {
|
|
867
872
|
if (atRule.name === "layer") {
|
|
868
873
|
if (atRule.params === "properties") {
|
|
869
|
-
if (atRule.nodes === void 0 || _optionalChain([atRule, 'access',
|
|
874
|
+
if (atRule.nodes === void 0 || _optionalChain([atRule, 'access', _34 => _34.nodes, 'optionalAccess', _35 => _35.length]) === 0) {
|
|
870
875
|
layerProperties = atRule;
|
|
871
|
-
} else if (_optionalChain([atRule, 'access',
|
|
876
|
+
} else if (_optionalChain([atRule, 'access', _36 => _36.first, 'optionalAccess', _37 => _37.type]) === "atrule" && isTailwindcssV4ModernCheck(atRule.first)) {
|
|
872
877
|
if (layerProperties) {
|
|
873
878
|
layerProperties.replaceWith(atRule.first.nodes);
|
|
874
879
|
atRule.remove();
|
|
@@ -880,7 +885,7 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
|
|
|
880
885
|
atRule.replaceWith(atRule.nodes);
|
|
881
886
|
}
|
|
882
887
|
} else if (isTailwindcssV4ModernCheck(atRule)) {
|
|
883
|
-
if (_optionalChain([atRule, 'access',
|
|
888
|
+
if (_optionalChain([atRule, 'access', _38 => _38.first, 'optionalAccess', _39 => _39.type]) === "atrule" && atRule.first.name === "layer") {
|
|
884
889
|
atRule.replaceWith(atRule.first.nodes);
|
|
885
890
|
}
|
|
886
891
|
}
|
|
@@ -903,7 +908,7 @@ function compare(e3, t) {
|
|
|
903
908
|
return e3.a === t.a ? e3.b === t.b ? e3.c - t.c : e3.b - t.b : e3.a - t.a;
|
|
904
909
|
}
|
|
905
910
|
function selectorSpecificity(t, s) {
|
|
906
|
-
const i = _optionalChain([s, 'optionalAccess',
|
|
911
|
+
const i = _optionalChain([s, 'optionalAccess', _40 => _40.customSpecificity, 'optionalCall', _41 => _41(t)]);
|
|
907
912
|
if (i) return i;
|
|
908
913
|
if (!t) return { a: 0, b: 0, c: 0 };
|
|
909
914
|
let c = 0, n2 = 0, o2 = 0;
|
|
@@ -979,7 +984,7 @@ function selectorSpecificity(t, s) {
|
|
|
979
984
|
case ":active-view-transition-type":
|
|
980
985
|
return { a: 0, b: 1, c: 0 };
|
|
981
986
|
}
|
|
982
|
-
else _postcssselectorparser2.default.isContainer(t) && _optionalChain([t, 'access',
|
|
987
|
+
else _postcssselectorparser2.default.isContainer(t) && _optionalChain([t, 'access', _42 => _42.nodes, 'optionalAccess', _43 => _43.length]) > 0 && t.nodes.forEach(((e3) => {
|
|
983
988
|
const t2 = selectorSpecificity(e3, s);
|
|
984
989
|
c += t2.a, n2 += t2.b, o2 += t2.c;
|
|
985
990
|
}));
|
|
@@ -1007,8 +1012,8 @@ function alwaysValidSelector(s) {
|
|
|
1007
1012
|
const o2 = _postcssselectorparser2.default.call(void 0, ).astSync(s);
|
|
1008
1013
|
let n2 = true;
|
|
1009
1014
|
return o2.walk(((e3) => {
|
|
1010
|
-
if ("class" !== e3.type && "comment" !== e3.type && "id" !== e3.type && "root" !== e3.type && "selector" !== e3.type && "string" !== e3.type && "tag" !== e3.type && "universal" !== e3.type && ("attribute" !== e3.type || e3.insensitive) && ("combinator" !== e3.type || "+" !== e3.value && ">" !== e3.value && "~" !== e3.value && " " !== e3.value) && ("pseudo" !== e3.type || _optionalChain([e3, 'access',
|
|
1011
|
-
if ("pseudo" === e3.type && 1 === _optionalChain([e3, 'access',
|
|
1015
|
+
if ("class" !== e3.type && "comment" !== e3.type && "id" !== e3.type && "root" !== e3.type && "selector" !== e3.type && "string" !== e3.type && "tag" !== e3.type && "universal" !== e3.type && ("attribute" !== e3.type || e3.insensitive) && ("combinator" !== e3.type || "+" !== e3.value && ">" !== e3.value && "~" !== e3.value && " " !== e3.value) && ("pseudo" !== e3.type || _optionalChain([e3, 'access', _44 => _44.nodes, 'optionalAccess', _45 => _45.length]) || ":hover" !== e3.value.toLowerCase() && ":focus" !== e3.value.toLowerCase())) {
|
|
1016
|
+
if ("pseudo" === e3.type && 1 === _optionalChain([e3, 'access', _46 => _46.nodes, 'optionalAccess', _47 => _47.length]) && ":not" === e3.value.toLowerCase()) {
|
|
1012
1017
|
let s2 = true;
|
|
1013
1018
|
if (e3.nodes[0].walkCombinators((() => {
|
|
1014
1019
|
s2 = false;
|
|
@@ -1159,8 +1164,8 @@ function splitSelectors(o2, n2, t = 0) {
|
|
|
1159
1164
|
if (_postcssselectorparser2.default.call(void 0, ).astSync(o3).walkPseudos(((e3) => {
|
|
1160
1165
|
if (":is" !== e3.value.toLowerCase() || !e3.nodes || !e3.nodes.length) return;
|
|
1161
1166
|
if ("selector" === e3.nodes[0].type && 0 === e3.nodes[0].nodes.length) return;
|
|
1162
|
-
if ("pseudo" === _optionalChain([e3, 'access',
|
|
1163
|
-
if ("pseudo" === _optionalChain([e3, 'access',
|
|
1167
|
+
if ("pseudo" === _optionalChain([e3, 'access', _48 => _48.parent, 'optionalAccess', _49 => _49.parent, 'optionalAccess', _50 => _50.type]) && ":not" === _optionalChain([e3, 'access', _51 => _51.parent, 'optionalAccess', _52 => _52.parent, 'optionalAccess', _53 => _53.value, 'optionalAccess', _54 => _54.toLowerCase, 'call', _55 => _55()])) return void a.push([{ start: e3.parent.parent.sourceIndex, end: e3.parent.parent.sourceIndex + e3.parent.parent.toString().length, option: `:not(${e3.nodes.toString()})` }]);
|
|
1168
|
+
if ("pseudo" === _optionalChain([e3, 'access', _56 => _56.parent, 'optionalAccess', _57 => _57.parent, 'optionalAccess', _58 => _58.type]) && ":has" === _optionalChain([e3, 'access', _59 => _59.parent, 'optionalAccess', _60 => _60.parent, 'optionalAccess', _61 => _61.value, 'optionalAccess', _62 => _62.toLowerCase, 'call', _63 => _63()])) return void (e3.value = ":-csstools-matches");
|
|
1164
1169
|
let o4 = e3.parent;
|
|
1165
1170
|
for (; o4; ) {
|
|
1166
1171
|
if (o4.value && ":is" === o4.value.toLowerCase() && "pseudo" === o4.type) return void (i = true);
|
|
@@ -1182,7 +1187,7 @@ function splitSelectors(o2, n2, t = 0) {
|
|
|
1182
1187
|
let s = "";
|
|
1183
1188
|
for (let n3 = 0; n3 < e3.length; n3++) {
|
|
1184
1189
|
const t2 = e3[n3];
|
|
1185
|
-
s += o3.substring(_optionalChain([e3, 'access',
|
|
1190
|
+
s += o3.substring(_optionalChain([e3, 'access', _64 => _64[n3 - 1], 'optionalAccess', _65 => _65.end]) || 0, e3[n3].start), s += ":-csstools-matches(" + t2.option + ")", n3 === e3.length - 1 && (s += o3.substring(e3[n3].end));
|
|
1186
1191
|
}
|
|
1187
1192
|
c.push(s);
|
|
1188
1193
|
})), i && t < 10 && (c = splitSelectors(c, n2, t + 1)), c;
|
|
@@ -1243,19 +1248,60 @@ function getPlugins(options) {
|
|
|
1243
1248
|
const ctx = createContext();
|
|
1244
1249
|
options.ctx = ctx;
|
|
1245
1250
|
const plugins = [
|
|
1246
|
-
..._nullishCoalesce(_optionalChain([options, 'access',
|
|
1247
|
-
postcssWeappTailwindcssPrePlugin(options)
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
+
..._nullishCoalesce(_optionalChain([options, 'access', _66 => _66.postcssOptions, 'optionalAccess', _67 => _67.plugins]), () => ( [])),
|
|
1252
|
+
postcssWeappTailwindcssPrePlugin(options)
|
|
1253
|
+
].filter((x) => Boolean(x));
|
|
1254
|
+
plugins.push(
|
|
1255
|
+
_postcsspresetenv2.default.call(void 0,
|
|
1256
|
+
options.cssPresetEnv
|
|
1257
|
+
)
|
|
1258
|
+
);
|
|
1259
|
+
if (options.px2rpx) {
|
|
1260
|
+
plugins.push(
|
|
1261
|
+
_postcsspxtransform2.default.call(void 0,
|
|
1262
|
+
_shared.defuOverrideArray.call(void 0,
|
|
1263
|
+
typeof options.px2rpx === "object" ? options.px2rpx : {},
|
|
1264
|
+
{
|
|
1265
|
+
platform: "weapp",
|
|
1266
|
+
unitPrecision: 5,
|
|
1267
|
+
propList: ["*"],
|
|
1268
|
+
selectorBlackList: [],
|
|
1269
|
+
replace: true,
|
|
1270
|
+
mediaQuery: false,
|
|
1271
|
+
minPixelValue: 0,
|
|
1272
|
+
designWidth: 750,
|
|
1273
|
+
deviceRatio: {
|
|
1274
|
+
375: 2,
|
|
1275
|
+
640: 2.34 / 2,
|
|
1276
|
+
750: 1,
|
|
1277
|
+
828: 1.81 / 2
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
)
|
|
1281
|
+
)
|
|
1282
|
+
);
|
|
1283
|
+
}
|
|
1251
1284
|
if (options.rem2rpx) {
|
|
1252
1285
|
plugins.push(
|
|
1253
1286
|
_postcssremtoresponsivepixel2.default.call(void 0,
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1287
|
+
_shared.defuOverrideArray.call(void 0,
|
|
1288
|
+
typeof options.rem2rpx === "object" ? options.rem2rpx : {
|
|
1289
|
+
rootValue: 32,
|
|
1290
|
+
propList: ["*"],
|
|
1291
|
+
transformUnit: "rpx"
|
|
1292
|
+
},
|
|
1293
|
+
{
|
|
1294
|
+
processorStage: "OnceExit"
|
|
1295
|
+
}
|
|
1296
|
+
)
|
|
1297
|
+
)
|
|
1298
|
+
);
|
|
1299
|
+
}
|
|
1300
|
+
if (options.cssCalc) {
|
|
1301
|
+
plugins.push(
|
|
1302
|
+
// 核心在 OnceExit 的时候去执行的
|
|
1303
|
+
_postcsscalc2.default.call(void 0,
|
|
1304
|
+
typeof options.cssCalc === "object" ? options.cssCalc : {}
|
|
1259
1305
|
)
|
|
1260
1306
|
);
|
|
1261
1307
|
}
|
|
@@ -1288,7 +1334,7 @@ function styleHandler(rawSource, options) {
|
|
|
1288
1334
|
getPlugins(options)
|
|
1289
1335
|
).process(
|
|
1290
1336
|
rawSource,
|
|
1291
|
-
_shared.defu.call(void 0, _optionalChain([options, 'access',
|
|
1337
|
+
_shared.defu.call(void 0, _optionalChain([options, 'access', _68 => _68.postcssOptions, 'optionalAccess', _69 => _69.options]), {
|
|
1292
1338
|
from: void 0
|
|
1293
1339
|
})
|
|
1294
1340
|
).async();
|
|
@@ -1296,7 +1342,7 @@ function styleHandler(rawSource, options) {
|
|
|
1296
1342
|
function createStyleHandler(options) {
|
|
1297
1343
|
const cachedOptions = _shared.defuOverrideArray.call(void 0,
|
|
1298
1344
|
options,
|
|
1299
|
-
getDefaultOptions()
|
|
1345
|
+
getDefaultOptions(options)
|
|
1300
1346
|
);
|
|
1301
1347
|
cachedOptions.cssInjectPreflight = createInjectPreflight(cachedOptions.cssPreflight);
|
|
1302
1348
|
return (rawSource, opt) => {
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import "./chunk-WAXGOBY2.mjs";
|
|
2
2
|
|
|
3
3
|
// src/handler.ts
|
|
4
|
-
import { defu as defu3, defuOverrideArray as
|
|
4
|
+
import { defu as defu3, defuOverrideArray as defuOverrideArray3 } from "@weapp-tailwindcss/shared";
|
|
5
5
|
import postcss from "postcss";
|
|
6
6
|
|
|
7
7
|
// src/defaults.ts
|
|
8
|
-
function getDefaultOptions() {
|
|
8
|
+
function getDefaultOptions(options) {
|
|
9
9
|
return {
|
|
10
10
|
// https://github.com/postcss/postcss-calc
|
|
11
11
|
cssPresetEnv: {
|
|
@@ -16,12 +16,14 @@ function getDefaultOptions() {
|
|
|
16
16
|
},
|
|
17
17
|
"oklab-function": true,
|
|
18
18
|
"color-mix": true,
|
|
19
|
-
|
|
19
|
+
// 在 calc 下,这个需要开启
|
|
20
|
+
"custom-properties": options?.cssCalc ? { preserve: false } : options?.cssPresetEnv?.features?.["custom-properties"] ?? false
|
|
20
21
|
},
|
|
21
22
|
autoprefixer: {
|
|
22
23
|
add: false
|
|
23
24
|
}
|
|
24
25
|
},
|
|
26
|
+
// 支付宝小程序不支持,所以默认关闭
|
|
25
27
|
cssRemoveProperty: true,
|
|
26
28
|
// cssRemoveAtSupports: true,
|
|
27
29
|
// cssRemoveAtMedia: true,
|
|
@@ -33,7 +35,10 @@ function getDefaultOptions() {
|
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
// src/plugins/index.ts
|
|
38
|
+
import postcssCalc from "@weapp-tailwindcss/postcss-calc";
|
|
39
|
+
import { defuOverrideArray as defuOverrideArray2 } from "@weapp-tailwindcss/shared";
|
|
36
40
|
import postcssPresetEnv from "postcss-preset-env";
|
|
41
|
+
import postcssPxtransform from "postcss-pxtransform";
|
|
37
42
|
import postcssRem2rpx from "postcss-rem-to-responsive-pixel";
|
|
38
43
|
|
|
39
44
|
// src/plugins/ctx.ts
|
|
@@ -347,7 +352,7 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
|
|
|
347
352
|
p.DeclarationExit = (decl) => {
|
|
348
353
|
if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OklabSuffix)) {
|
|
349
354
|
decl.value = decl.value.slice(0, decl.value.length - OklabSuffix.length);
|
|
350
|
-
} else if (/calc\(\s*infinity\s*\*\s*
|
|
355
|
+
} else if (/calc\(\s*infinity\s*\*\s*(?:\d+(?:\.\d*)?|\.\d+)r?px/.test(decl.value)) {
|
|
351
356
|
decl.value = "9999px";
|
|
352
357
|
}
|
|
353
358
|
};
|
|
@@ -1244,18 +1249,59 @@ function getPlugins(options) {
|
|
|
1244
1249
|
options.ctx = ctx;
|
|
1245
1250
|
const plugins = [
|
|
1246
1251
|
...options.postcssOptions?.plugins ?? [],
|
|
1247
|
-
postcssWeappTailwindcssPrePlugin(options)
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1252
|
+
postcssWeappTailwindcssPrePlugin(options)
|
|
1253
|
+
].filter((x) => Boolean(x));
|
|
1254
|
+
plugins.push(
|
|
1255
|
+
postcssPresetEnv(
|
|
1256
|
+
options.cssPresetEnv
|
|
1257
|
+
)
|
|
1258
|
+
);
|
|
1259
|
+
if (options.px2rpx) {
|
|
1260
|
+
plugins.push(
|
|
1261
|
+
postcssPxtransform(
|
|
1262
|
+
defuOverrideArray2(
|
|
1263
|
+
typeof options.px2rpx === "object" ? options.px2rpx : {},
|
|
1264
|
+
{
|
|
1265
|
+
platform: "weapp",
|
|
1266
|
+
unitPrecision: 5,
|
|
1267
|
+
propList: ["*"],
|
|
1268
|
+
selectorBlackList: [],
|
|
1269
|
+
replace: true,
|
|
1270
|
+
mediaQuery: false,
|
|
1271
|
+
minPixelValue: 0,
|
|
1272
|
+
designWidth: 750,
|
|
1273
|
+
deviceRatio: {
|
|
1274
|
+
375: 2,
|
|
1275
|
+
640: 2.34 / 2,
|
|
1276
|
+
750: 1,
|
|
1277
|
+
828: 1.81 / 2
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
)
|
|
1281
|
+
)
|
|
1282
|
+
);
|
|
1283
|
+
}
|
|
1251
1284
|
if (options.rem2rpx) {
|
|
1252
1285
|
plugins.push(
|
|
1253
1286
|
postcssRem2rpx(
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1287
|
+
defuOverrideArray2(
|
|
1288
|
+
typeof options.rem2rpx === "object" ? options.rem2rpx : {
|
|
1289
|
+
rootValue: 32,
|
|
1290
|
+
propList: ["*"],
|
|
1291
|
+
transformUnit: "rpx"
|
|
1292
|
+
},
|
|
1293
|
+
{
|
|
1294
|
+
processorStage: "OnceExit"
|
|
1295
|
+
}
|
|
1296
|
+
)
|
|
1297
|
+
)
|
|
1298
|
+
);
|
|
1299
|
+
}
|
|
1300
|
+
if (options.cssCalc) {
|
|
1301
|
+
plugins.push(
|
|
1302
|
+
// 核心在 OnceExit 的时候去执行的
|
|
1303
|
+
postcssCalc(
|
|
1304
|
+
typeof options.cssCalc === "object" ? options.cssCalc : {}
|
|
1259
1305
|
)
|
|
1260
1306
|
);
|
|
1261
1307
|
}
|
|
@@ -1294,15 +1340,15 @@ function styleHandler(rawSource, options) {
|
|
|
1294
1340
|
).async();
|
|
1295
1341
|
}
|
|
1296
1342
|
function createStyleHandler(options) {
|
|
1297
|
-
const cachedOptions =
|
|
1343
|
+
const cachedOptions = defuOverrideArray3(
|
|
1298
1344
|
options,
|
|
1299
|
-
getDefaultOptions()
|
|
1345
|
+
getDefaultOptions(options)
|
|
1300
1346
|
);
|
|
1301
1347
|
cachedOptions.cssInjectPreflight = createInjectPreflight(cachedOptions.cssPreflight);
|
|
1302
1348
|
return (rawSource, opt) => {
|
|
1303
1349
|
return styleHandler(
|
|
1304
1350
|
rawSource,
|
|
1305
|
-
|
|
1351
|
+
defuOverrideArray3(opt, cachedOptions)
|
|
1306
1352
|
);
|
|
1307
1353
|
};
|
|
1308
1354
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { IMangleScopeContext } from '@weapp-tailwindcss/mangle';
|
|
2
|
+
import { PostCssCalcOptions } from '@weapp-tailwindcss/postcss-calc';
|
|
2
3
|
import { Rule } from 'postcss';
|
|
3
4
|
import { Result } from 'postcss-load-config';
|
|
4
5
|
import { pluginOptions } from 'postcss-preset-env';
|
|
6
|
+
import { PxtransformOptions } from 'postcss-pxtransform';
|
|
5
7
|
import { UserDefinedOptions } from 'postcss-rem-to-responsive-pixel';
|
|
6
8
|
|
|
7
9
|
declare function createContext(): {
|
|
@@ -31,7 +33,7 @@ type RequiredStyleHandlerOptions = {
|
|
|
31
33
|
cssPreflight?: CssPreflightOptions;
|
|
32
34
|
cssInjectPreflight?: InjectPreflight;
|
|
33
35
|
escapeMap?: Record<string, string>;
|
|
34
|
-
} & Pick<UserDefinedPostcssOptions, 'cssPreflightRange' | 'cssChildCombinatorReplaceValue' | 'injectAdditionalCssVarScope' | 'cssSelectorReplacement' | 'rem2rpx'>;
|
|
36
|
+
} & Pick<UserDefinedPostcssOptions, 'cssPreflightRange' | 'cssChildCombinatorReplaceValue' | 'injectAdditionalCssVarScope' | 'cssSelectorReplacement' | 'rem2rpx' | 'px2rpx'>;
|
|
35
37
|
interface InternalCssSelectorReplacerOptions {
|
|
36
38
|
mangleContext?: IMangleScopeContext;
|
|
37
39
|
escapeMap?: Record<string, string>;
|
|
@@ -44,6 +46,7 @@ type IStyleHandlerOptions = {
|
|
|
44
46
|
cssRemoveProperty?: boolean;
|
|
45
47
|
cssRemoveHoverPseudoClass?: boolean;
|
|
46
48
|
cssPresetEnv?: pluginOptions;
|
|
49
|
+
cssCalc?: boolean | PostCssCalcOptions;
|
|
47
50
|
atRules?: {
|
|
48
51
|
property?: boolean;
|
|
49
52
|
supports?: boolean;
|
|
@@ -63,6 +66,7 @@ interface UserDefinedPostcssOptions {
|
|
|
63
66
|
universal?: string | string[] | false;
|
|
64
67
|
};
|
|
65
68
|
rem2rpx?: boolean | UserDefinedOptions;
|
|
69
|
+
px2rpx?: boolean | PxtransformOptions;
|
|
66
70
|
postcssOptions?: LoadedPostcssOptions;
|
|
67
71
|
cssRemoveHoverPseudoClass?: boolean;
|
|
68
72
|
cssRemoveProperty?: boolean;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { IMangleScopeContext } from '@weapp-tailwindcss/mangle';
|
|
2
|
+
import { PostCssCalcOptions } from '@weapp-tailwindcss/postcss-calc';
|
|
2
3
|
import { Rule } from 'postcss';
|
|
3
4
|
import { Result } from 'postcss-load-config';
|
|
4
5
|
import { pluginOptions } from 'postcss-preset-env';
|
|
6
|
+
import { PxtransformOptions } from 'postcss-pxtransform';
|
|
5
7
|
import { UserDefinedOptions } from 'postcss-rem-to-responsive-pixel';
|
|
6
8
|
|
|
7
9
|
declare function createContext(): {
|
|
@@ -31,7 +33,7 @@ type RequiredStyleHandlerOptions = {
|
|
|
31
33
|
cssPreflight?: CssPreflightOptions;
|
|
32
34
|
cssInjectPreflight?: InjectPreflight;
|
|
33
35
|
escapeMap?: Record<string, string>;
|
|
34
|
-
} & Pick<UserDefinedPostcssOptions, 'cssPreflightRange' | 'cssChildCombinatorReplaceValue' | 'injectAdditionalCssVarScope' | 'cssSelectorReplacement' | 'rem2rpx'>;
|
|
36
|
+
} & Pick<UserDefinedPostcssOptions, 'cssPreflightRange' | 'cssChildCombinatorReplaceValue' | 'injectAdditionalCssVarScope' | 'cssSelectorReplacement' | 'rem2rpx' | 'px2rpx'>;
|
|
35
37
|
interface InternalCssSelectorReplacerOptions {
|
|
36
38
|
mangleContext?: IMangleScopeContext;
|
|
37
39
|
escapeMap?: Record<string, string>;
|
|
@@ -44,6 +46,7 @@ type IStyleHandlerOptions = {
|
|
|
44
46
|
cssRemoveProperty?: boolean;
|
|
45
47
|
cssRemoveHoverPseudoClass?: boolean;
|
|
46
48
|
cssPresetEnv?: pluginOptions;
|
|
49
|
+
cssCalc?: boolean | PostCssCalcOptions;
|
|
47
50
|
atRules?: {
|
|
48
51
|
property?: boolean;
|
|
49
52
|
supports?: boolean;
|
|
@@ -63,6 +66,7 @@ interface UserDefinedPostcssOptions {
|
|
|
63
66
|
universal?: string | string[] | false;
|
|
64
67
|
};
|
|
65
68
|
rem2rpx?: boolean | UserDefinedOptions;
|
|
69
|
+
px2rpx?: boolean | PxtransformOptions;
|
|
66
70
|
postcssOptions?: LoadedPostcssOptions;
|
|
67
71
|
cssRemoveHoverPseudoClass?: boolean;
|
|
68
72
|
cssRemoveProperty?: boolean;
|
package/dist/types.d.mts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import '@weapp-tailwindcss/mangle';
|
|
2
|
+
import '@weapp-tailwindcss/postcss-calc';
|
|
2
3
|
import 'postcss';
|
|
3
4
|
import 'postcss-load-config';
|
|
4
5
|
import 'postcss-preset-env';
|
|
6
|
+
import 'postcss-pxtransform';
|
|
5
7
|
import 'postcss-rem-to-responsive-pixel';
|
|
6
|
-
export { d as CssPreflightOptions, C as CustomRuleCallback, b as IPropValue, I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions } from './types-
|
|
8
|
+
export { d as CssPreflightOptions, C as CustomRuleCallback, b as IPropValue, I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions } from './types-C5X6IWCb.mjs';
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import '@weapp-tailwindcss/mangle';
|
|
2
|
+
import '@weapp-tailwindcss/postcss-calc';
|
|
2
3
|
import 'postcss';
|
|
3
4
|
import 'postcss-load-config';
|
|
4
5
|
import 'postcss-preset-env';
|
|
6
|
+
import 'postcss-pxtransform';
|
|
5
7
|
import 'postcss-rem-to-responsive-pixel';
|
|
6
|
-
export { d as CssPreflightOptions, C as CustomRuleCallback, b as IPropValue, I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions } from './types-
|
|
8
|
+
export { d as CssPreflightOptions, C as CustomRuleCallback, b as IPropValue, I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions } from './types-C5X6IWCb.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-tailwindcss/postcss",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "@weapp-tailwindcss/postcss",
|
|
5
5
|
"author": "ice breaker <1324318532@qq.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,9 +40,11 @@
|
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@weapp-core/escape": "~4.0.1",
|
|
43
|
+
"@weapp-tailwindcss/postcss-calc": "^1.0.0",
|
|
43
44
|
"postcss": "~8.5.6",
|
|
44
45
|
"postcss-preset-env": "^10.3.1",
|
|
45
|
-
"postcss-
|
|
46
|
+
"postcss-pxtransform": "^4.1.6",
|
|
47
|
+
"postcss-rem-to-responsive-pixel": "~6.1.0",
|
|
46
48
|
"postcss-selector-parser": "~7.1.0",
|
|
47
49
|
"@weapp-tailwindcss/shared": "1.0.3"
|
|
48
50
|
},
|