tailwindcss-injector 1.0.6 → 1.0.8-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/postcss.js CHANGED
@@ -1,677 +1,22 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __esm = (fn, res) => function __init() {
8
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
- };
10
- var __commonJS = (cb, mod) => function __require() {
11
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
-
30
- // ../../node_modules/.pnpm/tsup@8.5.0_@swc+core@1.13.5_jiti@2.5.1_postcss@8.5.6_tsx@4.20.5_typescript@5.9.2_yaml@2.8.1/node_modules/tsup/assets/esm_shims.js
31
- import path from "path";
32
- import { fileURLToPath } from "url";
33
- var init_esm_shims = __esm({
34
- "../../node_modules/.pnpm/tsup@8.5.0_@swc+core@1.13.5_jiti@2.5.1_postcss@8.5.6_tsx@4.20.5_typescript@5.9.2_yaml@2.8.1/node_modules/tsup/assets/esm_shims.js"() {
35
- "use strict";
36
- }
37
- });
38
-
39
- // ../../node_modules/.pnpm/is-primitive@3.0.1/node_modules/is-primitive/index.js
40
- var require_is_primitive = __commonJS({
41
- "../../node_modules/.pnpm/is-primitive@3.0.1/node_modules/is-primitive/index.js"(exports, module) {
42
- "use strict";
43
- init_esm_shims();
44
- module.exports = function isPrimitive(val) {
45
- if (typeof val === "object") {
46
- return val === null;
47
- }
48
- return typeof val !== "function";
49
- };
50
- }
51
- });
52
-
53
- // ../../node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js
54
- var require_isobject = __commonJS({
55
- "../../node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js"(exports, module) {
56
- "use strict";
57
- init_esm_shims();
58
- module.exports = function isObject(val) {
59
- return val != null && typeof val === "object" && Array.isArray(val) === false;
60
- };
61
- }
62
- });
63
-
64
- // ../../node_modules/.pnpm/is-plain-object@2.0.4/node_modules/is-plain-object/index.js
65
- var require_is_plain_object = __commonJS({
66
- "../../node_modules/.pnpm/is-plain-object@2.0.4/node_modules/is-plain-object/index.js"(exports, module) {
67
- "use strict";
68
- init_esm_shims();
69
- var isObject = require_isobject();
70
- function isObjectObject(o) {
71
- return isObject(o) === true && Object.prototype.toString.call(o) === "[object Object]";
72
- }
73
- module.exports = function isPlainObject(o) {
74
- var ctor, prot;
75
- if (isObjectObject(o) === false) return false;
76
- ctor = o.constructor;
77
- if (typeof ctor !== "function") return false;
78
- prot = ctor.prototype;
79
- if (isObjectObject(prot) === false) return false;
80
- if (prot.hasOwnProperty("isPrototypeOf") === false) {
81
- return false;
82
- }
83
- return true;
84
- };
85
- }
86
- });
87
-
88
- // ../../node_modules/.pnpm/set-value@4.1.0/node_modules/set-value/index.js
89
- var require_set_value = __commonJS({
90
- "../../node_modules/.pnpm/set-value@4.1.0/node_modules/set-value/index.js"(exports, module) {
91
- "use strict";
92
- init_esm_shims();
93
- var { deleteProperty } = Reflect;
94
- var isPrimitive = require_is_primitive();
95
- var isPlainObject = require_is_plain_object();
96
- var isObject = (value) => {
97
- return typeof value === "object" && value !== null || typeof value === "function";
98
- };
99
- var isUnsafeKey = (key) => {
100
- return key === "__proto__" || key === "constructor" || key === "prototype";
101
- };
102
- var validateKey = (key) => {
103
- if (!isPrimitive(key)) {
104
- throw new TypeError("Object keys must be strings or symbols");
105
- }
106
- if (isUnsafeKey(key)) {
107
- throw new Error(`Cannot set unsafe key: "${key}"`);
108
- }
109
- };
110
- var toStringKey = (input) => {
111
- return Array.isArray(input) ? input.flat().map(String).join(",") : input;
112
- };
113
- var createMemoKey = (input, options) => {
114
- if (typeof input !== "string" || !options) return input;
115
- let key = input + ";";
116
- if (options.arrays !== void 0) key += `arrays=${options.arrays};`;
117
- if (options.separator !== void 0) key += `separator=${options.separator};`;
118
- if (options.split !== void 0) key += `split=${options.split};`;
119
- if (options.merge !== void 0) key += `merge=${options.merge};`;
120
- if (options.preservePaths !== void 0) key += `preservePaths=${options.preservePaths};`;
121
- return key;
122
- };
123
- var memoize = (input, options, fn) => {
124
- const key = toStringKey(options ? createMemoKey(input, options) : input);
125
- validateKey(key);
126
- const value = setValue.cache.get(key) || fn();
127
- setValue.cache.set(key, value);
128
- return value;
129
- };
130
- var splitString = (input, options = {}) => {
131
- const sep2 = options.separator || ".";
132
- const preserve = sep2 === "/" ? false : options.preservePaths;
133
- if (typeof input === "string" && preserve !== false && /\//.test(input)) {
134
- return [input];
135
- }
136
- const parts = [];
137
- let part = "";
138
- const push = (part2) => {
139
- let number;
140
- if (part2.trim() !== "" && Number.isInteger(number = Number(part2))) {
141
- parts.push(number);
142
- } else {
143
- parts.push(part2);
144
- }
145
- };
146
- for (let i = 0; i < input.length; i++) {
147
- const value = input[i];
148
- if (value === "\\") {
149
- part += input[++i];
150
- continue;
151
- }
152
- if (value === sep2) {
153
- push(part);
154
- part = "";
155
- continue;
156
- }
157
- part += value;
158
- }
159
- if (part) {
160
- push(part);
161
- }
162
- return parts;
163
- };
164
- var split = (input, options) => {
165
- if (options && typeof options.split === "function") return options.split(input);
166
- if (typeof input === "symbol") return [input];
167
- if (Array.isArray(input)) return input;
168
- return memoize(input, options, () => splitString(input, options));
169
- };
170
- var assignProp = (obj, prop, value, options) => {
171
- validateKey(prop);
172
- if (value === void 0) {
173
- deleteProperty(obj, prop);
174
- } else if (options && options.merge) {
175
- const merge = options.merge === "function" ? options.merge : Object.assign;
176
- if (merge && isPlainObject(obj[prop]) && isPlainObject(value)) {
177
- obj[prop] = merge(obj[prop], value);
178
- } else {
179
- obj[prop] = value;
180
- }
181
- } else {
182
- obj[prop] = value;
183
- }
184
- return obj;
185
- };
186
- var setValue = (target, path3, value, options) => {
187
- if (!path3 || !isObject(target)) return target;
188
- const keys = split(path3, options);
189
- let obj = target;
190
- for (let i = 0; i < keys.length; i++) {
191
- const key = keys[i];
192
- const next = keys[i + 1];
193
- validateKey(key);
194
- if (next === void 0) {
195
- assignProp(obj, key, value, options);
196
- break;
197
- }
198
- if (typeof next === "number" && !Array.isArray(obj[key])) {
199
- obj = obj[key] = [];
200
- continue;
201
- }
202
- if (!isObject(obj[key])) {
203
- obj[key] = {};
204
- }
205
- obj = obj[key];
206
- }
207
- return target;
208
- };
209
- setValue.split = split;
210
- setValue.cache = /* @__PURE__ */ new Map();
211
- setValue.clear = () => {
212
- setValue.cache = /* @__PURE__ */ new Map();
213
- };
214
- module.exports = setValue;
215
- }
216
- });
217
-
218
1
  // src/postcss.ts
219
- init_esm_shims();
220
- var import_set_value = __toESM(require_set_value(), 1);
221
2
  import postcss from "postcss";
222
3
  import tailwindcss from "tailwindcss";
223
4
  import { loadConfig } from "tailwindcss-config";
224
5
 
225
6
  // src/config.ts
226
- init_esm_shims();
227
- import process2 from "process";
228
-
229
- // src/utils.ts
230
- init_esm_shims();
231
- import crypto from "crypto";
232
- import { defu, defuOverrideArray, isRegexp, regExpTest } from "@weapp-tailwindcss/shared";
233
-
234
- // ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/index.mjs
235
- init_esm_shims();
236
-
237
- // ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
238
- init_esm_shims();
239
- var _lazyMatch = () => {
240
- var __lib__ = (() => {
241
- var m = Object.defineProperty, V = Object.getOwnPropertyDescriptor, G = Object.getOwnPropertyNames, T = Object.prototype.hasOwnProperty, q = (r, e) => {
242
- for (var n in e) m(r, n, { get: e[n], enumerable: true });
243
- }, H = (r, e, n, a) => {
244
- if (e && typeof e == "object" || typeof e == "function") for (let t of G(e)) !T.call(r, t) && t !== n && m(r, t, { get: () => e[t], enumerable: !(a = V(e, t)) || a.enumerable });
245
- return r;
246
- }, J = (r) => H(m({}, "__esModule", { value: true }), r), w = {};
247
- q(w, { default: () => re });
248
- var A = (r) => Array.isArray(r), d = (r) => typeof r == "function", Q = (r) => r.length === 0, W = (r) => typeof r == "number", K = (r) => typeof r == "object" && r !== null, X = (r) => r instanceof RegExp, b = (r) => typeof r == "string", h = (r) => r === void 0, Y = (r) => {
249
- const e = /* @__PURE__ */ new Map();
250
- return (n) => {
251
- const a = e.get(n);
252
- if (a) return a;
253
- const t = r(n);
254
- return e.set(n, t), t;
255
- };
256
- }, rr = (r, e, n = {}) => {
257
- const a = { cache: {}, input: r, index: 0, indexMax: 0, options: n, output: [] };
258
- if (v(e)(a) && a.index === r.length) return a.output;
259
- throw new Error(`Failed to parse at index ${a.indexMax}`);
260
- }, i = (r, e) => A(r) ? er(r, e) : b(r) ? ar(r, e) : nr(r, e), er = (r, e) => {
261
- const n = {};
262
- for (const a of r) {
263
- if (a.length !== 1) throw new Error(`Invalid character: "${a}"`);
264
- const t = a.charCodeAt(0);
265
- n[t] = true;
266
- }
267
- return (a) => {
268
- const t = a.index, o = a.input;
269
- for (; a.index < o.length && o.charCodeAt(a.index) in n; ) a.index += 1;
270
- const u = a.index;
271
- if (u > t) {
272
- if (!h(e) && !a.options.silent) {
273
- const s = a.input.slice(t, u), c = d(e) ? e(s, o, String(t)) : e;
274
- h(c) || a.output.push(c);
275
- }
276
- a.indexMax = Math.max(a.indexMax, a.index);
277
- }
278
- return true;
279
- };
280
- }, nr = (r, e) => {
281
- const n = r.source, a = r.flags.replace(/y|$/, "y"), t = new RegExp(n, a);
282
- return g((o) => {
283
- t.lastIndex = o.index;
284
- const u = t.exec(o.input);
285
- if (u) {
286
- if (!h(e) && !o.options.silent) {
287
- const s = d(e) ? e(...u, o.input, String(o.index)) : e;
288
- h(s) || o.output.push(s);
289
- }
290
- return o.index += u[0].length, o.indexMax = Math.max(o.indexMax, o.index), true;
291
- } else return false;
292
- });
293
- }, ar = (r, e) => (n) => {
294
- if (n.input.startsWith(r, n.index)) {
295
- if (!h(e) && !n.options.silent) {
296
- const t = d(e) ? e(r, n.input, String(n.index)) : e;
297
- h(t) || n.output.push(t);
298
- }
299
- return n.index += r.length, n.indexMax = Math.max(n.indexMax, n.index), true;
300
- } else return false;
301
- }, C = (r, e, n, a) => {
302
- const t = v(r);
303
- return g(_(M((o) => {
304
- let u = 0;
305
- for (; u < n; ) {
306
- const s = o.index;
307
- if (!t(o) || (u += 1, o.index === s)) break;
308
- }
309
- return u >= e;
310
- })));
311
- }, tr = (r, e) => C(r, 0, 1), f = (r, e) => C(r, 0, 1 / 0), x = (r, e) => {
312
- const n = r.map(v);
313
- return g(_(M((a) => {
314
- for (let t = 0, o = n.length; t < o; t++) if (!n[t](a)) return false;
315
- return true;
316
- })));
317
- }, l = (r, e) => {
318
- const n = r.map(v);
319
- return g(_((a) => {
320
- for (let t = 0, o = n.length; t < o; t++) if (n[t](a)) return true;
321
- return false;
322
- }));
323
- }, M = (r, e = false) => {
324
- const n = v(r);
325
- return (a) => {
326
- const t = a.index, o = a.output.length, u = n(a);
327
- return (!u || e) && (a.index = t, a.output.length !== o && (a.output.length = o)), u;
328
- };
329
- }, _ = (r, e) => {
330
- const n = v(r);
331
- return n;
332
- }, g = /* @__PURE__ */ (() => {
333
- let r = 0;
334
- return (e) => {
335
- const n = v(e), a = r += 1;
336
- return (t) => {
337
- var o;
338
- if (t.options.memoization === false) return n(t);
339
- const u = t.index, s = (o = t.cache)[a] || (o[a] = /* @__PURE__ */ new Map()), c = s.get(u);
340
- if (c === false) return false;
341
- if (W(c)) return t.index = c, true;
342
- if (c) return t.index = c.index, c.output?.length && t.output.push(...c.output), true;
343
- {
344
- const Z = t.output.length;
345
- if (n(t)) {
346
- const D = t.index, U = t.output.length;
347
- if (U > Z) {
348
- const ee = t.output.slice(Z, U);
349
- s.set(u, { index: D, output: ee });
350
- } else s.set(u, D);
351
- return true;
352
- } else return s.set(u, false), false;
353
- }
354
- };
355
- };
356
- })(), E = (r) => {
357
- let e;
358
- return (n) => (e || (e = v(r())), e(n));
359
- }, v = Y((r) => {
360
- if (d(r)) return Q(r) ? E(r) : r;
361
- if (b(r) || X(r)) return i(r);
362
- if (A(r)) return x(r);
363
- if (K(r)) return l(Object.values(r));
364
- throw new Error("Invalid rule");
365
- }), P = "abcdefghijklmnopqrstuvwxyz", ir = (r) => {
366
- let e = "";
367
- for (; r > 0; ) {
368
- const n = (r - 1) % 26;
369
- e = P[n] + e, r = Math.floor((r - 1) / 26);
370
- }
371
- return e;
372
- }, O = (r) => {
373
- let e = 0;
374
- for (let n = 0, a = r.length; n < a; n++) e = e * 26 + P.indexOf(r[n]) + 1;
375
- return e;
376
- }, S = (r, e) => {
377
- if (e < r) return S(e, r);
378
- const n = [];
379
- for (; r <= e; ) n.push(r++);
380
- return n;
381
- }, or = (r, e, n) => S(r, e).map((a) => String(a).padStart(n, "0")), R = (r, e) => S(O(r), O(e)).map(ir), p = (r) => r, z = (r) => ur((e) => rr(e, r, { memoization: false }).join("")), ur = (r) => {
382
- const e = {};
383
- return (n) => e[n] ?? (e[n] = r(n));
384
- }, sr = i(/^\*\*\/\*$/, ".*"), cr = i(/^\*\*\/(\*)?([ a-zA-Z0-9._-]+)$/, (r, e, n) => `.*${e ? "" : "(?:^|/)"}${n.replaceAll(".", "\\.")}`), lr = i(/^\*\*\/(\*)?([ a-zA-Z0-9._-]*)\{([ a-zA-Z0-9._-]+(?:,[ a-zA-Z0-9._-]+)*)\}$/, (r, e, n, a) => `.*${e ? "" : "(?:^|/)"}${n.replaceAll(".", "\\.")}(?:${a.replaceAll(",", "|").replaceAll(".", "\\.")})`), y = i(/\\./, p), pr = i(/[$.*+?^(){}[\]\|]/, (r) => `\\${r}`), vr = i(/./, p), hr = i(/^(?:!!)*!(.*)$/, (r, e) => `(?!^${L(e)}$).*?`), dr = i(/^(!!)+/, ""), fr = l([hr, dr]), xr = i(/\/(\*\*\/)+/, "(?:/.+/|/)"), gr = i(/^(\*\*\/)+/, "(?:^|.*/)"), mr = i(/\/(\*\*)$/, "(?:/.*|$)"), _r = i(/\*\*/, ".*"), j = l([xr, gr, mr, _r]), Sr = i(/\*\/(?!\*\*\/)/, "[^/]*/"), yr = i(/\*/, "[^/]*"), N = l([Sr, yr]), k = i("?", "[^/]"), $r = i("[", p), wr = i("]", p), Ar = i(/[!^]/, "^/"), br = i(/[a-z]-[a-z]|[0-9]-[0-9]/i, p), Cr = i(/[$.*+?^(){}[\|]/, (r) => `\\${r}`), Mr = i(/[^\]]/, p), Er = l([y, Cr, br, Mr]), B = x([$r, tr(Ar), f(Er), wr]), Pr = i("{", "(?:"), Or = i("}", ")"), Rr = i(/(\d+)\.\.(\d+)/, (r, e, n) => or(+e, +n, Math.min(e.length, n.length)).join("|")), zr = i(/([a-z]+)\.\.([a-z]+)/, (r, e, n) => R(e, n).join("|")), jr = i(/([A-Z]+)\.\.([A-Z]+)/, (r, e, n) => R(e.toLowerCase(), n.toLowerCase()).join("|").toUpperCase()), Nr = l([Rr, zr, jr]), I = x([Pr, Nr, Or]), kr = i("{", "(?:"), Br = i("}", ")"), Ir = i(",", "|"), Fr = i(/[$.*+?^(){[\]\|]/, (r) => `\\${r}`), Lr = i(/[^}]/, p), Zr = E(() => F), Dr = l([j, N, k, B, I, Zr, y, Fr, Ir, Lr]), F = x([kr, f(Dr), Br]), Ur = f(l([sr, cr, lr, fr, j, N, k, B, I, F, y, pr, vr])), Vr = Ur, Gr = z(Vr), L = Gr, Tr = i(/\\./, p), qr = i(/./, p), Hr = i(/\*\*\*+/, "*"), Jr = i(/([^/{[(!])\*\*/, (r, e) => `${e}*`), Qr = i(/(^|.)\*\*(?=[^*/)\]}])/, (r, e) => `${e}*`), Wr = f(l([Tr, Hr, Jr, Qr, qr])), Kr = Wr, Xr = z(Kr), Yr = Xr, $ = (r, e) => {
385
- const n = Array.isArray(r) ? r : [r];
386
- if (!n.length) return false;
387
- const a = n.map($.compile), t = n.every((s) => /(\/(?:\*\*)?|\[\/\])$/.test(s)), o = e.replace(/[\\\/]+/g, "/").replace(/\/$/, t ? "/" : "");
388
- return a.some((s) => s.test(o));
389
- };
390
- $.compile = (r) => new RegExp(`^${L(Yr(r))}$`, "s");
391
- var re = $;
392
- return J(w);
393
- })();
394
- return __lib__.default || __lib__;
395
- };
396
- var _match;
397
- var zeptomatch = (path3, pattern) => {
398
- if (!_match) {
399
- _match = _lazyMatch();
400
- _lazyMatch = null;
401
- }
402
- return _match(path3, pattern);
403
- };
404
- var _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
405
- function normalizeWindowsPath(input = "") {
406
- if (!input) {
407
- return input;
408
- }
409
- return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
410
- }
411
- var _UNC_REGEX = /^[/\\]{2}/;
412
- var _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
413
- var _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
414
- var _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
415
- var _EXTNAME_RE = /.(\.[^./]+|\.)$/;
416
- var _PATH_ROOT_RE = /^[/\\]|^[a-zA-Z]:[/\\]/;
417
- var sep = "/";
418
- var normalize = function(path3) {
419
- if (path3.length === 0) {
420
- return ".";
421
- }
422
- path3 = normalizeWindowsPath(path3);
423
- const isUNCPath = path3.match(_UNC_REGEX);
424
- const isPathAbsolute = isAbsolute(path3);
425
- const trailingSeparator = path3[path3.length - 1] === "/";
426
- path3 = normalizeString(path3, !isPathAbsolute);
427
- if (path3.length === 0) {
428
- if (isPathAbsolute) {
429
- return "/";
430
- }
431
- return trailingSeparator ? "./" : ".";
432
- }
433
- if (trailingSeparator) {
434
- path3 += "/";
435
- }
436
- if (_DRIVE_LETTER_RE.test(path3)) {
437
- path3 += "/";
438
- }
439
- if (isUNCPath) {
440
- if (!isPathAbsolute) {
441
- return `//./${path3}`;
442
- }
443
- return `//${path3}`;
444
- }
445
- return isPathAbsolute && !isAbsolute(path3) ? `/${path3}` : path3;
446
- };
447
- var join = function(...segments) {
448
- let path3 = "";
449
- for (const seg of segments) {
450
- if (!seg) {
451
- continue;
452
- }
453
- if (path3.length > 0) {
454
- const pathTrailing = path3[path3.length - 1] === "/";
455
- const segLeading = seg[0] === "/";
456
- const both = pathTrailing && segLeading;
457
- if (both) {
458
- path3 += seg.slice(1);
459
- } else {
460
- path3 += pathTrailing || segLeading ? seg : `/${seg}`;
461
- }
462
- } else {
463
- path3 += seg;
464
- }
465
- }
466
- return normalize(path3);
467
- };
468
- function cwd() {
469
- if (typeof process !== "undefined" && typeof process.cwd === "function") {
470
- return process.cwd().replace(/\\/g, "/");
471
- }
472
- return "/";
473
- }
474
- var resolve = function(...arguments_) {
475
- arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
476
- let resolvedPath = "";
477
- let resolvedAbsolute = false;
478
- for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
479
- const path3 = index >= 0 ? arguments_[index] : cwd();
480
- if (!path3 || path3.length === 0) {
481
- continue;
482
- }
483
- resolvedPath = `${path3}/${resolvedPath}`;
484
- resolvedAbsolute = isAbsolute(path3);
485
- }
486
- resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
487
- if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
488
- return `/${resolvedPath}`;
489
- }
490
- return resolvedPath.length > 0 ? resolvedPath : ".";
491
- };
492
- function normalizeString(path3, allowAboveRoot) {
493
- let res = "";
494
- let lastSegmentLength = 0;
495
- let lastSlash = -1;
496
- let dots = 0;
497
- let char = null;
498
- for (let index = 0; index <= path3.length; ++index) {
499
- if (index < path3.length) {
500
- char = path3[index];
501
- } else if (char === "/") {
502
- break;
503
- } else {
504
- char = "/";
505
- }
506
- if (char === "/") {
507
- if (lastSlash === index - 1 || dots === 1) ;
508
- else if (dots === 2) {
509
- if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
510
- if (res.length > 2) {
511
- const lastSlashIndex = res.lastIndexOf("/");
512
- if (lastSlashIndex === -1) {
513
- res = "";
514
- lastSegmentLength = 0;
515
- } else {
516
- res = res.slice(0, lastSlashIndex);
517
- lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
518
- }
519
- lastSlash = index;
520
- dots = 0;
521
- continue;
522
- } else if (res.length > 0) {
523
- res = "";
524
- lastSegmentLength = 0;
525
- lastSlash = index;
526
- dots = 0;
527
- continue;
528
- }
529
- }
530
- if (allowAboveRoot) {
531
- res += res.length > 0 ? "/.." : "..";
532
- lastSegmentLength = 2;
533
- }
534
- } else {
535
- if (res.length > 0) {
536
- res += `/${path3.slice(lastSlash + 1, index)}`;
537
- } else {
538
- res = path3.slice(lastSlash + 1, index);
539
- }
540
- lastSegmentLength = index - lastSlash - 1;
541
- }
542
- lastSlash = index;
543
- dots = 0;
544
- } else if (char === "." && dots !== -1) {
545
- ++dots;
546
- } else {
547
- dots = -1;
548
- }
549
- }
550
- return res;
551
- }
552
- var isAbsolute = function(p) {
553
- return _IS_ABSOLUTE_RE.test(p);
554
- };
555
- var toNamespacedPath = function(p) {
556
- return normalizeWindowsPath(p);
557
- };
558
- var extname = function(p) {
559
- if (p === "..") return "";
560
- const match = _EXTNAME_RE.exec(normalizeWindowsPath(p));
561
- return match && match[1] || "";
562
- };
563
- var relative = function(from, to) {
564
- const _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
565
- const _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
566
- if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) {
567
- return _to.join("/");
568
- }
569
- const _fromCopy = [..._from];
570
- for (const segment of _fromCopy) {
571
- if (_to[0] !== segment) {
572
- break;
573
- }
574
- _from.shift();
575
- _to.shift();
576
- }
577
- return [..._from.map(() => ".."), ..._to].join("/");
578
- };
579
- var dirname = function(p) {
580
- const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
581
- if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) {
582
- segments[0] += "/";
583
- }
584
- return segments.join("/") || (isAbsolute(p) ? "/" : ".");
585
- };
586
- var format = function(p) {
587
- const ext = p.ext ? p.ext.startsWith(".") ? p.ext : `.${p.ext}` : "";
588
- const segments = [p.root, p.dir, p.base ?? (p.name ?? "") + ext].filter(
589
- Boolean
590
- );
591
- return normalizeWindowsPath(
592
- p.root ? resolve(...segments) : segments.join("/")
593
- );
594
- };
595
- var basename = function(p, extension) {
596
- const segments = normalizeWindowsPath(p).split("/");
597
- let lastSegment = "";
598
- for (let i = segments.length - 1; i >= 0; i--) {
599
- const val = segments[i];
600
- if (val) {
601
- lastSegment = val;
602
- break;
603
- }
604
- }
605
- return extension && lastSegment.endsWith(extension) ? lastSegment.slice(0, -extension.length) : lastSegment;
606
- };
607
- var parse = function(p) {
608
- const root = _PATH_ROOT_RE.exec(p)?.[0]?.replace(/\\/g, "/") || "";
609
- const base = basename(p);
610
- const extension = extname(base);
611
- return {
612
- root,
613
- dir: dirname(p),
614
- base,
615
- ext: extension,
616
- name: base.slice(0, base.length - extension.length)
617
- };
618
- };
619
- var matchesGlob = (path3, pattern) => {
620
- return zeptomatch(pattern, normalize(path3));
621
- };
622
- var _path = {
623
- __proto__: null,
624
- basename,
625
- dirname,
626
- extname,
627
- format,
628
- isAbsolute,
629
- join,
630
- matchesGlob,
631
- normalize,
632
- normalizeString,
633
- parse,
634
- relative,
635
- resolve,
636
- sep,
637
- toNamespacedPath
638
- };
639
-
640
- // ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/index.mjs
641
- var delimiter = /* @__PURE__ */ (() => globalThis.process?.platform === "win32" ? ";" : ":")();
642
- var _platforms = { posix: void 0, win32: void 0 };
643
- var mix = (del = delimiter) => {
644
- return new Proxy(_path, {
645
- get(_, prop) {
646
- if (prop === "delimiter") return del;
647
- if (prop === "posix") return posix;
648
- if (prop === "win32") return win32;
649
- return _platforms[prop] || _path[prop];
650
- }
651
- });
652
- };
653
- var posix = /* @__PURE__ */ mix(":");
654
- var win32 = /* @__PURE__ */ mix(";");
7
+ import process from "process";
655
8
 
656
9
  // src/utils.ts
657
- function removeFileExtension(filePath) {
658
- if (!filePath) {
659
- return "";
660
- }
661
- let baseName = posix.basename(filePath);
662
- let ext = posix.extname(baseName);
663
- while (ext) {
664
- baseName = baseName.slice(0, -ext.length);
665
- ext = posix.extname(baseName);
666
- }
667
- const dir = posix.dirname(filePath);
668
- return posix.join(dir, baseName);
669
- }
670
- function md5(input) {
671
- const hash = crypto.createHash("md5");
672
- hash.update(input);
673
- return hash.digest("hex");
674
- }
10
+ import {
11
+ defu,
12
+ defuOverrideArray,
13
+ isRegexp,
14
+ regExpTest
15
+ } from "@weapp-tailwindcss/shared";
16
+ import {
17
+ md5,
18
+ removeAllExtensions
19
+ } from "@weapp-tailwindcss/shared/node";
675
20
 
676
21
  // src/config.ts
677
22
  function getDefaultConfig() {
@@ -680,7 +25,7 @@ function getDefaultConfig() {
680
25
  config: void 0,
681
26
  // 倒叙插入
682
27
  directiveParams: ["utilities", "components"],
683
- cwd: process2.cwd(),
28
+ cwd: process.cwd(),
684
29
  extensions: ["wxml", "js", "ts"],
685
30
  // @import and @use (scss)
686
31
  insertAfterAtRulesNames: ["import", "use"],
@@ -692,12 +37,10 @@ function getConfig(options) {
692
37
  }
693
38
 
694
39
  // src/constants.ts
695
- init_esm_shims();
696
40
  var postcssPlugin = "postcss-tailwindcss-injector";
697
41
 
698
42
  // src/wxml.ts
699
- init_esm_shims();
700
- import path2 from "path";
43
+ import path from "path";
701
44
  import fs from "fs-extra";
702
45
  import { Parser } from "htmlparser2";
703
46
  import MagicString from "magic-string";
@@ -760,10 +103,10 @@ function processWxml(wxml) {
760
103
  parser.end();
761
104
  return deps;
762
105
  }
763
- async function getDep(filepath, set2) {
106
+ async function getDep(filepath, set) {
764
107
  if (await fs.exists(filepath)) {
765
- const dirname2 = path2.dirname(filepath);
766
- set2.add(filepath);
108
+ const dirname = path.dirname(filepath);
109
+ set.add(filepath);
767
110
  const wxml = await fs.readFile(filepath, "utf8");
768
111
  const hash = md5(wxml);
769
112
  const oldHash = hashMap.get(filepath);
@@ -778,22 +121,54 @@ async function getDep(filepath, set2) {
778
121
  deps = cacheDeps;
779
122
  }
780
123
  for (const { value } of deps) {
781
- const p = path2.resolve(dirname2, value);
782
- if (!set2.has(p)) {
783
- await getDep(p, set2);
124
+ const p = path.resolve(dirname, value);
125
+ if (!set.has(p)) {
126
+ await getDep(p, set);
784
127
  }
785
128
  }
786
129
  }
787
130
  }
788
131
  async function getDepFiles(file) {
789
- const set2 = /* @__PURE__ */ new Set();
790
- await getDep(file, set2);
791
- return set2;
132
+ const set = /* @__PURE__ */ new Set();
133
+ await getDep(file, set);
134
+ return set;
792
135
  }
793
136
 
794
137
  // src/postcss.ts
138
+ var configCache = /* @__PURE__ */ new Map();
139
+ async function loadTailwindConfigOnce(cwd, configPath) {
140
+ const cacheKey = `${cwd}::${configPath}`;
141
+ let cached = configCache.get(cacheKey);
142
+ if (!cached) {
143
+ cached = loadConfig({
144
+ cwd,
145
+ config: configPath
146
+ }).then((result) => result?.config);
147
+ configCache.set(cacheKey, cached);
148
+ }
149
+ return cached;
150
+ }
151
+ function cloneConfig(config) {
152
+ if (!config) {
153
+ return config;
154
+ }
155
+ return {
156
+ ...config
157
+ };
158
+ }
159
+ async function resolveTailwindConfig(config, cwd, sourceInput) {
160
+ if (!config) {
161
+ return void 0;
162
+ }
163
+ const resolved = typeof config === "function" ? config(sourceInput) : config;
164
+ if (typeof resolved === "string") {
165
+ const loaded = await loadTailwindConfigOnce(cwd, resolved);
166
+ return cloneConfig(loaded);
167
+ }
168
+ return cloneConfig(resolved);
169
+ }
795
170
  var creator = (options) => {
796
- const { config, filter, directiveParams, cwd: cwd2, extensions, insertAfterAtRulesNames, insertAfterComments } = getConfig(options);
171
+ const { config, filter, directiveParams, cwd, extensions, insertAfterAtRulesNames, insertAfterComments } = getConfig(options);
797
172
  const extensionsGlob = `{${extensions.join(",")}}`;
798
173
  return {
799
174
  postcssPlugin,
@@ -801,51 +176,65 @@ var creator = (options) => {
801
176
  {
802
177
  postcssPlugin: `${postcssPlugin}:post`,
803
178
  async Once(root, helpers) {
804
- if (filter(root.source?.input)) {
805
- const atruleLastIndex = root.nodes.findLastIndex((x) => x.type === "atrule" && insertAfterAtRulesNames.includes(x.name));
806
- const commentLastIndex = root.nodes.findLastIndex((x) => x.type === "comment" && regExpTest(insertAfterComments, x.text));
807
- const lastIndex = Math.max(atruleLastIndex, commentLastIndex);
179
+ const sourceInput = root.source?.input;
180
+ if (filter(sourceInput)) {
181
+ const nodes = root.nodes ?? [];
182
+ let atruleAnchorIndex = -1;
183
+ let commentAnchorIndex = -1;
184
+ const directivePresence = /* @__PURE__ */ new Set();
185
+ nodes.forEach((node, index) => {
186
+ if (node.type === "atrule") {
187
+ const nameMatches = insertAfterAtRulesNames.includes(node.name);
188
+ if (nameMatches) {
189
+ atruleAnchorIndex = Math.max(atruleAnchorIndex, index);
190
+ }
191
+ if (typeof node.params === "string") {
192
+ directivePresence.add(node.params);
193
+ }
194
+ } else if (node.type === "comment" && regExpTest(insertAfterComments, node.text)) {
195
+ commentAnchorIndex = Math.max(commentAnchorIndex, index);
196
+ }
197
+ });
198
+ const anchorIndex = Math.max(atruleAnchorIndex, commentAnchorIndex);
199
+ const anchorNode = anchorIndex >= 0 ? nodes[anchorIndex] : void 0;
200
+ let lastInserted = anchorNode;
808
201
  for (const params of directiveParams) {
809
- const node = root.nodes.find((x) => x.type === "atrule" && x.params === params);
810
- if (!node) {
202
+ if (!directivePresence.has(params)) {
811
203
  const atRule = helpers.atRule({ name: "tailwind", params });
812
- if (lastIndex < 0) {
813
- root.prepend(atRule);
204
+ if (lastInserted) {
205
+ root.insertAfter(lastInserted, atRule);
814
206
  } else {
815
- root.insertAfter(lastIndex, atRule);
207
+ root.prepend(atRule);
816
208
  }
209
+ lastInserted = atRule;
210
+ directivePresence.add(params);
817
211
  }
818
212
  }
819
- const cfg = typeof config === "function" ? config(root.source?.input) : config;
820
- let tailwindcssConfig;
821
- if (typeof cfg === "string") {
822
- const result = await loadConfig({
823
- cwd: cwd2,
824
- config: cfg
825
- });
826
- if (result) {
827
- tailwindcssConfig = result.config;
828
- }
829
- } else {
830
- tailwindcssConfig = cfg ?? {
831
- content: []
832
- };
833
- }
834
- if (tailwindcssConfig && root.source?.input && root.source.input.file) {
835
- const basename2 = removeFileExtension(root.source.input.file);
836
- (0, import_set_value.default)(tailwindcssConfig, "content", [
837
- `${basename2}.${extensionsGlob}`
838
- ]);
839
- const deps = await getDepFiles(`${basename2}.wxml`);
213
+ if (sourceInput?.file) {
214
+ const tailwindcssConfig = await resolveTailwindConfig(config, cwd, sourceInput) ?? { content: [] };
215
+ const basename = removeAllExtensions(sourceInput.file);
216
+ const contentEntries = [`${basename}.${extensionsGlob}`];
217
+ const deps = await getDepFiles(`${basename}.wxml`);
840
218
  for (const dep of deps) {
841
- if (Array.isArray(tailwindcssConfig.content)) {
842
- tailwindcssConfig.content.push(`${removeFileExtension(dep)}.${extensionsGlob}`);
843
- }
219
+ contentEntries.push(`${removeAllExtensions(dep)}.${extensionsGlob}`);
220
+ }
221
+ const uniqueEntries = Array.from(new Set(contentEntries));
222
+ const { content: existingContent } = tailwindcssConfig;
223
+ if (!existingContent || Array.isArray(existingContent)) {
224
+ tailwindcssConfig.content = uniqueEntries;
225
+ } else if (typeof existingContent === "object" && existingContent !== null) {
226
+ const normalizedContent = { ...existingContent };
227
+ const currentFiles = normalizedContent.files;
228
+ const normalizedFiles = Array.isArray(currentFiles) ? currentFiles : typeof currentFiles === "string" ? [currentFiles] : [];
229
+ normalizedContent.files = Array.from(/* @__PURE__ */ new Set([...normalizedFiles, ...uniqueEntries]));
230
+ tailwindcssConfig.content = normalizedContent;
231
+ } else {
232
+ tailwindcssConfig.content = uniqueEntries;
844
233
  }
845
234
  await postcss([
846
235
  tailwindcss(tailwindcssConfig)
847
236
  ]).process(root, {
848
- from: root.source.input.file
237
+ from: sourceInput.file
849
238
  }).async();
850
239
  }
851
240
  }
@@ -859,37 +248,3 @@ var postcss_default = creator;
859
248
  export {
860
249
  postcss_default as default
861
250
  };
862
- /*! Bundled license information:
863
-
864
- is-primitive/index.js:
865
- (*!
866
- * is-primitive <https://github.com/jonschlinkert/is-primitive>
867
- *
868
- * Copyright (c) 2014-present, Jon Schlinkert.
869
- * Released under the MIT License.
870
- *)
871
-
872
- isobject/index.js:
873
- (*!
874
- * isobject <https://github.com/jonschlinkert/isobject>
875
- *
876
- * Copyright (c) 2014-2017, Jon Schlinkert.
877
- * Released under the MIT License.
878
- *)
879
-
880
- is-plain-object/index.js:
881
- (*!
882
- * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
883
- *
884
- * Copyright (c) 2014-2017, Jon Schlinkert.
885
- * Released under the MIT License.
886
- *)
887
-
888
- set-value/index.js:
889
- (*!
890
- * set-value <https://github.com/jonschlinkert/set-value>
891
- *
892
- * Copyright (c) Jon Schlinkert (https://github.com/jonschlinkert).
893
- * Released under the MIT License.
894
- *)
895
- */