@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/index.cjs DELETED
@@ -1,428 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
6
- const plugin = require("tailwindcss/plugin");
7
- const fs = require("fs");
8
- const replaceInFile = require("replace-in-file");
9
- const console = require("node:console");
10
- const pathe = require("pathe");
11
- const url = require("url");
12
- const path = require("path");
13
- const theme = require("@udixio/theme");
14
- function _interopNamespaceDefault(e) {
15
- const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
16
- if (e) {
17
- for (const k in e) {
18
- if (k !== "default") {
19
- const d = Object.getOwnPropertyDescriptor(e, k);
20
- Object.defineProperty(n, k, d.get ? d : {
21
- enumerable: true,
22
- get: () => e[k]
23
- });
24
- }
25
- }
26
- }
27
- n.default = e;
28
- return Object.freeze(n);
29
- }
30
- const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
31
- const console__namespace = /* @__PURE__ */ _interopNamespaceDefault(console);
32
- const defaultConfig = {
33
- statePrefix: "state",
34
- disabledStyles: {
35
- textOpacity: 0.38,
36
- backgroundOpacity: 0.12
37
- },
38
- transition: {
39
- duration: 150
40
- }
41
- };
42
- const state = plugin.withOptions(({ colorKeys }) => {
43
- const resolved = {
44
- ...defaultConfig,
45
- disabledStyles: {
46
- ...defaultConfig.disabledStyles,
47
- ...{}
48
- },
49
- transition: {
50
- ...defaultConfig.transition,
51
- ...{}
52
- }
53
- };
54
- return ({ addComponents }) => {
55
- const newComponents = {};
56
- for (const isGroup of [false, true]) {
57
- const group = isGroup ? "group-" : "";
58
- for (const colorName of colorKeys) {
59
- const className = `.${group}${resolved.statePrefix}-${colorName}`;
60
- newComponents[className] = {
61
- [`@apply ${group}hover:bg-${colorName}/[0.08]`]: {},
62
- [`@apply ${group}active:bg-${colorName}/[0.12]`]: {},
63
- [`@apply ${group}focus-visible:bg-${colorName}/[0.12]`]: {},
64
- [`@apply transition-colors`]: {},
65
- [`@apply duration-${resolved.transition.duration}`]: {},
66
- [`@apply ${group}disabled:text-on-surface/[${resolved.disabledStyles.textOpacity}]`]: {},
67
- [`@apply ${group}disabled:bg-on-surface/[${resolved.disabledStyles.backgroundOpacity}]`]: {}
68
- };
69
- }
70
- }
71
- for (const colorName of colorKeys) {
72
- for (const stateName of ["hover", "active", "focus", "disabled"]) {
73
- const className = `.${stateName}-${resolved.statePrefix}-${colorName}`;
74
- if (stateName === "disabled") {
75
- newComponents[className] = {
76
- [`@apply text-on-surface/[${resolved.disabledStyles.textOpacity}]`]: {},
77
- [`@apply bg-on-surface/[${resolved.disabledStyles.backgroundOpacity}]`]: {}
78
- };
79
- } else {
80
- const opacity = stateName === "hover" ? 0.08 : 0.12;
81
- newComponents[className] = {
82
- [`@apply bg-${colorName}/[${opacity}]`]: {}
83
- };
84
- }
85
- }
86
- }
87
- addComponents(newComponents);
88
- };
89
- });
90
- const font = plugin.withOptions((options) => {
91
- return ({
92
- addUtilities,
93
- theme: theme2
94
- }) => {
95
- const { fontStyles, responsiveBreakPoints } = options;
96
- const pixelUnit = "rem";
97
- const newUtilities = {};
98
- const baseTextStyle = (sizeValue) => ({
99
- fontSize: sizeValue.fontSize + pixelUnit,
100
- fontWeight: sizeValue.fontWeight,
101
- lineHeight: sizeValue.lineHeight + pixelUnit,
102
- letterSpacing: sizeValue.letterSpacing ? sizeValue.letterSpacing + pixelUnit : null,
103
- fontFamily: theme2("fontFamily." + sizeValue.fontFamily)
104
- });
105
- const responsiveTextStyle = (sizeValue, breakPointName, breakPointRatio) => ({
106
- [`@media (min-width: ${theme2("screens." + breakPointName, {})})`]: {
107
- fontSize: sizeValue.fontSize * breakPointRatio + pixelUnit,
108
- lineHeight: sizeValue.lineHeight * breakPointRatio + pixelUnit
109
- }
110
- });
111
- for (const [roleName, roleValue] of Object.entries(fontStyles)) {
112
- for (const [sizeName, sizeValue] of Object.entries(roleValue)) {
113
- newUtilities[`.text-${roleName}-${sizeName}`] = {
114
- ...baseTextStyle(sizeValue),
115
- ...Object.entries(responsiveBreakPoints).reduce(
116
- (acc, [breakPointName, breakPointRatio]) => ({
117
- ...acc,
118
- ...responsiveTextStyle(
119
- sizeValue,
120
- breakPointName,
121
- breakPointRatio
122
- )
123
- }),
124
- {}
125
- )
126
- };
127
- }
128
- }
129
- addUtilities(newUtilities);
130
- };
131
- });
132
- const shadow = plugin(
133
- ({ addUtilities }) => {
134
- addUtilities({
135
- [".shadow"]: {
136
- boxShadow: "0 4px 10px #00000008, 0 0 2px #0000000f, 0 2px 6px #0000001f"
137
- },
138
- [".shadow-1"]: {
139
- boxShadow: "0px 1px 3px 1px rgba(0, 0, 0, 0.15), 0px 1px 2px 0px rgba(0, 0, 0, 0.30)"
140
- },
141
- [".shadow-2"]: {
142
- boxShadow: "0px 2px 6px 2px rgba(0, 0, 0, 0.15), 0px 1px 2px 0px rgba(0, 0, 0, 0.30)"
143
- },
144
- [".shadow-3"]: {
145
- boxShadow: "0px 1px 3px 0px rgba(0, 0, 0, 0.30), 0px 4px 8px 3px rgba(0, 0, 0, 0.15)"
146
- },
147
- [".shadow-4"]: {
148
- boxShadow: "0px 2px 3px 0px rgba(0, 0, 0, 0.30), 0px 6px 10px 4px rgba(0, 0, 0, 0.15)"
149
- },
150
- [".box-shadow-5"]: {
151
- boxShadow: "0px 4px 4px 0px rgba(0, 0, 0, 0.30), 0px 8px 12px 6px rgba(0, 0, 0, 0.15)"
152
- }
153
- });
154
- }
155
- );
156
- const main = plugin.withOptions((args) => {
157
- const configCss = args;
158
- const fontStyles = {};
159
- configCss.fontStyles.forEach((line) => {
160
- const [styleToken, ...properties] = line.split(" ");
161
- const [roleToken, sizeToken] = styleToken.split("-");
162
- fontStyles[roleToken] ?? (fontStyles[roleToken] = {});
163
- properties.forEach((properties2) => {
164
- var _a;
165
- (_a = fontStyles[roleToken])[sizeToken] ?? (_a[sizeToken] = {});
166
- const [key, value] = properties2.slice(0, -1).split("[");
167
- fontStyles[roleToken][sizeToken][key] = value;
168
- });
169
- });
170
- let breakPointsCss = configCss.responsiveBreakPoints;
171
- if (!Array.isArray(breakPointsCss)) {
172
- breakPointsCss = [breakPointsCss];
173
- }
174
- const responsiveBreakPoints = {};
175
- breakPointsCss.forEach((line) => {
176
- const [key, value] = line.split(" ");
177
- responsiveBreakPoints[key] = value;
178
- });
179
- const options = {
180
- colorKeys: configCss.colorKeys,
181
- fontStyles,
182
- responsiveBreakPoints
183
- };
184
- return (api) => {
185
- font(options).handler(api);
186
- state(options).handler(api);
187
- shadow.handler(api);
188
- };
189
- });
190
- const normalizePath = (filePath) => {
191
- try {
192
- if (filePath.startsWith("file://")) {
193
- return pathe.normalize(url.fileURLToPath(filePath));
194
- }
195
- return pathe.normalize(filePath);
196
- } catch (error) {
197
- console__namespace.warn(
198
- `Warning: Could not process path ${filePath}, treating as regular path`
199
- );
200
- return pathe.normalize(filePath);
201
- }
202
- };
203
- const safeExistsSync = (filePath) => {
204
- return fs__namespace.existsSync(normalizePath(filePath));
205
- };
206
- const safeReadFileSync = (filePath, encoding = "utf8") => {
207
- return fs__namespace.readFileSync(normalizePath(filePath), encoding);
208
- };
209
- const safeWriteFileSync = (filePath, data) => {
210
- const normalizedPath = normalizePath(filePath);
211
- const dirPath = pathe.dirname(normalizedPath);
212
- if (!fs__namespace.existsSync(dirPath)) {
213
- fs__namespace.mkdirSync(dirPath, { recursive: true });
214
- }
215
- fs__namespace.writeFileSync(normalizedPath, data);
216
- };
217
- const createOrUpdateFile = (filePath, content) => {
218
- try {
219
- const normalizedPath = normalizePath(filePath);
220
- if (!safeExistsSync(filePath)) {
221
- safeWriteFileSync(filePath, content);
222
- console__namespace.log(`✅ File successfully created: ${normalizedPath}`);
223
- } else {
224
- console__namespace.log(`⚠️ File already exists: ${normalizedPath}`);
225
- replaceFileContent(filePath, /[\s\S]*/, content);
226
- }
227
- } catch (error) {
228
- console__namespace.error("❌ Error while creating the file:", error);
229
- }
230
- };
231
- const getFileContent = (filePath, searchPattern) => {
232
- try {
233
- const normalizedPath = normalizePath(filePath);
234
- if (!safeExistsSync(filePath)) {
235
- console__namespace.error(`❌ The specified file does not exist: ${normalizedPath}`);
236
- return null;
237
- }
238
- const fileContent = safeReadFileSync(filePath);
239
- if (searchPattern) {
240
- if (typeof searchPattern === "string") {
241
- const found = fileContent.includes(searchPattern) ? searchPattern : false;
242
- console__namespace.log(
243
- found ? `✅ The file contains the specified string: "${searchPattern}"` : `⚠️ The file does NOT contain the specified string: "${searchPattern}"`
244
- );
245
- return found;
246
- } else {
247
- const match = fileContent.match(searchPattern);
248
- if (match) {
249
- console__namespace.log(`✅ Found match: "${match[0]}"`);
250
- return match[0];
251
- } else {
252
- console__namespace.log(
253
- `⚠️ No match found for the pattern: "${searchPattern.toString()}"`
254
- );
255
- return false;
256
- }
257
- }
258
- }
259
- console__namespace.log(`✅ File content successfully retrieved.`);
260
- return fileContent;
261
- } catch (error) {
262
- console__namespace.error("❌ An error occurred while processing the file:", error);
263
- return null;
264
- }
265
- };
266
- const replaceFileContent = (filePath, searchPattern, replacement) => {
267
- try {
268
- const normalizedPath = normalizePath(filePath);
269
- const results = replaceInFile.replaceInFileSync({
270
- files: normalizedPath,
271
- from: searchPattern,
272
- to: replacement
273
- });
274
- if (results.length > 0 && results[0].hasChanged) {
275
- console__namespace.log(
276
- `✅ Content successfully replaced in the file: ${normalizedPath}`
277
- );
278
- } else {
279
- console__namespace.log(
280
- `⚠️ No replacement made. Here are some possible reasons:
281
- - The pattern ${searchPattern} was not found.
282
- - The file might already contain the expected content.`
283
- );
284
- }
285
- } catch (error) {
286
- console__namespace.error("❌ Error while replacing the file content:", error);
287
- }
288
- };
289
- const findTailwindCssFile = (startDir, searchPattern) => {
290
- const normalizedStartDir = normalizePath(startDir);
291
- console__namespace.log("Recherche du fichier contenant le motif...", normalizedStartDir);
292
- const stack = [normalizedStartDir];
293
- while (stack.length > 0) {
294
- const currentDir = stack.pop();
295
- let files;
296
- try {
297
- files = fs__namespace.readdirSync(currentDir);
298
- } catch (error) {
299
- console__namespace.error(
300
- `Erreur lors de la lecture du répertoire ${currentDir}:`,
301
- error
302
- );
303
- continue;
304
- }
305
- for (const file of files) {
306
- const filePath = pathe.join(currentDir, file);
307
- let stats;
308
- try {
309
- stats = fs__namespace.statSync(filePath);
310
- } catch (error) {
311
- console__namespace.error(`Erreur lors de l'accès à ${filePath}:`, error);
312
- continue;
313
- }
314
- if (stats.isDirectory()) {
315
- if (file !== "node_modules" && !file.startsWith(".")) {
316
- stack.push(filePath);
317
- }
318
- } else if (stats.isFile() && (file.endsWith(".css") || file.endsWith(".scss") || file.endsWith(".sass"))) {
319
- try {
320
- console__namespace.log(`Analyse du fichier : ${filePath}`);
321
- const content = safeReadFileSync(filePath);
322
- const hasMatch = typeof searchPattern === "string" ? content.includes(searchPattern) : searchPattern.test(content);
323
- if (hasMatch) {
324
- console__namespace.log("Fichier trouvé :", filePath);
325
- return filePath;
326
- }
327
- } catch (readError) {
328
- console__namespace.error(`Erreur lors de la lecture de ${filePath}:`, readError);
329
- }
330
- }
331
- }
332
- }
333
- throw new Error(
334
- `Impossible de trouver un fichier contenant "${searchPattern}" dans "${normalizedStartDir}".`
335
- );
336
- };
337
- function findProjectRoot(startPath) {
338
- const normalizedStartPath = normalizePath(startPath);
339
- let currentPath = pathe.resolve(normalizedStartPath);
340
- while (!fs__namespace.existsSync(pathe.join(currentPath, "package.json"))) {
341
- const parentPath = pathe.dirname(currentPath);
342
- if (currentPath === parentPath) {
343
- throw new Error("Impossible de localiser la racine du projet.");
344
- }
345
- currentPath = parentPath;
346
- }
347
- return currentPath;
348
- }
349
- class TailwindPlugin extends theme.PluginAbstract {
350
- constructor() {
351
- super(...arguments);
352
- __publicField(this, "dependencies", [theme.FontPlugin]);
353
- __publicField(this, "name", "tailwind");
354
- __publicField(this, "pluginClass", TailwindImplPlugin);
355
- }
356
- }
357
- class TailwindImplPlugin extends theme.PluginImplAbstract {
358
- onInit() {
359
- var _a;
360
- (_a = this.options).responsiveBreakPoints ?? (_a.responsiveBreakPoints = {
361
- lg: 1.125
362
- });
363
- }
364
- onLoad() {
365
- let udixioCssPath = this.options.styleFilePath;
366
- const projectRoot = findProjectRoot(path.resolve());
367
- if (!udixioCssPath) {
368
- const searchPattern = /@import ["']tailwindcss["'];/;
369
- const replacement = `@import 'tailwindcss';
370
- @import "./udixio.css";`;
371
- const tailwindCssPath = findTailwindCssFile(projectRoot, searchPattern);
372
- udixioCssPath = path.join(tailwindCssPath, "../udixio.css");
373
- if (!getFileContent(tailwindCssPath, /@import\s+"\.\/udixio\.css";/)) {
374
- replaceFileContent(tailwindCssPath, searchPattern, replacement);
375
- }
376
- }
377
- const colors = {};
378
- for (const isDark of [false, true]) {
379
- this.api.themes.update({ isDark });
380
- for (const [key, value] of this.api.colors.getColors().entries()) {
381
- const newKey = key.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
382
- colors[newKey] ?? (colors[newKey] = { light: "", dark: "" });
383
- colors[newKey][isDark ? "dark" : "light"] = value.getHex();
384
- }
385
- }
386
- const { fontStyles, fontFamily } = this.api.plugins.getPlugin(theme.FontPlugin).getInstance().getFonts();
387
- const configCss = {
388
- colorKeys: Object.keys(colors).join(", "),
389
- fontStyles: Object.entries(fontStyles).map(
390
- ([fontRole, fontStyle]) => Object.entries(fontStyle).map(
391
- ([fontSize, fontStyle2]) => `${fontRole}-${fontSize} ${Object.entries(fontStyle2).map(([name, value]) => `${name}[${value}]`).join(" ")}`
392
- ).join(", ")
393
- ).join(", "),
394
- responsiveBreakPoints: Object.entries(
395
- this.options.responsiveBreakPoints ?? {}
396
- ).map(([key, value]) => `${key} ${value}`).join(", ")
397
- };
398
- createOrUpdateFile(
399
- udixioCssPath,
400
- `
401
- @plugin "@udixio/tailwind" {
402
- colorKeys: ${configCss.colorKeys};
403
- fontStyles: ${configCss.fontStyles};
404
- responsiveBreakPoints: ${configCss.responsiveBreakPoints};
405
- }
406
- @custom-variant dark (&:where(.dark, .dark *));
407
- @theme {
408
- --color-*: initial;
409
- ${Object.entries(colors).map(([key, value]) => `--color-${key}: ${value.light};`).join("\n ")}
410
- }
411
- @layer theme {
412
- .dark {
413
- ${Object.entries(colors).map(([key, value]) => `--color-${key}: ${value.dark};`).join("\n ")}
414
- }
415
- }
416
- @theme {
417
- ${Object.entries(fontFamily).map(
418
- ([key, values]) => `--font-${key}: ${values.map((value) => `"${value}"`).join(", ")};`
419
- ).join("\n ")}
420
- }
421
- `
422
- );
423
- }
424
- }
425
- exports.TailwindPlugin = TailwindPlugin;
426
- exports.default = main;
427
- exports.font = font;
428
- exports.state = state;
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,eAAe,IAAI,CAAC"}