@weapp-tailwindcss/postcss 0.0.1-alpha.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.js ADDED
@@ -0,0 +1,889 @@
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; }// src/index.ts
2
+ var _shared = require('@weapp-tailwindcss/shared');
3
+ var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postcss);
4
+
5
+ // ../../node_modules/.pnpm/@csstools+postcss-is-pseudo-class@5.0.1_postcss@8.4.49/node_modules/@csstools/postcss-is-pseudo-class/dist/index.mjs
6
+ var _postcssselectorparser = require('postcss-selector-parser'); var _postcssselectorparser2 = _interopRequireDefault(_postcssselectorparser);
7
+
8
+ // ../../node_modules/.pnpm/@csstools+selector-specificity@5.0.0_postcss-selector-parser@7.0.0/node_modules/@csstools/selector-specificity/dist/index.mjs
9
+
10
+ function compare(e3, t2) {
11
+ return e3.a === t2.a ? e3.b === t2.b ? e3.c - t2.c : e3.b - t2.b : e3.a - t2.a;
12
+ }
13
+ function selectorSpecificity(t2, s) {
14
+ const i = _optionalChain([s, 'optionalAccess', _ => _.customSpecificity, 'optionalCall', _2 => _2(t2)]);
15
+ if (i) return i;
16
+ if (!t2) return { a: 0, b: 0, c: 0 };
17
+ let c = 0, n = 0, o2 = 0;
18
+ if ("universal" == t2.type) return { a: 0, b: 0, c: 0 };
19
+ if ("id" === t2.type) c += 1;
20
+ else if ("tag" === t2.type) o2 += 1;
21
+ else if ("class" === t2.type) n += 1;
22
+ else if ("attribute" === t2.type) n += 1;
23
+ else if (isPseudoElement(t2)) switch (t2.value.toLowerCase()) {
24
+ case "::slotted":
25
+ if (o2 += 1, t2.nodes && t2.nodes.length > 0) {
26
+ const e3 = specificityOfMostSpecificListItem(t2.nodes, s);
27
+ c += e3.a, n += e3.b, o2 += e3.c;
28
+ }
29
+ break;
30
+ case "::view-transition-group":
31
+ case "::view-transition-image-pair":
32
+ case "::view-transition-old":
33
+ case "::view-transition-new":
34
+ return t2.nodes && 1 === t2.nodes.length && "selector" === t2.nodes[0].type && selectorNodeContainsNothingOrOnlyUniversal(t2.nodes[0]) ? { a: 0, b: 0, c: 0 } : { a: 0, b: 0, c: 1 };
35
+ default:
36
+ o2 += 1;
37
+ }
38
+ else if (_postcssselectorparser2.default.isPseudoClass(t2)) switch (t2.value.toLowerCase()) {
39
+ case ":-webkit-any":
40
+ case ":any":
41
+ default:
42
+ n += 1;
43
+ break;
44
+ case ":-moz-any":
45
+ case ":has":
46
+ case ":is":
47
+ case ":matches":
48
+ case ":not":
49
+ if (t2.nodes && t2.nodes.length > 0) {
50
+ const e3 = specificityOfMostSpecificListItem(t2.nodes, s);
51
+ c += e3.a, n += e3.b, o2 += e3.c;
52
+ }
53
+ break;
54
+ case ":where":
55
+ break;
56
+ case ":nth-child":
57
+ case ":nth-last-child":
58
+ if (n += 1, t2.nodes && t2.nodes.length > 0) {
59
+ const i2 = t2.nodes[0].nodes.findIndex((e3) => "tag" === e3.type && "of" === e3.value.toLowerCase());
60
+ if (i2 > -1) {
61
+ const a = _postcssselectorparser2.default.selector({ nodes: [], value: "" });
62
+ t2.nodes[0].nodes.slice(i2 + 1).forEach((e3) => {
63
+ a.append(e3.clone());
64
+ });
65
+ const r = [a];
66
+ t2.nodes.length > 1 && r.push(...t2.nodes.slice(1));
67
+ const l = specificityOfMostSpecificListItem(r, s);
68
+ c += l.a, n += l.b, o2 += l.c;
69
+ }
70
+ }
71
+ break;
72
+ case ":local":
73
+ case ":global":
74
+ t2.nodes && t2.nodes.length > 0 && t2.nodes.forEach((e3) => {
75
+ const t3 = selectorSpecificity(e3, s);
76
+ c += t3.a, n += t3.b, o2 += t3.c;
77
+ });
78
+ break;
79
+ case ":host":
80
+ case ":host-context":
81
+ if (n += 1, t2.nodes && t2.nodes.length > 0) {
82
+ const e3 = specificityOfMostSpecificListItem(t2.nodes, s);
83
+ c += e3.a, n += e3.b, o2 += e3.c;
84
+ }
85
+ break;
86
+ case ":active-view-transition":
87
+ case ":active-view-transition-type":
88
+ return { a: 0, b: 1, c: 0 };
89
+ }
90
+ else _postcssselectorparser2.default.isContainer(t2) && _optionalChain([t2, 'access', _3 => _3.nodes, 'optionalAccess', _4 => _4.length]) > 0 && t2.nodes.forEach((e3) => {
91
+ const t3 = selectorSpecificity(e3, s);
92
+ c += t3.a, n += t3.b, o2 += t3.c;
93
+ });
94
+ return { a: c, b: n, c: o2 };
95
+ }
96
+ function specificityOfMostSpecificListItem(e3, t2) {
97
+ let s = { a: 0, b: 0, c: 0 };
98
+ return e3.forEach((e4) => {
99
+ const i = selectorSpecificity(e4, t2);
100
+ compare(i, s) < 0 || (s = i);
101
+ }), s;
102
+ }
103
+ function isPseudoElement(t2) {
104
+ return _postcssselectorparser2.default.isPseudoElement(t2);
105
+ }
106
+ function selectorNodeContainsNothingOrOnlyUniversal(e3) {
107
+ if (!e3) return false;
108
+ if (!e3.nodes) return false;
109
+ const t2 = e3.nodes.filter((e4) => "comment" !== e4.type);
110
+ return 0 === t2.length || 1 === t2.length && "universal" === t2[0].type;
111
+ }
112
+
113
+ // ../../node_modules/.pnpm/@csstools+postcss-is-pseudo-class@5.0.1_postcss@8.4.49/node_modules/@csstools/postcss-is-pseudo-class/dist/index.mjs
114
+ function alwaysValidSelector(s) {
115
+ const o2 = _postcssselectorparser2.default.call(void 0, ).astSync(s);
116
+ let t2 = true;
117
+ return o2.walk((e3) => {
118
+ 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', _5 => _5.nodes, 'optionalAccess', _6 => _6.length]) || ":hover" !== e3.value.toLowerCase() && ":focus" !== e3.value.toLowerCase())) {
119
+ if ("pseudo" === e3.type && 1 === _optionalChain([e3, 'access', _7 => _7.nodes, 'optionalAccess', _8 => _8.length]) && ":not" === e3.value.toLowerCase()) {
120
+ let s2 = true;
121
+ if (e3.nodes[0].walkCombinators(() => {
122
+ s2 = false;
123
+ }), s2) return;
124
+ }
125
+ return t2 = false, false;
126
+ }
127
+ }), t2;
128
+ }
129
+ function sortCompoundSelectorsInsideComplexSelector(s) {
130
+ if (!s || !s.nodes || 1 === s.nodes.length) return;
131
+ const o2 = [];
132
+ let t2 = [];
133
+ for (let n2 = 0; n2 < s.nodes.length; n2++) "combinator" !== s.nodes[n2].type ? _postcssselectorparser2.default.isPseudoElement(s.nodes[n2]) ? (o2.push(t2), t2 = [s.nodes[n2]]) : t2.push(s.nodes[n2]) : (o2.push(t2), o2.push([s.nodes[n2]]), t2 = []);
134
+ o2.push(t2);
135
+ const n = [];
136
+ for (let e3 = 0; e3 < o2.length; e3++) {
137
+ const s2 = o2[e3];
138
+ s2.sort((e4, s3) => "selector" === e4.type && "selector" === s3.type && e4.nodes.length && s3.nodes.length ? selectorTypeOrder(e4.nodes[0], e4.nodes[0].type) - selectorTypeOrder(s3.nodes[0], s3.nodes[0].type) : "selector" === e4.type && e4.nodes.length ? selectorTypeOrder(e4.nodes[0], e4.nodes[0].type) - selectorTypeOrder(s3, s3.type) : "selector" === s3.type && s3.nodes.length ? selectorTypeOrder(e4, e4.type) - selectorTypeOrder(s3.nodes[0], s3.nodes[0].type) : selectorTypeOrder(e4, e4.type) - selectorTypeOrder(s3, s3.type));
139
+ const t3 = new Set(s2.map((e4) => e4.type)), r = t3.has("universal") && (t3.has("tag") || t3.has("attribute") || t3.has("class") || t3.has("id") || t3.has("pseudo"));
140
+ for (let e4 = 0; e4 < s2.length; e4++) "universal" === s2[e4].type && r ? s2[e4].remove() : n.push(s2[e4]);
141
+ }
142
+ s.removeAll();
143
+ for (let o3 = n.length - 1; o3 >= 0; o3--) {
144
+ const t3 = n[o3 - 1];
145
+ if (n[o3].remove(), t3 && "tag" === t3.type && "tag" === n[o3].type) {
146
+ const t4 = _postcssselectorparser2.default.pseudo({ value: ":is", nodes: [_postcssselectorparser2.default.selector({ value: "", nodes: [n[o3]] })] });
147
+ t4.parent = s, s.nodes.unshift(t4);
148
+ } else n[o3].parent = s, s.nodes.unshift(n[o3]);
149
+ }
150
+ }
151
+ function selectorTypeOrder(s, t2) {
152
+ return _postcssselectorparser2.default.isPseudoElement(s) ? o.pseudoElement : o[t2];
153
+ }
154
+ var o = { universal: 0, tag: 1, pseudoElement: 2, id: 3, class: 4, attribute: 5, pseudo: 6, selector: 7, string: 8, root: 9, comment: 10 };
155
+ function childAdjacentChild(e3) {
156
+ return !(!e3 || !e3.nodes) && ("selector" === e3.type && (3 === e3.nodes.length && (!(!e3.nodes[0] || "pseudo" !== e3.nodes[0].type || ":-csstools-matches" !== e3.nodes[0].value) && (!(!e3.nodes[1] || "combinator" !== e3.nodes[1].type || "+" !== e3.nodes[1].value && "~" !== e3.nodes[1].value) && (!(!e3.nodes[2] || "pseudo" !== e3.nodes[2].type || ":-csstools-matches" !== e3.nodes[2].value) && (!(!e3.nodes[0].nodes || 1 !== e3.nodes[0].nodes.length) && ("selector" === e3.nodes[0].nodes[0].type && (!(!e3.nodes[0].nodes[0].nodes || 3 !== e3.nodes[0].nodes[0].nodes.length) && (!(!e3.nodes[0].nodes[0].nodes || "combinator" !== e3.nodes[0].nodes[0].nodes[1].type || ">" !== e3.nodes[0].nodes[0].nodes[1].value) && (!(!e3.nodes[2].nodes || 1 !== e3.nodes[2].nodes.length) && ("selector" === e3.nodes[2].nodes[0].type && (!(!e3.nodes[2].nodes[0].nodes || 3 !== e3.nodes[2].nodes[0].nodes.length) && (!(!e3.nodes[2].nodes[0].nodes || "combinator" !== e3.nodes[2].nodes[0].nodes[1].type || ">" !== e3.nodes[2].nodes[0].nodes[1].value) && (e3.nodes[0].nodes[0].insertAfter(e3.nodes[0].nodes[0].nodes[0], e3.nodes[2].nodes[0].nodes[0].clone()), e3.nodes[2].nodes[0].nodes[1].remove(), e3.nodes[2].nodes[0].nodes[0].remove(), e3.nodes[0].replaceWith(e3.nodes[0].nodes[0]), e3.nodes[2].replaceWith(e3.nodes[2].nodes[0]), true))))))))))))));
157
+ }
158
+ function isInCompoundWithOneOtherElement(s) {
159
+ if (!s || !s.nodes) return false;
160
+ if (!_postcssselectorparser2.default.isSelector(s)) return false;
161
+ if (2 !== s.nodes.length) return false;
162
+ let o2 = -1, t2 = -1;
163
+ s.nodes[0] && _postcssselectorparser2.default.isPseudoClass(s.nodes[0]) && ":-csstools-matches" === s.nodes[0].value ? (o2 = 0, t2 = 1) : s.nodes[1] && _postcssselectorparser2.default.isPseudoClass(s.nodes[1]) && ":-csstools-matches" === s.nodes[1].value && (o2 = 1, t2 = 0);
164
+ const n = s.nodes[o2];
165
+ if (!n || !_postcssselectorparser2.default.isPseudoClass(n) || 1 !== n.nodes.length) return false;
166
+ const r = s.nodes[t2];
167
+ return !!r && (!_postcssselectorparser2.default.isCombinator(r) && (n.nodes[0].append(r.clone()), n.replaceWith(...n.nodes[0].nodes), r.remove(), true));
168
+ }
169
+ function isPseudoInFirstCompound(s) {
170
+ if (!s || !s.nodes) return false;
171
+ if (!_postcssselectorparser2.default.isSelector(s)) return false;
172
+ let o2 = -1;
173
+ for (let t3 = 0; t3 < s.nodes.length; t3++) {
174
+ const n2 = s.nodes[t3];
175
+ if (_postcssselectorparser2.default.isCombinator(n2)) return false;
176
+ if (_postcssselectorparser2.default.isPseudoClass(n2) && ":-csstools-matches" === n2.value) {
177
+ if (!n2.nodes || 1 !== n2.nodes.length) return false;
178
+ o2 = t3;
179
+ break;
180
+ }
181
+ }
182
+ const t2 = s.nodes[o2];
183
+ if (!t2 || !_postcssselectorparser2.default.isPseudoClass(t2)) return false;
184
+ const n = s.nodes.slice(0, o2), r = s.nodes.slice(o2 + 1);
185
+ return n.forEach((e3) => {
186
+ t2.nodes[0].append(e3.clone());
187
+ }), r.forEach((e3) => {
188
+ t2.nodes[0].append(e3.clone());
189
+ }), t2.replaceWith(...t2.nodes), n.forEach((e3) => {
190
+ e3.remove();
191
+ }), r.forEach((e3) => {
192
+ e3.remove();
193
+ }), true;
194
+ }
195
+ function complexSelectors(s, o2, t2, n) {
196
+ return s.flatMap((s2) => {
197
+ if (-1 === s2.indexOf(":-csstools-matches") && -1 === s2.toLowerCase().indexOf(":is")) return s2;
198
+ const r = _postcssselectorparser2.default.call(void 0, ).astSync(s2);
199
+ return r.walkPseudos((s3) => {
200
+ if (":is" === s3.value.toLowerCase() && s3.nodes && s3.nodes.length && "selector" === s3.nodes[0].type && 0 === s3.nodes[0].nodes.length) return s3.value = ":not", void s3.nodes[0].append(_postcssselectorparser2.default.universal());
201
+ if (":-csstools-matches" === s3.value) if (!s3.nodes || s3.nodes.length) {
202
+ if (s3.walkPseudos((s4) => {
203
+ if (_postcssselectorparser2.default.isPseudoElement(s4)) {
204
+ let e3 = s4.value;
205
+ if (e3.startsWith("::-csstools-invalid-")) return;
206
+ for (; e3.startsWith(":"); ) e3 = e3.slice(1);
207
+ s4.value = `::-csstools-invalid-${e3}`, n();
208
+ }
209
+ }), 1 === s3.nodes.length && "selector" === s3.nodes[0].type) {
210
+ if (1 === s3.nodes[0].nodes.length) return void s3.replaceWith(s3.nodes[0].nodes[0]);
211
+ if (!s3.nodes[0].some((e3) => "combinator" === e3.type)) return void s3.replaceWith(...s3.nodes[0].nodes);
212
+ }
213
+ 1 !== r.nodes.length || "selector" !== r.nodes[0].type || 1 !== r.nodes[0].nodes.length || r.nodes[0].nodes[0] !== s3 ? childAdjacentChild(s3.parent) || isInCompoundWithOneOtherElement(s3.parent) || isPseudoInFirstCompound(s3.parent) || ("warning" === o2.onComplexSelector && t2(), s3.value = ":is") : s3.replaceWith(...s3.nodes[0].nodes);
214
+ } else s3.remove();
215
+ }), r.walk((e3) => {
216
+ "selector" === e3.type && "nodes" in e3 && 1 === e3.nodes.length && "selector" === e3.nodes[0].type && e3.replaceWith(e3.nodes[0]);
217
+ }), r.walk((e3) => {
218
+ "nodes" in e3 && sortCompoundSelectorsInsideComplexSelector(e3);
219
+ }), r.toString();
220
+ }).filter((e3) => !!e3);
221
+ }
222
+ function splitSelectors(o2, t2, n = 0) {
223
+ const r = ":not(#" + t2.specificityMatchingName + ")", d = ":not(." + t2.specificityMatchingName + ")", l = ":not(" + t2.specificityMatchingName + ")";
224
+ return o2.flatMap((o3) => {
225
+ if (-1 === o3.toLowerCase().indexOf(":is")) return o3;
226
+ let a = false;
227
+ const i = [];
228
+ if (_postcssselectorparser2.default.call(void 0, ).astSync(o3).walkPseudos((e3) => {
229
+ if (":is" !== e3.value.toLowerCase() || !e3.nodes || !e3.nodes.length) return;
230
+ if ("selector" === e3.nodes[0].type && 0 === e3.nodes[0].nodes.length) return;
231
+ if ("pseudo" === _optionalChain([e3, 'access', _9 => _9.parent, 'optionalAccess', _10 => _10.parent, 'optionalAccess', _11 => _11.type]) && ":not" === _optionalChain([e3, 'access', _12 => _12.parent, 'optionalAccess', _13 => _13.parent, 'optionalAccess', _14 => _14.value, 'optionalAccess', _15 => _15.toLowerCase, 'call', _16 => _16()])) return void i.push([{ start: e3.parent.parent.sourceIndex, end: e3.parent.parent.sourceIndex + e3.parent.parent.toString().length, option: `:not(${e3.nodes.toString()})` }]);
232
+ if ("pseudo" === _optionalChain([e3, 'access', _17 => _17.parent, 'optionalAccess', _18 => _18.parent, 'optionalAccess', _19 => _19.type]) && ":has" === _optionalChain([e3, 'access', _20 => _20.parent, 'optionalAccess', _21 => _21.parent, 'optionalAccess', _22 => _22.value, 'optionalAccess', _23 => _23.toLowerCase, 'call', _24 => _24()])) return void (e3.value = ":-csstools-matches");
233
+ let o4 = e3.parent;
234
+ for (; o4; ) {
235
+ if (o4.value && ":is" === o4.value.toLowerCase() && "pseudo" === o4.type) return void (a = true);
236
+ o4 = o4.parent;
237
+ }
238
+ const t3 = selectorSpecificity(e3), n2 = e3.sourceIndex, c2 = n2 + e3.toString().length, p = [];
239
+ e3.nodes.forEach((e4) => {
240
+ const o5 = { start: n2, end: c2, option: "" }, a2 = selectorSpecificity(e4);
241
+ let i2 = e4.toString().trim();
242
+ const u = Math.max(0, t3.a - a2.a), h = Math.max(0, t3.b - a2.b), f = Math.max(0, t3.c - a2.c);
243
+ for (let e5 = 0; e5 < u; e5++) i2 += r;
244
+ for (let e5 = 0; e5 < h; e5++) i2 += d;
245
+ for (let e5 = 0; e5 < f; e5++) i2 += l;
246
+ o5.option = i2, p.push(o5);
247
+ }), i.push(p);
248
+ }), !i.length) return [o3];
249
+ let c = [];
250
+ return cartesianProduct(...i).forEach((e3) => {
251
+ let s = "";
252
+ for (let t3 = 0; t3 < e3.length; t3++) {
253
+ const n2 = e3[t3];
254
+ s += o3.substring(_optionalChain([e3, 'access', _25 => _25[t3 - 1], 'optionalAccess', _26 => _26.end]) || 0, e3[t3].start), s += ":-csstools-matches(" + n2.option + ")", t3 === e3.length - 1 && (s += o3.substring(e3[t3].end));
255
+ }
256
+ c.push(s);
257
+ }), a && n < 10 && (c = splitSelectors(c, t2, n + 1)), c;
258
+ }).filter((e3) => !!e3);
259
+ }
260
+ function cartesianProduct(...e3) {
261
+ const s = [], o2 = e3.length - 1;
262
+ return function helper(t2, n) {
263
+ for (let r = 0, d = e3[n].length; r < d; r++) {
264
+ const d2 = t2.slice(0);
265
+ d2.push(e3[n][r]), n === o2 ? s.push(d2) : helper(d2, n + 1);
266
+ }
267
+ }([], 0), s;
268
+ }
269
+ var t = /:is\(/i;
270
+ var creator = (e3) => {
271
+ const s = { specificityMatchingName: "does-not-exist", ...e3 || {} };
272
+ return { postcssPlugin: "postcss-is-pseudo-class", prepare() {
273
+ const e4 = /* @__PURE__ */ new WeakSet();
274
+ return { postcssPlugin: "postcss-is-pseudo-class", Rule(o2, { result: n }) {
275
+ if (!o2.selector) return;
276
+ if (!t.test(o2.selector)) return;
277
+ if (e4.has(o2)) return;
278
+ let r = false;
279
+ const warnOnComplexSelector = () => {
280
+ "warning" === s.onComplexSelector && (r || (r = true, o2.warn(n, `Complex selectors in '${o2.selector}' can not be transformed to an equivalent selector without ':is()'.`)));
281
+ };
282
+ let d = false;
283
+ const warnOnPseudoElements = () => {
284
+ "warning" === s.onPseudoElement && (d || (d = true, o2.warn(n, `Pseudo elements are not allowed in ':is()', unable to transform '${o2.selector}'`)));
285
+ };
286
+ try {
287
+ let t2 = false;
288
+ const n2 = [], r2 = complexSelectors(splitSelectors(o2.selectors, { specificityMatchingName: s.specificityMatchingName }), { onComplexSelector: s.onComplexSelector }, warnOnComplexSelector, warnOnPseudoElements);
289
+ if (Array.from(new Set(r2)).forEach((s2) => {
290
+ if (o2.selectors.indexOf(s2) > -1) n2.push(s2);
291
+ else {
292
+ if (alwaysValidSelector(s2)) return n2.push(s2), void (t2 = true);
293
+ e4.add(o2), o2.cloneBefore({ selector: s2 }), t2 = true;
294
+ }
295
+ }), n2.length && t2 && (e4.add(o2), o2.cloneBefore({ selectors: n2 })), !s.preserve) {
296
+ if (!t2) return;
297
+ o2.remove();
298
+ }
299
+ } catch (e5) {
300
+ if (!(e5 instanceof Error)) throw e5;
301
+ if (e5.message.indexOf("call stack size exceeded") > -1) throw e5;
302
+ o2.warn(n, `Failed to parse selector "${o2.selector}" with error: ${e5.message}`);
303
+ }
304
+ } };
305
+ } };
306
+ };
307
+ creator.postcss = true;
308
+
309
+ // src/plugins/index.ts
310
+ var _postcssremtoresponsivepixel = require('postcss-rem-to-responsive-pixel'); var _postcssremtoresponsivepixel2 = _interopRequireDefault(_postcssremtoresponsivepixel);
311
+
312
+ // src/symbols.ts
313
+ var VariablesScopeSymbol = Symbol("VariablesScope");
314
+
315
+ // src/plugins/ctx.ts
316
+ function createContext() {
317
+ const variablesScopeWeakMap = /* @__PURE__ */ new WeakMap();
318
+ function isVariablesScope(rule) {
319
+ return variablesScopeWeakMap.get(rule) === VariablesScopeSymbol;
320
+ }
321
+ function markVariablesScope(rule) {
322
+ variablesScopeWeakMap.set(rule, VariablesScopeSymbol);
323
+ }
324
+ return {
325
+ variablesScopeWeakMap,
326
+ isVariablesScope,
327
+ markVariablesScope
328
+ };
329
+ }
330
+
331
+ // src/constants.ts
332
+ var postcssPlugin = "postcss-weapp-tailwindcss-rename-plugin";
333
+
334
+ // src/selectorParser.ts
335
+
336
+
337
+ // src/shared.ts
338
+ var _escape = require('@weapp-core/escape');
339
+ function internalCssSelectorReplacer(selectors, options = {
340
+ escapeMap: _escape.SimpleMappingChars2String
341
+ }) {
342
+ const { mangleContext, escapeMap } = options;
343
+ if (mangleContext) {
344
+ selectors = mangleContext.cssHandler(selectors);
345
+ }
346
+ return _escape.escape.call(void 0, selectors, {
347
+ map: escapeMap
348
+ });
349
+ }
350
+ function composeIsPseudo(strs) {
351
+ if (typeof strs === "string") {
352
+ return strs;
353
+ }
354
+ if (strs.length > 1) {
355
+ return `:is(${strs.join(",")})`;
356
+ }
357
+ return strs.join("");
358
+ }
359
+
360
+ // src/selectorParser.ts
361
+ function createRuleTransform(rule, options) {
362
+ const { escapeMap, mangleContext, cssSelectorReplacement, cssRemoveHoverPseudoClass } = options;
363
+ const transform = (selectors) => {
364
+ selectors.walk((selector) => {
365
+ if (selector.type === "universal" && _optionalChain([cssSelectorReplacement, 'optionalAccess', _27 => _27.universal])) {
366
+ selector.value = composeIsPseudo(cssSelectorReplacement.universal);
367
+ }
368
+ if (cssRemoveHoverPseudoClass && selector.type === "selector") {
369
+ const node = selector.nodes.find((x) => x.type === "pseudo" && x.value === ":hover");
370
+ if (node) {
371
+ selector.remove();
372
+ }
373
+ }
374
+ if (selector.type === "pseudo" && selector.value === ":root" && _optionalChain([cssSelectorReplacement, 'optionalAccess', _28 => _28.root])) {
375
+ selector.value = composeIsPseudo(cssSelectorReplacement.root);
376
+ }
377
+ if (selector.type === "class") {
378
+ selector.value = internalCssSelectorReplacer(selector.value, {
379
+ escapeMap,
380
+ mangleContext
381
+ });
382
+ }
383
+ });
384
+ if (selectors.length === 0) {
385
+ rule.remove();
386
+ }
387
+ };
388
+ return transform;
389
+ }
390
+ function getRuleTransformer(rule, options) {
391
+ return _postcssselectorparser2.default.call(void 0, createRuleTransform(rule, options));
392
+ }
393
+ function ruleTransformSync(rule, options) {
394
+ const transformer = getRuleTransformer(rule, options);
395
+ return transformer.transformSync(rule, {
396
+ lossless: false,
397
+ updateSelector: true
398
+ });
399
+ }
400
+ function isOnlyBeforeAndAfterPseudoElement(node) {
401
+ let b = false;
402
+ let a = false;
403
+ _postcssselectorparser2.default.call(void 0, (selectors) => {
404
+ selectors.walkPseudos((s) => {
405
+ if (_optionalChain([s, 'access', _29 => _29.parent, 'optionalAccess', _30 => _30.length]) === 1) {
406
+ if (/^:?:before$/.test(s.value)) {
407
+ b = true;
408
+ }
409
+ if (/^:?:after$/.test(s.value)) {
410
+ a = true;
411
+ }
412
+ }
413
+ });
414
+ }).astSync(node);
415
+ return b && a;
416
+ }
417
+ var fallbackRemove = _postcssselectorparser2.default.call(void 0, (selectors) => {
418
+ let maybeImportantId = false;
419
+ selectors.walk((selector, idx) => {
420
+ if (idx === 0 && (selector.type === "id" || selector.type === "class" || selector.type === "attribute")) {
421
+ maybeImportantId = true;
422
+ }
423
+ if (selector.type === "universal") {
424
+ _optionalChain([selector, 'access', _31 => _31.parent, 'optionalAccess', _32 => _32.remove, 'call', _33 => _33()]);
425
+ }
426
+ if (selector.type === "pseudo" && selector.value === ":is") {
427
+ if (maybeImportantId && _optionalChain([selector, 'access', _34 => _34.nodes, 'access', _35 => _35[0], 'optionalAccess', _36 => _36.type]) === "selector") {
428
+ selector.replaceWith(selector.nodes[0]);
429
+ } else {
430
+ _optionalChain([selector, 'access', _37 => _37.parent, 'optionalAccess', _38 => _38.remove, 'call', _39 => _39()]);
431
+ }
432
+ }
433
+ });
434
+ });
435
+
436
+ // src/plugins/post.ts
437
+ var postcssWeappTailwindcssPostPlugin = (options = {
438
+ isMainChunk: true
439
+ }) => {
440
+ const { customRuleCallback, isMainChunk } = options;
441
+ const p = {
442
+ postcssPlugin
443
+ };
444
+ if (isMainChunk) {
445
+ p.OnceExit = (root) => {
446
+ root.walkRules((rule) => {
447
+ fallbackRemove.transformSync(rule, {
448
+ updateSelector: true,
449
+ lossless: false
450
+ });
451
+ if (rule.selectors.length === 0 || rule.selectors.length === 1 && rule.selector.trim() === "") {
452
+ rule.remove();
453
+ }
454
+ });
455
+ };
456
+ }
457
+ if (typeof customRuleCallback === "function") {
458
+ p.Rule = (rule) => {
459
+ customRuleCallback(rule, options);
460
+ };
461
+ }
462
+ return p;
463
+ };
464
+ postcssWeappTailwindcssPostPlugin.postcss = true;
465
+
466
+ // src/mp.ts
467
+
468
+
469
+ // src/cssVars.ts
470
+ var cssVars_default = [
471
+ {
472
+ prop: "--tw-border-spacing-x",
473
+ value: "0"
474
+ },
475
+ {
476
+ prop: "--tw-border-spacing-y",
477
+ value: "0"
478
+ },
479
+ {
480
+ prop: "--tw-translate-x",
481
+ value: "0"
482
+ },
483
+ {
484
+ prop: "--tw-translate-y",
485
+ value: "0"
486
+ },
487
+ {
488
+ prop: "--tw-rotate",
489
+ value: "0"
490
+ },
491
+ {
492
+ prop: "--tw-skew-x",
493
+ value: "0"
494
+ },
495
+ {
496
+ prop: "--tw-skew-y",
497
+ value: "0"
498
+ },
499
+ {
500
+ prop: "--tw-scale-x",
501
+ value: "1"
502
+ },
503
+ {
504
+ prop: "--tw-scale-y",
505
+ value: "1"
506
+ },
507
+ {
508
+ prop: "--tw-pan-x",
509
+ value: " "
510
+ },
511
+ {
512
+ prop: "--tw-pan-y",
513
+ value: " "
514
+ },
515
+ {
516
+ prop: "--tw-pinch-zoom",
517
+ value: " "
518
+ },
519
+ {
520
+ prop: "--tw-scroll-snap-strictness",
521
+ value: "proximity"
522
+ },
523
+ {
524
+ prop: "--tw-gradient-from-position",
525
+ value: " "
526
+ },
527
+ {
528
+ prop: "--tw-gradient-via-position",
529
+ value: " "
530
+ },
531
+ {
532
+ prop: "--tw-gradient-to-position",
533
+ value: " "
534
+ },
535
+ {
536
+ prop: "--tw-ordinal",
537
+ value: " "
538
+ },
539
+ {
540
+ prop: "--tw-slashed-zero",
541
+ value: " "
542
+ },
543
+ {
544
+ prop: "--tw-numeric-figure",
545
+ value: " "
546
+ },
547
+ {
548
+ prop: "--tw-numeric-spacing",
549
+ value: " "
550
+ },
551
+ {
552
+ prop: "--tw-numeric-fraction",
553
+ value: " "
554
+ },
555
+ {
556
+ prop: "--tw-ring-inset",
557
+ value: " "
558
+ },
559
+ {
560
+ prop: "--tw-ring-offset-width",
561
+ value: "0px"
562
+ },
563
+ {
564
+ prop: "--tw-ring-offset-color",
565
+ value: "#fff"
566
+ },
567
+ {
568
+ prop: "--tw-ring-color",
569
+ value: "rgb(59 130 246 / 0.5)"
570
+ },
571
+ {
572
+ prop: "--tw-ring-offset-shadow",
573
+ value: "0 0 #0000"
574
+ },
575
+ {
576
+ prop: "--tw-ring-shadow",
577
+ value: "0 0 #0000"
578
+ },
579
+ {
580
+ prop: "--tw-shadow",
581
+ value: "0 0 #0000"
582
+ },
583
+ {
584
+ prop: "--tw-shadow-colored",
585
+ value: "0 0 #0000"
586
+ },
587
+ {
588
+ prop: "--tw-blur",
589
+ value: " "
590
+ },
591
+ {
592
+ prop: "--tw-brightness",
593
+ value: " "
594
+ },
595
+ {
596
+ prop: "--tw-contrast",
597
+ value: " "
598
+ },
599
+ {
600
+ prop: "--tw-grayscale",
601
+ value: " "
602
+ },
603
+ {
604
+ prop: "--tw-hue-rotate",
605
+ value: " "
606
+ },
607
+ {
608
+ prop: "--tw-invert",
609
+ value: " "
610
+ },
611
+ {
612
+ prop: "--tw-saturate",
613
+ value: " "
614
+ },
615
+ {
616
+ prop: "--tw-sepia",
617
+ value: " "
618
+ },
619
+ {
620
+ prop: "--tw-drop-shadow",
621
+ value: " "
622
+ },
623
+ {
624
+ prop: "--tw-backdrop-blur",
625
+ value: " "
626
+ },
627
+ {
628
+ prop: "--tw-backdrop-brightness",
629
+ value: " "
630
+ },
631
+ {
632
+ prop: "--tw-backdrop-contrast",
633
+ value: " "
634
+ },
635
+ {
636
+ prop: "--tw-backdrop-grayscale",
637
+ value: " "
638
+ },
639
+ {
640
+ prop: "--tw-backdrop-hue-rotate",
641
+ value: " "
642
+ },
643
+ {
644
+ prop: "--tw-backdrop-invert",
645
+ value: " "
646
+ },
647
+ {
648
+ prop: "--tw-backdrop-opacity",
649
+ value: " "
650
+ },
651
+ {
652
+ prop: "--tw-backdrop-saturate",
653
+ value: " "
654
+ },
655
+ {
656
+ prop: "--tw-backdrop-sepia",
657
+ value: " "
658
+ },
659
+ {
660
+ prop: "--tw-contain-size",
661
+ value: " "
662
+ },
663
+ {
664
+ prop: "--tw-contain-layout",
665
+ value: " "
666
+ },
667
+ {
668
+ prop: "--tw-contain-paint",
669
+ value: " "
670
+ },
671
+ {
672
+ prop: "--tw-contain-style",
673
+ value: " "
674
+ }
675
+ ];
676
+
677
+ // src/mp.ts
678
+ var initialNodes = cssVars_default.map((x) => {
679
+ return new (0, _postcss.Declaration)({
680
+ prop: x.prop,
681
+ value: x.value
682
+ });
683
+ });
684
+ var PATTERNS = [
685
+ /:not\(template\)\s*[~+]\s*:not\(template\)/.source,
686
+ /:not\(\[hidden\]\)\s*[~+]\s*:not\(\[hidden\]\)/.source
687
+ ].join("|");
688
+ var BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, "g");
689
+ function testIfVariablesScope(node, count = 2) {
690
+ if (isOnlyBeforeAndAfterPseudoElement(node)) {
691
+ const nodes = node.nodes;
692
+ let c = 0;
693
+ for (const tryTestDecl of nodes) {
694
+ if (tryTestDecl && tryTestDecl.type === "decl" && tryTestDecl.prop.startsWith("--tw-")) {
695
+ c++;
696
+ }
697
+ if (c >= count) {
698
+ return true;
699
+ }
700
+ }
701
+ return false;
702
+ }
703
+ return false;
704
+ }
705
+ function testIfTwBackdrop(node, count = 2) {
706
+ if (node.type === "rule" && node.selector === "::backdrop") {
707
+ const nodes = node.nodes;
708
+ let c = 0;
709
+ for (const tryTestDecl of nodes) {
710
+ if (tryTestDecl && tryTestDecl.type === "decl" && tryTestDecl.prop.startsWith("--tw-")) {
711
+ c++;
712
+ }
713
+ if (c >= count) {
714
+ return true;
715
+ }
716
+ }
717
+ return false;
718
+ }
719
+ return false;
720
+ }
721
+ function makePseudoVarRule() {
722
+ const pseudoVarRule = new (0, _postcss.Rule)({
723
+ // selectors: ['::before', '::after'],
724
+ selector: "::before,::after"
725
+ });
726
+ pseudoVarRule.append(
727
+ new (0, _postcss.Declaration)({
728
+ prop: "--tw-content",
729
+ value: '""'
730
+ })
731
+ );
732
+ return pseudoVarRule;
733
+ }
734
+ function remakeCssVarSelector(selectors, options) {
735
+ const { cssPreflightRange, cssSelectorReplacement } = options;
736
+ if (cssPreflightRange === "all" && !selectors.includes(":not(not)")) {
737
+ selectors.push(":not(not)");
738
+ }
739
+ if (cssSelectorReplacement) {
740
+ if (Array.isArray(cssSelectorReplacement.universal)) {
741
+ if (!cssSelectorReplacement.universal.every((x) => {
742
+ return selectors.includes(x);
743
+ }) && !selectors.includes("*")) {
744
+ selectors.unshift("*");
745
+ }
746
+ } else if (typeof cssSelectorReplacement.universal === "string" && !selectors.includes(cssSelectorReplacement.universal) && !selectors.includes("*")) {
747
+ selectors.unshift("*");
748
+ }
749
+ }
750
+ return selectors;
751
+ }
752
+ function remakeCombinatorSelector(selector, cssChildCombinatorReplaceValue) {
753
+ let childCombinatorReplaceValue = "view + view";
754
+ if (Array.isArray(cssChildCombinatorReplaceValue) && cssChildCombinatorReplaceValue.length > 0) {
755
+ const x = composeIsPseudo(cssChildCombinatorReplaceValue);
756
+ childCombinatorReplaceValue = `${x} + ${x}`;
757
+ } else if (typeof cssChildCombinatorReplaceValue === "string") {
758
+ childCombinatorReplaceValue = cssChildCombinatorReplaceValue;
759
+ }
760
+ return selector.replaceAll(BROAD_MATCH_GLOBAL_REGEXP, childCombinatorReplaceValue);
761
+ }
762
+ function commonChunkPreflight(node, options) {
763
+ const { ctx, cssChildCombinatorReplaceValue, cssInjectPreflight, injectAdditionalCssVarScope } = options;
764
+ node.selector = remakeCombinatorSelector(node.selector, cssChildCombinatorReplaceValue);
765
+ if (testIfVariablesScope(node)) {
766
+ _optionalChain([ctx, 'optionalAccess', _40 => _40.markVariablesScope, 'call', _41 => _41(node)]);
767
+ node.selectors = remakeCssVarSelector(node.selectors, options);
768
+ node.before(makePseudoVarRule());
769
+ if (typeof cssInjectPreflight === "function") {
770
+ node.append(...cssInjectPreflight());
771
+ }
772
+ }
773
+ if (injectAdditionalCssVarScope && testIfTwBackdrop(node)) {
774
+ const syntheticRule = new (0, _postcss.Rule)({
775
+ selectors: ["*", "::after", "::before"],
776
+ nodes: initialNodes
777
+ });
778
+ syntheticRule.selectors = remakeCssVarSelector(syntheticRule.selectors, options);
779
+ node.before(syntheticRule);
780
+ node.before(makePseudoVarRule());
781
+ if (typeof cssInjectPreflight === "function") {
782
+ syntheticRule.append(...cssInjectPreflight());
783
+ }
784
+ }
785
+ }
786
+
787
+ // src/plugins/pre.ts
788
+ function isAtMediaHover(atRule) {
789
+ return /media\(\s*hover\s*:\s*hover\s*\)/.test(atRule.name) || atRule.name === "media" && /\(\s*hover\s*:\s*hover\s*\)/.test(atRule.params);
790
+ }
791
+ var postcssWeappTailwindcssPrePlugin = (options = {
792
+ isMainChunk: true
793
+ }) => {
794
+ const { isMainChunk } = options;
795
+ const p = {
796
+ postcssPlugin,
797
+ Rule(rule) {
798
+ ruleTransformSync(rule, options);
799
+ },
800
+ AtRule(atRule) {
801
+ if (isAtMediaHover(atRule)) {
802
+ if (atRule.nodes) {
803
+ atRule.replaceWith(atRule.nodes);
804
+ } else {
805
+ atRule.remove();
806
+ }
807
+ }
808
+ }
809
+ };
810
+ if (isMainChunk) {
811
+ p.Once = (root) => {
812
+ root.walkRules((rule) => {
813
+ commonChunkPreflight(rule, options);
814
+ });
815
+ };
816
+ }
817
+ return p;
818
+ };
819
+ postcssWeappTailwindcssPrePlugin.postcss = true;
820
+
821
+ // src/plugins/index.ts
822
+
823
+ function getPlugins(options) {
824
+ const ctx = createContext();
825
+ options.ctx = ctx;
826
+ const plugins = [
827
+ ..._nullishCoalesce(_optionalChain([options, 'access', _42 => _42.postcssOptions, 'optionalAccess', _43 => _43.plugins]), () => ( [])),
828
+ postcssWeappTailwindcssPrePlugin(options),
829
+ creator({
830
+ specificityMatchingName: "weapp-tw-ig"
831
+ })
832
+ ];
833
+ if (options.rem2rpx) {
834
+ plugins.push(
835
+ _postcssremtoresponsivepixel2.default.call(void 0,
836
+ typeof options.rem2rpx === "object" ? options.rem2rpx : {
837
+ rootValue: 32,
838
+ propList: ["*"],
839
+ transformUnit: "rpx"
840
+ }
841
+ )
842
+ );
843
+ }
844
+ plugins.push(postcssWeappTailwindcssPostPlugin(options));
845
+ return plugins;
846
+ }
847
+
848
+ // src/preflight.ts
849
+ function createInjectPreflight(options) {
850
+ const result = [];
851
+ if (options && typeof options === "object") {
852
+ const entries = Object.entries(options);
853
+ for (const [prop, value] of entries) {
854
+ if (value !== false) {
855
+ result.push({
856
+ prop,
857
+ value: value.toString()
858
+ });
859
+ }
860
+ }
861
+ }
862
+ return () => {
863
+ return result;
864
+ };
865
+ }
866
+
867
+ // src/index.ts
868
+ function styleHandler(rawSource, options) {
869
+ return _postcss2.default.call(void 0, getPlugins(options)).process(
870
+ rawSource,
871
+ _nullishCoalesce(_optionalChain([options, 'access', _44 => _44.postcssOptions, 'optionalAccess', _45 => _45.options]), () => ( {
872
+ from: void 0
873
+ }))
874
+ ).async();
875
+ }
876
+ function createStyleHandler(options) {
877
+ return (rawSource, opt) => {
878
+ return styleHandler(
879
+ rawSource,
880
+ _shared.defuOverrideArray.call(void 0, opt, options)
881
+ );
882
+ };
883
+ }
884
+
885
+
886
+
887
+
888
+
889
+ exports.createInjectPreflight = createInjectPreflight; exports.createStyleHandler = createStyleHandler; exports.internalCssSelectorReplacer = internalCssSelectorReplacer; exports.styleHandler = styleHandler;