@windi-ui/core 0.8.0-beta.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 +88 -57
- package/dist/components.d.cts +1 -1
- package/dist/components.d.mts +1 -1
- package/dist/index.cjs +560 -163
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +560 -164
- package/dist/nuxt-ui-CvNwRMiY.cjs +104 -0
- package/dist/nuxt-ui-S3tspIeQ.mjs +93 -0
- package/dist/presets.cjs +4 -0
- package/dist/presets.d.cts +4 -0
- package/dist/presets.d.mts +4 -0
- package/dist/presets.mjs +1 -0
- package/dist/{types-DKL2Gqrn.d.mts → types-7pMUZGLb.d.mts} +170 -13
- package/dist/{vars-BQT8iude.d.cts → vars-D-T56h9H.d.cts} +170 -13
- package/package.json +5 -1
package/dist/index.mjs
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
|
+
import { n as definePreset, t as nuxtUi } from "./nuxt-ui-S3tspIeQ.mjs";
|
|
1
2
|
import { n as button_default, t as badge_default } from "./badge-B-3Z5qKd.mjs";
|
|
2
3
|
// src/config.ts
|
|
4
|
+
const PRESETS = { "nuxt-ui": nuxtUi };
|
|
3
5
|
function resolveConfig(config) {
|
|
4
|
-
const { prefix = "wui", rootSelector = ":root", variantScope = "element", darkSelector, build, safelist = false, debug = false } = config;
|
|
6
|
+
const { prefix = "wui", rootSelector = ":root", variantScope = "element", overrideMode = "vars", darkSelector, presets = [], build, safelist = false, debug = false } = config;
|
|
5
7
|
return {
|
|
6
8
|
prefix,
|
|
7
9
|
rootSelector,
|
|
8
10
|
default: config.default,
|
|
9
11
|
accent: config.accent,
|
|
12
|
+
colors: config.colors,
|
|
10
13
|
variantScope,
|
|
14
|
+
overrides: config.overrides,
|
|
15
|
+
overrideMode,
|
|
16
|
+
variantUtilities: config.variantUtilities,
|
|
11
17
|
darkSelector,
|
|
18
|
+
presets: presets.map((p) => typeof p !== "string" ? p : Object.hasOwn(PRESETS, p) ? PRESETS[p]() : unknownPreset(p)),
|
|
12
19
|
build,
|
|
13
20
|
safelist,
|
|
14
21
|
debug
|
|
15
22
|
};
|
|
16
23
|
}
|
|
24
|
+
function unknownPreset(name) {
|
|
25
|
+
throw new Error(`WindiUI: unknown preset "${name}". The presets are: ${Object.keys(PRESETS).join(", ")}.`);
|
|
26
|
+
}
|
|
17
27
|
/** Types a config object, so that one object can be shared by the plugin, a config file and other tools. */
|
|
18
28
|
function defineConfig(config) {
|
|
19
29
|
return config;
|
|
@@ -42,8 +52,11 @@ var BuilderBase = class {
|
|
|
42
52
|
console.error(`"${name}" already exists.`);
|
|
43
53
|
return;
|
|
44
54
|
}
|
|
45
|
-
|
|
46
|
-
|
|
55
|
+
this.set(name, builder);
|
|
56
|
+
}
|
|
57
|
+
/** Adds an item, or replaces the one of that name, `default` included. */
|
|
58
|
+
set(name, builder) {
|
|
59
|
+
this.items.set(name, builder(this.ctx));
|
|
47
60
|
}
|
|
48
61
|
update(name, builder) {
|
|
49
62
|
const elem = this.items.get(name);
|
|
@@ -84,7 +97,252 @@ var VarsGeneratorBase = class extends BuilderBase {
|
|
|
84
97
|
return this.cssVars("default");
|
|
85
98
|
}
|
|
86
99
|
};
|
|
100
|
+
// src/colors.ts
|
|
101
|
+
const COLOR_SHADES = [
|
|
102
|
+
"50",
|
|
103
|
+
"100",
|
|
104
|
+
"200",
|
|
105
|
+
"300",
|
|
106
|
+
"400",
|
|
107
|
+
"500",
|
|
108
|
+
"600",
|
|
109
|
+
"700",
|
|
110
|
+
"800",
|
|
111
|
+
"900",
|
|
112
|
+
"950"
|
|
113
|
+
];
|
|
114
|
+
const COLOR_SHADE_REGEX = /50|950|[1-9]00/;
|
|
115
|
+
const COLOR_SHADE_EX_REGEX = new RegExp(`^((?:(default|accent)-)?(${COLOR_SHADE_REGEX.source})|black|white)$`);
|
|
116
|
+
/** The theme method that paints each main property of `apply-v`, `btn` and `variantUtilities`. */
|
|
117
|
+
const APPLY = {
|
|
118
|
+
bg: "applyBackgroundColor",
|
|
119
|
+
border: "applyBorderColor",
|
|
120
|
+
text: "applyTextColor"
|
|
121
|
+
};
|
|
122
|
+
/** The variant variable that each main property of `apply-v`, `btn` and `variantUtilities` reads. */
|
|
123
|
+
const VAR_PROP = {
|
|
124
|
+
bg: "bg",
|
|
125
|
+
border: "border",
|
|
126
|
+
text: "fg"
|
|
127
|
+
};
|
|
128
|
+
const COLOR_PALETTE_REGEX = new RegExp(`^(.+)-(${COLOR_SHADE_REGEX.source})$`);
|
|
129
|
+
const FLAT_COLORS = {
|
|
130
|
+
black: "#000",
|
|
131
|
+
white: "#fff"
|
|
132
|
+
};
|
|
133
|
+
function getColorMap(colors, debug) {
|
|
134
|
+
const cMap = {
|
|
135
|
+
palette: /* @__PURE__ */ new Map(),
|
|
136
|
+
custom: /* @__PURE__ */ new Map()
|
|
137
|
+
};
|
|
138
|
+
for (const key in colors) {
|
|
139
|
+
const value = colors[key];
|
|
140
|
+
const mRes = COLOR_PALETTE_REGEX.exec(key);
|
|
141
|
+
if (mRes) {
|
|
142
|
+
const cName = mRes[1];
|
|
143
|
+
if (cName === "c") continue;
|
|
144
|
+
if (!cMap.palette.has(cName)) cMap.palette.set(cName, /* @__PURE__ */ new Map());
|
|
145
|
+
cMap.palette.get(cName).set(mRes[2], value);
|
|
146
|
+
} else cMap.custom.set(key, value);
|
|
147
|
+
}
|
|
148
|
+
for (const [cName, shades] of cMap.palette) if (shades.size !== 11) {
|
|
149
|
+
if (debug) console.warn(`Color palette "${cName}" does not have all 11 shades (50, 100, ..., 950).`);
|
|
150
|
+
cMap.palette.delete(cName);
|
|
151
|
+
for (const [sKey, sVal] of shades) cMap.custom.set(`${cName}-${sKey}`, sVal);
|
|
152
|
+
}
|
|
153
|
+
return cMap;
|
|
154
|
+
}
|
|
155
|
+
var ColorsGenerator = class extends VarsGeneratorBase {
|
|
156
|
+
options;
|
|
157
|
+
variants;
|
|
158
|
+
colors;
|
|
159
|
+
items;
|
|
160
|
+
/** The colors with a `c-*` class: `colors.only` and those of the builder. Left out, all of them. */
|
|
161
|
+
only;
|
|
162
|
+
/** @param variants gives the override variables of each `c-*` class */
|
|
163
|
+
constructor(ctx, options, variants) {
|
|
164
|
+
super(ctx);
|
|
165
|
+
this.options = options;
|
|
166
|
+
this.variants = variants;
|
|
167
|
+
this.colors = getColorMap(this.theme.colors(), options.debug);
|
|
168
|
+
this.items = this.colors.palette;
|
|
169
|
+
const only = options.colors?.only;
|
|
170
|
+
if (only) {
|
|
171
|
+
this.only = new Set(only);
|
|
172
|
+
variants.hasColor = (c) => this.only.has(c) || c === "default" || c === "accent";
|
|
173
|
+
}
|
|
174
|
+
for (const name of ["default", "accent"]) {
|
|
175
|
+
const value = options[name];
|
|
176
|
+
if (value == null) continue;
|
|
177
|
+
const palette = this.resolve(value);
|
|
178
|
+
if (!palette) throw new Error(`WindiUI: the \`${name}\` option does not give a palette.`);
|
|
179
|
+
this.items.set(name, palette);
|
|
180
|
+
this.alias(name, value);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/** The 11 shades of a palette given by name, by CSS variables or as the shades themselves. */
|
|
184
|
+
resolve(value) {
|
|
185
|
+
if (typeof value === "string") {
|
|
186
|
+
const palette = this.items.get(value);
|
|
187
|
+
if (!palette) console.error(`Color "${value}" not found.`);
|
|
188
|
+
return palette && new Map(palette);
|
|
189
|
+
}
|
|
190
|
+
if ("vars" in value) return new Map(COLOR_SHADES.map((s) => [s, `var(${value.vars}-${s})`]));
|
|
191
|
+
const missing = COLOR_SHADES.filter((s) => !value[s]);
|
|
192
|
+
if (missing.length) {
|
|
193
|
+
console.error(`A color needs all 11 shades; ${missing.join(", ")} ${missing.length > 1 ? "are" : "is"} missing.`);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
return new Map(COLOR_SHADES.map((s) => [s, this.theme.toColor?.(value[s]) ?? value[s]]));
|
|
197
|
+
}
|
|
198
|
+
addColor(name, value) {
|
|
199
|
+
if (this.items.has(name)) {
|
|
200
|
+
console.error(`"${name}" already exists.`);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
this.setColor(name, value);
|
|
204
|
+
}
|
|
205
|
+
/** Adds a palette, or replaces the one of that name. */
|
|
206
|
+
setColor(name, value) {
|
|
207
|
+
const palette = this.resolve(value);
|
|
208
|
+
if (palette) {
|
|
209
|
+
this.items.set(name, palette);
|
|
210
|
+
this.alias(name, value);
|
|
211
|
+
this.only?.add(name);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
remove(name) {
|
|
215
|
+
super.remove(name);
|
|
216
|
+
if (!this.items.has(name)) this.variants.alias(name);
|
|
217
|
+
}
|
|
218
|
+
alias(name, value) {
|
|
219
|
+
this.variants.alias(name, typeof value === "object" && "vars" in value && value.overrideVars ? {
|
|
220
|
+
...value.overrideVars,
|
|
221
|
+
vars: value.vars
|
|
222
|
+
} : void 0);
|
|
223
|
+
}
|
|
224
|
+
/** @param all also the palettes that `colors.only` leaves without a class */
|
|
225
|
+
names(all = false) {
|
|
226
|
+
const cNames = super.names().filter((c) => all || (this.only?.has(c) ?? true));
|
|
227
|
+
cNames.push(...cNames.map((c) => `accent-${c}`));
|
|
228
|
+
return cNames;
|
|
229
|
+
}
|
|
230
|
+
/** The names of `colors.only` that are not palettes. */
|
|
231
|
+
unknownOnly() {
|
|
232
|
+
return (this.options.colors?.only ?? []).filter((c) => !this.items.has(c));
|
|
233
|
+
}
|
|
234
|
+
cssVars(name) {
|
|
235
|
+
let palette = this.items.get(name);
|
|
236
|
+
let accentVars = false;
|
|
237
|
+
if (!palette) {
|
|
238
|
+
if (name.startsWith("accent-")) {
|
|
239
|
+
name = name.replace(/^accent-/, "");
|
|
240
|
+
palette = this.items.get(name);
|
|
241
|
+
if (palette) accentVars = true;
|
|
242
|
+
else {
|
|
243
|
+
console.error(`Color "${name}" not found.`);
|
|
244
|
+
return {};
|
|
245
|
+
}
|
|
246
|
+
} else {
|
|
247
|
+
console.error(`Color "${name}" not found.`);
|
|
248
|
+
return {};
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return {
|
|
252
|
+
...cssVars(Object.fromEntries(palette.entries()), (n) => this.vars.c(accentVars ? `accent-${n}` : n)),
|
|
253
|
+
...this.variants.colorVars(name, accentVars)
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
rootVars() {
|
|
257
|
+
const cRoot = {};
|
|
258
|
+
for (const mn in FLAT_COLORS) cRoot[this.vars.c(mn)] = this.colors.custom.get(mn) ?? FLAT_COLORS[mn];
|
|
259
|
+
const dc = super.rootVars();
|
|
260
|
+
Object.assign(cRoot, dc);
|
|
261
|
+
const { "@dark": accentDark, ...accent } = this.variants.colorVars("accent", true);
|
|
262
|
+
Object.assign(cRoot, accent);
|
|
263
|
+
if (accentDark) cRoot["@dark"] = {
|
|
264
|
+
...cRoot["@dark"],
|
|
265
|
+
...accentDark
|
|
266
|
+
};
|
|
267
|
+
const addPalette = (suffix, palette) => {
|
|
268
|
+
for (const [shade, color] of palette) cRoot[this.vars.c(`${suffix}-${shade}`)] = color;
|
|
269
|
+
};
|
|
270
|
+
addPalette("default", this.items.get("default") ?? /* @__PURE__ */ new Map());
|
|
271
|
+
addPalette("accent", this.items.get("accent") ?? /* @__PURE__ */ new Map());
|
|
272
|
+
return cRoot;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* `bg-{color}` and the like of `variantUtilities`: the value of `variant` for this color, overrides included, with
|
|
276
|
+
* its opacity unless `alpha` is given, light and dark. A shade is this palette's, not the element's `c-*` class.
|
|
277
|
+
*/
|
|
278
|
+
variantUtilCss(color, prop, variant, alpha) {
|
|
279
|
+
const palette = this.items.get(color);
|
|
280
|
+
const values = palette && this.variants.colorValues(variant, color);
|
|
281
|
+
if (!values) return {};
|
|
282
|
+
const key = VAR_PROP[prop];
|
|
283
|
+
const shade = new RegExp(`var\\(${this.vars.c("")}(${COLOR_SHADE_REGEX.source})\\)`, "g");
|
|
284
|
+
const paint = (v) => {
|
|
285
|
+
const target = {};
|
|
286
|
+
const value = v[key].replace(shade, (read, s) => palette.get(s) ?? read);
|
|
287
|
+
this.theme[APPLY[prop]](value, target, alpha ?? v[`${key}-opacity`]);
|
|
288
|
+
return target;
|
|
289
|
+
};
|
|
290
|
+
const { light, dark } = values;
|
|
291
|
+
const css = paint(light);
|
|
292
|
+
if (key in dark || `${key}-opacity` in dark) css["@dark"] = paint({
|
|
293
|
+
...light,
|
|
294
|
+
...dark
|
|
295
|
+
});
|
|
296
|
+
return css;
|
|
297
|
+
}
|
|
298
|
+
toValue(name, alpha) {
|
|
299
|
+
return this.theme.colorValue(COLOR_SHADE_EX_REGEX.exec(name) ? this.vars.color(name) : name, alpha);
|
|
300
|
+
}
|
|
301
|
+
};
|
|
87
302
|
// src/variants.ts
|
|
303
|
+
const CALIBRATED = [
|
|
304
|
+
"bg",
|
|
305
|
+
"fg",
|
|
306
|
+
"border",
|
|
307
|
+
"bg-:hover",
|
|
308
|
+
"fg-:hover",
|
|
309
|
+
"border-:hover"
|
|
310
|
+
];
|
|
311
|
+
const ACCENT_KEY = /^(bg|border|fg)-accent(-:|$)/;
|
|
312
|
+
const APPLY_PROPS = [
|
|
313
|
+
"bg",
|
|
314
|
+
"border",
|
|
315
|
+
"text"
|
|
316
|
+
].flatMap((p) => [
|
|
317
|
+
p,
|
|
318
|
+
`${p}-soft`,
|
|
319
|
+
`${p}-muted`,
|
|
320
|
+
`${p}-accent`
|
|
321
|
+
]);
|
|
322
|
+
/** The states `apply-v-[...]` takes, by name without the colon. */
|
|
323
|
+
const APPLY_STATES = [
|
|
324
|
+
":hover",
|
|
325
|
+
":focus",
|
|
326
|
+
":focus-visible",
|
|
327
|
+
":focus-within",
|
|
328
|
+
":active",
|
|
329
|
+
":visited",
|
|
330
|
+
":target",
|
|
331
|
+
":checked",
|
|
332
|
+
":indeterminate",
|
|
333
|
+
":disabled",
|
|
334
|
+
":enabled",
|
|
335
|
+
":invalid",
|
|
336
|
+
":valid",
|
|
337
|
+
":user-invalid",
|
|
338
|
+
":user-valid",
|
|
339
|
+
":required",
|
|
340
|
+
":optional",
|
|
341
|
+
":read-only",
|
|
342
|
+
":placeholder-shown",
|
|
343
|
+
":autofill",
|
|
344
|
+
":open"
|
|
345
|
+
];
|
|
88
346
|
function defaultVariant(vars) {
|
|
89
347
|
return {
|
|
90
348
|
"bg": vars.color("white"),
|
|
@@ -261,32 +519,57 @@ function mainVariants(vars) {
|
|
|
261
519
|
}
|
|
262
520
|
};
|
|
263
521
|
}
|
|
264
|
-
|
|
522
|
+
/** @param fill whether a state refers to the base value of each property it leaves out */
|
|
523
|
+
function flatten(vars, props, fill = true) {
|
|
265
524
|
const { pseudos: vPseudos, ...vProps } = props;
|
|
266
525
|
const cssObj = vProps;
|
|
267
526
|
if (vPseudos) {
|
|
268
|
-
const propKeys =
|
|
527
|
+
const propKeys = fill ? Object.keys(vProps) : [];
|
|
269
528
|
for (const vpk in vPseudos) {
|
|
270
529
|
const vp = vPseudos[vpk];
|
|
271
530
|
if (vp) {
|
|
272
|
-
const vpPropKeys = new Set(Object.keys(vp)
|
|
273
|
-
for (const vppk of vpPropKeys) cssObj[`${vppk}-${vpk}`] =
|
|
531
|
+
const vpPropKeys = /* @__PURE__ */ new Set([...Object.keys(vp), ...propKeys]);
|
|
532
|
+
for (const vppk of vpPropKeys) cssObj[`${vppk}-${vpk}`] = vp[vppk] ?? vars.variant(vppk);
|
|
274
533
|
}
|
|
275
534
|
}
|
|
276
535
|
}
|
|
277
|
-
return
|
|
536
|
+
return cssObj;
|
|
537
|
+
}
|
|
538
|
+
function getCssVars(vars, props) {
|
|
539
|
+
return cssVars(flatten(vars, props), (n) => vars.v(n));
|
|
540
|
+
}
|
|
541
|
+
/** An override value: a shade of the color, of the accent color for an `-accent` property, or the value as written. */
|
|
542
|
+
function shade(vars, key, value) {
|
|
543
|
+
if (key.includes("opacity") || !COLOR_SHADE_EX_REGEX.test(value)) return value;
|
|
544
|
+
return ACCENT_KEY.test(key) && /^\d/.test(value) ? vars.color.accent(value) : vars.color(value);
|
|
545
|
+
}
|
|
546
|
+
/** Merges `source` into `target` in depth; `under` keeps the values `target` has. */
|
|
547
|
+
function merge(target, source, under) {
|
|
548
|
+
for (const [key, value] of Object.entries(source)) if (value && typeof value === "object") merge(target[key] ??= {}, value, under);
|
|
549
|
+
else if (!under || !(key in target)) target[key] = value;
|
|
278
550
|
}
|
|
279
551
|
/** The light values of the built-in default variant, by CSS variable name. */
|
|
280
552
|
function defaultVariantVars(vars) {
|
|
281
553
|
const { dark: _, ...props } = defaultVariant(vars);
|
|
282
|
-
|
|
554
|
+
const light = getCssVars(vars, props);
|
|
555
|
+
for (const [name, value] of Object.entries(light)) {
|
|
556
|
+
const base = /^var\((--[^,()\s]+)\)$/.exec(value)?.[1];
|
|
557
|
+
if (base && base in light) light[name] = `var(${base}, ${light[base]})`;
|
|
558
|
+
}
|
|
559
|
+
return light;
|
|
283
560
|
}
|
|
284
561
|
var VariantsGenerator = class extends VarsGeneratorBase {
|
|
285
562
|
scope;
|
|
563
|
+
mode;
|
|
286
564
|
items;
|
|
287
|
-
|
|
565
|
+
/** Palettes given by CSS variables that also take their overrides from variables. */
|
|
566
|
+
aliases = /* @__PURE__ */ new Map();
|
|
567
|
+
/** Whether a color is applied anywhere; the overrides of the others are left out. Set by `colors.only`. */
|
|
568
|
+
hasColor = (_color) => true;
|
|
569
|
+
constructor(ctx, scope = "universal", mode = "vars") {
|
|
288
570
|
super(ctx);
|
|
289
571
|
this.scope = scope;
|
|
572
|
+
this.mode = mode;
|
|
290
573
|
this.items = new Map([["default", defaultVariant(this.vars)], ...Object.entries(mainVariants(this.vars))]);
|
|
291
574
|
}
|
|
292
575
|
cssVars(name) {
|
|
@@ -295,10 +578,169 @@ var VariantsGenerator = class extends VarsGeneratorBase {
|
|
|
295
578
|
console.error(`Variant "${name}" not found.`);
|
|
296
579
|
return {};
|
|
297
580
|
}
|
|
298
|
-
const {
|
|
299
|
-
const
|
|
300
|
-
if (
|
|
301
|
-
|
|
581
|
+
const { values: { light, dark }, statics, entries, keys } = this.resolved(name);
|
|
582
|
+
const compound = {};
|
|
583
|
+
if (this.mode !== "vars") for (const [color, own] of statics) {
|
|
584
|
+
const entry = entries.get(color);
|
|
585
|
+
for (const accent of [false, true]) {
|
|
586
|
+
const block = {};
|
|
587
|
+
const blockDark = {};
|
|
588
|
+
for (const k of Object.keys({
|
|
589
|
+
...own.light,
|
|
590
|
+
...own.dark
|
|
591
|
+
})) {
|
|
592
|
+
if (ACCENT_KEY.test(k) !== accent) continue;
|
|
593
|
+
if (k in own.light) block[k] = entry.light[k];
|
|
594
|
+
if (k in entry.dark) blockDark[k] = entry.dark[k];
|
|
595
|
+
else if (k in own.light && k in dark) blockDark[k] = dark[k];
|
|
596
|
+
}
|
|
597
|
+
if (Object.keys(block).length || Object.keys(blockDark).length) compound[`&.c-${accent ? "accent-" : ""}${color}`] = {
|
|
598
|
+
...cssVars(block, (n) => this.vars.v(n)),
|
|
599
|
+
...Object.keys(blockDark).length ? { "@dark": cssVars(blockDark, (n) => this.vars.v(n)) } : {}
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
for (const k of keys) {
|
|
604
|
+
const cv = cssEsc(this.vars.cv(`${name}-${k}`));
|
|
605
|
+
light[k] = `var(${cv}, ${light[k]})`;
|
|
606
|
+
if (k in dark) dark[k] = `var(${cv}, ${dark[k]})`;
|
|
607
|
+
}
|
|
608
|
+
const css = cssVars(light, (n) => this.vars.v(n));
|
|
609
|
+
if (variant.dark || Object.keys(dark).length) css["@dark"] = cssVars(dark, (n) => this.vars.v(n));
|
|
610
|
+
return Object.assign(css, compound);
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Sets values of a variant for some colors, over those they have.
|
|
614
|
+
* @param under keeps the values set before, so that a preset or a calibration never replaces an explicit override
|
|
615
|
+
*/
|
|
616
|
+
override(name, colors, override, under = false) {
|
|
617
|
+
const variant = this.items.get(name);
|
|
618
|
+
if (!variant) {
|
|
619
|
+
console.error(`"${name}" not found.`);
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
const value = typeof override === "function" ? override(this.ctx) : override;
|
|
623
|
+
const byColor = {};
|
|
624
|
+
for (const [key, own] of Object.entries(variant.colors ?? {})) for (const color of key.split(",")) merge(byColor[color.trim()] ??= {}, own, false);
|
|
625
|
+
for (const color of [colors].flat().flatMap((c) => c.split(","))) merge(byColor[color.trim()] ??= {}, value, under);
|
|
626
|
+
this.items.set(name, {
|
|
627
|
+
...variant,
|
|
628
|
+
colors: byColor
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
/** The colors that overrides name. */
|
|
632
|
+
overrideColors() {
|
|
633
|
+
return [...new Set([...this.items.values()].flatMap((v) => Object.keys(v.colors ?? {}).flatMap((k) => k.split(",").map((c) => c.trim()))))];
|
|
634
|
+
}
|
|
635
|
+
/** Makes the palette `color` take its overrides from `{vars}-{variant}-{prop}` variables, or with no `value` stops that. */
|
|
636
|
+
alias(color, value) {
|
|
637
|
+
if (value) this.aliases.set(color, value);
|
|
638
|
+
else this.aliases.delete(color);
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* The override variables a `c-*` class sets: the values of `color`, and `initial` for the others, so that a color
|
|
642
|
+
* inside another one is not overridden by it. In dark mode it resets a light override where the variant has a dark
|
|
643
|
+
* value of its own. With `accent`, those of the `-accent` properties, for `c-accent-*`.
|
|
644
|
+
*/
|
|
645
|
+
colorVars(color, accent = false) {
|
|
646
|
+
const light = {};
|
|
647
|
+
const dark = {};
|
|
648
|
+
for (const name of this.items.keys()) {
|
|
649
|
+
const { values, varEntries, keys } = this.resolved(name);
|
|
650
|
+
const entry = varEntries.get(color);
|
|
651
|
+
for (const k of keys) {
|
|
652
|
+
if (ACCENT_KEY.test(k) !== accent) continue;
|
|
653
|
+
const cv = cssEsc(this.vars.cv(`${name}-${k}`));
|
|
654
|
+
light[cv] = entry?.light[k] ?? "initial";
|
|
655
|
+
if (entry && k in entry.dark) dark[cv] = entry.dark[k];
|
|
656
|
+
else if (entry && k in entry.light && k in values.dark) dark[cv] = "initial";
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
return Object.keys(dark).length ? {
|
|
660
|
+
...light,
|
|
661
|
+
"@dark": dark
|
|
662
|
+
} : light;
|
|
663
|
+
}
|
|
664
|
+
values(name) {
|
|
665
|
+
const { dark = {}, colors: _, ...props } = this.items.get(name);
|
|
666
|
+
return {
|
|
667
|
+
light: flatten(this.vars, props),
|
|
668
|
+
dark: flatten(this.vars, dark)
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* The values of a variant, and its overrides by color: `statics` as configured, `entries` with what a palette given
|
|
673
|
+
* by variables forwards. `keys` get an override variable, which the colors of `varEntries` set.
|
|
674
|
+
*/
|
|
675
|
+
resolved(name) {
|
|
676
|
+
const values = this.values(name);
|
|
677
|
+
const statics = /* @__PURE__ */ new Map();
|
|
678
|
+
for (const [key, { dark = {}, ...light }] of Object.entries(this.items.get(name).colors ?? {})) for (const color of key.split(",").map((c) => c.trim()).filter(this.hasColor)) {
|
|
679
|
+
const flat = statics.get(color) ?? {
|
|
680
|
+
light: {},
|
|
681
|
+
dark: {}
|
|
682
|
+
};
|
|
683
|
+
for (const [k, v] of Object.entries(flatten(this.vars, light, false))) flat.light[k] = shade(this.vars, k, v);
|
|
684
|
+
for (const [k, v] of Object.entries(flatten(this.vars, dark, false))) flat.dark[k] = shade(this.vars, k, v);
|
|
685
|
+
statics.set(color, flat);
|
|
686
|
+
}
|
|
687
|
+
const forwarded = /* @__PURE__ */ new Map();
|
|
688
|
+
for (const [color, { variants, props = "calibrated" }] of this.aliases) {
|
|
689
|
+
if (variants && !variants.includes(name)) continue;
|
|
690
|
+
forwarded.set(color, props === "all" ? Object.keys({
|
|
691
|
+
...values.light,
|
|
692
|
+
...values.dark
|
|
693
|
+
}) : props === "calibrated" ? CALIBRATED : props);
|
|
694
|
+
}
|
|
695
|
+
const staticKeys = [...statics.values()].flatMap((f) => [...Object.keys(f.light), ...Object.keys(f.dark)]);
|
|
696
|
+
const forwardedKeys = [...forwarded.values()].flat();
|
|
697
|
+
const def = this.values("default");
|
|
698
|
+
for (const k of [...staticKeys, ...forwardedKeys]) {
|
|
699
|
+
if (k in values.light) continue;
|
|
700
|
+
values.light[k] = def.light[k] ?? this.vars.variant(k.replace(/-:.*$/, ""));
|
|
701
|
+
if (k in def.dark && !(k in values.dark)) values.dark[k] = def.dark[k];
|
|
702
|
+
}
|
|
703
|
+
const entries = new Map(statics);
|
|
704
|
+
const aliasEntries = /* @__PURE__ */ new Map();
|
|
705
|
+
for (const [color, keys] of forwarded) {
|
|
706
|
+
const { vars } = this.aliases.get(color);
|
|
707
|
+
const own = statics.get(color);
|
|
708
|
+
const entry = {
|
|
709
|
+
light: {},
|
|
710
|
+
dark: {}
|
|
711
|
+
};
|
|
712
|
+
for (const k of keys) {
|
|
713
|
+
const runtime = `var(${vars}-${name}-${k.replace(/:/g, "")}`;
|
|
714
|
+
entry.light[k] = `${runtime}${own?.light[k] ? `, ${own.light[k]}` : ""})`;
|
|
715
|
+
if (own?.dark[k]) entry.dark[k] = `${runtime}, ${own.dark[k]})`;
|
|
716
|
+
else if (k in values.dark) entry.dark[k] = `${runtime})`;
|
|
717
|
+
}
|
|
718
|
+
aliasEntries.set(color, entry);
|
|
719
|
+
entries.set(color, {
|
|
720
|
+
light: {
|
|
721
|
+
...own?.light,
|
|
722
|
+
...entry.light
|
|
723
|
+
},
|
|
724
|
+
dark: {
|
|
725
|
+
...own?.dark,
|
|
726
|
+
...entry.dark
|
|
727
|
+
}
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
if (this.mode === "compound") return {
|
|
731
|
+
values,
|
|
732
|
+
statics,
|
|
733
|
+
entries,
|
|
734
|
+
varEntries: aliasEntries,
|
|
735
|
+
keys: new Set(forwardedKeys)
|
|
736
|
+
};
|
|
737
|
+
return {
|
|
738
|
+
values,
|
|
739
|
+
statics,
|
|
740
|
+
entries,
|
|
741
|
+
varEntries: entries,
|
|
742
|
+
keys: /* @__PURE__ */ new Set([...staticKeys, ...forwardedKeys])
|
|
743
|
+
};
|
|
302
744
|
}
|
|
303
745
|
/** Every variable a variant can set, as `initial`: on a child it stops the parent's variant from inheriting. */
|
|
304
746
|
resetVars() {
|
|
@@ -308,7 +750,7 @@ var VariantsGenerator = class extends VarsGeneratorBase {
|
|
|
308
750
|
for (const v of Object.keys({
|
|
309
751
|
...light,
|
|
310
752
|
...dark
|
|
311
|
-
})) reset[v] = "initial";
|
|
753
|
+
})) if (v.startsWith("--")) reset[v] = "initial";
|
|
312
754
|
}
|
|
313
755
|
return reset;
|
|
314
756
|
}
|
|
@@ -316,6 +758,43 @@ var VariantsGenerator = class extends VarsGeneratorBase {
|
|
|
316
758
|
return this.withFallback(this.vApplyProp(v, prop, {}, void 0, alpha));
|
|
317
759
|
}
|
|
318
760
|
/**
|
|
761
|
+
* The CSS of `apply-v`: what `btn` gets, `bg`, `border` and `text` with `:hover`. `list` names props and states
|
|
762
|
+
* instead, such as `bg,text,focus-visible`: the props are applied at rest and in each state. Without props it is
|
|
763
|
+
* all three, without states `:hover`. A name it does not know gives `undefined`.
|
|
764
|
+
*/
|
|
765
|
+
applyCss(list) {
|
|
766
|
+
const tokens = list ? list.split(",").map((t) => t.trim()) : [];
|
|
767
|
+
const props = tokens.filter((t) => APPLY_PROPS.includes(t));
|
|
768
|
+
const states = tokens.map((t) => `:${t}`).filter((s) => APPLY_STATES.includes(s));
|
|
769
|
+
if (props.length + states.length !== tokens.length) return;
|
|
770
|
+
const v = props.length ? props : true;
|
|
771
|
+
return this.withFallback(this.apply(v, Object.fromEntries((states.length ? states : [":hover"]).map((s) => [s, v]))));
|
|
772
|
+
}
|
|
773
|
+
/**
|
|
774
|
+
* The values of a variant on an element of `color`, its overrides applied as the `c-*` and `v-*` classes would
|
|
775
|
+
* resolve them. `dark` holds the values that change in dark mode.
|
|
776
|
+
*/
|
|
777
|
+
colorValues(name, color) {
|
|
778
|
+
if (!this.items.has(name)) {
|
|
779
|
+
console.error(`Variant "${name}" not found.`);
|
|
780
|
+
return;
|
|
781
|
+
}
|
|
782
|
+
const { values, entries } = this.resolved(name);
|
|
783
|
+
const entry = entries.get(color);
|
|
784
|
+
const or = (value, base) => {
|
|
785
|
+
const read = /^var\((--[^,()\s]+)\)$/.exec(value)?.[1];
|
|
786
|
+
return read && !read.startsWith(this.vars.c("")) ? `var(${read}, ${base})` : value;
|
|
787
|
+
};
|
|
788
|
+
const light = { ...values.light };
|
|
789
|
+
const dark = { ...values.dark };
|
|
790
|
+
for (const [k, v] of Object.entries(entry?.light ?? {})) light[k] = or(v, values.light[k]);
|
|
791
|
+
for (const [k, v] of Object.entries(entry?.dark ?? {})) dark[k] = or(v, values.dark[k] ?? values.light[k]);
|
|
792
|
+
return {
|
|
793
|
+
light,
|
|
794
|
+
dark
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
319
798
|
* The two switches a fallback picks its light or dark value with: `var(on-light, <light>) var(on-dark, <dark>)`.
|
|
320
799
|
* The one of the current mode is not set, so its fallback is used, and the other one is empty.
|
|
321
800
|
* They inherit, so a pseudo-element is in the mode of its element, which a dark selector nested in its rule cannot tell.
|
|
@@ -377,21 +856,14 @@ var VariantsGenerator = class extends VarsGeneratorBase {
|
|
|
377
856
|
return target;
|
|
378
857
|
}
|
|
379
858
|
vApplyProp(mProp, sProp, target = {}, pseudo, alpha) {
|
|
380
|
-
const mvp = mProp
|
|
859
|
+
const mvp = VAR_PROP[mProp];
|
|
381
860
|
const vp = sProp && sProp !== "default" ? `${mvp}-${sProp}` : mvp;
|
|
382
861
|
const aVar = pseudo ? `${mvp}-opacity-${pseudo}` : `${mvp}-opacity`;
|
|
383
|
-
const
|
|
862
|
+
const key = pseudo ? `${vp}-${pseudo}` : vp;
|
|
863
|
+
const vVal = this.vars.variant(key, !pseudo || key in this.values("default").light ? void 0 : this.vars.variant(vp));
|
|
384
864
|
const one = this.scope === "universal" ? "1" : void 0;
|
|
385
865
|
const vAlpha = this.vars.variant(aVar, pseudo ? this.vars.variant(`${mvp}-opacity`, one) : one);
|
|
386
|
-
|
|
387
|
-
case "bg":
|
|
388
|
-
this.theme.applyBackgroundColor(vVal, target, vAlpha);
|
|
389
|
-
break;
|
|
390
|
-
case "border":
|
|
391
|
-
this.theme.applyBorderColor(vVal, target, vAlpha);
|
|
392
|
-
break;
|
|
393
|
-
case "text": this.theme.applyTextColor(vVal, target, vAlpha);
|
|
394
|
-
}
|
|
866
|
+
this.theme[APPLY[mProp]](vVal, target, vAlpha);
|
|
395
867
|
if (alpha) {
|
|
396
868
|
target[this.vars.v(aVar)] = `${alpha} !important`;
|
|
397
869
|
if (this.scope === "element") target[":where(&) > *"] = { [this.vars.v(aVar)]: "initial" };
|
|
@@ -410,6 +882,7 @@ function varsProvider(prefix) {
|
|
|
410
882
|
const c = (v) => vName(`c-${v}`);
|
|
411
883
|
const v = (v) => vName(`v-${v}`);
|
|
412
884
|
const s = (v) => vName(`s-${v}`);
|
|
885
|
+
const cv = (v) => vName(`cv-${v}`);
|
|
413
886
|
function color(name, fallback) {
|
|
414
887
|
return varFunc(c(name), fallback);
|
|
415
888
|
}
|
|
@@ -419,6 +892,7 @@ function varsProvider(prefix) {
|
|
|
419
892
|
c,
|
|
420
893
|
v,
|
|
421
894
|
s,
|
|
895
|
+
cv,
|
|
422
896
|
color,
|
|
423
897
|
variant(name, fallback) {
|
|
424
898
|
if (typeof fallback === "object") fallback = defaultVariantVars(vars)[cssEsc(v(name))];
|
|
@@ -433,136 +907,11 @@ function varsProvider(prefix) {
|
|
|
433
907
|
function cssVars(obj, keyMap, vars = {}) {
|
|
434
908
|
for (const p in obj) {
|
|
435
909
|
const val = obj[p];
|
|
436
|
-
if (typeof val === "string") vars[cssEsc(keyMap(p))] = val;
|
|
910
|
+
if (typeof val === "string" || typeof val === "number") vars[cssEsc(keyMap(p))] = String(val);
|
|
437
911
|
else cssVars(val, (cp) => `${keyMap(p)}-${cp}`, vars);
|
|
438
912
|
}
|
|
439
913
|
return vars;
|
|
440
914
|
}
|
|
441
|
-
// src/colors.ts
|
|
442
|
-
const COLOR_SHADES = [
|
|
443
|
-
"50",
|
|
444
|
-
"100",
|
|
445
|
-
"200",
|
|
446
|
-
"300",
|
|
447
|
-
"400",
|
|
448
|
-
"500",
|
|
449
|
-
"600",
|
|
450
|
-
"700",
|
|
451
|
-
"800",
|
|
452
|
-
"900",
|
|
453
|
-
"950"
|
|
454
|
-
];
|
|
455
|
-
const COLOR_SHADE_REGEX = /50|950|[1-9]00/;
|
|
456
|
-
const COLOR_SHADE_EX_REGEX = new RegExp(`^((?:(default|accent)-)?(${COLOR_SHADE_REGEX.source})|black|white)$`);
|
|
457
|
-
const COLOR_PALETTE_REGEX = new RegExp(`^(.+)-(${COLOR_SHADE_REGEX.source})$`);
|
|
458
|
-
const FLAT_COLORS = {
|
|
459
|
-
black: "#000",
|
|
460
|
-
white: "#fff"
|
|
461
|
-
};
|
|
462
|
-
function getColorMap(colors, debug) {
|
|
463
|
-
const cMap = {
|
|
464
|
-
palette: /* @__PURE__ */ new Map(),
|
|
465
|
-
custom: /* @__PURE__ */ new Map()
|
|
466
|
-
};
|
|
467
|
-
for (const key in colors) {
|
|
468
|
-
const value = colors[key];
|
|
469
|
-
const mRes = COLOR_PALETTE_REGEX.exec(key);
|
|
470
|
-
if (mRes) {
|
|
471
|
-
const cName = mRes[1];
|
|
472
|
-
if (cName === "c") continue;
|
|
473
|
-
if (!cMap.palette.has(cName)) cMap.palette.set(cName, /* @__PURE__ */ new Map());
|
|
474
|
-
cMap.palette.get(cName).set(mRes[2], value);
|
|
475
|
-
} else cMap.custom.set(key, value);
|
|
476
|
-
}
|
|
477
|
-
for (const [cName, shades] of cMap.palette) if (shades.size !== 11) {
|
|
478
|
-
if (debug) console.warn(`Color palette "${cName}" does not have all 11 shades (50, 100, ..., 950).`);
|
|
479
|
-
cMap.palette.delete(cName);
|
|
480
|
-
for (const [sKey, sVal] of shades) cMap.custom.set(`${cName}-${sKey}`, sVal);
|
|
481
|
-
}
|
|
482
|
-
return cMap;
|
|
483
|
-
}
|
|
484
|
-
var ColorsGenerator = class extends VarsGeneratorBase {
|
|
485
|
-
colors;
|
|
486
|
-
items;
|
|
487
|
-
constructor(ctx, options = {}) {
|
|
488
|
-
super(ctx);
|
|
489
|
-
this.colors = getColorMap(this.theme.colors(), options.debug);
|
|
490
|
-
this.items = this.colors.palette;
|
|
491
|
-
for (const name of ["default", "accent"]) {
|
|
492
|
-
const value = options[name];
|
|
493
|
-
if (value == null) continue;
|
|
494
|
-
const palette = this.resolve(value);
|
|
495
|
-
if (!palette) throw new Error(`WindiUI: the \`${name}\` option does not give a palette.`);
|
|
496
|
-
this.items.set(name, palette);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
/** The 11 shades of a palette given by name, by CSS variables or as the shades themselves. */
|
|
500
|
-
resolve(value) {
|
|
501
|
-
if (typeof value === "string") {
|
|
502
|
-
const palette = this.items.get(value);
|
|
503
|
-
if (!palette) console.error(`Color "${value}" not found.`);
|
|
504
|
-
return palette && new Map(palette);
|
|
505
|
-
}
|
|
506
|
-
if ("vars" in value) return new Map(COLOR_SHADES.map((s) => [s, `var(${value.vars}-${s})`]));
|
|
507
|
-
const missing = COLOR_SHADES.filter((s) => !value[s]);
|
|
508
|
-
if (missing.length) {
|
|
509
|
-
console.error(`A color needs all 11 shades; ${missing.join(", ")} ${missing.length > 1 ? "are" : "is"} missing.`);
|
|
510
|
-
return;
|
|
511
|
-
}
|
|
512
|
-
return new Map(COLOR_SHADES.map((s) => [s, this.theme.toColor?.(value[s]) ?? value[s]]));
|
|
513
|
-
}
|
|
514
|
-
addColor(name, value) {
|
|
515
|
-
if (this.items.has(name)) {
|
|
516
|
-
console.error(`"${name}" already exists.`);
|
|
517
|
-
return;
|
|
518
|
-
}
|
|
519
|
-
this.setColor(name, value);
|
|
520
|
-
}
|
|
521
|
-
/** Adds a palette, or replaces the one of that name. */
|
|
522
|
-
setColor(name, value) {
|
|
523
|
-
const palette = this.resolve(value);
|
|
524
|
-
if (palette) this.items.set(name, palette);
|
|
525
|
-
}
|
|
526
|
-
names() {
|
|
527
|
-
const cNames = super.names();
|
|
528
|
-
cNames.push(...cNames.map((c) => `accent-${c}`));
|
|
529
|
-
return cNames;
|
|
530
|
-
}
|
|
531
|
-
cssVars(name) {
|
|
532
|
-
let palette = this.items.get(name);
|
|
533
|
-
let accentVars = false;
|
|
534
|
-
if (!palette) {
|
|
535
|
-
if (name.startsWith("accent-")) {
|
|
536
|
-
name = name.replace(/^accent-/, "");
|
|
537
|
-
palette = this.items.get(name);
|
|
538
|
-
if (palette) accentVars = true;
|
|
539
|
-
else {
|
|
540
|
-
console.error(`Color "${name}" not found.`);
|
|
541
|
-
return {};
|
|
542
|
-
}
|
|
543
|
-
} else {
|
|
544
|
-
console.error(`Color "${name}" not found.`);
|
|
545
|
-
return {};
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
return cssVars(Object.fromEntries(palette.entries()), (n) => this.vars.c(accentVars ? `accent-${n}` : n));
|
|
549
|
-
}
|
|
550
|
-
rootVars() {
|
|
551
|
-
const cRoot = {};
|
|
552
|
-
for (const mn in FLAT_COLORS) cRoot[this.vars.c(mn)] = this.colors.custom.get(mn) ?? FLAT_COLORS[mn];
|
|
553
|
-
const dc = super.rootVars();
|
|
554
|
-
Object.assign(cRoot, dc);
|
|
555
|
-
const addPalette = (suffix, palette) => {
|
|
556
|
-
for (const [shade, color] of palette) cRoot[this.vars.c(`${suffix}-${shade}`)] = color;
|
|
557
|
-
};
|
|
558
|
-
addPalette("default", this.items.get("default") ?? /* @__PURE__ */ new Map());
|
|
559
|
-
addPalette("accent", this.items.get("accent") ?? /* @__PURE__ */ new Map());
|
|
560
|
-
return cRoot;
|
|
561
|
-
}
|
|
562
|
-
toValue(name, alpha) {
|
|
563
|
-
return this.theme.colorValue(COLOR_SHADE_EX_REGEX.exec(name) ? this.vars.color(name) : name, alpha);
|
|
564
|
-
}
|
|
565
|
-
};
|
|
566
915
|
// src/size.ts
|
|
567
916
|
function sizes(themeProvider) {
|
|
568
917
|
return {
|
|
@@ -620,20 +969,40 @@ function sizes(themeProvider) {
|
|
|
620
969
|
}
|
|
621
970
|
var SizesGenerator = class extends VarsGeneratorBase {
|
|
622
971
|
items;
|
|
972
|
+
/** Whether `md` names the `default` size while no size of that name exists. Removing `md` ends it. */
|
|
973
|
+
md = true;
|
|
623
974
|
constructor(ctx) {
|
|
624
975
|
super(ctx);
|
|
625
976
|
this.items = new Map(Object.entries(sizes(this.theme)));
|
|
626
977
|
}
|
|
978
|
+
alias(name) {
|
|
979
|
+
return name === "md" && this.md && !this.items.has("md");
|
|
980
|
+
}
|
|
981
|
+
names() {
|
|
982
|
+
const names = super.names();
|
|
983
|
+
return this.alias("md") ? names.flatMap((n) => n === "default" ? [n, "md"] : [n]) : names;
|
|
984
|
+
}
|
|
985
|
+
update(name, builder) {
|
|
986
|
+
if (this.alias(name)) this.items.set(name, structuredClone(this.items.get("default")));
|
|
987
|
+
super.update(name, builder);
|
|
988
|
+
}
|
|
989
|
+
remove(name) {
|
|
990
|
+
const alias = this.alias(name);
|
|
991
|
+
if (name === "md") this.md = false;
|
|
992
|
+
if (!alias) super.remove(name);
|
|
993
|
+
}
|
|
627
994
|
cssVars(name) {
|
|
628
|
-
const size = this.items.get(name);
|
|
995
|
+
const size = this.items.get(this.alias(name) ? "default" : name);
|
|
629
996
|
if (!size) {
|
|
630
997
|
console.error(`Size "${name}" not found.`);
|
|
631
998
|
return {};
|
|
632
999
|
}
|
|
633
|
-
const
|
|
634
|
-
const
|
|
1000
|
+
const { spacing, text: sText, ...own } = size;
|
|
1001
|
+
const rSize = {
|
|
1002
|
+
spacing,
|
|
1003
|
+
text: Array.isArray(sText) ? sText[0] : sText
|
|
1004
|
+
};
|
|
635
1005
|
if (Array.isArray(sText)) {
|
|
636
|
-
rSize.text = sText[0];
|
|
637
1006
|
const rVal = sText[1];
|
|
638
1007
|
if (typeof rVal === "string") rSize["line-height"] = rVal;
|
|
639
1008
|
else if (typeof rVal === "object" && rVal !== null) {
|
|
@@ -642,6 +1011,7 @@ var SizesGenerator = class extends VarsGeneratorBase {
|
|
|
642
1011
|
if (rVal.fontWeight) rSize["font-weight"] = rVal.fontWeight;
|
|
643
1012
|
}
|
|
644
1013
|
}
|
|
1014
|
+
Object.assign(rSize, own);
|
|
645
1015
|
return cssVars(rSize, (n) => this.vars.s(n));
|
|
646
1016
|
}
|
|
647
1017
|
};
|
|
@@ -668,7 +1038,7 @@ var ComponentsGenerator = class extends BuilderBase {
|
|
|
668
1038
|
// src/builder.ts
|
|
669
1039
|
function createBuilder(colors, variants, sizes, components) {
|
|
670
1040
|
return {
|
|
671
|
-
colorsNames: () => colors.names(),
|
|
1041
|
+
colorsNames: (all) => colors.names(all),
|
|
672
1042
|
variantsNames: () => variants.names(),
|
|
673
1043
|
sizesNames: () => sizes.names(),
|
|
674
1044
|
componentsNames: () => components.names(),
|
|
@@ -692,6 +1062,18 @@ function createBuilder(colors, variants, sizes, components) {
|
|
|
692
1062
|
colors.setColor(name, value);
|
|
693
1063
|
return this;
|
|
694
1064
|
},
|
|
1065
|
+
setVariant(name, builder) {
|
|
1066
|
+
variants.set(name, builder);
|
|
1067
|
+
return this;
|
|
1068
|
+
},
|
|
1069
|
+
setSize(name, builder) {
|
|
1070
|
+
sizes.set(name, builder);
|
|
1071
|
+
return this;
|
|
1072
|
+
},
|
|
1073
|
+
setComponent(name, builder) {
|
|
1074
|
+
components.set(name, builder);
|
|
1075
|
+
return this;
|
|
1076
|
+
},
|
|
695
1077
|
updateColor(name, builder) {
|
|
696
1078
|
colors.update(name, builder);
|
|
697
1079
|
return this;
|
|
@@ -723,6 +1105,10 @@ function createBuilder(colors, variants, sizes, components) {
|
|
|
723
1105
|
removeComponent(name) {
|
|
724
1106
|
components.remove(name);
|
|
725
1107
|
return this;
|
|
1108
|
+
},
|
|
1109
|
+
overrideVariant(variant, colors, override) {
|
|
1110
|
+
variants.override(variant, colors, override);
|
|
1111
|
+
return this;
|
|
726
1112
|
}
|
|
727
1113
|
};
|
|
728
1114
|
}
|
|
@@ -730,6 +1116,13 @@ function createBuilder(colors, variants, sizes, components) {
|
|
|
730
1116
|
function create(config) {
|
|
731
1117
|
const rConfig = resolveConfig(config);
|
|
732
1118
|
const vars = varsProvider(rConfig.prefix);
|
|
1119
|
+
const reported = /* @__PURE__ */ new Set();
|
|
1120
|
+
/** Warns once per instance, for each source, about the names that are not palettes. */
|
|
1121
|
+
const notPalettes = (source, names) => {
|
|
1122
|
+
if (!names.length || reported.has(source)) return;
|
|
1123
|
+
reported.add(source);
|
|
1124
|
+
console.warn(`WindiUI: ${source} names ${names.map((c) => `"${c}"`).join(", ")}, which ${names.length > 1 ? "are not palettes" : "is not a palette"}.`);
|
|
1125
|
+
};
|
|
733
1126
|
return {
|
|
734
1127
|
vars,
|
|
735
1128
|
config: rConfig,
|
|
@@ -738,18 +1131,21 @@ function create(config) {
|
|
|
738
1131
|
vars,
|
|
739
1132
|
theme
|
|
740
1133
|
};
|
|
741
|
-
const
|
|
742
|
-
const
|
|
1134
|
+
const variants = new VariantsGenerator(ctx, rConfig.variantScope, rConfig.overrideMode);
|
|
1135
|
+
const colors = new ColorsGenerator(ctx, rConfig, variants);
|
|
743
1136
|
const sizes = new SizesGenerator(ctx);
|
|
744
1137
|
const components = new ComponentsGenerator({
|
|
745
1138
|
...ctx,
|
|
746
1139
|
colors,
|
|
747
1140
|
variants
|
|
748
1141
|
});
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
}
|
|
1142
|
+
const builder = createBuilder(colors, variants, sizes, components);
|
|
1143
|
+
for (const preset of rConfig.presets) preset.build(builder);
|
|
1144
|
+
rConfig.build?.(builder);
|
|
1145
|
+
for (const [variant, overrides] of Object.entries(rConfig.overrides ?? {})) for (const [color, override] of Object.entries(overrides)) variants.override(variant, color, override);
|
|
1146
|
+
const palettes = colors.names(true);
|
|
1147
|
+
notPalettes("`colors.only`", colors.unknownOnly());
|
|
1148
|
+
notPalettes("an override", variants.overrideColors().filter((c) => !palettes.includes(c) && c !== "default" && c !== "accent"));
|
|
753
1149
|
return {
|
|
754
1150
|
colors,
|
|
755
1151
|
variants,
|
|
@@ -759,4 +1155,4 @@ function create(config) {
|
|
|
759
1155
|
}
|
|
760
1156
|
};
|
|
761
1157
|
}
|
|
762
|
-
export { create, defineConfig, varsProvider };
|
|
1158
|
+
export { create, defineConfig, definePreset, varsProvider };
|