@weapp-tailwindcss/postcss 2.0.7 → 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 +2 -1
package/dist/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }require('./chunk-GGNOJ77I.js');
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;require('./chunk-GGNOJ77I.js');
|
|
2
2
|
|
|
3
3
|
// src/handler.ts
|
|
4
4
|
var _shared = require('@weapp-tailwindcss/shared');
|
|
5
|
-
var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postcss);
|
|
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
|
+
|
|
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 = _shared.defuOverrideArray.call(void 0,
|
|
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
|
+
var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postcss);
|
|
132
|
+
|
|
38
133
|
// src/pipeline.ts
|
|
39
134
|
var _postcsspresetenv = require('postcss-preset-env'); var _postcsspresetenv2 = _interopRequireDefault(_postcsspresetenv);
|
|
40
135
|
|
|
@@ -154,7 +249,7 @@ function createContext() {
|
|
|
154
249
|
// src/plugins/getCalcPlugin.ts
|
|
155
250
|
var _postcsscalc = require('@weapp-tailwindcss/postcss-calc'); var _postcsscalc2 = _interopRequireDefault(_postcsscalc);
|
|
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++) {
|
|
@@ -276,8 +371,36 @@ function getRemTransformPlugin(options) {
|
|
|
276
371
|
// src/plugins/post.ts
|
|
277
372
|
|
|
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 = _optionalChain([options, 'optionalAccess', _12 => _12.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,23 +540,27 @@ 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
|
+
|
|
545
|
+
function createCssVarNodes(definitions) {
|
|
546
|
+
return definitions.map((def) => new (0, _postcss.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/;
|
|
423
555
|
var RADIUS_THRESHOLD = 1e5;
|
|
424
556
|
var CLAMP_PX = 9999;
|
|
425
557
|
function isTailwindcssV4(options) {
|
|
426
|
-
return _optionalChain([options, 'optionalAccess',
|
|
558
|
+
return _optionalChain([options, 'optionalAccess', _13 => _13.majorVersion]) === 4;
|
|
427
559
|
}
|
|
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 (0, _postcss.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/,
|
|
@@ -475,7 +602,7 @@ function normalizeTailwindcssV4Declaration(decl) {
|
|
|
475
602
|
|
|
476
603
|
// src/compat/uni-app-x.ts
|
|
477
604
|
function isUniAppXEnabled(options) {
|
|
478
|
-
return Boolean(_optionalChain([options, 'optionalAccess',
|
|
605
|
+
return Boolean(_optionalChain([options, 'optionalAccess', _14 => _14.uniAppX]));
|
|
479
606
|
}
|
|
480
607
|
function stripUnsupportedPseudoForUniAppX(node, enabled) {
|
|
481
608
|
if (!enabled) {
|
|
@@ -509,7 +636,7 @@ var beforeAfterParser = _postcssselectorparser2.default.call(void 0, (selectors)
|
|
|
509
636
|
return;
|
|
510
637
|
}
|
|
511
638
|
selectors.walkPseudos((s) => {
|
|
512
|
-
if (_optionalChain([s, 'access',
|
|
639
|
+
if (_optionalChain([s, 'access', _15 => _15.parent, 'optionalAccess', _16 => _16.length]) === 1) {
|
|
513
640
|
if (/^:?:before$/.test(s.value)) {
|
|
514
641
|
state.before = true;
|
|
515
642
|
}
|
|
@@ -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 = _nullishCoalesce(options, () => ( fallbackDefaultKey));
|
|
588
716
|
let entry = fallbackRemoveCache.get(cacheKey);
|
|
@@ -597,13 +725,13 @@ function getFallbackRemove(_rule, options) {
|
|
|
597
725
|
maybeImportantId = true;
|
|
598
726
|
}
|
|
599
727
|
if (selector.type === "universal") {
|
|
600
|
-
_optionalChain([selector, 'access',
|
|
728
|
+
_optionalChain([selector, 'access', _17 => _17.parent, 'optionalAccess', _18 => _18.remove, 'call', _19 => _19()]);
|
|
601
729
|
} else if (selector.type === "pseudo") {
|
|
602
730
|
if (selector.value === ":is") {
|
|
603
|
-
if (maybeImportantId && _optionalChain([selector, 'access',
|
|
731
|
+
if (maybeImportantId && _optionalChain([selector, 'access', _20 => _20.nodes, 'access', _21 => _21[0], 'optionalAccess', _22 => _22.type]) === "selector") {
|
|
604
732
|
selector.replaceWith(selector.nodes[0]);
|
|
605
733
|
} else {
|
|
606
|
-
_optionalChain([selector, 'access',
|
|
734
|
+
_optionalChain([selector, 'access', _23 => _23.parent, 'optionalAccess', _24 => _24.remove, 'call', _25 => _25()]);
|
|
607
735
|
}
|
|
608
736
|
} else if (selector.value === ":not") {
|
|
609
737
|
for (const x of selector.nodes) {
|
|
@@ -626,7 +754,7 @@ function getFallbackRemove(_rule, options) {
|
|
|
626
754
|
}
|
|
627
755
|
} else if (selector.type === "attribute") {
|
|
628
756
|
if (selector.attribute === "hidden") {
|
|
629
|
-
_optionalChain([activeRule, 'optionalAccess',
|
|
757
|
+
_optionalChain([activeRule, 'optionalAccess', _26 => _26.remove, 'call', _27 => _27()]);
|
|
630
758
|
}
|
|
631
759
|
}
|
|
632
760
|
});
|
|
@@ -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 = _nullishCoalesce(_optionalChain([declarations, 'access', _28 => _28[declarations.length - 1], 'optionalAccess', _29 => _29.next, 'call', _30 => _30()]), () => ( 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 = _nullishCoalesce(_optionalChain([unique, 'access', _27 => _27[unique.length - 1], 'optionalAccess', _28 => _28.next, 'call', _29 => _29()]), () => ( 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) {
|
|
@@ -797,7 +952,7 @@ function isNotLastChildPseudo(node) {
|
|
|
797
952
|
if (firstSelector.type !== "selector") {
|
|
798
953
|
return false;
|
|
799
954
|
}
|
|
800
|
-
const target = _optionalChain([firstSelector, 'access',
|
|
955
|
+
const target = _optionalChain([firstSelector, 'access', _31 => _31.nodes, 'optionalAccess', _32 => _32[0]]);
|
|
801
956
|
return Boolean(target && target.type === "pseudo" && target.value === ":last-child");
|
|
802
957
|
}
|
|
803
958
|
function transformSpacingSelector(nodes2, options) {
|
|
@@ -844,7 +999,7 @@ function flattenWherePseudo(node, context, index, parent) {
|
|
|
844
999
|
node.value = ":is";
|
|
845
1000
|
}
|
|
846
1001
|
if (index === 0 && node.length === 1) {
|
|
847
|
-
const targetSelector = _optionalChain([node, 'access',
|
|
1002
|
+
const targetSelector = _optionalChain([node, 'access', _33 => _33.nodes, 'optionalAccess', _34 => _34[0]]);
|
|
848
1003
|
if (targetSelector && targetSelector.type === "selector" && transformSpacingSelector(targetSelector.nodes, context.options)) {
|
|
849
1004
|
context.requiresSpacingNormalization = true;
|
|
850
1005
|
}
|
|
@@ -864,7 +1019,7 @@ function handleUniversalNode(node, context) {
|
|
|
864
1019
|
if (node.type !== "universal") {
|
|
865
1020
|
return;
|
|
866
1021
|
}
|
|
867
|
-
const replacement = _optionalChain([context, 'access',
|
|
1022
|
+
const replacement = _optionalChain([context, 'access', _35 => _35.options, 'access', _36 => _36.cssSelectorReplacement, 'optionalAccess', _37 => _37.universal]);
|
|
868
1023
|
if (replacement) {
|
|
869
1024
|
node.value = composeIsPseudo(replacement);
|
|
870
1025
|
}
|
|
@@ -899,7 +1054,7 @@ function handleCombinatorNode(node, index, context) {
|
|
|
899
1054
|
if (node.type !== "combinator" || node.value !== ">") {
|
|
900
1055
|
return;
|
|
901
1056
|
}
|
|
902
|
-
const nodes2 = _optionalChain([node, 'access',
|
|
1057
|
+
const nodes2 = _optionalChain([node, 'access', _38 => _38.parent, 'optionalAccess', _39 => _39.nodes]);
|
|
903
1058
|
if (!nodes2) {
|
|
904
1059
|
return;
|
|
905
1060
|
}
|
|
@@ -915,7 +1070,7 @@ function handlePseudoNode(node, index, context, parent) {
|
|
|
915
1070
|
if (node.type !== "pseudo") {
|
|
916
1071
|
return;
|
|
917
1072
|
}
|
|
918
|
-
if (node.value === ":root" && _optionalChain([context, 'access',
|
|
1073
|
+
if (node.value === ":root" && _optionalChain([context, 'access', _40 => _40.options, 'access', _41 => _41.cssSelectorReplacement, 'optionalAccess', _42 => _42.root])) {
|
|
919
1074
|
node.value = composeIsPseudo(context.options.cssSelectorReplacement.root);
|
|
920
1075
|
return;
|
|
921
1076
|
}
|
|
@@ -937,7 +1092,7 @@ function handleSelectorNode(selector, context) {
|
|
|
937
1092
|
}
|
|
938
1093
|
function transformSelectors(selectors, context) {
|
|
939
1094
|
selectors.walk((node, index) => {
|
|
940
|
-
const parent = _optionalChain([node, 'access',
|
|
1095
|
+
const parent = _optionalChain([node, 'access', _43 => _43.parent, 'optionalAccess', _44 => _44.type]) === "selector" ? node.parent : void 0;
|
|
941
1096
|
switch (node.type) {
|
|
942
1097
|
case "class":
|
|
943
1098
|
handleClassNode(node, context);
|
|
@@ -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
|
}
|
|
@@ -1015,7 +1170,7 @@ function normalizeSelectorList(value) {
|
|
|
1015
1170
|
return Array.isArray(value) ? value.filter(Boolean) : [value];
|
|
1016
1171
|
}
|
|
1017
1172
|
function getSpecificityMatchingName(options) {
|
|
1018
|
-
const feature = _optionalChain([options, 'access',
|
|
1173
|
+
const feature = _optionalChain([options, 'access', _45 => _45.cssPresetEnv, 'optionalAccess', _46 => _46.features, 'optionalAccess', _47 => _47["is-pseudo-class"]]);
|
|
1019
1174
|
if (feature && typeof feature === "object" && "specificityMatchingName" in feature) {
|
|
1020
1175
|
const specificityName = feature.specificityMatchingName;
|
|
1021
1176
|
return typeof specificityName === "string" && specificityName.length > 0 ? specificityName : void 0;
|
|
@@ -1024,12 +1179,12 @@ function getSpecificityMatchingName(options) {
|
|
|
1024
1179
|
}
|
|
1025
1180
|
function createRootSpecificityCleaner(options) {
|
|
1026
1181
|
const specificityMatchingName = getSpecificityMatchingName(options);
|
|
1027
|
-
const selectors = normalizeSelectorList(_optionalChain([options, 'access',
|
|
1182
|
+
const selectors = normalizeSelectorList(_optionalChain([options, 'access', _48 => _48.cssSelectorReplacement, 'optionalAccess', _49 => _49.root]));
|
|
1028
1183
|
if (!specificityMatchingName || selectors.length === 0) {
|
|
1029
1184
|
return void 0;
|
|
1030
1185
|
}
|
|
1031
1186
|
const suffix = `:not(.${specificityMatchingName})`;
|
|
1032
|
-
const targets = selectors.map((selector) => _optionalChain([selector, 'optionalAccess',
|
|
1187
|
+
const targets = selectors.map((selector) => _optionalChain([selector, 'optionalAccess', _50 => _50.trim, 'call', _51 => _51()])).filter((selector) => Boolean(_optionalChain([selector, 'optionalAccess', _52 => _52.length]))).map((selector) => ({
|
|
1033
1188
|
match: `${selector}${suffix}`,
|
|
1034
1189
|
spacedMatch: `${selector} ${suffix}`,
|
|
1035
1190
|
replacement: selector
|
|
@@ -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 = _nullishCoalesce(_optionalChain([declarations, 'access', _52 => _52[declarations.length - 1], 'optionalAccess', _53 => _53.next, 'call', _54 => _54()]), () => ( 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]) {
|
|
@@ -1219,9 +1352,9 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
|
|
|
1219
1352
|
const fallbackRemove = enableMainChunkTransforms ? getFallbackRemove(void 0, opts) : void 0;
|
|
1220
1353
|
p.RuleExit = (rule) => {
|
|
1221
1354
|
if (enableMainChunkTransforms) {
|
|
1222
|
-
_optionalChain([fallbackRemove, 'optionalAccess',
|
|
1355
|
+
_optionalChain([fallbackRemove, 'optionalAccess', _53 => _53.transformSync, 'call', _54 => _54(rule)]);
|
|
1223
1356
|
}
|
|
1224
|
-
_optionalChain([cleanRootSpecificity, 'optionalCall',
|
|
1357
|
+
_optionalChain([cleanRootSpecificity, 'optionalCall', _55 => _55(rule)]);
|
|
1225
1358
|
if (enableMainChunkTransforms) {
|
|
1226
1359
|
dedupeDeclarations(rule);
|
|
1227
1360
|
if (rule.selectors.length === 0 || rule.selectors.length === 1 && rule.selector.trim() === "") {
|
|
@@ -1234,12 +1367,15 @@ 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();
|
|
1241
1377
|
}
|
|
1242
|
-
_optionalChain([atRule, 'access',
|
|
1378
|
+
_optionalChain([atRule, 'access', _56 => _56.nodes, 'optionalAccess', _57 => _57.length]) === 0 && atRule.remove();
|
|
1243
1379
|
};
|
|
1244
1380
|
}
|
|
1245
1381
|
return p;
|
|
@@ -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 _nullishCoalesce(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
|
}
|
|
@@ -1533,7 +1658,7 @@ function remakeCssVarSelector(selectors, options) {
|
|
|
1533
1658
|
function commonChunkPreflight(node, options) {
|
|
1534
1659
|
const { ctx, cssInjectPreflight, injectAdditionalCssVarScope } = options;
|
|
1535
1660
|
if (testIfVariablesScope(node)) {
|
|
1536
|
-
_optionalChain([ctx, 'optionalAccess',
|
|
1661
|
+
_optionalChain([ctx, 'optionalAccess', _58 => _58.markVariablesScope, 'call', _59 => _59(node)]);
|
|
1537
1662
|
node.selectors = remakeCssVarSelector(node.selectors, options);
|
|
1538
1663
|
node.before(makePseudoVarRule());
|
|
1539
1664
|
if (typeof cssInjectPreflight === "function") {
|
|
@@ -1590,9 +1715,9 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
|
|
|
1590
1715
|
root.walkAtRules((atRule) => {
|
|
1591
1716
|
if (atRule.name === "layer") {
|
|
1592
1717
|
if (atRule.params === "properties") {
|
|
1593
|
-
if (atRule.nodes === void 0 || _optionalChain([atRule, 'access',
|
|
1718
|
+
if (atRule.nodes === void 0 || _optionalChain([atRule, 'access', _60 => _60.nodes, 'optionalAccess', _61 => _61.length]) === 0) {
|
|
1594
1719
|
layerProperties = atRule;
|
|
1595
|
-
} else if (_optionalChain([atRule, 'access',
|
|
1720
|
+
} else if (_optionalChain([atRule, 'access', _62 => _62.first, 'optionalAccess', _63 => _63.type]) === "atrule" && isTailwindcssV4ModernCheck(atRule.first)) {
|
|
1596
1721
|
if (layerProperties) {
|
|
1597
1722
|
layerProperties.replaceWith(atRule.first.nodes);
|
|
1598
1723
|
atRule.remove();
|
|
@@ -1604,7 +1729,7 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
|
|
|
1604
1729
|
atRule.replaceWith(atRule.nodes);
|
|
1605
1730
|
}
|
|
1606
1731
|
} else if (isTailwindcssV4ModernCheck(atRule)) {
|
|
1607
|
-
if (_optionalChain([atRule, 'access',
|
|
1732
|
+
if (_optionalChain([atRule, 'access', _64 => _64.first, 'optionalAccess', _65 => _65.type]) === "atrule" && atRule.first.name === "layer") {
|
|
1608
1733
|
atRule.replaceWith(atRule.first.nodes);
|
|
1609
1734
|
}
|
|
1610
1735
|
}
|
|
@@ -1649,7 +1774,7 @@ function createPipelineDefinitions(options) {
|
|
|
1649
1774
|
normal: [],
|
|
1650
1775
|
post: []
|
|
1651
1776
|
};
|
|
1652
|
-
const userPlugins = normalizeUserPlugins(_optionalChain([options, 'access',
|
|
1777
|
+
const userPlugins = normalizeUserPlugins(_optionalChain([options, 'access', _66 => _66.postcssOptions, 'optionalAccess', _67 => _67.plugins]));
|
|
1653
1778
|
userPlugins.forEach((plugin, index) => {
|
|
1654
1779
|
stages.pre.push(createStaticDefinition(`pre:user-${index}`, "pre", plugin));
|
|
1655
1780
|
});
|
|
@@ -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
|
-
..._nullishCoalesce(_optionalChain([options, 'access',
|
|
1918
|
+
..._nullishCoalesce(_optionalChain([options, 'access', _68 => _68.postcssOptions, 'optionalAccess', _69 => _69.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 = class {constructor() { _class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this); }
|
|
1922
|
+
__init() {this.pipelineCache = /* @__PURE__ */ new WeakMap()}
|
|
1923
|
+
__init2() {this.processOptionsCache = /* @__PURE__ */ new WeakMap()}
|
|
1924
|
+
__init3() {this.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 = _optionalChain([options, 'access', _70 => _70.postcssOptions, 'optionalAccess', _71 => _71.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 = _postcss2.default.call(void 0, pipeline.plugins);
|
|
1949
|
+
this.processorCache.set(options, processor);
|
|
1950
|
+
}
|
|
1951
|
+
return processor;
|
|
1952
|
+
}
|
|
1953
|
+
}, _class);
|
|
1954
|
+
|
|
1955
|
+
// src/handler.ts
|
|
1845
1956
|
function createStyleHandler(options) {
|
|
1846
1957
|
const cachedOptions = _shared.defuOverrideArray.call(void 0,
|
|
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 = _shared.defuOverrideArray.call(void 0, 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/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",
|
|
@@ -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 .",
|