@bitovi/vybit 0.6.0 → 0.8.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.
@@ -1,158 +1,488 @@
1
1
  // Tailwind v3 adapter — uses resolveConfig + PostCSS from the target project's tailwindcss v3.
2
2
 
3
3
  import { existsSync, readFileSync } from "fs";
4
- import { resolve } from "path";
5
4
  import { createRequire } from "module";
6
- import type { TailwindAdapter, TailwindThemeSubset } from "./tailwind-adapter.js";
5
+ import { resolve } from "path";
6
+ import { pathToFileURL } from "url";
7
+ import type {
8
+ TailwindAdapter,
9
+ TailwindThemeSubset,
10
+ } from "./tailwind-adapter.js";
7
11
 
8
12
  let cached: TailwindThemeSubset | null = null;
9
13
 
10
14
  const defaultTheme: TailwindThemeSubset = {
11
- spacing: {
12
- "0": "0px", px: "1px",
13
- "0.5": "0.125rem", "1": "0.25rem", "1.5": "0.375rem", "2": "0.5rem",
14
- "2.5": "0.625rem", "3": "0.75rem", "3.5": "0.875rem", "4": "1rem",
15
- "5": "1.25rem", "6": "1.5rem", "7": "1.75rem", "8": "2rem",
16
- "9": "2.25rem", "10": "2.5rem", "11": "2.75rem", "12": "3rem",
17
- "14": "3.5rem", "16": "4rem", "20": "5rem", "24": "6rem",
18
- "28": "7rem", "32": "8rem", "36": "9rem", "40": "10rem",
19
- "44": "11rem", "48": "12rem", "52": "13rem", "56": "14rem",
20
- "60": "15rem", "64": "16rem", "72": "18rem", "80": "20rem", "96": "24rem",
21
- },
22
- colors: {
23
- inherit: "inherit", current: "currentColor", transparent: "transparent",
24
- black: "#000", white: "#fff",
25
- slate: { "50": "#f8fafc", "100": "#f1f5f9", "200": "#e2e8f0", "300": "#cbd5e1", "400": "#94a3b8", "500": "#64748b", "600": "#475569", "700": "#334155", "800": "#1e293b", "900": "#0f172a", "950": "#020617" },
26
- gray: { "50": "#f9fafb", "100": "#f3f4f6", "200": "#e5e7eb", "300": "#d1d5db", "400": "#9ca3af", "500": "#6b7280", "600": "#4b5563", "700": "#374151", "800": "#1f2937", "900": "#111827", "950": "#030712" },
27
- zinc: { "50": "#fafafa", "100": "#f4f4f5", "200": "#e4e4e7", "300": "#d4d4d8", "400": "#a1a1aa", "500": "#71717a", "600": "#52525b", "700": "#3f3f46", "800": "#27272a", "900": "#18181b", "950": "#09090b" },
28
- neutral: { "50": "#fafafa", "100": "#f5f5f5", "200": "#e5e5e5", "300": "#d4d4d4", "400": "#a3a3a3", "500": "#737373", "600": "#525252", "700": "#404040", "800": "#262626", "900": "#171717", "950": "#0a0a0a" },
29
- stone: { "50": "#fafaf9", "100": "#f5f5f4", "200": "#e7e5e4", "300": "#d6d3d1", "400": "#a8a29e", "500": "#78716c", "600": "#57534e", "700": "#44403c", "800": "#292524", "900": "#1c1917", "950": "#0c0a09" },
30
- red: { "50": "#fef2f2", "100": "#fee2e2", "200": "#fecaca", "300": "#fca5a5", "400": "#f87171", "500": "#ef4444", "600": "#dc2626", "700": "#b91c1c", "800": "#991b1b", "900": "#7f1d1d", "950": "#450a0a" },
31
- orange: { "50": "#fff7ed", "100": "#ffedd5", "200": "#fed7aa", "300": "#fdba74", "400": "#fb923c", "500": "#f97316", "600": "#ea580c", "700": "#c2410c", "800": "#9a3412", "900": "#7c2d12", "950": "#431407" },
32
- amber: { "50": "#fffbeb", "100": "#fef3c7", "200": "#fde68a", "300": "#fcd34d", "400": "#fbbf24", "500": "#f59e0b", "600": "#d97706", "700": "#b45309", "800": "#92400e", "900": "#78350f", "950": "#451a03" },
33
- yellow: { "50": "#fefce8", "100": "#fef9c3", "200": "#fef08a", "300": "#fde047", "400": "#facc15", "500": "#eab308", "600": "#ca8a04", "700": "#a16207", "800": "#854d0e", "900": "#713f12", "950": "#422006" },
34
- lime: { "50": "#f7fee7", "100": "#ecfccb", "200": "#d9f99d", "300": "#bef264", "400": "#a3e635", "500": "#84cc16", "600": "#65a30d", "700": "#4d7c0f", "800": "#3f6212", "900": "#365314", "950": "#1a2e05" },
35
- green: { "50": "#f0fdf4", "100": "#dcfce7", "200": "#bbf7d0", "300": "#86efac", "400": "#4ade80", "500": "#22c55e", "600": "#16a34a", "700": "#15803d", "800": "#166534", "900": "#14532d", "950": "#052e16" },
36
- emerald: { "50": "#ecfdf5", "100": "#d1fae5", "200": "#a7f3d0", "300": "#6ee7b7", "400": "#34d399", "500": "#10b981", "600": "#059669", "700": "#047857", "800": "#065f46", "900": "#064e3b", "950": "#022c22" },
37
- teal: { "50": "#f0fdfa", "100": "#ccfbf1", "200": "#99f6e4", "300": "#5eead4", "400": "#2dd4bf", "500": "#14b8a6", "600": "#0d9488", "700": "#0f766e", "800": "#115e59", "900": "#134e4a", "950": "#042f2e" },
38
- cyan: { "50": "#ecfeff", "100": "#cffafe", "200": "#a5f3fc", "300": "#67e8f9", "400": "#22d3ee", "500": "#06b6d4", "600": "#0891b2", "700": "#0e7490", "800": "#155e75", "900": "#164e63", "950": "#083344" },
39
- sky: { "50": "#f0f9ff", "100": "#e0f2fe", "200": "#bae6fd", "300": "#7dd3fc", "400": "#38bdf8", "500": "#0ea5e9", "600": "#0284c7", "700": "#0369a1", "800": "#075985", "900": "#0c4a6e", "950": "#082f49" },
40
- blue: { "50": "#eff6ff", "100": "#dbeafe", "200": "#bfdbfe", "300": "#93c5fd", "400": "#60a5fa", "500": "#3b82f6", "600": "#2563eb", "700": "#1d4ed8", "800": "#1e40af", "900": "#1e3a8a", "950": "#172554" },
41
- indigo: { "50": "#eef2ff", "100": "#e0e7ff", "200": "#c7d2fe", "300": "#a5b4fc", "400": "#818cf8", "500": "#6366f1", "600": "#4f46e5", "700": "#4338ca", "800": "#3730a3", "900": "#312e81", "950": "#1e1b4b" },
42
- violet: { "50": "#f5f3ff", "100": "#ede9fe", "200": "#ddd6fe", "300": "#c4b5fd", "400": "#a78bfa", "500": "#8b5cf6", "600": "#7c3aed", "700": "#6d28d9", "800": "#5b21b6", "900": "#4c1d95", "950": "#2e1065" },
43
- purple: { "50": "#faf5ff", "100": "#f3e8ff", "200": "#e9d5ff", "300": "#d8b4fe", "400": "#c084fc", "500": "#a855f7", "600": "#9333ea", "700": "#7e22ce", "800": "#6b21a8", "900": "#581c87", "950": "#3b0764" },
44
- fuchsia: { "50": "#fdf4ff", "100": "#fae8ff", "200": "#f5d0fe", "300": "#f0abfc", "400": "#e879f9", "500": "#d946ef", "600": "#c026d3", "700": "#a21caf", "800": "#86198f", "900": "#701a75", "950": "#4a044e" },
45
- pink: { "50": "#fdf2f8", "100": "#fce7f3", "200": "#fbcfe8", "300": "#f9a8d4", "400": "#f472b6", "500": "#ec4899", "600": "#db2777", "700": "#be185d", "800": "#9d174d", "900": "#831843", "950": "#500724" },
46
- rose: { "50": "#fff1f2", "100": "#ffe4e6", "200": "#fecdd3", "300": "#fda4af", "400": "#fb7185", "500": "#f43f5e", "600": "#e11d48", "700": "#be123c", "800": "#9f1239", "900": "#881337", "950": "#4c0519" },
47
- },
48
- fontSize: {
49
- xs: ["0.75rem", { lineHeight: "1rem" }],
50
- sm: ["0.875rem", { lineHeight: "1.25rem" }],
51
- base: ["1rem", { lineHeight: "1.5rem" }],
52
- lg: ["1.125rem", { lineHeight: "1.75rem" }],
53
- xl: ["1.25rem", { lineHeight: "1.75rem" }],
54
- "2xl": ["1.5rem", { lineHeight: "2rem" }],
55
- "3xl": ["1.875rem", { lineHeight: "2.25rem" }],
56
- "4xl": ["2.25rem", { lineHeight: "2.5rem" }],
57
- "5xl": ["3rem", { lineHeight: "1" }],
58
- "6xl": ["3.75rem", { lineHeight: "1" }],
59
- "7xl": ["4.5rem", { lineHeight: "1" }],
60
- "8xl": ["6rem", { lineHeight: "1" }],
61
- "9xl": ["8rem", { lineHeight: "1" }],
62
- },
63
- fontWeight: {
64
- thin: "100", extralight: "200", light: "300", normal: "400",
65
- medium: "500", semibold: "600", bold: "700", extrabold: "800", black: "900",
66
- },
67
- borderRadius: {
68
- none: "0px", sm: "0.125rem", DEFAULT: "0.25rem", md: "0.375rem",
69
- lg: "0.5rem", xl: "0.75rem", "2xl": "1rem", "3xl": "1.5rem", full: "9999px",
70
- },
15
+ spacing: {
16
+ "0": "0px",
17
+ px: "1px",
18
+ "0.5": "0.125rem",
19
+ "1": "0.25rem",
20
+ "1.5": "0.375rem",
21
+ "2": "0.5rem",
22
+ "2.5": "0.625rem",
23
+ "3": "0.75rem",
24
+ "3.5": "0.875rem",
25
+ "4": "1rem",
26
+ "5": "1.25rem",
27
+ "6": "1.5rem",
28
+ "7": "1.75rem",
29
+ "8": "2rem",
30
+ "9": "2.25rem",
31
+ "10": "2.5rem",
32
+ "11": "2.75rem",
33
+ "12": "3rem",
34
+ "14": "3.5rem",
35
+ "16": "4rem",
36
+ "20": "5rem",
37
+ "24": "6rem",
38
+ "28": "7rem",
39
+ "32": "8rem",
40
+ "36": "9rem",
41
+ "40": "10rem",
42
+ "44": "11rem",
43
+ "48": "12rem",
44
+ "52": "13rem",
45
+ "56": "14rem",
46
+ "60": "15rem",
47
+ "64": "16rem",
48
+ "72": "18rem",
49
+ "80": "20rem",
50
+ "96": "24rem",
51
+ },
52
+ colors: {
53
+ inherit: "inherit",
54
+ current: "currentColor",
55
+ transparent: "transparent",
56
+ black: "#000",
57
+ white: "#fff",
58
+ slate: {
59
+ "50": "#f8fafc",
60
+ "100": "#f1f5f9",
61
+ "200": "#e2e8f0",
62
+ "300": "#cbd5e1",
63
+ "400": "#94a3b8",
64
+ "500": "#64748b",
65
+ "600": "#475569",
66
+ "700": "#334155",
67
+ "800": "#1e293b",
68
+ "900": "#0f172a",
69
+ "950": "#020617",
70
+ },
71
+ gray: {
72
+ "50": "#f9fafb",
73
+ "100": "#f3f4f6",
74
+ "200": "#e5e7eb",
75
+ "300": "#d1d5db",
76
+ "400": "#9ca3af",
77
+ "500": "#6b7280",
78
+ "600": "#4b5563",
79
+ "700": "#374151",
80
+ "800": "#1f2937",
81
+ "900": "#111827",
82
+ "950": "#030712",
83
+ },
84
+ zinc: {
85
+ "50": "#fafafa",
86
+ "100": "#f4f4f5",
87
+ "200": "#e4e4e7",
88
+ "300": "#d4d4d8",
89
+ "400": "#a1a1aa",
90
+ "500": "#71717a",
91
+ "600": "#52525b",
92
+ "700": "#3f3f46",
93
+ "800": "#27272a",
94
+ "900": "#18181b",
95
+ "950": "#09090b",
96
+ },
97
+ neutral: {
98
+ "50": "#fafafa",
99
+ "100": "#f5f5f5",
100
+ "200": "#e5e5e5",
101
+ "300": "#d4d4d4",
102
+ "400": "#a3a3a3",
103
+ "500": "#737373",
104
+ "600": "#525252",
105
+ "700": "#404040",
106
+ "800": "#262626",
107
+ "900": "#171717",
108
+ "950": "#0a0a0a",
109
+ },
110
+ stone: {
111
+ "50": "#fafaf9",
112
+ "100": "#f5f5f4",
113
+ "200": "#e7e5e4",
114
+ "300": "#d6d3d1",
115
+ "400": "#a8a29e",
116
+ "500": "#78716c",
117
+ "600": "#57534e",
118
+ "700": "#44403c",
119
+ "800": "#292524",
120
+ "900": "#1c1917",
121
+ "950": "#0c0a09",
122
+ },
123
+ red: {
124
+ "50": "#fef2f2",
125
+ "100": "#fee2e2",
126
+ "200": "#fecaca",
127
+ "300": "#fca5a5",
128
+ "400": "#f87171",
129
+ "500": "#ef4444",
130
+ "600": "#dc2626",
131
+ "700": "#b91c1c",
132
+ "800": "#991b1b",
133
+ "900": "#7f1d1d",
134
+ "950": "#450a0a",
135
+ },
136
+ orange: {
137
+ "50": "#fff7ed",
138
+ "100": "#ffedd5",
139
+ "200": "#fed7aa",
140
+ "300": "#fdba74",
141
+ "400": "#fb923c",
142
+ "500": "#f97316",
143
+ "600": "#ea580c",
144
+ "700": "#c2410c",
145
+ "800": "#9a3412",
146
+ "900": "#7c2d12",
147
+ "950": "#431407",
148
+ },
149
+ amber: {
150
+ "50": "#fffbeb",
151
+ "100": "#fef3c7",
152
+ "200": "#fde68a",
153
+ "300": "#fcd34d",
154
+ "400": "#fbbf24",
155
+ "500": "#f59e0b",
156
+ "600": "#d97706",
157
+ "700": "#b45309",
158
+ "800": "#92400e",
159
+ "900": "#78350f",
160
+ "950": "#451a03",
161
+ },
162
+ yellow: {
163
+ "50": "#fefce8",
164
+ "100": "#fef9c3",
165
+ "200": "#fef08a",
166
+ "300": "#fde047",
167
+ "400": "#facc15",
168
+ "500": "#eab308",
169
+ "600": "#ca8a04",
170
+ "700": "#a16207",
171
+ "800": "#854d0e",
172
+ "900": "#713f12",
173
+ "950": "#422006",
174
+ },
175
+ lime: {
176
+ "50": "#f7fee7",
177
+ "100": "#ecfccb",
178
+ "200": "#d9f99d",
179
+ "300": "#bef264",
180
+ "400": "#a3e635",
181
+ "500": "#84cc16",
182
+ "600": "#65a30d",
183
+ "700": "#4d7c0f",
184
+ "800": "#3f6212",
185
+ "900": "#365314",
186
+ "950": "#1a2e05",
187
+ },
188
+ green: {
189
+ "50": "#f0fdf4",
190
+ "100": "#dcfce7",
191
+ "200": "#bbf7d0",
192
+ "300": "#86efac",
193
+ "400": "#4ade80",
194
+ "500": "#22c55e",
195
+ "600": "#16a34a",
196
+ "700": "#15803d",
197
+ "800": "#166534",
198
+ "900": "#14532d",
199
+ "950": "#052e16",
200
+ },
201
+ emerald: {
202
+ "50": "#ecfdf5",
203
+ "100": "#d1fae5",
204
+ "200": "#a7f3d0",
205
+ "300": "#6ee7b7",
206
+ "400": "#34d399",
207
+ "500": "#10b981",
208
+ "600": "#059669",
209
+ "700": "#047857",
210
+ "800": "#065f46",
211
+ "900": "#064e3b",
212
+ "950": "#022c22",
213
+ },
214
+ teal: {
215
+ "50": "#f0fdfa",
216
+ "100": "#ccfbf1",
217
+ "200": "#99f6e4",
218
+ "300": "#5eead4",
219
+ "400": "#2dd4bf",
220
+ "500": "#14b8a6",
221
+ "600": "#0d9488",
222
+ "700": "#0f766e",
223
+ "800": "#115e59",
224
+ "900": "#134e4a",
225
+ "950": "#042f2e",
226
+ },
227
+ cyan: {
228
+ "50": "#ecfeff",
229
+ "100": "#cffafe",
230
+ "200": "#a5f3fc",
231
+ "300": "#67e8f9",
232
+ "400": "#22d3ee",
233
+ "500": "#06b6d4",
234
+ "600": "#0891b2",
235
+ "700": "#0e7490",
236
+ "800": "#155e75",
237
+ "900": "#164e63",
238
+ "950": "#083344",
239
+ },
240
+ sky: {
241
+ "50": "#f0f9ff",
242
+ "100": "#e0f2fe",
243
+ "200": "#bae6fd",
244
+ "300": "#7dd3fc",
245
+ "400": "#38bdf8",
246
+ "500": "#0ea5e9",
247
+ "600": "#0284c7",
248
+ "700": "#0369a1",
249
+ "800": "#075985",
250
+ "900": "#0c4a6e",
251
+ "950": "#082f49",
252
+ },
253
+ blue: {
254
+ "50": "#eff6ff",
255
+ "100": "#dbeafe",
256
+ "200": "#bfdbfe",
257
+ "300": "#93c5fd",
258
+ "400": "#60a5fa",
259
+ "500": "#3b82f6",
260
+ "600": "#2563eb",
261
+ "700": "#1d4ed8",
262
+ "800": "#1e40af",
263
+ "900": "#1e3a8a",
264
+ "950": "#172554",
265
+ },
266
+ indigo: {
267
+ "50": "#eef2ff",
268
+ "100": "#e0e7ff",
269
+ "200": "#c7d2fe",
270
+ "300": "#a5b4fc",
271
+ "400": "#818cf8",
272
+ "500": "#6366f1",
273
+ "600": "#4f46e5",
274
+ "700": "#4338ca",
275
+ "800": "#3730a3",
276
+ "900": "#312e81",
277
+ "950": "#1e1b4b",
278
+ },
279
+ violet: {
280
+ "50": "#f5f3ff",
281
+ "100": "#ede9fe",
282
+ "200": "#ddd6fe",
283
+ "300": "#c4b5fd",
284
+ "400": "#a78bfa",
285
+ "500": "#8b5cf6",
286
+ "600": "#7c3aed",
287
+ "700": "#6d28d9",
288
+ "800": "#5b21b6",
289
+ "900": "#4c1d95",
290
+ "950": "#2e1065",
291
+ },
292
+ purple: {
293
+ "50": "#faf5ff",
294
+ "100": "#f3e8ff",
295
+ "200": "#e9d5ff",
296
+ "300": "#d8b4fe",
297
+ "400": "#c084fc",
298
+ "500": "#a855f7",
299
+ "600": "#9333ea",
300
+ "700": "#7e22ce",
301
+ "800": "#6b21a8",
302
+ "900": "#581c87",
303
+ "950": "#3b0764",
304
+ },
305
+ fuchsia: {
306
+ "50": "#fdf4ff",
307
+ "100": "#fae8ff",
308
+ "200": "#f5d0fe",
309
+ "300": "#f0abfc",
310
+ "400": "#e879f9",
311
+ "500": "#d946ef",
312
+ "600": "#c026d3",
313
+ "700": "#a21caf",
314
+ "800": "#86198f",
315
+ "900": "#701a75",
316
+ "950": "#4a044e",
317
+ },
318
+ pink: {
319
+ "50": "#fdf2f8",
320
+ "100": "#fce7f3",
321
+ "200": "#fbcfe8",
322
+ "300": "#f9a8d4",
323
+ "400": "#f472b6",
324
+ "500": "#ec4899",
325
+ "600": "#db2777",
326
+ "700": "#be185d",
327
+ "800": "#9d174d",
328
+ "900": "#831843",
329
+ "950": "#500724",
330
+ },
331
+ rose: {
332
+ "50": "#fff1f2",
333
+ "100": "#ffe4e6",
334
+ "200": "#fecdd3",
335
+ "300": "#fda4af",
336
+ "400": "#fb7185",
337
+ "500": "#f43f5e",
338
+ "600": "#e11d48",
339
+ "700": "#be123c",
340
+ "800": "#9f1239",
341
+ "900": "#881337",
342
+ "950": "#4c0519",
343
+ },
344
+ },
345
+ fontSize: {
346
+ xs: ["0.75rem", { lineHeight: "1rem" }],
347
+ sm: ["0.875rem", { lineHeight: "1.25rem" }],
348
+ base: ["1rem", { lineHeight: "1.5rem" }],
349
+ lg: ["1.125rem", { lineHeight: "1.75rem" }],
350
+ xl: ["1.25rem", { lineHeight: "1.75rem" }],
351
+ "2xl": ["1.5rem", { lineHeight: "2rem" }],
352
+ "3xl": ["1.875rem", { lineHeight: "2.25rem" }],
353
+ "4xl": ["2.25rem", { lineHeight: "2.5rem" }],
354
+ "5xl": ["3rem", { lineHeight: "1" }],
355
+ "6xl": ["3.75rem", { lineHeight: "1" }],
356
+ "7xl": ["4.5rem", { lineHeight: "1" }],
357
+ "8xl": ["6rem", { lineHeight: "1" }],
358
+ "9xl": ["8rem", { lineHeight: "1" }],
359
+ },
360
+ fontWeight: {
361
+ thin: "100",
362
+ extralight: "200",
363
+ light: "300",
364
+ normal: "400",
365
+ medium: "500",
366
+ semibold: "600",
367
+ bold: "700",
368
+ extrabold: "800",
369
+ black: "900",
370
+ },
371
+ borderRadius: {
372
+ none: "0px",
373
+ sm: "0.125rem",
374
+ DEFAULT: "0.25rem",
375
+ md: "0.375rem",
376
+ lg: "0.5rem",
377
+ xl: "0.75rem",
378
+ "2xl": "1rem",
379
+ "3xl": "1.5rem",
380
+ full: "9999px",
381
+ },
71
382
  };
72
383
 
73
384
  export class TailwindV3Adapter implements TailwindAdapter {
74
- readonly version = 3 as const;
75
-
76
- async resolveTailwindConfig(): Promise<TailwindThemeSubset> {
77
- if (cached) return cached;
78
-
79
- const cwd = process.cwd();
80
- const jsPath = resolve(cwd, "tailwind.config.js");
81
- const tsPath = resolve(cwd, "tailwind.config.ts");
82
- const cjsPath = resolve(cwd, "tailwind.config.cjs");
83
- const configPath = existsSync(jsPath)
84
- ? jsPath
85
- : existsSync(tsPath)
86
- ? tsPath
87
- : existsSync(cjsPath)
88
- ? cjsPath
89
- : null;
90
-
91
- if (configPath) {
92
- try {
93
- const req = createRequire(resolve(cwd, "package.json"));
94
- const resolveConfig = (await import(req.resolve("tailwindcss/resolveConfig"))).default;
95
- const userConfig = (await import(configPath)).default;
96
- const full = resolveConfig(userConfig);
97
- const theme = full.theme ?? {};
98
-
99
- cached = {
100
- spacing: (theme.spacing as Record<string, string>) ?? defaultTheme.spacing,
101
- colors: (theme.colors as Record<string, unknown>) ?? defaultTheme.colors,
102
- fontSize: (theme.fontSize as Record<string, unknown>) ?? defaultTheme.fontSize,
103
- fontWeight: (theme.fontWeight as Record<string, unknown>) ?? defaultTheme.fontWeight,
104
- borderRadius: (theme.borderRadius as Record<string, string>) ?? defaultTheme.borderRadius,
105
- };
106
-
107
- console.error(`[tailwind] v3 resolved config from ${configPath}`);
108
- return cached;
109
- } catch (err) {
110
- console.error("[tailwind] v3 failed to resolve config, using defaults:", err);
111
- }
112
- } else {
113
- console.error("[tailwind] v3 no tailwind.config found using defaults.");
114
- }
115
-
116
- cached = defaultTheme;
117
- return cached;
118
- }
119
-
120
- async generateCssForClasses(classes: string[]): Promise<string> {
121
- const cwd = process.cwd();
122
- const req = createRequire(resolve(cwd, "package.json"));
123
-
124
- const jsPath = resolve(cwd, "tailwind.config.js");
125
- const tsPath = resolve(cwd, "tailwind.config.ts");
126
- const cjsPath = resolve(cwd, "tailwind.config.cjs");
127
- const configPath = existsSync(jsPath)
128
- ? jsPath
129
- : existsSync(tsPath)
130
- ? tsPath
131
- : existsSync(cjsPath)
132
- ? cjsPath
133
- : null;
134
-
135
- let userConfig: object = {};
136
- if (configPath) {
137
- try {
138
- userConfig = (await import(configPath)).default;
139
- } catch {
140
- // fall through to empty config
141
- }
142
- }
143
-
144
- // Load postcss and tailwindcss as a PostCSS plugin from the target project
145
- const postcss = (await import(req.resolve("postcss"))).default;
146
- const tailwindPlugin = (await import(req.resolve("tailwindcss"))).default;
147
-
148
- const result = await postcss([
149
- tailwindPlugin({
150
- ...userConfig,
151
- content: [], // skip file scanning
152
- safelist: classes, // generate only the requested classes
153
- }),
154
- ]).process("@tailwind utilities;", { from: undefined });
155
-
156
- return result.css;
157
- }
385
+ readonly version = 3 as const;
386
+
387
+ async resolveTailwindConfig(): Promise<TailwindThemeSubset> {
388
+ if (cached) return cached;
389
+
390
+ const cwd = process.cwd();
391
+ const jsPath = resolve(cwd, "tailwind.config.js");
392
+ const tsPath = resolve(cwd, "tailwind.config.ts");
393
+ const cjsPath = resolve(cwd, "tailwind.config.cjs");
394
+ const configPath = existsSync(jsPath)
395
+ ? jsPath
396
+ : existsSync(tsPath)
397
+ ? tsPath
398
+ : existsSync(cjsPath)
399
+ ? cjsPath
400
+ : null;
401
+
402
+ if (configPath) {
403
+ try {
404
+ const req = createRequire(resolve(cwd, "package.json"));
405
+ const resolveConfig = (
406
+ await import(
407
+ pathToFileURL(req.resolve("tailwindcss/resolveConfig")).href
408
+ )
409
+ ).default;
410
+ const userConfig = (await import(pathToFileURL(configPath).href))
411
+ .default;
412
+ const full = resolveConfig(userConfig);
413
+ const theme = full.theme ?? {};
414
+
415
+ cached = {
416
+ spacing:
417
+ (theme.spacing as Record<string, string>) ?? defaultTheme.spacing,
418
+ colors:
419
+ (theme.colors as Record<string, unknown>) ?? defaultTheme.colors,
420
+ fontSize:
421
+ (theme.fontSize as Record<string, unknown>) ??
422
+ defaultTheme.fontSize,
423
+ fontWeight:
424
+ (theme.fontWeight as Record<string, unknown>) ??
425
+ defaultTheme.fontWeight,
426
+ borderRadius:
427
+ (theme.borderRadius as Record<string, string>) ??
428
+ defaultTheme.borderRadius,
429
+ };
430
+
431
+ console.error(`[tailwind] v3 resolved config from ${configPath}`);
432
+ return cached;
433
+ } catch (err) {
434
+ console.error(
435
+ "[tailwind] v3 failed to resolve config, using defaults:",
436
+ err,
437
+ );
438
+ }
439
+ } else {
440
+ console.error("[tailwind] v3 no tailwind.config found — using defaults.");
441
+ }
442
+
443
+ cached = defaultTheme;
444
+ return cached;
445
+ }
446
+
447
+ async generateCssForClasses(classes: string[]): Promise<string> {
448
+ const cwd = process.cwd();
449
+ const req = createRequire(resolve(cwd, "package.json"));
450
+
451
+ const jsPath = resolve(cwd, "tailwind.config.js");
452
+ const tsPath = resolve(cwd, "tailwind.config.ts");
453
+ const cjsPath = resolve(cwd, "tailwind.config.cjs");
454
+ const configPath = existsSync(jsPath)
455
+ ? jsPath
456
+ : existsSync(tsPath)
457
+ ? tsPath
458
+ : existsSync(cjsPath)
459
+ ? cjsPath
460
+ : null;
461
+
462
+ let userConfig: object = {};
463
+ if (configPath) {
464
+ try {
465
+ userConfig = (await import(pathToFileURL(configPath).href)).default;
466
+ } catch {
467
+ // fall through to empty config
468
+ }
469
+ }
470
+
471
+ // Load postcss and tailwindcss as a PostCSS plugin from the target project
472
+ const postcss = (await import(pathToFileURL(req.resolve("postcss")).href))
473
+ .default;
474
+ const tailwindPlugin = (
475
+ await import(pathToFileURL(req.resolve("tailwindcss")).href)
476
+ ).default;
477
+
478
+ const result = await postcss([
479
+ tailwindPlugin({
480
+ ...userConfig,
481
+ content: [], // skip file scanning
482
+ safelist: classes, // generate only the requested classes
483
+ }),
484
+ ]).process("@tailwind utilities;", { from: undefined });
485
+
486
+ return result.css;
487
+ }
158
488
  }