@windi-ui/tailwind 0.7.1 → 0.8.0-beta.1
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 +198 -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 +22 -330
- package/dist/index.d.cts +13 -6
- package/dist/index.d.mts +8 -6
- package/dist/index.mjs +6 -322
- package/dist/plugin-BWBKFnff.mjs +504 -0
- package/dist/plugin-BmHj0642.cjs +509 -0
- package/dist/plugin-QCWiD6Wb.d.cts +16 -0
- package/dist/plugin-ayXaeLBM.d.mts +17 -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 +27 -11
- package/dist/index.d.ts +0 -6
|
@@ -0,0 +1,504 @@
|
|
|
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
|
+
function setNestedValue(obj, keys, value) {
|
|
234
|
+
if (keys.length === 0) return obj;
|
|
235
|
+
let curr = obj;
|
|
236
|
+
for (let i = 0; i < keys.length; i++) {
|
|
237
|
+
const K = keys[i];
|
|
238
|
+
if (i === keys.length - 1) curr[K] = value;
|
|
239
|
+
else {
|
|
240
|
+
if (typeof curr[K] !== "object" || curr[K] === null) curr[K] = {};
|
|
241
|
+
curr = curr[K];
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return obj;
|
|
245
|
+
}
|
|
246
|
+
function applyDark(selector, styles) {
|
|
247
|
+
const { "@dark": darkStyle, ...style } = styles;
|
|
248
|
+
if (darkStyle) for (const s of selector) setNestedValue(style, s, darkStyle);
|
|
249
|
+
return style;
|
|
250
|
+
}
|
|
251
|
+
// src/utils/version.ts
|
|
252
|
+
const versions = /* @__PURE__ */ new Map();
|
|
253
|
+
/** The version of the `tailwindcss` package `file` belongs to, if it belongs to one. */
|
|
254
|
+
function tailwindVersionOf(file) {
|
|
255
|
+
if (!versions.has(file)) {
|
|
256
|
+
let version;
|
|
257
|
+
for (let dir = dirname(file); dirname(dir) !== dir; dir = dirname(dir)) {
|
|
258
|
+
const path = join(dir, "package.json");
|
|
259
|
+
if (!existsSync(path)) continue;
|
|
260
|
+
const pkg = JSON.parse(readFileSync(path, "utf8"));
|
|
261
|
+
if (pkg.name === "tailwindcss") version = pkg.version;
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
versions.set(file, version);
|
|
265
|
+
}
|
|
266
|
+
return versions.get(file);
|
|
267
|
+
}
|
|
268
|
+
/** The call stack, from this function outwards: for each frame, the version of the Tailwind its file belongs to, if any. */
|
|
269
|
+
function callers() {
|
|
270
|
+
const prepare = Error.prepareStackTrace;
|
|
271
|
+
Error.prepareStackTrace = (_, sites) => sites.map((site) => site.getFileName());
|
|
272
|
+
const files = (/* @__PURE__ */ new Error()).stack;
|
|
273
|
+
Error.prepareStackTrace = prepare;
|
|
274
|
+
return files.map((file) => file ? tailwindVersionOf(file.startsWith("file:") ? fileURLToPath(file) : file) : void 0);
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Whether Tailwind itself made the call `depth` frames above the function that asks, as it does for an `@plugin` block.
|
|
278
|
+
* It is `false` when that Tailwind cannot be found, for example when it is bundled.
|
|
279
|
+
*/
|
|
280
|
+
function calledByTailwind(depth) {
|
|
281
|
+
return callers()[depth + 2] != null;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Whether the Tailwind that is calling the plugin is at least this version. The plugin API does not carry a version,
|
|
285
|
+
* and the `tailwindcss` that resolves from here or from the working directory need not be the one that runs, so this
|
|
286
|
+
* goes by the call stack. It is `false` when that Tailwind cannot be found, for example when it is bundled.
|
|
287
|
+
*/
|
|
288
|
+
function tailwindAtLeast(...min) {
|
|
289
|
+
for (const version of callers()) {
|
|
290
|
+
if (!version) continue;
|
|
291
|
+
const parts = version.split(".").map((part) => parseInt(part));
|
|
292
|
+
for (let i = 0; i < 3; i++) if (parts[i] !== min[i]) return parts[i] > min[i];
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
// src/plugin.ts
|
|
298
|
+
const createPlugin = createRequire(import.meta.url)("tailwindcss/plugin");
|
|
299
|
+
function keyValuePairs(keys, val = (k) => k) {
|
|
300
|
+
return keys.reduce((acc, k) => {
|
|
301
|
+
acc[k] = val(k);
|
|
302
|
+
return acc;
|
|
303
|
+
}, {});
|
|
304
|
+
}
|
|
305
|
+
const FALLBACK = {
|
|
306
|
+
default: "gray",
|
|
307
|
+
accent: "blue"
|
|
308
|
+
};
|
|
309
|
+
const VARIANT_UTILS = {
|
|
310
|
+
v: "default",
|
|
311
|
+
"v-soft": "soft",
|
|
312
|
+
"v-muted": "muted",
|
|
313
|
+
"v-accent": "accent"
|
|
314
|
+
};
|
|
315
|
+
const NOTHING = [];
|
|
316
|
+
/** Tailwind also calls a `matchUtilities` callback for arbitrary values (`bg-[#123456]`, `c-[foo]`), which emit nothing. */
|
|
317
|
+
function known(values, css) {
|
|
318
|
+
const set = new Set(values);
|
|
319
|
+
return (val, ext) => set.has(val) ? css(val, ext) : NOTHING;
|
|
320
|
+
}
|
|
321
|
+
const OPTIONS = [
|
|
322
|
+
"prefix",
|
|
323
|
+
"rootSelector",
|
|
324
|
+
"default",
|
|
325
|
+
"accent",
|
|
326
|
+
"variantScope",
|
|
327
|
+
"darkSelector",
|
|
328
|
+
"build",
|
|
329
|
+
"safelist",
|
|
330
|
+
"debug",
|
|
331
|
+
"config"
|
|
332
|
+
];
|
|
333
|
+
/**
|
|
334
|
+
* Inline options over those of the config file. An `@plugin` block writes the names in kebab-case.
|
|
335
|
+
* @param strict whether an unknown option is an error. In a JavaScript call it was ignored in 0.7, and still only warns.
|
|
336
|
+
*/
|
|
337
|
+
function resolveOptions(options = {}, strict = false) {
|
|
338
|
+
const inline = {};
|
|
339
|
+
for (const [name, value] of Object.entries(options)) {
|
|
340
|
+
const key = name.replace(/-(\w)/g, (_, c) => c.toUpperCase());
|
|
341
|
+
if (!OPTIONS.includes(key)) {
|
|
342
|
+
const message = `WindiUI: unknown option "${name}". The options are: ${OPTIONS.join(", ")}.`;
|
|
343
|
+
if (strict) throw new Error(message);
|
|
344
|
+
console.warn(message);
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
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.");
|
|
348
|
+
if (value !== void 0) inline[key] = key === "rootSelector" && Array.isArray(value) ? value.join(", ") : value;
|
|
349
|
+
}
|
|
350
|
+
const { config: file, ...config } = inline;
|
|
351
|
+
if (file === false || file == null && config.build || isLoadingConfig()) return config;
|
|
352
|
+
return {
|
|
353
|
+
...loadWindiUIConfig({ config: file }).config,
|
|
354
|
+
...config
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* The palettes `build` adds with `utilities: true`. Tailwind resolves its theme before the builder can run, so `build`
|
|
359
|
+
* is first run on a builder that does nothing but note them.
|
|
360
|
+
*/
|
|
361
|
+
function utilityColors(build, inTheme) {
|
|
362
|
+
const found = /* @__PURE__ */ new Map();
|
|
363
|
+
const removed = /* @__PURE__ */ new Set();
|
|
364
|
+
const set = (name, value, options) => {
|
|
365
|
+
if (options?.utilities) found.set(name, value);
|
|
366
|
+
else found.delete(name);
|
|
367
|
+
return builder;
|
|
368
|
+
};
|
|
369
|
+
const builder = new Proxy({
|
|
370
|
+
addColor: (name, ...rest) => inTheme(name) && !removed.has(name) && !found.has(name) ? builder : set(name, ...rest),
|
|
371
|
+
setColor: set,
|
|
372
|
+
removeColor: (name) => (found.delete(name), removed.add(name), builder)
|
|
373
|
+
}, { get: (target, key) => target[key] ?? (() => key.endsWith("Names") ? [] : builder) });
|
|
374
|
+
try {
|
|
375
|
+
build?.(builder);
|
|
376
|
+
} catch {}
|
|
377
|
+
return found;
|
|
378
|
+
}
|
|
379
|
+
/** @param ver the Tailwind major to build for; left out, it is taken from the Tailwind that runs the plugin. */
|
|
380
|
+
function createWindiUIPlugin(ver) {
|
|
381
|
+
return Object.assign((options) => WindiUITailwindCSS(resolveOptions(options, calledByTailwind(1)), ver), { __isOptionsFunction: true });
|
|
382
|
+
}
|
|
383
|
+
function WindiUITailwindCSS(config, ver) {
|
|
384
|
+
const wiu = create(config);
|
|
385
|
+
let followed = {};
|
|
386
|
+
let missing = {};
|
|
387
|
+
let probing = false;
|
|
388
|
+
let mixReported = false;
|
|
389
|
+
let utilities;
|
|
390
|
+
let utilitiesReported = false;
|
|
391
|
+
let safelistReported = false;
|
|
392
|
+
return Object.assign(createPlugin((tw) => {
|
|
393
|
+
const tp = createTailwindTheme(tw, ver, utilities && [...utilities.keys()]);
|
|
394
|
+
const gt = wiu.generator(tp);
|
|
395
|
+
for (const [name, shades] of Object.entries(mixReported ? {} : missing)) {
|
|
396
|
+
mixReported = true;
|
|
397
|
+
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.`);
|
|
398
|
+
}
|
|
399
|
+
for (const [name, palette] of Object.entries(mixReported ? {} : followed)) {
|
|
400
|
+
const theme = tw.theme(`colors.${name}`, {});
|
|
401
|
+
if (Object.keys(palette).some((s) => theme[s] !== palette[s])) {
|
|
402
|
+
mixReported = true;
|
|
403
|
+
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.`);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
const darkMode = wiu.config.darkSelector != null ? toDarkMode(wiu.config.darkSelector) : tw.config("darkMode");
|
|
407
|
+
const darkSelector = darkMode != null ? getDarkSelector(darkMode) : tp.ver === 4 && tailwindAtLeast(4, 1, 17) ? VARIANT_DARK : getDarkSelector("media");
|
|
408
|
+
const root = wiu.config.rootSelector;
|
|
409
|
+
tw.addBase({ [root]: gt.colors.rootVars() });
|
|
410
|
+
tw.addBase({ [root]: gt.sizes.rootVars() });
|
|
411
|
+
const scope = wiu.config.variantScope;
|
|
412
|
+
if (scope === "universal") tw.addBase({ "*": applyDark(darkSelector, gt.variants.rootVars()) });
|
|
413
|
+
else {
|
|
414
|
+
const mode = gt.variants.modeVars();
|
|
415
|
+
tw.addBase({ ":where(:root)": mode.light });
|
|
416
|
+
tw.addBase({ "*": applyDark(darkSelector, { "@dark": mode.dark }) });
|
|
417
|
+
const reset = gt.variants.resetVars();
|
|
418
|
+
if (scope === "element") tw.addBase({ ":where([class*=\"v-\"]) > *": reset });
|
|
419
|
+
tw.addUtilities({ ".v-scope": { ":where(&) > *": reset } });
|
|
420
|
+
}
|
|
421
|
+
const colorNames = gt.colors.names();
|
|
422
|
+
const variantNames = gt.variants.names();
|
|
423
|
+
const sizeNames = gt.sizes.names();
|
|
424
|
+
if (tp.ver === 3) {
|
|
425
|
+
const list = tw.config("safelist");
|
|
426
|
+
for (const [, name] of darkSelector.flat().join(" ").matchAll(/\.(-?[_a-zA-Z][\w-]*)/g)) if (!list.includes(name)) list.push(name);
|
|
427
|
+
}
|
|
428
|
+
if (wiu.config.safelist && tp.ver === 3) {
|
|
429
|
+
const list = tw.config("safelist");
|
|
430
|
+
const pattern = new RegExp(`^${tw.config("prefix", "").replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}[cvs]-`);
|
|
431
|
+
if (!list.some((entry) => String(entry?.pattern) === String(pattern))) list.push({ pattern });
|
|
432
|
+
}
|
|
433
|
+
if (wiu.config.safelist && tp.ver === 4 && !safelistReported) {
|
|
434
|
+
safelistReported = true;
|
|
435
|
+
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({
|
|
436
|
+
c: colorNames,
|
|
437
|
+
v: variantNames,
|
|
438
|
+
s: sizeNames
|
|
439
|
+
})}");`);
|
|
440
|
+
}
|
|
441
|
+
tw.matchUtilities({ c: known(colorNames, (val) => gt.colors.cssVars(val)) }, { values: keyValuePairs(colorNames) });
|
|
442
|
+
tw.matchUtilities({ v: known(variantNames, (val) => applyDark(darkSelector, gt.variants.cssVars(val))) }, { values: keyValuePairs(variantNames) });
|
|
443
|
+
const variantUtil = (prop) => known(Object.values(VARIANT_UTILS), (val, ext) => gt.variants.utilCss(prop, val, ext.modifier ?? void 0));
|
|
444
|
+
tw.matchUtilities({
|
|
445
|
+
bg: variantUtil("bg"),
|
|
446
|
+
border: variantUtil("border"),
|
|
447
|
+
text: variantUtil("text")
|
|
448
|
+
}, {
|
|
449
|
+
values: VARIANT_UTILS,
|
|
450
|
+
modifiers: tw.theme("opacity"),
|
|
451
|
+
...tp.ver === 3 ? { type: ["lookup"] } : {}
|
|
452
|
+
});
|
|
453
|
+
tw.matchUtilities({ s: known(sizeNames, (val) => gt.sizes.cssVars(val)) }, { values: keyValuePairs(sizeNames) });
|
|
454
|
+
tw.addComponents([...gt.components.css()]);
|
|
455
|
+
}, {
|
|
456
|
+
content: [],
|
|
457
|
+
theme: { extend: { colors(utils) {
|
|
458
|
+
const { colors } = utils;
|
|
459
|
+
const isV3 = ver ? ver === 3 : "breakpoints" in utils;
|
|
460
|
+
const follow = (prefix) => keyValuePairs(Object.keys(colors.gray), (v) => {
|
|
461
|
+
const c = wiu.vars.color(`${prefix}${v}`);
|
|
462
|
+
return isV3 ? `rgb(${c} / <alpha-value>)` : c;
|
|
463
|
+
});
|
|
464
|
+
if (probing) return {};
|
|
465
|
+
let theme = [];
|
|
466
|
+
probing = true;
|
|
467
|
+
try {
|
|
468
|
+
theme = Object.keys(flattenColorPalette(utils.theme("colors") ?? {}));
|
|
469
|
+
} catch {} finally {
|
|
470
|
+
probing = false;
|
|
471
|
+
}
|
|
472
|
+
const inTheme = (name) => theme.some((key) => key === name || key.startsWith(`${name}-`));
|
|
473
|
+
const fallback = {
|
|
474
|
+
default: colors[FALLBACK.default],
|
|
475
|
+
accent: colors[FALLBACK.accent]
|
|
476
|
+
};
|
|
477
|
+
missing = {};
|
|
478
|
+
for (const name of ["default", "accent"]) {
|
|
479
|
+
const shades = Object.keys(fallback[name]).filter((s) => !theme.includes(`${name}-${s}`));
|
|
480
|
+
if (wiu.config[name] == null && shades.length && shades.length < 11) missing[name] = shades;
|
|
481
|
+
}
|
|
482
|
+
utilities ??= utilityColors(wiu.config.build, inTheme);
|
|
483
|
+
const own = {};
|
|
484
|
+
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;
|
|
485
|
+
else if (value in colors) own[name] = colors[value];
|
|
486
|
+
else if (!utilitiesReported) {
|
|
487
|
+
utilitiesReported = true;
|
|
488
|
+
console.error(`WindiUI: "${value}" is not one of Tailwind's own palettes, so "${name}" gets no color utilities.`);
|
|
489
|
+
}
|
|
490
|
+
followed = {
|
|
491
|
+
...wiu.config.default != null ? { default: follow("default-") } : {},
|
|
492
|
+
...wiu.config.accent != null ? { accent: follow("accent-") } : {}
|
|
493
|
+
};
|
|
494
|
+
return {
|
|
495
|
+
...own,
|
|
496
|
+
c: follow(""),
|
|
497
|
+
...fallback,
|
|
498
|
+
...followed
|
|
499
|
+
};
|
|
500
|
+
} } }
|
|
501
|
+
}), { [CONFIG]: config });
|
|
502
|
+
}
|
|
503
|
+
export { createWindiUIPlugin as t };
|
|
504
|
+
|