@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/README.md +229 -0
- package/dist/config.cjs +92 -0
- package/dist/config.d.cts +18 -0
- package/dist/config.d.mts +18 -0
- package/dist/config.mjs +85 -0
- package/dist/configState-BnylRpdM.cjs +42 -0
- package/dist/configState-DfiH-8b9.mjs +19 -0
- package/dist/index.cjs +36 -330
- package/dist/index.d.cts +14 -6
- package/dist/index.d.mts +9 -6
- package/dist/index.mjs +7 -322
- package/dist/plugin-BDVW4Keh.cjs +545 -0
- package/dist/plugin-DJjsT2Zj.mjs +540 -0
- package/dist/plugin-QCWiD6Wb.d.cts +16 -0
- package/dist/plugin-ayXaeLBM.d.mts +17 -0
- package/dist/presets.cjs +15 -0
- package/dist/presets.d.cts +2 -0
- package/dist/presets.d.mts +2 -0
- package/dist/presets.mjs +2 -0
- package/dist/safelist.cjs +85 -0
- package/dist/safelist.d.cts +21 -0
- package/dist/safelist.d.mts +21 -0
- package/dist/safelist.mjs +83 -0
- package/dist/v3.cjs +5 -0
- package/dist/v3.d.cts +7 -0
- package/dist/v3.d.mts +7 -0
- package/dist/v3.mjs +6 -0
- package/dist/v4.cjs +5 -0
- package/dist/v4.d.cts +4 -0
- package/dist/v4.d.mts +4 -0
- package/dist/v4.mjs +6 -0
- package/package.json +31 -11
- package/dist/index.d.ts +0 -6
|
@@ -0,0 +1,540 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { create } from "@windi-ui/core";
|
|
3
|
+
import { loadWindiUIConfig } from "./config.mjs";
|
|
4
|
+
import { n as isLoadingConfig, t as CONFIG } from "./configState-DfiH-8b9.mjs";
|
|
5
|
+
import { classSource } from "./safelist.mjs";
|
|
6
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
7
|
+
import { dirname, join } from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
// src/utils/color.ts
|
|
10
|
+
function hslToRgb(h, s, l) {
|
|
11
|
+
let r, g, b;
|
|
12
|
+
if (s === 0) r = g = b = l;
|
|
13
|
+
else {
|
|
14
|
+
const q = l < .5 ? l * (1 + s) : l + s - l * s;
|
|
15
|
+
const p = 2 * l - q;
|
|
16
|
+
r = hueToRgb(p, q, h + 1 / 3);
|
|
17
|
+
g = hueToRgb(p, q, h);
|
|
18
|
+
b = hueToRgb(p, q, h - 1 / 3);
|
|
19
|
+
}
|
|
20
|
+
return [
|
|
21
|
+
Math.round(r * 255),
|
|
22
|
+
Math.round(g * 255),
|
|
23
|
+
Math.round(b * 255)
|
|
24
|
+
];
|
|
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
|
+
// src/theme.ts
|
|
35
|
+
function _interopDefaultCompat(e) {
|
|
36
|
+
return e && typeof e === "object" && "default" in e ? e.default : e;
|
|
37
|
+
}
|
|
38
|
+
const require = createRequire(import.meta.url);
|
|
39
|
+
/** `{ red: { 500: '#f00', DEFAULT: '#e00' } }` to `{ 'red-500': '#f00', red: '#e00' }`, as Tailwind's own helper does. */
|
|
40
|
+
function flattenColorPalette(colors, prefix = "", flat = {}, css = colors.__CSS_VALUES__ ?? {}) {
|
|
41
|
+
for (const [name, value] of Object.entries(colors)) {
|
|
42
|
+
if (name === "__CSS_VALUES__") continue;
|
|
43
|
+
const key = !prefix ? name : name === "DEFAULT" ? prefix : `${prefix}-${name}`;
|
|
44
|
+
if (typeof value !== "object") {
|
|
45
|
+
if (!prefix || !(key in css)) flat[key] = value;
|
|
46
|
+
} else if (value) flattenColorPalette(value, key, flat, css);
|
|
47
|
+
}
|
|
48
|
+
return flat;
|
|
49
|
+
}
|
|
50
|
+
const NUM_REGEX = /(\d*\.\d+|\d+)/;
|
|
51
|
+
const ANGLE_REGEX = new RegExp(`^${NUM_REGEX.source}(deg|rad|grad|turn)?$`);
|
|
52
|
+
const PERCENT_REGEX = new RegExp(`^${NUM_REGEX.source}%?$`);
|
|
53
|
+
/**
|
|
54
|
+
* Picks the theme by what the plugin API offers, unless `ver` says which: only Tailwind 3 has `corePlugins`.
|
|
55
|
+
* @param own theme colors the plugin registered for palettes of the builder, which `colors()` leaves to the builder.
|
|
56
|
+
*/
|
|
57
|
+
function createTailwindTheme(tw, ver, own) {
|
|
58
|
+
return (ver ? ver === 3 : typeof tw.corePlugins === "function") ? new TailwindV3Theme(tw, own) : new TailwindV4Theme(tw, own);
|
|
59
|
+
}
|
|
60
|
+
var TailwindTheme = class {
|
|
61
|
+
own;
|
|
62
|
+
theme;
|
|
63
|
+
fSize;
|
|
64
|
+
constructor(pluginApi, own = []) {
|
|
65
|
+
this.own = own;
|
|
66
|
+
this.theme = pluginApi.theme;
|
|
67
|
+
this.fSize = this.theme("fontSize");
|
|
68
|
+
}
|
|
69
|
+
colors(name) {
|
|
70
|
+
const cname = name ? `colors.${name}` : "colors";
|
|
71
|
+
let c = this.theme(cname);
|
|
72
|
+
if (typeof c !== "object") return c;
|
|
73
|
+
if (!name) {
|
|
74
|
+
c = { ...c };
|
|
75
|
+
for (const own of this.own) delete c[own];
|
|
76
|
+
}
|
|
77
|
+
return flattenColorPalette(c);
|
|
78
|
+
}
|
|
79
|
+
spacing(name) {
|
|
80
|
+
return this.theme(`spacing[${name}]`);
|
|
81
|
+
}
|
|
82
|
+
fontSize(name) {
|
|
83
|
+
return this.fSize[name];
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var TailwindV4Theme = class extends TailwindTheme {
|
|
87
|
+
ver = 4;
|
|
88
|
+
constructor(pluginApi, own) {
|
|
89
|
+
super(pluginApi, own);
|
|
90
|
+
}
|
|
91
|
+
colorValue(value, alpha) {
|
|
92
|
+
return this.withAlpha(value, alpha);
|
|
93
|
+
}
|
|
94
|
+
applyTextColor(value, target, alpha) {
|
|
95
|
+
target.color = this.withAlpha(value, alpha);
|
|
96
|
+
}
|
|
97
|
+
applyBackgroundColor(value, target, alpha) {
|
|
98
|
+
target.backgroundColor = this.withAlpha(value, alpha);
|
|
99
|
+
}
|
|
100
|
+
applyBorderColor(value, target, alpha) {
|
|
101
|
+
target.borderColor = this.withAlpha(value, alpha);
|
|
102
|
+
}
|
|
103
|
+
withAlpha(value, alpha) {
|
|
104
|
+
if (alpha == null || alpha === "") return value;
|
|
105
|
+
const alphaAsNumber = Number(alpha);
|
|
106
|
+
if (!Number.isNaN(alphaAsNumber)) alpha = `${alphaAsNumber * 100}%`;
|
|
107
|
+
if (alpha === "100%") return value;
|
|
108
|
+
if (typeof alpha === "string" && alpha.startsWith("var(")) alpha = `calc(${alpha} * 100%)`;
|
|
109
|
+
return `color-mix(in oklab, ${value} ${alpha}, transparent)`;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
var TailwindV3Theme = class extends TailwindTheme {
|
|
113
|
+
ver = 3;
|
|
114
|
+
withAlphaVariable = _interopDefaultCompat(require("tailwindcss/lib/util/withAlphaVariable"));
|
|
115
|
+
parseColorFormat = require("tailwindcss/lib/util/pluginUtils").parseColorFormat;
|
|
116
|
+
parseColor = require("tailwindcss/lib/util/color").parseColor;
|
|
117
|
+
corePlugins;
|
|
118
|
+
constructor(pluginApi, own) {
|
|
119
|
+
super(pluginApi, own);
|
|
120
|
+
this.corePlugins = (p) => pluginApi.corePlugins(p);
|
|
121
|
+
}
|
|
122
|
+
colors(name) {
|
|
123
|
+
const c = super.colors(name);
|
|
124
|
+
return typeof c === "string" ? this.colorToRgb(c) : this.colorsToRgb(c);
|
|
125
|
+
}
|
|
126
|
+
colorValue(value, alpha) {
|
|
127
|
+
const c = this.parseRgbFormat(value);
|
|
128
|
+
return typeof c === "string" ? c : c({ opacityValue: alpha?.toString() });
|
|
129
|
+
}
|
|
130
|
+
applyTextColor(value, target, alpha) {
|
|
131
|
+
this.applyColor({
|
|
132
|
+
color: value,
|
|
133
|
+
property: "color",
|
|
134
|
+
variable: "--tw-text-opacity"
|
|
135
|
+
}, "textOpacity", target, alpha);
|
|
136
|
+
}
|
|
137
|
+
applyBackgroundColor(value, target, alpha) {
|
|
138
|
+
this.applyColor({
|
|
139
|
+
color: value,
|
|
140
|
+
property: "background-color",
|
|
141
|
+
variable: "--tw-bg-opacity"
|
|
142
|
+
}, "backgroundOpacity", target, alpha);
|
|
143
|
+
}
|
|
144
|
+
applyBorderColor(value, target, alpha) {
|
|
145
|
+
this.applyColor({
|
|
146
|
+
color: value,
|
|
147
|
+
property: "border-color",
|
|
148
|
+
variable: "--tw-border-opacity"
|
|
149
|
+
}, "borderOpacity", target, alpha);
|
|
150
|
+
}
|
|
151
|
+
applyColor(args, opacityPlugin, target, alpha) {
|
|
152
|
+
args = {
|
|
153
|
+
...args,
|
|
154
|
+
color: this.parseRgbFormat(args.color)
|
|
155
|
+
};
|
|
156
|
+
Object.assign(target, this.corePlugins?.(opacityPlugin) ? this.withAlphaVariable(args) : { [args.property]: this.toColorValue(args.color, alpha) });
|
|
157
|
+
if (alpha != null && alpha !== "" && args.variable in target) {
|
|
158
|
+
const alphaValue = alpha.toString();
|
|
159
|
+
target[args.variable] = alphaValue;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
toColorValue(maybeFunction, alpha) {
|
|
163
|
+
return typeof maybeFunction === "function" ? maybeFunction(alpha != null && alpha !== "" ? { opacityValue: alpha.toString() } : {}) : maybeFunction;
|
|
164
|
+
}
|
|
165
|
+
parseRgbFormat(color) {
|
|
166
|
+
return this.parseColorFormat(`rgb(${color} / <alpha-value>)`);
|
|
167
|
+
}
|
|
168
|
+
colorsToRgb(colors) {
|
|
169
|
+
for (const c in colors) if (c === "black" || c === "white" || !c.startsWith("c-") && /^(?:.+-)?(?:50|950|[1-9]00)$/.exec(c)) colors[c] = this.colorToRgb(colors[c]);
|
|
170
|
+
return colors;
|
|
171
|
+
}
|
|
172
|
+
toColor(value) {
|
|
173
|
+
return this.colorToRgb(value);
|
|
174
|
+
}
|
|
175
|
+
colorToRgb(color) {
|
|
176
|
+
if (color.includes("var(")) return color;
|
|
177
|
+
const parsed = this.parseColor(color, { loose: true });
|
|
178
|
+
if (parsed?.mode.startsWith("rgb")) return parsed.color.join(" ");
|
|
179
|
+
else if (parsed?.mode.startsWith("hsl")) {
|
|
180
|
+
if (parsed.color.length === 3) {
|
|
181
|
+
const rh = ANGLE_REGEX.exec(parsed.color[0]);
|
|
182
|
+
const rs = PERCENT_REGEX.exec(parsed.color[1]);
|
|
183
|
+
const rl = PERCENT_REGEX.exec(parsed.color[2]);
|
|
184
|
+
if (rh && rs && rl) return hslToRgb(parseFloat(rh[1]) / (rh[2] === "rad" ? 2 * Math.PI : rh[2] === "grad" ? 400 : rh[2] === "turn" ? 1 : 360), parseFloat(rs[1]) / 100, parseFloat(rl[1]) / 100).join(" ");
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
console.warn(`Unsupported color format: ${color}`);
|
|
188
|
+
return color;
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
// src/utils/darkMode.ts
|
|
192
|
+
const BLOCK_SELECTOR_REGEX = /^([^{]+)\{([^}]+)\}$/;
|
|
193
|
+
const MODES = [
|
|
194
|
+
"media",
|
|
195
|
+
"class",
|
|
196
|
+
"selector",
|
|
197
|
+
"variant"
|
|
198
|
+
];
|
|
199
|
+
/** Tailwind expands this key with the app's own dark variant, `@custom-variant dark` included. */
|
|
200
|
+
const VARIANT_DARK = [["@variant dark"]];
|
|
201
|
+
/** The `darkSelector` option as a Tailwind `darkMode`: a bare selector is the `selector` strategy. */
|
|
202
|
+
function toDarkMode(option) {
|
|
203
|
+
return typeof option === "string" && !MODES.includes(option) ? ["selector", option] : option;
|
|
204
|
+
}
|
|
205
|
+
function getDarkSelector(darkMode) {
|
|
206
|
+
let [mode, selector = ".dark"] = Array.isArray(darkMode) ? darkMode : [darkMode];
|
|
207
|
+
if (typeof selector === "function") selector = selector();
|
|
208
|
+
if (typeof selector === "string") selector = [selector];
|
|
209
|
+
if (mode === "variant") {
|
|
210
|
+
for (const s of selector) if (!s.startsWith("@") && !s.includes("&")) {
|
|
211
|
+
console.warn("Invalid `variant` selector");
|
|
212
|
+
return [];
|
|
213
|
+
}
|
|
214
|
+
} else if (selector.length !== 1) {
|
|
215
|
+
console.warn("Invalid `darkMode` selector");
|
|
216
|
+
return [];
|
|
217
|
+
}
|
|
218
|
+
switch (mode) {
|
|
219
|
+
case "media": return [["@media (prefers-color-scheme: dark)"]];
|
|
220
|
+
case "class": return [[`&:is(${selector[0]} *)`]];
|
|
221
|
+
case "selector": return [[`&:where(${selector[0]}, ${selector[0]} *)`]];
|
|
222
|
+
case "variant": {
|
|
223
|
+
const ss = [];
|
|
224
|
+
for (const s of selector) {
|
|
225
|
+
const bsMatch = BLOCK_SELECTOR_REGEX.exec(s);
|
|
226
|
+
ss.push(bsMatch ? [bsMatch[1].trim(), bsMatch[2].trim()] : [s]);
|
|
227
|
+
}
|
|
228
|
+
return ss;
|
|
229
|
+
}
|
|
230
|
+
default: return [selector];
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/** The dark selector for a rule on the root element, which `&:is(.dark *)` never matches and `&:not(.light *)` always does: it has no ancestor. */
|
|
234
|
+
function rootDarkSelector(selector) {
|
|
235
|
+
return selector.map((chain) => chain.map((s) => s.replace(/^&:(is|not)\((.+) \*\)$/, "&:$1($2, $2 *)")));
|
|
236
|
+
}
|
|
237
|
+
function setNestedValue(obj, keys, value) {
|
|
238
|
+
if (keys.length === 0) return obj;
|
|
239
|
+
let curr = obj;
|
|
240
|
+
for (let i = 0; i < keys.length; i++) {
|
|
241
|
+
const K = keys[i];
|
|
242
|
+
if (i === keys.length - 1) curr[K] = value;
|
|
243
|
+
else {
|
|
244
|
+
if (typeof curr[K] !== "object" || curr[K] === null) curr[K] = {};
|
|
245
|
+
curr = curr[K];
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return obj;
|
|
249
|
+
}
|
|
250
|
+
function applyDark(selector, styles) {
|
|
251
|
+
const { "@dark": darkStyle, ...style } = styles;
|
|
252
|
+
for (const [key, value] of Object.entries(style)) if (value && typeof value === "object" && "@dark" in value) style[key] = applyDark(selector, value);
|
|
253
|
+
if (darkStyle) for (const s of selector) setNestedValue(style, s, darkStyle);
|
|
254
|
+
return style;
|
|
255
|
+
}
|
|
256
|
+
// src/utils/version.ts
|
|
257
|
+
const versions = /* @__PURE__ */ new Map();
|
|
258
|
+
/** The version of the `tailwindcss` package `file` belongs to, if it belongs to one. */
|
|
259
|
+
function tailwindVersionOf(file) {
|
|
260
|
+
if (!versions.has(file)) {
|
|
261
|
+
let version;
|
|
262
|
+
for (let dir = dirname(file); dirname(dir) !== dir; dir = dirname(dir)) {
|
|
263
|
+
const path = join(dir, "package.json");
|
|
264
|
+
if (!existsSync(path)) continue;
|
|
265
|
+
const pkg = JSON.parse(readFileSync(path, "utf8"));
|
|
266
|
+
if (pkg.name === "tailwindcss") version = pkg.version;
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
versions.set(file, version);
|
|
270
|
+
}
|
|
271
|
+
return versions.get(file);
|
|
272
|
+
}
|
|
273
|
+
/** The call stack, from this function outwards: for each frame, the version of the Tailwind its file belongs to, if any. */
|
|
274
|
+
function callers() {
|
|
275
|
+
const prepare = Error.prepareStackTrace;
|
|
276
|
+
Error.prepareStackTrace = (_, sites) => sites.map((site) => site.getFileName());
|
|
277
|
+
const files = (/* @__PURE__ */ new Error()).stack;
|
|
278
|
+
Error.prepareStackTrace = prepare;
|
|
279
|
+
return files.map((file) => file ? tailwindVersionOf(file.startsWith("file:") ? fileURLToPath(file) : file) : void 0);
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Whether Tailwind itself made the call `depth` frames above the function that asks, as it does for an `@plugin` block.
|
|
283
|
+
* It is `false` when that Tailwind cannot be found, for example when it is bundled.
|
|
284
|
+
*/
|
|
285
|
+
function calledByTailwind(depth) {
|
|
286
|
+
return callers()[depth + 2] != null;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Whether the Tailwind that is calling the plugin is at least this version. The plugin API does not carry a version,
|
|
290
|
+
* and the `tailwindcss` that resolves from here or from the working directory need not be the one that runs, so this
|
|
291
|
+
* goes by the call stack. It is `false` when that Tailwind cannot be found, for example when it is bundled.
|
|
292
|
+
*/
|
|
293
|
+
function tailwindAtLeast(...min) {
|
|
294
|
+
for (const version of callers()) {
|
|
295
|
+
if (!version) continue;
|
|
296
|
+
const parts = version.split(".").map((part) => parseInt(part));
|
|
297
|
+
for (let i = 0; i < 3; i++) if (parts[i] !== min[i]) return parts[i] > min[i];
|
|
298
|
+
return true;
|
|
299
|
+
}
|
|
300
|
+
return false;
|
|
301
|
+
}
|
|
302
|
+
// src/plugin.ts
|
|
303
|
+
const createPlugin = createRequire(import.meta.url)("tailwindcss/plugin");
|
|
304
|
+
function keyValuePairs(keys, val = (k) => k) {
|
|
305
|
+
return keys.reduce((acc, k) => {
|
|
306
|
+
acc[k] = val(k);
|
|
307
|
+
return acc;
|
|
308
|
+
}, {});
|
|
309
|
+
}
|
|
310
|
+
const FALLBACK = {
|
|
311
|
+
default: "gray",
|
|
312
|
+
accent: "blue"
|
|
313
|
+
};
|
|
314
|
+
const VARIANT_UTILS = {
|
|
315
|
+
v: "default",
|
|
316
|
+
"v-soft": "soft",
|
|
317
|
+
"v-muted": "muted",
|
|
318
|
+
"v-accent": "accent"
|
|
319
|
+
};
|
|
320
|
+
const NOTHING = [];
|
|
321
|
+
/** Tailwind also calls a `matchUtilities` callback for arbitrary values (`bg-[#123456]`, `c-[foo]`), which emit nothing. */
|
|
322
|
+
function known(values, css) {
|
|
323
|
+
const set = new Set(values);
|
|
324
|
+
return (val, ext) => set.has(val) ? css(val, ext) : NOTHING;
|
|
325
|
+
}
|
|
326
|
+
const OPTIONS = [
|
|
327
|
+
"prefix",
|
|
328
|
+
"rootSelector",
|
|
329
|
+
"default",
|
|
330
|
+
"accent",
|
|
331
|
+
"colors",
|
|
332
|
+
"variantScope",
|
|
333
|
+
"overrides",
|
|
334
|
+
"overrideMode",
|
|
335
|
+
"variantUtilities",
|
|
336
|
+
"darkSelector",
|
|
337
|
+
"presets",
|
|
338
|
+
"build",
|
|
339
|
+
"safelist",
|
|
340
|
+
"debug",
|
|
341
|
+
"config"
|
|
342
|
+
];
|
|
343
|
+
/**
|
|
344
|
+
* Inline options over those of the config file. An `@plugin` block writes the names in kebab-case.
|
|
345
|
+
* @param strict whether an unknown option is an error. In a JavaScript call it was ignored in 0.7, and still only warns.
|
|
346
|
+
*/
|
|
347
|
+
function resolveOptions(options = {}, strict = false) {
|
|
348
|
+
const inline = {};
|
|
349
|
+
for (const [name, value] of Object.entries(options)) {
|
|
350
|
+
const key = name.replace(/-(\w)/g, (_, c) => c.toUpperCase());
|
|
351
|
+
if (!OPTIONS.includes(key)) {
|
|
352
|
+
const message = `WindiUI: unknown option "${name}". The options are: ${OPTIONS.join(", ")}.`;
|
|
353
|
+
if (strict) throw new Error(message);
|
|
354
|
+
console.warn(message);
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
if (key === "build" && value != null && typeof value !== "function") throw new Error("WindiUI: `build` is a function, which an `@plugin` block cannot hold. Put it in a config file or a plugin module.");
|
|
358
|
+
if ((key === "overrides" || key === "variantUtilities") && value != null && (typeof value !== "object" || Array.isArray(value))) throw new Error(`WindiUI: \`${key}\` is an object, which an \`@plugin\` block cannot hold. Put it in a config file or a plugin module.`);
|
|
359
|
+
if (value !== void 0) inline[key] = key === "rootSelector" && Array.isArray(value) ? value.join(", ") : value;
|
|
360
|
+
if (key === "presets" && typeof value === "string") inline[key] = [value];
|
|
361
|
+
if (key === "colors" && (typeof value === "string" || Array.isArray(value))) inline[key] = { only: [value].flat() };
|
|
362
|
+
}
|
|
363
|
+
const { config: file, ...config } = inline;
|
|
364
|
+
if (file === false || file == null && config.build || isLoadingConfig()) return config;
|
|
365
|
+
return {
|
|
366
|
+
...loadWindiUIConfig({ config: file }).config,
|
|
367
|
+
...config
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* The palettes the presets and `build` add with `utilities: true`. Tailwind resolves its theme before the builder can
|
|
372
|
+
* run, so they are first run on a builder that does nothing but note them.
|
|
373
|
+
*/
|
|
374
|
+
function utilityColors({ presets, build }, inTheme) {
|
|
375
|
+
const found = /* @__PURE__ */ new Map();
|
|
376
|
+
const removed = /* @__PURE__ */ new Set();
|
|
377
|
+
const set = (name, value, options) => {
|
|
378
|
+
if (options?.utilities) found.set(name, value);
|
|
379
|
+
else found.delete(name);
|
|
380
|
+
return builder;
|
|
381
|
+
};
|
|
382
|
+
const builder = new Proxy({
|
|
383
|
+
addColor: (name, ...rest) => inTheme(name) && !removed.has(name) && !found.has(name) ? builder : set(name, ...rest),
|
|
384
|
+
setColor: set,
|
|
385
|
+
removeColor: (name) => (found.delete(name), removed.add(name), builder)
|
|
386
|
+
}, { get: (target, key) => target[key] ?? (() => key.endsWith("Names") ? [] : builder) });
|
|
387
|
+
try {
|
|
388
|
+
for (const preset of presets) preset.build(builder);
|
|
389
|
+
build?.(builder);
|
|
390
|
+
} catch {}
|
|
391
|
+
return found;
|
|
392
|
+
}
|
|
393
|
+
/** @param ver the Tailwind major to build for; left out, it is taken from the Tailwind that runs the plugin. */
|
|
394
|
+
function createWindiUIPlugin(ver) {
|
|
395
|
+
return Object.assign((options) => WindiUITailwindCSS(resolveOptions(options, calledByTailwind(1)), ver), { __isOptionsFunction: true });
|
|
396
|
+
}
|
|
397
|
+
function WindiUITailwindCSS(config, ver) {
|
|
398
|
+
const wiu = create(config);
|
|
399
|
+
let followed = {};
|
|
400
|
+
let missing = {};
|
|
401
|
+
let probing = false;
|
|
402
|
+
let mixReported = false;
|
|
403
|
+
let utilities;
|
|
404
|
+
let utilitiesReported = false;
|
|
405
|
+
let safelistReported = false;
|
|
406
|
+
return Object.assign(createPlugin((tw) => {
|
|
407
|
+
const tp = createTailwindTheme(tw, ver, utilities && [...utilities.keys()]);
|
|
408
|
+
const gt = wiu.generator(tp);
|
|
409
|
+
for (const [name, shades] of Object.entries(mixReported ? {} : missing)) {
|
|
410
|
+
mixReported = true;
|
|
411
|
+
console.warn(`WindiUI: the theme's "${name}" palette has no shade ${shades.join(", ")}; ${shades.length > 1 ? "these are" : "it is"} taken from ${FALLBACK[name]}. Give it all 11 shades, or set the \`${name}\` option.`);
|
|
412
|
+
}
|
|
413
|
+
for (const [name, palette] of Object.entries(mixReported ? {} : followed)) {
|
|
414
|
+
const theme = tw.theme(`colors.${name}`, {});
|
|
415
|
+
if (Object.keys(palette).some((s) => theme[s] !== palette[s])) {
|
|
416
|
+
mixReported = true;
|
|
417
|
+
console.warn(`WindiUI: the theme has a "${name}" palette of its own, which utilities such as \`bg-${name}-500\` keep using. The \`${name}\` option only sets \`c-${name}\` and the variables. Use one of the two.`);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
const darkMode = wiu.config.darkSelector != null ? toDarkMode(wiu.config.darkSelector) : tw.config("darkMode");
|
|
421
|
+
const darkSelector = darkMode != null ? getDarkSelector(darkMode) : tp.ver === 4 && tailwindAtLeast(4, 1, 17) ? VARIANT_DARK : getDarkSelector("media");
|
|
422
|
+
const root = wiu.config.rootSelector;
|
|
423
|
+
tw.addBase({ [root]: applyDark(rootDarkSelector(darkSelector), gt.colors.rootVars()) });
|
|
424
|
+
tw.addBase({ [root]: gt.sizes.rootVars() });
|
|
425
|
+
const scope = wiu.config.variantScope;
|
|
426
|
+
if (scope === "universal") tw.addBase({ "*": applyDark(darkSelector, gt.variants.rootVars()) });
|
|
427
|
+
else {
|
|
428
|
+
const mode = gt.variants.modeVars();
|
|
429
|
+
tw.addBase({ ":where(:root)": mode.light });
|
|
430
|
+
tw.addBase({ "*": applyDark(darkSelector, { "@dark": mode.dark }) });
|
|
431
|
+
const reset = gt.variants.resetVars();
|
|
432
|
+
if (scope === "element") tw.addBase({ ":where([class*=\"v-\"]) > *": reset });
|
|
433
|
+
tw.addUtilities({ ".v-scope": { ":where(&) > *": reset } });
|
|
434
|
+
}
|
|
435
|
+
const colorNames = gt.colors.names();
|
|
436
|
+
const variantNames = gt.variants.names();
|
|
437
|
+
const sizeNames = gt.sizes.names();
|
|
438
|
+
if (tp.ver === 3) {
|
|
439
|
+
const list = tw.config("safelist");
|
|
440
|
+
for (const [, name] of darkSelector.flat().join(" ").matchAll(/\.(-?[_a-zA-Z][\w-]*)/g)) if (!list.includes(name)) list.push(name);
|
|
441
|
+
}
|
|
442
|
+
if (wiu.config.safelist && tp.ver === 3) {
|
|
443
|
+
const list = tw.config("safelist");
|
|
444
|
+
const pattern = new RegExp(`^${tw.config("prefix", "").replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}[cvs]-`);
|
|
445
|
+
if (!list.some((entry) => String(entry?.pattern) === String(pattern))) list.push({ pattern });
|
|
446
|
+
}
|
|
447
|
+
if (wiu.config.safelist && tp.ver === 4 && !safelistReported) {
|
|
448
|
+
safelistReported = true;
|
|
449
|
+
console.warn(`WindiUI: \`safelist\` only works on Tailwind 3. On Tailwind 4, add this line to the stylesheet (\`safelistSource()\` from "@windi-ui/tailwind" returns the string, to keep it current with a test):\n@source inline("${classSource({
|
|
450
|
+
c: colorNames,
|
|
451
|
+
v: variantNames,
|
|
452
|
+
s: sizeNames
|
|
453
|
+
})}");`);
|
|
454
|
+
}
|
|
455
|
+
tw.matchUtilities({ c: known(colorNames, (val) => applyDark(darkSelector, gt.colors.cssVars(val))) }, { values: keyValuePairs(colorNames) });
|
|
456
|
+
tw.matchUtilities({ v: known(variantNames, (val) => applyDark(darkSelector, gt.variants.cssVars(val))) }, { values: keyValuePairs(variantNames) });
|
|
457
|
+
const variantUtil = (prop) => known(Object.values(VARIANT_UTILS), (val, ext) => gt.variants.utilCss(prop, val, ext.modifier ?? void 0));
|
|
458
|
+
tw.matchUtilities({
|
|
459
|
+
bg: variantUtil("bg"),
|
|
460
|
+
border: variantUtil("border"),
|
|
461
|
+
text: variantUtil("text")
|
|
462
|
+
}, {
|
|
463
|
+
values: VARIANT_UTILS,
|
|
464
|
+
modifiers: tw.theme("opacity"),
|
|
465
|
+
...tp.ver === 3 ? { type: ["lookup"] } : {}
|
|
466
|
+
});
|
|
467
|
+
tw.matchUtilities({ "apply-v": (val) => gt.variants.applyCss(val) ?? NOTHING }, { values: { DEFAULT: "" } });
|
|
468
|
+
const variantUtils = Object.entries(wiu.config.variantUtilities ?? {}).filter(([prop, variant]) => {
|
|
469
|
+
if (![
|
|
470
|
+
"bg",
|
|
471
|
+
"border",
|
|
472
|
+
"text"
|
|
473
|
+
].includes(prop)) {
|
|
474
|
+
console.error(`WindiUI: \`variantUtilities\` takes bg, border and text, not "${prop}".`);
|
|
475
|
+
return false;
|
|
476
|
+
}
|
|
477
|
+
if (!variantNames.includes(variant)) console.error(`WindiUI: \`variantUtilities\` names the variant "${variant}", which does not exist.`);
|
|
478
|
+
return variantNames.includes(variant);
|
|
479
|
+
});
|
|
480
|
+
if (variantUtils.length) {
|
|
481
|
+
const theme = tp.colors();
|
|
482
|
+
const named = colorNames.filter((c) => !(c.startsWith("accent-") && colorNames.includes(c.slice(7))) && !(c in theme));
|
|
483
|
+
tw.matchUtilities(Object.fromEntries(variantUtils.map(([prop, variant]) => [prop, known(named, (color, ext) => applyDark(darkSelector, gt.colors.variantUtilCss(color, prop, variant, ext.modifier ?? void 0)))])), {
|
|
484
|
+
values: keyValuePairs(named),
|
|
485
|
+
modifiers: tw.theme("opacity"),
|
|
486
|
+
type: ["lookup"]
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
tw.matchUtilities({ s: known(sizeNames, (val) => gt.sizes.cssVars(val)) }, { values: keyValuePairs(sizeNames) });
|
|
490
|
+
tw.addComponents([...gt.components.css()]);
|
|
491
|
+
}, {
|
|
492
|
+
content: [],
|
|
493
|
+
theme: { extend: { colors(utils) {
|
|
494
|
+
const { colors } = utils;
|
|
495
|
+
const isV3 = ver ? ver === 3 : "breakpoints" in utils;
|
|
496
|
+
const follow = (prefix) => keyValuePairs(Object.keys(colors.gray), (v) => {
|
|
497
|
+
const c = wiu.vars.color(`${prefix}${v}`);
|
|
498
|
+
return isV3 ? `rgb(${c} / <alpha-value>)` : c;
|
|
499
|
+
});
|
|
500
|
+
if (probing) return {};
|
|
501
|
+
let theme = [];
|
|
502
|
+
probing = true;
|
|
503
|
+
try {
|
|
504
|
+
theme = Object.keys(flattenColorPalette(utils.theme("colors") ?? {}));
|
|
505
|
+
} catch {} finally {
|
|
506
|
+
probing = false;
|
|
507
|
+
}
|
|
508
|
+
const inTheme = (name) => theme.some((key) => key === name || key.startsWith(`${name}-`));
|
|
509
|
+
const fallback = {
|
|
510
|
+
default: colors[FALLBACK.default],
|
|
511
|
+
accent: colors[FALLBACK.accent]
|
|
512
|
+
};
|
|
513
|
+
missing = {};
|
|
514
|
+
for (const name of ["default", "accent"]) {
|
|
515
|
+
const shades = Object.keys(fallback[name]).filter((s) => !theme.includes(`${name}-${s}`));
|
|
516
|
+
if (wiu.config[name] == null && shades.length && shades.length < 11) missing[name] = shades;
|
|
517
|
+
}
|
|
518
|
+
utilities ??= utilityColors(wiu.config, inTheme);
|
|
519
|
+
const own = {};
|
|
520
|
+
for (const [name, value] of utilities) if (typeof value !== "string") own[name] = "vars" in value ? keyValuePairs(Object.keys(colors.gray), (s) => isV3 ? `rgb(var(${value.vars}-${s}) / <alpha-value>)` : `var(${value.vars}-${s})`) : value;
|
|
521
|
+
else if (value in colors) own[name] = colors[value];
|
|
522
|
+
else if (!utilitiesReported) {
|
|
523
|
+
utilitiesReported = true;
|
|
524
|
+
console.error(`WindiUI: "${value}" is not one of Tailwind's own palettes, so "${name}" gets no color utilities.`);
|
|
525
|
+
}
|
|
526
|
+
followed = {
|
|
527
|
+
...wiu.config.default != null ? { default: follow("default-") } : {},
|
|
528
|
+
...wiu.config.accent != null ? { accent: follow("accent-") } : {}
|
|
529
|
+
};
|
|
530
|
+
return {
|
|
531
|
+
...own,
|
|
532
|
+
c: follow(""),
|
|
533
|
+
...fallback,
|
|
534
|
+
...followed
|
|
535
|
+
};
|
|
536
|
+
} } }
|
|
537
|
+
}), { [CONFIG]: config });
|
|
538
|
+
}
|
|
539
|
+
export { createWindiUIPlugin as t };
|
|
540
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Config } from "@windi-ui/core";
|
|
2
|
+
interface PluginOptions extends Config {
|
|
3
|
+
/** The config file to load, relative to the working directory. `false` turns the search for one off. */
|
|
4
|
+
config?: string | false;
|
|
5
|
+
}
|
|
6
|
+
/** The plugin factory. Tailwind calls it itself for `@plugin "@windi-ui/tailwind"`, with the options of the `@plugin` block. */
|
|
7
|
+
interface WindiUIPlugin<P> {
|
|
8
|
+
(options?: PluginOptions): P;
|
|
9
|
+
__isOptionsFunction: true;
|
|
10
|
+
}
|
|
11
|
+
/** What Tailwind 4 takes as a plugin. Its own types are not used: this package is built against Tailwind 3's. */
|
|
12
|
+
interface TailwindV4Plugin {
|
|
13
|
+
handler: (api: any) => void;
|
|
14
|
+
config?: any;
|
|
15
|
+
}
|
|
16
|
+
export { WindiUIPlugin as n, TailwindV4Plugin as t };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import "tailwindcss/plugin";
|
|
2
|
+
import { Config } from "@windi-ui/core";
|
|
3
|
+
interface PluginOptions extends Config {
|
|
4
|
+
/** The config file to load, relative to the working directory. `false` turns the search for one off. */
|
|
5
|
+
config?: string | false;
|
|
6
|
+
}
|
|
7
|
+
/** The plugin factory. Tailwind calls it itself for `@plugin "@windi-ui/tailwind"`, with the options of the `@plugin` block. */
|
|
8
|
+
interface WindiUIPlugin<P> {
|
|
9
|
+
(options?: PluginOptions): P;
|
|
10
|
+
__isOptionsFunction: true;
|
|
11
|
+
}
|
|
12
|
+
/** What Tailwind 4 takes as a plugin. Its own types are not used: this package is built against Tailwind 3's. */
|
|
13
|
+
interface TailwindV4Plugin {
|
|
14
|
+
handler: (api: any) => void;
|
|
15
|
+
config?: any;
|
|
16
|
+
}
|
|
17
|
+
export { WindiUIPlugin as n, TailwindV4Plugin as t };
|
package/dist/presets.cjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _windi_ui_core_presets = require("@windi-ui/core/presets");
|
|
3
|
+
Object.defineProperty(exports, "definePreset", {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
get: function() {
|
|
6
|
+
return _windi_ui_core_presets.definePreset;
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
Object.defineProperty(exports, "nuxtUi", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return _windi_ui_core_presets.nuxtUi;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
package/dist/presets.mjs
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _windi_ui_core = require("@windi-ui/core");
|
|
3
|
+
const require_configState = require("./configState-BnylRpdM.cjs");
|
|
4
|
+
// src/safelist.ts
|
|
5
|
+
const AXES = [
|
|
6
|
+
"c",
|
|
7
|
+
"v",
|
|
8
|
+
"s"
|
|
9
|
+
];
|
|
10
|
+
const SHADES = [
|
|
11
|
+
50,
|
|
12
|
+
100,
|
|
13
|
+
200,
|
|
14
|
+
300,
|
|
15
|
+
400,
|
|
16
|
+
500,
|
|
17
|
+
600,
|
|
18
|
+
700,
|
|
19
|
+
800,
|
|
20
|
+
900,
|
|
21
|
+
950
|
|
22
|
+
];
|
|
23
|
+
/** The palettes of Tailwind 4's default theme. Tailwind 3 has no mauve, olive, mist and taupe. */
|
|
24
|
+
const PALETTES = [
|
|
25
|
+
"slate",
|
|
26
|
+
"gray",
|
|
27
|
+
"zinc",
|
|
28
|
+
"neutral",
|
|
29
|
+
"stone",
|
|
30
|
+
"mauve",
|
|
31
|
+
"olive",
|
|
32
|
+
"mist",
|
|
33
|
+
"taupe",
|
|
34
|
+
"red",
|
|
35
|
+
"orange",
|
|
36
|
+
"amber",
|
|
37
|
+
"yellow",
|
|
38
|
+
"lime",
|
|
39
|
+
"green",
|
|
40
|
+
"emerald",
|
|
41
|
+
"teal",
|
|
42
|
+
"cyan",
|
|
43
|
+
"sky",
|
|
44
|
+
"blue",
|
|
45
|
+
"indigo",
|
|
46
|
+
"violet",
|
|
47
|
+
"purple",
|
|
48
|
+
"fuchsia",
|
|
49
|
+
"pink",
|
|
50
|
+
"rose"
|
|
51
|
+
];
|
|
52
|
+
const braces = (items) => items.length === 1 ? items[0] : `{${items.join(",")}}`;
|
|
53
|
+
/** The classes of the given names as one brace expression, sorted: `{c-{blue,red},v-{default,solid},s-{default,lg}}`. */
|
|
54
|
+
function classSource(names, axes = AXES) {
|
|
55
|
+
return braces(axes.map((axis) => `${axis}-${braces([...names[axis]].sort())}`));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The `c-*`, `v-*` and `s-*` classes a config registers, for `@source inline("...")` in a Tailwind 4 stylesheet.
|
|
59
|
+
* It runs without Tailwind, so it knows the palettes of the theme only by name: see `palettes`.
|
|
60
|
+
* @param config the options, or the plugin `windiui()` made from them.
|
|
61
|
+
*/
|
|
62
|
+
function safelistSource(config = {}, { axes, palettes = PALETTES } = {}) {
|
|
63
|
+
const colors = Object.fromEntries([
|
|
64
|
+
...palettes,
|
|
65
|
+
"default",
|
|
66
|
+
"accent"
|
|
67
|
+
].flatMap((p) => SHADES.map((s) => [`${p}-${s}`, ""])));
|
|
68
|
+
const gt = (0, _windi_ui_core.create)(require_configState.unwrap(config)).generator({
|
|
69
|
+
colors: () => colors,
|
|
70
|
+
spacing: () => "",
|
|
71
|
+
fontSize: () => "",
|
|
72
|
+
applyTextColor() {},
|
|
73
|
+
applyBackgroundColor() {},
|
|
74
|
+
applyBorderColor() {},
|
|
75
|
+
colorValue: (value) => value
|
|
76
|
+
});
|
|
77
|
+
return classSource({
|
|
78
|
+
c: gt.colors.names(),
|
|
79
|
+
v: gt.variants.names(),
|
|
80
|
+
s: gt.sizes.names()
|
|
81
|
+
}, axes);
|
|
82
|
+
}
|
|
83
|
+
exports.classSource = classSource;
|
|
84
|
+
exports.safelistSource = safelistSource;
|
|
85
|
+
|