@udixio/tailwind 0.5.3 → 1.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.
- package/.eslintrc.mjs +22 -0
- package/CHANGELOG.md +65 -0
- package/{src → dist}/file.d.ts +2 -1
- package/dist/file.d.ts.map +1 -0
- package/dist/index.cjs +360 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +342 -0
- package/dist/plugins-tailwind/index.d.ts.map +1 -0
- package/{src → dist}/tailwind.plugin.d.ts +1 -2
- package/dist/tailwind.plugin.d.ts.map +1 -0
- package/package.json +11 -7
- package/src/file.ts +163 -0
- package/src/index.test.ts +5 -0
- package/src/index.ts +5 -0
- package/src/main.ts +52 -0
- package/src/plugins-tailwind/font.ts +61 -0
- package/src/plugins-tailwind/index.ts +2 -0
- package/src/plugins-tailwind/state.ts +75 -0
- package/src/tailwind.plugin.ts +133 -0
- package/tsconfig.json +16 -0
- package/tsconfig.lib.json +37 -0
- package/tsconfig.spec.json +36 -0
- package/vite.config.ts +54 -0
- package/index.cjs +0 -313
- package/index.js +0 -296
- package/src/file.d.ts.map +0 -1
- package/src/index.d.ts +0 -6
- package/src/index.d.ts.map +0 -1
- package/src/main.d.ts +0 -3
- package/src/main.d.ts.map +0 -1
- package/src/plugins-tailwind/font.d.ts +0 -4
- package/src/plugins-tailwind/font.d.ts.map +0 -1
- package/src/plugins-tailwind/index.d.ts.map +0 -1
- package/src/plugins-tailwind/state.d.ts +0 -3
- package/src/plugins-tailwind/state.d.ts.map +0 -1
- package/src/tailwind.plugin.d.ts.map +0 -1
- /package/{LICENSE → dist/LICENSE} +0 -0
- /package/{src → dist}/plugins-tailwind/index.d.ts +0 -0
package/index.js
DELETED
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
import { PluginAbstract, FontPlugin, PluginImplAbstract, bootstrapFromConfig } from "@udixio/theme";
|
|
2
|
-
import plugin from "tailwindcss/plugin";
|
|
3
|
-
import * as fs from "fs";
|
|
4
|
-
import * as path from "path";
|
|
5
|
-
import path__default from "path";
|
|
6
|
-
import { replaceInFileSync } from "replace-in-file";
|
|
7
|
-
const createOrUpdateFile = (filePath, content) => {
|
|
8
|
-
try {
|
|
9
|
-
if (!fs.existsSync(filePath)) {
|
|
10
|
-
const dirPath = path.dirname(filePath);
|
|
11
|
-
if (!fs.existsSync(dirPath)) {
|
|
12
|
-
fs.mkdirSync(dirPath, { recursive: true });
|
|
13
|
-
}
|
|
14
|
-
fs.writeFileSync(filePath, content);
|
|
15
|
-
console.log(`✅ File successfully created: ${filePath}`);
|
|
16
|
-
} else {
|
|
17
|
-
console.log(`⚠️ File already exists: ${filePath}`);
|
|
18
|
-
replaceFileContent(filePath, /[\s\S]*/, content);
|
|
19
|
-
}
|
|
20
|
-
} catch (error) {
|
|
21
|
-
console.error("❌ Error while creating the file:", error);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
const getFileContent = (filePath, searchPattern) => {
|
|
25
|
-
try {
|
|
26
|
-
if (!fs.existsSync(filePath)) {
|
|
27
|
-
console.error(`❌ The specified file does not exist: ${filePath}`);
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
const fileContent = fs.readFileSync(filePath, "utf8");
|
|
31
|
-
if (searchPattern) {
|
|
32
|
-
if (typeof searchPattern === "string") {
|
|
33
|
-
const found = fileContent.includes(searchPattern) ? searchPattern : false;
|
|
34
|
-
console.log(
|
|
35
|
-
found ? `✅ The file contains the specified string: "${searchPattern}"` : `⚠️ The file does NOT contain the specified string: "${searchPattern}"`
|
|
36
|
-
);
|
|
37
|
-
return found;
|
|
38
|
-
} else {
|
|
39
|
-
const match = fileContent.match(searchPattern);
|
|
40
|
-
if (match) {
|
|
41
|
-
console.log(`✅ Found match: "${match[0]}"`);
|
|
42
|
-
return match[0];
|
|
43
|
-
} else {
|
|
44
|
-
console.log(
|
|
45
|
-
`⚠️ No match found for the pattern: "${searchPattern.toString()}"`
|
|
46
|
-
);
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
console.log(`✅ File content successfully retrieved.`);
|
|
52
|
-
return fileContent;
|
|
53
|
-
} catch (error) {
|
|
54
|
-
console.error("❌ An error occurred while processing the file:", error);
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
const replaceFileContent = (filePath, searchPattern, replacement) => {
|
|
59
|
-
try {
|
|
60
|
-
const results = replaceInFileSync({
|
|
61
|
-
files: filePath,
|
|
62
|
-
from: searchPattern,
|
|
63
|
-
to: replacement
|
|
64
|
-
});
|
|
65
|
-
if (results.length > 0 && results[0].hasChanged) {
|
|
66
|
-
console.log(`✅ Content successfully replaced in the file: ${filePath}`);
|
|
67
|
-
} else {
|
|
68
|
-
console.log(
|
|
69
|
-
`⚠️ No replacement made. Here are some possible reasons:
|
|
70
|
-
- The pattern ${searchPattern} was not found.
|
|
71
|
-
- The file might already contain the expected content.`
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
} catch (error) {
|
|
75
|
-
console.error("❌ Error while replacing the file content:", error);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
const findTailwindCssFile = (startDir, searchPattern) => {
|
|
79
|
-
const files = fs.readdirSync(startDir);
|
|
80
|
-
for (const file of files) {
|
|
81
|
-
const filePath = path.join(startDir, file);
|
|
82
|
-
const stats = fs.statSync(filePath);
|
|
83
|
-
if (stats.isDirectory()) {
|
|
84
|
-
const result = findTailwindCssFile(filePath, searchPattern);
|
|
85
|
-
if (result) return result;
|
|
86
|
-
} else if (file.endsWith(".css") || file.endsWith(".scss") || file.endsWith(".sass")) {
|
|
87
|
-
const content = fs.readFileSync(filePath, "utf8");
|
|
88
|
-
if (content.includes(searchPattern)) {
|
|
89
|
-
console.log("File found:\n", filePath);
|
|
90
|
-
return filePath;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return null;
|
|
95
|
-
};
|
|
96
|
-
const state = (colorKeys) => plugin((pluginArgs) => {
|
|
97
|
-
addAllNewComponents(
|
|
98
|
-
pluginArgs,
|
|
99
|
-
{
|
|
100
|
-
statePrefix: "state",
|
|
101
|
-
disabledStyles: {
|
|
102
|
-
textOpacity: 0.38,
|
|
103
|
-
backgroundOpacity: 0.12
|
|
104
|
-
},
|
|
105
|
-
transition: {
|
|
106
|
-
duration: 150
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
colorKeys
|
|
110
|
-
);
|
|
111
|
-
}, {});
|
|
112
|
-
const addAllNewComponents = ({ addComponents }, { statePrefix, disabledStyles, transition }, colorKeys) => {
|
|
113
|
-
const newComponents = {};
|
|
114
|
-
for (const isGroup of [false, true]) {
|
|
115
|
-
const group = isGroup ? "group-" : "";
|
|
116
|
-
for (const colorName of colorKeys) {
|
|
117
|
-
const className = `.${group}${statePrefix}-${colorName}`;
|
|
118
|
-
newComponents[className] = {
|
|
119
|
-
[`@apply ${group}hover:bg-${colorName}/[0.08]`]: {},
|
|
120
|
-
[`@apply ${group}active:bg-${colorName}/[0.12]`]: {},
|
|
121
|
-
[`@apply ${group}focus-visible:bg-${colorName}/[0.12]`]: {}
|
|
122
|
-
};
|
|
123
|
-
if (transition) {
|
|
124
|
-
newComponents[className][`@apply transition-colors`] = {};
|
|
125
|
-
newComponents[className][`@apply duration-${transition.duration}`] = {};
|
|
126
|
-
}
|
|
127
|
-
if (disabledStyles) {
|
|
128
|
-
newComponents[className][`@apply ${group}disabled:text-on-surface/[${disabledStyles.textOpacity}]`] = {};
|
|
129
|
-
newComponents[className][`@apply ${group}disabled:bg-on-surface/[${disabledStyles.backgroundOpacity}]`] = {};
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
for (const colorName of colorKeys) {
|
|
134
|
-
for (const stateName of ["hover", "active", "focus", "disabled"]) {
|
|
135
|
-
const className = `.${stateName}-${statePrefix}-${colorName}`;
|
|
136
|
-
if (stateName === "active" || stateName === "focus") {
|
|
137
|
-
newComponents[className] = {
|
|
138
|
-
[`@apply bg-${colorName}/[0.12]`]: {}
|
|
139
|
-
};
|
|
140
|
-
} else if (stateName === "hover") {
|
|
141
|
-
newComponents[className] = {
|
|
142
|
-
[`@apply bg-${colorName}/[0.08]`]: {}
|
|
143
|
-
};
|
|
144
|
-
} else if (stateName === "disabled") {
|
|
145
|
-
newComponents[className] = {
|
|
146
|
-
[`@apply text-on-surface/[${disabledStyles.textOpacity}]`]: {}
|
|
147
|
-
};
|
|
148
|
-
newComponents[className] = {
|
|
149
|
-
[`@apply bg-on-surface/[${disabledStyles.backgroundOpacity}]`]: {}
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
addComponents(newComponents);
|
|
155
|
-
};
|
|
156
|
-
const font = (fontStyles, responsiveBreakPoints) => {
|
|
157
|
-
const createUtilities = ({ theme }) => {
|
|
158
|
-
const pixelUnit = "rem";
|
|
159
|
-
const newUtilities = {};
|
|
160
|
-
const baseTextStyle = (sizeValue) => ({
|
|
161
|
-
fontSize: sizeValue.fontSize + pixelUnit,
|
|
162
|
-
fontWeight: sizeValue.fontWeight,
|
|
163
|
-
lineHeight: sizeValue.lineHeight + pixelUnit,
|
|
164
|
-
letterSpacing: sizeValue.letterSpacing ? sizeValue.letterSpacing + pixelUnit : null,
|
|
165
|
-
fontFamily: theme("fontFamily." + sizeValue.fontFamily)
|
|
166
|
-
});
|
|
167
|
-
const responsiveTextStyle = (sizeValue, breakPointName, breakPointRatio) => ({
|
|
168
|
-
[`@media (min-width: ${theme("screens." + breakPointName, {})})`]: {
|
|
169
|
-
fontSize: sizeValue.fontSize * breakPointRatio + pixelUnit,
|
|
170
|
-
lineHeight: sizeValue.lineHeight * breakPointRatio + pixelUnit
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
for (const [roleName, roleValue] of Object.entries(fontStyles)) {
|
|
174
|
-
for (const [sizeName, sizeValue] of Object.entries(roleValue)) {
|
|
175
|
-
newUtilities[".text-" + roleName + "-" + sizeName] = {
|
|
176
|
-
...baseTextStyle(sizeValue),
|
|
177
|
-
...Object.entries(responsiveBreakPoints).reduce(
|
|
178
|
-
(acc, [breakPointName, breakPointRatio]) => {
|
|
179
|
-
acc = {
|
|
180
|
-
...acc,
|
|
181
|
-
...responsiveTextStyle(
|
|
182
|
-
sizeValue,
|
|
183
|
-
breakPointName,
|
|
184
|
-
breakPointRatio
|
|
185
|
-
)
|
|
186
|
-
};
|
|
187
|
-
return acc;
|
|
188
|
-
},
|
|
189
|
-
{}
|
|
190
|
-
)
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
return newUtilities;
|
|
195
|
-
};
|
|
196
|
-
return plugin(
|
|
197
|
-
({
|
|
198
|
-
addUtilities,
|
|
199
|
-
theme
|
|
200
|
-
}) => {
|
|
201
|
-
const newUtilities = createUtilities({ theme });
|
|
202
|
-
addUtilities(newUtilities);
|
|
203
|
-
}
|
|
204
|
-
);
|
|
205
|
-
};
|
|
206
|
-
class TailwindPlugin extends PluginAbstract {
|
|
207
|
-
constructor() {
|
|
208
|
-
super(...arguments);
|
|
209
|
-
this.dependencies = [FontPlugin];
|
|
210
|
-
this.name = "tailwind";
|
|
211
|
-
this.pluginClass = TailwindImplPlugin;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
class TailwindImplPlugin extends PluginImplAbstract {
|
|
215
|
-
onInit() {
|
|
216
|
-
var _a;
|
|
217
|
-
(_a = this.options).responsiveBreakPoints ?? (_a.responsiveBreakPoints = {
|
|
218
|
-
lg: 1.125
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
load() {
|
|
222
|
-
const searchKeyword = '@plugin "@udixio/tailwind"';
|
|
223
|
-
const tailwindCssPath = this.options.styleFilePath ?? findTailwindCssFile(process.cwd(), searchKeyword);
|
|
224
|
-
if (!tailwindCssPath) {
|
|
225
|
-
throw new Error(
|
|
226
|
-
'The style file containing the Udixio plugin was not found.\n Please use it first. (@plugin "@udixio/tailwind")'
|
|
227
|
-
);
|
|
228
|
-
}
|
|
229
|
-
const searchPattern = /@import ["']tailwindcss["'];/;
|
|
230
|
-
const replacement = `@import 'tailwindcss';
|
|
231
|
-
@import "./udixio.css";`;
|
|
232
|
-
if (!getFileContent(tailwindCssPath, /@import\s+"\.\/udixio\.css";/)) {
|
|
233
|
-
replaceFileContent(tailwindCssPath, searchPattern, replacement);
|
|
234
|
-
}
|
|
235
|
-
const cssFilePath = path__default.dirname(tailwindCssPath);
|
|
236
|
-
const colors = {};
|
|
237
|
-
for (const isDark of [false, true]) {
|
|
238
|
-
this.api.themes.update({ isDark });
|
|
239
|
-
for (const [key, value] of this.api.colors.getColors().entries()) {
|
|
240
|
-
const newKey = key.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
|
|
241
|
-
colors[newKey] ?? (colors[newKey] = { light: "", dark: "" });
|
|
242
|
-
colors[newKey][isDark ? "dark" : "light"] = value.getHex();
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
const { fontStyles, fontFamily } = this.api.plugins.getPlugin(FontPlugin).getInstance().getFonts();
|
|
246
|
-
createOrUpdateFile(
|
|
247
|
-
path__default.join(cssFilePath, "udixio.css"),
|
|
248
|
-
`
|
|
249
|
-
@custom-variant dark (&:where(.dark, .dark *));
|
|
250
|
-
@theme {
|
|
251
|
-
--color-*: initial;
|
|
252
|
-
${Object.entries(colors).map(([key, value]) => `--color-${key}: ${value.light};`).join("\n ")}
|
|
253
|
-
}
|
|
254
|
-
@layer theme {
|
|
255
|
-
.dark {
|
|
256
|
-
${Object.entries(colors).map(([key, value]) => `--color-${key}: ${value.dark};`).join("\n ")}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
`
|
|
260
|
-
);
|
|
261
|
-
const plugins = [
|
|
262
|
-
state(Object.keys(colors)),
|
|
263
|
-
font(fontStyles, this.options.responsiveBreakPoints)
|
|
264
|
-
];
|
|
265
|
-
return plugin.withOptions(
|
|
266
|
-
// 1) factory(options) → la fonction “handler” du plugin
|
|
267
|
-
(options = {}) => {
|
|
268
|
-
return async function(api) {
|
|
269
|
-
plugins.forEach((plugin2) => {
|
|
270
|
-
plugin2.handler(api);
|
|
271
|
-
});
|
|
272
|
-
};
|
|
273
|
-
},
|
|
274
|
-
// 2) config(options) → objet à merger dans tailwind.config
|
|
275
|
-
(options = {}) => {
|
|
276
|
-
return {
|
|
277
|
-
theme: {
|
|
278
|
-
fontFamily
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
const createTheme = async () => {
|
|
286
|
-
const app = await bootstrapFromConfig();
|
|
287
|
-
const plugin2 = app.plugins.getPlugin(TailwindPlugin).getInstance();
|
|
288
|
-
return plugin2.load();
|
|
289
|
-
};
|
|
290
|
-
export {
|
|
291
|
-
TailwindPlugin,
|
|
292
|
-
createTheme,
|
|
293
|
-
createTheme as default,
|
|
294
|
-
font,
|
|
295
|
-
state
|
|
296
|
-
};
|
package/src/file.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../../../packages/tailwind/src/file.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,kBAAkB,GAAI,UAAU,MAAM,EAAE,SAAS,MAAM,KAAG,IAmBtE,CAAC;AAEF,eAAO,MAAM,cAAc,GACzB,UAAU,MAAM,EAChB,gBAAgB,MAAM,GAAG,MAAM,KAC9B,MAAM,GAAG,KAAK,GAAG,IA4CnB,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,UAAU,MAAM,EAChB,eAAe,MAAM,GAAG,MAAM,EAC9B,aAAa,MAAM,KAClB,IAkBF,CAAC;AACF,eAAO,MAAM,mBAAmB,GAC9B,UAAU,MAAM,EAChB,eAAe,MAAM,KACpB,MAAM,GAAG,IAyBX,CAAC"}
|
package/src/index.d.ts
DELETED
package/src/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/tailwind/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,cAAc,QAAQ,CAAC;AACvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,eAAe,WAAW,CAAC"}
|
package/src/main.d.ts
DELETED
package/src/main.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../../packages/tailwind/src/main.ts"],"names":[],"mappings":"AAEA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AAExC,eAAO,MAAM,WAAW,EAAE,MAAM,OAAO,CACrC,UAAU,CAAC,OAAO,MAAM,CAAC,WAAW,CAAC,CAKtC,CAAC"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { FontRole, FontSize, FontStyle } from '@udixio/theme';
|
|
2
|
-
import { default as plugin } from 'tailwindcss/plugin';
|
|
3
|
-
export declare const font: (fontStyles: Record<FontRole, Record<FontSize, FontStyle>>, responsiveBreakPoints: Record<string, number>) => ReturnType<typeof plugin>;
|
|
4
|
-
//# sourceMappingURL=font.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"font.d.ts","sourceRoot":"","sources":["../../../../../packages/tailwind/src/plugins-tailwind/font.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,MAAqB,MAAM,oBAAoB,CAAC;AAEvD,eAAO,MAAM,IAAI,EAAE,CACjB,UAAU,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,EACzD,qBAAqB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAC1C,UAAU,CAAC,OAAO,MAAM,CA2D5B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/tailwind/src/plugins-tailwind/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../../../packages/tailwind/src/plugins-tailwind/state.ts"],"names":[],"mappings":"AACA,OAAO,MAAqB,MAAM,oBAAoB,CAAC;AAevD,eAAO,MAAM,KAAK,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,UAAU,CAAC,OAAO,MAAM,CAkB7D,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tailwind.plugin.d.ts","sourceRoot":"","sources":["../../../../packages/tailwind/src/tailwind.plugin.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AAUxC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAE/E,UAAU,qBAAqB;IAE7B,qBAAqB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/C,aAAa,CAAC,EAAE,MAAM,CAAC;CAExB;AAED,qBAAa,cAAe,SAAQ,cAAc,CAChD,kBAAkB,EAClB,qBAAqB,CACtB;IACQ,YAAY,wBAAgB;IAC5B,IAAI,SAAc;IACzB,WAAW,4BAAsB;CAClC;AAED,cAAM,kBAAmB,SAAQ,kBAAkB,CAAC,qBAAqB,CAAC;IACxE,MAAM;IAMN,IAAI,IAAI,UAAU,CAAC,OAAO,MAAM,CAAC,WAAW,CAAC;CAwF9C"}
|
|
File without changes
|
|
File without changes
|