@windi-ui/tailwind 0.7.1 → 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.
package/dist/index.cjs CHANGED
@@ -1,330 +1,36 @@
1
- 'use strict';
2
-
3
- const createPlugin = require('tailwindcss/plugin');
4
- const core = require('@windi-ui/core');
5
- const node_module = require('node:module');
6
- const node_fs = require('node:fs');
7
-
8
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
9
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
10
-
11
- const createPlugin__default = /*#__PURE__*/_interopDefaultCompat(createPlugin);
12
-
13
- function hslToRgb(h, s, l) {
14
- let r, g, b;
15
- if (s === 0) {
16
- r = g = b = l;
17
- } else {
18
- const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
19
- const p = 2 * l - q;
20
- r = hueToRgb(p, q, h + 1 / 3);
21
- g = hueToRgb(p, q, h);
22
- b = hueToRgb(p, q, h - 1 / 3);
23
- }
24
- return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
25
- }
26
- function hueToRgb(p, q, t) {
27
- if (t < 0) t += 1;
28
- if (t > 1) t -= 1;
29
- if (t < 1 / 6) return p + (q - p) * 6 * t;
30
- if (t < 1 / 2) return q;
31
- if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
32
- return p;
33
- }
34
-
35
- function _interopDefaultCompat$1(e) {
36
- return e && typeof e === "object" && "default" in e ? e.default : e;
37
- }
38
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
39
- const flattenColorPalette = _interopDefaultCompat$1(
40
- require$1(require$1.resolve("tailwindcss/lib/util/flattenColorPalette", { paths: [process.cwd()] }))
41
- );
42
- const NUM_REGEX = /(\d*\.\d+|\d+)/;
43
- const ANGLE_REGEX = new RegExp(`^${NUM_REGEX.source}(deg|rad|grad|turn)?$`);
44
- const PERCENT_REGEX = new RegExp(`^${NUM_REGEX.source}%?$`);
45
- let twPkgPath;
46
- let twPkg;
47
- try {
48
- twPkgPath = node_module.findPackageJSON(undefined("tailwindcss", process.cwd()));
49
- if (twPkgPath) {
50
- twPkg = JSON.parse(node_fs.readFileSync(twPkgPath, { encoding: "utf8" }));
51
- }
52
- } catch (e) {
53
- console.error("Failed to read Tailwind CSS package.json:", e);
54
- }
55
- const TW_VER_REGEX = /^(3|4)\./;
56
- const match = twPkg?.version.match(TW_VER_REGEX);
57
- if (!match) {
58
- console.warn(`Unsupported Tailwind CSS version: ${twPkg?.version}. Expected 3.x or 4.x.`);
59
- }
60
- const TailwindVer = match ? Number(match[1]) : 3;
61
- function createTailwindTheme(tw) {
62
- return TailwindVer === 4 ? new TailwindV4Theme(tw) : new TailwindV3Theme(tw);
63
- }
64
- class TailwindTheme {
65
- theme;
66
- fSize;
67
- constructor(pluginApi) {
68
- this.theme = pluginApi.theme;
69
- this.fSize = this.theme("fontSize");
70
- }
71
- colors(name) {
72
- const cname = name ? `colors.${name}` : "colors";
73
- const c = this.theme(cname);
74
- return typeof c === "object" ? flattenColorPalette(c) : c;
75
- }
76
- spacing(name) {
77
- return this.theme(`spacing[${name}]`);
78
- }
79
- fontSize(name) {
80
- return this.fSize[name];
81
- }
82
- }
83
- class TailwindV4Theme extends TailwindTheme {
84
- ver = 4;
85
- constructor(pluginApi) {
86
- super(pluginApi);
87
- }
88
- colorValue(value, alpha) {
89
- return this.withAlpha(value, alpha);
90
- }
91
- applyTextColor(value, target, alpha) {
92
- target.color = this.withAlpha(value, alpha);
93
- }
94
- applyBackgroundColor(value, target, alpha) {
95
- target.backgroundColor = this.withAlpha(value, alpha);
96
- }
97
- applyBorderColor(value, target, alpha) {
98
- target.borderColor = this.withAlpha(value, alpha);
99
- }
100
- // https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L165C1-L182C2
101
- withAlpha(value, alpha) {
102
- if (alpha == null || alpha === "") return value;
103
- const alphaAsNumber = Number(alpha);
104
- if (!Number.isNaN(alphaAsNumber)) {
105
- alpha = `${alphaAsNumber * 100}%`;
106
- }
107
- if (alpha === "100%") {
108
- return value;
109
- }
110
- if (typeof alpha === "string" && alpha.startsWith("var(")) {
111
- alpha = `calc(${alpha} * 100%)`;
112
- }
113
- return `color-mix(in oklab, ${value} ${alpha}, transparent)`;
114
- }
115
- }
116
- class TailwindV3Theme extends TailwindTheme {
117
- ver = 3;
118
- withAlphaVariable = _interopDefaultCompat$1(require$1("tailwindcss/lib/util/withAlphaVariable"));
119
- parseColorFormat = require$1("tailwindcss/lib/util/pluginUtils").parseColorFormat;
120
- parseColor = require$1("tailwindcss/lib/util/color").parseColor;
121
- corePlugins;
122
- constructor(pluginApi) {
123
- super(pluginApi);
124
- this.corePlugins = (p) => pluginApi.corePlugins(p);
125
- }
126
- colors(name) {
127
- const c = super.colors(name);
128
- return typeof c === "string" ? this.colorToRgb(c) : this.colorsToRgb(c);
129
- }
130
- colorValue(value, alpha) {
131
- const c = this.parseRgbFormat(value);
132
- return typeof c === "string" ? c : c({ opacityValue: alpha?.toString() });
133
- }
134
- applyTextColor(value, target, alpha) {
135
- this.applyColor({
136
- color: value,
137
- property: "color",
138
- variable: "--tw-text-opacity"
139
- }, "textOpacity", target, alpha);
140
- }
141
- applyBackgroundColor(value, target, alpha) {
142
- this.applyColor({
143
- color: value,
144
- property: "background-color",
145
- variable: "--tw-bg-opacity"
146
- }, "backgroundOpacity", target, alpha);
147
- }
148
- applyBorderColor(value, target, alpha) {
149
- this.applyColor({
150
- color: value,
151
- property: "border-color",
152
- variable: "--tw-border-opacity"
153
- }, "borderOpacity", target, alpha);
154
- }
155
- applyColor(args, opacityPlugin, target, alpha) {
156
- args = {
157
- ...args,
158
- color: this.parseRgbFormat(args.color)
159
- };
160
- Object.assign(target, this.corePlugins?.(opacityPlugin) ? this.withAlphaVariable(args) : { [args.property]: this.toColorValue(args.color, alpha) });
161
- if (alpha != null && alpha !== "" && args.variable in target) {
162
- const alphaValue = alpha.toString();
163
- target[args.variable] = alphaValue;
164
- }
165
- }
166
- toColorValue(maybeFunction, alpha) {
167
- return typeof maybeFunction === "function" ? maybeFunction(alpha != null && alpha !== "" ? { opacityValue: alpha.toString() } : {}) : maybeFunction;
168
- }
169
- parseRgbFormat(color) {
170
- return this.parseColorFormat(`rgb(${color} / <alpha-value>)`);
171
- }
172
- colorsToRgb(colors) {
173
- for (const c in colors) {
174
- if (c === "black" || c === "white" || !c.startsWith("c-") && /^(?:.+-)?(?:50|950|[1-9]00)$/.exec(c))
175
- colors[c] = this.colorToRgb(colors[c]);
176
- }
177
- return colors;
178
- }
179
- colorToRgb(color) {
180
- const parsed = this.parseColor(color, { loose: true });
181
- if (parsed?.mode.startsWith("rgb")) {
182
- return parsed.color.join(" ");
183
- } else if (parsed?.mode.startsWith("hsl")) {
184
- if (parsed.color.length === 3) {
185
- const rh = ANGLE_REGEX.exec(parsed.color[0]);
186
- const rs = PERCENT_REGEX.exec(parsed.color[1]);
187
- const rl = PERCENT_REGEX.exec(parsed.color[2]);
188
- if (rh && rs && rl) {
189
- const h = parseFloat(rh[1]) / (rh[2] === "rad" ? 2 * Math.PI : rh[2] === "grad" ? 400 : rh[2] === "turn" ? 1 : 360);
190
- const s = parseFloat(rs[1]) / 100;
191
- const l = parseFloat(rl[1]) / 100;
192
- return hslToRgb(h, s, l).join(" ");
193
- }
194
- }
195
- }
196
- console.warn(`Unsupported color format: ${color}`);
197
- return color;
198
- }
199
- }
200
-
201
- const BLOCK_SELECTOR_REGEX = /^([^{]+)\{([^}]+)\}$/;
202
- function getDarkSelector(darkMode) {
203
- let [mode, selector = ".dark"] = Array.isArray(darkMode) ? darkMode : [darkMode];
204
- if (typeof selector === "function") {
205
- selector = selector();
206
- }
207
- if (typeof selector === "string") {
208
- selector = [selector];
209
- }
210
- if (mode === "variant") {
211
- for (const s of selector) {
212
- if (!s.startsWith("@") && !s.includes("&")) {
213
- console.warn("Invalid `variant` selector");
214
- return [];
215
- }
216
- }
217
- } else if (selector.length !== 1) {
218
- console.warn("Invalid `darkMode` selector");
219
- return [];
220
- }
221
- switch (mode) {
222
- case "media":
223
- return [["@media (prefers-color-scheme: dark)"]];
224
- case "class":
225
- return [[`&:is(${selector[0]} *)`]];
226
- case "selector":
227
- return [[`&:where(${selector[0]}, ${selector[0]} *)`]];
228
- case "variant": {
229
- const ss = [];
230
- for (const s of selector) {
231
- const bsMatch = BLOCK_SELECTOR_REGEX.exec(s);
232
- ss.push(bsMatch ? [bsMatch[1].trim(), bsMatch[2].trim()] : [s]);
233
- }
234
- return ss;
235
- }
236
- default:
237
- return [selector];
238
- }
239
- }
240
- function setNestedValue(obj, keys, value) {
241
- if (keys.length === 0) {
242
- return obj;
243
- }
244
- let curr = obj;
245
- for (let i = 0; i < keys.length; i++) {
246
- const K = keys[i];
247
- if (i === keys.length - 1) {
248
- curr[K] = value;
249
- } else {
250
- if (typeof curr[K] !== "object" || curr[K] === null) {
251
- curr[K] = {};
252
- }
253
- curr = curr[K];
254
- }
255
- }
256
- return obj;
257
- }
258
- function applyDark(selector, styles) {
259
- const { "@dark": darkStyle, ...style } = styles;
260
- if (darkStyle) {
261
- for (const s of selector) {
262
- setNestedValue(style, s, darkStyle);
263
- }
264
- }
265
- return style;
266
- }
267
-
268
- function keyValuePairs(keys, val = (k) => k) {
269
- return keys.reduce((acc, k) => {
270
- acc[k] = val(k);
271
- return acc;
272
- }, {});
273
- }
274
- function WindUITailwindCSS(config = {}) {
275
- const wiu = core.create(config);
276
- return createPlugin__default((tw) => {
277
- const tp = createTailwindTheme(tw);
278
- const gt = wiu.generator(tp);
279
- const darkMode = tw.config("darkMode", "media");
280
- const darkSelector = getDarkSelector(darkMode);
281
- tw.addBase({ ":root": gt.colors.rootVars() });
282
- tw.addBase({ ":root": gt.sizes.rootVars() });
283
- tw.addBase({ "*": applyDark(darkSelector, gt.variants.rootVars()) });
284
- tw.matchUtilities({
285
- c: (val) => gt.colors.cssVars(val)
286
- }, { values: keyValuePairs(gt.colors.names()) });
287
- tw.matchUtilities({
288
- v: (val) => applyDark(darkSelector, gt.variants.cssVars(val))
289
- }, { values: keyValuePairs(gt.variants.names()) });
290
- tw.matchUtilities({
291
- "bg": (val, ext) => {
292
- return gt.variants.utilCss("bg", val, ext.modifier);
293
- },
294
- "border": (val, ext) => {
295
- return gt.variants.utilCss("border", val, ext.modifier);
296
- },
297
- "text": (val, ext) => {
298
- return gt.variants.utilCss("text", val, ext.modifier);
299
- }
300
- }, {
301
- values: { v: "default", "v-soft": "soft", "v-muted": "muted", "v-accent": "accent" },
302
- modifiers: tw.theme("opacity")
303
- });
304
- tw.matchUtilities({
305
- s: (val) => gt.sizes.cssVars(val)
306
- }, {
307
- values: keyValuePairs(gt.sizes.names())
308
- });
309
- tw.addComponents([...gt.components.css()]);
310
- }, {
311
- content: [],
312
- theme: {
313
- extend: {
314
- colors({ colors }) {
315
- return {
316
- c: keyValuePairs(Object.keys(colors.gray), (v) => {
317
- const c = wiu.vars.color(v);
318
- return TailwindVer === 4 ? c : `rgb(${c} / <alpha-value>)`;
319
- }),
320
- // TODO: add as configurable option
321
- default: colors.gray,
322
- accent: colors.blue
323
- };
324
- }
325
- }
326
- }
327
- });
328
- }
329
-
330
- module.exports = WindUITailwindCSS;
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
5
+ const require_plugin = require("./plugin-BDVW4Keh.cjs");
6
+ const require_config = require("./config.cjs");
7
+ const require_safelist = require("./safelist.cjs");
8
+ require("./presets.cjs");
9
+ let _windi_ui_core = require("@windi-ui/core");
10
+ let _windi_ui_core_presets = require("@windi-ui/core/presets");
11
+ // src/index.ts
12
+ var src_default = require_plugin.createWindiUIPlugin();
13
+ exports.classSource = require_safelist.classSource;
14
+ exports.default = src_default;
15
+ Object.defineProperty(exports, "defineConfig", {
16
+ enumerable: true,
17
+ get: function() {
18
+ return _windi_ui_core.defineConfig;
19
+ }
20
+ });
21
+ Object.defineProperty(exports, "definePreset", {
22
+ enumerable: true,
23
+ get: function() {
24
+ return _windi_ui_core_presets.definePreset;
25
+ }
26
+ });
27
+ exports.loadWindiUIConfig = require_config.loadWindiUIConfig;
28
+ Object.defineProperty(exports, "nuxtUi", {
29
+ enumerable: true,
30
+ get: function() {
31
+ return _windi_ui_core_presets.nuxtUi;
32
+ }
33
+ });
34
+ exports.safelistSource = require_safelist.safelistSource;
35
+
36
+ module.exports = Object.assign(exports.default, exports);
package/dist/index.d.cts CHANGED
@@ -1,6 +1,14 @@
1
- import createPlugin from 'tailwindcss/plugin';
2
- import { Config } from '@windi-ui/core';
3
-
4
- declare function WindUITailwindCSS(config?: Config): ReturnType<typeof createPlugin>;
5
-
6
- export = WindUITailwindCSS;
1
+ import { n as WindiUIPlugin } from "./plugin-QCWiD6Wb.cjs";
2
+ import { Config, LoadConfigOptions, LoadedConfig, defineConfig, loadWindiUIConfig } from "./config.cjs";
3
+ import { SafelistAxis, SafelistOptions, classSource, safelistSource } from "./safelist.cjs";
4
+ import { Preset, PresetOptions, definePreset, nuxtUi } from "./presets.cjs";
5
+ declare const _default: WindiUIPlugin<{
6
+ handler: import("tailwindcss/types/config").PluginCreator;
7
+ config?: Partial<import("tailwindcss/types/config").Config>;
8
+ }>;
9
+ declare function _cjs(...args: Parameters<typeof _default>): ReturnType<typeof _default>;
10
+ declare namespace _cjs {
11
+ export { type Config, LoadConfigOptions, LoadedConfig, type Preset, type PresetOptions, SafelistAxis, SafelistOptions, classSource, _default as default, defineConfig, definePreset, loadWindiUIConfig, nuxtUi, safelistSource };
12
+ export const __isOptionsFunction: true;
13
+ }
14
+ export = _cjs;
package/dist/index.d.mts CHANGED
@@ -1,6 +1,9 @@
1
- import createPlugin from 'tailwindcss/plugin';
2
- import { Config } from '@windi-ui/core';
3
-
4
- declare function WindUITailwindCSS(config?: Config): ReturnType<typeof createPlugin>;
5
-
6
- export { WindUITailwindCSS as default };
1
+ import { n as WindiUIPlugin } from "./plugin-ayXaeLBM.mjs";
2
+ import { Config, LoadConfigOptions, LoadedConfig, defineConfig, loadWindiUIConfig } from "./config.mjs";
3
+ import { SafelistAxis, SafelistOptions, classSource, safelistSource } from "./safelist.mjs";
4
+ import { Preset, PresetOptions, definePreset, nuxtUi } from "./presets.mjs";
5
+ declare const _default: WindiUIPlugin<{
6
+ handler: import("tailwindcss/types/config").PluginCreator;
7
+ config?: Partial<import("tailwindcss/types/config").Config>;
8
+ }>;
9
+ export { type Config, LoadConfigOptions, LoadedConfig, type Preset, type PresetOptions, SafelistAxis, SafelistOptions, classSource, _default as default, defineConfig, definePreset, loadWindiUIConfig, nuxtUi, safelistSource };