@udixio/tailwind 1.2.1 → 1.4.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,239 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
+ // If the importer is in node compatibility mode or this is not an ESM
19
+ // file that has been converted to a CommonJS file using a Babel-
20
+ // compatible transform (i.e. "__esModule" has not been set), then set
21
+ // "default" to the CommonJS "module.exports" for node compatibility.
22
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
+ mod
24
+ ));
25
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
26
+ const plugin = require("tailwindcss/plugin");
27
+ const theme = require("@udixio/theme");
28
+ const defaultConfig = {
29
+ statePrefix: "state",
30
+ disabledStyles: {
31
+ textOpacity: 0.38,
32
+ backgroundOpacity: 0.12
33
+ },
34
+ transition: {
35
+ duration: 150
36
+ }
37
+ };
38
+ const state = plugin.withOptions(({ colorKeys }) => {
39
+ const resolved = {
40
+ ...defaultConfig,
41
+ disabledStyles: {
42
+ ...defaultConfig.disabledStyles,
43
+ ...{}
44
+ },
45
+ transition: {
46
+ ...defaultConfig.transition,
47
+ ...{}
48
+ }
49
+ };
50
+ return ({ addComponents }) => {
51
+ const newComponents = {};
52
+ for (const isGroup of [false, true]) {
53
+ const group = isGroup ? "group-" : "";
54
+ for (const colorName of colorKeys) {
55
+ const className = `.${group}${resolved.statePrefix}-${colorName}`;
56
+ newComponents[className] = {
57
+ [`@apply ${group}hover:bg-${colorName}/[0.08]`]: {},
58
+ [`@apply ${group}active:bg-${colorName}/[0.12]`]: {},
59
+ [`@apply ${group}focus-visible:bg-${colorName}/[0.12]`]: {},
60
+ [`@apply transition-colors`]: {},
61
+ [`@apply duration-${resolved.transition.duration}`]: {},
62
+ [`@apply ${group}disabled:text-on-surface/[${resolved.disabledStyles.textOpacity}]`]: {},
63
+ [`@apply ${group}disabled:bg-on-surface/[${resolved.disabledStyles.backgroundOpacity}]`]: {}
64
+ };
65
+ }
66
+ }
67
+ for (const colorName of colorKeys) {
68
+ for (const stateName of ["hover", "active", "focus", "disabled"]) {
69
+ const className = `.${stateName}-${resolved.statePrefix}-${colorName}`;
70
+ if (stateName === "disabled") {
71
+ newComponents[className] = {
72
+ [`@apply text-on-surface/[${resolved.disabledStyles.textOpacity}]`]: {},
73
+ [`@apply bg-on-surface/[${resolved.disabledStyles.backgroundOpacity}]`]: {}
74
+ };
75
+ } else {
76
+ const opacity = stateName === "hover" ? 0.08 : 0.12;
77
+ newComponents[className] = {
78
+ [`@apply bg-${colorName}/[${opacity}]`]: {}
79
+ };
80
+ }
81
+ }
82
+ }
83
+ addComponents(newComponents);
84
+ };
85
+ });
86
+ const font = plugin.withOptions((options) => {
87
+ return ({
88
+ addUtilities,
89
+ theme: theme2
90
+ }) => {
91
+ const { fontStyles, responsiveBreakPoints } = options;
92
+ const pixelUnit = "rem";
93
+ const newUtilities = {};
94
+ const baseTextStyle = (sizeValue) => ({
95
+ fontSize: sizeValue.fontSize + pixelUnit,
96
+ fontWeight: sizeValue.fontWeight,
97
+ lineHeight: sizeValue.lineHeight + pixelUnit,
98
+ letterSpacing: sizeValue.letterSpacing ? sizeValue.letterSpacing + pixelUnit : null,
99
+ fontFamily: theme2("fontFamily." + sizeValue.fontFamily)
100
+ });
101
+ const responsiveTextStyle = (sizeValue, breakPointName, breakPointRatio) => ({
102
+ [`@media (min-width: ${theme2("screens." + breakPointName, {})})`]: {
103
+ fontSize: sizeValue.fontSize * breakPointRatio + pixelUnit,
104
+ lineHeight: sizeValue.lineHeight * breakPointRatio + pixelUnit
105
+ }
106
+ });
107
+ for (const [roleName, roleValue] of Object.entries(fontStyles)) {
108
+ for (const [sizeName, sizeValue] of Object.entries(roleValue)) {
109
+ newUtilities[`.text-${roleName}-${sizeName}`] = {
110
+ ...baseTextStyle(sizeValue),
111
+ ...Object.entries(responsiveBreakPoints).reduce(
112
+ (acc, [breakPointName, breakPointRatio]) => ({
113
+ ...acc,
114
+ ...responsiveTextStyle(
115
+ sizeValue,
116
+ breakPointName,
117
+ breakPointRatio
118
+ )
119
+ }),
120
+ {}
121
+ )
122
+ };
123
+ }
124
+ }
125
+ addUtilities(newUtilities);
126
+ };
127
+ });
128
+ const shadow = plugin(
129
+ ({ addUtilities }) => {
130
+ addUtilities({
131
+ [".shadow"]: {
132
+ boxShadow: "0 4px 10px #00000008, 0 0 2px #0000000f, 0 2px 6px #0000001f"
133
+ },
134
+ [".shadow-1"]: {
135
+ boxShadow: "0px 1px 3px 1px rgba(0, 0, 0, 0.15), 0px 1px 2px 0px rgba(0, 0, 0, 0.30)"
136
+ },
137
+ [".shadow-2"]: {
138
+ boxShadow: "0px 2px 6px 2px rgba(0, 0, 0, 0.15), 0px 1px 2px 0px rgba(0, 0, 0, 0.30)"
139
+ },
140
+ [".shadow-3"]: {
141
+ boxShadow: "0px 1px 3px 0px rgba(0, 0, 0, 0.30), 0px 4px 8px 3px rgba(0, 0, 0, 0.15)"
142
+ },
143
+ [".shadow-4"]: {
144
+ boxShadow: "0px 2px 3px 0px rgba(0, 0, 0, 0.30), 0px 6px 10px 4px rgba(0, 0, 0, 0.15)"
145
+ },
146
+ [".box-shadow-5"]: {
147
+ boxShadow: "0px 4px 4px 0px rgba(0, 0, 0, 0.30), 0px 8px 12px 6px rgba(0, 0, 0, 0.15)"
148
+ }
149
+ });
150
+ }
151
+ );
152
+ const main = plugin.withOptions((args) => {
153
+ const configCss = args;
154
+ const fontStyles = {};
155
+ configCss.fontStyles.forEach((line) => {
156
+ const [styleToken, ...properties] = line.split(" ");
157
+ const [roleToken, sizeToken] = styleToken.split("-");
158
+ fontStyles[roleToken] ?? (fontStyles[roleToken] = {});
159
+ properties.forEach((properties2) => {
160
+ var _a;
161
+ (_a = fontStyles[roleToken])[sizeToken] ?? (_a[sizeToken] = {});
162
+ const [key, value] = properties2.slice(0, -1).split("[");
163
+ fontStyles[roleToken][sizeToken][key] = value;
164
+ });
165
+ });
166
+ let breakPointsCss = configCss.responsiveBreakPoints;
167
+ if (!Array.isArray(breakPointsCss)) {
168
+ breakPointsCss = [breakPointsCss];
169
+ }
170
+ const responsiveBreakPoints = {};
171
+ breakPointsCss.forEach((line) => {
172
+ const [key, value] = line.split(" ");
173
+ responsiveBreakPoints[key] = value;
174
+ });
175
+ const options = {
176
+ colorKeys: configCss.colorKeys,
177
+ fontStyles,
178
+ responsiveBreakPoints
179
+ };
180
+ return (api) => {
181
+ font(options).handler(api);
182
+ state(options).handler(api);
183
+ shadow.handler(api);
184
+ };
185
+ });
186
+ class TailwindPlugin extends theme.PluginAbstract {
187
+ constructor() {
188
+ super(...arguments);
189
+ __publicField(this, "dependencies", [theme.FontPlugin]);
190
+ __publicField(this, "name", "tailwind");
191
+ __publicField(this, "pluginClass", TailwindImplPluginBrowser);
192
+ }
193
+ }
194
+ class TailwindImplPluginBrowser extends theme.PluginImplAbstract {
195
+ constructor() {
196
+ super(...arguments);
197
+ __publicField(this, "outputCss", "");
198
+ __publicField(this, "colors", {});
199
+ }
200
+ onInit() {
201
+ var _a;
202
+ (_a = this.options).responsiveBreakPoints ?? (_a.responsiveBreakPoints = {
203
+ lg: 1.125
204
+ });
205
+ }
206
+ loadColor() {
207
+ this.outputCss += `
208
+ @custom-variant dark (&:where(.dark, .dark *));
209
+ @theme {
210
+ --color-*: initial;
211
+ ${Object.entries(this.colors).map(([key, value]) => `--color-${key}: ${value.light};`).join("\n ")}
212
+ }
213
+ @layer theme {
214
+ .dark {
215
+ ${Object.entries(this.colors).map(([key, value]) => `--color-${key}: ${value.dark};`).join("\n ")}
216
+ }
217
+ }
218
+ `;
219
+ }
220
+ async onLoad() {
221
+ var _a;
222
+ this.colors = {};
223
+ for (const isDark of [false, true]) {
224
+ this.api.themes.update({ isDark });
225
+ for (const [key, value] of this.api.colors.getColors().entries()) {
226
+ const newKey = key.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
227
+ (_a = this.colors)[newKey] ?? (_a[newKey] = { light: "", dark: "" });
228
+ this.colors[newKey][isDark ? "dark" : "light"] = value.getHex();
229
+ }
230
+ }
231
+ await import("@tailwindcss/browser");
232
+ this.loadColor();
233
+ }
234
+ }
235
+ exports.TailwindImplPluginBrowser = TailwindImplPluginBrowser;
236
+ exports.TailwindPlugin = TailwindPlugin;
237
+ exports.font = font;
238
+ exports.main = main;
239
+ exports.state = state;
package/package.json CHANGED
@@ -1,23 +1,36 @@
1
1
  {
2
2
  "name": "@udixio/tailwind",
3
- "version": "1.2.1",
3
+ "version": "1.4.0",
4
4
  "type": "module",
5
- "main": "./dist/index.js",
6
- "module": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
5
+ "main": "./dist/node.js",
6
+ "module": "./dist/node.js",
7
+ "types": "./dist/node.d.ts",
8
8
  "exports": {
9
9
  "./package.json": "./package.json",
10
10
  ".": {
11
- "development": "./src/index.ts",
12
- "types": "./dist/index.d.ts",
13
- "import": "./dist/index.js",
14
- "require": "./dist/index.cjs",
15
- "default": "./dist/index.js"
11
+ "development": "./src/index.node.ts",
12
+ "types": "./dist/index.node.d.ts",
13
+ "browser": {
14
+ "import": "./dist/browser.js",
15
+ "require": "./dist/browser.cjs",
16
+ "default": "./dist/browser.js"
17
+ },
18
+ "node": {
19
+ "import": "./dist/node.js",
20
+ "require": "./dist/node.cjs",
21
+ "default": "./dist/node.js"
22
+ },
23
+ "import": "./dist/browser.js",
24
+ "require": "./dist/browser.cjs",
25
+ "default": "./dist/browser.js"
16
26
  }
17
27
  },
18
28
  "dependencies": {
29
+ "@tailwindcss/browser": "^4.1.12",
30
+ "chalk": "^5.6.0",
31
+ "pathe": "^2.0.3",
19
32
  "tslib": "^2.3.0",
20
- "@udixio/theme": "1.0.0"
33
+ "@udixio/theme": "1.2.0"
21
34
  },
22
35
  "repository": {
23
36
  "type": "git",
@@ -0,0 +1,71 @@
1
+ import { FontPlugin, PluginAbstract, PluginImplAbstract } from '@udixio/theme';
2
+
3
+ export interface TailwindPluginOptions {
4
+ // darkMode?: 'class' | 'media';
5
+ responsiveBreakPoints?: Record<string, number>;
6
+ styleFilePath?: string;
7
+ // subThemes?: Record<string, string>;
8
+ }
9
+
10
+ export class TailwindPlugin extends PluginAbstract<
11
+ TailwindImplPluginBrowser,
12
+ TailwindPluginOptions
13
+ > {
14
+ public dependencies = [FontPlugin];
15
+ public name = 'tailwind';
16
+ pluginClass = TailwindImplPluginBrowser;
17
+ }
18
+
19
+ export class TailwindImplPluginBrowser extends PluginImplAbstract<TailwindPluginOptions> {
20
+ public outputCss = '';
21
+ protected colors: Record<
22
+ string,
23
+ {
24
+ light: string;
25
+ dark: string;
26
+ }
27
+ > = {};
28
+
29
+ onInit() {
30
+ this.options.responsiveBreakPoints ??= {
31
+ lg: 1.125,
32
+ };
33
+ }
34
+
35
+ loadColor() {
36
+ this.outputCss += `
37
+ @custom-variant dark (&:where(.dark, .dark *));
38
+ @theme {
39
+ --color-*: initial;
40
+ ${Object.entries(this.colors)
41
+ .map(([key, value]) => `--color-${key}: ${value.light};`)
42
+ .join('\n ')}
43
+ }
44
+ @layer theme {
45
+ .dark {
46
+ ${Object.entries(this.colors)
47
+ .map(([key, value]) => `--color-${key}: ${value.dark};`)
48
+ .join('\n ')}
49
+ }
50
+ }
51
+ `;
52
+ }
53
+
54
+ async onLoad() {
55
+ this.colors = {};
56
+ for (const isDark of [false, true]) {
57
+ this.api.themes.update({ isDark: isDark });
58
+ for (const [key, value] of this.api.colors.getColors().entries()) {
59
+ const newKey = key
60
+ .replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2')
61
+ .toLowerCase();
62
+ this.colors[newKey] ??= { light: '', dark: '' };
63
+ this.colors[newKey][isDark ? 'dark' : 'light'] = value.getHex();
64
+ }
65
+ }
66
+
67
+ await import('@tailwindcss/browser');
68
+
69
+ this.loadColor();
70
+ }
71
+ }
@@ -0,0 +1,5 @@
1
+ import { main } from './main';
2
+
3
+ export * from './plugins-tailwind';
4
+ export * from './browser/tailwind.plugin';
5
+ export default main;
@@ -1,5 +1,5 @@
1
1
  import { main } from './main';
2
2
 
3
3
  export * from './plugins-tailwind';
4
- export * from './tailwind.plugin';
4
+ export * from './node';
5
5
  export default main;