@udixio/tailwind 1.3.0 → 1.5.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.
Files changed (56) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/browser/assets.d.ts +7 -0
  3. package/dist/browser/assets.d.ts.map +1 -0
  4. package/dist/browser/instrumentation.d.ts +7 -0
  5. package/dist/browser/instrumentation.d.ts.map +1 -0
  6. package/dist/browser/tailwind-browser.d.ts +2 -0
  7. package/dist/browser/tailwind-browser.d.ts.map +1 -0
  8. package/dist/browser/tailwind.plugin.d.ts +21 -0
  9. package/dist/browser/tailwind.plugin.d.ts.map +1 -0
  10. package/dist/browser.cjs +8 -0
  11. package/dist/browser.js +9 -0
  12. package/dist/index.browser.d.ts +5 -0
  13. package/dist/index.browser.d.ts.map +1 -0
  14. package/dist/{index.d.ts → index.node.d.ts} +2 -2
  15. package/dist/index.node.d.ts.map +1 -0
  16. package/dist/main.d.ts +9 -0
  17. package/dist/main.d.ts.map +1 -0
  18. package/dist/node/file.d.ts +6 -0
  19. package/dist/node/file.d.ts.map +1 -0
  20. package/dist/node/index.d.ts +3 -0
  21. package/dist/node/index.d.ts.map +1 -0
  22. package/dist/node/tailwind.plugin.d.ts +13 -0
  23. package/dist/node/tailwind.plugin.d.ts.map +1 -0
  24. package/dist/node.cjs +370 -0
  25. package/dist/node.js +332 -0
  26. package/dist/plugins-tailwind/font.d.ts +7 -0
  27. package/dist/plugins-tailwind/font.d.ts.map +1 -0
  28. package/dist/plugins-tailwind/shadow.d.ts +2 -0
  29. package/dist/plugins-tailwind/shadow.d.ts.map +1 -0
  30. package/dist/plugins-tailwind/state.d.ts +5 -0
  31. package/dist/plugins-tailwind/state.d.ts.map +1 -0
  32. package/dist/tailwind-browser-COFzjMN4.cjs +249 -0
  33. package/dist/tailwind-browser-CTGKNrKy.js +232 -0
  34. package/dist/tailwind.plugin-Ce1R9Jc0.js +222 -0
  35. package/dist/tailwind.plugin-JU5cwZvP.cjs +221 -0
  36. package/package.json +22 -10
  37. package/src/browser/assets.ts +11 -0
  38. package/src/browser/instrumentation.ts +29 -0
  39. package/src/browser/tailwind-browser.ts +327 -0
  40. package/src/browser/tailwind.plugin.ts +74 -0
  41. package/src/index.browser.ts +5 -0
  42. package/src/{index.ts → index.node.ts} +1 -1
  43. package/src/node/file.ts +340 -0
  44. package/src/node/index.ts +2 -0
  45. package/src/{tailwind.plugin.ts → node/tailwind.plugin.ts} +57 -71
  46. package/tsconfig.lib.json +1 -0
  47. package/vite.config.ts +21 -4
  48. package/dist/file.d.ts +0 -6
  49. package/dist/file.d.ts.map +0 -1
  50. package/dist/index.cjs +0 -428
  51. package/dist/index.d.ts.map +0 -1
  52. package/dist/index.js +0 -410
  53. package/dist/tailwind.plugin.d.ts +0 -16
  54. package/dist/tailwind.plugin.d.ts.map +0 -1
  55. package/src/file.ts +0 -227
  56. package/src/index.test.ts +0 -5
package/dist/node.js ADDED
@@ -0,0 +1,332 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ import { T as TailwindImplPluginBrowser, m as main } from "./tailwind.plugin-Ce1R9Jc0.js";
5
+ import { f, s } from "./tailwind.plugin-Ce1R9Jc0.js";
6
+ import { PluginAbstract, FontPlugin } from "@udixio/theme";
7
+ import * as fs from "fs";
8
+ import * as console from "node:console";
9
+ import { join, resolve, dirname, normalize } from "pathe";
10
+ import chalk from "chalk";
11
+ class TailwindPlugin extends PluginAbstract {
12
+ constructor() {
13
+ super(...arguments);
14
+ __publicField(this, "dependencies", [FontPlugin]);
15
+ __publicField(this, "name", "tailwind");
16
+ __publicField(this, "pluginClass", TailwindImplPlugin);
17
+ }
18
+ }
19
+ class TailwindImplPlugin extends TailwindImplPluginBrowser {
20
+ isNodeJs() {
21
+ return typeof process !== "undefined" && process.versions != null && process.versions.node != null;
22
+ }
23
+ async onLoad() {
24
+ var _a;
25
+ if (!this.isNodeJs()) {
26
+ await super.onLoad();
27
+ return;
28
+ }
29
+ const { join: join2, resolve: resolve2 } = await import("pathe");
30
+ const {
31
+ createOrUpdateFile: createOrUpdateFile2,
32
+ findProjectRoot: findProjectRoot2,
33
+ findTailwindCssFile: findTailwindCssFile2,
34
+ getFileContent: getFileContent2,
35
+ replaceFileContent: replaceFileContent2
36
+ } = await Promise.resolve().then(() => file);
37
+ this.colors = {};
38
+ for (const isDark of [false, true]) {
39
+ this.api.themes.update({ isDark });
40
+ for (const [key, value] of this.api.colors.getColors().entries()) {
41
+ const newKey = key.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
42
+ (_a = this.colors)[newKey] ?? (_a[newKey] = { light: "", dark: "" });
43
+ this.colors[newKey][isDark ? "dark" : "light"] = value.getHex();
44
+ }
45
+ }
46
+ let udixioCssPath = this.options.styleFilePath;
47
+ const projectRoot = await findProjectRoot2(resolve2());
48
+ if (!udixioCssPath) {
49
+ const searchPattern = /@import ["']tailwindcss["'];/;
50
+ const replacement = `@import 'tailwindcss';
51
+ @import "./udixio.css";`;
52
+ const tailwindCssPath = await findTailwindCssFile2(
53
+ projectRoot,
54
+ searchPattern
55
+ );
56
+ udixioCssPath = join2(tailwindCssPath, "../udixio.css");
57
+ if (!await getFileContent2(tailwindCssPath, /@import\s+"\.\/udixio\.css";/)) {
58
+ await replaceFileContent2(tailwindCssPath, searchPattern, replacement);
59
+ }
60
+ }
61
+ const { fontStyles, fontFamily } = this.api.plugins.getPlugin(FontPlugin).getInstance().getFonts();
62
+ const configCss = {
63
+ colorKeys: Object.keys(this.colors).join(", "),
64
+ fontStyles: Object.entries(fontStyles).map(
65
+ ([fontRole, fontStyle]) => Object.entries(fontStyle).map(
66
+ ([fontSize, fontStyle2]) => `${fontRole}-${fontSize} ${Object.entries(fontStyle2).map(([name, value]) => `${name}[${value}]`).join(" ")}`
67
+ ).join(", ")
68
+ ).join(", "),
69
+ responsiveBreakPoints: Object.entries(
70
+ this.options.responsiveBreakPoints ?? {}
71
+ ).map(([key, value]) => `${key} ${value}`).join(", ")
72
+ };
73
+ this.outputCss += `@plugin "@udixio/tailwind" {
74
+ colorKeys: ${configCss.colorKeys};
75
+ fontStyles: ${configCss.fontStyles};
76
+ responsiveBreakPoints: ${configCss.responsiveBreakPoints};
77
+ }`;
78
+ this.loadColor();
79
+ this.outputCss += `
80
+ @theme {
81
+ ${Object.entries(fontFamily).map(
82
+ ([key, values]) => `--font-${key}: ${values.map((value) => `"${value}"`).join(", ")};`
83
+ ).join("\n ")}
84
+ }`;
85
+ await createOrUpdateFile2(udixioCssPath, this.outputCss);
86
+ }
87
+ }
88
+ const normalizePath = async (filePath) => {
89
+ const { fileURLToPath } = await import("url");
90
+ try {
91
+ if (filePath.startsWith("file://")) {
92
+ return normalize(fileURLToPath(filePath));
93
+ }
94
+ return normalize(filePath);
95
+ } catch (error) {
96
+ console.warn(
97
+ chalk.yellow(
98
+ `⚠️ Could not process path ${filePath}, treating as regular path`
99
+ )
100
+ );
101
+ return normalize(filePath);
102
+ }
103
+ };
104
+ const safeExistsSync = async (filePath) => {
105
+ return fs.existsSync(await normalizePath(filePath));
106
+ };
107
+ const safeReadFileSync = async (filePath, encoding = "utf8") => {
108
+ return fs.readFileSync(await normalizePath(filePath), encoding);
109
+ };
110
+ const safeWriteFileSync = async (filePath, data) => {
111
+ const normalizedPath = await normalizePath(filePath);
112
+ const dirPath = dirname(normalizedPath);
113
+ if (!fs.existsSync(dirPath)) {
114
+ fs.mkdirSync(dirPath, { recursive: true });
115
+ }
116
+ fs.writeFileSync(normalizedPath, data);
117
+ };
118
+ const createOrUpdateFile = async (filePath, content) => {
119
+ try {
120
+ const normalizedPath = normalizePath(filePath);
121
+ if (!await safeExistsSync(filePath)) {
122
+ await safeWriteFileSync(filePath, content);
123
+ console.log(
124
+ chalk.green(`📄 Created`) + chalk.gray(` • `) + chalk.cyan(normalizedPath)
125
+ );
126
+ } else {
127
+ console.log(
128
+ chalk.blue(`📝 Exists`) + chalk.gray(` • `) + chalk.cyan(normalizedPath)
129
+ );
130
+ await replaceFileContent(filePath, /[\s\S]*/, content);
131
+ }
132
+ } catch (error) {
133
+ console.error(
134
+ chalk.red(`🚨 Failed to create file`) + chalk.gray(` • `) + chalk.cyan(filePath)
135
+ );
136
+ console.error(
137
+ chalk.gray(` `) + chalk.red(error instanceof Error ? error.message : error)
138
+ );
139
+ }
140
+ };
141
+ const getFileContent = async (filePath, searchPattern) => {
142
+ try {
143
+ const normalizedPath = normalizePath(filePath);
144
+ if (!await safeExistsSync(filePath)) {
145
+ console.error(
146
+ chalk.red(`❌ File not found`) + chalk.gray(` • `) + chalk.cyan(normalizedPath)
147
+ );
148
+ return null;
149
+ }
150
+ const fileContent = await safeReadFileSync(filePath);
151
+ if (searchPattern) {
152
+ if (typeof searchPattern === "string") {
153
+ const found = fileContent.includes(searchPattern) ? searchPattern : false;
154
+ if (found) {
155
+ console.log(
156
+ chalk.green(`🔍 Found`) + chalk.gray(` • `) + chalk.yellow(`"${searchPattern}"`)
157
+ );
158
+ } else {
159
+ console.log(
160
+ chalk.yellow(`🔍 Missing`) + chalk.gray(` • `) + chalk.yellow(`"${searchPattern}"`)
161
+ );
162
+ }
163
+ return found;
164
+ } else {
165
+ const match = fileContent.match(searchPattern);
166
+ if (match) {
167
+ console.log(
168
+ chalk.green(`🎯 Match`) + chalk.gray(` • `) + chalk.yellow(`"${match[0]}"`)
169
+ );
170
+ return match[0];
171
+ } else {
172
+ console.log(
173
+ chalk.yellow(`🎯 No match`) + chalk.gray(` • `) + chalk.magenta(searchPattern.toString())
174
+ );
175
+ return false;
176
+ }
177
+ }
178
+ }
179
+ console.log(
180
+ chalk.blue(`📖 Read`) + chalk.gray(` • `) + chalk.cyan(normalizedPath)
181
+ );
182
+ return fileContent;
183
+ } catch (error) {
184
+ console.error(
185
+ chalk.red(`🚨 Read failed`) + chalk.gray(` • `) + chalk.cyan(filePath)
186
+ );
187
+ console.error(
188
+ chalk.gray(` `) + chalk.red(error instanceof Error ? error.message : error)
189
+ );
190
+ return null;
191
+ }
192
+ };
193
+ const replaceFileContent = async (filePath, searchPattern, replacement) => {
194
+ try {
195
+ const { replaceInFileSync } = await import("replace-in-file");
196
+ const normalizedPath = await normalizePath(filePath);
197
+ const results = replaceInFileSync({
198
+ files: normalizedPath,
199
+ from: searchPattern,
200
+ to: replacement
201
+ });
202
+ if (results.length > 0 && results[0].hasChanged) {
203
+ console.log(
204
+ chalk.green(`✏️ Updated`) + chalk.gray(` • `) + chalk.cyan(normalizedPath)
205
+ );
206
+ } else {
207
+ console.log(
208
+ chalk.yellow(`⏭️ Skipped`) + chalk.gray(` • `) + chalk.cyan(normalizedPath) + chalk.gray(` (no changes needed)`)
209
+ );
210
+ }
211
+ } catch (error) {
212
+ console.error(
213
+ chalk.red(`🚨 Update failed`) + chalk.gray(` • `) + chalk.cyan(filePath)
214
+ );
215
+ console.error(
216
+ chalk.gray(` `) + chalk.red(error instanceof Error ? error.message : error)
217
+ );
218
+ }
219
+ };
220
+ const findTailwindCssFile = async (startDir, searchPattern) => {
221
+ const normalizedStartDir = await normalizePath(startDir);
222
+ console.log(chalk.blue(`🔎 Searching for CSS file...`));
223
+ console.log(
224
+ chalk.gray(` Starting from: `) + chalk.cyan(normalizedStartDir)
225
+ );
226
+ const stack = [normalizedStartDir];
227
+ let filesScanned = 0;
228
+ while (stack.length > 0) {
229
+ const currentDir = stack.pop();
230
+ let files;
231
+ try {
232
+ files = fs.readdirSync(currentDir);
233
+ } catch (error) {
234
+ console.error(
235
+ chalk.gray(` `) + chalk.red(`❌ Cannot read directory: `) + chalk.cyan(currentDir)
236
+ );
237
+ continue;
238
+ }
239
+ for (const file2 of files) {
240
+ const filePath = join(currentDir, file2);
241
+ let stats;
242
+ try {
243
+ stats = fs.statSync(filePath);
244
+ } catch (error) {
245
+ console.error(
246
+ chalk.gray(` `) + chalk.red(`❌ Cannot access: `) + chalk.cyan(filePath)
247
+ );
248
+ continue;
249
+ }
250
+ if (stats.isDirectory()) {
251
+ if (file2 !== "node_modules" && !file2.startsWith(".")) {
252
+ stack.push(filePath);
253
+ }
254
+ } else if (stats.isFile() && (file2.endsWith(".css") || file2.endsWith(".scss") || file2.endsWith(".sass"))) {
255
+ try {
256
+ filesScanned++;
257
+ process.stdout.write(
258
+ chalk.gray(` 📂 Scanning: `) + chalk.yellow(file2) + `\r`
259
+ );
260
+ const content = await safeReadFileSync(filePath);
261
+ const hasMatch = typeof searchPattern === "string" ? content.includes(searchPattern) : searchPattern.test(content);
262
+ if (hasMatch) {
263
+ console.log(chalk.green(`
264
+ 🎯 Found target file!`));
265
+ console.log(chalk.gray(` 📍 Location: `) + chalk.cyan(filePath));
266
+ return filePath;
267
+ }
268
+ } catch (readError) {
269
+ console.error(
270
+ chalk.gray(`
271
+ `) + chalk.red(`❌ Cannot read: `) + chalk.cyan(filePath)
272
+ );
273
+ }
274
+ }
275
+ }
276
+ }
277
+ console.log(
278
+ chalk.blue(`
279
+ 📊 Scanned `) + chalk.white.bold(filesScanned.toString()) + chalk.blue(` CSS files`)
280
+ );
281
+ const errorMsg = chalk.red(`❌ No file found containing `) + chalk.yellow(`"${searchPattern}"`) + chalk.red(` in `) + chalk.cyan(`"${normalizedStartDir}"`);
282
+ throw new Error(errorMsg);
283
+ };
284
+ async function findProjectRoot(startPath) {
285
+ const normalizedStartPath = await normalizePath(startPath);
286
+ let currentPath = resolve(normalizedStartPath);
287
+ let levels = 0;
288
+ console.log(chalk.blue(`🏠 Finding project root...`));
289
+ console.log(
290
+ chalk.gray(` Starting from: `) + chalk.cyan(normalizedStartPath)
291
+ );
292
+ while (!fs.existsSync(join(currentPath, "package.json"))) {
293
+ const parentPath = dirname(currentPath);
294
+ if (currentPath === parentPath) {
295
+ console.error(
296
+ chalk.red(`❌ Project root not found after checking `) + chalk.white.bold(levels.toString()) + chalk.red(` levels`)
297
+ );
298
+ throw new Error(
299
+ chalk.red("Unable to locate project root (no package.json found)")
300
+ );
301
+ }
302
+ currentPath = parentPath;
303
+ levels++;
304
+ if (levels > 10) {
305
+ console.error(
306
+ chalk.red(`❌ Stopped after `) + chalk.white.bold(levels.toString()) + chalk.red(` levels (too deep)`)
307
+ );
308
+ throw new Error(chalk.red("Project root search exceeded maximum depth"));
309
+ }
310
+ }
311
+ console.log(chalk.green(`📁 Project root: `) + chalk.cyan(currentPath));
312
+ return currentPath;
313
+ }
314
+ const file = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
315
+ __proto__: null,
316
+ createOrUpdateFile,
317
+ findProjectRoot,
318
+ findTailwindCssFile,
319
+ getFileContent,
320
+ replaceFileContent
321
+ }, Symbol.toStringTag, { value: "Module" }));
322
+ export {
323
+ TailwindPlugin,
324
+ createOrUpdateFile,
325
+ main as default,
326
+ findProjectRoot,
327
+ findTailwindCssFile,
328
+ f as font,
329
+ getFileContent,
330
+ replaceFileContent,
331
+ s as state
332
+ };
@@ -0,0 +1,7 @@
1
+ import { FontRole, FontSize, FontStyle } from '@udixio/theme';
2
+ export interface FontPluginOptions {
3
+ fontStyles: Record<FontRole, Record<FontSize, FontStyle>>;
4
+ responsiveBreakPoints: Record<string, number>;
5
+ }
6
+ export declare const font: import('node_modules/tailwindcss/dist/types-WlZgYgM8.mjs').c<FontPluginOptions>;
7
+ //# sourceMappingURL=font.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"font.d.ts","sourceRoot":"","sources":["../../src/plugins-tailwind/font.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG9D,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;IAC1D,qBAAqB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/C;AAED,eAAO,MAAM,IAAI,iFAoDf,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const shadow: import('node_modules/tailwindcss/dist/types-WlZgYgM8.mjs').b;
2
+ //# sourceMappingURL=shadow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shadow.d.ts","sourceRoot":"","sources":["../../src/plugins-tailwind/shadow.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM,8DA6BlB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export type StateOptions = {
2
+ colorKeys: string[];
3
+ };
4
+ export declare const state: import('node_modules/tailwindcss/dist/types-WlZgYgM8.mjs').c<StateOptions>;
5
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/plugins-tailwind/state.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,YAAY,GAAG;IACzB,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAeF,eAAO,MAAM,KAAK,4EAuDhB,CAAC"}