@weapp-tailwindcss/postcss 2.0.6 → 2.0.8
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.js +291 -178
- package/dist/index.mjs +271 -158
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import "./chunk-WAXGOBY2.mjs";
|
|
2
2
|
|
|
3
3
|
// src/handler.ts
|
|
4
|
-
import { defuOverrideArray as
|
|
5
|
-
import postcss from "postcss";
|
|
4
|
+
import { defuOverrideArray as defuOverrideArray4 } from "@weapp-tailwindcss/shared";
|
|
6
5
|
|
|
7
6
|
// src/defaults.ts
|
|
8
7
|
function getDefaultOptions(options) {
|
|
@@ -35,6 +34,102 @@ function getDefaultOptions(options) {
|
|
|
35
34
|
};
|
|
36
35
|
}
|
|
37
36
|
|
|
37
|
+
// src/options-resolver.ts
|
|
38
|
+
import { defuOverrideArray } from "@weapp-tailwindcss/shared";
|
|
39
|
+
|
|
40
|
+
// src/fingerprint.ts
|
|
41
|
+
function fingerprintOptions(value, state = { map: /* @__PURE__ */ new WeakMap(), counter: 0 }) {
|
|
42
|
+
if (value === null || value === void 0) {
|
|
43
|
+
return String(value);
|
|
44
|
+
}
|
|
45
|
+
if (typeof value === "function") {
|
|
46
|
+
return `fn:${value.name || "anonymous"}`;
|
|
47
|
+
}
|
|
48
|
+
if (typeof value === "symbol") {
|
|
49
|
+
return `sym:${String(value)}`;
|
|
50
|
+
}
|
|
51
|
+
if (typeof value !== "object") {
|
|
52
|
+
return `${typeof value}:${String(value)}`;
|
|
53
|
+
}
|
|
54
|
+
const objectValue = value;
|
|
55
|
+
const cached = state.map.get(objectValue);
|
|
56
|
+
if (cached) {
|
|
57
|
+
return cached;
|
|
58
|
+
}
|
|
59
|
+
const marker = `ref:${state.counter++}`;
|
|
60
|
+
state.map.set(objectValue, marker);
|
|
61
|
+
if (Array.isArray(objectValue)) {
|
|
62
|
+
const parts2 = objectValue.map((entry) => fingerprintOptions(entry, state));
|
|
63
|
+
return `[${parts2.join(",")}]`;
|
|
64
|
+
}
|
|
65
|
+
const keys = Object.keys(objectValue).sort();
|
|
66
|
+
const parts = keys.map((key) => `${key}:${fingerprintOptions(objectValue[key], state)}`);
|
|
67
|
+
return `{${parts.join(",")}}@${marker}`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/options-resolver.ts
|
|
71
|
+
var BASE_CACHE_KEY = "base";
|
|
72
|
+
function hasOverrides(options) {
|
|
73
|
+
return Boolean(options && Object.keys(options).length > 0);
|
|
74
|
+
}
|
|
75
|
+
function createOptionsResolver(baseOptions) {
|
|
76
|
+
const cacheByKey = /* @__PURE__ */ new Map();
|
|
77
|
+
const cacheByRef = /* @__PURE__ */ new WeakMap();
|
|
78
|
+
const fingerprintByRef = /* @__PURE__ */ new WeakMap();
|
|
79
|
+
cacheByKey.set(BASE_CACHE_KEY, baseOptions);
|
|
80
|
+
const resolve = (overrides) => {
|
|
81
|
+
if (!hasOverrides(overrides)) {
|
|
82
|
+
return baseOptions;
|
|
83
|
+
}
|
|
84
|
+
const refCached = cacheByRef.get(overrides);
|
|
85
|
+
if (refCached) {
|
|
86
|
+
return refCached;
|
|
87
|
+
}
|
|
88
|
+
let key = fingerprintByRef.get(overrides);
|
|
89
|
+
if (!key) {
|
|
90
|
+
key = fingerprintOptions(overrides);
|
|
91
|
+
fingerprintByRef.set(overrides, key);
|
|
92
|
+
}
|
|
93
|
+
const cached = cacheByKey.get(key);
|
|
94
|
+
if (cached) {
|
|
95
|
+
cacheByRef.set(overrides, cached);
|
|
96
|
+
return cached;
|
|
97
|
+
}
|
|
98
|
+
const merged = defuOverrideArray(
|
|
99
|
+
{ ...overrides },
|
|
100
|
+
baseOptions
|
|
101
|
+
);
|
|
102
|
+
cacheByKey.set(key, merged);
|
|
103
|
+
cacheByRef.set(overrides, merged);
|
|
104
|
+
return merged;
|
|
105
|
+
};
|
|
106
|
+
return {
|
|
107
|
+
resolve
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// src/preflight.ts
|
|
112
|
+
function createInjectPreflight(options) {
|
|
113
|
+
const result = [];
|
|
114
|
+
if (options && typeof options === "object") {
|
|
115
|
+
const entries = Object.entries(options);
|
|
116
|
+
for (const [prop, value] of entries) {
|
|
117
|
+
if (value !== false) {
|
|
118
|
+
result.push({
|
|
119
|
+
prop,
|
|
120
|
+
value: value.toString()
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return () => {
|
|
126
|
+
return result;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/processor-cache.ts
|
|
131
|
+
import postcss from "postcss";
|
|
132
|
+
|
|
38
133
|
// src/pipeline.ts
|
|
39
134
|
import postcssPresetEnv from "postcss-preset-env";
|
|
40
135
|
|
|
@@ -154,7 +249,7 @@ function createContext() {
|
|
|
154
249
|
// src/plugins/getCalcPlugin.ts
|
|
155
250
|
import postcssCalc from "@weapp-tailwindcss/postcss-calc";
|
|
156
251
|
|
|
157
|
-
// ../../node_modules/.pnpm/es-toolkit@1.
|
|
252
|
+
// ../../node_modules/.pnpm/es-toolkit@1.43.0/node_modules/es-toolkit/dist/object/omit.mjs
|
|
158
253
|
function omit(obj, keys) {
|
|
159
254
|
const result = { ...obj };
|
|
160
255
|
for (let i = 0; i < keys.length; i++) {
|
|
@@ -219,7 +314,7 @@ function getCustomPropertyCleaner(options) {
|
|
|
219
314
|
}
|
|
220
315
|
|
|
221
316
|
// src/plugins/getPxTransformPlugin.ts
|
|
222
|
-
import { defuOverrideArray } from "@weapp-tailwindcss/shared";
|
|
317
|
+
import { defuOverrideArray as defuOverrideArray2 } from "@weapp-tailwindcss/shared";
|
|
223
318
|
import postcssPxtransform from "postcss-pxtransform";
|
|
224
319
|
var defaultPxTransformOptions = {
|
|
225
320
|
platform: "weapp",
|
|
@@ -243,7 +338,7 @@ function getPxTransformPlugin(options) {
|
|
|
243
338
|
}
|
|
244
339
|
const userOptions = typeof options.px2rpx === "object" ? options.px2rpx : {};
|
|
245
340
|
return postcssPxtransform(
|
|
246
|
-
|
|
341
|
+
defuOverrideArray2(
|
|
247
342
|
userOptions,
|
|
248
343
|
defaultPxTransformOptions
|
|
249
344
|
)
|
|
@@ -251,7 +346,7 @@ function getPxTransformPlugin(options) {
|
|
|
251
346
|
}
|
|
252
347
|
|
|
253
348
|
// src/plugins/getRemTransformPlugin.ts
|
|
254
|
-
import { defuOverrideArray as
|
|
349
|
+
import { defuOverrideArray as defuOverrideArray3 } from "@weapp-tailwindcss/shared";
|
|
255
350
|
import postcssRem2rpx from "postcss-rem-to-responsive-pixel";
|
|
256
351
|
var defaultRemOptions = {
|
|
257
352
|
rootValue: 32,
|
|
@@ -266,7 +361,7 @@ function getRemTransformPlugin(options) {
|
|
|
266
361
|
return null;
|
|
267
362
|
}
|
|
268
363
|
const userOptions = typeof options.rem2rpx === "object" ? options.rem2rpx : defaultRemOptions;
|
|
269
|
-
const merged =
|
|
364
|
+
const merged = defuOverrideArray3(
|
|
270
365
|
userOptions,
|
|
271
366
|
defaultStage
|
|
272
367
|
);
|
|
@@ -276,8 +371,36 @@ function getRemTransformPlugin(options) {
|
|
|
276
371
|
// src/plugins/post.ts
|
|
277
372
|
import { defu } from "@weapp-tailwindcss/shared";
|
|
278
373
|
|
|
279
|
-
// src/compat/tailwindcss-
|
|
280
|
-
|
|
374
|
+
// src/compat/tailwindcss-rpx.ts
|
|
375
|
+
var LENGTH_VALUE_REGEXP = /^[+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?rpx$/i;
|
|
376
|
+
function normalizeTailwindcssRpxDeclaration(decl, options) {
|
|
377
|
+
const majorVersion = options?.majorVersion;
|
|
378
|
+
const normalizedValue = decl.value.trim();
|
|
379
|
+
if (LENGTH_VALUE_REGEXP.test(normalizedValue) && (majorVersion === void 0 || majorVersion === 2 || majorVersion === 3 || majorVersion === 4)) {
|
|
380
|
+
const lowerProp = decl.prop.toLowerCase();
|
|
381
|
+
if (lowerProp === "color") {
|
|
382
|
+
decl.prop = "font-size";
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
if (lowerProp === "background-color") {
|
|
386
|
+
decl.prop = "background-size";
|
|
387
|
+
return true;
|
|
388
|
+
}
|
|
389
|
+
if (lowerProp === "outline-color") {
|
|
390
|
+
decl.prop = "outline-width";
|
|
391
|
+
return true;
|
|
392
|
+
}
|
|
393
|
+
if (lowerProp.startsWith("border") && lowerProp.endsWith("color")) {
|
|
394
|
+
decl.prop = `${decl.prop.slice(0, -"color".length)}width`;
|
|
395
|
+
return true;
|
|
396
|
+
}
|
|
397
|
+
if (lowerProp === "--tw-ring-color") {
|
|
398
|
+
decl.prop = "--tw-ring-offset-width";
|
|
399
|
+
return true;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return false;
|
|
403
|
+
}
|
|
281
404
|
|
|
282
405
|
// src/cssVarsV4.ts
|
|
283
406
|
function property(ident, initialValue, _syntax) {
|
|
@@ -417,6 +540,15 @@ for (const edge of ["top", "right", "bottom", "left"]) {
|
|
|
417
540
|
}
|
|
418
541
|
var cssVarsV4_default = nodes;
|
|
419
542
|
|
|
543
|
+
// src/utils/css-vars.ts
|
|
544
|
+
import { Declaration } from "postcss";
|
|
545
|
+
function createCssVarNodes(definitions) {
|
|
546
|
+
return definitions.map((def) => new Declaration({
|
|
547
|
+
prop: def.prop,
|
|
548
|
+
value: def.value
|
|
549
|
+
}));
|
|
550
|
+
}
|
|
551
|
+
|
|
420
552
|
// src/compat/tailwindcss-v4.ts
|
|
421
553
|
var OKLAB_SUFFIX = "in oklab";
|
|
422
554
|
var INFINITY_CALC_REGEXP = /calc\(\s*infinity\s*\*\s*(?:\d+(?:\.\d*)?|\.\d+)r?px/;
|
|
@@ -428,12 +560,7 @@ function isTailwindcssV4(options) {
|
|
|
428
560
|
function testIfRootHostForV4(node) {
|
|
429
561
|
return node.type === "rule" && node.selector.includes(":root") && node.selector.includes(":host");
|
|
430
562
|
}
|
|
431
|
-
var cssVarsV4Nodes = cssVarsV4_default
|
|
432
|
-
return new Declaration({
|
|
433
|
-
prop: x.prop,
|
|
434
|
-
value: x.value
|
|
435
|
-
});
|
|
436
|
-
});
|
|
563
|
+
var cssVarsV4Nodes = createCssVarNodes(cssVarsV4_default);
|
|
437
564
|
function isTailwindcssV4ModernCheck(atRule) {
|
|
438
565
|
return atRule.name === "supports" && [
|
|
439
566
|
/-webkit-hyphens\s*:\s*none/,
|
|
@@ -583,6 +710,7 @@ function getCombinatorSelectorAst(options) {
|
|
|
583
710
|
// src/selectorParser/fallback.ts
|
|
584
711
|
var fallbackRemoveCache = /* @__PURE__ */ new WeakMap();
|
|
585
712
|
var fallbackDefaultKey = {};
|
|
713
|
+
var FALLBACK_TRANSFORM_OPTIONS = normalizeTransformOptions();
|
|
586
714
|
function getFallbackRemove(_rule, options) {
|
|
587
715
|
const cacheKey = options ?? fallbackDefaultKey;
|
|
588
716
|
let entry = fallbackRemoveCache.get(cacheKey);
|
|
@@ -647,24 +775,25 @@ function getFallbackRemove(_rule, options) {
|
|
|
647
775
|
const transform = (targetRule) => {
|
|
648
776
|
currentRule = targetRule;
|
|
649
777
|
try {
|
|
650
|
-
rawTransformSync(targetRule,
|
|
778
|
+
rawTransformSync(targetRule, FALLBACK_TRANSFORM_OPTIONS);
|
|
651
779
|
} finally {
|
|
652
780
|
currentRule = void 0;
|
|
653
781
|
}
|
|
654
782
|
};
|
|
655
783
|
parser.transformSync = ((input, opts) => {
|
|
784
|
+
const transformOptions = opts ? normalizeTransformOptions(opts) : FALLBACK_TRANSFORM_OPTIONS;
|
|
656
785
|
if (input && typeof input === "object" && "type" in input) {
|
|
657
786
|
const maybeRule = input;
|
|
658
787
|
if (maybeRule.type === "rule") {
|
|
659
788
|
currentRule = input;
|
|
660
789
|
try {
|
|
661
|
-
return rawTransformSync(input,
|
|
790
|
+
return rawTransformSync(input, transformOptions);
|
|
662
791
|
} finally {
|
|
663
792
|
currentRule = void 0;
|
|
664
793
|
}
|
|
665
794
|
}
|
|
666
795
|
}
|
|
667
|
-
return rawTransformSync(input,
|
|
796
|
+
return rawTransformSync(input, transformOptions);
|
|
668
797
|
});
|
|
669
798
|
entry = {
|
|
670
799
|
parser,
|
|
@@ -698,6 +827,47 @@ function composeIsPseudo(strs) {
|
|
|
698
827
|
return strs.join("");
|
|
699
828
|
}
|
|
700
829
|
|
|
830
|
+
// src/utils/decl-order.ts
|
|
831
|
+
function reorderLiteralFirst(rule, declarations, isVariable) {
|
|
832
|
+
if (declarations.length <= 1) {
|
|
833
|
+
return;
|
|
834
|
+
}
|
|
835
|
+
const literals = [];
|
|
836
|
+
const variables = [];
|
|
837
|
+
for (const decl of declarations) {
|
|
838
|
+
if (isVariable(decl)) {
|
|
839
|
+
variables.push(decl);
|
|
840
|
+
} else {
|
|
841
|
+
literals.push(decl);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
if (literals.length === 0 || variables.length === 0) {
|
|
845
|
+
return;
|
|
846
|
+
}
|
|
847
|
+
const desired = [...literals, ...variables];
|
|
848
|
+
let alreadyOrdered = true;
|
|
849
|
+
for (let index = 0; index < desired.length; index++) {
|
|
850
|
+
if (desired[index] !== declarations[index]) {
|
|
851
|
+
alreadyOrdered = false;
|
|
852
|
+
break;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
if (alreadyOrdered) {
|
|
856
|
+
return;
|
|
857
|
+
}
|
|
858
|
+
const anchor = declarations[declarations.length - 1]?.next() ?? void 0;
|
|
859
|
+
for (const decl of declarations) {
|
|
860
|
+
decl.remove();
|
|
861
|
+
}
|
|
862
|
+
for (const decl of desired) {
|
|
863
|
+
if (anchor) {
|
|
864
|
+
rule.insertBefore(anchor, decl);
|
|
865
|
+
} else {
|
|
866
|
+
rule.append(decl);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
|
|
701
871
|
// src/selectorParser/rule-transformer.ts
|
|
702
872
|
var ruleTransformCache = /* @__PURE__ */ new WeakMap();
|
|
703
873
|
var MIRROR_PROP_PAIRS = [
|
|
@@ -725,6 +895,7 @@ var LEGACY_WEBKIT_SPACING_PROPS = /* @__PURE__ */ new Set([
|
|
|
725
895
|
"-webkit-margin-after"
|
|
726
896
|
]);
|
|
727
897
|
var VAR_REFERENCE_PATTERN = /var\(/i;
|
|
898
|
+
var SELECTOR_TRANSFORM_OPTIONS = normalizeTransformOptions();
|
|
728
899
|
function dedupeSpacingProps(rule) {
|
|
729
900
|
const grouped = /* @__PURE__ */ new Map();
|
|
730
901
|
for (const node of rule.nodes) {
|
|
@@ -762,27 +933,11 @@ function dedupeSpacingProps(rule) {
|
|
|
762
933
|
if (unique.length <= 1) {
|
|
763
934
|
continue;
|
|
764
935
|
}
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
const ordered = [...literals, ...variables];
|
|
771
|
-
const alreadyOrdered = ordered.every((decl, index) => decl === unique[index]);
|
|
772
|
-
if (alreadyOrdered) {
|
|
773
|
-
continue;
|
|
774
|
-
}
|
|
775
|
-
const anchor = unique[unique.length - 1]?.next() ?? void 0;
|
|
776
|
-
for (const decl of unique) {
|
|
777
|
-
decl.remove();
|
|
778
|
-
}
|
|
779
|
-
for (const decl of ordered) {
|
|
780
|
-
if (anchor) {
|
|
781
|
-
rule.insertBefore(anchor, decl);
|
|
782
|
-
} else {
|
|
783
|
-
rule.append(decl);
|
|
784
|
-
}
|
|
785
|
-
}
|
|
936
|
+
reorderLiteralFirst(
|
|
937
|
+
rule,
|
|
938
|
+
unique,
|
|
939
|
+
(decl) => VAR_REFERENCE_PATTERN.test(decl.value)
|
|
940
|
+
);
|
|
786
941
|
}
|
|
787
942
|
}
|
|
788
943
|
function isNotLastChildPseudo(node) {
|
|
@@ -992,7 +1147,7 @@ function createRuleTransformer(options) {
|
|
|
992
1147
|
rule
|
|
993
1148
|
};
|
|
994
1149
|
try {
|
|
995
|
-
parser.transformSync(rule,
|
|
1150
|
+
parser.transformSync(rule, SELECTOR_TRANSFORM_OPTIONS);
|
|
996
1151
|
} finally {
|
|
997
1152
|
context = void 0;
|
|
998
1153
|
}
|
|
@@ -1158,33 +1313,11 @@ function dedupeDeclarations(rule) {
|
|
|
1158
1313
|
if (declarations.length <= 1) {
|
|
1159
1314
|
continue;
|
|
1160
1315
|
}
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
const ordered = [...literals, ...variables];
|
|
1167
|
-
let needReorder = false;
|
|
1168
|
-
for (let index = 0; index < ordered.length; index++) {
|
|
1169
|
-
if (ordered[index] !== declarations[index]) {
|
|
1170
|
-
needReorder = true;
|
|
1171
|
-
break;
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
if (!needReorder) {
|
|
1175
|
-
continue;
|
|
1176
|
-
}
|
|
1177
|
-
const anchor = declarations[declarations.length - 1]?.next() ?? void 0;
|
|
1178
|
-
for (const decl of declarations) {
|
|
1179
|
-
decl.remove();
|
|
1180
|
-
}
|
|
1181
|
-
for (const decl of ordered) {
|
|
1182
|
-
if (anchor) {
|
|
1183
|
-
rule.insertBefore(anchor, decl);
|
|
1184
|
-
} else {
|
|
1185
|
-
rule.append(decl);
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1316
|
+
reorderLiteralFirst(
|
|
1317
|
+
rule,
|
|
1318
|
+
declarations,
|
|
1319
|
+
(decl) => hasVariableReference(decl.value)
|
|
1320
|
+
);
|
|
1188
1321
|
}
|
|
1189
1322
|
const literalSeen = /* @__PURE__ */ new Map();
|
|
1190
1323
|
for (const node of [...rule.nodes]) {
|
|
@@ -1234,7 +1367,10 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
|
|
|
1234
1367
|
};
|
|
1235
1368
|
}
|
|
1236
1369
|
if (enableMainChunkTransforms) {
|
|
1237
|
-
p.DeclarationExit = (decl) =>
|
|
1370
|
+
p.DeclarationExit = (decl) => {
|
|
1371
|
+
normalizeTailwindcssRpxDeclaration(decl, { majorVersion: opts.majorVersion });
|
|
1372
|
+
normalizeTailwindcssV4Declaration(decl);
|
|
1373
|
+
};
|
|
1238
1374
|
p.AtRuleExit = (atRule) => {
|
|
1239
1375
|
if (opts.cssRemoveProperty && atRule.name === "property") {
|
|
1240
1376
|
atRule.remove();
|
|
@@ -1460,42 +1596,31 @@ var cssVarsV3_default = [
|
|
|
1460
1596
|
}
|
|
1461
1597
|
];
|
|
1462
1598
|
|
|
1463
|
-
// src/
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
function testIfVariablesScope(node, count = 2) {
|
|
1471
|
-
if (isOnlyBeforeAndAfterPseudoElement(node)) {
|
|
1472
|
-
const nodes2 = node.nodes;
|
|
1473
|
-
let c = 0;
|
|
1474
|
-
for (const tryTestDecl of nodes2) {
|
|
1475
|
-
if (tryTestDecl && tryTestDecl.type === "decl" && tryTestDecl.prop.startsWith("--tw-")) {
|
|
1476
|
-
c++;
|
|
1477
|
-
}
|
|
1478
|
-
if (c >= count) {
|
|
1599
|
+
// src/utils/tw-vars.ts
|
|
1600
|
+
function hasTwVars(rule, count = 2) {
|
|
1601
|
+
let matched = 0;
|
|
1602
|
+
for (const node of rule.nodes ?? []) {
|
|
1603
|
+
if (node.type === "decl" && node.prop.startsWith("--tw-")) {
|
|
1604
|
+
matched++;
|
|
1605
|
+
if (matched >= count) {
|
|
1479
1606
|
return true;
|
|
1480
1607
|
}
|
|
1481
1608
|
}
|
|
1482
|
-
|
|
1609
|
+
}
|
|
1610
|
+
return false;
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
// src/mp.ts
|
|
1614
|
+
var cssVarsV3Nodes = createCssVarNodes(cssVarsV3_default);
|
|
1615
|
+
function testIfVariablesScope(node, count = 2) {
|
|
1616
|
+
if (isOnlyBeforeAndAfterPseudoElement(node)) {
|
|
1617
|
+
return hasTwVars(node, count);
|
|
1483
1618
|
}
|
|
1484
1619
|
return false;
|
|
1485
1620
|
}
|
|
1486
1621
|
function testIfTwBackdrop(node, count = 2) {
|
|
1487
1622
|
if (node.type === "rule" && node.selector === "::backdrop") {
|
|
1488
|
-
|
|
1489
|
-
let c = 0;
|
|
1490
|
-
for (const tryTestDecl of nodes2) {
|
|
1491
|
-
if (tryTestDecl && tryTestDecl.type === "decl" && tryTestDecl.prop.startsWith("--tw-")) {
|
|
1492
|
-
c++;
|
|
1493
|
-
}
|
|
1494
|
-
if (c >= count) {
|
|
1495
|
-
return true;
|
|
1496
|
-
}
|
|
1497
|
-
}
|
|
1498
|
-
return false;
|
|
1623
|
+
return hasTwVars(node, count);
|
|
1499
1624
|
}
|
|
1500
1625
|
return false;
|
|
1501
1626
|
}
|
|
@@ -1786,83 +1911,71 @@ function createStylePipeline(options) {
|
|
|
1786
1911
|
};
|
|
1787
1912
|
}
|
|
1788
1913
|
|
|
1789
|
-
// src/
|
|
1790
|
-
function createInjectPreflight(options) {
|
|
1791
|
-
const result = [];
|
|
1792
|
-
if (options && typeof options === "object") {
|
|
1793
|
-
const entries = Object.entries(options);
|
|
1794
|
-
for (const [prop, value] of entries) {
|
|
1795
|
-
if (value !== false) {
|
|
1796
|
-
result.push({
|
|
1797
|
-
prop,
|
|
1798
|
-
value: value.toString()
|
|
1799
|
-
});
|
|
1800
|
-
}
|
|
1801
|
-
}
|
|
1802
|
-
}
|
|
1803
|
-
return () => {
|
|
1804
|
-
return result;
|
|
1805
|
-
};
|
|
1806
|
-
}
|
|
1807
|
-
|
|
1808
|
-
// src/handler.ts
|
|
1914
|
+
// src/processor-cache.ts
|
|
1809
1915
|
function createProcessOptions(options) {
|
|
1810
1916
|
return {
|
|
1811
1917
|
from: void 0,
|
|
1812
1918
|
...options.postcssOptions?.options ?? {}
|
|
1813
1919
|
};
|
|
1814
1920
|
}
|
|
1815
|
-
var
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
cached
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
}
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
}
|
|
1921
|
+
var StyleProcessorCache = class {
|
|
1922
|
+
pipelineCache = /* @__PURE__ */ new WeakMap();
|
|
1923
|
+
processOptionsCache = /* @__PURE__ */ new WeakMap();
|
|
1924
|
+
processorCache = /* @__PURE__ */ new WeakMap();
|
|
1925
|
+
getPipeline(options) {
|
|
1926
|
+
let pipeline = this.pipelineCache.get(options);
|
|
1927
|
+
if (!pipeline) {
|
|
1928
|
+
pipeline = createStylePipeline(options);
|
|
1929
|
+
this.pipelineCache.set(options, pipeline);
|
|
1930
|
+
}
|
|
1931
|
+
return pipeline;
|
|
1932
|
+
}
|
|
1933
|
+
getProcessOptions(options) {
|
|
1934
|
+
const source = options.postcssOptions?.options;
|
|
1935
|
+
const fingerprint = source ? fingerprintOptions(source) : void 0;
|
|
1936
|
+
const cached = this.processOptionsCache.get(options);
|
|
1937
|
+
if (!cached || cached.fingerprint !== fingerprint) {
|
|
1938
|
+
const created = createProcessOptions(options);
|
|
1939
|
+
this.processOptionsCache.set(options, { value: created, fingerprint });
|
|
1940
|
+
return { ...created };
|
|
1941
|
+
}
|
|
1942
|
+
return { ...cached.value };
|
|
1943
|
+
}
|
|
1944
|
+
getProcessor(options) {
|
|
1945
|
+
let processor = this.processorCache.get(options);
|
|
1946
|
+
if (!processor) {
|
|
1947
|
+
const pipeline = this.getPipeline(options);
|
|
1948
|
+
processor = postcss(pipeline.plugins);
|
|
1949
|
+
this.processorCache.set(options, processor);
|
|
1950
|
+
}
|
|
1951
|
+
return processor;
|
|
1952
|
+
}
|
|
1953
|
+
};
|
|
1954
|
+
|
|
1955
|
+
// src/handler.ts
|
|
1845
1956
|
function createStyleHandler(options) {
|
|
1846
|
-
const cachedOptions =
|
|
1957
|
+
const cachedOptions = defuOverrideArray4(
|
|
1847
1958
|
options,
|
|
1848
1959
|
getDefaultOptions(options)
|
|
1849
1960
|
);
|
|
1850
1961
|
cachedOptions.cssInjectPreflight = createInjectPreflight(cachedOptions.cssPreflight);
|
|
1851
|
-
|
|
1852
|
-
|
|
1962
|
+
const resolver = createOptionsResolver(cachedOptions);
|
|
1963
|
+
const cache = new StyleProcessorCache();
|
|
1964
|
+
const base = resolver.resolve();
|
|
1965
|
+
cache.getProcessor(base);
|
|
1966
|
+
cache.getProcessOptions(base);
|
|
1853
1967
|
const handler = ((rawSource, opt) => {
|
|
1854
|
-
const resolvedOptions =
|
|
1855
|
-
|
|
1968
|
+
const resolvedOptions = resolver.resolve(opt);
|
|
1969
|
+
const processor = cache.getProcessor(resolvedOptions);
|
|
1970
|
+
const processOptions = cache.getProcessOptions(resolvedOptions);
|
|
1971
|
+
return processor.process(
|
|
1856
1972
|
rawSource,
|
|
1857
|
-
|
|
1858
|
-
);
|
|
1973
|
+
processOptions
|
|
1974
|
+
).async();
|
|
1859
1975
|
});
|
|
1860
1976
|
handler.getPipeline = (opt) => {
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
}
|
|
1864
|
-
const resolvedOptions = defuOverrideArray3(opt, cachedOptions);
|
|
1865
|
-
return getCachedPipeline(resolvedOptions);
|
|
1977
|
+
const resolvedOptions = resolver.resolve(opt);
|
|
1978
|
+
return cache.getPipeline(resolvedOptions);
|
|
1866
1979
|
};
|
|
1867
1980
|
return handler;
|
|
1868
1981
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-tailwindcss/postcss",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.8",
|
|
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": "~6.0.1",
|
|
43
43
|
"@weapp-tailwindcss/postcss-calc": "^1.0.0",
|
|
44
44
|
"postcss": "~8.5.6",
|
|
45
45
|
"postcss-preset-env": "^10.5.0",
|
|
@@ -58,6 +58,7 @@
|
|
|
58
58
|
"dev": "tsup --watch --sourcemap",
|
|
59
59
|
"build": "tsup",
|
|
60
60
|
"test": "vitest run",
|
|
61
|
+
"bench": "vitest bench",
|
|
61
62
|
"test:dev": "vitest",
|
|
62
63
|
"release": "pnpm publish",
|
|
63
64
|
"lint": "eslint .",
|