tailwindcss-patch 7.1.6 → 8.1.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.
@@ -0,0 +1,1389 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } 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;// ../../node_modules/.pnpm/tsup@8.5.0_jiti@2.6.1_postcss@8.5.6_tsx@4.20.6_typescript@5.9.3_yaml@2.8.1/node_modules/tsup/assets/cjs_shims.js
2
+ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
3
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
4
+
5
+ // src/logger.ts
6
+ var _consola = require('consola');
7
+ var logger = _consola.createConsola.call(void 0, );
8
+ var logger_default = logger;
9
+
10
+ // src/cache/store.ts
11
+ var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsextra);
12
+ var CacheStore = class {
13
+ constructor(options) {
14
+ this.options = options;
15
+ }
16
+ async ensureDir() {
17
+ await _fsextra2.default.ensureDir(this.options.dir);
18
+ }
19
+ ensureDirSync() {
20
+ _fsextra2.default.ensureDirSync(this.options.dir);
21
+ }
22
+ async write(data) {
23
+ if (!this.options.enabled) {
24
+ return void 0;
25
+ }
26
+ try {
27
+ await this.ensureDir();
28
+ await _fsextra2.default.writeJSON(this.options.path, Array.from(data));
29
+ return this.options.path;
30
+ } catch (error) {
31
+ logger_default.error("Unable to persist Tailwind class cache", error);
32
+ return void 0;
33
+ }
34
+ }
35
+ writeSync(data) {
36
+ if (!this.options.enabled) {
37
+ return void 0;
38
+ }
39
+ try {
40
+ this.ensureDirSync();
41
+ _fsextra2.default.writeJSONSync(this.options.path, Array.from(data));
42
+ return this.options.path;
43
+ } catch (error) {
44
+ logger_default.error("Unable to persist Tailwind class cache", error);
45
+ return void 0;
46
+ }
47
+ }
48
+ async read() {
49
+ if (!this.options.enabled) {
50
+ return /* @__PURE__ */ new Set();
51
+ }
52
+ try {
53
+ const exists = await _fsextra2.default.pathExists(this.options.path);
54
+ if (!exists) {
55
+ return /* @__PURE__ */ new Set();
56
+ }
57
+ const data = await _fsextra2.default.readJSON(this.options.path);
58
+ if (Array.isArray(data)) {
59
+ return new Set(data.filter((item) => typeof item === "string"));
60
+ }
61
+ } catch (error) {
62
+ logger_default.warn("Unable to read Tailwind class cache, removing invalid file.", error);
63
+ try {
64
+ await _fsextra2.default.remove(this.options.path);
65
+ } catch (cleanupError) {
66
+ logger_default.error("Failed to clean up invalid cache file", cleanupError);
67
+ }
68
+ }
69
+ return /* @__PURE__ */ new Set();
70
+ }
71
+ readSync() {
72
+ if (!this.options.enabled) {
73
+ return /* @__PURE__ */ new Set();
74
+ }
75
+ try {
76
+ const exists = _fsextra2.default.pathExistsSync(this.options.path);
77
+ if (!exists) {
78
+ return /* @__PURE__ */ new Set();
79
+ }
80
+ const data = _fsextra2.default.readJSONSync(this.options.path);
81
+ if (Array.isArray(data)) {
82
+ return new Set(data.filter((item) => typeof item === "string"));
83
+ }
84
+ } catch (error) {
85
+ logger_default.warn("Unable to read Tailwind class cache, removing invalid file.", error);
86
+ try {
87
+ _fsextra2.default.removeSync(this.options.path);
88
+ } catch (cleanupError) {
89
+ logger_default.error("Failed to clean up invalid cache file", cleanupError);
90
+ }
91
+ }
92
+ return /* @__PURE__ */ new Set();
93
+ }
94
+ };
95
+
96
+ // src/extraction/candidate-extractor.ts
97
+ var _process = require('process'); var _process2 = _interopRequireDefault(_process);
98
+ async function importNode() {
99
+ return Promise.resolve().then(() => _interopRequireWildcard(require("@tailwindcss/node")));
100
+ }
101
+ async function importOxide() {
102
+ return Promise.resolve().then(() => _interopRequireWildcard(require("@tailwindcss/oxide")));
103
+ }
104
+ async function extractRawCandidatesWithPositions(content, extension = "html") {
105
+ const { Scanner } = await importOxide();
106
+ const scanner = new Scanner({});
107
+ const result = scanner.getCandidatesWithPositions({ content, extension });
108
+ return result.map(({ candidate, position }) => ({
109
+ rawCandidate: candidate,
110
+ start: position,
111
+ end: position + candidate.length
112
+ }));
113
+ }
114
+ async function extractRawCandidates(sources) {
115
+ const { Scanner } = await importOxide();
116
+ const scanner = new Scanner({
117
+ sources
118
+ });
119
+ return scanner.scan();
120
+ }
121
+ async function extractValidCandidates(options) {
122
+ const providedOptions = _nullishCoalesce(options, () => ( {}));
123
+ const defaultCwd = _nullishCoalesce(providedOptions.cwd, () => ( _process2.default.cwd()));
124
+ const base = _nullishCoalesce(providedOptions.base, () => ( defaultCwd));
125
+ const css = _nullishCoalesce(providedOptions.css, () => ( '@import "tailwindcss";'));
126
+ const sources = (_nullishCoalesce(providedOptions.sources, () => ( [
127
+ {
128
+ base: defaultCwd,
129
+ pattern: "**/*",
130
+ negated: false
131
+ }
132
+ ]))).map((source) => ({
133
+ base: _nullishCoalesce(source.base, () => ( defaultCwd)),
134
+ pattern: source.pattern,
135
+ negated: source.negated
136
+ }));
137
+ const { __unstable__loadDesignSystem } = await importNode();
138
+ const designSystem = await __unstable__loadDesignSystem(css, { base });
139
+ const candidates = await extractRawCandidates(sources);
140
+ const validCandidates = candidates.filter(
141
+ (rawCandidate) => designSystem.parseCandidate(rawCandidate).length > 0
142
+ );
143
+ return validCandidates;
144
+ }
145
+
146
+ // src/options/legacy.ts
147
+ function normalizeLegacyFeatures(patch) {
148
+ const apply = _optionalChain([patch, 'optionalAccess', _ => _.applyPatches]);
149
+ const extend = _optionalChain([apply, 'optionalAccess', _2 => _2.extendLengthUnits]);
150
+ let extendOption = false;
151
+ if (extend && typeof extend === "object") {
152
+ extendOption = {
153
+ ...extend,
154
+ enabled: true
155
+ };
156
+ } else if (extend === true) {
157
+ extendOption = {
158
+ enabled: true,
159
+ units: ["rpx"],
160
+ overwrite: _optionalChain([patch, 'optionalAccess', _3 => _3.overwrite])
161
+ };
162
+ }
163
+ return {
164
+ exposeContext: _nullishCoalesce(_optionalChain([apply, 'optionalAccess', _4 => _4.exportContext]), () => ( true)),
165
+ extendLengthUnits: extendOption
166
+ };
167
+ }
168
+ function fromLegacyOptions(options) {
169
+ if (!options) {
170
+ return {};
171
+ }
172
+ const patch = options.patch;
173
+ const features = normalizeLegacyFeatures(patch);
174
+ const output = _optionalChain([patch, 'optionalAccess', _5 => _5.output]);
175
+ const tailwindConfig = _optionalChain([patch, 'optionalAccess', _6 => _6.tailwindcss]);
176
+ const tailwindVersion = _optionalChain([tailwindConfig, 'optionalAccess', _7 => _7.version]);
177
+ const tailwindV2 = _optionalChain([tailwindConfig, 'optionalAccess', _8 => _8.v2]);
178
+ const tailwindV3 = _optionalChain([tailwindConfig, 'optionalAccess', _9 => _9.v3]);
179
+ const tailwindV4 = _optionalChain([tailwindConfig, 'optionalAccess', _10 => _10.v4]);
180
+ const tailwindConfigPath = _nullishCoalesce(_optionalChain([tailwindV3, 'optionalAccess', _11 => _11.config]), () => ( _optionalChain([tailwindV2, 'optionalAccess', _12 => _12.config])));
181
+ const tailwindCwd = _nullishCoalesce(_nullishCoalesce(_optionalChain([tailwindV3, 'optionalAccess', _13 => _13.cwd]), () => ( _optionalChain([tailwindV2, 'optionalAccess', _14 => _14.cwd]))), () => ( _optionalChain([patch, 'optionalAccess', _15 => _15.cwd])));
182
+ return {
183
+ cwd: _optionalChain([patch, 'optionalAccess', _16 => _16.cwd]),
184
+ overwrite: _optionalChain([patch, 'optionalAccess', _17 => _17.overwrite]),
185
+ filter: _optionalChain([patch, 'optionalAccess', _18 => _18.filter]),
186
+ cache: typeof options.cache === "boolean" ? options.cache : options.cache ? {
187
+ ...options.cache,
188
+ enabled: _nullishCoalesce(options.cache.enabled, () => ( true))
189
+ } : void 0,
190
+ output: output ? {
191
+ file: output.filename,
192
+ pretty: output.loose ? 2 : false,
193
+ removeUniversalSelector: output.removeUniversalSelector
194
+ } : void 0,
195
+ tailwind: {
196
+ packageName: _optionalChain([patch, 'optionalAccess', _19 => _19.packageName]),
197
+ version: tailwindVersion,
198
+ resolve: _optionalChain([patch, 'optionalAccess', _20 => _20.resolve]),
199
+ config: tailwindConfigPath,
200
+ cwd: tailwindCwd,
201
+ v2: tailwindV2,
202
+ v3: tailwindV3,
203
+ v4: tailwindV4
204
+ },
205
+ features: {
206
+ exposeContext: features.exposeContext,
207
+ extendLengthUnits: features.extendLengthUnits
208
+ }
209
+ };
210
+ }
211
+ function fromUnifiedConfig(registry) {
212
+ if (!registry) {
213
+ return {};
214
+ }
215
+ const tailwind = registry.tailwind;
216
+ const output = registry.output;
217
+ const pretty = (() => {
218
+ if (_optionalChain([output, 'optionalAccess', _21 => _21.pretty]) === void 0) {
219
+ return void 0;
220
+ }
221
+ if (typeof output.pretty === "boolean") {
222
+ return output.pretty ? 2 : false;
223
+ }
224
+ return output.pretty;
225
+ })();
226
+ return {
227
+ output: output ? {
228
+ file: output.file,
229
+ pretty,
230
+ removeUniversalSelector: output.stripUniversalSelector
231
+ } : void 0,
232
+ tailwind: tailwind ? {
233
+ version: tailwind.version,
234
+ packageName: tailwind.package,
235
+ resolve: tailwind.resolve,
236
+ config: tailwind.config,
237
+ cwd: tailwind.cwd,
238
+ v2: tailwind.legacy,
239
+ v3: tailwind.classic,
240
+ v4: tailwind.next
241
+ } : void 0
242
+ };
243
+ }
244
+
245
+ // src/options/normalize.ts
246
+
247
+ var _pathe = require('pathe'); var _pathe2 = _interopRequireDefault(_pathe);
248
+
249
+ // src/constants.ts
250
+ var pkgName = "tailwindcss-patch";
251
+
252
+ // src/options/normalize.ts
253
+ function toPrettyValue(value) {
254
+ if (typeof value === "number") {
255
+ return value > 0 ? value : false;
256
+ }
257
+ if (value === true) {
258
+ return 2;
259
+ }
260
+ return false;
261
+ }
262
+ function normalizeCacheOptions(cache, projectRoot) {
263
+ let enabled = false;
264
+ let cwd = projectRoot;
265
+ let dir = _pathe2.default.resolve(cwd, "node_modules/.cache", pkgName);
266
+ let file = "class-cache.json";
267
+ let strategy = "merge";
268
+ if (typeof cache === "boolean") {
269
+ enabled = cache;
270
+ } else if (typeof cache === "object" && cache) {
271
+ enabled = _nullishCoalesce(cache.enabled, () => ( true));
272
+ cwd = _nullishCoalesce(cache.cwd, () => ( cwd));
273
+ dir = cache.dir ? _pathe2.default.resolve(cache.dir) : _pathe2.default.resolve(cwd, "node_modules/.cache", pkgName);
274
+ file = _nullishCoalesce(cache.file, () => ( file));
275
+ strategy = _nullishCoalesce(cache.strategy, () => ( strategy));
276
+ }
277
+ const filename = _pathe2.default.resolve(dir, file);
278
+ return {
279
+ enabled,
280
+ cwd,
281
+ dir,
282
+ file,
283
+ path: filename,
284
+ strategy
285
+ };
286
+ }
287
+ function normalizeOutputOptions(output) {
288
+ const enabled = _nullishCoalesce(_optionalChain([output, 'optionalAccess', _22 => _22.enabled]), () => ( true));
289
+ const file = _nullishCoalesce(_optionalChain([output, 'optionalAccess', _23 => _23.file]), () => ( ".tw-patch/tw-class-list.json"));
290
+ const format = _nullishCoalesce(_optionalChain([output, 'optionalAccess', _24 => _24.format]), () => ( "json"));
291
+ const pretty = toPrettyValue(_nullishCoalesce(_optionalChain([output, 'optionalAccess', _25 => _25.pretty]), () => ( true)));
292
+ const removeUniversalSelector = _nullishCoalesce(_optionalChain([output, 'optionalAccess', _26 => _26.removeUniversalSelector]), () => ( true));
293
+ return {
294
+ enabled,
295
+ file,
296
+ format,
297
+ pretty,
298
+ removeUniversalSelector
299
+ };
300
+ }
301
+ function normalizeExposeContextOptions(features) {
302
+ if (_optionalChain([features, 'optionalAccess', _27 => _27.exposeContext]) === false) {
303
+ return {
304
+ enabled: false,
305
+ refProperty: "contextRef"
306
+ };
307
+ }
308
+ if (typeof _optionalChain([features, 'optionalAccess', _28 => _28.exposeContext]) === "object" && features.exposeContext) {
309
+ return {
310
+ enabled: true,
311
+ refProperty: _nullishCoalesce(features.exposeContext.refProperty, () => ( "contextRef"))
312
+ };
313
+ }
314
+ return {
315
+ enabled: true,
316
+ refProperty: "contextRef"
317
+ };
318
+ }
319
+ function normalizeExtendLengthUnitsOptions(features) {
320
+ const extend = _optionalChain([features, 'optionalAccess', _29 => _29.extendLengthUnits]);
321
+ if (extend === false || extend === void 0) {
322
+ return null;
323
+ }
324
+ if (extend.enabled === false) {
325
+ return null;
326
+ }
327
+ const base = {
328
+ units: ["rpx"],
329
+ overwrite: true
330
+ };
331
+ return {
332
+ ...base,
333
+ ...extend,
334
+ enabled: _nullishCoalesce(extend.enabled, () => ( true)),
335
+ units: _nullishCoalesce(extend.units, () => ( base.units)),
336
+ overwrite: _nullishCoalesce(extend.overwrite, () => ( base.overwrite))
337
+ };
338
+ }
339
+ function normalizeTailwindV4Options(v4, fallbackBase) {
340
+ const base = _optionalChain([v4, 'optionalAccess', _30 => _30.base]) ? _pathe2.default.resolve(v4.base) : fallbackBase;
341
+ const cssEntries = Array.isArray(_optionalChain([v4, 'optionalAccess', _31 => _31.cssEntries])) ? v4.cssEntries.filter((entry) => Boolean(entry)).map((entry) => _pathe2.default.resolve(entry)) : [];
342
+ const sources = _optionalChain([v4, 'optionalAccess', _32 => _32.sources, 'optionalAccess', _33 => _33.length]) ? v4.sources : [
343
+ {
344
+ base,
345
+ pattern: "**/*",
346
+ negated: false
347
+ }
348
+ ];
349
+ return {
350
+ base,
351
+ css: _optionalChain([v4, 'optionalAccess', _34 => _34.css]),
352
+ cssEntries,
353
+ sources
354
+ };
355
+ }
356
+ function normalizeTailwindOptions(tailwind, projectRoot) {
357
+ const packageName = _nullishCoalesce(_optionalChain([tailwind, 'optionalAccess', _35 => _35.packageName]), () => ( "tailwindcss"));
358
+ const versionHint = _optionalChain([tailwind, 'optionalAccess', _36 => _36.version]);
359
+ const resolve = _optionalChain([tailwind, 'optionalAccess', _37 => _37.resolve]);
360
+ const cwd = _nullishCoalesce(_optionalChain([tailwind, 'optionalAccess', _38 => _38.cwd]), () => ( projectRoot));
361
+ const config = _optionalChain([tailwind, 'optionalAccess', _39 => _39.config]);
362
+ const postcssPlugin = _optionalChain([tailwind, 'optionalAccess', _40 => _40.postcssPlugin]);
363
+ const v4 = normalizeTailwindV4Options(_optionalChain([tailwind, 'optionalAccess', _41 => _41.v4]), cwd);
364
+ return {
365
+ packageName,
366
+ versionHint,
367
+ resolve,
368
+ cwd,
369
+ config,
370
+ postcssPlugin,
371
+ v2: _optionalChain([tailwind, 'optionalAccess', _42 => _42.v2]),
372
+ v3: _optionalChain([tailwind, 'optionalAccess', _43 => _43.v3]),
373
+ v4
374
+ };
375
+ }
376
+ function normalizeOptions(options = {}) {
377
+ const projectRoot = options.cwd ? _pathe2.default.resolve(options.cwd) : _process2.default.cwd();
378
+ const overwrite = _nullishCoalesce(options.overwrite, () => ( true));
379
+ const output = normalizeOutputOptions(options.output);
380
+ const cache = normalizeCacheOptions(options.cache, projectRoot);
381
+ const tailwind = normalizeTailwindOptions(options.tailwind, projectRoot);
382
+ const exposeContext = normalizeExposeContextOptions(options.features);
383
+ const extendLengthUnits = normalizeExtendLengthUnitsOptions(options.features);
384
+ const filter = (className) => {
385
+ if (output.removeUniversalSelector && className === "*") {
386
+ return false;
387
+ }
388
+ if (typeof options.filter === "function") {
389
+ return options.filter(className) !== false;
390
+ }
391
+ return true;
392
+ };
393
+ return {
394
+ projectRoot,
395
+ overwrite,
396
+ tailwind,
397
+ features: {
398
+ exposeContext,
399
+ extendLengthUnits
400
+ },
401
+ output,
402
+ cache,
403
+ filter
404
+ };
405
+ }
406
+
407
+ // src/runtime/class-collector.ts
408
+
409
+
410
+
411
+
412
+ // src/utils.ts
413
+ function isObject(val) {
414
+ return val !== null && typeof val === "object" && Array.isArray(val) === false;
415
+ }
416
+ function spliceChangesIntoString(str, changes) {
417
+ if (!changes[0]) {
418
+ return str;
419
+ }
420
+ changes.sort((a, b) => {
421
+ return a.end - b.end || a.start - b.start;
422
+ });
423
+ let result = "";
424
+ let previous = changes[0];
425
+ result += str.slice(0, previous.start);
426
+ result += previous.replacement;
427
+ for (let i = 1; i < changes.length; ++i) {
428
+ const change = changes[i];
429
+ result += str.slice(previous.end, change.start);
430
+ result += change.replacement;
431
+ previous = change;
432
+ }
433
+ result += str.slice(previous.end);
434
+ return result;
435
+ }
436
+
437
+ // src/runtime/class-collector.ts
438
+ function collectClassesFromContexts(contexts, filter) {
439
+ const set = /* @__PURE__ */ new Set();
440
+ for (const context of contexts) {
441
+ if (!isObject(context) || !context.classCache) {
442
+ continue;
443
+ }
444
+ for (const key of context.classCache.keys()) {
445
+ const className = key.toString();
446
+ if (filter(className)) {
447
+ set.add(className);
448
+ }
449
+ }
450
+ }
451
+ return set;
452
+ }
453
+ async function collectClassesFromTailwindV4(options) {
454
+ const set = /* @__PURE__ */ new Set();
455
+ const v4Options = options.tailwind.v4;
456
+ if (!v4Options) {
457
+ return set;
458
+ }
459
+ const sources = _optionalChain([v4Options, 'access', _44 => _44.sources, 'optionalAccess', _45 => _45.map, 'call', _46 => _46((source) => {
460
+ return {
461
+ base: _nullishCoalesce(_nullishCoalesce(source.base, () => ( v4Options.base)), () => ( _process2.default.cwd())),
462
+ pattern: source.pattern,
463
+ negated: source.negated
464
+ };
465
+ })]);
466
+ if (v4Options.cssEntries.length > 0) {
467
+ for (const entry of v4Options.cssEntries) {
468
+ const filePath = _pathe2.default.isAbsolute(entry) ? entry : _pathe2.default.resolve(options.projectRoot, entry);
469
+ if (!await _fsextra2.default.pathExists(filePath)) {
470
+ continue;
471
+ }
472
+ const css = await _fsextra2.default.readFile(filePath, "utf8");
473
+ const candidates = await extractValidCandidates({
474
+ cwd: options.projectRoot,
475
+ base: v4Options.base,
476
+ css,
477
+ sources
478
+ });
479
+ for (const candidate of candidates) {
480
+ if (options.filter(candidate)) {
481
+ set.add(candidate);
482
+ }
483
+ }
484
+ }
485
+ } else {
486
+ const candidates = await extractValidCandidates({
487
+ cwd: options.projectRoot,
488
+ base: v4Options.base,
489
+ css: v4Options.css,
490
+ sources
491
+ });
492
+ for (const candidate of candidates) {
493
+ if (options.filter(candidate)) {
494
+ set.add(candidate);
495
+ }
496
+ }
497
+ }
498
+ return set;
499
+ }
500
+
501
+ // src/runtime/context-registry.ts
502
+ var _module = require('module');
503
+
504
+
505
+ var require2 = _module.createRequire.call(void 0, importMetaUrl);
506
+ function resolveRuntimeEntry(packageInfo, majorVersion) {
507
+ const root = packageInfo.rootPath;
508
+ if (majorVersion === 2) {
509
+ const jitIndex = _pathe2.default.join(root, "lib/jit/index.js");
510
+ if (_fsextra2.default.existsSync(jitIndex)) {
511
+ return jitIndex;
512
+ }
513
+ } else if (majorVersion === 3) {
514
+ const plugin = _pathe2.default.join(root, "lib/plugin.js");
515
+ const index = _pathe2.default.join(root, "lib/index.js");
516
+ if (_fsextra2.default.existsSync(plugin)) {
517
+ return plugin;
518
+ }
519
+ if (_fsextra2.default.existsSync(index)) {
520
+ return index;
521
+ }
522
+ }
523
+ return void 0;
524
+ }
525
+ function loadRuntimeContexts(packageInfo, majorVersion, refProperty) {
526
+ if (majorVersion === 4) {
527
+ return [];
528
+ }
529
+ const entry = resolveRuntimeEntry(packageInfo, majorVersion);
530
+ if (!entry) {
531
+ return [];
532
+ }
533
+ const moduleExports = require2(entry);
534
+ if (!moduleExports) {
535
+ return [];
536
+ }
537
+ const ref = moduleExports[refProperty];
538
+ if (!ref) {
539
+ return [];
540
+ }
541
+ if (Array.isArray(ref)) {
542
+ return ref;
543
+ }
544
+ if (typeof ref === "object" && Array.isArray(ref.value)) {
545
+ return ref.value;
546
+ }
547
+ return [];
548
+ }
549
+
550
+ // src/runtime/process-tailwindcss.ts
551
+
552
+
553
+ var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postcss);
554
+ var _tailwindcssconfig = require('tailwindcss-config');
555
+ var require3 = _module.createRequire.call(void 0, importMetaUrl);
556
+ async function resolveConfigPath(options) {
557
+ if (options.config && _pathe2.default.isAbsolute(options.config)) {
558
+ return options.config;
559
+ }
560
+ const result = await _tailwindcssconfig.loadConfig.call(void 0, { cwd: options.cwd });
561
+ if (!result) {
562
+ throw new Error(`Unable to locate Tailwind CSS config from ${options.cwd}`);
563
+ }
564
+ return result.filepath;
565
+ }
566
+ async function runTailwindBuild(options) {
567
+ const configPath = await resolveConfigPath(options);
568
+ const pluginName = _nullishCoalesce(options.postcssPlugin, () => ( (options.majorVersion === 4 ? "@tailwindcss/postcss" : "tailwindcss")));
569
+ if (options.majorVersion === 4) {
570
+ return _postcss2.default.call(void 0, [
571
+ require3(pluginName)({
572
+ config: configPath
573
+ })
574
+ ]).process("@import 'tailwindcss';", {
575
+ from: void 0
576
+ });
577
+ }
578
+ return _postcss2.default.call(void 0, [
579
+ require3(pluginName)({
580
+ config: configPath
581
+ })
582
+ ]).process("@tailwind base;@tailwind components;@tailwind utilities;", {
583
+ from: void 0
584
+ });
585
+ }
586
+
587
+ // src/api/tailwindcss-patcher.ts
588
+
589
+
590
+ var _localpkg = require('local-pkg');
591
+
592
+ var _semver = require('semver');
593
+
594
+ // src/patching/operations/export-context/index.ts
595
+
596
+
597
+
598
+ // src/patching/operations/export-context/postcss-v2.ts
599
+ var _types = require('@babel/types'); var t = _interopRequireWildcard(_types); var t2 = _interopRequireWildcard(_types); var t3 = _interopRequireWildcard(_types);
600
+
601
+ // src/babel/index.ts
602
+ var _generator = require('@babel/generator'); var _generator2 = _interopRequireDefault(_generator);
603
+ var _traverse = require('@babel/traverse'); var _traverse2 = _interopRequireDefault(_traverse);
604
+ var _parser = require('@babel/parser');
605
+ function _interopDefaultCompat(e) {
606
+ return e && typeof e === "object" && "default" in e ? e.default : e;
607
+ }
608
+ var generate = _interopDefaultCompat(_generator2.default);
609
+ var traverse = _interopDefaultCompat(_traverse2.default);
610
+
611
+ // src/patching/operations/export-context/postcss-v2.ts
612
+ var IDENTIFIER_RE = /^[A-Z_$][\w$]*$/i;
613
+ function toIdentifierName(property) {
614
+ if (!property) {
615
+ return "contextRef";
616
+ }
617
+ const sanitized = property.replace(/[^\w$]/gu, "_");
618
+ if (/^\d/.test(sanitized)) {
619
+ return `_${sanitized}`;
620
+ }
621
+ return sanitized || "contextRef";
622
+ }
623
+ function createExportsMember(property) {
624
+ if (IDENTIFIER_RE.test(property)) {
625
+ return t.memberExpression(t.identifier("exports"), t.identifier(property));
626
+ }
627
+ return t.memberExpression(t.identifier("exports"), t.stringLiteral(property), true);
628
+ }
629
+ function transformProcessTailwindFeaturesReturnContextV2(content) {
630
+ const ast = _parser.parse.call(void 0, content, {
631
+ sourceType: "unambiguous"
632
+ });
633
+ let hasPatched = false;
634
+ traverse(ast, {
635
+ FunctionDeclaration(path8) {
636
+ const node = path8.node;
637
+ if (_optionalChain([node, 'access', _47 => _47.id, 'optionalAccess', _48 => _48.name]) !== "processTailwindFeatures" || node.body.body.length !== 1 || !t.isReturnStatement(node.body.body[0])) {
638
+ return;
639
+ }
640
+ const returnStatement3 = node.body.body[0];
641
+ if (!t.isFunctionExpression(returnStatement3.argument)) {
642
+ return;
643
+ }
644
+ const body = returnStatement3.argument.body.body;
645
+ const lastStatement = body[body.length - 1];
646
+ const alreadyReturnsContext = Boolean(
647
+ t.isReturnStatement(lastStatement) && t.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context"
648
+ );
649
+ hasPatched = alreadyReturnsContext;
650
+ if (!alreadyReturnsContext) {
651
+ body.push(t.returnStatement(t.identifier("context")));
652
+ }
653
+ }
654
+ });
655
+ return {
656
+ code: hasPatched ? content : generate(ast).code,
657
+ hasPatched
658
+ };
659
+ }
660
+ function transformPostcssPluginV2(content, options) {
661
+ const refIdentifier = t.identifier(toIdentifierName(options.refProperty));
662
+ const exportMember = createExportsMember(options.refProperty);
663
+ const valueMember = t.memberExpression(refIdentifier, t.identifier("value"));
664
+ const ast = _parser.parse.call(void 0, content);
665
+ let hasPatched = false;
666
+ traverse(ast, {
667
+ Program(path8) {
668
+ const program = path8.node;
669
+ const index = program.body.findIndex((statement) => {
670
+ return t.isFunctionDeclaration(statement) && _optionalChain([statement, 'access', _49 => _49.id, 'optionalAccess', _50 => _50.name]) === "_default";
671
+ });
672
+ if (index === -1) {
673
+ return;
674
+ }
675
+ const previous = program.body[index - 1];
676
+ const beforePrevious = program.body[index - 2];
677
+ const alreadyHasVariable = Boolean(
678
+ previous && t.isVariableDeclaration(previous) && previous.declarations.length === 1 && t.isIdentifier(previous.declarations[0].id) && previous.declarations[0].id.name === refIdentifier.name
679
+ );
680
+ const alreadyAssignsExports = Boolean(
681
+ beforePrevious && t.isExpressionStatement(beforePrevious) && t.isAssignmentExpression(beforePrevious.expression) && t.isMemberExpression(beforePrevious.expression.left) && t.isIdentifier(beforePrevious.expression.right) && beforePrevious.expression.right.name === refIdentifier.name && generate(beforePrevious.expression.left).code === generate(exportMember).code
682
+ );
683
+ hasPatched = alreadyHasVariable && alreadyAssignsExports;
684
+ if (!alreadyHasVariable) {
685
+ program.body.splice(
686
+ index,
687
+ 0,
688
+ t.variableDeclaration("var", [
689
+ t.variableDeclarator(
690
+ refIdentifier,
691
+ t.objectExpression([
692
+ t.objectProperty(t.identifier("value"), t.arrayExpression())
693
+ ])
694
+ )
695
+ ]),
696
+ t.expressionStatement(
697
+ t.assignmentExpression("=", exportMember, refIdentifier)
698
+ )
699
+ );
700
+ }
701
+ },
702
+ FunctionDeclaration(path8) {
703
+ if (hasPatched) {
704
+ return;
705
+ }
706
+ const fn = path8.node;
707
+ if (_optionalChain([fn, 'access', _51 => _51.id, 'optionalAccess', _52 => _52.name]) !== "_default") {
708
+ return;
709
+ }
710
+ if (fn.body.body.length !== 1 || !t.isReturnStatement(fn.body.body[0])) {
711
+ return;
712
+ }
713
+ const returnStatement3 = fn.body.body[0];
714
+ if (!t.isCallExpression(returnStatement3.argument) || !t.isMemberExpression(returnStatement3.argument.callee) || !t.isArrayExpression(returnStatement3.argument.callee.object)) {
715
+ return;
716
+ }
717
+ const fnExpression = returnStatement3.argument.callee.object.elements[1];
718
+ if (!fnExpression || !t.isFunctionExpression(fnExpression)) {
719
+ return;
720
+ }
721
+ const block = fnExpression.body;
722
+ const statements = block.body;
723
+ if (t.isExpressionStatement(statements[0]) && t.isAssignmentExpression(statements[0].expression) && t.isNumericLiteral(statements[0].expression.right)) {
724
+ hasPatched = true;
725
+ return;
726
+ }
727
+ const lastStatement = statements[statements.length - 1];
728
+ if (lastStatement && t.isExpressionStatement(lastStatement)) {
729
+ statements[statements.length - 1] = t.expressionStatement(
730
+ t.callExpression(
731
+ t.memberExpression(valueMember, t.identifier("push")),
732
+ [lastStatement.expression]
733
+ )
734
+ );
735
+ }
736
+ const index = statements.findIndex((statement) => t.isIfStatement(statement));
737
+ if (index > -1) {
738
+ const ifStatement = statements[index];
739
+ if (t.isBlockStatement(ifStatement.consequent) && ifStatement.consequent.body[1] && t.isForOfStatement(ifStatement.consequent.body[1])) {
740
+ const forOf = ifStatement.consequent.body[1];
741
+ if (t.isBlockStatement(forOf.body) && forOf.body.body.length === 1) {
742
+ const nestedIf = forOf.body.body[0];
743
+ if (nestedIf && t.isIfStatement(nestedIf) && t.isBlockStatement(nestedIf.consequent) && nestedIf.consequent.body.length === 1 && t.isExpressionStatement(nestedIf.consequent.body[0])) {
744
+ nestedIf.consequent.body[0] = t.expressionStatement(
745
+ t.callExpression(
746
+ t.memberExpression(valueMember, t.identifier("push")),
747
+ [nestedIf.consequent.body[0].expression]
748
+ )
749
+ );
750
+ }
751
+ }
752
+ }
753
+ }
754
+ statements.unshift(
755
+ t.expressionStatement(
756
+ t.assignmentExpression(
757
+ "=",
758
+ t.memberExpression(valueMember, t.identifier("length")),
759
+ t.numericLiteral(0)
760
+ )
761
+ )
762
+ );
763
+ }
764
+ });
765
+ return {
766
+ code: hasPatched ? content : generate(ast).code,
767
+ hasPatched
768
+ };
769
+ }
770
+
771
+ // src/patching/operations/export-context/postcss-v3.ts
772
+
773
+ var IDENTIFIER_RE2 = /^[A-Z_$][\w$]*$/i;
774
+ function toIdentifierName2(property) {
775
+ if (!property) {
776
+ return "contextRef";
777
+ }
778
+ const sanitized = property.replace(/[^\w$]/gu, "_");
779
+ if (/^\d/.test(sanitized)) {
780
+ return `_${sanitized}`;
781
+ }
782
+ return sanitized || "contextRef";
783
+ }
784
+ function createModuleExportsMember(property) {
785
+ const object = t2.memberExpression(t2.identifier("module"), t2.identifier("exports"));
786
+ if (IDENTIFIER_RE2.test(property)) {
787
+ return t2.memberExpression(object, t2.identifier(property));
788
+ }
789
+ return t2.memberExpression(object, t2.stringLiteral(property), true);
790
+ }
791
+ function transformProcessTailwindFeaturesReturnContext(content) {
792
+ const ast = _parser.parse.call(void 0, content);
793
+ let hasPatched = false;
794
+ traverse(ast, {
795
+ FunctionDeclaration(path8) {
796
+ const node = path8.node;
797
+ if (_optionalChain([node, 'access', _53 => _53.id, 'optionalAccess', _54 => _54.name]) !== "processTailwindFeatures" || node.body.body.length !== 1) {
798
+ return;
799
+ }
800
+ const [returnStatement3] = node.body.body;
801
+ if (!t2.isReturnStatement(returnStatement3) || !t2.isFunctionExpression(returnStatement3.argument)) {
802
+ return;
803
+ }
804
+ const expression = returnStatement3.argument;
805
+ const body = expression.body.body;
806
+ const lastStatement = body[body.length - 1];
807
+ const alreadyReturnsContext = Boolean(
808
+ t2.isReturnStatement(lastStatement) && t2.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context"
809
+ );
810
+ hasPatched = alreadyReturnsContext;
811
+ if (!alreadyReturnsContext) {
812
+ body.push(t2.returnStatement(t2.identifier("context")));
813
+ }
814
+ }
815
+ });
816
+ return {
817
+ code: hasPatched ? content : generate(ast).code,
818
+ hasPatched
819
+ };
820
+ }
821
+ function transformPostcssPlugin(content, { refProperty }) {
822
+ const ast = _parser.parse.call(void 0, content);
823
+ const refIdentifier = t2.identifier(toIdentifierName2(refProperty));
824
+ const moduleExportsMember = createModuleExportsMember(refProperty);
825
+ const valueMember = t2.memberExpression(refIdentifier, t2.identifier("value"));
826
+ let hasPatched = false;
827
+ traverse(ast, {
828
+ Program(path8) {
829
+ const program = path8.node;
830
+ const index = program.body.findIndex((statement) => {
831
+ return t2.isExpressionStatement(statement) && t2.isAssignmentExpression(statement.expression) && t2.isMemberExpression(statement.expression.left) && t2.isFunctionExpression(statement.expression.right) && _optionalChain([statement, 'access', _55 => _55.expression, 'access', _56 => _56.right, 'access', _57 => _57.id, 'optionalAccess', _58 => _58.name]) === "tailwindcss";
832
+ });
833
+ if (index === -1) {
834
+ return;
835
+ }
836
+ const previousStatement = program.body[index - 1];
837
+ const lastStatement = program.body[program.body.length - 1];
838
+ const alreadyHasVariable = Boolean(
839
+ previousStatement && t2.isVariableDeclaration(previousStatement) && previousStatement.declarations.length === 1 && t2.isIdentifier(previousStatement.declarations[0].id) && previousStatement.declarations[0].id.name === refIdentifier.name
840
+ );
841
+ const alreadyAssignsModuleExports = Boolean(
842
+ t2.isExpressionStatement(lastStatement) && t2.isAssignmentExpression(lastStatement.expression) && t2.isMemberExpression(lastStatement.expression.left) && t2.isIdentifier(lastStatement.expression.right) && lastStatement.expression.right.name === refIdentifier.name && generate(lastStatement.expression.left).code === generate(moduleExportsMember).code
843
+ );
844
+ hasPatched = alreadyHasVariable && alreadyAssignsModuleExports;
845
+ if (!alreadyHasVariable) {
846
+ program.body.splice(
847
+ index,
848
+ 0,
849
+ t2.variableDeclaration("const", [
850
+ t2.variableDeclarator(
851
+ refIdentifier,
852
+ t2.objectExpression([
853
+ t2.objectProperty(t2.identifier("value"), t2.arrayExpression())
854
+ ])
855
+ )
856
+ ])
857
+ );
858
+ }
859
+ if (!alreadyAssignsModuleExports) {
860
+ program.body.push(
861
+ t2.expressionStatement(
862
+ t2.assignmentExpression("=", moduleExportsMember, refIdentifier)
863
+ )
864
+ );
865
+ }
866
+ },
867
+ FunctionExpression(path8) {
868
+ if (hasPatched) {
869
+ return;
870
+ }
871
+ const fn = path8.node;
872
+ if (_optionalChain([fn, 'access', _59 => _59.id, 'optionalAccess', _60 => _60.name]) !== "tailwindcss" || fn.body.body.length !== 1) {
873
+ return;
874
+ }
875
+ const [returnStatement3] = fn.body.body;
876
+ if (!returnStatement3 || !t2.isReturnStatement(returnStatement3) || !t2.isObjectExpression(returnStatement3.argument)) {
877
+ return;
878
+ }
879
+ const properties = returnStatement3.argument.properties;
880
+ if (properties.length !== 2) {
881
+ return;
882
+ }
883
+ const pluginsProperty = properties.find(
884
+ (prop) => t2.isObjectProperty(prop) && t2.isIdentifier(prop.key) && prop.key.name === "plugins"
885
+ );
886
+ if (!pluginsProperty || !t2.isObjectProperty(pluginsProperty) || !t2.isCallExpression(pluginsProperty.value) || !t2.isMemberExpression(pluginsProperty.value.callee) || !t2.isArrayExpression(pluginsProperty.value.callee.object)) {
887
+ return;
888
+ }
889
+ const pluginsArray = pluginsProperty.value.callee.object.elements;
890
+ const targetPlugin = pluginsArray[1];
891
+ if (!targetPlugin || !t2.isFunctionExpression(targetPlugin)) {
892
+ return;
893
+ }
894
+ const block = targetPlugin.body;
895
+ const statements = block.body;
896
+ const last = statements[statements.length - 1];
897
+ if (last && t2.isExpressionStatement(last)) {
898
+ statements[statements.length - 1] = t2.expressionStatement(
899
+ t2.callExpression(
900
+ t2.memberExpression(valueMember, t2.identifier("push")),
901
+ [last.expression]
902
+ )
903
+ );
904
+ }
905
+ const index = statements.findIndex((s) => t2.isIfStatement(s));
906
+ if (index > -1) {
907
+ const ifStatement = statements[index];
908
+ if (t2.isBlockStatement(ifStatement.consequent)) {
909
+ const [, second] = ifStatement.consequent.body;
910
+ if (second && t2.isForOfStatement(second) && t2.isBlockStatement(second.body)) {
911
+ const bodyStatement = second.body.body[0];
912
+ if (bodyStatement && t2.isIfStatement(bodyStatement) && t2.isBlockStatement(bodyStatement.consequent) && bodyStatement.consequent.body.length === 1 && t2.isExpressionStatement(bodyStatement.consequent.body[0])) {
913
+ bodyStatement.consequent.body[0] = t2.expressionStatement(
914
+ t2.callExpression(
915
+ t2.memberExpression(valueMember, t2.identifier("push")),
916
+ [bodyStatement.consequent.body[0].expression]
917
+ )
918
+ );
919
+ }
920
+ }
921
+ }
922
+ }
923
+ statements.unshift(
924
+ t2.expressionStatement(
925
+ t2.assignmentExpression(
926
+ "=",
927
+ t2.memberExpression(valueMember, t2.identifier("length")),
928
+ t2.numericLiteral(0)
929
+ )
930
+ )
931
+ );
932
+ }
933
+ });
934
+ return {
935
+ code: hasPatched ? content : generate(ast).code,
936
+ hasPatched
937
+ };
938
+ }
939
+
940
+ // src/patching/operations/export-context/index.ts
941
+ function writeFileIfRequired(filePath, code, overwrite, successMessage) {
942
+ if (!overwrite) {
943
+ return;
944
+ }
945
+ _fsextra2.default.writeFileSync(filePath, code, {
946
+ encoding: "utf8"
947
+ });
948
+ logger_default.success(successMessage);
949
+ }
950
+ function applyExposeContextPatch(params) {
951
+ const { rootDir, refProperty, overwrite, majorVersion } = params;
952
+ const result = {
953
+ applied: false,
954
+ files: {}
955
+ };
956
+ if (majorVersion === 3) {
957
+ const processFileRelative = "lib/processTailwindFeatures.js";
958
+ const processFilePath = _pathe2.default.resolve(rootDir, processFileRelative);
959
+ if (_fsextra2.default.existsSync(processFilePath)) {
960
+ const content = _fsextra2.default.readFileSync(processFilePath, "utf8");
961
+ const { code, hasPatched } = transformProcessTailwindFeaturesReturnContext(content);
962
+ result.files[processFileRelative] = code;
963
+ if (!hasPatched) {
964
+ writeFileIfRequired(
965
+ processFilePath,
966
+ code,
967
+ overwrite,
968
+ "Patched Tailwind CSS processTailwindFeatures to expose runtime context."
969
+ );
970
+ result.applied = true;
971
+ }
972
+ }
973
+ const pluginCandidates = ["lib/plugin.js", "lib/index.js"];
974
+ const pluginRelative = pluginCandidates.find((candidate) => _fsextra2.default.existsSync(_pathe2.default.resolve(rootDir, candidate)));
975
+ if (pluginRelative) {
976
+ const pluginPath = _pathe2.default.resolve(rootDir, pluginRelative);
977
+ const content = _fsextra2.default.readFileSync(pluginPath, "utf8");
978
+ const { code, hasPatched } = transformPostcssPlugin(content, { refProperty });
979
+ result.files[pluginRelative] = code;
980
+ if (!hasPatched) {
981
+ writeFileIfRequired(
982
+ pluginPath,
983
+ code,
984
+ overwrite,
985
+ "Patched Tailwind CSS plugin entry to collect runtime contexts."
986
+ );
987
+ result.applied = true;
988
+ }
989
+ }
990
+ } else if (majorVersion === 2) {
991
+ const processFileRelative = "lib/jit/processTailwindFeatures.js";
992
+ const processFilePath = _pathe2.default.resolve(rootDir, processFileRelative);
993
+ if (_fsextra2.default.existsSync(processFilePath)) {
994
+ const content = _fsextra2.default.readFileSync(processFilePath, "utf8");
995
+ const { code, hasPatched } = transformProcessTailwindFeaturesReturnContextV2(content);
996
+ result.files[processFileRelative] = code;
997
+ if (!hasPatched) {
998
+ writeFileIfRequired(
999
+ processFilePath,
1000
+ code,
1001
+ overwrite,
1002
+ "Patched Tailwind CSS JIT processTailwindFeatures to expose runtime context."
1003
+ );
1004
+ result.applied = true;
1005
+ }
1006
+ }
1007
+ const pluginRelative = "lib/jit/index.js";
1008
+ const pluginPath = _pathe2.default.resolve(rootDir, pluginRelative);
1009
+ if (_fsextra2.default.existsSync(pluginPath)) {
1010
+ const content = _fsextra2.default.readFileSync(pluginPath, "utf8");
1011
+ const { code, hasPatched } = transformPostcssPluginV2(content, { refProperty });
1012
+ result.files[pluginRelative] = code;
1013
+ if (!hasPatched) {
1014
+ writeFileIfRequired(
1015
+ pluginPath,
1016
+ code,
1017
+ overwrite,
1018
+ "Patched Tailwind CSS JIT entry to collect runtime contexts."
1019
+ );
1020
+ result.applied = true;
1021
+ }
1022
+ }
1023
+ }
1024
+ return result;
1025
+ }
1026
+
1027
+ // src/patching/operations/extend-length-units.ts
1028
+
1029
+
1030
+
1031
+ function updateLengthUnitsArray(content, options) {
1032
+ const { variableName = "lengthUnits", units } = options;
1033
+ const ast = _parser.parse.call(void 0, content);
1034
+ let arrayRef;
1035
+ let changed = false;
1036
+ traverse(ast, {
1037
+ Identifier(path8) {
1038
+ if (path8.node.name === variableName && t3.isVariableDeclarator(path8.parent) && t3.isArrayExpression(path8.parent.init)) {
1039
+ arrayRef = path8.parent.init;
1040
+ const existing = new Set(
1041
+ path8.parent.init.elements.map((element) => t3.isStringLiteral(element) ? element.value : void 0).filter(Boolean)
1042
+ );
1043
+ for (const unit of units) {
1044
+ if (!existing.has(unit)) {
1045
+ path8.parent.init.elements = path8.parent.init.elements.map((element) => {
1046
+ if (t3.isStringLiteral(element)) {
1047
+ return t3.stringLiteral(element.value);
1048
+ }
1049
+ return element;
1050
+ });
1051
+ path8.parent.init.elements.push(t3.stringLiteral(unit));
1052
+ changed = true;
1053
+ }
1054
+ }
1055
+ }
1056
+ }
1057
+ });
1058
+ return {
1059
+ arrayRef,
1060
+ changed
1061
+ };
1062
+ }
1063
+ function applyExtendLengthUnitsPatchV3(rootDir, options) {
1064
+ if (!options.enabled) {
1065
+ return { changed: false, code: void 0 };
1066
+ }
1067
+ const opts = {
1068
+ ...options,
1069
+ lengthUnitsFilePath: _nullishCoalesce(options.lengthUnitsFilePath, () => ( "lib/util/dataTypes.js")),
1070
+ variableName: _nullishCoalesce(options.variableName, () => ( "lengthUnits"))
1071
+ };
1072
+ const dataTypesFilePath = _pathe2.default.resolve(rootDir, opts.lengthUnitsFilePath);
1073
+ const exists = _fsextra2.default.existsSync(dataTypesFilePath);
1074
+ if (!exists) {
1075
+ return { changed: false, code: void 0 };
1076
+ }
1077
+ const content = _fsextra2.default.readFileSync(dataTypesFilePath, "utf8");
1078
+ const { arrayRef, changed } = updateLengthUnitsArray(content, opts);
1079
+ if (!arrayRef || !changed) {
1080
+ return { changed: false, code: void 0 };
1081
+ }
1082
+ const { code } = generate(arrayRef, {
1083
+ jsescOption: { quotes: "single" }
1084
+ });
1085
+ if (arrayRef.start != null && arrayRef.end != null) {
1086
+ const nextCode = `${content.slice(0, arrayRef.start)}${code}${content.slice(arrayRef.end)}`;
1087
+ if (opts.overwrite) {
1088
+ const target = opts.destPath ? _pathe2.default.resolve(opts.destPath) : dataTypesFilePath;
1089
+ _fsextra2.default.writeFileSync(target, nextCode, "utf8");
1090
+ logger_default.success("Patched Tailwind CSS length unit list (v3).");
1091
+ }
1092
+ return {
1093
+ changed: true,
1094
+ code: nextCode
1095
+ };
1096
+ }
1097
+ return {
1098
+ changed: false,
1099
+ code: void 0
1100
+ };
1101
+ }
1102
+ function applyExtendLengthUnitsPatchV4(rootDir, options) {
1103
+ if (!options.enabled) {
1104
+ return { files: [], changed: false };
1105
+ }
1106
+ const opts = { ...options };
1107
+ const distDir = _pathe2.default.resolve(rootDir, "dist");
1108
+ if (!_fsextra2.default.existsSync(distDir)) {
1109
+ return { files: [], changed: false };
1110
+ }
1111
+ const entries = _fsextra2.default.readdirSync(distDir);
1112
+ const chunkNames = entries.filter((entry) => entry.endsWith(".js") || entry.endsWith(".mjs"));
1113
+ const pattern = /\[\s*["']cm["'],\s*["']mm["'],[\w,"']+\]/;
1114
+ const candidates = chunkNames.map((chunkName) => {
1115
+ const file = _pathe2.default.join(distDir, chunkName);
1116
+ const code = _fsextra2.default.readFileSync(file, "utf8");
1117
+ const match = pattern.exec(code);
1118
+ if (!match) {
1119
+ return null;
1120
+ }
1121
+ return {
1122
+ file,
1123
+ code,
1124
+ match,
1125
+ hasPatched: false
1126
+ };
1127
+ }).filter((candidate) => candidate !== null);
1128
+ for (const item of candidates) {
1129
+ const { code, file, match } = item;
1130
+ const ast = _parser.parse.call(void 0, match[0], { sourceType: "unambiguous" });
1131
+ traverse(ast, {
1132
+ ArrayExpression(path8) {
1133
+ for (const unit of opts.units) {
1134
+ if (path8.node.elements.some((element) => t3.isStringLiteral(element) && element.value === unit)) {
1135
+ item.hasPatched = true;
1136
+ return;
1137
+ }
1138
+ path8.node.elements.push(t3.stringLiteral(unit));
1139
+ }
1140
+ }
1141
+ });
1142
+ if (item.hasPatched) {
1143
+ continue;
1144
+ }
1145
+ const { code: replacement } = generate(ast, { minified: true });
1146
+ const start = _nullishCoalesce(match.index, () => ( 0));
1147
+ const end = start + match[0].length;
1148
+ item.code = spliceChangesIntoString(code, [
1149
+ {
1150
+ start,
1151
+ end,
1152
+ replacement: replacement.endsWith(";") ? replacement.slice(0, -1) : replacement
1153
+ }
1154
+ ]);
1155
+ if (opts.overwrite) {
1156
+ _fsextra2.default.writeFileSync(file, item.code, "utf8");
1157
+ }
1158
+ }
1159
+ if (candidates.some((file) => !file.hasPatched)) {
1160
+ logger_default.success("Patched Tailwind CSS length unit list (v4).");
1161
+ }
1162
+ return {
1163
+ changed: candidates.some((file) => !file.hasPatched),
1164
+ files: candidates
1165
+ };
1166
+ }
1167
+
1168
+ // src/patching/patch-runner.ts
1169
+ function applyTailwindPatches(context) {
1170
+ const { packageInfo, options, majorVersion } = context;
1171
+ const results = {};
1172
+ if (options.features.exposeContext.enabled && (majorVersion === 2 || majorVersion === 3)) {
1173
+ results.exposeContext = applyExposeContextPatch({
1174
+ rootDir: packageInfo.rootPath,
1175
+ refProperty: options.features.exposeContext.refProperty,
1176
+ overwrite: options.overwrite,
1177
+ majorVersion
1178
+ });
1179
+ }
1180
+ if (_optionalChain([options, 'access', _61 => _61.features, 'access', _62 => _62.extendLengthUnits, 'optionalAccess', _63 => _63.enabled])) {
1181
+ if (majorVersion === 3) {
1182
+ results.extendLengthUnits = applyExtendLengthUnitsPatchV3(
1183
+ packageInfo.rootPath,
1184
+ options.features.extendLengthUnits
1185
+ );
1186
+ } else if (majorVersion === 4) {
1187
+ results.extendLengthUnits = applyExtendLengthUnitsPatchV4(
1188
+ packageInfo.rootPath,
1189
+ options.features.extendLengthUnits
1190
+ );
1191
+ }
1192
+ }
1193
+ return results;
1194
+ }
1195
+
1196
+ // src/api/tailwindcss-patcher.ts
1197
+ function resolveMajorVersion(version, hint) {
1198
+ if (hint && [2, 3, 4].includes(hint)) {
1199
+ return hint;
1200
+ }
1201
+ if (version) {
1202
+ const coerced = _semver.coerce.call(void 0, version);
1203
+ if (coerced) {
1204
+ const major = coerced.major;
1205
+ if (major === 2 || major === 3 || major === 4) {
1206
+ return major;
1207
+ }
1208
+ if (major >= 4) {
1209
+ return 4;
1210
+ }
1211
+ }
1212
+ }
1213
+ return 3;
1214
+ }
1215
+ function resolveTailwindExecutionOptions(normalized, majorVersion) {
1216
+ const base = normalized.tailwind;
1217
+ if (majorVersion === 2 && base.v2) {
1218
+ return {
1219
+ cwd: _nullishCoalesce(_nullishCoalesce(base.v2.cwd, () => ( base.cwd)), () => ( normalized.projectRoot)),
1220
+ config: _nullishCoalesce(base.v2.config, () => ( base.config)),
1221
+ postcssPlugin: _nullishCoalesce(base.v2.postcssPlugin, () => ( base.postcssPlugin))
1222
+ };
1223
+ }
1224
+ if (majorVersion === 3 && base.v3) {
1225
+ return {
1226
+ cwd: _nullishCoalesce(_nullishCoalesce(base.v3.cwd, () => ( base.cwd)), () => ( normalized.projectRoot)),
1227
+ config: _nullishCoalesce(base.v3.config, () => ( base.config)),
1228
+ postcssPlugin: _nullishCoalesce(base.v3.postcssPlugin, () => ( base.postcssPlugin))
1229
+ };
1230
+ }
1231
+ return {
1232
+ cwd: _nullishCoalesce(base.cwd, () => ( normalized.projectRoot)),
1233
+ config: base.config,
1234
+ postcssPlugin: base.postcssPlugin
1235
+ };
1236
+ }
1237
+ var TailwindcssPatcher = (_class = class {
1238
+
1239
+
1240
+
1241
+
1242
+ constructor(options = {}) {;_class.prototype.__init.call(this);
1243
+ const resolvedOptions = options && typeof options === "object" && "patch" in options ? fromLegacyOptions(options) : options;
1244
+ this.options = normalizeOptions(resolvedOptions);
1245
+ const packageInfo = _localpkg.getPackageInfoSync.call(void 0,
1246
+ this.options.tailwind.packageName,
1247
+ this.options.tailwind.resolve
1248
+ );
1249
+ if (!packageInfo) {
1250
+ throw new Error(`Unable to locate Tailwind CSS package "${this.options.tailwind.packageName}".`);
1251
+ }
1252
+ this.packageInfo = packageInfo;
1253
+ this.majorVersion = resolveMajorVersion(
1254
+ this.packageInfo.version,
1255
+ this.options.tailwind.versionHint
1256
+ );
1257
+ this.cacheStore = new CacheStore(this.options.cache);
1258
+ }
1259
+ async patch() {
1260
+ return applyTailwindPatches({
1261
+ packageInfo: this.packageInfo,
1262
+ options: this.options,
1263
+ majorVersion: this.majorVersion
1264
+ });
1265
+ }
1266
+ getContexts() {
1267
+ return loadRuntimeContexts(
1268
+ this.packageInfo,
1269
+ this.majorVersion,
1270
+ this.options.features.exposeContext.refProperty
1271
+ );
1272
+ }
1273
+ async runTailwindBuildIfNeeded() {
1274
+ if (this.majorVersion === 2 || this.majorVersion === 3) {
1275
+ const executionOptions = resolveTailwindExecutionOptions(this.options, this.majorVersion);
1276
+ await runTailwindBuild({
1277
+ cwd: executionOptions.cwd,
1278
+ config: executionOptions.config,
1279
+ majorVersion: this.majorVersion,
1280
+ postcssPlugin: executionOptions.postcssPlugin
1281
+ });
1282
+ }
1283
+ }
1284
+ async collectClassSet() {
1285
+ if (this.majorVersion === 4) {
1286
+ return collectClassesFromTailwindV4(this.options);
1287
+ }
1288
+ const contexts = this.getContexts();
1289
+ return collectClassesFromContexts(contexts, this.options.filter);
1290
+ }
1291
+ collectClassSetSync() {
1292
+ if (this.majorVersion === 4) {
1293
+ throw new Error("getClassSetSync is not supported for Tailwind CSS v4 projects. Use getClassSet instead.");
1294
+ }
1295
+ const contexts = this.getContexts();
1296
+ return collectClassesFromContexts(contexts, this.options.filter);
1297
+ }
1298
+ async mergeWithCache(set) {
1299
+ if (!this.options.cache.enabled) {
1300
+ return set;
1301
+ }
1302
+ const existing = await this.cacheStore.read();
1303
+ if (this.options.cache.strategy === "merge") {
1304
+ for (const value of existing) {
1305
+ set.add(value);
1306
+ }
1307
+ await this.cacheStore.write(set);
1308
+ } else {
1309
+ if (set.size > 0) {
1310
+ await this.cacheStore.write(set);
1311
+ } else {
1312
+ return existing;
1313
+ }
1314
+ }
1315
+ return set;
1316
+ }
1317
+ mergeWithCacheSync(set) {
1318
+ if (!this.options.cache.enabled) {
1319
+ return set;
1320
+ }
1321
+ const existing = this.cacheStore.readSync();
1322
+ if (this.options.cache.strategy === "merge") {
1323
+ for (const value of existing) {
1324
+ set.add(value);
1325
+ }
1326
+ this.cacheStore.writeSync(set);
1327
+ } else {
1328
+ if (set.size > 0) {
1329
+ this.cacheStore.writeSync(set);
1330
+ } else {
1331
+ return existing;
1332
+ }
1333
+ }
1334
+ return set;
1335
+ }
1336
+ async getClassSet() {
1337
+ await this.runTailwindBuildIfNeeded();
1338
+ const set = await this.collectClassSet();
1339
+ return this.mergeWithCache(set);
1340
+ }
1341
+ getClassSetSync() {
1342
+ const set = this.collectClassSetSync();
1343
+ return this.mergeWithCacheSync(set);
1344
+ }
1345
+ async extract(options) {
1346
+ const shouldWrite = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _64 => _64.write]), () => ( this.options.output.enabled));
1347
+ const classSet = await this.getClassSet();
1348
+ const classList = Array.from(classSet);
1349
+ const result = {
1350
+ classList,
1351
+ classSet
1352
+ };
1353
+ if (!shouldWrite || !this.options.output.file) {
1354
+ return result;
1355
+ }
1356
+ const target = _pathe2.default.resolve(this.options.output.file);
1357
+ await _fsextra2.default.ensureDir(_pathe2.default.dirname(target));
1358
+ if (this.options.output.format === "json") {
1359
+ const spaces = typeof this.options.output.pretty === "number" ? this.options.output.pretty : void 0;
1360
+ await _fsextra2.default.writeJSON(target, classList, { spaces });
1361
+ } else {
1362
+ await _fsextra2.default.writeFile(target, `${classList.join("\n")}
1363
+ `, "utf8");
1364
+ }
1365
+ logger_default.success(`Tailwind CSS class list saved to ${target.replace(_process2.default.cwd(), ".")}`);
1366
+ return {
1367
+ ...result,
1368
+ filename: target
1369
+ };
1370
+ }
1371
+ // Backwards compatibility helper used by tests and API consumers.
1372
+ __init() {this.extractValidCandidates = exports.extractValidCandidates = extractValidCandidates}
1373
+ }, _class);
1374
+
1375
+
1376
+
1377
+
1378
+
1379
+
1380
+
1381
+
1382
+
1383
+
1384
+
1385
+
1386
+
1387
+
1388
+
1389
+ exports.logger_default = logger_default; exports.CacheStore = CacheStore; exports.extractRawCandidatesWithPositions = extractRawCandidatesWithPositions; exports.extractRawCandidates = extractRawCandidates; exports.extractValidCandidates = extractValidCandidates; exports.fromLegacyOptions = fromLegacyOptions; exports.fromUnifiedConfig = fromUnifiedConfig; exports.normalizeOptions = normalizeOptions; exports.collectClassesFromContexts = collectClassesFromContexts; exports.collectClassesFromTailwindV4 = collectClassesFromTailwindV4; exports.loadRuntimeContexts = loadRuntimeContexts; exports.runTailwindBuild = runTailwindBuild; exports.TailwindcssPatcher = TailwindcssPatcher;